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