1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_GroupUtils.h"
35 #include "SMESHGUI_IdValidator.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_ActorUtils.h>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <SalomeApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewWindow.h>
55 #include <TColStd_ListOfInteger.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
60 #include <vtkIdList.h>
61 #include <vtkUnstructuredGrid.h>
62 #include <vtkDataSetMapper.h>
63 #include <vtkProperty.h>
66 #include <QApplication>
67 #include <QButtonGroup>
72 #include <QPushButton>
73 #include <QRadioButton>
75 #include <QHBoxLayout>
76 #include <QVBoxLayout>
77 #include <QGridLayout>
78 #include <QListWidget>
82 #include <SALOMEconfig.h>
83 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
92 SVTK_ViewWindow* myViewWindow;
94 SALOME_Actor *myPreviewActor;
95 vtkDataSetMapper* myMapper;
96 vtkUnstructuredGrid* myGrid;
100 TPolySimulation(SalomeApp_Application* app)
102 SUIT_ViewManager* mgr = app->activeViewManager();
103 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
105 myGrid = vtkUnstructuredGrid::New();
107 // Create and display actor
108 myMapper = vtkDataSetMapper::New();
109 myMapper->SetInput( myGrid );
111 myPreviewActor = SALOME_Actor::New();
112 myPreviewActor->PickableOff();
113 myPreviewActor->VisibilityOff();
114 myPreviewActor->SetMapper( myMapper );
115 myPreviewActor->SetRepresentation( 3 );
117 vtkFloatingPointType anRGB[3];
118 vtkProperty* aProp = vtkProperty::New();
119 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
120 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
121 myPreviewActor->SetProperty( aProp );
122 vtkFloatingPointType aFactor,aUnits;
123 myPreviewActor->SetResolveCoincidentTopology(true);
124 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
125 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
128 myViewWindow->AddActor( myPreviewActor );
133 typedef std::vector<vtkIdType> TVTKIds;
134 void SetPosition(SMESH_Actor* theActor,
136 const TVTKIds& theIds,
139 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
140 myGrid->SetPoints(aGrid->GetPoints());
144 vtkIdList *anIds = vtkIdList::New();
146 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
147 anIds->InsertId(i,theIds[i]);
149 myGrid->InsertNextCell(theType,anIds);
150 if(theIds.size()!=0){
151 myGrid->InsertNextCell(theType,anIds);
161 void ResetGrid(bool theReset=true){
162 if (theReset) myGrid->Reset();
165 void SetVisibility(bool theVisibility){
166 myPreviewActor->SetVisibility(theVisibility);
167 RepaintCurrentView();
173 myViewWindow->RemoveActor(myPreviewActor);
175 myPreviewActor->Delete();
177 myMapper->RemoveAllInputs();
186 //=================================================================================
187 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
189 //=================================================================================
190 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule )
191 : QDialog( SMESH::GetDesktop( theModule ) ),
192 mySMESHGUI( theModule ),
193 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
195 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
198 setAttribute(Qt::WA_DeleteOnClose, true);
199 setWindowTitle( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
200 setSizeGripEnabled( true );
202 QVBoxLayout* topLayout = new QVBoxLayout( this );
203 topLayout->setSpacing( SPACING );
204 topLayout->setMargin( MARGIN );
206 /***************************************************************/
207 ConstructorsBox = new QGroupBox(tr( "SMESH_ELEMENTS_TYPE" ), this);
208 GroupConstructors = new QButtonGroup(this);
209 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout( ConstructorsBox );
210 ConstructorsBoxLayout->setSpacing( SPACING );
211 ConstructorsBoxLayout->setMargin( MARGIN );
213 RadioButton1 = new QRadioButton( tr( "MESH_NODE" ), ConstructorsBox );
214 RadioButton2 = new QRadioButton( tr( "SMESH_FACE" ), ConstructorsBox );
216 ConstructorsBoxLayout->addWidget( RadioButton1 );
217 ConstructorsBoxLayout->addWidget( RadioButton2 );
218 GroupConstructors->addButton(RadioButton1, 0);
219 GroupConstructors->addButton(RadioButton2, 1);
221 /***************************************************************/
222 GroupContent = new QGroupBox( tr( "SMESH_CONTENT" ), this );
223 QGridLayout* GroupContentLayout = new QGridLayout( GroupContent );
224 GroupContentLayout->setSpacing( SPACING );
225 GroupContentLayout->setMargin( MARGIN );
227 TextLabelIds = new QLabel( tr( "SMESH_ID_NODES" ), GroupContent );
228 SelectElementsButton = new QPushButton( GroupContent );
229 SelectElementsButton->setIcon( image0 );
230 LineEditElements = new QLineEdit( GroupContent );
231 LineEditElements->setValidator( new SMESHGUI_IdValidator( this ) );
233 myFacesByNodesLabel = new QLabel( tr( "FACES_BY_NODES" ), GroupContent );
234 myFacesByNodes = new QListWidget( GroupContent);
235 myFacesByNodes->setSelectionMode( QListWidget::ExtendedSelection );
236 myFacesByNodes->setMinimumHeight( 150);
238 AddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), GroupContent );
239 RemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), GroupContent );
241 Preview = new QCheckBox( tr( "SMESH_POLYEDRE_PREVIEW" ), GroupContent );
243 GroupContentLayout->addWidget( TextLabelIds, 0, 0 );
244 GroupContentLayout->addWidget( SelectElementsButton, 0, 1 );
245 GroupContentLayout->addWidget( LineEditElements, 0, 2, 1, 2 );
246 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
247 GroupContentLayout->addWidget( myFacesByNodes, 2, 0, 3, 3 );
248 GroupContentLayout->addWidget( AddButton, 2, 3 );
249 GroupContentLayout->addWidget( RemoveButton, 3, 3 );
250 GroupContentLayout->addWidget( Preview, 5, 0, 1, 4 );
252 /***************************************************************/
253 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
254 GroupGroups->setCheckable( true );
255 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
256 GroupGroupsLayout->setSpacing(SPACING);
257 GroupGroupsLayout->setMargin(MARGIN);
259 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
260 ComboBox_GroupName = new QComboBox( GroupGroups );
261 ComboBox_GroupName->setEditable( true );
263 GroupGroupsLayout->addWidget( TextLabel_GroupName );
264 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
266 /***************************************************************/
267 GroupButtons = new QGroupBox( this );
268 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
269 GroupButtonsLayout->setSpacing( SPACING );
270 GroupButtonsLayout->setMargin( MARGIN );
272 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
273 buttonOk->setAutoDefault( true );
274 buttonOk->setDefault( true );
275 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
276 buttonApply->setAutoDefault( true );
277 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
278 buttonCancel->setAutoDefault( true );
279 buttonHelp = new QPushButton( tr("SMESH_BUT_HELP" ), GroupButtons );
280 buttonHelp->setAutoDefault(true);
282 GroupButtonsLayout->addWidget( buttonOk );
283 GroupButtonsLayout->addSpacing( 10 );
284 GroupButtonsLayout->addWidget( buttonApply );
285 GroupButtonsLayout->addSpacing( 10 );
286 GroupButtonsLayout->addStretch();
287 GroupButtonsLayout->addWidget( buttonCancel );
288 GroupButtonsLayout->addWidget( buttonHelp);
290 /***************************************************************/
291 topLayout->addWidget( ConstructorsBox );
292 topLayout->addWidget( GroupContent );
293 topLayout->addWidget( GroupGroups );
294 topLayout->addWidget( GroupButtons );
296 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
298 RadioButton1->setChecked( true );
300 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
302 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
307 //=================================================================================
308 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
309 // purpose : Destroys the object and frees any allocated resources
310 //=================================================================================
311 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
316 static bool busy = false;
318 //=================================================================================
321 //=================================================================================
322 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
324 myEditCurrentArgument = LineEditElements;
325 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
327 /* reset "Add to group" control */
328 GroupGroups->setChecked( false );
333 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
335 /* signals and slots connections */
336 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
337 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) );
338 connect(buttonApply, SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
339 connect(buttonHelp, SIGNAL( clicked() ), SLOT( ClickOnHelp() ) );
341 connect(GroupConstructors, SIGNAL(buttonClicked(int) ), SLOT( ConstructorsClicked(int) ) );
342 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) );
343 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
345 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
346 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
347 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
349 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
350 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
351 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
352 /* to close dialog if study change */
353 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
355 ConstructorsClicked(0);
356 SelectionIntoArgument();
360 //=================================================================================
361 // function : ConstructorsClicked()
362 // purpose : Radio button management
363 //=================================================================================
364 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
366 //disconnect(mySelectionMgr, 0, this, 0);
369 mySelectionMgr->selectedObjects( io );
371 mySelectionMgr->setSelectedObjects( aList );
372 myEditCurrentArgument->clear();
374 buttonApply->setEnabled(false);
375 buttonOk->setEnabled(false);
376 mySimulation->SetVisibility(false);
378 switch(constructorId)
383 myActor->SetPointRepresentation(true);
386 SMESH::SetPointRepresentation(true);
387 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
388 aViewWindow->SetSelectionMode(NodeSelection);
390 AddButton->setEnabled(false);
391 RemoveButton->setEnabled(false);
392 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
393 myFacesByNodesLabel->show();
394 myFacesByNodes->clear();
395 myFacesByNodes->show();
397 RemoveButton->show();
404 myActor->SetPointRepresentation(false);
406 SMESH::SetPointRepresentation(false);
408 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
409 aViewWindow->SetSelectionMode(FaceSelection);
411 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
412 myFacesByNodesLabel->hide();
413 myFacesByNodes->hide();
415 RemoveButton->hide();
421 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
422 mySelectionMgr->setSelectedObjects( io );
424 QApplication::instance()->processEvents();
429 //=================================================================================
430 // function : ClickOnPreview()
432 //=================================================================================
433 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
434 Preview->setChecked(theToggled);
438 //=================================================================================
439 // function : ClickOnApply()
441 //=================================================================================
442 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
447 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
449 if(checkEditLine(false) == -1) {return;}
453 bool addToGroup = GroupGroups->isChecked();
456 SMESH::SMESH_GroupBase_var aGroup;
459 aGroupName = ComboBox_GroupName->currentText();
460 for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
461 QString aName = ComboBox_GroupName->itemText( i );
462 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
466 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
467 if ( !aGeomGroup->_is_nil() ) {
468 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
469 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
470 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
471 if ( res == 1 ) return;
473 aGroup = myGroups[idx-1];
477 if (GetConstructorId() == 0)
479 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
480 SMESH::long_array_var aQuantities = new SMESH::long_array;
482 aQuantities->length( myFacesByNodes->count() );
484 TColStd_ListOfInteger aNodesIds;
486 int aNbQuantities = 0;
487 for (int i = 0; i < myFacesByNodes->count(); i++ ) {
488 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
489 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
490 aNodesIds.Append( (*it).toInt() );
492 aQuantities[aNbQuantities++] = anIds.count();
495 anIdsOfNodes->length(aNodesIds.Extent());
497 int aNbIdsOfNodes = 0;
498 TColStd_ListIteratorOfListOfInteger It;
499 It.Initialize(aNodesIds);
500 for( ;It.More();It.Next())
501 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
504 SUIT_OverrideCursor aWaitCursor;
505 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
506 anElemId = aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
507 }catch(SALOME::SALOME_Exception& exc){
508 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
509 }catch(std::exception& exc){
510 INFOS("Follow exception was cought:\n\t"<<exc.what());
512 INFOS("Unknown exception was cought !!!");
515 else if (GetConstructorId() == 1)
517 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
519 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
520 anIdsOfFaces->length(aListId.count());
521 for ( int i = 0; i < aListId.count(); i++ )
522 anIdsOfFaces[i] = aListId[i].toInt();
525 SUIT_OverrideCursor aWaitCursor;
526 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
527 anElemId = aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
528 }catch(SALOME::SALOME_Exception& exc){
529 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
530 }catch(std::exception& exc){
531 INFOS("Follow exception was cought:\n\t"<<exc.what());
533 INFOS("Unknown exception was cought !!!");
537 if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
538 SMESH::SMESH_Group_var aGroupUsed;
539 if ( aGroup->_is_nil() ) {
541 aGroupUsed = SMESH::AddGroup( myMesh, SMESH::VOLUME, aGroupName );
542 if ( !aGroupUsed->_is_nil() ) {
543 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
544 ComboBox_GroupName->addItem( aGroupName );
548 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
549 if ( !aGeomGroup->_is_nil() ) {
550 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
551 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
552 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
553 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
557 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
560 if ( !aGroupUsed->_is_nil() ) {
561 SMESH::long_array_var anIdList = new SMESH::long_array;
562 anIdList->length( 1 );
563 anIdList[0] = anElemId;
564 aGroupUsed->Add( anIdList.inout() );
568 //SALOME_ListIO aList;
569 //mySelectionMgr->setSelectedObjects( aList );
572 unsigned int anEntityMode = myActor->GetEntityMode();
573 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
575 //ConstructorsClicked( GetConstructorId() );
578 SMESHGUI::Modified();
582 //=================================================================================
583 // function : ClickOnOk()
585 //=================================================================================
586 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
588 if(checkEditLine(false) == -1) {return;}
594 //=================================================================================
595 // function : ClickOnCancel()
597 //=================================================================================
598 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
600 mySelectionMgr->clearFilters();
601 //SALOME_ListIO aList;
602 //mySelectionMgr->setSelectedObjects( aList );
603 SMESH::SetPointRepresentation(false);
604 mySimulation->SetVisibility(false);
605 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
606 aViewWindow->SetSelectionMode( ActorSelection );
607 disconnect( mySelectionMgr, 0, this, 0 );
608 mySMESHGUI->ResetState();
612 //=================================================================================
613 // function : ClickOnHelp()
615 //=================================================================================
616 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
618 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
620 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
624 platform = "winapplication";
626 platform = "application";
628 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
629 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
630 arg(app->resourceMgr()->stringValue("ExternalBrowser",
632 arg(myHelpFileName));
636 //=======================================================================
637 //function : onTextChange
639 //=======================================================================
641 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
644 if (checkEditLine() == -1) return;
647 mySimulation->SetVisibility(false);
649 SMDS_Mesh* aMesh = 0;
651 aMesh = myActor->GetObject()->GetMesh();
653 if (GetConstructorId() == 0)
656 TColStd_MapOfInteger newIndices;
658 QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts );
659 for ( int i = 0; i < aListId.count(); i++ ) {
660 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
662 newIndices.Add(n->GetID());
667 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
669 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
670 aViewWindow->highlight( myActor->getIO(), true, true );
672 if ( myNbOkElements>0 && aListId.count()>=3)
673 AddButton->setEnabled(true);
675 AddButton->setEnabled(false);
679 } else if (GetConstructorId() == 1)
682 buttonOk->setEnabled( false );
683 buttonApply->setEnabled( false );
685 // check entered ids of faces and hilight them
688 TColStd_MapOfInteger newIndices;
690 aListId = theNewText.split( " ", QString::SkipEmptyParts );
692 for ( int i = 0; i < aListId.count(); i++ ) {
693 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
695 newIndices.Add(e->GetID());
700 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
701 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
702 aViewWindow->highlight( myActor->getIO(), true, true );
704 if ( myNbOkElements ) {
705 if (aListId.count()>1){
706 buttonOk->setEnabled( true );
707 buttonApply->setEnabled( true );
710 buttonOk->setEnabled( false );
711 buttonApply->setEnabled( false );
713 if(aListId.count()>1)
721 //=================================================================================
722 // function : SelectionIntoArgument()
723 // purpose : Called when selection as changed or other case
724 //=================================================================================
725 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
731 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
734 AddButton->setEnabled(false);
735 buttonOk->setEnabled( false );
736 buttonApply->setEnabled( false );
742 myEditCurrentArgument->setText( "" );
744 if ( !GroupButtons->isEnabled() ) // inactive
747 mySimulation->SetVisibility(false);
749 QString aCurrentEntry = myEntry;
753 SALOME_ListIO selected;
754 mySelectionMgr->selectedObjects( selected );
755 int nbSel = selected.Extent();
760 myEntry = selected.First()->getEntry();
761 myMesh = SMESH::GetMeshByIO( selected.First() );
762 if ( myMesh->_is_nil() )
766 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
768 ComboBox_GroupName->clear();
769 ComboBox_GroupName->addItem( QString() );
770 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
771 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
772 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
773 if ( !aGroup->_is_nil() && aGroup->GetType() == SMESH::VOLUME ) {
774 QString aGroupName( aGroup->GetName() );
775 if ( !aGroupName.isEmpty() ) {
776 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
777 ComboBox_GroupName->addItem( aGroupName );
783 myActor = SMESH::FindActorByObject(myMesh);
787 // get selected nodes/faces
788 QString aString = "";
789 int anbNodes=0,aNbFaces=0;
790 switch(GetConstructorId()){
792 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
794 AddButton->setEnabled(true);
795 else if (anbNodes < 3){
796 AddButton->setEnabled(false);
799 myEditCurrentArgument->setText( aString );
800 if (checkEditLine() == -1) {busy = false;return;}
805 // get selected faces
806 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
808 buttonOk->setEnabled( false );
809 buttonApply->setEnabled( false );
811 buttonOk->setEnabled( true );
812 buttonApply->setEnabled( true );
815 myEditCurrentArgument->setText( aString );
816 if (checkEditLine() == -1) {busy = false;return;}
825 if(anbNodes>2 || aNbFaces>1)
829 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
830 * Checking of indices in edit line.
831 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
832 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
834 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
836 QString aString = "";
837 SMDS_Mesh* aMesh = 0;
839 if(myMesh->_is_nil()) return 1;
841 myActor = SMESH::FindActorByObject(myMesh);
846 aMesh = myActor->GetObject()->GetMesh();
848 // checking for nodes
849 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
850 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
851 for ( int i = 0; i < aListId.count(); i++ ){
852 switch (GetConstructorId()){
854 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
856 SUIT_MessageBox::warning(this,
857 tr("SMESH_POLYEDRE_CREATE_ERROR"),
858 tr("The incorrect indices of nodes!"));
860 myEditCurrentArgument->clear();
861 myEditCurrentArgument->setText( aString );
868 bool aElemIsOK = true;
869 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
876 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
877 if (aType != SMDSAbs_Face){
882 SUIT_MessageBox::warning(this,
883 tr("SMESH_POLYEDRE_CREATE_ERROR"),
884 tr("The incorrect indices of faces!"));
886 myEditCurrentArgument->clear();
887 myEditCurrentArgument->setText( aString );
893 aString += aListId[ i ] + " ";
899 //=======================================================================
900 //function : displaySimulation
902 //=======================================================================
903 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
905 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
907 SMESH::TPolySimulation::TVTKIds aVTKIds;
908 vtkIdType aType = VTK_CONVEX_POINT_SET;
909 SMDS_Mesh* aMesh = 0;
911 aMesh = myActor->GetObject()->GetMesh();
913 if (GetConstructorId() == 0 && aMesh){
914 if (!AddButton->isEnabled()){
915 mySimulation->ResetGrid(true);
916 for (int i = 0; i < myFacesByNodes->count(); i++) {
917 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
918 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
919 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
920 const SMDS_MeshNode* aNode = aMesh->FindNode( (*it).toInt() );
921 if (!aNode) continue;
922 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() );
923 aVTKIds.push_back(aId);
924 aVTKIds_faces.push_back(aId);
926 if(!Preview->isChecked()){
928 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
931 if(myFacesByNodes->count() == 0){
932 mySimulation->SetVisibility(false);
934 mySimulation->SetVisibility(true);
936 if(Preview->isChecked()){
937 mySimulation->SetPosition(myActor, aType, aVTKIds);
940 // add ids from edit line
941 QStringList anEditIds = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
942 for ( int i = 0; i < anEditIds.count(); i++ )
943 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
945 mySimulation->SetPosition(myActor, aType, aVTKIds);
947 }else if(GetConstructorId() == 1 && aMesh){
948 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
949 for ( int i = 0; i < aListId.count(); i++ )
951 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
952 if ( !anElem ) continue;
953 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
954 if (aFaceType != SMDSAbs_Face) continue;
956 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
957 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
958 while( anIter->more() )
959 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
960 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() );
961 aVTKIds.push_back(aId);
962 aVTKIds_faces.push_back(aId);
964 if(!Preview->isChecked()){
966 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
969 if(Preview->isChecked())
970 mySimulation->SetPosition(myActor, aType, aVTKIds);
976 //=================================================================================
977 // function : SetEditCurrentArgument()
979 //=================================================================================
980 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
982 QPushButton* send = (QPushButton*)sender();
983 if(send == SelectElementsButton) {
984 LineEditElements->setFocus();
985 myEditCurrentArgument = LineEditElements;
987 SelectionIntoArgument();
990 //=================================================================================
991 // function : DeactivateActiveDialog()
993 //=================================================================================
994 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
996 if ( ConstructorsBox->isEnabled() ) {
997 ConstructorsBox->setEnabled(false);
998 GroupContent->setEnabled(false);
999 GroupButtons->setEnabled(false);
1000 mySimulation->SetVisibility(false);
1001 mySMESHGUI->ResetState();
1002 mySMESHGUI->SetActiveDialogBox(0);
1007 //=================================================================================
1008 // function : ActivateThisDialog()
1010 //=================================================================================
1011 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
1013 /* Emit a signal to deactivate the active dialog */
1014 mySMESHGUI->EmitSignalDeactivateDialog();
1015 ConstructorsBox->setEnabled(true);
1016 GroupContent->setEnabled(true);
1017 GroupButtons->setEnabled(true);
1019 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
1021 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1022 aViewWindow->SetSelectionMode( FaceSelection );
1023 SelectionIntoArgument();
1027 //=================================================================================
1028 // function : enterEvent()
1030 //=================================================================================
1031 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
1033 if ( ConstructorsBox->isEnabled() )
1035 ActivateThisDialog();
1039 //=================================================================================
1040 // function : closeEvent()
1042 //=================================================================================
1043 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
1045 /* same than click on cancel button */
1050 //=======================================================================
1051 //function : hideEvent
1052 //purpose : caused by ESC key
1053 //=======================================================================
1055 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
1057 if ( !isMinimized() )
1062 //=================================================================================
1063 // function : GetConstructorId()
1065 //=================================================================================
1066 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1068 return GroupConstructors->checkedId();
1071 //=================================================================================
1072 // function : onAdd()
1074 //=================================================================================
1075 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1077 SALOME_ListIO selected;
1078 mySelectionMgr->selectedObjects( selected );
1079 int aNbSel = selected.Extent();
1080 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1082 if (checkEditLine(false) == -1) return;
1085 if ( !(myEditCurrentArgument->text().isEmpty()) )
1087 myFacesByNodes->addItem(myEditCurrentArgument->text());
1088 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1090 myEditCurrentArgument->clear();
1091 AddButton->setEnabled(false);
1092 buttonOk->setEnabled( true );
1093 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1096 onListSelectionChanged();
1097 displaySimulation();
1100 //=================================================================================
1101 // function : onRemove()
1103 //=================================================================================
1104 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1107 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1108 QListWidgetItem* anItem;
1110 if ( selItems.count() > 0 ) myNbOkElements = 1;
1112 foreach( anItem, selItems )
1115 RemoveButton->setEnabled( myFacesByNodes->count() > 0 );
1116 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
1117 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
1120 displaySimulation();
1123 //=================================================================================
1124 // function : onListSelectionChanged()
1125 // purpose : Called when selection in element list is changed
1126 //=================================================================================
1127 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1129 if (busy || !myActor) return;
1132 SALOME_ListIO aList;
1133 mySelectionMgr->setSelectedObjects( aList );
1134 TColStd_MapOfInteger aIndexes;
1136 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1137 QListWidgetItem* anItem;
1138 foreach( anItem, selItems ) {
1139 QStringList anIds = anItem->text().split( " ", QString::SkipEmptyParts );
1140 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1141 aIndexes.Add((*it).toInt());
1143 RemoveButton->setEnabled(selItems.count() > 0);
1144 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1145 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1146 aViewWindow->highlight( myActor->getIO(), true, true );
1147 mySelectionMgr->clearFilters();
1148 aList.Append( myActor->getIO() );
1149 mySelectionMgr->setSelectedObjects( aList );
1154 //=================================================================================
1155 // function : keyPressEvent()
1157 //=================================================================================
1158 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1160 QDialog::keyPressEvent( e );
1161 if ( e->isAccepted() )
1164 if ( e->key() == Qt::Key_F1 ) {
1170 //=================================================================================
1171 // function : isValid
1173 //=================================================================================
1174 bool SMESHGUI_CreatePolyhedralVolumeDlg::isValid()
1176 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
1177 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );