comparison Framework/Scene2DViewport/CreateLineMeasureTracker.cpp @ 700:059e1fd05fd6 refactor-viewport-controller

Introduced the ViewportController that sits between the application and the Scene2D to handle the trackers and measuring tools. This is a work in progress. The Scene2D is no longer an observable. Message sending is managed by the ViewportController. Move some refs to shared and weak to prevent lifetime issues.
author Benjamin Golinvaux <bgo@osimis.io>
date Sun, 19 May 2019 16:26:17 +0200
parents 8b6adfb62a2f
children 28b9e3a54200
comparison
equal deleted inserted replaced
699:5c551f078c18 700:059e1fd05fd6
25 25
26 namespace OrthancStone 26 namespace OrthancStone
27 { 27 {
28 CreateLineMeasureTracker::CreateLineMeasureTracker( 28 CreateLineMeasureTracker::CreateLineMeasureTracker(
29 MessageBroker& broker, 29 MessageBroker& broker,
30 Scene2DWPtr sceneW, 30 ViewportControllerWPtr controllerW,
31 std::vector<TrackerCommandPtr>& undoStack, 31 std::vector<TrackerCommandPtr>& undoStack,
32 MeasureToolList& measureTools, 32 MeasureToolList& measureTools,
33 const PointerEvent& e) 33 const PointerEvent& e)
34 : CreateMeasureTracker(sceneW, undoStack, measureTools) 34 : CreateMeasureTracker(controllerW, undoStack, measureTools)
35 { 35 {
36 Scene2DPtr scene = sceneW.lock();
37 command_.reset( 36 command_.reset(
38 new CreateLineMeasureCommand( 37 new CreateLineMeasureCommand(
39 broker, 38 broker,
40 sceneW, 39 controllerW,
41 measureTools, 40 measureTools,
42 e.GetMainPosition().Apply(scene->GetCanvasToSceneTransform()))); 41 e.GetMainPosition().Apply(GetScene()->GetCanvasToSceneTransform())));
43 } 42 }
44 43
45 CreateLineMeasureTracker::~CreateLineMeasureTracker() 44 CreateLineMeasureTracker::~CreateLineMeasureTracker()
46 { 45 {
47 46
48 } 47 }
49 48
50 void CreateLineMeasureTracker::PointerMove(const PointerEvent& event) 49 void CreateLineMeasureTracker::PointerMove(const PointerEvent& event)
51 { 50 {
52 Scene2DPtr scene = scene_.lock(); 51 assert(GetScene());
53 assert(scene);
54 52
55 if (!active_) 53 if (!alive_)
56 { 54 {
57 throw OrthancException(ErrorCode_InternalError, 55 throw OrthancException(ErrorCode_InternalError,
58 "Internal error: wrong state in CreateLineMeasureTracker::" 56 "Internal error: wrong state in CreateLineMeasureTracker::"
59 "PointerMove: active_ == false"); 57 "PointerMove: active_ == false");
60 } 58 }
61 59
62 ScenePoint2D scenePos = event.GetMainPosition().Apply( 60 ScenePoint2D scenePos = event.GetMainPosition().Apply(
63 scene->GetCanvasToSceneTransform()); 61 GetScene()->GetCanvasToSceneTransform());
64 62
65 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " << 63 //LOG(TRACE) << "scenePos.GetX() = " << scenePos.GetX() << " " <<
66 // "scenePos.GetY() = " << scenePos.GetY(); 64 // "scenePos.GetY() = " << scenePos.GetY();
67 65
68 CreateLineMeasureTracker* concreteThis = 66 CreateLineMeasureTracker* concreteThis =
76 // TODO: the current app does not prevent multiple PointerDown AND 74 // TODO: the current app does not prevent multiple PointerDown AND
77 // PointerUp to be sent to the tracker. 75 // PointerUp to be sent to the tracker.
78 // Unless we augment the PointerEvent structure with the button index, 76 // Unless we augment the PointerEvent structure with the button index,
79 // we cannot really tell if this pointer up event matches the initial 77 // we cannot really tell if this pointer up event matches the initial
80 // pointer down event. Let's make it simple for now. 78 // pointer down event. Let's make it simple for now.
81 active_ = false; 79 alive_ = false;
82 } 80 }
83 81
84 void CreateLineMeasureTracker::PointerDown(const PointerEvent& e) 82 void CreateLineMeasureTracker::PointerDown(const PointerEvent& e)
85 { 83 {
86 LOG(WARNING) << "Additional touches (fingers, pen, mouse buttons...) " 84 LOG(WARNING) << "Additional touches (fingers, pen, mouse buttons...) "