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