From: rkv Date: Mon, 2 Dec 2013 06:19:52 +0000 (+0000) Subject: Polyline3D creation/edit dialog and operation are added. X-Git-Tag: BR_hydro_v_0_4~115 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=902f7fd2408dda7bec3b9cc407cf476319871b6b;p=modules%2Fhydro.git Polyline3D creation/edit dialog and operation are added. --- diff --git a/src/HYDROData/HYDROData_Polyline3D.h b/src/HYDROData/HYDROData_Polyline3D.h index f45091b8..73f21cbb 100644 --- a/src/HYDROData/HYDROData_Polyline3D.h +++ b/src/HYDROData/HYDROData_Polyline3D.h @@ -38,7 +38,7 @@ public: /** * Returns the kind of this object. Must be redefined in all objects of known type. */ - HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_STREAM;} + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_POLYLINE;} /** * Dump object to Python script representation. diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 42b7be58..52b10504 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -30,6 +30,8 @@ set(PROJECT_HEADERS HYDROGUI_OCCSelector.h HYDROGUI_Operation.h HYDROGUI_Operations.h + HYDROGUI_Poly3DDlg.h + HYDROGUI_Poly3DOp.h HYDROGUI_PolylineDlg.h HYDROGUI_PolylineOp.h HYDROGUI_ProfileDlg.h @@ -101,6 +103,8 @@ set(PROJECT_SOURCES HYDROGUI_OCCSelector.cxx HYDROGUI_Operation.cxx HYDROGUI_Operations.cxx + HYDROGUI_Poly3DDlg.cxx + HYDROGUI_Poly3DOp.cxx HYDROGUI_PolylineDlg.cxx HYDROGUI_PolylineOp.cxx HYDROGUI_ProfileDlg.cxx diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 9357c85f..616b4a9a 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -229,6 +229,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsSplittedImage = false; bool anIsMustBeUpdatedImage = false; bool anIsPolyline = false; + bool anIsPolyline3D = false; bool anIsProfile = false; bool anIsValidProfile = false; bool anAllAreProfiles = false; @@ -290,6 +291,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, } else if( anObject->GetKind() == KIND_POLYLINEXY ) anIsPolyline = true; + else if( anObject->GetKind() == KIND_POLYLINE ) + anIsPolyline3D = true; else if( anObject->GetKind() == KIND_PROFILE ) { anIsProfile = true; aNbOfSelectedProfiles++; @@ -337,6 +340,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, case KIND_POLYLINEXY: theMenu->addAction( action( CreatePolylineId ) ); break; + case KIND_POLYLINE: + theMenu->addAction( action( CreatePolyline3DId ) ); + break; case KIND_PROFILE: theMenu->addAction( action( CreateProfileId ) ); theMenu->addAction( action( ImportProfilesId ) ); @@ -408,6 +414,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( EditPolylineId ) ); theMenu->addSeparator(); } + else if( anIsPolyline3D ) + { + theMenu->addAction( action( EditPolyline3DId ) ); + theMenu->addSeparator(); + } else if( anIsProfile ) { theMenu->addAction( action( EditProfileId ) ); @@ -446,7 +457,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( DeleteId ) ); theMenu->addSeparator(); - if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || + if( anIsImage || anIsPolyline || anIsPolyline3D || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle || anIsValidProfile ) { if( anIsHiddenInSelection ) diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 2e08c268..233cddba 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -33,6 +33,7 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_ObserveImageOp.h" #include "HYDROGUI_PolylineOp.h" +#include "HYDROGUI_Poly3DOp.h" #include "HYDROGUI_ProfileOp.h" #include "HYDROGUI_RemoveImageRefsOp.h" #include "HYDROGUI_ShowHideOp.h" @@ -107,6 +108,9 @@ void HYDROGUI_Module::createActions() createAction( CreatePolylineId, "CREATE_POLYLINE" ); createAction( EditPolylineId, "EDIT_POLYLINE" ); + createAction( CreatePolyline3DId, "CREATE_POLYLINE_3D" ); + createAction( EditPolyline3DId, "EDIT_POLYLINE_3D" ); + createAction( CreateProfileId, "CREATE_PROFILE" ); createAction( ImportProfilesId, "IMPORT_PROFILES" ); createAction( EditProfileId, "EDIT_PROFILE" ); @@ -167,6 +171,7 @@ void HYDROGUI_Module::createMenus() createMenu( ImportImageId, aHydroId, -1, -1 ); createMenu( ImportBathymetryId, aHydroId, -1, -1 ); createMenu( CreatePolylineId, aHydroId, -1, -1 ); + createMenu( CreatePolyline3DId, aHydroId, -1, -1 ); int aNewProfileId = createMenu( tr( "MEN_PROFILE" ), aHydroId, -1 ); createMenu( CreateProfileId, aNewProfileId, -1, -1 ); @@ -332,6 +337,10 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case RemoveImageRefsId: anOp = new HYDROGUI_RemoveImageRefsOp( aModule ); break; + case CreatePolyline3DId: + case EditPolyline3DId: + anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId ); + break; case CreatePolylineId: case EditPolylineId: anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 795fe283..6a488f27 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -46,6 +46,9 @@ enum OperationId CreatePolylineId, EditPolylineId, + CreatePolyline3DId, + EditPolyline3DId, + ImportProfilesId, CreateProfileId, EditProfileId, diff --git a/src/HYDROGUI/HYDROGUI_Poly3DDlg.cxx b/src/HYDROGUI/HYDROGUI_Poly3DDlg.cxx new file mode 100644 index 00000000..5cbf6235 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Poly3DDlg.cxx @@ -0,0 +1,120 @@ +// 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_Poly3DDlg.h" + +#include "HYDROGUI_ObjSelector.h" + +#include +#include +#include +#include +#include + +HYDROGUI_Poly3DDlg::HYDROGUI_Poly3DDlg( HYDROGUI_Module* theModule, const QString& theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ), + myIsEdit( false ) +{ + // Profile name + QGroupBox* aNameGroup = new QGroupBox( tr( "POLYLINE_3D_NAME" ) ); + + QLabel* aNameLabel = new QLabel( tr( "NAME" ), aNameGroup ); + myName = new QLineEdit( aNameGroup ); + + QGridLayout* aNameLayout = new QGridLayout( aNameGroup ); + aNameLayout->setMargin( 5 ); + aNameLayout->setSpacing( 5 ); + aNameLayout->addWidget( aNameLabel, 0, 0 ); + aNameLayout->addWidget( myName, 0, 1 ); + + // Parameters + QGroupBox* aParamGroup = new QGroupBox( tr( "PARAMETERS" ) ); + + myProfileLabel = new QLabel( tr( "PROFILE" ), aParamGroup ); + myProfile = new HYDROGUI_ObjSelector( theModule, KIND_PROFILE, aParamGroup ); + + myPolylineLabel = new QLabel( tr( "POLYLINE" ), aParamGroup ); + myPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINEXY, aParamGroup ); + + QGridLayout* aParamLayout = new QGridLayout( aParamGroup ); + aParamLayout->setMargin( 5 ); + aParamLayout->setSpacing( 5 ); + aParamLayout->addWidget( myProfileLabel, 0, 0 ); + aParamLayout->addWidget( myProfile, 0, 1 ); + aParamLayout->addWidget( myPolylineLabel, 1, 0 ); + aParamLayout->addWidget( myPolyline, 1, 1 ); + + // Common + addWidget( aNameGroup ); + addWidget( aParamGroup ); + addStretch(); + + setMode( myIsEdit ); +} + +HYDROGUI_Poly3DDlg::~HYDROGUI_Poly3DDlg() +{ +} + +void HYDROGUI_Poly3DDlg::reset() +{ + myName->clear(); + myProfile->Clear(); + myPolyline->Clear(); +} + +void HYDROGUI_Poly3DDlg::setMode( const bool theIsEdit ) +{ + myIsEdit = theIsEdit; +} + +void HYDROGUI_Poly3DDlg::setResultName( const QString& theName ) +{ + myName->setText( theName ); +} + +QString HYDROGUI_Poly3DDlg::getResultName() const +{ + return myName->text(); +} + +void HYDROGUI_Poly3DDlg::setSelectedObjects( const QString& theName1, + const QString& theName2 ) +{ + myProfile->SetName( theName1 ); + myPolyline->SetName( theName2 ); +} + +bool HYDROGUI_Poly3DDlg::getSelectedObjects( QString& theName1, + QString& theName2 ) const +{ + theName1 = myProfile->GetName(); + theName2 = myPolyline->GetName(); + return !theName1.isEmpty() && !theName2.isEmpty(); +} + +void HYDROGUI_Poly3DDlg::setPreselectedObject( const QString& theName ) +{ + myProfile->SetName( theName ); + myPolyline->SetChecked( true ); + myPolyline->SetName( QString() ); +} diff --git a/src/HYDROGUI/HYDROGUI_Poly3DDlg.h b/src/HYDROGUI/HYDROGUI_Poly3DDlg.h new file mode 100644 index 00000000..e8aaced1 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Poly3DDlg.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_POLY3DDLG_H +#define HYDROGUI_POLY3DDLG_H + +#include "HYDROGUI_InputPanel.h" + +class QCheckBox; +class QLabel; +class QLineEdit; + +class HYDROGUI_ObjSelector; + +class HYDROGUI_Poly3DDlg : public HYDROGUI_InputPanel +{ + Q_OBJECT + +public: + HYDROGUI_Poly3DDlg( HYDROGUI_Module* theModule, const QString& theTitle ); + virtual ~HYDROGUI_Poly3DDlg(); + + void reset(); + + void setMode( const bool theIsEdit ); + + void setResultName( const QString& theName ); + QString getResultName() const; + + void setSelectedObjects( const QString& theName1, + const QString& theName2 ); + bool getSelectedObjects( QString& theName1, + QString& theName2 ) const; + + void setPreselectedObject( const QString& theName ); + +private: + bool myIsEdit; + + QLineEdit* myName; + + QLabel* myProfileLabel; + HYDROGUI_ObjSelector* myProfile; + + QLabel* myPolylineLabel; + HYDROGUI_ObjSelector* myPolyline; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_Poly3DOp.cxx b/src/HYDROGUI/HYDROGUI_Poly3DOp.cxx new file mode 100644 index 00000000..9be0f751 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Poly3DOp.cxx @@ -0,0 +1,171 @@ +// 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_Poly3DOp.h" + +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_Poly3DDlg.h" +#include "HYDROGUI_UpdateFlags.h" + +#include +#include +#include +#include + +#include + +HYDROGUI_Poly3DOp::HYDROGUI_Poly3DOp( HYDROGUI_Module* theModule, + const bool theIsEdit ) +: HYDROGUI_Operation( theModule ), + myIsEdit( theIsEdit ), + myEditedObject( 0 ) +{ + setName( theIsEdit ? tr( "EDIT_POLYLINE_3D" ) : tr( "CREATE_POLYLINE_3D" ) ); +} + +HYDROGUI_Poly3DOp::~HYDROGUI_Poly3DOp() +{ +} + +HYDROGUI_InputPanel* HYDROGUI_Poly3DOp::createInputPanel() const +{ + return new HYDROGUI_Poly3DDlg( module(), getName() ); +} + +void HYDROGUI_Poly3DOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + HYDROGUI_Poly3DDlg* aPanel = (HYDROGUI_Poly3DDlg*)inputPanel(); + aPanel->reset(); + aPanel->setMode( myIsEdit ); + + QString aPoly3DName; + if( myIsEdit ) + { + myEditedObject = Handle(HYDROData_Polyline3D)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if( !myEditedObject.IsNull() ) + aPoly3DName = myEditedObject->GetName(); + } + else + { + aPoly3DName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "POLYLINE_3D" ) ); + } + aPanel->setResultName( aPoly3DName ); + + QString aSelectedName1, aSelectedName2; + if( myIsEdit && !myEditedObject.IsNull() ) + { + Handle(HYDROData_Entity) anObject1 = myEditedObject->GetProfileUZ()->GetFatherObject(); + if( !anObject1.IsNull() ) + aSelectedName1 = anObject1->GetName(); + Handle(HYDROData_Entity) anObject2 = myEditedObject->GetPolylineXY(); + if( !anObject2.IsNull() ) + aSelectedName2 = anObject2->GetName(); + aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 ); + } + else if( !myIsEdit ) + { + Handle(HYDROData_Profile) aSelectedProfile = + Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if( !aSelectedProfile.IsNull() ) + { + QString aSelectedName = aSelectedProfile->GetName(); + aPanel->setPreselectedObject( aSelectedName ); + } + } +} + +bool HYDROGUI_Poly3DOp::processApply( int& theUpdateFlags, + QString& theErrorMsg ) +{ + HYDROGUI_Poly3DDlg* aPanel = dynamic_cast( inputPanel() ); + + QString aResultName = aPanel->getResultName(); + if( aResultName.isEmpty() ) + return false; + + QString aSelectedName1, aSelectedName2; + if( !aPanel->getSelectedObjects( aSelectedName1, aSelectedName2 ) ) + return false; + + if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aResultName ) ) + { + // check that there are no other objects with the same name in the document + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aResultName ); + if( !anObject.IsNull() ) + { + theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aResultName ); + return false; + } + } + + Handle(HYDROData_Entity) anObject1 = + HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_PROFILE ) ; + Handle(HYDROData_Entity) anObject2 = + HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_POLYLINEXY ); + if( anObject1.IsNull() || anObject2.IsNull() ) + return false; + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( anObject1 ); + Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( anObject2 ); + + if( aProfile.IsNull() || aPolyline.IsNull() ) + return false; + + Handle(HYDROData_ProfileUZ) aProfileUZ = aProfile->GetProfileUZ(); + if( aProfileUZ.IsNull() ) + return false; + + Handle(HYDROData_Polyline3D) aResult; + if( myIsEdit ) + { + aResult = myEditedObject; + aResult->RemoveProfileUZ(); + aResult->RemovePolylineXY(); + } + else + { + aResult = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) ); + } + + if( aResult.IsNull() ) + return false; + + aResult->SetName( aResultName ); + aResult->SetProfileUZ( aProfileUZ ); + aResult->SetPolylineXY( aPolyline ); + + aResult->Update(); + + if( !myIsEdit ) + { + size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); + module()->setObjectVisible( aViewId, anObject1, false ); + module()->setObjectVisible( aViewId, anObject2, false ); + module()->setObjectVisible( aViewId, aResult, true ); + } + + theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced; + return true; +} diff --git a/src/HYDROGUI/HYDROGUI_Poly3DOp.h b/src/HYDROGUI/HYDROGUI_Poly3DOp.h new file mode 100644 index 00000000..572e179a --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Poly3DOp.h @@ -0,0 +1,50 @@ +// 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_POLY3DOP_H +#define HYDROGUI_POLY3DOP_H + +#include "HYDROGUI_Operation.h" + +#include + +class HYDROGUI_Poly3DOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_Poly3DOp( HYDROGUI_Module* theModule, const bool theIsEdit ); + virtual ~HYDROGUI_Poly3DOp(); + +protected: + virtual void startOperation(); + + virtual HYDROGUI_InputPanel* createInputPanel() const; + + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); + +private: + bool myIsEdit; + Handle(HYDROData_Polyline3D) myEditedObject; +}; + +#endif