From: mzn Date: Thu, 16 Jan 2014 09:43:54 +0000 (+0000) Subject: Feature #197: translation or georeferencing of OBSTACLES Box and Cylinder. X-Git-Tag: BR_hydro_v_1_0~87 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fc42f9cabfa130d72aea8c10f003d6bec315b6c6;p=modules%2Fhydro.git Feature #197: translation or georeferencing of OBSTACLES Box and Cylinder. --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 5eac71fd..612e9be9 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -84,6 +84,8 @@ set(PROJECT_HEADERS HYDROGUI_GeoreferencementOp.h HYDROGUI_Actor.h HYDROGUI_BathymetryBoundsOp.h + HYDROGUI_TranslateObstacleDlg.h + HYDROGUI_TranslateObstacleOp.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -169,6 +171,8 @@ set(PROJECT_SOURCES HYDROGUI_GeoreferencementOp.cxx HYDROGUI_Actor.cxx HYDROGUI_BathymetryBoundsOp.cxx + HYDROGUI_TranslateObstacleDlg.cxx + HYDROGUI_TranslateObstacleOp.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index c409cdbe..c9aa1704 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -592,6 +592,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( EditDigueId ) ); theMenu->addSeparator(); } + else if( anIsObstacle ) + { + theMenu->addAction( action( TranslateObstacleId ) ); + theMenu->addSeparator(); + } else if( anIsVisualState && anIsObjectBrowser ) { theMenu->addAction( action( SaveVisualStateId ) ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 768781b1..aedb1dee 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -48,6 +48,7 @@ #include "HYDROGUI_ImmersibleZoneOp.h" #include "HYDROGUI_ImportGeomObjectOp.h" #include "HYDROGUI_ImportObstacleFromFileOp.h" +#include "HYDROGUI_TranslateObstacleOp.h" #include "HYDROGUI_ExportCalculationOp.h" #include "HYDROGUI_ImportProfilesOp.h" #include "HYDROGUI_GeoreferencementOp.h" @@ -148,6 +149,7 @@ void HYDROGUI_Module::createActions() createAction( ImportGeomObjectAsPolylineId, "IMPORT_GEOM_OBJECT_AS_POLYLINE", "IMPORT_GEOM_OBJECT_ICO" ); createAction( CreateBoxId, "CREATE_BOX", "CREATE_BOX_ICO" ); createAction( CreateCylinderId, "CREATE_CYLINDER", "CREATE_CYLINDER_ICO" ); + createAction( TranslateObstacleId, "TRANSLATE_OBSTACLE" ); createAction( CreateCalculationId, "CREATE_CALCULATION", "CREATE_CALCULATION_ICO" ); createAction( EditCalculationId, "EDIT_CALCULATION", "EDIT_CALCULATION_ICO" ); @@ -480,6 +482,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpCylinder ); break; + case TranslateObstacleId: + anOp = new HYDROGUI_TranslateObstacleOp( aModule ); + break; case CopyViewerPositionId: anOp = new HYDROGUI_CopyPastePositionOp( aModule, false ); break; diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index a376f7b6..435206a2 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -91,6 +91,7 @@ enum OperationId ImportGeomObjectAsPolylineId, CreateBoxId, CreateCylinderId, + TranslateObstacleId, CopyViewerPositionId, diff --git a/src/HYDROGUI/HYDROGUI_TranslateObstacleDlg.cxx b/src/HYDROGUI/HYDROGUI_TranslateObstacleDlg.cxx new file mode 100644 index 00000000..c130f355 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_TranslateObstacleDlg.cxx @@ -0,0 +1,115 @@ +// 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_TranslateObstacleDlg.h" + +#include + +#include +#include +#include +#include + +#include + +HYDROGUI_TranslateObstacleDlg::HYDROGUI_TranslateObstacleDlg( HYDROGUI_Module* theModule, const QString& theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ) +{ + // Obstacle name + QGroupBox* aNameGroup = new QGroupBox( tr( "OBSTACLE_NAME" ), this ); + + QLabel* aNameLabel = new QLabel( tr( "NAME" ), aNameGroup ); + myName = new QLineEdit( aNameGroup ); + myName->setEnabled( false ); + + QBoxLayout* aNameLayout = new QHBoxLayout( aNameGroup ); + aNameLayout->setMargin( 5 ); + aNameLayout->setSpacing( 5 ); + aNameLayout->addWidget( aNameLabel ); + aNameLayout->addWidget( myName ); + + // Translation arguments + QGroupBox* anArgGroup = new QGroupBox( tr( "TRANSLATION_ARGUMENTS" ), this ); + + QLabel* aDxLabel = new QLabel( tr( "DX" ), anArgGroup ); + myDxSpin = new QtxDoubleSpinBox( -1e+15, +1e+15, 10, anArgGroup ); + + QLabel* aDyLabel = new QLabel( tr( "DY" ), anArgGroup ); + myDySpin = new QtxDoubleSpinBox( -1e+15, +1e+15, 10, anArgGroup ); + + QLabel* aDzLabel = new QLabel( tr( "DZ" ), anArgGroup ); + myDzSpin = new QtxDoubleSpinBox( -1e+15, +1e+15, 10, anArgGroup ); + + QGridLayout* anArgLayout = new QGridLayout( anArgGroup ); + anArgLayout->setMargin( 5 ); + anArgLayout->setSpacing( 5 ); + + anArgLayout->addWidget( aDxLabel, 0, 0 ); + anArgLayout->addWidget( myDxSpin, 0, 1 ); + anArgLayout->addWidget( aDyLabel, 1, 0 ); + anArgLayout->addWidget( myDySpin, 1, 1 ); + anArgLayout->addWidget( aDzLabel, 2, 0 ); + anArgLayout->addWidget( myDzSpin, 2, 1 ); + + // Layout + addWidget( aNameGroup ); + addWidget( anArgGroup ); + addStretch(); + + // Connect signals and slots + connect( myDxSpin, SIGNAL( valueChanged( double ) ), this, SIGNAL( argumentsChanged() ) ); + connect( myDySpin, SIGNAL( valueChanged( double ) ), this, SIGNAL( argumentsChanged() ) ); + connect( myDzSpin, SIGNAL( valueChanged( double ) ), this, SIGNAL( argumentsChanged() ) ); +} + +HYDROGUI_TranslateObstacleDlg::~HYDROGUI_TranslateObstacleDlg() +{ +} + +void HYDROGUI_TranslateObstacleDlg::reset() +{ + myName->clear(); + + myDxSpin->setValue( 0 ); + myDySpin->setValue( 0 ); + myDzSpin->setValue( 0 ); +} + +void HYDROGUI_TranslateObstacleDlg::setName( const QString& theName ) +{ + myName->setText( theName ); +} + +double HYDROGUI_TranslateObstacleDlg::getDx() const +{ + return myDxSpin->value(); +} + +double HYDROGUI_TranslateObstacleDlg::getDy() const +{ + return myDySpin->value(); +} + +double HYDROGUI_TranslateObstacleDlg::getDz() const +{ + return myDzSpin->value(); +} diff --git a/src/HYDROGUI/HYDROGUI_TranslateObstacleDlg.h b/src/HYDROGUI/HYDROGUI_TranslateObstacleDlg.h new file mode 100644 index 00000000..e9c20804 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_TranslateObstacleDlg.h @@ -0,0 +1,59 @@ +// 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_TranslateObstacleDlg_H +#define HYDROGUI_TranslateObstacleDlg_H + +#include "HYDROGUI_InputPanel.h" + +class QtxDoubleSpinBox; + +class QLineEdit; + +class HYDROGUI_TranslateObstacleDlg : public HYDROGUI_InputPanel +{ + Q_OBJECT + +public: + HYDROGUI_TranslateObstacleDlg( HYDROGUI_Module* theModule, const QString& theTitle ); + virtual ~HYDROGUI_TranslateObstacleDlg(); + + void reset(); + + void setName( const QString& theName ); + + double getDx() const; + double getDy() const; + double getDz() const; + +signals: + void argumentsChanged(); + +private: + QLineEdit* myName; + + QtxDoubleSpinBox* myDxSpin; + QtxDoubleSpinBox* myDySpin; + QtxDoubleSpinBox* myDzSpin; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_TranslateObstacleOp.cxx b/src/HYDROGUI/HYDROGUI_TranslateObstacleOp.cxx new file mode 100644 index 00000000..c6771910 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_TranslateObstacleOp.cxx @@ -0,0 +1,201 @@ +// 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_TranslateObstacleOp.h" + +#include "HYDROGUI_TranslateObstacleDlg.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Shape.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include + + +HYDROGUI_TranslateObstacleOp::HYDROGUI_TranslateObstacleOp( HYDROGUI_Module* theModule ) +: HYDROGUI_Operation( theModule ), + myPreviewPrs( NULL ) +{ + setName( tr( "TRANSLATE_OBSTACLE" ) ); +} + +HYDROGUI_TranslateObstacleOp::~HYDROGUI_TranslateObstacleOp() +{ + erasePreview(); +} + +void HYDROGUI_TranslateObstacleOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + // Get panel and reset its state + HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel(); + aPanel->reset(); + + // Get the edited object + myEditedObject = Handle(HYDROData_Obstacle)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if ( myEditedObject.IsNull() ) { + abort(); + return; + } + else if ( myEditedObject->IsMustBeUpdated() ) { + myEditedObject->Update(); + } + + // Set the edited object name to the panel + aPanel->setName( myEditedObject->GetName() ); + + // Create preview + createPreview(); +} + +void HYDROGUI_TranslateObstacleOp::abortOperation() +{ + erasePreview(); + abortDocOperation(); + + HYDROGUI_Operation::abortOperation(); +} + +void HYDROGUI_TranslateObstacleOp::commitOperation() +{ + erasePreview(); + + HYDROGUI_Operation::commitOperation(); +} + +HYDROGUI_InputPanel* HYDROGUI_TranslateObstacleOp::createInputPanel() const +{ + HYDROGUI_TranslateObstacleDlg* aPanel = new HYDROGUI_TranslateObstacleDlg( module(), getName() ); + + connect( aPanel, SIGNAL( argumentsChanged() ), this, SLOT( onArgumentsChanged() ) ); + + return aPanel; +} + +bool HYDROGUI_TranslateObstacleOp::processApply( int& theUpdateFlags, + QString& theErrorMsg ) +{ + HYDROGUI_TranslateObstacleDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel || myEditedObject.IsNull() ) { + return false; + } + + // Get the translated shape + TopoDS_Shape aTranslatedShape = getTranslatedShape(); + if ( aTranslatedShape.IsNull() ) { + return false; + } + + // Erase preview + erasePreview(); + + // Set the translated shape to the obstacle + myEditedObject->SetShape3D( aTranslatedShape ); + myEditedObject->Update(); + + module()->setIsToUpdate( myEditedObject ); + + // Set update flags + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; + + return true; +} + +void HYDROGUI_TranslateObstacleOp::createPreview() +{ + if ( myEditedObject.IsNull() ) { + return; + } + + // Create preview presentation if necessary + if ( !myPreviewPrs ) { + LightApp_Application* anApp = module()->getApp(); + OCCViewer_ViewManager* aViewManager = ::qobject_cast( + anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ); + + if ( aViewManager ) { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( !aCtx.IsNull() ) { + myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL ); + myPreviewPrs->setFillingColor( myEditedObject->GetFillingColor(), false, false ); + myPreviewPrs->setBorderColor( myEditedObject->GetBorderColor(), false, false ); + } + } + } + } + + // Get the translated shape + TopoDS_Shape aTranslatedShape = getTranslatedShape(); + + // Set the translated shape to the preview presentation + if ( myPreviewPrs ) { + myPreviewPrs->setShape( aTranslatedShape ); + } +} + +void HYDROGUI_TranslateObstacleOp::erasePreview() +{ + if( myPreviewPrs ) { + delete myPreviewPrs; + myPreviewPrs = 0; + } +} + +void HYDROGUI_TranslateObstacleOp::onArgumentsChanged() +{ + // Update preview + createPreview(); +} + +TopoDS_Shape HYDROGUI_TranslateObstacleOp::getTranslatedShape() const +{ + TopoDS_Shape aTranslatedShape; + + HYDROGUI_TranslateObstacleDlg* aPanel = (HYDROGUI_TranslateObstacleDlg*)inputPanel(); + if ( aPanel && !myEditedObject.IsNull() ) { + double aDx = aPanel->getDx(); + double aDy = aPanel->getDy(); + double aDz = aPanel->getDz(); + + TopoDS_Shape aShape = myEditedObject->GetShape3D(); + gp_Trsf aTrsf; + gp_Vec aVec( aDx, aDy, aDz ); + aTrsf.SetTranslation(aVec); + TopLoc_Location aLocOrig = aShape.Location(); + gp_Trsf aTrsfOrig = aLocOrig.Transformation(); + TopLoc_Location aLocRes( aTrsf * aTrsfOrig ); + aTranslatedShape = aShape.Located( aLocRes ); + } + + return aTranslatedShape; +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_TranslateObstacleOp.h b/src/HYDROGUI/HYDROGUI_TranslateObstacleOp.h new file mode 100644 index 00000000..5d21e047 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_TranslateObstacleOp.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_TranslateObstacleOp_H +#define HYDROGUI_TranslateObstacleOp_H + +#include "HYDROGUI_Operation.h" + +#include + +class HYDROGUI_Shape; +class TopoDS_Shape; + +class HYDROGUI_TranslateObstacleOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_TranslateObstacleOp( HYDROGUI_Module* theModule ); + virtual ~HYDROGUI_TranslateObstacleOp(); + +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 onArgumentsChanged(); + +private: + void createPreview(); + void erasePreview(); + + TopoDS_Shape getTranslatedShape() const; + +private: + Handle(HYDROData_Obstacle) myEditedObject; + + HYDROGUI_Shape* myPreviewPrs; +}; + +#endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 2ccbb1c3..0703adc5 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -810,6 +810,10 @@ Would you like to remove all references from the image? DSK_CREATE_CYLINDER Create cylinder obstacle + + DSK_TRANSLATE_OBSTACLE + Translate obstacle + DSK_COLOR Set object color @@ -1050,6 +1054,10 @@ Would you like to remove all references from the image? MEN_CREATE_CYLINDER Create cylinder + + MEN_TRANSLATE_OBSTACLE + Translate + MEN_COLOR Color @@ -1262,6 +1270,10 @@ Would you like to remove all references from the image? STB_CREATE_CYLINDER Create cylinder obstacle + + STB_TRANSLATE_OBSTACLE + Translate obstacle + STB_COLOR Set object color @@ -1988,6 +2000,42 @@ Polyline should consist from one not closed curve. + + HYDROGUI_TranslateObstacleDlg + + OBSTACLE_NAME + Obstacle name + + + NAME + Name + + + TRANSLATION_ARGUMENTS + Arguments + + + DX + Dx + + + DY + Dy + + + DZ + Dz + + + + + HYDROGUI_TranslateObstacleOp + + TRANSLATE_OBSTACLE + Translation of an obstacle + + + HYDROGUI_RunBrowser