annotate OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 1819:fe402c678d18

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