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
30 #include "MeasureGUI_BndBoxDlg.h"
32 #include <BRepPrimAPI_MakeBox.hxx>
33 #include <BRepBndLib.hxx>
35 //=================================================================================
36 // class : MeasureGUI_BndBoxDlg()
37 // purpose : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the
38 // name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
43 :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BOUNDING_BOX")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
48 setCaption(tr("GEOM_BNDBOX_TITLE"));
50 /***************************************************************/
51 GroupConstructors->setTitle(tr("GEOM_BNDBOX"));
52 RadioButton1->setPixmap(image0);
54 GroupC1 = new MeasureGUI_1Sel6LineEdit_QTD(this, "GroupC1");
55 GroupC1->GroupBox1->setTitle(tr("GEOM_BNDBOX_OBJDIM"));
56 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
57 GroupC1->TextLabel2->setText(tr("GEOM_MIN"));
58 GroupC1->TextLabel3->setText(tr("GEOM_MAX"));
59 GroupC1->TextLabel4->setText(tr("GEOM_X"));
60 GroupC1->TextLabel5->setText(tr("GEOM_Y"));
61 GroupC1->TextLabel6->setText(tr("GEOM_Z"));
62 GroupC1->LineEdit11->setReadOnly(TRUE);
63 GroupC1->LineEdit12->setReadOnly(TRUE);
64 GroupC1->LineEdit21->setReadOnly(TRUE);
65 GroupC1->LineEdit22->setReadOnly(TRUE);
66 GroupC1->LineEdit31->setReadOnly(TRUE);
67 GroupC1->LineEdit32->setReadOnly(TRUE);
68 GroupC1->PushButton1->setPixmap(image1);
70 Layout1->addWidget(GroupC1, 1, 0);
71 /***************************************************************/
78 //=================================================================================
79 // function : ~MeasureGUI_BndBoxDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
84 // no need to delete child widgets, Qt does it all for us
88 //=================================================================================
91 //=================================================================================
92 void MeasureGUI_BndBoxDlg::Init()
95 myEditCurrentArgument = GroupC1->LineEdit1;
97 /* signals and slots connections */
98 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
99 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
101 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
103 /* displays Dialog */
111 //=================================================================================
112 // function : SelectionIntoArgument()
113 // purpose : Called when selection as changed or other case
114 //=================================================================================
115 void MeasureGUI_BndBoxDlg::SelectionIntoArgument()
117 myGeomBase->EraseSimulationShape();
118 mySimulationTopoDs.Nullify();
119 myEditCurrentArgument->setText("");
120 QString aString = "";
122 GroupC1->LineEdit11->setText("");
123 GroupC1->LineEdit12->setText("");
124 GroupC1->LineEdit21->setText("");
125 GroupC1->LineEdit22->setText("");
126 GroupC1->LineEdit31->setText("");
127 GroupC1->LineEdit32->setText("");
129 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
135 if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
138 GroupC1->LineEdit1->setText(aString);
140 this->CalculateAndDisplayBndBox(S);
145 //=================================================================================
146 // function : SetEditCurrentArgument()
148 //=================================================================================
149 void MeasureGUI_BndBoxDlg::SetEditCurrentArgument()
151 QPushButton* send = (QPushButton*)sender();
153 if(send == GroupC1->PushButton1) {
154 GroupC1->LineEdit1->setFocus();
155 myEditCurrentArgument = GroupC1->LineEdit1;
158 this->SelectionIntoArgument();
163 //=================================================================================
164 // function : LineEditReturnPressed()
166 //=================================================================================
167 void MeasureGUI_BndBoxDlg::LineEditReturnPressed()
169 QLineEdit* send = (QLineEdit*)sender();
170 if(send == GroupC1->LineEdit1)
171 myEditCurrentArgument = GroupC1->LineEdit1;
175 MeasureGUI_Skeleton::LineEditReturnPressed();
180 //=================================================================================
181 // function : ActivateThisDialog()
183 //=================================================================================
184 void MeasureGUI_BndBoxDlg::ActivateThisDialog()
186 MeasureGUI_Skeleton::ActivateThisDialog();
187 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
188 if(!mySimulationTopoDs.IsNull())
189 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
194 //=================================================================================
195 // function : enterEvent()
197 //=================================================================================
198 void MeasureGUI_BndBoxDlg::enterEvent(QEvent* e)
200 if(GroupConstructors->isEnabled())
202 this->ActivateThisDialog();
207 //=================================================================================
208 // function : CalculateAndDisplayBndBox()
210 //=================================================================================
211 void MeasureGUI_BndBoxDlg::CalculateAndDisplayBndBox(const TopoDS_Shape& S)
213 GroupC1->LineEdit11->setText("");
214 GroupC1->LineEdit12->setText("");
215 GroupC1->LineEdit21->setText("");
216 GroupC1->LineEdit22->setText("");
217 GroupC1->LineEdit31->setText("");
218 GroupC1->LineEdit32->setText("");
223 Standard_Real axmin, aymin, azmin, axmax, aymax, azmax;
227 BRepBndLib::Add(S,B);
228 B.Get(axmin, aymin, azmin, axmax, aymax, azmax);
229 GroupC1->LineEdit11->setText(tr("%1").arg(axmin, 12, 'f', 6));
230 GroupC1->LineEdit12->setText(tr("%1").arg(axmax, 12, 'f', 6));
231 GroupC1->LineEdit21->setText(tr("%1").arg(aymin, 12, 'f', 6));
232 GroupC1->LineEdit22->setText(tr("%1").arg(aymax, 12, 'f', 6));
233 GroupC1->LineEdit31->setText(tr("%1").arg(azmin, 12, 'f', 6));
234 GroupC1->LineEdit32->setText(tr("%1").arg(azmax, 12, 'f', 6));
236 mySimulationTopoDs = BRepPrimAPI_MakeBox(gp_Pnt(axmin, aymin, azmin), gp_Pnt(axmax, aymax, azmax)).Shape();
237 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
239 catch(Standard_Failure) {
240 MESSAGE("Catch intercepted in CalculateAndDisplayBndBox()");