]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_BndBoxDlg.cxx
Salome HOME
DCQ : New Architecture
[modules/geom.git] / src / MeasureGUI / MeasureGUI_BndBoxDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MeasureGUI_BndBoxDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "MeasureGUI_BndBoxDlg.h"
31
32 #include <BRepPrimAPI_MakeBox.hxx>
33 #include <BRepBndLib.hxx>
34
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)
44 {
45   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BOUNDING_BOX")));
46   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
47
48   setCaption(tr("GEOM_BNDBOX_TITLE"));
49
50   /***************************************************************/
51   GroupConstructors->setTitle(tr("GEOM_BNDBOX"));
52   RadioButton1->setPixmap(image0);
53
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);
69
70   Layout1->addWidget(GroupC1, 1, 0);
71   /***************************************************************/
72
73   /* Initialisation */
74   Init();
75 }
76
77
78 //=================================================================================
79 // function : ~MeasureGUI_BndBoxDlg()
80 // purpose  : Destroys the object and frees any allocated resources
81 //=================================================================================
82 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
83 {
84   // no need to delete child widgets, Qt does it all for us
85 }
86
87
88 //=================================================================================
89 // function : Init()
90 // purpose  :
91 //=================================================================================
92 void MeasureGUI_BndBoxDlg::Init()
93 {
94   /* init variables */
95   myEditCurrentArgument = GroupC1->LineEdit1;
96
97    /* signals and slots connections */
98   connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
99   connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
100
101   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
102
103   /* displays Dialog */
104   GroupC1->show();
105   this->show();
106
107   return;
108 }
109
110
111 //=================================================================================
112 // function : SelectionIntoArgument()
113 // purpose  : Called when selection as changed or other case
114 //=================================================================================
115 void MeasureGUI_BndBoxDlg::SelectionIntoArgument()
116 {
117   myGeomBase->EraseSimulationShape();
118   mySimulationTopoDs.Nullify();
119   myEditCurrentArgument->setText("");
120   QString aString = "";
121
122   GroupC1->LineEdit11->setText("");
123   GroupC1->LineEdit12->setText("");
124   GroupC1->LineEdit21->setText("");
125   GroupC1->LineEdit22->setText("");
126   GroupC1->LineEdit31->setText("");
127   GroupC1->LineEdit32->setText("");
128
129   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
130   if(nbSel != 1)
131     return;
132
133   /*  nbSel == 1  */
134   TopoDS_Shape S;
135   if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
136     return;
137
138   GroupC1->LineEdit1->setText(aString);
139
140   this->CalculateAndDisplayBndBox(S);
141   return;
142 }
143
144
145 //=================================================================================
146 // function : SetEditCurrentArgument()
147 // purpose  :
148 //=================================================================================
149 void MeasureGUI_BndBoxDlg::SetEditCurrentArgument()
150 {
151   QPushButton* send = (QPushButton*)sender();
152
153   if(send == GroupC1->PushButton1) {
154     GroupC1->LineEdit1->setFocus();
155     myEditCurrentArgument = GroupC1->LineEdit1;
156   }
157
158   this->SelectionIntoArgument();
159   return;
160 }
161
162
163 //=================================================================================
164 // function : LineEditReturnPressed()
165 // purpose  :
166 //=================================================================================
167 void MeasureGUI_BndBoxDlg::LineEditReturnPressed()
168 {
169   QLineEdit* send = (QLineEdit*)sender();
170   if(send == GroupC1->LineEdit1)
171     myEditCurrentArgument = GroupC1->LineEdit1;
172   else
173     return;
174
175   MeasureGUI_Skeleton::LineEditReturnPressed();
176   return;
177 }
178
179
180 //=================================================================================
181 // function : ActivateThisDialog()
182 // purpose  :
183 //=================================================================================
184 void MeasureGUI_BndBoxDlg::ActivateThisDialog()
185 {
186   MeasureGUI_Skeleton::ActivateThisDialog();
187   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
188   if(!mySimulationTopoDs.IsNull())
189     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
190   return;
191 }
192
193
194 //=================================================================================
195 // function : enterEvent()
196 // purpose  :
197 //=================================================================================
198 void MeasureGUI_BndBoxDlg::enterEvent(QEvent* e)
199 {
200   if(GroupConstructors->isEnabled())
201     return;
202   this->ActivateThisDialog();
203   return;
204 }
205
206
207 //=================================================================================
208 // function : CalculateAndDisplayBndBox()
209 // purpose  :
210 //=================================================================================
211 void MeasureGUI_BndBoxDlg::CalculateAndDisplayBndBox(const TopoDS_Shape& S)
212 {
213   GroupC1->LineEdit11->setText("");
214   GroupC1->LineEdit12->setText("");
215   GroupC1->LineEdit21->setText("");
216   GroupC1->LineEdit22->setText("");
217   GroupC1->LineEdit31->setText("");
218   GroupC1->LineEdit32->setText("");
219
220   if(S.IsNull()) 
221     return;
222
223   Standard_Real axmin, aymin, azmin, axmax, aymax, azmax;
224   Bnd_Box B;
225
226   try {
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));
235     
236     mySimulationTopoDs = BRepPrimAPI_MakeBox(gp_Pnt(axmin, aymin, azmin), gp_Pnt(axmax, aymax, azmax)).Shape();
237     myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
238   }
239   catch(Standard_Failure) {
240     MESSAGE("Catch intercepted in CalculateAndDisplayBndBox()");
241   }
242   return;
243 }