コード例 #1
0
        public static DesignBody CreateCircle(Frame frame, double diameter, IPart part)
        {
            Plane plane = Plane.Create(frame);

            List <ITrimmedCurve> profile = new List <ITrimmedCurve>();
            Circle circle = Circle.Create(frame, diameter / 2);

            profile.Add(CurveSegment.Create(circle));

            Body body = null;

            try {
                body = Body.CreatePlanarBody(plane, profile);
            }
            catch {
                Debug.Assert(false, "Exception thrown creating body");
            }

            if (body == null)
            {
                Debug.Fail("Profile was not connected, not closed, or not in order.");
                return(null);
            }

            if (part == null)
            {
                part = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Circle", body);

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
コード例 #2
0
        // TBD move all this designbody nonsense to an abstract class for shape creation and get rid of all the copied code
        public static DesignBody CreateDesignBody(Body body, string name, IPart part)
        {
            if (part == null)
            {
                part = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sphere", body);

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
コード例 #3
0
        public static DesignBody CreateSphere(Point center, double diameter, IPart part)
        {
            if (part == null)
            {
                part = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sphere", CreateSphere(center, diameter));

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
コード例 #4
0
        public static DesignBody CreatePolygon(IList <Point> inputPoints, Plane plane, double thickness, IPart part)
        {
            if (part == null)
            {
                part = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Polygon", CreatePolygon(inputPoints, plane, thickness));

            desBodyMaster.Transform(part.TransformToMaster);  // TBD I should be doing this before we make it ??
            return(desBodyMaster);
        }
コード例 #5
0
        public static DesignBody CreateCable(ITrimmedCurve iTrimmedCurve, double diameter, IPart part)
        {
            Body body = CreateCable(iTrimmedCurve, diameter);

            if (part == null)
            {
                part = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sweep", body);

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
コード例 #6
0
        public static DesignBody CreateCylinder(Point point1, Point point2, double diameter, IPart part)
        {
            Body body = CreateCylinder(point1, point2, diameter);

            if (part == null)
            {
                part = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Cylinder", body);

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
コード例 #7
0
        public static DesignBody CreateSausage(Point point1, Point point2, double diameter, IPart part)
        {
            double    radius       = diameter / 2;
            Vector    lengthVector = point2.Vector - point1.Vector;
            Direction dirX         = lengthVector.Direction;
            Direction dirY         = dirX.ArbitraryPerpendicular;
            Direction dirZ         = Direction.Cross(dirX, dirY);

            Frame profileFrame = Frame.Create(point1, dirX, dirY);
            Plane profilePlane = Plane.Create(profileFrame);

            IList <ITrimmedCurve> profile = new List <ITrimmedCurve>();

            Line axisLine = Line.Create(point1, dirX);

            profile.Add(CurveSegment.Create(axisLine, Interval.Create(-radius, lengthVector.Magnitude + radius)));

            Circle circle1 = Circle.Create(profileFrame, radius);

            profile.Add(CurveSegment.Create(circle1, Interval.Create(Math.PI / 2, Math.PI)));

            Line tangentLine = Line.Create(Matrix.CreateTranslation(dirY * radius) * point1, dirX);

            profile.Add(CurveSegment.Create(tangentLine, Interval.Create(0, lengthVector.Magnitude)));

            Circle circle2 = Circle.Create(Frame.Create(point2, dirX, dirY), radius);

            profile.Add(CurveSegment.Create(circle2, Interval.Create(0, Math.PI / 2)));

            IList <ITrimmedCurve> path = new List <ITrimmedCurve>();
            Circle sweepCircle         = Circle.Create(Frame.Create(point1, dirY, dirZ), radius);

            path.Add(CurveSegment.Create(sweepCircle));

            Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path);

            if (body == null)
            {
                Debug.Fail("Profile was not connected, not closed, or swept along an inappropriate path.");
                return(null);
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sausage", body);

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
コード例 #8
0
        public static DesignBody CreateTorus(Point center, Direction axis, double minorDiameter, double majorDiameter, IPart part)
        {
            double    radius = minorDiameter / 2;
            Direction dirX   = axis.ArbitraryPerpendicular;
            Direction dirY   = Direction.Cross(axis, dirX);

            Frame  profileFrame = Frame.Create(center + dirX * majorDiameter / 2, dirX, axis);
            Circle sphereCircle = Circle.Create(profileFrame, radius);

            IList <ITrimmedCurve> profile = new List <ITrimmedCurve>();

            profile.Add(CurveSegment.Create(sphereCircle));

            IList <ITrimmedCurve> path = new List <ITrimmedCurve>();
            Circle sweepCircle         = Circle.Create(Frame.Create(center, dirX, dirY), radius);

            path.Add(CurveSegment.Create(sweepCircle));

            Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path);

            if (body == null)
            {
                Debug.Fail("Sweep failed.");
                return(null);
            }

            if (part == null)
            {
                part = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Torus", body);

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
コード例 #9
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            base.OnExecute(command, context, buttonRect);

            Window activeWindow = Window.ActiveWindow;
            Part   activePart   = (activeWindow.Scene as Part);

            Layer tabLayer = NoteHelper.CreateOrGetLayer(activeWindow.ActiveContext.Context.Document, "Tabs", System.Drawing.Color.Fuchsia);

            IDesignEdge iDesignEdge = activeWindow.ActiveContext.SingleSelection as IDesignEdge;

            if (iDesignEdge == null)
            {
                return;
            }

            if (iDesignEdge.Faces.Count != 1)
            {
                return;
            }

            IDesignFace iDesignFace = null;

            foreach (IDesignFace testFace in iDesignEdge.Faces)
            {
                iDesignFace = testFace;
            }

            Debug.Assert(iDesignFace != null);

            Point startPoint = iDesignEdge.Shape.StartPoint;
            Point endPoint   = iDesignEdge.Shape.EndPoint;

            if (areTabsFlipped)
            {
                Point tempPoint = startPoint;
                startPoint = endPoint;
                endPoint   = tempPoint;
            }

            SurfaceEvaluation surfEval   = iDesignFace.Shape.ProjectPoint(startPoint);
            Direction         faceNormal = surfEval.Normal;
            Point             midpoint   = startPoint + (endPoint - startPoint) / 2;
            Double            edgeLength = iDesignEdge.Shape.Length;
            Direction         xDir       = (endPoint - startPoint).Direction;

            List <Window> tabWindows = null;
            string        tabFile    = string.Empty;

            if (!isTabStartSlot)
            {
                tabFile = @"C:\Users\bcr.SPACECLAIM\Documents\Models\Dodecahedron Foldcrease\Tab-Circle-Male.scdoc";
            }
            else
            {
                tabFile = @"C:\Users\bcr.SPACECLAIM\Documents\Models\Dodecahedron Foldcrease\Tab-Circle-Female.scdoc";
            }

            try {
                tabWindows = new List <Window>(Document.Open(tabFile, ImportOptions.Create()));
            }
            catch (Exception exception) {
                System.Windows.Forms.MessageBox.Show(SpaceClaim.Api.V10.Application.MainWindow, exception.Message);
            }

            DesignBody tabDesignBody = null;

            foreach (DesignBody testBody in (tabWindows[0].Scene as Part).Bodies)
            {
                tabDesignBody = testBody;
            }

            Debug.Assert(tabDesignBody != null);

            tabDesignBody = DesignBody.Create(activePart, "tab", tabDesignBody.Shape.Body.Copy());

            foreach (Window window in tabWindows)
            {
                window.Delete();
            }

            Matrix scale = Matrix.CreateScale(edgeLength / 0.02, Point.Origin);
            Matrix trans = Matrix.CreateMapping(Frame.Create(midpoint, xDir, Direction.Cross(faceNormal, xDir)));

            tabDesignBody.Transform(trans * scale);
            tabDesignBody.Layer = tabLayer;
        }