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"
43 #include "SUIT_Session.h"
44 #include "SUIT_MessageBox.h"
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"
54 #include "SVTK_ViewWindow.h"
55 #include "SVTK_Selector.h"
57 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
58 #include <TColStd_ListOfInteger.hxx>
59 #include <TColStd_ListIteratorOfListOfInteger.hxx>
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>
71 #include <qapplication.h>
72 #include <qbuttongroup.h>
73 #include <qgroupbox.h>
75 #include <qlineedit.h>
76 #include <qpushbutton.h>
77 #include <qradiobutton.h>
78 #include <qcheckbox.h>
85 #include "SALOMEconfig.h"
86 #include CORBA_SERVER_HEADER(SMESH_Group)
92 class TPolySimulation{
93 SVTK_ViewWindow* myViewWindow;
95 SALOME_Actor *myPreviewActor;
96 vtkDataSetMapper* myMapper;
97 vtkUnstructuredGrid* myGrid;
101 TPolySimulation(SalomeApp_Application* app)
103 SUIT_ViewManager* mgr = app->activeViewManager();
104 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
106 myGrid = vtkUnstructuredGrid::New();
108 // Create and display actor
109 myMapper = vtkDataSetMapper::New();
110 myMapper->SetInput( myGrid );
112 myPreviewActor = SALOME_Actor::New();
113 myPreviewActor->PickableOff();
114 myPreviewActor->VisibilityOff();
115 myPreviewActor->SetMapper( myMapper );
116 myPreviewActor->SetRepresentation( 3 );
118 vtkFloatingPointType anRGB[3];
119 vtkProperty* aProp = vtkProperty::New();
120 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
121 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
122 myPreviewActor->SetProperty( aProp );
123 vtkFloatingPointType aFactor,aUnits;
124 myPreviewActor->SetResolveCoincidentTopology(true);
125 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
126 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
129 myViewWindow->AddActor( myPreviewActor );
134 typedef std::vector<vtkIdType> TVTKIds;
135 void SetPosition(SMESH_Actor* theActor,
137 const TVTKIds& theIds,
140 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
141 myGrid->SetPoints(aGrid->GetPoints());
145 vtkIdList *anIds = vtkIdList::New();
147 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
148 anIds->InsertId(i,theIds[i]);
150 myGrid->InsertNextCell(theType,anIds);
151 if(theIds.size()!=0){
152 myGrid->InsertNextCell(theType,anIds);
162 void ResetGrid(bool theReset=true){
163 if (theReset) myGrid->Reset();
166 void SetVisibility(bool theVisibility){
167 myPreviewActor->SetVisibility(theVisibility);
168 RepaintCurrentView();
174 myViewWindow->RemoveActor(myPreviewActor);
176 myPreviewActor->Delete();
178 myMapper->RemoveAllInputs();
187 //=================================================================================
188 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
190 //=================================================================================
191 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule, const char* name,
192 bool modal, WFlags fl )
193 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
194 mySMESHGUI( theModule ),
195 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
197 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
200 setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
202 setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
203 setSizeGripEnabled( TRUE );
204 SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this );
205 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
206 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
208 /***************************************************************/
209 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
210 GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
211 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
212 GroupConstructors->setExclusive( TRUE );
213 GroupConstructors->setColumnLayout(0, Qt::Vertical );
214 GroupConstructors->layout()->setSpacing( 0 );
215 GroupConstructors->layout()->setMargin( 0 );
216 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
217 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
218 GroupConstructorsLayout->setSpacing( 6 );
219 GroupConstructorsLayout->setMargin( 11 );
220 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
221 RadioButton1->setText( tr( "MESH_NODE" ) );
222 GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
223 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
224 RadioButton2->setText( tr( "SMESH_FACE" ) );
225 GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
226 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
228 /***************************************************************/
229 GroupButtons = new QGroupBox( this, "GroupButtons" );
230 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
231 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
232 GroupButtons->setTitle( tr( "" ) );
233 GroupButtons->setColumnLayout(0, Qt::Vertical );
234 GroupButtons->layout()->setSpacing( 0 );
235 GroupButtons->layout()->setMargin( 0 );
236 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
237 GroupButtonsLayout->setAlignment( Qt::AlignTop );
238 GroupButtonsLayout->setSpacing( 6 );
239 GroupButtonsLayout->setMargin( 11 );
240 buttonCancel = new QPushButton( GroupButtons, "cancel" );
241 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
242 buttonCancel->setAutoDefault( TRUE );
243 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
244 buttonApply = new QPushButton( GroupButtons, "apply" );
245 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
246 buttonApply->setAutoDefault( TRUE );
247 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
248 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
249 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
250 buttonOk = new QPushButton( GroupButtons, "ok" );
251 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
252 buttonOk->setAutoDefault( TRUE );
253 buttonOk->setDefault( TRUE );
254 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
255 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
256 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
257 buttonHelp->setAutoDefault(TRUE);
258 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
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 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
320 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
322 GroupContent->show();
323 RadioButton1->setChecked( TRUE );
325 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
327 myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_polyhedrons?";
332 //=================================================================================
333 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
334 // purpose : Destroys the object and frees any allocated resources
335 //=================================================================================
336 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
338 // no need to delete child widgets, Qt does it all for us
342 static bool busy = false;
343 //=================================================================================
346 //=================================================================================
347 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
349 myEditCurrentArgument = LineEditElements;
350 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
355 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
357 /* signals and slots connections */
358 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
359 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
360 connect(buttonApply, SIGNAL( clicked() ), SLOT(ClickOnApply() ) );
361 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp() ) );
363 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
364 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
365 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
367 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
368 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
369 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
371 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
372 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
373 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
374 /* to close dialog if study change */
375 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
377 this->show() ; /* displays Dialog */
379 ConstructorsClicked(0);
380 SelectionIntoArgument();
384 //=================================================================================
385 // function : ConstructorsClicked()
386 // purpose : Radio button management
387 //=================================================================================
388 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
390 //disconnect(mySelectionMgr, 0, this, 0);
393 mySelectionMgr->selectedObjects( io );
395 mySelectionMgr->setSelectedObjects( aList );
396 myEditCurrentArgument->clear();
398 buttonApply->setEnabled(false);
399 buttonOk->setEnabled(false);
400 mySimulation->SetVisibility(false);
402 switch(constructorId)
407 myActor->SetPointRepresentation(true);
410 SMESH::SetPointRepresentation(true);
411 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
412 aViewWindow->SetSelectionMode(NodeSelection);
414 AddButton->setEnabled(false);
415 RemoveButton->setEnabled(false);
416 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
417 myFacesByNodesLabel->show();
418 myFacesByNodes->clear();
419 myFacesByNodes->show();
421 RemoveButton->show();
428 myActor->SetPointRepresentation(false);
430 SMESH::SetPointRepresentation(false);
432 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
433 aViewWindow->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()));
446 mySelectionMgr->setSelectedObjects( io );
449 //=================================================================================
450 // function : ClickOnPreview()
452 //=================================================================================
453 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
454 Preview->setChecked(theToggled);
458 //=================================================================================
459 // function : ClickOnApply()
461 //=================================================================================
462 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
464 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
466 if(checkEditLine(false) == -1) {return;}
468 if (GetConstructorId() == 0)
470 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
471 SMESH::long_array_var aQuantities = new SMESH::long_array;
473 aQuantities->length( myFacesByNodes->count() );
475 TColStd_ListOfInteger aNodesIds;
477 QListBoxItem* anItem;
478 int aNbQuantities = 0;
479 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
480 QStringList anIds = QStringList::split(" ", anItem->text());
481 int aNbNodesInFace = 0;
482 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
483 aNodesIds.Append( (*it).toInt() );
485 aQuantities[aNbQuantities++] = aNbNodesInFace;
488 anIdsOfNodes->length(aNodesIds.Extent());
490 int aNbIdsOfNodes = 0;
491 TColStd_ListIteratorOfListOfInteger It;
492 It.Initialize(aNodesIds);
493 for(;It.More();It.Next())
494 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
497 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
498 QApplication::setOverrideCursor(Qt::waitCursor);
499 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
500 QApplication::restoreOverrideCursor();
501 }catch(SALOME::SALOME_Exception& exc){
502 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
503 }catch(std::exception& exc){
504 INFOS("Follow exception was cought:\n\t"<<exc.what());
506 INFOS("Unknown exception was cought !!!");
509 else if (GetConstructorId() == 1)
511 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
513 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
514 anIdsOfFaces->length(aListId.count());
515 for ( int i = 0; i < aListId.count(); i++ )
516 anIdsOfFaces[i] = aListId[i].toInt();
519 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
520 QApplication::setOverrideCursor(Qt::waitCursor);
521 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
522 QApplication::restoreOverrideCursor();
523 }catch(SALOME::SALOME_Exception& exc){
524 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
525 }catch(std::exception& exc){
526 INFOS("Follow exception was cought:\n\t"<<exc.what());
528 INFOS("Unknown exception was cought !!!");
532 //SALOME_ListIO aList;
533 //mySelectionMgr->setSelectedObjects( aList );
536 unsigned int anEntityMode = myActor->GetEntityMode();
537 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
539 //ConstructorsClicked( GetConstructorId() );
544 //=================================================================================
545 // function : ClickOnOk()
547 //=================================================================================
548 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
550 if(checkEditLine(false) == -1) {return;}
556 //=================================================================================
557 // function : ClickOnCancel()
559 //=================================================================================
560 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
562 mySelectionMgr->clearFilters();
563 //SALOME_ListIO aList;
564 //mySelectionMgr->setSelectedObjects( aList );
565 SMESH::SetPointRepresentation(false);
566 mySimulation->SetVisibility(false);
567 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
568 aViewWindow->SetSelectionMode( ActorSelection );
569 disconnect( mySelectionMgr, 0, this, 0 );
570 mySMESHGUI->ResetState() ;
574 //=================================================================================
575 // function : ClickOnHelp()
577 //=================================================================================
578 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
580 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
582 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
584 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
585 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
586 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
587 QObject::tr("BUT_OK"));
591 //=======================================================================
592 //function : onTextChange
594 //=======================================================================
596 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
599 if (checkEditLine() == -1) return;
602 mySimulation->SetVisibility(false);
604 SMDS_Mesh* aMesh = 0;
606 aMesh = myActor->GetObject()->GetMesh();
608 if (GetConstructorId() == 0)
611 TColStd_MapOfInteger newIndices;
613 QStringList aListId = QStringList::split( " ", theNewText, false);
614 for ( int i = 0; i < aListId.count(); i++ ) {
615 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
617 newIndices.Add(n->GetID());
622 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
624 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
625 aViewWindow->highlight( myActor->getIO(), true, true );
627 if ( myNbOkElements>0 && aListId.count()>=3)
628 AddButton->setEnabled(true);
630 AddButton->setEnabled(false);
634 } else if (GetConstructorId() == 1)
637 buttonOk->setEnabled( false );
638 buttonApply->setEnabled( false );
640 // check entered ids of faces and hilight them
643 TColStd_MapOfInteger newIndices;
645 aListId = QStringList::split( " ", theNewText, false);
647 for ( int i = 0; i < aListId.count(); i++ ) {
648 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
650 newIndices.Add(e->GetID());
655 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
656 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
657 aViewWindow->highlight( myActor->getIO(), true, true );
659 if ( myNbOkElements ) {
660 if (aListId.count()>1){
661 buttonOk->setEnabled( true );
662 buttonApply->setEnabled( true );
665 buttonOk->setEnabled( false );
666 buttonApply->setEnabled( false );
668 if(aListId.count()>1)
676 //=================================================================================
677 // function : SelectionIntoArgument()
678 // purpose : Called when selection as changed or other case
679 //=================================================================================
680 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
686 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
689 AddButton->setEnabled(false);
690 buttonOk->setEnabled( false );
691 buttonApply->setEnabled( false );
697 myEditCurrentArgument->setText( "" );
699 if ( !GroupButtons->isEnabled() ) // inactive
702 mySimulation->SetVisibility(false);
706 SALOME_ListIO selected;
707 mySelectionMgr->selectedObjects( selected );
708 int nbSel = selected.Extent();
713 myMesh = SMESH::GetMeshByIO( selected.First() );
714 if ( myMesh->_is_nil() )
717 myActor = SMESH::FindActorByObject(myMesh);
721 // get selected nodes/faces
722 QString aString = "";
723 int anbNodes=0,aNbFaces=0;
724 switch(GetConstructorId()){
726 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
728 AddButton->setEnabled(true);
729 else if (anbNodes < 3){
730 AddButton->setEnabled(false);
733 myEditCurrentArgument->setText( aString );
734 if (checkEditLine() == -1) {busy = false;return;}
739 // get selected faces
740 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
742 buttonOk->setEnabled( false );
743 buttonApply->setEnabled( false );
745 buttonOk->setEnabled( true );
746 buttonApply->setEnabled( true );
749 myEditCurrentArgument->setText( aString );
750 if (checkEditLine() == -1) {busy = false;return;}
759 if(anbNodes>2 || aNbFaces>1)
763 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
764 * Checking of indices in edit line.
765 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
766 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
768 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
770 QString aString = "";
771 SMDS_Mesh* aMesh = 0;
773 if(myMesh->_is_nil()) return 1;
775 myActor = SMESH::FindActorByObject(myMesh);
780 aMesh = myActor->GetObject()->GetMesh();
782 // checking for nodes
783 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
784 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
785 for ( int i = 0; i < aListId.count(); i++ ){
786 switch (GetConstructorId()){
788 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
790 std::string aWarning;
791 aWarning = "The incorrect indices of nodes!";
792 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
793 QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
794 QObject::tr(aWarning.c_str()),
795 QObject::tr("SMESH_BUT_OK"));
797 myEditCurrentArgument->clear();
798 myEditCurrentArgument->setText( aString );
805 bool aElemIsOK = true;
806 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
813 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
814 if (aType != SMDSAbs_Face){
819 std::string aWarning;
820 aWarning = "The incorrect indices of faces!";
821 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
822 QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
823 QObject::tr(aWarning.c_str()),
824 QObject::tr("SMESH_BUT_OK"));
826 myEditCurrentArgument->clear();
827 myEditCurrentArgument->setText( aString );
833 aString += aListId[ i ] + " ";
839 //=======================================================================
840 //function : displaySimulation
842 //=======================================================================
843 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
845 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
847 SMESH::TPolySimulation::TVTKIds aVTKIds;
848 vtkIdType aType = VTK_CONVEX_POINT_SET ;
849 SMDS_Mesh* aMesh = 0;
851 aMesh = myActor->GetObject()->GetMesh();
853 if (GetConstructorId() == 0 && aMesh){
854 if (!AddButton->isEnabled()){
855 QListBoxItem* anItem;
856 mySimulation->ResetGrid(true);
857 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
858 QStringList anIds = QStringList::split(" ", anItem->text());
859 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
860 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
861 const SMDS_MeshNode * aNode = aMesh->FindNode( (*it).toInt() );
862 if (!aNode) continue;
863 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
864 aVTKIds.push_back(aId);
865 aVTKIds_faces.push_back(aId);
867 if(!Preview->isChecked()){
869 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
872 if(myFacesByNodes->count() == 0){
873 mySimulation->SetVisibility(false);
875 mySimulation->SetVisibility(true);
877 if(Preview->isChecked()){
878 mySimulation->SetPosition(myActor, aType, aVTKIds);
881 // add ids from edit line
882 QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
883 for ( int i = 0; i < anEditIds.count(); i++ )
884 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
886 mySimulation->SetPosition(myActor, aType, aVTKIds);
888 }else if(GetConstructorId() == 1 && aMesh){
889 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
890 for ( int i = 0; i < aListId.count(); i++ )
892 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
893 if ( !anElem ) continue;
894 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
895 if (aFaceType != SMDSAbs_Face) continue;
897 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
898 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
899 while( anIter->more() )
900 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
901 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
902 aVTKIds.push_back(aId);
903 aVTKIds_faces.push_back(aId);
905 if(!Preview->isChecked()){
907 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
910 if(Preview->isChecked())
911 mySimulation->SetPosition(myActor, aType, aVTKIds);
917 //=================================================================================
918 // function : SetEditCurrentArgument()
920 //=================================================================================
921 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
923 QPushButton* send = (QPushButton*)sender();
924 if(send == SelectElementsButton) {
925 LineEditElements->setFocus() ;
926 myEditCurrentArgument = LineEditElements;
928 SelectionIntoArgument();
931 //=================================================================================
932 // function : DeactivateActiveDialog()
934 //=================================================================================
935 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
937 if ( GroupConstructors->isEnabled() ) {
938 GroupConstructors->setEnabled(false) ;
939 GroupContent->setEnabled(false) ;
940 GroupButtons->setEnabled(false) ;
941 mySimulation->SetVisibility(false);
942 mySMESHGUI->ResetState() ;
943 mySMESHGUI->SetActiveDialogBox(0) ;
948 //=================================================================================
949 // function : ActivateThisDialog()
951 //=================================================================================
952 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
954 /* Emit a signal to deactivate the active dialog */
955 mySMESHGUI->EmitSignalDeactivateDialog() ;
956 GroupConstructors->setEnabled(true) ;
957 GroupContent->setEnabled(true) ;
958 GroupButtons->setEnabled(true) ;
960 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
962 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
963 aViewWindow->SetSelectionMode( FaceSelection );
964 SelectionIntoArgument();
968 //=================================================================================
969 // function : enterEvent()
971 //=================================================================================
972 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
974 if ( GroupConstructors->isEnabled() )
976 ActivateThisDialog() ;
980 //=================================================================================
981 // function : closeEvent()
983 //=================================================================================
984 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
986 /* same than click on cancel button */
987 this->ClickOnCancel() ;
991 //=======================================================================
992 //function : hideEvent
993 //purpose : caused by ESC key
994 //=======================================================================
996 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
998 if ( !isMinimized() )
1003 //=================================================================================
1004 // function : GetConstructorId()
1006 //=================================================================================
1007 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1009 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
1010 return GroupConstructors->id( GroupConstructors->selected() );
1014 //=================================================================================
1015 // function : onAdd()
1017 //=================================================================================
1018 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1020 SALOME_ListIO selected;
1021 mySelectionMgr->selectedObjects( selected );
1022 int aNbSel = selected.Extent();
1023 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1025 if (this->checkEditLine(false) == -1) return;
1028 if ( !(myEditCurrentArgument->text().isEmpty()) )
1030 myFacesByNodes->insertItem(myEditCurrentArgument->text());
1031 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1033 myEditCurrentArgument->clear();
1034 AddButton->setEnabled(false);
1035 buttonOk->setEnabled( true );
1036 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1039 onListSelectionChanged();
1040 displaySimulation();
1043 //=================================================================================
1044 // function : onRemove()
1046 //=================================================================================
1047 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1050 for (int i = myFacesByNodes->count(); i > 0; i--) {
1051 if (myFacesByNodes->isSelected(i-1)) {
1052 myFacesByNodes->removeItem(i-1);
1056 if (myFacesByNodes->count() < 1){
1057 RemoveButton->setEnabled(false);
1058 buttonOk->setEnabled( false );
1059 buttonApply->setEnabled( false );
1061 else if (myFacesByNodes->count() == 1){
1062 buttonOk->setEnabled( false );
1063 buttonApply->setEnabled( false );
1066 displaySimulation();
1069 //=================================================================================
1070 // function : onListSelectionChanged()
1071 // purpose : Called when selection in element list is changed
1072 //=================================================================================
1073 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1075 if (busy || !myActor) return;
1077 bool isSelected=false;
1078 SALOME_ListIO aList;
1079 mySelectionMgr->setSelectedObjects( aList );
1080 TColStd_MapOfInteger aIndexes;
1081 QListBoxItem* anItem;
1082 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
1083 if (anItem->isSelected()) {
1085 QStringList anIds = QStringList::split(" ", anItem->text());
1086 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1087 aIndexes.Add((*it).toInt());
1090 if(isSelected) RemoveButton->setEnabled(true);
1091 else RemoveButton->setEnabled(false);
1092 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1093 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1094 aViewWindow->highlight( myActor->getIO(), true, true );
1095 mySelectionMgr->clearFilters();
1096 aList.Append( myActor->getIO() );
1097 mySelectionMgr->setSelectedObjects( aList );