1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_IdValidator.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_ActorUtils.h>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GUI includes
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <SalomeApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewWindow.h>
54 #include <TColStd_ListOfInteger.hxx>
55 #include <TColStd_ListIteratorOfListOfInteger.hxx>
59 #include <vtkIdList.h>
60 #include <vtkUnstructuredGrid.h>
61 #include <vtkDataSetMapper.h>
62 #include <vtkProperty.h>
65 #include <QApplication>
66 #include <QButtonGroup>
71 #include <QPushButton>
72 #include <QRadioButton>
74 #include <QHBoxLayout>
75 #include <QVBoxLayout>
76 #include <QGridLayout>
77 #include <QListWidget>
81 #include <SALOMEconfig.h>
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
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 );
114 myPreviewActor->SetRepresentation( 3 );
116 vtkFloatingPointType anRGB[3];
117 vtkProperty* aProp = vtkProperty::New();
118 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
119 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
120 myPreviewActor->SetProperty( aProp );
121 vtkFloatingPointType aFactor,aUnits;
122 myPreviewActor->SetResolveCoincidentTopology(true);
123 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
124 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
127 myViewWindow->AddActor( myPreviewActor );
132 typedef std::vector<vtkIdType> TVTKIds;
133 void SetPosition(SMESH_Actor* theActor,
135 const TVTKIds& theIds,
138 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
139 myGrid->SetPoints(aGrid->GetPoints());
143 vtkIdList *anIds = vtkIdList::New();
145 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
146 anIds->InsertId(i,theIds[i]);
148 myGrid->InsertNextCell(theType,anIds);
149 if(theIds.size()!=0){
150 myGrid->InsertNextCell(theType,anIds);
160 void ResetGrid(bool theReset=true){
161 if (theReset) myGrid->Reset();
164 void SetVisibility(bool theVisibility){
165 myPreviewActor->SetVisibility(theVisibility);
166 RepaintCurrentView();
172 myViewWindow->RemoveActor(myPreviewActor);
174 myPreviewActor->Delete();
176 myMapper->RemoveAllInputs();
185 //=================================================================================
186 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
188 //=================================================================================
189 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule )
190 : QDialog( SMESH::GetDesktop( theModule ) ),
191 mySMESHGUI( theModule ),
192 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
194 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
197 setAttribute(Qt::WA_DeleteOnClose, true);
198 setWindowTitle( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
199 setSizeGripEnabled( true );
201 QVBoxLayout* topLayout = new QVBoxLayout( this );
202 topLayout->setSpacing( SPACING );
203 topLayout->setMargin( MARGIN );
205 /***************************************************************/
206 ConstructorsBox = new QGroupBox(tr( "SMESH_ELEMENTS_TYPE" ), this);
207 GroupConstructors = new QButtonGroup(this);
208 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout( ConstructorsBox );
209 ConstructorsBoxLayout->setSpacing( SPACING );
210 ConstructorsBoxLayout->setMargin( MARGIN );
212 RadioButton1 = new QRadioButton( tr( "MESH_NODE" ), ConstructorsBox );
213 RadioButton2 = new QRadioButton( tr( "SMESH_FACE" ), ConstructorsBox );
215 ConstructorsBoxLayout->addWidget( RadioButton1 );
216 ConstructorsBoxLayout->addWidget( RadioButton2 );
217 GroupConstructors->addButton(RadioButton1, 0);
218 GroupConstructors->addButton(RadioButton2, 1);
220 /***************************************************************/
221 GroupContent = new QGroupBox( tr( "SMESH_CONTENT" ), this );
222 QGridLayout* GroupContentLayout = new QGridLayout( GroupContent );
223 GroupContentLayout->setSpacing( SPACING );
224 GroupContentLayout->setMargin( MARGIN );
226 TextLabelIds = new QLabel( tr( "SMESH_ID_NODES" ), GroupContent );
227 SelectElementsButton = new QPushButton( GroupContent );
228 SelectElementsButton->setIcon( image0 );
229 LineEditElements = new QLineEdit( GroupContent );
230 LineEditElements->setValidator( new SMESHGUI_IdValidator( this ) );
232 myFacesByNodesLabel = new QLabel( tr( "FACES_BY_NODES" ), GroupContent );
233 myFacesByNodes = new QListWidget( GroupContent);
234 myFacesByNodes->setSelectionMode( QListWidget::ExtendedSelection );
235 myFacesByNodes->setMinimumHeight( 150);
237 AddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), GroupContent );
238 RemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), GroupContent );
240 Preview = new QCheckBox( tr( "SMESH_POLYEDRE_PREVIEW" ), GroupContent );
242 GroupContentLayout->addWidget( TextLabelIds, 0, 0 );
243 GroupContentLayout->addWidget( SelectElementsButton, 0, 1 );
244 GroupContentLayout->addWidget( LineEditElements, 0, 2, 1, 2 );
245 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
246 GroupContentLayout->addWidget( myFacesByNodes, 2, 0, 3, 3 );
247 GroupContentLayout->addWidget( AddButton, 2, 3 );
248 GroupContentLayout->addWidget( RemoveButton, 3, 3 );
249 GroupContentLayout->addWidget( Preview, 5, 0, 1, 4 );
251 /***************************************************************/
252 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
253 GroupGroups->setCheckable( true );
254 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
255 GroupGroupsLayout->setSpacing(SPACING);
256 GroupGroupsLayout->setMargin(MARGIN);
258 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
259 ComboBox_GroupName = new QComboBox( GroupGroups );
260 ComboBox_GroupName->setEditable( true );
262 GroupGroupsLayout->addWidget( TextLabel_GroupName );
263 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
265 /***************************************************************/
266 GroupButtons = new QGroupBox( this );
267 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
268 GroupButtonsLayout->setSpacing( SPACING );
269 GroupButtonsLayout->setMargin( MARGIN );
271 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
272 buttonOk->setAutoDefault( true );
273 buttonOk->setDefault( true );
274 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
275 buttonApply->setAutoDefault( true );
276 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
277 buttonCancel->setAutoDefault( true );
278 buttonHelp = new QPushButton( tr("SMESH_BUT_HELP" ), GroupButtons );
279 buttonHelp->setAutoDefault(true);
281 GroupButtonsLayout->addWidget( buttonOk );
282 GroupButtonsLayout->addSpacing( 10 );
283 GroupButtonsLayout->addWidget( buttonApply );
284 GroupButtonsLayout->addSpacing( 10 );
285 GroupButtonsLayout->addStretch();
286 GroupButtonsLayout->addWidget( buttonCancel );
287 GroupButtonsLayout->addWidget( buttonHelp);
289 /***************************************************************/
290 topLayout->addWidget( ConstructorsBox );
291 topLayout->addWidget( GroupContent );
292 topLayout->addWidget( GroupGroups );
293 topLayout->addWidget( GroupButtons );
295 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
297 RadioButton1->setChecked( true );
299 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
301 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
306 //=================================================================================
307 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
308 // purpose : Destroys the object and frees any allocated resources
309 //=================================================================================
310 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
315 static bool busy = false;
317 //=================================================================================
320 //=================================================================================
321 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
323 myEditCurrentArgument = LineEditElements;
324 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
326 /* reset "Add to group" control */
327 GroupGroups->setChecked( false );
332 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
334 /* signals and slots connections */
335 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
336 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) );
337 connect(buttonApply, SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
338 connect(buttonHelp, SIGNAL( clicked() ), SLOT( ClickOnHelp() ) );
340 connect(GroupConstructors, SIGNAL(buttonClicked(int) ), SLOT( ConstructorsClicked(int) ) );
341 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) );
342 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
344 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
345 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
346 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
348 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
349 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
350 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
351 /* to close dialog if study change */
352 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
354 ConstructorsClicked(0);
355 SelectionIntoArgument();
359 //=================================================================================
360 // function : ConstructorsClicked()
361 // purpose : Radio button management
362 //=================================================================================
363 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
365 //disconnect(mySelectionMgr, 0, this, 0);
368 mySelectionMgr->selectedObjects( io );
370 mySelectionMgr->setSelectedObjects( aList );
371 myEditCurrentArgument->clear();
373 buttonApply->setEnabled(false);
374 buttonOk->setEnabled(false);
375 mySimulation->SetVisibility(false);
377 switch(constructorId)
382 myActor->SetPointRepresentation(true);
385 SMESH::SetPointRepresentation(true);
386 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
387 aViewWindow->SetSelectionMode(NodeSelection);
389 AddButton->setEnabled(false);
390 RemoveButton->setEnabled(false);
391 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
392 myFacesByNodesLabel->show();
393 myFacesByNodes->clear();
394 myFacesByNodes->show();
396 RemoveButton->show();
403 myActor->SetPointRepresentation(false);
405 SMESH::SetPointRepresentation(false);
407 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
408 aViewWindow->SetSelectionMode(FaceSelection);
410 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
411 myFacesByNodesLabel->hide();
412 myFacesByNodes->hide();
414 RemoveButton->hide();
420 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
421 mySelectionMgr->setSelectedObjects( io );
423 QApplication::instance()->processEvents();
428 //=================================================================================
429 // function : ClickOnPreview()
431 //=================================================================================
432 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
433 Preview->setChecked(theToggled);
437 //=================================================================================
438 // function : ClickOnApply()
440 //=================================================================================
441 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
446 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
448 if(checkEditLine(false) == -1) {return;}
451 if (GetConstructorId() == 0)
453 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
454 SMESH::long_array_var aQuantities = new SMESH::long_array;
456 aQuantities->length( myFacesByNodes->count() );
458 TColStd_ListOfInteger aNodesIds;
460 int aNbQuantities = 0;
461 for (int i = 0; i < myFacesByNodes->count(); i++ ) {
462 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
463 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
464 aNodesIds.Append( (*it).toInt() );
466 aQuantities[aNbQuantities++] = anIds.count();
469 anIdsOfNodes->length(aNodesIds.Extent());
471 int aNbIdsOfNodes = 0;
472 TColStd_ListIteratorOfListOfInteger It;
473 It.Initialize(aNodesIds);
474 for( ;It.More();It.Next())
475 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
478 SUIT_OverrideCursor aWaitCursor;
479 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
480 anElemId = aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
481 }catch(SALOME::SALOME_Exception& exc){
482 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
483 }catch(std::exception& exc){
484 INFOS("Follow exception was cought:\n\t"<<exc.what());
486 INFOS("Unknown exception was cought !!!");
489 else if (GetConstructorId() == 1)
491 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
493 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
494 anIdsOfFaces->length(aListId.count());
495 for ( int i = 0; i < aListId.count(); i++ )
496 anIdsOfFaces[i] = aListId[i].toInt();
499 SUIT_OverrideCursor aWaitCursor;
500 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
501 anElemId = aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
502 }catch(SALOME::SALOME_Exception& exc){
503 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
504 }catch(std::exception& exc){
505 INFOS("Follow exception was cought:\n\t"<<exc.what());
507 INFOS("Unknown exception was cought !!!");
511 if( anElemId != -1 && GroupGroups->isChecked() ) {
512 SMESH::SMESH_Group_var aGroup;
513 QString aGroupName = ComboBox_GroupName->currentText();
514 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
515 for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
516 SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i];
517 if( !aGroupBase->_is_nil() ) {
518 SMESH::SMESH_Group_var aRefGroup = SMESH::SMESH_Group::_narrow( aGroupBase );
519 if( !aRefGroup->_is_nil() ) {
520 QString aRefGroupName( aRefGroup->GetName() );
521 if( aRefGroupName == aGroupName ) {
522 aGroup = aRefGroup; // // add node to existing group
528 if( aGroup->_is_nil() ) // create new group
529 aGroup = SMESH::AddGroup( myMesh, SMESH::VOLUME, aGroupName );
531 if( !aGroup->_is_nil() ) {
532 SMESH::long_array_var anIdList = new SMESH::long_array;
533 anIdList->length( 1 );
534 anIdList[0] = anElemId;
535 aGroup->Add( anIdList.inout() );
539 //SALOME_ListIO aList;
540 //mySelectionMgr->setSelectedObjects( aList );
543 unsigned int anEntityMode = myActor->GetEntityMode();
544 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
546 //ConstructorsClicked( GetConstructorId() );
551 //=================================================================================
552 // function : ClickOnOk()
554 //=================================================================================
555 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
557 if(checkEditLine(false) == -1) {return;}
563 //=================================================================================
564 // function : ClickOnCancel()
566 //=================================================================================
567 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
569 mySelectionMgr->clearFilters();
570 //SALOME_ListIO aList;
571 //mySelectionMgr->setSelectedObjects( aList );
572 SMESH::SetPointRepresentation(false);
573 mySimulation->SetVisibility(false);
574 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
575 aViewWindow->SetSelectionMode( ActorSelection );
576 disconnect( mySelectionMgr, 0, this, 0 );
577 mySMESHGUI->ResetState();
581 //=================================================================================
582 // function : ClickOnHelp()
584 //=================================================================================
585 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
587 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
589 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
593 platform = "winapplication";
595 platform = "application";
597 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
598 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
599 arg(app->resourceMgr()->stringValue("ExternalBrowser",
601 arg(myHelpFileName));
605 //=======================================================================
606 //function : onTextChange
608 //=======================================================================
610 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
613 if (checkEditLine() == -1) return;
616 mySimulation->SetVisibility(false);
618 SMDS_Mesh* aMesh = 0;
620 aMesh = myActor->GetObject()->GetMesh();
622 if (GetConstructorId() == 0)
625 TColStd_MapOfInteger newIndices;
627 QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts );
628 for ( int i = 0; i < aListId.count(); i++ ) {
629 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
631 newIndices.Add(n->GetID());
636 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
638 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
639 aViewWindow->highlight( myActor->getIO(), true, true );
641 if ( myNbOkElements>0 && aListId.count()>=3)
642 AddButton->setEnabled(true);
644 AddButton->setEnabled(false);
648 } else if (GetConstructorId() == 1)
651 buttonOk->setEnabled( false );
652 buttonApply->setEnabled( false );
654 // check entered ids of faces and hilight them
657 TColStd_MapOfInteger newIndices;
659 aListId = theNewText.split( " ", QString::SkipEmptyParts );
661 for ( int i = 0; i < aListId.count(); i++ ) {
662 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
664 newIndices.Add(e->GetID());
669 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
670 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
671 aViewWindow->highlight( myActor->getIO(), true, true );
673 if ( myNbOkElements ) {
674 if (aListId.count()>1){
675 buttonOk->setEnabled( true );
676 buttonApply->setEnabled( true );
679 buttonOk->setEnabled( false );
680 buttonApply->setEnabled( false );
682 if(aListId.count()>1)
690 //=================================================================================
691 // function : SelectionIntoArgument()
692 // purpose : Called when selection as changed or other case
693 //=================================================================================
694 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
700 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
703 AddButton->setEnabled(false);
704 buttonOk->setEnabled( false );
705 buttonApply->setEnabled( false );
711 myEditCurrentArgument->setText( "" );
713 if ( !GroupButtons->isEnabled() ) // inactive
716 mySimulation->SetVisibility(false);
718 QString aCurrentEntry = myEntry;
722 SALOME_ListIO selected;
723 mySelectionMgr->selectedObjects( selected );
724 int nbSel = selected.Extent();
729 myEntry = selected.First()->getEntry();
730 myMesh = SMESH::GetMeshByIO( selected.First() );
731 if ( myMesh->_is_nil() )
735 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
736 ComboBox_GroupName->clear();
737 ComboBox_GroupName->addItem( QString() );
738 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
739 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
740 SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i];
741 if ( !aGroupBase->_is_nil() && aGroupBase->GetType() == SMESH::VOLUME ) {
742 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupBase );
743 if ( !aGroup->_is_nil() ) {
744 QString aGroupName( aGroup->GetName() );
745 if ( !aGroupName.isEmpty() )
746 ComboBox_GroupName->addItem( aGroupName );
752 myActor = SMESH::FindActorByObject(myMesh);
756 // get selected nodes/faces
757 QString aString = "";
758 int anbNodes=0,aNbFaces=0;
759 switch(GetConstructorId()){
761 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
763 AddButton->setEnabled(true);
764 else if (anbNodes < 3){
765 AddButton->setEnabled(false);
768 myEditCurrentArgument->setText( aString );
769 if (checkEditLine() == -1) {busy = false;return;}
774 // get selected faces
775 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
777 buttonOk->setEnabled( false );
778 buttonApply->setEnabled( false );
780 buttonOk->setEnabled( true );
781 buttonApply->setEnabled( true );
784 myEditCurrentArgument->setText( aString );
785 if (checkEditLine() == -1) {busy = false;return;}
794 if(anbNodes>2 || aNbFaces>1)
798 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
799 * Checking of indices in edit line.
800 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
801 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
803 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
805 QString aString = "";
806 SMDS_Mesh* aMesh = 0;
808 if(myMesh->_is_nil()) return 1;
810 myActor = SMESH::FindActorByObject(myMesh);
815 aMesh = myActor->GetObject()->GetMesh();
817 // checking for nodes
818 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
819 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
820 for ( int i = 0; i < aListId.count(); i++ ){
821 switch (GetConstructorId()){
823 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
825 SUIT_MessageBox::warning(this,
826 tr("SMESH_POLYEDRE_CREATE_ERROR"),
827 tr("The incorrect indices of nodes!"));
829 myEditCurrentArgument->clear();
830 myEditCurrentArgument->setText( aString );
837 bool aElemIsOK = true;
838 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
845 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
846 if (aType != SMDSAbs_Face){
851 SUIT_MessageBox::warning(this,
852 tr("SMESH_POLYEDRE_CREATE_ERROR"),
853 tr("The incorrect indices of faces!"));
855 myEditCurrentArgument->clear();
856 myEditCurrentArgument->setText( aString );
862 aString += aListId[ i ] + " ";
868 //=======================================================================
869 //function : displaySimulation
871 //=======================================================================
872 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
874 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
876 SMESH::TPolySimulation::TVTKIds aVTKIds;
877 vtkIdType aType = VTK_CONVEX_POINT_SET;
878 SMDS_Mesh* aMesh = 0;
880 aMesh = myActor->GetObject()->GetMesh();
882 if (GetConstructorId() == 0 && aMesh){
883 if (!AddButton->isEnabled()){
884 mySimulation->ResetGrid(true);
885 for (int i = 0; i < myFacesByNodes->count(); i++) {
886 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
887 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
888 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
889 const SMDS_MeshNode* aNode = aMesh->FindNode( (*it).toInt() );
890 if (!aNode) continue;
891 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() );
892 aVTKIds.push_back(aId);
893 aVTKIds_faces.push_back(aId);
895 if(!Preview->isChecked()){
897 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
900 if(myFacesByNodes->count() == 0){
901 mySimulation->SetVisibility(false);
903 mySimulation->SetVisibility(true);
905 if(Preview->isChecked()){
906 mySimulation->SetPosition(myActor, aType, aVTKIds);
909 // add ids from edit line
910 QStringList anEditIds = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
911 for ( int i = 0; i < anEditIds.count(); i++ )
912 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
914 mySimulation->SetPosition(myActor, aType, aVTKIds);
916 }else if(GetConstructorId() == 1 && aMesh){
917 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
918 for ( int i = 0; i < aListId.count(); i++ )
920 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
921 if ( !anElem ) continue;
922 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
923 if (aFaceType != SMDSAbs_Face) continue;
925 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
926 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
927 while( anIter->more() )
928 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
929 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() );
930 aVTKIds.push_back(aId);
931 aVTKIds_faces.push_back(aId);
933 if(!Preview->isChecked()){
935 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
938 if(Preview->isChecked())
939 mySimulation->SetPosition(myActor, aType, aVTKIds);
945 //=================================================================================
946 // function : SetEditCurrentArgument()
948 //=================================================================================
949 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
951 QPushButton* send = (QPushButton*)sender();
952 if(send == SelectElementsButton) {
953 LineEditElements->setFocus();
954 myEditCurrentArgument = LineEditElements;
956 SelectionIntoArgument();
959 //=================================================================================
960 // function : DeactivateActiveDialog()
962 //=================================================================================
963 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
965 if ( ConstructorsBox->isEnabled() ) {
966 ConstructorsBox->setEnabled(false);
967 GroupContent->setEnabled(false);
968 GroupButtons->setEnabled(false);
969 mySimulation->SetVisibility(false);
970 mySMESHGUI->ResetState();
971 mySMESHGUI->SetActiveDialogBox(0);
976 //=================================================================================
977 // function : ActivateThisDialog()
979 //=================================================================================
980 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
982 /* Emit a signal to deactivate the active dialog */
983 mySMESHGUI->EmitSignalDeactivateDialog();
984 ConstructorsBox->setEnabled(true);
985 GroupContent->setEnabled(true);
986 GroupButtons->setEnabled(true);
988 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
990 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
991 aViewWindow->SetSelectionMode( FaceSelection );
992 SelectionIntoArgument();
996 //=================================================================================
997 // function : enterEvent()
999 //=================================================================================
1000 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
1002 if ( ConstructorsBox->isEnabled() )
1004 ActivateThisDialog();
1008 //=================================================================================
1009 // function : closeEvent()
1011 //=================================================================================
1012 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
1014 /* same than click on cancel button */
1019 //=======================================================================
1020 //function : hideEvent
1021 //purpose : caused by ESC key
1022 //=======================================================================
1024 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
1026 if ( !isMinimized() )
1031 //=================================================================================
1032 // function : GetConstructorId()
1034 //=================================================================================
1035 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1037 return GroupConstructors->checkedId();
1040 //=================================================================================
1041 // function : onAdd()
1043 //=================================================================================
1044 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1046 SALOME_ListIO selected;
1047 mySelectionMgr->selectedObjects( selected );
1048 int aNbSel = selected.Extent();
1049 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1051 if (checkEditLine(false) == -1) return;
1054 if ( !(myEditCurrentArgument->text().isEmpty()) )
1056 myFacesByNodes->addItem(myEditCurrentArgument->text());
1057 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1059 myEditCurrentArgument->clear();
1060 AddButton->setEnabled(false);
1061 buttonOk->setEnabled( true );
1062 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1065 onListSelectionChanged();
1066 displaySimulation();
1069 //=================================================================================
1070 // function : onRemove()
1072 //=================================================================================
1073 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1076 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1077 QListWidgetItem* anItem;
1079 if ( selItems.count() > 0 ) myNbOkElements = 1;
1081 foreach( anItem, selItems )
1084 RemoveButton->setEnabled( myFacesByNodes->count() > 0 );
1085 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
1086 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
1089 displaySimulation();
1092 //=================================================================================
1093 // function : onListSelectionChanged()
1094 // purpose : Called when selection in element list is changed
1095 //=================================================================================
1096 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1098 if (busy || !myActor) return;
1101 SALOME_ListIO aList;
1102 mySelectionMgr->setSelectedObjects( aList );
1103 TColStd_MapOfInteger aIndexes;
1105 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1106 QListWidgetItem* anItem;
1107 foreach( anItem, selItems ) {
1108 QStringList anIds = anItem->text().split( " ", QString::SkipEmptyParts );
1109 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1110 aIndexes.Add((*it).toInt());
1112 RemoveButton->setEnabled(selItems.count() > 0);
1113 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1114 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1115 aViewWindow->highlight( myActor->getIO(), true, true );
1116 mySelectionMgr->clearFilters();
1117 aList.Append( myActor->getIO() );
1118 mySelectionMgr->setSelectedObjects( aList );
1123 //=================================================================================
1124 // function : keyPressEvent()
1126 //=================================================================================
1127 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1129 QDialog::keyPressEvent( e );
1130 if ( e->isAccepted() )
1133 if ( e->key() == Qt::Key_F1 ) {
1139 //=================================================================================
1140 // function : isValid
1142 //=================================================================================
1143 bool SMESHGUI_CreatePolyhedralVolumeDlg::isValid()
1145 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
1146 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );