+ }
+}
+
+//================================================================================
+/*!
+ * \brief Return True if addition of accesor method is needed
+ */
+//================================================================================
+
+bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
+{
+ // names of SMESH_Mesh methods fully equal to methods of python class Mesh,
+ // so no conversion is needed for them at all:
+ static TStringSet sameMethods;
+ if ( sameMethods.empty() ) {
+ const char * names[] =
+ { "ExportDAT","ExportUNV","ExportSTL","ExportSAUV", "RemoveGroup","RemoveGroupWithContents",
+ "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog",
+ "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements",
+ "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles",
+ "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes",
+ "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder",
+ "NbPyramids","NbPyramidsOfOrder","NbPrisms","NbPrismsOfOrder","NbPolyhedrons",
+ "NbSubMesh","GetElementsId","GetElementsByType","GetNodesId","GetElementType",
+ "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
+ "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
+ "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
+ "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
+ "Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder"
+ ,"" }; // <- mark of end
+ sameMethods.Insert( names );
+ }
+
+ return !sameMethods.Contains( theCommand->GetMethod() );
+}
+
+//================================================================================
+/*!
+ * \brief Convert creation and addition of all algos and hypos
+ */
+//================================================================================
+
+void _pyMesh::Flush()
+{
+ {
+ // get the meshes this mesh depends on via hypotheses
+ list< Handle(_pyMesh) > fatherMeshes;
+ list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
+ for ( ; hyp != myHypos.end(); ++hyp )
+ if ( ! (*hyp)->GetReferredMeshesAndGeom( fatherMeshes ))
+ myGeomNotInStudy = true;
+
+ list< Handle(_pyMesh) >::iterator m = fatherMeshes.begin();
+ for ( ; m != fatherMeshes.end(); ++m )
+ addFatherMesh( *m );
+ // if ( removedGeom )
+ // SetRemovedFromStudy(); // as reffered geometry not in study
+ }
+ if ( myGeomNotInStudy )
+ return;
+
+ list < Handle(_pyCommand) >::iterator cmd;
+
+ // try to convert algo addition like this:
+ // mesh.AddHypothesis(geom, ALGO ) --> ALGO = mesh.Algo()
+ for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
+ {
+ Handle(_pyCommand) addCmd = *cmd;
+
+ _pyID algoID = addCmd->GetArg( 2 );
+ Handle(_pyHypothesis) algo = theGen->FindHyp( algoID );
+ if ( algo.IsNull() || !algo->IsAlgo() )
+ continue;
+
+ // check and create new algorithm instance if it is already wrapped
+ if ( algo->IsWrapped() ) {
+ _pyID localAlgoID = theGen->GenerateNewID( algoID );
+ TCollection_AsciiString aNewCmdStr = addCmd->GetIndentation() + localAlgoID +
+ TCollection_AsciiString( " = " ) + theGen->GetID() +
+ TCollection_AsciiString( ".CreateHypothesis( \"" ) + algo->GetAlgoType() +
+ TCollection_AsciiString( "\" )" );
+
+ Handle(_pyCommand) newCmd = theGen->AddCommand( aNewCmdStr );
+ Handle(_pyAlgorithm) newAlgo = Handle(_pyAlgorithm)::DownCast(theGen->FindHyp( localAlgoID ));
+ if ( !newAlgo.IsNull() ) {
+ newAlgo->Assign( algo, this->GetID() );
+ newAlgo->SetCreationCmd( newCmd );
+ algo = newAlgo;
+ // set algorithm creation
+ theGen->SetCommandBefore( newCmd, addCmd );
+ myHypos.push_back( newAlgo );
+ if ( !myLastComputeCmd.IsNull() &&
+ newCmd->GetOrderNb() == myLastComputeCmd->GetOrderNb() + 1)
+ newAlgo->MeshComputed( myLastComputeCmd );
+ }
+ else
+ newCmd->Clear();
+ }
+ _pyID geom = addCmd->GetArg( 1 );
+ bool isLocalAlgo = ( geom != GetGeom() );
+
+ // try to convert
+ if ( algo->Addition2Creation( addCmd, this->GetID() )) // OK
+ {
+ // wrapped algo is created after mesh creation
+ GetCreationCmd()->AddDependantCmd( addCmd );
+
+ if ( isLocalAlgo ) {
+ // mesh.AddHypothesis(geom, ALGO ) --> mesh.AlgoMethod(geom)
+ addCmd->SetArg( addCmd->GetNbArgs() + 1,
+ TCollection_AsciiString( "geom=" ) + geom );
+ // sm = mesh.GetSubMesh(geom, name) --> sm = ALGO.GetSubMesh()
+ list < Handle(_pySubMesh) >::iterator smIt;
+ for ( smIt = mySubmeshes.begin(); smIt != mySubmeshes.end(); ++smIt ) {
+ Handle(_pySubMesh) subMesh = *smIt;
+ Handle(_pyCommand) subCmd = subMesh->GetCreationCmd();
+ if ( geom == subCmd->GetArg( 1 )) {
+ subCmd->SetObject( algo->GetID() );
+ subCmd->RemoveArgs();
+ subMesh->SetCreator( algo );
+ }
+ }
+ }
+ }
+ else // KO - ALGO was already created
+ {
+ // mesh.AddHypothesis(geom, ALGO) --> mesh.AddHypothesis(ALGO, geom=0)
+ addCmd->RemoveArgs();
+ addCmd->SetArg( 1, algoID );
+ if ( isLocalAlgo )
+ addCmd->SetArg( 2, geom );
+ }
+ }
+
+ // try to convert hypo addition like this:
+ // mesh.AddHypothesis(geom, HYPO ) --> HYPO = algo.Hypo()
+ for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
+ {
+ Handle(_pyCommand) addCmd = *cmd;
+ _pyID hypID = addCmd->GetArg( 2 );
+ Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
+ if ( hyp.IsNull() || hyp->IsAlgo() )
+ continue;
+ bool converted = hyp->Addition2Creation( addCmd, this->GetID() );
+ if ( !converted ) {
+ // mesh.AddHypothesis(geom, HYP) --> mesh.AddHypothesis(HYP, geom=0)
+ _pyID geom = addCmd->GetArg( 1 );
+ addCmd->RemoveArgs();
+ addCmd->SetArg( 1, hypID );
+ if ( geom != GetGeom() )
+ addCmd->SetArg( 2, geom );
+ }
+ }
+
+ myAddHypCmds.clear();
+ mySubmeshes.clear();
+
+ // flush hypotheses
+ list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
+ for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
+ (*hyp)->Flush();
+}
+
+//================================================================================
+/*!
+ * \brief Sets myIsPublished of me and of all objects depending on me.
+ */
+//================================================================================
+
+void _pyMesh::SetRemovedFromStudy(const bool isRemoved)
+{
+ _pyObject::SetRemovedFromStudy(isRemoved);
+
+ list< Handle(_pySubMesh) >::iterator sm = mySubmeshes.begin();
+ for ( ; sm != mySubmeshes.end(); ++sm )
+ (*sm)->SetRemovedFromStudy(isRemoved);
+
+ list< Handle(_pyGroup) >::iterator gr = myGroups.begin();
+ for ( ; gr != myGroups.end(); ++gr )
+ (*gr)->SetRemovedFromStudy(isRemoved);
+
+ list< Handle(_pyMesh) >::iterator m = myChildMeshes.begin();
+ for ( ; m != myChildMeshes.end(); ++m )
+ (*m)->SetRemovedFromStudy(isRemoved);
+
+ list< Handle(_pyMeshEditor)>::iterator e = myEditors.begin();
+ for ( ; e != myEditors.end(); ++e )
+ (*e)->SetRemovedFromStudy(isRemoved);
+}
+
+//================================================================================
+/*!
+ * \brief Return true if none of myChildMeshes is in study
+ */
+//================================================================================
+
+bool _pyMesh::CanClear()
+{
+ if ( IsInStudy() )
+ return false;
+
+ list< Handle(_pyMesh) >::iterator m = myChildMeshes.begin();
+ for ( ; m != myChildMeshes.end(); ++m )
+ if ( !(*m)->CanClear() )
+ return false;
+
+ return true;
+}
+
+//================================================================================
+/*!
+ * \brief Clear my commands and commands of mesh editor
+ */
+//================================================================================
+
+void _pyMesh::ClearCommands()
+{
+ if ( !CanClear() )
+ {
+ if ( !IsInStudy() )
+ {
+ // mark all sub-objects as not removed, except child meshes
+ list< Handle(_pyMesh) > children;
+ children.swap( myChildMeshes );
+ SetRemovedFromStudy( false );
+ children.swap( myChildMeshes );
+ }
+ return;
+ }
+ _pyObject::ClearCommands();
+
+ list< Handle(_pySubMesh) >::iterator sm = mySubmeshes.begin();
+ for ( ; sm != mySubmeshes.end(); ++sm )
+ (*sm)->ClearCommands();
+
+ list< Handle(_pyGroup) >::iterator gr = myGroups.begin();
+ for ( ; gr != myGroups.end(); ++gr )
+ (*gr)->ClearCommands();
+
+ list< Handle(_pyMeshEditor)>::iterator e = myEditors.begin();
+ for ( ; e != myEditors.end(); ++e )
+ (*e)->ClearCommands();
+}
+
+//================================================================================
+/*!
+ * \brief Add a father mesh by ID
+ */
+//================================================================================
+
+void _pyMesh::addFatherMesh( const _pyID& meshID )
+{
+ if ( !meshID.IsEmpty() )
+ addFatherMesh( Handle(_pyMesh)::DownCast( theGen->FindObject( meshID )));
+}
+
+//================================================================================
+/*!
+ * \brief Add a father mesh
+ */
+//================================================================================
+
+void _pyMesh::addFatherMesh( const Handle(_pyMesh)& mesh )
+{
+ if ( !mesh.IsNull() )
+ {
+ //myFatherMeshes.push_back( mesh );
+ mesh->myChildMeshes.push_back( this );
+
+ // protect last Compute() from clearing by the next Compute()
+ mesh->myLastComputeCmd.Nullify();
+ }
+}
+
+//================================================================================
+/*!
+ * \brief MeshEditor convert its commands to ones of mesh
+ */
+//================================================================================
+
+_pyMeshEditor::_pyMeshEditor(const Handle(_pyCommand)& theCreationCmd):
+ _pyObject( theCreationCmd )
+{
+ myMesh = theCreationCmd->GetObject();
+ myCreationCmdStr = theCreationCmd->GetString();
+ theCreationCmd->Clear();
+
+ Handle(_pyMesh) mesh = ObjectToMesh( theGen->FindObject( myMesh ));
+ if ( !mesh.IsNull() )
+ mesh->AddEditor( this );
+}
+
+//================================================================================
+/*!
+ * \brief convert its commands to ones of mesh
+ */
+//================================================================================
+
+void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
+{
+ // names of SMESH_MeshEditor methods fully equal to methods of python class Mesh, so
+ // commands calling this methods are converted to calls of methods of Mesh
+ static TStringSet sameMethods;
+ if ( sameMethods.empty() ) {
+ const char * names[] = {
+ "RemoveElements","RemoveNodes","RemoveOrphanNodes","AddNode","Add0DElement","AddEdge","AddFace","AddPolygonalFace",
+ "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode", "MoveClosestNodeToPoint",
+ "InverseDiag","DeleteDiag","Reorient","ReorientObject","TriToQuad","SplitQuad","SplitQuadObject",
+ "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
+ "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
+ "RotationSweep","RotationSweepObject","RotationSweepObject1D","RotationSweepObject2D",
+ "ExtrusionSweep","AdvancedExtrusion","ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D",
+ "ExtrusionAlongPath","ExtrusionAlongPathObject","ExtrusionAlongPathX",
+ "ExtrusionAlongPathObject1D","ExtrusionAlongPathObject2D",
+ "Mirror","MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
+ "FindCoincidentNodes",/*"FindCoincidentNodesOnPart",*/"MergeNodes","FindEqualElements",
+ "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
+ "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
+ "GetLastCreatedElems",
+ "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
+ "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh",
+ "MakeBoundaryElements"
+ ,"" }; // <- mark of the end
+ sameMethods.Insert( names );
+ }
+
+ // names of SMESH_MeshEditor methods which differ from methods of class Mesh
+ // only by last two arguments
+ static TStringSet diffLastTwoArgsMethods;
+ if (diffLastTwoArgsMethods.empty() ) {
+ const char * names[] = {
+ "MirrorMakeGroups","MirrorObjectMakeGroups",
+ "TranslateMakeGroups","TranslateObjectMakeGroups",
+ "RotateMakeGroups","RotateObjectMakeGroups",
+ ""};// <- mark of the end
+ diffLastTwoArgsMethods.Insert( names );
+ }
+
+ const TCollection_AsciiString & method = theCommand->GetMethod();
+ bool isPyMeshMethod = sameMethods.Contains( method );
+ if ( !isPyMeshMethod )
+ {
+ //Replace SMESH_MeshEditor "MakeGroups" functions by the Mesh
+ //functions with the flag "theMakeGroups = True" like:
+ //SMESH_MeshEditor.CmdMakeGroups => Mesh.Cmd(...,True)
+ int pos = method.Search("MakeGroups");
+ if( pos != -1)
+ {
+ isPyMeshMethod = true;
+ bool is0DmethId = ( method == "ExtrusionSweepMakeGroups0D" );
+ bool is0DmethObj = ( method == "ExtrusionSweepObject0DMakeGroups");
+
+ // 1. Remove "MakeGroups" from the Command
+ TCollection_AsciiString aMethod = theCommand->GetMethod();
+ int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1;
+
+ if(is0DmethObj)
+ pos = pos-2; //Remove "0D" from the Command too
+ aMethod.Trunc(pos-1);
+ theCommand->SetMethod(aMethod);
+
+ // 2. And add last "True" argument(s)
+ while(nbArgsToAdd--)
+ theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
+ if( is0DmethId || is0DmethObj )
+ theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
+ }
+ }
+
+ // ExtrusionSweep0D() -> ExtrusionSweep()
+ // ExtrusionSweepObject0D() -> ExtrusionSweepObject()
+ if ( !isPyMeshMethod && ( method == "ExtrusionSweep0D" ||
+ method == "ExtrusionSweepObject0D" ))
+ {
+ isPyMeshMethod=true;
+ theCommand->SetMethod( method.SubString( 1, method.Length()-2));
+ theCommand->SetArg(theCommand->GetNbArgs()+1,"False"); //sets flag "MakeGroups = False"
+ theCommand->SetArg(theCommand->GetNbArgs()+1,"True"); //sets flag "IsNode = True"
+ }
+ // set "ExtrusionAlongPathX()" instead of "ExtrusionAlongPathObjX()"
+ if ( !isPyMeshMethod && method == "ExtrusionAlongPathObjX")
+ {
+ isPyMeshMethod=true;
+ theCommand->SetMethod("ExtrusionAlongPathX");
+ }
+
+ // set "FindCoincidentNodesOnPart()" instead of "FindCoincidentNodesOnPartBut()"
+ if ( !isPyMeshMethod && method == "FindCoincidentNodesOnPartBut")
+ {
+ isPyMeshMethod=true;
+ theCommand->SetMethod("FindCoincidentNodesOnPart");
+ }
+ // DoubleNodeElemGroupNew() -> DoubleNodeElemGroup()
+ // DoubleNodeGroupNew() -> DoubleNodeGroup()
+ // DoubleNodeGroupsNew() -> DoubleNodeGroups()
+ // DoubleNodeElemGroupsNew() -> DoubleNodeElemGroups()
+ if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" ||
+ method == "DoubleNodeElemGroupsNew" ||
+ method == "DoubleNodeGroupNew" ||
+ method == "DoubleNodeGroupsNew"))
+ {
+ isPyMeshMethod=true;
+ theCommand->SetMethod( method.SubString( 1, method.Length()-3));
+ theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
+ }
+ // ConvertToQuadraticObject(bool,obj) -> ConvertToQuadratic(bool,obj)
+ // ConvertFromQuadraticObject(obj) -> ConvertFromQuadratic(obj)
+ if ( !isPyMeshMethod && ( method == "ConvertToQuadraticObject" ||
+ method == "ConvertFromQuadraticObject" ))
+ {
+ isPyMeshMethod=true;
+ theCommand->SetMethod( method.SubString( 1, method.Length()-6));
+ // prevent moving creation of the converted sub-mesh to the end of the script
+ bool isFromQua = ( method.Value( 8 ) == 'F' );
+ Handle(_pySubMesh) sm = theGen->FindSubMesh( theCommand->GetArg( isFromQua ? 1 : 2 ));
+ if ( !sm.IsNull() )
+ sm->Process( theCommand );
+ }
+ // FindAmongElementsByPoint(meshPart, x, y, z, elementType) ->
+ // FindElementsByPoint(x, y, z, elementType, meshPart)
+ if ( !isPyMeshMethod && method == "FindAmongElementsByPoint" )
+ {
+ isPyMeshMethod=true;
+ theCommand->SetMethod( "FindElementsByPoint" );
+ // make the 1st arg be the last one
+ _pyID partID = theCommand->GetArg( 1 );
+ int nbArgs = theCommand->GetNbArgs();
+ for ( int i = 2; i <= nbArgs; ++i )
+ theCommand->SetArg( i-1, theCommand->GetArg( i ));
+ theCommand->SetArg( nbArgs, partID );