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