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