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 : GeometryGUI_BoxDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_BoxDlg.h"
32 #include <Precision.hxx>
33 #include <BRepPrimAPI_MakeBox.hxx>
35 #include "GeometryGUI.h"
36 #include "QAD_Desktop.h"
37 #include "QAD_Config.h"
39 //=================================================================================
40 // class : GeometryGUI_BoxDlg()
41 // purpose : Constructs a GeometryGUI_BoxDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 GeometryGUI_BoxDlg::GeometryGUI_BoxDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
47 :GeometryGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
49 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BOX_2P")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BOX_DXYZ")));
51 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_SELECT")));
53 setCaption(tr("GEOM_BOX_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_BOX"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->setPixmap(image1);
59 RadioButton3->close(TRUE);
61 GroupPoints = new GeometryGUI_2Sel_QTD(this, "GroupPoints");
62 GroupPoints->GroupBox1->setTitle(tr("GEOM_DIAGONAL_POINTS"));
63 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
64 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
65 GroupPoints->PushButton1->setPixmap(image2);
66 GroupPoints->PushButton2->setPixmap(image2);
68 GroupDimensions = new GeometryGUI_3Spin(this, "GroupDimensions");
69 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
70 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
71 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
72 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
74 Layout1->addWidget(GroupPoints, 1, 0);
75 Layout1->addWidget(GroupDimensions, 1, 0);
76 /***************************************************************/
83 //=================================================================================
84 // function : ~DialogBox_Box()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 GeometryGUI_BoxDlg::~GeometryGUI_BoxDlg()
89 // no need to delete child widgets, Qt does it all for us
93 //=================================================================================
96 //=================================================================================
97 void GeometryGUI_BoxDlg::Init(SALOME_Selection* Sel)
101 myEditCurrentArgument = GroupPoints->LineEdit1;
103 myPoint1.SetCoord(0.0, 0.0, 0.0);
104 myPoint2.SetCoord(0.0, 0.0, 0.0);
105 myOkPoint1 = myOkPoint2 = false;
107 /* Vertices Filter for all arguments */
108 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
109 mySelection->AddFilter(myVertexFilter);
111 /* Get setting of step value from file configuration */
112 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
113 step = St.toDouble();
115 /* min, max, step and decimals for spin boxes */
116 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
117 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
118 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
120 double initValue = 200.0;
121 GroupDimensions->SpinBox_DX->SetValue(initValue);
122 GroupDimensions->SpinBox_DY->SetValue(initValue);
123 GroupDimensions->SpinBox_DZ->SetValue(initValue);
125 /* signals and slots connections */
126 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
130 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
137 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
138 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
140 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
142 /* displays Dialog */
143 GroupDimensions->hide();
151 //=================================================================================
152 // function : ConstructorsClicked()
153 // purpose : Radio button management
154 //=================================================================================
155 void GeometryGUI_BoxDlg::ConstructorsClicked(int constructorId)
157 myConstructorId = constructorId;
158 mySelection->ClearFilters();
159 myGeomGUI->EraseSimulationShape();
160 disconnect(mySelection, 0, this, 0);
161 myOkPoint1 = myOkPoint2 = false;
163 switch (constructorId)
167 GroupDimensions->hide();
170 myEditCurrentArgument = GroupPoints->LineEdit1;
171 GroupPoints->LineEdit1->setText("");
172 GroupPoints->LineEdit2->setText("");
174 /* filter for next selection */
175 mySelection->AddFilter(myVertexFilter);
176 connect (mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
183 GroupDimensions->show();
185 double initValue = 200.0;
186 GroupDimensions->SpinBox_DX->SetValue(initValue);
187 GroupDimensions->SpinBox_DY->SetValue(initValue);
188 GroupDimensions->SpinBox_DZ->SetValue(initValue);
190 myPoint1.SetCoord(0.0, 0.0, 0.0) ;
191 myPoint2.SetCoord(initValue, initValue, initValue);
193 mySimulationTopoDs = BRepPrimAPI_MakeBox(myPoint1, myPoint2).Shape();
194 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs);
202 //=================================================================================
203 // function : ClickOnOk()
205 //=================================================================================
206 void GeometryGUI_BoxDlg::ClickOnOk()
208 this->ClickOnApply();
214 //=================================================================================
215 // function : ClickOnApply()
217 //=================================================================================
218 void GeometryGUI_BoxDlg::ClickOnApply()
220 myGeomGUI->GetDesktop()->putInfo(tr(""));
221 if (mySimulationTopoDs.IsNull())
223 myGeomGUI->EraseSimulationShape();
224 mySimulationTopoDs.Nullify();
226 switch(myConstructorId)
230 if(myOkPoint1 && myOkPoint2)
231 myGeomGUI->MakeBoxAndDisplay(myPoint1, myPoint2);
236 /* Recup args and call method */
237 double vx = GroupDimensions->SpinBox_DX->GetValue();
238 double vy = GroupDimensions->SpinBox_DY->GetValue();
239 double vz = GroupDimensions->SpinBox_DZ->GetValue();
240 myPoint1.SetCoord(0.0, 0.0, 0.0);
241 myPoint2.SetCoord(vx, vy, vz);
242 myGeomGUI->MakeBoxAndDisplay(myPoint1, myPoint2);
250 //=================================================================================
251 // function : SelectionIntoArgument()
252 // purpose : Called when selection as changed
253 //=================================================================================
254 void GeometryGUI_BoxDlg::SelectionIntoArgument()
256 myGeomGUI->EraseSimulationShape();
257 myEditCurrentArgument->setText("");
258 QString aString = ""; /* name of selection */
260 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString);
262 if (myEditCurrentArgument == GroupPoints->LineEdit1)
264 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
271 if(!myGeomGUI->GetTopoFromSelection(mySelection, S))
274 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomGUI->VertexToPoint(S, myPoint1)) {
275 myEditCurrentArgument->setText(aString);
278 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomGUI->VertexToPoint(S, myPoint2)) {
279 myEditCurrentArgument->setText(aString);
283 if(myOkPoint1 && myOkPoint2 && TestBoxDimensions(myPoint1, myPoint2)) {
284 mySimulationTopoDs = BRepPrimAPI_MakeBox(myPoint1, myPoint2).Shape();
285 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs);
291 //=================================================================================
292 // function : SetEditCurrentArgument()
294 //=================================================================================
295 void GeometryGUI_BoxDlg::SetEditCurrentArgument()
297 if(myConstructorId != 0)
300 QPushButton* send = (QPushButton*)sender();
302 if(send == GroupPoints->PushButton1) {
303 GroupPoints->LineEdit1->setFocus();
304 myEditCurrentArgument = GroupPoints->LineEdit1;
306 else if(send == GroupPoints->PushButton2) {
307 GroupPoints->LineEdit2->setFocus();
308 myEditCurrentArgument = GroupPoints->LineEdit2;
310 mySelection->AddFilter(myVertexFilter);
311 this->SelectionIntoArgument();
317 //=================================================================================
318 // function : LineEditReturnPressed()
320 //=================================================================================
321 void GeometryGUI_BoxDlg::LineEditReturnPressed()
323 QLineEdit* send = (QLineEdit*)sender();
324 if(send == GroupPoints->LineEdit1)
325 myEditCurrentArgument = GroupPoints->LineEdit1;
326 else if (send == GroupPoints->LineEdit2)
327 myEditCurrentArgument = GroupPoints->LineEdit2;
331 GeometryGUI_Skeleton::LineEditReturnPressed();
336 //=================================================================================
337 // function : ActivateThisDialog()
339 //=================================================================================
340 void GeometryGUI_BoxDlg::ActivateThisDialog()
342 GeometryGUI_Skeleton::ActivateThisDialog();
343 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
344 if(!mySimulationTopoDs.IsNull())
345 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs);
350 //=================================================================================
351 // function : enterEvent [REDEFINED]
353 //=================================================================================
354 void GeometryGUI_BoxDlg::enterEvent(QEvent* e)
356 if (GroupConstructors->isEnabled())
358 this->ActivateThisDialog();
363 //=================================================================================
364 // function : ValueChangedInSpinBox()
366 //=================================================================================
367 void GeometryGUI_BoxDlg::ValueChangedInSpinBox(double newValue)
369 myGeomGUI->EraseSimulationShape();
370 mySimulationTopoDs.Nullify();
371 QObject* send = (QObject*)sender();
374 if(send == GroupDimensions->SpinBox_DX ) {
376 vy = GroupDimensions->SpinBox_DY->GetValue();
377 vz = GroupDimensions->SpinBox_DZ->GetValue();
378 } else if (send == GroupDimensions->SpinBox_DY) {
379 vx = GroupDimensions->SpinBox_DX->GetValue();
381 vz = GroupDimensions->SpinBox_DZ->GetValue();
382 } else if (send == GroupDimensions->SpinBox_DZ) {
383 vx = GroupDimensions->SpinBox_DX->GetValue();
384 vy = GroupDimensions->SpinBox_DY->GetValue();
388 myPoint1.SetCoord(0.0, 0.0, 0.0);
389 myPoint2.SetCoord(vx, vy, vz);
391 if(TestBoxDimensions(myPoint1, myPoint2)) {
392 mySimulationTopoDs = BRepPrimAPI_MakeBox(myPoint1, myPoint2).Shape();
393 myGeomGUI->DisplaySimulationShape(mySimulationTopoDs);
399 //=================================================================================
400 // function : TestBoxDimensions()
402 //=================================================================================
403 bool GeometryGUI_BoxDlg::TestBoxDimensions(gp_Pnt P1, gp_Pnt P2)
405 if ((fabs(P1.X() - P2.X()) > Precision::Confusion()) &&
406 (fabs(P1.Y() - P2.Y()) > Precision::Confusion()) &&
407 (fabs(P1.Z() - P2.Z()) > Precision::Confusion()))