Salome HOME
Update copyrights 2014.
[modules/geom.git] / src / MeasureGUI / MeasureGUI_MaxToleranceDlg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : MeasureGUI_MaxToleranceDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
26 //
27 #include "MeasureGUI_MaxToleranceDlg.h"
28 #include "MeasureGUI_Widgets.h"
29 #include "DlgRef.h"
30
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SalomeApp_Tools.h>
34
35 //=================================================================================
36 // class    : MeasureGUI_MaxToleranceDlg()
37 // purpose  : Constructs a MeasureGUI_MaxToleranceDlg which is a child of 'parent', with the
38 //            name 'name' and widget flags set to 'f'.
39 //            The dialog will by default be modeless, unless you set 'modal' to
40 //            true to construct a modal dialog.
41 //=================================================================================
42 MeasureGUI_MaxToleranceDlg::MeasureGUI_MaxToleranceDlg( GeometryGUI* GUI, QWidget* parent )
43   : MeasureGUI_Skeleton( GUI, parent )
44 {
45   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
46     "GEOM", tr( "ICON_DLG_TOLERANCE" ) ) );
47   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
48     "GEOM", tr( "ICON_SELECT" ) ) );
49
50   setWindowTitle( tr( "GEOM_TOLERANCE_TITLE" ) );
51
52   /***************************************************************/
53   
54   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TOLERANCE" ) );
55   mainFrame()->RadioButton1->setIcon( image0 );
56
57   myGrp = new MeasureGUI_1Sel6LineEdit( centralWidget() );
58   myGrp->GroupBox1->setTitle( tr( "GEOM_TOLERANCE_CONSTR" ) );
59   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
60   myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
61   myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
62   myGrp->TextLabel4->setText( tr( "GEOM_TOLERANCE_FACE" ) );
63   myGrp->TextLabel5->setText( tr( "GEOM_TOLERANCE_EDGE" ) );
64   myGrp->TextLabel6->setText( tr( "GEOM_TOLERANCE_VERTEX" ) );
65   myGrp->LineEdit11->setReadOnly( true );
66   myGrp->LineEdit12->setReadOnly( true );
67   myGrp->LineEdit21->setReadOnly( true );
68   myGrp->LineEdit22->setReadOnly( true );
69   myGrp->LineEdit31->setReadOnly( true );
70   myGrp->LineEdit32->setReadOnly( true );
71   myGrp->PushButton1->setIcon( image1 );
72   myGrp->LineEdit1->setReadOnly( true );
73
74   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
75   layout->setMargin( 0 ); layout->setSpacing( 6 );
76   layout->addWidget( myGrp );
77   
78   /***************************************************************/
79
80   myHelpFileName = "using_measurement_tools_page.html#tolerance_anchor";
81   
82   /* Initialisation */
83   Init();
84 }
85
86
87 //=================================================================================
88 // function : ~MeasureGUI_MaxToleranceDlg()
89 // purpose  : Destroys the object and frees any allocated resources
90 //=================================================================================
91 MeasureGUI_MaxToleranceDlg::~MeasureGUI_MaxToleranceDlg()
92 {
93 }
94
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void MeasureGUI_MaxToleranceDlg::Init()
101 {
102   mySelBtn = myGrp->PushButton1;
103   mySelEdit = myGrp->LineEdit1;
104   MeasureGUI_Skeleton::Init();
105 }
106
107 //=================================================================================
108 // function : processObject
109 // purpose  :
110 //=================================================================================
111 void MeasureGUI_MaxToleranceDlg::processObject()
112 {
113   double aMinFaceToler, aMaxFaceToler;
114   double aMinEdgeToler, aMaxEdgeToler;
115   double aMinVertexToler, aMaxVertexToler;
116   
117   if ( !getParameters( aMinFaceToler, aMaxFaceToler,
118                        aMinEdgeToler, aMaxEdgeToler,
119                        aMinVertexToler, aMaxVertexToler ) ) {
120     myGrp->LineEdit11->setText( "" );
121     myGrp->LineEdit12->setText( "" );
122
123     myGrp->LineEdit21->setText( "" );
124     myGrp->LineEdit22->setText( "" );
125
126     myGrp->LineEdit31->setText( "" );
127     myGrp->LineEdit32->setText( "" );
128
129     return;
130   }
131
132   double invalidMin = RealLast();
133   double invalidMax = -RealLast();
134
135   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
136   int aPrecision = resMgr->integerValue( "Geometry", "len_tol_precision", -9);
137
138   myGrp->LineEdit11->setText( aMinFaceToler != invalidMin ? DlgRef::PrintDoubleValue( aMinFaceToler, aPrecision ) : QString("") );
139   myGrp->LineEdit12->setText( aMaxFaceToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxFaceToler, aPrecision ) : QString("") );
140
141   myGrp->LineEdit21->setText( aMinEdgeToler != invalidMin ? DlgRef::PrintDoubleValue( aMinEdgeToler, aPrecision ) : QString("") );
142   myGrp->LineEdit22->setText( aMaxEdgeToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxEdgeToler, aPrecision ) : QString("") );
143
144   myGrp->LineEdit31->setText( aMinVertexToler != invalidMin ? DlgRef::PrintDoubleValue( aMinVertexToler, aPrecision ) : QString("") );
145   myGrp->LineEdit32->setText( aMaxVertexToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxVertexToler, aPrecision ) : QString("") );
146 }
147
148 //=================================================================================
149 // function : getParameters
150 // purpose  : Get tolerances. Returns false is myObj is nill. If there is no a
151 //            type of entity ( face, edge or vertex ) in selected object then corresponding
152 //            tolerances is less than 0
153 //=================================================================================
154 bool MeasureGUI_MaxToleranceDlg::getParameters( double& theMinFaceToler,
155                                                 double& theMaxFaceToler,
156                                                 double& theMinEdgeToler,
157                                                 double& theMaxEdgeToler,
158                                                 double& theMinVertexToler,
159                                                 double& theMaxVertexToler )
160 {
161   if ( myObj->_is_nil() )
162     return false;
163   else {
164     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
165     try {
166       anOper->GetTolerance( myObj, 
167                             theMinFaceToler, theMaxFaceToler,   theMinEdgeToler,
168                             theMaxEdgeToler, theMinVertexToler, theMaxVertexToler );
169     }
170     catch( const SALOME::SALOME_Exception& e ) {
171       SalomeApp_Tools::QtCatchCorbaException( e );
172       return false;
173     }
174
175     return anOper->IsDone();
176   }
177 }