00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00027 #include <exotkAF_Document.hxx>
00028
00029 #ifndef _TCollection_AsciiString_HeaderFile
00030 #include <TCollection_AsciiString.hxx>
00031 #endif
00032 #ifndef _exotkAIS_DisplayManager_HeaderFile
00033 #include <exotkAIS_DisplayManager.hxx>
00034 #endif
00035 #ifndef _OSD_Path_HeaderFile
00036 #include <OSD_Path.hxx>
00037 #endif
00038 #ifndef _TopoDS_Shape_HeaderFile
00039 #include <TopoDS_Shape.hxx>
00040 #endif
00041 #ifndef _AIS_Shape_HeaderFile
00042 #include <AIS_Shape.hxx>
00043 #endif
00044 #ifndef _exotkAF_HSetOfView_HeaderFile
00045 #include <exotkAF_HSetOfView.hxx>
00046 #endif
00047 #ifndef _exotkAF_SetIteratorOfSetOfView_HeaderFile
00048 #include <exotkAF_SetIteratorOfSetOfView.hxx>
00049 #endif
00050 #ifndef _exotkAF_View_HeaderFile
00051 #include <exotkAF_View.hxx>
00052 #endif
00053 #ifndef _exotkAF_HeaderFile
00054 #include <exotkAF.hxx>
00055 #endif
00056 #ifndef _exotkAF_Application_HeaderFile
00057 #include <exotkAF_Application.hxx>
00058 #endif
00059 #ifndef _exotkTree_Tree_HeaderFile
00060 #include <exotkTree_Tree.hxx>
00061 #endif
00062 #ifndef _exotkTree_TreeNode_HeaderFile
00063 #include <exotkTree_TreeNode.hxx>
00064 #endif
00065 #ifndef _exotkBRepTree_HeaderFile
00066 #include <exotkBRepTree.hxx>
00067 #endif
00068 #ifndef _exotkBRepTree_ShapeNode_HeaderFile
00069 #include <exotkBRepTree_ShapeNode.hxx>
00070 #endif
00071 #ifndef _exotkDX_HeaderFile
00072 #include <exotkDX.hxx>
00073 #endif
00074 #ifndef _Standard_DefineHandle_HeaderFile
00075 #include <Standard_DefineHandle.hxx>
00076 #endif
00077 #ifndef _TopTools_HSequenceOfShape_HeaderFile
00078 #include <TopTools_HSequenceOfShape.hxx>
00079 #endif
00080 #ifndef _exotkTrace_HeaderFile
00081 #include <exotkTrace.hxx>
00082 #endif
00083 #ifndef _exotkGUI_HeaderFile
00084 #include <exotkGUI.hxx>
00085 #endif
00086 #ifndef _AIS_InteractiveContext_HeaderFile
00087 #include <AIS_InteractiveContext.hxx>
00088 #endif
00089
00090
00091 IMPLEMENT_STANDARD_HANDLE(exotkAF_Document, MMgt_TShared)
00092 IMPLEMENT_STANDARD_RTTI(exotkAF_Document, MMgt_TShared)
00093
00094
00095
00096
00097
00098
00099
00100 IMPLEMENT_STANDARD_TYPE(exotkAF_Document)
00101 IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared)
00102 IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient)
00103 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
00104 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared)
00105 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient)
00106 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
00107 IMPLEMENT_STANDARD_TYPE_END(exotkAF_Document)
00108
00114 namespace exotkAF_Document_Datas
00115 {
00117 exotkAF_SetIteratorOfSetOfView theViewIterator;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 exotkAF_Document::exotkAF_Document()
00129 {
00130 myIsInitialized = Standard_False;
00131 myViews = new exotkAF_HSetOfView();
00132
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 exotkAF_Document::~exotkAF_Document()
00144 {
00145 if (!myViews.IsNull())
00146 myViews->Clear();
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156 Handle_exotkAIS_DisplayManager exotkAF_Document::DisplayManager()
00157 {
00158 return myDisplayManager;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 void exotkAF_Document::SetName(const TCollection_AsciiString& aName)
00170 {
00171 myName = aName;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181 TCollection_AsciiString exotkAF_Document::Name()
00182 {
00183 return myName;
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 Handle_exotkTree_Tree exotkAF_Document::Tree()
00195 {
00196 return myTree;
00197 }
00198
00199
00200
00201
00202
00203
00204
00205 Standard_Boolean exotkAF_Document::Init()
00206 {
00207 if (!myIsInitialized)
00208 {
00209 exotkAF::Application()->AddDocument(this);
00210 myDisplayManager = new exotkAIS_DisplayManager();
00211 myIsInitialized = Standard_True;
00212 myTree = new exotkTree_Tree();
00213 Handle_exotkTree_TreeNode theRoot = new exotkTree_TreeNode();
00214 theRoot->SetTree(myTree);
00215 theRoot->SetName("Structure");
00216 myTree->SetRoot(theRoot);
00217 myShapes = new TopTools_HSequenceOfShape();
00218 }
00219 return Standard_True;
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 Standard_Boolean exotkAF_Document::OpenFile(const TCollection_AsciiString &aFilename)
00232 {
00233 Handle_TopTools_HSequenceOfShape theReadShapes;
00234 Standard_Boolean theReadIsOK = exotkDX::LoadShapes( aFilename,theReadShapes);
00235 if ( theReadIsOK )
00236 {
00237 exotkTrace::Debug("shape loaded from %s",aFilename.ToCString());
00238 }
00239 else
00240 {
00241 exotkTrace::Error("shape not loaded from %s",aFilename.ToCString());
00242 }
00243 Standard_Boolean theAddShapeIsOK = Standard_False;
00244 if (theReadIsOK)
00245 {
00246 OSD_Path thePath(aFilename);
00247 TCollection_AsciiString theShapeName = thePath.Name();
00248 Standard_Integer theNbShapes = theReadShapes->Length();
00249 exotkGUI::ShowProgressBox();
00250 exotkGUI::SetProgressBoxTitle("Opening file");
00251 exotkGUI::SetProgressBoxRange(0,100);
00252 exotkGUI::SetProgressBoxText("Adding the shapes");
00253 for ( Standard_Integer i = 1 ; i <= theNbShapes ; i++ )
00254 {
00255 exotkGUI::SetProgressBoxPosition(i*100/theNbShapes);
00256 TCollection_AsciiString theCurrentShapeName = theShapeName;
00257 if ( theReadShapes->Length() > 1 )
00258 {
00259 theCurrentShapeName += TCollection_AsciiString("_") + TCollection_AsciiString(i);
00260 }
00261 if ( AddShape(theReadShapes->Value(i),theCurrentShapeName) )
00262 {
00263 theAddShapeIsOK = Standard_True;
00264 }
00265 }
00266 if ( myName.IsEmpty())
00267 {
00268 myName = theShapeName + thePath.Extension();
00269 }
00270 exotkGUI::HideProgressBox();
00271 }
00272
00273 if ( theAddShapeIsOK )
00274 {
00275 exotkTrace::Debug("Shape successfully added in doc from %s",aFilename.ToCString());
00276 }
00277 else
00278 {
00279 exotkTrace::Error("Shape NOT added in doc from %s",aFilename.ToCString());
00280 }
00281 if (theReadIsOK && theAddShapeIsOK)
00282 {
00283 exotkTrace::Debug("Opening %s",aFilename.ToCString());
00284 return Standard_True;
00285 }
00286 else
00287 {
00288 exotkTrace::Error("Cannot open %s",aFilename.ToCString());
00289 }
00290 return Standard_False;
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 Standard_Boolean exotkAF_Document::AddShape(const TopoDS_Shape &aShapeToAdd,const TCollection_AsciiString& aName)
00304 {
00305 if ( aShapeToAdd.IsNull() )
00306 return Standard_False;
00307 Handle_AIS_Shape theAISShape = new AIS_Shape(aShapeToAdd);
00308
00309 Standard_Boolean theDocIsOK = Init();
00310 myShapes->Append(aShapeToAdd);
00311 if (theDocIsOK)
00312 {
00313 myDisplayManager->Add(theAISShape, aName);
00314 Handle_exotkTree_TreeNode theShapeTopNode = exotkBRepTree::ComputeTopNode(aShapeToAdd,aName);
00315 if ( !theShapeTopNode.IsNull() )
00316 {
00317 myTree->Root()->AppendChild(theShapeTopNode);
00318
00319 myTree->SetVisible(theShapeTopNode);
00320 }
00321 }
00322
00323 return theDocIsOK;
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 Handle_exotkAF_View exotkAF_Document::CreateView(const Aspect_Handle &anHandle)
00335 {
00336 Handle_exotkAF_View theNewView = new exotkAF_View();
00337 theNewView->SetDocument(this);
00338 if (theNewView->CreateView(myDisplayManager->InteractiveContext()->CurrentViewer(), anHandle))
00339 {
00340 if (AddView(theNewView))
00341 return theNewView;
00342 else
00343 return Handle_exotkAF_View();
00344 }
00345 else
00346 {
00347 return Handle_exotkAF_View();
00348 }
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 Standard_Boolean exotkAF_Document::AddView(const Handle_exotkAF_View &aView)
00361 {
00362 return myViews->Add(aView);
00363 }
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 Standard_Boolean exotkAF_Document::RemoveView(const Handle_exotkAF_View &aView)
00374 {
00375 return myViews->Remove(aView);
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385 void exotkAF_Document::InitViewIterator()
00386 {
00387 exotkAF_Document_Datas::theViewIterator.Initialize(myViews->Set());
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397 Standard_Boolean exotkAF_Document::MoreViewIterator()
00398 {
00399 return exotkAF_Document_Datas::theViewIterator.More();
00400 }
00401
00402
00403
00404
00405
00406
00407
00408
00409 void exotkAF_Document::NextViewIterator()
00410 {
00411 exotkAF_Document_Datas::theViewIterator.Next();
00412 }
00413
00414
00415
00416
00417
00418
00419
00420
00421 Handle_exotkAF_View exotkAF_Document::CurrentViewIterator()
00422 {
00423 return exotkAF_Document_Datas::theViewIterator.Value();
00424 }
00425
00426
00427
00428
00429
00430
00431
00432
00433 Standard_Integer exotkAF_Document::NbViews()
00434 {
00435 return myViews->Extent();
00436 }
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 Standard_Boolean exotkAF_Document::SetActiveView(const Handle_exotkAF_View& aView)
00448 {
00449 Standard_Boolean theSuccess = Standard_False;
00450 if ( !aView.IsNull() && !myViews.IsNull() && myViews->Contains(aView) )
00451 {
00452 myActiveView = aView;
00453 theSuccess = Standard_True;
00454 }
00455 return theSuccess;
00456 }
00457
00458
00459
00460
00461
00462
00463
00464
00465 Handle_exotkAF_View exotkAF_Document::ActiveView()
00466 {
00467 return myActiveView;
00468 }
00469
00470 Standard_Boolean exotkAF_Document::SaveFile(const TCollection_AsciiString& aFilename)
00471 {
00472 Standard_Boolean theSuccess = Standard_False;
00473 if ( !aFilename.IsEmpty() )
00474 {
00475 exotkDX::SaveShapes(aFilename,myShapes);
00476 }
00477
00478 return theSuccess;
00479 }