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