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