]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_MaxToleranceDlg.cxx
Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / MeasureGUI / MeasureGUI_MaxToleranceDlg.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_MaxToleranceDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "MeasureGUI_MaxToleranceDlg.h"
30
31 #include <TopoDS_Vertex.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <BRep_Tool.hxx>
36
37 #include "utilities.h"
38
39 using namespace std;
40
41 //=================================================================================
42 // class    : MeasureGUI_MaxToleranceDlg()
43 // purpose  : Constructs a MeasureGUI_MaxToleranceDlg which is a child of 'parent', with the 
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 MeasureGUI_MaxToleranceDlg::MeasureGUI_MaxToleranceDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
49   :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 {
51   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TOLERANCE")));
52   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53
54   setCaption(tr("GEOM_TOLERANCE_TITLE"));
55
56   /***************************************************************/
57   GroupConstructors->setTitle(tr("GEOM_TOLERANCE"));
58   RadioButton1->setPixmap(image0);
59
60   GroupC1 = new MeasureGUI_1Sel6LineEdit_QTD(this, "GroupC1");
61   GroupC1->GroupBox1->setTitle(tr("GEOM_TOLERANCE_CONSTR"));
62   GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
63   GroupC1->TextLabel2->setText(tr("GEOM_MIN"));
64   GroupC1->TextLabel3->setText(tr("GEOM_MAX"));
65   GroupC1->TextLabel4->setText(tr("GEOM_TOLERANCE_FACE"));
66   GroupC1->TextLabel5->setText(tr("GEOM_TOLERANCE_EDGE"));
67   GroupC1->TextLabel6->setText(tr("GEOM_TOLERANCE_VERTEX"));
68   GroupC1->LineEdit11->setReadOnly(TRUE);
69   GroupC1->LineEdit12->setReadOnly(TRUE);
70   GroupC1->LineEdit21->setReadOnly(TRUE);
71   GroupC1->LineEdit22->setReadOnly(TRUE);
72   GroupC1->LineEdit31->setReadOnly(TRUE);
73   GroupC1->LineEdit32->setReadOnly(TRUE);
74   GroupC1->PushButton1->setPixmap(image1);
75
76   Layout1->addWidget(GroupC1, 1, 0);
77   /***************************************************************/
78
79   /* Initialisation */
80   Init();
81 }
82
83
84 //=================================================================================
85 // function : ~MeasureGUI_MaxToleranceDlg()
86 // purpose  : Destroys the object and frees any allocated resources
87 //=================================================================================
88 MeasureGUI_MaxToleranceDlg::~MeasureGUI_MaxToleranceDlg()
89 {
90   // no need to delete child widgets, Qt does it all for us
91 }
92
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void MeasureGUI_MaxToleranceDlg::Init()
99 {
100   /* init variables */
101   myEditCurrentArgument = GroupC1->LineEdit1;
102
103    /* signals and slots connections */
104   connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
105   connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
106
107   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
108
109   /* displays Dialog */
110   GroupC1->show();
111   this->show();
112
113   return;
114 }
115
116
117 //=================================================================================
118 // function : SelectionIntoArgument()
119 // purpose  : Called when selection as changed or other case
120 //=================================================================================
121 void MeasureGUI_MaxToleranceDlg::SelectionIntoArgument()
122 {
123   myEditCurrentArgument->setText("");
124   QString aString = "";
125
126   GroupC1->LineEdit11->setText("");
127   GroupC1->LineEdit12->setText("");
128   GroupC1->LineEdit21->setText("");
129   GroupC1->LineEdit22->setText("");
130   GroupC1->LineEdit31->setText("");
131   GroupC1->LineEdit32->setText("");
132
133   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
134   if(nbSel != 1)
135     return;
136
137   /*  nbSel == 1  */
138   TopoDS_Shape S;
139   if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
140     return;
141
142   if(S.IsNull())
143     return;
144
145   GroupC1->LineEdit1->setText(aString);
146
147   this->CalculateMaxTolerance(S);
148   return;
149 }
150
151
152 //=================================================================================
153 // function : SetEditCurrentArgument()
154 // purpose  :
155 //=================================================================================
156 void MeasureGUI_MaxToleranceDlg::SetEditCurrentArgument()
157 {
158   QPushButton* send = (QPushButton*)sender();
159
160   if(send == GroupC1->PushButton1) {
161     GroupC1->LineEdit1->setFocus();
162     myEditCurrentArgument = GroupC1->LineEdit1;
163   }
164
165   this->SelectionIntoArgument();
166   return;
167 }
168
169
170 //=================================================================================
171 // function : LineEditReturnPressed()
172 // purpose  :
173 //=================================================================================
174 void MeasureGUI_MaxToleranceDlg::LineEditReturnPressed()
175 {
176   QLineEdit* send = (QLineEdit*)sender();
177   if(send == GroupC1->LineEdit1)
178     myEditCurrentArgument = GroupC1->LineEdit1;
179   else
180     return;
181
182   MeasureGUI_Skeleton::LineEditReturnPressed();
183   return;
184 }
185
186
187 //=================================================================================
188 // function : ActivateThisDialog()
189 // purpose  :
190 //=================================================================================
191 void MeasureGUI_MaxToleranceDlg::ActivateThisDialog()
192 {
193   MeasureGUI_Skeleton::ActivateThisDialog();
194   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
195   return;
196 }
197
198
199 //=================================================================================
200 // function : enterEvent()
201 // purpose  :
202 //=================================================================================
203 void MeasureGUI_MaxToleranceDlg::enterEvent(QEvent* e)
204 {
205   if(GroupConstructors->isEnabled())
206     return;
207   this->ActivateThisDialog();
208   return;
209 }
210
211
212 //=================================================================================
213 // function : CalculateMaxTolerance()
214 // purpose  :
215 //=================================================================================
216 void MeasureGUI_MaxToleranceDlg::CalculateMaxTolerance(const TopoDS_Shape& S)
217 {
218   GroupC1->LineEdit11->setText("");
219   GroupC1->LineEdit12->setText("");
220   GroupC1->LineEdit21->setText("");
221   GroupC1->LineEdit22->setText("");
222   GroupC1->LineEdit31->setText("");
223   GroupC1->LineEdit32->setText("");
224
225   if(S.IsNull()) 
226     return;
227
228   Standard_Real T, TMF, TME, TMV, TmF, TmE, TmV;
229   Standard_Integer nbF, nbE, nbV;
230   bool m_isFace, m_isEdge, m_isVertex;
231
232   TMF = TME = TMV = -RealLast();
233   TmF = TmE = TmV = RealLast();
234   nbF = nbE = nbV = 0;
235   m_isFace = m_isEdge = m_isVertex = false;
236
237   try {
238     for(TopExp_Explorer ExF(S,TopAbs_FACE); ExF.More(); ExF.Next()) { 
239       m_isFace = true;
240       TopoDS_Face Face=TopoDS::Face(ExF.Current());
241       T=BRep_Tool::Tolerance(Face);
242       if(T>TMF)
243         TMF=T;
244       if(T<TmF)
245         TmF=T;
246       nbF++;
247     }
248     for(TopExp_Explorer ExE(S,TopAbs_EDGE); ExE.More(); ExE.Next()) { 
249       m_isEdge = true;
250       TopoDS_Edge Edge=TopoDS::Edge(ExE.Current());
251       T=BRep_Tool::Tolerance(Edge);
252       if(T>TME)
253         TME=T;
254       if(T<TmE)
255         TmE=T;
256       nbE++;
257     }
258     for(TopExp_Explorer ExV(S,TopAbs_VERTEX); ExV.More(); ExV.Next()) { 
259       m_isVertex = true;
260       TopoDS_Vertex Vertex=TopoDS::Vertex(ExV.Current());
261       T=BRep_Tool::Tolerance(Vertex);
262       if(T>TMV)
263         TMV=T;
264       if(T<TmV)
265         TmV=T;
266       nbV++;
267     }
268
269     if(m_isFace) {
270       GroupC1->LineEdit11->setText(tr("%1").arg(TmF, 5, 'e', 8));
271       GroupC1->LineEdit12->setText(tr("%1").arg(TMF, 5, 'e', 8));
272     }
273     if(m_isEdge) {
274       GroupC1->LineEdit21->setText(tr("%1").arg(TmE, 5, 'e', 8));
275       GroupC1->LineEdit22->setText(tr("%1").arg(TME, 5, 'e', 8));
276       }
277     if(m_isVertex) {
278       GroupC1->LineEdit31->setText(tr("%1").arg(TmV, 5, 'e', 8));
279       GroupC1->LineEdit32->setText(tr("%1").arg(TMV, 5, 'e', 8));
280     }
281   }
282   catch(Standard_Failure) 
283     {
284       MESSAGE("Catch intercepted in CalculateMaxTolerance()");
285     }
286   return;
287 }