1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_CreatePolyhedralVolumeDlg.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"
42 #include "SUIT_ResourceMgr.h"
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"
51 #include "SVTK_ViewWindow.h"
52 #include "SVTK_Selector.h"
54 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
55 #include <TColStd_ListOfInteger.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
59 #include <vtkIdList.h>
60 #include <vtkIntArray.h>
61 #include <vtkCellArray.h>
62 #include <vtkUnsignedCharArray.h>
63 #include <vtkUnstructuredGrid.h>
64 #include <vtkDataSetMapper.h>
67 #include <qapplication.h>
68 #include <qbuttongroup.h>
69 #include <qgroupbox.h>
71 #include <qlineedit.h>
72 #include <qpushbutton.h>
73 #include <qradiobutton.h>
74 #include <qcheckbox.h>
81 #include "SALOMEconfig.h"
82 #include CORBA_SERVER_HEADER(SMESH_Group)
88 class TPolySimulation{
89 SVTK_ViewWindow* myViewWindow;
91 SALOME_Actor *myPreviewActor;
92 vtkDataSetMapper* myMapper;
93 vtkUnstructuredGrid* myGrid;
97 TPolySimulation(SalomeApp_Application* app)
99 SUIT_ViewManager* mgr = app->activeViewManager();
100 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
102 myGrid = vtkUnstructuredGrid::New();
104 // Create and display actor
105 myMapper = vtkDataSetMapper::New();
106 myMapper->SetInput( myGrid );
108 myPreviewActor = SALOME_Actor::New();
109 myPreviewActor->PickableOff();
110 myPreviewActor->VisibilityOff();
111 myPreviewActor->SetMapper( myMapper );
112 myPreviewActor->SetRepresentation( 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 );
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 );
127 myViewWindow->AddActor( myPreviewActor );
132 typedef std::vector<vtkIdType> TVTKIds;
133 void SetPosition(SMESH_Actor* theActor,
135 const TVTKIds& theIds,
138 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
139 myGrid->SetPoints(aGrid->GetPoints());
141 if (theReset) ResetGrid(theReset);
143 vtkIdList *anIds = vtkIdList::New();
145 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
146 anIds->InsertId(i,theIds[i]);
148 myGrid->InsertNextCell(theType,anIds);
149 if(theIds.size()!=0){
150 myGrid->InsertNextCell(theType,anIds);
160 void ResetGrid(bool theReset=true){
161 if (theReset) myGrid->Reset();
164 void SetVisibility(bool theVisibility){
165 myPreviewActor->SetVisibility(theVisibility);
166 RepaintCurrentView();
172 myViewWindow->RemoveActor(myPreviewActor);
174 myPreviewActor->Delete();
176 myMapper->RemoveAllInputs();
185 //=================================================================================
186 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
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 ) )
195 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
198 setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
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 );
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 );
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 );
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 );
266 QFrame* anIds = new QFrame(GroupContent, "anIds");
267 QGridLayout* aLayout = new QGridLayout(anIds, 1, 3);
268 aLayout->setSpacing(6);
269 aLayout->setAutoAdd(false);
271 TextLabelIds = new QLabel( anIds, "TextLabelIds" );
272 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
273 TextLabelIds->setFixedWidth(74);
274 aLayout->addWidget( TextLabelIds, 0, 0 );
276 SelectElementsButton = new QPushButton( anIds, "SelectElementsButton" );
277 SelectElementsButton->setText( tr( "" ) );
278 SelectElementsButton->setPixmap( image0 );
279 SelectElementsButton->setToggleButton( FALSE );
280 aLayout->addWidget( SelectElementsButton, 0, 1 );
282 LineEditElements = new QLineEdit( anIds, "LineEditElements" );
283 LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
284 aLayout->addWidget( LineEditElements, 0, 2 );
286 GroupContentLayout->addMultiCellWidget(anIds, 0, 0, 0, 1);
288 myFacesByNodesLabel = new QLabel(GroupContent, "faces by nodes label");
289 myFacesByNodesLabel->setText(tr("FACES_BY_NODES"));
290 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
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 );
297 AddButton = new QPushButton(GroupContent, "add");
298 AddButton->setText(tr("SMESH_BUT_ADD"));
299 AddButton->setMaximumWidth(85);
300 GroupContentLayout->addWidget( AddButton, 2, 1 );
302 RemoveButton = new QPushButton(GroupContent, "remove");
303 RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
304 RemoveButton->setMaximumWidth(85);
305 GroupContentLayout->addWidget( RemoveButton, 3, 1 );
307 Preview = new QCheckBox( GroupContent, "Preview" );
308 Preview->setText( tr( "SMESH_POLYEDRE_PREVIEW" ) );
309 GroupContentLayout->addWidget( Preview , 5, 0 );
311 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
313 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
315 GroupContent->show();
316 RadioButton1->setChecked( TRUE );
318 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
323 //=================================================================================
324 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
325 // purpose : Destroys the object and frees any allocated resources
326 //=================================================================================
327 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
329 // no need to delete child widgets, Qt does it all for us
333 static bool busy = false;
334 //=================================================================================
337 //=================================================================================
338 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
340 myEditCurrentArgument = LineEditElements;
341 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
346 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
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() ) );
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&)));
357 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
358 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
359 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
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() ) ) ;
367 /* Move widget on the botton right corner of main widget */
369 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
371 this->show() ; /* displays Dialog */
373 ConstructorsClicked(0);
374 SelectionIntoArgument();
378 //=================================================================================
379 // function : ConstructorsClicked()
380 // purpose : Radio button management
381 //=================================================================================
382 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
384 //disconnect(mySelectionMgr, 0, this, 0);
387 mySelectionMgr->selectedObjects( io );
389 mySelectionMgr->setSelectedObjects( aList );
390 myEditCurrentArgument->clear();
392 buttonApply->setEnabled(false);
393 buttonOk->setEnabled(false);
394 mySimulation->SetVisibility(false);
396 switch(constructorId)
401 myActor->SetPointRepresentation(true);
404 SMESH::SetPointRepresentation(true);
405 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
406 aViewWindow->SetSelectionMode(NodeSelection);
408 AddButton->setEnabled(false);
409 RemoveButton->setEnabled(false);
410 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
411 myFacesByNodesLabel->show();
412 myFacesByNodes->clear();
413 myFacesByNodes->show();
415 RemoveButton->show();
422 myActor->SetPointRepresentation(false);
424 SMESH::SetPointRepresentation(false);
426 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
427 aViewWindow->SetSelectionMode(FaceSelection);
429 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
430 myFacesByNodesLabel->hide();
431 myFacesByNodes->hide();
433 RemoveButton->hide();
439 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
440 mySelectionMgr->setSelectedObjects( io );
443 //=================================================================================
444 // function : ClickOnPreview()
446 //=================================================================================
447 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
448 Preview->setChecked(theToggled);
452 //=================================================================================
453 // function : ClickOnApply()
455 //=================================================================================
456 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
458 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
461 if (GetConstructorId() == 0)
463 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
464 SMESH::long_array_var aQuantities = new SMESH::long_array;
466 aQuantities->length( myFacesByNodes->count() );
468 TColStd_ListOfInteger aNodesIds;
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() );
478 aQuantities[aNbQuantities++] = aNbNodesInFace;
481 anIdsOfNodes->length(aNodesIds.Extent());
483 int aNbIdsOfNodes = 0;
484 TColStd_ListIteratorOfListOfInteger It;
485 It.Initialize(aNodesIds);
486 for(;It.More();It.Next())
487 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
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());
499 INFOS("Unknown exception was cought !!!");
502 else if (GetConstructorId() == 1)
504 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
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();
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());
521 INFOS("Unknown exception was cought !!!");
525 //SALOME_ListIO aList;
526 //mySelectionMgr->setSelectedObjects( aList );
529 unsigned int anEntityMode = myActor->GetEntityMode();
530 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
532 ConstructorsClicked( GetConstructorId() );
537 //=================================================================================
538 // function : ClickOnOk()
540 //=================================================================================
541 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
548 //=================================================================================
549 // function : ClickOnCancel()
551 //=================================================================================
552 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
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() ;
566 //=======================================================================
567 //function : onTextChange
569 //=======================================================================
571 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
576 mySimulation->SetVisibility(false);
578 SMDS_Mesh* aMesh = 0;
580 aMesh = myActor->GetObject()->GetMesh();
582 if (GetConstructorId() == 0)
585 TColStd_MapOfInteger newIndices;
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() );
591 newIndices.Add(n->GetID());
596 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
598 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
599 aViewWindow->highlight( myActor->getIO(), true, true );
601 if ( myNbOkElements>0 && aListId.count()>=3)
602 AddButton->setEnabled(true);
604 AddButton->setEnabled(false);
608 } else if (GetConstructorId() == 1)
611 buttonOk->setEnabled( false );
612 buttonApply->setEnabled( false );
614 // check entered ids of faces and hilight them
617 TColStd_MapOfInteger newIndices;
619 aListId = QStringList::split( " ", theNewText, false);
621 for ( int i = 0; i < aListId.count(); i++ ) {
622 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
624 newIndices.Add(e->GetID());
629 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
630 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
631 aViewWindow->highlight( myActor->getIO(), true, true );
633 if ( myNbOkElements ) {
634 if (aListId.count()>1){
635 buttonOk->setEnabled( true );
636 buttonApply->setEnabled( true );
639 buttonOk->setEnabled( false );
640 buttonApply->setEnabled( false );
642 if(aListId.count()>1)
650 //=================================================================================
651 // function : SelectionIntoArgument()
652 // purpose : Called when selection as changed or other case
653 //=================================================================================
654 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
660 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
663 AddButton->setEnabled(false);
664 buttonOk->setEnabled( false );
665 buttonApply->setEnabled( false );
671 myEditCurrentArgument->setText( "" );
673 if ( !GroupButtons->isEnabled() ) // inactive
676 mySimulation->SetVisibility(false);
680 SALOME_ListIO selected;
681 mySelectionMgr->selectedObjects( selected );
682 int nbSel = selected.Extent();
687 myMesh = SMESH::GetMeshByIO( selected.First() );
688 if ( myMesh->_is_nil() )
691 myActor = SMESH::FindActorByObject(myMesh);
695 // get selected nodes/faces
696 QString aString = "";
697 int anbNodes=0,aNbFaces=0;
698 switch(GetConstructorId()){
700 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
702 AddButton->setEnabled(true);
703 else if (anbNodes < 3){
704 AddButton->setEnabled(false);
707 myEditCurrentArgument->setText( aString );
712 // get selected faces
713 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
715 buttonOk->setEnabled( false );
716 buttonApply->setEnabled( false );
718 buttonOk->setEnabled( true );
719 buttonApply->setEnabled( true );
722 myEditCurrentArgument->setText( aString );
731 if(anbNodes>2 || aNbFaces>1)
735 //=======================================================================
736 //function : displaySimulation
738 //=======================================================================
739 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
741 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
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);
757 if(!Preview->isChecked()){
759 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
762 if(myFacesByNodes->count() == 0){
763 mySimulation->SetVisibility(false);
765 mySimulation->SetVisibility(true);
767 if(Preview->isChecked()){
768 mySimulation->SetPosition(myActor, aType, aVTKIds);
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() ));
776 mySimulation->SetPosition(myActor, aType, aVTKIds);
778 }else if(GetConstructorId() == 1){
779 SMDS_Mesh* aMesh = 0;
781 aMesh = myActor->GetObject()->GetMesh();
784 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
785 for ( int i = 0; i < aListId.count(); i++ )
787 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
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);
799 if(!Preview->isChecked()){
801 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
804 if(Preview->isChecked())
805 mySimulation->SetPosition(myActor, aType, aVTKIds);
812 //=================================================================================
813 // function : SetEditCurrentArgument()
815 //=================================================================================
816 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
818 QPushButton* send = (QPushButton*)sender();
819 if(send == SelectElementsButton) {
820 LineEditElements->setFocus() ;
821 myEditCurrentArgument = LineEditElements;
823 SelectionIntoArgument();
826 //=================================================================================
827 // function : DeactivateActiveDialog()
829 //=================================================================================
830 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
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) ;
843 //=================================================================================
844 // function : ActivateThisDialog()
846 //=================================================================================
847 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
849 /* Emit a signal to deactivate the active dialog */
850 mySMESHGUI->EmitSignalDeactivateDialog() ;
851 GroupConstructors->setEnabled(true) ;
852 GroupContent->setEnabled(true) ;
853 GroupButtons->setEnabled(true) ;
855 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
857 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
858 aViewWindow->SetSelectionMode( FaceSelection );
859 SelectionIntoArgument();
863 //=================================================================================
864 // function : enterEvent()
866 //=================================================================================
867 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
869 if ( GroupConstructors->isEnabled() )
871 ActivateThisDialog() ;
875 //=================================================================================
876 // function : closeEvent()
878 //=================================================================================
879 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
881 /* same than click on cancel button */
882 this->ClickOnCancel() ;
886 //=======================================================================
887 //function : hideEvent
888 //purpose : caused by ESC key
889 //=======================================================================
891 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
893 if ( !isMinimized() )
898 //=================================================================================
899 // function : GetConstructorId()
901 //=================================================================================
902 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
904 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
905 return GroupConstructors->id( GroupConstructors->selected() );
909 //=================================================================================
910 // function : onAdd()
912 //=================================================================================
913 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
915 SALOME_ListIO selected;
916 mySelectionMgr->selectedObjects( selected );
917 int aNbSel = selected.Extent();
918 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
922 if ( !(myEditCurrentArgument->text().isEmpty()) )
924 myFacesByNodes->insertItem(myEditCurrentArgument->text());
925 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
927 myEditCurrentArgument->clear();
928 AddButton->setEnabled(false);
929 buttonOk->setEnabled( true );
930 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
933 onListSelectionChanged();
937 //=================================================================================
938 // function : onRemove()
940 //=================================================================================
941 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
944 for (int i = myFacesByNodes->count(); i > 0; i--) {
945 if (myFacesByNodes->isSelected(i-1)) {
946 myFacesByNodes->removeItem(i-1);
950 if (myFacesByNodes->count() < 1){
951 RemoveButton->setEnabled(false);
952 buttonOk->setEnabled( false );
953 buttonApply->setEnabled( false );
955 else if (myFacesByNodes->count() == 1){
956 buttonOk->setEnabled( false );
957 buttonApply->setEnabled( false );
963 //=================================================================================
964 // function : onListSelectionChanged()
965 // purpose : Called when selection in element list is changed
966 //=================================================================================
967 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
969 if (busy || !myActor) return;
971 bool isSelected=false;
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()) {
979 QStringList anIds = QStringList::split(" ", anItem->text());
980 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
981 aIndexes.Add((*it).toInt());
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 );