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_PropertiesDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "MeasureGUI_PropertiesDlg.h"
28 #include "MeasureGUI_Widgets.h"
30 #include <GEOMImpl_Types.hxx>
34 #include <SalomeApp_Tools.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
38 #include <TColStd_MapOfInteger.hxx>
40 #define DEFAULT_TOLERANCE_VALUE 1.e-6
42 //=================================================================================
43 // class : MeasureGUI_PropertiesDlg()
44 // purpose : Constructs a MeasureGUI_PropertiesDlg 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_PropertiesDlg::MeasureGUI_PropertiesDlg( GeometryGUI* GUI, QWidget* parent )
50 : MeasureGUI_Skeleton(GUI, parent),
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
57 "GEOM", tr( "ICON_DLG_BASICPROPERTIES" ) ) );
58 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
59 "GEOM", tr( "ICON_SELECT" ) ) );
61 setWindowTitle( tr( "GEOM_PROPERTIES_TITLE" ) );
63 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PROPERTIES" ) );
66 mainFrame()->RadioButton1->setIcon( image0 );
69 new QGroupBox(tr("GEOM_PROPERTIES_CONSTR"), centralWidget());
70 QLabel *anObjLbl = new QLabel(tr("GEOM_OBJECT"), aGrpBox);
71 QLabel *aTolLbl = new QLabel(tr("GEOM_TOLERANCE"), aGrpBox);
72 QLabel *aLenLbl = new QLabel(tr("GEOM_LENGTH"), aGrpBox);
73 QLabel *aSurfLbl = new QLabel(tr("GEOM_PROPERTIES_SURFACE"), aGrpBox);
74 QLabel *aVolLbl = new QLabel(tr("GEOM_PROPERTIES_VOLUME"), aGrpBox);
76 mySelBtn = new QPushButton(aGrpBox);
77 mySelBtn->setIcon(image1);
78 mySelEdit = new QLineEdit(aGrpBox);
79 mySelEdit->setReadOnly(true);
80 myTolerance = new SalomeApp_DoubleSpinBox(aGrpBox);
81 myLength = new QLineEdit(aGrpBox);
82 mySurface = new QLineEdit(aGrpBox);
83 myVolume = new QLineEdit(aGrpBox);
84 myLength->setReadOnly(true);
85 mySurface->setReadOnly(true);
86 myVolume->setReadOnly(true);
88 QGridLayout* aLayout = new QGridLayout(aGrpBox);
90 aLayout->setMargin(9);
91 aLayout->setSpacing(6);
92 aLayout->addWidget(anObjLbl, 0, 0);
93 aLayout->addWidget(aTolLbl, 1, 0);
94 aLayout->addWidget(aLenLbl, 2, 0);
95 aLayout->addWidget(aSurfLbl, 3, 0);
96 aLayout->addWidget(aVolLbl, 4, 0);
97 aLayout->addWidget(mySelBtn, 0, 1);
98 aLayout->addWidget(mySelEdit, 0, 2);
99 aLayout->addWidget(myTolerance, 1, 1, 1, 2);
100 aLayout->addWidget(myLength, 2, 1, 1, 2);
101 aLayout->addWidget(mySurface, 3, 1, 1, 2);
102 aLayout->addWidget(myVolume, 4, 1, 1, 2);
104 QVBoxLayout* aDlgLayout = new QVBoxLayout( centralWidget() );
105 aDlgLayout->setMargin( 0 ); aDlgLayout->setSpacing( 6 );
106 aDlgLayout->addWidget(aGrpBox);
108 /***************************************************************/
110 myHelpFileName = "basic_prop_page.html";
117 //=================================================================================
118 // function : ~MeasureGUI_PropertiesDlg()
119 // purpose : Destroys the object and frees any allocated resources
120 //=================================================================================
121 MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
126 //=================================================================================
129 //=================================================================================
130 void MeasureGUI_PropertiesDlg::Init()
132 mySelEdit->setMinimumSize(100, 0);
134 // Obtain precision from preferences
135 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
136 int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
138 myTolerance->setPrecision(aPrecision);
139 // it's necessary to set decimals before the range setting,
140 // by default Qt rounds boundaries to 2 decimals at setRange
141 myTolerance->setDecimals(qAbs(aPrecision));
142 myTolerance->setRange(0., 1.);
143 myTolerance->setSingleStep(DEFAULT_TOLERANCE_VALUE);
144 myTolerance->setValue(DEFAULT_TOLERANCE_VALUE);
146 MeasureGUI_Skeleton::Init();
148 connect(myTolerance, SIGNAL(valueChanged(double)),
149 this, SLOT(toleranceChanged(double)));
152 //=================================================================================
153 // function : activateSelection
155 //=================================================================================
156 void MeasureGUI_PropertiesDlg::activateSelection()
158 static TColStd_MapOfInteger aTypes;
159 if ( aTypes.IsEmpty() ) {
160 aTypes.Add( GEOM_COMPOUND );
161 // aTypes.Add( TopAbs_COMPSOLID );
162 aTypes.Add( GEOM_SOLID );
163 aTypes.Add( GEOM_SHELL );
164 aTypes.Add( GEOM_FACE );
165 aTypes.Add( GEOM_WIRE );
166 aTypes.Add( GEOM_EDGE );
169 globalSelection( aTypes );
171 std::list<int> needTypes;
172 needTypes.push_back( TopAbs_EDGE ), needTypes.push_back( TopAbs_WIRE ), needTypes.push_back( TopAbs_FACE ), needTypes.push_back( TopAbs_SHELL ), needTypes.push_back( TopAbs_SOLID ), needTypes.push_back( TopAbs_COMPOUND );
173 localSelection( needTypes );
176 void MeasureGUI_PropertiesDlg::SelectionIntoArgument()
179 QList<TopAbs_ShapeEnum> aTypes;
180 aTypes << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPOUND;
181 myObj = getSelected( aTypes );
184 mySelEdit->setText("");
190 mySelEdit->setText(GEOMBase::GetName(myObj.get()));
195 //=================================================================================
196 // function : isValid
198 //=================================================================================
199 bool MeasureGUI_PropertiesDlg::isValid(QString& msg)
201 return myTolerance->isValid(msg) && MeasureGUI_Skeleton::isValid(msg);
204 //=================================================================================
205 // function : processObject
207 //=================================================================================
208 void MeasureGUI_PropertiesDlg::processObject()
210 double aLength, anArea, aVolume;
212 if ( !getParameters( aLength, anArea, aVolume ) ) {
213 mySelEdit->setText( "" );
214 myLength->setText( "" );
215 mySurface->setText( "" );
216 myVolume->setText( "" );
219 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
220 int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
221 myLength->setText( DlgRef::PrintDoubleValue( aLength, aPrecision ) );
222 mySurface->setText( DlgRef::PrintDoubleValue( anArea, aPrecision ) );
223 myVolume->setText( DlgRef::PrintDoubleValue( aVolume, aPrecision ) );
227 //=================================================================================
228 // function : getParameters
230 //=================================================================================
231 bool MeasureGUI_PropertiesDlg::getParameters( double& theLength,
238 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
240 anOper->GetBasicProperties( myObj.get(), myTolerance->value(), theLength, theArea, theVolume );
242 catch( const SALOME::SALOME_Exception& e ) {
243 SalomeApp_Tools::QtCatchCorbaException( e );
247 return anOper->IsDone();
251 //=================================================================================
252 // function : createOperation
254 //=================================================================================
255 SALOME_Prs* MeasureGUI_PropertiesDlg::buildPrs()
260 if ( GEOMBase::GetShape( myObj.get(), shape, TopAbs_EDGE ) &&
261 getDisplayer()->IsDisplayed( GEOMBase::GetEntry(myObj.get()) ) ) {
262 shape = GEOMBase::CreateArrowForLinearEdge( shape );
263 if ( !shape.IsNull() )
264 prs = getDisplayer()->BuildPrs( shape );
269 //=================================================================================
270 // function : toleranceChanged
272 //=================================================================================
273 void MeasureGUI_PropertiesDlg::toleranceChanged(double)