1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : BasicGUI_PointDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "BasicGUI_PointDlg.h"
32 #include "QAD_RightFrame.h"
33 #include "OCCViewer_Viewer3d.h"
35 #include <BRepBuilderAPI_MakeVertex.hxx>
36 #include <BRep_Tool.hxx>
37 #include <Geom_Curve.hxx>
38 #if OCC_VERSION_MAJOR >= 5
39 #include <BRepAlgo.hxx>
41 #include <BRepAlgoAPI.hxx>
44 //=================================================================================
45 // class : BasicGUI_PointDlg()
46 // purpose : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 BasicGUI_PointDlg::BasicGUI_PointDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, const Handle (AIS_InteractiveContext)& ic, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
54 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POINT")));
55 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POINT_EDGE")));
56 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_POINT_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_POINTS"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->setPixmap(image1);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_3Spin(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_X"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_Y"));
70 GroupPoints->TextLabel3->setText(tr("GEOM_Z"));
72 GroupDimensions = new DlgRef_1Sel1Spin(this, "GroupDimensions");
73 GroupDimensions->GroupBox1->setTitle(tr("GEOM_PARAM_POINT"));
74 GroupDimensions->TextLabel1->setText(tr("GEOM_EDGE"));
75 GroupDimensions->TextLabel2->setText(tr("GEOM_PARAMETER"));
76 GroupDimensions->PushButton1->setPixmap(image2);
78 Layout1->addWidget(GroupPoints, 1, 0);
79 Layout1->addWidget(GroupDimensions, 1, 0);
80 /***************************************************************/
83 myBasicGUI = theBasicGUI;
88 //=======================================================================
89 // function : ~BasicGUI_PointDlg()
90 // purpose : Destructor
91 //=======================================================================
92 BasicGUI_PointDlg::~BasicGUI_PointDlg()
94 /* no need to delete child widgets, Qt does it all for us */
98 //=================================================================================
101 //=================================================================================
102 void BasicGUI_PointDlg::Init(const Handle(AIS_InteractiveContext)& ic)
106 myEditCurrentArgument = GroupDimensions->LineEdit1;
110 myPoint.SetCoord(0.0, 0.0, 0.0);
113 myGeomGUI->myState = 0;
115 /* Vertices Filter for all arguments */
116 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
118 /* Get setting of step value from file configuration */
119 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
120 step = St.toDouble();
122 /* min, max, step and decimals for spin boxes */
123 double specificStep = 0.1;
124 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999999.99999, 999999.99999, specificStep, 5);
125 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
126 GroupPoints->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
127 GroupPoints->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
128 GroupDimensions->SpinBox_DX->SetValue(myParameter);
129 GroupPoints->SpinBox_DX->SetValue(0.0);
130 GroupPoints->SpinBox_DY->SetValue(0.0);
131 GroupPoints->SpinBox_DZ->SetValue(0.0);
133 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
134 myLocalContextId = myIC->OpenLocalContext();
135 //myGeomBase->SetDisplayedObjectList();
136 /* sub shapes selection */
137 myLocalContextMode = TopAbs_VERTEX;
138 myIC->ActivateStandardMode(myLocalContextMode);
139 myUseLocalContext = true;
142 myUseLocalContext = false;
145 bool displayPoint = true;
146 if(myGeomBase->GetTopoFromSelection(mySelection, S)) {
147 /* Filter a possibly previous selection and try to put it into coordinates */
148 if(myGeomBase->VertexToPoint(S, myPoint))
149 displayPoint = false;
151 this->PointIntoCoordinates(myPoint, displayPoint);
153 /* signals and slots connections */
154 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
155 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
156 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
158 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
159 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
160 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
162 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
163 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168 connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
170 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
171 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
172 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
173 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
175 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
177 /* displays Dialog */
178 GroupDimensions->hide();
186 //=================================================================================
187 // function : ConstructorsClicked()
188 // purpose : Radio button management
189 //=================================================================================
190 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
192 myConstructorId = constructorId;
193 mySelection->ClearFilters();
194 myGeomBase->EraseSimulationShape();
195 mySimulationTopoDs.Nullify();
196 disconnect(mySelection, 0, this, 0);
198 switch (constructorId)
202 if(myUseLocalContext == false && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
203 myLocalContextId = myIC->OpenLocalContext();
204 //myGeomBase->SetDisplayedObjectList();
205 /* sub shapes selection */
206 myLocalContextMode = TopAbs_VERTEX;
207 myIC->ActivateStandardMode(myLocalContextMode);
208 myUseLocalContext = true;
211 GroupDimensions->hide();
215 /* Display point simulation */
216 PointIntoCoordinates(myPoint, true);
221 if(myUseLocalContext == true && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
222 myIC->CloseLocalContext(myLocalContextId);
223 myUseLocalContext = false;
228 GroupDimensions->show();
230 myEditCurrentArgument = GroupDimensions->LineEdit1;
231 GroupDimensions->LineEdit1->setText("");
234 /* filter for next selections */
235 mySelection->AddFilter(myEdgeFilter);
236 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
244 //=================================================================================
245 // function : ClickOnOk()
247 //=================================================================================
248 void BasicGUI_PointDlg::ClickOnOk()
250 this->ClickOnApply();
251 this->ClickOnCancel();
256 //=================================================================================
257 // function : ClickOnApply()
259 //=================================================================================
260 void BasicGUI_PointDlg::ClickOnApply()
262 QAD_Application::getDesktop()->putInfo(tr(""));
263 if(mySimulationTopoDs.IsNull())
265 myGeomBase->EraseSimulationShape();
266 mySimulationTopoDs.Nullify();
268 /* Close local context */
269 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
270 myIC->CloseLocalContext(myLocalContextId);
271 myUseLocalContext = false;
274 switch(myConstructorId)
278 /* Recup args and call method */
279 double x = GroupPoints->SpinBox_DX->GetValue();
280 double y = GroupPoints->SpinBox_DY->GetValue();
281 double z = GroupPoints->SpinBox_DZ->GetValue();
283 myBasicGUI->MakePointAndDisplay(x,y,z); /* WARNING : no display if a local context is opened */
284 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
285 /* no display if a local context is opened */
286 myLocalContextId = myIC->OpenLocalContext();
287 //myGeomBase->SetDisplayedObjectList();
288 /* sub shapes selection */
289 myLocalContextMode = TopAbs_VERTEX;
290 myIC->ActivateStandardMode(myLocalContextMode);
291 myUseLocalContext = true;
297 if(myOkEdge == true) {
298 /* this constructor method has no idl interface : we use same than constructor 0 */
299 myBasicGUI->MakePointAndDisplay(myPoint.X(), myPoint.Y(), myPoint.Z());
308 //=======================================================================
309 // function : ClickOnCancel()
311 //=======================================================================
312 void BasicGUI_PointDlg::ClickOnCancel()
314 if(myConstructorId == 0 && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
315 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
316 myIC = v3d->getAISContext();
317 if(myIC->HasOpenedContext()) {
318 myIC->CloseLocalContext(myLocalContextId);
319 myUseLocalContext = false;
323 myGeomGUI->myState = -1;
324 GEOMBase_Skeleton::ClickOnCancel();
329 //=================================================================================
330 // function : SelectionIntoArgument()
331 // purpose : Called when selection as changed (for constructors not using local context)
332 //=================================================================================
333 void BasicGUI_PointDlg::SelectionIntoArgument()
335 myGeomBase->EraseSimulationShape();
336 mySimulationTopoDs.Nullify();
337 myEditCurrentArgument->setText("");
338 QString aString = ""; /* name of selection */
340 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
348 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
351 if(S.ShapeType() == TopAbs_EDGE) {
352 if(CalculateVertexOnCurve(TopoDS::Edge(S), myParameter, mySimulationTopoDs)) {
353 if(myGeomBase->VertexToPoint(mySimulationTopoDs, myPoint)) {
354 GroupDimensions->LineEdit1->setText(aString);
356 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
364 //=================================================================================
365 // function : LineEditReturnPressed()
367 //=================================================================================
368 void BasicGUI_PointDlg::LineEditReturnPressed()
370 QLineEdit* send = (QLineEdit*)sender();
371 if(send == GroupDimensions->LineEdit1)
372 myEditCurrentArgument = GroupDimensions->LineEdit1;
376 GEOMBase_Skeleton::LineEditReturnPressed();
381 //=================================================================================
382 // function : SetEditCurrentArgument()
384 //=================================================================================
385 void BasicGUI_PointDlg::SetEditCurrentArgument()
387 QPushButton* send = (QPushButton*)sender();
389 if(send == GroupDimensions->PushButton1) {
390 GroupDimensions->LineEdit1->setFocus();
391 myEditCurrentArgument = GroupDimensions->LineEdit1;
392 mySelection->AddFilter(myEdgeFilter);
393 this->SelectionIntoArgument();
399 //=================================================================================
400 // function : enterEvent()
401 // purpose : to reactivate this dialog box when mouse enter onto the window
402 //=================================================================================
403 void BasicGUI_PointDlg::enterEvent(QEvent* e)
405 if (GroupConstructors->isEnabled())
407 this->ActivateThisDialog();
412 //=======================================================================
413 // function : closeEvent()
415 //=======================================================================
416 void BasicGUI_PointDlg::closeEvent(QCloseEvent* e)
418 /* same than click on cancel button */
419 this->ClickOnCancel();
423 //=================================================================================
424 // function : ActivateThisDialog()
426 //=================================================================================
427 void BasicGUI_PointDlg::ActivateThisDialog( )
429 GEOMBase_Skeleton::ActivateThisDialog();
430 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
432 myGeomGUI->myState = 0;
433 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
434 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
435 myIC = v3d->getAISContext();
436 myLocalContextId = myIC->OpenLocalContext();
437 //myGeomBase->SetDisplayedObjectList();
438 /* sub shapes selection */
439 myLocalContextMode = TopAbs_VERTEX;
440 myIC->ActivateStandardMode(myLocalContextMode);
441 myUseLocalContext = true;
444 if(myConstructorId == 1)
445 mySelection->AddFilter(myEdgeFilter);
447 if(!mySimulationTopoDs.IsNull())
448 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
453 //=================================================================================
454 // function : DeactivateActiveDialog()
455 // purpose : public slot to deactivate if active
456 //=================================================================================
457 void BasicGUI_PointDlg::DeactivateActiveDialog()
459 if(myConstructorId == 0 && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
460 myIC->CloseLocalContext(myLocalContextId);
461 myUseLocalContext = false;
463 myGeomGUI->myState = -1;
464 GEOMBase_Skeleton::DeactivateActiveDialog();
469 //=================================================================================
470 // function : ValueChangedInSpinBox()
472 //=================================================================================
473 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
475 DlgRef_SpinBox* send = (DlgRef_SpinBox*)sender();
478 if(send == GroupPoints->SpinBox_DX) {
480 vy = GroupPoints->SpinBox_DY->GetValue();
481 vz = GroupPoints->SpinBox_DZ->GetValue();
482 } else if(send == GroupPoints->SpinBox_DY) {
483 vx = GroupPoints->SpinBox_DX->GetValue();
485 vz = GroupPoints->SpinBox_DZ->GetValue();
486 } else if(send == GroupPoints->SpinBox_DZ) {
487 vx = GroupPoints->SpinBox_DX->GetValue();
488 vy = GroupPoints->SpinBox_DY->GetValue();
490 } else if(send == GroupDimensions->SpinBox_DX) {
491 myParameter = newValue;
495 switch(myConstructorId)
497 case 0: // default constructor
499 myPoint.SetCoord(vx, vy, vz);
500 mySimulationTopoDs = BRepBuilderAPI_MakeVertex (myPoint).Shape();
501 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
506 this->SelectionIntoArgument();
514 //=================================================================================
515 // function : CalculateVertexOnCurve()
516 // purpose : Calculate a Vertex on the curve given by 'anEdge'.
517 // : The position of resultVertex is given by aParameter.
518 // : For a linear edge, aParameter=0.0 gives the first vertex of edge
519 // : aParameter=1.0 gives the last vertex of edge
520 // : aParameter=0.5 gives the vertex on the middle of edge
521 // : It is possible to get vertices out of edge using values > 1.0 or < 0.0
522 //=================================================================================
523 bool BasicGUI_PointDlg::CalculateVertexOnCurve(const TopoDS_Edge& anEdge, const Standard_Real aParameter, TopoDS_Shape& resultVertex)
525 #if OCC_VERSION_MAJOR >= 5
526 if(anEdge.IsNull() || !BRepAlgo::IsValid(anEdge))
528 if(anEdge.IsNull() || !BRepAlgoAPI::IsValid(anEdge))
532 Standard_Real first, last;
533 Handle(Geom_Curve) curv = BRep_Tool::Curve(anEdge, first, last);
538 if(anEdge.Orientation() == TopAbs_FORWARD)
539 param = first + (last-first) * aParameter;
541 param = last + (first-last) * aParameter;
544 curv->D0(param, paramPoint);
545 resultVertex = BRepBuilderAPI_MakeVertex(paramPoint);
550 //=======================================================================
551 // funcion : PointIntoCoordinates()
552 // purpose : Sets user point coordinates into this dialog Spin boxes
553 // : and displays it or not according to 'bool displayPoint'
554 //=======================================================================
555 void BasicGUI_PointDlg::PointIntoCoordinates(gp_Pnt P, bool displayPoint)
557 GroupPoints->SpinBox_DX->SetValue(P.X());
558 GroupPoints->SpinBox_DY->SetValue(P.Y());
559 GroupPoints->SpinBox_DZ->SetValue(P.Z());
560 myPoint.SetCoord(P.X(), P.Y(), P.Z());
562 mySimulationTopoDs = BRepBuilderAPI_MakeVertex(P).Shape();
563 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);