From 74a891c6f3692b77f5fc32de3d90334b0d1e9a13 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 5 Feb 2014 09:13:00 +0000 Subject: [PATCH] 22359: Body Fitting algorithm: grid orientation Fix a crash in the release mode + // Creation of this class disables vtkMatplotlibMathTextUtilities + struct MPLMathText_Disabler : protected vtkMatplotlibMathTextUtilities --- src/SMESHGUI/SMESHGUI.cxx | 339 ++++++++++++++++++++------------------ 1 file changed, 178 insertions(+), 161 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 1dca53b61..e94bf1016 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -181,7 +181,23 @@ // of auto-color picking up #define SIMPLE_AUTOCOLOR -//namespace{ +// REMOVE the code about MPLMathText_Disabler if it does not complite at porting to ParaView-4.1 +#include +namespace +{ + // Creation of this class disables vtkMatplotlibMathTextUtilities + struct MPLMathText_Disabler : protected vtkMatplotlibMathTextUtilities + { + MPLMathText_Disabler() + { + vtkMatplotlibMathTextUtilities::MPLMathTextAvailable = + vtkMatplotlibMathTextUtilities::UNAVAILABLE; + } + }; +} + +namespace +{ // Declarations //============================================================= void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh, @@ -195,7 +211,6 @@ void Control( int theCommandID ); - // Definitions //============================================================= void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh, @@ -1698,190 +1713,190 @@ QString RefType = CheckTypeObject(selected.First()); SALOME_ListIteratorOfListIO It(selected); for ( ; It.More(); It.Next()) - { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - QString Type = CheckTypeObject(IObject); - if (Type.compare(RefType) != 0) - return "Heterogeneous Selection"; - } + { + Handle(SALOME_InteractiveObject) IObject = It.Value(); + QString Type = CheckTypeObject(IObject); + if (Type.compare(RefType) != 0) + return "Heterogeneous Selection"; + } return RefType; } +} //namespace - void SMESHGUI::OnEditDelete() - { - // VSR 17/11/04: check if all objects selected belong to SMESH component --> start - LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr(); - SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false ); +void SMESHGUI::OnEditDelete() +{ + // VSR 17/11/04: check if all objects selected belong to SMESH component --> start + LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr(); + SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false ); - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder(); - _PTR(GenericAttribute) anAttr; - _PTR(AttributeIOR) anIOR; - - int objectCount = 0; - QString aNameList; - QString aParentComponent = QString::null; - Handle(SALOME_InteractiveObject) anIO; - for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() ) - { - anIO = anIt.Value(); - QString cur = anIO->getComponentDataType(); - _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry()); - if (aSO) { - // check if object is reference - _PTR(SObject) aRefSObj; - aNameList.append("\n - "); - if ( aSO->ReferencedObject( aRefSObj ) ) { - QString aRefName = QString::fromStdString ( aRefSObj->GetName() ); - aNameList.append( aRefName ); - cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() ); - } - else - aNameList.append(anIO->getName()); - objectCount++; - } + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder(); + _PTR(GenericAttribute) anAttr; + _PTR(AttributeIOR) anIOR; - if( aParentComponent.isNull() ) - aParentComponent = cur; - else if( !aParentComponent.isEmpty() && aParentComponent!=cur ) - aParentComponent = ""; + int objectCount = 0; + QString aNameList; + QString aParentComponent = QString::null; + Handle(SALOME_InteractiveObject) anIO; + for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() ) + { + anIO = anIt.Value(); + QString cur = anIO->getComponentDataType(); + _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry()); + if (aSO) { + // check if object is reference + _PTR(SObject) aRefSObj; + aNameList.append("\n - "); + if ( aSO->ReferencedObject( aRefSObj ) ) { + QString aRefName = QString::fromStdString ( aRefSObj->GetName() ); + aNameList.append( aRefName ); + cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() ); + } + else + aNameList.append(anIO->getName()); + objectCount++; } - if ( objectCount == 0 ) - return; // No Valid Objects Selected + if( aParentComponent.isNull() ) + aParentComponent = cur; + else if( !aParentComponent.isEmpty() && aParentComponent!=cur ) + aParentComponent = ""; + } - if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() ) { - SUIT_MessageBox::warning( SMESHGUI::desktop(), - QObject::tr("ERR_ERROR"), - QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) ); - return; - } - // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish - if (SUIT_MessageBox::warning - (SMESHGUI::desktop(), - QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ), - SUIT_MessageBox::Yes | SUIT_MessageBox::No, - SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes) - return; + if ( objectCount == 0 ) + return; // No Valid Objects Selected - SalomeApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() ) { + SUIT_MessageBox::warning( SMESHGUI::desktop(), + QObject::tr("ERR_ERROR"), + QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) ); + return; + } + // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish + if (SUIT_MessageBox::warning + (SMESHGUI::desktop(), + QObject::tr("SMESH_WRN_WARNING"), + QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes) + return; - // Put the whole hierarchy of sub-objects of the selected SO's into a list and - // then treat them all starting from the deepest objects (at list back) - std::list< _PTR(SObject) > listSO; - SALOME_ListIteratorOfListIO It(selected); - for( ; It.More(); It.Next()) // loop on selected IO's - { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - if(IObject->hasEntry()) { - _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry()); - - // disable removal of "SMESH" component object - if(aSO->FindAttribute(anAttr, "AttributeIOR")){ - anIOR = anAttr; - if ( engineIOR() == anIOR->Value().c_str() ) - continue; - } - //Check the referenced object - _PTR(SObject) aRefSObject; - if ( aSO && aSO->ReferencedObject( aRefSObject ) ) - aSO = aRefSObject; // Delete main Object instead of reference - - listSO.push_back( aSO ); - std::list< _PTR(SObject) >::iterator itSO = --listSO.end(); - for ( ; itSO != listSO.end(); ++itSO ) { - _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO ); - for (it->InitEx(false); it->More(); it->Next()) - listSO.push_back( it->Value() ); - } + SalomeApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); + + // Put the whole hierarchy of sub-objects of the selected SO's into a list and + // then treat them all starting from the deepest objects (at list back) + std::list< _PTR(SObject) > listSO; + SALOME_ListIteratorOfListIO It(selected); + for( ; It.More(); It.Next()) // loop on selected IO's + { + Handle(SALOME_InteractiveObject) IObject = It.Value(); + if(IObject->hasEntry()) { + _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry()); + + // disable removal of "SMESH" component object + if(aSO->FindAttribute(anAttr, "AttributeIOR")){ + anIOR = anAttr; + if ( engineIOR() == anIOR->Value().c_str() ) + continue; + } + //Check the referenced object + _PTR(SObject) aRefSObject; + if ( aSO && aSO->ReferencedObject( aRefSObject ) ) + aSO = aRefSObject; // Delete main Object instead of reference + + listSO.push_back( aSO ); + std::list< _PTR(SObject) >::iterator itSO = --listSO.end(); + for ( ; itSO != listSO.end(); ++itSO ) { + _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO ); + for (it->InitEx(false); it->More(); it->Next()) + listSO.push_back( it->Value() ); } } - // Check if none of objects to delete is referred from outside - std::list< _PTR(SObject) >::reverse_iterator ritSO; - for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO ) - { - _PTR(SObject) SO = *ritSO; - if ( !SO ) continue; - std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( *ritSO ); - for (size_t i = 0; i < aReferences.size(); i++) { - _PTR(SComponent) aComponent = aReferences[i]->GetFatherComponent(); - std::string type = aComponent->ComponentDataType(); - if ( type != "SMESH" ) - { - SUIT_MessageBox::warning( anApp->desktop(), - QObject::tr("WRN_WARNING"), - QObject::tr("DEP_OBJECT") ); - return; // outside SMESH, there is an object depending on a SMESH object - } + } + // Check if none of objects to delete is referred from outside + std::list< _PTR(SObject) >::reverse_iterator ritSO; + for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO ) + { + _PTR(SObject) SO = *ritSO; + if ( !SO ) continue; + std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( *ritSO ); + for (size_t i = 0; i < aReferences.size(); i++) { + _PTR(SComponent) aComponent = aReferences[i]->GetFatherComponent(); + std::string type = aComponent->ComponentDataType(); + if ( type != "SMESH" ) + { + SUIT_MessageBox::warning( anApp->desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("DEP_OBJECT") ); + return; // outside SMESH, there is an object depending on a SMESH object } } + } - // Call mesh->Clear() to prevent loading mesh from file caused by hypotheses removal - for( It.Initialize( selected ); It.More(); It.Next()) // loop on selected IO's - { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface< SMESH::SMESH_Mesh >( IObject ); - if ( !mesh->_is_nil() ) - mesh->Clear(); - } + // Call mesh->Clear() to prevent loading mesh from file caused by hypotheses removal + for( It.Initialize( selected ); It.More(); It.Next()) // loop on selected IO's + { + Handle(SALOME_InteractiveObject) IObject = It.Value(); + SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface< SMESH::SMESH_Mesh >( IObject ); + if ( !mesh->_is_nil() ) + mesh->Clear(); + } - // Treat SO's in the list starting from the back - aStudyBuilder->NewCommand(); // There is a transaction - for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO ) - { - _PTR(SObject) SO = *ritSO; - if ( !SO ) continue; - std::string anEntry = SO->GetID(); + // Treat SO's in the list starting from the back + aStudyBuilder->NewCommand(); // There is a transaction + for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO ) + { + _PTR(SObject) SO = *ritSO; + if ( !SO ) continue; + std::string anEntry = SO->GetID(); - /** Erase graphical object and remove all its data **/ - if(SO->FindAttribute(anAttr, "AttributeIOR")) { - SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true); - } - /** Remove an object from data structures **/ - SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO )); - SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO )); - if ( !aGroup->_is_nil() ) { // DELETE GROUP - SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh(); - aMesh->RemoveGroup( aGroup ); - } - else if ( !aSubMesh->_is_nil() ) { // DELETE SUBMESH - SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather(); - aMesh->RemoveSubMesh( aSubMesh ); + /** Erase graphical object and remove all its data **/ + if(SO->FindAttribute(anAttr, "AttributeIOR")) { + SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true); + } + /** Remove an object from data structures **/ + SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO )); + SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO )); + if ( !aGroup->_is_nil() ) { // DELETE GROUP + SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh(); + aMesh->RemoveGroup( aGroup ); + } + else if ( !aSubMesh->_is_nil() ) { // DELETE SUBMESH + SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather(); + aMesh->RemoveSubMesh( aSubMesh ); - _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh); - if (aMeshSO) - SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0); + _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh); + if (aMeshSO) + SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0); + } + else { + Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject + ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() ); + QString objType = CheckTypeObject(IObject); + if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS + SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject); + aStudyBuilder->RemoveObjectWithChildren( SO ); } - else { - Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject - ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() ); - QString objType = CheckTypeObject(IObject); - if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS - SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject); - aStudyBuilder->RemoveObjectWithChildren( SO ); - } - else {// default action: remove SObject from the study - // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH - //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy); - //op->start(); - aStudyBuilder->RemoveObjectWithChildren( SO ); - //op->finish(); - } + else {// default action: remove SObject from the study + // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH + //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy); + //op->start(); + aStudyBuilder->RemoveObjectWithChildren( SO ); + //op->finish(); } - } /* listSO back loop */ + } + } /* listSO back loop */ - aStudyBuilder->CommitCommand(); + aStudyBuilder->CommitCommand(); - /* Clear any previous selection */ - SALOME_ListIO l1; - aSel->setSelectedObjects( l1 ); + /* Clear any previous selection */ + SALOME_ListIO l1; + aSel->setSelectedObjects( l1 ); - SMESHGUI::GetSMESHGUI()->updateObjBrowser(); - } -//} namespace + SMESHGUI::GetSMESHGUI()->updateObjBrowser(); +} extern "C" { SMESHGUI_EXPORT CAM_Module* createModule() @@ -1939,6 +1954,8 @@ SalomeApp_Module( "SMESH" ) /* load resources for all available meshers */ SMESH::InitAvailableHypotheses(); + + MPLMathText_Disabler d; // disable vtkMatplotlibMathTextUtilities } //============================================================================= -- 2.30.2