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