Add polygon file readers and make sure UI items are in sync

* Add polygon reader for POL file format
* Add CSV import
* Add helper function to create tag with color and text
* Show polygon color as tag, allow color edit by clicking on tag
* Support optional header in csv file
* Add Reload on polygon file
* Show warning icon if no polygons
* Improve logging text
* Do not show file polygon in view if no polygons are imported
* Use appendMenuItems
* Set default polygon color to orange
* Enter edit state when creating a new polygon
* Fix missing UI text in menu builder
This commit is contained in:
Magne Sjaastad
2024-03-01 14:59:14 +01:00
committed by GitHub
parent 04b14cf52a
commit 818c5c0f9c
37 changed files with 1117 additions and 159 deletions

View File

@@ -1048,10 +1048,7 @@ void RimGeoMechView::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrderin
if ( surfaceInViewCollection() ) uiTreeOrdering.add( surfaceInViewCollection() );
if ( seismicSectionCollection()->shouldBeVisibleInTree() ) uiTreeOrdering.add( seismicSectionCollection() );
if ( RiaApplication::enableDevelopmentFeatures() )
{
uiTreeOrdering.add( m_polygonInViewCollection );
}
uiTreeOrdering.add( m_polygonInViewCollection );
uiTreeOrdering.skipRemainingChildren( true );
}

View File

@@ -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"
@@ -132,6 +137,30 @@ bool RimPolygon::isReadOnly() const
return m_isReadOnly();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -189,18 +218,51 @@ 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 ) );
objectChanged.send();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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" );
caf::PdmUiTreeViewItemAttribute::appendTagToTreeViewItemAttribute( attribute, ":/padlock.svg" );
}
}

View File

@@ -24,6 +24,7 @@
#include "cafPdmChildField.h"
#include "cafPdmFieldCvfVec3d.h"
#include "cvfColor3.h"
#include "cvfVector3.h"
class RimPolygonAppearance;
@@ -51,13 +52,19 @@ public:
void setReadOnly( bool isReadOnly );
bool isReadOnly() const;
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;

View File

@@ -85,8 +85,8 @@ RimPolygonAppearance::RimPolygonAppearance()
CAF_PDM_InitField( &m_lineThickness, "LineThickness", 3, "Line Thickness" );
CAF_PDM_InitField( &m_sphereRadiusFactor, "SphereRadiusFactor", 0.15, "Sphere Radius Factor" );
CAF_PDM_InitField( &m_lineColor, "LineColor", cvf::Color3f( cvf::Color3f::WHITE ), "Line Color" );
CAF_PDM_InitField( &m_sphereColor, "SphereColor", cvf::Color3f( cvf::Color3f::WHITE ), "Sphere Color" );
CAF_PDM_InitField( &m_lineColor, "LineColor", cvf::Color3f( cvf::Color3f::ORANGE ), "Line Color" );
CAF_PDM_InitField( &m_sphereColor, "SphereColor", cvf::Color3f( cvf::Color3f::ORANGE ), "Sphere Color" );
CAF_PDM_InitField( &m_polygonPlaneDepth, "PolygonPlaneDepth", 0.0, "Polygon Plane Depth" );
CAF_PDM_InitField( &m_lockPolygonToPlane, "LockPolygon", false, "Lock Polygon to Plane" );
@@ -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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -37,6 +37,9 @@ public:
void setIsClosed( bool isClosed );
bool isClosed() const;
cvf::Color3f lineColor() const;
void setLineColor( const cvf::Color3f& color );
public:
RimPolygonAppearance();

View File

@@ -23,6 +23,8 @@
#include "RimPolygonFile.h"
#include "RimProject.h"
#include "cafCmdFeatureMenuBuilder.h"
CAF_PDM_SOURCE_INIT( RimPolygonCollection, "RimPolygonCollection" );
//--------------------------------------------------------------------------------------------------
@@ -30,7 +32,7 @@ CAF_PDM_SOURCE_INIT( RimPolygonCollection, "RimPolygonCollection" );
//--------------------------------------------------------------------------------------------------
RimPolygonCollection::RimPolygonCollection()
{
CAF_PDM_InitObject( "Polygons (Under construction)", ":/PolylinesFromFile16x16.png" );
CAF_PDM_InitObject( "Polygons", ":/PolylinesFromFile16x16.png" );
CAF_PDM_InitFieldNoDefault( &m_polygons, "Polygons", "Polygons" );
CAF_PDM_InitFieldNoDefault( &m_polygonFiles, "PolygonFiles", "Polygon Files" );
@@ -66,7 +68,7 @@ void RimPolygonCollection::addUserDefinedPolygon( RimPolygon* polygon )
{
m_polygons().push_back( polygon );
connectSignals( polygon );
connectPolygonSignals( polygon );
updateViewTreeItems();
scheduleRedrawViews();
@@ -90,6 +92,8 @@ void RimPolygonCollection::addPolygonFile( RimPolygonFile* polygonFile )
{
m_polygonFiles().push_back( polygonFile );
connectPolygonFileSignals( polygonFile );
updateViewTreeItems();
scheduleRedrawViews();
}
@@ -150,6 +154,15 @@ void RimPolygonCollection::childFieldChangedByUi( const caf::PdmFieldHandle* cha
scheduleRedrawViews();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonCollection::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
{
menuBuilder << "RicCreatePolygonFeature";
menuBuilder << "RicImportPolygonFileFeature";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -178,19 +191,39 @@ void RimPolygonCollection::scheduleRedrawViews()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonCollection::connectSignals( RimPolygon* polygon )
void RimPolygonCollection::connectPolygonSignals( RimPolygon* polygon )
{
if ( polygon )
{
polygon->objectChanged.connect( this, &RimPolygonCollection::onObjectChanged );
polygon->objectChanged.connect( this, &RimPolygonCollection::onPolygonChanged );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonCollection::onObjectChanged( const caf::SignalEmitter* emitter )
void RimPolygonCollection::connectPolygonFileSignals( RimPolygonFile* polygonFile )
{
if ( polygonFile )
{
polygonFile->objectChanged.connect( this, &RimPolygonCollection::onPolygonFileChanged );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonCollection::onPolygonChanged( const caf::SignalEmitter* emitter )
{
scheduleRedrawViews();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonCollection::onPolygonFileChanged( const caf::SignalEmitter* emitter )
{
updateViewTreeItems();
scheduleRedrawViews();
}
@@ -201,6 +234,11 @@ void RimPolygonCollection::initAfterRead()
{
for ( auto& p : m_polygons() )
{
connectSignals( p );
connectPolygonSignals( p );
}
for ( auto& pf : m_polygonFiles() )
{
connectPolygonFileSignals( pf );
}
}

View File

@@ -46,15 +46,18 @@ public:
std::vector<RimPolygonFile*> polygonFiles() const;
std::vector<RimPolygon*> allPolygons() const;
void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& referringObjects ) override;
void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override;
private:
void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& referringObjects ) override;
void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override;
void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override;
void updateViewTreeItems();
void scheduleRedrawViews();
void connectSignals( RimPolygon* polygon );
void onObjectChanged( const caf::SignalEmitter* emitter );
void connectPolygonSignals( RimPolygon* polygon );
void connectPolygonFileSignals( RimPolygonFile* polygonFile );
void onPolygonChanged( const caf::SignalEmitter* emitter );
void onPolygonFileChanged( const caf::SignalEmitter* emitter );
private:
caf::PdmChildArrayField<RimPolygon*> m_polygons;

View File

@@ -17,14 +17,25 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RimPolygonFile.h"
#include "RiaLogging.h"
#include "RifPolygonReader.h"
#include "RimPolygon.h"
#include "cafCmdFeatureMenuBuilder.h"
#include "cafPdmUiTreeAttributes.h"
#include <QFileInfo>
CAF_PDM_SOURCE_INIT( RimPolygonFile, "RimPolygonFileFile" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPolygonFile::RimPolygonFile()
: objectChanged( this )
{
CAF_PDM_InitObject( "PolygonFile", ":/PolylinesFromFile16x16.png" );
@@ -34,12 +45,48 @@ RimPolygonFile::RimPolygonFile()
setDeletable( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::setFileName( const QString& fileName )
{
m_fileName = fileName;
updateName();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::loadData()
{
loadPolygonsFromFile();
auto polygonsFromFile = importDataFromFile( m_fileName().path() );
if ( m_polygons.size() == polygonsFromFile.size() )
{
for ( size_t i = 0; i < m_polygons.size(); i++ )
{
auto projectPoly = m_polygons()[i];
auto filePoly = polygonsFromFile[i];
projectPoly->setPointsInDomainCoords( filePoly->pointsInDomainCoords() );
delete filePoly;
}
}
else
{
m_polygons.deleteChildren();
m_polygons.setValue( polygonsFromFile );
}
if ( polygonsFromFile.empty() )
{
RiaLogging::warning( "No polygons found in file: " + m_fileName().path() );
}
else
{
RiaLogging::info( QString( "Imported %1 polygons from file: " ).arg( polygonsFromFile.size() ) + m_fileName().path() );
}
}
//--------------------------------------------------------------------------------------------------
@@ -50,11 +97,36 @@ std::vector<RimPolygon*> RimPolygonFile::polygons() const
return m_polygons.childrenByType();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPolygonFile::name() const
{
QString nameCandidate = RimNamedObject::name();
if ( !nameCandidate.isEmpty() )
{
return nameCandidate;
}
auto fileName = m_fileName().path();
if ( fileName.isEmpty() )
{
return "Polygon File";
}
QFileInfo fileInfo( fileName );
return fileInfo.fileName();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( nameField() );
uiOrdering.add( &m_fileName );
uiOrdering.skipRemainingFields();
}
//--------------------------------------------------------------------------------------------------
@@ -62,21 +134,71 @@ void RimPolygonFile::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
loadPolygonsFromFile();
if ( changedField == &m_fileName )
{
updateName();
m_polygons.deleteChildren();
loadData();
}
objectChanged.send();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::loadPolygonsFromFile()
std::vector<RimPolygon*> RimPolygonFile::importDataFromFile( const QString& fileName )
{
// m_polygons()->deletePolygons();
QString errorMessages;
auto filePolygons = RifPolygonReader::parsePolygonFile( fileName, &errorMessages );
auto polygon = new RimPolygon();
polygon->setName( "Polygon 1" );
m_polygons.push_back( polygon );
std::vector<RimPolygon*> polygons;
polygon = new RimPolygon();
polygon->setName( "Polygon 2" );
m_polygons.push_back( polygon );
for ( const auto& [polygonId, filePolygon] : filePolygons )
{
auto polygon = new RimPolygon();
polygon->disableStorageOfPolygonPoints();
polygon->setReadOnly( true );
int id = ( polygonId != -1 ) ? polygonId : static_cast<int>( polygons.size() + 1 );
polygon->setName( QString( "Polygon %1" ).arg( id ) );
polygon->setPointsInDomainCoords( filePolygon );
polygons.push_back( polygon );
}
if ( !errorMessages.isEmpty() )
{
RiaLogging::error( errorMessages );
}
return polygons;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::updateName()
{
QFileInfo fileInfo( m_fileName().path() );
setName( fileInfo.fileName() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
{
menuBuilder << "RicReloadPolygonFileFeature";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
{
if ( m_polygons.empty() )
{
caf::PdmUiTreeViewItemAttribute::appendTagToTreeViewItemAttribute( attribute, ":/warning.svg" );
}
}

View File

@@ -28,19 +28,29 @@ class RimPolygonFile : public RimNamedObject
{
CAF_PDM_HEADER_INIT;
public:
caf::Signal<> objectChanged;
public:
RimPolygonFile();
void setFileName( const QString& fileName );
void loadData();
std::vector<RimPolygon*> polygons() const;
QString name() const override;
protected:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override;
void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
private:
void loadPolygonsFromFile();
static std::vector<RimPolygon*> importDataFromFile( const QString& fileName );
void updateName();
private:
caf::PdmField<caf::FilePath> m_fileName;

View File

@@ -18,6 +18,8 @@
#include "RimPolygonInView.h"
#include "RiaColorTools.h"
#include "RigPolyLinesData.h"
#include "Rim3dView.h"
@@ -70,6 +72,7 @@ RimPolygonInView::RimPolygonInView()
m_targets.uiCapability()->setUiTreeChildrenHidden( true );
m_targets.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP );
m_targets.uiCapability()->setCustomContextMenuEnabled( true );
m_targets.xmlCapability()->disableIO();
setUi3dEditorTypeName( RicPolyline3dEditor::uiEditorTypeName() );
}
@@ -87,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();
@@ -322,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::appendTagToTreeViewItemAttribute( attribute, ":/padlock.svg" );
}
}
}
@@ -346,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 );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -79,6 +79,8 @@ protected:
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();

View File

@@ -21,6 +21,7 @@
#include "Rim3dView.h"
#include "RimPolygon.h"
#include "RimPolygonCollection.h"
#include "RimPolygonFile.h"
#include "RimPolygonInView.h"
#include "RimTools.h"
@@ -31,58 +32,74 @@ CAF_PDM_SOURCE_INIT( RimPolygonInViewCollection, "RimPolygonInViewCollection" );
//--------------------------------------------------------------------------------------------------
RimPolygonInViewCollection::RimPolygonInViewCollection()
{
CAF_PDM_InitObject( "Polygons (Under construction)", ":/PolylinesFromFile16x16.png" );
CAF_PDM_InitObject( "Polygons", ":/PolylinesFromFile16x16.png" );
CAF_PDM_InitFieldNoDefault( &m_polygons, "Polygons", "Polygons" );
CAF_PDM_InitFieldNoDefault( &m_polygonsInView, "Polygons", "Polygons" );
CAF_PDM_InitFieldNoDefault( &m_collectionsInView, "Collections", "Collections" );
nameField()->uiCapability()->setUiHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInViewCollection::syncPolygonsInView()
void RimPolygonInViewCollection::updateFromPolygonCollection()
{
std::vector<RimPolygonInView*> existingPolygonsInView = m_polygons.childrenByType();
m_polygons.clearWithoutDelete();
auto polygonCollection = RimTools::polygonCollection();
if ( polygonCollection )
{
std::vector<RimPolygonInView*> newPolygonsInView;
for ( auto polygon : polygonCollection->allPolygons() )
{
auto it = std::find_if( existingPolygonsInView.begin(),
existingPolygonsInView.end(),
[polygon]( auto* polygonInView ) { return polygonInView->polygon() == polygon; } );
if ( it != existingPolygonsInView.end() )
{
newPolygonsInView.push_back( *it );
existingPolygonsInView.erase( it );
}
else
{
auto polygonInView = new RimPolygonInView();
polygonInView->setPolygon( polygon );
newPolygonsInView.push_back( polygonInView );
}
}
m_polygons.setValue( newPolygonsInView );
}
for ( auto polyInView : existingPolygonsInView )
{
delete polyInView;
}
updateAllViewItems();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPolygonInView*> RimPolygonInViewCollection::polygonsInView() const
std::vector<RimPolygonInView*> RimPolygonInViewCollection::visiblePolygonsInView() const
{
return m_polygons.childrenByType();
if ( !m_isChecked ) return {};
std::vector<RimPolygonInView*> polys = m_polygonsInView.childrenByType();
for ( auto coll : m_collectionsInView )
{
if ( coll->isChecked() == false ) continue;
auto other = coll->visiblePolygonsInView();
polys.insert( polys.end(), other.begin(), other.end() );
}
return polys;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPolygonInView*> RimPolygonInViewCollection::allPolygonsInView() const
{
std::vector<RimPolygonInView*> polys = m_polygonsInView.childrenByType();
for ( auto coll : m_collectionsInView )
{
auto other = coll->visiblePolygonsInView();
polys.insert( polys.end(), other.begin(), other.end() );
}
return polys;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInViewCollection::setPolygonFile( RimPolygonFile* polygonFile )
{
m_polygonFile = polygonFile;
updateName();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPolygonFile* RimPolygonInViewCollection::polygonFile() const
{
return m_polygonFile;
}
//--------------------------------------------------------------------------------------------------
@@ -90,11 +107,11 @@ std::vector<RimPolygonInView*> RimPolygonInViewCollection::polygonsInView() cons
//--------------------------------------------------------------------------------------------------
void RimPolygonInViewCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
RimCheckableObject::fieldChangedByUi( changedField, oldValue, newValue );
RimCheckableNamedObject::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_isChecked )
{
for ( auto poly : polygonsInView() )
for ( auto poly : visiblePolygonsInView() )
{
poly->updateConnectedEditors();
}
@@ -105,3 +122,151 @@ void RimPolygonInViewCollection::fieldChangedByUi( const caf::PdmFieldHandle* ch
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInViewCollection::updateAllViewItems()
{
// Based on the same concept as RimSurfaceInViewCollection
syncCollectionsWithView();
syncPolygonsWithView();
updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInViewCollection::syncCollectionsWithView()
{
// Based on the same concept as RimSurfaceInViewCollection
auto colls = m_collectionsInView.childrenByType();
for ( auto coll : colls )
{
if ( !coll->polygonFile() )
{
m_collectionsInView.removeChild( coll );
delete coll;
}
}
if ( !m_polygonFile )
{
std::vector<RimPolygonInViewCollection*> orderedColls;
if ( auto polygonCollection = RimTools::polygonCollection() )
{
std::vector<RimPolygonInView*> newPolygonsInView;
for ( auto polygonFile : polygonCollection->polygonFiles() )
{
if ( polygonFile->polygons().empty() ) continue;
auto viewPolygonFile = getCollectionInViewForPolygonFile( polygonFile );
if ( viewPolygonFile == nullptr )
{
auto newColl = new RimPolygonInViewCollection();
newColl->setPolygonFile( polygonFile );
orderedColls.push_back( newColl );
}
else
{
viewPolygonFile->updateName();
orderedColls.push_back( viewPolygonFile );
}
}
}
m_collectionsInView.clearWithoutDelete();
for ( auto viewColl : orderedColls )
{
m_collectionsInView.push_back( viewColl );
viewColl->updateAllViewItems();
}
}
updateName();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInViewCollection::syncPolygonsWithView()
{
std::vector<RimPolygonInView*> existingPolygonsInView = m_polygonsInView.childrenByType();
m_polygonsInView.clearWithoutDelete();
std::vector<RimPolygon*> polygons;
if ( m_polygonFile )
{
polygons = m_polygonFile->polygons();
}
else
{
auto polygonCollection = RimTools::polygonCollection();
polygons = polygonCollection->userDefinedPolygons();
}
std::vector<RimPolygonInView*> newPolygonsInView;
for ( auto polygon : polygons )
{
auto it = std::find_if( existingPolygonsInView.begin(),
existingPolygonsInView.end(),
[polygon]( auto* polygonInView ) { return polygonInView->polygon() == polygon; } );
if ( it != existingPolygonsInView.end() )
{
newPolygonsInView.push_back( *it );
existingPolygonsInView.erase( it );
}
else
{
auto polygonInView = new RimPolygonInView();
polygonInView->setPolygon( polygon );
newPolygonsInView.push_back( polygonInView );
}
}
m_polygonsInView.setValue( newPolygonsInView );
for ( auto polyInView : existingPolygonsInView )
{
delete polyInView;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInViewCollection::updateName()
{
QString name = "Polygons";
if ( m_polygonFile )
{
name = m_polygonFile->name();
}
setName( name );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPolygonInViewCollection* RimPolygonInViewCollection::getCollectionInViewForPolygonFile( const RimPolygonFile* polygonFile ) const
{
for ( auto collInView : m_collectionsInView )
{
if ( collInView->polygonFile() == polygonFile )
{
return collInView;
}
}
return nullptr;
}

View File

@@ -18,29 +18,47 @@
#pragma once
#include "RimCheckableObject.h"
#include "RimCheckableNamedObject.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmPointer.h"
class RimPolygonInView;
class RimPolygonFile;
class RimPolygon;
//==================================================================================================
///
///
//==================================================================================================
class RimPolygonInViewCollection : public RimCheckableObject
class RimPolygonInViewCollection : public RimCheckableNamedObject
{
CAF_PDM_HEADER_INIT;
public:
RimPolygonInViewCollection();
void syncPolygonsInView();
void updateFromPolygonCollection();
std::vector<RimPolygonInView*> polygonsInView() const;
std::vector<RimPolygonInView*> visiblePolygonsInView() const;
std::vector<RimPolygonInView*> allPolygonsInView() const;
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void setPolygonFile( RimPolygonFile* polygonFile );
RimPolygonFile* polygonFile() const;
void updateAllViewItems();
void syncCollectionsWithView();
void syncPolygonsWithView();
void updateName();
RimPolygonInViewCollection* getCollectionInViewForPolygonFile( const RimPolygonFile* polygonFile ) const;
private:
caf::PdmChildArrayField<RimPolygonInView*> m_polygons;
caf::PdmChildArrayField<RimPolygonInView*> m_polygonsInView;
caf::PdmChildArrayField<RimPolygonInViewCollection*> m_collectionsInView;
caf::PdmPointer<RimPolygonFile> m_polygonFile;
};

View File

@@ -55,7 +55,7 @@ RimPolygonInView* RimPolygonTools::findPolygonInView( RimPolygon* polygon, caf::
{
auto polyCollection = gridView->polygonInViewCollection();
for ( auto polygonInView : polyCollection->polygonsInView() )
for ( auto polygonInView : polyCollection->allPolygonsInView() )
{
if ( polygonInView && polygonInView->polygon() == polygon )
{

View File

@@ -23,7 +23,6 @@
#include "PlotTemplates/RimPlotTemplateFileItem.h"
#include "PlotTemplates/RimPlotTemplateFolderItem.h"
#include "Polygons/RimPolygonCollection.h"
#include "Rim3dOverlayInfoConfig.h"
#include "Rim3dWellLogCurveCollection.h"
#include "Rim3dWellLogExtractionCurve.h"
@@ -1139,11 +1138,6 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
{
menuBuilder << "RicAddGridCalculationFeature";
}
else if ( dynamic_cast<RimPolygonCollection*>( firstUiItem ) )
{
menuBuilder << "RicNewPolygonFeature";
menuBuilder << "RicNewPolygonFileFeature";
}
if ( dynamic_cast<Rim3dView*>( firstUiItem ) )
{

View File

@@ -1946,16 +1946,13 @@ void RimEclipseView::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrderin
if ( faultReactivationModelCollection()->shouldBeVisibleInTree() ) uiTreeOrdering.add( faultReactivationModelCollection() );
uiTreeOrdering.add( annotationCollection() );
uiTreeOrdering.add( intersectionCollection() );
uiTreeOrdering.add( m_polygonInViewCollection );
if ( surfaceInViewCollection() ) uiTreeOrdering.add( surfaceInViewCollection() );
if ( seismicSectionCollection()->shouldBeVisibleInTree() ) uiTreeOrdering.add( seismicSectionCollection() );
if ( RiaApplication::enableDevelopmentFeatures() )
{
uiTreeOrdering.add( m_polygonInViewCollection );
}
uiTreeOrdering.add( annotationCollection() );
uiTreeOrdering.skipRemainingChildren( true );
}

View File

@@ -405,16 +405,9 @@ void RimGridView::appendPolygonPartsToModel( caf::DisplayCoordTransform* scaleTr
m_polygonVizModel->removeAllParts();
std::vector<RimPolygonInView*> polygonsInView;
if ( m_polygonInViewCollection && m_polygonInViewCollection->isChecked() )
if ( m_polygonInViewCollection )
{
auto candidates = m_polygonInViewCollection->polygonsInView();
for ( auto polygonInView : candidates )
{
if ( polygonInView->isChecked() )
{
polygonsInView.push_back( polygonInView );
}
}
polygonsInView = m_polygonInViewCollection->visiblePolygonsInView();
}
if ( cellFilterCollection() && cellFilterCollection()->isActive() )
@@ -534,7 +527,7 @@ void RimGridView::updateViewTreeItems( RiaDefines::ItemIn3dView itemType )
if ( bitmaskEnum.AnyOf( RiaDefines::ItemIn3dView::POLYGON ) )
{
m_polygonInViewCollection->syncPolygonsInView();
m_polygonInViewCollection->updateFromPolygonCollection();
}
updateConnectedEditors();

View File

@@ -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 );

View File

@@ -1524,6 +1524,7 @@ void RimProject::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, Q
if ( oilField->analysisModels() ) uiTreeOrdering.add( oilField->analysisModels() );
if ( oilField->geoMechModels() ) uiTreeOrdering.add( oilField->geoMechModels() );
if ( oilField->wellPathCollection() ) uiTreeOrdering.add( oilField->wellPathCollection() );
if ( oilField->polygonCollection() ) uiTreeOrdering.add( oilField->polygonCollection() );
if ( oilField->surfaceCollection() ) uiTreeOrdering.add( oilField->surfaceCollection() );
if ( oilField->seismicDataCollection() )
{
@@ -1534,11 +1535,6 @@ void RimProject::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, Q
if ( oilField->formationNamesCollection() ) uiTreeOrdering.add( oilField->formationNamesCollection() );
if ( oilField->completionTemplateCollection() ) uiTreeOrdering.add( oilField->completionTemplateCollection() );
if ( oilField->annotationCollection() ) uiTreeOrdering.add( oilField->annotationCollection() );
if ( RiaApplication::enableDevelopmentFeatures() )
{
if ( oilField->polygonCollection() ) uiTreeOrdering.add( oilField->polygonCollection() );
}
}
uiTreeOrdering.add( colorLegendCollection() );