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