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