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