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