qoccdocument.cpp

Go to the documentation of this file.
00001 /************************************************************************************
00002 **
00003 ** This file is part of the QtOPENCASCADE Toolkit.
00004 **
00005 ** Copyright (C) 2006, 2007, 2008 QtOCC Team Members
00006 **               Peter Dolbey, Marc Britten, Stephane Routelous
00007 **               Stefan Boeykens, Pawel Dobrolowski, Walter Steffe
00008 **               Álvaro Castro Castilla, Dirk Burski, Fotis Sioutis
00009 **
00010 ** This library is free software; you can redistribute it and/or
00011 ** modify it under the terms of the GNU Lesser General Public
00012 ** License as published by the Free Software Foundation; either
00013 ** version 2.1 of the License, or (at your option) any later version.
00014 ** 
00015 ** This library is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 ** Lesser General Public License for more details.
00019 ** 
00020 ** You should have received a copy of the GNU Lesser General Public
00021 ** License along with this library; if not, write to the Free Software
00022 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 **
00024 ***********************************************************************************/
00025 /*!
00026 \class  QoccDocument
00027 \brief  This class provides a base object for "proxy" OpenCascade objects,
00028         and a set of starter files for new classes
00029 \author Peter C. Dolbey
00030 */
00031 
00032 #include <qnamespace.h>
00033 #include "qoccapplication.h"
00034 #include "qoccdocument.h"
00035 #include "qoccinternal.h"
00036 
00037 #include <TNaming_NamedShape.hxx>
00038 #include <TDF_ChildIterator.hxx>
00039 #include <TDataStd_Integer.hxx>
00040 #include <TPrsStd_AISViewer.hxx>
00041 #include <GEOM_Object.hxx>
00042 
00043 QoccDocument::QoccDocument( const Handle(TDocStd_Document)& aDoc, int anID )
00044 {
00045         myDocument = aDoc;
00046         myID  = anID;
00047 }
00048 
00049 QoccDocument::~QoccDocument( )
00050 {
00051 }
00052 
00053 void QoccDocument::undo()
00054 {
00055         qGeomApp->Undo( this );
00056 }
00057 
00058 void QoccDocument::redo()
00059 {
00060         qGeomApp->Redo( this );
00061 }
00062 
00063 Handle(TPrsStd_AISPresentation) QoccDocument::RegisterPresentation(Handle(GEOM_Object) TheGeomObject)
00064 {
00065   TDF_Label aResultLabel = TheGeomObject->GetLastFunction()->GetEntry().FindChild(RESULT_LABEL);
00066   Handle(TPrsStd_AISPresentation) prs_main = TPrsStd_AISPresentation::Set(aResultLabel, TNaming_NamedShape::GetID());
00067   prs_main->Display(Standard_True);
00068   return prs_main;
00069 }
00070 
00071 bool QoccDocument::RemovePresentation(Handle(GEOM_Object) TheGeomObject)
00072 {
00073   if (TheGeomObject != NULL)
00074   {
00075         if (!TheGeomObject.IsNull())
00076         {
00077           TDF_Label aResultLabel = TheGeomObject->GetLastFunction()->GetEntry().FindChild(RESULT_LABEL);
00078           Handle(TPrsStd_AISPresentation) prs_ref;
00079           aResultLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), prs_ref);
00080           prs_ref->Erase(Standard_True);
00081         }
00082   }
00083   return true;
00084 }
00085 
00086 void QoccDocument::UpdatePresentations(TDF_Label aRoot)
00087 {
00088   TDF_Label LabGEOM = aRoot;
00089 
00090   if (!LabGEOM.IsNull())
00091   {
00092         for (TDF_ChildIterator it(LabGEOM); it.More(); it.Next())
00093         {
00094           TDF_Label Label = it.Value();
00095           Handle_GEOM_Object this_obj = GEOM_Object::GetObject  (Label);
00096           if (!this_obj.IsNull())
00097           {
00098                 int func_num = this_obj->GetNbFunctions();
00099                 for (int i = 1 ; i <= func_num; i++)
00100                 {
00101                   Handle(GEOM_Function) aFunction = this_obj->GetFunction(i);
00102                   if (!aFunction.IsNull())
00103                   {
00104                         TDF_Label aResultLabel = aFunction->GetEntry().FindChild(RESULT_LABEL);
00105                         Handle(TNaming_NamedShape) TNS;
00106                         if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), TNS))
00107                         {
00108                           continue;
00109                         }
00110                         Handle(TDataStd_Integer) TDI;
00111                         if (aResultLabel.FindAttribute(TDataStd_Integer::GetID(), TDI))
00112                         {
00113                           if(!TDI->Get())
00114                           {
00115                                 continue;
00116                           }
00117                         }
00118                         Handle(TPrsStd_AISPresentation) prs;
00119                         if (!aResultLabel.FindAttribute(TPrsStd_AISPresentation::GetID(),prs))
00120                         {
00121                           prs = TPrsStd_AISPresentation::Set(aResultLabel,TNaming_NamedShape::GetID());
00122                         }
00123 
00124                         if (prs->IsDisplayed())
00125                         {
00126                           prs->Display(Standard_True);
00127                         }
00128                   }
00129                 }
00130           }
00131           UpdatePresentations(Label);
00132         }
00133   }
00134 }
00135 
00136 void QoccDocument::SetDocumentAndID(Handle(TDocStd_Document) aDocument, int anID)
00137 {
00138         myDocument = aDocument;
00139         myID  = anID;
00140 }
00141 
00142 
00143 
00144 

Generated on Sat Feb 23 21:22:15 2008 for QtGEOM by  doxygen 1.4.7