1 // Copyright (C) 2007-2012 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.
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(SALOMEDS)
37 class SMESH_MeshEditor_i;
38 class TCollection_AsciiString;
39 class Resource_DataMapOfAsciiStringAsciiString;
41 // ===========================================================================================
43 * \brief Tool converting SMESH engine calls into commands defined in smeshDC.py
45 * Implementation is in SMESH_2smeshpy.cxx
47 // ===========================================================================================
53 * \brief Convert a python script using commands of smesh.py
54 * \param theScript - Input script
55 * \param theEntry2AccessorMethod - returns method names to access to
56 * objects wrapped with python class
57 * \param theObjectNames - names of objects
58 * \param theRemovedObjIDs - entries of objects whose created commands were removed
59 * \param theHistoricalDump - true means to keep all commands, false means
60 * to exclude commands relating to objects removed from study
61 * \retval TCollection_AsciiString - Convertion result
63 static TCollection_AsciiString
64 ConvertScript(const TCollection_AsciiString& theScript,
65 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
66 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
67 std::set< TCollection_AsciiString >& theRemovedObjIDs,
68 SALOMEDS::Study_ptr& theStudy,
69 const bool theHistoricalDump);
72 * \brief Return the name of the python file wrapping IDL API
73 * \retval const char* - the file name
75 static const char* SmeshpyName() { return "smesh"; }
76 static const char* GenName() { return "smesh"; }
81 class FilterLibrary_i;
82 class FilterManager_i;
87 // ===========================================================================================
89 * \brief Object used to make TPythonDump know that its held value can be a varible
91 * TPythonDump substitute TVar with names of notebook variables if any.
93 // ===========================================================================================
95 struct SMESH_I_EXPORT TVar
97 std::vector< std::string > myVals;
98 TVar(CORBA::Double value);
99 TVar(CORBA::Long value);
100 TVar(CORBA::Short value);
101 TVar(const SMESH::double_array& value);
102 // string used to temporary quote variable names in order
103 // not to confuse variables with string arguments
104 static char Quote() { return '$'; }
107 // ===========================================================================================
109 * \brief Utility helping in storing SMESH engine calls as python commands
111 // ===========================================================================================
113 class SMESH_I_EXPORT TPythonDump
115 std::ostringstream myStream;
116 static size_t myCounter;
117 int myVarsCounter; // counts stored TVar's
120 virtual ~TPythonDump();
123 operator<<(const TVar& theVariableValue);
126 operator<<(long int theArg);
129 operator<<(int theArg);
132 operator<<(double theArg);
135 operator<<(float theArg);
138 operator<<(const void* theArg);
141 operator<<(const char* theArg);
144 operator<<(const SMESH::ElementType& theArg);
147 operator<<(const SMESH::GeometryType& theArg);
150 operator<<(const SMESH::EntityType& theArg);
153 operator<<(const SMESH::long_array& theArg);
156 operator<<(const SMESH::double_array& theArg);
159 operator<<(const SMESH::string_array& theArg);
162 operator<<(SMESH::SMESH_Hypothesis_ptr theArg);
165 operator<<(SMESH::SMESH_IDSource_ptr theArg);
168 operator<<(SALOMEDS::SObject_ptr theArg);
171 operator<<(CORBA::Object_ptr theArg);
174 operator<<(SMESH::FilterLibrary_i* theArg);
177 operator<<(SMESH::FilterManager_i* theArg);
180 operator<<(SMESH::Filter_i* theArg);
183 operator<<(SMESH::Functor_i* theArg);
186 operator<<(SMESH::Measurements_i* theArg);
189 operator<<(SMESH_Gen_i* theArg);
192 operator<<(SMESH_MeshEditor_i* theArg);
195 operator<<(SMESH::MED_VERSION theArg);
198 operator<<(const SMESH::AxisStruct & theAxis);
201 operator<<(const SMESH::DirStruct & theDir);
204 operator<<(const SMESH::PointStruct & P);
207 operator<<(const TCollection_AsciiString & theArg);
210 operator<<(const SMESH::ListOfGroups& theList);
213 operator<<(const SMESH::ListOfGroups * theList);
216 operator<<(const SMESH::ListOfIDSources& theList);
218 static const char* SMESHGenName() { return "smeshgen"; }
219 static const char* MeshEditorName() { return "mesh_editor"; }
220 static const char* NotPublishedObjectName();
223 * \brief Return marker of long string literal beginning
224 * \param type - a name of functionality producing the string literal
225 * \retval TCollection_AsciiString - the marker string to be written into
226 * a raw python script
228 static TCollection_AsciiString LongStringStart(const char* type);
230 * \brief Return marker of long string literal end
231 * \retval TCollection_AsciiString - the marker string to be written into
232 * a raw python script
234 static TCollection_AsciiString LongStringEnd();
236 * \brief Cut out a long string literal from a string
237 * \param theText - text possibly containing string literals
238 * \param theFrom - position in the text to search from
239 * \param theLongString - the retrieved literal
240 * \param theStringType - a name of functionality produced the literal
241 * \retval bool - true if a string literal found
243 * The literal is removed from theText; theFrom points position right after
244 * the removed literal
246 static bool CutoutLongString( TCollection_AsciiString & theText,
248 TCollection_AsciiString & theLongString,
249 TCollection_AsciiString & theStringType);