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