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