void Unfold(Body body, Face startFace, bool isDetectingCollisions, bool isCreatingDashes, double breakAngle, double dashSize) { DateTime startTime = DateTime.Now; FlatPattern flatPattern = new FlatPattern(body, startFace, isDetectingCollisions, isCreatingDashes, breakAngle, dashSize, Resources.FlatPatternText); DateTime calcTime = DateTime.Now; double calcDuration = (calcTime - startTime).TotalSeconds; flatPattern.Render(); double drawDuration = (DateTime.Now - calcTime).TotalSeconds; int n = 0; foreach (FlatBody flatBody in flatPattern.FlatBodies) { foreach (FlatFace flatFace in flatBody.FlatFaces) { foreach (FlatLoop flatLoop in flatFace.Loops) { n++; } } } string output = String.Format("Unfolded {0:D} faces in {1:F} s. ({2:F} fps.) \n", n, Math.Round(calcDuration, 2), Math.Round((double)n / calcDuration, 2)) + String.Format("Modeled {0:F} seconds. ({1:F} fps.)", Math.Round(drawDuration, 2), Math.Round((double)n / drawDuration, 2)) ; Application.ReportStatus(output, StatusMessageType.Information, null); }
public void AddFace(FlatFace flatFace) { flatFaces.Add(flatFace); flatPattern.FlatFaceMapping[flatFace.SourceFace] = flatFace; foreach (FlatLoop flatLoop in flatFace.Loops) { foreach (FlatFin flatFin in flatLoop.Fins) { Face testFace = flatFin.FlatFace.SourceFace.GetAdjacentFace(flatFin.SourceFin.Edge); if (testFace == null) // one-sided (laminar) edge { continue; } if (!FlatPattern.FlatFaceExists(testFace)) { openFins.Add(flatFin); } List <FlatFin> removeFins = new List <FlatFin>(); foreach (FlatFin baseFin in openFins) { if (baseFin.SourceFin.Edge.Equals(flatFin.SourceFin.Edge) && !baseFin.FlatFace.Equals(flatFace)) { removeFins.Add(baseFin); } } foreach (FlatFin removeFin in removeFins) { openFins.Remove(removeFin); } } } openFins.Sort(new FlatFin.FlatFinComparer()); // get longest fin --TBD use sorted list structure? openFins.Reverse(); if (flatPattern.IsDetectingIntersections) { Body body = flatFace.CreateUnfoldedFaceBody(); if (flatBodyShape == null) { flatBodyShape = body; } else { try { flatBodyShape.Unite(new Body[] { body }); } catch { DesignBody.Create(Window.ActiveWindow.Scene as Part, "flatBodyShape", flatBodyShape); DesignBody.Create(Window.ActiveWindow.Scene as Part, "tool", body); Debug.Fail("Boolean failed when merging flatBodyShape."); } } } }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { //isDetectingCollisions = Booleans[Resources.DetectCollisionsText].Value; //isCreatingDashes = Booleans[Resources.CreateDashesText].Value; Part part = Window.ActiveWindow.Scene as Part; if (part == null) { return; } Layer curveLayer = NoteHelper.CreateOrGetLayer(Window.ActiveWindow.Document, Resources.FlatMediumEngravingLayerName, System.Drawing.Color.Green); Layer planeLayer = NoteHelper.CreateOrGetLayer(part.Document, Resources.AnnotationPlanesLayerName, Color.Gray); planeLayer.SetVisible(null, false); foreach (Component component in part.Components) { Body body = component.Content.Bodies.First().Master.Shape.Copy(); body.Transform(component.Content.TransformToMaster.Inverse); Face startFace = body.Faces.First(); string name = component.Content.Master.Name; FlatPattern flatPattern = new FlatPattern(body, startFace, isDetectingCollisions, false, 0, 0, name); flatPattern.Render(); DatumPlane datumPlane = DatumPlane.Create(flatPattern.FlatPart, Resources.AnnotationPlaneName, flatPattern.PaperPlane); datumPlane.Layer = planeLayer; PointUV center = flatPattern.PaperPlane.ProjectPoint(flatPattern.GetBoundingBox(Matrix.Identity).Center).Param; Note note = Note.Create(datumPlane, center, TextPoint.Center, 0.01, name); note.Layer = NoteHelper.CreateOrGetLayer(part.Document, Resources.AnnotationLayerName, System.Drawing.Color.DarkViolet); foreach (FlatBody flatBody in flatPattern.FlatBodies) { foreach (FlatFace flatFace in flatBody.FlatFaces) { foreach (ITrimmedCurve iTrimmedCurve in part.Curves.Select(c => c.Shape).Where(c => c.AreEndPointsOnFace(flatFace.SourceFace))) { var designCurve = DesignCurve.Create(flatBody.FlatPart, iTrimmedCurve); designCurve.Transform(flatFace.Transform); designCurve.Layer = curveLayer; } } } } }
public FlatBody(FlatPattern flatPattern) { this.flatPattern = flatPattern; if (flatPattern.IsDetectingIntersections) { this.flatPart = Part.Create(flatPattern.FlatPart.Document, "Flat Part"); Debug.Assert(flatPart != null, "flatPart != null"); Component flatComponent = Component.Create(flatPattern.FlatPart, flatPart); Debug.Assert(flatComponent != null, "flatComponent != null"); } else { Part mainPart = Window.ActiveWindow.ActiveContext.Context as Part; this.flatPart = flatPattern.FlatPart; } }