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