+/*!
+ \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<SUIT_SelectionFilter*> 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<QRadioButton*>( 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<SMESH::SMESH_IDSource>( 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();
+}
+