protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { InteractionContext activeContext = Window.ActiveWindow.ActiveContext; Part mainPart = Window.ActiveWindow.Scene as Part; #if false foreach (Part part in mainPart.Components.Select(c => c.Content.Master).Where(p => p.Bodies.Count > 1)) { ICollection <Body> bodies = part.Bodies.Select(b => b.Shape).TryUnionBodies2(); foreach (DesignBody desBody in part.Bodies) { desBody.Delete(); } foreach (Body body in bodies) { DesignBody.Create(part, "merged", body); } } #else foreach (IPart iPart in mainPart.Components.Select(c => c.Content).Where(p => p.Bodies.Count > 1)) { activeContext.Selection = iPart.Bodies.Cast <IDocObject>().ToArray(); Command.Execute("IntersectTool"); //Combine // System.Threading.Thread.Sleep(4000); Command.Execute("Select"); } #endif }
public static DesignBody CreateBar(Part part) { Debug.Assert(part != null, "part != null"); double barRadius = 0.002; double barLenght = 0.020; Point pointStart = Point.Create(0, 0, 0); Point pointEnd = Point.Create(0, 0.04, 0.05); DesignCurve.Create(part, CurveSegment.Create(pointStart, pointEnd)); Body cylinder1 = Body.ExtrudeProfile(new CircleProfile(Plane.PlaneZX, barRadius), barLenght); DesignBody.Create(part, "Cylinder1", cylinder1); Body cylinder2 = Body.ExtrudeProfile(new CircleProfile(Plane.PlaneXY, barRadius), barLenght); DesignBody.Create(part, "Cylinder2", cylinder2); Body cylinder3 = Body.ExtrudeProfile(new CircleProfile(Plane.PlaneYZ, barRadius), barLenght); return(DesignBody.Create(part, "Cylinder3", cylinder3)); }
//static Plane CreatePlane(Point origin, Direction normal) //{ // return Plane.Create(Frame.Create(origin, normal)); //} static DesignBody CreatePPBar(Part part) { Window window = Window.ActiveWindow; Debug.Assert(part != null, "part 1= null"); double barRadius = 0.002; double barLenght = 0.020; Point pointStart = Point.Create(0, 0.03, 0.07); Point pointEnd = Point.Create(0.02, 0.04, 0.09); DesignCurve.Create(part, CurveSegment.Create(pointStart, pointEnd)); //Plane plane = CreatePlane(pointStart, normal); //DesignCurve line = DesignCurve.Create(); //Direction direction = Direction.Equals(CurveSegment); //Frame frame = Frame.Create(pointStart); //Plane plane = Plane.Create(frame); Body bar = Body.ExtrudeProfile(new CircleProfile(Plane.PlaneYZ, barRadius), barLenght); return(DesignBody.Create(part, "Cylinder", bar)); }
public override Color?ColorForBody(DesignBody designBody) { Color color = designBody.GetVisibleColor(); HSBColor hsbColor = HSBColor.FromColor(color); return(HSBColor.ShiftSaturation(color, RandomMiddleRGB() - hsbColor.S)); }
static void notesImagePlanar_Executing(object sender, EventArgs e) { Bitmap bitmap = OpenBitmap(); if (bitmap == null) { return; } Part part = CreateImagePart(); Point[] points = new Point[4]; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { points[0] = Point.Create((i + 0) * stepSize, (j + 0) * stepSize, 0); points[1] = Point.Create((i + 1) * stepSize, (j + 0) * stepSize, 0); points[2] = Point.Create((i + 1) * stepSize, (j + 1) * stepSize, 0); points[3] = Point.Create((i + 0) * stepSize, (j + 1) * stepSize, 0); DesignBody designBody = ShapeHelper.CreatePolygon(points, Plane.PlaneXY, 0, part); designBody.SetColor(null, GetOpaquePixel(bitmap, i, j)); } } }
public static DesignBody CreateTransformedCopy(this DesignBody desBody, Matrix trans) { Body body = desBody.Shape.Copy(); body.Transform(trans); return(DesignBody.Create(desBody.Parent, desBody.Name, body)); }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { double lengthConversion = ActiveWindow.Units.Length.ConversionFactor; bool isImperial = Booleans[Resources.IsImperial].Value; bool isInternal = Booleans[Resources.ThreadIsInternal].Value; double pitch = isImperial ? (Const.inches / Values[Resources.ThreadPitch].Value) : (1E-3 * Values[Resources.ThreadPitch].Value); double angle = Values[Resources.ThreadAngle].Value * Math.PI / 180; Body[] bodies = SpaceClaimExtensions.GetAllSelectedIDesignFaces(Window.ActiveWindow) .Where(f => f.Shape.Geometry is Cylinder) .Select(f => f.Master.Parent.Shape.CopyFaces(new[] { f.Master.Shape })) .Select(b => b.Faces.First()) .Select(f => CreateThreads(f, pitch, angle, isInternal)) .ToArray(); Part part = Window.ActiveWindow.Scene as Part; foreach (Body body in bodies) { DesignBody.Create(part, Resources.ThreadStructureText, body); } Settings.Default.IsImperial = isImperial; Settings.Default.IsInternal = isInternal; Settings.Default.Pitch = isImperial ? 0.0254 / pitch : pitch / 1E3; Settings.Default.Angle = angle * 180 / Math.PI; Settings.Default.Save(); }
public static DesignBody CreateCircle(Frame frame, double diameter, IPart part) { Plane plane = Plane.Create(frame); List <ITrimmedCurve> profile = new List <ITrimmedCurve>(); Circle circle = Circle.Create(frame, diameter / 2); profile.Add(CurveSegment.Create(circle)); Body body = null; try { body = Body.CreatePlanarBody(plane, profile); } catch { Debug.Assert(false, "Exception thrown creating body"); } if (body == null) { Debug.Fail("Profile was not connected, not closed, or not in order."); return(null); } if (part == null) { part = Window.ActiveWindow.ActiveContext.ActivePart; } DesignBody desBodyMaster = DesignBody.Create(part.Master, "Circle", body); desBodyMaster.Transform(part.TransformToMaster); return(desBodyMaster); }
private bool CreateFlatPatternDXF(string dxfFilePath, Body firstBody) { var largestFace = firstBody.Faces.OrderBy(x => x.Area).Last(); var tempDoc = Document.Create(); var tempPart = tempDoc.MainPart; var tempMasterUnused = DesignBody.Create(tempPart, "Flat Pattern", firstBody); var largestSurface = largestFace.Geometry; var box = largestFace.BoxUV; var centre = box.Center; var surfEval = largestSurface.Evaluate(centre); var normal = surfEval.Normal; var origin = surfEval.Point; var frame = Frame.Create(origin, normal); var viewProj = Matrix.CreateMapping(frame); var viewProjInv = viewProj.Inverse; var firstTempWindow = Window.GetWindows(tempDoc).First(); firstTempWindow.SetProjection(viewProjInv, true, false); // this is the API causing the problems :-( //firstTempWindow.Export(WindowExportFormat.AutoCadDxf, dxfFilePath); //var allTempWindows = Window.GetWindows(tempDoc); //foreach (var thisWindow in allTempWindows) //{ // thisWindow.Close(); //} return(true); }
public void SetFaceTranslucent(Face face, DesignBody desBody) { // Get face current colour var bodyColour = desBody.GetColor(null); var otherColour = Color.FromArgb(173, bodyColour.Value.R, bodyColour.Value.G, bodyColour.Value.B); var desFace = desBody.GetDesignFace(face); desFace.SetColor(null, otherColour); }
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."); } } } }
public override Color?ColorForBody(DesignBody designBody) { Color color = designBody.GetVisibleColor(); return(Color.FromArgb( RandomVaryRGB(color.R), RandomVaryRGB(color.G), RandomVaryRGB(color.B) )); }
static void AnisotropicScale_Executing(object sender, EventArgs e) { DesignBody designBody = Window.ActiveWindow.ActiveContext.SingleSelection as DesignBody; designBody.Scale( Frame.Create(designBody.GetBoundingBox(Matrix.Identity).Center, Direction.DirX, Direction.DirY), 1, 1.5, 2 ); }
public static DesignBody CreatePolygon(IList <Point> inputPoints, Plane plane, double thickness, IPart part) { if (part == null) { part = Window.ActiveWindow.ActiveContext.ActivePart; } DesignBody desBodyMaster = DesignBody.Create(part.Master, "Polygon", CreatePolygon(inputPoints, plane, thickness)); desBodyMaster.Transform(part.TransformToMaster); // TBD I should be doing this before we make it ?? return(desBodyMaster); }
public static DesignBody CreateSphere(Point center, double diameter, IPart part) { if (part == null) { part = Window.ActiveWindow.ActiveContext.ActivePart; } DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sphere", CreateSphere(center, diameter)); desBodyMaster.Transform(part.TransformToMaster); return(desBodyMaster); }
// TBD move all this designbody nonsense to an abstract class for shape creation and get rid of all the copied code public static DesignBody CreateDesignBody(Body body, string name, IPart part) { if (part == null) { part = Window.ActiveWindow.ActiveContext.ActivePart; } DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sphere", body); desBodyMaster.Transform(part.TransformToMaster); return(desBodyMaster); }
void Reset() { StopThread(); Rendering = null; StatusText = "Get ready for some mayhem."; DesignBody desBody = ShapeHelper.CreateCircle(Frame.World, 11, Window.ActiveWindow.Scene as Part); desBody.SetVisibility(null, false); lawson.Reset(); }
void Reset() { StopThread(); Rendering = null; StatusText = "Get ready for some mayhem."; double size = Math.PI; DesignBody desBody = ShapeHelper.CreateBlock(Point.Create(-size, -size, -size), Point.Origin, Window.ActiveWindow.Scene as Part); desBody.SetVisibility(null, false); gyroid.Reset(); }
protected void CreateDesignBodies(Body gearBody, Body pitchCircleBody, Body addendumBody, Body dedendumBody) { Debug.Assert(gearBody != null); Debug.Assert(pitchCircleBody != null); Debug.Assert(addendumBody != null); Debug.Assert(dedendumBody != null); // Fillets var roundEdges = new List <KeyValuePair <Edge, EdgeRound> >(); FixedRadiusRound round = new FixedRadiusRound(GearData.Module * GearData.DedendumClearance); foreach (Edge edge in gearBody.Edges) { if (edge.Faces.Count == 2 && Accuracy.AngleIsNegative(edge.GetAngle())) { roundEdges.Add(new KeyValuePair <Edge, EdgeRound>(edge, round)); } } // if (!GearData.IsSmallDedendum)////////tdb gearBody.RoundEdges(roundEdges); GearDesBody = DesignBody.Create(Part, Resources.GearNameSimple, gearBody); GearDesBody.Layer = GearLayer; PitchCircleDesBody = DesignBody.Create(Part, Resources.PitchCircleSurfaceName, pitchCircleBody); PitchCircleDesBody.Layer = PitchCircleLayer; var alignmentPlanes = new List <Body>(); Matrix trans; for (int i = 0; i < GearData.NumberOfTeeth; i++) { trans = Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirZ), GearData.PitchAngle * 2 * i); alignmentPlanes.Add(addendumBody.CreateTransformedCopy(trans)); alignmentPlanes.Add(dedendumBody.CreateTransformedCopy(trans)); } // Alignment planes foreach (Body alignmentBody in alignmentPlanes) { DesignBody desBody = DesignBody.Create(AlignmentPart, Resources.AlignmentPlaneBodyName, alignmentBody); desBody.Layer = AlignmentLayer; AlignmentDesBodies.Add(desBody); } foreach (Body visualizationBody in CreateVisualizationBodies()) { DesignBody desBody = DesignBody.Create(Part, Resources.VisualizationBodyName, visualizationBody); desBody.Layer = VisualizationLayer; } }
static void CreateShotNearPoint(Point point, double height, double radius) { Window activeWindow = Window.ActiveWindow; Line rayLine = Line.Create(point, activeWindow.Projection.Inverse * Direction.DirZ); ITrimmedCurve rayCurve = CurveSegment.Create(rayLine, Interval.Create(1000, -1000)); //DesignCurve.Create(activeWindow.Scene as Part, rayCurve); // draws the ray as a design object var intersectionList = new List <IntPoint <SurfaceEvaluation, CurveEvaluation> >(); foreach (IDesignBody designBody in (activeWindow.Scene as Part).Bodies) { foreach (IDesignFace designFace in designBody.Faces) { intersectionList.AddRange(designFace.Shape.IntersectCurve(rayCurve)); } } Point? closePoint = null; double closeParam = Double.MinValue; foreach (IntPoint <SurfaceEvaluation, CurveEvaluation> intersection in intersectionList) { if (intersection.EvaluationB.Param > closeParam) { closeParam = intersection.EvaluationB.Param; closePoint = intersection.Point; } } if (closePoint == null) { return; } DesignBody toolBody = ShapeHelper.CreateSphere(closePoint.Value, radius, activeWindow.Scene as Part); //TBD why doesn't this work on spacklePart? //Frame? frame = GetFrameFromPoint(designFace, point); //if (frame == null) // return; //Body body = CreateCylinder(point, frame.Value.DirX, frame.Value.DirY, radius, height); //DesignBody toolBody = AddInHelper.CreateSphere(frame.Value.Origin, radius, spacklePart); // TBD XXX Fix for v5 //if (spackleMode == SpackleMode.Add) // targetBody.Unite(new IDesignBody[] { toolBody }); //else if (spackleMode == SpackleMode.Cut) // targetBody.Subtract(new IDesignBody[] { toolBody }); }
public static DesignBody CreateCylinder(Point point1, Point point2, double diameter, IPart part) { Body body = CreateCylinder(point1, point2, diameter); if (part == null) { part = Window.ActiveWindow.ActiveContext.ActivePart; } DesignBody desBodyMaster = DesignBody.Create(part.Master, "Cylinder", body); desBodyMaster.Transform(part.TransformToMaster); return(desBodyMaster); }
public static DesignBody CreateCable(ITrimmedCurve iTrimmedCurve, double diameter, IPart part) { Body body = CreateCable(iTrimmedCurve, diameter); if (part == null) { part = Window.ActiveWindow.ActiveContext.ActivePart; } DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sweep", body); desBodyMaster.Transform(part.TransformToMaster); return(desBodyMaster); }
private void CreatePart(Body firstBody) { #if DEBUG // create new part to hold the result var uniteDoc = Document.Create(); var unitePart = uniteDoc.MainPart; var pieces = firstBody.SeparatePieces().Where(x => x.IsManifold); var i = 0; foreach (var thisPiece in pieces) { DesignBody.Create(unitePart, "Unite " + i++, thisPiece); } #endif }
private void CreateGeometry() { Window activeWindow = Window.ActiveWindow; Part mainPart = activeWindow.Scene as Part; if (mainPart == null) { return; } List <Body> bodies = new List <Body>(); foreach (int[,] patchData in patchIndices) { ControlPoint[,] controlPoints = new ControlPoint[4, 4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { controlPoints[i, j] = new ControlPoint(vertices[patchData[i, j] - 1], 1); } } IDictionary <string, Face> idToFace; IDictionary <string, Edge> idToEdge; bodies.Add(Body.Import(new BezierPatchForeignBody(controlPoints), out idToFace, out idToEdge)); if (bodies[bodies.Count - 1].Faces.Count == 0) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { DesignCurve.Create(mainPart, CurveSegment.Create(PointCurve.Create(vertices[patchData[i, j] - 1]))); } } } } foreach (Body body in bodies) { if (body.Faces.Count > 0) { DesignBody.Create(mainPart, "Bezier", body); } } activeWindow.InteractionMode = InteractionMode.Solid; activeWindow.ZoomExtents(); }
public static DesignBody CylinderPtPt(Part part) { Point point1 = Point.Create(0.00, 0.01, 0.00); Point point2 = Point.Create(0.03, 0.05, 0.04); double diameter = 0.004; double radi = diameter / 2; Vector heightVector = point2 - point1; Frame frame = Frame.Create(point1, heightVector.Direction); Plane plane = Plane.Create(frame); Body cylinder4 = Body.ExtrudeProfile(new CircleProfile(plane, radi), heightVector.Magnitude); return(DesignBody.Create(part, "Cylinder3", cylinder4)); }
public List <Body> CopyIDesign(List <IDesignBody> iDesBods) { var bodies = new List <Body>(); foreach (IDesignBody bod in iDesBods) { DesignBody master = bod.Master; Matrix masterTrans = bod.TransformToMaster; Matrix reverseTrans = masterTrans.Inverse; Body copy = master.Shape.Copy(); copy.Transform(reverseTrans); bodies.Add(copy); } return(bodies); }
protected override void OnExecute(Command command, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, buttonRect); foreach (VideoForm videoForm in controlForm.VideoForms) { Line line = videoForm.TrackingCamera.GetLine(); var curveSegment = CurveSegment.Create(line, Interval.Create(-10, 10)); var desCurve = DesignCurve.Create(part, curveSegment); desCurve.Layer = referenceLayer; Point point = line.Origin; DesignBody desBody = ShapeHelper.CreateSphere(point, 0.1, part); desBody.Layer = referenceLayer; } }
public static DesignBody CreateSausage(Point point1, Point point2, double diameter, IPart part) { double radius = diameter / 2; Vector lengthVector = point2.Vector - point1.Vector; Direction dirX = lengthVector.Direction; Direction dirY = dirX.ArbitraryPerpendicular; Direction dirZ = Direction.Cross(dirX, dirY); Frame profileFrame = Frame.Create(point1, dirX, dirY); Plane profilePlane = Plane.Create(profileFrame); IList <ITrimmedCurve> profile = new List <ITrimmedCurve>(); Line axisLine = Line.Create(point1, dirX); profile.Add(CurveSegment.Create(axisLine, Interval.Create(-radius, lengthVector.Magnitude + radius))); Circle circle1 = Circle.Create(profileFrame, radius); profile.Add(CurveSegment.Create(circle1, Interval.Create(Math.PI / 2, Math.PI))); Line tangentLine = Line.Create(Matrix.CreateTranslation(dirY * radius) * point1, dirX); profile.Add(CurveSegment.Create(tangentLine, Interval.Create(0, lengthVector.Magnitude))); Circle circle2 = Circle.Create(Frame.Create(point2, dirX, dirY), radius); profile.Add(CurveSegment.Create(circle2, Interval.Create(0, Math.PI / 2))); IList <ITrimmedCurve> path = new List <ITrimmedCurve>(); Circle sweepCircle = Circle.Create(Frame.Create(point1, dirY, dirZ), radius); path.Add(CurveSegment.Create(sweepCircle)); Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path); if (body == null) { Debug.Fail("Profile was not connected, not closed, or swept along an inappropriate path."); return(null); } DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sausage", body); desBodyMaster.Transform(part.TransformToMaster); return(desBodyMaster); }
public static void Print(this Body body, Part part = null) { body = body.Copy(); if (body.PieceCount > 1) { ICollection <Body> bodies = body.SeparatePieces(); Debug.Assert(bodies.Count == body.PieceCount); bodies.Print(); return; } try { DesignBody.Create(part ?? MainPart, GetDebugString(body), body); } catch { } }
static void PrintBodies(Queue <Body> bodyQueue, List <Body> bodyList) { printBodiesCount++; foreach (Body body in bodyList) { Body bodyTrans = body.Copy(); bodyTrans.Transform(Matrix.CreateTranslation(Vector.Create(printBodiesOffset * printBodiesCount, 0, 0))); DesignBody.Create(Window.ActiveWindow.Scene as Part, "Merged", bodyTrans); } List <Body> bodies = new List <Body>(bodyQueue); foreach (Body body in bodies) { Body bodyTrans = body.Copy(); bodyTrans.Transform(Matrix.CreateTranslation(Vector.Create(printBodiesOffset * printBodiesCount, 0, 0))); DesignBody.Create(Window.ActiveWindow.Scene as Part, "TBD", bodyTrans); } }
public void ColorBody(DesignBody designBody) { designBody.SetColor(null, ColorForBody(designBody)); }
public abstract Color? ColorForBody(DesignBody designBody);
public override Color? ColorForBody(DesignBody designBody) { return HSBColor.ShiftBrightness(designBody.GetVisibleColor(), -VaryAmount); }
public override Color? ColorForBody(DesignBody designBody) { return HSBColor.ShiftBrightness(designBody.GetVisibleColor(), RandomVary()); }
public override Color? ColorForBody(DesignBody designBody) { return Color.FromArgb(RandomMiddleRGB(), RandomMiddleRGB(), RandomMiddleRGB()); }
public override Color? ColorForBody(DesignBody designBody) { Color color = designBody.GetVisibleColor(); return HSBColor.ShiftHue(color, RandomHue()); }
public override Color? ColorForBody(DesignBody designBody) { Color color = designBody.GetVisibleColor(); HSBColor hsbColor = HSBColor.FromColor(color); return HSBColor.ShiftSaturation(color, RandomMiddleRGB() - hsbColor.S); }
public override Color? ColorForBody(DesignBody designBody) { return HSBColor.ShiftSaturation(designBody.GetVisibleColor(), RandomVary()); }
public override Color? ColorForBody(DesignBody designBody) { Color color = designBody.GetVisibleColor(); return Color.FromArgb( RandomVaryRGB(color.R), RandomVaryRGB(color.G), RandomVaryRGB(color.B) ); }
public override Color? ColorForBody(DesignBody designBody) { return HSBColor.ShiftSaturation(designBody.GetVisibleColor(), -VaryAmount); }
public override Color? ColorForBody(DesignBody designBody) { return HSBColor.ShiftHue(designBody.GetVisibleColor(), VaryHueAmount); }
public override Color? ColorForBody(DesignBody designBody) { return null; }