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