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