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