1 // Copyright (C) 2007-2016 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 <QDialogButtonBox>
159 #include <boost/shared_ptr.hpp>
162 #include <vtkCallbackCommand.h>
163 #include <vtkCamera.h>
164 #include <vtkLookupTable.h>
165 #include <vtkPlane.h>
166 #include <vtkRenderer.h>
168 // SALOME KERNEL includes
169 #include <SALOMEDSClient_ClientFactory.hxx>
170 #include <SALOMEDSClient_IParameters.hxx>
171 #include <SALOMEDSClient_SComponent.hxx>
172 #include <SALOMEDSClient_StudyBuilder.hxx>
173 #include <SALOMEDS_Study.hxx>
174 #include <SALOMEDS_SObject.hxx>
175 #include "utilities.h"
178 #include <Standard_ErrorHandler.hxx>
179 #include <NCollection_DataMap.hxx>
180 #include <NCollection_DoubleMap.hxx>
182 #include <Basics_Utils.hxx>
184 // Below macro, when uncommented, switches on simplified (more performant) algorithm
185 // of auto-color picking up
186 #define SIMPLE_AUTOCOLOR
191 //=============================================================
192 void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
195 void ExportMeshToFile(int theCommandID);
197 void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap);
199 void SetDisplayEntity(int theCommandID);
201 int ActionToControl( int theID, bool theReversed = false );
203 void Control( int theCommandID );
206 //================================================================================
208 * \brief Reads meshes from file
210 //================================================================================
212 void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
216 std::string myExtension;
218 if ( theCommandID == SMESHOp::OpImportMED ||
219 theCommandID == SMESHOp::OpPopupImportMED ) {
220 filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.*med)" );
221 filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
223 else if ( theCommandID == SMESHOp::OpImportUNV ||
224 theCommandID == SMESHOp::OpPopupImportUNV ) {
225 filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
227 else if ( theCommandID == SMESHOp::OpImportDAT ||
228 theCommandID == SMESHOp::OpPopupImportDAT ) {
229 filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
231 else if ( theCommandID == SMESHOp::OpImportSTL ||
232 theCommandID == SMESHOp::OpPopupImportSTL ) {
233 filter.append( QObject::tr( "STL_FILES_FILTER" ) + " (*.stl)" );
235 else if ( theCommandID == SMESHOp::OpImportCGNS ||
236 theCommandID == SMESHOp::OpPopupImportCGNS ) {
237 filter.append( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
239 else if ( theCommandID == SMESHOp::OpImportSAUV ||
240 theCommandID == SMESHOp::OpPopupImportSAUV ) {
241 filter.append( QObject::tr( "SAUV files (*.sauv*)" ) );
242 filter.append( QObject::tr( "All files (*)" ) );
244 else if ( theCommandID == SMESHOp::OpImportGMF ||
245 theCommandID == SMESHOp::OpPopupImportGMF ) {
246 filter.append( QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)" );
247 filter.append( QObject::tr( "GMF_BINARY_FILES_FILTER") + " (*.meshb)" );
250 QString anInitialPath = "";
251 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
252 anInitialPath = QDir::currentPath();
254 QStringList filenames;
255 bool toCreateGroups = true;
257 // if ( theCommandID == SMESHOp::OpImportGMF ) { // GMF
258 // SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
259 // ( SMESHGUI::desktop(), true, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
260 // fd->setWindowTitle( QObject::tr( "SMESH_IMPORT_MESH" ) );
261 // fd->setNameFilters( filter );
262 // fd->SetChecked( true );
264 // filenames << fd->selectedFile();
265 // toCreateGroups = fd->IsChecked();
271 filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
274 QObject::tr( "SMESH_IMPORT_MESH" ) );
276 if ( filenames.count() > 0 )
278 SUIT_OverrideCursor wc;
279 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
282 QStringList anEntryList;
283 bool isEmpty = false;
284 for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it )
286 QString filename = *it;
287 SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
289 switch ( theCommandID ) {
290 case SMESHOp::OpImportDAT:
291 case SMESHOp::OpPopupImportDAT:
293 // DAT format (currently unsupported)
294 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
295 arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
298 case SMESHOp::OpImportUNV:
299 case SMESHOp::OpPopupImportUNV:
302 aMeshes->length( 1 );
303 aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toUtf8().constData() );
304 if ( aMeshes[0]->_is_nil() )
305 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
306 arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
309 case SMESHOp::OpImportMED:
310 case SMESHOp::OpPopupImportMED:
313 SMESH::DriverMED_ReadStatus res;
314 aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toUtf8().constData(), res );
315 if ( res != SMESH::DRS_OK ) {
316 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
317 arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
321 case SMESHOp::OpImportSTL:
322 case SMESHOp::OpPopupImportSTL:
325 aMeshes->length( 1 );
326 aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toUtf8().constData() );
327 if ( aMeshes[0]->_is_nil() ) {
328 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
329 arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
333 case SMESHOp::OpImportCGNS:
334 case SMESHOp::OpPopupImportCGNS:
337 SMESH::DriverMED_ReadStatus res;
338 aMeshes = theComponentMesh->CreateMeshesFromCGNS( filename.toUtf8().constData(), res );
339 if ( res != SMESH::DRS_OK ) {
340 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
341 arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
345 case SMESHOp::OpImportSAUV:
346 case SMESHOp::OpPopupImportSAUV:
349 SMESH::DriverMED_ReadStatus res;
350 aMeshes = theComponentMesh->CreateMeshesFromSAUV( filename.toUtf8().constData(), res );
351 if ( res != SMESH::DRS_OK ) {
352 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
353 arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
357 case SMESHOp::OpImportGMF:
358 case SMESHOp::OpPopupImportGMF:
361 SMESH::ComputeError_var res;
362 aMeshes->length( 1 );
363 aMeshes[0] = theComponentMesh->CreateMeshesFromGMF( filename.toUtf8().constData(),
366 if ( res->code != SMESH::DRS_OK ) {
367 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
368 arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res->code ).toLatin1().data() ) ) );
369 if ( strlen( res->comment.in() ) > 0 ) {
370 errors.back() += ": ";
371 errors.back() += res->comment.in();
378 catch ( const SALOME::SALOME_Exception& S_ex ) {
379 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
380 arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
383 for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ )
385 _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
387 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
388 _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
389 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
390 if ( theCommandID == SMESHOp::OpImportUNV ) // mesh names aren't taken from the file for UNV import
391 SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
393 anEntryList.append( aMeshSO->GetID().c_str() );
401 // update Object browser
402 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
404 // browse to the published meshes
405 if( LightApp_Application* anApp =
406 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
407 anApp->browseObjects( anEntryList );
409 // show Error message box if there were errors
410 if ( errors.count() > 0 ) {
411 SUIT_MessageBox::critical( SMESHGUI::desktop(),
412 QObject::tr( "SMESH_ERROR" ),
413 QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
416 // show warning message box, if some imported mesh is empty
418 SUIT_MessageBox::warning( SMESHGUI::desktop(),
419 QObject::tr( "SMESH_WRN_WARNING" ),
420 QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
425 //================================================================================
427 * \brief Export selected meshes or groups into a file
429 //================================================================================
431 void ExportMeshToFile( int theCommandID )
433 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
434 SALOME_ListIO selected;
436 aSel->selectedObjects( selected );
438 const bool isDAT = ( theCommandID == SMESHOp::OpExportDAT ||
439 theCommandID == SMESHOp::OpPopupExportDAT );
440 const bool isMED = ( theCommandID == SMESHOp::OpExportMED ||
441 theCommandID == SMESHOp::OpPopupExportMED );
442 const bool isUNV = ( theCommandID == SMESHOp::OpExportUNV ||
443 theCommandID == SMESHOp::OpPopupExportUNV );
444 const bool isSTL = ( theCommandID == SMESHOp::OpExportSTL ||
445 theCommandID == SMESHOp::OpPopupExportSTL );
446 const bool isCGNS= ( theCommandID == SMESHOp::OpExportCGNS ||
447 theCommandID == SMESHOp::OpPopupExportCGNS );
448 const bool isSAUV= ( theCommandID == SMESHOp::OpExportSAUV ||
449 theCommandID == SMESHOp::OpPopupExportSAUV );
450 const bool isGMF = ( theCommandID == SMESHOp::OpExportGMF ||
451 theCommandID == SMESHOp::OpPopupExportGMF );
453 const bool multiMeshSupported = ( isMED || isCGNS ); // file can hold several meshes
454 if ( selected.Extent() == 0 || ( selected.Extent() > 1 && !multiMeshSupported ))
456 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
457 bool aCheckWarn = true;
459 aCheckWarn = resMgr->booleanValue( "SMESH", "show_warning", false );
460 // get mesh object from selection and check duplication of their names
461 bool hasDuplicatedMeshNames = false;
462 QList< QPair< SMESH::SMESH_IDSource_var, QString > > aMeshList;
463 QList< QPair< SMESH::SMESH_IDSource_var, QString > >::iterator aMeshIter;
464 SALOME_ListIteratorOfListIO It( selected );
465 for( ; It.More(); It.Next() )
467 Handle(SALOME_InteractiveObject) anIObject = It.Value();
468 SMESH::SMESH_IDSource_var aMeshItem =
469 SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIObject);
470 if ( aMeshItem->_is_nil() ) {
471 SUIT_MessageBox::warning( SMESHGUI::desktop(),
472 QObject::tr( "SMESH_WRN_WARNING" ),
473 QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
476 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( aMeshItem );
477 if ( aCheckWarn && !aGroup->_is_nil() )
479 QMessageBox msgBox(SUIT_MessageBox::Warning,
480 QObject::tr("SMESH_WRN_WARNING"),
481 QObject::tr("SMESH_EXPORT_ONLY_GPOUP"),
482 QMessageBox::StandardButton::NoButton,
483 SMESHGUI::desktop());
484 QCheckBox dontShowCheckBox(QObject::tr("SMESH_WRN_SHOW_DLG_CHECKBOX"));
485 msgBox.addButton(QMessageBox::Ok);
486 msgBox.addButton(QMessageBox::Cancel);
487 msgBox.setDefaultButton(QMessageBox::Cancel);
488 QGridLayout* lt = qobject_cast<QGridLayout*>(msgBox.layout());
489 QDialogButtonBox* btnbox = msgBox.findChild<QDialogButtonBox*>();
490 lt->addWidget(&dontShowCheckBox, lt->rowCount(), lt->columnCount()-1, lt->rowCount(), lt->columnCount());
491 lt->addWidget(btnbox, lt->rowCount(), 0, lt->rowCount(), lt->columnCount());
492 if(msgBox.exec() == QMessageBox::Ok)
494 if(dontShowCheckBox.checkState() == Qt::Checked)
497 resMgr->setValue( "SMESH", "show_warning", false);
505 QString aMeshName = anIObject->getName();
507 // check for name duplications
508 if ( !hasDuplicatedMeshNames )
509 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
510 if( aMeshName == (*aMeshIter).second ) {
511 hasDuplicatedMeshNames = true;
516 aMeshList.append( QPair< SMESH::SMESH_IDSource_var, QString >( aMeshItem, aMeshName ) );
519 if( hasDuplicatedMeshNames && isMED ) {
520 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
521 QObject::tr("SMESH_WRN_WARNING"),
522 QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
523 QObject::tr("SMESH_BUT_YES"),
524 QObject::tr("SMESH_BUT_NO"), 0, 1);
529 aMeshIter = aMeshList.begin();
530 SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
531 SMESH::SMESH_Mesh_var aMesh = aMeshOrGroup->GetMesh();
532 QString aMeshName = (*aMeshIter).second;
534 if ( isMED || isCGNS || isSAUV ) // formats where group names must be unique
536 // check for equal group names within each mesh
537 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
538 SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
539 if ( !aMeshItem->_is_nil() && aMeshItem->HasDuplicatedGroupNamesMED()) {
540 int aRet = SUIT_MessageBox::warning
541 (SMESHGUI::desktop(),
542 QObject::tr("SMESH_WRN_WARNING"),
543 QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
544 QObject::tr("SMESH_BUT_YES"),
545 QObject::tr("SMESH_BUT_NO"), 0, 1);
552 // Warn the user about presence of not supported elements
554 std::vector< SMESH::EntityType > notSupportedElemTypes, presentNotSupported;
558 notSupportedElemTypes.push_back( SMESH::Entity_0D );
559 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
564 notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
565 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
566 notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
567 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
568 notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
569 notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
570 notSupportedElemTypes.push_back( SMESH::Entity_0D );
571 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
576 notSupportedElemTypes.push_back( SMESH::Entity_Edge );
577 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Edge );
578 notSupportedElemTypes.push_back( SMESH::Entity_0D );
579 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
584 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
589 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
590 notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Triangle );
591 notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
592 notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
593 notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
594 notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
595 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
596 notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
601 notSupportedElemTypes.push_back( SMESH::Entity_0D );
602 notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
603 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
604 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
605 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
606 notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
607 notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
608 notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
609 notSupportedElemTypes.push_back( SMESH::Entity_Ball );
611 if ( ! notSupportedElemTypes.empty() )
613 SMESH::long_array_var nbElems = aMeshOrGroup->GetMeshInfo();
614 for ( size_t iType = 0; iType < notSupportedElemTypes.size(); ++iType )
615 if ( nbElems[ notSupportedElemTypes[ iType ]] > 0 )
616 presentNotSupported.push_back( notSupportedElemTypes[ iType ]);
618 if ( !presentNotSupported.empty() )
621 const char* typeMsg[] = {
622 "SMESH_NODES", "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES",
623 "SMESH_TRIANGLES", "SMESH_QUADRATIC_TRIANGLES", "SMESH_BIQUADRATIC_TRIANGLES",
624 "SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES", "SMESH_BIQUADRATIC_QUADRANGLES",
625 "SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
626 "SMESH_TETRAHEDRA","SMESH_QUADRATIC_TETRAHEDRONS","SMESH_PYRAMIDS",
627 "SMESH_QUADRATIC_PYRAMIDS","SMESH_HEXAHEDRA","SMESH_QUADRATIC_HEXAHEDRONS",
628 "SMESH_TRIQUADRATIC_HEXAHEDRONS","SMESH_PENTAHEDRA","SMESH_QUADRATIC_PENTAHEDRONS",
629 "SMESH_OCTAHEDRA","SMESH_POLYEDRONS","SMESH_QUADRATIC_POLYEDRONS","SMESH_BALLS"
631 // is typeMsg complete? (compilation failure mains that enum SMDSAbs_EntityType changed)
632 const int nbTypes = sizeof( typeMsg ) / sizeof( const char* );
633 int _assert[( nbTypes == SMESH::Entity_Last ) ? 2 : -1 ]; _assert[0]=_assert[1];
635 QString andStr = " " + QObject::tr("SMESH_AND") + " ", comma(", ");
636 for ( size_t iType = 0; iType < presentNotSupported.size(); ++iType ) {
637 typeNames += QObject::tr( typeMsg[ presentNotSupported[ iType ]]);
638 if ( iType != presentNotSupported.size() - 1 )
639 typeNames += ( iType == presentNotSupported.size() - 2 ) ? andStr : comma;
641 int aRet = SUIT_MessageBox::warning
642 (SMESHGUI::desktop(),
643 QObject::tr("SMESH_WRN_WARNING"),
644 QObject::tr("EXPORT_NOT_SUPPORTED").arg(aMeshName).arg(format).arg(typeNames),
645 QObject::tr("SMESH_BUT_YES"),
646 QObject::tr("SMESH_BUT_NO"), 0, 1);
651 // Get parameters of export operation
654 SMESH::MED_VERSION aFormat = SMESH::MED_V2_2;
655 // Init the parameters with the default values
656 bool aIsASCII_STL = true;
657 bool toCreateGroups = false;
659 toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
660 bool toOverwrite = true;
661 bool toFindOutDim = true;
663 QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
664 QString anInitialPath = "";
665 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
666 anInitialPath = QDir::currentPath();
668 QList< QPair< GEOM::ListOfFields_var, QString > > aFieldList;
670 // Get a file name to write in and additional otions
671 if ( isUNV || isDAT || isGMF ) // Export w/o options
674 aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
676 aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
678 aFilter = QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)" +
679 ";;" + QObject::tr( "GMF_BINARY_FILES_FILTER" ) + " (*.meshb)";
680 if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
681 aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
682 anInitialPath + QString("/") + aMeshName,
683 aFilter, aTitle, false);
685 else if ( isCGNS )// Export to CGNS
687 SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
688 fd->setWindowTitle( aTitle );
689 fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
690 if ( !anInitialPath.isEmpty() )
691 fd->setDirectory( anInitialPath );
692 fd->selectFile(aMeshName);
693 SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
694 fd->setValidator( fv );
697 aFilename = fd->selectedFile();
698 toOverwrite = fv->isOverwrite();
702 else if ( isSTL ) // Export to STL
704 QMap<QString, int> aFilterMap;
705 aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
706 aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" ) + " (*.stl)", 0 );
709 QMap<QString, int>::const_iterator it = aFilterMap.begin();
710 for ( ; it != aFilterMap.end(); ++it )
711 filters.push_back( it.key() );
713 SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
714 fd->setWindowTitle( aTitle );
715 fd->setNameFilters( filters );
716 fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
717 if ( !anInitialPath.isEmpty() )
718 fd->setDirectory( anInitialPath );
719 fd->selectFile(aMeshName);
723 aFilename = fd->selectedFile();
724 aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
729 else if ( isMED || isSAUV ) // Export to MED or SAUV
731 QMap<QString, SMESH::MED_VERSION> aFilterMap;
732 //QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
734 QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
735 //aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v21 ) + " (*.med)", SMESH::MED_V2_1 );
736 aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v22 ) + " (*.med)", SMESH::MED_V2_2 );
739 aFilterMap.insert("All files (*)", SMESH::MED_V2_1 );
740 aFilterMap.insert("SAUV files (*.sauv)", SMESH::MED_V2_2 );
741 aFilterMap.insert("SAUV files (*.sauve)", SMESH::MED_V2_1 );
745 QString aDefaultFilter;
746 QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
747 for ( ; it != aFilterMap.end(); ++it ) {
748 filters.push_back( it.key() );
749 if (it.value() == SMESH::MED_V2_2)
750 aDefaultFilter = it.key();
752 QStringList checkBoxes;
753 checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM");
755 SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
756 QList< QWidget* > wdgList;
757 if ( fieldSelWdg->GetAllFeilds( aMeshList, aFieldList ))
758 wdgList.append( fieldSelWdg );
760 SalomeApp_CheckFileDlg* fd =
761 new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true, wdgList );
762 fd->setWindowTitle( aTitle );
763 fd->setNameFilters( filters );
764 fd->selectNameFilter( aDefaultFilter );
765 fd->SetChecked( toCreateGroups, 0 );
766 fd->SetChecked( toFindOutDim, 1 );
767 if ( !anInitialPath.isEmpty() )
768 fd->setDirectory( anInitialPath );
769 fd->selectFile(aMeshName);
772 QListView *lview = fd->findChild<QListView*>("listView");
774 lview->setMinimumHeight(200);
776 QTreeView *tview = fd->findChild<QTreeView*>("treeView");
778 tview->setMinimumHeight(200);
781 SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
782 fd->setValidator( fv );
787 aFilename = fd->selectedFile();
789 aFilename = QString::null;
792 aFormat = aFilterMap[fd->selectedNameFilter()];
793 toOverwrite = fv->isOverwrite();
795 if ( !aFilename.isEmpty() ) {
796 // med-2.1 does not support poly elements
797 if ( aFormat==SMESH::MED_V2_1 )
798 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
799 SMESH::SMESH_IDSource_var aMeshItem = (*aMeshIter).first;
800 SMESH::long_array_var nbElems = aMeshItem->GetMeshInfo();
801 if ( nbElems[ SMESH::Entity_Polygon ] + nbElems[ SMESH::Entity_Quad_Polygon ] +
802 nbElems[ SMESH::Entity_Polyhedra ] + nbElems[ SMESH::Entity_Quad_Polyhedra ])
804 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
805 QObject::tr("SMESH_WRN_WARNING"),
806 QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
807 QObject::tr("SMESH_BUT_YES"),
808 QObject::tr("SMESH_BUT_NO"), 0, 1);
816 // can't append to an existing using other format
817 SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
818 bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toUtf8().constData(), aVersion );
819 if( !isVersionOk || aVersion != aFormat ) {
820 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
821 QObject::tr("SMESH_WRN_WARNING"),
822 QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
823 QObject::tr("SMESH_BUT_YES"),
824 QObject::tr("SMESH_BUT_NO"), 0, 1);
831 QStringList aMeshNamesCollisionList;
832 SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() );
833 for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
834 QString anExistingMeshName( aMeshNames[ i ] );
835 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
836 QString anExportMeshName = (*aMeshIter).second;
837 if( anExportMeshName == anExistingMeshName ) {
838 aMeshNamesCollisionList.append( anExportMeshName );
843 if( !aMeshNamesCollisionList.isEmpty() ) {
844 QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
845 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
846 QObject::tr("SMESH_WRN_WARNING"),
847 QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
848 QObject::tr("SMESH_BUT_YES"),
849 QObject::tr("SMESH_BUT_NO"),
850 QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
859 toCreateGroups = fd->IsChecked(0);
860 toFindOutDim = fd->IsChecked(1);
861 fieldSelWdg->GetSelectedFeilds();
862 if ( !fieldSelWdg->parent() )
873 if ( !aFilename.isEmpty() ) {
874 // Check whether the file already exists and delete it if yes
875 QFile aFile( aFilename );
876 if ( aFile.exists() && toOverwrite )
878 SUIT_OverrideCursor wc;
881 // Renumbering is not needed since SMDS redesign in V6.2.0 (Nov 2010)
882 // bool Renumber = false;
883 // // PAL 14172 : Check of we have to renumber or not from the preferences before export
885 // Renumber= resMgr->booleanValue("renumbering");
887 // SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
888 // aMeshEditor->RenumberNodes();
889 // aMeshEditor->RenumberElements();
890 // if ( SMESHGUI::automaticUpdate() )
891 // SMESH::UpdateView();
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 const GEOM::ListOfFields& fields = aFieldList[ aMeshIndex ].first.in();
901 const QString& geoAssFields = aFieldList[ aMeshIndex ].second;
902 const bool hasFields = ( fields.length() || !geoAssFields.isEmpty() );
903 if ( !hasFields && aMeshOrGroup->_is_equivalent( aMeshItem ))
904 aMeshItem->ExportToMEDX( aFilename.toUtf8().data(), toCreateGroups,
905 aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim );
907 aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups,
908 aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim,
909 fields, geoAssFields.toLatin1().data() );
914 for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ )
916 SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
917 if( !aMeshItem->_is_nil() )
918 aMeshItem->ExportSAUV( aFilename.toUtf8().data(), toCreateGroups );
923 if ( aMeshOrGroup->_is_equivalent( aMesh ))
924 aMesh->ExportDAT( aFilename.toUtf8().data() );
926 aMesh->ExportPartToDAT( aMeshOrGroup, aFilename.toUtf8().data() );
930 if ( aMeshOrGroup->_is_equivalent( aMesh ))
931 aMesh->ExportUNV( aFilename.toUtf8().data() );
933 aMesh->ExportPartToUNV( aMeshOrGroup, aFilename.toUtf8().data() );
937 if ( aMeshOrGroup->_is_equivalent( aMesh ))
938 aMesh->ExportSTL( aFilename.toUtf8().data(), aIsASCII_STL );
940 aMesh->ExportPartToSTL( aMeshOrGroup, aFilename.toUtf8().data(), aIsASCII_STL );
944 aMeshIter = aMeshList.begin();
945 for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
947 SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
948 SMESH::SMESH_Mesh_var aMeshItem = aMeshOrGroup->GetMesh();
949 aMeshItem->ExportCGNS( aMeshOrGroup,
950 aFilename.toUtf8().data(),
951 toOverwrite && aMeshIndex == 0 );
956 toCreateGroups = true;
957 aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
960 catch (const SALOME::SALOME_Exception& S_ex){
962 SUIT_MessageBox::warning(SMESHGUI::desktop(),
963 QObject::tr("SMESH_WRN_WARNING"),
964 QObject::tr("SMESH_EXPORT_FAILED"));
970 inline void InverseEntityMode(unsigned int& theOutputMode,
971 unsigned int theMode)
973 bool anIsNotPresent = ~theOutputMode & theMode;
975 theOutputMode |= theMode;
977 theOutputMode &= ~theMode;
980 void SetDisplayEntity(int theCommandID)
982 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
983 SALOME_ListIO selected;
985 aSel->selectedObjects( selected );
987 if ( selected.Extent() >= 1 ) {
988 SUIT_OverrideCursor wc;
989 SALOME_ListIteratorOfListIO It( selected );
990 for( ; It.More(); It.Next()){
991 Handle(SALOME_InteractiveObject) IObject = It.Value();
992 if(IObject->hasEntry()){
993 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
994 unsigned int aMode = anActor->GetEntityMode();
995 switch(theCommandID){
996 case SMESHOp::OpDE0DElements: InverseEntityMode(aMode,SMESH_Actor::e0DElements); break;
997 case SMESHOp::OpDEEdges: InverseEntityMode(aMode,SMESH_Actor::eEdges); break;
998 case SMESHOp::OpDEFaces: InverseEntityMode(aMode,SMESH_Actor::eFaces); break;
999 case SMESHOp::OpDEVolumes: InverseEntityMode(aMode,SMESH_Actor::eVolumes); break;
1000 case SMESHOp::OpDEBalls: InverseEntityMode(aMode,SMESH_Actor::eBallElem); break;
1001 case SMESHOp::OpDEAllEntity: aMode = SMESH_Actor::eAllEntity; break;
1004 anActor->SetEntityMode(aMode);
1013 SalomeApp_Application* app =
1014 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1018 LightApp_SelectionMgr* aSel = app->selectionMgr();
1019 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1020 if ( !aSel || !appStudy )
1023 SALOME_ListIO selected;
1024 aSel->selectedObjects( selected );
1025 if ( selected.IsEmpty() )
1028 Handle(SALOME_InteractiveObject) anIObject = selected.First();
1030 _PTR(Study) aStudy = appStudy->studyDS();
1031 _PTR(SObject) aMainSObject = aStudy->FindObjectID( anIObject->getEntry() );
1032 SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1033 if ( aMainObject->_is_nil() )
1036 SUIT_OverrideCursor wc;
1038 aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
1040 QList<SALOMEDS::Color> aReservedColors;
1042 SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
1043 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1045 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1047 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
1048 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
1049 #else // old algorithm for auto-colors
1050 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1051 aReservedColors.append( aColor );
1052 #endif // SIMPLE_AUTOCOLOR
1053 aGroupObject->SetColor( aColor );
1055 _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
1056 if ( aGroupSObject ) {
1059 if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
1060 switch ( aGroupObject->GetType ()) {
1062 anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1064 anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1066 anActor->Set0DColor( aColor.R, aColor.G, aColor.B ); break;
1068 anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1070 SMESH::GetColor("SMESH", "volume_color", c, delta, "255,0,170|-100");
1071 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1074 SMESH::GetColor("SMESH", "fill_color", c, delta, "0,170,255|-100");
1075 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta );
1081 SMESH::RepaintCurrentView();
1084 void OverallMeshQuality()
1086 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1087 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1088 SALOME_ListIO selected;
1090 aSel->selectedObjects( selected );
1092 if ( selected.IsEmpty() ) return;
1093 SALOME_ListIteratorOfListIO It( selected );
1094 for ( ; It.More(); It.Next() ) {
1095 SMESHGUI_CtrlInfoDlg* ctrlDlg = new SMESHGUI_CtrlInfoDlg( SMESHGUI::desktop() );
1096 ctrlDlg->showInfo( It.Value() );
1101 QString functorToString( SMESH::Controls::FunctorPtr f )
1103 QString type = QObject::tr( "UNKNOWN_CONTROL" );
1104 if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
1105 type = QObject::tr( "VOLUME_3D_ELEMENTS" );
1106 else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
1107 type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
1108 else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
1109 type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
1110 else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
1111 type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
1112 else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
1113 type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
1114 else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
1115 type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
1116 else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
1117 type = QObject::tr( "WARP_ELEMENTS" );
1118 else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
1119 type = QObject::tr( "TAPER_ELEMENTS" );
1120 else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
1121 type = QObject::tr( "SKEW_ELEMENTS" );
1122 else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
1123 type = QObject::tr( "AREA_ELEMENTS" );
1124 else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
1125 type = QObject::tr( "LENGTH_EDGES" );
1126 else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
1127 type = QObject::tr( "LENGTH2D_EDGES" );
1128 else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
1129 type = QObject::tr( "MULTI_BORDERS" );
1130 else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
1131 type = QObject::tr( "MULTI2D_BORDERS" );
1132 else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
1133 type = QObject::tr( "FREE_NODES" );
1134 else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
1135 type = QObject::tr( "FREE_EDGES" );
1136 else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
1137 type = QObject::tr( "FREE_BORDERS" );
1138 else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
1139 type = QObject::tr( "FREE_FACES" );
1140 else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
1141 type = QObject::tr( "BARE_BORDER_VOLUME" );
1142 else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
1143 type = QObject::tr( "BARE_BORDER_FACE" );
1144 else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
1145 type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
1146 else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
1147 type = QObject::tr( "OVER_CONSTRAINED_FACE" );
1148 else if ( dynamic_cast< SMESH::Controls::CoincidentNodes* >( f.get() ) )
1149 type = QObject::tr( "EQUAL_NODE" );
1150 else if ( dynamic_cast< SMESH::Controls::CoincidentElements1D* >( f.get() ) )
1151 type = QObject::tr( "EQUAL_EDGE" );
1152 else if ( dynamic_cast< SMESH::Controls::CoincidentElements2D* >( f.get() ) )
1153 type = QObject::tr( "EQUAL_FACE" );
1154 else if ( dynamic_cast< SMESH::Controls::CoincidentElements3D* >( f.get() ) )
1155 type = QObject::tr( "EQUAL_VOLUME" );
1156 else if ( dynamic_cast< SMESH::Controls::NodeConnectivityNumber* >( f.get() ) )
1157 type = QObject::tr( "NODE_CONNECTIVITY_NB" );
1161 void SaveDistribution()
1163 LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1164 SALOME_ListIO selected;
1166 aSel->selectedObjects( selected );
1168 if ( selected.Extent() == 1 ) {
1169 Handle(SALOME_InteractiveObject) anIO = selected.First();
1170 if ( anIO->hasEntry() ) {
1171 SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1173 anActor->GetScalarBarActor() &&
1174 anActor->GetControlMode() != SMESH_Actor::eNone )
1176 SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
1177 SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
1178 if ( aScalarBarActor && aFunctor ) {
1179 SMESH::Controls::NumericalFunctor* aNumFun =
1180 dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
1182 std::vector<int> elements;
1183 SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
1184 if ( mesh->_is_nil() ) {
1185 SMESH::SMESH_IDSource_var idSource =
1186 SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
1187 if ( !idSource->_is_nil() )
1189 SMESH::long_array_var ids = idSource->GetIDs();
1190 elements.resize( ids->length() );
1191 for ( unsigned i = 0; i < elements.size(); ++i )
1192 elements[i] = ids[i];
1195 int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
1196 vtkLookupTable* lookupTable =
1197 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
1198 double * minmax = lookupTable->GetRange();
1199 bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
1200 std::vector<int> nbEvents;
1201 std::vector<double> funValues;
1202 aNumFun->GetHistogram( nbIntervals, nbEvents, funValues,
1203 elements, minmax, isLogarithmic );
1204 QString anInitialPath = "";
1205 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
1206 anInitialPath = QDir::currentPath();
1207 QString aMeshName = anIO->getName();
1209 filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
1210 filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
1211 QString aFilename = anInitialPath + "/" + aMeshName + "_" +
1212 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
1213 aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
1216 QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
1218 if ( !aFilename.isEmpty() ) {
1219 QFile f( aFilename );
1220 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
1221 QTextStream out( &f );
1222 out << "# Mesh: " << aMeshName << endl;
1223 out << "# Control: " << functorToString( aFunctor ) << endl;
1225 out.setFieldWidth( 10 );
1226 for ( int i = 0; i < (int)qMin( nbEvents.size(), funValues.size()-1 ); i++ )
1227 out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
1238 void ShowElement( int theCommandID )
1240 LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1241 SALOME_ListIO selected;
1243 aSel->selectedObjects( selected );
1245 if ( selected.Extent() == 1 ) {
1246 Handle(SALOME_InteractiveObject) anIO = selected.First();
1247 if ( anIO->hasEntry() ) {
1248 SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1250 anActor->GetScalarBarActor() &&
1251 anActor->GetControlMode() != SMESH_Actor::eNone )
1253 SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
1254 if ( theCommandID == SMESHOp::OpShowDistribution ) {
1255 aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
1257 else if ( theCommandID == SMESHOp::OpShowScalarBar ) {
1258 aScalarBarActor->SetVisibility( !aScalarBarActor->GetVisibility());
1265 #ifndef DISABLE_PLOT2DVIEWER
1266 void PlotDistribution()
1268 SalomeApp_Application* app =
1269 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1273 LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1274 SALOME_ListIO selected;
1276 aSel->selectedObjects( selected );
1278 if ( selected.Extent() == 1 ) {
1279 Handle(SALOME_InteractiveObject) anIO = selected.First();
1280 if ( anIO->hasEntry() ) {
1281 //Find Actor by entry before getting Plot2d viewer,
1282 //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
1283 SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1285 SUIT_ViewManager* aViewManager =
1286 app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
1290 SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
1294 Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1298 if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone )
1300 SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1301 QString functorName = functorToString( anActor->GetFunctor());
1302 QString aHistogramName("%1 : %2");
1303 aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1304 aHistogram->setName(aHistogramName);
1305 aHistogram->setHorTitle(functorName);
1306 aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
1307 aPlot->displayObject(aHistogram, true);
1312 #endif //DISABLE_PLOT2DVIEWER
1314 void DisableAutoColor()
1316 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1317 SALOME_ListIO selected;
1319 aSel->selectedObjects( selected );
1321 if ( selected.Extent() ) {
1322 Handle(SALOME_InteractiveObject) anIObject = selected.First();
1323 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1324 if ( !aMesh->_is_nil() ) {
1325 aMesh->SetAutoColor( false );
1332 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1333 SALOME_ListIO selected;
1335 aSel->selectedObjects( selected );
1336 if ( selected.Extent() )
1338 Handle(SALOME_InteractiveObject) anIObject = selected.First();
1339 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1340 _PTR(SObject) aSObj = aStudy->FindObjectID(anIObject->getEntry());
1342 if ( aStudy->GetUseCaseBuilder()->SortChildren( aSObj, true/*AscendingOrder*/ ) ) {
1343 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1350 void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap)
1352 SALOME_ListIO selected;
1353 SalomeApp_Application* app =
1354 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1358 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1359 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1360 if ( !aSel || !appStudy )
1363 if ( theCommandID == SMESHOp::OpClipping ) { // Clipping dialog can be activated without selection
1364 if ( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
1365 aModule->EmitSignalDeactivateDialog();
1366 if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
1367 (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
1372 _PTR(Study) aStudy = appStudy->studyDS();
1374 aSel->selectedObjects( selected );
1376 if ( selected.Extent() >= 1 )
1378 switch ( theCommandID ) {
1379 case SMESHOp::OpTransparency:
1381 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1382 (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
1385 case SMESHOp::OpProperties:
1388 QColor faceColor, edgeColor, nodeColor, elem0dColor, ballColor;
1389 QColor orientationColor, outlineColor, volumeColor;
1390 int deltaF = 0, deltaV = 0;
1393 double ballScale = 1.0;
1395 int outlineWidth = 1;
1396 double shrinkCoef = 0.0;
1397 double orientationScale = 0.0;
1398 bool orientation3d = false;
1399 VTK::MarkerType markerType = VTK::MT_NONE;
1400 VTK::MarkerScale markerScale = VTK::MS_NONE;
1402 bool hasNodes = false;
1403 int presentEntities = 0;
1404 bool firstTime = true;
1406 SALOME_ListIteratorOfListIO It( selected );
1407 for ( ; It.More(); It.Next() ) {
1408 Handle(SALOME_InteractiveObject) IObject = It.Value();
1409 if ( !IObject->hasEntry() ) continue;
1410 SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1411 if ( !anActor || !anActor->GetObject() ) continue;
1414 // nodes: color, marker
1415 anActor->GetNodeColor( color[0], color[1], color[2] );
1416 nodeColor.setRgbF( color[0], color[1], color[2] );
1417 markerType = anActor->GetMarkerType();
1418 markerScale = anActor->GetMarkerScale();
1419 markerId = anActor->GetMarkerTexture();
1420 // edges: color, width
1421 anActor->GetEdgeColor( color[0], color[1], color[2] );
1422 edgeColor.setRgbF( color[0], color[1], color[2] );
1423 edgeWidth = qMax( (int)anActor->GetLineWidth(), 1 ); // minimum allowed width is 1
1424 // faces: front color, back color (delta)
1425 anActor->GetSufaceColor( color[0], color[1], color[2], deltaF );
1426 faceColor.setRgbF( color[0], color[1], color[2] );
1427 // faces: front color, back color (delta)
1428 anActor->GetVolumeColor( color[0], color[1], color[2], deltaV );
1429 volumeColor.setRgbF( color[0], color[1], color[2] );
1430 // 0d elements: color, size
1431 anActor->Get0DColor( color[0], color[1], color[2] );
1432 elem0dColor.setRgbF( color[0], color[1], color[2] );
1433 elem0dSize = qMax( (int)anActor->Get0DSize(), 1 ); // minimum allowed size is 1
1434 // balls: color, size
1435 anActor->GetBallColor( color[0], color[1], color[2] );
1436 ballColor.setRgbF( color[0], color[1], color[2] );
1437 //ballSize = qMax( (int)anActor->GetBallSize(), 1 ); // minimum allowed size is 1
1438 ballScale = qMax( (double)anActor->GetBallScale(), 1e-2 ); // minimum allowed scale is 1e-2
1440 anActor->GetOutlineColor( color[0], color[1], color[2] );
1441 outlineColor.setRgbF( color[0], color[1], color[2] );
1442 outlineWidth = qMax( (int)anActor->GetOutlineWidth(), 1 ); // minimum allowed width is 1
1443 // orientation vectors: color, scale, 3d flag
1444 anActor->GetFacesOrientationColor( color[0], color[1], color[2] );
1445 orientationColor.setRgbF( color[0], color[1], color[2] );
1446 orientationScale = anActor->GetFacesOrientationScale();
1447 orientation3d = anActor->GetFacesOrientation3DVectors();
1449 shrinkCoef = anActor->GetShrinkFactor();
1452 firstTime = false; // we only take properties from first object (for performance reasons)
1455 hasNodes = anActor->GetObject()->GetNbEntities( SMDSAbs_Node );
1456 if ( !(presentEntities & SMESH_Actor::eEdges) && anActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) )
1457 presentEntities = presentEntities | SMESH_Actor::eEdges;
1458 if ( !(presentEntities & SMESH_Actor::eFaces) && anActor->GetObject()->GetNbEntities( SMDSAbs_Face ) )
1459 presentEntities = presentEntities | SMESH_Actor::eFaces;
1460 if ( !(presentEntities & SMESH_Actor::eVolumes) && anActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) )
1461 presentEntities = presentEntities | SMESH_Actor::eVolumes;
1462 if ( !(presentEntities & SMESH_Actor::e0DElements) && anActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) )
1463 presentEntities = presentEntities | SMESH_Actor::e0DElements;
1464 if ( !(presentEntities & SMESH_Actor::eBallElem) && anActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) )
1465 presentEntities = presentEntities | SMESH_Actor::eBallElem;
1467 // as we know that all types of elements are present, we can exit the loop
1468 if ( presentEntities == SMESH_Actor::eAllEntity )
1472 SMESHGUI_PropertiesDlg dlg( theMarkerMap[ aStudy->StudyId() ], SMESHGUI::desktop() );
1473 // nodes: color, marker
1474 dlg.setNodeColor( nodeColor );
1475 if( markerType != VTK::MT_USER )
1476 dlg.setNodeMarker( markerType, markerScale );
1478 dlg.setNodeCustomMarker( markerId );
1479 // edges: color, line width
1480 dlg.setEdgeColor( edgeColor );
1481 dlg.setEdgeWidth( edgeWidth );
1482 // faces: front color, back color
1483 dlg.setFaceColor( faceColor, deltaF );
1484 // volumes: normal color, reversed color
1485 dlg.setVolumeColor( volumeColor, deltaV );
1486 // outlines: color, line width
1487 dlg.setOutlineColor( outlineColor );
1488 dlg.setOutlineWidth( outlineWidth );
1489 // 0d elements: color, size
1490 dlg.setElem0dColor( elem0dColor );
1491 dlg.setElem0dSize( elem0dSize );
1492 // balls: color, size
1493 dlg.setBallColor( ballColor );
1494 //dlg.setBallSize( ballSize );
1495 dlg.setBallScale( ballScale );
1496 // orientation: color, scale, 3d flag
1497 dlg.setOrientationColor( orientationColor );
1498 dlg.setOrientationSize( int( orientationScale * 100. ) );
1499 dlg.setOrientation3d( orientation3d );
1500 // shrink: scale factor
1501 dlg.setShrinkCoef( int( shrinkCoef * 100. ) );
1502 // hide unused controls
1503 dlg.showControls( presentEntities, hasNodes );
1506 nodeColor = dlg.nodeColor();
1507 markerType = dlg.nodeMarkerType();
1508 markerScale = dlg.nodeMarkerScale();
1509 markerId = dlg.nodeMarkerId();
1510 edgeColor = dlg.edgeColor();
1511 edgeWidth = dlg.edgeWidth();
1512 faceColor = dlg.faceColor();
1513 deltaF = dlg.faceColorDelta();
1514 volumeColor = dlg.volumeColor();
1515 deltaV = dlg.volumeColorDelta();
1516 outlineColor = dlg.outlineColor();
1517 outlineWidth = dlg.outlineWidth();
1518 elem0dColor = dlg.elem0dColor();
1519 elem0dSize = dlg.elem0dSize();
1520 ballColor = dlg.ballColor();
1521 // ballSize = dlg.ballSize();
1522 ballScale = dlg.ballScale();
1523 orientationColor = dlg.orientationColor();
1524 orientationScale = dlg.orientationSize() / 100.;
1525 orientation3d = dlg.orientation3d();
1526 shrinkCoef = dlg.shrinkCoef() / 100.;
1528 // store point markers map that might be changed by the user
1529 theMarkerMap[ aStudy->StudyId() ] = dlg.customMarkers();
1531 // set properties from dialog box to the presentations
1532 SALOME_ListIteratorOfListIO It( selected );
1533 for ( ; It.More(); It.Next() ) {
1534 Handle(SALOME_InteractiveObject) IObject = It.Value();
1535 if ( !IObject->hasEntry() ) continue;
1536 SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1537 if ( !anActor ) continue;
1539 // nodes: color, marker
1540 anActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
1541 if ( markerType != VTK::MT_USER ) {
1542 anActor->SetMarkerStd( markerType, markerScale );
1545 const VTK::MarkerMap& markerMap = theMarkerMap[ aStudy->StudyId() ];
1546 VTK::MarkerMap::const_iterator iter = markerMap.find( markerId );
1547 if ( iter != markerMap.end() )
1548 anActor->SetMarkerTexture( markerId, iter->second.second );
1550 // volumes: normal color, reversed color (delta)
1551 anActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
1552 // faces: front color, back color (delta)
1553 anActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
1554 // edges: color, width
1555 anActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
1556 anActor->SetLineWidth( edgeWidth );
1558 anActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
1559 anActor->SetOutlineWidth( outlineWidth );
1560 // 0D elements: color, size
1561 anActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
1562 anActor->Set0DSize( elem0dSize );
1563 // balls: color, size
1564 anActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
1565 // anActor->SetBallSize( ballSize );
1566 anActor->SetBallScale( ballScale );
1567 // orientation: color, scale, 3d flag
1568 anActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
1569 anActor->SetFacesOrientationScale( orientationScale );
1570 anActor->SetFacesOrientation3DVectors( orientation3d );
1572 anActor->SetShrinkFactor( shrinkCoef );
1574 // for groups, set also proper color
1575 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1576 if ( !aGroupObject->_is_nil() ) {
1577 SMESH::ElementType anElementType = aGroupObject->GetType();
1579 switch( anElementType ) {
1581 aColor = nodeColor; break;
1583 aColor = edgeColor; break;
1585 aColor = faceColor; break;
1587 aColor = volumeColor; break;
1589 aColor = elem0dColor; break;
1591 aColor = ballColor; break;
1595 if ( aColor.isValid() ) {
1596 SALOMEDS::Color aGroupColor;
1597 aGroupColor.R = aColor.redF();
1598 aGroupColor.G = aColor.greenF();
1599 aGroupColor.B = aColor.blueF();
1600 aGroupObject->SetColor( aGroupColor );
1602 } // if ( !aGroupObject->_is_nil() )
1603 } // for ( ; It.More(); It.Next() )
1604 SMESH::RepaintCurrentView();
1605 } // if ( dlg.exec() )
1607 } // case SMESHOp::OpProperties:
1608 } // switch(theCommandID)
1609 SUIT_OverrideCursor wc;
1610 SALOME_ListIteratorOfListIO It( selected );
1611 for( ; It.More(); It.Next()){
1612 Handle(SALOME_InteractiveObject) IObject = It.Value();
1613 if(IObject->hasEntry()){
1614 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1615 switch(theCommandID){
1616 case SMESHOp::OpDMWireframe:
1617 anActor->SetRepresentation(SMESH_Actor::eEdge);
1619 case SMESHOp::OpDMShading:
1620 anActor->SetRepresentation(SMESH_Actor::eSurface);
1622 case SMESHOp::OpDMShrink:
1623 if(anActor->IsShrunk())
1624 anActor->UnShrink();
1626 anActor->SetShrink();
1628 case SMESHOp::OpDMNodes:
1629 anActor->SetRepresentation(SMESH_Actor::ePoint);
1631 case SMESHOp::OpRepresentationLines:
1632 if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1633 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1635 case SMESHOp::OpRepresentationArcs:
1636 if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1637 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1643 SMESH::RepaintCurrentView();
1647 int ActionToControl( int theID, bool theReversed )
1649 NCollection_DoubleMap<int,int> ActionControl;
1650 ActionControl.Bind( 0, SMESH_Actor::eNone );
1651 ActionControl.Bind( SMESHOp::OpFreeNode, SMESH_Actor::eFreeNodes );
1652 ActionControl.Bind( SMESHOp::OpEqualNode, SMESH_Actor::eCoincidentNodes );
1653 ActionControl.Bind( SMESHOp::OpNodeConnectivityNb, SMESH_Actor::eNodeConnectivityNb );
1654 ActionControl.Bind( SMESHOp::OpFreeEdge, SMESH_Actor::eFreeEdges );
1655 ActionControl.Bind( SMESHOp::OpFreeBorder, SMESH_Actor::eFreeBorders );
1656 ActionControl.Bind( SMESHOp::OpLength, SMESH_Actor::eLength );
1657 ActionControl.Bind( SMESHOp::OpConnection, SMESH_Actor::eMultiConnection );
1658 ActionControl.Bind( SMESHOp::OpEqualEdge, SMESH_Actor::eCoincidentElems1D );
1659 ActionControl.Bind( SMESHOp::OpFreeFace, SMESH_Actor::eFreeFaces );
1660 ActionControl.Bind( SMESHOp::OpBareBorderFace, SMESH_Actor::eBareBorderFace );
1661 ActionControl.Bind( SMESHOp::OpOverConstrainedFace, SMESH_Actor::eOverConstrainedFace );
1662 ActionControl.Bind( SMESHOp::OpLength2D, SMESH_Actor::eLength2D );
1663 ActionControl.Bind( SMESHOp::OpConnection2D, SMESH_Actor::eMultiConnection2D );
1664 ActionControl.Bind( SMESHOp::OpArea, SMESH_Actor::eArea );
1665 ActionControl.Bind( SMESHOp::OpTaper, SMESH_Actor::eTaper );
1666 ActionControl.Bind( SMESHOp::OpAspectRatio, SMESH_Actor::eAspectRatio );
1667 ActionControl.Bind( SMESHOp::OpMinimumAngle, SMESH_Actor::eMinimumAngle );
1668 ActionControl.Bind( SMESHOp::OpWarpingAngle, SMESH_Actor::eWarping );
1669 ActionControl.Bind( SMESHOp::OpSkew, SMESH_Actor::eSkew );
1670 ActionControl.Bind( SMESHOp::OpMaxElementLength2D, SMESH_Actor::eMaxElementLength2D );
1671 ActionControl.Bind( SMESHOp::OpEqualFace, SMESH_Actor::eCoincidentElems2D );
1672 ActionControl.Bind( SMESHOp::OpAspectRatio3D, SMESH_Actor::eAspectRatio3D );
1673 ActionControl.Bind( SMESHOp::OpVolume, SMESH_Actor::eVolume3D );
1674 ActionControl.Bind( SMESHOp::OpMaxElementLength3D, SMESH_Actor::eMaxElementLength3D );
1675 ActionControl.Bind( SMESHOp::OpBareBorderVolume, SMESH_Actor::eBareBorderVolume );
1676 ActionControl.Bind( SMESHOp::OpOverConstrainedVolume, SMESH_Actor::eOverConstrainedVolume );
1677 ActionControl.Bind( SMESHOp::OpEqualVolume, SMESH_Actor::eCoincidentElems3D );
1679 return theReversed ? ActionControl.Find2( theID ) : ActionControl.Find1( theID );
1682 void Control( int theCommandID )
1684 SMESH_Actor::eControl aControl = SMESH_Actor::eControl( ActionToControl( theCommandID ));
1685 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1687 SALOME_ListIO selected;
1688 if ( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
1689 aSel->selectedObjects( selected );
1691 if ( !selected.IsEmpty() ) {
1692 SALOME_ListIteratorOfListIO It(selected);
1693 for ( ; It.More(); It.Next())
1695 Handle(SALOME_InteractiveObject) anIO = It.Value();
1696 if ( !anIO.IsNull() ) {
1697 _PTR(SObject) SO = aStudy->FindObjectID( It.Value()->getEntry() );
1699 CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
1700 SMESH::SMESH_IDSource_var anIDSrc = SMESH::SMESH_IDSource::_narrow( aObject );
1701 if ( !anIDSrc->_is_nil() ) {
1702 SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry());
1703 if (( !anActor && selected.Extent() == 1 ) &&
1704 ( anActor = SMESH::CreateActor( aStudy, anIO->getEntry() )))
1706 anActor->SetControlMode( aControl );
1707 SMESH::DisplayActor( SMESH::GetCurrentVtkView(), anActor );
1708 SMESH::UpdateView ( SMESH::eDisplay, anIO->getEntry() );
1712 if ( anActor->GetControlMode() != aControl )
1713 anActor->SetControlMode( aControl );
1714 QString functorName = functorToString( anActor->GetFunctor() );
1715 int anEntitiesCount = anActor->GetNumberControlEntities();
1716 if (anEntitiesCount >= 0)
1717 functorName = functorName + ": " + QString::number(anEntitiesCount);
1718 anActor->GetScalarBarActor()->SetTitle( functorName.toLatin1().constData() );
1719 SMESH::RepaintCurrentView();
1720 #ifndef DISABLE_PLOT2DVIEWER
1721 if ( anActor->GetPlot2Histogram() ) {
1722 SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1723 QString aHistogramName("%1 : %2");
1724 aHistogramName = aHistogramName.arg( anIO->getName() ).arg( functorName );
1725 aHistogram->setName( aHistogramName );
1726 aHistogram->setHorTitle( functorName );
1727 SMESH::ProcessIn2DViewers( anActor );
1739 bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1740 SMESH::MeshObjectType theType,
1741 const QString theInTypeName,
1742 QString & theOutTypeName)
1744 SMESH_TypeFilter aTypeFilter( theType );
1746 if ( !theIO.IsNull() )
1748 entry = theIO->getEntry();
1749 LightApp_DataOwner owner( entry );
1750 if ( aTypeFilter.isOk( &owner )) {
1751 theOutTypeName = theInTypeName;
1759 QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1761 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1762 _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1764 _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1765 CORBA::String_var anID = aSComp->GetID().c_str();
1766 if ( !strcmp(anID.in(),theIO->getEntry()) )
1772 CheckOIType ( theIO, SMESH::HYPOTHESIS, "Hypothesis", aTypeName ) ||
1773 CheckOIType ( theIO, SMESH::ALGORITHM, "Algorithm", aTypeName ) ||
1774 CheckOIType ( theIO, SMESH::MESH, "Mesh", aTypeName ) ||
1775 CheckOIType ( theIO, SMESH::SUBMESH, "SubMesh", aTypeName ) ||
1776 CheckOIType ( theIO, SMESH::GROUP, "Group", aTypeName )
1784 // QString CheckHomogeneousSelection()
1786 // LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1787 // SALOME_ListIO selected;
1789 // aSel->selectedObjects( selected );
1791 // QString RefType = CheckTypeObject(selected.First());
1792 // SALOME_ListIteratorOfListIO It(selected);
1793 // for ( ; It.More(); It.Next())
1795 // Handle(SALOME_InteractiveObject) IObject = It.Value();
1796 // QString Type = CheckTypeObject(IObject);
1797 // if ( Type.compare(RefType) != 0 )
1798 // return "Heterogeneous Selection";
1804 uint randomize( uint size )
1806 static bool initialized = false;
1807 if ( !initialized ) {
1808 qsrand( QDateTime::currentDateTime().toTime_t() );
1812 v = uint( (double)( v ) / RAND_MAX * size );
1813 v = qMax( uint(0), qMin ( v, size-1 ) );
1819 void SMESHGUI::OnEditDelete()
1821 // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1822 LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1823 SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1825 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1826 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1827 _PTR(GenericAttribute) anAttr;
1828 _PTR(AttributeIOR) anIOR;
1830 int objectCount = 0;
1832 QString aParentComponent = QString::null;
1833 Handle(SALOME_InteractiveObject) anIO;
1834 for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1836 anIO = anIt.Value();
1837 QString cur = anIO->getComponentDataType();
1838 _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
1840 // check if object is reference
1841 _PTR(SObject) aRefSObj;
1842 aNameList.append("\n - ");
1843 if ( aSO->ReferencedObject( aRefSObj ) ) {
1844 QString aRefName = QString::fromStdString ( aRefSObj->GetName() );
1845 aNameList.append( aRefName );
1846 cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1849 aNameList.append(anIO->getName());
1853 if( aParentComponent.isNull() )
1854 aParentComponent = cur;
1855 else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
1856 aParentComponent = "";
1859 if ( objectCount == 0 )
1860 return; // No Valid Objects Selected
1862 if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() ) {
1863 SUIT_MessageBox::warning( SMESHGUI::desktop(),
1864 QObject::tr("ERR_ERROR"),
1865 QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1868 // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1869 if (SUIT_MessageBox::warning
1870 (SMESHGUI::desktop(),
1871 QObject::tr("SMESH_WRN_WARNING"),
1872 QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1873 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1874 SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1877 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1879 // Put the whole hierarchy of sub-objects of the selected SO's into a list and
1880 // then treat them all starting from the deepest objects (at list back)
1881 std::list< _PTR(SObject) > listSO;
1882 SALOME_ListIteratorOfListIO It(selected);
1883 for( ; It.More(); It.Next()) // loop on selected IO's
1885 Handle(SALOME_InteractiveObject) IObject = It.Value();
1886 if(IObject->hasEntry()) {
1887 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1889 // disable removal of "SMESH" component object
1890 if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1892 if ( engineIOR() == anIOR->Value().c_str() )
1895 //Check the referenced object
1896 _PTR(SObject) aRefSObject;
1897 if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1898 aSO = aRefSObject; // Delete main Object instead of reference
1900 listSO.push_back( aSO );
1901 std::list< _PTR(SObject) >::iterator itSO = --listSO.end();
1902 for ( ; itSO != listSO.end(); ++itSO ) {
1903 _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1904 for (it->InitEx(false); it->More(); it->Next())
1905 listSO.push_back( it->Value() );
1909 // Check if none of objects to delete is referred from outside
1910 std::list< _PTR(SObject) >::reverse_iterator ritSO;
1911 for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1913 _PTR(SObject) SO = *ritSO;
1914 if ( !SO ) continue;
1915 std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( *ritSO );
1916 for (size_t i = 0; i < aReferences.size(); i++) {
1917 _PTR(SComponent) aComponent = aReferences[i]->GetFatherComponent();
1918 std::string type = aComponent->ComponentDataType();
1919 if ( type != "SMESH" )
1921 SUIT_MessageBox::warning( anApp->desktop(),
1922 QObject::tr("WRN_WARNING"),
1923 QObject::tr("DEP_OBJECT") );
1924 return; // outside SMESH, there is an object depending on a SMESH object
1929 // Call mesh->Clear() to prevent loading mesh from file caused by hypotheses removal
1930 for( It.Initialize( selected ); It.More(); It.Next()) // loop on selected IO's
1932 Handle(SALOME_InteractiveObject) IObject = It.Value();
1933 SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface< SMESH::SMESH_Mesh >( IObject );
1934 if ( !mesh->_is_nil() )
1938 // Treat SO's in the list starting from the back
1939 aStudyBuilder->NewCommand(); // There is a transaction
1940 for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1942 _PTR(SObject) SO = *ritSO;
1943 if ( !SO ) continue;
1944 std::string anEntry = SO->GetID();
1946 /** Erase graphical object and remove all its data **/
1947 if(SO->FindAttribute(anAttr, "AttributeIOR")) {
1948 SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true);
1950 /** Remove an object from data structures **/
1951 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1952 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1953 if ( !aGroup->_is_nil() ) { // DELETE GROUP
1954 SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1955 aMesh->RemoveGroup( aGroup );
1957 else if ( !aSubMesh->_is_nil() ) { // DELETE SUBMESH
1958 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1959 aMesh->RemoveSubMesh( aSubMesh );
1961 _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1963 SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1966 Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject
1967 ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1968 QString objType = CheckTypeObject(IObject);
1969 if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1970 SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1971 aStudyBuilder->RemoveObjectWithChildren( SO );
1973 else {// default action: remove SObject from the study
1974 // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1975 //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1977 aStudyBuilder->RemoveObjectWithChildren( SO );
1981 } /* listSO back loop */
1983 aStudyBuilder->CommitCommand();
1985 /* Clear any previous selection */
1987 aSel->setSelectedObjects( l1 );
1989 SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1993 SMESHGUI_EXPORT CAM_Module* createModule()
1995 return new SMESHGUI();
1998 SMESHGUI_EXPORT char* getModuleVersion() {
1999 return (char*)SMESH_VERSION_STR;
2003 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
2005 //=============================================================================
2009 //=============================================================================
2010 SMESHGUI::SMESHGUI() :
2011 SalomeApp_Module( "SMESH" )
2013 if ( CORBA::is_nil( myComponentSMESH ) )
2015 CORBA::Boolean anIsEmbeddedMode;
2016 myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
2017 //MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
2019 // 0019923: EDF 765 SMESH : default values of hypothesis
2020 SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
2021 int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
2022 myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
2023 nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
2024 myComponentSMESH->SetDefaultNbSegments( nbSeg );
2026 const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif", "default_grp_color" };
2027 for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
2028 if ( aResourceMgr->hasValue( "SMESH", options[i] ))
2030 QString val = aResourceMgr->stringValue( "SMESH", options[i] );
2031 myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
2035 myActiveDialogBox = 0;
2036 myFilterLibraryDlg = 0;
2040 myEventCallbackCommand = vtkCallbackCommand::New();
2041 myEventCallbackCommand->Delete();
2042 myEventCallbackCommand->SetClientData( this );
2043 myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
2046 /* load resources for all available meshers */
2047 SMESH::InitAvailableHypotheses();
2050 //=============================================================================
2054 //=============================================================================
2055 SMESHGUI::~SMESHGUI()
2059 //=============================================================================
2063 //=============================================================================
2064 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
2066 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2068 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2073 //=============================================================================
2077 //=============================================================================
2078 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
2080 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2084 bool autoUpdate = resMgr->booleanValue( "SMESH", "auto_update", false );
2085 long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2086 bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2087 if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2088 return autoUpdate && !exceeded;
2091 //=============================================================================
2095 //=============================================================================
2096 bool SMESHGUI::automaticUpdate( SMESH::SMESH_IDSource_ptr theMesh,
2097 int* entities, bool* limitExceeded, int* hidden, long* nbElements )
2099 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2103 bool autoUpdate = resMgr->booleanValue( "SMESH", "auto_update", false );
2104 long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2105 bool incrementalLimit = resMgr->booleanValue( "SMESH", "incremental_limit", false );
2107 SMESH::long_array_var info = theMesh->GetMeshInfo();
2108 long nbOdElems = info[SMDSEntity_0D];
2109 long nbEdges = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
2110 long nbFaces = info[SMDSEntity_Triangle] + info[SMDSEntity_Quad_Triangle] + info[SMDSEntity_BiQuad_Triangle] +
2111 info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle] + info[SMDSEntity_BiQuad_Quadrangle] +
2112 info[SMDSEntity_Polygon] + info[SMDSEntity_Quad_Polygon];
2113 long nbVolumes = info[SMDSEntity_Tetra] + info[SMDSEntity_Quad_Tetra] +
2114 info[SMDSEntity_Hexa] + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_TriQuad_Hexa] +
2115 info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid] +
2116 info[SMDSEntity_Penta] + info[SMDSEntity_Quad_Penta] +
2117 info[SMDSEntity_Polyhedra] +
2118 info[SMDSEntity_Hexagonal_Prism];
2119 long nbBalls = info[SMDSEntity_Ball];
2121 long requestedSize = nbOdElems + nbBalls + nbEdges + nbFaces + nbVolumes;
2122 *nbElements = requestedSize;
2124 *entities = SMESH_Actor::eAllEntity;
2127 bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2129 if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2131 if ( incrementalLimit ) {
2134 if ( nbOdElems > 0 ) {
2135 if ( total + nbOdElems > updateLimit ) {
2136 *entities = *entities & ~SMESH_Actor::e0DElements;
2137 *hidden = *hidden | SMESH_Actor::e0DElements;
2144 if ( nbEdges > 0 ) {
2145 if ( total + nbEdges > updateLimit ) {
2146 *entities = *entities & ~SMESH_Actor::eEdges;
2147 *hidden = *hidden | SMESH_Actor::eEdges;
2154 if ( nbFaces > 0 ) {
2155 if ( total + nbFaces > updateLimit ) {
2156 *entities = *entities & ~SMESH_Actor::eFaces;
2157 *hidden = *hidden | SMESH_Actor::eFaces;
2164 if ( nbVolumes > 0 ) {
2165 if ( total + nbVolumes > updateLimit ) {
2166 *entities = *entities & ~SMESH_Actor::eVolumes;
2167 *hidden = *hidden | SMESH_Actor::eVolumes;
2174 if ( nbBalls > 0 ) {
2175 if ( total + nbBalls > updateLimit ) {
2176 *entities = *entities & ~SMESH_Actor::eBallElem;
2177 *hidden = *hidden | SMESH_Actor::eBallElem;
2185 return autoUpdate && !exceeded;
2188 //=============================================================================
2192 //=============================================================================
2193 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
2195 return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
2198 //=============================================================================
2202 //=============================================================================
2203 SMESHGUI* SMESHGUI::GetSMESHGUI()
2205 SMESHGUI* smeshMod = 0;
2206 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
2209 CAM_Module* module = app->module( "Mesh" );
2210 smeshMod = dynamic_cast<SMESHGUI*>( module );
2213 if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
2215 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
2218 _PTR(Study) aStudy = study->studyDS();
2220 GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
2229 Standard_EXPORT SMESHGUI* GetComponentGUI()
2231 return SMESHGUI::GetSMESHGUI();
2235 //=============================================================================
2239 //=============================================================================
2240 void SMESHGUI::SetState(int aState)
2245 //=============================================================================
2249 //=============================================================================
2250 void SMESHGUI::ResetState()
2255 //=============================================================================
2259 //=============================================================================
2260 void SMESHGUI::EmitSignalDeactivateDialog()
2262 emit SignalDeactivateActiveDialog();
2265 //=============================================================================
2269 //=============================================================================
2270 void SMESHGUI::EmitSignalStudyFrameChanged()
2272 emit SignalStudyFrameChanged();
2275 //=============================================================================
2279 //=============================================================================
2280 void SMESHGUI::EmitSignalCloseAllDialogs()
2282 emit SignalCloseAllDialogs();
2285 //=============================================================================
2289 //=============================================================================
2290 void SMESHGUI::EmitSignalVisibilityChanged()
2292 emit SignalVisibilityChanged();
2295 //=============================================================================
2299 //=============================================================================
2300 void SMESHGUI::EmitSignalCloseView()
2302 emit SignalCloseView();
2305 //=============================================================================
2309 //=============================================================================
2310 void SMESHGUI::EmitSignalActivatedViewManager()
2312 emit SignalActivatedViewManager();
2315 //=============================================================================
2319 //=============================================================================
2320 QDialog *SMESHGUI::GetActiveDialogBox()
2322 return myActiveDialogBox;
2325 //=============================================================================
2329 //=============================================================================
2330 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2332 myActiveDialogBox = (QDialog *) aDlg;
2336 //=============================================================================
2340 //=============================================================================
2341 SUIT_Desktop* SMESHGUI::desktop()
2343 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2345 return app->desktop();
2350 //=============================================================================
2354 //=============================================================================
2355 SalomeApp_Study* SMESHGUI::activeStudy()
2357 SUIT_Application* app = SUIT_Session::session()->activeApplication();
2359 return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2364 //=============================================================================
2368 //=============================================================================
2369 void SMESHGUI::Modified( bool theIsUpdateActions )
2371 if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2372 if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2373 appStudy->Modified();
2374 if( theIsUpdateActions )
2375 app->updateActions();
2380 //=============================================================================
2384 //=============================================================================
2385 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2387 /* Here the position is on the bottom right corner - 10 */
2388 // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2390 SUIT_Desktop *PP = desktop();
2391 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2392 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2396 //=============================================================================
2400 //=============================================================================
2401 static int isStudyLocked(_PTR(Study) theStudy){
2402 return theStudy->GetProperties()->IsLocked();
2405 static bool checkLock(_PTR(Study) theStudy) {
2406 if (isStudyLocked(theStudy)) {
2407 SUIT_MessageBox::warning( SMESHGUI::desktop(),
2408 QObject::tr("WRN_WARNING"),
2409 QObject::tr("WRN_STUDY_LOCKED") );
2415 //=======================================================================
2416 //function : CheckActiveStudyLocked
2418 //=======================================================================
2420 bool SMESHGUI::isActiveStudyLocked()
2422 _PTR(Study) aStudy = activeStudy()->studyDS();
2423 return checkLock( aStudy );
2426 //=============================================================================
2430 //=============================================================================
2431 bool SMESHGUI::OnGUIEvent( int theCommandID )
2433 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2437 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2438 SUIT_ResourceMgr* mgr = resourceMgr();
2442 if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
2443 GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2446 SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2447 SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2449 //QAction* act = action( theCommandID );
2451 switch (theCommandID) {
2452 case SMESHOp::OpDelete:
2453 if(checkLock(aStudy)) break;
2456 case SMESHOp::OpImportDAT:
2457 case SMESHOp::OpImportUNV:
2458 case SMESHOp::OpImportMED:
2459 case SMESHOp::OpImportSTL:
2460 case SMESHOp::OpImportCGNS:
2461 case SMESHOp::OpImportSAUV:
2462 case SMESHOp::OpImportGMF:
2463 case SMESHOp::OpPopupImportDAT:
2464 case SMESHOp::OpPopupImportUNV:
2465 case SMESHOp::OpPopupImportMED:
2466 case SMESHOp::OpPopupImportSTL:
2467 case SMESHOp::OpPopupImportCGNS:
2468 case SMESHOp::OpPopupImportSAUV:
2469 case SMESHOp::OpPopupImportGMF:
2471 if(checkLock(aStudy)) break;
2472 ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2476 case SMESHOp::OpFileInformation:
2478 SALOME_ListIO selected;
2479 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2481 aSel->selectedObjects( selected );
2482 if( selected.Extent() )
2484 Handle(SALOME_InteractiveObject) anIObject = selected.First();
2485 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2486 if ( !aMesh->_is_nil() )
2488 SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2494 case SMESHOp::OpExportDAT:
2495 case SMESHOp::OpExportMED:
2496 case SMESHOp::OpExportUNV:
2497 case SMESHOp::OpExportSTL:
2498 case SMESHOp::OpExportCGNS:
2499 case SMESHOp::OpExportSAUV:
2500 case SMESHOp::OpExportGMF:
2501 case SMESHOp::OpPopupExportDAT:
2502 case SMESHOp::OpPopupExportMED:
2503 case SMESHOp::OpPopupExportUNV:
2504 case SMESHOp::OpPopupExportSTL:
2505 case SMESHOp::OpPopupExportCGNS:
2506 case SMESHOp::OpPopupExportSAUV:
2507 case SMESHOp::OpPopupExportGMF:
2509 ::ExportMeshToFile(theCommandID);
2513 case SMESHOp::OpReset: // SCALAR BAR
2515 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2516 SALOME_ListIO selected;
2518 aSel->selectedObjects( selected );
2520 SALOME_ListIteratorOfListIO it(selected);
2521 for( ; it.More(); it.Next()) {
2522 Handle(SALOME_InteractiveObject) anIO = it.Value();
2523 if( anIO->hasEntry() ) {
2524 if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2525 anActor->SetControlMode( SMESH_Actor::eNone );
2526 #ifndef DISABLE_PLOT2DVIEWER
2527 SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2532 SMESH::UpdateView();
2535 case SMESHOp::OpScalarBarProperties:
2537 SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2540 case SMESHOp::OpShowScalarBar:
2542 // show/hide scalar bar
2543 ::ShowElement(theCommandID);
2546 case SMESHOp::OpSaveDistribution:
2548 // dump control distribution data to the text file
2549 ::SaveDistribution();
2553 case SMESHOp::OpShowDistribution:
2555 // show/hide distribution
2556 ::ShowElement(theCommandID);
2560 #ifndef DISABLE_PLOT2DVIEWER
2561 case SMESHOp::OpPlotDistribution:
2563 // plot distribution
2564 ::PlotDistribution();
2570 case SMESHOp::OpAutoColor:
2574 case SMESHOp::OpDisableAutoColor:
2575 ::DisableAutoColor();
2578 case SMESHOp::OpClipping:
2579 case SMESHOp::OpTransparency:
2580 case SMESHOp::OpProperties: // Display preferences (colors, shrink size, line width, ...)
2583 case SMESHOp::OpDMWireframe:
2584 case SMESHOp::OpDMShading:
2585 case SMESHOp::OpDMNodes:
2586 case SMESHOp::OpDMShrink:
2587 ::SetDisplayMode(theCommandID, myMarkerMap);
2590 //2D quadratic representation
2591 case SMESHOp::OpRepresentationLines:
2592 case SMESHOp::OpRepresentationArcs:
2593 ::SetDisplayMode(theCommandID, myMarkerMap);
2597 case SMESHOp::OpDE0DElements:
2598 case SMESHOp::OpDEEdges:
2599 case SMESHOp::OpDEFaces:
2600 case SMESHOp::OpDEVolumes:
2601 case SMESHOp::OpDEBalls:
2602 case SMESHOp::OpDEAllEntity:
2603 ::SetDisplayEntity(theCommandID);
2606 // Choose entities to be displayed
2607 case SMESHOp::OpDEChoose:
2609 ( new SMESHGUI_DisplayEntitiesDlg( SMESHGUI::desktop() ) )->exec();
2613 case SMESHOp::OpOrientationOnFaces:
2615 SUIT_OverrideCursor wc;
2616 LightApp_SelectionMgr* mgr = selectionMgr();
2617 SALOME_ListIO selected; mgr->selectedObjects( selected );
2619 SALOME_ListIteratorOfListIO it(selected);
2620 for( ; it.More(); it.Next()) {
2621 Handle(SALOME_InteractiveObject) anIObject = it.Value();
2622 if(anIObject->hasEntry()) {
2623 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2624 anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2631 case SMESHOp::OpUpdate:
2633 if(checkLock(aStudy)) break;
2634 SUIT_OverrideCursor wc;
2636 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2639 SMESH::UpdateView();
2641 catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2642 SMESH::OnVisuException();
2644 catch (...) { // PAL16774 (Crash after display of many groups)
2645 SMESH::OnVisuException();
2649 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2650 aSel->selectedObjects( l );
2651 aSel->setSelectedObjects( l );
2655 case SMESHOp::OpHide:
2656 case SMESHOp::OpShow:
2657 case SMESHOp::OpShowOnly:
2659 SUIT_OverrideCursor wc;
2660 SMESH::EDisplaing anAction;
2661 switch (theCommandID) {
2662 case SMESHOp::OpHide: anAction = SMESH::eErase; break;
2663 case SMESHOp::OpShow: anAction = SMESH::eDisplay; break;
2664 case SMESHOp::OpShowOnly: anAction = SMESH::eDisplayOnly; break;
2667 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2668 SALOME_ListIO sel_objects, to_process;
2670 aSel->selectedObjects( sel_objects );
2672 if ( theCommandID==SMESHOp::OpShowOnly )
2674 //MESSAGE("anAction = SMESH::eDisplayOnly");
2675 startOperation( myEraseAll );
2678 extractContainers( sel_objects, to_process );
2683 SALOME_ListIteratorOfListIO It( to_process );
2684 for ( ; It.More(); It.Next())
2686 Handle(SALOME_InteractiveObject) IOS = It.Value();
2687 if ( IOS->hasEntry() )
2689 if ( !SMESH::UpdateView( anAction, IOS->getEntry() )) {
2690 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2691 break; // PAL16774 (Crash after display of many groups)
2693 if (anAction == SMESH::eDisplayOnly)
2694 anAction = SMESH::eDisplay;
2699 // PAL13338 + PAL15161 -->
2700 if ( ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) && !checkLock(aStudy)) {
2701 SMESH::UpdateView();
2702 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2704 // PAL13338 + PAL15161 <--
2706 catch (...) { // PAL16774 (Crash after display of many groups)
2707 SMESH::OnVisuException();
2710 if (anAction == SMESH::eErase) {
2712 aSel->setSelectedObjects( l1 );
2715 aSel->setSelectedObjects( to_process );
2720 case SMESHOp::OpNode:
2722 if(checkLock(aStudy)) break;
2725 EmitSignalDeactivateDialog();
2727 ( new SMESHGUI_NodesDlg( this ) )->show();
2730 SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"),tr("SMESH_WRN_VIEWER_VTK"));
2735 case SMESHOp::OpCreateMesh:
2736 case SMESHOp::OpCreateSubMesh:
2737 case SMESHOp::OpEditMeshOrSubMesh:
2738 case SMESHOp::OpEditMesh:
2739 case SMESHOp::OpEditSubMesh:
2740 case SMESHOp::OpCompute:
2741 case SMESHOp::OpComputeSubMesh:
2742 case SMESHOp::OpPreCompute:
2743 case SMESHOp::OpEvaluate:
2744 case SMESHOp::OpMeshOrder:
2745 startOperation( theCommandID );
2747 case SMESHOp::OpCopyMesh:
2749 if (checkLock(aStudy)) break;
2750 EmitSignalDeactivateDialog();
2751 ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2754 case SMESHOp::OpBuildCompoundMesh:
2756 if (checkLock(aStudy)) break;
2757 EmitSignalDeactivateDialog();
2758 ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2762 case SMESHOp::OpDiagonalInversion:
2763 case SMESHOp::OpUnionOfTwoTriangle:
2767 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "NOT_A_VTK_VIEWER" ) );
2771 if ( checkLock( aStudy ) )
2774 /*Standard_Boolean aRes;
2775 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2776 if ( aMesh->_is_nil() )
2778 SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2779 tr( "SMESH_BAD_SELECTION" ) );
2783 EmitSignalDeactivateDialog();
2784 if ( theCommandID == SMESHOp::OpDiagonalInversion )
2785 ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2787 ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2790 case SMESHOp::OpOrientation:
2791 case SMESHOp::OpUnionOfTriangles:
2792 case SMESHOp::OpCuttingOfQuadrangles:
2793 case SMESHOp::OpSplitVolumes:
2797 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "NOT_A_VTK_VIEWER" ) );
2801 if ( checkLock( aStudy ) )
2804 EmitSignalDeactivateDialog();
2805 SMESHGUI_MultiEditDlg* aDlg = NULL;
2806 if ( theCommandID == SMESHOp::OpOrientation )
2807 aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2808 else if ( theCommandID == SMESHOp::OpUnionOfTriangles )
2809 aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2810 else if ( theCommandID == SMESHOp::OpSplitVolumes )
2811 aDlg = new SMESHGUI_SplitVolumesDlg(this);
2813 aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2818 case SMESHOp::OpSmoothing:
2820 if(checkLock(aStudy)) break;
2822 EmitSignalDeactivateDialog();
2823 ( new SMESHGUI_SmoothingDlg( this ) )->show();
2826 SUIT_MessageBox::warning(desktop(), tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2830 case SMESHOp::OpExtrusion:
2832 if (checkLock(aStudy)) break;
2834 EmitSignalDeactivateDialog();
2835 ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2837 SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2841 case SMESHOp::OpExtrusionAlongAPath:
2843 if (checkLock(aStudy)) break;
2845 EmitSignalDeactivateDialog();
2846 ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2848 SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2852 case SMESHOp::OpRevolution:
2854 if(checkLock(aStudy)) break;
2856 EmitSignalDeactivateDialog();
2857 ( new SMESHGUI_RevolutionDlg( this ) )->show();
2860 SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2864 case SMESHOp::OpPatternMapping:
2866 if ( checkLock( aStudy ) )
2870 EmitSignalDeactivateDialog();
2871 ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2874 SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2878 case SMESHOp::OpSplitBiQuadratic:
2879 case SMESHOp::OpConvertMeshToQuadratic:
2880 case SMESHOp::OpCreateBoundaryElements: // create 2D mesh from 3D
2881 case SMESHOp::OpReorientFaces:
2882 case SMESHOp::OpCreateGeometryGroup:
2884 startOperation( theCommandID );
2887 case SMESHOp::OpCreateGroup:
2891 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
2895 if(checkLock(aStudy)) break;
2896 EmitSignalDeactivateDialog();
2897 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2899 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2900 SALOME_ListIO selected;
2902 aSel->selectedObjects( selected );
2904 int nbSel = selected.Extent();
2906 // check if mesh is selected
2907 aMesh = SMESH::GetMeshByIO( selected.First() );
2909 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2914 case SMESHOp::OpConstructGroup:
2918 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
2922 if(checkLock(aStudy)) break;
2923 EmitSignalDeactivateDialog();
2925 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2926 SALOME_ListIO selected;
2928 aSel->selectedObjects( selected );
2930 int nbSel = selected.Extent();
2932 // check if submesh is selected
2933 Handle(SALOME_InteractiveObject) IObject = selected.First();
2934 if (IObject->hasEntry()) {
2935 _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2937 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2938 if (!aSubMesh->_is_nil()) {
2940 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2941 // get submesh elements list by types
2942 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2943 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2944 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2945 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2946 // create group for each type o elements
2947 QString aName = IObject->getName();
2948 QStringList anEntryList;
2949 if (aNodes->length() > 0) {
2950 SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2951 aGroup->Add(aNodes.inout());
2952 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2953 anEntryList.append( aSObject->GetID().c_str() );
2955 if (aEdges->length() > 0) {
2956 SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2957 aGroup->Add(aEdges.inout());
2958 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2959 anEntryList.append( aSObject->GetID().c_str() );
2961 if (aFaces->length() > 0) {
2962 SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2963 aGroup->Add(aFaces.inout());
2964 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2965 anEntryList.append( aSObject->GetID().c_str() );
2967 if (aVolumes->length() > 0) {
2968 SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2969 aGroup->Add(aVolumes.inout());
2970 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2971 anEntryList.append( aSObject->GetID().c_str() );
2974 anApp->browseObjects( anEntryList );
2976 catch(const SALOME::SALOME_Exception & S_ex){
2977 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2984 SUIT_MessageBox::warning(desktop(),
2985 tr("SMESH_WRN_WARNING"),
2986 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2991 case SMESHOp::OpEditGroup:
2995 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
2999 if(checkLock(aStudy)) break;
3000 EmitSignalDeactivateDialog();
3002 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3003 SALOME_ListIO selected;
3005 aSel->selectedObjects( selected );
3007 SALOME_ListIteratorOfListIO It (selected);
3008 int nbSelectedGroups = 0;
3009 for ( ; It.More(); It.Next() )
3011 SMESH::SMESH_GroupBase_var aGroup =
3012 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
3013 if (!aGroup->_is_nil()) {
3015 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
3019 if (nbSelectedGroups == 0)
3021 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
3027 case SMESHOp::OpAddElemGroupPopup: // Add elements to group
3029 if(checkLock(aStudy)) break;
3030 if (myState == 800) {
3031 SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
3032 if (aDlg) aDlg->onAdd();
3037 case SMESHOp::OpRemoveElemGroupPopup: // Remove elements from group
3039 if(checkLock(aStudy)) break;
3040 if (myState == 800) {
3041 SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
3042 if (aDlg) aDlg->onRemove();
3047 case SMESHOp::OpEditGeomGroupAsGroup:
3051 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3055 if(checkLock(aStudy)) break;
3056 EmitSignalDeactivateDialog();
3058 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3059 SALOME_ListIO selected;
3061 aSel->selectedObjects( selected );
3063 SALOME_ListIteratorOfListIO It (selected);
3064 for ( ; It.More(); It.Next() )
3066 SMESH::SMESH_GroupOnGeom_var aGroup =
3067 SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
3068 if (!aGroup->_is_nil()) {
3069 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3074 SMESH::SMESH_GroupOnFilter_var aGroup =
3075 SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
3076 if (!aGroup->_is_nil()) {
3077 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3085 case SMESHOp::OpUnionGroups:
3086 case SMESHOp::OpIntersectGroups:
3087 case SMESHOp::OpCutGroups:
3091 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3095 if ( checkLock( aStudy ) )
3098 EmitSignalDeactivateDialog();
3100 SMESHGUI_GroupOpDlg* aDlg = 0;
3101 if ( theCommandID == SMESHOp::OpUnionGroups )
3102 aDlg = new SMESHGUI_UnionGroupsDlg( this );
3103 else if ( theCommandID == SMESHOp::OpIntersectGroups )
3104 aDlg = new SMESHGUI_IntersectGroupsDlg( this );
3106 aDlg = new SMESHGUI_CutGroupsDlg( this );
3113 case SMESHOp::OpGroupUnderlyingElem: // Create groups of entities from existing groups of superior dimensions
3115 if ( checkLock( aStudy ) )
3118 EmitSignalDeactivateDialog();
3119 SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
3125 case SMESHOp::OpDeleteGroup: // Delete groups with their contents
3129 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3133 if ( checkLock( aStudy ) )
3136 EmitSignalDeactivateDialog();
3138 ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
3142 case SMESHOp::OpMeshInformation:
3143 case SMESHOp::OpWhatIs:
3145 int page = theCommandID == SMESHOp::OpMeshInformation ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
3146 EmitSignalDeactivateDialog();
3147 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3148 SALOME_ListIO selected;
3150 aSel->selectedObjects( selected );
3152 if ( selected.Extent() > 1 ) { // a dlg for each IO
3153 SALOME_ListIteratorOfListIO It( selected );
3154 for ( ; It.More(); It.Next() ) {
3155 SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3156 dlg->showInfo( It.Value() );
3161 SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3167 case SMESHOp::OpFindElementByPoint:
3169 startOperation( theCommandID );
3173 case SMESHOp::OpEditHypothesis:
3175 if(checkLock(aStudy)) break;
3177 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3178 SALOME_ListIO selected;
3180 aSel->selectedObjects( selected );
3182 int nbSel = selected.Extent();
3185 Handle(SALOME_InteractiveObject) anIObject = selected.First();
3186 SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
3188 if ( !aHypothesis->_is_nil() )
3190 SMESHGUI_GenericHypothesisCreator* aCreator =
3191 SMESH::GetHypothesisCreator( SMESH::toQStr( aHypothesis->GetName() ));
3194 // set geometry of mesh and sub-mesh to aCreator
3195 aSel->selectedObjects( selected, "", /*convertReferences=*/false);
3196 if ( selected.Extent() == 1 )
3198 QString subGeomID, meshGeomID;
3199 Handle(SALOME_InteractiveObject) hypIO = selected.First();
3200 if ( SMESH::GetGeomEntries( hypIO, subGeomID, meshGeomID ))
3202 if ( subGeomID.isEmpty() ) subGeomID = meshGeomID;
3203 aCreator->setShapeEntry( subGeomID );
3204 aCreator->setMainShapeEntry( meshGeomID );
3208 aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
3218 case SMESHOp::OpUnassign: // REMOVE HYPOTHESIS / ALGORITHMS
3220 if(checkLock(aStudy)) break;
3221 SUIT_OverrideCursor wc;
3223 LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3224 SALOME_ListIO selected;
3226 aSel->selectedObjects( selected, QString::null, false );
3228 SALOME_ListIteratorOfListIO It(selected);
3229 for (int i = 0; It.More(); It.Next(), i++) {
3230 Handle(SALOME_InteractiveObject) IObject = It.Value();
3231 SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
3234 aSel->setSelectedObjects( l1 );
3239 case SMESHOp::OpElem0D:
3240 case SMESHOp::OpBall:
3241 case SMESHOp::OpEdge:
3242 case SMESHOp::OpTriangle:
3243 case SMESHOp::OpQuadrangle:
3244 case SMESHOp::OpPolygon:
3245 case SMESHOp::OpTetrahedron:
3246 case SMESHOp::OpHexahedron:
3247 case SMESHOp::OpPentahedron:
3248 case SMESHOp::OpPyramid:
3249 case SMESHOp::OpHexagonalPrism:
3251 if(checkLock(aStudy)) break;
3253 EmitSignalDeactivateDialog();
3254 SMDSAbs_EntityType type = SMDSEntity_Edge;
3255 switch (theCommandID) {
3256 case SMESHOp::OpElem0D: type = SMDSEntity_0D; break;
3257 case SMESHOp::OpBall: type = SMDSEntity_Ball; break;
3258 case SMESHOp::OpTriangle: type = SMDSEntity_Triangle; break;
3259 case SMESHOp::OpQuadrangle: type = SMDSEntity_Quadrangle; break;
3260 case SMESHOp::OpTetrahedron: type = SMDSEntity_Tetra; break;
3261 case SMESHOp::OpPolygon: type = SMDSEntity_Polygon; break;
3262 case SMESHOp::OpHexahedron: type = SMDSEntity_Hexa; break;
3263 case SMESHOp::OpPentahedron: type = SMDSEntity_Penta; break;
3264 case SMESHOp::OpPyramid: type = SMDSEntity_Pyramid; break;
3265 case SMESHOp::OpHexagonalPrism: type = SMDSEntity_Hexagonal_Prism; break;
3268 ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
3271 SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3275 case SMESHOp::OpPolyhedron:
3277 if(checkLock(aStudy)) break;
3279 EmitSignalDeactivateDialog();
3280 ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
3283 SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3287 case SMESHOp::OpQuadraticEdge:
3288 case SMESHOp::OpQuadraticTriangle:
3289 case SMESHOp::OpBiQuadraticTriangle:
3290 case SMESHOp::OpQuadraticQuadrangle:
3291 case SMESHOp::OpBiQuadraticQuadrangle:
3292 case SMESHOp::OpQuadraticPolygon:
3293 case SMESHOp::OpQuadraticTetrahedron:
3294 case SMESHOp::OpQuadraticPyramid:
3295 case SMESHOp::OpQuadraticPentahedron:
3296 case SMESHOp::OpQuadraticHexahedron:
3297 case SMESHOp::OpTriQuadraticHexahedron:
3299 if(checkLock(aStudy)) break;
3301 EmitSignalDeactivateDialog();
3302 SMDSAbs_EntityType type = SMDSEntity_Last;
3304 switch (theCommandID) {
3305 case SMESHOp::OpQuadraticEdge: type = SMDSEntity_Quad_Edge; break;
3306 case SMESHOp::OpQuadraticTriangle: type = SMDSEntity_Quad_Triangle; break;
3307 case SMESHOp::OpBiQuadraticTriangle: type = SMDSEntity_BiQuad_Triangle; break;
3308 case SMESHOp::OpQuadraticQuadrangle: type = SMDSEntity_Quad_Quadrangle; break;
3309 case SMESHOp::OpBiQuadraticQuadrangle: type = SMDSEntity_BiQuad_Quadrangle; break;
3310 case SMESHOp::OpQuadraticPolygon: type = SMDSEntity_Quad_Polygon; break;
3311 case SMESHOp::OpQuadraticTetrahedron: type = SMDSEntity_Quad_Tetra; break;
3312 case SMESHOp::OpQuadraticPyramid: type = SMDSEntity_Quad_Pyramid; break;
3313 case SMESHOp::OpQuadraticPentahedron: type = SMDSEntity_Quad_Penta; break;
3314 case SMESHOp::OpQuadraticHexahedron: type = SMDSEntity_Quad_Hexa; break;
3315 case SMESHOp::OpTriQuadraticHexahedron: type = SMDSEntity_TriQuad_Hexa; break;
3318 if ( type != SMDSEntity_Last )
3319 ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
3322 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3323 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3327 case SMESHOp::OpRemoveNodes:
3329 if(checkLock(aStudy)) break;
3331 EmitSignalDeactivateDialog();
3332 ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
3335 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3336 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3340 case SMESHOp::OpRemoveElements: // REMOVES ELEMENTS
3342 if(checkLock(aStudy)) break;
3344 EmitSignalDeactivateDialog();
3345 ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
3349 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3350 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3354 case SMESHOp::OpClearMesh: {
3356 if(checkLock(aStudy)) break;
3358 SALOME_ListIO selected;
3359 if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3360 aSel->selectedObjects( selected );
3362 SUIT_OverrideCursor wc;
3363 SALOME_ListIteratorOfListIO It (selected);
3364 for ( ; It.More(); It.Next() )
3366 Handle(SALOME_InteractiveObject) IOS = It.Value();
3367 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
3368 if ( aMesh->_is_nil()) continue;
3371 if ( aMesh->NbNodes() == 0 ) // imported mesh is not empty
3372 SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3373 _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3374 SMESH::ModifiedMesh( aMeshSObj, false, true);
3375 // hide groups and submeshes
3376 _PTR(ChildIterator) anIter =
3377 SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
3378 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3380 _PTR(SObject) so = anIter->Value();
3381 SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3384 catch (const SALOME::SALOME_Exception& S_ex){
3386 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3390 SMESH::UpdateView();
3394 case SMESHOp::OpRemoveOrphanNodes:
3396 if(checkLock(aStudy)) break;
3397 SALOME_ListIO selected;
3398 if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3399 aSel->selectedObjects( selected );
3400 if ( selected.Extent() == 1 ) {
3401 Handle(SALOME_InteractiveObject) anIO = selected.First();
3402 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3403 if ( !aMesh->_is_nil() ) {
3404 bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3405 tr( "SMESH_WARNING" ),
3406 tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3407 SUIT_MessageBox::Yes |
3408 SUIT_MessageBox::No,
3409 SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3412 SUIT_OverrideCursor wc;
3413 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3414 int removed = aMeshEditor->RemoveOrphanNodes();
3415 SUIT_MessageBox::information(SMESHGUI::desktop(),
3416 tr("SMESH_INFORMATION"),
3417 tr("NB_NODES_REMOVED").arg(removed));
3418 if ( removed > 0 ) {
3419 SMESH::UpdateView();
3420 SMESHGUI::Modified();
3423 catch (const SALOME::SALOME_Exception& S_ex) {
3424 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3433 case SMESHOp::OpRenumberingNodes:
3435 if(checkLock(aStudy)) break;
3437 EmitSignalDeactivateDialog();
3438 ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3442 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3443 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3447 case SMESHOp::OpRenumberingElements:
3449 if(checkLock(aStudy)) break;
3451 EmitSignalDeactivateDialog();
3452 ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3456 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3457 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3461 case SMESHOp::OpTranslation:
3463 if(checkLock(aStudy)) break;
3465 EmitSignalDeactivateDialog();
3466 ( new SMESHGUI_TranslationDlg( this ) )->show();
3469 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3470 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3474 case SMESHOp::OpRotation:
3476 if(checkLock(aStudy)) break;
3478 EmitSignalDeactivateDialog();
3479 ( new SMESHGUI_RotationDlg( this ) )->show();
3482 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3483 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3487 case SMESHOp::OpSymmetry:
3489 if(checkLock(aStudy)) break;
3491 EmitSignalDeactivateDialog();
3492 ( new SMESHGUI_SymmetryDlg( this ) )->show();
3495 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3496 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3500 case SMESHOp::OpScale:
3502 if(checkLock(aStudy)) break;
3504 EmitSignalDeactivateDialog();
3505 ( new SMESHGUI_ScaleDlg( this ) )->show();
3508 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3509 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3514 case SMESHOp::OpSewing:
3516 if(checkLock(aStudy)) break;
3518 EmitSignalDeactivateDialog();
3519 ( new SMESHGUI_SewingDlg( this ) )->show();
3522 SUIT_MessageBox::warning(SMESHGUI::desktop(),
3523 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));