Salome HOME
6bdf007aef371fe94c86afe671257fd9417f18ee
[modules/geom.git] / src / MeasureGUI / MeasureGUI_MaxToleranceDlg.cxx
1 // Copyright (C) 2007-2023  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 <GEOMBase.h>
30 #include "DlgRef.h"
31
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Tools.h>
35
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 )
45 {
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" ) ) );
50
51   setWindowTitle( tr( "GEOM_TOLERANCE_TITLE" ) );
52
53   /***************************************************************/
54   
55   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_TOLERANCE" ) );
56   mainFrame()->RadioButton1->setIcon( image0 );
57
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 );
74
75   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76   layout->setMargin( 0 ); layout->setSpacing( 6 );
77   layout->addWidget( myGrp );
78   
79   /***************************************************************/
80
81   myHelpFileName = "tolerance_page.html";
82   
83   /* Initialisation */
84   Init();
85 }
86
87
88 //=================================================================================
89 // function : ~MeasureGUI_MaxToleranceDlg()
90 // purpose  : Destroys the object and frees any allocated resources
91 //=================================================================================
92 MeasureGUI_MaxToleranceDlg::~MeasureGUI_MaxToleranceDlg()
93 {
94 }
95
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void MeasureGUI_MaxToleranceDlg::Init()
102 {
103   mySelBtn = myGrp->PushButton1;
104   mySelEdit = myGrp->LineEdit1;
105   MeasureGUI_Skeleton::Init();
106 }
107
108 //=================================================================================
109 // function : processObject
110 // purpose  :
111 //=================================================================================
112 void MeasureGUI_MaxToleranceDlg::processObject()
113 {
114   double aMinFaceToler, aMaxFaceToler;
115   double aMinEdgeToler, aMaxEdgeToler;
116   double aMinVertexToler, aMaxVertexToler;
117   
118   if ( !getParameters( aMinFaceToler, aMaxFaceToler,
119                        aMinEdgeToler, aMaxEdgeToler,
120                        aMinVertexToler, aMaxVertexToler ) ) {
121     myGrp->LineEdit11->setText( "" );
122     myGrp->LineEdit12->setText( "" );
123
124     myGrp->LineEdit21->setText( "" );
125     myGrp->LineEdit22->setText( "" );
126
127     myGrp->LineEdit31->setText( "" );
128     myGrp->LineEdit32->setText( "" );
129
130     return;
131   }
132
133   double invalidMin = RealLast();
134   double invalidMax = -RealLast();
135
136   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
137   int aPrecision = resMgr->integerValue( "Geometry", "len_tol_precision", -9);
138
139   myGrp->LineEdit11->setText( aMinFaceToler != invalidMin ? DlgRef::PrintDoubleValue( aMinFaceToler, aPrecision ) : QString("") );
140   myGrp->LineEdit12->setText( aMaxFaceToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxFaceToler, aPrecision ) : QString("") );
141
142   myGrp->LineEdit21->setText( aMinEdgeToler != invalidMin ? DlgRef::PrintDoubleValue( aMinEdgeToler, aPrecision ) : QString("") );
143   myGrp->LineEdit22->setText( aMaxEdgeToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxEdgeToler, aPrecision ) : QString("") );
144
145   myGrp->LineEdit31->setText( aMinVertexToler != invalidMin ? DlgRef::PrintDoubleValue( aMinVertexToler, aPrecision ) : QString("") );
146   myGrp->LineEdit32->setText( aMaxVertexToler != invalidMax ? DlgRef::PrintDoubleValue( aMaxVertexToler, aPrecision ) : QString("") );
147 }
148
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 )
161 {
162   if ( myObj->_is_nil() )
163     return false;
164   else {
165     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
166     try {
167       anOper->GetTolerance( myObj.get(), 
168                             theMinFaceToler, theMaxFaceToler,   theMinEdgeToler,
169                             theMaxEdgeToler, theMinVertexToler, theMaxVertexToler );
170     }
171     catch( const SALOME::SALOME_Exception& e ) {
172       SalomeApp_Tools::QtCatchCorbaException( e );
173       return false;
174     }
175
176     return anOper->IsDone();
177   }
178 }
179
180 //=================================================================================
181 // function : activateSelection()
182 // purpose  :
183 //=================================================================================
184 void MeasureGUI_MaxToleranceDlg::activateSelection()
185 {
186   globalSelection( GEOM_ALLSHAPES );
187   localSelection( TopAbs_SHAPE );
188 }
189
190 void MeasureGUI_MaxToleranceDlg::SelectionIntoArgument()
191 {
192   myObj.nullify();
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 );
196  
197   if (!myObj) {
198     mySelEdit->setText("");
199     processObject();
200     erasePreview();
201     return;
202   }
203
204   mySelEdit->setText(GEOMBase::GetName(myObj.get()));
205   processObject();
206   redisplayPreview();
207 }