1 // Copyright (C) 2007-2016 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_ExtrusionAlongPathDlg.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S.
28 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
31 #include "SMESHGUI_ExtrusionDlg.h" // for SMESHGUI_3TypesSelector
32 #include "SMESHGUI_FilterDlg.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_MeshEditPreview.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_SpinBox.h"
37 #include "SMESHGUI_Utils.h"
38 #include "SMESHGUI_VTKUtils.h"
40 #include <SMESH_Actor.h>
41 #include <SMESH_TypeFilter.hxx>
42 #include <SMESH_NumberFilter.hxx>
43 #include <SMESH_LogicalFilter.hxx>
45 #include <SMDS_Mesh.hxx>
47 // SALOME GEOM includes
50 // SALOME GUI includes
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_MessageBox.h>
55 #include <SUIT_Session.h>
56 #include <LightApp_Application.h>
57 #include <LightApp_SelectionMgr.h>
58 #include <SVTK_ViewWindow.h>
61 #include <BRep_Tool.hxx>
62 #include <TopoDS_Vertex.hxx>
64 #include <TColStd_MapOfInteger.hxx>
67 #include <QButtonGroup>
71 #include <QPushButton>
72 #include <QToolButton>
73 #include <QRadioButton>
75 #include <QListWidget>
76 #include <QVBoxLayout>
77 #include <QHBoxLayout>
78 #include <QGridLayout>
82 #include <SALOMEconfig.h>
83 #include CORBA_SERVER_HEADER(SMESH_Group)
84 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
89 class SMESHGUI_ExtrusionAlongPathDlg::SetBusy
92 SetBusy( SMESHGUI_ExtrusionAlongPathDlg* _dlg )
100 myDlg->myBusy = false;
104 SMESHGUI_ExtrusionAlongPathDlg* myDlg;
107 //=================================================================================
108 // function : SMESHGUI_ExtrusionAlongPathDlg()
109 // purpose : constructor
110 //=================================================================================
111 SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg( SMESHGUI* theModule )
112 : SMESHGUI_PreviewDlg( theModule ),
113 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
115 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
116 QPixmap selectImage ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
117 QPixmap addImage ( mgr->loadPixmap("SMESH", tr("ICON_APPEND")));
118 QPixmap removeImage ( mgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
121 setAttribute( Qt::WA_DeleteOnClose, true );
122 setWindowTitle(tr("EXTRUSION_ALONG_PATH"));
123 setSizeGripEnabled(true);
125 QVBoxLayout* topLayout = new QVBoxLayout(this);
126 topLayout->setSpacing(SPACING);
127 topLayout->setMargin(MARGIN);
129 /***************************************************************/
130 // Arguments group box
131 GroupArguments = new QGroupBox(tr("SMESH_EXTRUSION"), this);
132 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
133 GroupArgumentsLayout->setSpacing(SPACING); GroupArgumentsLayout->setMargin(MARGIN);
135 myIdValidator = new SMESHGUI_IdValidator(this);
137 // Controls for elements selection
138 SelectorWdg = new SMESHGUI_3TypesSelector( GroupArguments );
140 // Controls for path selection
141 PathGrp = new QGroupBox(tr("SMESH_PATH"), GroupArguments);
142 QGridLayout* PathGrpLayout = new QGridLayout(PathGrp);
143 PathGrpLayout->setSpacing(SPACING); PathGrpLayout->setMargin(MARGIN);
145 // Controls for path mesh selection
146 QLabel* PathMeshLab = new QLabel(tr("SMESH_PATH_MESH"), PathGrp);
148 SelectPathMeshButton = new QPushButton(PathGrp);
149 SelectPathMeshButton->setIcon(selectImage);
150 SelectPathMeshButton->setCheckable(true);
152 PathMeshLineEdit = new QLineEdit(PathGrp);
153 PathMeshLineEdit->setReadOnly(true);
155 // Controls for path starting point selection
156 QLabel* StartPointLab = new QLabel(tr("SMESH_PATH_START"), PathGrp);
158 SelectStartPointButton = new QPushButton(PathGrp);
159 SelectStartPointButton->setIcon(selectImage);
160 SelectStartPointButton->setCheckable(true);
162 StartPointLineEdit = new QLineEdit(PathGrp);
163 StartPointLineEdit->setValidator(new QIntValidator(this));
166 PathGrpLayout->addWidget(PathMeshLab, 0, 0);
167 PathGrpLayout->addWidget(SelectPathMeshButton, 0, 1);
168 PathGrpLayout->addWidget(PathMeshLineEdit, 0, 2);
169 PathGrpLayout->addWidget(StartPointLab, 1, 0);
170 PathGrpLayout->addWidget(SelectStartPointButton, 1, 1);
171 PathGrpLayout->addWidget(StartPointLineEdit, 1, 2);
173 BasePointGrp = new QGroupBox(tr("SMESH_BASE_POINT"), GroupArguments);
174 BasePointGrp->setCheckable(true);
175 BasePointGrp->setChecked(false);
176 QHBoxLayout* BasePointGrpLayout = new QHBoxLayout(BasePointGrp);
177 BasePointGrpLayout->setSpacing(SPACING); BasePointGrpLayout->setMargin(MARGIN);
179 SelectBasePointButton = new QPushButton(BasePointGrp);
180 SelectBasePointButton->setIcon(selectImage);
181 SelectBasePointButton->setCheckable(true);
183 SelectorWdg->GetButtonGroup()->addButton( SelectPathMeshButton );
184 SelectorWdg->GetButtonGroup()->addButton( SelectStartPointButton );
185 SelectorWdg->GetButtonGroup()->addButton( SelectBasePointButton );
187 QLabel* XLab = new QLabel(tr("SMESH_X"), BasePointGrp);
188 XSpin = new SMESHGUI_SpinBox(BasePointGrp);
189 QLabel* YLab = new QLabel(tr("SMESH_Y"), BasePointGrp);
190 YSpin = new SMESHGUI_SpinBox(BasePointGrp);
191 QLabel* ZLab = new QLabel(tr("SMESH_Z"), BasePointGrp);
192 ZSpin = new SMESHGUI_SpinBox(BasePointGrp);
195 BasePointGrpLayout->addWidget(SelectBasePointButton);
196 BasePointGrpLayout->addWidget(XLab);
197 BasePointGrpLayout->addWidget(XSpin);
198 BasePointGrpLayout->addWidget(YLab);
199 BasePointGrpLayout->addWidget(YSpin);
200 BasePointGrpLayout->addWidget(ZLab);
201 BasePointGrpLayout->addWidget(ZSpin);
203 AnglesGrp = new QGroupBox(tr("SMESH_ANGLES"), GroupArguments);
204 AnglesGrp->setCheckable(true);
205 AnglesGrp->setChecked(false);
206 QGridLayout* AnglesGrpLayout = new QGridLayout(AnglesGrp);
207 AnglesGrpLayout->setSpacing(SPACING); AnglesGrpLayout->setMargin(MARGIN);
209 AnglesList = new QListWidget(AnglesGrp);
210 AnglesList->setSelectionMode(QListWidget::ExtendedSelection);
212 AddAngleButton = new QToolButton(AnglesGrp);
213 AddAngleButton->setIcon(addImage);
215 RemoveAngleButton = new QToolButton(AnglesGrp);
216 RemoveAngleButton->setIcon(removeImage);
218 AngleSpin = new SMESHGUI_SpinBox(AnglesGrp);
220 LinearAnglesCheck = new QCheckBox(tr("LINEAR_ANGLES"), AnglesGrp);
223 AnglesGrpLayout->addWidget(AnglesList, 0, 0, 4, 1);
224 AnglesGrpLayout->addWidget(AddAngleButton, 0, 1);
225 AnglesGrpLayout->addWidget(RemoveAngleButton, 2, 1);
226 AnglesGrpLayout->addWidget(AngleSpin, 0, 2);
227 AnglesGrpLayout->addWidget(LinearAnglesCheck, 4, 0);
228 AnglesGrpLayout->setRowMinimumHeight(1, 10);
229 AnglesGrpLayout->setRowStretch(3, 10);
231 // CheckBox for groups generation
232 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
233 MakeGroupsCheck->setChecked(true);
236 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
239 GroupArgumentsLayout->addWidget(SelectorWdg, 0, 0);
240 GroupArgumentsLayout->addWidget(PathGrp, 1, 0);
241 GroupArgumentsLayout->addWidget(BasePointGrp, 2, 0);
242 GroupArgumentsLayout->addWidget(AnglesGrp, 3, 0);
243 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 4, 0);
244 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 0);
246 /***************************************************************/
247 // common buttons group box
248 GroupButtons = new QGroupBox(this);
249 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
250 GroupButtonsLayout->setSpacing(SPACING); GroupButtonsLayout->setMargin(MARGIN);
252 OkButton = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
253 OkButton->setAutoDefault(true);
254 OkButton->setDefault(true);
256 ApplyButton = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
257 ApplyButton->setAutoDefault(true);
259 CloseButton = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
260 CloseButton->setAutoDefault(true);
262 HelpButton = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
263 HelpButton->setAutoDefault(true);
266 GroupButtonsLayout->addWidget(OkButton);
267 GroupButtonsLayout->addSpacing(10);
268 GroupButtonsLayout->addWidget(ApplyButton);
269 GroupButtonsLayout->addSpacing(10);
270 GroupButtonsLayout->addStretch();
271 GroupButtonsLayout->addWidget(CloseButton);
272 GroupButtonsLayout->addWidget(HelpButton);
274 /***************************************************************/
276 topLayout->addWidget(GroupArguments);
277 topLayout->addWidget(GroupButtons);
279 /***************************************************************/
281 XSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
282 YSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
283 ZSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
284 AngleSpin->RangeStepAndValidator(-180.0, 180.0, 5.0, "angle_precision");
286 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
288 mySMESHGUI->SetActiveDialogBox(this);
290 myPathMeshFilter = new SMESH_TypeFilter(SMESH::MESHorSUBMESH);
292 myHelpFileName = "extrusion_along_path_page.html";
296 /***************************************************************/
297 // signals-slots connections
298 connect(OkButton, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
299 connect(CloseButton, SIGNAL(clicked()), this, SLOT(reject()));
300 connect(ApplyButton, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
301 connect(HelpButton, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
303 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleAdded()));
304 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleRemoved()));
306 connect(SelectPathMeshButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(SelectStartPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(SelectBasePointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(BasePointGrp, SIGNAL(toggled(bool)), this, SLOT(SetEditCurrentArgument()));
311 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
312 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT(onOpenView()));
313 connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT(onCloseView()));
314 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
315 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
316 connect(SelectorWdg, SIGNAL(selectionChanged()), this, SLOT(toDisplaySimulation()));
317 connect(SelectorWdg, SIGNAL(selectionChanged()), this, SLOT(CheckIsEnable()));
319 connect(StartPointLineEdit, SIGNAL(textChanged(const QString&)),
320 SLOT(onTextChange(const QString&)));
322 connect(XSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(YSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(ZSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
326 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
327 //connect(LinearAnglesCheck, SIGNAL(toggled(bool)), SLOT(onSelectMesh()));
330 //To Connect preview check box
331 connectPreviewControl();
333 AnglesList ->installEventFilter(this);
334 StartPointLineEdit->installEventFilter(this);
335 XSpin->editor() ->installEventFilter(this);
336 YSpin->editor() ->installEventFilter(this);
337 ZSpin->editor() ->installEventFilter(this);
342 //=================================================================================
343 // function : ~SMESHGUI_ExtrusionAlongPathDlg()
344 // purpose : destructor
345 //=================================================================================
346 SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg()
348 // no need to delete child widgets, Qt does it all for us
351 //=================================================================================
353 // purpose : initialization
354 //=================================================================================
355 void SMESHGUI_ExtrusionAlongPathDlg::Init (bool ResetControls)
358 myEditCurrentArgument = 0;
360 myPath = SMESH::SMESH_IDSource::_nil();
362 SelectorWdg->Clear();
363 PathMeshLineEdit->clear();
364 StartPointLineEdit->clear();
367 XSpin->SetValue(0.0);
368 YSpin->SetValue(0.0);
369 ZSpin->SetValue(0.0);
371 AngleSpin->SetValue(45);
372 myPreviewCheckBox->setChecked(false);
373 onDisplaySimulation(false);
375 SetEditCurrentArgument(0);
378 //=================================================================================
379 // function : CheckIsEnable()
380 // purpose : Check whether the Ok and Apply buttons should be enabled or not
381 //=================================================================================
383 void SMESHGUI_ExtrusionAlongPathDlg::CheckIsEnable()
385 bool anIsEnable = SelectorWdg->IsAnythingSelected() && isValuesValid();
387 OkButton->setEnabled(anIsEnable);
388 ApplyButton->setEnabled(anIsEnable);
391 //=================================================================================
392 // function : ClickOnApply()
393 // purpose : Called when user presses <Apply> button
394 //=================================================================================
395 bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
397 if (SMESHGUI::isStudyLocked())
400 if ( !SelectorWdg->IsAnythingSelected() || myPath->_is_nil() )
406 if (StartPointLineEdit->text().trimmed().isEmpty()) {
411 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
416 QStringList aParameters;
419 SMESH::double_array_var anAngles = getAngles();
421 for (int i = 0; i < myAnglesList.count(); i++)
422 aParameters << AnglesList->item(i)->text();
426 SMESH::PointStruct aBasePoint;
427 if (BasePointGrp->isChecked()) {
428 aBasePoint.x = XSpin->GetValue();
429 aBasePoint.y = YSpin->GetValue();
430 aBasePoint.z = ZSpin->GetValue();
432 aParameters << XSpin->text();
433 aParameters << YSpin->text();
434 aParameters << ZSpin->text();
436 bool meshHadNewTypeBefore = true;
438 const bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
441 SUIT_OverrideCursor wc;
443 SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
445 mesh->SetParameters( aParameters.join(":").toUtf8().constData() );
447 SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
448 SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
449 SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
450 maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
452 // is it necessary to switch on the next Display Mode?
453 SMESH::ElementType newType = (SMESH::ElementType)( maxSelType + 1 );
454 SMESH::array_of_ElementType_var oldTypes = mesh->GetTypes();
455 meshHadNewTypeBefore = false;
456 for ( size_t i = 0; i < oldTypes->length() && !meshHadNewTypeBefore; ++i )
457 meshHadNewTypeBefore = ( oldTypes[i] >= newType );
459 SMESH::SMESH_MeshEditor_var aMeshEditor = mesh->GetMeshEditor();
460 SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
462 SMESH::ListOfGroups_var groups =
463 aMeshEditor->ExtrusionAlongPathObjects( nodes, edges, faces, myPath,
464 GEOM::GEOM_Object::_nil(),
465 aNodeStart, AnglesGrp->isChecked(),
466 anAngles, LinearAnglesCheck->isChecked(),
467 BasePointGrp->isChecked(), aBasePoint,
468 makeGroups, retVal );
472 case SMESH::SMESH_MeshEditor::EXTR_NO_ELEMENTS:
473 SUIT_MessageBox::warning(this,
475 tr("NO_ELEMENTS_SELECTED"));
477 case SMESH::SMESH_MeshEditor::EXTR_PATH_NOT_EDGE:
478 SUIT_MessageBox::warning(this,
480 tr("SELECTED_PATH_IS_NOT_EDGE"));
482 case SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE:
483 SUIT_MessageBox::warning(this,
485 tr("BAD_SHAPE_TYPE"));
487 case SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE:
488 SUIT_MessageBox::warning(this,
490 tr("EXTR_BAD_STARTING_NODE"));
492 case SMESH::SMESH_MeshEditor::EXTR_BAD_ANGLES_NUMBER:
493 SUIT_MessageBox::warning(this,
495 tr("WRONG_ANGLES_NUMBER"));
497 case SMESH::SMESH_MeshEditor::EXTR_CANT_GET_TANGENT:
498 SUIT_MessageBox::warning(this,
500 tr("CANT_GET_TANGENT"));
502 case SMESH::SMESH_MeshEditor::EXTR_OK:
509 SMESH_Actor* actor = SelectorWdg->GetActor();
510 if ( actor && !meshHadNewTypeBefore )
512 unsigned int aMode = actor->GetEntityMode();
513 switch ( maxSelType ) {
514 case SMESH::NODE: // extrude node -> edges
515 actor->SetRepresentation(SMESH_Actor::eEdge);
516 actor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
517 case SMESH::EDGE: // edge -> faces
518 actor->SetRepresentation(SMESH_Actor::eSurface);
519 actor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
520 case SMESH::FACE: // faces -> volumes
521 actor->SetRepresentation(SMESH_Actor::eSurface);
522 actor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
526 SMESH::Update( actor->getIO(), actor->GetVisibility() );
528 mySMESHGUI->updateObjBrowser(true); // new groups may appear
530 mySelectionMgr->clearSelected();
531 SelectorWdg->Clear();
533 SMESHGUI::Modified();
537 //=================================================================================
538 // function : ClickOnOk()
539 // purpose : Called when user presses <OK> button
540 //=================================================================================
541 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk()
547 //=================================================================================
548 // function : ClickOnHelp()
550 //=================================================================================
551 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnHelp()
553 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
555 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
559 platform = "winapplication";
561 platform = "application";
563 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
564 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
565 arg(app->resourceMgr()->stringValue("ExternalBrowser",
567 arg(myHelpFileName));
571 //=================================================================================
572 // function : reject()
573 // purpose : Called when dialog box is closed
574 //=================================================================================
575 void SMESHGUI_ExtrusionAlongPathDlg::reject()
577 disconnect(mySelectionMgr, 0, this, 0);
578 mySelectionMgr->clearFilters();
579 //mySelectionMgr->clearSelected();
580 if (SMESH::GetCurrentVtkView()) {
581 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
582 SMESH::SetPointRepresentation(false);
583 SMESH::SetPickable();
585 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
586 aViewWindow->SetSelectionMode(ActorSelection);
587 mySMESHGUI->ResetState();
592 //=================================================================================
593 // function : onOpenView()
595 //=================================================================================
596 void SMESHGUI_ExtrusionAlongPathDlg::onOpenView()
599 SMESH::SetPointRepresentation(false);
602 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
603 ActivateThisDialog();
607 //=================================================================================
608 // function : onCloseView()
610 //=================================================================================
611 void SMESHGUI_ExtrusionAlongPathDlg::onCloseView()
613 DeactivateActiveDialog();
617 //=======================================================================
618 // function : onTextChange()
620 //=======================================================================
621 void SMESHGUI_ExtrusionAlongPathDlg::onTextChange (const QString& theNewText)
623 QLineEdit* send = (QLineEdit*)sender();
631 if (send == StartPointLineEdit &&
632 myEditCurrentArgument == StartPointLineEdit)
634 if (!myPath->_is_nil()) {
635 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
636 SMDS_Mesh* aMesh = aPathActor ? aPathActor->GetObject()->GetMesh() : 0;
639 aList.Append(aPathActor->getIO());
640 mySelectionMgr->setSelectedObjects(aList, false);
643 long ind = theNewText.toLong(&bOk);
645 const SMDS_MeshNode* n = aMesh->FindNode(ind);
647 TColStd_MapOfInteger newIndices;
648 newIndices.Add(n->GetID());
649 mySelector->AddOrRemoveIndex( aPathActor->getIO(), newIndices, false );
650 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
651 aViewWindow->highlight( aPathActor->getIO(), true, true );
658 onDisplaySimulation(true);
661 //=================================================================================
662 // function : SelectionIntoArgument()
663 // purpose : Called when selection as changed or other case
664 //=================================================================================
665 void SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument()
669 // return if dialog box is inactive
670 if (!GroupButtons->isEnabled())
673 // selected objects count
674 const SALOME_ListIO& aList = mySelector->StoredIObjects();
675 int nbSel = aList.Extent();
682 const bool isPathDef = ( SelectPathMeshButton->isChecked() ||
683 SelectStartPointButton->isChecked() );
685 if (myEditCurrentArgument == PathMeshLineEdit && isPathDef)
687 // we are now selecting path mesh
689 PathMeshLineEdit->clear();
690 myPath = SMESH::SMESH_IDSource::_nil();
691 StartPointLineEdit->clear();
693 // try to get mesh from selection
694 Handle(SALOME_InteractiveObject) IO = aList.First();
695 myPath = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
696 if( myPath->_is_nil() )
700 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
701 PathMeshLineEdit->setText(aString);
703 else if (myEditCurrentArgument == StartPointLineEdit && isPathDef )
705 // we are now selecting start point of path
707 StartPointLineEdit->clear();
709 // return if path mesh or path shape is not yet selected
710 if( myPath->_is_nil() )
713 // try to get shape from selection
714 Handle(SALOME_InteractiveObject) IO = aList.First();
716 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
721 int aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aPathActor->getIO(), aString);
723 StartPointLineEdit->setText(aString.trimmed());
725 else if ( myEditCurrentArgument == XSpin &&
726 SelectBasePointButton->isChecked() )
728 // we are now selecting base point
729 // reset is not performed here!
731 // return if is not enabled
732 if (!BasePointGrp->isChecked())
735 // try to get shape from selection
736 Handle(SALOME_InteractiveObject) IO = aList.First();
738 // check if geom vertex is selected
739 GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
740 TopoDS_Vertex aVertex;
741 if (!aGeomObj->_is_nil()) {
742 if (aGeomObj->IsShape() && GEOMBase::GetShape(aGeomObj, aVertex) && !aVertex.IsNull()) {
743 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
744 XSpin->SetValue(aPnt.X());
745 YSpin->SetValue(aPnt.Y());
746 ZSpin->SetValue(aPnt.Z());
751 // check if smesh node is selected
752 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
753 if (aMesh->_is_nil())
757 int aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
758 // return if more than one node is selected
762 SMESH_Actor* aMeshActor = SMESH::FindActorByObject(aMesh);
766 SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
770 const SMDS_MeshNode* n = mesh->FindNode(aString.toLong());
774 XSpin->SetValue(n->X());
775 YSpin->SetValue(n->Y());
776 ZSpin->SetValue(n->Z());
783 onDisplaySimulation(true);
787 //=================================================================================
788 // function : SetEditCurrentArgument()
790 //=================================================================================
791 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
793 QPushButton* send = (QPushButton*)sender();
794 if ( sender() == BasePointGrp )
795 send = SelectBasePointButton;
796 if (send != SelectPathMeshButton &&
797 send != SelectStartPointButton &&
798 send != SelectBasePointButton)
800 SetEditCurrentArgument(send);
803 //=================================================================================
804 // function : SetEditCurrentArgument()
806 //=================================================================================
807 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument (QPushButton* button)
809 disconnect(mySelectionMgr, 0, this, 0);
810 // mySelectionMgr->clearSelected();
811 mySelectionMgr->clearFilters();
812 SMESH::SetPickable();
814 myEditCurrentArgument = 0;
815 if (button == SelectPathMeshButton)
817 myEditCurrentArgument = PathMeshLineEdit;
818 SMESH::SetPointRepresentation(false);
819 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
820 aViewWindow->SetSelectionMode(ActorSelection);
821 mySelectionMgr->installFilter(myPathMeshFilter);
823 else if (button == SelectStartPointButton)
825 myEditCurrentArgument = StartPointLineEdit;
826 if (!myPath->_is_nil()) {
827 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
829 aPathActor->SetPointRepresentation( true );
830 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
831 aViewWindow->SetSelectionMode(NodeSelection);
832 SMESH::SetPickable(aPathActor);
836 else if (button == SelectBasePointButton)
838 myEditCurrentArgument = XSpin;
839 SMESH::SetPointRepresentation(true);
840 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
841 aViewWindow->SetSelectionMode(NodeSelection);
843 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter(SMESH::IDSOURCE);
844 SMESH_NumberFilter* aVertexFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE,
846 QList<SUIT_SelectionFilter*> aListOfFilters;
847 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
848 if (aVertexFilter) aListOfFilters.append(aVertexFilter);
850 mySelectionMgr->installFilter(new SMESH_LogicalFilter
851 (aListOfFilters, SMESH_LogicalFilter::LO_OR, true));
854 if (myEditCurrentArgument && !myEditCurrentArgument->hasFocus())
855 myEditCurrentArgument->setFocus();
857 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
858 SelectionIntoArgument();
861 //=================================================================================
862 // function : DeactivateActiveDialog()
863 // purpose : Deactivates this dialog
864 //=================================================================================
865 void SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog()
867 if (GroupButtons->isEnabled())
869 GroupArguments->setEnabled(false);
870 GroupButtons->setEnabled(false);
871 SelectorWdg->setEnabled(false);
872 mySMESHGUI->ResetState();
873 mySMESHGUI->SetActiveDialogBox(0);
877 //=================================================================================
878 // function : ActivateThisDialog()
879 // purpose : Activates this dialog
880 //=================================================================================
881 void SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog()
883 // Emit a signal to deactivate the active dialog
884 mySMESHGUI->EmitSignalDeactivateDialog();
885 GroupArguments->setEnabled(true);
886 GroupButtons->setEnabled(true);
887 SelectorWdg->setEnabled(true);
889 mySMESHGUI->SetActiveDialogBox(this);
890 SelectionIntoArgument();
893 //=================================================================================
894 // function : enterEvent()
896 //=================================================================================
897 void SMESHGUI_ExtrusionAlongPathDlg::enterEvent (QEvent*)
899 if ( !GroupButtons->isEnabled() ) {
900 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
901 if ( aViewWindow && !mySelector) {
902 mySelector = aViewWindow->GetSelector();
904 ActivateThisDialog();
908 //=======================================================================
909 // function : OnAngleAdded()
910 // purpose : Called when user adds angle to the list
911 //=======================================================================
912 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded()
915 if( !AngleSpin->isValid( msg, true ) ) {
916 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
917 if ( !msg.isEmpty() )
919 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
922 AnglesList->addItem(AngleSpin->text());
923 myAnglesList.append(AngleSpin->GetValue());
925 updateLinearAngles();
928 //=======================================================================
929 // function : OnAngleRemoved()
930 // purpose : Called when user removes angle(s) from the list
931 //=======================================================================
932 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved()
934 QList<QListWidgetItem*> aList = AnglesList->selectedItems();
935 QListWidgetItem* anItem;
936 foreach(anItem, aList) {
937 myAnglesList.removeAt(AnglesList->row(anItem));
941 updateLinearAngles();
944 //=================================================================================
945 // function : eventFilter()
946 // purpose : event filter ???
947 //=================================================================================
948 bool SMESHGUI_ExtrusionAlongPathDlg::eventFilter (QObject* object, QEvent* event)
950 if (event->type() == QEvent::KeyPress) {
951 QKeyEvent* ke = (QKeyEvent*)event;
952 if (object == AnglesList) {
953 if (ke->key() == Qt::Key_Delete)
957 else if (event->type() == QEvent::FocusIn) {
958 if (object == StartPointLineEdit) {
959 if (myEditCurrentArgument != StartPointLineEdit)
960 SetEditCurrentArgument(SelectStartPointButton);
962 else if (object == XSpin->editor() || object == YSpin->editor() || object == ZSpin->editor()) {
963 if (myEditCurrentArgument != XSpin)
964 SetEditCurrentArgument(SelectBasePointButton);
967 return QDialog::eventFilter(object, event);
970 //=================================================================================
971 // function : keyPressEvent()
973 //=================================================================================
974 void SMESHGUI_ExtrusionAlongPathDlg::keyPressEvent( QKeyEvent* e )
976 QDialog::keyPressEvent( e );
977 if ( e->isAccepted() )
980 if ( e->key() == Qt::Key_F1 ) {
986 //=================================================================================
987 // function : isValid
989 //=================================================================================
990 bool SMESHGUI_ExtrusionAlongPathDlg::isValid()
994 ok = XSpin->isValid( msg, true ) && ok;
995 ok = YSpin->isValid( msg, true ) && ok;
996 ok = ZSpin->isValid( msg, true ) && ok;
999 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1000 if ( !msg.isEmpty() )
1002 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1008 //=================================================================================
1009 // function : updateLinearAngles
1011 //=================================================================================
1012 void SMESHGUI_ExtrusionAlongPathDlg::updateLinearAngles()
1014 bool enableLinear = true;
1015 for( int row = 0, nbRows = AnglesList->count(); row < nbRows; row++ ) {
1016 if( QListWidgetItem* anItem = AnglesList->item( row ) ) {
1017 enableLinear = false;
1018 anItem->text().toDouble(&enableLinear);
1024 LinearAnglesCheck->setChecked( false );
1025 LinearAnglesCheck->setEnabled( enableLinear );
1028 //=================================================================================
1029 // function : isValuesValid()
1030 // purpose : Return true in case if values entered into dialog are valid
1031 //=================================================================================
1033 bool SMESHGUI_ExtrusionAlongPathDlg::isValuesValid()
1035 if ( myPath->_is_nil() )
1039 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
1040 if ( !bOk || aNodeStart < 1 )
1043 SMESH::SMESH_Mesh_var mesh = myPath->GetMesh();
1044 if ( mesh->_is_nil() )
1047 SMESH::ElementType type = mesh->GetElementType( aNodeStart, false );
1048 if ( type != SMESH::NODE )
1051 if ( mesh->HasShapeToMesh() )
1053 SMESH::NodePosition_var pos = mesh->GetNodePosition( aNodeStart );
1054 if ( pos->shapeType != GEOM::VERTEX )
1059 SMESH::long_array_var elems = mesh->GetNodeInverseElements( aNodeStart );
1060 if ( elems->length() != 1 ||
1061 mesh->GetElementType( elems[0], true ) != SMESH::EDGE )
1067 //=================================================================================
1068 // function : onDisplaySimulation
1069 // purpose : Show/Hide preview
1070 //=================================================================================
1072 void SMESHGUI_ExtrusionAlongPathDlg::onDisplaySimulation( bool toDisplayPreview )
1074 if ( myPreviewCheckBox->isChecked() && toDisplayPreview ) {
1075 if ( SelectorWdg->IsAnythingSelected() && isValid() && isValuesValid())
1078 SMESH::double_array_var anAngles = getAngles();
1081 SMESH::PointStruct aBasePoint;
1082 if (BasePointGrp->isChecked()) {
1083 aBasePoint.x = XSpin->GetValue();
1084 aBasePoint.y = YSpin->GetValue();
1085 aBasePoint.z = ZSpin->GetValue();
1088 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
1092 SUIT_OverrideCursor wc;
1094 SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
1095 SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
1096 SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditPreviewer();
1098 SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1099 SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1100 SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1101 SelectorWdg->GetSelected( nodes, edges, faces );
1102 const bool makeGroups = false;
1104 SMESH::ListOfGroups_var groups =
1105 meshEditor->ExtrusionAlongPathObjects( nodes, edges, faces, myPath,
1106 GEOM::GEOM_Object::_nil(),
1107 aNodeStart, AnglesGrp->isChecked(),
1108 anAngles, LinearAnglesCheck->isChecked(),
1109 BasePointGrp->isChecked(), aBasePoint,
1110 makeGroups, retVal );
1112 if( retVal == SMESH::SMESH_MeshEditor::EXTR_OK )
1114 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = meshEditor->GetPreviewData();
1115 mySimulation->SetData( aMeshPreviewStruct._retn() );
1136 SMESH::double_array_var SMESHGUI_ExtrusionAlongPathDlg::getAngles()
1138 SMESH::double_array_var anAngles = new SMESH::double_array;
1139 if (AnglesGrp->isChecked())
1141 anAngles->length(myAnglesList.count());
1143 for (int i = 0; i < myAnglesList.count(); i++) {
1144 double angle = myAnglesList[i];
1145 anAngles[ j++ ] = angle*M_PI/180.;
1147 anAngles->length(j);