Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 1823:781e9fc8925e
dragging circle annotations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 26 May 2021 20:52:13 +0200 |
parents | 36430d73e36c |
children | 3889ae96d2e9 |
comparison
equal
deleted
inserted
replaced
1822:0489fe25ce48 | 1823:781e9fc8925e |
---|---|
404 class AnnotationsSceneLayer::Circle : public GeometricPrimitive | 404 class AnnotationsSceneLayer::Circle : public GeometricPrimitive |
405 { | 405 { |
406 private: | 406 private: |
407 ScenePoint2D p1_; | 407 ScenePoint2D p1_; |
408 ScenePoint2D p2_; | 408 ScenePoint2D p2_; |
409 ScenePoint2D delta_; | |
409 | 410 |
410 public: | 411 public: |
411 Circle(Annotation& parentAnnotation, | 412 Circle(Annotation& parentAnnotation, |
412 const ScenePoint2D& p1, | 413 const ScenePoint2D& p1, |
413 const ScenePoint2D& p2) : | 414 const ScenePoint2D& p2) : |
414 GeometricPrimitive(parentAnnotation, 2), | 415 GeometricPrimitive(parentAnnotation, 2), |
415 p1_(p1), | 416 p1_(p1), |
416 p2_(p2) | 417 p2_(p2), |
418 delta_(0, 0) | |
417 { | 419 { |
418 } | 420 } |
419 | 421 |
420 void SetPosition(const ScenePoint2D& p1, | 422 void SetPosition(const ScenePoint2D& p1, |
421 const ScenePoint2D& p2) | 423 const ScenePoint2D& p2) |
422 { | 424 { |
423 SetModified(true); | 425 SetModified(true); |
424 p1_ = p1; | 426 p1_ = p1; |
425 p2_ = p2; | 427 p2_ = p2; |
428 delta_ = ScenePoint2D(0, 0); | |
426 } | 429 } |
427 | 430 |
428 ScenePoint2D GetPosition1() const | 431 ScenePoint2D GetPosition1() const |
429 { | 432 { |
430 return p1_; | 433 return p1_ + delta_; |
431 } | 434 } |
432 | 435 |
433 ScenePoint2D GetPosition2() const | 436 ScenePoint2D GetPosition2() const |
434 { | 437 { |
435 return p2_; | 438 return p2_ + delta_; |
436 } | 439 } |
437 | 440 |
438 virtual bool IsHit(const ScenePoint2D& p, | 441 virtual bool IsHit(const ScenePoint2D& p, |
439 const Scene2D& scene) const ORTHANC_OVERRIDE | 442 const Scene2D& scene) const ORTHANC_OVERRIDE |
440 { | 443 { |
441 return false; | 444 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); |
442 } | |
443 | |
444 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
445 const Scene2D& scene) ORTHANC_OVERRIDE | |
446 { | |
447 static unsigned int NUM_SEGMENTS = 128; | |
448 | 445 |
449 ScenePoint2D middle((p1_.GetX() + p2_.GetX()) / 2.0, | 446 ScenePoint2D middle((p1_.GetX() + p2_.GetX()) / 2.0, |
450 (p1_.GetY() + p2_.GetY()) / 2.0); | 447 (p1_.GetY() + p2_.GetY()) / 2.0); |
451 | 448 |
452 const double radius = ScenePoint2D::DistancePtPt(middle, p1_); | 449 const double radius = ScenePoint2D::DistancePtPt(middle, p1_); |
450 const double distance = ScenePoint2D::DistancePtPt(middle, p - delta_); | |
451 | |
452 return std::abs(radius - distance) * zoom <= HANDLE_SIZE / 2.0; | |
453 } | |
454 | |
455 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
456 const Scene2D& scene) ORTHANC_OVERRIDE | |
457 { | |
458 static unsigned int NUM_SEGMENTS = 128; | |
459 | |
460 ScenePoint2D middle((p1_.GetX() + p2_.GetX()) / 2.0, | |
461 (p1_.GetY() + p2_.GetY()) / 2.0); | |
462 | |
463 const double radius = ScenePoint2D::DistancePtPt(middle, p1_); | |
453 | 464 |
454 double increment = 2.0 * PI / static_cast<double>(NUM_SEGMENTS - 1); | 465 double increment = 2.0 * PI / static_cast<double>(NUM_SEGMENTS - 1); |
455 | 466 |
456 PolylineSceneLayer::Chain chain; | 467 PolylineSceneLayer::Chain chain; |
457 chain.reserve(NUM_SEGMENTS); | 468 chain.reserve(NUM_SEGMENTS); |
458 | 469 |
459 double theta = 0; | 470 double theta = 0; |
460 for (unsigned int i = 0; i < NUM_SEGMENTS; i++) | 471 for (unsigned int i = 0; i < NUM_SEGMENTS; i++) |
461 { | 472 { |
462 chain.push_back(ScenePoint2D(middle.GetX() + radius * cos(theta), | 473 chain.push_back(ScenePoint2D(delta_.GetX() + middle.GetX() + radius * cos(theta), |
463 middle.GetY() + radius * sin(theta))); | 474 delta_.GetY() + middle.GetY() + radius * sin(theta))); |
464 theta += increment; | 475 theta += increment; |
465 } | 476 } |
466 | 477 |
467 if (IsHover()) | 478 if (IsHover()) |
468 { | 479 { |
479 { | 490 { |
480 } | 491 } |
481 | 492 |
482 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE | 493 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE |
483 { | 494 { |
484 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | 495 SetModified(true); |
496 delta_ = delta; | |
497 GetParentAnnotation().SignalMove(*this); | |
485 } | 498 } |
486 | 499 |
487 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE | 500 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE |
488 { | 501 { |
489 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | 502 SetModified(true); |
503 p1_ = p1_ + delta; | |
504 p2_ = p2_ + delta; | |
505 delta_ = ScenePoint2D(0, 0); | |
506 GetParentAnnotation().SignalMove(*this); | |
490 } | 507 } |
491 }; | 508 }; |
492 | 509 |
493 | 510 |
494 class AnnotationsSceneLayer::Arc : public GeometricPrimitive | 511 class AnnotationsSceneLayer::Arc : public GeometricPrimitive |
1122 { | 1139 { |
1123 handle1_.SetCenter(segment_.GetPosition1()); | 1140 handle1_.SetCenter(segment_.GetPosition1()); |
1124 handle2_.SetCenter(segment_.GetPosition2()); | 1141 handle2_.SetCenter(segment_.GetPosition2()); |
1125 circle_.SetPosition(segment_.GetPosition1(), segment_.GetPosition2()); | 1142 circle_.SetPosition(segment_.GetPosition1(), segment_.GetPosition2()); |
1126 } | 1143 } |
1144 else if (&primitive == &circle_) | |
1145 { | |
1146 handle1_.SetCenter(circle_.GetPosition1()); | |
1147 handle2_.SetCenter(circle_.GetPosition2()); | |
1148 segment_.SetPosition(circle_.GetPosition1(), circle_.GetPosition2()); | |
1149 } | |
1127 | 1150 |
1128 UpdateLabel(); | 1151 UpdateLabel(); |
1129 } | 1152 } |
1130 | 1153 |
1131 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE | 1154 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |