Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_CreatePolyhedralVolumeDlg.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 //
23 //
24 //  File   : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_ActorUtils.h"
37 #include "SMESHGUI_SpinBox.h"
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMDS_Mesh.hxx"
41
42 #include "SUIT_ResourceMgr.h"
43 #include "SUIT_Session.h"
44 #include "SUIT_MessageBox.h"
45
46 #include "SalomeApp_Application.h"
47 #include "SalomeApp_Study.h"
48 #include "SUIT_Desktop.h"
49 #include "SUIT_MessageBox.h"
50 #include "LightApp_Application.h"
51 #include "LightApp_SelectionMgr.h"
52 #include "utilities.h"
53
54 #include "SVTK_ViewWindow.h"
55 #include "SVTK_Selector.h"
56
57 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
58 #include <TColStd_ListOfInteger.hxx>
59 #include <TColStd_ListIteratorOfListOfInteger.hxx>
60
61 #include <vtkCell.h>
62 #include <vtkIdList.h>
63 #include <vtkIntArray.h>
64 #include <vtkCellArray.h>
65 #include <vtkUnsignedCharArray.h>
66 #include <vtkUnstructuredGrid.h>
67 #include <vtkDataSetMapper.h>
68 #include <vtkProperty.h>
69
70 // QT Includes
71 #include <qapplication.h>
72 #include <qbuttongroup.h>
73 #include <qgroupbox.h>
74 #include <qlabel.h>
75 #include <qlineedit.h>
76 #include <qpushbutton.h>
77 #include <qradiobutton.h>
78 #include <qcheckbox.h>
79 #include <qlayout.h>
80 #include <qspinbox.h> 
81 #include <qpixmap.h>
82 #include <qlistbox.h>
83
84 // IDL Headers
85 #include "SALOMEconfig.h"
86 #include CORBA_SERVER_HEADER(SMESH_Group)
87 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
88
89 using namespace std;
90
91 namespace SMESH{
92
93 class TPolySimulation{
94     SVTK_ViewWindow* myViewWindow;
95
96     SALOME_Actor *myPreviewActor;
97     vtkDataSetMapper* myMapper;
98     vtkUnstructuredGrid* myGrid;
99
100   public:
101
102     TPolySimulation(SalomeApp_Application* app)
103     {
104       SUIT_ViewManager* mgr = app->activeViewManager();
105       myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
106
107       myGrid = vtkUnstructuredGrid::New();
108   
109       // Create and display actor
110       myMapper = vtkDataSetMapper::New();
111       myMapper->SetInput( myGrid );
112
113       myPreviewActor = SALOME_Actor::New();
114       myPreviewActor->PickableOff();
115       myPreviewActor->VisibilityOff();
116       myPreviewActor->SetMapper( myMapper );
117       myPreviewActor->SetRepresentation( 3 );
118
119       vtkFloatingPointType anRGB[3];
120       vtkProperty* aProp = vtkProperty::New();
121       GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
122       aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
123       myPreviewActor->SetProperty( aProp );
124       vtkFloatingPointType aFactor,aUnits;
125       myPreviewActor->SetResolveCoincidentTopology(true);
126       myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
127       myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
128       aProp->Delete();
129
130       myViewWindow->AddActor( myPreviewActor );
131       
132     }
133
134
135     typedef std::vector<vtkIdType> TVTKIds;
136     void SetPosition(SMESH_Actor* theActor, 
137                      vtkIdType theType, 
138                      const TVTKIds& theIds,
139                      bool theReset=true)
140     {
141       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
142       myGrid->SetPoints(aGrid->GetPoints());
143
144       ResetGrid(theReset);
145       
146       vtkIdList *anIds = vtkIdList::New();
147
148       for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
149         anIds->InsertId(i,theIds[i]);
150
151       myGrid->InsertNextCell(theType,anIds);
152       if(theIds.size()!=0){
153         myGrid->InsertNextCell(theType,anIds);
154         myGrid->Modified();
155       }
156         
157       anIds->Delete();
158
159       SetVisibility(true);
160
161     }
162   
163     void ResetGrid(bool theReset=true){
164       if (theReset) myGrid->Reset();
165     }
166
167     void SetVisibility(bool theVisibility){
168       myPreviewActor->SetVisibility(theVisibility);
169       RepaintCurrentView();
170     }
171
172
173     ~TPolySimulation(){
174         if( myViewWindow )
175           myViewWindow->RemoveActor(myPreviewActor);
176
177       myPreviewActor->Delete();
178
179       myMapper->RemoveAllInputs();
180       myMapper->Delete();
181
182       myGrid->Delete();
183     }
184
185   };
186 }
187
188 //=================================================================================
189 // class    : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
190 // purpose  : 
191 //=================================================================================
192 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule, const char* name,
193                                                                         bool modal, WFlags fl )
194   : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
195     mySMESHGUI( theModule ),
196     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
197 {
198   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
199
200   if ( !name )
201     setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
202   resize( 300, 185 ); 
203   setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
204   setSizeGripEnabled( TRUE );
205   SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this ); 
206   SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
207   SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
208
209   /***************************************************************/
210   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
211   GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
212   GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
213   GroupConstructors->setExclusive( TRUE );
214   GroupConstructors->setColumnLayout(0, Qt::Vertical );
215   GroupConstructors->layout()->setSpacing( 0 );
216   GroupConstructors->layout()->setMargin( 0 );
217   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
218   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
219   GroupConstructorsLayout->setSpacing( 6 );
220   GroupConstructorsLayout->setMargin( 11 );
221   RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
222   RadioButton1->setText( tr( "MESH_NODE"  ) );
223   GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
224   RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
225   RadioButton2->setText( tr( "SMESH_FACE"  ) );
226   GroupConstructorsLayout->addWidget( RadioButton2, 0, 2  );
227   SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
228   
229   /***************************************************************/
230   GroupButtons = new QGroupBox( this, "GroupButtons" );
231   GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
232   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
233   GroupButtons->setTitle( tr( ""  ) );
234   GroupButtons->setColumnLayout(0, Qt::Vertical );
235   GroupButtons->layout()->setSpacing( 0 );
236   GroupButtons->layout()->setMargin( 0 );
237   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
238   GroupButtonsLayout->setAlignment( Qt::AlignTop );
239   GroupButtonsLayout->setSpacing( 6 );
240   GroupButtonsLayout->setMargin( 11 );
241   buttonCancel = new QPushButton( GroupButtons, "cancel" );
242   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
243   buttonCancel->setAutoDefault( TRUE );
244   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
245   buttonApply = new QPushButton( GroupButtons, "apply" );
246   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
247   buttonApply->setAutoDefault( TRUE );
248   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
249   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
250   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
251   buttonOk = new QPushButton( GroupButtons, "ok" );
252   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
253   buttonOk->setAutoDefault( TRUE );
254   buttonOk->setDefault( TRUE );
255   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
256   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
257   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
258   buttonHelp->setAutoDefault(TRUE);
259   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
260
261   SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
262
263   /***************************************************************/
264   GroupContent = new QGroupBox( this, "GroupContent" );
265   GroupContent->setTitle( tr( "SMESH_CONTENT" ) );
266   GroupContent->setColumnLayout(0, Qt::Vertical );
267   GroupContent->layout()->setSpacing( 0 );
268   GroupContent->layout()->setMargin( 0 );
269   GroupContentLayout = new QGridLayout( GroupContent->layout() );
270   GroupContentLayout->setAlignment( Qt::AlignTop );
271   GroupContentLayout->setSpacing( 6 );
272   GroupContentLayout->setMargin( 11 );
273
274   QFrame* anIds = new QFrame(GroupContent, "anIds");
275   QGridLayout* aLayout = new QGridLayout(anIds, 1, 3);
276   aLayout->setSpacing(6);
277   aLayout->setAutoAdd(false);
278   
279   TextLabelIds = new QLabel( anIds, "TextLabelIds" );
280   TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
281   TextLabelIds->setFixedWidth(74);
282   aLayout->addWidget( TextLabelIds, 0, 0 );
283
284   SelectElementsButton  = new QPushButton( anIds, "SelectElementsButton" );
285   SelectElementsButton->setText( tr( "" ) );
286   SelectElementsButton->setPixmap( image0 );
287   SelectElementsButton->setToggleButton( FALSE );
288   aLayout->addWidget( SelectElementsButton, 0, 1 );
289
290   LineEditElements  = new QLineEdit( anIds, "LineEditElements" );
291   LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
292   aLayout->addWidget( LineEditElements, 0, 2 );
293   
294   GroupContentLayout->addMultiCellWidget(anIds, 0, 0, 0, 1);
295
296   myFacesByNodesLabel = new QLabel(GroupContent, "faces by nodes label");
297   myFacesByNodesLabel->setText(tr("FACES_BY_NODES"));
298   GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
299
300   myFacesByNodes = new QListBox(GroupContent, "faces by nodes list");
301   myFacesByNodes->setSelectionMode(QListBox::Extended);
302   myFacesByNodes->setMinimumHeight(150);
303   GroupContentLayout->addMultiCellWidget( myFacesByNodes, 2, 4, 0, 0 );
304
305   AddButton = new QPushButton(GroupContent, "add");
306   AddButton->setText(tr("SMESH_BUT_ADD"));
307   AddButton->setMaximumWidth(85);
308   GroupContentLayout->addWidget( AddButton, 2, 1 );
309
310   RemoveButton = new QPushButton(GroupContent, "remove");
311   RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
312   RemoveButton->setMaximumWidth(85);
313   GroupContentLayout->addWidget( RemoveButton, 3, 1 );
314
315   Preview = new QCheckBox( GroupContent, "Preview" );
316   Preview->setText( tr( "SMESH_POLYEDRE_PREVIEW"  ) );
317   GroupContentLayout->addWidget( Preview , 5, 0 );
318
319   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
320   
321   SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
322   
323   GroupContent->show();
324   RadioButton1->setChecked( TRUE );
325  
326   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
327
328   myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
329   
330   Init();
331 }
332
333 //=================================================================================
334 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
335 // purpose  : Destroys the object and frees any allocated resources
336 //=================================================================================
337 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
338 {
339   // no need to delete child widgets, Qt does it all for us
340   delete mySimulation;
341 }
342
343 static bool busy = false;
344 //=================================================================================
345 // function : Init()
346 // purpose  :
347 //=================================================================================
348 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
349 {
350   myEditCurrentArgument = LineEditElements;
351   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
352
353   myNbOkElements = 0;
354   myActor = 0;
355
356   mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
357
358   /* signals and slots connections */
359   connect(buttonOk, SIGNAL( clicked() ),     SLOT( ClickOnOk() ) );
360   connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
361   connect(buttonApply, SIGNAL( clicked() ),  SLOT(ClickOnApply() ) );
362   connect(buttonHelp, SIGNAL(clicked()),     SLOT(ClickOnHelp() ) );
363
364   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
365   connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
366   connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
367
368   connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
369   connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
370   connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
371   
372   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
373   connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
374   connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
375   /* to close dialog if study change */
376   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
377   
378   this->show() ; /* displays Dialog */
379
380   ConstructorsClicked(0);
381   SelectionIntoArgument();
382 }
383
384
385 //=================================================================================
386 // function : ConstructorsClicked()
387 // purpose  : Radio button management
388 //=================================================================================
389 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
390 {
391   //disconnect(mySelectionMgr, 0, this, 0);
392
393   SALOME_ListIO io;
394   mySelectionMgr->selectedObjects( io );
395   SALOME_ListIO aList;
396   mySelectionMgr->setSelectedObjects( aList );
397   myEditCurrentArgument->clear();
398   myNbOkElements = 0;
399   buttonApply->setEnabled(false);
400   buttonOk->setEnabled(false);
401   mySimulation->SetVisibility(false);
402
403   switch(constructorId)
404     {
405     case 0 :
406       { 
407         if ( myActor ){
408           myActor->SetPointRepresentation(true);
409         }
410         else
411           SMESH::SetPointRepresentation(true);
412         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
413           aViewWindow->SetSelectionMode(NodeSelection);
414         
415         AddButton->setEnabled(false);
416         RemoveButton->setEnabled(false);
417         TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
418         myFacesByNodesLabel->show();
419         myFacesByNodes->clear();
420         myFacesByNodes->show();
421         AddButton->show();
422         RemoveButton->show();
423         Preview->show();
424         break;
425       }
426     case 1 :
427       {
428         if( myActor ){
429           myActor->SetPointRepresentation(false);
430         } else {
431           SMESH::SetPointRepresentation(false);
432         }
433         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
434           aViewWindow->SetSelectionMode(FaceSelection);
435         
436         TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
437         myFacesByNodesLabel->hide();
438         myFacesByNodes->hide();
439         AddButton->hide();
440         RemoveButton->hide();
441         Preview->show();
442         break;
443       }
444     }
445   
446   //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
447   mySelectionMgr->setSelectedObjects( io );
448 }
449
450 //=================================================================================
451 // function : ClickOnPreview()
452 // purpose  :
453 //=================================================================================
454 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
455   Preview->setChecked(theToggled);
456   displaySimulation();
457 }
458
459 //=================================================================================
460 // function : ClickOnApply()
461 // purpose  :
462 //=================================================================================
463 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
464 {
465   if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
466     {
467       if(checkEditLine(false) == -1) {return;}
468       busy = true;
469       if (GetConstructorId() == 0)
470         {
471           SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
472           SMESH::long_array_var aQuantities  = new SMESH::long_array;
473
474           aQuantities->length( myFacesByNodes->count() );
475
476           TColStd_ListOfInteger aNodesIds;
477
478           QListBoxItem* anItem;
479           int aNbQuantities = 0;
480           for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
481             QStringList anIds = QStringList::split(" ", anItem->text());
482             int aNbNodesInFace = 0;
483             for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
484               aNodesIds.Append( (*it).toInt() );
485
486             aQuantities[aNbQuantities++] = aNbNodesInFace;
487           }
488
489           anIdsOfNodes->length(aNodesIds.Extent());
490
491           int aNbIdsOfNodes = 0;
492           TColStd_ListIteratorOfListOfInteger It;
493           It.Initialize(aNodesIds);
494           for(;It.More();It.Next())
495             anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
496             
497           try{
498             SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
499             QApplication::setOverrideCursor(Qt::waitCursor);
500             aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
501             QApplication::restoreOverrideCursor();
502           }catch(SALOME::SALOME_Exception& exc){
503             INFOS("Follow exception was cought:\n\t"<<exc.details.text);
504           }catch(std::exception& exc){
505             INFOS("Follow exception was cought:\n\t"<<exc.what());
506           }catch(...){
507             INFOS("Unknown exception was cought !!!");
508           }
509         }
510       else if (GetConstructorId() == 1)
511         {
512           SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
513           
514           QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
515           anIdsOfFaces->length(aListId.count());
516           for ( int i = 0; i < aListId.count(); i++ )
517             anIdsOfFaces[i] = aListId[i].toInt();
518           
519           try{
520             SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
521             QApplication::setOverrideCursor(Qt::waitCursor);
522             aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
523             QApplication::restoreOverrideCursor();
524           }catch(SALOME::SALOME_Exception& exc){
525             INFOS("Follow exception was cought:\n\t"<<exc.details.text);
526           }catch(std::exception& exc){
527             INFOS("Follow exception was cought:\n\t"<<exc.what());
528           }catch(...){
529             INFOS("Unknown exception was cought !!!");
530           }
531         }
532       
533       //SALOME_ListIO aList;
534       //mySelectionMgr->setSelectedObjects( aList );
535       SMESH::UpdateView();
536       if( myActor ){
537         unsigned int anEntityMode = myActor->GetEntityMode();
538         myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
539       }
540       //ConstructorsClicked( GetConstructorId() );
541       busy = false;
542     }
543 }
544
545 //=================================================================================
546 // function : ClickOnOk()
547 // purpose  :
548 //=================================================================================
549 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
550 {
551   if(checkEditLine(false) == -1) {return;}
552   ClickOnApply() ;
553   ClickOnCancel() ;
554 }
555
556         
557 //=================================================================================
558 // function : ClickOnCancel()
559 // purpose  :
560 //=================================================================================
561 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
562 {
563   mySelectionMgr->clearFilters();
564   //SALOME_ListIO aList;
565   //mySelectionMgr->setSelectedObjects( aList );
566   SMESH::SetPointRepresentation(false);
567   mySimulation->SetVisibility(false);
568   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
569     aViewWindow->SetSelectionMode( ActorSelection );
570   disconnect( mySelectionMgr, 0, this, 0 );
571   mySMESHGUI->ResetState() ;
572   reject() ;
573 }
574
575 //=================================================================================
576 // function : ClickOnHelp()
577 // purpose  :
578 //=================================================================================
579 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
580 {
581   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
582   if (app) 
583     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
584   else {
585                 QString platform;
586 #ifdef WIN32
587                 platform = "winapplication";
588 #else
589                 platform = "application";
590 #endif
591     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
592                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
593                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
594                            QObject::tr("BUT_OK"));
595   }
596 }
597
598 //=======================================================================
599 //function : onTextChange
600 //purpose  : 
601 //=======================================================================
602
603 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
604 {
605   if ( busy ) return;
606   if (checkEditLine() == -1) return;
607   busy = true;
608
609   mySimulation->SetVisibility(false);
610
611   SMDS_Mesh* aMesh = 0;
612   if ( myActor )
613     aMesh = myActor->GetObject()->GetMesh();
614
615   if (GetConstructorId() == 0)
616   {
617     if ( aMesh ) {
618       TColStd_MapOfInteger newIndices;
619       
620       QStringList aListId = QStringList::split( " ", theNewText, false);
621       for ( int i = 0; i < aListId.count(); i++ ) {
622         const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
623         if ( n ) {
624           newIndices.Add(n->GetID());
625           myNbOkElements++;
626         }
627       }
628       
629       mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
630       
631       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
632         aViewWindow->highlight( myActor->getIO(), true, true );
633       
634       if ( myNbOkElements>0 && aListId.count()>=3)
635         AddButton->setEnabled(true);
636       else
637         AddButton->setEnabled(false);
638       
639       displaySimulation();
640     }
641   } else if (GetConstructorId() == 1)
642   {
643     myNbOkElements = 0;
644     buttonOk->setEnabled( false );
645     buttonApply->setEnabled( false );
646       
647       // check entered ids of faces and hilight them
648     QStringList aListId;
649     if ( aMesh ) {
650       TColStd_MapOfInteger newIndices;
651       
652       aListId = QStringList::split( " ", theNewText, false);
653
654       for ( int i = 0; i < aListId.count(); i++ ) {
655         const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
656         if ( e ) {
657           newIndices.Add(e->GetID());
658           myNbOkElements++;  
659         }
660       }
661
662       mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
663       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
664         aViewWindow->highlight( myActor->getIO(), true, true );
665       
666       if ( myNbOkElements ) {
667         if (aListId.count()>1){ 
668           buttonOk->setEnabled( true );
669           buttonApply->setEnabled( true );
670         }
671         else{
672           buttonOk->setEnabled( false );
673           buttonApply->setEnabled( false );
674         }
675         if(aListId.count()>1)
676           displaySimulation();
677       }
678     }
679   }
680   busy = false;
681 }
682
683 //=================================================================================
684 // function : SelectionIntoArgument()
685 // purpose  : Called when selection as changed or other case
686 //=================================================================================
687 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
688 {
689   if ( busy ) return;
690   
691   // clear
692   
693   if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
694     {
695       myNbOkElements = 0;
696       AddButton->setEnabled(false);
697       buttonOk->setEnabled( false );
698       buttonApply->setEnabled( false );
699     }
700
701   myActor = 0;
702
703   busy = true;
704   myEditCurrentArgument->setText( "" );
705   busy = false;
706   if ( !GroupButtons->isEnabled() ) // inactive
707     return;
708   
709   mySimulation->SetVisibility(false);
710   
711   // get selected mesh
712   
713   SALOME_ListIO selected;
714   mySelectionMgr->selectedObjects( selected );
715   int nbSel = selected.Extent();
716   if(nbSel != 1){
717     return;
718   }
719   
720   myMesh = SMESH::GetMeshByIO( selected.First() );
721   if ( myMesh->_is_nil() )
722     return;
723   
724   myActor = SMESH::FindActorByObject(myMesh);
725   if ( !myActor )
726     return;
727   
728   // get selected nodes/faces
729   QString aString = "";
730   int anbNodes=0,aNbFaces=0;
731   switch(GetConstructorId()){
732   case 0:{
733     anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
734     if (anbNodes >= 3)
735       AddButton->setEnabled(true);
736     else if (anbNodes < 3){
737       AddButton->setEnabled(false);
738     }
739     busy = true;
740     myEditCurrentArgument->setText( aString );
741     if (checkEditLine() == -1) {busy = false;return;}
742     busy = false;
743     break;
744   }
745   case 1:{
746     // get selected faces
747     aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
748     if (aNbFaces<=1){
749       buttonOk->setEnabled( false );
750       buttonApply->setEnabled( false );
751     } else {
752       buttonOk->setEnabled( true );
753       buttonApply->setEnabled( true );
754     }
755     busy = true;
756     myEditCurrentArgument->setText( aString );
757     if (checkEditLine() == -1) {busy = false;return;}
758     busy = false;
759     
760     // OK
761     myNbOkElements = 1;
762     break;
763   }
764   default: return;
765   }
766   if(anbNodes>2 || aNbFaces>1)
767     displaySimulation();
768 }
769
770 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
771  * Checking of indices in edit line.
772  * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
773  * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
774  */
775 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
776 {
777   QString aString = "";
778   SMDS_Mesh* aMesh = 0;
779   
780   if(myMesh->_is_nil()) return 1;
781   if(!myActor){
782     myActor = SMESH::FindActorByObject(myMesh);
783     if(!myActor)
784       return 1;
785   }
786     
787   aMesh = myActor->GetObject()->GetMesh();
788
789   // checking for nodes
790   if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
791   QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
792   for ( int i = 0; i < aListId.count(); i++ ){
793     switch (GetConstructorId()){
794     case 0:{ // nodes
795       const SMDS_MeshNode    * aNode = aMesh->FindNode( aListId[ i ].toInt() );
796       if( !aNode ){
797         std::string aWarning;
798         aWarning = "The incorrect indices of nodes!";
799         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
800                                QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
801                                QObject::tr(aWarning.c_str()),
802                                QObject::tr("SMESH_BUT_OK"));
803         
804         myEditCurrentArgument->clear();
805         myEditCurrentArgument->setText( aString );
806         return -1;
807       }
808
809       break;
810     }
811     case 1:{ // faces
812       bool aElemIsOK = true;
813       const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
814       if (!aElem)
815         {
816           aElemIsOK = false;
817         }
818       else
819         {
820           SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
821           if (aType != SMDSAbs_Face){
822             aElemIsOK = false;
823           }
824         }
825       if (!aElemIsOK){
826         std::string aWarning;
827         aWarning = "The incorrect indices of faces!";
828         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
829                                QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
830                                QObject::tr(aWarning.c_str()),
831                                QObject::tr("SMESH_BUT_OK"));
832         
833         myEditCurrentArgument->clear();
834         myEditCurrentArgument->setText( aString );
835         return -1;
836       }
837       break;
838     }
839     }
840     aString += aListId[ i ] + " "; 
841   }
842
843   return 1;
844 }
845
846 //=======================================================================
847 //function : displaySimulation
848 //purpose  : 
849 //=======================================================================
850 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
851 {
852   if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
853     {
854       SMESH::TPolySimulation::TVTKIds aVTKIds;
855       vtkIdType aType = VTK_CONVEX_POINT_SET ;
856       SMDS_Mesh* aMesh = 0;
857       if ( myActor ){
858         aMesh = myActor->GetObject()->GetMesh();
859       }
860       if (GetConstructorId() == 0 && aMesh){
861         if (!AddButton->isEnabled()){
862           QListBoxItem* anItem;
863           mySimulation->ResetGrid(true);
864           for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
865             QStringList anIds = QStringList::split(" ", anItem->text());
866             SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
867             for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
868               const SMDS_MeshNode    * aNode = aMesh->FindNode( (*it).toInt() );
869               if (!aNode) continue;
870               vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
871               aVTKIds.push_back(aId);
872               aVTKIds_faces.push_back(aId);
873             }
874             if(!Preview->isChecked()){
875               aType = VTK_POLYGON;
876               mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
877             }
878           }
879           if(myFacesByNodes->count() == 0){
880             mySimulation->SetVisibility(false);
881           } else {
882             mySimulation->SetVisibility(true);
883           }
884           if(Preview->isChecked()){
885             mySimulation->SetPosition(myActor, aType, aVTKIds);
886           }
887         } else {
888           // add ids from edit line
889           QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
890           for ( int i = 0; i < anEditIds.count(); i++ )
891             aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
892           aType = VTK_POLYGON;
893           mySimulation->SetPosition(myActor, aType, aVTKIds);
894         }
895       }else if(GetConstructorId() == 1 && aMesh){
896         QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
897         for ( int i = 0; i < aListId.count(); i++ )
898           {
899             const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
900             if ( !anElem ) continue;
901             SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
902             if (aFaceType != SMDSAbs_Face) continue;
903               
904             SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
905             SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
906             while( anIter->more() )
907                 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
908                   vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
909                   aVTKIds.push_back(aId);
910                   aVTKIds_faces.push_back(aId);
911                 }
912             if(!Preview->isChecked()){
913               aType = VTK_POLYGON;
914               mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
915             }
916           }
917         if(Preview->isChecked())
918           mySimulation->SetPosition(myActor, aType, aVTKIds);
919       }
920       SMESH::UpdateView();
921     }
922 }
923
924 //=================================================================================
925 // function : SetEditCurrentArgument()
926 // purpose  :
927 //=================================================================================
928 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
929 {
930   QPushButton* send = (QPushButton*)sender();
931   if(send == SelectElementsButton) {
932     LineEditElements->setFocus() ;
933     myEditCurrentArgument = LineEditElements;
934   }
935   SelectionIntoArgument();
936 }
937
938 //=================================================================================
939 // function : DeactivateActiveDialog()
940 // purpose  :
941 //=================================================================================
942 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
943 {
944   if ( GroupConstructors->isEnabled() ) {
945     GroupConstructors->setEnabled(false) ;
946     GroupContent->setEnabled(false) ;
947     GroupButtons->setEnabled(false) ;
948     mySimulation->SetVisibility(false);
949     mySMESHGUI->ResetState() ;    
950     mySMESHGUI->SetActiveDialogBox(0) ;
951   }
952 }
953
954
955 //=================================================================================
956 // function : ActivateThisDialog()
957 // purpose  :
958 //=================================================================================
959 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
960 {
961   /* Emit a signal to deactivate the active dialog */
962   mySMESHGUI->EmitSignalDeactivateDialog() ;   
963   GroupConstructors->setEnabled(true) ;
964   GroupContent->setEnabled(true) ;
965   GroupButtons->setEnabled(true) ;
966   
967   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
968
969   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
970     aViewWindow->SetSelectionMode( FaceSelection );
971   SelectionIntoArgument();
972 }
973
974
975 //=================================================================================
976 // function : enterEvent()
977 // purpose  :
978 //=================================================================================
979 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
980 {
981   if ( GroupConstructors->isEnabled() )
982     return ;  
983   ActivateThisDialog() ;
984 }
985
986
987 //=================================================================================
988 // function : closeEvent()
989 // purpose  :
990 //=================================================================================
991 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
992 {
993   /* same than click on cancel button */
994   this->ClickOnCancel() ;
995 }
996
997
998 //=======================================================================
999 //function : hideEvent
1000 //purpose  : caused by ESC key
1001 //=======================================================================
1002
1003 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
1004 {
1005   if ( !isMinimized() )
1006     ClickOnCancel();
1007 }
1008
1009
1010 //=================================================================================
1011 // function : GetConstructorId()
1012 // purpose  : 
1013 //=================================================================================
1014 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1015
1016   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
1017     return GroupConstructors->id( GroupConstructors->selected() );
1018   return -1;
1019 }
1020
1021 //=================================================================================
1022 // function : onAdd()
1023 // purpose  :
1024 //=================================================================================
1025 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1026 {
1027   SALOME_ListIO selected;
1028   mySelectionMgr->selectedObjects( selected );
1029   int aNbSel = selected.Extent();
1030   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1031   
1032   if (this->checkEditLine(false) == -1) return;
1033
1034   busy = true;
1035   if ( !(myEditCurrentArgument->text().isEmpty()) )
1036     {
1037       myFacesByNodes->insertItem(myEditCurrentArgument->text());
1038       //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1039       myNbOkElements = 1;
1040       myEditCurrentArgument->clear();
1041       AddButton->setEnabled(false);
1042       buttonOk->setEnabled( true );
1043       if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1044     }
1045   busy = false;
1046   onListSelectionChanged();
1047   displaySimulation();
1048 }
1049
1050 //=================================================================================
1051 // function : onRemove()
1052 // purpose  :
1053 //=================================================================================
1054 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1055 {
1056   busy = true;
1057   for (int i = myFacesByNodes->count(); i > 0; i--) {
1058     if (myFacesByNodes->isSelected(i-1)) {
1059       myFacesByNodes->removeItem(i-1);
1060       myNbOkElements = 1;
1061     }
1062   }
1063   if (myFacesByNodes->count() < 1){
1064     RemoveButton->setEnabled(false);
1065     buttonOk->setEnabled( false );
1066     buttonApply->setEnabled( false );
1067   } 
1068   else if (myFacesByNodes->count() == 1){
1069     buttonOk->setEnabled( false );
1070     buttonApply->setEnabled( false );
1071   }
1072   busy = false;
1073   displaySimulation();
1074 }
1075
1076 //=================================================================================
1077 // function : onListSelectionChanged()
1078 // purpose  : Called when selection in element list is changed
1079 //=================================================================================
1080 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1081 {
1082   if (busy || !myActor) return;
1083   busy = true;
1084   bool isSelected=false;
1085   SALOME_ListIO aList;
1086   mySelectionMgr->setSelectedObjects( aList );
1087   TColStd_MapOfInteger aIndexes;
1088   QListBoxItem* anItem;
1089   for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
1090     if (anItem->isSelected()) {
1091       isSelected = true;
1092       QStringList anIds = QStringList::split(" ", anItem->text());
1093       for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1094         aIndexes.Add((*it).toInt());
1095     }
1096   }
1097   if(isSelected) RemoveButton->setEnabled(true);
1098   else RemoveButton->setEnabled(false);
1099   mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1100   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1101     aViewWindow->highlight( myActor->getIO(), true, true );
1102   mySelectionMgr->clearFilters(); 
1103   aList.Append( myActor->getIO() );
1104   mySelectionMgr->setSelectedObjects( aList );
1105   
1106   busy = false;
1107 }
1108
1109 //=================================================================================
1110 // function : keyPressEvent()
1111 // purpose  :
1112 //=================================================================================
1113 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1114 {
1115   QDialog::keyPressEvent( e );
1116   if ( e->isAccepted() )
1117     return;
1118
1119   if ( e->key() == Key_F1 )
1120     {
1121       e->accept();
1122       ClickOnHelp();
1123     }
1124 }