1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef _SMESH_PYTHONDUMP_HXX_
24 #define _SMESH_PYTHONDUMP_HXX_
28 #include <SALOMEconfig.h>
29 #include CORBA_SERVER_HEADER(SMESH_Mesh)
30 #include CORBA_SERVER_HEADER(GEOM_Gen)
31 #include CORBA_SERVER_HEADER(SALOMEDS)
33 #include <TCollection_AsciiString.hxx>
41 class SMESH_MeshEditor_i;
42 class Resource_DataMapOfAsciiStringAsciiString;
44 // ===========================================================================================
46 * \brief Tool converting SMESH engine calls into commands defined in smeshBuilder.py
48 * Implementation is in SMESH_2smeshpy.cxx
50 // ===========================================================================================
56 * \brief Convert a python script using commands of smeshBuilder.py
57 * \param theScript - the Input script to convert
58 * \param theEntry2AccessorMethod - returns method names to access to
59 * objects wrapped with python class
60 * \param theObjectNames - names of objects
61 * \param theRemovedObjIDs - entries of objects whose created commands were removed
62 * \param theHistoricalDump - true means to keep all commands, false means
63 * to exclude commands relating to objects removed from study
64 * \retval TCollection_AsciiString - Convertion result
67 ConvertScript(std::list< TCollection_AsciiString >& theScriptLines,
68 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
69 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
70 std::set< TCollection_AsciiString >& theRemovedObjIDs,
71 SALOMEDS::Study_ptr& theStudy,
72 const bool theHistoricalDump);
75 * \brief Return the name of the python file wrapping IDL API
76 * \retval const char* - the file name
78 static const char* SmeshpyName() { return "smesh"; }
79 static const char* GenName() { return "smesh"; }
84 class FilterLibrary_i;
85 class FilterManager_i;
90 // ===========================================================================================
92 * \brief Object used to make TPythonDump know that its held value can be a varible
94 * TPythonDump substitute TVar with names of notebook variables if any.
96 // ===========================================================================================
98 struct SMESH_I_EXPORT TVar
100 std::vector< std::string > myVals;
101 TVar(CORBA::Double value);
102 TVar(CORBA::Long value);
103 TVar(CORBA::Short value);
104 TVar(const SMESH::double_array& value);
105 // string used to temporary quote variable names in order
106 // not to confuse variables with string arguments
107 static char Quote() { return '$'; }
108 // string preceding an entry of object storing the attribute holding var names
109 static const char* ObjPrefix() { return " # OBJ: "; }
112 // ===========================================================================================
114 * \brief Utility helping in storing SMESH engine calls as python commands
116 // ===========================================================================================
118 class SMESH_I_EXPORT TPythonDump
120 std::ostringstream myStream;
121 static size_t myCounter;
122 int myVarsCounter; // counts stored TVar's
125 virtual ~TPythonDump();
128 operator<<(const TVar& theVariableValue);
131 operator<<(long int theArg);
134 operator<<(int theArg);
137 operator<<(double theArg);
140 operator<<(float theArg);
143 operator<<(const void* theArg);
146 operator<<(const char* theArg);
149 operator<<(const SMESH::ElementType& theArg);
152 operator<<(const SMESH::GeometryType& theArg);
155 operator<<(const SMESH::EntityType& theArg);
158 operator<<(const SMESH::long_array& theArg);
161 operator<<(const SMESH::double_array& theArg);
164 operator<<(const SMESH::string_array& theArg);
167 operator<<(const SMESH::nodes_array& theArg);
170 operator<<(SMESH::SMESH_Hypothesis_ptr theArg);
173 operator<<(SMESH::SMESH_IDSource_ptr theArg);
176 operator<<(SALOMEDS::SObject_ptr theArg);
179 operator<<(CORBA::Object_ptr theArg);
182 operator<<(SMESH::FilterLibrary_i* theArg);
185 operator<<(SMESH::FilterManager_i* theArg);
188 operator<<(SMESH::Filter_i* theArg);
191 operator<<(SMESH::Functor_i* theArg);
194 operator<<(SMESH::Measurements_i* theArg);
197 operator<<(SMESH_Gen_i* theArg);
200 operator<<(SMESH_MeshEditor_i* theArg);
203 operator<<(SMESH::MED_VERSION theArg);
206 operator<<(const SMESH::AxisStruct & theAxis);
209 operator<<(const SMESH::DirStruct & theDir);
212 operator<<(const SMESH::PointStruct & P);
215 operator<<(const TCollection_AsciiString & theArg);
218 operator<<(const SMESH::ListOfGroups& theList);
221 operator<<(const SMESH::ListOfGroups * theList);
224 operator<<(const GEOM::ListOfGO& theList);
227 operator<<(const GEOM::ListOfGBO& theList);
230 operator<<(const SMESH::ListOfIDSources& theList);
232 static const char* SMESHGenName() { return "smeshgen"; }
233 static const char* MeshEditorName() { return "mesh_editor"; }
234 static const char* NotPublishedObjectName();
237 * \brief Return marker of long string literal beginning
238 * \param type - a name of functionality producing the string literal
239 * \retval TCollection_AsciiString - the marker string to be written into
240 * a raw python script
242 static TCollection_AsciiString LongStringStart(const char* type);
244 * \brief Return marker of long string literal end
245 * \retval TCollection_AsciiString - the marker string to be written into
246 * a raw python script
248 static TCollection_AsciiString LongStringEnd();
250 * \brief Cut out a long string literal from a string
251 * \param theText - text possibly containing string literals
252 * \param theFrom - position in the text to search from
253 * \param theLongString - the retrieved literal
254 * \param theStringType - a name of functionality produced the literal
255 * \retval bool - true if a string literal found
257 * The literal is removed from theText; theFrom points position right after
258 * the removed literal
260 static bool CutoutLongString( TCollection_AsciiString & theText,
262 TCollection_AsciiString & theLongString,
263 TCollection_AsciiString & theStringType);