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
347 (new SMESHGUI_IdValidator(this, ( myIsPoly || myNbNodes == 1 ) ? 1000 : myNbNodes));
349 Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
351 DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0;
352 QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0;
354 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
355 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
356 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
358 GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
360 if ( DiameterSpinBox ) {
361 GroupC1Layout->addWidget(diameterLabel, 1, 0);
362 GroupC1Layout->addWidget(DiameterSpinBox, 1, 1, 1, 2);
364 DiameterSpinBox->RangeStepAndValidator( 1e-7, 1e+9, 0.1 );
365 DiameterSpinBox->SetValue( 1. );
367 /* Add to group ************************************************/
368 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
369 GroupGroups->setCheckable( true );
370 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
371 GroupGroupsLayout->setSpacing(SPACING);
372 GroupGroupsLayout->setMargin(MARGIN);
374 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
375 ComboBox_GroupName = new QComboBox( GroupGroups );
376 ComboBox_GroupName->setEditable( true );
377 ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
379 GroupGroupsLayout->addWidget( TextLabel_GroupName );
380 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
382 /* Apply etc ***************************************************/
383 GroupButtons = new QGroupBox(this);
384 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
385 GroupButtonsLayout->setSpacing(SPACING);
386 GroupButtonsLayout->setMargin(MARGIN);
388 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
389 buttonOk->setAutoDefault(true);
390 buttonOk->setDefault(true);
391 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
392 buttonApply->setAutoDefault(true);
393 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
394 buttonCancel->setAutoDefault(true);
395 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
396 buttonHelp->setAutoDefault(true);
398 GroupButtonsLayout->addWidget(buttonOk);
399 GroupButtonsLayout->addSpacing(10);
400 GroupButtonsLayout->addWidget(buttonApply);
401 GroupButtonsLayout->addSpacing(10);
402 GroupButtonsLayout->addStretch();
403 GroupButtonsLayout->addWidget(buttonCancel);
404 GroupButtonsLayout->addWidget(buttonHelp);
406 /***************************************************************/
407 aTopLayout->addWidget(GroupConstructors);
408 aTopLayout->addWidget(GroupC1);
409 aTopLayout->addWidget(GroupGroups);
410 aTopLayout->addWidget(GroupButtons);
412 Init(); /* Initialisations */
415 //=================================================================================
416 // function : ~SMESHGUI_AddMeshElementDlg()
417 // purpose : Destroys the object and frees any allocated resources
418 //=================================================================================
419 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
424 //=================================================================================
427 //=================================================================================
428 void SMESHGUI_AddMeshElementDlg::Init()
431 Constructor1->setChecked(true);
432 myEditCurrentArgument = LineEditC1A1;
433 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
435 /* reset "Add to group" control */
436 GroupGroups->setChecked( false );
437 //GroupGroups->setVisible( myElementType != SMDSAbs_0DElement );
442 /* signals and slots connections */
443 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
444 connect(buttonCancel, SIGNAL(clicked()), SLOT(reject()));
445 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
446 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
448 connect(SelectButtonC1A1,SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
449 connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
450 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()),SLOT(DeactivateActiveDialog()));
451 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
452 /* to close dialog if study frame change */
453 connect(mySMESHGUI, SIGNAL(SignalStudyFrameChanged()), SLOT(reject()));
454 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
457 connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
459 // set selection mode
460 SMESH::SetPointRepresentation(true);
462 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
463 aViewWindow->SetSelectionMode( NodeSelection );
467 SelectionIntoArgument();
470 //=================================================================================
471 // function : ClickOnApply()
473 //=================================================================================
474 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
479 if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
481 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
482 SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
483 anArrayOfIndices->length(aListId.count());
484 const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
485 if ( Reverse && Reverse->isChecked() && !revIndex.empty() )
486 for (int i = 0; i < aListId.count(); i++)
487 anArrayOfIndices[i] = aListId[ revIndex[i] ].toInt();
488 else if ( Reverse && Reverse->isChecked() && revIndex.empty() ) // polygon
489 for (int i = 0; i < aListId.count(); i++)
490 anArrayOfIndices[i] = aListId[ aListId.count()-1 - i ].toInt();
492 for (int i = 0; i < aListId.count(); i++)
493 anArrayOfIndices[i] = aListId[ i ].toInt();
495 bool addToGroup = GroupGroups->isChecked();
498 SMESH::SMESH_GroupBase_var aGroup;
501 aGroupName = ComboBox_GroupName->currentText();
502 for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
503 QString aName = ComboBox_GroupName->itemText( i );
504 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
507 if ( idx > 0 && idx <= myGroups.count() ) {
508 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
509 if ( !aGeomGroup->_is_nil() ) {
510 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
511 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
512 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
513 if ( res == 1 ) return;
515 aGroup = myGroups[idx-1];
519 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
520 SMESH::long_array_var anIdList = new SMESH::long_array;
521 anIdList->length( 1 );
524 switch (myElementType) {
525 case SMDSAbs_0DElement:
526 anIdList->length( anArrayOfIndices->length() );
527 for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
528 anIdList[i] = aMeshEditor->Add0DElement(anArrayOfIndices[i]);
531 if ( myGeomType == SMDSEntity_Ball ) {
532 anIdList->length( anArrayOfIndices->length() );
533 for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
534 anIdList[i] = aMeshEditor->AddBall(anArrayOfIndices[i],
535 DiameterSpinBox->GetValue());
539 anIdList[0] = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
542 anIdList[0] = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
544 anIdList[0] = aMeshEditor->AddFace(anArrayOfIndices.inout());
547 anIdList[0] = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
550 if ( anIdList[0] > 0 && addToGroup && !aGroupName.isEmpty() ) {
551 SMESH::SMESH_Group_var aGroupUsed;
552 if ( aGroup->_is_nil() ) {
554 aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
555 if ( !aGroupUsed->_is_nil() ) {
556 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
557 ComboBox_GroupName->addItem( aGroupName );
561 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
562 if ( !aGeomGroup->_is_nil() ) {
563 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
564 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
565 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
566 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
570 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
573 if ( !aGroupUsed->_is_nil() )
574 aGroupUsed->Add( anIdList.inout() );
577 SALOME_ListIO aList; aList.Append( myActor->getIO() );
578 mySelector->ClearIndex();
579 mySelectionMgr->setSelectedObjects( aList, false );
582 mySimulation->SetVisibility(false);
584 buttonOk->setEnabled(false);
585 buttonApply->setEnabled(false);
587 myEditCurrentArgument->setText("");
591 SMESHGUI::Modified();
595 //=================================================================================
596 // function : ClickOnOk()
598 //=================================================================================
599 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
605 //=================================================================================
606 // function : reject()
608 //=================================================================================
609 void SMESHGUI_AddMeshElementDlg::reject()
611 //mySelectionMgr->clearSelected();
612 mySimulation->SetVisibility(false);
613 SMESH::SetPointRepresentation(false);
614 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
615 aViewWindow->SetSelectionMode( ActorSelection );
616 disconnect(mySelectionMgr, 0, this, 0);
617 mySMESHGUI->ResetState();
621 //=================================================================================
622 // function : ClickOnHelp()
624 //=================================================================================
625 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
627 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
629 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
634 platform = "winapplication";
636 platform = "application";
638 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
639 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
640 arg(app->resourceMgr()->stringValue("ExternalBrowser",
642 arg(myHelpFileName));
646 //=================================================================================
647 // function : onTextChange()
649 //=================================================================================
650 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
657 buttonOk->setEnabled(false);
658 buttonApply->setEnabled(false);
660 mySimulation->SetVisibility(false);
662 // hilight entered nodes
663 SMDS_Mesh* aMesh = 0;
665 aMesh = myActor->GetObject()->GetMesh();
668 TColStd_MapOfInteger newIndices;
670 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
672 for (int i = 0; i < aListId.count(); i++) {
673 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
675 newIndices.Add( n->GetID() );
682 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
683 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
684 aViewWindow->highlight( myActor->getIO(), true, true );
686 myNbOkNodes = ( allOk && ( myNbNodes == aListId.count() || myNbNodes == 1 ));
690 if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
693 myNbOkNodes = aListId.count();
698 buttonOk->setEnabled(true);
699 buttonApply->setEnabled(true);
706 //=================================================================================
707 // function : SelectionIntoArgument()
708 // purpose : Called when selection has changed
709 //=================================================================================
710 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
719 myEditCurrentArgument->setText("");
722 if (!GroupButtons->isEnabled()) // inactive
725 buttonOk->setEnabled(false);
726 buttonApply->setEnabled(false);
728 mySimulation->SetVisibility(false);
729 // SMESH::SetPointRepresentation(true);
731 QString aCurrentEntry = myEntry;
735 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
737 if (aList.Extent() != 1)
740 Handle(SALOME_InteractiveObject) anIO = aList.First();
741 myEntry = anIO->getEntry();
742 myMesh = SMESH::GetMeshByIO(anIO);
743 if (myMesh->_is_nil())
747 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
749 ComboBox_GroupName->clear();
750 ComboBox_GroupName->addItem( QString() );
751 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
752 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
753 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
754 if ( !aGroup->_is_nil() && aGroup->GetType() == (SMESH::ElementType)myElementType ) {
755 QString aGroupName( aGroup->GetName() );
756 if ( !aGroupName.isEmpty() ) {
757 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
758 ComboBox_GroupName->addItem( aGroupName );
764 myActor = SMESH::FindActorByEntry(anIO->getEntry());
768 // get selected nodes
769 QString aString = "";
770 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
772 myEditCurrentArgument->setText(aString);
774 if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
776 } else if (myNbNodes != nbNodes && myNbNodes != 1) {
781 myNbOkNodes = nbNodes;
783 buttonOk->setEnabled(true);
784 buttonApply->setEnabled(true);
789 //=================================================================================
790 // function : displaySimulation()
792 //=================================================================================
793 void SMESHGUI_AddMeshElementDlg::displaySimulation()
795 if (myNbOkNodes && GroupButtons->isEnabled()) {
796 SMESH::TElementSimulation::TVTKIds anIds;
797 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
798 for (int i = 0; i < aListId.count(); i++)
799 anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
801 if (Reverse && Reverse->isChecked())
803 const std::vector<int>& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
804 if ( i.empty() ) // polygon
805 std::reverse( anIds.begin(), anIds.end() );
807 SMDS_MeshCell::applyInterlace( i, anIds );
810 vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType );
811 mySimulation->SetPosition(myActor,aType,anIds);
816 //=================================================================================
817 // function : SetEditCurrentArgument()
819 //=================================================================================
820 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
822 QPushButton* send = (QPushButton*)sender();
823 if (send == SelectButtonC1A1) {
824 LineEditC1A1->setFocus();
825 myEditCurrentArgument = LineEditC1A1;
827 SelectionIntoArgument();
830 //=================================================================================
831 // function : DeactivateActiveDialog()
833 //=================================================================================
834 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
836 if (GroupConstructors->isEnabled()) {
837 GroupConstructors->setEnabled(false);
838 GroupC1->setEnabled(false);
839 GroupButtons->setEnabled(false);
840 mySimulation->SetVisibility(false);
841 mySMESHGUI->ResetState();
842 mySMESHGUI->SetActiveDialogBox(0);
846 //=================================================================================
847 // function : ActivateThisDialog()
849 //=================================================================================
850 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
852 /* Emit a signal to deactivate the active dialog */
853 mySMESHGUI->EmitSignalDeactivateDialog();
855 GroupConstructors->setEnabled(true);
856 GroupC1->setEnabled(true);
857 GroupButtons->setEnabled(true);
859 SMESH::SetPointRepresentation(true);
861 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
862 aViewWindow->SetSelectionMode( NodeSelection );
863 SelectionIntoArgument();
866 //=================================================================================
867 // function : enterEvent()
869 //=================================================================================
870 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
872 if (GroupConstructors->isEnabled())
874 ActivateThisDialog();
877 //=================================================================================
878 // function : CheckBox()
880 //=================================================================================
881 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
887 mySimulation->SetVisibility(false);
892 //=================================================================================
893 // function : keyPressEvent()
895 //=================================================================================
896 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
898 QDialog::keyPressEvent( e );
899 if ( e->isAccepted() )
902 if ( e->key() == Qt::Key_F1 ) {
908 //=================================================================================
909 // function : isValid
911 //=================================================================================
912 bool SMESHGUI_AddMeshElementDlg::isValid()
914 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
915 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );