From bbec88b5d15c9da14759a50cc72e27b0a6e34d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Wed, 28 Nov 2018 15:00:10 +0100 Subject: [PATCH] #3773 Annotations. Set default color for line based annotations --- .../RicCreateReachCircleAnnotationFeature.cpp | 3 ++ ...eUserDefinedPolylinesAnnotationFeature.cpp | 3 ++ .../Annotations/CMakeLists_files.cmake | 2 ++ .../Annotations/RimAnnotationCollection.cpp | 9 +++-- .../Annotations/RimAnnotationColorFactory.cpp | 30 ++++++++++++++++ .../Annotations/RimAnnotationColorFactory.h | 35 +++++++++++++++++++ 6 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 ApplicationCode/ProjectDataModel/Annotations/RimAnnotationColorFactory.cpp create mode 100644 ApplicationCode/ProjectDataModel/Annotations/RimAnnotationColorFactory.h diff --git a/ApplicationCode/Commands/AnnotationCommands/RicCreateReachCircleAnnotationFeature.cpp b/ApplicationCode/Commands/AnnotationCommands/RicCreateReachCircleAnnotationFeature.cpp index d082b8175a..4889c34824 100644 --- a/ApplicationCode/Commands/AnnotationCommands/RicCreateReachCircleAnnotationFeature.cpp +++ b/ApplicationCode/Commands/AnnotationCommands/RicCreateReachCircleAnnotationFeature.cpp @@ -20,6 +20,7 @@ #include "RiaApplication.h" +#include "RimAnnotationColorFactory.h" #include "RimTextAnnotation.h" #include "RimReachCircleAnnotation.h" #include "RimPolylinesAnnotation.h" @@ -56,6 +57,8 @@ void RicCreateReachCircleAnnotationFeature::onActionTriggered(bool isChecked) if (coll) { auto newAnnotation = new RimReachCircleAnnotation(); + auto newColor = RimAnnotationColorFactory::getColor(coll->lineBasedAnnotationsCount()); + newAnnotation->appearance()->setColor(newColor); coll->addAnnotation(newAnnotation); coll->updateConnectedEditors(); RiuMainWindow::instance()->selectAsCurrentItem(newAnnotation); diff --git a/ApplicationCode/Commands/AnnotationCommands/RicCreateUserDefinedPolylinesAnnotationFeature.cpp b/ApplicationCode/Commands/AnnotationCommands/RicCreateUserDefinedPolylinesAnnotationFeature.cpp index 1b31d95ac0..2cb46183e3 100644 --- a/ApplicationCode/Commands/AnnotationCommands/RicCreateUserDefinedPolylinesAnnotationFeature.cpp +++ b/ApplicationCode/Commands/AnnotationCommands/RicCreateUserDefinedPolylinesAnnotationFeature.cpp @@ -20,6 +20,7 @@ #include "RiaApplication.h" +#include "RimAnnotationColorFactory.h" #include "RimTextAnnotation.h" #include "RimReachCircleAnnotation.h" #include "RimUserDefinedPolylinesAnnotation.h" @@ -56,6 +57,8 @@ void RicCreateUserDefinedPolylinesAnnotationFeature::onActionTriggered(bool isCh if (coll) { auto newAnnotation = new RimUserDefinedPolylinesAnnotation(); + auto newColor = RimAnnotationColorFactory::getColor(coll->lineBasedAnnotationsCount()); + newAnnotation->appearance()->setColor(newColor); coll->addAnnotation(newAnnotation); coll->updateConnectedEditors(); RiuMainWindow::instance()->selectAsCurrentItem(newAnnotation); diff --git a/ApplicationCode/ProjectDataModel/Annotations/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/Annotations/CMakeLists_files.cmake index a4b31f31e5..8ec697e300 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/Annotations/CMakeLists_files.cmake @@ -10,6 +10,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimTextAnnotation.h ${CMAKE_CURRENT_LIST_DIR}/RimAnnotationInViewCollection.h ${CMAKE_CURRENT_LIST_DIR}/RimAnnotationLineAppearance.h ${CMAKE_CURRENT_LIST_DIR}/RimLineBasedAnnotation.h +${CMAKE_CURRENT_LIST_DIR}/RimAnnotationColorFactory.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -23,6 +24,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimTextAnnotation.cpp ${CMAKE_CURRENT_LIST_DIR}/RimAnnotationInViewCollection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimAnnotationLineAppearance.cpp ${CMAKE_CURRENT_LIST_DIR}/RimLineBasedAnnotation.cpp +${CMAKE_CURRENT_LIST_DIR}/RimAnnotationColorFactory.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationCollection.cpp b/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationCollection.cpp index 48a7dbedb7..76eac2116c 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationCollection.cpp @@ -20,6 +20,7 @@ #include "RiaApplication.h" +#include "RimAnnotationColorFactory.h" #include "RimTextAnnotation.h" #include "RimReachCircleAnnotation.h" #include "RimPolylinesFromFileAnnotation.h" @@ -134,7 +135,6 @@ RimPolylinesFromFileAnnotation* RimAnnotationCollection::importOrUpdatePolylines { QStringList newFileNames; std::vector polyLinesObjsToReload; - size_t formationListBeforeImportCount = m_polylineFromFileAnnotations.size(); for(const QString& newFileName : fileNames) { @@ -160,7 +160,7 @@ RimPolylinesFromFileAnnotation* RimAnnotationCollection::importOrUpdatePolylines { RimPolylinesFromFileAnnotation* newPolyLinesAnnot = new RimPolylinesFromFileAnnotation; - auto newColor = RiaColorTables::categoryPaletteColors().cycledColor3f(formationListBeforeImportCount + newLinesIdx); + auto newColor = RimAnnotationColorFactory::getColor(lineBasedAnnotationsCount()); newPolyLinesAnnot->setFileName(newFileName); newPolyLinesAnnot->setDescriptionFromFileName(); @@ -174,10 +174,9 @@ RimPolylinesFromFileAnnotation* RimAnnotationCollection::importOrUpdatePolylines reloadPolylinesFromFile(polyLinesObjsToReload); - - if (m_polylineFromFileAnnotations.size() > formationListBeforeImportCount) + if (!newFileNames.empty()) { - return m_polylineFromFileAnnotations[m_polylineFromFileAnnotations.size() - 1]; + return m_polylineFromFileAnnotations.childObjects().back(); } else { diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationColorFactory.cpp b/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationColorFactory.cpp new file mode 100644 index 0000000000..4e439610be --- /dev/null +++ b/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationColorFactory.cpp @@ -0,0 +1,30 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RimAnnotationColorFactory.h" + +#include "RiaColorTables.h" + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Color3f RimAnnotationColorFactory::getColor(int index) +{ + return RiaColorTables::categoryPaletteColors().cycledColor3f(index); +} diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationColorFactory.h b/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationColorFactory.h new file mode 100644 index 0000000000..c81d51704a --- /dev/null +++ b/ApplicationCode/ProjectDataModel/Annotations/RimAnnotationColorFactory.h @@ -0,0 +1,35 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018- Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include + + + +//================================================================================================== +/// +/// +//================================================================================================== +class RimAnnotationColorFactory +{ +public: + static cvf::Color3f getColor(int index); +}; +