public void FlipAndCopyWithPlane(List <CadFigure> rootFigList, Vector3d p0, Vector3d normal) { List <CadFigure> cpy = PlotterClipboard.CopyFigures(rootFigList); CadOpeList opeRoot = new CadOpeList(); CadLayer layer = Controller.CurrentLayer; foreach (CadFigure fig in cpy) { fig.ForEachFig(f => { FlipWithPlane(f, p0, normal); Controller.DB.AddFigure(f); }); layer.AddFigure(fig); CadOpe ope = new CadOpeAddFigure(layer.ID, fig.ID); opeRoot.OpeList.Add(ope); } Controller.HistoryMan.foward(opeRoot); RunOnMainThread(() => { Controller.Redraw(); Controller.UpdateObjectTree(remakeTree: true); }); }
public void SeparateFigures(CadFigure fig, int pointIdx) { var res = CadFigureCutter.Cut(mDB, fig, pointIdx); if (!res.isValid()) { return; } CadOpeList opeRoot = new CadOpeList(); CadOpe ope; foreach (EditResult.Item ri in res.AddList) { CadLayer layer = mDB.GetLayer(ri.LayerID); ope = new CadOpeAddFigure(ri.LayerID, ri.FigureID); opeRoot.OpeList.Add(ope); layer.AddFigure(ri.Figure); } foreach (EditResult.Item ri in res.RemoveList) { CadLayer layer = mDB.GetLayer(ri.LayerID); ope = new CadOpeRemoveFigure(layer, ri.FigureID); opeRoot.OpeList.Add(ope); layer.RemoveFigureByID(ri.FigureID); } HistoryMan.foward(opeRoot); }
private CadOpeList RemoveInvalidFigure() { CadOpeList opeList = new CadOpeList(); int removeCnt = 0; foreach (CadLayer layer in mDB.LayerList) { IReadOnlyList <CadFigure> list = layer.FigureList; int i = list.Count - 1; for (; i >= 0; i--) { CadFigure fig = list[i]; if (fig.IsGarbage()) { CadOpe ope = new CadOpeRemoveFigure(layer, fig.ID); opeList.OpeList.Add(ope); layer.RemoveFigureByIndex(i); removeCnt++; } } } if (removeCnt > 0) { UpdateObjectTree(true); } return(opeList); }
public void SetLoop(bool isLoop) { List <uint> list = DB.GetSelectedFigIDList(); CadOpeList opeRoot = new CadOpeList(); CadOpe ope; foreach (uint id in list) { CadFigure fig = DB.GetFigure(id); if (fig.Type != CadFigure.Types.POLY_LINES) { continue; } if (fig.IsLoop != isLoop) { fig.IsLoop = isLoop; if (isLoop) { fig.RecalcNormal(); } ope = new CadOpeSetClose(CurrentLayer.ID, id, isLoop); opeRoot.OpeList.Add(ope); } } HistoryMan.foward(opeRoot); }
public static void PasteFiguresAsBin(PlotterController controller) { if (!Clipboard.ContainsData(CadClipBoard.TypeNameBin)) { return; } byte[] bin = (byte[])Clipboard.GetData(CadClipBoard.TypeNameBin); List <CadFigure> figList = BinToFigList(bin); // Pase figures in fig list Vector3d pp = controller.LastDownPoint; MinMax3D mm3d = CadUtil.GetFigureMinMaxIncludeChild(figList); Vector3d d = pp - mm3d.GetMinAsVector(); CadOpeList opeRoot = new CadOpeList(); foreach (CadFigure fig in figList) { PasteFigure(controller, fig, d); controller.CurrentLayer.AddFigure(fig); // 子ObjectはLayerに追加しない CadOpe ope = new CadOpeAddFigure(controller.CurrentLayer.ID, fig.ID); opeRoot.OpeList.Add(ope); } controller.HistoryMan.foward(opeRoot); }
public void Group(List <CadFigure> targetList) { List <CadFigure> list = FilterRootFigure(targetList); if (list.Count < 2) { ItConsole.println( global::KCad.Properties.Resources.error_select_2_or_more ); return; } CadFigure parent = Controller.DB.NewFigure(CadFigure.Types.GROUP); CadOpeList opeRoot = new CadOpeList(); CadOpe ope; foreach (CadFigure fig in list) { int idx = Controller.CurrentLayer.GetFigureIndex(fig.ID); if (idx < 0) { continue; } ope = new CadOpeRemoveFigure(Controller.CurrentLayer, fig.ID); opeRoot.Add(ope); Controller.CurrentLayer.RemoveFigureByIndex(idx); parent.AddChild(fig); } Controller.CurrentLayer.AddFigure(parent); ope = new CadOpeAddChildlen(parent, parent.ChildList); opeRoot.Add(ope); ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, parent.ID); opeRoot.Add(ope); Session.AddOpe(opeRoot); ItConsole.println( global::KCad.Properties.Resources.notice_was_grouped ); Session.PostRemakeObjectTree(); }
public void ToPolyLine(uint id) { CadFigure fig = Controller.DB.GetFigure(id); if (!(fig is CadFigureMesh)) { return; } CadFigureMesh figMesh = (CadFigureMesh)fig; HeModel hm = figMesh.mHeModel; CadFigure figPoly = Controller.DB.NewFigure(CadFigure.Types.POLY_LINES); hm.ForReachEdgePoint(v => { figPoly.AddPoint(v); }); if (figPoly.PointCount < 1) { return; } figPoly.IsLoop = true; CadOpeList opeRoot = new CadOpeList(); CadOpe ope; ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, figPoly.ID); opeRoot.Add(ope); Controller.CurrentLayer.AddFigure(figPoly); ope = new CadOpeRemoveFigure(Controller.CurrentLayer, fig.ID); opeRoot.Add(ope); Controller.CurrentLayer.RemoveFigureByID(fig.ID); Session.AddOpe(opeRoot); Env.RunOnMainThread(() => { Controller.ClearSelection(); }); Session.PostRemakeObjectTree(); }
private void testMesh() { var figlist = Controller.DB.GetSelectedFigList(); CadOpeList opeRoot = new CadOpeList(); CadOpe ope; for (int i = 0; i < figlist.Count; i++) { CadFigure fig = figlist[i]; if (fig == null) { continue; } if (fig.Type != CadFigure.Types.POLY_LINES) { continue; } CadFigureMesh mesh = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH); mesh.CreateModel(fig); ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, mesh.ID); opeRoot.Add(ope); Controller.CurrentLayer.AddFigure(mesh); ope = new CadOpeRemoveFigure(Controller.CurrentLayer, fig.ID); opeRoot.Add(ope); Controller.CurrentLayer.RemoveFigureByID(fig.ID); } if (opeRoot.OpeList.Count > 0) { Controller.HistoryMan.foward(opeRoot); } Controller.UpdateObjectTree(true); }
public void ClearLayer(uint layerID) { if (layerID == 0) { layerID = CurrentLayer.ID; } CadLayer layer = mDB.GetLayer(layerID); if (layer == null) { return; } CadOpeList opeList = layer.Clear(); HistoryMan.foward(opeList); }
public void InvertDir() { List <CadFigure> figList = Controller.DB.GetSelectedFigList(); CadOpeList opeRoot = new CadOpeList(); CadOpeInvertDir ope; for (int i = 0; i < figList.Count; i++) { CadFigure fig = figList[i]; fig.InvertDir(); ope = new CadOpeInvertDir(fig.ID); opeRoot.Add(ope); } Session.AddOpe(opeRoot); }
public void CutSegment(MarkSegment ms) { if (!ms.Valid) { return; } if (!ms.CrossPoint.IsValid()) { return; } var res = CadSegmentCutter.CutSegment(mDB, ms, ms.CrossPoint); if (!res.isValid()) { return; } CadOpeList opeRoot = new CadOpeList(); CadOpe ope; foreach (EditResult.Item ri in res.AddList) { CadLayer layer = mDB.GetLayer(ri.LayerID); ope = new CadOpeAddFigure(ri.LayerID, ri.FigureID); opeRoot.OpeList.Add(ope); layer.AddFigure(ri.Figure); } foreach (EditResult.Item ri in res.RemoveList) { CadLayer layer = mDB.GetLayer(ri.LayerID); ope = new CadOpeRemoveFigure(layer, ri.FigureID); opeRoot.OpeList.Add(ope); layer.RemoveFigureByID(ri.FigureID); } HistoryMan.foward(opeRoot); }
public void FlipNormal() { List <uint> ids = DB.GetSelectedFigIDList(); CadOpeList opeList = new CadOpeList(); foreach (uint id in ids) { CadFigure fig = mDB.GetFigure(id); Vector3d old = fig.Normal; fig.Normal *= -1; CadOpe ope = new CadOpeChangeNormal(id, old, fig.Normal); opeList.Add(ope); } HistoryMan.foward(opeList); }
public void Ungroup(List <CadFigure> targetList) { List <CadFigure> list = FilterRootFigure(targetList); CadOpeList opeList = new CadOpeList(); CadOpe ope; foreach (CadFigure root in list) { root.ForEachFig((fig) => { if (fig.Parent == null) { return; } fig.Parent = null; if (fig.PointCount > 0) { ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, fig.ID); opeList.Add(ope); Controller.CurrentLayer.AddFigure(fig); } }); ope = new CadOpeRemoveFigure(Controller.CurrentLayer, root.ID); opeList.Add(ope); Controller.CurrentLayer.RemoveFigureByID(root.ID); } Session.AddOpe(opeList); ItConsole.println( KCad.Properties.Resources.notice_was_ungrouped ); Session.PostRemakeObjectTree(); }
// 押し出し public void Extrude(uint id, Vector3d v, double d, int divide) { CadFigure tfig = Controller.DB.GetFigure(id); if (tfig == null || tfig.Type != CadFigure.Types.POLY_LINES) { return; } v = v.UnitVector(); v *= -d; CadMesh cm = MeshMaker.CreateExtruded(tfig.GetPoints(16), v, divide); HeModel hem = HeModelConverter.ToHeModel(cm); CadFigureMesh fig = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH); fig.RecalcNormal(); fig.SetMesh(hem); CadOpeList root = new CadOpeList(); CadOpe ope; ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, fig.ID); root.Add(ope); ope = new CadOpeRemoveFigure(Controller.CurrentLayer, tfig.ID); root.Add(ope); Session.AddOpe(root); Controller.CurrentLayer.AddFigure(fig); Controller.CurrentLayer.RemoveFigureByID(tfig.ID); Session.PostRemakeObjectTree(); }
public void CutMeshWithVector(CadFigureMesh tfig, Vector3d p0, Vector3d p1, Vector3d normal) { HeModel he = tfig.mHeModel; CadMesh src = HeModelConverter.ToCadMesh(he); (CadMesh m1, CadMesh m2) = MeshUtil.CutMeshWithVector(src, p0, p1, normal); if (m1 == null || m2 == null) { return; } CadFigureMesh fig1 = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH); fig1.SetMesh(HeModelConverter.ToHeModel(m1)); CadFigureMesh fig2 = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH); fig2.SetMesh(HeModelConverter.ToHeModel(m2)); CadOpeList opeRoot = new CadOpeList(); CadOpe ope; ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, fig1.ID); opeRoot.Add(ope); Controller.CurrentLayer.AddFigure(fig1); ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, fig2.ID); opeRoot.Add(ope); Controller.CurrentLayer.AddFigure(fig2); ope = new CadOpeRemoveFigure(Controller.CurrentLayer, tfig.ID); opeRoot.Add(ope); Controller.CurrentLayer.RemoveFigureByID(tfig.ID); Controller.HistoryMan.foward(opeRoot); }
public void EndEdit(List <CadFigure> targetList) { foreach (CadFigure fig in targetList) { if (fig != null) { fig.EndEdit(); } } CadOpeList root = new CadOpeList(); CadOpeList rmOpeList = RemoveInvalidFigure(); root.Add(rmOpeList); mSnapShotList.StoreAfter(DB); root.Add(mSnapShotList); HistoryMan.foward(root); mSnapShotList = null; }
// option: // e.g. // a100q30 max area = 100, min degree = 30 // a100q max area = 100, min degree = default (20) // min degree < 34 // Other options see // https://www.cs.cmu.edu/~quake/triangle.switch.html // public void Triangulate(uint figID, string option) { CadFigure tfig = Controller.DB.GetFigure(figID); if (tfig == null || tfig.Type != Types.POLY_LINES) { return; } if (tfig.PointCount < 3) { return; } CadFigure cfig = FigUtil.Clone(tfig); Vector3d org = cfig.PointList[0].vector; Vector3d dir = Vector3d.UnitZ; Vector3d faceNormal = CadUtil.TypicalNormal(cfig.PointList); Vector3d rotateV = default; double t = 0; if (!faceNormal.EqualsThreshold(dir) && !(-faceNormal).EqualsThreshold(dir)) { rotateV = CadMath.Normal(faceNormal, dir); t = -CadMath.AngleOfVector(faceNormal, dir); CadUtil.RotateFigure(cfig, org, rotateV, t); } //Controller.CurrentLayer.AddFigure(cfig); VertexList vl = cfig.GetPoints(12); CadMesh m = IglW.Triangulate(vl, option); HeModel hem = HeModelConverter.ToHeModel(m); CadFigureMesh fig = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH); fig.SetMesh(hem); for (int i = 0; i < fig.PointCount; i++) { CadVertex v = fig.PointList[i]; v.Z = org.Z; fig.PointList[i] = v; } if (t != 0) { CadUtil.RotateFigure(fig, org, rotateV, -t); } CadOpeList root = new CadOpeList(); CadOpe ope; ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, fig.ID); Session.AddOpe(ope); Controller.CurrentLayer.AddFigure(fig); ope = new CadOpeRemoveFigure(Controller.CurrentLayer, figID); Session.AddOpe(ope); Controller.CurrentLayer.RemoveFigureByID(figID); Controller.CurrentFigure = null; Session.PostRemakeObjectTree(); }
public void ToMesh(uint id) { CadOpeList opeRoot = new CadOpeList(); CadOpe ope; CadFigure orgFig = Controller.DB.GetFigure(id); if (orgFig == null) { return; } if (orgFig.Type != CadFigure.Types.POLY_LINES) { return; } CadFigureMesh mesh = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH); mesh.CreateModel(orgFig); foreach (CadFigure fig in orgFig.ChildList) { mesh.AddChild(fig); } CadFigure parent = orgFig.Parent; if (parent != null) { int index = orgFig.Parent.ChildList.IndexOf(orgFig); // Remove original poly lines object ope = new CadOpeRemoveChild(parent, orgFig, index); opeRoot.Add(ope); orgFig.Parent.ChildList.Remove(orgFig); // Insert mesh object ope = new CadOpeAddChild(parent, mesh, index); opeRoot.Add(ope); orgFig.Parent.ChildList.Insert(index, mesh); mesh.Parent = parent; } else { // Remove original poly lines object ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, mesh.ID); opeRoot.Add(ope); Controller.CurrentLayer.AddFigure(mesh); // Insert mesh object ope = new CadOpeRemoveFigure(Controller.CurrentLayer, orgFig.ID); opeRoot.Add(ope); Controller.CurrentLayer.RemoveFigureByID(orgFig.ID); } Session.AddOpe(opeRoot); Env.RunOnMainThread(() => { Controller.ClearSelection(); }); Session.PostRemakeObjectTree(); //PrintSuccess(); }