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