sprk_ops.h
1 // Copyright (c) Tech Soft 3D, Inc.
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
10 #ifndef SPRK_STD_OPERATORS_H
11 #define SPRK_STD_OPERATORS_H
12 #include "sprk.h"
13 
14 #include <list>
15 #include <stack>
16 #include <unordered_map>
17 
18 namespace std
19 {
20  template<>
21  struct hash<HPS::RGBColor>
22  {
23  size_t operator()(HPS::RGBColor const & x) const
24  {
25  return (
26  (51 + std::hash<float>()(x.red)) * 51 + std::hash<float>()(x.green) * 51 + std::hash<float>()(x.blue));
27  }
28  };
29 }
30 
31 #ifdef _MSC_VER
32 #ifndef STATIC_APP
33 # ifdef SPRK_OPS
34 # define SPRK_OPS_API __declspec (dllexport)
35 # else
36 # define SPRK_OPS_API __declspec (dllimport)
37 # endif
38 #endif
39 #else
40 # include <stddef.h>
41 # if defined(LINUX_SYSTEM) && defined(SPRK_OPS)
42 # ifndef STATIC_APP
43 # define SPRK_OPS_API __attribute__ ((visibility ("default")))
44 # endif
45 # endif
46 #endif
47 
48 #ifndef SPRK_OPS_API
49 # define SPRK_OPS_API
50 #endif
51 
52 
53 namespace HPS
54 {
55 
67 class SPRK_OPS_API PanOrbitZoomOperator : public Operator
68 {
69 public:
70  PanOrbitZoomOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
72  virtual HPS::UTF8 GetName() const { return "HPS_PanOrbitZoomOperator"; }
73 
78  virtual bool OnMouseDown(MouseState const & in_state);
83  virtual bool OnMouseUp(MouseState const & in_state);
88  virtual bool OnMouseMove(MouseState const & in_state);
89 
94  virtual bool OnTouchDown(TouchState const & in_state);
99  virtual bool OnTouchUp(TouchState const & in_state);
104  virtual bool OnTouchMove(TouchState const & in_state);
105 
106 private:
107  HPS::WorldPoint start;
108 
109  HPS::WindowPoint start_point, new_point;
110  HPS::Vector start_sphere_pos, new_sphere_pos;
111 
112  bool operator_active;
113  float zoom_limit;
114  float focal_length;
115  HPS::WindowPoint last_zoom;
116  HPS::Vector last_relative;
117  float zoom_start_field_width;
118  float zoom_start_field_height;
119  HPS::Vector zoom_start_camera_look;
120  size_t current_touches;
121 
122  void ZoomStart();
123  void UpdateZoom(float zoom_factor);
124  void UpdateZoomLimit();
125  void UpdatePan(HPS::WorldPoint const & newLocation);
126  void UpdateRoll(HPS::Vector const & relative);
127 };
128 
136 class SPRK_OPS_API PanOperator : public Operator
137 {
138 public:
139  PanOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
141  virtual HPS::UTF8 GetName() const { return "HPS_PanOperator"; }
142 
147  virtual bool OnMouseDown(MouseState const & in_state);
152  virtual bool OnMouseUp(MouseState const & in_state);
157  virtual bool OnMouseMove(MouseState const & in_state);
158 
163  virtual bool OnTouchDown(TouchState const & in_state);
168  virtual bool OnTouchUp(TouchState const & in_state);
173  virtual bool OnTouchMove(TouchState const & in_state);
174 
175 private:
176  bool PanCommon(HPS::WindowPoint const & in_loc, HPS::KeyPath const & in_key_path);
177 
178  bool operator_active;
179  HPS::TouchID tracked_touch_ID;
180  HPS::WorldPoint start;
181 };
182 
190 class SPRK_OPS_API OrbitOperator : public Operator
191 {
192 public:
193  OrbitOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
195  virtual HPS::UTF8 GetName() const { return "HPS_OrbitOperator"; }
196 
201  virtual bool OnMouseDown(MouseState const & in_state);
206  virtual bool OnMouseUp(MouseState const & in_state);
211  virtual bool OnMouseMove(MouseState const & in_state);
212 
217  virtual bool OnTouchDown(TouchState const & in_state);
222  virtual bool OnTouchUp(TouchState const & in_state);
227  virtual bool OnTouchMove(TouchState const & in_state);
228 
229 private:
230  bool OrbitCommon(HPS::WindowPoint const & in_loc);
231 
232  bool operator_active;
233  HPS::TouchID tracked_touch_ID;
234  HPS::WindowPoint start_point, new_point;
235  HPS::Vector start_sphere_pos, new_sphere_pos;
236 };
237 
238 
239 class SPRK_OPS_API RelativeOrbitOperator : public Operator
240 {
241 
242 public:
249  RelativeOrbitOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonMiddle(), ModifierKeys in_modifier_trigger = ModifierKeys());
250  virtual HPS::UTF8 GetName() const { return "HPS_RelativeOrbitOperator"; }
251 
252  virtual bool OnMouseDown(MouseState const & in_state);
253  virtual bool OnMouseUp(MouseState const & in_state);
254  virtual bool OnMouseMove(MouseState const & in_state);
255 
256  virtual bool OnTouchDown(TouchState const & in_state);
257  virtual bool OnTouchUp(TouchState const & in_state);
258  virtual bool OnTouchMove(TouchState const & in_state);
259 
260 private:
261  bool OrbitCommon(HPS::WindowPoint const & in_loc);
262  bool RelativeOrbitCommon(HPS::WindowPoint const & in_loc, HPS::KeyPath & in_event_path);
263  void CalculateTarget(HPS::WindowKey const & in_window);
264 
265  HPS::Point faux_target;
266  bool operator_active;
267  HPS::TouchID tracked_touch_ID;
268  HPS::Vector start_sphere_pos, new_sphere_pos;
269  HPS::WindowPoint start_point, new_point;
270  HPS::SelectionOptionsKit selection_options;
271 };
272 
280 class SPRK_OPS_API ZoomOperator : public Operator
281 {
282 public:
283  ZoomOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
285  virtual HPS::UTF8 GetName() const { return "HPS_ZoomOperator"; }
286 
291  virtual bool OnMouseDown(MouseState const & in_state);
296  virtual bool OnMouseUp(MouseState const & in_state);
301  virtual bool OnMouseMove(MouseState const & in_state);
302 
307  virtual bool OnTouchDown(TouchState const & in_state);
312  virtual bool OnTouchMove(TouchState const & in_state);
313 
314 private:
315  bool operator_active;
316  HPS::TouchID tracked_touch_ID;
317  HPS::WindowPoint start_point;
318  float zoom_limit;
319  float focal_length;
320  HPS::WindowPoint last_zoom;
321  HPS::Vector last_relative;
322  float zoom_start_field_width;
323  float zoom_start_field_height;
324  HPS::Vector zoom_start_camera_look;
325  HPS::Point zoom_start_camera_target;
326 
327  void ZoomStart();
328  void UpdateZoom(float zoom_factor);
329  void UpdateZoomLimit();
330 };
331 
332 
333 class SPRK_OPS_API ConstructRectangleOperator : public Operator
334 {
335 public:
336  ConstructRectangleOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys(), bool draw_faces = false);
337  virtual HPS::UTF8 GetName() const { return "HPS_ConstructRectangleOperator"; }
338 
339  virtual void OnViewAttached();
340 
341  virtual bool OnMouseDown(MouseState const & in_state);
342  virtual bool OnMouseUp(MouseState const & in_state);
343  virtual bool OnMouseMove(MouseState const & in_state);
344 
345  virtual bool OnTouchDown(TouchState const & in_state);
346  virtual bool OnTouchUp(TouchState const & in_state);
347  virtual bool OnTouchMove(TouchState const & in_state);
348 
349  bool IsRectangleValid() const { return is_rect_valid; }
350 
352  HPS::Rectangle GetRectangle() const { return rect; }
353 
354 private:
355  bool ConstructRectCommon(WindowPoint const & in_loc);
356  void SetupConstructionSegment();
357 
358  bool draw_faces;
359  bool use_center_marker;
360  bool is_rect_valid;
361  bool operator_active;
362  HPS::WindowPoint start_point;
363  HPS::SegmentKey scratch_seg;
364  HPS::Rectangle rect;
365  HPS::LineKey temp_line_key;
366  HPS::PolygonKey temp_polygon_key;
367  HPS::MarkerKey temp_marker_key;
368  HPS::TouchID tracked_touch_ID;
369 };
370 
371 class SPRK_OPS_API ZoomBoxOperator : public ConstructRectangleOperator
372 {
373 public:
374  ZoomBoxOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
375  virtual HPS::UTF8 GetName() const { return "HPS_ZoomBoxOperator"; }
376 
377  virtual bool OnMouseUp(MouseState const & in_state);
378  virtual bool OnTouchUp(TouchState const & in_state);
379 
380 private:
381  bool ZoomCommon(HPS::WindowKey const & in_window, HPS::KeyPath const & in_event_path);
382 
383 };
384 
395 {
396 public:
409  SelectAreaOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
410 
411  virtual HPS::UTF8 GetName() const { return "HPS_SelectAreaOperator"; }
412 
413  virtual void OnViewAttached();
414 
415  virtual bool OnMouseUp(MouseState const & in_state);
416  virtual bool OnTouchUp(TouchState const & in_state);
417 
422  HPS::SelectionResults GetActiveSelection() const;
423 
429  void SetSelectionOptions(HPS::SelectionOptionsKit const & in_options) { selection_options = in_options; }
430 
434  HPS::SelectionOptionsKit GetSelectionOptions() const { return selection_options; }
435 
436 private:
437  bool SelectCommon(HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers = HPS::ModifierKeys());
438 
439  HPS::SelectionResults active_selection;
440  HPS::SelectionOptionsKit selection_options;
441 };
442 
443 
444 class SPRK_OPS_API HighlightAreaOperator : public SelectAreaOperator
445 {
446 public:
453  HighlightAreaOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
454 
455  virtual HPS::UTF8 GetName() const { return "HPS_HighlightAreaOperator"; }
456 
457  virtual void OnViewAttached();
458 
459  virtual bool OnMouseUp(MouseState const & in_state);
460  virtual bool OnTouchUp(TouchState const & in_state);
461 
467  void SetHighlightOptions(HPS::HighlightOptionsKit const & in_options) { highlight_options = in_options; }
468 
472  HPS::HighlightOptionsKit GetHighlightOptions() const { return highlight_options; }
473 
474 private:
475  bool HighlightCommon(WindowKey & in_window, ModifierKeys in_modifiers);
476 
477  HPS::HighlightOptionsKit highlight_options;
478 
479 };
480 
481 
491 class SPRK_OPS_API SelectOperator : public Operator
492 {
493 public:
506  SelectOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
507 
508  virtual HPS::UTF8 GetName() const { return "HPS_SelectOperator"; }
509 
510  virtual bool OnMouseDown(MouseState const & in_state);
511  virtual bool OnTouchDown(TouchState const & in_state);
512 
517  HPS::SelectionResults GetActiveSelection() const;
518 
522  void SetSelectionOptions(HPS::SelectionOptionsKit const & in_options) { selection_options = in_options; }
523 
527  HPS::SelectionOptionsKit GetSelectionOptions() const { return selection_options; }
528 
529 private:
530  bool SelectCommon(HPS::Point const & in_loc, HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers = HPS::ModifierKeys());
531 
532  HPS::SelectionResults active_selection;
533  HPS::SelectionOptionsKit selection_options;
534 };
535 
536 
537 class SPRK_OPS_API HighlightOperator : public SelectOperator
538 {
539 public:
544  HighlightOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
545 
546  virtual HPS::UTF8 GetName() const { return "HPS_HighlightOperator"; }
547 
548  virtual bool OnMouseDown(MouseState const & in_state);
549  virtual bool OnTouchDown(TouchState const & in_state);
550 
554  void SetHighlightOptions(HPS::HighlightOptionsKit const & in_options) { highlight_options = in_options; }
555 
559  HPS::HighlightOptionsKit GetHighlightOptions() const { return highlight_options; }
560 
561 private:
562  bool HighlightCommon(HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers);
563 
564  HPS::HighlightOptionsKit highlight_options;
565 };
566 
567 class SPRK_OPS_API MouseWheelOperator : public Operator
568 {
569 public:
570  enum class ZoomType
571  {
572  Fast,
573  Accurate,
574  };
575 
580  MouseWheelOperator(ZoomType in_default_type = ZoomType::Accurate, HPS::ModifierKeys in_alternate_type_modifiers = HPS::ModifierKeys::KeyControl());
581 
582  virtual HPS::UTF8 GetName() const { return "HPS_MouseWheelOperator"; }
583 
585  void UpdateZoomLimit();
586 
587  virtual bool OnMouseWheel(HPS::MouseState const & in_state);
588 
589  virtual void OnModelAttached();
590 
591  virtual void OnViewAttached();
592 
593 private:
594  float zoom_limit;
595  ZoomType zoom_type;
596  HPS::ModifierKeys zoom_modifier;
597 };
598 
610 class SPRK_OPS_API TurntableOperator : public Operator
611 {
612 public:
613  TurntableOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
615  virtual HPS::UTF8 GetName() const { return "HPS_TurntableOperator"; }
616 
622  virtual bool OnMouseDown(MouseState const & in_state);
627  virtual bool OnMouseUp(MouseState const & in_state);
632  virtual bool OnMouseMove(MouseState const & in_state);
637  virtual bool OnMouseWheel(MouseState const & in_state);
638 
644  virtual bool OnTouchDown(TouchState const & in_state);
649  virtual bool OnTouchUp(TouchState const & in_state);
655  virtual bool OnTouchMove(TouchState const & in_state);
656 
657 private:
658  void TurntableCommon(HPS::WindowPoint const & delta, HPS::Vector const & rotation_axis);
659  void CalculateCenterPoint(HPS::WindowKey const & window, HPS::Point const & location);
660 
661  bool operator_active;
662  bool center_point_set;
663  HPS::WorldPoint center_point;
664  HPS::TouchID tracked_touch_ID;
665  HPS::WindowPoint start_point;
666  HPS::SelectionOptionsKit selection_options;
667 };
668 
674 class SPRK_OPS_API ZoomFitTouchOperator : public Operator
675 {
676 public:
679  virtual HPS::UTF8 GetName() const { return "HPS_ZoomFitTouchOperator"; }
680 
685  virtual bool OnTouchDown(TouchState const & in_state);
690  virtual bool OnTouchUp(TouchState const & in_state);
691 
692 private:
693  HPS::TouchID tracked_touch_ID;
694 };
695 
718 class SPRK_OPS_API FlyOperator : public Operator
719 {
720 public:
721  FlyOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
723  virtual HPS::UTF8 GetName() const { return "HPS_FlyOperator"; }
724 
739  virtual bool OnKeyDown(KeyboardState const & in_state);
743  virtual bool OnKeyUp(KeyboardState const & in_state);
744 
749  virtual bool OnMouseDown(MouseState const & in_state);
753  virtual bool OnMouseUp(MouseState const & in_state);
758  virtual bool OnMouseMove(MouseState const & in_state);
764  virtual bool OnMouseWheel(MouseState const & in_state);
765 
770  virtual bool OnTouchDown(TouchState const & in_state);
774  virtual bool OnTouchUp(TouchState const & in_state);
779  virtual bool OnTouchMove(TouchState const & in_state);
780 
785  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
786 
787  virtual void OnModelAttached();
788  virtual void OnViewAttached();
789  virtual void OnViewDetached();
790 
791  /* getters/setters for inverting the X and Y axis */
792  void InvertXAxis() { invert_x_axis = !invert_x_axis;}
793  void InvertYAxis() { invert_y_axis = !invert_y_axis;}
794  bool IsXAxisInverted() { return invert_x_axis; }
795  bool IsYAxisInverted() { return invert_y_axis; }
796 
797  /* getters/setters for sensitivity */
798  /* Keyboard sensitivity affects the speed of movement of action triggered from the keyboard, such as walking forward by pressing W */
799  float GetKeyboardSensitivity() { return keyboard_sensitivity; }
800  void SetKeyboardSensitivity(float in_keyboard_sensitivity) { keyboard_sensitivity = in_keyboard_sensitivity; }
801 
802  /* Mouse sensitivity affects the speed of movement of action triggered from the mouse, such as rotating */
803  float GetMouseSensitivity() { return mouse_sensitivity; }
804  void SetMouseSensitivity(float in_mouse_sensitivity) { mouse_sensitivity = in_mouse_sensitivity; }
805 
806  /* Left Joystick sensitivity affects the speed of movement of action triggered from the left joystick on touch devices */
807  float GetLeftJoystickSensitivity() { return left_joystick_sensitivity; }
808  void SetLeftJoystickSensitivity(float in_left_joystick_sensitivity) { left_joystick_sensitivity = in_left_joystick_sensitivity; }
809 
810  /* Right Joystick sensitivity affects the speed of movement of action triggered from the right joystick on touch devices */
811  float GetRightJoystickSensitivity() { return right_joystick_sensitivity; }
812  void SetRightJoystickSensitivity(float in_right_joystick_sensitivity) { right_joystick_sensitivity = in_right_joystick_sensitivity; }
813 
814  /* getters/setters for joystick dead zone
815  The dead zone is an area around the initial touch down position where the user can move its finger
816  without triggering any movement.
817  The default value is 0.07. */
818  float GetJoystickDeadZone() { return joystick_dead_zone; }
819  void SetJoystickDeadZone(float in_dead_zone) { joystick_dead_zone = in_dead_zone; }
820 
821 protected:
822 
823  enum MovementFlags
824  {
825  no_movement = 0x0000,
826  moving_forward = 0x0001,
827  moving_back = 0x0002,
828  moving_left = 0x0004,
829  moving_right = 0x0008,
830  moving_up = 0x0010,
831  moving_down = 0x0020,
832  roll_left = 0x0040,
833  roll_right = 0x0080,
834  rotating = 0x0100,
835  move_with_touch = 0x0200,
836  rotate_with_touch = 0x0400
837  };
838 
839  unsigned int movement_flags;
840 
841  //movement functions
842  void MoveLeft(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
843  void MoveRight(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
844  void MoveUp(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
845  void MoveDown(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
846  void MoveForward(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
847  void MoveBack(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
848  void MoveWithTouch(HPS::Point & position, HPS::Point & target, HPS::Vector & up, HPS::Vector const & walking_direction);
849  void RotateScene(HPS::Point & position, HPS::Point & target);
850  void RotateWithTouch(HPS::Point & position, HPS::Point & target);
851  void RotateCommon(HPS::Point const & delta, HPS::Point & position, HPS::Point & target);
852 
853 private:
854 
855  enum class TouchPosition
856  {
857  Left,
858  Right,
859  None
860  };
861 
862  //touch IDs tracked by the operator
863  HPS::TouchID left_side_touch;
864  HPS::TouchID right_side_touch;
865  HPS::TouchID second_right_touch;
866 
867  //current and start location for touch operations
868  HPS::WindowPoint start_point;
869  HPS::WindowPoint left_start_point;
870  HPS::WindowPoint right_start_point;
871  HPS::WindowPoint current_right_touch_position;
872  HPS::WindowPoint second_right_start_point;
873  HPS::WindowPoint current_second_right_touch_position;
874  HPS::WindowPoint start_mid_point;
875 
876  //virtual joystick information
877  HPS::SegmentKey left_joystick_segment;
878  HPS::SegmentKey right_joystick_segment;
879  float joystick_dead_zone;
880 
881  //step length for left touch, right touch, and desktop operation
882  float keyboard_sensitivity;
883  float old_keyboard_sensitivity;
884  float left_joystick_sensitivity;
885  float old_left_joystick_sensitivity;
886  float right_joystick_sensitivity;
887  float old_right_joystick_sensitivity;
888  float mouse_sensitivity;
889 
890  //operator state flags
891  bool two_right_fingers_down;
892  bool invert_x_axis;
893  bool invert_y_axis;
894  Drawing::Handedness world_handedness;
895  bool shift_pressed;
896  bool ctrl_pressed;
897  HPS::KeyPath event_path;
898  HPS::WindowPoint rotation_location;
899  HPS::WindowPoint moving_position;
900 
901  //utility functions
902  void UpdateKeyboardState(KeyboardState const & in_state);
903  void ComputeReasonableStepLength();
904  void CreateJoystick(HPS::TouchState const & in_state, TouchPosition touch_position);
905 };
906 
942 class SPRK_OPS_API WalkOperator : public FlyOperator
943 {
944 public:
945  WalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
946 
948  virtual HPS::UTF8 GetName() const { return "HPS_WalkOperator"; }
949 
950  virtual void OnViewAttached();
951  virtual void OnModelAttached();
952 
957  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
958 
959  /* Getters / Setters for the plane the operator walks on. */
960  void SetGroundPlane(HPS::Plane const & in_plane) { ground = in_plane; }
961  HPS::Plane GetGroundPlane() { return ground; }
962 
963  /* Getters / Setters for camera vertical offset from the ground plane */
964  void SetWalkerHeight(float height) { height_off_ground = height; }
965  float GetWalkerHeight() { return height_off_ground; }
966 
967 private:
968  HPS::Plane ground;
969  HPS::Vector walking_direction;
970  float height_off_ground;
971 
972  void CalculateGroundPlane();
973  void SnapToPlane();
974  void AdjustWalkingDirection(HPS::Vector const & camera_direction, HPS::Vector const & camera_up);
975 };
976 
986 class SPRK_OPS_API SimpleWalkOperator : public WalkOperator
987 {
988 public:
989  SimpleWalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
990 
992  virtual HPS::UTF8 GetName() const { return "HPS_SimpleWalkOperator"; }
993 
997  virtual bool OnKeyDown(KeyboardState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1001  virtual bool OnKeyUp(KeyboardState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1006  virtual bool OnMouseWheel(MouseState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1007 
1012  virtual bool OnMouseDown(MouseState const & in_state);
1017  virtual bool OnMouseMove(MouseState const & in_state);
1021  virtual bool OnMouseUp(MouseState const & in_state);
1022 
1027  virtual bool OnTouchDown(TouchState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1032  virtual bool OnTouchMove(TouchState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1036  virtual bool OnTouchUp(TouchState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1037 
1042  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
1043 
1044 private:
1045  void MoveWithMouse(HPS::Point & position, HPS::Point & target);
1046 
1047  HPS::KeyPath event_path;
1048  HPS::WindowPoint rotation_location;
1049  HPS::WindowPoint start_point;
1050  bool moving;
1051 };
1052 
1053 
1111 class SPRK_OPS_API CuttingSectionOperator : public SelectOperator
1112 {
1113 private:
1114  enum class OpState
1115  {
1116  Uninitialized,
1117  Initialized,
1118  Translating,
1119  FacePicking,
1120  };
1121 
1122 public:
1123  CuttingSectionOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1124 
1126  virtual HPS::UTF8 GetName() const { return "HPS_CuttingSectionOperator"; }
1127 
1128  virtual void OnModelAttached();
1129  virtual void OnViewAttached();
1130  virtual void OnViewDetached();
1131 
1132  /* This function programmatically assigns cutting planes to this operator from plane equations.
1133  * If this operator has already had cutting planes associated with it, the cutting planes set using
1134  * this function replace the previous cutting planes.
1135  * \param in_planes An array of Plane objects describing the cutting planes to be inserted. */
1136  void SetPlanes(PlaneArray const & in_planes);
1137 
1138  /* This function returns the planes associated with the active cutting sections
1139  * \return planes associated with the active cutting sections. */
1140  PlaneArray GetPlanes();
1141 
1147  virtual bool OnMouseDown(MouseState const & in_state);
1148 
1152  virtual bool OnMouseUp(MouseState const & in_state);
1153 
1159  virtual bool OnMouseMove(MouseState const & in_state);
1160 
1166  virtual bool OnTouchDown(TouchState const & in_state);
1167 
1171  virtual bool OnTouchUp(TouchState const & in_state);
1172 
1177  virtual bool OnTouchMove(TouchState const & in_state);
1178 
1183  virtual bool OnTimerTick(TimerTickEvent const & in_event);
1184 
1187  float GetIndicatorScale() const { return indicator_scale; }
1188 
1191  void SetIndicatorScale(float in_scale) { indicator_scale = in_scale; }
1192 
1195  MaterialMappingKit GetPlaneMaterial() const { return plane_material; }
1196 
1199  void SetPlaneMaterial(MaterialMappingKit const & in_plane_material);
1200 
1203  HighlightOptionsKit GetPlaneHighlightOptions() const { return highlight_options; }
1204 
1207  void SetPlaneHighlightOptions(HighlightOptionsKit const & in_highlight_options) { highlight_options = in_highlight_options; }
1208 
1211  bool GetMouseOverHighlighting() const { return enable_mouse_over_highlighting; }
1212 
1215  void SetMouseOverHighlighting(bool in_enable_mouse_over_highlighting) { enable_mouse_over_highlighting = in_enable_mouse_over_highlighting; }
1216 
1220  void SetSectioning(bool in_sectioning);
1221 
1224  bool GetSectioning() { return sectioning; }
1225 
1229  void SetIndicatorVisibility(bool in_use_indicator);
1230 
1233  bool GetIndicatorVisibility() { return (op_state == OpState::Uninitialized || op_state == OpState::FacePicking) ? true : false; }
1234 
1238  void SetPlaneVisibility(bool in_visibility);
1239 
1242  bool GetPlaneVisibility();
1243 
1244 private:
1245 
1246  void SetupOperatorSegment();
1247  void InsertNormalIndicator(float scale);
1248  ShellKey InsertCuttingPlaneGeometry();
1249  void MouseOverHighlighting(MouseState const & in_state);
1250  void TranslateCuttingPlane(KeyPath const & in_event_path, WindowPoint const & in_event_location);
1251  bool HandleMouseAndTouchDown(WindowKey const & in_event_source, int in_number_of_clicks,
1252  KeyPath const & in_event_path, WindowPoint const & in_event_location);
1253  void ViewAlignSectionPlanes(HPS::PlaneArray & in_out_planes) const;
1254  typedef std::pair<CuttingSectionKey, std::vector<ShellKey>> SectionInfo;
1255  typedef std::vector<SectionInfo> SectionArray;
1256  SectionArray sections;
1257 
1258  SegmentKey operator_root_segment;
1259  SegmentKey cutting_sections_segment;
1260  SegmentKey plane_representation_segment;
1261  bool sectioning;
1262 
1263  CuttingSectionKey translating_section;
1264  size_t translating_plane_offset;
1265  ShellKey translating_plane_representation;
1266 
1267  TouchID tracked_touch_ID;
1268  MaterialMappingKit plane_material;
1269  SegmentKey indicator_seg;
1270  OpState op_state;
1271  WorldPoint start_world_point;
1272  SelectionOptionsKit selection_options;
1273  SelectionOptionsKit mouse_over_selection_options;
1274  float indicator_scale;
1275  Vector plane_normal;
1276  bool plane_normal_valid;
1277  WorldPoint anchor_point;
1278  SimpleCuboid model_bounding;
1279 
1280  UpdateNotifier last_highlight_notifier;
1281  bool last_skipped_highlight_state_valid;
1282  MouseState last_skipped_highlight_state;
1283  bool is_plane_highlighted;
1284  PortfolioKey portfolio;
1285  SegmentKey style_segment;
1286  HighlightOptionsKit highlight_options;
1287  bool enable_mouse_over_highlighting;
1288  bool skip_mouse_overs;
1289 
1290  View attached_view;
1291  KeyArray navigation_keys;
1292 };
1293 
1329 class SPRK_OPS_API MarkupOperator : public Operator
1330 {
1331 public:
1332  enum class MarkupType
1333  {
1334  Freehand,
1335  Text,
1336  Circle,
1337  Rectangle,
1338  };
1339 
1340  MarkupOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1341 
1343  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_MarkupOperator"; }
1344 
1345  virtual void OnViewAttached() OVERRIDE;
1346  virtual void OnViewDetached() OVERRIDE;
1347 
1352  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1353 
1357  virtual bool OnMouseUp(MouseState const & in_state) OVERRIDE;
1358 
1365  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1366 
1367 
1372  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1373 
1377  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
1378 
1385  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
1386 
1392  virtual bool OnKeyDown(KeyboardState const & in_state) OVERRIDE;
1393 
1399  virtual bool OnTextInput(HPS::UTF8 const & in_text) OVERRIDE;
1400 
1402  MarkupType GetMarkupType() { return markup_type; }
1403 
1405  void SetMarkupType(MarkupType in_markup_type) { markup_type = in_markup_type; }
1406 
1409  RGBColor GetColor() { return current_attributes.color; }
1410 
1412  void SetColor(RGBColor const & in_color) { current_attributes.color = in_color; }
1413 
1416  TextAttributeKit GetTextAttributes() { return current_attributes.text_attributes; }
1417 
1419  void SetTextAttribute(TextAttributeKit const & in_text_attributes) { current_attributes.text_attributes = in_text_attributes; }
1420 
1423  LineAttributeKit GetLineAttributes() { return current_attributes.line_attributes; }
1424 
1426  void SetLineAttribute(LineAttributeKit const & in_line_attributes) {current_attributes.line_attributes = in_line_attributes; }
1427 
1431  SegmentKey GetSegmentKey() { return markup_segment; }
1432 
1434  void DeleteMarkups();
1435 
1436  /* Whether a markup is currently being inserted.
1437  * \return <span class='code'>true</span> if a markup is being inserted, <span class='code'>false</span> otherwise. */
1438  bool IsMarkupActive() { return operator_active; }
1439 
1440  class SPRK_OPS_API MarkupInsertedEvent : public HPS::Event
1441  {
1442  public:
1445  {
1446  channel = GetClassID();
1447  consumable = false;
1448  }
1449 
1450  MarkupInsertedEvent(HPS::Key const & in_markup_key, HPS::View const & in_view) : Event()
1451  {
1452  channel = GetClassID();
1453  consumable = false;
1454  markup_key = in_markup_key;
1455  view = in_view;
1456  }
1457 
1460  MarkupInsertedEvent(Event const & in_event) : Event(in_event)
1461  {
1462  if (in_event.GetChannel() == Object::ClassID<MarkupInsertedEvent>())
1463  {
1464  auto that = static_cast<MarkupInsertedEvent const &>(in_event);
1465  markup_key = that.markup_key;
1466  view = that.view;
1467  }
1468  else
1469  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1470  }
1471 
1473 
1476  Event * Clone() const
1477  {
1478  MarkupInsertedEvent * new_event = new MarkupInsertedEvent(*this);
1479  return new_event;
1480  }
1481 
1482  Key markup_key;
1483  View view;
1484  };
1485 
1486 private:
1487  struct Attributes
1488  {
1489  RGBColor color;
1490  LineAttributeKit line_attributes;
1491  TextAttributeKit text_attributes;
1492  };
1493 
1494  class KeyboardHiddenEventHandler : public EventHandler
1495  {
1496  public:
1497  KeyboardHiddenEventHandler()
1498  : EventHandler()
1499  { }
1500 
1501  virtual ~KeyboardHiddenEventHandler()
1502  { Shutdown(); }
1503 
1504  virtual HandleResult Handle(Event const * /*in_event*/)
1505  {
1506  markup_operator->keyboard_active = false;
1507 
1508  markup_operator->ResetCameras();
1509  return HandleResult::Handled;
1510  }
1511 
1512  void SetOperator(MarkupOperator * in_operator) { markup_operator = in_operator; }
1513 
1514  private:
1515  MarkupOperator * markup_operator;
1516  };
1517 
1518  std::unordered_multimap<RGBColor, SegmentKey> attribute_map;
1519 
1520  MouseButtons mouse_trigger;
1521  ModifierKeys modifier_trigger;
1522 
1523  MarkupType markup_type;
1524  SegmentKey markup_segment;
1525  SegmentKey current_segment;
1526  Attributes current_attributes;
1527 
1528  static const RGBColor default_color;
1529  static const TextAttributeKit default_text_attributes;
1530  static const LineAttributeKit default_line_attributes;
1531 
1532  Point start_point;
1533  bool start_new_line;
1534  LineKey current_line;
1535  size_t current_line_size;
1536  CircleKey current_circle;
1537  LineKey current_circle_line;
1538  LineKey current_rectangle;
1539  View last_attached_view;
1540 
1541  bool start_new_note;
1542  bool keyboard_active;
1543  TextKey default_text;
1544  TextKey current_text;
1545  SizeTArray text_columns;
1546  size_t current_text_row;
1547 
1548  bool operator_active;
1549  TouchID tracked_touch_id;
1550  TouchID second_tracked_touch_id;
1551 
1552  CameraKit original_camera;
1553  CameraKit original_markup_camera;
1554 
1555  KeyboardHiddenEventHandler handler;
1556 
1557  bool SetupConstructionSegments();
1558  void LookupSegment();
1559  void CreateNewMarkupSegment();
1560  void DrawFreehand(Point const & location);
1561  void DrawText();
1562  void DrawCircle(Point const & location);
1563  void DrawCircleFromTwoPoints(Point const & point_one, Point const & point_two);
1564  void DrawRectangleFromTwoPoints(Point const & point_one, Point const & point_two);
1565  void DrawRectangle(Point const & location);
1566  void CenterCameras(Point const & main_camera_center, Point const & markup_camera_center);
1567  void ResetCameras();
1568  void EndTextNote();
1569 };
1570 
1588 class SPRK_OPS_API AnnotationOperator : public Operator
1589 {
1590 public:
1591  AnnotationOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1592 
1594  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_AnnotationOperator"; }
1595 
1596  virtual void OnViewAttached() OVERRIDE;
1597  virtual void OnViewDetached() OVERRIDE;
1598 
1606  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1607 
1613  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1614 
1615 
1623  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1624 
1628  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
1629 
1634  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
1635 
1636 
1641  virtual bool OnKeyDown(KeyboardState const & in_state) OVERRIDE;
1642 
1647  virtual bool OnTextInput(HPS::UTF8 const & in_text) OVERRIDE;
1648 
1656  void SetBackgroundShape(const char * in_shape);
1657 
1661  UTF8 GetBackgroundShape() const;
1662 
1663  /* An event injected every time a new annotation is inserted.
1664  * It contains the key of the segment containing the annotation and the view currently attached to this operator.
1665  * This operator places each annotation in a separate segment. */
1666  class SPRK_OPS_API AnnotationInsertedEvent : public HPS::Event
1667  {
1668  public:
1671  {
1672  channel = GetClassID();
1673  consumable = false;
1674  }
1675 
1676  AnnotationInsertedEvent(HPS::SegmentKey const & in_text_key, HPS::View const & in_view) : Event()
1677  {
1678  channel = GetClassID();
1679  consumable = false;
1680  text_key = in_text_key;
1681  view = in_view;
1682  }
1683 
1686  AnnotationInsertedEvent(Event const & in_event) : Event(in_event)
1687  {
1688  if (in_event.GetChannel() == Object::ClassID<AnnotationInsertedEvent>())
1689  {
1690  auto that = static_cast<AnnotationInsertedEvent const &>(in_event);
1691  text_key = that.text_key;
1692  view = that.view;
1693  }
1694  else
1695  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1696  }
1697 
1699 
1702  Event * Clone() const
1703  {
1704  AnnotationInsertedEvent * new_event = new AnnotationInsertedEvent(*this);
1705  return new_event;
1706  }
1707 
1708  SegmentKey text_key; //the key of the segment containing the annotation
1709  View view;
1710  };
1711 
1712 private:
1713  void AddAnnotationUserData();
1714  void StartNewNote();
1715 
1716  bool InputDown(WindowKey const & window_key, Point const & location, KeyPath & event_path);
1717  bool InputMove(Point const & location, KeyPath & event_path);
1718 
1719  void CenterCamera(Point const & camera_center);
1720  void ResetCamera();
1721 
1722  class KeyboardHiddenEventHandler : public EventHandler
1723  {
1724  public:
1725  KeyboardHiddenEventHandler()
1726  : EventHandler()
1727  { }
1728 
1729  virtual ~KeyboardHiddenEventHandler()
1730  { Shutdown(); }
1731 
1732  virtual HandleResult Handle(Event const * /*in_event*/)
1733  {
1734  annotation_operator->keyboard_active = false;
1735 
1736  annotation_operator->ResetCamera();
1737  return HandleResult::Handled;
1738  }
1739 
1740  void SetOperator(AnnotationOperator * in_operator) { annotation_operator = in_operator; }
1741 
1742  private:
1743  AnnotationOperator * annotation_operator;
1744  };
1745 
1746 
1747  SegmentKey annotation_segment; //segment containing all annotations
1748  View last_attached_view; //the last view that was attached to this operator
1749  SelectionOptionsKit selection_options; //selection options used to select geometry
1750  SelectionOptionsKit annotation_selection_options; //selection options used when trying to select annotations
1751  bool editing_text; //whether we are in a state which allows editing of an annotation
1752  bool start_new_note; //whether we should delete the text of an annotation when typing
1753  UTF8 annotation_user_data; //the user data set on annotation geometry to distinguish it from non annotation geometry
1754  UTF8 annotation_shape; //the name of the shape definition used to draw the annotation background
1755 
1756  PortfolioKey current_portfolio; //the portfolio used to store the default definitions used by this operator
1757  SegmentKey highlight_style_segment; //the highlight background style
1758 
1759  RGBColor background_color; //the color of the annotation background
1760  RGBColor leader_line_color; //the color of the annotation leader line and edges
1761  RGBColor highlight_color; //the color the annotation becomes while it is being edited
1762 
1763  TextKey text_to_edit; //the annotation text which we are working on
1764  SizeTArray text_columns; //the number of columns of the text for the current annotation
1765  size_t current_text_row; //the number of rows of the text for the current annotation
1766 
1767  //touch only flags -- these flags are only relevant when running the operator on a touch enabled device
1768  TouchID tracked_touch_id; //the ID of the touch we are tracking
1769  bool keyboard_active; //whether the software keyboard is visible
1770  CameraKit original_camera; //the camera setting as they were just before the annotation text is edited
1771  KeyboardHiddenEventHandler handler; //a handler that takes care of resetting the camera when the software keyboard is hidden
1772  Point touch_down_position; //the position the last touch down occurred at
1773  bool always_show_keyboard_on_touch_up; //true if we are just inserting the annotation, false if we are editing a previously inserted one.
1774 };
1775 
1793 class SPRK_OPS_API HandlesOperator : public Operator
1794 {
1795 public:
1796  HandlesOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1797 
1799  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_HandlesOperator"; }
1800 
1801  virtual void OnViewAttached() OVERRIDE;
1802  virtual void OnViewDetached() OVERRIDE;
1803 
1810  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1811 
1816  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1817 
1821  virtual bool OnMouseUp(MouseState const & in_state) OVERRIDE;
1822 
1829  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1830 
1835  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
1836 
1840  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
1841 
1852  void SetHandlesColors(MaterialKitArray const & in_colors) { handles_colors = in_colors; }
1853 
1854  /* This function returns the materials used to color the handles.
1855  * Only the diffuse color field of the materials is guaranteed to have a value.
1856  * The materials are used as follows:
1857  *
1858  * Entry 0 - translation handle in the x direction
1859  * Entry 1 - translation handle in the y direction
1860  * Entry 2 - translation handle in the z direction
1861  * Entry 3 - rotation handle in the x direction
1862  * Entry 4 - rotation handle in the y direction
1863  * \return An array of materials associated with the handles */
1864  MaterialKitArray GetHandlesColors() const { return handles_colors; }
1865 
1866  /* Sets the highlight color used when the user mouses over the handles.
1867  * The default value for the highlight color is RGBAColor(1.0f, 0.55f, 0.0f)
1868  * \param in_highlight_color The color used to highlight handles when the user mouses over them. */
1869  void SetHighlightColor(RGBAColor const & in_highlight_color);
1870 
1871  /* Returns the color used to highlight the handles then the user mouses over them.
1872  * \return the color used to highlight the handles then the user mouses over them. */
1873  RGBAColor GetHighlightColor() const { return highlight_color; }
1874 
1875  /* This function can be used by the user to modify the appearance of the handles.
1876  * If the user passes values outside of the acceptable ranges, these values will be ignored and a warning will be issued for each out-of-range value.
1877  * Changes will take effect the next time handles are inserted.
1878  * \param in_length The length of the handles, specified as a percentage of the view containing it. Valid range is (0, 1].
1879  * \param in_radius The radius of the handles, specified as a percentage of the view containing it. Valid range is (0, 1].
1880  * \param in_offset The distance between the end of a translation handle and the rotation handle associated with it, specified as a percentage of the handle length. Valid range is (0, 1].
1881  * \param in_angle The angle formed by the rotation handles, specified in degrees. Valid range is > 0
1882  * \param in_handles_points The number of points used to draw the handles. A higher number will yield a smoother appearance. Valid range is > 0
1883  * \param in_tip_size The size of the tip at the end of the handles, specified as a percentage of the handle. Valid range is [0, 1] */
1884  void SetHandlesAppearance(float in_length = 0.2f, float in_radius = 0.005f, float in_offset = 0.2f, float in_angle = 25.0f, size_t in_handles_points = 30, float in_tip_size = 0.15f);
1885 
1886  /* Returns the parameters used to decide the appearance of the handles.
1887  * \param out_length The length of the handles, specified as a percentage of the view containing it.
1888  * \param out_radius The radius of the handles, specified as a percentage of the view containing it.
1889  * \param out_offset The distance between the end of a translation handle and the rotation handle associated with it, specified as a percentage of the handle length.
1890  * \param out_angle The angle formed by the rotation handles, specified in degrees.
1891  * \param out_handle_points The number of points used to draw the handles. A higher number will yield a smoother appearance.
1892  * \param out_tip_size The size of the tip at the end of the handles, specified as a percentage of the handle. */
1893  void GetHandlesAppearance(float & out_length, float & out_radius, float & out_offset, float & out_angle, size_t & out_handles_points, float & out_tip_size) const;
1894 
1895  /* Whether to draw trailing geometry when using the handles.
1896  * Trailing geometry is geometry which shows you the path of the last movement operation you performed through the handles.
1897  * \param in_state Whether to draw trailing geometry when using the handles. */
1898  void SetTrailingGeometry(bool in_state) { display_trailing_geometry = in_state; }
1899 
1900  /* Whether trailing geometry will be drawn when using the handles.
1901  * Trailing geometry is geometry which shows you the path of the last movement operation you performed through the handles.
1902  * \return <span class='code'>true</span> if trailing geometry will be drawn, <span class='code'>false</span> otherwise. */
1903  bool GetTrailingGeometry() const { return display_trailing_geometry; }
1904 
1905  class SPRK_OPS_API GeometryTransformedEvent : public HPS::Event
1906  {
1907  public:
1910  {
1911  channel = GetClassID();
1912  consumable = false;
1913  }
1914 
1915  GeometryTransformedEvent(HPS::View const & in_view, HPS::SegmentKey const & in_segment_key, HPS::MatrixKit const & in_transform) : Event()
1916  {
1917  channel = GetClassID();
1918  consumable = false;
1919  view = in_view;
1920  segment_key = in_segment_key;
1921  transform = in_transform;
1922  }
1923 
1926  GeometryTransformedEvent(Event const & in_event) : Event(in_event)
1927  {
1928  if (in_event.GetChannel() == Object::ClassID<GeometryTransformedEvent>())
1929  {
1930  auto that = static_cast<GeometryTransformedEvent const &>(in_event);
1931  view = that.view;
1932  segment_key = that.segment_key;
1933  transform = that.transform;
1934  }
1935  else
1936  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1937  }
1938 
1940 
1943  Event * Clone() const
1944  {
1945  GeometryTransformedEvent * new_event = new GeometryTransformedEvent(*this);
1946  return new_event;
1947  }
1948 
1949  SegmentKey segment_key;
1950  MatrixKit transform;
1951  View view;
1952  };
1953 
1954 private:
1955  enum class Movement
1956  {
1957  None,
1958  Translation,
1959  Rotation,
1960  };
1961 
1962  CanvasArray canvases; //A list of Canvas objects that the View attached to this operator belongs to. This value only gets updated on OnViewAttached.
1963  View last_attached_view; //The last View to where this operator was pushed.
1964  TouchID tracked_touch_id;
1965 
1966  SegmentKey handles; //top level segment
1967  SegmentKey handles_segment; //segment where the matrices for the handles transformations are accumulated
1968  SegmentKey handles_geometry; //segment where the handles geometry lives
1969  SegmentKey reference_segment; //segment containing all the net attributes of segment_to_move
1970  SegmentKey segment_to_move; //segment containing geometry affected by the handles
1971  SegmentKey temporary_segment_to_move; //segment where we accumulate changes while the handles are active
1972  SegmentKey handles_trail; //segment containing the trailing geometry
1973  KeyPath path_to_segment_to_move;
1974 
1975  WorldPoint handles_origin_point;
1976  WorldPoint movement_start_point;
1977  Point input_down_position;
1978 
1979  Camera::Projection camera_projection;
1980 
1981  SelectionOptionsKit geometry_selection_options;
1982  SelectionOptionsKit handles_selection_options;
1983 
1984  HighlightOptionsKit hide_highlight_options;
1985  HighlightOptionsKit partial_transparency_options;
1986  HighlightOptionsKit highlight_options;
1987  SegmentKey style_segment;
1988  SegmentKey transparency_style_segment;
1989  UTF8 style_name;
1990  bool something_is_highlighted;
1991  MaterialKitArray handles_colors;
1992  RGBAColor highlight_color;
1993  Key highlighted_handle;
1994 
1995  //state flags
1996  bool are_handles_on;
1997  bool remove_handles;
1998  Movement move_geometry;
1999  Vector movement_direction;
2000  Vector base_vector;
2001 
2002  //handles appearance
2003  float handles_length; //Length of the handles. Expressed in percentage of screen [0 - 1]
2004  float handles_radius; //Radius of the handles. Expressed in percentage of screen [0 - 1]
2005  float arc_offset; //Distance between the end of the translation handle and the start of the translation arc. Expressed in percentage of handles_length [0 - 1].
2006  float arc_angle; //The angle formed by the arc handles. Must be greater than zero.
2007  size_t arc_points; //The number of points used to draw the arc handles.
2008  float tip_size; //The size of the tips at the end of the handles, specified as a percentage of the handles length
2009 
2010  //handle geometry
2011  CylinderKey x;
2012  CylinderKey y;
2013  CylinderKey z;
2014  CylinderKey arc_x;
2015  CylinderKey arc_y;
2016  CylinderKey arc_z;
2017 
2018  //trailing geometry
2019  bool display_trailing_geometry;
2020  Point trailing_line_start;
2021  Point trailing_circle_start;
2022  Point trailing_circle_center;
2023  Vector trailing_rotation;
2024  MarkerKey trail_marker;
2025  LineKey trailing_line;
2026  CircularArcKey trailing_circle;
2027  float rotation_direction;
2028 
2029  bool InputDown(size_t in_click_count, WindowKey const & in_window, Point const & in_location);
2030  bool InputMove(KeyPath const & in_path, Point const & in_location);
2031  void InputUp(Point const & in_location);
2032 
2033  void InsertHandles();
2034  void RemoveHandles();
2035  bool HighlightHandles(WindowKey & in_window, Point const & in_location);
2036 
2037  //moves the geometry affected by handles into a new segment, and hides the original
2038  void ReferenceGeometry(KeyPath const & in_path);
2039 
2040  //copies the accumulated transform from the reference geometry segment back into the original place.
2041  //removes the hide highlight from the original geometry
2042  void CommitChanges();
2043 };
2044 
2045 }
2046 #endif
2047 
2048 
Definition: hps.h:6171
Handedness
Definition: hps.h:1262
Event * Clone() const
Definition: sprk_ops.h:1702
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:508
MarkupInsertedEvent(Event const &in_event)
Definition: sprk_ops.h:1460
Definition: sprk.h:237
virtual bool OnMouseWheel(MouseState const &in_state)
Definition: sprk_ops.h:1006
bool GetSectioning()
Definition: sprk_ops.h:1224
An InvalidSpecificationException is thrown when a method is called with non-sensical or contradictory...
Definition: hps.h:5680
SegmentKey GetSegmentKey()
Definition: sprk_ops.h:1431
static MouseButtons ButtonRight()
Definition: hps.h:44260
Definition: sprk_ops.h:986
Definition: sprk_ops.h:280
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:195
Event * Clone() const
Definition: sprk_ops.h:1943
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1799
Definition: hps.h:35040
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:472
Definition: sprk_ops.h:394
HPS::SelectionOptionsKit GetSelectionOptions() const
Definition: sprk_ops.h:527
void SetMarkupType(MarkupType in_markup_type)
Definition: sprk_ops.h:1405
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:992
Definition: hps.h:44747
Definition: hps.h:7680
Definition: sprk_ops.h:67
AnnotationInsertedEvent()
Definition: sprk_ops.h:1670
Definition: hps.h:3506
ZoomType
Definition: sprk_ops.h:570
void SetIndicatorScale(float in_scale)
Definition: sprk_ops.h:1191
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:250
Definition: hps.h:15670
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:455
HPS::SelectionOptionsKit GetSelectionOptions() const
Definition: sprk_ops.h:434
Definition: sprk_ops.h:610
GeometryTransformedEvent(Event const &in_event)
Definition: sprk_ops.h:1926
virtual bool OnTouchDown(TouchState const &in_state)
Definition: sprk_ops.h:1027
void SetPlaneHighlightOptions(HighlightOptionsKit const &in_highlight_options)
Definition: sprk_ops.h:1207
Definition: sprk_ops.h:491
Definition: sprk_ops.h:190
TextAttributeKit GetTextAttributes()
Definition: sprk_ops.h:1416
GeometryTransformedEvent()
Definition: sprk_ops.h:1909
Definition: hps.h:1501
Definition: hps.h:8847
void SetLineAttribute(LineAttributeKit const &in_line_attributes)
Definition: sprk_ops.h:1426
Definition: sprk_ops.h:333
Definition: sprk_ops.h:1440
Definition: sprk_ops.h:674
virtual bool OnTouchMove(TouchState const &in_state)
Definition: sprk_ops.h:1032
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:522
Definition: sprk_ops.h:1111
Definition: sprk_ops.h:1793
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1594
Definition: hps.h:44646
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:337
Definition: sprk_ops.h:718
Definition: sprk_ops.h:444
Definition: hps.h:31458
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:411
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:582
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:948
Definition: sprk_ops.h:1329
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:141
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:679
AnnotationInsertedEvent(Event const &in_event)
Definition: sprk_ops.h:1686
bool GetIndicatorVisibility()
Definition: sprk_ops.h:1233
virtual bool OnTouchUp(TouchState const &in_state)
Definition: sprk_ops.h:1036
Definition: hps.h:4334
RGBColor GetColor()
Definition: sprk_ops.h:1409
Definition: hps.h:7053
Definition: hps.h:44138
Definition: hps.h:25665
Definition: hps.h:41683
Definition: hps.h:5875
Definition: hps.h:43191
Definition: hps.h:40980
Definition: hps.h:44534
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:375
Definition: sprk_ops.h:537
Definition: hps.h:15084
intptr_t GetChannel() const
Definition: hps.h:6304
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1126
Definition: hps.h:14356
Definition: hps.h:41960
Definition: hps.h:43803
bool GetMouseOverHighlighting() const
Definition: sprk_ops.h:1211
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:546
HPS::Rectangle GetRectangle() const
Definition: sprk_ops.h:352
Definition: hps.h:6271
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:429
Definition: hps.h:13390
virtual bool OnKeyDown(KeyboardState const &in_state)
Definition: sprk_ops.h:997
void SetMouseOverHighlighting(bool in_enable_mouse_over_highlighting)
Definition: sprk_ops.h:1215
Definition: sprk_ops.h:239
LineAttributeKit GetLineAttributes()
Definition: sprk_ops.h:1423
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:467
float GetIndicatorScale() const
Definition: sprk_ops.h:1187
Definition: sprk_ops.h:1588
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:559
Definition: hps.h:43117
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:285
Definition: sprk_ops.h:567
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:615
Definition: sprk_ops.h:942
static MouseButtons ButtonLeft()
Definition: hps.h:44256
static MouseButtons ButtonMiddle()
Definition: hps.h:44264
Definition: hps.h:8965
static ModifierKeys KeyControl()
Definition: hps.h:43918
MaterialMappingKit GetPlaneMaterial() const
Definition: sprk_ops.h:1195
Definition: hps.h:7599
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:72
Definition: hps.h:9179
void SetTextAttribute(TextAttributeKit const &in_text_attributes)
Definition: sprk_ops.h:1419
Definition: hps.h:23017
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:723
Definition: hps.h:23302
Event * Clone() const
Definition: sprk_ops.h:1476
void SetColor(RGBColor const &in_color)
Definition: sprk_ops.h:1412
Definition: sprk.h:1065
Definition: sprk_ops.h:136
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1343
virtual bool OnKeyUp(KeyboardState const &in_state)
Definition: sprk_ops.h:1001
HighlightOptionsKit GetPlaneHighlightOptions() const
Definition: sprk_ops.h:1203
Definition: hps.h:38548
MarkupInsertedEvent()
Definition: sprk_ops.h:1444
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:554
Definition: sprk_ops.h:371
Projection
Definition: hps.h:1387