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