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 buttonApply->setFocus();
263 QAD_Application::getDesktop()->putInfo(tr(""));
264 if(mySimulationTopoDs.IsNull())
266 myGeomBase->EraseSimulationShape();
267 mySimulationTopoDs.Nullify();
269 /* Close local context */
270 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
271 myIC->CloseLocalContext(myLocalContextId);
272 myUseLocalContext = false;
275 switch(myConstructorId)
279 /* Recup args and call method */
280 double x = GroupPoints->SpinBox_DX->GetValue();
281 double y = GroupPoints->SpinBox_DY->GetValue();
282 double z = GroupPoints->SpinBox_DZ->GetValue();
284 myBasicGUI->MakePointAndDisplay(x,y,z); /* WARNING : no display if a local context is opened */
285 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
286 /* no display if a local context is opened */
287 myLocalContextId = myIC->OpenLocalContext();
288 //myGeomBase->SetDisplayedObjectList();
289 /* sub shapes selection */
290 myLocalContextMode = TopAbs_VERTEX;
291 myIC->ActivateStandardMode(myLocalContextMode);
292 myUseLocalContext = true;
298 if(myOkEdge == true) {
299 /* this constructor method has no idl interface : we use same than constructor 0 */
300 myBasicGUI->MakePointAndDisplay(myPoint.X(), myPoint.Y(), myPoint.Z());
309 //=======================================================================
310 // function : ClickOnCancel()
312 //=======================================================================
313 void BasicGUI_PointDlg::ClickOnCancel()
315 if(myConstructorId == 0 && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
316 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
317 myIC = v3d->getAISContext();
318 if(myIC->HasOpenedContext()) {
319 myIC->CloseLocalContext(myLocalContextId);
320 myUseLocalContext = false;
324 myGeomGUI->myState = -1;
325 GEOMBase_Skeleton::ClickOnCancel();
330 //=================================================================================
331 // function : SelectionIntoArgument()
332 // purpose : Called when selection as changed (for constructors not using local context)
333 //=================================================================================
334 void BasicGUI_PointDlg::SelectionIntoArgument()
336 myGeomBase->EraseSimulationShape();
337 mySimulationTopoDs.Nullify();
338 myEditCurrentArgument->setText("");
339 QString aString = ""; /* name of selection */
341 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
349 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
352 if(S.ShapeType() == TopAbs_EDGE) {
353 if(CalculateVertexOnCurve(TopoDS::Edge(S), myParameter, mySimulationTopoDs)) {
354 if(myGeomBase->VertexToPoint(mySimulationTopoDs, myPoint)) {
355 GroupDimensions->LineEdit1->setText(aString);
357 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
365 //=================================================================================
366 // function : LineEditReturnPressed()
368 //=================================================================================
369 void BasicGUI_PointDlg::LineEditReturnPressed()
371 QLineEdit* send = (QLineEdit*)sender();
372 if(send == GroupDimensions->LineEdit1)
373 myEditCurrentArgument = GroupDimensions->LineEdit1;
377 GEOMBase_Skeleton::LineEditReturnPressed();
382 //=================================================================================
383 // function : SetEditCurrentArgument()
385 //=================================================================================
386 void BasicGUI_PointDlg::SetEditCurrentArgument()
388 QPushButton* send = (QPushButton*)sender();
390 if(send == GroupDimensions->PushButton1) {
391 GroupDimensions->LineEdit1->setFocus();
392 myEditCurrentArgument = GroupDimensions->LineEdit1;
393 mySelection->AddFilter(myEdgeFilter);
394 this->SelectionIntoArgument();
400 //=================================================================================
401 // function : enterEvent()
402 // purpose : to reactivate this dialog box when mouse enter onto the window
403 //=================================================================================
404 void BasicGUI_PointDlg::enterEvent(QEvent* e)
406 if (GroupConstructors->isEnabled())
408 this->ActivateThisDialog();
413 //=======================================================================
414 // function : closeEvent()
416 //=======================================================================
417 void BasicGUI_PointDlg::closeEvent(QCloseEvent* e)
419 /* same than click on cancel button */
420 this->ClickOnCancel();
424 //=================================================================================
425 // function : ActivateThisDialog()
427 //=================================================================================
428 void BasicGUI_PointDlg::ActivateThisDialog( )
430 GEOMBase_Skeleton::ActivateThisDialog();
431 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
433 myGeomGUI->myState = 0;
434 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
435 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
436 myIC = v3d->getAISContext();
437 myLocalContextId = myIC->OpenLocalContext();
438 //myGeomBase->SetDisplayedObjectList();
439 /* sub shapes selection */
440 myLocalContextMode = TopAbs_VERTEX;
441 myIC->ActivateStandardMode(myLocalContextMode);
442 myUseLocalContext = true;
445 if(myConstructorId == 1)
446 mySelection->AddFilter(myEdgeFilter);
448 if(!mySimulationTopoDs.IsNull())
449 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
454 //=================================================================================
455 // function : DeactivateActiveDialog()
456 // purpose : public slot to deactivate if active
457 //=================================================================================
458 void BasicGUI_PointDlg::DeactivateActiveDialog()
460 if(myConstructorId == 0 && QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
461 myIC->CloseLocalContext(myLocalContextId);
462 myUseLocalContext = false;
464 myGeomGUI->myState = -1;
465 GEOMBase_Skeleton::DeactivateActiveDialog();
470 //=================================================================================
471 // function : ValueChangedInSpinBox()
473 //=================================================================================
474 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
476 DlgRef_SpinBox* send = (DlgRef_SpinBox*)sender();
479 if(send == GroupPoints->SpinBox_DX) {
481 vy = GroupPoints->SpinBox_DY->GetValue();
482 vz = GroupPoints->SpinBox_DZ->GetValue();
483 } else if(send == GroupPoints->SpinBox_DY) {
484 vx = GroupPoints->SpinBox_DX->GetValue();
486 vz = GroupPoints->SpinBox_DZ->GetValue();
487 } else if(send == GroupPoints->SpinBox_DZ) {
488 vx = GroupPoints->SpinBox_DX->GetValue();
489 vy = GroupPoints->SpinBox_DY->GetValue();
491 } else if(send == GroupDimensions->SpinBox_DX) {
492 myParameter = newValue;
496 switch(myConstructorId)
498 case 0: // default constructor
500 myPoint.SetCoord(vx, vy, vz);
501 mySimulationTopoDs = BRepBuilderAPI_MakeVertex (myPoint).Shape();
502 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
507 this->SelectionIntoArgument();
515 //=================================================================================
516 // function : CalculateVertexOnCurve()
517 // purpose : Calculate a Vertex on the curve given by 'anEdge'.
518 // : The position of resultVertex is given by aParameter.
519 // : For a linear edge, aParameter=0.0 gives the first vertex of edge
520 // : aParameter=1.0 gives the last vertex of edge
521 // : aParameter=0.5 gives the vertex on the middle of edge
522 // : It is possible to get vertices out of edge using values > 1.0 or < 0.0
523 //=================================================================================
524 bool BasicGUI_PointDlg::CalculateVertexOnCurve(const TopoDS_Edge& anEdge, const Standard_Real aParameter, TopoDS_Shape& resultVertex)
526 #if OCC_VERSION_MAJOR >= 5
527 if(anEdge.IsNull() || !BRepAlgo::IsValid(anEdge))
529 if(anEdge.IsNull() || !BRepAlgoAPI::IsValid(anEdge))
533 Standard_Real first, last;
534 Handle(Geom_Curve) curv = BRep_Tool::Curve(anEdge, first, last);
539 if(anEdge.Orientation() == TopAbs_FORWARD)
540 param = first + (last-first) * aParameter;
542 param = last + (first-last) * aParameter;
545 curv->D0(param, paramPoint);
546 resultVertex = BRepBuilderAPI_MakeVertex(paramPoint);
551 //=======================================================================
552 // funcion : PointIntoCoordinates()
553 // purpose : Sets user point coordinates into this dialog Spin boxes
554 // : and displays it or not according to 'bool displayPoint'
555 //=======================================================================
556 void BasicGUI_PointDlg::PointIntoCoordinates(gp_Pnt P, bool displayPoint)
558 GroupPoints->SpinBox_DX->SetValue(P.X());
559 GroupPoints->SpinBox_DY->SetValue(P.Y());
560 GroupPoints->SpinBox_DZ->SetValue(P.Z());
561 myPoint.SetCoord(P.X(), P.Y(), P.Z());
563 mySimulationTopoDs = BRepBuilderAPI_MakeVertex(P).Shape();
564 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);