From 38afdfd781e77ef1d5135bed210c8ebd4b60f34f Mon Sep 17 00:00:00 2001 From: adv Date: Wed, 18 Sep 2013 11:38:17 +0000 Subject: [PATCH] GUI part for zones. Preview for zone is done in 2D view. (Feature #31) --- src/HYDROData/HYDROData_Iterator.cxx | 4 + src/HYDROData/HYDROData_Object.cxx | 48 ++- src/HYDROData/HYDROData_Object.h | 16 + src/HYDROData/HYDROData_Zone.cxx | 40 +-- src/HYDROData/HYDROData_Zone.h | 36 ++- src/HYDROGUI/HYDROGUI.vcproj | 64 +++- src/HYDROGUI/HYDROGUI_DataModel.cxx | 89 +++++- src/HYDROGUI/HYDROGUI_DataModel.h | 21 +- src/HYDROGUI/HYDROGUI_DataObject.cxx | 12 +- src/HYDROGUI/HYDROGUI_DataObject.h | 4 +- src/HYDROGUI/HYDROGUI_Displayer.cxx | 10 +- src/HYDROGUI/HYDROGUI_Module.cxx | 13 +- src/HYDROGUI/HYDROGUI_Module.h | 5 +- src/HYDROGUI/HYDROGUI_Operations.cxx | 9 + src/HYDROGUI/HYDROGUI_Operations.h | 3 + src/HYDROGUI/HYDROGUI_PrsZone.cxx | 166 ++++++++++ src/HYDROGUI/HYDROGUI_PrsZone.h | 71 +++++ src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx | 65 ++++ src/HYDROGUI/HYDROGUI_PrsZoneDriver.h | 56 ++++ src/HYDROGUI/HYDROGUI_Tool.cxx | 8 + src/HYDROGUI/HYDROGUI_ZoneDlg.cxx | 297 ++++++++++++++++++ src/HYDROGUI/HYDROGUI_ZoneDlg.h | 85 ++++++ src/HYDROGUI/HYDROGUI_ZoneOp.cxx | 350 ++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_ZoneOp.h | 75 +++++ src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 90 +++++- 25 files changed, 1576 insertions(+), 61 deletions(-) create mode 100644 src/HYDROGUI/HYDROGUI_PrsZone.cxx create mode 100644 src/HYDROGUI/HYDROGUI_PrsZone.h create mode 100644 src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx create mode 100644 src/HYDROGUI/HYDROGUI_PrsZoneDriver.h create mode 100644 src/HYDROGUI/HYDROGUI_ZoneDlg.cxx create mode 100644 src/HYDROGUI/HYDROGUI_ZoneDlg.h create mode 100644 src/HYDROGUI/HYDROGUI_ZoneOp.cxx create mode 100644 src/HYDROGUI/HYDROGUI_ZoneOp.h diff --git a/src/HYDROData/HYDROData_Iterator.cxx b/src/HYDROData/HYDROData_Iterator.cxx index 2a3d2a77..401b54d4 100644 --- a/src/HYDROData/HYDROData_Iterator.cxx +++ b/src/HYDROData/HYDROData_Iterator.cxx @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -72,6 +73,9 @@ Handle_HYDROData_Object HYDROData_Iterator::Object( const TDF_Label theLabel ) case KIND_CALCULATION: aResult = new HYDROData_Calculation(); break; + case KIND_ZONE: + aResult = new HYDROData_Zone(); + break; } if ( !aResult.IsNull() ) diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index 1be3985a..062be0df 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -145,7 +146,10 @@ void HYDROData_Object::SetReferenceObject( const Handle_HYDROData_Object& theObj const int theIndex ) { if ( theObj.IsNull() ) + { + RemoveReferenceObject( theTag, theIndex ); return; + } Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true ); @@ -226,11 +230,15 @@ void HYDROData_Object::RemoveReferenceObject( const int theTag, return; } - Handle(HYDROData_Object) aRemovedObj = GetReferenceObject( theTag, theIndex ); - if ( aRemovedObj.IsNull() ) + int anIndex = 0; + TDF_ListIteratorOfLabelList anIter( aRefs->List() ); + for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex ); + + if ( anIndex != theIndex ) return; - aRefs->Remove( aRemovedObj->Label() ); + const TDF_Label& aRefLabel = anIter.Value(); + aRefs->Remove( aRefLabel ); } void HYDROData_Object::ClearReferenceObjects( const int theTag ) @@ -250,3 +258,37 @@ Handle(TDataStd_ReferenceList) HYDROData_Object::getReferenceList( const int the return aRefs; } + +void HYDROData_Object::SetColor( const QColor& theColor, + const int theTag ) +{ + TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); + + Handle(TDataStd_IntegerArray) aColorArray; + if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) + aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 ); + + aColorArray->SetValue( 1, theColor.red() ); + aColorArray->SetValue( 2, theColor.green() ); + aColorArray->SetValue( 3, theColor.blue() ); + aColorArray->SetValue( 4, theColor.alpha() ); +} + +QColor HYDROData_Object::GetColor( const QColor& theDefColor, + const int theTag ) const +{ + QColor aResColor = theDefColor; + + TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag ); + + Handle(TDataStd_IntegerArray) aColorArray; + if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) + { + aResColor.setRed( aColorArray->Value( 1 ) ); + aResColor.setGreen( aColorArray->Value( 2 ) ); + aResColor.setBlue( aColorArray->Value( 3 ) ); + aResColor.setAlpha( aColorArray->Value( 4 ) ); + } + + return aResColor; +} \ No newline at end of file diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index 5d43cdde..a44ffdb5 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -7,6 +7,7 @@ #include #include +class QColor; class QString; class QVariant; class QStringList; @@ -213,11 +214,26 @@ protected: */ void ClearReferenceObjects( const int theTag = 0 ); + /** + * Internal method that used to store the color attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theColor color to save + */ + void SetColor( const QColor& theColor, const int theTag = 0 ); + + /** + * Internal method that used to retreive the color attribute + * \param theTag tag of a label that keeps the attribute (for 0 this is myLab) + * \param theDefColor default color to return if attribute has not been set before + */ + QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const; + protected: Handle(TDataStd_ReferenceList) getReferenceList( const int theTag, const bool theIsCreate ) const; + protected: /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty. TDF_Label myLab; ///< label of this object diff --git a/src/HYDROData/HYDROData_Zone.cxx b/src/HYDROData/HYDROData_Zone.cxx index f8723453..fa2c0e16 100644 --- a/src/HYDROData/HYDROData_Zone.cxx +++ b/src/HYDROData/HYDROData_Zone.cxx @@ -35,32 +35,34 @@ QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects return aResList; } -void HYDROData_Zone::SetColor( const QColor& theColor ) +QColor HYDROData_Zone::DefaultFillingColor() { - Handle(TDataStd_IntegerArray) aColorArray; - if ( !myLab.FindChild( DataTag_Color ).FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) - aColorArray = TDataStd_IntegerArray::Set( myLab.FindChild( DataTag_Color ), 1, 4 ); + return QColor( Qt::green ); +} - aColorArray->SetValue( 1, theColor.red() ); - aColorArray->SetValue( 2, theColor.green() ); - aColorArray->SetValue( 3, theColor.blue() ); - aColorArray->SetValue( 4, theColor.alpha() ); +void HYDROData_Zone::SetFillingColor( const QColor& theColor ) +{ + return SetColor( theColor, DataTag_FillingColor ); } -QColor HYDROData_Zone::GetColor() const +QColor HYDROData_Zone::GetFillingColor() const { - QColor aResColor( Qt::green ); + return GetColor( DefaultFillingColor(), DataTag_FillingColor ); +} - Handle(TDataStd_IntegerArray) aColorArray; - if ( myLab.FindChild( DataTag_Color ).FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) ) - { - aResColor.setRed( aColorArray->Value( 1 ) ); - aResColor.setGreen( aColorArray->Value( 2 ) ); - aResColor.setBlue( aColorArray->Value( 3 ) ); - aResColor.setAlpha( aColorArray->Value( 4 ) ); - } +QColor HYDROData_Zone::DefaultBorderColor() +{ + return QColor( Qt::transparent ); +} - return aResColor; +void HYDROData_Zone::SetBorderColor( const QColor& theColor ) +{ + return SetColor( theColor, DataTag_BorderColor ); +} + +QColor HYDROData_Zone::GetBorderColor() const +{ + return GetColor( DefaultBorderColor(), DataTag_BorderColor ); } void HYDROData_Zone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline ) diff --git a/src/HYDROData/HYDROData_Zone.h b/src/HYDROData/HYDROData_Zone.h index e9ad3ba9..5b277a13 100644 --- a/src/HYDROData/HYDROData_Zone.h +++ b/src/HYDROData/HYDROData_Zone.h @@ -27,9 +27,10 @@ protected: enum DataTag { DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve - DataTag_Bathymetry, ///< reference bathymetries - DataTag_Polyline, ///< reference polyline - DataTag_Color ///< color of zone + DataTag_Bathymetry, ///< reference bathymetries + DataTag_Polyline, ///< reference polyline + DataTag_FillingColor, ///< filling color of zone + DataTag_BorderColor, ///< border color of zone }; public: @@ -47,14 +48,35 @@ public: /** - * Sets color for zone. + * Returns default filling color for new zone. */ - HYDRODATA_EXPORT virtual void SetColor( const QColor& theColor ); + HYDRODATA_EXPORT static QColor DefaultFillingColor(); /** - * Returns color of zone. + * Sets filling color for zone. */ - HYDRODATA_EXPORT virtual QColor GetColor() const; + HYDRODATA_EXPORT virtual void SetFillingColor( const QColor& theColor ); + + /** + * Returns filling color of zone. + */ + HYDRODATA_EXPORT virtual QColor GetFillingColor() const; + + + /** + * Returns default border color for new zone. + */ + HYDRODATA_EXPORT static QColor DefaultBorderColor(); + + /** + * Sets border color for zone. + */ + HYDRODATA_EXPORT virtual void SetBorderColor( const QColor& theColor ); + + /** + * Returns border color of zone. + */ + HYDRODATA_EXPORT virtual QColor GetBorderColor() const; /** diff --git a/src/HYDROGUI/HYDROGUI.vcproj b/src/HYDROGUI/HYDROGUI.vcproj index 50be70ba..3a6362ad 100644 --- a/src/HYDROGUI/HYDROGUI.vcproj +++ b/src/HYDROGUI/HYDROGUI.vcproj @@ -1,7 +1,7 @@ + + + + @@ -270,6 +278,14 @@ RelativePath=".\HYDROGUI_VisualStateOp.cxx" > + + + + @@ -354,7 +370,7 @@ @@ -609,6 +625,14 @@ RelativePath=".\HYDROGUI_PrsPolylineDriver.h" > + + + + @@ -687,6 +711,34 @@ /> + + + + + + + + + + + + + + diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index 392dfef5..c7b0cedf 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -227,17 +228,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() ); if( !anImageObj.IsNull() ) - { - if( LightApp_DataObject* anImageDataObj = createObject( anImageRootObj, anImageObj ) ) - { - for( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ ) - { - Handle(HYDROData_Object) aRefObj = anImageObj->Reference( anIndex ); - if( !aRefObj.IsNull() && !aRefObj->IsRemoved() ) - createObject( anImageDataObj, aRefObj, anImageDataObj->entry() ); - } - } - } + createObject( anImageRootObj, anImageObj ); } LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, partitionName( KIND_BATHYMETRY ) ); @@ -273,6 +264,17 @@ void HYDROGUI_DataModel::update( const int theStudyId ) createObject( aPolylineRootObj, aPolylineObj ); } + LightApp_DataObject* aZonesRootObj = createObject( aRootObj, partitionName( KIND_ZONE ) ); + + anIterator = HYDROData_Iterator( aDocument, KIND_ZONE ); + for( ; anIterator.More(); anIterator.Next() ) + { + Handle(HYDROData_Zone) aZoneObj = + Handle(HYDROData_Zone)::DownCast( anIterator.Current() ); + if( !aZoneObj.IsNull() ) + createObject( aZonesRootObj, aZoneObj ); + } + LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, partitionName( KIND_VISUAL_STATE ) ); anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE ); @@ -506,6 +508,7 @@ QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind ) case KIND_VISUAL_STATE: return "VISUAL_STATES"; case KIND_BATHYMETRY: return "BATHYMETRIES"; case KIND_CALCULATION: return "CALCULATION_CASES"; + case KIND_ZONE: return "ZONES"; default: break; } return QString(); @@ -517,17 +520,71 @@ Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const return HYDROData_Document::Document( aStudyId ); } -LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, +LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, Handle(HYDROData_Object) theModelObject, - const QString& theParentEntry ) + const QString& theParentEntry ) { - return new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); + HYDROGUI_DataObject* aResObj = + new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); + buildObjectTree( theParent, aResObj, theParentEntry ); + return aResObj; } LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, - const QString& theName ) + const QString& theName, + const QString& theParentEntry ) +{ + return new HYDROGUI_NamedObject( theParent, theName, theParentEntry ); +} + +void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, + SUIT_DataObject* theObject, + const QString& theParentEntry ) { - return new HYDROGUI_NamedObject( theParent, theName ); + HYDROGUI_DataObject* aGuiObj = dynamic_cast( theObject ); + if ( !aGuiObj ) + return; + + Handle(HYDROData_Object) aDataObj = aGuiObj->modelObject(); + if ( aDataObj.IsNull() ) + return; + + ObjectKind anObjectKind = aDataObj->GetKind(); + + if ( anObjectKind == KIND_IMAGE ) + { + Handle(HYDROData_Image) anImageObj = + Handle(HYDROData_Image)::DownCast( aDataObj ); + for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ ) + { + Handle(HYDROData_Object) aRefObj = anImageObj->Reference( anIndex ); + if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() ) + createObject( aGuiObj, aRefObj, aGuiObj->entry() ); + } + } + else if ( anObjectKind == KIND_ZONE ) + { + Handle(HYDROData_Zone) aZoneObj = + Handle(HYDROData_Zone)::DownCast( aDataObj ); + + LightApp_DataObject* aPolylineSect = createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() ); + + Handle(HYDROData_Polyline) aPolyline = aZoneObj->GetPolyline(); + if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() ) + createObject( aPolylineSect, aPolyline, aGuiObj->entry() ); + + LightApp_DataObject* aBathsSect = createObject( aGuiObj, tr( "ZONE_BATHYMETRIES" ), aGuiObj->entry() ); + + HYDROData_SequenceOfObjects aZoneBaths = aZoneObj->GetBathymetries(); + HYDROData_SequenceOfObjects::Iterator aBathsIter( aZoneBaths ); + for ( ; aBathsIter.More(); aBathsIter.Next() ) + { + Handle(HYDROData_Bathymetry) aRefBath = + Handle(HYDROData_Bathymetry)::DownCast( aBathsIter.Value() ); + if( !aRefBath.IsNull() && !aRefBath->IsRemoved() ) + createObject( aBathsSect, aRefBath, aGuiObj->entry() ); + } + } } void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent, diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 3576a1a0..a4216902 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -231,19 +231,32 @@ protected: /** * Creates the GUI data object according to the model object. * \param theParent a created object will be appended as a child of this object - * \param theObject model object + * \param theModelObject model object + * \param theParentEntry entry of parent object */ - LightApp_DataObject* createObject( SUIT_DataObject* theParent, + LightApp_DataObject* createObject( SUIT_DataObject* theParent, Handle(HYDROData_Object) theModelObject, - const QString& theParentEntry = QString() ); + const QString& theParentEntry = QString() ); /** * Creates the GUI data object without corresponding model object: just by name * \param theParent a created object will be appended as a child of this object * \param theName name of this object + * \param theParentEntry entry of parent object */ LightApp_DataObject* createObject( SUIT_DataObject* theParent, - const QString& theName ); + const QString& theName, + const QString& theParentEntry = QString() ); + + /** + * Build tree of model object. + * \param theParent a created object will be appended as a child of this object + * \param theObject gui object for which the tree will be build + * \param theParentEntry entry of parent object + */ + void buildObjectTree( SUIT_DataObject* theParent, + SUIT_DataObject* theObject, + const QString& theParentEntry = QString() ); /** * Removes data object from the tree. diff --git a/src/HYDROGUI/HYDROGUI_DataObject.cxx b/src/HYDROGUI/HYDROGUI_DataObject.cxx index bbd53f6b..f0b47e22 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.cxx +++ b/src/HYDROGUI/HYDROGUI_DataObject.cxx @@ -85,17 +85,21 @@ QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Object)& th } HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent, - const QString& theName ) + const QString& theName, + const QString& theParentEntry ) : CAM_DataObject( theParent ), LightApp_DataObject( theParent ), - myName( theName ) + myName( theName ), + myParentEntry( theParentEntry ) { } QString HYDROGUI_NamedObject::entry() const { - //return LightApp_DataObject::entry(); - return HYDROGUI_DataObject::entryPrefix() + name(); + QString anEntry = HYDROGUI_DataObject::entryPrefix() + name(); + if( !myParentEntry.isEmpty() ) + anEntry.prepend( myParentEntry + "_" ); + return anEntry; } QString HYDROGUI_NamedObject::name() const diff --git a/src/HYDROGUI/HYDROGUI_DataObject.h b/src/HYDROGUI/HYDROGUI_DataObject.h index baa09573..edb79f02 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.h +++ b/src/HYDROGUI/HYDROGUI_DataObject.h @@ -116,7 +116,8 @@ public: * \param theName displayed name */ HYDROGUI_NamedObject( SUIT_DataObject* theParent, - const QString& theName ); + const QString& theName, + const QString& theParentEntry ); /** * Returns the unique object identifier string. @@ -130,6 +131,7 @@ public: private: QString myName; ///< name in the OB + QString myParentEntry; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index d979bfbe..7f91a6a9 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -27,6 +27,7 @@ #include "HYDROGUI_Prs.h" #include "HYDROGUI_PrsImageDriver.h" #include "HYDROGUI_PrsPolylineDriver.h" +#include "HYDROGUI_PrsZoneDriver.h" #include "HYDROGUI_Tool.h" #include @@ -236,15 +237,20 @@ HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Object { case KIND_IMAGE: aDriver = new HYDROGUI_PrsImageDriver(); - myPrsDriversMap[ aKind ] = aDriver; break; case KIND_POLYLINE: aDriver = new HYDROGUI_PrsPolylineDriver(); - myPrsDriversMap[ aKind ] = aDriver; + break; + case KIND_ZONE: + aDriver = new HYDROGUI_PrsZoneDriver(); break; default: break; } + + if ( aDriver ) + myPrsDriversMap[ aKind ] = aDriver; } + return aDriver; } diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 6ce7fa53..b6d25267 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -193,6 +193,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsMustBeUpdatedImage = false; bool anIsPolyline = false; bool anIsCalculation = false; + bool anIsZone = false; bool anIsVisualState = false; // check the selected data model objects @@ -236,6 +237,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, anIsPolyline = true; else if( anObject->GetKind() == KIND_CALCULATION ) anIsCalculation = true; + else if( anObject->GetKind() == KIND_ZONE ) + anIsZone = true; else if( anObject->GetKind() == KIND_VISUAL_STATE ) anIsVisualState = true; } @@ -264,6 +267,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, case KIND_CALCULATION: theMenu->addAction( action( CreateCalculationId ) ); break; + case KIND_ZONE: + theMenu->addAction( action( CreateZoneId ) ); + break; } theMenu->addSeparator(); } @@ -310,6 +316,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( EditCalculationId ) ); theMenu->addSeparator(); } + else if( anIsZone ) + { + theMenu->addAction( action( EditZoneId ) ); + theMenu->addSeparator(); + } else if( anIsVisualState && anIsObjectBrowser ) { theMenu->addAction( action( SaveVisualStateId ) ); @@ -324,7 +335,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addSeparator(); } - if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline ) ) + if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline || anIsZone ) ) { if( anIsHiddenInSelection ) theMenu->addAction( action( ShowId ) ); diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 0e637e5f..453b9e47 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -48,7 +48,10 @@ class HYDROGUI_Module : public LightApp_Module enum CustomEvent { NewViewEvent = QEvent::User + 100 }; public: - enum ViewManagerRole { VMR_Unknown = 0, VMR_General, VMR_TransformImage, VMR_ObserveImage }; + + enum ViewManagerRole { VMR_Unknown = 0, VMR_General, + VMR_TransformImage, VMR_ObserveImage, + VMR_PreviewZone }; typedef QPair< SUIT_ViewManager*, ViewManagerRole > ViewManagerInfo; typedef QMap < int, ViewManagerInfo > ViewManagerMap; diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 544d124d..87428aa3 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -37,6 +37,7 @@ #include "HYDROGUI_UpdateFlags.h" #include "HYDROGUI_UpdateImageOp.h" #include "HYDROGUI_VisualStateOp.h" +#include "HYDROGUI_ZoneOp.h" #include @@ -86,6 +87,9 @@ void HYDROGUI_Module::createActions() createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B ); + createAction( CreateZoneId, "CREATE_ZONE" ); + createAction( EditZoneId, "EDIT_ZONE" ); + createAction( CreateCalculationId, "CREATE_CALCULATION" ); createAction( EditCalculationId, "EDIT_CALCULATION" ); @@ -126,6 +130,7 @@ void HYDROGUI_Module::createMenus() createMenu( ImportImageId, aHydroId, -1, -1 ); createMenu( ImportBathymetryId, aHydroId, -1, -1 ); createMenu( CreatePolylineId, aHydroId, -1, -1 ); + createMenu( CreateZoneId, aHydroId, -1, -1 ); createMenu( CreateCalculationId, aHydroId, -1, -1 ); createMenu( separator(), aHydroId ); createMenu( FuseImagesId, aHydroId, -1, -1 ); @@ -271,6 +276,10 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case ImportBathymetryId: anOp = new HYDROGUI_ImportBathymetryOp( aModule ); break; + case CreateZoneId: + case EditZoneId: + anOp = new HYDROGUI_ZoneOp( aModule, theId == EditZoneId ); + 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 92f9869f..c8b8309f 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -48,6 +48,9 @@ enum OperationId ImportBathymetryId, EditImportedBathymetryId, + CreateZoneId, + EditZoneId, + CreateCalculationId, EditCalculationId, diff --git a/src/HYDROGUI/HYDROGUI_PrsZone.cxx b/src/HYDROGUI/HYDROGUI_PrsZone.cxx new file mode 100644 index 00000000..3dafc9a2 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PrsZone.cxx @@ -0,0 +1,166 @@ +// 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_PrsZone.h" + +#include +#include + +//======================================================================= +// name : HYDROGUI_PrsZone +// Purpose : Constructor +//======================================================================= +HYDROGUI_PrsZone::HYDROGUI_PrsZone( const Handle(HYDROData_Object)& theObject ) +: HYDROGUI_Prs( theObject ), + myZoneItem( 0 ), + myFillingColor( Qt::transparent ), + myBorderColor( Qt::transparent ) +{ +} + +//======================================================================= +// name : HYDROGUI_PrsZone +// Purpose : Destructor +//======================================================================= +HYDROGUI_PrsZone::~HYDROGUI_PrsZone() +{ +} + +//================================================================ +// Function : setPath +// Purpose : +//================================================================ +void HYDROGUI_PrsZone::setPath( const QPainterPath& thePath ) +{ + myPath = thePath; +} + +//================================================================ +// Function : getPath +// Purpose : +//================================================================ +QPainterPath HYDROGUI_PrsZone::getPath() const +{ + return myPath; +} + +//================================================================ +// Function : setFillingColor +// Purpose : +//================================================================ +void HYDROGUI_PrsZone::setFillingColor( const QColor& theColor ) +{ + myFillingColor = theColor; +} + +//================================================================ +// Function : getFillingColor +// Purpose : +//================================================================ +QColor HYDROGUI_PrsZone::getFillingColor() const +{ + return myFillingColor; +} + +//================================================================ +// Function : setBorderColor +// Purpose : +//================================================================ +void HYDROGUI_PrsZone::setBorderColor( const QColor& theColor ) +{ + myBorderColor = theColor; +} + +//================================================================ +// Function : getBorderColor +// Purpose : +//================================================================ +QColor HYDROGUI_PrsZone::getBorderColor() const +{ + return myBorderColor; +} + +//================================================================ +// Function : boundingRect +// Purpose : +//================================================================ +QRectF HYDROGUI_PrsZone::boundingRect() const +{ + return myZoneItem->boundingRect(); +} + +//================================================================ +// Function : compute +// Purpose : +//================================================================ +void HYDROGUI_PrsZone::compute() +{ + if( !myZoneItem ) + { + myZoneItem = new QGraphicsPathItem( this ); + addToGroup( myZoneItem ); + } + + QPainterPath aPath( myPath ); + aPath.setFillRule( Qt::WindingFill ); + + myZoneItem->setPath( aPath ); + myZoneItem->setBrush( QBrush( myFillingColor ) ); + myZoneItem->setPen( QPen( myBorderColor ) ); +} + +//================================================================ +// Function : checkHighlight +// Purpose : +//================================================================ +bool HYDROGUI_PrsZone::checkHighlight( double theX, double theY, QCursor& theCursor ) const +{ + // to do + return false; +} + +//================================================================ +// Function : select +// Purpose : +//================================================================ +bool HYDROGUI_PrsZone::select( double theX, double theY, const QRectF& theRect ) +{ + return GraphicsView_Object::select( theX, theY, theRect ); +} + +//================================================================ +// Function : unselect +// Purpose : +//================================================================ +void HYDROGUI_PrsZone::unselect() +{ + GraphicsView_Object::unselect(); +} + +//================================================================ +// Function : setSelected +// Purpose : +//================================================================ +void HYDROGUI_PrsZone::setSelected( bool theState ) +{ + GraphicsView_Object::setSelected( theState ); +} diff --git a/src/HYDROGUI/HYDROGUI_PrsZone.h b/src/HYDROGUI/HYDROGUI_PrsZone.h new file mode 100644 index 00000000..3c21dc39 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PrsZone.h @@ -0,0 +1,71 @@ +// 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_PRSZONE_H +#define HYDROGUI_PRSZONE_H + +#include "HYDROGUI_Prs.h" + +/* + Class : HYDROGUI_PrsZone + Description : Presentation for zone object +*/ +class HYDROGUI_PrsZone : public HYDROGUI_Prs +{ +public: + HYDROGUI_PrsZone( const Handle(HYDROData_Object)& theObject ); + virtual ~HYDROGUI_PrsZone(); + +public: + void setPath( const QPainterPath& thePath ); + QPainterPath getPath() const; + + void setFillingColor( const QColor& theColor ); + QColor getFillingColor() const; + + void setBorderColor( const QColor& theColor ); + QColor getBorderColor() const; + +public: + // from QGraphicsItem + virtual QRectF boundingRect() const; + + // from GraphicsView_Object + virtual void compute(); + + virtual bool isMovable() const { return false; } + + virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const; + + virtual bool select( double theX, double theY, const QRectF& theRect ); + virtual void unselect(); + virtual void setSelected( bool theState ); + +protected: + QGraphicsPathItem* myZoneItem; + + QPainterPath myPath; + QColor myFillingColor; + QColor myBorderColor; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx new file mode 100644 index 00000000..5edfaa1d --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx @@ -0,0 +1,65 @@ +// 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_PrsZoneDriver.h" + +#include "HYDROGUI_PrsZone.h" + +#include + +HYDROGUI_PrsZoneDriver::HYDROGUI_PrsZoneDriver() +:HYDROGUI_PrsDriver() +{ +} + +HYDROGUI_PrsZoneDriver::~HYDROGUI_PrsZoneDriver() +{ +} + +bool HYDROGUI_PrsZoneDriver::Update( const Handle(HYDROData_Object)& theObj, + HYDROGUI_Prs*& thePrs ) +{ + HYDROGUI_PrsDriver::Update( theObj, thePrs ); + + if ( theObj.IsNull() ) + return false; + + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( theObj ); + if ( aZone.IsNull() ) + return false; + + if ( !thePrs ) + thePrs = new HYDROGUI_PrsZone( theObj ); + + HYDROGUI_PrsZone* aPrsZone = (HYDROGUI_PrsZone*)thePrs; + + aPrsZone->setName( aZone->GetName() ); + + aPrsZone->setFillingColor( aZone->GetFillingColor() ); + aPrsZone->setBorderColor( aZone->GetBorderColor() ); + + aPrsZone->setPath( aZone->GetPainterPath() ); + + aPrsZone->compute(); + + return true; +} diff --git a/src/HYDROGUI/HYDROGUI_PrsZoneDriver.h b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.h new file mode 100644 index 00000000..0eb5dbc3 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.h @@ -0,0 +1,56 @@ +// 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_PRSZONEDRIVER_H +#define HYDROGUI_PRSZONEDRIVER_H + +#include + +/** + * \class HYDROGUI_PrsZoneDriver + * \brief Presentation driver for zone objects. + */ +class HYDROGUI_PrsZoneDriver : public HYDROGUI_PrsDriver +{ +public: + /** + * \brief Constructor. + */ + HYDROGUI_PrsZoneDriver(); + + /** + * \brief Destructor. + */ + virtual ~HYDROGUI_PrsZoneDriver(); + +public: + /** + * \brief Update or create the polyline presentation on a basis of data object. + * \param theObj data object + * \param thePrs presentation + * \return status of the operation + */ + virtual bool Update( const Handle(HYDROData_Object)& theObj, + HYDROGUI_Prs*& thePrs ); +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index e030e1db..3e11ed93 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -194,6 +194,14 @@ void HYDROGUI_Tool::GetPrsSubObjects( HYDROGUI_Module* theModule, if( !anObject.IsNull() ) theSeq.Append( anObject ); } + + anIterator = HYDROData_Iterator( aDocument, KIND_ZONE ); + for( ; anIterator.More(); anIterator.Next() ) + { + Handle(HYDROData_Object) anObject = anIterator.Current(); + if( !anObject.IsNull() ) + theSeq.Append( anObject ); + } } HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Object)& theObj, diff --git a/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx b/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx new file mode 100644 index 00000000..02e6a60b --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ZoneDlg.cxx @@ -0,0 +1,297 @@ +// 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_ZoneDlg.h" + +#include "HYDROGUI_ColorWidget.h" +#include "HYDROGUI_Tool.h" + +#include +#include +#include +#include +#include +#include +#include + +HYDROGUI_ZoneDlg::HYDROGUI_ZoneDlg( HYDROGUI_Module* theModule, const QString& theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ) +{ + // Zone name + myObjectNameGroup = new QGroupBox( tr( "ZONE_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 ); + + + QGroupBox* aParamGroup = new QGroupBox( tr( "ZONE_PARAMETERS" ), mainFrame() ); + + QFrame* aPolylineFrame = new QFrame( aParamGroup ); + + myPolylines = new QComboBox( aPolylineFrame ); + myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + QBoxLayout* aPolyLayout = new QHBoxLayout( aPolylineFrame ); + aPolyLayout->setMargin( 0 ); + aPolyLayout->setSpacing( 5 ); + aPolyLayout->addWidget( new QLabel( tr( "ZONE_POLYLINE" ), aPolylineFrame ) ); + aPolyLayout->addWidget( myPolylines ); + + + QFrame* aFillingFrame = new QFrame( aParamGroup ); + QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame ); + myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame ); + myFillingTransparent->setChecked( true ); + myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame ); + myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame ); + + QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame ); + aFillingLayout->setMargin( 0 ); + aFillingLayout->setSpacing( 5 ); + aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 ); + aFillingLayout->addWidget( myFillingTransparent, 0, 1 ); + aFillingLayout->addWidget( myFillingColor, 1, 1 ); + aFillingLayout->addWidget( myFillingColorBox, 1, 2 ); + + + myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), mainFrame() ); + myBorderColorGroup->setCheckable( true ); + + myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup ); + + QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup ); + aBorderColorLayout->setMargin( 5 ); + aBorderColorLayout->setSpacing( 5 ); + aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) ); + aBorderColorLayout->addWidget( myBorderColorBox ); + + + QBoxLayout* aParamLayout = new QVBoxLayout( aParamGroup ); + aParamLayout->setMargin( 5 ); + aParamLayout->setSpacing( 5 ); + aParamLayout->addWidget( aPolylineFrame ); + aParamLayout->addWidget( aFillingFrame ); + aParamLayout->addWidget( myBorderColorGroup ); + + + QGroupBox* aBathGroup = new QGroupBox( tr( "ZONE_BATHYMETRIES" ), mainFrame() ); + + myBathymetries = new QListWidget( aBathGroup ); + myBathymetries->setSelectionMode( QListWidget::SingleSelection ); + myBathymetries->setEditTriggers( QListWidget::NoEditTriggers ); + myBathymetries->setViewMode( QListWidget::ListMode ); + + QBoxLayout* aBathLayout = new QHBoxLayout( aBathGroup ); + aBathLayout->setMargin( 5 ); + aBathLayout->setSpacing( 5 ); + aBathLayout->addWidget( myBathymetries ); + + + // Common + addWidget( myObjectNameGroup ); + addWidget( aParamGroup ); + addWidget( aBathGroup ); + + addStretch(); + + + // Connect signals and slots + connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myFillingTransparent, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myFillingColor, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myFillingColorBox, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( onFillingColorChanged() ) ); + connect( myBorderColorGroup, SIGNAL( toggled( bool ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myBorderColorBox, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( onZoneDefChanged() ) ); +} + +HYDROGUI_ZoneDlg::~HYDROGUI_ZoneDlg() +{ +} + +void HYDROGUI_ZoneDlg::reset() +{ + bool isBlocked = blockSignals( true ); + + myObjectName->clear(); + + myPolylines->clear(); + myBathymetries->clear(); + + myFillingTransparent->setChecked( true ); + myFillingColorBox->resetColor(); + + myBorderColorGroup->setChecked( false ); + myBorderColorBox->resetColor(); + + blockSignals( isBlocked ); + + onZoneDefChanged(); +} + +void HYDROGUI_ZoneDlg::setObjectName( const QString& theName ) +{ + myObjectName->setText( theName ); +} + +QString HYDROGUI_ZoneDlg::getObjectName() const +{ + return myObjectName->text(); +} + +void HYDROGUI_ZoneDlg::setPolylineNames( const QStringList& thePolylines ) +{ + bool isBlocked = blockSignals( true ); + + myPolylines->clear(); + myPolylines->addItems( thePolylines ); + + blockSignals( isBlocked ); +} + +void HYDROGUI_ZoneDlg::setPolylineName( const QString& theName ) +{ + myPolylines->setCurrentIndex( myPolylines->findText( theName ) ); +} + +QString HYDROGUI_ZoneDlg::getPolylineName() const +{ + return myPolylines->currentText(); +} + +void HYDROGUI_ZoneDlg::setBathymetries( const QStringList& theBathymetries ) +{ + myBathymetries->clear(); + + for ( int i = 0, n = theBathymetries.length(); i < n; ++i ) + { + QString aBathymetryName = theBathymetries.at( i ); + + QListWidgetItem* aListItem = new QListWidgetItem( aBathymetryName, myBathymetries ); + aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable ); + aListItem->setCheckState( Qt::Unchecked ); + } +} + +void HYDROGUI_ZoneDlg::setSelectedBathymetries( const QStringList& theBathymetries ) +{ + for ( int i = 0, n = theBathymetries.length(); i < n; ++i ) + { + QString aBathymetryName = theBathymetries.at( i ); + + QList anItems = + myBathymetries->findItems( aBathymetryName, Qt::MatchFixedString | Qt::MatchCaseSensitive ); + if ( anItems.isEmpty() ) + continue; + + QListWidgetItem* aListItem = anItems.first(); + if ( !aListItem ) + continue; + + aListItem->setCheckState( Qt::Checked ); + } +} + +QStringList HYDROGUI_ZoneDlg::getSelectedBathymetries() const +{ + QStringList aResList; + + for ( int i = 0, n = myBathymetries->count(); i < n; ++i ) + { + QListWidgetItem* aListItem = myBathymetries->item( i ); + if ( !aListItem || aListItem->checkState() != Qt::Checked ) + continue; + + QString aSelBathName = aListItem->text(); + aResList.append( aSelBathName ); + } + + return aResList; +} + +void HYDROGUI_ZoneDlg::setFillingColor( const QColor& theColor ) +{ + bool isBlocked = blockSignals( true ); + + if( theColor.alpha() == 0 ) // transparent + myFillingTransparent->setChecked( true ); + else + myFillingColor->setChecked( true ); + + myFillingColorBox->setColor( theColor ); + + blockSignals( isBlocked ); + + onZoneDefChanged(); +} + +QColor HYDROGUI_ZoneDlg::getFillingColor() const +{ + QColor aColor( 255, 255, 255, 0 ); // transparent + if( myFillingColor->isChecked() ) + aColor = myFillingColorBox->color(); + return aColor; +} + +void HYDROGUI_ZoneDlg::setBorderColor( const QColor& theColor ) +{ + bool isBlocked = blockSignals( true ); + + bool isTransparent = theColor.alpha() == 0; + myBorderColorGroup->setChecked( !isTransparent ); + myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) ); + + blockSignals( isBlocked ); + + onZoneDefChanged(); +} + +QColor HYDROGUI_ZoneDlg::getBorderColor() const +{ + QColor aColor( Qt::transparent ); // transparent + if( myBorderColorGroup->isChecked() ) + aColor = myBorderColorBox->color(); + return aColor; +} + +void HYDROGUI_ZoneDlg::onFillingColorChanged() +{ + if ( !myFillingColor->isChecked() ) + return; + + onZoneDefChanged(); +} + +void HYDROGUI_ZoneDlg::onZoneDefChanged() +{ + if ( signalsBlocked() ) + return; + + QString aPolylineName = getPolylineName(); + emit CreatePreview( aPolylineName ); +} + + diff --git a/src/HYDROGUI/HYDROGUI_ZoneDlg.h b/src/HYDROGUI/HYDROGUI_ZoneDlg.h new file mode 100644 index 00000000..ad70cb5e --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ZoneDlg.h @@ -0,0 +1,85 @@ +// 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_ZONEDLG_H +#define HYDROGUI_ZONEDLG_H + +#include "HYDROGUI_InputPanel.h" + +class HYDROGUI_ColorWidget; +class QComboBox; +class QGroupBox; +class QLineEdit; +class QListWidget; +class QRadioButton; + +class HYDROGUI_ZoneDlg : public HYDROGUI_InputPanel +{ + Q_OBJECT + +public: + HYDROGUI_ZoneDlg( HYDROGUI_Module* theModule, const QString& theTitle ); + virtual ~HYDROGUI_ZoneDlg(); + + void reset(); + + void setObjectName( const QString& theName ); + QString getObjectName() const; + + void setPolylineNames( const QStringList& thePolylines ); + void setPolylineName( const QString& thePolyline ); + QString getPolylineName() const; + + void setBathymetries( const QStringList& theBathymetries ); + void setSelectedBathymetries( const QStringList& theBathymetries ); + QStringList getSelectedBathymetries() const; + + void setFillingColor( const QColor& theColor ); + QColor getFillingColor() const; + + void setBorderColor( const QColor& theColor ); + QColor getBorderColor() const; + +signals: + void CreatePreview( const QString& thePolylineName ); + +private slots: + void onZoneDefChanged(); + void onFillingColorChanged(); + +private: + + QGroupBox* myObjectNameGroup; + QLineEdit* myObjectName; + + QComboBox* myPolylines; + QListWidget* myBathymetries; + + QRadioButton* myFillingTransparent; + QRadioButton* myFillingColor; + HYDROGUI_ColorWidget* myFillingColorBox; + + QGroupBox* myBorderColorGroup; + HYDROGUI_ColorWidget* myBorderColorBox; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ZoneOp.cxx new file mode 100644 index 00000000..88c54024 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ZoneOp.cxx @@ -0,0 +1,350 @@ +// 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_ZoneOp.h" + +#include "HYDROGUI_DataModel.h" +#include "HYDROGUI_ZoneDlg.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_PrsZone.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" + +#include +#include +#include + +#include +#include +#include + +#include +#include + +HYDROGUI_ZoneOp::HYDROGUI_ZoneOp( HYDROGUI_Module* theModule, + const bool theIsEdit ) +: HYDROGUI_Operation( theModule ), + myIsEdit( theIsEdit ), + myActiveViewManager( 0 ), + myPreviewViewManager( 0 ), + myPreviewPrs( 0 ) +{ + setName( theIsEdit ? tr( "EDIT_ZONE" ) : tr( "CREATE_ZONE" ) ); +} + +HYDROGUI_ZoneOp::~HYDROGUI_ZoneOp() +{ + closePreview(); +} + +void HYDROGUI_ZoneOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + HYDROGUI_ZoneDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + aPanel->reset(); + + QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Zone" ); + + QColor aFillingColor( HYDROData_Zone::DefaultFillingColor() ); + QColor aBorderColor( HYDROData_Zone::DefaultBorderColor() ); + QString aSelectedPolyline; + QStringList aSelectedBathymetries; + + if ( myIsEdit ) + { + myEditedObject = Handle(HYDROData_Zone)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if( !myEditedObject.IsNull() ) + { + anObjectName = myEditedObject->GetName(); + + aFillingColor = myEditedObject->GetFillingColor(); + aBorderColor = myEditedObject->GetBorderColor(); + + Handle(HYDROData_Polyline) aRefPolyline = myEditedObject->GetPolyline(); + if ( !aRefPolyline.IsNull() ) + aSelectedPolyline = aRefPolyline->GetName(); + + HYDROData_SequenceOfObjects aRefBathymetries = myEditedObject->GetBathymetries(); + HYDROData_SequenceOfObjects::Iterator anIter( aRefBathymetries ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Bathymetry) aRefBathymetry = + Handle(HYDROData_Bathymetry)::DownCast( anIter.Value() ); + if ( aRefBathymetry.IsNull() ) + continue; + + QString aRefBathymetryName = aRefBathymetry->GetName(); + if ( aRefBathymetryName.isEmpty() ) + continue; + + aSelectedBathymetries.append( aRefBathymetryName ); + } + } + } + + // collect information about existing closed polylines + QStringList aPolylines; + + HYDROData_Iterator anIter( doc(), KIND_POLYLINE ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Polyline) aPolylineObj = + Handle(HYDROData_Polyline)::DownCast( anIter.Current() ); + if ( aPolylineObj.IsNull() || !aPolylineObj->isClosed() ) + continue; + + QString aPolylineName = aPolylineObj->GetName(); + if ( aPolylineName.isEmpty() ) + continue; + + aPolylines.append( aPolylineName ); + } + + // collect information about existing bathymetries + QStringList aBathymetries; + + anIter = HYDROData_Iterator( doc(), KIND_BATHYMETRY ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Bathymetry) aBathymetryObj = + Handle(HYDROData_Bathymetry)::DownCast( anIter.Current() ); + if ( aBathymetryObj.IsNull() ) + continue; + + QString aBathymetryName = aBathymetryObj->GetName(); + if ( aBathymetryName.isEmpty() ) + continue; + + aBathymetries.append( aBathymetryName ); + } + + aPanel->setObjectName( anObjectName ); + + aPanel->setFillingColor( aFillingColor ); + aPanel->setBorderColor( aBorderColor ); + + aPanel->setPolylineNames( aPolylines ); + aPanel->setPolylineName( aSelectedPolyline ); + + aPanel->setBathymetries( aBathymetries ); + aPanel->setSelectedBathymetries( aSelectedBathymetries ); + +} + +void HYDROGUI_ZoneOp::abortOperation() +{ + closePreview(); + + HYDROGUI_Operation::abortOperation(); +} + +void HYDROGUI_ZoneOp::commitOperation() +{ + closePreview(); + + HYDROGUI_Operation::commitOperation(); +} + +HYDROGUI_InputPanel* HYDROGUI_ZoneOp::createInputPanel() const +{ + HYDROGUI_ZoneDlg* aPanel = new HYDROGUI_ZoneDlg( module(), getName() ); + connect( aPanel, SIGNAL( CreatePreview( const QString& ) ), + this, SLOT( onCreatePreview( const QString& ) ) ); + return aPanel; +} + +bool HYDROGUI_ZoneOp::processApply( int& theUpdateFlags, + QString& theErrorMsg ) +{ + HYDROGUI_ZoneDlg* 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_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); + if( !anObject.IsNull() ) + { + theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName ); + return false; + } + } + + Handle(HYDROData_Zone) aZoneObj = myIsEdit ? myEditedObject : + Handle(HYDROData_Zone)::DownCast( doc()->CreateObject( KIND_ZONE ) ); + if ( aZoneObj.IsNull() ) + return false; + + aZoneObj->SetName( anObjectName ); + + aZoneObj->SetFillingColor( aPanel->getFillingColor() ); + aZoneObj->SetBorderColor( aPanel->getBorderColor() ); + + Handle(HYDROData_Polyline) aZonePolyline; + + QString aPolylineName = aPanel->getPolylineName(); + if ( !aPolylineName.isEmpty() ) + { + aZonePolyline = Handle(HYDROData_Polyline)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) ); + } + + aZoneObj->SetPolyline( aZonePolyline ); + + + aZoneObj->RemoveBathymetries(); + + QStringList aBathymetries = aPanel->getSelectedBathymetries(); + for ( int i = 0; i < aBathymetries.length(); ++i ) + { + const QString& aBathymetryName = aBathymetries.at( i ); + if ( aBathymetryName.isEmpty() ) + continue; + + Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aBathymetryName, KIND_BATHYMETRY ) ); + if ( aBathymetry.IsNull() ) + continue; + + aZoneObj->AddBathymetry( aBathymetry ); + } + + + theUpdateFlags = UF_Model; + + return true; +} + +void HYDROGUI_ZoneOp::onCreatePreview( const QString& thePolylineName ) +{ + HYDROGUI_ZoneDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + QPainterPath aPath; + + Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINE ) ); + if ( !aPolyline.IsNull() ) + { + aPath = aPolyline->painterPath(); + } + + LightApp_Application* anApp = module()->getApp(); + + if ( !myActiveViewManager ) + { + myActiveViewManager = anApp->activeViewManager(); + } + + if ( !myPreviewPrs ) + { + myPreviewPrs = new HYDROGUI_PrsZone( myIsEdit ? myEditedObject : 0 ); + } + + myPreviewPrs->setPath( aPath ); + myPreviewPrs->setFillingColor( aPanel->getFillingColor() ); + myPreviewPrs->setBorderColor( aPanel->getBorderColor() ); + myPreviewPrs->compute(); + + if ( !myPreviewViewManager ) + { + myPreviewViewManager = ::qobject_cast( + anApp->createViewManager( GraphicsView_Viewer::Type() ) ); + if ( myPreviewViewManager ) + { + connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), + this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); + + module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewZone ); + myPreviewViewManager->setTitle( tr( "PREVIEW_ZONE" ) ); + if ( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() ) + { + if ( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() ) + { + aViewPort->addItem( myPreviewPrs ); + } + } + } + } + + if ( myPreviewViewManager ) + { + if ( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() ) + { + if ( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() ) + { + aViewPort->update(); + aViewPort->fitAll(); + } + } + } +} + +void HYDROGUI_ZoneOp::onLastViewClosed( SUIT_ViewManager* theViewManager ) +{ + closePreview(); +} + +void HYDROGUI_ZoneOp::closePreview() +{ + // It's very strange, but without calling this method (it's quite safe) a crash is stably reproduced. + // Scenario: create any non-Graphics view, activate import op, click apply. + // Result: a few SIGSEGVs coming from processEvents(), then crash. + if( myPreviewViewManager ) + if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() ) + if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() ) + aViewPort->onBoundingRectChanged(); + + if( myPreviewPrs ) + { + delete myPreviewPrs; + myPreviewPrs = 0; + } + + if( myPreviewViewManager ) + { + disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), + this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); + + module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here + myPreviewViewManager = 0; + } + + if( myActiveViewManager ) + { + HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager ); + myActiveViewManager = 0; + } +} diff --git a/src/HYDROGUI/HYDROGUI_ZoneOp.h b/src/HYDROGUI/HYDROGUI_ZoneOp.h new file mode 100644 index 00000000..9764d0f6 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ZoneOp.h @@ -0,0 +1,75 @@ +// 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_ZONEOP_H +#define HYDROGUI_ZONEOP_H + +#include "HYDROGUI_Operation.h" + +#include + +#include + +class GraphicsView_ViewManager; + +class SUIT_ViewManager; + +class HYDROGUI_PrsZone; + +class HYDROGUI_ZoneOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_ZoneOp( HYDROGUI_Module* theModule, const bool theIsEdit ); + virtual ~HYDROGUI_ZoneOp(); + +protected: + virtual void startOperation(); + virtual void abortOperation(); + virtual void commitOperation(); + + virtual HYDROGUI_InputPanel* createInputPanel() const; + + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); + +protected slots: + void onCreatePreview( const QString& thePolylineName ); + + void onLastViewClosed( SUIT_ViewManager* ); + +private: + void closePreview(); + +private: + bool myIsEdit; + Handle(HYDROData_Zone) myEditedObject; + + SUIT_ViewManager* myActiveViewManager; + + GraphicsView_ViewManager* myPreviewViewManager; + HYDROGUI_PrsZone* myPreviewPrs; + + QPainterPath myZonePath; +}; + +#endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 18d81f7f..10132b31 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -44,6 +44,14 @@ does not exist or you have not enough permissions to open it. SAVE_ERROR Study could not be saved + + ZONE_POLYLINE + Polyline + + + ZONE_BATHYMETRIES + Bathymetries + @@ -259,6 +267,14 @@ file cannot be correctly imported for a Bathymetry definition. DSK_CREATE_POLYLINE Create polyline + + DSK_CREATE_ZONE + Create zone + + + DSK_EDIT_ZONE + Edit zone + DSK_COPY Copy @@ -371,6 +387,14 @@ file cannot be correctly imported for a Bathymetry definition. MEN_CREATE_POLYLINE Create polyline + + MEN_CREATE_ZONE + Create zone + + + MEN_EDIT_ZONE + Edit zone + MEN_COPY Copy @@ -487,6 +511,14 @@ file cannot be correctly imported for a Bathymetry definition. STB_CREATE_POLYLINE Create polyline + + STB_CREATE_ZONE + Create zone + + + STB_EDIT_ZONE + Edit zone + STB_COPY Copy @@ -752,5 +784,61 @@ file cannot be correctly imported for a Bathymetry definition. Save visual state - + + + HYDROGUI_ZoneDlg + + BORDER_COLOR + Border + + + COLOR + Color + + + FILLING_COLOR + Filling color + + + NAME + Name + + + TRANSPARENT + Transparent + + + ZONE_BATHYMETRIES + Bathymetries + + + ZONE_NAME + Zone name + + + ZONE_PARAMETERS + Parameters + + + ZONE_POLYLINE + Polyline + + + + + HYDROGUI_ZoneOp + + CREATE_ZONE + Create zone + + + EDIT_ZONE + Edit zone + + + PREVIEW_ZONE + Preview zone + + + -- 2.39.2