Salome HOME
0021130: EDF 1746 SMESH: Issue with export in STL format
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 //  Copyright (C) 2007-2010  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.
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 //  SMESH SMESHGUI : GUI for SMESH component
23 //  File   : SMESHGUI.cxx
24 //  Author : Nicolas REJNERI, Open CASCADE S.A.S.
25
26 #include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
27 #include "Python.h"
28 //  SMESH includes
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_AddMeshElementDlg.h"
31 #include "SMESHGUI_AddQuadraticElementDlg.h"
32 #include "SMESHGUI_BuildCompoundDlg.h"
33 #include "SMESHGUI_ClippingDlg.h"
34 #include "SMESHGUI_ComputeDlg.h"
35 #include "SMESHGUI_ConvToQuadOp.h"
36 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
37 #include "SMESHGUI_DeleteGroupDlg.h"
38 #include "SMESHGUI_Displayer.h"
39 #include "SMESHGUI_MergeDlg.h"
40 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
41 #include "SMESHGUI_ExtrusionDlg.h"
42 #include "SMESHGUI_FileInfoDlg.h"
43 #include "SMESHGUI_FileValidator.h"
44 #include "SMESHGUI_FilterDlg.h"
45 #include "SMESHGUI_FilterLibraryDlg.h"
46 #include "SMESHGUI_FindElemByPointDlg.h"
47 #include "SMESHGUI_GroupDlg.h"
48 #include "SMESHGUI_GroupOnShapeDlg.h"
49 #include "SMESHGUI_GroupOpDlg.h"
50 #include "SMESHGUI_Hypotheses.h"
51 #include "SMESHGUI_Make2DFrom3DOp.h"
52 #include "SMESHGUI_MakeNodeAtPointDlg.h"
53 //#include "SMESHGUI_MeshInfosDlg.h"
54 #include "SMESHGUI_Measurements.h"
55 #include "SMESHGUI_MeshInfo.h"
56 #include "SMESHGUI_MeshOp.h"
57 #include "SMESHGUI_MeshOrderOp.h"
58 #include "SMESHGUI_MeshPatternDlg.h"
59 #include "SMESHGUI_MultiEditDlg.h"
60 #include "SMESHGUI_NodesDlg.h"
61 #include "SMESHGUI_Preferences_ColorDlg.h"
62 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
63 #include "SMESHGUI_RemoveElementsDlg.h"
64 #include "SMESHGUI_RemoveNodesDlg.h"
65 #include "SMESHGUI_RenumberingDlg.h"
66 #include "SMESHGUI_RevolutionDlg.h"
67 #include "SMESHGUI_RotationDlg.h"
68 #include "SMESHGUI_Selection.h"
69 #include "SMESHGUI_SewingDlg.h"
70 #include "SMESHGUI_SingleEditDlg.h"
71 #include "SMESHGUI_SmoothingDlg.h"
72 //#include "SMESHGUI_StandardMeshInfosDlg.h"
73 #include "SMESHGUI_SymmetryDlg.h"
74 #include "SMESHGUI_TranslationDlg.h"
75 #include "SMESHGUI_ScaleDlg.h"
76 #include "SMESHGUI_TransparencyDlg.h"
77 //#include "SMESHGUI_WhatIsDlg.h"
78 #include "SMESHGUI_DuplicateNodesDlg.h"
79 #include "SMESHGUI_CopyMeshDlg.h"
80
81 #include "SMESHGUI_Utils.h"
82 #include "SMESHGUI_MeshUtils.h"
83 #include "SMESHGUI_GroupUtils.h"
84 #include "SMESHGUI_FilterUtils.h"
85 #include "SMESHGUI_PatternUtils.h"
86 #include "SMESHGUI_VTKUtils.h"
87 #include "SMESHGUI_HypothesesUtils.h"
88
89 #include <SMESH_Client.hxx>
90 #include <SMESH_Actor.h>
91 #include <SMESH_ScalarBarActor.h>
92 #include <SMESH_ActorUtils.h>
93 #include <SMESH_TypeFilter.hxx>
94 #include "SMESH_ControlsDef.hxx"
95
96 // SALOME GUI includes
97 #include <SalomeApp_Tools.h>
98 #include <SalomeApp_Study.h>
99 #include <SalomeApp_Application.h>
100 #include <SalomeApp_CheckFileDlg.h>
101
102 #include <LightApp_DataOwner.h>
103 #include <LightApp_Preferences.h>
104 #include <LightApp_SelectionMgr.h>
105 #include <LightApp_UpdateFlags.h>
106 #include <LightApp_NameDlg.h>
107
108 #include <SVTK_ViewWindow.h>
109 #include <SVTK_ViewModel.h>
110 #include <SVTK_ViewManager.h>
111
112 #include <VTKViewer_Algorithm.h>
113
114 #include <SUIT_MessageBox.h>
115 #include <SUIT_ResourceMgr.h>
116 #include <SUIT_FileDlg.h>
117 #include <SUIT_Desktop.h>
118 #include <SUIT_OverrideCursor.h>
119 #include <SUIT_Session.h>
120
121 #include <QtxPopupMgr.h>
122 #include <QtxFontEdit.h>
123
124 #include <SALOME_ListIO.hxx>
125 #include <SALOME_ListIteratorOfListIO.hxx>
126
127 #ifndef DISABLE_PLOT2DVIEWER
128 #include <SPlot2d_ViewModel.h>
129 #include <SPlot2d_Histogram.h>
130 #endif
131
132 // IDL includes
133 #include <SALOMEconfig.h>
134 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
135 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
136 #include CORBA_CLIENT_HEADER(SMESH_Measurements)
137
138 // Qt includes
139 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
140 #include <QMenu>
141 #include <QTextStream>
142
143 // BOOST includes
144 #include <boost/shared_ptr.hpp>
145
146 // VTK includes
147 #include <vtkCamera.h>
148 #include <vtkRenderer.h>
149 #include <vtkPlane.h>
150 #include <vtkCallbackCommand.h>
151 #include <vtkLookupTable.h>
152
153 // SALOME KERNEL includes
154 #include <SALOMEDS_Study.hxx>
155 #include <SALOMEDSClient_StudyBuilder.hxx>
156 #include <SALOMEDSClient_SComponent.hxx>
157 #include <SALOMEDSClient_ClientFactory.hxx>
158 #include <SALOMEDSClient_IParameters.hxx>
159
160 // OCCT includes
161 #include <Standard_ErrorHandler.hxx>
162 #include <NCollection_DataMap.hxx>
163
164 //To disable automatic genericobj management, the following line should be commented.
165 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
166 #define WITHGENERICOBJ
167
168 //namespace{
169   // Declarations
170   //=============================================================
171   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
172                             int theCommandID);
173
174   void ExportMeshToFile(int theCommandID);
175
176   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap);
177
178   void SetDisplayEntity(int theCommandID);
179
180   void Control( int theCommandID );
181
182
183   // Definitions
184   //=============================================================
185   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
186                              int theCommandID )
187   {
188     QStringList filter;
189     std::string myExtension;
190
191     if ( theCommandID == 113 ) {
192       filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.med)" );
193       filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
194     }
195     else if ( theCommandID == 112 ) {
196       filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
197     }
198     else if ( theCommandID == 111 ) {
199       filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
200     }
201     else if ( theCommandID == 140 ) {
202       filter.append( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
203     }
204
205     QString anInitialPath = "";
206     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
207       anInitialPath = QDir::currentPath();
208
209     QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
210                                                             anInitialPath,
211                                                             filter,
212                                                             QObject::tr( "SMESH_IMPORT_MESH" ) );
213     if ( filenames.count() > 0 ) {
214       SUIT_OverrideCursor wc;
215       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
216
217       QStringList errors;
218       bool isEmpty = false;
219       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
220         QString filename = *it;
221         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
222         try {
223           switch ( theCommandID ) {
224           case 111:
225             {
226               // DAT format (currently unsupported)
227               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
228                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
229               break;
230             }
231           case 112:
232             {
233               // UNV format
234               aMeshes->length( 1 );
235               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toLatin1().constData() );
236               if ( aMeshes[0]->_is_nil() )
237                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
238                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
239               break;
240             }
241           case 113:
242             {
243               // MED format
244               SMESH::DriverMED_ReadStatus res;
245               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toLatin1().constData(), res );
246               if ( res != SMESH::DRS_OK ) {
247                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
248                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
249               }
250               break;
251             }
252           case 140:
253             {
254               // STL format
255               aMeshes->length( 1 );
256               aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toLatin1().constData() );
257               if ( aMeshes[0]->_is_nil() ) {
258                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
259                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
260               }
261               break;
262             }
263           }
264         }
265         catch ( const SALOME::SALOME_Exception& S_ex ) {
266           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
267                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
268         }
269
270         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
271           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
272           if ( aMeshSO ) {
273             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
274             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
275             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
276             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
277               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
278
279 #ifdef WITHGENERICOBJ
280             // obj has been published in study. Its refcount has been incremented.
281             // It is safe to decrement its refcount
282             // so that it will be destroyed when the entry in study will be removed
283             aMeshes[i]->Destroy();
284 #endif
285           }
286           else {
287             isEmpty = true;
288           }
289         }
290       }
291
292       // update Object browser
293       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
294
295       // show Error message box if there were errors
296       if ( errors.count() > 0 ) {
297         SUIT_MessageBox::critical( SMESHGUI::desktop(),
298                                    QObject::tr( "SMESH_ERROR" ),
299                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
300       }
301
302       // show warning message box, if some imported mesh is empty
303       if ( isEmpty ) {
304           SUIT_MessageBox::warning( SMESHGUI::desktop(),
305                                     QObject::tr( "SMESH_WRN_WARNING" ),
306                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
307       }
308     }
309   }
310
311   void ExportMeshToFile( int theCommandID )
312   {
313     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
314     SALOME_ListIO selected;
315     if( aSel )
316       aSel->selectedObjects( selected );
317
318     // actually, the following condition can't be met (added for insurance)
319     if( selected.Extent() == 0 ||
320         ( selected.Extent() > 1 && theCommandID != 122 && theCommandID != 125 ) )
321       return;
322
323     bool hasDuplicatedMeshNames = false;
324     QList< QPair< SMESH::SMESH_Mesh_var, QString > > aMeshList;
325     QList< QPair< SMESH::SMESH_Mesh_var, QString > >::iterator aMeshIter;
326     SALOME_ListIteratorOfListIO It( selected );
327     for( ; It.More(); It.Next() ) {
328       Handle(SALOME_InteractiveObject) anIObject = It.Value();
329       SMESH::SMESH_Mesh_var aMeshItem = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIObject );
330       if ( aMeshItem->_is_nil() ) {
331         SUIT_MessageBox::warning( SMESHGUI::desktop(),
332                                   QObject::tr( "SMESH_WRN_WARNING" ),
333                                   QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
334         return;
335       }
336
337       QString aMeshName = anIObject->getName();
338
339       // check for duplications
340       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
341         if( aMeshName == (*aMeshIter).second ) {
342           hasDuplicatedMeshNames = true;
343           break;
344         }
345       }
346
347       aMeshList.append( QPair< SMESH::SMESH_Mesh_var, QString >( aMeshItem, aMeshName ) );
348     }
349
350     if( hasDuplicatedMeshNames ) {
351       int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
352                                           QObject::tr("SMESH_WRN_WARNING"),
353                                           QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
354                                           QObject::tr("SMESH_BUT_YES"),
355                                           QObject::tr("SMESH_BUT_NO"), 0, 1);
356       if (aRet != 0)
357         return;
358     }
359
360     aMeshIter = aMeshList.begin();
361     SMESH::SMESH_Mesh_var aMesh = (*aMeshIter).first;
362     QString aMeshName = (*aMeshIter).second;
363
364     QList<SALOMEDS::Color> aReservedColors;
365
366     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
367     QMap<QString, SMESH::MED_VERSION> aFilterMap;
368     QMap<QString, int> aFilterMapSTL;
369     switch ( theCommandID ) {
370     case 125:
371     case 122:
372       {
373         for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
374           SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
375           if (aMeshItem->HasDuplicatedGroupNamesMED()) {
376             int aRet = SUIT_MessageBox::warning
377               (SMESHGUI::desktop(),
378                QObject::tr("SMESH_WRN_WARNING"),
379                QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
380                QObject::tr("SMESH_BUT_YES"),
381                QObject::tr("SMESH_BUT_NO"), 0, 1);
382             if (aRet != 0)
383               return;
384           }
385         }
386         // PAL18696
387         QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
388         QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
389         aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v21 ) + " (*.med)", SMESH::MED_V2_1 );
390         aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v22 ) + " (*.med)", SMESH::MED_V2_2 );
391       }
392       break;
393     case 124:
394     case 121:
395       aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
396       break;
397     case 126:
398     case 123:
399       {
400         if (aMesh->NbPyramids()) {
401           int aRet = SUIT_MessageBox::warning
402             (SMESHGUI::desktop(),
403              QObject::tr("SMESH_WRN_WARNING"),
404              QObject::tr("SMESH_EXPORT_UNV").arg(aMeshName),
405              QObject::tr("SMESH_BUT_YES"),
406              QObject::tr("SMESH_BUT_NO"), 0, 1);
407           if (aRet != 0)
408             return;
409         }
410         aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
411       }
412       break;
413     case 141:
414       {
415         // export STL
416         /*
417           there must be check on others mesh elements not equal triangles
418         */
419 //         if (aMesh->NbTriangles() < 1) {
420 //           SUIT_MessageBox::warning
421 //             (SMESHGUI::desktop(),
422 //              QObject::tr("SMESH_WRN_WARNING"),
423 //              QObject::tr("SMESH_EXPORT_STL1").arg(aMeshName));
424 //           return;
425 //         }
426 //         if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
427 //           int aRet = SUIT_MessageBox::warning
428 //             (SMESHGUI::desktop(),
429 //              QObject::tr("SMESH_WRN_WARNING"),
430 //              QObject::tr("SMESH_EXPORT_STL2").arg(aMeshName),
431 //              QObject::tr("SMESH_BUT_YES"),
432 //              QObject::tr("SMESH_BUT_NO"), 0, 1);
433 //           if (aRet != 0)
434 //             return;
435 //         }
436
437         aFilterMapSTL.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 ); // 1 - ASCII mode
438         aFilterMapSTL.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 ); // 0 - Binary mode
439       }
440       break;
441     default:
442       return;
443     }
444
445     QString aFilename;
446     SMESH::MED_VERSION aFormat;
447     // Init the parameter with the default value
448     bool aIsASCII_STL = true;
449     bool toCreateGroups = false;
450     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
451     if ( resMgr )
452       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
453     bool toOverwrite = true;
454
455     QString anInitialPath = "";
456     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
457       anInitialPath = QDir::currentPath();
458
459     if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 141) {
460       if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
461       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + aMeshName,
462                                             aFilter, aTitle, false);
463     }
464     else if(theCommandID == 141) { // Export to STL
465       QStringList filters;
466       QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
467       for ( ; it != aFilterMapSTL.end(); ++it )
468         filters.push_back( it.key() );
469
470       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
471       fd->setWindowTitle( aTitle );
472       fd->setNameFilters( filters );
473       fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
474       if ( !anInitialPath.isEmpty() )
475         fd->setDirectory( anInitialPath );
476       fd->selectFile(aMeshName);
477       bool is_ok = false;
478       while (!is_ok) {
479         if ( fd->exec() )
480           aFilename = fd->selectedFile();
481         aIsASCII_STL = (aFilterMapSTL[fd->selectedNameFilter()]) == 1 ? true: false;
482         is_ok = true;
483       }
484       delete fd;
485     }
486     else { // Export to MED
487       QStringList filters;
488       QString aDefaultFilter;
489       QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
490       for ( ; it != aFilterMap.end(); ++it ) {
491         filters.push_back( it.key() );
492         if (it.value() == SMESH::MED_V2_2)
493           aDefaultFilter = it.key();
494       }
495
496       //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
497       SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
498         ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS"), true, true );
499       fd->setWindowTitle( aTitle );
500       fd->setNameFilters( filters );
501       //fd->setSelectedNameFilter( QObject::tr("MED 2.2 (*.med)") );
502       fd->selectNameFilter(aDefaultFilter);
503       fd->SetChecked(toCreateGroups);
504       if ( !anInitialPath.isEmpty() )
505         fd->setDirectory( anInitialPath );
506       fd->selectFile(aMeshName);
507
508       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
509       fd->setValidator( fv );
510
511       bool is_ok = false;
512       while (!is_ok) {
513         if ( fd->exec() )
514           aFilename = fd->selectedFile();
515         else {
516           aFilename = QString::null;
517           break;
518         }
519         aFormat = aFilterMap[fd->selectedNameFilter()];
520         toOverwrite = fv->isOverwrite();
521         is_ok = true;
522         if ( !aFilename.isEmpty() ) {
523           for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
524             SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
525             if( (aMeshItem->NbPolygons()>0 || aMeshItem->NbPolyhedrons()>0)
526                 && aFormat==SMESH::MED_V2_1) {
527               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
528                                                   QObject::tr("SMESH_WRN_WARNING"),
529                                                   QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
530                                                   QObject::tr("SMESH_BUT_YES"),
531                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
532               if (aRet != 0) {
533                 is_ok = false;
534                 break;
535               }
536             }
537           }
538           if( !toOverwrite ) {
539             SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
540             bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toLatin1().constData(), aVersion );
541             if( !isVersionOk || aVersion != aFormat ) {
542               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
543                                                   QObject::tr("SMESH_WRN_WARNING"),
544                                                   QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
545                                                   QObject::tr("SMESH_BUT_YES"),
546                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
547               if (aRet == 0)
548                 toOverwrite = true;
549               else
550                 is_ok = false;
551             }
552
553             QStringList aMeshNamesCollisionList;
554             SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toLatin1().constData() );
555             for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
556               QString anExistingMeshName( aMeshNames[ i ] );
557               for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
558                 QString anExportMeshName = (*aMeshIter).second;
559                 if( anExportMeshName == anExistingMeshName ) {
560                   aMeshNamesCollisionList.append( anExportMeshName );
561                   break;
562                 }
563               }
564             }
565
566             if( !aMeshNamesCollisionList.isEmpty() ) {
567               QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
568               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
569                                                   QObject::tr("SMESH_WRN_WARNING"),
570                                                   QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
571                                                   QObject::tr("SMESH_BUT_YES"),
572                                                   QObject::tr("SMESH_BUT_NO"),
573                                                   QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
574               if (aRet == 0)
575                 toOverwrite = true;
576               else if (aRet == 2)
577                 is_ok = false;
578             }
579           }
580         }
581       }
582       toCreateGroups = fd->IsChecked();
583       delete fd;
584     }
585     if ( !aFilename.isEmpty() ) {
586       // Check whether the file already exists and delete it if yes
587       QFile aFile( aFilename );
588       if ( aFile.exists() && toOverwrite )
589         aFile.remove();
590       SUIT_OverrideCursor wc;
591
592       try {
593         bool Renumber = false;
594         // PAL 14172  : Check of we have to renumber or not from the preferences before export
595         if (resMgr)
596           Renumber= resMgr->booleanValue("SMESH","renumbering");
597         if (Renumber){
598           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
599           aMeshEditor->RenumberNodes();
600           aMeshEditor->RenumberElements();
601           if ( SMESHGUI::automaticUpdate() )
602             SMESH::UpdateView();
603         }
604         switch ( theCommandID ) {
605         case 125:
606         case 122: {
607             int aMeshIndex = 0;
608             for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ ) {
609               SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
610               if( !aMeshItem->_is_nil() )
611                 aMeshItem->ExportToMEDX( aFilename.toLatin1().data(), toCreateGroups, aFormat, toOverwrite && aMeshIndex == 0 );
612             }
613           }
614           break;
615         case 124:
616         case 121:
617           aMesh->ExportDAT( aFilename.toLatin1().data() );
618           break;
619         case 126:
620         case 123:
621           aMesh->ExportUNV( aFilename.toLatin1().data() );
622           break;
623         case 141:
624           aMesh->ExportSTL( aFilename.toLatin1().data(), aIsASCII_STL );
625           break;
626         default:
627           break;
628         }
629       }
630       catch (const SALOME::SALOME_Exception& S_ex){
631         wc.suspend();
632         SUIT_MessageBox::warning(SMESHGUI::desktop(),
633                                  QObject::tr("SMESH_WRN_WARNING"),
634                                  QObject::tr("SMESH_EXPORT_FAILED"));
635         wc.resume();
636       }
637     }
638   }
639
640   inline void InverseEntityMode(unsigned int& theOutputMode,
641                                 unsigned int theMode)
642   {
643     bool anIsNotPresent = ~theOutputMode & theMode;
644     if(anIsNotPresent)
645       theOutputMode |= theMode;
646     else
647       theOutputMode &= ~theMode;
648   }
649
650   void SetDisplayEntity(int theCommandID){
651     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
652     SALOME_ListIO selected;
653     if( aSel )
654       aSel->selectedObjects( selected );
655
656     if(selected.Extent() >= 1){
657       SALOME_ListIteratorOfListIO It( selected );
658       for( ; It.More(); It.Next()){
659         Handle(SALOME_InteractiveObject) IObject = It.Value();
660         if(IObject->hasEntry()){
661           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
662             unsigned int aMode = anActor->GetEntityMode();
663             switch(theCommandID){
664             case 216:
665               InverseEntityMode(aMode,SMESH_Actor::e0DElements);
666               break;
667             case 217:
668               InverseEntityMode(aMode,SMESH_Actor::eEdges);
669               break;
670             case 218:
671               InverseEntityMode(aMode,SMESH_Actor::eFaces);
672               break;
673             case 219:
674               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
675               break;
676             case 220:
677               aMode = SMESH_Actor::eAllEntity;
678               break;
679             }
680             if(aMode)
681               anActor->SetEntityMode(aMode);
682           }
683         }
684       }
685     }
686   }
687
688   void AutoColor(){
689     SALOME_ListIO selected;
690     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
691     if( !app )
692       return;
693
694     LightApp_SelectionMgr* aSel = app->selectionMgr();
695     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
696     if( !aSel || !appStudy )
697       return;
698
699     aSel->selectedObjects( selected );
700     if( selected.IsEmpty() )
701       return;
702
703     Handle(SALOME_InteractiveObject) anIObject = selected.First();
704
705     _PTR(Study) aStudy = appStudy->studyDS();
706     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
707     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
708     if( aMainObject->_is_nil() )
709       return;
710
711     aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
712
713     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
714     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
715     {
716       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
717       SALOMEDS::Color aColor = aGroupObject->GetColor();
718       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
719       if (aGroupSObject) {
720         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
721           if( aGroupObject->GetType() == SMESH::NODE )
722             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
723           else if( aGroupObject->GetType() == SMESH::EDGE )
724             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
725           else if( aGroupObject->GetType() == SMESH::ELEM0D )
726             anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
727           else
728             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
729         }
730       }
731     }
732
733     SMESH::RepaintCurrentView();
734   }
735
736   QString functorToString( SMESH::Controls::FunctorPtr f )
737   {
738     QString type = QObject::tr( "UNKNOWN_CONTROL" );
739     if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
740       type = QObject::tr( "VOLUME_3D_ELEMENTS" );
741     else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
742       type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
743     else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
744       type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
745     else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
746       type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
747     else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
748       type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
749     else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
750       type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
751     else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
752       type = QObject::tr( "WARP_ELEMENTS" );
753     else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
754       type = QObject::tr( "TAPER_ELEMENTS" );
755     else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
756       type = QObject::tr( "SKEW_ELEMENTS" );
757     else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
758       type = QObject::tr( "AREA_ELEMENTS" );
759     else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
760       type = QObject::tr( "LENGTH_EDGES" );
761     else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
762       type = QObject::tr( "LENGTH2D_EDGES" );
763     else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
764       type = QObject::tr( "MULTI_BORDERS" );
765     else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
766       type = QObject::tr( "MULTI2D_BORDERS" );
767     else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
768       type = QObject::tr( "FREE_NODES" );
769     else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
770       type = QObject::tr( "FREE_EDGES" );
771     else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
772       type = QObject::tr( "FREE_BORDERS" );
773     else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
774       type = QObject::tr( "FREE_FACES" );
775     else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
776       type = QObject::tr( "BARE_BORDER_VOLUME" );
777     else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
778       type = QObject::tr( "BARE_BORDER_FACE" );
779     else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
780       type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
781     else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
782       type = QObject::tr( "OVER_CONSTRAINED_FACE" );
783     return type;
784   }
785
786   void SaveDistribution()
787   {
788     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
789     SALOME_ListIO selected;
790     if ( aSel )
791       aSel->selectedObjects( selected );
792
793     if ( selected.Extent() == 1 ) {
794       Handle(SALOME_InteractiveObject) anIO = selected.First();
795       if ( anIO->hasEntry() ) {
796         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
797         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
798           SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
799           SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
800           if ( aScalarBarActor && aFunctor ) {
801             SMESH::Controls::NumericalFunctor* aNumFun = dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
802             if ( aNumFun ) {
803               std::vector<int> elements;
804               SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
805               if ( mesh->_is_nil() ) {
806                 SMESH::SMESH_IDSource_var idSource =
807                   SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
808                 if ( !idSource->_is_nil() )
809                 {
810                   SMESH::long_array_var ids = idSource->GetIDs();
811                   elements.resize( ids->length() );
812                   for ( unsigned i = 0; i < elements.size(); ++i )
813                     elements[i] = ids[i];
814                 }
815               }
816               int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
817               vtkLookupTable* lookupTable =
818                 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
819               double * minmax = lookupTable->GetRange();
820               std::vector<int>    nbEvents;
821               std::vector<double> funValues;
822               aNumFun->GetHistogram( nbIntervals, nbEvents, funValues, elements, minmax );
823               QString anInitialPath = "";
824               if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
825                 anInitialPath = QDir::currentPath();
826               QString aMeshName = anIO->getName();
827               QStringList filter;
828               filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
829               filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
830               QString aFilename = anInitialPath + "/" + aMeshName + "_" + 
831                 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
832               aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
833                                                      aFilename,
834                                                      filter,
835                                                      QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
836                                                      false );
837               if ( !aFilename.isEmpty() ) {
838                 QFile f( aFilename );
839                 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
840                   QTextStream out( &f );
841                   out << "# Mesh: " << aMeshName << endl;
842                   out << "# Control: " << functorToString( aFunctor ) << endl;
843                   out << "#" << endl;
844                   out.setFieldWidth( 10 );
845                   for ( int i = 0; i < qMin( nbEvents.size(), funValues.size()-1 ); i++ )
846                     out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
847                   f.close();
848                 }
849               }
850             }
851           }
852         }
853       }
854     }
855   }
856
857   void ShowDistribution() {
858     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
859     SALOME_ListIO selected;
860     if ( aSel )
861       aSel->selectedObjects( selected );
862     
863     if ( selected.Extent() == 1 ) {
864       Handle(SALOME_InteractiveObject) anIO = selected.First();
865       if ( anIO->hasEntry() ) {
866         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
867         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
868           SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
869           aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
870         }
871       }
872     }
873   }
874
875 #ifndef DISABLE_PLOT2DVIEWER
876  void PlotDistribution() {
877    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
878    if( !app )
879      return;
880
881    LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
882    SALOME_ListIO selected;
883    if ( aSel )
884      aSel->selectedObjects( selected );
885     
886    if ( selected.Extent() == 1 ) {
887      Handle(SALOME_InteractiveObject) anIO = selected.First();
888      if ( anIO->hasEntry() ) {
889        //Find Actor by entry before getting Plot2d viewer,
890        //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
891        SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
892
893        SUIT_ViewManager* aViewManager = app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
894
895        if( !aViewManager )
896          return;
897        
898        SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
899        if ( !aView )
900          return;
901
902        Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
903        if ( !aPlot )
904          return;
905
906        if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone ) {
907          SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
908          QString functorName = functorToString( anActor->GetFunctor());
909          QString aHistogramName("%1 : %2");
910          aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
911          aHistogram->setName(aHistogramName);
912          aHistogram->setHorTitle(functorName);
913          aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
914          aPlot->displayObject(aHistogram, true);
915        }
916      }
917    }
918  }
919 #endif //DISABLE_PLOT2DVIEWER
920
921   void DisableAutoColor(){
922     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
923     SALOME_ListIO selected;
924     if( aSel )
925       aSel->selectedObjects( selected );
926
927     if(selected.Extent()){
928       Handle(SALOME_InteractiveObject) anIObject = selected.First();
929       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
930       if ( !aMesh->_is_nil() ) {
931         aMesh->SetAutoColor( false );
932       }
933     }
934   }
935
936   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap){
937     SALOME_ListIO selected;
938     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
939     if( !app )
940       return;
941
942     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
943     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
944     if( !aSel || !appStudy )
945       return;
946
947     if( theCommandID == 1134 ) { // Clipping dialog can be activated without selection
948       if( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
949         aModule->EmitSignalDeactivateDialog();
950         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
951           (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
952       }
953       return;
954     }
955
956     _PTR(Study) aStudy = appStudy->studyDS();
957
958     aSel->selectedObjects( selected );
959
960     if(selected.Extent() >= 1){
961       switch(theCommandID){
962       case 1133:{
963         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
964         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
965         return;
966       }
967       case 1132:{
968         QColor c, e, b, n, c0D, o;
969         int size0D = 0;
970         int Edgewidth = 0;
971         vtkFloatingPointType Shrink = 0.0;
972         vtkFloatingPointType faces_orientation_scale = 0.0;
973         bool faces_orientation_3dvectors = false;
974
975         VTK::MarkerType aMarkerTypeCurrent = VTK::MT_NONE;
976         VTK::MarkerScale aMarkerScaleCurrent = VTK::MS_NONE;
977         int aMarkerTextureCurrent = 0;
978
979         SALOME_ListIteratorOfListIO It( selected );
980         for( ; It.More(); It.Next()){
981           Handle(SALOME_InteractiveObject) IObject = It.Value();
982           if(IObject->hasEntry()){
983             if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
984               vtkFloatingPointType color[3];
985               anActor->GetSufaceColor(color[0], color[1], color[2]);
986               int c0 = int (color[0] * 255);
987               int c1 = int (color[1] * 255);
988               int c2 = int (color[2] * 255);
989               c.setRgb(c0, c1, c2);
990
991               vtkFloatingPointType edgecolor[3];
992               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
993               c0 = int (edgecolor[0] * 255);
994               c1 = int (edgecolor[1] * 255);
995               c2 = int (edgecolor[2] * 255);
996               e.setRgb(c0, c1, c2);
997
998               vtkFloatingPointType backfacecolor[3];
999               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
1000               c0 = int (backfacecolor[0] * 255);
1001               c1 = int (backfacecolor[1] * 255);
1002               c2 = int (backfacecolor[2] * 255);
1003               b.setRgb(c0, c1, c2);
1004
1005               vtkFloatingPointType nodecolor[3];
1006               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1007               c0 = int (nodecolor[0] * 255);
1008               c1 = int (nodecolor[1] * 255);
1009               c2 = int (nodecolor[2] * 255);
1010               n.setRgb(c0, c1, c2);
1011
1012               vtkFloatingPointType color0D[3];
1013               anActor->Get0DColor(color0D[0], color0D[1], color0D[2]);
1014               c0 = int (color0D[0] * 255);
1015               c1 = int (color0D[1] * 255);
1016               c2 = int (color0D[2] * 255);
1017               c0D.setRgb(c0, c1, c2);
1018
1019               size0D = (int)anActor->Get0DSize();
1020               if(size0D == 0)
1021                 size0D = 1;
1022               Edgewidth = (int)anActor->GetLineWidth();
1023               if(Edgewidth == 0)
1024                 Edgewidth = 1;
1025               Shrink = anActor->GetShrinkFactor();
1026
1027               vtkFloatingPointType faces_orientation_color[3];
1028               anActor->GetFacesOrientationColor(faces_orientation_color);
1029               c0 = int (faces_orientation_color[0] * 255);
1030               c1 = int (faces_orientation_color[1] * 255);
1031               c2 = int (faces_orientation_color[2] * 255);
1032               o.setRgb(c0, c1, c2);
1033
1034               faces_orientation_scale = anActor->GetFacesOrientationScale();
1035               faces_orientation_3dvectors = anActor->GetFacesOrientation3DVectors();
1036
1037               aMarkerTypeCurrent = anActor->GetMarkerType();
1038               aMarkerScaleCurrent = anActor->GetMarkerScale();
1039               aMarkerTextureCurrent = anActor->GetMarkerTexture();
1040
1041               // even if there are multiple objects in the selection,
1042               // we need only the first one to get values for the dialog
1043               break;
1044             }
1045           }
1046         }
1047
1048         SMESHGUI_Preferences_ColorDlg *aDlg =
1049           new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI() );
1050         aDlg->SetColor(1, c);
1051         aDlg->SetColor(2, e);
1052         aDlg->SetColor(3, n);
1053         aDlg->SetColor(4, b);
1054         aDlg->SetColor(5, c0D);
1055         aDlg->SetColor(6, o);
1056         aDlg->SetIntValue(1, Edgewidth);
1057         aDlg->SetIntValue(2, int(Shrink*100.));
1058         aDlg->SetIntValue(3, size0D);
1059         aDlg->SetDoubleValue(1, faces_orientation_scale);
1060         aDlg->SetBooleanValue(1, faces_orientation_3dvectors);
1061  
1062         aDlg->setCustomMarkerMap( theMarkerMap[ aStudy->StudyId() ] );
1063
1064         if( aMarkerTypeCurrent != VTK::MT_USER )
1065           aDlg->setStandardMarker( aMarkerTypeCurrent, aMarkerScaleCurrent );
1066         else
1067           aDlg->setCustomMarker( aMarkerTextureCurrent );
1068
1069         if(aDlg->exec()){
1070           QColor color = aDlg->GetColor(1);
1071           QColor edgecolor = aDlg->GetColor(2);
1072           QColor nodecolor = aDlg->GetColor(3);
1073           QColor backfacecolor = aDlg->GetColor(4);
1074           QColor color0D = aDlg->GetColor(5);
1075           QColor faces_orientation_color = aDlg->GetColor(6);
1076
1077           /* Point marker */
1078           theMarkerMap[ aStudy->StudyId() ] = aDlg->getCustomMarkerMap();
1079
1080           SALOME_ListIteratorOfListIO It( selected );
1081           for( ; It.More(); It.Next()){
1082             Handle(SALOME_InteractiveObject) IObject = It.Value();
1083             if(IObject->hasEntry()){
1084               if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1085                 /* actor color and backface color */
1086                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
1087                                         vtkFloatingPointType (color.green()) / 255.,
1088                                         vtkFloatingPointType (color.blue()) / 255.);
1089                 anActor->SetBackSufaceColor(vtkFloatingPointType (backfacecolor.red()) / 255.,
1090                                             vtkFloatingPointType (backfacecolor.green()) / 255.,
1091                                             vtkFloatingPointType (backfacecolor.blue()) / 255.);
1092
1093                 /* edge color */
1094                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
1095                                       vtkFloatingPointType (edgecolor.green()) / 255.,
1096                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
1097
1098                 /* Shrink factor and size edges */
1099                 anActor->SetShrinkFactor(aDlg->GetIntValue(2) / 100.);
1100                 anActor->SetLineWidth(aDlg->GetIntValue(1));
1101
1102                 /* Nodes color and size */
1103                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
1104                                       vtkFloatingPointType (nodecolor.green()) / 255.,
1105                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
1106
1107                 /* 0D elements */
1108                 anActor->Set0DColor(vtkFloatingPointType (color0D.red()) / 255.,
1109                                     vtkFloatingPointType (color0D.green()) / 255.,
1110                                     vtkFloatingPointType (color0D.blue()) / 255.);
1111                 anActor->Set0DSize(aDlg->GetIntValue(3));
1112
1113                 /* Faces orientation */
1114                 vtkFloatingPointType c[3] = {vtkFloatingPointType(faces_orientation_color.redF()),
1115                                              vtkFloatingPointType(faces_orientation_color.greenF()),
1116                                              vtkFloatingPointType(faces_orientation_color.blueF())};
1117                 anActor->SetFacesOrientationColor(c);
1118                 anActor->SetFacesOrientationScale(aDlg->GetDoubleValue(1));
1119                 anActor->SetFacesOrientation3DVectors(aDlg->GetBooleanValue(1));
1120
1121                 VTK::MarkerType aMarkerTypeNew = aDlg->getMarkerType();
1122                 VTK::MarkerScale aMarkerScaleNew = aDlg->getStandardMarkerScale();
1123                 int aMarkerTextureNew = aDlg->getCustomMarkerID();
1124                 if( aMarkerTypeNew != VTK::MT_USER )
1125                   anActor->SetMarkerStd( aMarkerTypeNew, aMarkerScaleNew );
1126                 else {
1127                   const VTK::MarkerMap& aMarkerMap = theMarkerMap[ aStudy->StudyId() ];
1128                   VTK::MarkerMap::const_iterator anIter = aMarkerMap.find( aMarkerTextureNew );
1129                   if( anIter != aMarkerMap.end() )
1130                     anActor->SetMarkerTexture( aMarkerTextureNew, anIter->second.second );
1131                 }
1132
1133                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1134                 if( !aGroupObject->_is_nil() )
1135                 {
1136                   SMESH::ElementType anElementType = aGroupObject->GetType();
1137                   QColor aColor;
1138                   switch( anElementType )
1139                   {
1140                     case SMESH::NODE: aColor = nodecolor; break;
1141                     case SMESH::EDGE: aColor = edgecolor; break;
1142                     default: aColor = color; break;
1143                   }
1144
1145                   SALOMEDS::Color aGroupColor;
1146                   aGroupColor.R = (float)aColor.red() / 255.0;
1147                   aGroupColor.G = (float)aColor.green() / 255.0;
1148                   aGroupColor.B = (float)aColor.blue() / 255.0;
1149                   aGroupObject->SetColor( aGroupColor );
1150                 }
1151               }
1152             }
1153           }
1154           SMESH::RepaintCurrentView();
1155         }
1156         delete aDlg;
1157         return;
1158       }
1159       }
1160       SALOME_ListIteratorOfListIO It( selected );
1161       for( ; It.More(); It.Next()){
1162         Handle(SALOME_InteractiveObject) IObject = It.Value();
1163         if(IObject->hasEntry()){
1164           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1165             switch(theCommandID){
1166             case 211:
1167               anActor->SetRepresentation(SMESH_Actor::eEdge);
1168               break;
1169             case 212:
1170               anActor->SetRepresentation(SMESH_Actor::eSurface);
1171               break;
1172             case 213:
1173               if(anActor->IsShrunk())
1174                 anActor->UnShrink();
1175               else
1176                 anActor->SetShrink();
1177               break;
1178             case 215:
1179               anActor->SetRepresentation(SMESH_Actor::ePoint);
1180               break;
1181             case 231:
1182               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1183                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1184               break;
1185             case 232:
1186               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1187                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1188               break;
1189             }
1190           }
1191         }
1192       }
1193       SMESH::RepaintCurrentView();
1194     }
1195   }
1196
1197   void Control( int theCommandID )
1198   {
1199     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1200     SALOME_ListIO selected;
1201     if( aSel )
1202       aSel->selectedObjects( selected );
1203
1204     if( !selected.IsEmpty() ){
1205       Handle(SALOME_InteractiveObject) anIO = selected.First();
1206       if(!anIO.IsNull()){
1207         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
1208         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
1209           switch ( theCommandID ){
1210           case 6001:
1211             aControl = SMESH_Actor::eLength;
1212             break;
1213           case 6018:
1214             aControl = SMESH_Actor::eLength2D;
1215             break;
1216           case 6002:
1217             aControl = SMESH_Actor::eFreeEdges;
1218             break;
1219           case 6003:
1220             aControl = SMESH_Actor::eFreeBorders;
1221             break;
1222           case 6004:
1223             aControl = SMESH_Actor::eMultiConnection;
1224             break;
1225           case 6005:
1226             aControl = SMESH_Actor::eFreeNodes;
1227             break;
1228           case 6019:
1229             aControl = SMESH_Actor::eMultiConnection2D;
1230             break;
1231           case 6011:
1232             aControl = SMESH_Actor::eArea;
1233             break;
1234           case 6012:
1235             aControl = SMESH_Actor::eTaper;
1236             break;
1237           case 6013:
1238             aControl = SMESH_Actor::eAspectRatio;
1239             break;
1240           case 6017:
1241             aControl = SMESH_Actor::eAspectRatio3D;
1242             break;
1243           case 6014:
1244             aControl = SMESH_Actor::eMinimumAngle;
1245             break;
1246           case 6015:
1247             aControl = SMESH_Actor::eWarping;
1248             break;
1249           case 6016:
1250             aControl = SMESH_Actor::eSkew;
1251             break;
1252           case 6009:
1253             aControl = SMESH_Actor::eVolume3D;
1254             break;
1255           case 6021:
1256             aControl = SMESH_Actor::eFreeFaces;
1257             break;
1258           case 6022:
1259             aControl = SMESH_Actor::eMaxElementLength2D;
1260             break;
1261           case 6023:
1262             aControl = SMESH_Actor::eMaxElementLength3D;
1263             break;
1264           case 6024:
1265             aControl = SMESH_Actor::eBareBorderVolume;
1266             break;
1267           case 6025:
1268             aControl = SMESH_Actor::eBareBorderFace;
1269             break;
1270           case 6026:
1271             aControl = SMESH_Actor::eOverConstrainedVolume;
1272             break;
1273           case 6027:
1274             aControl = SMESH_Actor::eOverConstrainedFace;
1275             break;
1276           }
1277           anActor->SetControlMode(aControl);
1278           anActor->GetScalarBarActor()->SetTitle( functorToString( anActor->GetFunctor() ).toLatin1().constData() );
1279           SMESH::RepaintCurrentView();
1280 #ifndef DISABLE_PLOT2DVIEWER
1281           if(anActor->GetPlot2Histogram()) {
1282             SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1283             QString functorName = functorToString( anActor->GetFunctor());
1284             QString aHistogramName("%1 : %2");
1285             aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1286             aHistogram->setName(aHistogramName);
1287             aHistogram->setHorTitle(functorName);
1288             SMESH::ProcessIn2DViewers(anActor);
1289           }
1290 #endif
1291         }
1292       }
1293     }
1294   }
1295
1296
1297   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1298                    MeshObjectType                           theType,
1299                    const QString                            theInTypeName,
1300                    QString &                                theOutTypeName)
1301   {
1302     SMESH_TypeFilter aTypeFilter( theType );
1303     QString entry;
1304     if( !theIO.IsNull() )
1305     {
1306       entry = theIO->getEntry();
1307       LightApp_DataOwner owner( entry );
1308       if ( aTypeFilter.isOk( &owner )) {
1309         theOutTypeName = theInTypeName;
1310         return true;
1311       }
1312     }
1313     return false;
1314   }
1315
1316
1317   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1318   {
1319     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1320     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1321     if (aSObj) {
1322       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1323       CORBA::String_var anID = aSComp->GetID().c_str();
1324       if (!strcmp(anID.in(),theIO->getEntry()))
1325         return "Component";
1326     }
1327
1328     QString aTypeName;
1329     if (
1330         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
1331         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
1332         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
1333         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
1334         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
1335         )
1336       return aTypeName;
1337
1338     return "NoType";
1339   }
1340
1341
1342   QString CheckHomogeneousSelection()
1343   {
1344     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
1345     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1346     SALOME_ListIO selected;
1347     if( aSel )
1348       aSel->selectedObjects( selected );
1349
1350     QString RefType = CheckTypeObject(selected.First());
1351     SALOME_ListIteratorOfListIO It(selected);
1352     for ( ; It.More(); It.Next())
1353       {
1354         Handle(SALOME_InteractiveObject) IObject = It.Value();
1355         QString Type = CheckTypeObject(IObject);
1356         if (Type.compare(RefType) != 0)
1357           return "Heterogeneous Selection";
1358       }
1359
1360     return RefType;
1361   }
1362
1363
1364   void SMESHGUI::OnEditDelete()
1365   {
1366     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1367     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1368     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1369
1370     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1371     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1372     _PTR(GenericAttribute) anAttr;
1373     _PTR(AttributeIOR) anIOR;
1374
1375     int objectCount = 0;
1376     QString aNameList;
1377     QString aParentComponent = QString::null;
1378     Handle(SALOME_InteractiveObject) anIO;
1379     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1380     {
1381       anIO = anIt.Value();
1382       QString cur = anIO->getComponentDataType();
1383       _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
1384       if (aSO) {
1385         // check if object is reference
1386         _PTR(SObject) aRefSObj;
1387         aNameList.append("\n    - ");
1388         if ( aSO->ReferencedObject( aRefSObj ) ) {
1389           QString aRefName = QString::fromStdString ( aRefSObj->GetName() );
1390           aNameList.append( aRefName );
1391           cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1392         }
1393         else
1394           aNameList.append(anIO->getName());
1395         objectCount++;
1396       }
1397
1398       if( aParentComponent.isNull() )
1399         aParentComponent = cur;
1400       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
1401         aParentComponent = "";
1402     }
1403
1404     if ( objectCount == 0 )
1405       return; // No Valid Objects Selected
1406
1407     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
1408       SUIT_MessageBox::warning( SMESHGUI::desktop(),
1409                                 QObject::tr("ERR_ERROR"),
1410                                 QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1411       return;
1412     }
1413     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1414     if (SUIT_MessageBox::warning
1415         (SMESHGUI::desktop(),
1416          QObject::tr("SMESH_WRN_WARNING"),
1417          QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1418          SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1419          SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1420       return;
1421
1422     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1423
1424     ViewManagerList aViewMenegers = anApp->viewManagers();
1425     ViewManagerList::const_iterator it = aViewMenegers.begin();
1426     for( ; it != aViewMenegers.end(); it++) {
1427       
1428       SUIT_ViewManager* vm = *it;
1429       int nbSf = vm ? vm->getViewsCount() : 0;
1430
1431       SALOME_ListIteratorOfListIO It(selected);
1432       
1433       aStudyBuilder->NewCommand();  // There is a transaction
1434       for( ; It.More(); It.Next()){ // loop on selected IO's
1435         Handle(SALOME_InteractiveObject) IObject = It.Value();
1436         if(IObject->hasEntry()) {
1437           _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1438           
1439           // disable removal of "SMESH" component object
1440           if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1441             anIOR = anAttr;
1442             if ( engineIOR() == anIOR->Value().c_str() )
1443               continue;
1444           }
1445           //Check the referenced object
1446           _PTR(SObject) aRefSObject;
1447           if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1448             aSO = aRefSObject; // Delete main Object instead of reference
1449           
1450           // put the whole hierarchy of sub-objects of the selected SO into a list and
1451           // then treat them all starting from the deepest objects (at list back)
1452           
1453           std::list< _PTR(SObject) > listSO;
1454           listSO.push_back( aSO );
1455           std::list< _PTR(SObject) >::iterator itSO = listSO.begin();
1456           for ( ; itSO != listSO.end(); ++itSO ) {
1457             _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1458             for (it->InitEx(false); it->More(); it->Next())
1459               listSO.push_back( it->Value() );
1460           }
1461           
1462           // treat SO's in the list starting from the back
1463           
1464           std::list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
1465           for ( ; ritSO != listSO.rend(); ++ritSO ) {
1466             _PTR(SObject) SO = *ritSO;
1467             if ( !SO ) continue;
1468             std::string anEntry = SO->GetID();
1469             
1470             /** Erase graphical object **/
1471             if(SO->FindAttribute(anAttr, "AttributeIOR") && vm ){
1472               QVector<SUIT_ViewWindow*> aViews = vm->getViews();
1473               for(int i = 0; i < nbSf; i++){
1474                 SUIT_ViewWindow *sf = aViews[i];
1475                 if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
1476                   SMESH::RemoveActor(sf,anActor);
1477                 }
1478               }
1479             }
1480             
1481             /** Remove an object from data structures **/
1482             SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1483             SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1484             if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
1485               SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1486               aMesh->RemoveGroup( aGroup );
1487             }
1488             else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
1489               SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1490               aMesh->RemoveSubMesh( aSubMesh );
1491               
1492               _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1493               if (aMeshSO)
1494                 SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1495             }
1496             else {
1497               IObject = new SALOME_InteractiveObject
1498                 ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1499               QString objType = CheckTypeObject(IObject);
1500               if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1501                 SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1502                 aStudyBuilder->RemoveObjectWithChildren( SO );
1503               }
1504               else {// default action: remove SObject from the study
1505                 // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1506                 //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1507                 //op->start();
1508                 aStudyBuilder->RemoveObjectWithChildren( SO );
1509                 //op->finish();
1510               }
1511             }
1512           } /* listSO back loop */
1513         } /* IObject->hasEntry() */
1514       } /* more/next */
1515     } /* aViewMenegers list loop */
1516     
1517     aStudyBuilder->CommitCommand();
1518
1519     /* Clear any previous selection */
1520     SALOME_ListIO l1;
1521     aSel->setSelectedObjects( l1 );
1522
1523     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1524   }
1525 //}
1526
1527 extern "C" {
1528   SMESHGUI_EXPORT CAM_Module* createModule()
1529   {
1530     return new SMESHGUI();
1531   }
1532 }
1533
1534 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1535
1536 //=============================================================================
1537 /*!
1538  *
1539  */
1540 //=============================================================================
1541 SMESHGUI::SMESHGUI() :
1542 SalomeApp_Module( "SMESH" ),
1543 LightApp_Module( "SMESH" )
1544 {
1545   if ( CORBA::is_nil( myComponentSMESH ) )
1546   {
1547     CORBA::Boolean anIsEmbeddedMode;
1548     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1549     MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
1550
1551     //  0019923: EDF 765 SMESH : default values of hypothesis
1552     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
1553     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
1554     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
1555     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
1556     myComponentSMESH->SetDefaultNbSegments( nbSeg );
1557   }
1558
1559   myActiveDialogBox = 0;
1560   myFilterLibraryDlg = 0;
1561   myState = -1;
1562   myDisplayer = 0;
1563
1564   myEventCallbackCommand = vtkCallbackCommand::New();
1565   myEventCallbackCommand->Delete();
1566   myEventCallbackCommand->SetClientData( this );
1567   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
1568   myPriority = 0.0;
1569
1570   SMESH::GetFilterManager();
1571   SMESH::GetPattern();
1572   SMESH::GetMeasurements();
1573
1574   /* load resources for all available meshers */
1575   SMESH::InitAvailableHypotheses();
1576 }
1577
1578 //=============================================================================
1579 /*!
1580  *
1581  */
1582 //=============================================================================
1583 SMESHGUI::~SMESHGUI()
1584 {
1585 #ifdef WITHGENERICOBJ
1586   SMESH::GetFilterManager()->Destroy();
1587   SMESH::GetMeasurements()->Destroy();
1588 #endif
1589   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1590   SMESH::GetMeasurements() = SMESH::Measurements::_nil();
1591 }
1592
1593 //=============================================================================
1594 /*!
1595  *
1596  */
1597 //=============================================================================
1598 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1599 {
1600   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1601   if( anApp )
1602     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1603   else
1604     return 0;
1605 }
1606
1607 //=============================================================================
1608 /*!
1609  *
1610  */
1611 //=============================================================================
1612 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
1613 {
1614   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1615   if ( !resMgr )
1616     return false;
1617
1618   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
1619   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
1620   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
1621   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
1622   return autoUpdate && !exceeded;
1623 }
1624
1625 //=============================================================================
1626 /*!
1627  *
1628  */
1629 //=============================================================================
1630 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1631 {
1632   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1633 }
1634
1635 //=============================================================================
1636 /*!
1637  *
1638  */
1639 //=============================================================================
1640 SMESHGUI* SMESHGUI::GetSMESHGUI()
1641 {
1642   SMESHGUI* smeshMod = 0;
1643   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1644   if ( app )
1645   {
1646     CAM_Module* module = app->module( "Mesh" );
1647     smeshMod = dynamic_cast<SMESHGUI*>( module );
1648   }
1649
1650   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1651   {
1652     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1653     if ( study )
1654     {
1655       _PTR(Study) aStudy = study->studyDS();
1656       if ( aStudy )
1657         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1658     }
1659   }
1660
1661   return smeshMod;
1662 }
1663
1664 extern "C"
1665 {
1666   Standard_EXPORT SMESHGUI* GetComponentGUI()
1667   {
1668     return SMESHGUI::GetSMESHGUI();
1669   }
1670 }
1671
1672 //=============================================================================
1673 /*!
1674  *
1675  */
1676 //=============================================================================
1677 void SMESHGUI::SetState(int aState)
1678 {
1679   myState = aState;
1680 }
1681
1682 //=============================================================================
1683 /*!
1684  *
1685  */
1686 //=============================================================================
1687 void SMESHGUI::ResetState()
1688 {
1689   myState = -1;
1690 }
1691
1692 //=============================================================================
1693 /*!
1694  *
1695  */
1696 //=============================================================================
1697 void SMESHGUI::EmitSignalDeactivateDialog()
1698 {
1699   emit SignalDeactivateActiveDialog();
1700 }
1701
1702 //=============================================================================
1703 /*!
1704  *
1705  */
1706 //=============================================================================
1707 void SMESHGUI::EmitSignalStudyFrameChanged()
1708 {
1709   emit SignalStudyFrameChanged();
1710 }
1711
1712 //=============================================================================
1713 /*!
1714  *
1715  */
1716 //=============================================================================
1717 void SMESHGUI::EmitSignalCloseAllDialogs()
1718 {
1719   emit SignalCloseAllDialogs();
1720 }
1721
1722 //=============================================================================
1723 /*!
1724  *
1725  */
1726 //=============================================================================
1727 void SMESHGUI::EmitSignalVisibilityChanged()
1728 {
1729   emit SignalVisibilityChanged();
1730 }
1731
1732 //=============================================================================
1733 /*!
1734  *
1735  */
1736 //=============================================================================
1737 QDialog *SMESHGUI::GetActiveDialogBox()
1738 {
1739   return myActiveDialogBox;
1740 }
1741
1742 //=============================================================================
1743 /*!
1744  *
1745  */
1746 //=============================================================================
1747 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1748 {
1749   myActiveDialogBox = (QDialog *) aDlg;
1750   return;
1751 }
1752
1753 //=============================================================================
1754 /*!
1755  *
1756  */
1757 //=============================================================================
1758 SUIT_Desktop* SMESHGUI::desktop()
1759 {
1760   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1761   if( app )
1762     return app->desktop();
1763   else
1764     return 0;
1765 }
1766
1767 //=============================================================================
1768 /*!
1769  *
1770  */
1771 //=============================================================================
1772 SalomeApp_Study* SMESHGUI::activeStudy()
1773 {
1774   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1775   if( app )
1776     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1777   else
1778     return NULL;
1779 }
1780
1781 //=============================================================================
1782 /*!
1783  *
1784  */
1785 //=============================================================================
1786 void SMESHGUI::Modified( bool theIsUpdateActions )
1787 {
1788   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
1789     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
1790       appStudy->Modified();
1791       if( theIsUpdateActions )
1792         app->updateActions();
1793     }
1794   }
1795 }
1796
1797 //=============================================================================
1798 /*!
1799  *
1800  */
1801 //=============================================================================
1802 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1803 {
1804   /* Here the position is on the bottom right corner - 10 */
1805   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1806   aDlg->adjustSize();
1807   SUIT_Desktop *PP = desktop();
1808   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1809   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1810   return true;
1811 }
1812
1813 //=============================================================================
1814 /*!
1815  *
1816  */
1817 //=============================================================================
1818 static int isStudyLocked(_PTR(Study) theStudy){
1819   return theStudy->GetProperties()->IsLocked();
1820 }
1821
1822 static bool checkLock(_PTR(Study) theStudy) {
1823   if (isStudyLocked(theStudy)) {
1824     SUIT_MessageBox::warning( SMESHGUI::desktop(),
1825                               QObject::tr("WRN_WARNING"),
1826                               QObject::tr("WRN_STUDY_LOCKED") );
1827     return true;
1828   }
1829   return false;
1830 }
1831
1832 //=======================================================================
1833 //function : CheckActiveStudyLocked
1834 //purpose  :
1835 //=======================================================================
1836
1837 bool SMESHGUI::isActiveStudyLocked()
1838 {
1839   _PTR(Study) aStudy = activeStudy()->studyDS();
1840   return checkLock( aStudy );
1841 }
1842
1843 //=============================================================================
1844 /*!
1845  *
1846  */
1847 //=============================================================================
1848 bool SMESHGUI::OnGUIEvent( int theCommandID )
1849 {
1850   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1851   if( !anApp )
1852     return false;
1853
1854   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1855   SUIT_ResourceMgr* mgr = resourceMgr();
1856   if( !mgr )
1857     return false;
1858
1859   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1860     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1861   }
1862
1863   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1864   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1865
1866   //QAction* act = action( theCommandID );
1867
1868   switch (theCommandID) {
1869   case 33:                                      // DELETE
1870     if(checkLock(aStudy)) break;
1871     OnEditDelete();
1872     break;
1873
1874   case 113:                                     // IMPORT
1875   case 112:
1876   case 111:
1877   case 140:
1878     {
1879       if(checkLock(aStudy)) break;
1880       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1881       break;
1882     }
1883
1884   case 150:    //MED FILE INFORMATION
1885     {
1886       SALOME_ListIO selected;
1887       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1888       if( aSel )
1889         aSel->selectedObjects( selected );
1890       if( selected.Extent() )
1891       {
1892         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1893         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1894         if ( !aMesh->_is_nil() )
1895         {
1896           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
1897           dlg.exec();
1898         }
1899       }
1900       break;
1901     }
1902
1903   case 122:                                     // EXPORT MED
1904   case 121:
1905   case 123:
1906   case 124:
1907   case 125:
1908   case 126:
1909   case 141:
1910     {
1911       ::ExportMeshToFile(theCommandID);
1912       break;
1913     }
1914
1915   case 200:                                     // SCALAR BAR
1916     {
1917       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1918       SALOME_ListIO selected;
1919       if( aSel )
1920         aSel->selectedObjects( selected );
1921
1922       if( selected.Extent() ) {
1923         Handle(SALOME_InteractiveObject) anIO = selected.First();
1924         if( anIO->hasEntry() ) {
1925           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1926             anActor->SetControlMode( SMESH_Actor::eNone );
1927 #ifndef DISABLE_PLOT2DVIEWER
1928             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
1929 #endif
1930           }
1931         }
1932       }
1933       break;
1934     }
1935   case 201:
1936     {
1937       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1938       break;
1939     }
1940   case 2021:
1941     {
1942       // dump control distribution data to the text file
1943       ::SaveDistribution();
1944       break;
1945     }
1946
1947   case 2022:
1948     {
1949       // show/ distribution
1950       ::ShowDistribution();
1951       break;
1952     }
1953
1954 #ifndef DISABLE_PLOT2DVIEWER
1955   case 2023:
1956     {
1957       // plot distribution
1958       ::PlotDistribution();
1959       break;
1960     }
1961 #endif
1962
1963     // Auto-color
1964   case 1136:
1965     ::AutoColor();
1966   break;
1967
1968   case 1137:
1969     ::DisableAutoColor();
1970   break;
1971
1972   case 1134: // Clipping
1973   case 1133: // Tranparency
1974   case 1132: // Colors / Size
1975
1976     // Display Mode
1977   case 215: // Nodes
1978   case 213: // Nodes
1979   case 212: // Nodes
1980   case 211: // Nodes
1981     ::SetDisplayMode(theCommandID, myMarkerMap);
1982   break;
1983
1984   //2D quadratic representation
1985   case 231:
1986   case 232:
1987     ::SetDisplayMode(theCommandID, myMarkerMap);
1988   break;
1989
1990   // Display Entity
1991   case 216: // 0D elements
1992   case 217: // Edges
1993   case 218: // Faces
1994   case 219: // Volumes
1995   case 220: // All Entity
1996     ::SetDisplayEntity(theCommandID);
1997   break;
1998
1999   case 221: // Orientation of faces
2000     {
2001       LightApp_SelectionMgr* mgr = selectionMgr();
2002       SALOME_ListIO selected; mgr->selectedObjects( selected );
2003
2004       SALOME_ListIteratorOfListIO it(selected);
2005       for( ; it.More(); it.Next()) {
2006         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2007         if(anIObject->hasEntry()) {
2008           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2009             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2010           }
2011         }
2012       }
2013       break;
2014     }
2015
2016   case 214:                                     // UPDATE
2017     {
2018       if(checkLock(aStudy)) break;
2019       try {
2020 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2021         OCC_CATCH_SIGNALS;
2022 #endif
2023         SMESH::UpdateView();
2024       }
2025       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2026         SMESH::OnVisuException();
2027       }
2028       catch (...) { // PAL16774 (Crash after display of many groups)
2029         SMESH::OnVisuException();
2030       }
2031
2032       SALOME_ListIO l;
2033       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2034       aSel->selectedObjects( l );
2035       aSel->setSelectedObjects( l );
2036       break;
2037     }
2038
2039   case 300:                                     // ERASE
2040   case 301:                                     // DISPLAY
2041   case 302:                                     // DISPLAY ONLY
2042     {
2043       SMESH::EDisplaing anAction;
2044       switch (theCommandID) {
2045       case 300: anAction = SMESH::eErase; break;
2046       case 301: anAction = SMESH::eDisplay; break;
2047       case 302: anAction = SMESH::eDisplayOnly; break;
2048       }
2049
2050       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2051       SALOME_ListIO sel_objects, to_process;
2052       if (aSel)
2053         aSel->selectedObjects( sel_objects );
2054
2055       if( theCommandID==302 )
2056       {
2057         MESSAGE("anAction = SMESH::eDisplayOnly");
2058         startOperation( myEraseAll );
2059       }
2060
2061       extractContainers( sel_objects, to_process );
2062
2063       try {
2064 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2065         OCC_CATCH_SIGNALS;
2066 #endif
2067         if (vtkwnd) {
2068           SALOME_ListIteratorOfListIO It( to_process );
2069           for ( ; It.More(); It.Next()) {
2070                 MESSAGE("---");
2071             Handle(SALOME_InteractiveObject) IOS = It.Value();
2072             if (IOS->hasEntry()) {
2073                 MESSAGE("---");
2074               if (!SMESH::UpdateView(anAction, IOS->getEntry())) {
2075                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2076                 break; // PAL16774 (Crash after display of many groups)
2077               }
2078               if (anAction == SMESH::eDisplayOnly)
2079               {
2080                 MESSAGE("anAction = SMESH::eDisplayOnly");
2081                 anAction = SMESH::eDisplay;
2082               }
2083             }
2084           }
2085         }
2086
2087         // PAL13338 + PAL15161 -->
2088         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy)) {
2089                 MESSAGE("anAction = SMESH::eDisplayOnly");
2090           SMESH::UpdateView();
2091           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2092         }
2093         // PAL13338 + PAL15161 <--
2094       }
2095       catch (...) { // PAL16774 (Crash after display of many groups)
2096         SMESH::OnVisuException();
2097       }
2098
2099       if (anAction == SMESH::eErase) {
2100         MESSAGE("anAction == SMESH::eErase");
2101         SALOME_ListIO l1;
2102         aSel->setSelectedObjects( l1 );
2103       }
2104       else
2105         aSel->setSelectedObjects( to_process );
2106
2107       break;
2108     }
2109
2110   case 4000:                                    // NODES
2111     {
2112       if(checkLock(aStudy)) break;
2113
2114       if ( vtkwnd ) {
2115         EmitSignalDeactivateDialog();
2116
2117         ( new SMESHGUI_NodesDlg( this ) )->show();
2118       }
2119       else {
2120         SUIT_MessageBox::warning(desktop(),
2121                                  tr("SMESH_WRN_WARNING"),
2122                                  tr("SMESH_WRN_VIEWER_VTK"));
2123       }
2124       break;
2125     }
2126
2127   case 2151:  // FILTER
2128   {
2129     if ( vtkwnd )
2130     {
2131       EmitSignalDeactivateDialog();
2132       ( new SMESHGUI_FilterDlg( this, SMESH::EDGE ) )->show();
2133     }
2134     break;
2135   }
2136
2137   case 701:                                     // COMPUTE MESH
2138   case 711:                                     // PRECOMPUTE MESH
2139   case 712:                                     // EVALUATE MESH
2140   case 713:                                     // MESH ORDER
2141     {
2142       if (checkLock(aStudy)) break;
2143       startOperation( theCommandID );
2144     }
2145     break;
2146
2147   case 702: // Create mesh
2148   case 703: // Create sub-mesh
2149   case 704: // Edit mesh/sub-mesh
2150     startOperation( theCommandID );
2151     break;
2152   case 705: // copy mesh
2153     {
2154       if (checkLock(aStudy)) break;
2155       EmitSignalDeactivateDialog();
2156       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2157     }
2158     break;
2159   case 710: // Build compound mesh
2160     {
2161       if (checkLock(aStudy)) break;
2162       EmitSignalDeactivateDialog();
2163       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2164     }
2165     break;
2166
2167   case 407: // DIAGONAL INVERSION
2168   case 408: // Delete diagonal
2169     {
2170       if ( !vtkwnd )
2171       {
2172         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2173                                   tr( "NOT_A_VTK_VIEWER" ) );
2174         break;
2175       }
2176
2177       if ( checkLock( aStudy ) )
2178         break;
2179
2180       /*Standard_Boolean aRes;
2181       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2182       if ( aMesh->_is_nil() )
2183       {
2184         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2185           tr( "SMESH_BAD_SELECTION" ) );
2186         break;
2187       }
2188       */
2189       EmitSignalDeactivateDialog();
2190       if ( theCommandID == 407 )
2191         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2192       else
2193         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2194       break;
2195     }
2196   case 409: // Change orientation
2197   case 410: // Union of triangles
2198   case 411: // Cutting of quadrangles
2199   case 419: // Splitting volumes into tetrahedra
2200     {
2201       if ( !vtkwnd )
2202       {
2203         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2204                                   tr( "NOT_A_VTK_VIEWER" ) );
2205         break;
2206       }
2207
2208       if ( checkLock( aStudy ) )
2209         break;
2210
2211       EmitSignalDeactivateDialog();
2212       SMESHGUI_MultiEditDlg* aDlg = NULL;
2213       if ( theCommandID == 409 )
2214         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2215       else if ( theCommandID == 410 )
2216         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2217       else if ( theCommandID == 419 )
2218         aDlg = new SMESHGUI_CuttingIntoTetraDlg(this);
2219       else
2220         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2221
2222       aDlg->show();
2223       break;
2224     }
2225   case 412: // Smoothing
2226     {
2227       if(checkLock(aStudy)) break;
2228       if( vtkwnd ) {
2229         EmitSignalDeactivateDialog();
2230         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2231       }
2232       else {
2233         SUIT_MessageBox::warning(desktop(),
2234                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2235       }
2236       break;
2237     }
2238   case 413: // Extrusion
2239     {
2240       if (checkLock(aStudy)) break;
2241       if (vtkwnd) {
2242         EmitSignalDeactivateDialog();
2243         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2244       } else {
2245         SUIT_MessageBox::warning(desktop(),
2246                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2247       }
2248       break;
2249     }
2250   case 414: // Revolution
2251     {
2252       if(checkLock(aStudy)) break;
2253       if( vtkwnd ) {
2254         EmitSignalDeactivateDialog();
2255         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2256       }
2257       else {
2258         SUIT_MessageBox::warning(desktop(),
2259                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2260       }
2261       break;
2262     }
2263   case 415: // Pattern mapping
2264     {
2265       if ( checkLock( aStudy ) )
2266         break;
2267       if ( vtkwnd )
2268       {
2269         EmitSignalDeactivateDialog();
2270         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2271       }
2272       else {
2273         SUIT_MessageBox::warning(desktop(),
2274                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2275       }
2276       break;
2277     }
2278   case 416: // Extrusion along a path
2279     {
2280       if (checkLock(aStudy)) break;
2281       if (vtkwnd) {
2282         EmitSignalDeactivateDialog();
2283         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2284       } else {
2285         SUIT_MessageBox::warning(desktop(),
2286                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2287       }
2288       break;
2289     }
2290   case 417: // Convert mesh to quadratic
2291     {
2292     startOperation( 417 );
2293       /*      if (checkLock(aStudy)) break;
2294       if (vtkwnd) {
2295         EmitSignalDeactivateDialog();
2296         new SMESHGUI_ConvToQuadDlg();
2297       } else {
2298         SUIT_MessageBox::warning(desktop(),
2299                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2300                                }*/
2301       break;
2302     }
2303   case 418: // create 2D mesh from 3D
2304     {
2305       startOperation( 418 );
2306       break;
2307     }
2308   case 806:                                     // CREATE GEO GROUP
2309     {
2310       startOperation( 806 );
2311       break;
2312     }
2313   case 801:                                     // CREATE GROUP
2314     {
2315       if ( !vtkwnd )
2316       {
2317         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2318                                   tr( "NOT_A_VTK_VIEWER" ) );
2319         break;
2320       }
2321
2322       if(checkLock(aStudy)) break;
2323       EmitSignalDeactivateDialog();
2324       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2325
2326       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2327       SALOME_ListIO selected;
2328       if( aSel )
2329         aSel->selectedObjects( selected );
2330
2331       int nbSel = selected.Extent();
2332       if (nbSel == 1) {
2333         // check if mesh is selected
2334         aMesh = SMESH::GetMeshByIO( selected.First() );
2335       }
2336       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2337       aDlg->show();
2338       break;
2339     }
2340
2341   case 802:                                     // CONSTRUCT GROUP
2342     {
2343       if ( !vtkwnd )
2344       {
2345         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2346                                   tr( "NOT_A_VTK_VIEWER" ) );
2347         break;
2348       }
2349
2350       if(checkLock(aStudy)) break;
2351       EmitSignalDeactivateDialog();
2352
2353       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2354       SALOME_ListIO selected;
2355       if( aSel )
2356         aSel->selectedObjects( selected );
2357
2358       int nbSel = selected.Extent();
2359       if (nbSel == 1) {
2360         // check if submesh is selected
2361         Handle(SALOME_InteractiveObject) IObject = selected.First();
2362         if (IObject->hasEntry()) {
2363           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2364           if( aSObj ) {
2365             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2366             if (!aSubMesh->_is_nil()) {
2367               try {
2368                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2369                 // get submesh elements list by types
2370                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2371                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2372                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2373                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2374                 // create group for each type o elements
2375                 QString aName = IObject->getName();
2376                 if (aNodes->length() > 0) {
2377                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2378                   aGroup->Add(aNodes.inout());
2379                 }
2380                 if (aEdges->length() > 0) {
2381                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2382                   aGroup->Add(aEdges.inout());
2383                 }
2384                 if (aFaces->length() > 0) {
2385                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2386                   aGroup->Add(aFaces.inout());
2387                 }
2388                 if (aVolumes->length() > 0) {
2389                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2390                   aGroup->Add(aVolumes.inout());
2391                 }
2392                 updateObjBrowser();
2393
2394               }
2395               catch(const SALOME::SALOME_Exception & S_ex){
2396                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2397               }
2398             }
2399           }
2400         }
2401       }
2402       else if(nbSel==0) {
2403         SUIT_MessageBox::warning(desktop(),
2404                                  tr("SMESH_WRN_WARNING"),
2405                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2406       }
2407       break;
2408     }
2409
2410   case 803:                                     // EDIT GROUP
2411     {
2412       if ( !vtkwnd )
2413       {
2414         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2415                                   tr( "NOT_A_VTK_VIEWER" ) );
2416         break;
2417       }
2418
2419       if(checkLock(aStudy)) break;
2420       EmitSignalDeactivateDialog();
2421
2422       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2423       SALOME_ListIO selected;
2424       if( aSel )
2425         aSel->selectedObjects( selected );
2426
2427       SALOME_ListIteratorOfListIO It (selected);
2428       int nbSelectedGroups = 0;
2429       for ( ; It.More(); It.Next() )
2430       {
2431         SMESH::SMESH_GroupBase_var aGroup =
2432           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
2433         if (!aGroup->_is_nil()) {
2434           nbSelectedGroups++;
2435           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
2436           aDlg->show();
2437         }
2438       }
2439       if (nbSelectedGroups == 0)
2440         {
2441           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
2442           aDlg->show();
2443         }
2444       break;
2445     }
2446
2447   case 804:                                     // Add elements to group
2448     {
2449       if(checkLock(aStudy)) break;
2450       if (myState == 800) {
2451         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2452         if (aDlg) aDlg->onAdd();
2453       }
2454       break;
2455     }
2456
2457   case 805:                                     // Remove elements from group
2458     {
2459       if(checkLock(aStudy)) break;
2460       if (myState == 800) {
2461         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2462         if (aDlg) aDlg->onRemove();
2463       }
2464       break;
2465     }
2466
2467   case 815:                                     // Edit GEOM GROUP as standalone
2468     {
2469       if ( !vtkwnd )
2470       {
2471         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2472                                   tr( "NOT_A_VTK_VIEWER" ) );
2473         break;
2474       }
2475
2476       if(checkLock(aStudy)) break;
2477       EmitSignalDeactivateDialog();
2478
2479       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2480       SALOME_ListIO selected;
2481       if( aSel )
2482         aSel->selectedObjects( selected );
2483
2484       SALOME_ListIteratorOfListIO It (selected);
2485       for ( ; It.More(); It.Next() )
2486       {
2487         SMESH::SMESH_GroupOnGeom_var aGroup =
2488           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
2489         if (!aGroup->_is_nil()) {
2490           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
2491           aDlg->show();
2492         }
2493       }
2494       break;
2495     }
2496
2497     case 810: // Union Groups
2498     case 811: // Intersect groups
2499     case 812: // Cut groups
2500     {
2501       if ( !vtkwnd )
2502       {
2503         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2504                                   tr( "NOT_A_VTK_VIEWER" ) );
2505         break;
2506       }
2507
2508       if ( checkLock( aStudy ) )
2509         break;
2510
2511       EmitSignalDeactivateDialog();
2512
2513       SMESHGUI_GroupOpDlg* aDlg = 0;
2514       if ( theCommandID == 810 )
2515         aDlg = new SMESHGUI_UnionGroupsDlg( this );
2516       else if ( theCommandID == 811 )
2517         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
2518       else
2519         aDlg = new SMESHGUI_CutGroupsDlg( this );
2520
2521       aDlg->show();
2522
2523       break;
2524     }
2525
2526     case 814: // Create groups of entities from existing groups of superior dimensions
2527     {
2528       if ( checkLock( aStudy ) )
2529         break;
2530
2531       EmitSignalDeactivateDialog();
2532       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
2533       aDlg->show();
2534
2535       break;
2536     }
2537
2538     case 813: // Delete groups with their contents
2539     {
2540       if ( !vtkwnd )
2541       {
2542         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2543                                   tr( "NOT_A_VTK_VIEWER" ) );
2544         break;
2545       }
2546
2547       if ( checkLock( aStudy ) )
2548         break;
2549
2550       EmitSignalDeactivateDialog();
2551
2552       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
2553       break;
2554     }
2555
2556   case 900:                                     // MESH INFOS
2557   case 903:                                     // WHAT IS
2558     {
2559       int page = theCommandID == 900 ? SMESHGUI_MeshInfoDlg::BaseInfo : SMESHGUI_MeshInfoDlg::ElemInfo;
2560       EmitSignalDeactivateDialog();
2561       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2562       SALOME_ListIO selected;
2563       if( aSel )
2564         aSel->selectedObjects( selected );
2565
2566       if ( selected.Extent() > 1 ) { // a dlg for each IO
2567         SALOME_ListIteratorOfListIO It( selected );
2568         for ( ; It.More(); It.Next() ) {
2569           SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
2570           dlg->showInfo( It.Value() ); 
2571           dlg->show();
2572         }
2573       }
2574       else {
2575         SMESHGUI_MeshInfoDlg* dlg = new SMESHGUI_MeshInfoDlg( SMESHGUI::desktop(), page );
2576         dlg->show();
2577       }
2578       break;
2579     }
2580     /*
2581   case 902:                                     // STANDARD MESH INFOS
2582     {
2583       EmitSignalDeactivateDialog();
2584       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2585       SALOME_ListIO selected;
2586       if( aSel )
2587         aSel->selectedObjects( selected );
2588
2589       if ( selected.Extent() > 1 ) { // a dlg for each IO
2590         SALOME_ListIO IOs;
2591         SALOME_ListIteratorOfListIO It (selected);
2592         for ( ; It.More(); It.Next() ) {
2593           IOs.Clear();
2594           IOs.Append( It.Value() );
2595           aSel->setSelectedObjects( IOs );
2596           ( new SMESHGUI_StandardMeshInfosDlg( this ) )->show();
2597         }
2598         // restore selection
2599         aSel->setSelectedObjects( selected );
2600       }
2601       else
2602         ( new SMESHGUI_StandardMeshInfosDlg( this ) )->show();
2603       break;
2604     }
2605   case 903:                                     // WHAT IS
2606     {
2607       EmitSignalDeactivateDialog();
2608       ( new SMESHGUI_WhatIsDlg( this ) )->show();
2609       break;
2610     }
2611     */
2612
2613   case 904:                                     // FIND ELEM
2614     {
2615       startOperation( theCommandID );
2616       break;
2617     }
2618
2619   case 1100:                                    // EDIT HYPOTHESIS
2620     {
2621       if(checkLock(aStudy)) break;
2622
2623       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2624       SALOME_ListIO selected;
2625       if( aSel )
2626         aSel->selectedObjects( selected );
2627
2628       int nbSel = selected.Extent();
2629
2630       if (nbSel == 1) {
2631         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2632         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
2633
2634         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2635         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2636         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2637         if ( !aHypothesis->_is_nil() )
2638         {
2639           // BUG 0020378
2640           //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2641           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2642           if (aCreator) {
2643             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
2644           }
2645           else
2646           {
2647             // report error
2648           }
2649         }
2650       }
2651       break;
2652     }
2653
2654   case 1101:                                    // RENAME
2655     {
2656       if ( checkLock( aStudy ) )
2657         break;
2658
2659       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2660       SALOME_ListIO selected;
2661       if( aSel )
2662         aSel->selectedObjects( selected );
2663
2664       bool isAny = false; // is there any appropriate object selected
2665
2666       SALOME_ListIteratorOfListIO It( selected );
2667       for ( ; It.More(); It.Next() )
2668       {
2669         Handle(SALOME_InteractiveObject) IObject = It.Value();
2670         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
2671         _PTR(GenericAttribute) anAttr;
2672         _PTR(AttributeName) aName;
2673         if ( obj )
2674         {
2675           if ( obj->FindAttribute(anAttr, "AttributeName") )
2676           {
2677             aName = anAttr;
2678             QString newName = QString(aName->Value().c_str());
2679
2680             // check type to prevent renaming of inappropriate objects
2681             int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
2682             if (aType == MESH || aType == GROUP ||
2683                 aType == SUBMESH || aType == SUBMESH_COMPOUND ||
2684                 aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
2685                 aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
2686                 aType == HYPOTHESIS || aType == ALGORITHM)
2687             {
2688               isAny = true;
2689               newName = LightApp_NameDlg::getName(desktop(), newName);
2690               if ( !newName.isEmpty() )
2691               {
2692                 SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), newName.toLatin1().data());
2693
2694                 // update name of group object and its actor
2695                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
2696                 if( !aGroupObject->_is_nil() )
2697                 {
2698                   aGroupObject->SetName( newName.toLatin1().data() );
2699                   if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( IObject->getEntry() ) )
2700                     anActor->setName( newName.toLatin1().data() );
2701                 }
2702
2703                 updateObjBrowser();
2704               }
2705             }
2706           }
2707         }
2708       } // for
2709
2710       if (!isAny) {
2711         SUIT_MessageBox::warning(desktop(),
2712                                  QObject::tr("SMESH_WRN_WARNING"),
2713                                  QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"));
2714       }
2715       break;
2716     }
2717
2718   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2719     {
2720       if(checkLock(aStudy)) break;
2721       SUIT_OverrideCursor wc;
2722
2723       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2724       SALOME_ListIO selected;
2725       if( aSel )
2726         aSel->selectedObjects( selected, QString::null, false );
2727
2728       SALOME_ListIteratorOfListIO It(selected);
2729       for (int i = 0; It.More(); It.Next(), i++) {
2730         Handle(SALOME_InteractiveObject) IObject = It.Value();
2731         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2732       }
2733       SALOME_ListIO l1;
2734       aSel->setSelectedObjects( l1 );
2735       updateObjBrowser();
2736       break;
2737     }
2738
2739   case 4009:                                    // ELEM0D
2740   case 4010:                                    // GEOM::EDGE
2741   case 4021:                                    // TRIANGLE
2742   case 4022:                                    // QUAD
2743   case 4023:                                    // POLYGON
2744   case 4031:                                    // TETRA
2745   case 4032:                                    // HEXA
2746     {
2747       if(checkLock(aStudy)) break;
2748       if ( vtkwnd ) {
2749         EmitSignalDeactivateDialog();
2750         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2751         int                 nbNodes = 2;
2752         switch (theCommandID) {
2753         case 4009:                                      // ELEM0D
2754           type = SMDSAbs_0DElement; nbNodes = 1; break;
2755         case 4021:                                      // TRIANGLE
2756           type = SMDSAbs_Face; nbNodes = 3; break;
2757         case 4022:                                      // QUAD
2758           type = SMDSAbs_Face; nbNodes = 4; break;
2759         case 4031:                                      // TETRA
2760           type = SMDSAbs_Volume; nbNodes = 4; break;
2761         case 4023:                                      // POLYGON
2762           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2763         case 4032:                                      // HEXA
2764           type = SMDSAbs_Volume; nbNodes = 8; break;
2765         case 4033:                                      // POLYHEDRE
2766           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2767         default:;
2768         }
2769         ( new SMESHGUI_AddMeshElementDlg( this, type, nbNodes ) )->show();
2770       }
2771       else {
2772         SUIT_MessageBox::warning(desktop(),
2773                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2774       }
2775       break;
2776     }
2777   case 4033:                                    // POLYHEDRON
2778     {
2779       if(checkLock(aStudy)) break;
2780       if ( vtkwnd ) {
2781         EmitSignalDeactivateDialog();
2782         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
2783       }
2784       else {
2785         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2786                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2787       }
2788       break;
2789     }
2790   case 4034:     // QUADRATIC EDGE
2791   case 4035:     // QUADRATIC TRIANGLE
2792   case 4036:     // QUADRATIC QUADRANGLE
2793   case 4037:     // QUADRATIC TETRAHEDRON
2794   case 4038:     // QUADRATIC PYRAMID
2795   case 4039:     // QUADRATIC PENTAHEDRON
2796   case 4040:     // QUADRATIC HEXAHEDRON
2797     {
2798       if(checkLock(aStudy)) break;
2799       if ( vtkwnd ) {
2800         EmitSignalDeactivateDialog();
2801         int type;
2802
2803         switch (theCommandID) {
2804         case 4034:
2805           type = QUAD_EDGE; break;
2806         case 4035:
2807           type = QUAD_TRIANGLE; break;
2808         case 4036:
2809           type = QUAD_QUADRANGLE; break;
2810         case 4037:
2811           type = QUAD_TETRAHEDRON; break;
2812         case 4038:
2813           type = QUAD_PYRAMID; break;
2814         case 4039:
2815           type = QUAD_PENTAHEDRON; break;
2816         case 4040:
2817           type = QUAD_HEXAHEDRON;
2818           break;
2819         default:;
2820         }
2821          ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
2822       }
2823       else {
2824         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2825                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2826       }
2827       break;
2828     }
2829   case 4041:                                    // REMOVES NODES
2830     {
2831       if(checkLock(aStudy)) break;
2832       if ( vtkwnd ) {
2833         EmitSignalDeactivateDialog();
2834         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
2835       }
2836       else {
2837         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2838                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2839       }
2840       break;
2841     }
2842   case 4042:                                    // REMOVES ELEMENTS
2843     {
2844       if(checkLock(aStudy)) break;
2845       if( vtkwnd ) {
2846         EmitSignalDeactivateDialog();
2847         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
2848       }
2849       else
2850         {
2851           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2852                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2853         }
2854       break;
2855     }
2856   case 4043: {                                // CLEAR_MESH
2857
2858     if(checkLock(aStudy)) break;
2859
2860     SALOME_ListIO selected;
2861     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2862       aSel->selectedObjects( selected );
2863
2864     SUIT_OverrideCursor wc;
2865     SALOME_ListIteratorOfListIO It (selected);
2866     for ( ; It.More(); It.Next() )
2867     {
2868       Handle(SALOME_InteractiveObject) IOS = It.Value();
2869       SMESH::SMESH_Mesh_var aMesh =
2870         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2871       if ( aMesh->_is_nil()) continue;
2872       try {
2873         SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
2874         aMesh->Clear();
2875         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
2876         SMESH::ModifiedMesh( aMeshSObj, false, true);
2877         // hide groups and submeshes
2878         _PTR(ChildIterator) anIter =
2879           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
2880         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
2881         {
2882           _PTR(SObject) so = anIter->Value();
2883           SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
2884         }
2885       }
2886       catch (const SALOME::SALOME_Exception& S_ex){
2887         wc.suspend();
2888         SalomeApp_Tools::QtCatchCorbaException(S_ex);
2889         wc.resume();
2890       }
2891     }
2892     SMESH::UpdateView();
2893     updateObjBrowser();
2894     break;
2895   }
2896   case 4044:                                     // REMOVE ORPHAN NODES
2897     {
2898       if(checkLock(aStudy)) break;
2899       SALOME_ListIO selected;
2900       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2901         aSel->selectedObjects( selected );
2902       if ( selected.Extent() == 1 ) {
2903         Handle(SALOME_InteractiveObject) anIO = selected.First();
2904         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
2905         if ( !aMesh->_is_nil() ) {
2906           bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
2907                                                     tr( "SMESH_WARNING" ),
2908                                                     tr( "REMOVE_ORPHAN_NODES_QUESTION"),
2909                                                     SUIT_MessageBox::Yes |
2910                                                     SUIT_MessageBox::No,
2911                                                     SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
2912           if( confirm ) {
2913             try {
2914               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
2915               int removed = aMeshEditor->RemoveOrphanNodes();
2916               SUIT_MessageBox::information(SMESHGUI::desktop(),
2917                                            tr("SMESH_INFORMATION"),
2918                                            tr("NB_NODES_REMOVED").arg(removed));
2919               if ( removed > 0 ) {
2920                 SMESH::UpdateView();
2921                 SMESHGUI::Modified();
2922               }
2923             }
2924             catch (const SALOME::SALOME_Exception& S_ex) {
2925               SalomeApp_Tools::QtCatchCorbaException(S_ex);
2926             } 
2927             catch (...) {
2928             }
2929           }
2930         }
2931       }
2932       break;
2933     }
2934   case 4051:                                    // RENUMBERING NODES
2935     {
2936       if(checkLock(aStudy)) break;
2937       if( vtkwnd ) {
2938         EmitSignalDeactivateDialog();
2939         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
2940       }
2941       else
2942         {
2943           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2944                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2945         }
2946       break;
2947     }
2948   case 4052:                                    // RENUMBERING ELEMENTS
2949     {
2950       if(checkLock(aStudy)) break;
2951       if ( vtkwnd ) {
2952         EmitSignalDeactivateDialog();
2953         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
2954       }
2955       else
2956         {
2957           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2958                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2959         }
2960       break;
2961     }
2962   case 4061:                                   // TRANSLATION
2963     {
2964       if(checkLock(aStudy)) break;
2965       if ( vtkwnd ) {
2966         EmitSignalDeactivateDialog();
2967         ( new SMESHGUI_TranslationDlg( this ) )->show();
2968       }
2969       else {
2970         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2971                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2972       }
2973       break;
2974     }
2975   case 4062:                                   // ROTATION
2976     {
2977       if(checkLock(aStudy)) break;
2978       if( vtkwnd ) {
2979         EmitSignalDeactivateDialog();
2980         ( new SMESHGUI_RotationDlg( this ) )->show();
2981       }
2982       else {
2983         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2984                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2985       }
2986       break;
2987     }
2988   case 4063:                                   // SYMMETRY
2989     {
2990       if(checkLock(aStudy)) break;
2991       if(vtkwnd) {
2992         EmitSignalDeactivateDialog();
2993         ( new SMESHGUI_SymmetryDlg( this ) )->show();
2994       }
2995       else {
2996         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2997                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2998       }
2999       break;
3000     }
3001   case 4064:                                   // SEWING
3002     {
3003       if(checkLock(aStudy)) break;
3004       if(vtkwnd) {
3005         EmitSignalDeactivateDialog();
3006         ( new SMESHGUI_SewingDlg( this ) )->show();
3007       }
3008       else {
3009         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3010                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3011       }
3012       break;
3013     }
3014   case 4065:                                   // MERGE NODES
3015     {
3016       if(checkLock(aStudy)) break;
3017       if(vtkwnd) {
3018         EmitSignalDeactivateDialog();
3019         ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
3020       }
3021       else {
3022         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3023                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3024       }
3025       break;
3026     }
3027   case 4066:                                   // MERGE EQUAL ELEMENTS
3028     {
3029       if (checkLock(aStudy)) break;
3030       if (vtkwnd) {
3031         EmitSignalDeactivateDialog();
3032         ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
3033       } else {
3034         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3035                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3036       }
3037       break;
3038     }
3039
3040   case 4067: // MAKE MESH PASS THROUGH POINT
3041     startOperation( 4067 );
3042     break;
3043
3044   case 4068: // SCALE
3045     {
3046       if(checkLock(aStudy)) break;
3047       if ( vtkwnd ) {
3048         EmitSignalDeactivateDialog();
3049         ( new SMESHGUI_ScaleDlg( this ) )->show();
3050       }
3051       else {
3052         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3053                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3054       }
3055       break;
3056     }
3057
3058   case 4069: // DUPLICATE NODES
3059     {
3060       if(checkLock(aStudy)) break;
3061       if ( vtkwnd ) {
3062         EmitSignalDeactivateDialog();
3063         ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
3064       }
3065       else {
3066         SUIT_MessageBox::warning(SMESHGUI::desktop(),
3067                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
3068       }
3069       break;
3070     }
3071
3072   case 5105: // Library of selection filters
3073   {
3074     static QList<int> aTypes;
3075     if ( aTypes.isEmpty() )
3076     {
3077       aTypes.append( SMESH::NODE );
3078       aTypes.append( SMESH::EDGE );
3079       aTypes.append( SMESH::FACE );
3080       aTypes.append( SMESH::VOLUME );
3081     }
3082     if (!myFilterLibraryDlg)
3083       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3084     else if (myFilterLibraryDlg->isHidden())
3085       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
3086     myFilterLibraryDlg->raise();
3087   }
3088   break;
3089
3090   case 6017:                                    // CONTROLS
3091   case 6016:
3092   case 6015:
3093   case 6014:
3094   case 6013:
3095   case 6012:
3096   case 6011:
3097   case 6001:
3098   case 6018:
3099   case 6019:
3100   case 6002:
3101   case 6003:
3102   case 6004:
3103   case 6005:
3104   case 6009:
3105   case 6021:
3106   case 6022:
3107   case 6023:
3108   case 6024:
3109   case 6025:
3110   case 6026:
3111   case 6027:
3112     if ( vtkwnd ) {
3113
3114       LightApp_SelectionMgr* mgr = selectionMgr();
3115       SALOME_ListIO selected; mgr->selectedObjects( selected );
3116
3117       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
3118         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
3119         if ( SO ) {
3120           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
3121           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
3122           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
3123           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
3124           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
3125             ::Control( theCommandID );
3126             break;
3127           }
3128         }
3129       }
3130       SUIT_MessageBox::warning(desktop(),
3131                                tr( "SMESH_WRN_WARNING" ),
3132                                tr( "SMESH_BAD_SELECTION" ) );
3133       break;
3134     }
3135     else {
3136       SUIT_MessageBox::warning(desktop(),
3137                                tr( "SMESH_WRN_WARNING" ),
3138                                tr( "NOT_A_VTK_VIEWER" ) );
3139     }
3140     break;
3141   case 9010:
3142     {
3143       LightApp_SelectionMgr* mgr = selectionMgr();
3144       SALOME_ListIO selected; mgr->selectedObjects( selected );
3145
3146       SALOME_ListIteratorOfListIO it(selected);
3147       for( ; it.More(); it.Next()) {
3148         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3149         if(anIObject->hasEntry()) {
3150           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3151             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3152           }
3153         }
3154       }
3155       break;
3156     }
3157   case 9011:
3158     {
3159       LightApp_SelectionMgr* mgr = selectionMgr();
3160       SALOME_ListIO selected; mgr->selectedObjects( selected );
3161
3162       SALOME_ListIteratorOfListIO it(selected);
3163       for( ; it.More(); it.Next()) {
3164         Handle(SALOME_InteractiveObject) anIObject = it.Value();
3165         if(anIObject->hasEntry())
3166           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
3167             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3168           }
3169       }
3170       break;
3171     }
3172   case 501:
3173   case 502:
3174     {
3175       int page = theCommandID == 501 ? SMESHGUI_MeasureDlg::MinDistance : SMESHGUI_MeasureDlg::BoundingBox;
3176       EmitSignalDeactivateDialog();
3177       SMESHGUI_MeasureDlg* dlg = new SMESHGUI_MeasureDlg( SMESHGUI::desktop(), page );
3178       dlg->show();
3179       break;
3180     }
3181   }
3182
3183   anApp->updateActions(); //SRN: To update a Save button in the toolbar
3184   //updateObjBrowser();
3185   return true;
3186 }
3187
3188 //=============================================================================
3189 /*!
3190  *
3191  */
3192 //=============================================================================
3193 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3194 {
3195   return false;
3196 }
3197
3198 //=============================================================================
3199 /*!
3200  *
3201  */
3202 //=============================================================================
3203 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
3204 {
3205   return true;
3206 }
3207
3208 //=============================================================================
3209 /*!
3210  *
3211  */
3212 //=============================================================================
3213 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
3214 {
3215   return true;
3216 }
3217
3218 //=============================================================================
3219 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3220  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3221  */
3222 //=============================================================================
3223 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
3224                                   SUIT_ViewWindow* wnd )
3225 {
3226   if(theIO->hasEntry()){
3227     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
3228     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
3229   }
3230 }
3231
3232 //=======================================================================
3233 // function : createSMESHAction
3234 // purpose  :
3235 //=======================================================================
3236 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, 
3237                                   const int key, const bool toggle, const QString& shortcutAction  )
3238 {
3239   QIcon icon;
3240   QWidget* parent = application()->desktop();
3241   SUIT_ResourceMgr* resMgr = resourceMgr();
3242   QPixmap pix;
3243   if ( !icon_id.isEmpty() )
3244     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
3245   else
3246     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
3247   if ( !pix.isNull() )
3248     icon = QIcon( pix );
3249
3250   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
3251           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
3252           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
3253
3254   createAction( id, tooltip, icon, menu, status_bar, key, parent, 
3255                 toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
3256 }
3257
3258 //=======================================================================
3259 // function : createPopupItem
3260 // purpose  :
3261 //=======================================================================
3262 void SMESHGUI::createPopupItem( const int id,
3263                                 const QString& clients,
3264                                 const QString& types,
3265                                 const QString& theRule,
3266                                 const int pId )
3267 {
3268   int parentId = pId;
3269   if( pId!=-1 )
3270     parentId = popupMgr()->actionId( action( pId ) );
3271
3272   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
3273     popupMgr()->insert( action( id ), parentId, 0 );
3274
3275   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3276   QString dc = "selcount"; // VSR : insetad of QtxPopupSelection::defSelCountParam()
3277   QString rule = "(%1) and (%2) and (%3)";
3278   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
3279   if( clients.isEmpty() )
3280     rule = rule.arg( QString( "true" ) );
3281   else
3282     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
3283   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
3284   rule += theRule;
3285
3286   bool cont = myRules.contains( id );
3287   if( cont )
3288     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
3289
3290   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
3291   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
3292 }
3293
3294 //=======================================================================
3295 // function : initialize
3296 // purpose  :
3297 //=======================================================================
3298 void SMESHGUI::initialize( CAM_Application* app )
3299 {
3300   SalomeApp_Module::initialize( app );
3301
3302 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
3303 //   if ( mgr )
3304   /* Automatic Update flag */
3305 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
3306
3307   // ----- create actions --------------
3308
3309   createSMESHAction(  111, "DAT", "", (Qt::CTRL+Qt::Key_B) );
3310   createSMESHAction(  112, "UNV", "", (Qt::CTRL+Qt::Key_U) );
3311   createSMESHAction(  113, "MED", "", (Qt::CTRL+Qt::Key_M) );
3312   createSMESHAction(  114, "NUM" );
3313   createSMESHAction(  121, "DAT" );
3314   createSMESHAction(  122, "MED" );
3315   createSMESHAction(  123, "UNV" );
3316   createSMESHAction(  140, "STL" );
3317   createSMESHAction(  124, "EXPORT_DAT" );
3318   createSMESHAction(  125, "EXPORT_MED" );
3319   createSMESHAction(  126, "EXPORT_UNV" );
3320   createSMESHAction(  141, "EXPORT_STL" );
3321   createSMESHAction(  150, "FILE_INFO" );
3322   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Qt::Key_Delete );
3323   createSMESHAction( 5105, "SEL_FILTER_LIB" );
3324   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
3325   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
3326   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
3327   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
3328   createSMESHAction(  705, "COPY_MESH",       "ICON_COPY_MESH" );
3329   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
3330   createSMESHAction(  711, "PRECOMPUTE",      "ICON_PRECOMPUTE" );
3331   createSMESHAction(  712, "EVALUATE",        "ICON_COMPUTE" );
3332   createSMESHAction(  713, "MESH_ORDER",      "ICON_COMPUTE" );
3333   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_CREATE_GEO_GROUP" );
3334   createSMESHAction(  801, "CREATE_GROUP",    "ICON_CREATE_GROUP" );
3335   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
3336   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
3337   createSMESHAction(  815, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
3338   createSMESHAction(  804, "ADD" );
3339   createSMESHAction(  805, "REMOVE" );
3340   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
3341   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
3342   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
3343   createSMESHAction(  814, "UNDERLYING_ELEMS","ICON_UNDERLYING_ELEMS" );
3344   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
3345   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
3346   //createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
3347   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
3348   createSMESHAction(  904, "FIND_ELEM",       "ICON_FIND_ELEM" );
3349   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH",        0, true );
3350   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE",     0, true );
3351   createSMESHAction( 6021, "FREE_FACES",      "ICON_FREE_FACES",    0, true );
3352   createSMESHAction( 6022, "MAX_ELEMENT_LENGTH_2D", "ICON_MAX_ELEMENT_LENGTH_2D", 0, true );
3353   createSMESHAction( 6023, "MAX_ELEMENT_LENGTH_3D", "ICON_MAX_ELEMENT_LENGTH_3D", 0, true );
3354   createSMESHAction( 6024, "BARE_BORDER_VOLUME","ICON_BARE_BORDER_VOLUME", 0, true );
3355   createSMESHAction( 6025, "BARE_BORDER_FACE","ICON_BARE_BORDER_FACE", 0, true );
3356   createSMESHAction( 6026, "OVER_CONSTRAINED_VOLUME","ICON_OVER_CONSTRAINED_VOLUME", 0, true );
3357   createSMESHAction( 6027, "OVER_CONSTRAINED_FACE","ICON_OVER_CONSTRAINED_FACE", 0, true );
3358   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D",  0, true );
3359   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION",    0, true );
3360   createSMESHAction( 6005, "FREE_NODE",       "ICON_FREE_NODE",     0, true );
3361   createSMESHAction( 6011, "AREA",            "ICON_AREA",          0, true );
3362   createSMESHAction( 6012, "TAPER",           "ICON_TAPER",         0, true );
3363   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT",        0, true );
3364   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE",         0, true );
3365   createSMESHAction( 6015, "WARP",            "ICON_WARP",          0, true );
3366   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
3367   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
3368   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
3369   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
3370   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
3371   createSMESHAction( 4000, "NODE",            "ICON_DLG_NODE" );
3372   createSMESHAction( 4009, "ELEM0D",          "ICON_DLG_ELEM0D" );
3373   createSMESHAction( 4010, "EDGE",            "ICON_DLG_EDGE" );
3374   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
3375   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
3376   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
3377   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
3378   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
3379   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
3380   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
3381   createSMESHAction( 4044, "REMOVE_ORPHAN_NODES", "ICON_DLG_REM_ORPHAN_NODES" );
3382   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
3383   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
3384   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
3385   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
3386   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
3387   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
3388   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
3389   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
3390   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
3391   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
3392   createSMESHAction( 4068, "SCALE",           "ICON_DLG_MESH_SCALE" );
3393   createSMESHAction( 4069, "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
3394   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
3395   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
3396   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
3397   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
3398   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
3399   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
3400   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
3401   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
3402   createSMESHAction(  415, "MAP",             "ICON_MAP" );
3403   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
3404   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
3405   createSMESHAction(  418, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
3406   createSMESHAction(  419, "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
3407   createSMESHAction(  200, "RESET" );
3408   createSMESHAction(  201, "SCALAR_BAR_PROP" );
3409   createSMESHAction(  2021, "SAVE_DISTRIBUTION" );
3410   createSMESHAction(  2022, "SHOW_DISTRIBUTION","",0, true );
3411 #ifndef DISABLE_PLOT2DVIEWER
3412   createSMESHAction(  2023, "PLOT_DISTRIBUTION" );
3413 #endif
3414   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
3415   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
3416   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
3417   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
3418   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
3419   createSMESHAction(  216, "ELEMS0D",        "ICON_DLG_ELEM0D", 0, true );
3420   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
3421   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
3422   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
3423   createSMESHAction(  220, "ALL" );
3424   createSMESHAction(  221, "FACE_ORIENTATION", "", 0, true );
3425
3426   createSMESHAction(  231, "LINE_REPRESENTATION", "", 0, true );
3427   createSMESHAction(  232, "ARC_REPRESENTATION", "", 0, true );
3428
3429   createSMESHAction( 1100, "EDIT_HYPO" );
3430   createSMESHAction( 1101, "RENAME", "", Qt::Key_F2 );
3431   createSMESHAction( 1102, "UNASSIGN" );
3432   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
3433   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
3434   createSMESHAction( 1131, "DISPMODE" );
3435   createSMESHAction( 1132, "COLORS" );
3436   createSMESHAction( 1133, "TRANSP" );
3437   createSMESHAction( 1134, "CLIP" );
3438   createSMESHAction( 1135, "DISP_ENT" );
3439   createSMESHAction( 1136, "AUTO_COLOR" );
3440   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
3441   createSMESHAction( 2000, "CTRL" );
3442
3443   createSMESHAction( 501, "MEASURE_MIN_DIST", "ICON_MEASURE_MIN_DIST" );
3444   createSMESHAction( 502, "MEASURE_BND_BOX",  "ICON_MEASURE_BND_BOX" );
3445
3446   createSMESHAction( 300, "ERASE" );
3447   createSMESHAction( 301, "DISPLAY" );
3448   createSMESHAction( 302, "DISPLAY_ONLY" );
3449   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
3450   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
3451   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
3452   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
3453   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
3454   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
3455   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
3456   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
3457
3458   // ----- create menu --------------
3459   int fileId    = createMenu( tr( "MEN_FILE" ),    -1,  1 ),
3460       editId    = createMenu( tr( "MEN_EDIT" ),    -1,  3 ),
3461       toolsId   = createMenu( tr( "MEN_TOOLS" ),   -1,  5, 50 ),
3462       meshId    = createMenu( tr( "MEN_MESH" ),    -1, 70, 10 ),
3463       ctrlId    = createMenu( tr( "MEN_CTRL" ),    -1, 60, 10 ),
3464       modifyId  = createMenu( tr( "MEN_MODIFY" ),  -1, 40, 10 ),
3465       measureId = createMenu( tr( "MEN_MEASURE" ), -1, 50, 10 ),
3466       viewId    = createMenu( tr( "MEN_VIEW" ),    -1,  2 );
3467
3468   createMenu( separator(), fileId );
3469
3470   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
3471       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
3472       nodeId   = createMenu( tr( "MEN_NODE_CTRL" ), ctrlId, -1, 10 ),
3473       edgeId   = createMenu( tr( "MEN_EDGE_CTRL" ), ctrlId, -1, 10 ),
3474       faceId   = createMenu( tr( "MEN_FACE_CTRL" ), ctrlId, -1, 10 ),
3475       volumeId = createMenu( tr( "MEN_VOLUME_CTRL" ), ctrlId, -1, 10 ),
3476       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
3477       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
3478       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
3479       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
3480
3481   createMenu( 111, importId, -1 );
3482   createMenu( 112, importId, -1 );
3483   createMenu( 113, importId, -1 );
3484   createMenu( 140, importId, -1 );
3485
3486   createMenu( 121, exportId, -1 );
3487   createMenu( 122, exportId, -1 );
3488   createMenu( 123, exportId, -1 );
3489   createMenu( 141, exportId, -1 ); // export to stl STL
3490
3491   createMenu( separator(), fileId, 10 );
3492
3493   createMenu( 33, editId, -1 );
3494
3495   createMenu( 5105, toolsId, -1 );
3496
3497   createMenu( 702, meshId, -1 ); // "Mesh" menu
3498   createMenu( 703, meshId, -1 );
3499   createMenu( 704, meshId, -1 );
3500   createMenu( 710, meshId, -1 );
3501   createMenu( 705, meshId, -1 );
3502   createMenu( separator(), meshId, -1 );
3503   createMenu( 701, meshId, -1 );
3504   createMenu( 711, meshId, -1 );
3505   createMenu( 712, meshId, -1 );
3506   createMenu( 713, meshId, -1 );
3507   createMenu( separator(), meshId, -1 );
3508   createMenu( 801, meshId, -1 );
3509   createMenu( 806, meshId, -1 );
3510   createMenu( 802, meshId, -1 );
3511   createMenu( 803, meshId, -1 );
3512   createMenu( 815, meshId, -1 );
3513   createMenu( separator(), meshId, -1 );
3514   createMenu( 810, meshId, -1 );
3515   createMenu( 811, meshId, -1 );
3516   createMenu( 812, meshId, -1 );
3517   createMenu( separator(), meshId, -1 );
3518   createMenu( 814, meshId, -1 );
3519   createMenu( separator(), meshId, -1 );
3520   createMenu( 900, meshId, -1 );
3521   //createMenu( 902, meshId, -1 );
3522   createMenu( 903, meshId, -1 );
3523   createMenu( 904, meshId, -1 );
3524   createMenu( separator(), meshId, -1 );
3525
3526   createMenu( 6005, nodeId, -1 );
3527   createMenu( 6002, edgeId, -1 );
3528   createMenu( 6003, edgeId, -1 );
3529   createMenu( 6001, edgeId, -1 );
3530   createMenu( 6004, edgeId, -1 );
3531   createMenu( 6021, faceId, -1 );
3532   createMenu( 6025, faceId, -1 );
3533   createMenu( 6027, faceId, -1 );
3534   createMenu( 6018, faceId, -1 );
3535   createMenu( 6019, faceId, -1 );
3536   createMenu( 6011, faceId, -1 );
3537   createMenu( 6012, faceId, -1 );
3538   createMenu( 6013, faceId, -1 );
3539   createMenu( 6014, faceId, -1 );
3540   createMenu( 6015, faceId, -1 );
3541   createMenu( 6016, faceId, -1 );
3542   createMenu( 6022, faceId, -1 );
3543   createMenu( 6017, volumeId, -1 );
3544   createMenu( 6009, volumeId, -1 );
3545   createMenu( 6023, volumeId, -1 );
3546   createMenu( 6024, volumeId, -1 );
3547   createMenu( 6026, volumeId, -1 );
3548
3549   createMenu( 4000, addId, -1 );
3550   createMenu( 4009, addId, -1 );
3551   createMenu( 4010, addId, -1 );
3552   createMenu( 4021, addId, -1 );
3553   createMenu( 4022, addId, -1 );
3554   createMenu( 4023, addId, -1 );
3555   createMenu( 4031, addId, -1 );
3556   createMenu( 4032, addId, -1 );
3557   createMenu( 4033, addId, -1 );
3558   createMenu( separator(), addId, -1 );
3559   createMenu( 4034, addId, -1 );
3560   createMenu( 4035, addId, -1 );
3561   createMenu( 4036, addId, -1 );
3562   createMenu( 4037, addId, -1 );
3563   createMenu( 4038, addId, -1 );
3564   createMenu( 4039, addId, -1 );
3565   createMenu( 4040, addId, -1 );
3566
3567   createMenu( 4041, removeId, -1 );
3568   createMenu( 4042, removeId, -1 );
3569   createMenu( 4044, removeId, -1 );
3570   createMenu( separator(), removeId, -1 );
3571   createMenu( 813, removeId, -1 );
3572   createMenu( separator(), removeId, -1 );
3573   createMenu( 4043, removeId, -1 );
3574
3575   createMenu( 4051, renumId, -1 );
3576   createMenu( 4052, renumId, -1 );
3577
3578   createMenu( 4061, transfId, -1 );
3579   createMenu( 4062, transfId, -1 );
3580   createMenu( 4063, transfId, -1 );
3581   createMenu( 4064, transfId, -1 );
3582   createMenu( 4065, transfId, -1 );
3583   createMenu( 4066, transfId, -1 );
3584   createMenu( 4068, transfId, -1 );
3585   createMenu( 4069, transfId, -1 );
3586
3587   createMenu( 4067,modifyId, -1 );
3588   createMenu( 407, modifyId, -1 );
3589   createMenu( 408, modifyId, -1 );
3590   createMenu( 409, modifyId, -1 );
3591   createMenu( 410, modifyId, -1 );
3592   createMenu( 411, modifyId, -1 );
3593   createMenu( 419, modifyId, -1 );
3594   createMenu( 412, modifyId, -1 );
3595   createMenu( 413, modifyId, -1 );
3596   createMenu( 416, modifyId, -1 );
3597   createMenu( 414, modifyId, -1 );
3598   createMenu( 415, modifyId, -1 );
3599   createMenu( 417, modifyId, -1 );
3600   createMenu( 418, modifyId, -1 );
3601
3602   createMenu( 501, measureId, -1 );
3603   createMenu( 502, measureId, -1 );
3604   createMenu( 214, viewId, -1 );
3605
3606   // ----- create toolbars --------------
3607   int meshTb     = createTool( tr( "TB_MESH" ) ),
3608       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
3609       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
3610       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
3611       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
3612
3613   createTool( 702, meshTb );
3614   createTool( 703, meshTb );
3615   createTool( 704, meshTb );
3616   createTool( 710, meshTb );
3617   createTool( 705, meshTb );
3618   createTool( separator(), meshTb );
3619   createTool( 701, meshTb );
3620   createTool( 711, meshTb );
3621   createTool( 712, meshTb );
3622   createTool( 713, meshTb );
3623   createTool( separator(), meshTb );
3624   createTool( 801, meshTb );
3625   createTool( 806, meshTb );
3626   createTool( 802, meshTb );
3627   createTool( 803, meshTb );
3628   //createTool( 815, meshTb );
3629   createTool( separator(), meshTb );
3630   createTool( 900, meshTb );
3631   //createTool( 902, meshTb );
3632   createTool( 903, meshTb );
3633   createTool( 904, meshTb );
3634   createTool( separator(), meshTb );
3635
3636   createTool( 6005, ctrlTb );
3637   createTool( separator(), ctrlTb );
3638   createTool( 6002, ctrlTb );
3639   createTool( 6003, ctrlTb );
3640   createTool( 6001, ctrlTb );
3641   createTool( 6004, ctrlTb );
3642   createTool( separator(), ctrlTb );
3643   createTool( 6021, ctrlTb );
3644   createTool( 6025, ctrlTb );
3645   createTool( 6027, ctrlTb );
3646   createTool( 6018, ctrlTb );
3647   createTool( 6019, ctrlTb );
3648   createTool( 6011, ctrlTb );
3649   createTool( 6012, ctrlTb );
3650   createTool( 6013, ctrlTb );
3651   createTool( 6014, ctrlTb );
3652   createTool( 6015, ctrlTb );
3653   createTool( 6016, ctrlTb );
3654   createTool( 6022, ctrlTb );
3655   createTool( separator(), ctrlTb );
3656   createTool( 6017, ctrlTb );
3657   createTool( 6009, ctrlTb );
3658   createTool( 6023, ctrlTb );
3659   createTool( 6024, ctrlTb );
3660   createTool( 6026, ctrlTb );
3661   createTool( separator(), ctrlTb );
3662
3663   createTool( 4000, addRemTb );
3664   createTool( 4009, addRemTb );
3665   createTool( 4010, addRemTb );
3666   createTool( 4021, addRemTb );
3667   createTool( 4022, addRemTb );
3668   createTool( 4023, addRemTb );
3669   createTool( 4031, addRemTb );
3670   createTool( 4032, addRemTb );
3671   createTool( 4033, addRemTb );
3672   createTool( separator(), addRemTb );
3673   createTool( 4034, addRemTb );
3674   createTool( 4035, addRemTb );
3675   createTool( 4036, addRemTb );
3676   createTool( 4037, addRemTb );
3677   createTool( 4038, addRemTb );
3678   createTool( 4039, addRemTb );
3679   createTool( 4040, addRemTb );
3680   createTool( separator(), addRemTb );
3681   createTool( 4041, addRemTb );
3682   createTool( 4042, addRemTb );
3683   createTool( 4044, addRemTb );
3684   createTool( 4043, addRemTb );
3685   createTool( separator(), addRemTb );
3686   createTool( 4051, addRemTb );
3687   createTool( 4052, addRemTb );
3688   createTool( separator(), addRemTb );
3689   createTool( 4061, addRemTb );
3690   createTool( 4062, addRemTb );
3691   createTool( 4063, addRemTb );
3692   createTool( 4064, addRemTb );
3693   createTool( 4065, addRemTb );
3694   createTool( 4066, addRemTb );
3695   createTool( 4068, addRemTb );
3696   createTool( 4069, addRemTb );
3697   createTool( separator(), addRemTb );
3698
3699   createTool( 4067,modifyTb );
3700   createTool( 407, modifyTb );
3701   createTool( 408, modifyTb );
3702   createTool( 409, modifyTb );
3703   createTool( 410, modifyTb );
3704   createTool( 411, modifyTb );
3705   createTool( 419, modifyTb );
3706   createTool( 412, modifyTb );
3707   createTool( 413, modifyTb );
3708   createTool( 416, modifyTb );
3709   createTool( 414, modifyTb );
3710   createTool( 415, modifyTb );
3711   createTool( 417, modifyTb );
3712   createTool( 418, modifyTb );
3713
3714   createTool( 214, dispModeTb );
3715
3716   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3717   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
3718
3719   myRules.clear();
3720   QString OB = "'ObjectBrowser'",
3721           View = "'" + SVTK_Viewer::Type() + "'",
3722           pat = "'%1'",
3723           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
3724           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
3725           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
3726           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
3727           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
3728                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
3729                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
3730                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
3731                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
3732                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
3733                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
3734           subMesh = elems,
3735           mesh_group = mesh + " " + subMesh + " " + group,
3736           hyp_alg = hypo + " " + algo;
3737
3738   // popup for object browser
3739   QString
3740     isInvisible("not( isVisible )"),
3741     isEmpty("numberOfNodes = 0"),
3742     isNotEmpty("numberOfNodes <> 0"),
3743
3744     // has nodes, edges, etc in VISIBLE! actor
3745     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3746     hasElems("(count( elemTypes ) > 0)"),
3747     hasDifferentElems("(count( elemTypes ) > 1)"),
3748     hasElems0d("({'Elem0d'} in elemTypes)"),
3749     hasEdges("({'Edge'} in elemTypes)"),
3750     hasFaces("({'Face'} in elemTypes)"),
3751     hasVolumes("({'Volume'} in elemTypes)");
3752
3753   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
3754   createPopupItem( 703, OB, mesh, "&& isComputable");      // CREATE_SUBMESH
3755   //createPopupItem( 703, OB, subMesh, "&& isComputable" );  // CREATE_SUBMESH
3756   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
3757   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
3758   createPopupItem( 803, OB, group );                       // EDIT_GROUP
3759   createPopupItem( 815, OB, group, "&& groupType = 'GroupOnGeom'" ); // EDIT_GROUP
3760
3761   popupMgr()->insert( separator(), -1, 0 );
3762   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
3763   createPopupItem( 711, OB, mesh, "&& isComputable && isPreComputable" ); // PRECOMPUTE
3764   createPopupItem( 712, OB, mesh, "&& isComputable" );     // EVALUATE
3765   createPopupItem( 713, OB, mesh, "&& isComputable" );     // MESH ORDER
3766   createPopupItem( 214, OB, mesh_group );                  // UPDATE
3767   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
3768   //createPopupItem( 902, OB, mesh );                        // STD_INFO
3769   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
3770   createPopupItem( 904, OB, mesh_group );                  // FIND_ELEM
3771   popupMgr()->insert( separator(), -1, 0 );
3772   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
3773   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
3774   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
3775   popupMgr()->insert( separator(), -1, 0 );
3776   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
3777   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
3778   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
3779   popupMgr()->insert( separator(), -1, 0 );
3780   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
3781   popupMgr()->insert( separator(), -1, 0 );
3782   createPopupItem( 417, OB, mesh/*, "&& " + hasElems*/);       // convert to quadratic
3783   createPopupItem( 418, OB, mesh/*, "&& " + hasVolumes*/);     // create 2D mesh on 3D
3784   popupMgr()->insert( separator(), -1, 0 );
3785
3786   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
3787   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
3788
3789   createPopupItem( 125, OB, mesh, multiple_non_empty );   // EXPORT_MED
3790   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
3791   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
3792   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
3793   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
3794   popupMgr()->insert( separator(), -1, 0 );
3795
3796   // popup for viewer
3797   createPopupItem( 803, View, group ); // EDIT_GROUP
3798   createPopupItem( 804, View, elems ); // ADD
3799   createPopupItem( 805, View, elems ); // REMOVE
3800
3801   popupMgr()->insert( separator(), -1, 0 );
3802   createPopupItem( 214, View, mesh_group ); // UPDATE
3803   createPopupItem( 900, View, mesh_group ); // ADV_INFO
3804   //createPopupItem( 902, View, mesh );       // STD_INFO
3805   createPopupItem( 903, View, mesh_group ); // WHAT_IS
3806   createPopupItem( 904, View, mesh_group ); // FIND_ELEM
3807   popupMgr()->insert( separator(), -1, 0 );
3808
3809   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
3810   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
3811   popupMgr()->insert( separator(), -1, 0 );
3812
3813   int anId;
3814   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
3815   QString aType = QString( "%1type in {%2}" ).arg( lc );
3816   aType = aType.arg( mesh_group );
3817   QString aMeshInVTK = aClient + "&&" + aType;
3818
3819   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3820   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
3821   QString aSelCount = QString( "%1 > 0" ).arg( dc );
3822
3823   //-------------------------------------------------
3824   // Numbering
3825   //-------------------------------------------------
3826   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
3827
3828   popupMgr()->insert( action( 9010 ), anId, -1 );
3829   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
3830   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
3831
3832   popupMgr()->insert( action( 9011 ), anId, -1 );
3833   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
3834   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
3835
3836   popupMgr()->insert( separator(), -1, -1 );
3837
3838   //-------------------------------------------------
3839   // Display Mode
3840   //-------------------------------------------------
3841   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3842
3843   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3844   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
3845   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
3846
3847   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3848   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
3849   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
3850
3851   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3852   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
3853   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
3854
3855   popupMgr()->insert( separator(), anId, -1 );
3856
3857   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3858   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
3859   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
3860
3861   //-------------------------------------------------
3862   // Display Entity
3863   //-------------------------------------------------
3864   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3865
3866   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3867
3868   popupMgr()->insert( action(216), anId, -1 ); // ELEMS 0D
3869   popupMgr()->setRule(action(216), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
3870   popupMgr()->setRule(action(216), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
3871
3872   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3873   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
3874   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
3875
3876   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3877   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
3878   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
3879
3880   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3881   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
3882   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
3883
3884   popupMgr()->insert( separator(), anId, -1 );
3885
3886   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3887   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
3888
3889
3890   //-------------------------------------------------
3891   // Representation of the 2D Quadratic elements
3892   //-------------------------------------------------
3893   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
3894   popupMgr()->insert( action( 231 ), anId, -1 ); // LINE REPRESENTATION
3895   popupMgr()->setRule( action( 231 ), aMeshInVTK + "and isVisible",QtxPopupMgr::VisibleRule );
3896   popupMgr()->setRule( action( 231 ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
3897
3898   popupMgr()->insert( action( 232 ), anId, -1 ); // ARC REPRESENTATION
3899   popupMgr()->setRule( action( 232 ), aMeshInVTK + "and isVisible", QtxPopupMgr::VisibleRule );
3900   popupMgr()->setRule( action( 232 ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
3901
3902   //-------------------------------------------------
3903   // Orientation of faces
3904   //-------------------------------------------------
3905   popupMgr()->insert( action( 221 ), -1, -1 );
3906   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
3907   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
3908
3909   //-------------------------------------------------
3910   // Color / Size
3911   //-------------------------------------------------
3912   popupMgr()->insert( action( 1132 ), -1, -1 );
3913   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3914
3915   //-------------------------------------------------
3916   // Transparency
3917   //-------------------------------------------------
3918   popupMgr()->insert( action( 1133 ), -1, -1 );
3919   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3920
3921   //-------------------------------------------------
3922   // Controls
3923   //-------------------------------------------------
3924   QString
3925     aMeshInVtkHasNodes = aMeshInVTK + "&&" + hasNodes,
3926     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3927     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3928     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3929
3930   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3931
3932   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3933   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3934
3935   popupMgr()->insert( separator(), anId, -1 );
3936
3937   int aSubId = popupMgr()->insert( tr( "MEN_NODE_CTRL" ), anId, -1 ); // NODE CONTROLS
3938
3939   popupMgr()->insert( action( 6005 ), aSubId, -1 ); // FREE_NODE
3940   popupMgr()->setRule( action( 6005 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
3941   popupMgr()->setRule( action( 6005 ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
3942
3943   aSubId = popupMgr()->insert( tr( "MEN_EDGE_CTRL" ), anId, -1 ); // EDGE CONTROLS
3944
3945   popupMgr()->insert( action( 6002 ), aSubId, -1 ); // FREE_EDGE
3946   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3947   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
3948
3949   popupMgr()->insert( action( 6003 ), aSubId, -1 ); // FREE_BORDER
3950   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3951   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
3952
3953   popupMgr()->insert( action( 6001 ), aSubId, -1 ); // LENGTH
3954   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3955   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
3956
3957   popupMgr()->insert( action( 6004 ), aSubId, -1 ); // CONNECTION
3958   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3959   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
3960
3961   aSubId = popupMgr()->insert( tr( "MEN_FACE_CTRL" ), anId, -1 ); // FACE CONTROLS
3962
3963   popupMgr()->insert ( action( 6021 ), aSubId, -1 ); // FREE_FACE
3964   popupMgr()->setRule( action( 6021 ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
3965                                        QtxPopupMgr::VisibleRule );
3966   popupMgr()->setRule( action( 6021 ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
3967
3968   popupMgr()->insert ( action( 6018 ), aSubId, -1 ); // LENGTH_2D
3969   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3970   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
3971
3972   popupMgr()->insert ( action( 6019 ), aSubId, -1 ); // CONNECTION_2D
3973   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3974   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
3975
3976   popupMgr()->insert ( action( 6011 ), aSubId, -1 ); // AREA
3977   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3978   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
3979
3980   popupMgr()->insert ( action( 6012 ), aSubId, -1 ); // TAPER
3981   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3982   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
3983
3984   popupMgr()->insert ( action( 6013 ), aSubId, -1 ); // ASPECT
3985   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3986   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
3987
3988   popupMgr()->insert ( action( 6014 ), aSubId, -1 ); // MIN_ANG
3989   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3990   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
3991
3992   popupMgr()->insert ( action( 6015 ), aSubId, -1 ); // WARP
3993   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3994   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
3995
3996   popupMgr()->insert ( action( 6016 ), aSubId, -1 ); // SKEW
3997   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3998   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
3999
4000   popupMgr()->insert ( action( 6022 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_2D
4001   popupMgr()->setRule( action( 6022 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4002   popupMgr()->setRule( action( 6022 ), "controlMode = 'eMaxElementLength2D'", QtxPopupMgr::ToggleRule );
4003
4004   popupMgr()->insert ( action( 6025 ), aSubId, -1 ); // BARE_BORDER_FACE
4005   popupMgr()->setRule( action( 6025 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4006   popupMgr()->setRule( action( 6025 ), "controlMode = 'eBareBorderFace'", QtxPopupMgr::ToggleRule );
4007
4008   popupMgr()->insert ( action( 6027 ), aSubId, -1 ); // OVER_CONSTRAINED_FACE
4009   popupMgr()->setRule( action( 6027 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
4010   popupMgr()->setRule( action( 6027 ), "controlMode = 'eOverConstrainedFace'", QtxPopupMgr::ToggleRule );
4011
4012   aSubId = popupMgr()->insert( tr( "MEN_VOLUME_CTRL" ), anId, -1 ); // VOLUME CONTROLS
4013
4014   popupMgr()->insert ( action( 6017 ), aSubId, -1 ); // ASPECT_3D
4015   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4016   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
4017
4018   popupMgr()->insert ( action( 6009 ), aSubId, -1 ); // VOLUME_3D
4019   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4020   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
4021
4022   popupMgr()->insert ( action( 6023 ), aSubId, -1 ); // MAX_ELEMENT_LENGTH_3D
4023   popupMgr()->setRule( action( 6023 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4024   popupMgr()->setRule( action( 6023 ), "controlMode = 'eMaxElementLength3D'", QtxPopupMgr::ToggleRule );
4025
4026   popupMgr()->insert ( action( 6024 ), aSubId, -1 ); // BARE_BORDER_VOLUME
4027   popupMgr()->setRule( action( 6024 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4028   popupMgr()->setRule( action( 6024 ), "controlMode = 'eBareBorderVolume'", QtxPopupMgr::ToggleRule );
4029
4030   popupMgr()->insert ( action( 6026 ), aSubId, -1 ); // OVER_CONSTRAINED_VOLUME
4031   popupMgr()->setRule( action( 6026 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
4032   popupMgr()->setRule( action( 6026 ), "controlMode = 'eOverConstrainedVolume'", QtxPopupMgr::ToggleRule );
4033
4034   popupMgr()->insert( separator(), anId, -1 );
4035
4036   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
4037   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
4038
4039   popupMgr()->insert( separator(), anId, -1 );
4040
4041   aSubId = popupMgr()->insert( tr( "MEN_DISTRIBUTION_CTRL" ), anId, -1 ); // NODE CONTROLS
4042
4043   popupMgr()->insert( action( 2021 ), aSubId, -1 ); // SAVE_DISTRIBUTION
4044   popupMgr()->setRule( action( 2021 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4045
4046   popupMgr()->insert( action( 2022 ), aSubId, -1 ); // SHOW_DISTRIBUTION
4047   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4048   popupMgr()->setRule( action( 2022 ), aMeshInVTK + "&& isNumFunctor && isDistributionVisible", QtxPopupMgr::ToggleRule);
4049
4050 #ifndef DISABLE_PLOT2DVIEWER
4051   popupMgr()->insert( action( 2023 ), aSubId, -1 ); // PLOT_DISTRIBUTION
4052   popupMgr()->setRule( action( 2023 ), aMeshInVTK + "&& isNumFunctor", QtxPopupMgr::VisibleRule );
4053 #endif
4054
4055   //-------------------------------------------------
4056   // Display / Erase
4057   //-------------------------------------------------
4058   popupMgr()->insert( separator(), -1, -1 );
4059   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
4060     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
4061   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
4062   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
4063
4064   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
4065   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
4066
4067   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
4068   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
4069
4070   popupMgr()->insert( separator(), -1, -1 );
4071
4072   //-------------------------------------------------
4073   // Clipping
4074   //-------------------------------------------------
4075   popupMgr()->insert( action( 1134 ), -1, -1 );
4076   popupMgr()->setRule( action( 1134 ), "client='VTKViewer'", QtxPopupMgr::VisibleRule );
4077
4078   popupMgr()->insert( separator(), -1, -1 );
4079
4080   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
4081            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
4082
4083   connect( application(), SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
4084            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
4085 }
4086
4087 //================================================================================
4088 /*!
4089  * \brief Return true if SMESH or GEOM objects are selected.
4090  * Is called form LightApp_Module::activateModule() which clear selection if
4091  * not isSelectionCompatible()
4092  */
4093 //================================================================================
4094
4095 bool SMESHGUI::isSelectionCompatible()
4096 {
4097   bool isCompatible = true;
4098   SALOME_ListIO selected;
4099   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
4100     Sel->selectedObjects( selected );
4101
4102   SALOME_ListIteratorOfListIO It( selected );
4103   for ( ; isCompatible && It.More(); It.Next())
4104     isCompatible =
4105       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
4106       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
4107
4108   return isCompatible;
4109 }
4110
4111
4112 bool SMESHGUI::reusableOperation( const int id )
4113 {
4114   // compute, evaluate and precompute are not reusable operations
4115   return ( id == 701 || id == 711 || id == 712 ) ? false : SalomeApp_Module::reusableOperation( id );
4116 }
4117
4118 bool SMESHGUI::activateModule( SUIT_Study* study )
4119 {
4120   bool res = SalomeApp_Module::activateModule( study );
4121
4122   setMenuShown( true );
4123   setToolShown( true );
4124
4125   // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
4126   PyGILState_STATE gstate = PyGILState_Ensure();
4127   PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");
4128   if(pluginsmanager==NULL)
4129     PyErr_Print();
4130   else
4131     {
4132       PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toStdString().c_str(),tr("SMESH_PLUGINS_OTHER").toStdString().c_str());
4133       if(result==NULL)
4134         PyErr_Print();
4135       Py_XDECREF(result);
4136     }
4137   PyGILState_Release(gstate);
4138   // end of GEOM plugins loading
4139
4140   // Reset actions accelerator keys
4141   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
4142   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
4143   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
4144
4145   action(  33)->setEnabled(true); // Delete: Key_Delete
4146   action(1101)->setEnabled(true); // Rename: Key_F2
4147
4148   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
4149   GetSMESHGen()->SetCurrentStudy(SALOMEDS::Study::_nil());
4150   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study ))
4151     if ( _PTR(Study) aStudy = s->studyDS()) {
4152       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
4153       updateObjBrowser(); // objects can be removed
4154     }
4155   
4156   // get all view currently opened in the study and connect their signals  to
4157   // the corresponding slots of the class.
4158   SUIT_Desktop* aDesk = study->application()->desktop();
4159   if ( aDesk ) {
4160     QList<SUIT_ViewWindow*> wndList = aDesk->windows();
4161     SUIT_ViewWindow* wnd;
4162     foreach ( wnd, wndList )
4163       connectView( wnd );
4164   }
4165
4166   return res;
4167 }
4168
4169 bool SMESHGUI::deactivateModule( SUIT_Study* study )
4170 {
4171   setMenuShown( false );
4172   setToolShown( false );
4173
4174   EmitSignalCloseAllDialogs();
4175
4176   // Unset actions accelerator keys
4177   action(111)->setShortcut(QKeySequence()); // Import DAT
4178   action(112)->setShortcut(QKeySequence()); // Import UNV
4179   action(113)->setShortcut(QKeySequence()); // Import MED
4180
4181   action(  33)->setEnabled(false); // Delete: Key_Delete
4182   action(1101)->setEnabled(false); // Rename: Key_F2
4183
4184   return SalomeApp_Module::deactivateModule( study );
4185 }
4186
4187 void SMESHGUI::studyClosed( SUIT_Study* s )
4188 {
4189   SMESH::RemoveVisuData( s->id() );
4190   SalomeApp_Module::studyClosed( s );
4191 }
4192
4193 void SMESHGUI::OnGUIEvent()
4194 {
4195   const QObject* obj = sender();
4196   if ( !obj || !obj->inherits( "QAction" ) )
4197     return;
4198   int id = actionId((QAction*)obj);
4199   if ( id != -1 )
4200     OnGUIEvent( id );
4201 }
4202
4203 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
4204 {
4205   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
4206   if ( CORBA::is_nil( myComponentSMESH ) )
4207     {
4208       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
4209       if ( aStudy )
4210         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4211       return aGUI.myComponentSMESH;
4212     }
4213   if ( aStudy )
4214     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
4215   return myComponentSMESH;
4216 }
4217
4218 QString SMESHGUI::engineIOR() const
4219 {
4220   CORBA::ORB_var anORB = getApp()->orb();
4221   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
4222   return QString( anIOR.in() );
4223 }
4224
4225 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
4226 {
4227   SalomeApp_Module::contextMenuPopup( client, menu, title );
4228   SALOME_ListIO lst;
4229   selectionMgr()->selectedObjects( lst );
4230   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
4231     Handle(SALOME_InteractiveObject) io = lst.First();
4232     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
4233     _PTR(Study) study = appStudy->studyDS();
4234     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
4235     if ( obj ) {
4236       QString aName = QString( obj->GetName().c_str() );
4237       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
4238           aName.remove( (aName.length() - 1), 1 );
4239       title = aName;
4240     }
4241   }
4242 }
4243
4244 LightApp_Selection* SMESHGUI::createSelection() const
4245 {
4246   return new SMESHGUI_Selection();
4247 }
4248
4249 void SMESHGUI::windows( QMap<int, int>& aMap ) const
4250 {
4251   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
4252   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
4253 }
4254
4255 void SMESHGUI::viewManagers( QStringList& list ) const
4256 {
4257   list.append( SVTK_Viewer::Type() );
4258 }
4259
4260 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
4261 {
4262   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) ) {
4263     SMESH::UpdateSelectionProp( this );
4264     
4265     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
4266     for(int i = 0; i < aViews.count() ; i++){
4267       SUIT_ViewWindow *sf = aViews[i];
4268       connectView( sf );
4269     }
4270   }
4271 }
4272
4273 void SMESHGUI::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
4274 {
4275   if( theViewManager && theViewManager->getType() == SVTK_Viewer::Type() )
4276     myClippingPlaneInfoMap.erase( theViewManager );
4277 }
4278
4279 void SMESHGUI::addActorAsObserver( SMESH_Actor* theActor )
4280 {
4281   theActor->AddObserver( SMESH::DeleteActorEvent,
4282                          myEventCallbackCommand.GetPointer(),
4283                          myPriority );
4284 }
4285
4286 void SMESHGUI::ProcessEvents( vtkObject* theObject,
4287                               unsigned long theEvent,
4288                               void* theClientData,
4289                               void* theCallData )
4290 {
4291   if( SMESHGUI* aSMESHGUI = reinterpret_cast<SMESHGUI*>( theClientData ) ) {
4292     if( theObject && theEvent == SMESH::DeleteActorEvent ) {
4293       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( theObject ) ) {
4294         SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = aSMESHGUI->getClippingPlaneInfoMap();
4295         SMESHGUI_ClippingPlaneInfoMap::iterator anIter1 = aClippingPlaneInfoMap.begin();
4296         for( ; anIter1 != aClippingPlaneInfoMap.end(); anIter1++ ) {
4297           SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
4298           SMESHGUI_ClippingPlaneInfoList::iterator anIter2 = aClippingPlaneInfoList.begin();
4299           for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
4300             SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
4301             std::list<vtkActor*>& anActorList = aClippingPlaneInfo.ActorList;
4302             SMESH::TActorList::iterator anIter3 = anActorList.begin();
4303             for ( ; anIter3 != anActorList.end(); anIter3++ ) {
4304               if( anActor == *anIter3 ) {
4305                 anActorList.erase( anIter3 );
4306                 break;
4307               }
4308             }
4309           }
4310         }
4311       }
4312     }
4313   }
4314 }
4315
4316 void SMESHGUI::createPreferences()
4317 {
4318   // General tab ------------------------------------------------------------------------
4319   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
4320
4321   int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
4322   int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
4323   setPreferenceProperty( lim, "min",  0 );
4324   setPreferenceProperty( lim, "max",  100000000 );
4325   setPreferenceProperty( lim, "step", 1000 );
4326   setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
4327
4328   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
4329   setPreferenceProperty( qaGroup, "columns", 2 );
4330   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
4331   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
4332   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
4333   setPreferenceProperty( prec, "min", 0 );
4334   setPreferenceProperty( prec, "max", 16 );
4335
4336   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
4337   setPreferenceProperty( dispgroup, "columns", 2 );
4338   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
4339   QStringList modes;
4340   modes.append( "Wireframe" );
4341   modes.append( "Shading" );
4342   modes.append( "Nodes" );
4343   modes.append( "Shrink" );
4344   QList<QVariant> indices;
4345   indices.append( 0 );
4346   indices.append( 1 );
4347   indices.append( 2 );
4348   indices.append( 3 );
4349   setPreferenceProperty( dispmode, "strings", modes );
4350   setPreferenceProperty( dispmode, "indexes", indices );
4351
4352   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), genTab );
4353   setPreferenceProperty( arcgroup, "columns", 2 );
4354   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
4355   QStringList quadraticModes;
4356   quadraticModes.append("Lines");
4357   quadraticModes.append("Arcs");
4358   indices.clear();
4359   indices.append( 0 );
4360   indices.append( 1 );
4361   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
4362   setPreferenceProperty( quadraticmode, "indexes", indices );
4363
4364   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
4365                               "SMESH", "max_angle" );
4366   setPreferenceProperty( maxAngle, "min", 1 );
4367   setPreferenceProperty( maxAngle, "max", 90 );
4368
4369
4370
4371   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
4372   setPreferenceProperty( exportgroup, "columns", 2 );
4373   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
4374   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
4375
4376   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
4377   setPreferenceProperty( computeGroup, "columns", 2 );
4378   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
4379   modes.clear();
4380   modes.append( tr( "PREF_NOTIFY_NEVER" ) );
4381   modes.append( tr( "PREF_NOTIFY_ERROR" ) );
4382   modes.append( tr( "PREF_NOTIFY_ALWAYS" ) );
4383   indices.clear();
4384   indices.append( 0 );
4385   indices.append( 1 );
4386   indices.append( 2 );
4387   setPreferenceProperty( notifyMode, "strings", modes );
4388   setPreferenceProperty( notifyMode, "indexes", indices );
4389
4390   int infoGroup = addPreference( tr( "PREF_GROUP_INFO" ), genTab );
4391   setPreferenceProperty( computeGroup, "columns", 2 );
4392   int elemInfo = addPreference( tr( "PREF_ELEM_INFO" ), infoGroup, LightApp_Preferences::Selector, "SMESH", "mesh_elem_info" );
4393   modes.clear();
4394   modes.append( tr( "PREF_ELEM_INFO_SIMPLE" ) );
4395   modes.append( tr( "PREF_ELEM_INFO_TREE" ) );
4396   indices.clear();
4397   indices.append( 0 );
4398   indices.append( 1 );
4399   setPreferenceProperty( elemInfo, "strings", modes );
4400   setPreferenceProperty( elemInfo, "indexes", indices );
4401
4402   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
4403   setPreferenceProperty( segGroup, "columns", 2 );
4404   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
4405                               "SMESH", "segmentation" );
4406   setPreferenceProperty( segLen, "min", 1 );
4407   setPreferenceProperty( segLen, "max", 10000000 );
4408   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
4409                              "SMESH", "nb_segments_per_edge" );
4410   setPreferenceProperty( nbSeg, "min", 1 );
4411   setPreferenceProperty( nbSeg, "max", 10000000 );
4412
4413   // Quantities with individual precision settings
4414   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
4415   setPreferenceProperty( precGroup, "columns", 2 );
4416
4417   const int nbQuantities = 6;
4418   int precs[nbQuantities], ii = 0;
4419   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
4420                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );
4421   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
4422                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
4423   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
4424                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
4425   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
4426                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
4427   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
4428                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
4429   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
4430                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );
4431
4432   // Set property for precision value for spinboxes
4433   for ( ii = 0; ii < nbQuantities; ii++ ){
4434     setPreferenceProperty( precs[ii], "min", -14 );
4435     setPreferenceProperty( precs[ii], "max", 14 );
4436     setPreferenceProperty( precs[ii], "precision", 2 );
4437   }
4438
4439   // Mesh tab ------------------------------------------------------------------------
4440   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
4441   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
4442   setPreferenceProperty( nodeGroup, "columns", 3 );
4443
4444   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
4445
4446   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
4447
4448   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4449   QList<QVariant> aMarkerTypeIndicesList;
4450   QList<QVariant> aMarkerTypeIconsList;
4451   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
4452     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
4453     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
4454     aMarkerTypeIndicesList << i;
4455     aMarkerTypeIconsList << pixmap;
4456   }
4457   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
4458   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
4459
4460   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
4461
4462   QList<QVariant> aMarkerScaleIndicesList;
4463   QStringList     aMarkerScaleValuesList;
4464   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
4465     aMarkerScaleIndicesList << i;
4466     aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
4467   }
4468   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
4469   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
4470
4471   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
4472   setPreferenceProperty( elemGroup, "columns", 2 );
4473
4474   addPreference( tr( "PREF_FILL"     ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
4475   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
4476   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
4477   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
4478
4479   int grpGroup = addPreference( tr( "PREF_GROUP_GROUPS" ), meshTab );
4480   setPreferenceProperty( grpGroup, "columns", 2 );
4481
4482   addPreference( tr( "PREF_GRP_NAMES" ), grpGroup, LightApp_Preferences::Color, "SMESH", "group_name_color" );
4483
4484   //int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
4485   //setPreferenceProperty( sp, "hstretch", 0 );
4486   //setPreferenceProperty( sp, "vstretch", 0 );
4487
4488   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
4489                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
4490   int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
4491   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
4492                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
4493   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
4494                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
4495
4496   setPreferenceProperty( size0d, "min", 1 );
4497   setPreferenceProperty( size0d, "max", 10 );
4498
4499   setPreferenceProperty( sp, "hstretch", 0 );
4500   setPreferenceProperty( sp, "vstretch", 0 );
4501
4502   setPreferenceProperty( elemW, "min", 1 );
4503   setPreferenceProperty( elemW, "max", 5 );
4504
4505   setPreferenceProperty( shrink, "min", 0 );
4506   setPreferenceProperty( shrink, "max", 100 );
4507
4508   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
4509   setPreferenceProperty( orientGroup, "columns", 1 );
4510
4511   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
4512   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
4513
4514   setPreferenceProperty( orientScale, "min", 0.05 );
4515   setPreferenceProperty( orientScale, "max", 0.5 );
4516   setPreferenceProperty( orientScale, "step", 0.05 );
4517
4518   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
4519
4520   // Selection tab ------------------------------------------------------------------------
4521   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
4522
4523   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
4524   setPreferenceProperty( selGroup, "columns", 2 );
4525
4526   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
4527   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
4528   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
4529
4530   setPreferenceProperty( selW, "min", 1 );
4531   setPreferenceProperty( selW, "max", 5 );
4532
4533   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
4534   setPreferenceProperty( preGroup, "columns", 2 );
4535
4536   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
4537   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
4538
4539   setPreferenceProperty( preW, "min", 1 );
4540   setPreferenceProperty( preW, "max", 5 );
4541
4542   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
4543   setPreferenceProperty( precSelGroup, "columns", 2 );
4544
4545   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
4546   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
4547   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
4548
4549   // Scalar Bar tab ------------------------------------------------------------------------
4550   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
4551   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
4552   setPreferenceProperty( fontGr, "columns", 2 );
4553
4554   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
4555   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
4556
4557   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
4558   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
4559
4560   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
4561   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
4562
4563   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
4564   setPreferenceProperty( numcol, "min", 2 );
4565   setPreferenceProperty( numcol, "max", 256 );
4566
4567   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
4568   setPreferenceProperty( numlab, "min", 2 );
4569   setPreferenceProperty( numlab, "max", 65 );
4570
4571   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
4572   setPreferenceProperty( orientGr, "columns", 2 );
4573   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
4574   QStringList orients;
4575   orients.append( tr( "SMESH_VERTICAL" ) );
4576   orients.append( tr( "SMESH_HORIZONTAL" ) );
4577   indices.clear(); indices.append( 0 ); indices.append( 1 );
4578   setPreferenceProperty( orient, "strings", orients );
4579   setPreferenceProperty( orient, "indexes", indices );
4580
4581   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
4582   setPreferenceProperty( posVSizeGr, "columns", 2 );
4583   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
4584   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
4585   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
4586   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
4587   setPreferenceProperty( xv, "step", 0.1 );
4588   setPreferenceProperty( xv, "min", 0.0 );
4589   setPreferenceProperty( xv, "max", 1.0 );
4590   setPreferenceProperty( yv, "step", 0.1 );
4591   setPreferenceProperty( yv, "min", 0.0 );
4592   setPreferenceProperty( yv, "max", 1.0 );
4593   setPreferenceProperty( wv, "step", 0.1 );
4594   setPreferenceProperty( wv, "min", 0.0 );
4595   setPreferenceProperty( wv, "max", 1.0 );
4596   setPreferenceProperty( hv, "min", 0.0 );
4597   setPreferenceProperty( hv, "max", 1.0 );
4598   setPreferenceProperty( hv, "step", 0.1 );
4599
4600   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
4601   setPreferenceProperty( posHSizeGr, "columns", 2 );
4602   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
4603   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
4604   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
4605   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
4606   setPreferenceProperty( xv, "min", 0.0 );
4607   setPreferenceProperty( xv, "max", 1.0 );
4608   setPreferenceProperty( xv, "step", 0.1 );
4609   setPreferenceProperty( xh, "min", 0.0 );
4610   setPreferenceProperty( xh, "max", 1.0 );
4611   setPreferenceProperty( xh, "step", 0.1 );
4612   setPreferenceProperty( yh, "min", 0.0 );
4613   setPreferenceProperty( yh, "max", 1.0 );
4614   setPreferenceProperty( yh, "step", 0.1 );
4615   setPreferenceProperty( wh, "min", 0.0 );
4616   setPreferenceProperty( wh, "max", 1.0 );
4617   setPreferenceProperty( wh, "step", 0.1 );
4618   setPreferenceProperty( hh, "min", 0.0 );
4619   setPreferenceProperty( hh, "max", 1.0 );
4620   setPreferenceProperty( hh, "step", 0.1 );
4621   
4622   int distributionGr = addPreference( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), sbarTab, LightApp_Preferences::Auto, "SMESH", "distribution_visibility" );
4623   int coloringType = addPreference( tr( "SMESH_DISTRIBUTION_COLORING_TYPE" ), distributionGr, LightApp_Preferences::Selector, "SMESH", "distribution_coloring_type" );
4624   setPreferenceProperty( distributionGr, "columns", 3 );
4625   QStringList types;
4626   types.append( tr( "SMESH_MONOCOLOR" ) ); 
4627   types.append( tr( "SMESH_MULTICOLOR" ) );
4628   indices.clear(); indices.append( 0 ); indices.append( 1 );
4629   setPreferenceProperty( coloringType, "strings", types );
4630   setPreferenceProperty( coloringType, "indexes", indices );
4631   addPreference( tr( "SMESH_DISTRIBUTION_COLOR" ), distributionGr, LightApp_Preferences::Color, "SMESH", "distribution_color" );
4632
4633 }
4634
4635 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
4636 {
4637   if( sect=="SMESH" ) {
4638     float sbX1,sbY1,sbW,sbH;
4639     float aTol = 1.00000009999999;
4640     std::string aWarning;
4641     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4642     if( name=="selection_object_color" || name=="selection_element_color" ||
4643         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
4644         name=="selection_precision_node" || name=="selection_precision_element" ||
4645         name=="selection_precision_object")
4646       SMESH::UpdateSelectionProp( this );
4647     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
4648       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
4649       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
4650       if(sbX1+sbW > aTol){
4651         aWarning = "Origin and Size Vertical: X+Width > 1\n";
4652         sbX1=0.01;
4653         sbW=0.08;
4654         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
4655         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
4656       }
4657     }
4658     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
4659       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
4660       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
4661       if(sbY1+sbH > aTol){
4662         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
4663         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
4664         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
4665       }
4666     }
4667     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
4668       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4669       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
4670       if(sbX1+sbW > aTol){
4671         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
4672         sbX1=0.1;
4673         sbW=0.08;
4674         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4675         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
4676       }
4677     }
4678     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
4679       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4680       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
4681       if(sbY1+sbH > aTol){
4682         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
4683         sbY1=0.01;
4684         sbH=0.08;
4685         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4686         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
4687       }
4688     }
4689     else if ( name == "segmentation" ) {
4690       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
4691       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
4692     }
4693     else if ( name == "nb_segments_per_edge" ) {
4694       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
4695       myComponentSMESH->SetDefaultNbSegments( nbSeg );
4696     }
4697
4698     if(aWarning.size() != 0){
4699       aWarning += "The default values are applied instead.";
4700       SUIT_MessageBox::warning(SMESHGUI::desktop(),
4701                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
4702                                QObject::tr(aWarning.c_str()));
4703     }
4704   }
4705 }
4706
4707 //================================================================================
4708 /*!
4709  * \brief Update something in accordance with update flags
4710   * \param theFlags - update flags
4711 *
4712 * Update viewer or/and object browser etc. in accordance with update flags ( see
4713 * LightApp_UpdateFlags enumeration ).
4714 */
4715 //================================================================================
4716 void SMESHGUI::update( const int flags )
4717 {
4718   if ( flags & UF_Viewer | flags & UF_Forced )
4719     SMESH::UpdateView();
4720   else
4721     SalomeApp_Module::update( flags );
4722 }
4723
4724 //================================================================================
4725 /*!
4726  * \brief Set default selection mode
4727 *
4728 * SLOT called when operation commited. Sets default selection mode
4729 */
4730 //================================================================================
4731 void SMESHGUI::onOperationCommited( SUIT_Operation* )
4732 {
4733   SVTK_ViewWindow* vtkWnd =
4734     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4735   if ( vtkWnd )
4736     vtkWnd->SetSelectionMode( ActorSelection );
4737 }
4738
4739 //================================================================================
4740 /*!
4741  * \brief Set default selection mode
4742 *
4743 * SLOT called when operation aborted. Sets default selection mode
4744 */
4745 //================================================================================
4746 void SMESHGUI::onOperationAborted( SUIT_Operation* )
4747 {
4748   SVTK_ViewWindow* vtkWnd =
4749     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4750   if ( vtkWnd )
4751     vtkWnd->SetSelectionMode( ActorSelection );
4752 }
4753
4754 //================================================================================
4755 /*!
4756  * \brief Creates operation with given identifier
4757   * \param id - identifier of operation to be started
4758   * \return Pointer on created operation or NULL if operation is not created
4759 *
4760 * Virtual method redefined from the base class creates operation with given id.
4761 * It is called called automatically from startOperation method of base class.
4762 */
4763 //================================================================================
4764 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
4765 {
4766   LightApp_Operation* op = 0;
4767   // to do : create operation here
4768   switch( id )
4769   {
4770     case 417: //convert to quadratic
4771       op = new SMESHGUI_ConvToQuadOp();
4772     break;
4773     case 418: // create 2D mesh as boundary on 3D
4774       op = new SMESHGUI_Make2DFrom3DOp();
4775     break;
4776     case 701: // Compute mesh
4777       op = new SMESHGUI_ComputeOp();
4778     break;
4779     case 702: // Create mesh
4780       op = new SMESHGUI_MeshOp( true, true );
4781     break;
4782     case 703: // Create sub-mesh
4783       op = new SMESHGUI_MeshOp( true, false );
4784     break;
4785     case 704: // Edit mesh/sub-mesh
4786       op = new SMESHGUI_MeshOp( false );
4787     break;
4788     case 711: // Precompute mesh
4789       op = new SMESHGUI_PrecomputeOp();
4790     break;
4791     case 712: // Evaluate mesh
4792       op = new SMESHGUI_EvaluateOp();
4793     break;
4794     case 713: // Evaluate mesh
4795       op = new SMESHGUI_MeshOrderOp();
4796     break;
4797     case 806: // Create group on geom
4798       op = new SMESHGUI_GroupOnShapeOp();
4799       break;
4800     case 904: // Find element
4801       op = new SMESHGUI_FindElemByPointOp();
4802       break;
4803     case 4067: // make mesh pass through point
4804       op = new SMESHGUI_MakeNodeAtPointOp();
4805       break;
4806     default:
4807     break;
4808   }
4809
4810   if( !op )
4811     op = SalomeApp_Module::createOperation( id );
4812   return op;
4813 }
4814
4815 //================================================================================
4816 /*!
4817  * \brief Stops current operations and starts a given one
4818   * \param id - The id of the operation to start
4819  */
4820 //================================================================================
4821
4822 void SMESHGUI::switchToOperation(int id)
4823 {
4824   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
4825     activeStudy()->abortAllOperations();
4826   startOperation( id );
4827 }
4828
4829 LightApp_Displayer* SMESHGUI::displayer()
4830 {
4831   if( !myDisplayer )
4832     myDisplayer = new SMESHGUI_Displayer( getApp() );
4833   return myDisplayer;
4834 }
4835
4836 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
4837 {
4838   int aHue = -1;
4839   int aTolerance = 64;
4840   int anIterations = 0;
4841   int aPeriod = 5;
4842
4843   while( 1 )
4844   {
4845     anIterations++;
4846     if( anIterations % aPeriod == 0 )
4847     {
4848       aTolerance /= 2;
4849       if( aTolerance < 1 )
4850         break;
4851     }
4852
4853     aHue = (int)( 360.0 * rand() / RAND_MAX );
4854
4855     bool ok = true;
4856     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
4857     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
4858     for( ; it != itEnd; ++it )
4859     {
4860       SALOMEDS::Color anAutoColor = *it;
4861       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
4862
4863       int h, s, v;
4864       aQColor.getHsv( &h, &s, &v );
4865       if( abs( h - aHue ) < aTolerance )
4866       {
4867         ok = false;
4868         break;
4869       }
4870     }
4871
4872     if( ok )
4873       break;
4874   }
4875
4876   QColor aColor;
4877   aColor.setHsv( aHue, 255, 255 );
4878
4879   SALOMEDS::Color aSColor;
4880   aSColor.R = (double)aColor.red() / 255.0;
4881   aSColor.G = (double)aColor.green() / 255.0;
4882   aSColor.B = (double)aColor.blue() / 255.0;
4883
4884   return aSColor;
4885 }
4886
4887 const char gSeparator = '_'; // character used to separate parameter names
4888 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
4889 const char gPathSep   = '|'; // character used to separate paths
4890
4891 /*!
4892  * \brief Store visual parameters
4893  *
4894  * This method is called just before the study document is saved.
4895  * Store visual parameters in AttributeParameter attribue(s)
4896  */
4897 void SMESHGUI::storeVisualParameters (int savePoint)
4898 {
4899   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
4900   if (!appStudy || !appStudy->studyDS())
4901     return;
4902   _PTR(Study) studyDS = appStudy->studyDS();
4903
4904   // componentName is used for encoding of entries when storing them in IParameters
4905   std::string componentName = myComponentSMESH->ComponentDataType();
4906   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
4907   //if (!aSComponent) return;
4908
4909   // IParameters
4910   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
4911                                                              componentName.c_str(),
4912                                                              savePoint);
4913   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
4914
4915   // store map of custom markers
4916   const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
4917   if( !aMarkerMap.empty() )
4918   {
4919     VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
4920     for( ; anIter != aMarkerMap.end(); anIter++ )
4921     {
4922       int anId = anIter->first;
4923       VTK::MarkerData aMarkerData = anIter->second;
4924       std::string aMarkerFileName = aMarkerData.first;
4925       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
4926       if( aMarkerTexture.size() < 3 )
4927         continue; // should contain at least width, height and the first value
4928
4929       QString aPropertyName( "texture" );
4930       aPropertyName += gSeparator;
4931       aPropertyName += QString::number( anId );
4932
4933       QString aPropertyValue = aMarkerFileName.c_str();
4934       aPropertyValue += gPathSep;
4935
4936       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
4937       ushort aWidth = *aTextureIter++;
4938       ushort aHeight = *aTextureIter++;
4939       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
4940       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
4941       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
4942         aPropertyValue += QString::number( *aTextureIter );
4943
4944       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
4945     }
4946   }
4947
4948   // viewers counters are used for storing view_numbers in IParameters
4949   int vtkViewers = 0;
4950
4951   // main cycle to store parameters of displayed objects
4952   QList<SUIT_ViewManager*> lst;
4953   QList<SUIT_ViewManager*>::Iterator it;
4954   getApp()->viewManagers(lst);
4955   for (it = lst.begin(); it != lst.end(); it++)
4956   {
4957     SUIT_ViewManager* vman = *it;
4958     QString vType = vman->getType();
4959
4960     // saving VTK actors properties
4961     if (vType == SVTK_Viewer::Type())
4962     {
4963       // store the clipping planes attached to the view manager
4964       SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
4965       SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
4966       if( anIter != myClippingPlaneInfoMap.end() )
4967         aClippingPlaneInfoList = anIter->second;
4968
4969       if( !aClippingPlaneInfoList.empty() ) {
4970         SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
4971         for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
4972         {
4973           const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
4974           SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
4975
4976           QString aPropertyName( "ClippingPlane" );
4977           aPropertyName += gSeparator;
4978           aPropertyName += QString::number( vtkViewers );
4979           aPropertyName += gSeparator;
4980           aPropertyName += QString::number( anId );
4981
4982           QString aPropertyValue = QString::number( (int)aPlane->GetOrientation() ).toLatin1().constData();
4983           aPropertyValue += gDigitsSep;
4984           aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
4985           aPropertyValue += gDigitsSep;
4986           aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
4987           aPropertyValue += gDigitsSep;
4988           aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
4989
4990           ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
4991         }
4992       }
4993
4994       QVector<SUIT_ViewWindow*> views = vman->getViews();
4995       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
4996       {
4997         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
4998         {
4999           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
5000           vtkActorCollection* allActors = aCopy.GetActors();
5001           allActors->InitTraversal();
5002           while (vtkActor* actor = allActors->GetNextActor())
5003           {
5004             if (actor->GetVisibility()) // store only visible actors
5005             {
5006               SMESH_Actor* aSmeshActor = 0;
5007               if (actor->IsA("SMESH_Actor"))
5008                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
5009               if (aSmeshActor && aSmeshActor->hasIO())
5010               {
5011                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
5012                 if (io->hasEntry())
5013                 {
5014                   // entry is "encoded" = it does NOT contain component adress,
5015                   // since it is a subject to change on next component loading
5016                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
5017
5018                   std::string param, vtkParam = vType.toLatin1().data();
5019                   vtkParam += gSeparator;
5020                   vtkParam += QString::number(vtkViewers).toLatin1().data();
5021                   vtkParam += gSeparator;
5022
5023                   // Visibility
5024                   param = vtkParam + "Visibility";
5025                   ip->setParameter(entry, param, "On");
5026
5027                   // Representation
5028                   param = vtkParam + "Representation";
5029                   ip->setParameter(entry, param, QString::number
5030                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
5031
5032                   // IsShrunk
5033                   param = vtkParam + "IsShrunk";
5034                   ip->setParameter(entry, param, QString::number
5035                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
5036
5037                   // Displayed entities
5038                   unsigned int aMode = aSmeshActor->GetEntityMode();
5039                   bool isE = aMode & SMESH_Actor::eEdges;
5040                   bool isF = aMode & SMESH_Actor::eFaces;
5041                   bool isV = aMode & SMESH_Actor::eVolumes;
5042
5043                   QString modeStr ("e");
5044                   modeStr += gDigitsSep; modeStr += QString::number(isE);
5045                   modeStr += gDigitsSep; modeStr += "f";
5046                   modeStr += gDigitsSep; modeStr += QString::number(isF);
5047                   modeStr += gDigitsSep; modeStr += "v";
5048                   modeStr += gDigitsSep; modeStr += QString::number(isV);
5049
5050                   param = vtkParam + "Entities";
5051                   ip->setParameter(entry, param, modeStr.toLatin1().data());
5052
5053                   // Colors (surface:edge:)
5054                   vtkFloatingPointType r, g, b;
5055
5056                   aSmeshActor->GetSufaceColor(r, g, b);
5057                   QString colorStr ("surface");
5058                   colorStr += gDigitsSep; colorStr += QString::number(r);
5059                   colorStr += gDigitsSep; colorStr += QString::number(g);
5060                   colorStr += gDigitsSep; colorStr += QString::number(b);
5061
5062                   aSmeshActor->GetBackSufaceColor(r, g, b);
5063                   colorStr += gDigitsSep; colorStr += "backsurface";
5064                   colorStr += gDigitsSep; colorStr += QString::number(r);
5065                   colorStr += gDigitsSep; colorStr += QString::number(g);
5066                   colorStr += gDigitsSep; colorStr += QString::number(b);
5067
5068                   aSmeshActor->GetEdgeColor(r, g, b);
5069                   colorStr += gDigitsSep; colorStr += "edge";
5070                   colorStr += gDigitsSep; colorStr += QString::number(r);
5071                   colorStr += gDigitsSep; colorStr += QString::number(g);
5072                   colorStr += gDigitsSep; colorStr += QString::number(b);
5073
5074                   aSmeshActor->GetNodeColor(r, g, b);
5075                   colorStr += gDigitsSep; colorStr += "node";
5076                   colorStr += gDigitsSep; colorStr += QString::number(r);
5077                   colorStr += gDigitsSep; colorStr += QString::number(g);
5078                   colorStr += gDigitsSep; colorStr += QString::number(b);
5079
5080                   param = vtkParam + "Colors";
5081                   ip->setParameter(entry, param, colorStr.toLatin1().data());
5082
5083                   // Sizes of lines and points
5084                   QString sizeStr ("line");
5085                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetLineWidth());
5086                   sizeStr += gDigitsSep; sizeStr += "shrink";
5087                   sizeStr += gDigitsSep; sizeStr += QString::number(aSmeshActor->GetShrinkFactor());
5088
5089                   param = vtkParam + "Sizes";
5090                   ip->setParameter(entry, param, sizeStr.toLatin1().data());
5091
5092                   // Point marker
5093                   QString markerStr;
5094
5095                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
5096                   if( aMarkerType == VTK::MT_USER ) {
5097                     markerStr += "custom";
5098                     markerStr += gDigitsSep;
5099                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
5100                   }
5101                   else {
5102                     markerStr += "std";
5103                     markerStr += gDigitsSep;
5104                     markerStr += QString::number( (int)aMarkerType );
5105                     markerStr += gDigitsSep;
5106                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
5107                   }
5108
5109                   param = vtkParam + "PointMarker";
5110                   ip->setParameter(entry, param, markerStr.toLatin1().data());
5111
5112                   // Opacity
5113                   param = vtkParam + "Opacity";
5114                   ip->setParameter(entry, param,
5115                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
5116
5117                   // Clipping
5118                   param = vtkParam + "ClippingPlane";
5119                   int aPlaneId = 0;
5120                   if( !aClippingPlaneInfoList.empty() ) {
5121                     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
5122                     for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
5123                     {
5124                       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
5125                       std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
5126                       SMESH::TActorList::iterator anIter2 = anActorList.begin();
5127                       for ( ; anIter2 != anActorList.end(); anIter2++ ) {
5128                         if( aSmeshActor == *anIter2 ) {
5129                           ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
5130                                             QString::number( anId ).toLatin1().constData() );                          
5131                           break;
5132                         }
5133                       }
5134                     }
5135                   }
5136                   if( aPlaneId == 0 )
5137                     ip->setParameter( entry, param, "Off" );
5138                 } // if (io->hasEntry())
5139               } // SMESH_Actor && hasIO
5140             } // isVisible
5141           } // while.. actors traversal
5142         } // if (vtkView)
5143       } // for (views)
5144       vtkViewers++;
5145     } // if (SVTK view model)
5146   } // for (viewManagers)
5147 }
5148
5149 // data structures for clipping planes processing
5150 typedef struct {
5151   int Id;
5152   vtkIdType Orientation;
5153   vtkFloatingPointType Distance;
5154   vtkFloatingPointType Angle[2];
5155 } TPlaneData;
5156 typedef std::list<TPlaneData>         TPlaneDataList;
5157 typedef std::map<int, TPlaneDataList> TPlaneDataMap;
5158
5159 typedef std::list<vtkActor*>          TActorList;
5160 typedef struct {
5161   int PlaneId;
5162   TActorList ActorList;
5163   SUIT_ViewManager* ViewManager;
5164 } TPlaneInfo;
5165 typedef std::list<TPlaneInfo>         TPlaneInfoList;
5166 typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
5167
5168 /*!
5169  * \brief Restore visual parameters
5170  *
5171  * This method is called after the study document is opened.
5172  * Restore visual parameters from AttributeParameter attribue(s)
5173  */
5174 void SMESHGUI::restoreVisualParameters (int savePoint)
5175 {
5176   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
5177   if (!appStudy || !appStudy->studyDS())
5178     return;
5179   _PTR(Study) studyDS = appStudy->studyDS();
5180
5181   // componentName is used for encoding of entries when storing them in IParameters
5182   std::string componentName = myComponentSMESH->ComponentDataType();
5183   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
5184   //if (!aSComponent) return;
5185
5186   // IParameters
5187   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
5188                                                              componentName.c_str(),
5189                                                              savePoint);
5190   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
5191
5192   // restore map of custom markers and map of clipping planes
5193   VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
5194   TPlaneDataMap aPlaneDataMap;
5195
5196   std::vector<std::string> properties = ip->getProperties();
5197   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
5198   {
5199     std::string property = *propIt;
5200     QString aPropertyName( property.c_str() );
5201     QString aPropertyValue( ip->getProperty( property ).c_str() );
5202
5203     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
5204     if( aPropertyNameList.isEmpty() )
5205       continue;
5206
5207     QString aPropertyType = aPropertyNameList[0];
5208     if( aPropertyType == "texture" )
5209     {
5210       if( aPropertyNameList.size() != 2 )
5211         continue;
5212
5213       bool ok = false;
5214       int anId = aPropertyNameList[1].toInt( &ok );
5215       if( !ok || anId < 1 )
5216         continue;
5217
5218       QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
5219       if( aPropertyValueList.size() != 2 )
5220         continue;
5221
5222       std::string aMarkerFileName = aPropertyValueList[0].toStdString();
5223       QString aMarkerTextureString = aPropertyValueList[1];
5224       QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
5225       if( aMarkerTextureStringList.size() != 3 )
5226         continue;
5227
5228       ok = false;
5229       ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
5230       if( !ok )
5231         continue;
5232
5233       ok = false;
5234       ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
5235       if( !ok )
5236         continue;
5237
5238       VTK::MarkerTexture aMarkerTexture;
5239       aMarkerTexture.push_back( aWidth );
5240       aMarkerTexture.push_back( aHeight );
5241
5242       QString aMarkerTextureData = aMarkerTextureStringList[2];
5243       for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
5244       {
5245         QChar aChar = aMarkerTextureData.at( i );
5246         if( aChar.isDigit() )
5247           aMarkerTexture.push_back( aChar.digitValue() );
5248       }
5249
5250       aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
5251     }
5252     else if( aPropertyType == "ClippingPlane" )
5253     {
5254       if( aPropertyNameList.size() != 3 )
5255         continue;
5256
5257       bool ok = false;
5258       int aViewId = aPropertyNameList[1].toInt( &ok );
5259       if( !ok || aViewId < 0 )
5260         continue;
5261
5262       ok = false;
5263       int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
5264       if( !ok || aClippingPlaneId < 0 )
5265         continue;
5266
5267       QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
5268       if( aPropertyValueList.size() != 4 )
5269         continue;
5270
5271       TPlaneData aPlaneData;
5272       aPlaneData.Id = aClippingPlaneId;
5273
5274       ok = false;
5275       aPlaneData.Orientation = aPropertyValueList[0].toInt( &ok );
5276       if( !ok )
5277         continue;
5278
5279       ok = false;
5280       aPlaneData.Distance = aPropertyValueList[1].toDouble( &ok );
5281       if( !ok )
5282         continue;
5283
5284       ok = false;
5285       aPlaneData.Angle[0] = aPropertyValueList[2].toDouble( &ok );
5286       if( !ok )
5287         continue;
5288
5289       ok = false;
5290       aPlaneData.Angle[1] = aPropertyValueList[3].toDouble( &ok );
5291       if( !ok )
5292         continue;
5293
5294       TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
5295       aPlaneDataList.push_back( aPlaneData );      
5296     }
5297   }
5298
5299   TPlaneInfoMap aPlaneInfoMap;
5300
5301   std::vector<std::string> entries = ip->getEntries();
5302
5303   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
5304   {
5305     // entry is a normal entry - it should be "decoded" (setting base adress of component)
5306     QString entry (ip->decodeEntry(*entIt).c_str());
5307
5308     // Check that the entry corresponds to a real object in the Study
5309     // as the object may be deleted or modified after the visual state is saved.
5310     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
5311     if (!so) continue; //Skip the not existent entry
5312
5313     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
5314     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
5315
5316     std::vector<std::string>::iterator namesIt = paramNames.begin();
5317     std::vector<std::string>::iterator valuesIt = paramValues.begin();
5318
5319     // actors are stored in a map after displaying of them for
5320     // quicker access in the future: map < viewID to actor >
5321     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
5322
5323     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
5324     {
5325       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
5326       // '_' is used as separator and should not be used in viewer type or parameter names.
5327       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
5328       if (lst.size() != 3)
5329         continue;
5330
5331       QString viewerTypStr = lst[0];
5332       QString viewIndexStr = lst[1];
5333       QString paramNameStr = lst[2];
5334
5335       bool ok;
5336       int viewIndex = viewIndexStr.toUInt(&ok);
5337       if (!ok) // bad conversion of view index to integer
5338         continue;
5339
5340       // viewers
5341       if (viewerTypStr == SVTK_Viewer::Type())
5342       {
5343         SMESH_Actor* aSmeshActor = 0;
5344         if (vtkActors.IsBound(viewIndex))
5345           aSmeshActor = vtkActors.Find(viewIndex);
5346
5347         QList<SUIT_ViewManager*> lst;
5348         getApp()->viewManagers(viewerTypStr, lst);
5349
5350         // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
5351         SUIT_ViewManager* vman = NULL;
5352         if (viewIndex >= 0 && viewIndex < lst.count())
5353           vman = lst.at(viewIndex);
5354
5355         if (paramNameStr == "Visibility")
5356         {
5357           if (!aSmeshActor && displayer() && vman)
5358           {
5359             SUIT_ViewModel* vmodel = vman->getViewModel();
5360             // SVTK view model can be casted to SALOME_View
5361             displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
5362
5363             // store displayed actor in a temporary map for quicker
5364             // access later when restoring other parameters
5365             SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
5366             vtkRenderer* Renderer = vtkView->getRenderer();
5367             VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
5368             vtkActorCollection* theActors = aCopy.GetActors();
5369             theActors->InitTraversal();
5370             bool isFound = false;
5371             vtkActor *ac = theActors->GetNextActor();
5372             for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
5373               if (ac->IsA("SMESH_Actor")) {
5374                 SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
5375                 if (aGeomAc->hasIO()) {
5376                   Handle(SALOME_InteractiveObject) io =
5377                     Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
5378                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
5379                     isFound = true;
5380                     vtkActors.Bind(viewIndex, aGeomAc);
5381                   }
5382                 }
5383               }
5384             }
5385           }
5386         } // if (paramNameStr == "Visibility")
5387         else
5388         {
5389           // the rest properties "work" with SMESH_Actor
5390           if (aSmeshActor)
5391           {
5392             QString val ((*valuesIt).c_str());
5393
5394             // Representation
5395             if (paramNameStr == "Representation") {
5396               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
5397             }
5398             // IsShrunk
5399             else if (paramNameStr == "IsShrunk") {
5400               if (val.toInt()) {
5401                 if (!aSmeshActor->IsShrunk())
5402                   aSmeshActor->SetShrink();
5403               }
5404               else {
5405                 if (aSmeshActor->IsShrunk())
5406                   aSmeshActor->UnShrink();
5407               }
5408             }
5409             // Displayed entities
5410             else if (paramNameStr == "Entities") {
5411               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
5412               if (mode.count() == 6) {
5413                 if (mode[0] != "e" || mode[2]  != "f" || mode[4] != "v") {
5414                   MESSAGE("Invalid order of data in Entities, must be: "
5415                           "e:0/1:f:0/1:v:0/1");
5416                 }
5417                 else {
5418                   unsigned int aMode = aSmeshActor->GetEntityMode();
5419                   unsigned int aNewMode =
5420                     (int(SMESH_Actor::eEdges  ) * mode[1].toInt()) |
5421                     (int(SMESH_Actor::eFaces  ) * mode[3].toInt()) |
5422                     (int(SMESH_Actor::eVolumes) * mode[5].toInt());
5423                   if (aNewMode != aMode)
5424                     aSmeshActor->SetEntityMode(aNewMode);
5425                 }
5426               }
5427             }
5428             // Colors
5429             else if (paramNameStr == "Colors") {
5430               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
5431               if (colors.count() == 16) {
5432                 if (colors[0] != "surface" || colors[4]  != "backsurface" ||
5433                     colors[8] != "edge"    || colors[12] != "node") {
5434                   MESSAGE("Invalid order of data in Colors, must be: "
5435                           "surface:r:g:b:backsurface:r:g:b:edge:r:g:b:node:r:g:b");
5436                 }
5437                 else {
5438                   aSmeshActor->SetSufaceColor(colors[1].toFloat(), colors[2].toFloat(), colors[3].toFloat());
5439                   aSmeshActor->SetBackSufaceColor(colors[5].toFloat(), colors[6].toFloat(), colors[7].toFloat());
5440                   aSmeshActor->SetEdgeColor(colors[9].toFloat(), colors[10].toFloat(), colors[11].toFloat());
5441                   aSmeshActor->SetNodeColor(colors[13].toFloat(), colors[14].toFloat(), colors[15].toFloat());
5442                 }
5443               }
5444             }
5445             // Sizes of lines and points
5446             else if (paramNameStr == "Sizes") {
5447               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
5448               if (sizes.count() == 4) {
5449                 if (sizes[0] != "line" || sizes[2] != "shrink") {
5450                   MESSAGE("Invalid order of data in Sizes, must be: "
5451                           "line:int:shrink:float");
5452                 }
5453                 else {
5454                   aSmeshActor->SetLineWidth(sizes[1].toInt());
5455                   aSmeshActor->SetShrinkFactor(sizes[3].toFloat());
5456                 }
5457               }
5458               else if (sizes.count() == 6) { // just to support old format
5459                 if (sizes[0] != "line" || sizes[2]  != "node" || sizes[4] != "shrink") {
5460                   MESSAGE("Invalid order of data in Sizes, must be: "
5461                           "line:int:node:int:shrink:float");
5462                 }
5463                 else {
5464                   aSmeshActor->SetLineWidth(sizes[1].toInt());
5465                   //aSmeshActor->SetNodeSize(sizes[3].toInt()); // made obsolete
5466                   aSmeshActor->SetShrinkFactor(sizes[5].toFloat());
5467                 }
5468               }
5469             }
5470             // Point marker
5471             else if (paramNameStr == "PointMarker") {
5472               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
5473               if( data.count() >= 2 ) {
5474                 bool ok = false;
5475                 int aParam1 = data[1].toInt( &ok );
5476                 if( ok ) {
5477                   if( data[0] == "std" && data.count() == 3 ) {
5478                     int aParam2 = data[2].toInt( &ok );
5479                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
5480                   }
5481                   else if( data[0] == "custom" ) {
5482                     VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
5483                     if( markerIt != aMarkerMap.end() ) {
5484                       VTK::MarkerData aMarkerData = markerIt->second;
5485                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
5486                     }
5487                   }
5488                 }
5489               }
5490             }
5491             // Opacity
5492             else if (paramNameStr == "Opacity") {
5493               aSmeshActor->SetOpacity(val.toFloat());
5494             }
5495             // Clipping
5496             else if (paramNameStr.startsWith("ClippingPlane")) {
5497               QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
5498               // old format - val looks like "Off" or "0:0.5:0:0" (orientation, distance, two angles)
5499               // new format - val looks like "Off" or "0" (plane id)
5500               // (note: in new format "Off" value is used only for consistency,
5501               //  so it is processed together with values in old format)
5502               bool anIsOldFormat = ( vals.count() == 4 || val == "Off" );
5503               if( anIsOldFormat ) {
5504                 if (paramNameStr == "ClippingPlane1" || val == "Off")
5505                   aSmeshActor->RemoveAllClippingPlanes();
5506                 if (val != "Off") {
5507                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
5508                   double aDistance = vals[1].toFloat();
5509                   vtkFloatingPointType anAngle[2];
5510                   anAngle[0] = vals[2].toFloat();
5511                   anAngle[1] = vals[3].toFloat();
5512
5513                   QList<SUIT_ViewManager*> lst;
5514                   getApp()->viewManagers(viewerTypStr, lst);
5515                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
5516                   if (viewIndex >= 0 && viewIndex < lst.count()) {
5517                     SUIT_ViewManager* vman = lst.at(viewIndex);
5518                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
5519
5520                     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
5521
5522                     SMESH::TActorList anActorList;
5523                     anActorList.push_back( aSmeshActor );
5524                     SMESH::OrientedPlane* aPlane =
5525                       SMESHGUI_ClippingDlg::AddPlane(anActorList, vtkView, anOrientation, aDistance, anAngle);
5526                     if( aPlane ) {
5527                       SMESH::ClippingPlaneInfo aClippingPlaneInfo;
5528                       aClippingPlaneInfo.Plane = aPlane;
5529                       aClippingPlaneInfo.ActorList = anActorList;
5530                       aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
5531                     }
5532                   }
5533                 }
5534               }
5535               else {
5536                 bool ok = false;
5537                 int aPlaneId = val.toInt( &ok );
5538                 if( ok && aPlaneId >= 0 ) {
5539                   bool anIsDefinedPlane = false;
5540                   TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
5541                   TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
5542                   for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
5543                     TPlaneInfo& aPlaneInfo = *anIter;
5544                     if( aPlaneInfo.PlaneId == aPlaneId ) {
5545                       aPlaneInfo.ActorList.push_back( aSmeshActor );
5546                       anIsDefinedPlane = true;
5547                       break;
5548                     }
5549                   }
5550                   if( !anIsDefinedPlane ) {
5551                     TPlaneInfo aPlaneInfo;
5552                     aPlaneInfo.PlaneId = aPlaneId;
5553                     aPlaneInfo.ActorList.push_back( aSmeshActor );
5554                     aPlaneInfo.ViewManager = vman;
5555
5556                     // to make the list sorted by plane id
5557                     anIter = aPlaneInfoList.begin();
5558                     for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
5559                       const TPlaneInfo& aPlaneInfoRef = *anIter;
5560                       if( aPlaneInfoRef.PlaneId > aPlaneId )
5561                         break;
5562                     }
5563                     aPlaneInfoList.insert( anIter, aPlaneInfo );
5564                   }
5565                 }
5566               }
5567             }
5568           } // if (aSmeshActor)
5569         } // other parameters than Visibility
5570       }
5571     } // for names/parameters iterator
5572   } // for entries iterator
5573
5574   // take into account planes with empty list of actors referred to them
5575   QList<SUIT_ViewManager*> aVMList;
5576   getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
5577
5578   TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
5579   for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
5580     int aViewId = aPlaneDataIter->first;
5581     if( aViewId >= 0 && aViewId < aVMList.count() ) {
5582       SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
5583
5584       const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
5585
5586       TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
5587       TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
5588       for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
5589         const TPlaneData& aPlaneData = *anIter2;
5590         int aPlaneId = aPlaneData.Id;
5591
5592         bool anIsFound = false;
5593         TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
5594         for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
5595           const TPlaneInfo& aPlaneInfo = *anIter3;
5596           if( aPlaneInfo.PlaneId == aPlaneId ) {
5597             anIsFound = true;
5598             break;
5599           }
5600         }
5601
5602         if( !anIsFound ) {
5603           TPlaneInfo aPlaneInfo; // ActorList field is empty
5604           aPlaneInfo.PlaneId = aPlaneId;
5605           aPlaneInfo.ViewManager = aViewManager;
5606
5607           // to make the list sorted by plane id
5608           TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
5609           for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
5610             const TPlaneInfo& aPlaneInfoRef = *anIter4;
5611             if( aPlaneInfoRef.PlaneId > aPlaneId )
5612               break;
5613           }
5614           aPlaneInfoList.insert( anIter4, aPlaneInfo );
5615         }
5616       }
5617     }
5618   }
5619
5620   // add clipping planes to actors according to the restored parameters
5621   // and update the clipping plane map
5622   TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
5623   for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
5624     int aViewId = anIter1->first;
5625     const TPlaneInfoList& aPlaneInfoList = anIter1->second;
5626
5627     TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
5628     if( anIter2 == aPlaneDataMap.end() )
5629       continue;
5630     const TPlaneDataList& aPlaneDataList = anIter2->second;
5631
5632     TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
5633     for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
5634       const TPlaneInfo& aPlaneInfo = *anIter3;
5635       int aPlaneId = aPlaneInfo.PlaneId;
5636       const TActorList& anActorList = aPlaneInfo.ActorList;
5637       SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
5638       if( !aViewManager )
5639         continue;
5640
5641       SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
5642       if( !aViewWindow )
5643         continue;
5644
5645       SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
5646
5647       TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
5648       for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
5649         const TPlaneData& aPlaneData = *anIter4;
5650         if( aPlaneData.Id == aPlaneId ) {
5651           SMESH::OrientedPlane* aPlane =
5652             SMESHGUI_ClippingDlg::AddPlane( anActorList,
5653                                             aViewWindow,
5654                                             (SMESH::Orientation)aPlaneData.Orientation,
5655                                             aPlaneData.Distance,
5656                                             aPlaneData.Angle );
5657           if( aPlane ) {
5658             SMESH::ClippingPlaneInfo aClippingPlaneInfo;
5659             aClippingPlaneInfo.Plane = aPlane;
5660             aClippingPlaneInfo.ActorList = anActorList;
5661             aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
5662           }
5663           break;
5664         }
5665       }
5666     }
5667   }
5668
5669   // update all VTK views
5670   QList<SUIT_ViewManager*> lst;
5671   getApp()->viewManagers(lst);
5672   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
5673     SUIT_ViewModel* vmodel = (*it)->getViewModel();
5674     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
5675       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
5676       vtkView->getRenderer()->ResetCameraClippingRange();
5677       vtkView->Repaint();
5678     }
5679   }
5680 }
5681
5682 /*!
5683   \brief Adds preferences for dfont of VTK viewer
5684   \param label label
5685   \param pIf group identifier
5686   \param param parameter
5687   \return identifier of preferences
5688 */
5689 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param )
5690 {
5691   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "VISU", param );
5692
5693   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
5694
5695   QStringList fam;
5696   fam.append( tr( "SMESH_FONT_ARIAL" ) );
5697   fam.append( tr( "SMESH_FONT_COURIER" ) );
5698   fam.append( tr( "SMESH_FONT_TIMES" ) );
5699
5700   setPreferenceProperty( tfont, "fonts", fam );
5701
5702   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
5703   setPreferenceProperty( tfont, "features", f );
5704
5705   return tfont;
5706 }
5707
5708 /*!
5709   \brief Actions after hypothesis edition
5710   Updates object browser after hypothesis edition
5711 */
5712 void SMESHGUI::onHypothesisEdit( int result )
5713 {
5714   if( result == 1 )
5715     SMESHGUI::Modified();
5716   updateObjBrowser( true );
5717 }
5718
5719
5720 /*!
5721   \brief Signal handler closing(SUIT_ViewWindow*) of a view
5722   \param pview view being closed
5723 */
5724 void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
5725 #ifndef DISABLE_PLOT2DVIEWER
5726   //Crear all Plot2d Viewers if need.
5727   SMESH::ClearPlot2Viewers(pview);
5728 #endif  
5729 }
5730
5731 /*!
5732   \brief Connects or disconnects signals about activating and cloning view on the module slots
5733   \param pview view which is connected/disconnected
5734 */
5735 void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
5736   if(!pview)
5737     return;
5738   
5739   SUIT_ViewManager* viewMgr = pview->getViewManager();
5740   if ( viewMgr ) {
5741     disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
5742                 this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
5743     
5744     connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
5745              this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
5746   }
5747 }
5748