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