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