Mercurial > hg > orthanc-stone
comparison Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp @ 1801:64dad1d7aca4
renamed subclass
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 May 2021 13:23:59 +0200 |
parents | 2c0497d61a5d |
children | d1849468729b |
comparison
equal
deleted
inserted
replaced
1800:2c0497d61a5d | 1801:64dad1d7aca4 |
---|---|
82 }; | 82 }; |
83 | 83 |
84 private: | 84 private: |
85 class Annotation; | 85 class Annotation; |
86 | 86 |
87 class Primitive : public boost::noncopyable | 87 class GeometricPrimitive : public boost::noncopyable |
88 { | 88 { |
89 private: | 89 private: |
90 bool modified_; | 90 bool modified_; |
91 Annotation& parentAnnotation_; | 91 Annotation& parentAnnotation_; |
92 Color color_; | 92 Color color_; |
93 Color hoverColor_; | 93 Color hoverColor_; |
94 bool isHover_; | 94 bool isHover_; |
95 int depth_; | 95 int depth_; |
96 | 96 |
97 public: | 97 public: |
98 Primitive(Annotation& parentAnnotation, | 98 GeometricPrimitive(Annotation& parentAnnotation, |
99 int depth) : | 99 int depth) : |
100 modified_(true), | 100 modified_(true), |
101 parentAnnotation_(parentAnnotation), | 101 parentAnnotation_(parentAnnotation), |
102 color_(192, 192, 192), | 102 color_(192, 192, 192), |
103 hoverColor_(0, 255, 0), | 103 hoverColor_(0, 255, 0), |
104 isHover_(false), | 104 isHover_(false), |
105 depth_(depth) | 105 depth_(depth) |
106 { | 106 { |
107 } | 107 } |
108 | 108 |
109 virtual ~Primitive() | 109 virtual ~GeometricPrimitive() |
110 { | 110 { |
111 } | 111 } |
112 | 112 |
113 Annotation& GetParentAnnotation() const | 113 Annotation& GetParentAnnotation() const |
114 { | 114 { |
184 | 184 |
185 | 185 |
186 class Annotation : public boost::noncopyable | 186 class Annotation : public boost::noncopyable |
187 { | 187 { |
188 private: | 188 private: |
189 typedef std::list<Primitive*> Primitives; | 189 typedef std::list<GeometricPrimitive*> GeometricPrimitives; |
190 | 190 |
191 AnnotationsOverlay& that_; | 191 AnnotationsOverlay& that_; |
192 Primitives primitives_; | 192 GeometricPrimitives primitives_; |
193 | 193 |
194 public: | 194 public: |
195 Annotation(AnnotationsOverlay& that) : | 195 Annotation(AnnotationsOverlay& that) : |
196 that_(that) | 196 that_(that) |
197 { | 197 { |
198 that.AddAnnotation(this); | 198 that.AddAnnotation(this); |
199 } | 199 } |
200 | 200 |
201 virtual ~Annotation() | 201 virtual ~Annotation() |
202 { | 202 { |
203 for (Primitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | 203 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) |
204 { | 204 { |
205 that_.DeletePrimitive(*it); | 205 that_.DeletePrimitive(*it); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 Primitive* AddPrimitive(Primitive* primitive) | 209 GeometricPrimitive* AddPrimitive(GeometricPrimitive* primitive) |
210 { | 210 { |
211 if (primitive == NULL) | 211 if (primitive == NULL) |
212 { | 212 { |
213 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 213 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
214 } | 214 } |
226 { | 226 { |
227 AddPrimitive(primitive); | 227 AddPrimitive(primitive); |
228 return *primitive; | 228 return *primitive; |
229 } | 229 } |
230 | 230 |
231 virtual void SignalMove(Primitive& primitive) = 0; | 231 virtual void SignalMove(GeometricPrimitive& primitive) = 0; |
232 | 232 |
233 virtual void Serialize(Json::Value& target) = 0; | 233 virtual void Serialize(Json::Value& target) = 0; |
234 }; | 234 }; |
235 | 235 |
236 | 236 |
237 class Handle : public Primitive | 237 class Handle : public GeometricPrimitive |
238 { | 238 { |
239 private: | 239 private: |
240 ScenePoint2D center_; | 240 ScenePoint2D center_; |
241 ScenePoint2D delta_; | 241 ScenePoint2D delta_; |
242 | 242 |
243 public: | 243 public: |
244 explicit Handle(Annotation& parentAnnotation, | 244 explicit Handle(Annotation& parentAnnotation, |
245 const ScenePoint2D& center) : | 245 const ScenePoint2D& center) : |
246 Primitive(parentAnnotation, 0), // Highest priority | 246 GeometricPrimitive(parentAnnotation, 0), // Highest priority |
247 center_(center), | 247 center_(center), |
248 delta_(0, 0) | 248 delta_(0, 0) |
249 { | 249 { |
250 } | 250 } |
251 | 251 |
326 GetParentAnnotation().SignalMove(*this); | 326 GetParentAnnotation().SignalMove(*this); |
327 } | 327 } |
328 }; | 328 }; |
329 | 329 |
330 | 330 |
331 class Segment : public Primitive | 331 class Segment : public GeometricPrimitive |
332 { | 332 { |
333 private: | 333 private: |
334 ScenePoint2D p1_; | 334 ScenePoint2D p1_; |
335 ScenePoint2D p2_; | 335 ScenePoint2D p2_; |
336 ScenePoint2D delta_; | 336 ScenePoint2D delta_; |
337 | 337 |
338 public: | 338 public: |
339 Segment(Annotation& parentAnnotation, | 339 Segment(Annotation& parentAnnotation, |
340 const ScenePoint2D& p1, | 340 const ScenePoint2D& p1, |
341 const ScenePoint2D& p2) : | 341 const ScenePoint2D& p2) : |
342 Primitive(parentAnnotation, 1), // Can only be selected if no handle matches | 342 GeometricPrimitive(parentAnnotation, 1), // Can only be selected if no handle matches |
343 p1_(p1), | 343 p1_(p1), |
344 p2_(p2), | 344 p2_(p2), |
345 delta_(0, 0) | 345 delta_(0, 0) |
346 { | 346 { |
347 } | 347 } |
412 GetParentAnnotation().SignalMove(*this); | 412 GetParentAnnotation().SignalMove(*this); |
413 } | 413 } |
414 }; | 414 }; |
415 | 415 |
416 | 416 |
417 class Circle : public Primitive | 417 class Circle : public GeometricPrimitive |
418 { | 418 { |
419 private: | 419 private: |
420 ScenePoint2D p1_; | 420 ScenePoint2D p1_; |
421 ScenePoint2D p2_; | 421 ScenePoint2D p2_; |
422 | 422 |
423 public: | 423 public: |
424 Circle(Annotation& parentAnnotation, | 424 Circle(Annotation& parentAnnotation, |
425 const ScenePoint2D& p1, | 425 const ScenePoint2D& p1, |
426 const ScenePoint2D& p2) : | 426 const ScenePoint2D& p2) : |
427 Primitive(parentAnnotation, 2), | 427 GeometricPrimitive(parentAnnotation, 2), |
428 p1_(p1), | 428 p1_(p1), |
429 p2_(p2) | 429 p2_(p2) |
430 { | 430 { |
431 } | 431 } |
432 | 432 |
502 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | 502 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible |
503 } | 503 } |
504 }; | 504 }; |
505 | 505 |
506 | 506 |
507 class Arc : public Primitive | 507 class Arc : public GeometricPrimitive |
508 { | 508 { |
509 private: | 509 private: |
510 ScenePoint2D start_; | 510 ScenePoint2D start_; |
511 ScenePoint2D middle_; | 511 ScenePoint2D middle_; |
512 ScenePoint2D end_; | 512 ScenePoint2D end_; |
542 public: | 542 public: |
543 Arc(Annotation& parentAnnotation, | 543 Arc(Annotation& parentAnnotation, |
544 const ScenePoint2D& start, | 544 const ScenePoint2D& start, |
545 const ScenePoint2D& middle, | 545 const ScenePoint2D& middle, |
546 const ScenePoint2D& end) : | 546 const ScenePoint2D& end) : |
547 Primitive(parentAnnotation, 2), | 547 GeometricPrimitive(parentAnnotation, 2), |
548 start_(start), | 548 start_(start), |
549 middle_(middle), | 549 middle_(middle), |
550 end_(end), | 550 end_(end), |
551 radius_(20) | 551 radius_(20) |
552 { | 552 { |
631 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | 631 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible |
632 } | 632 } |
633 }; | 633 }; |
634 | 634 |
635 | 635 |
636 class Text : public Primitive | 636 class Text : public GeometricPrimitive |
637 { | 637 { |
638 private: | 638 private: |
639 AnnotationsOverlay& that_; | 639 AnnotationsOverlay& that_; |
640 bool first_; | 640 bool first_; |
641 size_t subLayer_; | 641 size_t subLayer_; |
642 std::unique_ptr<TextSceneLayer> content_; | 642 std::unique_ptr<TextSceneLayer> content_; |
643 | 643 |
644 public: | 644 public: |
645 Text(AnnotationsOverlay& that, | 645 Text(AnnotationsOverlay& that, |
646 Annotation& parentAnnotation) : | 646 Annotation& parentAnnotation) : |
647 Primitive(parentAnnotation, 2), | 647 GeometricPrimitive(parentAnnotation, 2), |
648 that_(that), | 648 that_(that), |
649 first_(true) | 649 first_(true) |
650 { | 650 { |
651 } | 651 } |
652 | 652 |
709 | 709 |
710 | 710 |
711 class EditPrimitiveTracker : public IFlexiblePointerTracker | 711 class EditPrimitiveTracker : public IFlexiblePointerTracker |
712 { | 712 { |
713 private: | 713 private: |
714 Primitive& primitive_; | 714 GeometricPrimitive& primitive_; |
715 ScenePoint2D sceneClick_; | 715 ScenePoint2D sceneClick_; |
716 AffineTransform2D canvasToScene_; | 716 AffineTransform2D canvasToScene_; |
717 bool alive_; | 717 bool alive_; |
718 | 718 |
719 public: | 719 public: |
720 EditPrimitiveTracker(Primitive& primitive, | 720 EditPrimitiveTracker(GeometricPrimitive& primitive, |
721 const ScenePoint2D& sceneClick, | 721 const ScenePoint2D& sceneClick, |
722 const AffineTransform2D& canvasToScene) : | 722 const AffineTransform2D& canvasToScene) : |
723 primitive_(primitive), | 723 primitive_(primitive), |
724 sceneClick_(sceneClick), | 724 sceneClick_(sceneClick), |
725 canvasToScene_(canvasToScene), | 725 canvasToScene_(canvasToScene), |
821 Handle& GetHandle2() const | 821 Handle& GetHandle2() const |
822 { | 822 { |
823 return handle2_; | 823 return handle2_; |
824 } | 824 } |
825 | 825 |
826 virtual void SignalMove(Primitive& primitive) ORTHANC_OVERRIDE | 826 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE |
827 { | 827 { |
828 if (&primitive == &handle1_ || | 828 if (&primitive == &handle1_ || |
829 &primitive == &handle2_) | 829 &primitive == &handle2_) |
830 { | 830 { |
831 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); | 831 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); |
935 Handle& GetEndHandle() const | 935 Handle& GetEndHandle() const |
936 { | 936 { |
937 return endHandle_; | 937 return endHandle_; |
938 } | 938 } |
939 | 939 |
940 virtual void SignalMove(Primitive& primitive) ORTHANC_OVERRIDE | 940 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE |
941 { | 941 { |
942 if (&primitive == &startHandle_) | 942 if (&primitive == &startHandle_) |
943 { | 943 { |
944 segment1_.SetPosition(startHandle_.GetCenter(), middleHandle_.GetCenter()); | 944 segment1_.SetPosition(startHandle_.GetCenter(), middleHandle_.GetCenter()); |
945 arc_.SetStart(startHandle_.GetCenter()); | 945 arc_.SetStart(startHandle_.GetCenter()); |
1081 Handle& GetHandle2() const | 1081 Handle& GetHandle2() const |
1082 { | 1082 { |
1083 return handle2_; | 1083 return handle2_; |
1084 } | 1084 } |
1085 | 1085 |
1086 virtual void SignalMove(Primitive& primitive) ORTHANC_OVERRIDE | 1086 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE |
1087 { | 1087 { |
1088 if (&primitive == &handle1_ || | 1088 if (&primitive == &handle1_ || |
1089 &primitive == &handle2_) | 1089 &primitive == &handle2_) |
1090 { | 1090 { |
1091 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); | 1091 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); |
1314 { | 1314 { |
1315 } | 1315 } |
1316 }; | 1316 }; |
1317 | 1317 |
1318 | 1318 |
1319 typedef std::set<Primitive*> Primitives; | 1319 typedef std::set<GeometricPrimitive*> GeometricPrimitives; |
1320 typedef std::set<Annotation*> Annotations; | 1320 typedef std::set<Annotation*> Annotations; |
1321 typedef std::set<size_t> SubLayers; | 1321 typedef std::set<size_t> SubLayers; |
1322 | 1322 |
1323 Tool activeTool_; | 1323 Tool activeTool_; |
1324 size_t macroLayerIndex_; | 1324 size_t macroLayerIndex_; |
1325 size_t polylineSubLayer_; | 1325 size_t polylineSubLayer_; |
1326 Primitives primitives_; | 1326 GeometricPrimitives primitives_; |
1327 Annotations annotations_; | 1327 Annotations annotations_; |
1328 SubLayers subLayersToRemove_; | 1328 SubLayers subLayersToRemove_; |
1329 | 1329 |
1330 void AddAnnotation(Annotation* annotation) | 1330 void AddAnnotation(Annotation* annotation) |
1331 { | 1331 { |
1332 assert(annotation != NULL); | 1332 assert(annotation != NULL); |
1333 assert(annotations_.find(annotation) == annotations_.end()); | 1333 assert(annotations_.find(annotation) == annotations_.end()); |
1342 annotations_.erase(annotation); | 1342 annotations_.erase(annotation); |
1343 delete annotation; | 1343 delete annotation; |
1344 } | 1344 } |
1345 } | 1345 } |
1346 | 1346 |
1347 void DeletePrimitive(Primitive* primitive) | 1347 void DeletePrimitive(GeometricPrimitive* primitive) |
1348 { | 1348 { |
1349 if (primitive != NULL) | 1349 if (primitive != NULL) |
1350 { | 1350 { |
1351 assert(primitives_.find(primitive) != primitives_.end()); | 1351 assert(primitives_.find(primitive) != primitives_.end()); |
1352 primitives_.erase(primitive); | 1352 primitives_.erase(primitive); |
1419 | 1419 |
1420 subLayersToRemove_.clear(); | 1420 subLayersToRemove_.clear(); |
1421 | 1421 |
1422 std::unique_ptr<PolylineSceneLayer> polyline(new PolylineSceneLayer); | 1422 std::unique_ptr<PolylineSceneLayer> polyline(new PolylineSceneLayer); |
1423 | 1423 |
1424 for (Primitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | 1424 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) |
1425 { | 1425 { |
1426 assert(*it != NULL); | 1426 assert(*it != NULL); |
1427 Primitive& primitive = **it; | 1427 GeometricPrimitive& primitive = **it; |
1428 | 1428 |
1429 primitive.RenderPolylineLayer(*polyline, scene); | 1429 primitive.RenderPolylineLayer(*polyline, scene); |
1430 | 1430 |
1431 if (primitive.IsModified()) | 1431 if (primitive.IsModified()) |
1432 { | 1432 { |
1440 | 1440 |
1441 bool ClearHover() | 1441 bool ClearHover() |
1442 { | 1442 { |
1443 bool needsRefresh = false; | 1443 bool needsRefresh = false; |
1444 | 1444 |
1445 for (Primitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | 1445 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) |
1446 { | 1446 { |
1447 assert(*it != NULL); | 1447 assert(*it != NULL); |
1448 if ((*it)->IsHover()) | 1448 if ((*it)->IsHover()) |
1449 { | 1449 { |
1450 (*it)->SetHover(false); | 1450 (*it)->SetHover(false); |
1466 { | 1466 { |
1467 bool needsRefresh = false; | 1467 bool needsRefresh = false; |
1468 | 1468 |
1469 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform()); | 1469 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform()); |
1470 | 1470 |
1471 for (Primitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | 1471 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) |
1472 { | 1472 { |
1473 assert(*it != NULL); | 1473 assert(*it != NULL); |
1474 bool hover = (*it)->IsHit(s, scene); | 1474 bool hover = (*it)->IsHit(s, scene); |
1475 | 1475 |
1476 if ((*it)->IsHover() != hover) | 1476 if ((*it)->IsHover() != hover) |
1495 } | 1495 } |
1496 else | 1496 else |
1497 { | 1497 { |
1498 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform()); | 1498 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform()); |
1499 | 1499 |
1500 Primitive* bestHit = NULL; | 1500 GeometricPrimitive* bestHit = NULL; |
1501 | 1501 |
1502 for (Primitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | 1502 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) |
1503 { | 1503 { |
1504 assert(*it != NULL); | 1504 assert(*it != NULL); |
1505 if ((*it)->IsHit(s, scene)) | 1505 if ((*it)->IsHit(s, scene)) |
1506 { | 1506 { |
1507 if (bestHit == NULL || | 1507 if (bestHit == NULL || |