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