comparison OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 2000:3e9ced39cd1b

simplification
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Nov 2022 13:52:14 +0100
parents 709b90ae0f89
children e943a84da9ac
comparison
equal deleted inserted replaced
1999:709b90ae0f89 2000:3e9ced39cd1b
187 private: 187 private:
188 typedef std::list<GeometricPrimitive*> GeometricPrimitives; 188 typedef std::list<GeometricPrimitive*> GeometricPrimitives;
189 189
190 AnnotationsSceneLayer& that_; 190 AnnotationsSceneLayer& that_;
191 GeometricPrimitives primitives_; 191 GeometricPrimitives primitives_;
192 Units units_;
193 192
194 public: 193 public:
195 explicit Annotation(AnnotationsSceneLayer& that, 194 explicit Annotation(AnnotationsSceneLayer& that) :
196 Units units) : 195 that_(that)
197 that_(that),
198 units_(units)
199 { 196 {
200 that.AddAnnotation(this); 197 that.AddAnnotation(this);
201 } 198 }
202 199
203 virtual ~Annotation() 200 virtual ~Annotation()
209 } 206 }
210 207
211 AnnotationsSceneLayer& GetParentLayer() const 208 AnnotationsSceneLayer& GetParentLayer() const
212 { 209 {
213 return that_; 210 return that_;
214 }
215
216 Units GetUnits() const
217 {
218 return units_;
219 } 211 }
220 212
221 GeometricPrimitive* AddPrimitive(GeometricPrimitive* primitive) 213 GeometricPrimitive* AddPrimitive(GeometricPrimitive* primitive)
222 { 214 {
223 if (primitive == NULL) 215 if (primitive == NULL)
1106 segment_.SetEndArrow(enabled); 1098 segment_.SetEndArrow(enabled);
1107 } 1099 }
1108 1100
1109 public: 1101 public:
1110 SegmentAnnotation(AnnotationsSceneLayer& that, 1102 SegmentAnnotation(AnnotationsSceneLayer& that,
1111 Units units,
1112 Handle::Shape shape1, 1103 Handle::Shape shape1,
1113 const ScenePoint2D& p1, 1104 const ScenePoint2D& p1,
1114 Handle::Shape shape2, 1105 Handle::Shape shape2,
1115 const ScenePoint2D& p2) : 1106 const ScenePoint2D& p2) :
1116 Annotation(that, units), 1107 Annotation(that),
1117 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, shape1, p1))), 1108 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, shape1, p1))),
1118 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, shape2, p2))), 1109 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, shape2, p2))),
1119 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))), 1110 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))),
1120 label_(AddTypedPrimitive<Text>(new Text(that, *this))) 1111 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
1121 { 1112 {
1168 1159
1169 1160
1170 class AnnotationsSceneLayer::LengthAnnotation : public SegmentAnnotation 1161 class AnnotationsSceneLayer::LengthAnnotation : public SegmentAnnotation
1171 { 1162 {
1172 private: 1163 private:
1173 bool showLabel_; 1164 Units units_;
1165 bool showLabel_;
1174 1166
1175 void UpdateLabel() 1167 void UpdateLabel()
1176 { 1168 {
1177 if (showLabel_) 1169 if (showLabel_)
1178 { 1170 {
1198 1190
1199 double dx = x1 - x2; 1191 double dx = x1 - x2;
1200 double dy = y1 - y2; 1192 double dy = y1 - y2;
1201 char buf[32]; 1193 char buf[32];
1202 1194
1203 switch (GetUnits()) 1195 switch (units_)
1204 { 1196 {
1205 case Units_Millimeters: 1197 case Units_Millimeters:
1206 sprintf(buf, "%0.2f cm", sqrt(dx * dx + dy * dy) / 10.0); 1198 sprintf(buf, "%0.2f cm", sqrt(dx * dx + dy * dy) / 10.0);
1207 break; 1199 break;
1208 1200
1224 LengthAnnotation(AnnotationsSceneLayer& that, 1216 LengthAnnotation(AnnotationsSceneLayer& that,
1225 Units units, 1217 Units units,
1226 bool showLabel, 1218 bool showLabel,
1227 const ScenePoint2D& p1, 1219 const ScenePoint2D& p1,
1228 const ScenePoint2D& p2) : 1220 const ScenePoint2D& p2) :
1229 SegmentAnnotation(that, units, Handle::Shape_Square, p1, Handle::Shape_Square, p2), 1221 SegmentAnnotation(that, Handle::Shape_Square, p1, Handle::Shape_Square, p2),
1222 units_(units),
1230 showLabel_(showLabel) 1223 showLabel_(showLabel)
1231 { 1224 {
1232 UpdateLabel(); 1225 UpdateLabel();
1233 } 1226 }
1234 1227
1276 1269
1277 class AnnotationsSceneLayer::TextAnnotation : public SegmentAnnotation 1270 class AnnotationsSceneLayer::TextAnnotation : public SegmentAnnotation
1278 { 1271 {
1279 public: 1272 public:
1280 TextAnnotation(AnnotationsSceneLayer& that, 1273 TextAnnotation(AnnotationsSceneLayer& that,
1281 Units units,
1282 const std::string& label, 1274 const std::string& label,
1283 const ScenePoint2D& p1, 1275 const ScenePoint2D& p1,
1284 const ScenePoint2D& p2) : 1276 const ScenePoint2D& p2) :
1285 SegmentAnnotation(that, units, Handle::Shape_Invisible, p1, Handle::Shape_Square, p2) 1277 SegmentAnnotation(that, Handle::Shape_Invisible, p1, Handle::Shape_Square, p2)
1286 { 1278 {
1287 SetStartArrow(true); 1279 SetStartArrow(true);
1288 UpdateLabel(label); 1280 UpdateLabel(label);
1289 } 1281 }
1290 1282
1334 target[KEY_Y2] = GetHandle2().GetCenter().GetY(); 1326 target[KEY_Y2] = GetHandle2().GetCenter().GetY();
1335 target[KEY_LABEL] = GetCurrentLabel(); 1327 target[KEY_LABEL] = GetCurrentLabel();
1336 } 1328 }
1337 1329
1338 static void Unserialize(AnnotationsSceneLayer& target, 1330 static void Unserialize(AnnotationsSceneLayer& target,
1339 Units units,
1340 const Json::Value& source) 1331 const Json::Value& source)
1341 { 1332 {
1342 if (source.isMember(KEY_X1) && 1333 if (source.isMember(KEY_X1) &&
1343 source.isMember(KEY_Y1) && 1334 source.isMember(KEY_Y1) &&
1344 source.isMember(KEY_X2) && 1335 source.isMember(KEY_X2) &&
1348 source[KEY_Y1].isNumeric() && 1339 source[KEY_Y1].isNumeric() &&
1349 source[KEY_X2].isNumeric() && 1340 source[KEY_X2].isNumeric() &&
1350 source[KEY_Y2].isNumeric() && 1341 source[KEY_Y2].isNumeric() &&
1351 source[KEY_LABEL].isString()) 1342 source[KEY_LABEL].isString())
1352 { 1343 {
1353 new TextAnnotation(target, units, source[KEY_LABEL].asString(), 1344 new TextAnnotation(target, source[KEY_LABEL].asString(),
1354 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), 1345 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()),
1355 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); 1346 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()));
1356 } 1347 }
1357 else 1348 else
1358 { 1349 {
1378 { 1369 {
1379 probeChanged_ = true; 1370 probeChanged_ = true;
1380 } 1371 }
1381 1372
1382 public: 1373 public:
1383 ProbingAnnotation(AnnotationsSceneLayer& that, 1374 ProbingAnnotation(AnnotationsSceneLayer& that) :
1384 Units units) : 1375 Annotation(that),
1385 Annotation(that, units),
1386 probedLayer_(that.GetProbedLayer()), 1376 probedLayer_(that.GetProbedLayer()),
1387 probeChanged_(true), 1377 probeChanged_(true),
1388 lastLayerRevision_(0) 1378 lastLayerRevision_(0)
1389 { 1379 {
1390 } 1380 }
1466 } 1456 }
1467 } 1457 }
1468 1458
1469 public: 1459 public:
1470 PixelProbeAnnotation(AnnotationsSceneLayer& that, 1460 PixelProbeAnnotation(AnnotationsSceneLayer& that,
1471 Units units,
1472 const ScenePoint2D& p) : 1461 const ScenePoint2D& p) :
1473 ProbingAnnotation(that, units), 1462 ProbingAnnotation(that),
1474 handle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_CrossedSquare, p))), 1463 handle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_CrossedSquare, p))),
1475 label_(AddTypedPrimitive<Text>(new Text(that, *this))) 1464 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
1476 { 1465 {
1477 TextSceneLayer content; 1466 TextSceneLayer content;
1478 content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); 1467 content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY());
1515 target[KEY_X] = handle_.GetCenter().GetX(); 1504 target[KEY_X] = handle_.GetCenter().GetX();
1516 target[KEY_Y] = handle_.GetCenter().GetY(); 1505 target[KEY_Y] = handle_.GetCenter().GetY();
1517 } 1506 }
1518 1507
1519 static void Unserialize(AnnotationsSceneLayer& target, 1508 static void Unserialize(AnnotationsSceneLayer& target,
1520 Units units,
1521 const Json::Value& source) 1509 const Json::Value& source)
1522 { 1510 {
1523 if (source.isMember(KEY_X) && 1511 if (source.isMember(KEY_X) &&
1524 source.isMember(KEY_Y) && 1512 source.isMember(KEY_Y) &&
1525 source[KEY_X].isNumeric() && 1513 source[KEY_X].isNumeric() &&
1526 source[KEY_Y].isNumeric()) 1514 source[KEY_Y].isNumeric())
1527 { 1515 {
1528 new PixelProbeAnnotation(target, units, 1516 new PixelProbeAnnotation(target, ScenePoint2D(source[KEY_X].asDouble(), source[KEY_Y].asDouble()));
1529 ScenePoint2D(source[KEY_X].asDouble(), source[KEY_Y].asDouble()));
1530 } 1517 }
1531 else 1518 else
1532 { 1519 {
1533 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a pixel probe"); 1520 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a pixel probe");
1534 } 1521 }
1577 label_.SetContent(content); 1564 label_.SetContent(content);
1578 } 1565 }
1579 1566
1580 public: 1567 public:
1581 AngleAnnotation(AnnotationsSceneLayer& that, 1568 AngleAnnotation(AnnotationsSceneLayer& that,
1582 Units units,
1583 const ScenePoint2D& start, 1569 const ScenePoint2D& start,
1584 const ScenePoint2D& middle, 1570 const ScenePoint2D& middle,
1585 const ScenePoint2D& end) : 1571 const ScenePoint2D& end) :
1586 Annotation(that, units), 1572 Annotation(that),
1587 startHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, start))), 1573 startHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, start))),
1588 middleHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, middle))), 1574 middleHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, middle))),
1589 endHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, end))), 1575 endHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, end))),
1590 segment1_(AddTypedPrimitive<Segment>(new Segment(*this, start, middle))), 1576 segment1_(AddTypedPrimitive<Segment>(new Segment(*this, start, middle))),
1591 segment2_(AddTypedPrimitive<Segment>(new Segment(*this, middle, end))), 1577 segment2_(AddTypedPrimitive<Segment>(new Segment(*this, middle, end))),
1677 target[KEY_X3] = endHandle_.GetCenter().GetX(); 1663 target[KEY_X3] = endHandle_.GetCenter().GetX();
1678 target[KEY_Y3] = endHandle_.GetCenter().GetY(); 1664 target[KEY_Y3] = endHandle_.GetCenter().GetY();
1679 } 1665 }
1680 1666
1681 static void Unserialize(AnnotationsSceneLayer& target, 1667 static void Unserialize(AnnotationsSceneLayer& target,
1682 Units units,
1683 const Json::Value& source) 1668 const Json::Value& source)
1684 { 1669 {
1685 if (source.isMember(KEY_X1) && 1670 if (source.isMember(KEY_X1) &&
1686 source.isMember(KEY_Y1) && 1671 source.isMember(KEY_Y1) &&
1687 source.isMember(KEY_X2) && 1672 source.isMember(KEY_X2) &&
1693 source[KEY_X2].isNumeric() && 1678 source[KEY_X2].isNumeric() &&
1694 source[KEY_Y2].isNumeric() && 1679 source[KEY_Y2].isNumeric() &&
1695 source[KEY_X3].isNumeric() && 1680 source[KEY_X3].isNumeric() &&
1696 source[KEY_Y3].isNumeric()) 1681 source[KEY_Y3].isNumeric())
1697 { 1682 {
1698 new AngleAnnotation(target, units, 1683 new AngleAnnotation(target,
1699 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), 1684 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()),
1700 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()), 1685 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()),
1701 ScenePoint2D(source[KEY_X3].asDouble(), source[KEY_Y3].asDouble())); 1686 ScenePoint2D(source[KEY_X3].asDouble(), source[KEY_Y3].asDouble()));
1702 } 1687 }
1703 else 1688 else
1709 1694
1710 1695
1711 class AnnotationsSceneLayer::CircleAnnotation : public Annotation 1696 class AnnotationsSceneLayer::CircleAnnotation : public Annotation
1712 { 1697 {
1713 private: 1698 private:
1699 Units units_;
1714 Handle& handle1_; 1700 Handle& handle1_;
1715 Handle& handle2_; 1701 Handle& handle2_;
1716 Segment& segment_; 1702 Segment& segment_;
1717 Circle& circle_; 1703 Circle& circle_;
1718 Text& label_; 1704 Text& label_;
1745 1731
1746 double area = PI * diameter * diameter / 4.0; 1732 double area = PI * diameter * diameter / 4.0;
1747 1733
1748 char buf[32]; 1734 char buf[32];
1749 1735
1750 switch (GetUnits()) 1736 switch (units_)
1751 { 1737 {
1752 case Units_Millimeters: 1738 case Units_Millimeters:
1753 sprintf(buf, "%0.2f cm\n%0.2f cm%c%c", 1739 sprintf(buf, "%0.2f cm\n%0.2f cm%c%c",
1754 diameter / 10.0, 1740 diameter / 10.0,
1755 area / 100.0, 1741 area / 100.0,
1773 public: 1759 public:
1774 CircleAnnotation(AnnotationsSceneLayer& that, 1760 CircleAnnotation(AnnotationsSceneLayer& that,
1775 Units units, 1761 Units units,
1776 const ScenePoint2D& p1, 1762 const ScenePoint2D& p1,
1777 const ScenePoint2D& p2) : 1763 const ScenePoint2D& p2) :
1778 Annotation(that, units), 1764 Annotation(that),
1765 units_(units),
1779 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))), 1766 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))),
1780 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))), 1767 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))),
1781 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))), 1768 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))),
1782 circle_(AddTypedPrimitive<Circle>(new Circle(*this, p1, p2))), 1769 circle_(AddTypedPrimitive<Circle>(new Circle(*this, p1, p2))),
1783 label_(AddTypedPrimitive<Text>(new Text(that, *this))) 1770 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
1875 1862
1876 1863
1877 class AnnotationsSceneLayer::RectangleProbeAnnotation : public ProbingAnnotation 1864 class AnnotationsSceneLayer::RectangleProbeAnnotation : public ProbingAnnotation
1878 { 1865 {
1879 private: 1866 private:
1867 Units units_;
1880 Handle& handle1_; 1868 Handle& handle1_;
1881 Handle& handle2_; 1869 Handle& handle2_;
1882 Segment& segment1_; 1870 Segment& segment1_;
1883 Segment& segment2_; 1871 Segment& segment2_;
1884 Segment& segment3_; 1872 Segment& segment3_;
1909 1897
1910 std::string text; 1898 std::string text;
1911 1899
1912 char buf[32]; 1900 char buf[32];
1913 1901
1914 if (GetUnits() == Units_Millimeters) 1902 if (units_ == Units_Millimeters)
1915 { 1903 {
1916 const double area = std::abs(x1 - x2) * std::abs(y1 - y2); 1904 const double area = std::abs(x1 - x2) * std::abs(y1 - y2);
1917 1905
1918 sprintf(buf, "Area: %0.2f cm%c%c", 1906 sprintf(buf, "Area: %0.2f cm%c%c",
1919 area / 100.0, 1907 area / 100.0,
1977 public: 1965 public:
1978 RectangleProbeAnnotation(AnnotationsSceneLayer& that, 1966 RectangleProbeAnnotation(AnnotationsSceneLayer& that,
1979 Units units, 1967 Units units,
1980 const ScenePoint2D& p1, 1968 const ScenePoint2D& p1,
1981 const ScenePoint2D& p2) : 1969 const ScenePoint2D& p2) :
1982 ProbingAnnotation(that, units), 1970 ProbingAnnotation(that),
1971 units_(units),
1983 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))), 1972 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))),
1984 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))), 1973 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))),
1985 segment1_(AddTypedPrimitive<Segment>(new Segment(*this, p1.GetX(), p1.GetY(), p2.GetX(), p1.GetY()))), 1974 segment1_(AddTypedPrimitive<Segment>(new Segment(*this, p1.GetX(), p1.GetY(), p2.GetX(), p1.GetY()))),
1986 segment2_(AddTypedPrimitive<Segment>(new Segment(*this, p2.GetX(), p1.GetY(), p2.GetX(), p2.GetY()))), 1975 segment2_(AddTypedPrimitive<Segment>(new Segment(*this, p2.GetX(), p1.GetY(), p2.GetX(), p2.GetY()))),
1987 segment3_(AddTypedPrimitive<Segment>(new Segment(*this, p1.GetX(), p2.GetY(), p2.GetX(), p2.GetY()))), 1976 segment3_(AddTypedPrimitive<Segment>(new Segment(*this, p1.GetX(), p2.GetY(), p2.GetX(), p2.GetY()))),
2132 2121
2133 2122
2134 class AnnotationsSceneLayer::EllipseProbeAnnotation : public ProbingAnnotation 2123 class AnnotationsSceneLayer::EllipseProbeAnnotation : public ProbingAnnotation
2135 { 2124 {
2136 private: 2125 private:
2126 Units units_;
2137 Handle& handle1_; 2127 Handle& handle1_;
2138 Handle& handle2_; 2128 Handle& handle2_;
2139 Ellipse& ellipse_; 2129 Ellipse& ellipse_;
2140 Text& label_; 2130 Text& label_;
2141 2131
2163 2153
2164 std::string text; 2154 std::string text;
2165 2155
2166 char buf[32]; 2156 char buf[32];
2167 2157
2168 if (GetUnits() == Units_Millimeters) 2158 if (units_ == Units_Millimeters)
2169 { 2159 {
2170 sprintf(buf, "Area: %0.2f cm%c%c", 2160 sprintf(buf, "Area: %0.2f cm%c%c",
2171 ellipse_.GetArea() / 100.0, 2161 ellipse_.GetArea() / 100.0,
2172 0xc2, 0xb2 /* two bytes corresponding to two power in UTF-8 */); 2162 0xc2, 0xb2 /* two bytes corresponding to two power in UTF-8 */);
2173 text = buf; 2163 text = buf;
2235 public: 2225 public:
2236 EllipseProbeAnnotation(AnnotationsSceneLayer& that, 2226 EllipseProbeAnnotation(AnnotationsSceneLayer& that,
2237 Units units, 2227 Units units,
2238 const ScenePoint2D& p1, 2228 const ScenePoint2D& p1,
2239 const ScenePoint2D& p2) : 2229 const ScenePoint2D& p2) :
2240 ProbingAnnotation(that, units), 2230 ProbingAnnotation(that),
2231 units_(units),
2241 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))), 2232 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))),
2242 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))), 2233 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))),
2243 ellipse_(AddTypedPrimitive<Ellipse>(new Ellipse(*this, p1, p2))), 2234 ellipse_(AddTypedPrimitive<Ellipse>(new Ellipse(*this, p1, p2))),
2244 label_(AddTypedPrimitive<Text>(new Text(that, *this))) 2235 label_(AddTypedPrimitive<Text>(new Text(that, *this)))
2245 { 2236 {
2395 AngleAnnotation* angle_; 2386 AngleAnnotation* angle_;
2396 AffineTransform2D canvasToScene_; 2387 AffineTransform2D canvasToScene_;
2397 2388
2398 public: 2389 public:
2399 CreateAngleTracker(AnnotationsSceneLayer& that, 2390 CreateAngleTracker(AnnotationsSceneLayer& that,
2400 Units units,
2401 const ScenePoint2D& sceneClick, 2391 const ScenePoint2D& sceneClick,
2402 const AffineTransform2D& canvasToScene) : 2392 const AffineTransform2D& canvasToScene) :
2403 that_(that), 2393 that_(that),
2404 length_(NULL), 2394 length_(NULL),
2405 angle_(NULL), 2395 angle_(NULL),
2406 canvasToScene_(canvasToScene) 2396 canvasToScene_(canvasToScene)
2407 { 2397 {
2408 length_ = new LengthAnnotation(that, units, false /* no length label */, sceneClick, sceneClick); 2398 length_ = new LengthAnnotation(that, that.GetUnits(), false /* no length label */, sceneClick, sceneClick);
2409 } 2399 }
2410 2400
2411 virtual void PointerMove(const PointerEvent& event, 2401 virtual void PointerMove(const PointerEvent& event,
2412 const Scene2D& scene) ORTHANC_OVERRIDE 2402 const Scene2D& scene) ORTHANC_OVERRIDE
2413 { 2403 {
2431 { 2421 {
2432 if (length_ != NULL) 2422 if (length_ != NULL)
2433 { 2423 {
2434 // End of first step: The first segment is available, now create the angle 2424 // End of first step: The first segment is available, now create the angle
2435 2425
2436 angle_ = new AngleAnnotation(that_, length_->GetUnits(), length_->GetHandle(0).GetCenter(), 2426 angle_ = new AngleAnnotation(that_, length_->GetHandle(0).GetCenter(),
2437 length_->GetHandle(1).GetCenter(), 2427 length_->GetHandle(1).GetCenter(),
2438 length_->GetHandle(1).GetCenter()); 2428 length_->GetHandle(1).GetCenter());
2439 2429
2440 that_.DeleteAnnotation(length_); 2430 that_.DeleteAnnotation(length_);
2441 length_ = NULL; 2431 length_ = NULL;
2480 2470
2481 class AnnotationsSceneLayer::CreatePixelProbeTracker : public IFlexiblePointerTracker 2471 class AnnotationsSceneLayer::CreatePixelProbeTracker : public IFlexiblePointerTracker
2482 { 2472 {
2483 public: 2473 public:
2484 CreatePixelProbeTracker(AnnotationsSceneLayer& that, 2474 CreatePixelProbeTracker(AnnotationsSceneLayer& that,
2485 Units units,
2486 const ScenePoint2D& sceneClick, 2475 const ScenePoint2D& sceneClick,
2487 const Scene2D& scene) 2476 const Scene2D& scene)
2488 { 2477 {
2489 PixelProbeAnnotation* annotation = new PixelProbeAnnotation(that, units, sceneClick); 2478 PixelProbeAnnotation* annotation = new PixelProbeAnnotation(that, sceneClick);
2490 annotation->UpdateProbe(scene); 2479 annotation->UpdateProbe(scene);
2491 that.BroadcastMessage(AnnotationAddedMessage(that)); 2480 that.BroadcastMessage(AnnotationAddedMessage(that));
2492 } 2481 }
2493 2482
2494 virtual void PointerMove(const PointerEvent& event, 2483 virtual void PointerMove(const PointerEvent& event,
2639 2628
2640 void AnnotationsSceneLayer::AddAngleAnnotation(const ScenePoint2D& p1, 2629 void AnnotationsSceneLayer::AddAngleAnnotation(const ScenePoint2D& p1,
2641 const ScenePoint2D& p2, 2630 const ScenePoint2D& p2,
2642 const ScenePoint2D& p3) 2631 const ScenePoint2D& p3)
2643 { 2632 {
2644 annotations_.insert(new AngleAnnotation(*this, units_, p1, p2, p3)); 2633 annotations_.insert(new AngleAnnotation(*this, p1, p2, p3));
2645 } 2634 }
2646 2635
2647 2636
2648 void AnnotationsSceneLayer::Render(Scene2D& scene) 2637 void AnnotationsSceneLayer::Render(Scene2D& scene)
2649 { 2638 {
2801 Annotation* annotation = new CircleAnnotation(*this, units_, s, s); 2790 Annotation* annotation = new CircleAnnotation(*this, units_, s, s);
2802 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform()); 2791 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform());
2803 } 2792 }
2804 2793
2805 case Tool_Angle: 2794 case Tool_Angle:
2806 return new CreateAngleTracker(*this, units_, s, scene.GetCanvasToSceneTransform()); 2795 return new CreateAngleTracker(*this, s, scene.GetCanvasToSceneTransform());
2807 2796
2808 case Tool_PixelProbe: 2797 case Tool_PixelProbe:
2809 return new CreatePixelProbeTracker(*this, units_, s, scene); 2798 return new CreatePixelProbeTracker(*this, s, scene);
2810 2799
2811 case Tool_RectangleProbe: 2800 case Tool_RectangleProbe:
2812 { 2801 {
2813 Annotation* annotation = new RectangleProbeAnnotation(*this, units_, s, s); 2802 Annotation* annotation = new RectangleProbeAnnotation(*this, units_, s, s);
2814 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform()); 2803 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform());
2820 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform()); 2809 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform());
2821 } 2810 }
2822 2811
2823 case Tool_TextAnnotation: 2812 case Tool_TextAnnotation:
2824 { 2813 {
2825 Annotation* annotation = new TextAnnotation(*this, units_, "" /* empty label */, s, s); 2814 Annotation* annotation = new TextAnnotation(*this, "" /* empty label */, s, s);
2826 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform()); 2815 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform());
2827 } 2816 }
2828 2817
2829 default: 2818 default:
2830 return NULL; 2819 return NULL;
2907 2896
2908 const std::string& type = annotations[i][KEY_TYPE].asString(); 2897 const std::string& type = annotations[i][KEY_TYPE].asString();
2909 2898
2910 if (type == VALUE_ANGLE) 2899 if (type == VALUE_ANGLE)
2911 { 2900 {
2912 AngleAnnotation::Unserialize(*this, units_, annotations[i]); 2901 AngleAnnotation::Unserialize(*this, annotations[i]);
2913 } 2902 }
2914 else if (type == VALUE_CIRCLE) 2903 else if (type == VALUE_CIRCLE)
2915 { 2904 {
2916 CircleAnnotation::Unserialize(*this, units_, annotations[i]); 2905 CircleAnnotation::Unserialize(*this, units_, annotations[i]);
2917 } 2906 }
2919 { 2908 {
2920 LengthAnnotation::Unserialize(*this, units_, annotations[i]); 2909 LengthAnnotation::Unserialize(*this, units_, annotations[i]);
2921 } 2910 }
2922 else if (type == VALUE_PIXEL_PROBE) 2911 else if (type == VALUE_PIXEL_PROBE)
2923 { 2912 {
2924 PixelProbeAnnotation::Unserialize(*this, units_, annotations[i]); 2913 PixelProbeAnnotation::Unserialize(*this, annotations[i]);
2925 } 2914 }
2926 else if (type == VALUE_RECTANGLE_PROBE) 2915 else if (type == VALUE_RECTANGLE_PROBE)
2927 { 2916 {
2928 RectangleProbeAnnotation::Unserialize(*this, units_, annotations[i]); 2917 RectangleProbeAnnotation::Unserialize(*this, units_, annotations[i]);
2929 } 2918 }
2931 { 2920 {
2932 EllipseProbeAnnotation::Unserialize(*this, units_, annotations[i]); 2921 EllipseProbeAnnotation::Unserialize(*this, units_, annotations[i]);
2933 } 2922 }
2934 else if (type == VALUE_TEXT_ANNOTATION) 2923 else if (type == VALUE_TEXT_ANNOTATION)
2935 { 2924 {
2936 TextAnnotation::Unserialize(*this, units_, annotations[i]); 2925 TextAnnotation::Unserialize(*this, annotations[i]);
2937 } 2926 }
2938 else 2927 else
2939 { 2928 {
2940 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type; 2929 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type;
2941 } 2930 }