Salome HOME
22318: [CEA] Problems with study dump in SMESH
[modules/smesh.git] / src / SMESH_I / SMESH_PythonDump.hxx
1 // Copyright (C) 2007-2013  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 _SMESH_PYTHONDUMP_HXX_
24 #define _SMESH_PYTHONDUMP_HXX_
25
26 #include "SMESH.hxx"
27
28 #include <SALOMEconfig.h>
29 #include CORBA_SERVER_HEADER(SMESH_Mesh)
30 #include CORBA_SERVER_HEADER(SALOMEDS)
31
32 #include <TCollection_AsciiString.hxx>
33
34 #include <sstream>
35 #include <vector>
36 #include <set>
37 #include <list>
38
39 class SMESH_Gen_i;
40 class SMESH_MeshEditor_i;
41 class Resource_DataMapOfAsciiStringAsciiString;
42
43 // ===========================================================================================
44 /*!
45  * \brief Tool converting SMESH engine calls into commands defined in smeshBuilder.py
46  *
47  * Implementation is in SMESH_2smeshpy.cxx
48  */
49 // ===========================================================================================
50
51 class SMESH_2smeshpy
52 {
53 public:
54   /*!
55    * \brief Convert a python script using commands of smeshBuilder.py
56    * \param theScript - the Input script to convert
57    * \param theEntry2AccessorMethod - returns method names to access to
58    *        objects wrapped with python class
59    * \param theObjectNames - names of objects
60    * \param theRemovedObjIDs - entries of objects whose created commands were removed
61    * \param theHistoricalDump - true means to keep all commands, false means
62    *        to exclude commands relating to objects removed from study
63    * \retval TCollection_AsciiString - Convertion result
64    */
65   static void
66   ConvertScript(std::list< TCollection_AsciiString >&     theScriptLines,
67                 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
68                 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
69                 std::set< TCollection_AsciiString >&      theRemovedObjIDs,
70                 SALOMEDS::Study_ptr&                      theStudy,
71                 const bool                                theHistoricalDump);
72
73   /*!
74    * \brief Return the name of the python file wrapping IDL API
75     * \retval const char* - the file name
76    */
77   static const char* SmeshpyName() { return "smesh"; }
78   static const char* GenName() { return "smesh"; }
79 };
80
81 namespace SMESH
82 {
83   class FilterLibrary_i;
84   class FilterManager_i;
85   class Filter_i;
86   class Functor_i;
87   class Measurements_i;
88
89   // ===========================================================================================
90   /*!
91    * \brief Object used to make TPythonDump know that its held value can be a varible
92    *
93    * TPythonDump substitute TVar with names of notebook variables if any.
94    */
95   // ===========================================================================================
96
97   struct SMESH_I_EXPORT TVar
98   {
99     std::vector< std::string > myVals;
100     TVar(CORBA::Double value);
101     TVar(CORBA::Long   value);
102     TVar(CORBA::Short  value);
103     TVar(const SMESH::double_array& value);
104     // string used to temporary quote variable names in order
105     // not to confuse variables with string arguments
106     static char Quote() { return '$'; }
107     // string preceding an entry of object storing the attribute holding var names
108     static const char* ObjPrefix() { return " # OBJ: "; }
109   };
110
111   // ===========================================================================================
112   /*!
113    * \brief Utility helping in storing SMESH engine calls as python commands
114    */
115   // ===========================================================================================
116
117   class SMESH_I_EXPORT TPythonDump
118   {
119     std::ostringstream myStream;
120     static size_t      myCounter;
121     int                myVarsCounter; // counts stored TVar's
122   public:
123     TPythonDump();
124     virtual ~TPythonDump();
125
126     TPythonDump&
127     operator<<(const TVar& theVariableValue);
128
129     TPythonDump&
130     operator<<(long int theArg);
131
132     TPythonDump&
133     operator<<(int theArg);
134
135     TPythonDump&
136     operator<<(double theArg);
137
138     TPythonDump&
139     operator<<(float theArg);
140
141     TPythonDump&
142     operator<<(const void* theArg);
143
144     TPythonDump&
145     operator<<(const char* theArg);
146
147     TPythonDump&
148     operator<<(const SMESH::ElementType& theArg);
149
150     TPythonDump&
151     operator<<(const SMESH::GeometryType& theArg);
152
153     TPythonDump&
154     operator<<(const SMESH::EntityType& theArg);
155
156     TPythonDump&
157     operator<<(const SMESH::long_array& theArg);
158
159     TPythonDump&
160     operator<<(const SMESH::double_array& theArg);
161
162     TPythonDump&
163     operator<<(const SMESH::string_array& theArg);
164
165     TPythonDump&
166     operator<<(SMESH::SMESH_Hypothesis_ptr theArg);
167
168     TPythonDump&
169     operator<<(SMESH::SMESH_IDSource_ptr theArg);
170
171     TPythonDump&
172     operator<<(SALOMEDS::SObject_ptr theArg);
173
174     TPythonDump&
175     operator<<(CORBA::Object_ptr theArg);
176
177     TPythonDump&
178     operator<<(SMESH::FilterLibrary_i* theArg);
179
180     TPythonDump&
181     operator<<(SMESH::FilterManager_i* theArg);
182
183     TPythonDump&
184     operator<<(SMESH::Filter_i* theArg);
185
186     TPythonDump&
187     operator<<(SMESH::Functor_i* theArg);
188
189     TPythonDump&
190     operator<<(SMESH::Measurements_i* theArg);
191
192     TPythonDump&
193     operator<<(SMESH_Gen_i* theArg);
194
195     TPythonDump&
196     operator<<(SMESH_MeshEditor_i* theArg);
197
198     TPythonDump&
199     operator<<(SMESH::MED_VERSION theArg);
200
201     TPythonDump&
202     operator<<(const SMESH::AxisStruct & theAxis);
203
204     TPythonDump&
205     operator<<(const SMESH::DirStruct & theDir);
206
207     TPythonDump&
208     operator<<(const SMESH::PointStruct & P);
209
210     TPythonDump&
211     operator<<(const TCollection_AsciiString & theArg);
212
213     TPythonDump&
214     operator<<(const SMESH::ListOfGroups& theList);
215
216     TPythonDump&
217     operator<<(const SMESH::ListOfGroups * theList);
218
219     TPythonDump&
220     operator<<(const SMESH::ListOfIDSources& theList);
221
222     static const char* SMESHGenName() { return "smeshgen"; }
223     static const char* MeshEditorName() { return "mesh_editor"; }
224     static const char* NotPublishedObjectName();
225
226     /*!
227      * \brief Return marker of long string literal beginning
228       * \param type - a name of functionality producing the string literal
229       * \retval TCollection_AsciiString - the marker string to be written into
230       * a raw python script
231      */
232     static TCollection_AsciiString LongStringStart(const char* type);
233     /*!
234      * \brief Return marker of long string literal end
235       * \retval TCollection_AsciiString - the marker string to be written into
236       * a raw python script
237      */
238     static TCollection_AsciiString LongStringEnd();
239     /*!
240      * \brief Cut out a long string literal from a string
241       * \param theText - text possibly containing string literals
242       * \param theFrom - position in the text to search from
243       * \param theLongString - the retrieved literal
244       * \param theStringType - a name of functionality produced the literal
245       * \retval bool - true if a string literal found
246      *
247      * The literal is removed from theText; theFrom points position right after
248      * the removed literal
249      */
250     static bool  CutoutLongString( TCollection_AsciiString & theText,
251                                    int                     & theFrom,
252                                    TCollection_AsciiString & theLongString,
253                                    TCollection_AsciiString & theStringType);
254   };
255 }
256
257 #endif