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