#include <QLayout>
#include <QLineEdit>
#include <QListWidget>
+#include <QPushButton>
HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_InputPanel( theModule, theTitle )
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()
myAxises->clear();
myProfiles->clear();
+ myAddButton->setEnabled( false );
blockSignals( isBlocked );
void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
{
+ myAddButton->setEnabled( !myAxises->currentText().isEmpty() );
+
int aNewIdx = myAxises->findText( theName );
if ( aNewIdx != myAxises->currentIndex() )
{
emit CreatePreview();
}
+
+void HYDROGUI_StreamDlg::onRemoveProfiles()
+{
+ QStringList aSelectedProfiles;
+
+ QList<QListWidgetItem*> aSelectedItems = myProfiles->selectedItems();
+ foreach( const QListWidgetItem* anItem, aSelectedItems ) {
+ QString aProfileName = anItem->text();
+ if ( !aProfileName.isEmpty() ) {
+ aSelectedProfiles << aProfileName;
+ }
+ }
+
+ if ( !aSelectedProfiles.isEmpty() ) {
+ emit RemoveProfiles( aSelectedProfiles );
+ }
+}
#include <LightApp_SelectionMgr.h>
#include <LightApp_UpdateFlags.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+
#include <OCCViewer_ViewManager.h>
#include <OCCViewer_ViewModel.h>
#include <OCCViewer_ViewWindow.h>
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();
}
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;
}
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();
void HYDROGUI_StreamOp::onCreatePreview()
{
- HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( 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<OCCViewer_ViewManager*>(
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<HYDROGUI_StreamDlg*>( 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 );
+}