From: mzn Date: Tue, 3 Dec 2013 11:31:55 +0000 (+0000) Subject: Initial solution for bug #141: Stream object. X-Git-Tag: BR_hydro_v_0_4~81 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7293e4989b4e85a3531cd6c77b14e5129ee617aa;p=modules%2Fhydro.git Initial solution for bug #141: Stream object. --- diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx index b2aa1e1a..cc8ba0f8 100644 --- a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx @@ -30,6 +30,7 @@ #include #include #include +#include HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_InputPanel( theModule, theTitle ) @@ -50,28 +51,44 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin myAxises = new QComboBox( aParamGroup ); myAxises->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + QBoxLayout* anAxisLayout = new QHBoxLayout(); + anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) ); + anAxisLayout->addWidget( myAxises ); myProfiles = new QListWidget( aParamGroup ); - myProfiles->setSelectionMode( QListWidget::SingleSelection ); + myProfiles->setSelectionMode( QListWidget::MultiSelection ); myProfiles->setEditTriggers( QListWidget::NoEditTriggers ); myProfiles->setViewMode( QListWidget::ListMode ); myProfiles->setSortingEnabled( false ); + + myAddButton = new QPushButton( aParamGroup ); + myAddButton->setText( tr("ADD") ); + myRemoveButton = new QPushButton( aParamGroup ); + myRemoveButton->setText( tr("REMOVE") ); + QBoxLayout* aButtonsLayout = new QHBoxLayout(); + aButtonsLayout->addWidget( myAddButton ); + aButtonsLayout->addWidget( myRemoveButton ); + aButtonsLayout->addStretch(); - QGridLayout* aParamLayout = new QGridLayout( aParamGroup ); + QBoxLayout* aParamLayout = new QVBoxLayout(); aParamLayout->setMargin( 5 ); aParamLayout->setSpacing( 5 ); - aParamLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ), aParamGroup ), 0, 0 ); - aParamLayout->addWidget( myAxises, 0, 1 ); - aParamLayout->addWidget( myProfiles, 1, 0, 1, 2 ); + aParamLayout->addLayout( anAxisLayout ); + aParamLayout->addWidget( myProfiles ); + aParamLayout->addLayout( aButtonsLayout ); + + aParamGroup->setLayout( aParamLayout ); // Common addWidget( myObjectNameGroup ); addWidget( aParamGroup ); - addStretch(); // Connect signals and slots - connect( myAxises, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onStreamDefChanged() ) ); + connect( myAxises, SIGNAL( currentIndexChanged( const QString & ) ), + this, SIGNAL( AxisChanged( const QString& ) ) ); + connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) ); + connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) ); } HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg() @@ -86,6 +103,7 @@ void HYDROGUI_StreamDlg::reset() myAxises->clear(); myProfiles->clear(); + myAddButton->setEnabled( false ); blockSignals( isBlocked ); @@ -114,6 +132,8 @@ void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises ) void HYDROGUI_StreamDlg::setAxisName( const QString& theName ) { + myAddButton->setEnabled( !myAxises->currentText().isEmpty() ); + int aNewIdx = myAxises->findText( theName ); if ( aNewIdx != myAxises->currentIndex() ) { @@ -175,3 +195,20 @@ void HYDROGUI_StreamDlg::onStreamDefChanged() emit CreatePreview(); } + +void HYDROGUI_StreamDlg::onRemoveProfiles() +{ + QStringList aSelectedProfiles; + + QList aSelectedItems = myProfiles->selectedItems(); + foreach( const QListWidgetItem* anItem, aSelectedItems ) { + QString aProfileName = anItem->text(); + if ( !aProfileName.isEmpty() ) { + aSelectedProfiles << aProfileName; + } + } + + if ( !aSelectedProfiles.isEmpty() ) { + emit RemoveProfiles( aSelectedProfiles ); + } +} diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.h b/src/HYDROGUI/HYDROGUI_StreamDlg.h index 425f8699..b78dc719 100644 --- a/src/HYDROGUI/HYDROGUI_StreamDlg.h +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.h @@ -29,6 +29,7 @@ class QComboBox; class QGroupBox; class QLineEdit; class QListWidget; +class QPushButton; class HYDROGUI_StreamDlg : public HYDROGUI_InputPanel { @@ -52,9 +53,13 @@ public: signals: void CreatePreview(); + void AddProfiles(); + void RemoveProfiles( const QStringList& ); + void AxisChanged( const QString& ); private slots: void onStreamDefChanged(); + void onRemoveProfiles(); private: @@ -63,6 +68,8 @@ private: QComboBox* myAxises; QListWidget* myProfiles; + QPushButton* myRemoveButton; + QPushButton* myAddButton; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index 30cad0e3..103d8bd3 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -36,6 +36,9 @@ #include #include +#include +#include + #include #include #include @@ -63,55 +66,30 @@ void HYDROGUI_StreamOp::startOperation() HYDROGUI_StreamDlg* aPanel = (HYDROGUI_StreamDlg*)inputPanel(); - aPanel->blockSignals( true ); - - aPanel->reset(); - if( myIsEdit ) myEditedObject = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); else myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) ); - QString aSelectedAxis; - QStringList aSelectedProfiles; - QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) ); - if ( myIsEdit && !myEditedObject.IsNull() ) - { + if ( myIsEdit && !myEditedObject.IsNull() ) { anObjectName = myEditedObject->GetName(); - - Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis(); - if ( !aHydraulicAxis.IsNull() ) - aSelectedAxis = aHydraulicAxis->GetName(); - - HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles(); - for ( int i = 1, n = aProfiles.Length(); i <= n; ++i ) - { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) ); - if ( aProfile.IsNull() ) - continue; - - QString aProfileName = aProfile->GetName(); - aSelectedProfiles << aProfileName; - } - } - - QStringList anAxises = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ); - - // Temporary, to be removed - if ( aSelectedProfiles.isEmpty() ) - { - aSelectedProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE ); } + // Update panel data + aPanel->blockSignals( true ); + aPanel->reset(); aPanel->setObjectName( anObjectName ); - aPanel->setAxisNames( anAxises ); - aPanel->setAxisName( aSelectedAxis ); - aPanel->setSelectedProfiles( aSelectedProfiles ); - + aPanel->setAxisNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) ); aPanel->blockSignals( false ); + if ( myIsEdit ) { + updatePanel(); + } else { + onAxisChanged( aPanel->getAxisName() ); + } + + // Create preview onCreatePreview(); } @@ -133,7 +111,12 @@ void HYDROGUI_StreamOp::commitOperation() HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const { HYDROGUI_StreamDlg* aPanel = new HYDROGUI_StreamDlg( module(), getName() ); - connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) ); + //TODO connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) ); + connect( aPanel, SIGNAL( AddProfiles() ), this, SLOT( onAddProfiles() ) ); + connect( aPanel, SIGNAL( RemoveProfiles( const QStringList& ) ), + this, SLOT( onRemoveProfiles( const QStringList& ) ) ); + connect( aPanel, SIGNAL( AxisChanged( const QString& ) ), + this, SLOT( onAxisChanged( const QString& ) ) ); return aPanel; } @@ -165,6 +148,20 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, if ( myEditedObject.IsNull() ) return false; + // Check if the axis is set + Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis(); + if ( aHydraulicAxis.IsNull() ) { + theErrorMsg = tr( "AXIS_NOT_DEFINED" ); + return false; + } + + // Check if the axis is set + HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles(); + if ( aProfiles.Length() < 2 ) { + theErrorMsg = tr( "PROFILES_NOT_DEFINED" ); + return false; + } + myEditedObject->SetName( anObjectName ); erasePreview(); @@ -179,43 +176,9 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, void HYDROGUI_StreamOp::onCreatePreview() { - HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel ) - return; - - QString anAxisName = aPanel->getAxisName(); - QStringList aProfiles = aPanel->getSelectedProfiles(); - if ( anAxisName.isEmpty() || aProfiles.isEmpty() ) - { - erasePreview(); - return; - } - if ( myEditedObject.IsNull() ) return; - // At first we remove all references from stream - myEditedObject->RemoveProfiles(); - - Handle(HYDROData_PolylineXY) anAxis = Handle(HYDROData_PolylineXY)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), anAxisName, KIND_POLYLINEXY ) ); - myEditedObject->SetHydraulicAxis( anAxis ); - - HYDROData_SequenceOfObjects aProfileObjects = - HYDROGUI_Tool::FindObjectsByNames( module(), aProfiles, KIND_PROFILE ); - for ( int i = 1, n = aProfileObjects.Length(); i <= n; ++i ) - { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aProfileObjects.Value( i ) ); - if ( aProfile.IsNull() ) - continue; - - myEditedObject->AddProfile( aProfile ); - } - - myEditedObject->Update(); - - LightApp_Application* anApp = module()->getApp(); if ( !myViewManager ) myViewManager = ::qobject_cast( @@ -245,3 +208,164 @@ void HYDROGUI_StreamOp::erasePreview() myPreviewPrs = 0; } } + +void HYDROGUI_StreamOp::onAddProfiles() +{ + if ( myEditedObject.IsNull() ) { + return; + } + + // Get the current profiles list + HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles(); + + // TODO: to be optimized + QStringList aCurrentProfiles; + for( int anIndex = 1, aLength = aProfiles.Length(); anIndex <= aLength; anIndex++ ) { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aProfiles.Value( anIndex ) ); + if ( !aProfile.IsNull() ) { + aCurrentProfiles << aProfile->GetName(); + } + } + + // Get the selected profiles ( in the Object Browser ) + QStringList anInvalidProfiles, anExistingProfiles, aHasNoIntersectionProfiles; + + HYDROData_SequenceOfObjects aSeqOfProfiles; + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); + for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aSeq.Value( anIndex ) ); + if ( !aProfile.IsNull() ) { + QString aProfileName = aProfile->GetName(); + + // Check the profile, if all is ok - add it to the list + if ( !aProfile->IsValid() ) { // check whether the profile is valid + anInvalidProfiles << aProfileName; + } else if ( aCurrentProfiles.contains( aProfileName ) ) { // check whether the profile is already added + anExistingProfiles << aProfileName; + } else if ( !myEditedObject->HasIntersection( aProfile ) ) { // check whether the profile has intersection + aHasNoIntersectionProfiles << aProfile->GetName(); + } else { + aSeqOfProfiles.Append( aProfile ); + } + } + } + + // Show message box with the ignored profiles + QStringList anIgnoredProfiles; + anIgnoredProfiles << anInvalidProfiles << anExistingProfiles << aHasNoIntersectionProfiles; + if ( !anIgnoredProfiles.isEmpty() ) { + QString aMessage = tr( "IGNORED_PROFILES" ).arg( anIgnoredProfiles.join( "\n" ) ); + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), aMessage ); + } + + // Update the stream object + for( int anIndex = 1, aLength = aSeqOfProfiles.Length(); anIndex <= aLength; anIndex++ ) { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( anIndex ) ); + myEditedObject->AddProfile( aProfile ); + } + myEditedObject->Update(); + + // Update the panel + updatePanel(); + + // Update preview + onCreatePreview(); +} + +void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove ) +{ + if ( myEditedObject.IsNull() ) { + return; + } + + // Remove profiles + foreach( const QString& aProfileName, theProfilesToRemove ) { + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + myEditedObject->RemoveProfile( aProfile ); + } + myEditedObject->Update(); + + // Update the panel + updatePanel(); + + // Update preview + onCreatePreview(); +} + +void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis ) +{ + if ( myEditedObject.IsNull() ) { + return; + } + + // Get axis object + Handle(HYDROData_PolylineXY) anAxis = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), theNewAxis, KIND_POLYLINEXY ) ); + + // Get list of profiles which do not intersect the axis + QStringList aHasNoIntersectionProfiles; + HYDROData_SequenceOfObjects aCurrentProfiles = myEditedObject->GetProfiles(); + for( int anIndex = 1, aLength = aCurrentProfiles.Length(); anIndex <= aLength; anIndex++ ) { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aCurrentProfiles.Value( anIndex ) ); + if ( !aProfile.IsNull() ) { + // TODO check intersection + } + } + + // Show message box to confirm + bool isConfirmed = true; + if ( !aHasNoIntersectionProfiles.isEmpty() ) { + // TODO show message box + } + + // Check if the user has confirmed axis change + if ( !isConfirmed ) { + updatePanel(); + } else { + // Set axis + myEditedObject->SetHydraulicAxis( anAxis ); + myEditedObject->Update(); + + // Update the panel + updatePanel(); + + // Update preview + onCreatePreview(); + } +} + +void HYDROGUI_StreamOp::updatePanel() +{ + HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) { + return; + } + + // Hydraulic axis + Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis(); + if ( !aHydraulicAxis.IsNull() ) { + aPanel->setAxisName( aHydraulicAxis->GetName() ); + } + + // Stream profiles + QStringList aSelectedProfiles; + + HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles(); + for ( int i = 1, n = aProfiles.Length(); i <= n; ++i ) { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) ); + if ( aProfile.IsNull() ) { + continue; + } + + QString aProfileName = aProfile->GetName(); + aSelectedProfiles << aProfileName; + } + + aPanel->setSelectedProfiles( aSelectedProfiles ); +} diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.h b/src/HYDROGUI/HYDROGUI_StreamOp.h index 05ccea56..0d35f92e 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.h +++ b/src/HYDROGUI/HYDROGUI_StreamOp.h @@ -51,8 +51,13 @@ protected: private slots: void onCreatePreview(); + void onAddProfiles(); + void onRemoveProfiles( const QStringList& ); + void onAxisChanged( const QString& ); + private: void erasePreview(); + void updatePanel(); private: OCCViewer_ViewManager* myViewManager; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index bd122612..c0538c9d 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1547,6 +1547,14 @@ file cannot be correctly imported for an Obstacle definition. STREAM_HYDRAULIC_AXIS Hydraulic axis + + ADD + Add + + + REMOVE + Remove + @@ -1563,6 +1571,23 @@ file cannot be correctly imported for an Obstacle definition. DEFAULT_STREAM_NAME Stream + + WARNING + Warning + + + IGNORED_PROFILES + The following profile(s) will be ignored: +%1 + + + AXIS_NOT_DEFINED + Hydraulic axis is not defiled. + + + PROFILES_NOT_DEFINED + At least 2 profiles should be defined. +