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