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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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)
87 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
93 class TPolySimulation{
94 SVTK_ViewWindow* myViewWindow;
96 SALOME_Actor *myPreviewActor;
97 vtkDataSetMapper* myMapper;
98 vtkUnstructuredGrid* myGrid;
102 TPolySimulation(SalomeApp_Application* app)
104 SUIT_ViewManager* mgr = app->activeViewManager();
105 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
107 myGrid = vtkUnstructuredGrid::New();
109 // Create and display actor
110 myMapper = vtkDataSetMapper::New();
111 myMapper->SetInput( myGrid );
113 myPreviewActor = SALOME_Actor::New();
114 myPreviewActor->PickableOff();
115 myPreviewActor->VisibilityOff();
116 myPreviewActor->SetMapper( myMapper );
117 myPreviewActor->SetRepresentation( 3 );
119 vtkFloatingPointType anRGB[3];
120 vtkProperty* aProp = vtkProperty::New();
121 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
122 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
123 myPreviewActor->SetProperty( aProp );
124 vtkFloatingPointType aFactor,aUnits;
125 myPreviewActor->SetResolveCoincidentTopology(true);
126 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
127 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
130 myViewWindow->AddActor( myPreviewActor );
135 typedef std::vector<vtkIdType> TVTKIds;
136 void SetPosition(SMESH_Actor* theActor,
138 const TVTKIds& theIds,
141 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
142 myGrid->SetPoints(aGrid->GetPoints());
146 vtkIdList *anIds = vtkIdList::New();
148 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
149 anIds->InsertId(i,theIds[i]);
151 myGrid->InsertNextCell(theType,anIds);
152 if(theIds.size()!=0){
153 myGrid->InsertNextCell(theType,anIds);
163 void ResetGrid(bool theReset=true){
164 if (theReset) myGrid->Reset();
167 void SetVisibility(bool theVisibility){
168 myPreviewActor->SetVisibility(theVisibility);
169 RepaintCurrentView();
175 myViewWindow->RemoveActor(myPreviewActor);
177 myPreviewActor->Delete();
179 myMapper->RemoveAllInputs();
188 //=================================================================================
189 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
191 //=================================================================================
192 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule, const char* name,
193 bool modal, WFlags fl )
194 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
195 mySMESHGUI( theModule ),
196 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
198 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
201 setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
203 setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
204 setSizeGripEnabled( TRUE );
205 SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this );
206 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
207 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
209 /***************************************************************/
210 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
211 GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
212 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
213 GroupConstructors->setExclusive( TRUE );
214 GroupConstructors->setColumnLayout(0, Qt::Vertical );
215 GroupConstructors->layout()->setSpacing( 0 );
216 GroupConstructors->layout()->setMargin( 0 );
217 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
218 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
219 GroupConstructorsLayout->setSpacing( 6 );
220 GroupConstructorsLayout->setMargin( 11 );
221 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
222 RadioButton1->setText( tr( "MESH_NODE" ) );
223 GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
224 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
225 RadioButton2->setText( tr( "SMESH_FACE" ) );
226 GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
227 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
229 /***************************************************************/
230 GroupButtons = new QGroupBox( this, "GroupButtons" );
231 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
232 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
233 GroupButtons->setTitle( tr( "" ) );
234 GroupButtons->setColumnLayout(0, Qt::Vertical );
235 GroupButtons->layout()->setSpacing( 0 );
236 GroupButtons->layout()->setMargin( 0 );
237 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
238 GroupButtonsLayout->setAlignment( Qt::AlignTop );
239 GroupButtonsLayout->setSpacing( 6 );
240 GroupButtonsLayout->setMargin( 11 );
241 buttonCancel = new QPushButton( GroupButtons, "cancel" );
242 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
243 buttonCancel->setAutoDefault( TRUE );
244 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
245 buttonApply = new QPushButton( GroupButtons, "apply" );
246 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
247 buttonApply->setAutoDefault( TRUE );
248 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
249 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
250 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
251 buttonOk = new QPushButton( GroupButtons, "ok" );
252 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
253 buttonOk->setAutoDefault( TRUE );
254 buttonOk->setDefault( TRUE );
255 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
256 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
257 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
258 buttonHelp->setAutoDefault(TRUE);
259 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
261 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
263 /***************************************************************/
264 GroupContent = new QGroupBox( this, "GroupContent" );
265 GroupContent->setTitle( tr( "SMESH_CONTENT" ) );
266 GroupContent->setColumnLayout(0, Qt::Vertical );
267 GroupContent->layout()->setSpacing( 0 );
268 GroupContent->layout()->setMargin( 0 );
269 GroupContentLayout = new QGridLayout( GroupContent->layout() );
270 GroupContentLayout->setAlignment( Qt::AlignTop );
271 GroupContentLayout->setSpacing( 6 );
272 GroupContentLayout->setMargin( 11 );
274 QFrame* anIds = new QFrame(GroupContent, "anIds");
275 QGridLayout* aLayout = new QGridLayout(anIds, 1, 3);
276 aLayout->setSpacing(6);
277 aLayout->setAutoAdd(false);
279 TextLabelIds = new QLabel( anIds, "TextLabelIds" );
280 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
281 TextLabelIds->setFixedWidth(74);
282 aLayout->addWidget( TextLabelIds, 0, 0 );
284 SelectElementsButton = new QPushButton( anIds, "SelectElementsButton" );
285 SelectElementsButton->setText( tr( "" ) );
286 SelectElementsButton->setPixmap( image0 );
287 SelectElementsButton->setToggleButton( FALSE );
288 aLayout->addWidget( SelectElementsButton, 0, 1 );
290 LineEditElements = new QLineEdit( anIds, "LineEditElements" );
291 LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
292 aLayout->addWidget( LineEditElements, 0, 2 );
294 GroupContentLayout->addMultiCellWidget(anIds, 0, 0, 0, 1);
296 myFacesByNodesLabel = new QLabel(GroupContent, "faces by nodes label");
297 myFacesByNodesLabel->setText(tr("FACES_BY_NODES"));
298 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
300 myFacesByNodes = new QListBox(GroupContent, "faces by nodes list");
301 myFacesByNodes->setSelectionMode(QListBox::Extended);
302 myFacesByNodes->setMinimumHeight(150);
303 GroupContentLayout->addMultiCellWidget( myFacesByNodes, 2, 4, 0, 0 );
305 AddButton = new QPushButton(GroupContent, "add");
306 AddButton->setText(tr("SMESH_BUT_ADD"));
307 AddButton->setMaximumWidth(85);
308 GroupContentLayout->addWidget( AddButton, 2, 1 );
310 RemoveButton = new QPushButton(GroupContent, "remove");
311 RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
312 RemoveButton->setMaximumWidth(85);
313 GroupContentLayout->addWidget( RemoveButton, 3, 1 );
315 Preview = new QCheckBox( GroupContent, "Preview" );
316 Preview->setText( tr( "SMESH_POLYEDRE_PREVIEW" ) );
317 GroupContentLayout->addWidget( Preview , 5, 0 );
319 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
321 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
323 GroupContent->show();
324 RadioButton1->setChecked( TRUE );
326 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
328 myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_polyhedrons";
333 //=================================================================================
334 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
335 // purpose : Destroys the object and frees any allocated resources
336 //=================================================================================
337 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
339 // no need to delete child widgets, Qt does it all for us
343 static bool busy = false;
344 //=================================================================================
347 //=================================================================================
348 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
350 myEditCurrentArgument = LineEditElements;
351 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
356 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
358 /* signals and slots connections */
359 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
360 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
361 connect(buttonApply, SIGNAL( clicked() ), SLOT(ClickOnApply() ) );
362 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp() ) );
364 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
365 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
366 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
368 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
369 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
370 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
372 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
373 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
374 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
375 /* to close dialog if study change */
376 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
378 this->show() ; /* displays Dialog */
380 ConstructorsClicked(0);
381 SelectionIntoArgument();
385 //=================================================================================
386 // function : ConstructorsClicked()
387 // purpose : Radio button management
388 //=================================================================================
389 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
391 //disconnect(mySelectionMgr, 0, this, 0);
394 mySelectionMgr->selectedObjects( io );
396 mySelectionMgr->setSelectedObjects( aList );
397 myEditCurrentArgument->clear();
399 buttonApply->setEnabled(false);
400 buttonOk->setEnabled(false);
401 mySimulation->SetVisibility(false);
403 switch(constructorId)
408 myActor->SetPointRepresentation(true);
411 SMESH::SetPointRepresentation(true);
412 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
413 aViewWindow->SetSelectionMode(NodeSelection);
415 AddButton->setEnabled(false);
416 RemoveButton->setEnabled(false);
417 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
418 myFacesByNodesLabel->show();
419 myFacesByNodes->clear();
420 myFacesByNodes->show();
422 RemoveButton->show();
429 myActor->SetPointRepresentation(false);
431 SMESH::SetPointRepresentation(false);
433 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
434 aViewWindow->SetSelectionMode(FaceSelection);
436 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
437 myFacesByNodesLabel->hide();
438 myFacesByNodes->hide();
440 RemoveButton->hide();
446 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
447 mySelectionMgr->setSelectedObjects( io );
450 //=================================================================================
451 // function : ClickOnPreview()
453 //=================================================================================
454 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
455 Preview->setChecked(theToggled);
459 //=================================================================================
460 // function : ClickOnApply()
462 //=================================================================================
463 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
465 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
467 if(checkEditLine(false) == -1) {return;}
469 if (GetConstructorId() == 0)
471 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
472 SMESH::long_array_var aQuantities = new SMESH::long_array;
474 aQuantities->length( myFacesByNodes->count() );
476 TColStd_ListOfInteger aNodesIds;
478 QListBoxItem* anItem;
479 int aNbQuantities = 0;
480 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
481 QStringList anIds = QStringList::split(" ", anItem->text());
482 int aNbNodesInFace = 0;
483 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
484 aNodesIds.Append( (*it).toInt() );
486 aQuantities[aNbQuantities++] = aNbNodesInFace;
489 anIdsOfNodes->length(aNodesIds.Extent());
491 int aNbIdsOfNodes = 0;
492 TColStd_ListIteratorOfListOfInteger It;
493 It.Initialize(aNodesIds);
494 for(;It.More();It.Next())
495 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
498 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
499 QApplication::setOverrideCursor(Qt::waitCursor);
500 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
501 QApplication::restoreOverrideCursor();
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 !!!");
510 else if (GetConstructorId() == 1)
512 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
514 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
515 anIdsOfFaces->length(aListId.count());
516 for ( int i = 0; i < aListId.count(); i++ )
517 anIdsOfFaces[i] = aListId[i].toInt();
520 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
521 QApplication::setOverrideCursor(Qt::waitCursor);
522 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
523 QApplication::restoreOverrideCursor();
524 }catch(SALOME::SALOME_Exception& exc){
525 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
526 }catch(std::exception& exc){
527 INFOS("Follow exception was cought:\n\t"<<exc.what());
529 INFOS("Unknown exception was cought !!!");
533 //SALOME_ListIO aList;
534 //mySelectionMgr->setSelectedObjects( aList );
537 unsigned int anEntityMode = myActor->GetEntityMode();
538 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
540 //ConstructorsClicked( GetConstructorId() );
545 //=================================================================================
546 // function : ClickOnOk()
548 //=================================================================================
549 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
551 if(checkEditLine(false) == -1) {return;}
557 //=================================================================================
558 // function : ClickOnCancel()
560 //=================================================================================
561 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
563 mySelectionMgr->clearFilters();
564 //SALOME_ListIO aList;
565 //mySelectionMgr->setSelectedObjects( aList );
566 SMESH::SetPointRepresentation(false);
567 mySimulation->SetVisibility(false);
568 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
569 aViewWindow->SetSelectionMode( ActorSelection );
570 disconnect( mySelectionMgr, 0, this, 0 );
571 mySMESHGUI->ResetState() ;
575 //=================================================================================
576 // function : ClickOnHelp()
578 //=================================================================================
579 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
581 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
583 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
587 platform = "winapplication";
589 platform = "application";
591 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
592 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
593 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
594 QObject::tr("BUT_OK"));
598 //=======================================================================
599 //function : onTextChange
601 //=======================================================================
603 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
606 if (checkEditLine() == -1) return;
609 mySimulation->SetVisibility(false);
611 SMDS_Mesh* aMesh = 0;
613 aMesh = myActor->GetObject()->GetMesh();
615 if (GetConstructorId() == 0)
618 TColStd_MapOfInteger newIndices;
620 QStringList aListId = QStringList::split( " ", theNewText, false);
621 for ( int i = 0; i < aListId.count(); i++ ) {
622 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
624 newIndices.Add(n->GetID());
629 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
631 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
632 aViewWindow->highlight( myActor->getIO(), true, true );
634 if ( myNbOkElements>0 && aListId.count()>=3)
635 AddButton->setEnabled(true);
637 AddButton->setEnabled(false);
641 } else if (GetConstructorId() == 1)
644 buttonOk->setEnabled( false );
645 buttonApply->setEnabled( false );
647 // check entered ids of faces and hilight them
650 TColStd_MapOfInteger newIndices;
652 aListId = QStringList::split( " ", theNewText, false);
654 for ( int i = 0; i < aListId.count(); i++ ) {
655 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
657 newIndices.Add(e->GetID());
662 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
663 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
664 aViewWindow->highlight( myActor->getIO(), true, true );
666 if ( myNbOkElements ) {
667 if (aListId.count()>1){
668 buttonOk->setEnabled( true );
669 buttonApply->setEnabled( true );
672 buttonOk->setEnabled( false );
673 buttonApply->setEnabled( false );
675 if(aListId.count()>1)
683 //=================================================================================
684 // function : SelectionIntoArgument()
685 // purpose : Called when selection as changed or other case
686 //=================================================================================
687 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
693 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
696 AddButton->setEnabled(false);
697 buttonOk->setEnabled( false );
698 buttonApply->setEnabled( false );
704 myEditCurrentArgument->setText( "" );
706 if ( !GroupButtons->isEnabled() ) // inactive
709 mySimulation->SetVisibility(false);
713 SALOME_ListIO selected;
714 mySelectionMgr->selectedObjects( selected );
715 int nbSel = selected.Extent();
720 myMesh = SMESH::GetMeshByIO( selected.First() );
721 if ( myMesh->_is_nil() )
724 myActor = SMESH::FindActorByObject(myMesh);
728 // get selected nodes/faces
729 QString aString = "";
730 int anbNodes=0,aNbFaces=0;
731 switch(GetConstructorId()){
733 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
735 AddButton->setEnabled(true);
736 else if (anbNodes < 3){
737 AddButton->setEnabled(false);
740 myEditCurrentArgument->setText( aString );
741 if (checkEditLine() == -1) {busy = false;return;}
746 // get selected faces
747 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
749 buttonOk->setEnabled( false );
750 buttonApply->setEnabled( false );
752 buttonOk->setEnabled( true );
753 buttonApply->setEnabled( true );
756 myEditCurrentArgument->setText( aString );
757 if (checkEditLine() == -1) {busy = false;return;}
766 if(anbNodes>2 || aNbFaces>1)
770 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
771 * Checking of indices in edit line.
772 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
773 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
775 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
777 QString aString = "";
778 SMDS_Mesh* aMesh = 0;
780 if(myMesh->_is_nil()) return 1;
782 myActor = SMESH::FindActorByObject(myMesh);
787 aMesh = myActor->GetObject()->GetMesh();
789 // checking for nodes
790 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
791 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
792 for ( int i = 0; i < aListId.count(); i++ ){
793 switch (GetConstructorId()){
795 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
797 std::string aWarning;
798 aWarning = "The incorrect indices of nodes!";
799 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
800 QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
801 QObject::tr(aWarning.c_str()),
802 QObject::tr("SMESH_BUT_OK"));
804 myEditCurrentArgument->clear();
805 myEditCurrentArgument->setText( aString );
812 bool aElemIsOK = true;
813 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
820 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
821 if (aType != SMDSAbs_Face){
826 std::string aWarning;
827 aWarning = "The incorrect indices of faces!";
828 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
829 QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
830 QObject::tr(aWarning.c_str()),
831 QObject::tr("SMESH_BUT_OK"));
833 myEditCurrentArgument->clear();
834 myEditCurrentArgument->setText( aString );
840 aString += aListId[ i ] + " ";
846 //=======================================================================
847 //function : displaySimulation
849 //=======================================================================
850 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
852 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
854 SMESH::TPolySimulation::TVTKIds aVTKIds;
855 vtkIdType aType = VTK_CONVEX_POINT_SET ;
856 SMDS_Mesh* aMesh = 0;
858 aMesh = myActor->GetObject()->GetMesh();
860 if (GetConstructorId() == 0 && aMesh){
861 if (!AddButton->isEnabled()){
862 QListBoxItem* anItem;
863 mySimulation->ResetGrid(true);
864 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
865 QStringList anIds = QStringList::split(" ", anItem->text());
866 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
867 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
868 const SMDS_MeshNode * aNode = aMesh->FindNode( (*it).toInt() );
869 if (!aNode) continue;
870 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
871 aVTKIds.push_back(aId);
872 aVTKIds_faces.push_back(aId);
874 if(!Preview->isChecked()){
876 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
879 if(myFacesByNodes->count() == 0){
880 mySimulation->SetVisibility(false);
882 mySimulation->SetVisibility(true);
884 if(Preview->isChecked()){
885 mySimulation->SetPosition(myActor, aType, aVTKIds);
888 // add ids from edit line
889 QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
890 for ( int i = 0; i < anEditIds.count(); i++ )
891 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
893 mySimulation->SetPosition(myActor, aType, aVTKIds);
895 }else if(GetConstructorId() == 1 && aMesh){
896 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
897 for ( int i = 0; i < aListId.count(); i++ )
899 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
900 if ( !anElem ) continue;
901 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
902 if (aFaceType != SMDSAbs_Face) continue;
904 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
905 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
906 while( anIter->more() )
907 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
908 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
909 aVTKIds.push_back(aId);
910 aVTKIds_faces.push_back(aId);
912 if(!Preview->isChecked()){
914 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
917 if(Preview->isChecked())
918 mySimulation->SetPosition(myActor, aType, aVTKIds);
924 //=================================================================================
925 // function : SetEditCurrentArgument()
927 //=================================================================================
928 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
930 QPushButton* send = (QPushButton*)sender();
931 if(send == SelectElementsButton) {
932 LineEditElements->setFocus() ;
933 myEditCurrentArgument = LineEditElements;
935 SelectionIntoArgument();
938 //=================================================================================
939 // function : DeactivateActiveDialog()
941 //=================================================================================
942 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
944 if ( GroupConstructors->isEnabled() ) {
945 GroupConstructors->setEnabled(false) ;
946 GroupContent->setEnabled(false) ;
947 GroupButtons->setEnabled(false) ;
948 mySimulation->SetVisibility(false);
949 mySMESHGUI->ResetState() ;
950 mySMESHGUI->SetActiveDialogBox(0) ;
955 //=================================================================================
956 // function : ActivateThisDialog()
958 //=================================================================================
959 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
961 /* Emit a signal to deactivate the active dialog */
962 mySMESHGUI->EmitSignalDeactivateDialog() ;
963 GroupConstructors->setEnabled(true) ;
964 GroupContent->setEnabled(true) ;
965 GroupButtons->setEnabled(true) ;
967 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
969 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
970 aViewWindow->SetSelectionMode( FaceSelection );
971 SelectionIntoArgument();
975 //=================================================================================
976 // function : enterEvent()
978 //=================================================================================
979 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
981 if ( GroupConstructors->isEnabled() )
983 ActivateThisDialog() ;
987 //=================================================================================
988 // function : closeEvent()
990 //=================================================================================
991 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
993 /* same than click on cancel button */
994 this->ClickOnCancel() ;
998 //=======================================================================
999 //function : hideEvent
1000 //purpose : caused by ESC key
1001 //=======================================================================
1003 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
1005 if ( !isMinimized() )
1010 //=================================================================================
1011 // function : GetConstructorId()
1013 //=================================================================================
1014 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1016 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
1017 return GroupConstructors->id( GroupConstructors->selected() );
1021 //=================================================================================
1022 // function : onAdd()
1024 //=================================================================================
1025 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1027 SALOME_ListIO selected;
1028 mySelectionMgr->selectedObjects( selected );
1029 int aNbSel = selected.Extent();
1030 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1032 if (this->checkEditLine(false) == -1) return;
1035 if ( !(myEditCurrentArgument->text().isEmpty()) )
1037 myFacesByNodes->insertItem(myEditCurrentArgument->text());
1038 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1040 myEditCurrentArgument->clear();
1041 AddButton->setEnabled(false);
1042 buttonOk->setEnabled( true );
1043 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1046 onListSelectionChanged();
1047 displaySimulation();
1050 //=================================================================================
1051 // function : onRemove()
1053 //=================================================================================
1054 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1057 for (int i = myFacesByNodes->count(); i > 0; i--) {
1058 if (myFacesByNodes->isSelected(i-1)) {
1059 myFacesByNodes->removeItem(i-1);
1063 if (myFacesByNodes->count() < 1){
1064 RemoveButton->setEnabled(false);
1065 buttonOk->setEnabled( false );
1066 buttonApply->setEnabled( false );
1068 else if (myFacesByNodes->count() == 1){
1069 buttonOk->setEnabled( false );
1070 buttonApply->setEnabled( false );
1073 displaySimulation();
1076 //=================================================================================
1077 // function : onListSelectionChanged()
1078 // purpose : Called when selection in element list is changed
1079 //=================================================================================
1080 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1082 if (busy || !myActor) return;
1084 bool isSelected=false;
1085 SALOME_ListIO aList;
1086 mySelectionMgr->setSelectedObjects( aList );
1087 TColStd_MapOfInteger aIndexes;
1088 QListBoxItem* anItem;
1089 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
1090 if (anItem->isSelected()) {
1092 QStringList anIds = QStringList::split(" ", anItem->text());
1093 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1094 aIndexes.Add((*it).toInt());
1097 if(isSelected) RemoveButton->setEnabled(true);
1098 else RemoveButton->setEnabled(false);
1099 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1100 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1101 aViewWindow->highlight( myActor->getIO(), true, true );
1102 mySelectionMgr->clearFilters();
1103 aList.Append( myActor->getIO() );
1104 mySelectionMgr->setSelectedObjects( aList );
1109 //=================================================================================
1110 // function : keyPressEvent()
1112 //=================================================================================
1113 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1115 QDialog::keyPressEvent( e );
1116 if ( e->isAccepted() )
1119 if ( e->key() == Key_F1 )