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, HPS::CameraKit & out_camera);
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 
789  virtual void OnModelAttached();
790 
792  virtual void OnViewAttached();
793 
795  virtual void OnViewDetached();
796 
797  /* getters/setters for inverting the X and Y axis */
798  void InvertXAxis() { invert_x_axis = !invert_x_axis;}
799  void InvertYAxis() { invert_y_axis = !invert_y_axis;}
800  bool IsXAxisInverted() const { return invert_x_axis; }
801  bool IsYAxisInverted() const { return invert_y_axis; }
802 
803  /* getters/setters for sensitivity */
804  /* Keyboard sensitivity affects the speed of movement of action triggered from the keyboard, such as walking forward by pressing W */
805  float GetKeyboardSensitivity() const { return keyboard_sensitivity; }
806  void SetKeyboardSensitivity(float in_keyboard_sensitivity) { keyboard_sensitivity = in_keyboard_sensitivity; }
807 
808  /* Mouse sensitivity affects the speed of movement of action triggered from the mouse, such as rotating */
809  float GetMouseSensitivity() const { return mouse_sensitivity; }
810  void SetMouseSensitivity(float in_mouse_sensitivity) { mouse_sensitivity = in_mouse_sensitivity; }
811 
812  /* Left Joystick sensitivity affects the speed of movement of action triggered from the left joystick on touch devices */
813  float GetLeftJoystickSensitivity() const { return left_joystick_sensitivity; }
814  void SetLeftJoystickSensitivity(float in_left_joystick_sensitivity) { left_joystick_sensitivity = in_left_joystick_sensitivity; }
815 
816  /* Right Joystick sensitivity affects the speed of movement of action triggered from the right joystick on touch devices */
817  float GetRightJoystickSensitivity() const { return right_joystick_sensitivity; }
818  void SetRightJoystickSensitivity(float in_right_joystick_sensitivity) { right_joystick_sensitivity = in_right_joystick_sensitivity; }
819 
820  /* getters/setters for joystick dead zone
821  The dead zone is an area around the initial touch down position where the user can move its finger
822  without triggering any movement.
823  The default value is 0.07. */
824  float GetJoystickDeadZone() const { return joystick_dead_zone; }
825  void SetJoystickDeadZone(float in_dead_zone) { joystick_dead_zone = in_dead_zone; }
826 
827  float GetSceneExtents() const { return scene_extents; }
828 
829 protected:
830 
831  enum MovementFlags
832  {
833  no_movement = 0x0000,
834  moving_forward = 0x0001,
835  moving_back = 0x0002,
836  moving_left = 0x0004,
837  moving_right = 0x0008,
838  moving_up = 0x0010,
839  moving_down = 0x0020,
840  roll_left = 0x0040,
841  roll_right = 0x0080,
842  rotating = 0x0100,
843  move_with_touch = 0x0200,
844  rotate_with_touch = 0x0400
845  };
846 
847  unsigned int movement_flags;
848 
849  //movement functions
850  void MoveLeft(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
851  void MoveRight(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
852  void MoveUp(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
853  void MoveDown(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
854  void MoveForward(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
855  void MoveBack(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
856  bool MoveWithTouch(HPS::Point & position, HPS::Point & target, HPS::Vector & up, HPS::Vector const & walking_direction);
857  bool RotateScene(HPS::Point & position, HPS::Point & target);
858  bool RotateWithTouch(HPS::Point & position, HPS::Point & target);
859  void RotateCommon(HPS::Point const & delta, HPS::Point & position, HPS::Point & target);
860 
861 private:
862 
863  enum class TouchPosition
864  {
865  Left,
866  Right,
867  None
868  };
869 
870  //touch IDs tracked by the operator
871  HPS::TouchID left_side_touch;
872  HPS::TouchID right_side_touch;
873  HPS::TouchID second_right_touch;
874 
875  //current and start location for touch operations
876  HPS::WindowPoint start_point;
877  HPS::WindowPoint left_start_point;
878  HPS::WindowPoint right_start_point;
879  HPS::WindowPoint current_right_touch_position;
880  HPS::WindowPoint second_right_start_point;
881  HPS::WindowPoint current_second_right_touch_position;
882  HPS::WindowPoint start_mid_point;
883 
884  //virtual joystick information
885  HPS::SegmentKey left_joystick_segment;
886  HPS::SegmentKey right_joystick_segment;
887  float joystick_dead_zone;
888 
889  //step length for left touch, right touch, and desktop operation
890  float keyboard_sensitivity;
891  float old_keyboard_sensitivity;
892  float left_joystick_sensitivity;
893  float old_left_joystick_sensitivity;
894  float right_joystick_sensitivity;
895  float old_right_joystick_sensitivity;
896  float mouse_sensitivity;
897  float scene_extents;
898 
899  //operator state flags
900  bool two_right_fingers_down;
901  bool invert_x_axis;
902  bool invert_y_axis;
903  Drawing::Handedness world_handedness;
904  bool shift_pressed;
905  bool ctrl_pressed;
906  HPS::KeyPath event_path;
907  HPS::WindowPoint rotation_location;
908  HPS::WindowPoint moving_position;
909 
910  //utility functions
911  void UpdateKeyboardState(KeyboardState const & in_state);
912  float CalculateSceneExtents();
913  void ComputeReasonableStepLength();
914  void CreateJoystick(HPS::TouchState const & in_state, TouchPosition touch_position);
915 };
916 
952 class SPRK_OPS_API WalkOperator : public FlyOperator
953 {
954 public:
955  WalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
956 
958  virtual HPS::UTF8 GetName() const { return "HPS_WalkOperator"; }
959 
962  virtual void OnModelAttached();
963 
965  virtual void OnViewAttached();
966 
971  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
972 
973  /* Getters / Setters for the plane the operator walks on. */
974  void SetGroundPlane(HPS::Plane const & in_plane) { ground = in_plane; }
975  HPS::Plane GetGroundPlane() const { return ground; }
976 
977  /* Getters / Setters for camera vertical offset from the ground plane */
978  void SetWalkerHeight(float height) { height_off_ground = height; }
979  float GetWalkerHeight() const { return height_off_ground; }
980 
981  /* An enumeration for the direction of a vector. */
982  enum class Axis { X, Y, Z, Negative_X, Negative_Y, Negative_Z };
983  static Axis GetPrimaryAxis(HPS::Vector const & v);
984 
985  /* Returns the primary direction of the camera Up vector. */
986  Axis GetPrimaryUpAxis() const { return primary_up_axis; }
987 
988  Axis UpdatePrimaryUpAxis(HPS::Vector const & v);
989 
990 private:
991  HPS::Plane ground;
992  HPS::Vector walking_direction;
993  float height_off_ground;
994 
995  Axis primary_up_axis;
996 
997  void CalculateGroundPlane();
998  void SnapToPlane();
999  void AdjustWalkingDirection(HPS::Vector const & camera_direction, HPS::Vector const & camera_up);
1000 };
1001 
1027 class SPRK_OPS_API SimpleWalkOperator : public WalkOperator
1028 {
1029 public:
1030  SimpleWalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1031 
1033  virtual HPS::UTF8 GetName() const { return "HPS_SimpleWalkOperator"; }
1034 
1037  virtual void OnModelAttached();
1038 
1040  virtual void OnViewAttached();
1041 
1045  virtual bool OnKeyDown(KeyboardState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1049  virtual bool OnKeyUp(KeyboardState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1053  virtual bool OnMouseWheel(MouseState const & in_state);
1054 
1059  virtual bool OnMouseDown(MouseState const & in_state);
1064  virtual bool OnMouseMove(MouseState const & in_state);
1068  virtual bool OnMouseUp(MouseState const & in_state);
1072  virtual bool OnMouseEnter(MouseState const & in_state);
1076  virtual bool OnMouseLeave(MouseState const & in_state);
1077 
1081  virtual bool OnTouchDown(TouchState const & in_state);
1085  virtual bool OnTouchMove(TouchState const & in_state);
1088  virtual bool OnTouchUp(TouchState const & in_state);
1089 
1094  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
1095 
1100  void SetKeyboardShiftKey(bool in_state);
1101 
1106  void SetKeyboardControlKey(bool in_state);
1107 
1112  void SetEnableMiddleMouseButtonDolly(bool in_enable);
1113 
1118  bool GetEnableMiddleMouseButtonDolly() const;
1119 
1123  bool IsMouseTriggered(MouseState const & in_state);
1124 
1125 private:
1126  class ScaleFactor
1127  {
1128  public:
1129  float time;
1130  float forward, horizontal, vertical;
1131  float roll, pitch, yaw;
1132  ScaleFactor(float time) : time(time),
1133  forward(1), horizontal(1), vertical(1),
1134  roll(1), pitch(1), yaw(1) {}
1135 
1136  void SetTime(float t) { time = t; }
1137  void SetForward(float f) { forward=f; }
1138  void SetHorizontal(float h) { horizontal = h; }
1139  void SetVertical(float v) { vertical = v; }
1140  void SetRoll(float r) { roll = r; }
1141  void SetPitch(float p) { pitch = p; }
1142  void SetYaw(float y) { yaw = y; }
1143 
1144  float GetTime() const { return time; }
1145  float GetForward() const { return forward; }
1146  float GetHorizontal() const { return horizontal; }
1147  float GetVertical() const { return vertical; }
1148  float GetRoll() const { return roll; }
1149  float GetPitch() const { return pitch; }
1150  float GetYaw() const { return yaw; }
1151 
1152  float Forward() const { return forward*time; }
1153  float Horizontal() const { return horizontal*time; }
1154  float Vertical() const { return vertical*time; }
1155  float Roll() const { return roll*time; }
1156  float Pitch() const { return pitch*time; }
1157  float Yaw() const { return yaw*time; }
1158  };
1159 
1160  void Pan(float in_theta, float in_phi);
1161  void Dolly(float in_right, float in_up, float in_forward);
1162  void ResetCamera(HPS::CameraKit & camera) const;
1163  float CalculatePitch(HPS::CameraKit & camera) const;
1164  bool NotableCameraDifference(HPS::CameraKit const & camera1, HPS::CameraKit const & camera2);
1165 
1166  int DirectionForward() const { return 0x1; }
1167  int DirectionHorizontal() const { return 0x2; }
1168  int DirectionVertical() const { return 0x4; }
1169  int DirectionRoll() const { return 0x8; }
1170  int DirectionPitch() const { return 0x10; }
1171  int DirectionYaw() const { return 0x20; }
1172 
1173  bool Move(HPS::Point const & start, HPS::Point const & current, int directions, HPS::CameraKit & camera, ScaleFactor const & scale);
1174 
1175  void Init();
1176 
1177  HPS::WindowPoint mouse_current_point;
1178  HPS::WindowPoint mouse_start_point;
1179  bool mouse_operator_started;
1180  bool mouse_moving;
1181  bool middle_mouse_button_active;
1182 
1183  HPS::WindowPoint touch_current_point;
1184  HPS::WindowPoint touch_start_point;
1185  bool touch_operator_started;
1186  bool touch_moving;
1187  bool double_touch_active;
1188  HPS::Touch touch1, touch2;
1189 
1190  bool keybrd_control;
1191  bool keybrd_shift;
1192  bool enable_middle_button_dolly;
1193  HPS::UpdateNotifier last_notifier;
1194  bool pending_camera_valid;
1195  HPS::CameraKit pending_camera;
1196  HPS::CameraKit last_camera;
1197 };
1198 
1199 
1257 class SPRK_OPS_API CuttingSectionOperator : public SelectOperator
1258 {
1259 private:
1260  enum class OpState
1261  {
1262  Uninitialized,
1263  Initialized,
1264  Translating,
1265  FacePicking,
1266  };
1267 
1268 public:
1269  CuttingSectionOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1270 
1272  virtual HPS::UTF8 GetName() const { return "HPS_CuttingSectionOperator"; }
1273 
1274  virtual void OnModelAttached();
1275  virtual void OnViewAttached();
1276  virtual void OnViewDetached();
1277 
1282  void SetPlanes(PlaneArray const & in_planes);
1283 
1286  PlaneArray GetPlanes();
1287 
1293  virtual bool OnMouseDown(MouseState const & in_state);
1294 
1298  virtual bool OnMouseUp(MouseState const & in_state);
1299 
1305  virtual bool OnMouseMove(MouseState const & in_state);
1306 
1312  virtual bool OnTouchDown(TouchState const & in_state);
1313 
1317  virtual bool OnTouchUp(TouchState const & in_state);
1318 
1323  virtual bool OnTouchMove(TouchState const & in_state);
1324 
1329  virtual bool OnTimerTick(TimerTickEvent const & in_event);
1330 
1333  float GetIndicatorScale() const { return indicator_scale; }
1334 
1337  void SetIndicatorScale(float in_scale) { indicator_scale = in_scale; }
1338 
1341  MaterialMappingKit GetPlaneMaterial() const { return plane_material; }
1342 
1345  void SetPlaneMaterial(MaterialMappingKit const & in_plane_material);
1346 
1349  HighlightOptionsKit GetPlaneHighlightOptions() const { return highlight_options; }
1350 
1353  void SetPlaneHighlightOptions(HighlightOptionsKit const & in_highlight_options) { highlight_options = in_highlight_options; }
1354 
1357  bool GetMouseOverHighlighting() const { return enable_mouse_over_highlighting; }
1358 
1361  void SetMouseOverHighlighting(bool in_enable_mouse_over_highlighting) { enable_mouse_over_highlighting = in_enable_mouse_over_highlighting; }
1362 
1366  void SetSectioning(bool in_sectioning);
1367 
1370  bool GetSectioning() { return sectioning; }
1371 
1375  void SetIndicatorVisibility(bool in_use_indicator);
1376 
1379  bool GetIndicatorVisibility() { return (op_state == OpState::Uninitialized || op_state == OpState::FacePicking) ? true : false; }
1380 
1384  void SetPlaneVisibility(bool in_visibility);
1385 
1388  bool GetPlaneVisibility();
1389 
1390 private:
1391 
1392  void SetupOperatorSegment();
1393  void InsertNormalIndicator(float scale);
1394  ShellKey InsertCuttingPlaneGeometry();
1395  void MouseOverHighlighting(MouseState const & in_state);
1396  void TranslateCuttingPlane(KeyPath const & in_event_path, WindowPoint const & in_event_location);
1397  bool HandleMouseAndTouchDown(WindowKey const & in_event_source, size_t in_number_of_clicks,
1398  KeyPath const & in_event_path, WindowPoint const & in_event_location);
1399  void ViewAlignSectionPlanes(HPS::PlaneArray & in_out_planes) const;
1400  typedef std::pair<CuttingSectionKey, std::vector<ShellKey>> SectionInfo;
1401  typedef std::vector<SectionInfo> SectionArray;
1402  SectionArray sections;
1403 
1404  SegmentKey operator_root_segment;
1405  SegmentKey cutting_sections_segment;
1406  SegmentKey plane_representation_segment;
1407  bool sectioning;
1408 
1409  CuttingSectionKey translating_section;
1410  size_t translating_plane_offset;
1411  ShellKey translating_plane_representation;
1412 
1413  TouchID tracked_touch_ID;
1414  MaterialMappingKit plane_material;
1415  SegmentKey indicator_seg;
1416  OpState op_state;
1417  WorldPoint start_world_point;
1418  SelectionOptionsKit selection_options;
1419  SelectionOptionsKit mouse_over_selection_options;
1420  float indicator_scale;
1421  Vector plane_normal;
1422  bool plane_normal_valid;
1423  WorldPoint anchor_point;
1424  SimpleCuboid model_bounding;
1425 
1426  UpdateNotifier last_highlight_notifier;
1427  bool last_skipped_highlight_state_valid;
1428  MouseState last_skipped_highlight_state;
1429  bool is_plane_highlighted;
1430  PortfolioKey portfolio;
1431  SegmentKey style_segment;
1432  HighlightOptionsKit highlight_options;
1433  bool enable_mouse_over_highlighting;
1434  bool skip_mouse_overs;
1435 
1436  View attached_view;
1437  KeyArray navigation_keys;
1438 };
1439 
1475 class SPRK_OPS_API MarkupOperator : public Operator
1476 {
1477 public:
1478  enum class MarkupType
1479  {
1480  Freehand,
1481  Text,
1482  Circle,
1483  Rectangle,
1484  };
1485 
1486  MarkupOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1487 
1489  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_MarkupOperator"; }
1490 
1491  virtual void OnViewAttached() OVERRIDE;
1492  virtual void OnViewDetached() OVERRIDE;
1493 
1498  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1499 
1503  virtual bool OnMouseUp(MouseState const & in_state) OVERRIDE;
1504 
1511  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1512 
1513 
1518  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1519 
1523  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
1524 
1531  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
1532 
1538  virtual bool OnKeyDown(KeyboardState const & in_state) OVERRIDE;
1539 
1545  virtual bool OnTextInput(HPS::UTF8 const & in_text) OVERRIDE;
1546 
1548  MarkupType GetMarkupType() { return markup_type; }
1549 
1551  void SetMarkupType(MarkupType in_markup_type) { markup_type = in_markup_type; }
1552 
1555  RGBColor GetColor() { return current_attributes.color; }
1556 
1558  void SetColor(RGBColor const & in_color) { current_attributes.color = in_color; }
1559 
1562  TextAttributeKit GetTextAttributes() { return current_attributes.text_attributes; }
1563 
1565  void SetTextAttribute(TextAttributeKit const & in_text_attributes) { current_attributes.text_attributes = in_text_attributes; }
1566 
1569  LineAttributeKit GetLineAttributes() { return current_attributes.line_attributes; }
1570 
1572  void SetLineAttribute(LineAttributeKit const & in_line_attributes) {current_attributes.line_attributes = in_line_attributes; }
1573 
1577  SegmentKey GetSegmentKey() { return markup_segment; }
1578 
1580  void DeleteMarkups();
1581 
1584  bool IsMarkupActive() { return operator_active; }
1585 
1586  class SPRK_OPS_API MarkupInsertedEvent : public HPS::Event
1587  {
1588  public:
1591  {
1592  channel = GetClassID();
1593  consumable = false;
1594  }
1595 
1596  MarkupInsertedEvent(HPS::Key const & in_markup_key, HPS::View const & in_view) : Event()
1597  {
1598  channel = GetClassID();
1599  consumable = false;
1600  markup_key = in_markup_key;
1601  view = in_view;
1602  }
1603 
1606  MarkupInsertedEvent(Event const & in_event) : Event(in_event)
1607  {
1608  if (in_event.GetChannel() == Object::ClassID<MarkupInsertedEvent>())
1609  {
1610  auto that = static_cast<MarkupInsertedEvent const &>(in_event);
1611  markup_key = that.markup_key;
1612  view = that.view;
1613  }
1614  else
1615  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1616  }
1617 
1619 
1622  Event * Clone() const
1623  {
1624  MarkupInsertedEvent * new_event = new MarkupInsertedEvent(*this);
1625  return new_event;
1626  }
1627 
1628  Key markup_key;
1629  View view;
1630  };
1631 
1632 private:
1633  struct Attributes
1634  {
1635  RGBColor color;
1636  LineAttributeKit line_attributes;
1637  TextAttributeKit text_attributes;
1638  };
1639 
1640  class KeyboardHiddenEventHandler : public EventHandler
1641  {
1642  public:
1643  KeyboardHiddenEventHandler()
1644  : EventHandler()
1645  { }
1646 
1647  virtual ~KeyboardHiddenEventHandler()
1648  { Shutdown(); }
1649 
1650  virtual HandleResult Handle(Event const * /*in_event*/)
1651  {
1652  markup_operator->keyboard_active = false;
1653 
1654  markup_operator->ResetCameras();
1655  return HandleResult::Handled;
1656  }
1657 
1658  void SetOperator(MarkupOperator * in_operator) { markup_operator = in_operator; }
1659 
1660  private:
1661  MarkupOperator * markup_operator;
1662  };
1663 
1664  std::unordered_multimap<RGBColor, SegmentKey> attribute_map;
1665 
1666  MouseButtons mouse_trigger;
1667  ModifierKeys modifier_trigger;
1668 
1669  MarkupType markup_type;
1670  SegmentKey markup_segment;
1671  SegmentKey current_segment;
1672  Attributes current_attributes;
1673 
1674  static const RGBColor default_color;
1675  static const TextAttributeKit default_text_attributes;
1676  static const LineAttributeKit default_line_attributes;
1677 
1678  Point start_point;
1679  bool start_new_line;
1680  LineKey current_line;
1681  size_t current_line_size;
1682  CircleKey current_circle;
1683  LineKey current_circle_line;
1684  LineKey current_rectangle;
1685  View last_attached_view;
1686 
1687  bool start_new_note;
1688  bool keyboard_active;
1689  TextKey default_text;
1690  TextKey current_text;
1691  SizeTArray text_columns;
1692  size_t current_text_row;
1693 
1694  bool operator_active;
1695  TouchID tracked_touch_id;
1696  TouchID second_tracked_touch_id;
1697 
1698  CameraKit original_camera;
1699  CameraKit original_markup_camera;
1700 
1701  KeyboardHiddenEventHandler handler;
1702 
1703  bool SetupConstructionSegments();
1704  void LookupSegment();
1705  void CreateNewMarkupSegment();
1706  void DrawFreehand(Point const & location);
1707  void DrawText();
1708  void DrawCircle(Point const & location);
1709  void DrawCircleFromTwoPoints(Point const & point_one, Point const & point_two);
1710  void DrawRectangleFromTwoPoints(Point const & point_one, Point const & point_two);
1711  void DrawRectangle(Point const & location);
1712  void CenterCameras(Point const & main_camera_center, Point const & markup_camera_center);
1713  void ResetCameras();
1714  void EndTextNote();
1715 };
1716 
1734 class SPRK_OPS_API AnnotationOperator : public Operator
1735 {
1736 public:
1737  AnnotationOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1738 
1740  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_AnnotationOperator"; }
1741 
1742  virtual void OnViewAttached() OVERRIDE;
1743  virtual void OnViewDetached() OVERRIDE;
1744 
1752  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1753 
1759  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1760 
1761 
1769  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1770 
1774  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
1775 
1780  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
1781 
1782 
1787  virtual bool OnKeyDown(KeyboardState const & in_state) OVERRIDE;
1788 
1793  virtual bool OnTextInput(HPS::UTF8 const & in_text) OVERRIDE;
1794 
1802  void SetBackgroundShape(const char * in_shape);
1803 
1807  UTF8 GetBackgroundShape() const;
1808 
1812  class SPRK_OPS_API AnnotationInsertedEvent : public HPS::Event
1813  {
1814  public:
1817  {
1818  channel = GetClassID();
1819  consumable = false;
1820  }
1821 
1822  AnnotationInsertedEvent(HPS::SegmentKey const & in_text_key, HPS::View const & in_view) : Event()
1823  {
1824  channel = GetClassID();
1825  consumable = false;
1826  text_key = in_text_key;
1827  view = in_view;
1828  }
1829 
1832  AnnotationInsertedEvent(Event const & in_event) : Event(in_event)
1833  {
1834  if (in_event.GetChannel() == Object::ClassID<AnnotationInsertedEvent>())
1835  {
1836  auto that = static_cast<AnnotationInsertedEvent const &>(in_event);
1837  text_key = that.text_key;
1838  view = that.view;
1839  }
1840  else
1841  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1842  }
1843 
1845 
1848  Event * Clone() const
1849  {
1850  AnnotationInsertedEvent * new_event = new AnnotationInsertedEvent(*this);
1851  return new_event;
1852  }
1853 
1854  SegmentKey text_key; //the key of the segment containing the annotation
1855  View view;
1856  };
1857 
1858 private:
1859  void AddAnnotationUserData();
1860  void StartNewNote();
1861 
1862  bool InputDown(WindowKey const & window_key, Point const & location, KeyPath & event_path);
1863  bool InputMove(Point const & location, KeyPath & event_path);
1864 
1865  void CenterCamera(Point const & camera_center);
1866  void ResetCamera();
1867 
1868  class KeyboardHiddenEventHandler : public EventHandler
1869  {
1870  public:
1871  KeyboardHiddenEventHandler()
1872  : EventHandler()
1873  { }
1874 
1875  virtual ~KeyboardHiddenEventHandler()
1876  { Shutdown(); }
1877 
1878  virtual HandleResult Handle(Event const * /*in_event*/)
1879  {
1880  annotation_operator->keyboard_active = false;
1881 
1882  annotation_operator->ResetCamera();
1883  return HandleResult::Handled;
1884  }
1885 
1886  void SetOperator(AnnotationOperator * in_operator) { annotation_operator = in_operator; }
1887 
1888  private:
1889  AnnotationOperator * annotation_operator;
1890  };
1891 
1892 
1893  SegmentKey annotation_segment; //segment containing all annotations
1894  View last_attached_view; //the last view that was attached to this operator
1895  SelectionOptionsKit selection_options; //selection options used to select geometry
1896  SelectionOptionsKit annotation_selection_options; //selection options used when trying to select annotations
1897  bool editing_text; //whether we are in a state which allows editing of an annotation
1898  bool start_new_note; //whether we should delete the text of an annotation when typing
1899  UTF8 annotation_user_data; //the user data set on annotation geometry to distinguish it from non annotation geometry
1900  UTF8 annotation_shape; //the name of the shape definition used to draw the annotation background
1901 
1902  PortfolioKey current_portfolio; //the portfolio used to store the default definitions used by this operator
1903  SegmentKey highlight_style_segment; //the highlight background style
1904 
1905  RGBColor background_color; //the color of the annotation background
1906  RGBColor leader_line_color; //the color of the annotation leader line and edges
1907  RGBColor highlight_color; //the color the annotation becomes while it is being edited
1908 
1909  TextKey text_to_edit; //the annotation text which we are working on
1910  SizeTArray text_columns; //the number of columns of the text for the current annotation
1911  size_t current_text_row; //the number of rows of the text for the current annotation
1912 
1913  //touch only flags -- these flags are only relevant when running the operator on a touch enabled device
1914  TouchID tracked_touch_id; //the ID of the touch we are tracking
1915  bool keyboard_active; //whether the software keyboard is visible
1916  CameraKit original_camera; //the camera setting as they were just before the annotation text is edited
1917  KeyboardHiddenEventHandler handler; //a handler that takes care of resetting the camera when the software keyboard is hidden
1918  Point touch_down_position; //the position the last touch down occurred at
1919  bool always_show_keyboard_on_touch_up; //true if we are just inserting the annotation, false if we are editing a previously inserted one.
1920 };
1921 
1939 class SPRK_OPS_API HandlesOperator : public Operator
1940 {
1941 public:
1942  HandlesOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1943 
1944  enum class HandleType
1945  {
1946  Rotation,
1947  AxisTranslation,
1948  PlaneTranslation,
1949  CenterPoint,
1950  };
1951 
1953  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_HandlesOperator"; }
1954 
1955  virtual void OnViewAttached() OVERRIDE;
1956  virtual void OnViewDetached() OVERRIDE;
1957 
1964  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1965 
1970  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1971 
1975  virtual bool OnMouseUp(MouseState const & in_state) OVERRIDE;
1976 
1983  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1984 
1989  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
1990 
1994  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
1995 
2010  void SetHandlesColors(MaterialKitArray const & in_colors) { handles_colors = in_colors; }
2011 
2027  MaterialKitArray GetHandlesColors() const { return handles_colors; }
2028 
2032  void SetHighlightColor(RGBAColor const & in_highlight_color);
2033 
2036  RGBAColor GetHighlightColor() const { return highlight_color; }
2037 
2043  void SetHandlesAppearance(float in_length = 0.16f, float in_radius = 0.005f, size_t in_handles_points = 30);
2044 
2050  void SetRotationHandleAppearance(float in_offset = 0.045f, float in_angle = 25.0f, float in_tip_size = 0.15f);
2051 
2057  void SetPlaneTranslationAppearance(float in_plane_offset = 0.2f, float in_plane_length = 0.6f, float in_center_radius = 0.2f);
2058 
2063  void GetHandlesAppearance(float & out_length, float & out_radius, size_t & out_handles_points) const;
2064 
2069  void GetRotationHandleAppearance(float & out_offset, float & out_angle, float & out_tip_size) const;
2070 
2075  void GetPlaneTranslationAppearance(float & out_plane_offset, float & out_plane_length, float & out_center_radius) const;
2076 
2080  void SetTrailingGeometry(bool in_state) { display_trailing_geometry = in_state; }
2081 
2085  bool GetTrailingGeometry() const { return display_trailing_geometry; }
2086 
2090  void AddHandles(HandleType handle_type);
2091 
2095  void RemoveHandles(HandleType handle_type);
2096 
2097  class SPRK_OPS_API GeometryTransformedEvent : public HPS::Event
2098  {
2099  public:
2102  {
2103  channel = GetClassID();
2104  consumable = false;
2105  }
2106 
2107  GeometryTransformedEvent(HPS::View const & in_view, HPS::SegmentKey const & in_segment_key, HPS::MatrixKit const & in_transform) : Event()
2108  {
2109  channel = GetClassID();
2110  consumable = false;
2111  view = in_view;
2112  segment_key = in_segment_key;
2113  transform = in_transform;
2114  }
2115 
2118  GeometryTransformedEvent(Event const & in_event) : Event(in_event)
2119  {
2120  if (in_event.GetChannel() == Object::ClassID<GeometryTransformedEvent>())
2121  {
2122  auto that = static_cast<GeometryTransformedEvent const &>(in_event);
2123  view = that.view;
2124  segment_key = that.segment_key;
2125  transform = that.transform;
2126  }
2127  else
2128  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
2129  }
2130 
2132 
2135  Event * Clone() const
2136  {
2137  GeometryTransformedEvent * new_event = new GeometryTransformedEvent(*this);
2138  return new_event;
2139  }
2140 
2141  SegmentKey segment_key;
2142  MatrixKit transform;
2143  View view;
2144  };
2145 
2146 private:
2147  enum class Movement
2148  {
2149  None,
2150  Translation,
2151  Rotation,
2152  PlaneTranslation,
2153  };
2154 
2155  enum InternalHandleType : size_t
2156  {
2157  rotation = 0,
2158  axis_translation,
2159  plane_translation,
2160  center_point_translation,
2161  last = center_point_translation,
2162  };
2163 
2164  CanvasArray canvases; //A list of Canvas objects that the View attached to this operator belongs to. This value only gets updated on OnViewAttached.
2165  View last_attached_view; //The last View to where this operator was pushed.
2166  TouchID tracked_touch_id;
2167 
2168  SegmentKey handles; //top level segment
2169  SegmentKey handles_segment; //segment where the matrices for the handles transformations are accumulated
2170  SegmentKey handles_geometry; //segment where the handles geometry lives
2171  SegmentKey center_sphere;
2172  SegmentKey reference_segment; //segment containing all the net attributes of segment_to_move
2173  SegmentKey segment_to_move; //segment containing geometry affected by the handles
2174  SegmentKey temporary_segment_to_move; //segment where we accumulate changes while the handles are active
2175  SegmentKey handles_trail; //segment containing the trailing geometry
2176  KeyPath path_to_segment_to_move;
2177 
2178  std::vector<bool> requested_handle_type;
2179  std::vector<bool> current_handle_type;
2180 
2181  WorldPoint handles_origin_point;
2182  WorldPoint movement_start_point;
2183  Point input_down_position;
2184 
2185  Camera::Projection camera_projection;
2186 
2187  SelectionOptionsKit geometry_selection_options;
2188  SelectionOptionsKit handles_selection_options;
2189 
2190  HighlightOptionsKit hide_highlight_options;
2191  HighlightOptionsKit partial_transparency_options;
2192  HighlightOptionsKit highlight_options;
2193  SegmentKey style_segment;
2194  SegmentKey transparency_style_segment;
2195  UTF8 style_name;
2196  bool something_is_highlighted;
2197  MaterialKitArray handles_colors;
2198  RGBAColor highlight_color;
2199  Key highlighted_handle;
2200 
2201  //state flags
2202  bool are_handles_on;
2203  bool remove_handles;
2204  Movement move_geometry;
2205  Movement previous_movement;
2206  Vector movement_direction;
2207  Plane movement_plane;
2208  Vector base_vector;
2209 
2210  //handles appearance
2211  float handles_length; //Length of the handles. Expressed in percentage of screen [0 - 1]
2212  float handles_radius; //Radius of the handles. Expressed in percentage of screen [0 - 1]
2213  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].
2214  float arc_angle; //The angle formed by the arc handles. Must be greater than zero.
2215  size_t arc_points; //The number of points used to draw the arc handles.
2216  float tip_size; //The size of the tips at the end of the handles, specified as a percentage of the handles length
2217  float plane_offset; //The distance between the axis translation handle and the start of the plane translation handle, specified as a percentage of handles_length.
2218  float plane_length; //The length of the plane translation handle, specified as a percentage of handles_length.
2219  float center_radius;
2220 
2221  //handle geometry
2222  CylinderKey x;
2223  CylinderKey y;
2224  CylinderKey z;
2225  CylinderKey arc_x;
2226  CylinderKey arc_y;
2227  CylinderKey arc_z;
2228  ShellKey xy;
2229  ShellKey xz;
2230  ShellKey yz;
2231  SphereKey center;
2232 
2233  //trailing geometry
2234  bool display_trailing_geometry;
2235  Point trailing_line_start;
2236  Point trailing_circle_start;
2237  Point trailing_circle_center;
2238  Vector trailing_rotation;
2239  MarkerKey trail_marker;
2240  LineKey trailing_line;
2241  CircularArcKey trailing_circle;
2242  float rotation_direction;
2243 
2244  bool InputDown(size_t in_click_count, WindowKey const & in_window, Point const & in_location);
2245  bool InputMove(KeyPath const & in_path, Point const & in_location);
2246  void InputUp(Point const & in_location);
2247 
2248  void InsertHandles();
2249  void InsertRotationHandles();
2250  void InsertAxisTranslationHandles();
2251  void InsertPlaneTranslationHandles();
2252  void InsertCenterPoint();
2253 
2254  void RemoveHandles();
2255 
2256  bool HighlightHandles(WindowKey & in_window, Point const & in_location);
2257 
2258  //moves the geometry affected by handles into a new segment, and hides the original
2259  void ReferenceGeometry(KeyPath const & in_path);
2260 
2261  //copies the accumulated transform from the reference geometry segment back into the original place.
2262  //removes the hide highlight from the original geometry
2263  void CommitChanges();
2264 };
2265 
2266 }
2267 #endif
2268 
2269 
Definition: hps.h:6196
Event * Clone() const
Definition: sprk_ops.h:1848
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:508
MarkupInsertedEvent(Event const &in_event)
Definition: sprk_ops.h:1606
Definition: sprk.h:264
bool GetSectioning()
Definition: sprk_ops.h:1370
An InvalidSpecificationException is thrown when a method is called with non-sensical or contradictory...
Definition: hps.h:5676
SegmentKey GetSegmentKey()
Definition: sprk_ops.h:1577
static MouseButtons ButtonRight()
Definition: hps.h:44957
Definition: sprk_ops.h:1027
Definition: sprk_ops.h:280
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:195
Event * Clone() const
Definition: sprk_ops.h:2135
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1953
RGBAColor GetHighlightColor() const
Definition: sprk_ops.h:2036
Definition: hps.h:35546
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:1551
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1033
Definition: hps.h:45444
Definition: hps.h:7703
Definition: sprk_ops.h:67
AnnotationInsertedEvent()
Definition: sprk_ops.h:1816
Definition: hps.h:3477
Definition: hps.h:6580
ZoomType
Definition: sprk_ops.h:570
void SetIndicatorScale(float in_scale)
Definition: sprk_ops.h:1337
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:250
Definition: hps.h:15918
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:2118
void SetPlaneHighlightOptions(HighlightOptionsKit const &in_highlight_options)
Definition: sprk_ops.h:1353
Definition: sprk_ops.h:491
Definition: sprk_ops.h:190
TextAttributeKit GetTextAttributes()
Definition: sprk_ops.h:1562
GeometryTransformedEvent()
Definition: sprk_ops.h:2101
Definition: hps.h:1514
Definition: hps.h:8876
void SetLineAttribute(LineAttributeKit const &in_line_attributes)
Definition: sprk_ops.h:1572
Definition: sprk_ops.h:333
Definition: sprk_ops.h:1586
Definition: sprk_ops.h:674
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:522
Definition: sprk_ops.h:1257
Definition: sprk_ops.h:1939
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1740
Definition: hps.h:45343
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:337
Definition: sprk_ops.h:718
Definition: sprk_ops.h:444
Definition: hps.h:31964
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:411
Definition: hps.h:4378
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:582
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:958
Definition: sprk_ops.h:1475
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:141
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:679
bool GetTrailingGeometry() const
Definition: sprk_ops.h:2085
AnnotationInsertedEvent(Event const &in_event)
Definition: sprk_ops.h:1832
bool GetIndicatorVisibility()
Definition: sprk_ops.h:1379
bool IsMarkupActive()
Definition: sprk_ops.h:1584
Definition: hps.h:4317
RGBColor GetColor()
Definition: sprk_ops.h:1555
Definition: hps.h:7076
Definition: hps.h:44835
Definition: hps.h:26171
Definition: hps.h:42218
Definition: hps.h:5900
Definition: hps.h:43742
Definition: hps.h:41510
Definition: hps.h:45231
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:375
void SetTrailingGeometry(bool in_state)
Definition: sprk_ops.h:2080
Definition: sprk_ops.h:537
Definition: hps.h:15311
intptr_t GetChannel() const
Definition: hps.h:6329
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1272
Definition: hps.h:14563
Definition: hps.h:42495
Definition: hps.h:44354
Projection
Definition: hps.h:1391
bool GetMouseOverHighlighting() const
Definition: sprk_ops.h:1357
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:546
HPS::Rectangle GetRectangle() const
Definition: sprk_ops.h:352
Definition: hps.h:6296
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:429
Definition: hps.h:13572
virtual bool OnKeyDown(KeyboardState const &in_state)
Definition: sprk_ops.h:1045
void SetMouseOverHighlighting(bool in_enable_mouse_over_highlighting)
Definition: sprk_ops.h:1361
Definition: sprk_ops.h:239
LineAttributeKit GetLineAttributes()
Definition: sprk_ops.h:1569
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:467
float GetIndicatorScale() const
Definition: sprk_ops.h:1333
Definition: sprk_ops.h:1734
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:559
Definition: hps.h:43668
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:952
Handedness
Definition: hps.h:1266
static MouseButtons ButtonLeft()
Definition: hps.h:44953
static MouseButtons ButtonMiddle()
Definition: hps.h:44961
Definition: hps.h:9015
static ModifierKeys KeyControl()
Definition: hps.h:44558
MaterialMappingKit GetPlaneMaterial() const
Definition: sprk_ops.h:1341
Definition: hps.h:7622
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:72
Definition: hps.h:9229
Definition: hps.h:10773
void SetTextAttribute(TextAttributeKit const &in_text_attributes)
Definition: sprk_ops.h:1565
MaterialKitArray GetHandlesColors() const
Definition: sprk_ops.h:2027
Definition: hps.h:23523
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:723
Definition: hps.h:23808
Event * Clone() const
Definition: sprk_ops.h:1622
void SetColor(RGBColor const &in_color)
Definition: sprk_ops.h:1558
Definition: sprk.h:1092
Definition: sprk_ops.h:136
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1489
virtual bool OnKeyUp(KeyboardState const &in_state)
Definition: sprk_ops.h:1049
HighlightOptionsKit GetPlaneHighlightOptions() const
Definition: sprk_ops.h:1349
Definition: hps.h:39072
MarkupInsertedEvent()
Definition: sprk_ops.h:1590
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:554
Definition: sprk_ops.h:371