00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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