annotate OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 1821:36430d73e36c

introducing measure units in AnnotationsSceneLayer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 26 May 2021 14:02:12 +0200
parents fe402c678d18
children 781e9fc8925e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Lesser General Public License for more details.
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * License along with this program. If not, see
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * <http://www.gnu.org/licenses/>.
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "AnnotationsSceneLayer.h"
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "MacroSceneLayer.h"
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "PolylineSceneLayer.h"
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "TextSceneLayer.h"
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <OrthancException.h>
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <boost/math/constants/constants.hpp>
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <list>
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 static const double HANDLE_SIZE = 10.0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 static const double PI = boost::math::constants::pi<double>();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 static const char* const KEY_ANNOTATIONS = "annotations";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 static const char* const KEY_TYPE = "type";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 static const char* const KEY_X1 = "x1";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 static const char* const KEY_Y1 = "y1";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 static const char* const KEY_X2 = "x2";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 static const char* const KEY_Y2 = "y2";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 static const char* const KEY_X3 = "x3";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 static const char* const KEY_Y3 = "y3";
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
45 static const char* const KEY_UNITS = "units";
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 static const char* const VALUE_ANGLE = "angle";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 static const char* const VALUE_CIRCLE = "circle";
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 static const char* const VALUE_SEGMENT = "segment";
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
50 static const char* const VALUE_MILLIMETERS = "millimeters";
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
51 static const char* const VALUE_PIXELS = "pixels";
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
1819
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
53 #if 0
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
54 static OrthancStone::Color COLOR_PRIMITIVES(192, 192, 192);
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
55 static OrthancStone::Color COLOR_HOVER(0, 255, 0);
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
56 static OrthancStone::Color COLOR_TEXT(255, 0, 0);
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
57 #else
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
58 static OrthancStone::Color COLOR_PRIMITIVES(0x40, 0x82, 0xad);
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
59 static OrthancStone::Color COLOR_HOVER(0x40, 0xad, 0x79);
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
60 static OrthancStone::Color COLOR_TEXT(0x4e, 0xde, 0x99);
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
61 #endif
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
62
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 namespace OrthancStone
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 class AnnotationsSceneLayer::GeometricPrimitive : public boost::noncopyable
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 bool modified_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 Annotation& parentAnnotation_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 Color color_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 Color hoverColor_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 bool isHover_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 int depth_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 GeometricPrimitive(Annotation& parentAnnotation,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 int depth) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 modified_(true),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 parentAnnotation_(parentAnnotation),
1819
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
81 color_(COLOR_PRIMITIVES),
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
82 hoverColor_(COLOR_HOVER),
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 isHover_(false),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 depth_(depth)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 virtual ~GeometricPrimitive()
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 Annotation& GetParentAnnotation() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 return parentAnnotation_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 int GetDepth() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return depth_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 void SetHover(bool hover)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 if (hover != isHover_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 isHover_ = hover;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 modified_ = true;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 bool IsHover() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return isHover_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 void SetModified(bool modified)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 modified_ = modified;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 bool IsModified() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 return modified_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 void SetColor(const Color& color)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 color_ = color;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 void SetHoverColor(const Color& color)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 hoverColor_ = color;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 const Color& GetColor() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 return color_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 const Color& GetHoverColor() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 return hoverColor_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 virtual bool IsHit(const ScenePoint2D& p,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 const Scene2D& scene) const = 0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 // Always called, even if not modified
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 const Scene2D& scene) = 0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 // Only called if modified
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 virtual void RenderOtherLayers(MacroSceneLayer& macro,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 const Scene2D& scene) = 0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 virtual void MovePreview(const ScenePoint2D& delta) = 0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 virtual void MoveDone(const ScenePoint2D& delta) = 0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 class AnnotationsSceneLayer::Annotation : public boost::noncopyable
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 typedef std::list<GeometricPrimitive*> GeometricPrimitives;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 AnnotationsSceneLayer& that_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 GeometricPrimitives primitives_;
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
172 Units units_;
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 public:
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
175 explicit Annotation(AnnotationsSceneLayer& that,
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
176 Units units) :
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
177 that_(that),
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
178 units_(units)
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 that.AddAnnotation(this);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 virtual ~Annotation()
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 that_.DeletePrimitive(*it);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
191 Units GetUnits() const
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
192 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
193 return units_;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
194 }
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
195
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 GeometricPrimitive* AddPrimitive(GeometricPrimitive* primitive)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 if (primitive == NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 assert(that_.primitives_.find(primitive) == that_.primitives_.end());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 primitives_.push_back(primitive); // For automated deallocation
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 that_.primitives_.insert(primitive);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 return primitive;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 template <typename T>
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 T& AddTypedPrimitive(T* primitive)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 AddPrimitive(primitive);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 return *primitive;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 virtual void SignalMove(GeometricPrimitive& primitive) = 0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 virtual void Serialize(Json::Value& target) = 0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 class AnnotationsSceneLayer::Handle : public GeometricPrimitive
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 ScenePoint2D center_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 ScenePoint2D delta_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 explicit Handle(Annotation& parentAnnotation,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 const ScenePoint2D& center) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 GeometricPrimitive(parentAnnotation, 0), // Highest priority
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 center_(center),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 delta_(0, 0)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 void SetSize(unsigned int size)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 void SetCenter(const ScenePoint2D& center)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 center_ = center;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 delta_ = ScenePoint2D(0, 0);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 ScenePoint2D GetCenter() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 return center_ + delta_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 virtual bool IsHit(const ScenePoint2D& p,
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
257 const Scene2D& scene) const ORTHANC_OVERRIDE
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 double dx = (center_.GetX() + delta_.GetX() - p.GetX()) * zoom;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 double dy = (center_.GetY() + delta_.GetY() - p.GetY()) * zoom;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 return (std::abs(dx) <= HANDLE_SIZE / 2.0 &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 std::abs(dy) <= HANDLE_SIZE / 2.0);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 // TODO: take DPI into account
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 double x1 = center_.GetX() + delta_.GetX() - (HANDLE_SIZE / 2.0) / zoom;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 double y1 = center_.GetY() + delta_.GetY() - (HANDLE_SIZE / 2.0) / zoom;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 double x2 = center_.GetX() + delta_.GetX() + (HANDLE_SIZE / 2.0) / zoom;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 double y2 = center_.GetY() + delta_.GetY() + (HANDLE_SIZE / 2.0) / zoom;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 PolylineSceneLayer::Chain chain;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 chain.reserve(4);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 chain.push_back(ScenePoint2D(x1, y1));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 chain.push_back(ScenePoint2D(x2, y1));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 chain.push_back(ScenePoint2D(x2, y2));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 chain.push_back(ScenePoint2D(x1, y2));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 if (IsHover())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 polyline.AddChain(chain, true /* closed */, GetHoverColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 polyline.AddChain(chain, true /* closed */, GetColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 virtual void RenderOtherLayers(MacroSceneLayer& macro,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 delta_ = delta;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 GetParentAnnotation().SignalMove(*this);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 center_ = center_ + delta;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 delta_ = ScenePoint2D(0, 0);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 GetParentAnnotation().SignalMove(*this);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 class AnnotationsSceneLayer::Segment : public GeometricPrimitive
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 ScenePoint2D p1_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 ScenePoint2D p2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 ScenePoint2D delta_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 Segment(Annotation& parentAnnotation,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 const ScenePoint2D& p1,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 const ScenePoint2D& p2) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 GeometricPrimitive(parentAnnotation, 1), // Can only be selected if no handle matches
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 p1_(p1),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 p2_(p2),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 delta_(0, 0)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 void SetPosition(const ScenePoint2D& p1,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 const ScenePoint2D& p2)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 p1_ = p1;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 p2_ = p2;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 delta_ = ScenePoint2D(0, 0);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 ScenePoint2D GetPosition1() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 return p1_ + delta_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 ScenePoint2D GetPosition2() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 return p2_ + delta_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 virtual bool IsHit(const ScenePoint2D& p,
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
356 const Scene2D& scene) const ORTHANC_OVERRIDE
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 return (ScenePoint2D::SquaredDistancePtSegment(p1_ + delta_, p2_ + delta_, p) * zoom * zoom <=
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 (HANDLE_SIZE / 2.0) * (HANDLE_SIZE / 2.0));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 PolylineSceneLayer::Chain chain;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 chain.reserve(2);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 chain.push_back(p1_ + delta_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 chain.push_back(p2_ + delta_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 if (IsHover())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 polyline.AddChain(chain, false /* closed */, GetHoverColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 polyline.AddChain(chain, false /* closed */, GetColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 virtual void RenderOtherLayers(MacroSceneLayer& macro,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 delta_ = delta;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 GetParentAnnotation().SignalMove(*this);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 p1_ = p1_ + delta;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 p2_ = p2_ + delta;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 delta_ = ScenePoint2D(0, 0);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 GetParentAnnotation().SignalMove(*this);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 class AnnotationsSceneLayer::Circle : public GeometricPrimitive
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 ScenePoint2D p1_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 ScenePoint2D p2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 Circle(Annotation& parentAnnotation,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 const ScenePoint2D& p1,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 const ScenePoint2D& p2) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 GeometricPrimitive(parentAnnotation, 2),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 p1_(p1),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 p2_(p2)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 void SetPosition(const ScenePoint2D& p1,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 const ScenePoint2D& p2)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 p1_ = p1;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 p2_ = p2;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 ScenePoint2D GetPosition1() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 return p1_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 ScenePoint2D GetPosition2() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 return p2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 virtual bool IsHit(const ScenePoint2D& p,
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
439 const Scene2D& scene) const ORTHANC_OVERRIDE
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 return false;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 static unsigned int NUM_SEGMENTS = 128;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 ScenePoint2D middle((p1_.GetX() + p2_.GetX()) / 2.0,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 (p1_.GetY() + p2_.GetY()) / 2.0);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 const double radius = ScenePoint2D::DistancePtPt(middle, p1_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 double increment = 2.0 * PI / static_cast<double>(NUM_SEGMENTS - 1);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 PolylineSceneLayer::Chain chain;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 chain.reserve(NUM_SEGMENTS);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 double theta = 0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 for (unsigned int i = 0; i < NUM_SEGMENTS; i++)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 chain.push_back(ScenePoint2D(middle.GetX() + radius * cos(theta),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 middle.GetY() + radius * sin(theta)));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 theta += increment;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 if (IsHover())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 polyline.AddChain(chain, false /* closed */, GetHoverColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 polyline.AddChain(chain, false /* closed */, GetColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 virtual void RenderOtherLayers(MacroSceneLayer& macro,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 class AnnotationsSceneLayer::Arc : public GeometricPrimitive
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 ScenePoint2D start_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 ScenePoint2D middle_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 ScenePoint2D end_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 double radius_; // in pixels
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 void ComputeAngles(double& fullAngle,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 double& startAngle,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 double& endAngle) const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 const double x1 = start_.GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 const double y1 = start_.GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 const double xc = middle_.GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 const double yc = middle_.GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 const double x2 = end_.GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 const double y2 = end_.GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 startAngle = atan2(y1 - yc, x1 - xc);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 endAngle = atan2(y2 - yc, x2 - xc);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 fullAngle = endAngle - startAngle;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 while (fullAngle < -PI)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 fullAngle += 2.0 * PI;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 while (fullAngle >= PI)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 fullAngle -= 2.0 * PI;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 Arc(Annotation& parentAnnotation,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 const ScenePoint2D& start,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 const ScenePoint2D& middle,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 const ScenePoint2D& end) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 GeometricPrimitive(parentAnnotation, 2),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 start_(start),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 middle_(middle),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 end_(end),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 radius_(20)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 double GetAngle() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 double fullAngle, startAngle, endAngle;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 ComputeAngles(fullAngle, startAngle, endAngle);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 return fullAngle;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 void SetStart(const ScenePoint2D& p)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 start_ = p;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 void SetMiddle(const ScenePoint2D& p)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 middle_ = p;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 void SetEnd(const ScenePoint2D& p)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 end_ = p;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 virtual bool IsHit(const ScenePoint2D& p,
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
568 const Scene2D& scene) const ORTHANC_OVERRIDE
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 return false;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 static unsigned int NUM_SEGMENTS = 64;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 const double radius = radius_ / scene.GetSceneToCanvasTransform().ComputeZoom();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 double fullAngle, startAngle, endAngle;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 ComputeAngles(fullAngle, startAngle, endAngle);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 double increment = fullAngle / static_cast<double>(NUM_SEGMENTS - 1);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 PolylineSceneLayer::Chain chain;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 chain.reserve(NUM_SEGMENTS);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 double theta = startAngle;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 for (unsigned int i = 0; i < NUM_SEGMENTS; i++)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 chain.push_back(ScenePoint2D(middle_.GetX() + radius * cos(theta),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 middle_.GetY() + radius * sin(theta)));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 theta += increment;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 if (IsHover())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 polyline.AddChain(chain, false /* closed */, GetHoverColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 polyline.AddChain(chain, false /* closed */, GetColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 virtual void RenderOtherLayers(MacroSceneLayer& macro,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 class AnnotationsSceneLayer::Text : public GeometricPrimitive
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 AnnotationsSceneLayer& that_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 bool first_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 size_t subLayer_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 std::unique_ptr<TextSceneLayer> content_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 Text(AnnotationsSceneLayer& that,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 Annotation& parentAnnotation) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 GeometricPrimitive(parentAnnotation, 2),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 that_(that),
1817
385c268e8b56 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1812
diff changeset
636 first_(true),
385c268e8b56 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1812
diff changeset
637 subLayer_(0) // dummy initialization
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 virtual ~Text()
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 if (!first_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 that_.TagSubLayerToRemove(subLayer_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 void SetContent(const TextSceneLayer& content)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 SetModified(true);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 content_.reset(dynamic_cast<TextSceneLayer*>(content.Clone()));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 virtual bool IsHit(const ScenePoint2D& p,
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
656 const Scene2D& scene) const ORTHANC_OVERRIDE
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 return false;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 virtual void RenderOtherLayers(MacroSceneLayer& macro,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 const Scene2D& scene) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 if (content_.get() != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 std::unique_ptr<TextSceneLayer> layer(reinterpret_cast<TextSceneLayer*>(content_->Clone()));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 layer->SetColor(IsHover() ? GetHoverColor() : GetColor());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 if (first_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 subLayer_ = macro.AddLayer(layer.release());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 first_ = false;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 macro.UpdateLayer(subLayer_, layer.release());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 class AnnotationsSceneLayer::EditPrimitiveTracker : public IFlexiblePointerTracker
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 private:
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
702 AnnotationsSceneLayer& that_;
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
703 GeometricPrimitive& primitive_;
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
704 ScenePoint2D sceneClick_;
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
705 AffineTransform2D canvasToScene_;
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
706 bool alive_;
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 public:
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
709 EditPrimitiveTracker(AnnotationsSceneLayer& that,
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
710 GeometricPrimitive& primitive,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 const ScenePoint2D& sceneClick,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 const AffineTransform2D& canvasToScene) :
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
713 that_(that),
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 primitive_(primitive),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 sceneClick_(sceneClick),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 canvasToScene_(canvasToScene),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 alive_(true)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 primitive_.MovePreview(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_);
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
724 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 primitive_.MoveDone(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 alive_ = false;
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
731 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 virtual bool IsAlive() const ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 return alive_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 virtual void Cancel() ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 primitive_.MoveDone(ScenePoint2D(0, 0));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 class AnnotationsSceneLayer::SegmentAnnotation : public Annotation
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 bool showLabel_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 Handle& handle1_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 Handle& handle2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 Segment& segment_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 Text& label_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 void UpdateLabel()
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 if (showLabel_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 TextSceneLayer content;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 double x1 = handle1_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 double y1 = handle1_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 double x2 = handle2_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 double y2 = handle2_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 // Put the label to the right of the right-most handle
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 if (x1 < x2)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 content.SetPosition(x2, y2);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 content.SetPosition(x1, y1);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 content.SetAnchor(BitmapAnchor_CenterLeft);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 content.SetBorder(10);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 double dx = x1 - x2;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 double dy = y1 - y2;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 char buf[32];
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
786
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
787 switch (GetUnits())
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
788 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
789 case Units_Millimeters:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
790 sprintf(buf, "%0.2f cm", sqrt(dx * dx + dy * dy) / 10.0);
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
791 break;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
792
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
793 case Units_Pixels:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
794 sprintf(buf, "%0.1f px", sqrt(dx * dx + dy * dy));
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
795 break;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
796
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
797 default:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
798 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
799 }
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
800
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 content.SetText(buf);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 label_.SetContent(content);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 SegmentAnnotation(AnnotationsSceneLayer& that,
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
809 Units units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 bool showLabel,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 const ScenePoint2D& p1,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 const ScenePoint2D& p2) :
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
813 Annotation(that, units),
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 showLabel_(showLabel),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, p1))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, p2))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 {
1819
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
820 label_.SetColor(COLOR_TEXT);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 UpdateLabel();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 Handle& GetHandle1() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 return handle1_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 Handle& GetHandle2() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 return handle2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 if (&primitive == &handle1_ ||
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 &primitive == &handle2_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 else if (&primitive == &segment_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 handle1_.SetCenter(segment_.GetPosition1());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 handle2_.SetCenter(segment_.GetPosition2());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 UpdateLabel();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 target = Json::objectValue;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 target[KEY_TYPE] = VALUE_SEGMENT;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 target[KEY_X1] = handle1_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 target[KEY_Y1] = handle1_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 target[KEY_X2] = handle2_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 target[KEY_Y2] = handle2_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 static void Unserialize(AnnotationsSceneLayer& target,
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
861 Units units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 const Json::Value& source)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 if (source.isMember(KEY_X1) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 source.isMember(KEY_Y1) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 source.isMember(KEY_X2) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 source.isMember(KEY_Y2) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 source[KEY_X1].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 source[KEY_Y1].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 source[KEY_X2].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 source[KEY_Y2].isNumeric())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
873 new SegmentAnnotation(target, units, true,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an segment annotation");
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 class AnnotationsSceneLayer::AngleAnnotation : public Annotation
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 Handle& startHandle_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 Handle& middleHandle_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 Handle& endHandle_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 Segment& segment1_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 Segment& segment2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 Arc& arc_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 Text& label_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 void UpdateLabel()
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 TextSceneLayer content;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 const double x1 = startHandle_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 const double x2 = middleHandle_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 const double y2 = middleHandle_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 const double x3 = endHandle_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 if (x2 < x1 &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 x2 < x3)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 content.SetAnchor(BitmapAnchor_CenterRight);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 content.SetAnchor(BitmapAnchor_CenterLeft);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 content.SetPosition(x2, y2);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 content.SetBorder(10);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 char buf[32];
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 sprintf(buf, "%.01f%c%c", std::abs(arc_.GetAngle()) / PI * 180.0,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 0xc2, 0xb0 /* two bytes corresponding to degree symbol in UTF-8 */);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 content.SetText(buf);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 label_.SetContent(content);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 AngleAnnotation(AnnotationsSceneLayer& that,
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
928 Units units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 const ScenePoint2D& start,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 const ScenePoint2D& middle,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 const ScenePoint2D& end) :
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
932 Annotation(that, units),
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 startHandle_(AddTypedPrimitive<Handle>(new Handle(*this, start))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 middleHandle_(AddTypedPrimitive<Handle>(new Handle(*this, middle))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 endHandle_(AddTypedPrimitive<Handle>(new Handle(*this, end))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 segment1_(AddTypedPrimitive<Segment>(new Segment(*this, start, middle))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 segment2_(AddTypedPrimitive<Segment>(new Segment(*this, middle, end))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 arc_(AddTypedPrimitive<Arc>(new Arc(*this, start, middle, end))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 {
1819
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
941 label_.SetColor(COLOR_TEXT);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 UpdateLabel();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 Handle& GetEndHandle() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 return endHandle_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 if (&primitive == &startHandle_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 segment1_.SetPosition(startHandle_.GetCenter(), middleHandle_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 arc_.SetStart(startHandle_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 else if (&primitive == &middleHandle_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 segment1_.SetPosition(startHandle_.GetCenter(), middleHandle_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 segment2_.SetPosition(middleHandle_.GetCenter(), endHandle_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 arc_.SetMiddle(middleHandle_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 else if (&primitive == &endHandle_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 segment2_.SetPosition(middleHandle_.GetCenter(), endHandle_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 arc_.SetEnd(endHandle_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 else if (&primitive == &segment1_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 startHandle_.SetCenter(segment1_.GetPosition1());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 middleHandle_.SetCenter(segment1_.GetPosition2());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 segment2_.SetPosition(segment1_.GetPosition2(), segment2_.GetPosition2());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 arc_.SetStart(segment1_.GetPosition1());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 arc_.SetMiddle(segment1_.GetPosition2());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 else if (&primitive == &segment2_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 middleHandle_.SetCenter(segment2_.GetPosition1());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 endHandle_.SetCenter(segment2_.GetPosition2());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 segment1_.SetPosition(segment1_.GetPosition1(), segment2_.GetPosition1());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 arc_.SetMiddle(segment2_.GetPosition1());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 arc_.SetEnd(segment2_.GetPosition2());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 UpdateLabel();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 target = Json::objectValue;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 target[KEY_TYPE] = VALUE_ANGLE;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 target[KEY_X1] = startHandle_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 target[KEY_Y1] = startHandle_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994 target[KEY_X2] = middleHandle_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 target[KEY_Y2] = middleHandle_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
996 target[KEY_X3] = endHandle_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 target[KEY_Y3] = endHandle_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000 static void Unserialize(AnnotationsSceneLayer& target,
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1001 Units units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002 const Json::Value& source)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 if (source.isMember(KEY_X1) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005 source.isMember(KEY_Y1) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 source.isMember(KEY_X2) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 source.isMember(KEY_Y2) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 source.isMember(KEY_X3) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009 source.isMember(KEY_Y3) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 source[KEY_X1].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 source[KEY_Y1].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012 source[KEY_X2].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1013 source[KEY_Y2].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 source[KEY_X3].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015 source[KEY_Y3].isNumeric())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1017 new AngleAnnotation(target, units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 ScenePoint2D(source[KEY_X3].asDouble(), source[KEY_Y3].asDouble()));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an angle annotation");
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030 class AnnotationsSceneLayer::CircleAnnotation : public Annotation
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 Handle& handle1_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 Handle& handle2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 Segment& segment_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 Circle& circle_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 Text& label_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 void UpdateLabel()
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 TextSceneLayer content;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043 double x1 = handle1_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 double y1 = handle1_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045 double x2 = handle2_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046 double y2 = handle2_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 // Put the label to the right of the right-most handle
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 if (x1 < x2)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 content.SetPosition(x2, y2);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 content.SetPosition(x1, y1);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 content.SetAnchor(BitmapAnchor_CenterLeft);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 content.SetBorder(10);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 double dx = x1 - x2;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 double dy = y1 - y2;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063 double diameter = sqrt(dx * dx + dy * dy); // in millimeters
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065 double area = PI * diameter * diameter / 4.0;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 char buf[32];
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1068
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1069 switch (GetUnits())
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1070 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1071 case Units_Millimeters:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1072 sprintf(buf, "%0.2f cm\n%0.2f cm%c%c",
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1073 diameter / 10.0,
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1074 area / 100.0,
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1075 0xc2, 0xb2 /* two bytes corresponding to two power in UTF-8 */);
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1076 break;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1077
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1078 case Units_Pixels:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1079 // Don't report area (pixel-times-pixel is a strange unit)
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1080 sprintf(buf, "%0.1f px", diameter);
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1081 break;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1082
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1083 default:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1084 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1085 }
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1086
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087 content.SetText(buf);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1088
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 label_.SetContent(content);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 CircleAnnotation(AnnotationsSceneLayer& that,
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1094 Units units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 const ScenePoint2D& p1,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 const ScenePoint2D& p2) :
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1097 Annotation(that, units),
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, p1))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, p2))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101 circle_(AddTypedPrimitive<Circle>(new Circle(*this, p1, p2))),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 {
1819
fe402c678d18 improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1817
diff changeset
1104 label_.SetColor(COLOR_TEXT);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105 UpdateLabel();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 Handle& GetHandle2() const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 return handle2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 if (&primitive == &handle1_ ||
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 &primitive == &handle2_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 circle_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 else if (&primitive == &segment_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 handle1_.SetCenter(segment_.GetPosition1());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124 handle2_.SetCenter(segment_.GetPosition2());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 circle_.SetPosition(segment_.GetPosition1(), segment_.GetPosition2());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1126 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1128 UpdateLabel();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1129 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133 target = Json::objectValue;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 target[KEY_TYPE] = VALUE_CIRCLE;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135 target[KEY_X1] = handle1_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136 target[KEY_Y1] = handle1_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1137 target[KEY_X2] = handle2_.GetCenter().GetX();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 target[KEY_Y2] = handle2_.GetCenter().GetY();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 static void Unserialize(AnnotationsSceneLayer& target,
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1142 Units units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 const Json::Value& source)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 if (source.isMember(KEY_X1) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146 source.isMember(KEY_Y1) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 source.isMember(KEY_X2) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 source.isMember(KEY_Y2) &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 source[KEY_X1].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 source[KEY_Y1].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 source[KEY_X2].isNumeric() &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 source[KEY_Y2].isNumeric())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1154 new CircleAnnotation(target, units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an circle annotation");
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 class AnnotationsSceneLayer::CreateSegmentOrCircleTracker : public IFlexiblePointerTracker
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169 AnnotationsSceneLayer& that_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170 Annotation* annotation_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 AffineTransform2D canvasToScene_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 Handle* handle2_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175 CreateSegmentOrCircleTracker(AnnotationsSceneLayer& that,
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1176 Units units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 bool isCircle,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 const ScenePoint2D& sceneClick,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 const AffineTransform2D& canvasToScene) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 that_(that),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181 annotation_(NULL),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182 canvasToScene_(canvasToScene),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 handle2_(NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 if (isCircle)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1187 annotation_ = new CircleAnnotation(that, units, sceneClick, sceneClick);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 handle2_ = &dynamic_cast<CircleAnnotation*>(annotation_)->GetHandle2();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1192 annotation_ = new SegmentAnnotation(that, units, true /* show label */, sceneClick, sceneClick);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 handle2_ = &dynamic_cast<SegmentAnnotation*>(annotation_)->GetHandle2();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196 assert(annotation_ != NULL &&
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197 handle2_ != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 if (annotation_ != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 assert(handle2_ != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205 handle2_->SetCenter(event.GetMainPosition().Apply(canvasToScene_));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 annotation_->SignalMove(*handle2_);
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1207
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1208 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214 annotation_ = NULL; // IsAlive() becomes false
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 that_.BroadcastMessage(AnnotationAddedMessage(that_));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 virtual bool IsAlive() const ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 return (annotation_ != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 virtual void Cancel() ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 if (annotation_ != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 that_.DeleteAnnotation(annotation_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 annotation_ = NULL;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 class AnnotationsSceneLayer::CreateAngleTracker : public IFlexiblePointerTracker
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 private:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 AnnotationsSceneLayer& that_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 SegmentAnnotation* segment_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 AngleAnnotation* angle_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 AffineTransform2D canvasToScene_;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 public:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 CreateAngleTracker(AnnotationsSceneLayer& that,
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1249 Units units,
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250 const ScenePoint2D& sceneClick,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1251 const AffineTransform2D& canvasToScene) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 that_(that),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 segment_(NULL),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254 angle_(NULL),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255 canvasToScene_(canvasToScene)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1257 segment_ = new SegmentAnnotation(that, units, false /* no length label */, sceneClick, sceneClick);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1260 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1262 if (segment_ != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264 segment_->GetHandle2().SetCenter(event.GetMainPosition().Apply(canvasToScene_));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265 segment_->SignalMove(segment_->GetHandle2());
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1266 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1267 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1269 if (angle_ != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271 angle_->GetEndHandle().SetCenter(event.GetMainPosition().Apply(canvasToScene_));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1272 angle_->SignalMove(angle_->GetEndHandle());
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1273 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1274 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1276
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1277 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1278 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1279 if (segment_ != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281 // End of first step: The first segment is available, now create the angle
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1282
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1283 angle_ = new AngleAnnotation(that_, segment_->GetUnits(), segment_->GetHandle1().GetCenter(),
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1284 segment_->GetHandle2().GetCenter(),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285 segment_->GetHandle2().GetCenter());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1287 that_.DeleteAnnotation(segment_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1288 segment_ = NULL;
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1289
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1290 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1293 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1294 angle_ = NULL; // IsAlive() becomes false
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296 that_.BroadcastMessage(AnnotationAddedMessage(that_));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1300 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1301 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1302 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1303
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1304 virtual bool IsAlive() const ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1305 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1306 return (segment_ != NULL ||
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1307 angle_ != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1308 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1309
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1310 virtual void Cancel() ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1311 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1312 if (segment_ != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314 that_.DeleteAnnotation(segment_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1315 segment_ = NULL;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1316 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1317
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1318 if (angle_ != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1319 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320 that_.DeleteAnnotation(angle_);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321 angle_ = NULL;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1323 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1325
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1326
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327 // Dummy tracker that is only used for deletion, in order to warn
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 // the caller that the mouse action was taken into consideration
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1329 class AnnotationsSceneLayer::RemoveTracker : public IFlexiblePointerTracker
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331 public:
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1332 RemoveTracker()
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1342 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1347
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1348 virtual bool IsAlive() const ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1349 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350 return false;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 virtual void Cancel() ORTHANC_OVERRIDE
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1356 };
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1358
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359 void AnnotationsSceneLayer::AddAnnotation(Annotation* annotation)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1360 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1361 assert(annotation != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1362 assert(annotations_.find(annotation) == annotations_.end());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1363 annotations_.insert(annotation);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1365
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 void AnnotationsSceneLayer::DeleteAnnotation(Annotation* annotation)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369 if (annotation != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1370 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1371 assert(annotations_.find(annotation) != annotations_.end());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372 annotations_.erase(annotation);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 delete annotation;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1375 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1376
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1378 void AnnotationsSceneLayer::DeletePrimitive(GeometricPrimitive* primitive)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 if (primitive != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1381 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1382 assert(primitives_.find(primitive) != primitives_.end());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383 primitives_.erase(primitive);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1384 delete primitive;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1385 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1386 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1387
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389 void AnnotationsSceneLayer::TagSubLayerToRemove(size_t subLayerIndex)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391 assert(subLayersToRemove_.find(subLayerIndex) == subLayersToRemove_.end());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392 subLayersToRemove_.insert(subLayerIndex);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1395
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396 AnnotationsSceneLayer::AnnotationsSceneLayer(size_t macroLayerIndex) :
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397 activeTool_(Tool_Edit),
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398 macroLayerIndex_(macroLayerIndex),
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1399 polylineSubLayer_(0), // dummy initialization
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1400 units_(Units_Pixels)
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1405 void AnnotationsSceneLayer::Clear()
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407 for (Annotations::iterator it = annotations_.begin(); it != annotations_.end(); ++it)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409 assert(*it != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410 delete *it;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1411 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413 annotations_.clear();
1812
db341679dc9f ViewerViewport::StoneAnnotationsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1809
diff changeset
1414
db341679dc9f ViewerViewport::StoneAnnotationsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1809
diff changeset
1415 ClearHover();
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1418
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1419 void AnnotationsSceneLayer::SetUnits(Units units)
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1420 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1421 if (units_ != units)
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1422 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1423 Clear();
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1424 units_ = units;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1425 }
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1426 }
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1427
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1428
1806
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1429 void AnnotationsSceneLayer::AddSegmentAnnotation(const ScenePoint2D& p1,
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1430 const ScenePoint2D& p2)
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1431 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1432 annotations_.insert(new SegmentAnnotation(*this, units_, true /* show label */, p1, p2));
1806
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1433 }
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1434
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1435
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1436 void AnnotationsSceneLayer::AddCircleAnnotation(const ScenePoint2D& p1,
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1437 const ScenePoint2D& p2)
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1438 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1439 annotations_.insert(new CircleAnnotation(*this, units_, p1, p2));
1806
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1440 }
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1441
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1442
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1443 void AnnotationsSceneLayer::AddAngleAnnotation(const ScenePoint2D& p1,
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1444 const ScenePoint2D& p2,
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1445 const ScenePoint2D& p3)
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1446 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1447 annotations_.insert(new AngleAnnotation(*this, units_, p1, p2, p3));
1806
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1448 }
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1449
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
1450
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1451 void AnnotationsSceneLayer::Render(Scene2D& scene)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1452 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1453 MacroSceneLayer* macro = NULL;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1454
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455 if (scene.HasLayer(macroLayerIndex_))
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1456 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1457 macro = &dynamic_cast<MacroSceneLayer&>(scene.GetLayer(macroLayerIndex_));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1458 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1459 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1460 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1461 macro = &dynamic_cast<MacroSceneLayer&>(scene.SetLayer(macroLayerIndex_, new MacroSceneLayer));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1462 polylineSubLayer_ = macro->AddLayer(new PolylineSceneLayer);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1463 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1464
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1465 for (SubLayers::const_iterator it = subLayersToRemove_.begin(); it != subLayersToRemove_.end(); ++it)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1466 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1467 assert(macro->HasLayer(*it));
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1468 macro->DeleteLayer(*it);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1471 subLayersToRemove_.clear();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1472
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1473 std::unique_ptr<PolylineSceneLayer> polyline(new PolylineSceneLayer);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1474
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1475 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1476 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1477 assert(*it != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1478 GeometricPrimitive& primitive = **it;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1479
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1480 primitive.RenderPolylineLayer(*polyline, scene);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1481
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1482 if (primitive.IsModified())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1483 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1484 primitive.RenderOtherLayers(*macro, scene);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485 primitive.SetModified(false);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1488
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1489 macro->UpdateLayer(polylineSubLayer_, polyline.release());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1493 bool AnnotationsSceneLayer::ClearHover()
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1494 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1495 bool needsRefresh = false;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1496
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1497 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1498 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1499 assert(*it != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1500 if ((*it)->IsHover())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1501 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1502 (*it)->SetHover(false);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1503 needsRefresh = true;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1504 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1505 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1506
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507 return needsRefresh;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1508 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1509
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1510
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1511 bool AnnotationsSceneLayer::SetMouseHover(const ScenePoint2D& p,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1512 const Scene2D& scene)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1513 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1514 if (activeTool_ == Tool_None)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1515 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1516 return ClearHover();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1517 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1519 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1520 bool needsRefresh = false;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1521
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1522 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1523
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1524 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1525 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1526 assert(*it != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1527 bool hover = (*it)->IsHit(s, scene);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1528
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1529 if ((*it)->IsHover() != hover)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1530 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1531 needsRefresh = true;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1532 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534 (*it)->SetHover(hover);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1536
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537 return needsRefresh;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1540
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 IFlexiblePointerTracker* AnnotationsSceneLayer::CreateTracker(const ScenePoint2D& p,
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543 const Scene2D& scene)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 if (activeTool_ == Tool_None)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 return NULL;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1548 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1549 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1550 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1551 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1552
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1553 GeometricPrimitive* bestHit = NULL;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1554
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1557 assert(*it != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 if ((*it)->IsHit(s, scene))
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560 if (bestHit == NULL ||
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1561 bestHit->GetDepth() > (*it)->GetDepth())
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1562 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 bestHit = *it;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1566 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1568 if (bestHit != NULL)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 {
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1570 if (activeTool_ == Tool_Remove)
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1571 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1572 DeleteAnnotation(&bestHit->GetParentAnnotation());
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1573 BroadcastMessage(AnnotationRemovedMessage(*this));
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1574 return new RemoveTracker;
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1575 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1576 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1577 {
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
1578 return new EditPrimitiveTracker(*this, *bestHit, s, scene.GetCanvasToSceneTransform());
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1579 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1580 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1581 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1582 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1583 switch (activeTool_)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1584 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1585 case Tool_Segment:
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1586 return new CreateSegmentOrCircleTracker(*this, units_, false /* segment */, s, scene.GetCanvasToSceneTransform());
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1587
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1588 case Tool_Circle:
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1589 return new CreateSegmentOrCircleTracker(*this, units_, true /* circle */, s, scene.GetCanvasToSceneTransform());
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1590
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1591 case Tool_Angle:
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1592 return new CreateAngleTracker(*this, units_, s, scene.GetCanvasToSceneTransform());
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1593
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1594 default:
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1595 return NULL;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1596 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1597 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1598 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1599 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1600
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1601
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1602 void AnnotationsSceneLayer::Serialize(Json::Value& target) const
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1603 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1604 Json::Value annotations = Json::arrayValue;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1605
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1606 for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1607 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1608 assert(*it != NULL);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1609
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1610 Json::Value item;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1611 (*it)->Serialize(item);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1612 annotations.append(item);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1613 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1614
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1615 target = Json::objectValue;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1616 target[KEY_ANNOTATIONS] = annotations;
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1617
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1618 switch (units_)
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1619 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1620 case Units_Millimeters:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1621 target[KEY_UNITS] = VALUE_MILLIMETERS;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1622 break;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1623
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1624 case Units_Pixels:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1625 target[KEY_UNITS] = VALUE_PIXELS;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1626 break;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1627
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1628 default:
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1629 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1630 }
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1631 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1632
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1633
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1634 void AnnotationsSceneLayer::Unserialize(const Json::Value& serialized)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1635 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1636 Clear();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1637
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1638 if (serialized.type() != Json::objectValue ||
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1639 !serialized.isMember(KEY_ANNOTATIONS) ||
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1640 !serialized.isMember(KEY_UNITS) ||
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1641 serialized[KEY_ANNOTATIONS].type() != Json::arrayValue ||
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1642 serialized[KEY_UNITS].type() != Json::stringValue)
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1643 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1644 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a set of annotations");
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1647 const std::string& u = serialized[KEY_UNITS].asString();
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1648
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1649 if (u == VALUE_MILLIMETERS)
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1650 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1651 units_ = Units_Millimeters;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1652 }
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1653 else if (u == VALUE_PIXELS)
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1654 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1655 units_ = Units_Pixels;
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1656 }
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1657 else
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1658 {
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1659 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Unknown units: " + u);
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1660 }
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1661
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1662 const Json::Value& annotations = serialized[KEY_ANNOTATIONS];
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1663
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1664 for (Json::Value::ArrayIndex i = 0; i < annotations.size(); i++)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1665 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1666 if (annotations[i].type() != Json::objectValue ||
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1667 !annotations[i].isMember(KEY_TYPE) ||
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1668 annotations[i][KEY_TYPE].type() != Json::stringValue)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1669 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1670 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1671 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1672
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1673 const std::string& type = annotations[i][KEY_TYPE].asString();
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1674
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1675 if (type == VALUE_ANGLE)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1676 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1677 AngleAnnotation::Unserialize(*this, units_, annotations[i]);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1678 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1679 else if (type == VALUE_CIRCLE)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1680 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1681 CircleAnnotation::Unserialize(*this, units_, annotations[i]);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1682 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1683 else if (type == VALUE_SEGMENT)
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1684 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1819
diff changeset
1685 SegmentAnnotation::Unserialize(*this, units_, annotations[i]);
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1686 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1687 else
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1688 {
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1689 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1690 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1691 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1692 }
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1693 }