0023272: [CEA] Add a tolerance for basic properties computation

This commit is contained in:
skv 2016-10-18 19:54:53 +03:00
parent afce74184a
commit 2c66cf4f4a
10 changed files with 117 additions and 33 deletions

BIN
doc/salome/gui/GEOM/images/neo-basicprop.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -15,8 +15,9 @@ in the viewer to navigate between selectable objects.
For more details, please refer to the \em "Functionality common for OCC and VTK viewers" chapter
of the GUI module's documentation.
<b>TUI Command:</b> <em>geompy.BasicProperties(Shape),</em> where
\em Shape is a shape whose properties are inquired.
<b>TUI Command:</b> <em>geompy.BasicProperties(Shape, theTolerance=1.e-6),</em>
where \em Shape is a shape whose properties are inquired, \em theTolerance is
maximal relative error of area and volume computation.
See also a \ref tui_basic_properties_page "TUI example".

View File

@ -4337,12 +4337,14 @@ module GEOM
* \brief Get summarized length of all wires,
* area of surface and volume of the given shape.
* \param theShape Shape to define properties of.
* \param theTolerance maximal relative error of area and volume computation.
* \param theLength Output. Summarized length of all wires of the given shape.
* \param theSurfArea Output. Area of surface of the given shape.
* \param theVolume Output. Volume of the given shape.
* \return Returns shape properties through the last three arguments.
*/
void GetBasicProperties (in GEOM_Object theShape,
in double theTolerance,
out double theLength,
out double theSurfArea,
out double theVolume);

View File

@ -965,6 +965,7 @@ Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
*/
//=============================================================================
void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
const Standard_Real theTolerance,
Standard_Real& theLength,
Standard_Real& theSurfArea,
Standard_Real& theVolume)
@ -984,7 +985,7 @@ void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theSha
//Compute the parameters
GProp_GProps LProps, SProps;
Standard_Real anEps = 1.e-6;
Standard_Real anEps = theTolerance >= 0 ? theTolerance : 1.e-6;
try {
OCC_CATCH_SIGNALS;
BRepGProp::LinearProperties(aShape, LProps);

View File

@ -119,6 +119,7 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations {
Handle(GEOM_Object) theOptionalPoint);
Standard_EXPORT void GetBasicProperties (Handle(GEOM_Object) theShape,
const Standard_Real theTolerance,
Standard_Real& theLength,
Standard_Real& theSurfArea,
Standard_Real& theVolume);

View File

@ -495,6 +495,7 @@ GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
*/
//=============================================================================
void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
CORBA::Double theTolerance,
CORBA::Double& theLength,
CORBA::Double& theSurfArea,
CORBA::Double& theVolume)
@ -507,7 +508,8 @@ void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theSha
if (aShape.IsNull()) return;
// Get shape parameters
GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
GetOperations()->GetBasicProperties(aShape, theTolerance, theLength,
theSurfArea, theVolume);
}
//=============================================================================

View File

@ -52,6 +52,7 @@ class GEOM_I_EXPORT GEOM_IMeasureOperations_i :
CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz);
void GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
CORBA::Double theTolerance,
CORBA::Double& theLength,
CORBA::Double& theSurfArea,
CORBA::Double& theVolume);

View File

@ -10579,6 +10579,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
## Get summarized length of all wires,
# area of surface and volume of the given shape.
# @param theShape Shape to define properties of.
# @param theTolerance maximal relative error of area
# and volume computation.
# @return [theLength, theSurfArea, theVolume]\n
# theLength: Summarized length of all wires of the given shape.\n
# theSurfArea: Area of surface of the given shape.\n
@ -10586,13 +10588,15 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
#
# @ref tui_basic_properties_page "Example"
@ManageTransactions("MeasuOp")
def BasicProperties(self,theShape):
def BasicProperties(self,theShape, theTolerance=1.e-6):
"""
Get summarized length of all wires,
area of surface and volume of the given shape.
Parameters:
theShape Shape to define properties of.
theTolerance maximal relative error of area
and volume computation.
Returns:
[theLength, theSurfArea, theVolume]
@ -10601,7 +10605,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
theVolume: Volume of the given shape.
"""
# Example: see GEOM_TestMeasures.py
aTuple = self.MeasuOp.GetBasicProperties(theShape)
aTuple = self.MeasuOp.GetBasicProperties(theShape, theTolerance)
RaiseIfFailed("GetBasicProperties", self.MeasuOp)
return aTuple

View File

@ -37,6 +37,8 @@
#include <TColStd_MapOfInteger.hxx>
#define DEFAULT_TOLERANCE_VALUE 1.e-6
//=================================================================================
// class : MeasureGUI_PropertiesDlg()
// purpose : Constructs a MeasureGUI_PropertiesDlg which is a child of 'parent', with the
@ -45,7 +47,11 @@
// true to construct a modal dialog.
//=================================================================================
MeasureGUI_PropertiesDlg::MeasureGUI_PropertiesDlg( GeometryGUI* GUI, QWidget* parent )
: MeasureGUI_Skeleton( GUI, parent )
: MeasureGUI_Skeleton(GUI, parent),
myTolerance(0),
myLength(0),
mySurface(0),
myVolume(0)
{
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
"GEOM", tr( "ICON_DLG_BASICPROPERTIES" ) ) );
@ -59,21 +65,45 @@ MeasureGUI_PropertiesDlg::MeasureGUI_PropertiesDlg( GeometryGUI* GUI, QWidget* p
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PROPERTIES" ) );
mainFrame()->RadioButton1->setIcon( image0 );
myGrp = new MeasureGUI_1Sel3LineEdit( centralWidget() );
myGrp->GroupBox1->setTitle( tr( "GEOM_PROPERTIES_CONSTR" ) );
myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
myGrp->TextLabel2->setText( tr( "GEOM_LENGTH" ) );
myGrp->TextLabel3->setText( tr( "GEOM_PROPERTIES_SURFACE" ) );
myGrp->TextLabel4->setText( tr( "GEOM_PROPERTIES_VOLUME" ) );
myGrp->LineEdit1->setReadOnly( true );
myGrp->PushButton1->setIcon( image1 );
myGrp->LineEdit2->setReadOnly( true );
myGrp->LineEdit3->setReadOnly( true );
myGrp->LineEdit4->setReadOnly( true );
QGroupBox *aGrpBox =
new QGroupBox(tr("GEOM_PROPERTIES_CONSTR"), centralWidget());
QLabel *anObjLbl = new QLabel(tr("GEOM_OBJECT"), aGrpBox);
QLabel *aTolLbl = new QLabel(tr("GEOM_TOLERANCE"), aGrpBox);
QLabel *aLenLbl = new QLabel(tr("GEOM_LENGTH"), aGrpBox);
QLabel *aSurfLbl = new QLabel(tr("GEOM_PROPERTIES_SURFACE"), aGrpBox);
QLabel *aVolLbl = new QLabel(tr("GEOM_PROPERTIES_VOLUME"), aGrpBox);
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( myGrp );
mySelBtn = new QPushButton(aGrpBox);
mySelBtn->setIcon(image1);
mySelEdit = new QLineEdit(aGrpBox);
mySelEdit->setReadOnly(true);
myTolerance = new SalomeApp_DoubleSpinBox(aGrpBox);
myLength = new QLineEdit(aGrpBox);
mySurface = new QLineEdit(aGrpBox);
myVolume = new QLineEdit(aGrpBox);
myLength->setReadOnly(true);
mySurface->setReadOnly(true);
myVolume->setReadOnly(true);
QGridLayout* aLayout = new QGridLayout(aGrpBox);
aLayout->setMargin(9);
aLayout->setSpacing(6);
aLayout->addWidget(anObjLbl, 0, 0);
aLayout->addWidget(aTolLbl, 1, 0);
aLayout->addWidget(aLenLbl, 2, 0);
aLayout->addWidget(aSurfLbl, 3, 0);
aLayout->addWidget(aVolLbl, 4, 0);
aLayout->addWidget(mySelBtn, 0, 1);
aLayout->addWidget(mySelEdit, 0, 2);
aLayout->addWidget(myTolerance, 1, 1, 1, 2);
aLayout->addWidget(myLength, 2, 1, 1, 2);
aLayout->addWidget(mySurface, 3, 1, 1, 2);
aLayout->addWidget(myVolume, 4, 1, 1, 2);
QVBoxLayout* aDlgLayout = new QVBoxLayout( centralWidget() );
aDlgLayout->setMargin( 0 ); aDlgLayout->setSpacing( 6 );
aDlgLayout->addWidget(aGrpBox);
/***************************************************************/
@ -99,9 +129,24 @@ MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
//=================================================================================
void MeasureGUI_PropertiesDlg::Init()
{
mySelBtn = myGrp->PushButton1;
mySelEdit = myGrp->LineEdit1;
mySelEdit->setMinimumSize(100, 0);
// Obtain precision from preferences
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
myTolerance->setPrecision(aPrecision);
// it's necessary to set decimals before the range setting,
// by default Qt rounds boundaries to 2 decimals at setRange
myTolerance->setDecimals(qAbs(aPrecision));
myTolerance->setRange(0., 1.);
myTolerance->setSingleStep(DEFAULT_TOLERANCE_VALUE);
myTolerance->setValue(DEFAULT_TOLERANCE_VALUE);
MeasureGUI_Skeleton::Init();
connect(myTolerance, SIGNAL(valueChanged(double)),
this, SLOT(toleranceChanged(double)));
}
//=================================================================================
@ -146,6 +191,16 @@ void MeasureGUI_PropertiesDlg::SelectionIntoArgument()
processObject();
redisplayPreview();
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool MeasureGUI_PropertiesDlg::isValid(QString& msg)
{
return myTolerance->isValid(msg) && MeasureGUI_Skeleton::isValid(msg);
}
//=================================================================================
// function : processObject
// purpose :
@ -156,16 +211,16 @@ void MeasureGUI_PropertiesDlg::processObject()
if ( !getParameters( aLength, anArea, aVolume ) ) {
mySelEdit->setText( "" );
myGrp->LineEdit2->setText( "" );
myGrp->LineEdit3->setText( "" );
myGrp->LineEdit4->setText( "" );
myLength->setText( "" );
mySurface->setText( "" );
myVolume->setText( "" );
}
else {
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
myGrp->LineEdit2->setText( DlgRef::PrintDoubleValue( aLength, aPrecision ) );
myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( anArea, aPrecision ) );
myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aVolume, aPrecision ) );
myLength->setText( DlgRef::PrintDoubleValue( aLength, aPrecision ) );
mySurface->setText( DlgRef::PrintDoubleValue( anArea, aPrecision ) );
myVolume->setText( DlgRef::PrintDoubleValue( aVolume, aPrecision ) );
}
}
@ -182,7 +237,7 @@ bool MeasureGUI_PropertiesDlg::getParameters( double& theLength,
else {
GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
try {
anOper->GetBasicProperties( myObj.get(), theLength, theArea, theVolume );
anOper->GetBasicProperties( myObj.get(), myTolerance->value(), theLength, theArea, theVolume );
}
catch( const SALOME::SALOME_Exception& e ) {
SalomeApp_Tools::QtCatchCorbaException( e );
@ -210,3 +265,12 @@ SALOME_Prs* MeasureGUI_PropertiesDlg::buildPrs()
}
return prs;
}
//=================================================================================
// function : toleranceChanged
// purpose :
//=================================================================================
void MeasureGUI_PropertiesDlg::toleranceChanged(double)
{
processObject();
}

View File

@ -29,7 +29,8 @@
#include "MeasureGUI_Skeleton.h"
class MeasureGUI_1Sel3LineEdit;
class SalomeApp_DoubleSpinBox;
class QLineEdit;
//=================================================================================
// class : MeasureGUI_PropertiesDlg
@ -46,6 +47,7 @@ public:
protected:
// redefined from GEOMBase_Helper and MeasureGUI_Skeleton
virtual bool isValid( QString& );
virtual void processObject();
virtual void activateSelection();
virtual void SelectionIntoArgument();
@ -57,8 +59,14 @@ private:
double&,
double& );
private:
MeasureGUI_1Sel3LineEdit* myGrp;
private:
SalomeApp_DoubleSpinBox *myTolerance;
QLineEdit *myLength;
QLineEdit *mySurface;
QLineEdit *myVolume;
private slots:
void toleranceChanged(double);
};
#endif // MEASUREGUI_PROPERTIESDLG_H