1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESH_smesh.hxx
21 // Created : Fri Nov 18 12:05:18 2005
22 // Author : Edward AGAPOV (eap)
24 #ifndef SMESH_smesh_HeaderFile
25 #define SMESH_smesh_HeaderFile
27 #include <Standard_DefineHandle.hxx>
28 #include <Standard_Type.hxx>
29 #include <Standard_Transient.hxx>
30 #include <TCollection_AsciiString.hxx>
31 #include <TColStd_SequenceOfAsciiString.hxx>
32 #include <TColStd_SequenceOfInteger.hxx>
37 // ===========================================================================================
39 * This file was created in order to respond to requirement of bug PAL10494:
40 * SMESH python dump uses idl interface.
42 * The creation reason is that smesh.py commands defining hypotheses encapsulate
43 * several SMESH engine method calls. As well, the dependencies between smesh.py
44 * classes differ from ones between corresponding SMESH IDL interfaces.
46 * Everything here is for internal usage by SMESH_2smeshpy::ConvertScript()
47 * declared in SMESH_PythonDump.hxx
49 * See comments to _pyHypothesis class to know how to assure convertion of a new
52 // ===========================================================================================
54 class Resource_DataMapOfAsciiStringAsciiString;
56 // ===========================================================================================
57 // =====================
59 // =====================
60 // ===========================================================================================
69 DEFINE_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
70 DEFINE_STANDARD_HANDLE (_pyObject ,Standard_Transient);
71 DEFINE_STANDARD_HANDLE (_pyGen ,_pyObject);
72 DEFINE_STANDARD_HANDLE (_pyMesh ,_pyObject);
73 DEFINE_STANDARD_HANDLE (_pyMeshEditor,_pyObject);
74 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
75 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
77 typedef TCollection_AsciiString _pyID;
79 // ===========================================================
81 * \brief Class operating on a command string looking like
82 * ResultValue = Object.Method( Arg1, Arg2,...)
84 // ===========================================================
86 class _pyCommand: public Standard_Transient
88 int myOrderNb; //!< position within the script
89 TCollection_AsciiString myString; //!< command text
90 TCollection_AsciiString myRes, myObj, myMeth; //!< found parts of command
91 TColStd_SequenceOfAsciiString myArgs; //!< found arguments
92 TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
93 std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script
95 enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
96 int GetBegPos( int thePartIndex );
97 void SetBegPos( int thePartIndex, int thePosition );
98 void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
99 TCollection_AsciiString& theOldPart);
100 void FindAllArgs() { GetArg(1); }
104 _pyCommand( const TCollection_AsciiString& theString, int theNb )
105 : myString( theString ), myOrderNb( theNb ) {};
106 TCollection_AsciiString & GetString() { return myString; }
107 int GetOrderNb() const { return myOrderNb; }
108 void SetOrderNb( int theNb ) { myOrderNb = theNb; }
109 int Length() { return myString.Length(); }
110 void Clear() { myString.Clear(); myBegPos.Clear(); }
111 bool IsEmpty() const { return myString.IsEmpty(); }
112 TCollection_AsciiString GetIndentation();
113 const TCollection_AsciiString & GetResultValue();
114 const int GetNbResultValues();
115 const TCollection_AsciiString & GetResultValue(int res);
116 const TCollection_AsciiString & GetObject();
117 const TCollection_AsciiString & GetMethod();
118 const TCollection_AsciiString & GetArg( int index );
119 int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
120 //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
121 void SetResultValue( const TCollection_AsciiString& theResult )
122 { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
123 void SetObject(const TCollection_AsciiString& theObject)
124 { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
125 void SetMethod(const TCollection_AsciiString& theMethod)
126 { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
127 void SetArg( int index, const TCollection_AsciiString& theArg);
129 static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
130 static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
131 int & theStartPos, const bool theForward,
132 const bool dotIsWord = false);
133 void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
134 { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
135 bool SetDependentCmdsAfter() const;
137 bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
139 DEFINE_STANDARD_RTTI (_pyCommand)
142 // -------------------------------------------------------------------------------------
144 * \brief Root of all objects
146 // -------------------------------------------------------------------------------------
148 class _pyObject: public Standard_Transient
150 Handle(_pyCommand) myCreationCmd;
152 _pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
153 const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
154 static _pyID FatherID(const _pyID & childID);
155 const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
156 void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
157 int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
158 virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
159 virtual void Flush() = 0;
160 virtual const char* AccessorMethod() const;
162 DEFINE_STANDARD_RTTI (_pyObject)
165 // -------------------------------------------------------------------------------------
167 * \brief Class corresponding to SMESH_Gen. It holds info on existing
168 * meshes and hypotheses
170 // -------------------------------------------------------------------------------------
171 class _pyGen: public _pyObject
174 _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
176 Handle(_pyCommand) AddCommand( const TCollection_AsciiString& theCommand );
177 void Process( const Handle(_pyCommand)& theCommand );
179 Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
180 Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
181 const Handle(_pyHypothesis)& theHypothesis);
182 void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
183 void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
184 std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
185 void SetAccessorMethod(const _pyID& theID, const char* theMethod );
186 bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
187 bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
188 const char* AccessorMethod() const;
190 std::map< _pyID, Handle(_pyMesh) > myMeshes;
191 std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
192 std::list< Handle(_pyHypothesis) > myHypos;
193 std::list< Handle(_pyCommand) > myCommands;
196 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
198 DEFINE_STANDARD_RTTI (_pyGen)
201 // -------------------------------------------------------------------------------------
203 * \brief Contains commands concerning mesh substructures
205 // -------------------------------------------------------------------------------------
206 #define _pyMesh_ACCESS_METHOD "GetMesh()"
207 class _pyMesh: public _pyObject
209 std::list< Handle(_pyHypothesis) > myHypos;
210 std::list< Handle(_pyCommand) > myAddHypCmds;
211 std::list< Handle(_pyCommand) > mySubmeshes;
214 _pyMesh(const Handle(_pyCommand) creationCmd);
215 _pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString & id);
216 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
217 void Process( const Handle(_pyCommand)& theCommand);
219 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
221 static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
222 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
223 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
225 //friend class _pyMeshEditor;
226 DEFINE_STANDARD_RTTI (_pyMesh)
228 #undef _pyMesh_ACCESS_METHOD
230 // -------------------------------------------------------------------------------------
232 * \brief MeshEditor convert its commands to ones of mesh
234 // -------------------------------------------------------------------------------------
235 class _pyMeshEditor: public _pyObject
238 TCollection_AsciiString myCreationCmdStr;
240 _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
241 void Process( const Handle(_pyCommand)& theCommand);
242 virtual void Flush() {}
244 DEFINE_STANDARD_RTTI (_pyMesh)
247 // -------------------------------------------------------------------------------------
249 * \brief Root class for hypothesis
251 * HOWTO assure convertion of a new type of hypothesis
252 * In _pyHypothesis::NewHypothesis():
253 * 1. add a case for the name of the new hypothesis
254 * 2. use SetConvMethodAndType() to set
255 * . for algo: algorithm name and method of Mesh creating the algo
256 * . for hypo: name of the algorithm and method creating the hypothesis
257 * 3. append to myArgMethods interface methods setting param values in the
258 * order they are used when creation method is called. If arguments of
259 * the creation method can't be easily got from calls of hypothesis methods, you are
260 * to derive a specific class from _pyHypothesis that would redefine Process(),
261 * see _pyComplexParamHypo for example
263 // -------------------------------------------------------------------------------------
264 class _pyHypothesis: public _pyObject
267 bool myIsAlgo, myIsWrapped;
268 _pyID myGeom, myMesh;
269 // a hypothesis can be used and created by different algos by different methods
270 std::map<TCollection_AsciiString, TCollection_AsciiString > myType2CreationMethod;
271 //TCollection_AsciiString myCreationMethod, myType;
272 TColStd_SequenceOfAsciiString myArgs; // creation arguments
273 TColStd_SequenceOfAsciiString myArgMethods; // hypo methods setting myArgs
274 TColStd_SequenceOfInteger myNbArgsByMethod; // nb args set by each method
275 std::list<Handle(_pyCommand)> myArgCommands;
276 std::list<Handle(_pyCommand)> myUnknownCommands;
278 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
279 void SetConvMethodAndType(const char* creationMethod, const char* type)
280 { myType2CreationMethod[ (char*)type ] = (char*)creationMethod; }
281 void AddArgMethod(const char* method, const int nbArgs = 1)
282 { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
283 const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
284 const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
285 void ClearAllCommands();
286 virtual bool IsAlgo() const { return myIsAlgo; }
287 bool IsValid() const { return !myType2CreationMethod.empty(); }
288 bool IsWrapped() const { return myIsWrapped; }
289 const _pyID & GetGeom() const { return myGeom; }
290 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
291 const _pyID & GetMesh() const { return myMesh; }
292 const TCollection_AsciiString& GetAlgoType() const
293 { return myType2CreationMethod.begin()->first; }
294 const TCollection_AsciiString& GetAlgoCreationMethod() const
295 { return myType2CreationMethod.begin()->second; }
296 bool CanBeCreatedBy(const TCollection_AsciiString& algoType ) const
297 { return myType2CreationMethod.find( algoType ) != myType2CreationMethod.end(); }
298 const TCollection_AsciiString& GetCreationMethod(const TCollection_AsciiString& algoType) const
299 { return myType2CreationMethod.find( algoType )->second; }
300 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
301 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
302 const _pyID& theMesh);
303 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
304 void Process( const Handle(_pyCommand)& theCommand);
307 DEFINE_STANDARD_RTTI (_pyHypothesis)
310 // -------------------------------------------------------------------------------------
312 * \brief Class representing smesh.Mesh_Algorithm
314 // -------------------------------------------------------------------------------------
315 class _pyAlgorithm: public _pyHypothesis
318 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
319 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
320 const _pyID& theMesh);
321 const char* AccessorMethod() const { return "GetAlgorithm()"; }
323 DEFINE_STANDARD_RTTI (_pyAlgorithm)
326 // -------------------------------------------------------------------------------------
328 * \brief Class for hypotheses having several parameters modified by one method
330 // -------------------------------------------------------------------------------------
331 class _pyComplexParamHypo: public _pyHypothesis
334 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
335 void Process( const Handle(_pyCommand)& theCommand);
337 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
339 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
341 // -------------------------------------------------------------------------------------
343 * \brief Class for LayerDistribution hypothesis conversion
345 // -------------------------------------------------------------------------------------
346 class _pyLayerDistributionHypo: public _pyHypothesis
348 Handle(_pyHypothesis) my1dHyp;
350 _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd):
351 _pyHypothesis(theCreationCmd) {}
352 void Process( const Handle(_pyCommand)& theCommand);
354 bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
355 const _pyID& theMesh);
357 DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
359 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
361 // -------------------------------------------------------------------------------------
363 * \brief Class representing NumberOfSegments hypothesis
365 // -------------------------------------------------------------------------------------
366 class _pyNumberOfSegmentsHyp: public _pyHypothesis
369 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
370 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
371 const _pyID& theMesh);
374 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
376 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
378 // -------------------------------------------------------------------------------------
380 * \brief Class representing SegmentLengthAroundVertex hypothesis
382 // -------------------------------------------------------------------------------------
383 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
386 _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
387 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
388 const _pyID& theMesh);
389 DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
391 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);