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