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