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_PlaneDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_PlaneDlg.h"
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <BRepAdaptor_Surface.hxx>
36 #include <Precision.hxx>
37 #include "QAD_Config.h"
39 #include "utilities.h"
43 //=================================================================================
44 // class : BasicGUI_PlaneDlg()
45 // purpose : Constructs a BasicGUI_PlaneDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 BasicGUI_PlaneDlg::BasicGUI_PlaneDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_PV")));
54 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_DXYZ")));
55 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_FACE")));
56 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_PLANE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_PLANE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->setPixmap(image1);
64 RadioButton3->setPixmap(image2);
66 GroupPointDirection = new DlgRef_2Sel1Spin(this, "GroupPointDirection");
67 GroupPointDirection->GroupBox1->setTitle(tr("GEOM_PLANE_PV"));
68 GroupPointDirection->TextLabel1->setText(tr("GEOM_POINT"));
69 GroupPointDirection->TextLabel2->setText(tr("GEOM_VECTOR"));
70 GroupPointDirection->TextLabel3->setText(tr("GEOM_PLANE_SIZE"));
71 GroupPointDirection->PushButton1->setPixmap(image3);
72 GroupPointDirection->PushButton2->setPixmap(image3);
74 GroupPointPlusCoordinates = new DlgRef_1Sel4Spin(this, "GroupPointPlusCoordinates" );
75 GroupPointPlusCoordinates->GroupBox1->setTitle(tr("GEOM_PLANE_PVC"));
76 GroupPointPlusCoordinates->TextLabel1->setText(tr("GEOM_POINT"));
77 GroupPointPlusCoordinates->TextLabel2->setText(tr("GEOM_COOR"));
78 GroupPointPlusCoordinates->TextLabel3->setText(tr("GEOM_DX"));
79 GroupPointPlusCoordinates->TextLabel4->setText(tr("GEOM_DY"));
80 GroupPointPlusCoordinates->TextLabel5->setText(tr("GEOM_DZ"));
81 GroupPointPlusCoordinates->TextLabel6->setText(tr("GEOM_PLANE_SIZE"));
82 GroupPointPlusCoordinates->PushButton1->setPixmap(image3);
84 GroupFace = new DlgRef_1Sel1Spin(this, "GroupFace");
85 GroupFace->GroupBox1->setTitle(tr("GEOM_FACE"));
86 GroupFace->TextLabel1->setText(tr("GEOM_SELECTION"));
87 GroupFace->TextLabel2->setText(tr("GEOM_PLANE_SIZE"));
88 GroupFace->PushButton1->setPixmap(image3);
90 Layout1->addWidget(GroupPointDirection, 1, 0);
91 Layout1->addWidget(GroupPointPlusCoordinates, 1, 0);
92 Layout1->addWidget(GroupFace, 1, 0);
93 /***************************************************************/
96 myBasicGUI = theBasicGUI;
101 //=================================================================================
102 // function : ~BasicGUI_PlaneDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
107 /* no need to delete child widgets, Qt does it all for us */
111 //=================================================================================
114 //=================================================================================
115 void BasicGUI_PlaneDlg::Init()
119 myEditCurrentArgument = GroupPointDirection->LineEdit1;
121 myPoint1.SetCoord(0.0, 0.0, 0.0);
122 myOkPoint1 = myOkDirection = myOkCoordinates = myOkPlanarFace = false;
124 /* Filters definition */
125 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
126 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
127 myFaceFilter = new GEOM_FaceFilter(StdSelect_Plane, myGeom);
128 /* Filter for the next selection */
129 mySelection->AddFilter(myVertexFilter);
131 /* Get setting of step value from file configuration */
132 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
133 step = St.toDouble();
134 this->myTrimSize = 2000.0;
136 /* min, max, step and decimals for spin boxes */
137 GroupPointDirection->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, step, 3);
138 GroupPointDirection->SpinBox_DX->SetValue(myTrimSize);
140 double SpecificStep = 1;
141 GroupPointPlusCoordinates->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
142 GroupPointPlusCoordinates->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
143 GroupPointPlusCoordinates->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
144 GroupPointPlusCoordinates->SpinBox_DX->SetValue(0.0);
145 GroupPointPlusCoordinates->SpinBox_DY->SetValue(0.0);
146 GroupPointPlusCoordinates->SpinBox_DZ->SetValue(1.0);
147 GroupPointPlusCoordinates->SpinBox_S->RangeStepAndValidator(0.001, 10000000.0, step, 3);
148 GroupPointPlusCoordinates->SpinBox_S->SetValue(myTrimSize) ;
150 GroupFace->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, step, 3);
151 GroupFace->SpinBox_DX->SetValue(myTrimSize);
153 /* signals and slots connections */
154 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
155 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
156 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
158 connect(GroupPointDirection->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159 connect(GroupPointDirection->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160 connect(GroupPointPlusCoordinates->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(GroupFace->PushButton1, SIGNAL(clicked()), this, SLOT( SetEditCurrentArgument()));
163 connect(GroupPointDirection->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
164 connect(GroupPointDirection->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(GroupPointPlusCoordinates->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
166 connect(GroupFace->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
168 connect(GroupPointPlusCoordinates->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
169 connect(GroupPointPlusCoordinates->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
170 connect(GroupPointPlusCoordinates->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
171 connect(GroupPointPlusCoordinates->SpinBox_S, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
172 connect(GroupPointDirection->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
173 connect(GroupFace->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
175 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointPlusCoordinates->SpinBox_DX, SLOT(SetStep(double)));
176 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointPlusCoordinates->SpinBox_DY, SLOT(SetStep(double)));
177 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointPlusCoordinates->SpinBox_DZ, SLOT(SetStep(double)));
178 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointPlusCoordinates->SpinBox_S, SLOT(SetStep(double)));
179 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointDirection->SpinBox_DX, SLOT(SetStep(double)));
180 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupFace->SpinBox_DX, SLOT(SetStep(double)));
182 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
184 /* Displays Dialog */
185 GroupPointPlusCoordinates->hide();
187 GroupPointDirection->show();
194 //=================================================================================
195 // function : ConstructorsClicked()
196 // purpose : Radio button management
197 //=================================================================================
198 void BasicGUI_PlaneDlg::ConstructorsClicked(int constructorId)
200 myConstructorId = constructorId;
201 mySelection->ClearFilters();
202 myGeomBase->EraseSimulationShape();
203 mySimulationTopoDs.Nullify();
204 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
205 myOkPoint1 = myOkDirection = myOkCoordinates = myOkPlanarFace = false;
207 switch (constructorId)
209 case 0: /* plane from a point and a direction (vector, edge...) */
211 GroupPointPlusCoordinates->hide();
214 GroupPointDirection->show();
216 myEditCurrentArgument = GroupPointDirection->LineEdit1;
217 GroupPointDirection->LineEdit1->setText(tr(""));
218 GroupPointDirection->LineEdit2->setText(tr(""));
220 /* for the first argument */
221 mySelection->AddFilter(myVertexFilter);
224 case 1: /* plane from a point and vector coordinates */
226 GroupPointDirection->hide();
229 GroupPointPlusCoordinates->show();
231 myEditCurrentArgument = GroupPointPlusCoordinates->LineEdit1;
232 GroupPointPlusCoordinates->LineEdit1->setText(tr(""));
233 GroupPointPlusCoordinates->SpinBox_DX->SetValue(0.0);
234 GroupPointPlusCoordinates->SpinBox_DY->SetValue(0.0);
235 GroupPointPlusCoordinates->SpinBox_DZ->SetValue(1.0);
236 myOkCoordinates = true;
238 /* for the first argument */
239 mySelection->AddFilter(myVertexFilter);
242 case 2: /* plane from a planar face selection */
244 GroupPointDirection->hide();
245 GroupPointPlusCoordinates->hide();
249 myEditCurrentArgument = GroupFace->LineEdit1;
250 GroupFace->LineEdit1->setText(tr(""));
252 /* for the first argument */
253 mySelection->AddFilter(myFaceFilter);
261 //=================================================================================
262 // function : ClickOnOk()
264 //=================================================================================
265 void BasicGUI_PlaneDlg::ClickOnOk()
267 this->ClickOnApply();
273 //=================================================================================
274 // function : ClickOnApply()
276 //=================================================================================
277 void BasicGUI_PlaneDlg::ClickOnApply()
279 buttonApply->setFocus();
280 QAD_Application::getDesktop()->putInfo(tr(""));
281 if (mySimulationTopoDs.IsNull())
283 myGeomBase->EraseSimulationShape();
284 mySimulationTopoDs.Nullify();
286 switch(myConstructorId)
288 case 0 : /* args are myPoint1 and myDx, myDy, myDz from a vector(edge) */
290 if(myOkPoint1 && myOkDirection)
291 myBasicGUI->MakePlaneAndDisplay(myPoint1, myDx, myDy, myDz, myTrimSize);
294 case 1 : /* args are myPoint1 and myDx, myDy, myDz from a Spin Box */
297 myBasicGUI->MakePlaneAndDisplay(myPoint1, myDx, myDy, myDz, myTrimSize);
300 case 2 : /* arg is a planar face selection */
303 myBasicGUI->MakePlaneAndDisplay(myPoint1, myDx, myDy, myDz, myTrimSize);
311 //=================================================================================
312 // function : SelectionIntoArgument()
313 // purpose : Called when selection has changed
314 //=================================================================================
315 void BasicGUI_PlaneDlg::SelectionIntoArgument()
317 myGeomBase->EraseSimulationShape();
318 mySimulationTopoDs.Nullify();
319 QString aString = "";
321 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
323 switch (myConstructorId)
327 if(myEditCurrentArgument == GroupPointDirection->LineEdit1) {
328 GroupPointDirection->LineEdit1->setText("");
331 else if(myEditCurrentArgument == GroupPointDirection->LineEdit2) {
332 GroupPointDirection->LineEdit2->setText("");
333 myOkDirection = false ;
339 if(myEditCurrentArgument == GroupPointPlusCoordinates->LineEdit1) {
340 GroupPointPlusCoordinates->LineEdit1->setText("") ;
347 if(myEditCurrentArgument == GroupFace->LineEdit1) {
348 GroupFace->LineEdit1->setText("") ;
349 if(aString.compare("") == 0)
350 myOkPlanarFace = false;
352 myOkPlanarFace = true;
362 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
365 /* FIRST CONSTRUCTOR */
366 if(myEditCurrentArgument == GroupPointDirection->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
367 GroupPointDirection->LineEdit1->setText(aString);
370 else if( myEditCurrentArgument == GroupPointDirection->LineEdit2) {
371 /* We verify if the selection is a linear edge */
372 gp_Pnt Pfirst, Plast;
373 if( myGeomBase->LinearEdgeExtremities(S, Pfirst, Plast)) {
374 myGeomBase->GetBipointDxDyDz(Pfirst, Plast, myDx, myDy, myDz);
375 GroupPointDirection->LineEdit2->setText(aString);
376 myOkDirection = true;
377 myTrimSize = GroupPointDirection->SpinBox_DX->GetValue();
381 /* SECOND CONSTRUCTOR */
382 else if(myEditCurrentArgument == GroupPointPlusCoordinates->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
383 GroupPointPlusCoordinates->LineEdit1->setText(aString);
385 myDx = GroupPointPlusCoordinates->SpinBox_DX->GetValue();
386 myDy = GroupPointPlusCoordinates->SpinBox_DY->GetValue();
387 myDz = GroupPointPlusCoordinates->SpinBox_DZ->GetValue();
388 myTrimSize = GroupPointPlusCoordinates->SpinBox_S->GetValue();
390 myOkCoordinates = true;
393 /* THIRD CONSTRUCTOR */
394 else if(myEditCurrentArgument == GroupFace->LineEdit1) {
396 GroupFace->LineEdit1->setText(aString);
397 BRepAdaptor_Surface surf(TopoDS::Face(S));
398 gp_Pln Plane = surf.Plane();
400 gp_Pnt myPoint1 = Plane.Location();
401 gp_Ax1 ax = Plane.Axis();
402 myDx = (ax.Direction()).X();
403 myDy = (ax.Direction()).Y();
404 myDz = (ax.Direction()).Z();
405 myTrimSize = GroupFace->SpinBox_DX->GetValue();
409 /* Call method simulation */
410 if((myOkPoint1 && myOkDirection) || (myOkPoint1 && myOkCoordinates) || myOkPlanarFace) {
411 if(myDx*myDx + myDy*myDy + myDz*myDz > Precision::Confusion()*Precision::Confusion())
412 this->MakePlaneSimulationAndDisplay();
418 //=================================================================================
419 // function : SetEditCurrentArgument()
421 //=================================================================================
422 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
424 QPushButton* send = (QPushButton*)sender();
425 mySelection->ClearFilters();
427 switch(myConstructorId)
431 if(send == GroupPointDirection->PushButton1) {
432 GroupPointDirection->LineEdit1->setFocus();
433 myEditCurrentArgument = GroupPointDirection->LineEdit1;
434 mySelection->AddFilter(myVertexFilter);
436 else if(send == GroupPointDirection->PushButton2) {
437 GroupPointDirection->LineEdit2->setFocus();
438 myEditCurrentArgument = GroupPointDirection->LineEdit2;
439 /* Edge filter here */
440 mySelection->AddFilter(myEdgeFilter);
446 if(send == GroupPointPlusCoordinates->PushButton1) {
447 GroupPointPlusCoordinates->LineEdit1->setFocus();
448 myEditCurrentArgument = GroupPointPlusCoordinates->LineEdit1;
449 /* Vertex filter here */
450 mySelection->AddFilter(myVertexFilter);
456 if(send == GroupFace->PushButton1) {
457 GroupFace->LineEdit1->setFocus();
458 myEditCurrentArgument = GroupFace->LineEdit1;
459 /* Face filter here */
460 mySelection->AddFilter(myFaceFilter);
465 this->SelectionIntoArgument();
470 //=================================================================================
471 // function : LineEditReturnPressed()
473 //=================================================================================
474 void BasicGUI_PlaneDlg::LineEditReturnPressed()
476 QLineEdit* send = (QLineEdit*)sender();
477 if(send == GroupPointDirection->LineEdit1)
478 myEditCurrentArgument = GroupPointDirection->LineEdit1;
479 else if (send == GroupPointDirection->LineEdit2)
480 myEditCurrentArgument = GroupPointDirection->LineEdit2;
481 else if (send == GroupPointPlusCoordinates->LineEdit1)
482 myEditCurrentArgument = GroupPointPlusCoordinates->LineEdit1;
483 else if (send == GroupFace->LineEdit1)
484 myEditCurrentArgument = GroupFace->LineEdit1;
488 GEOMBase_Skeleton::LineEditReturnPressed();
493 //=================================================================================
494 // function : ActivateThisDialog()
496 //=================================================================================
497 void BasicGUI_PlaneDlg::ActivateThisDialog()
499 GEOMBase_Skeleton::ActivateThisDialog();
500 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
501 switch(myConstructorId)
505 GroupPointDirection->LineEdit1->setFocus();
506 myEditCurrentArgument = GroupPointDirection->LineEdit1;
507 mySelection->AddFilter(myVertexFilter);
512 GroupPointPlusCoordinates->LineEdit1->setFocus();
513 myEditCurrentArgument = GroupPointPlusCoordinates->LineEdit1;
514 mySelection->AddFilter(myVertexFilter);
519 GroupFace->LineEdit1->setFocus();
520 myEditCurrentArgument = GroupFace->LineEdit1;
521 mySelection->AddFilter(myFaceFilter);
525 if(!mySimulationTopoDs.IsNull())
526 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
531 //=================================================================================
532 // function : enterEvent()
534 //=================================================================================
535 void BasicGUI_PlaneDlg::enterEvent(QEvent* e)
537 if (GroupConstructors->isEnabled())
539 this->ActivateThisDialog();
544 //=================================================================================
545 // function : ValueChangedInSpinBox()
547 //=================================================================================
548 void BasicGUI_PlaneDlg::ValueChangedInSpinBox(double newValue)
550 QObject* send = (QObject*)sender();
552 if(send == GroupPointPlusCoordinates->SpinBox_DX)
554 else if(send == GroupPointPlusCoordinates->SpinBox_DY)
556 else if(send == GroupPointPlusCoordinates->SpinBox_DZ)
558 else if(send == GroupPointDirection->SpinBox_DX || send == GroupPointPlusCoordinates->SpinBox_S || send == GroupFace->SpinBox_DX) {
559 myTrimSize = newValue;
563 if((myOkPoint1 && myOkDirection) || (myOkPoint1 && myOkCoordinates) || myOkPlanarFace) {
564 if(myDx*myDx + myDy*myDy + myDz*myDz > Precision::Confusion() * Precision::Confusion())
565 this->MakePlaneSimulationAndDisplay();
571 //=================================================================================
572 // function : MakePlaneSimulationAndDisplay(()
574 //=================================================================================
575 void BasicGUI_PlaneDlg::MakePlaneSimulationAndDisplay()
577 myGeomBase->EraseSimulationShape();
578 mySimulationTopoDs.Nullify();
581 gp_Dir aDirection(myDx, myDy, myDz);
582 /* We make a trimmed plane */
583 gp_Pln gplane(myPoint1, aDirection);
584 mySimulationTopoDs = BRepBuilderAPI_MakeFace(gplane, -myTrimSize, +myTrimSize, -myTrimSize, +myTrimSize);
585 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
587 catch(Standard_Failure) {
588 MESSAGE( "Exception catched in MakePlaneSimulation" << endl );