diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp index 29fd3b4697..e368660039 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp @@ -18,14 +18,19 @@ #include "RimPolygon.h" +#include "RiaApplication.h" +#include "RiaColorTools.h" + #include "RigPolyLinesData.h" -#include "RiaApplication.h" #include "Rim3dView.h" #include "RimPolygonAppearance.h" #include "RimPolygonTools.h" +#include "RiuGuiTheme.h" + #include "cafCmdFeatureMenuBuilder.h" +#include "cafPdmUiColorEditor.h" #include "cafPdmUiPushButtonEditor.h" #include "cafPdmUiTreeAttributes.h" @@ -140,6 +145,22 @@ void RimPolygon::disableStorageOfPolygonPoints() m_pointsInDomainCoords.xmlCapability()->setIOWritable( false ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Color3f RimPolygon::color() const +{ + return m_appearance->lineColor(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygon::setColor( const cvf::Color3f& color ) +{ + m_appearance->setLineColor( color ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -197,16 +218,48 @@ void RimPolygon::defineEditorAttribute( const caf::PdmFieldHandle* field, QStrin { if ( auto attrib = dynamic_cast( attribute ) ) { - attrib->m_buttonText = "Edit in Active View"; + if ( m_isReadOnly() ) + { + attrib->m_buttonText = "Select in Active View"; + } + else + { + attrib->m_buttonText = "Edit in Active View"; + } } } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygon::onColorTagClicked( const SignalEmitter* emitter, size_t index ) +{ + QColor sourceColor = RiaColorTools::toQColor( color() ); + QColor newColor = caf::PdmUiColorEditor::getColor( sourceColor ); + + if ( newColor.isValid() && newColor != sourceColor ) + { + setColor( RiaColorTools::fromQColorTo3f( newColor ) ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimPolygon::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) { + if ( auto* treeItemAttribute = dynamic_cast( attribute ) ) + { + auto tag = caf::PdmUiTreeViewItemAttribute::createTag( RiaColorTools::toQColor( color() ), + RiuGuiTheme::getColorByVariableName( "backgroundColor1" ), + "---" ); + + tag->clicked.connect( this, &RimPolygon::onColorTagClicked ); + + treeItemAttribute->tags.push_back( std::move( tag ) ); + } + if ( m_isReadOnly ) { caf::PdmUiTreeViewItemAttribute::createTagIfTreeViewItemAttribute( attribute, ":/padlock.svg" ); diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h index 5ad152112e..7fd0c88eee 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h @@ -53,13 +53,17 @@ class RimPolygon : public RimNamedObject, public RimPolylinesDataInterface void disableStorageOfPolygonPoints(); + cvf::Color3f color() const; + void setColor( const cvf::Color3f& color ); + cvf::ref polyLinesData() const override; void uiOrderingForLocalPolygon( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ); void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override; - void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; + void onColorTagClicked( const SignalEmitter* emitter, size_t index ); -protected: +private: + void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override; diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp index 1cd83a0a5c..b15105ed4a 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.cpp @@ -123,6 +123,22 @@ bool RimPolygonAppearance::isClosed() const return m_isClosed(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Color3f RimPolygonAppearance::lineColor() const +{ + return m_lineColor(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonAppearance::setLineColor( const cvf::Color3f& color ) +{ + m_lineColor = color; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h index 4fae753127..0f6fd767d0 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonAppearance.h @@ -37,6 +37,9 @@ class RimPolygonAppearance : public caf::PdmObject void setIsClosed( bool isClosed ); bool isClosed() const; + cvf::Color3f lineColor() const; + void setLineColor( const cvf::Color3f& color ); + public: RimPolygonAppearance(); diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp index cb358a6c34..c922610847 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp @@ -18,6 +18,8 @@ #include "RimPolygonInView.h" +#include "RiaColorTools.h" + #include "RigPolyLinesData.h" #include "Rim3dView.h" @@ -88,6 +90,16 @@ RimPolygon* RimPolygonInView::polygon() const //-------------------------------------------------------------------------------------------------- void RimPolygonInView::setPolygon( RimPolygon* polygon ) { + if ( m_polygon ) + { + m_polygon->objectChanged.disconnect( this ); + } + + if ( polygon ) + { + polygon->objectChanged.connect( this, &RimPolygonInView::onObjectChanged ); + } + m_polygon = polygon; updateTargetsFromPolygon(); @@ -323,9 +335,23 @@ void RimPolygonInView::defineObjectEditorAttribute( QString uiConfigName, caf::P attrib->enablePicking = m_enablePicking; } - if ( m_polygon() && m_polygon->isReadOnly() ) + if ( m_polygon() ) { - caf::PdmUiTreeViewItemAttribute::createTagIfTreeViewItemAttribute( attribute, ":/padlock.svg" ); + if ( auto* treeItemAttribute = dynamic_cast( attribute ) ) + { + auto tag = caf::PdmUiTreeViewItemAttribute::createTag( RiaColorTools::toQColor( m_polygon->color() ), + RiuGuiTheme::getColorByVariableName( "backgroundColor1" ), + "---" ); + + tag->clicked.connect( m_polygon(), &RimPolygon::onColorTagClicked ); + + treeItemAttribute->tags.push_back( std::move( tag ) ); + } + + if ( m_polygon->isReadOnly() ) + { + caf::PdmUiTreeViewItemAttribute::createTagIfTreeViewItemAttribute( attribute, ":/padlock.svg" ); + } } } @@ -347,6 +373,25 @@ void RimPolygonInView::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder if ( m_polygon() ) m_polygon->appendMenuItems( menuBuilder ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonInView::onObjectChanged( const caf::SignalEmitter* emitter ) +{ + updateVisualization(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonInView::initAfterRead() +{ + if ( m_polygon ) + { + m_polygon->objectChanged.connect( this, &RimPolygonInView::onObjectChanged ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h index c77494d0d3..545da480ed 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h @@ -79,6 +79,8 @@ class RimPolygonInView : public RimCheckableNamedObject, public RimPolylinesData void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; void defineCustomContextMenu( const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget ) override; void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override; + void onObjectChanged( const caf::SignalEmitter* emitter ); + void initAfterRead() override; private: void updateNameField(); diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp b/ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp index 5fb6ce2068..a9015e2ada 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp @@ -1262,19 +1262,10 @@ void RimPlotCurve::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUi if ( auto* treeItemAttribute = dynamic_cast( attribute ) ) { treeItemAttribute->tags.clear(); - auto tag = caf::PdmUiTreeViewItemAttribute::createTag(); - - // Blend with background for a nice look - auto backgroundColor = RiuGuiTheme::getColorByVariableName( "backgroundColor1" ); - auto color = RiaColorTools::toQColor( m_curveAppearance->color() ); - auto sourceWeight = 100; - double transparency = 0.3; - int backgroundWeight = std::max( 1, static_cast( sourceWeight * 10 * transparency ) ); - auto blendedColor = RiaColorTools::blendQColors( backgroundColor, color, backgroundWeight, sourceWeight ); - - tag->bgColor = blendedColor; - tag->fgColor = RiaColorTools::toQColor( m_curveAppearance->color() ); - tag->text = "---"; + + auto tag = caf::PdmUiTreeViewItemAttribute::createTag( RiaColorTools::toQColor( m_curveAppearance->color() ), + RiuGuiTheme::getColorByVariableName( "backgroundColor1" ), + "---" ); tag->clicked.connect( this, &RimPlotCurve::onColorTagClicked );