1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 #include <Standard_math.hxx> // E.A. must be included before Python.h to fix compilation on windows
27 #undef HAVE_FINITE // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
33 #include "SMESHGUI_Add0DElemsOnAllNodesDlg.h"
34 #include "SMESHGUI_AddMeshElementDlg.h"
35 #include "SMESHGUI_AddQuadraticElementDlg.h"
36 #include "SMESHGUI_BuildCompoundDlg.h"
37 #include "SMESHGUI_ClippingDlg.h"
38 #include "SMESHGUI_ComputeDlg.h"
39 #include "SMESHGUI_ConvToQuadOp.h"
40 #include "SMESHGUI_CopyMeshDlg.h"
41 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
42 #include "SMESHGUI_DeleteGroupDlg.h"
43 #include "SMESHGUI_Displayer.h"
44 #include "SMESHGUI_DuplicateNodesDlg.h"
45 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
46 #include "SMESHGUI_ExtrusionDlg.h"
47 #include "SMESHGUI_FieldSelectorWdg.h"
48 #include "SMESHGUI_FileInfoDlg.h"
49 #include "SMESHGUI_FileValidator.h"
50 #include "SMESHGUI_FilterDlg.h"
51 #include "SMESHGUI_FilterLibraryDlg.h"
52 #include "SMESHGUI_FindElemByPointDlg.h"
53 #include "SMESHGUI_GroupDlg.h"
54 #include "SMESHGUI_GroupOnShapeDlg.h"
55 #include "SMESHGUI_GroupOpDlg.h"
56 #include "SMESHGUI_Hypotheses.h"
57 #include "SMESHGUI_Make2DFrom3DOp.h"
58 #include "SMESHGUI_MakeNodeAtPointDlg.h"
59 #include "SMESHGUI_Measurements.h"
60 #include "SMESHGUI_MergeDlg.h"
61 #include "SMESHGUI_MeshInfo.h"
62 #include "SMESHGUI_MeshOp.h"
63 #include "SMESHGUI_MeshOrderOp.h"
64 #include "SMESHGUI_MeshPatternDlg.h"
65 #include "SMESHGUI_MultiEditDlg.h"
66 #include "SMESHGUI_NodesDlg.h"
67 #include "SMESHGUI_Operations.h"
68 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
69 #include "SMESHGUI_PropertiesDlg.h"
70 #include "SMESHGUI_RemoveElementsDlg.h"
71 #include "SMESHGUI_RemoveNodesDlg.h"
72 #include "SMESHGUI_RenumberingDlg.h"
73 #include "SMESHGUI_ReorientFacesDlg.h"
74 #include "SMESHGUI_RevolutionDlg.h"
75 #include "SMESHGUI_RotationDlg.h"
76 #include "SMESHGUI_ScaleDlg.h"
77 #include "SMESHGUI_Selection.h"
78 #include "SMESHGUI_SewingDlg.h"
79 #include "SMESHGUI_SingleEditDlg.h"
80 #include "SMESHGUI_SmoothingDlg.h"
81 #include "SMESHGUI_SymmetryDlg.h"
82 #include "SMESHGUI_TranslationDlg.h"
83 #include "SMESHGUI_TransparencyDlg.h"
84 #include "SMESHGUI_DisplayEntitiesDlg.h"
85 #include "SMESHGUI_SplitBiQuad.h"
87 #include "SMESHGUI_FilterUtils.h"
88 #include "SMESHGUI_GEOMGenUtils.h"
89 #include "SMESHGUI_GroupUtils.h"
90 #include "SMESHGUI_HypothesesUtils.h"
91 #include "SMESHGUI_MeshUtils.h"
92 #include "SMESHGUI_PatternUtils.h"
93 #include "SMESHGUI_Utils.h"
94 #include "SMESHGUI_VTKUtils.h"
96 #include "SMESH_version.h"
98 #include "SMESH_ControlsDef.hxx"
99 #include "SMESH_Actor.h"
100 #include "SMESH_ActorUtils.h"
101 #include "SMESH_Client.hxx"
102 #include "SMESH_ScalarBarActor.h"
103 #include "SMESH_TypeFilter.hxx"
105 // SALOME GUI includes
106 #include <SalomeApp_Application.h>
107 #include <SalomeApp_CheckFileDlg.h>
108 #include <SalomeApp_DataObject.h>
109 #include <SalomeApp_Study.h>
110 #include <SalomeApp_Tools.h>
112 #include <LightApp_DataOwner.h>
113 #include <LightApp_NameDlg.h>
114 #include <LightApp_Preferences.h>
115 #include <LightApp_SelectionMgr.h>
116 #include <LightApp_UpdateFlags.h>
118 #include <SVTK_ViewManager.h>
119 #include <SVTK_ViewModel.h>
120 #include <SVTK_ViewWindow.h>
122 #include <VTKViewer_Algorithm.h>
124 #include <SUIT_Desktop.h>
125 #include <SUIT_FileDlg.h>
126 #include <SUIT_MessageBox.h>
127 #include <SUIT_OverrideCursor.h>
128 #include <SUIT_ResourceMgr.h>
129 #include <SUIT_Session.h>
131 #include <QtxPopupMgr.h>
132 #include <QtxFontEdit.h>
134 #include <SALOME_ListIO.hxx>
136 #ifndef DISABLE_PLOT2DVIEWER
137 #include <SPlot2d_ViewModel.h>
138 #include <SPlot2d_Histogram.h>
142 #include <SALOMEconfig.h>
143 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
144 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
145 #include CORBA_CLIENT_HEADER(SMESH_Measurements)
148 // #define INCLUDE_MENUITEM_DEF // VSR commented ????????
149 #include <QApplication>
151 #include <QTextStream>
156 #include <boost/shared_ptr.hpp>
159 #include <vtkCallbackCommand.h>
160 #include <vtkCamera.h>
161 #include <vtkLookupTable.h>
162 #include <vtkPlane.h>
163 #include <vtkRenderer.h>
165 // SALOME KERNEL includes
166 #include <SALOMEDSClient_ClientFactory.hxx>
167 #include <SALOMEDSClient_IParameters.hxx>
168 #include <SALOMEDSClient_SComponent.hxx>
169 #include <SALOMEDSClient_StudyBuilder.hxx>
170 #include <SALOMEDS_Study.hxx>
171 #include <SALOMEDS_SObject.hxx>
172 #include "utilities.h"
175 #include <Standard_ErrorHandler.hxx>
176 #include <NCollection_DataMap.hxx>
177 #include <NCollection_DoubleMap.hxx>
179 #include <Basics_Utils.hxx>
181 //To disable automatic genericobj management, the following line should be commented.
182 //Otherwise, it should be uncommented.
183 //Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
184 #define WITHGENERICOBJ
186 // Below macro, when uncommented, switches on simplified (more performant) algorithm
187 // of auto-color picking up
188 #define SIMPLE_AUTOCOLOR
193 //=============================================================
194 void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
197 void ExportMeshToFile(int theCommandID);
199 void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap);
201 void SetDisplayEntity(int theCommandID);
203 int ActionToControl( int theID, bool theReversed = false );
205 void Control( int theCommandID );
208 //================================================================================
210 * \brief Reads meshes from file
212 //================================================================================
214 void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
218 std::string myExtension;
220 if ( theCommandID == SMESHOp::OpImportMED ) {
221 filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.*med)" );
222 filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
224 else if ( theCommandID == SMESHOp::OpImportUNV ) {
225 filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
227 else if ( theCommandID == SMESHOp::OpImportDAT ) {
228 filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
230 else if ( theCommandID == SMESHOp::OpImportSTL ) {
231 filter.append( QObject::tr( "STL_FILES_FILTER" ) + " (*.stl)" );
234 else if ( theCommandID == SMESHOp::OpImportCGNS ) {
235 filter.append( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
238 else if ( theCommandID == SMESHOp::OpImportSAUV ) {
239 filter.append( QObject::tr( "SAUV files (*.sauv*)" ) );
240 filter.append( QObject::tr( "All files (*)" ) );
242 else if ( theCommandID == SMESHOp::OpImportGMF ) {
243 filter.append( QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)" );
244 filter.append( QObject::tr( "GMF_BINARY_FILES_FILTER") + " (*.meshb)" );
247 QString anInitialPath = "";
248 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
249 anInitialPath = QDir::currentPath();
251 QStringList filenames;
252 bool toCreateGroups = true;
254 // if ( theCommandID == SMESHOp::OpImportGMF ) { // GMF
255 // SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
256 // ( SMESHGUI::desktop(), true, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
257 // fd->setWindowTitle( QObject::tr( "SMESH_IMPORT_MESH" ) );
258 // fd->setNameFilters( filter );
259 // fd->SetChecked( true );
261 // filenames << fd->selectedFile();
262 // toCreateGroups = fd->IsChecked();
268 filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
271 QObject::tr( "SMESH_IMPORT_MESH" ) );
273 if ( filenames.count() > 0 ) {
274 SUIT_OverrideCursor wc;
275 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
278 QStringList anEntryList;
279 bool isEmpty = false;
280 for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
281 QString filename = *it;
282 SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
284 switch ( theCommandID ) {
285 case SMESHOp::OpImportDAT:
287 // DAT format (currently unsupported)
288 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
289 arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
292 case SMESHOp::OpImportUNV:
295 aMeshes->length( 1 );
296 aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toUtf8().constData() );
297 if ( aMeshes[0]->_is_nil() )
298 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
299 arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
302 case SMESHOp::OpImportMED:
305 SMESH::DriverMED_ReadStatus res;
306 aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toUtf8().constData(), res );
307 if ( res != SMESH::DRS_OK ) {
308 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
309 arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
313 case SMESHOp::OpImportSTL:
316 aMeshes->length( 1 );
317 aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toUtf8().constData() );
318 if ( aMeshes[0]->_is_nil() ) {
319 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
320 arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
325 case SMESHOp::OpImportCGNS:
328 SMESH::DriverMED_ReadStatus res;
329 aMeshes = theComponentMesh->CreateMeshesFromCGNS( filename.toUtf8().constData(), res );
330 if ( res != SMESH::DRS_OK ) {
331 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
332 arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
337 case SMESHOp::OpImportSAUV:
340 SMESH::DriverMED_ReadStatus res;
341 aMeshes = theComponentMesh->CreateMeshesFromSAUV( filename.toUtf8().constData(), res );
342 if ( res != SMESH::DRS_OK ) {
343 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
344 arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
348 case SMESHOp::OpImportGMF:
351 SMESH::ComputeError_var res;
352 aMeshes->length( 1 );
353 aMeshes[0] = theComponentMesh->CreateMeshesFromGMF( filename.toUtf8().constData(),
356 if ( res->code != SMESH::DRS_OK ) {
357 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
358 arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res->code ).toLatin1().data() ) ) );
359 if ( strlen( res->comment.in() ) > 0 ) {
360 errors.back() += ": ";
361 errors.back() += res->comment.in();
368 catch ( const SALOME::SALOME_Exception& S_ex ) {
369 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
370 arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
373 for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
374 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
376 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
377 _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
378 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
379 if ( theCommandID == SMESHOp::OpImportUNV ) // mesh names aren't taken from the file for UNV import
380 SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
382 anEntryList.append( aMeshSO->GetID().c_str() );
390 // update Object browser
391 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
393 // browse to the published meshes
394 if( LightApp_Application* anApp =
395 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
396 anApp->browseObjects( anEntryList );
398 // show Error message box if there were errors
399 if ( errors.count() > 0 ) {
400 SUIT_MessageBox::critical( SMESHGUI::desktop(),
401 QObject::tr( "SMESH_ERROR" ),
402 QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
405 // show warning message box, if some imported mesh is empty
407 SUIT_MessageBox::warning( SMESHGUI::desktop(),
408 QObject::tr( "SMESH_WRN_WARNING" ),
409 QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
414 //================================================================================
416 * \brief Export selected meshes or groups into a file
418 //================================================================================
420 void ExportMeshToFile( int theCommandID )
422 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
423 SALOME_ListIO selected;
425 aSel->selectedObjects( selected );
427 const bool isDAT = ( theCommandID == SMESHOp::OpExportDAT || theCommandID == SMESHOp::OpPopupExportDAT );
428 const bool isMED = ( theCommandID == SMESHOp::OpExportMED || theCommandID == SMESHOp::OpPopupExportMED );
429 const bool isUNV = ( theCommandID == SMESHOp::OpExportUNV || theCommandID == SMESHOp::OpPopupExportUNV );
430 const bool isSTL = ( theCommandID == SMESHOp::OpExportSTL || theCommandID == SMESHOp::OpPopupExportSTL );
432 const bool isCGNS= ( theCommandID == SMESHOp::OpExportCGNS || theCommandID == SMESHOp::OpPopupExportCGNS );
434 const bool isCGNS= false;
436 const bool isSAUV= ( theCommandID == SMESHOp::OpExportSAUV || theCommandID == SMESHOp::OpPopupExportSAUV );
437 const bool isGMF = ( theCommandID == SMESHOp::OpExportGMF || theCommandID == SMESHOp::OpPopupExportGMF );
439 const bool multiMeshSupported = ( isMED || isCGNS ); // file can hold several meshes
440 if ( selected.Extent() == 0 || ( selected.Extent() > 1 && !multiMeshSupported ))
443 // get mesh object from selection and check duplication of their names
444 bool hasDuplicatedMeshNames = false;
445 QList< QPair< SMESH::SMESH_IDSource_var, QString > > aMeshList;
446 QList< QPair< SMESH::SMESH_IDSource_var, QString > >::iterator aMeshIter;
447 SALOME_ListIteratorOfListIO It( selected );
448 for( ; It.More(); It.Next() )
450 Handle(SALOME_InteractiveObject) anIObject = It.Value();
451 SMESH::SMESH_IDSource_var aMeshItem = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIObject);
452 if ( aMeshItem->_is_nil() ) {
453 SUIT_MessageBox::warning( SMESHGUI::desktop(),
454 QObject::tr( "SMESH_WRN_WARNING" ),
455 QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
459 QString aMeshName = anIObject->getName();
461 // check for name duplications
462 if ( !hasDuplicatedMeshNames )
463 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
464 if( aMeshName == (*aMeshIter).second ) {
465 hasDuplicatedMeshNames = true;
470 aMeshList.append( QPair< SMESH::SMESH_IDSource_var, QString >( aMeshItem, aMeshName ) );
473 if( hasDuplicatedMeshNames && isMED ) {
474 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
475 QObject::tr("SMESH_WRN_WARNING"),
476 QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
477 QObject::tr("SMESH_BUT_YES"),
478 QObject::tr("SMESH_BUT_NO"), 0, 1);
483 aMeshIter = aMeshList.begin();
484 SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
485 SMESH::SMESH_Mesh_var aMesh = aMeshOrGroup->GetMesh();
486 QString aMeshName = (*aMeshIter).second;
488 if ( isMED || isCGNS || isSAUV ) // formats where group names must be unique
490 // check for equal group names within each mesh
491 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
492 SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
493 if ( !aMeshItem->_is_nil() && aMeshItem->HasDuplicatedGroupNamesMED()) {
494 int aRet = SUIT_MessageBox::warning
495 (SMESHGUI::desktop(),
496 QObject::tr("SMESH_WRN_WARNING"),
497 QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
498 QObject::tr("SMESH_BUT_YES"),
499 QObject::tr("SMESH_BUT_NO"), 0, 1);
506 // Warn the user about presence of not supported elements
508 std::vector< SMESH::EntityType > notSupportedElemTypes, presentNotSupported;
512 notSupportedElemTypes.push_back( SMESH::Entity_0D );
513 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
518 notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
519 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
520 notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
521 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
522 notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
523 notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
524 notSupportedElemTypes.push_back( SMESH::Entity_0D );
525 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
530 notSupportedElemTypes.push_back( SMESH::Entity_Edge );
531 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Edge );
532 notSupportedElemTypes.push_back( SMESH::Entity_0D );
533 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
538 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
543 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
544 notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Triangle );
545 notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
546 notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
547 notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
548 notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
549 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
550 notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
555 notSupportedElemTypes.push_back( SMESH::Entity_0D );
556 notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
557 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
558 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
559 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
560 notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
561 notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
562 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
563 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
565 if ( ! notSupportedElemTypes.empty() )
567 SMESH::long_array_var nbElems = aMeshOrGroup->GetMeshInfo();
568 for ( size_t iType = 0; iType < notSupportedElemTypes.size(); ++iType )
569 if ( nbElems[ notSupportedElemTypes[ iType ]] > 0 )
570 presentNotSupported.push_back( notSupportedElemTypes[ iType ]);
572 if ( !presentNotSupported.empty() )
575 const char* typeMsg[SMESH::Entity_Last] = {
576 "SMESH_NODES", "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES",
577 "SMESH_TRIANGLES", "SMESH_QUADRATIC_TRIANGLES", "SMESH_BIQUADRATIC_TRIANGLES",
578 "SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES", "SMESH_BIQUADRATIC_QUADRANGLES",
579 "SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
580 "SMESH_TETRAHEDRA","SMESH_QUADRATIC_TETRAHEDRONS","SMESH_PYRAMIDS",
581 "SMESH_QUADRATIC_PYRAMIDS","SMESH_HEXAHEDRA","SMESH_QUADRATIC_HEXAHEDRONS",
582 "SMESH_TRIQUADRATIC_HEXAHEDRONS","SMESH_PENTAHEDRA","SMESH_QUADRATIC_PENTAHEDRONS",
583 "SMESH_OCTAHEDRA","SMESH_POLYEDRONS","SMESH_QUADRATIC_POLYEDRONS","SMESH_BALLS"
585 QString andStr = " " + QObject::tr("SMESH_AND") + " ", comma(", ");
586 for ( size_t iType = 0; iType < presentNotSupported.size(); ++iType ) {
587 typeNames += QObject::tr( typeMsg[ presentNotSupported[ iType ]]);
588 if ( iType != presentNotSupported.size() - 1 )
589 typeNames += ( iType == presentNotSupported.size() - 2 ) ? andStr : comma;
591 int aRet = SUIT_MessageBox::warning
592 (SMESHGUI::desktop(),
593 QObject::tr("SMESH_WRN_WARNING"),
594 QObject::tr("EXPORT_NOT_SUPPORTED").arg(aMeshName).arg(format).arg(typeNames),
595 QObject::tr("SMESH_BUT_YES"),
596 QObject::tr("SMESH_BUT_NO"), 0, 1);
601 // Get parameters of export operation
604 SMESH::MED_VERSION aFormat;
605 // Init the parameters with the default values
606 bool aIsASCII_STL = true;
607 bool toCreateGroups = false;
608 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
610 toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
611 bool toOverwrite = true;
612 bool toFindOutDim = true;
614 QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
615 QString anInitialPath = "";
616 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
617 anInitialPath = QDir::currentPath();
619 QList< QPair< GEOM::ListOfFields_var, QString > > aFieldList;
621 // Get a file name to write in and additional otions
622 if ( isUNV || isDAT || isGMF ) // Export w/o options
625 aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
627 aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
629 aFilter = QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)" +
630 ";;" + QObject::tr( "GMF_BINARY_FILES_FILTER" ) + " (*.meshb)";
631 if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
632 aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
633 anInitialPath + QString("/") + aMeshName,
634 aFilter, aTitle, false);
636 else if ( isCGNS )// Export to CGNS
638 SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
639 fd->setWindowTitle( aTitle );
640 fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
641 if ( !anInitialPath.isEmpty() )
642 fd->setDirectory( anInitialPath );
643 fd->selectFile(aMeshName);
644 SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
645 fd->setValidator( fv );
648 aFilename = fd->selectedFile();
649 toOverwrite = fv->isOverwrite();
653 else if ( isSTL ) // Export to STL
655 QMap<QString, int> aFilterMap;
656 aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
657 aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" ) + " (*.stl)", 0 );
660 QMap<QString, int>::const_iterator it = aFilterMap.begin();
661 for ( ; it != aFilterMap.end(); ++it )
662 filters.push_back( it.key() );
664 SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
665 fd->setWindowTitle( aTitle );
666 fd->setNameFilters( filters );
667 fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
668 if ( !anInitialPath.isEmpty() )
669 fd->setDirectory( anInitialPath );
670 fd->selectFile(aMeshName);
674 aFilename = fd->selectedFile();
675 aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
680 else if ( isMED || isSAUV ) // Export to MED or SAUV
682 QMap<QString, SMESH::MED_VERSION> aFilterMap;
683 //QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
685 QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
686 //aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v21 ) + " (*.med)", SMESH::MED_V2_1 );
687 aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v22 ) + " (*.med)", SMESH::MED_V2_2 );
690 aFilterMap.insert("All files (*)", SMESH::MED_V2_1 );
691 aFilterMap.insert("SAUV files (*.sauv)", SMESH::MED_V2_2 );
692 aFilterMap.insert("SAUV files (*.sauve)", SMESH::MED_V2_1 );
696 QString aDefaultFilter;
697 QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
698 for ( ; it != aFilterMap.end(); ++it ) {
699 filters.push_back( it.key() );
700 if (it.value() == SMESH::MED_V2_2)
701 aDefaultFilter = it.key();
703 QStringList checkBoxes;
704 checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM");
706 SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
707 QList< QWidget* > wdgList;
708 if ( fieldSelWdg->GetAllFeilds( aMeshList, aFieldList ))
709 wdgList.append( fieldSelWdg );
711 SalomeApp_CheckFileDlg* fd =
712 new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true, wdgList );
713 fd->setWindowTitle( aTitle );
714 fd->setNameFilters( filters );
715 fd->selectNameFilter( aDefaultFilter );
716 fd->SetChecked( toCreateGroups, 0 );
717 fd->SetChecked( toFindOutDim, 1 );
718 if ( !anInitialPath.isEmpty() )
719 fd->setDirectory( anInitialPath );
720 fd->selectFile(aMeshName);
723 QListView *lview = fd->findChild<QListView*>("listView");
725 lview->setMinimumHeight(200);
727 QTreeView *tview = fd->findChild<QTreeView*>("treeView");
729 tview->setMinimumHeight(200);
732 SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
733 fd->setValidator( fv );
738 aFilename = fd->selectedFile();
740 aFilename = QString::null;
743 aFormat = aFilterMap[fd->selectedNameFilter()];
744 toOverwrite = fv->isOverwrite();
746 if ( !aFilename.isEmpty() ) {
747 // med-2.1 does not support poly elements
748 if ( aFormat==SMESH::MED_V2_1 )
749 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
750 SMESH::SMESH_IDSource_var aMeshItem = (*aMeshIter).first;
751 SMESH::long_array_var nbElems = aMeshItem->GetMeshInfo();
752 if ( nbElems[ SMESH::Entity_Polygon ] + nbElems[ SMESH::Entity_Quad_Polygon ] +
753 nbElems[ SMESH::Entity_Polyhedra ] + nbElems[ SMESH::Entity_Quad_Polyhedra ])
755 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
756 QObject::tr("SMESH_WRN_WARNING"),
757 QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
758 QObject::tr("SMESH_BUT_YES"),
759 QObject::tr("SMESH_BUT_NO"), 0, 1);
767 // can't append to an existing using other format
768 SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
769 bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toUtf8().constData(), aVersion );
770 if( !isVersionOk || aVersion != aFormat ) {
771 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
772 QObject::tr("SMESH_WRN_WARNING"),
773 QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
774 QObject::tr("SMESH_BUT_YES"),
775 QObject::tr("SMESH_BUT_NO"), 0, 1);
782 QStringList aMeshNamesCollisionList;
783 SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() );
784 for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
785 QString anExistingMeshName( aMeshNames[ i ] );
786 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
787 QString anExportMeshName = (*aMeshIter).second;
788 if( anExportMeshName == anExistingMeshName ) {
789 aMeshNamesCollisionList.append( anExportMeshName );
794 if( !aMeshNamesCollisionList.isEmpty() ) {
795 QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
796 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
797 QObject::tr("SMESH_WRN_WARNING"),
798 QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
799 QObject::tr("SMESH_BUT_YES"),
800 QObject::tr("SMESH_BUT_NO"),
801 QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
810 toCreateGroups = fd->IsChecked(0);
811 toFindOutDim = fd->IsChecked(1);
812 fieldSelWdg->GetSelectedFeilds();
813 if ( !fieldSelWdg->parent() )
824 if ( !aFilename.isEmpty() ) {
825 // Check whether the file already exists and delete it if yes
826 QFile aFile( aFilename );
827 if ( aFile.exists() && toOverwrite )
829 SUIT_OverrideCursor wc;
832 // Renumbering is not needed since SMDS redesign in V6.2.0 (Nov 2010)
833 // bool Renumber = false;
834 // // PAL 14172 : Check of we have to renumber or not from the preferences before export
836 // Renumber= resMgr->booleanValue("renumbering");
838 // SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
839 // aMeshEditor->RenumberNodes();
840 // aMeshEditor->RenumberElements();
841 // if ( SMESHGUI::automaticUpdate() )
842 // SMESH::UpdateView();
846 aMeshIter = aMeshList.begin();
847 for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
849 SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
850 SMESH::SMESH_Mesh_var aMeshItem = aMeshOrGroup->GetMesh();
851 const GEOM::ListOfFields& fields = aFieldList[ aMeshIndex ].first.in();
852 const QString& geoAssFields = aFieldList[ aMeshIndex ].second;
853 const bool hasFields = ( fields.length() || !geoAssFields.isEmpty() );
854 if ( !hasFields && aMeshOrGroup->_is_equivalent( aMeshItem ))
855 aMeshItem->ExportToMEDX( aFilename.toUtf8().data(), toCreateGroups,
856 aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim );
858 aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups,
859 aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim,
860 fields, geoAssFields.toLatin1().data() );
865 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ )
867 SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
868 if( !aMeshItem->_is_nil() )
869 aMeshItem->ExportSAUV( aFilename.toUtf8().data(), toCreateGroups );
874 if ( aMeshOrGroup->_is_equivalent( aMesh ))
875 aMesh->ExportDAT( aFilename.toUtf8().data() );
877 aMesh->ExportPartToDAT( aMeshOrGroup, aFilename.toUtf8().data() );
881 if ( aMeshOrGroup->_is_equivalent( aMesh ))
882 aMesh->ExportUNV( aFilename.toUtf8().data() );
884 aMesh->ExportPartToUNV( aMeshOrGroup, aFilename.toUtf8().data() );
888 if ( aMeshOrGroup->_is_equivalent( aMesh ))
889 aMesh->ExportSTL( aFilename.toUtf8().data(), aIsASCII_STL );
891 aMesh->ExportPartToSTL( aMeshOrGroup, aFilename.toUtf8().data(), aIsASCII_STL );
895 aMeshIter = aMeshList.begin();
896 for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
898 SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
899 SMESH::SMESH_Mesh_var aMeshItem = aMeshOrGroup->GetMesh();
900 aMeshItem->ExportCGNS( aMeshOrGroup,
901 aFilename.toUtf8().data(),
902 toOverwrite && aMeshIndex == 0 );
907 toCreateGroups = true;
908 aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
911 catch (const SALOME::SALOME_Exception& S_ex){
913 SUIT_MessageBox::warning(SMESHGUI::desktop(),
914 QObject::tr("SMESH_WRN_WARNING"),
915 QObject::tr("SMESH_EXPORT_FAILED"));
921 inline void InverseEntityMode(unsigned int& theOutputMode,
922 unsigned int theMode)
924 bool anIsNotPresent = ~theOutputMode & theMode;
926 theOutputMode |= theMode;
928 theOutputMode &= ~theMode;
931 void SetDisplayEntity(int theCommandID){
932 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
933 SALOME_ListIO selected;
935 aSel->selectedObjects( selected );
937 if(selected.Extent() >= 1){
938 SALOME_ListIteratorOfListIO It( selected );
939 for( ; It.More(); It.Next()){
940 Handle(SALOME_InteractiveObject) IObject = It.Value();
941 if(IObject->hasEntry()){
942 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
943 unsigned int aMode = anActor->GetEntityMode();
944 switch(theCommandID){
945 case SMESHOp::OpDE0DElements:
946 InverseEntityMode(aMode,SMESH_Actor::e0DElements);
948 case SMESHOp::OpDEEdges:
949 InverseEntityMode(aMode,SMESH_Actor::eEdges);
951 case SMESHOp::OpDEFaces:
952 InverseEntityMode(aMode,SMESH_Actor::eFaces);
954 case SMESHOp::OpDEVolumes:
955 InverseEntityMode(aMode,SMESH_Actor::eVolumes);
957 case SMESHOp::OpDEBalls:
958 InverseEntityMode(aMode,SMESH_Actor::eBallElem);
960 case SMESHOp::OpDEAllEntity:
961 aMode = SMESH_Actor::eAllEntity;
965 anActor->SetEntityMode(aMode);
974 SALOME_ListIO selected;
975 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
979 LightApp_SelectionMgr* aSel = app->selectionMgr();
980 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
981 if( !aSel || !appStudy )
984 aSel->selectedObjects( selected );
985 if( selected.IsEmpty() )
988 Handle(SALOME_InteractiveObject) anIObject = selected.First();
990 _PTR(Study) aStudy = appStudy->studyDS();
991 _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
992 SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
993 if( aMainObject->_is_nil() )
996 SUIT_OverrideCursor wc;
998 aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
1000 QList<SALOMEDS::Color> aReservedColors;
1002 SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
1003 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1005 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1006 //SALOMEDS::Color aColor = aGroupObject->GetColor();
1008 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
1009 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
1010 #else // old algorithm for auto-colors
1011 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1012 aReservedColors.append( aColor );
1013 #endif // SIMPLE_AUTOCOLOR
1014 aGroupObject->SetColor( aColor );
1016 _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
1017 if (aGroupSObject) {
1020 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
1021 switch ( aGroupObject->GetType ()) {
1023 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1025 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1027 anActor->Set0DColor( aColor.R, aColor.G, aColor.B ); break;
1029 anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1031 SMESH::GetColor("SMESH", "volume_color", c, delta, "255,0,170|-100");
1032 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1035 SMESH::GetColor("SMESH", "fill_color", c, delta, "0,170,255|-100");
1036 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta );
1042 SMESH::RepaintCurrentView();
1045 void OverallMeshQuality() {
1046 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1047 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1048 SALOME_ListIO selected;
1050 aSel->selectedObjects( selected );
1052 if ( selected.IsEmpty() ) return;
1053 SALOME_ListIteratorOfListIO It( selected );
1054 for ( ; It.More(); It.Next() ) {
1055 SMESHGUI_CtrlInfoDlg* ctrlDlg = new SMESHGUI_CtrlInfoDlg( SMESHGUI::desktop() );
1056 ctrlDlg->showInfo( It.Value() );
1061 QString functorToString( SMESH::Controls::FunctorPtr f )
1063 QString type = QObject::tr( "UNKNOWN_CONTROL" );
1064 if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
1065 type = QObject::tr( "VOLUME_3D_ELEMENTS" );
1066 else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
1067 type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
1068 else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
1069 type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
1070 else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
1071 type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
1072 else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
1073 type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
1074 else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
1075 type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
1076 else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
1077 type = QObject::tr( "WARP_ELEMENTS" );
1078 else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
1079 type = QObject::tr( "TAPER_ELEMENTS" );
1080 else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
1081 type = QObject::tr( "SKEW_ELEMENTS" );
1082 else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
1083 type = QObject::tr( "AREA_ELEMENTS" );
1084 else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
1085 type = QObject::tr( "LENGTH_EDGES" );
1086 else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
1087 type = QObject::tr( "LENGTH2D_EDGES" );
1088 else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
1089 type = QObject::tr( "MULTI_BORDERS" );
1090 else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
1091 type = QObject::tr( "MULTI2D_BORDERS" );
1092 else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
1093 type = QObject::tr( "FREE_NODES" );
1094 else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
1095 type = QObject::tr( "FREE_EDGES" );
1096 else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
1097 type = QObject::tr( "FREE_BORDERS" );
1098 else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
1099 type = QObject::tr( "FREE_FACES" );
1100 else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
1101 type = QObject::tr( "BARE_BORDER_VOLUME" );
1102 else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
1103 type = QObject::tr( "BARE_BORDER_FACE" );
1104 else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
1105 type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
1106 else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
1107 type = QObject::tr( "OVER_CONSTRAINED_FACE" );
1108 else if ( dynamic_cast< SMESH::Controls::CoincidentNodes* >( f.get() ) )
1109 type = QObject::tr( "EQUAL_NODE" );
1110 else if ( dynamic_cast< SMESH::Controls::CoincidentElements1D* >( f.get() ) )
1111 type = QObject::tr( "EQUAL_EDGE" );
1112 else if ( dynamic_cast< SMESH::Controls::CoincidentElements2D* >( f.get() ) )
1113 type = QObject::tr( "EQUAL_FACE" );
1114 else if ( dynamic_cast< SMESH::Controls::CoincidentElements3D* >( f.get() ) )
1115 type = QObject::tr( "EQUAL_VOLUME" );
1119 void SaveDistribution()
1121 LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1122 SALOME_ListIO selected;
1124 aSel->selectedObjects( selected );
1126 if ( selected.Extent() == 1 ) {
1127 Handle(SALOME_InteractiveObject) anIO = selected.First();
1128 if ( anIO->hasEntry() ) {
1129 SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1130 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1131 SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
1132 SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
1133 if ( aScalarBarActor && aFunctor ) {
1134 SMESH::Controls::NumericalFunctor* aNumFun = dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
1136 std::vector<int> elements;
1137 SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
1138 if ( mesh->_is_nil() ) {
1139 SMESH::SMESH_IDSource_var idSource =
1140 SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
1141 if ( !idSource->_is_nil() )
1143 SMESH::long_array_var ids = idSource->GetIDs();
1144 elements.resize( ids->length() );
1145 for ( unsigned i = 0; i < elements.size(); ++i )
1146 elements[i] = ids[i];
1149 int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
1150 vtkLookupTable* lookupTable =
1151 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
1152 double * minmax = lookupTable->GetRange();
1153 bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
1154 std::vector<int> nbEvents;
1155 std::vector<double> funValues;
1156 aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax, isLogarithmic );
1157 QString anInitialPath = "";
1158 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
1159 anInitialPath = QDir::currentPath();
1160 QString aMeshName = anIO->getName();
1162 filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
1163 filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
1164 QString aFilename = anInitialPath + "/" + aMeshName + "_" +
1165 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
1166 aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
1169 QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
1171 if ( !aFilename.isEmpty() ) {
1172 QFile f( aFilename );
1173 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
1174 QTextStream out( &f );
1175 out << "# Mesh: " << aMeshName << endl;
1176 out << "# Control: " << functorToString( aFunctor ) << endl;
1178 out.setFieldWidth( 10 );
1179 for ( int i = 0; i < (int)qMin( nbEvents.size(), funValues.size()-1 ); i++ )
1180 out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
1191 void ShowElement(int theCommandID ) {
1192 LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1193 SALOME_ListIO selected;
1195 aSel->selectedObjects( selected );
1197 if ( selected.Extent() == 1 ) {
1198 Handle(SALOME_InteractiveObject) anIO = selected.First();
1199 if ( anIO->hasEntry() ) {
1200 SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1201 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1202 SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
1203 if ( theCommandID == SMESHOp::OpShowDistribution ) {
1204 aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
1206 else if ( theCommandID == SMESHOp::OpShowScalarBar ) {
1207 aScalarBarActor->SetVisibility( !aScalarBarActor->GetVisibility());
1214 #ifndef DISABLE_PLOT2DVIEWER
1215 void PlotDistribution() {
1216 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1220 LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1221 SALOME_ListIO selected;
1223 aSel->selectedObjects( selected );
1225 if ( selected.Extent() == 1 ) {
1226 Handle(SALOME_InteractiveObject) anIO = selected.First();
1227 if ( anIO->hasEntry() ) {
1228 //Find Actor by entry before getting Plot2d viewer,
1229 //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
1230 SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1232 SUIT_ViewManager* aViewManager = app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
1237 SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
1241 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1245 if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1246 SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1247 QString functorName = functorToString( anActor->GetFunctor());
1248 QString aHistogramName("%1 : %2");
1249 aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1250 aHistogram->setName(aHistogramName);
1251 aHistogram->setHorTitle(functorName);
1252 aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
1253 aPlot->displayObject(aHistogram, true);
1258 #endif //DISABLE_PLOT2DVIEWER
1260 void DisableAutoColor(){
1261 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1262 SALOME_ListIO selected;
1264 aSel->selectedObjects( selected );
1266 if(selected.Extent()){
1267 Handle(SALOME_InteractiveObject) anIObject = selected.First();
1268 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1269 if ( !aMesh->_is_nil() ) {
1270 aMesh->SetAutoColor( false );
1275 void sortChildren(){
1276 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1277 SALOME_ListIO selected;
1279 aSel->selectedObjects( selected );
1281 if(selected.Extent()){
1282 Handle(SALOME_InteractiveObject) anIObject = selected.First();
1283 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1284 _PTR(SObject) aSObj = aStudy->FindObjectID(anIObject->getEntry());
1286 if ( aStudy->GetUseCaseBuilder()->SortChildren( aSObj, true/*AscendingOrder*/ ) ) {
1287 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1294 void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap)
1296 SALOME_ListIO selected;
1297 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1301 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1302 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1303 if( !aSel || !appStudy )
1306 if( theCommandID == SMESHOp::OpClipping ) { // Clipping dialog can be activated without selection
1307 if( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
1308 aModule->EmitSignalDeactivateDialog();
1309 if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
1310 (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
1315 _PTR(Study) aStudy = appStudy->studyDS();
1317 aSel->selectedObjects( selected );
1319 if(selected.Extent() >= 1){
1320 switch(theCommandID){
1321 case SMESHOp::OpTransparency:{
1322 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1323 (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
1326 case SMESHOp::OpProperties: {
1328 QColor faceColor, edgeColor, nodeColor, elem0dColor, ballColor;
1329 QColor orientationColor, outlineColor, volumeColor;
1330 int deltaF = 0, deltaV = 0;
1333 double ballScale = 1.0;
1335 int outlineWidth = 1;
1336 double shrinkCoef = 0.0;
1337 double orientationScale = 0.0;
1338 bool orientation3d = false;
1339 VTK::MarkerType markerType = VTK::MT_NONE;
1340 VTK::MarkerScale markerScale = VTK::MS_NONE;
1342 bool hasNodes = false;
1343 int presentEntities = 0;
1344 bool firstTime = true;
1346 SALOME_ListIteratorOfListIO It( selected );
1347 for ( ; It.More(); It.Next() ) {
1348 Handle(SALOME_InteractiveObject) IObject = It.Value();
1349 if ( !IObject->hasEntry() ) continue;
1350 SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1351 if ( !anActor || !anActor->GetObject() ) continue;
1354 // nodes: color, marker
1355 anActor->GetNodeColor( color[0], color[1], color[2] );
1356 nodeColor.setRgbF( color[0], color[1], color[2] );
1357 markerType = anActor->GetMarkerType();
1358 markerScale = anActor->GetMarkerScale();
1359 markerId = anActor->GetMarkerTexture();
1360 // edges: color, width
1361 anActor->GetEdgeColor( color[0], color[1], color[2] );
1362 edgeColor.setRgbF( color[0], color[1], color[2] );
1363 edgeWidth = qMax( (int)anActor->GetLineWidth(), 1 ); // minimum allowed width is 1
1364 // faces: front color, back color (delta)
1365 anActor->GetSufaceColor( color[0], color[1], color[2], deltaF );
1366 faceColor.setRgbF( color[0], color[1], color[2] );
1367 // faces: front color, back color (delta)
1368 anActor->GetVolumeColor( color[0], color[1], color[2], deltaV );
1369 volumeColor.setRgbF( color[0], color[1], color[2] );
1370 // 0d elements: color, size
1371 anActor->Get0DColor( color[0], color[1], color[2] );
1372 elem0dColor.setRgbF( color[0], color[1], color[2] );
1373 elem0dSize = qMax( (int)anActor->Get0DSize(), 1 ); // minimum allowed size is 1
1374 // balls: color, size
1375 anActor->GetBallColor( color[0], color[1], color[2] );
1376 ballColor.setRgbF( color[0], color[1], color[2] );
1377 //ballSize = qMax( (int)anActor->GetBallSize(), 1 ); // minimum allowed size is 1
1378 ballScale = qMax( (double)anActor->GetBallScale(), 1e-2 ); // minimum allowed scale is 1e-2
1380 anActor->GetOutlineColor( color[0], color[1], color[2] );
1381 outlineColor.setRgbF( color[0], color[1], color[2] );
1382 outlineWidth = qMax( (int)anActor->GetOutlineWidth(), 1 ); // minimum allowed width is 1
1383 // orientation vectors: color, scale, 3d flag
1384 anActor->GetFacesOrientationColor( color[0], color[1], color[2] );
1385 orientationColor.setRgbF( color[0], color[1], color[2] );
1386 orientationScale = anActor->GetFacesOrientationScale();
1387 orientation3d = anActor->GetFacesOrientation3DVectors();
1389 shrinkCoef = anActor->GetShrinkFactor();
1392 firstTime = false; // we only take properties from first object (for performance reasons)
1395 hasNodes = anActor->GetObject()->GetNbEntities( SMDSAbs_Node );
1396 if ( !(presentEntities & SMESH_Actor::eEdges) && anActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) )
1397 presentEntities = presentEntities | SMESH_Actor::eEdges;
1398 if ( !(presentEntities & SMESH_Actor::eFaces) && anActor->GetObject()->GetNbEntities( SMDSAbs_Face ) )
1399 presentEntities = presentEntities | SMESH_Actor::eFaces;
1400 if ( !(presentEntities & SMESH_Actor::eVolumes) && anActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) )
1401 presentEntities = presentEntities | SMESH_Actor::eVolumes;
1402 if ( !(presentEntities & SMESH_Actor::e0DElements) && anActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) )
1403 presentEntities = presentEntities | SMESH_Actor::e0DElements;
1404 if ( !(presentEntities & SMESH_Actor::eBallElem) && anActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) )
1405 presentEntities = presentEntities | SMESH_Actor::eBallElem;
1407 // as we know that all types of elements are present, we can exit the loop
1408 if ( presentEntities == SMESH_Actor::eAllEntity )
1412 SMESHGUI_PropertiesDlg dlg( theMarkerMap[ aStudy->StudyId() ], SMESHGUI::desktop() );
1413 // nodes: color, marker
1414 dlg.setNodeColor( nodeColor );
1415 if( markerType != VTK::MT_USER )
1416 dlg.setNodeMarker( markerType, markerScale );
1418 dlg.setNodeCustomMarker( markerId );
1419 // edges: color, line width
1420 dlg.setEdgeColor( edgeColor );
1421 dlg.setEdgeWidth( edgeWidth );
1422 // faces: front color, back color
1423 dlg.setFaceColor( faceColor, deltaF );
1424 // volumes: normal color, reversed color
1425 dlg.setVolumeColor( volumeColor, deltaV );
1426 // outlines: color, line width
1427 dlg.setOutlineColor( outlineColor );
1428 dlg.setOutlineWidth( outlineWidth );
1429 // 0d elements: color, size
1430 dlg.setElem0dColor( elem0dColor );
1431 dlg.setElem0dSize( elem0dSize );
1432 // balls: color, size
1433 dlg.setBallColor( ballColor );
1434 //dlg.setBallSize( ballSize );
1435 dlg.setBallScale( ballScale );
1436 // orientation: color, scale, 3d flag
1437 dlg.setOrientationColor( orientationColor );
1438 dlg.setOrientationSize( int( orientationScale * 100. ) );
1439 dlg.setOrientation3d( orientation3d );
1440 // shrink: scale factor
1441 dlg.setShrinkCoef( int( shrinkCoef * 100. ) );
1442 // hide unused controls
1443 dlg.showControls( presentEntities, hasNodes );
1446 nodeColor = dlg.nodeColor();
1447 markerType = dlg.nodeMarkerType();
1448 markerScale = dlg.nodeMarkerScale();
1449 markerId = dlg.nodeMarkerId();
1450 edgeColor = dlg.edgeColor();
1451 edgeWidth = dlg.edgeWidth();
1452 faceColor = dlg.faceColor();
1453 deltaF = dlg.faceColorDelta();
1454 volumeColor = dlg.volumeColor();
1455 deltaV = dlg.volumeColorDelta();
1456 outlineColor = dlg.outlineColor();
1457 outlineWidth = dlg.outlineWidth();
1458 elem0dColor = dlg.elem0dColor();
1459 elem0dSize = dlg.elem0dSize();
1460 ballColor = dlg.ballColor();
1461 // ballSize = dlg.ballSize();
1462 ballScale = dlg.ballScale();
1463 orientationColor = dlg.orientationColor();
1464 orientationScale = dlg.orientationSize() / 100.;
1465 orientation3d = dlg.orientation3d();
1466 shrinkCoef = dlg.shrinkCoef() / 100.;
1468 // store point markers map that might be changed by the user
1469 theMarkerMap[ aStudy->StudyId() ] = dlg.customMarkers();
1471 // set properties from dialog box to the presentations
1472 SALOME_ListIteratorOfListIO It( selected );
1473 for ( ; It.More(); It.Next() ) {
1474 Handle(SALOME_InteractiveObject) IObject = It.Value();
1475 if ( !IObject->hasEntry() ) continue;
1476 SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1477 if ( !anActor ) continue;
1479 // nodes: color, marker
1480 anActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
1481 if ( markerType != VTK::MT_USER ) {
1482 anActor->SetMarkerStd( markerType, markerScale );
1485 const VTK::MarkerMap& markerMap = theMarkerMap[ aStudy->StudyId() ];
1486 VTK::MarkerMap::const_iterator iter = markerMap.find( markerId );
1487 if ( iter != markerMap.end() )
1488 anActor->SetMarkerTexture( markerId, iter->second.second );
1490 // volumes: normal color, reversed color (delta)
1491 anActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
1492 // faces: front color, back color (delta)
1493 anActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
1494 // edges: color, width
1495 anActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
1496 anActor->SetLineWidth( edgeWidth );
1498 anActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
1499 anActor->SetOutlineWidth( outlineWidth );
1500 // 0D elements: color, size
1501 anActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
1502 anActor->Set0DSize( elem0dSize );
1503 // balls: color, size
1504 anActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
1505 // anActor->SetBallSize( ballSize );
1506 anActor->SetBallScale( ballScale );
1507 // orientation: color, scale, 3d flag
1508 anActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
1509 anActor->SetFacesOrientationScale( orientationScale );
1510 anActor->SetFacesOrientation3DVectors( orientation3d );
1512 anActor->SetShrinkFactor( shrinkCoef );
1514 // for groups, set also proper color
1515 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1516 if ( !aGroupObject->_is_nil() ) {
1517 SMESH::ElementType anElementType = aGroupObject->GetType();
1519 switch( anElementType ) {
1521 aColor = nodeColor; break;
1523 aColor = edgeColor; break;
1525 aColor = faceColor; break;
1527 aColor = volumeColor; break;
1529 aColor = elem0dColor; break;
1531 aColor = ballColor; break;
1535 if ( aColor.isValid() ) {
1536 SALOMEDS::Color aGroupColor;
1537 aGroupColor.R = aColor.redF();
1538 aGroupColor.G = aColor.greenF();
1539 aGroupColor.B = aColor.blueF();
1540 aGroupObject->SetColor( aGroupColor );
1542 } // if ( !aGroupObject->_is_nil() )
1543 } // for ( ; It.More(); It.Next() )
1544 SMESH::RepaintCurrentView();
1545 } // if ( dlg.exec() )
1547 } // case SMESHOp::OpProperties:
1548 } // switch(theCommandID)
1549 SALOME_ListIteratorOfListIO It( selected );
1550 for( ; It.More(); It.Next()){
1551 Handle(SALOME_InteractiveObject) IObject = It.Value();
1552 if(IObject->hasEntry()){
1553 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1554 switch(theCommandID){
1555 case SMESHOp::OpDMWireframe:
1556 anActor->SetRepresentation(SMESH_Actor::eEdge);
1558 case SMESHOp::OpDMShading:
1559 anActor->SetRepresentation(SMESH_Actor::eSurface);
1561 case SMESHOp::OpDMShrink:
1562 if(anActor->IsShrunk())
1563 anActor->UnShrink();
1565 anActor->SetShrink();
1567 case SMESHOp::OpDMNodes:
1568 anActor->SetRepresentation(SMESH_Actor::ePoint);
1570 case SMESHOp::OpRepresentationLines:
1571 if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1572 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1574 case SMESHOp::OpRepresentationArcs:
1575 if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1576 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1582 SMESH::RepaintCurrentView();
1586 int ActionToControl( int theID, bool theReversed )
1588 NCollection_DoubleMap<int,int> ActionControl;
1589 ActionControl.Bind( 0, SMESH_Actor::eNone );
1590 ActionControl.Bind( SMESHOp::OpFreeNode, SMESH_Actor::eFreeNodes );
1591 ActionControl.Bind( SMESHOp::OpEqualNode, SMESH_Actor::eCoincidentNodes );
1592 ActionControl.Bind( SMESHOp::OpFreeEdge, SMESH_Actor::eFreeEdges );
1593 ActionControl.Bind( SMESHOp::OpFreeBorder, SMESH_Actor::eFreeBorders );
1594 ActionControl.Bind( SMESHOp::OpLength, SMESH_Actor::eLength );
1595 ActionControl.Bind( SMESHOp::OpConnection, SMESH_Actor::eMultiConnection );
1596 ActionControl.Bind( SMESHOp::OpEqualEdge, SMESH_Actor::eCoincidentElems1D );
1597 ActionControl.Bind( SMESHOp::OpFreeFace, SMESH_Actor::eFreeFaces );
1598 ActionControl.Bind( SMESHOp::OpBareBorderFace, SMESH_Actor::eBareBorderFace );
1599 ActionControl.Bind( SMESHOp::OpOverConstrainedFace, SMESH_Actor::eOverConstrainedFace );
1600 ActionControl.Bind( SMESHOp::OpLength2D, SMESH_Actor::eLength2D );
1601 ActionControl.Bind( SMESHOp::OpConnection2D, SMESH_Actor::eMultiConnection2D );
1602 ActionControl.Bind( SMESHOp::OpArea, SMESH_Actor::eArea );
1603 ActionControl.Bind( SMESHOp::OpTaper, SMESH_Actor::eTaper );
1604 ActionControl.Bind( SMESHOp::OpAspectRatio, SMESH_Actor::eAspectRatio );
1605 ActionControl.Bind( SMESHOp::OpMinimumAngle, SMESH_Actor::eMinimumAngle );
1606 ActionControl.Bind( SMESHOp::OpWarpingAngle, SMESH_Actor::eWarping );
1607 ActionControl.Bind( SMESHOp::OpSkew, SMESH_Actor::eSkew );
1608 ActionControl.Bind( SMESHOp::OpMaxElementLength2D, SMESH_Actor::eMaxElementLength2D );
1609 ActionControl.Bind( SMESHOp::OpEqualFace, SMESH_Actor::eCoincidentElems2D );
1610 ActionControl.Bind( SMESHOp::OpAspectRatio3D, SMESH_Actor::eAspectRatio3D );
1611 ActionControl.Bind( SMESHOp::OpVolume, SMESH_Actor::eVolume3D );
1612 ActionControl.Bind( SMESHOp::OpMaxElementLength3D, SMESH_Actor::eMaxElementLength3D );
1613 ActionControl.Bind( SMESHOp::OpBareBorderVolume, SMESH_Actor::eBareBorderVolume );
1614 ActionControl.Bind( SMESHOp::OpOverConstrainedVolume, SMESH_Actor::eOverConstrainedVolume );
1615 ActionControl.Bind( SMESHOp::OpEqualVolume, SMESH_Actor::eCoincidentElems3D );
1617 return theReversed ? ActionControl.Find2( theID ) : ActionControl.Find1( theID );
1620 void Control( int theCommandID )
1622 SMESH_Actor::eControl aControl = SMESH_Actor::eControl( ActionToControl( theCommandID ) );
1623 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1624 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1625 SALOME_ListIO selected;
1627 aSel->selectedObjects( selected );
1629 if( !selected.IsEmpty() ){
1630 SALOME_ListIteratorOfListIO It(selected);
1631 for ( ; It.More(); It.Next())
1633 Handle(SALOME_InteractiveObject) anIO = It.Value();
1635 _PTR(SObject) SO = aStudy->FindObjectID( It.Value()->getEntry() );
1637 CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
1638 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( aObject );
1639 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
1640 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( aObject );
1641 if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
1642 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())) {
1643 anActor->SetControlMode(aControl);
1644 anActor->GetScalarBarActor()->SetTitle( functorToString( anActor->GetFunctor() ).toLatin1().constData() );
1645 SMESH::RepaintCurrentView();
1646 #ifndef DISABLE_PLOT2DVIEWER
1647 if(anActor->GetPlot2Histogram()) {
1648 SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1649 QString functorName = functorToString( anActor->GetFunctor());
1650 QString aHistogramName("%1 : %2");
1651 aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1652 aHistogram->setName(aHistogramName);
1653 aHistogram->setHorTitle(functorName);
1654 SMESH::ProcessIn2DViewers(anActor);
1666 bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1667 SMESH::MeshObjectType theType,
1668 const QString theInTypeName,
1669 QString & theOutTypeName)
1671 SMESH_TypeFilter aTypeFilter( theType );
1673 if( !theIO.IsNull() )
1675 entry = theIO->getEntry();
1676 LightApp_DataOwner owner( entry );
1677 if ( aTypeFilter.isOk( &owner )) {
1678 theOutTypeName = theInTypeName;
1686 QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1688 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1689 _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1691 _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1692 CORBA::String_var anID = aSComp->GetID().c_str();
1693 if (!strcmp(anID.in(),theIO->getEntry()))
1699 CheckOIType ( theIO, SMESH::HYPOTHESIS, "Hypothesis", aTypeName ) ||
1700 CheckOIType ( theIO, SMESH::ALGORITHM, "Algorithm", aTypeName ) ||
1701 CheckOIType ( theIO, SMESH::MESH, "Mesh", aTypeName ) ||
1702 CheckOIType ( theIO, SMESH::SUBMESH, "SubMesh", aTypeName ) ||
1703 CheckOIType ( theIO, SMESH::GROUP, "Group", aTypeName )
1711 QString CheckHomogeneousSelection()
1713 //SUIT_Study* aStudy = SMESH::GetActiveStudy();
1714 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1715 SALOME_ListIO selected;
1717 aSel->selectedObjects( selected );
1719 QString RefType = CheckTypeObject(selected.First());
1720 SALOME_ListIteratorOfListIO It(selected);
1721 for ( ; It.More(); It.Next())
1723 Handle(SALOME_InteractiveObject) IObject = It.Value();
1724 QString Type = CheckTypeObject(IObject);
1725 if (Type.compare(RefType) != 0)
1726 return "Heterogeneous Selection";
1732 uint randomize( uint size )
1734 static bool initialized = false;
1735 if ( !initialized ) {
1736 qsrand( QDateTime::currentDateTime().toTime_t() );
1740 v = uint( (double)( v ) / RAND_MAX * size );
1741 v = qMax( uint(0), qMin ( v, size-1 ) );
1747 void SMESHGUI::OnEditDelete()
1749 // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1750 LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1751 SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1753 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1754 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1755 _PTR(GenericAttribute) anAttr;
1756 _PTR(AttributeIOR) anIOR;
1758 int objectCount = 0;
1760 QString aParentComponent = QString::null;
1761 Handle(SALOME_InteractiveObject) anIO;
1762 for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1764 anIO = anIt.Value();
1765 QString cur = anIO->getComponentDataType();
1766 _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
1768 // check if object is reference
1769 _PTR(SObject) aRefSObj;
1770 aNameList.append("\n - ");
1771 if ( aSO->ReferencedObject( aRefSObj ) ) {
1772 QString aRefName = QString::fromStdString ( aRefSObj->GetName() );
1773 aNameList.append( aRefName );
1774 cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1777 aNameList.append(anIO->getName());
1781 if( aParentComponent.isNull() )
1782 aParentComponent = cur;
1783 else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
1784 aParentComponent = "";
1787 if ( objectCount == 0 )
1788 return; // No Valid Objects Selected
1790 if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() ) {
1791 SUIT_MessageBox::warning( SMESHGUI::desktop(),
1792 QObject::tr("ERR_ERROR"),
1793 QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1796 // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1797 if (SUIT_MessageBox::warning
1798 (SMESHGUI::desktop(),
1799 QObject::tr("SMESH_WRN_WARNING"),
1800 QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1801 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1802 SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1805 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1807 // Put the whole hierarchy of sub-objects of the selected SO's into a list and
1808 // then treat them all starting from the deepest objects (at list back)
1809 std::list< _PTR(SObject) > listSO;
1810 SALOME_ListIteratorOfListIO It(selected);
1811 for( ; It.More(); It.Next()) // loop on selected IO's
1813 Handle(SALOME_InteractiveObject) IObject = It.Value();
1814 if(IObject->hasEntry()) {
1815 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1817 // disable removal of "SMESH" component object
1818 if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1820 if ( engineIOR() == anIOR->Value().c_str() )
1823 //Check the referenced object
1824 _PTR(SObject) aRefSObject;
1825 if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1826 aSO = aRefSObject; // Delete main Object instead of reference
1828 listSO.push_back( aSO );
1829 std::list< _PTR(SObject) >::iterator itSO = --listSO.end();
1830 for ( ; itSO != listSO.end(); ++itSO ) {
1831 _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1832 for (it->InitEx(false); it->More(); it->Next())
1833 listSO.push_back( it->Value() );
1837 // Check if none of objects to delete is referred from outside
1838 std::list< _PTR(SObject) >::reverse_iterator ritSO;
1839 for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1841 _PTR(SObject) SO = *ritSO;
1842 if ( !SO ) continue;
1843 std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( *ritSO );
1844 for (size_t i = 0; i < aReferences.size(); i++) {
1845 _PTR(SComponent) aComponent = aReferences[i]->GetFatherComponent();
1846 std::string type = aComponent->ComponentDataType();
1847 if ( type != "SMESH" )
1849 SUIT_MessageBox::warning( anApp->desktop(),
1850 QObject::tr("WRN_WARNING"),
1851 QObject::tr("DEP_OBJECT") );
1852 return; // outside SMESH, there is an object depending on a SMESH object
1857 // Call mesh->Clear() to prevent loading mesh from file caused by hypotheses removal
1858 for( It.Initialize( selected ); It.More(); It.Next()) // loop on selected IO's
1860 Handle(SALOME_InteractiveObject) IObject = It.Value();
1861 SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface< SMESH::SMESH_Mesh >( IObject );
1862 if ( !mesh->_is_nil() )
1866 // Treat SO's in the list starting from the back
1867 aStudyBuilder->NewCommand(); // There is a transaction
1868 for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1870 _PTR(SObject) SO = *ritSO;
1871 if ( !SO ) continue;
1872 std::string anEntry = SO->GetID();
1874 /** Erase graphical object and remove all its data **/
1875 if(SO->FindAttribute(anAttr, "AttributeIOR")) {
1876 SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true);
1878 /** Remove an object from data structures **/
1879 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1880 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1881 if ( !aGroup->_is_nil() ) { // DELETE GROUP
1882 SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1883 aMesh->RemoveGroup( aGroup );
1885 else if ( !aSubMesh->_is_nil() ) { // DELETE SUBMESH
1886 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1887 aMesh->RemoveSubMesh( aSubMesh );
1889 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1891 SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1894 Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject
1895 ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1896 QString objType = CheckTypeObject(IObject);
1897 if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1898 SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1899 aStudyBuilder->RemoveObjectWithChildren( SO );
1901 else {// default action: remove SObject from the study
1902 // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1903 //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1905 aStudyBuilder->RemoveObjectWithChildren( SO );
1909 } /* listSO back loop */
1911 aStudyBuilder->CommitCommand();
1913 /* Clear any previous selection */
1915 aSel->setSelectedObjects( l1 );
1917 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1921 SMESHGUI_EXPORT CAM_Module* createModule()
1923 return new SMESHGUI();
1926 SMESHGUI_EXPORT char* getModuleVersion() {
1927 return (char*)SMESH_VERSION_STR;
1931 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1933 //=============================================================================
1937 //=============================================================================
1938 SMESHGUI::SMESHGUI() :
1939 SalomeApp_Module( "SMESH" )
1941 if ( CORBA::is_nil( myComponentSMESH ) )
1943 CORBA::Boolean anIsEmbeddedMode;
1944 myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1945 MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
1947 // 0019923: EDF 765 SMESH : default values of hypothesis
1948 SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
1949 int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
1950 myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
1951 nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
1952 myComponentSMESH->SetDefaultNbSegments( nbSeg );
1954 const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif" };
1955 for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
1956 if ( aResourceMgr->hasValue( "SMESH", options[i] ))
1958 QString val = aResourceMgr->stringValue( "SMESH", options[i] );
1959 myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
1963 myActiveDialogBox = 0;
1964 myFilterLibraryDlg = 0;
1968 myEventCallbackCommand = vtkCallbackCommand::New();
1969 myEventCallbackCommand->Delete();
1970 myEventCallbackCommand->SetClientData( this );
1971 myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
1974 /* load resources for all available meshers */
1975 SMESH::InitAvailableHypotheses();
1978 //=============================================================================
1982 //=============================================================================
1983 SMESHGUI::~SMESHGUI()
1987 //=============================================================================
1991 //=============================================================================
1992 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1994 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1996 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2001 //=============================================================================
2005 //=============================================================================
2006 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
2008 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2012 bool autoUpdate = resMgr->booleanValue( "SMESH", "auto_update", false );
2013 long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2014 bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2015 if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2016 return autoUpdate && !exceeded;
2019 //=============================================================================
2023 //=============================================================================
2024 bool SMESHGUI::automaticUpdate( SMESH::SMESH_IDSource_ptr theMesh,
2025 int* entities, bool* limitExceeded, int* hidden, long* nbElements )
2027 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2031 bool autoUpdate = resMgr->booleanValue( "SMESH", "auto_update", false );
2032 long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2033 bool incrementalLimit = resMgr->booleanValue( "SMESH", "incremental_limit", false );
2035 SMESH::long_array_var info = theMesh->GetMeshInfo();
2036 long nbOdElems = info[SMDSEntity_0D];
2037 long nbEdges = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
2038 long nbFaces = info[SMDSEntity_Triangle] + info[SMDSEntity_Quad_Triangle] + info[SMDSEntity_BiQuad_Triangle] +
2039 info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle] + info[SMDSEntity_BiQuad_Quadrangle] +
2040 info[SMDSEntity_Polygon] + info[SMDSEntity_Quad_Polygon];
2041 long nbVolumes = info[SMDSEntity_Tetra] + info[SMDSEntity_Quad_Tetra] +
2042 info[SMDSEntity_Hexa] + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_TriQuad_Hexa] +
2043 info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid] +
2044 info[SMDSEntity_Penta] + info[SMDSEntity_Quad_Penta] +
2045 info[SMDSEntity_Polyhedra] +
2046 info[SMDSEntity_Hexagonal_Prism];
2047 long nbBalls = info[SMDSEntity_Ball];
2049 long requestedSize = nbOdElems + nbBalls + nbEdges + nbFaces + nbVolumes;
2050 *nbElements = requestedSize;
2052 *entities = SMESH_Actor::eAllEntity;
2055 bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2057 if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2059 if ( incrementalLimit ) {
2062 if ( nbOdElems > 0 ) {
2063 if ( total + nbOdElems > updateLimit ) {
2064 *entities = *entities & ~SMESH_Actor::e0DElements;
2065 *hidden = *hidden | SMESH_Actor::e0DElements;
2072 if ( nbEdges > 0 ) {
2073 if ( total + nbEdges > updateLimit ) {
2074 *entities = *entities & ~SMESH_Actor::eEdges;
2075 *hidden = *hidden | SMESH_Actor::eEdges;
2082 if ( nbFaces > 0 ) {
2083 if ( total + nbFaces > updateLimit ) {
2084 *entities = *entities & ~SMESH_Actor::eFaces;
2085 *hidden = *hidden | SMESH_Actor::eFaces;
2092 if ( nbVolumes > 0 ) {
2093 if ( total + nbVolumes > updateLimit ) {
2094 *entities = *entities & ~SMESH_Actor::eVolumes;
2095 *hidden = *hidden | SMESH_Actor::eVolumes;
2102 if ( nbBalls > 0 ) {
2103 if ( total + nbBalls > updateLimit ) {
2104 *entities = *entities & ~SMESH_Actor::eBallElem;
2105 *hidden = *hidden | SMESH_Actor::eBallElem;
2113 return autoUpdate && !exceeded;
2116 //=============================================================================
2120 //=============================================================================
2121 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
2123 return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
2126 //=============================================================================
2130 //=============================================================================
2131 SMESHGUI* SMESHGUI::GetSMESHGUI()
2133 SMESHGUI* smeshMod = 0;
2134 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
2137 CAM_Module* module = app->module( "Mesh" );
2138 smeshMod = dynamic_cast<SMESHGUI*>( module );
2141 if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
2143 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
2146 _PTR(Study) aStudy = study->studyDS();
2148 GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
2157 Standard_EXPORT SMESHGUI* GetComponentGUI()
2159 return SMESHGUI::GetSMESHGUI();
2163 //=============================================================================
2167 //=============================================================================
2168 void SMESHGUI::SetState(int aState)
2173 //=============================================================================
2177 //=============================================================================
2178 void SMESHGUI::ResetState()
2183 //=============================================================================
2187 //=============================================================================
2188 void SMESHGUI::EmitSignalDeactivateDialog()
2190 emit SignalDeactivateActiveDialog();
2193 //=============================================================================
2197 //=============================================================================
2198 void SMESHGUI::EmitSignalStudyFrameChanged()
2200 emit SignalStudyFrameChanged();
2203 //=============================================================================
2207 //=============================================================================
2208 void SMESHGUI::EmitSignalCloseAllDialogs()
2210 emit SignalCloseAllDialogs();
2213 //=============================================================================
2217 //=============================================================================
2218 void SMESHGUI::EmitSignalVisibilityChanged()
2220 emit SignalVisibilityChanged();
2223 //=============================================================================
2227 //=============================================================================
2228 void SMESHGUI::EmitSignalCloseView()
2230 emit SignalCloseView();
2233 //=============================================================================
2237 //=============================================================================
2238 void SMESHGUI::EmitSignalActivatedViewManager()
2240 emit SignalActivatedViewManager();
2243 //=============================================================================
2247 //=============================================================================
2248 QDialog *SMESHGUI::GetActiveDialogBox()
2250 return myActiveDialogBox;
2253 //=============================================================================
2257 //=============================================================================
2258 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2260 myActiveDialogBox = (QDialog *) aDlg;
2264 //=============================================================================
2268 //=============================================================================
2269 SUIT_Desktop* SMESHGUI::desktop()
2271 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2273 return app->desktop();
2278 //=============================================================================
2282 //=============================================================================
2283 SalomeApp_Study* SMESHGUI::activeStudy()
2285 SUIT_Application* app = SUIT_Session::session()->activeApplication();
2287 return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2292 //=============================================================================
2296 //=============================================================================
2297 void SMESHGUI::Modified( bool theIsUpdateActions )
2299 if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2300 if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2301 appStudy->Modified();
2302 if( theIsUpdateActions )
2303 app->updateActions();
2308 //=============================================================================
2312 //=============================================================================
2313 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2315 /* Here the position is on the bottom right corner - 10 */
2316 // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2318 SUIT_Desktop *PP = desktop();
2319 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2320 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2324 //=============================================================================
2328 //=============================================================================
2329 static int isStudyLocked(_PTR(Study) theStudy){
2330 return theStudy->GetProperties()->IsLocked();
2333 static bool checkLock(_PTR(Study) theStudy) {
2334 if (isStudyLocked(theStudy)) {
2335 SUIT_MessageBox::warning( SMESHGUI::desktop(),
2336 QObject::tr("WRN_WARNING"),
2337 QObject::tr("WRN_STUDY_LOCKED") );
2343 //=======================================================================
2344 //function : CheckActiveStudyLocked
2346 //=======================================================================
2348 bool SMESHGUI::isActiveStudyLocked()
2350 _PTR(Study) aStudy = activeStudy()->studyDS();
2351 return checkLock( aStudy );
2354 //=============================================================================
2358 //=============================================================================
2359 bool SMESHGUI::OnGUIEvent( int theCommandID )
2361 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2365 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2366 SUIT_ResourceMgr* mgr = resourceMgr();
2370 if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
2371 GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2374 SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2375 SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2377 //QAction* act = action( theCommandID );
2379 switch (theCommandID) {
2380 case SMESHOp::OpDelete:
2381 if(checkLock(aStudy)) break;
2384 case SMESHOp::OpImportDAT:
2385 case SMESHOp::OpImportUNV:
2386 case SMESHOp::OpImportMED:
2387 case SMESHOp::OpImportSTL:
2389 case SMESHOp::OpImportCGNS:
2391 case SMESHOp::OpImportSAUV:
2392 case SMESHOp::OpImportGMF:
2394 if(checkLock(aStudy)) break;
2395 ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2399 case SMESHOp::OpFileInformation:
2401 SALOME_ListIO selected;
2402 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2404 aSel->selectedObjects( selected );
2405 if( selected.Extent() )
2407 Handle(SALOME_InteractiveObject) anIObject = selected.First();
2408 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2409 if ( !aMesh->_is_nil() )
2411 SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2417 case SMESHOp::OpExportDAT:
2418 case SMESHOp::OpExportMED:
2419 case SMESHOp::OpExportUNV:
2420 case SMESHOp::OpExportSTL:
2422 case SMESHOp::OpExportCGNS:
2424 case SMESHOp::OpExportSAUV:
2425 case SMESHOp::OpExportGMF:
2426 case SMESHOp::OpPopupExportDAT:
2427 case SMESHOp::OpPopupExportMED:
2428 case SMESHOp::OpPopupExportUNV:
2429 case SMESHOp::OpPopupExportSTL:
2431 case SMESHOp::OpPopupExportCGNS:
2433 case SMESHOp::OpPopupExportSAUV:
2434 case SMESHOp::OpPopupExportGMF:
2436 ::ExportMeshToFile(theCommandID);
2440 case SMESHOp::OpReset: // SCALAR BAR
2442 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2443 SALOME_ListIO selected;
2445 aSel->selectedObjects( selected );
2447 SALOME_ListIteratorOfListIO it(selected);
2448 for( ; it.More(); it.Next()) {
2449 Handle(SALOME_InteractiveObject) anIO = it.Value();
2450 if( anIO->hasEntry() ) {
2451 if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2452 anActor->SetControlMode( SMESH_Actor::eNone );
2453 #ifndef DISABLE_PLOT2DVIEWER
2454 SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2459 SMESH::UpdateView();
2462 case SMESHOp::OpScalarBarProperties:
2464 SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2467 case SMESHOp::OpShowScalarBar:
2469 // show/hide scalar bar
2470 ::ShowElement(theCommandID);
2473 case SMESHOp::OpSaveDistribution:
2475 // dump control distribution data to the text file
2476 ::SaveDistribution();
2480 case SMESHOp::OpShowDistribution:
2482 // show/hide distribution
2483 ::ShowElement(theCommandID);
2487 #ifndef DISABLE_PLOT2DVIEWER
2488 case SMESHOp::OpPlotDistribution:
2490 // plot distribution
2491 ::PlotDistribution();
2497 case SMESHOp::OpAutoColor:
2501 case SMESHOp::OpDisableAutoColor:
2502 ::DisableAutoColor();
2505 case SMESHOp::OpClipping:
2506 case SMESHOp::OpTransparency:
2507 case SMESHOp::OpProperties: // Display preferences (colors, shrink size, line width, ...)
2510 case SMESHOp::OpDMWireframe:
2511 case SMESHOp::OpDMShading:
2512 case SMESHOp::OpDMNodes:
2513 case SMESHOp::OpDMShrink:
2514 ::SetDisplayMode(theCommandID, myMarkerMap);
2517 //2D quadratic representation
2518 case SMESHOp::OpRepresentationLines:
2519 case SMESHOp::OpRepresentationArcs:
2520 ::SetDisplayMode(theCommandID, myMarkerMap);
2524 case SMESHOp::OpDE0DElements:
2525 case SMESHOp::OpDEEdges:
2526 case SMESHOp::OpDEFaces:
2527 case SMESHOp::OpDEVolumes:
2528 case SMESHOp::OpDEBalls:
2529 case SMESHOp::OpDEAllEntity:
2530 ::SetDisplayEntity(theCommandID);
2533 // Choose entities to be displayed
2534 case SMESHOp::OpDEChoose:
2536 ( new SMESHGUI_DisplayEntitiesDlg( SMESHGUI::desktop() ) )->exec();
2540 case SMESHOp::OpOrientationOnFaces:
2542 LightApp_SelectionMgr* mgr = selectionMgr();
2543 SALOME_ListIO selected; mgr->selectedObjects( selected );
2545 SALOME_ListIteratorOfListIO it(selected);
2546 for( ; it.More(); it.Next()) {
2547 Handle(SALOME_InteractiveObject) anIObject = it.Value();
2548 if(anIObject->hasEntry()) {
2549 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2550 anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2557 case SMESHOp::OpUpdate:
2559 if(checkLock(aStudy)) break;
2560 SUIT_OverrideCursor wc;
2562 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2565 SMESH::UpdateView();
2567 catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2568 SMESH::OnVisuException();
2570 catch (...) { // PAL16774 (Crash after display of many groups)
2571 SMESH::OnVisuException();
2575 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2576 aSel->selectedObjects( l );
2577 aSel->setSelectedObjects( l );
2581 case SMESHOp::OpHide:
2582 case SMESHOp::OpShow:
2583 case SMESHOp::OpShowOnly:
2585 SMESH::EDisplaing anAction;
2586 switch (theCommandID) {
2587 case SMESHOp::OpHide: anAction = SMESH::eErase; break;
2588 case SMESHOp::OpShow: anAction = SMESH::eDisplay; break;
2589 case SMESHOp::OpShowOnly: anAction = SMESH::eDisplayOnly; break;
2592 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2593 SALOME_ListIO sel_objects, to_process;
2595 aSel->selectedObjects( sel_objects );
2597 if ( theCommandID==SMESHOp::OpShowOnly )
2599 MESSAGE("anAction = SMESH::eDisplayOnly");
2600 startOperation( myEraseAll );
2603 extractContainers( sel_objects, to_process );
2606 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2610 SALOME_ListIteratorOfListIO It( to_process );
2611 for ( ; It.More(); It.Next())
2613 Handle(SALOME_InteractiveObject) IOS = It.Value();
2614 if ( IOS->hasEntry() )
2616 if ( !SMESH::UpdateView( anAction, IOS->getEntry() )) {
2617 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2618 break; // PAL16774 (Crash after display of many groups)
2620 if (anAction == SMESH::eDisplayOnly)
2621 anAction = SMESH::eDisplay;
2626 // PAL13338 + PAL15161 -->
2627 if ( ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) && !checkLock(aStudy)) {
2628 MESSAGE("anAction = SMESH::eDisplayOnly");
2629 SMESH::UpdateView();
2630 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2632 // PAL13338 + PAL15161 <--
2634 catch (...) { // PAL16774 (Crash after display of many groups)
2635 SMESH::OnVisuException();
2638 if (anAction == SMESH::eErase) {
2639 MESSAGE("anAction == SMESH::eErase");
2641 aSel->setSelectedObjects( l1 );
2644 aSel->setSelectedObjects( to_process );
2649 case SMESHOp::OpNode:
2651 if(checkLock(aStudy)) break;
2654 EmitSignalDeactivateDialog();
2656 ( new SMESHGUI_NodesDlg( this ) )->show();
2659 SUIT_MessageBox::warning(desktop(),
2660 tr("SMESH_WRN_WARNING"),
2661 tr("SMESH_WRN_VIEWER_VTK"));
2666 case SMESHOp::OpCreateMesh:
2667 case SMESHOp::OpCreateSubMesh:
2668 case SMESHOp::OpEditMeshOrSubMesh:
2669 case SMESHOp::OpCompute:
2670 case SMESHOp::OpPreCompute:
2671 case SMESHOp::OpEvaluate:
2672 case SMESHOp::OpMeshOrder:
2673 startOperation( theCommandID );
2675 case SMESHOp::OpCopyMesh:
2677 if (checkLock(aStudy)) break;
2678 EmitSignalDeactivateDialog();
2679 ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2682 case SMESHOp::OpBuildCompoundMesh:
2684 if (checkLock(aStudy)) break;
2685 EmitSignalDeactivateDialog();
2686 ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2690 case SMESHOp::OpDiagonalInversion:
2691 case SMESHOp::OpUnionOfTwoTriangle:
2695 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2696 tr( "NOT_A_VTK_VIEWER" ) );
2700 if ( checkLock( aStudy ) )
2703 /*Standard_Boolean aRes;
2704 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2705 if ( aMesh->_is_nil() )
2707 SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2708 tr( "SMESH_BAD_SELECTION" ) );
2712 EmitSignalDeactivateDialog();
2713 if ( theCommandID == SMESHOp::OpDiagonalInversion )
2714 ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2716 ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2719 case SMESHOp::OpOrientation:
2720 case SMESHOp::OpUnionOfTriangles:
2721 case SMESHOp::OpCuttingOfQuadrangles:
2722 case SMESHOp::OpSplitVolumes:
2726 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2727 tr( "NOT_A_VTK_VIEWER" ) );
2731 if ( checkLock( aStudy ) )
2734 EmitSignalDeactivateDialog();
2735 SMESHGUI_MultiEditDlg* aDlg = NULL;
2736 if ( theCommandID == SMESHOp::OpOrientation )
2737 aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2738 else if ( theCommandID == SMESHOp::OpUnionOfTriangles )
2739 aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2740 else if ( theCommandID == SMESHOp::OpSplitVolumes )
2741 aDlg = new SMESHGUI_SplitVolumesDlg(this);
2743 aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2748 case SMESHOp::OpSmoothing:
2750 if(checkLock(aStudy)) break;
2752 EmitSignalDeactivateDialog();
2753 ( new SMESHGUI_SmoothingDlg( this ) )->show();
2756 SUIT_MessageBox::warning(desktop(),
2757 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2761 case SMESHOp::OpExtrusion:
2763 if (checkLock(aStudy)) break;
2765 EmitSignalDeactivateDialog();
2766 ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2768 SUIT_MessageBox::warning(desktop(),
2769 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2773 case SMESHOp::OpExtrusionAlongAPath:
2775 if (checkLock(aStudy)) break;
2777 EmitSignalDeactivateDialog();
2778 ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2780 SUIT_MessageBox::warning(desktop(),
2781 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2785 case SMESHOp::OpRevolution:
2787 if(checkLock(aStudy)) break;
2789 EmitSignalDeactivateDialog();
2790 ( new SMESHGUI_RevolutionDlg( this ) )->show();
2793 SUIT_MessageBox::warning(desktop(),
2794 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2798 case SMESHOp::OpPatternMapping:
2800 if ( checkLock( aStudy ) )
2804 EmitSignalDeactivateDialog();
2805 ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2808 SUIT_MessageBox::warning(desktop(),
2809 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2813 case SMESHOp::OpSplitBiQuadratic:
2814 case SMESHOp::OpConvertMeshToQuadratic:
2815 case SMESHOp::OpCreateBoundaryElements: // create 2D mesh from 3D
2816 case SMESHOp::OpReorientFaces:
2817 case SMESHOp::OpCreateGeometryGroup:
2819 startOperation( theCommandID );
2822 case SMESHOp::OpCreateGroup:
2826 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2827 tr( "NOT_A_VTK_VIEWER" ) );
2831 if(checkLock(aStudy)) break;
2832 EmitSignalDeactivateDialog();
2833 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2835 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2836 SALOME_ListIO selected;
2838 aSel->selectedObjects( selected );
2840 int nbSel = selected.Extent();
2842 // check if mesh is selected
2843 aMesh = SMESH::GetMeshByIO( selected.First() );
2845 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2850 case SMESHOp::OpConstructGroup:
2854 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2855 tr( "NOT_A_VTK_VIEWER" ) );
2859 if(checkLock(aStudy)) break;
2860 EmitSignalDeactivateDialog();
2862 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2863 SALOME_ListIO selected;
2865 aSel->selectedObjects( selected );
2867 int nbSel = selected.Extent();
2869 // check if submesh is selected
2870 Handle(SALOME_InteractiveObject) IObject = selected.First();
2871 if (IObject->hasEntry()) {
2872 _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2874 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2875 if (!aSubMesh->_is_nil()) {
2877 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2878 // get submesh elements list by types
2879 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2880 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2881 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2882 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2883 // create group for each type o elements
2884 QString aName = IObject->getName();
2885 QStringList anEntryList;
2886 if (aNodes->length() > 0) {
2887 SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2888 aGroup->Add(aNodes.inout());
2889 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2890 anEntryList.append( aSObject->GetID().c_str() );
2892 if (aEdges->length() > 0) {
2893 SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2894 aGroup->Add(aEdges.inout());
2895 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2896 anEntryList.append( aSObject->GetID().c_str() );
2898 if (aFaces->length() > 0) {
2899 SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2900 aGroup->Add(aFaces.inout());
2901 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2902 anEntryList.append( aSObject->GetID().c_str() );
2904 if (aVolumes->length() > 0) {
2905 SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2906 aGroup->Add(aVolumes.inout());
2907 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2908 anEntryList.append( aSObject->GetID().c_str() );
2911 anApp->browseObjects( anEntryList );
2913 catch(const SALOME::SALOME_Exception & S_ex){
2914 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2921 SUIT_MessageBox::warning(desktop(),
2922 tr("SMESH_WRN_WARNING"),
2923 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2928 case SMESHOp::OpEditGroup:
2932 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2933 tr( "NOT_A_VTK_VIEWER" ) );
2937 if(checkLock(aStudy)) break;
2938 EmitSignalDeactivateDialog();
2940 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2941 SALOME_ListIO selected;
2943 aSel->selectedObjects( selected );
2945 SALOME_ListIteratorOfListIO It (selected);
2946 int nbSelectedGroups = 0;
2947 for ( ; It.More(); It.Next() )
2949 SMESH::SMESH_GroupBase_var aGroup =
2950 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
2951 if (!aGroup->_is_nil()) {
2953 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
2957 if (nbSelectedGroups == 0)
2959 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
2965 case SMESHOp::OpAddElemGroupPopup: // Add elements to group
2967 if(checkLock(aStudy)) break;
2968 if (myState == 800) {
2969 SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2970 if (aDlg) aDlg->onAdd();
2975 case SMESHOp::OpRemoveElemGroupPopup: // Remove elements from group
2977 if(checkLock(aStudy)) break;
2978 if (myState == 800) {
2979 SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2980 if (aDlg) aDlg->onRemove();
2985 case SMESHOp::OpEditGeomGroupAsGroup:
2989 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2990 tr( "NOT_A_VTK_VIEWER" ) );
2994 if(checkLock(aStudy)) break;
2995 EmitSignalDeactivateDialog();
2997 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2998 SALOME_ListIO selected;
3000 aSel->selectedObjects( selected );
3002 SALOME_ListIteratorOfListIO It (selected);
3003 for ( ; It.More(); It.Next() )
3005 SMESH::SMESH_GroupOnGeom_var aGroup =
3006 SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
3007 if (!aGroup->_is_nil()) {
3008 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3013 SMESH::SMESH_GroupOnFilter_var aGroup =
3014 SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
3015 if (!aGroup->_is_nil()) {
3016 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3024 case SMESHOp::OpUnionGroups:
3025 case SMESHOp::OpIntersectGroups:
3026 case SMESHOp::OpCutGroups:
3030 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
3031 tr( "NOT_A_VTK_VIEWER" ) );
3035 if ( checkLock( aStudy ) )
3038 EmitSignalDeactivateDialog();
3040 SMESHGUI_GroupOpDlg* aDlg = 0;
3041 if ( theCommandID == SMESHOp::OpUnionGroups )
3042 aDlg = new SMESHGUI_UnionGroupsDlg( this );
3043 else if ( theCommandID == SMESHOp::OpIntersectGroups )
3044 aDlg = new SMESHGUI_IntersectGroupsDlg( this );
3046 aDlg = new SMESHGUI_CutGroupsDlg( this );
3053 case SMESHOp::OpGroupUnderlyingElem: // Create groups of entities from existing groups of superior dimensions
3055 if ( checkLock( aStudy ) )
3058 EmitSignalDeactivateDialog();
3059 SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
3065 case SMESHOp::OpDeleteGroup: // Delete groups with their contents
3069 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
3070 tr( "NOT_A_VTK_VIEWER" ) );
3074 if ( checkLock( aStudy ) )
3077 EmitSignalDeactivateDialog();
3079 ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
3083 case SMESHOp::OpMeshInformation:
3084 case SMESHOp::OpWhatIs:
3086 int page = theCommandID == SMESHOp::OpMeshInformation ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
3087 EmitSignalDeactivateDialog();
3088 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3089 SALOME_ListIO selected;
3091 aSel->selectedObjects( selected );
3093 if ( selected.Extent() > 1 ) { // a dlg for each IO
3094 SALOME_ListIteratorOfListIO It( selected );
3095 for ( ; It.More(); It.Next() ) {
3096 SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3097 dlg->showInfo( It.Value() );
3102 SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3108 case SMESHOp::OpFindElementByPoint:
3110 startOperation( theCommandID );
3114 case SMESHOp::OpEditHypothesis:
3116 if(checkLock(aStudy)) break;
3118 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3119 SALOME_ListIO selected;
3121 aSel->selectedObjects( selected );
3123 int nbSel = selected.Extent();
3126 Handle(SALOME_InteractiveObject) anIObject = selected.First();
3127 SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
3129 if ( !aHypothesis->_is_nil() )
3131 SMESHGUI_GenericHypothesisCreator* aCreator =
3132 SMESH::GetHypothesisCreator( SMESH::toQStr( aHypothesis->GetName() ));
3135 // set geometry of mesh and sub-mesh to aCreator
3136 aSel->selectedObjects( selected, "", /*convertReferences=*/false);
3137 if ( selected.Extent() == 1 )
3139 QString subGeomID, meshGeomID;
3140 Handle(SALOME_InteractiveObject) hypIO = selected.First();
3141 if ( SMESH::GetGeomEntries( hypIO, subGeomID, meshGeomID ))
3143 if ( subGeomID.isEmpty() ) subGeomID = meshGeomID;
3144 aCreator->setShapeEntry( subGeomID );
3145 aCreator->setMainShapeEntry( meshGeomID );
3149 aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
3159 case SMESHOp::OpUnassign: // REMOVE HYPOTHESIS / ALGORITHMS
3161 if(checkLock(aStudy)) break;
3162 SUIT_OverrideCursor wc;
3164 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3165 SALOME_ListIO selected;
3167 aSel->selectedObjects( selected, QString::null, false );
3169 SALOME_ListIteratorOfListIO It(selected);
3170 for (int i = 0; It.More(); It.Next(), i++) {
3171 Handle(SALOME_InteractiveObject) IObject = It.Value();
3172 SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
3175 aSel->setSelectedObjects( l1 );
3180 case SMESHOp::OpElem0D:
3181 case SMESHOp::OpBall:
3182 case SMESHOp::OpEdge:
3183 case SMESHOp::OpTriangle:
3184 case SMESHOp::OpQuadrangle:
3185 case SMESHOp::OpPolygon:
3186 case SMESHOp::OpTetrahedron:
3187 case SMESHOp::OpHexahedron:
3188 case SMESHOp::OpPentahedron:
3189 case SMESHOp::OpPyramid:
3190 case SMESHOp::OpHexagonalPrism:
3192 if(checkLock(aStudy)) break;
3194 EmitSignalDeactivateDialog();
3195 SMDSAbs_EntityType type = SMDSEntity_Edge;
3196 switch (theCommandID) {
3197 case SMESHOp::OpElem0D: type = SMDSEntity_0D; break;
3198 case SMESHOp::OpBall: type = SMDSEntity_Ball; break;
3199 case SMESHOp::OpTriangle: type = SMDSEntity_Triangle; break;
3200 case SMESHOp::OpQuadrangle: type = SMDSEntity_Quadrangle; break;
3201 case SMESHOp::OpTetrahedron: type = SMDSEntity_Tetra; break;
3202 case SMESHOp::OpPolygon: type = SMDSEntity_Polygon; break;
3203 case SMESHOp::OpHexahedron: type = SMDSEntity_Hexa; break;
3204 case SMESHOp::OpPentahedron: type = SMDSEntity_Penta; break;
3205 case SMESHOp::OpPyramid: type = SMDSEntity_Pyramid; break;
3206 case SMESHOp::OpHexagonalPrism: type = SMDSEntity_Hexagonal_Prism; break;
3209 ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
3212 SUIT_MessageBox::warning(desktop(),
3213 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3217 case SMESHOp::OpPolyhedron:
3219 if(checkLock(aStudy)) break;
3221 EmitSignalDeactivateDialog();
3222 ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
3225 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3226 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3230 case SMESHOp::OpQuadraticEdge:
3231 case SMESHOp::OpQuadraticTriangle:
3232 case SMESHOp::OpBiQuadraticTriangle:
3233 case SMESHOp::OpQuadraticQuadrangle:
3234 case SMESHOp::OpBiQuadraticQuadrangle:
3235 case SMESHOp::OpQuadraticPolygon:
3236 case SMESHOp::OpQuadraticTetrahedron:
3237 case SMESHOp::OpQuadraticPyramid:
3238 case SMESHOp::OpQuadraticPentahedron:
3239 case SMESHOp::OpQuadraticHexahedron:
3240 case SMESHOp::OpTriQuadraticHexahedron:
3242 if(checkLock(aStudy)) break;
3244 EmitSignalDeactivateDialog();
3245 SMDSAbs_EntityType type = SMDSEntity_Last;
3247 switch (theCommandID) {
3248 case SMESHOp::OpQuadraticEdge: type = SMDSEntity_Quad_Edge; break;
3249 case SMESHOp::OpQuadraticTriangle: type = SMDSEntity_Quad_Triangle; break;
3250 case SMESHOp::OpBiQuadraticTriangle: type = SMDSEntity_BiQuad_Triangle; break;
3251 case SMESHOp::OpQuadraticQuadrangle: type = SMDSEntity_Quad_Quadrangle; break;
3252 case SMESHOp::OpBiQuadraticQuadrangle: type = SMDSEntity_BiQuad_Quadrangle; break;
3253 case SMESHOp::OpQuadraticPolygon: type = SMDSEntity_Quad_Polygon; break;
3254 case SMESHOp::OpQuadraticTetrahedron: type = SMDSEntity_Quad_Tetra; break;
3255 case SMESHOp::OpQuadraticPyramid: type = SMDSEntity_Quad_Pyramid; break;
3256 case SMESHOp::OpQuadraticPentahedron: type = SMDSEntity_Quad_Penta; break;
3257 case SMESHOp::OpQuadraticHexahedron: type = SMDSEntity_Quad_Hexa; break;
3258 case SMESHOp::OpTriQuadraticHexahedron: type = SMDSEntity_TriQuad_Hexa; break;
3261 if ( type != SMDSEntity_Last )
3262 ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
3265 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3266 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3270 case SMESHOp::OpRemoveNodes:
3272 if(checkLock(aStudy)) break;
3274 EmitSignalDeactivateDialog();
3275 ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
3278 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3279 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3283 case SMESHOp::OpRemoveElements: // REMOVES ELEMENTS
3285 if(checkLock(aStudy)) break;
3287 EmitSignalDeactivateDialog();
3288 ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
3292 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3293 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3297 case SMESHOp::OpClearMesh: {
3299 if(checkLock(aStudy)) break;
3301 SALOME_ListIO selected;
3302 if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3303 aSel->selectedObjects( selected );
3305 SUIT_OverrideCursor wc;
3306 SALOME_ListIteratorOfListIO It (selected);
3307 for ( ; It.More(); It.Next() )
3309 Handle(SALOME_InteractiveObject) IOS = It.Value();
3310 SMESH::SMESH_Mesh_var aMesh =
3311 SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
3312 if ( aMesh->_is_nil()) continue;
3314 SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3316 _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3317 SMESH::ModifiedMesh( aMeshSObj, false, true);
3318 // hide groups and submeshes
3319 _PTR(ChildIterator) anIter =
3320 SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
3321 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3323 _PTR(SObject) so = anIter->Value();
3324 SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3327 catch (const SALOME::SALOME_Exception& S_ex){
3329 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3333 SMESH::UpdateView();
3337 case SMESHOp::OpRemoveOrphanNodes:
3339 if(checkLock(aStudy)) break;
3340 SALOME_ListIO selected;
3341 if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3342 aSel->selectedObjects( selected );
3343 if ( selected.Extent() == 1 ) {
3344 Handle(SALOME_InteractiveObject) anIO = selected.First();
3345 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3346 if ( !aMesh->_is_nil() ) {
3347 bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3348 tr( "SMESH_WARNING" ),
3349 tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3350 SUIT_MessageBox::Yes |
3351 SUIT_MessageBox::No,
3352 SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3355 SUIT_OverrideCursor wc;
3356 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3357 int removed = aMeshEditor->RemoveOrphanNodes();
3358 SUIT_MessageBox::information(SMESHGUI::desktop(),
3359 tr("SMESH_INFORMATION"),
3360 tr("NB_NODES_REMOVED").arg(removed));
3361 if ( removed > 0 ) {
3362 SMESH::UpdateView();
3363 SMESHGUI::Modified();
3366 catch (const SALOME::SALOME_Exception& S_ex) {
3367 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3376 case SMESHOp::OpRenumberingNodes:
3378 if(checkLock(aStudy)) break;
3380 EmitSignalDeactivateDialog();
3381 ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3385 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3386 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3390 case SMESHOp::OpRenumberingElements:
3392 if(checkLock(aStudy)) break;
3394 EmitSignalDeactivateDialog();
3395 ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3399 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3400 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3404 case SMESHOp::OpTranslation:
3406 if(checkLock(aStudy)) break;
3408 EmitSignalDeactivateDialog();
3409 ( new SMESHGUI_TranslationDlg( this ) )->show();
3412 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3413 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3417 case SMESHOp::OpRotation:
3419 if(checkLock(aStudy)) break;
3421 EmitSignalDeactivateDialog();
3422 ( new SMESHGUI_RotationDlg( this ) )->show();
3425 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3426 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3430 case SMESHOp::OpSymmetry:
3432 if(checkLock(aStudy)) break;
3434 EmitSignalDeactivateDialog();
3435 ( new SMESHGUI_SymmetryDlg( this ) )->show();
3438 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3439 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3443 case SMESHOp::OpScale:
3445 if(checkLock(aStudy)) break;
3447 EmitSignalDeactivateDialog();
3448 ( new SMESHGUI_ScaleDlg( this ) )->show();
3451 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3452 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3457 case SMESHOp::OpSewing:
3459 if(checkLock(aStudy)) break;
3461 EmitSignalDeactivateDialog();
3462 ( new SMESHGUI_SewingDlg( this ) )->show();
3465 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3466 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3470 case SMESHOp::OpMergeNodes:
3472 if(checkLock(aStudy)) break;
3474 EmitSignalDeactivateDialog();
3475 ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3478 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3479 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3483 case SMESHOp::OpMergeElements:
3485 if (checkLock(aStudy)) break;
3487 EmitSignalDeactivateDialog();
3488 ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3490 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3491 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3496 case SMESHOp::OpMoveNode: // MAKE MESH PASS THROUGH POINT
3497 startOperation( SMESHOp::OpMoveNode );
3500 case SMESHOp::OpDuplicateNodes:
3502 if(checkLock(aStudy)) break;
3504 EmitSignalDeactivateDialog();
3505 ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3508 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3509 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3514 case SMESHOp::OpElem0DOnElemNodes: // 0D_ON_ALL_NODES
3515 startOperation( SMESHOp::OpElem0DOnElemNodes );
3518 case SMESHOp::OpSelectFiltersLibrary: // Library of selection filters
3520 static QList<int> aTypes;
3521 if ( aTypes.isEmpty() )
3523 aTypes.append( SMESH::NODE );
3524 aTypes.append( SMESH::EDGE );
3525 aTypes.append( SMESH::FACE );
3526 aTypes.append( SMESH::VOLUME );
3528 if (!myFilterLibraryDlg)
3529 myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3530 else if (myFilterLibraryDlg->isHidden())
3531 myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );