Skip to content

Commit

Permalink
Show polygon color as tag, allow color edit by clicking on tag
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Feb 27, 2024
1 parent 4814eb6 commit cc5b8c3
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 19 deletions.
57 changes: 55 additions & 2 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -197,16 +218,48 @@ void RimPolygon::defineEditorAttribute( const caf::PdmFieldHandle* field, QStrin
{
if ( auto attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( 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<caf::PdmUiTreeViewItemAttribute*>( 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" );
Expand Down
8 changes: 6 additions & 2 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ class RimPolygon : public RimNamedObject, public RimPolylinesDataInterface

void disableStorageOfPolygonPoints();

cvf::Color3f color() const;
void setColor( const cvf::Color3f& color );

cvf::ref<RigPolyLinesData> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
49 changes: 47 additions & 2 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "RimPolygonInView.h"

#include "RiaColorTools.h"

#include "RigPolyLinesData.h"

#include "Rim3dView.h"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<caf::PdmUiTreeViewItemAttribute*>( 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" );
}
}
}

Expand All @@ -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 );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 4 additions & 13 deletions ApplicationLibCode/ProjectDataModel/RimPlotCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,19 +1262,10 @@ void RimPlotCurve::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUi
if ( auto* treeItemAttribute = dynamic_cast<caf::PdmUiTreeViewItemAttribute*>( 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<int>( 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 );

Expand Down

0 comments on commit cc5b8c3

Please sign in to comment.