Salome HOME
0021672: [CEA 565] Dump Study from script
[modules/geom.git] / src / GEOM / GEOM_Engine.hxx
1 // Copyright (C) 2007-2012  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
23 #ifndef _GEOM_Engine_HXX_
24 #define _GEOM_Engine_HXX_
25
26 #include "GEOM_Application.hxx"
27 #include "GEOM_Object.hxx"
28 #include "GEOM_DataMapOfAsciiStringTransient.hxx"
29
30 #include <Basics_OCCTVersion.hxx>
31
32 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
33 #include <TColStd_DataMapOfIntegerTransient.hxx>
34 #else
35 #include <Interface_DataMapOfIntegerTransient.hxx>
36 #endif
37
38 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
39 #include <TDocStd_Document.hxx>
40 #include <TColStd_HArray1OfInteger.hxx>
41 #include <TColStd_HSequenceOfAsciiString.hxx>
42 #include <TDF_Label.hxx>
43
44 #include <map>
45 #include <list>
46 #include <vector>
47 #include <string>
48
49 /*!
50  * \brief Data of GEOM_Object
51  */
52 struct TObjectData
53 {
54   TCollection_AsciiString _entry;
55   TCollection_AsciiString _studyEntry;
56   TCollection_AsciiString _name;
57   TCollection_AsciiString _pyName;
58   bool                    _unpublished;
59 };
60   
61 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
62 class Handle_TColStd_HArray1OfByte;
63 #else
64 class Handle_TDataStd_HArray1OfByte;
65 #endif
66
67 struct TVariable{
68   TCollection_AsciiString myVariable;
69   bool isVariable;
70
71   TVariable(const TCollection_AsciiString& theVariable, bool theFlag = true):
72     myVariable(theVariable),
73     isVariable(theFlag){}
74 };
75
76 typedef std::vector<TVariable> TState;
77 typedef std::vector<TState>    TAllStates;
78
79 class ObjectStates
80 {
81 public:
82   Standard_EXPORT ObjectStates();
83   ~ObjectStates();
84
85   TAllStates GetAllStates() const { return _states; }
86
87   TState GetCurrectState() const;
88   Standard_EXPORT void AddState(const TState &theState);
89   void IncrementState();
90
91 private:
92   TAllStates              _states;
93   int                     _dumpstate;
94 };
95
96 typedef std::map<TCollection_AsciiString, ObjectStates* > TVariablesList;
97
98 typedef std::map<int, std::list<TDF_Label> > TFreeLabelsList;
99
100 class GEOM_Engine
101 {
102  public:
103   Standard_EXPORT GEOM_Engine();
104   Standard_EXPORT virtual ~GEOM_Engine();
105
106   //Retuns the engine    
107   Standard_EXPORT static GEOM_Engine* GetEngine();   
108
109   //Returns the OCAF document by its ID, if document doesn't exists it will be created
110   Standard_EXPORT Handle(TDocStd_Document) GetDocument(int theDocID, bool force=true);
111
112   //Returns the ID of the given OCAF document
113   Standard_EXPORT int GetDocID(Handle(TDocStd_Document) theDocument);
114   
115   //Returns the OCAF appliaction
116   Standard_EXPORT Handle(TDocStd_Application) GetApplication() { return _OCAFApp; }
117
118   //Returns a pointer to GEOM_Object defined by a document and the entry
119   Standard_EXPORT Handle(GEOM_Object) GetObject(int theDocID, char* theEntry, bool force=true);
120   
121   //Adds a new object of the type theType in the OCAF document
122   Standard_EXPORT Handle(GEOM_Object) AddObject(int theDocID, int theType);
123
124   //Removes the object from the OCAF document
125   Standard_EXPORT bool RemoveObject(Handle(GEOM_Object) theObject);  
126
127   //Saves the OCAF document with ID = theDocID with file with name theFileName
128   Standard_EXPORT bool Save(int theDocID, char* theFileName);
129   
130   //Loads the OCAF document into the application and assigns to it an ID = theDocID
131   Standard_EXPORT bool Load(int theDocID, char* theFileName);
132
133   //Closes the document with ID =  theDocID
134   Standard_EXPORT void Close(int theDocID);
135
136   //Sets the number of Undos (default value = 10)
137   Standard_EXPORT void SetUndoLimit(int theLimit) { _UndoLimit = theLimit; }
138
139   //Applies an Undo to document with ID = theDocID
140   Standard_EXPORT void Undo(int theDocID);
141
142   //Applies an Redo to document with ID = theDocID
143   Standard_EXPORT void Redo(int theDocID);
144
145   //Adds a new sub-shape object of the MainShape object
146   Standard_EXPORT Handle(GEOM_Object) AddSubShape(Handle(GEOM_Object) theMainShape, 
147                                   Handle(TColStd_HArray1OfInteger) theIndices,
148                                   bool isStandaloneOperation = false);
149
150   Standard_EXPORT TCollection_AsciiString DumpPython(int theDocID, 
151                                                      std::vector<TObjectData>& theObjectData,
152                                                      TVariablesList theVariables,
153                                                      bool isPublished, 
154                                                      bool isMultiFile, 
155                                                      bool& aValidScript);
156
157   Standard_EXPORT const char* GetDumpName (const char* theStudyEntry) const;
158
159   Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) GetAllDumpNames() const;
160
161   Standard_EXPORT int addTexture(int theDocID, int theWidth, int theHeight,
162 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
163                                  const Handle(TColStd_HArray1OfByte)& theTexture,
164 #else
165                                  const Handle(TDataStd_HArray1OfByte)& theTexture,
166 #endif
167                                  const TCollection_AsciiString& theFileName = "");
168
169 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
170   Standard_EXPORT Handle(TColStd_HArray1OfByte) getTexture(int theDocID, int theTextureID,
171 #else
172   Standard_EXPORT Handle(TDataStd_HArray1OfByte) getTexture(int theDocID, int theTextureID,
173 #endif
174                                                            int& theWidth, int& theHeight,
175                                                            TCollection_AsciiString& theFileName);
176
177   Standard_EXPORT std::list<int> getAllTextures(int theDocID);
178
179   static const Standard_GUID& GetTextureGUID();
180
181  protected:
182   Standard_EXPORT static void SetEngine(GEOM_Engine* theEngine);       
183   
184  private:
185
186   Handle(GEOM_Application)  _OCAFApp;
187 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
188   TColStd_DataMapOfIntegerTransient _mapIDDocument;
189 #else
190   Interface_DataMapOfIntegerTransient _mapIDDocument;
191 #endif
192   int _UndoLimit;
193   GEOM_DataMapOfAsciiStringTransient _objects;
194
195   Resource_DataMapOfAsciiStringAsciiString _studyEntry2NameMap;
196
197   TFreeLabelsList _freeLabels;
198 };
199
200 #endif