protected override bool OnMouseMove(ScreenPoint cursorPos, Line cursorRay, MouseButtons button) { if (button != MouseButtons.None) { return(false); } IDocObject preselection = InteractionContext.Preselection; DesignEdge designEdge = preselection as DesignEdge; if (designEdge == null) // selection filtering is not applied if you (pre)select in the tree { return(false); } Circle edgeCircle = (Circle)designEdge.Shape.Geometry; CurveSegment innerCurve = CurveSegment.Create(Circle.Create(edgeCircle.Frame, apiGroove.InnerDiameter / 2)); CurveSegment outerCurve = CurveSegment.Create(Circle.Create(edgeCircle.Frame, apiGroove.OuterDiameter / 2)); var style = new GraphicStyle { LineColor = Color.DarkGray, LineWidth = 2 }; Graphic centerLine = Graphic.Create(style, new[] { CurvePrimitive.Create(innerCurve), CurvePrimitive.Create(outerCurve) }); style = new GraphicStyle { LineColor = Color.White, LineWidth = 4 }; Graphic highlightLine = Graphic.Create(style, new[] { CurvePrimitive.Create(innerCurve), CurvePrimitive.Create(outerCurve) }); Rendering = Graphic.Create(style, null, new[] { highlightLine, centerLine }); return(false); // if we return true, the preselection won't update }
public static void GetGraphics(ToolPath toolPath, out Graphic curveGraphic, out Graphic arrowGraphic) { IList <CurveSegment> cutterCurves; IList <CurveSegment> rapidCurves; IList <CurveSegment> arrowCurves; toolPath.GetCurves(out cutterCurves, out rapidCurves, out arrowCurves); var style = new GraphicStyle { LineWidth = 2 }; Graphic cutterGraphic = Graphic.Create(style, cutterCurves.Select(c => CurvePrimitive.Create(c)).ToArray()); style = new GraphicStyle { LineWidth = 1 }; Graphic rapidGraphic = Graphic.Create(style, rapidCurves.Select(c => CurvePrimitive.Create(c)).ToArray()); curveGraphic = Graphic.Create(null, null, new[] { cutterGraphic, rapidGraphic }); style = new GraphicStyle { LineColor = Color.Black, FillColor = Color.Gray, // IsFlatOn = true, LineWidth = 1 }; //arrowGraphic = Graphic.Create(style, arrowCurves.Select(c => { // var point = c.StartPoint; // var tangent = (c.EndPoint - c.StartPoint).Direction; // var frame = Frame.Create(point, tangent); // return ArrowPrimitive.Create(frame, 20, 10); //}).ToArray()); arrowGraphic = null; }
protected override bool OnMouseMove(ScreenPoint cursorPos, Line cursorRay, MouseButtons button) { if (button != MouseButtons.None) { return(false); } IDocObject preselection = InteractionContext.Preselection; DesignFace designFace = preselection as DesignFace; if (designFace == null) // selection filtering is not applied if you (pre)select in the tree { return(false); } CurveSegment innerCurve, outerCurveA, outerCurveB; CreateThreadCurves(designFace.Shape, pitch, angle, positionOffset, out innerCurve, out outerCurveA, out outerCurveB); var primitives = new[] { CurvePrimitive.Create(innerCurve), CurvePrimitive.Create(outerCurveA), CurvePrimitive.Create(outerCurveB) }; var style = new GraphicStyle { LineColor = Color.DarkGray, LineWidth = 2 }; Graphic centerLine = Graphic.Create(style, primitives); style = new GraphicStyle { LineColor = Color.White, LineWidth = 4 }; Graphic highlightLine = Graphic.Create(style, primitives); Rendering = Graphic.Create(style, null, new[] { highlightLine, centerLine }); return(false); // if we return true, the preselection won't update }
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 }
void UpdateRendering() { // list of primitives to be rendered: var primitives = new List <Primitive> { }; // line for basX, basY: if (tState >= 1) { Vector v1, v2; v1 = basX.Direction.UnitVector * ext; v2 = basY.Direction.UnitVector * ext; primitives.Add(CurvePrimitive.Create(CurveSegment.Create(pOrig, pOrig + v1))); primitives.Add(CurvePrimitive.Create(CurveSegment.Create(pOrig, pOrig + v2))); } if (tState >= 2) { Point p1, p2, p3, p4; Vector v1, v2; v1 = basX.Direction.UnitVector * ext; v2 = basY.Direction.UnitVector * ext; p1 = pOrig - v1 - v2; p2 = pOrig - v1 + v2; p3 = pOrig + v1 + v2; p4 = pOrig + v1 - v2; primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p1, p2))); primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p2, p3))); primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p3, p4))); primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p4, p1))); } /*{ * // show frame of the sectionPlane: * Point p0 = Window.ActiveContext.SectionPlane.Frame.Origin; * Vector vx = Window.ActiveContext.SectionPlane.Frame.DirX.UnitVector * ext * 1.2; * Vector vy = Window.ActiveContext.SectionPlane.Frame.DirY.UnitVector * ext * 0.9; * primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p0, p0 + vx))); * primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p0, p0 + vy))); * } */ { // show screen ScreenPoint sp1 = new ScreenPoint(10, 10); ScreenPoint sp2 = new ScreenPoint(Window.ActiveWindow.Size.Width - 10, Window.ActiveWindow.Size.Height - 10); Point p1; Single r = 1.0f; Line l; Vector v1; l = Window.ActiveContext.GetCursorRay(sp1); if (getPointUnderCursor(l, out p1, out v1)) { primitives.Add(PointPrimitive.Create(p1, r)); } l = Window.ActiveContext.GetCursorRay(sp2); if (getPointUnderCursor(l, out p1, out v1)) { primitives.Add(PointPrimitive.Create(p1, r)); } } // string msg = PlotCommands[0] + PlotCommands[1] + PlotCommands[2]; // primitives.Add(TextPrimitive.Create(msg, LocationPoint.RightSide, pCur, 0, 0, new TextPadding(3))); var style = new GraphicStyle { LineColor = Color.Blue, FillColor = Color.Black, TextColor = Color.DarkGray, LineWidth = 2 }; Rendering = Graphic.Create(style, primitives); }
//private Point GetFivePointNurbsAverage(int[,] indices) { // var knots = new Knot[] { // new Knot(0, 4), // new Knot(1, 4) // }; // var controlPoints = new ControlPoint[] { // new ControlPoint(Point.Create(tabAngles[indices[0,0]][indices[0,1]], GetSpanAt(indices[0,0], indices[0,1]),0), 1), // new ControlPoint(Point.Create(tabAngles[indices[1,0]][indices[1,1]], GetSpanAt(indices[1,0], indices[1,1]),0), 1), // new ControlPoint(Point.Create(tabAngles[indices[2,0]][indices[2,1]], GetSpanAt(indices[2,0], indices[2,1]),0), 1), // new ControlPoint(Point.Create(tabAngles[indices[3,0]][indices[3,1]], GetSpanAt(indices[3,0], indices[3,1]),0), 1), // new ControlPoint(Point.Create(tabAngles[indices[4,0]][indices[4,1]], GetSpanAt(indices[4,0], indices[4,1]),0), 1) // }; // NurbsData data = new NurbsData(5, false, false, knots); // NurbsCurve curve = NurbsCurve.CreateFromControlPoints(data, controlPoints); // Point midpoint = curve.Evaluate(0.5).Point; // return midpoint; //} //private Circle GetTabFromPoints(bool swap, int i, int j, int iOther) { // Point p0 = points[i,j]; // Point p1 = points[i,j + 1]; // Point pn = (new Point[] { points[iOther,j], points[iOther,j + 1] }).Average(); // Direction normal = Vector.Cross(p0 - pn, p1 - pn).Direction; // return Tabs.GetCircularTabCircle(p0, p1, normal, tabAngles[i,j], swap); //} //private double GetSpanAt(int i, int j) { // return (vParameters[i][j + 1] - vParameters[i][j] + Math.PI * 2) % (Math.PI * 2); //} public Graphic GetGraphic() { var graphics = new List <Graphic>(); int iSteps = points.GetLength(0); int jSteps = points.GetLength(1); bool swap = false; for (int i = 0; i < iSteps - 1; i++) { var facetVertices = new List <FacetVertex>(); var facets = new List <Facet>(); var tabMeshes = new List <MeshPrimitive>(); var porcupineCurves = new List <CurvePrimitive>(); for (int j = 0; j < jSteps - 1; j++) { int facetOffset = facetVertices.Count; // 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]; Vector n0 = Vector.Cross(p00 - p01, p00 - p10); Vector n1 = Vector.Cross(p11 - p10, p11 - p01); Direction n = (n0 + n1).Direction; facetVertices.Add(new FacetVertex(p00, n)); facetVertices.Add(new FacetVertex(p01, n)); facetVertices.Add(new FacetVertex(p10, n)); facetVertices.Add(new FacetVertex(p11, n)); if ((p00 - p11).Magnitude < (p10 - p01).Magnitude) { facets.Add(new Facet(0 + facetOffset, 1 + facetOffset, 3 + facetOffset)); facets.Add(new Facet(0 + facetOffset, 3 + facetOffset, 2 + facetOffset)); } else { facets.Add(new Facet(0 + facetOffset, 2 + facetOffset, 1 + facetOffset)); facets.Add(new Facet(1 + facetOffset, 3 + facetOffset, 2 + facetOffset)); } tabMeshes.Add(MeshPrimitive.Create(facetVertices, facets)); Point basePoint = points[i, j]; Point endPoint = basePoint + Gradient(basePoint) / 10; if (basePoint != endPoint) { porcupineCurves.Add(CurvePrimitive.Create(CurveSegment.Create(basePoint, endPoint))); } swap = !swap; } HSBColor hsbFill = new HSBColor(255, (float)i / iSteps * 360, 122, 88); HSBColor hsbLine = new HSBColor(System.Drawing.Color.MidnightBlue); hsbLine.H = (float)i / iSteps * 360; var style = new GraphicStyle { EnableDepthBuffer = true, LineColor = hsbLine.Color, LineWidth = 1, FillColor = hsbFill.Color, EnableCulling = false }; // graphics.Add(Graphic.Create(style, MeshPrimitive.Create(facetVertices, facets))); foreach (MeshPrimitive mesh in tabMeshes) { graphics.Add(Graphic.Create(style, mesh)); } foreach (CurvePrimitive curve in porcupineCurves) { graphics.Add(Graphic.Create(style, curve)); } } return(Graphic.Create(null, null, graphics)); }