comparison Framework/Scene2DViewport/LayerHolder.cpp @ 751:712ff6ff3c19

- undo redo now works fine for both measure tool creation commands - added LayerHolder to streamline layer index management - added overloads for ORTHANC_ASSERT with no string message (some heavy preprocessor wizardry in there) - fixing wasm BasicScene is *not* finished.
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 22 May 2019 11:55:52 +0200
parents
children e42b491f1fb2
comparison
equal deleted inserted replaced
750:284f37dc1c66 751:712ff6ff3c19
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-2019 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 "../Scene2DViewport/ViewportController.h"
26 #include "../StoneException.h"
27
28 using namespace Orthanc;
29
30 namespace OrthancStone
31 {
32 LayerHolder::LayerHolder(
33 ViewportControllerWPtr controllerW,
34 int polylineLayerCount,
35 int textLayerCount)
36 : textLayerCount_(textLayerCount)
37 , polylineLayerCount_(polylineLayerCount)
38 , controllerW_(controllerW)
39 , baseLayerIndex_(-1)
40 {
41
42 }
43
44 void LayerHolder::CreateLayers()
45 {
46 assert(baseLayerIndex_ == -1);
47
48 baseLayerIndex_ = GetScene()->GetMaxDepth() + 100;
49
50 for (int i = 0; i < polylineLayerCount_; ++i)
51 {
52 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer());
53 GetScene()->SetLayer(baseLayerIndex_ + i, layer.release());
54 }
55
56 for (int i = 0; i < textLayerCount_; ++i)
57 {
58 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer());
59 GetScene()->SetLayer(
60 baseLayerIndex_ + polylineLayerCount_ + i,
61 layer.release());
62 }
63
64 }
65
66 void LayerHolder::CreateLayersIfNeeded()
67 {
68 if (baseLayerIndex_ == -1)
69 CreateLayers();
70 }
71
72 bool LayerHolder::AreLayersCreated() const
73 {
74 return (baseLayerIndex_ != -1);
75 }
76
77 OrthancStone::Scene2DPtr LayerHolder::GetScene()
78 {
79 ViewportControllerPtr controller = controllerW_.lock();
80 ORTHANC_ASSERT(controller.get() != 0, "Zombie attack!");
81 return controller->GetScene();
82 }
83
84 void LayerHolder::DeleteLayers()
85 {
86 for (int i = 0; i < textLayerCount_ + polylineLayerCount_; ++i)
87 {
88 ORTHANC_ASSERT(GetScene()->HasLayer(baseLayerIndex_ + i), "No layer");
89 GetScene()->DeleteLayer(baseLayerIndex_ + i);
90 }
91 baseLayerIndex_ = -1;
92 }
93
94 PolylineSceneLayer* LayerHolder::GetPolylineLayer(int index /*= 0*/)
95 {
96 ORTHANC_ASSERT(baseLayerIndex_ != -1);
97 ORTHANC_ASSERT(GetScene()->HasLayer(GetPolylineLayerIndex(index)));
98 ISceneLayer* layer =
99 &(GetScene()->GetLayer(GetPolylineLayerIndex(index)));
100
101 PolylineSceneLayer* concreteLayer =
102 dynamic_cast<PolylineSceneLayer*>(layer);
103
104 ORTHANC_ASSERT(concreteLayer != NULL);
105 return concreteLayer;
106 }
107
108 TextSceneLayer* LayerHolder::GetTextLayer(int index /*= 0*/)
109 {
110 ORTHANC_ASSERT(baseLayerIndex_ != -1);
111 ORTHANC_ASSERT(GetScene()->HasLayer(GetTextLayerIndex(index)));
112 ISceneLayer* layer =
113 &(GetScene()->GetLayer(GetTextLayerIndex(index)));
114
115 TextSceneLayer* concreteLayer =
116 dynamic_cast<TextSceneLayer*>(layer);
117
118 ORTHANC_ASSERT(concreteLayer != NULL);
119 return concreteLayer;
120 }
121
122 int LayerHolder::GetPolylineLayerIndex(int index /*= 0*/)
123 {
124 ORTHANC_ASSERT(index < polylineLayerCount_);
125 return baseLayerIndex_ + index;
126 }
127
128
129 int LayerHolder::GetTextLayerIndex(int index /*= 0*/)
130 {
131 ORTHANC_ASSERT(index < textLayerCount_);
132
133 // the text layers are placed right after the polyline layers
134 // this means they are drawn ON TOP
135 return baseLayerIndex_ + polylineLayerCount_ + index;
136 }
137 }