Salome HOME
a465cd3bec41d431b0c77ae3f81f83ca1d4dc47b
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI, Open CASCADE S.A.S.
24
25 #include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
26 #ifdef HAVE_FINITE
27 #undef HAVE_FINITE            // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
28 #endif
29 #include "Python.h"
30
31 //  SMESH includes
32 #include "SMESHGUI.h"
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"
86
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"
95
96 #include "SMESH_version.h"
97
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"
104
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>
111
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>
117
118 #include <SVTK_ViewManager.h>
119 #include <SVTK_ViewModel.h>
120 #include <SVTK_ViewWindow.h>
121
122 #include <VTKViewer_Algorithm.h>
123
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>
130
131 #include <QtxPopupMgr.h>
132 #include <QtxFontEdit.h>
133
134 #include <SALOME_ListIO.hxx>
135
136 #ifndef DISABLE_PLOT2DVIEWER
137 #include <SPlot2d_ViewModel.h>
138 #include <SPlot2d_Histogram.h>
139 #endif
140
141 // IDL includes
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)
146
147 // Qt includes
148 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
149 #include <QApplication>
150 #include <QMenu>
151 #include <QTextStream>
152 #include <QListView>
153 #include <QTreeView>
154
155 // BOOST includes
156 #include <boost/shared_ptr.hpp>
157
158 // VTK includes
159 #include <vtkCallbackCommand.h>
160 #include <vtkCamera.h>
161 #include <vtkLookupTable.h>
162 #include <vtkPlane.h>
163 #include <vtkRenderer.h>
164
165 // SALOME KERNEL includes
166 #include <SALOMEDSClient_ClientFactory.hxx>
167 #include <SALOMEDSClient_IParameters.hxx>
168 #include <SALOMEDSClient_SComponent.hxx>
169 #include <SALOMEDSClient_StudyBuilder.hxx>
170 #include <SALOMEDS_Study.hxx>
171 #include <SALOMEDS_SObject.hxx>
172 #include "utilities.h"
173
174 // OCCT includes
175 #include <Standard_ErrorHandler.hxx>
176 #include <NCollection_DataMap.hxx>
177 #include <NCollection_DoubleMap.hxx>
178
179 #include <Basics_Utils.hxx>
180
181 //To disable automatic genericobj management, the following line should be commented.
182 //Otherwise, it should be uncommented.
183 //Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
184 #define WITHGENERICOBJ
185
186 // Below macro, when uncommented, switches on simplified (more performant) algorithm
187 // of auto-color picking up
188 #define SIMPLE_AUTOCOLOR
189
190 namespace
191 {
192   // Declarations
193   //=============================================================
194   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
195                             int theCommandID);
196
197   void ExportMeshToFile(int theCommandID);
198
199   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap);
200
201   void SetDisplayEntity(int theCommandID);
202
203   int ActionToControl( int theID, bool theReversed = false );
204
205   void Control( int theCommandID );
206
207   // Definitions
208   //================================================================================
209   /*!
210    * \brief Reads meshes from file
211    */
212   //================================================================================
213
214   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
215                              int theCommandID )
216   {
217     QStringList filter;
218     std::string myExtension;
219
220     if ( theCommandID == SMESHOp::OpImportMED ) {
221       filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.*med)" );
222       filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
223     }
224     else if ( theCommandID == SMESHOp::OpImportUNV ) {
225       filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
226     }
227     else if ( theCommandID == SMESHOp::OpImportDAT ) {
228       filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
229     }
230     else if ( theCommandID == SMESHOp::OpImportSTL ) {
231       filter.append( QObject::tr( "STL_FILES_FILTER" ) + " (*.stl)" );
232     }
233   #ifdef WITH_CGNS
234     else if ( theCommandID == SMESHOp::OpImportCGNS ) {
235       filter.append( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
236     }
237   #endif
238     else if ( theCommandID == SMESHOp::OpImportSAUV ) {
239       filter.append( QObject::tr( "SAUV files (*.sauv*)" ) );
240       filter.append( QObject::tr( "All files (*)" ) );
241     }
242     else if ( theCommandID == SMESHOp::OpImportGMF ) {
243       filter.append( QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)"  );
244       filter.append( QObject::tr( "GMF_BINARY_FILES_FILTER") + " (*.meshb)" );
245     }
246
247     QString anInitialPath = "";
248     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
249       anInitialPath = QDir::currentPath();
250
251     QStringList filenames;
252     bool toCreateGroups = true;
253
254     // if ( theCommandID == SMESHOp::OpImportGMF ) { // GMF
255     //   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
256     //     ( SMESHGUI::desktop(), true, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
257     //   fd->setWindowTitle( QObject::tr( "SMESH_IMPORT_MESH" ) );
258     //   fd->setNameFilters( filter );
259     //   fd->SetChecked( true );
260     //   if ( fd->exec() )
261     //     filenames << fd->selectedFile();
262     //   toCreateGroups = fd->IsChecked();
263
264     //   delete fd;
265     // }
266     // else
267     {
268       filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
269                                                   anInitialPath,
270                                                   filter,
271                                                   QObject::tr( "SMESH_IMPORT_MESH" ) );
272     }
273     if ( filenames.count() > 0 ) {
274       SUIT_OverrideCursor wc;
275       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
276
277       QStringList errors;
278       QStringList anEntryList;
279       bool isEmpty = false;
280       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
281         QString filename = *it;
282         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
283         try {
284           switch ( theCommandID ) {
285           case SMESHOp::OpImportDAT:
286             {
287               // DAT format (currently unsupported)
288               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
289                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
290               break;
291             }
292           case SMESHOp::OpImportUNV:
293             {
294               // UNV format
295               aMeshes->length( 1 );
296               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toUtf8().constData() );
297               if ( aMeshes[0]->_is_nil() )
298                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
299                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
300               break;
301             }
302           case SMESHOp::OpImportMED:
303             {
304               // MED format
305               SMESH::DriverMED_ReadStatus res;
306               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toUtf8().constData(), res );
307               if ( res != SMESH::DRS_OK ) {
308                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
309                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
310               }
311               break;
312             }
313           case SMESHOp::OpImportSTL:
314             {
315               // STL format
316               aMeshes->length( 1 );
317               aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toUtf8().constData() );
318               if ( aMeshes[0]->_is_nil() ) {
319                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
320                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
321               }
322               break;
323             }
324         #ifdef WITH_CGNS
325           case SMESHOp::OpImportCGNS:
326             {
327               // CGNS format
328               SMESH::DriverMED_ReadStatus res;
329               aMeshes = theComponentMesh->CreateMeshesFromCGNS( filename.toUtf8().constData(), res );
330               if ( res != SMESH::DRS_OK ) {
331                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
332                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
333               }
334               break;
335             }
336         #endif
337           case SMESHOp::OpImportSAUV:
338             {
339               // SAUV format
340               SMESH::DriverMED_ReadStatus res;
341               aMeshes = theComponentMesh->CreateMeshesFromSAUV( filename.toUtf8().constData(), res );
342               if ( res != SMESH::DRS_OK ) {
343                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
344                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
345               }
346               break;
347             }
348           case SMESHOp::OpImportGMF:
349             {
350               // GMF format
351               SMESH::ComputeError_var res;
352               aMeshes->length( 1 );
353               aMeshes[0] = theComponentMesh->CreateMeshesFromGMF( filename.toUtf8().constData(),
354                                                                   toCreateGroups,
355                                                                   res.out() );
356               if ( res->code != SMESH::DRS_OK ) {
357                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
358                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res->code ).toLatin1().data() ) ) );
359                 if ( strlen( res->comment.in() ) > 0 ) {
360                   errors.back() += ": ";
361                   errors.back() += res->comment.in();
362                 }
363               }
364               break;
365             }
366           }
367         }
368         catch ( const SALOME::SALOME_Exception& S_ex ) {
369           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
370                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
371         }
372
373         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
374           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
375           if ( aMeshSO ) {
376             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
377             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
378             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
379             if ( theCommandID == SMESHOp::OpImportUNV ) // mesh names aren't taken from the file for UNV import
380               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
381
382             anEntryList.append( aMeshSO->GetID().c_str() );
383           }
384           else {
385             isEmpty = true;
386           }
387         }
388       }
389
390       // update Object browser
391       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
392
393       // browse to the published meshes
394       if( LightApp_Application* anApp =
395           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
396         anApp->browseObjects( anEntryList );
397
398       // show Error message box if there were errors
399       if ( errors.count() > 0 ) {
400         SUIT_MessageBox::critical( SMESHGUI::desktop(),
401                                    QObject::tr( "SMESH_ERROR" ),
402                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
403       }
404
405       // show warning message box, if some imported mesh is empty
406       if ( isEmpty ) {
407           SUIT_MessageBox::warning( SMESHGUI::desktop(),
408                                     QObject::tr( "SMESH_WRN_WARNING" ),
409                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
410       }
411     }
412   }
413
414   //================================================================================
415   /*!
416    * \brief Export selected meshes or groups into a file
417    */
418   //================================================================================
419
420   void ExportMeshToFile( int theCommandID )
421   {
422     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
423     SALOME_ListIO selected;
424     if( aSel )
425       aSel->selectedObjects( selected );
426
427     const bool isDAT = ( theCommandID == SMESHOp::OpExportDAT || theCommandID == SMESHOp::OpPopupExportDAT );
428     const bool isMED = ( theCommandID == SMESHOp::OpExportMED || theCommandID == SMESHOp::OpPopupExportMED );
429     const bool isUNV = ( theCommandID == SMESHOp::OpExportUNV || theCommandID == SMESHOp::OpPopupExportUNV );
430     const bool isSTL = ( theCommandID == SMESHOp::OpExportSTL || theCommandID == SMESHOp::OpPopupExportSTL );
431 #ifdef WITH_CGNS
432     const bool isCGNS= ( theCommandID == SMESHOp::OpExportCGNS || theCommandID == SMESHOp::OpPopupExportCGNS );
433 #else
434     const bool isCGNS= false;
435 #endif
436     const bool isSAUV= ( theCommandID == SMESHOp::OpExportSAUV || theCommandID == SMESHOp::OpPopupExportSAUV );
437     const bool isGMF = ( theCommandID == SMESHOp::OpExportGMF || theCommandID == SMESHOp::OpPopupExportGMF );
438
439     const bool multiMeshSupported = ( isMED || isCGNS ); // file can hold several meshes
440     if ( selected.Extent() == 0 || ( selected.Extent() > 1 && !multiMeshSupported ))
441       return;
442
443     // get mesh object from selection and check duplication of their names
444     bool hasDuplicatedMeshNames = false;
445     QList< QPair< SMESH::SMESH_IDSource_var, QString > > aMeshList;
446     QList< QPair< SMESH::SMESH_IDSource_var, QString > >::iterator aMeshIter;
447     SALOME_ListIteratorOfListIO It( selected );
448     for( ; It.More(); It.Next() )
449     {
450       Handle(SALOME_InteractiveObject) anIObject = It.Value();
451       SMESH::SMESH_IDSource_var aMeshItem = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIObject);
452       if ( aMeshItem->_is_nil() ) {
453         SUIT_MessageBox::warning( SMESHGUI::desktop(),
454                                   QObject::tr( "SMESH_WRN_WARNING" ),
455                                   QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
456         return;
457       }
458
459       QString aMeshName = anIObject->getName();
460
461       // check for name duplications
462       if ( !hasDuplicatedMeshNames )
463         for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
464           if( aMeshName == (*aMeshIter).second ) {
465             hasDuplicatedMeshNames = true;
466             break;
467           }
468         }
469
470       aMeshList.append( QPair< SMESH::SMESH_IDSource_var, QString >( aMeshItem, aMeshName ) );
471     }
472
473     if( hasDuplicatedMeshNames && isMED ) {
474       int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
475                                           QObject::tr("SMESH_WRN_WARNING"),
476                                           QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
477                                           QObject::tr("SMESH_BUT_YES"),
478                                           QObject::tr("SMESH_BUT_NO"), 0, 1);
479       if (aRet != 0)
480         return;
481     }
482
483     aMeshIter = aMeshList.begin();
484     SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
485     SMESH::SMESH_Mesh_var            aMesh = aMeshOrGroup->GetMesh();
486     QString                      aMeshName = (*aMeshIter).second;
487
488     if ( isMED || isCGNS || isSAUV ) // formats where group names must be unique
489     {
490       // check for equal group names within each mesh
491       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
492         SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
493         if ( !aMeshItem->_is_nil() && aMeshItem->HasDuplicatedGroupNamesMED()) {
494           int aRet = SUIT_MessageBox::warning
495             (SMESHGUI::desktop(),
496              QObject::tr("SMESH_WRN_WARNING"),
497              QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
498              QObject::tr("SMESH_BUT_YES"),
499              QObject::tr("SMESH_BUT_NO"), 0, 1);
500           if (aRet != 0)
501             return;
502         }
503       }
504     }
505     
506     // Warn the user about presence of not supported elements
507     QString format;
508     std::vector< SMESH::EntityType > notSupportedElemTypes, presentNotSupported;
509     if ( isDAT )
510     {
511       format = "DAT";
512       notSupportedElemTypes.push_back( SMESH::Entity_0D );
513       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
514     }
515     else if ( isUNV )
516     {
517       format = "UNV";
518       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
519       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
520       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
521       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
522       notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
523       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
524       notSupportedElemTypes.push_back( SMESH::Entity_0D );
525       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
526     }
527     else if ( isSTL )
528     {
529       format = "STL";
530       notSupportedElemTypes.push_back( SMESH::Entity_Edge );
531       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Edge );
532       notSupportedElemTypes.push_back( SMESH::Entity_0D );
533       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
534     }
535     else if ( isCGNS )
536     {
537       format = "CGNS";
538       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
539     }
540     else if ( isSAUV )
541     {
542       format = "SAUV";
543       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
544       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Triangle );
545       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
546       notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
547       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
548       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
549       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
550       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
551     }
552     else if ( isGMF )
553     {
554       format = "GMF";
555       notSupportedElemTypes.push_back( SMESH::Entity_0D );
556       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
557       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
558       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
559       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
560       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
561       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
562       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
563       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
564     }
565     if ( ! notSupportedElemTypes.empty() )
566     {
567       SMESH::long_array_var nbElems = aMeshOrGroup->GetMeshInfo();
568       for ( size_t iType = 0; iType < notSupportedElemTypes.size(); ++iType )
569         if ( nbElems[ notSupportedElemTypes[ iType ]] > 0 )
570           presentNotSupported.push_back( notSupportedElemTypes[ iType ]);
571     }
572     if ( !presentNotSupported.empty() )
573     {
574       QString typeNames;
575       const char* typeMsg[SMESH::Entity_Last] = {
576         "SMESH_NODES", "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES",
577         "SMESH_TRIANGLES", "SMESH_QUADRATIC_TRIANGLES", "SMESH_BIQUADRATIC_TRIANGLES",
578         "SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES", "SMESH_BIQUADRATIC_QUADRANGLES",
579         "SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
580         "SMESH_TETRAHEDRA","SMESH_QUADRATIC_TETRAHEDRONS","SMESH_PYRAMIDS",
581         "SMESH_QUADRATIC_PYRAMIDS","SMESH_HEXAHEDRA","SMESH_QUADRATIC_HEXAHEDRONS",
582         "SMESH_TRIQUADRATIC_HEXAHEDRONS","SMESH_PENTAHEDRA","SMESH_QUADRATIC_PENTAHEDRONS",
583         "SMESH_OCTAHEDRA","SMESH_POLYEDRONS","SMESH_QUADRATIC_POLYEDRONS","SMESH_BALLS"
584       };
585       QString andStr = " " + QObject::tr("SMESH_AND") + " ", comma(", ");
586       for ( size_t iType = 0; iType < presentNotSupported.size(); ++iType ) {
587         typeNames += QObject::tr( typeMsg[ presentNotSupported[ iType ]]);
588         if ( iType != presentNotSupported.size() - 1 )
589           typeNames += ( iType == presentNotSupported.size() - 2 ) ? andStr : comma;
590       }
591       int aRet = SUIT_MessageBox::warning
592         (SMESHGUI::desktop(),
593          QObject::tr("SMESH_WRN_WARNING"),
594          QObject::tr("EXPORT_NOT_SUPPORTED").arg(aMeshName).arg(format).arg(typeNames),
595          QObject::tr("SMESH_BUT_YES"),
596          QObject::tr("SMESH_BUT_NO"), 0, 1);
597       if (aRet != 0)
598         return;
599     }
600
601     // Get parameters of export operation
602
603     QString            aFilename;
604     SMESH::MED_VERSION aFormat;
605     // Init the parameters with the default values
606     bool aIsASCII_STL   = true;
607     bool toCreateGroups = false;
608     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
609     if ( resMgr )
610       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
611     bool toOverwrite = true;
612     bool toFindOutDim = true;
613
614     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
615     QString anInitialPath = "";
616     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
617       anInitialPath = QDir::currentPath();
618
619     QList< QPair< GEOM::ListOfFields_var, QString > > aFieldList;
620
621     // Get a file name to write in and additional otions
622     if ( isUNV || isDAT || isGMF ) // Export w/o options
623     {
624       if ( isUNV )
625         aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
626       else if ( isDAT )
627         aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
628       else if ( isGMF )
629         aFilter = QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)" +
630           ";;" +  QObject::tr( "GMF_BINARY_FILES_FILTER" )  + " (*.meshb)";
631      if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
632       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
633                                             anInitialPath + QString("/") + aMeshName,
634                                             aFilter, aTitle, false);
635     }
636     else if ( isCGNS )// Export to CGNS
637     {
638       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
639       fd->setWindowTitle( aTitle );
640       fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
641       if ( !anInitialPath.isEmpty() )
642         fd->setDirectory( anInitialPath );
643       fd->selectFile(aMeshName);
644       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
645       fd->setValidator( fv );
646
647       if ( fd->exec() )
648         aFilename = fd->selectedFile();
649       toOverwrite = fv->isOverwrite();
650
651       delete fd;
652     }
653     else if ( isSTL ) // Export to STL
654     {
655       QMap<QString, int> aFilterMap;
656       aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
657       aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 );
658
659       QStringList filters;
660       QMap<QString, int>::const_iterator it = aFilterMap.begin();
661       for ( ; it != aFilterMap.end(); ++it )
662         filters.push_back( it.key() );
663
664       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
665       fd->setWindowTitle( aTitle );
666       fd->setNameFilters( filters );
667       fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
668       if ( !anInitialPath.isEmpty() )
669         fd->setDirectory( anInitialPath );
670       fd->selectFile(aMeshName);
671       bool is_ok = false;
672       while (!is_ok) {
673         if ( fd->exec() )
674           aFilename = fd->selectedFile();
675         aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
676         is_ok = true;
677       }
678       delete fd;
679     }
680     else if ( isMED || isSAUV ) // Export to MED or SAUV
681     {
682       QMap<QString, SMESH::MED_VERSION> aFilterMap;
683       //QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
684       if ( isMED ) {
685         QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
686         //aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v21 ) + " (*.med)", SMESH::MED_V2_1 );
687         aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v22 ) + " (*.med)", SMESH::MED_V2_2 );
688       }
689       else { // isSAUV
690         aFilterMap.insert("All files (*)", SMESH::MED_V2_1 );
691         aFilterMap.insert("SAUV files (*.sauv)", SMESH::MED_V2_2 );
692         aFilterMap.insert("SAUV files (*.sauve)", SMESH::MED_V2_1 );
693       }
694
695       QStringList filters;
696       QString aDefaultFilter;
697       QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
698       for ( ; it != aFilterMap.end(); ++it ) {
699         filters.push_back( it.key() );
700         if (it.value() == SMESH::MED_V2_2)
701           aDefaultFilter = it.key();
702       }
703       QStringList checkBoxes;
704       checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM");
705
706       SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
707       QList< QWidget* > wdgList;
708       if ( fieldSelWdg->GetAllFeilds( aMeshList, aFieldList ))
709         wdgList.append( fieldSelWdg );
710
711       SalomeApp_CheckFileDlg* fd =
712         new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true, wdgList );
713       fd->setWindowTitle( aTitle );
714       fd->setNameFilters( filters );
715       fd->selectNameFilter( aDefaultFilter );
716       fd->SetChecked( toCreateGroups, 0 );
717       fd->SetChecked( toFindOutDim,   1 );
718       if ( !anInitialPath.isEmpty() )
719         fd->setDirectory( anInitialPath );
720       fd->selectFile(aMeshName);
721       
722       
723       QListView *lview = fd->findChild<QListView*>("listView");
724       if( lview ) {
725         lview->setMinimumHeight(200);
726       }
727       QTreeView *tview = fd->findChild<QTreeView*>("treeView");
728       if( tview ) {
729         tview->setMinimumHeight(200);
730       }
731
732       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
733       fd->setValidator( fv );
734
735       bool is_ok = false;
736       while (!is_ok) {
737         if ( fd->exec() )
738           aFilename = fd->selectedFile();
739         else {
740           aFilename = QString::null;
741           break;
742         }
743         aFormat = aFilterMap[fd->selectedNameFilter()];
744         toOverwrite = fv->isOverwrite();
745         is_ok = true;
746         if ( !aFilename.isEmpty() ) {
747           // med-2.1 does not support poly elements
748           if ( aFormat==SMESH::MED_V2_1 )
749             for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
750               SMESH::SMESH_IDSource_var aMeshItem = (*aMeshIter).first;
751               SMESH::long_array_var nbElems = aMeshItem->GetMeshInfo();
752               if ( nbElems[ SMESH::Entity_Polygon   ] + nbElems[ SMESH::Entity_Quad_Polygon   ] +
753                    nbElems[ SMESH::Entity_Polyhedra ] + nbElems[ SMESH::Entity_Quad_Polyhedra ])
754               {
755                 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
756                                                     QObject::tr("SMESH_WRN_WARNING"),
757                                                     QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
758                                                     QObject::tr("SMESH_BUT_YES"),
759                                                     QObject::tr("SMESH_BUT_NO"), 0, 1);
760                 if (aRet != 0) {
761                   is_ok = false;
762                   break;
763                 }
764               }
765             }
766           if( !toOverwrite ) {
767             // can't append to an existing using other format
768             SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
769             bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toUtf8().constData(), aVersion );
770             if( !isVersionOk || aVersion != aFormat ) {
771               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
772                                                   QObject::tr("SMESH_WRN_WARNING"),
773                                                   QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
774                                                   QObject::tr("SMESH_BUT_YES"),
775                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
776               if (aRet == 0)
777                 toOverwrite = true;
778               else
779                 is_ok = false;
780             }
781
782             QStringList aMeshNamesCollisionList;
783             SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() );
784             for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
785               QString anExistingMeshName( aMeshNames[ i ] );
786               for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
787                 QString anExportMeshName = (*aMeshIter).second;
788                 if( anExportMeshName == anExistingMeshName ) {
789                   aMeshNamesCollisionList.append( anExportMeshName );
790                   break;
791                 }
792               }
793             }
794             if( !aMeshNamesCollisionList.isEmpty() ) {
795               QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
796               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
797                                                   QObject::tr("SMESH_WRN_WARNING"),
798                                                   QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
799                                                   QObject::tr("SMESH_BUT_YES"),
800                                                   QObject::tr("SMESH_BUT_NO"),
801                                                   QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
802               if (aRet == 0)
803                 toOverwrite = true;
804               else if (aRet == 2)
805                 is_ok = false;
806             }
807           }
808         }
809       }
810       toCreateGroups = fd->IsChecked(0);
811       toFindOutDim   = fd->IsChecked(1);
812       fieldSelWdg->GetSelectedFeilds();
813       if ( !fieldSelWdg->parent() )
814         delete fieldSelWdg;
815       delete fd;
816     }
817     else
818     {
819       return;
820     }
821
822     // Perform export
823
824     if ( !aFilename.isEmpty() ) {
825       // Check whether the file already exists and delete it if yes
826       QFile aFile( aFilename );
827       if ( aFile.exists() && toOverwrite )
828         aFile.remove();
829       SUIT_OverrideCursor wc;
830
831       try {
832         // Renumbering is not needed since SMDS redesign in V6.2.0 (Nov 2010)
833 //         bool Renumber = false;
834 //         // PAL 14172  : Check of we have to renumber or not from the preferences before export
835 //         if (resMgr)
836 //           Renumber= resMgr->booleanValue("renumbering");
837 //         if (Renumber){
838 //           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
839 //           aMeshEditor->RenumberNodes();
840 //           aMeshEditor->RenumberElements();
841 //           if ( SMESHGUI::automaticUpdate() )
842 //             SMESH::UpdateView();
843 //         }
844         if ( isMED )
845         {
846           aMeshIter = aMeshList.begin();
847           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
848           {
849             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
850             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
851             const GEOM::ListOfFields&       fields = aFieldList[ aMeshIndex ].first.in();
852             const QString&            geoAssFields = aFieldList[ aMeshIndex ].second;
853             const bool                   hasFields = ( fields.length() || !geoAssFields.isEmpty() );
854             if ( !hasFields && aMeshOrGroup->_is_equivalent( aMeshItem ))
855               aMeshItem->ExportToMEDX( aFilename.toUtf8().data(), toCreateGroups,
856                                        aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim );
857             else
858               aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups,
859                                           aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim,
860                                           fields, geoAssFields.toLatin1().data() );
861           }
862         }
863         else if ( isSAUV )
864         {
865           for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ )
866           {
867             SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
868             if( !aMeshItem->_is_nil() )
869               aMeshItem->ExportSAUV( aFilename.toUtf8().data(), toCreateGroups );
870           }
871         }
872         else if ( isDAT )
873         {
874           if ( aMeshOrGroup->_is_equivalent( aMesh ))
875             aMesh->ExportDAT( aFilename.toUtf8().data() );
876           else
877             aMesh->ExportPartToDAT( aMeshOrGroup, aFilename.toUtf8().data() );
878         }
879         else if ( isUNV )
880         {
881           if ( aMeshOrGroup->_is_equivalent( aMesh ))
882             aMesh->ExportUNV( aFilename.toUtf8().data() );
883           else
884             aMesh->ExportPartToUNV( aMeshOrGroup, aFilename.toUtf8().data() );
885         }
886         else if ( isSTL )
887         {
888           if ( aMeshOrGroup->_is_equivalent( aMesh ))
889             aMesh->ExportSTL( aFilename.toUtf8().data(), aIsASCII_STL );
890           else
891             aMesh->ExportPartToSTL( aMeshOrGroup, aFilename.toUtf8().data(), aIsASCII_STL );
892         }
893         else if ( isCGNS )
894         {
895           aMeshIter = aMeshList.begin();
896           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
897           {
898             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
899             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
900             aMeshItem->ExportCGNS( aMeshOrGroup,
901                                    aFilename.toUtf8().data(),
902                                    toOverwrite && aMeshIndex == 0 );
903           }
904         }
905         else if ( isGMF )
906         {
907           toCreateGroups = true;
908           aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
909         }
910       }
911       catch (const SALOME::SALOME_Exception& S_ex){
912         wc.suspend();
913         SUIT_MessageBox::warning(SMESHGUI::desktop(),
914                                  QObject::tr("SMESH_WRN_WARNING"),
915                                  QObject::tr("SMESH_EXPORT_FAILED"));
916         wc.resume();
917       }
918     }
919   }
920
921   inline void InverseEntityMode(unsigned int& theOutputMode,
922                                 unsigned int theMode)
923   {
924     bool anIsNotPresent = ~theOutputMode & theMode;
925     if(anIsNotPresent)
926       theOutputMode |= theMode;
927     else
928       theOutputMode &= ~theMode;
929   }
930
931   void SetDisplayEntity(int theCommandID){
932     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
933     SALOME_ListIO selected;
934     if( aSel )
935       aSel->selectedObjects( selected );
936
937     if(selected.Extent() >= 1){
938       SALOME_ListIteratorOfListIO It( selected );
939       for( ; It.More(); It.Next()){
940         Handle(SALOME_InteractiveObject) IObject = It.Value();
941         if(IObject->hasEntry()){
942           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
943             unsigned int aMode = anActor->GetEntityMode();
944             switch(theCommandID){
945             case SMESHOp::OpDE0DElements:
946               InverseEntityMode(aMode,SMESH_Actor::e0DElements);
947               break;
948             case SMESHOp::OpDEEdges:
949               InverseEntityMode(aMode,SMESH_Actor::eEdges);
950               break;
951             case SMESHOp::OpDEFaces:
952               InverseEntityMode(aMode,SMESH_Actor::eFaces);
953               break;
954             case SMESHOp::OpDEVolumes:
955               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
956               break;
957             case SMESHOp::OpDEBalls:
958               InverseEntityMode(aMode,SMESH_Actor::eBallElem);
959               break;
960             case SMESHOp::OpDEAllEntity:
961               aMode = SMESH_Actor::eAllEntity;
962               break;
963             }
964             if(aMode)
965               anActor->SetEntityMode(aMode);
966           }
967         }
968       }
969     }
970   }
971
972   void AutoColor()
973   {
974     SALOME_ListIO selected;
975     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
976     if( !app )
977       return;
978
979     LightApp_SelectionMgr* aSel = app->selectionMgr();
980     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
981     if( !aSel || !appStudy )
982       return;
983
984     aSel->selectedObjects( selected );
985     if( selected.IsEmpty() )
986       return;
987
988     Handle(SALOME_InteractiveObject) anIObject = selected.First();
989
990     _PTR(Study) aStudy = appStudy->studyDS();
991     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
992     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
993     if( aMainObject->_is_nil() )
994       return;
995
996     SUIT_OverrideCursor wc;
997
998     aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
999
1000     QList<SALOMEDS::Color> aReservedColors;
1001
1002     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
1003     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1004     {
1005       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1006       //SALOMEDS::Color aColor = aGroupObject->GetColor();
1007
1008 #ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
1009       SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
1010 #else                     // old algorithm  for auto-colors
1011       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1012       aReservedColors.append( aColor );
1013 #endif                    // SIMPLE_AUTOCOLOR
1014       aGroupObject->SetColor( aColor );
1015
1016       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
1017       if (aGroupSObject) {
1018         QColor c;
1019         int delta;
1020         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
1021           switch ( aGroupObject->GetType ()) {
1022           case SMESH::NODE:
1023             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1024           case SMESH::EDGE:
1025             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1026           case SMESH::ELEM0D:
1027             anActor->Set0DColor( aColor.R, aColor.G, aColor.B ); break;
1028           case SMESH::BALL:
1029             anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1030           case SMESH::VOLUME:
1031             SMESH::GetColor("SMESH", "volume_color", c, delta, "255,0,170|-100");
1032             anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1033           case SMESH::FACE:
1034           default:
1035             SMESH::GetColor("SMESH", "fill_color", c, delta, "0,170,255|-100");
1036             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta );
1037           }
1038         }
1039       }
1040     }
1041
1042     SMESH::RepaintCurrentView();
1043   }
1044
1045   void OverallMeshQuality() {
1046     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1047     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1048     SALOME_ListIO selected;
1049     if( aSel )
1050       aSel->selectedObjects( selected );
1051
1052     if ( selected.IsEmpty() ) return;
1053     SALOME_ListIteratorOfListIO It( selected );
1054     for ( ; It.More(); It.Next() ) {
1055       SMESHGUI_CtrlInfoDlg* ctrlDlg = new SMESHGUI_CtrlInfoDlg( SMESHGUI::desktop() );
1056       ctrlDlg->showInfo( It.Value() );
1057       ctrlDlg->show();
1058     }
1059   }
1060
1061   QString functorToString( SMESH::Controls::FunctorPtr f )
1062   {
1063     QString type = QObject::tr( "UNKNOWN_CONTROL" );
1064     if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
1065       type = QObject::tr( "VOLUME_3D_ELEMENTS" );
1066     else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
1067       type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
1068     else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
1069       type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
1070     else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
1071       type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
1072     else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
1073       type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
1074     else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
1075       type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
1076     else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
1077       type = QObject::tr( "WARP_ELEMENTS" );
1078     else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
1079       type = QObject::tr( "TAPER_ELEMENTS" );
1080     else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
1081       type = QObject::tr( "SKEW_ELEMENTS" );
1082     else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
1083       type = QObject::tr( "AREA_ELEMENTS" );
1084     else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
1085       type = QObject::tr( "LENGTH_EDGES" );
1086     else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
1087       type = QObject::tr( "LENGTH2D_EDGES" );
1088     else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
1089       type = QObject::tr( "MULTI_BORDERS" );
1090     else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
1091       type = QObject::tr( "MULTI2D_BORDERS" );
1092     else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
1093       type = QObject::tr( "FREE_NODES" );
1094     else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
1095       type = QObject::tr( "FREE_EDGES" );
1096     else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
1097       type = QObject::tr( "FREE_BORDERS" );
1098     else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
1099       type = QObject::tr( "FREE_FACES" );
1100     else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
1101       type = QObject::tr( "BARE_BORDER_VOLUME" );
1102     else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
1103       type = QObject::tr( "BARE_BORDER_FACE" );
1104     else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
1105       type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
1106     else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
1107       type = QObject::tr( "OVER_CONSTRAINED_FACE" );
1108     else if ( dynamic_cast< SMESH::Controls::CoincidentNodes* >( f.get() ) )
1109       type = QObject::tr( "EQUAL_NODE" );
1110     else if ( dynamic_cast< SMESH::Controls::CoincidentElements1D* >( f.get() ) )
1111       type = QObject::tr( "EQUAL_EDGE" );
1112     else if ( dynamic_cast< SMESH::Controls::CoincidentElements2D* >( f.get() ) )
1113       type = QObject::tr( "EQUAL_FACE" );
1114     else if ( dynamic_cast< SMESH::Controls::CoincidentElements3D* >( f.get() ) )
1115       type = QObject::tr( "EQUAL_VOLUME" );
1116     return type;
1117   }
1118
1119   void SaveDistribution()
1120   {
1121     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1122     SALOME_ListIO selected;
1123     if ( aSel )
1124       aSel->selectedObjects( selected );
1125
1126     if ( selected.Extent() == 1 ) {
1127       Handle(SALOME_InteractiveObject) anIO = selected.First();
1128       if ( anIO->hasEntry() ) {
1129         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1130         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1131           SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
1132           SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
1133           if ( aScalarBarActor && aFunctor ) {
1134             SMESH::Controls::NumericalFunctor* aNumFun = dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
1135             if ( aNumFun ) {
1136               std::vector<int> elements;
1137               SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
1138               if ( mesh->_is_nil() ) {
1139                 SMESH::SMESH_IDSource_var idSource =
1140                   SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
1141                 if ( !idSource->_is_nil() )
1142                 {
1143                   SMESH::long_array_var ids = idSource->GetIDs();
1144                   elements.resize( ids->length() );
1145                   for ( unsigned i = 0; i < elements.size(); ++i )
1146                     elements[i] = ids[i];
1147                 }
1148               }
1149               int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
1150               vtkLookupTable* lookupTable =
1151                 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
1152               double * minmax = lookupTable->GetRange();
1153               bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
1154               std::vector<int>    nbEvents;
1155               std::vector<double> funValues;
1156               aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax, isLogarithmic );
1157               QString anInitialPath = "";
1158               if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
1159                 anInitialPath = QDir::currentPath();
1160               QString aMeshName = anIO->getName();
1161               QStringList filter;
1162               filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
1163               filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
1164               QString aFilename = anInitialPath + "/" + aMeshName + "_" + 
1165                 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
1166               aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
1167                                                      aFilename,
1168                                                      filter,
1169                                                      QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
1170                                                      false );
1171               if ( !aFilename.isEmpty() ) {
1172                 QFile f( aFilename );
1173                 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
1174                   QTextStream out( &f );
1175                   out << "# Mesh: " << aMeshName << endl;
1176                   out << "# Control: " << functorToString( aFunctor ) << endl;
1177                   out << "#" << endl;
1178                   out.setFieldWidth( 10 );
1179                   for ( int i = 0; i < (int)qMin( nbEvents.size(), funValues.size()-1 ); i++ )
1180                     out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
1181                   f.close();
1182                 }
1183               }
1184             }
1185           }
1186         }
1187       }
1188     }
1189   }
1190
1191   void ShowElement(int theCommandID ) {
1192     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1193     SALOME_ListIO selected;
1194     if ( aSel )
1195       aSel->selectedObjects( selected );
1196     
1197     if ( selected.Extent() == 1 ) {
1198       Handle(SALOME_InteractiveObject) anIO = selected.First();
1199       if ( anIO->hasEntry() ) {
1200         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1201         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1202           SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
1203           if ( theCommandID == SMESHOp::OpShowDistribution ) {
1204             aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
1205           }
1206           else if ( theCommandID == SMESHOp::OpShowScalarBar ) {
1207             aScalarBarActor->SetVisibility( !aScalarBarActor->GetVisibility());
1208           }
1209         }
1210       }
1211     }
1212   }
1213
1214 #ifndef DISABLE_PLOT2DVIEWER
1215  void PlotDistribution() {
1216    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1217    if( !app )
1218      return;
1219
1220    LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1221    SALOME_ListIO selected;
1222    if ( aSel )
1223      aSel->selectedObjects( selected );
1224     
1225    if ( selected.Extent() == 1 ) {
1226      Handle(SALOME_InteractiveObject) anIO = selected.First();
1227      if ( anIO->hasEntry() ) {
1228        //Find Actor by entry before getting Plot2d viewer,
1229        //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
1230        SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1231
1232        SUIT_ViewManager* aViewManager = app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
1233
1234        if( !aViewManager )
1235          return;
1236        
1237        SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
1238        if ( !aView )
1239          return;
1240
1241        Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1242        if ( !aPlot )
1243          return;
1244
1245        if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone ) {
1246          SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1247          QString functorName = functorToString( anActor->GetFunctor());
1248          QString aHistogramName("%1 : %2");
1249          aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1250          aHistogram->setName(aHistogramName);
1251          aHistogram->setHorTitle(functorName);
1252          aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
1253          aPlot->displayObject(aHistogram, true);
1254        }
1255      }
1256    }
1257  }
1258 #endif //DISABLE_PLOT2DVIEWER
1259
1260   void DisableAutoColor(){
1261     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1262     SALOME_ListIO selected;
1263     if( aSel )
1264       aSel->selectedObjects( selected );
1265
1266     if(selected.Extent()){
1267       Handle(SALOME_InteractiveObject) anIObject = selected.First();
1268       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1269       if ( !aMesh->_is_nil() ) {
1270         aMesh->SetAutoColor( false );
1271       }
1272     }
1273   }
1274
1275   void sortChildren(){
1276     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1277     SALOME_ListIO selected;
1278     if( aSel ) {
1279       aSel->selectedObjects( selected );
1280
1281       if(selected.Extent()){
1282         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1283         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1284         _PTR(SObject) aSObj = aStudy->FindObjectID(anIObject->getEntry());
1285         if (aSObj) {
1286           if ( aStudy->GetUseCaseBuilder()->SortChildren( aSObj, true/*AscendingOrder*/ ) ) {
1287             SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1288           }
1289         }
1290       }
1291     }
1292   }
1293
1294   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap)
1295   {
1296     SALOME_ListIO selected;
1297     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1298     if( !app )
1299       return;
1300
1301     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1302     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1303     if( !aSel || !appStudy )
1304       return;
1305
1306     if( theCommandID == SMESHOp::OpClipping ) { // Clipping dialog can be activated without selection
1307       if( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
1308         aModule->EmitSignalDeactivateDialog();
1309         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
1310           (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
1311       }
1312       return;
1313     }
1314
1315     _PTR(Study) aStudy = appStudy->studyDS();
1316
1317     aSel->selectedObjects( selected );
1318
1319     if(selected.Extent() >= 1){
1320       switch(theCommandID){
1321       case SMESHOp::OpTransparency:{
1322         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1323         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
1324         return;
1325       }
1326       case SMESHOp::OpProperties: {
1327         double color[3];
1328         QColor faceColor, edgeColor, nodeColor, elem0dColor, ballColor;
1329         QColor orientationColor, outlineColor, volumeColor;
1330         int deltaF = 0, deltaV = 0;
1331         int elem0dSize   = 1;
1332         //int ballSize     = 1;
1333         double ballScale = 1.0;
1334         int edgeWidth    = 1;
1335         int outlineWidth = 1;
1336         double shrinkCoef = 0.0;
1337         double orientationScale = 0.0;
1338         bool orientation3d = false;
1339         VTK::MarkerType markerType = VTK::MT_NONE;
1340         VTK::MarkerScale markerScale = VTK::MS_NONE;
1341         int markerId = 0;
1342         bool hasNodes = false;
1343         int presentEntities = 0;
1344         bool firstTime  = true;
1345
1346         SALOME_ListIteratorOfListIO It( selected );
1347         for ( ; It.More(); It.Next() ) {
1348           Handle(SALOME_InteractiveObject) IObject = It.Value();
1349           if ( !IObject->hasEntry() ) continue;
1350           SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1351           if ( !anActor || !anActor->GetObject() ) continue;
1352
1353           if ( firstTime ) {
1354             // nodes: color, marker
1355             anActor->GetNodeColor( color[0], color[1], color[2] );
1356             nodeColor.setRgbF( color[0], color[1], color[2] );
1357             markerType  = anActor->GetMarkerType();
1358             markerScale = anActor->GetMarkerScale();
1359             markerId    = anActor->GetMarkerTexture();
1360             // edges: color, width
1361             anActor->GetEdgeColor( color[0], color[1], color[2] );
1362             edgeColor.setRgbF( color[0], color[1], color[2] );
1363             edgeWidth = qMax( (int)anActor->GetLineWidth(), 1 ); // minimum allowed width is 1
1364             // faces: front color, back color (delta)
1365             anActor->GetSufaceColor( color[0], color[1], color[2], deltaF );
1366             faceColor.setRgbF( color[0], color[1], color[2] );
1367             // faces: front color, back color (delta)
1368             anActor->GetVolumeColor( color[0], color[1], color[2], deltaV );
1369             volumeColor.setRgbF( color[0], color[1], color[2] );
1370             // 0d elements: color, size
1371             anActor->Get0DColor( color[0], color[1], color[2] );
1372             elem0dColor.setRgbF( color[0], color[1], color[2] );
1373             elem0dSize = qMax( (int)anActor->Get0DSize(), 1 ); // minimum allowed size is 1
1374             // balls: color, size
1375             anActor->GetBallColor( color[0], color[1], color[2] );
1376             ballColor.setRgbF( color[0], color[1], color[2] );
1377             //ballSize = qMax( (int)anActor->GetBallSize(), 1 ); // minimum allowed size is 1
1378             ballScale = qMax( (double)anActor->GetBallScale(), 1e-2 ); // minimum allowed scale is 1e-2
1379             // outlines: color
1380             anActor->GetOutlineColor( color[0], color[1], color[2] );
1381             outlineColor.setRgbF( color[0], color[1], color[2] );
1382             outlineWidth = qMax( (int)anActor->GetOutlineWidth(), 1 ); // minimum allowed width is 1
1383             // orientation vectors: color, scale, 3d flag
1384             anActor->GetFacesOrientationColor( color[0], color[1], color[2] );
1385             orientationColor.setRgbF( color[0], color[1], color[2] );
1386             orientationScale = anActor->GetFacesOrientationScale();
1387             orientation3d = anActor->GetFacesOrientation3DVectors();
1388             // shrink factor
1389             shrinkCoef = anActor->GetShrinkFactor();
1390           }
1391
1392           firstTime = false; // we only take properties from first object (for performance reasons)
1393
1394           if ( !hasNodes )
1395             hasNodes = anActor->GetObject()->GetNbEntities( SMDSAbs_Node );
1396           if ( !(presentEntities & SMESH_Actor::eEdges) && anActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) )
1397             presentEntities = presentEntities | SMESH_Actor::eEdges;
1398           if ( !(presentEntities & SMESH_Actor::eFaces) && anActor->GetObject()->GetNbEntities( SMDSAbs_Face ) )
1399             presentEntities = presentEntities | SMESH_Actor::eFaces;
1400           if ( !(presentEntities & SMESH_Actor::eVolumes) && anActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) )
1401             presentEntities = presentEntities | SMESH_Actor::eVolumes;
1402           if ( !(presentEntities & SMESH_Actor::e0DElements) && anActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) )
1403             presentEntities = presentEntities | SMESH_Actor::e0DElements;
1404           if ( !(presentEntities & SMESH_Actor::eBallElem) && anActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) )
1405             presentEntities = presentEntities | SMESH_Actor::eBallElem;
1406           
1407           // as we know that all types of elements are present, we can exit the loop
1408           if ( presentEntities == SMESH_Actor::eAllEntity )
1409             break;
1410         }
1411
1412         SMESHGUI_PropertiesDlg dlg( theMarkerMap[ aStudy->StudyId() ], SMESHGUI::desktop() );
1413         // nodes: color, marker
1414         dlg.setNodeColor( nodeColor );
1415         if( markerType != VTK::MT_USER )
1416           dlg.setNodeMarker( markerType, markerScale );
1417         else
1418           dlg.setNodeCustomMarker( markerId );
1419         // edges: color, line width
1420         dlg.setEdgeColor( edgeColor );
1421         dlg.setEdgeWidth( edgeWidth );
1422         // faces: front color, back color
1423         dlg.setFaceColor( faceColor, deltaF );
1424         // volumes: normal color, reversed color
1425         dlg.setVolumeColor( volumeColor, deltaV );
1426         // outlines: color, line width
1427         dlg.setOutlineColor( outlineColor );
1428         dlg.setOutlineWidth( outlineWidth );
1429         // 0d elements: color, size
1430         dlg.setElem0dColor( elem0dColor );
1431         dlg.setElem0dSize( elem0dSize );
1432         // balls: color, size
1433         dlg.setBallColor( ballColor );
1434         //dlg.setBallSize( ballSize );
1435         dlg.setBallScale( ballScale );
1436         // orientation: color, scale, 3d flag
1437         dlg.setOrientationColor( orientationColor );
1438         dlg.setOrientationSize( int( orientationScale * 100. ) );
1439         dlg.setOrientation3d( orientation3d );
1440         // shrink: scale factor
1441         dlg.setShrinkCoef( int( shrinkCoef * 100. ) );
1442         // hide unused controls
1443         dlg.showControls( presentEntities, hasNodes );
1444         
1445         if ( dlg.exec() ) {
1446           nodeColor        = dlg.nodeColor();
1447           markerType       = dlg.nodeMarkerType();
1448           markerScale      = dlg.nodeMarkerScale();
1449           markerId         = dlg.nodeMarkerId();
1450           edgeColor        = dlg.edgeColor();
1451           edgeWidth        = dlg.edgeWidth();
1452           faceColor        = dlg.faceColor();
1453           deltaF           = dlg.faceColorDelta();
1454           volumeColor      = dlg.volumeColor();
1455           deltaV           = dlg.volumeColorDelta();
1456           outlineColor     = dlg.outlineColor();
1457           outlineWidth     = dlg.outlineWidth();
1458           elem0dColor      = dlg.elem0dColor();
1459           elem0dSize       = dlg.elem0dSize();
1460           ballColor        = dlg.ballColor();
1461          // ballSize         = dlg.ballSize();
1462           ballScale        = dlg.ballScale();
1463           orientationColor = dlg.orientationColor();
1464           orientationScale = dlg.orientationSize() / 100.;
1465           orientation3d    = dlg.orientation3d();
1466           shrinkCoef       = dlg.shrinkCoef() / 100.;
1467
1468           // store point markers map that might be changed by the user
1469           theMarkerMap[ aStudy->StudyId() ] = dlg.customMarkers();
1470
1471           // set properties from dialog box to the presentations
1472           SALOME_ListIteratorOfListIO It( selected );
1473           for ( ; It.More(); It.Next() ) {
1474             Handle(SALOME_InteractiveObject) IObject = It.Value();
1475             if ( !IObject->hasEntry() ) continue;
1476             SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1477             if ( !anActor ) continue;
1478             
1479             // nodes: color, marker
1480             anActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
1481             if ( markerType != VTK::MT_USER ) {
1482               anActor->SetMarkerStd( markerType, markerScale );
1483             }
1484             else {
1485               const VTK::MarkerMap& markerMap = theMarkerMap[ aStudy->StudyId() ];
1486               VTK::MarkerMap::const_iterator iter = markerMap.find( markerId );
1487               if ( iter != markerMap.end() )
1488                 anActor->SetMarkerTexture( markerId, iter->second.second );
1489             }
1490             // volumes: normal color, reversed color (delta)
1491             anActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
1492             // faces: front color, back color (delta)
1493             anActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
1494             // edges: color, width
1495             anActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
1496             anActor->SetLineWidth( edgeWidth );
1497             // outlines: color
1498             anActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
1499             anActor->SetOutlineWidth( outlineWidth );
1500             // 0D elements: color, size
1501             anActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
1502             anActor->Set0DSize( elem0dSize );
1503             // balls: color, size
1504             anActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
1505             // anActor->SetBallSize( ballSize );
1506             anActor->SetBallScale( ballScale );
1507             // orientation: color, scale, 3d flag
1508             anActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
1509             anActor->SetFacesOrientationScale( orientationScale );
1510             anActor->SetFacesOrientation3DVectors( orientation3d );
1511             // shrink factor
1512             anActor->SetShrinkFactor( shrinkCoef );
1513
1514             // for groups, set also proper color
1515             SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1516             if ( !aGroupObject->_is_nil() ) {
1517               SMESH::ElementType anElementType = aGroupObject->GetType();
1518               QColor aColor;
1519               switch( anElementType ) {
1520               case SMESH::NODE:
1521                 aColor = nodeColor; break;
1522               case SMESH::EDGE:
1523                 aColor = edgeColor; break;
1524               case SMESH::FACE: 
1525                 aColor = faceColor; break;
1526               case SMESH::VOLUME:
1527                 aColor = volumeColor; break;
1528               case SMESH::ELEM0D: 
1529                 aColor = elem0dColor; break;
1530               case SMESH::BALL: 
1531                 aColor = ballColor; break;
1532               default: break;
1533               }
1534               
1535               if ( aColor.isValid() ) {
1536                 SALOMEDS::Color aGroupColor;
1537                 aGroupColor.R = aColor.redF();
1538                 aGroupColor.G = aColor.greenF();
1539                 aGroupColor.B = aColor.blueF();
1540                 aGroupObject->SetColor( aGroupColor );
1541               }
1542             } // if ( !aGroupObject->_is_nil() )
1543           } // for ( ; It.More(); It.Next() )
1544           SMESH::RepaintCurrentView();
1545         } // if ( dlg.exec() )
1546         return;
1547       } // case SMESHOp::OpProperties:
1548       } // switch(theCommandID)
1549       SALOME_ListIteratorOfListIO It( selected );
1550       for( ; It.More(); It.Next()){
1551         Handle(SALOME_InteractiveObject) IObject = It.Value();
1552         if(IObject->hasEntry()){
1553           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1554             switch(theCommandID){
1555             case SMESHOp::OpDMWireframe:
1556               anActor->SetRepresentation(SMESH_Actor::eEdge);
1557               break;
1558             case SMESHOp::OpDMShading:
1559               anActor->SetRepresentation(SMESH_Actor::eSurface);
1560               break;
1561             case SMESHOp::OpDMShrink:
1562               if(anActor->IsShrunk())
1563                 anActor->UnShrink();
1564               else
1565                 anActor->SetShrink();
1566               break;
1567             case SMESHOp::OpDMNodes:
1568               anActor->SetRepresentation(SMESH_Actor::ePoint);
1569               break;
1570             case SMESHOp::OpRepresentationLines:
1571               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1572                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1573               break;
1574             case SMESHOp::OpRepresentationArcs:
1575               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1576                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1577               break;
1578             }
1579           }
1580         }
1581       }
1582       SMESH::RepaintCurrentView();
1583     }
1584   }
1585
1586   int ActionToControl( int theID, bool theReversed )
1587   {
1588     NCollection_DoubleMap<int,int> ActionControl;
1589     ActionControl.Bind( 0,                                SMESH_Actor::eNone );
1590     ActionControl.Bind( SMESHOp::OpFreeNode,              SMESH_Actor::eFreeNodes );
1591     ActionControl.Bind( SMESHOp::OpEqualNode,             SMESH_Actor::eCoincidentNodes );
1592     ActionControl.Bind( SMESHOp::OpFreeEdge,              SMESH_Actor::eFreeEdges );
1593     ActionControl.Bind( SMESHOp::OpFreeBorder,            SMESH_Actor::eFreeBorders );
1594     ActionControl.Bind( SMESHOp::OpLength,                SMESH_Actor::eLength );
1595     ActionControl.Bind( SMESHOp::OpConnection,            SMESH_Actor::eMultiConnection );
1596     ActionControl.Bind( SMESHOp::OpEqualEdge,             SMESH_Actor::eCoincidentElems1D );
1597     ActionControl.Bind( SMESHOp::OpFreeFace,              SMESH_Actor::eFreeFaces );
1598     ActionControl.Bind( SMESHOp::OpBareBorderFace,        SMESH_Actor::eBareBorderFace );
1599     ActionControl.Bind( SMESHOp::OpOverConstrainedFace,   SMESH_Actor::eOverConstrainedFace );
1600     ActionControl.Bind( SMESHOp::OpLength2D,              SMESH_Actor::eLength2D );
1601     ActionControl.Bind( SMESHOp::OpConnection2D,          SMESH_Actor::eMultiConnection2D );
1602     ActionControl.Bind( SMESHOp::OpArea,                  SMESH_Actor::eArea );
1603     ActionControl.Bind( SMESHOp::OpTaper,                 SMESH_Actor::eTaper );
1604     ActionControl.Bind( SMESHOp::OpAspectRatio,           SMESH_Actor::eAspectRatio );
1605     ActionControl.Bind( SMESHOp::OpMinimumAngle,          SMESH_Actor::eMinimumAngle );
1606     ActionControl.Bind( SMESHOp::OpWarpingAngle,          SMESH_Actor::eWarping );
1607     ActionControl.Bind( SMESHOp::OpSkew,                  SMESH_Actor::eSkew );
1608     ActionControl.Bind( SMESHOp::OpMaxElementLength2D,    SMESH_Actor::eMaxElementLength2D );
1609     ActionControl.Bind( SMESHOp::OpEqualFace,             SMESH_Actor::eCoincidentElems2D );
1610     ActionControl.Bind( SMESHOp::OpAspectRatio3D,         SMESH_Actor::eAspectRatio3D );
1611     ActionControl.Bind( SMESHOp::OpVolume,                SMESH_Actor::eVolume3D );
1612     ActionControl.Bind( SMESHOp::OpMaxElementLength3D,    SMESH_Actor::eMaxElementLength3D );
1613     ActionControl.Bind( SMESHOp::OpBareBorderVolume,      SMESH_Actor::eBareBorderVolume );
1614     ActionControl.Bind( SMESHOp::OpOverConstrainedVolume, SMESH_Actor::eOverConstrainedVolume );
1615     ActionControl.Bind( SMESHOp::OpEqualVolume,           SMESH_Actor::eCoincidentElems3D );
1616
1617     return theReversed ? ActionControl.Find2( theID ) : ActionControl.Find1( theID );
1618   }
1619
1620   void Control( int theCommandID )
1621   {
1622     SMESH_Actor::eControl aControl = SMESH_Actor::eControl( ActionToControl( theCommandID ) );
1623     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1624     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1625     SALOME_ListIO selected;
1626     if( aSel )
1627       aSel->selectedObjects( selected );
1628
1629     if( !selected.IsEmpty() ){
1630       SALOME_ListIteratorOfListIO It(selected);
1631       for ( ; It.More(); It.Next())
1632       {
1633         Handle(SALOME_InteractiveObject) anIO = It.Value();
1634         if(!anIO.IsNull()){
1635           _PTR(SObject) SO = aStudy->FindObjectID( It.Value()->getEntry() );
1636           if ( SO ) {
1637             CORBA::Object_var           aObject = SMESH::SObjectToObject( SO );
1638             SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
1639             SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
1640             SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
1641             if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
1642               if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())) {
1643                 anActor->SetControlMode(aControl);
1644                 anActor->GetScalarBarActor()->SetTitle( functorToString( anActor->GetFunctor() ).toLatin1().constData() );
1645                 SMESH::RepaintCurrentView();
1646 #ifndef DISABLE_PLOT2DVIEWER
1647                 if(anActor->GetPlot2Histogram()) {
1648                   SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1649                   QString functorName = functorToString( anActor->GetFunctor());
1650                   QString aHistogramName("%1 : %2");
1651                   aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1652                   aHistogram->setName(aHistogramName);
1653                   aHistogram->setHorTitle(functorName);
1654                   SMESH::ProcessIn2DViewers(anActor);
1655                 }
1656 #endif
1657               }
1658             }
1659           }
1660         }
1661       }
1662     }
1663   }
1664
1665
1666   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1667                    SMESH::MeshObjectType                           theType,
1668                    const QString                            theInTypeName,
1669                    QString &                                theOutTypeName)
1670   {
1671     SMESH_TypeFilter aTypeFilter( theType );
1672     QString entry;
1673     if( !theIO.IsNull() )
1674     {
1675       entry = theIO->getEntry();
1676       LightApp_DataOwner owner( entry );
1677       if ( aTypeFilter.isOk( &owner )) {
1678         theOutTypeName = theInTypeName;
1679         return true;
1680       }
1681     }
1682     return false;
1683   }
1684
1685
1686   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1687   {
1688     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1689     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1690     if (aSObj) {
1691       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1692       CORBA::String_var anID = aSComp->GetID().c_str();
1693       if (!strcmp(anID.in(),theIO->getEntry()))
1694         return "Component";
1695     }
1696
1697     QString aTypeName;
1698     if (
1699         CheckOIType ( theIO, SMESH::HYPOTHESIS,    "Hypothesis", aTypeName ) ||
1700         CheckOIType ( theIO, SMESH::ALGORITHM,     "Algorithm",  aTypeName ) ||
1701         CheckOIType ( theIO, SMESH::MESH,          "Mesh",       aTypeName ) ||
1702         CheckOIType ( theIO, SMESH::SUBMESH,       "SubMesh",    aTypeName ) ||
1703         CheckOIType ( theIO, SMESH::GROUP,         "Group",      aTypeName )
1704         )
1705       return aTypeName;
1706
1707     return "NoType";
1708   }
1709
1710
1711   QString CheckHomogeneousSelection()
1712   {
1713     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
1714     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1715     SALOME_ListIO selected;
1716     if( aSel )
1717       aSel->selectedObjects( selected );
1718
1719     QString RefType = CheckTypeObject(selected.First());
1720     SALOME_ListIteratorOfListIO It(selected);
1721     for ( ; It.More(); It.Next())
1722     {
1723       Handle(SALOME_InteractiveObject) IObject = It.Value();
1724       QString Type = CheckTypeObject(IObject);
1725       if (Type.compare(RefType) != 0)
1726         return "Heterogeneous Selection";
1727     }
1728
1729     return RefType;
1730   }
1731
1732   uint randomize( uint size )
1733   {
1734     static bool initialized = false;
1735     if ( !initialized ) {
1736       qsrand( QDateTime::currentDateTime().toTime_t() );
1737       initialized = true;
1738     }
1739     uint v = qrand();
1740     v = uint( (double)( v ) / RAND_MAX * size );
1741     v = qMax( uint(0), qMin ( v, size-1 ) );
1742     return v;
1743   }
1744   
1745 } //namespace
1746
1747 void SMESHGUI::OnEditDelete()
1748 {
1749   // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1750   LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1751   SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1752
1753   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1754   _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1755   _PTR(GenericAttribute) anAttr;
1756   _PTR(AttributeIOR) anIOR;
1757
1758   int objectCount = 0;
1759   QString aNameList;
1760   QString aParentComponent = QString::null;
1761   Handle(SALOME_InteractiveObject) anIO;
1762   for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1763   {
1764     anIO = anIt.Value();
1765     QString cur = anIO->getComponentDataType();
1766     _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
1767     if (aSO) {
1768       // check if object is reference
1769       _PTR(SObject) aRefSObj;
1770       aNameList.append("\n    - ");
1771       if ( aSO->ReferencedObject( aRefSObj ) ) {
1772         QString aRefName = QString::fromStdString ( aRefSObj->GetName() );
1773         aNameList.append( aRefName );
1774         cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1775       }
1776       else
1777         aNameList.append(anIO->getName());
1778       objectCount++;
1779     }
1780
1781     if( aParentComponent.isNull() )
1782       aParentComponent = cur;
1783     else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
1784       aParentComponent = "";
1785   }
1786
1787   if ( objectCount == 0 )
1788     return; // No Valid Objects Selected
1789
1790   if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
1791     SUIT_MessageBox::warning( SMESHGUI::desktop(),
1792                               QObject::tr("ERR_ERROR"),
1793                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1794     return;
1795   }
1796   // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1797   if (SUIT_MessageBox::warning
1798       (SMESHGUI::desktop(),
1799        QObject::tr("SMESH_WRN_WARNING"),
1800        QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1801        SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1802        SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1803     return;
1804
1805   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1806
1807   // Put the whole hierarchy of sub-objects of the selected SO's into a list and
1808   // then treat them all starting from the deepest objects (at list back)
1809   std::list< _PTR(SObject) > listSO;
1810   SALOME_ListIteratorOfListIO It(selected);
1811   for( ; It.More(); It.Next()) // loop on selected IO's
1812   {
1813     Handle(SALOME_InteractiveObject) IObject = It.Value();
1814     if(IObject->hasEntry()) {
1815       _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1816
1817       // disable removal of "SMESH" component object
1818       if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1819         anIOR = anAttr;
1820         if ( engineIOR() == anIOR->Value().c_str() )
1821           continue;
1822       }
1823       //Check the referenced object
1824       _PTR(SObject) aRefSObject;
1825       if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1826         aSO = aRefSObject; // Delete main Object instead of reference
1827
1828       listSO.push_back( aSO );
1829       std::list< _PTR(SObject) >::iterator itSO = --listSO.end();
1830       for ( ; itSO != listSO.end(); ++itSO ) {
1831         _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1832         for (it->InitEx(false); it->More(); it->Next())
1833           listSO.push_back( it->Value() );
1834       }
1835     }
1836   }
1837   // Check if none of objects to delete is referred from outside
1838   std::list< _PTR(SObject) >::reverse_iterator ritSO;
1839   for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1840   {
1841     _PTR(SObject) SO = *ritSO;
1842     if ( !SO ) continue;
1843     std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( *ritSO  );
1844     for (size_t i = 0; i < aReferences.size(); i++) {
1845       _PTR(SComponent) aComponent = aReferences[i]->GetFatherComponent();
1846       std::string type = aComponent->ComponentDataType();
1847       if ( type != "SMESH" )
1848       {
1849         SUIT_MessageBox::warning( anApp->desktop(),
1850                                   QObject::tr("WRN_WARNING"),
1851                                   QObject::tr("DEP_OBJECT") );
1852         return; // outside SMESH, there is an object depending on a SMESH object
1853       }
1854     }
1855   }
1856
1857   // Call mesh->Clear() to prevent loading mesh from file caused by hypotheses removal
1858   for( It.Initialize( selected ); It.More(); It.Next()) // loop on selected IO's
1859   {
1860     Handle(SALOME_InteractiveObject) IObject = It.Value();
1861     SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface< SMESH::SMESH_Mesh >( IObject );
1862     if ( !mesh->_is_nil() )
1863       mesh->Clear();
1864   }
1865
1866   // Treat SO's in the list starting from the back
1867   aStudyBuilder->NewCommand();  // There is a transaction
1868   for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1869   {
1870     _PTR(SObject) SO = *ritSO;
1871     if ( !SO ) continue;
1872     std::string anEntry = SO->GetID();
1873
1874     /** Erase graphical object and remove all its data **/
1875     if(SO->FindAttribute(anAttr, "AttributeIOR")) {
1876       SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true);
1877     }
1878     /** Remove an object from data structures **/
1879     SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1880     SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1881     if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
1882       SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1883       aMesh->RemoveGroup( aGroup );
1884     }
1885     else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
1886       SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1887       aMesh->RemoveSubMesh( aSubMesh );
1888
1889       _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1890       if (aMeshSO)
1891         SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1892     }
1893     else {
1894       Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject
1895         ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1896       QString objType = CheckTypeObject(IObject);
1897       if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1898         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1899         aStudyBuilder->RemoveObjectWithChildren( SO );
1900       }
1901       else {// default action: remove SObject from the study
1902         // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1903         //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1904         //op->start();
1905         aStudyBuilder->RemoveObjectWithChildren( SO );
1906         //op->finish();
1907       }
1908     }
1909   } /* listSO back loop */
1910
1911   aStudyBuilder->CommitCommand();
1912
1913   /* Clear any previous selection */
1914   SALOME_ListIO l1;
1915   aSel->setSelectedObjects( l1 );
1916
1917   SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1918 }
1919
1920 extern "C" {
1921   SMESHGUI_EXPORT CAM_Module* createModule()
1922   {
1923     return new SMESHGUI();
1924   }
1925
1926   SMESHGUI_EXPORT  char* getModuleVersion() {
1927     return (char*)SMESH_VERSION_STR;
1928   }
1929 }
1930
1931 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1932
1933 //=============================================================================
1934 /*!
1935  *
1936  */
1937 //=============================================================================
1938 SMESHGUI::SMESHGUI() :
1939 SalomeApp_Module( "SMESH" )
1940 {
1941   if ( CORBA::is_nil( myComponentSMESH ) )
1942   {
1943     CORBA::Boolean anIsEmbeddedMode;
1944     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1945     MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
1946
1947     //  0019923: EDF 765 SMESH : default values of hypothesis
1948     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
1949     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
1950     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
1951     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
1952     myComponentSMESH->SetDefaultNbSegments( nbSeg );
1953
1954     const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif" };
1955     for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
1956       if ( aResourceMgr->hasValue( "SMESH", options[i] ))
1957       {
1958         QString val = aResourceMgr->stringValue( "SMESH", options[i] );
1959         myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
1960       }
1961   }
1962
1963   myActiveDialogBox = 0;
1964   myFilterLibraryDlg = 0;
1965   myState = -1;
1966   myDisplayer = 0;
1967
1968   myEventCallbackCommand = vtkCallbackCommand::New();
1969   myEventCallbackCommand->Delete();
1970   myEventCallbackCommand->SetClientData( this );
1971   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
1972   myPriority = 0.0;
1973
1974   /* load resources for all available meshers */
1975   SMESH::InitAvailableHypotheses();
1976 }
1977
1978 //=============================================================================
1979 /*!
1980  *
1981  */
1982 //=============================================================================
1983 SMESHGUI::~SMESHGUI()
1984 {
1985 }
1986
1987 //=============================================================================
1988 /*!
1989  *
1990  */
1991 //=============================================================================
1992 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1993 {
1994   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1995   if( anApp )
1996     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1997   else
1998     return 0;
1999 }
2000
2001 //=============================================================================
2002 /*!
2003  *
2004  */
2005 //=============================================================================
2006 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
2007 {
2008   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2009   if ( !resMgr )
2010     return false;
2011
2012   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
2013   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2014   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2015   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2016   return autoUpdate && !exceeded;
2017 }
2018
2019 //=============================================================================
2020 /*!
2021  *
2022  */
2023 //=============================================================================
2024 bool SMESHGUI::automaticUpdate( SMESH::SMESH_IDSource_ptr theMesh,
2025                                 int* entities, bool* limitExceeded, int* hidden, long* nbElements )
2026 {
2027   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2028   if ( !resMgr )
2029     return false;
2030
2031   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update", false );
2032   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2033   bool incrementalLimit = resMgr->booleanValue( "SMESH", "incremental_limit", false );
2034
2035   SMESH::long_array_var info = theMesh->GetMeshInfo();
2036   long nbOdElems = info[SMDSEntity_0D];
2037   long nbEdges   = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
2038   long nbFaces   = info[SMDSEntity_Triangle]   + info[SMDSEntity_Quad_Triangle]   + info[SMDSEntity_BiQuad_Triangle] + 
2039                    info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle] + info[SMDSEntity_BiQuad_Quadrangle] + 
2040                    info[SMDSEntity_Polygon] + info[SMDSEntity_Quad_Polygon];
2041   long nbVolumes = info[SMDSEntity_Tetra]   + info[SMDSEntity_Quad_Tetra] + 
2042                    info[SMDSEntity_Hexa]    + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_TriQuad_Hexa] + 
2043                    info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid] + 
2044                    info[SMDSEntity_Penta]   + info[SMDSEntity_Quad_Penta] + 
2045                    info[SMDSEntity_Polyhedra] + 
2046                    info[SMDSEntity_Hexagonal_Prism];
2047   long nbBalls   = info[SMDSEntity_Ball];
2048
2049   long requestedSize = nbOdElems + nbBalls + nbEdges + nbFaces + nbVolumes;
2050   *nbElements = requestedSize;
2051   
2052   *entities = SMESH_Actor::eAllEntity;
2053   *hidden   = 0;
2054
2055   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2056
2057   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2058
2059   if ( incrementalLimit ) {
2060     long total     = 0;
2061
2062     if ( nbOdElems > 0 ) {
2063       if ( total + nbOdElems > updateLimit ) {
2064         *entities = *entities & ~SMESH_Actor::e0DElements;
2065         *hidden = *hidden | SMESH_Actor::e0DElements;
2066       }
2067       else
2068         exceeded = false;
2069     }
2070     total += nbOdElems;
2071
2072     if ( nbEdges > 0 ) {
2073       if ( total + nbEdges > updateLimit ) {
2074         *entities = *entities & ~SMESH_Actor::eEdges;
2075         *hidden = *hidden | SMESH_Actor::eEdges;
2076       }
2077       else
2078         exceeded = false;
2079     }
2080     total += nbEdges;
2081
2082     if ( nbFaces > 0 ) {
2083       if ( total + nbFaces > updateLimit ) {
2084         *entities = *entities & ~SMESH_Actor::eFaces;
2085         *hidden = *hidden | SMESH_Actor::eFaces;
2086       }
2087       else
2088         exceeded = false;
2089     }
2090     total += nbFaces;
2091
2092     if ( nbVolumes > 0 ) {
2093       if ( total + nbVolumes > updateLimit ) {
2094         *entities = *entities & ~SMESH_Actor::eVolumes;
2095         *hidden = *hidden | SMESH_Actor::eVolumes;
2096       }
2097       else
2098         exceeded = false;
2099     }
2100     total += nbVolumes;
2101
2102     if ( nbBalls > 0 ) {
2103       if ( total + nbBalls > updateLimit ) {
2104         *entities = *entities & ~SMESH_Actor::eBallElem;
2105         *hidden = *hidden | SMESH_Actor::eBallElem;
2106       }
2107       else
2108         exceeded = false;
2109     }
2110     total += nbBalls;
2111   }
2112
2113   return autoUpdate && !exceeded;
2114 }
2115
2116 //=============================================================================
2117 /*!
2118  *
2119  */
2120 //=============================================================================
2121 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
2122 {
2123   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
2124 }
2125
2126 //=============================================================================
2127 /*!
2128  *
2129  */
2130 //=============================================================================
2131 SMESHGUI* SMESHGUI::GetSMESHGUI()
2132 {
2133   SMESHGUI* smeshMod = 0;
2134   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
2135   if ( app )
2136   {
2137     CAM_Module* module = app->module( "Mesh" );
2138     smeshMod = dynamic_cast<SMESHGUI*>( module );
2139   }
2140
2141   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
2142   {
2143     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
2144     if ( study )
2145     {
2146       _PTR(Study) aStudy = study->studyDS();
2147       if ( aStudy )
2148         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
2149     }
2150   }
2151
2152   return smeshMod;
2153 }
2154
2155 extern "C"
2156 {
2157   Standard_EXPORT SMESHGUI* GetComponentGUI()
2158   {
2159     return SMESHGUI::GetSMESHGUI();
2160   }
2161 }
2162
2163 //=============================================================================
2164 /*!
2165  *
2166  */
2167 //=============================================================================
2168 void SMESHGUI::SetState(int aState)
2169 {
2170   myState = aState;
2171 }
2172
2173 //=============================================================================
2174 /*!
2175  *
2176  */
2177 //=============================================================================
2178 void SMESHGUI::ResetState()
2179 {
2180   myState = -1;
2181 }
2182
2183 //=============================================================================
2184 /*!
2185  *
2186  */
2187 //=============================================================================
2188 void SMESHGUI::EmitSignalDeactivateDialog()
2189 {
2190   emit SignalDeactivateActiveDialog();
2191 }
2192
2193 //=============================================================================
2194 /*!
2195  *
2196  */
2197 //=============================================================================
2198 void SMESHGUI::EmitSignalStudyFrameChanged()
2199 {
2200   emit SignalStudyFrameChanged();
2201 }
2202
2203 //=============================================================================
2204 /*!
2205  *
2206  */
2207 //=============================================================================
2208 void SMESHGUI::EmitSignalCloseAllDialogs()
2209 {
2210   emit SignalCloseAllDialogs();
2211 }
2212
2213 //=============================================================================
2214 /*!
2215  *
2216  */
2217 //=============================================================================
2218 void SMESHGUI::EmitSignalVisibilityChanged()
2219 {
2220   emit SignalVisibilityChanged();
2221 }
2222
2223 //=============================================================================
2224 /*!
2225  *
2226  */
2227 //=============================================================================
2228 void SMESHGUI::EmitSignalCloseView()
2229 {
2230   emit SignalCloseView();
2231 }
2232
2233 //=============================================================================
2234 /*!
2235  *
2236  */
2237 //=============================================================================
2238 void SMESHGUI::EmitSignalActivatedViewManager()
2239 {
2240   emit SignalActivatedViewManager();
2241 }
2242
2243 //=============================================================================
2244 /*!
2245  *
2246  */
2247 //=============================================================================
2248 QDialog *SMESHGUI::GetActiveDialogBox()
2249 {
2250   return myActiveDialogBox;
2251 }
2252
2253 //=============================================================================
2254 /*!
2255  *
2256  */
2257 //=============================================================================
2258 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2259 {
2260   myActiveDialogBox = (QDialog *) aDlg;
2261   return;
2262 }
2263
2264 //=============================================================================
2265 /*!
2266  *
2267  */
2268 //=============================================================================
2269 SUIT_Desktop* SMESHGUI::desktop()
2270 {
2271   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2272   if( app )
2273     return app->desktop();
2274   else
2275     return 0;
2276 }
2277
2278 //=============================================================================
2279 /*!
2280  *
2281  */
2282 //=============================================================================
2283 SalomeApp_Study* SMESHGUI::activeStudy()
2284 {
2285   SUIT_Application* app = SUIT_Session::session()->activeApplication();
2286   if( app )
2287     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2288   else
2289     return NULL;
2290 }
2291
2292 //=============================================================================
2293 /*!
2294  *
2295  */
2296 //=============================================================================
2297 void SMESHGUI::Modified( bool theIsUpdateActions )
2298 {
2299   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2300     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2301       appStudy->Modified();
2302       if( theIsUpdateActions )
2303         app->updateActions();
2304     }
2305   }
2306 }
2307
2308 //=============================================================================
2309 /*!
2310  *
2311  */
2312 //=============================================================================
2313 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2314 {
2315   /* Here the position is on the bottom right corner - 10 */
2316   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2317   aDlg->adjustSize();
2318   SUIT_Desktop *PP = desktop();
2319   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2320   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2321   return true;
2322 }
2323
2324 //=============================================================================
2325 /*!
2326  *
2327  */
2328 //=============================================================================
2329 static int isStudyLocked(_PTR(Study) theStudy){
2330   return theStudy->GetProperties()->IsLocked();
2331 }
2332
2333 static bool checkLock(_PTR(Study) theStudy) {
2334   if (isStudyLocked(theStudy)) {
2335     SUIT_MessageBox::warning( SMESHGUI::desktop(),
2336                               QObject::tr("WRN_WARNING"),
2337                               QObject::tr("WRN_STUDY_LOCKED") );
2338     return true;
2339   }
2340   return false;
2341 }
2342
2343 //=======================================================================
2344 //function : CheckActiveStudyLocked
2345 //purpose  :
2346 //=======================================================================
2347
2348 bool SMESHGUI::isActiveStudyLocked()
2349 {
2350   _PTR(Study) aStudy = activeStudy()->studyDS();
2351   return checkLock( aStudy );
2352 }
2353
2354 //=============================================================================
2355 /*!
2356  *
2357  */
2358 //=============================================================================
2359 bool SMESHGUI::OnGUIEvent( int theCommandID )
2360 {
2361   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2362   if( !anApp )
2363     return false;
2364
2365   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2366   SUIT_ResourceMgr* mgr = resourceMgr();
2367   if( !mgr )
2368     return false;
2369
2370   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
2371     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2372   }
2373
2374   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2375   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2376
2377   //QAction* act = action( theCommandID );
2378
2379   switch (theCommandID) {
2380   case SMESHOp::OpDelete:
2381     if(checkLock(aStudy)) break;
2382     OnEditDelete();
2383     break;
2384   case SMESHOp::OpImportDAT:
2385   case SMESHOp::OpImportUNV:
2386   case SMESHOp::OpImportMED:
2387   case SMESHOp::OpImportSTL:
2388 #ifdef WITH_CGNS
2389   case SMESHOp::OpImportCGNS:
2390 #endif
2391   case SMESHOp::OpImportSAUV:
2392   case SMESHOp::OpImportGMF:
2393     {
2394       if(checkLock(aStudy)) break;
2395       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2396       break;
2397     }
2398
2399   case SMESHOp::OpFileInformation:
2400     {
2401       SALOME_ListIO selected;
2402       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2403       if( aSel )
2404         aSel->selectedObjects( selected );
2405       if( selected.Extent() )
2406       {
2407         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2408         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2409         if ( !aMesh->_is_nil() )
2410         {
2411           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2412           dlg.exec();
2413         }
2414       }
2415       break;
2416     }
2417   case SMESHOp::OpExportDAT:
2418   case SMESHOp::OpExportMED:
2419   case SMESHOp::OpExportUNV:
2420   case SMESHOp::OpExportSTL:
2421 #ifdef WITH_CGNS
2422   case SMESHOp::OpExportCGNS:
2423 #endif
2424   case SMESHOp::OpExportSAUV:
2425   case SMESHOp::OpExportGMF:
2426   case SMESHOp::OpPopupExportDAT:
2427   case SMESHOp::OpPopupExportMED:
2428   case SMESHOp::OpPopupExportUNV:
2429   case SMESHOp::OpPopupExportSTL:
2430 #ifdef WITH_CGNS
2431   case SMESHOp::OpPopupExportCGNS:
2432 #endif
2433   case SMESHOp::OpPopupExportSAUV:
2434   case SMESHOp::OpPopupExportGMF:
2435     {
2436       ::ExportMeshToFile(theCommandID);
2437       break;
2438     }
2439
2440   case SMESHOp::OpReset:                      // SCALAR BAR
2441     {
2442       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2443       SALOME_ListIO selected;
2444       if( aSel )
2445         aSel->selectedObjects( selected );
2446
2447       SALOME_ListIteratorOfListIO it(selected);
2448       for( ; it.More(); it.Next()) {
2449         Handle(SALOME_InteractiveObject) anIO = it.Value();
2450         if( anIO->hasEntry() ) {
2451           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2452             anActor->SetControlMode( SMESH_Actor::eNone );
2453 #ifndef DISABLE_PLOT2DVIEWER
2454             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2455 #endif
2456           }
2457         }
2458       }
2459       SMESH::UpdateView();
2460       break;
2461     }
2462   case SMESHOp::OpScalarBarProperties:
2463     {
2464       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2465       break;
2466     }
2467   case SMESHOp::OpShowScalarBar:
2468     {
2469       // show/hide scalar bar
2470       ::ShowElement(theCommandID);
2471       break;
2472     }
2473   case SMESHOp::OpSaveDistribution:
2474     {
2475       // dump control distribution data to the text file
2476       ::SaveDistribution();
2477       break;
2478     }
2479
2480   case SMESHOp::OpShowDistribution:
2481     {
2482       // show/hide distribution
2483       ::ShowElement(theCommandID);
2484       break;
2485     }
2486
2487 #ifndef DISABLE_PLOT2DVIEWER
2488   case SMESHOp::OpPlotDistribution:
2489     {
2490       // plot distribution
2491       ::PlotDistribution();
2492       break;
2493     }
2494 #endif
2495
2496     // Auto-color
2497   case SMESHOp::OpAutoColor:
2498     ::AutoColor();
2499   break;
2500
2501   case SMESHOp::OpDisableAutoColor:
2502     ::DisableAutoColor();
2503   break;
2504
2505   case SMESHOp::OpClipping:
2506   case SMESHOp::OpTransparency:
2507   case SMESHOp::OpProperties: // Display preferences (colors, shrink size, line width, ...)
2508
2509     // Display Mode
2510   case SMESHOp::OpDMWireframe:
2511   case SMESHOp::OpDMShading:
2512   case SMESHOp::OpDMNodes:
2513   case SMESHOp::OpDMShrink:
2514     ::SetDisplayMode(theCommandID, myMarkerMap);
2515   break;
2516
2517   //2D quadratic representation
2518   case SMESHOp::OpRepresentationLines:
2519   case SMESHOp::OpRepresentationArcs:
2520     ::SetDisplayMode(theCommandID, myMarkerMap);
2521   break;
2522
2523   // Display Entity
2524   case SMESHOp::OpDE0DElements:
2525   case SMESHOp::OpDEEdges:
2526   case SMESHOp::OpDEFaces:
2527   case SMESHOp::OpDEVolumes:
2528   case SMESHOp::OpDEBalls:
2529   case SMESHOp::OpDEAllEntity:
2530     ::SetDisplayEntity(theCommandID);
2531   break;
2532
2533   // Choose entities to be displayed
2534   case SMESHOp::OpDEChoose:
2535     {
2536       ( new SMESHGUI_DisplayEntitiesDlg( SMESHGUI::desktop() ) )->exec();
2537       break;
2538     }
2539
2540   case SMESHOp::OpOrientationOnFaces:
2541     {
2542       LightApp_SelectionMgr* mgr = selectionMgr();
2543       SALOME_ListIO selected; mgr->selectedObjects( selected );
2544
2545       SALOME_ListIteratorOfListIO it(selected);
2546       for( ; it.More(); it.Next()) {
2547         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2548         if(anIObject->hasEntry()) {
2549           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2550             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2551           }
2552         }
2553       }
2554       break;
2555     }
2556
2557   case SMESHOp::OpUpdate:
2558     {
2559       if(checkLock(aStudy)) break;
2560       SUIT_OverrideCursor wc;
2561       try {
2562 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2563         OCC_CATCH_SIGNALS;
2564 #endif
2565         SMESH::UpdateView();
2566       }
2567       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2568         SMESH::OnVisuException();
2569       }
2570       catch (...) { // PAL16774 (Crash after display of many groups)
2571         SMESH::OnVisuException();
2572       }
2573
2574       SALOME_ListIO l;
2575       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2576       aSel->selectedObjects( l );
2577       aSel->setSelectedObjects( l );
2578       break;
2579     }
2580
2581   case SMESHOp::OpHide:
2582   case SMESHOp::OpShow:
2583   case SMESHOp::OpShowOnly:
2584     {
2585       SMESH::EDisplaing anAction;
2586       switch (theCommandID) {
2587       case SMESHOp::OpHide:     anAction = SMESH::eErase; break;
2588       case SMESHOp::OpShow:     anAction = SMESH::eDisplay; break;
2589       case SMESHOp::OpShowOnly: anAction = SMESH::eDisplayOnly; break;
2590       }
2591
2592       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2593       SALOME_ListIO sel_objects, to_process;
2594       if (aSel)
2595         aSel->selectedObjects( sel_objects );
2596
2597       if ( theCommandID==SMESHOp::OpShowOnly )
2598       {
2599         MESSAGE("anAction = SMESH::eDisplayOnly");
2600         startOperation( myEraseAll );
2601       }
2602
2603       extractContainers( sel_objects, to_process );
2604
2605       try {
2606 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2607         OCC_CATCH_SIGNALS;
2608 #endif
2609         if (vtkwnd) {
2610           SALOME_ListIteratorOfListIO It( to_process );
2611           for ( ; It.More(); It.Next())
2612           {
2613             Handle(SALOME_InteractiveObject) IOS = It.Value();
2614             if ( IOS->hasEntry() )
2615             {
2616               if ( !SMESH::UpdateView( anAction, IOS->getEntry() )) {
2617                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2618                 break; // PAL16774 (Crash after display of many groups)
2619               }
2620               if (anAction == SMESH::eDisplayOnly)
2621                 anAction = SMESH::eDisplay;
2622             }
2623           }
2624         }
2625
2626         // PAL13338 + PAL15161 -->
2627         if ( ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) && !checkLock(aStudy)) {
2628           MESSAGE("anAction = SMESH::eDisplayOnly");
2629           SMESH::UpdateView();
2630           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2631         }
2632         // PAL13338 + PAL15161 <--
2633       }
2634       catch (...) { // PAL16774 (Crash after display of many groups)
2635         SMESH::OnVisuException();
2636       }
2637
2638       if (anAction == SMESH::eErase) {
2639         MESSAGE("anAction == SMESH::eErase");
2640         SALOME_ListIO l1;
2641         aSel->setSelectedObjects( l1 );
2642       }
2643       else
2644         aSel->setSelectedObjects( to_process );
2645
2646       break;
2647     }
2648
2649   case SMESHOp::OpNode:
2650     {
2651       if(checkLock(aStudy)) break;
2652
2653       if ( vtkwnd ) {
2654         EmitSignalDeactivateDialog();
2655
2656         ( new SMESHGUI_NodesDlg( this ) )->show();
2657       }
2658       else {
2659         SUIT_MessageBox::warning(desktop(),
2660                                  tr("SMESH_WRN_WARNING"),
2661                                  tr("SMESH_WRN_VIEWER_VTK"));
2662       }
2663       break;
2664     }
2665
2666   case SMESHOp::OpCreateMesh:
2667   case SMESHOp::OpCreateSubMesh:
2668   case SMESHOp::OpEditMeshOrSubMesh:
2669   case SMESHOp::OpCompute:
2670   case SMESHOp::OpPreCompute:
2671   case SMESHOp::OpEvaluate:
2672   case SMESHOp::OpMeshOrder:
2673     startOperation( theCommandID );
2674     break;
2675   case SMESHOp::OpCopyMesh:
2676     {
2677       if (checkLock(aStudy)) break;
2678       EmitSignalDeactivateDialog();
2679       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2680     }
2681     break;
2682   case SMESHOp::OpBuildCompoundMesh:
2683     {
2684       if (checkLock(aStudy)) break;
2685       EmitSignalDeactivateDialog();
2686       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2687     }
2688     break;
2689
2690   case SMESHOp::OpDiagonalInversion:
2691   case SMESHOp::OpUnionOfTwoTriangle:
2692     {
2693       if ( !vtkwnd )
2694       {
2695         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2696                                   tr( "NOT_A_VTK_VIEWER" ) );
2697         break;
2698       }
2699
2700       if ( checkLock( aStudy ) )
2701         break;
2702
2703       /*Standard_Boolean aRes;
2704       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2705       if ( aMesh->_is_nil() )
2706       {
2707         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2708           tr( "SMESH_BAD_SELECTION" ) );
2709         break;
2710       }
2711       */
2712       EmitSignalDeactivateDialog();
2713       if ( theCommandID == SMESHOp::OpDiagonalInversion )
2714         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2715       else
2716         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2717       break;
2718     }
2719   case SMESHOp::OpOrientation:
2720   case SMESHOp::OpUnionOfTriangles:
2721   case SMESHOp::OpCuttingOfQuadrangles:
2722   case SMESHOp::OpSplitVolumes:
2723     {
2724       if ( !vtkwnd )
2725       {
2726         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2727                                   tr( "NOT_A_VTK_VIEWER" ) );
2728         break;
2729       }
2730
2731       if ( checkLock( aStudy ) )
2732         break;
2733
2734       EmitSignalDeactivateDialog();
2735       SMESHGUI_MultiEditDlg* aDlg = NULL;
2736       if ( theCommandID == SMESHOp::OpOrientation )
2737         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2738       else if ( theCommandID == SMESHOp::OpUnionOfTriangles )
2739         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2740       else if ( theCommandID == SMESHOp::OpSplitVolumes )
2741         aDlg = new SMESHGUI_SplitVolumesDlg(this);
2742       else
2743         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2744
2745       aDlg->show();
2746       break;
2747     }
2748   case SMESHOp::OpSmoothing:
2749     {
2750       if(checkLock(aStudy)) break;
2751       if( vtkwnd ) {
2752         EmitSignalDeactivateDialog();
2753         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2754       }
2755       else {
2756         SUIT_MessageBox::warning(desktop(),
2757                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2758       }
2759       break;
2760     }
2761   case SMESHOp::OpExtrusion:
2762     {
2763       if (checkLock(aStudy)) break;
2764       if (vtkwnd) {
2765         EmitSignalDeactivateDialog();
2766         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2767       } else {
2768         SUIT_MessageBox::warning(desktop(),
2769                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2770       }
2771       break;
2772     }
2773   case SMESHOp::OpExtrusionAlongAPath:
2774     {
2775       if (checkLock(aStudy)) break;
2776       if (vtkwnd) {
2777         EmitSignalDeactivateDialog();
2778         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2779       } else {
2780         SUIT_MessageBox::warning(desktop(),
2781                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2782       }
2783       break;
2784     }
2785   case SMESHOp::OpRevolution:
2786     {
2787       if(checkLock(aStudy)) break;
2788       if( vtkwnd ) {
2789         EmitSignalDeactivateDialog();
2790         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2791       }
2792       else {
2793         SUIT_MessageBox::warning(desktop(),
2794                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2795       }
2796       break;
2797     }
2798   case SMESHOp::OpPatternMapping:
2799     {
2800       if ( checkLock( aStudy ) )
2801         break;
2802       if ( vtkwnd )
2803       {
2804         EmitSignalDeactivateDialog();
2805         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2806       }
2807       else {
2808         SUIT_MessageBox::warning(desktop(),
2809                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2810       }
2811       break;
2812     }
2813   case SMESHOp::OpSplitBiQuadratic:
2814   case SMESHOp::OpConvertMeshToQuadratic:
2815   case SMESHOp::OpCreateBoundaryElements: // create 2D mesh from 3D
2816   case SMESHOp::OpReorientFaces:
2817   case SMESHOp::OpCreateGeometryGroup:
2818     {
2819       startOperation( theCommandID );
2820       break;
2821     }
2822   case SMESHOp::OpCreateGroup:
2823     {
2824       if ( !vtkwnd )
2825       {
2826         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2827                                   tr( "NOT_A_VTK_VIEWER" ) );
2828         break;
2829       }
2830
2831       if(checkLock(aStudy)) break;
2832       EmitSignalDeactivateDialog();
2833       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2834
2835       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2836       SALOME_ListIO selected;
2837       if( aSel )
2838         aSel->selectedObjects( selected );
2839
2840       int nbSel = selected.Extent();
2841       if (nbSel == 1) {
2842         // check if mesh is selected
2843         aMesh = SMESH::GetMeshByIO( selected.First() );
2844       }
2845       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2846       aDlg->show();
2847       break;
2848     }
2849
2850   case SMESHOp::OpConstructGroup:
2851     {
2852       if ( !vtkwnd )
2853       {
2854         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2855                                   tr( "NOT_A_VTK_VIEWER" ) );
2856         break;
2857       }
2858
2859       if(checkLock(aStudy)) break;
2860       EmitSignalDeactivateDialog();
2861
2862       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2863       SALOME_ListIO selected;
2864       if( aSel )
2865         aSel->selectedObjects( selected );
2866
2867       int nbSel = selected.Extent();
2868       if (nbSel == 1) {
2869         // check if submesh is selected
2870         Handle(SALOME_InteractiveObject) IObject = selected.First();
2871         if (IObject->hasEntry()) {
2872           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2873           if( aSObj ) {
2874             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2875             if (!aSubMesh->_is_nil()) {
2876               try {
2877                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2878                 // get submesh elements list by types
2879                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2880                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2881                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2882                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2883                 // create group for each type o elements
2884                 QString aName = IObject->getName();
2885                 QStringList anEntryList;
2886                 if (aNodes->length() > 0) {
2887                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2888                   aGroup->Add(aNodes.inout());
2889                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2890                     anEntryList.append( aSObject->GetID().c_str() );
2891                 }
2892                 if (aEdges->length() > 0) {
2893                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2894                   aGroup->Add(aEdges.inout());
2895                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2896                     anEntryList.append( aSObject->GetID().c_str() );
2897                 }
2898                 if (aFaces->length() > 0) {
2899                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2900                   aGroup->Add(aFaces.inout());
2901                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2902                     anEntryList.append( aSObject->GetID().c_str() );
2903                 }
2904                 if (aVolumes->length() > 0) {
2905                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2906                   aGroup->Add(aVolumes.inout());
2907                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2908                     anEntryList.append( aSObject->GetID().c_str() );
2909                 }
2910                 updateObjBrowser();
2911                 anApp->browseObjects( anEntryList );
2912               }
2913               catch(const SALOME::SALOME_Exception & S_ex){
2914                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2915               }
2916             }
2917           }
2918         }
2919       }
2920       else if(nbSel==0) {
2921         SUIT_MessageBox::warning(desktop(),
2922                                  tr("SMESH_WRN_WARNING"),
2923                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2924       }
2925       break;
2926     }
2927
2928   case SMESHOp::OpEditGroup:
2929     {
2930       if ( !vtkwnd )
2931       {
2932         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2933                                   tr( "NOT_A_VTK_VIEWER" ) );
2934         break;
2935       }
2936
2937       if(checkLock(aStudy)) break;
2938       EmitSignalDeactivateDialog();
2939
2940       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2941       SALOME_ListIO selected;
2942       if( aSel )
2943         aSel->selectedObjects( selected );
2944
2945       SALOME_ListIteratorOfListIO It (selected);
2946       int nbSelectedGroups = 0;
2947       for ( ; It.More(); It.Next() )
2948       {
2949         SMESH::SMESH_GroupBase_var aGroup =
2950           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
2951         if (!aGroup->_is_nil()) {
2952           nbSelectedGroups++;
2953           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
2954           aDlg->show();
2955         }
2956       }
2957       if (nbSelectedGroups == 0)
2958         {
2959           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
2960           aDlg->show();
2961         }
2962       break;
2963     }
2964
2965   case SMESHOp::OpAddElemGroupPopup:     // Add elements to group
2966     {
2967       if(checkLock(aStudy)) break;
2968       if (myState == 800) {
2969         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2970         if (aDlg) aDlg->onAdd();
2971       }
2972       break;
2973     }
2974
2975   case SMESHOp::OpRemoveElemGroupPopup:  // Remove elements from group
2976     {
2977       if(checkLock(aStudy)) break;
2978       if (myState == 800) {
2979         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2980         if (aDlg) aDlg->onRemove();
2981       }
2982       break;
2983     }
2984
2985   case SMESHOp::OpEditGeomGroupAsGroup:
2986     {
2987       if ( !vtkwnd )
2988       {
2989         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2990                                   tr( "NOT_A_VTK_VIEWER" ) );
2991         break;
2992       }
2993
2994       if(checkLock(aStudy)) break;
2995       EmitSignalDeactivateDialog();
2996
2997       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2998       SALOME_ListIO selected;
2999       if( aSel )
3000         aSel->selectedObjects( selected );
3001
3002       SALOME_ListIteratorOfListIO It (selected);
3003       for ( ; It.More(); It.Next() )
3004       {
3005         SMESH::SMESH_GroupOnGeom_var aGroup =
3006           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
3007         if (!aGroup->_is_nil()) {
3008           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3009           aDlg->show();
3010         }
3011         else
3012         {
3013           SMESH::SMESH_GroupOnFilter_var aGroup =
3014             SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
3015           if (!aGroup->_is_nil()) {
3016             SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3017             aDlg->show();
3018           }
3019         }
3020       }
3021       break;
3022     }
3023
3024     case SMESHOp::OpUnionGroups:
3025     case SMESHOp::OpIntersectGroups:
3026     case SMESHOp::OpCutGroups:
3027     {
3028       if ( !vtkwnd )
3029       {
3030         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
3031                                   tr( "NOT_A_VTK_VIEWER" ) );
3032         break;
3033       }
3034
3035       if ( checkLock( aStudy ) )
3036         break;
3037
3038       EmitSignalDeactivateDialog();
3039
3040       SMESHGUI_GroupOpDlg* aDlg = 0;
3041       if ( theCommandID == SMESHOp::OpUnionGroups )
3042         aDlg = new SMESHGUI_UnionGroupsDlg( this );
3043       else if ( theCommandID == SMESHOp::OpIntersectGroups )
3044         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
3045       else
3046         aDlg = new SMESHGUI_CutGroupsDlg( this );
3047
3048       aDlg->show();
3049
3050       break;
3051     }
3052
3053     case SMESHOp::OpGroupUnderlyingElem: // Create groups of entities from existing groups of superior dimensions
3054     {
3055       if ( checkLock( aStudy ) )
3056         break;
3057
3058       EmitSignalDeactivateDialog();
3059       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
3060       aDlg->show();
3061
3062       break;
3063     }
3064
3065     case SMESHOp::OpDeleteGroup: // Delete groups with their contents
3066     {
3067       if ( !vtkwnd )
3068       {
3069         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
3070                                   tr( "NOT_A_VTK_VIEWER" ) );
3071         break;
3072       }
3073
3074       if ( checkLock( aStudy ) )
3075         break;
3076
3077       EmitSignalDeactivateDialog();
3078
3079       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
3080       break;
3081     }
3082
3083   case SMESHOp::OpMeshInformation:
3084   case SMESHOp::OpWhatIs:
3085     {
3086       int page = theCommandID == SMESHOp::OpMeshInformation ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
3087       EmitSignalDeactivateDialog();
3088       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3089       SALOME_ListIO selected;
3090       if( aSel )
3091         aSel->selectedObjects( selected );
3092
3093       if ( selected.Extent() > 1 ) { // a dlg for each IO
3094         SALOME_ListIteratorOfListIO It( selected );
3095         for ( ; It.More(); It.Next() ) {
3096           SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3097           dlg->showInfo( It.Value() ); 
3098           dlg->show();
3099         }
3100       }
3101       else {
3102         SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3103         dlg->show();
3104       }
3105       break;
3106     }
3107
3108   case SMESHOp::OpFindElementByPoint:
3109     {
3110       startOperation( theCommandID );
3111       break;
3112     }
3113
3114   case SMESHOp::OpEditHypothesis:
3115     {
3116       if(checkLock(aStudy)) break;
3117
3118       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3119       SALOME_ListIO selected;
3120       if( aSel )
3121         aSel->selectedObjects( selected );
3122
3123       int nbSel = selected.Extent();
3124
3125       if (nbSel == 1) {
3126         Handle(SALOME_InteractiveObject) anIObject = selected.First();
3127         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
3128
3129         if ( !aHypothesis->_is_nil() )
3130         {
3131           SMESHGUI_GenericHypothesisCreator* aCreator =
3132             SMESH::GetHypothesisCreator( SMESH::toQStr( aHypothesis->GetName() ));
3133           if (aCreator)
3134           {
3135             // set geometry of mesh and sub-mesh to aCreator
3136             aSel->selectedObjects( selected, "",  /*convertReferences=*/false);
3137             if ( selected.Extent() == 1 )
3138             {
3139               QString subGeomID, meshGeomID;
3140               Handle(SALOME_InteractiveObject) hypIO = selected.First();
3141               if ( SMESH::GetGeomEntries( hypIO, subGeomID, meshGeomID ))
3142               {
3143                 if ( subGeomID.isEmpty() ) subGeomID = meshGeomID;
3144                 aCreator->setShapeEntry( subGeomID );
3145                 aCreator->setMainShapeEntry( meshGeomID );
3146               }
3147             }
3148
3149             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
3150           }
3151           else
3152           {
3153             // report error
3154           }
3155         }
3156       }
3157       break;
3158     }
3159   case SMESHOp::OpUnassign:                      // REMOVE HYPOTHESIS / ALGORITHMS
3160     {
3161       if(checkLock(aStudy)) break;
3162       SUIT_OverrideCursor wc;
3163
3164       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3165       SALOME_ListIO selected;
3166       if( aSel )
3167         aSel->selectedObjects( selected, QString::null, false );
3168
3169       SALOME_ListIteratorOfListIO It(selected);
3170       for (int i = 0; It.More(); It.Next(), i++) {
3171         Handle(SALOME_InteractiveObject) IObject = It.Value();
3172         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
3173       }
3174       SALOME_ListIO l1;
3175       aSel->setSelectedObjects( l1 );
3176       updateObjBrowser();
3177       break;
3178     }
3179
3180   case SMESHOp::OpElem0D:
3181   case SMESHOp::OpBall:
3182   case SMESHOp::OpEdge:
3183   case SMESHOp::OpTriangle:
3184   case SMESHOp::OpQuadrangle:
3185   case SMESHOp::OpPolygon:
3186   case SMESHOp::OpTetrahedron:
3187   case SMESHOp::OpHexahedron:
3188   case SMESHOp::OpPentahedron:
3189   case SMESHOp::OpPyramid:
3190   case SMESHOp::OpHexagonalPrism:
3191     {
3192       if(checkLock(aStudy)) break;
3193       if ( vtkwnd ) {
3194         EmitSignalDeactivateDialog();
3195         SMDSAbs_EntityType type = SMDSEntity_Edge;
3196         switch (theCommandID) {
3197         case SMESHOp::OpElem0D: type = SMDSEntity_0D;                      break;
3198         case SMESHOp::OpBall: type = SMDSEntity_Ball;                      break;
3199         case SMESHOp::OpTriangle: type = SMDSEntity_Triangle;              break;
3200         case SMESHOp::OpQuadrangle: type = SMDSEntity_Quadrangle;          break;
3201         case SMESHOp::OpTetrahedron: type = SMDSEntity_Tetra;              break;
3202         case SMESHOp::OpPolygon: type = SMDSEntity_Polygon;                break;
3203         case SMESHOp::OpHexahedron: type = SMDSEntity_Hexa;                break;
3204         case SMESHOp::OpPentahedron: type = SMDSEntity_Penta;              break;
3205         case SMESHOp::OpPyramid: type = SMDSEntity_Pyramid;                break;
3206         case SMESHOp::OpHexagonalPrism: type = SMDSEntity_Hexagonal_Prism; break;
3207         default:;
3208         }
3209         ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
3210       }
3211       else {
3212         SUIT_MessageBox::warning(desktop(),
3213                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3214       }
3215       break;
3216     }
3217   case SMESHOp::OpPolyhedron:
3218     {
3219       if(checkLock(aStudy)) break;
3220       if ( vtkwnd ) {
3221         EmitSignalDeactivateDialog();
3222         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
3223       }
3224       else {
3225         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3226                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3227       }
3228       break;
3229     }
3230   case SMESHOp::OpQuadraticEdge:
3231   case SMESHOp::OpQuadraticTriangle:
3232   case SMESHOp::OpBiQuadraticTriangle:
3233   case SMESHOp::OpQuadraticQuadrangle:
3234   case SMESHOp::OpBiQuadraticQuadrangle:
3235   case SMESHOp::OpQuadraticPolygon:
3236   case SMESHOp::OpQuadraticTetrahedron:
3237   case SMESHOp::OpQuadraticPyramid:
3238   case SMESHOp::OpQuadraticPentahedron:
3239   case SMESHOp::OpQuadraticHexahedron:
3240   case SMESHOp::OpTriQuadraticHexahedron:
3241     {
3242       if(checkLock(aStudy)) break;
3243       if ( vtkwnd ) {
3244         EmitSignalDeactivateDialog();
3245         SMDSAbs_EntityType type = SMDSEntity_Last;
3246
3247         switch (theCommandID) {
3248         case SMESHOp::OpQuadraticEdge:          type = SMDSEntity_Quad_Edge; break;
3249         case SMESHOp::OpQuadraticTriangle:      type = SMDSEntity_Quad_Triangle; break;
3250         case SMESHOp::OpBiQuadraticTriangle:    type = SMDSEntity_BiQuad_Triangle; break;
3251         case SMESHOp::OpQuadraticQuadrangle:    type = SMDSEntity_Quad_Quadrangle; break;
3252         case SMESHOp::OpBiQuadraticQuadrangle:  type = SMDSEntity_BiQuad_Quadrangle; break;
3253         case SMESHOp::OpQuadraticPolygon:       type = SMDSEntity_Quad_Polygon; break;
3254         case SMESHOp::OpQuadraticTetrahedron:   type = SMDSEntity_Quad_Tetra; break;
3255         case SMESHOp::OpQuadraticPyramid:       type = SMDSEntity_Quad_Pyramid; break;
3256         case SMESHOp::OpQuadraticPentahedron:   type = SMDSEntity_Quad_Penta; break;
3257         case SMESHOp::OpQuadraticHexahedron:    type = SMDSEntity_Quad_Hexa; break;
3258         case SMESHOp::OpTriQuadraticHexahedron: type = SMDSEntity_TriQuad_Hexa; break;
3259         default: break;
3260         }
3261         if ( type != SMDSEntity_Last )
3262           ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
3263       }
3264       else {
3265         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3266                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3267       }
3268       break;
3269     }
3270   case SMESHOp::OpRemoveNodes:
3271     {
3272       if(checkLock(aStudy)) break;
3273       if ( vtkwnd ) {
3274         EmitSignalDeactivateDialog();
3275         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
3276       }
3277       else {
3278         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3279                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3280       }
3281       break;
3282     }
3283   case SMESHOp::OpRemoveElements:                                    // REMOVES ELEMENTS
3284     {
3285       if(checkLock(aStudy)) break;
3286       if( vtkwnd ) {
3287         EmitSignalDeactivateDialog();
3288         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
3289       }
3290       else
3291         {
3292           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3293                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3294         }
3295       break;
3296     }
3297   case SMESHOp::OpClearMesh: {
3298
3299     if(checkLock(aStudy)) break;
3300
3301     SALOME_ListIO selected;
3302     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3303       aSel->selectedObjects( selected );
3304
3305     SUIT_OverrideCursor wc;
3306     SALOME_ListIteratorOfListIO It (selected);
3307     for ( ; It.More(); It.Next() )
3308     {
3309       Handle(SALOME_InteractiveObject) IOS = It.Value();
3310       SMESH::SMESH_Mesh_var aMesh =
3311         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
3312       if ( aMesh->_is_nil()) continue;
3313       try {
3314         SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3315         aMesh->Clear();
3316         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3317         SMESH::ModifiedMesh( aMeshSObj, false, true);
3318         // hide groups and submeshes
3319         _PTR(ChildIterator) anIter =
3320           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
3321         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3322         {
3323           _PTR(SObject) so = anIter->Value();
3324           SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3325         }
3326       }
3327       catch (const SALOME::SALOME_Exception& S_ex){
3328         wc.suspend();
3329         SalomeApp_Tools::QtCatchCorbaException(S_ex);
3330         wc.resume();
3331       }
3332     }
3333     SMESH::UpdateView();
3334     updateObjBrowser();
3335     break;
3336   }
3337   case SMESHOp::OpRemoveOrphanNodes:
3338     {
3339       if(checkLock(aStudy)) break;
3340       SALOME_ListIO selected;
3341       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3342         aSel->selectedObjects( selected );
3343       if ( selected.Extent() == 1 ) {
3344         Handle(SALOME_InteractiveObject) anIO = selected.First();
3345         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3346         if ( !aMesh->_is_nil() ) {
3347           bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3348                                                     tr( "SMESH_WARNING" ),
3349                                                     tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3350                                                     SUIT_MessageBox::Yes |
3351                                                     SUIT_MessageBox::No,
3352                                                     SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3353           if( confirm ) {
3354             try {
3355               SUIT_OverrideCursor wc;
3356               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3357               int removed = aMeshEditor->RemoveOrphanNodes();
3358               SUIT_MessageBox::information(SMESHGUI::desktop(),
3359                                            tr("SMESH_INFORMATION"),
3360                                            tr("NB_NODES_REMOVED").arg(removed));
3361               if ( removed > 0 ) {
3362                 SMESH::UpdateView();
3363                 SMESHGUI::Modified();
3364               }
3365             }
3366             catch (const SALOME::SALOME_Exception& S_ex) {
3367               SalomeApp_Tools::QtCatchCorbaException(S_ex);
3368             }
3369             catch (...) {
3370             }
3371           }
3372         }
3373       }
3374       break;
3375     }
3376   case SMESHOp::OpRenumberingNodes:
3377     {
3378       if(checkLock(aStudy)) break;
3379       if( vtkwnd ) {
3380         EmitSignalDeactivateDialog();
3381         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3382       }
3383       else
3384         {
3385           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3386                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3387         }
3388       break;
3389     }
3390   case SMESHOp::OpRenumberingElements:
3391     {
3392       if(checkLock(aStudy)) break;
3393       if ( vtkwnd ) {
3394         EmitSignalDeactivateDialog();
3395         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3396       }
3397       else
3398         {
3399           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3400                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3401         }
3402       break;
3403     }
3404   case SMESHOp::OpTranslation:
3405     {
3406       if(checkLock(aStudy)) break;
3407       if ( vtkwnd ) {
3408         EmitSignalDeactivateDialog();
3409         ( new SMESHGUI_TranslationDlg( this ) )->show();
3410       }
3411       else {
3412         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3413                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3414       }
3415       break;
3416     }
3417   case SMESHOp::OpRotation:
3418     {
3419       if(checkLock(aStudy)) break;
3420       if( vtkwnd ) {
3421         EmitSignalDeactivateDialog();
3422         ( new SMESHGUI_RotationDlg( this ) )->show();
3423       }
3424       else {
3425         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3426                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3427       }
3428       break;
3429     }
3430   case SMESHOp::OpSymmetry:
3431     {
3432       if(checkLock(aStudy)) break;
3433       if(vtkwnd) {
3434         EmitSignalDeactivateDialog();
3435         ( new SMESHGUI_SymmetryDlg( this ) )->show();
3436       }
3437       else {
3438         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3439                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3440       }
3441       break;
3442     }
3443   case SMESHOp::OpScale:
3444     {
3445       if(checkLock(aStudy)) break;
3446       if ( vtkwnd ) {
3447         EmitSignalDeactivateDialog();
3448         ( new SMESHGUI_ScaleDlg( this ) )->show();
3449       }
3450       else {
3451         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3452                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3453       }
3454       break;
3455     }
3456
3457   case SMESHOp::OpSewing:
3458     {
3459       if(checkLock(aStudy)) break;
3460       if(vtkwnd) {
3461         EmitSignalDeactivateDialog();
3462         ( new SMESHGUI_SewingDlg( this ) )->show();
3463       }
3464       else {
3465         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3466                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3467       }
3468       break;
3469     }
3470   case SMESHOp::OpMergeNodes:
3471     {
3472       if(checkLock(aStudy)) break;
3473       if(vtkwnd) {
3474         EmitSignalDeactivateDialog();
3475         ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3476       }
3477       else {
3478         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3479                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3480       }
3481       break;
3482     }
3483   case SMESHOp::OpMergeElements:
3484     {
3485       if (checkLock(aStudy)) break;
3486       if (vtkwnd) {
3487         EmitSignalDeactivateDialog();
3488         ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3489       } else {
3490         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3491                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3492       }
3493       break;
3494     }
3495
3496   case SMESHOp::OpMoveNode: // MAKE MESH PASS THROUGH POINT
3497     startOperation( SMESHOp::OpMoveNode );
3498     break;
3499
3500   case SMESHOp::OpDuplicateNodes:
3501     {
3502       if(checkLock(aStudy)) break;
3503       if ( vtkwnd ) {
3504         EmitSignalDeactivateDialog();
3505         ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3506       }
3507       else {
3508         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3509                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3510       }
3511       break;
3512     }
3513
3514   case SMESHOp::OpElem0DOnElemNodes: // 0D_ON_ALL_NODES
3515     startOperation( SMESHOp::OpElem0DOnElemNodes );
3516     break;
3517
3518   case SMESHOp::OpSelectFiltersLibrary: // Library of selection filters
3519   {
3520     static QList<int> aTypes;
3521     if ( aTypes.isEmpty() )
3522     {
3523       aTypes.append( SMESH::NODE );
3524       aTypes.append( SMESH::EDGE );
3525       aTypes.append( SMESH::FACE );
3526       aTypes.append( SMESH::VOLUME );
3527     }
3528     if (!myFilterLibraryDlg)
3529       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3530     else if (myFilterLibraryDlg->isHidden())
3531       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );