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 "VTKViewer_ViewWindow.h"
44 #include "SUIT_ResourceMgr.h"
46 #include "SalomeApp_Application.h"
47 #include "SalomeApp_Study.h"
48 #include "SUIT_Desktop.h"
49 #include "SUIT_MessageBox.h"
50 #include "SalomeApp_SelectionMgr.h"
51 #include "utilities.h"
53 #include "SVTK_ViewWindow.h"
54 #include "SVTK_Selector.h"
56 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
57 #include <TColStd_ListOfInteger.hxx>
58 #include <TColStd_ListIteratorOfListOfInteger.hxx>
61 #include <vtkIdList.h>
62 #include <vtkIntArray.h>
63 #include <vtkCellArray.h>
64 #include <vtkUnsignedCharArray.h>
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkDataSetMapper.h>
69 #include <qapplication.h>
70 #include <qbuttongroup.h>
71 #include <qgroupbox.h>
73 #include <qlineedit.h>
74 #include <qpushbutton.h>
75 #include <qradiobutton.h>
76 #include <qcheckbox.h>
83 #include "SALOMEconfig.h"
84 #include CORBA_SERVER_HEADER(SMESH_Group)
90 class TPolySimulation{
91 SVTK_ViewWindow* myViewWindow;
93 SALOME_Actor *myPreviewActor;
94 vtkDataSetMapper* myMapper;
95 vtkUnstructuredGrid* myGrid;
99 TPolySimulation(SalomeApp_Application* app)
101 SUIT_ViewManager* mgr = app->activeViewManager();
102 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
104 myGrid = vtkUnstructuredGrid::New();
106 // Create and display actor
107 myMapper = vtkDataSetMapper::New();
108 myMapper->SetInput( myGrid );
110 myPreviewActor = SALOME_Actor::New();
111 myPreviewActor->PickableOff();
112 myPreviewActor->VisibilityOff();
113 myPreviewActor->SetMapper( myMapper );
115 vtkProperty* aProp = vtkProperty::New();
117 anRGB[0] = GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
118 anRGB[1] = GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
119 anRGB[2] = GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
120 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
121 myPreviewActor->SetProperty( aProp );
124 vtkProperty* aBackProp = vtkProperty::New();
125 anRGB[0] = GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
126 anRGB[1] = GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
127 anRGB[2] = GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
128 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
129 myPreviewActor->SetBackfaceProperty( aBackProp );
132 myViewWindow->AddActor( myPreviewActor );
137 typedef std::vector<vtkIdType> TVTKIds;
138 void SetPosition(SMESH_Actor* theActor,
140 const TVTKIds& theIds,
143 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
144 myGrid->SetPoints(aGrid->GetPoints());
146 if (theReset) ResetGrid(theReset);
148 vtkIdList *anIds = vtkIdList::New();
150 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
151 anIds->InsertId(i,theIds[i]);
153 myGrid->InsertNextCell(theType,anIds);
154 if(theIds.size()!=0){
155 myGrid->InsertNextCell(theType,anIds);
165 void ResetGrid(bool theReset=true){
166 if (theReset) myGrid->Reset();
169 void SetVisibility(bool theVisibility){
170 myPreviewActor->SetVisibility(theVisibility);
171 RepaintCurrentView();
177 myViewWindow->RemoveActor(myPreviewActor);
179 myPreviewActor->Delete();
181 myMapper->RemoveAllInputs();
190 //=================================================================================
191 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
193 //=================================================================================
194 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule, const char* name,
195 bool modal, WFlags fl )
196 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
197 mySMESHGUI( theModule ),
198 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
199 myViewWindow( SMESH::GetViewWindow( theModule ) ),
200 mySelector( myViewWindow->GetSelector() )
202 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
205 setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
207 setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
208 setSizeGripEnabled( TRUE );
209 SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this );
210 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
211 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
213 /***************************************************************/
214 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
215 GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
216 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
217 GroupConstructors->setExclusive( TRUE );
218 GroupConstructors->setColumnLayout(0, Qt::Vertical );
219 GroupConstructors->layout()->setSpacing( 0 );
220 GroupConstructors->layout()->setMargin( 0 );
221 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
222 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
223 GroupConstructorsLayout->setSpacing( 6 );
224 GroupConstructorsLayout->setMargin( 11 );
225 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
226 RadioButton1->setText( tr( "MESH_NODE" ) );
227 GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
228 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
229 RadioButton2->setText( tr( "SMESH_FACE" ) );
230 GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
231 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
233 /***************************************************************/
234 GroupButtons = new QGroupBox( this, "GroupButtons" );
235 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
236 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
237 GroupButtons->setTitle( tr( "" ) );
238 GroupButtons->setColumnLayout(0, Qt::Vertical );
239 GroupButtons->layout()->setSpacing( 0 );
240 GroupButtons->layout()->setMargin( 0 );
241 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
242 GroupButtonsLayout->setAlignment( Qt::AlignTop );
243 GroupButtonsLayout->setSpacing( 6 );
244 GroupButtonsLayout->setMargin( 11 );
245 buttonCancel = new QPushButton( GroupButtons, "cancel" );
246 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
247 buttonCancel->setAutoDefault( TRUE );
248 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
249 buttonApply = new QPushButton( GroupButtons, "apply" );
250 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
251 buttonApply->setAutoDefault( TRUE );
252 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
253 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
254 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
255 buttonOk = new QPushButton( GroupButtons, "ok" );
256 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
257 buttonOk->setAutoDefault( TRUE );
258 buttonOk->setDefault( TRUE );
259 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
260 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
262 /***************************************************************/
263 GroupContent = new QGroupBox( this, "GroupContent" );
264 GroupContent->setTitle( tr( "SMESH_CONTENT" ) );
265 GroupContent->setColumnLayout(0, Qt::Vertical );
266 GroupContent->layout()->setSpacing( 0 );
267 GroupContent->layout()->setMargin( 0 );
268 GroupContentLayout = new QGridLayout( GroupContent->layout() );
269 GroupContentLayout->setAlignment( Qt::AlignTop );
270 GroupContentLayout->setSpacing( 6 );
271 GroupContentLayout->setMargin( 11 );
273 QFrame* anIds = new QFrame(GroupContent, "anIds");
274 QGridLayout* aLayout = new QGridLayout(anIds, 1, 3);
275 aLayout->setSpacing(6);
276 aLayout->setAutoAdd(false);
278 TextLabelIds = new QLabel( anIds, "TextLabelIds" );
279 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
280 TextLabelIds->setFixedWidth(74);
281 aLayout->addWidget( TextLabelIds, 0, 0 );
283 SelectElementsButton = new QPushButton( anIds, "SelectElementsButton" );
284 SelectElementsButton->setText( tr( "" ) );
285 SelectElementsButton->setPixmap( image0 );
286 SelectElementsButton->setToggleButton( FALSE );
287 aLayout->addWidget( SelectElementsButton, 0, 1 );
289 LineEditElements = new QLineEdit( anIds, "LineEditElements" );
290 LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
291 aLayout->addWidget( LineEditElements, 0, 2 );
293 GroupContentLayout->addMultiCellWidget(anIds, 0, 0, 0, 1);
295 myFacesByNodesLabel = new QLabel(GroupContent, "faces by nodes label");
296 myFacesByNodesLabel->setText(tr("FACES_BY_NODES"));
297 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
299 myFacesByNodes = new QListBox(GroupContent, "faces by nodes list");
300 myFacesByNodes->setSelectionMode(QListBox::Extended);
301 myFacesByNodes->setMinimumHeight(150);
302 GroupContentLayout->addMultiCellWidget( myFacesByNodes, 2, 4, 0, 0 );
304 AddButton = new QPushButton(GroupContent, "add");
305 AddButton->setText(tr("SMESH_BUT_ADD"));
306 AddButton->setMaximumWidth(85);
307 GroupContentLayout->addWidget( AddButton, 2, 1 );
309 RemoveButton = new QPushButton(GroupContent, "remove");
310 RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
311 RemoveButton->setMaximumWidth(85);
312 GroupContentLayout->addWidget( RemoveButton, 3, 1 );
314 Preview = new QCheckBox( GroupContent, "Preview" );
315 Preview->setText( tr( "SMESH_POLYEDRE_PREVIEW" ) );
316 GroupContentLayout->addWidget( Preview , 5, 0 );
318 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
320 GroupContent->show();
321 RadioButton1->setChecked( TRUE );
323 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
328 //=================================================================================
329 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
330 // purpose : Destroys the object and frees any allocated resources
331 //=================================================================================
332 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
334 // no need to delete child widgets, Qt does it all for us
338 static bool busy = false;
339 //=================================================================================
342 //=================================================================================
343 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
345 myEditCurrentArgument = LineEditElements;
346 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
351 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
353 /* signals and slots connections */
354 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
355 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
356 connect(buttonApply, SIGNAL( clicked() ), SLOT(ClickOnApply() ) );
358 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
359 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
360 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
362 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
363 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
364 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
366 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
367 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
368 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
369 /* to close dialog if study change */
370 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
372 /* Move widget on the botton right corner of main widget */
374 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
376 this->show() ; /* displays Dialog */
378 ConstructorsClicked(0);
379 SelectionIntoArgument();
383 //=================================================================================
384 // function : ConstructorsClicked()
385 // purpose : Radio button management
386 //=================================================================================
387 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
389 //disconnect(mySelectionMgr, 0, this, 0);
392 mySelectionMgr->setSelectedObjects( aList );
393 myEditCurrentArgument->clear();
395 buttonApply->setEnabled(false);
396 buttonOk->setEnabled(false);
397 mySimulation->SetVisibility(false);
399 switch(constructorId)
404 myActor->SetPointRepresentation(true);
405 myActor->SetEntityMode(SMESH_Actor::eVolumes);
406 myActor->SetRepresentation(SMESH_Actor::eSurface);
409 SMESH::SetPointRepresentation(true);
410 myViewWindow->SetSelectionMode(NodeSelection);
412 AddButton->setEnabled(false);
413 RemoveButton->setEnabled(false);
414 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
415 myFacesByNodesLabel->show();
416 myFacesByNodes->clear();
417 myFacesByNodes->show();
419 RemoveButton->show();
426 myActor->SetPointRepresentation(false);
427 myActor->SetEntityMode(SMESH_Actor::eFaces);
428 myActor->SetEntityMode(SMESH_Actor::eVolumes);
429 myActor->SetRepresentation(SMESH_Actor::eSurface);
431 SMESH::SetPointRepresentation(false);
433 myViewWindow->SetSelectionMode(FaceSelection);
435 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
436 myFacesByNodesLabel->hide();
437 myFacesByNodes->hide();
439 RemoveButton->hide();
445 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
448 //=================================================================================
449 // function : ClickOnPreview()
451 //=================================================================================
452 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
453 Preview->setChecked(theToggled);
457 //=================================================================================
458 // function : ClickOnApply()
460 //=================================================================================
461 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
463 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
466 if (GetConstructorId() == 0)
468 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
469 SMESH::long_array_var aQuantities = new SMESH::long_array;
471 aQuantities->length( myFacesByNodes->count() );
473 TColStd_ListOfInteger aNodesIds;
475 QListBoxItem* anItem;
476 int aNbQuantities = 0;
477 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
478 QStringList anIds = QStringList::split(" ", anItem->text());
479 int aNbNodesInFace = 0;
480 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
481 aNodesIds.Append( (*it).toInt() );
483 aQuantities[aNbQuantities++] = aNbNodesInFace;
486 anIdsOfNodes->length(aNodesIds.Extent());
488 int aNbIdsOfNodes = 0;
489 TColStd_ListIteratorOfListOfInteger It;
490 It.Initialize(aNodesIds);
491 for(;It.More();It.Next())
492 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
495 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
496 QApplication::setOverrideCursor(Qt::waitCursor);
497 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
498 QApplication::restoreOverrideCursor();
499 }catch(SALOME::SALOME_Exception& exc){
500 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
501 }catch(std::exception& exc){
502 INFOS("Follow exception was cought:\n\t"<<exc.what());
504 INFOS("Unknown exception was cought !!!");
507 else if (GetConstructorId() == 1)
509 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
511 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
512 anIdsOfFaces->length(aListId.count());
513 for ( int i = 0; i < aListId.count(); i++ )
514 anIdsOfFaces[i] = aListId[i].toInt();
517 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
518 QApplication::setOverrideCursor(Qt::waitCursor);
519 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
520 QApplication::restoreOverrideCursor();
521 }catch(SALOME::SALOME_Exception& exc){
522 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
523 }catch(std::exception& exc){
524 INFOS("Follow exception was cought:\n\t"<<exc.what());
526 INFOS("Unknown exception was cought !!!");
531 mySelectionMgr->setSelectedObjects( aList );
532 mySimulation->SetVisibility(false);
534 ConstructorsClicked( GetConstructorId() );
539 //=================================================================================
540 // function : ClickOnOk()
542 //=================================================================================
543 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
550 //=================================================================================
551 // function : ClickOnCancel()
553 //=================================================================================
554 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
556 mySelectionMgr->clearFilters();
558 mySelectionMgr->setSelectedObjects( aList );
559 SMESH::SetPointRepresentation(false);
560 mySimulation->SetVisibility(false);
561 myViewWindow->SetSelectionMode( ActorSelection );
562 disconnect( mySelectionMgr, 0, this, 0 );
563 mySMESHGUI->ResetState() ;
567 //=======================================================================
568 //function : onTextChange
570 //=======================================================================
572 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
577 mySimulation->SetVisibility(false);
579 SMDS_Mesh* aMesh = 0;
581 aMesh = myActor->GetObject()->GetMesh();
583 if (GetConstructorId() == 0)
586 TColStd_MapOfInteger newIndices;
588 QStringList aListId = QStringList::split( " ", theNewText, false);
589 for ( int i = 0; i < aListId.count(); i++ ) {
590 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
592 newIndices.Add(n->GetID());
597 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
598 myViewWindow->highlight( myActor->getIO(), true, true );
600 if ( myNbOkElements>0 && aListId.count()>=3)
601 AddButton->setEnabled(true);
603 AddButton->setEnabled(false);
607 } else if (GetConstructorId() == 1)
610 buttonOk->setEnabled( false );
611 buttonApply->setEnabled( false );
613 // check entered ids of faces and hilight them
616 TColStd_MapOfInteger newIndices;
618 aListId = QStringList::split( " ", theNewText, false);
620 for ( int i = 0; i < aListId.count(); i++ ) {
621 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
623 newIndices.Add(e->GetID());
628 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
629 myViewWindow->highlight( myActor->getIO(), true, true );
631 if ( myNbOkElements ) {
632 if (aListId.count()>1){
633 buttonOk->setEnabled( true );
634 buttonApply->setEnabled( true );
637 buttonOk->setEnabled( false );
638 buttonApply->setEnabled( false );
647 //=================================================================================
648 // function : SelectionIntoArgument()
649 // purpose : Called when selection as changed or other case
650 //=================================================================================
651 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
657 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
660 AddButton->setEnabled(false);
661 buttonOk->setEnabled( false );
662 buttonApply->setEnabled( false );
668 myEditCurrentArgument->setText( "" );
670 if ( !GroupButtons->isEnabled() ) // inactive
673 mySimulation->SetVisibility(false);
677 SALOME_ListIO selected;
678 mySelectionMgr->selectedObjects( selected );
679 int nbSel = selected.Extent();
684 myMesh = SMESH::GetMeshByIO( selected.First() );
685 if ( myMesh->_is_nil() )
688 myActor = SMESH::FindActorByObject(myMesh);
692 // get selected nodes/faces
693 QString aString = "";
694 switch(GetConstructorId()){
696 int anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
698 AddButton->setEnabled(true);
699 else if (anbNodes < 3){
700 AddButton->setEnabled(false);
703 myEditCurrentArgument->setText( aString );
708 // get selected faces
709 int aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
711 buttonOk->setEnabled( false );
712 buttonApply->setEnabled( false );
714 buttonOk->setEnabled( true );
715 buttonApply->setEnabled( true );
718 myEditCurrentArgument->setText( aString );
731 //=======================================================================
732 //function : displaySimulation
734 //=======================================================================
735 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
737 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
739 SMESH::TPolySimulation::TVTKIds aVTKIds;
740 vtkIdType aType = VTK_CONVEX_POINT_SET ;
741 if (GetConstructorId() == 0){
742 if(!Preview->isChecked()) myActor->SetEntityMode(SMESH_Actor::eFaces);
743 else myActor->SetEntityMode(SMESH_Actor::eVolumes);
744 if (!AddButton->isEnabled()){
745 QListBoxItem* anItem;
746 mySimulation->ResetGrid(true);
747 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
748 QStringList anIds = QStringList::split(" ", anItem->text());
749 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
750 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
751 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
752 aVTKIds.push_back(aId);
753 aVTKIds_faces.push_back(aId);
755 if(!Preview->isChecked()){
757 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
760 if(myFacesByNodes->count() == 0){
761 mySimulation->SetVisibility(false);
763 mySimulation->SetVisibility(true);
765 if(Preview->isChecked()){
766 mySimulation->SetPosition(myActor, aType, aVTKIds);
769 // add ids from edit line
770 QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
771 myActor->SetEntityMode(SMESH_Actor::eFaces);
772 for ( int i = 0; i < anEditIds.count(); i++ )
773 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
775 mySimulation->SetPosition(myActor, aType, aVTKIds);
777 }else if(GetConstructorId() == 1){
778 SMDS_Mesh* aMesh = 0;
780 aMesh = myActor->GetObject()->GetMesh();
781 if (Preview->isChecked())
782 myActor->SetEntityMode(SMESH_Actor::eVolumes);
784 myActor->SetEntityMode(SMESH_Actor::eFaces);
787 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
788 for ( int i = 0; i < aListId.count(); i++ )
790 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
794 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
795 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
796 while( anIter->more() )
797 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
798 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
799 aVTKIds.push_back(aId);
800 aVTKIds_faces.push_back(aId);
802 if(!Preview->isChecked()){
804 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
807 if(Preview->isChecked())
808 mySimulation->SetPosition(myActor, aType, aVTKIds);
815 //=================================================================================
816 // function : SetEditCurrentArgument()
818 //=================================================================================
819 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
821 QPushButton* send = (QPushButton*)sender();
822 if(send == SelectElementsButton) {
823 LineEditElements->setFocus() ;
824 myEditCurrentArgument = LineEditElements;
826 SelectionIntoArgument();
829 //=================================================================================
830 // function : DeactivateActiveDialog()
832 //=================================================================================
833 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
835 if ( GroupConstructors->isEnabled() ) {
836 GroupConstructors->setEnabled(false) ;
837 GroupContent->setEnabled(false) ;
838 GroupButtons->setEnabled(false) ;
839 mySimulation->SetVisibility(false);
840 mySMESHGUI->ResetState() ;
841 mySMESHGUI->SetActiveDialogBox(0) ;
846 //=================================================================================
847 // function : ActivateThisDialog()
849 //=================================================================================
850 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
852 /* Emit a signal to deactivate the active dialog */
853 mySMESHGUI->EmitSignalDeactivateDialog() ;
854 GroupConstructors->setEnabled(true) ;
855 GroupContent->setEnabled(true) ;
856 GroupButtons->setEnabled(true) ;
858 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
860 myViewWindow->SetSelectionMode( FaceSelection );
861 SelectionIntoArgument();
865 //=================================================================================
866 // function : enterEvent()
868 //=================================================================================
869 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
871 if ( GroupConstructors->isEnabled() )
873 ActivateThisDialog() ;
877 //=================================================================================
878 // function : closeEvent()
880 //=================================================================================
881 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
883 /* same than click on cancel button */
884 this->ClickOnCancel() ;
888 //=======================================================================
889 //function : hideEvent
890 //purpose : caused by ESC key
891 //=======================================================================
893 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
895 if ( !isMinimized() )
900 //=================================================================================
901 // function : GetConstructorId()
903 //=================================================================================
904 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
906 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
907 return GroupConstructors->id( GroupConstructors->selected() );
911 //=================================================================================
912 // function : onAdd()
914 //=================================================================================
915 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
917 SALOME_ListIO selected;
918 mySelectionMgr->selectedObjects( selected );
919 int aNbSel = selected.Extent();
920 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
924 if ( !(myEditCurrentArgument->text().isEmpty()) )
926 myFacesByNodes->insertItem(myEditCurrentArgument->text());
927 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
929 myEditCurrentArgument->clear();
930 AddButton->setEnabled(false);
931 buttonOk->setEnabled( true );
932 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
935 onListSelectionChanged();
939 //=================================================================================
940 // function : onRemove()
942 //=================================================================================
943 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
946 for (int i = myFacesByNodes->count(); i > 0; i--) {
947 if (myFacesByNodes->isSelected(i-1)) {
948 myFacesByNodes->removeItem(i-1);
952 if (myFacesByNodes->count() < 1){
953 RemoveButton->setEnabled(false);
954 buttonOk->setEnabled( false );
955 buttonApply->setEnabled( false );
957 else if (myFacesByNodes->count() == 1){
958 buttonOk->setEnabled( false );
959 buttonApply->setEnabled( false );
965 //=================================================================================
966 // function : onListSelectionChanged()
967 // purpose : Called when selection in element list is changed
968 //=================================================================================
969 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
971 if (busy || !myActor) return;
973 bool isSelected=false;
975 mySelectionMgr->setSelectedObjects( aList );
976 TColStd_MapOfInteger aIndexes;
977 QListBoxItem* anItem;
978 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
979 if (anItem->isSelected()) {
981 QStringList anIds = QStringList::split(" ", anItem->text());
982 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
983 aIndexes.Add((*it).toInt());
986 if(isSelected) RemoveButton->setEnabled(true);
987 else RemoveButton->setEnabled(false);
988 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
989 myViewWindow->highlight( myActor->getIO(), true, true );
990 mySelectionMgr->clearFilters();
991 aList.Append( myActor->getIO() );
992 mySelectionMgr->setSelectedObjects( aList );