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
30 #include "BasicGUI_PlaneDlg.h"
32 #include <BRepBuilderAPI_MakeFace.hxx>
33 #include <BRepAdaptor_Surface.hxx>
37 #include <Precision.hxx>
38 #include "QAD_Config.h"
40 //=================================================================================
41 // class : BasicGUI_PlaneDlg()
42 // purpose : Constructs a BasicGUI_PlaneDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 BasicGUI_PlaneDlg::BasicGUI_PlaneDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_PV")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_DXYZ")));
52 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PLANE_FACE")));
53 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_PLANE_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_PLANE"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->setPixmap(image1);
61 RadioButton3->setPixmap(image2);
63 GroupPointDirection = new DlgRef_2Sel1Spin(this, "GroupPointDirection");
64 GroupPointDirection->GroupBox1->setTitle(tr("GEOM_PLANE_PV"));
65 GroupPointDirection->TextLabel1->setText(tr("GEOM_POINT"));
66 GroupPointDirection->TextLabel2->setText(tr("GEOM_VECTOR"));
67 GroupPointDirection->TextLabel3->setText(tr("GEOM_PLANE_SIZE"));
68 GroupPointDirection->PushButton1->setPixmap(image3);
69 GroupPointDirection->PushButton2->setPixmap(image3);
71 GroupPointPlusCoordinates = new DlgRef_1Sel4Spin(this, "GroupPointPlusCoordinates" );
72 GroupPointPlusCoordinates->GroupBox1->setTitle(tr("GEOM_PLANE_PVC"));
73 GroupPointPlusCoordinates->TextLabel1->setText(tr("GEOM_POINT"));
74 GroupPointPlusCoordinates->TextLabel2->setText(tr("GEOM_COOR"));
75 GroupPointPlusCoordinates->TextLabel3->setText(tr("GEOM_DX"));
76 GroupPointPlusCoordinates->TextLabel4->setText(tr("GEOM_DY"));
77 GroupPointPlusCoordinates->TextLabel5->setText(tr("GEOM_DZ"));
78 GroupPointPlusCoordinates->TextLabel6->setText(tr("GEOM_PLANE_SIZE"));
79 GroupPointPlusCoordinates->PushButton1->setPixmap(image3);
81 GroupFace = new DlgRef_1Sel1Spin(this, "GroupFace");
82 GroupFace->GroupBox1->setTitle(tr("GEOM_FACE"));
83 GroupFace->TextLabel1->setText(tr("GEOM_SELECTION"));
84 GroupFace->TextLabel2->setText(tr("GEOM_PLANE_SIZE"));
85 GroupFace->PushButton1->setPixmap(image3);
87 Layout1->addWidget(GroupPointDirection, 1, 0);
88 Layout1->addWidget(GroupPointPlusCoordinates, 1, 0);
89 Layout1->addWidget(GroupFace, 1, 0);
90 /***************************************************************/
93 myBasicGUI = theBasicGUI;
98 //=================================================================================
99 // function : ~BasicGUI_PlaneDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
104 /* no need to delete child widgets, Qt does it all for us */
108 //=================================================================================
111 //=================================================================================
112 void BasicGUI_PlaneDlg::Init()
116 myEditCurrentArgument = GroupPointDirection->LineEdit1;
118 myPoint1.SetCoord(0.0, 0.0, 0.0);
119 myOkPoint1 = myOkDirection = myOkCoordinates = myOkPlanarFace = false;
121 /* Filters definition */
122 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
123 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
124 myFaceFilter = new GEOM_FaceFilter(StdSelect_Plane, myGeom);
125 /* Filter for the next selection */
126 mySelection->AddFilter(myVertexFilter);
128 /* Get setting of step value from file configuration */
129 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
130 step = St.toDouble();
131 this->myTrimSize = 2000.0;
133 /* min, max, step and decimals for spin boxes */
134 GroupPointDirection->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, step, 3);
135 GroupPointDirection->SpinBox_DX->SetValue(myTrimSize);
137 double SpecificStep = 1;
138 GroupPointPlusCoordinates->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
139 GroupPointPlusCoordinates->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
140 GroupPointPlusCoordinates->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
141 GroupPointPlusCoordinates->SpinBox_DX->SetValue(0.0);
142 GroupPointPlusCoordinates->SpinBox_DY->SetValue(0.0);
143 GroupPointPlusCoordinates->SpinBox_DZ->SetValue(1.0);
144 GroupPointPlusCoordinates->SpinBox_S->RangeStepAndValidator(0.001, 10000000.0, step, 3);
145 GroupPointPlusCoordinates->SpinBox_S->SetValue(myTrimSize) ;
147 GroupFace->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, step, 3);
148 GroupFace->SpinBox_DX->SetValue(myTrimSize);
150 /* signals and slots connections */
151 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
152 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
153 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
155 connect(GroupPointDirection->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(GroupPointDirection->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157 connect(GroupPointPlusCoordinates->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupFace->PushButton1, SIGNAL(clicked()), this, SLOT( SetEditCurrentArgument()));
160 connect(GroupPointDirection->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161 connect(GroupPointDirection->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(GroupPointPlusCoordinates->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(GroupFace->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(GroupPointPlusCoordinates->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166 connect(GroupPointPlusCoordinates->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167 connect(GroupPointPlusCoordinates->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168 connect(GroupPointPlusCoordinates->SpinBox_S, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
169 connect(GroupPointDirection->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
170 connect(GroupFace->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
172 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointPlusCoordinates->SpinBox_DX, SLOT(SetStep(double)));
173 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointPlusCoordinates->SpinBox_DY, SLOT(SetStep(double)));
174 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointPlusCoordinates->SpinBox_DZ, SLOT(SetStep(double)));
175 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointPlusCoordinates->SpinBox_S, SLOT(SetStep(double)));
176 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPointDirection->SpinBox_DX, SLOT(SetStep(double)));
177 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupFace->SpinBox_DX, SLOT(SetStep(double)));
179 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
181 /* Displays Dialog */
182 GroupPointPlusCoordinates->hide();
184 GroupPointDirection->show();
191 //=================================================================================
192 // function : ConstructorsClicked()
193 // purpose : Radio button management
194 //=================================================================================
195 void BasicGUI_PlaneDlg::ConstructorsClicked(int constructorId)
197 myConstructorId = constructorId;
198 mySelection->ClearFilters();
199 myGeomBase->EraseSimulationShape();
200 mySimulationTopoDs.Nullify();
201 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
202 myOkPoint1 = myOkDirection = myOkCoordinates = myOkPlanarFace = false;
204 switch (constructorId)
206 case 0: /* plane from a point and a direction (vector, edge...) */
208 GroupPointPlusCoordinates->hide();
211 GroupPointDirection->show();
213 myEditCurrentArgument = GroupPointDirection->LineEdit1;
214 GroupPointDirection->LineEdit1->setText(tr(""));
215 GroupPointDirection->LineEdit2->setText(tr(""));
217 /* for the first argument */
218 mySelection->AddFilter(myVertexFilter);
221 case 1: /* plane from a point and vector coordinates */
223 GroupPointDirection->hide();
226 GroupPointPlusCoordinates->show();
228 myEditCurrentArgument = GroupPointPlusCoordinates->LineEdit1;
229 GroupPointPlusCoordinates->LineEdit1->setText(tr(""));
230 GroupPointPlusCoordinates->SpinBox_DX->SetValue(0.0);
231 GroupPointPlusCoordinates->SpinBox_DY->SetValue(0.0);
232 GroupPointPlusCoordinates->SpinBox_DZ->SetValue(1.0);
233 myOkCoordinates = true;
235 /* for the first argument */
236 mySelection->AddFilter(myVertexFilter);
239 case 2: /* plane from a planar face selection */
241 GroupPointDirection->hide();
242 GroupPointPlusCoordinates->hide();
246 myEditCurrentArgument = GroupFace->LineEdit1;
247 GroupFace->LineEdit1->setText(tr(""));
249 /* for the first argument */
250 mySelection->AddFilter(myFaceFilter);
258 //=================================================================================
259 // function : ClickOnOk()
261 //=================================================================================
262 void BasicGUI_PlaneDlg::ClickOnOk()
264 this->ClickOnApply();
270 //=================================================================================
271 // function : ClickOnApply()
273 //=================================================================================
274 void BasicGUI_PlaneDlg::ClickOnApply()
276 QAD_Application::getDesktop()->putInfo(tr(""));
277 if (mySimulationTopoDs.IsNull())
279 myGeomBase->EraseSimulationShape();
280 mySimulationTopoDs.Nullify();
282 switch(myConstructorId)
284 case 0 : /* args are myPoint1 and myDx, myDy, myDz from a vector(edge) */
286 if(myOkPoint1 && myOkDirection)
287 myBasicGUI->MakePlaneAndDisplay(myPoint1, myDx, myDy, myDz, myTrimSize);
290 case 1 : /* args are myPoint1 and myDx, myDy, myDz from a Spin Box */
293 myBasicGUI->MakePlaneAndDisplay(myPoint1, myDx, myDy, myDz, myTrimSize);
296 case 2 : /* arg is a planar face selection */
299 myBasicGUI->MakePlaneAndDisplay(myPoint1, myDx, myDy, myDz, myTrimSize);
307 //=================================================================================
308 // function : SelectionIntoArgument()
309 // purpose : Called when selection has changed
310 //=================================================================================
311 void BasicGUI_PlaneDlg::SelectionIntoArgument()
313 myGeomBase->EraseSimulationShape();
314 mySimulationTopoDs.Nullify();
315 QString aString = "";
317 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
319 switch (myConstructorId)
323 if(myEditCurrentArgument == GroupPointDirection->LineEdit1) {
324 GroupPointDirection->LineEdit1->setText("");
327 else if(myEditCurrentArgument == GroupPointDirection->LineEdit2) {
328 GroupPointDirection->LineEdit2->setText("");
329 myOkDirection = false ;
335 if(myEditCurrentArgument == GroupPointPlusCoordinates->LineEdit1) {
336 GroupPointPlusCoordinates->LineEdit1->setText("") ;
343 if(myEditCurrentArgument == GroupFace->LineEdit1) {
344 GroupFace->LineEdit1->setText("") ;
345 if(aString.compare("") == 0)
346 myOkPlanarFace = false;
348 myOkPlanarFace = true;
358 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
361 /* FIRST CONSTRUCTOR */
362 if(myEditCurrentArgument == GroupPointDirection->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
363 GroupPointDirection->LineEdit1->setText(aString);
366 else if( myEditCurrentArgument == GroupPointDirection->LineEdit2) {
367 /* We verify if the selection is a linear edge */
368 gp_Pnt Pfirst, Plast;
369 if( myGeomBase->LinearEdgeExtremities(S, Pfirst, Plast)) {
370 myGeomBase->GetBipointDxDyDz(Pfirst, Plast, myDx, myDy, myDz);
371 GroupPointDirection->LineEdit2->setText(aString);
372 myOkDirection = true;
373 myTrimSize = GroupPointDirection->SpinBox_DX->GetValue();
377 /* SECOND CONSTRUCTOR */
378 else if(myEditCurrentArgument == GroupPointPlusCoordinates->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
379 GroupPointPlusCoordinates->LineEdit1->setText(aString);
381 myDx = GroupPointPlusCoordinates->SpinBox_DX->GetValue();
382 myDy = GroupPointPlusCoordinates->SpinBox_DY->GetValue();
383 myDz = GroupPointPlusCoordinates->SpinBox_DZ->GetValue();
384 myTrimSize = GroupPointPlusCoordinates->SpinBox_S->GetValue();
386 myOkCoordinates = true;
389 /* THIRD CONSTRUCTOR */
390 else if(myEditCurrentArgument == GroupFace->LineEdit1) {
392 GroupFace->LineEdit1->setText(aString);
393 BRepAdaptor_Surface surf(TopoDS::Face(S));
394 gp_Pln Plane = surf.Plane();
396 gp_Pnt myPoint1 = Plane.Location();
397 gp_Ax1 ax = Plane.Axis();
398 myDx = (ax.Direction()).X();
399 myDy = (ax.Direction()).Y();
400 myDz = (ax.Direction()).Z();
401 myTrimSize = GroupFace->SpinBox_DX->GetValue();
405 /* Call method simulation */
406 if((myOkPoint1 && myOkDirection) || (myOkPoint1 && myOkCoordinates) || myOkPlanarFace) {
407 if(myDx*myDx + myDy*myDy + myDz*myDz > Precision::Confusion()*Precision::Confusion())
408 this->MakePlaneSimulationAndDisplay();
414 //=================================================================================
415 // function : SetEditCurrentArgument()
417 //=================================================================================
418 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
420 QPushButton* send = (QPushButton*)sender();
421 mySelection->ClearFilters();
423 switch(myConstructorId)
427 if(send == GroupPointDirection->PushButton1) {
428 GroupPointDirection->LineEdit1->setFocus();
429 myEditCurrentArgument = GroupPointDirection->LineEdit1;
430 mySelection->AddFilter(myVertexFilter);
432 else if(send == GroupPointDirection->PushButton2) {
433 GroupPointDirection->LineEdit2->setFocus();
434 myEditCurrentArgument = GroupPointDirection->LineEdit2;
435 /* Edge filter here */
436 mySelection->AddFilter(myEdgeFilter);
442 if(send == GroupPointPlusCoordinates->PushButton1) {
443 GroupPointPlusCoordinates->LineEdit1->setFocus();
444 myEditCurrentArgument = GroupPointPlusCoordinates->LineEdit1;
445 /* Vertex filter here */
446 mySelection->AddFilter(myVertexFilter);
452 if(send == GroupFace->PushButton1) {
453 GroupFace->LineEdit1->setFocus();
454 myEditCurrentArgument = GroupFace->LineEdit1;
455 /* Face filter here */
456 mySelection->AddFilter(myFaceFilter);
461 this->SelectionIntoArgument();
466 //=================================================================================
467 // function : LineEditReturnPressed()
469 //=================================================================================
470 void BasicGUI_PlaneDlg::LineEditReturnPressed()
472 QLineEdit* send = (QLineEdit*)sender();
473 if(send == GroupPointDirection->LineEdit1)
474 myEditCurrentArgument = GroupPointDirection->LineEdit1;
475 else if (send == GroupPointDirection->LineEdit2)
476 myEditCurrentArgument = GroupPointDirection->LineEdit2;
477 else if (send == GroupPointPlusCoordinates->LineEdit1)
478 myEditCurrentArgument = GroupPointPlusCoordinates->LineEdit1;
479 else if (send == GroupFace->LineEdit1)
480 myEditCurrentArgument = GroupFace->LineEdit1;
484 GEOMBase_Skeleton::LineEditReturnPressed();
489 //=================================================================================
490 // function : ActivateThisDialog()
492 //=================================================================================
493 void BasicGUI_PlaneDlg::ActivateThisDialog()
495 GEOMBase_Skeleton::ActivateThisDialog();
496 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
497 switch(myConstructorId)
501 GroupPointDirection->LineEdit1->setFocus();
502 myEditCurrentArgument = GroupPointDirection->LineEdit1;
503 mySelection->AddFilter(myVertexFilter);
508 GroupPointPlusCoordinates->LineEdit1->setFocus();
509 myEditCurrentArgument = GroupPointPlusCoordinates->LineEdit1;
510 mySelection->AddFilter(myVertexFilter);
515 GroupFace->LineEdit1->setFocus();
516 myEditCurrentArgument = GroupFace->LineEdit1;
517 mySelection->AddFilter(myFaceFilter);
521 if(!mySimulationTopoDs.IsNull())
522 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
527 //=================================================================================
528 // function : enterEvent()
530 //=================================================================================
531 void BasicGUI_PlaneDlg::enterEvent(QEvent* e)
533 if (GroupConstructors->isEnabled())
535 this->ActivateThisDialog();
540 //=================================================================================
541 // function : ValueChangedInSpinBox()
543 //=================================================================================
544 void BasicGUI_PlaneDlg::ValueChangedInSpinBox(double newValue)
546 QObject* send = (QObject*)sender();
548 if(send == GroupPointPlusCoordinates->SpinBox_DX)
550 else if(send == GroupPointPlusCoordinates->SpinBox_DY)
552 else if(send == GroupPointPlusCoordinates->SpinBox_DZ)
554 else if(send == GroupPointDirection->SpinBox_DX || send == GroupPointPlusCoordinates->SpinBox_S || send == GroupFace->SpinBox_DX) {
555 myTrimSize = newValue;
559 if((myOkPoint1 && myOkDirection) || (myOkPoint1 && myOkCoordinates) || myOkPlanarFace) {
560 if(myDx*myDx + myDy*myDy + myDz*myDz > Precision::Confusion() * Precision::Confusion())
561 this->MakePlaneSimulationAndDisplay();
567 //=================================================================================
568 // function : MakePlaneSimulationAndDisplay(()
570 //=================================================================================
571 void BasicGUI_PlaneDlg::MakePlaneSimulationAndDisplay()
573 myGeomBase->EraseSimulationShape();
574 mySimulationTopoDs.Nullify();
577 gp_Dir aDirection(myDx, myDy, myDz);
578 /* We make a trimmed plane */
579 gp_Pln gplane(myPoint1, aDirection);
580 mySimulationTopoDs = BRepBuilderAPI_MakeFace(gplane, -myTrimSize, +myTrimSize, -myTrimSize, +myTrimSize);
581 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
583 catch(Standard_Failure) {
584 MESSAGE( "Exception catched in MakePlaneSimulation" << endl );