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