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