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