1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_AddMeshElementDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_AddMeshElementDlg.h"
31 #include "SMESHGUI_GroupUtils.h"
32 #include "SMESHGUI_IdValidator.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_SpinBox.h"
35 #include "SMESHGUI_Utils.h"
36 #include "SMESHGUI_VTKUtils.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_ActorUtils.h>
40 #include <SMESH_FaceOrientationFilter.h>
41 #include <SMDS_Mesh.hxx>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_ViewManager.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <SALOME_ListIO.hxx>
51 #include <SalomeApp_Application.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
56 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
59 #include <TColStd_MapOfInteger.hxx>
63 #include <vtkIdList.h>
64 #include <vtkUnstructuredGrid.h>
65 #include <vtkDataSetMapper.h>
66 #include <vtkPolyDataMapper.h>
67 #include <vtkProperty.h>
74 #include <QPushButton>
75 #include <QRadioButton>
76 #include <QHBoxLayout>
77 #include <QVBoxLayout>
78 #include <QGridLayout>
82 #include <QButtonGroup>
89 class TElementSimulation
91 SalomeApp_Application* myApplication;
92 SUIT_ViewWindow* myViewWindow;
93 SVTK_ViewWindow* myVTKViewWindow;
95 SALOME_Actor* myPreviewActor;
96 vtkDataSetMapper* myMapper;
97 vtkUnstructuredGrid* myGrid;
99 SALOME_Actor* myFaceOrientation;
100 vtkPolyDataMapper* myFaceOrientationDataMapper;
101 SMESH_FaceOrientationFilter* myFaceOrientationFilter;
104 TElementSimulation (SalomeApp_Application* theApplication)
106 myApplication = theApplication;
107 SUIT_ViewManager* mgr = theApplication->activeViewManager();
109 myViewWindow = mgr->getActiveView();
110 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
112 myGrid = vtkUnstructuredGrid::New();
114 // Create and display actor
115 myMapper = vtkDataSetMapper::New();
116 myMapper->SetInput(myGrid);
118 myPreviewActor = SALOME_Actor::New();
119 myPreviewActor->PickableOff();
120 myPreviewActor->VisibilityOff();
121 myPreviewActor->SetMapper(myMapper);
123 vtkFloatingPointType anRGB[3];
124 vtkProperty* aProp = vtkProperty::New();
125 GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
126 aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
127 myPreviewActor->SetProperty( aProp );
130 vtkProperty* aBackProp = vtkProperty::New();
131 GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
132 aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
133 myPreviewActor->SetBackfaceProperty( aBackProp );
136 myVTKViewWindow->AddActor(myPreviewActor);
138 // Orientation of faces
139 myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
140 myFaceOrientationFilter->SetInput(myGrid);
142 myFaceOrientationDataMapper = vtkPolyDataMapper::New();
143 myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
145 myFaceOrientation = SALOME_Actor::New();
146 myFaceOrientation->PickableOff();
147 myFaceOrientation->VisibilityOff();
148 myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
150 vtkProperty* anOrientationProp = vtkProperty::New();
151 GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
152 anOrientationProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
153 myFaceOrientation->SetProperty( anOrientationProp );
154 anOrientationProp->Delete();
156 myVTKViewWindow->AddActor(myFaceOrientation);
159 typedef std::vector<vtkIdType> TVTKIds;
160 void SetPosition (SMESH_Actor* theActor,
164 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
165 myGrid->SetPoints(aGrid->GetPoints());
168 const std::vector<int>& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( theType ));
169 SMDS_MeshCell::applyInterlace( interlace, theIds );
171 vtkIdList *anIds = vtkIdList::New();
172 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
173 anIds->InsertId(i,theIds[i]);
175 myGrid->InsertNextCell(theType,anIds);
180 SetVisibility(true, theActor->GetFacesOriented());
184 void SetVisibility (bool theVisibility, bool theShowOrientation = false)
186 myPreviewActor->SetVisibility(theVisibility);
187 myFaceOrientation->SetVisibility(theShowOrientation);
188 RepaintCurrentView();
192 ~TElementSimulation()
194 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
195 myVTKViewWindow->RemoveActor(myPreviewActor);
196 myVTKViewWindow->RemoveActor(myFaceOrientation);
198 myPreviewActor->Delete();
199 myFaceOrientation->Delete();
201 myMapper->RemoveAllInputs();
204 myFaceOrientationFilter->Delete();
206 myFaceOrientationDataMapper->RemoveAllInputs();
207 myFaceOrientationDataMapper->Delete();
214 //=================================================================================
215 // function : SMESHGUI_AddMeshElementDlg()
216 // purpose : constructor
217 //=================================================================================
218 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
219 SMDSAbs_EntityType ElementType)
220 : QDialog( SMESH::GetDesktop( theModule ) ),
221 mySMESHGUI( theModule ),
222 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
226 setAttribute( Qt::WA_DeleteOnClose, true );
228 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
229 (SUIT_Session::session()->activeApplication());
231 mySimulation = new SMESH::TElementSimulation (anApp);
232 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
233 myGeomType = ElementType;
234 myElementType = SMDSAbs_Volume;
236 // verify nb nodes and type
238 switch ( myGeomType ) {
241 myElementType = SMDSAbs_0DElement;
243 myHelpFileName = "adding_nodes_and_elements_page.html#adding_0delems_anchor";
245 case SMDSEntity_Ball:
247 myElementType = SMDSAbs_Ball;
249 myHelpFileName = "adding_nodes_and_elements_page.html#adding_ball_anchor";
251 case SMDSEntity_Edge:
253 myElementType = SMDSAbs_Edge;
255 myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
257 case SMDSEntity_Triangle:
259 elemName = "TRIANGLE";
260 myElementType = SMDSAbs_Face;
261 myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
263 case SMDSEntity_Quadrangle:
265 myElementType = SMDSAbs_Face;
266 elemName = "QUADRANGLE";
267 myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
269 case SMDSEntity_Polygon:
271 myElementType = SMDSAbs_Face;
272 elemName = "POLYGON";
274 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
276 case SMDSEntity_Tetra:
279 myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
281 case SMDSEntity_Pyramid:
283 elemName = "PYRAMID";
284 myHelpFileName = "adding_nodes_and_elements_page.html#adding_pyramids_anchor";
286 case SMDSEntity_Hexa:
289 myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
291 case SMDSEntity_Penta:
294 myHelpFileName = "adding_nodes_and_elements_page.html#adding_pentahedrons_anchor";
296 case SMDSEntity_Hexagonal_Prism:
299 myHelpFileName = "adding_nodes_and_elements_page.html#adding_octahedrons_anchor";
304 myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
307 QString iconName = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
308 QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
309 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
310 QString grBoxTitle = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
312 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
313 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
315 setWindowTitle(caption);
316 setSizeGripEnabled(true);
318 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
319 aTopLayout->setSpacing(SPACING);
320 aTopLayout->setMargin(MARGIN);
322 /* Constructor *************************************************/
323 GroupConstructors = new QGroupBox(buttonGrTitle, this);
324 QButtonGroup* ButtonGroup = new QButtonGroup(this);
325 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
326 GroupConstructorsLayout->setSpacing(SPACING);
327 GroupConstructorsLayout->setMargin(MARGIN);
329 Constructor1 = new QRadioButton(GroupConstructors);
330 Constructor1->setIcon(image0);
331 Constructor1->setChecked(true);
333 GroupConstructorsLayout->addWidget(Constructor1);
334 ButtonGroup->addButton( Constructor1, 0 );
336 /* Nodes & Reverse *********************************************/
337 GroupC1 = new QGroupBox(grBoxTitle, this);
338 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
339 GroupC1Layout->setSpacing(SPACING);
340 GroupC1Layout->setMargin(MARGIN);
342 TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
343 SelectButtonC1A1 = new QPushButton(GroupC1);
344 SelectButtonC1A1->setIcon(image1);
345 LineEditC1A1 = new QLineEdit(GroupC1);
346 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, myIsPoly ? 1000 : myNbNodes));
348 Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
350 DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0;
351 QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0;
353 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
354 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
355 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
357 GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
359 if ( DiameterSpinBox ) {
360 GroupC1Layout->addWidget(diameterLabel, 1, 0);
361 GroupC1Layout->addWidget(DiameterSpinBox, 1, 1, 1, 2);
363 DiameterSpinBox->RangeStepAndValidator( 1e-7, 1e+9, 0.1 );
364 DiameterSpinBox->SetValue( 1. );
366 /* Add to group ************************************************/
367 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
368 GroupGroups->setCheckable( true );
369 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
370 GroupGroupsLayout->setSpacing(SPACING);
371 GroupGroupsLayout->setMargin(MARGIN);
373 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
374 ComboBox_GroupName = new QComboBox( GroupGroups );
375 ComboBox_GroupName->setEditable( true );
376 ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
378 GroupGroupsLayout->addWidget( TextLabel_GroupName );
379 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
381 /* Apply etc ***************************************************/
382 GroupButtons = new QGroupBox(this);
383 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
384 GroupButtonsLayout->setSpacing(SPACING);
385 GroupButtonsLayout->setMargin(MARGIN);
387 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
388 buttonOk->setAutoDefault(true);
389 buttonOk->setDefault(true);
390 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
391 buttonApply->setAutoDefault(true);
392 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
393 buttonCancel->setAutoDefault(true);
394 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
395 buttonHelp->setAutoDefault(true);
397 GroupButtonsLayout->addWidget(buttonOk);
398 GroupButtonsLayout->addSpacing(10);
399 GroupButtonsLayout->addWidget(buttonApply);
400 GroupButtonsLayout->addSpacing(10);
401 GroupButtonsLayout->addStretch();
402 GroupButtonsLayout->addWidget(buttonCancel);
403 GroupButtonsLayout->addWidget(buttonHelp);
405 /***************************************************************/
406 aTopLayout->addWidget(GroupConstructors);
407 aTopLayout->addWidget(GroupC1);
408 aTopLayout->addWidget(GroupGroups);
409 aTopLayout->addWidget(GroupButtons);
411 Init(); /* Initialisations */
414 //=================================================================================
415 // function : ~SMESHGUI_AddMeshElementDlg()
416 // purpose : Destroys the object and frees any allocated resources
417 //=================================================================================
418 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
423 //=================================================================================
426 //=================================================================================
427 void SMESHGUI_AddMeshElementDlg::Init()
430 Constructor1->setChecked(true);
431 myEditCurrentArgument = LineEditC1A1;
432 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
434 /* reset "Add to group" control */
435 GroupGroups->setChecked( false );
436 //GroupGroups->setVisible( myElementType != SMDSAbs_0DElement );
441 /* signals and slots connections */
442 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
443 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
444 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
445 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
447 connect(SelectButtonC1A1, SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
448 connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
449 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
450 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
451 /* to close dialog if study frame change */
452 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
453 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(ClickOnCancel()));
456 connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
458 // set selection mode
459 SMESH::SetPointRepresentation(true);
461 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
462 aViewWindow->SetSelectionMode( NodeSelection );
466 SelectionIntoArgument();
469 //=================================================================================
470 // function : ClickOnApply()
472 //=================================================================================
473 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
478 if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
480 SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
481 anArrayOfIndices->length(myNbNodes);
482 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
483 const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
484 if ( Reverse && Reverse->isChecked() && !revIndex.empty() )
485 for (int i = 0; i < aListId.count(); i++)
486 anArrayOfIndices[i] = aListId[ revIndex[i] ].toInt();
487 else if ( Reverse && Reverse->isChecked() && revIndex.empty() ) // polygon
488 for (int i = 0; i < aListId.count(); i++)
489 anArrayOfIndices[i] = aListId[ aListId.count()-1 - i ].toInt();
491 for (int i = 0; i < aListId.count(); i++)
492 anArrayOfIndices[i] = aListId[ i ].toInt();
494 bool addToGroup = GroupGroups->isChecked();
497 SMESH::SMESH_GroupBase_var aGroup;
500 aGroupName = ComboBox_GroupName->currentText();
501 for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
502 QString aName = ComboBox_GroupName->itemText( i );
503 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
506 if ( idx > 0 && idx <= myGroups.count() ) {
507 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
508 if ( !aGeomGroup->_is_nil() ) {
509 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
510 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
511 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
512 if ( res == 1 ) return;
514 aGroup = myGroups[idx-1];
519 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
520 switch (myElementType) {
521 case SMDSAbs_0DElement:
522 anElemId = aMeshEditor->Add0DElement(anArrayOfIndices[0]); break;
524 if ( myGeomType == SMDSEntity_Ball )
525 anElemId = aMeshEditor->AddBall(anArrayOfIndices[0],
526 DiameterSpinBox->GetValue()); break;
528 anElemId = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
531 anElemId = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
533 anElemId = aMeshEditor->AddFace(anArrayOfIndices.inout());
536 anElemId = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
539 if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
540 SMESH::SMESH_Group_var aGroupUsed;
541 if ( aGroup->_is_nil() ) {
543 aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
544 if ( !aGroupUsed->_is_nil() ) {
545 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
546 ComboBox_GroupName->addItem( aGroupName );
550 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
551 if ( !aGeomGroup->_is_nil() ) {
552 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
553 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
554 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
555 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
559 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
562 if ( !aGroupUsed->_is_nil() ) {
563 SMESH::long_array_var anIdList = new SMESH::long_array;
564 anIdList->length( 1 );
565 anIdList[0] = anElemId;
566 aGroupUsed->Add( anIdList.inout() );
570 SALOME_ListIO aList; aList.Append( myActor->getIO() );
571 mySelector->ClearIndex();
572 mySelectionMgr->setSelectedObjects( aList, false );
575 mySimulation->SetVisibility(false);
577 buttonOk->setEnabled(false);
578 buttonApply->setEnabled(false);
580 myEditCurrentArgument->setText("");
584 SMESHGUI::Modified();
588 //=================================================================================
589 // function : ClickOnOk()
591 //=================================================================================
592 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
598 //=================================================================================
599 // function : ClickOnCancel()
601 //=================================================================================
602 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
604 //mySelectionMgr->clearSelected();
605 mySimulation->SetVisibility(false);
606 SMESH::SetPointRepresentation(false);
607 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
608 aViewWindow->SetSelectionMode( ActorSelection );
609 disconnect(mySelectionMgr, 0, this, 0);
610 mySMESHGUI->ResetState();
614 //=================================================================================
615 // function : ClickOnHelp()
617 //=================================================================================
618 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
620 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
622 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
627 platform = "winapplication";
629 platform = "application";
631 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
632 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
633 arg(app->resourceMgr()->stringValue("ExternalBrowser",
635 arg(myHelpFileName));
639 //=================================================================================
640 // function : onTextChange()
642 //=================================================================================
643 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
650 buttonOk->setEnabled(false);
651 buttonApply->setEnabled(false);
653 mySimulation->SetVisibility(false);
655 // hilight entered nodes
656 SMDS_Mesh* aMesh = 0;
658 aMesh = myActor->GetObject()->GetMesh();
661 TColStd_MapOfInteger newIndices;
663 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
665 for (int i = 0; i < aListId.count(); i++) {
666 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
668 newIndices.Add( n->GetID() );
675 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
676 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
677 aViewWindow->highlight( myActor->getIO(), true, true );
679 myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
683 if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
686 myNbOkNodes = aListId.count();
691 buttonOk->setEnabled(true);
692 buttonApply->setEnabled(true);
699 //=================================================================================
700 // function : SelectionIntoArgument()
701 // purpose : Called when selection has changed
702 //=================================================================================
703 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
712 myEditCurrentArgument->setText("");
715 if (!GroupButtons->isEnabled()) // inactive
718 buttonOk->setEnabled(false);
719 buttonApply->setEnabled(false);
721 mySimulation->SetVisibility(false);
722 // SMESH::SetPointRepresentation(true);
724 QString aCurrentEntry = myEntry;
728 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
730 if (aList.Extent() != 1)
733 Handle(SALOME_InteractiveObject) anIO = aList.First();
734 myEntry = anIO->getEntry();
735 myMesh = SMESH::GetMeshByIO(anIO);
736 if (myMesh->_is_nil())
740 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
742 ComboBox_GroupName->clear();
743 ComboBox_GroupName->addItem( QString() );
744 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
745 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
746 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
747 if ( !aGroup->_is_nil() && aGroup->GetType() == (SMESH::ElementType)myElementType ) {
748 QString aGroupName( aGroup->GetName() );
749 if ( !aGroupName.isEmpty() ) {
750 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
751 ComboBox_GroupName->addItem( aGroupName );
757 myActor = SMESH::FindActorByEntry(anIO->getEntry());
761 // get selected nodes
762 QString aString = "";
763 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
765 myEditCurrentArgument->setText(aString);
767 if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
769 } else if (myNbNodes != nbNodes) {
774 myNbOkNodes = nbNodes;
776 buttonOk->setEnabled(true);
777 buttonApply->setEnabled(true);
782 //=================================================================================
783 // function : displaySimulation()
785 //=================================================================================
786 void SMESHGUI_AddMeshElementDlg::displaySimulation()
788 if (myNbOkNodes && GroupButtons->isEnabled()) {
789 SMESH::TElementSimulation::TVTKIds anIds;
790 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
791 for (int i = 0; i < aListId.count(); i++)
792 anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
794 if (Reverse && Reverse->isChecked())
796 const std::vector<int>& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
797 if ( i.empty() ) // polygon
798 std::reverse( anIds.begin(), anIds.end() );
800 SMDS_MeshCell::applyInterlace( i, anIds );
803 vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType );
804 mySimulation->SetPosition(myActor,aType,anIds);
809 //=================================================================================
810 // function : SetEditCurrentArgument()
812 //=================================================================================
813 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
815 QPushButton* send = (QPushButton*)sender();
816 if (send == SelectButtonC1A1) {
817 LineEditC1A1->setFocus();
818 myEditCurrentArgument = LineEditC1A1;
820 SelectionIntoArgument();
823 //=================================================================================
824 // function : DeactivateActiveDialog()
826 //=================================================================================
827 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
829 if (GroupConstructors->isEnabled()) {
830 GroupConstructors->setEnabled(false);
831 GroupC1->setEnabled(false);
832 GroupButtons->setEnabled(false);
833 mySimulation->SetVisibility(false);
834 mySMESHGUI->ResetState();
835 mySMESHGUI->SetActiveDialogBox(0);
839 //=================================================================================
840 // function : ActivateThisDialog()
842 //=================================================================================
843 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
845 /* Emit a signal to deactivate the active dialog */
846 mySMESHGUI->EmitSignalDeactivateDialog();
848 GroupConstructors->setEnabled(true);
849 GroupC1->setEnabled(true);
850 GroupButtons->setEnabled(true);
852 SMESH::SetPointRepresentation(true);
854 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
855 aViewWindow->SetSelectionMode( NodeSelection );
856 SelectionIntoArgument();
859 //=================================================================================
860 // function : enterEvent()
862 //=================================================================================
863 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
865 if (GroupConstructors->isEnabled())
867 ActivateThisDialog();
870 //=================================================================================
871 // function : closeEvent()
873 //=================================================================================
874 void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
876 /* same than click on cancel button */
880 //=================================================================================
881 // function : hideEvent()
882 // purpose : caused by ESC key
883 //=================================================================================
884 void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
890 //=================================================================================
891 // function : CheckBox()
893 //=================================================================================
894 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
900 mySimulation->SetVisibility(false);
905 //=================================================================================
906 // function : keyPressEvent()
908 //=================================================================================
909 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
911 QDialog::keyPressEvent( e );
912 if ( e->isAccepted() )
915 if ( e->key() == Qt::Key_F1 ) {
921 //=================================================================================
922 // function : isValid
924 //=================================================================================
925 bool SMESHGUI_AddMeshElementDlg::isValid()
927 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
928 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );