}
};
+ //================================================================================
+ /*!
+ * \brief Map of TCollection_AsciiString initialized by C array of C strings.
+ * Odd items of the C array are map keys, and even items are values
+ */
+ //================================================================================
+
+ struct TStringMap: public map<TCollection_AsciiString,TCollection_AsciiString>
+ {
+ /*!
+ * \brief Filling. The last string must be ""
+ */
+ void Insert(const char* names_values[]) {
+ for ( int i = 0; names_values[i][0] ; i += 2 )
+ insert( make_pair( (char*) names_values[i], names_values[i+1] ));
+ }
+ /*!
+ * \brief Check if a string is in
+ */
+ TCollection_AsciiString Value(const TCollection_AsciiString& name ) {
+ map< _AString, _AString >::iterator it = find( name );
+ return it == end() ? "" : it->second;
+ }
+ };
+
//================================================================================
/*!
* \brief Returns a mesh by object
groups = aCommand->GetResultValue(2);
else if ( method == "MakeBoundaryElements")
groups = aCommand->GetResultValue(3);
+ else if ( method == "Create0DElementsOnAllNodes" &&
+ aCommand->GetArg(2).Length() > 2 ) // group name != ''
+ groups = aCommand->GetResultValue();
id_editor->second->Process( aCommand );
id_editor->second->AddProcessedCmd( aCommand );
+ // create meshes
if ( !meshID.IsEmpty() &&
!myMeshes.count( meshID ) &&
aCommand->IsStudyEntry( meshID ))
aCommand->Clear();
aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
}
+ // create groups
if ( !groups.IsEmpty() )
{
if ( !aCommand->IsStudyEntry( meshID ))
myGroups.push_back( group );
theGen->AddObject( group );
}
+ // update list of groups
+ else if ( method == "GetGroups" )
+ {
+ TCollection_AsciiString grIDs = theCommand->GetResultValue();
+ list< _pyID > idList = theCommand->GetStudyEntries( grIDs );
+ list< _pyID >::iterator grID = idList.begin();
+ for ( ; grID != idList.end(); ++grID )
+ {
+ Handle(_pyObject) obj = theGen->FindObject( *grID );
+ if ( obj.IsNull() )
+ {
+ Handle(_pyGroup) group = new _pyGroup( theCommand, *grID );
+ theGen->AddObject( group );
+ myGroups.push_back( group );
+ }
+ }
+ }
+ // notify a group about full removal
+ else if ( method == "RemoveGroupWithContents" )
+ {
+ if ( !theGen->IsToKeepAllCommands() ) { // snapshot mode
+ const _pyID groupID = theCommand->GetArg( 1 );
+ Handle(_pyGroup) grp = Handle(_pyGroup)::DownCast( theGen->FindObject( groupID ));
+ if ( !grp.IsNull() )
+ grp->RemovedWithContents();
+ }
+ }
// ----------------------------------------------------------------------
else if ( theCommand->MethodStartsFrom( "Export" ))
{
subMesh->Process( theCommand ); // it moves GetSubMesh() before theCommand
}
}
- // update list of groups
- else if ( method == "GetGroups" )
- {
- TCollection_AsciiString grIDs = theCommand->GetResultValue();
- list< _pyID > idList = theCommand->GetStudyEntries( grIDs );
- list< _pyID >::iterator grID = idList.begin();
- for ( ; grID != idList.end(); ++grID )
- {
- Handle(_pyObject) obj = theGen->FindObject( *grID );
- if ( obj.IsNull() )
- {
- Handle(_pyGroup) group = new _pyGroup( theCommand, *grID );
- theGen->AddObject( group );
- myGroups.push_back( group );
- }
- }
- }
// add accessor method if necessary
else
{
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
+ // names of SMESH_MeshEditor methods fully equal to methods of the python class Mesh, so
+ // commands calling this methods are converted to calls of Mesh methods
static TStringSet sameMethods;
if ( sameMethods.empty() ) {
const char * names[] = {
sameMethods.Insert( names );
}
- // names of SMESH_MeshEditor methods which differ from methods of class Mesh
+ // names of SMESH_MeshEditor commands in which only a method name must be replaced
+ TStringMap diffMethods;
+ if ( diffMethods.empty() ) {
+ const char * orig2newName[] = {
+ // original name --------------> new name
+ "ExtrusionAlongPathObjX" , "ExtrusionAlongPathX",
+ "FindCoincidentNodesOnPartBut", "FindCoincidentNodesOnPart",
+ "ConvertToQuadraticObject" , "ConvertToQuadratic",
+ "ConvertFromQuadraticObject" , "ConvertFromQuadratic",
+ "Create0DElementsOnAllNodes" , "Add0DElementsToAllNodes",
+ ""};// <- mark of the end
+ diffMethods.Insert( orig2newName );
+ }
+
+ // names of SMESH_MeshEditor methods which differ from methods of Mesh class
// only by last two arguments
static TStringSet diffLastTwoArgsMethods;
if (diffLastTwoArgsMethods.empty() ) {
diffLastTwoArgsMethods.Insert( names );
}
+ // only a method name is to change?
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)
+ TCollection_AsciiString newMethod = diffMethods.Value( method );
+ if (( isPyMeshMethod = ( newMethod.Length() > 0 )))
+ theCommand->SetMethod( newMethod );
+ }
+
+ 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)
{
}
}
- // ExtrusionSweep0D() -> ExtrusionSweep()
+ // ExtrusionSweep0D() -> ExtrusionSweep()
// ExtrusionSweepObject0D() -> ExtrusionSweepObject()
if ( !isPyMeshMethod && ( method == "ExtrusionSweep0D" ||
method == "ExtrusionSweepObject0D" ))
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");
- }
// DoubleNode...New(...) -> DoubleNode...(...,True)
if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" ||
method == "DoubleNodeElemGroupsNew" ||
theCommand->SetResultValue( groupID );
}
}
- // 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));
- }
// FindAmongElementsByPoint(meshPart, x, y, z, elementType) ->
// FindElementsByPoint(x, y, z, elementType, meshPart)
if ( !isPyMeshMethod && method == "FindAmongElementsByPoint" )
theCommand->SetArg( 3, face );
}
- // meshes made by *MakeMesh() methods are not wrapped by _pyMesh,
- // so let _pyMesh care of it (TMP?)
- // if ( theCommand->GetMethod().Search("MakeMesh") != -1 )
- // _pyMesh( new _pyCommand( theCommand->GetString(), 0 )); // for theGen->SetAccessorMethod()
if ( isPyMeshMethod )
{
theCommand->SetObject( myMesh );
else
{
// editor creation command is needed only if any editor function is called
- theGen->AddMeshAccessorMethod( theCommand ); // for *Object()
+ theGen->AddMeshAccessorMethod( theCommand ); // for *Object() methods
if ( !myCreationCmdStr.IsEmpty() ) {
GetCreationCmd()->GetString() = myCreationCmdStr;
myCreationCmdStr.Clear();
"TranslateObjectMakeGroups","TranslateObjectMakeMesh","ScaleMakeGroups","ScaleMakeMesh",
"RotateObject","RotateObjectMakeGroups","RotateObjectMakeMesh","FindCoincidentNodesOnPart",
"FindCoincidentNodesOnPartBut","FindEqualElements","FindAmongElementsByPoint",
- "MakeBoundaryMesh",
+ "MakeBoundaryMesh","Create0DElementsOnAllNodes",
"" }; // <- mark of end
methods.Insert( names );
}
}
}
+//================================================================================
+/*!
+ * \brief set myCanClearCreationCmd = true if the main action of the creation
+ * command is discarded
+ */
+//================================================================================
+
+void _pyGroup::RemovedWithContents()
+{
+ // this code would be appropriate if Add0DElementsToAllNodes() returned only new nodes
+ // via a created group
+ //if ( GetCreationCmd()->GetMethod() == "Add0DElementsToAllNodes")
+ // myCanClearCreationCmd = true;
+}
+
//================================================================================
/*!
* \brief To convert creation of a group by filter
//================================================================================
/*!
* \brief Prevent clearing "DoubleNode...() command if a group created by it is removed
- *
- *
*/
//================================================================================