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