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