Salome HOME
PAL19802 A "Clear Mesh data" method for SMESH.Mesh objects
[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
1517   case 407: // DIAGONAL INVERSION
1518   case 408: // Delete diagonal
1519     {
1520       if ( !vtkwnd )
1521       {
1522         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1523           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1524         break;
1525       }
1526
1527       if ( checkLock( aStudy ) )
1528         break;
1529
1530       /*Standard_Boolean aRes;
1531       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1532       if ( aMesh->_is_nil() )
1533       {
1534         SUIT_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1535           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1536         break;
1537       }
1538       */
1539       EmitSignalDeactivateDialog();
1540       if ( theCommandID == 407 )
1541         new SMESHGUI_TrianglesInversionDlg(this);
1542       else
1543         new SMESHGUI_UnionOfTwoTrianglesDlg(this);
1544       break;
1545     }
1546     case 409: // Change orientation
1547     case 410: // Union of triangles
1548     case 411: // Cutting of quadrangles
1549     {
1550       if ( !vtkwnd )
1551       {
1552         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1553           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1554         break;
1555       }
1556
1557       if ( checkLock( aStudy ) )
1558         break;
1559
1560       EmitSignalDeactivateDialog();
1561       SMESHGUI_MultiEditDlg* aDlg = NULL;
1562       if ( theCommandID == 409 )
1563         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1564       else if ( theCommandID == 410 )
1565         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1566       else
1567         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1568
1569       aDlg->show();
1570       break;
1571     }
1572   case 412: // Smoothing
1573     {
1574       if(checkLock(aStudy)) break;
1575       if( vtkwnd ) {
1576         EmitSignalDeactivateDialog();
1577         new SMESHGUI_SmoothingDlg( this );
1578       }
1579       else {
1580         SUIT_MessageBox::warn1(desktop(),
1581                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1582                               tr("SMESH_BUT_OK"));
1583       }
1584       break;
1585     }
1586   case 413: // Extrusion
1587     {
1588       if (checkLock(aStudy)) break;
1589       if (vtkwnd) {
1590         EmitSignalDeactivateDialog();
1591         new SMESHGUI_ExtrusionDlg ( this );
1592       } else {
1593         SUIT_MessageBox::warn1(desktop(),
1594                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1595                                tr("SMESH_BUT_OK"));
1596       }
1597       break;
1598     }
1599   case 414: // Revolution
1600     {
1601       if(checkLock(aStudy)) break;
1602       if( vtkwnd ) {
1603         EmitSignalDeactivateDialog();
1604         new SMESHGUI_RevolutionDlg( this );
1605       }
1606       else {
1607         SUIT_MessageBox::warn1(desktop(),
1608                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1609                               tr("SMESH_BUT_OK"));
1610       }
1611       break;
1612     }
1613   case 415: // Pattern mapping
1614     {
1615       if ( checkLock( aStudy ) )
1616         break;
1617       if ( vtkwnd )
1618       {
1619         EmitSignalDeactivateDialog();
1620         new SMESHGUI_MeshPatternDlg( this );
1621       }
1622       else {
1623         SUIT_MessageBox::warn1(desktop(),
1624                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1625                               tr("SMESH_BUT_OK"));
1626       }
1627       break;
1628     }
1629   case 416: // Extrusion along a path
1630     {
1631       if (checkLock(aStudy)) break;
1632       if (vtkwnd) {
1633         EmitSignalDeactivateDialog();
1634         new SMESHGUI_ExtrusionAlongPathDlg( this );
1635       } else {
1636         SUIT_MessageBox::warn1(desktop(),
1637                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1638                                tr("SMESH_BUT_OK"));
1639       }
1640       break;
1641     }
1642   case 417: // Convert mesh to quadratic
1643     {
1644     startOperation( 417 );
1645       /*      if (checkLock(aStudy)) break;
1646       if (vtkwnd) {
1647         EmitSignalDeactivateDialog();
1648         new SMESHGUI_ConvToQuadDlg();
1649       } else {
1650         SUIT_MessageBox::warn1(desktop(),
1651                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1652                                tr("SMESH_BUT_OK"));
1653                                }*/
1654       break;
1655     }
1656   case 801:                                     // CREATE GROUP
1657     {
1658       if ( !vtkwnd )
1659       {
1660         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1661           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1662         break;
1663       }
1664
1665       if(checkLock(aStudy)) break;
1666       EmitSignalDeactivateDialog();
1667       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1668
1669       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1670       SALOME_ListIO selected;
1671       if( aSel )
1672         aSel->selectedObjects( selected );
1673
1674       int nbSel = selected.Extent();
1675       if (nbSel == 1) {
1676         // check if mesh is selected
1677         aMesh = SMESH::GetMeshByIO( selected.First() );
1678       }
1679       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aMesh);
1680       aDlg->show();
1681       break;
1682     }
1683
1684   case 802:                                     // CONSTRUCT GROUP
1685     {
1686       if ( !vtkwnd )
1687       {
1688         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1689           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1690         break;
1691       }
1692
1693       if(checkLock(aStudy)) break;
1694       EmitSignalDeactivateDialog();
1695
1696       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1697       SALOME_ListIO selected;
1698       if( aSel )
1699         aSel->selectedObjects( selected );
1700
1701       int nbSel = selected.Extent();
1702       if (nbSel == 1) {
1703         // check if submesh is selected
1704         Handle(SALOME_InteractiveObject) IObject = selected.First();
1705         if (IObject->hasEntry()) {
1706           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1707           if( aSObj ) {
1708             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1709             if (!aSubMesh->_is_nil()) {
1710               try {
1711                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1712                 // get submesh elements list by types
1713                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1714                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1715                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1716                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1717                 // create group for each type o elements
1718                 QString aName = IObject->getName();
1719                 if (aNodes->length() > 0) {
1720                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1721                   aGroup->Add(aNodes.inout());
1722                 }
1723                 if (aEdges->length() > 0) {
1724                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1725                   aGroup->Add(aEdges.inout());
1726                 }
1727                 if (aFaces->length() > 0) {
1728                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1729                   aGroup->Add(aFaces.inout());
1730                 }
1731                 if (aVolumes->length() > 0) {
1732                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1733                   aGroup->Add(aVolumes.inout());
1734                 }
1735                 updateObjBrowser();
1736
1737               }
1738               catch(const SALOME::SALOME_Exception & S_ex){
1739                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1740               }
1741             }
1742           }
1743         }
1744       }
1745       else if(nbSel==0) {
1746         SUIT_MessageBox::warn1(desktop(),
1747                                tr("SMESH_WRN_WARNING"),
1748                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
1749                                tr("SMESH_BUT_OK"));
1750       }
1751       break;
1752     }
1753
1754   case 803:                                     // EDIT GROUP
1755     {
1756       if ( !vtkwnd )
1757       {
1758         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1759           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1760         break;
1761       }
1762
1763       if(checkLock(aStudy)) break;
1764       EmitSignalDeactivateDialog();
1765
1766       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1767       SALOME_ListIO selected;
1768       if( aSel )
1769         aSel->selectedObjects( selected );
1770
1771       SALOME_ListIteratorOfListIO It (selected);
1772       int nbSelectedGroups = 0;
1773       for ( ; It.More(); It.Next() )
1774       {
1775         SMESH::SMESH_GroupBase_var aGroup =
1776           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1777         if (!aGroup->_is_nil()) {
1778           nbSelectedGroups++;
1779           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
1780           aDlg->show();
1781         }
1782       }
1783       if (nbSelectedGroups == 0)
1784         {
1785           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_GroupBase::_nil());
1786           aDlg->show();
1787         }
1788       break;
1789     }
1790
1791   case 804:                                     // Add elements to group
1792     {
1793       if(checkLock(aStudy)) break;
1794       if (myState == 800) {
1795         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1796         if (aDlg) aDlg->onAdd();
1797       }
1798       break;
1799     }
1800
1801   case 805:                                     // Remove elements from group
1802     {
1803       if(checkLock(aStudy)) break;
1804       if (myState == 800) {
1805         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1806         if (aDlg) aDlg->onRemove();
1807       }
1808       break;
1809     }
1810
1811     case 810: // Union Groups
1812     case 811: // Intersect groups
1813     case 812: // Cut groups
1814     {
1815       if ( !vtkwnd )
1816       {
1817         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1818           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1819         break;
1820       }
1821
1822       if ( checkLock( aStudy ) )
1823         break;
1824
1825       EmitSignalDeactivateDialog();
1826
1827       int aMode;
1828       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1829       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1830       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1831
1832       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1833       break;
1834     }
1835
1836     case 813: // Delete groups with their contents
1837     {
1838       if ( !vtkwnd )
1839       {
1840         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1841           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1842         break;
1843       }
1844
1845       if ( checkLock( aStudy ) )
1846         break;
1847
1848       EmitSignalDeactivateDialog();
1849
1850       new SMESHGUI_DeleteGroupDlg( this );
1851       break;
1852     }
1853
1854   case 900:                                     // MESH INFOS
1855     {
1856       EmitSignalDeactivateDialog();
1857       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1858       SALOME_ListIO selected;
1859       if( aSel )
1860         aSel->selectedObjects( selected );
1861
1862       if ( selected.Extent() > 1 ) { // a dlg for each IO
1863         SALOME_ListIO IOs;
1864         SALOME_ListIteratorOfListIO It (selected);
1865         for ( ; It.More(); It.Next() ) {
1866           IOs.Clear(); IOs.Append( It.Value() );
1867           aSel->setSelectedObjects( IOs );
1868           new SMESHGUI_MeshInfosDlg(this, "", false);
1869         }
1870         // restore selection
1871         aSel->setSelectedObjects( selected );
1872       }
1873       else
1874         new SMESHGUI_MeshInfosDlg(this, "", false);
1875       break;
1876     }
1877
1878   case 902:                                     // STANDARD MESH INFOS
1879     {
1880       EmitSignalDeactivateDialog();
1881       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1882       SALOME_ListIO selected;
1883       if( aSel )
1884         aSel->selectedObjects( selected );
1885
1886       if ( selected.Extent() > 1 ) { // a dlg for each IO
1887         SALOME_ListIO IOs;
1888         SALOME_ListIteratorOfListIO It (selected);
1889         for ( ; It.More(); It.Next() ) {
1890           IOs.Clear();
1891           IOs.Append( It.Value() );
1892           aSel->setSelectedObjects( IOs );
1893           new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1894         }
1895         // restore selection
1896         aSel->setSelectedObjects( selected );
1897       }
1898       else
1899         new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1900       break;
1901     }
1902
1903   case 903:                                     // WHAT IS
1904     {
1905       EmitSignalDeactivateDialog();
1906       new SMESHGUI_WhatIsDlg( this, "", false);
1907       break;
1908     }
1909
1910   case 1100:                                    // EDIT HYPOTHESIS
1911     {
1912       if(checkLock(aStudy)) break;
1913
1914       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1915       SALOME_ListIO selected;
1916       if( aSel )
1917         aSel->selectedObjects( selected );
1918
1919       int nbSel = selected.Extent();
1920
1921       if (nbSel == 1) {
1922         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1923         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
1924
1925         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1926         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1927         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1928         if ( !aHypothesis->_is_nil() )
1929         {
1930           CORBA::String_var aHypType = aHypothesis->GetName();
1931           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypType);
1932           if (aCreator)
1933             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop() );
1934           else
1935           {
1936             // report error
1937           }
1938         }
1939       }
1940       updateObjBrowser( true );
1941       break;
1942     }
1943
1944   case 1101:                                    // RENAME
1945     {
1946       if ( checkLock( aStudy ) )
1947         break;
1948
1949       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1950       SALOME_ListIO selected;
1951       if( aSel )
1952         aSel->selectedObjects( selected );
1953
1954       bool isAny = false; // iss there any appropriate object selected
1955
1956       SALOME_ListIteratorOfListIO It( selected );
1957       for ( ; It.More(); It.Next() )
1958       {
1959         Handle(SALOME_InteractiveObject) IObject = It.Value();
1960         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
1961         _PTR(GenericAttribute) anAttr;
1962         _PTR(AttributeName) aName;
1963         if ( obj )
1964         {
1965           if ( obj->FindAttribute(anAttr, "AttributeName") )
1966           {
1967             aName = anAttr;
1968             QString newName = QString(aName->Value().c_str());
1969
1970             // check type to prevent renaming of inappropriate objects
1971             int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
1972             if (aType == MESH || aType == GROUP ||
1973                 aType == SUBMESH || aType == SUBMESH_COMPOUND ||
1974                 aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
1975                 aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
1976                 aType == HYPOTHESIS || aType == ALGORITHM)
1977             {
1978               isAny = true;
1979               newName = LightApp_NameDlg::getName(desktop(), newName);
1980               if ( !newName.isEmpty() )
1981               {
1982                 //old source: aStudy->renameIObject( IObject, newName );
1983                 aName->SetValue( newName.latin1() );
1984
1985                 // if current object is group update group's name
1986                 SMESH::SMESH_GroupBase_var aGroup =
1987                   SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1988                 if (!aGroup->_is_nil() )
1989                   aGroup->SetName( newName.latin1() );
1990
1991                 updateObjBrowser();
1992               }
1993             }
1994           }
1995         }
1996       } // for
1997
1998       if (!isAny) {
1999         SUIT_MessageBox::warn1(desktop(),
2000                                QObject::tr("SMESH_WRN_WARNING"),
2001                                QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"),
2002                                QObject::tr("SMESH_BUT_OK"));
2003       }
2004       break;
2005     }
2006
2007   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2008     {
2009       if(checkLock(aStudy)) break;
2010       SUIT_OverrideCursor wc;
2011
2012       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2013       SALOME_ListIO selected;
2014       if( aSel )
2015         aSel->selectedObjects( selected, QString::null, false );
2016
2017       SALOME_ListIteratorOfListIO It(selected);
2018       for (int i = 0; It.More(); It.Next(), i++) {
2019         Handle(SALOME_InteractiveObject) IObject = It.Value();
2020         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2021       }
2022       SALOME_ListIO l1;
2023       aSel->setSelectedObjects( l1 );
2024       updateObjBrowser();
2025       break;
2026     }
2027
2028   case 401:                                     // GEOM::EDGE
2029   case 4021:                                    // TRIANGLE
2030   case 4022:                                    // QUAD
2031   case 4023:                                    // POLYGON
2032   case 4031:                                    // TETRA
2033   case 4032:                                    // HEXA
2034     {
2035       if(checkLock(aStudy)) break;
2036       if ( vtkwnd ) {
2037         EmitSignalDeactivateDialog();
2038         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2039         int                 nbNodes = 2;
2040         switch (theCommandID) {
2041         case 4021:                                      // TRIANGLE
2042           type = SMDSAbs_Face; nbNodes = 3; break;
2043         case 4022:                                      // QUAD
2044           type = SMDSAbs_Face; nbNodes = 4; break;
2045         case 4031:                                      // TETRA
2046           type = SMDSAbs_Volume; nbNodes = 4; break;
2047         case 4023:                                      // POLYGON
2048           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2049         case 4032:                                      // HEXA
2050           type = SMDSAbs_Volume; nbNodes = 8; break;
2051         case 4033:                                      // POLYHEDRE
2052           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2053         default:;
2054         }
2055         new SMESHGUI_AddMeshElementDlg( this, "", type, nbNodes);
2056       }
2057       else {
2058         SUIT_MessageBox::warn1(desktop(),
2059                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2060                               tr("SMESH_BUT_OK"));
2061       }
2062       break;
2063     }
2064   case 4033:                                    // POLYHEDRON
2065     {
2066       if(checkLock(aStudy)) break;
2067       if ( vtkwnd ) {
2068         EmitSignalDeactivateDialog();
2069         new SMESHGUI_CreatePolyhedralVolumeDlg(this, "", FALSE );
2070       }
2071       else {
2072         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2073                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2074                               tr("SMESH_BUT_OK"));
2075       }
2076       break;
2077     }
2078   case 4034:     // QUADRATIC EDGE
2079   case 4035:     // QUADRATIC TRIANGLE
2080   case 4036:     // QUADRATIC QUADRANGLE
2081   case 4037:     // QUADRATIC TETRAHEDRON
2082   case 4038:     // QUADRATIC PYRAMID
2083   case 4039:     // QUADRATIC PENTAHEDRON
2084   case 4040:     // QUADRATIC HEXAHEDRON
2085     {
2086       if(checkLock(aStudy)) break;
2087       if ( vtkwnd ) {
2088         EmitSignalDeactivateDialog();
2089         int type;
2090
2091         switch (theCommandID) {
2092         case 4034:
2093           type = QUAD_EDGE; break;
2094         case 4035:
2095           type = QUAD_TRIANGLE; break;
2096         case 4036:
2097           type = QUAD_QUADRANGLE; break;
2098         case 4037:
2099           type = QUAD_TETRAHEDRON; break;
2100         case 4038:
2101           type = QUAD_PYRAMID; break;
2102         case 4039:
2103           type = QUAD_PENTAHEDRON; break;
2104         case 4040:
2105           type = QUAD_HEXAHEDRON;
2106           break;
2107         default:;
2108         }
2109          new SMESHGUI_AddQuadraticElementDlg( this, type );
2110       }
2111       else {
2112         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2113                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2114                                tr("SMESH_BUT_OK"));
2115       }
2116       break;
2117     }
2118   case 4041:                                    // REMOVES NODES
2119     {
2120       if(checkLock(aStudy)) break;
2121       if ( vtkwnd ) {
2122         EmitSignalDeactivateDialog();
2123         new SMESHGUI_RemoveNodesDlg(this);
2124       }
2125       else {
2126         SUIT_MessageBox::warn1(desktop(),
2127                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2128                               tr("SMESH_BUT_OK"));
2129       }
2130       break;
2131     }
2132   case 4042:                                    // REMOVES ELEMENTS
2133     {
2134       if(checkLock(aStudy)) break;
2135       if( vtkwnd ) {
2136         EmitSignalDeactivateDialog();
2137         new SMESHGUI_RemoveElementsDlg(this);
2138       }
2139       else
2140         {
2141           SUIT_MessageBox::warn1(desktop(),
2142                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2143                                 tr("SMESH_BUT_OK"));
2144         }
2145       break;
2146     }
2147   case 4043: {                                // CLEAR_MESH
2148
2149     if(checkLock(aStudy)) break;
2150     
2151     SALOME_ListIO selected;
2152     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2153       aSel->selectedObjects( selected );
2154
2155     SUIT_OverrideCursor wc;
2156     SALOME_ListIteratorOfListIO It (selected);
2157     for ( ; It.More(); It.Next() )
2158     {
2159       Handle(SALOME_InteractiveObject) IOS = It.Value();
2160       SMESH::SMESH_Mesh_var aMesh =
2161         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2162       if ( aMesh->_is_nil()) continue;
2163       try {
2164         SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
2165         aMesh->Clear();
2166         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
2167         SMESH::ModifiedMesh( aMeshSObj, false, true);
2168         // hide groups and submeshes
2169         _PTR(ChildIterator) anIter =
2170           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
2171         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
2172         {
2173           _PTR(SObject) so = anIter->Value();
2174           SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
2175         }
2176       }
2177       catch (const SALOME::SALOME_Exception& S_ex){
2178         wc.suspend();
2179         SalomeApp_Tools::QtCatchCorbaException(S_ex);
2180         wc.resume();
2181       }
2182     }
2183     SMESH::UpdateView();
2184     updateObjBrowser();
2185     break;
2186   }
2187   case 4051:                                    // RENUMBERING NODES
2188     {
2189       if(checkLock(aStudy)) break;
2190       if( vtkwnd ) {
2191         EmitSignalDeactivateDialog();
2192         new SMESHGUI_RenumberingDlg( this, "", 0);
2193       }
2194       else
2195         {
2196           SUIT_MessageBox::warn1(desktop(),
2197                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2198                                 tr("SMESH_BUT_OK"));
2199         }
2200       break;
2201     }
2202   case 4052:                                    // RENUMBERING ELEMENTS
2203     {
2204       if(checkLock(aStudy)) break;
2205       if ( vtkwnd ) {
2206         EmitSignalDeactivateDialog();
2207         new SMESHGUI_RenumberingDlg( this, "", 1);
2208       }
2209       else
2210         {
2211           SUIT_MessageBox::warn1(desktop(),
2212                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2213                                 tr("SMESH_BUT_OK"));
2214         }
2215       break;
2216     }
2217   case 4061:                                   // TRANSLATION
2218     {
2219       if(checkLock(aStudy)) break;
2220       if ( vtkwnd ) {
2221         EmitSignalDeactivateDialog();
2222         new SMESHGUI_TranslationDlg( this );
2223       }
2224       else {
2225         SUIT_MessageBox::warn1(desktop(),
2226                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2227                               tr("SMESH_BUT_OK"));
2228       }
2229       break;
2230     }
2231   case 4062:                                   // ROTATION
2232     {
2233       if(checkLock(aStudy)) break;
2234       if( vtkwnd ) {
2235         EmitSignalDeactivateDialog();
2236         new SMESHGUI_RotationDlg( this );
2237       }
2238       else {
2239         SUIT_MessageBox::warn1(desktop(),
2240                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2241                               tr("SMESH_BUT_OK"));
2242       }
2243       break;
2244     }
2245   case 4063:                                   // SYMMETRY
2246     {
2247       if(checkLock(aStudy)) break;
2248       if(vtkwnd) {
2249         EmitSignalDeactivateDialog();
2250         new SMESHGUI_SymmetryDlg( this );
2251       }
2252       else {
2253         SUIT_MessageBox::warn1(desktop(),
2254                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2255                               tr("SMESH_BUT_OK"));
2256       }
2257       break;
2258     }
2259   case 4064:                                   // SEWING
2260     {
2261       if(checkLock(aStudy)) break;
2262       if(vtkwnd) {
2263         EmitSignalDeactivateDialog();
2264         new SMESHGUI_SewingDlg( this );
2265       }
2266       else {
2267         SUIT_MessageBox::warn1(desktop(),
2268                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2269                               tr("SMESH_BUT_OK"));
2270       }
2271       break;
2272     }
2273   case 4065:                                   // MERGE NODES
2274     {
2275       if(checkLock(aStudy)) break;
2276       if(vtkwnd) {
2277         EmitSignalDeactivateDialog();
2278         new SMESHGUI_EditMeshDlg( this, 0 );
2279       }
2280       else {
2281         SUIT_MessageBox::warn1(desktop(),
2282                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2283                               tr("SMESH_BUT_OK"));
2284       }
2285       break;
2286     }
2287   case 4066:                                   // MERGE EQUAL ELEMENTS
2288     {
2289       if (checkLock(aStudy)) break;
2290       if (vtkwnd) {
2291         EmitSignalDeactivateDialog();
2292         new SMESHGUI_EditMeshDlg( this, 1 );
2293       } else {
2294         SUIT_MessageBox::warn1(desktop(),
2295                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2296                               tr("SMESH_BUT_OK"));
2297       }
2298       break;
2299     }
2300
2301   case 4067: // MAKE MESH PASS THROUGH POINT
2302     startOperation( 4067 );
2303     break;
2304
2305   case 5105: // Library of selection filters
2306   {
2307     static QValueList<int> aTypes;
2308     if ( aTypes.isEmpty() )
2309     {
2310       aTypes.append( SMESH::NODE );
2311       aTypes.append( SMESH::EDGE );
2312       aTypes.append( SMESH::FACE );
2313       aTypes.append( SMESH::VOLUME );
2314     }
2315     if (!myFilterLibraryDlg)
2316       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2317     else if (myFilterLibraryDlg->isHidden())
2318       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2319     myFilterLibraryDlg->raise();
2320   }
2321   break;
2322
2323   case 6017:                                    // CONTROLS
2324   case 6016:
2325   case 6015:
2326   case 6014:
2327   case 6013:
2328   case 6012:
2329   case 6011:
2330   case 6001:
2331   case 6018:
2332   case 6019:
2333   case 6002:
2334   case 6003:
2335   case 6004:
2336   case 6009:
2337     if ( vtkwnd ) {
2338
2339       LightApp_SelectionMgr* mgr = selectionMgr();
2340       SALOME_ListIO selected; mgr->selectedObjects( selected );
2341
2342       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2343         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2344         if ( SO ) {
2345           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2346           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2347           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2348           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2349           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2350             ::Control( theCommandID );
2351             break;
2352           }
2353         }
2354       }
2355       SUIT_MessageBox::warn1(desktop(),
2356                             tr( "SMESH_WRN_WARNING" ),
2357                             tr( "SMESH_BAD_SELECTION" ),
2358                             tr( "SMESH_BUT_OK" ) );
2359       break;
2360     }
2361     else {
2362       SUIT_MessageBox::warn1(desktop(),
2363                             tr( "SMESH_WRN_WARNING" ),
2364                             tr( "NOT_A_VTK_VIEWER" ),
2365                             tr( "SMESH_BUT_OK" ) );
2366     }
2367     break;
2368   case 9010:
2369     {
2370       LightApp_SelectionMgr* mgr = selectionMgr();
2371       SALOME_ListIO selected; mgr->selectedObjects( selected );
2372
2373       SALOME_ListIteratorOfListIO it(selected);
2374       for(; it.More(); it.Next()) {
2375         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2376         if(anIObject->hasEntry()) {
2377           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2378             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2379           }
2380         }
2381       }
2382       break;
2383     }
2384   case 9011:
2385     {
2386       LightApp_SelectionMgr* mgr = selectionMgr();
2387       SALOME_ListIO selected; mgr->selectedObjects( selected );
2388
2389       if (selected.Extent() == 1)       {
2390         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2391         if(anIObject->hasEntry())
2392           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2393             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2394           }
2395       }
2396       break;
2397     }
2398   }
2399
2400   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2401   //updateObjBrowser();
2402   return true;
2403 }
2404
2405 //=============================================================================
2406 /*!
2407  *
2408  */
2409 //=============================================================================
2410 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2411 {
2412   return false;
2413 }
2414
2415 //=============================================================================
2416 /*!
2417  *
2418  */
2419 //=============================================================================
2420 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2421 {
2422   return true;
2423 }
2424
2425 //=============================================================================
2426 /*!
2427  *
2428  */
2429 //=============================================================================
2430 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2431 {
2432   return true;
2433 }
2434
2435 //=============================================================================
2436 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2437  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2438  */
2439 //=============================================================================
2440 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2441                                   SUIT_ViewWindow* wnd )
2442 {
2443   if(theIO->hasEntry()){
2444     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2445     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2446   }
2447 }
2448
2449 //=======================================================================
2450 // function : createSMESHAction
2451 // purpose  :
2452 //=======================================================================
2453 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2454 {
2455   QIconSet icon;
2456   QWidget* parent = application()->desktop();
2457   SUIT_ResourceMgr* resMgr = resourceMgr();
2458   QPixmap pix;
2459   if ( icon_id.length() )
2460     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2461   else
2462     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ), false );
2463   if ( !pix.isNull() )
2464     icon = QIconSet( pix );
2465
2466   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2467           menu       = tr( QString( "MEN_" )+po_id ),
2468           status_bar = tr( QString( "STB_" )+po_id );
2469
2470   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2471 }
2472
2473 //=======================================================================
2474 // function : createPopupItem
2475 // purpose  :
2476 //=======================================================================
2477 void SMESHGUI::createPopupItem( const int id,
2478                                 const QString& clients,
2479                                 const QString& types,
2480                                 const QString& theRule,
2481                                 const int pId )
2482 {
2483   int parentId = pId;
2484   if( pId!=-1 )
2485     parentId = popupMgr()->actionId( action( pId ) );
2486
2487   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2488     popupMgr()->insert( action( id ), parentId, 0 );
2489
2490   QChar lc = QtxPopupMgr::Selection::defEquality();
2491   QString rule = "(%1) and (%2) and (%3)";
2492   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2493   if( clients.isEmpty() )
2494     rule = rule.arg( QString( "true" ) );
2495   else
2496     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2497   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2498   rule += theRule;
2499
2500   bool cont = myRules.contains( id );
2501   if( cont )
2502     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2503
2504   popupMgr()->setRule( action( id ), rule, true );
2505   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2506 }
2507
2508 //=======================================================================
2509 // function : initialize
2510 // purpose  :
2511 //=======================================================================
2512 void SMESHGUI::initialize( CAM_Application* app )
2513 {
2514   SalomeApp_Module::initialize( app );
2515
2516 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2517 //   if ( mgr )
2518   /* Automatic Update flag */
2519 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2520
2521   // ----- create actions --------------
2522
2523   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2524   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2525   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2526   createSMESHAction(  114, "NUM" );
2527   createSMESHAction(  121, "DAT" );
2528   createSMESHAction(  122, "MED" );
2529   createSMESHAction(  123, "UNV" );
2530   createSMESHAction(  140, "STL" );
2531   createSMESHAction(  124, "EXPORT_DAT" );
2532   createSMESHAction(  125, "EXPORT_MED" );
2533   createSMESHAction(  126, "EXPORT_UNV" );
2534   createSMESHAction(  141, "EXPORT_STL" );
2535   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
2536   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2537   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2538   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2539   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2540   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2541   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2542   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2543   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2544   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2545   createSMESHAction(  804, "ADD" );
2546   createSMESHAction(  805, "REMOVE" );
2547   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2548   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2549   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2550   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2551   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2552   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2553   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
2554   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2555   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2556   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2557   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2558   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2559   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2560   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2561   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2562   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2563   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2564   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2565   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2566   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2567   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2568   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2569   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2570   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2571   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2572   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2573   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2574   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2575   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2576   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2577   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
2578   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2579   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2580   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2581   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2582   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2583   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2584   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2585   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2586   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2587   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2588   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2589   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2590   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2591   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2592   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2593   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2594   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2595   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2596   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2597   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2598   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2599   createSMESHAction(  200, "RESET" );
2600   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2601   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2602   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2603   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2604   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2605   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2606   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2607   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2608   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2609   createSMESHAction(  220, "ALL" );
2610   createSMESHAction( 1100, "EDIT_HYPO" );
2611   createSMESHAction( 1101, "RENAME", "", Key_F2 );
2612   createSMESHAction( 1102, "UNASSIGN" );
2613   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2614   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2615   createSMESHAction( 1131, "DISPMODE" );
2616   createSMESHAction( 1132, "COLORS" );
2617   createSMESHAction( 1133, "TRANSP" );
2618   createSMESHAction( 1134, "CLIP" );
2619   createSMESHAction( 1135, "DISP_ENT" );
2620   createSMESHAction( 1136, "AUTO_COLOR" );
2621   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
2622   createSMESHAction( 2000, "CTRL" );
2623
2624   createSMESHAction( 300, "ERASE" );
2625   createSMESHAction( 301, "DISPLAY" );
2626   createSMESHAction( 302, "DISPLAY_ONLY" );
2627   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2628   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2629   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2630   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2631   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2632   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2633   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2634   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2635
2636   // ----- create menu --------------
2637   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2638       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2639       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2640       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2641       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2642       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2643       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2644
2645   createMenu( separator(), fileId );
2646
2647   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2648       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2649       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2650       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2651       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2652       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2653
2654   createMenu( 111, importId, -1 );
2655   createMenu( 112, importId, -1 );
2656   createMenu( 113, importId, -1 );
2657
2658   createMenu( 121, exportId, -1 );
2659   createMenu( 122, exportId, -1 );
2660   createMenu( 123, exportId, -1 );
2661   createMenu( 140, exportId, -1 ); // export to stl STL
2662
2663   createMenu( separator(), fileId, 10 );
2664
2665   createMenu( 33, editId, -1 );
2666
2667   createMenu( 5105, toolsId, -1 );
2668
2669   createMenu( 702, meshId, -1 ); // "Mesh" menu
2670   createMenu( 703, meshId, -1 );
2671   createMenu( 704, meshId, -1 );
2672   createMenu( 710, meshId, -1 );
2673   createMenu( separator(), meshId, -1 );
2674   createMenu( 701, meshId, -1 );
2675   createMenu( separator(), meshId, -1 );
2676   createMenu( 801, meshId, -1 );
2677   createMenu( 802, meshId, -1 );
2678   createMenu( 803, meshId, -1 );
2679   createMenu( separator(), meshId, -1 );
2680   createMenu( 810, meshId, -1 );
2681   createMenu( 811, meshId, -1 );
2682   createMenu( 812, meshId, -1 );
2683   createMenu( separator(), meshId, -1 );
2684   createMenu( 813, meshId, -1 );
2685   createMenu( separator(), meshId, -1 );
2686   createMenu( 900, meshId, -1 );
2687   createMenu( 902, meshId, -1 );
2688   createMenu( 903, meshId, -1 );
2689   createMenu( separator(), meshId, -1 );
2690
2691   createMenu( 6003, ctrlId, -1 );
2692   createMenu( 6001, ctrlId, -1 );
2693   createMenu( 6004, ctrlId, -1 );
2694   createMenu( separator(), ctrlId, -1 );
2695   createMenu( 6002, ctrlId, -1 );
2696   createMenu( 6018, ctrlId, -1 );
2697   createMenu( 6019, ctrlId, -1 );
2698   createMenu( 6011, ctrlId, -1 );
2699   createMenu( 6012, ctrlId, -1 );
2700   createMenu( 6013, ctrlId, -1 );
2701   createMenu( 6014, ctrlId, -1 );
2702   createMenu( 6015, ctrlId, -1 );
2703   createMenu( 6016, ctrlId, -1 );
2704   createMenu( separator(), ctrlId, -1 );
2705   createMenu( 6017, ctrlId, -1 );
2706   createMenu( 6009, ctrlId, -1 );
2707   createMenu( separator(), ctrlId, -1 );
2708
2709   createMenu( 400, addId, -1 );
2710   createMenu( 401, addId, -1 );
2711   createMenu( 4021, addId, -1 );
2712   createMenu( 4022, addId, -1 );
2713   createMenu( 4023, addId, -1 );
2714   createMenu( 4031, addId, -1 );
2715   createMenu( 4032, addId, -1 );
2716   createMenu( 4033, addId, -1 );
2717   createMenu( separator(), addId, -1 );
2718   createMenu( 4034, addId, -1 );
2719   createMenu( 4035, addId, -1 );
2720   createMenu( 4036, addId, -1 );
2721   createMenu( 4037, addId, -1 );
2722   createMenu( 4038, addId, -1 );
2723   createMenu( 4039, addId, -1 );
2724   createMenu( 4040, addId, -1 );
2725
2726   createMenu( 4041, removeId, -1 );
2727   createMenu( 4042, removeId, -1 );
2728   createMenu( 4043, removeId, -1 );
2729
2730   createMenu( 4051, renumId, -1 );
2731   createMenu( 4052, renumId, -1 );
2732
2733   createMenu( 4061, transfId, -1 );
2734   createMenu( 4062, transfId, -1 );
2735   createMenu( 4063, transfId, -1 );
2736   createMenu( 4064, transfId, -1 );
2737   createMenu( 4065, transfId, -1 );
2738   createMenu( 4066, transfId, -1 );
2739
2740   createMenu( 406, modifyId, -1 );
2741   createMenu( 4067,modifyId, -1 );
2742   createMenu( 407, modifyId, -1 );
2743   createMenu( 408, modifyId, -1 );
2744   createMenu( 409, modifyId, -1 );
2745   createMenu( 410, modifyId, -1 );
2746   createMenu( 411, modifyId, -1 );
2747   createMenu( 412, modifyId, -1 );
2748   createMenu( 413, modifyId, -1 );
2749   createMenu( 416, modifyId, -1 );
2750   createMenu( 414, modifyId, -1 );
2751   createMenu( 415, modifyId, -1 );
2752   createMenu( 417, modifyId, -1 );
2753
2754   createMenu( 214, viewId, -1 );
2755
2756   // ----- create toolbars --------------
2757   int meshTb     = createTool( tr( "TB_MESH" ) ),
2758       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2759       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2760       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2761       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2762
2763   createTool( 702, meshTb );
2764   createTool( 703, meshTb );
2765   createTool( 704, meshTb );
2766   createTool( 710, meshTb );
2767   createTool( separator(), meshTb );
2768   createTool( 701, meshTb );
2769   createTool( separator(), meshTb );
2770   createTool( 801, meshTb );
2771   createTool( 802, meshTb );
2772   createTool( 803, meshTb );
2773   createTool( separator(), meshTb );
2774   createTool( 900, meshTb );
2775   createTool( 902, meshTb );
2776   createTool( 903, meshTb );
2777   createTool( separator(), meshTb );
2778
2779   createTool( 6001, ctrlTb );
2780   createTool( 6003, ctrlTb );
2781   createTool( 6004, ctrlTb );
2782   createTool( separator(), ctrlTb );
2783   createTool( 6002, ctrlTb );
2784   createTool( 6018, ctrlTb );
2785   createTool( 6019, ctrlTb );
2786   createTool( 6011, ctrlTb );
2787   createTool( 6012, ctrlTb );
2788   createTool( 6013, ctrlTb );
2789   createTool( 6014, ctrlTb );
2790   createTool( 6015, ctrlTb );
2791   createTool( 6016, ctrlTb );
2792   createTool( separator(), ctrlTb );
2793   createTool( 6017, ctrlTb );
2794   createTool( 6009, ctrlTb );
2795   createTool( separator(), ctrlTb );
2796
2797   createTool( 400, addRemTb );
2798   createTool( 401, addRemTb );
2799   createTool( 4021, addRemTb );
2800   createTool( 4022, addRemTb );
2801   createTool( 4023, addRemTb );
2802   createTool( 4031, addRemTb );
2803   createTool( 4032, addRemTb );
2804   createTool( 4033, addRemTb );
2805   createTool( separator(), addRemTb );
2806   createTool( 4034, addRemTb );
2807   createTool( 4035, addRemTb );
2808   createTool( 4036, addRemTb );
2809   createTool( 4037, addRemTb );
2810   createTool( 4038, addRemTb );
2811   createTool( 4039, addRemTb );
2812   createTool( 4040, addRemTb );
2813   createTool( separator(), addRemTb );
2814   createTool( 4041, addRemTb );
2815   createTool( 4042, addRemTb );
2816   createTool( 4043, addRemTb );
2817   createTool( separator(), addRemTb );
2818   createTool( 4051, addRemTb );
2819   createTool( 4052, addRemTb );
2820   createTool( separator(), addRemTb );
2821   createTool( 4061, addRemTb );
2822   createTool( 4062, addRemTb );
2823   createTool( 4063, addRemTb );
2824   createTool( 4064, addRemTb );
2825   createTool( 4065, addRemTb );
2826   createTool( 4066, addRemTb );
2827   createTool( separator(), addRemTb );
2828
2829   createTool( 406, modifyTb );
2830   createTool( 4067,modifyTb );
2831   createTool( 407, modifyTb );
2832   createTool( 408, modifyTb );
2833   createTool( 409, modifyTb );
2834   createTool( 410, modifyTb );
2835   createTool( 411, modifyTb );
2836   createTool( 412, modifyTb );
2837   createTool( 413, modifyTb );
2838   createTool( 416, modifyTb );
2839   createTool( 414, modifyTb );
2840   createTool( 415, modifyTb );
2841   createTool( 417, modifyTb );
2842
2843   createTool( 214, dispModeTb );
2844
2845
2846   myRules.clear();
2847   QString OB = "'ObjectBrowser'",
2848           View = "'" + SVTK_Viewer::Type() + "'",
2849           pat = "'%1'",
2850           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2851           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2852           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2853           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2854           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
2855                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2856                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2857                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2858                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2859                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
2860                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
2861           subMesh = elems,
2862           mesh_group = mesh + " " + subMesh + " " + group,
2863           hyp_alg = hypo + " " + algo;
2864
2865   // popup for object browser
2866
2867   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
2868   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
2869   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2870   popupMgr()->insert( separator(), -1, 0 );
2871   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2872   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2873   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2874   createPopupItem( 902, OB, mesh );                        // STD_INFO
2875   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
2876   popupMgr()->insert( separator(), -1, 0 );
2877   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2878   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2879   popupMgr()->insert( separator(), -1, 0 );
2880   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
2881   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2882   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
2883   popupMgr()->insert( separator(), -1, 0 );
2884   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
2885   popupMgr()->insert( separator(), -1, 0 );
2886
2887   QString         nbSelected = QtxPopupMgr::Selection::defSelCountParam();
2888   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( nbSelected );
2889
2890   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
2891   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
2892   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
2893   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
2894   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
2895   popupMgr()->insert( separator(), -1, 0 );
2896
2897   // popup for viewer
2898   createPopupItem( 803, View, group ); // EDIT_GROUP
2899   createPopupItem( 804, View, elems ); // ADD
2900   createPopupItem( 805, View, elems ); // REMOVE
2901   popupMgr()->insert( separator(), -1, 0 );
2902   createPopupItem( 214, View, mesh_group ); // UPDATE
2903   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2904   createPopupItem( 902, View, mesh );       // STD_INFO
2905   createPopupItem( 903, View, mesh_group ); // WHAT_IS
2906   popupMgr()->insert( separator(), -1, 0 );
2907
2908   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
2909   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
2910   popupMgr()->insert( separator(), -1, 0 );
2911
2912   int anId;
2913   QString
2914     isInvisible("not( isVisible )"),
2915     isEmpty("numberOfNodes = 0"),
2916     isNotEmpty("numberOfNodes <> 0"),
2917
2918     // has nodes, edges, etc in VISIBLE! actor
2919     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
2920     hasElems("(count( elemTypes ) > 0)"),
2921     hasDifferentElems("(count( elemTypes ) > 1)"),
2922     hasEdges("({'Edge'} in elemTypes)"),
2923     hasFaces("({'Face'} in elemTypes)"),
2924     hasVolumes("({'Volume'} in elemTypes)");
2925
2926   QString lc = QtxPopupMgr::Selection::defEquality();
2927   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
2928   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() );
2929   aType = aType.arg( mesh_group );
2930   QString aMeshInVTK = aClient + "&&" + aType;
2931
2932   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
2933   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
2934   QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2935
2936   //-------------------------------------------------
2937   // Numbering
2938   //-------------------------------------------------
2939   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
2940
2941   popupMgr()->insert( action( 9010 ), anId, -1 );
2942   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, true );
2943   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
2944
2945   popupMgr()->insert( action( 9011 ), anId, -1 );
2946   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, true );
2947   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
2948
2949   popupMgr()->insert( separator(), -1, -1 );
2950
2951   //-------------------------------------------------
2952   // Display Mode
2953   //-------------------------------------------------
2954   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
2955
2956   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
2957   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
2958   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
2959
2960   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
2961   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
2962   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
2963
2964   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
2965   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
2966   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
2967
2968   popupMgr()->insert( separator(), anId, -1 );
2969
2970   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
2971   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
2972   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
2973
2974   //-------------------------------------------------
2975   // Display Entity
2976   //-------------------------------------------------
2977   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
2978
2979   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
2980
2981   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
2982   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, true );
2983   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
2984
2985   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
2986   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, true );
2987   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
2988
2989   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
2990   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, true );
2991   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
2992
2993   popupMgr()->insert( separator(), anId, -1 );
2994
2995   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
2996   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", true );
2997
2998   //-------------------------------------------------
2999   // Color / Size
3000   //-------------------------------------------------
3001   popupMgr()->insert( action( 1132 ), -1, -1 );
3002   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
3003
3004   //-------------------------------------------------
3005   // Transparency
3006   //-------------------------------------------------
3007   popupMgr()->insert( action( 1133 ), -1, -1 );
3008   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
3009
3010   //-------------------------------------------------
3011   // Clipping
3012   //-------------------------------------------------
3013   popupMgr()->insert( action( 1134 ), -1, -1 );
3014   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
3015
3016   popupMgr()->insert( separator(), -1, -1 );
3017
3018   //-------------------------------------------------
3019   // Controls
3020   //-------------------------------------------------
3021   QString
3022     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3023     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3024     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3025
3026   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3027
3028   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3029   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3030
3031   popupMgr()->insert( separator(), anId, -1 );
3032
3033   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
3034   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
3035   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", false );
3036
3037   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
3038   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
3039   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
3040
3041   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
3042   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
3043   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
3044
3045   popupMgr()->insert( separator(), anId, -1 );
3046
3047   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
3048   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
3049   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", false );
3050
3051   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
3052   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
3053   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
3054
3055   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3056   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
3057   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
3058
3059   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3060   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
3061   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
3062
3063   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3064   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
3065   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
3066
3067   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3068   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
3069   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
3070
3071   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3072   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
3073   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
3074
3075   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3076   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
3077   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
3078
3079   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3080   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
3081   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
3082
3083   popupMgr()->insert( separator(), anId, -1 );
3084
3085   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3086   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
3087   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
3088
3089   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3090   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, true );
3091   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", false );
3092
3093   popupMgr()->insert( separator(), anId, -1 );
3094
3095   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3096   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3097
3098   popupMgr()->insert( separator(), -1, -1 );
3099
3100   //-------------------------------------------------
3101   // Display / Erase
3102   //-------------------------------------------------
3103   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3104     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3105   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3106   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), true);
3107
3108   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3109   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), true );
3110
3111   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3112   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), true );
3113
3114   popupMgr()->insert( separator(), -1, -1 );
3115
3116   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3117            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3118 }
3119
3120 //================================================================================
3121 /*!
3122  * \brief Return true if SMESH or GEOM objects are selected.
3123  * Is called form LightApp_Module::activateModule() which clear selection if
3124  * not isSelectionCompatible()
3125  */
3126 //================================================================================
3127
3128 bool SMESHGUI::isSelectionCompatible()
3129 {
3130   bool isCompatible = true;
3131   SALOME_ListIO selected;
3132   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
3133     Sel->selectedObjects( selected );
3134
3135   SALOME_ListIteratorOfListIO It( selected );
3136   for ( ; isCompatible && It.More(); It.Next())
3137     isCompatible =
3138       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
3139       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
3140
3141   return isCompatible;
3142 }
3143
3144 bool SMESHGUI::activateModule( SUIT_Study* study )
3145 {
3146   bool res = SalomeApp_Module::activateModule( study );
3147
3148   setMenuShown( true );
3149   setToolShown( true );
3150
3151   // Reset actions accelerator keys
3152   action(111)->setAccel(QKeySequence(CTRL + Key_B)); // Import DAT
3153   action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
3154   action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
3155
3156   action(  33)->setEnabled(true); // Delete: Key_Delete
3157   action(1101)->setEnabled(true); // Rename: Key_F2
3158
3159   return res;
3160 }
3161
3162 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3163 {
3164   setMenuShown( false );
3165   setToolShown( false );
3166
3167   EmitSignalCloseAllDialogs();
3168
3169   // Unset actions accelerator keys
3170   action(111)->setAccel(QKeySequence()); // Import DAT
3171   action(112)->setAccel(QKeySequence()); // Import UNV
3172   action(113)->setAccel(QKeySequence()); // Import MED
3173
3174   action(  33)->setEnabled(false); // Delete: Key_Delete
3175   action(1101)->setEnabled(false); // Rename: Key_F2
3176
3177   return SalomeApp_Module::deactivateModule( study );
3178 }
3179
3180 void SMESHGUI::studyClosed( SUIT_Study* s )
3181 {
3182   SMESH::RemoveVisuData( s->id() );
3183   SalomeApp_Module::studyClosed( s );
3184 }
3185
3186 void SMESHGUI::OnGUIEvent()
3187 {
3188   const QObject* obj = sender();
3189   if ( !obj || !obj->inherits( "QAction" ) )
3190     return;
3191   int id = actionId((QAction*)obj);
3192   if ( id != -1 )
3193     OnGUIEvent( id );
3194 }
3195
3196 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3197 {
3198   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3199   if ( CORBA::is_nil( myComponentSMESH ) )
3200     {
3201       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3202       if ( aStudy )
3203         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3204       return aGUI.myComponentSMESH;
3205     }
3206   if ( aStudy )
3207     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3208   return myComponentSMESH;
3209 }
3210
3211 QString SMESHGUI::engineIOR() const
3212 {
3213   CORBA::ORB_var anORB = getApp()->orb();
3214   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3215   return QString( anIOR.in() );
3216 }
3217
3218 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
3219 {
3220   SMESHGUI_Selection sel;
3221   sel.init( client, selectionMgr() );
3222   popupMgr()->updatePopup( menu, &sel );
3223
3224   SALOME_ListIO lst;
3225   selectionMgr()->selectedObjects( lst );
3226   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
3227     Handle(SALOME_InteractiveObject) io = lst.First();
3228     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
3229     _PTR(Study) study = appStudy->studyDS();
3230     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
3231     if ( obj ) {
3232       QString aName = QString( obj->GetName().c_str() );
3233       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
3234           aName.remove( (aName.length() - 1), 1 );
3235       title = aName;
3236     }
3237   }
3238 }
3239
3240 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3241 {
3242   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
3243   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
3244 }
3245
3246 void SMESHGUI::viewManagers( QStringList& list ) const
3247 {
3248   list.append( SVTK_Viewer::Type() );
3249 }
3250
3251 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3252 {
3253   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3254     SMESH::UpdateSelectionProp( this );
3255 }
3256
3257 void SMESHGUI::createPreferences()
3258 {
3259   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3260
3261   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3262   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3263
3264   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3265   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3266   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3267
3268   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
3269   setPreferenceProperty( precGroup, "columns", 1 );
3270
3271   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3272
3273   setPreferenceProperty( prec, "min", 0 );
3274   setPreferenceProperty( prec, "max", 16 );
3275
3276   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3277   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3278   QStringList modes;
3279   modes.append( "Wireframe" );
3280   modes.append( "Shading" );
3281   modes.append( "Nodes" );
3282   modes.append( "Shrink" );
3283   QValueList<QVariant> indices;
3284   indices.append( 0 );
3285   indices.append( 1 );
3286   indices.append( 2 );
3287   indices.append( 3 );
3288   setPreferenceProperty( dispmode, "strings", modes );
3289   setPreferenceProperty( dispmode, "indexes", indices );
3290
3291   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3292   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3293   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3294
3295   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3296   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3297
3298   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3299   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3300
3301   setPreferenceProperty( nodeSz, "min", 1 );
3302   setPreferenceProperty( nodeSz, "max", 5 );
3303
3304   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3305
3306   addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3307   addPreference( tr( "PREF_OUTLINE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3308   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3309   addPreference( "", elemGroup, LightApp_Preferences::Space );
3310
3311   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "element_width" );
3312   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
3313
3314   setPreferenceProperty( elemW, "min", 1 );
3315   setPreferenceProperty( elemW, "max", 5 );
3316
3317   setPreferenceProperty( shrink, "min", 0 );
3318   setPreferenceProperty( shrink, "max", 100 );
3319
3320   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3321
3322   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3323
3324   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3325   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3326   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3327
3328   setPreferenceProperty( selW, "min", 1 );
3329   setPreferenceProperty( selW, "max", 5 );
3330
3331   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3332
3333   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3334   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3335
3336   setPreferenceProperty( preW, "min", 1 );
3337   setPreferenceProperty( preW, "max", 5 );
3338
3339   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3340
3341   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3342   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3343   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3344
3345   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3346   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3347
3348   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
3349   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3350   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
3351   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3352
3353   QStringList fam;
3354   fam.append( tr( "SMESH_FONT_ARIAL" ) );
3355   fam.append( tr( "SMESH_FONT_COURIER" ) );
3356   fam.append( tr( "SMESH_FONT_TIMES" ) );
3357   int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
3358
3359   setPreferenceProperty( tfont, "families", fam );
3360   setPreferenceProperty( tfont, "system", false );
3361   setPreferenceProperty( tfont, "widget_flags", wflag );
3362   setPreferenceProperty( lfont, "families", fam );
3363   setPreferenceProperty( lfont, "system", false );
3364   setPreferenceProperty( lfont, "widget_flags", wflag );
3365
3366   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3367
3368   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3369   setPreferenceProperty( numcol, "min", 2 );
3370   setPreferenceProperty( numcol, "max", 256 );
3371
3372   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3373   setPreferenceProperty( numlab, "min", 2 );
3374   setPreferenceProperty( numlab, "max", 65 );
3375
3376   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3377   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3378   QStringList orients;
3379   orients.append( tr( "SMESH_VERTICAL" ) );
3380   orients.append( tr( "SMESH_HORIZONTAL" ) );
3381   indices.clear(); indices.append( 0 ); indices.append( 1 );
3382   setPreferenceProperty( orient, "strings", orients );
3383   setPreferenceProperty( orient, "indexes", indices );
3384
3385   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3386   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3387   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3388   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3389   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3390   setPreferenceProperty( xv, "step", 0.1 );
3391   setPreferenceProperty( xv, "min", 0.0 );
3392   setPreferenceProperty( xv, "max", 1.0 );
3393   setPreferenceProperty( yv, "step", 0.1 );
3394   setPreferenceProperty( yv, "min", 0.0 );
3395   setPreferenceProperty( yv, "max", 1.0 );
3396   setPreferenceProperty( wv, "step", 0.1 );
3397   setPreferenceProperty( wv, "min", 0.0 );
3398   setPreferenceProperty( wv, "max", 1.0 );
3399   setPreferenceProperty( hv, "min", 0.0 );
3400   setPreferenceProperty( hv, "max", 1.0 );
3401   setPreferenceProperty( hv, "step", 0.1 );
3402
3403   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3404   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3405   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3406   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3407   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3408   setPreferenceProperty( xv, "min", 0.0 );
3409   setPreferenceProperty( xv, "max", 1.0 );
3410   setPreferenceProperty( xv, "step", 0.1 );
3411   setPreferenceProperty( xh, "min", 0.0 );
3412   setPreferenceProperty( xh, "max", 1.0 );
3413   setPreferenceProperty( xh, "step", 0.1 );
3414   setPreferenceProperty( yh, "min", 0.0 );
3415   setPreferenceProperty( yh, "max", 1.0 );
3416   setPreferenceProperty( yh, "step", 0.1 );
3417   setPreferenceProperty( wh, "min", 0.0 );
3418   setPreferenceProperty( wh, "max", 1.0 );
3419   setPreferenceProperty( wh, "step", 0.1 );
3420   setPreferenceProperty( hh, "min", 0.0 );
3421   setPreferenceProperty( hh, "max", 1.0 );
3422   setPreferenceProperty( hh, "step", 0.1 );
3423 }
3424
3425 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3426 {
3427   if( sect=="SMESH" ){
3428     float sbX1,sbY1,sbW,sbH;
3429     float aTol = 1.00000009999999;
3430     std::string aWarning;
3431     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3432     if( name=="selection_object_color" || name=="selection_element_color" ||
3433         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3434         name=="selection_precision_node" || name=="selection_precision_element" ||
3435         name=="selection_precision_object")
3436       SMESH::UpdateSelectionProp( this );
3437     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3438       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3439       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3440       if(sbX1+sbW > aTol){
3441         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3442         sbX1=0.01;
3443         sbW=0.05;
3444         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3445         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3446       }
3447     }
3448     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3449       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3450       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3451       if(sbY1+sbH > aTol){
3452         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3453         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3454         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3455       }
3456     }
3457     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3458       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3459       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3460       if(sbX1+sbW > aTol){
3461         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3462         sbX1=0.01;
3463         sbW=0.05;
3464         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3465         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3466       }
3467     }
3468     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3469       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3470       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3471       if(sbY1+sbH > aTol){
3472         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3473         sbY1=0.01;
3474         sbH=0.05;
3475         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3476         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3477       }
3478     }
3479
3480     if(aWarning.size() != 0){
3481       aWarning += "The default values are applied instead.";
3482       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
3483                              QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3484                              QObject::tr(aWarning.c_str()),
3485                              QObject::tr("SMESH_BUT_OK"));
3486     }
3487   }
3488 }
3489
3490 //================================================================================
3491 /*!
3492  * \brief Update something in accordance with update flags
3493   * \param theFlags - update flags
3494 *
3495 * Update viewer or/and object browser etc. in accordance with update flags ( see
3496 * LightApp_UpdateFlags enumeration ).
3497 */
3498 //================================================================================
3499 void SMESHGUI::update( const int flags )
3500 {
3501   if ( flags & UF_Viewer | flags & UF_Forced )
3502     SMESH::UpdateView();
3503   else
3504     SalomeApp_Module::update( flags );
3505 }
3506
3507 //================================================================================
3508 /*!
3509  * \brief Set default selection mode
3510 *
3511 * SLOT called when operation commited. Sets default selection mode
3512 */
3513 //================================================================================
3514 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3515 {
3516   SVTK_ViewWindow* vtkWnd =
3517     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3518   if ( vtkWnd )
3519     vtkWnd->SetSelectionMode( ActorSelection );
3520 }
3521
3522 //================================================================================
3523 /*!
3524  * \brief Set default selection mode
3525 *
3526 * SLOT called when operation aborted. Sets default selection mode
3527 */
3528 //================================================================================
3529 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3530 {
3531   SVTK_ViewWindow* vtkWnd =
3532     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3533   if ( vtkWnd )
3534     vtkWnd->SetSelectionMode( ActorSelection );
3535 }
3536
3537 //================================================================================
3538 /*!
3539  * \brief Creates operation with given identifier
3540   * \param id - identifier of operation to be started
3541   * \return Pointer on created operation or NULL if operation is not created
3542 *
3543 * Virtual method redefined from the base class creates operation with given id.
3544 * It is called called automatically from startOperation method of base class.
3545 */
3546 //================================================================================
3547 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3548 {
3549   LightApp_Operation* op = 0;
3550   // to do : create operation here
3551   switch( id )
3552   {
3553     case 701: // Compute mesh
3554       op = new SMESHGUI_ComputeOp();
3555     break;
3556     case 702: // Create mesh
3557       op = new SMESHGUI_MeshOp( true, true );
3558     break;
3559     case 703: // Create sub-mesh
3560       op = new SMESHGUI_MeshOp( true, false );
3561     break;
3562     case 704: // Edit mesh/sub-mesh
3563       op = new SMESHGUI_MeshOp( false );
3564     break;
3565     case 417: //convert to quadratic
3566       op = new SMESHGUI_ConvToQuadOp();
3567     break;
3568     case 4067: // make mesh pass through point
3569       op = new SMESHGUI_MakeNodeAtPointOp();
3570       break;
3571     default:
3572     break;
3573   }
3574
3575   if( !op )
3576     op = SalomeApp_Module::createOperation( id );
3577   return op;
3578 }
3579
3580 //================================================================================
3581 /*!
3582  * \brief Stops current operations and starts a given one
3583   * \param id - The id of the operation to start
3584  */
3585 //================================================================================
3586
3587 void SMESHGUI::switchToOperation(int id)
3588 {
3589   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3590     activeStudy()->abortAllOperations();
3591   startOperation( id );
3592 }
3593
3594 LightApp_Displayer* SMESHGUI::displayer()
3595 {
3596   if( !myDisplayer )
3597     myDisplayer = new SMESHGUI_Displayer( getApp() );
3598   return myDisplayer;
3599 }
3600
3601 SALOMEDS::Color SMESHGUI::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
3602 {
3603   int aHue = -1;
3604   int aTolerance = 64;
3605   int anIterations = 0;
3606   int aPeriod = 5;
3607
3608   while( 1 )
3609   {
3610     anIterations++;
3611     if( anIterations % aPeriod == 0 )
3612     {
3613       aTolerance /= 2;
3614       if( aTolerance < 1 )
3615         break;
3616     }
3617     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
3618
3619     aHue = (int)( 360.0 * rand() / RAND_MAX );
3620     //cout << "Hue = " << aHue << endl;
3621
3622     //cout << "Auto colors : ";
3623     bool ok = true;
3624     QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
3625     QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
3626     for( ; it != itEnd; ++it )
3627     {
3628       SALOMEDS::Color anAutoColor = *it;
3629       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
3630
3631       int h, s, v;
3632       aQColor.getHsv( &h, &s, &v );
3633       //cout << h << " ";
3634       if( abs( h - aHue ) < aTolerance )
3635       {
3636         ok = false;
3637         //cout << "break (diff = " << abs( h - aHue ) << ")";
3638         break;
3639       }
3640     }
3641     //cout << endl;
3642
3643     if( ok )
3644       break;
3645   }
3646
3647   //cout << "Hue of the returned color = " << aHue << endl;
3648   QColor aColor;
3649   aColor.setHsv( aHue, 255, 255 );
3650
3651   SALOMEDS::Color aSColor;
3652   aSColor.R = (double)aColor.red() / 255.0;
3653   aSColor.G = (double)aColor.green() / 255.0;
3654   aSColor.B = (double)aColor.blue() / 255.0;
3655
3656   return aSColor;
3657 }