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 : MeasureGUI_BndBoxDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "MeasureGUI_BndBoxDlg.h"
31 #include <BRepPrimAPI_MakeBox.hxx>
32 #include <BRepBndLib.hxx>
34 #include "utilities.h"
38 //=================================================================================
39 // class : MeasureGUI_BndBoxDlg()
40 // purpose : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
46 :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BOUNDING_BOX")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_BNDBOX_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_BNDBOX"));
55 RadioButton1->setPixmap(image0);
57 GroupC1 = new MeasureGUI_1Sel6LineEdit_QTD(this, "GroupC1");
58 GroupC1->GroupBox1->setTitle(tr("GEOM_BNDBOX_OBJDIM"));
59 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
60 GroupC1->TextLabel2->setText(tr("GEOM_MIN"));
61 GroupC1->TextLabel3->setText(tr("GEOM_MAX"));
62 GroupC1->TextLabel4->setText(tr("GEOM_X"));
63 GroupC1->TextLabel5->setText(tr("GEOM_Y"));
64 GroupC1->TextLabel6->setText(tr("GEOM_Z"));
65 GroupC1->LineEdit11->setReadOnly(TRUE);
66 GroupC1->LineEdit12->setReadOnly(TRUE);
67 GroupC1->LineEdit21->setReadOnly(TRUE);
68 GroupC1->LineEdit22->setReadOnly(TRUE);
69 GroupC1->LineEdit31->setReadOnly(TRUE);
70 GroupC1->LineEdit32->setReadOnly(TRUE);
71 GroupC1->PushButton1->setPixmap(image1);
73 Layout1->addWidget(GroupC1, 1, 0);
74 /***************************************************************/
81 //=================================================================================
82 // function : ~MeasureGUI_BndBoxDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
87 // no need to delete child widgets, Qt does it all for us
91 //=================================================================================
94 //=================================================================================
95 void MeasureGUI_BndBoxDlg::Init()
98 myEditCurrentArgument = GroupC1->LineEdit1;
100 /* signals and slots connections */
101 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
102 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
104 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
106 /* displays Dialog */
114 //=================================================================================
115 // function : SelectionIntoArgument()
116 // purpose : Called when selection as changed or other case
117 //=================================================================================
118 void MeasureGUI_BndBoxDlg::SelectionIntoArgument()
120 myGeomBase->EraseSimulationShape();
121 mySimulationTopoDs.Nullify();
122 myEditCurrentArgument->setText("");
123 QString aString = "";
125 GroupC1->LineEdit11->setText("");
126 GroupC1->LineEdit12->setText("");
127 GroupC1->LineEdit21->setText("");
128 GroupC1->LineEdit22->setText("");
129 GroupC1->LineEdit31->setText("");
130 GroupC1->LineEdit32->setText("");
132 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
138 if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
141 GroupC1->LineEdit1->setText(aString);
143 this->CalculateAndDisplayBndBox(S);
148 //=================================================================================
149 // function : SetEditCurrentArgument()
151 //=================================================================================
152 void MeasureGUI_BndBoxDlg::SetEditCurrentArgument()
154 QPushButton* send = (QPushButton*)sender();
156 if(send == GroupC1->PushButton1) {
157 GroupC1->LineEdit1->setFocus();
158 myEditCurrentArgument = GroupC1->LineEdit1;
161 this->SelectionIntoArgument();
166 //=================================================================================
167 // function : LineEditReturnPressed()
169 //=================================================================================
170 void MeasureGUI_BndBoxDlg::LineEditReturnPressed()
172 QLineEdit* send = (QLineEdit*)sender();
173 if(send == GroupC1->LineEdit1)
174 myEditCurrentArgument = GroupC1->LineEdit1;
178 MeasureGUI_Skeleton::LineEditReturnPressed();
183 //=================================================================================
184 // function : ActivateThisDialog()
186 //=================================================================================
187 void MeasureGUI_BndBoxDlg::ActivateThisDialog()
189 MeasureGUI_Skeleton::ActivateThisDialog();
190 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
191 if(!mySimulationTopoDs.IsNull())
192 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
197 //=================================================================================
198 // function : enterEvent()
200 //=================================================================================
201 void MeasureGUI_BndBoxDlg::enterEvent(QEvent* e)
203 if(GroupConstructors->isEnabled())
205 this->ActivateThisDialog();
210 //=================================================================================
211 // function : CalculateAndDisplayBndBox()
213 //=================================================================================
214 void MeasureGUI_BndBoxDlg::CalculateAndDisplayBndBox(const TopoDS_Shape& S)
216 GroupC1->LineEdit11->setText("");
217 GroupC1->LineEdit12->setText("");
218 GroupC1->LineEdit21->setText("");
219 GroupC1->LineEdit22->setText("");
220 GroupC1->LineEdit31->setText("");
221 GroupC1->LineEdit32->setText("");
226 Standard_Real axmin, aymin, azmin, axmax, aymax, azmax;
230 BRepBndLib::Add(S,B);
231 B.Get(axmin, aymin, azmin, axmax, aymax, azmax);
232 GroupC1->LineEdit11->setText(tr("%1").arg(axmin, 12, 'f', 6));
233 GroupC1->LineEdit12->setText(tr("%1").arg(axmax, 12, 'f', 6));
234 GroupC1->LineEdit21->setText(tr("%1").arg(aymin, 12, 'f', 6));
235 GroupC1->LineEdit22->setText(tr("%1").arg(aymax, 12, 'f', 6));
236 GroupC1->LineEdit31->setText(tr("%1").arg(azmin, 12, 'f', 6));
237 GroupC1->LineEdit32->setText(tr("%1").arg(azmax, 12, 'f', 6));
239 mySimulationTopoDs = BRepPrimAPI_MakeBox(gp_Pnt(axmin, aymin, azmin), gp_Pnt(axmax, aymax, azmax)).Shape();
240 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
242 catch(Standard_Failure) {
243 MESSAGE("Catch intercepted in CalculateAndDisplayBndBox()");