_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() += "=";
}
// 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 );
}
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 )
myMeshes.insert( make_pair( mesh->GetID(), mesh ));
return;
}
- if ( method == "CreateMeshesFromUNV" || method == "CreateMeshesFromSTL" || method == "CopyMesh" )
+ if ( method == "CreateMeshesFromUNV" ||
+ method == "CreateMeshesFromSTL" ||
+ method == "CreateMeshesFromCGNS" ||
+ method == "CopyMesh" )
{
Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
myMeshes.insert( make_pair( mesh->GetID(), mesh ));
return;
}
- if( method == "CreateMeshesFromMED")
+ if( method == "CreateMeshesFromMED" || method == "CreateMeshesFromSAUV")
{
for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
{
{
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;
+}
//================================================================================
/*!
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()
theCommand->SetMethod( "ExportMED" );
}
// ----------------------------------------------------------------------
+ else if ( method == "ExportCGNS" )
+ { // ExportCGNS(part, ...) -> ExportCGNS(..., part)
+ _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 );
+ }
+ // ----------------------------------------------------------------------
else if ( method.Location( "ExportPartTo", 1, method.Length() ) == 1 )
{ // ExportPartTo*(part, ...) -> Export*(..., part)
//
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",
"SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
"GetLastCreatedElems",
"MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
- "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh"
+ "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh",
+ "MakeBoundaryElements"
,"" }; // <- mark of the end
sameMethods.Insert( names );
}
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");
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;
}
//================================================================================
/*!
* \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
// move to be just after creator
myCreator->GetCreationCmd()->AddDependantCmd( GetCreationCmd() );
}
+
//================================================================================
/*!
* \brief To convert creation of a group by filter
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();
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)
{
// 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" );
theGen->AddMeshAccessorMethod( theCommand );
}
}
+
+//================================================================================
+/*!
+ * \brief Set new filter name to the creation command
+ */
+//================================================================================
+
+void _pyFilter::Flush()
+{
+ if ( !myNewID.IsEmpty() && !GetCreationCmd()->IsEmpty() )
+ GetCreationCmd()->SetResultValue( myNewID );
+}