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