internal void DrawMirrorAxis(List <IssoPoint2D> mirrorAxis, SKCanvas canvas) { SKPaint dashPaint = new SKPaint() { Style = SKPaintStyle.Stroke, Color = Color.AliceBlue.ToSKColor(), PathEffect = SKPathEffect.CreateDash(new Single[2] { surface.ViewHeight / 100, surface.ViewHeight / 100 }, surface.ViewHeight / 80), IsAntialias = true, StrokeWidth = 1 }; SKPoint pt1 = IssoConvert.IssoPoint2DToSkPoint(mirrorAxis[0], surface.ScaleFactor, surface.Origin, surface.ViewHeight); SKPoint pt2 = IssoConvert.IssoPoint2DToSkPoint(mirrorAxis[1], surface.ScaleFactor, surface.Origin, surface.ViewHeight); canvas.DrawLine(pt1.X, pt1.Y, pt2.X, pt2.Y, dashPaint); // Рисуем то, как будет выглядеть отражение dashPaint.PathEffect = null; foreach (ComponentLinear c in SelectedBeams) { IssoPoint2D p1 = IssoDist.MirrorPoint(c.Start, mirrorAxis[0], mirrorAxis[1]); IssoPoint2D p2 = IssoDist.MirrorPoint(c.End, mirrorAxis[0], mirrorAxis[1]); pt1 = IssoConvert.IssoPoint2DToSkPoint(p1, surface.ScaleFactor, surface.Origin, surface.ViewHeight); pt2 = IssoConvert.IssoPoint2DToSkPoint(p2, surface.ScaleFactor, surface.Origin, surface.ViewHeight); canvas.DrawLine(pt1.X, pt1.Y, pt2.X, pt2.Y, dashPaint); } }
public float NodeDist(IssoPoint2D pt, ComponentNode node) { // Если точка pt лежит внутри области узла, возвращаем ноль - иначе // возвразаем расстояние от pt до Node.Location if (ComponentNodeVM.Contains(node, pt, surface)) { return(0f); } else { return(IssoDist.PointDst(pt, node.Location)); } }
private ComponentNode MirrorNode(IssoPoint2D point, List <ComponentBasic> newElements) { IssoPoint2D pt = IssoDist.MirrorPoint(point, surface.MirrorAxis[0], surface.MirrorAxis[1]); IssoPoint2D ptout; ComponentNode nd = (ComponentNode)GetComponent(pt, out ptout, ComponentTypes.ctNode); if (nd == null) { nd = new ComponentNode(pt); newElements.Add(nd); } return(nd); }
internal ComponentLinear GetLinear(IssoPoint2D p1, IssoPoint2D p2) { // Возвращаем линейный компонент, которому принадлежат обе точки p1 и p2 for (int i = 0; i < model.CompsList.Count; i++) { if (model.CompsList[i].CompType == ComponentTypes.ctLinear) { ComponentLinear lin = (ComponentLinear)model.CompsList[i]; if (IssoDist.PointsOnLine(new IssoPoint2D[] { p1, p2 }, new IssoPoint2D[] { lin.Start, lin.End })) { return(lin); } } } return(null); }
internal int SelectElementsByRect(SKRect selectionRect) { IssoRect2D rect = new IssoRect2D(new IssoPoint2D() { X = selectionRect.Left, Y = selectionRect.Top }, selectionRect.Width, selectionRect.Height); int count = 0; foreach (ComponentLinear c in ModelBeams) { if (IssoDist.PointInRect(c.Start, rect) && IssoDist.PointInRect(c.End, rect)) { c.CompState = ComponentState.csSelected; count++; } } MultipleSelected = count > 1; return(count); }
private static SKPath GetEquallyDistributed(ComponentLoad load, float scaleFactor, IssoPoint2D origin, float ViewHeight) { SKPath p = new SKPath(); float Angle = load.Direction * (float)Math.PI / 180f; float length = IssoDist.PointDst(load.AppNodes[0].Location, load.AppNodes[1].Location); float dx = (load.AppNodes[1].Location.X - load.AppNodes[0].Location.X) * scaleFactor; float dy = -(load.AppNodes[1].Location.Y - load.AppNodes[0].Location.Y) * scaleFactor; float ArrawHeight = ViewHeight / 30; float step = ViewHeight / 70; int stepcnt = Math.Max((int)Math.Round(length * scaleFactor / step, 0), 1); SKPoint start = IssoConvert.IssoPoint2DToSkPoint(load.AppNodes[0].Location, scaleFactor, origin, ViewHeight); dx = dx / stepcnt; dy = dy / stepcnt; SKMatrix rotate = SKMatrix.MakeRotation(-Angle); for (int i = 0; i < stepcnt + 1; i++) { SKPath arrow = GetDistibutedArrow((load.Value > 0) || (load.isOrthogonal && load.isReverse)); arrow.Transform(SKMatrix.MakeScale(ArrawHeight, ArrawHeight)); arrow.Transform(rotate); p.AddPath(arrow, start.X, start.Y); start.X += dx; start.Y += dy; } start = IssoConvert.IssoPoint2DToSkPoint(load.AppNodes[0].Location, scaleFactor, origin, ViewHeight); SKPoint end = IssoConvert.IssoPoint2DToSkPoint(load.AppNodes[1].Location, scaleFactor, origin, ViewHeight); p.MoveTo(start.X + ArrawHeight * (float)Math.Cos(Angle), start.Y - ArrawHeight * (float)Math.Sin(Angle)); p.LineTo(end.X + ArrawHeight * (float)Math.Cos(Angle), end.Y - ArrawHeight * (float)Math.Sin(Angle)); return(p); }
internal ComponentBasic GetComponent(IssoPoint2D pt1, out IssoPoint2D pt2, ComponentTypes type = ComponentTypes.ctAny) { pt2 = new IssoPoint2D() { X = pt1.X, Y = pt1.Y }; if (model.CompsList.Count == 0) { return(null); } int j = 0; for (int i = 0; i < model.CompsList.Count; i++) { switch (model.CompsList[i].CompType) { case ComponentTypes.ctNode: { if ((type == ComponentTypes.ctAny) || (type == ComponentTypes.ctNode)) { if (ComponentNodeVM.Contains((ComponentNode)model.CompsList[i], pt1, surface)) { pt2 = ((ComponentNode)model.CompsList[i]).Location; return(model.CompsList[i]); } } break; } case ComponentTypes.ctLinear: { if ((type == ComponentTypes.ctAny) || (type == ComponentTypes.ctLinear)) { if (ComponentLinearVM.Contains((ComponentLinear)model.CompsList[i], pt1, surface)) { pt2 = IssoDist.PurpPoint(pt1, (ComponentLinear)model.CompsList[i]); return(model.CompsList[i]); } } break; } case ComponentTypes.ctBinding: { if ((type == ComponentTypes.ctAny) || (type == ComponentTypes.ctBinding)) { if (IssoBindingVM.Contains((IssoBinding)model.CompsList[i], pt1, surface)) { pt2 = ((IssoBinding)model.CompsList[i]).LinePlace; return(model.CompsList[i]); } } break; } case ComponentTypes.ctForce: case ComponentTypes.ctDistributedLoad: { if ((type == ComponentTypes.ctAny) || (type == ComponentTypes.ctForce) || (type == ComponentTypes.ctDistributedLoad)) { if (ComponentLoadVM.Contains((ComponentLoad)model.CompsList[i], pt1, surface)) { pt2 = ((ComponentLoad)model.CompsList[i]).AppNodes[0].Location; return(model.CompsList[i]); } } break; } } } return(null); }
public bool CloseEnough(IssoPoint2D pt1, IssoPoint2D pt2) { float d = IssoDist.PointDst(pt1, pt2); return(d <= DistTolerance); }
public void Touch(SKTouchEventArgs e) { if (e.ActionType == SKTouchAction.WheelChanged) { WheelZoom(e.WheelDelta); return; } if (e.MouseButton == SKMouseButton.Right) { CancelAction(); return; } try { IssoPoint2D pt1 = IssoConvert.SkPointToIssoPoint2D(e.Location, ScaleFactor, ModelViewFragment, ViewHeight); // TODO: Обработать активность привязок pt1 = Grid.Snap(pt1); modelVM.SnapPoint = modelVM.SnapToNodes(pt1); if (modelVM.SnapPoint.X != float.MinValue) { pt1.X = modelVM.SnapPoint.X; } if (modelVM.SnapPoint.Y != float.MinValue) { pt1.Y = modelVM.SnapPoint.Y; } // TODO: Окончание создания компонентов при "касательном" вводе // НАЖАТИЕ if (e.ActionType == SKTouchAction.Pressed) { switch (EditorAction) { case EditorActions.None: StartPt = pt1; SelectComponent(pt1); break; case EditorActions.SelectFrame: SelectByFrame(pt1, SelectionStarted); break; case EditorActions.NewLinearFirstPoint: CreateNewLinear(pt1); break; case EditorActions.NewLinearLastPoint: FinishNewLinear(pt1, e.MouseButton); break; case EditorActions.EditNode: CreateOrEditNode(pt1); break; case EditorActions.NewDimensionFirstNode: DimensionFirstNode(pt1); break; case EditorActions.NewDimensionVFirstNode: DimensionFirstNode(pt1); break; case EditorActions.NewDimensionLastNode: DimensionLastNode(pt1); break; case EditorActions.NewDimensionLinePlace: DimensionLinePlace(pt1); break; case EditorActions.NewForce: CreateForce(pt1); break; case EditorActions.NewDstLoad: CreateDistLoad(pt1); break; case EditorActions.MirrorElements: MirrorElements(pt1, true); break; case EditorActions.CopyElements: CopyElements(pt1, CopyBasePointDefined); break; } } // ДВИЖЕНИЕ if (e.ActionType == SKTouchAction.Moved) { EndPt = pt1; MovingView = e.InContact && (IssoDist.PointDst(StartPt, EndPt) > (5 / ScaleFactor)); switch (EditorAction) { case EditorActions.NewLinearLastPoint: ChangeLastPoint(pt1); break; case EditorActions.NewDimensionLastNode: ChangeDimPlace(pt1); break; case EditorActions.NewDimensionLinePlace: ChangeDimPlace(pt1); break; case EditorActions.SelectFrame: if (SelectionStarted) { SelectByFrame(pt1, false); } break; case EditorActions.MirrorElements: MirrorElements(pt1, false); break; case EditorActions.None: if (MovingView) { MoveOrigin(); } break; case EditorActions.CopyElements: CopyTargetPoint = pt1; break; } return; } } finally { // ОТОБРАЖАЕМ ПРОЦЕСС РЕДАКТИРОВАНИЯ if (EditorAction != EditorActions.None) { RModelView.InvalidateSurface(); } OnVisualStates?.Invoke(EditorAction); } }