public SvgPathData(SvgEditData item, PolygonUnit polygonUnitValue) { CurrentIndex = new SvgPathIndex(); var m_path = item?.GetPathData(); Paths = new List <List <SvgPathItem> >(); List <SvgPathItem> path = null; if (m_path != null) { SvgPathItem top = null; SvgPathItem befor = null; foreach (var p in m_path) { if (p.Command == 'm' || p.Command == 'M') { befor = null; top = p; path = new List <SvgPathItem>(); path.Add(p); Paths.Add(path); } else if (path != null) { path.Add(p); } if (befor != null) { befor.Next = p; } befor = p; } } }
internal void DrawPolygonCenter(ViewInfo info, CanvasDrawingSession win2d, PolygonUnit polygonUnitValue) { if (polygonUnitValue == PolygonUnit.RulerOrigin) { } else if (polygonUnitValue == PolygonUnit.Symmetry) { /* * Vector2 start = new Vector2(); * Vector2 end = new Vector2(); * CalcReferenceLine(ref start, ref end); * * start *= info.Scale; * end *= info.Scale; * var style = new CanvasStrokeStyle(); * win2d.DrawLine(start, end, Colors.DodgerBlue,2,style); */ } else { var count = Paths.Count; if (RulerVisible) { count--; // 念のため 表示されてもあまり問題ないけど } for (int bx = 0; bx < count; bx++) { var path = Paths[bx]; if (!IsConsistentAsPolygonData((int)polygonUnitValue, path)) { continue; } var center = CalcCenter(path); float xc = center.X * info.Scale; float yc = center.Y * info.Scale; win2d.FillEllipse(xc, yc, 4, 4, Colors.DodgerBlue); } } }
internal bool PointChange(KeyCommand keyCmd, PolygonUnit polygonUnitValue, ViewInfo info) { var item = GetItem(CurrentIndex); if (item == null) { return(false); } int unit = (int)polygonUnitValue; var m_path = Paths[CurrentIndex.BlockIndex]; switch (polygonUnitValue) { case PolygonUnit.unit1: case PolygonUnit.unit2: case PolygonUnit.unit3: case PolygonUnit.unit4: if (!IsConsistentAsPolygonData(unit, m_path)) { return(false); } break; } switch (keyCmd) { case KeyCommand.Home: case KeyCommand.End: case KeyCommand.PageUp: case KeyCommand.PageDown: if (!(polygonUnitValue != PolygonUnit.none || item.IsC() && (CurrentIndex.PartIndex == 0 || CurrentIndex.PartIndex == 1))) { if (item.IsC() && CurrentIndex.PartIndex == 2) { if (keyCmd == KeyCommand.PageUp) { return(RoundCorner(1)); } else if (keyCmd == KeyCommand.PageDown) { return(RoundCorner(-1)); } // 面取り } return(false); } break; } bool res = false; float moveunit = 0.1f; switch (info.MoveUnit) { case MoveUnitDef.normal: moveunit = 1.0f; break; case MoveUnitDef.rough: moveunit = 5.0f; break; } if (keyCmd == KeyCommand.PageUp || keyCmd == KeyCommand.PageDown) { moveunit = 1f; switch (info.MoveUnit) { case MoveUnitDef.normal: moveunit = 5.0f; break; case MoveUnitDef.rough: moveunit = 45.0f; break; } } float dr = 0; float da = 0; float dx = 0; float dy = 0; switch (keyCmd) { case KeyCommand.Home: dr = moveunit; break; case KeyCommand.End: dr = -moveunit; break; case KeyCommand.PageUp: da = moveunit; break; case KeyCommand.PageDown: da = -moveunit; break; case KeyCommand.Up: dy = -moveunit; break; case KeyCommand.Down: dy = moveunit; break; case KeyCommand.Left: dx = -moveunit; break; case KeyCommand.Right: dx = moveunit; break; } Vector2 center = new Vector2(0, 0); if (polygonUnitValue == PolygonUnit.RulerOrigin) { if (RulerVisible) { { var ruler = Paths[Paths.Count - 1]; center = ruler[0].GetPoint(); } } } else if (polygonUnitValue == PolygonUnit.Symmetry) { if (CurrentIndex.BlockIndex == Paths.Count - 1) { var ruler = Paths[Paths.Count - 1]; if (CurrentIndex.ItemIndex == 0) { center = ruler[1].GetPoint(); } else { center = ruler[0].GetPoint(); } } } else if (polygonUnitValue != PolygonUnit.none) { center = CalcCenter(m_path); } res = item.PointChange(polygonUnitValue, CurrentIndex.PartIndex, dx, dy, da, dr, center); if (res && polygonUnitValue == PolygonUnit.Symmetry && Paths.Count - 1 != CurrentIndex.BlockIndex) { // 線対称 int pc = m_path.Count; if (m_path.Count < 2) { return(res); } var i1 = m_path[0]; var i2 = m_path[m_path.Count - 1]; if (i2.IsZ()) { if (m_path.Count < 3) { return(res); } i2 = m_path[m_path.Count - 2]; pc--; } int ti = 0; var ci = pc / 2; if (CurrentIndex.ItemIndex == ci && pc % 2 == 1) { return(res); } if (pc % 2 == 1) { ti = ci + (ci - CurrentIndex.ItemIndex); } else { ti = ci + (ci - 1 - CurrentIndex.ItemIndex); } var rulerlist = Paths[Paths.Count - 1]; var start = rulerlist[0].GetPoint(); var end = rulerlist[1].GetPoint(); m_path[ti].ApplyOtherValue(item, CurrentIndex.PartIndex, start, end); } return(res); }