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