Salome HOME
Bug IPAL18040 - 4.x: color of the displayed edge group doesn't correspond to set...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHGUI.h"
28
29 #include "SMESH_Client.hxx"
30 #include "SMESHGUI_NodesDlg.h"
31 #include "SMESHGUI_TransparencyDlg.h"
32 #include "SMESHGUI_ClippingDlg.h"
33 #include "SMESHGUI_GroupDlg.h"
34 #include "SMESHGUI_RemoveNodesDlg.h"
35 #include "SMESHGUI_RemoveElementsDlg.h"
36 #include "SMESHGUI_MeshInfosDlg.h"
37 #include "SMESHGUI_StandardMeshInfosDlg.h"
38 #include "SMESHGUI_Preferences_ColorDlg.h"
39 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
40 #include "SMESHGUI_Preferences_SelectionDlg.h"
41 #include "SMESHGUI_Hypotheses.h"
42 #include "SMESHGUI_MoveNodesDlg.h"
43 #include "SMESHGUI_AddMeshElementDlg.h"
44 #include "SMESHGUI_AddQuadraticElementDlg.h"
45 #include "SMESHGUI_FilterDlg.h"
46 #include "SMESHGUI_FilterLibraryDlg.h"
47 #include "SMESHGUI_SingleEditDlg.h"
48 #include "SMESHGUI_MultiEditDlg.h"
49 #include "SMESHGUI_GroupOpDlg.h"
50 #include "SMESHGUI_DeleteGroupDlg.h"
51 #include "SMESHGUI_SmoothingDlg.h"
52 #include "SMESHGUI_RenumberingDlg.h"
53 #include "SMESHGUI_ExtrusionDlg.h"
54 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
55 #include "SMESHGUI_RevolutionDlg.h"
56 #include "SMESHGUI_TranslationDlg.h"
57 #include "SMESHGUI_RotationDlg.h"
58 #include "SMESHGUI_SymmetryDlg.h"
59 #include "SMESHGUI_SewingDlg.h"
60 #include "SMESHGUI_EditMeshDlg.h"
61 #include "SMESHGUI_MeshPatternDlg.h"
62 #include "SMESHGUI_Selection.h"
63 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
64 #include "SMESHGUI_ConvToQuadOp.h"
65 #include "SMESHGUI_MeshOp.h"
66 #include "SMESHGUI_Displayer.h"
67 #include "SMESHGUI_MakeNodeAtPointDlg.h"
68 #include "SMESHGUI_BuildCompoundDlg.h"
69 #include "SMESHGUI_ComputeDlg.h"
70
71 #include "SMESHGUI_Utils.h"
72 #include "SMESHGUI_GEOMGenUtils.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_Actor.h"
81 #include "SMESH_Object.h"
82 #include "SMESH_TypeFilter.hxx"
83
84 #include "SalomeApp_Tools.h"
85 #include "SalomeApp_Study.h"
86 #include "SalomeApp_Application.h"
87 #include "SalomeApp_CheckFileDlg.h"
88 #include "SalomeApp_ImportOperation.h"
89
90 #include "LightApp_DataOwner.h"
91 #include "LightApp_Preferences.h"
92 #include "LightApp_VTKSelector.h"
93 #include "LightApp_Operation.h"
94 #include "LightApp_UpdateFlags.h"
95 #include "LightApp_NameDlg.h"
96
97 #include <SVTK_ViewWindow.h>
98 #include <SVTK_ViewModel.h>
99 #include <SVTK_InteractorStyle.h>
100 #include <SVTK_RenderWindowInteractor.h>
101 #include <SVTK_ViewManager.h>
102
103 #include "OB_Browser.h"
104
105 #include "SUIT_Tools.h"
106 #include "SUIT_MessageBox.h"
107 #include "SUIT_ResourceMgr.h"
108 #include "SUIT_FileDlg.h"
109 #include "SUIT_Desktop.h"
110 #include "SUIT_OverrideCursor.h"
111 #include "SUIT_Study.h"
112 #include "SUIT_Session.h"
113
114 #include "QtxPopupMgr.h"
115
116 #include "SALOME_ListIO.hxx"
117 #include "SALOME_ListIteratorOfListIO.hxx"
118 #include "SALOME_InteractiveObject.hxx"
119 #include "SALOME_NamingService.hxx"
120 #include "SALOME_LifeCycleCORBA.hxx"
121
122 #include "SALOMEconfig.h"
123 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
125
126 // QT Includes
127 #define  INCLUDE_MENUITEM_DEF
128 #include <qpopupmenu.h>
129 #include <qstring.h>
130 #include <qwidget.h>
131 #include <qaction.h>
132
133 // BOOST Includes
134 #include <boost/shared_ptr.hpp>
135
136 // VTK Includes
137 #include <vtkRenderer.h>
138 #include <vtkRenderWindow.h>
139 #include <vtkActorCollection.h>
140 #include <vtkScalarBarActor.h>
141 #include <vtkUnstructuredGrid.h>
142
143 #include "utilities.h"
144
145 #include "SALOMEDS_Study.hxx"
146 #include "SALOMEDSClient_StudyBuilder.hxx"
147 #include "SALOMEDSClient_SComponent.hxx"
148
149 #include <Standard_ErrorHandler.hxx>
150
151 using namespace std;
152
153 //namespace{
154   // Declarations
155   //=============================================================
156   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
157                             int theCommandID);
158
159   void ExportMeshToFile(int theCommandID);
160
161   void SetDisplayMode(int theCommandID);
162
163   void SetDisplayEntity(int theCommandID);
164
165   void Control( int theCommandID );
166
167
168   // Definitions
169   //=============================================================
170   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
171                             int theCommandID)
172   {
173     QStringList filter;
174     string myExtension;
175
176     if(theCommandID == 113){
177       filter.append(QObject::tr("MED files (*.med)"));
178       filter.append(QObject::tr("All files (*)"));
179     }else if (theCommandID == 112){
180       filter.append(QObject::tr("IDEAS files (*.unv)"));
181     }else if (theCommandID == 111){
182       filter.append(QObject::tr("DAT files (*.dat)"));
183     }
184     QString filename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
185                                                 "",
186                                                 filter,
187                                                 QObject::tr("Import mesh"),
188                                                 true);
189     if(!filename.isEmpty()) {
190       SUIT_OverrideCursor wc;
191       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
192
193       try {
194         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
195         switch ( theCommandID ) {
196         case 112:
197           {
198             aMeshes->length( 1 );
199             aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1());
200             break;
201           }
202         case 113:
203           {
204             SMESH::DriverMED_ReadStatus res;
205             aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res);
206             if ( res != SMESH::DRS_OK ) {
207               wc.suspend();
208               SUIT_MessageBox::warn1(SMESHGUI::desktop(),
209                                     QObject::tr("SMESH_WRN_WARNING"),
210                                     QObject::tr(QString("SMESH_DRS_%1").arg(res)),
211                                     QObject::tr("SMESH_BUT_OK"));
212               aMeshes->length( 0 );
213               wc.resume();
214             }
215             break;
216           }
217         }
218
219         bool isEmpty = false;
220         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
221           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
222           if ( aMeshSO ) {
223             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
224             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
225             aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED");
226             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
227               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
228           } else
229             isEmpty = true;
230         }
231
232         if ( isEmpty ) {
233           wc.suspend();
234           SUIT_MessageBox::warn1(SMESHGUI::desktop(),
235                                 QObject::tr("SMESH_WRN_WARNING"),
236                                 QObject::tr("SMESH_DRS_EMPTY"),
237                                 QObject::tr("SMESH_BUT_OK"));
238           wc.resume();
239         }
240
241         SMESHGUI::GetSMESHGUI()->updateObjBrowser();
242       }
243       catch (const SALOME::SALOME_Exception& S_ex){
244         wc.suspend();
245         SalomeApp_Tools::QtCatchCorbaException(S_ex);
246         wc.resume();
247       }
248     }
249   }
250
251
252   void ExportMeshToFile( int theCommandID )
253   {
254     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
255     SALOME_ListIO selected;
256     if( aSel )
257       aSel->selectedObjects( selected );
258
259     if(selected.Extent()){
260       Handle(SALOME_InteractiveObject) anIObject = selected.First();
261       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
262       if ( !aMesh->_is_nil() ) {
263         QString aFilter, aTitle = QObject::tr("Export mesh");
264         QMap<QString, SMESH::MED_VERSION> aFilterMap;
265         QMap<QString, int> aFilterMapSTL;
266         switch ( theCommandID ) {
267         case 125:
268         case 122:
269           {
270             if (aMesh->HasDuplicatedGroupNamesMED()) {
271               int aRet = SUIT_MessageBox::warn2
272                 (SMESHGUI::desktop(),
273                  QObject::tr("SMESH_WRN_WARNING"),
274                  QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()),
275                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
276                  0, 1, 0);
277               if (aRet)
278                 return;
279             }
280
281             aFilterMap.insert( QObject::tr("MED 2.1 (*.med)"), SMESH::MED_V2_1 );
282             aFilterMap.insert( QObject::tr("MED 2.2 (*.med)"), SMESH::MED_V2_2 );
283           }
284           break;
285         case 124:
286         case 121:
287           aFilter = QObject::tr("DAT files (*.dat)");
288           break;
289         case 126:
290         case 123:
291           {
292             if (aMesh->NbPyramids()) {
293               int aRet = SUIT_MessageBox::warn2
294                 (SMESHGUI::desktop(),
295                  QObject::tr("SMESH_WRN_WARNING"),
296                  QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
297                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
298                  0, 1, 0);
299               if (aRet)
300                 return;
301             }
302             aFilter = QObject::tr("IDEAS files (*.unv)");
303           }
304           break;
305         case 140:
306         case 141:
307           {
308             // export STL
309             /*
310               there must be check on others mesh elements not equal triangles
311             */
312             if (aMesh->NbTriangles() < 1) {
313               SUIT_MessageBox::warn1
314                 (SMESHGUI::desktop(),
315                  QObject::tr("SMESH_WRN_WARNING"),
316                  QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()),
317                  QObject::tr("SMESH_BUT_OK"));
318               return;
319             }
320             if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
321               int aRet = SUIT_MessageBox::warn2
322                 (SMESHGUI::desktop(),
323                  QObject::tr("SMESH_WRN_WARNING"),
324                  QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
325                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
326                  0, 1, 0);
327               if (aRet)
328                 return;
329             }
330
331             aFilterMapSTL.insert( QObject::tr("STL ASCII  (*.stl)"), 1 ); // 1 - ASCII mode
332             aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
333           }
334           break;
335         default:
336           return;
337         }
338
339         QString aFilename;
340         SMESH::MED_VERSION aFormat;
341         // Init the parameter with the default value
342         bool aIsASCII_STL = true;
343         bool toCreateGroups = false;
344         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
345         if ( resMgr )
346           toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
347
348         if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
349
350           aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
351
352         else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
353           QStringList filters;
354           QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
355           for ( ; it != aFilterMapSTL.end(); ++it )
356             filters.push_back( it.key() );
357
358           SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
359           fd->setCaption( aTitle );
360           fd->setFilters( filters );
361           fd->setSelectedFilter( QObject::tr("STL ASCII  (*.stl)") );
362           bool is_ok = false;
363           while (!is_ok) {
364             fd->exec();
365             aFilename = fd->selectedFile();
366             aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false;
367             is_ok = true;
368           }
369           delete fd;
370         }
371         else {
372           QStringList filters;
373           QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
374           for ( ; it != aFilterMap.end(); ++it )
375             filters.push_back( it.key() );
376
377           //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
378           SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
379             ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true );
380           fd->setCaption( aTitle );
381           fd->setFilters( filters );
382           fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
383           fd->SetChecked(toCreateGroups);
384           bool is_ok = false;
385           while (!is_ok) {
386             fd->exec();
387             aFilename = fd->selectedFile();
388             aFormat = aFilterMap[fd->selectedFilter()];
389             is_ok = true;
390             if ( !aFilename.isEmpty()
391                  && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0)
392                  && aFormat==SMESH::MED_V2_1) {
393               int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
394                                                 QObject::tr("SMESH_WRN_WARNING"),
395                                                 QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
396                                                 QObject::tr("SMESH_BUT_YES"),
397                                                 QObject::tr("SMESH_BUT_NO"),
398                                                 0,1,0);
399               if (aRet) {
400                 is_ok = false;
401               }
402             }
403           }
404           toCreateGroups = fd->IsChecked();
405           delete fd;
406         }
407         if ( !aFilename.isEmpty() ) {
408           // Check whether the file already exists and delete it if yes
409           QFile aFile( aFilename );
410           if ( aFile.exists() )
411             aFile.remove();
412           SUIT_OverrideCursor wc;
413
414           try {
415             bool Renumber = false ;
416             // PAL 14172  : Check of we have to renumber or not from the preferences before export
417             if (resMgr)
418               Renumber= resMgr->booleanValue("SMESH","renumbering");
419             if (Renumber){
420               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
421               aMeshEditor->RenumberNodes();
422               aMeshEditor->RenumberElements();
423               if ( SMESHGUI::automaticUpdate() )
424                 SMESH::UpdateView();
425               }
426             switch ( theCommandID ) {
427             case 125:
428             case 122:
429               aMesh->ExportToMED( aFilename.latin1(), toCreateGroups, aFormat );
430               break;
431             case 124:
432             case 121:
433               aMesh->ExportDAT( aFilename.latin1() );
434               break;
435             case 126:
436             case 123:
437               aMesh->ExportUNV( aFilename.latin1() );
438               break;
439             case 140:
440             case 141:
441               aMesh->ExportSTL( aFilename.latin1(), aIsASCII_STL );
442               break;
443             default:
444               break;
445             }
446           }
447           catch (const SALOME::SALOME_Exception& S_ex){
448             wc.suspend();
449             SUIT_MessageBox::warn1(SMESHGUI::desktop(),
450                                     QObject::tr("SMESH_WRN_WARNING"),
451                                     QObject::tr("SMESH_EXPORT_FAILED"),
452                                     QObject::tr("SMESH_BUT_OK"));
453             wc.resume();
454           }
455         }
456       }
457     }
458   }
459
460   inline void InverseEntityMode(unsigned int& theOutputMode,
461                                 unsigned int theMode)
462   {
463     bool anIsNotPresent = ~theOutputMode & theMode;
464     if(anIsNotPresent)
465       theOutputMode |= theMode;
466     else
467       theOutputMode &= ~theMode;
468   }
469
470   void SetDisplayEntity(int theCommandID){
471     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
472     SALOME_ListIO selected;
473     if( aSel )
474       aSel->selectedObjects( selected );
475
476     if(selected.Extent() >= 1){
477       SALOME_ListIteratorOfListIO It( selected );
478       for(; It.More(); It.Next()){
479         Handle(SALOME_InteractiveObject) IObject = It.Value();
480         if(IObject->hasEntry()){
481           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
482             unsigned int aMode = anActor->GetEntityMode();
483             switch(theCommandID){
484             case 217:
485               InverseEntityMode(aMode,SMESH_Actor::eEdges);
486               break;
487             case 218:
488               InverseEntityMode(aMode,SMESH_Actor::eFaces);
489               break;
490             case 219:
491               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
492               break;
493             case 220:
494               aMode = SMESH_Actor::eAllEntity;
495               break;
496             }
497             if(aMode)
498               anActor->SetEntityMode(aMode);
499           }
500         }
501       }
502     }
503   }
504
505   void AutoColor(){
506     SALOME_ListIO selected;
507     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
508     if( !app )
509       return;
510
511     LightApp_SelectionMgr* aSel = app->selectionMgr();
512     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
513     if( !aSel || !appStudy )
514       return;
515
516     aSel->selectedObjects( selected );
517     if( selected.IsEmpty() )
518       return;
519
520     Handle(SALOME_InteractiveObject) anIObject = selected.First();
521
522     _PTR(Study) aStudy = appStudy->studyDS();
523     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
524     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
525     if( aMainObject->_is_nil() )
526       return;
527
528     aMainObject->SetAutoColor( true );
529
530     QValueList<SALOMEDS::Color> aReservedColors;
531
532     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
533     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
534     {
535       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
536       SALOMEDS::Color aCurrentColor = aGroupObject->GetColor();
537
538       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
539       aGroupObject->SetColor( aColor );
540       aReservedColors.append( aColor );
541
542       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
543       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str()))
544       {
545         if( aGroupObject->GetType() == SMESH::NODE )
546           anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
547         else if( aGroupObject->GetType() == SMESH::EDGE )
548           anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
549         else
550           anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
551       }
552     }
553
554     SMESH::RepaintCurrentView();
555   }
556
557   void DisableAutoColor(){
558     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
559     SALOME_ListIO selected;
560     if( aSel )
561       aSel->selectedObjects( selected );
562
563     if(selected.Extent()){
564       Handle(SALOME_InteractiveObject) anIObject = selected.First();
565       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
566       if ( !aMesh->_is_nil() ) {
567         aMesh->SetAutoColor( false );
568       }
569     }
570   }
571
572   void SetDisplayMode(int theCommandID){
573     SALOME_ListIO selected;
574     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
575     if( !app )
576       return;
577
578     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
579     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
580     if( !aSel || !appStudy )
581       return;
582
583     _PTR(Study) aStudy = appStudy->studyDS();
584
585     aSel->selectedObjects( selected );
586
587     if(selected.Extent() >= 1){
588       switch(theCommandID){
589       case 1134:{
590         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
591         new SMESHGUI_ClippingDlg( SMESHGUI::GetSMESHGUI(), "", false );
592         return;
593       }
594       case 1133:{
595         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
596         new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI(), "", false );
597         return;
598       }}
599       SALOME_ListIteratorOfListIO It( selected );
600       for(; It.More(); It.Next()){
601         Handle(SALOME_InteractiveObject) IObject = It.Value();
602         if(IObject->hasEntry()){
603           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
604             switch(theCommandID){
605             case 211:
606               anActor->SetRepresentation(SMESH_Actor::eEdge);
607               break;
608             case 212:
609               anActor->SetRepresentation(SMESH_Actor::eSurface);
610               break;
611             case 213:
612               if(anActor->IsShrunk())
613                 anActor->UnShrink();
614               else
615                 anActor->SetShrink();
616               break;
617             case 215:
618               anActor->SetRepresentation(SMESH_Actor::ePoint);
619               break;
620             case 1132:{
621               vtkFloatingPointType color[3];
622               anActor->GetSufaceColor(color[0], color[1], color[2]);
623               int c0 = int (color[0] * 255);
624               int c1 = int (color[1] * 255);
625               int c2 = int (color[2] * 255);
626               QColor c(c0, c1, c2);
627
628               vtkFloatingPointType edgecolor[3];
629               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
630               c0 = int (edgecolor[0] * 255);
631               c1 = int (edgecolor[1] * 255);
632               c2 = int (edgecolor[2] * 255);
633               QColor e(c0, c1, c2);
634
635               vtkFloatingPointType backfacecolor[3];
636               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
637               c0 = int (backfacecolor[0] * 255);
638               c1 = int (backfacecolor[1] * 255);
639               c2 = int (backfacecolor[2] * 255);
640               QColor b(c0, c1, c2);
641
642               vtkFloatingPointType nodecolor[3];
643               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
644               c0 = int (nodecolor[0] * 255);
645               c1 = int (nodecolor[1] * 255);
646               c2 = int (nodecolor[2] * 255);
647               QColor n(c0, c1, c2);
648
649               int Edgewidth = (int)anActor->GetLineWidth();
650               if(Edgewidth == 0)
651                 Edgewidth = 1;
652               int intValue = int(anActor->GetNodeSize());
653               vtkFloatingPointType Shrink = anActor->GetShrinkFactor();
654
655               SMESHGUI_Preferences_ColorDlg *aDlg =
656                 new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI(), "" );
657               aDlg->SetColor(1, c);
658               aDlg->SetColor(2, e);
659               aDlg->SetColor(3, n);
660               aDlg->SetColor(4, b);
661               aDlg->SetIntValue(1, Edgewidth);
662               aDlg->SetIntValue(2, intValue);
663               aDlg->SetIntValue(3, int(Shrink*100.));
664               if(aDlg->exec()){
665                 QColor color = aDlg->GetColor(1);
666                 QColor edgecolor = aDlg->GetColor(2);
667                 QColor nodecolor = aDlg->GetColor(3);
668                 QColor backfacecolor = aDlg->GetColor(4);
669                 /* actor color and backface color */
670                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
671                                         vtkFloatingPointType (color.green()) / 255.,
672                                         vtkFloatingPointType (color.blue()) / 255.);
673                 anActor->SetBackSufaceColor(vtkFloatingPointType (backfacecolor.red()) / 255.,
674                                             vtkFloatingPointType (backfacecolor.green()) / 255.,
675                                             vtkFloatingPointType (backfacecolor.blue()) / 255.);
676
677                 /* edge color */
678                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
679                                       vtkFloatingPointType (edgecolor.green()) / 255.,
680                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
681
682                 /* Shrink factor and size edges */
683                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
684                 anActor->SetLineWidth(aDlg->GetIntValue(1));
685
686                 /* Nodes color and size */
687                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
688                                       vtkFloatingPointType (nodecolor.green()) / 255.,
689                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
690                 anActor->SetNodeSize(aDlg->GetIntValue(2));
691
692                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
693                 if( !aGroupObject->_is_nil() )
694                 {
695                   SALOMEDS::Color aColor;
696                   aColor.R = (float)color.red() / 255.0;
697                   aColor.G = (float)color.green() / 255.0;
698                   aColor.B = (float)color.blue() / 255.0;
699                   aGroupObject->SetColor( aColor );
700                 }
701
702                 delete aDlg;
703               }
704               break;
705             }}
706           }
707         }
708       }
709       SMESH::RepaintCurrentView();
710     }
711   }
712
713   void Control( int theCommandID )
714   {
715     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
716     SALOME_ListIO selected;
717     if( aSel )
718       aSel->selectedObjects( selected );
719
720     if( !selected.IsEmpty() ){
721       Handle(SALOME_InteractiveObject) anIO = selected.First();
722       if(!anIO.IsNull()){
723         QString aTitle;
724         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
725         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
726           switch ( theCommandID ){
727           case 6001:
728             aTitle = QObject::tr( "LENGTH_EDGES" );
729             aControl = SMESH_Actor::eLength;
730             break;
731           case 6018:
732             aTitle = QObject::tr( "LENGTH2D_EDGES" );
733             aControl = SMESH_Actor::eLength2D;
734             break;
735           case 6002:
736             aTitle = QObject::tr( "FREE_EDGES" );
737             aControl = SMESH_Actor::eFreeEdges;
738             break;
739           case 6003:
740             aTitle = QObject::tr( "FREE_BORDERS" );
741             aControl = SMESH_Actor::eFreeBorders;
742             break;
743           case 6004:
744             aTitle = QObject::tr( "MULTI_BORDERS" );
745             aControl = SMESH_Actor::eMultiConnection;
746             break;
747           case 6019:
748             aTitle = QObject::tr( "MULTI2D_BORDERS" );
749             aControl = SMESH_Actor::eMultiConnection2D;
750             break;
751           case 6011:
752             aTitle = QObject::tr( "AREA_ELEMENTS" );
753             aControl = SMESH_Actor::eArea;
754             break;
755           case 6012:
756             aTitle = QObject::tr( "TAPER_ELEMENTS" );
757             aControl = SMESH_Actor::eTaper;
758             break;
759           case 6013:
760             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
761             aControl = SMESH_Actor::eAspectRatio;
762             break;
763           case 6017:
764             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
765             aControl = SMESH_Actor::eAspectRatio3D;
766             break;
767           case 6014:
768             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
769             aControl = SMESH_Actor::eMinimumAngle;
770             break;
771           case 6015:
772             aTitle = QObject::tr( "WARP_ELEMENTS" );
773             aControl = SMESH_Actor::eWarping;
774             break;
775           case 6016:
776             aTitle = QObject::tr( "SKEW_ELEMENTS" );
777             aControl = SMESH_Actor::eSkew;
778             break;
779           case 6009:
780             aTitle = QObject::tr( "SMESH_VOLUME" );
781             aControl = SMESH_Actor::eVolume3D;
782             break;
783           }
784           anActor->SetControlMode(aControl);
785           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
786           SMESH::RepaintCurrentView();
787         }
788       }
789     }
790   }
791
792
793   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
794                    MeshObjectType                           theType,
795                    const QString                            theInTypeName,
796                    QString &                                theOutTypeName)
797   {
798     SMESH_TypeFilter aTypeFilter( theType );
799     QString entry;
800     if( !theIO.IsNull() )
801     {
802       entry = theIO->getEntry();
803       LightApp_DataOwner owner( entry );
804       if ( aTypeFilter.isOk( &owner )) {
805         theOutTypeName = theInTypeName;
806         return true;
807       }
808     }
809     return false;
810   }
811
812
813   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
814   {
815     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
816     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
817     if (aSObj) {
818       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
819       CORBA::String_var anID = aSComp->GetID().c_str();
820       if (!strcmp(anID.in(),theIO->getEntry()))
821         return "Component";
822     }
823
824     QString aTypeName;
825     if (
826         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
827         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
828         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
829         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
830         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
831         )
832       return aTypeName;
833
834     return "NoType";
835   }
836
837
838   QString CheckHomogeneousSelection()
839   {
840     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
841     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
842     SALOME_ListIO selected;
843     if( aSel )
844       aSel->selectedObjects( selected );
845
846     QString RefType = CheckTypeObject(selected.First());
847     SALOME_ListIteratorOfListIO It(selected);
848     for (; It.More(); It.Next())
849       {
850         Handle(SALOME_InteractiveObject) IObject = It.Value();
851         QString Type = CheckTypeObject(IObject);
852         if (Type.compare(RefType) != 0)
853           return "Heterogeneous Selection";
854       }
855
856     return RefType;
857   }
858
859
860   void SMESHGUI::OnEditDelete()
861   {
862     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
863     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
864     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
865
866     QString aParentComponent = QString::null;
867     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
868     {
869       QString cur = anIt.Value()->getComponentDataType();
870       if( aParentComponent.isNull() )
871         aParentComponent = cur;
872       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
873         aParentComponent = "";
874     }
875
876     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
877       SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
878                               QObject::tr("ERR_ERROR"),
879                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ),
880                               QObject::tr("BUT_OK") );
881       return;
882     }
883     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
884     if (SUIT_MessageBox::warn2
885         (SMESHGUI::desktop(),
886          QObject::tr("SMESH_WRN_WARNING"),
887          QObject::tr("SMESH_REALLY_DELETE"),
888          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
889       return;
890
891     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
892     SUIT_ViewManager* vm = anApp->activeViewManager();
893     int nbSf = vm->getViewsCount();
894
895     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
896     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
897     _PTR(GenericAttribute) anAttr;
898     _PTR(AttributeIOR) anIOR;
899
900     SALOME_ListIteratorOfListIO It(selected);
901
902     aStudyBuilder->NewCommand();  // There is a transaction
903     for(; It.More(); It.Next()){ // loop on selected IO's
904       Handle(SALOME_InteractiveObject) IObject = It.Value();
905       if(IObject->hasEntry()) {
906         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
907
908         // disable removal of "SMESH" component object
909         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
910           anIOR = anAttr;
911           if ( !strcmp( (char*)anIOR->Value().c_str(), engineIOR().latin1() ) )
912             continue;
913         }
914
915         // put the whole hierarchy of sub-objects of the selected SO into a list and
916         // then treat them all starting from the deepest objects (at list back)
917
918         list< _PTR(SObject) > listSO;
919         listSO.push_back( aSO );
920         list< _PTR(SObject) >::iterator itSO = listSO.begin();
921         for ( ; itSO != listSO.end(); ++itSO ) {
922           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
923           for (it->InitEx(false); it->More(); it->Next())
924             listSO.push_back( it->Value() );
925         }
926
927         // treat SO's in the list starting from the back
928
929         list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
930         for ( ; ritSO != listSO.rend(); ++ritSO ) {
931           _PTR(SObject) SO = *ritSO;
932           if ( !SO ) continue;
933           string anEntry = SO->GetID();
934
935           /** Erase graphical object **/
936           if(SO->FindAttribute(anAttr, "AttributeIOR")){
937             QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
938             for(int i = 0; i < nbSf; i++){
939               SUIT_ViewWindow *sf = aViews[i];
940               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
941                 SMESH::RemoveActor(sf,anActor);
942               }
943             }
944           }
945
946           /** Remove an object from data structures **/
947           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
948           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
949           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
950             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
951             aMesh->RemoveGroup( aGroup );
952           }
953           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
954             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
955             aMesh->RemoveSubMesh( aSubMesh );
956
957             _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
958             if (aMeshSO)
959               SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
960           }
961           else {
962             IObject = new SALOME_InteractiveObject
963               ( anEntry.c_str(), engineIOR().latin1(), SO->GetName().c_str() );
964             QString objType = CheckTypeObject(IObject);
965             if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
966               SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
967               aStudyBuilder->RemoveObjectWithChildren( SO );
968             }
969             else {// default action: remove SObject from the study
970               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
971               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
972               //op->start();
973               aStudyBuilder->RemoveObjectWithChildren( SO );
974               //op->finish();
975             }
976           }
977         } /* listSO back loop */
978       } /* IObject->hasEntry() */
979     } /* more/next */
980     aStudyBuilder->CommitCommand();
981
982     /* Clear any previous selection */
983     SALOME_ListIO l1;
984     aSel->setSelectedObjects( l1 );
985
986     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
987   }
988 //}
989
990 extern "C" {
991   SMESHGUI_EXPORT CAM_Module* createModule()
992   {
993     return new SMESHGUI();
994   }
995 }
996
997 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
998
999 //=============================================================================
1000 /*!
1001  *
1002  */
1003 //=============================================================================
1004 SMESHGUI::SMESHGUI() :
1005 SalomeApp_Module( "SMESH" )
1006 {
1007   if ( CORBA::is_nil( myComponentSMESH ) )
1008   {
1009     CORBA::Boolean anIsEmbeddedMode;
1010     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1011   }
1012
1013   myActiveDialogBox = 0;
1014   myFilterLibraryDlg = 0;
1015   myState = -1;
1016   myDisplayer = 0;
1017
1018   SMESH::GetFilterManager();
1019   SMESH::GetPattern();
1020
1021   /* load resources for all available meshers */
1022   SMESH::InitAvailableHypotheses();
1023 }
1024
1025 //=============================================================================
1026 /*!
1027  *
1028  */
1029 //=============================================================================
1030 SMESHGUI::~SMESHGUI()
1031 {
1032   SMESH::GetFilterManager()->Destroy();
1033   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1034 }
1035
1036 //=============================================================================
1037 /*!
1038  *
1039  */
1040 //=============================================================================
1041 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1042 {
1043   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1044   if( anApp )
1045     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1046   else
1047     return 0;
1048 }
1049
1050 bool SMESHGUI::automaticUpdate()
1051 {
1052   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1053   if ( !resMgr )
1054     return false;
1055
1056   return resMgr->booleanValue( "SMESH", "auto_update", false );
1057 }
1058
1059 //=============================================================================
1060 /*!
1061  *
1062  */
1063 //=============================================================================
1064 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1065 {
1066   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1067 }
1068
1069 //=============================================================================
1070 /*!
1071  *
1072  */
1073 //=============================================================================
1074 SMESHGUI* SMESHGUI::GetSMESHGUI()
1075 {
1076   SMESHGUI* smeshMod = 0;
1077   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1078   if ( app )
1079   {
1080     CAM_Module* module = app->module( "Mesh" );
1081     smeshMod = dynamic_cast<SMESHGUI*>( module );
1082   }
1083
1084   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1085   {
1086     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1087     if ( study )
1088     {
1089       _PTR(Study) aStudy = study->studyDS();
1090       if ( aStudy )
1091         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1092     }
1093   }
1094
1095   return smeshMod;
1096 }
1097
1098 extern "C"
1099 {
1100   Standard_EXPORT SMESHGUI* GetComponentGUI()
1101   {
1102     return SMESHGUI::GetSMESHGUI();
1103   }
1104 }
1105
1106 //=============================================================================
1107 /*!
1108  *
1109  */
1110 //=============================================================================
1111 void SMESHGUI::SetState(int aState)
1112 {
1113   myState = aState;
1114 }
1115
1116 //=============================================================================
1117 /*!
1118  *
1119  */
1120 //=============================================================================
1121 void SMESHGUI::ResetState()
1122 {
1123   myState = -1;
1124 }
1125
1126 //=============================================================================
1127 /*!
1128  *
1129  */
1130 //=============================================================================
1131 void SMESHGUI::EmitSignalDeactivateDialog()
1132 {
1133   emit SignalDeactivateActiveDialog();
1134 }
1135
1136 //=============================================================================
1137 /*!
1138  *
1139  */
1140 //=============================================================================
1141 void SMESHGUI::EmitSignalStudyFrameChanged()
1142 {
1143   emit SignalStudyFrameChanged();
1144 }
1145
1146 //=============================================================================
1147 /*!
1148  *
1149  */
1150 //=============================================================================
1151 void SMESHGUI::EmitSignalCloseAllDialogs()
1152 {
1153   emit SignalCloseAllDialogs();
1154 }
1155
1156 //=============================================================================
1157 /*!
1158  *
1159  */
1160 //=============================================================================
1161 QDialog *SMESHGUI::GetActiveDialogBox()
1162 {
1163   return myActiveDialogBox;
1164 }
1165
1166 //=============================================================================
1167 /*!
1168  *
1169  */
1170 //=============================================================================
1171 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1172 {
1173   myActiveDialogBox = (QDialog *) aDlg;
1174   return;
1175 }
1176
1177 //=============================================================================
1178 /*!
1179  *
1180  */
1181 //=============================================================================
1182 SUIT_Desktop* SMESHGUI::desktop()
1183 {
1184   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1185   if( app )
1186     return app->desktop();
1187   else
1188     return 0;
1189 }
1190
1191 //=============================================================================
1192 /*!
1193  *
1194  */
1195 //=============================================================================
1196 SalomeApp_Study* SMESHGUI::activeStudy()
1197 {
1198   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1199   if( app )
1200     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1201   else
1202     return NULL;
1203 }
1204
1205 //=============================================================================
1206 /*!
1207  *
1208  */
1209 //=============================================================================
1210 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1211 {
1212   /* Here the position is on the bottom right corner - 10 */
1213   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1214   aDlg->adjustSize();
1215   SUIT_Desktop *PP = desktop();
1216   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1217   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1218   return true;
1219 }
1220
1221 //=============================================================================
1222 /*!
1223  *
1224  */
1225 //=============================================================================
1226 static int isStudyLocked(_PTR(Study) theStudy){
1227   return theStudy->GetProperties()->IsLocked();
1228 }
1229
1230 static bool checkLock(_PTR(Study) theStudy) {
1231   if (isStudyLocked(theStudy)) {
1232     SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
1233                            QObject::tr("WRN_WARNING"),
1234                            QObject::tr("WRN_STUDY_LOCKED"),
1235                            QObject::tr("BUT_OK") );
1236     return true;
1237   }
1238   return false;
1239 }
1240
1241 //=======================================================================
1242 //function : CheckActiveStudyLocked
1243 //purpose  :
1244 //=======================================================================
1245
1246 bool SMESHGUI::isActiveStudyLocked()
1247 {
1248   _PTR(Study) aStudy = activeStudy()->studyDS();
1249   return checkLock( aStudy );
1250 }
1251
1252 //=============================================================================
1253 /*!
1254  *
1255  */
1256 //=============================================================================
1257 bool SMESHGUI::OnGUIEvent( int theCommandID )
1258 {
1259   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1260   if( !anApp )
1261     return false;
1262
1263   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1264   SUIT_ResourceMgr* mgr = resourceMgr();
1265   if( !mgr )
1266     return false;
1267
1268   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1269     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1270   }
1271
1272   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1273   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1274
1275   //QAction* act = action( theCommandID );
1276
1277   switch (theCommandID) {
1278   case 33:                                      // DELETE
1279     if(checkLock(aStudy)) break;
1280     OnEditDelete();
1281     break;
1282
1283   case 113:                                     // IMPORT
1284   case 112:
1285   case 111:
1286     {
1287       if(checkLock(aStudy)) break;
1288       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1289       break;
1290     }
1291
1292   case 122:                                     // EXPORT MED
1293   case 121:
1294   case 123:
1295   case 124:
1296   case 125:
1297   case 126:
1298   case 140:
1299   case 141:
1300     {
1301       ::ExportMeshToFile(theCommandID);
1302       break;
1303     }
1304
1305   case 200:                                     // SCALAR BAR
1306     {
1307       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1308       SALOME_ListIO selected;
1309       if( aSel )
1310         aSel->selectedObjects( selected );
1311
1312       if( selected.Extent() ) {
1313         Handle(SALOME_InteractiveObject) anIO = selected.First();
1314         if( anIO->hasEntry() ) {
1315           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1316             anActor->SetControlMode( SMESH_Actor::eNone );
1317           }
1318         }
1319       }
1320       break;
1321     }
1322   case 201:
1323     {
1324       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1325       break;
1326     }
1327
1328     // Auto-color
1329   case 1136:
1330     ::AutoColor();
1331   break;
1332
1333   case 1137:
1334     ::DisableAutoColor();
1335   break;
1336
1337   case 1134: // Clipping
1338   case 1133: // Tranparency
1339   case 1132: // Colors / Size
1340
1341     // Display Mode
1342   case 215: // Nodes
1343   case 213: // Nodes
1344   case 212: // Nodes
1345   case 211: // Nodes
1346     ::SetDisplayMode(theCommandID);
1347   break;
1348
1349     // Display Entity
1350   case 217: // Edges
1351   case 218: // Faces
1352   case 219: // Volumes
1353   case 220: // All Entity
1354     ::SetDisplayEntity(theCommandID);
1355   break;
1356
1357   case 214:                                     // UPDATE
1358     {
1359       if(checkLock(aStudy)) break;
1360       try {
1361 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1362         OCC_CATCH_SIGNALS;
1363 #endif
1364         SMESH::UpdateView();
1365       }
1366       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
1367         SMESH::OnVisuException();
1368       }
1369       catch (...) { // PAL16774 (Crash after display of many groups)
1370         SMESH::OnVisuException();
1371       }
1372
1373       SALOME_ListIO l;
1374       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1375       aSel->selectedObjects( l );
1376       aSel->setSelectedObjects( l );
1377       break;
1378     }
1379
1380   case 300:                                     // ERASE
1381   case 301:                                     // DISPLAY
1382   case 302:                                     // DISPLAY ONLY
1383     {
1384       SMESH::EDisplaing anAction;
1385       switch (theCommandID) {
1386       case 300: anAction = SMESH::eErase; break;
1387       case 301: anAction = SMESH::eDisplay; break;
1388       case 302: anAction = SMESH::eDisplayOnly; break;
1389       }
1390
1391       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1392       SALOME_ListIO sel_objects, to_process;
1393       if (aSel)
1394         aSel->selectedObjects( sel_objects );
1395
1396       if( theCommandID==302 )
1397         startOperation( myEraseAll );
1398
1399       extractContainers( sel_objects, to_process );
1400
1401       try {
1402 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1403         OCC_CATCH_SIGNALS;
1404 #endif
1405         if (vtkwnd) {
1406           SALOME_ListIteratorOfListIO It( to_process );
1407           for (; It.More(); It.Next()) {
1408             Handle(SALOME_InteractiveObject) IOS = It.Value();
1409             if (IOS->hasEntry()) {
1410               if (!SMESH::UpdateView(anAction, IOS->getEntry()))
1411                 break; // PAL16774 (Crash after display of many groups)
1412               if (anAction == SMESH::eDisplayOnly)
1413                 anAction = SMESH::eDisplay;
1414             }
1415           }
1416         }
1417
1418         // PAL13338 + PAL15161 -->
1419         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy))
1420           SMESH::UpdateView();
1421         // PAL13338 + PAL15161 <--
1422       }
1423       catch (...) { // PAL16774 (Crash after display of many groups)
1424         SMESH::OnVisuException();
1425       }
1426
1427       if (anAction == SMESH::eErase) {
1428         SALOME_ListIO l1;
1429         aSel->setSelectedObjects( l1 );
1430       }
1431       else
1432         aSel->setSelectedObjects( to_process );
1433
1434       break;
1435     }
1436
1437   case 400:                                     // NODES
1438     {
1439       if(checkLock(aStudy)) break;
1440
1441       if ( vtkwnd ) {
1442         EmitSignalDeactivateDialog();
1443
1444         new SMESHGUI_NodesDlg(this);
1445       }
1446       else {
1447         SUIT_MessageBox::warn1(desktop(),
1448                               tr("SMESH_WRN_WARNING"),
1449                               tr("SMESH_WRN_VIEWER_VTK"),
1450                               tr("SMESH_BUT_OK"));
1451       }
1452       break;
1453     }
1454
1455   case 2151:  // FILTER
1456   {
1457     if ( vtkwnd )
1458     {
1459       EmitSignalDeactivateDialog();
1460       new SMESHGUI_FilterDlg( this, SMESH::EDGE );
1461     }
1462     break;
1463   }
1464
1465   case 406:                                     // MOVE NODE
1466     {
1467       if ( !vtkwnd )
1468       {
1469         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1470           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1471         break;
1472       }
1473
1474       if(checkLock(aStudy)) break;
1475       new SMESHGUI_MoveNodesDlg(this);
1476       break;
1477     }
1478
1479   case 701:                                     // COMPUTE MESH
1480     {
1481       if (checkLock(aStudy)) break;
1482
1483       startOperation( 701 );
1484     }
1485     break;
1486
1487   case 702:  // Create mesh
1488     startOperation( 702 );
1489     break;
1490   case 703:  // Create sub-mesh
1491     startOperation( 703 );
1492     break;
1493   case 704: // Edit mesh/sub-mesh
1494     startOperation( 704 );
1495     break;
1496   case 710: // Build compound mesh
1497     {
1498       if (checkLock(aStudy)) break;
1499       EmitSignalDeactivateDialog();
1500       new SMESHGUI_BuildCompoundDlg( this );
1501     }
1502     break;
1503   case 407: // DIAGONAL INVERSION
1504   case 408: // Delete diagonal
1505     {
1506       if ( !vtkwnd )
1507       {
1508         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1509           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1510         break;
1511       }
1512
1513       if ( checkLock( aStudy ) )
1514         break;
1515
1516       /*Standard_Boolean aRes;
1517       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1518       if ( aMesh->_is_nil() )
1519       {
1520         SUIT_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1521           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1522         break;
1523       }
1524       */
1525       EmitSignalDeactivateDialog();
1526       if ( theCommandID == 407 )
1527         new SMESHGUI_TrianglesInversionDlg(this);
1528       else
1529         new SMESHGUI_UnionOfTwoTrianglesDlg(this);
1530       break;
1531     }
1532     case 409: // Change orientation
1533     case 410: // Union of triangles
1534     case 411: // Cutting of quadrangles
1535     {
1536       if ( !vtkwnd )
1537       {
1538         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1539           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1540         break;
1541       }
1542
1543       if ( checkLock( aStudy ) )
1544         break;
1545
1546       EmitSignalDeactivateDialog();
1547       SMESHGUI_MultiEditDlg* aDlg = NULL;
1548       if ( theCommandID == 409 )
1549         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1550       else if ( theCommandID == 410 )
1551         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1552       else
1553         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1554
1555       aDlg->show();
1556       break;
1557     }
1558   case 412: // Smoothing
1559     {
1560       if(checkLock(aStudy)) break;
1561       if( vtkwnd ) {
1562         EmitSignalDeactivateDialog();
1563         new SMESHGUI_SmoothingDlg( this );
1564       }
1565       else {
1566         SUIT_MessageBox::warn1(desktop(),
1567                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1568                               tr("SMESH_BUT_OK"));
1569       }
1570       break;
1571     }
1572   case 413: // Extrusion
1573     {
1574       if (checkLock(aStudy)) break;
1575       if (vtkwnd) {
1576         EmitSignalDeactivateDialog();
1577         new SMESHGUI_ExtrusionDlg ( this );
1578       } else {
1579         SUIT_MessageBox::warn1(desktop(),
1580                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1581                                tr("SMESH_BUT_OK"));
1582       }
1583       break;
1584     }
1585   case 414: // Revolution
1586     {
1587       if(checkLock(aStudy)) break;
1588       if( vtkwnd ) {
1589         EmitSignalDeactivateDialog();
1590         new SMESHGUI_RevolutionDlg( this );
1591       }
1592       else {
1593         SUIT_MessageBox::warn1(desktop(),
1594                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1595                               tr("SMESH_BUT_OK"));
1596       }
1597       break;
1598     }
1599   case 415: // Pattern mapping
1600     {
1601       if ( checkLock( aStudy ) )
1602         break;
1603       if ( vtkwnd )
1604       {
1605         EmitSignalDeactivateDialog();
1606         new SMESHGUI_MeshPatternDlg( this );
1607       }
1608       else {
1609         SUIT_MessageBox::warn1(desktop(),
1610                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1611                               tr("SMESH_BUT_OK"));
1612       }
1613       break;
1614     }
1615   case 416: // Extrusion along a path
1616     {
1617       if (checkLock(aStudy)) break;
1618       if (vtkwnd) {
1619         EmitSignalDeactivateDialog();
1620         new SMESHGUI_ExtrusionAlongPathDlg( this );
1621       } else {
1622         SUIT_MessageBox::warn1(desktop(),
1623                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1624                                tr("SMESH_BUT_OK"));
1625       }
1626       break;
1627     }
1628   case 417: // Convert mesh to quadratic
1629     {
1630     startOperation( 417 );
1631       /*      if (checkLock(aStudy)) break;
1632       if (vtkwnd) {
1633         EmitSignalDeactivateDialog();
1634         new SMESHGUI_ConvToQuadDlg();
1635       } else {
1636         SUIT_MessageBox::warn1(desktop(),
1637                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1638                                tr("SMESH_BUT_OK"));
1639                                }*/
1640       break;
1641     }
1642   case 801:                                     // CREATE GROUP
1643     {
1644       if ( !vtkwnd )
1645       {
1646         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1647           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1648         break;
1649       }
1650
1651       if(checkLock(aStudy)) break;
1652       EmitSignalDeactivateDialog();
1653       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1654
1655       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1656       SALOME_ListIO selected;
1657       if( aSel )
1658         aSel->selectedObjects( selected );
1659
1660       int nbSel = selected.Extent();
1661       if (nbSel == 1) {
1662         // check if mesh is selected
1663         aMesh = SMESH::GetMeshByIO( selected.First() );
1664       }
1665       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aMesh);
1666       aDlg->show();
1667       break;
1668     }
1669
1670   case 802:                                     // CONSTRUCT GROUP
1671     {
1672       if ( !vtkwnd )
1673       {
1674         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1675           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1676         break;
1677       }
1678
1679       if(checkLock(aStudy)) break;
1680       EmitSignalDeactivateDialog();
1681
1682       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1683       SALOME_ListIO selected;
1684       if( aSel )
1685         aSel->selectedObjects( selected );
1686
1687       int nbSel = selected.Extent();
1688       if (nbSel == 1) {
1689         // check if submesh is selected
1690         Handle(SALOME_InteractiveObject) IObject = selected.First();
1691         if (IObject->hasEntry()) {
1692           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1693           if( aSObj ) {
1694             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1695             if (!aSubMesh->_is_nil()) {
1696               try {
1697                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1698                 // get submesh elements list by types
1699                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1700                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1701                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1702                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1703                 // create group for each type o elements
1704                 QString aName = IObject->getName();
1705                 if (aNodes->length() > 0) {
1706                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1707                   aGroup->Add(aNodes.inout());
1708                 }
1709                 if (aEdges->length() > 0) {
1710                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1711                   aGroup->Add(aEdges.inout());
1712                 }
1713                 if (aFaces->length() > 0) {
1714                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1715                   aGroup->Add(aFaces.inout());
1716                 }
1717                 if (aVolumes->length() > 0) {
1718                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1719                   aGroup->Add(aVolumes.inout());
1720                 }
1721                 updateObjBrowser();
1722
1723               }
1724               catch(const SALOME::SALOME_Exception & S_ex){
1725                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1726               }
1727             }
1728           }
1729         }
1730       }
1731       else if(nbSel==0) {
1732         SUIT_MessageBox::warn1(desktop(),
1733                                tr("SMESH_WRN_WARNING"),
1734                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
1735                                tr("SMESH_BUT_OK"));
1736       }
1737       break;
1738     }
1739
1740   case 803:                                     // EDIT GROUP
1741     {
1742       if ( !vtkwnd )
1743       {
1744         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1745           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1746         break;
1747       }
1748
1749       if(checkLock(aStudy)) break;
1750       EmitSignalDeactivateDialog();
1751
1752       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1753       SALOME_ListIO selected;
1754       if( aSel )
1755         aSel->selectedObjects( selected );
1756
1757       SALOME_ListIteratorOfListIO It (selected);
1758       int nbSelectedGroups = 0;
1759       for ( ; It.More(); It.Next() )
1760       {
1761         SMESH::SMESH_GroupBase_var aGroup =
1762           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1763         if (!aGroup->_is_nil()) {
1764           nbSelectedGroups++;
1765           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
1766           aDlg->show();
1767         }
1768       }
1769       if (nbSelectedGroups == 0)
1770         {
1771           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_GroupBase::_nil());
1772           aDlg->show();
1773         }
1774       break;
1775     }
1776
1777   case 804:                                     // Add elements to group
1778     {
1779       if(checkLock(aStudy)) break;
1780       if (myState == 800) {
1781         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1782         if (aDlg) aDlg->onAdd();
1783       }
1784       break;
1785     }
1786
1787   case 805:                                     // Remove elements from group
1788     {
1789       if(checkLock(aStudy)) break;
1790       if (myState == 800) {
1791         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1792         if (aDlg) aDlg->onRemove();
1793       }
1794       break;
1795     }
1796
1797     case 810: // Union Groups
1798     case 811: // Intersect groups
1799     case 812: // Cut groups
1800     {
1801       if ( !vtkwnd )
1802       {
1803         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1804           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1805         break;
1806       }
1807
1808       if ( checkLock( aStudy ) )
1809         break;
1810
1811       EmitSignalDeactivateDialog();
1812
1813       int aMode;
1814       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1815       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1816       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1817
1818       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1819       break;
1820     }
1821
1822     case 813: // Delete groups with their contents
1823     {
1824       if ( !vtkwnd )
1825       {
1826         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1827           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1828         break;
1829       }
1830
1831       if ( checkLock( aStudy ) )
1832         break;
1833
1834       EmitSignalDeactivateDialog();
1835
1836       new SMESHGUI_DeleteGroupDlg( this );
1837       break;
1838     }
1839
1840   case 900:                                     // MESH INFOS
1841     {
1842       EmitSignalDeactivateDialog();
1843       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1844       SALOME_ListIO selected;
1845       if( aSel )
1846         aSel->selectedObjects( selected );
1847
1848       if ( selected.Extent() > 1 ) { // a dlg for each IO
1849         SALOME_ListIO IOs;
1850         SALOME_ListIteratorOfListIO It (selected);
1851         for ( ; It.More(); It.Next() ) {
1852           IOs.Clear(); IOs.Append( It.Value() );
1853           aSel->setSelectedObjects( IOs );
1854           new SMESHGUI_MeshInfosDlg(this, "", false);
1855         }
1856         // restore selection
1857         aSel->setSelectedObjects( selected );
1858       }
1859       else
1860         new SMESHGUI_MeshInfosDlg(this, "", false);
1861       break;
1862     }
1863
1864   case 902:                                     // STANDARD MESH INFOS
1865     {
1866       EmitSignalDeactivateDialog();
1867       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1868       SALOME_ListIO selected;
1869       if( aSel )
1870         aSel->selectedObjects( selected );
1871
1872       if ( selected.Extent() > 1 ) { // a dlg for each IO
1873         SALOME_ListIO IOs;
1874         SALOME_ListIteratorOfListIO It (selected);
1875         for ( ; It.More(); It.Next() ) {
1876           IOs.Clear();
1877           IOs.Append( It.Value() );
1878           aSel->setSelectedObjects( IOs );
1879           new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1880         }
1881         // restore selection
1882         aSel->setSelectedObjects( selected );
1883       }
1884       else
1885         new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1886       break;
1887     }
1888
1889   case 1100:                                    // EDIT HYPOTHESIS
1890     {
1891       if(checkLock(aStudy)) break;
1892
1893       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1894       SALOME_ListIO selected;
1895       if( aSel )
1896         aSel->selectedObjects( selected );
1897
1898       int nbSel = selected.Extent();
1899
1900       if (nbSel == 1) {
1901         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1902         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
1903
1904         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1905         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1906         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1907         if ( !aHypothesis->_is_nil() )
1908         {
1909           CORBA::String_var aHypType = aHypothesis->GetName();
1910           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypType);
1911           if (aCreator)
1912             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop() );
1913           else
1914           {
1915             // report error
1916           }
1917         }
1918       }
1919       updateObjBrowser( true );
1920       break;
1921     }
1922
1923   case 1101:                                    // RENAME
1924     {
1925       if ( checkLock( aStudy ) )
1926         break;
1927
1928       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1929       SALOME_ListIO selected;
1930       if( aSel )
1931         aSel->selectedObjects( selected );
1932
1933       SALOME_ListIteratorOfListIO It( selected );
1934       for ( ; It.More(); It.Next() )
1935       {
1936         Handle(SALOME_InteractiveObject) IObject = It.Value();
1937         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
1938         _PTR(GenericAttribute) anAttr;
1939         _PTR(AttributeName) aName;
1940         if ( obj )
1941         {
1942           if ( obj->FindAttribute(anAttr, "AttributeName") )
1943           {
1944             aName = anAttr;
1945             QString newName = QString(aName->Value().c_str());
1946             newName = LightApp_NameDlg::getName(desktop(), newName);
1947             if ( !newName.isEmpty() )
1948             {
1949               //old source: aStudy->renameIObject( IObject, newName );
1950               aName->SetValue( newName.latin1() );
1951
1952               // if current object is group update group's name
1953               SMESH::SMESH_GroupBase_var aGroup =
1954                 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1955               if (!aGroup->_is_nil() )
1956                 aGroup->SetName( newName.latin1() );
1957
1958               updateObjBrowser();
1959             }
1960           }
1961         }
1962       }
1963       break;
1964     }
1965
1966   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
1967     {
1968       if(checkLock(aStudy)) break;
1969       SUIT_OverrideCursor wc;
1970
1971       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1972       SALOME_ListIO selected;
1973       if( aSel )
1974         aSel->selectedObjects( selected, QString::null, false );
1975
1976       SALOME_ListIteratorOfListIO It(selected);
1977       for (int i = 0; It.More(); It.Next(), i++) {
1978         Handle(SALOME_InteractiveObject) IObject = It.Value();
1979         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1980       }
1981       SALOME_ListIO l1;
1982       aSel->setSelectedObjects( l1 );
1983       updateObjBrowser();
1984       break;
1985     }
1986
1987   case 401:                                     // GEOM::EDGE
1988   case 4021:                                    // TRIANGLE
1989   case 4022:                                    // QUAD
1990   case 4023:                                    // POLYGON
1991   case 4031:                                    // TETRA
1992   case 4032:                                    // HEXA
1993     {
1994       if(checkLock(aStudy)) break;
1995       if ( vtkwnd ) {
1996         EmitSignalDeactivateDialog();
1997         SMDSAbs_ElementType type    = SMDSAbs_Edge;
1998         int                 nbNodes = 2;
1999         switch (theCommandID) {
2000         case 4021:                                      // TRIANGLE
2001           type = SMDSAbs_Face; nbNodes = 3; break;
2002         case 4022:                                      // QUAD
2003           type = SMDSAbs_Face; nbNodes = 4; break;
2004         case 4031:                                      // TETRA
2005           type = SMDSAbs_Volume; nbNodes = 4; break;
2006         case 4023:                                      // POLYGON
2007           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2008         case 4032:                                      // HEXA
2009           type = SMDSAbs_Volume; nbNodes = 8; break;
2010         case 4033:                                      // POLYHEDRE
2011           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2012         default:;
2013         }
2014         new SMESHGUI_AddMeshElementDlg( this, "", type, nbNodes);
2015       }
2016       else {
2017         SUIT_MessageBox::warn1(desktop(),
2018                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2019                               tr("SMESH_BUT_OK"));
2020       }
2021       break;
2022     }
2023   case 4033:                                    // POLYHEDRON
2024     {
2025       if(checkLock(aStudy)) break;
2026       if ( vtkwnd ) {
2027         EmitSignalDeactivateDialog();
2028         new SMESHGUI_CreatePolyhedralVolumeDlg(this, "", FALSE );
2029       }
2030       else {
2031         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2032                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2033                               tr("SMESH_BUT_OK"));
2034       }
2035       break;
2036     }
2037   case 4034:     // QUADRATIC EDGE
2038   case 4035:     // QUADRATIC TRIANGLE
2039   case 4036:     // QUADRATIC QUADRANGLE
2040   case 4037:     // QUADRATIC TETRAHEDRON
2041   case 4038:     // QUADRATIC PYRAMID
2042   case 4039:     // QUADRATIC PENTAHEDRON
2043   case 4040:     // QUADRATIC HEXAHEDRON
2044     {
2045       if(checkLock(aStudy)) break;
2046       if ( vtkwnd ) {
2047         EmitSignalDeactivateDialog();
2048         int type;
2049
2050         switch (theCommandID) {
2051         case 4034:
2052           type = QUAD_EDGE; break;
2053         case 4035:
2054           type = QUAD_TRIANGLE; break;
2055         case 4036:
2056           type = QUAD_QUADRANGLE; break;
2057         case 4037:
2058           type = QUAD_TETRAHEDRON; break;
2059         case 4038:
2060           type = QUAD_PYRAMID; break;
2061         case 4039:
2062           type = QUAD_PENTAHEDRON; break;
2063         case 4040:
2064           type = QUAD_HEXAHEDRON;
2065           break;
2066         default:;
2067         }
2068          new SMESHGUI_AddQuadraticElementDlg( this, type );
2069       }
2070       else {
2071         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2072                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2073                                tr("SMESH_BUT_OK"));
2074       }
2075       break;
2076     }
2077   case 4041:                                    // REMOVES NODES
2078     {
2079       if(checkLock(aStudy)) break;
2080       if ( vtkwnd ) {
2081         EmitSignalDeactivateDialog();
2082         new SMESHGUI_RemoveNodesDlg(this);
2083       }
2084       else {
2085         SUIT_MessageBox::warn1(desktop(),
2086                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2087                               tr("SMESH_BUT_OK"));
2088       }
2089       break;
2090     }
2091   case 4042:                                    // REMOVES ELEMENTS
2092     {
2093       if(checkLock(aStudy)) break;
2094       if( vtkwnd ) {
2095         EmitSignalDeactivateDialog();
2096         new SMESHGUI_RemoveElementsDlg(this);
2097       }
2098       else
2099         {
2100           SUIT_MessageBox::warn1(desktop(),
2101                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2102                                 tr("SMESH_BUT_OK"));
2103         }
2104       break;
2105     }
2106   case 4051:                                    // RENUMBERING NODES
2107     {
2108       if(checkLock(aStudy)) break;
2109       if( vtkwnd ) {
2110         EmitSignalDeactivateDialog();
2111         new SMESHGUI_RenumberingDlg( this, "", 0);
2112       }
2113       else
2114         {
2115           SUIT_MessageBox::warn1(desktop(),
2116                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2117                                 tr("SMESH_BUT_OK"));
2118         }
2119       break;
2120     }
2121   case 4052:                                    // RENUMBERING ELEMENTS
2122     {
2123       if(checkLock(aStudy)) break;
2124       if ( vtkwnd ) {
2125         EmitSignalDeactivateDialog();
2126         new SMESHGUI_RenumberingDlg( this, "", 1);
2127       }
2128       else
2129         {
2130           SUIT_MessageBox::warn1(desktop(),
2131                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2132                                 tr("SMESH_BUT_OK"));
2133         }
2134       break;
2135     }
2136   case 4061:                                   // TRANSLATION
2137     {
2138       if(checkLock(aStudy)) break;
2139       if ( vtkwnd ) {
2140         EmitSignalDeactivateDialog();
2141         new SMESHGUI_TranslationDlg( this );
2142       }
2143       else {
2144         SUIT_MessageBox::warn1(desktop(),
2145                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2146                               tr("SMESH_BUT_OK"));
2147       }
2148       break;
2149     }
2150   case 4062:                                   // ROTATION
2151     {
2152       if(checkLock(aStudy)) break;
2153       if( vtkwnd ) {
2154         EmitSignalDeactivateDialog();
2155         new SMESHGUI_RotationDlg( this );
2156       }
2157       else {
2158         SUIT_MessageBox::warn1(desktop(),
2159                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2160                               tr("SMESH_BUT_OK"));
2161       }
2162       break;
2163     }
2164   case 4063:                                   // SYMMETRY
2165     {
2166       if(checkLock(aStudy)) break;
2167       if(vtkwnd) {
2168         EmitSignalDeactivateDialog();
2169         new SMESHGUI_SymmetryDlg( this );
2170       }
2171       else {
2172         SUIT_MessageBox::warn1(desktop(),
2173                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2174                               tr("SMESH_BUT_OK"));
2175       }
2176       break;
2177     }
2178   case 4064:                                   // SEWING
2179     {
2180       if(checkLock(aStudy)) break;
2181       if(vtkwnd) {
2182         EmitSignalDeactivateDialog();
2183         new SMESHGUI_SewingDlg( this );
2184       }
2185       else {
2186         SUIT_MessageBox::warn1(desktop(),
2187                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2188                               tr("SMESH_BUT_OK"));
2189       }
2190       break;
2191     }
2192   case 4065:                                   // MERGE NODES
2193     {
2194       if(checkLock(aStudy)) break;
2195       if(vtkwnd) {
2196         EmitSignalDeactivateDialog();
2197         new SMESHGUI_EditMeshDlg( this, 0 );
2198       }
2199       else {
2200         SUIT_MessageBox::warn1(desktop(),
2201                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2202                               tr("SMESH_BUT_OK"));
2203       }
2204       break;
2205     }
2206   case 4066:                                   // MERGE EQUAL ELEMENTS
2207     {
2208       if (checkLock(aStudy)) break;
2209       if (vtkwnd) {
2210         EmitSignalDeactivateDialog();
2211         new SMESHGUI_EditMeshDlg( this, 1 );
2212       } else {
2213         SUIT_MessageBox::warn1(desktop(),
2214                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2215                               tr("SMESH_BUT_OK"));
2216       }
2217       break;
2218     }
2219
2220   case 4067: // MAKE MESH PASS THROUGH POINT
2221     startOperation( 4067 );
2222     break;
2223
2224   case 5105: // Library of selection filters
2225   {
2226     static QValueList<int> aTypes;
2227     if ( aTypes.isEmpty() )
2228     {
2229       aTypes.append( SMESH::NODE );
2230       aTypes.append( SMESH::EDGE );
2231       aTypes.append( SMESH::FACE );
2232       aTypes.append( SMESH::VOLUME );
2233     }
2234     if (!myFilterLibraryDlg)
2235       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2236     else if (myFilterLibraryDlg->isHidden())
2237       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2238     myFilterLibraryDlg->raise();
2239   }
2240   break;
2241
2242   case 6017:                                    // CONTROLS
2243   case 6016:
2244   case 6015:
2245   case 6014:
2246   case 6013:
2247   case 6012:
2248   case 6011:
2249   case 6001:
2250   case 6018:
2251   case 6019:
2252   case 6002:
2253   case 6003:
2254   case 6004:
2255   case 6009:
2256     if ( vtkwnd ) {
2257
2258       LightApp_SelectionMgr* mgr = selectionMgr();
2259       SALOME_ListIO selected; mgr->selectedObjects( selected );
2260
2261       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2262         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2263         if ( SO ) {
2264           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2265           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2266           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2267           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2268           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2269             ::Control( theCommandID );
2270             break;
2271           }
2272         }
2273       }
2274       SUIT_MessageBox::warn1(desktop(),
2275                             tr( "SMESH_WRN_WARNING" ),
2276                             tr( "SMESH_BAD_SELECTION" ),
2277                             tr( "SMESH_BUT_OK" ) );
2278       break;
2279     }
2280     else {
2281       SUIT_MessageBox::warn1(desktop(),
2282                             tr( "SMESH_WRN_WARNING" ),
2283                             tr( "NOT_A_VTK_VIEWER" ),
2284                             tr( "SMESH_BUT_OK" ) );
2285     }
2286     break;
2287   case 9010:
2288     {
2289       LightApp_SelectionMgr* mgr = selectionMgr();
2290       SALOME_ListIO selected; mgr->selectedObjects( selected );
2291
2292       SALOME_ListIteratorOfListIO it(selected);
2293       for(; it.More(); it.Next()) {
2294         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2295         if(anIObject->hasEntry()) {
2296           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2297             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2298           }
2299         }
2300       }
2301       break;
2302     }
2303   case 9011:
2304     {
2305       LightApp_SelectionMgr* mgr = selectionMgr();
2306       SALOME_ListIO selected; mgr->selectedObjects( selected );
2307
2308       if (selected.Extent() == 1)       {
2309         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2310         if(anIObject->hasEntry())
2311           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2312             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2313           }
2314       }
2315       break;
2316     }
2317   }
2318
2319   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2320   //updateObjBrowser();
2321   return true;
2322 }
2323
2324 //=============================================================================
2325 /*!
2326  *
2327  */
2328 //=============================================================================
2329 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2330 {
2331   return false;
2332 }
2333
2334 //=============================================================================
2335 /*!
2336  *
2337  */
2338 //=============================================================================
2339 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2340 {
2341   return true;
2342 }
2343
2344 //=============================================================================
2345 /*!
2346  *
2347  */
2348 //=============================================================================
2349 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2350 {
2351   return true;
2352 }
2353
2354 //=============================================================================
2355 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2356  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2357  */
2358 //=============================================================================
2359 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2360                                   SUIT_ViewWindow* wnd )
2361 {
2362   if(theIO->hasEntry()){
2363     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2364     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2365   }
2366 }
2367
2368 //=======================================================================
2369 // function : createSMESHAction
2370 // purpose  :
2371 //=======================================================================
2372 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2373 {
2374   QIconSet icon;
2375   QWidget* parent = application()->desktop();
2376   SUIT_ResourceMgr* resMgr = resourceMgr();
2377   QPixmap pix;
2378   if ( icon_id.length() )
2379     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2380   else
2381     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ), false );
2382   if ( !pix.isNull() )
2383     icon = QIconSet( pix );
2384
2385   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2386           menu       = tr( QString( "MEN_" )+po_id ),
2387           status_bar = tr( QString( "STB_" )+po_id );
2388
2389   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2390 }
2391
2392 //=======================================================================
2393 // function : createPopupItem
2394 // purpose  :
2395 //=======================================================================
2396 void SMESHGUI::createPopupItem( const int id,
2397                                 const QString& clients,
2398                                 const QString& types,
2399                                 const QString& theRule,
2400                                 const int pId )
2401 {
2402   int parentId = pId;
2403   if( pId!=-1 )
2404     parentId = popupMgr()->actionId( action( pId ) );
2405
2406   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2407     popupMgr()->insert( action( id ), parentId, 0 );
2408
2409   QChar lc = QtxPopupMgr::Selection::defEquality();
2410   QString rule = "(%1) and (%2) and (%3)";
2411   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2412   if( clients.isEmpty() )
2413     rule = rule.arg( QString( "true" ) );
2414   else
2415     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2416   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2417   rule += theRule;
2418
2419   bool cont = myRules.contains( id );
2420   if( cont )
2421     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2422
2423   popupMgr()->setRule( action( id ), rule, true );
2424   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2425 }
2426
2427 //=======================================================================
2428 // function : initialize
2429 // purpose  :
2430 //=======================================================================
2431 void SMESHGUI::initialize( CAM_Application* app )
2432 {
2433   SalomeApp_Module::initialize( app );
2434
2435 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2436 //   if ( mgr )
2437   /* Automatic Update flag */
2438 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2439
2440   // ----- create actions --------------
2441
2442   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2443   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2444   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2445   createSMESHAction(  114, "NUM" );
2446   createSMESHAction(  121, "DAT" );
2447   createSMESHAction(  122, "MED" );
2448   createSMESHAction(  123, "UNV" );
2449   createSMESHAction(  140, "STL" );
2450   createSMESHAction(  124, "EXPORT_DAT" );
2451   createSMESHAction(  125, "EXPORT_MED" );
2452   createSMESHAction(  126, "EXPORT_UNV" );
2453   createSMESHAction(  141, "EXPORT_STL" );
2454   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
2455   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2456   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2457   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2458   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2459   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2460   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2461   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2462   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2463   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2464   createSMESHAction(  804, "ADD" );
2465   createSMESHAction(  805, "REMOVE" );
2466   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2467   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2468   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2469   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2470   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2471   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2472   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2473   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2474   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2475   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2476   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2477   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2478   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2479   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2480   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2481   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2482   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2483   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2484   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2485   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2486   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2487   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2488   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2489   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2490   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2491   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2492   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2493   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2494   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2495   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2496   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2497   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2498   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2499   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2500   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2501   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2502   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2503   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2504   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2505   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2506   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2507   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2508   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2509   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2510   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2511   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2512   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2513   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2514   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2515   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2516   createSMESHAction(  200, "RESET" );
2517   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2518   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2519   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2520   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2521   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2522   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2523   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2524   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2525   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2526   createSMESHAction(  220, "ALL" );
2527   createSMESHAction( 1100, "EDIT_HYPO" );
2528   createSMESHAction( 1101, "RENAME", "", Key_F2 );
2529   createSMESHAction( 1102, "UNASSIGN" );
2530   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2531   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2532   createSMESHAction( 1131, "DISPMODE" );
2533   createSMESHAction( 1132, "COLORS" );
2534   createSMESHAction( 1133, "TRANSP" );
2535   createSMESHAction( 1134, "CLIP" );
2536   createSMESHAction( 1135, "DISP_ENT" );
2537   createSMESHAction( 1136, "AUTO_COLOR" );
2538   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
2539   createSMESHAction( 2000, "CTRL" );
2540
2541   createSMESHAction( 300, "ERASE" );
2542   createSMESHAction( 301, "DISPLAY" );
2543   createSMESHAction( 302, "DISPLAY_ONLY" );
2544   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2545   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2546   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2547   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2548   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2549   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2550   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2551   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2552
2553   // ----- create menu --------------
2554   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2555       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2556       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2557       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2558       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2559       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2560       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2561
2562   createMenu( separator(), fileId );
2563
2564   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2565       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2566       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2567       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2568       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2569       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2570
2571   createMenu( 111, importId, -1 );
2572   createMenu( 112, importId, -1 );
2573   createMenu( 113, importId, -1 );
2574
2575   createMenu( 121, exportId, -1 );
2576   createMenu( 122, exportId, -1 );
2577   createMenu( 123, exportId, -1 );
2578   createMenu( 140, exportId, -1 ); // export to stl STL
2579
2580   createMenu( separator(), fileId, 10 );
2581
2582   createMenu( 33, editId, -1 );
2583
2584   createMenu( 5105, toolsId, -1 );
2585
2586   createMenu( 702, meshId, -1 );
2587   createMenu( 703, meshId, -1 );
2588   createMenu( 704, meshId, -1 );
2589   createMenu( 710, meshId, -1 );
2590   createMenu( separator(), meshId, -1 );
2591   createMenu( 701, meshId, -1 );
2592   createMenu( separator(), meshId, -1 );
2593   createMenu( 801, meshId, -1 );
2594   createMenu( 802, meshId, -1 );
2595   createMenu( 803, meshId, -1 );
2596   createMenu( separator(), meshId, -1 );
2597   createMenu( 810, meshId, -1 );
2598   createMenu( 811, meshId, -1 );
2599   createMenu( 812, meshId, -1 );
2600   createMenu( separator(), meshId, -1 );
2601   createMenu( 813, meshId, -1 );
2602   createMenu( separator(), meshId, -1 );
2603   createMenu( 900, meshId, -1 );
2604   createMenu( 902, meshId, -1 );
2605   createMenu( separator(), meshId, -1 );
2606
2607   createMenu( 6003, ctrlId, -1 );
2608   createMenu( 6001, ctrlId, -1 );
2609   createMenu( 6004, ctrlId, -1 );
2610   createMenu( separator(), ctrlId, -1 );
2611   createMenu( 6002, ctrlId, -1 );
2612   createMenu( 6018, ctrlId, -1 );
2613   createMenu( 6019, ctrlId, -1 );
2614   createMenu( 6011, ctrlId, -1 );
2615   createMenu( 6012, ctrlId, -1 );
2616   createMenu( 6013, ctrlId, -1 );
2617   createMenu( 6014, ctrlId, -1 );
2618   createMenu( 6015, ctrlId, -1 );
2619   createMenu( 6016, ctrlId, -1 );
2620   createMenu( separator(), ctrlId, -1 );
2621   createMenu( 6017, ctrlId, -1 );
2622   createMenu( 6009, ctrlId, -1 );
2623   createMenu( separator(), ctrlId, -1 );
2624
2625   createMenu( 400, addId, -1 );
2626   createMenu( 401, addId, -1 );
2627   createMenu( 4021, addId, -1 );
2628   createMenu( 4022, addId, -1 );
2629   createMenu( 4023, addId, -1 );
2630   createMenu( 4031, addId, -1 );
2631   createMenu( 4032, addId, -1 );
2632   createMenu( 4033, addId, -1 );
2633   createMenu( separator(), addId, -1 );
2634   createMenu( 4034, addId, -1 );
2635   createMenu( 4035, addId, -1 );
2636   createMenu( 4036, addId, -1 );
2637   createMenu( 4037, addId, -1 );
2638   createMenu( 4038, addId, -1 );
2639   createMenu( 4039, addId, -1 );
2640   createMenu( 4040, addId, -1 );
2641
2642   createMenu( 4041, removeId, -1 );
2643   createMenu( 4042, removeId, -1 );
2644
2645   createMenu( 4051, renumId, -1 );
2646   createMenu( 4052, renumId, -1 );
2647
2648   createMenu( 4061, transfId, -1 );
2649   createMenu( 4062, transfId, -1 );
2650   createMenu( 4063, transfId, -1 );
2651   createMenu( 4064, transfId, -1 );
2652   createMenu( 4065, transfId, -1 );
2653   createMenu( 4066, transfId, -1 );
2654
2655   createMenu( 406, modifyId, -1 );
2656   createMenu( 4067,modifyId, -1 );
2657   createMenu( 407, modifyId, -1 );
2658   createMenu( 408, modifyId, -1 );
2659   createMenu( 409, modifyId, -1 );
2660   createMenu( 410, modifyId, -1 );
2661   createMenu( 411, modifyId, -1 );
2662   createMenu( 412, modifyId, -1 );
2663   createMenu( 413, modifyId, -1 );
2664   createMenu( 416, modifyId, -1 );
2665   createMenu( 414, modifyId, -1 );
2666   createMenu( 415, modifyId, -1 );
2667   createMenu( 417, modifyId, -1 );
2668
2669   createMenu( 214, viewId, -1 );
2670
2671   // ----- create toolbars --------------
2672   int meshTb     = createTool( tr( "TB_MESH" ) ),
2673       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2674       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2675       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2676       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2677
2678   createTool( 702, meshTb );
2679   createTool( 703, meshTb );
2680   createTool( 704, meshTb );
2681   createTool( 710, meshTb );
2682   createTool( separator(), meshTb );
2683   createTool( 701, meshTb );
2684   createTool( separator(), meshTb );
2685   createTool( 801, meshTb );
2686   createTool( 802, meshTb );
2687   createTool( 803, meshTb );
2688   createTool( separator(), meshTb );
2689   createTool( 900, meshTb );
2690   createTool( 902, meshTb );
2691   createTool( separator(), meshTb );
2692
2693   createTool( 6001, ctrlTb );
2694   createTool( 6003, ctrlTb );
2695   createTool( 6004, ctrlTb );
2696   createTool( separator(), ctrlTb );
2697   createTool( 6002, ctrlTb );
2698   createTool( 6018, ctrlTb );
2699   createTool( 6019, ctrlTb );
2700   createTool( 6011, ctrlTb );
2701   createTool( 6012, ctrlTb );
2702   createTool( 6013, ctrlTb );
2703   createTool( 6014, ctrlTb );
2704   createTool( 6015, ctrlTb );
2705   createTool( 6016, ctrlTb );
2706   createTool( separator(), ctrlTb );
2707   createTool( 6017, ctrlTb );
2708   createTool( 6009, ctrlTb );
2709   createTool( separator(), ctrlTb );
2710
2711   createTool( 400, addRemTb );
2712   createTool( 401, addRemTb );
2713   createTool( 4021, addRemTb );
2714   createTool( 4022, addRemTb );
2715   createTool( 4023, addRemTb );
2716   createTool( 4031, addRemTb );
2717   createTool( 4032, addRemTb );
2718   createTool( 4033, addRemTb );
2719   createTool( separator(), addRemTb );
2720   createTool( 4034, addRemTb );
2721   createTool( 4035, addRemTb );
2722   createTool( 4036, addRemTb );
2723   createTool( 4037, addRemTb );
2724   createTool( 4038, addRemTb );
2725   createTool( 4039, addRemTb );
2726   createTool( 4040, addRemTb );
2727   createTool( separator(), addRemTb );
2728   createTool( 4041, addRemTb );
2729   createTool( 4042, addRemTb );
2730   createTool( separator(), addRemTb );
2731   createTool( 4051, addRemTb );
2732   createTool( 4052, addRemTb );
2733   createTool( separator(), addRemTb );
2734   createTool( 4061, addRemTb );
2735   createTool( 4062, addRemTb );
2736   createTool( 4063, addRemTb );
2737   createTool( 4064, addRemTb );
2738   createTool( 4065, addRemTb );
2739   createTool( 4066, addRemTb );
2740   createTool( separator(), addRemTb );
2741
2742   createTool( 406, modifyTb );
2743   createTool( 4067,modifyTb );
2744   createTool( 407, modifyTb );
2745   createTool( 408, modifyTb );
2746   createTool( 409, modifyTb );
2747   createTool( 410, modifyTb );
2748   createTool( 411, modifyTb );
2749   createTool( 412, modifyTb );
2750   createTool( 413, modifyTb );
2751   createTool( 416, modifyTb );
2752   createTool( 414, modifyTb );
2753   createTool( 415, modifyTb );
2754   createTool( 417, modifyTb );
2755
2756   createTool( 214, dispModeTb );
2757
2758
2759   myRules.clear();
2760   QString OB = "'ObjectBrowser'",
2761           View = "'" + SVTK_Viewer::Type() + "'",
2762           pat = "'%1'",
2763           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2764           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2765           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2766           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2767           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
2768                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2769                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2770                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2771                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2772                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
2773                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
2774           subMesh = elems,
2775           mesh_group = mesh + " " + subMesh + " " + group,
2776           hyp_alg = hypo + " " + algo;
2777
2778   // popup for object browser
2779
2780   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
2781   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
2782   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2783   popupMgr()->insert( separator(), -1, 0 );
2784   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2785   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2786   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2787   createPopupItem( 902, OB, mesh );                        // STD_INFO
2788   popupMgr()->insert( separator(), -1, 0 );
2789   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2790   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2791   popupMgr()->insert( separator(), -1, 0 );
2792   createPopupItem( 1100, OB, hypo, "" /*"&& $hasReference={false}"*/ );   // EDIT HYPOTHESIS
2793   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2794   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg, "" /*"&& $hasReference={false}"*/ ); // RENAME
2795   popupMgr()->insert( separator(), -1, 0 );
2796
2797   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2798   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
2799   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
2800   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
2801   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
2802   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
2803   popupMgr()->insert( separator(), -1, 0 );
2804
2805   // popup for viewer
2806   createPopupItem( 803, View, group ); // EDIT_GROUP
2807   createPopupItem( 804, View, elems ); // ADD
2808   createPopupItem( 805, View, elems ); // REMOVE
2809   popupMgr()->insert( separator(), -1, 0 );
2810   createPopupItem( 214, View, mesh_group ); // UPDATE
2811   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2812   createPopupItem( 902, View, mesh );       // STD_INFO
2813   popupMgr()->insert( separator(), -1, 0 );
2814
2815   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
2816   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
2817   popupMgr()->insert( separator(), -1, 0 );
2818
2819   int anId;
2820   QString
2821     isInvisible("not( isVisible )"),
2822     isEmpty("numberOfNodes = 0"),
2823     isNotEmpty("numberOfNodes <> 0"),
2824
2825     // has nodes, edges, etc in VISIBLE! actor
2826     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
2827     hasElems("(count( elemTypes ) > 0)"),
2828     hasDifferentElems("(count( elemTypes ) > 1)"),
2829     hasEdges("({'Edge'} in elemTypes)"),
2830     hasFaces("({'Face'} in elemTypes)"),
2831     hasVolumes("({'Volume'} in elemTypes)");
2832
2833   QString lc = QtxPopupMgr::Selection::defEquality();
2834   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
2835   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() );
2836   aType = aType.arg( mesh_group );
2837   QString aMeshInVTK = aClient + "&&" + aType;
2838
2839   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
2840   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
2841   QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2842
2843   //-------------------------------------------------
2844   // Numbering
2845   //-------------------------------------------------
2846   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
2847
2848   popupMgr()->insert( action( 9010 ), anId, -1 );
2849   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, true );
2850   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
2851
2852   popupMgr()->insert( action( 9011 ), anId, -1 );
2853   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, true );
2854   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
2855
2856   popupMgr()->insert( separator(), -1, -1 );
2857
2858   //-------------------------------------------------
2859   // Display Mode
2860   //-------------------------------------------------
2861   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
2862
2863   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
2864   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
2865   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
2866
2867   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
2868   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
2869   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
2870
2871   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
2872   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
2873   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
2874
2875   popupMgr()->insert( separator(), anId, -1 );
2876
2877   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
2878   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
2879   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
2880
2881   //-------------------------------------------------
2882   // Display Entity
2883   //-------------------------------------------------
2884   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
2885
2886   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
2887
2888   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
2889   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, true );
2890   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
2891
2892   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
2893   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, true );
2894   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
2895
2896   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
2897   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, true );
2898   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
2899
2900   popupMgr()->insert( separator(), anId, -1 );
2901
2902   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
2903   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", true );
2904
2905   //-------------------------------------------------
2906   // Color / Size
2907   //-------------------------------------------------
2908   popupMgr()->insert( action( 1132 ), -1, -1 );
2909   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
2910
2911   //-------------------------------------------------
2912   // Transparency
2913   //-------------------------------------------------
2914   popupMgr()->insert( action( 1133 ), -1, -1 );
2915   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
2916
2917   //-------------------------------------------------
2918   // Clipping
2919   //-------------------------------------------------
2920   popupMgr()->insert( action( 1134 ), -1, -1 );
2921   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
2922
2923   popupMgr()->insert( separator(), -1, -1 );
2924
2925   //-------------------------------------------------
2926   // Controls
2927   //-------------------------------------------------
2928   QString
2929     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
2930     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
2931     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
2932
2933   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
2934
2935   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
2936   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
2937
2938   popupMgr()->insert( separator(), anId, -1 );
2939
2940   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
2941   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
2942   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", false );
2943
2944   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
2945   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
2946   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
2947
2948   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
2949   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
2950   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
2951
2952   popupMgr()->insert( separator(), anId, -1 );
2953
2954   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
2955   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
2956   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", false );
2957
2958   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
2959   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
2960   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
2961
2962   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
2963   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
2964   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
2965
2966   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
2967   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
2968   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
2969
2970   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
2971   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
2972   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
2973
2974   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
2975   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
2976   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
2977
2978   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
2979   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
2980   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
2981
2982   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
2983   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
2984   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
2985
2986   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
2987   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
2988   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
2989
2990   popupMgr()->insert( separator(), anId, -1 );
2991
2992   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
2993   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
2994   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
2995
2996   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
2997   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, true );
2998   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", false );
2999
3000   popupMgr()->insert( separator(), anId, -1 );
3001
3002   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3003   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3004
3005   popupMgr()->insert( separator(), -1, -1 );
3006
3007   //-------------------------------------------------
3008   // Display / Erase
3009   //-------------------------------------------------
3010   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3011     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3012   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3013   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), true);
3014
3015   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3016   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), true );
3017
3018   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3019   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), true );
3020
3021   popupMgr()->insert( separator(), -1, -1 );
3022
3023   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3024            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3025 }
3026
3027 bool SMESHGUI::activateModule( SUIT_Study* study )
3028 {
3029   bool res = SalomeApp_Module::activateModule( study );
3030
3031   setMenuShown( true );
3032   setToolShown( true );
3033
3034   // Reset actions accelerator keys
3035   action(111)->setAccel(QKeySequence(CTRL + Key_B)); // Import DAT
3036   action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
3037   action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
3038
3039   return res;
3040 }
3041
3042 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3043 {
3044   setMenuShown( false );
3045   setToolShown( false );
3046
3047   EmitSignalCloseAllDialogs();
3048
3049   // Unset actions accelerator keys
3050   action(111)->setAccel(QKeySequence()); // Import DAT
3051   action(112)->setAccel(QKeySequence()); // Import UNV
3052   action(113)->setAccel(QKeySequence()); // Import MED
3053
3054   return SalomeApp_Module::deactivateModule( study );
3055 }
3056
3057 void SMESHGUI::studyClosed( SUIT_Study* s )
3058 {
3059   SMESH::RemoveVisuData( s->id() );
3060   SalomeApp_Module::studyClosed( s );
3061 }
3062
3063 void SMESHGUI::OnGUIEvent()
3064 {
3065   const QObject* obj = sender();
3066   if ( !obj || !obj->inherits( "QAction" ) )
3067     return;
3068   int id = actionId((QAction*)obj);
3069   if ( id != -1 )
3070     OnGUIEvent( id );
3071 }
3072
3073 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3074 {
3075   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3076   if ( CORBA::is_nil( myComponentSMESH ) )
3077     {
3078       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3079       if ( aStudy )
3080         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3081       return aGUI.myComponentSMESH;
3082     }
3083   if ( aStudy )
3084     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3085   return myComponentSMESH;
3086 }
3087
3088 QString SMESHGUI::engineIOR() const
3089 {
3090   CORBA::ORB_var anORB = getApp()->orb();
3091   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3092   return QString( anIOR.in() );
3093 }
3094
3095 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
3096 {
3097   SMESHGUI_Selection sel;
3098   sel.init( client, selectionMgr() );
3099   popupMgr()->updatePopup( menu, &sel );
3100 }
3101
3102 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3103 {
3104   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
3105   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
3106 }
3107
3108 void SMESHGUI::viewManagers( QStringList& list ) const
3109 {
3110   list.append( SVTK_Viewer::Type() );
3111 }
3112
3113 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3114 {
3115   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3116     SMESH::UpdateSelectionProp( this );
3117 }
3118
3119 void SMESHGUI::createPreferences()
3120 {
3121   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3122
3123   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3124   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3125
3126   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3127   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3128   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3129
3130   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
3131   setPreferenceProperty( precGroup, "columns", 1 );
3132
3133   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3134
3135   setPreferenceProperty( prec, "min", 0 );
3136   setPreferenceProperty( prec, "max", 16 );
3137
3138   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3139   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3140   QStringList modes;
3141   modes.append( "Wireframe" );
3142   modes.append( "Shading" );
3143   modes.append( "Nodes" );
3144   modes.append( "Shrink" );
3145   QValueList<QVariant> indices;
3146   indices.append( 0 );
3147   indices.append( 1 );
3148   indices.append( 2 );
3149   indices.append( 3 );
3150   setPreferenceProperty( dispmode, "strings", modes );
3151   setPreferenceProperty( dispmode, "indexes", indices );
3152
3153   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3154   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3155   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3156
3157   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3158   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3159
3160   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3161   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3162
3163   setPreferenceProperty( nodeSz, "min", 1 );
3164   setPreferenceProperty( nodeSz, "max", 5 );
3165
3166   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3167
3168   addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3169   addPreference( tr( "PREF_OUTLINE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3170   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3171   addPreference( "", elemGroup, LightApp_Preferences::Space );
3172
3173   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "element_width" );
3174   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
3175
3176   setPreferenceProperty( elemW, "min", 1 );
3177   setPreferenceProperty( elemW, "max", 5 );
3178
3179   setPreferenceProperty( shrink, "min", 0 );
3180   setPreferenceProperty( shrink, "max", 100 );
3181
3182   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3183
3184   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3185
3186   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3187   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3188   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3189
3190   setPreferenceProperty( selW, "min", 1 );
3191   setPreferenceProperty( selW, "max", 5 );
3192
3193   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3194
3195   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3196   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3197
3198   setPreferenceProperty( preW, "min", 1 );
3199   setPreferenceProperty( preW, "max", 5 );
3200
3201   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3202
3203   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3204   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3205   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3206
3207   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3208   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3209
3210   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
3211   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3212   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
3213   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3214
3215   QStringList fam;
3216   fam.append( tr( "SMESH_FONT_ARIAL" ) );
3217   fam.append( tr( "SMESH_FONT_COURIER" ) );
3218   fam.append( tr( "SMESH_FONT_TIMES" ) );
3219   int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
3220
3221   setPreferenceProperty( tfont, "families", fam );
3222   setPreferenceProperty( tfont, "system", false );
3223   setPreferenceProperty( tfont, "widget_flags", wflag );
3224   setPreferenceProperty( lfont, "families", fam );
3225   setPreferenceProperty( lfont, "system", false );
3226   setPreferenceProperty( lfont, "widget_flags", wflag );
3227
3228   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3229
3230   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3231   setPreferenceProperty( numcol, "min", 2 );
3232   setPreferenceProperty( numcol, "max", 256 );
3233
3234   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3235   setPreferenceProperty( numlab, "min", 2 );
3236   setPreferenceProperty( numlab, "max", 65 );
3237
3238   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3239   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3240   QStringList orients;
3241   orients.append( tr( "SMESH_VERTICAL" ) );
3242   orients.append( tr( "SMESH_HORIZONTAL" ) );
3243   indices.clear(); indices.append( 0 ); indices.append( 1 );
3244   setPreferenceProperty( orient, "strings", orients );
3245   setPreferenceProperty( orient, "indexes", indices );
3246
3247   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3248   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3249   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3250   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3251   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3252   setPreferenceProperty( xv, "step", 0.1 );
3253   setPreferenceProperty( xv, "min", 0.0 );
3254   setPreferenceProperty( xv, "max", 1.0 );
3255   setPreferenceProperty( yv, "step", 0.1 );
3256   setPreferenceProperty( yv, "min", 0.0 );
3257   setPreferenceProperty( yv, "max", 1.0 );
3258   setPreferenceProperty( wv, "step", 0.1 );
3259   setPreferenceProperty( wv, "min", 0.0 );
3260   setPreferenceProperty( wv, "max", 1.0 );
3261   setPreferenceProperty( hv, "min", 0.0 );
3262   setPreferenceProperty( hv, "max", 1.0 );
3263   setPreferenceProperty( hv, "step", 0.1 );
3264
3265   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3266   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3267   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3268   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3269   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3270   setPreferenceProperty( xv, "min", 0.0 );
3271   setPreferenceProperty( xv, "max", 1.0 );
3272   setPreferenceProperty( xv, "step", 0.1 );
3273   setPreferenceProperty( xh, "min", 0.0 );
3274   setPreferenceProperty( xh, "max", 1.0 );
3275   setPreferenceProperty( xh, "step", 0.1 );
3276   setPreferenceProperty( yh, "min", 0.0 );
3277   setPreferenceProperty( yh, "max", 1.0 );
3278   setPreferenceProperty( yh, "step", 0.1 );
3279   setPreferenceProperty( wh, "min", 0.0 );
3280   setPreferenceProperty( wh, "max", 1.0 );
3281   setPreferenceProperty( wh, "step", 0.1 );
3282   setPreferenceProperty( hh, "min", 0.0 );
3283   setPreferenceProperty( hh, "max", 1.0 );
3284   setPreferenceProperty( hh, "step", 0.1 );
3285 }
3286
3287 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3288 {
3289   if( sect=="SMESH" ){
3290     float sbX1,sbY1,sbW,sbH;
3291     float aTol = 1.00000009999999;
3292     std::string aWarning;
3293     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3294     if( name=="selection_object_color" || name=="selection_element_color" ||
3295         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3296         name=="selection_precision_node" || name=="selection_precision_element" ||
3297         name=="selection_precision_object")
3298       SMESH::UpdateSelectionProp( this );
3299     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3300       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3301       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3302       if(sbX1+sbW > aTol){
3303         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3304         sbX1=0.01;
3305         sbW=0.05;
3306         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3307         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3308       }
3309     }
3310     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3311       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3312       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3313       if(sbY1+sbH > aTol){
3314         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3315         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3316         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3317       }
3318     }
3319     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3320       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3321       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3322       if(sbX1+sbW > aTol){
3323         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3324         sbX1=0.01;
3325         sbW=0.05;
3326         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3327         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3328       }
3329     }
3330     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3331       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3332       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3333       if(sbY1+sbH > aTol){
3334         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3335         sbY1=0.01;
3336         sbH=0.05;
3337         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3338         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3339       }
3340     }
3341
3342     if(aWarning.size() != 0){
3343       aWarning += "The default values are applied instead.";
3344       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
3345                              QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3346                              QObject::tr(aWarning.c_str()),
3347                              QObject::tr("SMESH_BUT_OK"));
3348     }
3349   }
3350 }
3351
3352 //================================================================================
3353 /*!
3354  * \brief Update something in accordance with update flags
3355   * \param theFlags - update flags
3356 *
3357 * Update viewer or/and object browser etc. in accordance with update flags ( see
3358 * LightApp_UpdateFlags enumeration ).
3359 */
3360 //================================================================================
3361 void SMESHGUI::update( const int flags )
3362 {
3363   if ( flags & UF_Viewer | flags & UF_Forced )
3364     SMESH::UpdateView();
3365   else
3366     SalomeApp_Module::update( flags );
3367 }
3368
3369 //================================================================================
3370 /*!
3371  * \brief Set default selection mode
3372 *
3373 * SLOT called when operation commited. Sets default selection mode
3374 */
3375 //================================================================================
3376 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3377 {
3378   SVTK_ViewWindow* vtkWnd =
3379     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3380   if ( vtkWnd )
3381     vtkWnd->SetSelectionMode( ActorSelection );
3382 }
3383
3384 //================================================================================
3385 /*!
3386  * \brief Set default selection mode
3387 *
3388 * SLOT called when operation aborted. Sets default selection mode
3389 */
3390 //================================================================================
3391 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3392 {
3393   SVTK_ViewWindow* vtkWnd =
3394     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3395   if ( vtkWnd )
3396     vtkWnd->SetSelectionMode( ActorSelection );
3397 }
3398
3399 //================================================================================
3400 /*!
3401  * \brief Creates operation with given identifier
3402   * \param id - identifier of operation to be started
3403   * \return Pointer on created operation or NULL if operation is not created
3404 *
3405 * Virtual method redefined from the base class creates operation with given id.
3406 * It is called called automatically from startOperation method of base class.
3407 */
3408 //================================================================================
3409 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3410 {
3411   LightApp_Operation* op = 0;
3412   // to do : create operation here
3413   switch( id )
3414   {
3415     case 701: // Compute mesh
3416       op = new SMESHGUI_ComputeOp();
3417     break;
3418     case 702: // Create mesh
3419       op = new SMESHGUI_MeshOp( true, true );
3420     break;
3421     case 703: // Create sub-mesh
3422       op = new SMESHGUI_MeshOp( true, false );
3423     break;
3424     case 704: // Edit mesh/sub-mesh
3425       op = new SMESHGUI_MeshOp( false );
3426     break;
3427     case 417: //convert to quadratic
3428       op = new SMESHGUI_ConvToQuadOp();
3429     break;
3430     case 4067: // make mesh pass through point
3431       op = new SMESHGUI_MakeNodeAtPointOp();
3432       break;
3433     default:
3434     break;
3435   }
3436
3437   if( !op )
3438     op = SalomeApp_Module::createOperation( id );
3439   return op;
3440 }
3441
3442 //================================================================================
3443 /*!
3444  * \brief Stops current operations and starts a given one
3445   * \param id - The id of the operation to start
3446  */
3447 //================================================================================
3448
3449 void SMESHGUI::switchToOperation(int id)
3450 {
3451   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3452     activeStudy()->abortAllOperations();
3453   startOperation( id );
3454 }
3455
3456 LightApp_Displayer* SMESHGUI::displayer()
3457 {
3458   if( !myDisplayer )
3459     myDisplayer = new SMESHGUI_Displayer( getApp() );
3460   return myDisplayer;
3461 }
3462
3463 SALOMEDS::Color SMESHGUI::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
3464 {
3465   int aHue = -1;
3466   int aTolerance = 64;
3467   int anIterations = 0;
3468   int aPeriod = 5;
3469
3470   while( 1 )
3471   {
3472     anIterations++;
3473     if( anIterations % aPeriod == 0 )
3474     {
3475       aTolerance /= 2;
3476       if( aTolerance < 1 )
3477         break;
3478     }
3479     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
3480
3481     aHue = (int)( 360.0 * rand() / RAND_MAX );
3482     //cout << "Hue = " << aHue << endl;
3483
3484     //cout << "Auto colors : ";
3485     bool ok = true;
3486     QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
3487     QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
3488     for( ; it != itEnd; ++it )
3489     {
3490       SALOMEDS::Color anAutoColor = *it;
3491       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
3492
3493       int h, s, v;
3494       aQColor.getHsv( &h, &s, &v );
3495       //cout << h << " ";
3496       if( abs( h - aHue ) < aTolerance )
3497       {
3498         ok = false;
3499         //cout << "break (diff = " << abs( h - aHue ) << ")";
3500         break;
3501       }
3502     }
3503     //cout << endl;
3504
3505     if( ok )
3506       break;
3507   }
3508
3509   //cout << "Hue of the returned color = " << aHue << endl;
3510   QColor aColor;
3511   aColor.setHsv( aHue, 255, 255 );
3512
3513   SALOMEDS::Color aSColor;
3514   aSColor.R = (double)aColor.red() / 255.0;
3515   aSColor.G = (double)aColor.green() / 255.0;
3516   aSColor.B = (double)aColor.blue() / 255.0;
3517
3518   return aSColor;
3519 }