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_MaxToleranceDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "MeasureGUI_MaxToleranceDlg.h"
32 #include <TopoDS_Vertex.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <BRep_Tool.hxx>
38 //=================================================================================
39 // class : MeasureGUI_MaxToleranceDlg()
40 // purpose : Constructs a MeasureGUI_MaxToleranceDlg 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_MaxToleranceDlg::MeasureGUI_MaxToleranceDlg(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_TOLERANCE")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_TOLERANCE_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_TOLERANCE"));
55 RadioButton1->setPixmap(image0);
57 GroupC1 = new MeasureGUI_1Sel6LineEdit_QTD(this, "GroupC1");
58 GroupC1->GroupBox1->setTitle(tr("GEOM_TOLERANCE_CONSTR"));
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_TOLERANCE_FACE"));
63 GroupC1->TextLabel5->setText(tr("GEOM_TOLERANCE_EDGE"));
64 GroupC1->TextLabel6->setText(tr("GEOM_TOLERANCE_VERTEX"));
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_MaxToleranceDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 MeasureGUI_MaxToleranceDlg::~MeasureGUI_MaxToleranceDlg()
87 // no need to delete child widgets, Qt does it all for us
91 //=================================================================================
94 //=================================================================================
95 void MeasureGUI_MaxToleranceDlg::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_MaxToleranceDlg::SelectionIntoArgument()
120 myEditCurrentArgument->setText("");
121 QString aString = "";
123 GroupC1->LineEdit11->setText("");
124 GroupC1->LineEdit12->setText("");
125 GroupC1->LineEdit21->setText("");
126 GroupC1->LineEdit22->setText("");
127 GroupC1->LineEdit31->setText("");
128 GroupC1->LineEdit32->setText("");
130 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
136 if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
142 GroupC1->LineEdit1->setText(aString);
144 this->CalculateMaxTolerance(S);
149 //=================================================================================
150 // function : SetEditCurrentArgument()
152 //=================================================================================
153 void MeasureGUI_MaxToleranceDlg::SetEditCurrentArgument()
155 QPushButton* send = (QPushButton*)sender();
157 if(send == GroupC1->PushButton1) {
158 GroupC1->LineEdit1->setFocus();
159 myEditCurrentArgument = GroupC1->LineEdit1;
162 this->SelectionIntoArgument();
167 //=================================================================================
168 // function : LineEditReturnPressed()
170 //=================================================================================
171 void MeasureGUI_MaxToleranceDlg::LineEditReturnPressed()
173 QLineEdit* send = (QLineEdit*)sender();
174 if(send == GroupC1->LineEdit1)
175 myEditCurrentArgument = GroupC1->LineEdit1;
179 MeasureGUI_Skeleton::LineEditReturnPressed();
184 //=================================================================================
185 // function : ActivateThisDialog()
187 //=================================================================================
188 void MeasureGUI_MaxToleranceDlg::ActivateThisDialog()
190 MeasureGUI_Skeleton::ActivateThisDialog();
191 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
196 //=================================================================================
197 // function : enterEvent()
199 //=================================================================================
200 void MeasureGUI_MaxToleranceDlg::enterEvent(QEvent* e)
202 if(GroupConstructors->isEnabled())
204 this->ActivateThisDialog();
209 //=================================================================================
210 // function : CalculateMaxTolerance()
212 //=================================================================================
213 void MeasureGUI_MaxToleranceDlg::CalculateMaxTolerance(const TopoDS_Shape& S)
215 GroupC1->LineEdit11->setText("");
216 GroupC1->LineEdit12->setText("");
217 GroupC1->LineEdit21->setText("");
218 GroupC1->LineEdit22->setText("");
219 GroupC1->LineEdit31->setText("");
220 GroupC1->LineEdit32->setText("");
225 Standard_Real T, TMF, TME, TMV, TmF, TmE, TmV;
226 Standard_Integer nbF, nbE, nbV;
227 bool m_isFace, m_isEdge, m_isVertex;
229 TMF = TME = TMV = -RealLast();
230 TmF = TmE = TmV = RealLast();
232 m_isFace = m_isEdge = m_isVertex = false;
235 for(TopExp_Explorer ExF(S,TopAbs_FACE); ExF.More(); ExF.Next()) {
237 TopoDS_Face Face=TopoDS::Face(ExF.Current());
238 T=BRep_Tool::Tolerance(Face);
245 for(TopExp_Explorer ExE(S,TopAbs_EDGE); ExE.More(); ExE.Next()) {
247 TopoDS_Edge Edge=TopoDS::Edge(ExE.Current());
248 T=BRep_Tool::Tolerance(Edge);
255 for(TopExp_Explorer ExV(S,TopAbs_VERTEX); ExV.More(); ExV.Next()) {
257 TopoDS_Vertex Vertex=TopoDS::Vertex(ExV.Current());
258 T=BRep_Tool::Tolerance(Vertex);
267 GroupC1->LineEdit11->setText(tr("%1").arg(TmF, 5, 'e', 8));
268 GroupC1->LineEdit12->setText(tr("%1").arg(TMF, 5, 'e', 8));
271 GroupC1->LineEdit21->setText(tr("%1").arg(TmE, 5, 'e', 8));
272 GroupC1->LineEdit22->setText(tr("%1").arg(TME, 5, 'e', 8));
275 GroupC1->LineEdit31->setText(tr("%1").arg(TmV, 5, 'e', 8));
276 GroupC1->LineEdit32->setText(tr("%1").arg(TMV, 5, 'e', 8));
279 catch(Standard_Failure)
281 MESSAGE("Catch intercepted in CalculateMaxTolerance()");