X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_2smeshpy.hxx;h=71ecd144552f6256e1fb0897450b7c71abdc2cba;hb=2b3c553f4facafcea7cb1b2f23ab4b91b64771df;hp=f92c285b4c4176cf3463c4afe671db5b35fc7e4a;hpb=bd4e115a78b52e3fbc016e5e30bb0e19b2a9e7d6;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_2smeshpy.hxx b/src/SMESH_I/SMESH_2smeshpy.hxx index f92c285b4..71ecd1445 100644 --- a/src/SMESH_I/SMESH_2smeshpy.hxx +++ b/src/SMESH_I/SMESH_2smeshpy.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -33,21 +33,25 @@ #include #include #include +#include #include #include #include +#include #include #include CORBA_CLIENT_HEADER(SALOMEDS) +#define USE_STRING_FAMILY + // =========================================================================================== /*! * This file was created in order to respond to requirement of bug PAL10494: * SMESH python dump uses idl interface. * - * The creation reason is that smesh.py commands defining hypotheses encapsulate - * several SMESH engine method calls. As well, the dependencies between smesh.py + * The creation reason is that smeshBuilder.py commands defining hypotheses encapsulate + * several SMESH engine method calls. As well, the dependencies between smeshBuilder.py * classes differ from ones between corresponding SMESH IDL interfaces. * * Everything here is for internal usage by SMESH_2smeshpy::ConvertScript() @@ -55,8 +59,6 @@ */ // =========================================================================================== -class Resource_DataMapOfAsciiStringAsciiString; - // =========================================================================================== // ===================== // INTERNAL STUFF @@ -99,11 +101,12 @@ class _pyCommand: public Standard_Transient _AString myString; //!< command text _AString myRes, myObj, myMeth; //!< found parts of command TColStd_SequenceOfAsciiString myArgs; //!< found arguments + TColStd_SequenceOfAsciiString myResults; //!< found results TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin - std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that sould follow me in the script + std::list< Handle(_pyCommand) > myDependentCmds; //!< commands that should follow me in the script enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND }; - int GetBegPos( int thePartIndex ); + int GetBegPos( int thePartIndex ) const; void SetBegPos( int thePartIndex, int thePosition ); void SetPart( int thePartIndex, const _AString& theNewPart, _AString& theOldPart); void FindAllArgs() { GetArg(1); } @@ -111,23 +114,25 @@ class _pyCommand: public Standard_Transient public: _pyCommand() {}; _pyCommand( const _AString& theString, int theNb=-1 ) - : myString( theString ), myOrderNb( theNb ) {}; + : myOrderNb( theNb ), myString( theString ) {}; _AString & GetString() { return myString; } - int GetOrderNb() const { return myOrderNb; } + int GetOrderNb() const { return myOrderNb; } void SetOrderNb( int theNb ) { myOrderNb = theNb; } typedef void* TAddr; TAddr GetAddress() const { return (void*) this; } - int Length() { return myString.Length(); } + int Length() const { return myString.Length(); } void Clear() { myString.Clear(); myBegPos.Clear(); myArgs.Clear(); } bool IsEmpty() const { return myString.IsEmpty(); } _AString GetIndentation(); const _AString & GetResultValue(); - const int GetNbResultValues(); - _AString GetResultValue(int res); + int GetNbResultValues(); + const _AString & GetResultValue(int res); const _AString & GetObject(); const _AString & GetMethod(); const _AString & GetArg( int index ); int GetNbArgs() { FindAllArgs(); return myArgs.Length(); } + int GetArgBeginning() const; + bool IsMethodCall(); bool MethodStartsFrom(const _AString& beg) { GetMethod(); return ( myMeth.Location( beg, 1, myMeth.Length() ) == 1 ); } void SetResultValue( const _AString& theResult ) @@ -143,6 +148,9 @@ public: static _AString GetWord( const _AString & theSring, int & theStartPos, const bool theForward, const bool dotIsWord = false); static bool IsStudyEntry( const _AString& str ); + static bool IsID( const _AString& str ); + static bool IsIDChar( char c ) + { return ( isalnum( c ) || c == '_' || c == ':' ); } static std::list< _pyID > GetStudyEntries( const _AString& str ); void AddDependantCmd( Handle(_pyCommand) cmd, bool prepend = false) { if (prepend) myDependentCmds.push_front( cmd ); else myDependentCmds.push_back( cmd ); } @@ -150,7 +158,7 @@ public: bool AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod ); - DEFINE_STANDARD_RTTI (_pyCommand) + DEFINE_STANDARD_RTTIEXT(_pyCommand,Standard_Transient) }; // ------------------------------------------------------------------------------------- @@ -165,6 +173,7 @@ protected: _pyID myID; Handle(_pyCommand) myCreationCmd; std::list< Handle(_pyCommand) > myProcessedCmds; + std::list< Handle(_pyCommand) > myArgCmds; // where this obj is used as an argument bool myIsPublished; void setID(const _pyID& theID); @@ -173,22 +182,23 @@ public: const _pyID& GetID() { return myID.IsEmpty() ? myCreationCmd->GetResultValue() : myID; } static _pyID FatherID(const _pyID & childID); const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; } - int GetNbCalls() const { return myProcessedCmds.size(); } + int GetNbCalls() const { return myProcessedCmds.size(); } bool IsInStudy() const { return myIsPublished; } virtual void SetRemovedFromStudy(const bool isRemoved) { myIsPublished = !isRemoved; } void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; } - int GetCommandNb() { return myCreationCmd->GetOrderNb(); } + int GetCommandNb() { return myCreationCmd->GetOrderNb(); } void AddProcessedCmd( const Handle(_pyCommand) & cmd ) { if (myProcessedCmds.empty() || myProcessedCmds.back()!=cmd) myProcessedCmds.push_back( cmd );} std::list< Handle(_pyCommand) >& GetProcessedCmds() { return myProcessedCmds; } + void AddArgCmd( const Handle(_pyCommand) & cmd ) { myArgCmds.push_back( cmd ); } virtual void Process(const Handle(_pyCommand) & cmd) { AddProcessedCmd(cmd); } virtual void Flush() = 0; virtual const char* AccessorMethod() const; - virtual bool CanClear() { return !myIsPublished; } + virtual bool CanClear(); virtual void ClearCommands(); virtual void Free() {} - DEFINE_STANDARD_RTTI (_pyObject) + DEFINE_STANDARD_RTTIEXT(_pyObject,Standard_Transient) }; // ------------------------------------------------------------------------------------- @@ -211,6 +221,26 @@ struct ExportedMeshData } }; +// ------------------------------------------------------------------------------------- +/*! + * \brief A container of strings groupped by prefix. It is used for a faster search of + * objects requiring to KeepAgrCmds() in commands. A speed up is gained because + * only a common prefix (e.g. "aArea") of many object IDs is searched in a command + * and not every object ID + */ +// ------------------------------------------------------------------------------------- +class _pyStringFamily +{ + _AString _prefix; + std::list< _pyStringFamily > _subFams; + std::list< _AString > _strings; + int isIn( const char* str ); +public: + bool Add( const char* str ); + bool IsInArgs( Handle( _pyCommand)& cmd, std::list<_AString>& subStr ); + void Print( int level = 0 ); +}; + // ------------------------------------------------------------------------------------- /*! * \brief Class corresponding to SMESH_Gen. It holds info on existing @@ -222,21 +252,22 @@ class _pyGen: public _pyObject public: _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod, Resource_DataMapOfAsciiStringAsciiString& theObjectNames, - SALOMEDS::Study_ptr& theStudy, + std::set< TCollection_AsciiString >& theRemovedObjIDs, const bool theToKeepAllCommands); Handle(_pyCommand) AddCommand( const _AString& theCommand ); void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 ); - void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd ); - void SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd ); + void SetCommandAfter ( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd ); + void SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd ); Handle(_pyCommand)& GetLastCommand(); std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; } void PlaceSubmeshAfterItsCreation( Handle(_pyCommand) theCmdUsingSubmesh ) const; _pyID GenerateNewID( const _pyID& theID ); - void AddObject( Handle(_pyObject)& theObj ); + bool AddObject( Handle(_pyObject)& theObj ); + void CheckObjectIsReCreated( Handle(_pyObject)& theObj ); void SetProxyObject( const _pyID& theID, Handle(_pyObject)& theObj ); - Handle(_pyObject) FindObject( const _pyID& theObjID ) const; - Handle(_pySubMesh) FindSubMesh( const _pyID& theSubMeshID ); + Handle(_pyObject) FindObject( const _pyID& theObjID ) const; + Handle(_pySubMesh) FindSubMesh( const _pyID& theSubMeshID ); Handle(_pyHypothesis) FindHyp( const _pyID& theHypID ); Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh, const Handle(_pyHypothesis)& theHypothesis); @@ -248,6 +279,12 @@ public: bool IsGeomObject(const _pyID& theObjID) const; bool IsNotPublished(const _pyID& theObjID) const; + void ObjectCreationRemoved(const _pyID& theObjID); +#ifdef USE_STRING_FAMILY + void KeepAgrCmds(const _pyID& theObjID) { myKeepAgrCmdsIDs.Add( theObjID.ToCString() ); } +#else + void KeepAgrCmds(const _pyID& theObjID) { myKeepAgrCmdsIDs.push_back( theObjID ); } +#endif bool IsToKeepAllCommands() const { return myToKeepAllCommands; } void AddExportedMesh(const _AString& file, const ExportedMeshData& mesh ) { myFile2ExportedMesh[ file ] = mesh; } @@ -265,25 +302,32 @@ private: void setNeighbourCommand( Handle(_pyCommand)& theCmd, Handle(_pyCommand)& theOtherCmd, const bool theIsAfter ); - + //void addFilterUser( Handle(_pyCommand)& theCmd, const Handle(_pyObject)& user ); + private: - std::map< _pyID, Handle(_pyMesh) > myMeshes; - std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors; - std::map< _pyID, Handle(_pyObject) > myObjects; - std::list< Handle(_pyHypothesis) > myHypos; - std::list< Handle(_pyCommand) > myCommands; - int myNbCommands; + std::map< _pyID, Handle(_pyMesh) > myMeshes; + std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors; + std::map< _pyID, Handle(_pyHypothesis) > myHypos; + std::map< _pyID, Handle(_pyObject) > myObjects; + std::list< Handle(_pyObject) > myOrderedObjects; // to know order of myObjects creation +#ifdef USE_STRING_FAMILY + _pyStringFamily myKeepAgrCmdsIDs; +#else + std::list< _pyID > myKeepAgrCmdsIDs; +#endif + std::list< Handle(_pyCommand) > myCommands; + int myNbCommands; Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod; Resource_DataMapOfAsciiStringAsciiString& myObjectNames; - Handle(_pyCommand) myLastCommand; - int myNbFilters; - bool myToKeepAllCommands; - SALOMEDS::Study_var myStudy; - int myGeomIDNb, myGeomIDIndex; - std::map< _AString, ExportedMeshData > myFile2ExportedMesh; - Handle( _pyHypothesisReader ) myHypReader; - - DEFINE_STANDARD_RTTI (_pyGen) + std::set< TCollection_AsciiString >& myRemovedObjIDs; + Handle(_pyCommand) myLastCommand; + int myNbFilters; + bool myToKeepAllCommands; + int myGeomIDNb, myGeomIDIndex; + std::map< _AString, ExportedMeshData > myFile2ExportedMesh; + Handle( _pyHypothesisReader ) myHypReader; + + DEFINE_STANDARD_RTTIEXT(_pyGen,_pyObject) }; // ------------------------------------------------------------------------------------- @@ -295,7 +339,7 @@ private: class _pyMesh: public _pyObject { std::list< Handle(_pyHypothesis) > myHypos; - std::list< Handle(_pyCommand) > myAddHypCmds; + std::list< Handle(_pyCommand) > myAddHypCmds, myNotConvertedAddHypCmds; std::list< Handle(_pySubMesh) > mySubmeshes; std::list< Handle(_pyGroup) > myGroups; std::list< Handle(_pyMeshEditor)> myEditors; @@ -324,7 +368,7 @@ private: static void AddMeshAccess( const Handle(_pyCommand)& theCommand ) { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); } - DEFINE_STANDARD_RTTI (_pyMesh) + DEFINE_STANDARD_RTTIEXT(_pyMesh,_pyObject) }; #undef _pyMesh_ACCESS_METHOD @@ -344,7 +388,7 @@ public: virtual void Flush() {} virtual bool CanClear(); - DEFINE_STANDARD_RTTI (_pyMesh) + DEFINE_STANDARD_RTTIEXT(_pyMeshEditor,_pyObject) }; // ------------------------------------------------------------------------------------- @@ -360,7 +404,7 @@ protected: _pyID myGeom, myMesh; struct CreationMethod { _AString myMethod; // method of algo or mesh creating a hyp - // myArgNb(i)-th arg of myArgMethods(i) of hyp becomes an i-th arg of myAlgoMethod + // myArgNb(i)-th arg of myArgMethods(i) of hyp becomes an i-th arg of myMethod std::vector<_AString> myArgMethods; std::vector myArgNb; // arg nb countered from 1 std::vector<_AString> myArgs; // creation arguments @@ -369,6 +413,7 @@ protected: // a hypothesis can be created by different algos by different methods typedef std::map<_AString, CreationMethod > TType2CrMethod; TType2CrMethod myAlgoType2CreationMethod; + std::set< _AString > myAccumulativeMethods; CreationMethod* myCurCrMethod; // used for adding to myAlgoType2CreationMethod std::list myArgCommands; std::list myUnusedCommands; @@ -389,6 +434,8 @@ public: void AddArgMethod(const _AString& method, const int argNb = 1) { myCurCrMethod->myArgMethods.push_back( method ); myCurCrMethod->myArgNb.push_back( argNb ); } + void AddAccumulativeMethod( const _AString& method) + { myAccumulativeMethods.insert( method ); } //const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; } const std::list& GetArgCommands() const { return myArgCommands; } void ClearAllCommands(); @@ -425,7 +472,7 @@ public: //void ComputeSaved ( const Handle(_pyCommand)& theComputeCommand ); - DEFINE_STANDARD_RTTI (_pyHypothesis) + DEFINE_STANDARD_RTTIEXT(_pyHypothesis,_pyObject) }; // ------------------------------------------------------------------------------------- @@ -442,7 +489,7 @@ public: virtual const char* AccessorMethod() const { return "GetAlgorithm()"; } virtual bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped; } - DEFINE_STANDARD_RTTI (_pyAlgorithm) + DEFINE_STANDARD_RTTIEXT(_pyAlgorithm,_pyHypothesis) }; // ------------------------------------------------------------------------------------- @@ -457,7 +504,7 @@ public: virtual void Process( const Handle(_pyCommand)& theCommand); virtual void Flush(); - DEFINE_STANDARD_RTTI (_pyComplexParamHypo) + DEFINE_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis) }; DEFINE_STANDARD_HANDLE (_pyComplexParamHypo, _pyHypothesis); @@ -479,7 +526,7 @@ public: const _pyID& theMesh); virtual void Free() { my1dHyp.Nullify(); } - DEFINE_STANDARD_RTTI (_pyLayerDistributionHypo) + DEFINE_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis) }; DEFINE_STANDARD_HANDLE (_pyLayerDistributionHypo, _pyHypothesis); @@ -496,7 +543,7 @@ public: const _pyID& theMesh); void Flush(); - DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp) + DEFINE_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis) }; DEFINE_STANDARD_HANDLE (_pyNumberOfSegmentsHyp, _pyHypothesis); @@ -511,7 +558,7 @@ public: _pySegmentLengthAroundVertexHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {} virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd, const _pyID& theMesh); - DEFINE_STANDARD_RTTI (_pySegmentLengthAroundVertexHyp) + DEFINE_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis) }; DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis); @@ -522,12 +569,15 @@ DEFINE_STANDARD_HANDLE (_pySegmentLengthAroundVertexHyp, _pyHypothesis); // ------------------------------------------------------------------------------------- class _pySelfEraser: public _pyObject { + bool myIgnoreOwnCalls; // not to erase only if this obj is used as argument public: - _pySelfEraser(const Handle(_pyCommand)& theCreationCmd) - :_pyObject(theCreationCmd) { myIsPublished = true; } + _pySelfEraser(const Handle(_pyCommand)& theCreationCmd); + void IgnoreOwnCalls() { myIgnoreOwnCalls = true; } virtual void Flush(); + virtual bool CanClear(); + static bool IsAliveCmd( const Handle(_pyCommand)& theCmd ); - DEFINE_STANDARD_RTTI (_pySelfEraser) + DEFINE_STANDARD_RTTIEXT(_pySelfEraser,_pyObject) }; DEFINE_STANDARD_HANDLE (_pySelfEraser, _pyObject); @@ -541,7 +591,7 @@ class _pySubMesh: public _pyObject Handle(_pyObject) myCreator; Handle(_pyMesh) myMesh; public: - _pySubMesh(const Handle(_pyCommand)& theCreationCmd); + _pySubMesh(const Handle(_pyCommand)& theCreationCmd, bool toKeepAgrCmds=true); virtual void Process( const Handle(_pyCommand)& theCommand); virtual void Flush(); virtual Handle(_pyMesh) GetMesh() { return myMesh; } @@ -549,7 +599,7 @@ public: void SetCreator( const Handle(_pyObject)& theCreator ) { myCreator = theCreator; } static bool CanBeArgOfMethod(const _AString& theMethodName); - DEFINE_STANDARD_RTTI (_pySubMesh) + DEFINE_STANDARD_RTTIEXT(_pySubMesh,_pyObject) }; // ------------------------------------------------------------------------------------- /*! @@ -559,17 +609,17 @@ public: class _pyFilter: public _pyObject { _pyID myNewID, myMesh; - std::list< Handle(_pyObject) > myUsers; + //std::list< Handle(_pyObject) > myUsers; public: _pyFilter(const Handle(_pyCommand)& theCreationCmd, const _pyID& newID=""); - void AddUser( const Handle(_pyObject)& user) { myUsers.push_back( user ); } + //void AddUser( const Handle(_pyObject)& user) { myUsers.push_back( user ); } virtual void Process( const Handle(_pyCommand)& theCommand); virtual void Flush(); - virtual bool CanClear(); - virtual void Free() { myUsers.clear(); } + //virtual bool CanClear(); + //virtual void Free() { myUsers.clear(); } const _pyID& GetNewID() const { return myNewID; } - DEFINE_STANDARD_RTTI (_pyFilter) + DEFINE_STANDARD_RTTIEXT(_pyFilter,_pyObject) }; DEFINE_STANDARD_HANDLE (_pyFilter, _pyObject); @@ -578,7 +628,7 @@ DEFINE_STANDARD_HANDLE (_pyFilter, _pyObject); * \brief To convert creation of a group by filter */ // ------------------------------------------------------------------------------------- -class _pyGroup: public _pySubMesh +class _pyGroup: public _pySubMesh // use myMesh of _pySubMesh { Handle(_pyFilter) myFilter; bool myCanClearCreationCmd; @@ -587,8 +637,10 @@ public: virtual void Process( const Handle(_pyCommand)& theCommand); virtual void Flush(); virtual void Free() { myFilter.Nullify(); } + virtual bool CanClear(); + void RemovedWithContents(); - DEFINE_STANDARD_RTTI (_pyGroup) + DEFINE_STANDARD_RTTIEXT(_pyGroup,_pySubMesh) }; // ------------------------------------------------------------------------------------- @@ -603,7 +655,7 @@ public: _pyHypothesisReader(); Handle(_pyHypothesis) GetHypothesis(const _AString& hypType, const Handle(_pyCommand)& creationCmd) const; - DEFINE_STANDARD_RTTI (_pyHypothesisReader) + DEFINE_STANDARD_RTTIEXT(_pyHypothesisReader,Standard_Transient) }; #endif