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