From: ouv Date: Wed, 11 Sep 2013 06:29:40 +0000 (+0000) Subject: HYDRO feature 3: Crop image (T 1.3) X-Git-Tag: BR_hydro_v_0_1~47 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a51a8a154799a4a022e4f8d5f8547585102e83f7;p=modules%2Fhydro.git HYDRO feature 3: Crop image (T 1.3) --- diff --git a/src/HYDROData/HYDROData_Image.cxx b/src/HYDROData/HYDROData_Image.cxx index 4dcb9e17..88650062 100644 --- a/src/HYDROData/HYDROData_Image.cxx +++ b/src/HYDROData/HYDROData_Image.cxx @@ -17,6 +17,7 @@ #include static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000"); +static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8"); #define PYTHON_IMAGE_ID "1" @@ -91,7 +92,7 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject for ( int i = 0; i < aNbReferences; ++i ) { - Handle(HYDROData_Image) aRefImg = Reference( i ); + Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) ); if ( aRefImg.IsNull() ) continue; @@ -302,7 +303,13 @@ void HYDROData_Image::TrsfPoints(QPoint& thePointAIn, } } -void HYDROData_Image::AppendReference(Handle(HYDROData_Image) theReferenced) +bool HYDROData_Image::HasTrsfPoints() const +{ + Handle(TDataStd_RealArray) anArray; + return myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray); +} + +void HYDROData_Image::AppendReference(Handle(HYDROData_Object) theReferenced) { Handle(TDataStd_ReferenceList) aRefs; if (!myLab.FindAttribute(TDataStd_ReferenceList::GetID(), aRefs)) @@ -318,22 +325,22 @@ int HYDROData_Image::NbReferences() const return aRefs->Extent(); } -Handle(HYDROData_Image) HYDROData_Image::Reference(const int theIndex) const +Handle(HYDROData_Object) HYDROData_Image::Reference(const int theIndex) const { Handle(TDataStd_ReferenceList) aRefs; if (!myLab.FindAttribute(TDataStd_ReferenceList::GetID(), aRefs)) - return Handle(HYDROData_Image)(); + return Handle(HYDROData_Object)(); if (theIndex < 0 || theIndex >= aRefs->Extent()) - return Handle(HYDROData_Image)(); + return Handle(HYDROData_Object)(); TDF_ListIteratorOfLabelList anIter(aRefs->List()); for(int anIndex = 0; anIndex != theIndex; anIter.Next(), anIndex++); const TDF_Label& aRefLab = anIter.Value(); - return Handle(HYDROData_Image)::DownCast(HYDROData_Iterator::Object(aRefLab)); + return Handle(HYDROData_Object)::DownCast(HYDROData_Iterator::Object(aRefLab)); } void HYDROData_Image::ChangeReference( - const int theIndex, Handle(HYDROData_Image) theReferenced) + const int theIndex, Handle(HYDROData_Object) theReferenced) { Handle(TDataStd_ReferenceList) aRefs; if (!myLab.FindAttribute(TDataStd_ReferenceList::GetID(), aRefs)) @@ -415,7 +422,21 @@ void HYDROData_Image::MustBeUpdated(bool theFlag) } } -bool HYDROData_Image::MustBeUpdated() +bool HYDROData_Image::MustBeUpdated() const { return myLab.IsAttribute(GUID_MUST_BE_UPDATED); } + +void HYDROData_Image::SetIsSelfSplitted(bool theFlag) +{ + if (theFlag) { + TDataStd_UAttribute::Set(myLab, GUID_SELF_SPLITTED); + } else { + myLab.ForgetAttribute(GUID_SELF_SPLITTED); + } +} + +bool HYDROData_Image::IsSelfSplitted() const +{ + return myLab.IsAttribute(GUID_SELF_SPLITTED); +} diff --git a/src/HYDROData/HYDROData_Image.h b/src/HYDROData/HYDROData_Image.h index b9db13c6..4966616e 100644 --- a/src/HYDROData/HYDROData_Image.h +++ b/src/HYDROData/HYDROData_Image.h @@ -112,14 +112,16 @@ public: QPointF& thePointBOut, QPointF& thePointCOut) const; + HYDRODATA_EXPORT bool HasTrsfPoints() const; + /** - * Appends reference to other image. - * \param theReferenced the image referenced by this + * Appends reference to other object (image or polyline). + * \param theReferenced the object referenced by this */ - HYDRODATA_EXPORT void AppendReference(Handle(HYDROData_Image) theReferenced); + HYDRODATA_EXPORT void AppendReference(Handle(HYDROData_Object) theReferenced); /** - * Returns the number of referenced images + * Returns the number of referenced objects * \return zero if there is no references */ HYDRODATA_EXPORT int NbReferences() const; @@ -127,18 +129,18 @@ public: /** * Returns reference by index. * \param theIndex number of reference [0; NbReference) - * \returns the referenced image, or Null if index is invalid + * \returns the referenced object, or Null if index is invalid */ - HYDRODATA_EXPORT Handle(HYDROData_Image) Reference(const int theIndex) const; + HYDRODATA_EXPORT Handle(HYDROData_Object) Reference(const int theIndex) const; /** * Updates reference by index. If index is one-bigger than \a NbReferences, * this method appends it to the end (NbReferences is incremented). * \param theIndex number of reference [0; NbReference] - * \param theReferenced the image referenced by this + * \param theReferenced the object referenced by this */ HYDRODATA_EXPORT void ChangeReference( - const int theIndex, Handle(HYDROData_Image) theReferenced); + const int theIndex, Handle(HYDROData_Object) theReferenced); /** * Removes reference by index @@ -185,7 +187,19 @@ public: * Returns the "MustBeUpdated" flag: is image must be recomputed or not * \returns false if image is up to date */ - HYDRODATA_EXPORT bool MustBeUpdated(); + HYDRODATA_EXPORT bool MustBeUpdated() const; + + /** + * Marks the image as self-splitted. + * \param theFlag is true for self-splitted image + */ + HYDRODATA_EXPORT void SetIsSelfSplitted(bool theFlag); + + /** + * Checks that the image is self-splitted. + * \returns true if image is self-splitted + */ + HYDRODATA_EXPORT bool IsSelfSplitted() const; protected: diff --git a/src/HYDROData/HYDROData_Polyline.cxx b/src/HYDROData/HYDROData_Polyline.cxx index 34ebfe25..4360cc15 100755 --- a/src/HYDROData/HYDROData_Polyline.cxx +++ b/src/HYDROData/HYDROData_Polyline.cxx @@ -202,10 +202,10 @@ QPainterPath HYDROData_Polyline::painterPath() { QPainterPath aPath; int aDim = getDimension(); - if( ( aDim != 2 ) || ( aDim != 3) ) + if( ( aDim != 2 ) && ( aDim != 3) ) return aPath; QList aSects = getPolylineData(); - for( int i = 0 ; aSects.size() ; i++ ){ + for( int i = 0 ; i < aSects.size() ; i++ ){ int aPntCnt = aSects[i].myCoords.size()/aDim; if( aPntCnt ){ aPath.moveTo(aSects[i].myCoords[0], aSects[i].myCoords[1] ); diff --git a/src/HYDROData/HYDROOperations_Factory.cxx b/src/HYDROData/HYDROOperations_Factory.cxx index bfbfbdbf..c4fff685 100644 --- a/src/HYDROData/HYDROOperations_Factory.cxx +++ b/src/HYDROData/HYDROOperations_Factory.cxx @@ -81,16 +81,24 @@ void HYDROOperations_Factory::UpdateImage( QTransform aTransform; ImageComposer_Image anImage1; // first referenced image if (theImage->NbReferences()) { - Handle(HYDROData_Image) anImage = theImage->Reference(0); - anImage1 = anImage->Image(); - anImage1.setTransform(anImage->Trsf()); - aTransform = anImage1.transform(); + Handle(HYDROData_Image) anImage = + Handle(HYDROData_Image)::DownCast( theImage->Reference(0) ); + if( !anImage.IsNull() ) + { + anImage1 = anImage->Image(); + anImage1.setTransform(anImage->Trsf()); + aTransform = anImage1.transform(); + } } ImageComposer_Image anImage2; // second referenced image if (theImage->NbReferences() > 1) { - Handle(HYDROData_Image) anImage = theImage->Reference(1); - anImage2 = anImage->Image(); - anImage2.setTransform(anImage->Trsf()); + Handle(HYDROData_Image) anImage = + Handle(HYDROData_Image)::DownCast( theImage->Reference(1) ); + if( !anImage.IsNull() ) + { + anImage2 = anImage->Image(); + anImage2.setTransform(anImage->Trsf()); + } } ImageComposer_Image aResImg = anOp->process(anImage1, anImage2); theImage->SetImage(aResImg); @@ -116,7 +124,9 @@ void HYDROOperations_Factory::SetMustBeUpdatedImages( if (!anImage->MustBeUpdated()) { int a, aNBRefs = anImage->NbReferences(); for(a = 0; a < aNBRefs; a++) { - if (anImage->Reference(a)->MustBeUpdated()) { + Handle(HYDROData_Image) aRefImage = + Handle(HYDROData_Image)::DownCast(anImage->Reference(a)); + if (!aRefImage.IsNull() && aRefImage->MustBeUpdated()) { // image references to updated => also must be updated anImage->MustBeUpdated(true); aChanged = true; diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index 09910953..e72d9488 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -229,9 +229,9 @@ void HYDROGUI_DataModel::update( const int theStudyId ) { for( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ ) { - Handle(HYDROData_Image) aRefImageObj = anImageObj->Reference( anIndex ); - if( !aRefImageObj.IsNull() && !aRefImageObj->IsRemoved() ) - createObject( anImageDataObj, aRefImageObj, anImageDataObj->entry() ); + Handle(HYDROData_Object) aRefObj = anImageObj->Reference( anIndex ); + if( !aRefObj.IsNull() && !aRefObj->IsRemoved() ) + createObject( anImageDataObj, aRefObj, anImageDataObj->entry() ); } } } diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index c436594d..33a57e03 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -35,11 +35,17 @@ #include +#include + #include #include #include #include +#include +#include +#include + #include #include #include @@ -150,7 +156,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsHiddenInSelection = false; bool anIsImage = false; + bool anIsImportedImage = false; bool anIsCompositeImage = false; + bool anIsFusedImage = false; + bool anIsCutImage = false; + bool anIsSplittedImage = false; bool anIsMustBeUpdatedImage = false; bool anIsPolyline = false; bool anIsVisualState = false; @@ -173,7 +183,20 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject ); if( !anImage.IsNull() ) { + anIsImportedImage = anImage->HasTrsfPoints() && !anImage->IsSelfSplitted(); anIsCompositeImage = anImage->NbReferences() > 0; + if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() ) + { + if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) ) + { + if( dynamic_cast( anOperator ) ) + anIsFusedImage = true; + else if( dynamic_cast( anOperator ) ) + anIsCutImage = true; + else if( dynamic_cast( anOperator ) ) + anIsSplittedImage = true; + } + } anIsMustBeUpdatedImage = anImage->MustBeUpdated(); } } @@ -200,7 +223,18 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, { if( anIsImage ) { - theMenu->addAction( action( anIsCompositeImage ? EditCompositeImageId : EditImportedImageId ) ); + if( anIsImportedImage ) + theMenu->addAction( action( EditImportedImageId ) ); + else if( anIsCompositeImage ) + { + if( anIsFusedImage ) + theMenu->addAction( action( EditFusedImageId ) ); + else if( anIsCutImage ) + theMenu->addAction( action( EditCutImageId ) ); + else if( anIsSplittedImage ) + theMenu->addAction( action( EditSplittedImageId ) ); + } + theMenu->addAction( action( ObserveImageId ) ); theMenu->addAction( action( ExportImageId ) ); theMenu->addSeparator(); diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx index 04bd20f0..f97212a0 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx @@ -39,8 +39,12 @@ #include #include -HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule, QWidget* theParent ) -: QAbstractButton( theParent ), myModule( theModule ) +HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule, + const ObjectKind theObjectKind, + QWidget* theParent ) +: QAbstractButton( theParent ), + myObjectKind( theObjectKind ), + myModule( theModule ) { QHBoxLayout* aLayout = new QHBoxLayout( this ); aLayout->setMargin( 0 ); @@ -97,7 +101,8 @@ void HYDROGUI_ObjSelector::OnSelectionChanged() QString anObjName; Handle(HYDROData_Object) anObject = HYDROGUI_Tool::GetSelectedObject( myModule ); if( !anObject.IsNull() ) - anObjName = anObject->GetName(); + if( myObjectKind == KIND_UNKNOWN || myObjectKind == anObject->GetKind() ) + anObjName = anObject->GetName(); SetName( anObjName ); } diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.h b/src/HYDROGUI/HYDROGUI_ObjSelector.h index f3853d74..ba1ff514 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.h +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.h @@ -23,6 +23,8 @@ #ifndef HYDROGUI_OBJSELECTOR_H #define HYDROGUI_OBJSELECTOR_H +#include + #include class QToolButton; @@ -34,7 +36,9 @@ class HYDROGUI_ObjSelector : public QAbstractButton Q_OBJECT public: - HYDROGUI_ObjSelector( HYDROGUI_Module* theModule, QWidget* theParent ); + HYDROGUI_ObjSelector( HYDROGUI_Module* theModule, + const ObjectKind theObjectKind, + QWidget* theParent ); virtual ~HYDROGUI_ObjSelector(); void Clear(); @@ -52,6 +56,8 @@ protected slots: private: HYDROGUI_Module* myModule; + ObjectKind myObjectKind; + QToolButton* myBtn; QLineEdit* myObjName; }; diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index e5e3ea77..5a9529fc 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -72,7 +72,6 @@ void HYDROGUI_Module::createActions() createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I ); createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" ); - createAction( EditCompositeImageId, "EDIT_COMPOSITE_IMAGE" ); createAction( ObserveImageId, "OBSERVE_IMAGE" ); createAction( ExportImageId, "EXPORT_IMAGE" ); createAction( UpdateImageId, "UPDATE_IMAGE" ); @@ -82,8 +81,14 @@ void HYDROGUI_Module::createActions() createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::SHIFT + Qt::Key_I ); - createAction( FuseId, "FUSE_IMAGES" ); - createAction( CutId, "CUT_IMAGES" ); + createAction( FuseImagesId, "FUSE_IMAGES" ); + createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" ); + + createAction( CutImagesId, "CUT_IMAGES" ); + createAction( EditCutImageId, "EDIT_CUT_IMAGE" ); + + createAction( SplitImageId, "SPLIT_IMAGE" ); + createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" ); createAction( DeleteId, "DELETE", "", Qt::Key_Delete ); @@ -110,8 +115,9 @@ void HYDROGUI_Module::createMenus() createMenu( ImportImageId, aHydroId, -1, -1 ); createMenu( ImportBathymetryId, aHydroId, -1, -1 ); createMenu( CreatePolylineId, aHydroId, -1, -1 ); - createMenu( FuseId, aHydroId, -1, -1 ); - createMenu( CutId, aHydroId, -1, -1 ); + createMenu( FuseImagesId, aHydroId, -1, -1 ); + createMenu( CutImagesId, aHydroId, -1, -1 ); + createMenu( SplitImageId, aHydroId, -1, -1 ); } void HYDROGUI_Module::createPopups() @@ -245,17 +251,20 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case EditPolylineId: anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId ); break; - case FuseId: - anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse ); + case ImportBathymetryId: + anOp = new HYDROGUI_ImportBathymetryOp( aModule ); break; - case CutId: - anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut ); + case FuseImagesId: + case EditFusedImageId: + anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId ); break; - case EditCompositeImageId: - anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Edit ); + case CutImagesId: + case EditCutImageId: + anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId ); break; - case ImportBathymetryId: - anOp = new HYDROGUI_ImportBathymetryOp( aModule ); + case SplitImageId: + case EditSplittedImageId: + anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId ); break; case DeleteId: anOp = new HYDROGUI_DeleteOp( aModule ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 01232035..77ddc3f8 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -35,7 +35,6 @@ enum OperationId ImportImageId, EditImportedImageId, - EditCompositeImageId, ObserveImageId, ExportImageId, UpdateImageId, @@ -46,8 +45,15 @@ enum OperationId ImportBathymetryId, EditImportedBathymetryId, - FuseId, - CutId, + FuseImagesId, + EditFusedImageId, + + CutImagesId, + EditCutImageId, + + SplitImageId, + EditSplittedImageId, + DeleteId, ShowId, diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 991dff25..e224ff80 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -342,15 +342,20 @@ void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Image)& theImage for( int anIndex = 0, aNbRef = theImage->NbReferences(); anIndex < aNbRef; anIndex++ ) { - Handle(HYDROData_Image) aRefImage = theImage->Reference( anIndex ); - if( !aRefImage.IsNull() && !aRefImage->IsRemoved() ) + Handle(HYDROData_Object) aRefObj = theImage->Reference( anIndex ); + if( !aRefObj.IsNull() && !aRefObj->IsRemoved() ) { - QString aName = aRefImage->GetName(); + QString aName = aRefObj->GetName(); if( !theRefNames.contains( aName ) ) { - theRefObjects.Append( aRefImage ); - theRefNames.append( aRefImage->GetName() ); - GetObjectReferences( aRefImage, theRefObjects, theRefNames ); + theRefObjects.Append( aRefObj ); + theRefNames.append( aRefObj->GetName() ); + if( aRefObj->GetKind() == KIND_IMAGE ) + { + Handle(HYDROData_Image) aRefImage = Handle(HYDROData_Image)::DownCast( aRefObj ); + if( !aRefImage.IsNull() ) + GetObjectReferences( aRefImage, theRefObjects, theRefNames ); + } } } } diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx index 145db26b..5a80d9e2 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx @@ -25,6 +25,7 @@ #include "HYDROGUI_ColorWidget.h" #include "HYDROGUI_ObjSelector.h" +#include #include #include #include @@ -32,7 +33,9 @@ #include HYDROGUI_TwoImagesDlg::HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QString& theTitle ) -: HYDROGUI_InputPanel( theModule, theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ), + myMode( TwoImages ), + myIsEdit( false ) { // Image name QGroupBox* anImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) ); @@ -40,20 +43,26 @@ HYDROGUI_TwoImagesDlg::HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), anImageNameGroup ); myImageName = new QLineEdit( anImageNameGroup ); - QBoxLayout* anImageNameLayout = new QHBoxLayout( anImageNameGroup ); + myModifySelectedImage = new QCheckBox( tr( "MODIFY_SELECTED_IMAGE" ) ); + + QGridLayout* anImageNameLayout = new QGridLayout( anImageNameGroup ); anImageNameLayout->setMargin( 5 ); anImageNameLayout->setSpacing( 5 ); - anImageNameLayout->addWidget( anImageNameLabel ); - anImageNameLayout->addWidget( myImageName ); + anImageNameLayout->addWidget( anImageNameLabel, 0, 0 ); + anImageNameLayout->addWidget( myImageName, 0, 1 ); + anImageNameLayout->addWidget( myModifySelectedImage, 1, 0, 1, 2 ); - // Image name + // Parameters QGroupBox* aParamGroup = new QGroupBox( tr( "PARAMETERS" ) ); - QLabel* anImage1Label = new QLabel( tr( "IMAGE_1" ), aParamGroup ); - myImage1 = new HYDROGUI_ObjSelector( theModule, aParamGroup ); + myImage1Label = new QLabel( tr( "IMAGE_1" ), aParamGroup ); + myImage1 = new HYDROGUI_ObjSelector( theModule, KIND_IMAGE, aParamGroup ); + + myImage2Label = new QLabel( tr( "IMAGE_2" ), aParamGroup ); + myImage2 = new HYDROGUI_ObjSelector( theModule, KIND_IMAGE, aParamGroup ); - QLabel* anImage2Label = new QLabel( tr( "IMAGE_2" ), aParamGroup ); - myImage2 = new HYDROGUI_ObjSelector( theModule, aParamGroup ); + myPolylineLabel = new QLabel( tr( "POLYLINE" ), aParamGroup ); + myPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINE, aParamGroup ); QFrame* aBackgroundFrame = new QFrame( aParamGroup ); QLabel* aBackgroundLabel = new QLabel( tr( "BACKGROUND" ), aBackgroundFrame ); @@ -73,16 +82,23 @@ HYDROGUI_TwoImagesDlg::HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QGridLayout* aParamLayout = new QGridLayout( aParamGroup ); aParamLayout->setMargin( 5 ); aParamLayout->setSpacing( 5 ); - aParamLayout->addWidget( anImage1Label, 0, 0 ); + aParamLayout->addWidget( myImage1Label, 0, 0 ); aParamLayout->addWidget( myImage1, 0, 1 ); - aParamLayout->addWidget( anImage2Label, 1, 0 ); + aParamLayout->addWidget( myImage2Label, 1, 0 ); aParamLayout->addWidget( myImage2, 1, 1 ); + aParamLayout->addWidget( myPolylineLabel, 1, 0 ); + aParamLayout->addWidget( myPolyline, 1, 1 ); aParamLayout->addWidget( aBackgroundFrame, 2, 0, 1, 2 ); // Common addWidget( anImageNameGroup ); addWidget( aParamGroup ); addStretch(); + + connect( myModifySelectedImage, SIGNAL( toggled( bool ) ), + this, SLOT( onModifySelectedImage( bool ) ) ); + + setMode( myMode, myIsEdit ); } HYDROGUI_TwoImagesDlg::~HYDROGUI_TwoImagesDlg() @@ -92,12 +108,36 @@ HYDROGUI_TwoImagesDlg::~HYDROGUI_TwoImagesDlg() void HYDROGUI_TwoImagesDlg::reset() { myImageName->clear(); + myModifySelectedImage->setChecked( false ); myImage1->Clear(); myImage2->Clear(); + myPolyline->Clear(); myTransparent->setChecked( true ); myColorBox->resetColor(); } +void HYDROGUI_TwoImagesDlg::setMode( const int theMode, const bool theIsEdit ) +{ + myMode = theMode; + myIsEdit = theIsEdit; + + bool anIsTwoImages = myMode == TwoImages; + + myModifySelectedImage->setVisible( !anIsTwoImages && !myIsEdit ); + + myImage1Label->setText( anIsTwoImages ? tr( "IMAGE_1" ) : tr( "IMAGE" ) ); + + myImage2Label->setVisible( anIsTwoImages ); + myImage2->setVisible( anIsTwoImages ); + myPolylineLabel->setVisible( !anIsTwoImages ); + myPolyline->setVisible( !anIsTwoImages ); +} + +bool HYDROGUI_TwoImagesDlg::isModifySelected() const +{ + return myModifySelectedImage->isChecked(); +} + void HYDROGUI_TwoImagesDlg::setImageName( const QString& theName ) { myImageName->setText( theName ); @@ -108,18 +148,24 @@ QString HYDROGUI_TwoImagesDlg::getImageName() const return myImageName->text(); } -void HYDROGUI_TwoImagesDlg::setSelectedImages( const QString& theName1, - const QString& theName2 ) +void HYDROGUI_TwoImagesDlg::setSelectedObjects( const QString& theName1, + const QString& theName2 ) { myImage1->SetName( theName1 ); - myImage2->SetName( theName2 ); + if( myMode == TwoImages ) + myImage2->SetName( theName2 ); + else + myPolyline->SetName( theName2 ); } -bool HYDROGUI_TwoImagesDlg::getSelectedImages( QString& theName1, - QString& theName2 ) const +bool HYDROGUI_TwoImagesDlg::getSelectedObjects( QString& theName1, + QString& theName2 ) const { theName1 = myImage1->GetName(); - theName2 = myImage2->GetName(); + if( myMode == TwoImages ) + theName2 = myImage2->GetName(); + else + theName2 = myPolyline->GetName(); return !theName1.isEmpty() && !theName2.isEmpty(); } @@ -139,3 +185,8 @@ QColor HYDROGUI_TwoImagesDlg::getColor() const aColor = myColorBox->color(); return aColor; } + +void HYDROGUI_TwoImagesDlg::onModifySelectedImage( bool theState ) +{ + myImageName->setEnabled( !theState ); +} diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h index c3c14d82..8ac3bce7 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h @@ -25,6 +25,8 @@ #include "HYDROGUI_InputPanel.h" +class QCheckBox; +class QLabel; class QLineEdit; class QRadioButton; @@ -35,27 +37,49 @@ class HYDROGUI_TwoImagesDlg : public HYDROGUI_InputPanel { Q_OBJECT +public: + enum Mode { TwoImages = 0, ImageAndPolyline }; + public: HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QString& theTitle ); virtual ~HYDROGUI_TwoImagesDlg(); void reset(); + void setMode( const int theMode, const bool theIsEdit ); + + bool isModifySelected() const; + void setImageName( const QString& theName ); QString getImageName() const; - void setSelectedImages( const QString& theName1, - const QString& theName2 ); - bool getSelectedImages( QString& theName1, - QString& theName2 ) const; + void setSelectedObjects( const QString& theName1, + const QString& theName2 ); + bool getSelectedObjects( QString& theName1, + QString& theName2 ) const; void setColor( const QColor& theColor ); QColor getColor() const; +protected slots: + void onModifySelectedImage( bool theState ); + private: + int myMode; + bool myIsEdit; + QLineEdit* myImageName; + QCheckBox* myModifySelectedImage; + + QLabel* myImage1Label; HYDROGUI_ObjSelector* myImage1; + + QLabel* myImage2Label; HYDROGUI_ObjSelector* myImage2; + + QLabel* myPolylineLabel; + HYDROGUI_ObjSelector* myPolyline; + QRadioButton* myTransparent; QRadioButton* myColor; HYDROGUI_ColorWidget* myColorBox; diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index 74deaf71..19baa6a7 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -29,42 +29,28 @@ #include #include +#include #include #include +#include #include -HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType ) +HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, + const int theType, + const bool theIsEdit ) : HYDROGUI_Operation( theModule ), myType( theType ), - myIsEdit( false ), + myIsEdit( theIsEdit ), myEditedObject( 0 ) { - if( myType == Edit ) - { - myIsEdit = true; - myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); - if( !myEditedObject.IsNull() ) - { - if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() ) - { - if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) ) - { - if( dynamic_cast( anOperator ) ) - myType = Fuse; - else if( dynamic_cast( anOperator ) ) - myType = Cut; - } - } - } - } - QString aName; switch( myType ) { - case Fuse: aName = tr( "FUSE" ); break; - case Cut: aName = tr( "CUT" ); break; + case Fuse: aName = theIsEdit ? tr( "EDIT_FUSED_IMAGE" ) : tr( "FUSE_IMAGES" ); break; + case Cut: aName = theIsEdit ? tr( "EDIT_CUT_IMAGE" ) : tr( "CUT_IMAGES" ); break; + case Split: aName = theIsEdit ? tr( "EDIT_SPLITTED_IMAGE" ) : tr( "SPLIT_IMAGE" ); break; default: break; } setName( aName ); @@ -86,14 +72,30 @@ void HYDROGUI_TwoImagesOp::startOperation() HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel(); aPanel->reset(); + if( myType == Fuse || myType == Cut ) + aPanel->setMode( HYDROGUI_TwoImagesDlg::TwoImages, myIsEdit ); + else if( myType == Split ) + aPanel->setMode( HYDROGUI_TwoImagesDlg::ImageAndPolyline, myIsEdit ); + QString anImageName; if( myIsEdit ) { + myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); if( !myEditedObject.IsNull() ) anImageName = myEditedObject->GetName(); } else - anImageName = HYDROGUI_Tool::GenerateObjectName( module(), getName() ); + { + QString aPrefix; + switch( myType ) + { + case Fuse: aPrefix = tr( "FUSE" ); break; + case Cut: aPrefix = tr( "CUT" ); break; + case Split: aPrefix = tr( "SPLIT" ); break; + default: break; + } + anImageName = HYDROGUI_Tool::GenerateObjectName( module(), aPrefix ); + } aPanel->setImageName( anImageName ); QString aSelectedName1, aSelectedName2; @@ -101,17 +103,17 @@ void HYDROGUI_TwoImagesOp::startOperation() { if( myEditedObject->NbReferences() > 0 ) { - Handle(HYDROData_Image) anImage1 = myEditedObject->Reference( 0 ); - if( !anImage1.IsNull() ) - aSelectedName1 = anImage1->GetName(); + Handle(HYDROData_Object) anObject1 = myEditedObject->Reference( 0 ); + if( !anObject1.IsNull() ) + aSelectedName1 = anObject1->GetName(); } if( myEditedObject->NbReferences() > 1 ) { - Handle(HYDROData_Image) anImage2 = myEditedObject->Reference( 1 ); - if( !anImage2.IsNull() ) - aSelectedName2 = anImage2->GetName(); + Handle(HYDROData_Object) anObject2 = myEditedObject->Reference( 1 ); + if( !anObject2.IsNull() ) + aSelectedName2 = anObject2->GetName(); } - aPanel->setSelectedImages( aSelectedName1, aSelectedName2 ); + aPanel->setSelectedObjects( aSelectedName1, aSelectedName2 ); HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory(); if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) ) @@ -128,15 +130,18 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, { HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast( inputPanel() ); + bool anIsModifySelected = myType == Split && aPanel->isModifySelected(); + QString anImageName = aPanel->getImageName(); - if( anImageName.isEmpty() ) + if( !anIsModifySelected && anImageName.isEmpty() ) return false; QString aSelectedName1, aSelectedName2; - if( !aPanel->getSelectedImages( aSelectedName1, aSelectedName2 ) ) + if( !aPanel->getSelectedObjects( aSelectedName1, aSelectedName2 ) ) return false; - if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) + if( !anIsModifySelected && + ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) ) ) { // check that there are no other objects with the same name in the document Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName ); @@ -147,11 +152,11 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, } } - Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_IMAGE ) ); - Handle(HYDROData_Image) anImage2 = Handle(HYDROData_Image)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_IMAGE ) ); - if( anImage1.IsNull() || anImage2.IsNull() ) + Handle(HYDROData_Object) anObject1 = Handle(HYDROData_Object)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_UNKNOWN ) ); + Handle(HYDROData_Object) anObject2 = Handle(HYDROData_Object)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_UNKNOWN ) ); + if( anObject1.IsNull() || anObject2.IsNull() ) return false; HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory(); @@ -168,6 +173,7 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, { case Fuse: anOperator = new ImageComposer_FuseOperator(); break; case Cut: anOperator = new ImageComposer_CutOperator(); break; + case Split: anOperator = new ImageComposer_CropOperator(); break; default: break; } @@ -181,22 +187,45 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, return false; aResult->SetName( anImageName ); - aResult->AppendReference( anImage1 ); - aResult->AppendReference( anImage2 ); + aResult->AppendReference( anObject1 ); + aResult->AppendReference( anObject2 ); + // Setting the operator arguments (probably, it should be done somewhere else). + // For Fuse and Cut operators: setting background color. + // For Crop operator: setting background color and polyline path to crop. if( ImageComposer_Operator* anOperator = aFactory->Operator( aResult ) ) { - anOperator->setArgs( aPanel->getColor() ); + if( ImageComposer_CropOperator* aCropOperator = + dynamic_cast( anOperator ) ) + { + Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( anObject2 ); + if( !aPolyline.IsNull() ) + aCropOperator->setArgs( aPanel->getColor(), aPolyline->painterPath() ); + } + else + anOperator->setArgs( aPanel->getColor() ); aResult->SetArgs( anOperator->getBinArgs() ); } aFactory->UpdateImage( doc(), aResult ); - if( !myIsEdit ) + if( anIsModifySelected ) + { + Handle(HYDROData_Image) aSelectedImage = Handle(HYDROData_Image)::DownCast( anObject1 ); + if( !aSelectedImage.IsNull() ) + { + aSelectedImage->SetIsSelfSplitted( true ); + aSelectedImage->SetImage( aResult->Image() ); + aSelectedImage->SetTrsf( aResult->Trsf() ); + aResult->Remove(); + } + } + + if( !myIsEdit && !anIsModifySelected ) { size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); - module()->setObjectVisible( aViewId, anImage1, false ); - module()->setObjectVisible( aViewId, anImage2, false ); + module()->setObjectVisible( aViewId, anObject1, false ); + module()->setObjectVisible( aViewId, anObject2, false ); module()->setObjectVisible( aViewId, aResult, true ); } diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h index d537f4c6..83ef1de9 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h @@ -32,10 +32,10 @@ class HYDROGUI_TwoImagesOp : public HYDROGUI_Operation Q_OBJECT public: - enum OperationType { Fuse, Cut, Edit }; + enum OperationType { Fuse, Cut, Split }; public: - HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType ); + HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType, const bool theIsEdit ); virtual ~HYDROGUI_TwoImagesOp(); protected: diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 4ebc6382..64a96777 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -228,8 +228,12 @@ file cannot be correctly imported for a Bathymetry definition. Delete - DSK_EDIT_COMPOSITE_IMAGE - Edit composite image + DSK_EDIT_CUT_IMAGE + Edit cut image + + + DSK_EDIT_FUSED_IMAGE + Edit fused image DSK_EDIT_IMPORTED_IMAGE @@ -239,6 +243,10 @@ file cannot be correctly imported for a Bathymetry definition. DSK_EDIT_POLYLINE Edit polyline + + DSK_EDIT_SPLITTED_IMAGE + Edit splitted image + DSK_EXPORT_IMAGE Export image @@ -291,6 +299,10 @@ file cannot be correctly imported for a Bathymetry definition. DSK_SHOW_ONLY Show only + + DSK_SPLIT_IMAGE + Split image + DSK_UNDO Undo @@ -320,8 +332,12 @@ file cannot be correctly imported for a Bathymetry definition. HYDRO - MEN_EDIT_COMPOSITE_IMAGE - Edit composite image + MEN_EDIT_CUT_IMAGE + Edit cut image + + + MEN_EDIT_FUSED_IMAGE + Edit fused image MEN_EDIT_IMPORTED_IMAGE @@ -331,6 +347,10 @@ file cannot be correctly imported for a Bathymetry definition. MEN_EDIT_POLYLINE Create polyline + + MEN_EDIT_SPLITTED_IMAGE + Edit splitted image + MEN_EXPORT_IMAGE Export image @@ -383,6 +403,10 @@ file cannot be correctly imported for a Bathymetry definition. MEN_SHOW_ONLY Show only + + MEN_SPLIT_IMAGE + Split image + MEN_UNDO Undo @@ -404,8 +428,12 @@ file cannot be correctly imported for a Bathymetry definition. Delete - STB_EDIT_COMPOSITE_IMAGE - Edit composite image + STB_EDIT_CUT_IMAGE + Edit cut image + + + STB_EDIT_FUSED_IMAGE + Edit fused image STB_EDIT_IMPORTED_IMAGE @@ -415,6 +443,10 @@ file cannot be correctly imported for a Bathymetry definition. STB_EDIT_POLYLINE Edit polyline + + STB_EDIT_SPLITTED_IMAGE + Edit splitted image + STB_EXPORT_IMAGE Export image @@ -467,6 +499,10 @@ file cannot be correctly imported for a Bathymetry definition. STB_SHOW_ONLY Show only + + STB_SPLIT_IMAGE + Split image + STB_UNDO Undo @@ -539,6 +575,10 @@ file cannot be correctly imported for a Bathymetry definition. COLOR Color + + IMAGE + Image + IMAGE_1 Image 1 @@ -551,6 +591,10 @@ file cannot be correctly imported for a Bathymetry definition. IMAGE_NAME Image name + + MODIFY_SELECTED_IMAGE + Modify selected image + NAME Name @@ -559,6 +603,10 @@ file cannot be correctly imported for a Bathymetry definition. PARAMETERS Parameters + + POLYLINE + Polyline + TRANSPARENT Transparent @@ -571,10 +619,38 @@ file cannot be correctly imported for a Bathymetry definition. CUT Cut + + CUT_IMAGES + Cut images + + + EDIT_CUT_IMAGE + Edit cut image + + + EDIT_FUSED_IMAGE + Edit fused image + + + EDIT_SPLITTED_IMAGE + Edit splitted image + FUSE Fuse + + FUSE_IMAGES + Fuse images + + + SPLIT + Split + + + SPLIT_IMAGE + Split image +