API Search || Global Search
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  bool ShowCenterOfRotation(HPS::Point & out_point) const;
261 
262 private:
263  bool OrbitCommon(HPS::WindowPoint const & in_loc, HPS::CameraKit & out_camera);
264  bool RelativeOrbitCommon(HPS::WindowPoint const & in_loc, HPS::KeyPath & in_event_path);
265  void CalculateTarget(KeyArray const & in_event_path);
266 
267  HPS::Point center_of_rotation;
268  bool operator_active;
269  HPS::TouchID tracked_touch_ID;
270  HPS::Vector start_sphere_pos, new_sphere_pos;
271  HPS::WindowPoint start_point, new_point;
272  HPS::SelectionOptionsKit selection_options;
273 };
274 
282 class SPRK_OPS_API ZoomOperator : public Operator
283 {
284 public:
285  ZoomOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
287  virtual HPS::UTF8 GetName() const { return "HPS_ZoomOperator"; }
288 
293  virtual bool OnMouseDown(MouseState const & in_state);
298  virtual bool OnMouseUp(MouseState const & in_state);
303  virtual bool OnMouseMove(MouseState const & in_state);
304 
309  virtual bool OnTouchDown(TouchState const & in_state);
314  virtual bool OnTouchMove(TouchState const & in_state);
315 
316 private:
317  bool operator_active;
318  HPS::TouchID tracked_touch_ID;
319  HPS::WindowPoint start_point;
320  float zoom_limit;
321  float focal_length;
322  HPS::WindowPoint last_zoom;
323  HPS::Vector last_relative;
324  float zoom_start_field_width;
325  float zoom_start_field_height;
326  HPS::Vector zoom_start_camera_look;
327  HPS::Point zoom_start_camera_target;
328 
329  void ZoomStart();
330  void UpdateZoom(float zoom_factor);
331  void UpdateZoomLimit();
332 };
333 
334 
335 class SPRK_OPS_API ConstructRectangleOperator : public Operator
336 {
337 public:
338  ConstructRectangleOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys(), bool draw_faces = false);
339  virtual HPS::UTF8 GetName() const { return "HPS_ConstructRectangleOperator"; }
340 
341  virtual void OnViewAttached();
342 
343  virtual bool OnMouseDown(MouseState const & in_state);
344  virtual bool OnMouseUp(MouseState const & in_state);
345  virtual bool OnMouseMove(MouseState const & in_state);
346 
347  virtual bool OnTouchDown(TouchState const & in_state);
348  virtual bool OnTouchUp(TouchState const & in_state);
349  virtual bool OnTouchMove(TouchState const & in_state);
350 
351  bool IsRectangleValid() const { return is_rect_valid; }
352 
354  HPS::Rectangle GetRectangle() const { return rect; }
355 
356 private:
357  bool ConstructRectCommon(WindowPoint const & in_loc);
358  void SetupConstructionSegment();
359 
360  bool draw_faces;
361  bool use_center_marker;
362  bool is_rect_valid;
363  bool operator_active;
364  HPS::WindowPoint start_point;
365  HPS::SegmentKey scratch_seg;
366  HPS::Rectangle rect;
367  HPS::LineKey temp_line_key;
368  HPS::PolygonKey temp_polygon_key;
369  HPS::MarkerKey temp_marker_key;
370  HPS::TouchID tracked_touch_ID;
371 };
372 
373 class SPRK_OPS_API ZoomBoxOperator : public ConstructRectangleOperator
374 {
375 public:
376  ZoomBoxOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
377  virtual HPS::UTF8 GetName() const { return "HPS_ZoomBoxOperator"; }
378 
379  virtual bool OnMouseUp(MouseState const & in_state);
380  virtual bool OnTouchUp(TouchState const & in_state);
381 
382 private:
383  bool ZoomCommon(HPS::WindowKey const & in_window, HPS::KeyPath const & in_event_path);
384 
385 };
386 
397 {
398 public:
411  SelectAreaOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
412 
413  virtual HPS::UTF8 GetName() const { return "HPS_SelectAreaOperator"; }
414 
415  virtual void OnViewAttached();
416 
417  virtual bool OnMouseUp(MouseState const & in_state);
418  virtual bool OnTouchUp(TouchState const & in_state);
419 
424  HPS::SelectionResults GetActiveSelection() const;
425 
431  void SetSelectionOptions(HPS::SelectionOptionsKit const & in_options) { selection_options = in_options; }
432 
436  HPS::SelectionOptionsKit GetSelectionOptions() const { return selection_options; }
437 
438 private:
439  bool SelectCommon(HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers = HPS::ModifierKeys());
440 
441  HPS::SelectionResults active_selection;
442  HPS::SelectionOptionsKit selection_options;
443 };
444 
445 
446 class SPRK_OPS_API HighlightAreaOperator : public SelectAreaOperator
447 {
448 public:
455  HighlightAreaOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
456 
457  virtual HPS::UTF8 GetName() const { return "HPS_HighlightAreaOperator"; }
458 
459  virtual void OnViewAttached();
460 
461  virtual bool OnMouseUp(MouseState const & in_state);
462  virtual bool OnTouchUp(TouchState const & in_state);
463 
469  void SetHighlightOptions(HPS::HighlightOptionsKit const & in_options) { highlight_options = in_options; }
470 
474  HPS::HighlightOptionsKit GetHighlightOptions() const { return highlight_options; }
475 
476 private:
477  bool HighlightCommon(WindowKey & in_window, ModifierKeys in_modifiers);
478 
479  HPS::HighlightOptionsKit highlight_options;
480 
481 };
482 
483 
493 class SPRK_OPS_API SelectOperator : public Operator
494 {
495 public:
508  SelectOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
509 
510  virtual HPS::UTF8 GetName() const { return "HPS_SelectOperator"; }
511 
512  virtual bool OnMouseDown(MouseState const & in_state);
513  virtual bool OnTouchDown(TouchState const & in_state);
514 
519  HPS::SelectionResults GetActiveSelection() const;
520 
524  void SetSelectionOptions(HPS::SelectionOptionsKit const & in_options) { selection_options = in_options; }
525 
529  HPS::SelectionOptionsKit GetSelectionOptions() const { return selection_options; }
530 
531 private:
532  bool SelectCommon(HPS::Point const & in_loc, HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers = HPS::ModifierKeys());
533 
534  HPS::SelectionResults active_selection;
535  HPS::SelectionOptionsKit selection_options;
536 };
537 
538 
539 class SPRK_OPS_API HighlightOperator : public SelectOperator
540 {
541 public:
546  HighlightOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
547 
548  virtual HPS::UTF8 GetName() const { return "HPS_HighlightOperator"; }
549 
550  virtual bool OnMouseDown(MouseState const & in_state);
551  virtual bool OnTouchDown(TouchState const & in_state);
552 
556  void SetHighlightOptions(HPS::HighlightOptionsKit const & in_options) { highlight_options = in_options; }
557 
561  HPS::HighlightOptionsKit GetHighlightOptions() const { return highlight_options; }
562 
563 private:
564  bool HighlightCommon(HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers);
565 
566  HPS::HighlightOptionsKit highlight_options;
567 };
568 
569 class SPRK_OPS_API MouseWheelOperator : public Operator
570 {
571 public:
572  enum class ZoomType
573  {
574  Fast,
575  Accurate,
576  };
577 
582  MouseWheelOperator(ZoomType in_default_type = ZoomType::Accurate, HPS::ModifierKeys in_alternate_type_modifiers = HPS::ModifierKeys::KeyControl());
583 
584  virtual HPS::UTF8 GetName() const { return "HPS_MouseWheelOperator"; }
585 
587  void UpdateZoomLimit();
588 
589  virtual bool OnMouseWheel(HPS::MouseState const & in_state);
590 
591  virtual void OnModelAttached();
592 
593  virtual void OnViewAttached();
594 
595 private:
596  float zoom_limit;
597  ZoomType zoom_type;
598  HPS::ModifierKeys zoom_modifier;
599 };
600 
612 class SPRK_OPS_API TurntableOperator : public Operator
613 {
614 public:
615  TurntableOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
617  virtual HPS::UTF8 GetName() const { return "HPS_TurntableOperator"; }
618 
624  virtual bool OnMouseDown(MouseState const & in_state);
629  virtual bool OnMouseUp(MouseState const & in_state);
634  virtual bool OnMouseMove(MouseState const & in_state);
639  virtual bool OnMouseWheel(MouseState const & in_state);
640 
646  virtual bool OnTouchDown(TouchState const & in_state);
651  virtual bool OnTouchUp(TouchState const & in_state);
657  virtual bool OnTouchMove(TouchState const & in_state);
658 
659 private:
660  void TurntableCommon(HPS::WindowPoint const & delta, HPS::Vector const & rotation_axis);
661  void CalculateCenterPoint(HPS::WindowKey const & window, HPS::Point const & location);
662 
663  bool operator_active;
664  bool center_point_set;
665  HPS::WorldPoint center_point;
666  HPS::TouchID tracked_touch_ID;
667  HPS::WindowPoint start_point;
668  HPS::SelectionOptionsKit selection_options;
669 };
670 
676 class SPRK_OPS_API ZoomFitTouchOperator : public Operator
677 {
678 public:
681  virtual HPS::UTF8 GetName() const { return "HPS_ZoomFitTouchOperator"; }
682 
687  virtual bool OnTouchDown(TouchState const & in_state);
692  virtual bool OnTouchUp(TouchState const & in_state);
693 
694 private:
695  HPS::TouchID tracked_touch_ID;
696 };
697 
720 class SPRK_OPS_API FlyOperator : public Operator
721 {
722 public:
723  FlyOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
725  virtual HPS::UTF8 GetName() const { return "HPS_FlyOperator"; }
726 
741  virtual bool OnKeyDown(KeyboardState const & in_state);
745  virtual bool OnKeyUp(KeyboardState const & in_state);
746 
751  virtual bool OnMouseDown(MouseState const & in_state);
755  virtual bool OnMouseUp(MouseState const & in_state);
760  virtual bool OnMouseMove(MouseState const & in_state);
766  virtual bool OnMouseWheel(MouseState const & in_state);
767 
772  virtual bool OnTouchDown(TouchState const & in_state);
776  virtual bool OnTouchUp(TouchState const & in_state);
781  virtual bool OnTouchMove(TouchState const & in_state);
782 
787  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
788 
791  virtual void OnModelAttached();
792 
794  virtual void OnViewAttached();
795 
797  virtual void OnViewDetached();
798 
799  /* getters/setters for inverting the X and Y axis */
800  void InvertXAxis() { invert_x_axis = !invert_x_axis;}
801  void InvertYAxis() { invert_y_axis = !invert_y_axis;}
802  bool IsXAxisInverted() const { return invert_x_axis; }
803  bool IsYAxisInverted() const { return invert_y_axis; }
804 
805  /* getters/setters for sensitivity */
806  /* Keyboard sensitivity affects the speed of movement of action triggered from the keyboard, such as walking forward by pressing W */
807  float GetKeyboardSensitivity() const { return keyboard_sensitivity; }
808  void SetKeyboardSensitivity(float in_keyboard_sensitivity) { keyboard_sensitivity = in_keyboard_sensitivity; }
809 
810  /* Mouse sensitivity affects the speed of movement of action triggered from the mouse, such as rotating */
811  float GetMouseSensitivity() const { return mouse_sensitivity; }
812  void SetMouseSensitivity(float in_mouse_sensitivity) { mouse_sensitivity = in_mouse_sensitivity; }
813 
814  /* Left Joystick sensitivity affects the speed of movement of action triggered from the left joystick on touch devices */
815  float GetLeftJoystickSensitivity() const { return left_joystick_sensitivity; }
816  void SetLeftJoystickSensitivity(float in_left_joystick_sensitivity) { left_joystick_sensitivity = in_left_joystick_sensitivity; }
817 
818  /* Right Joystick sensitivity affects the speed of movement of action triggered from the right joystick on touch devices */
819  float GetRightJoystickSensitivity() const { return right_joystick_sensitivity; }
820  void SetRightJoystickSensitivity(float in_right_joystick_sensitivity) { right_joystick_sensitivity = in_right_joystick_sensitivity; }
821 
822  /* getters/setters for joystick dead zone
823  The dead zone is an area around the initial touch down position where the user can move its finger
824  without triggering any movement.
825  The default value is 0.07. */
826  float GetJoystickDeadZone() const { return joystick_dead_zone; }
827  void SetJoystickDeadZone(float in_dead_zone) { joystick_dead_zone = in_dead_zone; }
828 
829  float GetSceneExtents() const { return scene_extents; }
830 
831 protected:
832 
833  enum MovementFlags
834  {
835  no_movement = 0x0000,
836  moving_forward = 0x0001,
837  moving_back = 0x0002,
838  moving_left = 0x0004,
839  moving_right = 0x0008,
840  moving_up = 0x0010,
841  moving_down = 0x0020,
842  roll_left = 0x0040,
843  roll_right = 0x0080,
844  rotating = 0x0100,
845  move_with_touch = 0x0200,
846  rotate_with_touch = 0x0400
847  };
848 
849  unsigned int movement_flags;
850 
851  //movement functions
852  void MoveLeft(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
853  void MoveRight(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
854  void MoveUp(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
855  void MoveDown(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
856  void MoveForward(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
857  void MoveBack(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
858  bool MoveWithTouch(HPS::Point & position, HPS::Point & target, HPS::Vector & up, HPS::Vector const & walking_direction);
859  bool RotateScene(HPS::Point & position, HPS::Point & target);
860  bool RotateWithTouch(HPS::Point & position, HPS::Point & target);
861  void RotateCommon(HPS::Point const & delta, HPS::Point & position, HPS::Point & target);
862 
863 private:
864 
865  enum class TouchPosition
866  {
867  Left,
868  Right,
869  None
870  };
871 
872  //touch IDs tracked by the operator
873  HPS::TouchID left_side_touch;
874  HPS::TouchID right_side_touch;
875  HPS::TouchID second_right_touch;
876 
877  //current and start location for touch operations
878  HPS::WindowPoint start_point;
879  HPS::WindowPoint left_start_point;
880  HPS::WindowPoint right_start_point;
881  HPS::WindowPoint current_right_touch_position;
882  HPS::WindowPoint second_right_start_point;
883  HPS::WindowPoint current_second_right_touch_position;
884  HPS::WindowPoint start_mid_point;
885 
886  //virtual joystick information
887  HPS::SegmentKey left_joystick_segment;
888  HPS::SegmentKey right_joystick_segment;
889  float joystick_dead_zone;
890 
891  //step length for left touch, right touch, and desktop operation
892  float keyboard_sensitivity;
893  float old_keyboard_sensitivity;
894  float left_joystick_sensitivity;
895  float old_left_joystick_sensitivity;
896  float right_joystick_sensitivity;
897  float old_right_joystick_sensitivity;
898  float mouse_sensitivity;
899  float scene_extents;
900 
901  //operator state flags
902  bool two_right_fingers_down;
903  bool invert_x_axis;
904  bool invert_y_axis;
905  Drawing::Handedness world_handedness;
906  bool shift_pressed;
907  bool ctrl_pressed;
908  HPS::KeyPath event_path;
909  HPS::WindowPoint rotation_location;
910  HPS::WindowPoint moving_position;
911 
912  //utility functions
913  void UpdateKeyboardState(KeyboardState const & in_state);
914  float CalculateSceneExtents();
915  void ComputeReasonableStepLength();
916  void CreateJoystick(HPS::TouchState const & in_state, TouchPosition touch_position);
917 };
918 
953 class SPRK_OPS_API WalkOperator : public FlyOperator
954 {
955 public:
956  WalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
957 
959  virtual HPS::UTF8 GetName() const { return "HPS_WalkOperator"; }
960 
963  virtual void OnModelAttached();
964 
966  virtual void OnViewAttached();
967 
972  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
973 
974  /* Getters / Setters for the plane the operator walks on. */
975  void SetGroundPlane(HPS::Plane const & in_plane) { ground = in_plane; }
976  HPS::Plane GetGroundPlane() const { return ground; }
977 
978  /* Getters / Setters for camera vertical offset from the ground plane */
979  void SetWalkerHeight(float height) { height_off_ground = height; }
980  float GetWalkerHeight() const { return height_off_ground; }
981 
982  /* An enumeration for the direction of a vector. */
983  enum class Axis { X, Y, Z, Negative_X, Negative_Y, Negative_Z };
984  static Axis GetPrimaryAxis(HPS::Vector const & v);
985 
986  /* Returns the primary direction of the camera Up vector. */
987  Axis GetPrimaryUpAxis() const { return primary_up_axis; }
988 
989  Axis UpdatePrimaryUpAxis(HPS::Vector const & v);
990 
991 private:
992  HPS::Plane ground;
993  HPS::Vector walking_direction;
994  float height_off_ground;
995 
996  Axis primary_up_axis;
997 
998  void CalculateGroundPlane();
999  void SnapToPlane();
1000  void AdjustWalkingDirection(HPS::Vector const & camera_direction, HPS::Vector const & camera_up);
1001 };
1002 
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:6205
Event * Clone() const
Definition: sprk_ops.h:1848
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:510
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:5685
SegmentKey GetSegmentKey()
Definition: sprk_ops.h:1577
static MouseButtons ButtonRight()
Definition: hps.h:46029
Definition: sprk_ops.h:1027
Definition: sprk_ops.h:282
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:36480
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:474
Definition: sprk_ops.h:396
HPS::SelectionOptionsKit GetSelectionOptions() const
Definition: sprk_ops.h:529
void SetMarkupType(MarkupType in_markup_type)
Definition: sprk_ops.h:1551
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1033
Definition: hps.h:46516
Definition: hps.h:7713
Definition: sprk_ops.h:67
AnnotationInsertedEvent()
Definition: sprk_ops.h:1816
Definition: hps.h:3484
Definition: hps.h:6589
ZoomType
Definition: sprk_ops.h:572
void SetIndicatorScale(float in_scale)
Definition: sprk_ops.h:1337
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:250
Definition: hps.h:15928
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:457
HPS::SelectionOptionsKit GetSelectionOptions() const
Definition: sprk_ops.h:436
Definition: sprk_ops.h:612
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:493
Definition: sprk_ops.h:190
TextAttributeKit GetTextAttributes()
Definition: sprk_ops.h:1562
GeometryTransformedEvent()
Definition: sprk_ops.h:2101
Definition: hps.h:1519
Definition: hps.h:8886
void SetLineAttribute(LineAttributeKit const &in_line_attributes)
Definition: sprk_ops.h:1572
Definition: sprk_ops.h:335
Definition: sprk_ops.h:1586
Definition: sprk_ops.h:676
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:524
Definition: sprk_ops.h:1257
Definition: sprk_ops.h:1939
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1740
Definition: hps.h:46415
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:339
Definition: sprk_ops.h:720
Definition: sprk_ops.h:446
Definition: hps.h:32326
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:413
Definition: hps.h:4385
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:584
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:959
Definition: sprk_ops.h:1475
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:141
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:681
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:4324
RGBColor GetColor()
Definition: sprk_ops.h:1555
Definition: hps.h:7086
Definition: hps.h:45907
Definition: hps.h:26342
Definition: hps.h:43281
Definition: hps.h:5909
Definition: hps.h:44814
Definition: hps.h:42478
Definition: hps.h:46303
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:377
void SetTrailingGeometry(bool in_state)
Definition: sprk_ops.h:2080
Definition: sprk_ops.h:539
Definition: hps.h:15321
intptr_t GetChannel() const
Definition: hps.h:6338
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1272
Definition: hps.h:14573
Definition: hps.h:43558
Definition: hps.h:45426
Projection
Definition: hps.h:1396
bool GetMouseOverHighlighting() const
Definition: sprk_ops.h:1357
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:548
HPS::Rectangle GetRectangle() const
Definition: sprk_ops.h:354
Definition: hps.h:6305
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:431
Definition: hps.h:13582
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:469
float GetIndicatorScale() const
Definition: sprk_ops.h:1333
Definition: sprk_ops.h:1734
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:561
Definition: hps.h:44740
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:287
Definition: sprk_ops.h:569
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:617
Definition: sprk_ops.h:953
Handedness
Definition: hps.h:1271
static MouseButtons ButtonLeft()
Definition: hps.h:46025
static MouseButtons ButtonMiddle()
Definition: hps.h:46033
Definition: hps.h:9025
static ModifierKeys KeyControl()
Definition: hps.h:45630
MaterialMappingKit GetPlaneMaterial() const
Definition: sprk_ops.h:1341
Definition: hps.h:7632
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:72
Definition: hps.h:9239
Definition: hps.h:10783
void SetTextAttribute(TextAttributeKit const &in_text_attributes)
Definition: sprk_ops.h:1565
MaterialKitArray GetHandlesColors() const
Definition: sprk_ops.h:2027
Definition: hps.h:23598
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:725
Definition: hps.h:23883
Event * Clone() const
Definition: sprk_ops.h:1622
void SetColor(RGBColor const &in_color)
Definition: sprk_ops.h:1558
Definition: sprk.h:1093
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:40018
MarkupInsertedEvent()
Definition: sprk_ops.h:1590
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:556
Definition: sprk_ops.h:373