From: vsr Date: Thu, 8 Aug 2013 15:17:00 +0000 (+0000) Subject: 0021920: [CEA 689] Get some measure functions on groups available in GUI and TUI X-Git-Tag: V7_3_0a1~208 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=fa3a593199ed2de967bebf43bd0a48858cbbd578 0021920: [CEA 689] Get some measure functions on groups available in GUI and TUI --- diff --git a/doc/salome/examples/Makefile.am b/doc/salome/examples/Makefile.am index 94c233a75..1846b16a2 100644 --- a/doc/salome/examples/Makefile.am +++ b/doc/salome/examples/Makefile.am @@ -110,6 +110,7 @@ GOOD_TESTS = \ grouping_elements_ex08.py \ measurements_ex01.py \ measurements_ex02.py \ + measurements_ex03.py \ modifying_meshes_ex01.py \ modifying_meshes_ex02.py \ modifying_meshes_ex03.py \ diff --git a/doc/salome/examples/measurements_ex03.py b/doc/salome/examples/measurements_ex03.py new file mode 100644 index 000000000..ef15e7e25 --- /dev/null +++ b/doc/salome/examples/measurements_ex03.py @@ -0,0 +1,34 @@ +# Basic Properties + + +import salome +salome.salome_init() +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) +import salome_notebook + +from SMESH_mechanic import mesh as mesh1 + +mesh1.Compute() + +# compute length for mesh1 +length = mesh1.GetLength() + +# compute area for mesh1 +area = mesh1.GetArea() + +# compute volume for mesh1 +volume = mesh1.GetVolume() + +# print basic properties +print +print "Basic Properties for mesh:" +print "* length =", length +print "* area =", area +print "* volume =", volume +print diff --git a/doc/salome/gui/SMESH/images/basic_props.png b/doc/salome/gui/SMESH/images/basic_props.png new file mode 100644 index 000000000..bba200d09 Binary files /dev/null and b/doc/salome/gui/SMESH/images/basic_props.png differ diff --git a/doc/salome/gui/SMESH/images/bnd_box.png b/doc/salome/gui/SMESH/images/bnd_box.png index 6761a76ff..d079eaaa4 100644 Binary files a/doc/salome/gui/SMESH/images/bnd_box.png and b/doc/salome/gui/SMESH/images/bnd_box.png differ diff --git a/doc/salome/gui/SMESH/images/min_distance.png b/doc/salome/gui/SMESH/images/min_distance.png index 765522e88..486dab376 100644 Binary files a/doc/salome/gui/SMESH/images/min_distance.png and b/doc/salome/gui/SMESH/images/min_distance.png differ diff --git a/doc/salome/gui/SMESH/input/measurements.doc b/doc/salome/gui/SMESH/input/measurements.doc index 6514cf287..0787b7c20 100644 --- a/doc/salome/gui/SMESH/input/measurements.doc +++ b/doc/salome/gui/SMESH/input/measurements.doc @@ -64,6 +64,32 @@ viewer. \image html bnd_box_preview.png +\section basic_properties_anchor Basic Properties + +This operation allows calculation of length, area or volume for the the selected +object: +- Length is calculated as a sum of length of all 1D elements; +- Area id a sum of area of all 2D elements +- Volume is a sum of volume of all 3D elements. + +To start one of Basic Properties calculations, select Length, Area +or Volume item from Measurements - Basic Properties menu. + +\image html basic_props.png + +In the dialog box select the required type of calculation (length, area or volume), select +the the object (mesh, sub-mesh or group) and press \em Compute button. + +The result of calculation will be shown in the bottom area of the +dialog box. + +\note +- If mesh consists of 3D elements only, its "length" and "area" will be 0. +- As calculation result is a sum of length, area and volume of all mesh elements, + duplications are not taken into account; i.e. all duplicated elements + (elements built on the same set of nodes) will be included into the result. +- Similarly, intersection of elements is not taken into account. + See Also a sample TUI Script of a \ref tui_measurements_page "Measurement operations". diff --git a/doc/salome/gui/SMESH/input/tui_measurements.doc b/doc/salome/gui/SMESH/input/tui_measurements.doc index 4d25c7358..950cc2aba 100644 --- a/doc/salome/gui/SMESH/input/tui_measurements.doc +++ b/doc/salome/gui/SMESH/input/tui_measurements.doc @@ -8,4 +8,7 @@ \section tui_bounding_box Bounding Box \tui_script{measurements_ex02.py} +\section tui_bounding_box Basic Properties +\tui_script{measurements_ex03.py} + */ diff --git a/idl/SMESH_Measurements.idl b/idl/SMESH_Measurements.idl index becc67547..43e5bf2bc 100644 --- a/idl/SMESH_Measurements.idl +++ b/idl/SMESH_Measurements.idl @@ -55,6 +55,21 @@ module SMESH * common bounding box of entities */ Measure BoundingBox(in ListOfIDSources sources); + + /*! + * sum of length of 1D elements of the source + */ + double Length(in SMESH_IDSource source); + + /*! + * sum of area of 2D elements of the source + */ + double Area(in SMESH_IDSource source); + + /*! + * sum of volume of 3D elements of the source + */ + double Volume(in SMESH_IDSource source); }; }; diff --git a/resources/Makefile.am b/resources/Makefile.am index 7a057d202..786c3cd48 100644 --- a/resources/Makefile.am +++ b/resources/Makefile.am @@ -208,7 +208,11 @@ dist_salomeres_DATA = \ mesh_min_dist.png \ reorient_faces_point.png \ reorient_faces_face.png \ - mesh_ball.png + mesh_ball.png \ + mesh_measure_basic_props.png \ + mesh_measure_length.png \ + mesh_measure_area.png \ + mesh_measure_volume.png # VSR: little trick to avoid putting if SMESHCatalog.xml to the distribution archive nodist_salomeres_SCRIPTS = SMESHCatalog.xml SalomeApp.xml diff --git a/resources/mesh_measure_area.png b/resources/mesh_measure_area.png new file mode 100644 index 000000000..72d292be9 Binary files /dev/null and b/resources/mesh_measure_area.png differ diff --git a/resources/mesh_measure_basic_props.png b/resources/mesh_measure_basic_props.png new file mode 100644 index 000000000..4d7ed1378 Binary files /dev/null and b/resources/mesh_measure_basic_props.png differ diff --git a/resources/mesh_measure_length.png b/resources/mesh_measure_length.png new file mode 100644 index 000000000..996f7c311 Binary files /dev/null and b/resources/mesh_measure_length.png differ diff --git a/resources/mesh_measure_volume.png b/resources/mesh_measure_volume.png new file mode 100644 index 000000000..7e4ae014d Binary files /dev/null and b/resources/mesh_measure_volume.png differ diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 5d3cac68f..11eb2b89e 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -3541,8 +3541,20 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) } case 501: case 502: + case 503: + case 504: + case 505: { - int page = theCommandID == 501 ? SMESHGUI_MeasureDlg::MinDistance : SMESHGUI_MeasureDlg::BoundingBox; + int page = SMESHGUI_MeasureDlg::MinDistance; + if ( theCommandID == 502 ) + page = SMESHGUI_MeasureDlg::BoundingBox; + else if ( theCommandID == 503 ) + page = SMESHGUI_MeasureDlg::Length; + else if ( theCommandID == 504 ) + page = SMESHGUI_MeasureDlg::Area; + else if ( theCommandID == 505 ) + page = SMESHGUI_MeasureDlg::Volume; + EmitSignalDeactivateDialog(); SMESHGUI_MeasureDlg* dlg = new SMESHGUI_MeasureDlg( SMESHGUI::desktop(), page ); dlg->show(); @@ -3844,6 +3856,9 @@ void SMESHGUI::initialize( CAM_Application* app ) createSMESHAction( 501, "MEASURE_MIN_DIST", "ICON_MEASURE_MIN_DIST" ); createSMESHAction( 502, "MEASURE_BND_BOX", "ICON_MEASURE_BND_BOX" ); + createSMESHAction( 503, "MEASURE_LENGTH", "ICON_MEASURE_LENGTH" ); + createSMESHAction( 504, "MEASURE_AREA", "ICON_MEASURE_AREA" ); + createSMESHAction( 505, "MEASURE_VOLUME", "ICON_MEASURE_VOLUME" ); createSMESHAction( 300, "HIDE" ); createSMESHAction( 301, "SHOW" ); @@ -3872,7 +3887,8 @@ void SMESHGUI::initialize( CAM_Application* app ) addId = createMenu( tr( "MEN_ADD" ), modifyId, 402 ), removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ), renumId = createMenu( tr( "MEN_RENUM" ), modifyId, 404 ), - transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 ); + transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 ), + basicPropId = createMenu( tr( "MEN_BASIC_PROPERTIES" ), measureId, -1, 10 ); //createMenu( 111, importId, -1 ); createMenu( 112, importId, -1 ); @@ -4020,6 +4036,9 @@ void SMESHGUI::initialize( CAM_Application* app ) createMenu( 501, measureId, -1 ); createMenu( 502, measureId, -1 ); + createMenu( 503, basicPropId, -1 ); + createMenu( 504, basicPropId, -1 ); + createMenu( 505, basicPropId, -1 ); createMenu( 214, viewId, -1 ); // ----- create toolbars -------------- diff --git a/src/SMESHGUI/SMESHGUI_Measurements.cxx b/src/SMESHGUI/SMESHGUI_Measurements.cxx index a5580dd65..8cbf40364 100644 --- a/src/SMESHGUI/SMESHGUI_Measurements.cxx +++ b/src/SMESHGUI/SMESHGUI_Measurements.cxx @@ -1085,6 +1085,219 @@ void SMESHGUI_BoundingBox::clear() erasePreview(); } +/*! + \class SMESHGUI_BasicProperties + \brief basic properties measurement widget. + + Widget to calculate length, area or volume for the selected object(s). +*/ + +/*! + \brief Constructor. + \param parent parent widget +*/ +SMESHGUI_BasicProperties::SMESHGUI_BasicProperties( QWidget* parent ) +: QWidget( parent ) +{ + // Property (length, area or volume) + QGroupBox* aPropertyGrp = new QGroupBox( tr( "PROPERTY" ), this ); + + QRadioButton* aLength = new QRadioButton( tr( "LENGTH" ), aPropertyGrp ); + QRadioButton* anArea = new QRadioButton( tr( "AREA" ), aPropertyGrp ); + QRadioButton* aVolume = new QRadioButton( tr( "VOLUME" ), aPropertyGrp ); + + myMode = new QButtonGroup( this ); + myMode->addButton( aLength, Length ); + myMode->addButton( anArea, Area ); + myMode->addButton( aVolume, Volume ); + + QHBoxLayout* aPropertyLayout = new QHBoxLayout; + aPropertyLayout->addWidget( aLength ); + aPropertyLayout->addWidget( anArea ); + aPropertyLayout->addWidget( aVolume ); + + aPropertyGrp->setLayout( aPropertyLayout ); + + // Source object + QGroupBox* aSourceGrp = new QGroupBox( tr( "SOURCE_MESH_SUBMESH_GROUP" ), this ); + + mySource = new QLineEdit( aSourceGrp ); + mySource->setReadOnly( true ); + + QHBoxLayout* aSourceLayout = new QHBoxLayout; + aSourceLayout->addWidget( mySource ); + + aSourceGrp->setLayout( aSourceLayout ); + + // Compute button + QPushButton* aCompute = new QPushButton( tr( "COMPUTE" ), this ); + + // Result of computation (length, area or volume) + myResultGrp = new QGroupBox( this ); + + myResult = new QLineEdit; + myResult->setReadOnly( true ); + + QHBoxLayout* aResultLayout = new QHBoxLayout; + aResultLayout->addWidget( myResult ); + + myResultGrp->setLayout( aResultLayout ); + + // Layout + QGridLayout* aMainLayout = new QGridLayout( this ); + aMainLayout->setMargin( MARGIN ); + aMainLayout->setSpacing( SPACING ); + + aMainLayout->addWidget( aPropertyGrp, 0, 0, 1, 2 ); + aMainLayout->addWidget( aSourceGrp, 1, 0, 1, 2 ); + aMainLayout->addWidget( aCompute, 2, 0 ); + aMainLayout->addWidget( myResultGrp, 3, 0, 1, 2 ); + aMainLayout->setColumnStretch( 1, 5 ); + aMainLayout->setRowStretch( 4, 5 ); + + // Initial state + setMode( Length ); + + // Connections + connect( myMode, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) ); + connect( aCompute, SIGNAL( clicked() ), this, SLOT( compute() ) ); + + // Selection filter + QList filters; + filters.append( new SMESH_TypeFilter( SMESH::MESHorSUBMESH ) ); + filters.append( new SMESH_TypeFilter( SMESH::GROUP ) ); + myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR ); +} + +/*! + \brief Destructor +*/ +SMESHGUI_BasicProperties::~SMESHGUI_BasicProperties() +{ +} + +/*! + \brief Sets the measurement mode. + \param theMode the mode to set (length, area or volume meausurement) +*/ +void SMESHGUI_BasicProperties::setMode( const Mode theMode ) +{ + QRadioButton* aButton = qobject_cast( myMode->button( theMode ) ); + if ( aButton ) { + aButton->setChecked( true ); + modeChanged( theMode ); + } +} + +/*! + \brief Setup the selection mode. +*/ +void SMESHGUI_BasicProperties::updateSelection() +{ + LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr(); + + disconnect( selMgr, 0, this, 0 ); + selMgr->clearFilters(); + + SMESH::SetPointRepresentation( false ); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() ) { + aViewWindow->SetSelectionMode( ActorSelection ); + } + selMgr->installFilter( myFilter ); + + connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) ); +} + +/*! + \brief Deactivate widget +*/ +void SMESHGUI_BasicProperties::deactivate() +{ + disconnect( SMESHGUI::selectionMgr(), 0, this, 0 ); +} + +/*! + \brief Called when selection is changed +*/ +void SMESHGUI_BasicProperties::selectionChanged() +{ + SUIT_OverrideCursor wc; + + SALOME_ListIO selected; + SMESHGUI::selectionMgr()->selectedObjects( selected ); + + if ( selected.Extent() == 1 ) { + Handle(SALOME_InteractiveObject) IO = selected.First(); + SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface( IO ); + if ( !CORBA::is_nil( obj ) ) { + mySrc = obj; + + QString aName; + SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName ); + mySource->setText( aName ); + } + } + + clear(); +} + +/*! + \brief Called when the measurement mode selection is changed. + \param theMode the selected mode +*/ +void SMESHGUI_BasicProperties::modeChanged( int theMode ) +{ + clear(); + + if ( theMode == Length ) { + myResultGrp->setTitle( tr("LENGTH") ); + } else if ( theMode == Area ) { + myResultGrp->setTitle( tr("AREA") ); + } else if ( theMode == Volume ) { + myResultGrp->setTitle( tr("VOLUME") ); + } +} + +/*! + \brief Calculate length, area or volume for the selected object(s) +*/ +void SMESHGUI_BasicProperties::compute() +{ + SUIT_OverrideCursor wc; + + SMESH::SMESH_IDSource_var source; + + if ( !CORBA::is_nil( mySrc ) ) { + // compute + int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 ); + SMESH::Measurements_var measure = SMESHGUI::GetSMESHGen()->CreateMeasurements(); + + double result = 0; + + if ( myMode->checkedId() == Length ) { + result = measure->Length( mySrc.in() ); + } else if ( myMode->checkedId() == Area ) { + result = measure->Area( mySrc.in() ); + } else if ( myMode->checkedId() == Volume ) { + result = measure->Volume( mySrc.in() ); + } + + measure->UnRegister(); + + myResult->setText( QString::number( result, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + } else { + clear(); + } +} + +/*! + \brief Reset the widget to the initial state (nullify the result field) +*/ +void SMESHGUI_BasicProperties::clear() +{ + myResult->clear(); +} + /*! \class SMESHGUI_MeshInfoDlg \brief Centralized dialog box for the measurements @@ -1110,12 +1323,17 @@ SMESHGUI_MeasureDlg::SMESHGUI_MeasureDlg( QWidget* parent, int page ) // min distance myMinDist = new SMESHGUI_MinDistance( myTabWidget ); - myTabWidget->addTab( myMinDist, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_MIN_DIST" ) ), tr( "MIN_DIST" ) ); + int aMinDistInd = myTabWidget->addTab( myMinDist, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_MIN_DIST" ) ), tr( "MIN_DIST" ) ); // bounding box myBndBox = new SMESHGUI_BoundingBox( myTabWidget ); - myTabWidget->addTab( myBndBox, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_BND_BOX" ) ), tr( "BND_BOX" ) ); + int aBndBoxInd = myTabWidget->addTab( myBndBox, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_BND_BOX" ) ), tr( "BND_BOX" ) ); + + // basic properties + + myBasicProps = new SMESHGUI_BasicProperties( myTabWidget ); + int aBasicPropInd = myTabWidget->addTab( myBasicProps, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_BASIC_PROPS" ) ), tr( "BASIC_PROPERTIES" ) ); // buttons QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this ); @@ -1139,7 +1357,19 @@ SMESHGUI_MeasureDlg::SMESHGUI_MeasureDlg( QWidget* parent, int page ) l->addStretch(); l->addLayout( btnLayout ); - myTabWidget->setCurrentIndex( qMax( (int)MinDistance, qMin( (int)BoundingBox, page ) ) ); + int anInd = -1; + if ( page == MinDistance ) { + anInd = aMinDistInd; + } else if ( page == BoundingBox ) { + anInd = aBndBoxInd; + } else if ( page == Length || page == Area || page == Volume ) { + myBasicProps->setMode( (SMESHGUI_BasicProperties::Mode)(page - Length) ); + anInd = aBasicPropInd; + } + + if ( anInd >= 0 ) { + myTabWidget->setCurrentIndex( anInd ); + } connect( okBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); connect( helpBtn, SIGNAL( clicked() ), this, SLOT( help() ) ); @@ -1200,7 +1430,10 @@ void SMESHGUI_MeasureDlg::updateSelection() myMinDist->updateSelection(); else if ( myTabWidget->currentIndex() == BoundingBox ) myBndBox->updateSelection(); - + else { + myBndBox->erasePreview(); + myBasicProps->updateSelection(); + } } /*! @@ -1208,9 +1441,16 @@ void SMESHGUI_MeasureDlg::updateSelection() */ void SMESHGUI_MeasureDlg::help() { - SMESH::ShowHelpFile( myTabWidget->currentIndex() == MinDistance ? - "measurements_page.html#min_distance_anchor" : - "measurements_page.html#bounding_box_anchor" ); + QString aHelpFile; + if ( myTabWidget->currentIndex() == MinDistance ) { + aHelpFile = "measurements_page.html#min_distance_anchor"; + } else if ( myTabWidget->currentIndex() == BoundingBox ) { + aHelpFile = "measurements_page.html#bounding_box_anchor"; + } else { + aHelpFile = "measurements_page.html#basic_properties_anchor"; + } + + SMESH::ShowHelpFile( aHelpFile ); } /*! @@ -1229,6 +1469,7 @@ void SMESHGUI_MeasureDlg::activate() */ void SMESHGUI_MeasureDlg::deactivate() { + myBasicProps->deactivate(); myMinDist->deactivate(); myBndBox->deactivate(); myTabWidget->setEnabled( false ); diff --git a/src/SMESHGUI/SMESHGUI_Measurements.h b/src/SMESHGUI/SMESHGUI_Measurements.h index f4cd672fb..65e3539cd 100644 --- a/src/SMESHGUI/SMESHGUI_Measurements.h +++ b/src/SMESHGUI/SMESHGUI_Measurements.h @@ -32,6 +32,7 @@ class QButtonGroup; class QLineEdit; class QTabWidget; +class QGroupBox; class SUIT_SelectionFilter; class SALOME_Actor; class SMESH_Actor; @@ -101,9 +102,9 @@ public: void updateSelection(); void deactivate(); + void erasePreview(); private: - void erasePreview(); void displayPreview(); void createPreview( double, double, double, double, double, double ); @@ -135,6 +136,37 @@ private: SALOME_Actor* myPreview; }; +class SMESHGUI_EXPORT SMESHGUI_BasicProperties : public QWidget +{ + Q_OBJECT; + +public: + //! Property type + enum Mode { Length, Area, Volume }; + + SMESHGUI_BasicProperties( QWidget* = 0 ); + ~SMESHGUI_BasicProperties(); + + void setMode( const Mode ); + + void updateSelection(); + void deactivate(); + +private slots: + void selectionChanged(); + void modeChanged( int); + void compute(); + void clear(); + +private: + QButtonGroup* myMode; + QLineEdit* mySource; + QGroupBox* myResultGrp; + QLineEdit* myResult; + SMESH::SMESH_IDSource_var mySrc; + SUIT_SelectionFilter* myFilter; +}; + class SMESHGUI_EXPORT SMESHGUI_MeasureDlg : public QDialog { Q_OBJECT; @@ -145,7 +177,10 @@ public: //! Measurement type enum { MinDistance, //!< minimum distance - BoundingBox //!< bounding box + BoundingBox, //!< bounding box + Length, //!< length + Area, //!< area + Volume //!< volume }; SMESHGUI_MeasureDlg( QWidget* = 0, int = MinDistance ); @@ -167,6 +202,7 @@ private: QTabWidget* myTabWidget; SMESHGUI_MinDistance* myMinDist; SMESHGUI_BoundingBox* myBndBox; + SMESHGUI_BasicProperties* myBasicProps; }; #endif // SMESHGUI_MEASUREMENTS_H diff --git a/src/SMESHGUI/SMESH_images.ts b/src/SMESHGUI/SMESH_images.ts index a8fa7fd73..c985f167e 100644 --- a/src/SMESHGUI/SMESH_images.ts +++ b/src/SMESHGUI/SMESH_images.ts @@ -559,6 +559,22 @@ ICON_SPLIT_TO_TETRA split_into_tetra.png + + ICON_MEASURE_LENGTH + mesh_measure_length.png + + + ICON_MEASURE_AREA + mesh_measure_area.png + + + ICON_MEASURE_VOLUME + mesh_measure_volume.png + + + ICON_MEASURE_BASIC_PROPS + mesh_measure_basic_props.png + ICON_MEASURE_MIN_DIST mesh_min_dist.png diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index ba6d7aedf..e989562ed 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -712,6 +712,46 @@ TOP_MEASURE_BND_BOX Bounding box + + MEN_BASIC_PROPERTIES + Basic Properties + + + MEN_MEASURE_LENGTH + Length + + + STB_MEASURE_LENGTH + Calculate sum of length of all 1D elements of the selected object(s) + + + TOP_MEASURE_LENGTH + Length + + + MEN_MEASURE_AREA + Area + + + STB_MEASURE_AREA + Calculate sum of area of all 2D elements of the selected object(s) + + + TOP_MEASURE_AREA + Area + + + MEN_MEASURE_VOLUME + Volume + + + STB_MEASURE_VOLUME + Calculate sum of volume of all 3D elements of the selected object(s) + + + TOP_MEASURE_VOLUME + Volume + MEN_MOVE Move Node @@ -7308,6 +7348,33 @@ as they are of improper type: Distance + + SMESHGUI_BasicProperties + + PROPERTY + Property + + + LENGTH + Length + + + AREA + Area + + + VOLUME + Volume + + + SOURCE_MESH_SUBMESH_GROUP + Source (mesh, sub-mesh or group) + + + COMPUTE + Compute + + SMESHGUI_CopyMeshDlg @@ -7337,6 +7404,10 @@ as they are of improper type: BND_BOX Bounding Box + + BASIC_PROPERTIES + Basic Properties + SMESHGUI_BoundingBox diff --git a/src/SMESHGUI/SMESH_msg_fr.ts b/src/SMESHGUI/SMESH_msg_fr.ts index bc0d57a4d..6f409879b 100755 --- a/src/SMESHGUI/SMESH_msg_fr.ts +++ b/src/SMESHGUI/SMESH_msg_fr.ts @@ -748,6 +748,46 @@ TOP_MEASURE_BND_BOX Boîte englobante + + MEN_BASIC_PROPERTIES + Basic Properties + + + MEN_MEASURE_LENGTH + Length + + + STB_MEASURE_LENGTH + Calculate sum of length of all 1D elements of the selected object(s) + + + TOP_MEASURE_LENGTH + Length + + + MEN_MEASURE_AREA + Area + + + STB_MEASURE_AREA + Calculate sum of area of all 2D elements of the selected object(s) + + + TOP_MEASURE_AREA + Area + + + MEN_MEASURE_VOLUME + Volume + + + STB_MEASURE_VOLUME + Calculate sum of volume of all 3D elements of the selected object(s) + + + TOP_MEASURE_VOLUME + Volume + MEN_MOVE Déplacer un nœud @@ -7294,6 +7334,33 @@ en raison de leurs types incompatibles: Distance + + SMESHGUI_BasicProperties + + PROPERTY + Property + + + LENGTH + Length + + + AREA + Area + + + VOLUME + Volume + + + SOURCE_MESH_SUBMESH_GROUP + Source (mesh, sub-mesh or group) + + + COMPUTE + Compute + + SMESHGUI_CopyMeshDlg @@ -7323,6 +7390,10 @@ en raison de leurs types incompatibles: BND_BOX Boîte englobante + + BASIC_PROPERTIES + Basic Properties + SMESHGUI_BoundingBox diff --git a/src/SMESH_I/SMESH_Measurements_i.cxx b/src/SMESH_I/SMESH_Measurements_i.cxx index 9a9d439aa..9bb687fc3 100644 --- a/src/SMESH_I/SMESH_Measurements_i.cxx +++ b/src/SMESH_I/SMESH_Measurements_i.cxx @@ -25,6 +25,7 @@ #include "SMESH_Measurements_i.hxx" #include "SMESH_Gen_i.hxx" +#include "SMESH_Filter_i.hxx" #include "SMESH_PythonDump.hxx" #include "SMDS_Mesh.hxx" @@ -131,6 +132,24 @@ static bool isNodeType (SMESH::array_of_ElementType_var theTypes) return theTypes->length() > 0 && theTypes[0] == SMESH::NODE; } +static double getNumericalValue(SMESH::SMESH_IDSource_ptr theSource, SMESH::Controls::NumericalFunctorPtr theFunctor) +{ + double value = 0; + + if ( !CORBA::is_nil( theSource ) ) { + const SMESHDS_Mesh* aMesh = getMesh( theSource ); + if ( aMesh ) { + theFunctor->SetMesh( aMesh ); + + SMESH::long_array_var anElementsId = theSource->GetIDs(); + for (int i = 0; i < anElementsId->length(); i++) { + value += theFunctor->GetValue( anElementsId[i] ); + } + } + } + return value; +} + //======================================================================= // name : MinDistance // Purpose : minimal distance between two given entities @@ -257,3 +276,30 @@ SMESH::Measure Measurements_i::BoundingBox (const SMESH::ListOfIDSources& theSou return aMeasure; } + +//======================================================================= +// name : Length +// Purpose : sum of length of 1D elements of the source +//======================================================================= +double Measurements_i::Length(SMESH::SMESH_IDSource_ptr theSource) +{ + return getNumericalValue( theSource, SMESH::Controls::NumericalFunctorPtr(new SMESH::Controls::Length()) ); +} + +//======================================================================= +// name : Area +// Purpose : sum of area of 2D elements of the source +//======================================================================= +double Measurements_i::Area(SMESH::SMESH_IDSource_ptr theSource) +{ + return getNumericalValue( theSource, SMESH::Controls::NumericalFunctorPtr(new SMESH::Controls::Area()) ); +} + +//======================================================================= +// name : Volume +// Purpose : sum of volume of 3D elements of the source +//======================================================================= +double Measurements_i::Volume(SMESH::SMESH_IDSource_ptr theSource) +{ + return getNumericalValue( theSource, SMESH::Controls::NumericalFunctorPtr(new SMESH::Controls::Volume()) ); +} diff --git a/src/SMESH_I/SMESH_Measurements_i.hxx b/src/SMESH_I/SMESH_Measurements_i.hxx index 0f1bbadac..f7135ae44 100644 --- a/src/SMESH_I/SMESH_Measurements_i.hxx +++ b/src/SMESH_I/SMESH_Measurements_i.hxx @@ -57,6 +57,22 @@ namespace SMESH * common bounding box of entities */ SMESH::Measure BoundingBox(const SMESH::ListOfIDSources& theSources); + + + /*! + * sum of length of 1D elements of the source + */ + double Length(SMESH::SMESH_IDSource_ptr theSource); + + /*! + * sum of area of 2D elements of the source + */ + double Area(SMESH::SMESH_IDSource_ptr); + + /*! + * sum of volume of 3D elements of the source + */ + double Volume(SMESH::SMESH_IDSource_ptr); }; } diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index d0471ca0f..b0f55e498 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -4398,25 +4398,46 @@ class Mesh: return val ## Get length of 1D element. - # @param elemId mesh element ID + # @param elemId mesh element ID (if not defined - sum of length of all 1D elements will be calculated) # @return element's length value # @ingroup l1_measurements - def GetLength(self, elemId): - return self._valueFromFunctor(SMESH.FT_Length, elemId) + def GetLength(self, elemId=None): + length = 0 + if elemId == None: + aMeasurements = self.smeshpyD.CreateMeasurements() + length = aMeasurements.Length(self.GetMesh()) + aMeasurements.UnRegister() + else: + length = self._valueFromFunctor(SMESH.FT_Length, elemId) + return length ## Get area of 2D element. - # @param elemId mesh element ID + # @param elemId mesh element ID (if not defined - sum of area of all 2D elements will be calculated) # @return element's area value # @ingroup l1_measurements - def GetArea(self, elemId): - return self._valueFromFunctor(SMESH.FT_Area, elemId) + def GetArea(self, elemId=None): + area = 0 + if elemId == None: + aMeasurements = self.smeshpyD.CreateMeasurements() + area = aMeasurements.Area(self.GetMesh()) + aMeasurements.UnRegister() + else: + area = self._valueFromFunctor(SMESH.FT_Area, elemId) + return area ## Get volume of 3D element. - # @param elemId mesh element ID + # @param elemId mesh element ID (if not defined - sum of volume of all 3D elements will be calculated) # @return element's volume value # @ingroup l1_measurements - def GetVolume(self, elemId): - return self._valueFromFunctor(SMESH.FT_Volume3D, elemId) + def GetVolume(self, elemId=None): + volume = 0 + if elemId == None: + aMeasurements = self.smeshpyD.CreateMeasurements() + volume = aMeasurements.Volume(self.GetMesh()) + aMeasurements.UnRegister() + else: + volume = self._valueFromFunctor(SMESH.FT_Volume3D, elemId) + return volume ## Get maximum element length. # @param elemId mesh element ID