Version: 6.3.1

src/SMESH_I/SMESH_2smeshpy.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File      : SMESH_smesh.hxx
00024 // Created   : Fri Nov 18 12:05:18 2005
00025 // Author    : Edward AGAPOV (eap)
00026 //
00027 #ifndef SMESH_smesh_HeaderFile
00028 #define SMESH_smesh_HeaderFile
00029 
00030 #include <Standard_DefineHandle.hxx>
00031 #include <Standard_Type.hxx>
00032 #include <Standard_Transient.hxx>
00033 #include <TCollection_AsciiString.hxx>
00034 #include <TColStd_SequenceOfAsciiString.hxx>
00035 #include <TColStd_SequenceOfInteger.hxx>
00036 
00037 #include <list>
00038 #include <map>
00039 
00040 // ===========================================================================================
00055 // ===========================================================================================
00056 
00057 class Resource_DataMapOfAsciiStringAsciiString;
00058 
00059 // ===========================================================================================
00060 // =====================
00061 //    INTERNAL STUFF
00062 // =====================
00063 // ===========================================================================================
00064 
00065 class _pyCommand;
00066 class _pyObject;
00067 class _pyGen;
00068 class _pyMesh;
00069 class _pySubMesh;
00070 class _pyHypothesis;
00071 class _pyAlgorithm;
00072 class _pyFilterManager;
00073 
00074 DEFINE_STANDARD_HANDLE (_pyCommand   ,Standard_Transient);
00075 DEFINE_STANDARD_HANDLE (_pyObject    ,Standard_Transient);
00076 DEFINE_STANDARD_HANDLE (_pyGen       ,_pyObject);
00077 DEFINE_STANDARD_HANDLE (_pyMesh      ,_pyObject);
00078 DEFINE_STANDARD_HANDLE (_pySubMesh   ,_pyObject);
00079 DEFINE_STANDARD_HANDLE (_pyMeshEditor,_pyObject);
00080 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
00081 DEFINE_STANDARD_HANDLE (_pyFilterManager,_pyObject);
00082 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
00083 
00084 typedef TCollection_AsciiString _pyID;
00085 
00086 // ===========================================================
00091 // ===========================================================
00092 
00093 class _pyCommand: public Standard_Transient
00094 {
00095   int                             myOrderNb;            
00096   TCollection_AsciiString         myString;             
00097   TCollection_AsciiString         myRes, myObj, myMeth; 
00098   TColStd_SequenceOfAsciiString   myArgs;               
00099   TColStd_SequenceOfInteger       myBegPos;             
00100   std::list< Handle(_pyCommand) > myDependentCmds; 
00101 
00102   enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
00103   int GetBegPos( int thePartIndex );
00104   void SetBegPos( int thePartIndex, int thePosition );
00105   void SetPart( int thePartIndex, const TCollection_AsciiString& theNewPart,
00106                 TCollection_AsciiString& theOldPart);
00107   void FindAllArgs() { GetArg(1); }
00108 
00109 public:
00110   _pyCommand() {};
00111   _pyCommand( const TCollection_AsciiString& theString, int theNb )
00112     : myString( theString ), myOrderNb( theNb ) {};
00113   TCollection_AsciiString & GetString() { return myString; }
00114   int GetOrderNb() const { return myOrderNb; }
00115   void SetOrderNb( int theNb ) { myOrderNb = theNb; }
00116   int Length() { return myString.Length(); }
00117   void Clear() { myString.Clear(); myBegPos.Clear(); myArgs.Clear(); }
00118   bool IsEmpty() const { return myString.IsEmpty(); }
00119   TCollection_AsciiString GetIndentation();
00120   const TCollection_AsciiString & GetResultValue();
00121   const int GetNbResultValues();
00122   const TCollection_AsciiString & GetResultValue(int res);
00123   const TCollection_AsciiString & GetObject();
00124   const TCollection_AsciiString & GetMethod();
00125   const TCollection_AsciiString & GetArg( int index );
00126   int GetNbArgs() { FindAllArgs(); return myArgs.Length(); }
00127   //Handle(TColStd_HSequenceOfAsciiString) GetArgs();
00128   void SetResultValue( const TCollection_AsciiString& theResult )
00129   { GetResultValue(); SetPart( RESULT_IND, theResult, myRes ); }
00130   void SetObject(const TCollection_AsciiString& theObject)
00131   { GetObject(); SetPart( OBJECT_IND, theObject, myObj ); }
00132   void SetMethod(const TCollection_AsciiString& theMethod)
00133   { GetMethod(); SetPart( METHOD_IND, theMethod, myMeth ); }
00134   void SetArg( int index, const TCollection_AsciiString& theArg);
00135   void RemoveArgs();
00136   static bool SkipSpaces( const TCollection_AsciiString & theSring, int & thePos );
00137   static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
00138                                           int & theStartPos, const bool theForward,
00139                                           const bool dotIsWord = false);
00140   void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false)
00141   { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); }
00142   bool SetDependentCmdsAfter() const;
00143 
00144   bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod );
00145 
00146   DEFINE_STANDARD_RTTI (_pyCommand)
00147 };
00148 
00149 // -------------------------------------------------------------------------------------
00153 // -------------------------------------------------------------------------------------
00154 
00155 class _pyObject: public Standard_Transient
00156 {
00157   Handle(_pyCommand) myCreationCmd;
00158   int                myNbCalls;
00159 public:
00160   _pyObject(const Handle(_pyCommand)& theCreationCmd)
00161     : myCreationCmd(theCreationCmd), myNbCalls(0) {}
00162   const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
00163   static _pyID FatherID(const _pyID & childID);
00164   const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
00165   int GetNbCalls() const { return myNbCalls; }
00166   void  SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
00167   int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
00168   virtual void Process(const Handle(_pyCommand) & theCommand) { myNbCalls++; }
00169   virtual void Flush() = 0;
00170   virtual const char* AccessorMethod() const;
00171 
00172   DEFINE_STANDARD_RTTI (_pyObject)
00173 };
00174 
00175 // -------------------------------------------------------------------------------------
00180 // -------------------------------------------------------------------------------------
00181 class _pyGen: public _pyObject
00182 {
00183 public:
00184   _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
00185          Resource_DataMapOfAsciiStringAsciiString& theObjectNames);
00186   //~_pyGen();
00187   Handle(_pyCommand) AddCommand( const TCollection_AsciiString& theCommand );
00188   void Process( const Handle(_pyCommand)& theCommand );
00189   void Flush();
00190   Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
00191   Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
00192                                   const Handle(_pyHypothesis)& theHypothesis);
00193   Handle(_pySubMesh) FindSubMesh( const _pyID& theSubMeshID );
00194   void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
00195   void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
00196   void SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd );
00197   Handle(_pyCommand)& GetLastCommand();
00198   std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
00199   void SetAccessorMethod(const _pyID& theID, const char* theMethod );
00200   bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
00201   bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
00202   const char* AccessorMethod() const;
00203   _pyID GenerateNewID( const _pyID& theID );
00204 
00205 private:
00206   void setNeighbourCommand( Handle(_pyCommand)& theCmd,
00207                             Handle(_pyCommand)& theOtherCmd,
00208                             const bool theIsAfter );
00209   
00210 private:
00211   std::map< _pyID, Handle(_pyMesh) >       myMeshes;
00212   //std::map< _pyID, Handle(_pySubMesh) >    mySubMeshes;
00213   std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
00214   std::map< _pyID, Handle(_pyObject) >     myObjects;
00215   std::list< Handle(_pyHypothesis) >       myHypos;
00216   std::list< Handle(_pyCommand) >          myCommands;
00217   int                                      myNbCommands;
00218   Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
00219   Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
00220   Handle(_pyCommand)                       myLastCommand;
00221 
00222   DEFINE_STANDARD_RTTI (_pyGen)
00223 };
00224 
00225 // -------------------------------------------------------------------------------------
00229 // -------------------------------------------------------------------------------------
00230 #define _pyMesh_ACCESS_METHOD "GetMesh()"
00231 class _pyMesh: public _pyObject
00232 {
00233   std::list< Handle(_pyHypothesis) > myHypos;
00234   std::list< Handle(_pyCommand) > myAddHypCmds;
00235   std::list< Handle(_pySubMesh) > mySubmeshes;
00236   bool                            myHasEditor;
00237 public:
00238   _pyMesh(const Handle(_pyCommand) creationCmd);
00239   _pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString & id);
00240   const _pyID& GetGeom() { return GetCreationCmd()->GetArg(1); }
00241   void Process( const Handle(_pyCommand)& theCommand);
00242   void Flush();
00243   const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
00244 private:
00245   static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
00246   static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
00247   { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
00248 
00249   //friend class _pyMeshEditor;
00250   DEFINE_STANDARD_RTTI (_pyMesh)
00251 };
00252 #undef _pyMesh_ACCESS_METHOD 
00253 
00254 // -------------------------------------------------------------------------------------
00258 // -------------------------------------------------------------------------------------
00259 class _pyMeshEditor: public _pyObject
00260 {
00261   _pyID myMesh;
00262   TCollection_AsciiString myCreationCmdStr;
00263 public:
00264   _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
00265   void Process( const Handle(_pyCommand)& theCommand);
00266   virtual void Flush() {}
00267 
00268   DEFINE_STANDARD_RTTI (_pyMesh)
00269 };
00270 
00271 // -------------------------------------------------------------------------------------
00287 // -------------------------------------------------------------------------------------
00288 class _pyHypothesis: public _pyObject
00289 {
00290 protected:
00291   bool    myIsAlgo, myIsWrapped;
00292   _pyID   myGeom,   myMesh;
00293   // a hypothesis can be used and created by different algos by different methods
00294   std::map<TCollection_AsciiString, TCollection_AsciiString > myType2CreationMethod;
00295   //TCollection_AsciiString       myCreationMethod, myType;
00296   TColStd_SequenceOfAsciiString myArgs;           // creation arguments
00297   TColStd_SequenceOfAsciiString myArgMethods;     // hypo methods setting myArgs
00298   TColStd_SequenceOfInteger     myNbArgsByMethod; // nb args set by each method
00299   std::list<Handle(_pyCommand)>  myArgCommands;
00300   std::list<Handle(_pyCommand)>  myUnknownCommands;
00301 public:
00302   _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
00303   void SetConvMethodAndType(const char* creationMethod, const char* type)
00304   { myType2CreationMethod[ (char*)type ] = (char*)creationMethod; }
00305   void AddArgMethod(const char* method, const int nbArgs = 1)
00306   { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
00307   const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
00308   const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
00309   void ClearAllCommands();
00310   virtual bool IsAlgo() const { return myIsAlgo; }
00311   bool IsValid() const { return !myType2CreationMethod.empty(); }
00312   bool IsWrapped() const { return myIsWrapped; }
00313   const _pyID & GetGeom() const { return myGeom; }
00314   void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
00315   const _pyID & GetMesh() const { return myMesh; }
00316   const TCollection_AsciiString& GetAlgoType() const
00317   { return myType2CreationMethod.begin()->first; }
00318   const TCollection_AsciiString& GetAlgoCreationMethod() const
00319   { return myType2CreationMethod.begin()->second; }
00320   bool CanBeCreatedBy(const TCollection_AsciiString& algoType ) const
00321   { return myType2CreationMethod.find( algoType ) != myType2CreationMethod.end(); }
00322   const TCollection_AsciiString& GetCreationMethod(const TCollection_AsciiString& algoType) const
00323   { return myType2CreationMethod.find( algoType )->second; }
00324   virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
00325   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
00326                                   const _pyID&              theMesh);
00327   static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
00328   void Process( const Handle(_pyCommand)& theCommand);
00329   void Flush();
00330   virtual void Assign( const Handle(_pyHypothesis)& theOther,
00331                        const _pyID&                 theMesh );
00332 
00333   DEFINE_STANDARD_RTTI (_pyHypothesis)
00334 };
00335 
00336 // -------------------------------------------------------------------------------------
00340 // -------------------------------------------------------------------------------------
00341 class _pyAlgorithm: public _pyHypothesis
00342 {
00343 public:
00344   _pyAlgorithm(const Handle(_pyCommand)& theCreationCmd);
00345   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
00346                                   const _pyID&              theMesh);
00347   const char* AccessorMethod() const { return "GetAlgorithm()"; }
00348   virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped; }
00349 
00350   DEFINE_STANDARD_RTTI (_pyAlgorithm)
00351 };
00352 
00353 // -------------------------------------------------------------------------------------
00357 // -------------------------------------------------------------------------------------
00358 class _pyComplexParamHypo: public _pyHypothesis
00359 {
00360 public:
00361   _pyComplexParamHypo(const Handle(_pyCommand)& theCreationCmd): _pyHypothesis(theCreationCmd) {}
00362   void Process( const Handle(_pyCommand)& theCommand);
00363   void Flush();
00364 
00365   DEFINE_STANDARD_RTTI (_pyComplexParamHypo)
00366 };
00367 DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis);
00368 
00369 // -------------------------------------------------------------------------------------
00373 // -------------------------------------------------------------------------------------
00374 class _pyLayerDistributionHypo: public _pyHypothesis
00375 {
00376   Handle(_pyHypothesis) my1dHyp;
00377   TCollection_AsciiString myAlgoMethod;
00378 public:
00379   _pyLayerDistributionHypo(const Handle(_pyCommand)& theCreationCmd, const char* algoMethod):
00380     _pyHypothesis(theCreationCmd), myAlgoMethod((char*)algoMethod) {}
00381   void Process( const Handle(_pyCommand)& theCommand);
00382   void Flush();
00383   bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
00384                           const _pyID&              theMesh);
00385 
00386   DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo)
00387 };
00388 DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis);
00389 
00390 // -------------------------------------------------------------------------------------
00394 // -------------------------------------------------------------------------------------
00395 class _pyNumberOfSegmentsHyp: public _pyHypothesis
00396 {
00397 public:
00398   _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
00399   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
00400                                   const _pyID&              theMesh);
00401   void Flush();
00402 
00403   DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
00404 };
00405 DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis);
00406 
00407 // -------------------------------------------------------------------------------------
00411 // -------------------------------------------------------------------------------------
00412 class _pySegmentLengthAroundVertexHyp: public _pyHypothesis
00413 {
00414 public:
00415   _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
00416   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
00417                                   const _pyID&              theMesh);
00418   DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp)
00419 };
00420 DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis);
00421 
00422 // -------------------------------------------------------------------------------------
00426 // -------------------------------------------------------------------------------------
00427 class _pySelfEraser: public _pyObject
00428 {
00429 public:
00430   _pySelfEraser(const Handle(_pyCommand)& theCreationCmd):_pyObject(theCreationCmd) {}
00431   virtual void Flush();
00432 
00433   DEFINE_STANDARD_RTTI (_pySelfEraser)
00434 };
00435 DEFINE_STANDARD_HANDLE (_pySelfEraser, _pyObject);
00436 
00437 // -------------------------------------------------------------------------------------
00441 // -------------------------------------------------------------------------------------
00442 class _pySubMesh:  public _pyObject
00443 {
00444 public:
00445   _pySubMesh(const Handle(_pyCommand)& theCreationCmd):_pyObject(theCreationCmd) {}
00446   void Process( const Handle(_pyCommand)& theCommand);
00447   virtual void Flush();
00448   void SetCreator( const Handle(_pyObject)& theCreator ) { myCreator = theCreator; }
00449 
00450   DEFINE_STANDARD_RTTI (_pySubMesh)
00451 private:
00452   Handle(_pyObject) myCreator;
00453 };
00454 
00455 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS