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 
357  HPS::Rectangle GetWindowRectangle() const { return window_rect; }
362  HPS::Rectangle GetInnerWindowRectangle() const { return inner_window_rect; }
363 
364 private:
365  bool ConstructRectCommon(WindowPoint const & in_loc);
366  void SetupConstructionSegment();
367 
368  bool draw_faces;
369  bool use_center_marker;
370  bool is_rect_valid;
371  bool operator_active;
372  HPS::WindowPoint window_start_point;
373  HPS::WindowPoint inner_window_start_point;
374  HPS::SegmentKey scratch_seg;
375  HPS::Rectangle window_rect;
376  HPS::Rectangle inner_window_rect;
377  HPS::LineKey temp_line_key;
378  HPS::PolygonKey temp_polygon_key;
379  HPS::MarkerKey temp_marker_key;
380  HPS::TouchID tracked_touch_ID;
381 };
382 
383 class SPRK_OPS_API ZoomBoxOperator : public ConstructRectangleOperator
384 {
385 public:
386  ZoomBoxOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
387  virtual HPS::UTF8 GetName() const { return "HPS_ZoomBoxOperator"; }
388 
389  virtual bool OnMouseUp(MouseState const & in_state);
390  virtual bool OnTouchUp(TouchState const & in_state);
391 
392 private:
393  bool ZoomCommon(HPS::WindowKey const & in_window, HPS::KeyPath const & in_event_path);
394 
395 };
396 
407 {
408 public:
421  SelectAreaOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
422 
423  virtual HPS::UTF8 GetName() const { return "HPS_SelectAreaOperator"; }
424 
425  virtual void OnViewAttached();
426 
427  virtual bool OnMouseUp(MouseState const & in_state);
428  virtual bool OnTouchUp(TouchState const & in_state);
429 
434  HPS::SelectionResults GetActiveSelection() const;
435 
441  void SetSelectionOptions(HPS::SelectionOptionsKit const & in_options) { selection_options = in_options; }
442 
446  HPS::SelectionOptionsKit GetSelectionOptions() const { return selection_options; }
447 
448 private:
449  bool SelectCommon(HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers = HPS::ModifierKeys());
450 
451  HPS::SelectionResults active_selection;
452  HPS::SelectionOptionsKit selection_options;
453 };
454 
455 
456 class SPRK_OPS_API HighlightAreaOperator : public SelectAreaOperator
457 {
458 public:
465  HighlightAreaOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
466 
467  virtual HPS::UTF8 GetName() const { return "HPS_HighlightAreaOperator"; }
468 
469  virtual void OnViewAttached();
470 
471  virtual bool OnMouseUp(MouseState const & in_state);
472  virtual bool OnTouchUp(TouchState const & in_state);
473 
479  void SetHighlightOptions(HPS::HighlightOptionsKit const & in_options) { highlight_options = in_options; }
480 
484  HPS::HighlightOptionsKit GetHighlightOptions() const { return highlight_options; }
485 
486 private:
487  bool HighlightCommon(WindowKey & in_window, ModifierKeys in_modifiers);
488 
489  HPS::HighlightOptionsKit highlight_options;
490 
491 };
492 
493 
503 class SPRK_OPS_API SelectOperator : public Operator
504 {
505 public:
518  SelectOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
519 
520  virtual HPS::UTF8 GetName() const { return "HPS_SelectOperator"; }
521 
522  virtual bool OnMouseDown(MouseState const & in_state);
523  virtual bool OnTouchDown(TouchState const & in_state);
524 
529  HPS::SelectionResults GetActiveSelection() const;
530 
534  void SetSelectionOptions(HPS::SelectionOptionsKit const & in_options) { selection_options = in_options; }
535 
539  HPS::SelectionOptionsKit GetSelectionOptions() const { return selection_options; }
540 
541 protected:
542  HPS::SelectionResults active_selection;
543 
544 private:
545  bool SelectCommon(HPS::Point const & in_loc, HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers = HPS::ModifierKeys());
546 
547  HPS::SelectionOptionsKit selection_options;
548 };
549 
550 
551 class SPRK_OPS_API HighlightOperator : public SelectOperator
552 {
553 public:
558  HighlightOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
559 
560  virtual HPS::UTF8 GetName() const { return "HPS_HighlightOperator"; }
561 
562  virtual bool OnMouseDown(MouseState const & in_state);
563  virtual bool OnTouchDown(TouchState const & in_state);
564 
568  void SetHighlightOptions(HPS::HighlightOptionsKit const & in_options) { highlight_options = in_options; }
569 
573  HPS::HighlightOptionsKit GetHighlightOptions() const { return highlight_options; }
574 
575 private:
576  bool HighlightCommon(HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers);
577 
578  HPS::HighlightOptionsKit highlight_options;
579 };
580 
581 class SPRK_OPS_API MouseWheelOperator : public Operator
582 {
583 public:
584  enum class ZoomType
585  {
586  Fast,
587  Accurate,
588  };
589 
594  MouseWheelOperator(ZoomType in_default_type = ZoomType::Accurate, HPS::ModifierKeys in_alternate_type_modifiers = HPS::ModifierKeys::KeyControl());
595 
596  virtual HPS::UTF8 GetName() const { return "HPS_MouseWheelOperator"; }
597 
599  void UpdateZoomLimit();
600 
601  virtual bool OnMouseWheel(HPS::MouseState const & in_state);
602 
603  virtual void OnModelAttached();
604 
605  virtual void OnViewAttached();
606 
607 private:
608  float zoom_limit;
609  ZoomType zoom_type;
610  HPS::ModifierKeys zoom_modifier;
611 };
612 
624 class SPRK_OPS_API TurntableOperator : public Operator
625 {
626 public:
627  TurntableOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
629  virtual HPS::UTF8 GetName() const { return "HPS_TurntableOperator"; }
630 
636  virtual bool OnMouseDown(MouseState const & in_state);
641  virtual bool OnMouseUp(MouseState const & in_state);
646  virtual bool OnMouseMove(MouseState const & in_state);
651  virtual bool OnMouseWheel(MouseState const & in_state);
652 
658  virtual bool OnTouchDown(TouchState const & in_state);
663  virtual bool OnTouchUp(TouchState const & in_state);
669  virtual bool OnTouchMove(TouchState const & in_state);
670 
671 private:
672  void TurntableCommon(HPS::WindowPoint const & delta, HPS::Vector const & rotation_axis);
673  void CalculateCenterPoint(HPS::WindowKey const & window, HPS::Point const & location);
674 
675  bool operator_active;
676  bool center_point_set;
677  HPS::WorldPoint center_point;
678  HPS::TouchID tracked_touch_ID;
679  HPS::WindowPoint start_point;
680  HPS::SelectionOptionsKit selection_options;
681 };
682 
688 class SPRK_OPS_API ZoomFitTouchOperator : public Operator
689 {
690 public:
693  virtual HPS::UTF8 GetName() const { return "HPS_ZoomFitTouchOperator"; }
694 
699  virtual bool OnTouchDown(TouchState const & in_state);
704  virtual bool OnTouchUp(TouchState const & in_state);
705 
706 private:
707  HPS::TouchID tracked_touch_ID;
708 };
709 
732 class SPRK_OPS_API FlyOperator : public Operator
733 {
734 public:
735  FlyOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
737  virtual HPS::UTF8 GetName() const { return "HPS_FlyOperator"; }
738 
753  virtual bool OnKeyDown(KeyboardState const & in_state);
757  virtual bool OnKeyUp(KeyboardState const & in_state);
758 
763  virtual bool OnMouseDown(MouseState const & in_state);
767  virtual bool OnMouseUp(MouseState const & in_state);
772  virtual bool OnMouseMove(MouseState const & in_state);
778  virtual bool OnMouseWheel(MouseState const & in_state);
779 
784  virtual bool OnTouchDown(TouchState const & in_state);
788  virtual bool OnTouchUp(TouchState const & in_state);
793  virtual bool OnTouchMove(TouchState const & in_state);
794 
799  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
800 
803  virtual void OnModelAttached();
804 
806  virtual void OnViewAttached();
807 
809  virtual void OnViewDetached();
810 
811  /* getters/setters for inverting the X and Y axis */
812  void InvertXAxis() { invert_x_axis = !invert_x_axis;}
813  void InvertYAxis() { invert_y_axis = !invert_y_axis;}
814  bool IsXAxisInverted() const { return invert_x_axis; }
815  bool IsYAxisInverted() const { return invert_y_axis; }
816 
817  /* getters/setters for sensitivity */
818  /* Keyboard sensitivity affects the speed of movement of action triggered from the keyboard, such as walking forward by pressing W */
819  float GetKeyboardSensitivity() const { return keyboard_sensitivity; }
820  void SetKeyboardSensitivity(float in_keyboard_sensitivity) { keyboard_sensitivity = in_keyboard_sensitivity; }
821 
822  /* Mouse sensitivity affects the speed of movement of action triggered from the mouse, such as rotating */
823  float GetMouseSensitivity() const { return mouse_sensitivity; }
824  void SetMouseSensitivity(float in_mouse_sensitivity) { mouse_sensitivity = in_mouse_sensitivity; }
825 
826  /* Left Joystick sensitivity affects the speed of movement of action triggered from the left joystick on touch devices */
827  float GetLeftJoystickSensitivity() const { return left_joystick_sensitivity; }
828  void SetLeftJoystickSensitivity(float in_left_joystick_sensitivity) { left_joystick_sensitivity = in_left_joystick_sensitivity; }
829 
830  /* Right Joystick sensitivity affects the speed of movement of action triggered from the right joystick on touch devices */
831  float GetRightJoystickSensitivity() const { return right_joystick_sensitivity; }
832  void SetRightJoystickSensitivity(float in_right_joystick_sensitivity) { right_joystick_sensitivity = in_right_joystick_sensitivity; }
833 
834  /* getters/setters for joystick dead zone
835  The dead zone is an area around the initial touch down position where the user can move its finger
836  without triggering any movement.
837  The default value is 0.07. */
838  float GetJoystickDeadZone() const { return joystick_dead_zone; }
839  void SetJoystickDeadZone(float in_dead_zone) { joystick_dead_zone = in_dead_zone; }
840 
841  float GetSceneExtents() const { return scene_extents; }
842 
843 protected:
844 
845  enum MovementFlags
846  {
847  no_movement = 0x0000,
848  moving_forward = 0x0001,
849  moving_back = 0x0002,
850  moving_left = 0x0004,
851  moving_right = 0x0008,
852  moving_up = 0x0010,
853  moving_down = 0x0020,
854  roll_left = 0x0040,
855  roll_right = 0x0080,
856  rotating = 0x0100,
857  move_with_touch = 0x0200,
858  rotate_with_touch = 0x0400
859  };
860 
861  unsigned int movement_flags;
862 
863  //movement functions
864  void MoveLeft(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
865  void MoveRight(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
866  void MoveUp(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
867  void MoveDown(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
868  void MoveForward(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
869  void MoveBack(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
870  bool MoveWithTouch(HPS::Point & position, HPS::Point & target, HPS::Vector & up, HPS::Vector const & walking_direction);
871  bool RotateScene(HPS::Point & position, HPS::Point & target);
872  bool RotateWithTouch(HPS::Point & position, HPS::Point & target);
873  void RotateCommon(HPS::Point const & delta, HPS::Point & position, HPS::Point & target);
874 
875 private:
876 
877  enum class TouchPosition
878  {
879  Left,
880  Right,
881  None
882  };
883 
884  //touch IDs tracked by the operator
885  HPS::TouchID left_side_touch;
886  HPS::TouchID right_side_touch;
887  HPS::TouchID second_right_touch;
888 
889  //current and start location for touch operations
890  HPS::WindowPoint start_point;
891  HPS::WindowPoint left_start_point;
892  HPS::WindowPoint right_start_point;
893  HPS::WindowPoint current_right_touch_position;
894  HPS::WindowPoint second_right_start_point;
895  HPS::WindowPoint current_second_right_touch_position;
896  HPS::WindowPoint start_mid_point;
897 
898  //virtual joystick information
899  HPS::SegmentKey left_joystick_segment;
900  HPS::SegmentKey right_joystick_segment;
901  float joystick_dead_zone;
902 
903  //step length for left touch, right touch, and desktop operation
904  float keyboard_sensitivity;
905  float old_keyboard_sensitivity;
906  float left_joystick_sensitivity;
907  float old_left_joystick_sensitivity;
908  float right_joystick_sensitivity;
909  float old_right_joystick_sensitivity;
910  float mouse_sensitivity;
911  float scene_extents;
912 
913  //operator state flags
914  bool two_right_fingers_down;
915  bool invert_x_axis;
916  bool invert_y_axis;
917  Drawing::Handedness world_handedness;
918  bool shift_pressed;
919  bool ctrl_pressed;
920  HPS::KeyPath event_path;
921  HPS::WindowPoint rotation_location;
922  HPS::WindowPoint moving_position;
923 
924  //utility functions
925  void UpdateKeyboardState(KeyboardState const & in_state);
926  float CalculateSceneExtents();
927  void ComputeReasonableStepLength();
928  void CreateJoystick(HPS::TouchState const & in_state, TouchPosition touch_position);
929 };
930 
965 class SPRK_OPS_API WalkOperator : public FlyOperator
966 {
967 public:
968  WalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
969 
971  virtual HPS::UTF8 GetName() const { return "HPS_WalkOperator"; }
972 
975  virtual void OnModelAttached();
976 
978  virtual void OnViewAttached();
979 
984  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
985 
986  /* Getters / Setters for the plane the operator walks on. */
987  void SetGroundPlane(HPS::Plane const & in_plane) { ground = in_plane; }
988  HPS::Plane GetGroundPlane() const { return ground; }
989 
990  /* Getters / Setters for camera vertical offset from the ground plane */
991  void SetWalkerHeight(float height) { height_off_ground = height; }
992  float GetWalkerHeight() const { return height_off_ground; }
993 
994  /* An enumeration for the direction of a vector. */
995  enum class Axis { X, Y, Z, Negative_X, Negative_Y, Negative_Z };
996  static Axis GetPrimaryAxis(HPS::Vector const & v);
997 
998  /* Returns the primary direction of the camera Up vector. */
999  Axis GetPrimaryUpAxis() const { return primary_up_axis; }
1000 
1001  Axis UpdatePrimaryUpAxis(HPS::Vector const & v);
1002 
1003 private:
1004  HPS::Plane ground;
1005  HPS::Vector walking_direction;
1006  float height_off_ground;
1007 
1008  Axis primary_up_axis;
1009 
1010  void CalculateGroundPlane();
1011  void SnapToPlane();
1012  void AdjustWalkingDirection(HPS::Vector const & camera_direction, HPS::Vector const & camera_up);
1013 };
1014 
1039 class SPRK_OPS_API SimpleWalkOperator : public WalkOperator
1040 {
1041 public:
1042  SimpleWalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1043 
1045  virtual HPS::UTF8 GetName() const { return "HPS_SimpleWalkOperator"; }
1046 
1049  virtual void OnModelAttached();
1050 
1052  virtual void OnViewAttached();
1053 
1057  virtual bool OnKeyDown(KeyboardState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1061  virtual bool OnKeyUp(KeyboardState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1065  virtual bool OnMouseWheel(MouseState const & in_state);
1066 
1071  virtual bool OnMouseDown(MouseState const & in_state);
1076  virtual bool OnMouseMove(MouseState const & in_state);
1080  virtual bool OnMouseUp(MouseState const & in_state);
1084  virtual bool OnMouseEnter(MouseState const & in_state);
1088  virtual bool OnMouseLeave(MouseState const & in_state);
1089 
1093  virtual bool OnTouchDown(TouchState const & in_state);
1097  virtual bool OnTouchMove(TouchState const & in_state);
1100  virtual bool OnTouchUp(TouchState const & in_state);
1101 
1106  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
1107 
1112  void SetKeyboardShiftKey(bool in_state);
1113 
1118  void SetKeyboardControlKey(bool in_state);
1119 
1124  void SetEnableMiddleMouseButtonDolly(bool in_enable);
1125 
1130  bool GetEnableMiddleMouseButtonDolly() const;
1131 
1135  bool IsMouseTriggered(MouseState const & in_state);
1136 
1137 private:
1138  class ScaleFactor
1139  {
1140  public:
1141  float time;
1142  float forward, horizontal, vertical;
1143  float roll, pitch, yaw;
1144  ScaleFactor(float time) : time(time),
1145  forward(1), horizontal(1), vertical(1),
1146  roll(1), pitch(1), yaw(1) {}
1147 
1148  void SetTime(float t) { time = t; }
1149  void SetForward(float f) { forward=f; }
1150  void SetHorizontal(float h) { horizontal = h; }
1151  void SetVertical(float v) { vertical = v; }
1152  void SetRoll(float r) { roll = r; }
1153  void SetPitch(float p) { pitch = p; }
1154  void SetYaw(float y) { yaw = y; }
1155 
1156  float GetTime() const { return time; }
1157  float GetForward() const { return forward; }
1158  float GetHorizontal() const { return horizontal; }
1159  float GetVertical() const { return vertical; }
1160  float GetRoll() const { return roll; }
1161  float GetPitch() const { return pitch; }
1162  float GetYaw() const { return yaw; }
1163 
1164  float Forward() const { return forward*time; }
1165  float Horizontal() const { return horizontal*time; }
1166  float Vertical() const { return vertical*time; }
1167  float Roll() const { return roll*time; }
1168  float Pitch() const { return pitch*time; }
1169  float Yaw() const { return yaw*time; }
1170  };
1171 
1172  void Pan(float in_theta, float in_phi);
1173  void Dolly(float in_right, float in_up, float in_forward);
1174  void ResetCamera(HPS::CameraKit & camera) const;
1175  float CalculatePitch(HPS::CameraKit & camera) const;
1176  bool NotableCameraDifference(HPS::CameraKit const & camera1, HPS::CameraKit const & camera2);
1177 
1178  int DirectionForward() const { return 0x1; }
1179  int DirectionHorizontal() const { return 0x2; }
1180  int DirectionVertical() const { return 0x4; }
1181  int DirectionRoll() const { return 0x8; }
1182  int DirectionPitch() const { return 0x10; }
1183  int DirectionYaw() const { return 0x20; }
1184 
1185  bool Move(HPS::Point const & start, HPS::Point const & current, int directions, HPS::CameraKit & camera, ScaleFactor const & scale);
1186 
1187  void Init();
1188 
1189  HPS::WindowPoint mouse_current_point;
1190  HPS::WindowPoint mouse_start_point;
1191  bool mouse_operator_started;
1192  bool mouse_moving;
1193  bool middle_mouse_button_active;
1194 
1195  HPS::WindowPoint touch_current_point;
1196  HPS::WindowPoint touch_start_point;
1197  bool touch_operator_started;
1198  bool touch_moving;
1199  bool double_touch_active;
1200  HPS::Touch touch1, touch2;
1201 
1202  bool keybrd_control;
1203  bool keybrd_shift;
1204  bool enable_middle_button_dolly;
1205  HPS::UpdateNotifier last_notifier;
1206  bool pending_camera_valid;
1207  HPS::CameraKit pending_camera;
1208  HPS::CameraKit last_camera;
1209 };
1210 
1211 
1269 class SPRK_OPS_API CuttingSectionOperator : public SelectOperator
1270 {
1271 private:
1272  enum class OpState
1273  {
1274  Uninitialized,
1275  Initialized,
1276  Translating,
1277  FacePicking,
1278  };
1279 
1280 public:
1281  CuttingSectionOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1282 
1284  virtual HPS::UTF8 GetName() const { return "HPS_CuttingSectionOperator"; }
1285 
1286  virtual void OnModelAttached();
1287  virtual void OnViewAttached();
1288  virtual void OnViewDetached();
1289 
1294  void SetPlanes(PlaneArray const & in_planes);
1295 
1298  PlaneArray GetPlanes();
1299 
1305  virtual bool OnMouseDown(MouseState const & in_state);
1306 
1310  virtual bool OnMouseUp(MouseState const & in_state);
1311 
1317  virtual bool OnMouseMove(MouseState const & in_state);
1318 
1324  virtual bool OnTouchDown(TouchState const & in_state);
1325 
1329  virtual bool OnTouchUp(TouchState const & in_state);
1330 
1335  virtual bool OnTouchMove(TouchState const & in_state);
1336 
1341  virtual bool OnTimerTick(TimerTickEvent const & in_event);
1342 
1345  float GetIndicatorScale() const { return indicator_scale; }
1346 
1349  void SetIndicatorScale(float in_scale) { indicator_scale = in_scale; }
1350 
1353  MaterialMappingKit GetPlaneMaterial() const { return plane_material; }
1354 
1357  void SetPlaneMaterial(MaterialMappingKit const & in_plane_material);
1358 
1361  HighlightOptionsKit GetPlaneHighlightOptions() const { return highlight_options; }
1362 
1365  void SetPlaneHighlightOptions(HighlightOptionsKit const & in_highlight_options) { highlight_options = in_highlight_options; }
1366 
1369  bool GetMouseOverHighlighting() const { return enable_mouse_over_highlighting; }
1370 
1373  void SetMouseOverHighlighting(bool in_enable_mouse_over_highlighting) { enable_mouse_over_highlighting = in_enable_mouse_over_highlighting; }
1374 
1378  void SetSectioning(bool in_sectioning);
1379 
1382  bool GetSectioning() { return sectioning; }
1383 
1387  void SetIndicatorVisibility(bool in_use_indicator);
1388 
1391  bool GetIndicatorVisibility() { return (op_state == OpState::Uninitialized || op_state == OpState::FacePicking) ? true : false; }
1392 
1396  void SetPlaneVisibility(bool in_visibility);
1397 
1400  bool GetPlaneVisibility();
1401 
1402 private:
1403 
1404  void SetupOperatorSegment();
1405  void InsertNormalIndicator(float scale);
1406  ShellKey InsertCuttingPlaneGeometry();
1407  void MouseOverHighlighting(MouseState const & in_state);
1408  void TranslateCuttingPlane(KeyPath const & in_event_path, WindowPoint const & in_event_location);
1409  bool HandleMouseAndTouchDown(WindowKey const & in_event_source, size_t in_number_of_clicks,
1410  KeyPath const & in_event_path, WindowPoint const & in_event_location);
1411  void ViewAlignSectionPlanes(HPS::PlaneArray & in_out_planes) const;
1412  typedef std::pair<CuttingSectionKey, std::vector<ShellKey>> SectionInfo;
1413  typedef std::vector<SectionInfo> SectionArray;
1414  SectionArray sections;
1415 
1416  SegmentKey operator_root_segment;
1417  SegmentKey cutting_sections_segment;
1418  SegmentKey plane_representation_segment;
1419  bool sectioning;
1420 
1421  CuttingSectionKey translating_section;
1422  size_t translating_plane_offset;
1423  ShellKey translating_plane_representation;
1424 
1425  TouchID tracked_touch_ID;
1426  MaterialMappingKit plane_material;
1427  SegmentKey indicator_seg;
1428  OpState op_state;
1429  WorldPoint start_world_point;
1430  SelectionOptionsKit selection_options;
1431  SelectionOptionsKit mouse_over_selection_options;
1432  float indicator_scale;
1433  Vector plane_normal;
1434  bool plane_normal_valid;
1435  WorldPoint anchor_point;
1436  SimpleCuboid model_bounding;
1437 
1438  UpdateNotifier last_highlight_notifier;
1439  bool last_skipped_highlight_state_valid;
1440  MouseState last_skipped_highlight_state;
1441  bool is_plane_highlighted;
1442  PortfolioKey portfolio;
1443  SegmentKey style_segment;
1444  HighlightOptionsKit highlight_options;
1445  bool enable_mouse_over_highlighting;
1446  bool skip_mouse_overs;
1447 
1448  View attached_view;
1449  KeyArray navigation_keys;
1450 };
1451 
1487 class SPRK_OPS_API MarkupOperator : public Operator
1488 {
1489 public:
1490  enum class MarkupType
1491  {
1492  Freehand,
1493  Text,
1494  Circle,
1495  Rectangle,
1496  };
1497 
1498  MarkupOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1499 
1501  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_MarkupOperator"; }
1502 
1503  virtual void OnViewAttached() OVERRIDE;
1504  virtual void OnViewDetached() OVERRIDE;
1505 
1510  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1511 
1515  virtual bool OnMouseUp(MouseState const & in_state) OVERRIDE;
1516 
1523  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1524 
1525 
1530  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1531 
1535  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
1536 
1543  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
1544 
1550  virtual bool OnKeyDown(KeyboardState const & in_state) OVERRIDE;
1551 
1557  virtual bool OnTextInput(HPS::UTF8 const & in_text) OVERRIDE;
1558 
1560  MarkupType GetMarkupType() { return markup_type; }
1561 
1563  void SetMarkupType(MarkupType in_markup_type) { markup_type = in_markup_type; }
1564 
1567  RGBColor GetColor() { return current_attributes.color; }
1568 
1570  void SetColor(RGBColor const & in_color) { current_attributes.color = in_color; }
1571 
1574  TextAttributeKit GetTextAttributes() { return current_attributes.text_attributes; }
1575 
1577  void SetTextAttribute(TextAttributeKit const & in_text_attributes) { current_attributes.text_attributes = in_text_attributes; }
1578 
1581  LineAttributeKit GetLineAttributes() { return current_attributes.line_attributes; }
1582 
1584  void SetLineAttribute(LineAttributeKit const & in_line_attributes) {current_attributes.line_attributes = in_line_attributes; }
1585 
1589  SegmentKey GetSegmentKey() { return markup_segment; }
1590 
1592  void DeleteMarkups();
1593 
1596  bool IsMarkupActive() { return operator_active; }
1597 
1598  class SPRK_OPS_API MarkupInsertedEvent : public HPS::Event
1599  {
1600  public:
1603  {
1604  channel = GetClassID();
1605  consumable = false;
1606  }
1607 
1608  MarkupInsertedEvent(HPS::Key const & in_markup_key, HPS::View const & in_view) : Event()
1609  {
1610  channel = GetClassID();
1611  consumable = false;
1612  markup_key = in_markup_key;
1613  view = in_view;
1614  }
1615 
1618  MarkupInsertedEvent(Event const & in_event) : Event(in_event)
1619  {
1620  if (in_event.GetChannel() == Object::ClassID<MarkupInsertedEvent>())
1621  {
1622  auto that = static_cast<MarkupInsertedEvent const &>(in_event);
1623  markup_key = that.markup_key;
1624  view = that.view;
1625  }
1626  else
1627  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1628  }
1629 
1631 
1634  Event * Clone() const
1635  {
1636  MarkupInsertedEvent * new_event = new MarkupInsertedEvent(*this);
1637  return new_event;
1638  }
1639 
1640  Key markup_key;
1641  View view;
1642  };
1643 
1644 private:
1645  struct Attributes
1646  {
1647  RGBColor color;
1648  LineAttributeKit line_attributes;
1649  TextAttributeKit text_attributes;
1650  };
1651 
1652  class KeyboardHiddenEventHandler : public EventHandler
1653  {
1654  public:
1655  KeyboardHiddenEventHandler()
1656  : EventHandler()
1657  { }
1658 
1659  virtual ~KeyboardHiddenEventHandler()
1660  { Shutdown(); }
1661 
1662  virtual HandleResult Handle(Event const * /*in_event*/)
1663  {
1664  markup_operator->keyboard_active = false;
1665 
1666  markup_operator->ResetCameras();
1667  return HandleResult::Handled;
1668  }
1669 
1670  void SetOperator(MarkupOperator * in_operator) { markup_operator = in_operator; }
1671 
1672  private:
1673  MarkupOperator * markup_operator;
1674  };
1675 
1676  std::unordered_multimap<RGBColor, SegmentKey> attribute_map;
1677 
1678  MouseButtons mouse_trigger;
1679  ModifierKeys modifier_trigger;
1680 
1681  MarkupType markup_type;
1682  SegmentKey markup_segment;
1683  SegmentKey current_segment;
1684  Attributes current_attributes;
1685 
1686  static const RGBColor default_color;
1687  static const TextAttributeKit default_text_attributes;
1688  static const LineAttributeKit default_line_attributes;
1689 
1690  Point start_point;
1691  bool start_new_line;
1692  LineKey current_line;
1693  size_t current_line_size;
1694  CircleKey current_circle;
1695  LineKey current_circle_line;
1696  LineKey current_rectangle;
1697  View last_attached_view;
1698 
1699  bool start_new_note;
1700  bool keyboard_active;
1701  TextKey default_text;
1702  TextKey current_text;
1703  SizeTArray text_columns;
1704  size_t current_text_row;
1705 
1706  bool operator_active;
1707  TouchID tracked_touch_id;
1708  TouchID second_tracked_touch_id;
1709 
1710  CameraKit original_camera;
1711  CameraKit original_markup_camera;
1712 
1713  KeyboardHiddenEventHandler handler;
1714 
1715  bool SetupConstructionSegments();
1716  void LookupSegment();
1717  void CreateNewMarkupSegment();
1718  void DrawFreehand(Point const & location);
1719  void DrawText();
1720  void DrawCircle(Point const & location);
1721  void DrawCircleFromTwoPoints(Point const & point_one, Point const & point_two);
1722  void DrawRectangleFromTwoPoints(Point const & point_one, Point const & point_two);
1723  void DrawRectangle(Point const & location);
1724  void CenterCameras(Point const & main_camera_center, Point const & markup_camera_center);
1725  void ResetCameras();
1726  void EndTextNote();
1727 };
1728 
1746 class SPRK_OPS_API AnnotationOperator : public Operator
1747 {
1748 public:
1749  AnnotationOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1750 
1752  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_AnnotationOperator"; }
1753 
1754  virtual void OnViewAttached() OVERRIDE;
1755  virtual void OnViewDetached() OVERRIDE;
1756 
1764  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1765 
1771  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1772 
1773 
1781  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1782 
1786  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
1787 
1792  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
1793 
1794 
1799  virtual bool OnKeyDown(KeyboardState const & in_state) OVERRIDE;
1800 
1805  virtual bool OnTextInput(HPS::UTF8 const & in_text) OVERRIDE;
1806 
1814  void SetBackgroundShape(const char * in_shape);
1815 
1819  UTF8 GetBackgroundShape() const;
1820 
1824  class SPRK_OPS_API AnnotationInsertedEvent : public HPS::Event
1825  {
1826  public:
1829  {
1830  channel = GetClassID();
1831  consumable = false;
1832  }
1833 
1834  AnnotationInsertedEvent(HPS::SegmentKey const & in_text_key, HPS::View const & in_view) : Event()
1835  {
1836  channel = GetClassID();
1837  consumable = false;
1838  text_key = in_text_key;
1839  view = in_view;
1840  }
1841 
1844  AnnotationInsertedEvent(Event const & in_event) : Event(in_event)
1845  {
1846  if (in_event.GetChannel() == Object::ClassID<AnnotationInsertedEvent>())
1847  {
1848  auto that = static_cast<AnnotationInsertedEvent const &>(in_event);
1849  text_key = that.text_key;
1850  view = that.view;
1851  }
1852  else
1853  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1854  }
1855 
1857 
1860  Event * Clone() const
1861  {
1862  AnnotationInsertedEvent * new_event = new AnnotationInsertedEvent(*this);
1863  return new_event;
1864  }
1865 
1866  SegmentKey text_key; //the key of the segment containing the annotation
1867  View view;
1868  };
1869 
1870 private:
1871  void AddAnnotationUserData();
1872  void StartNewNote();
1873 
1874  bool InputDown(WindowKey const & window_key, Point const & location, KeyPath & event_path);
1875  bool InputMove(Point const & location, KeyPath & event_path);
1876 
1877  void CenterCamera(Point const & camera_center);
1878  void ResetCamera();
1879 
1880  class KeyboardHiddenEventHandler : public EventHandler
1881  {
1882  public:
1883  KeyboardHiddenEventHandler()
1884  : EventHandler()
1885  { }
1886 
1887  virtual ~KeyboardHiddenEventHandler()
1888  { Shutdown(); }
1889 
1890  virtual HandleResult Handle(Event const * /*in_event*/)
1891  {
1892  annotation_operator->keyboard_active = false;
1893 
1894  annotation_operator->ResetCamera();
1895  return HandleResult::Handled;
1896  }
1897 
1898  void SetOperator(AnnotationOperator * in_operator) { annotation_operator = in_operator; }
1899 
1900  private:
1901  AnnotationOperator * annotation_operator;
1902  };
1903 
1904 
1905  SegmentKey annotation_segment; //segment containing all annotations
1906  View last_attached_view; //the last view that was attached to this operator
1907  SelectionOptionsKit selection_options; //selection options used to select geometry
1908  SelectionOptionsKit annotation_selection_options; //selection options used when trying to select annotations
1909  bool editing_text; //whether we are in a state which allows editing of an annotation
1910  bool start_new_note; //whether we should delete the text of an annotation when typing
1911  UTF8 annotation_user_data; //the user data set on annotation geometry to distinguish it from non annotation geometry
1912  UTF8 annotation_shape; //the name of the shape definition used to draw the annotation background
1913 
1914  PortfolioKey current_portfolio; //the portfolio used to store the default definitions used by this operator
1915  SegmentKey highlight_style_segment; //the highlight background style
1916 
1917  RGBColor background_color; //the color of the annotation background
1918  RGBColor leader_line_color; //the color of the annotation leader line and edges
1919  RGBColor highlight_color; //the color the annotation becomes while it is being edited
1920 
1921  TextKey text_to_edit; //the annotation text which we are working on
1922  SizeTArray text_columns; //the number of columns of the text for the current annotation
1923  size_t current_text_row; //the number of rows of the text for the current annotation
1924 
1925  //touch only flags -- these flags are only relevant when running the operator on a touch enabled device
1926  TouchID tracked_touch_id; //the ID of the touch we are tracking
1927  bool keyboard_active; //whether the software keyboard is visible
1928  CameraKit original_camera; //the camera setting as they were just before the annotation text is edited
1929  KeyboardHiddenEventHandler handler; //a handler that takes care of resetting the camera when the software keyboard is hidden
1930  Point touch_down_position; //the position the last touch down occurred at
1931  bool always_show_keyboard_on_touch_up; //true if we are just inserting the annotation, false if we are editing a previously inserted one.
1932 };
1933 
1951 class SPRK_OPS_API HandlesOperator : public Operator
1952 {
1953 public:
1954  HandlesOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1955 
1956  enum class HandleType
1957  {
1958  Rotation,
1959  AxisTranslation,
1960  PlaneTranslation,
1961  CenterPoint,
1962  };
1963 
1965  virtual HPS::UTF8 GetName() const OVERRIDE { return "HPS_HandlesOperator"; }
1966 
1967  virtual void OnViewAttached() OVERRIDE;
1968  virtual void OnViewDetached() OVERRIDE;
1969 
1976  virtual bool OnMouseDown(MouseState const & in_state) OVERRIDE;
1977 
1982  virtual bool OnMouseMove(MouseState const & in_state) OVERRIDE;
1983 
1987  virtual bool OnMouseUp(MouseState const & in_state) OVERRIDE;
1988 
1995  virtual bool OnTouchDown(TouchState const & in_state) OVERRIDE;
1996 
2001  virtual bool OnTouchMove(TouchState const & in_state) OVERRIDE;
2002 
2006  virtual bool OnTouchUp(TouchState const & in_state) OVERRIDE;
2007 
2022  void SetHandlesColors(MaterialKitArray const & in_colors) { handles_colors = in_colors; }
2023 
2039  MaterialKitArray GetHandlesColors() const { return handles_colors; }
2040 
2044  void SetHighlightColor(RGBAColor const & in_highlight_color);
2045 
2048  RGBAColor GetHighlightColor() const { return highlight_color; }
2049 
2055  void SetHandlesAppearance(float in_length = 0.16f, float in_radius = 0.005f, size_t in_handles_points = 30);
2056 
2062  void SetRotationHandleAppearance(float in_offset = 0.045f, float in_angle = 25.0f, float in_tip_size = 0.15f);
2063 
2069  void SetPlaneTranslationAppearance(float in_plane_offset = 0.2f, float in_plane_length = 0.6f, float in_center_radius = 0.2f);
2070 
2075  void GetHandlesAppearance(float & out_length, float & out_radius, size_t & out_handles_points) const;
2076 
2081  void GetRotationHandleAppearance(float & out_offset, float & out_angle, float & out_tip_size) const;
2082 
2087  void GetPlaneTranslationAppearance(float & out_plane_offset, float & out_plane_length, float & out_center_radius) const;
2088 
2092  void SetTrailingGeometry(bool in_state) { display_trailing_geometry = in_state; }
2093 
2097  bool GetTrailingGeometry() const { return display_trailing_geometry; }
2098 
2102  void AddHandles(HandleType handle_type);
2103 
2107  void RemoveHandles(HandleType handle_type);
2108 
2109  class SPRK_OPS_API GeometryTransformedEvent : public HPS::Event
2110  {
2111  public:
2114  {
2115  channel = GetClassID();
2116  consumable = false;
2117  }
2118 
2119  GeometryTransformedEvent(HPS::View const & in_view, HPS::SegmentKey const & in_segment_key, HPS::MatrixKit const & in_transform) : Event()
2120  {
2121  channel = GetClassID();
2122  consumable = false;
2123  view = in_view;
2124  segment_key = in_segment_key;
2125  transform = in_transform;
2126  }
2127 
2130  GeometryTransformedEvent(Event const & in_event) : Event(in_event)
2131  {
2132  if (in_event.GetChannel() == Object::ClassID<GeometryTransformedEvent>())
2133  {
2134  auto that = static_cast<GeometryTransformedEvent const &>(in_event);
2135  view = that.view;
2136  segment_key = that.segment_key;
2137  transform = that.transform;
2138  }
2139  else
2140  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
2141  }
2142 
2144 
2147  Event * Clone() const
2148  {
2149  GeometryTransformedEvent * new_event = new GeometryTransformedEvent(*this);
2150  return new_event;
2151  }
2152 
2153  SegmentKey segment_key;
2154  MatrixKit transform;
2155  View view;
2156  };
2157 
2158 private:
2159  enum class Movement
2160  {
2161  None,
2162  Translation,
2163  Rotation,
2164  PlaneTranslation,
2165  };
2166 
2167  enum InternalHandleType : size_t
2168  {
2169  rotation = 0,
2170  axis_translation,
2171  plane_translation,
2172  center_point_translation,
2173  last = center_point_translation,
2174  };
2175 
2176  CanvasArray canvases; //A list of Canvas objects that the View attached to this operator belongs to. This value only gets updated on OnViewAttached.
2177  View last_attached_view; //The last View to where this operator was pushed.
2178  TouchID tracked_touch_id;
2179 
2180  SegmentKey handles; //top level segment
2181  SegmentKey handles_segment; //segment where the matrices for the handles transformations are accumulated
2182  SegmentKey handles_geometry; //segment where the handles geometry lives
2183  SegmentKey center_sphere;
2184  SegmentKey reference_segment; //segment containing all the net attributes of segment_to_move
2185  SegmentKey segment_to_move; //segment containing geometry affected by the handles
2186  SegmentKey temporary_segment_to_move; //segment where we accumulate changes while the handles are active
2187  SegmentKey handles_trail; //segment containing the trailing geometry
2188  KeyPath path_to_segment_to_move;
2189 
2190  std::vector<bool> requested_handle_type;
2191  std::vector<bool> current_handle_type;
2192 
2193  WorldPoint handles_origin_point;
2194  WorldPoint movement_start_point;
2195  Point input_down_position;
2196 
2197  Camera::Projection camera_projection;
2198 
2199  SelectionOptionsKit geometry_selection_options;
2200  SelectionOptionsKit handles_selection_options;
2201 
2202  HighlightOptionsKit hide_highlight_options;
2203  HighlightOptionsKit partial_transparency_options;
2204  HighlightOptionsKit highlight_options;
2205  SegmentKey style_segment;
2206  SegmentKey transparency_style_segment;
2207  UTF8 style_name;
2208  bool something_is_highlighted;
2209  MaterialKitArray handles_colors;
2210  RGBAColor highlight_color;
2211  Key highlighted_handle;
2212 
2213  //state flags
2214  bool are_handles_on;
2215  bool remove_handles;
2216  Movement move_geometry;
2217  Movement previous_movement;
2218  Vector movement_direction;
2219  Plane movement_plane;
2220  Vector base_vector;
2221 
2222  //handles appearance
2223  float handles_length; //Length of the handles. Expressed in percentage of screen [0 - 1]
2224  float handles_radius; //Radius of the handles. Expressed in percentage of screen [0 - 1]
2225  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].
2226  float arc_angle; //The angle formed by the arc handles. Must be greater than zero.
2227  size_t arc_points; //The number of points used to draw the arc handles.
2228  float tip_size; //The size of the tips at the end of the handles, specified as a percentage of the handles length
2229  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.
2230  float plane_length; //The length of the plane translation handle, specified as a percentage of handles_length.
2231  float center_radius;
2232 
2233  //handle geometry
2234  CylinderKey x;
2235  CylinderKey y;
2236  CylinderKey z;
2237  CylinderKey arc_x;
2238  CylinderKey arc_y;
2239  CylinderKey arc_z;
2240  ShellKey xy;
2241  ShellKey xz;
2242  ShellKey yz;
2243  SphereKey center;
2244 
2245  //trailing geometry
2246  bool display_trailing_geometry;
2247  Point trailing_line_start;
2248  Point trailing_circle_start;
2249  Point trailing_circle_center;
2250  Vector trailing_rotation;
2251  MarkerKey trail_marker;
2252  LineKey trailing_line;
2253  CircularArcKey trailing_circle;
2254  float rotation_direction;
2255 
2256  bool InputDown(size_t in_click_count, WindowKey const & in_window, KeyArray const & in_event_path, Point const & in_location);
2257  bool InputMove(KeyPath const & in_path, Point const & in_location);
2258  void InputUp(Point const & in_location);
2259 
2260  void InsertHandles();
2261  void InsertRotationHandles();
2262  void InsertAxisTranslationHandles();
2263  void InsertPlaneTranslationHandles();
2264  void InsertCenterPoint();
2265 
2266  void RemoveHandles();
2267 
2268  bool HighlightHandles(WindowKey & in_window, KeyArray const & in_event_path, Point const & in_location);
2269 
2270  //moves the geometry affected by handles into a new segment, and hides the original
2271  void ReferenceGeometry(KeyPath const & in_path);
2272 
2273  //copies the accumulated transform from the reference geometry segment back into the original place.
2274  //removes the hide highlight from the original geometry
2275  void CommitChanges();
2276 };
2277 
2278 }
2279 #endif
2280 
2281 
Definition: hps.h:6114
Event * Clone() const
Definition: sprk_ops.h:1860
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:520
MarkupInsertedEvent(Event const &in_event)
Definition: sprk_ops.h:1618
Definition: sprk.h:264
bool GetSectioning()
Definition: sprk_ops.h:1382
An InvalidSpecificationException is thrown when a method is called with non-sensical or contradictory...
Definition: hps.h:5732
SegmentKey GetSegmentKey()
Definition: sprk_ops.h:1589
static MouseButtons ButtonRight()
Definition: hps.h:46652
Definition: sprk_ops.h:1039
Definition: sprk_ops.h:282
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:195
Event * Clone() const
Definition: sprk_ops.h:2147
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1965
RGBAColor GetHighlightColor() const
Definition: sprk_ops.h:2048
Definition: hps.h:36623
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:484
Definition: sprk_ops.h:406
HPS::SelectionOptionsKit GetSelectionOptions() const
Definition: sprk_ops.h:539
void SetMarkupType(MarkupType in_markup_type)
Definition: sprk_ops.h:1563
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1045
Definition: hps.h:47139
Definition: hps.h:7612
Definition: sprk_ops.h:67
AnnotationInsertedEvent()
Definition: sprk_ops.h:1828
Definition: hps.h:3523
Definition: hps.h:6482
ZoomType
Definition: sprk_ops.h:584
void SetIndicatorScale(float in_scale)
Definition: sprk_ops.h:1349
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:250
Definition: hps.h:15878
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:467
HPS::SelectionOptionsKit GetSelectionOptions() const
Definition: sprk_ops.h:446
Definition: sprk_ops.h:624
GeometryTransformedEvent(Event const &in_event)
Definition: sprk_ops.h:2130
void SetPlaneHighlightOptions(HighlightOptionsKit const &in_highlight_options)
Definition: sprk_ops.h:1365
Definition: sprk_ops.h:503
Definition: sprk_ops.h:190
TextAttributeKit GetTextAttributes()
Definition: sprk_ops.h:1574
GeometryTransformedEvent()
Definition: sprk_ops.h:2113
Definition: hps.h:1538
Definition: hps.h:8819
void SetLineAttribute(LineAttributeKit const &in_line_attributes)
Definition: sprk_ops.h:1584
Definition: sprk_ops.h:335
Definition: sprk_ops.h:1598
Definition: sprk_ops.h:688
HPS::Rectangle GetInnerWindowRectangle() const
Definition: sprk_ops.h:362
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:534
Definition: sprk_ops.h:1269
Definition: sprk_ops.h:1951
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1752
Definition: hps.h:47038
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:339
Definition: sprk_ops.h:732
Definition: sprk_ops.h:456
std::vector< MaterialKit, Allocator< MaterialKit > > MaterialKitArray
Array of type HPS::MaterialKit.
Definition: hps.h:6557
Definition: hps.h:32469
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:423
Definition: hps.h:4424
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:596
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:971
Definition: sprk_ops.h:1487
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:141
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:693
bool GetTrailingGeometry() const
Definition: sprk_ops.h:2097
AnnotationInsertedEvent(Event const &in_event)
Definition: sprk_ops.h:1844
bool GetIndicatorVisibility()
Definition: sprk_ops.h:1391
bool IsMarkupActive()
Definition: sprk_ops.h:1596
Definition: hps.h:4363
RGBColor GetColor()
Definition: sprk_ops.h:1567
Definition: hps.h:6985
Definition: hps.h:46530
Definition: hps.h:26485
Definition: hps.h:43550
Definition: hps.h:5948
Definition: hps.h:45437
Definition: hps.h:42704
Definition: hps.h:46926
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:387
void SetTrailingGeometry(bool in_state)
Definition: sprk_ops.h:2092
Definition: sprk_ops.h:551
Definition: hps.h:15271
intptr_t GetChannel() const
Definition: hps.h:6231
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1284
Definition: hps.h:14523
Definition: hps.h:43827
Definition: hps.h:46049
Projection
Definition: hps.h:1415
bool GetMouseOverHighlighting() const
Definition: sprk_ops.h:1369
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:560
Definition: hps.h:6198
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:441
Definition: hps.h:13532
virtual bool OnKeyDown(KeyboardState const &in_state)
Definition: sprk_ops.h:1057
void SetMouseOverHighlighting(bool in_enable_mouse_over_highlighting)
Definition: sprk_ops.h:1373
Definition: sprk_ops.h:239
LineAttributeKit GetLineAttributes()
Definition: sprk_ops.h:1581
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:479
float GetIndicatorScale() const
Definition: sprk_ops.h:1345
Definition: sprk_ops.h:1746
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:573
Definition: hps.h:45363
std::vector< Key, Allocator< Key > > KeyArray
Array of type HPS::Key.
Definition: hps.h:6550
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:287
std::vector< Plane, Allocator< Plane > > PlaneArray
Array of type HPS::Plane.
Definition: hps.h:6533
Definition: sprk_ops.h:581
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:629
Definition: sprk_ops.h:965
Handedness
Definition: hps.h:1275
static MouseButtons ButtonLeft()
Definition: hps.h:46648
static MouseButtons ButtonMiddle()
Definition: hps.h:46656
Definition: hps.h:8969
static ModifierKeys KeyControl()
Definition: hps.h:46253
MaterialMappingKit GetPlaneMaterial() const
Definition: sprk_ops.h:1353
Definition: hps.h:7531
HPS::Rectangle GetWindowRectangle() const
Definition: sprk_ops.h:357
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:72
Definition: hps.h:9189
Definition: hps.h:10733
void SetTextAttribute(TextAttributeKit const &in_text_attributes)
Definition: sprk_ops.h:1577
MaterialKitArray GetHandlesColors() const
Definition: sprk_ops.h:2039
Definition: hps.h:23666
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:737
Definition: hps.h:24026
Event * Clone() const
Definition: sprk_ops.h:1634
void SetColor(RGBColor const &in_color)
Definition: sprk_ops.h:1570
Definition: sprk.h:1093
Definition: sprk_ops.h:136
virtual HPS::UTF8 GetName() const OVERRIDE
Definition: sprk_ops.h:1501
virtual bool OnKeyUp(KeyboardState const &in_state)
Definition: sprk_ops.h:1061
HighlightOptionsKit GetPlaneHighlightOptions() const
Definition: sprk_ops.h:1361
Definition: hps.h:40244
MarkupInsertedEvent()
Definition: sprk_ops.h:1602
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:568
Definition: sprk_ops.h:383
std::vector< size_t, Allocator< size_t > > SizeTArray
Array of type size_t.
Definition: hps.h:6538