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