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