1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_MaxToleranceDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "MeasureGUI_MaxToleranceDlg.h"
28 #include "MeasureGUI_Widgets.h"
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Tools.h>
36 //=================================================================================
37 // class : MeasureGUI_MaxToleranceDlg()
38 // purpose : Constructs a MeasureGUI_MaxToleranceDlg which is a child of 'parent', with the
39 // name 'name' and widget flags set to 'f'.
40 // The dialog will by default be modeless, unless you set 'modal' to
41 // true to construct a modal dialog.
42 //=================================================================================
43 MeasureGUI_MaxToleranceDlg::MeasureGUI_MaxToleranceDlg( GeometryGUI* GUI, QWidget* parent )
44 : MeasureGUI_Skeleton( GUI, parent )
46 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
47 "GEOM", tr( "ICON_DLG_TOLERANCE" ) ) );
48 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
49 "GEOM", tr( "ICON_SELECT" ) ) );
51 setWindowTitle( tr( "GEOM_TOLERANCE_TITLE" ) );
53 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TOLERANCE" ) );
56 mainFrame()->RadioButton1->setIcon( image0 );
58 myGrp = new MeasureGUI_1Sel6LineEdit( centralWidget() );
59 myGrp->GroupBox1->setTitle( tr( "GEOM_TOLERANCE_CONSTR" ) );
60 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
61 myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
62 myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
63 myGrp->TextLabel4->setText( tr( "GEOM_TOLERANCE_FACE" ) );
64 myGrp->TextLabel5->setText( tr( "GEOM_TOLERANCE_EDGE" ) );
65 myGrp->TextLabel6->setText( tr( "GEOM_TOLERANCE_VERTEX" ) );
66 myGrp->LineEdit11->setReadOnly( true );
67 myGrp->LineEdit12->setReadOnly( true );
68 myGrp->LineEdit21->setReadOnly( true );
69 myGrp->LineEdit22->setReadOnly( true );
70 myGrp->LineEdit31->setReadOnly( true );
71 myGrp->LineEdit32->setReadOnly( true );
72 myGrp->PushButton1->setIcon( image1 );
73 myGrp->LineEdit1->setReadOnly( true );
75 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76 layout->setMargin( 0 ); layout->setSpacing( 6 );
77 layout->addWidget( myGrp );
79 /***************************************************************/
81 myHelpFileName = "tolerance_page.html";
88 //=================================================================================
89 // function : ~MeasureGUI_MaxToleranceDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 MeasureGUI_MaxToleranceDlg::~MeasureGUI_MaxToleranceDlg()
97 //=================================================================================
100 //=================================================================================
101 void MeasureGUI_MaxToleranceDlg::Init()
103 mySelBtn = myGrp->PushButton1;
104 mySelEdit = myGrp->LineEdit1;
105 MeasureGUI_Skeleton::Init();
108 //=================================================================================
109 // function : processObject
111 //=================================================================================
112 void MeasureGUI_MaxToleranceDlg::processObject()
114 double aMinFaceToler, aMaxFaceToler;
115 double aMinEdgeToler, aMaxEdgeToler;
116 double aMinVertexToler, aMaxVertexToler;
118 if ( !getParameters( aMinFaceToler, aMaxFaceToler,
119 aMinEdgeToler, aMaxEdgeToler,
120 aMinVertexToler, aMaxVertexToler ) ) {
121 myGrp->LineEdit11->setText( "" );
122 myGrp->LineEdit12->setText( "" );
124 myGrp->LineEdit21->setText( "" );
125 myGrp->LineEdit22->setText( "" );
127 myGrp->LineEdit31->setText( "" );
128 myGrp->LineEdit32->setText( "" );
133 double invalidMin = RealLast();
134 double invalidMax = -RealLast();
136 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
137 int aPrecision = resMgr->integerValue( "Geometry", "len_tol_precision", -9);
139 myGrp->LineEdit11->setText( aMinFaceToler != invalidMin ? DlgRef::PrintDoubleValue( aMinFaceToler, aPrecision ) : QString("") );
140 myGrp->LineEdit12->setText( aMaxFaceToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxFaceToler, aPrecision ) : QString("") );
142 myGrp->LineEdit21->setText( aMinEdgeToler != invalidMin ? DlgRef::PrintDoubleValue( aMinEdgeToler, aPrecision ) : QString("") );
143 myGrp->LineEdit22->setText( aMaxEdgeToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxEdgeToler, aPrecision ) : QString("") );
145 myGrp->LineEdit31->setText( aMinVertexToler != invalidMin ? DlgRef::PrintDoubleValue( aMinVertexToler, aPrecision ) : QString("") );
146 myGrp->LineEdit32->setText( aMaxVertexToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxVertexToler, aPrecision ) : QString("") );
149 //=================================================================================
150 // function : getParameters
151 // purpose : Get tolerances. Returns false is myObj is nill. If there is no a
152 // type of entity ( face, edge or vertex ) in selected object then corresponding
153 // tolerances is less than 0
154 //=================================================================================
155 bool MeasureGUI_MaxToleranceDlg::getParameters( double& theMinFaceToler,
156 double& theMaxFaceToler,
157 double& theMinEdgeToler,
158 double& theMaxEdgeToler,
159 double& theMinVertexToler,
160 double& theMaxVertexToler )
162 if ( myObj->_is_nil() )
165 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
167 anOper->GetTolerance( myObj.get(),
168 theMinFaceToler, theMaxFaceToler, theMinEdgeToler,
169 theMaxEdgeToler, theMinVertexToler, theMaxVertexToler );
171 catch( const SALOME::SALOME_Exception& e ) {
172 SalomeApp_Tools::QtCatchCorbaException( e );
176 return anOper->IsDone();
180 //=================================================================================
181 // function : activateSelection()
183 //=================================================================================
184 void MeasureGUI_MaxToleranceDlg::activateSelection()
186 globalSelection( GEOM_ALLSHAPES );
187 localSelection( TopAbs_SHAPE );
190 void MeasureGUI_MaxToleranceDlg::SelectionIntoArgument()
193 QList<TopAbs_ShapeEnum> aTypes;
194 aTypes << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPSOLID << TopAbs_COMPOUND << TopAbs_SHAPE;
195 myObj = getSelected( aTypes );
198 mySelEdit->setText("");
204 mySelEdit->setText(GEOMBase::GetName(myObj.get()));