1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_GroupUtils.h"
35 #include "SMESHGUI_IdValidator.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_ActorUtils.h>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <SalomeApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include "utilities.h"
54 #include <SVTK_ViewWindow.h>
57 #include <TColStd_ListOfInteger.hxx>
58 #include <TColStd_ListIteratorOfListOfInteger.hxx>
62 #include <vtkIdList.h>
63 #include <vtkUnstructuredGrid.h>
64 #include <vtkDataSetMapper.h>
65 #include <vtkProperty.h>
68 #include <QApplication>
69 #include <QButtonGroup>
74 #include <QPushButton>
75 #include <QRadioButton>
77 #include <QHBoxLayout>
78 #include <QVBoxLayout>
79 #include <QGridLayout>
80 #include <QListWidget>
84 #include <SALOMEconfig.h>
85 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
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->SetInputData( myGrid );
113 myPreviewActor = SALOME_Actor::New();
114 myPreviewActor->PickableOff();
115 myPreviewActor->VisibilityOff();
116 myPreviewActor->SetMapper( myMapper );
117 myPreviewActor->SetRepresentation( 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 double 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 )
193 : QDialog( SMESH::GetDesktop( theModule ) ),
194 mySMESHGUI( theModule ),
195 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
197 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
200 setAttribute(Qt::WA_DeleteOnClose, true);
201 setWindowTitle( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
202 setSizeGripEnabled( true );
204 QVBoxLayout* topLayout = new QVBoxLayout( this );
205 topLayout->setSpacing( SPACING );
206 topLayout->setMargin( MARGIN );
208 /***************************************************************/
209 ConstructorsBox = new QGroupBox(tr( "SMESH_ELEMENTS_TYPE" ), this);
210 GroupConstructors = new QButtonGroup(this);
211 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout( ConstructorsBox );
212 ConstructorsBoxLayout->setSpacing( SPACING );
213 ConstructorsBoxLayout->setMargin( MARGIN );
215 RadioButton1 = new QRadioButton( tr( "MESH_NODE" ), ConstructorsBox );
216 RadioButton2 = new QRadioButton( tr( "SMESH_FACE" ), ConstructorsBox );
218 ConstructorsBoxLayout->addWidget( RadioButton1 );
219 ConstructorsBoxLayout->addWidget( RadioButton2 );
220 GroupConstructors->addButton(RadioButton1, 0);
221 GroupConstructors->addButton(RadioButton2, 1);
223 /***************************************************************/
224 GroupContent = new QGroupBox( tr( "SMESH_CONTENT" ), this );
225 QGridLayout* GroupContentLayout = new QGridLayout( GroupContent );
226 GroupContentLayout->setSpacing( SPACING );
227 GroupContentLayout->setMargin( MARGIN );
229 TextLabelIds = new QLabel( tr( "SMESH_ID_NODES" ), GroupContent );
230 SelectElementsButton = new QPushButton( GroupContent );
231 SelectElementsButton->setIcon( image0 );
232 LineEditElements = new QLineEdit( GroupContent );
233 LineEditElements->setValidator( new SMESHGUI_IdValidator( this ) );
235 myFacesByNodesLabel = new QLabel( tr( "FACES_BY_NODES" ), GroupContent );
236 myFacesByNodes = new QListWidget( GroupContent);
237 myFacesByNodes->setSelectionMode( QListWidget::ExtendedSelection );
238 myFacesByNodes->setMinimumHeight( 150);
240 AddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), GroupContent );
241 RemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), GroupContent );
243 Preview = new QCheckBox( tr( "SMESH_POLYEDRE_PREVIEW" ), GroupContent );
245 GroupContentLayout->addWidget( TextLabelIds, 0, 0 );
246 GroupContentLayout->addWidget( SelectElementsButton, 0, 1 );
247 GroupContentLayout->addWidget( LineEditElements, 0, 2, 1, 2 );
248 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
249 GroupContentLayout->addWidget( myFacesByNodes, 2, 0, 3, 3 );
250 GroupContentLayout->addWidget( AddButton, 2, 3 );
251 GroupContentLayout->addWidget( RemoveButton, 3, 3 );
252 GroupContentLayout->addWidget( Preview, 5, 0, 1, 4 );
254 /***************************************************************/
255 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
256 GroupGroups->setCheckable( true );
257 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
258 GroupGroupsLayout->setSpacing(SPACING);
259 GroupGroupsLayout->setMargin(MARGIN);
261 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
262 ComboBox_GroupName = new QComboBox( GroupGroups );
263 ComboBox_GroupName->setEditable( true );
264 ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
266 GroupGroupsLayout->addWidget( TextLabel_GroupName );
267 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
269 /***************************************************************/
270 GroupButtons = new QGroupBox( this );
271 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
272 GroupButtonsLayout->setSpacing( SPACING );
273 GroupButtonsLayout->setMargin( MARGIN );
275 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
276 buttonOk->setAutoDefault( true );
277 buttonOk->setDefault( true );
278 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
279 buttonApply->setAutoDefault( true );
280 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
281 buttonCancel->setAutoDefault( true );
282 buttonHelp = new QPushButton( tr("SMESH_BUT_HELP" ), GroupButtons );
283 buttonHelp->setAutoDefault(true);
285 GroupButtonsLayout->addWidget( buttonOk );
286 GroupButtonsLayout->addSpacing( 10 );
287 GroupButtonsLayout->addWidget( buttonApply );
288 GroupButtonsLayout->addSpacing( 10 );
289 GroupButtonsLayout->addStretch();
290 GroupButtonsLayout->addWidget( buttonCancel );
291 GroupButtonsLayout->addWidget( buttonHelp);
293 /***************************************************************/
294 topLayout->addWidget( ConstructorsBox );
295 topLayout->addWidget( GroupContent );
296 topLayout->addWidget( GroupGroups );
297 topLayout->addWidget( GroupButtons );
299 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
301 RadioButton1->setChecked( true );
303 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
305 myHelpFileName = "adding_nodes_and_elements.html#adding-polyhedrons-anchor";
310 //=================================================================================
311 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
312 // purpose : Destroys the object and frees any allocated resources
313 //=================================================================================
314 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
319 static bool busy = false;
321 //=================================================================================
324 //=================================================================================
325 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
327 myEditCurrentArgument = LineEditElements;
328 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
330 /* reset "Add to group" control */
331 GroupGroups->setChecked( false );
336 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
338 /* signals and slots connections */
339 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
340 connect(buttonCancel, SIGNAL( clicked() ), SLOT( reject() ) );
341 connect(buttonApply, SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
342 connect(buttonHelp, SIGNAL( clicked() ), SLOT( ClickOnHelp() ) );
344 connect(GroupConstructors, SIGNAL(buttonClicked(int) ), SLOT( ConstructorsClicked(int) ) );
345 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) );
346 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
348 connect(myFacesByNodes, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
349 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
350 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
352 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
353 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
354 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
355 /* to close dialog if study change */
356 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( reject() ) );
357 connect( mySMESHGUI, SIGNAL ( SignalActivatedViewManager() ), this, SLOT( onOpenView() ) );
358 connect( mySMESHGUI, SIGNAL ( SignalCloseView() ), this, SLOT( onCloseView() ) );
359 ConstructorsClicked(0);
360 SelectionIntoArgument();
364 //=================================================================================
365 // function : ConstructorsClicked()
366 // purpose : Radio button management
367 //=================================================================================
368 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
370 //disconnect(mySelectionMgr, 0, this, 0);
373 mySelectionMgr->selectedObjects( io );
375 mySelectionMgr->setSelectedObjects( aList );
376 myEditCurrentArgument->clear();
378 buttonApply->setEnabled(false);
379 buttonOk->setEnabled(false);
380 mySimulation->SetVisibility(false);
382 switch(constructorId)
387 myActor->SetPointRepresentation(true);
390 SMESH::SetPointRepresentation(true);
391 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
392 aViewWindow->SetSelectionMode(NodeSelection);
394 AddButton->setEnabled(false);
395 RemoveButton->setEnabled(false);
396 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
397 myFacesByNodesLabel->show();
398 myFacesByNodes->clear();
399 myFacesByNodes->show();
401 RemoveButton->show();
408 myActor->SetPointRepresentation(false);
410 SMESH::SetPointRepresentation(false);
412 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
413 aViewWindow->SetSelectionMode(FaceSelection);
415 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
416 myFacesByNodesLabel->hide();
417 myFacesByNodes->hide();
419 RemoveButton->hide();
425 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
426 mySelectionMgr->setSelectedObjects( io );
428 QApplication::instance()->processEvents();
433 //=================================================================================
434 // function : ClickOnPreview()
436 //=================================================================================
437 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
438 Preview->setChecked(theToggled);
442 //=================================================================================
443 // function : ClickOnApply()
445 //=================================================================================
446 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
451 if ( myNbOkElements>0 && !SMESHGUI::isStudyLocked())
453 if(checkEditLine(false) == -1) {return;}
457 bool addToGroup = GroupGroups->isChecked();
460 SMESH::SMESH_GroupBase_var aGroup;
463 aGroupName = ComboBox_GroupName->currentText();
464 for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
465 QString aName = ComboBox_GroupName->itemText( i );
466 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
469 if ( idx > 0 && idx <= myGroups.count() ) {
470 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
471 if ( !aGeomGroup->_is_nil() ) {
472 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
473 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
474 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
475 if ( res == 1 ) return;
477 aGroup = myGroups[idx-1];
481 if (GetConstructorId() == 0)
483 SMESH::smIdType_array_var anIdsOfNodes = new SMESH::smIdType_array;
484 SMESH::long_array_var aQuantities = new SMESH::long_array;
486 aQuantities->length( myFacesByNodes->count() );
488 TColStd_ListOfInteger aNodesIds;
490 int aNbQuantities = 0;
491 for (int i = 0; i < myFacesByNodes->count(); i++ ) {
492 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
493 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
494 aNodesIds.Append( (*it).toInt() );
496 aQuantities[aNbQuantities++] = anIds.count();
499 anIdsOfNodes->length(aNodesIds.Extent());
501 int aNbIdsOfNodes = 0;
502 TColStd_ListIteratorOfListOfInteger It;
503 It.Initialize(aNodesIds);
504 for( ;It.More();It.Next())
505 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
508 SUIT_OverrideCursor aWaitCursor;
509 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
510 anElemId = aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
511 }catch(SALOME::SALOME_Exception& exc){
512 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
513 }catch(std::exception& exc){
514 INFOS("Follow exception was cought:\n\t"<<exc.what());
516 INFOS("Unknown exception was cought !!!");
519 else if (GetConstructorId() == 1)
521 SMESH::smIdType_array_var anIdsOfFaces = new SMESH::smIdType_array;
523 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
524 anIdsOfFaces->length(aListId.count());
525 for ( int i = 0; i < aListId.count(); i++ )
526 anIdsOfFaces[i] = aListId[i].toInt();
529 SUIT_OverrideCursor aWaitCursor;
530 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
531 anElemId = aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
532 }catch(SALOME::SALOME_Exception& exc){
533 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
534 }catch(std::exception& exc){
535 INFOS("Follow exception was cought:\n\t"<<exc.what());
537 INFOS("Unknown exception was cought !!!");
541 if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
542 SMESH::SMESH_Group_var aGroupUsed;
543 if ( aGroup->_is_nil() ) {
545 aGroupUsed = SMESH::AddGroup( myMesh, SMESH::VOLUME, aGroupName );
546 if ( !aGroupUsed->_is_nil() ) {
547 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
548 ComboBox_GroupName->addItem( aGroupName );
552 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
553 if ( !aGeomGroup->_is_nil() ) {
554 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
555 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
556 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
557 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
561 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
564 if ( !aGroupUsed->_is_nil() ) {
565 SMESH::smIdType_array_var anIdList = new SMESH::smIdType_array;
566 anIdList->length( 1 );
567 anIdList[0] = anElemId;
568 aGroupUsed->Add( anIdList.inout() );
572 //SALOME_ListIO aList;
573 //mySelectionMgr->setSelectedObjects( aList );
576 unsigned int anEntityMode = myActor->GetEntityMode();
577 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
579 //ConstructorsClicked( GetConstructorId() );
582 SMESHGUI::Modified();
584 myFacesByNodes->clear();
587 //=================================================================================
588 // function : ClickOnOk()
590 //=================================================================================
591 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
593 if(checkEditLine(false) == -1) {return;}
599 //=================================================================================
600 // function : reject()
602 //=================================================================================
603 void SMESHGUI_CreatePolyhedralVolumeDlg::reject()
605 mySelectionMgr->clearFilters();
606 //SALOME_ListIO aList;
607 //mySelectionMgr->setSelectedObjects( aList );
608 SMESH::SetPointRepresentation(false);
609 mySimulation->SetVisibility(false);
610 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
611 aViewWindow->SetSelectionMode( ActorSelection );
612 disconnect( mySelectionMgr, 0, this, 0 );
613 mySMESHGUI->ResetState();
617 //=================================================================================
618 // function : onOpenView()
620 //=================================================================================
621 void SMESHGUI_CreatePolyhedralVolumeDlg::onOpenView()
623 if ( mySelector && mySimulation ) {
624 mySimulation->SetVisibility(false);
625 SMESH::SetPointRepresentation(false);
628 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
629 mySimulation = new SMESH::TPolySimulation(
630 dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
631 ActivateThisDialog();
635 //=================================================================================
636 // function : onCloseView()
638 //=================================================================================
639 void SMESHGUI_CreatePolyhedralVolumeDlg::onCloseView()
641 DeactivateActiveDialog();
647 //=================================================================================
648 // function : ClickOnHelp()
650 //=================================================================================
651 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
653 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
655 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
659 platform = "winapplication";
661 platform = "application";
663 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
664 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
665 arg(app->resourceMgr()->stringValue("ExternalBrowser",
667 arg(myHelpFileName));
671 //=======================================================================
672 //function : onTextChange
674 //=======================================================================
676 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
679 if (checkEditLine() == -1) return;
682 mySimulation->SetVisibility(false);
684 SMDS_Mesh* aMesh = 0;
686 aMesh = myActor->GetObject()->GetMesh();
688 if (GetConstructorId() == 0)
691 SVTK_TVtkIDsMap newIndices;
693 QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts );
694 for ( int i = 0; i < aListId.count(); i++ ) {
695 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
697 newIndices.Add(n->GetID());
702 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
704 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
705 aViewWindow->highlight( myActor->getIO(), true, true );
707 if ( myNbOkElements>0 && aListId.count()>=3)
708 AddButton->setEnabled(true);
710 AddButton->setEnabled(false);
714 } else if (GetConstructorId() == 1)
717 buttonOk->setEnabled( false );
718 buttonApply->setEnabled( false );
720 // check entered ids of faces and highlight them
723 SVTK_TVtkIDsMap newIndices;
725 aListId = theNewText.split( " ", QString::SkipEmptyParts );
727 for ( int i = 0; i < aListId.count(); i++ ) {
728 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
730 newIndices.Add(e->GetID());
735 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
736 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
737 aViewWindow->highlight( myActor->getIO(), true, true );
739 if ( myNbOkElements ) {
740 if (aListId.count()>1){
741 buttonOk->setEnabled( true );
742 buttonApply->setEnabled( true );
745 buttonOk->setEnabled( false );
746 buttonApply->setEnabled( false );
748 if(aListId.count()>1)
756 //=================================================================================
757 // function : SelectionIntoArgument()
758 // purpose : Called when selection as changed or other case
759 //=================================================================================
760 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
766 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
769 AddButton->setEnabled(false);
770 buttonOk->setEnabled( false );
771 buttonApply->setEnabled( false );
777 myEditCurrentArgument->setText( "" );
779 if ( !GroupButtons->isEnabled() ) // inactive
782 mySimulation->SetVisibility(false);
784 QString aCurrentEntry = myEntry;
788 SALOME_ListIO selected;
789 mySelectionMgr->selectedObjects( selected );
790 int nbSel = selected.Extent();
795 myEntry = selected.First()->getEntry();
796 myMesh = SMESH::GetMeshByIO( selected.First() );
797 if ( myMesh->_is_nil() )
801 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
803 ComboBox_GroupName->clear();
804 ComboBox_GroupName->addItem( QString() );
805 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
806 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
807 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
808 if ( !aGroup->_is_nil() && aGroup->GetType() == SMESH::VOLUME ) {
809 QString aGroupName( aGroup->GetName() );
810 if ( !aGroupName.isEmpty() ) {
811 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
812 ComboBox_GroupName->addItem( aGroupName );
818 myActor = SMESH::FindActorByObject(myMesh);
822 // get selected nodes/faces
823 QString aString = "";
824 int anbNodes=0,aNbFaces=0;
825 switch(GetConstructorId()){
827 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
829 AddButton->setEnabled(true);
830 else if (anbNodes < 3){
831 AddButton->setEnabled(false);
834 myEditCurrentArgument->setText( aString );
835 if (checkEditLine() == -1) {busy = false;return;}
840 // get selected faces
841 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
843 buttonOk->setEnabled( false );
844 buttonApply->setEnabled( false );
846 buttonOk->setEnabled( true );
847 buttonApply->setEnabled( true );
850 myEditCurrentArgument->setText( aString );
851 if (checkEditLine() == -1) {busy = false;return;}
860 if(anbNodes>2 || aNbFaces>1)
864 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
865 * Checking of indices in edit line.
866 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
867 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
869 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
871 QString aString = "";
872 SMDS_Mesh* aMesh = 0;
874 if(myMesh->_is_nil()) return 1;
876 myActor = SMESH::FindActorByObject(myMesh);
881 aMesh = myActor->GetObject()->GetMesh();
883 // checking for nodes
884 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
885 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
886 for ( int i = 0; i < aListId.count(); i++ ){
887 switch (GetConstructorId()){
889 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
891 SUIT_MessageBox::warning(this,
892 tr("SMESH_POLYEDRE_CREATE_ERROR"),
893 tr("The incorrect indices of nodes!"));
895 myEditCurrentArgument->clear();
896 myEditCurrentArgument->setText( aString );
903 bool aElemIsOK = true;
904 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
911 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
912 if (aType != SMDSAbs_Face){
917 SUIT_MessageBox::warning(this,
918 tr("SMESH_POLYEDRE_CREATE_ERROR"),
919 tr("The incorrect indices of faces!"));
921 myEditCurrentArgument->clear();
922 myEditCurrentArgument->setText( aString );
928 aString += aListId[ i ] + " ";
934 //=======================================================================
935 //function : displaySimulation
937 //=======================================================================
938 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
940 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
942 SMESH::TPolySimulation::TVTKIds aVTKIds;
943 vtkIdType aType = VTK_CONVEX_POINT_SET;
944 SMDS_Mesh* aMesh = 0;
946 aMesh = myActor->GetObject()->GetMesh();
948 if (GetConstructorId() == 0 && aMesh){
949 if (!AddButton->isEnabled()){
950 mySimulation->ResetGrid(true);
951 for (int i = 0; i < myFacesByNodes->count(); i++) {
952 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
953 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
954 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
955 const SMDS_MeshNode* aNode = aMesh->FindNode( (*it).toInt() );
956 if (!aNode) continue;
957 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() );
958 aVTKIds.push_back(aId);
959 aVTKIds_faces.push_back(aId);
961 if(!Preview->isChecked()){
963 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
966 if(myFacesByNodes->count() == 0){
967 mySimulation->SetVisibility(false);
969 mySimulation->SetVisibility(true);
971 if(Preview->isChecked()){
972 mySimulation->SetPosition(myActor, aType, aVTKIds);
975 // add ids from edit line
976 QStringList anEditIds = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
977 for ( int i = 0; i < anEditIds.count(); i++ )
978 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
980 mySimulation->SetPosition(myActor, aType, aVTKIds);
982 }else if(GetConstructorId() == 1 && aMesh){
983 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
984 for ( int i = 0; i < aListId.count(); i++ )
986 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
987 if ( !anElem ) continue;
988 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
989 if (aFaceType != SMDSAbs_Face) continue;
991 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
992 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
993 while( anIter->more() )
994 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
995 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() );
996 aVTKIds.push_back(aId);
997 aVTKIds_faces.push_back(aId);
999 if(!Preview->isChecked()){
1000 aType = VTK_POLYGON;
1001 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
1004 if(Preview->isChecked())
1005 mySimulation->SetPosition(myActor, aType, aVTKIds);
1007 SMESH::UpdateView();
1011 //=================================================================================
1012 // function : SetEditCurrentArgument()
1014 //=================================================================================
1015 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
1017 QPushButton* send = (QPushButton*)sender();
1018 if(send == SelectElementsButton) {
1019 LineEditElements->setFocus();
1020 myEditCurrentArgument = LineEditElements;
1022 SelectionIntoArgument();
1025 //=================================================================================
1026 // function : DeactivateActiveDialog()
1028 //=================================================================================
1029 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
1031 if ( ConstructorsBox->isEnabled() ) {
1032 ConstructorsBox->setEnabled(false);
1033 GroupContent->setEnabled(false);
1034 GroupButtons->setEnabled(false);
1035 mySimulation->SetVisibility(false);
1036 mySMESHGUI->ResetState();
1037 mySMESHGUI->SetActiveDialogBox(0);
1042 //=================================================================================
1043 // function : ActivateThisDialog()
1045 //=================================================================================
1046 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
1048 /* Emit a signal to deactivate the active dialog */
1049 mySMESHGUI->EmitSignalDeactivateDialog();
1050 ConstructorsBox->setEnabled(true);
1051 GroupContent->setEnabled(true);
1052 GroupButtons->setEnabled(true);
1054 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
1056 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1057 aViewWindow->SetSelectionMode( FaceSelection );
1058 SelectionIntoArgument();
1061 //=================================================================================
1062 // function : enterEvent()
1064 //=================================================================================
1065 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent (QEvent*)
1067 if ( !ConstructorsBox->isEnabled() ) {
1068 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1069 if ( aViewWindow && !mySelector && !mySimulation) {
1070 mySelector = aViewWindow->GetSelector();
1071 mySimulation = new SMESH::TPolySimulation(
1072 dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
1074 ActivateThisDialog();
1078 //=================================================================================
1079 // function : GetConstructorId()
1081 //=================================================================================
1082 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1084 return GroupConstructors->checkedId();
1087 //=================================================================================
1088 // function : onAdd()
1090 //=================================================================================
1091 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1093 SALOME_ListIO selected;
1094 mySelectionMgr->selectedObjects( selected );
1095 int aNbSel = selected.Extent();
1096 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1098 if (checkEditLine(false) == -1) return;
1101 if ( !(myEditCurrentArgument->text().isEmpty()) )
1103 myFacesByNodes->addItem(myEditCurrentArgument->text());
1104 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1106 myEditCurrentArgument->clear();
1107 AddButton->setEnabled(false);
1108 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
1109 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
1112 onListSelectionChanged();
1113 displaySimulation();
1116 //=================================================================================
1117 // function : onRemove()
1119 //=================================================================================
1120 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1123 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1124 QListWidgetItem* anItem;
1126 if ( selItems.count() > 0 ) myNbOkElements = 1;
1128 foreach( anItem, selItems )
1131 RemoveButton->setEnabled( myFacesByNodes->count() > 0 );
1132 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
1133 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
1136 displaySimulation();
1139 //=================================================================================
1140 // function : onListSelectionChanged()
1141 // purpose : Called when selection in element list is changed
1142 //=================================================================================
1143 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1145 if (busy || !myActor) return;
1148 SALOME_ListIO aList;
1149 mySelectionMgr->setSelectedObjects( aList );
1150 SVTK_TVtkIDsMap aIndexes;
1152 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1153 QListWidgetItem* anItem;
1154 foreach( anItem, selItems ) {
1155 QStringList anIds = anItem->text().split( " ", QString::SkipEmptyParts );
1156 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1157 aIndexes.Add((*it).toInt());
1159 RemoveButton->setEnabled(selItems.count() > 0);
1160 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1161 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1162 aViewWindow->highlight( myActor->getIO(), true, true );
1163 mySelectionMgr->clearFilters();
1164 aList.Append( myActor->getIO() );
1165 mySelectionMgr->setSelectedObjects( aList );
1170 //=================================================================================
1171 // function : keyPressEvent()
1173 //=================================================================================
1174 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1176 QDialog::keyPressEvent( e );
1177 if ( e->isAccepted() )
1180 if ( e->key() == Qt::Key_F1 ) {
1186 //=================================================================================
1187 // function : isValid
1189 //=================================================================================
1190 bool SMESHGUI_CreatePolyhedralVolumeDlg::isValid()
1192 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
1193 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );