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