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 #include <set>
18 
19 namespace std
20 {
21  template<>
22  struct hash<HPS::RGBColor>
23  {
24  size_t operator()(HPS::RGBColor const & x) const
25  {
26  return (
27  (51 + std::hash<float>()(x.red)) * 51 + std::hash<float>()(x.green) * 51 + std::hash<float>()(x.blue));
28  }
29  };
30 }
31 
32 #ifdef _MSC_VER
33 #ifndef STATIC_APP
34 # ifdef SPRK_OPS
35 # define SPRK_OPS_API __declspec (dllexport)
36 # else
37 # define SPRK_OPS_API __declspec (dllimport)
38 # endif
39 #endif
40 #else
41 # include <stddef.h>
42 # if defined(LINUX_SYSTEM) && defined(SPRK_OPS)
43 # ifndef STATIC_APP
44 # define SPRK_OPS_API __attribute__ ((visibility ("default")))
45 # endif
46 # endif
47 #endif
48 
49 #ifndef SPRK_OPS_API
50 # define SPRK_OPS_API
51 #endif
52 
53 
54 namespace HPS
55 {
56 
68 class SPRK_OPS_API PanOrbitZoomOperator : public Operator
69 {
70 public:
71  PanOrbitZoomOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
73  virtual HPS::UTF8 GetName() const { return "HPS_PanOrbitZoomOperator"; }
74 
79  virtual bool OnMouseDown(MouseState const & in_state);
84  virtual bool OnMouseUp(MouseState const & in_state);
89  virtual bool OnMouseMove(MouseState const & in_state);
90 
95  virtual bool OnTouchDown(TouchState const & in_state);
100  virtual bool OnTouchUp(TouchState const & in_state);
105  virtual bool OnTouchMove(TouchState const & in_state);
106 
107 private:
108  HPS::WorldPoint start;
109 
110  HPS::WindowPoint start_point, new_point;
111  HPS::Vector start_sphere_pos, new_sphere_pos;
112 
113  bool operator_active;
114  float zoom_limit;
115  float focal_length;
116  HPS::WindowPoint last_zoom;
117  HPS::Vector last_relative;
118  float zoom_start_field_width;
119  float zoom_start_field_height;
120  HPS::Vector zoom_start_camera_look;
121  size_t current_touches;
122 
123  void ZoomStart();
124  void UpdateZoom(float zoom_factor);
125  void UpdateZoomLimit();
126  void UpdatePan(HPS::WorldPoint const & newLocation);
127  void UpdateRoll(HPS::Vector const & relative);
128 };
129 
137 class SPRK_OPS_API PanOperator : public Operator
138 {
139 public:
140  PanOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
142  virtual HPS::UTF8 GetName() const { return "HPS_PanOperator"; }
143 
148  virtual bool OnMouseDown(MouseState const & in_state);
153  virtual bool OnMouseUp(MouseState const & in_state);
158  virtual bool OnMouseMove(MouseState const & in_state);
159 
164  virtual bool OnTouchDown(TouchState const & in_state);
169  virtual bool OnTouchUp(TouchState const & in_state);
174  virtual bool OnTouchMove(TouchState const & in_state);
175 
176 private:
177  bool PanCommon(HPS::WindowPoint const & in_loc, HPS::KeyPath const & in_key_path);
178 
179  bool operator_active;
180  HPS::TouchID tracked_touch_ID;
181  HPS::WorldPoint start;
182 };
183 
191 class SPRK_OPS_API OrbitOperator : public Operator
192 {
193 public:
194  OrbitOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
196  virtual HPS::UTF8 GetName() const { return "HPS_OrbitOperator"; }
197 
202  virtual bool OnMouseDown(MouseState const & in_state);
207  virtual bool OnMouseUp(MouseState const & in_state);
212  virtual bool OnMouseMove(MouseState const & in_state);
213 
218  virtual bool OnTouchDown(TouchState const & in_state);
223  virtual bool OnTouchUp(TouchState const & in_state);
228  virtual bool OnTouchMove(TouchState const & in_state);
229 
230 private:
231  bool OrbitCommon(HPS::WindowPoint const & in_loc);
232 
233  bool operator_active;
234  HPS::TouchID tracked_touch_ID;
235  HPS::WindowPoint start_point, new_point;
236  HPS::Vector start_sphere_pos, new_sphere_pos;
237 };
238 
239 
240 class SPRK_OPS_API RelativeOrbitOperator : public Operator
241 {
242 
243 public:
250  RelativeOrbitOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonMiddle(), ModifierKeys in_modifier_trigger = ModifierKeys());
251  virtual HPS::UTF8 GetName() const { return "HPS_RelativeOrbitOperator"; }
252 
253  virtual bool OnMouseDown(MouseState const & in_state);
254  virtual bool OnMouseUp(MouseState const & in_state);
255  virtual bool OnMouseMove(MouseState const & in_state);
256 
257  virtual bool OnTouchDown(TouchState const & in_state);
258  virtual bool OnTouchUp(TouchState const & in_state);
259  virtual bool OnTouchMove(TouchState const & in_state);
260 
261  bool ShowCenterOfRotation(HPS::Point & out_point) const;
262 
263 private:
264  bool OrbitCommon(HPS::WindowPoint const & in_loc, HPS::CameraKit & out_camera);
265  bool RelativeOrbitCommon(HPS::WindowPoint const & in_loc, HPS::KeyPath & in_event_path);
266  void CalculateTarget(KeyArray const & in_event_path);
267 
268  HPS::Point center_of_rotation;
269  bool operator_active;
270  HPS::TouchID tracked_touch_ID;
271  HPS::Vector start_sphere_pos, new_sphere_pos;
272  HPS::WindowPoint start_point, new_point;
273  HPS::SelectionOptionsKit selection_options;
274 };
275 
283 class SPRK_OPS_API ZoomOperator : public Operator
284 {
285 public:
286  ZoomOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
288  virtual HPS::UTF8 GetName() const { return "HPS_ZoomOperator"; }
289 
294  virtual bool OnMouseDown(MouseState const & in_state);
299  virtual bool OnMouseUp(MouseState const & in_state);
304  virtual bool OnMouseMove(MouseState const & in_state);
305 
310  virtual bool OnTouchDown(TouchState const & in_state);
315  virtual bool OnTouchMove(TouchState const & in_state);
316 
317 private:
318  bool operator_active;
319  HPS::TouchID tracked_touch_ID;
320  HPS::WindowPoint start_point;
321  float zoom_limit;
322  float focal_length;
323  HPS::WindowPoint last_zoom;
324  HPS::Vector last_relative;
325  float zoom_start_field_width;
326  float zoom_start_field_height;
327  HPS::Vector zoom_start_camera_look;
328  HPS::Point zoom_start_camera_target;
329 
330  void ZoomStart();
331  void UpdateZoom(float zoom_factor);
332  void UpdateZoomLimit();
333 };
334 
335 
336 class SPRK_OPS_API ConstructRectangleOperator : public Operator
337 {
338 public:
339  ConstructRectangleOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys(), bool draw_faces = false);
340  virtual HPS::UTF8 GetName() const { return "HPS_ConstructRectangleOperator"; }
341 
342  virtual void OnViewAttached(HPS::View const & in_attached_view);
343 
344  virtual bool OnMouseDown(MouseState const & in_state);
345  virtual bool OnMouseUp(MouseState const & in_state);
346  virtual bool OnMouseMove(MouseState const & in_state);
347 
348  virtual bool OnTouchDown(TouchState const & in_state);
349  virtual bool OnTouchUp(TouchState const & in_state);
350  virtual bool OnTouchMove(TouchState const & in_state);
351 
352  bool IsRectangleValid() const { return is_rect_valid; }
353 
358  HPS::Rectangle GetWindowRectangle() const { return window_rect; }
363  HPS::Rectangle GetInnerWindowRectangle() const { return inner_window_rect; }
364 
365 private:
366  bool ConstructRectCommon(WindowPoint const & in_loc);
367  void SetupConstructionSegment();
368 
369  bool draw_faces;
370  bool use_center_marker;
371  bool is_rect_valid;
372  bool operator_active;
373  HPS::WindowPoint window_start_point;
374  HPS::WindowPoint inner_window_start_point;
375  HPS::SegmentKey scratch_seg;
376  HPS::Rectangle window_rect;
377  HPS::Rectangle inner_window_rect;
378  HPS::LineKey temp_line_key;
379  HPS::PolygonKey temp_polygon_key;
380  HPS::MarkerKey temp_marker_key;
381  HPS::TouchID tracked_touch_ID;
382 };
383 
384 class SPRK_OPS_API ZoomBoxOperator : public ConstructRectangleOperator
385 {
386 public:
387  ZoomBoxOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
388  virtual HPS::UTF8 GetName() const { return "HPS_ZoomBoxOperator"; }
389 
390  virtual bool OnMouseUp(MouseState const & in_state);
391  virtual bool OnTouchUp(TouchState const & in_state);
392 
393 private:
394  bool ZoomCommon(HPS::WindowKey const & in_window, HPS::KeyPath const & in_event_path);
395 
396 };
397 
408 {
409 public:
422  SelectAreaOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
423 
424  virtual HPS::UTF8 GetName() const { return "HPS_SelectAreaOperator"; }
425 
426  virtual void OnViewAttached(HPS::View const & in_attached_view);
427 
428  virtual bool OnMouseUp(MouseState const & in_state);
429  virtual bool OnTouchUp(TouchState const & in_state);
430 
435  HPS::SelectionResults GetActiveSelection() const;
436 
442  void SetSelectionOptions(HPS::SelectionOptionsKit const & in_options) { selection_options = in_options; }
443 
447  HPS::SelectionOptionsKit GetSelectionOptions() const { return selection_options; }
448 
449 private:
450  bool SelectCommon(HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers = HPS::ModifierKeys());
451 
452  HPS::SelectionResults active_selection;
453  HPS::SelectionOptionsKit selection_options;
454 };
455 
456 
457 class SPRK_OPS_API HighlightAreaOperator : public SelectAreaOperator
458 {
459 public:
466  HighlightAreaOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
467 
468  virtual HPS::UTF8 GetName() const { return "HPS_HighlightAreaOperator"; }
469 
470  virtual void OnViewAttached(HPS::View const & in_attached_view);
471 
472  virtual bool OnMouseUp(MouseState const & in_state);
473  virtual bool OnTouchUp(TouchState const & in_state);
474 
480  void SetHighlightOptions(HPS::HighlightOptionsKit const & in_options) { highlight_options = in_options; }
481 
485  HPS::HighlightOptionsKit GetHighlightOptions() const { return highlight_options; }
486 
487 private:
488  bool HighlightCommon(WindowKey & in_window, ModifierKeys in_modifiers);
489 
490  HPS::HighlightOptionsKit highlight_options;
491 
492 };
493 
494 
504 class SPRK_OPS_API SelectOperator : public Operator
505 {
506 public:
519  SelectOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
520 
521  virtual HPS::UTF8 GetName() const { return "HPS_SelectOperator"; }
522 
523  virtual bool OnMouseDown(MouseState const & in_state);
524  virtual bool OnTouchDown(TouchState const & in_state);
525 
530  HPS::SelectionResults GetActiveSelection() const;
531 
535  void SetSelectionOptions(HPS::SelectionOptionsKit const & in_options) { selection_options = in_options; }
536 
540  HPS::SelectionOptionsKit GetSelectionOptions() const { return selection_options; }
541 
542 protected:
543  HPS::SelectionResults active_selection;
544 
545 private:
546  bool SelectCommon(HPS::Point const & in_loc, HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers = HPS::ModifierKeys());
547 
548  HPS::SelectionOptionsKit selection_options;
549 };
550 
551 
552 class SPRK_OPS_API HighlightOperator : public SelectOperator
553 {
554 public:
559  HighlightOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
560 
561  virtual HPS::UTF8 GetName() const { return "HPS_HighlightOperator"; }
562 
563  virtual bool OnMouseDown(MouseState const & in_state);
564  virtual bool OnTouchDown(TouchState const & in_state);
565 
569  void SetHighlightOptions(HPS::HighlightOptionsKit const & in_options) { highlight_options = in_options; }
570 
574  HPS::HighlightOptionsKit GetHighlightOptions() const { return highlight_options; }
575 
576 private:
577  bool HighlightCommon(HPS::WindowKey & in_window, HPS::ModifierKeys in_modifiers);
578 
579  HPS::HighlightOptionsKit highlight_options;
580 };
581 
582 class SPRK_OPS_API MouseWheelOperator : public Operator
583 {
584 public:
585  enum class ZoomType
586  {
587  Fast,
588  Accurate,
589  };
590 
595  MouseWheelOperator(ZoomType in_default_type = ZoomType::Accurate, HPS::ModifierKeys in_alternate_type_modifiers = HPS::ModifierKeys::KeyControl());
596 
597  virtual HPS::UTF8 GetName() const { return "HPS_MouseWheelOperator"; }
598 
600  void UpdateZoomLimit();
601 
602  virtual bool OnMouseWheel(HPS::MouseState const & in_state);
603 
604  virtual void OnModelAttached();
605 
606  virtual void OnViewAttached(HPS::View const & in_attached_view);
607 
608 private:
609  float zoom_limit;
610  ZoomType zoom_type;
611  HPS::ModifierKeys zoom_modifier;
612 };
613 
625 class SPRK_OPS_API TurntableOperator : public Operator
626 {
627 public:
628  TurntableOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
630  virtual HPS::UTF8 GetName() const { return "HPS_TurntableOperator"; }
631 
637  virtual bool OnMouseDown(MouseState const & in_state);
642  virtual bool OnMouseUp(MouseState const & in_state);
647  virtual bool OnMouseMove(MouseState const & in_state);
652  virtual bool OnMouseWheel(MouseState const & in_state);
653 
659  virtual bool OnTouchDown(TouchState const & in_state);
664  virtual bool OnTouchUp(TouchState const & in_state);
670  virtual bool OnTouchMove(TouchState const & in_state);
671 
672 private:
673  void TurntableCommon(HPS::WindowPoint const & delta, HPS::Vector const & rotation_axis);
674  void CalculateCenterPoint(HPS::WindowKey const & window, HPS::Point const & location);
675 
676  bool operator_active;
677  bool center_point_set;
678  HPS::WorldPoint center_point;
679  HPS::TouchID tracked_touch_ID;
680  HPS::WindowPoint start_point;
681  HPS::SelectionOptionsKit selection_options;
682 };
683 
689 class SPRK_OPS_API ZoomFitTouchOperator : public Operator
690 {
691 public:
694  virtual HPS::UTF8 GetName() const { return "HPS_ZoomFitTouchOperator"; }
695 
700  virtual bool OnTouchDown(TouchState const & in_state);
705  virtual bool OnTouchUp(TouchState const & in_state);
706 
707 private:
708  HPS::TouchID tracked_touch_ID;
709 };
710 
733 class SPRK_OPS_API FlyOperator : public Operator
734 {
735 public:
736  FlyOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
738  virtual HPS::UTF8 GetName() const { return "HPS_FlyOperator"; }
739 
754  virtual bool OnKeyDown(KeyboardState const & in_state);
758  virtual bool OnKeyUp(KeyboardState const & in_state);
759 
764  virtual bool OnMouseDown(MouseState const & in_state);
768  virtual bool OnMouseUp(MouseState const & in_state);
773  virtual bool OnMouseMove(MouseState const & in_state);
779  virtual bool OnMouseWheel(MouseState const & in_state);
780 
785  virtual bool OnTouchDown(TouchState const & in_state);
789  virtual bool OnTouchUp(TouchState const & in_state);
794  virtual bool OnTouchMove(TouchState const & in_state);
795 
800  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
801 
804  virtual void OnModelAttached();
805 
807  virtual void OnViewAttached(HPS::View const & in_attached_view);
808 
810  virtual void OnViewDetached(HPS::View const & in_detached_view);
811 
812  /* getters/setters for inverting the X and Y axis */
813  void InvertXAxis() { invert_x_axis = !invert_x_axis;}
814  void InvertYAxis() { invert_y_axis = !invert_y_axis;}
815  bool IsXAxisInverted() const { return invert_x_axis; }
816  bool IsYAxisInverted() const { return invert_y_axis; }
817 
818  /* getters/setters for sensitivity */
819  /* Keyboard sensitivity affects the speed of movement of action triggered from the keyboard, such as walking forward by pressing W */
820  float GetKeyboardSensitivity() const { return keyboard_sensitivity; }
821  void SetKeyboardSensitivity(float in_keyboard_sensitivity) { keyboard_sensitivity = in_keyboard_sensitivity; }
822 
823  /* Mouse sensitivity affects the speed of movement of action triggered from the mouse, such as rotating */
824  float GetMouseSensitivity() const { return mouse_sensitivity; }
825  void SetMouseSensitivity(float in_mouse_sensitivity) { mouse_sensitivity = in_mouse_sensitivity; }
826 
827  /* Left Joystick sensitivity affects the speed of movement of action triggered from the left joystick on touch devices */
828  float GetLeftJoystickSensitivity() const { return left_joystick_sensitivity; }
829  void SetLeftJoystickSensitivity(float in_left_joystick_sensitivity) { left_joystick_sensitivity = in_left_joystick_sensitivity; }
830 
831  /* Right Joystick sensitivity affects the speed of movement of action triggered from the right joystick on touch devices */
832  float GetRightJoystickSensitivity() const { return right_joystick_sensitivity; }
833  void SetRightJoystickSensitivity(float in_right_joystick_sensitivity) { right_joystick_sensitivity = in_right_joystick_sensitivity; }
834 
835  /* getters/setters for joystick dead zone
836  The dead zone is an area around the initial touch down position where the user can move its finger
837  without triggering any movement.
838  The default value is 0.07. */
839  float GetJoystickDeadZone() const { return joystick_dead_zone; }
840  void SetJoystickDeadZone(float in_dead_zone) { joystick_dead_zone = in_dead_zone; }
841 
842  float GetSceneExtents() const { return scene_extents; }
843 
844 protected:
845 
846  enum MovementFlags
847  {
848  no_movement = 0x0000,
849  moving_forward = 0x0001,
850  moving_back = 0x0002,
851  moving_left = 0x0004,
852  moving_right = 0x0008,
853  moving_up = 0x0010,
854  moving_down = 0x0020,
855  roll_left = 0x0040,
856  roll_right = 0x0080,
857  rotating = 0x0100,
858  move_with_touch = 0x0200,
859  rotate_with_touch = 0x0400
860  };
861 
862  unsigned int movement_flags;
863 
864  //movement functions
865  void MoveLeft(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
866  void MoveRight(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
867  void MoveUp(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
868  void MoveDown(HPS::Point & position, HPS::Point & target, HPS::Vector & up);
869  void MoveForward(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
870  void MoveBack(HPS::Point & position, HPS::Point & target, HPS::Vector const & direction);
871  bool MoveWithTouch(HPS::Point & position, HPS::Point & target, HPS::Vector & up, HPS::Vector const & walking_direction);
872  bool RotateScene(HPS::Point & position, HPS::Point & target);
873  bool RotateWithTouch(HPS::Point & position, HPS::Point & target);
874  void RotateCommon(HPS::Point const & delta, HPS::Point & position, HPS::Point & target);
875 
876 private:
877 
878  enum class TouchPosition
879  {
880  Left,
881  Right,
882  None
883  };
884 
885  //touch IDs tracked by the operator
886  HPS::TouchID left_side_touch;
887  HPS::TouchID right_side_touch;
888  HPS::TouchID second_right_touch;
889 
890  //current and start location for touch operations
891  HPS::WindowPoint start_point;
892  HPS::WindowPoint left_start_point;
893  HPS::WindowPoint right_start_point;
894  HPS::WindowPoint current_right_touch_position;
895  HPS::WindowPoint second_right_start_point;
896  HPS::WindowPoint current_second_right_touch_position;
897  HPS::WindowPoint start_mid_point;
898 
899  //virtual joystick information
900  HPS::SegmentKey left_joystick_segment;
901  HPS::SegmentKey right_joystick_segment;
902  float joystick_dead_zone;
903 
904  //step length for left touch, right touch, and desktop operation
905  float keyboard_sensitivity;
906  float old_keyboard_sensitivity;
907  float left_joystick_sensitivity;
908  float old_left_joystick_sensitivity;
909  float right_joystick_sensitivity;
910  float old_right_joystick_sensitivity;
911  float mouse_sensitivity;
912  float scene_extents;
913 
914  //operator state flags
915  bool two_right_fingers_down;
916  bool invert_x_axis;
917  bool invert_y_axis;
918  Drawing::Handedness world_handedness;
919  bool shift_pressed;
920  bool ctrl_pressed;
921  HPS::KeyPath event_path;
922  HPS::WindowPoint rotation_location;
923  HPS::WindowPoint moving_position;
924 
925  //utility functions
926  void UpdateKeyboardState(KeyboardState const & in_state);
927  float CalculateSceneExtents();
928  void ComputeReasonableStepLength();
929  void CreateJoystick(HPS::TouchState const & in_state, TouchPosition touch_position);
930 };
931 
966 class SPRK_OPS_API WalkOperator : public FlyOperator
967 {
968 public:
969  WalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonRight(), ModifierKeys in_modifier_trigger = ModifierKeys());
970 
972  virtual HPS::UTF8 GetName() const { return "HPS_WalkOperator"; }
973 
976  virtual void OnModelAttached();
977 
979  virtual void OnViewAttached(HPS::View const & in_attached_view);
980 
985  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
986 
987  /* Getters / Setters for the plane the operator walks on. */
988  void SetGroundPlane(HPS::Plane const & in_plane) { ground = in_plane; }
989  HPS::Plane GetGroundPlane() const { return ground; }
990 
991  /* Getters / Setters for camera vertical offset from the ground plane */
992  void SetWalkerHeight(float height) { height_off_ground = height; }
993  float GetWalkerHeight() const { return height_off_ground; }
994 
995  /* An enumeration for the direction of a vector. */
996  enum class Axis { X, Y, Z, Negative_X, Negative_Y, Negative_Z };
997  static Axis GetPrimaryAxis(HPS::Vector const & v);
998 
999  /* Returns the primary direction of the camera Up vector. */
1000  Axis GetPrimaryUpAxis() const { return primary_up_axis; }
1001 
1002  Axis UpdatePrimaryUpAxis(HPS::Vector const & v);
1003 
1004 private:
1005  HPS::Plane ground;
1006  HPS::Vector walking_direction;
1007  float height_off_ground;
1008 
1009  Axis primary_up_axis;
1010 
1011  void CalculateGroundPlane();
1012  void SnapToPlane();
1013  void AdjustWalkingDirection(HPS::Vector const & camera_direction, HPS::Vector const & camera_up);
1014 };
1015 
1040 class SPRK_OPS_API SimpleWalkOperator : public WalkOperator
1041 {
1042 public:
1043  SimpleWalkOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1044 
1046  virtual HPS::UTF8 GetName() const { return "HPS_SimpleWalkOperator"; }
1047 
1050  virtual void OnModelAttached();
1051 
1053  virtual void OnViewAttached(HPS::View const & in_attached_view);
1054 
1058  virtual bool OnKeyDown(KeyboardState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1062  virtual bool OnKeyUp(KeyboardState const & in_state) { HPS_UNREFERENCED(in_state); return false; }
1066  virtual bool OnMouseWheel(MouseState const & in_state);
1067 
1072  virtual bool OnMouseDown(MouseState const & in_state);
1077  virtual bool OnMouseMove(MouseState const & in_state);
1081  virtual bool OnMouseUp(MouseState const & in_state);
1085  virtual bool OnMouseEnter(MouseState const & in_state);
1089  virtual bool OnMouseLeave(MouseState const & in_state);
1090 
1094  virtual bool OnTouchDown(TouchState const & in_state);
1098  virtual bool OnTouchMove(TouchState const & in_state);
1101  virtual bool OnTouchUp(TouchState const & in_state);
1102 
1107  virtual bool OnTimerTick(HPS::TimerTickEvent const & in_event);
1108 
1113  void SetKeyboardShiftKey(bool in_state);
1114 
1119  void SetKeyboardControlKey(bool in_state);
1120 
1125  void SetEnableMiddleMouseButtonDolly(bool in_enable);
1126 
1131  bool GetEnableMiddleMouseButtonDolly() const;
1132 
1136  bool IsMouseTriggered(MouseState const & in_state);
1137 
1138 private:
1139  class ScaleFactor
1140  {
1141  public:
1142  float time;
1143  float forward, horizontal, vertical;
1144  float roll, pitch, yaw;
1145  ScaleFactor(float time) : time(time),
1146  forward(1), horizontal(1), vertical(1),
1147  roll(1), pitch(1), yaw(1) {}
1148 
1149  void SetTime(float t) { time = t; }
1150  void SetForward(float f) { forward=f; }
1151  void SetHorizontal(float h) { horizontal = h; }
1152  void SetVertical(float v) { vertical = v; }
1153  void SetRoll(float r) { roll = r; }
1154  void SetPitch(float p) { pitch = p; }
1155  void SetYaw(float y) { yaw = y; }
1156 
1157  float GetTime() const { return time; }
1158  float GetForward() const { return forward; }
1159  float GetHorizontal() const { return horizontal; }
1160  float GetVertical() const { return vertical; }
1161  float GetRoll() const { return roll; }
1162  float GetPitch() const { return pitch; }
1163  float GetYaw() const { return yaw; }
1164 
1165  float Forward() const { return forward*time; }
1166  float Horizontal() const { return horizontal*time; }
1167  float Vertical() const { return vertical*time; }
1168  float Roll() const { return roll*time; }
1169  float Pitch() const { return pitch*time; }
1170  float Yaw() const { return yaw*time; }
1171  };
1172 
1173  void Pan(float in_theta, float in_phi);
1174  void Dolly(float in_right, float in_up, float in_forward);
1175  void ResetCamera(HPS::CameraKit & camera) const;
1176  float CalculatePitch(HPS::CameraKit & camera) const;
1177  bool NotableCameraDifference(HPS::CameraKit const & camera1, HPS::CameraKit const & camera2);
1178 
1179  int DirectionForward() const { return 0x1; }
1180  int DirectionHorizontal() const { return 0x2; }
1181  int DirectionVertical() const { return 0x4; }
1182  int DirectionRoll() const { return 0x8; }
1183  int DirectionPitch() const { return 0x10; }
1184  int DirectionYaw() const { return 0x20; }
1185 
1186  bool Move(HPS::Point const & start, HPS::Point const & current, int directions, HPS::CameraKit & camera, ScaleFactor const & scale);
1187 
1188  void Init();
1189 
1190  HPS::WindowPoint mouse_current_point;
1191  HPS::WindowPoint mouse_start_point;
1192  bool mouse_operator_started;
1193  bool mouse_moving;
1194  bool middle_mouse_button_active;
1195 
1196  HPS::WindowPoint touch_current_point;
1197  HPS::WindowPoint touch_start_point;
1198  bool touch_operator_started;
1199  bool touch_moving;
1200  bool double_touch_active;
1201  HPS::Touch touch1, touch2;
1202 
1203  bool keybrd_control;
1204  bool keybrd_shift;
1205  bool enable_middle_button_dolly;
1206  HPS::UpdateNotifier last_notifier;
1207  bool pending_camera_valid;
1208  HPS::CameraKit pending_camera;
1209  HPS::CameraKit last_camera;
1210 };
1211 
1212 
1270 class SPRK_OPS_API CuttingSectionOperator : public SelectOperator
1271 {
1272 private:
1273  enum class OpState
1274  {
1275  Uninitialized,
1276  Initialized,
1277  Translating,
1278  FacePicking,
1279  };
1280 
1281 public:
1282  CuttingSectionOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1283 
1285  virtual HPS::UTF8 GetName() const { return "HPS_CuttingSectionOperator"; }
1286 
1287  virtual void OnModelAttached();
1288  virtual void OnViewAttached(HPS::View const & in_attached_view);
1289  virtual void OnViewDetached(HPS::View const & in_detached_view);
1290 
1295  void SetPlanes(PlaneArray const & in_planes);
1296 
1299  PlaneArray GetPlanes();
1300 
1306  virtual bool OnMouseDown(MouseState const & in_state);
1307 
1311  virtual bool OnMouseUp(MouseState const & in_state);
1312 
1318  virtual bool OnMouseMove(MouseState const & in_state);
1319 
1325  virtual bool OnTouchDown(TouchState const & in_state);
1326 
1330  virtual bool OnTouchUp(TouchState const & in_state);
1331 
1336  virtual bool OnTouchMove(TouchState const & in_state);
1337 
1342  virtual bool OnTimerTick(TimerTickEvent const & in_event);
1343 
1346  float GetIndicatorScale() const { return indicator_scale; }
1347 
1350  void SetIndicatorScale(float in_scale) { indicator_scale = in_scale; }
1351 
1354  MaterialMappingKit GetPlaneMaterial() const { return plane_material; }
1355 
1358  void SetPlaneMaterial(MaterialMappingKit const & in_plane_material);
1359 
1362  HighlightOptionsKit GetPlaneHighlightOptions() const { return highlight_options; }
1363 
1366  void SetPlaneHighlightOptions(HighlightOptionsKit const & in_highlight_options) { highlight_options = in_highlight_options; }
1367 
1370  bool GetMouseOverHighlighting() const { return enable_mouse_over_highlighting; }
1371 
1374  void SetMouseOverHighlighting(bool in_enable_mouse_over_highlighting) { enable_mouse_over_highlighting = in_enable_mouse_over_highlighting; }
1375 
1379  void SetSectioning(bool in_sectioning);
1380 
1383  bool GetSectioning() { return sectioning; }
1384 
1388  void SetIndicatorVisibility(bool in_use_indicator);
1389 
1392  bool GetIndicatorVisibility() { return (op_state == OpState::Uninitialized || op_state == OpState::FacePicking) ? true : false; }
1393 
1397  void SetPlaneVisibility(bool in_visibility);
1398 
1401  bool GetPlaneVisibility();
1402 
1403 private:
1404 
1405  void SetupOperatorSegment();
1406  void InsertNormalIndicator(float scale);
1407  ShellKey InsertCuttingPlaneGeometry();
1408  void MouseOverHighlighting(MouseState const & in_state);
1409  void TranslateCuttingPlane(KeyPath const & in_event_path, WindowPoint const & in_event_location);
1410  bool HandleMouseAndTouchDown(WindowKey const & in_event_source, size_t in_number_of_clicks,
1411  KeyPath const & in_event_path, WindowPoint const & in_event_location);
1412  void ViewAlignSectionPlanes(HPS::PlaneArray & in_out_planes) const;
1413  typedef std::pair<CuttingSectionKey, std::vector<ShellKey>> SectionInfo;
1414  typedef std::vector<SectionInfo> SectionArray;
1415  SectionArray sections;
1416 
1417  SegmentKey operator_root_segment;
1418  SegmentKey cutting_sections_segment;
1419  SegmentKey plane_representation_segment;
1420  bool sectioning;
1421 
1422  CuttingSectionKey translating_section;
1423  size_t translating_plane_offset;
1424  ShellKey translating_plane_representation;
1425 
1426  TouchID tracked_touch_ID;
1427  MaterialMappingKit plane_material;
1428  SegmentKey indicator_seg;
1429  OpState op_state;
1430  WorldPoint start_world_point;
1431  SelectionOptionsKit selection_options;
1432  SelectionOptionsKit mouse_over_selection_options;
1433  float indicator_scale;
1434  Vector plane_normal;
1435  bool plane_normal_valid;
1436  WorldPoint anchor_point;
1437  SimpleCuboid model_bounding;
1438 
1439  UpdateNotifier last_highlight_notifier;
1440  bool last_skipped_highlight_state_valid;
1441  MouseState last_skipped_highlight_state;
1442  bool is_plane_highlighted;
1443  PortfolioKey portfolio;
1444  SegmentKey style_segment;
1445  HighlightOptionsKit highlight_options;
1446  bool enable_mouse_over_highlighting;
1447  bool skip_mouse_overs;
1448 
1449  View attached_view;
1450  KeyArray navigation_keys;
1451 };
1452 
1488 class SPRK_OPS_API MarkupOperator : public Operator
1489 {
1490 public:
1491  enum class MarkupType
1492  {
1493  Freehand,
1494  Text,
1495  Circle,
1496  Rectangle,
1497  };
1498 
1499  MarkupOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1500 
1502  virtual HPS::UTF8 GetName() const override { return "HPS_MarkupOperator"; }
1503 
1504  virtual void OnViewAttached(HPS::View const & in_attached_view) override;
1505  virtual void OnViewDetached(HPS::View const & in_detached_view) override;
1506 
1511  virtual bool OnMouseDown(MouseState const & in_state) override;
1512 
1516  virtual bool OnMouseUp(MouseState const & in_state) override;
1517 
1524  virtual bool OnMouseMove(MouseState const & in_state) override;
1525 
1526 
1531  virtual bool OnTouchDown(TouchState const & in_state) override;
1532 
1536  virtual bool OnTouchUp(TouchState const & in_state) override;
1537 
1544  virtual bool OnTouchMove(TouchState const & in_state) override;
1545 
1551  virtual bool OnKeyDown(KeyboardState const & in_state) override;
1552 
1558  virtual bool OnTextInput(HPS::UTF8 const & in_text) override;
1559 
1561  MarkupType GetMarkupType() { return markup_type; }
1562 
1564  void SetMarkupType(MarkupType in_markup_type) { markup_type = in_markup_type; }
1565 
1568  RGBColor GetColor() { return current_attributes.color; }
1569 
1571  void SetColor(RGBColor const & in_color) { current_attributes.color = in_color; }
1572 
1575  TextAttributeKit GetTextAttributes() { return current_attributes.text_attributes; }
1576 
1578  void SetTextAttribute(TextAttributeKit const & in_text_attributes) { current_attributes.text_attributes = in_text_attributes; }
1579 
1582  LineAttributeKit GetLineAttributes() { return current_attributes.line_attributes; }
1583 
1585  void SetLineAttribute(LineAttributeKit const & in_line_attributes) {current_attributes.line_attributes = in_line_attributes; }
1586 
1590  SegmentKey GetSegmentKey() { return markup_segment; }
1591 
1593  void DeleteMarkups();
1594 
1597  bool IsMarkupActive() { return operator_active; }
1598 
1599  class SPRK_OPS_API MarkupInsertedEvent : public HPS::Event
1600  {
1601  public:
1604  {
1605  channel = GetClassID();
1606  consumable = false;
1607  }
1608 
1609  MarkupInsertedEvent(HPS::Key const & in_markup_key, HPS::View const & in_view) : Event()
1610  {
1611  channel = GetClassID();
1612  consumable = false;
1613  markup_key = in_markup_key;
1614  view = in_view;
1615  }
1616 
1619  MarkupInsertedEvent(Event const & in_event) : Event(in_event)
1620  {
1621  if (in_event.GetChannel() == Object::ClassID<MarkupInsertedEvent>())
1622  {
1623  auto that = static_cast<MarkupInsertedEvent const &>(in_event);
1624  markup_key = that.markup_key;
1625  view = that.view;
1626  }
1627  else
1628  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1629  }
1630 
1632 
1635  Event * Clone() const
1636  {
1637  MarkupInsertedEvent * new_event = new MarkupInsertedEvent(*this);
1638  return new_event;
1639  }
1640 
1641  Key markup_key;
1642  View view;
1643  };
1644 
1645 private:
1646  struct Attributes
1647  {
1648  RGBColor color;
1649  LineAttributeKit line_attributes;
1650  TextAttributeKit text_attributes;
1651  };
1652 
1653  class KeyboardHiddenEventHandler : public EventHandler
1654  {
1655  public:
1656  KeyboardHiddenEventHandler()
1657  : EventHandler()
1658  { }
1659 
1660  virtual ~KeyboardHiddenEventHandler()
1661  { Shutdown(); }
1662 
1663  virtual HandleResult Handle(Event const * /*in_event*/)
1664  {
1665  markup_operator->keyboard_active = false;
1666 
1667  markup_operator->ResetCameras();
1668  return HandleResult::Handled;
1669  }
1670 
1671  void SetOperator(MarkupOperator * in_operator) { markup_operator = in_operator; }
1672 
1673  private:
1674  MarkupOperator * markup_operator;
1675  };
1676 
1677  std::unordered_multimap<RGBColor, SegmentKey> attribute_map;
1678 
1679  MouseButtons mouse_trigger;
1680  ModifierKeys modifier_trigger;
1681 
1682  MarkupType markup_type;
1683  SegmentKey markup_segment;
1684  SegmentKey current_segment;
1685  Attributes current_attributes;
1686 
1687  static const RGBColor default_color;
1688  static const TextAttributeKit default_text_attributes;
1689  static const LineAttributeKit default_line_attributes;
1690 
1691  Point start_point;
1692  bool start_new_line;
1693  LineKey current_line;
1694  size_t current_line_size;
1695  CircleKey current_circle;
1696  LineKey current_circle_line;
1697  LineKey current_rectangle;
1698  View last_attached_view;
1699 
1700  bool start_new_note;
1701  bool keyboard_active;
1702  TextKey default_text;
1703  TextKey current_text;
1704  SizeTArray text_columns;
1705  size_t current_text_row;
1706 
1707  bool operator_active;
1708  TouchID tracked_touch_id;
1709  TouchID second_tracked_touch_id;
1710 
1711  CameraKit original_camera;
1712  CameraKit original_markup_camera;
1713 
1714  KeyboardHiddenEventHandler handler;
1715 
1716  bool SetupConstructionSegments();
1717  void LookupSegment();
1718  void CreateNewMarkupSegment();
1719  void DrawFreehand(Point const & location);
1720  void DrawText();
1721  void DrawCircle(Point const & location);
1722  void DrawCircleFromTwoPoints(Point const & point_one, Point const & point_two);
1723  void DrawRectangleFromTwoPoints(Point const & point_one, Point const & point_two);
1724  void DrawRectangle(Point const & location);
1725  void CenterCameras(Point const & main_camera_center, Point const & markup_camera_center);
1726  void ResetCameras();
1727  void EndTextNote();
1728 };
1729 
1747 class SPRK_OPS_API AnnotationOperator : public Operator
1748 {
1749 public:
1750  AnnotationOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1751 
1753  virtual HPS::UTF8 GetName() const override { return "HPS_AnnotationOperator"; }
1754 
1755  virtual void OnViewAttached(HPS::View const & in_attached_view) override;
1756  virtual void OnViewDetached(HPS::View const & in_detached_view) override;
1757 
1765  virtual bool OnMouseDown(MouseState const & in_state) override;
1766 
1772  virtual bool OnMouseMove(MouseState const & in_state) override;
1773 
1774 
1782  virtual bool OnTouchDown(TouchState const & in_state) override;
1783 
1787  virtual bool OnTouchUp(TouchState const & in_state) override;
1788 
1793  virtual bool OnTouchMove(TouchState const & in_state) override;
1794 
1795 
1800  virtual bool OnKeyDown(KeyboardState const & in_state) override;
1801 
1806  virtual bool OnTextInput(HPS::UTF8 const & in_text) override;
1807 
1815  void SetBackgroundShape(const char * in_shape);
1816 
1820  UTF8 GetBackgroundShape() const;
1821 
1825  class SPRK_OPS_API AnnotationInsertedEvent : public HPS::Event
1826  {
1827  public:
1830  {
1831  channel = GetClassID();
1832  consumable = false;
1833  }
1834 
1835  AnnotationInsertedEvent(HPS::SegmentKey const & in_text_key, HPS::View const & in_view) : Event()
1836  {
1837  channel = GetClassID();
1838  consumable = false;
1839  text_key = in_text_key;
1840  view = in_view;
1841  }
1842 
1845  AnnotationInsertedEvent(Event const & in_event) : Event(in_event)
1846  {
1847  if (in_event.GetChannel() == Object::ClassID<AnnotationInsertedEvent>())
1848  {
1849  auto that = static_cast<AnnotationInsertedEvent const &>(in_event);
1850  text_key = that.text_key;
1851  view = that.view;
1852  }
1853  else
1854  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
1855  }
1856 
1858 
1861  Event * Clone() const
1862  {
1863  AnnotationInsertedEvent * new_event = new AnnotationInsertedEvent(*this);
1864  return new_event;
1865  }
1866 
1867  SegmentKey text_key; //the key of the segment containing the annotation
1868  View view;
1869  };
1870 
1871 private:
1872  void AddAnnotationUserData();
1873  void StartNewNote();
1874 
1875  bool InputDown(WindowKey const & window_key, Point const & location, KeyPath & event_path);
1876  bool InputMove(Point const & location, KeyPath & event_path);
1877 
1878  void CenterCamera(Point const & camera_center);
1879  void ResetCamera();
1880 
1881  class KeyboardHiddenEventHandler : public EventHandler
1882  {
1883  public:
1884  KeyboardHiddenEventHandler()
1885  : EventHandler()
1886  { }
1887 
1888  virtual ~KeyboardHiddenEventHandler()
1889  { Shutdown(); }
1890 
1891  virtual HandleResult Handle(Event const * /*in_event*/)
1892  {
1893  annotation_operator->keyboard_active = false;
1894 
1895  annotation_operator->ResetCamera();
1896  return HandleResult::Handled;
1897  }
1898 
1899  void SetOperator(AnnotationOperator * in_operator) { annotation_operator = in_operator; }
1900 
1901  private:
1902  AnnotationOperator * annotation_operator;
1903  };
1904 
1905 
1906  SegmentKey annotation_segment; //segment containing all annotations
1907  View last_attached_view; //the last view that was attached to this operator
1908  SelectionOptionsKit selection_options; //selection options used to select geometry
1909  SelectionOptionsKit annotation_selection_options; //selection options used when trying to select annotations
1910  bool editing_text; //whether we are in a state which allows editing of an annotation
1911  bool start_new_note; //whether we should delete the text of an annotation when typing
1912  UTF8 annotation_user_data; //the user data set on annotation geometry to distinguish it from non annotation geometry
1913  UTF8 annotation_shape; //the name of the shape definition used to draw the annotation background
1914 
1915  PortfolioKey current_portfolio; //the portfolio used to store the default definitions used by this operator
1916  SegmentKey highlight_style_segment; //the highlight background style
1917 
1918  RGBColor background_color; //the color of the annotation background
1919  RGBColor leader_line_color; //the color of the annotation leader line and edges
1920  RGBColor highlight_color; //the color the annotation becomes while it is being edited
1921 
1922  TextKey text_to_edit; //the annotation text which we are working on
1923  SizeTArray text_columns; //the number of columns of the text for the current annotation
1924  size_t current_text_row; //the number of rows of the text for the current annotation
1925 
1926  //touch only flags -- these flags are only relevant when running the operator on a touch enabled device
1927  TouchID tracked_touch_id; //the ID of the touch we are tracking
1928  bool keyboard_active; //whether the software keyboard is visible
1929  CameraKit original_camera; //the camera setting as they were just before the annotation text is edited
1930  KeyboardHiddenEventHandler handler; //a handler that takes care of resetting the camera when the software keyboard is hidden
1931  Point touch_down_position; //the position the last touch down occurred at
1932  bool always_show_keyboard_on_touch_up; //true if we are just inserting the annotation, false if we are editing a previously inserted one.
1933 };
1934 
1957 class SPRK_OPS_API HandlesOperator : public Operator
1958 {
1959 public:
1960  HandlesOperator(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys());
1961  ~HandlesOperator();
1962 
1963  enum class HandleType
1964  {
1965  Rotation,
1966  RotationX,
1967  RotationY,
1968  RotationZ,
1969  AxisTranslation,
1970  AxisTranslationX,
1971  AxisTranslationY,
1972  AxisTranslationZ,
1973  PlaneTranslation,
1974  PlaneTranslationXY,
1975  PlaneTranslationYZ,
1976  PlaneTranslationZX,
1977  CenterPoint,
1978  };
1979 
1981  virtual HPS::UTF8 GetName() const override { return "HPS_HandlesOperator"; }
1982 
1983  virtual void OnViewAttached(HPS::View const & in_attached_view) override;
1984  virtual void OnViewDetached(HPS::View const & in_detached_view) override;
1985 
1992  virtual bool OnMouseDown(MouseState const & in_state) override;
1993 
1998  virtual bool OnMouseMove(MouseState const & in_state) override;
1999 
2003  virtual bool OnMouseUp(MouseState const & in_state) override;
2004 
2011  virtual bool OnTouchDown(TouchState const & in_state) override;
2012 
2017  virtual bool OnTouchMove(TouchState const & in_state) override;
2018 
2022  virtual bool OnTouchUp(TouchState const & in_state) override;
2023 
2038  void SetHandlesColors(MaterialKitArray const & in_colors) { handles_colors = in_colors; }
2039 
2055  MaterialKitArray GetHandlesColors() const { return handles_colors; }
2056 
2060  void SetHighlightColor(RGBAColor const & in_highlight_color);
2061 
2064  RGBAColor GetHighlightColor() const { return highlight_color; }
2065 
2071  void SetHandlesAppearance(float in_length = 0.16f, float in_radius = 0.005f, size_t in_handles_points = 30);
2072 
2078  void SetRotationHandleAppearance(float in_offset = 0.045f, float in_angle = 25.0f, float in_tip_size = 0.15f);
2079 
2085  void SetPlaneTranslationAppearance(float in_plane_offset = 0.2f, float in_plane_length = 0.6f, float in_center_radius = 0.2f);
2086 
2092  void SetCADModel(CADModel const & in_cad_model);
2093 
2098  void GetHandlesAppearance(float & out_length, float & out_radius, size_t & out_handles_points) const;
2099 
2104  void GetRotationHandleAppearance(float & out_offset, float & out_angle, float & out_tip_size) const;
2105 
2110  void GetPlaneTranslationAppearance(float & out_plane_offset, float & out_plane_length, float & out_center_radius) const;
2111 
2115  void SetTrailingGeometry(bool in_state) { display_trailing_geometry = in_state; }
2116 
2120  bool GetTrailingGeometry() const { return display_trailing_geometry; }
2121 
2125  CADModel GetCADModel() const { return cad_model; }
2126 
2130  void AddHandles(HandleType handle_type);
2131 
2135  void RemoveHandles(HandleType handle_type);
2136 
2137  /* Dismisses the handles.*/
2138  void DismissHandles();
2139 
2140  class SPRK_OPS_API GeometryTransformedEvent : public HPS::Event
2141  {
2142  public:
2145  {
2146  channel = GetClassID();
2147  consumable = false;
2148  }
2149 
2150  GeometryTransformedEvent(HPS::View const & in_view, HPS::SegmentKey const & in_segment_key, HPS::MatrixKit const & in_transform) : Event()
2151  {
2152  channel = GetClassID();
2153  consumable = false;
2154  view = in_view;
2155  segment_key = in_segment_key;
2156  transform = in_transform;
2157  }
2158 
2161  GeometryTransformedEvent(Event const & in_event) : Event(in_event)
2162  {
2163  if (in_event.GetChannel() == Object::ClassID<GeometryTransformedEvent>())
2164  {
2165  auto that = static_cast<GeometryTransformedEvent const &>(in_event);
2166  view = that.view;
2167  segment_key = that.segment_key;
2168  transform = that.transform;
2169  }
2170  else
2171  throw HPS::InvalidSpecificationException("Invalid Event Type to Cast From.");
2172  }
2173 
2175 
2178  Event * Clone() const
2179  {
2180  GeometryTransformedEvent * new_event = new GeometryTransformedEvent(*this);
2181  return new_event;
2182  }
2183 
2184  SegmentKey segment_key;
2185  MatrixKit transform;
2186  View view;
2187  };
2188 
2189 private:
2190  enum class Movement
2191  {
2192  None,
2193  Translation,
2194  Rotation,
2195  PlaneTranslation,
2196  ViewPlaneTranslation,
2197  };
2198 
2199  enum InternalHandleType : size_t
2200  {
2201  rotation_x = 0,
2202  rotation_y,
2203  rotation_z,
2204  axis_translation_x,
2205  axis_translation_y,
2206  axis_translation_z,
2207  plane_translation_x,
2208  plane_translation_y,
2209  plane_translation_z,
2210  center_point_translation,
2211  last = center_point_translation,
2212  };
2213 
2214  CanvasArray canvases; //A list of Canvas objects that the View attached to this operator belongs to. This value only gets updated on OnViewAttached.
2215  View last_attached_view; //The last View to where this operator was pushed.
2216  TouchID tracked_touch_id;
2217 
2218  SegmentKey handles; //top level segment
2219  SegmentKey handles_segment; //segment where the matrices for the handles transformations are accumulated
2220  SegmentKey handles_geometry; //segment where the handles geometry lives
2221  SegmentKey center_sphere;
2222  SegmentKey reference_segment; //segment containing all the net attributes of segment_to_move
2223  SegmentKey segment_to_move; //segment containing geometry affected by the handles
2224  SegmentKey temporary_segment_to_move; //segment where we accumulate changes while the handles are active
2225  SegmentKey handles_trail; //segment containing the trailing geometry
2226  KeyPath path_to_segment_to_move;
2227  KeyPath complete_referenced_path;
2228 
2229  //Component level variables
2230  CADModel cad_model; //The CADModel associated with this operator. Might be Invalid.
2231  HPS::Type cad_model_type; //HPS::Type::None when cad_model is not valid.
2232  ComponentPath component_path_to_move; //Analogous to path_to_segment_to_move in the case where a CADModel is valid.
2233  Component component_to_move; //Analogous to segment_to_move in the case where a CADModel is valid.
2234 
2235  std::vector<bool> requested_handle_type;
2236  std::vector<bool> current_handle_type;
2237 
2238  WorldPoint handles_origin_point;
2239  WorldPoint movement_start_point;
2240  Point input_down_position;
2241 
2242  Camera::Projection camera_projection;
2243 
2244  SelectionOptionsKit geometry_selection_options;
2245  SelectionOptionsKit handles_selection_options;
2246 
2247  HighlightOptionsKit hide_highlight_options;
2248  HighlightOptionsKit partial_transparency_options;
2249  HighlightOptionsKit highlight_options;
2250  SegmentKey style_segment;
2251  SegmentKey transparency_style_segment;
2252  UTF8 style_name;
2253  bool something_is_highlighted;
2254  MaterialKitArray handles_colors;
2255  RGBAColor highlight_color;
2256  Key highlighted_handle;
2257 
2258  //state flags
2259  bool are_handles_on;
2260  bool remove_handles;
2261  Movement move_geometry;
2262  Movement previous_movement;
2263  Vector movement_direction;
2264  Plane movement_plane;
2265  Vector base_vector;
2266 
2267  //handles appearance
2268  float handles_length; //Length of the handles. Expressed in percentage of screen [0 - 1]
2269  float handles_radius; //Radius of the handles. Expressed in percentage of screen [0 - 1]
2270  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].
2271  float arc_angle; //The angle formed by the arc handles. Must be greater than zero.
2272  size_t arc_points; //The number of points used to draw the arc handles.
2273  float tip_size; //The size of the tips at the end of the handles, specified as a percentage of the handles length
2274  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.
2275  float plane_length; //The length of the plane translation handle, specified as a percentage of handles_length.
2276  float center_radius;
2277 
2278  //handle geometry
2279  CylinderKey x;
2280  CylinderKey y;
2281  CylinderKey z;
2282  CylinderKey arc_x;
2283  CylinderKey arc_y;
2284  CylinderKey arc_z;
2285  ShellKey xy;
2286  ShellKey xz;
2287  ShellKey yz;
2288  SphereKey center;
2289 
2290  //trailing geometry
2291  bool display_trailing_geometry;
2292  Point trailing_line_start;
2293  Point trailing_circle_start;
2294  Point trailing_circle_center;
2295  Vector trailing_rotation;
2296  MarkerKey trail_marker;
2297  LineKey trailing_line;
2298  CircularArcKey trailing_circle;
2299  float rotation_direction;
2300 
2301  bool InputDown(size_t in_click_count, WindowKey const & in_window, KeyArray const & in_event_path, Point const & in_location);
2302  bool InputMove(KeyPath const & in_path, Point const & in_location);
2303  void InputUp(Point const & in_location);
2304 
2305  void InsertHandles();
2306  void InsertRotationHandles(bool in_x, bool in_y, bool in_z);
2307  void InsertAxisTranslationHandles(bool in_x, bool in_y, bool in_z);
2308  void InsertPlaneTranslationHandles(bool in_x, bool in_y, bool in_z);
2309  void InsertCenterPoint();
2310 
2311  bool HighlightHandles(WindowKey & in_window, KeyArray const & in_event_path, Point const & in_location);
2312 
2313  //moves the geometry affected by handles into a new segment, and hides the original
2314  void ReferenceGeometry(KeyPath const & in_path);
2315 
2316  //copies the accumulated transform from the reference geometry segment back into the original place.
2317  //removes the hide highlight from the original geometry
2318  //if a CADModel is associated with this operator, it propagates the changes to the Component and PRC/Parasolid geometry
2319  void CommitChanges();
2320 };
2321 
2322 
2323 }
2324 #endif
2325 
2326 
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:142
Definition: hps.h:6280
Definition: hps.h:85
MaterialKitArray GetHandlesColors() const
Definition: sprk_ops.h:2055
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:630
HandleType
Definition: sprk_ops.h:1963
MarkupInsertedEvent(Event const &in_event)
Definition: sprk_ops.h:1619
HPS::Rectangle GetWindowRectangle() const
Definition: sprk_ops.h:358
Definition: sprk.h:273
bool GetSectioning()
Definition: sprk_ops.h:1383
An InvalidSpecificationException is thrown when a method is called with non-sensical or contradictory...
Definition: hps.h:5884
SegmentKey GetSegmentKey()
Definition: sprk_ops.h:1590
static MouseButtons ButtonRight()
Definition: hps.h:48316
Definition: sprk_ops.h:1040
float GetIndicatorScale() const
Definition: sprk_ops.h:1346
Definition: sprk_ops.h:283
virtual HPS::UTF8 GetName() const override
Definition: sprk_ops.h:1981
intptr_t GetChannel() const
Definition: hps.h:6397
Definition: hps.h:37701
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:972
Definition: sprk_ops.h:407
void SetMarkupType(MarkupType in_markup_type)
Definition: sprk_ops.h:1564
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:424
Definition: hps.h:48825
Definition: hps.h:7787
Definition: sprk_ops.h:68
AnnotationInsertedEvent()
Definition: sprk_ops.h:1829
Definition: hps.h:3579
Definition: hps.h:6650
ZoomType
Definition: sprk_ops.h:585
void SetIndicatorScale(float in_scale)
Definition: sprk_ops.h:1350
HPS::SelectionOptionsKit GetSelectionOptions() const
Definition: sprk_ops.h:540
Definition: hps.h:16454
Definition: sprk_ops.h:625
GeometryTransformedEvent(Event const &in_event)
Definition: sprk_ops.h:2161
void SetHandlesColors(MaterialKitArray const &in_colors)
Definition: sprk_ops.h:2038
void SetPlaneHighlightOptions(HighlightOptionsKit const &in_highlight_options)
Definition: sprk_ops.h:1366
Definition: sprk_ops.h:504
Definition: sprk_ops.h:19
Definition: sprk_ops.h:191
TextAttributeKit GetTextAttributes()
Definition: sprk_ops.h:1575
GeometryTransformedEvent()
Definition: sprk_ops.h:2144
Definition: hps.h:1564
Definition: hps.h:9031
RGBAColor GetHighlightColor() const
Definition: sprk_ops.h:2064
void SetLineAttribute(LineAttributeKit const &in_line_attributes)
Definition: sprk_ops.h:1585
Definition: sprk_ops.h:336
Definition: sprk_ops.h:1599
Definition: sprk_ops.h:689
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1046
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:388
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:196
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:535
HPS::SelectionOptionsKit GetSelectionOptions() const
Definition: sprk_ops.h:447
Definition: sprk_ops.h:1270
Definition: sprk_ops.h:1957
Definition: hps.h:48723
Definition: sprk_ops.h:733
Definition: sprk_ops.h:457
virtual HPS::UTF8 GetName() const override
Definition: sprk_ops.h:1753
std::vector< MaterialKit, Allocator< MaterialKit > > MaterialKitArray
Array of type HPS::MaterialKit.
Definition: hps.h:6725
Definition: hps.h:33516
Definition: hps.h:4547
Definition: sprk_ops.h:1488
AnnotationInsertedEvent(Event const &in_event)
Definition: sprk_ops.h:1845
bool GetIndicatorVisibility()
Definition: sprk_ops.h:1392
Event * Clone() const
Definition: sprk_ops.h:2178
bool IsMarkupActive()
Definition: sprk_ops.h:1597
Definition: hps.h:4486
RGBColor GetColor()
Definition: sprk_ops.h:1568
Definition: hps.h:7158
Definition: hps.h:48194
Definition: hps.h:27511
Definition: hps.h:45033
HPS::Rectangle GetInnerWindowRectangle() const
Definition: sprk_ops.h:363
Definition: hps.h:6114
Definition: hps.h:47087
Definition: hps.h:44113
Event * Clone() const
Definition: sprk_ops.h:1635
Definition: hps.h:48610
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:597
void SetTrailingGeometry(bool in_state)
Definition: sprk_ops.h:2115
Definition: sprk_ops.h:552
Definition: hps.h:15841
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:1285
HighlightOptionsKit GetPlaneHighlightOptions() const
Definition: sprk_ops.h:1362
Definition: hps.h:15084
bool GetMouseOverHighlighting() const
Definition: sprk_ops.h:1370
Definition: hps.h:45312
Definition: hps.h:47701
Projection
Definition: hps.h:1435
bool GetTrailingGeometry() const
Definition: sprk_ops.h:2120
Event * Clone() const
Definition: sprk_ops.h:1861
Definition: hps.h:6364
void SetSelectionOptions(HPS::SelectionOptionsKit const &in_options)
Definition: sprk_ops.h:442
Definition: hps.h:14089
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:251
virtual bool OnKeyDown(KeyboardState const &in_state)
Definition: sprk_ops.h:1058
void SetMouseOverHighlighting(bool in_enable_mouse_over_highlighting)
Definition: sprk_ops.h:1374
MarkupType GetMarkupType()
Definition: sprk_ops.h:1561
Definition: sprk_ops.h:240
LineAttributeKit GetLineAttributes()
Definition: sprk_ops.h:1582
CADModel GetCADModel() const
Definition: sprk_ops.h:2125
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:73
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:480
Definition: sprk_ops.h:1747
MaterialMappingKit GetPlaneMaterial() const
Definition: sprk_ops.h:1354
Definition: hps.h:47012
std::vector< Key, Allocator< Key > > KeyArray
Array of type HPS::Key.
Definition: hps.h:6718
std::vector< Plane, Allocator< Plane > > PlaneArray
Array of type HPS::Plane.
Definition: hps.h:6701
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:521
Definition: sprk_ops.h:582
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:340
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:485
Definition: sprk_ops.h:966
Handedness
Definition: hps.h:1295
static MouseButtons ButtonLeft()
Definition: hps.h:48312
static MouseButtons ButtonMiddle()
Definition: hps.h:48320
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:288
Definition: hps.h:9189
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:561
static ModifierKeys KeyControl()
Definition: hps.h:47905
Definition: hps.h:7705
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:738
HPS::HighlightOptionsKit GetHighlightOptions() const
Definition: sprk_ops.h:574
Definition: hps.h:9418
Definition: hps.h:11101
void SetTextAttribute(TextAttributeKit const &in_text_attributes)
Definition: sprk_ops.h:1578
Definition: hps.h:24676
Definition: hps.h:25038
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:694
Definition: sprk.h:3041
void SetColor(RGBColor const &in_color)
Definition: sprk_ops.h:1571
Definition: sprk.h:1107
Definition: sprk_ops.h:137
virtual HPS::UTF8 GetName() const override
Definition: sprk_ops.h:1502
virtual bool OnKeyUp(KeyboardState const &in_state)
Definition: sprk_ops.h:1062
virtual HPS::UTF8 GetName() const
Definition: sprk_ops.h:468
Definition: hps.h:41596
MarkupInsertedEvent()
Definition: sprk_ops.h:1603
void SetHighlightOptions(HPS::HighlightOptionsKit const &in_options)
Definition: sprk_ops.h:569
Definition: sprk_ops.h:384
std::vector< size_t, Allocator< size_t > > SizeTArray
Array of type size_t.
Definition: hps.h:6706