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); +}; +