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 }); }
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; } }
static void FaceCenter_Executing(object sender, EventArgs e) { Window activeWindow = Window.ActiveWindow; ICollection <IDesignFace> iDesignFaces = activeWindow.GetAllSelectedIDesignFaces(); if (iDesignFaces.Count == 0) { return; } Part parent = activeWindow.ActiveContext.Context as Part; if (parent == null) { return; } Part part = Part.Create(parent.Document, "Face Centers"); Component component = Component.Create(parent, part); foreach (IDesignFace iDesignFace in iDesignFaces) { List <Point> points = new List <Point>(); foreach (IDesignEdge iDesignEdge in iDesignFace.Edges) { points.Add(iDesignEdge.Shape.StartPoint); points.Add(iDesignEdge.Shape.EndPoint); } Point center = points.Average(); SurfaceEvaluation surfaceEvaluation = iDesignFace.Shape.ProjectPoint(center); center = surfaceEvaluation.Point; if (isCreatingSpheres) { ShapeHelper.CreateSphere(center, cylinderDiameter, part); } if (isCreatingCylinders) { ShapeHelper.CreateCylinder(center + surfaceEvaluation.Normal * cylinderDiameter, center - surfaceEvaluation.Normal * cylinderDiameter, cylinderDiameter, part); } } }
void createSphereCommand_Execute(object sender, CommandExecutingEventArgs e) { SphereSet sphereSet = SelectedSphereSet; if (sphereSet == null) { return; } Part sphereRootPart = Part.Create(Window.Document, "Spheres"); Component.Create(Window.ActiveWindow.Scene as Part, sphereRootPart); Part innerSpherePart = Part.Create(Window.Document, "Inner Spheres"); Part outerSpherePart = Part.Create(Window.Document, "Outer Spheres"); Component.Create(sphereRootPart, innerSpherePart); Component.Create(sphereRootPart, outerSpherePart); Part spherePart = Part.Create(Window.Document, "Sphere"); ShapeHelper.CreateSphere(Point.Origin, sphereSet.Radius * 2, spherePart); Body body = sphereSet.DesFace.Shape.Body; foreach (Point point in sphereSet.Positions) { bool isEdge = false; foreach (Edge edge in body.Edges.Where(edge => edge.Faces.Count == 1)) { if ((edge.ProjectPoint(point).Point - point).MagnitudeSquared() < (sphereSet.Radius * sphereSet.Radius)) { isEdge = true; break; } } Component component = Component.Create(isEdge ? outerSpherePart : innerSpherePart, spherePart); component.Placement = Matrix.CreateTranslation(point.Vector); } }
protected override void OnExecute(Command command, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, buttonRect); foreach (Point point in controlForm.CalibrationPoints) { DesignBody desBody = ShapeHelper.CreateSphere(point, 0.1, part); desBody.Layer = referenceLayer; } foreach (VideoForm videoForm in controlForm.VideoForms) { Point point = videoForm.TrackingCamera.GetLine(PointUV.Origin).Evaluate(0.2).Point; DesignBody desBody = ShapeHelper.CreateSphere(point, 0.1, part); desBody.Layer = referenceLayer; foreach (PointUV pointUV in videoForm.TrackingCamera.CalibrationPoints) { point = videoForm.TrackingCamera.GetLine(pointUV).Evaluate(0.2).Point; //desBody = ShapeHelper.CreateSphere(point, 0.1, part); //desBody.Layer = referenceLayer; var desCurve = DesignCurve.Create(part, CurveSegment.Create(PointCurve.Create(point))); desCurve.Layer = referenceLayer; } for (int i = 0; i < videoForm.Size.Width; i += videoForm.Size.Width / 12) { for (int j = 0; j < videoForm.Size.Height; j += videoForm.Size.Height / 12) { Line line = videoForm.TrackingCamera.GetLine(PointUV.Create(i, j)); var curveSegment = CurveSegment.Create(line, Interval.Create(-3, 6)); var desCurve = DesignCurve.Create(part, curveSegment); desCurve.Layer = referenceLayer; } } } }
static void Skeletize_Executing(object sender, EventArgs e) { double sphereDiameter = cylinderDiameter * 2; Window activeWindow = Window.ActiveWindow; ICollection <ITrimmedCurve> iTrimmedCurves = activeWindow.GetAllSelectedITrimmedCurves(); if (iTrimmedCurves.Count == 0) { return; } Part parent = activeWindow.ActiveContext.Context as Part; if (parent == null) { return; } Part part = Part.Create(parent.Document, "Skeleton"); Component component = Component.Create(parent, part); List <Point> allPoints = new List <Point>(); foreach (ITrimmedCurve iTrimmedCurve in iTrimmedCurves) { if (isCreatingSpheres && !Accuracy.Equals(iTrimmedCurve.StartPoint, iTrimmedCurve.EndPoint)) { allPoints.Add(iTrimmedCurve.StartPoint); allPoints.Add(iTrimmedCurve.EndPoint); } if (iTrimmedCurve.Geometry.GetType().Name == "Line") { if (isCreatingCylinders) { ShapeHelper.CreateCylinder(iTrimmedCurve.StartPoint, iTrimmedCurve.EndPoint, cylinderDiameter, part); } if (isCreatingSausages) { ShapeHelper.CreateSausage(iTrimmedCurve.StartPoint, iTrimmedCurve.EndPoint, cylinderDiameter, part); } } else { if (isCreatingCylinders || isCreatingSausages) { ShapeHelper.CreateCable(iTrimmedCurve, cylinderDiameter, part); } if (isCreatingSausages && !Accuracy.Equals(iTrimmedCurve.StartPoint, iTrimmedCurve.EndPoint)) { ShapeHelper.CreateSphere(iTrimmedCurve.StartPoint, cylinderDiameter, part); ShapeHelper.CreateSphere(iTrimmedCurve.EndPoint, cylinderDiameter, part); // TBD boolean these with cable } } } if (isCreatingSpheres) { List <Point> points = new List <Point>(); while (allPoints.Count > 0) { Point testPoint = allPoints[0]; allPoints.Remove(allPoints[0]); bool isDuplicate = false; foreach (Point point in allPoints) { if (Accuracy.Equals(testPoint, point)) { isDuplicate = true; break; } } if (!isDuplicate) { points.Add(testPoint); } } foreach (Point point in points) { ShapeHelper.CreateSphere(point, sphereDiameter, part); } } }