comparison OrthancStone/Sources/Scene2DViewport/LayerHolder.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Scene2DViewport/LayerHolder.cpp@ab81ee8fce1f
children 314b6dc507d9
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21 #include "LayerHolder.h"
22 #include "../Scene2D/TextSceneLayer.h"
23 #include "../Scene2D/PolylineSceneLayer.h"
24 #include "../Scene2D/Scene2D.h"
25 #include "../Viewport/IViewport.h"
26 #include "../StoneException.h"
27
28 namespace OrthancStone
29 {
30 LayerHolder::LayerHolder(
31 boost::shared_ptr<IViewport> viewport,
32 int polylineLayerCount,
33 int textLayerCount,
34 int infoTextCount)
35 : textLayerCount_(textLayerCount)
36 , polylineLayerCount_(polylineLayerCount)
37 , infoTextCount_(infoTextCount)
38 , viewport_(viewport)
39 , baseLayerIndex_(-1)
40 {
41
42 }
43
44 void LayerHolder::CreateLayers()
45 {
46 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
47 ViewportController& controller = lock->GetController();
48 Scene2D& scene = controller.GetScene();
49
50 assert(baseLayerIndex_ == -1);
51
52 baseLayerIndex_ = scene.GetMaxDepth() + 100;
53
54 for (int i = 0; i < polylineLayerCount_; ++i)
55 {
56 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer());
57 scene.SetLayer(baseLayerIndex_ + i, layer.release());
58 }
59
60 for (int i = 0; i < textLayerCount_; ++i)
61 {
62 std::unique_ptr<TextSceneLayer> layer(new TextSceneLayer());
63 scene.SetLayer(baseLayerIndex_ + polylineLayerCount_ + i, layer.release());
64 }
65 lock->Invalidate();
66 }
67
68 void LayerHolder::CreateLayersIfNeeded()
69 {
70 if (baseLayerIndex_ == -1)
71 CreateLayers();
72 }
73
74 bool LayerHolder::AreLayersCreated() const
75 {
76 return (baseLayerIndex_ != -1);
77 }
78
79 void LayerHolder::DeleteLayersIfNeeded()
80 {
81 if (baseLayerIndex_ != -1)
82 DeleteLayers();
83 }
84
85 void LayerHolder::DeleteLayers()
86 {
87 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
88 Scene2D& scene = lock->GetController().GetScene();
89
90 for (int i = 0; i < textLayerCount_ + polylineLayerCount_; ++i)
91 {
92 ORTHANC_ASSERT(scene.HasLayer(baseLayerIndex_ + i), "No layer");
93 scene.DeleteLayer(baseLayerIndex_ + i);
94 }
95 baseLayerIndex_ = -1;
96 lock->Invalidate();
97 }
98
99 PolylineSceneLayer* LayerHolder::GetPolylineLayer(int index /*= 0*/)
100 {
101 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
102 Scene2D& scene = lock->GetController().GetScene();
103
104 using namespace Orthanc;
105 ORTHANC_ASSERT(baseLayerIndex_ != -1);
106 ORTHANC_ASSERT(scene.HasLayer(GetPolylineLayerIndex(index)));
107 ISceneLayer* layer = &(scene.GetLayer(GetPolylineLayerIndex(index)));
108
109 PolylineSceneLayer* concreteLayer =
110 dynamic_cast<PolylineSceneLayer*>(layer);
111
112 ORTHANC_ASSERT(concreteLayer != NULL);
113 return concreteLayer;
114 }
115
116 TextSceneLayer* LayerHolder::GetTextLayer(int index /*= 0*/)
117 {
118 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
119 Scene2D& scene = lock->GetController().GetScene();
120
121 using namespace Orthanc;
122 ORTHANC_ASSERT(baseLayerIndex_ != -1);
123 ORTHANC_ASSERT(scene.HasLayer(GetTextLayerIndex(index)));
124 ISceneLayer* layer = &(scene.GetLayer(GetTextLayerIndex(index)));
125
126 TextSceneLayer* concreteLayer =
127 dynamic_cast<TextSceneLayer*>(layer);
128
129 ORTHANC_ASSERT(concreteLayer != NULL);
130 return concreteLayer;
131 }
132
133 int LayerHolder::GetPolylineLayerIndex(int index /*= 0*/)
134 {
135 using namespace Orthanc;
136 ORTHANC_ASSERT(index < polylineLayerCount_);
137 return baseLayerIndex_ + index;
138 }
139
140 int LayerHolder::GetTextLayerIndex(int index /*= 0*/)
141 {
142 using namespace Orthanc;
143 ORTHANC_ASSERT(index < textLayerCount_);
144
145 // the text layers are placed right after the polyline layers
146 // this means they are drawn ON TOP
147 return baseLayerIndex_ + polylineLayerCount_ + index;
148 }
149 }