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