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