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