public static void AddPointToDrawing(ref PCad.Model model, Action saveToHistory) { CoordinateCreation.BakePosition(model.InteractionState.focusPosition); model.Sketch.coordinateSystem.SetAnchorPosition(MouseInput.RaycastPosition); switch (model.Tool.CurrentGeometryType) { case GeometryType.Point: model.Sketch.geometries.Add(PointCreation.NewPoint(model.InteractionState.focusPosition)); saveToHistory(); break; case GeometryType.Line: if (!(model.InteractionState.incompleteGeometry is LineModel)) { model.InteractionState.incompleteGeometry = LineCreation.StartNewLine(model.InteractionState.focusPosition); model.Sketch.geometries.Add(model.InteractionState.incompleteGeometry); } else { LineCreation.CompleteLine(model.InteractionState.incompleteGeometry as LineModel, model.InteractionState.focusPosition); model.InteractionState.incompleteGeometry = null; saveToHistory(); } break; case GeometryType.Rectangle: if (!(model.InteractionState.incompleteGeometry is RectangleModel)) { model.InteractionState.incompleteGeometry = RectangleCreation.StartNewRectangle(model.InteractionState.focusPosition, model.Tool.CurrentGeometryColor); model.Sketch.geometries.Add(model.InteractionState.incompleteGeometry); } else { RectangleCreation.CompleteRectangle(model.InteractionState.incompleteGeometry as RectangleModel, model.InteractionState.focusPosition); model.InteractionState.incompleteGeometry = null; saveToHistory(); } break; default: throw new ArgumentOutOfRangeException(); } // reset input model.InteractionState.keyboardInputModel = new NumpadInput.Model(); }
public static void Update(ref PCad.Model model, CoordinateSystemUI coordinateSystemUI, bool isMouseOnDrawArea, Action saveToHistory) { model.InteractionState.hoveredCoordinate = CoordinateManipulation.TryGetCoordinateAtPosition(coordinateSystemUI); NumpadInput.UpdateNumpadInput(ref model.InteractionState.keyboardInputModel, model.Sketch.coordinateSystem.GetAllParameters() ); model.InteractionState.focusPosition = CoordinateCreation.UpdateCursorPosition( model.InteractionState.focusPosition, model.Sketch.coordinateSystem, model.InteractionState.keyboardInputModel ); if (model.InteractionState.focusPosition == null) { Debug.LogError($"Focus Position should always be != null if state == DrawRectangles"); return; } switch (model.InteractionState.CurrentMouseState) { case MouseInput.MouseState.None: case MouseInput.MouseState.PrimaryHold: case MouseInput.MouseState.PrimaryUp: break; case MouseInput.MouseState.PrimaryDown: if (isMouseOnDrawArea || Input.GetKeyDown(KeyCode.Return)) { AddPointToDrawing(ref model, saveToHistory); } break; case MouseInput.MouseState.SetAnchorDown: var mousePosition = MouseInput.RaycastPosition; model.Sketch.coordinateSystem.SetAnchorPosition(mousePosition); break; case MouseInput.MouseState.DeleteDown: CoordinateCreation.DeletePositionAtMousePosition(model.Sketch.coordinateSystem); break; default: throw new ArgumentOutOfRangeException(); } UpdateGeometry(ref model.InteractionState.incompleteGeometry, model.InteractionState.focusPosition); }
public void Initialize(Vec <float> mousePositionAsOrigin) { Sketch.coordinateSystem = new CoordinateSystem(mousePositionAsOrigin); Sketch.geometries = new List <GeometryModel>(); InteractionState.keyboardInputModel = new NumpadInput.Model(); Tool = new ToolConfiguration() { ActiveTool = ToolConfiguration.Tool.Drawing, CurrentGeometryType = GeometryType.Rectangle, CurrentGeometryColor = GeometryStyleAsset.GeometryColor.White, }; InteractionState.focusPosition = CoordinateCreation.UpdateCursorPosition( InteractionState.focusPosition, Sketch.coordinateSystem, InteractionState.keyboardInputModel ); }