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_IdValidator.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37 #include <SMDS_Mesh.hxx>
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_ViewManager.h>
45 #include <SUIT_OverrideCursor.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewWindow.h>
53 #include <TColStd_ListOfInteger.hxx>
54 #include <TColStd_ListIteratorOfListOfInteger.hxx>
58 #include <vtkIdList.h>
59 #include <vtkUnstructuredGrid.h>
60 #include <vtkDataSetMapper.h>
61 #include <vtkProperty.h>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
75 #include <QListWidget>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
89 SVTK_ViewWindow* myViewWindow;
91 SALOME_Actor *myPreviewActor;
92 vtkDataSetMapper* myMapper;
93 vtkUnstructuredGrid* myGrid;
97 TPolySimulation(SalomeApp_Application* app)
99 SUIT_ViewManager* mgr = app->activeViewManager();
100 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
102 myGrid = vtkUnstructuredGrid::New();
104 // Create and display actor
105 myMapper = vtkDataSetMapper::New();
106 myMapper->SetInput( myGrid );
108 myPreviewActor = SALOME_Actor::New();
109 myPreviewActor->PickableOff();
110 myPreviewActor->VisibilityOff();
111 myPreviewActor->SetMapper( myMapper );
112 myPreviewActor->SetRepresentation( 3 );
114 vtkFloatingPointType anRGB[3];
115 vtkProperty* aProp = vtkProperty::New();
116 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
117 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
118 myPreviewActor->SetProperty( aProp );
119 vtkFloatingPointType aFactor,aUnits;
120 myPreviewActor->SetResolveCoincidentTopology(true);
121 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
122 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
125 myViewWindow->AddActor( myPreviewActor );
130 typedef std::vector<vtkIdType> TVTKIds;
131 void SetPosition(SMESH_Actor* theActor,
133 const TVTKIds& theIds,
136 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
137 myGrid->SetPoints(aGrid->GetPoints());
141 vtkIdList *anIds = vtkIdList::New();
143 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
144 anIds->InsertId(i,theIds[i]);
146 myGrid->InsertNextCell(theType,anIds);
147 if(theIds.size()!=0){
148 myGrid->InsertNextCell(theType,anIds);
158 void ResetGrid(bool theReset=true){
159 if (theReset) myGrid->Reset();
162 void SetVisibility(bool theVisibility){
163 myPreviewActor->SetVisibility(theVisibility);
164 RepaintCurrentView();
170 myViewWindow->RemoveActor(myPreviewActor);
172 myPreviewActor->Delete();
174 myMapper->RemoveAllInputs();
183 //=================================================================================
184 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
186 //=================================================================================
187 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule )
188 : QDialog( SMESH::GetDesktop( theModule ) ),
189 mySMESHGUI( theModule ),
190 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
192 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
195 setAttribute(Qt::WA_DeleteOnClose, true);
196 setWindowTitle( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
197 setSizeGripEnabled( true );
199 QVBoxLayout* topLayout = new QVBoxLayout( this );
200 topLayout->setSpacing( SPACING );
201 topLayout->setMargin( MARGIN );
203 /***************************************************************/
204 ConstructorsBox = new QGroupBox(tr( "SMESH_ELEMENTS_TYPE" ), this);
205 GroupConstructors = new QButtonGroup(this);
206 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout( ConstructorsBox );
207 ConstructorsBoxLayout->setSpacing( SPACING );
208 ConstructorsBoxLayout->setMargin( MARGIN );
210 RadioButton1 = new QRadioButton( tr( "MESH_NODE" ), ConstructorsBox );
211 RadioButton2 = new QRadioButton( tr( "SMESH_FACE" ), ConstructorsBox );
213 ConstructorsBoxLayout->addWidget( RadioButton1 );
214 ConstructorsBoxLayout->addWidget( RadioButton2 );
215 GroupConstructors->addButton(RadioButton1, 0);
216 GroupConstructors->addButton(RadioButton2, 1);
218 /***************************************************************/
219 GroupContent = new QGroupBox( tr( "SMESH_CONTENT" ), this );
220 QGridLayout* GroupContentLayout = new QGridLayout( GroupContent );
221 GroupContentLayout->setSpacing( SPACING );
222 GroupContentLayout->setMargin( MARGIN );
224 TextLabelIds = new QLabel( tr( "SMESH_ID_NODES" ), GroupContent );
225 SelectElementsButton = new QPushButton( GroupContent );
226 SelectElementsButton->setIcon( image0 );
227 LineEditElements = new QLineEdit( GroupContent );
228 LineEditElements->setValidator( new SMESHGUI_IdValidator( this ) );
230 myFacesByNodesLabel = new QLabel( tr( "FACES_BY_NODES" ), GroupContent );
231 myFacesByNodes = new QListWidget( GroupContent);
232 myFacesByNodes->setSelectionMode( QListWidget::ExtendedSelection );
233 myFacesByNodes->setMinimumHeight( 150);
235 AddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), GroupContent );
236 RemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), GroupContent );
238 Preview = new QCheckBox( tr( "SMESH_POLYEDRE_PREVIEW" ), GroupContent );
240 GroupContentLayout->addWidget( TextLabelIds, 0, 0 );
241 GroupContentLayout->addWidget( SelectElementsButton, 0, 1 );
242 GroupContentLayout->addWidget( LineEditElements, 0, 2, 1, 2 );
243 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
244 GroupContentLayout->addWidget( myFacesByNodes, 2, 0, 3, 3 );
245 GroupContentLayout->addWidget( AddButton, 2, 3 );
246 GroupContentLayout->addWidget( RemoveButton, 3, 3 );
247 GroupContentLayout->addWidget( Preview, 5, 0, 1, 4 );
249 /***************************************************************/
250 GroupButtons = new QGroupBox( this );
251 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
252 GroupButtonsLayout->setSpacing( SPACING );
253 GroupButtonsLayout->setMargin( MARGIN );
255 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
256 buttonOk->setAutoDefault( true );
257 buttonOk->setDefault( true );
258 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
259 buttonApply->setAutoDefault( true );
260 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
261 buttonCancel->setAutoDefault( true );
262 buttonHelp = new QPushButton( tr("SMESH_BUT_HELP" ), GroupButtons );
263 buttonHelp->setAutoDefault(true);
265 GroupButtonsLayout->addWidget( buttonOk );
266 GroupButtonsLayout->addSpacing( 10 );
267 GroupButtonsLayout->addWidget( buttonApply );
268 GroupButtonsLayout->addSpacing( 10 );
269 GroupButtonsLayout->addStretch();
270 GroupButtonsLayout->addWidget( buttonCancel );
271 GroupButtonsLayout->addWidget( buttonHelp);
273 /***************************************************************/
274 topLayout->addWidget( ConstructorsBox );
275 topLayout->addWidget( GroupContent );
276 topLayout->addWidget( GroupButtons );
278 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
280 RadioButton1->setChecked( true );
282 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
284 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
289 //=================================================================================
290 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
291 // purpose : Destroys the object and frees any allocated resources
292 //=================================================================================
293 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
298 static bool busy = false;
300 //=================================================================================
303 //=================================================================================
304 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
306 myEditCurrentArgument = LineEditElements;
307 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
312 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
314 /* signals and slots connections */
315 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
316 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) );
317 connect(buttonApply, SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
318 connect(buttonHelp, SIGNAL( clicked() ), SLOT( ClickOnHelp() ) );
320 connect(GroupConstructors, SIGNAL(buttonClicked(int) ), SLOT( ConstructorsClicked(int) ) );
321 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) );
322 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
324 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
325 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
326 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
328 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
329 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
330 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
331 /* to close dialog if study change */
332 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
334 ConstructorsClicked(0);
335 SelectionIntoArgument();
339 //=================================================================================
340 // function : ConstructorsClicked()
341 // purpose : Radio button management
342 //=================================================================================
343 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
345 //disconnect(mySelectionMgr, 0, this, 0);
348 mySelectionMgr->selectedObjects( io );
350 mySelectionMgr->setSelectedObjects( aList );
351 myEditCurrentArgument->clear();
353 buttonApply->setEnabled(false);
354 buttonOk->setEnabled(false);
355 mySimulation->SetVisibility(false);
357 switch(constructorId)
362 myActor->SetPointRepresentation(true);
365 SMESH::SetPointRepresentation(true);
366 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
367 aViewWindow->SetSelectionMode(NodeSelection);
369 AddButton->setEnabled(false);
370 RemoveButton->setEnabled(false);
371 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
372 myFacesByNodesLabel->show();
373 myFacesByNodes->clear();
374 myFacesByNodes->show();
376 RemoveButton->show();
383 myActor->SetPointRepresentation(false);
385 SMESH::SetPointRepresentation(false);
387 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
388 aViewWindow->SetSelectionMode(FaceSelection);
390 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
391 myFacesByNodesLabel->hide();
392 myFacesByNodes->hide();
394 RemoveButton->hide();
400 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
401 mySelectionMgr->setSelectedObjects( io );
403 QApplication::instance()->processEvents();
408 //=================================================================================
409 // function : ClickOnPreview()
411 //=================================================================================
412 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
413 Preview->setChecked(theToggled);
417 //=================================================================================
418 // function : ClickOnApply()
420 //=================================================================================
421 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
423 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
425 if(checkEditLine(false) == -1) {return;}
427 if (GetConstructorId() == 0)
429 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
430 SMESH::long_array_var aQuantities = new SMESH::long_array;
432 aQuantities->length( myFacesByNodes->count() );
434 TColStd_ListOfInteger aNodesIds;
436 int aNbQuantities = 0;
437 for (int i = 0; i < myFacesByNodes->count(); i++ ) {
438 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
439 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
440 aNodesIds.Append( (*it).toInt() );
442 aQuantities[aNbQuantities++] = anIds.count();
445 anIdsOfNodes->length(aNodesIds.Extent());
447 int aNbIdsOfNodes = 0;
448 TColStd_ListIteratorOfListOfInteger It;
449 It.Initialize(aNodesIds);
450 for( ;It.More();It.Next())
451 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
454 SUIT_OverrideCursor aWaitCursor;
455 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
456 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
457 }catch(SALOME::SALOME_Exception& exc){
458 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
459 }catch(std::exception& exc){
460 INFOS("Follow exception was cought:\n\t"<<exc.what());
462 INFOS("Unknown exception was cought !!!");
465 else if (GetConstructorId() == 1)
467 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
469 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
470 anIdsOfFaces->length(aListId.count());
471 for ( int i = 0; i < aListId.count(); i++ )
472 anIdsOfFaces[i] = aListId[i].toInt();
475 SUIT_OverrideCursor aWaitCursor;
476 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
477 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
478 }catch(SALOME::SALOME_Exception& exc){
479 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
480 }catch(std::exception& exc){
481 INFOS("Follow exception was cought:\n\t"<<exc.what());
483 INFOS("Unknown exception was cought !!!");
487 //SALOME_ListIO aList;
488 //mySelectionMgr->setSelectedObjects( aList );
491 unsigned int anEntityMode = myActor->GetEntityMode();
492 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
494 //ConstructorsClicked( GetConstructorId() );
499 //=================================================================================
500 // function : ClickOnOk()
502 //=================================================================================
503 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
505 if(checkEditLine(false) == -1) {return;}
511 //=================================================================================
512 // function : ClickOnCancel()
514 //=================================================================================
515 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
517 mySelectionMgr->clearFilters();
518 //SALOME_ListIO aList;
519 //mySelectionMgr->setSelectedObjects( aList );
520 SMESH::SetPointRepresentation(false);
521 mySimulation->SetVisibility(false);
522 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
523 aViewWindow->SetSelectionMode( ActorSelection );
524 disconnect( mySelectionMgr, 0, this, 0 );
525 mySMESHGUI->ResetState();
529 //=================================================================================
530 // function : ClickOnHelp()
532 //=================================================================================
533 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
535 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
537 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
541 platform = "winapplication";
543 platform = "application";
545 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
546 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
547 arg(app->resourceMgr()->stringValue("ExternalBrowser",
549 arg(myHelpFileName));
553 //=======================================================================
554 //function : onTextChange
556 //=======================================================================
558 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
561 if (checkEditLine() == -1) return;
564 mySimulation->SetVisibility(false);
566 SMDS_Mesh* aMesh = 0;
568 aMesh = myActor->GetObject()->GetMesh();
570 if (GetConstructorId() == 0)
573 TColStd_MapOfInteger newIndices;
575 QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts );
576 for ( int i = 0; i < aListId.count(); i++ ) {
577 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
579 newIndices.Add(n->GetID());
584 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
586 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
587 aViewWindow->highlight( myActor->getIO(), true, true );
589 if ( myNbOkElements>0 && aListId.count()>=3)
590 AddButton->setEnabled(true);
592 AddButton->setEnabled(false);
596 } else if (GetConstructorId() == 1)
599 buttonOk->setEnabled( false );
600 buttonApply->setEnabled( false );
602 // check entered ids of faces and hilight them
605 TColStd_MapOfInteger newIndices;
607 aListId = theNewText.split( " ", QString::SkipEmptyParts );
609 for ( int i = 0; i < aListId.count(); i++ ) {
610 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
612 newIndices.Add(e->GetID());
617 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
618 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
619 aViewWindow->highlight( myActor->getIO(), true, true );
621 if ( myNbOkElements ) {
622 if (aListId.count()>1){
623 buttonOk->setEnabled( true );
624 buttonApply->setEnabled( true );
627 buttonOk->setEnabled( false );
628 buttonApply->setEnabled( false );
630 if(aListId.count()>1)
638 //=================================================================================
639 // function : SelectionIntoArgument()
640 // purpose : Called when selection as changed or other case
641 //=================================================================================
642 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
648 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
651 AddButton->setEnabled(false);
652 buttonOk->setEnabled( false );
653 buttonApply->setEnabled( false );
659 myEditCurrentArgument->setText( "" );
661 if ( !GroupButtons->isEnabled() ) // inactive
664 mySimulation->SetVisibility(false);
668 SALOME_ListIO selected;
669 mySelectionMgr->selectedObjects( selected );
670 int nbSel = selected.Extent();
675 myMesh = SMESH::GetMeshByIO( selected.First() );
676 if ( myMesh->_is_nil() )
679 myActor = SMESH::FindActorByObject(myMesh);
683 // get selected nodes/faces
684 QString aString = "";
685 int anbNodes=0,aNbFaces=0;
686 switch(GetConstructorId()){
688 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
690 AddButton->setEnabled(true);
691 else if (anbNodes < 3){
692 AddButton->setEnabled(false);
695 myEditCurrentArgument->setText( aString );
696 if (checkEditLine() == -1) {busy = false;return;}
701 // get selected faces
702 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
704 buttonOk->setEnabled( false );
705 buttonApply->setEnabled( false );
707 buttonOk->setEnabled( true );
708 buttonApply->setEnabled( true );
711 myEditCurrentArgument->setText( aString );
712 if (checkEditLine() == -1) {busy = false;return;}
721 if(anbNodes>2 || aNbFaces>1)
725 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
726 * Checking of indices in edit line.
727 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
728 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
730 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
732 QString aString = "";
733 SMDS_Mesh* aMesh = 0;
735 if(myMesh->_is_nil()) return 1;
737 myActor = SMESH::FindActorByObject(myMesh);
742 aMesh = myActor->GetObject()->GetMesh();
744 // checking for nodes
745 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
746 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
747 for ( int i = 0; i < aListId.count(); i++ ){
748 switch (GetConstructorId()){
750 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
752 SUIT_MessageBox::warning(this,
753 tr("SMESH_POLYEDRE_CREATE_ERROR"),
754 tr("The incorrect indices of nodes!"));
756 myEditCurrentArgument->clear();
757 myEditCurrentArgument->setText( aString );
764 bool aElemIsOK = true;
765 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
772 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
773 if (aType != SMDSAbs_Face){
778 SUIT_MessageBox::warning(this,
779 tr("SMESH_POLYEDRE_CREATE_ERROR"),
780 tr("The incorrect indices of faces!"));
782 myEditCurrentArgument->clear();
783 myEditCurrentArgument->setText( aString );
789 aString += aListId[ i ] + " ";
795 //=======================================================================
796 //function : displaySimulation
798 //=======================================================================
799 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
801 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
803 SMESH::TPolySimulation::TVTKIds aVTKIds;
804 vtkIdType aType = VTK_CONVEX_POINT_SET;
805 SMDS_Mesh* aMesh = 0;
807 aMesh = myActor->GetObject()->GetMesh();
809 if (GetConstructorId() == 0 && aMesh){
810 if (!AddButton->isEnabled()){
811 mySimulation->ResetGrid(true);
812 for (int i = 0; i < myFacesByNodes->count(); i++) {
813 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
814 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
815 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
816 const SMDS_MeshNode* aNode = aMesh->FindNode( (*it).toInt() );
817 if (!aNode) continue;
818 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() );
819 aVTKIds.push_back(aId);
820 aVTKIds_faces.push_back(aId);
822 if(!Preview->isChecked()){
824 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
827 if(myFacesByNodes->count() == 0){
828 mySimulation->SetVisibility(false);
830 mySimulation->SetVisibility(true);
832 if(Preview->isChecked()){
833 mySimulation->SetPosition(myActor, aType, aVTKIds);
836 // add ids from edit line
837 QStringList anEditIds = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
838 for ( int i = 0; i < anEditIds.count(); i++ )
839 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
841 mySimulation->SetPosition(myActor, aType, aVTKIds);
843 }else if(GetConstructorId() == 1 && aMesh){
844 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
845 for ( int i = 0; i < aListId.count(); i++ )
847 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
848 if ( !anElem ) continue;
849 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
850 if (aFaceType != SMDSAbs_Face) continue;
852 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
853 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
854 while( anIter->more() )
855 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
856 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() );
857 aVTKIds.push_back(aId);
858 aVTKIds_faces.push_back(aId);
860 if(!Preview->isChecked()){
862 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
865 if(Preview->isChecked())
866 mySimulation->SetPosition(myActor, aType, aVTKIds);
872 //=================================================================================
873 // function : SetEditCurrentArgument()
875 //=================================================================================
876 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
878 QPushButton* send = (QPushButton*)sender();
879 if(send == SelectElementsButton) {
880 LineEditElements->setFocus();
881 myEditCurrentArgument = LineEditElements;
883 SelectionIntoArgument();
886 //=================================================================================
887 // function : DeactivateActiveDialog()
889 //=================================================================================
890 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
892 if ( ConstructorsBox->isEnabled() ) {
893 ConstructorsBox->setEnabled(false);
894 GroupContent->setEnabled(false);
895 GroupButtons->setEnabled(false);
896 mySimulation->SetVisibility(false);
897 mySMESHGUI->ResetState();
898 mySMESHGUI->SetActiveDialogBox(0);
903 //=================================================================================
904 // function : ActivateThisDialog()
906 //=================================================================================
907 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
909 /* Emit a signal to deactivate the active dialog */
910 mySMESHGUI->EmitSignalDeactivateDialog();
911 ConstructorsBox->setEnabled(true);
912 GroupContent->setEnabled(true);
913 GroupButtons->setEnabled(true);
915 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
917 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
918 aViewWindow->SetSelectionMode( FaceSelection );
919 SelectionIntoArgument();
923 //=================================================================================
924 // function : enterEvent()
926 //=================================================================================
927 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
929 if ( ConstructorsBox->isEnabled() )
931 ActivateThisDialog();
935 //=================================================================================
936 // function : closeEvent()
938 //=================================================================================
939 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
941 /* same than click on cancel button */
946 //=======================================================================
947 //function : hideEvent
948 //purpose : caused by ESC key
949 //=======================================================================
951 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
953 if ( !isMinimized() )
958 //=================================================================================
959 // function : GetConstructorId()
961 //=================================================================================
962 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
964 return GroupConstructors->checkedId();
967 //=================================================================================
968 // function : onAdd()
970 //=================================================================================
971 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
973 SALOME_ListIO selected;
974 mySelectionMgr->selectedObjects( selected );
975 int aNbSel = selected.Extent();
976 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
978 if (checkEditLine(false) == -1) return;
981 if ( !(myEditCurrentArgument->text().isEmpty()) )
983 myFacesByNodes->addItem(myEditCurrentArgument->text());
984 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
986 myEditCurrentArgument->clear();
987 AddButton->setEnabled(false);
988 buttonOk->setEnabled( true );
989 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
992 onListSelectionChanged();
996 //=================================================================================
997 // function : onRemove()
999 //=================================================================================
1000 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1003 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1004 QListWidgetItem* anItem;
1006 if ( selItems.count() > 0 ) myNbOkElements = 1;
1008 foreach( anItem, selItems )
1011 RemoveButton->setEnabled( myFacesByNodes->count() > 0 );
1012 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
1013 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
1016 displaySimulation();
1019 //=================================================================================
1020 // function : onListSelectionChanged()
1021 // purpose : Called when selection in element list is changed
1022 //=================================================================================
1023 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1025 if (busy || !myActor) return;
1028 SALOME_ListIO aList;
1029 mySelectionMgr->setSelectedObjects( aList );
1030 TColStd_MapOfInteger aIndexes;
1032 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1033 QListWidgetItem* anItem;
1034 foreach( anItem, selItems ) {
1035 QStringList anIds = anItem->text().split( " ", QString::SkipEmptyParts );
1036 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1037 aIndexes.Add((*it).toInt());
1039 RemoveButton->setEnabled(selItems.count() > 0);
1040 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1041 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1042 aViewWindow->highlight( myActor->getIO(), true, true );
1043 mySelectionMgr->clearFilters();
1044 aList.Append( myActor->getIO() );
1045 mySelectionMgr->setSelectedObjects( aList );
1050 //=================================================================================
1051 // function : keyPressEvent()
1053 //=================================================================================
1054 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1056 QDialog::keyPressEvent( e );
1057 if ( e->isAccepted() )
1060 if ( e->key() == Qt::Key_F1 ) {