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