From 8c70d5cb1e04edf503afb50caf735fa1c4f45b25 Mon Sep 17 00:00:00 2001 From: adv Date: Mon, 2 Dec 2013 10:56:38 +0000 Subject: [PATCH] Creat\Edit stream operation. --- src/HYDROData/HYDROData_Stream.cxx | 15 +- src/HYDROGUI/CMakeLists.txt | 4 + src/HYDROGUI/HYDROGUI_Module.cxx | 34 +-- src/HYDROGUI/HYDROGUI_Operation.cxx | 9 +- src/HYDROGUI/HYDROGUI_Operations.cxx | 15 +- src/HYDROGUI/HYDROGUI_Operations.h | 3 + src/HYDROGUI/HYDROGUI_Shape.cxx | 52 +++-- src/HYDROGUI/HYDROGUI_StreamDlg.cxx | 177 ++++++++++++++++ src/HYDROGUI/HYDROGUI_StreamDlg.h | 68 ++++++ src/HYDROGUI/HYDROGUI_StreamOp.cxx | 247 ++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_StreamOp.h | 66 ++++++ src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 60 ++++++ 12 files changed, 709 insertions(+), 41 deletions(-) create mode 100644 src/HYDROGUI/HYDROGUI_StreamDlg.cxx create mode 100644 src/HYDROGUI/HYDROGUI_StreamDlg.h create mode 100755 src/HYDROGUI/HYDROGUI_StreamOp.cxx create mode 100755 src/HYDROGUI/HYDROGUI_StreamOp.h diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 2b5d29ea..0512e90a 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -121,6 +121,9 @@ void HYDROData_Stream::Update() { a2dShellBuilder.Add( a2dShell, aMakeFace.Face() ); } + + aPrevFirstPoint = aCurFirstPoint; + aPrevLastPoint = aCurLastPoint; } SetTopShape( a2dShell ); @@ -132,9 +135,16 @@ void HYDROData_Stream::Update() bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis ) { Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis(); - if ( theAxis.IsNull() || IsEqual( aPrevAxis, theAxis ) ) + + if ( theAxis.IsNull() ) + { + RemoveHydraulicAxis(); + return !aPrevAxis.IsNull(); + } + + if ( IsEqual( aPrevAxis, theAxis ) ) return false; - + TopoDS_Wire aHydraulicWire = TopoDS::Wire( theAxis->GetShape() ); if ( aHydraulicWire.IsNull() ) return false; // The polyline must be a single wire @@ -243,6 +253,7 @@ void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& return; // TODO + AddReferenceObject( theProfile, DataTag_Profile ); // temporary for testing only } void HYDROData_Stream::updateProfilesOrder() diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 52b10504..9d953b67 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -49,6 +49,8 @@ set(PROJECT_HEADERS HYDROGUI_RemoveImageRefsOp.h HYDROGUI_Shape.h HYDROGUI_ShowHideOp.h + HYDROGUI_StreamDlg.h + HYDROGUI_StreamOp.h HYDROGUI_Tool.h HYDROGUI_TwoImagesDlg.h HYDROGUI_TwoImagesOp.h @@ -122,6 +124,8 @@ set(PROJECT_SOURCES HYDROGUI_RemoveImageRefsOp.cxx HYDROGUI_Shape.cxx HYDROGUI_ShowHideOp.cxx + HYDROGUI_StreamDlg.cxx + HYDROGUI_StreamOp.cxx HYDROGUI_Tool.cxx HYDROGUI_TwoImagesDlg.cxx HYDROGUI_TwoImagesOp.cxx diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 616b4a9a..604ed597 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -240,6 +240,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsRegion = false; bool anIsZone = false; bool anIsObstacle = false; + bool anIsStream = false; bool anIsGeomObject = false; // check the selected GEOM objects @@ -262,7 +263,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, anIsVisibleInSelection |= aVisibility; anIsHiddenInSelection |= !aVisibility; - if( anObject->GetKind() == KIND_IMAGE ) + ObjectKind anObjectKind = anObject->GetKind(); + if( anObjectKind == KIND_IMAGE ) { anIsImage = true; Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject ); @@ -289,11 +291,12 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, } } } - else if( anObject->GetKind() == KIND_POLYLINEXY ) + else if( anObjectKind == KIND_POLYLINEXY ) anIsPolyline = true; - else if( anObject->GetKind() == KIND_POLYLINE ) + else if( anObjectKind == KIND_POLYLINE ) anIsPolyline3D = true; - else if( anObject->GetKind() == KIND_PROFILE ) { + else if( anObjectKind == KIND_PROFILE ) + { anIsProfile = true; aNbOfSelectedProfiles++; @@ -303,20 +306,22 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, anIsValidProfile = true; } } - else if( anObject->GetKind() == KIND_CALCULATION ) + else if( anObjectKind == KIND_CALCULATION ) anIsCalculation = true; - else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE ) + else if( anObjectKind == KIND_IMMERSIBLE_ZONE ) anIsImmersibleZone = true; - else if( anObject->GetKind() == KIND_VISUAL_STATE ) + else if( anObjectKind == KIND_VISUAL_STATE ) anIsVisualState = true; - else if( anObject->GetKind() == KIND_REGION ) + else if( anObjectKind == KIND_REGION ) anIsRegion = true; - else if( anObject->GetKind() == KIND_ZONE ) + else if( anObjectKind == KIND_ZONE ) anIsZone = true; - else if( anObject->GetKind() == KIND_BATHYMETRY ) + else if( anObjectKind == KIND_BATHYMETRY ) anIsBathymetry = true; - else if( anObject->GetKind() == KIND_OBSTACLE ) + else if( anObjectKind == KIND_OBSTACLE ) anIsObstacle = true; + else if( anObjectKind == KIND_STREAM ) + anIsStream = true; } anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject ); @@ -436,6 +441,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( EditImmersibleZoneId ) ); theMenu->addSeparator(); } + else if( anIsStream ) + { + theMenu->addAction( action( EditStreamId ) ); + theMenu->addSeparator(); + } else if( anIsVisualState && anIsObjectBrowser ) { theMenu->addAction( action( SaveVisualStateId ) ); @@ -458,7 +468,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addSeparator(); if( anIsImage || anIsPolyline || anIsPolyline3D || anIsImmersibleZone || anIsZone || - anIsRegion || anIsBathymetry || anIsObstacle || anIsValidProfile ) + anIsRegion || anIsBathymetry || anIsObstacle || anIsStream || anIsValidProfile ) { if( anIsHiddenInSelection ) theMenu->addAction( action( ShowId ) ); diff --git a/src/HYDROGUI/HYDROGUI_Operation.cxx b/src/HYDROGUI/HYDROGUI_Operation.cxx index 52fbcd17..1f308ea3 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.cxx +++ b/src/HYDROGUI/HYDROGUI_Operation.cxx @@ -143,19 +143,22 @@ void HYDROGUI_Operation::processCancel() void HYDROGUI_Operation::startDocOperation() { // Open transaction in the model document - doc()->StartOperation(); + if ( !doc()->IsOperation() ) + doc()->StartOperation(); } void HYDROGUI_Operation::abortDocOperation() { // Abort transaction in the model document - doc()->AbortOperation(); + if ( doc()->IsOperation() ) + doc()->AbortOperation(); } void HYDROGUI_Operation::commitDocOperation() { // Commit transaction in the model document - doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) ); + if ( doc()->IsOperation() ) + doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) ); } Handle_HYDROData_Document HYDROGUI_Operation::doc() const diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 233cddba..6e1bc51c 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -37,7 +37,7 @@ #include "HYDROGUI_ProfileOp.h" #include "HYDROGUI_RemoveImageRefsOp.h" #include "HYDROGUI_ShowHideOp.h" -#include "HYDROData_SplitToZonesTool.h" +#include "HYDROGUI_StreamOp.h" #include "HYDROGUI_TwoImagesOp.h" #include "HYDROGUI_UpdateFlags.h" #include "HYDROGUI_UpdateImageOp.h" @@ -50,8 +50,9 @@ #include "HYDROGUI_GeoreferencementOp.h" #include "HYDROGUI_SetColorOp.h" -#include "HYDROData_Document.h" -#include "HYDROData_Obstacle.h" +#include +#include +#include #include #include @@ -122,6 +123,9 @@ void HYDROGUI_Module::createActions() createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" ); createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" ); + createAction( CreateStreamId, "CREATE_STREAM" ); + createAction( EditStreamId, "EDIT_STREAM" ); + createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" ); createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" ); createAction( CreateBoxId, "CREATE_BOX" ); @@ -179,6 +183,7 @@ void HYDROGUI_Module::createMenus() createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 ); createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 ); + createMenu( CreateStreamId, aHydroId, -1, -1 ); int aNewObstacleId = createMenu( tr( "MEN_OBSTACLE" ), aHydroId, -1 ); createMenu( ImportObstacleFromFileId, aNewObstacleId, -1, -1 ); @@ -365,6 +370,10 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case EditImmersibleZoneId: anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId ); break; + case CreateStreamId: + case EditStreamId: + anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId ); + break; case CreateCalculationId: case EditCalculationId: anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 6a488f27..534d56ca 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -61,6 +61,9 @@ enum OperationId CreateImmersibleZoneId, EditImmersibleZoneId, + CreateStreamId, + EditStreamId, + CreateCalculationId, EditCalculationId, ExportCalculationId, diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 9e36f73d..86f12ef4 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -40,11 +40,12 @@ #include #include #include +#include #include +#include #include +#include #include -#include -#include #include #include @@ -169,25 +170,6 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() ); - // Generate the filling color for zone - QStringList aGeomObjectsNames; - - HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects(); - HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Object) aRefbject = - Handle(HYDROData_Object)::DownCast( anIter.Value() ); - if ( aRefbject.IsNull() ) - continue; - - QString aRefObjectName = aRefbject->GetName(); - if ( aRefObjectName.isEmpty() ) - continue; - - aGeomObjectsNames.append( aRefObjectName ); - } - setFace( aZoneFace, false, false ); if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) { @@ -196,6 +178,25 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) } else { + // Generate the filling color for zone + QStringList aGeomObjectsNames; + + HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Object) aRefbject = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( aRefbject.IsNull() ) + continue; + + QString aRefObjectName = aRefbject->GetName(); + if ( aRefObjectName.isEmpty() ) + continue; + + aGeomObjectsNames.append( aRefObjectName ); + } + setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) ); } } @@ -304,6 +305,15 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) setWire( aProfileWire, false, false ); } + else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ) + { + Handle(HYDROData_Stream) aStream = + Handle(HYDROData_Stream)::DownCast( myObject ); + + TopoDS_Shell aStreamShape = TopoDS::Shell( aStream->GetTopShape() ); + + setShape( aStreamShape, false, false ); + } } if ( myShape.IsNull() || !isVisible() ) diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx new file mode 100644 index 00000000..b2aa1e1a --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx @@ -0,0 +1,177 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_StreamDlg.h" + +#include "HYDROGUI_Tool.h" + +#include +#include +#include +#include +#include +#include + +HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ) +{ + // Stream name + myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() ); + + myObjectName = new QLineEdit( myObjectNameGroup ); + + QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup ); + aNameLayout->setMargin( 5 ); + aNameLayout->setSpacing( 5 ); + aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) ); + aNameLayout->addWidget( myObjectName ); + + // Stream parameters + QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() ); + + myAxises = new QComboBox( aParamGroup ); + myAxises->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + myProfiles = new QListWidget( aParamGroup ); + myProfiles->setSelectionMode( QListWidget::SingleSelection ); + myProfiles->setEditTriggers( QListWidget::NoEditTriggers ); + myProfiles->setViewMode( QListWidget::ListMode ); + myProfiles->setSortingEnabled( false ); + + QGridLayout* aParamLayout = new QGridLayout( aParamGroup ); + 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 ); + + // Common + addWidget( myObjectNameGroup ); + addWidget( aParamGroup ); + + addStretch(); + + // Connect signals and slots + connect( myAxises, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onStreamDefChanged() ) ); +} + +HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg() +{ +} + +void HYDROGUI_StreamDlg::reset() +{ + bool isBlocked = blockSignals( true ); + + myObjectName->clear(); + + myAxises->clear(); + myProfiles->clear(); + + blockSignals( isBlocked ); + + onStreamDefChanged(); +} + +void HYDROGUI_StreamDlg::setObjectName( const QString& theName ) +{ + myObjectName->setText( theName ); +} + +QString HYDROGUI_StreamDlg::getObjectName() const +{ + return myObjectName->text(); +} + +void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises ) +{ + bool isBlocked = blockSignals( true ); + + myAxises->clear(); + myAxises->addItems( theAxises ); + + blockSignals( isBlocked ); +} + +void HYDROGUI_StreamDlg::setAxisName( const QString& theName ) +{ + int aNewIdx = myAxises->findText( theName ); + if ( aNewIdx != myAxises->currentIndex() ) + { + myAxises->setCurrentIndex( aNewIdx ); + } + else + { + onStreamDefChanged(); + } +} + +QString HYDROGUI_StreamDlg::getAxisName() const +{ + return myAxises->currentText(); +} + +void HYDROGUI_StreamDlg::setSelectedProfiles( const QStringList& theProfiles ) +{ + bool isBlocked = blockSignals( true ); + + myProfiles->setUpdatesEnabled( false ); + + myProfiles->clear(); + for ( int i = 0, n = theProfiles.length(); i < n; ++i ) + { + const QString& aProfileName = theProfiles.at( i ); + QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles ); + aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); + } + + myProfiles->setUpdatesEnabled( true ); + + blockSignals( isBlocked ); + + onStreamDefChanged(); +} + +QStringList HYDROGUI_StreamDlg::getSelectedProfiles() const +{ + QStringList aProfiles; + + for ( int i = 0, n = myProfiles->count(); i < n; ++i ) + { + QListWidgetItem* aListItem = myProfiles->item( i ); + if ( !aListItem ) + continue; + + QString aProfileName = aListItem->text(); + aProfiles << aProfileName; + } + + return aProfiles; +} + +void HYDROGUI_StreamDlg::onStreamDefChanged() +{ + if ( signalsBlocked() ) + return; + + emit CreatePreview(); +} diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.h b/src/HYDROGUI/HYDROGUI_StreamDlg.h new file mode 100644 index 00000000..425f8699 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.h @@ -0,0 +1,68 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_StreamDlg_H +#define HYDROGUI_StreamDlg_H + +#include "HYDROGUI_InputPanel.h" + +class QComboBox; +class QGroupBox; +class QLineEdit; +class QListWidget; + +class HYDROGUI_StreamDlg : public HYDROGUI_InputPanel +{ + Q_OBJECT + +public: + HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle ); + virtual ~HYDROGUI_StreamDlg(); + + void reset(); + + void setObjectName( const QString& theName ); + QString getObjectName() const; + + void setAxisNames( const QStringList& theAxises ); + void setAxisName( const QString& thePolyline ); + QString getAxisName() const; + + void setSelectedProfiles( const QStringList& theProfiles ); + QStringList getSelectedProfiles() const; + +signals: + void CreatePreview(); + +private slots: + void onStreamDefChanged(); + +private: + + QGroupBox* myObjectNameGroup; + QLineEdit* myObjectName; + + QComboBox* myAxises; + QListWidget* myProfiles; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx new file mode 100755 index 00000000..30cad0e3 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -0,0 +1,247 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_StreamOp.h" + +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Shape.h" +#include "HYDROGUI_StreamDlg.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +HYDROGUI_StreamOp::HYDROGUI_StreamOp( HYDROGUI_Module* theModule, bool theIsEdit ) +: HYDROGUI_Operation( theModule ), + myIsEdit( theIsEdit ), + myViewManager( NULL ), + myPreviewPrs( NULL ) +{ + setName( theIsEdit ? tr( "EDIT_STREAM" ) : tr( "CREATE_STREAM" ) ); +} + +HYDROGUI_StreamOp::~HYDROGUI_StreamOp() +{ + erasePreview(); +} + +void HYDROGUI_StreamOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + // We start operation in the document + startDocOperation(); + + 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() ) + { + 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 ); + } + + aPanel->setObjectName( anObjectName ); + aPanel->setAxisNames( anAxises ); + aPanel->setAxisName( aSelectedAxis ); + aPanel->setSelectedProfiles( aSelectedProfiles ); + + aPanel->blockSignals( false ); + + onCreatePreview(); +} + +void HYDROGUI_StreamOp::abortOperation() +{ + erasePreview(); + abortDocOperation(); + + HYDROGUI_Operation::abortOperation(); +} + +void HYDROGUI_StreamOp::commitOperation() +{ + erasePreview(); + + HYDROGUI_Operation::commitOperation(); +} + +HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const +{ + HYDROGUI_StreamDlg* aPanel = new HYDROGUI_StreamDlg( module(), getName() ); + connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) ); + return aPanel; +} + +bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, + QString& theErrorMsg ) +{ + HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return false; + + QString anObjectName = aPanel->getObjectName().simplified(); + if ( anObjectName.isEmpty() ) + { + theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); + return false; + } + + if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) + { + // check that there are no other objects with the same name in the document + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); + if( !anObject.IsNull() ) + { + theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName ); + return false; + } + } + + if ( myEditedObject.IsNull() ) + return false; + + myEditedObject->SetName( anObjectName ); + + erasePreview(); + + if( !myIsEdit ) + module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true ); + + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + + return true; +} + +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( + anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ); + + if ( myViewManager && !myPreviewPrs ) + { + if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( !aCtx.IsNull() ) + myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject ); + } + } + + if ( !myViewManager || !myPreviewPrs ) + return; + + myPreviewPrs->update(); +} + +void HYDROGUI_StreamOp::erasePreview() +{ + if( myPreviewPrs ) + { + delete myPreviewPrs; + myPreviewPrs = 0; + } +} diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.h b/src/HYDROGUI/HYDROGUI_StreamOp.h new file mode 100755 index 00000000..05ccea56 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_StreamOp.h @@ -0,0 +1,66 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_StreamOp_H +#define HYDROGUI_StreamOp_H + +#include "HYDROGUI_Operation.h" + +#include + +class OCCViewer_ViewManager; +class HYDROGUI_Shape; + +class HYDROGUI_StreamOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_StreamOp( HYDROGUI_Module* theModule, bool isEdit ); + virtual ~HYDROGUI_StreamOp(); + +protected: + + virtual void startOperation(); + virtual void abortOperation(); + virtual void commitOperation(); + + virtual HYDROGUI_InputPanel* createInputPanel() const; + + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); + +private slots: + void onCreatePreview(); + +private: + void erasePreview(); + +private: + OCCViewer_ViewManager* myViewManager; + + bool myIsEdit; + Handle(HYDROData_Stream) myEditedObject; + + HYDROGUI_Shape* myPreviewPrs; +}; + +#endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 84d57407..4b13e041 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -504,6 +504,14 @@ file cannot be correctly imported for a Bathymetry definition. DSK_EDIT_IMMERSIBLE_ZONE Edit immersible zone + + DSK_CREATE_STREAM + Create stream + + + DSK_EDIT_STREAM + Edit stream + DSK_COPY Copy @@ -676,6 +684,14 @@ file cannot be correctly imported for a Bathymetry definition. MEN_EDIT_IMMERSIBLE_ZONE Edit immersible zone + + MEN_CREATE_STREAM + Create stream + + + MEN_EDIT_STREAM + Edit stream + MEN_CUT_IMAGES Cut images @@ -856,6 +872,14 @@ file cannot be correctly imported for a Bathymetry definition. STB_EDIT_IMMERSIBLE_ZONE Edit immersible zone + + STB_CREATE_STREAM + Create stream + + + STB_EDIT_STREAM + Edit stream + STB_COPY Copy @@ -1465,4 +1489,40 @@ file cannot be correctly imported for an Obstacle definition. + + HYDROGUI_StreamDlg + + NAME + Name + + + STREAM_NAME + Stream name + + + STREAM_PARAMETERS + Parameters + + + STREAM_HYDRAULIC_AXIS + Hydraulic axis + + + + + HYDROGUI_StreamOp + + CREATE_STREAM + Create stream + + + EDIT_STREAM + Edit stream + + + DEFAULT_STREAM_NAME + Stream + + + -- 2.39.2