annotate OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 1928:c73e696967b0 StoneWebViewer-2.3

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