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;
189 const std::map< _pyID, Handle(_pyMeshEditor) >& getMeshEditors() const { return myMeshEditors; }
191 std::map< _pyID, Handle(_pyMesh) > myMeshes;
192 std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
193 std::list< Handle(_pyHypothesis) > myHypos;
194 std::list< Handle(_pyCommand) > myCommands;
197 Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
199 DEFINE_STANDARD_RTTI (_pyGen)
202 // -------------------------------------------------------------------------------------
204 * \brief Contains commands concerning mesh substructures
206 // -------------------------------------------------------------------------------------
207 #define _pyMesh_ACCESS_METHOD "GetMesh()"
208 class _pyMesh: public _pyObject
210 std::list< Handle(_pyHypothesis) > myHypos;
211 std::list< Handle(_pyCommand) > myAddHypCmds;
212 std::list< Handle(_pyCommand) > mySubmeshes;
215 _pyMesh(const Handle(_pyCommand) theCreationCmd);
216 _pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString &);
217 const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
218 void Process( const Handle(_pyCommand)& theCommand);
220 const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
222 static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
223 static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
224 { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
226 //friend class _pyMeshEditor;
227 DEFINE_STANDARD_RTTI (_pyMesh)
229 #undef _pyMesh_ACCESS_METHOD
231 // -------------------------------------------------------------------------------------
233 * \brief MeshEditor convert its commands to ones of mesh
235 // -------------------------------------------------------------------------------------
236 class _pyMeshEditor: public _pyObject
239 TCollection_AsciiString myCreationCmdStr;
241 _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
242 void Process( const Handle(_pyCommand)& theCommand);
243 virtual void Flush() {}
245 DEFINE_STANDARD_RTTI (_pyMesh)
248 // -------------------------------------------------------------------------------------
250 * \brief Root class for hypothesis
252 * HOWTO assure convertion of a new type of hypothesis
253 * In _pyHypothesis::NewHypothesis():
254 * 1. add a case for the name of the new hypothesis
255 * 2. use SetConvMethodAndType() to set
256 * . for algo: algorithm name and method of Mesh creating the algo
257 * . for hypo: name of the algorithm and method creating the hypothesis
258 * 3. append to myArgMethods interface methods setting param values in the
259 * order they are used when creation method is called. If arguments of
260 * the creation method can't be easily got from calls of hypothesis methods, you are
261 * to derive a specific class from _pyHypothesis that would redefine Process(),
262 * see _pyComplexParamHypo for example
264 // -------------------------------------------------------------------------------------
265 class _pyHypothesis: public _pyObject
268 bool myIsAlgo, myIsWrapped;
269 _pyID myGeom, myMesh;
270 // a hypothesis can be used and created by different algos by different methods
271 std::map<TCollection_AsciiString, TCollection_AsciiString > myType2CreationMethod;
272 //TCollection_AsciiString myCreationMethod, myType;
273 TColStd_SequenceOfAsciiString myArgs; // creation arguments
274 TColStd_SequenceOfAsciiString myArgMethods; // hypo methods setting myArgs
275 TColStd_SequenceOfInteger myNbArgsByMethod; // nb args set by each method
276 std::list<Handle(_pyCommand)> myArgCommands;
277 std::list<Handle(_pyCommand)> myUnknownCommands;
279 _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
280 void SetConvMethodAndType(const char* creationMethod, const char* type)
281 { myType2CreationMethod[ (char*)type ] = (char*)creationMethod; }
282 void AddArgMethod(const char* method, const int nbArgs = 1)
283 { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
284 const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
285 const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
286 void ClearAllCommands();
287 virtual bool IsAlgo() const { return myIsAlgo; }
288 bool IsValid() const { return !myType2CreationMethod.empty(); }
289 bool IsWrapped() const { return myIsWrapped; }
290 const _pyID & GetGeom() const { return myGeom; }
291 void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
292 const _pyID & GetMesh() const { return myMesh; }
293 const TCollection_AsciiString& GetAlgoType() const
294 { return myType2CreationMethod.begin()->first; }
295 const TCollection_AsciiString& GetAlgoCreationMethod() const
296 { return myType2CreationMethod.begin()->second; }
297 bool CanBeCreatedBy(const TCollection_AsciiString& algoType ) const
298 { return myType2CreationMethod.find( algoType ) != myType2CreationMethod.end(); }
299 const TCollection_AsciiString& GetCreationMethod(const TCollection_AsciiString& algoType) const
300 { return myType2CreationMethod.find( algoType )->second; }
301 bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
302 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
303 const _pyID& theMesh);
304 static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
305 void Process( const Handle(_pyCommand)& theCommand);
308 DEFINE_STANDARD_RTTI (_pyHypothesis)
311 // -------------------------------------------------------------------------------------
313 * \brief Class representing smesh.Mesh_Algorithm
315 // -------------------------------------------------------------------------------------
316 class _pyAlgorithm: public _pyHypothesis
319 _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
320 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
321 const _pyID& theMesh);
322 const char* AccessorMethod() const { return "GetAlgorithm()"; }
324 DEFINE_STANDARD_RTTI (_pyAlgorithm)
327 // -------------------------------------------------------------------------------------
329 * \brief Class for hypotheses having several parameters modified by one method
331 // -------------------------------------------------------------------------------------
332 class _pyComplexParamHypo: public _pyHypothesis
335 _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
336 void Process( const Handle(_pyCommand)& theCommand);
338 DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
340 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
342 // -------------------------------------------------------------------------------------
344 * \brief Class for LayerDistribution hypothesis conversion
346 // -------------------------------------------------------------------------------------
347 class _pyLayerDistributionHypo: public _pyHypothesis
349 Handle(_pyHypothesis) my1dHyp;
351 _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd):
352 _pyHypothesis(theCreationCmd) {}
353 void Process( const Handle(_pyCommand)& theCommand);
355 bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
356 const _pyID& theMesh);
358 DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
360 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
362 // -------------------------------------------------------------------------------------
364 * \brief Class representing NumberOfSegments hypothesis
366 // -------------------------------------------------------------------------------------
367 class _pyNumberOfSegmentsHyp: public _pyHypothesis
370 _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
371 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
372 const _pyID& theMesh);
375 DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
377 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
379 // -------------------------------------------------------------------------------------
381 * \brief Class representing SegmentLengthAroundVertex hypothesis
383 // -------------------------------------------------------------------------------------
384 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
387 _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
388 virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
389 const _pyID& theMesh);
390 DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
392 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);