#3724 Added cycling default color to polyline import. Set default line thickness to 2.

Refactored away unneccesary complexity. loadAndUpdate when opening project file. Toggle now working
This commit is contained in:
Jacob Støren 2018-11-27 17:53:56 +01:00
parent d138770a2a
commit 29e6e08779
11 changed files with 114 additions and 138 deletions

View File

@ -37,6 +37,7 @@
#include "HoloLensCommands/RicHoloLensSessionManager.h"
#include "Rim2dIntersectionViewCollection.h"
#include "RimAnnotationCollection.h"
#include "RimCellRangeFilterCollection.h"
#include "RimCommandObject.h"
#include "RimEclipseCaseCollection.h"
@ -611,6 +612,8 @@ bool RiaApplication::loadProject(const QString& projectFileName, ProjectLoadActi
{
sumCaseGroup->loadDataAndUpdate();
}
oilField->annotationCollection()->loadDataAndUpdate();
}
loadAndUpdatePlotData();

View File

@ -56,7 +56,7 @@ void RivPolylineAnnotationPartMgr::buildPolylineAnnotationParts(const caf::Displ
{
clearAllGeometry();
if (!m_rimAnnotation->isEmpty())
if (!m_rimAnnotation->isEmpty() && m_rimAnnotation->isActive())
{
const auto& points = m_rimAnnotation->polyLinesData();
auto lineColor = m_rimAnnotation->appearance()->color();
@ -111,6 +111,10 @@ void RivPolylineAnnotationPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelB
if (m_rimAnnotation->isEmpty()) return;
buildPolylineAnnotationParts(displayXf);
model->addPart(m_part.p());
if ( m_part.notNull() )
{
model->addPart(m_part.p());
}
}

View File

@ -30,6 +30,7 @@
#include "QMessageBox"
#include <QString>
#include "RiaColorTables.h"
CAF_PDM_SOURCE_INIT(RimAnnotationCollection, "RimAnnotationCollection");
@ -159,33 +160,25 @@ RimPolylinesFromFileAnnotation* RimAnnotationCollection::importOrUpdatePolylines
}
}
size_t newLinesIdx = 0;
for(const QString& newFileName : newFileNames)
{
RimPolylinesFromFileAnnotation* newPolyLinesAnnot = new RimPolylinesFromFileAnnotation;
auto newColor = RiaColorTables::categoryPaletteColors().cycledColor3f(formationListBeforeImportCount + newLinesIdx);
newPolyLinesAnnot->setFileName(newFileName);
newPolyLinesAnnot->setDescriptionFromFileName();
newPolyLinesAnnot->appearance()->setColor(newColor);
m_polylineFromFileAnnotations.push_back(newPolyLinesAnnot);
polyLinesObjsToReload.push_back(newPolyLinesAnnot);
newPolyLinesAnnot->setDescriptionFromFileName();
++newLinesIdx;
}
QString totalErrorMessage;
reloadPolylinesFromFile(polyLinesObjsToReload);
for (RimPolylinesFromFileAnnotation* polyLinesAnnot: polyLinesObjsToReload)
{
QString errormessage;
polyLinesAnnot->readPolyLinesFile(&errormessage);
if (!errormessage.isEmpty())
{
totalErrorMessage += "\nError in: " + polyLinesAnnot->fileName()
+ "\n\t" + errormessage;
}
}
if (!totalErrorMessage.isEmpty())
{
QMessageBox::warning(nullptr, "Import Formation Names", totalErrorMessage);
}
if (m_polylineFromFileAnnotations.size() > formationListBeforeImportCount)
{
@ -198,6 +191,31 @@ RimPolylinesFromFileAnnotation* RimAnnotationCollection::importOrUpdatePolylines
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAnnotationCollection::reloadPolylinesFromFile(const std::vector<RimPolylinesFromFileAnnotation *>& polyLinesObjsToReload)
{
QString totalErrorMessage;
for ( RimPolylinesFromFileAnnotation* polyLinesAnnot: polyLinesObjsToReload )
{
QString errormessage;
polyLinesAnnot->readPolyLinesFile(&errormessage);
if ( !errormessage.isEmpty() )
{
totalErrorMessage += "\nError in: " + polyLinesAnnot->fileName()
+ "\n\t" + errormessage;
}
}
if ( !totalErrorMessage.isEmpty() )
{
QMessageBox::warning(nullptr, "Import Formation Names", totalErrorMessage);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -235,3 +253,11 @@ std::vector<RimGridView*> RimAnnotationCollection::gridViewsContainingAnnotation
}
return views;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAnnotationCollection::loadDataAndUpdate()
{
reloadPolylinesFromFile(m_polylineFromFileAnnotations.childObjects());
}

View File

@ -43,6 +43,8 @@ public:
RimAnnotationCollection();
~RimAnnotationCollection() override;
void loadDataAndUpdate();
void addAnnotation(RimTextAnnotation* annotation);
void addAnnotation(RimReachCircleAnnotation* annotation);
void addAnnotation(RimPolylinesAnnotation* annotation);
@ -55,10 +57,13 @@ public:
void onAnnotationDeleted();
RimPolylinesFromFileAnnotation* importOrUpdatePolylinesFromFile(const QStringList& fileNames );
void scheduleRedrawOfRelevantViews();
std::vector<RimGridView*> gridViewsContainingAnnotations() const;
private:
void reloadPolylinesFromFile(const std::vector<RimPolylinesFromFileAnnotation *>& polyLinesObjsToReload);
caf::PdmChildArrayField<RimTextAnnotation*> m_textAnnotations;
caf::PdmChildArrayField<RimReachCircleAnnotation*> m_reachCircleAnnotations;
caf::PdmChildArrayField<RimPolylinesAnnotation*> m_polylineAnnotations;

View File

@ -55,6 +55,7 @@
#include <fstream>
#include "RimFileWellPath.h"
#include "RimModeledWellPath.h"
#include "RimAnnotationCollection.h"
namespace caf
{
@ -79,11 +80,22 @@ RimAnnotationLineAppearance::RimAnnotationLineAppearance()
{
CAF_PDM_InitObject("TextAnnotation", ":/WellCollection.png", "", "");
CAF_PDM_InitField(&m_color, "Color", cvf::Color3f(cvf::Color3f::BLACK), "Color", "", "", "");
CAF_PDM_InitField(&m_style, "Style", LineStyle(), "Style", "", "", "");
CAF_PDM_InitField(&m_thickness, "Thickness", 1, "Thickness", "", "", "");
CAF_PDM_InitField(&m_color, "Color", cvf::Color3f(cvf::Color3f::BLACK), "Color", "", "", "");
CAF_PDM_InitField(&m_thickness, "Thickness", 2, "Thickness", "", "", "");
m_fieldChangedByUiCallback = nullptr;
// Stippling not yet supported. Needs new stuff in VizFwk
CAF_PDM_InitField(&m_style, "Style", LineStyle(), "Style", "", "", "");
m_style.uiCapability()->setUiHidden(true);
m_style.xmlCapability()->disableIO();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAnnotationLineAppearance::setColor(const cvf::Color3f& newColor)
{
m_color = newColor;
}
//--------------------------------------------------------------------------------------------------
@ -110,38 +122,6 @@ int RimAnnotationLineAppearance::thickness() const
return m_thickness();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const caf::PdmFieldHandle* RimAnnotationLineAppearance::colorField() const
{
return &m_color;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const caf::PdmFieldHandle* RimAnnotationLineAppearance::styleField() const
{
return &m_style;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const caf::PdmFieldHandle* RimAnnotationLineAppearance::thicknessField() const
{
return &m_thickness;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAnnotationLineAppearance::registerFieldChangedByUiCallback(FieldChangedByUiDelegate func)
{
m_fieldChangedByUiCallback = func;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -161,8 +141,7 @@ void RimAnnotationLineAppearance::fieldChangedByUi(const caf::PdmFieldHandle* ch
const QVariant& oldValue,
const QVariant& newValue)
{
if (m_fieldChangedByUiCallback)
{
m_fieldChangedByUiCallback(changedField, oldValue, newValue);
}
RimAnnotationCollection* annColl = nullptr;
this->firstAncestorOrThisOfTypeAsserted(annColl);
annColl->scheduleRedrawOfRelevantViews();
}

View File

@ -28,12 +28,8 @@
// Include to make Pdm work for cvf::Color
#include "cafPdmFieldCvfColor.h"
#include "cafPdmChildField.h"
#include "cafPdmFieldCvfVec3d.h"
#include "cvfObject.h"
#include "cvfVector3.h"
#include <vector>
class QString;
class RimGridView;
@ -45,18 +41,9 @@ class RimGridView;
//==================================================================================================
class RimAnnotationLineAppearance : public caf::PdmObject
{
// Friends
friend class RimReachCircleAnnotation;
friend class RimUserDefinedPolylinesAnnotation;
friend class RimPolylinesFromFileAnnotation;
using Vec3d = cvf::Vec3d;
CAF_PDM_HEADER_INIT;
public:
using FieldChangedByUiDelegate = std::function<void(const caf::PdmFieldHandle*, const QVariant&, const QVariant&)>;
enum LineStyleEnum
{
STYLE_SOLID,
@ -66,17 +53,11 @@ public:
public:
RimAnnotationLineAppearance();
void setColor(const cvf::Color3f& newColor);
cvf::Color3f color() const;
bool isDashed() const;
int thickness() const;
const caf::PdmFieldHandle* colorField() const;
const caf::PdmFieldHandle* styleField() const;
const caf::PdmFieldHandle* thicknessField() const;
void registerFieldChangedByUiCallback(FieldChangedByUiDelegate func);
protected:
void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
@ -86,6 +67,5 @@ private:
caf::PdmField<LineStyle> m_style;
caf::PdmField<int> m_thickness;
FieldChangedByUiDelegate m_fieldChangedByUiCallback;
};

View File

@ -32,10 +32,6 @@ RimLineBasedAnnotation::RimLineBasedAnnotation()
m_appearance.uiCapability()->setUiTreeHidden(true);
m_appearance.uiCapability()->setUiTreeChildrenHidden(true);
m_appearance->registerFieldChangedByUiCallback(
[this](const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) {
this->fieldChangedByUi(changedField, oldValue, newValue);
});
}
//--------------------------------------------------------------------------------------------------

View File

@ -53,9 +53,6 @@ public:
RimLineBasedAnnotation();
RimAnnotationLineAppearance* appearance() const;
protected:
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override {};
private:
caf::PdmChildField<RimAnnotationLineAppearance*> m_appearance;
};

View File

@ -48,6 +48,13 @@ RimPolylinesAnnotation::~RimPolylinesAnnotation()
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPolylinesAnnotation::isActive()
{
return m_isActive();
}
//--------------------------------------------------------------------------------------------------
///
@ -106,7 +113,7 @@ void RimUserDefinedPolylinesAnnotation::defineUiOrdering(QString uiConfigName, c
uiOrdering.add(&m_points);
auto appearanceGroup = uiOrdering.addNewGroup("Line Appearance");
appearance()->defineUiOrdering(uiConfigName, *appearanceGroup);
appearance()->uiOrdering(uiConfigName, *appearanceGroup);
uiOrdering.skipRemainingFields(true);
}
@ -119,11 +126,9 @@ void RimUserDefinedPolylinesAnnotation::fieldChangedByUi(const caf::PdmFieldHand
const QVariant& newValue)
{
RimAnnotationCollection* annColl = nullptr;
this->firstAncestorOrThisOfType(annColl);
if (annColl)
{
annColl->scheduleRedrawOfRelevantViews();
}
this->firstAncestorOrThisOfTypeAsserted(annColl);
annColl->scheduleRedrawOfRelevantViews();
}
@ -138,7 +143,7 @@ RimPolylinesFromFileAnnotation::RimPolylinesFromFileAnnotation()
{
CAF_PDM_InitObject("PolyLines Annotation", ":/WellCollection.png", "", "");
CAF_PDM_InitField(&m_polyLinesFileName, "PolyLineFilePath", QString(""), "File Path", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_polyLinesFileName, "PolyLineFilePath", "File Path", "", "", "");
m_polyLinesFileName.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_userDescription, "PolyLineDescription", QString(""), "Name", "", "", "");
@ -163,9 +168,9 @@ void RimPolylinesFromFileAnnotation::setFileName(const QString& fileName)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const QString& RimPolylinesFromFileAnnotation::fileName()
QString RimPolylinesFromFileAnnotation::fileName() const
{
return m_polyLinesFileName();
return m_polyLinesFileName().path();
}
//--------------------------------------------------------------------------------------------------
@ -173,11 +178,11 @@ const QString& RimPolylinesFromFileAnnotation::fileName()
//--------------------------------------------------------------------------------------------------
void RimPolylinesFromFileAnnotation::readPolyLinesFile(QString * errorMessage)
{
QFile dataFile(m_polyLinesFileName());
QFile dataFile(m_polyLinesFileName().path());
if (!dataFile.open(QFile::ReadOnly))
{
if (errorMessage) (*errorMessage) += "Could not open the File: " + (m_polyLinesFileName()) + "\n";
if (errorMessage) (*errorMessage) += "Could not open the File: " + (m_polyLinesFileName().path()) + "\n";
return;
}
@ -244,7 +249,8 @@ void RimPolylinesFromFileAnnotation::readPolyLinesFile(QString * errorMessage)
//--------------------------------------------------------------------------------------------------
bool RimPolylinesFromFileAnnotation::isEmpty()
{
bool isThisEmpty = true;
if (m_polyLinesData.isNull()) return true;
for (const std::vector<cvf::Vec3d> & line :m_polyLinesData->polyLines())
{
if (!line.empty()) return false;
@ -253,21 +259,13 @@ bool RimPolylinesFromFileAnnotation::isEmpty()
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolylinesFromFileAnnotation::updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath)
{
m_polyLinesFileName = RimTools::relocateFile(m_polyLinesFileName(), newProjectPath, oldProjectPath, nullptr, nullptr);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolylinesFromFileAnnotation::setDescriptionFromFileName()
{
QFileInfo fileInfo(m_polyLinesFileName());
QFileInfo fileInfo(m_polyLinesFileName().path());
m_userDescription = fileInfo.fileName();
}
@ -277,8 +275,9 @@ void RimPolylinesFromFileAnnotation::setDescriptionFromFileName()
//--------------------------------------------------------------------------------------------------
void RimPolylinesFromFileAnnotation::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
uiOrdering.add(&m_polyLinesFileName);
auto appearanceGroup = uiOrdering.addNewGroup("Line Appearance");
appearance()->defineUiOrdering(uiConfigName, *appearanceGroup);
appearance()->uiOrdering(uiConfigName, *appearanceGroup);
uiOrdering.skipRemainingFields(true);
}
@ -291,11 +290,9 @@ void RimPolylinesFromFileAnnotation::fieldChangedByUi(const caf::PdmFieldHandle*
const QVariant& newValue)
{
RimAnnotationCollection* annColl = nullptr;
this->firstAncestorOrThisOfType(annColl);
if (annColl)
{
annColl->scheduleRedrawOfRelevantViews();
}
this->firstAncestorOrThisOfTypeAsserted(annColl);
annColl->scheduleRedrawOfRelevantViews();
}
//--------------------------------------------------------------------------------------------------

View File

@ -44,7 +44,7 @@ class RigPolyLinesData;
///
///
//==================================================================================================
class RimPolylinesAnnotation : public RimLineBasedAnnotation// caf::PdmObject
class RimPolylinesAnnotation : public RimLineBasedAnnotation
{
using Vec3d = cvf::Vec3d;
@ -54,14 +54,15 @@ public:
RimPolylinesAnnotation();
~RimPolylinesAnnotation();
bool isActive();
virtual cvf::ref<RigPolyLinesData> polyLinesData() = 0;
virtual bool isEmpty() = 0;
protected:
virtual caf::PdmFieldHandle* objectToggleField() override;
private:
caf::PdmField<std::vector<Vec3d>> m_points;
caf::PdmField<bool> m_isActive;
};
@ -104,14 +105,12 @@ public:
~RimPolylinesFromFileAnnotation();
void setFileName(const QString& fileName);
const QString& fileName();
QString fileName() const;
void readPolyLinesFile(QString * errorMessage);
cvf::ref<RigPolyLinesData> polyLinesData() override { return m_polyLinesData;}
virtual bool isEmpty() override;
void updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath);
void setDescriptionFromFileName();
protected:
@ -122,7 +121,7 @@ private:
virtual caf::PdmFieldHandle* userDescriptionField() override;
caf::PdmField<QString> m_userDescription;
caf::PdmField<QString> m_polyLinesFileName;
caf::PdmField<caf::FilePath> m_polyLinesFileName;
cvf::ref<RigPolyLinesData> m_polyLinesData;
};

View File

@ -21,6 +21,7 @@
#include "RimAnnotationInViewCollection.h"
#include "RimGridView.h"
#include "RimProject.h"
#include "RimAnnotationCollection.h"
CAF_PDM_SOURCE_INIT(RimReachCircleAnnotation, "RimReachCircleAnnotation");
@ -62,7 +63,7 @@ void RimReachCircleAnnotation::defineUiOrdering(QString uiConfigName, caf::PdmUi
uiOrdering.add(&m_radius);
auto appearanceGroup = uiOrdering.addNewGroup("Line Appearance");
appearance()->defineUiOrdering(uiConfigName, *appearanceGroup);
appearance()->uiOrdering(uiConfigName, *appearanceGroup);
uiOrdering.skipRemainingFields(true);
}
@ -74,21 +75,10 @@ void RimReachCircleAnnotation::fieldChangedByUi(const caf::PdmFieldHandle* chang
const QVariant& oldValue,
const QVariant& newValue)
{
auto views = gridViewsContainingAnnotations();
if (!views.empty())
{
if (changedField == &m_centerPoint ||
changedField == &m_radius ||
changedField == appearance()->colorField() ||
changedField == appearance()->styleField() ||
changedField == appearance()->thicknessField())
{
for (auto& view : views)
{
view->scheduleCreateDisplayModelAndRedraw();
}
}
}
RimAnnotationCollection* annColl = nullptr;
this->firstAncestorOrThisOfTypeAsserted(annColl);
annColl->scheduleRedrawOfRelevantViews();
}
//--------------------------------------------------------------------------------------------------