X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_2smeshpy.cxx;h=2d5ee24f1031f8ead9562b5fccb35c59a7fdc5b8;hb=493747e8ea338a2d88204a5f12ba924d72ecbb5b;hp=af9123b210aae038ffbd085318238e6bec9941d8;hpb=34bcb9e1fb0a3d8cfe61939ac53557dc0a2dea57;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index af9123b21..2d5ee24f1 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -204,10 +204,11 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript, _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod, Resource_DataMapOfAsciiStringAsciiString& theObjectNames) : _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )), + myNbCommands( 0 ), myID2AccessorMethod( theEntry2AccessorMethod ), - myObjectNames( theObjectNames ) + myObjectNames( theObjectNames ), + myNbFilters( 0 ) { - myNbCommands = 0; // make that GetID() to return TPythonDump::SMESHGenName() GetCreationCmd()->GetString() += "="; } @@ -309,7 +310,14 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand // aFilterManager.CreateFilter() ? if ( aCommand->GetMethod() == "CreateFilter" ) { - Handle(_pyObject) filter( new _pyFilter( aCommand )); + // Set a more human readable name to a filter + // aFilter0x7fbf6c71cfb0 -> aFilter_nb + _pyID newID, filterID = aCommand->GetResultValue(); + int pos = filterID.Search( "0x" ); + if ( pos > 1 ) + newID = (filterID.SubString(1,pos-1) + "_") + _pyID( ++myNbFilters ); + + Handle(_pyObject) filter( new _pyFilter( aCommand, newID )); AddObject( filter ); } @@ -376,6 +384,17 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand aCommand->SetArg( 2, Type ); aCommand->SetArg( 3, Compare ); + if ( Type == "SMESH.FT_ElemGeomType" && Threshold.IsIntegerValue() ) + { + // set SMESH.GeometryType instead of a numerical Threshold + const char* types[SMESH::Geom_POLYHEDRA+1] = { + "Geom_POINT", "Geom_EDGE", "Geom_TRIANGLE", "Geom_QUADRANGLE", "Geom_POLYGON", + "Geom_TETRA", "Geom_PYRAMID", "Geom_HEXA", "Geom_PENTA", "Geom_POLYHEDRA" + }; + int iGeom = Threshold.IntegerValue(); + if ( -1 < iGeom && iGeom < SMESH::Geom_POLYHEDRA+1 ) + Threshold = SMESH + types[ iGeom ]; + } if ( ThresholdStr.Length() != 2 ) // not '' or "" aCommand->SetArg( 4, ThresholdStr ); else if ( ThresholdID.Length() != 2 ) @@ -438,7 +457,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand ) myMeshes.insert( make_pair( mesh->GetID(), mesh )); return; } - if( method == "CreateMeshesFromMED") + if( method == "CreateMeshesFromMED" || method == "CreateMeshesFromSAUV") { for(int ind = 0;indGetNbResultValues();ind++) { @@ -793,6 +812,18 @@ void _pyGen::AddObject( Handle(_pyObject)& theObj ) { myObjects.insert( make_pair( theObj->GetID(), theObj )); } + +//================================================================================ +/*! + * \brief Finds a _pyObject by ID + */ +//================================================================================ + +Handle(_pyObject) _pyGen::FindObject( const _pyID& theObjID ) const +{ + std::map< _pyID, Handle(_pyObject) >::const_iterator id_obj = myObjects.find( theObjID ); + return ( id_obj == myObjects.end() ) ? Handle(_pyObject)() : id_obj->second; +} //================================================================================ /*! @@ -960,6 +991,23 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand ) else if ( method == "CreateGroupFromFilter" ) // --> GroupOnFilter() { theCommand->SetMethod( "GroupOnFilter" ); + Handle(_pyGroup) group = new _pyGroup( theCommand ); + theGen->AddObject( group ); + + // GroupOnFilter(typ, name, aFilter0x4743dc0 -> aFilter_1) + _pyID filterID = theCommand->GetArg(3); + Handle(_pyObject) filter = theGen->FindObject( filterID ); + if ( !filter.IsNull() && filter->IsKind(STANDARD_TYPE(_pyFilter))) + filter->Process( theCommand ); + } + // ---------------------------------------------------------------------- + else if ( method == "GetIdsFromFilter" ) + { + // GetIdsFromFilter( aFilter0x4743dc0) -> GetIdsFromFilter( aFilter_1) + _pyID filterID = theCommand->GetArg(1); + Handle(_pyObject) filter = theGen->FindObject( filterID ); + if ( !filter.IsNull() && filter->IsKind(STANDARD_TYPE(_pyFilter))) + filter->Process( theCommand ); } // ---------------------------------------------------------------------- else if ( method == "CreateGroup" ) // CreateGroup() --> CreateEmptyGroup() @@ -1075,7 +1123,7 @@ bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand ) static TStringSet sameMethods; if ( sameMethods.empty() ) { const char * names[] = - { "ExportDAT","ExportUNV","ExportSTL", "RemoveGroup","RemoveGroupWithContents", + { "ExportDAT","ExportUNV","ExportSTL","ExportSAUV", "RemoveGroup","RemoveGroupWithContents", "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog", "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements", "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles", @@ -1249,7 +1297,8 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand) "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes", "GetLastCreatedElems", "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh", - "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh" + "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh", + "MakeBoundaryElements" ,"" }; // <- mark of the end sameMethods.Insert( names ); } @@ -1585,6 +1634,9 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th else if ( hypType == "Projection_2D" ) { algo->SetConvMethodAndType( "Projection2D", hypType.ToCString()); } + else if ( hypType == "Projection_1D2D" ) { + algo->SetConvMethodAndType( "Projection1D2D", hypType.ToCString()); + } else if ( hypType == "ProjectionSource2D" ) { hyp->SetConvMethodAndType( "SourceFace", "Projection_2D"); hyp->AddArgMethod( "SetSourceFace"); @@ -1617,6 +1669,16 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get3DHypothesis" ); hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D"); } + // Cartesian 3D --------- + else if ( hypType == "Cartesian_3D" ) { + algo->SetConvMethodAndType( "BodyFitted", hypType.ToCString()); + } + else if ( hypType == "CartesianParameters3D" ) { + hyp = new _pyComplexParamHypo( theCreationCmd ); + hyp->SetConvMethodAndType( "SetGrid", "Cartesian_3D"); + for ( int iArg = 0; iArg < 4; ++iArg ) + hyp->myArgs.Append("[]"); + } return algo->IsValid() ? algo : hyp; } @@ -1787,12 +1849,44 @@ void _pyHypothesis::Assign( const Handle(_pyHypothesis)& theOther, //================================================================================ /*! * \brief Remember hypothesis parameter values - * \param theCommand - The called hypothesis method + * \param theCommand - The called hypothesis method */ //================================================================================ void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand) { + if ( GetAlgoType() == "Cartesian_3D" ) + { + // CartesianParameters3D hyp + + if ( theCommand->GetMethod() == "SetSizeThreshold" ) + { + myArgs( 4 ) = theCommand->GetArg( 1 ); + myArgCommands.push_back( theCommand ); + return; + } + if ( theCommand->GetMethod() == "SetGrid" || + theCommand->GetMethod() == "SetGridSpacing" ) + { + TCollection_AsciiString axis = theCommand->GetArg( theCommand->GetNbArgs() ); + int iArg = 1 + ( axis.Value(1) - '0' ); + if ( theCommand->GetMethod() == "SetGrid" ) + { + myArgs( iArg ) = theCommand->GetArg( 1 ); + } + else + { + myArgs( iArg ) = "[ "; + myArgs( iArg ) += theCommand->GetArg( 1 ); + myArgs( iArg ) += ", "; + myArgs( iArg ) += theCommand->GetArg( 2 ); + myArgs( iArg ) += "]"; + } + myArgCommands.push_back( theCommand ); + return; + } + } + if( theCommand->GetMethod() == "SetLength" ) { // NOW it becomes OBSOLETE @@ -2695,6 +2789,7 @@ void _pySubMesh::Flush() // move to be just after creator myCreator->GetCreationCmd()->AddDependantCmd( GetCreationCmd() ); } + //================================================================================ /*! * \brief To convert creation of a group by filter @@ -2710,31 +2805,25 @@ void _pyGroup::Process( const Handle(_pyCommand)& theCommand) if ( theCommand->GetMethod() == "AddFrom" ) { _pyID idSource = theCommand->GetArg(1); - // check if idSource is a filter: find a command creating idSource, - // it should be "idSource = aFilterManager.CreateFilter()" or - // "idSource = smesh.GetFilterFromCriteria(aCriteria) - const list< Handle(_pyCommand) >& commands = theGen->GetCommands(); - list< Handle(_pyCommand) >::const_reverse_iterator cmdIt = commands.rbegin(); - bool isFilter = false; - for ( ; cmdIt != commands.rend(); ++cmdIt ) - if ( (*cmdIt)->GetResultValue() == idSource ) - { - isFilter = ( (*cmdIt)->GetMethod() == "CreateFilter" || - (*cmdIt)->GetMethod() == "GetFilterFromCriteria" ); - break; - } - if ( !isFilter ) return; - + // check if idSource is a filter + Handle(_pyObject) filter = theGen->FindObject( idSource ); + if ( filter.IsNull() || !filter->IsKind(STANDARD_TYPE(_pyFilter))) + return; // find aFilter.SetMesh(mesh) to clear it, it should be just before theCommand - for ( cmdIt = commands.rbegin(); cmdIt != commands.rend(); ++cmdIt ) - if ( *cmdIt == theCommand && (*cmdIt)->GetOrderNb() != 1 ) + list< Handle(_pyCommand) >::reverse_iterator cmdIt = theGen->GetCommands().rbegin(); + while ( *cmdIt != theCommand ) ++cmdIt; + while ( (*cmdIt)->GetOrderNb() != 1 ) + { + const Handle(_pyCommand)& setMeshCmd = *(++cmdIt); + if ((setMeshCmd->GetObject() == idSource || + setMeshCmd->GetObject() == Handle(_pyFilter)::DownCast(filter)->GetNewID() ) + && + setMeshCmd->GetMethod() == "SetMesh") { - const Handle(_pyCommand)& setMeshCmd = *(++cmdIt); - if ( setMeshCmd->GetObject() == idSource && - setMeshCmd->GetMethod() == "SetMesh") - setMeshCmd->Clear(); + setMeshCmd->Clear(); break; } + } // replace 3 commands by one theCommand->Clear(); const Handle(_pyCommand)& makeGroupCmd = GetCreationCmd(); @@ -2742,17 +2831,57 @@ void _pyGroup::Process( const Handle(_pyCommand)& theCommand) makeGroupCmd->SetMethod( "MakeGroupByFilter" ); makeGroupCmd->SetArg( 1, name ); makeGroupCmd->SetArg( 2, idSource ); + // set new name of a filter + filter->Process( makeGroupCmd ); + } + else if ( theCommand->GetMethod() == "SetFilter" ) + { + // set new name of a filter + _pyID filterID = theCommand->GetArg(1); + Handle(_pyObject) filter = theGen->FindObject( filterID ); + if ( !filter.IsNull() ) + filter->Process( theCommand ); } } //================================================================================ /*! - * \brief To convert creation of a filter by criteria + * \brief Constructor of _pyFilter + */ +//================================================================================ + +_pyFilter::_pyFilter(const Handle(_pyCommand)& theCreationCmd, const _pyID& newID/*=""*/) + :_pyObject(theCreationCmd), myNewID( newID ) +{ +} + +//================================================================================ +/*! + * \brief To convert creation of a filter by criteria and + * to replace an old name by a new one */ //================================================================================ void _pyFilter::Process( const Handle(_pyCommand)& theCommand) { + if ( theCommand->GetObject() == GetID() ) + _pyObject::Process(theCommand); // count commands + + if ( !myNewID.IsEmpty() ) + { + if ( theCommand->GetObject() == GetID() ) + theCommand->SetObject( myNewID ); + else if ( theCommand->GetResultValue() == GetID() ) + theCommand->SetResultValue( myNewID ); + else + for ( int i = 1, nb = theCommand->GetNbArgs(); i <= nb; ++i ) + if ( theCommand->GetArg( i ) == GetID() ) + { + theCommand->SetArg( i, myNewID ); + break; + } + } + // Convert the following set of commands into smesh.GetFilterFromCriteria(criteria) // aFilter0x2aaab0487080 = aFilterManager.CreateFilter() // aFilter0x2aaab0487080.SetCriteria(aCriteria) @@ -2761,7 +2890,10 @@ void _pyFilter::Process( const Handle(_pyCommand)& theCommand) { // aFilter.SetCriteria(aCriteria) -> // aFilter = smesh.GetFilterFromCriteria(criteria) - theCommand->SetResultValue( GetID() ); + if ( myNewID.IsEmpty() ) + theCommand->SetResultValue( GetID() ); + else + theCommand->SetResultValue( myNewID ); theCommand->SetObject( SMESH_2smeshpy::GenName() ); theCommand->SetMethod( "GetFilterFromCriteria" ); @@ -2773,3 +2905,15 @@ void _pyFilter::Process( const Handle(_pyCommand)& theCommand) theGen->AddMeshAccessorMethod( theCommand ); } } + +//================================================================================ +/*! + * \brief Set new filter name to the creation command + */ +//================================================================================ + +void _pyFilter::Flush() +{ + if ( !myNewID.IsEmpty() && !GetCreationCmd()->IsEmpty() ) + GetCreationCmd()->SetResultValue( myNewID ); +}