Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

exotkAF_Document.cxx

Go to the documentation of this file.
00001 
00002 //   exotkAF_Document.cxx
00004 //    Copyright (C) 2001  Stephane Routelous
00005 //
00006 //    This file is part of exoTK.
00007 //
00008 //    exoTK is free software; you can redistribute it and/or modify
00009 //    it under the terms of the GNU General Public License as published by
00010 //    the Free Software Foundation; either version 2 of the License, or
00011 //    (at your option) any later version.
00012 //
00013 //    exoTK is distributed in the hope that it will be useful,
00014 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //    GNU General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU General Public License
00019 //    along with exoTK; if not, write to the Free Software
00020 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Foreach ancestors, we add a IMPLEMENT_STANDARD_SUPERTYPE and 
00095 // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro.
00096 // We must respect the order: from the direct ancestor class
00097 // to the base class.
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 // Function name        : exotkAF_Document::exotkAF_Document
00123 //==================================================================================
00124 // Written by       : Stephane Routelous - 2001-11-06 16:08:14
00125 // Description      : 
00126 // Return type          : 
00127 //==================================================================================
00128 exotkAF_Document::exotkAF_Document()
00129 {
00130         myIsInitialized = Standard_False;
00131         myViews = new exotkAF_HSetOfView();
00132 //      myName = TCollection_AsciiString("No Name");
00133 }
00134 
00135 
00136 //==================================================================================
00137 // Function name        : exotkAF_Document::~exotkAF_Document
00138 //==================================================================================
00139 // Written by       : Stephane Routelous - 2001-11-06 16:08:16
00140 // Description      : 
00141 // Return type          : 
00142 //==================================================================================
00143 exotkAF_Document::~exotkAF_Document()
00144 {
00145         if (!myViews.IsNull())
00146                 myViews->Clear();
00147 }
00148 
00149 //==================================================================================
00150 // Function name        : exotkAF_Document::DisplayManager
00151 //==================================================================================
00152 // Written by       : Stephane Routelous - 2001-11-06 16:08:18
00153 // Description      : 
00154 // Return type          : Handle_exotkAIS_DisplayManager 
00155 //==================================================================================
00156 Handle_exotkAIS_DisplayManager exotkAF_Document::DisplayManager()
00157 {
00158         return myDisplayManager;
00159 }
00160 
00161 //==================================================================================
00162 // Function name        : exotkAF_Document::SetName
00163 //==================================================================================
00164 // Written by       : Stephane Routelous - 2001-11-06 16:08:20
00165 // Description      : 
00166 // Return type          : void 
00167 //==================================================================================
00168 // Argument         : const TCollection_AsciiString& aName
00169 void exotkAF_Document::SetName(const TCollection_AsciiString& aName)
00170 {
00171         myName = aName;
00172 }
00173 
00174 //==================================================================================
00175 // Function name        : exotkAF_Document::Name
00176 //==================================================================================
00177 // Written by       : Stephane Routelous - 2001-11-06 16:08:21
00178 // Description      : 
00179 // Return type          : TCollection_AsciiString 
00180 //==================================================================================
00181 TCollection_AsciiString exotkAF_Document::Name()
00182 {
00183         return myName;
00184 }
00185 
00186 
00187 //==================================================================================
00188 // Function name        : exotkAF_Document::Tree
00189 //==================================================================================
00190 // Written by       : Stephane Routelous - 2001-11-20 19:36:29
00191 // Description      : 
00192 // Return type          : Handle_exotkTree_Tree 
00193 //==================================================================================
00194 Handle_exotkTree_Tree exotkAF_Document::Tree()
00195 {
00196         return myTree;
00197 }
00198 //==================================================================================
00199 // Function name        : exotkAF_Document::Init
00200 //==================================================================================
00201 // Written by       : Stephane Routelous - 2001-11-06 16:08:23
00202 // Description      : 
00203 // Return type          : Standard_Boolean 
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 // Function name        : exotkAF_Document::OpenFile
00225 //==================================================================================
00226 // Written by       : Stephane Routelous - 2001-11-06 16:08:25
00227 // Description      : 
00228 // Return type          : Standard_Boolean 
00229 //==================================================================================
00230 // Argument         : const TCollection_AsciiString &aFilename
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 // Function name        : exotkAF_Document::AddShape
00296 //==================================================================================
00297 // Written by       : Stephane Routelous - 2001-11-20 19:29:28
00298 // Description      : 
00299 // Return type          : Standard_Boolean 
00300 //==================================================================================
00301 // Argument         : const TopoDS_Shape &aShapeToAdd
00302 // Argument         : const TCollection_AsciiString& aName
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                 //      myTree->NotifyInsertItem(myTree->Root(),theShapeTopNode,Handle_exotkTree_TreeNode());
00319                         myTree->SetVisible(theShapeTopNode);
00320                 }
00321         }
00322         
00323         return theDocIsOK;
00324 }
00325 
00326 //==================================================================================
00327 // Function name        : exotkAF_Document::CreateView
00328 //==================================================================================
00329 // Written by       : Stephane Routelous - 2001-11-06 16:08:27
00330 // Description      : 
00331 // Return type          : Handle_exotkAF_View 
00332 //==================================================================================
00333 // Argument         : const Aspect_Handle &anHandle
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 // Function name        : exotkAF_Document::AddView
00354 //==================================================================================
00355 // Written by       : Stephane Routelous - 2001-11-06 16:08:30
00356 // Description      : 
00357 // Return type          : Standard_Boolean 
00358 //==================================================================================
00359 // Argument         : const Handle_exotkAF_View &aView
00360 Standard_Boolean exotkAF_Document::AddView(const Handle_exotkAF_View &aView)
00361 {
00362         return myViews->Add(aView);
00363 }
00364 
00365 //==================================================================================
00366 // Function name        : exotkAF_Document::RemoveView
00367 //==================================================================================
00368 // Written by       : Stephane Routelous - 2001-11-06 16:08:32
00369 // Description      : 
00370 // Return type          : Standard_Boolean 
00371 //==================================================================================
00372 // Argument         : const Handle_exotkAF_View &aView
00373 Standard_Boolean exotkAF_Document::RemoveView(const Handle_exotkAF_View &aView)
00374 {
00375         return myViews->Remove(aView);
00376 }
00377 
00378 //==================================================================================
00379 // Function name        : exotkAF_Document::InitViewIterator
00380 //==================================================================================
00381 // Written by       : Stephane Routelous - 2001-11-06 16:08:34
00382 // Description      : 
00383 // Return type          : void 
00384 //==================================================================================
00385 void exotkAF_Document::InitViewIterator()
00386 {
00387         exotkAF_Document_Datas::theViewIterator.Initialize(myViews->Set());
00388 }
00389 
00390 //==================================================================================
00391 // Function name        : exotkAF_Document::MoreViewIterator
00392 //==================================================================================
00393 // Written by       : Stephane Routelous - 2001-11-06 16:08:36
00394 // Description      : 
00395 // Return type          : Standard_Boolean 
00396 //==================================================================================
00397 Standard_Boolean exotkAF_Document::MoreViewIterator()
00398 {
00399         return exotkAF_Document_Datas::theViewIterator.More();
00400 }
00401 
00402 //==================================================================================
00403 // Function name        : exotkAF_Document::NextViewIterator
00404 //==================================================================================
00405 // Written by       : Stephane Routelous - 2001-11-06 16:08:37
00406 // Description      : 
00407 // Return type          : void 
00408 //==================================================================================
00409 void exotkAF_Document::NextViewIterator()
00410 {
00411         exotkAF_Document_Datas::theViewIterator.Next();
00412 }
00413 
00414 //==================================================================================
00415 // Function name        : exotkAF_Document::CurrentViewIterator
00416 //==================================================================================
00417 // Written by       : Stephane Routelous - 2001-11-06 16:08:40
00418 // Description      : 
00419 // Return type          : Handle_exotkAF_View 
00420 //==================================================================================
00421 Handle_exotkAF_View exotkAF_Document::CurrentViewIterator()
00422 {
00423         return exotkAF_Document_Datas::theViewIterator.Value();
00424 }
00425 
00426 //==================================================================================
00427 // Function name        : exotkAF_Document::NbViews
00428 //==================================================================================
00429 // Written by       : Stephane Routelous - 2001-11-06 16:08:42
00430 // Description      : 
00431 // Return type          : Standard_Integer 
00432 //==================================================================================
00433 Standard_Integer exotkAF_Document::NbViews()
00434 {
00435         return myViews->Extent();
00436 }
00437 
00438 
00439 //==================================================================================
00440 // Function name        : exotkAF_Document::SetActiveView
00441 //==================================================================================
00442 // Written by       : Stephane Routelous - 2001-11-27 12:37:00
00443 // Description      : 
00444 // Return type          : Standard_Boolean 
00445 //==================================================================================
00446 // Argument         : const Handle_exotkAF_View& aView
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 // Function name        : exotkAF_Document::ActiveView
00460 //==================================================================================
00461 // Written by       : Stephane Routelous - 2001-11-27 12:37:01
00462 // Description      : 
00463 // Return type          : Handle_exotkAF_View 
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 }

Generated on Wed Jan 23 12:16:39 2002 for exotk by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001