comparison OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 1809:79a5838739a6

starting the integration of AnnotationsSceneLayer into Stone Web viewer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 May 2021 18:52:02 +0200
parents 0840a25c6d41
children db341679dc9f
comparison
equal deleted inserted replaced
1808:797633f48a9c 1809:79a5838739a6
231 { 231 {
232 return center_ + delta_; 232 return center_ + delta_;
233 } 233 }
234 234
235 virtual bool IsHit(const ScenePoint2D& p, 235 virtual bool IsHit(const ScenePoint2D& p,
236 const Scene2D& scene) const 236 const Scene2D& scene) const ORTHANC_OVERRIDE
237 { 237 {
238 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); 238 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom();
239 239
240 double dx = (center_.GetX() + delta_.GetX() - p.GetX()) * zoom; 240 double dx = (center_.GetX() + delta_.GetX() - p.GetX()) * zoom;
241 double dy = (center_.GetY() + delta_.GetY() - p.GetY()) * zoom; 241 double dy = (center_.GetY() + delta_.GetY() - p.GetY()) * zoom;
330 { 330 {
331 return p2_ + delta_; 331 return p2_ + delta_;
332 } 332 }
333 333
334 virtual bool IsHit(const ScenePoint2D& p, 334 virtual bool IsHit(const ScenePoint2D& p,
335 const Scene2D& scene) const 335 const Scene2D& scene) const ORTHANC_OVERRIDE
336 { 336 {
337 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); 337 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom();
338 return (ScenePoint2D::SquaredDistancePtSegment(p1_ + delta_, p2_ + delta_, p) * zoom * zoom <= 338 return (ScenePoint2D::SquaredDistancePtSegment(p1_ + delta_, p2_ + delta_, p) * zoom * zoom <=
339 (HANDLE_SIZE / 2.0) * (HANDLE_SIZE / 2.0)); 339 (HANDLE_SIZE / 2.0) * (HANDLE_SIZE / 2.0));
340 } 340 }
413 { 413 {
414 return p2_; 414 return p2_;
415 } 415 }
416 416
417 virtual bool IsHit(const ScenePoint2D& p, 417 virtual bool IsHit(const ScenePoint2D& p,
418 const Scene2D& scene) const 418 const Scene2D& scene) const ORTHANC_OVERRIDE
419 { 419 {
420 return false; 420 return false;
421 } 421 }
422 422
423 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, 423 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
542 SetModified(true); 542 SetModified(true);
543 end_ = p; 543 end_ = p;
544 } 544 }
545 545
546 virtual bool IsHit(const ScenePoint2D& p, 546 virtual bool IsHit(const ScenePoint2D& p,
547 const Scene2D& scene) const 547 const Scene2D& scene) const ORTHANC_OVERRIDE
548 { 548 {
549 return false; 549 return false;
550 } 550 }
551 551
552 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, 552 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
629 SetModified(true); 629 SetModified(true);
630 content_.reset(dynamic_cast<TextSceneLayer*>(content.Clone())); 630 content_.reset(dynamic_cast<TextSceneLayer*>(content.Clone()));
631 } 631 }
632 632
633 virtual bool IsHit(const ScenePoint2D& p, 633 virtual bool IsHit(const ScenePoint2D& p,
634 const Scene2D& scene) const 634 const Scene2D& scene) const ORTHANC_OVERRIDE
635 { 635 {
636 return false; 636 return false;
637 } 637 }
638 638
639 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, 639 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline,
675 675
676 676
677 class AnnotationsSceneLayer::EditPrimitiveTracker : public IFlexiblePointerTracker 677 class AnnotationsSceneLayer::EditPrimitiveTracker : public IFlexiblePointerTracker
678 { 678 {
679 private: 679 private:
680 GeometricPrimitive& primitive_; 680 AnnotationsSceneLayer& that_;
681 ScenePoint2D sceneClick_; 681 GeometricPrimitive& primitive_;
682 AffineTransform2D canvasToScene_; 682 ScenePoint2D sceneClick_;
683 bool alive_; 683 AffineTransform2D canvasToScene_;
684 bool alive_;
684 685
685 public: 686 public:
686 EditPrimitiveTracker(GeometricPrimitive& primitive, 687 EditPrimitiveTracker(AnnotationsSceneLayer& that,
688 GeometricPrimitive& primitive,
687 const ScenePoint2D& sceneClick, 689 const ScenePoint2D& sceneClick,
688 const AffineTransform2D& canvasToScene) : 690 const AffineTransform2D& canvasToScene) :
691 that_(that),
689 primitive_(primitive), 692 primitive_(primitive),
690 sceneClick_(sceneClick), 693 sceneClick_(sceneClick),
691 canvasToScene_(canvasToScene), 694 canvasToScene_(canvasToScene),
692 alive_(true) 695 alive_(true)
693 { 696 {
694 } 697 }
695 698
696 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE 699 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE
697 { 700 {
698 primitive_.MovePreview(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_); 701 primitive_.MovePreview(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_);
702 that_.BroadcastMessage(AnnotationChangedMessage(that_));
699 } 703 }
700 704
701 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE 705 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE
702 { 706 {
703 primitive_.MoveDone(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_); 707 primitive_.MoveDone(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_);
704 alive_ = false; 708 alive_ = false;
709 that_.BroadcastMessage(AnnotationChangedMessage(that_));
705 } 710 }
706 711
707 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE 712 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE
708 { 713 {
709 } 714 }
1139 if (annotation_ != NULL) 1144 if (annotation_ != NULL)
1140 { 1145 {
1141 assert(handle2_ != NULL); 1146 assert(handle2_ != NULL);
1142 handle2_->SetCenter(event.GetMainPosition().Apply(canvasToScene_)); 1147 handle2_->SetCenter(event.GetMainPosition().Apply(canvasToScene_));
1143 annotation_->SignalMove(*handle2_); 1148 annotation_->SignalMove(*handle2_);
1149
1150 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1144 } 1151 }
1145 } 1152 }
1146 1153
1147 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE 1154 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE
1148 { 1155 {
1195 { 1202 {
1196 if (segment_ != NULL) 1203 if (segment_ != NULL)
1197 { 1204 {
1198 segment_->GetHandle2().SetCenter(event.GetMainPosition().Apply(canvasToScene_)); 1205 segment_->GetHandle2().SetCenter(event.GetMainPosition().Apply(canvasToScene_));
1199 segment_->SignalMove(segment_->GetHandle2()); 1206 segment_->SignalMove(segment_->GetHandle2());
1207 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1200 } 1208 }
1201 1209
1202 if (angle_ != NULL) 1210 if (angle_ != NULL)
1203 { 1211 {
1204 angle_->GetEndHandle().SetCenter(event.GetMainPosition().Apply(canvasToScene_)); 1212 angle_->GetEndHandle().SetCenter(event.GetMainPosition().Apply(canvasToScene_));
1205 angle_->SignalMove(angle_->GetEndHandle()); 1213 angle_->SignalMove(angle_->GetEndHandle());
1214 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1206 } 1215 }
1207 } 1216 }
1208 1217
1209 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE 1218 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE
1210 { 1219 {
1216 segment_->GetHandle2().GetCenter(), 1225 segment_->GetHandle2().GetCenter(),
1217 segment_->GetHandle2().GetCenter()); 1226 segment_->GetHandle2().GetCenter());
1218 1227
1219 that_.DeleteAnnotation(segment_); 1228 that_.DeleteAnnotation(segment_);
1220 segment_ = NULL; 1229 segment_ = NULL;
1230
1231 that_.BroadcastMessage(AnnotationChangedMessage(that_));
1221 } 1232 }
1222 else 1233 else
1223 { 1234 {
1224 angle_ = NULL; // IsAlive() becomes false 1235 angle_ = NULL; // IsAlive() becomes false
1225 1236
1254 }; 1265 };
1255 1266
1256 1267
1257 // Dummy tracker that is only used for deletion, in order to warn 1268 // Dummy tracker that is only used for deletion, in order to warn
1258 // the caller that the mouse action was taken into consideration 1269 // the caller that the mouse action was taken into consideration
1259 class AnnotationsSceneLayer::EraseTracker : public IFlexiblePointerTracker 1270 class AnnotationsSceneLayer::RemoveTracker : public IFlexiblePointerTracker
1260 { 1271 {
1261 public: 1272 public:
1262 EraseTracker() 1273 RemoveTracker()
1263 { 1274 {
1264 } 1275 }
1265 1276
1266 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE 1277 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE
1267 { 1278 {
1482 } 1493 }
1483 } 1494 }
1484 1495
1485 if (bestHit != NULL) 1496 if (bestHit != NULL)
1486 { 1497 {
1487 if (activeTool_ == Tool_Erase) 1498 if (activeTool_ == Tool_Remove)
1488 { 1499 {
1489 DeleteAnnotation(&bestHit->GetParentAnnotation()); 1500 DeleteAnnotation(&bestHit->GetParentAnnotation());
1490 BroadcastMessage(AnnotationRemovedMessage(*this)); 1501 BroadcastMessage(AnnotationRemovedMessage(*this));
1491 return new EraseTracker; 1502 return new RemoveTracker;
1492 } 1503 }
1493 else 1504 else
1494 { 1505 {
1495 return new EditPrimitiveTracker(*bestHit, s, scene.GetCanvasToSceneTransform()); 1506 return new EditPrimitiveTracker(*this, *bestHit, s, scene.GetCanvasToSceneTransform());
1496 } 1507 }
1497 } 1508 }
1498 else 1509 else
1499 { 1510 {
1500 switch (activeTool_) 1511 switch (activeTool_)