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 buttonApply->setFocus();
225 QAD_Application::getDesktop()->putInfo(tr(""));
226 if (mySimulationTopoDs.IsNull())
228 myGeomBase->EraseSimulationShape();
229 mySimulationTopoDs.Nullify();
231 switch(myConstructorId)
235 if(myOkPoint1 && myOkPoint2)
236 myPrimitiveGUI->MakeBoxAndDisplay(myPoint1, myPoint2);
241 /* Recup args and call method */
242 double vx = GroupDimensions->SpinBox_DX->GetValue();
243 double vy = GroupDimensions->SpinBox_DY->GetValue();
244 double vz = GroupDimensions->SpinBox_DZ->GetValue();
245 myPoint1.SetCoord(0.0, 0.0, 0.0);
246 myPoint2.SetCoord(vx, vy, vz);
247 myPrimitiveGUI->MakeBoxAndDisplay(myPoint1, myPoint2);
255 //=================================================================================
256 // function : SelectionIntoArgument()
257 // purpose : Called when selection as changed
258 //=================================================================================
259 void PrimitiveGUI_BoxDlg::SelectionIntoArgument()
261 myGeomBase->EraseSimulationShape();
262 myEditCurrentArgument->setText("");
263 QString aString = ""; /* name of selection */
265 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
267 if (myEditCurrentArgument == GroupPoints->LineEdit1)
269 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
276 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
279 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
280 myEditCurrentArgument->setText(aString);
283 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
284 myEditCurrentArgument->setText(aString);
288 if(myOkPoint1 && myOkPoint2 && TestBoxDimensions(myPoint1, myPoint2)) {
289 mySimulationTopoDs = BRepPrimAPI_MakeBox(myPoint1, myPoint2).Shape();
290 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
296 //=================================================================================
297 // function : SetEditCurrentArgument()
299 //=================================================================================
300 void PrimitiveGUI_BoxDlg::SetEditCurrentArgument()
302 if(myConstructorId != 0)
305 QPushButton* send = (QPushButton*)sender();
307 if(send == GroupPoints->PushButton1) {
308 GroupPoints->LineEdit1->setFocus();
309 myEditCurrentArgument = GroupPoints->LineEdit1;
311 else if(send == GroupPoints->PushButton2) {
312 GroupPoints->LineEdit2->setFocus();
313 myEditCurrentArgument = GroupPoints->LineEdit2;
315 mySelection->AddFilter(myVertexFilter);
316 this->SelectionIntoArgument();
322 //=================================================================================
323 // function : LineEditReturnPressed()
325 //=================================================================================
326 void PrimitiveGUI_BoxDlg::LineEditReturnPressed()
328 QLineEdit* send = (QLineEdit*)sender();
329 if(send == GroupPoints->LineEdit1)
330 myEditCurrentArgument = GroupPoints->LineEdit1;
331 else if (send == GroupPoints->LineEdit2)
332 myEditCurrentArgument = GroupPoints->LineEdit2;
336 GEOMBase_Skeleton::LineEditReturnPressed();
341 //=================================================================================
342 // function : ActivateThisDialog()
344 //=================================================================================
345 void PrimitiveGUI_BoxDlg::ActivateThisDialog()
347 GEOMBase_Skeleton::ActivateThisDialog();
348 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
349 if(myConstructorId == 0)
350 mySelection->AddFilter(myVertexFilter);
351 if(!mySimulationTopoDs.IsNull())
352 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
357 //=================================================================================
358 // function : enterEvent [REDEFINED]
360 //=================================================================================
361 void PrimitiveGUI_BoxDlg::enterEvent(QEvent* e)
363 if(GroupConstructors->isEnabled())
365 this->ActivateThisDialog();
370 //=================================================================================
371 // function : ValueChangedInSpinBox()
373 //=================================================================================
374 void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox(double newValue)
376 myGeomBase->EraseSimulationShape();
377 mySimulationTopoDs.Nullify();
378 QObject* send = (QObject*)sender();
381 if(send == GroupDimensions->SpinBox_DX) {
383 vy = GroupDimensions->SpinBox_DY->GetValue();
384 vz = GroupDimensions->SpinBox_DZ->GetValue();
386 else if(send == GroupDimensions->SpinBox_DY) {
387 vx = GroupDimensions->SpinBox_DX->GetValue();
389 vz = GroupDimensions->SpinBox_DZ->GetValue();
391 else if(send == GroupDimensions->SpinBox_DZ) {
392 vx = GroupDimensions->SpinBox_DX->GetValue();
393 vy = GroupDimensions->SpinBox_DY->GetValue();
397 myPoint1.SetCoord(0.0, 0.0, 0.0);
398 myPoint2.SetCoord(vx, vy, vz);
400 if(TestBoxDimensions(myPoint1, myPoint2)) {
401 mySimulationTopoDs = BRepPrimAPI_MakeBox(myPoint1, myPoint2).Shape();
402 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
408 //=================================================================================
409 // function : TestBoxDimensions()
411 //=================================================================================
412 bool PrimitiveGUI_BoxDlg::TestBoxDimensions(gp_Pnt P1, gp_Pnt P2)
414 if ((fabs(P1.X() - P2.X()) > Precision::Confusion()) &&
415 (fabs(P1.Y() - P2.Y()) > Precision::Confusion()) &&
416 (fabs(P1.Z() - P2.Z()) > Precision::Confusion()))