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