Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / src / GEOM / GEOM_Engine.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef _GEOM_Engine_HXX_
23 #define _GEOM_Engine_HXX_
24
25 #include "GEOM_Application.hxx"
26 #include "GEOM_Object.hxx"
27 #include "GEOM_DataMapOfAsciiStringTransient.hxx"
28
29 #include <Interface_DataMapOfIntegerTransient.hxx> 
30 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
31 #include <TDocStd_Document.hxx>
32 #include <TColStd_HArray1OfInteger.hxx>
33 #include <TColStd_HSequenceOfAsciiString.hxx>
34 #include <TDF_Label.hxx>
35
36 #include <map>
37 #include <vector>
38
39 struct TVariable{
40   TCollection_AsciiString myVariable;
41   bool isVariable;
42
43   TVariable(const TCollection_AsciiString& theVariable, bool theFlag = true):
44     myVariable(theVariable),
45     isVariable(theFlag){}
46 };
47
48 typedef std::vector<TVariable> TState;
49 typedef std::vector<TState>    TAllStates;
50
51 class ObjectStates
52 {
53 public:
54   ObjectStates();
55   ~ObjectStates();
56
57   TAllStates GetAllStates() const { return _states; }
58
59   TState GetCurrectState() const;
60   void AddState(const TState &theState);
61   void IncrementState();
62
63 private:
64   TAllStates              _states;
65   int                     _dumpstate;
66 };
67
68 typedef std::map<TCollection_AsciiString, ObjectStates* > TVariablesList;
69
70 class GEOM_Engine
71 {
72  public:
73   Standard_EXPORT GEOM_Engine();
74   Standard_EXPORT virtual ~GEOM_Engine();
75
76   //Retuns the engine    
77   Standard_EXPORT static GEOM_Engine* GetEngine();   
78
79   //Returns the OCAF document by its ID, if document doesn't exists it will be created
80   Standard_EXPORT Handle(TDocStd_Document) GetDocument(int theDocID);
81
82   //Returns the ID of the given OCAF document
83   Standard_EXPORT int GetDocID(Handle(TDocStd_Document) theDocument);
84   
85   //Returns the OCAF appliaction
86   Standard_EXPORT Handle(TDocStd_Application) GetApplication() { return _OCAFApp; }
87
88   //Returns a pointer to GEOM_Object defined by a document and the entry
89   Standard_EXPORT Handle(GEOM_Object) GetObject(int theDocID, char* theEntry);
90   
91   //Adds a new object of the type theType in the OCAF document
92   Standard_EXPORT Handle(GEOM_Object) AddObject(int theDocID, int theType);
93
94   //Removes the object from the OCAF document
95   Standard_EXPORT bool RemoveObject(Handle(GEOM_Object) theObject);  
96
97   //Saves the OCAF document with ID = theDocID with file with name theFileName
98   Standard_EXPORT bool Save(int theDocID, char* theFileName);
99   
100   //Loads the OCAF document into the application and assigns to it an ID = theDocID
101   Standard_EXPORT bool Load(int theDocID, char* theFileName);
102
103   //Closes the document with ID =  theDocID
104   Standard_EXPORT void Close(int theDocID);
105
106   //Sets the number of Undos (default value = 10)
107   Standard_EXPORT void SetUndoLimit(int theLimit) { _UndoLimit = theLimit; }
108
109   //Applies an Undo to document with ID = theDocID
110   Standard_EXPORT void Undo(int theDocID);
111
112   //Applies an Redo to document with ID = theDocID
113   Standard_EXPORT void Redo(int theDocID);
114
115   //Adds a new sub shape object of the MainShape object
116   Standard_EXPORT Handle(GEOM_Object) AddSubShape(Handle(GEOM_Object) theMainShape, 
117                                   Handle(TColStd_HArray1OfInteger) theIndices,
118                                   bool isStandaloneOperation = false);
119
120   Standard_EXPORT TCollection_AsciiString DumpPython(int theDocID, 
121                                      Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
122                                      TVariablesList theVariables,
123                                      bool isPublished, 
124                                      bool& aValidScript);
125
126   Standard_EXPORT const char* GetDumpName (const char* theStudyEntry) const;
127
128   Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) GetAllDumpNames() const;
129
130  protected:
131   Standard_EXPORT static void SetEngine(GEOM_Engine* theEngine);       
132   
133  private:
134
135   Handle(GEOM_Application)  _OCAFApp;
136   Interface_DataMapOfIntegerTransient _mapIDDocument;
137   int _UndoLimit;
138   GEOM_DataMapOfAsciiStringTransient _objects;
139
140   Resource_DataMapOfAsciiStringAsciiString _studyEntry2NameMap;
141
142   TDF_Label _lastCleared;
143 };
144
145 #endif