public static bool TryGetRound(DesignFace designFace, out Round round) { round = null; if (designFaceToRound.TryGetValue(designFace, out round)) return true; return false; }
// static Create method follows the API convention and parent should be first argument public static SphereSet Create(DesignFace desFace, int count, double strength, double radius, Color color) { Debug.Assert(desFace != null); var sphereSet = new SphereSet(desFace, count, strength, radius, color); sphereSet.Initialize(); return(sphereSet); }
public static bool TryGetRound(DesignFace designFace, out Round round) { round = null; if (designFaceToRound.TryGetValue(designFace, out round)) { return(true); } return(false); }
protected override bool OnMouseMove(System.Drawing.Point cursorPos, Line cursorRay, MouseButtons button) { #if false IDocObject preselection = InteractionContext.Preselection; DesignFace desFace = null; Profile existingProfile = Profile.GetWrapper(preselection as CustomObject); if (existingProfile != null) { desFace = existingProfile.Face; } if (desFace == null) { desFace = preselection as DesignFace; } if (desFace == null) // selection filtering is not applied if you (pre)select in the tree { return(false); } Face face = desFace.Shape; var plane = face.GetGeometry <Plane>(); Point point; if (!plane.TryIntersectLine(cursorRay, out point)) { return(false); // plane is side-on } Fin fin; double offset = GetOffset(face, plane, point, out fin); var style = new GraphicStyle { LineColor = Color.DodgerBlue, LineWidth = 3 }; Graphic datumGraphic = Graphic.Create(style, CurvePrimitive.Create(fin.Edge)); if (existingProfile != null) { Rendering = datumGraphic; } else { style = new GraphicStyle { LineColor = Color.Gray }; Rendering = Graphic.Create(style, null, Profile.GetGraphic(0.5, 1, Math.PI / 2, Vector.Create(0.5, 0, 0)), datumGraphic); } #endif return(false); // if we return true, the preselection won't update }
// creates a new custom object and a wrapper for it protected SphereSet(DesignFace desFace, int count, double strength, double radius, Color color) : base(desFace.GetAncestor <Part>()) { this.desFace = desFace; this.count = count; this.strength = strength; this.radius = radius; this.color = color; this.positions = GetInitialPositions(desFace.Shape.Body, count, true); desFace.KeepAlive(true); allSphereSets.Add(this); }
public static void AnnotateFace(Part targetPart, DesignFace face, string comment, double textHeight, Direction?direction) { string annotationPlanePartName = "Annotation Planes"; Part part = null; foreach (Part testPart in targetPart.Document.Parts) { if (testPart.Name == annotationPlanePartName) { part = testPart; } } if (part == null) { part = Part.Create(targetPart.Document, annotationPlanePartName); Component component = Component.Create(targetPart, part); } Plane plane = GetPlaneCenteredOnFace(face); if (direction != null) { Direction dirX = Direction.DirX; if (direction.Value != Direction.DirZ) { dirX = direction.Value.ArbitraryPerpendicular; } plane = Plane.Create(Frame.Create(plane.Frame.Origin, dirX, Direction.Cross(direction.Value, dirX))); } Layer planeLayer = CreateOrGetLayer(targetPart.Document, Resources.AnnotationPlaneLayerNameText, System.Drawing.Color.Black); planeLayer.SetVisible(null, false); Layer noteLayer = CreateOrGetLayer(targetPart.Document, Resources.AnnotationLayerNameText, System.Drawing.Color.DarkRed); DatumPlane datum = DatumPlane.Create(part, Resources.AnnotationPlaneNameText, plane); datum.Layer = planeLayer; PointUV location = PointUV.Origin; Note note = Note.Create(datum, location, TextPoint.Center, textHeight, comment); note.SetFontName(DraftingFont.Asme); note.Layer = noteLayer; note.SetColor(null, null); }
protected override sealed bool IsSmallFace(DesignFace desFace) { // From: // http://www.cfd-online.com/Forums/cfx/19977-sliver-face.html // // Sliver face is defined as a face whose ratio of perimeter length to area is // greater than the certain value. Default critical value is 25. Surfaces with // a high sliver factor can result in a poor quality surface mesh. // // The sliver factor associated with a surface is computed, as: // // Sliver factor = (perimeter length)^2 / (4Pi * surface area) var sliverFactor = Math.Pow(desFace.Perimeter, 2f) / (4f * Math.PI * desFace.Area); return(sliverFactor > (double)AreaThreshold.Value); }
// Traversal Helpers public static bool TryGetAdjacentDesignFace(DesignFace sourceFace, DesignEdge sourceEdge, out DesignFace otherFace) { Debug.Assert(sourceEdge.Faces.Count <= 2, "Yikes, non-manifold edge!"); otherFace = null; foreach (DesignFace designFace in sourceEdge.Faces) { if (designFace != sourceFace) { otherFace = designFace; return(true); } } return(false); }
protected override bool OnMouseMove(ScreenPoint cursorPos, Line cursorRay, MouseButtons button) { if (button != MouseButtons.None) { return(false); } IDocObject preselection = InteractionContext.Preselection; DesignFace desFace = null; SphereSet existingSphereSet = SphereSet.GetWrapper(preselection as CustomObject); if (existingSphereSet != null) { desFace = existingSphereSet.DesFace; } if (desFace == null) { desFace = preselection as DesignFace; } if (desFace == null) // selection filtering is not applied if you (pre)select in the tree { return(false); } if (SphereSet.AllSphereSets.Where(s => s.DesFace == desFace).Count() > 0) { return(false); } Body body = desFace.Shape.Body; GraphicStyle style = null; if (existingSphereSet == null) { style = new GraphicStyle { EnableDepthBuffer = true, FillColor = color }; Rendering = Graphic.Create(style, null, SphereSet.GetGraphics(SphereSet.GetInitialPositions(body, count, true), radius)); } return(false); // if we return true, the preselection won't update }
protected override bool OnClickStart(ScreenPoint cursorPos, Line cursorRay) { DesignFace designFace = InteractionContext.Preselection as DesignFace; if (designFace == null) { return(false); } CurveSegment innerCurve, outerCurveA, outerCurveB; CreateThreadCurves(designFace.Shape, pitch, angle, positionOffset, out innerCurve, out outerCurveA, out outerCurveB); WriteBlock.ExecuteTask(Resources.ThreadStructureText, () => { DesignBody.Create(designFace.Parent.Parent, Resources.ThreadStructureText, CreateThreadBody(designFace.Shape, pitch, angle, positionOffset)); }); return(false); }
static void AddRound(DesignFace designFace, List <Round> roundSet, List <DesignFace> remainingFaces, Queue <DesignEdge> edgesToVisit) { remainingFaces.Remove(designFace); Round round = new Round(designFace); roundSet.Add(round); DesignFace otherFace = null; Round otherRound = null; foreach (DesignEdge newEdge in designFace.Edges) { edgesToVisit.Enqueue(newEdge); if (AddInHelper.TryGetAdjacentDesignFace(designFace, newEdge, out otherFace) && Round.TryGetRound(otherFace, out otherRound)) { round.AddAdjacentRound(otherRound); otherRound.AddAdjacentRound(round); } } }
protected override sealed bool IsSmallFace(DesignFace desFace) { // faces below a threshold curvature var face = desFace.Shape; var surfShape = (ISurfaceShape)face; var surf = surfShape.Geometry; var surfParams = surf.Parameterization; var uParam = surfParams.U; var vParam = surfParams.V; double midU; double midV; if (!uParam.Bounds.Start.HasValue || !uParam.Bounds.End.HasValue) { midU = 0d; } else { midU = (uParam.Bounds.Start.Value + uParam.Bounds.End.Value) / 2d; } if (!vParam.Bounds.Start.HasValue || !vParam.Bounds.End.HasValue) { midV = 0; } else { midV = (vParam.Bounds.Start.Value + vParam.Bounds.End.Value) / 2d; } var midParam = PointUV.Create(midU, midV); var eval = surf.Evaluate(midParam); var maxCurve = eval.MaxCurvature; var doc = desFace.Document; var lengthFactor = doc.Units.Length.ConversionFactor; return(1d / maxCurve * lengthFactor < (double)AreaThreshold.Value); }
public static void AnnotateFace(Part targetPart, DesignFace face, string comment, double textHeight, Direction? direction) { string annotationPlanePartName = "Annotation Planes"; Part part = null; foreach (Part testPart in targetPart.Document.Parts) { if (testPart.Name == annotationPlanePartName) part = testPart; } if (part == null) { part = Part.Create(targetPart.Document, annotationPlanePartName); Component component = Component.Create(targetPart, part); } Plane plane = GetPlaneCenteredOnFace(face); if (direction != null) { Direction dirX = Direction.DirX; if (direction.Value != Direction.DirZ) dirX = direction.Value.ArbitraryPerpendicular; plane = Plane.Create(Frame.Create(plane.Frame.Origin, dirX, Direction.Cross(direction.Value, dirX))); } Layer planeLayer = CreateOrGetLayer(targetPart.Document, Resources.AnnotationPlaneLayerNameText, System.Drawing.Color.Black); planeLayer.SetVisible(null, false); Layer noteLayer = CreateOrGetLayer(targetPart.Document, Resources.AnnotationLayerNameText, System.Drawing.Color.DarkRed); DatumPlane datum = DatumPlane.Create(part, Resources.AnnotationPlaneNameText, plane); datum.Layer = planeLayer; PointUV location = PointUV.Origin; Note note = Note.Create(datum, location, TextPoint.Center, textHeight, comment); note.SetFontName(DraftingFont.Asme); note.Layer = noteLayer; note.SetColor(null, null); }
protected override sealed bool IsSmallFace(DesignFace desFace) { return(desFace.Area < mLargestFaceArea * (double)AreaThreshold.Value / 100d); }
public static void AnnotateFace(Part targetPart, DesignFace face, string comment) { AnnotateFace(targetPart, face, comment, 0.001, null); }
public static Plane GetPlaneCenteredOnFace(DesignFace face) { PointUV centerUV = face.Shape.BoxUV.Center; SurfaceEvaluation evaluation = face.Shape.Geometry.Evaluate(centerUV); Point point = evaluation.Point; Direction dirU = (face.Shape.Geometry.Evaluate(PointUV.Create(centerUV.U + 0.001, centerUV.V)).Point.Vector - face.Shape.Geometry.Evaluate(PointUV.Create(centerUV.U - 0.001, centerUV.V)).Point.Vector).Direction; Direction dirVTemp = Direction.Cross(evaluation.Normal, dirU); if (face.Shape.Geometry as Plane != null) { if (!Accuracy.Equals(Vector.Dot(dirU.UnitVector, Direction.DirZ.UnitVector), 0.0)) { // if our U direction has a Z component, the text might be slanted if (Accuracy.Equals(Vector.Dot(dirVTemp.UnitVector, Direction.DirZ.UnitVector), 0.0)) // if our V direction has no Z component, use it dirU = dirVTemp; } } if (face.Shape.Geometry as Cylinder != null) dirU = dirVTemp; dirVTemp = Direction.Cross(evaluation.Normal, dirU); if (Vector.Dot(dirVTemp.UnitVector, Direction.DirZ.UnitVector) < 0.0) // Prevent upside-down notes dirU = -dirU; return Plane.Create(Frame.Create(point, dirU, Direction.Cross(evaluation.Normal, dirU))); }
public Round(DesignFace designFace) { this.designFace = designFace; Debug.Assert(!designFaceToRound.ContainsKey(designFace), "Round already exists for face!"); designFaceToRound.Add(designFace, this); }
static void AddRound(DesignFace designFace, List<Round> roundSet, List<DesignFace> remainingFaces, Queue<DesignEdge> edgesToVisit) { remainingFaces.Remove(designFace); Round round = new Round(designFace); roundSet.Add(round); DesignFace otherFace = null; Round otherRound = null; foreach (DesignEdge newEdge in designFace.Edges) { edgesToVisit.Enqueue(newEdge); if (AddInHelper.TryGetAdjacentDesignFace(designFace, newEdge, out otherFace) && Round.TryGetRound(otherFace, out otherRound)) { round.AddAdjacentRound(otherRound); otherRound.AddAdjacentRound(round); } } }