protected override void OnExecute(Command command, Api.V10.ExecutionContext context, System.Drawing.Rectangle buttonRect) { dashMinSize = Values[Resources.DashSizeText].Value; activeWindow = Window.ActiveWindow; part = activeWindow.ActiveContext.Context as Part; dashLayer = NoteHelper.CreateOrGetLayer(activeWindow.ActiveContext.Context.Document, "Dashes", System.Drawing.Color.AliceBlue); }
protected Gear(IPart parent, GearData gearData, GearData conjugateGearData, ToothProfile toothProfile, double helicalAngle, double depth) { Parent = parent; GearData = gearData; ConjugateGearData = conjugateGearData; ToothProfile = toothProfile; HelicalAngle = helicalAngle; Depth = depth; Period = ToothProfile.GetProfile(); Window activeWindow = Window.ActiveWindow; string name = String.Format(Resources.GearPartNameFormat, GearData.Pitch * activeWindow.Units.Length.ConversionFactor, activeWindow.Units.Length.Symbol, GearData.NumberOfTeeth, GearData.PressureAngle * 180 / Math.PI); Part = Part.Create(Parent.Master.Document, name); Component = Component.Create(parent.Master, Part); Component.Transform(parent.TransformToMaster); GearLayer = NoteHelper.CreateOrGetLayer(Part.Document, Resources.GearLayerName, System.Drawing.Color.LightSteelBlue); PitchCircleLayer = NoteHelper.CreateOrGetLayer(Part.Document, Resources.PitchCircleLayerName, System.Drawing.Color.SteelBlue); PitchCircleLayer.SetVisible(null, false); VisualizationLayer = NoteHelper.CreateOrGetLayer(Part.Document, Resources.VisualizationBodyLayerName, System.Drawing.Color.SteelBlue); AlignmentPart = Part.Create(Part.Document, Resources.AlignmentPlanePartName); AlignmentComponent = Component.Create(Part, AlignmentPart); AlignmentDesBodies = new List <DesignBody>(); AlignmentLayer = NoteHelper.CreateOrGetLayer(Part.Document, Resources.AlignmentPlaneLayerName, System.Drawing.Color.AliceBlue); AlignmentLayer.SetVisible(null, false); }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { areTabsFlipped = Booleans[Resources.FlipTabsText].Value; isTabStartSlot = Booleans[Resources.StartSlotText].Value; edgeOffset = Values[Resources.EdgeOffsetFieldText].Value; activeWindow = Window.ActiveWindow; part = activeWindow.ActiveContext.Context as Part; dashLayer = NoteHelper.CreateOrGetLayer(activeWindow.ActiveContext.Context.Document, "Dashes", System.Drawing.Color.AliceBlue); }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { Part mainPart = Window.ActiveWindow.Scene as Part; Layer layer = NoteHelper.CreateOrGetLayer(mainPart.Document, "Convex Hull", Color.DarkTurquoise); foreach (Part part in mainPart.Components.Select(c => c.Content.Master).Where(p => p.Bodies.Count > 0)) { foreach (Body body in part.Bodies.Select(b => b.Shape)) { foreach (Face face in body.Faces) { foreach (Loop loop in face.Loops.Where(l => l.IsOuter)) { List <Point> points = new List <Point>(); foreach (Fin fin in loop.Fins) { bool wasPreviousLine = false; Line line = fin.Edge.Geometry as Line; if (line != null) { if (!wasPreviousLine) { points.Add(fin.TrueStartPoint()); } points.Add(fin.TrueEndPoint()); wasPreviousLine = true; } Circle circle = fin.Edge.Geometry as Circle; if (circle != null && fin.Edge.Bounds.Span < Math.PI) { continue; } ITrimmedCurve iTrimmedCurve = fin.Edge; double mid = (iTrimmedCurve.Bounds.Start + iTrimmedCurve.Bounds.End) / 2; points.Add(iTrimmedCurve.Geometry.Evaluate(mid).Point); } points.Add(points[0]); foreach (ITrimmedCurve iTrimmedCurve in points.CreatePolyline()) { DesignCurve desCurve = DesignCurve.Create(part, iTrimmedCurve); desCurve.Layer = layer; } } } } } }
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 void Render() { renderedBody = CreateUnfoldedFaceBody(); DesignBody designBody = DesignBody.Create(flatBody.FlatPart, Resources.FlatFaceName, renderedBody); designBody.Layer = NoteHelper.CreateOrGetLayer(Window.ActiveWindow.Document, Resources.FlatFaceLayerName, System.Drawing.Color.Beige); foreach (FlatLoop flatLoop in Loops) { foreach (FlatFin flatFin in flatLoop.Fins.Where(f => !f.IsInternal)) { DesignCurve designCurve = DesignCurve.Create(flatBody.FlatPart, flatFin.SourceFin.Edge); designCurve.Transform(transform); designCurve.Layer = NoteHelper.CreateOrGetLayer(Window.ActiveWindow.Document, Resources.FlatCuttingLinesLayerName, System.Drawing.Color.Blue); } foreach (FlatFin flatFin in flatLoop.Fins.Where(f => f.AdjacentFin != null)) { if ( flatBody.FlatPattern.IsCreatingDashes && Accuracy.CompareAngles(AddInHelper.AngleBetween(flatFin.FlatFace.SourceFace.Geometry.Evaluate(PointUV.Origin).Normal, flatFin.AdjacentFin.FlatFace.SourceFace.Geometry.Evaluate(PointUV.Origin).Normal), flatBody.FlatPattern.BreakAngle) <= 0) { Layer breakLayer = NoteHelper.CreateOrGetLayer(Window.ActiveWindow.Document, Resources.BreakLinesLayerName, System.Drawing.Color.DarkBlue); if (flatBody.FlatPattern.DashSize == 0) { DesignCurve desCurve = DesignCurve.Create(FlatBody.FlatPart, flatFin.AsCurveSegment()); desCurve.Layer = breakLayer; } else { DashesButtonCapsule.CreateDashes(flatFin.AsCurveSegment(), FlatBody.FlatPart, flatBody.FlatPattern.DashSize, breakLayer); } } } } }
protected override void OnExecute(Command command, System.Drawing.Rectangle buttonRect) { activeWindow = Window.ActiveWindow; part = activeWindow.ActiveContext.Context as Part; referenceLayer = NoteHelper.CreateOrGetLayer(activeWindow.ActiveContext.Context.Document, "Layout", System.Drawing.Color.Black); }
public ICollection <DesignBody> CreateSolid(Part mainPart) { var bands = new List <ICollection <Body> >(); var cutters = new List <Body[]>(); double newScale = 0.094; double cutterHeight = 0.01 / newScale; double cutterWidth = 0.0005 / newScale; bool swap = false; for (int i = 0; i < iSteps; i++) { var band = new List <Body>(); //if (i == 4) { // DesignCurve.Create(Window.ActiveWindow.Scene as Part, CurveSegment.Create(points[i][0], points[i][1])); // DesignCurve.Create(Window.ActiveWindow.Scene as Part, CurveSegment.Create(points[i + iSteps / 2][jSteps / 2], points[i + iSteps / 2][jSteps / 2 + 1])); //} for (int j = 0; j < jSteps; j++) { // Main ring Point p00 = points[i][j]; Point p01 = points[i][j + 1]; Point p10 = points[i + 1][j]; Point p11 = points[i + 1][j + 1]; Body b0, b1; if ((p00 - p11).Magnitude < (p10 - p01).Magnitude) { b0 = ShapeHelper.CreatePolygon(new Point[] { p00, p01, p11 }, 0); b1 = ShapeHelper.CreatePolygon(new Point[] { p00, p11, p10 }, 0); } else { b0 = ShapeHelper.CreatePolygon(new Point[] { p01, p10, p00 }, 0); b1 = ShapeHelper.CreatePolygon(new Point[] { p01, p11, p10 }, 0); } // Tabs /* Male Female Male * ---p00last-------p00--------p01-------p10next--- v+ * | | | | * | pn0 | | pn1 | * | | | | * ---p10last-------p10--------p11-------p11next--- * */ Point pn0 = (new Point[] { points[i - 1][j], points[i - 1][j + 1] }).Average(); Point pn1 = (new Point[] { points[i + 2][j], points[i + 2][j + 1] }).Average(); Direction normal0 = Vector.Cross(p01 - pn0, p00 - pn0).Direction; Direction normal1 = Vector.Cross(p10 - pn1, p11 - pn1).Direction; Body tab0 = Tabs.CreateCircularTab(p01, p00, -normal0, tabAngles[i][j], swap); Body tab1 = Tabs.CreateCircularTab(p10, p11, -normal1, tabAngles[i + 1][j], !swap); //DesignBody annotateMe = DesignBody.Create(mainPart, "annotatme", (swap ? tab0 : tab1).Copy()); //NoteHelper.AnnotateFace(mainPart, annotateMe.Faces.First(), string.Format("{0},{1}", i, j), 0.02, null); //annotateMe.Delete(); //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b0.Copy()); //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b1.Copy()); //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab0.Copy()); //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab1.Copy()); try { b0.Unite(new Body[] { b1, tab0, tab1 }); } catch { DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b0.Copy()); DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b1.Copy()); DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab0.Copy()); DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab1.Copy()); return(null); } // Debug.Assert(b0.Shells.Count == 1); band.Add(b0); swap = !swap; } bands.Add(band.TryUnionBodies()); // Cutters Point p0ThisSide0 = points[i][0]; Point p0ThisSide1 = points[i][1]; Point p0OtherSide0 = points[i + iSteps / 2][jSteps / 2]; Point p0OtherSide1 = points[i + iSteps / 2][1 + jSteps / 2]; Point p1ThisSide0 = points[i + 1][0]; Point p1ThisSide1 = points[i + 1][1]; Point p1OtherSide0 = points[i + 1 + iSteps / 2][jSteps / 2]; Point p1OtherSide1 = points[i + 1 + iSteps / 2][1 + jSteps / 2]; Point p0 = CurveSegment.Create(p0ThisSide0, p0ThisSide1).GetInBetweenPoint( CurveSegment.Create(p0OtherSide0, p0OtherSide1 )); Point p1 = CurveSegment.Create(p1ThisSide0, p1ThisSide1).GetInBetweenPoint( CurveSegment.Create(p1OtherSide0, p1OtherSide1 )); //Point p0 = CurveSegment.Create(p0ThisSide0, p0ThisSide1).IntersectCurve( // CurveSegment.Create(p0OtherSide0, p0OtherSide1 //)).First().Point; //Point p1 = CurveSegment.Create(p1ThisSide0, p1ThisSide1).IntersectCurve( // CurveSegment.Create(p1OtherSide0, p1OtherSide1 //)).First().Point; Direction n0 = (p0OtherSide1 - p0OtherSide0).Direction; Direction n1 = (p1OtherSide1 - p1OtherSide0).Direction; Direction d0 = (p0ThisSide1 - p0ThisSide0).Direction; Direction d1 = (p1ThisSide1 - p1ThisSide0).Direction; var profiles = new List <ICollection <ITrimmedCurve> >(); profiles.Add(p0.GetRectanglePointsAround(d0 * cutterHeight, n0 * cutterWidth).GetProfile()); profiles.Add(p1.GetRectanglePointsAround(d1 * cutterHeight, n1 * cutterWidth).GetProfile()); Body cutterA = Body.LoftProfiles(profiles, false, true); profiles = new List <ICollection <ITrimmedCurve> >(); profiles.Add(p0.GetRectanglePointsAround(n0 * cutterHeight, d0 * cutterWidth).GetProfile()); profiles.Add(p1.GetRectanglePointsAround(n1 * cutterHeight, d1 * cutterWidth).GetProfile()); Body cutterB = Body.LoftProfiles(profiles, false, true); cutters.Add(new Body[] { cutterA, cutterB }); } var designBands = new List <DesignBody>(); Layer cutterLayer = NoteHelper.CreateOrGetLayer(mainPart.Document, "Cutters", System.Drawing.Color.DarkViolet); Matrix scaleMatrix = Matrix.CreateScale(scale, Point.Origin); for (int i = 0; i < bands.Count; i++) { int whichCutter = i % 2; Part part = Part.Create(mainPart.Document, string.Format("Band {0:00}", i)); Component.Create(mainPart, part); int ii = i; if (whichCutter == 0) { ii = i + iSteps / 2; } List <Body> mergedCutters = new Body[] { cutters[(ii + iSteps - 1) % iSteps][whichCutter].Copy(), cutters[ii % iSteps][whichCutter].Copy(), cutters[(ii + 1) % iSteps][whichCutter].Copy() }.TryUnionBodies().ToList(); Debug.Assert(mergedCutters.Count == 1, "Couldn't merge cutters"); double nominalRadius = 0.02; double innerRadius = (nominalRadius - cutterWidth / 2) / newScale; double outerRadius = (nominalRadius + cutterWidth / 2) / newScale; var edgeRounds = new List <KeyValuePair <Edge, EdgeRound> >(); foreach (Edge edge in mergedCutters[0].Edges) { if (edge.Length > cutterHeight * 1.1 || edge.Length < cutterHeight * 0.9) { continue; } double angle = edge.GetAngle(); if (Math.Abs(angle) > Math.PI / 4 || angle == 0) { continue; } edgeRounds.Add(new KeyValuePair <Edge, EdgeRound>(edge, new FixedRadiusRound(angle > 0 ? outerRadius : innerRadius))); } mergedCutters[0].RoundEdges(edgeRounds); mergedCutters.Add(cutters[(ii - 1 + iSteps / 2) % iSteps][1 - whichCutter].Copy()); mergedCutters.Add(cutters[(ii + 1 + iSteps / 2) % iSteps][1 - whichCutter].Copy()); HSBColor hsbColor = new HSBColor(0, 100, 200); hsbColor.H = (float)((double)i / bands.Count * 360); var cutBand = new List <Body>(); foreach (Body body in bands[i]) { foreach (Body cutterBody in mergedCutters) { body.Imprint(cutterBody); foreach (Face face in body.Faces) { if (!IsSpanningBody(face, cutterBody)) { continue; } body.DeleteFaces(new Face[] { face }, RepairAction.None); // DesignBody designBody = DesignBody.Create(part, "Cutter", cutterBody.Copy()); // designBody.SetColor(null, hsbColor.Color); } } cutBand.AddRange(body.SeparatePieces()); } cutBand = cutBand.TryUnionBodies().ToList(); //foreach (Body body in bands[i]) { foreach (Body body in cutBand) { body.Transform(scaleMatrix); DesignBody designBody = DesignBody.Create(part, "Band", body); designBody.SetColor(null, hsbColor.Color); designBands.Add(designBody); } //foreach (Body body in mergedCutters) { // DesignBody designBody = DesignBody.Create(part, "Cutter", body); // designBody.Layer = cutterLayer; // hsbColor.H += 180 * whichCutter; // designBody.SetColor(null, hsbColor.Color); //// designBands[i].Shape.Imprint(designBody.Shape); //} } Trace.WriteLine("vParameters"); for (int j = 0; j < jSteps; j++) { for (int i = 0; i < iSteps; i++) { Trace.Write(vParameters[i][j] + " "); } Trace.WriteLine(""); } Trace.WriteLine("tabAngles"); for (int j = 0; j < jSteps; j++) { for (int i = 0; i < iSteps; i++) { Trace.Write(tabAngles[i][j] + " "); } Trace.WriteLine(""); } return(designBands); }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { double lengthConversion = ActiveWindow.Units.Length.ConversionFactor; int numberOfTeethL = (int)Values[Resources.NumberOfTeethLText].Value; int numberOfTeethR = (int)Values[Resources.NumberOfTeethRText].Value; bool isInternalL = numberOfTeethL < 0; bool isInternalR = numberOfTeethR < 0; numberOfTeethL = Math.Abs(numberOfTeethL); numberOfTeethR = Math.Abs(numberOfTeethR); double pressureAngle = Values[Resources.PressureAngleText].Value * Math.PI / 180; double module = Values[Resources.ModuleText].Value / lengthConversion; double dedendumClearance = Values[Resources.DedendumClearanceText].Value; double depth = Values[Resources.DepthText].Value / lengthConversion; bool useTrochoidalInterferenceRemoval = Booleans[Resources.UseTrochoidalText].Value; bool addDedendumClearance = Booleans[Resources.AddDedendumClearance].Value; if (!addDedendumClearance) { dedendumClearance = 0; } bool isBevel = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].IsEnabledCommandBoolean.Value; double bevelAngle = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].Values[Resources.BevelAngleText].Value * Math.PI / 180; double bevelKneeRatio = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].Values[Resources.BevelKneeRatioText].Value; bool isHelical = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHelicalText].IsEnabledCommandBoolean.Value; double helicalAngle = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHelicalText].Values[Resources.HelicalAngleText].Value * Math.PI / 180; if (!isHelical) { helicalAngle = 0; } bool isScrew = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].IsEnabledCommandBoolean.Value; double screwAngle = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].Values[Resources.ScrewAngleText].Value * Math.PI / 180; double screwAngleOffset = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].Values[Resources.ScrewAngleBiasText].Value * Math.PI / 180; if (!isScrew) { screwAngle = 0; screwAngleOffset = 0; } double screwAngleAverage = screwAngle / 2; double screwAngleL = screwAngleAverage + screwAngleOffset; double screwAngleR = screwAngleAverage - screwAngleOffset; bool isHypoid = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].IsEnabledCommandBoolean.Value; double hypoidAngle = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].Values[Resources.HypoidAngleText].Value * Math.PI / 180; double hypoidOffset = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].Values[Resources.HypoidOffsetText].Value / lengthConversion; if (!isHypoid) { hypoidAngle = 0; hypoidOffset = 0; } Frame frame = Frame.World; //Circle circle = SelectedCircle(ActiveWindow); //if (circle != null) // frame = circle.Frame; List <ITrimmedCurve> selectedCurves = ActiveWindow.GetAllSelectedITrimmedCurves().ToList(); if (selectedCurves.Count == 2 && selectedCurves[0].Geometry is Circle && selectedCurves[0].Geometry is Circle) { Circle circle0 = (Circle)selectedCurves[0].Geometry; Circle circle1 = (Circle)selectedCurves[1].Geometry; Separation separation = circle0.Axis.GetClosestSeparation(circle1.Axis); if (Accuracy.LengthIsZero(separation.Distance)) { throw new NotImplementedException("Distance between axes is zero; only hypoid implemented."); } isHypoid = true; hypoidAngle = AddInHelper.AngleBetween(circle0.Axis.Direction, circle1.Axis.Direction); hypoidOffset = ((circle0.Frame.Origin - separation.PointA).Magnitude - depth / 2) / Math.Cos(hypoidAngle / 2); double radiusAApprox = separation.Distance * circle0.Radius / (circle0.Radius + circle1.Radius); double radiusBApprox = separation.Distance - radiusAApprox; numberOfTeethR = (int)Math.Round((double)numberOfTeethL / radiusAApprox * radiusBApprox); module = radiusAApprox * 2 / numberOfTeethL; Point midpoint = separation.PointA + (separation.PointA - separation.PointB) * numberOfTeethL / numberOfTeethR; Direction sideSide = (circle0.Frame.Origin - circle1.Frame.Origin).Direction; frame = Frame.Create(midpoint, Direction.Cross(sideSide, -(midpoint - circle0.GetClosestSeparation(circle1).PointA).Direction), sideSide); } double hypoidAngleL = Math.Atan(Math.Sin(hypoidAngle) / (Math.Cos(hypoidAngle) + (double)numberOfTeethR / numberOfTeethL)); double hypoidAngleR = Math.Atan(Math.Sin(hypoidAngle) / (Math.Cos(hypoidAngle) + (double)numberOfTeethL / numberOfTeethR)); Gear gearL = null; Gear gearR = null; var gearDataL = new GearData(numberOfTeethL, pressureAngle, module, dedendumClearance, isInternalL, screwAngleL); var gearDataR = new GearData(numberOfTeethR, pressureAngle, module, dedendumClearance, isInternalR, screwAngleR); ToothProfile toothProfileL = GetGearProfileFromOptions(gearDataL, gearDataR, useTrochoidalInterferenceRemoval, addDedendumClearance); ToothProfile toothProfileR = GetGearProfileFromOptions(gearDataR, gearDataL, useTrochoidalInterferenceRemoval, addDedendumClearance); if (isBevel) { gearL = BevelGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, bevelAngle, bevelKneeRatio, depth); gearR = BevelGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, bevelAngle, bevelKneeRatio, depth); } else if (isHypoid) { gearL = HypoidGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, hypoidAngleL, hypoidOffset, bevelKneeRatio, depth); gearR = HypoidGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, hypoidAngleR, hypoidOffset, bevelKneeRatio, depth); } else { gearL = StraightGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, screwAngleL, depth); gearR = StraightGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, screwAngleR, depth); } Line zAxis = Line.Create(Point.Origin, Direction.DirZ); gearL.Component.Transform( Matrix.CreateMapping(frame) * Matrix.CreateRotation(zAxis, Math.PI) * gearL.TransformToTangent * Matrix.CreateRotation(zAxis, gearDataL.PitchAngle * ((double)1 / 2 + (gearDataL.NumberOfTeeth % 2 == 0 && !isHypoid ? -1 : 0))) ); gearR.Component.Transform( Matrix.CreateMapping(frame) * gearR.TransformToTangent * Matrix.CreateRotation(zAxis, gearDataR.PitchAngle * ((double)1 / 2 + (gearDataR.NumberOfTeeth % 2 == 0 && !isHypoid ? -1 : 0))) ); // if (gearDataR.NumberOfTeeth % 2 == 0) // gearR.Component.Transform(Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirZ), gearDataR.PitchAngle)); //gearR.Component.Transform(gearR.TransformToTangent); Part parent = ActiveIPart.Master; IDesignFace pitchCircleL = gearL.Component.Content.Bodies.Where(b => b.Master == gearL.PitchCircleDesBody).First().Faces.First(); IDesignFace pitchCircleR = gearR.Component.Content.Bodies.Where(b => b.Master == gearR.PitchCircleDesBody).First().Faces.First(); Part gearMountPart = Part.Create(parent.Document, String.Format(Resources.GearMountPartName, gearDataL.NumberOfTeeth, gearDataR.NumberOfTeeth)); Component gearMountComponent = Component.Create(parent, gearMountPart); DesignBody mountBodyL = DesignBody.Create(gearMountPart, string.Format(Resources.MountBodyName, gearDataL.NumberOfTeeth), pitchCircleL.Master.Shape.Body.CreateTransformedCopy(pitchCircleL.TransformToMaster.Inverse)); DesignBody mountBodyR = DesignBody.Create(gearMountPart, string.Format(Resources.MountBodyName, gearDataR.NumberOfTeeth), pitchCircleR.Master.Shape.Body.CreateTransformedCopy(pitchCircleR.TransformToMaster.Inverse)); IDesignFace mountCircleL = gearMountComponent.Content.Bodies.Where(b => b.Master == mountBodyL).First().Faces.First(); IDesignFace mountCircleR = gearMountComponent.Content.Bodies.Where(b => b.Master == mountBodyR).First().Faces.First(); Layer mountLayer = NoteHelper.CreateOrGetLayer(ActiveDocument, Resources.GearMountAlignmentCircleLayer, System.Drawing.Color.LightGray); mountLayer.SetVisible(null, false); mountBodyL.Layer = mountLayer; mountBodyR.Layer = mountLayer; MatingCondition matingCondition; matingCondition = AnchorCondition.Create(parent, gearMountComponent); matingCondition = AlignCondition.Create(parent, mountCircleL, pitchCircleL); matingCondition = AlignCondition.Create(parent, mountCircleR, pitchCircleR); // matingCondition = TangentCondition.Create(parent, pitchCircleL, pitchCircleR); GearCondition gearCondition = GearCondition.Create(parent, pitchCircleL, pitchCircleR); if (gearDataL.IsInternal ^ gearDataR.IsInternal) { gearCondition.IsBelt = true; } ActiveWindow.InteractionMode = InteractionMode.Solid; Settings.Default.NumberOfTeethL = numberOfTeethL; Settings.Default.NumberOfTeethR = numberOfTeethR; Settings.Default.PressureAngleDegrees = pressureAngle * 180 / Math.PI; Settings.Default.Module = module; Settings.Default.Depth = depth; Settings.Default.DedendumClearance = dedendumClearance; Settings.Default.UseTrochoidalInterferenceRemoval = useTrochoidalInterferenceRemoval; Settings.Default.AddDedendumClearace = addDedendumClearance; Settings.Default.IsBevel = isBevel; if (isBevel) { Settings.Default.BevelAngle = bevelAngle * 180 / Math.PI; Settings.Default.BevelKneeRatio = bevelKneeRatio; } Settings.Default.IsHelical = isHelical; Settings.Default.HelicalAngle = helicalAngle * 180 / Math.PI; Settings.Default.IsScrew = isScrew; Settings.Default.ScrewAngle = screwAngle * 180 / Math.PI; Settings.Default.ScrewAngleOffset = screwAngleOffset * 180 / Math.PI; Settings.Default.IsHypoid = isHypoid; Settings.Default.HypoidAngle = hypoidAngle * 180 / Math.PI; Settings.Default.HypoidOffset = hypoidOffset * lengthConversion; Settings.Default.Save(); }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, context, buttonRect); Window activeWindow = Window.ActiveWindow; Part activePart = (activeWindow.Scene as Part); Layer tabLayer = NoteHelper.CreateOrGetLayer(activeWindow.ActiveContext.Context.Document, "Tabs", System.Drawing.Color.Fuchsia); IDesignEdge iDesignEdge = activeWindow.ActiveContext.SingleSelection as IDesignEdge; if (iDesignEdge == null) { return; } if (iDesignEdge.Faces.Count != 1) { return; } IDesignFace iDesignFace = null; foreach (IDesignFace testFace in iDesignEdge.Faces) { iDesignFace = testFace; } Debug.Assert(iDesignFace != null); Point startPoint = iDesignEdge.Shape.StartPoint; Point endPoint = iDesignEdge.Shape.EndPoint; if (areTabsFlipped) { Point tempPoint = startPoint; startPoint = endPoint; endPoint = tempPoint; } SurfaceEvaluation surfEval = iDesignFace.Shape.ProjectPoint(startPoint); Direction faceNormal = surfEval.Normal; Point midpoint = startPoint + (endPoint - startPoint) / 2; Double edgeLength = iDesignEdge.Shape.Length; Direction xDir = (endPoint - startPoint).Direction; List <Window> tabWindows = null; string tabFile = string.Empty; if (!isTabStartSlot) { tabFile = @"C:\Users\bcr.SPACECLAIM\Documents\Models\Dodecahedron Foldcrease\Tab-Circle-Male.scdoc"; } else { tabFile = @"C:\Users\bcr.SPACECLAIM\Documents\Models\Dodecahedron Foldcrease\Tab-Circle-Female.scdoc"; } try { tabWindows = new List <Window>(Document.Open(tabFile, ImportOptions.Create())); } catch (Exception exception) { System.Windows.Forms.MessageBox.Show(SpaceClaim.Api.V10.Application.MainWindow, exception.Message); } DesignBody tabDesignBody = null; foreach (DesignBody testBody in (tabWindows[0].Scene as Part).Bodies) { tabDesignBody = testBody; } Debug.Assert(tabDesignBody != null); tabDesignBody = DesignBody.Create(activePart, "tab", tabDesignBody.Shape.Body.Copy()); foreach (Window window in tabWindows) { window.Delete(); } Matrix scale = Matrix.CreateScale(edgeLength / 0.02, Point.Origin); Matrix trans = Matrix.CreateMapping(Frame.Create(midpoint, xDir, Direction.Cross(faceNormal, xDir))); tabDesignBody.Transform(trans * scale); tabDesignBody.Layer = tabLayer; }
// hardwired to place on about inch-spaced points // Edge-only for now -- See EO comments static void MakeTabs_Executing(object sender, EventArgs e) { Window activeWindow = Window.ActiveWindow; Layer tabLayer = NoteHelper.CreateOrGetLayer(activeWindow.ActiveContext.Context.Document, "Tabs", System.Drawing.Color.Fuchsia); ICollection <ITrimmedCurve> trimmedCurves = AddInHelper.GetITrimmedCurvesOfSelectedTopology(activeWindow); // quantize with lines to points separated by approx targetDistance; TrimmedCurveChain curveChain = new TrimmedCurveChain(trimmedCurves); Point lastPoint = curveChain.Curves[0].StartPoint; double tolerance = 0.2 * inches; double targetDistance = 1 * inches; trimmedCurves = new List <ITrimmedCurve>(); Dictionary <ITrimmedCurve, Direction> OriginalNormals = new Dictionary <ITrimmedCurve, Direction>(); double extraLength = 0; foreach (OrientedTrimmedCurve curve in curveChain.Curves) { Point point = curve.EndPoint; if (Math.Abs((lastPoint - point).Magnitude - targetDistance) > tolerance) { extraLength += (lastPoint - point).Magnitude; continue; } CurveSegment curveSegment = null; // if (extraLength == 0) curveSegment = CurveSegment.Create(lastPoint, point); // else // curveSegment = CurveSegment.Create(point - (lastPoint - point).Direction * ((lastPoint - point).Magnitude + extraLength), point); trimmedCurves.Add(curveSegment); Edge edge = curve.TrimmedCurve as Edge; if (edge != null) { Face face = null; foreach (Face testFace in edge.Faces) { face = testFace; break; } SurfaceEvaluation surfEval = face.ProjectPoint(curve.StartPoint); OriginalNormals[curveSegment] = surfEval.Normal; } lastPoint = point; // extraLength = 0; } curveChain = new TrimmedCurveChain(trimmedCurves); if (AreTabsFlipped) { curveChain.Reverse(); } List <Window> curveWindows = new List <Window>(Document.Open(@"C:\Users\bcr.SPACECLAIM\Documents\Models\Pod Tent\TabCurve.scdoc", false)); bool adjustEnds = true; #if false List <Window> curveWindows = new List <Window>(Document.Open(@"C:\Users\bcr.SPACECLAIM\Documents\Models\Pod Tent\TabStrapEdgeCurve.scdoc", false)); bool adjustEnds = true; #endif NurbsCurve middle = GetFirstNurbsCurveFromPart(curveWindows[0].Scene as Part); Debug.Assert(middle != null); NurbsCurve endTab = null; NurbsCurve endSlot = null; foreach (Component component in (curveWindows[0].Scene as Part).Components) { if (component.Template.Name == "EndTab") { endTab = GetFirstNurbsCurveFromPart(component.Template); } if (component.Template.Name == "EndSlot") { endSlot = GetFirstNurbsCurveFromPart(component.Template); } } Debug.Assert(endTab != null); Debug.Assert(endSlot != null); Point startPoint = curveChain.Curves[0].StartPoint; Point endPoint = curveChain.Curves[0].EndPoint; Point startTail = startPoint + (endPoint - startPoint); bool mirror = false; if (IsTabStartSlot) { NurbsCurve tmp = endTab; endTab = endSlot; endSlot = tmp; mirror = !mirror; } for (int i = 0; i < curveChain.Curves.Count; i++) { Point endTail; if (i == curveChain.Curves.Count - 1) { endTail = curveChain.Curves[i].EndPoint + (curveChain.Curves[i].EndPoint - curveChain.Curves[i].StartPoint); } else { endTail = curveChain.Curves[i + 1].EndPoint; } Point mid = Point.Origin + (startPoint.Vector + endPoint.Vector) / 2; Direction startDirection = (startPoint - startTail).Direction; Direction lineDirection = (endPoint - startPoint).Direction; Direction endDirection = (endTail - endPoint).Direction; Direction upDirection = Direction.DirZ; //if (upDirection.IsParallelTo(lineDirection)) // upDirection = Direction.DirY; if (OriginalNormals.ContainsKey(curveChain.Curves[i].TrimmedCurve)) { upDirection = OriginalNormals[curveChain.Curves[i].TrimmedCurve]; } Direction normalDirection = Direction.Cross(lineDirection, upDirection); Line startMidLine; if (startDirection.UnitVector == lineDirection.UnitVector) { startMidLine = Line.Create(startPoint, Direction.Cross(lineDirection, upDirection)); } else { startMidLine = Line.Create(startPoint, (startDirection.UnitVector - lineDirection.UnitVector).Direction); } Line endMidLine; if (lineDirection.UnitVector == endDirection.UnitVector) { endMidLine = Line.Create(endPoint, Direction.Cross(lineDirection, upDirection)); } else { endMidLine = Line.Create(endPoint, (lineDirection.UnitVector - endDirection.UnitVector).Direction); } NurbsCurve template = middle; if (mirror) { lineDirection = -lineDirection; Line tmp = startMidLine; startMidLine = endMidLine; endMidLine = tmp; } if (i == 0) { template = endSlot; } if (i == curveChain.Curves.Count - 1) { if (mirror ^ IsTabStartSlot) { template = endSlot; } else { template = endTab; } } Frame frame = Frame.Create(mid, lineDirection, normalDirection); Matrix transform = Matrix.CreateMapping(frame); ControlPoint[] controlPoints = new ControlPoint[template.ControlPoints.Length]; int j = 0; foreach (ControlPoint controlPoint in template.ControlPoints) { controlPoints[j] = new ControlPoint(transform * controlPoint.Position, controlPoint.Weight); j++; } //CurveEvaluation curveEval = null; //curveEval = startMidLine.Evaluate(1); //DesignCurve.Create(activeWindow.SubjectMatter as Part, CurveSegment.Create(startPoint, curveEval.Point)); //curveEval = endMidLine.Evaluate(1); //DesignCurve.Create(activeWindow.SubjectMatter as Part, CurveSegment.Create(endPoint, curveEval.Point)); MakeNurbsEndTangent(endMidLine, controlPoints, 0, 1); if (adjustEnds) { MakeNurbsEndTangent(startMidLine, controlPoints, controlPoints.Length - 1, controlPoints.Length - 2); } Curve curve = NurbsCurve.Create(template.Data, controlPoints); CurveSegment curveSegment = CurveSegment.Create(curve, template.Parameterization.Range.Value); DesignCurve tab = DesignCurve.Create(activeWindow.ActiveContext.Context as Part, curveSegment); tab.Layer = tabLayer; startTail = startPoint; startPoint = endPoint; endPoint = endTail; mirror = !mirror; } foreach (Window window in curveWindows) { window.Close(); } }