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 : PrimitiveGUI_BoxDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "PrimitiveGUI_BoxDlg.h"
32 #include <BRepPrimAPI_MakeBox.hxx>
33 #include <Precision.hxx>
34 #include "QAD_Config.h"
36 //=================================================================================
37 // class : PrimitiveGUI_BoxDlg()
38 // purpose : Constructs a PrimitiveGUI_BoxDlg which is a child of 'parent', with the
39 // name 'name' and widget flags set to 'f'.
40 // The dialog will by default be modeless, unless you set 'modal' to
41 // TRUE to construct a modal dialog.
42 //=================================================================================
43 PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
44 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BOX_2P")));
47 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BOX_DXYZ")));
48 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_SELECT")));
50 setCaption(tr("GEOM_BOX_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_BOX"));
54 RadioButton1->setPixmap(image0);
55 RadioButton2->setPixmap(image1);
56 RadioButton3->close(TRUE);
58 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
59 GroupPoints->GroupBox1->setTitle(tr("GEOM_DIAGONAL_POINTS"));
60 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
61 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
62 GroupPoints->PushButton1->setPixmap(image2);
63 GroupPoints->PushButton2->setPixmap(image2);
65 GroupDimensions = new DlgRef_3Spin(this, "GroupDimensions");
66 GroupDimensions->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
67 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
68 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
69 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
71 Layout1->addWidget(GroupPoints, 1, 0);
72 Layout1->addWidget(GroupDimensions, 1, 0);
73 /***************************************************************/
76 myPrimitiveGUI = thePrimitiveGUI;
81 //=================================================================================
82 // function : ~DialogBox_Box()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 PrimitiveGUI_BoxDlg::~PrimitiveGUI_BoxDlg()
87 // no need to delete child widgets, Qt does it all for us
91 //=================================================================================
94 //=================================================================================
95 void PrimitiveGUI_BoxDlg::Init()
99 myEditCurrentArgument = GroupPoints->LineEdit1;
101 myPoint1.SetCoord(0.0, 0.0, 0.0);
102 myPoint2.SetCoord(0.0, 0.0, 0.0);
103 myOkPoint1 = myOkPoint2 = false;
105 /* Vertices Filter for all arguments */
106 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
107 mySelection->AddFilter(myVertexFilter);
109 /* Get setting of step value from file configuration */
110 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
111 step = St.toDouble();
113 /* min, max, step and decimals for spin boxes */
114 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
115 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
116 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
118 double initValue = 200.0;
119 GroupDimensions->SpinBox_DX->SetValue(initValue);
120 GroupDimensions->SpinBox_DY->SetValue(initValue);
121 GroupDimensions->SpinBox_DZ->SetValue(initValue);
123 /* signals and slots connections */
124 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
128 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
135 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
136 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
138 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
139 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
140 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
142 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
144 /* displays Dialog */
145 GroupDimensions->hide();
153 //=================================================================================
154 // function : ConstructorsClicked()
155 // purpose : Radio button management
156 //=================================================================================
157 void PrimitiveGUI_BoxDlg::ConstructorsClicked(int constructorId)
159 myConstructorId = constructorId;
160 mySelection->ClearFilters();
161 myGeomBase->EraseSimulationShape();
162 mySimulationTopoDs.Nullify();
163 disconnect(mySelection, 0, this, 0);
164 myOkPoint1 = myOkPoint2 = false;
166 switch (constructorId)
170 GroupDimensions->hide();
174 myEditCurrentArgument = GroupPoints->LineEdit1;
175 GroupPoints->LineEdit1->setText("");
176 GroupPoints->LineEdit2->setText("");
178 /* filter for next selection */
179 mySelection->AddFilter(myVertexFilter);
180 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
187 GroupDimensions->show();
189 double initValue = 200.0;
190 GroupDimensions->SpinBox_DX->SetValue(initValue);
191 GroupDimensions->SpinBox_DY->SetValue(initValue);
192 GroupDimensions->SpinBox_DZ->SetValue(initValue);
194 myPoint1.SetCoord(0.0, 0.0, 0.0) ;
195 myPoint2.SetCoord(initValue, initValue, initValue);
197 mySimulationTopoDs = BRepPrimAPI_MakeBox(myPoint1, myPoint2).Shape();
198 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
206 //=================================================================================
207 // function : ClickOnOk()
209 //=================================================================================
210 void PrimitiveGUI_BoxDlg::ClickOnOk()
212 this->ClickOnApply();
218 //=================================================================================
219 // function : ClickOnApply()
221 //=================================================================================
222 void PrimitiveGUI_BoxDlg::ClickOnApply()
224 QAD_Application::getDesktop()->putInfo(tr(""));
225 if (mySimulationTopoDs.IsNull())
227 myGeomBase->EraseSimulationShape();
228 mySimulationTopoDs.Nullify();
230 switch(myConstructorId)
234 if(myOkPoint1 && myOkPoint2)
235 myPrimitiveGUI->MakeBoxAndDisplay(myPoint1, myPoint2);
240 /* Recup args and call method */
241 double vx = GroupDimensions->SpinBox_DX->GetValue();
242 double vy = GroupDimensions->SpinBox_DY->GetValue();
243 double vz = GroupDimensions->SpinBox_DZ->GetValue();
244 myPoint1.SetCoord(0.0, 0.0, 0.0);
245 myPoint2.SetCoord(vx, vy, vz);
246 myPrimitiveGUI->MakeBoxAndDisplay(myPoint1, myPoint2);
254 //=================================================================================
255 // function : SelectionIntoArgument()
256 // purpose : Called when selection as changed
257 //=================================================================================
258 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
260 myGeomBase->EraseSimulationShape();
261 myEditCurrentArgument->setText("");
262 QString aString = ""; /* name of selection */
264 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
266 if (myEditCurrentArgument == GroupPoints->LineEdit1)
268 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
275 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
278 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
279 myEditCurrentArgument->setText(aString);
282 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
283 myEditCurrentArgument->setText(aString);
287 if(myOkPoint1 && myOkPoint2 && TestBoxDimensions(myPoint1, myPoint2)) {
288 mySimulationTopoDs = BRepPrimAPI_MakeBox(myPoint1, myPoint2).Shape();
289 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
295 //=================================================================================
296 // function : SetEditCurrentArgument()
298 //=================================================================================
299 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
301 if(myConstructorId != 0)
304 QPushButton* send = (QPushButton*)sender();
306 if(send == GroupPoints->PushButton1) {
307 GroupPoints->LineEdit1->setFocus();
308 myEditCurrentArgument = GroupPoints->LineEdit1;
310 else if(send == GroupPoints->PushButton2) {
311 GroupPoints->LineEdit2->setFocus();
312 myEditCurrentArgument = GroupPoints->LineEdit2;
314 mySelection->AddFilter(myVertexFilter);
315 this->SelectionIntoArgument();
321 //=================================================================================
322 // function : LineEditReturnPressed()
324 //=================================================================================
325 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
327 QLineEdit* send = (QLineEdit*)sender();
328 if(send == GroupPoints->LineEdit1)
329 myEditCurrentArgument = GroupPoints->LineEdit1;
330 else if (send == GroupPoints->LineEdit2)
331 myEditCurrentArgument = GroupPoints->LineEdit2;
335 GEOMBase_Skeleton::LineEditReturnPressed();
340 //=================================================================================
341 // function : ActivateThisDialog()
343 //=================================================================================
344 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
346 GEOMBase_Skeleton::ActivateThisDialog();
347 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
348 if(myConstructorId == 0)
349 mySelection->AddFilter(myVertexFilter);
350 if(!mySimulationTopoDs.IsNull())
351 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
356 //=================================================================================
357 // function : enterEvent [REDEFINED]
359 //=================================================================================
360 void PrimitiveGUI_BoxDlg::enterEvent(QEvent* e)
362 if(GroupConstructors->isEnabled())
364 this->ActivateThisDialog();
369 //=================================================================================
370 // function : ValueChangedInSpinBox()
372 //=================================================================================
373 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox(double newValue)
375 myGeomBase->EraseSimulationShape();
376 mySimulationTopoDs.Nullify();
377 QObject* send = (QObject*)sender();
380 if(send == GroupDimensions->SpinBox_DX) {
382 vy = GroupDimensions->SpinBox_DY->GetValue();
383 vz = GroupDimensions->SpinBox_DZ->GetValue();
385 else if(send == GroupDimensions->SpinBox_DY) {
386 vx = GroupDimensions->SpinBox_DX->GetValue();
388 vz = GroupDimensions->SpinBox_DZ->GetValue();
390 else if(send == GroupDimensions->SpinBox_DZ) {
391 vx = GroupDimensions->SpinBox_DX->GetValue();
392 vy = GroupDimensions->SpinBox_DY->GetValue();
396 myPoint1.SetCoord(0.0, 0.0, 0.0);
397 myPoint2.SetCoord(vx, vy, vz);
399 if(TestBoxDimensions(myPoint1, myPoint2)) {
400 mySimulationTopoDs = BRepPrimAPI_MakeBox(myPoint1, myPoint2).Shape();
401 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
407 //=================================================================================
408 // function : TestBoxDimensions()
410 //=================================================================================
411 bool PrimitiveGUI_BoxDlg::TestBoxDimensions(gp_Pnt P1, gp_Pnt P2)
413 if ((fabs(P1.X() - P2.X()) > Precision::Confusion()) &&
414 (fabs(P1.Y() - P2.Y()) > Precision::Confusion()) &&
415 (fabs(P1.Z() - P2.Z()) > Precision::Confusion()))