1 // Copyright (C) 2007-2008 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
22 // File : SMESH_smesh.hxx
23 // Created : Fri Nov 18 12:05:18 2005
24 // Author : Edward AGAPOV (eap)
26 #ifndef SMESH_smesh_HeaderFile
27 #define SMESH_smesh_HeaderFile
29 #include <Standard_DefineHandle.hxx>
30 #include <Standard_Type.hxx>
31 #include <Standard_Transient.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <TColStd_SequenceOfAsciiString.hxx>
34 #include <TColStd_SequenceOfInteger.hxx>
39 // ===========================================================================================
41 * This file was created in order to respond to requirement of bug PAL10494:
42 * SMESH python dump uses idl interface.
44 * The creation reason is that smesh.py commands defining hypotheses encapsulate
45 * several SMESH engine method calls. As well, the dependencies between smesh.py
46 * classes differ from ones between corresponding SMESH IDL interfaces.
48 * Everything here is for internal usage by SMESH_2smeshpy::ConvertScript()
49 * declared in SMESH_PythonDump.hxx
51 * See comments to _pyHypothesis class to know how to assure convertion of a new
54 // ===========================================================================================
56 class Resource_DataMapOfAsciiStringAsciiString;
58 // ===========================================================================================
59 // =====================
61 // =====================
62 // ===========================================================================================
71 DEFINE_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
72 DEFINE_STANDARD_HANDLE (_pyObject ,Standard_Transient);
73 DEFINE_STANDARD_HANDLE (_pyGen ,_pyObject);
74 DEFINE_STANDARD_HANDLE (_pyMesh ,_pyObject);
75 DEFINE_STANDARD_HANDLE (_pyMeshEditor,_pyObject);
76 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
77 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
79 typedef TCollection_AsciiString _pyID;
81 // ===========================================================
83 * \brief Class operating on a command string looking like
84 * ResultValue = Object.Method( Arg1, Arg2,...)
86 // ===========================================================
88 class _pyCommand: public Standard_Transient
90 int myOrderNb; //!< position within the script
91 TCollection_AsciiString myString; //!< command text
92 TCollection_AsciiString myRes, myObj, myMeth; //!< found parts of command
93 TColStd_SequenceOfAsciiString myArgs; //!< found arguments
94 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
95 std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
97 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
98 int GetBegPos( int thePartIndex );
99 void SetBegPos( int thePartIndex, int thePosition );
100 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
101 TCollection_AsciiString& theOldPart);
102 void FindAllArgs() { GetArg(1); }
106 _pyCommand( const TCollection_AsciiString& theString, int theNb )
107 : myString( theString ), myOrderNb( theNb ) {};
108 TCollection_AsciiString & GetString() { return myString; }
109 int GetOrderNb() const { return myOrderNb; }
110 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
111 int Length() { return myString.Length(); }
112 void Clear() { myString.Clear(); myBegPos.Clear(); }
113 bool IsEmpty() const { return myString.IsEmpty(); }
114 TCollection_AsciiString GetIndentation();
115 const TCollection_AsciiString & GetResultValue();
116 const int GetNbResultValues();
117 const TCollection_AsciiString & GetResultValue(int res);
118 const TCollection_AsciiString & GetObject();
119 const TCollection_AsciiString & GetMethod();
120 const TCollection_AsciiString & GetArg( int index );
121 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
122 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
123 void SetResultValue( const TCollection_AsciiString& theResult )
124 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
125 void SetObject(const TCollection_AsciiString& theObject)
126 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
127 void SetMethod(const TCollection_AsciiString& theMethod)
128 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
129 void SetArg( int index, const TCollection_AsciiString& theArg);
131 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
132 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
133 int & theStartPos, const bool theForward,
134 const bool dotIsWord = false);
135 void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
136 { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
137 bool SetDependentCmdsAfter() const;
139 bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
141 DEFINE_STANDARD_RTTI (_pyCommand)
144 // -------------------------------------------------------------------------------------
146 * \brief Root of all objects
148 // -------------------------------------------------------------------------------------
150 class _pyObject: public Standard_Transient
152 Handle(_pyCommand) myCreationCmd;
154 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
155 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
156 static _pyID FatherID(const _pyID & childID);
157 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
158 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
159 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
160 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
161 virtual void Flush() = 0;
162 virtual const char* AccessorMethod() const;
164 DEFINE_STANDARD_RTTI (_pyObject)
167 // -------------------------------------------------------------------------------------
169 * \brief Class corresponding to SMESH_Gen. It holds info on existing
170 * meshes and hypotheses
172 // -------------------------------------------------------------------------------------
173 class _pyGen: public _pyObject
176 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
178 Handle(_pyCommand) AddCommand( const TCollection_AsciiString& theCommand );
179 void Process( const Handle(_pyCommand)& theCommand );
181 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
182 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
183 const Handle(_pyHypothesis)& theHypothesis);
184 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
185 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
186 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
187 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
188 bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
189 bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
190 const char* AccessorMethod() const;
192 std::map< _pyID, Handle(_pyMesh) > myMeshes;
193 std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
194 std::list< Handle(_pyHypothesis) > myHypos;
195 std::list< Handle(_pyCommand) > myCommands;
198 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
200 DEFINE_STANDARD_RTTI (_pyGen)
203 // -------------------------------------------------------------------------------------
205 * \brief Contains commands concerning mesh substructures
207 // -------------------------------------------------------------------------------------
208 #define _pyMesh_ACCESS_METHOD "GetMesh()"
209 class _pyMesh: public _pyObject
211 std::list< Handle(_pyHypothesis) > myHypos;
212 std::list< Handle(_pyCommand) > myAddHypCmds;
213 std::list< Handle(_pyCommand) > mySubmeshes;
216 _pyMesh(const Handle(_pyCommand) creationCmd);
217 _pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString & id);
218 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
219 void Process( const Handle(_pyCommand)& theCommand);
221 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
223 static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
224 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
225 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
227 //friend class _pyMeshEditor;
228 DEFINE_STANDARD_RTTI (_pyMesh)
230 #undef _pyMesh_ACCESS_METHOD
232 // -------------------------------------------------------------------------------------
234 * \brief MeshEditor convert its commands to ones of mesh
236 // -------------------------------------------------------------------------------------
237 class _pyMeshEditor: public _pyObject
240 TCollection_AsciiString myCreationCmdStr;
242 _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
243 void Process( const Handle(_pyCommand)& theCommand);
244 virtual void Flush() {}
246 DEFINE_STANDARD_RTTI (_pyMesh)
249 // -------------------------------------------------------------------------------------
251 * \brief Root class for hypothesis
253 * HOWTO assure convertion of a new type of hypothesis
254 * In _pyHypothesis::NewHypothesis():
255 * 1. add a case for the name of the new hypothesis
256 * 2. use SetConvMethodAndType() to set
257 * . for algo: algorithm name and method of Mesh creating the algo
258 * . for hypo: name of the algorithm and method creating the hypothesis
259 * 3. append to myArgMethods interface methods setting param values in the
260 * order they are used when creation method is called. If arguments of
261 * the creation method can't be easily got from calls of hypothesis methods, you are
262 * to derive a specific class from _pyHypothesis that would redefine Process(),
263 * see _pyComplexParamHypo for example
265 // -------------------------------------------------------------------------------------
266 class _pyHypothesis: public _pyObject
269 bool myIsAlgo, myIsWrapped;
270 _pyID myGeom, myMesh;
271 // a hypothesis can be used and created by different algos by different methods
272 std::map<TCollection_AsciiString, TCollection_AsciiString > myType2CreationMethod;
273 //TCollection_AsciiString myCreationMethod, myType;
274 TColStd_SequenceOfAsciiString myArgs; // creation arguments
275 TColStd_SequenceOfAsciiString myArgMethods; // hypo methods setting myArgs
276 TColStd_SequenceOfInteger myNbArgsByMethod; // nb args set by each method
277 std::list<Handle(_pyCommand)> myArgCommands;
278 std::list<Handle(_pyCommand)> myUnknownCommands;
280 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
281 void SetConvMethodAndType(const char* creationMethod, const char* type)
282 { myType2CreationMethod[ (char*)type ] = (char*)creationMethod; }
283 void AddArgMethod(const char* method, const int nbArgs = 1)
284 { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
285 const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
286 const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
287 void ClearAllCommands();
288 virtual bool IsAlgo() const { return myIsAlgo; }
289 bool IsValid() const { return !myType2CreationMethod.empty(); }
290 bool IsWrapped() const { return myIsWrapped; }
291 const _pyID & GetGeom() const { return myGeom; }
292 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
293 const _pyID & GetMesh() const { return myMesh; }
294 const TCollection_AsciiString& GetAlgoType() const
295 { return myType2CreationMethod.begin()->first; }
296 const TCollection_AsciiString& GetAlgoCreationMethod() const
297 { return myType2CreationMethod.begin()->second; }
298 bool CanBeCreatedBy(const TCollection_AsciiString& algoType ) const
299 { return myType2CreationMethod.find( algoType ) != myType2CreationMethod.end(); }
300 const TCollection_AsciiString& GetCreationMethod(const TCollection_AsciiString& algoType) const
301 { return myType2CreationMethod.find( algoType )->second; }
302 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
303 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
304 const _pyID& theMesh);
305 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
306 void Process( const Handle(_pyCommand)& theCommand);
309 DEFINE_STANDARD_RTTI (_pyHypothesis)
312 // -------------------------------------------------------------------------------------
314 * \brief Class representing smesh.Mesh_Algorithm
316 // -------------------------------------------------------------------------------------
317 class _pyAlgorithm: public _pyHypothesis
320 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
321 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
322 const _pyID& theMesh);
323 const char* AccessorMethod() const { return "GetAlgorithm()"; }
325 DEFINE_STANDARD_RTTI (_pyAlgorithm)
328 // -------------------------------------------------------------------------------------
330 * \brief Class for hypotheses having several parameters modified by one method
332 // -------------------------------------------------------------------------------------
333 class _pyComplexParamHypo: public _pyHypothesis
336 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
337 void Process( const Handle(_pyCommand)& theCommand);
339 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
341 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
343 // -------------------------------------------------------------------------------------
345 * \brief Class for LayerDistribution hypothesis conversion
347 // -------------------------------------------------------------------------------------
348 class _pyLayerDistributionHypo: public _pyHypothesis
350 Handle(_pyHypothesis) my1dHyp;
352 _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd):
353 _pyHypothesis(theCreationCmd) {}
354 void Process( const Handle(_pyCommand)& theCommand);
356 bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
357 const _pyID& theMesh);
359 DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
361 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
363 // -------------------------------------------------------------------------------------
365 * \brief Class representing NumberOfSegments hypothesis
367 // -------------------------------------------------------------------------------------
368 class _pyNumberOfSegmentsHyp: public _pyHypothesis
371 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
372 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
373 const _pyID& theMesh);
376 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
378 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
380 // -------------------------------------------------------------------------------------
382 * \brief Class representing SegmentLengthAroundVertex hypothesis
384 // -------------------------------------------------------------------------------------
385 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
388 _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
389 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
390 const _pyID& theMesh);
391 DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
393 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);