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
29 #include "MeasureGUI_MaxToleranceDlg.h"
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>
37 #include "utilities.h"
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)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_TOLERANCE")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_TOLERANCE_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_TOLERANCE"));
58 RadioButton1->setPixmap(image0);
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);
76 Layout1->addWidget(GroupC1, 1, 0);
77 /***************************************************************/
84 //=================================================================================
85 // function : ~MeasureGUI_MaxToleranceDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 MeasureGUI_MaxToleranceDlg::~MeasureGUI_MaxToleranceDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void MeasureGUI_MaxToleranceDlg::Init()
101 myEditCurrentArgument = GroupC1->LineEdit1;
103 /* signals and slots connections */
104 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
105 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
107 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
109 /* displays Dialog */
117 //=================================================================================
118 // function : SelectionIntoArgument()
119 // purpose : Called when selection as changed or other case
120 //=================================================================================
121 void MeasureGUI_MaxToleranceDlg::SelectionIntoArgument()
123 myEditCurrentArgument->setText("");
124 QString aString = "";
126 GroupC1->LineEdit11->setText("");
127 GroupC1->LineEdit12->setText("");
128 GroupC1->LineEdit21->setText("");
129 GroupC1->LineEdit22->setText("");
130 GroupC1->LineEdit31->setText("");
131 GroupC1->LineEdit32->setText("");
133 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
139 if(!myGeomBase->GetTopoFromSelection(mySelection, S) || S.IsNull())
145 GroupC1->LineEdit1->setText(aString);
147 this->CalculateMaxTolerance(S);
152 //=================================================================================
153 // function : SetEditCurrentArgument()
155 //=================================================================================
156 void MeasureGUI_MaxToleranceDlg::SetEditCurrentArgument()
158 QPushButton* send = (QPushButton*)sender();
160 if(send == GroupC1->PushButton1) {
161 GroupC1->LineEdit1->setFocus();
162 myEditCurrentArgument = GroupC1->LineEdit1;
165 this->SelectionIntoArgument();
170 //=================================================================================
171 // function : LineEditReturnPressed()
173 //=================================================================================
174 void MeasureGUI_MaxToleranceDlg::LineEditReturnPressed()
176 QLineEdit* send = (QLineEdit*)sender();
177 if(send == GroupC1->LineEdit1)
178 myEditCurrentArgument = GroupC1->LineEdit1;
182 MeasureGUI_Skeleton::LineEditReturnPressed();
187 //=================================================================================
188 // function : ActivateThisDialog()
190 //=================================================================================
191 void MeasureGUI_MaxToleranceDlg::ActivateThisDialog()
193 MeasureGUI_Skeleton::ActivateThisDialog();
194 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
199 //=================================================================================
200 // function : enterEvent()
202 //=================================================================================
203 void MeasureGUI_MaxToleranceDlg::enterEvent(QEvent* e)
205 if(GroupConstructors->isEnabled())
207 this->ActivateThisDialog();
212 //=================================================================================
213 // function : CalculateMaxTolerance()
215 //=================================================================================
216 void MeasureGUI_MaxToleranceDlg::CalculateMaxTolerance(const TopoDS_Shape& S)
218 GroupC1->LineEdit11->setText("");
219 GroupC1->LineEdit12->setText("");
220 GroupC1->LineEdit21->setText("");
221 GroupC1->LineEdit22->setText("");
222 GroupC1->LineEdit31->setText("");
223 GroupC1->LineEdit32->setText("");
228 Standard_Real T, TMF, TME, TMV, TmF, TmE, TmV;
229 Standard_Integer nbF, nbE, nbV;
230 bool m_isFace, m_isEdge, m_isVertex;
232 TMF = TME = TMV = -RealLast();
233 TmF = TmE = TmV = RealLast();
235 m_isFace = m_isEdge = m_isVertex = false;
238 for(TopExp_Explorer ExF(S,TopAbs_FACE); ExF.More(); ExF.Next()) {
240 TopoDS_Face Face=TopoDS::Face(ExF.Current());
241 T=BRep_Tool::Tolerance(Face);
248 for(TopExp_Explorer ExE(S,TopAbs_EDGE); ExE.More(); ExE.Next()) {
250 TopoDS_Edge Edge=TopoDS::Edge(ExE.Current());
251 T=BRep_Tool::Tolerance(Edge);
258 for(TopExp_Explorer ExV(S,TopAbs_VERTEX); ExV.More(); ExV.Next()) {
260 TopoDS_Vertex Vertex=TopoDS::Vertex(ExV.Current());
261 T=BRep_Tool::Tolerance(Vertex);
270 GroupC1->LineEdit11->setText(tr("%1").arg(TmF, 5, 'e', 8));
271 GroupC1->LineEdit12->setText(tr("%1").arg(TMF, 5, 'e', 8));
274 GroupC1->LineEdit21->setText(tr("%1").arg(TmE, 5, 'e', 8));
275 GroupC1->LineEdit22->setText(tr("%1").arg(TME, 5, 'e', 8));
278 GroupC1->LineEdit31->setText(tr("%1").arg(TmV, 5, 'e', 8));
279 GroupC1->LineEdit32->setText(tr("%1").arg(TMV, 5, 'e', 8));
282 catch(Standard_Failure)
284 MESSAGE("Catch intercepted in CalculateMaxTolerance()");