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