From aa090594408d227e2a98e92946fc85206e49c0ea Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 6 Feb 2024 07:43:13 +0100 Subject: [PATCH] wip --- .../Polygons/RimPolygonInView.cpp | 78 ++++++++++++++++--- .../Polygons/RimPolygonInView.h | 1 + 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp index 38477eff44..a770df3b64 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp @@ -105,7 +105,11 @@ void RimPolygonInView::appendPartsToModel( cvf::ModelBasicList* model, //-------------------------------------------------------------------------------------------------- void RimPolygonInView::insertTarget( const RimPolylineTarget* targetToInsertBefore, RimPolylineTarget* targetToInsert ) { - m_targets.push_back( targetToInsert ); + size_t index = m_targets.indexOf( targetToInsertBefore ); + if ( index < m_targets.size() ) + m_targets.insert( index, targetToInsert ); + else + m_targets.push_back( targetToInsert ); } //-------------------------------------------------------------------------------------------------- @@ -113,6 +117,8 @@ void RimPolygonInView::insertTarget( const RimPolylineTarget* targetToInsertBefo //-------------------------------------------------------------------------------------------------- void RimPolygonInView::deleteTarget( RimPolylineTarget* targetToDelete ) { + m_targets.removeChild( targetToDelete ); + delete targetToDelete; } //-------------------------------------------------------------------------------------------------- @@ -120,6 +126,8 @@ void RimPolygonInView::deleteTarget( RimPolylineTarget* targetToDelete ) //-------------------------------------------------------------------------------------------------- void RimPolygonInView::updateEditorsAndVisualization() { + updateConnectedEditors(); + updateVisualization(); } //-------------------------------------------------------------------------------------------------- @@ -127,6 +135,11 @@ void RimPolygonInView::updateEditorsAndVisualization() //-------------------------------------------------------------------------------------------------- void RimPolygonInView::updateVisualization() { + auto view = firstAncestorOfType(); + if ( view ) + { + view->scheduleCreateDisplayModelAndRedraw(); + } } //-------------------------------------------------------------------------------------------------- @@ -189,6 +202,8 @@ void RimPolygonInView::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin //-------------------------------------------------------------------------------------------------- void RimPolygonInView::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) { + updateVisualization(); + ; } //-------------------------------------------------------------------------------------------------- @@ -223,25 +238,64 @@ void RimPolygonInView::defineObjectEditorAttribute( QString uiConfigName, caf::P //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimPolygonInView::updateNameField() +void RimPolygonInView::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) { - m_targets.deleteChildren(); - - QString name = "Undefined"; - if ( m_polygon() ) + if ( field == &m_enablePicking ) { - name = m_polygon->name(); + auto* pbAttribute = dynamic_cast( attribute ); + if ( pbAttribute ) + { + if ( !m_enablePicking ) + { + pbAttribute->m_buttonText = "Start Picking Points"; + } + else + { + pbAttribute->m_buttonText = "Stop Picking Points"; + } + } + } - for ( auto p : m_polygon->pointsInDomainCoords() ) + if ( field == &m_targets ) + { + auto tvAttribute = dynamic_cast( attribute ); + if ( tvAttribute ) { - auto target = new RimPolylineTarget(); - target->setAsPointXYZ( p ); + tvAttribute->resizePolicy = caf::PdmUiTableViewEditorAttribute::RESIZE_TO_FIT_CONTENT; - m_targets.push_back( target ); + if ( m_enablePicking ) + { + tvAttribute->baseColor.setRgb( 255, 220, 255 ); + tvAttribute->alwaysEnforceResizePolicy = true; + } } } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonInView::updateNameField() +{ + /* + m_targets.deleteChildren(); + + QString name = "Undefined"; + if ( m_polygon() ) + { + name = m_polygon->name(); + + for ( auto p : m_polygon->pointsInDomainCoords() ) + { + auto target = new RimPolylineTarget(); + target->setAsPointXYZ( p ); + + m_targets.push_back( target ); + } + } - setName( name ); + setName( name ); + */ } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h index e2f1e39875..2a68581eac 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h @@ -68,6 +68,7 @@ class RimPolygonInView : public RimCheckableNamedObject, public RimPolylinesData void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override; QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; + void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; private: void updateNameField();