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