X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI.cxx;h=723aec577c2289779ab6e195c911d3bcea7f1c85;hb=064a124120a53ac96aaba2b8fab28eae2ed72801;hp=0721eaeaa920fd5398f2d6de4acd85b920c3c4dc;hpb=4112f94a387c9f65d347cc021871184d24cda19d;p=modules%2Fsmesh.git diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 0721eaeaa..723aec577 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -1,6 +1,6 @@ -// SMESH SMESHGUI : GUI for SMESH component +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or @@ -19,11 +19,12 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// SMESH SMESHGUI : GUI for SMESH component // File : SMESHGUI.cxx // Author : Nicolas REJNERI // Module : SMESH // $Header$ - +// #include "SMESHGUI.h" #include "SMESH_Client.hxx" @@ -69,6 +70,7 @@ #include "SMESHGUI_BuildCompoundDlg.h" #include "SMESHGUI_ComputeDlg.h" #include "SMESHGUI_FileInfoDlg.h" +#include "SMESHGUI_GroupOnShapeDlg.h" #include "SMESHGUI_Utils.h" #include "SMESHGUI_GEOMGenUtils.h" @@ -283,221 +285,227 @@ using namespace std; if( aSel ) aSel->selectedObjects( selected ); - if(selected.Extent()){ - Handle(SALOME_InteractiveObject) anIObject = selected.First(); - SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface(anIObject); - if ( !aMesh->_is_nil() ) { - QString aFilter, aTitle = QObject::tr("Export mesh"); - QMap aFilterMap; - QMap aFilterMapSTL; - switch ( theCommandID ) { - case 125: - case 122: - { - if (aMesh->HasDuplicatedGroupNamesMED()) { - int aRet = SUIT_MessageBox::warn2 - (SMESHGUI::desktop(), - QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()), - QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), - 0, 1, 0); - if (aRet) - return; - } - // PAL18696 - QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2)); - QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2)); - aFilterMap.insert( QString("MED ") + v21 + " (*.med)", SMESH::MED_V2_1 ); - aFilterMap.insert( QString("MED ") + v22 + " (*.med)", SMESH::MED_V2_2 ); - } - break; - case 124: - case 121: - aFilter = QObject::tr("DAT files (*.dat)"); - break; - case 126: - case 123: - { - if (aMesh->NbPyramids()) { - int aRet = SUIT_MessageBox::warn2 - (SMESHGUI::desktop(), - QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()), - QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), - 0, 1, 0); - if (aRet) - return; - } - aFilter = QObject::tr("IDEAS files (*.unv)"); - } - break; - case 140: - case 141: - { - // export STL - /* - there must be check on others mesh elements not equal triangles - */ - if (aMesh->NbTriangles() < 1) { - SUIT_MessageBox::warn1 - (SMESHGUI::desktop(), - QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()), - QObject::tr("SMESH_BUT_OK")); - return; - } - if (!(aMesh->NbElements() - aMesh->NbTriangles())) { - int aRet = SUIT_MessageBox::warn2 - (SMESHGUI::desktop(), - QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()), - QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), - 0, 1, 0); - if (aRet) - return; - } + SMESH::SMESH_Mesh_var aMesh; + if(selected.Extent() == 1) + aMesh = SMESH::IObjectToInterface(selected.First()); + if ( aMesh->_is_nil() ) { + SUIT_MessageBox::warn1( SMESHGUI::desktop(), + QObject::tr( "SMESH_WRN_WARNING" ), + QObject::tr( "SMESH_BAD_MESH_SELECTION" ), + QObject::tr( "SMESH_BUT_OK" ) ); + return; + } - aFilterMapSTL.insert( QObject::tr("STL ASCII (*.stl)"), 1 ); // 1 - ASCII mode - aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode - } - break; - default: - return; - } + Handle(SALOME_InteractiveObject) anIObject = selected.First(); + QString aFilter, aTitle = QObject::tr("Export mesh"); + QMap aFilterMap; + QMap aFilterMapSTL; + switch ( theCommandID ) { + case 125: + case 122: + { + if (aMesh->HasDuplicatedGroupNamesMED()) { + int aRet = SUIT_MessageBox::warn2 + (SMESHGUI::desktop(), + QObject::tr("SMESH_WRN_WARNING"), + QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()), + QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), + 0, 1, 0); + if (aRet) + return; + } + // PAL18696 + QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2)); + QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2)); + aFilterMap.insert( QString("MED ") + v21 + " (*.med)", SMESH::MED_V2_1 ); + aFilterMap.insert( QString("MED ") + v22 + " (*.med)", SMESH::MED_V2_2 ); + } + break; + case 124: + case 121: + aFilter = QObject::tr("DAT files (*.dat)"); + break; + case 126: + case 123: + { + if (aMesh->NbPyramids()) { + int aRet = SUIT_MessageBox::warn2 + (SMESHGUI::desktop(), + QObject::tr("SMESH_WRN_WARNING"), + QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()), + QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), + 0, 1, 0); + if (aRet) + return; + } + aFilter = QObject::tr("IDEAS files (*.unv)"); + } + break; + case 140: + case 141: + { + // export STL + /* + there must be check on others mesh elements not equal triangles + */ + if (aMesh->NbTriangles() < 1) { + SUIT_MessageBox::warn1 + (SMESHGUI::desktop(), + QObject::tr("SMESH_WRN_WARNING"), + QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()), + QObject::tr("SMESH_BUT_OK")); + return; + } + if (!(aMesh->NbElements() - aMesh->NbTriangles())) { + int aRet = SUIT_MessageBox::warn2 + (SMESHGUI::desktop(), + QObject::tr("SMESH_WRN_WARNING"), + QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()), + QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), + 0, 1, 0); + if (aRet) + return; + } - QString aFilename; - SMESH::MED_VERSION aFormat; - // Init the parameter with the default value - bool aIsASCII_STL = true; - bool toCreateGroups = false; - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - if ( resMgr ) - toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false ); - - QString anInitialPath = ""; - if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() ) - anInitialPath = QDir::currentDirPath(); - - if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141) { - if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath(); - aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(), - aFilter, aTitle, false); - } - else if(theCommandID == 140 || theCommandID == 141) { // Export to STL - QStringList filters; - QMap::const_iterator it = aFilterMapSTL.begin(); - for ( ; it != aFilterMapSTL.end(); ++it ) - filters.push_back( it.key() ); - - SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true ); - fd->setCaption( aTitle ); - fd->setFilters( filters ); - fd->setSelectedFilter( QObject::tr("STL ASCII (*.stl)") ); - if ( !anInitialPath.isEmpty() ) - fd->setDir( anInitialPath ); - fd->setSelection(anIObject->getName()); - bool is_ok = false; - while (!is_ok) { - fd->exec(); - aFilename = fd->selectedFile(); - aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false; - is_ok = true; - } - delete fd; - } - else { // Export to MED - QStringList filters; - QString aDefaultFilter; - QMap::const_iterator it = aFilterMap.begin(); - for ( ; it != aFilterMap.end(); ++it ) { - filters.push_back( it.key() ); - if (it.data() == SMESH::MED_V2_2) - aDefaultFilter = it.key(); - } + aFilterMapSTL.insert( QObject::tr("STL ASCII (*.stl)"), 1 ); // 1 - ASCII mode + aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode + } + break; + default: + return; + } - //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true ); - SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg - ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true ); - fd->setCaption( aTitle ); - fd->setFilters( filters ); - //fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") ); - fd->setSelectedFilter(aDefaultFilter); - fd->SetChecked(toCreateGroups); - if ( !anInitialPath.isEmpty() ) - fd->setDir( anInitialPath ); - fd->setSelection(anIObject->getName()); - bool is_ok = false; - while (!is_ok) { - fd->exec(); - aFilename = fd->selectedFile(); - aFormat = aFilterMap[fd->selectedFilter()]; - is_ok = true; - if ( !aFilename.isEmpty() - && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0) - && aFormat==SMESH::MED_V2_1) { - int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(), - QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()), - QObject::tr("SMESH_BUT_YES"), - QObject::tr("SMESH_BUT_NO"), - 0,1,0); - if (aRet) { - is_ok = false; - } - } + QString aFilename; + SMESH::MED_VERSION aFormat; + // Init the parameter with the default value + bool aIsASCII_STL = true; + bool toCreateGroups = false; + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + if ( resMgr ) + toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false ); + + QString anInitialPath = ""; + if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() ) + anInitialPath = QDir::currentDirPath(); + + if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141) { + if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath(); + aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(), + aFilter, aTitle, false); + } + else if(theCommandID == 140 || theCommandID == 141) { // Export to STL + QStringList filters; + QMap::const_iterator it = aFilterMapSTL.begin(); + for ( ; it != aFilterMapSTL.end(); ++it ) + filters.push_back( it.key() ); + + SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true ); + fd->setCaption( aTitle ); + fd->setFilters( filters ); + fd->setSelectedFilter( QObject::tr("STL ASCII (*.stl)") ); + if ( !anInitialPath.isEmpty() ) + fd->setDir( anInitialPath ); + fd->setSelection(anIObject->getName()); + bool is_ok = false; + while (!is_ok) { + fd->exec(); + aFilename = fd->selectedFile(); + aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false; + is_ok = true; + } + delete fd; + } + else { // Export to MED + QStringList filters; + QString aDefaultFilter; + QMap::const_iterator it = aFilterMap.begin(); + for ( ; it != aFilterMap.end(); ++it ) { + filters.push_back( it.key() ); + if (it.data() == SMESH::MED_V2_2) + aDefaultFilter = it.key(); + } + + //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true ); + SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg + ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true ); + fd->setCaption( aTitle ); + fd->setFilters( filters ); + //fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") ); + fd->setSelectedFilter(aDefaultFilter); + fd->SetChecked(toCreateGroups); + if ( !anInitialPath.isEmpty() ) + fd->setDir( anInitialPath ); + fd->setSelection(anIObject->getName()); + bool is_ok = false; + while (!is_ok) { + fd->exec(); + aFilename = fd->selectedFile(); + aFormat = aFilterMap[fd->selectedFilter()]; + is_ok = true; + if ( !aFilename.isEmpty() + && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0) + && aFormat==SMESH::MED_V2_1) { + int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(), + QObject::tr("SMESH_WRN_WARNING"), + QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()), + QObject::tr("SMESH_BUT_YES"), + QObject::tr("SMESH_BUT_NO"), + 0,1,0); + if (aRet) { + is_ok = false; } - toCreateGroups = fd->IsChecked(); - delete fd; } - if ( !aFilename.isEmpty() ) { - // Check whether the file already exists and delete it if yes - QFile aFile( aFilename ); - if ( aFile.exists() ) - aFile.remove(); - SUIT_OverrideCursor wc; - - try { - bool Renumber = false ; - // PAL 14172 : Check of we have to renumber or not from the preferences before export - if (resMgr) - Renumber= resMgr->booleanValue("SMESH","renumbering"); - if (Renumber){ - SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor(); - aMeshEditor->RenumberNodes(); - aMeshEditor->RenumberElements(); - if ( SMESHGUI::automaticUpdate() ) - SMESH::UpdateView(); - } - switch ( theCommandID ) { - case 125: - case 122: - aMesh->ExportToMED( aFilename.latin1(), toCreateGroups, aFormat ); - break; - case 124: - case 121: - aMesh->ExportDAT( aFilename.latin1() ); - break; - case 126: - case 123: - aMesh->ExportUNV( aFilename.latin1() ); - break; - case 140: - case 141: - aMesh->ExportSTL( aFilename.latin1(), aIsASCII_STL ); - break; - default: - break; - } - } - catch (const SALOME::SALOME_Exception& S_ex){ - wc.suspend(); - SUIT_MessageBox::warn1(SMESHGUI::desktop(), - QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_EXPORT_FAILED"), - QObject::tr("SMESH_BUT_OK")); - wc.resume(); - } - } + } + toCreateGroups = fd->IsChecked(); + delete fd; + } + if ( !aFilename.isEmpty() ) { + // Check whether the file already exists and delete it if yes + QFile aFile( aFilename ); + if ( aFile.exists() ) + aFile.remove(); + SUIT_OverrideCursor wc; + + try { + bool Renumber = false ; + // PAL 14172 : Check of we have to renumber or not from the preferences before export + if (resMgr) + Renumber= resMgr->booleanValue("SMESH","renumbering"); + if (Renumber){ + SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor(); + aMeshEditor->RenumberNodes(); + aMeshEditor->RenumberElements(); + if ( SMESHGUI::automaticUpdate() ) + SMESH::UpdateView(); + } + switch ( theCommandID ) { + case 125: + case 122: + aMesh->ExportToMED( aFilename.latin1(), toCreateGroups, aFormat ); + break; + case 124: + case 121: + aMesh->ExportDAT( aFilename.latin1() ); + break; + case 126: + case 123: + aMesh->ExportUNV( aFilename.latin1() ); + break; + case 140: + case 141: + aMesh->ExportSTL( aFilename.latin1(), aIsASCII_STL ); + break; + default: + break; + } + } + catch (const SALOME::SALOME_Exception& S_ex){ + wc.suspend(); + SUIT_MessageBox::warn1(SMESHGUI::desktop(), + QObject::tr("SMESH_WRN_WARNING"), + QObject::tr("SMESH_EXPORT_FAILED"), + QObject::tr("SMESH_BUT_OK")); + wc.resume(); } } } @@ -914,18 +922,28 @@ using namespace std; _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() ) { - _PTR(SObject) aSO = aStudy->FindObjectID(anIt.Value()->getEntry()); + anIO = anIt.Value(); + QString cur = anIt.Value()->getComponentDataType(); + _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry()); if (aSO) { - // check if object is not reference - _PTR(SObject) refobj; - if ( !aSO->ReferencedObject( refobj ) ) - objectCount++; + // check if object is reference + _PTR(SObject) aRefSObj; + aNameList.append("\n - "); + if ( aSO->ReferencedObject( aRefSObj ) ) { + QString aRefName = aRefSObj->GetName(); + aNameList.append( aRefName ); + cur = aRefSObj->GetFatherComponent()->ComponentDataType(); + } + else + aNameList.append(anIO->getName()); + objectCount++; } - QString cur = anIt.Value()->getComponentDataType(); if( aParentComponent.isNull() ) aParentComponent = cur; else if( !aParentComponent.isEmpty() && aParentComponent!=cur ) @@ -946,7 +964,7 @@ using namespace std; if (SUIT_MessageBox::warn2 (SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_REALLY_DELETE"), + QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ), QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1) return; @@ -968,10 +986,10 @@ using namespace std; if ( !strcmp( (char*)anIOR->Value().c_str(), engineIOR().latin1() ) ) continue; } - + //Check the referenced object _PTR(SObject) refobj; if ( aSO && aSO->ReferencedObject( refobj ) ) - continue; // skip references + aSO = refobj; // Delete main Object instead of reference // put the whole hierarchy of sub-objects of the selected SO into a list and // then treat them all starting from the deepest objects (at list back) @@ -1719,6 +1737,11 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) }*/ break; } + case 806: // CREATE GEO GROUP + { + startOperation( 806 ); + break; + } case 801: // CREATE GROUP { if ( !vtkwnd ) @@ -2606,6 +2629,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createSMESHAction( 703, "CREATE_SUBMESH", "ICON_DLG_ADD_SUBMESH" ); createSMESHAction( 704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" ); createSMESHAction( 710, "BUILD_COMPOUND", "ICON_BUILD_COMPOUND" ); + createSMESHAction( 806, "CREATE_GEO_GROUP","ICON_GEO_GROUP" ); createSMESHAction( 801, "CREATE_GROUP", "ICON_SMESH_TREE_GROUP" ); createSMESHAction( 802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" ); createSMESHAction( 803, "EDIT_GROUP", "ICON_EDIT_GROUP" ); @@ -2741,6 +2765,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createMenu( 701, meshId, -1 ); createMenu( separator(), meshId, -1 ); createMenu( 801, meshId, -1 ); + createMenu( 806, meshId, -1 ); createMenu( 802, meshId, -1 ); createMenu( 803, meshId, -1 ); createMenu( separator(), meshId, -1 ); @@ -2835,6 +2860,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createTool( 701, meshTb ); createTool( separator(), meshTb ); createTool( 801, meshTb ); + createTool( 806, meshTb ); createTool( 802, meshTb ); createTool( 803, meshTb ); createTool( separator(), meshTb ); @@ -2944,6 +2970,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createPopupItem( 903, OB, mesh_group ); // WHAT_IS popupMgr()->insert( separator(), -1, 0 ); createPopupItem( 801, OB, mesh ); // CREATE_GROUP + createPopupItem( 806, OB, mesh ); // CREATE_GEO_GROUP createPopupItem( 802, OB, subMesh ); // CONSTRUCT_GROUP popupMgr()->insert( separator(), -1, 0 ); createPopupItem( 1100, OB, hypo); // EDIT HYPOTHESIS @@ -3080,7 +3107,7 @@ void SMESHGUI::initialize( CAM_Application* app ) // Clipping //------------------------------------------------- popupMgr()->insert( action( 1134 ), -1, -1 ); - popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true ); + popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& selcount=1 && isVisible", true ); popupMgr()->insert( separator(), -1, -1 ); @@ -3631,6 +3658,9 @@ LightApp_Operation* SMESHGUI::createOperation( const int id ) const case 704: // Edit mesh/sub-mesh op = new SMESHGUI_MeshOp( false ); break; + case 806: // Create group on geom + op = new SMESHGUI_GroupOnShapeOp(); + break; case 417: //convert to quadratic op = new SMESHGUI_ConvToQuadOp(); break;