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