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