Salome HOME
PAL13460 (force the mesh to go through a point)
[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 = "/files/adding_nodes_and_elements.htm#Adding_polyhedrons";
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     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
586                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
587                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
588                            QObject::tr("BUT_OK"));
589   }
590 }
591
592 //=======================================================================
593 //function : onTextChange
594 //purpose  : 
595 //=======================================================================
596
597 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
598 {
599   if ( busy ) return;
600   if (checkEditLine() == -1) return;
601   busy = true;
602
603   mySimulation->SetVisibility(false);
604
605   SMDS_Mesh* aMesh = 0;
606   if ( myActor )
607     aMesh = myActor->GetObject()->GetMesh();
608
609   if (GetConstructorId() == 0)
610   {
611     if ( aMesh ) {
612       TColStd_MapOfInteger newIndices;
613       
614       QStringList aListId = QStringList::split( " ", theNewText, false);
615       for ( int i = 0; i < aListId.count(); i++ ) {
616         const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
617         if ( n ) {
618           newIndices.Add(n->GetID());
619           myNbOkElements++;
620         }
621       }
622       
623       mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
624       
625       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
626         aViewWindow->highlight( myActor->getIO(), true, true );
627       
628       if ( myNbOkElements>0 && aListId.count()>=3)
629         AddButton->setEnabled(true);
630       else
631         AddButton->setEnabled(false);
632       
633       displaySimulation();
634     }
635   } else if (GetConstructorId() == 1)
636   {
637     myNbOkElements = 0;
638     buttonOk->setEnabled( false );
639     buttonApply->setEnabled( false );
640       
641       // check entered ids of faces and hilight them
642     QStringList aListId;
643     if ( aMesh ) {
644       TColStd_MapOfInteger newIndices;
645       
646       aListId = QStringList::split( " ", theNewText, false);
647
648       for ( int i = 0; i < aListId.count(); i++ ) {
649         const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
650         if ( e ) {
651           newIndices.Add(e->GetID());
652           myNbOkElements++;  
653         }
654       }
655
656       mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
657       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
658         aViewWindow->highlight( myActor->getIO(), true, true );
659       
660       if ( myNbOkElements ) {
661         if (aListId.count()>1){ 
662           buttonOk->setEnabled( true );
663           buttonApply->setEnabled( true );
664         }
665         else{
666           buttonOk->setEnabled( false );
667           buttonApply->setEnabled( false );
668         }
669         if(aListId.count()>1)
670           displaySimulation();
671       }
672     }
673   }
674   busy = false;
675 }
676
677 //=================================================================================
678 // function : SelectionIntoArgument()
679 // purpose  : Called when selection as changed or other case
680 //=================================================================================
681 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
682 {
683   if ( busy ) return;
684   
685   // clear
686   
687   if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
688     {
689       myNbOkElements = 0;
690       AddButton->setEnabled(false);
691       buttonOk->setEnabled( false );
692       buttonApply->setEnabled( false );
693     }
694
695   myActor = 0;
696
697   busy = true;
698   myEditCurrentArgument->setText( "" );
699   busy = false;
700   if ( !GroupButtons->isEnabled() ) // inactive
701     return;
702   
703   mySimulation->SetVisibility(false);
704   
705   // get selected mesh
706   
707   SALOME_ListIO selected;
708   mySelectionMgr->selectedObjects( selected );
709   int nbSel = selected.Extent();
710   if(nbSel != 1){
711     return;
712   }
713   
714   myMesh = SMESH::GetMeshByIO( selected.First() );
715   if ( myMesh->_is_nil() )
716     return;
717   
718   myActor = SMESH::FindActorByObject(myMesh);
719   if ( !myActor )
720     return;
721   
722   // get selected nodes/faces
723   QString aString = "";
724   int anbNodes=0,aNbFaces=0;
725   switch(GetConstructorId()){
726   case 0:{
727     anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
728     if (anbNodes >= 3)
729       AddButton->setEnabled(true);
730     else if (anbNodes < 3){
731       AddButton->setEnabled(false);
732     }
733     busy = true;
734     myEditCurrentArgument->setText( aString );
735     if (checkEditLine() == -1) {busy = false;return;}
736     busy = false;
737     break;
738   }
739   case 1:{
740     // get selected faces
741     aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
742     if (aNbFaces<=1){
743       buttonOk->setEnabled( false );
744       buttonApply->setEnabled( false );
745     } else {
746       buttonOk->setEnabled( true );
747       buttonApply->setEnabled( true );
748     }
749     busy = true;
750     myEditCurrentArgument->setText( aString );
751     if (checkEditLine() == -1) {busy = false;return;}
752     busy = false;
753     
754     // OK
755     myNbOkElements = 1;
756     break;
757   }
758   default: return;
759   }
760   if(anbNodes>2 || aNbFaces>1)
761     displaySimulation();
762 }
763
764 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
765  * Checking of indices in edit line.
766  * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
767  * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
768  */
769 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
770 {
771   QString aString = "";
772   SMDS_Mesh* aMesh = 0;
773   
774   if(myMesh->_is_nil()) return 1;
775   if(!myActor){
776     myActor = SMESH::FindActorByObject(myMesh);
777     if(!myActor)
778       return 1;
779   }
780     
781   aMesh = myActor->GetObject()->GetMesh();
782
783   // checking for nodes
784   if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
785   QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
786   for ( int i = 0; i < aListId.count(); i++ ){
787     switch (GetConstructorId()){
788     case 0:{ // nodes
789       const SMDS_MeshNode    * aNode = aMesh->FindNode( aListId[ i ].toInt() );
790       if( !aNode ){
791         std::string aWarning;
792         aWarning = "The incorrect indices of nodes!";
793         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
794                                QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
795                                QObject::tr(aWarning.c_str()),
796                                QObject::tr("SMESH_BUT_OK"));
797         
798         myEditCurrentArgument->clear();
799         myEditCurrentArgument->setText( aString );
800         return -1;
801       }
802
803       break;
804     }
805     case 1:{ // faces
806       bool aElemIsOK = true;
807       const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
808       if (!aElem)
809         {
810           aElemIsOK = false;
811         }
812       else
813         {
814           SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
815           if (aType != SMDSAbs_Face){
816             aElemIsOK = false;
817           }
818         }
819       if (!aElemIsOK){
820         std::string aWarning;
821         aWarning = "The incorrect indices of faces!";
822         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
823                                QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
824                                QObject::tr(aWarning.c_str()),
825                                QObject::tr("SMESH_BUT_OK"));
826         
827         myEditCurrentArgument->clear();
828         myEditCurrentArgument->setText( aString );
829         return -1;
830       }
831       break;
832     }
833     }
834     aString += aListId[ i ] + " "; 
835   }
836
837   return 1;
838 }
839
840 //=======================================================================
841 //function : displaySimulation
842 //purpose  : 
843 //=======================================================================
844 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
845 {
846   if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
847     {
848       SMESH::TPolySimulation::TVTKIds aVTKIds;
849       vtkIdType aType = VTK_CONVEX_POINT_SET ;
850       SMDS_Mesh* aMesh = 0;
851       if ( myActor ){
852         aMesh = myActor->GetObject()->GetMesh();
853       }
854       if (GetConstructorId() == 0 && aMesh){
855         if (!AddButton->isEnabled()){
856           QListBoxItem* anItem;
857           mySimulation->ResetGrid(true);
858           for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
859             QStringList anIds = QStringList::split(" ", anItem->text());
860             SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
861             for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
862               const SMDS_MeshNode    * aNode = aMesh->FindNode( (*it).toInt() );
863               if (!aNode) continue;
864               vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
865               aVTKIds.push_back(aId);
866               aVTKIds_faces.push_back(aId);
867             }
868             if(!Preview->isChecked()){
869               aType = VTK_POLYGON;
870               mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
871             }
872           }
873           if(myFacesByNodes->count() == 0){
874             mySimulation->SetVisibility(false);
875           } else {
876             mySimulation->SetVisibility(true);
877           }
878           if(Preview->isChecked()){
879             mySimulation->SetPosition(myActor, aType, aVTKIds);
880           }
881         } else {
882           // add ids from edit line
883           QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
884           for ( int i = 0; i < anEditIds.count(); i++ )
885             aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
886           aType = VTK_POLYGON;
887           mySimulation->SetPosition(myActor, aType, aVTKIds);
888         }
889       }else if(GetConstructorId() == 1 && aMesh){
890         QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
891         for ( int i = 0; i < aListId.count(); i++ )
892           {
893             const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
894             if ( !anElem ) continue;
895             SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
896             if (aFaceType != SMDSAbs_Face) continue;
897               
898             SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
899             SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
900             while( anIter->more() )
901                 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
902                   vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
903                   aVTKIds.push_back(aId);
904                   aVTKIds_faces.push_back(aId);
905                 }
906             if(!Preview->isChecked()){
907               aType = VTK_POLYGON;
908               mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
909             }
910           }
911         if(Preview->isChecked())
912           mySimulation->SetPosition(myActor, aType, aVTKIds);
913       }
914       SMESH::UpdateView();
915     }
916 }
917
918 //=================================================================================
919 // function : SetEditCurrentArgument()
920 // purpose  :
921 //=================================================================================
922 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
923 {
924   QPushButton* send = (QPushButton*)sender();
925   if(send == SelectElementsButton) {
926     LineEditElements->setFocus() ;
927     myEditCurrentArgument = LineEditElements;
928   }
929   SelectionIntoArgument();
930 }
931
932 //=================================================================================
933 // function : DeactivateActiveDialog()
934 // purpose  :
935 //=================================================================================
936 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
937 {
938   if ( GroupConstructors->isEnabled() ) {
939     GroupConstructors->setEnabled(false) ;
940     GroupContent->setEnabled(false) ;
941     GroupButtons->setEnabled(false) ;
942     mySimulation->SetVisibility(false);
943     mySMESHGUI->ResetState() ;    
944     mySMESHGUI->SetActiveDialogBox(0) ;
945   }
946 }
947
948
949 //=================================================================================
950 // function : ActivateThisDialog()
951 // purpose  :
952 //=================================================================================
953 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
954 {
955   /* Emit a signal to deactivate the active dialog */
956   mySMESHGUI->EmitSignalDeactivateDialog() ;   
957   GroupConstructors->setEnabled(true) ;
958   GroupContent->setEnabled(true) ;
959   GroupButtons->setEnabled(true) ;
960   
961   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
962
963   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
964     aViewWindow->SetSelectionMode( FaceSelection );
965   SelectionIntoArgument();
966 }
967
968
969 //=================================================================================
970 // function : enterEvent()
971 // purpose  :
972 //=================================================================================
973 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
974 {
975   if ( GroupConstructors->isEnabled() )
976     return ;  
977   ActivateThisDialog() ;
978 }
979
980
981 //=================================================================================
982 // function : closeEvent()
983 // purpose  :
984 //=================================================================================
985 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
986 {
987   /* same than click on cancel button */
988   this->ClickOnCancel() ;
989 }
990
991
992 //=======================================================================
993 //function : hideEvent
994 //purpose  : caused by ESC key
995 //=======================================================================
996
997 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
998 {
999   if ( !isMinimized() )
1000     ClickOnCancel();
1001 }
1002
1003
1004 //=================================================================================
1005 // function : GetConstructorId()
1006 // purpose  : 
1007 //=================================================================================
1008 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1009
1010   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
1011     return GroupConstructors->id( GroupConstructors->selected() );
1012   return -1;
1013 }
1014
1015 //=================================================================================
1016 // function : onAdd()
1017 // purpose  :
1018 //=================================================================================
1019 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1020 {
1021   SALOME_ListIO selected;
1022   mySelectionMgr->selectedObjects( selected );
1023   int aNbSel = selected.Extent();
1024   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1025   
1026   if (this->checkEditLine(false) == -1) return;
1027
1028   busy = true;
1029   if ( !(myEditCurrentArgument->text().isEmpty()) )
1030     {
1031       myFacesByNodes->insertItem(myEditCurrentArgument->text());
1032       //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1033       myNbOkElements = 1;
1034       myEditCurrentArgument->clear();
1035       AddButton->setEnabled(false);
1036       buttonOk->setEnabled( true );
1037       if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1038     }
1039   busy = false;
1040   onListSelectionChanged();
1041   displaySimulation();
1042 }
1043
1044 //=================================================================================
1045 // function : onRemove()
1046 // purpose  :
1047 //=================================================================================
1048 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1049 {
1050   busy = true;
1051   for (int i = myFacesByNodes->count(); i > 0; i--) {
1052     if (myFacesByNodes->isSelected(i-1)) {
1053       myFacesByNodes->removeItem(i-1);
1054       myNbOkElements = 1;
1055     }
1056   }
1057   if (myFacesByNodes->count() < 1){
1058     RemoveButton->setEnabled(false);
1059     buttonOk->setEnabled( false );
1060     buttonApply->setEnabled( false );
1061   } 
1062   else if (myFacesByNodes->count() == 1){
1063     buttonOk->setEnabled( false );
1064     buttonApply->setEnabled( false );
1065   }
1066   busy = false;
1067   displaySimulation();
1068 }
1069
1070 //=================================================================================
1071 // function : onListSelectionChanged()
1072 // purpose  : Called when selection in element list is changed
1073 //=================================================================================
1074 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1075 {
1076   if (busy || !myActor) return;
1077   busy = true;
1078   bool isSelected=false;
1079   SALOME_ListIO aList;
1080   mySelectionMgr->setSelectedObjects( aList );
1081   TColStd_MapOfInteger aIndexes;
1082   QListBoxItem* anItem;
1083   for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
1084     if (anItem->isSelected()) {
1085       isSelected = true;
1086       QStringList anIds = QStringList::split(" ", anItem->text());
1087       for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1088         aIndexes.Add((*it).toInt());
1089     }
1090   }
1091   if(isSelected) RemoveButton->setEnabled(true);
1092   else RemoveButton->setEnabled(false);
1093   mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1094   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1095     aViewWindow->highlight( myActor->getIO(), true, true );
1096   mySelectionMgr->clearFilters(); 
1097   aList.Append( myActor->getIO() );
1098   mySelectionMgr->setSelectedObjects( aList );
1099   
1100   busy = false;
1101 }
1102
1103 //=================================================================================
1104 // function : keyPressEvent()
1105 // purpose  :
1106 //=================================================================================
1107 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1108 {
1109   QDialog::keyPressEvent( e );
1110   if ( e->isAccepted() )
1111     return;
1112
1113   if ( e->key() == Key_F1 )
1114     {
1115       e->accept();
1116       ClickOnHelp();
1117     }
1118 }