Beispiel #1
0
 private void CreateDesignCurveIfPointsSeparate(Part part, Point a, Point b)
 {
     if (a != b)             // compares within modeling tolerance
     {
         DesignCurve.Create(part, CurveSegment.Create(a, b));
     }
 }
Beispiel #2
0
        private static Body CreateSphericalSegment(Point tangent, Direction normal, double radius, double halfWidth, double thickness)
        {
            Point center = tangent + normal * radius;

            radius = Math.Abs(radius);
            Plane        plane       = Plane.Create(Frame.Create(center, normal, normal.ArbitraryPerpendicular));
            Circle       circle      = Circle.Create(plane.Frame, radius);
            CurveSegment circleCurve = CurveSegment.Create(circle, Interval.Create(0, Math.Asin(halfWidth / radius)));

            Point rearCenter = tangent - normal * thickness;
            Point rearUpper  = rearCenter + plane.Frame.DirY * halfWidth;

            var profile = new List <ITrimmedCurve>();

            profile.Add(circleCurve);
            profile.Add(CurveSegment.Create(rearCenter, tangent));
            profile.Add(CurveSegment.Create(rearCenter, rearUpper));
            profile.Add(CurveSegment.Create(rearUpper, circleCurve.EndPoint));

            foreach (ITrimmedCurve curve in profile)
            {
                DesignCurve.Create(Window.ActiveWindow.Scene as Part, curve);
            }

            ITrimmedCurve path = CurveSegment.Create(Circle.Create(Frame.Create(tangent, normal), 1));

            return(Body.SweepProfile(plane, profile, new ITrimmedCurve[] { path }));
//			return Body.CreatePlanarBody(plane, new ITrimmedCurve[] { CurveSegment.Create(circle) });
//			return ShapeHelper.CreateCircle(plane.Frame, radius * 2, Window.ActiveWindow.Scene as Part).Shape.Copy();
        }
Beispiel #3
0
        //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 static void CreateDashes(ITrimmedCurve curve, Part part, double dashMinSize, Layer dashLayer)
        {
            double length = curve.Length;
            int    count  = (int)Math.Floor(length / dashMinSize / 2) * 2;

            if (curve.StartPoint != curve.EndPoint)             // odd number when not closed curve
            {
                count++;
            }

            double lastParam = curve.Bounds.Start;
            double param;

            for (int i = 0; i < count; i++)
            {
                if (curve.Geometry.TryOffsetParam(lastParam, length / count, out param))
                {
                    if (i % 2 == 1)
                    {
                        DesignCurve dash = DesignCurve.Create(part, CurveSegment.Create(curve.Geometry, Interval.Create(lastParam, param)));
                        dash.Layer = dashLayer;
                    }

                    lastParam = param;
                }
            }
        }
Beispiel #5
0
        protected override Body GetCappingBody()
        {
            Point startOuter  = StartCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale);
            Point endOuter    = EndCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale);
            Point startKnee   = StartCone.WrapPoint(0, -(1 + BevelKneeRatio) * GearData.Module);
            Point endKnee     = EndCone.WrapPoint(0, -(1 + BevelKneeRatio) * GearData.Module);
            Point startCenter = Axis.ProjectPoint(startKnee).Point;
            Point endCenter   = Axis.ProjectPoint(endKnee).Point;

            IList <ITrimmedCurve> cappingProfile = new Point[] { startCenter, startKnee, startOuter, endOuter, endKnee, endCenter }.AsPolygon();
            IList <ITrimmedCurve> revolvePath = new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(StartFrame, 1)) };

            Body cappingBody = null;

            try {
                cappingBody = Body.SweepProfile(Plane.PlaneZX, cappingProfile, revolvePath);
            }
            catch {
                foreach (ITrimmedCurve curve in cappingProfile)
                {
                    DesignCurve.Create(Part, curve);
                }
            }

            return(cappingBody);
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        static void CreateLine(Part line)
        {
            Window window     = Window.ActiveWindow;
            Point  pointStart = Point.Create(0.10, 0.04, 0.07);
            Point  pointEnd   = Point.Create(0.02, 0.11, 0.09);

            DesignCurve.Create(line, CurveSegment.Create(pointStart, pointEnd));
            MessageBox.Show($"Line between {pointStart} and {pointEnd} will be created", "Info");
        }
Beispiel #8
0
        static void CreateLines(Part multiLine)
        {
            Window window = Window.ActiveWindow;

            List <PointTarget> points = ImportingFun.LoadSampleData();

            foreach (var PointTarget in points)
            {
                //MessageBox.Show($"Line between {points[0]} and will be created");
                DesignCurve.Create(multiLine, CurveSegment.Create(Point.Create(PointTarget.xPoint, PointTarget.yPoint, PointTarget.zPoint), Point.Create(PointTarget.x2Point, PointTarget.y2Point, PointTarget.z2Point)));
            }
        }
Beispiel #9
0
        static void MultiBeamCreator(Part part)
        {
            try
            {
                //Document doc = Document.GetDocument(Settings.Default.ProjectPath + "/" + Settings.Default.ProjectName + ".scdoc");
                Document doc = Window.ActiveWindow.Document;
                Part     p   = doc.MainPart;

                int id = 0;
                List <PointLocation> pointLocations = CsvDataRead.ReadData();  // Get all beams out of file

                foreach (var location in pointLocations)
                {
                    Point startPoint = Point.Create(Double.Parse("" + (location.xPoint / 1000), new CultureInfo("de-DE")), Double.Parse("" + (location.yPoint / 1000), new CultureInfo("de-DE")), Double.Parse("" + (location.zPoint / 1000), new CultureInfo("de-DE")));
                    Point endPoint   = Point.Create(Double.Parse("" + (location.x2Point / 1000), new CultureInfo("de-DE")), Double.Parse("" + (location.y2Point / 1000), new CultureInfo("de-DE")), Double.Parse("" + (location.z2Point / 1000), new CultureInfo("de-DE")));
                    if (location.diameter != 0)
                    {
                        try
                        {
                            double diameter = location.diameter;
                            double radi     = Double.Parse("" + (location.diameter / 2000), new CultureInfo("de-DE"));

                            var lineSegment = CurveSegment.Create(startPoint, endPoint);
                            var designLine  = DesignCurve.Create(p, lineSegment);

                            Vector heightVector = endPoint - startPoint;
                            Frame  frame        = Frame.Create(startPoint, heightVector.Direction);
                            Plane  plane        = Plane.Create(frame);
                            var    profi        = new CircleProfile(plane, radi);

                            //var doc = DocumentHelper.GetActiveDocument();
                            //Document doc = Document.GetDocument(Path.GetDirectoryName("Document1"));
                            //Document doc = window.ActiveContext.Context.Document;


                            Part beamProfile = Part.CreateBeamProfile(doc, "Beam" + id, profi);

                            Beam.Create(beamProfile, designLine);
                            id += 1;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Info");
                        }
                    }
                }
            }
            catch (Exception exe)
            {
                MessageBox.Show(exe.ToString(), "Info");
            }
        }
        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;
                            }
                        }
                    }
                }
            }
        }
Beispiel #11
0
        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();
        }
Beispiel #12
0
        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;
            }
        }
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            base.OnExecute(command, context, buttonRect);

            List <ITrimmedCurve> iTrimmedCurves = new List <ITrimmedCurve>(activeWindow.GetAllSelectedITrimmedCurves());
            List <ITrimmedCurve> uniqueCurves   = new List <ITrimmedCurve>();

            uniqueCurves.Add(iTrimmedCurves[0]);
            iTrimmedCurves.RemoveAt(0);

            foreach (ITrimmedCurve candidate in iTrimmedCurves)
            {
                ITrimmedCurve notUnique = null;
                foreach (ITrimmedCurve uniqueCurve in uniqueCurves)
                {
                    if (candidate.IsCoincident(uniqueCurve))
                    {
                        notUnique = uniqueCurve;
                    }
                }

                if (notUnique != null)
                {
                    uniqueCurves.Remove(notUnique);
                    continue;
                }

                uniqueCurves.Add(candidate);
            }

            // Old crappy way
            //Dictionary<ITrimmedCurve, bool> uniqueCurves = new Dictionary<ITrimmedCurve, bool>(new ITrimmedCurveComparer());

            //foreach (ITrimmedCurve iTrimmedCurve in iTrimmedCurves) {
            //    if (!uniqueCurves.ContainsKey(iTrimmedCurve))
            //        uniqueCurves.Add(iTrimmedCurve, false);
            //    else
            //        uniqueCurves[iTrimmedCurve] = !uniqueCurves[iTrimmedCurve];
            //}

            //foreach (ITrimmedCurve iTrimmedCurve in uniqueCurves.Keys) {

            foreach (ITrimmedCurve iTrimmedCurve in uniqueCurves)
            {
                DesignCurve.Create(part, iTrimmedCurve);
            }
        }
        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;
                        }
                    }
                }
            }
        }
Beispiel #15
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            Window activeWindow = Window.ActiveWindow;
            Part   part         = activeWindow.Scene as Part;

            int    steps = 16;
            double step  = (double)1 / steps;

            for (int i = -steps; i <= steps; i++)
            {
                double u = (double)i * step;

                List <List <Body> > bands = new List <List <Body> >();

                for (int j = -steps; j <= steps; j++)
                {
                    double v = (double)j * step;

                    PointUV uv00 = PointUV.Create(u, v);
                    PointUV uv01 = PointUV.Create(u, v + step);
                    PointUV uv11 = PointUV.Create(u + step, v + step);
                    PointUV uv10 = PointUV.Create(u + step, v);

                    if (
                        uv00.MagnitudeSquared() > 1 ||
                        uv01.MagnitudeSquared() > 1 ||
                        uv11.MagnitudeSquared() > 1 ||
                        uv10.MagnitudeSquared() > 1
                        )
                    {
                        continue;
                    }

                    Point p00 = ToPoincare(uv00);
                    Point p01 = ToPoincare(uv01);
                    Point p11 = ToPoincare(uv11);
                    Point p10 = ToPoincare(uv10);

                    DesignCurve.Create(part, CurveSegment.Create(p00, p01));
                    DesignCurve.Create(part, CurveSegment.Create(p00, p10));
                }
            }

            activeWindow.ZoomExtents();
        }
Beispiel #16
0
        public static IList <IDesignCurve> CreatePolygon(IList <Point> inputPoints, IPart part)
        {
            IList <ITrimmedCurve> iTrimmedCurves = CreatePolygon(inputPoints);

            if (iTrimmedCurves == null)
            {
                return(null);
            }

            var designCurves = new List <IDesignCurve>();

            foreach (ITrimmedCurve iTrimmedCurve in iTrimmedCurves)
            {
                designCurves.Add(DesignCurve.Create(part, iTrimmedCurve));
            }

            return(designCurves);
        }
Beispiel #17
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            const int count = 24;

            double p             = 0.5;
            double q             = 1;
            double circleAngle   = Math.PI / 2;
            Vector inverseOffset = Vector.Create(0.5, 0, 0);

            Part mainPart = Window.ActiveWindow.Scene as Part;

            Point[] baseCirclePoints = new Point[count];
            for (int i = 0; i < count; i++)
            {
                double  u       = (double)i / count * 2 * Math.PI;
                Point[] vPoints = new Point[3];
                for (int j = 0; j < 3; j++)
                {
                    vPoints[j] = Lawson.Evaluate(PointUV.Create((double)j / 3 * 2 * Math.PI, u), p, q, circleAngle, inverseOffset, true);
                    if (j == 0)
                    {
                        baseCirclePoints[i] = vPoints[j];
                    }
                }

                Circle circle = Circle.CreateThroughPoints(
                    Plane.Create(Frame.Create(vPoints[0], Vector.Cross(vPoints[1] - vPoints[0], vPoints[2] - vPoints[0]).Direction)),
                    vPoints[0], vPoints[1], vPoints[2]
                    );

                DesignCurve.Create(mainPart, CurveSegment.Create(circle));

                //ShapeHelper.CreateTorus(circle.Frame.Origin, circle.Frame.DirZ, circle.Radius * 2,
            }

            Circle baseCircle = Circle.CreateThroughPoints(
                Plane.Create(Frame.Create(baseCirclePoints[0], Vector.Cross(baseCirclePoints[1] - baseCirclePoints[0], baseCirclePoints[2] - baseCirclePoints[0]).Direction)),
                baseCirclePoints[0], baseCirclePoints[1], baseCirclePoints[2]
                );

            DesignCurve.Create(mainPart, CurveSegment.Create(baseCircle));
        }
        public static ICollection <IDesignCurve> CreateLines(IList <Point> points, IPart iPart)
        {
            if (iPart == null)
            {
                iPart = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            List <IDesignCurve> iDesignCurves = new List <IDesignCurve>();

            for (int i = 0; i < points.Count - 1; i++)
            {
                CurveSegment curveSegment = CurveSegment.Create(points[i], points[i + 1]);
                if (curveSegment != null)
                {
                    iDesignCurves.Add(DesignCurve.Create(iPart, curveSegment));
                }
            }

            return(iDesignCurves);
        }
Beispiel #19
0
        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;
                    }
                }
            }
        }
Beispiel #20
0
        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);
                        }
                    }
                }
            }
        }
Beispiel #21
0
 public static void Print(this ITrimmedCurve curve, Part part = null)
 {
     DesignCurve.Create(part ?? MainPart, curve);
 }
Beispiel #22
0
        // 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();
            }
        }
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            base.OnExecute(command, context, buttonRect);

            List <ITrimmedCurve> trimmedCurves = new List <ITrimmedCurve>();

            foreach (ITrimmedCurve trimmedCurve in activeWindow.GetAllSelectedITrimmedCurves())
            {
                trimmedCurves.Add(trimmedCurve);
            }

            TrimmedCurveChain curveChain = new TrimmedCurveChain(trimmedCurves);
            double            length     = curveChain.Length;

            int count = (int)Math.Floor(length / dashMinSize / 2) * 2;

            if (curveChain.StartPoint != curveChain.EndPoint)             // odd number when not closed curve
            {
                count++;
            }

            List <DesignCurve> dashes    = new List <DesignCurve>();
            double             lastParam = curveChain.Bounds.Start;
            Point lastPoint;

            Debug.Assert(curveChain.TryGetPointAlongCurve(lastParam, out lastPoint));
            for (int i = 0; i < count; i++)
            {
                Point point;
                if (curveChain.TryGetPointAlongCurve(lastParam -= length / count, out point))
                {
                    if (i % 2 == 1)
                    {
                        DesignCurve dash = DesignCurve.Create(part, CurveSegment.Create(lastPoint, point));
                        dash.Layer = dashLayer;
                        dashes.Add(dash);
                    }
#if false // tori
                    ShapeHelper.CreateTorus(
                        new Point[] { point, lastPoint }.Average(),
                        (point - lastPoint).Direction,
                        0.188 * inches,
                        0.75 * inches,
                        part
                        );
#endif
                    lastPoint = point;
                }
            }
#if false // cylinders
            for (int i = 1; i < count; i++)
            {
                CurveEvaluation eval = dashes[i].Shape.Geometry.Evaluate(dashes[i].Shape.Bounds.Start);
                Direction       dir1 = eval.Tangent;

                eval = dashes[i - 1].Shape.Geometry.Evaluate(dashes[i - 1].Shape.Bounds.End);
                Direction dir2 = eval.Tangent;

                if (dir1 == dir2)
                {
                    DatumPlane.Create(part, "miter parallel", Plane.Create(Frame.Create(eval.Point, eval.Tangent.ArbitraryPerpendicular, Direction.Cross(eval.Tangent.ArbitraryPerpendicular, eval.Tangent))));
                    continue;
                }

                Direction averageDir = (dir1.UnitVector + dir2.UnitVector).Direction;
                Direction xDir       = Direction.Cross(averageDir, dir1);
                //	DatumPlane.Create(part, "miter", Plane.Create(Frame.Create(eval.Point, xDir, Direction.Cross(xDir, averageDir))));
                double offset = 0.0001 / 2;
                ShapeHelper.CreateCylinder(eval.Point + averageDir * offset, eval.Point - averageDir * offset, 7 * inches, part);
            }
#endif
        }
        protected override void OnExecute(Command command, ExecutionContext context, Rectangle buttonRect)
        {
            /*
             * Lost Particle Location Highlighter
             * Prompt user to select the MCNP output file which contains lost particle locations
             * Read in file and store locations
             * Highlight the point/plane which the particle loss occurs
             */

            // Instance common functions class
            InstanceClasses.CommonSpaceClaimFunctions FunctionsClass = new InstanceClasses.CommonSpaceClaimFunctions();

            // Variables
            Window window = Window.ActiveWindow;

            window.SetTool(new ToolClass());
            Document doc        = window.Document;
            Part     rootPart   = doc.MainPart;
            Part     lostPart   = Part.Create(doc, "Lost Particles");
            Part     vectorPart = Part.Create(doc, "Vector Lines");
            Part     curvePart  = Part.Create(doc, "Lost Particle Curves");

            Component lp2c = Component.Create(rootPart, curvePart);

            string filepath;
            bool   showVectors;
            bool   fileLocated = false;
            bool   maxParticlesBool;
            double maxParicles;

            int  particleCounter     = 0;
            int  particleLineCounter = 0;
            bool stopParticles       = false;
            bool stopLines           = false;

            string[] lines = null;

            string lostParticleIndicator = "x,y,z coordinates:";
            string vectorIndicator       = "u,v,w direction cosines:";

            char[] delimeterChars   = { ' ', '\t' };
            char[] secondDelimChars = { '+', '-' };

            int    pointCounter = 1;
            int    lineCounter  = 1;
            string pointName;
            string vectorName;
            string chosenColour;

            Point currentPoint = Point.Create(0, 0, 0);
            Point vectorPoint  = Point.Create(0, 0, 0);

            List <double> xValues         = new List <double>();
            List <double> yValues         = new List <double>();
            List <double> zValues         = new List <double>();
            List <Point>  vectorPointList = new List <Point>();
            List <Point>  pointList       = new List <Point>();
            List <Line>   lineList        = new List <Line>();

            // Bring up windows form

            using (var dialogue = new UI.LostParticlesForm())
            {
                if (dialogue.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var nameAndRendering = new List <KeyValuePair <string, Graphic> >();
                var partToGraphic    = new Dictionary <Part, Graphic>();

                var style = new GraphicStyle
                {
                    EnableDepthBuffer = true
                };

                filepath         = dialogue.FileName;
                showVectors      = dialogue.ShowVectors;
                maxParticlesBool = dialogue.MaxParticleBool;
                maxParicles      = dialogue.MaxParticle;
                chosenColour     = dialogue.ColourSelection;
            }

            if (window == null)
            {
                return;
            }

            //Debug.WriteLine(filepath);

            try
            {
                lines       = File.ReadAllLines(filepath);
                fileLocated = true;
            }
            catch
            {
                MessageBox.Show("File Could Not Be Located");
                //SpaceClaim.Api.V18.Application.Exit();
            }

            // Get x,y,z coordinates of lost particle points
            //-------------------------------------------------------------

            if (fileLocated)
            {
                // Check if MCNP output or text file
                if (lines[0].Contains("Code Name & Version") || lines[0].Contains(lostParticleIndicator) || lines[0].Contains(vectorIndicator))
                {
                    //Debug.WriteLine("MCNP File");
                    // MCNP File
                    foreach (string line in lines)
                    {
                        if (line.Contains(lostParticleIndicator))
                        {
                            //Debug.WriteLine(line);
                            if (!stopParticles)
                            {
                                string[] tempWords = line.Split(delimeterChars, StringSplitOptions.RemoveEmptyEntries);

                                // Convert API values in metres to cm for SpaceClaim
                                currentPoint = Point.Create(Convert.ToDouble(tempWords[2]) / 100, Convert.ToDouble(tempWords[3]) / 100, Convert.ToDouble(tempWords[4]) / 100);
                                pointList.Add(currentPoint);

                                particleCounter++;

                                if (particleCounter >= maxParicles && maxParticlesBool)
                                {
                                    stopParticles = true;
                                }
                            }
                        }

                        else if (line.Contains(vectorIndicator))
                        {
                            string[] tempWords = line.Split(delimeterChars, StringSplitOptions.RemoveEmptyEntries);

                            //Debug.WriteLine(tempWords[3] + "  " + tempWords[4] + "  " + tempWords[5]);

                            Point     origin    = Point.Create(0, 0, 0);
                            Direction direction = Direction.Create(Convert.ToDouble(tempWords[3]), Convert.ToDouble(tempWords[4]), Convert.ToDouble(tempWords[5]));
                            vectorPoint = Point.Create(currentPoint.X + Convert.ToDouble(tempWords[3]) / 1, currentPoint.Y + Convert.ToDouble(tempWords[4]) / 1, currentPoint.Z + Convert.ToDouble(tempWords[5]) / 1);

                            if (showVectors && !stopLines)
                            {
                                vectorName = "Lost Particle " + lineCounter.ToString() + " Vector";
                                LineSegment   lineSeg  = new LineSegment(currentPoint, vectorPoint);
                                ITrimmedCurve shape    = CurveSegment.Create(lineSeg);
                                DesignCurve   desCurve = DesignCurve.Create(vectorPart, shape);
                                desCurve.Name = vectorName;
                                desCurve.SetColor(null, Color.Blue);
                                lineCounter++;
                                particleLineCounter++;

                                if (particleLineCounter >= maxParicles && maxParticlesBool)
                                {
                                    stopLines = true;
                                }
                            }

                            //Line vectorLine = Line.CreateThroughPoints(currentPoint, origin);
                            Line vectorLine = Line.CreateThroughPoints(currentPoint, vectorPoint);



                            //Line vectorLine = Line.Create(currentPoint, direction);
                            lineList.Add(vectorLine);
                        }

                        #region Old Code

                        /*
                         * else if (lostParticleBool)
                         * {
                         *
                         *  if (line.Contains(endLostParticleIndicator))
                         *  {
                         *      //string patternOne = @"(\-|\d)\d*\.\d+";
                         *      string patternOne = @"(?<=\d)(\+|\-)";
                         *      string[] tempWords = prevLine.Split(delimeterChars, StringSplitOptions.RemoveEmptyEntries);
                         *      string[] xWords = Regex.Split(tempWords[2], patternOne);
                         *      string[] yWords = Regex.Split(tempWords[3], patternOne);
                         *      string[] zWords = Regex.Split(tempWords[4], patternOne);
                         *      //Debug.WriteLine(xWords[0]);
                         *      //Debug.WriteLine(yWords[0]);
                         *
                         *      string xFinal = xWords[0] + "E" + xWords[1] + xWords[2];
                         *      string yFinal = yWords[0] + "E" + yWords[1] + yWords[2];
                         *      string zFinal = zWords[0] + "E" + zWords[1] + zWords[2];
                         *
                         *      Debug.WriteLine(xFinal);
                         *      Debug.WriteLine(yFinal);
                         *      Debug.WriteLine(zFinal);
                         *
                         *      /*
                         *      foreach (string word in xWords)
                         *      {
                         *          Debug.WriteLine(word);
                         *      }
                         *
                         *      Debug.WriteLine(" ");
                         *
                         *      foreach (string word in yWords)
                         *      {
                         *          Debug.WriteLine(word);
                         *      }
                         *
                         *
                         *      xValues.Add(Convert.ToDouble(xFinal));
                         *      yValues.Add(Convert.ToDouble(yFinal));
                         *      zValues.Add(Convert.ToDouble(zFinal));
                         *
                         *  }
                         *
                         * //prevLine = line;
                         * }
                         */

                        #endregion
                    }

                    //Debug.WriteLine(pointList.Count);

                    // Use values and highlight the positions in SpaceClaim
                    //---------------------------------------------------------------
                    foreach (Point point in pointList)
                    {
                        pointName = "Lost Particle " + pointCounter.ToString();
                        window.ActiveTool.CreateIndicator(point);
                        //DatumPoint.Create(lostPart, pointName, point);
                        var           pc     = PointCurve.Create(point);
                        ITrimmedCurve shapey = CurveSegment.Create(pc);
                        DesignCurve   dcurve = DesignCurve.Create(curvePart, shapey);
                        if (chosenColour == "Blue")
                        {
                            dcurve.SetColor(null, Color.Blue);
                        }
                        else if (chosenColour == "Red")
                        {
                            dcurve.SetColor(null, Color.Red);
                        }
                        else if (chosenColour == "Green")
                        {
                            dcurve.SetColor(null, Color.Green);
                        }
                        else if (chosenColour == "Orange")
                        {
                            dcurve.SetColor(null, Color.Orange);
                        }
                        else if (chosenColour == "Black")
                        {
                            dcurve.SetColor(null, Color.Black);
                        }
                        else if (chosenColour == "Yellow")
                        {
                            dcurve.SetColor(null, Color.Yellow);
                        }
                        else if (chosenColour == "Salmon Pink")
                        {
                            dcurve.SetColor(null, Color.Salmon);
                        }
                        pointCounter++;
                    }


                    if (showVectors)
                    {
                        /*
                         * foreach (Line line in lineList)
                         * {
                         *  vectorName = "Lost Particle " + lineCounter + " Vector";
                         *  DatumLine dLine = DatumLine.Create(vectorPart, vectorName, line);
                         *  lineCounter++;
                         * }
                         */
                        Component vectorComponent = Component.Create(rootPart, vectorPart);
                    }

                    //Component lostParticleComponent = Component.Create(rootPart, lostPart);
                }
                else
                {
                    // Text file

                    /*
                     * foreach (string line in lines)
                     * {
                     *  Debug.Write(String.Format("{0}\n",line));
                     * }
                     */
                    bool firstLine = true;
                    int  length    = 0;

                    foreach (string line in lines)
                    {
                        if (line.Length != 0)
                        {
                            string[] tempWords = line.Split(delimeterChars, StringSplitOptions.RemoveEmptyEntries);
                            if (firstLine)
                            {
                                firstLine = false;
                                length    = tempWords.Length;
                            }

                            if (length > 3)
                            {
                                currentPoint = Point.Create(Convert.ToDouble(tempWords[0]) / 100, Convert.ToDouble(tempWords[1]) / 100, Convert.ToDouble(tempWords[2]) / 100);
                                pointList.Add(currentPoint);
                                particleCounter++;

                                Point     origin    = Point.Create(0, 0, 0);
                                Direction direction = Direction.Create(Convert.ToDouble(tempWords[3]), Convert.ToDouble(tempWords[4]), Convert.ToDouble(tempWords[5]));
                                vectorPoint = Point.Create(currentPoint.X + Convert.ToDouble(tempWords[3]) / 1, currentPoint.Y + Convert.ToDouble(tempWords[4]) / 1, currentPoint.Z + Convert.ToDouble(tempWords[5]) / 1);

                                if (showVectors)
                                {
                                    vectorName = "Lost Particle " + lineCounter.ToString() + " Vector";
                                    LineSegment   lineSeg  = new LineSegment(currentPoint, vectorPoint);
                                    ITrimmedCurve shape    = CurveSegment.Create(lineSeg);
                                    DesignCurve   desCurve = DesignCurve.Create(vectorPart, shape);
                                    desCurve.Name = vectorName;
                                    desCurve.SetColor(null, Color.Blue);
                                    lineCounter++;
                                    particleLineCounter++;
                                }

                                //Line vectorLine = Line.CreateThroughPoints(currentPoint, origin);
                                Line vectorLine = Line.CreateThroughPoints(currentPoint, vectorPoint);



                                //Line vectorLine = Line.Create(currentPoint, direction);
                                lineList.Add(vectorLine);
                            }
                            else if (length <= 3)
                            {
                                try
                                {
                                    currentPoint = Point.Create(Convert.ToDouble(tempWords[0]) / 100, Convert.ToDouble(tempWords[1]) / 100, Convert.ToDouble(tempWords[2]) / 100);
                                    pointList.Add(currentPoint);
                                    particleCounter++;
                                }
                                catch
                                {
                                }
                            }
                        }
                    }

                    foreach (Point point in pointList)
                    {
                        pointName = "Lost Particle " + pointCounter.ToString();
                        window.ActiveTool.CreateIndicator(point);
                        //DatumPoint.Create(lostPart, pointName, point);
                        var           pc     = PointCurve.Create(point);
                        ITrimmedCurve shapey = CurveSegment.Create(pc);
                        DesignCurve   dcurve = DesignCurve.Create(curvePart, shapey);
                        if (chosenColour == "Blue")
                        {
                            dcurve.SetColor(null, Color.Blue);
                        }
                        else if (chosenColour == "Red")
                        {
                            dcurve.SetColor(null, Color.Red);
                        }
                        else if (chosenColour == "Green")
                        {
                            dcurve.SetColor(null, Color.Green);
                        }
                        else if (chosenColour == "Orange")
                        {
                            dcurve.SetColor(null, Color.Orange);
                        }
                        else if (chosenColour == "Black")
                        {
                            dcurve.SetColor(null, Color.Black);
                        }
                        else if (chosenColour == "Yellow")
                        {
                            dcurve.SetColor(null, Color.Yellow);
                        }
                        else if (chosenColour == "Salmon Pink")
                        {
                            dcurve.SetColor(null, Color.Salmon);
                        }
                        pointCounter++;
                    }

                    if (showVectors)
                    {
                        Component vectorComponent = Component.Create(rootPart, vectorPart);
                    }

                    //Component lostParticleComponent = Component.Create(rootPart, lostPart);
                }
            }
        }
Beispiel #25
0
        private Body CreateGearBody()
        {
            int numSteps = (int)Math.Max(Math.Ceiling(Math.Abs(64 * HelixRotations / 2 / Math.PI) + 1), 2);

            if (this is BevelGear /*|| this is HypoidGear*/)
            {
                numSteps *= 4;
            }

            int extraSteps = 2;

            if (Accuracy.AngleIsZero(TotalTwistAngle))
            {
                numSteps   = 2;
                extraSteps = 0;                //0
            }

            double accuracy = Accuracy.LinearResolution;
            //	Period.Print();
            var orderedCurveChain = new TrimmedCurveChain(Period);

            orderedCurveChain.Reverse();
            IList <ITrimmedCurve> orderedCurves = orderedCurveChain.SortedCurves;

            var periodBodies = new List <Body>();

            foreach (ITrimmedCurve iTrimmedCurve in orderedCurves)
            {
                var profiles = new List <ICollection <ITrimmedCurve> >();
                for (int i = -extraSteps; i < numSteps + extraSteps; i++)
                {
                    ITrimmedCurve transformedCurve = GetTransformedProfileCurve(iTrimmedCurve, (double)i / (numSteps - 1));
                    var           profile          = new List <ITrimmedCurve>();
                    profile.Add(transformedCurve);
                    profiles.Add(profile);
                }

                try {
                    periodBodies.Add(Body.LoftProfiles(profiles, false, false));
                }
                catch {
                    foreach (ICollection <ITrimmedCurve> curves in profiles)
                    {
                        foreach (ITrimmedCurve curve in curves)
                        {
                            DesignCurve.Create(Part, curve);
                        }
                    }
                }
            }

            Body periodBody = periodBodies.TryUnionOrFailBodies();

            var    profileBodies = new List <Body>();
            var    startProfile  = new List <ITrimmedCurve>();
            var    endProfile    = new List <ITrimmedCurve>();
            Matrix trans;

            for (int i = 0; i < GearData.NumberOfTeeth; i++)
            {
                trans = Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirZ), GearData.PitchAngle * 2 * i);
                profileBodies.Add(periodBody.CreateTransformedCopy(trans));
            }

            Body gearBody    = profileBodies.TryUnionAndStitchOrFailBodies();
            Body cappingBody = GetCappingBody();

            try {
                //	throw new NotImplementedException();
                if (GearData.IsInternal)
                {
                    //	gearBody.Subtract(new Body[] { cappingBody });
                    cappingBody.Subtract(new Body[] { gearBody });
                    gearBody = cappingBody;
                }
                else
                {
                    gearBody.Intersect(new Body[] { cappingBody });
                }
            }
            catch {
                DesignBody.Create(Part, "capping", cappingBody.Copy());
                DesignBody.Create(Part, "gear", gearBody.Copy());
            }

            return(gearBody);
        }
Beispiel #26
0
        public override ICollection <ITrimmedCurve> GetProfile()
        {
            IPart iPart = Window.ActiveWindow.Scene as Part;

            if (base.GetProfile() != null)
            {
                return(period);
            }

            CurveSegment trochoidA = CurveSegment.Create(Data.CreateConjugateTrochoid(ConjugateGearData));
            ICollection <IntPoint <CurveEvaluation, CurveEvaluation> > intersectionsInvolute = trochoidA.IntersectCurve(curveA);

            CurveSegment addendumCircle = null;
            Matrix       conjugateTrans = Matrix.CreateTranslation(Vector.Create(Data.PitchRadius + ConjugateGearData.PitchRadius, 0, 0));

            // involute traced by only one corner
            //	addendumCircle = CurveSegment.Create(ConjugateGearData.AddendumCircle).CreateTransformedCopy(conjugateTrans);

            // ClosestSeparation extension technique, with scaling
            Circle     largeCircle = Circle.Create(Frame.Create(conjugateTrans * Point.Origin, Direction.DirX, Direction.DirY), ConjugateGearData.PitchRadius + pitchRadius);
            Separation separation  = CurveSegment.Create(largeCircle).GetClosestSeparation(trochoidA);
            Circle     circle      = Circle.Create(largeCircle.Frame, (separation.PointB - largeCircle.Frame.Origin).Magnitude - Accuracy.LinearResolution * 100);

            addendumCircle = CurveSegment.Create(circle);

            //// Three point circle techique
            //Matrix rotation = Matrix.CreateRotation(Line.Create(conjugateTrans * Point.Origin, Direction.DirZ), 2 * Math.PI / 3);
            //double param = trochoidA.Geometry.Parameterization.Range.Value.GetParameter(0.5);

            //CurveSegment curve0 = trochoidA.CreateTransformedCopy(Matrix.Identity);
            //CurveSegment curve1 = curve0.CreateTransformedCopy(rotation);
            //CurveSegment curve2 = curve1.CreateTransformedCopy(rotation);
            //Circle circle = Circle.CreateTangentToThree(
            //    Plane.PlaneXY,
            //    new CurveParam(curve0.Geometry, param),
            //    new CurveParam(curve1.Geometry, param),
            //    new CurveParam(curve2.Geometry, param)
            //);
            //				addendumCircle = CurveSegment.Create(Circle.Create(Frame.Create(circle.Frame.Origin, Direction.DirX, Direction.DirY), circle.Radius - Accuracy.LinearResolution * 10));

            if (intersectionsInvolute.Count == 0)               // error
            {
                DesignCurve.Create(iPart, CurveSegment.Create(addendumCircle.Geometry));

                DesignCurve.Create(iPart, trochoidA);
                DesignCurve.Create(iPart, trochoidA.CreateTransformedCopy(mirror));

                DesignCurve.Create(iPart, curveA);
                DesignCurve.Create(iPart, curveA.CreateTransformedCopy(mirror));
                return(null);
            }
            ///		else {
            IntPoint <CurveEvaluation, CurveEvaluation> intersectionInvolute = intersectionsInvolute.ToArray()[0];

            addendumCircle = addendumCircle.CreateTransformedCopy(Matrix.CreateScale(1 / 1.00, (addendumCircle.Geometry as Circle).Frame.Origin));
            double maxDist = 0;

            ICollection <IntPoint <CurveEvaluation, CurveEvaluation> > intersections = trochoidA.IntersectCurve(addendumCircle);
            IntPoint <CurveEvaluation, CurveEvaluation> intersectionOther            = intersections.First();

            foreach (IntPoint <CurveEvaluation, CurveEvaluation> intersection in intersections)
            {
                double dist = Math.Abs(intersection.EvaluationA.Param - intersectionInvolute.EvaluationA.Param);
                if (dist > maxDist)
                {
                    intersectionOther = intersection;
                    maxDist           = dist;
                }
            }

            //	period.Add(addendumCircle);
            if (maxDist == 0)               //error
            {
                DesignCurve.Create(iPart, CurveSegment.Create(addendumCircle.Geometry));

                DesignCurve.Create(iPart, trochoidA);
                DesignCurve.Create(iPart, trochoidA.CreateTransformedCopy(mirror));

                DesignCurve.Create(iPart, curveA);
                DesignCurve.Create(iPart, curveA.CreateTransformedCopy(mirror));
                return(null);
            }


            period.Add(CurveSegment.Create(addendumCircle.Geometry, Interval.Create(intersectionOther.EvaluationB.Param, 2 * Math.PI - intersectionOther.EvaluationB.Param)));
            //		}
            //CurveSegment trochoidB = trochoidA.CreateTransformedCopy(mirror);
            //intersectionOther = trochoidA.IntersectCurve(trochoidB).ToArray()[0];

            trochoidA = CurveSegment.Create(trochoidA.Geometry, Interval.Create(intersectionOther.EvaluationA.Param, intersectionInvolute.EvaluationA.Param));
            period.Add(trochoidA);
            period.Add(trochoidA.CreateTransformedCopy(mirror));

            curveA = CurveSegment.Create(curveA.Geometry, Interval.Create(intersectionInvolute.EvaluationB.Param, curveA.Bounds.End));
            period.Add(curveA);
            period.Add(curveA.CreateTransformedCopy(mirror));

            return(period);
        }
Beispiel #27
0
        public override ICollection <ITrimmedCurve> GetProfile()
        {
            IPart iPart = Window.ActiveWindow.Scene as Part;

            if (base.GetProfile() != null)
            {
                return(period);
            }

            CurveSegment trochoidA = CurveSegment.Create(Data.CreateConjugateTrochoid(ConjugateGearData));

            Line tangentLine = Line.CreateTangentToOne(Plane.PlaneXY, new CurveParam(trochoidA.Geometry, (trochoidA.Bounds.Start + trochoidA.Bounds.End) * 3 / 4), Point.Origin);
            ICollection <IntPoint <CurveEvaluation, CurveEvaluation> > intersectionsInvoluteTangent = tangentLine.IntersectCurve(trochoidA.Geometry);
            double paramA, paramB;

            if (intersectionsInvoluteTangent.Count != 1)                // Apparently, an ACIS bug can cause the intersection to miss even though the tangent line is perfect, so we work around it.
            {
                Separation sep = tangentLine.GetClosestSeparation(trochoidA.Geometry);
                paramA = tangentLine.ProjectPoint(sep.PointA).Param;
                paramB = trochoidA.Geometry.ProjectPoint(sep.PointB).Param;
            }
            else
            {
                IntPoint <CurveEvaluation, CurveEvaluation> intersectionInvoluteTangent = intersectionsInvoluteTangent.ToArray()[0];
                paramA = intersectionInvoluteTangent.EvaluationA.Param;
                paramB = intersectionInvoluteTangent.EvaluationB.Param;
            }

            CurveSegment tangentLineSegment = CurveSegment.Create(tangentLine, Interval.Create(
                                                                      Data.DedendumRadius, // line origin is world origin in direction of tangency
                                                                      paramA
                                                                      ));

            double       tangentAngle       = Math.Atan(tangentLine.Direction.Y / tangentLine.Direction.X);
            CurveSegment baseCircleSegment  = CurveSegment.Create(Data.DedendumCircle, Interval.Create(2 * Math.PI - tangentAngle, tangentAngle));

            ICollection <IntPoint <CurveEvaluation, CurveEvaluation> > intersectionsInvoluteTrochoid = trochoidA.IntersectCurve(curveA);

            if (intersectionsInvoluteTrochoid.Count == 0)               // error
            {
                DesignCurve.Create(iPart, baseCircleSegment);
                DesignCurve.Create(iPart, tangentLineSegment);

                DesignCurve.Create(iPart, trochoidA);
                DesignCurve.Create(iPart, trochoidA.CreateTransformedCopy(mirror));

                DesignCurve.Create(iPart, curveA);
                DesignCurve.Create(iPart, curveA.CreateTransformedCopy(mirror));
                return(null);
            }

            IntPoint <CurveEvaluation, CurveEvaluation> intersectionInvoluteTrochoid = intersectionsInvoluteTrochoid.ToArray()[0];


            // if (tangentLineSegment.IntersectCurve(curveA).Count > 0) an ACIS intersection bug prevents this from working.  e.g. 13 tooth gear with 20 degree pressure angle
            if (paramB > intersectionInvoluteTrochoid.EvaluationA.Param)
            {
                return(new ExtendedToothProfile(Data).GetProfile());
            }

            trochoidA = CurveSegment.Create(trochoidA.Geometry, Interval.Create(paramB, intersectionInvoluteTrochoid.EvaluationA.Param));

            period.Add(trochoidA);
            period.Add(trochoidA.CreateTransformedCopy(mirror));

            curveA = CurveSegment.Create(curveA.Geometry, Interval.Create(intersectionInvoluteTrochoid.EvaluationB.Param, curveA.Bounds.End));
            period.Add(curveA);
            period.Add(curveA.CreateTransformedCopy(mirror));

            period.Add(tangentLineSegment);
            period.Add(tangentLineSegment.CreateTransformedCopy(mirror));

            period.Add(baseCircleSegment);

            return(period);
        }