private void SetStraightLine(float point, bool isAxeX) { var line = new LineFigure(_d2DRenderTarget); var lineStart = new Vector2(); var lineFinish = new Vector2(); if (isAxeX) { lineStart.X = point; lineStart.Y = ClientSize.Height * (_chart.Paddings.PaddingTopRatio / 2); lineFinish.X = point; lineFinish.Y = ClientSize.Height * _chart.Paddings.PaddingBottomRatio; } else { lineStart.X = ClientSize.Width * (_chart.Paddings.PaddingLeftRatio / 2); lineStart.Y = point; lineFinish.X = ClientSize.Width * _chart.Paddings.PaddingRightRatio; lineFinish.Y = point; } line.Line = new CustomLine(lineStart, lineFinish); _drawings.Add((SelectedFigureBase)line); }
private void ScaleLine(LineFigure lf, Point pos) { if (_nowScaling == null) { _originalX = lf.X.CachedValue.AsDouble; _originalY = lf.Y.CachedValue.AsDouble; _originalW = lf.Width.CachedValue.AsDouble; _originalH = lf.Height.CachedValue.AsDouble; var snappedTo = StepManager.SnapTo(pos, lf.GetMagnets(), lf.Center); var bLenSquared = _originalW * _originalW + _originalH * _originalH; if ((snappedTo == lf.Start) && (Math.Abs(bLenSquared) > Utils.Tolerance)) { var ax = _originalX + _originalW - pos.X; var ay = _originalY + _originalH - pos.Y; _nowScaling = new ScaleLineStep(lf, ScaleLineStep.Side.End, (ax * _originalW + ay * _originalH) / bLenSquared); } else if ((snappedTo == lf.End) && (Math.Abs(bLenSquared) > Utils.Tolerance)) { var ax = pos.X - _originalX; var ay = pos.Y - _originalY; _nowScaling = new ScaleLineStep(lf, ScaleLineStep.Side.Start, (ax * _originalW + ay * _originalH) / bLenSquared); } if (_nowScaling == null) { return; } StepManager.InsertNext(_nowScaling); } else { var sls = (ScaleLineStep)_nowScaling; if (sls.ScaleAround == ScaleLineStep.Side.Start) { var bLenSquared = _originalW * _originalW + _originalH * _originalH; var ax = pos.X - _originalX; var ay = pos.Y - _originalY; sls.Scale((ax * _originalW + ay * _originalH) / bLenSquared); } else if (sls.ScaleAround == ScaleLineStep.Side.End) { var bLenSquared = _originalW * _originalW + _originalH * _originalH; var ax = _originalX + _originalW - pos.X; var ay = _originalY + _originalH - pos.Y; sls.Scale((ax * _originalW + ay * _originalH) / bLenSquared); } } }
private void RotateLine(LineFigure lf, Point pos) { if (_nowRotating == null) { var snappedTo = StepManager.SnapTo(pos, lf.GetMagnets(), lf.Center); if (snappedTo == lf.Start) { var angle = Utils.AngleBetween(lf.X.CachedValue.AsDouble + lf.Width.CachedValue.AsDouble - pos.X, lf.Y.CachedValue.AsDouble + lf.Height.CachedValue.AsDouble - pos.Y, lf.Width.CachedValue.AsDouble, lf.Height.CachedValue.AsDouble); _nowRotating = new RotateLineStep(lf, RotateLineStep.Side.End, angle / (2 * Math.PI)); } else if (snappedTo == lf.End) { var angle = Utils.AngleBetween(pos.X - lf.X.CachedValue.AsDouble, pos.Y - lf.Y.CachedValue.AsDouble, lf.Width.CachedValue.AsDouble, lf.Height.CachedValue.AsDouble); _nowRotating = new RotateLineStep(lf, RotateLineStep.Side.Start, angle / (2 * Math.PI)); } if (_nowRotating == null) { return; } _originalX = lf.X.CachedValue.AsDouble; _originalY = lf.Y.CachedValue.AsDouble; _originalW = lf.Width.CachedValue.AsDouble; _originalH = lf.Height.CachedValue.AsDouble; StepManager.InsertNext(_nowRotating); } else { var rls = (RotateLineStep)_nowRotating; if (rls.RotateAround == RotateLineStep.Side.Start) { var angle = Utils.AngleBetween(pos.X - _originalX, pos.Y - _originalY, _originalW, _originalH); rls.Rotate(angle / (2 * Math.PI)); } else if (rls.RotateAround == RotateLineStep.Side.End) { var angle = Utils.AngleBetween(_originalX + _originalW - pos.X, _originalY + _originalH - pos.Y, _originalW, _originalH); rls.Rotate(angle / (2 * Math.PI)); } } }
private void ResizeLine(LineFigure lf, Point pos) { if (_nowResizing == null) { var snappedTo = StepManager.SnapTo(pos, lf.GetMagnets(), lf.Center); if (snappedTo == lf.Start) { _nowResizing = new ResizeLineStep(lf, ResizeLineStep.Side.End, pos.X - _downPos.X, pos.Y - _downPos.Y); } else if (snappedTo == lf.End) { _nowResizing = new ResizeLineStep(lf, ResizeLineStep.Side.Start, pos.X - _downPos.X, pos.Y - _downPos.Y); } if (_nowResizing == null) { return; } StepManager.InsertNext(_nowResizing); } else { var rls = (ResizeLineStep)_nowResizing; var snapped = StepManager.Snap(pos, _nowResizing.Figure); if (snapped != null) { if (rls.ResizeAround == ResizeLineStep.Side.End) { rls.Resize("(" + snapped.X.ExprString + ") - " + rls.Figure.Name + ".x", "(" + snapped.Y.ExprString + ") - " + rls.Figure.Name + ".y", snapped.Def); } else if (rls.ResizeAround == ResizeLineStep.Side.Start) { rls.Resize("(" + snapped.X.ExprString + ") - (" + rls.Figure.Name + ".x + (" + rls.Figure.Name + ".width))", "(" + snapped.Y.ExprString + ") - (" + rls.Figure.Name + ".y + (" + rls.Figure.Name + ".height))", snapped.Def); } } else { if (rls.ResizeAround == ResizeLineStep.Side.End) { rls.Resize(pos.X - _downPos.X, pos.Y - _downPos.Y); } else if (rls.ResizeAround == ResizeLineStep.Side.Start) { rls.Resize(pos.X - _downPos.X, pos.Y - _downPos.Y); } } } }
public LineConnector(LineFigure leftFigure, LineFigure rightFigure, Point point) { LeftFigure = leftFigure; RightFigure = rightFigure; PosPoint = point; InitializeComponent(); UpdateLinks(); MouseMove += OnMouseMove; MouseLeftButtonDown += OnMouseLeftButtonDown; MouseLeftButtonUp += OnMouseLeftButtonUp; }
private void MoveLine(LineFigure lf, Point pos) { if (_nowMoving == null) { _nowMoving = new MoveLineStep(lf, pos.X - _downPos.X, pos.Y - _downPos.Y); StepManager.InsertNext(_nowMoving); } else { var snapped = StepManager.Snap(pos, _nowMoving.Figure); Magnet snappedBy; if ((snapped != null) && ((snappedBy = StepManager.SnapTo(pos, _nowMoving.Figure.GetMagnets())) != null)) { if (snappedBy.EqualExprStrings(lf.Start)) { ((MoveLineStep)_nowMoving).Move( "(" + snapped.X.ExprString + ") - (" + _nowMoving.Figure.Name + ".x)", "(" + snapped.Y.ExprString + ") - (" + _nowMoving.Figure.Name + ".y)", snappedBy.Def, snapped.Def); } else if (snappedBy.EqualExprStrings(lf.Center)) { ((MoveLineStep)_nowMoving).Move( "((" + snapped.X.ExprString + ") - (" + lf.Name + ".width/2)) - (" + _nowMoving.Figure.Name + ".x)", "((" + snapped.Y.ExprString + ") - (" + lf.Name + ".height/2)) - (" + _nowMoving.Figure.Name + ".y)", snappedBy.Def, snapped.Def); } else if (snappedBy.EqualExprStrings(lf.End)) { ((MoveLineStep)_nowMoving).Move( "((" + snapped.X.ExprString + ") - (" + lf.Name + ".width)) - (" + _nowMoving.Figure.Name + ".x)", "((" + snapped.Y.ExprString + ") - (" + lf.Name + ".height)) - (" + _nowMoving.Figure.Name + ".y)", snappedBy.Def, snapped.Def); } } else { ((MoveLineStep)_nowMoving).Move(pos.X - _downPos.X, pos.Y - _downPos.Y); } } }
public void TransformToBezier(LineFigure figure) { _canvas.Children.Remove(figure); var bezierLine = new BezierLine(); figure.LeftLineConnector.RightFigure = bezierLine; figure.LeftLineConnector.UpdateLinks(); figure.RightLineConnector.LeftFigure = bezierLine; figure.RightLineConnector.UpdateLinks(); var bezCont1 = new BezierControl(bezierLine, false); var bezCont2 = new BezierControl(bezierLine, true); _canvas.Children.Add(bezierLine); _canvas.Children.Add(bezCont1); _canvas.Children.Add(bezCont2); }
public void TransformToSpline(LineFigure figure) { var lines = _canvas.Children.OfType <LineFigure>().ToList(); foreach (var lineFigure in lines) { _canvas.Children.Remove(lineFigure); } var spline = CreateSpline(); var connector = _canvas.Children.OfType <LineConnector>().First(x => x.LeftFigure == null); var firstConnector = connector; var lastConnector = _canvas.Children.OfType <LineConnector>().First(x => x.RightFigure == null); var cons = new List <LineConnector>() { connector }; while (!Equals(connector, lastConnector)) { cons.Add(connector.RightFigure.RightLineConnector); connector.LeftFigure = spline; connector.UpdateLinks(); connector = connector.RightFigure.RightLineConnector; } foreach (var lineCon in _canvas.Children.OfType <LineConnector>()) { lineCon.RightFigure = spline; lineCon.UpdateLinks(); } firstConnector.LeftFigure = null; firstConnector.RightFigure = spline; firstConnector.UpdateLinks(); connector.LeftFigure = spline; connector.RightFigure = null; connector.UpdateLinks(); spline.Connectors = cons; _canvas.Children.Add(spline); }
public override void CopyStaticFigure() { if ((Iterations == -1) || Figure.IsGuide) { return; } var lf = new LineFigure { X = new ScalarExpression("a", "a", LineFigure.X.CachedValue.Str), Y = new ScalarExpression("a", "a", LineFigure.Y.CachedValue.Str), Width = new ScalarExpression("a", "a", LineFigure.Width.CachedValue.Str), Height = new ScalarExpression("a", "a", LineFigure.Height.CachedValue.Str), FigureColor = LineFigure.FigureColor.Copy() }; Figure.StaticLoopFigures.Add(lf); StepManager.Figures.Add(lf); }
private DrawLineStep() { Figure = new LineFigure("line" + _count++); LineFigure = (LineFigure)Figure; }
public ScaleLineStep(LineFigure figure, Side scaleAround, double factor) : this(figure, scaleAround, factor.Str()) { }
public ScaleLineStep(LineFigure figure, Side scaleAround, string factor) : this(figure, scaleAround) { Scale(factor); }
private ScaleLineStep(LineFigure figure, Side scaleAround) { Figure = figure; LineFigure = figure; ScaleAround = scaleAround; }
public MoveLineStep(LineFigure figure, double x, double y) : this(figure, x.Str(), y.Str()) { }
private ResizeLineStep(LineFigure figure, Side resizeAround) { Figure = figure; LineFigure = figure; ResizeAround = resizeAround; }
public ResizeLineStep(LineFigure figure, Side resizeAround, string deltaX, string deltaY, string where = null) : this(figure, resizeAround) { Resize(deltaX, deltaY, where); }
public ResizeLineStep(LineFigure figure, Side resizeAround, double deltaX, double deltaY) : this(figure, resizeAround, deltaX.Str(), deltaY.Str()) { }
private RotateLineStep(LineFigure figure, Side rotateAround) { Figure = figure; LineFigure = figure; RotateAround = rotateAround; }
public MoveLineStep(LineFigure figure, string x, string y) : this(figure) { Move(x, y); }
public RotateLineStep(LineFigure figure, Side rotateAround, double factor) : this(figure, rotateAround, factor.Str()) { }
public RotateLineStep(LineFigure figure, Side rotateAround, string factor) : this(figure, rotateAround) { Rotate(factor); }
public void TransformToLineSimple(LineFigure figure) { //TODO }
private MoveLineStep(LineFigure figure) { Figure = figure; LineFigure = figure; }