comparison Framework/Scene2DViewport/ViewportController.h @ 1331:ab81ee8fce1f broker

- Viewport is not passed and stored as a shared_ptr instead of raw reference. - ViewportController can now be injected with an undo stack (not a ctor param anymore, as a preparation for the move of the undo stack to an interactor) - Added (temp) flag to disable emscripten events registration in the WebAssemblyViewport (because legacy client code deals with them directly) - Added emscripten_clear_timeout in ~WebGLViewportsRegistry - Removed GenericToolbox::HoldingRef whose responsibility is better served with proper callback un-registration.
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 30 Mar 2020 14:23:46 +0200
parents adf234ecaa00
children 30deba7bc8e2
comparison
equal deleted inserted replaced
1329:8d3e669f01a2 1331:ab81ee8fce1f
39 public: 39 public:
40 virtual ~IViewportInteractor() 40 virtual ~IViewportInteractor()
41 { 41 {
42 } 42 }
43 43
44 virtual IFlexiblePointerTracker* CreateTracker(IViewport& viewport, 44 virtual IFlexiblePointerTracker* CreateTracker(boost::shared_ptr<IViewport> viewport,
45 const PointerEvent& event, 45 const PointerEvent& event,
46 unsigned int viewportWidth, 46 unsigned int viewportWidth,
47 unsigned int viewportHeight) = 0; 47 unsigned int viewportHeight) = 0;
48 }; 48 };
49 49
50 50
51 // TODO - Move this to another file 51 // TODO - Move this to another file
52 class DefaultViewportInteractor : public IViewportInteractor 52 class DefaultViewportInteractor : public IViewportInteractor
53 { 53 {
54 public: 54 public:
55 virtual IFlexiblePointerTracker* CreateTracker(IViewport& viewport, 55 virtual IFlexiblePointerTracker* CreateTracker(boost::shared_ptr<IViewport> viewport,
56 const PointerEvent& event, 56 const PointerEvent& event,
57 unsigned int viewportWidth, 57 unsigned int viewportWidth,
58 unsigned int viewportHeight) ORTHANC_OVERRIDE; 58 unsigned int viewportHeight) ORTHANC_OVERRIDE;
59 }; 59 };
60 60
107 public IObservable, 107 public IObservable,
108 public boost::enable_shared_from_this<ViewportController> 108 public boost::enable_shared_from_this<ViewportController>
109 { 109 {
110 public: 110 public:
111 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, \ 111 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, \
112 SceneTransformChanged, ViewportController); 112 SceneTransformChanged, \
113 113 ViewportController);
114 ViewportController(IViewport& viewport); 114
115 115 ViewportController(boost::shared_ptr<IViewport> viewport);
116 ViewportController(IViewport& viewport, const Scene2D& scene /* will be cloned */);
117
118 ViewportController(IViewport& viewport, boost::weak_ptr<UndoStack> undoStackW);
119 116
120 ~ViewportController(); 117 ~ViewportController();
121 118
122 /** 119 /**
123 This method returns the list of measure tools containing the supplied point 120 This method returns the list of measure tools containing the supplied point
124 (in scene coords). A tracker can then be requested from the chosen 121 (in scene coords). A tracker can then be requested from the chosen
125 measure tool, if needed 122 measure tool, if needed
126 */ 123 */
127 std::vector<boost::shared_ptr<MeasureTool> > HitTestMeasureTools(ScenePoint2D p); 124 std::vector<boost::shared_ptr<MeasureTool> > HitTestMeasureTools(
125 ScenePoint2D p);
128 126
129 /** 127 /**
130 This function will traverse the measuring tools and will clear their 128 This function will traverse the measuring tools and will clear their
131 highlighted state 129 highlighted state
132 */ 130 */
221 Scene2D& GetScene() 219 Scene2D& GetScene()
222 { 220 {
223 return *scene_; 221 return *scene_;
224 } 222 }
225 223
224 /**
225 This method is used in a move pattern: when the ownership of the scene
226 managed by this viewport controller must be transferred to another
227 controller.
228 */
229 Scene2D* ReleaseScene()
230 {
231 return scene_.release();
232 }
233
234 /**
235 This method is used when one wishes to replace the scene that is currently
236 managed by the controller. The previous scene is deleted and the controller
237 now has ownership of the new one.
238 */
239 void AcquireScene(Scene2D* scene)
240 {
241 scene_.reset(scene);
242 }
243
244 /**
245 Sets the undo stack that is used by PushCommand, Undo...
246 */
247 void SetUndoStack(boost::weak_ptr<UndoStack> undoStackW)
248 {
249 undoStackW_ = undoStackW;
250 }
251
226 bool HasActiveTracker() const 252 bool HasActiveTracker() const
227 { 253 {
228 return activeTracker_.get() != NULL; 254 return activeTracker_.get() != NULL;
229 } 255 }
230 256
231 private: 257 private:
232 double GetCanvasToSceneFactor() const; 258 double GetCanvasToSceneFactor() const;
233 259
234 IViewport& viewport_; 260 boost::shared_ptr<IViewport> viewport_;
235 boost::weak_ptr<UndoStack> undoStackW_; // Global stack, possibly shared by all viewports 261 boost::weak_ptr<UndoStack> undoStackW_; // Global stack, possibly shared by all viewports
236 std::vector<boost::shared_ptr<MeasureTool> > measureTools_; 262 std::vector<boost::shared_ptr<MeasureTool> > measureTools_;
237 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_; // TODO - Couldn't this be a "std::unique_ptr"? 263 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_; // TODO - Couldn't this be a "std::unique_ptr"?
238 264
239 std::unique_ptr<Scene2D> scene_; 265 std::unique_ptr<Scene2D> scene_;