Salome HOME
776e7653ceda3727929c207ed060b5496865ea68
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 // Copyright (C) 2007-2019  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_DisplayEntitiesDlg.h"
44 #include "SMESHGUI_Displayer.h"
45 #include "SMESHGUI_DuplicateNodesDlg.h"
46 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
47 #include "SMESHGUI_ExtrusionDlg.h"
48 #include "SMESHGUI_FaceGroupsSeparatedByEdgesDlg.h"
49 #include "SMESHGUI_FieldSelectorWdg.h"
50 #include "SMESHGUI_FileInfoDlg.h"
51 #include "SMESHGUI_FileValidator.h"
52 #include "SMESHGUI_FilterDlg.h"
53 #include "SMESHGUI_FilterLibraryDlg.h"
54 #include "SMESHGUI_FilterUtils.h"
55 #include "SMESHGUI_FindElemByPointDlg.h"
56 #include "SMESHGUI_GEOMGenUtils.h"
57 #include "SMESHGUI_GroupDlg.h"
58 #include "SMESHGUI_GroupOnShapeDlg.h"
59 #include "SMESHGUI_GroupOpDlg.h"
60 #include "SMESHGUI_GroupUtils.h"
61 #include "SMESHGUI_Hypotheses.h"
62 #include "SMESHGUI_HypothesesUtils.h"
63 #include "SMESHGUI_Make2DFrom3DOp.h"
64 #include "SMESHGUI_MakeNodeAtPointDlg.h"
65 #include "SMESHGUI_Measurements.h"
66 #include "SMESHGUI_MergeDlg.h"
67 #include "SMESHGUI_MeshInfo.h"
68 #include "SMESHGUI_MeshOp.h"
69 #include "SMESHGUI_MeshOrderOp.h"
70 #include "SMESHGUI_MeshPatternDlg.h"
71 #include "SMESHGUI_MeshUtils.h"
72 #include "SMESHGUI_MultiEditDlg.h"
73 #include "SMESHGUI_NodesDlg.h"
74 #include "SMESHGUI_OffsetDlg.h"
75 #include "SMESHGUI_Operations.h"
76 #include "SMESHGUI_PatternUtils.h"
77 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
78 #include "SMESHGUI_PropertiesDlg.h"
79 #include "SMESHGUI_RemoveElementsDlg.h"
80 #include "SMESHGUI_RemoveNodesDlg.h"
81 #include "SMESHGUI_RenumberingDlg.h"
82 #include "SMESHGUI_ReorientFacesDlg.h"
83 #include "SMESHGUI_RevolutionDlg.h"
84 #include "SMESHGUI_RotationDlg.h"
85 #include "SMESHGUI_ScaleDlg.h"
86 #include "SMESHGUI_Selection.h"
87 #include "SMESHGUI_SewingDlg.h"
88 #include "SMESHGUI_SingleEditDlg.h"
89 #include "SMESHGUI_SmoothingDlg.h"
90 #include "SMESHGUI_SpinBox.h"
91 #include "SMESHGUI_SplitBiQuad.h"
92 #include "SMESHGUI_SymmetryDlg.h"
93 #include "SMESHGUI_TranslationDlg.h"
94 #include "SMESHGUI_TransparencyDlg.h"
95 #include "SMESHGUI_Utils.h"
96 #include "SMESHGUI_VTKUtils.h"
97
98 #include "SMESH_version.h"
99
100 #include "SMESH_ControlsDef.hxx"
101 #include "SMESH_Actor.h"
102 #include "SMESH_ActorUtils.h"
103 #include "SMESH_Client.hxx"
104 #include "SMESH_ScalarBarActor.h"
105 #include <SMESH_Comment.hxx>
106 #include "SMESH_TypeFilter.hxx"
107
108 // SALOME GUI includes
109 #include <LightApp_DataOwner.h>
110 #include <LightApp_NameDlg.h>
111 #include <LightApp_Preferences.h>
112 #include <LightApp_SelectionMgr.h>
113 #include <LightApp_UpdateFlags.h>
114 #include <QtxFontEdit.h>
115 #include <QtxPopupMgr.h>
116 #include <SALOME_ListIO.hxx>
117 #include <SUIT_Desktop.h>
118 #include <SUIT_FileDlg.h>
119 #include <SUIT_MessageBox.h>
120 #include <SUIT_OverrideCursor.h>
121 #include <SUIT_ResourceMgr.h>
122 #include <SUIT_Session.h>
123 #include <SVTK_Renderer.h>
124 #include <SVTK_ViewManager.h>
125 #include <SVTK_ViewModel.h>
126 #include <SVTK_ViewWindow.h>
127 #include <SalomeApp_Application.h>
128 #include <SalomeApp_CheckFileDlg.h>
129 #include <SalomeApp_DataObject.h>
130 #include <SalomeApp_Study.h>
131 #include <SalomeApp_Tools.h>
132 #include <VTKViewer_Algorithm.h>
133
134 #ifndef DISABLE_PLOT2DVIEWER
135 #include <SPlot2d_ViewModel.h>
136 #include <SPlot2d_Histogram.h>
137 #endif
138
139 // IDL includes
140 #include <SALOMEconfig.h>
141 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
142 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
143 #include CORBA_CLIENT_HEADER(SMESH_Measurements)
144 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
145
146 // Qt includes
147 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
148 #include <QApplication>
149 #include <QCheckBox>
150 #include <QDialogButtonBox>
151 #include <QLayout>
152 #include <QListView>
153 #include <QMenu>
154 #include <QTextStream>
155 #include <QTreeView>
156
157 // BOOST includes
158 #include <boost/shared_ptr.hpp>
159
160 // VTK includes
161 #include <vtkCallbackCommand.h>
162 #include <vtkCamera.h>
163 #include <vtkLookupTable.h>
164 #include <vtkPlane.h>
165 #include <vtkRenderer.h>
166
167 // SALOME KERNEL includes
168 #include <SALOMEDSClient_ClientFactory.hxx>
169 #include <SALOMEDSClient_IParameters.hxx>
170 #include <SALOMEDSClient_SComponent.hxx>
171 #include <SALOMEDSClient_StudyBuilder.hxx>
172 #include <SALOMEDS_Study.hxx>
173 #include <SALOMEDS_SObject.hxx>
174 #include "utilities.h"
175
176 // OCCT includes
177 #include <Standard_ErrorHandler.hxx>
178 #include <NCollection_DataMap.hxx>
179 #include <NCollection_DoubleMap.hxx>
180
181 #include <Basics_Utils.hxx>
182
183 // Below macro, when uncommented, switches on simplified (more performant) algorithm
184 // of auto-color picking up
185 #define SIMPLE_AUTOCOLOR
186
187 namespace
188 {
189   // Declarations
190   //=============================================================
191   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
192                             int                  theCommandID);
193
194   void ExportMeshToFile(int theCommandID);
195
196   void SetDisplayMode(int theCommandID, VTK::MarkerMap& theMarkerMap);
197
198   void SetDisplayEntity(int theCommandID);
199
200   int  ActionToControl( int theID, bool theReversed = false );
201
202   void Control( int theCommandID );
203
204   // Definitions
205   //================================================================================
206   /*!
207    * \brief Reads meshes from file
208    */
209   //================================================================================
210
211   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
212                              int                  theCommandID )
213   {
214     QStringList filter;
215     std::string myExtension;
216
217     if ( theCommandID == SMESHOp::OpImportMED ||
218          theCommandID == SMESHOp::OpPopupImportMED ) {
219       filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.*med)" );
220       filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
221     }
222     else if ( theCommandID == SMESHOp::OpImportUNV ||
223               theCommandID == SMESHOp::OpPopupImportUNV ) {
224       filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
225     }
226     else if ( theCommandID == SMESHOp::OpImportDAT ||
227               theCommandID == SMESHOp::OpPopupImportDAT ) {
228       filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
229     }
230     else if ( theCommandID == SMESHOp::OpImportSTL ||
231               theCommandID == SMESHOp::OpPopupImportSTL ) {
232       filter.append( QObject::tr( "STL_FILES_FILTER" ) + " (*.stl)" );
233     }
234     else if ( theCommandID == SMESHOp::OpImportCGNS ||
235               theCommandID == SMESHOp::OpPopupImportCGNS ) {
236       filter.append( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
237     }
238     else if ( theCommandID == SMESHOp::OpImportSAUV ||
239               theCommandID == SMESHOp::OpPopupImportSAUV ) {
240       filter.append( QObject::tr( "SAUV_FILES_FILTER" ) + " (*.sauv *.sauve)" );
241       filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
242     }
243     else if ( theCommandID == SMESHOp::OpImportGMF ||
244               theCommandID == SMESHOp::OpPopupImportGMF ) {
245       filter.append( QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)"  );
246       filter.append( QObject::tr( "GMF_BINARY_FILES_FILTER") + " (*.meshb)" );
247     }
248
249     QString anInitialPath = "";
250     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
251       anInitialPath = QDir::currentPath();
252
253     QStringList filenames;
254     bool toCreateGroups = true;
255
256     // if ( theCommandID == SMESHOp::OpImportGMF ) { // GMF
257     //   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
258     //     ( SMESHGUI::desktop(), true, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
259     //   fd->setWindowTitle( QObject::tr( "SMESH_IMPORT_MESH" ) );
260     //   fd->setNameFilters( filter );
261     //   fd->SetChecked( true );
262     //   if ( fd->exec() )
263     //     filenames << fd->selectedFile();
264     //   toCreateGroups = fd->IsChecked();
265
266     //   delete fd;
267     // }
268     // else
269     {
270       filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
271                                                   anInitialPath,
272                                                   filter,
273                                                   QObject::tr( "SMESH_IMPORT_MESH" ) );
274     }
275     if ( filenames.count() > 0 )
276     {
277       SUIT_OverrideCursor wc;
278       _PTR(Study) aStudy = SMESH::getStudy();
279
280       QStringList errors;
281       QStringList anEntryList;
282       bool isEmpty = false;
283       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it )
284       {
285         QString filename = *it;
286         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
287         try {
288           switch ( theCommandID ) {
289           case SMESHOp::OpImportDAT:
290           case SMESHOp::OpPopupImportDAT:
291             {
292               // DAT format (currently unsupported)
293               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
294                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
295               break;
296             }
297           case SMESHOp::OpImportUNV:
298           case SMESHOp::OpPopupImportUNV:
299             {
300               // UNV format
301               aMeshes->length( 1 );
302               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toUtf8().constData() );
303               if ( aMeshes[0]->_is_nil() )
304                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
305                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
306               break;
307             }
308           case SMESHOp::OpImportMED:
309           case SMESHOp::OpPopupImportMED:
310             {
311               // MED format
312               SMESH::DriverMED_ReadStatus res;
313               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toUtf8().constData(), res );
314               if ( res != SMESH::DRS_OK ) {
315                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
316                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
317               }
318               break;
319             }
320           case SMESHOp::OpImportSTL:
321           case SMESHOp::OpPopupImportSTL:
322             {
323               // STL format
324               aMeshes->length( 1 );
325               aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toUtf8().constData() );
326               if ( aMeshes[0]->_is_nil() ) {
327                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
328                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
329               }
330               break;
331             }
332           case SMESHOp::OpImportCGNS:
333           case SMESHOp::OpPopupImportCGNS:
334             {
335               // CGNS format
336               SMESH::DriverMED_ReadStatus res;
337               aMeshes = theComponentMesh->CreateMeshesFromCGNS( filename.toUtf8().constData(), res );
338               if ( res != SMESH::DRS_OK ) {
339                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
340                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
341               }
342               break;
343             }
344           case SMESHOp::OpImportSAUV:
345           case SMESHOp::OpPopupImportSAUV:
346             {
347               // SAUV format
348               SMESH::DriverMED_ReadStatus res;
349               aMeshes = theComponentMesh->CreateMeshesFromSAUV( filename.toUtf8().constData(), res );
350               if ( res != SMESH::DRS_OK ) {
351                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
352                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
353               }
354               break;
355             }
356           case SMESHOp::OpImportGMF:
357           case SMESHOp::OpPopupImportGMF:
358             {
359               // GMF format
360               SMESH::ComputeError_var res;
361               aMeshes->length( 1 );
362               aMeshes[0] = theComponentMesh->CreateMeshesFromGMF( filename.toUtf8().constData(),
363                                                                   toCreateGroups,
364                                                                   res.out() );
365               if ( res->code != SMESH::DRS_OK ) {
366                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
367                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res->code ).toLatin1().data() ) ) );
368                 if ( strlen( res->comment.in() ) > 0 ) {
369                   errors.back() += ": ";
370                   errors.back() += res->comment.in();
371                 }
372               }
373               break;
374             }
375           }
376         }
377         catch ( const SALOME::SALOME_Exception& S_ex ) {
378           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
379                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
380         }
381
382         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ )
383         {
384           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
385           if ( aMeshSO ) {
386             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
387             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
388             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
389             if ( theCommandID == SMESHOp::OpImportUNV ) // mesh names aren't taken from the file for UNV import
390               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
391
392             anEntryList.append( aMeshSO->GetID().c_str() );
393           }
394           else {
395             isEmpty = true;
396           }
397         }
398       }
399
400       // update Object browser
401       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
402
403       // browse to the published meshes
404       if( LightApp_Application* anApp =
405           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
406         anApp->browseObjects( anEntryList );
407
408       // show Error message box if there were errors
409       if ( errors.count() > 0 ) {
410         SUIT_MessageBox::critical( SMESHGUI::desktop(),
411                                    QObject::tr( "SMESH_ERROR" ),
412                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
413       }
414
415       // show warning message box, if some imported mesh is empty
416       if ( isEmpty ) {
417           SUIT_MessageBox::warning( SMESHGUI::desktop(),
418                                     QObject::tr( "SMESH_WRN_WARNING" ),
419                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
420       }
421     }
422   }
423
424   //================================================================================
425   /*!
426    * \brief Export selected meshes or groups into a file
427    */
428   //================================================================================
429
430   void ExportMeshToFile( int theCommandID )
431   {
432     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
433     SALOME_ListIO selected;
434     if( aSel )
435       aSel->selectedObjects( selected );
436
437     const bool isDAT = ( theCommandID == SMESHOp::OpExportDAT ||
438                          theCommandID == SMESHOp::OpPopupExportDAT );
439     const bool isMED = ( theCommandID == SMESHOp::OpExportMED ||
440                          theCommandID == SMESHOp::OpPopupExportMED );
441     const bool isUNV = ( theCommandID == SMESHOp::OpExportUNV ||
442                          theCommandID == SMESHOp::OpPopupExportUNV );
443     const bool isSTL = ( theCommandID == SMESHOp::OpExportSTL ||
444                          theCommandID == SMESHOp::OpPopupExportSTL );
445     const bool isCGNS= ( theCommandID == SMESHOp::OpExportCGNS ||
446                          theCommandID == SMESHOp::OpPopupExportCGNS );
447     const bool isSAUV= ( theCommandID == SMESHOp::OpExportSAUV ||
448                          theCommandID == SMESHOp::OpPopupExportSAUV );
449     const bool isGMF = ( theCommandID == SMESHOp::OpExportGMF ||
450                          theCommandID == SMESHOp::OpPopupExportGMF );
451
452     const bool multiMeshSupported = ( isMED || isCGNS ); // file can hold several meshes
453     if ( selected.Extent() == 0 || ( selected.Extent() > 1 && !multiMeshSupported ))
454       return;
455     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
456     bool aCheckWarn = true;
457     if ( resMgr )
458       aCheckWarn = resMgr->booleanValue( "SMESH", "show_warning", false );
459     // get mesh object from selection and check duplication of their names
460     bool hasDuplicatedMeshNames = false;
461     QList< QPair< SMESH::SMESH_IDSource_var, QString > >           aMeshList;
462     QList< QPair< SMESH::SMESH_IDSource_var, QString > >::iterator aMeshIter;
463     SALOME_ListIteratorOfListIO It( selected );
464     for( ; It.More(); It.Next() )
465     {
466       Handle(SALOME_InteractiveObject) anIObject = It.Value();
467       SMESH::SMESH_IDSource_var aMeshItem =
468         SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIObject);
469       if ( aMeshItem->_is_nil() ) {
470         SUIT_MessageBox::warning( SMESHGUI::desktop(),
471                                   QObject::tr( "SMESH_WRN_WARNING" ),
472                                   QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
473         return;
474       }
475       SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( aMeshItem );
476       if ( aCheckWarn && !aGroup->_is_nil() )
477       {
478         QMessageBox msgBox(SUIT_MessageBox::Warning,
479                            QObject::tr("SMESH_WRN_WARNING"),
480                            QObject::tr("SMESH_EXPORT_ONLY_GPOUP"),
481                            QMessageBox::StandardButton::NoButton,
482                            SMESHGUI::desktop());
483         QCheckBox dontShowCheckBox(QObject::tr("SMESH_WRN_SHOW_DLG_CHECKBOX"));
484         msgBox.addButton(QMessageBox::Ok);
485         msgBox.addButton(QMessageBox::Cancel);
486         msgBox.setDefaultButton(QMessageBox::Cancel);
487         QGridLayout* lt = qobject_cast<QGridLayout*>(msgBox.layout());
488         QDialogButtonBox* btnbox = msgBox.findChild<QDialogButtonBox*>();
489         lt->addWidget(&dontShowCheckBox, lt->rowCount(), lt->columnCount()-1, lt->rowCount(), lt->columnCount());
490         lt->addWidget(btnbox, lt->rowCount(), 0, lt->rowCount(), lt->columnCount());
491         if ( msgBox.exec() != QMessageBox::Ok )
492           return;
493
494         if ( dontShowCheckBox.checkState() == Qt::Checked && resMgr )
495           resMgr->setValue( "SMESH", "show_warning", false);
496       }
497
498       QString aMeshName = anIObject->getName();
499
500       // check for name duplications
501       if ( !hasDuplicatedMeshNames )
502         for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
503           if( aMeshName == (*aMeshIter).second ) {
504             hasDuplicatedMeshNames = true;
505             break;
506           }
507         }
508
509       aMeshList.append( QPair< SMESH::SMESH_IDSource_var, QString >( aMeshItem, aMeshName ) );
510     }
511
512     if( hasDuplicatedMeshNames && isMED ) {
513       int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
514                                           QObject::tr("SMESH_WRN_WARNING"),
515                                           QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
516                                           QObject::tr("SMESH_BUT_YES"),
517                                           QObject::tr("SMESH_BUT_NO"), 0, 1);
518       if (aRet != 0)
519         return;
520     }
521
522     aMeshIter = aMeshList.begin();
523     SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
524     SMESH::SMESH_Mesh_var            aMesh = aMeshOrGroup->GetMesh();
525     QString                      aMeshName = (*aMeshIter).second;
526
527     if ( isMED || isCGNS || isSAUV ) // formats where group names must be unique
528     {
529       // check for equal group names within each mesh
530       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
531         SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
532         if ( !aMeshItem->_is_nil() && aMeshItem->HasDuplicatedGroupNamesMED()) {
533           int aRet = SUIT_MessageBox::warning
534             (SMESHGUI::desktop(),
535              QObject::tr("SMESH_WRN_WARNING"),
536              QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
537              QObject::tr("SMESH_BUT_YES"),
538              QObject::tr("SMESH_BUT_NO"), 0, 1);
539           if (aRet != 0)
540             return;
541         }
542       }
543     }
544
545     // Warn the user about presence of not supported elements
546     QString format;
547     std::vector< SMESH::EntityType > notSupportedElemTypes, presentNotSupported;
548     if ( isDAT )
549     {
550       format = "DAT";
551       notSupportedElemTypes.push_back( SMESH::Entity_0D );
552       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
553     }
554     else if ( isUNV )
555     {
556       format = "UNV";
557       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
558       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
559       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
560       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
561       notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
562       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
563       notSupportedElemTypes.push_back( SMESH::Entity_0D );
564       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
565     }
566     else if ( isSTL )
567     {
568       format = "STL";
569       notSupportedElemTypes.push_back( SMESH::Entity_Edge );
570       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Edge );
571       notSupportedElemTypes.push_back( SMESH::Entity_0D );
572       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
573     }
574     else if ( isCGNS )
575     {
576       format = "CGNS";
577       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
578     }
579     else if ( isSAUV )
580     {
581       format = "SAUV";
582       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
583       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Triangle );
584       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
585       notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
586       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
587       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
588       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
589       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
590     }
591     else if ( isGMF )
592     {
593       format = "GMF";
594       notSupportedElemTypes.push_back( SMESH::Entity_0D );
595       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
596       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
597       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
598       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
599       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Penta );
600       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
601       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
602       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
603       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
604     }
605     if ( ! notSupportedElemTypes.empty() )
606     {
607       SMESH::long_array_var nbElems = aMeshOrGroup->GetMeshInfo();
608       for ( size_t iType = 0; iType < notSupportedElemTypes.size(); ++iType )
609         if ( nbElems[ notSupportedElemTypes[ iType ]] > 0 )
610           presentNotSupported.push_back( notSupportedElemTypes[ iType ]);
611     }
612     if ( !presentNotSupported.empty() )
613     {
614       QString typeNames;
615       const char* typeMsg[] = {
616         "SMESH_NODES", "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES",
617         "SMESH_TRIANGLES", "SMESH_QUADRATIC_TRIANGLES", "SMESH_BIQUADRATIC_TRIANGLES",
618         "SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES", "SMESH_BIQUADRATIC_QUADRANGLES",
619         "SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
620         "SMESH_TETRAHEDRA","SMESH_QUADRATIC_TETRAHEDRONS","SMESH_PYRAMIDS",
621         "SMESH_QUADRATIC_PYRAMIDS","SMESH_HEXAHEDRA","SMESH_QUADRATIC_HEXAHEDRONS",
622         "SMESH_TRIQUADRATIC_HEXAHEDRONS","SMESH_PENTAHEDRA","SMESH_QUADRATIC_PENTAHEDRONS",
623         "SMESH_BIQUADRATIC_PENTAHEDRONS",
624         "SMESH_OCTAHEDRA","SMESH_POLYEDRONS","SMESH_QUADRATIC_POLYEDRONS","SMESH_BALLS"
625       };
626       // is typeMsg complete? (compilation failure mains that enum SMDSAbs_EntityType changed)
627       const int nbTypes = sizeof( typeMsg ) / sizeof( const char* );
628       int _assert[( nbTypes == SMESH::Entity_Last ) ? 2 : -1 ]; _assert[0]=_assert[1]=0;
629
630       QString andStr = " " + QObject::tr("SMESH_AND") + " ", comma(", ");
631       for ( size_t iType = 0; iType < presentNotSupported.size(); ++iType ) {
632         typeNames += QObject::tr( typeMsg[ presentNotSupported[ iType ]]);
633         if ( iType != presentNotSupported.size() - 1 )
634           typeNames += ( iType == presentNotSupported.size() - 2 ) ? andStr : comma;
635       }
636       int aRet = SUIT_MessageBox::warning
637         (SMESHGUI::desktop(),
638          QObject::tr("SMESH_WRN_WARNING"),
639          QObject::tr("EXPORT_NOT_SUPPORTED").arg(aMeshName).arg(format).arg(typeNames),
640          QObject::tr("SMESH_BUT_YES"),
641          QObject::tr("SMESH_BUT_NO"), 0, 1);
642       if (aRet != 0)
643         return;
644     }
645
646     // Get parameters of export operation
647
648     QString aFilename;
649     int aFormat =-1;         // for MED version used for write
650     bool isOkToWrite = true; // to check MED file version compatibility before adding a mesh in an existing file
651
652     // Init the parameters with the default values
653     bool aIsASCII_STL   = true;
654     bool toCreateGroups = false;
655     if ( resMgr )
656       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
657     bool toOverwrite  = true;
658     bool toFindOutDim = true;
659     double       zTol = resMgr ? resMgr->doubleValue( "SMESH", "med_ztolerance", 0. ) : 0.;
660
661     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
662     QString anInitialPath = "";
663     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
664       anInitialPath = QDir::currentPath();
665
666     QList< QPair< GEOM::ListOfFields_var, QString > > aFieldList;
667
668     // Get a file name to write in and additional options
669     if ( isUNV || isDAT || isGMF ) // Export w/o options
670     {
671       if ( isUNV )
672         aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
673       else if ( isDAT )
674         aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
675       else if ( isGMF )
676         aFilter = QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)" +
677           ";;" +  QObject::tr( "GMF_BINARY_FILES_FILTER" )  + " (*.meshb)";
678      if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
679       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
680                                             anInitialPath + QString("/") + aMeshName,
681                                             aFilter, aTitle, false);
682     }
683     else if ( isCGNS )// Export to CGNS
684     {
685       const char* theByTypeResource = "cgns_group_elems_by_type";
686       toCreateGroups = SMESHGUI::resourceMgr()->booleanValue( "SMESH", theByTypeResource, false );
687
688       QStringList checkBoxes;
689       checkBoxes << QObject::tr("CGNS_EXPORT_ELEMS_BY_TYPE");
690
691       SalomeApp_CheckFileDlg* fd =
692         new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true );
693       fd->setWindowTitle( aTitle );
694       fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
695       if ( !anInitialPath.isEmpty() )
696         fd->setDirectory( anInitialPath );
697       fd->selectFile(aMeshName);
698       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
699       fd->setValidator( fv );
700       fd->SetChecked( toCreateGroups, 0 );
701
702       if ( fd->exec() )
703         aFilename = fd->selectedFile();
704       toOverwrite    = fv->isOverwrite(aFilename);
705       toCreateGroups = fd->IsChecked(0);
706       SMESHGUI::resourceMgr()->setValue("SMESH", theByTypeResource, toCreateGroups );
707
708       delete fd;
709     }
710     else if ( isSTL ) // Export to STL
711     {
712       QMap<QString, int> aFilterMap;
713       aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
714       aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 );
715
716       QStringList filters;
717       QMap<QString, int>::const_iterator it = aFilterMap.begin();
718       for ( ; it != aFilterMap.end(); ++it )
719         filters.push_back( it.key() );
720
721       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
722       fd->setWindowTitle( aTitle );
723       fd->setNameFilters( filters );
724       fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
725       if ( !anInitialPath.isEmpty() )
726         fd->setDirectory( anInitialPath );
727       fd->selectFile(aMeshName);
728       bool is_ok = false;
729       while (!is_ok) {
730         if ( fd->exec() )
731           aFilename = fd->selectedFile();
732         aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
733         is_ok = true;
734       }
735       delete fd;
736     }
737     else if ( isMED || isSAUV ) // Export to MED or SAUV
738     {
739       int defaultVersion = 0;
740       QMap<QString, int> aFilterMap;
741       if ( isMED ) {
742         //filters << QObject::tr( "MED_FILES_FILTER" ) + " (*.med)";
743         //QString vmed (aMesh->GetVersionString(-1, 2));
744         SMESH::long_array_var mvok = aMesh->GetMEDVersionsCompatibleForAppend();
745         if ( mvok->length() > 0)
746           defaultVersion = mvok[0]; // the current version to set the default filter on it
747         for ( CORBA::ULong i = 0; i < mvok->length(); ++i )
748         {
749           QString vs = (char*)( SMESH_Comment( mvok[i]/10 ) << "." << mvok[i]%10 );
750           MESSAGE("MED version: " << vs.toStdString());
751           aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( vs ) + " (*.med)",  mvok[i]);
752         }
753       }
754       else { // isSAUV
755         aFilterMap.insert("All files (*)", -1 );
756         aFilterMap.insert("SAUV files (*.sauv)", defaultVersion ); // 0 = default filter (defaultVersion)
757         aFilterMap.insert("SAUV files (*.sauve)", -1 );
758       }
759       QStringList filters;
760       QMap<QString, int>::const_iterator it = aFilterMap.begin();
761       QString aDefaultFilter = it.key();
762       for ( ; it != aFilterMap.end(); ++it ) {
763         filters.push_back( it.key() );
764         if (it.value() == defaultVersion) // explicit default for MED = current MED version
765           aDefaultFilter = it.key();
766       }
767       QStringList checkBoxes;
768       checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM");
769
770       SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
771       QList< QWidget* > wdgList;
772       if ( fieldSelWdg->GetAllFields( aMeshList, aFieldList ))
773         wdgList.append( fieldSelWdg );
774
775       QWidget*           zTolWdg = new QWidget();
776       QCheckBox*       zTolCheck = new QCheckBox( QObject::tr( "SMESH_ZTOLERANCE" ), zTolWdg );
777       SMESHGUI_SpinBox* zTolSpin = new SMESHGUI_SpinBox( zTolWdg );
778       QHBoxLayout*    zTolLayout = new QHBoxLayout( zTolWdg );
779       zTolLayout->addWidget( zTolCheck );
780       zTolLayout->addWidget( zTolSpin );
781       zTolLayout->setMargin( 0 );
782       zTolSpin->RangeStepAndValidator( 0, 1e+100, 1., "length_precision" );
783       zTolSpin->setValue( zTol );
784       QObject::connect( zTolCheck, SIGNAL( toggled(bool)), zTolSpin, SLOT( setEnabled(bool)));
785       zTolCheck->setChecked( resMgr->booleanValue( "SMESH", "enable_ztolerance", false ));
786       zTolSpin ->setEnabled( zTolCheck->isChecked() );
787       wdgList.append( zTolWdg );
788
789       SalomeApp_CheckFileDlg* fd =
790         new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true, wdgList );
791       fd->setWindowTitle( aTitle );
792       fd->setNameFilters( filters );
793       fd->selectNameFilter( aDefaultFilter );
794       fd->SetChecked( toCreateGroups, 0 );
795       fd->SetChecked( toFindOutDim,   1 );
796       if ( !anInitialPath.isEmpty() )
797         fd->setDirectory( anInitialPath );
798       fd->selectFile(aMeshName);
799
800
801       QListView *lview = fd->findChild<QListView*>("listView");
802       if( lview ) {
803         lview->setMinimumHeight(200);
804       }
805       QTreeView *tview = fd->findChild<QTreeView*>("treeView");
806       if( tview ) {
807         tview->setMinimumHeight(200);
808       }
809
810       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
811       fd->setValidator( fv );
812
813       bool is_ok = false;
814       while (!is_ok)
815       {
816         //MESSAGE("******* Loop on file dialog ***********");
817         isOkToWrite =true;
818         if ( fd->exec() )
819           aFilename = fd->selectedFile();
820         else {
821           aFilename = QString::null;
822           break;
823         }
824         aFormat = aFilterMap[fd->selectedNameFilter()];
825         //MESSAGE("selected version: " << aFormat << " file: " << aFilename.toUtf8().constData());
826         toOverwrite = fv->isOverwrite(aFilename);
827         //MESSAGE("toOverwrite:" << toOverwrite);
828         is_ok = true;
829         if ( !aFilename.isEmpty() ) {
830           if( !toOverwrite ) {
831             // append is only possible if the existing file format is compatible
832             bool isVersionOk = SMESHGUI::GetSMESHGen()->CheckWriteCompatibility( aFilename.toUtf8().constData() );
833             MESSAGE("Append check, isVersionOk:" << isVersionOk);
834             if ( !isVersionOk ) {
835               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
836                                                   QObject::tr("SMESH_WRN_WARNING"),
837                                                   QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
838                                                   QObject::tr("SMESH_BUT_YES"),
839                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
840               if (aRet == 0)
841               {
842                 toOverwrite = true;
843                 //MESSAGE("incompatible MED file version for add, overwrite accepted");
844               }
845               else
846               {
847                 isOkToWrite = false;
848                 is_ok = false;
849                 //MESSAGE("incompatible MED file version for add, overwrite refused");
850               }
851             }
852             QStringList aMeshNamesCollisionList;
853             SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() );
854             for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
855               QString anExistingMeshName( aMeshNames[ i ] );
856               for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
857                 QString anExportMeshName = (*aMeshIter).second;
858                 if( anExportMeshName == anExistingMeshName ) {
859                   aMeshNamesCollisionList.append( anExportMeshName );
860                   break;
861                 }
862               }
863             }
864             if( !aMeshNamesCollisionList.isEmpty() ) {
865               isOkToWrite = false;
866               QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
867               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
868                                                   QObject::tr("SMESH_WRN_WARNING"),
869                                                   QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
870                                                   QObject::tr("SMESH_BUT_YES"),
871                                                   QObject::tr("SMESH_BUT_NO"),
872                                                   QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
873               MESSAGE("answer collision name " << aRet);
874               if (aRet == 0) {
875                 toOverwrite = true;
876                 isOkToWrite = true;
877               }
878               else if (aRet == 2)
879                 is_ok = false;
880             }
881           }
882         }
883       }
884       toCreateGroups = fd->IsChecked(0);
885       toFindOutDim   = fd->IsChecked(1);
886       zTol           = zTolCheck->isChecked() ? zTolSpin->value() : -1;
887       fieldSelWdg->GetSelectedFields();
888       if ( resMgr ) resMgr->setValue( "SMESH", "enable_ztolerance", zTolCheck->isChecked() );
889
890       if ( !fieldSelWdg->parent() )
891         delete fieldSelWdg;
892       if ( !zTolWdg->parent() )
893         delete zTolWdg;
894       delete fd;
895     }
896     else
897     {
898       return;
899     }
900
901     // Perform export
902
903     if ( !aFilename.isEmpty() ) {
904       // Check whether the file already exists and delete it if yes
905       QFile aFile( aFilename );
906       if ( aFile.exists() && toOverwrite )
907         aFile.remove();
908       SUIT_OverrideCursor wc;
909
910       try {
911         // Renumbering is not needed since SMDS redesign in V6.2.0 (Nov 2010)
912         //         bool Renumber = false;
913         //         // PAL 14172  : Check of we have to renumber or not from the preferences before export
914         //         if (resMgr)
915         //           Renumber= resMgr->booleanValue("renumbering");
916         //         if (Renumber){
917         //           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
918 //           aMeshEditor->RenumberNodes();
919 //           aMeshEditor->RenumberElements();
920 //           if ( SMESHGUI::automaticUpdate() )
921 //             SMESH::UpdateView();
922 //         }
923         if ( isMED && isOkToWrite)
924         {
925           MESSAGE("OK to write MED file "<< aFilename.toUtf8().constData());
926           aMeshIter = aMeshList.begin();
927           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
928           {
929             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
930             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
931             const GEOM::ListOfFields&       fields = aFieldList[ aMeshIndex ].first.in();
932             const QString&            geoAssFields = aFieldList[ aMeshIndex ].second;
933             const bool                   hasFields = ( fields.length() || !geoAssFields.isEmpty() );
934             if ( !hasFields && aMeshOrGroup->_is_equivalent( aMeshItem ) && zTol < 0 )
935               aMeshItem->ExportMED( aFilename.toUtf8().data(), toCreateGroups, aFormat,
936                                     toOverwrite && aMeshIndex == 0, toFindOutDim );
937             else
938               aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(),
939                                           toCreateGroups, aFormat,
940                                           toOverwrite && aMeshIndex == 0, toFindOutDim,
941                                           fields, geoAssFields.toLatin1().data(), zTol );
942           }
943         }
944         else if ( isSAUV )
945         {
946           for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ )
947           {
948             SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
949             if( !aMeshItem->_is_nil() )
950               aMeshItem->ExportSAUV( aFilename.toUtf8().data(), toCreateGroups );
951           }
952         }
953         else if ( isDAT )
954         {
955           if ( aMeshOrGroup->_is_equivalent( aMesh ))
956             aMesh->ExportDAT( aFilename.toUtf8().data() );
957           else
958             aMesh->ExportPartToDAT( aMeshOrGroup, aFilename.toUtf8().data() );
959         }
960         else if ( isUNV )
961         {
962           if ( aMeshOrGroup->_is_equivalent( aMesh ))
963             aMesh->ExportUNV( aFilename.toUtf8().data() );
964           else
965             aMesh->ExportPartToUNV( aMeshOrGroup, aFilename.toUtf8().data() );
966         }
967         else if ( isSTL )
968         {
969           if ( aMeshOrGroup->_is_equivalent( aMesh ))
970             aMesh->ExportSTL( aFilename.toUtf8().data(), aIsASCII_STL );
971           else
972             aMesh->ExportPartToSTL( aMeshOrGroup, aFilename.toUtf8().data(), aIsASCII_STL );
973         }
974         else if ( isCGNS )
975         {
976           aMeshIter = aMeshList.begin();
977           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
978           {
979             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
980             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
981             aMeshItem->ExportCGNS( aMeshOrGroup,
982                                    aFilename.toUtf8().data(),
983                                    toOverwrite && aMeshIndex == 0,
984                                    toCreateGroups );
985           }
986         }
987         else if ( isGMF )
988         {
989           toCreateGroups = true;
990           aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
991         }
992       }
993       catch (const SALOME::SALOME_Exception& S_ex){
994         wc.suspend();
995         SUIT_MessageBox::warning(SMESHGUI::desktop(),
996                                  QObject::tr("SMESH_WRN_WARNING"),
997                                  QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex));
998         wc.resume();
999       }
1000     }
1001   }
1002
1003   inline void InverseEntityMode(unsigned int& theOutputMode,
1004                                 unsigned int  theMode)
1005   {
1006     bool anIsNotPresent = ~theOutputMode & theMode;
1007     if(anIsNotPresent)
1008       theOutputMode |= theMode;
1009     else
1010       theOutputMode &= ~theMode;
1011   }
1012
1013   void SetDisplayEntity(int theCommandID)
1014   {
1015     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1016     SALOME_ListIO selected;
1017     if ( aSel )
1018       aSel->selectedObjects( selected );
1019
1020     if ( selected.Extent() >= 1 ) {
1021       SUIT_OverrideCursor wc;
1022       SALOME_ListIteratorOfListIO It( selected );
1023       for( ; It.More(); It.Next()){
1024         Handle(SALOME_InteractiveObject) IObject = It.Value();
1025         if(IObject->hasEntry()){
1026           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1027             unsigned int aMode = anActor->GetEntityMode();
1028             switch(theCommandID){
1029             case SMESHOp::OpDE0DElements: InverseEntityMode(aMode,SMESH_Actor::e0DElements); break;
1030             case SMESHOp::OpDEEdges:      InverseEntityMode(aMode,SMESH_Actor::eEdges); break;
1031             case SMESHOp::OpDEFaces:      InverseEntityMode(aMode,SMESH_Actor::eFaces); break;
1032             case SMESHOp::OpDEVolumes:    InverseEntityMode(aMode,SMESH_Actor::eVolumes); break;
1033             case SMESHOp::OpDEBalls:      InverseEntityMode(aMode,SMESH_Actor::eBallElem); break;
1034             case SMESHOp::OpDEAllEntity:  aMode = SMESH_Actor::eAllEntity; break;
1035             }
1036             if(aMode)
1037               anActor->SetEntityMode(aMode);
1038           }
1039         }
1040       }
1041     }
1042   }
1043
1044   void AutoColor()
1045   {
1046     SalomeApp_Application* app =
1047       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1048     if ( !app )
1049       return;
1050
1051     LightApp_SelectionMgr* aSel = app->selectionMgr();
1052     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1053     if ( !aSel || !appStudy )
1054       return;
1055
1056     SALOME_ListIO selected;
1057     aSel->selectedObjects( selected );
1058     if ( selected.IsEmpty() )
1059       return;
1060
1061     Handle(SALOME_InteractiveObject) anIObject = selected.First();
1062
1063     _PTR(Study)         aStudy = appStudy->studyDS();
1064     _PTR(SObject) aMainSObject = aStudy->FindObjectID( anIObject->getEntry() );
1065     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1066     if ( aMainObject->_is_nil() )
1067       return;
1068
1069     SUIT_OverrideCursor wc;
1070
1071     aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
1072
1073     QList<SALOMEDS::Color> aReservedColors;
1074
1075     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
1076     for ( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1077     {
1078       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1079
1080 #ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
1081       SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
1082 #else                     // old algorithm  for auto-colors
1083       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1084       aReservedColors.append( aColor );
1085 #endif                    // SIMPLE_AUTOCOLOR
1086       aGroupObject->SetColor( aColor );
1087
1088       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
1089       if ( aGroupSObject ) {
1090         QColor c;
1091         int delta;
1092         if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
1093           switch ( aGroupObject->GetType ()) {
1094           case SMESH::NODE:
1095             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1096           case SMESH::EDGE:
1097             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1098           case SMESH::ELEM0D:
1099             anActor->Set0DColor( aColor.R, aColor.G, aColor.B ); break;
1100           case SMESH::BALL:
1101             anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1102           case SMESH::VOLUME:
1103             SMESH::GetColor("SMESH", "volume_color", c, delta, "255,0,170|-100");
1104             anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1105           case SMESH::FACE:
1106           default:
1107             SMESH::GetColor("SMESH", "fill_color", c, delta, "0,170,255|-100");
1108             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta );
1109           }
1110         }
1111       }
1112     }
1113
1114     SMESH::RepaintCurrentView();
1115   }
1116
1117   void OverallMeshQuality()
1118   {
1119     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1120     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1121     SALOME_ListIO selected;
1122     if( aSel )
1123       aSel->selectedObjects( selected );
1124
1125     if ( selected.IsEmpty() ) return;
1126     SALOME_ListIteratorOfListIO It( selected );
1127     for ( ; It.More(); It.Next() ) {
1128       SMESHGUI_CtrlInfoDlg* ctrlDlg = new SMESHGUI_CtrlInfoDlg( SMESHGUI::desktop() );
1129       ctrlDlg->showInfo( It.Value() );
1130       ctrlDlg->show();
1131     }
1132   }
1133
1134   QString functorToString( SMESH::Controls::FunctorPtr f )
1135   {
1136     QString type = QObject::tr( "UNKNOWN_CONTROL" );
1137     if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
1138       type = QObject::tr( "VOLUME_3D_ELEMENTS" );
1139     else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
1140       type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
1141     else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
1142       type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
1143     else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
1144       type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
1145     else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
1146       type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
1147     else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
1148       type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
1149     else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
1150       type = QObject::tr( "WARP_ELEMENTS" );
1151     else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
1152       type = QObject::tr( "TAPER_ELEMENTS" );
1153     else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
1154       type = QObject::tr( "SKEW_ELEMENTS" );
1155     else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
1156       type = QObject::tr( "AREA_ELEMENTS" );
1157     else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
1158       type = QObject::tr( "LENGTH_EDGES" );
1159     else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
1160       type = QObject::tr( "LENGTH2D_EDGES" );
1161     else if ( dynamic_cast< SMESH::Controls::Deflection2D* >( f.get() ) )
1162       type = QObject::tr( "DEFLECTION2D_FACES" );
1163     else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
1164       type = QObject::tr( "MULTI_BORDERS" );
1165     else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
1166       type = QObject::tr( "MULTI2D_BORDERS" );
1167     else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
1168       type = QObject::tr( "FREE_NODES" );
1169     else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
1170       type = QObject::tr( "FREE_EDGES" );
1171     else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
1172       type = QObject::tr( "FREE_BORDERS" );
1173     else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
1174       type = QObject::tr( "FREE_FACES" );
1175     else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
1176       type = QObject::tr( "BARE_BORDER_VOLUME" );
1177     else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
1178       type = QObject::tr( "BARE_BORDER_FACE" );
1179     else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
1180       type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
1181     else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
1182       type = QObject::tr( "OVER_CONSTRAINED_FACE" );
1183     else if ( dynamic_cast< SMESH::Controls::CoincidentNodes* >( f.get() ) )
1184       type = QObject::tr( "EQUAL_NODE" );
1185     else if ( dynamic_cast< SMESH::Controls::CoincidentElements1D* >( f.get() ) )
1186       type = QObject::tr( "EQUAL_EDGE" );
1187     else if ( dynamic_cast< SMESH::Controls::CoincidentElements2D* >( f.get() ) )
1188       type = QObject::tr( "EQUAL_FACE" );
1189     else if ( dynamic_cast< SMESH::Controls::CoincidentElements3D* >( f.get() ) )
1190       type = QObject::tr( "EQUAL_VOLUME" );
1191     else if ( dynamic_cast< SMESH::Controls::NodeConnectivityNumber* >( f.get() ) )
1192       type = QObject::tr( "NODE_CONNECTIVITY_NB" );
1193     return type;
1194   }
1195
1196   void SaveDistribution()
1197   {
1198     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1199     SALOME_ListIO selected;
1200     if ( aSel )
1201       aSel->selectedObjects( selected );
1202
1203     if ( selected.Extent() == 1 ) {
1204       Handle(SALOME_InteractiveObject) anIO = selected.First();
1205       if ( anIO->hasEntry() ) {
1206         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1207         if ( anActor &&
1208              anActor->GetScalarBarActor() &&
1209              anActor->GetControlMode() != SMESH_Actor::eNone )
1210         {
1211           SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
1212           SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
1213           if ( aScalarBarActor && aFunctor ) {
1214             SMESH::Controls::NumericalFunctor* aNumFun =
1215               dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
1216             if ( aNumFun ) {
1217               std::vector<int> elements;
1218               SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
1219               if ( mesh->_is_nil() ) {
1220                 SMESH::SMESH_IDSource_var idSource =
1221                   SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
1222                 if ( !idSource->_is_nil() )
1223                 {
1224                   SMESH::long_array_var ids = idSource->GetIDs();
1225                   elements.resize( ids->length() );
1226                   for ( unsigned i = 0; i < elements.size(); ++i )
1227                     elements[i] = ids[i];
1228                 }
1229               }
1230               int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
1231               vtkLookupTable* lookupTable =
1232                 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
1233               double * minmax = lookupTable->GetRange();
1234               bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
1235               std::vector<int>    nbEvents;
1236               std::vector<double> funValues;
1237               aNumFun->GetHistogram( nbIntervals, nbEvents, funValues,
1238                                      elements, minmax, isLogarithmic );
1239               QString anInitialPath = "";
1240               if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
1241                 anInitialPath = QDir::currentPath();
1242               QString aMeshName = anIO->getName();
1243               QStringList filter;
1244               filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
1245               filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
1246               QString aFilename = anInitialPath + "/" + aMeshName + "_" +
1247                 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
1248               aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
1249                                                      aFilename,
1250                                                      filter,
1251                                                      QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
1252                                                      false );
1253               if ( !aFilename.isEmpty() ) {
1254                 QFile f( aFilename );
1255                 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
1256                   QTextStream out( &f );
1257                   out << "# Mesh: " << aMeshName << endl;
1258                   out << "# Control: " << functorToString( aFunctor ) << endl;
1259                   out << "#" << endl;
1260                   out.setFieldWidth( 10 );
1261                   for ( int i = 0; i < (int)qMin( nbEvents.size(), funValues.size()-1 ); i++ )
1262                     out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
1263                   f.close();
1264                 }
1265               }
1266             }
1267           }
1268         }
1269       }
1270     }
1271   }
1272
1273   void ShowElement( int theCommandID )
1274   {
1275     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1276     SALOME_ListIO selected;
1277     if ( aSel )
1278       aSel->selectedObjects( selected );
1279
1280     if ( selected.Extent() == 1 ) {
1281       Handle(SALOME_InteractiveObject) anIO = selected.First();
1282       if ( anIO->hasEntry() ) {
1283         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1284         if ( anActor &&
1285              anActor->GetScalarBarActor() &&
1286              anActor->GetControlMode() != SMESH_Actor::eNone )
1287         {
1288           SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
1289           if ( theCommandID == SMESHOp::OpShowDistribution ) {
1290             aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
1291           }
1292           else if ( theCommandID == SMESHOp::OpShowScalarBar ) {
1293             aScalarBarActor->SetVisibility( !aScalarBarActor->GetVisibility());
1294           }
1295         }
1296       }
1297     }
1298   }
1299
1300 #ifndef DISABLE_PLOT2DVIEWER
1301   void PlotDistribution()
1302   {
1303     SalomeApp_Application* app =
1304       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1305     if( !app )
1306       return;
1307
1308     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1309     SALOME_ListIO selected;
1310     if ( aSel )
1311       aSel->selectedObjects( selected );
1312
1313     if ( selected.Extent() == 1 ) {
1314       Handle(SALOME_InteractiveObject) anIO = selected.First();
1315       if ( anIO->hasEntry() ) {
1316         //Find Actor by entry before getting Plot2d viewer,
1317         //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
1318         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1319
1320         SUIT_ViewManager* aViewManager =
1321           app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
1322         if( !aViewManager )
1323           return;
1324
1325         SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
1326         if ( !aView )
1327           return;
1328
1329         Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1330         if ( !aPlot )
1331           return;
1332
1333         if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone )
1334         {
1335           SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1336           QString functorName = functorToString( anActor->GetFunctor());
1337           QString aHistogramName("%1 : %2");
1338           aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1339           aHistogram->setName(aHistogramName);
1340           aHistogram->setHorTitle(functorName);
1341           aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
1342           aPlot->displayObject(aHistogram, true);
1343         }
1344       }
1345     }
1346   }
1347 #endif //DISABLE_PLOT2DVIEWER
1348
1349   void DisableAutoColor()
1350   {
1351     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1352     SALOME_ListIO selected;
1353     if ( aSel )
1354       aSel->selectedObjects( selected );
1355
1356     if ( selected.Extent() ) {
1357       Handle(SALOME_InteractiveObject) anIObject = selected.First();
1358       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1359       if ( !aMesh->_is_nil() ) {
1360         aMesh->SetAutoColor( false );
1361       }
1362     }
1363   }
1364
1365   void sortChildren()
1366   {
1367     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1368     SALOME_ListIO selected;
1369     if ( aSel ) {
1370       aSel->selectedObjects( selected );
1371       if ( selected.Extent() )
1372       {
1373         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1374         _PTR(Study) aStudy = SMESH::getStudy();
1375         _PTR(SObject) aSObj = aStudy->FindObjectID(anIObject->getEntry());
1376         if (aSObj) {
1377           if ( aStudy->GetUseCaseBuilder()->SortChildren( aSObj, true/*AscendingOrder*/ ) ) {
1378             SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1379           }
1380         }
1381       }
1382     }
1383   }
1384
1385   // Break link with Shaper model
1386   void breakShaperLink()
1387   {
1388     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1389     SALOME_ListIO selected;
1390     if (aSel) {
1391       aSel->selectedObjects(selected);
1392       if (selected.Extent()) {
1393         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1394         _PTR(Study) aStudy = SMESH::getStudy();
1395         _PTR(SObject) aSObj = aStudy->FindObjectID(anIObject->getEntry());
1396         if (aSObj) {
1397           std::string aName = aSObj->GetName();
1398           QMessageBox::StandardButton aRes = SUIT_MessageBox::warning(SMESHGUI::desktop(),
1399             QObject::tr("SMESH_WRN_WARNING"),
1400             QObject::tr("MSG_BREAK_SHAPER_LINK").arg(aName.c_str()),
1401             SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No);
1402           if (aRes == SUIT_MessageBox::Yes) {
1403             GEOM::GEOM_Object_var aObject = SMESH::SObjectToInterface<GEOM::GEOM_Object>(aSObj);
1404             if (!aObject->_is_nil())
1405               aObject->BreakLinks();
1406           }
1407         }
1408       }
1409     }
1410   }
1411
1412   void SetDisplayMode(int theCommandID, VTK::MarkerMap& theMarkerMap)
1413   {
1414     SALOME_ListIO selected;
1415     SalomeApp_Application* app =
1416       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1417     if ( !app )
1418       return;
1419
1420     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1421     SalomeApp_Study*   appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1422     if ( !aSel || !appStudy )
1423       return;
1424
1425     if ( theCommandID == SMESHOp::OpClipping ) { // Clipping dialog can be activated without selection
1426       if ( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
1427         aModule->EmitSignalDeactivateDialog();
1428         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
1429           (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
1430       }
1431       return;
1432     }
1433
1434     aSel->selectedObjects( selected );
1435
1436     if ( selected.Extent() >= 1 )
1437     {
1438       switch ( theCommandID ) {
1439       case SMESHOp::OpTransparency:
1440       {
1441         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1442         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
1443         return;
1444       }
1445       case SMESHOp::OpProperties:
1446       {
1447         double color[3];
1448         QColor faceColor, edgeColor, nodeColor, elem0dColor, ballColor;
1449         QColor orientationColor, outlineColor, volumeColor;
1450         int deltaF = 0, deltaV = 0;
1451         int elem0dSize   = 1;
1452         //int ballSize     = 1;
1453         double ballScale = 1.0;
1454         int edgeWidth    = 1;
1455         int outlineWidth = 1;
1456         double shrinkCoef = 0.0;
1457         double orientationScale = 0.0;
1458         bool orientation3d = false;
1459         VTK::MarkerType markerType = VTK::MT_NONE;
1460         VTK::MarkerScale markerScale = VTK::MS_NONE;
1461         int markerId = 0;
1462         bool hasNodes = false;
1463         int presentEntities = 0;
1464         bool firstTime  = true;
1465
1466         SALOME_ListIteratorOfListIO It( selected );
1467         for ( ; It.More(); It.Next() ) {
1468           Handle(SALOME_InteractiveObject) IObject = It.Value();
1469           if ( !IObject->hasEntry() ) continue;
1470           SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1471           if ( !anActor || !anActor->GetObject() ) continue;
1472
1473           if ( firstTime ) {
1474             // nodes: color, marker
1475             anActor->GetNodeColor( color[0], color[1], color[2] );
1476             nodeColor.setRgbF( color[0], color[1], color[2] );
1477             markerType  = anActor->GetMarkerType();
1478             markerScale = anActor->GetMarkerScale();
1479             markerId    = anActor->GetMarkerTexture();
1480             // edges: color, width
1481             anActor->GetEdgeColor( color[0], color[1], color[2] );
1482             edgeColor.setRgbF( color[0], color[1], color[2] );
1483             edgeWidth = qMax( (int)anActor->GetLineWidth(), 1 ); // minimum allowed width is 1
1484             // faces: front color, back color (delta)
1485             anActor->GetSufaceColor( color[0], color[1], color[2], deltaF );
1486             faceColor.setRgbF( color[0], color[1], color[2] );
1487             // faces: front color, back color (delta)
1488             anActor->GetVolumeColor( color[0], color[1], color[2], deltaV );
1489             volumeColor.setRgbF( color[0], color[1], color[2] );
1490             // 0d elements: color, size
1491             anActor->Get0DColor( color[0], color[1], color[2] );
1492             elem0dColor.setRgbF( color[0], color[1], color[2] );
1493             elem0dSize = qMax( (int)anActor->Get0DSize(), 1 ); // minimum allowed size is 1
1494             // balls: color, size
1495             anActor->GetBallColor( color[0], color[1], color[2] );
1496             ballColor.setRgbF( color[0], color[1], color[2] );
1497             //ballSize = qMax( (int)anActor->GetBallSize(), 1 ); // minimum allowed size is 1
1498             ballScale = qMax( (double)anActor->GetBallScale(), 1e-2 ); // minimum allowed scale is 1e-2
1499             // outlines: color
1500             anActor->GetOutlineColor( color[0], color[1], color[2] );
1501             outlineColor.setRgbF( color[0], color[1], color[2] );
1502             outlineWidth = qMax( (int)anActor->GetOutlineWidth(), 1 ); // minimum allowed width is 1
1503             // orientation vectors: color, scale, 3d flag
1504             anActor->GetFacesOrientationColor( color[0], color[1], color[2] );
1505             orientationColor.setRgbF( color[0], color[1], color[2] );
1506             orientationScale = anActor->GetFacesOrientationScale();
1507             orientation3d = anActor->GetFacesOrientation3DVectors();
1508             // shrink factor
1509             shrinkCoef = anActor->GetShrinkFactor();
1510           }
1511
1512           firstTime = false; // we only take properties from first object (for performance reasons)
1513
1514           if ( !hasNodes )
1515             hasNodes = anActor->GetObject()->GetNbEntities( SMDSAbs_Node );
1516           if ( !(presentEntities & SMESH_Actor::eEdges) && anActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) )
1517             presentEntities = presentEntities | SMESH_Actor::eEdges;
1518           if ( !(presentEntities & SMESH_Actor::eFaces) && anActor->GetObject()->GetNbEntities( SMDSAbs_Face ) )
1519             presentEntities = presentEntities | SMESH_Actor::eFaces;
1520           if ( !(presentEntities & SMESH_Actor::eVolumes) && anActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) )
1521             presentEntities = presentEntities | SMESH_Actor::eVolumes;
1522           if ( !(presentEntities & SMESH_Actor::e0DElements) && anActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) )
1523             presentEntities = presentEntities | SMESH_Actor::e0DElements;
1524           if ( !(presentEntities & SMESH_Actor::eBallElem) && anActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) )
1525             presentEntities = presentEntities | SMESH_Actor::eBallElem;
1526
1527           // as we know that all types of elements are present, we can exit the loop
1528           if ( presentEntities == SMESH_Actor::eAllEntity )
1529             break;
1530         }
1531
1532         SMESHGUI_PropertiesDlg dlg( theMarkerMap, SMESHGUI::desktop() );
1533         // nodes: color, marker
1534         dlg.setNodeColor( nodeColor );
1535         if( markerType != VTK::MT_USER )
1536           dlg.setNodeMarker( markerType, markerScale );
1537         else
1538           dlg.setNodeCustomMarker( markerId );
1539         // edges: color, line width
1540         dlg.setEdgeColor( edgeColor );
1541         dlg.setEdgeWidth( edgeWidth );
1542         // faces: front color, back color
1543         dlg.setFaceColor( faceColor, deltaF );
1544         // volumes: normal color, reversed color
1545         dlg.setVolumeColor( volumeColor, deltaV );
1546         // outlines: color, line width
1547         dlg.setOutlineColor( outlineColor );
1548         dlg.setOutlineWidth( outlineWidth );
1549         // 0d elements: color, size
1550         dlg.setElem0dColor( elem0dColor );
1551         dlg.setElem0dSize( elem0dSize );
1552         // balls: color, size
1553         dlg.setBallColor( ballColor );
1554         //dlg.setBallSize( ballSize );
1555         dlg.setBallScale( ballScale );
1556         // orientation: color, scale, 3d flag
1557         dlg.setOrientationColor( orientationColor );
1558         dlg.setOrientationSize( int( orientationScale * 100. ) );
1559         dlg.setOrientation3d( orientation3d );
1560         // shrink: scale factor
1561         dlg.setShrinkCoef( int( shrinkCoef * 100. ) );
1562         // hide unused controls
1563         dlg.showControls( presentEntities, hasNodes );
1564
1565         if ( dlg.exec() ) {
1566           nodeColor        = dlg.nodeColor();
1567           markerType       = dlg.nodeMarkerType();
1568           markerScale      = dlg.nodeMarkerScale();
1569           markerId         = dlg.nodeMarkerId();
1570           edgeColor        = dlg.edgeColor();
1571           edgeWidth        = dlg.edgeWidth();
1572           faceColor        = dlg.faceColor();
1573           deltaF           = dlg.faceColorDelta();
1574           volumeColor      = dlg.volumeColor();
1575           deltaV           = dlg.volumeColorDelta();
1576           outlineColor     = dlg.outlineColor();
1577           outlineWidth     = dlg.outlineWidth();
1578           elem0dColor      = dlg.elem0dColor();
1579           elem0dSize       = dlg.elem0dSize();
1580           ballColor        = dlg.ballColor();
1581          // ballSize         = dlg.ballSize();
1582           ballScale        = dlg.ballScale();
1583           orientationColor = dlg.orientationColor();
1584           orientationScale = dlg.orientationSize() / 100.;
1585           orientation3d    = dlg.orientation3d();
1586           shrinkCoef       = dlg.shrinkCoef() / 100.;
1587
1588           // store point markers that might be changed by the user
1589           theMarkerMap = dlg.customMarkers();
1590
1591           // set properties from dialog box to the presentations
1592           SALOME_ListIteratorOfListIO It( selected );
1593           for ( ; It.More(); It.Next() ) {
1594             Handle(SALOME_InteractiveObject) IObject = It.Value();
1595             if ( !IObject->hasEntry() ) continue;
1596             SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1597             if ( !anActor ) continue;
1598
1599             // nodes: color, marker
1600             anActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
1601             if ( markerType != VTK::MT_USER ) {
1602               anActor->SetMarkerStd( markerType, markerScale );
1603             }
1604             else {
1605               VTK::MarkerMap::const_iterator iter = theMarkerMap.find( markerId );
1606               if ( iter != theMarkerMap.end() )
1607                 anActor->SetMarkerTexture( markerId, iter->second.second );
1608             }
1609             // volumes: normal color, reversed color (delta)
1610             anActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
1611             // faces: front color, back color (delta)
1612             anActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
1613             // edges: color, width
1614             anActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
1615             anActor->SetLineWidth( edgeWidth );
1616             // outlines: color
1617             anActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
1618             anActor->SetOutlineWidth( outlineWidth );
1619             // 0D elements: color, size
1620             anActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
1621             anActor->Set0DSize( elem0dSize );
1622             // balls: color, size
1623             anActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
1624             // anActor->SetBallSize( ballSize );
1625             anActor->SetBallScale( ballScale );
1626             // orientation: color, scale, 3d flag
1627             anActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
1628             anActor->SetFacesOrientationScale( orientationScale );
1629             anActor->SetFacesOrientation3DVectors( orientation3d );
1630             // shrink factor
1631             anActor->SetShrinkFactor( shrinkCoef );
1632
1633             // for groups, set also proper color
1634             SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1635             if ( !aGroupObject->_is_nil() ) {
1636               SMESH::ElementType anElementType = aGroupObject->GetType();
1637               QColor aColor;
1638               switch( anElementType ) {
1639               case SMESH::NODE:
1640                 aColor = nodeColor; break;
1641               case SMESH::EDGE:
1642                 aColor = edgeColor; break;
1643               case SMESH::FACE:
1644                 aColor = faceColor; break;
1645               case SMESH::VOLUME:
1646                 aColor = volumeColor; break;
1647               case SMESH::ELEM0D:
1648                 aColor = elem0dColor; break;
1649               case SMESH::BALL:
1650                 aColor = ballColor; break;
1651               default: break;
1652               }
1653
1654               if ( aColor.isValid() ) {
1655                 SALOMEDS::Color aGroupColor;
1656                 aGroupColor.R = aColor.redF();
1657                 aGroupColor.G = aColor.greenF();
1658                 aGroupColor.B = aColor.blueF();
1659                 aGroupObject->SetColor( aGroupColor );
1660               }
1661             } // if ( !aGroupObject->_is_nil() )
1662           } // for ( ; It.More(); It.Next() )
1663           SMESH::RepaintCurrentView();
1664         } // if ( dlg.exec() )
1665         return;
1666       } // case SMESHOp::OpProperties:
1667       } // switch(theCommandID)
1668       SUIT_OverrideCursor wc;
1669       SALOME_ListIteratorOfListIO It( selected );
1670       for( ; It.More(); It.Next()){
1671         Handle(SALOME_InteractiveObject) IObject = It.Value();
1672         if(IObject->hasEntry()){
1673           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1674             switch(theCommandID){
1675             case SMESHOp::OpDMWireframe:
1676               anActor->SetRepresentation(SMESH_Actor::eEdge);
1677               break;
1678             case SMESHOp::OpDMShading:
1679               anActor->SetRepresentation(SMESH_Actor::eSurface);
1680               break;
1681             case SMESHOp::OpDMShrink:
1682               if(anActor->IsShrunk())
1683                 anActor->UnShrink();
1684               else
1685                 anActor->SetShrink();
1686               break;
1687             case SMESHOp::OpDMNodes:
1688               anActor->SetRepresentation(SMESH_Actor::ePoint);
1689               break;
1690             case SMESHOp::OpRepresentationLines:
1691               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1692                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1693               break;
1694             case SMESHOp::OpRepresentationArcs:
1695               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1696                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1697               break;
1698             }
1699           }
1700         }
1701       }
1702       SMESH::RepaintCurrentView();
1703     }
1704   }
1705
1706   int ActionToControl( int theID, bool theReversed )
1707   {
1708     NCollection_DoubleMap<int,int> ActionControl;
1709     ActionControl.Bind( 0,                                SMESH_Actor::eNone );
1710     ActionControl.Bind( SMESHOp::OpFreeNode,              SMESH_Actor::eFreeNodes );
1711     ActionControl.Bind( SMESHOp::OpEqualNode,             SMESH_Actor::eCoincidentNodes );
1712     ActionControl.Bind( SMESHOp::OpNodeConnectivityNb,    SMESH_Actor::eNodeConnectivityNb );
1713     ActionControl.Bind( SMESHOp::OpFreeEdge,              SMESH_Actor::eFreeEdges );
1714     ActionControl.Bind( SMESHOp::OpFreeBorder,            SMESH_Actor::eFreeBorders );
1715     ActionControl.Bind( SMESHOp::OpLength,                SMESH_Actor::eLength );
1716     ActionControl.Bind( SMESHOp::OpConnection,            SMESH_Actor::eMultiConnection );
1717     ActionControl.Bind( SMESHOp::OpEqualEdge,             SMESH_Actor::eCoincidentElems1D );
1718     ActionControl.Bind( SMESHOp::OpFreeFace,              SMESH_Actor::eFreeFaces );
1719     ActionControl.Bind( SMESHOp::OpBareBorderFace,        SMESH_Actor::eBareBorderFace );
1720     ActionControl.Bind( SMESHOp::OpOverConstrainedFace,   SMESH_Actor::eOverConstrainedFace );
1721     ActionControl.Bind( SMESHOp::OpLength2D,              SMESH_Actor::eLength2D );
1722     ActionControl.Bind( SMESHOp::OpDeflection2D,          SMESH_Actor::eDeflection2D );
1723     ActionControl.Bind( SMESHOp::OpConnection2D,          SMESH_Actor::eMultiConnection2D );
1724     ActionControl.Bind( SMESHOp::OpArea,                  SMESH_Actor::eArea );
1725     ActionControl.Bind( SMESHOp::OpTaper,                 SMESH_Actor::eTaper );
1726     ActionControl.Bind( SMESHOp::OpAspectRatio,           SMESH_Actor::eAspectRatio );
1727     ActionControl.Bind( SMESHOp::OpMinimumAngle,          SMESH_Actor::eMinimumAngle );
1728     ActionControl.Bind( SMESHOp::OpWarpingAngle,          SMESH_Actor::eWarping );
1729     ActionControl.Bind( SMESHOp::OpSkew,                  SMESH_Actor::eSkew );
1730     ActionControl.Bind( SMESHOp::OpMaxElementLength2D,    SMESH_Actor::eMaxElementLength2D );
1731     ActionControl.Bind( SMESHOp::OpEqualFace,             SMESH_Actor::eCoincidentElems2D );
1732     ActionControl.Bind( SMESHOp::OpAspectRatio3D,         SMESH_Actor::eAspectRatio3D );
1733     ActionControl.Bind( SMESHOp::OpVolume,                SMESH_Actor::eVolume3D );
1734     ActionControl.Bind( SMESHOp::OpMaxElementLength3D,    SMESH_Actor::eMaxElementLength3D );
1735     ActionControl.Bind( SMESHOp::OpBareBorderVolume,      SMESH_Actor::eBareBorderVolume );
1736     ActionControl.Bind( SMESHOp::OpOverConstrainedVolume, SMESH_Actor::eOverConstrainedVolume );
1737     ActionControl.Bind( SMESHOp::OpEqualVolume,           SMESH_Actor::eCoincidentElems3D );
1738
1739     if ( theReversed )
1740       return ActionControl.IsBound2( theID ) ? ActionControl.Find2( theID ) : 0;
1741     return   ActionControl.IsBound1( theID ) ? ActionControl.Find1( theID ) : 0;
1742   }
1743
1744   void Control( int theCommandID )
1745   {
1746     SMESH_Actor::eControl aControl = SMESH_Actor::eControl( ActionToControl( theCommandID ));
1747     _PTR(Study) aStudy = SMESH::getStudy();
1748
1749     SALOME_ListIO selected;
1750     if ( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
1751       aSel->selectedObjects( selected );
1752
1753     if ( !selected.IsEmpty() ) {
1754       SALOME_ListIteratorOfListIO It(selected);
1755       for ( ; It.More(); It.Next())
1756       {
1757         Handle(SALOME_InteractiveObject) anIO = It.Value();
1758         if ( !anIO.IsNull() ) {
1759           _PTR(SObject) SO = aStudy->FindObjectID( It.Value()->getEntry() );
1760           if ( SO ) {
1761             CORBA::Object_var         aObject = SMESH::SObjectToObject( SO );
1762             SMESH::SMESH_IDSource_var anIDSrc = SMESH::SMESH_IDSource::_narrow( aObject );
1763             if ( !anIDSrc->_is_nil() ) {
1764               SMESH_Actor *anActor = SMESH::FindActorByEntry( anIO->getEntry());
1765               if (( !anActor && selected.Extent() == 1 ) &&
1766                   ( anActor = SMESH::CreateActor( anIO->getEntry() )))
1767               {
1768                 anActor->SetControlMode( aControl );
1769                 SMESH::DisplayActor( SMESH::GetCurrentVtkView(), anActor );
1770                 SMESH::UpdateView  ( SMESH::eDisplay, anIO->getEntry() );
1771               }
1772               if ( anActor )
1773               {
1774                 if ( anActor->GetControlMode() != aControl )
1775                   anActor->SetControlMode( aControl );
1776                 QString functorName = functorToString( anActor->GetFunctor() );
1777                 int anEntitiesCount = anActor->GetNumberControlEntities();
1778                 if (anEntitiesCount >= 0)
1779                   functorName = functorName + ": " + QString::number(anEntitiesCount);
1780                 anActor->GetScalarBarActor()->SetTitle( functorName.toUtf8().constData() );
1781                 SMESH::RepaintCurrentView();
1782 #ifndef DISABLE_PLOT2DVIEWER
1783                 if ( anActor->GetPlot2Histogram() ) {
1784                   SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1785                   QString aHistogramName("%1 : %2");
1786                   aHistogramName = aHistogramName.arg( anIO->getName() ).arg( functorName );
1787                   aHistogram->setName( aHistogramName );
1788                   aHistogram->setHorTitle( functorName );
1789                   SMESH::ProcessIn2DViewers( anActor );
1790                 }
1791 #endif
1792               }
1793             }
1794           }
1795         }
1796       }
1797     }
1798   }
1799
1800
1801   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1802                    SMESH::MeshObjectType                    theType,
1803                    const QString                            theInTypeName,
1804                    QString &                                theOutTypeName)
1805   {
1806     SMESH_TypeFilter aTypeFilter( theType );
1807     QString entry;
1808     if ( !theIO.IsNull() )
1809     {
1810       entry = theIO->getEntry();
1811       LightApp_DataOwner owner( entry );
1812       if ( aTypeFilter.isOk( &owner )) {
1813         theOutTypeName = theInTypeName;
1814         return true;
1815       }
1816     }
1817     return false;
1818   }
1819
1820
1821   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1822   {
1823     _PTR(Study)  aStudy = SMESH::getStudy();
1824     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1825     if (aSObj) {
1826       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1827       CORBA::String_var  anID = aSComp->GetID().c_str();
1828       if ( !strcmp(anID.in(),theIO->getEntry()) )
1829         return "Component";
1830     }
1831
1832     QString aTypeName;
1833     if (
1834         CheckOIType ( theIO, SMESH::HYPOTHESIS,    "Hypothesis", aTypeName ) ||
1835         CheckOIType ( theIO, SMESH::ALGORITHM,     "Algorithm",  aTypeName ) ||
1836         CheckOIType ( theIO, SMESH::MESH,          "Mesh",       aTypeName ) ||
1837         CheckOIType ( theIO, SMESH::SUBMESH,       "SubMesh",    aTypeName ) ||
1838         CheckOIType ( theIO, SMESH::GROUP,         "Group",      aTypeName )
1839         )
1840       return aTypeName;
1841
1842     return "NoType";
1843   }
1844
1845
1846   // QString CheckHomogeneousSelection()
1847   // {
1848   //   LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1849   //   SALOME_ListIO selected;
1850   //   if ( aSel )
1851   //     aSel->selectedObjects( selected );
1852
1853   //   QString RefType = CheckTypeObject(selected.First());
1854   //   SALOME_ListIteratorOfListIO It(selected);
1855   //   for ( ; It.More(); It.Next())
1856   //   {
1857   //     Handle(SALOME_InteractiveObject) IObject = It.Value();
1858   //     QString Type = CheckTypeObject(IObject);
1859   //     if ( Type.compare(RefType) != 0 )
1860   //       return "Heterogeneous Selection";
1861   //   }
1862
1863   //   return RefType;
1864   // }
1865
1866   uint randomize( uint size )
1867   {
1868     static bool initialized = false;
1869     if ( !initialized ) {
1870       qsrand( QDateTime::currentDateTime().toTime_t() );
1871       initialized = true;
1872     }
1873     uint v = qrand();
1874     v = uint( (double)( v ) / RAND_MAX * size );
1875     v = qMax( uint(0), qMin ( v, size-1 ) );
1876     return v;
1877   }
1878
1879 } //namespace
1880
1881 void SMESHGUI::OnEditDelete()
1882 {
1883   // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1884   LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1885   SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1886
1887   _PTR(Study) aStudy = SMESH::getStudy();
1888   _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1889   _PTR(GenericAttribute) anAttr;
1890   _PTR(AttributeIOR) anIOR;
1891
1892   const int objectCountLimit = 30; // PAL23599
1893   int objectCount = 0;
1894   QString aNameList;
1895   QString aParentComponent = QString::null;
1896   
1897   for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1898   {
1899     Handle(SALOME_InteractiveObject) anIO = anIt.Value();
1900     if ( anIO.IsNull() ) continue;
1901     
1902     QString father = "unknown", name;
1903
1904     _PTR(SObject) aSO = aStudy->FindObjectID( anIO->getEntry() );
1905     if (aSO) {
1906       father = QString::fromStdString( aSO->GetFatherComponent()->ComponentDataType() );
1907       // check if object is reference
1908       _PTR(SObject) aRefSObj;
1909       if ( aSO->ReferencedObject( aRefSObj ) ) {
1910         name = QString::fromStdString ( aRefSObj->GetName() );
1911         father = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1912       }
1913       else
1914         name = anIO->getName();
1915       objectCount++;
1916     }
1917     if ( objectCount < objectCountLimit ) { // avoid occupying the whole screen
1918       aNameList.append("\n    - ");
1919       aNameList.append( name );
1920     }
1921
1922     if( aParentComponent.isNull() )
1923       aParentComponent = father;
1924     else if( !aParentComponent.isEmpty() && aParentComponent!=father )
1925       aParentComponent = "";
1926   }
1927   if ( objectCount >= objectCountLimit )
1928     aNameList.append("\n    - ...");
1929
1930   if ( objectCount == 0 )
1931     return; // No Valid Objects Selected
1932
1933   if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
1934     SUIT_MessageBox::warning( SMESHGUI::desktop(),
1935                               QObject::tr("ERR_ERROR"),
1936                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1937     return;
1938   }
1939   // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1940   if (SUIT_MessageBox::warning
1941       (SMESHGUI::desktop(),
1942        QObject::tr("SMESH_WRN_WARNING"),
1943        QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1944        SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1945        SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1946     return;
1947
1948   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1949
1950   // Put one level of sub-objects of the selected SO's into a list
1951   // in order to get objects inside folders like "Assigned Algorithms"
1952   std::list< _PTR(SObject) > listSO;
1953   SALOME_ListIteratorOfListIO It(selected);
1954   for( ; It.More(); It.Next()) // loop on selected IO's
1955   {
1956     Handle(SALOME_InteractiveObject) IObject = It.Value();
1957     if(IObject->hasEntry()) {
1958       _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1959
1960       // disable removal of "SMESH" component object
1961       if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1962         anIOR = anAttr;
1963         if ( engineIOR() == anIOR->Value().c_str() )
1964           continue;
1965       }
1966       //Check the referenced object
1967       _PTR(SObject) aRefSObject;
1968       if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1969         aSO = aRefSObject; // Delete main Object instead of reference
1970
1971       listSO.push_back( aSO );
1972
1973       _PTR(ChildIterator) it = aStudy->NewChildIterator( aSO );
1974       for (it->InitEx(false); it->More(); it->Next())
1975         listSO.push_back( it->Value() );
1976     }
1977   }
1978   // Check if none of objects to delete is referred from outside
1979   std::list< _PTR(SObject) >::reverse_iterator ritSO;
1980   std::vector< _PTR(SObject) > subSO;
1981   for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1982   {
1983     _PTR(SObject) SO = *ritSO;
1984     if ( !SO ) continue;
1985
1986     int nbChildren = SO->GetLastChildTag();
1987     subSO.clear();
1988     subSO.reserve( 1 + nbChildren );
1989     subSO.push_back( SO );
1990     if ( nbChildren > 0 )
1991     {
1992       _PTR(ChildIterator) it = aStudy->NewChildIterator( SO );
1993       for ( it->InitEx( true ); it->More(); it->Next() )
1994         subSO.push_back( it->Value() );
1995     }
1996     for ( size_t i = 0; i < subSO.size(); ++i )
1997     {
1998       std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( subSO[i] );
1999       for ( size_t j = 0; j < aReferences.size(); j++ ) {
2000         _PTR(SComponent) aComponent = aReferences[j]->GetFatherComponent();
2001         std::string type = aComponent->ComponentDataType();
2002         if ( type != "SMESH" )
2003         {
2004           SUIT_MessageBox::warning( anApp->desktop(),
2005                                     QObject::tr("WRN_WARNING"),
2006                                     QObject::tr("DEP_OBJECT") );
2007           return; // outside SMESH, there is an object depending on a SMESH object
2008         }
2009       }
2010     }
2011   }
2012
2013   // Treat SO's in the list starting from the back
2014   aStudyBuilder->NewCommand();  // There is a transaction
2015   for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
2016   {
2017     _PTR(SObject) SO = *ritSO;
2018     if ( !SO ) continue;
2019     std::string anEntry = SO->GetID();
2020
2021     /** Erase graphical object and remove all its data **/
2022     if ( SO->FindAttribute( anAttr, "AttributeIOR" )) {
2023       SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true);
2024     }
2025     /** Remove an object from data structures **/
2026     SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
2027     SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
2028     if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
2029       SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
2030       aMesh->RemoveGroup( aGroup );
2031     }
2032     else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
2033       SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2034       aMesh->RemoveSubMesh( aSubMesh );
2035     }
2036     else {
2037       Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject
2038         ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
2039       QString objType = CheckTypeObject(IObject);
2040       if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
2041         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2042         aStudyBuilder->RemoveObjectWithChildren( SO );
2043       }
2044       else {// default action: remove SObject from the study
2045         // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
2046         //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
2047         //op->start();
2048         aStudyBuilder->RemoveObjectWithChildren( SO );
2049         //op->finish();
2050       }
2051     }
2052   } /* listSO back loop */
2053
2054   aStudyBuilder->CommitCommand();
2055
2056   /* Clear any previous selection */
2057   SALOME_ListIO l1;
2058   aSel->setSelectedObjects( l1 );
2059
2060   SMESHGUI::GetSMESHGUI()->updateObjBrowser();
2061 }
2062
2063 extern "C" {
2064   SMESHGUI_EXPORT CAM_Module* createModule()
2065   {
2066     return new SMESHGUI();
2067   }
2068
2069   SMESHGUI_EXPORT  char* getModuleVersion() {
2070     return (char*)SMESH_VERSION_STR;
2071   }
2072 }
2073
2074 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
2075
2076 //=============================================================================
2077 /*!
2078  *
2079  */
2080 //=============================================================================
2081 SMESHGUI::SMESHGUI() :
2082 SalomeApp_Module( "SMESH" )
2083 {
2084   if ( CORBA::is_nil( myComponentSMESH ) )
2085   {
2086     CORBA::Boolean anIsEmbeddedMode;
2087     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
2088     //MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
2089
2090     //  0019923: EDF 765 SMESH : default values of hypothesis
2091     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
2092     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
2093     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
2094     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
2095     myComponentSMESH->SetDefaultNbSegments( nbSeg );
2096
2097     const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif", "default_grp_color" };
2098     for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
2099       if ( aResourceMgr->hasValue( "SMESH", options[i] ))
2100       {
2101         QString val = aResourceMgr->stringValue( "SMESH", options[i] );
2102         myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
2103       }
2104   }
2105
2106   myActiveDialogBox = 0;
2107   myFilterLibraryDlg = 0;
2108   myState = -1;
2109   myDisplayer = 0;
2110
2111   myEventCallbackCommand = vtkCallbackCommand::New();
2112   myEventCallbackCommand->Delete();
2113   myEventCallbackCommand->SetClientData( this );
2114   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
2115   myPriority = 0.0;
2116
2117   /* load resources for all available meshers */
2118   SMESH::InitAvailableHypotheses();
2119 }
2120
2121 //=============================================================================
2122 /*!
2123  *
2124  */
2125 //=============================================================================
2126 SMESHGUI::~SMESHGUI()
2127 {
2128 }
2129
2130 //=============================================================================
2131 /*!
2132  *
2133  */
2134 //=============================================================================
2135 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
2136 {
2137   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2138   if( anApp )
2139     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2140   else
2141     return 0;
2142 }
2143
2144 //=============================================================================
2145 /*!
2146  *
2147  */
2148 //=============================================================================
2149 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
2150 {
2151   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2152   if ( !resMgr )
2153     return false;
2154
2155   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
2156   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2157   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2158   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2159   return autoUpdate && !exceeded;
2160 }
2161
2162 //=============================================================================
2163 /*!
2164  *
2165  */
2166 //=============================================================================
2167 bool SMESHGUI::automaticUpdate( SMESH::SMESH_IDSource_ptr theMesh,
2168                                 int* entities, bool* limitExceeded, int* hidden, long* nbElements )
2169 {
2170   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2171   if ( !resMgr )
2172     return false;
2173
2174   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update", false );
2175   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2176   bool incrementalLimit = resMgr->booleanValue( "SMESH", "incremental_limit", false );
2177
2178   SMESH::long_array_var info = theMesh->GetMeshInfo();
2179   long nbOdElems = info[SMDSEntity_0D];
2180   long nbEdges   = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
2181   long nbFaces   = info[SMDSEntity_Triangle]   + info[SMDSEntity_Quad_Triangle]   + info[SMDSEntity_BiQuad_Triangle] +
2182                    info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle] + info[SMDSEntity_BiQuad_Quadrangle] +
2183                    info[SMDSEntity_Polygon] + info[SMDSEntity_Quad_Polygon];
2184   long nbVolumes = info[SMDSEntity_Tetra]   + info[SMDSEntity_Quad_Tetra] +
2185                    info[SMDSEntity_Hexa]    + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_TriQuad_Hexa] +
2186                    info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid] +
2187                    info[SMDSEntity_Penta]   + info[SMDSEntity_Quad_Penta] + info[SMDSEntity_BiQuad_Penta] +
2188                    info[SMDSEntity_Polyhedra] +
2189                    info[SMDSEntity_Hexagonal_Prism];
2190   long nbBalls   = info[SMDSEntity_Ball];
2191
2192   long requestedSize = nbOdElems + nbBalls + nbEdges + nbFaces + nbVolumes;
2193   *nbElements = requestedSize;
2194
2195   *entities = SMESH_Actor::eAllEntity;
2196   *hidden   = 0;
2197
2198   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2199
2200   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2201
2202   if ( incrementalLimit ) {
2203     long total     = 0;
2204
2205     if ( nbOdElems > 0 ) {
2206       if ( total + nbOdElems > updateLimit ) {
2207         *entities = *entities & ~SMESH_Actor::e0DElements;
2208         *hidden = *hidden | SMESH_Actor::e0DElements;
2209       }
2210       else
2211         exceeded = false;
2212     }
2213     total += nbOdElems;
2214
2215     if ( nbEdges > 0 ) {
2216       if ( total + nbEdges > updateLimit ) {
2217         *entities = *entities & ~SMESH_Actor::eEdges;
2218         *hidden = *hidden | SMESH_Actor::eEdges;
2219       }
2220       else
2221         exceeded = false;
2222     }
2223     total += nbEdges;
2224
2225     if ( nbFaces > 0 ) {
2226       if ( total + nbFaces > updateLimit ) {
2227         *entities = *entities & ~SMESH_Actor::eFaces;
2228         *hidden = *hidden | SMESH_Actor::eFaces;
2229       }
2230       else
2231         exceeded = false;
2232     }
2233     total += nbFaces;
2234
2235     if ( nbVolumes > 0 ) {
2236       if ( total + nbVolumes > updateLimit ) {
2237         *entities = *entities & ~SMESH_Actor::eVolumes;
2238         *hidden = *hidden | SMESH_Actor::eVolumes;
2239       }
2240       else
2241         exceeded = false;
2242     }
2243     total += nbVolumes;
2244
2245     if ( nbBalls > 0 ) {
2246       if ( total + nbBalls > updateLimit ) {
2247         *entities = *entities & ~SMESH_Actor::eBallElem;
2248         *hidden = *hidden | SMESH_Actor::eBallElem;
2249       }
2250       else
2251         exceeded = false;
2252     }
2253     total += nbBalls;
2254   }
2255
2256   return autoUpdate && !exceeded;
2257 }
2258
2259 //=============================================================================
2260 /*!
2261  *
2262  */
2263 //=============================================================================
2264 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
2265 {
2266   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
2267 }
2268
2269 //=============================================================================
2270 /*!
2271  *
2272  */
2273 //=============================================================================
2274 SMESHGUI* SMESHGUI::GetSMESHGUI()
2275 {
2276   SMESHGUI* smeshMod = 0;
2277   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
2278   if ( app )
2279   {
2280     CAM_Module* module = app->module( "Mesh" );
2281     smeshMod = dynamic_cast<SMESHGUI*>( module );
2282   }
2283
2284   return smeshMod;
2285 }
2286
2287 extern "C"
2288 {
2289   Standard_EXPORT SMESHGUI* GetComponentGUI()
2290   {
2291     return SMESHGUI::GetSMESHGUI();
2292   }
2293 }
2294
2295 //=============================================================================
2296 /*!
2297  *
2298  */
2299 //=============================================================================
2300 void SMESHGUI::SetState(int aState)
2301 {
2302   myState = aState;
2303 }
2304
2305 //=============================================================================
2306 /*!
2307  *
2308  */
2309 //=============================================================================
2310 void SMESHGUI::ResetState()
2311 {
2312   myState = -1;
2313 }
2314
2315 //=============================================================================
2316 /*!
2317  *
2318  */
2319 //=============================================================================
2320 void SMESHGUI::EmitSignalDeactivateDialog()
2321 {
2322   emit SignalDeactivateActiveDialog();
2323 }
2324
2325 //=============================================================================
2326 /*!
2327  *
2328  */
2329 //=============================================================================
2330 void SMESHGUI::EmitSignalStudyFrameChanged()
2331 {
2332   emit SignalStudyFrameChanged();
2333 }
2334
2335 //=============================================================================
2336 /*!
2337  *
2338  */
2339 //=============================================================================
2340 void SMESHGUI::EmitSignalCloseAllDialogs()
2341 {
2342   emit SignalCloseAllDialogs();
2343 }
2344
2345 //=============================================================================
2346 /*!
2347  *
2348  */
2349 //=============================================================================
2350 void SMESHGUI::EmitSignalVisibilityChanged()
2351 {
2352   emit SignalVisibilityChanged();
2353 }
2354
2355 //=============================================================================
2356 /*!
2357  *
2358  */
2359 //=============================================================================
2360 void SMESHGUI::EmitSignalCloseView()
2361 {
2362   emit SignalCloseView();
2363 }
2364
2365 //=============================================================================
2366 /*!
2367  *
2368  */
2369 //=============================================================================
2370 void SMESHGUI::EmitSignalActivatedViewManager()
2371 {
2372   emit SignalActivatedViewManager();
2373 }
2374
2375 //=============================================================================
2376 /*!
2377  *
2378  */
2379 //=============================================================================
2380 QDialog *SMESHGUI::GetActiveDialogBox()
2381 {
2382   return myActiveDialogBox;
2383 }
2384
2385 //=============================================================================
2386 /*!
2387  *
2388  */
2389 //=============================================================================
2390 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2391 {
2392   myActiveDialogBox = (QDialog *) aDlg;
2393   return;
2394 }
2395
2396 //=============================================================================
2397 /*!
2398  *
2399  */
2400 //=============================================================================
2401 SUIT_Desktop* SMESHGUI::desktop()
2402 {
2403   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2404   if( app )
2405     return app->desktop();
2406   else
2407     return 0;
2408 }
2409
2410 //=============================================================================
2411 /*!
2412  *
2413  */
2414 //=============================================================================
2415 SalomeApp_Study* SMESHGUI::activeStudy()
2416 {
2417   SUIT_Application* app = SUIT_Session::session()->activeApplication();
2418   if( app )
2419     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2420   else
2421     return NULL;
2422 }
2423
2424 //=============================================================================
2425 /*!
2426  *
2427  */
2428 //=============================================================================
2429 void SMESHGUI::Modified( bool theIsUpdateActions )
2430 {
2431   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2432     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2433       appStudy->Modified();
2434       if( theIsUpdateActions )
2435         app->updateActions();
2436     }
2437   }
2438 }
2439
2440 //=============================================================================
2441 /*!
2442  *
2443  */
2444 //=============================================================================
2445 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2446 {
2447   /* Here the position is on the bottom right corner - 10 */
2448   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2449   aDlg->adjustSize();
2450   SUIT_Desktop *PP = desktop();
2451   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2452   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2453   return true;
2454 }
2455
2456 /*!
2457  * \brief Verifies whether study of operation is locked
2458   * \param theMess - specifies whether message box must be shown if study is locked
2459   * \return State of study.
2460 *
2461 * Verifies whether study of operation is locked. If second parameter is TRUE and study
2462 * is locked when corresponding message box appears
2463 */
2464 bool SMESHGUI::isStudyLocked( bool theMessage )
2465 {
2466   if ( SMESH::getStudy()->GetProperties()->IsLocked() )
2467   {
2468     if ( theMessage )
2469       SUIT_MessageBox::warning( SMESHGUI::desktop(),
2470                                 QObject::tr( "WRN_WARNING" ),
2471                                 QObject::tr( "WRN_STUDY_LOCKED" ) );
2472     return true;
2473   }
2474   return false;
2475 }
2476
2477 //=============================================================================
2478 /*!
2479  *
2480  */
2481 //=============================================================================
2482 bool SMESHGUI::OnGUIEvent( int theCommandID )
2483 {
2484   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2485   if( !anApp )
2486     return false;
2487
2488   SUIT_ResourceMgr* mgr = resourceMgr();
2489   if( !mgr )
2490     return false;
2491
2492   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2493   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2494
2495   //QAction* act = action( theCommandID );
2496
2497   switch (theCommandID) {
2498   case SMESHOp::OpDelete:
2499     if(isStudyLocked()) break;
2500     OnEditDelete();
2501     break;
2502   case SMESHOp::OpImportDAT:
2503   case SMESHOp::OpImportUNV:
2504   case SMESHOp::OpImportMED:
2505   case SMESHOp::OpImportSTL:
2506   case SMESHOp::OpImportCGNS:
2507   case SMESHOp::OpImportSAUV:
2508   case SMESHOp::OpImportGMF:
2509   case SMESHOp::OpPopupImportDAT:
2510   case SMESHOp::OpPopupImportUNV:
2511   case SMESHOp::OpPopupImportMED:
2512   case SMESHOp::OpPopupImportSTL:
2513   case SMESHOp::OpPopupImportCGNS:
2514   case SMESHOp::OpPopupImportSAUV:
2515   case SMESHOp::OpPopupImportGMF:
2516     {
2517       if(isStudyLocked()) break;
2518       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2519       break;
2520     }
2521
2522   case SMESHOp::OpFileInformation:
2523     {
2524       SALOME_ListIO selected;
2525       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2526       if( aSel )
2527         aSel->selectedObjects( selected );
2528       if( selected.Extent() )
2529       {
2530         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2531         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2532         if ( !aMesh->_is_nil() )
2533         {
2534           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2535           dlg.exec();
2536         }
2537       }
2538       break;
2539     }
2540   case SMESHOp::OpExportDAT:
2541   case SMESHOp::OpExportMED:
2542   case SMESHOp::OpExportUNV:
2543   case SMESHOp::OpExportSTL:
2544   case SMESHOp::OpExportCGNS:
2545   case SMESHOp::OpExportSAUV:
2546   case SMESHOp::OpExportGMF:
2547   case SMESHOp::OpPopupExportDAT:
2548   case SMESHOp::OpPopupExportMED:
2549   case SMESHOp::OpPopupExportUNV:
2550   case SMESHOp::OpPopupExportSTL:
2551   case SMESHOp::OpPopupExportCGNS:
2552   case SMESHOp::OpPopupExportSAUV:
2553   case SMESHOp::OpPopupExportGMF:
2554     {
2555       ::ExportMeshToFile(theCommandID);
2556       break;
2557     }
2558
2559   case SMESHOp::OpReset:                      // SCALAR BAR
2560     {
2561       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2562       SALOME_ListIO selected;
2563       if( aSel )
2564         aSel->selectedObjects( selected );
2565
2566       SALOME_ListIteratorOfListIO it(selected);
2567       for( ; it.More(); it.Next()) {
2568         Handle(SALOME_InteractiveObject) anIO = it.Value();
2569         if( anIO->hasEntry() ) {
2570           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2571             anActor->SetControlMode( SMESH_Actor::eNone );
2572 #ifndef DISABLE_PLOT2DVIEWER
2573             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2574 #endif
2575             anActor->UpdateFilter();
2576           }
2577         }
2578       }
2579       SMESH::UpdateView();
2580       break;
2581     }
2582   case SMESHOp::OpScalarBarProperties:
2583     {
2584       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2585       break;
2586     }
2587   case SMESHOp::OpShowScalarBar:
2588     {
2589       // show/hide scalar bar
2590       ::ShowElement(theCommandID);
2591       break;
2592     }
2593   case SMESHOp::OpSaveDistribution:
2594     {
2595       // dump control distribution data to the text file
2596       ::SaveDistribution();
2597       break;
2598     }
2599
2600   case SMESHOp::OpShowDistribution:
2601     {
2602       // show/hide distribution
2603       ::ShowElement(theCommandID);
2604       break;
2605     }
2606
2607 #ifndef DISABLE_PLOT2DVIEWER
2608   case SMESHOp::OpPlotDistribution:
2609     {
2610       // plot distribution
2611       ::PlotDistribution();
2612       break;
2613     }
2614 #endif
2615
2616     // Auto-color
2617   case SMESHOp::OpAutoColor:
2618     ::AutoColor();
2619   break;
2620
2621   case SMESHOp::OpDisableAutoColor:
2622     ::DisableAutoColor();
2623   break;
2624
2625   case SMESHOp::OpClipping:
2626   case SMESHOp::OpTransparency:
2627   case SMESHOp::OpProperties: // Display preferences (colors, shrink size, line width, ...)
2628
2629     // Display Mode
2630   case SMESHOp::OpDMWireframe:
2631   case SMESHOp::OpDMShading:
2632   case SMESHOp::OpDMNodes:
2633   case SMESHOp::OpDMShrink:
2634     ::SetDisplayMode(theCommandID, myMarkerMap);
2635   break;
2636
2637   //2D quadratic representation
2638   case SMESHOp::OpRepresentationLines:
2639   case SMESHOp::OpRepresentationArcs:
2640     ::SetDisplayMode(theCommandID, myMarkerMap);
2641   break;
2642
2643   // Display Entity
2644   case SMESHOp::OpDE0DElements:
2645   case SMESHOp::OpDEEdges:
2646   case SMESHOp::OpDEFaces:
2647   case SMESHOp::OpDEVolumes:
2648   case SMESHOp::OpDEBalls:
2649   case SMESHOp::OpDEAllEntity:
2650     ::SetDisplayEntity(theCommandID);
2651   break;
2652
2653   // Choose entities to be displayed
2654   case SMESHOp::OpDEChoose:
2655     {
2656       ( new SMESHGUI_DisplayEntitiesDlg( SMESHGUI::desktop() ) )->exec();
2657       break;
2658     }
2659
2660   case SMESHOp::OpOrientationOnFaces:
2661     {
2662       SUIT_OverrideCursor wc;
2663       LightApp_SelectionMgr* mgr = selectionMgr();
2664       SALOME_ListIO selected; mgr->selectedObjects( selected );
2665
2666       SALOME_ListIteratorOfListIO it(selected);
2667       for( ; it.More(); it.Next()) {
2668         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2669         if(anIObject->hasEntry()) {
2670           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2671             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2672           }
2673         }
2674       }
2675       break;
2676     }
2677
2678   case SMESHOp::OpUpdate:
2679     {
2680       if(isStudyLocked()) break;
2681       SUIT_OverrideCursor wc;
2682       try {
2683         OCC_CATCH_SIGNALS;
2684         SMESH::UpdateView();
2685       }
2686       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2687         SMESH::OnVisuException();
2688       }
2689       catch (...) { // PAL16774 (Crash after display of many groups)
2690         SMESH::OnVisuException();
2691       }
2692
2693       SALOME_ListIO l;
2694       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2695       aSel->selectedObjects( l );
2696       aSel->setSelectedObjects( l );
2697       break;
2698     }
2699
2700   case SMESHOp::OpHide:
2701   case SMESHOp::OpShow:
2702   case SMESHOp::OpShowOnly:
2703     {
2704       SUIT_OverrideCursor wc;
2705       SMESH::EDisplaing anAction;
2706       switch (theCommandID) {
2707       case SMESHOp::OpHide:     anAction = SMESH::eErase; break;
2708       case SMESHOp::OpShow:     anAction = SMESH::eDisplay; break;
2709       case SMESHOp::OpShowOnly: anAction = SMESH::eDisplayOnly; break;
2710       }
2711
2712       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2713       SALOME_ListIO sel_objects, to_process;
2714       if (aSel)
2715         aSel->selectedObjects( sel_objects );
2716
2717       if ( theCommandID==SMESHOp::OpShowOnly )
2718       {
2719         //MESSAGE("anAction = SMESH::eDisplayOnly");
2720         startOperation( myEraseAll );
2721       }
2722
2723       extractContainers( sel_objects, to_process );
2724
2725       try {
2726         OCC_CATCH_SIGNALS;
2727         if (vtkwnd) {
2728           SALOME_ListIteratorOfListIO It( to_process );
2729           for ( ; It.More(); It.Next())
2730           {
2731             Handle(SALOME_InteractiveObject) IOS = It.Value();
2732             if ( IOS->hasEntry() )
2733             {
2734               if ( !SMESH::UpdateView( anAction, IOS->getEntry() )) {
2735                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2736                 break; // PAL16774 (Crash after display of many groups)
2737               }
2738               if (anAction == SMESH::eDisplayOnly)
2739                 anAction = SMESH::eDisplay;
2740             }
2741           }
2742         }
2743
2744         // PAL13338 + PAL15161 -->
2745         if ( ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) && !isStudyLocked()) {
2746           SMESH::UpdateView();
2747           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2748         }
2749         // PAL13338 + PAL15161 <--
2750       }
2751       catch (...) { // PAL16774 (Crash after display of many groups)
2752         SMESH::OnVisuException();
2753       }
2754
2755       if (anAction == SMESH::eErase) {
2756         SALOME_ListIO l1;
2757         aSel->setSelectedObjects( l1 );
2758       }
2759       else
2760         aSel->setSelectedObjects( to_process );
2761
2762       if ( vtkwnd && vtkwnd->GetRenderer() && !isStudyLocked() &&
2763            ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) )
2764         vtkwnd->GetRenderer()->AdjustActors();
2765
2766       break;
2767     }
2768
2769   case SMESHOp::OpNode:
2770     {
2771       if(isStudyLocked()) break;
2772
2773       if ( vtkwnd ) {
2774         EmitSignalDeactivateDialog();
2775
2776         ( new SMESHGUI_NodesDlg( this ) )->show();
2777       }
2778       else {
2779         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"),tr("SMESH_WRN_VIEWER_VTK"));
2780       }
2781       break;
2782     }
2783
2784   case SMESHOp::OpCreateMesh:
2785   case SMESHOp::OpCreateSubMesh:
2786   case SMESHOp::OpEditMeshOrSubMesh:
2787   case SMESHOp::OpEditMesh:
2788   case SMESHOp::OpEditSubMesh:
2789   case SMESHOp::OpCompute:
2790   case SMESHOp::OpComputeSubMesh:
2791   case SMESHOp::OpPreCompute:
2792   case SMESHOp::OpEvaluate:
2793   case SMESHOp::OpMeshOrder:
2794     startOperation( theCommandID );
2795     break;
2796   case SMESHOp::OpCopyMesh:
2797     {
2798       if (isStudyLocked()) break;
2799       EmitSignalDeactivateDialog();
2800       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2801     }
2802     break;
2803   case SMESHOp::OpBuildCompoundMesh:
2804     {
2805       if (isStudyLocked()) break;
2806       EmitSignalDeactivateDialog();
2807       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2808     }
2809     break;
2810
2811   case SMESHOp::OpDiagonalInversion:
2812   case SMESHOp::OpUnionOfTwoTriangle:
2813     {
2814       if ( !vtkwnd )
2815       {
2816         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "NOT_A_VTK_VIEWER" ) );
2817         break;
2818       }
2819
2820       if ( isStudyLocked() )
2821         break;
2822
2823       /*Standard_Boolean aRes;
2824       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2825       if ( aMesh->_is_nil() )
2826       {
2827         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2828           tr( "SMESH_BAD_SELECTION" ) );
2829         break;
2830       }
2831       */
2832       EmitSignalDeactivateDialog();
2833       if ( theCommandID == SMESHOp::OpDiagonalInversion )
2834         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2835       else
2836         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2837       break;
2838     }
2839   case SMESHOp::OpOrientation:
2840   case SMESHOp::OpUnionOfTriangles:
2841   case SMESHOp::OpCuttingOfQuadrangles:
2842   case SMESHOp::OpSplitVolumes:
2843     {
2844       if ( !vtkwnd )
2845       {
2846         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ), tr( "NOT_A_VTK_VIEWER" ) );
2847         break;
2848       }
2849
2850       if ( isStudyLocked() )
2851         break;
2852
2853       EmitSignalDeactivateDialog();
2854       SMESHGUI_MultiEditDlg* aDlg = NULL;
2855       if ( theCommandID == SMESHOp::OpOrientation )
2856         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2857       else if ( theCommandID == SMESHOp::OpUnionOfTriangles )
2858         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2859       else if ( theCommandID == SMESHOp::OpSplitVolumes )
2860         aDlg = new SMESHGUI_SplitVolumesDlg(this);
2861       else
2862         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2863
2864       aDlg->show();
2865       break;
2866     }
2867   case SMESHOp::OpSmoothing:
2868     {
2869       if(isStudyLocked()) break;
2870       if( vtkwnd ) {
2871         EmitSignalDeactivateDialog();
2872         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2873       }
2874       else {
2875         SUIT_MessageBox::warning(desktop(), tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2876       }
2877       break;
2878     }
2879   case SMESHOp::OpExtrusion:
2880     {
2881       if (isStudyLocked()) break;
2882       if (vtkwnd) {
2883         EmitSignalDeactivateDialog();
2884         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2885       } else {
2886         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2887       }
2888       break;
2889     }
2890   case SMESHOp::OpExtrusionAlongAPath:
2891     {
2892       if (isStudyLocked()) break;
2893       if (vtkwnd) {
2894         EmitSignalDeactivateDialog();
2895         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2896       } else {
2897         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2898       }
2899       break;
2900     }
2901   case SMESHOp::OpRevolution:
2902     {
2903       if(isStudyLocked()) break;
2904       if( vtkwnd ) {
2905         EmitSignalDeactivateDialog();
2906         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2907       }
2908       else {
2909         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2910       }
2911       break;
2912     }
2913   case SMESHOp::OpPatternMapping:
2914     {
2915       if ( isStudyLocked() )
2916         break;
2917       if ( vtkwnd )
2918       {
2919         EmitSignalDeactivateDialog();
2920         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2921       }
2922       else {
2923         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2924       }
2925       break;
2926     }
2927   case SMESHOp::OpSplitBiQuadratic:
2928   case SMESHOp::OpConvertMeshToQuadratic:
2929   case SMESHOp::OpCreateBoundaryElements: // create 2D mesh from 3D
2930   case SMESHOp::OpReorientFaces:
2931   case SMESHOp::OpCreateGeometryGroup:
2932     {
2933       startOperation( theCommandID );
2934       break;
2935     }
2936   case SMESHOp::OpCreateGroup:
2937     {
2938       if ( !vtkwnd )
2939       {
2940         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
2941         break;
2942       }
2943
2944       if(isStudyLocked()) break;
2945       EmitSignalDeactivateDialog();
2946       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2947
2948       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2949       SALOME_ListIO selected;
2950       if( aSel )
2951         aSel->selectedObjects( selected );
2952
2953       int nbSel = selected.Extent();
2954       if (nbSel == 1) {
2955         // check if mesh is selected
2956         aMesh = SMESH::GetMeshByIO( selected.First() );
2957       }
2958       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2959       aDlg->show();
2960       break;
2961     }
2962
2963   case SMESHOp::OpConstructGroup:
2964     {
2965       if ( !vtkwnd )
2966       {
2967         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
2968         break;
2969       }
2970
2971       if(isStudyLocked()) break;
2972       EmitSignalDeactivateDialog();
2973
2974       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2975       SALOME_ListIO selected;
2976       if( aSel )
2977         aSel->selectedObjects( selected );
2978
2979       int nbSel = selected.Extent();
2980       if (nbSel == 1) {
2981         // check if submesh is selected
2982         Handle(SALOME_InteractiveObject) IObject = selected.First();
2983         if (IObject->hasEntry()) {
2984           _PTR(SObject) aSObj = SMESH::getStudy()->FindObjectID(IObject->getEntry());
2985           if( aSObj ) {
2986             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2987             if (!aSubMesh->_is_nil()) {
2988               try {
2989                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2990                 // get submesh elements list by types
2991                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2992                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2993                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2994                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2995                 // create group for each type o elements
2996                 QString aName = IObject->getName();
2997                 QStringList anEntryList;
2998                 if (aNodes->length() > 0) {
2999                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
3000                   aGroup->Add(aNodes.inout());
3001                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3002                     anEntryList.append( aSObject->GetID().c_str() );
3003                 }
3004                 if (aEdges->length() > 0) {
3005                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
3006                   aGroup->Add(aEdges.inout());
3007                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3008                     anEntryList.append( aSObject->GetID().c_str() );
3009                 }
3010                 if (aFaces->length() > 0) {
3011                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
3012                   aGroup->Add(aFaces.inout());
3013                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3014                     anEntryList.append( aSObject->GetID().c_str() );
3015                 }
3016                 if (aVolumes->length() > 0) {
3017                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
3018                   aGroup->Add(aVolumes.inout());
3019                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
3020                     anEntryList.append( aSObject->GetID().c_str() );
3021                 }
3022                 updateObjBrowser();
3023                 anApp->browseObjects( anEntryList );
3024               }
3025               catch(const SALOME::SALOME_Exception & S_ex){
3026                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3027               }
3028             }
3029           }
3030         }
3031       }
3032       else if(nbSel==0) {
3033         SUIT_MessageBox::warning(desktop(),
3034                                  tr("SMESH_WRN_WARNING"),
3035                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
3036       }
3037       break;
3038     }
3039
3040   case SMESHOp::OpEditGroup:
3041     {
3042       if ( !vtkwnd )
3043       {
3044         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3045         break;
3046       }
3047
3048       if(isStudyLocked()) break;
3049       EmitSignalDeactivateDialog();
3050
3051       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3052       SALOME_ListIO selected;
3053       if( aSel )
3054         aSel->selectedObjects( selected );
3055
3056       SALOME_ListIteratorOfListIO It (selected);
3057       int nbSelectedGroups = 0;
3058       for ( ; It.More(); It.Next() )
3059       {
3060         SMESH::SMESH_GroupBase_var aGroup =
3061           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
3062         if (!aGroup->_is_nil()) {
3063           nbSelectedGroups++;
3064           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
3065           aDlg->show();
3066         }
3067       }
3068       if (nbSelectedGroups == 0)
3069         {
3070           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
3071           aDlg->show();
3072         }
3073       break;
3074     }
3075
3076   case SMESHOp::OpAddElemGroupPopup:     // Add elements to group
3077     {
3078       if(isStudyLocked()) break;
3079       if (myState == 800) {
3080         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
3081         if (aDlg) aDlg->onAdd();
3082       }
3083       break;
3084     }
3085
3086   case SMESHOp::OpRemoveElemGroupPopup:  // Remove elements from group
3087     {
3088       if(isStudyLocked()) break;
3089       if (myState == 800) {
3090         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
3091         if (aDlg) aDlg->onRemove();
3092       }
3093       break;
3094     }
3095
3096   case SMESHOp::OpEditGeomGroupAsGroup:
3097     {
3098       if ( !vtkwnd )
3099       {
3100         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3101         break;
3102       }
3103
3104       if(isStudyLocked()) break;
3105       EmitSignalDeactivateDialog();
3106
3107       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3108       SALOME_ListIO selected;
3109       if( aSel )
3110         aSel->selectedObjects( selected );
3111
3112       SALOME_ListIteratorOfListIO It (selected);
3113       for ( ; It.More(); It.Next() )
3114       {
3115         SMESH::SMESH_GroupOnGeom_var aGroup =
3116           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
3117         if (!aGroup->_is_nil()) {
3118           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3119           aDlg->show();
3120         }
3121         else
3122         {
3123           SMESH::SMESH_GroupOnFilter_var aGroup =
3124             SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
3125           if (!aGroup->_is_nil()) {
3126             SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3127             aDlg->show();
3128           }
3129         }
3130       }
3131       break;
3132     }
3133
3134     case SMESHOp::OpUnionGroups:
3135     case SMESHOp::OpIntersectGroups:
3136     case SMESHOp::OpCutGroups:
3137     {
3138       if ( !vtkwnd )
3139       {
3140         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3141         break;
3142       }
3143
3144       if ( isStudyLocked() )
3145         break;
3146
3147       EmitSignalDeactivateDialog();
3148
3149       SMESHGUI_GroupOpDlg* aDlg = 0;
3150       if ( theCommandID == SMESHOp::OpUnionGroups )
3151         aDlg = new SMESHGUI_UnionGroupsDlg( this );
3152       else if ( theCommandID == SMESHOp::OpIntersectGroups )
3153         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
3154       else
3155         aDlg = new SMESHGUI_CutGroupsDlg( this );
3156
3157       aDlg->show();
3158
3159       break;
3160     }
3161
3162     case SMESHOp::OpGroupUnderlyingElem: // Create groups of entities from existing groups of superior dimensions
3163     {
3164       if ( isStudyLocked() )
3165         break;
3166
3167       EmitSignalDeactivateDialog();
3168       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
3169       aDlg->show();
3170
3171       break;
3172     }
3173
3174     case SMESHOp::OpFaceGroupsByEdges: // Create face groups separated by sharp edges
3175     {
3176       if ( isStudyLocked() )
3177         break;
3178
3179       EmitSignalDeactivateDialog();
3180       SMESHGUI_FaceGroupsSeparatedByEdgesDlg* aDlg = new SMESHGUI_FaceGroupsSeparatedByEdgesDlg( this );
3181       aDlg->show();
3182
3183       break;
3184     }
3185
3186     case SMESHOp::OpDeleteGroup: // Delete groups with their contents
3187     {
3188       if ( !vtkwnd )
3189       {
3190         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),tr( "NOT_A_VTK_VIEWER" ) );
3191         break;
3192       }
3193
3194       if ( isStudyLocked() )
3195         break;
3196
3197       EmitSignalDeactivateDialog();
3198
3199       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
3200       break;
3201     }
3202
3203   case SMESHOp::OpMeshInformation:
3204   case SMESHOp::OpWhatIs:
3205     {
3206       int page = theCommandID == SMESHOp::OpMeshInformation ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
3207       EmitSignalDeactivateDialog();
3208       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3209       SALOME_ListIO selected;
3210       if( aSel )
3211         aSel->selectedObjects( selected );
3212
3213       if ( selected.Extent() > 1 ) { // a dlg for each IO
3214         SALOME_ListIteratorOfListIO It( selected );
3215         for ( ; It.More(); It.Next() ) {
3216           SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3217           dlg->showInfo( It.Value() );
3218           dlg->show();
3219         }
3220       }
3221       else {
3222         SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
3223         dlg->show();
3224       }
3225       break;
3226     }
3227
3228   case SMESHOp::OpFindElementByPoint:
3229     {
3230       startOperation( theCommandID );
3231       break;
3232     }
3233
3234   case SMESHOp::OpEditHypothesis:
3235     {
3236       if(isStudyLocked()) break;
3237
3238       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3239       SALOME_ListIO selected;
3240       if( aSel )
3241         aSel->selectedObjects( selected );
3242
3243       int nbSel = selected.Extent();
3244
3245       if (nbSel == 1) {
3246         Handle(SALOME_InteractiveObject) anIObject = selected.First();
3247         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
3248
3249         if ( !aHypothesis->_is_nil() )
3250         {
3251           SMESHGUI_GenericHypothesisCreator* aCreator =
3252             SMESH::GetHypothesisCreator( SMESH::toQStr( aHypothesis->GetName() ));
3253           if (aCreator)
3254           {
3255             // set geometry of mesh and sub-mesh to aCreator
3256             aSel->selectedObjects( selected, "",  /*convertReferences=*/false);
3257             if ( selected.Extent() == 1 )
3258             {
3259               QString subGeomID, meshGeomID;
3260               Handle(SALOME_InteractiveObject) hypIO = selected.First();
3261               if ( SMESH::GetGeomEntries( hypIO, subGeomID, meshGeomID ))
3262               {
3263                 if ( subGeomID.isEmpty() ) subGeomID = meshGeomID;
3264                 aCreator->setShapeEntry( subGeomID );
3265                 aCreator->setMainShapeEntry( meshGeomID );
3266               }
3267             }
3268
3269             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
3270           }
3271           else
3272           {
3273             // report error
3274           }
3275         }
3276       }
3277       break;
3278     }
3279   case SMESHOp::OpUnassign:                      // REMOVE HYPOTHESIS / ALGORITHMS
3280     {
3281       if(isStudyLocked()) break;
3282       SUIT_OverrideCursor wc;
3283
3284       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3285       SALOME_ListIO selected;
3286       if( aSel )
3287         aSel->selectedObjects( selected, QString::null, false );
3288
3289       SALOME_ListIteratorOfListIO It(selected);
3290       for (int i = 0; It.More(); It.Next(), i++) {
3291         Handle(SALOME_InteractiveObject) IObject = It.Value();
3292         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
3293       }
3294       SALOME_ListIO l1;
3295       aSel->setSelectedObjects( l1 );
3296       updateObjBrowser();
3297       break;
3298     }
3299
3300   case SMESHOp::OpElem0D:
3301   case SMESHOp::OpBall:
3302   case SMESHOp::OpEdge:
3303   case SMESHOp::OpTriangle:
3304   case SMESHOp::OpQuadrangle:
3305   case SMESHOp::OpPolygon:
3306   case SMESHOp::OpTetrahedron:
3307   case SMESHOp::OpHexahedron:
3308   case SMESHOp::OpPentahedron:
3309   case SMESHOp::OpPyramid:
3310   case SMESHOp::OpHexagonalPrism:
3311     {
3312       if(isStudyLocked()) break;
3313       if ( vtkwnd ) {
3314         EmitSignalDeactivateDialog();
3315         SMDSAbs_EntityType type = SMDSEntity_Edge;
3316         switch (theCommandID) {
3317         case SMESHOp::OpElem0D: type = SMDSEntity_0D;                      break;
3318         case SMESHOp::OpBall: type = SMDSEntity_Ball;                      break;
3319         case SMESHOp::OpTriangle: type = SMDSEntity_Triangle;              break;
3320         case SMESHOp::OpQuadrangle: type = SMDSEntity_Quadrangle;          break;
3321         case SMESHOp::OpTetrahedron: type = SMDSEntity_Tetra;              break;
3322         case SMESHOp::OpPolygon: type = SMDSEntity_Polygon;                break;
3323         case SMESHOp::OpHexahedron: type = SMDSEntity_Hexa;                break;
3324         case SMESHOp::OpPentahedron: type = SMDSEntity_Penta;              break;
3325         case SMESHOp::OpPyramid: type = SMDSEntity_Pyramid;                break;
3326         case SMESHOp::OpHexagonalPrism: type = SMDSEntity_Hexagonal_Prism; break;
3327         default:;
3328         }
3329         ( new SMESHGUI_AddMeshElementDlg( this, type ) )->show();
3330       }
3331       else {
3332         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3333       }
3334       break;
3335     }
3336   case SMESHOp::OpPolyhedron:
3337     {
3338       if(isStudyLocked()) break;
3339       if ( vtkwnd ) {
3340         EmitSignalDeactivateDialog();
3341         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
3342       }
3343       else {
3344         SUIT_MessageBox::warning(desktop(),tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3345       }
3346       break;
3347     }
3348   case SMESHOp::OpQuadraticEdge:
3349   case SMESHOp::OpQuadraticTriangle:
3350   case SMESHOp::OpBiQuadraticTriangle:
3351   case SMESHOp::OpQuadraticQuadrangle:
3352   case SMESHOp::OpBiQuadraticQuadrangle:
3353   case SMESHOp::OpQuadraticPolygon:
3354   case SMESHOp::OpQuadraticTetrahedron:
3355   case SMESHOp::OpQuadraticPyramid:
3356   case SMESHOp::OpQuadraticPentahedron:
3357   case SMESHOp::OpBiQuadraticPentahedron:
3358   case SMESHOp::OpQuadraticHexahedron:
3359   case SMESHOp::OpTriQuadraticHexahedron:
3360     {
3361       if(isStudyLocked()) break;
3362       if ( vtkwnd ) {
3363         EmitSignalDeactivateDialog();
3364         SMDSAbs_EntityType type = SMDSEntity_Last;
3365
3366         switch (theCommandID) {
3367         case SMESHOp::OpQuadraticEdge:          type = SMDSEntity_Quad_Edge; break;
3368         case SMESHOp::OpQuadraticTriangle:      type = SMDSEntity_Quad_Triangle; break;
3369         case SMESHOp::OpBiQuadraticTriangle:    type = SMDSEntity_BiQuad_Triangle; break;
3370         case SMESHOp::OpQuadraticQuadrangle:    type = SMDSEntity_Quad_Quadrangle; break;
3371         case SMESHOp::OpBiQuadraticQuadrangle:  type = SMDSEntity_BiQuad_Quadrangle; break;
3372         case SMESHOp::OpQuadraticPolygon:       type = SMDSEntity_Quad_Polygon; break;
3373         case SMESHOp::OpQuadraticTetrahedron:   type = SMDSEntity_Quad_Tetra; break;
3374         case SMESHOp::OpQuadraticPyramid:       type = SMDSEntity_Quad_Pyramid; break;
3375         case SMESHOp::OpQuadraticPentahedron:   type = SMDSEntity_Quad_Penta; break;
3376         case SMESHOp::OpBiQuadraticPentahedron: type = SMDSEntity_BiQuad_Penta; break;
3377         case SMESHOp::OpQuadraticHexahedron:    type = SMDSEntity_Quad_Hexa; break;
3378         case SMESHOp::OpTriQuadraticHexahedron: type = SMDSEntity_TriQuad_Hexa; break;
3379         default: break;
3380         }
3381         if ( type != SMDSEntity_Last )
3382           ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
3383       }
3384       else {
3385         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3386                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3387       }
3388       break;
3389     }
3390   case SMESHOp::OpRemoveNodes:
3391     {
3392       if(isStudyLocked()) break;
3393       if ( vtkwnd ) {
3394         EmitSignalDeactivateDialog();
3395         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
3396       }
3397       else {
3398         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3399                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3400       }
3401       break;
3402     }
3403   case SMESHOp::OpRemoveElements:                                    // REMOVES ELEMENTS
3404     {
3405       if(isStudyLocked()) break;
3406       if( vtkwnd ) {
3407         EmitSignalDeactivateDialog();
3408         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
3409       }
3410       else
3411         {
3412           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3413                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3414         }
3415       break;
3416     }
3417   case SMESHOp::OpClearMesh: {
3418
3419     if(isStudyLocked()) break;
3420
3421     SALOME_ListIO selected;
3422     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3423       aSel->selectedObjects( selected );
3424
3425     SUIT_OverrideCursor wc;
3426     SALOME_ListIteratorOfListIO It (selected);
3427     for ( ; It.More(); It.Next() )
3428     {
3429       Handle(SALOME_InteractiveObject) IOS = It.Value();
3430       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
3431       if ( aMesh->_is_nil()) continue;
3432       try {
3433         aMesh->Clear();
3434         if ( aMesh->NbNodes() == 0 ) // imported mesh is not empty
3435           SMESH::RemoveVisualObjectWithActors(IOS->getEntry(), true);
3436         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
3437         // hide groups and submeshes
3438         _PTR(ChildIterator) anIter =
3439           SMESH::getStudy()->NewChildIterator( aMeshSObj );
3440         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
3441         {
3442           _PTR(SObject) so = anIter->Value();
3443           SMESH::RemoveVisualObjectWithActors(so->GetID().c_str(), true);
3444         }
3445       }
3446       catch (const SALOME::SALOME_Exception& S_ex){
3447         wc.suspend();
3448         SalomeApp_Tools::QtCatchCorbaException(S_ex);
3449         wc.resume();
3450       }
3451     }
3452     SMESH::UpdateView();
3453     updateObjBrowser();
3454     break;
3455   }
3456   case SMESHOp::OpRemoveOrphanNodes:
3457     {
3458       if(isStudyLocked()) break;
3459       SALOME_ListIO selected;
3460       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
3461         aSel->selectedObjects( selected );
3462       if ( selected.Extent() == 1 ) {
3463         Handle(SALOME_InteractiveObject) anIO = selected.First();
3464         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
3465         if ( !aMesh->_is_nil() ) {
3466           bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
3467                                                     tr( "SMESH_WARNING" ),
3468                                                     tr( "REMOVE_ORPHAN_NODES_QUESTION"),
3469                                                     SUIT_MessageBox::Yes |
3470                                                     SUIT_MessageBox::No,
3471                                                     SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
3472           if( confirm ) {
3473             try {
3474               SUIT_OverrideCursor wc;
3475               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3476               int removed = aMeshEditor->RemoveOrphanNodes();
3477               SUIT_MessageBox::information(SMESHGUI::desktop(),
3478                                            tr("SMESH_INFORMATION"),
3479                                            tr("NB_NODES_REMOVED").arg(removed));
3480               if ( removed > 0 ) {
3481                 SMESH::UpdateView();
3482                 SMESHGUI::Modified();
3483               }
3484             }
3485             catch (const SALOME::SALOME_Exception& S_ex) {
3486               SalomeApp_Tools::QtCatchCorbaException(S_ex);
3487             }
3488             catch (...) {
3489             }
3490           }
3491         }
3492       }
3493       break;
3494     }
3495   case SMESHOp::OpRenumberingNodes:
3496     {
3497       if(isStudyLocked()) break;
3498       if( vtkwnd ) {
3499         EmitSignalDeactivateDialog();
3500         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
3501       }
3502       else
3503         {
3504           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3505                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3506         }
3507       break;
3508     }
3509   case SMESHOp::OpRenumberingElements:
3510     {
3511       if(isStudyLocked()) break;
3512       if ( vtkwnd ) {
3513         EmitSignalDeactivateDialog();
3514         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
3515       }
3516       else
3517         {
3518           SUIT_MessageBox::warning(SMESHGUI::desktop(),
3519                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3520         }
3521       break;
3522     }
3523   case SMESHOp::OpTranslation:
3524     {
3525       if(isStudyLocked()) break;
3526       if ( vtkwnd ) {
3527         EmitSignalDeactivateDialog();
3528         ( new SMESHGUI_TranslationDlg( this ) )->show();
3529       }
3530       else {
3531         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3532                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3533       }
3534       break;
3535     }
3536   case SMESHOp::OpRotation:
3537     {
3538       if(isStudyLocked()) break;
3539       if( vtkwnd ) {
3540         EmitSignalDeactivateDialog();
3541         ( new SMESHGUI_RotationDlg( this ) )->show();
3542       }
3543       else {
3544         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3545                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3546       }
3547       break;
3548     }
3549   case SMESHOp::OpSymmetry:
3550     {
3551       if(isStudyLocked()) break;
3552       if(vtkwnd) {
3553         EmitSignalDeactivateDialog();
3554         ( new SMESHGUI_SymmetryDlg( this ) )->show();
3555       }
3556       else {
3557         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3558                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3559       }
3560       break;
3561     }
3562   case SMESHOp::OpScale:
3563     {
3564       if(isStudyLocked()) break;
3565       if ( vtkwnd ) {
3566         EmitSignalDeactivateDialog();
3567         ( new SMESHGUI_ScaleDlg( this ) )->show();
3568       }
3569       else {
3570         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3571                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3572       }
3573       break;
3574     }
3575
3576   case SMESHOp::OpOffset:
3577     {
3578       if(isStudyLocked()) break;
3579       if ( vtkwnd ) {
3580         EmitSignalDeactivateDialog();
3581         ( new SMESHGUI_OffsetDlg( this ) )->show();
3582       }
3583       else {
3584         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3585                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3586       }
3587       break;
3588     }
3589
3590   case SMESHOp::OpSewing:
3591     {
3592       if(isStudyLocked()) break;
3593       if(vtkwnd) {
3594         EmitSignalDeactivateDialog();
3595         ( new SMESHGUI_SewingDlg( this ) )->show();
3596       }
3597       else {
3598         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3599                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3600       }
3601       break;
3602     }
3603   case SMESHOp::OpMergeNodes:
3604     {
3605       if(isStudyLocked()) break;
3606       if(vtkwnd) {
3607         EmitSignalDeactivateDialog();
3608         ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3609       }
3610       else {
3611         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3612                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3613       }
3614       break;
3615     }
3616   case SMESHOp::OpMergeElements:
3617     {
3618       if (isStudyLocked()) break;
3619       if (vtkwnd) {
3620         EmitSignalDeactivateDialog();
3621         ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3622       } else {
3623         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3624                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3625       }
3626       break;
3627     }
3628
3629   case SMESHOp::OpMoveNode: // MAKE MESH PASS THROUGH POINT
3630     startOperation( SMESHOp::OpMoveNode );
3631     break;
3632
3633   case SMESHOp::OpDuplicateNodes:
3634     {
3635       if(isStudyLocked()) break;
3636       if ( vtkwnd ) {
3637         EmitSignalDeactivateDialog();
3638         ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3639       }
3640       else {
3641         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3642                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3643       }
3644       break;
3645     }
3646
3647   case SMESHOp::OpElem0DOnElemNodes: // 0D_ON_ALL_NODES
3648     startOperation( SMESHOp::OpElem0DOnElemNodes );
3649     break;
3650
3651   case SMESHOp::OpSelectFiltersLibrary: // Library of selection filters
3652   {
3653     static QList<int> aTypes;
3654     if ( aTypes.isEmpty() )
3655     {
3656       aTypes.append( SMESH::NODE );
3657       aTypes.append( SMESH::EDGE );
3658       aTypes.append( SMESH::FACE );
3659       aTypes.append( SMESH::VOLUME );
3660     }
3661     if (!myFilterLibraryDlg)
3662       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3663     else if (myFilterLibraryDlg->isHidden())
3664       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3665     myFilterLibraryDlg->raise();
3666   }
3667   break;
3668   // CONTROLS
3669   case SMESHOp::OpFreeNode:
3670   case SMESHOp::OpEqualNode:
3671   case SMESHOp::OpNodeConnectivityNb:
3672   case SMESHOp::OpFreeEdge:
3673   case SMESHOp::OpFreeBorder:
3674   case SMESHOp::OpLength:
3675   case SMESHOp::OpConnection:
3676   case SMESHOp::OpEqualEdge:
3677   case SMESHOp::OpFreeFace:
3678   case SMESHOp::OpBareBorderFace:
3679   case SMESHOp::OpOverConstrainedFace:
3680   case SMESHOp::OpLength2D:
3681   case SMESHOp::OpDeflection2D:
3682   case SMESHOp::OpConnection2D:
3683   case SMESHOp::OpArea:
3684   case SMESHOp::OpTaper:
3685   case SMESHOp::OpAspectRatio:
3686   case SMESHOp::OpMinimumAngle:
3687   case SMESHOp::OpWarpingAngle:
3688   case SMESHOp::OpSkew:
3689   case SMESHOp::OpMaxElementLength2D:
3690   case SMESHOp::OpEqualFace:
3691   case SMESHOp::OpAspectRatio3D:
3692   case SMESHOp::OpVolume:
3693   case SMESHOp::OpMaxElementLength3D:
3694   case SMESHOp::OpBareBorderVolume:
3695   case SMESHOp::OpOverConstrainedVolume:
3696   case SMESHOp::OpEqualVolume:
3697     if ( vtkwnd ) {
3698
3699       LightApp_SelectionMgr* mgr = selectionMgr();
3700       SALOME_ListIO selected; mgr->selectedObjects( selected );
3701
3702       if( !selected.IsEmpty() ) {
3703         SUIT_OverrideCursor wc;
3704         ::Control( theCommandID );
3705         break;
3706       }
3707       SUIT_MessageBox::warning(desktop(),
3708                                tr( "SMESH_WRN_WARNING" ),
3709                                tr( "SMESH_BAD_SELECTION" ) );
3710       break;
3711     }
3712     else {
3713       SUIT_MessageBox::warning(desktop(),
3714                                tr( "SMESH_WRN_WARNING" ),
3715                                tr( "NOT_A_VTK_VIEWER" ) );
3716     }
3717     break;
3718   case SMESHOp::OpOverallMeshQuality:
3719     OverallMeshQuality();
3720     break;
3721   case SMESHOp::OpNumberingNodes:
3722     {
3723       SUIT_OverrideCursor wc;
3724       LightApp_SelectionMgr* mgr = selectionMgr();
3725       SALOME_ListIO selected; mgr->selectedObjects( selected );
3726
3727       SALOME_ListIteratorOfListIO it(selected);
3728       for( ; it.More(); it.Next()) {
3729         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3730         if(anIObject->hasEntry()) {
3731           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3732             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3733           }
3734         }
3735       }
3736       break;
3737     }
3738   case SMESHOp::OpNumberingElements:
3739     {
3740       SUIT_OverrideCursor wc;
3741       LightApp_SelectionMgr* mgr = selectionMgr();
3742       SALOME_ListIO selected; mgr->selectedObjects( selected );
3743
3744       SALOME_ListIteratorOfListIO it(selected);
3745       for( ; it.More(); it.Next()) {
3746         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3747         if(anIObject->hasEntry())
3748           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3749             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3750           }
3751       }
3752       break;
3753     }
3754   case SMESHOp::OpPropertiesLength:
3755   case SMESHOp::OpPropertiesArea:
3756   case SMESHOp::OpPropertiesVolume:
3757   case SMESHOp::OpMinimumDistance:
3758   case SMESHOp::OpBoundingBox:
3759   case SMESHOp::OpAngle:
3760     {
3761       int page = SMESHGUI_MeasureDlg::MinDistance;
3762       if ( theCommandID == SMESHOp::OpBoundingBox )
3763         page = SMESHGUI_MeasureDlg::BoundingBox;
3764       else if ( theCommandID == SMESHOp::OpPropertiesLength )
3765         page = SMESHGUI_MeasureDlg::Length;
3766       else if ( theCommandID == SMESHOp::OpPropertiesArea )
3767         page = SMESHGUI_MeasureDlg::Area;
3768       else if ( theCommandID == SMESHOp::OpPropertiesVolume )
3769         page = SMESHGUI_MeasureDlg::Volume;
3770       else if ( theCommandID == SMESHOp::OpAngle )
3771         page = SMESHGUI_MeasureDlg::Angle;
3772
3773       EmitSignalDeactivateDialog();
3774       SMESHGUI_MeasureDlg* dlg = new SMESHGUI_MeasureDlg( SMESHGUI::desktop(), page );
3775       dlg->show();
3776       break;
3777     }
3778   case SMESHOp::OpSortChild:
3779     ::sortChildren();
3780     break;
3781   case SMESHOp::OpBreakLink:
3782     ::breakShaperLink();
3783     break;
3784
3785   }
3786
3787   anApp->updateActions(); //SRN: To update a Save button in the toolbar
3788   //updateObjBrowser();
3789   return true;
3790 }
3791
3792 //=============================================================================
3793 /*!
3794  *
3795  */
3796 //=============================================================================
3797 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3798 {
3799   return false;
3800 }
3801
3802 //=============================================================================
3803 /*!
3804  *
3805  */
3806 //=============================================================================
3807 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3808 {
3809   return true;
3810 }
3811
3812 //=============================================================================
3813 /*!
3814  *
3815  */
3816 //=============================================================================
3817 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
3818 {
3819   return true;
3820 }
3821
3822 //=============================================================================
3823 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3824  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3825  */
3826 //=============================================================================
3827 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
3828                                   SUIT_ViewWindow* wnd )
3829 {
3830   if(theIO->hasEntry()){
3831     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
3832     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
3833   }
3834 }
3835
3836 //=======================================================================
3837 // function : createSMESHAction
3838 // purpose  :
3839 //=======================================================================
3840 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id,
3841                                   const int key, const bool toggle, const QString& shortcutAction  )
3842 {
3843   QIcon icon;
3844   QWidget* parent = application()->desktop();
3845   SUIT_ResourceMgr* resMgr = resourceMgr();
3846   QPixmap pix;
3847   if ( !icon_id.isEmpty() )
3848     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
3849   else
3850     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
3851   if ( !pix.isNull() )
3852     icon = QIcon( pix );
3853
3854   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
3855           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
3856           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
3857
3858   createAction( id, tooltip, icon, menu, status_bar, key, parent,
3859                 toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
3860 }
3861
3862 //=======================================================================
3863 // function : createPopupItem
3864 // purpose  :
3865 //=======================================================================
3866 void SMESHGUI::createPopupItem( const int id,
3867                                 const QString& clients,
3868                                 const QString& types,
3869                                 const QString& theRule,
3870                                 const int pId )
3871 {
3872   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
3873     popupMgr()->insert( action( id ), pId, 0 );
3874
3875   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3876   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
3877   QString rule = "(%1) and (%2) and (%3)";
3878   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
3879   if( clients.isEmpty() )
3880     rule = rule.arg( QString( "true" ) );
3881   else
3882     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
3883   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
3884   rule += theRule;
3885
3886   bool cont = myRules.contains( id );
3887   if( cont )
3888     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
3889
3890   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
3891   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
3892 }
3893
3894 //=======================================================================
3895 // function : initialize
3896 // purpose  :
3897 //=======================================================================
3898 void SMESHGUI::initialize( CAM_Application* app )
3899 {
3900   SalomeApp_Module::initialize( app );
3901
3902 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
3903 //   if ( mgr )
3904   /* Automatic Update flag */
3905 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
3906
3907   // ----- create actions --------------
3908
3909   //createSMESHAction(  SMESHOp::OpImportDAT, "IMPORT_DAT", "", (Qt::CTRL+Qt::Key_B) );
3910   createSMESHAction( SMESHOp::OpImportUNV, "IMPORT_UNV", "", (Qt::CTRL+Qt::Key_I) );
3911   createSMESHAction( SMESHOp::OpImportMED, "IMPORT_MED", "", (Qt::CTRL+Qt::Key_M) );
3912   createSMESHAction( SMESHOp::OpImportSTL, "IMPORT_STL"  );
3913 #ifdef WITH_CGNS
3914   createSMESHAction( SMESHOp::OpImportCGNS, "IMPORT_CGNS" );
3915 #endif
3916   createSMESHAction( SMESHOp::OpImportSAUV, "IMPORT_SAUV" );
3917   createSMESHAction( SMESHOp::OpImportGMF,  "IMPORT_GMF"  );
3918   createSMESHAction( SMESHOp::OpPopupImportUNV, "IMPORT_UNV");
3919   createSMESHAction( SMESHOp::OpPopupImportMED, "IMPORT_MED");
3920   createSMESHAction( SMESHOp::OpPopupImportSTL, "IMPORT_STL"  );
3921 #ifdef WITH_CGNS
3922   createSMESHAction( SMESHOp::OpPopupImportCGNS, "IMPORT_CGNS" );
3923 #endif
3924   createSMESHAction( SMESHOp::OpPopupImportSAUV, "IMPORT_SAUV" );
3925   createSMESHAction( SMESHOp::OpPopupImportGMF,  "IMPORT_GMF"  );
3926
3927   createSMESHAction( SMESHOp::OpExportDAT,  "DAT" );
3928   createSMESHAction( SMESHOp::OpExportMED,  "MED" );
3929   createSMESHAction( SMESHOp::OpExportUNV,  "UNV" );
3930   createSMESHAction( SMESHOp::OpExportSTL,  "STL" );
3931 #ifdef WITH_CGNS
3932   createSMESHAction( SMESHOp::OpExportCGNS, "CGNS");
3933 #endif
3934   createSMESHAction( SMESHOp::OpExportSAUV,     "SAUV");
3935   createSMESHAction( SMESHOp::OpExportGMF,      "GMF" );
3936   createSMESHAction( SMESHOp::OpPopupExportDAT, "DAT" );
3937   createSMESHAction( SMESHOp::OpPopupExportMED, "MED" );
3938   createSMESHAction( SMESHOp::OpPopupExportUNV, "UNV" );
3939   createSMESHAction( SMESHOp::OpPopupExportSTL, "STL" );
3940 #ifdef WITH_CGNS
3941   createSMESHAction( SMESHOp::OpPopupExportCGNS, "CGNS");
3942 #endif
3943   createSMESHAction( SMESHOp::OpPopupExportSAUV, "SAUV");
3944   createSMESHAction( SMESHOp::OpPopupExportGMF,  "GMF" );
3945   createSMESHAction( SMESHOp::OpFileInformation, "FILE_INFO" );
3946   createSMESHAction( SMESHOp::OpDelete,          "DELETE", "ICON_DELETE", Qt::Key_Delete );
3947   createSMESHAction( SMESHOp::OpSelectFiltersLibrary, "SEL_FILTER_LIB" );
3948   createSMESHAction( SMESHOp::OpCreateMesh,           "CREATE_MESH",             "ICON_DLG_INIT_MESH" );
3949   createSMESHAction( SMESHOp::OpCreateSubMesh,        "CREATE_SUBMESH",          "ICON_DLG_ADD_SUBMESH" );
3950   createSMESHAction( SMESHOp::OpEditMeshOrSubMesh,    "EDIT_MESHSUBMESH",        "ICON_DLG_EDIT_MESH" );
3951   createSMESHAction( SMESHOp::OpEditMesh,             "EDIT_MESH",               "ICON_DLG_EDIT_MESH" );
3952   createSMESHAction( SMESHOp::OpEditSubMesh,          "EDIT_SUBMESH",            "ICON_DLG_EDIT_MESH" );
3953   createSMESHAction( SMESHOp::OpBuildCompoundMesh,    "BUILD_COMPOUND",          "ICON_BUILD_COMPOUND" );
3954   createSMESHAction( SMESHOp::OpCopyMesh,             "COPY_MESH",               "ICON_COPY_MESH" );
3955   createSMESHAction( SMESHOp::OpCompute,              "COMPUTE",                 "ICON_COMPUTE" );
3956   createSMESHAction( SMESHOp::OpComputeSubMesh,       "COMPUTE_SUBMESH",         "ICON_COMPUTE" );
3957   createSMESHAction( SMESHOp::OpPreCompute,           "PRECOMPUTE",              "ICON_PRECOMPUTE" );
3958   createSMESHAction( SMESHOp::OpEvaluate,             "EVALUATE",                "ICON_EVALUATE" );
3959   createSMESHAction( SMESHOp::OpMeshOrder,            "MESH_ORDER",              "ICON_MESH_ORDER");
3960   createSMESHAction( SMESHOp::OpCreateGroup,          "CREATE_GROUP",            "ICON_CREATE_GROUP" );
3961   createSMESHAction( SMESHOp::OpCreateGeometryGroup,  "CREATE_GEO_GROUP",        "ICON_CREATE_GEO_GROUP" );
3962   createSMESHAction( SMESHOp::OpConstructGroup,       "CONSTRUCT_GROUP",         "ICON_CONSTRUCT_GROUP" );
3963   createSMESHAction( SMESHOp::OpEditGroup,            "EDIT_GROUP",              "ICON_EDIT_GROUP" );
3964   createSMESHAction( SMESHOp::OpEditGeomGroupAsGroup, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
3965   createSMESHAction( SMESHOp::OpUnionGroups,          "UN_GROUP",                "ICON_UNION" );
3966   createSMESHAction( SMESHOp::OpIntersectGroups,      "INT_GROUP",               "ICON_INTERSECT" );
3967   createSMESHAction( SMESHOp::OpCutGroups,            "CUT_GROUP",               "ICON_CUT" );
3968   createSMESHAction( SMESHOp::OpGroupUnderlyingElem,  "UNDERLYING_ELEMS",        "ICON_UNDERLYING_ELEMS" );
3969   createSMESHAction( SMESHOp::OpFaceGroupsByEdges,    "FACE_GROUPS_BY_EDGES",    "ICON_FACE_GROUPS_BY_EDGES" );
3970   createSMESHAction( SMESHOp::OpAddElemGroupPopup,    "ADD_TO_GROUP" );
3971   createSMESHAction( SMESHOp::OpRemoveElemGroupPopup, "REMOVE_FROM_GROUP" );
3972   createSMESHAction( SMESHOp::OpDeleteGroup,          "DEL_GROUP",               "ICON_DEL_GROUP" );
3973   createSMESHAction( SMESHOp::OpMeshInformation ,     "ADV_INFO",                "ICON_ADV_INFO" );
3974   //createSMESHAction( SMESHOp::OpStdInfo, "STD_INFO",        "ICON_STD_INFO" );
3975   //createSMESHAction( SMESHOp::OpWhatIs, "WHAT_IS",         "ICON_WHAT_IS" ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
3976   createSMESHAction( SMESHOp::OpFindElementByPoint,   "FIND_ELEM",               "ICON_FIND_ELEM" );
3977   //update
3978   createSMESHAction( SMESHOp::OpFreeNode,              "FREE_NODE",               "ICON_FREE_NODE",     0, true );
3979   createSMESHAction( SMESHOp::OpEqualNode,             "EQUAL_NODE",              "ICON_EQUAL_NODE",    0, true );
3980   createSMESHAction( SMESHOp::OpNodeConnectivityNb,    "NODE_CONNECTIVITY_NB",    "ICON_NODE_CONN_NB",    0, true );
3981   createSMESHAction( SMESHOp::OpFreeEdge,              "FREE_EDGE",               "ICON_FREE_EDGE",     0, true );
3982   createSMESHAction( SMESHOp::OpFreeBorder,            "FREE_BORDER",             "ICON_FREE_EDGE_2D",  0, true );
3983   createSMESHAction( SMESHOp::OpLength,                "LENGTH",                  "ICON_LENGTH",        0, true );
3984   createSMESHAction( SMESHOp::OpConnection,            "CONNECTION",              "ICON_CONNECTION",    0, true );
3985   createSMESHAction( SMESHOp::OpEqualEdge,             "EQUAL_EDGE",              "ICON_EQUAL_EDGE",    0, true );
3986   createSMESHAction( SMESHOp::OpFreeFace,              "FREE_FACES",              "ICON_FREE_FACES",    0, true );
3987   createSMESHAction( SMESHOp::OpBareBorderFace,        "BARE_BORDER_FACE",        "ICON_BARE_BORDER_FACE",        0, true );
3988   createSMESHAction( SMESHOp::OpOverConstrainedFace,   "OVER_CONSTRAINED_FACE",   "ICON_OVER_CONSTRAINED_FACE",   0, true );
3989   createSMESHAction( SMESHOp::OpLength2D,              "LENGTH_2D",               "ICON_LENGTH_2D",     0, true );
3990   createSMESHAction( SMESHOp::OpDeflection2D,          "DEFLECTION_2D",           "ICON_DEFLECTION_2D", 0, true );
3991   createSMESHAction( SMESHOp::OpConnection2D,          "CONNECTION_2D",           "ICON_CONNECTION_2D", 0, true );
3992   createSMESHAction( SMESHOp::OpArea,                  "AREA",                    "ICON_AREA",          0, true );
3993   createSMESHAction( SMESHOp::OpTaper,                 "TAPER",                   "ICON_TAPER",         0, true );
3994   createSMESHAction( SMESHOp::OpAspectRatio,           "ASPECT",                  "ICON_ASPECT",        0, true );
3995   createSMESHAction( SMESHOp::OpMinimumAngle,          "MIN_ANG",                 "ICON_ANGLE",         0, true );
3996   createSMESHAction( SMESHOp::OpWarpingAngle,          "WARP",                    "ICON_WARP",          0, true );
3997   createSMESHAction( SMESHOp::OpSkew,                  "SKEW",                    "ICON_SKEW",          0, true );
3998   createSMESHAction( SMESHOp::OpMaxElementLength2D,    "MAX_ELEMENT_LENGTH_2D",   "ICON_MAX_ELEMENT_LENGTH_2D",   0, true );
3999   createSMESHAction( SMESHOp::OpEqualFace,             "EQUAL_FACE",              "ICON_EQUAL_FACE",    0, true );
4000   createSMESHAction( SMESHOp::OpAspectRatio3D,         "ASPECT_3D",               "ICON_ASPECT_3D",     0, true );
4001   createSMESHAction( SMESHOp::OpVolume,                "VOLUME_3D",               "ICON_VOLUME_3D",     0, true );
4002   createSMESHAction( SMESHOp::OpMaxElementLength3D,    "MAX_ELEMENT_LENGTH_3D",   "ICON_MAX_ELEMENT_LENGTH_3D",   0, true );
4003   createSMESHAction( SMESHOp::OpBareBorderVolume,      "BARE_BORDER_VOLUME",      "ICON_BARE_BORDER_VOLUME",      0, true );
4004   createSMESHAction( SMESHOp::OpOverConstrainedVolume, "OVER_CONSTRAINED_VOLUME", "ICON_OVER_CONSTRAINED_VOLUME", 0, true );
4005   createSMESHAction( SMESHOp::OpEqualVolume,           "EQUAL_VOLUME",            "ICON_EQUAL_VOLUME",  0, true );
4006   createSMESHAction( SMESHOp::OpOverallMeshQuality,    "OVERALL_MESH_QUALITY",    "ICON_OVL_MESH_QUALITY" );
4007
4008   createSMESHAction( SMESHOp::OpNode,                   "NODE",            "ICON_DLG_NODE" );
4009   createSMESHAction( SMESHOp::OpElem0D,                 "ELEM0D",          "ICON_DLG_ELEM0D" );
4010   createSMESHAction( SMESHOp::OpElem0DOnElemNodes,      "0D_ON_ALL_NODES", "ICON_0D_ON_ALL_NODES" );
4011   createSMESHAction( SMESHOp::OpBall,                   "BALL",            "ICON_DLG_BALL" );
4012   createSMESHAction( SMESHOp::OpEdge,                   "EDGE",            "ICON_DLG_EDGE" );
4013   createSMESHAction( SMESHOp::OpTriangle,               "TRIANGLE",        "ICON_DLG_TRIANGLE" );
4014   createSMESHAction( SMESHOp::OpQuadrangle,             "QUAD",            "ICON_DLG_QUADRANGLE" );
4015   createSMESHAction( SMESHOp::OpPolygon,                "POLYGON",         "ICON_DLG_POLYGON" );
4016   createSMESHAction( SMESHOp::OpTetrahedron,            "TETRA",           "ICON_DLG_TETRAS" );
4017   createSMESHAction( SMESHOp::OpHexahedron,             "HEXA",            "ICON_DLG_HEXAS" );
4018   createSMESHAction( SMESHOp::OpPentahedron,            "PENTA",           "ICON_DLG_PENTA" );
4019   createSMESHAction( SMESHOp::OpPyramid ,               "PYRAMID",         "ICON_DLG_PYRAMID" );
4020   createSMESHAction( SMESHOp::OpHexagonalPrism,         "OCTA",            "ICON_DLG_OCTA" );
4021   createSMESHAction( SMESHOp::OpPolyhedron,             "POLYHEDRON",      "ICON_DLG_POLYHEDRON" );
4022   createSMESHAction( SMESHOp::OpQuadraticEdge,          "QUADRATIC_EDGE",          "ICON_DLG_QUADRATIC_EDGE" );
4023   createSMESHAction( SMESHOp::OpQuadraticTriangle,      "QUADRATIC_TRIANGLE",      "ICON_DLG_QUADRATIC_TRIANGLE" );
4024   createSMESHAction( SMESHOp::OpBiQuadraticTriangle,    "BIQUADRATIC_TRIANGLE",    "ICON_DLG_BIQUADRATIC_TRIANGLE" );
4025   createSMESHAction( SMESHOp::OpQuadraticQuadrangle,    "QUADRATIC_QUADRANGLE",    "ICON_DLG_QUADRATIC_QUADRANGLE" );
4026   createSMESHAction( SMESHOp::OpBiQuadraticQuadrangle,  "BIQUADRATIC_QUADRANGLE",  "ICON_DLG_BIQUADRATIC_QUADRANGLE" );
4027   createSMESHAction( SMESHOp::OpQuadraticPolygon,       "QUADRATIC_POLYGON",       "ICON_DLG_QUADRATIC_POLYGON" );
4028   createSMESHAction( SMESHOp::OpQuadraticTetrahedron,   "QUADRATIC_TETRAHEDRON",   "ICON_DLG_QUADRATIC_TETRAHEDRON" );
4029   createSMESHAction( SMESHOp::OpQuadraticPyramid,       "QUADRATIC_PYRAMID",       "ICON_DLG_QUADRATIC_PYRAMID" );
4030   createSMESHAction( SMESHOp::OpQuadraticPentahedron,   "QUADRATIC_PENTAHEDRON",   "ICON_DLG_QUADRATIC_PENTAHEDRON" );
4031   createSMESHAction( SMESHOp::OpBiQuadraticPentahedron, "BIQUADRATIC_PENTAHEDRON", "ICON_DLG_BIQUADRATIC_PENTAHEDRON" );
4032   createSMESHAction( SMESHOp::OpQuadraticHexahedron,    "QUADRATIC_HEXAHEDRON",    "ICON_DLG_QUADRATIC_HEXAHEDRON" );
4033   createSMESHAction( SMESHOp::OpTriQuadraticHexahedron, "TRIQUADRATIC_HEXAHEDRON", "ICON_DLG_TRIQUADRATIC_HEXAHEDRON" );
4034
4035   createSMESHAction( SMESHOp::OpRemoveNodes,       "REMOVE_NODES",          "ICON_DLG_REM_NODE" );
4036   createSMESHAction( SMESHOp::OpRemoveElements,    "REMOVE_ELEMENTS",       "ICON_DLG_REM_ELEMENT" );
4037   createSMESHAction( SMESHOp::OpRemoveOrphanNodes, "REMOVE_ORPHAN_NODES",   "ICON_DLG_REM_ORPHAN_NODES" );
4038   createSMESHAction( SMESHOp::OpClearMesh,         "CLEAR_MESH",            "ICON_CLEAR_MESH" );
4039
4040   //createSMESHAction( SMESHOp::OpRenumberingNodes,    "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
4041   //createSMESHAction( SMESHOp::OpRenumberingElements, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
4042
4043   createSMESHAction( SMESHOp::OpTranslation,            "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
4044   createSMESHAction( SMESHOp::OpRotation,               "ROT",             "ICON_DLG_MESH_ROTATION" );
4045   createSMESHAction( SMESHOp::OpSymmetry,               "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
4046   createSMESHAction( SMESHOp::OpScale,                  "SCALE",           "ICON_DLG_MESH_SCALE" );
4047   createSMESHAction( SMESHOp::OpOffset,                 "OFFSET",          "ICON_DLG_MESH_OFFSET" );
4048   createSMESHAction( SMESHOp::OpSewing,                 "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
4049   createSMESHAction( SMESHOp::OpMergeNodes,             "MERGE",           "ICON_SMESH_MERGE_NODES" );
4050   createSMESHAction( SMESHOp::OpMergeElements,          "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
4051   createSMESHAction( SMESHOp::OpMoveNode,               "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
4052   createSMESHAction( SMESHOp::OpDuplicateNodes,         "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
4053   createSMESHAction( SMESHOp::OpDiagonalInversion,      "INV",             "ICON_DLG_MESH_DIAGONAL" );
4054   createSMESHAction( SMESHOp::OpUnionOfTwoTriangle,     "UNION2",          "ICON_UNION2TRI" );
4055   createSMESHAction( SMESHOp::OpOrientation,            "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
4056   createSMESHAction( SMESHOp::OpReorientFaces,          "REORIENT_2D",     "ICON_REORIENT_2D" );
4057   createSMESHAction( SMESHOp::OpUnionOfTriangles,       "UNION",           "ICON_UNIONTRI" );
4058   createSMESHAction( SMESHOp::OpCuttingOfQuadrangles,   "CUT",             "ICON_CUTQUAD" );
4059   createSMESHAction( SMESHOp::OpSplitVolumes,           "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
4060   createSMESHAction( SMESHOp::OpSplitBiQuadratic,       "SPLIT_BIQUAD",    "ICON_SPLIT_BIQUAD" );
4061   createSMESHAction( SMESHOp::OpSmoothing,              "SMOOTH",          "ICON_DLG_SMOOTHING" );
4062   createSMESHAction( SMESHOp::OpExtrusion,              "EXTRUSION",       "ICON_EXTRUSION" );
4063   createSMESHAction( SMESHOp::OpExtrusionAlongAPath,    "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
4064   createSMESHAction( SMESHOp::OpRevolution,             "REVOLUTION",      "ICON_REVOLUTION" );
4065   createSMESHAction( SMESHOp::OpPatternMapping,         "MAP",             "ICON_MAP" );
4066   createSMESHAction( SMESHOp::OpConvertMeshToQuadratic, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
4067   createSMESHAction( SMESHOp::OpCreateBoundaryElements, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
4068
4069   createSMESHAction( SMESHOp::OpReset,               "RESET" );
4070   createSMESHAction( SMESHOp::OpScalarBarProperties, "SCALAR_BAR_PROP" );
4071   createSMESHAction( SMESHOp::OpShowScalarBar,       "SHOW_SCALAR_BAR","",0, true  );
4072   createSMESHAction( SMESHOp::OpSaveDistribution,    "SAVE_DISTRIBUTION" );
4073   createSMESHAction( SMESHOp::OpShowDistribution,    "SHOW_DISTRIBUTION","",0, true );
4074 #ifndef DISABLE_PLOT2DVIEWER
4075   createSMESHAction( SMESHOp::OpPlotDistribution, "PLOT_DISTRIBUTION" );
4076 #endif
4077   createSMESHAction( SMESHOp::OpDMWireframe,  "WIRE",    "ICON_WIRE", 0, true );
4078   createSMESHAction( SMESHOp::OpDMShading,    "SHADE",   "ICON_SHADE", 0, true );
4079   createSMESHAction( SMESHOp::OpDMNodes,      "NODES",   "ICON_POINTS", 0, true );
4080   createSMESHAction( SMESHOp::OpDMShrink,     "SHRINK",  "ICON_SHRINK", 0, true );
4081   createSMESHAction( SMESHOp::OpUpdate,       "UPDATE",  "ICON_UPDATE" );
4082   createSMESHAction( SMESHOp::OpDE0DElements, "ELEMS0D", "ICON_DLG_ELEM0D", 0, true );
4083   createSMESHAction( SMESHOp::OpDEEdges,      "EDGES",   "ICON_DLG_EDGE", 0, true );
4084   createSMESHAction( SMESHOp::OpDEFaces,      "FACES",   "ICON_DLG_TRIANGLE", 0, true );
4085   createSMESHAction( SMESHOp::OpDEVolumes,    "VOLUMES", "ICON_DLG_TETRAS", 0, true );
4086   createSMESHAction( SMESHOp::OpDEBalls,      "BALLS",   "ICON_DLG_BALL", 0, true );
4087   createSMESHAction( SMESHOp::OpDEChoose,     "CHOOSE",  "ICON_DLG_CHOOSE", 0, false );
4088   createSMESHAction( SMESHOp::OpDEAllEntity,  "ALL",     "ICON_DLG_CHOOSE_ALL", 0, false );
4089   createSMESHAction( SMESHOp::OpOrientationOnFaces, "FACE_ORIENTATION", "", 0, true );
4090
4091   createSMESHAction( SMESHOp::OpRepresentationLines, "LINE_REPRESENTATION", "", 0, true );
4092   createSMESHAction( SMESHOp::OpRepresentationArcs,  "ARC_REPRESENTATION", "", 0, true );
4093
4094   createSMESHAction( SMESHOp::OpEditHypothesis,    "EDIT_HYPO" );
4095   createSMESHAction( SMESHOp::OpUnassign,          "UNASSIGN" );
4096   createSMESHAction( SMESHOp::OpNumberingNodes,    "NUM_NODES", "", 0, true );
4097   createSMESHAction( SMESHOp::OpNumberingElements, "NUM_ELEMENTS", "", 0, true );
4098   createSMESHAction( SMESHOp::OpProperties,   "COLORS" );
4099   createSMESHAction( SMESHOp::OpTransparency, "TRANSP" );
4100   createSMESHAction( SMESHOp::OpClipping,     "CLIP" );
4101   createSMESHAction( SMESHOp::OpAutoColor,        "AUTO_COLOR" );
4102   createSMESHAction( SMESHOp::OpDisableAutoColor, "DISABLE_AUTO_COLOR" );
4103
4104   createSMESHAction( SMESHOp::OpMinimumDistance,  "MEASURE_MIN_DIST", "ICON_MEASURE_MIN_DIST" );
4105   createSMESHAction( SMESHOp::OpBoundingBox,      "MEASURE_BND_BOX",  "ICON_MEASURE_BND_BOX" );
4106   createSMESHAction( SMESHOp::OpPropertiesLength, "MEASURE_LENGTH",   "ICON_MEASURE_LENGTH" );
4107   createSMESHAction( SMESHOp::OpPropertiesArea,   "MEASURE_AREA",     "ICON_MEASURE_AREA" );
4108   createSMESHAction( SMESHOp::OpPropertiesVolume, "MEASURE_VOLUME",   "ICON_MEASURE_VOLUME" );
4109   createSMESHAction( SMESHOp::OpAngle,            "MEASURE_ANGLE",    "ICON_MEASURE_ANGLE" );
4110
4111   createSMESHAction( SMESHOp::OpHide,     "HIDE", "ICON_HIDE" );
4112   createSMESHAction( SMESHOp::OpShow,     "SHOW", "ICON_SHOW" );
4113   createSMESHAction( SMESHOp::OpShowOnly, "DISPLAY_ONLY" );
4114
4115   createSMESHAction( SMESHOp::OpSortChild, "SORT_CHILD_ITEMS" );
4116
4117   createSMESHAction( SMESHOp::OpBreakLink, "BREAK_SHAPER_LINK" );
4118
4119   QList<int> aCtrlActions;
4120   aCtrlActions << SMESHOp::OpFreeNode << SMESHOp::OpEqualNode
4121                << SMESHOp::OpNodeConnectivityNb                                         // node controls
4122                << SMESHOp::OpFreeEdge << SMESHOp::OpFreeBorder
4123                << SMESHOp::OpLength << SMESHOp::OpConnection << SMESHOp::OpEqualEdge    // edge controls
4124                << SMESHOp::OpDeflection2D
4125                << SMESHOp::OpFreeFace << SMESHOp::OpLength2D << SMESHOp::OpConnection2D
4126                << SMESHOp::OpArea << SMESHOp::OpTaper << SMESHOp::OpAspectRatio
4127                << SMESHOp::OpMinimumAngle << SMESHOp::OpWarpingAngle << SMESHOp::OpSkew
4128                << SMESHOp::OpMaxElementLength2D << SMESHOp::OpBareBorderFace
4129                << SMESHOp::OpOverConstrainedFace << SMESHOp::OpEqualFace                // face controls
4130                << SMESHOp::OpAspectRatio3D << SMESHOp::OpVolume
4131                << SMESHOp::OpMaxElementLength3D << SMESHOp::OpBareBorderVolume
4132                << SMESHOp::OpOverConstrainedVolume << SMESHOp::OpEqualVolume;           // volume controls
4133   QActionGroup* aCtrlGroup = new QActionGroup( application()->desktop() );
4134   aCtrlGroup->setExclusive( true );
4135   for( int i = 0; i < aCtrlActions.size(); i++ )
4136     aCtrlGroup->addAction( action( aCtrlActions[i] ) );
4137
4138   // ----- create menu --------------
4139   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
4140       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
4141       toolsId   = createMenu( tr( "MEN_TOOLS" ),   -1,  5, 50 ),
4142       meshId    = createMenu( tr( "MEN_MESH" ),    -1, 70, 10 ),
4143       ctrlId    = createMenu( tr( "MEN_CTRL" ),    -1, 60, 10 ),
4144       modifyId  = createMenu( tr( "MEN_MODIFY" ),  -1, 40, 10 ),
4145       measureId = createMenu( tr( "MEN_MEASURE" ), -1, 50, 10 ),
4146       viewId    = createMenu( tr( "MEN_VIEW" ),    -1,  2 );
4147
4148   createMenu( separator(), fileId );
4149
4150   QMenu* nodeMenu = new QMenu(); QMenu* edgeMenu = new QMenu();
4151   QMenu* faceMenu = new QMenu(); QMenu* volumeMenu = new QMenu();
4152   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
4153       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
4154       nodeId   = createMenu( tr( "MEN_NODE_CTRL" ), ctrlId, -1, 10, -1, nodeMenu ),
4155       edgeId   = createMenu( tr( "MEN_EDGE_CTRL" ), ctrlId, -1, 10, -1, edgeMenu ),
4156       faceId   = createMenu( tr( "MEN_FACE_CTRL" ), ctrlId, -1, 10, -1, faceMenu ),
4157       volumeId = createMenu( tr( "MEN_VOLUME_CTRL" ), ctrlId, -1, 10, -1, volumeMenu ),
4158       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
4159       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
4160     //renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
4161       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 ),
4162       basicPropId = createMenu( tr( "MEN_BASIC_PROPERTIES" ), measureId, -1, 10 );
4163
4164   //createMenu( SMESHOp::OpImportDAT, importId, -1 );
4165   createMenu( SMESHOp::OpImportUNV,  importId, -1 );
4166   createMenu( SMESHOp::OpImportMED,  importId, -1 );
4167   createMenu( SMESHOp::OpImportSTL,  importId, -1 );
4168 #ifdef WITH_CGNS
4169   createMenu( SMESHOp::OpImportCGNS, importId, -1 );
4170 #endif
4171   createMenu( SMESHOp::OpImportSAUV, importId, -1 );
4172   createMenu( SMESHOp::OpImportGMF,  importId, -1 );
4173   createMenu( SMESHOp::OpExportDAT,  exportId, -1 );
4174   createMenu( SMESHOp::OpExportMED,  exportId, -1 );
4175   createMenu( SMESHOp::OpExportUNV,  exportId, -1 );
4176   createMenu( SMESHOp::OpExportSTL,  exportId, -1 );
4177 #ifdef WITH_CGNS
4178   createMenu( SMESHOp::OpExportCGNS, exportId, -1 );
4179 #endif
4180   createMenu( SMESHOp::OpExportSAUV, exportId, -1 );
4181   createMenu( SMESHOp::OpExportGMF,  exportId, -1 );
4182   createMenu( separator(), fileId, 10 );
4183
4184   createMenu( SMESHOp::OpDelete, editId, -1 );
4185
4186   createMenu( SMESHOp::OpSelectFiltersLibrary, toolsId, -1 );
4187
4188   createMenu( SMESHOp::OpCreateMesh,           meshId, -1 ); // "Mesh" menu
4189   createMenu( SMESHOp::OpCreateSubMesh,        meshId, -1 );
4190   createMenu( SMESHOp::OpEditMeshOrSubMesh,    meshId, -1 );
4191   createMenu( SMESHOp::OpBuildCompoundMesh,    meshId, -1 );
4192   createMenu( SMESHOp::OpCopyMesh,             meshId, -1 );
4193   createMenu( separator(),                     meshId, -1 );
4194   createMenu( SMESHOp::OpCompute,              meshId, -1 );
4195   createMenu( SMESHOp::OpPreCompute,           meshId, -1 );
4196   createMenu( SMESHOp::OpEvaluate,             meshId, -1 );
4197   createMenu( SMESHOp::OpMeshOrder,            meshId, -1 );
4198   createMenu( separator(),                     meshId, -1 );
4199   createMenu( SMESHOp::OpCreateGroup,          meshId, -1 );
4200   createMenu( SMESHOp::OpCreateGeometryGroup,  meshId, -1 );
4201   createMenu( SMESHOp::OpConstructGroup,       meshId, -1 );
4202   createMenu( SMESHOp::OpEditGroup,            meshId, -1 );
4203   createMenu( SMESHOp::OpEditGeomGroupAsGroup, meshId, -1 );
4204   createMenu( separator(),                     meshId, -1 );
4205   createMenu( SMESHOp::OpUnionGroups,          meshId, -1 );
4206   createMenu( SMESHOp::OpIntersectGroups,      meshId, -1 );
4207   createMenu( SMESHOp::OpCutGroups,            meshId, -1 );
4208   createMenu( separator(),                     meshId, -1 );
4209   createMenu( SMESHOp::OpGroupUnderlyingElem,  meshId, -1 );
4210   createMenu( SMESHOp::OpFaceGroupsByEdges,    meshId, -1 );
4211   createMenu( separator(),                     meshId, -1 );
4212   createMenu( SMESHOp::OpMeshInformation,      meshId, -1 );
4213   //createMenu( SMESHOp::OpStdInfo, meshId, -1 );
4214   //createMenu( SMESHOp::OpWhatIs, meshId, -1 ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4215   createMenu( SMESHOp::OpFindElementByPoint,   meshId, -1 );
4216   createMenu( separator(),                     meshId, -1 );
4217
4218   createMenu( SMESHOp::OpFreeNode,              nodeId,   -1 );
4219   createMenu( SMESHOp::OpEqualNode,             nodeId,   -1 );
4220   //createMenu( SMESHOp::OpNodeConnectivityNb,    nodeId,   -1 );
4221   createMenu( SMESHOp::OpFreeBorder,            edgeId,   -1 );
4222   createMenu( SMESHOp::OpLength,                edgeId,   -1 );
4223   createMenu( SMESHOp::OpConnection,            edgeId,   -1 );
4224   createMenu( SMESHOp::OpEqualEdge,             edgeId,   -1 );
4225   createMenu( SMESHOp::OpFreeEdge,              faceId,   -1 );
4226   createMenu( SMESHOp::OpFreeFace,              faceId,   -1 );
4227   createMenu( SMESHOp::OpBareBorderFace,        faceId,   -1 );
4228   createMenu( SMESHOp::OpOverConstrainedFace,   faceId,   -1 );
4229   createMenu( SMESHOp::OpLength2D,              faceId,   -1 );
4230   createMenu( SMESHOp::OpConnection2D,          faceId,   -1 );
4231   createMenu( SMESHOp::OpArea,                  faceId,   -1 );
4232   createMenu( SMESHOp::OpTaper,                 faceId,   -1 );
4233   createMenu( SMESHOp::OpAspectRatio,           faceId,   -1 );
4234   createMenu( SMESHOp::OpMinimumAngle,          faceId,   -1 );
4235   createMenu( SMESHOp::OpWarpingAngle,          faceId,   -1 );
4236   createMenu( SMESHOp::OpSkew,                  faceId,   -1 );
4237   createMenu( SMESHOp::OpMaxElementLength2D,    faceId,   -1 );
4238   createMenu( SMESHOp::OpEqualFace,             faceId,   -1 );
4239   createMenu( SMESHOp::OpDeflection2D,          faceId,   -1 );
4240   createMenu( SMESHOp::OpAspectRatio3D,         volumeId, -1 );
4241   createMenu( SMESHOp::OpVolume,                volumeId, -1 );
4242   createMenu( SMESHOp::OpMaxElementLength3D,    volumeId, -1 );
4243   createMenu( SMESHOp::OpBareBorderVolume,      volumeId, -1 );
4244   createMenu( SMESHOp::OpOverConstrainedVolume, volumeId, -1 );
4245   createMenu( SMESHOp::OpEqualVolume,           volumeId, -1 );
4246   createMenu( separator(),                      ctrlId,   -1 );
4247   createMenu( SMESHOp::OpReset,                 ctrlId,   -1 );
4248   createMenu( separator(),                      ctrlId,   -1 );
4249   createMenu( SMESHOp::OpOverallMeshQuality,    ctrlId,   -1 );
4250
4251   createMenu( SMESHOp::OpNode,                   addId, -1 );
4252   createMenu( SMESHOp::OpElem0D,                 addId, -1 );
4253   createMenu( SMESHOp::OpElem0DOnElemNodes,      addId, -1 );
4254   createMenu( SMESHOp::OpBall,                   addId, -1 );
4255   createMenu( SMESHOp::OpEdge,                   addId, -1 );
4256   createMenu( SMESHOp::OpTriangle,               addId, -1 );
4257   createMenu( SMESHOp::OpQuadrangle,             addId, -1 );
4258   createMenu( SMESHOp::OpPolygon,                addId, -1 );
4259   createMenu( SMESHOp::OpTetrahedron,            addId, -1 );
4260   createMenu( SMESHOp::OpHexahedron,             addId, -1 );
4261   createMenu( SMESHOp::OpPentahedron,            addId, -1 );
4262   createMenu( SMESHOp::OpPyramid,                addId, -1 );
4263   createMenu( SMESHOp::OpHexagonalPrism,         addId, -1 );
4264   createMenu( SMESHOp::OpPolyhedron,             addId, -1 );
4265   createMenu( separator(),                       addId, -1 );
4266   createMenu( SMESHOp::OpQuadraticEdge,          addId, -1 );
4267   createMenu( SMESHOp::OpQuadraticTriangle,      addId, -1 );
4268   createMenu( SMESHOp::OpBiQuadraticTriangle ,   addId, -1 );
4269   createMenu( SMESHOp::OpQuadraticQuadrangle,    addId, -1 );
4270   createMenu( SMESHOp::OpBiQuadraticQuadrangle,  addId, -1 );
4271   createMenu( SMESHOp::OpQuadraticPolygon,       addId, -1 );
4272   createMenu( SMESHOp::OpQuadraticTetrahedron,   addId, -1 );
4273   createMenu( SMESHOp::OpQuadraticPyramid,       addId, -1 );
4274   createMenu( SMESHOp::OpQuadraticPentahedron,   addId, -1 );
4275   createMenu( SMESHOp::OpBiQuadraticPentahedron, addId, -1 );
4276   createMenu( SMESHOp::OpQuadraticHexahedron,    addId, -1 );
4277   createMenu( SMESHOp::OpTriQuadraticHexahedron, addId, -1 );
4278
4279   createMenu( SMESHOp::OpRemoveNodes,       removeId, -1 );
4280   createMenu( SMESHOp::OpRemoveElements,    removeId, -1 );
4281   createMenu( SMESHOp::OpRemoveOrphanNodes, removeId, -1 );
4282   createMenu( separator(),                  removeId, -1 );
4283   createMenu( SMESHOp::OpDeleteGroup,       removeId, -1 );
4284   createMenu( separator(),                  removeId, -1 );
4285   createMenu( SMESHOp::OpClearMesh,         removeId, -1 );
4286
4287   //createMenu( SMESHOp::OpRenumberingNodes,    renumId, -1 );
4288   //createMenu( SMESHOp::OpRenumberingElements, renumId, -1 );
4289
4290   createMenu( SMESHOp::OpMergeNodes,     transfId, -1 );
4291   createMenu( SMESHOp::OpMergeElements,  transfId, -1 );
4292   createMenu( SMESHOp::OpTranslation,    transfId, -1 );
4293   createMenu( SMESHOp::OpRotation,       transfId, -1 );
4294   createMenu( SMESHOp::OpSymmetry,       transfId, -1 );
4295   createMenu( SMESHOp::OpScale,          transfId, -1 );
4296   createMenu( SMESHOp::OpOffset,         transfId, -1 );
4297   createMenu( SMESHOp::OpSewing,         transfId, -1 );
4298   createMenu( SMESHOp::OpDuplicateNodes, transfId, -1 );
4299
4300   createMenu( SMESHOp::OpConvertMeshToQuadratic, modifyId, -1 );
4301   createMenu( SMESHOp::OpCreateBoundaryElements, modifyId, -1 );
4302   createMenu( SMESHOp::OpExtrusion,              modifyId, -1 );
4303   createMenu( SMESHOp::OpExtrusionAlongAPath,    modifyId, -1 );
4304   createMenu( SMESHOp::OpRevolution,             modifyId, -1 );
4305   createMenu( SMESHOp::OpOrientation,            modifyId, -1 );
4306   createMenu( SMESHOp::OpReorientFaces,          modifyId, -1 );
4307   createMenu( SMESHOp::OpMoveNode,               modifyId, -1 );
4308   createMenu( SMESHOp::OpDiagonalInversion,      modifyId, -1 );
4309   createMenu( SMESHOp::OpUnionOfTwoTriangle,     modifyId, -1 );
4310   createMenu( SMESHOp::OpUnionOfTriangles,       modifyId, -1 );
4311   createMenu( SMESHOp::OpCuttingOfQuadrangles,   modifyId, -1 );
4312   createMenu( SMESHOp::OpSplitVolumes,           modifyId, -1 );
4313   createMenu( SMESHOp::OpSplitBiQuadratic,       modifyId, -1 );
4314   createMenu( SMESHOp::OpSmoothing,              modifyId, -1 );
4315   createMenu( SMESHOp::OpPatternMapping,         modifyId, -1 );
4316
4317   createMenu( SMESHOp::OpMinimumDistance,  measureId,   -1 );
4318   createMenu( SMESHOp::OpBoundingBox,      measureId,   -1 );
4319   createMenu( SMESHOp::OpAngle,            measureId,   -1 );
4320   createMenu( SMESHOp::OpPropertiesLength, basicPropId, -1 );
4321   createMenu( SMESHOp::OpPropertiesArea,   basicPropId, -1 );
4322   createMenu( SMESHOp::OpPropertiesVolume, basicPropId, -1 );
4323   createMenu( SMESHOp::OpUpdate,           viewId,      -1 );
4324
4325   connect( nodeMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4326   connect( edgeMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4327   connect( faceMenu,   SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4328   connect( volumeMenu, SIGNAL( aboutToShow() ), this, SLOT( onUpdateControlActions() ) );
4329
4330   // ----- create toolbars --------------
4331   int meshTb       = createTool( tr( "TB_MESH" ),      QString( "SMESHMeshToolbar" ) ),
4332       info         = createTool( tr( "TB_INFO" ),      QString( "SMESHInformationToolbar" ) ),
4333       groupTb      = createTool( tr( "TB_GROUP" ),     QString( "SMESHGroupToolbar" ) ),
4334       ctrl0dTb     = createTool( tr( "TB_CTRL0D" ),    QString( "SMESHNodeControlsToolbar" ) ),
4335       ctrl1dTb     = createTool( tr( "TB_CTRL1D" ),    QString( "SMESHEdgeControlsToolbar" ) ),
4336       ctrl2dTb     = createTool( tr( "TB_CTRL2D" ),    QString( "SMESHFaceControlsToolbar" ) ),
4337       ctrl3dTb     = createTool( tr( "TB_CTRL3D" ),    QString( "SMESHVolumeControlsToolbar" ) ),
4338       addElemTb    = createTool( tr( "TB_ADD" ),       QString( "SMESHAddElementToolbar" ) ),
4339       addNonElemTb = createTool( tr( "TB_ADDNON" ),    QString( "SMESHAddElementToolbar" ) ),
4340       remTb        = createTool( tr( "TB_REM" ),       QString( "SMESHRemoveToolbar" ) ),
4341     //renumbTb     = createTool( tr( "TB_RENUMBER" ),  QString( "SMESHRenumberingToolbar" ) ),
4342       transformTb  = createTool( tr( "TB_TRANSFORM" ), QString( "SMESHTransformationToolbar" ) ),
4343       modifyTb     = createTool( tr( "TB_MODIFY" ),    QString( "SMESHModificationToolbar" ) ),
4344       measuremTb   = createTool( tr( "TB_MEASUREM" ),  QString( "SMESHMeasurementsToolbar" ) ),
4345       dispModeTb   = createTool( tr( "TB_DISP_MODE" ), QString( "SMESHDisplayModeToolbar" ) );
4346
4347   createTool( SMESHOp::OpCreateMesh,        meshTb );
4348   createTool( SMESHOp::OpCreateSubMesh,     meshTb );
4349   createTool( SMESHOp::OpEditMeshOrSubMesh, meshTb );
4350   createTool( SMESHOp::OpBuildCompoundMesh, meshTb );
4351   createTool( SMESHOp::OpCopyMesh,          meshTb );
4352   createTool( separator(),                  meshTb );
4353   createTool( SMESHOp::OpCompute,           meshTb );
4354   createTool( SMESHOp::OpPreCompute,        meshTb );
4355   createTool( SMESHOp::OpEvaluate,          meshTb );
4356   createTool( SMESHOp::OpMeshOrder,         meshTb );
4357
4358   createTool( SMESHOp::OpCreateGroup,         groupTb );
4359   createTool( SMESHOp::OpCreateGeometryGroup, groupTb );
4360   createTool( SMESHOp::OpConstructGroup,      groupTb );
4361   createTool( SMESHOp::OpEditGroup,           groupTb );
4362
4363   createTool( SMESHOp::OpMeshInformation,    info );
4364   //createTool( SMESHOp::OpStdInfo, meshTb );
4365   //createTool( SMESHOp::OpWhatIs, meshTb ); // VSR: issue #0021242 (eliminate "Mesh Element Information" command)
4366   createTool( SMESHOp::OpFindElementByPoint, info );
4367
4368   createTool( SMESHOp::OpFreeNode,  ctrl0dTb );
4369   createTool( SMESHOp::OpEqualNode, ctrl0dTb );
4370   //createTool( SMESHOp::OpNodeConnectivityNb, ctrl0dTb );
4371
4372   createTool( SMESHOp::OpFreeBorder, ctrl1dTb );
4373   createTool( SMESHOp::OpLength,     ctrl1dTb );
4374   createTool( SMESHOp::OpConnection, ctrl1dTb );
4375   createTool( SMESHOp::OpEqualEdge,  ctrl1dTb );
4376
4377   createTool( SMESHOp::OpFreeEdge,            ctrl2dTb );
4378   createTool( SMESHOp::OpFreeFace,            ctrl2dTb );
4379   createTool( SMESHOp::OpBareBorderFace,      ctrl2dTb );
4380   createTool( SMESHOp::OpOverConstrainedFace, ctrl2dTb );
4381   createTool( SMESHOp::OpLength2D,            ctrl2dTb );
4382   createTool( SMESHOp::OpConnection2D,        ctrl2dTb );
4383   createTool( SMESHOp::OpArea,                ctrl2dTb );
4384   createTool( SMESHOp::OpTaper,               ctrl2dTb );
4385   createTool( SMESHOp::OpAspectRatio,         ctrl2dTb );
4386   createTool( SMESHOp::OpMinimumAngle,        ctrl2dTb );
4387   createTool( SMESHOp::OpWarpingAngle,        ctrl2dTb );
4388   createTool( SMESHOp::OpSkew,                ctrl2dTb );
4389   createTool( SMESHOp::OpMaxElementLength2D,  ctrl2dTb );
4390   createTool( SMESHOp::OpEqualFace,           ctrl2dTb );
4391   createTool( SMESHOp::OpDeflection2D,        ctrl2dTb );
4392
4393   createTool( SMESHOp::OpAspectRatio3D,         ctrl3dTb );
4394   createTool( SMESHOp::OpVolume,                ctrl3dTb );
4395   createTool( SMESHOp::OpMaxElementLength3D,    ctrl3dTb );
4396   createTool( SMESHOp::OpBareBorderVolume,      ctrl3dTb );
4397   createTool( SMESHOp::OpOverConstrainedVolume, ctrl3dTb );
4398   createTool( SMESHOp::OpEqualVolume,           ctrl3dTb );
4399
4400   createTool( SMESHOp::OpNode,              addElemTb );
4401   createTool( SMESHOp::OpElem0D,            addElemTb );
4402   createTool( SMESHOp::OpElem0DOnElemNodes, addElemTb );
4403   createTool( SMESHOp::OpBall,              addElemTb );
4404   createTool( SMESHOp::OpEdge,              addElemTb );
4405   createTool( SMESHOp::OpTriangle,          addElemTb );
4406   createTool( SMESHOp::OpQuadrangle,        addElemTb );
4407   createTool( SMESHOp::OpPolygon,           addElemTb );
4408   createTool( SMESHOp::OpTetrahedron,       addElemTb );
4409   createTool( SMESHOp::OpHexahedron,        addElemTb );
4410   createTool( SMESHOp::OpPentahedron,       addElemTb );
4411   createTool( SMESHOp::OpPyramid,           addElemTb );
4412   createTool( SMESHOp::OpHexagonalPrism,    addElemTb );
4413   createTool( SMESHOp::OpPolyhedron,        addElemTb );
4414
4415   createTool( SMESHOp::OpQuadraticEdge,          addNonElemTb );
4416   createTool( SMESHOp::OpQuadraticTriangle,      addNonElemTb );
4417   createTool( SMESHOp::OpBiQuadraticTriangle,    addNonElemTb );
4418   createTool( SMESHOp::OpQuadraticQuadrangle,    addNonElemTb );
4419   createTool( SMESHOp::OpBiQuadraticQuadrangle,  addNonElemTb );
4420   createTool( SMESHOp::OpQuadraticPolygon,       addNonElemTb );
4421   createTool( SMESHOp::OpQuadraticTetrahedron,   addNonElemTb );
4422   createTool( SMESHOp::OpQuadraticPyramid,       addNonElemTb );
4423   createTool( SMESHOp::OpQuadraticPentahedron,   addNonElemTb );
4424   createTool( SMESHOp::OpBiQuadraticPentahedron, addNonElemTb );
4425   createTool( SMESHOp::OpQuadraticHexahedron,    addNonElemTb );
4426   createTool( SMESHOp::OpTriQuadraticHexahedron, addNonElemTb );
4427
4428   createTool( SMESHOp::OpRemoveNodes,       remTb );
4429   createTool( SMESHOp::OpRemoveElements,    remTb );
4430   createTool( SMESHOp::OpRemoveOrphanNodes, remTb );
4431   createTool( SMESHOp::OpClearMesh,         remTb );
4432
4433   //createTool( SMESHOp::OpRenumberingNodes,    renumbTb );
4434   //createTool( SMESHOp::OpRenumberingElements, renumbTb );
4435
4436   createTool( SMESHOp::OpMergeNodes,     transformTb );
4437   createTool( SMESHOp::OpMergeElements,  transformTb );
4438   createTool( SMESHOp::OpTranslation,    transformTb );
4439   createTool( SMESHOp::OpRotation,       transformTb );
4440   createTool( SMESHOp::OpSymmetry,       transformTb );
4441   createTool( SMESHOp::OpScale,          transformTb );
4442   createTool( SMESHOp::OpOffset,         transformTb );
4443   createTool( SMESHOp::OpSewing,         transformTb );
4444   createTool( SMESHOp::OpDuplicateNodes, transformTb );
4445
4446   createTool( SMESHOp::OpConvertMeshToQuadratic, modifyTb );
4447   createTool( SMESHOp::OpCreateBoundaryElements, modifyTb );
4448   createTool( SMESHOp::OpExtrusion,              modifyTb );
4449   createTool( SMESHOp::OpExtrusionAlongAPath,    modifyTb );
4450   createTool( SMESHOp::OpRevolution,             modifyTb );
4451   createTool( SMESHOp::OpOrientation,            modifyTb );
4452   createTool( SMESHOp::OpReorientFaces,          modifyTb );
4453   createTool( SMESHOp::OpMoveNode,               modifyTb );
4454   createTool( SMESHOp::OpDiagonalInversion,      modifyTb );
4455   createTool( SMESHOp::OpUnionOfTwoTriangle,     modifyTb );
4456   createTool( SMESHOp::OpUnionOfTriangles,       modifyTb );
4457   createTool( SMESHOp::OpCuttingOfQuadrangles,   modifyTb );
4458   createTool( SMESHOp::OpSplitVolumes,           modifyTb );
4459   createTool( SMESHOp::OpSplitBiQuadratic,       modifyTb );
4460   createTool( SMESHOp::OpSmoothing,              modifyTb );
4461   createTool( SMESHOp::OpPatternMapping,         modifyTb );
4462
4463   createTool( SMESHOp::OpMinimumDistance, measuremTb );
4464
4465   createTool( SMESHOp::OpUpdate, dispModeTb );
4466
4467   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
4468   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
4469
4470   myRules.clear();
4471   QString
4472     OB      = "'ObjectBrowser'",
4473     View    = "'" + SVTK_Viewer::Type() + "'",
4474     pat     = "'%1'",
4475     mesh    = pat.arg( SMESHGUI_Selection::typeName( SMESH::MESH ) ),
4476     group   = pat.arg( SMESHGUI_Selection::typeName( SMESH::GROUP ) ),
4477     hypo    = pat.arg( SMESHGUI_Selection::typeName( SMESH::HYPOTHESIS ) ),
4478     algo    = pat.arg( SMESHGUI_Selection::typeName( SMESH::ALGORITHM ) ),
4479     smesh   = pat.arg( SMESHGUI_Selection::typeName( SMESH::COMPONENT ) ),
4480     elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
4481     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_VERTEX ) ).
4482     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_EDGE ) ).
4483     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_FACE ) ).
4484     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_SOLID ) ).
4485     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH_COMPOUND ) ).
4486     arg( SMESHGUI_Selection::typeName( SMESH::SUBMESH ) ),
4487     subMesh      = elems,
4488     mesh_part    = mesh + " " + subMesh + " " + group,
4489     mesh_group   = mesh + " " + group,
4490     mesh_submesh = mesh + " " + subMesh,
4491     hyp_alg      = hypo + " " + algo;
4492
4493   // popup for object browser
4494   QString
4495     isInvisible("not( isVisible )"),
4496     isEmpty("numberOfNodes = 0"),
4497     isNotEmpty("numberOfNodes <> 0"),
4498
4499     // has nodes, edges, etc in VISIBLE! actor
4500     hasNodes("(numberOfNodes > 0 ) && hasActor"),
4501     hasElems("(count( elemTypes ) > 0)"),
4502     hasDifferentElems("(count( elemTypes ) > 1)"),
4503     hasDifferentObjElems("(count( objElemTypes ) > 1)"),
4504     hasBalls("({'BallElem'} in elemTypes)"),
4505     hasElems0d("({'Elem0d'} in elemTypes)"),
4506     hasEdges("({'Edge'} in elemTypes)"),
4507     hasFaces("({'Face'} in elemTypes)"),
4508     hasVolumes("({'Volume'} in elemTypes)"),
4509     hasFacesOrVolumes("(({'Face'} in elemTypes) || ({'Volume'} in elemTypes)) ");
4510
4511   createPopupItem( SMESHOp::OpFileInformation,   OB, mesh, "&& selcount=1 && isImported" );
4512   createPopupItem( SMESHOp::OpCreateSubMesh,     OB, mesh, "&& hasGeomReference");
4513   createPopupItem( SMESHOp::OpEditMesh,          OB, mesh, "&& selcount=1" );
4514   createPopupItem( SMESHOp::OpEditSubMesh,       OB, subMesh, "&& selcount=1 && hasGeomReference" );
4515   createPopupItem( SMESHOp::OpEditGroup,         OB, group );
4516   createPopupItem( SMESHOp::OpEditGeomGroupAsGroup, OB, group, "&& groupType != 'Group'" );
4517
4518   popupMgr()->insert( separator(), -1, 0 );
4519   createPopupItem( SMESHOp::OpCompute,           OB, mesh, "&& selcount=1 && isComputable" );
4520   createPopupItem( SMESHOp::OpComputeSubMesh,    OB, subMesh, "&& selcount=1 && isComputable" );
4521   createPopupItem( SMESHOp::OpPreCompute,        OB, mesh, "&& selcount=1 && isPreComputable" );
4522   createPopupItem( SMESHOp::OpEvaluate,          OB, mesh, "&& selcount=1 && isComputable" );
4523   createPopupItem( SMESHOp::OpMeshOrder,         OB, mesh, "&& selcount=1 && isComputable && hasGeomReference" );
4524   createPopupItem( SMESHOp::OpUpdate,            OB, mesh_part );
4525   createPopupItem( SMESHOp::OpMeshInformation,   OB, mesh_part );
4526   createPopupItem( SMESHOp::OpFindElementByPoint,OB, mesh_group, "&& selcount=1" );
4527   createPopupItem( SMESHOp::OpOverallMeshQuality,OB, mesh_part );
4528   popupMgr()->insert( separator(), -1, 0 );
4529   createPopupItem( SMESHOp::OpCreateGroup,       OB, mesh, "&& selcount=1" );
4530   createPopupItem( SMESHOp::OpCreateGeometryGroup, OB, mesh, "&& selcount=1 && hasGeomReference" );
4531   createPopupItem( SMESHOp::OpConstructGroup,    OB, subMesh );
4532   popupMgr()->insert( separator(), -1, 0 );
4533   createPopupItem( SMESHOp::OpEditHypothesis,    OB, hypo, "&& isEditableHyp");
4534   createPopupItem( SMESHOp::OpUnassign,          OB, hyp_alg );
4535   popupMgr()->insert( separator(), -1, 0 );
4536   createPopupItem( SMESHOp::OpConvertMeshToQuadratic, OB, mesh_submesh );
4537   createPopupItem( SMESHOp::OpCreateBoundaryElements, OB, mesh_group, "&& selcount=1 && dim>=2");
4538   popupMgr()->insert( separator(), -1, 0 );
4539   createPopupItem( SMESHOp::OpClearMesh,              OB, mesh );
4540   //popupMgr()->insert( separator(), -1, 0 );
4541
4542   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
4543   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
4544   QString only_one_2D        = only_one_non_empty + " && dim>1";
4545
4546   int anId = popupMgr()->insert( tr( "MEN_EXPORT" ), -1, -1 );        // EXPORT submenu
4547   createPopupItem( SMESHOp::OpPopupExportMED,  OB, mesh_group, multiple_non_empty, anId );
4548   createPopupItem( SMESHOp::OpPopupExportUNV,  OB, mesh_group, only_one_non_empty, anId );
4549   createPopupItem( SMESHOp::OpPopupExportSTL,  OB, mesh_group, only_one_2D, anId );
4550 #ifdef WITH_CGNS
4551   createPopupItem( SMESHOp::OpPopupExportCGNS, OB, mesh_group, multiple_non_empty, anId );
4552 #endif
4553   createPopupItem( SMESHOp::OpPopupExportSAUV, OB, mesh_group, only_one_non_empty, anId );
4554   createPopupItem( SMESHOp::OpPopupExportGMF,  OB, mesh_group, only_one_non_empty, anId );
4555   createPopupItem( SMESHOp::OpPopupExportDAT,  OB, mesh_group, only_one_non_empty, anId );
4556   createPopupItem( SMESHOp::OpDelete,          OB, mesh_part + " " + hyp_alg );
4557   createPopupItem( SMESHOp::OpDeleteGroup,     OB, group );
4558
4559   anId = popupMgr()->insert( tr( "MEN_IMPORT" ), -1, -1 );        // IMPORT submenu
4560   createPopupItem( SMESHOp::OpPopupImportMED,  OB, smesh, "", anId );
4561   createPopupItem( SMESHOp::OpPopupImportUNV,  OB, smesh, "", anId );
4562   createPopupItem( SMESHOp::OpPopupImportSTL,  OB, smesh, "", anId );
4563 #ifdef WITH_CGNS
4564   createPopupItem( SMESHOp::OpPopupImportCGNS, OB, smesh, "", anId );
4565 #endif
4566   createPopupItem( SMESHOp::OpPopupImportSAUV, OB, smesh, "", anId );
4567   createPopupItem( SMESHOp::OpPopupImportGMF,  OB, smesh, "", anId );
4568   createPopupItem( SMESHOp::OpPopupImportDAT,  OB, smesh, "", anId );
4569   popupMgr()->insert( separator(), -1, 0 );
4570
4571   // popup for viewer
4572   createPopupItem( SMESHOp::OpEditGroup,            View, group );
4573   createPopupItem( SMESHOp::OpAddElemGroupPopup,    View, elems, "&& guiState = 800" );
4574   createPopupItem( SMESHOp::OpRemoveElemGroupPopup, View, elems, "&& guiState = 800" );
4575
4576   popupMgr()->insert( separator(), -1, 0 );
4577   createPopupItem( SMESHOp::OpUpdate,             View, mesh_part );
4578   createPopupItem( SMESHOp::OpMeshInformation,    View, mesh_part );
4579   createPopupItem( SMESHOp::OpOverallMeshQuality, View, mesh_part );
4580   createPopupItem( SMESHOp::OpFindElementByPoint, View, mesh );
4581   popupMgr()->insert( separator(), -1, 0 );
4582
4583   createPopupItem( SMESHOp::OpAutoColor,        OB + " " + View, mesh, "&& (not isAutoColor)" );
4584   createPopupItem( SMESHOp::OpDisableAutoColor, OB + " " + View, mesh, "&& isAutoColor" );
4585   popupMgr()->insert( separator(), -1, 0 );
4586
4587   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
4588   QString aType = QString( "%1type in {%2}" ).arg( lc );
4589   aType = aType.arg( mesh_part );
4590   QString aMeshInVTK = aClient + "&&" + aType;
4591
4592   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
4593   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
4594   QString aSelCount = QString( "%1 > 0" ).arg( dc );
4595
4596   //-------------------------------------------------
4597   // Numbering
4598   //-------------------------------------------------
4599   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
4600
4601   popupMgr()->insert( action( SMESHOp::OpNumberingNodes ), anId, -1 );
4602   popupMgr()->setRule( action( SMESHOp::OpNumberingNodes ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
4603   popupMgr()->setRule( action( SMESHOp::OpNumberingNodes ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
4604
4605   popupMgr()->insert( action( SMESHOp::OpNumberingElements ), anId, -1 );
4606   popupMgr()->setRule( action( SMESHOp::OpNumberingElements ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
4607   popupMgr()->setRule( action( SMESHOp::OpNumberingElements ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
4608
4609   popupMgr()->insert( separator(), -1, -1 );
4610
4611   //-------------------------------------------------
4612   // Display Mode
4613   //-------------------------------------------------
4614   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
4615
4616   popupMgr()->insert( action( SMESHOp::OpDMWireframe ), anId, -1 );
4617   popupMgr()->setRule( action( SMESHOp::OpDMWireframe ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4618   popupMgr()->setRule( action( SMESHOp::OpDMWireframe ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
4619
4620   popupMgr()->insert( action( SMESHOp::OpDMShading ), anId, -1 );
4621   popupMgr()->setRule( action( SMESHOp::OpDMShading ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
4622   popupMgr()->setRule( action( SMESHOp::OpDMShading ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
4623
4624   popupMgr()->insert( action( SMESHOp::OpDMNodes ), anId, -1 );
4625   popupMgr()->setRule( action( SMESHOp::OpDMNodes ), aMeshInVTK + "&&" + hasNodes + "&&" + hasElems, QtxPopupMgr::VisibleRule );
4626   popupMgr()->setRule( action( SMESHOp::OpDMNodes ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
4627
4628   popupMgr()->insert( separator(), anId, -1 );
4629
4630   popupMgr()->insert( action( SMESHOp::OpDMShrink ), anId, -1 );
4631   popupMgr()->setRule( action( SMESHOp::OpDMShrink ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
4632   popupMgr()->setRule( action( SMESHOp::OpDMShrink ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
4633
4634   //-------------------------------------------------
4635   // Display Entity
4636   //-------------------------------------------------
4637   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
4638
4639   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
4640
4641   popupMgr()->insert( action( SMESHOp::OpDE0DElements ), anId, -1 );
4642   popupMgr()->setRule( action( SMESHOp::OpDE0DElements ), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
4643   popupMgr()->setRule( action( SMESHOp::OpDE0DElements ), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
4644
4645   popupMgr()->insert( action( SMESHOp::OpDEEdges ), anId, -1 );
4646   popupMgr()->setRule( action( SMESHOp::OpDEEdges ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
4647   popupMgr()->setRule( action( SMESHOp::OpDEEdges ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
4648
4649   popupMgr()->insert( action( SMESHOp::OpDEFaces ), anId, -1 );
4650   popupMgr()->setRule( action( SMESHOp::OpDEFaces ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
4651   popupMgr()->setRule( action( SMESHOp::OpDEFaces ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
4652
4653   popupMgr()->insert( action( SMESHOp::OpDEVolumes ), anId, -1 );
4654   popupMgr()->setRule( action( SMESHOp::OpDEVolumes ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
4655   popupMgr()->setRule( action( SMESHOp::OpDEVolumes ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
4656
4657   popupMgr()->insert( action( SMESHOp::OpDEBalls ), anId, -1 );
4658   popupMgr()->setRule( action( SMESHOp::OpDEBalls ), aDiffElemsInVTK + "&& isVisible &&" + hasBalls, QtxPopupMgr::VisibleRule );
4659   popupMgr()->setRule( action( SMESHOp::OpDEBalls ), "{'BallElem'} in entityMode", QtxPopupMgr::ToggleRule );
4660
4661   popupMgr()->insert( separator(), anId, -1 );
4662
4663   popupMgr()->insert( action( SMESHOp::OpDEChoose ), anId, -1 );
4664   popupMgr()->setRule( action( SMESHOp::OpDEChoose ), aClient + "&& $type in {" + mesh + "} &&" + hasDifferentObjElems, QtxPopupMgr::VisibleRule );
4665
4666   popupMgr()->insert( separator(), anId, -1 );
4667
4668   popupMgr()->insert( action( SMESHOp::OpDEAllEntity ), anId, -1 );
4669   popupMgr()->setRule( action( SMESHOp::OpDEAllEntity ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
4670
4671
4672   //-------------------------------------------------
4673   // Representation of the 2D Quadratic elements
4674   //-------------------------------------------------
4675   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
4676   popupMgr()->insert( action( SMESHOp::OpRepresentationLines ), anId, -1 );
4677   popupMgr()->setRule( action( SMESHOp::OpRepresentationLines ), aMeshInVTK + "&& isVisible && isQuadratic",QtxPopupMgr::VisibleRule );
4678   popupMgr()->setRule( action( SMESHOp::OpRepresentationLines ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
4679
4680   popupMgr()->insert( action( SMESHOp::OpRepresentationArcs ), anId, -1 );
4681   popupMgr()->setRule( action( SMESHOp::OpRepresentationArcs ), aMeshInVTK + "&& isVisible && isQuadratic", QtxPopupMgr::VisibleRule );
4682   popupMgr()->setRule( action( SMESHOp::OpRepresentationArcs ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
4683
4684   //-------------------------------------------------
4685   // Orientation of faces
4686   //-------------------------------------------------
4687   popupMgr()->insert( action( SMESHOp::OpOrientationOnFaces ), -1, -1 );
4688   popupMgr()->setRule( action( SMESHOp::OpOrientationOnFaces ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
4689   popupMgr()->setRule( action( SMESHOp::OpOrientationOnFaces ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
4690
4691   //-------------------------------------------------
4692   // Color / Size
4693   //-------------------------------------------------
4694   popupMgr()->insert( action( SMESHOp::OpProperties ), -1, -1 );
4695   popupMgr()->setRule( action( SMESHOp::OpProperties ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4696
4697   //-------------------------------------------------
4698   // Transparency
4699   //-------------------------------------------------
4700   popupMgr()->insert( action( SMESHOp::OpTransparency ), -1, -1 );
4701   popupMgr()->setRule( action( SMESHOp::OpTransparency ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
4702
4703   //-------------------------------------------------
4704   // Controls
4705   //-------------------------------------------------
4706   QString
4707     aMeshInVtkHasNodes   = aMeshInVTK + "&&" + hasNodes,
4708     aMeshInVtkHasEdges   = aMeshInVTK + "&&" + hasEdges,
4709     aMeshInVtkHasFaces   = aMeshInVTK + "&&" + hasFaces,
4710     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
4711
4712   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
4713
4714   popupMgr()->insert( action( SMESHOp::OpReset ), anId, -1 ); // RESET
4715   popupMgr()->setRule( action( SMESHOp::OpReset ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4716
4717   popupMgr()->insert( separator(), anId, -1 );
4718
4719   int aSubId = popupMgr()->insert( tr( "MEN_NODE_CTRL" ), anId, -1 ); // NODE CONTROLS
4720
4721   popupMgr()->insert( action( SMESHOp::OpFreeNode ), aSubId, -1 );
4722   popupMgr()->setRule( action( SMESHOp::OpFreeNode ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4723   popupMgr()->setRule( action( SMESHOp::OpFreeNode ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
4724
4725   popupMgr()->insert ( action( SMESHOp::OpEqualNode ), aSubId, -1 );
4726   popupMgr()->setRule( action( SMESHOp::OpEqualNode ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4727   popupMgr()->setRule( action( SMESHOp::OpEqualNode ), "controlMode = 'eCoincidentNodes'", QtxPopupMgr::ToggleRule);
4728
4729   // popupMgr()->insert( action( SMESHOp::OpNodeConnectivityNb ), aSubId, -1 );
4730   // popupMgr()->setRule( action( SMESHOp::OpNodeConnectivityNb ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
4731   // popupMgr()->setRule( action( SMESHOp::OpNodeConnectivityNb ), "controlMode = 'eNodeConnectivityNb'", QtxPopupMgr::ToggleRule );
4732
4733   aSubId = popupMgr()->insert( tr( "MEN_EDGE_CTRL" ), anId, -1 ); // EDGE CONTROLS
4734
4735   popupMgr()->insert( action( SMESHOp::OpFreeBorder ), aSubId, -1 );
4736   popupMgr()->setRule( action( SMESHOp::OpFreeBorder ), aMeshInVTK + "&&" + hasEdges + "&&" + hasFacesOrVolumes, QtxPopupMgr::VisibleRule );
4737   popupMgr()->setRule( action( SMESHOp::OpFreeBorder ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
4738
4739   popupMgr()->insert( action( SMESHOp::OpLength ), aSubId, -1 );
4740   popupMgr()->setRule( action( SMESHOp::OpLength ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4741   popupMgr()->setRule( action( SMESHOp::OpLength ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
4742
4743   popupMgr()->insert( action( SMESHOp::OpConnection ), aSubId, -1 );
4744   popupMgr()->setRule( action( SMESHOp::OpConnection ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4745   popupMgr()->setRule( action( SMESHOp::OpConnection ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
4746   popupMgr()->insert ( action( SMESHOp::OpEqualEdge ), aSubId, -1 ); // EQUAL_EDGE
4747   popupMgr()->setRule( action( SMESHOp::OpEqualEdge ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
4748   popupMgr()->setRule( action( SMESHOp::OpEqualEdge ), "controlMode = 'eCoincidentElems1D'", QtxPopupMgr::ToggleRule);
4749
4750   aSubId = popupMgr()->insert( tr( "MEN_FACE_CTRL" ), anId, -1 ); // FACE CONTROLS
4751
4752   popupMgr()->insert( action( SMESHOp::OpFreeEdge ), aSubId, -1 );
4753   popupMgr()->setRule( action( SMESHOp::OpFreeEdge ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4754   popupMgr()->setRule( action( SMESHOp::OpFreeEdge ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
4755
4756   popupMgr()->insert ( action( SMESHOp::OpFreeFace ), aSubId, -1 );
4757   popupMgr()->setRule( action( SMESHOp::OpFreeFace ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
4758                                        QtxPopupMgr::VisibleRule );
4759   popupMgr()->setRule( action( SMESHOp::OpFreeFace ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
4760
4761   popupMgr()->insert ( action( SMESHOp::OpLength2D ), aSubId, -1 );
4762   popupMgr()->setRule( action( SMESHOp::OpLength2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4763   popupMgr()->setRule( action( SMESHOp::OpLength2D ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
4764
4765   popupMgr()->insert ( action( SMESHOp::OpConnection2D ), aSubId, -1 );
4766   popupMgr()->setRule( action( SMESHOp::OpConnection2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4767   popupMgr()->setRule( action( SMESHOp::OpConnection2D ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
4768
4769   popupMgr()->insert ( action( SMESHOp::OpArea ), aSubId, -1 );
4770   popupMgr()->setRule( action( SMESHOp::OpArea ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4771   popupMgr()->setRule( action( SMESHOp::OpArea ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
4772
4773   popupMgr()->insert ( action( SMESHOp::OpTaper ), aSubId, -1 );
4774   popupMgr()->setRule( action( SMESHOp::OpTaper ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4775   popupMgr()->setRule( action( SMESHOp::OpTaper ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
4776
4777   popupMgr()->insert ( action( SMESHOp::OpAspectRatio ), aSubId, -1 );
4778   popupMgr()->setRule( action( SMESHOp::OpAspectRatio ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4779   popupMgr()->setRule( action( SMESHOp::OpAspectRatio ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
4780
4781   popupMgr()->insert ( action( SMESHOp::OpMinimumAngle ), aSubId, -1 );
4782   popupMgr()->setRule( action( SMESHOp::OpMinimumAngle ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4783   popupMgr()->setRule( action( SMESHOp::OpMinimumAngle ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
4784
4785   popupMgr()->insert ( action( SMESHOp::OpWarpingAngle ), aSubId, -1 );
4786   popupMgr()->setRule( action( SMESHOp::OpWarpingAngle ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4787   popupMgr()->setRule( action( SMESHOp::OpWarpingAngle ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
4788
4789   popupMgr()->insert ( action( SMESHOp::OpSkew ), aSubId, -1 );
4790   popupMgr()->setRule( action( SMESHOp::OpSkew ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4791   popupMgr()->setRule( action( SMESHOp::OpSkew ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
4792
4793   popupMgr()->insert ( action( SMESHOp::OpMaxElementLength2D ), aSubId, -1 );
4794   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength2D ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4795   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength2D ), "controlMode = 'eMaxElementLength2D'", QtxPopupMgr::ToggleRule );
4796
4797   popupMgr()->insert ( action( SMESHOp::OpBareBorderFace ), aSubId, -1 );
4798   popupMgr()->setRule( action( SMESHOp::OpBareBorderFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4799   popupMgr()->setRule( action( SMESHOp::OpBareBorderFace ), "controlMode = 'eBareBorderFace'", QtxPopupMgr::ToggleRule );
4800
4801   popupMgr()->insert ( action( SMESHOp::OpOverConstrainedFace ), aSubId, -1 );
4802   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4803   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedFace ), "controlMode = 'eOverConstrainedFace'", QtxPopupMgr::ToggleRule );
4804
4805   popupMgr()->insert ( action( SMESHOp::OpEqualFace ), aSubId, -1 );
4806   popupMgr()->setRule( action( SMESHOp::OpEqualFace ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4807   popupMgr()->setRule( action( SMESHOp::OpEqualFace ), "controlMode = 'eCoincidentElems2D'", QtxPopupMgr::ToggleRule );
4808
4809   popupMgr()->insert ( action( SMESHOp::OpDeflection2D ), aSubId, -1 );
4810   popupMgr()->setRule( action( SMESHOp::OpDeflection2D ), aMeshInVtkHasFaces + " && hasGeomReference", QtxPopupMgr::VisibleRule );
4811   popupMgr()->setRule( action( SMESHOp::OpDeflection2D ), "controlMode = 'eDeflection2D'", QtxPopupMgr::ToggleRule );
4812
4813   aSubId = popupMgr()->insert( tr( "MEN_VOLUME_CTRL" ), anId, -1 ); // VOLUME CONTROLS
4814
4815   popupMgr()->insert ( action( SMESHOp::OpAspectRatio3D  ), aSubId, -1 );
4816   popupMgr()->setRule( action( SMESHOp::OpAspectRatio3D ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4817   popupMgr()->setRule( action( SMESHOp::OpAspectRatio3D ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
4818
4819   popupMgr()->insert ( action( SMESHOp::OpVolume ), aSubId, -1 );
4820   popupMgr()->setRule( action( SMESHOp::OpVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4821   popupMgr()->setRule( action( SMESHOp::OpVolume ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
4822
4823   popupMgr()->insert ( action( SMESHOp::OpMaxElementLength3D ), aSubId, -1 );
4824   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength3D ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4825   popupMgr()->setRule( action( SMESHOp::OpMaxElementLength3D ), "controlMode = 'eMaxElementLength3D'", QtxPopupMgr::ToggleRule );
4826
4827   popupMgr()->insert ( action( SMESHOp::OpBareBorderVolume ), aSubId, -1 );
4828   popupMgr()->setRule( action( SMESHOp::OpBareBorderVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4829   popupMgr()->setRule( action( SMESHOp::OpBareBorderVolume ), "controlMode = 'eBareBorderVolume'", QtxPopupMgr::ToggleRule );
4830
4831   popupMgr()->insert ( action( SMESHOp::OpOverConstrainedVolume ), aSubId, -1 );
4832   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4833   popupMgr()->setRule( action( SMESHOp::OpOverConstrainedVolume ), "controlMode = 'eOverConstrainedVolume'", QtxPopupMgr::ToggleRule );
4834
4835   popupMgr()->insert ( action( SMESHOp::OpEqualVolume  ), aSubId, -1 );
4836   popupMgr()->setRule( action( SMESHOp::OpEqualVolume ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4837   popupMgr()->setRule( action( SMESHOp::OpEqualVolume ), "controlMode = 'eCoincidentElems3D'", QtxPopupMgr::ToggleRule );
4838
4839   popupMgr()->insert( separator(), anId, -1 );
4840
4841   popupMgr()->insert( action( SMESHOp::OpShowScalarBar ), anId, -1 );
4842   popupMgr()->setRule( action( SMESHOp::OpShowScalarBar ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4843   popupMgr()->setRule( action( SMESHOp::OpShowScalarBar ), aMeshInVTK + "&& controlMode <> 'eNone' && isScalarBarVisible", QtxPopupMgr::ToggleRule );
4844   popupMgr()->insert( action( SMESHOp::OpScalarBarProperties ), anId, -1 );
4845   popupMgr()->setRule( action( SMESHOp::OpScalarBarProperties ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4846
4847   popupMgr()->insert( separator(), anId, -1 );
4848
4849   aSubId = popupMgr()->insert( tr( "MEN_DISTRIBUTION_CTRL" ), anId, -1 ); // NODE CONTROLS
4850
4851   popupMgr()->insert( action( SMESHOp::OpSaveDistribution ), aSubId, -1 );
4852   popupMgr()->setRule( action( SMESHOp::OpSaveDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4853
4854   popupMgr()->insert( action( SMESHOp::OpShowDistribution ), aSubId, -1 );
4855   popupMgr()->setRule( action( SMESHOp::OpShowDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4856   popupMgr()->setRule( action( SMESHOp::OpShowDistribution ), aMeshInVTK + "&& isNumFunctor && isScalarBarVisible && isDistributionVisible", QtxPopupMgr::ToggleRule);
4857
4858 #ifndef DISABLE_PLOT2DVIEWER
4859   popupMgr()->insert( action( SMESHOp::OpPlotDistribution ), aSubId, -1 );
4860   popupMgr()->setRule( action( SMESHOp::OpPlotDistribution ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4861 #endif
4862
4863   //-------------------------------------------------
4864   // Show / Hide
4865   //-------------------------------------------------
4866   popupMgr()->insert( separator(), -1, -1 );
4867   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
4868     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
4869   popupMgr()->insert( action( SMESHOp::OpShow ), -1, -1 );
4870   popupMgr()->setRule( action( SMESHOp::OpShow ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
4871
4872   popupMgr()->insert( action( SMESHOp::OpHide ), -1, -1 );
4873   popupMgr()->setRule( action( SMESHOp::OpHide ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
4874
4875   popupMgr()->insert( action( SMESHOp::OpShowOnly ), -1, -1 );
4876   popupMgr()->setRule( action( SMESHOp::OpShowOnly ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
4877
4878   popupMgr()->insert( separator(), -1, -1 );
4879
4880   //-------------------------------------------------
4881   // Clipping
4882   //-------------------------------------------------
4883   popupMgr()->insert( action( SMESHOp::OpClipping ), -1, -1 );
4884   popupMgr()->setRule( action( SMESHOp::OpClipping ), "client='VTKViewer'", QtxPopupMgr::VisibleRule );
4885
4886   popupMgr()->insert( separator(), -1, -1 );
4887
4888   popupMgr()->insert( action( SMESHOp::OpSortChild ), -1, -1 );
4889   popupMgr()->setRule( action( SMESHOp::OpSortChild ), "$component={'SMESH'} and client='ObjectBrowser' and isContainer and nbChildren>1", QtxPopupMgr::VisibleRule );
4890   popupMgr()->insert( separator(), -1, -1 );
4891
4892   popupMgr()->insert( action( SMESHOp::OpBreakLink), -1, -1 );
4893   popupMgr()->setRule( action( SMESHOp::OpBreakLink), "$component={'SHAPERSTUDY'} and client='ObjectBrowser' and canBreakLink", QtxPopupMgr::VisibleRule );
4894
4895   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
4896            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
4897
4898   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
4899            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
4900 }
4901
4902 //================================================================================
4903 /*!
4904  * \brief Return true if SMESH or GEOM objects are selected.
4905  * Is called form LightApp_Module::activateModule() which clear selection if
4906  * not isSelectionCompatible()
4907  */
4908 //================================================================================
4909
4910 bool SMESHGUI::isSelectionCompatible()
4911 {
4912   bool isCompatible = true;
4913   SALOME_ListIO selected;
4914   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
4915     Sel->selectedObjects( selected );
4916
4917   SALOME_ListIteratorOfListIO It( selected );
4918   for ( ; isCompatible && It.More(); It.Next())
4919     isCompatible =
4920       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
4921       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
4922
4923   return isCompatible;
4924 }
4925
4926
4927 bool SMESHGUI::reusableOperation( const int id )
4928 {
4929   // compute, evaluate and precompute are not reusable operations
4930   return ( id == SMESHOp::OpCompute || id == SMESHOp::OpPreCompute || id == SMESHOp::OpEvaluate ) ? false : SalomeApp_Module::reusableOperation( id );
4931 }
4932
4933 bool SMESHGUI::activateModule( SUIT_Study* study )
4934 {
4935   bool res = SalomeApp_Module::activateModule( study );
4936
4937   setMenuShown( true );
4938   setToolShown( true );
4939
4940   // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
4941   PyGILState_STATE gstate = PyGILState_Ensure();
4942   PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
4943   if ( !pluginsmanager ) {
4944     PyErr_Print();
4945   }
4946   else {
4947     PyObject* result = PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toUtf8().data(),tr("SMESH_PLUGINS_OTHER").toUtf8().data());
4948     if ( !result )
4949       PyErr_Print();
4950     Py_XDECREF(result);
4951   }
4952   PyGILState_Release(gstate);
4953   // end of SMESH plugins loading
4954
4955   // Reset actions accelerator keys
4956   action(SMESHOp::OpDelete)->setEnabled(true); // Delete: Key_Delete
4957
4958   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
4959   GetSMESHGen()->UpdateStudy();
4960
4961   // get all view currently opened in the study and connect their signals  to
4962   // the corresponding slots of the class.
4963   SUIT_Desktop* aDesk = study->application()->desktop();
4964   if ( aDesk ) {
4965     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
4966     SUIT_ViewWindow* wnd;
4967     foreach ( wnd, wndList )
4968       connectView( wnd );
4969   }
4970
4971   Py_XDECREF(pluginsmanager);
4972   return res;
4973 }
4974
4975 bool SMESHGUI::deactivateModule( SUIT_Study* study )
4976 {
4977   setMenuShown( false );
4978   setToolShown( false );
4979
4980   EmitSignalCloseAllDialogs();
4981
4982   // Unset actions accelerator keys
4983   action(SMESHOp::OpDelete)->setEnabled(false); // Delete: Key_Delete
4984
4985   return SalomeApp_Module::deactivateModule( study );
4986 }
4987
4988 void SMESHGUI::studyClosed( SUIT_Study* s )
4989 {
4990   if( !s )
4991     return;
4992   SMESH::RemoveVisuData();
4993   SalomeApp_Module::studyClosed( s );
4994 }
4995
4996 void SMESHGUI::OnGUIEvent()
4997 {
4998   const QObject* obj = sender();
4999   if ( !obj || !obj->inherits( "QAction" ) )
5000     return;
5001   int id = actionId((QAction*)obj);
5002   if ( id != -1 )
5003     OnGUIEvent( id );
5004 }
5005
5006 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
5007 {
5008   if ( CORBA::is_nil( myComponentSMESH ) )
5009   {
5010     SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
5011     return aGUI.myComponentSMESH;
5012   }
5013   return myComponentSMESH;
5014 }
5015
5016 QString SMESHGUI::engineIOR() const
5017 {
5018   CORBA::ORB_var anORB = getApp()->orb();
5019   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
5020   return QString( anIOR.in() );
5021 }
5022
5023 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
5024 {
5025   SalomeApp_Module::contextMenuPopup( client, menu, title );
5026   SALOME_ListIO lst;
5027   selectionMgr()->selectedObjects( lst );
5028   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
5029     Handle(SALOME_InteractiveObject) io = lst.First();
5030     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
5031     _PTR(Study) study = appStudy->studyDS();
5032     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
5033     if ( obj ) {
5034       QString aName = SMESH::fromUtf8( obj->GetName());
5035       while ( !aName.isEmpty() && aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
5036         aName.remove(( aName.length() - 1 ), 1 );
5037       title = aName;
5038     }
5039   }
5040 }
5041
5042 LightApp_Selection* SMESHGUI::createSelection() const
5043 {
5044   return new SMESHGUI_Selection();
5045 }
5046
5047 void SMESHGUI::windows( QMap<int, int>& aMap ) const
5048 {
5049   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
5050   aMap.insert( SalomeApp_Application::WT_NoteBook, Qt::LeftDockWidgetArea );
5051 #ifndef DISABLE_PYCONSOLE
5052   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
5053 #endif
5054 }
5055
5056 void SMESHGUI::viewManagers( QStringList& list ) const
5057 {
5058   list.append( SVTK_Viewer::Type() );
5059 }
5060
5061 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
5062 {
5063   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) ) {
5064     SMESH::UpdateSelectionProp( this );
5065
5066     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
5067     for(int i = 0; i < aViews.count() ; i++){
5068       SUIT_ViewWindow *sf = aViews[i];
5069       connectView( sf );
5070     }
5071     EmitSignalActivatedViewManager();
5072   }
5073 }
5074
5075 void SMESHGUI::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
5076 {
5077   if( theViewManager && theViewManager->getType() == SVTK_Viewer::Type() )
5078     myClippingPlaneInfoMap.erase( theViewManager );
5079 }
5080
5081 void SMESHGUI::addActorAsObserver( SMESH_Actor* theActor )
5082 {
5083   theActor->AddObserver( SMESH::DeleteActorEvent,
5084                          myEventCallbackCommand.GetPointer(),
5085                          myPriority );
5086 }
5087
5088 void SMESHGUI::ProcessEvents( vtkObject* theObject,
5089                               unsigned long theEvent,
5090                               void* theClientData,
5091                               void* theCallData )
5092 {
5093   if( SMESHGUI* aSMESHGUI = reinterpret_cast<SMESHGUI*>( theClientData ) ) {
5094     if( theObject && (int) theEvent == SMESH::DeleteActorEvent ) {
5095       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( theObject ) ) {
5096         SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = aSMESHGUI->getClippingPlaneInfoMap();
5097         SMESHGUI_ClippingPlaneInfoMap::iterator anIter1 = aClippingPlaneInfoMap.begin();
5098         for( ; anIter1 != aClippingPlaneInfoMap.end(); anIter1++ ) {
5099           SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
5100           SMESHGUI_ClippingPlaneInfoList::iterator anIter2 = aClippingPlaneInfoList.begin();
5101           for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
5102             SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
5103             std::list<vtkActor*>& anActorList = aClippingPlaneInfo.ActorList;
5104             SMESH::TActorList::iterator anIter3 = anActorList.begin();
5105             for ( ; anIter3 != anActorList.end(); anIter3++ ) {
5106               if( anActor == *anIter3 ) {
5107                 anActorList.erase( anIter3 );
5108                 break;
5109               }
5110             }
5111           }
5112         }
5113       }
5114     }
5115   }
5116 }
5117
5118 void SMESHGUI::createPreferences()
5119 {
5120   // General tab ------------------------------------------------------------------------
5121   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
5122
5123   int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
5124   setPreferenceProperty( autoUpdate, "columns", 2 );
5125   int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
5126   setPreferenceProperty( lim, "min",  0 );
5127   setPreferenceProperty( lim, "max",  100000000 );
5128   setPreferenceProperty( lim, "step", 1000 );
5129   setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5130   addPreference( tr( "PREF_INCREMENTAL_LIMIT" ), autoUpdate, LightApp_Preferences::Bool, "SMESH", "incremental_limit" );
5131
5132   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE_GROUP" ), genTab );
5133   setPreferenceProperty( dispgroup, "columns", 2 );
5134
5135   addPreference( tr( "PREF_FITALL_ON_DISPLAYONLY" ), dispgroup, LightApp_Preferences::Bool, "SMESH", "fitall_on_displayonly" );
5136   
5137   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
5138   QStringList modes;
5139   modes.append( tr("MEN_WIRE") );
5140   modes.append( tr("MEN_SHADE") );
5141   modes.append( tr("MEN_NODES") );
5142   modes.append( tr("MEN_SHRINK") );
5143   QList<QVariant> indices;
5144   indices.append( 0 );
5145   indices.append( 1 );
5146   indices.append( 2 );
5147   indices.append( 3 );
5148   setPreferenceProperty( dispmode, "strings", modes );
5149   setPreferenceProperty( dispmode, "indexes", indices );
5150
5151   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE_GROUP" ), genTab );
5152   setPreferenceProperty( arcgroup, "columns", 2 );
5153   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
5154   QStringList quadraticModes;
5155   quadraticModes.append(tr("MEN_LINE_REPRESENTATION"));
5156   quadraticModes.append(tr("MEN_ARC_REPRESENTATION"));
5157   indices.clear();
5158   indices.append( 0 );
5159   indices.append( 1 );
5160   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
5161   setPreferenceProperty( quadraticmode, "indexes", indices );
5162
5163   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
5164                               "SMESH", "max_angle" );
5165   setPreferenceProperty( maxAngle, "min", 1 );
5166   setPreferenceProperty( maxAngle, "max", 90 );
5167
5168   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
5169   setPreferenceProperty( qaGroup, "columns", 2 );
5170   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
5171   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
5172   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
5173   setPreferenceProperty( prec, "min", 0 );
5174   setPreferenceProperty( prec, "max", 100 );
5175   int doubleNodesTol = addPreference( tr( "PREF_EQUAL_NODES_TOL" ), qaGroup, LightApp_Preferences::DblSpin, "SMESH", "equal_nodes_tolerance" );
5176   setPreferenceProperty( doubleNodesTol, "precision", 10 );
5177   setPreferenceProperty( doubleNodesTol, "min", 0.0000000001 );
5178   setPreferenceProperty( doubleNodesTol, "max", 1000000.0 );
5179   setPreferenceProperty( doubleNodesTol, "step", 0.0000001 );
5180
5181   /*
5182   int cinc = addPreference(tr("PREF_CONTROLS_INCREMENT"), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_increment");
5183   setPreferenceProperty( cinc, "min", 0 );
5184   setPreferenceProperty( cinc, "max", 5 );
5185   */
5186
5187   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
5188   setPreferenceProperty( exportgroup, "columns", 2 );
5189   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
5190   addPreference( tr( "PREF_SHOW_WARN" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "show_warning" );
5191   int zTol = addPreference( tr( "PREF_ZTOLERANCE" ), exportgroup, LightApp_Preferences::DblSpin, "SMESH", "med_ztolerance" );
5192   setPreferenceProperty( zTol, "precision", 10 );
5193   setPreferenceProperty( zTol, "min", 0.0000000001 );
5194   setPreferenceProperty( zTol, "max", 1000000.0 );
5195   setPreferenceProperty( zTol, "step", 1. );
5196   //addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
5197
5198   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
5199   setPreferenceProperty( computeGroup, "columns", 2 );
5200   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
5201   modes.clear();
5202   modes.append( tr( "PREF_NOTIFY_NEVER" ) );
5203   modes.append( tr( "PREF_NOTIFY_ERROR" ) );
5204   modes.append( tr( "PREF_NOTIFY_ALWAYS" ) );
5205   indices.clear();
5206   indices.append( 0 );
5207   indices.append( 1 );
5208   indices.append( 2 );
5209   setPreferenceProperty( notifyMode, "strings", modes );
5210   setPreferenceProperty( notifyMode, "indexes", indices );
5211
5212   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
5213   setPreferenceProperty( infoGroup, "columns", 2 );
5214   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
5215   modes.clear();
5216   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
5217   modes.append( tr( "PREF_ELEM_INFO_TREE" ) );
5218   indices.clear();
5219   indices.append( 0 );
5220   indices.append( 1 );
5221   setPreferenceProperty( elemInfo, "strings", modes );
5222   setPreferenceProperty( elemInfo, "indexes", indices );
5223   int nodesLim = addPreference( tr( "PREF_GPP_NODES_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_groups_nodes_limit" );
5224   setPreferenceProperty( nodesLim, "min", 0 );
5225   setPreferenceProperty( nodesLim, "max", 10000000 );
5226   setPreferenceProperty( nodesLim, "step", 10000 );
5227   setPreferenceProperty( nodesLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5228   int ctrlLim = addPreference( tr( "PREF_CTRL_LIMIT" ), infoGroup, LightApp_Preferences::IntSpin, "SMESH", "info_controls_limit" );
5229   setPreferenceProperty( ctrlLim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
5230   setPreferenceProperty( ctrlLim, "min", 0 );
5231   setPreferenceProperty( ctrlLim, "max", 10000000 );
5232   setPreferenceProperty( ctrlLim, "step", 1000 );
5233   addPreference( tr( "PREF_ELEM_INFO_GRP_DETAILS" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "elem_info_grp_details" );
5234   addPreference( tr( "PREF_DUMP_BASE_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_base" );
5235   addPreference( tr( "PREF_DUMP_ELEM_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_elem" );
5236   addPreference( tr( "PREF_DUMP_ADD_INFO"  ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_add" );
5237   addPreference( tr( "PREF_DUMP_CTRL_INFO" ), infoGroup, LightApp_Preferences::Bool, "SMESH", "info_dump_ctrl" );
5238
5239   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
5240   setPreferenceProperty( segGroup, "columns", 2 );
5241   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
5242                               "SMESH", "segmentation" );
5243   setPreferenceProperty( segLen, "min", 1 );
5244   setPreferenceProperty( segLen, "max", 10000000 );
5245   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
5246                              "SMESH", "nb_segments_per_edge" );
5247   setPreferenceProperty( nbSeg, "min", 1 );
5248   setPreferenceProperty( nbSeg, "max", 10000000 );
5249
5250   int loadGroup = addPreference( tr( "SMESH_PREF_MESH_LOADING" ), genTab );
5251   addPreference( tr( "PREF_FORGET_MESH_AT_HYP_MODIF" ), loadGroup, LightApp_Preferences::Bool,
5252                  "SMESH", "forget_mesh_on_hyp_modif" );
5253
5254
5255   // Quantities with individual precision settings
5256   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
5257   setPreferenceProperty( precGroup, "columns", 2 );
5258
5259   const int nbQuantities = 6;
5260   int precs[nbQuantities], ii = 0;
5261   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
5262                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
5263   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
5264                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
5265   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
5266                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
5267   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
5268                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
5269   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
5270                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
5271   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
5272                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
5273
5274   // Set property for precision value for spinboxes
5275   for ( ii = 0; ii < nbQuantities; ii++ ){
5276     setPreferenceProperty( precs[ii], "min", -14 );
5277     setPreferenceProperty( precs[ii], "max", 14 );
5278     setPreferenceProperty( precs[ii], "precision", 2 );
5279   }
5280
5281   int previewGroup = addPreference( tr( "SMESH_PREF_GROUP_PREVIEW" ), genTab );
5282   setPreferenceProperty( previewGroup, "columns", 2 );
5283   int chunkSize = addPreference( tr( "PREF_PREVIEW_CHUNK_SIZE" ), previewGroup, LightApp_Preferences::IntSpin, "SMESH", "preview_actor_chunk_size" );
5284   setPreferenceProperty( chunkSize, "min",  1 );
5285   setPreferenceProperty( chunkSize, "max",  1000 );
5286   setPreferenceProperty( chunkSize, "step", 50 );
5287
5288   int pyDumpGroup = addPreference( tr( "PREF_PYTHON_DUMP" ), genTab );
5289   addPreference( tr( "PREF_HISTORICAL_PYTHON_DUMP" ), pyDumpGroup, LightApp_Preferences::Bool, "SMESH", "historical_python_dump" );
5290
5291   // Mesh tab ------------------------------------------------------------------------
5292   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
5293   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
5294   setPreferenceProperty( nodeGroup, "columns", 3 );
5295
5296   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
5297
5298   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
5299
5300   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5301   QList<QVariant> aMarkerTypeIndicesList;
5302   QList<QVariant> aMarkerTypeIconsList;
5303   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
5304     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
5305     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
5306     aMarkerTypeIndicesList << i;
5307     aMarkerTypeIconsList << pixmap;
5308   }
5309   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
5310   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
5311
5312   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
5313
5314   QList<QVariant> aMarkerScaleIndicesList;
5315   QStringList     aMarkerScaleValuesList;
5316   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
5317     aMarkerScaleIndicesList << i;
5318     //aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
5319     aMarkerScaleValuesList  << QString::number( i );
5320   }
5321   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
5322   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
5323
5324   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
5325   //setPreferenceProperty( elemGroup, "columns", 2 );
5326
5327   int ColorId = addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "fill_color" );
5328   setPreferenceProperty( ColorId, "text", tr("PREF_BACKFACE") );
5329   ColorId = addPreference( tr( "PREF_VOLUME" ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "volume_color" );
5330   setPreferenceProperty( ColorId, "text", tr("PREF_REVERSEDVOLUME") );
5331   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
5332   addPreference( tr( "PREF_BALL_COLOR" ), elemGroup, LightApp_Preferences::Color, "SMESH", "ball_elem_color" );
5333   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
5334   addPreference( tr( "PREF_WIREFRAME"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "wireframe_color" );
5335   addPreference( tr( "PREF_PREVIEW_COLOR"  ), elemGroup, LightApp_Preferences::BiColor, "SMESH", "preview_color" );
5336
5337
5338   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
5339   setPreferenceProperty( grpGroup, "columns", 2 );
5340
5341   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
5342   addPreference( tr( "PREF_GRP_DEF_COLOR" ), grpGroup, LightApp_Preferences::Color, "SMESH", "default_grp_color" );
5343
5344   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
5345                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
5346   /* int ballSize = addPreference(tr("PREF_BALL_SIZE"), elemGroup,
5347                              LightApp_Preferences::IntSpin, "SMESH", "ball_elem_size"); */
5348   double ballDiameter = addPreference(tr("PREF_BALL_DIAMETER"), elemGroup,
5349                              LightApp_Preferences::DblSpin, "SMESH", "ball_elem_diameter");
5350   double ballScale = addPreference(tr("PREF_BALL_SCALE"), elemGroup,
5351                              LightApp_Preferences::DblSpin, "SMESH", "ball_elem_scale");
5352   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
5353                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
5354   int outW  = addPreference(tr("PREF_OUTLINE_WIDTH"), elemGroup,
5355                              LightApp_Preferences::IntSpin, "SMESH", "outline_width");
5356   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
5357                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
5358
5359   setPreferenceProperty( size0d, "min", 1 );
5360   setPreferenceProperty( size0d, "max", 10 );
5361
5362  // setPreferenceProperty( ballSize, "min", 1 );
5363  // setPreferenceProperty( ballSize, "max", 10 );
5364
5365   setPreferenceProperty( ballDiameter, "min", 1e-7 );
5366   setPreferenceProperty( ballDiameter, "max", 1e9 );
5367   setPreferenceProperty( ballDiameter, "step", 0.1 );
5368
5369   setPreferenceProperty( ballScale, "min", 1e-2 );
5370   setPreferenceProperty( ballScale, "max", 1e7 );
5371   setPreferenceProperty( ballScale, "step", 0.5 );
5372
5373   setPreferenceProperty( elemW, "min", 1 );
5374   setPreferenceProperty( elemW, "max", 5 );
5375
5376   setPreferenceProperty( outW, "min", 1 );
5377   setPreferenceProperty( outW, "max", 5 );
5378
5379   setPreferenceProperty( shrink, "min", 0 );
5380   setPreferenceProperty( shrink, "max", 100 );
5381
5382   int numGroup = addPreference( tr( "PREF_GROUP_NUMBERING" ), meshTab );
5383   setPreferenceProperty( numGroup, "columns", 2 );
5384
5385   addPreference( tr( "PREF_NUMBERING_NODE" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_node_color" );
5386   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_node_font", true );
5387
5388   addPreference( tr( "PREF_NUMBERING_ELEM" ), numGroup, LightApp_Preferences::Color, "SMESH", "numbering_elem_color" );
5389   addVtkFontPref( tr( "PREF_NUMBERING_FONT" ), numGroup, "numbering_elem_font", true );
5390
5391   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
5392   setPreferenceProperty( orientGroup, "columns", 1 );
5393
5394   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
5395   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
5396
5397   setPreferenceProperty( orientScale, "min", 0.05 );
5398   setPreferenceProperty( orientScale, "max", 0.5 );
5399   setPreferenceProperty( orientScale, "step", 0.05 );
5400
5401   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
5402
5403   // Selection tab ------------------------------------------------------------------------
5404   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
5405
5406   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
5407   setPreferenceProperty( selGroup, "columns", 2 );
5408
5409   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
5410   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
5411
5412   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
5413   setPreferenceProperty( preGroup, "columns", 2 );
5414
5415   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
5416
5417   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
5418   setPreferenceProperty( precSelGroup, "columns", 2 );
5419
5420   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
5421   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
5422   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
5423
5424   int sinc = addPreference(tr("PREF_SELECTION_INCREMENT"), selTab, LightApp_Preferences::IntSpin, "SMESH", "selection_increment");
5425   setPreferenceProperty( sinc, "min", 0 );
5426   setPreferenceProperty( sinc, "max", 5 );
5427
5428   // Scalar Bar tab ------------------------------------------------------------------------
5429   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
5430   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
5431   setPreferenceProperty( fontGr, "columns", 2 );
5432
5433   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
5434   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
5435
5436   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
5437   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
5438
5439   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
5440   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
5441
5442   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
5443   setPreferenceProperty( numcol, "min", 2 );
5444   setPreferenceProperty( numcol, "max", 256 );
5445
5446   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
5447   setPreferenceProperty( numlab, "min", 2 );
5448   setPreferenceProperty( numlab, "max", 65 );
5449
5450   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
5451   setPreferenceProperty( orientGr, "columns", 2 );
5452   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
5453   QStringList orients;
5454   orients.append( tr( "SMESH_VERTICAL" ) );
5455   orients.append( tr( "SMESH_HORIZONTAL" ) );
5456   indices.clear(); indices.append( 0 ); indices.append( 1 );
5457   setPreferenceProperty( orient, "strings", orients );
5458   setPreferenceProperty( orient, "indexes", indices );
5459
5460   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
5461   setPreferenceProperty( posVSizeGr, "columns", 2 );
5462   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
5463   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
5464   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
5465   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
5466   setPreferenceProperty( xv, "step", 0.1 );
5467   setPreferenceProperty( xv, "min", 0.0 );
5468   setPreferenceProperty( xv, "max", 1.0 );
5469   setPreferenceProperty( yv, "step", 0.1 );
5470   setPreferenceProperty( yv, "min", 0.0 );
5471   setPreferenceProperty( yv, "max", 1.0 );
5472   setPreferenceProperty( wv, "step", 0.1 );
5473   setPreferenceProperty( wv, "min", 0.0 );
5474   setPreferenceProperty( wv, "max", 1.0 );
5475   setPreferenceProperty( hv, "min", 0.0 );
5476   setPreferenceProperty( hv, "max", 1.0 );
5477   setPreferenceProperty( hv, "step", 0.1 );
5478
5479   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
5480   setPreferenceProperty( posHSizeGr, "columns", 2 );
5481   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
5482   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
5483   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
5484   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
5485   setPreferenceProperty( xv, "min", 0.0 );
5486   setPreferenceProperty( xv, "max", 1.0 );
5487   setPreferenceProperty( xv, "step", 0.1 );
5488   setPreferenceProperty( xh, "min", 0.0 );
5489   setPreferenceProperty( xh, "max", 1.0 );
5490   setPreferenceProperty( xh, "step", 0.1 );
5491   setPreferenceProperty( yh, "min", 0.0 );
5492   setPreferenceProperty( yh, "max", 1.0 );
5493   setPreferenceProperty( yh, "step", 0.1 );
5494   setPreferenceProperty( wh, "min", 0.0 );
5495   setPreferenceProperty( wh, "max", 1.0 );
5496   setPreferenceProperty( wh, "step", 0.1 );
5497   setPreferenceProperty( hh, "min", 0.0 );
5498   setPreferenceProperty( hh, "max", 1.0 );
5499   setPreferenceProperty( hh, "step", 0.1 );
5500
5501   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
5502   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
5503   setPreferenceProperty( distributionGr, "columns", 3 );
5504   QStringList types;
5505   types.append( tr( "SMESH_MONOCOLOR" ) );
5506   types.append( tr( "SMESH_MULTICOLOR" ) );
5507   indices.clear(); indices.append( 0 ); indices.append( 1 );
5508   setPreferenceProperty( coloringType, "strings", types );
5509   setPreferenceProperty( coloringType, "indexes", indices );
5510   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
5511
5512 }
5513
5514 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
5515 {
5516   if ( sect=="SMESH" ) {
5517     float sbX1 = 0.01, sbY1 = 0.01, sbW = 0.08, sbH = 0.08;
5518     float aTol = 1.00000009999999;
5519     std::string aWarning;
5520     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
5521
5522     if ( name ==  "selection_object_color" ||
5523          name == "selection_element_color" ||
5524          name ==         "highlight_color" ||
5525          name == "selection_precision_node"    ||
5526          name == "selection_precision_element" ||
5527          name == "selection_precision_object"  ||
5528          name == "selection_increment")
5529     {
5530       SMESH::UpdateSelectionProp( this );
5531     }
5532     else if (name == "scalar_bar_vertical_x" || name == "scalar_bar_vertical_width")
5533     {
5534       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x",     sbX1);
5535       sbW  = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
5536       if ( sbX1+sbW > aTol ) {
5537         aWarning = "Origin and Size Vertical: X+Width > 1\n";
5538         sbX1 = 0.01;
5539         sbW  = 0.08;
5540         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x",     sbX1);
5541         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
5542       }
5543     }
5544     else if (name == "scalar_bar_vertical_y" || name == "scalar_bar_vertical_height" )
5545     {
5546       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y",     sbY1);
5547       sbH  = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
5548       if ( sbY1 + sbH > aTol ) {
5549         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
5550         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y",     sbY1);
5551         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
5552       }
5553     }
5554     else if (name == "scalar_bar_horizontal_x" || name ==  "scalar_bar_horizontal_width")
5555     {
5556       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x",     sbX1);
5557       sbW  = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
5558       if ( sbX1 + sbW > aTol ) {
5559         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
5560         sbX1=0.1;
5561         sbW =0.08;
5562         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
5563         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
5564       }
5565     }
5566     else if (name == "scalar_bar_horizontal_y" || name ==  "scalar_bar_horizontal_height")
5567     {
5568       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y",     sbY1);
5569       sbH  = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
5570       if ( sbY1 + sbH > aTol ) {
5571         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
5572         sbY1=0.01;
5573         sbH =0.08;
5574         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
5575         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
5576       }
5577     }
5578     else if ( name == "segmentation" )
5579     {
5580       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
5581       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
5582     }
5583     else if ( name == "nb_segments_per_edge" )
5584     {
5585       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
5586       myComponentSMESH->SetDefaultNbSegments( nbSeg );
5587     }
5588     else if ( name == "historical_python_dump" || name == "forget_mesh_on_hyp_modif" || name == "default_grp_color" )
5589     {
5590       QString val = aResourceMgr->stringValue( "SMESH", name );
5591       myComponentSMESH->SetOption( name.toLatin1().constData(), val.toLatin1().constData() );
5592     }
5593     else if ( name == "numbering_node_color" || name == "numbering_node_font" )
5594     {
5595       SMESH::UpdateFontProp( this );
5596     }
5597     else if ( name == "numbering_elem_color" || name == "numbering_elem_font" )
5598     {
5599       SMESH::UpdateFontProp( this );
5600     }
5601
5602     if ( aWarning.size() != 0 ) {
5603       aWarning += "The default values are applied instead.";
5604       SUIT_MessageBox::warning(SMESHGUI::desktop(),
5605                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
5606                                QObject::tr(aWarning.c_str()));
5607     }
5608   }
5609 }
5610
5611 //================================================================================
5612 /*!
5613  * \brief Update something in accordance with update flags
5614   * \param theFlags - update flags
5615 *
5616 * Update viewer or/and object browser etc. in accordance with update flags ( see
5617 * LightApp_UpdateFlags enumeration ).
5618 */
5619 //================================================================================
5620 void SMESHGUI::update( const int flags )
5621 {
5622   if ( (flags & UF_Viewer) | (flags & UF_Forced) )
5623     SMESH::UpdateView();
5624   else
5625     SalomeApp_Module::update( flags );
5626 }
5627
5628 //================================================================================
5629 /*!
5630  * \brief Set default selection mode
5631 *
5632 * SLOT called when operation committed. Sets default selection mode
5633 */
5634 //================================================================================
5635 void SMESHGUI::onOperationCommited( SUIT_Operation* )
5636 {
5637   SVTK_ViewWindow* vtkWnd =
5638     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5639   if ( vtkWnd )
5640     vtkWnd->SetSelectionMode( ActorSelection );
5641 }
5642
5643 //================================================================================
5644 /*!
5645  * \brief Set default selection mode
5646 *
5647 * SLOT called when operation aborted. Sets default selection mode
5648 */
5649 //================================================================================
5650 void SMESHGUI::onOperationAborted( SUIT_Operation* )
5651 {
5652   SVTK_ViewWindow* vtkWnd =
5653     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
5654   if ( vtkWnd )
5655     vtkWnd->SetSelectionMode( ActorSelection );
5656 }
5657
5658 //================================================================================
5659 /*!
5660  * \brief Creates operation with given identifier
5661   * \param id - identifier of operation to be started
5662   * \return Pointer on created operation or NULL if operation is not created
5663 *
5664 * Virtual method redefined from the base class creates operation with given id.
5665 * It is called called automatically from startOperation method of base class.
5666 */
5667 //================================================================================
5668 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
5669 {
5670   LightApp_Operation* op = 0;
5671   // to do : create operation here
5672   switch( id )
5673   {
5674     case SMESHOp::OpSplitBiQuadratic:
5675       op = new SMESHGUI_SplitBiQuadOp();
5676     break;
5677     case SMESHOp::OpConvertMeshToQuadratic:
5678       op = new SMESHGUI_ConvToQuadOp();
5679     break;
5680     case SMESHOp::OpCreateBoundaryElements: // create 2D mesh as boundary on 3D
5681       op = new SMESHGUI_Make2DFrom3DOp();
5682     break;
5683     case SMESHOp::OpReorientFaces:
5684       op = new SMESHGUI_ReorientFacesOp();
5685       break;
5686     case SMESHOp::OpCreateMesh:
5687       op = new SMESHGUI_MeshOp( true, true );
5688     break;
5689     case SMESHOp::OpCreateSubMesh:
5690       op = new SMESHGUI_MeshOp( true, false );
5691     break;
5692     case SMESHOp::OpEditMeshOrSubMesh:
5693     case SMESHOp::OpEditMesh:
5694     case SMESHOp::OpEditSubMesh:
5695       op = new SMESHGUI_MeshOp( false );
5696     break;
5697     case SMESHOp::OpCompute:
5698     case SMESHOp::OpComputeSubMesh:
5699       op = new SMESHGUI_ComputeOp();
5700     break;
5701     case SMESHOp::OpPreCompute:
5702       op = new SMESHGUI_PrecomputeOp();
5703     break;
5704     case SMESHOp::OpEvaluate:
5705       op = new SMESHGUI_EvaluateOp();
5706     break;
5707     case SMESHOp::OpMeshOrder:
5708       op = new SMESHGUI_MeshOrderOp();
5709     break;
5710     case SMESHOp::OpCreateGeometryGroup:
5711       op = new SMESHGUI_GroupOnShapeOp();
5712       break;
5713     case SMESHOp::OpFindElementByPoint:
5714       op = new SMESHGUI_FindElemByPointOp();
5715       break;
5716     case SMESHOp::OpMoveNode: // Make mesh pass through point
5717       op = new SMESHGUI_MakeNodeAtPointOp();
5718       break;
5719     case SMESHOp::OpElem0DOnElemNodes: // Create 0D elements on all nodes
5720       op = new SMESHGUI_Add0DElemsOnAllNodesOp();
5721       break;
5722     default:
5723     break;
5724   }
5725
5726   if( !op )
5727     op = SalomeApp_Module::createOperation( id );
5728   return op;
5729 }
5730
5731 //================================================================================
5732 /*!
5733  * \brief Stops current operations and starts a given one
5734   * \param id - The id of the operation to start
5735  */
5736 //================================================================================
5737
5738 void SMESHGUI::switchToOperation(int id)
5739 {
5740   activeStudy()->abortAllOperations();
5741   startOperation( id );
5742 }
5743
5744 LightApp_Displayer* SMESHGUI::displayer()
5745 {
5746   if( !myDisplayer )
5747     myDisplayer = new SMESHGUI_Displayer( getApp() );
5748   return myDisplayer;
5749 }
5750
5751 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
5752 {
5753   int aHue = -1;
5754   int aTolerance = 64;
5755   int anIterations = 0;
5756   int aPeriod = 5;
5757
5758   while( 1 )
5759   {
5760     anIterations++;
5761     if( anIterations % aPeriod == 0 )
5762     {
5763       aTolerance /= 2;
5764       if( aTolerance < 1 )
5765         break;
5766     }
5767
5768     aHue = (int)( 360.0 * rand() / RAND_MAX );
5769
5770     bool ok = true;
5771     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
5772     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
5773     for( ; it != itEnd; ++it )
5774     {
5775       SALOMEDS::Color anAutoColor = *it;
5776       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
5777
5778       int h, s, v;
5779       aQColor.getHsv( &h, &s, &v );
5780       if( abs( h - aHue ) < aTolerance )
5781       {
5782         ok = false;
5783         break;
5784       }
5785     }
5786
5787     if( ok )
5788       break;
5789   }
5790
5791   QColor aColor;
5792   aColor.setHsv( aHue, 255, 255 );
5793
5794   SALOMEDS::Color aSColor;
5795   aSColor.R = aColor.redF();
5796   aSColor.G = aColor.greenF();
5797   aSColor.B = aColor.blueF();
5798
5799   return aSColor;
5800 }
5801
5802 const char* gSeparator = "_"; // character used to separate parameter names
5803 const char* gDigitsSep = ":"; // character used to separate numeric parameter values (color = r:g:b)
5804 const char* gPathSep   = "|"; // character used to separate paths
5805
5806 /*!
5807  * \brief Store visual parameters
5808  *
5809  * This method is called just before the study document is saved.
5810  * Store visual parameters in AttributeParameter attribute(s)
5811  */
5812 void SMESHGUI::storeVisualParameters (int savePoint)
5813 {
5814   // localizing
5815   Kernel_Utils::Localizer loc;
5816
5817   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5818   if (!appStudy || !appStudy->studyDS())
5819     return;
5820   _PTR(Study) studyDS = appStudy->studyDS();
5821
5822   // componentName is used for encoding of entries when storing them in IParameters
5823   std::string componentName = myComponentSMESH->ComponentDataType();
5824   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
5825   //if (!aSComponent) return;
5826
5827   // IParameters
5828   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5829                                                              componentName.c_str(),
5830                                                              savePoint);
5831   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5832
5833   // store custom markers
5834   if( !myMarkerMap.empty() )
5835   {
5836     VTK::MarkerMap::const_iterator anIter = myMarkerMap.begin();
5837     for( ; anIter != myMarkerMap.end(); anIter++ )
5838     {
5839       int anId = anIter->first;
5840       VTK::MarkerData aMarkerData = anIter->second;
5841       std::string aMarkerFileName = aMarkerData.first;
5842       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
5843       if( aMarkerTexture.size() < 3 )
5844         continue; // should contain at least width, height and the first value
5845
5846       QString aPropertyName( "texture" );
5847       aPropertyName += gSeparator;
5848       aPropertyName += QString::number( anId );
5849
5850       QString aPropertyValue = aMarkerFileName.c_str();
5851       aPropertyValue += gPathSep;
5852
5853       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
5854       ushort aWidth = *aTextureIter++;
5855       ushort aHeight = *aTextureIter++;
5856       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
5857       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
5858       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
5859         aPropertyValue += QString::number( *aTextureIter );
5860
5861       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5862     }
5863   }
5864
5865   // viewers counters are used for storing view_numbers in IParameters
5866   int vtkViewers = 0;
5867
5868   // main cycle to store parameters of displayed objects
5869   QList<SUIT_ViewManager*> lst;
5870   QList<SUIT_ViewManager*>::Iterator it;
5871   getApp()->viewManagers(lst);
5872   for (it = lst.begin(); it != lst.end(); it++)
5873   {
5874     SUIT_ViewManager* vman = *it;
5875     QString vType = vman->getType();
5876
5877     // saving VTK actors properties
5878     if (vType == SVTK_Viewer::Type())
5879     {
5880       // store the clipping planes attached to the view manager
5881       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
5882       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
5883       if( anIter != myClippingPlaneInfoMap.end() )
5884         aClippingPlaneInfoList = anIter->second;
5885
5886       if( !aClippingPlaneInfoList.empty() ) {
5887         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
5888         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
5889         {
5890           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
5891           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
5892
5893           QString aPropertyName( "ClippingPlane" );
5894           aPropertyName += gSeparator;
5895           aPropertyName += QString::number( vtkViewers );
5896           aPropertyName += gSeparator;
5897           aPropertyName += QString::number( anId );
5898
5899           QString aPropertyValue = QString::number( (int)aPlane->PlaneMode ).toLatin1().constData();
5900           aPropertyValue += gDigitsSep;
5901           aPropertyValue += QString::number( aPlane->IsOpenGLClipping ).toLatin1().constData();
5902           aPropertyValue += gDigitsSep;
5903           if ( aPlane->PlaneMode == SMESH::Absolute ) {
5904             aPropertyValue += QString::number( aPlane->myAbsoluteOrientation ).toLatin1().constData();
5905             aPropertyValue += gDigitsSep;
5906             aPropertyValue += QString::number( aPlane->X ).toLatin1().constData();
5907             aPropertyValue += gDigitsSep;
5908             aPropertyValue += QString::number( aPlane->Y ).toLatin1().constData();
5909             aPropertyValue += gDigitsSep;
5910             aPropertyValue += QString::number( aPlane->Z ).toLatin1().constData();
5911             aPropertyValue += gDigitsSep;
5912             aPropertyValue += QString::number( aPlane->Dx ).toLatin1().constData();
5913             aPropertyValue += gDigitsSep;
5914             aPropertyValue += QString::number( aPlane->Dy ).toLatin1().constData();
5915             aPropertyValue += gDigitsSep;
5916             aPropertyValue += QString::number( aPlane->Dz ).toLatin1().constData();
5917           }
5918           else if ( aPlane->PlaneMode == SMESH::Relative ) {
5919             aPropertyValue += QString::number( (int)aPlane->myRelativeOrientation ).toLatin1().constData();
5920             aPropertyValue += gDigitsSep;
5921             aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
5922             aPropertyValue += gDigitsSep;
5923             aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
5924             aPropertyValue += gDigitsSep;
5925             aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
5926           }
5927
5928           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
5929         }
5930       }
5931
5932       QVector<SUIT_ViewWindow*> views = vman->getViews();
5933       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
5934       {
5935         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
5936         {
5937           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
5938           vtkActorCollection* allActors = aCopy.GetActors();
5939           allActors->InitTraversal();
5940           while (vtkActor* actor = allActors->GetNextActor())
5941           {
5942             if (actor->GetVisibility()) // store only visible actors
5943             {
5944               SMESH_Actor* aSmeshActor = 0;
5945               if (actor->IsA("SMESH_Actor"))
5946                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
5947               if (aSmeshActor && aSmeshActor->hasIO())
5948               {
5949                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
5950                 if (io->hasEntry())
5951                 {
5952                   // entry is "encoded" = it does NOT contain component address,
5953                   // since it is a subject to change on next component loading
5954                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
5955
5956                   std::string param, vtkParam = vType.toLatin1().data();
5957                   vtkParam += gSeparator;
5958                   vtkParam += QString::number(vtkViewers).toLatin1().data();
5959                   vtkParam += gSeparator;
5960
5961                   // Visibility
5962                   param = vtkParam + "Visibility";
5963                   ip->setParameter(entry, param, "On");
5964
5965                   // Representation
5966                   param = vtkParam + "Representation";
5967                   ip->setParameter(entry, param, QString::number
5968                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
5969
5970                   // IsShrunk
5971                   param = vtkParam + "IsShrunk";
5972                   ip->setParameter(entry, param, QString::number
5973                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
5974
5975                   // Displayed entities
5976                   unsigned int aMode = aSmeshActor->GetEntityMode();
5977                   bool isE  = aMode & SMESH_Actor::eEdges;
5978                   bool isF  = aMode & SMESH_Actor::eFaces;
5979                   bool isV  = aMode & SMESH_Actor::eVolumes;
5980                   bool is0d = aMode & SMESH_Actor::e0DElements;
5981                   bool isB  = aMode & SMESH_Actor::eBallElem;
5982
5983                   QString modeStr ("e");
5984                   modeStr += gDigitsSep; modeStr += QString::number(isE);
5985                   modeStr += gDigitsSep; modeStr += "f";
5986                   modeStr += gDigitsSep; modeStr += QString::number(isF);
5987                   modeStr += gDigitsSep; modeStr += "v";
5988                   modeStr += gDigitsSep; modeStr += QString::number(isV);
5989                   modeStr += gDigitsSep; modeStr += "0d";
5990                   modeStr += gDigitsSep; modeStr += QString::number(is0d);
5991                   modeStr += gDigitsSep; modeStr += "b";
5992                   modeStr += gDigitsSep; modeStr += QString::number(isB);
5993
5994                   param = vtkParam + "Entities";
5995                   ip->setParameter(entry, param, modeStr.toLatin1().data());
5996
5997                   // Colors
5998                   double r, g, b;
5999                   int delta;
6000
6001                   aSmeshActor->GetSufaceColor(r, g, b, delta);
6002                   QStringList colorStr;
6003                   colorStr << "surface";
6004                   colorStr << QString::number(r);
6005                   colorStr << QString::number(g);
6006                   colorStr << QString::number(b);
6007
6008                   colorStr << "backsurface";
6009                   colorStr << QString::number(delta);
6010
6011                   aSmeshActor->GetVolumeColor(r, g, b, delta);
6012                   colorStr << "volume";
6013                   colorStr << QString::number(r);
6014                   colorStr << QString::number(g);
6015                   colorStr << QString::number(b);
6016                   colorStr << QString::number(delta);
6017
6018                   aSmeshActor->GetEdgeColor(r, g, b);
6019                   colorStr << "edge";
6020                   colorStr << QString::number(r);
6021                   colorStr << QString::number(g);
6022                   colorStr << QString::number(b);
6023
6024                   aSmeshActor->GetNodeColor(r, g, b);
6025                   colorStr << "node";
6026                   colorStr << QString::number(r);
6027                   colorStr << QString::number(g);
6028                   colorStr << QString::number(b);
6029
6030                   aSmeshActor->GetOutlineColor(r, g, b);
6031                   colorStr << "outline";
6032                   colorStr << QString::number(r);
6033                   colorStr << QString::number(g);
6034                   colorStr << QString::number(b);
6035
6036                   aSmeshActor->Get0DColor(r, g, b);
6037                   colorStr << "elem0d";
6038                   colorStr << QString::number(r);
6039                   colorStr << QString::number(g);
6040                   colorStr << QString::number(b);
6041
6042                   aSmeshActor->GetBallColor(r, g, b);
6043                   colorStr << "ball";
6044                   colorStr << QString::number(r);
6045                   colorStr << QString::number(g);
6046                   colorStr << QString::number(b);
6047
6048                   aSmeshActor->GetFacesOrientationColor(r, g, b);
6049                   colorStr << "orientation";
6050                   colorStr << QString::number(r);
6051                   colorStr << QString::number(g);
6052                   colorStr << QString::number(b);
6053
6054                   param = vtkParam + "Colors";
6055                   ip->setParameter(entry, param, qPrintable(colorStr.join(gDigitsSep)));
6056
6057                   // Sizes
6058                   QStringList sizeStr;
6059                   sizeStr << "line";
6060                   sizeStr << QString::number((int)aSmeshActor->GetLineWidth());
6061                   sizeStr << "outline";
6062                   sizeStr << QString::number((int)aSmeshActor->GetOutlineWidth());
6063                   sizeStr << "elem0d";
6064                   sizeStr << QString::number((int)aSmeshActor->Get0DSize());
6065                   sizeStr << "ball";
6066                   //sizeStr << QString::number((int)aSmeshActor->GetBallSize());
6067                   sizeStr << QString::number((double)aSmeshActor->GetBallSize());
6068                   sizeStr << QString::number((double)aSmeshActor->GetBallScale());
6069                   sizeStr << "shrink";
6070                   sizeStr << QString::number(aSmeshActor->GetShrinkFactor());
6071                   sizeStr << "orientation";
6072                   sizeStr << QString::number(aSmeshActor->GetFacesOrientationScale());
6073                   sizeStr << QString::number(aSmeshActor->GetFacesOrientation3DVectors());
6074
6075                   param = vtkParam + "Sizes";
6076                   ip->setParameter(entry, param, qPrintable(sizeStr.join(gDigitsSep)));
6077
6078                   // Point marker
6079                   QString markerStr;
6080
6081                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
6082                   if( aMarkerType == VTK::MT_USER ) {
6083                     markerStr += "custom";
6084                     markerStr += gDigitsSep;
6085                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
6086                   }
6087                   else {
6088                     markerStr += "std";
6089                     markerStr += gDigitsSep;
6090                     markerStr += QString::number( (int)aMarkerType );
6091                     markerStr += gDigitsSep;
6092                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
6093                   }
6094
6095                   param = vtkParam + "PointMarker";
6096                   ip->setParameter(entry, param, markerStr.toLatin1().data());
6097
6098                   // Opacity
6099                   param = vtkParam + "Opacity";
6100                   ip->setParameter(entry, param,
6101                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
6102
6103                   // Clipping
6104                   param = vtkParam + "ClippingPlane";
6105                   int aPlaneId = 0;
6106                   if( !aClippingPlaneInfoList.empty() ) {
6107                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
6108                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
6109                     {
6110                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
6111                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
6112                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
6113                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
6114                         if( aSmeshActor == *anIter2 ) {
6115                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
6116                                             QString::number( anId ).toLatin1().constData() );
6117                           break;
6118                         }
6119                       }
6120                     }
6121                   }
6122                   if( aPlaneId == 0 )
6123                     ip->setParameter( entry, param, "Off" );
6124                 } // if (io->hasEntry())
6125               } // SMESH_Actor && hasIO
6126             } // isVisible
6127           } // while.. actors traversal
6128         } // if (vtkView)
6129       } // for (views)
6130       vtkViewers++;
6131     } // if (SVTK view model)
6132   } // for (viewManagers)
6133 }
6134
6135 // data structures for clipping planes processing
6136 typedef struct {
6137   int Id;
6138   int Mode;
6139   bool isOpenGLClipping;
6140   vtkIdType RelativeOrientation;
6141   double Distance;
6142   double Angle[2];
6143   int AbsoluteOrientation;
6144   double X, Y, Z, Dx, Dy, Dz;
6145 } TPlaneData;
6146 typedef std::list<TPlaneData>         TPlaneDataList;
6147 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
6148
6149 typedef std::list<vtkActor*>          TActorList;
6150 typedef struct {
6151   int PlaneId;
6152   TActorList ActorList;
6153   SUIT_ViewManager* ViewManager;
6154 } TPlaneInfo;
6155 typedef std::list<TPlaneInfo>         TPlaneInfoList;
6156 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
6157
6158 /*!
6159  * \brief Restore visual parameters
6160  *
6161  * This method is called after the study document is opened.
6162  * Restore visual parameters from AttributeParameter attribute(s)
6163  */
6164 void SMESHGUI::restoreVisualParameters (int savePoint)
6165 {
6166   // localizing
6167   Kernel_Utils::Localizer loc;
6168
6169   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
6170   if (!appStudy || !appStudy->studyDS())
6171     return;
6172   _PTR(Study) studyDS = appStudy->studyDS();
6173
6174   // componentName is used for encoding of entries when storing them in IParameters
6175   std::string componentName = myComponentSMESH->ComponentDataType();
6176   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
6177   //if (!aSComponent) return;
6178
6179   // IParameters
6180   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
6181                                                              componentName.c_str(),
6182                                                              savePoint);
6183   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
6184
6185   // restore custom markers and map of clipping planes
6186   TPlaneDataMap aPlaneDataMap;
6187
6188   std::vector<std::string> properties = ip->getProperties();
6189   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
6190   {
6191     std::string property = *propIt;
6192     QString aPropertyName( property.c_str() );
6193     QString aPropertyValue( ip->getProperty( property ).c_str() );
6194
6195     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
6196     if( aPropertyNameList.isEmpty() )
6197       continue;
6198
6199     QString aPropertyType = aPropertyNameList[0];
6200     if( aPropertyType == "texture" )
6201     {
6202       if( aPropertyNameList.size() != 2 )
6203         continue;
6204
6205       bool ok = false;
6206       int anId = aPropertyNameList[1].toInt( &ok );
6207       if( !ok || anId < 1 )
6208         continue;
6209
6210       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
6211       if( aPropertyValueList.size() != 2 )
6212         continue;
6213
6214       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
6215       QString aMarkerTextureString = aPropertyValueList[1];
6216       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
6217       if( aMarkerTextureStringList.size() != 3 )
6218         continue;
6219
6220       ok = false;
6221       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
6222       if( !ok )
6223         continue;
6224
6225       ok = false;
6226       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
6227       if( !ok )
6228         continue;
6229
6230       VTK::MarkerTexture aMarkerTexture;
6231       aMarkerTexture.push_back( aWidth );
6232       aMarkerTexture.push_back( aHeight );
6233
6234       QString aMarkerTextureData = aMarkerTextureStringList[2];
6235       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
6236       {
6237         QChar aChar = aMarkerTextureData.at( i );
6238         if( aChar.isDigit() )
6239           aMarkerTexture.push_back( aChar.digitValue() );
6240       }
6241
6242       myMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
6243     }
6244     else if( aPropertyType == "ClippingPlane" )
6245     {
6246       if( aPropertyNameList.size() != 3 )
6247         continue;
6248
6249       bool ok = false;
6250       int aViewId = aPropertyNameList[1].toInt( &ok );
6251       if( !ok || aViewId < 0 )
6252         continue;
6253
6254       ok = false;
6255       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
6256       if( !ok || aClippingPlaneId < 0 )
6257         continue;
6258
6259       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
6260       if( aPropertyValueList.size() != 6 && aPropertyValueList.size() != 9 )
6261         continue;
6262
6263       TPlaneData aPlaneData;
6264       aPlaneData.AbsoluteOrientation = false;
6265       aPlaneData.RelativeOrientation = 0;
6266       aPlaneData.Distance = aPlaneData.Angle[0] = aPlaneData.Angle[1] = 0;
6267       aPlaneData.X = aPlaneData.Y = aPlaneData.Z = 0;
6268       aPlaneData.Dx = aPlaneData.Dy = aPlaneData.Dz = 0;
6269
6270       aPlaneData.Id = aClippingPlaneId;
6271
6272       ok = false;
6273       aPlaneData.Mode = aPropertyValueList[0].toInt( &ok );
6274       if( !ok )
6275         continue;
6276
6277       ok = false;
6278       aPlaneData.isOpenGLClipping = aPropertyValueList[1].toInt( &ok );
6279       if( !ok )
6280         continue;
6281
6282       if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Absolute )
6283       {
6284         ok = false;
6285         aPlaneData.AbsoluteOrientation = aPropertyValueList[2].toInt( &ok );
6286         if( !ok )
6287           continue;
6288
6289         ok = false;
6290         aPlaneData.X = aPropertyValueList[3].toDouble( &ok );
6291         if( !ok )
6292           continue;
6293
6294         ok = false;
6295         aPlaneData.Y = aPropertyValueList[4].toDouble( &ok );
6296         if( !ok )
6297           continue;
6298
6299         ok = false;
6300         aPlaneData.Z = aPropertyValueList[5].toDouble( &ok );
6301         if( !ok )
6302           continue;
6303
6304         ok = false;
6305         aPlaneData.Dx = aPropertyValueList[6].toDouble( &ok );
6306         if( !ok )
6307           continue;
6308
6309         ok = false;
6310         aPlaneData.Dy = aPropertyValueList[7].toDouble( &ok );
6311         if( !ok )
6312           continue;
6313
6314         ok = false;
6315         aPlaneData.Dz = aPropertyValueList[8].toDouble( &ok );
6316         if( !ok )
6317           continue;
6318       }
6319       else if ( (SMESH::Mode)aPlaneData.Mode == SMESH::Relative ) {
6320         ok = false;
6321         aPlaneData.RelativeOrientation = aPropertyValueList[2].toInt( &ok );
6322         if( !ok )
6323           continue;
6324
6325         ok = false;
6326         aPlaneData.Distance = aPropertyValueList[3].toDouble( &ok );
6327         if( !ok )
6328           continue;
6329
6330         ok = false;
6331         aPlaneData.Angle[0] = aPropertyValueList[4].toDouble( &ok );
6332         if( !ok )
6333           continue;
6334
6335         ok = false;
6336         aPlaneData.Angle[1] = aPropertyValueList[5].toDouble( &ok );
6337         if( !ok )
6338           continue;
6339       }
6340
6341       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
6342       aPlaneDataList.push_back( aPlaneData );
6343     }
6344   }
6345
6346   TPlaneInfoMap aPlaneInfoMap;
6347
6348   std::vector<std::string> entries = ip->getEntries();
6349
6350   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
6351   {
6352     // entry is a normal entry - it should be "decoded" (setting base address of component)
6353     QString entry (ip->decodeEntry(*entIt).c_str());
6354
6355     // Check that the entry corresponds to a real object in the Study
6356     // as the object may be deleted or modified after the visual state is saved.
6357     _PTR(SObject) so = studyDS->FindObjectID(entry.toUtf8().data());
6358     if (!so) continue; //Skip the not existent entry
6359
6360     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
6361     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
6362
6363     std::vector<std::string>::iterator namesIt = paramNames.begin();
6364     std::vector<std::string>::iterator valuesIt = paramValues.begin();
6365
6366     // actors are stored in a map after displaying of them for
6367     // quicker access in the future: map < viewID to actor >
6368     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
6369
6370     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
6371     {
6372       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
6373       // '_' is used as separator and should not be used in viewer type or parameter names.
6374       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
6375       if (lst.size() != 3)
6376         continue;
6377
6378       QString viewerTypStr = lst[0];
6379       QString viewIndexStr = lst[1];
6380       QString paramNameStr = lst[2];
6381
6382       bool ok;
6383       int viewIndex = viewIndexStr.toUInt(&ok);
6384       if (!ok) // bad conversion of view index to integer
6385         continue;
6386
6387       // viewers
6388       if (viewerTypStr == SVTK_Viewer::Type())
6389       {
6390         SMESH_Actor* aSmeshActor = 0;
6391         if (vtkActors.IsBound(viewIndex))
6392           aSmeshActor = vtkActors.Find(viewIndex);
6393
6394         QList<SUIT_ViewManager*> lst;
6395         getApp()->viewManagers(viewerTypStr, lst);
6396
6397         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
6398         SUIT_ViewManager* vman = NULL;
6399         if (viewIndex >= 0 && viewIndex < lst.count())
6400           vman = lst.at(viewIndex);
6401
6402         if (paramNameStr == "Visibility")
6403         {
6404           if (!aSmeshActor && displayer() && vman)
6405           {
6406             SUIT_ViewModel* vmodel = vman->getViewModel();
6407             // SVTK view model can be casted to SALOME_View
6408             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
6409
6410             // store displayed actor in a temporary map for quicker
6411             // access later when restoring other parameters
6412             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
6413             vtkRenderer* Renderer = vtkView->getRenderer();
6414             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
6415             vtkActorCollection* theActors = aCopy.GetActors();
6416             theActors->InitTraversal();
6417             bool isFound = false;
6418             vtkActor *ac = theActors->GetNextActor();
6419             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
6420               if (ac->IsA("SMESH_Actor")) {
6421                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
6422                 if (aGeomAc->hasIO()) {
6423                   Handle(SALOME_InteractiveObject) io = aGeomAc->getIO();
6424                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toUtf8().data()) == 0) {
6425                     isFound = true;
6426                     vtkActors.Bind(viewIndex, aGeomAc);
6427                   }
6428                 }
6429               }
6430             }
6431           }
6432         } // if (paramNameStr == "Visibility")
6433         else
6434         {
6435           // the rest properties "work" with SMESH_Actor
6436           if (aSmeshActor)
6437           {
6438             QString val ((*valuesIt).c_str());
6439
6440             // Representation
6441             if (paramNameStr == "Representation") {
6442               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
6443             }
6444             // IsShrunk
6445             else if (paramNameStr == "IsShrunk") {
6446               if (val.toInt()) {
6447                 if (!aSmeshActor->IsShrunk())
6448                   aSmeshActor->SetShrink();
6449               }
6450               else {
6451                 if (aSmeshActor->IsShrunk())
6452                   aSmeshActor->UnShrink();
6453               }
6454             }
6455             // Displayed entities
6456             else if (paramNameStr == "Entities") {
6457               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
6458               int aEntityMode = SMESH_Actor::eAllEntity;
6459               for ( int i = 0; i < mode.count(); i+=2 ) {
6460                 if ( i < mode.count()-1 ) {
6461                   QString type = mode[i];
6462                   bool val = mode[i+1].toInt();
6463                   if      ( type == "e" && !val )
6464                     aEntityMode = aEntityMode & ~SMESH_Actor::eEdges;
6465                   else if ( type == "f" && !val )
6466                     aEntityMode = aEntityMode & ~SMESH_Actor::eFaces;
6467                   else if ( type == "v" && !val )
6468                     aEntityMode = aEntityMode & ~SMESH_Actor::eVolumes;
6469                   else if ( type == "0d" && !val )
6470                     aEntityMode = aEntityMode & ~SMESH_Actor::e0DElements;
6471                   else if ( type == "b" && !val )
6472                     aEntityMode = aEntityMode & ~SMESH_Actor::eBallElem;
6473                 }
6474               }
6475               aSmeshActor->SetEntityMode( aEntityMode );
6476             }
6477             // Colors
6478             else if (paramNameStr == "Colors") {
6479               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
6480               QColor nodeColor;
6481               QColor edgeColor;
6482               QColor faceColor;
6483               QColor volumeColor;
6484               QColor elem0dColor;
6485               QColor ballColor;
6486               QColor outlineColor;
6487               QColor orientationColor;
6488               int deltaF;
6489               int deltaV;
6490               QColor c;
6491               double r, g, b;
6492               bool bOk;
6493               // below lines are required to get default values for delta coefficients
6494               // of backface color for faces and color of reversed volumes
6495               SMESH::GetColor( "SMESH", "fill_color",   c, deltaF, "0,170,255|-100" );
6496               SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
6497               for ( int i = 0; i < colors.count(); i++ ) {
6498                 QString type = colors[i];
6499                 if ( type == "surface" ) {
6500                   // face color is set by 3 values r:g:b, where
6501                   // - r,g,b - is rgb color components
6502                   if ( i+1 >= colors.count() ) break;                  // format error
6503                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6504                   if ( i+2 >= colors.count() ) break;                  // format error
6505                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6506                   if ( i+3 >= colors.count() ) break;                  // format error
6507                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6508                   faceColor.setRgbF( r, g, b );
6509                   i += 3;
6510                 }
6511                 else if ( type == "backsurface" ) {
6512                   // backface color can be defined in several ways
6513                   // - in old versions, it is set as rgb triple r:g:b - this was is unsupported now
6514                   // - in latest versions, it is set as delta coefficient
6515                   bool rgbOk = false, deltaOk;
6516                   if ( i+1 >= colors.count() ) break;                  // format error
6517                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6518                   int delta = colors[i+1].toInt( &deltaOk );
6519                   i++;                                 // shift index
6520                   if ( i+1 < colors.count() )          // index is shifted to 1
6521                     g = colors[i+1].toDouble( &rgbOk );
6522                   if ( rgbOk ) i++;                    // shift index
6523                   if ( rgbOk && i+1 < colors.count() ) // index is shifted to 2
6524                     b = colors[i+1].toDouble( &rgbOk );
6525                   if ( rgbOk ) i++;
6526                   // - as currently there's no way to set directly backsurface color as it was before,
6527                   // we ignore old dump where r,g,b triple was set
6528                   // - also we check that delta parameter is set properly
6529                   if ( !rgbOk && deltaOk )
6530                     deltaF = delta;
6531                 }
6532                 else if ( type == "volume" ) {
6533                   // volume color is set by 4 values r:g:b:delta, where
6534                   // - r,g,b - is a normal volume rgb color components
6535                   // - delta - is a reversed volume color delta coefficient
6536                   if ( i+1 >= colors.count() ) break;                  // format error
6537                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6538                   if ( i+2 >= colors.count() ) break;                  // format error
6539                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6540                   if ( i+3 >= colors.count() ) break;                  // format error
6541                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6542                   if ( i+4 >= colors.count() ) break;                  // format error
6543                   int delta = colors[i+4].toInt( &bOk );
6544                   if ( !bOk ) break;                                   // format error
6545                   volumeColor.setRgbF( r, g, b );
6546                   deltaV = delta;
6547                   i += 4;
6548                 }
6549                 else if ( type == "edge" ) {
6550                   // edge color is set by 3 values r:g:b, where
6551                   // - r,g,b - is rgb color components
6552                   if ( i+1 >= colors.count() ) break;                  // format error
6553                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6554                   if ( i+2 >= colors.count() ) break;                  // format error
6555                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6556                   if ( i+3 >= colors.count() ) break;                  // format error
6557                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6558                   edgeColor.setRgbF( r, g, b );
6559                   i += 3;
6560                 }
6561                 else if ( type == "node" ) {
6562                   // node color is set by 3 values r:g:b, where
6563                   // - r,g,b - is rgb color components
6564                   if ( i+1 >= colors.count() ) break;                  // format error
6565                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6566                   if ( i+2 >= colors.count() ) break;                  // format error
6567                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6568                   if ( i+3 >= colors.count() ) break;                  // format error
6569                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6570                   nodeColor.setRgbF( r, g, b );
6571                   i += 3;
6572                 }
6573                 else if ( type == "elem0d" ) {
6574                   // 0d element color is set by 3 values r:g:b, where
6575                   // - r,g,b - is rgb color components
6576                   if ( i+1 >= colors.count() ) break;                  // format error
6577                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6578                   if ( i+2 >= colors.count() ) break;                  // format error
6579                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6580                   if ( i+3 >= colors.count() ) break;                  // format error
6581                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6582                   elem0dColor.setRgbF( r, g, b );
6583                   i += 3;
6584                 }
6585                 else if ( type == "ball" ) {
6586                   // ball color is set by 3 values r:g:b, where
6587                   // - r,g,b - is rgb color components
6588                   if ( i+1 >= colors.count() ) break;                  // format error
6589                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6590                   if ( i+2 >= colors.count() ) break;                  // format error
6591                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6592                   if ( i+3 >= colors.count() ) break;                  // format error
6593                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6594                   ballColor.setRgbF( r, g, b );
6595                   i += 3;
6596                 }
6597                 else if ( type == "outline" ) {
6598                   // outline color is set by 3 values r:g:b, where
6599                   // - r,g,b - is rgb color components
6600                   if ( i+1 >= colors.count() ) break;                  // format error
6601                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6602                   if ( i+2 >= colors.count() ) break;                  // format error
6603                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6604                   if ( i+3 >= colors.count() ) break;                  // format error
6605                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6606                   outlineColor.setRgbF( r, g, b );
6607                   i += 3;
6608                 }
6609                 else if ( type == "orientation" ) {
6610                   // orientation color is set by 3 values r:g:b, where
6611                   // - r,g,b - is rgb color components
6612                   if ( i+1 >= colors.count() ) break;                  // format error
6613                   r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6614                   if ( i+2 >= colors.count() ) break;                  // format error
6615                   g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6616                   if ( i+3 >= colors.count() ) break;                  // format error
6617                   b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
6618                   orientationColor.setRgbF( r, g, b );
6619                   i += 3;
6620                 }
6621               }
6622               // node color
6623               if ( nodeColor.isValid() )
6624                 aSmeshActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
6625               // edge color
6626               if ( edgeColor.isValid() )
6627                 aSmeshActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
6628               // face color
6629               if ( faceColor.isValid() )
6630                 aSmeshActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6631               // volume color
6632               if ( volumeColor.isValid() )
6633                 aSmeshActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
6634               else if ( faceColor.isValid() ) // backward compatibility (no separate color for volumes)
6635                 aSmeshActor->SetVolumeColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
6636               // 0d element color
6637               if ( elem0dColor.isValid() )
6638                 aSmeshActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
6639               // ball color
6640               if ( ballColor.isValid() )
6641                 aSmeshActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
6642               // outline color
6643               if ( outlineColor.isValid() )
6644                 aSmeshActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
6645               // orientation color
6646               if ( orientationColor.isValid() )
6647                 aSmeshActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
6648             }
6649             // Sizes
6650             else if (paramNameStr == "Sizes") {
6651               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
6652               bool bOk;
6653               int lineWidth = -1;
6654               int outlineWidth = -1;
6655               int elem0dSize = -1;
6656               //int ballSize = -1;
6657               double ballDiameter = -1.0;
6658               double ballScale = -1.0;
6659               double shrinkSize = -1;
6660               double orientationSize = -1;
6661               bool orientation3d = false;
6662               for ( int i = 0; i < sizes.count(); i++ ) {
6663                 QString type = sizes[i];
6664                 if ( type == "line" ) {
6665                   // line (wireframe) width is given as single integer value
6666                   if ( i+1 >= sizes.count() ) break;                    // format error
6667                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6668                   lineWidth = v;
6669                   i++;
6670                 }
6671                 if ( type == "outline" ) {
6672                   // outline width is given as single integer value
6673                   if ( i+1 >= sizes.count() ) break;                    // format error
6674                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6675                   outlineWidth = v;
6676                   i++;
6677                 }
6678                 else if ( type == "elem0d" ) {
6679                   // 0d element size is given as single integer value
6680                   if ( i+1 >= sizes.count() ) break;                    // format error
6681                   int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;  // format error
6682                   elem0dSize = v;
6683                   i++;
6684                 }
6685                 else if ( type == "ball" ) {
6686                   // balls are specified by two values: size:scale, where
6687                   // - size - is a integer value specifying size
6688                   // - scale - is a double value specifying scale factor
6689                   if ( i+1 >= sizes.count() ) break;                       // format error
6690                   //int v1 = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;    // format error
6691                   double v1 = sizes[i+1].toInt( &bOk ); if ( !bOk ) break;    // format error
6692                   if ( i+2 >= sizes.count() ) break;                       // format error
6693                   double v2 = sizes[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
6694                   //ballSize = v1;
6695                   ballDiameter = v1;
6696                   ballScale = v2;
6697                   i += 2;
6698                 }
6699                 else if ( type == "shrink" ) {
6700                   // shrink factor is given as single floating point value
6701                   if ( i+1 >= sizes.count() ) break;                          // format error
6702                   double v = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break;  // format error
6703                   shrinkSize = v;
6704                   i++;
6705                 }
6706                 else if ( type == "orientation" ) {
6707                   // orientation vectors are specified by two values size:3d, where
6708                   // - size - is a floating point value specifying scale factor
6709                   // - 3d - is a boolean
6710                   if ( i+1 >= sizes.count() ) break;                          // format error
6711                   double v1 = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
6712                   if ( i+2 >= sizes.count() ) break;                          // format error
6713                   int v2 = sizes[i+2].toInt( &bOk ); if ( !bOk ) break;       // format error
6714                   orientationSize = v1;
6715                   orientation3d = (bool)v2;
6716                   i += 2;
6717                 }
6718               }
6719               // line (wireframe) width
6720               if ( lineWidth > 0 )
6721                 aSmeshActor->SetLineWidth( lineWidth );
6722               // outline width
6723               if ( outlineWidth > 0 )
6724                 aSmeshActor->SetOutlineWidth( outlineWidth );
6725               else if ( lineWidth > 0 ) // backward compatibility (no separate width for outlines)
6726                 aSmeshActor->SetOutlineWidth( lineWidth );
6727               // 0d element size
6728               if ( elem0dSize > 0 )
6729                 aSmeshActor->Set0DSize( elem0dSize );
6730               // ball size
6731               /*if ( ballSize > 0 )
6732                 aSmeshActor->SetBallSize( ballSize );*/
6733               // ball diameter
6734               if ( ballDiameter > 0 )
6735                 aSmeshActor->SetBallSize( ballDiameter );
6736               // ball scale
6737               if ( ballScale > 0.0 )
6738                 aSmeshActor->SetBallScale( ballScale );
6739               // shrink factor
6740               if ( shrinkSize > 0 )
6741                 aSmeshActor->SetShrinkFactor( shrinkSize );
6742               // orientation vectors
6743               if ( orientationSize > 0 ) {
6744                 aSmeshActor->SetFacesOrientationScale( orientationSize );
6745                 aSmeshActor->SetFacesOrientation3DVectors( orientation3d );
6746               }
6747             }
6748             // Point marker
6749             else if (paramNameStr == "PointMarker") {
6750               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
6751               if( data.count() >= 2 ) {
6752                 bool ok = false;
6753                 int aParam1 = data[1].toInt( &ok );
6754                 if( ok ) {
6755                   if( data[0] == "std" && data.count() == 3 ) {
6756                     int aParam2 = data[2].toInt( &ok );
6757                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
6758                   }
6759                   else if( data[0] == "custom" ) {
6760                     VTK::MarkerMap::const_iterator markerIt = myMarkerMap.find( aParam1 );
6761                     if( markerIt != myMarkerMap.end() ) {
6762                       VTK::MarkerData aMarkerData = markerIt->second;
6763                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
6764                     }
6765                   }
6766                 }
6767               }
6768             }
6769             // Opacity
6770             else if (paramNameStr == "Opacity") {
6771               aSmeshActor->SetOpacity(val.toFloat());
6772             }
6773             // Clipping
6774             else if (paramNameStr.startsWith("ClippingPlane")) {
6775               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
6776               // old format - val looks like "Off" or "1:0:0:0.5:0:0"
6777               // (mode(relative), is OpenGL clipping plane, orientation, distance, two angles)
6778               // or "0:1:1:10.5:1.0:1.0:15.0:10.0:10.0"
6779               // (mode(absolute), is OpenGL clipping plane, orientation, base point(x, y, z), direction (dx, dy, dz))
6780               // new format - val looks like "Off" or "0" (plane id)
6781               // (note: in new format "Off" value is used only for consistency,
6782               //  so it is processed together with values in old format)
6783               bool anIsOldFormat = ( vals.count() == 6 || vals.count() == 9 || val == "Off" );
6784               if( anIsOldFormat ) {
6785                 if (paramNameStr == "ClippingPlane1" || val == "Off")
6786                   aSmeshActor->RemoveAllClippingPlanes();
6787                 if (val != "Off") {
6788                   QList<SUIT_ViewManager*> lst;
6789                   getApp()->viewManagers(viewerTypStr, lst);
6790                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
6791                   if (viewIndex >= 0 && viewIndex < lst.count()) {
6792                     SUIT_ViewManager* vman = lst.at(viewIndex);
6793                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
6794
6795                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
6796
6797                     SMESH::TActorList anActorList;
6798                     anActorList.push_back( aSmeshActor );
6799                     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( vtkView );
6800                     aPlane->myViewWindow = vtkView;
6801                     SMESH::Mode aMode = ( SMESH::Mode )vals[0].toInt();
6802                     aPlane->PlaneMode = aMode;
6803                     bool isOpenGLClipping = ( bool )vals[1].toInt();
6804                     aPlane->IsOpenGLClipping = isOpenGLClipping;
6805                     if ( aMode == SMESH::Absolute ) {
6806                       aPlane->myAbsoluteOrientation = vals[2].toInt();
6807                       aPlane->X = vals[3].toFloat();
6808                       aPlane->Y = vals[4].toFloat();
6809                       aPlane->Z = vals[5].toFloat();
6810                       aPlane->Dx = vals[6].toFloat();
6811                       aPlane->Dy = vals[7].toFloat();
6812                       aPlane->Dz = vals[8].toFloat();
6813                     }
6814                     else if ( aMode == SMESH::Relative ) {
6815                       aPlane->myRelativeOrientation = (SMESH::Orientation)vals[2].toInt();
6816                       aPlane->myDistance = vals[3].toFloat();
6817                       aPlane->myAngle[0] = vals[4].toFloat();
6818                       aPlane->myAngle[1] = vals[5].toFloat();
6819                     }
6820
6821                     if( aPlane ) {
6822                       if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
6823                         SMESH::ClippingPlaneInfo aClippingPlaneInfo;
6824                         aClippingPlaneInfo.Plane = aPlane;
6825                         aClippingPlaneInfo.ActorList = anActorList;
6826                         aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
6827                       }
6828                     }
6829                   }
6830                 }
6831               }
6832               else {
6833                 bool ok = false;
6834                 int aPlaneId = val.toInt( &ok );
6835                 if( ok && aPlaneId >= 0 ) {
6836                   bool anIsDefinedPlane = false;
6837                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
6838                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
6839                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
6840                     TPlaneInfo& aPlaneInfo = *anIter;
6841                     if( aPlaneInfo.PlaneId == aPlaneId ) {
6842                       aPlaneInfo.ActorList.push_back( aSmeshActor );
6843                       anIsDefinedPlane = true;
6844                       break;
6845                     }
6846                   }
6847                   if( !anIsDefinedPlane ) {
6848                     TPlaneInfo aPlaneInfo;
6849                     aPlaneInfo.PlaneId = aPlaneId;
6850                     aPlaneInfo.ActorList.push_back( aSmeshActor );
6851                     aPlaneInfo.ViewManager = vman;
6852
6853                     // to make the list sorted by plane id
6854                     anIter = aPlaneInfoList.begin();
6855                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
6856                       const TPlaneInfo& aPlaneInfoRef = *anIter;
6857                       if( aPlaneInfoRef.PlaneId > aPlaneId )
6858                         break;
6859                     }
6860                     aPlaneInfoList.insert( anIter, aPlaneInfo );
6861                   }
6862                 }
6863               }
6864             }
6865           } // if (aSmeshActor)
6866         } // other parameters than Visibility
6867       }
6868     } // for names/parameters iterator
6869   } // for entries iterator
6870
6871   // take into account planes with empty list of actors referred to them
6872   QList<SUIT_ViewManager*> aVMList;
6873   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
6874
6875   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
6876   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
6877     int aViewId = aPlaneDataIter->first;
6878     if( aViewId >= 0 && aViewId < aVMList.count() ) {
6879       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
6880
6881       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
6882
6883       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
6884       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
6885       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
6886         const TPlaneData& aPlaneData = *anIter2;
6887         int aPlaneId = aPlaneData.Id;
6888
6889         bool anIsFound = false;
6890         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
6891         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
6892           const TPlaneInfo& aPlaneInfo = *anIter3;
6893           if( aPlaneInfo.PlaneId == aPlaneId ) {
6894             anIsFound = true;
6895             break;
6896           }
6897         }
6898
6899         if( !anIsFound ) {
6900           TPlaneInfo aPlaneInfo; // ActorList field is empty
6901           aPlaneInfo.PlaneId = aPlaneId;
6902           aPlaneInfo.ViewManager = aViewManager;
6903
6904           // to make the list sorted by plane id
6905           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
6906           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
6907             const TPlaneInfo& aPlaneInfoRef = *anIter4;
6908             if( aPlaneInfoRef.PlaneId > aPlaneId )
6909               break;
6910           }
6911           aPlaneInfoList.insert( anIter4, aPlaneInfo );
6912         }
6913       }
6914     }
6915   }
6916
6917   // add clipping planes to actors according to the restored parameters
6918   // and update the clipping plane map
6919   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
6920   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
6921     int aViewId = anIter1->first;
6922     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
6923
6924     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
6925     if( anIter2 == aPlaneDataMap.end() )
6926       continue;
6927     const TPlaneDataList& aPlaneDataList = anIter2->second;
6928
6929     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
6930     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
6931       const TPlaneInfo& aPlaneInfo = *anIter3;
6932       int aPlaneId = aPlaneInfo.PlaneId;
6933       const TActorList& anActorList = aPlaneInfo.ActorList;
6934       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
6935       if( !aViewManager )
6936         continue;
6937
6938       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
6939       if( !aViewWindow )
6940         continue;
6941
6942       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
6943
6944       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
6945       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
6946         const TPlaneData& aPlaneData = *anIter4;
6947         if( aPlaneData.Id == aPlaneId ) {
6948           SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New( aViewWindow );
6949           aPlane->myViewWindow = aViewWindow;
6950           aPlane->PlaneMode = (SMESH::Mode)aPlaneData.Mode;
6951           aPlane->IsOpenGLClipping = aPlaneData.isOpenGLClipping;
6952           if ( aPlane->PlaneMode == SMESH::Absolute ) {
6953             aPlane->myAbsoluteOrientation = aPlaneData.AbsoluteOrientation;
6954             aPlane->X = aPlaneData.X;
6955             aPlane->Y = aPlaneData.Y;
6956             aPlane->Z = aPlaneData.Z;
6957             aPlane->Dx = aPlaneData.Dx;
6958             aPlane->Dy = aPlaneData.Dy;
6959             aPlane->Dz = aPlaneData.Dz;
6960           }
6961           else if ( aPlane->PlaneMode == SMESH::Relative ) {
6962             aPlane->myRelativeOrientation = (SMESH::Orientation)aPlaneData.RelativeOrientation;
6963             aPlane->myDistance = aPlaneData.Distance;
6964             aPlane->myAngle[0] = aPlaneData.Angle[0];
6965             aPlane->myAngle[1] = aPlaneData.Angle[1];
6966           }
6967           if( aPlane ) {
6968             if ( SMESHGUI_ClippingDlg::AddPlane( anActorList, aPlane ) ) {
6969               SMESH::ClippingPlaneInfo aClippingPlaneInfo;
6970               aClippingPlaneInfo.Plane = aPlane;
6971               aClippingPlaneInfo.ActorList = anActorList;
6972               aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
6973             }
6974           }
6975           break;
6976         }
6977       }
6978
6979     }
6980   }
6981
6982
6983   // update all VTK views
6984   QList<SUIT_ViewManager*> lst;
6985   getApp()->viewManagers(lst);
6986   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
6987     SUIT_ViewModel* vmodel = (*it)->getViewModel();
6988     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
6989       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
6990       // set OpenGL clipping planes
6991       VTK::ActorCollectionCopy aCopy( vtkView->getRenderer()->GetActors() );
6992       vtkActorCollection* anAllActors = aCopy.GetActors();
6993       anAllActors->InitTraversal();
6994       while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
6995         if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
6996           anActor->SetOpenGLClippingPlane();
6997
6998       vtkView->getRenderer()->ResetCameraClippingRange();
6999       vtkView->Repaint();
7000     }
7001   }
7002 }
7003
7004 /*!
7005   \brief Adds preferences for dfont of VTK viewer
7006   \param label label
7007   \param pIf group identifier
7008   \param param parameter
7009   \return identifier of preferences
7010 */
7011 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param, const bool needSize )
7012 {
7013   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
7014
7015   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
7016
7017   QStringList fam;
7018   fam.append( tr( "SMESH_FONT_ARIAL" ) );
7019   fam.append( tr( "SMESH_FONT_COURIER" ) );
7020   fam.append( tr( "SMESH_FONT_TIMES" ) );
7021
7022   setPreferenceProperty( tfont, "fonts", fam );
7023
7024   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
7025   if ( needSize ) f = f | QtxFontEdit::Size;
7026   setPreferenceProperty( tfont, "features", f );
7027
7028   return tfont;
7029 }
7030
7031 /*!
7032   \brief Actions after hypothesis edition
7033   Updates object browser after hypothesis edition
7034 */
7035 void SMESHGUI::onHypothesisEdit( int result )
7036 {
7037   if( result == 1 )
7038     SMESHGUI::Modified();
7039   updateObjBrowser( true );
7040 }
7041
7042 /*!
7043   \brief Actions after choosing menu of control modes
7044   Updates control mode actions according to current selection
7045 */
7046 void SMESHGUI::onUpdateControlActions()
7047 {
7048   SALOME_ListIO selected;
7049   if ( LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr() )
7050     aSel->selectedObjects( selected );
7051
7052   SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
7053   if ( selected.Extent() ) {
7054     if ( selected.First()->hasEntry() ) {
7055       if ( SMESH_Actor* anActor = SMESH::FindActorByEntry( selected.First()->getEntry() )) {
7056         aControl = anActor->GetControlMode();
7057         SALOME_ListIteratorOfListIO it(selected);
7058         for ( it.Next(); it.More(); it.Next() ) {
7059           Handle(SALOME_InteractiveObject) anIO = it.Value();
7060           if ( anIO->hasEntry() ) {
7061             if ( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
7062               if ( aControl != anActor->GetControlMode() ) {
7063                 aControl = SMESH_Actor::eNone;
7064                 break;
7065               }
7066             }
7067           }
7068         }
7069       }
7070     }
7071   }
7072
7073   int anAction = ActionToControl( aControl, true );
7074   if ( anAction)
7075     action( anAction )->setChecked( true );
7076   else {
7077     QMenu* send = (QMenu*)sender();
7078     QList<QAction*> actions = send->actions();
7079     for ( int i = 0; i < actions.size(); i++ )
7080       actions[i]->setChecked( false );
7081   }
7082 }
7083
7084
7085 /*!
7086   \brief Signal handler closing(SUIT_ViewWindow*) of a view
7087   \param pview view being closed
7088 */
7089 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
7090 #ifndef DISABLE_PLOT2DVIEWER
7091   //Crear all Plot2d Viewers if need.
7092   SMESH::ClearPlot2Viewers(pview);
7093 #endif
7094   EmitSignalCloseView();
7095 }
7096
7097 void SMESHGUI::message( const QString& msg )
7098 {
7099   // dispatch message
7100   QStringList data = msg.split("/");
7101   if ( data.count() > 0 ) {
7102     if ( data.first() == "mesh_loading" ) {
7103       // get mesh entry
7104       QString entry = data.count() > 1 ? data[1] : QString();
7105       if ( entry.isEmpty() )
7106         return;
7107       // get study
7108       _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() )->studyDS();
7109       // get mesh name
7110       _PTR(SObject) obj = study->FindObjectID( entry.toUtf8().constData() );
7111       QString name;
7112       if ( obj )
7113         name = SMESH::fromUtf8(obj->GetName());
7114       if ( name.isEmpty() )
7115         return;
7116
7117       if ( data.last() == "stop" )
7118         application()->putInfo( tr( "MESH_LOADING_MSG_FINISHED" ).arg( name ) );
7119       else
7120         application()->putInfo( tr( "MESH_LOADING_MSG" ).arg( name ) );
7121       QApplication::processEvents();
7122     }
7123   }
7124 }
7125
7126 /*!
7127   \brief Connects or disconnects signals about activating and cloning view on the module slots
7128   \param pview view which is connected/disconnected
7129 */
7130 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
7131   if(!pview)
7132     return;
7133
7134   SUIT_ViewManager* viewMgr = pview->getViewManager();
7135   if ( viewMgr ) {
7136     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
7137                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
7138
7139     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
7140              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
7141   }
7142 }
7143
7144 /*!
7145   \brief Return \c true if object can be renamed
7146 */
7147 bool SMESHGUI::renameAllowed( const QString& entry) const {
7148   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
7149   if( !anApp )
7150     return false;
7151
7152   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
7153   if( !appStudy )
7154     return false;
7155
7156   SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry));
7157
7158   if(!obj)
7159     return false;
7160
7161   if(appStudy->isComponent(entry) || obj->isReference())
7162     return false;
7163
7164   // check type to prevent renaming of inappropriate objects
7165   int aType = SMESHGUI_Selection::type(qPrintable(entry));
7166   if (aType == SMESH::MESH || aType == SMESH::GROUP ||
7167       aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
7168       aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
7169       aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
7170       aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM)
7171     return true;
7172
7173   return false;
7174 }
7175
7176 /*!
7177   Rename object by entry.
7178   \param entry entry of the object
7179   \param name new name of the object
7180   \brief Return \c true if rename operation finished successfully, \c false otherwise.
7181 */
7182 bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
7183
7184   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
7185   if( !anApp )
7186     return false;
7187
7188   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
7189
7190   if(!appStudy)
7191     return false;
7192
7193   _PTR(Study) aStudy = appStudy->studyDS();
7194
7195   if(!aStudy)
7196     return false;
7197
7198   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
7199   if ( aLocked ) {
7200     SUIT_MessageBox::warning ( anApp->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
7201     return false;
7202   }
7203
7204
7205   _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
7206   _PTR(GenericAttribute) anAttr;
7207   _PTR(AttributeName) aName;
7208   if ( obj ) {
7209     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
7210       aName = anAttr;
7211       // check type to prevent renaming of inappropriate objects
7212       int aType = SMESHGUI_Selection::type( qPrintable(entry));
7213       if (aType == SMESH::MESH || aType == SMESH::GROUP ||
7214           aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
7215           aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
7216           aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
7217           aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM) {
7218         if ( !name.isEmpty() ) {
7219           SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qUtf8Printable(name) );
7220
7221           // update name of group object and its actor
7222           Handle(SALOME_InteractiveObject) IObject =
7223             new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
7224
7225           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
7226           if( !aGroupObject->_is_nil() ) {
7227             aGroupObject->SetName( qUtf8Printable(name) );
7228             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
7229               anActor->setName( qUtf8Printable(name) );
7230           }
7231           return true;
7232         }
7233       }
7234     }
7235   }
7236   return false;
7237 }
7238
7239 SALOMEDS::Color SMESHGUI::getPredefinedUniqueColor()
7240 {
7241   static QList<QColor> colors;
7242
7243   if ( colors.isEmpty() ) {
7244
7245     for (int s = 0; s < 2 ; s++)
7246     {
7247       for (int v = 100; v >= 40; v = v - 20)
7248       {
7249         for (int h = 0; h < 359 ; h = h + 60)
7250         {
7251           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
7252         }
7253       }
7254     }
7255   }
7256   static int currentColor = randomize( colors.size() );
7257
7258   SALOMEDS::Color color;
7259   color.R = (double)colors[currentColor].red()   / 255.0;
7260   color.G = (double)colors[currentColor].green() / 255.0;
7261   color.B = (double)colors[currentColor].blue()  / 255.0;
7262
7263   currentColor = (currentColor+1) % colors.count();
7264
7265   return color;
7266 }