Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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 #include "MeasureGUI_BndBoxDlg.h"
30
31 #include <BRepPrimAPI_MakeBox.hxx>
32 #include <BRepBndLib.hxx>
33
34 #include "utilities.h"
35
36 using namespace std;
37
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)
47 {
48   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BOUNDING_BOX")));
49   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
50
51   setCaption(tr("GEOM_BNDBOX_TITLE"));
52
53   /***************************************************************/
54   GroupConstructors->setTitle(tr("GEOM_BNDBOX"));
55   RadioButton1->setPixmap(image0);
56
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);
72
73   Layout1->addWidget(GroupC1, 1, 0);
74   /***************************************************************/
75
76   /* Initialisation */
77   Init();
78 }
79
80
81 //=================================================================================
82 // function : ~MeasureGUI_BndBoxDlg()
83 // purpose  : Destroys the object and frees any allocated resources
84 //=================================================================================
85 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
86 {
87   // no need to delete child widgets, Qt does it all for us
88 }
89
90
91 //=================================================================================
92 // function : Init()
93 // purpose  :
94 //=================================================================================
95 void MeasureGUI_BndBoxDlg::Init()
96 {
97   /* init variables */
98   myEditCurrentArgument = GroupC1->LineEdit1;
99
100    /* signals and slots connections */
101   connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
102   connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
103
104   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
105
106   /* displays Dialog */
107   GroupC1->show();
108   this->show();
109
110   return;
111 }
112
113
114 //=================================================================================
115 // function : SelectionIntoArgument()
116 // purpose  : Called when selection as changed or other case
117 //=================================================================================
118 void MeasureGUI_BndBoxDlg::SelectionIntoArgument()
119 {
120   myGeomBase->EraseSimulationShape();
121   mySimulationTopoDs.Nullify();
122   myEditCurrentArgument->setText("");
123   QString aString = "";
124
125   GroupC1->LineEdit11->setText("");
126   GroupC1->LineEdit12->setText("");
127   GroupC1->LineEdit21->setText("");
128   GroupC1->LineEdit22->setText("");
129   GroupC1->LineEdit31->setText("");
130   GroupC1->LineEdit32->setText("");
131
132   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
133   if(nbSel != 1)
134     return;
135
136   /*  nbSel == 1  */
137   TopoDS_Shape S;
138   if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
139     return;
140
141   GroupC1->LineEdit1->setText(aString);
142
143   this->CalculateAndDisplayBndBox(S);
144   return;
145 }
146
147
148 //=================================================================================
149 // function : SetEditCurrentArgument()
150 // purpose  :
151 //=================================================================================
152 void MeasureGUI_BndBoxDlg::SetEditCurrentArgument()
153 {
154   QPushButton* send = (QPushButton*)sender();
155
156   if(send == GroupC1->PushButton1) {
157     GroupC1->LineEdit1->setFocus();
158     myEditCurrentArgument = GroupC1->LineEdit1;
159   }
160
161   this->SelectionIntoArgument();
162   return;
163 }
164
165
166 //=================================================================================
167 // function : LineEditReturnPressed()
168 // purpose  :
169 //=================================================================================
170 void MeasureGUI_BndBoxDlg::LineEditReturnPressed()
171 {
172   QLineEdit* send = (QLineEdit*)sender();
173   if(send == GroupC1->LineEdit1)
174     myEditCurrentArgument = GroupC1->LineEdit1;
175   else
176     return;
177
178   MeasureGUI_Skeleton::LineEditReturnPressed();
179   return;
180 }
181
182
183 //=================================================================================
184 // function : ActivateThisDialog()
185 // purpose  :
186 //=================================================================================
187 void MeasureGUI_BndBoxDlg::ActivateThisDialog()
188 {
189   MeasureGUI_Skeleton::ActivateThisDialog();
190   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
191   if(!mySimulationTopoDs.IsNull())
192     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
193   return;
194 }
195
196
197 //=================================================================================
198 // function : enterEvent()
199 // purpose  :
200 //=================================================================================
201 void MeasureGUI_BndBoxDlg::enterEvent(QEvent* e)
202 {
203   if(GroupConstructors->isEnabled())
204     return;
205   this->ActivateThisDialog();
206   return;
207 }
208
209
210 //=================================================================================
211 // function : CalculateAndDisplayBndBox()
212 // purpose  :
213 //=================================================================================
214 void MeasureGUI_BndBoxDlg::CalculateAndDisplayBndBox(const TopoDS_Shape& S)
215 {
216   GroupC1->LineEdit11->setText("");
217   GroupC1->LineEdit12->setText("");
218   GroupC1->LineEdit21->setText("");
219   GroupC1->LineEdit22->setText("");
220   GroupC1->LineEdit31->setText("");
221   GroupC1->LineEdit32->setText("");
222
223   if(S.IsNull()) 
224     return;
225
226   Standard_Real axmin, aymin, azmin, axmax, aymax, azmax;
227   Bnd_Box B;
228
229   try {
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));
238     
239     mySimulationTopoDs = BRepPrimAPI_MakeBox(gp_Pnt(axmin, aymin, azmin), gp_Pnt(axmax, aymax, azmax)).Shape();
240     myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
241   }
242   catch(Standard_Failure) {
243     MESSAGE("Catch intercepted in CalculateAndDisplayBndBox()");
244   }
245   return;
246 }