private bool CreateFlatPatternDXF(string dxfFilePath, Body firstBody)
        {
            var largestFace      = firstBody.Faces.OrderBy(x => x.Area).Last();
            var tempDoc          = Document.Create();
            var tempPart         = tempDoc.MainPart;
            var tempMasterUnused = DesignBody.Create(tempPart, "Flat Pattern", firstBody);
            var largestSurface   = largestFace.Geometry;
            var box             = largestFace.BoxUV;
            var centre          = box.Center;
            var surfEval        = largestSurface.Evaluate(centre);
            var normal          = surfEval.Normal;
            var origin          = surfEval.Point;
            var frame           = Frame.Create(origin, normal);
            var viewProj        = Matrix.CreateMapping(frame);
            var viewProjInv     = viewProj.Inverse;
            var firstTempWindow = Window.GetWindows(tempDoc).First();

            firstTempWindow.SetProjection(viewProjInv, true, false);

            // this is the API causing the problems :-(
            //firstTempWindow.Export(WindowExportFormat.AutoCadDxf, dxfFilePath);

            //var allTempWindows = Window.GetWindows(tempDoc);
            //foreach (var thisWindow in allTempWindows)
            //{
            //  thisWindow.Close();
            //}

            return(true);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 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));
        }
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            double lengthConversion = ActiveWindow.Units.Length.ConversionFactor;

            bool isImperial = Booleans[Resources.IsImperial].Value;
            bool isInternal = Booleans[Resources.ThreadIsInternal].Value;

            double pitch = isImperial ? (Const.inches / Values[Resources.ThreadPitch].Value) : (1E-3 * Values[Resources.ThreadPitch].Value);
            double angle = Values[Resources.ThreadAngle].Value * Math.PI / 180;


            Body[] bodies = SpaceClaimExtensions.GetAllSelectedIDesignFaces(Window.ActiveWindow)
                            .Where(f => f.Shape.Geometry is Cylinder)
                            .Select(f => f.Master.Parent.Shape.CopyFaces(new[] { f.Master.Shape }))
                            .Select(b => b.Faces.First())
                            .Select(f => CreateThreads(f, pitch, angle, isInternal))
                            .ToArray();

            Part part = Window.ActiveWindow.Scene as Part;

            foreach (Body body in bodies)
            {
                DesignBody.Create(part, Resources.ThreadStructureText, body);
            }

            Settings.Default.IsImperial = isImperial;
            Settings.Default.IsInternal = isInternal;
            Settings.Default.Pitch      = isImperial ? 0.0254 / pitch : pitch / 1E3;
            Settings.Default.Angle      = angle * 180 / Math.PI;

            Settings.Default.Save();
        }
Exemplo n.º 5
0
        public static DesignBody CreateTransformedCopy(this DesignBody desBody, Matrix trans)
        {
            Body body = desBody.Shape.Copy();

            body.Transform(trans);
            return(DesignBody.Create(desBody.Parent, desBody.Name, body));
        }
Exemplo n.º 6
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            InteractionContext activeContext = Window.ActiveWindow.ActiveContext;
            Part mainPart = Window.ActiveWindow.Scene as Part;

#if false
            foreach (Part part in mainPart.Components.Select(c => c.Content.Master).Where(p => p.Bodies.Count > 1))
            {
                ICollection <Body> bodies = part.Bodies.Select(b => b.Shape).TryUnionBodies2();
                foreach (DesignBody desBody in part.Bodies)
                {
                    desBody.Delete();
                }

                foreach (Body body in bodies)
                {
                    DesignBody.Create(part, "merged", body);
                }
            }
#else
            foreach (IPart iPart in mainPart.Components.Select(c => c.Content).Where(p => p.Bodies.Count > 1))
            {
                activeContext.Selection = iPart.Bodies.Cast <IDocObject>().ToArray();
                Command.Execute("IntersectTool");                 //Combine
                //	System.Threading.Thread.Sleep(4000);
                Command.Execute("Select");
            }
#endif
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
0
        public void AddFace(FlatFace flatFace)
        {
            flatFaces.Add(flatFace);
            flatPattern.FlatFaceMapping[flatFace.SourceFace] = flatFace;

            foreach (FlatLoop flatLoop in flatFace.Loops)
            {
                foreach (FlatFin flatFin in flatLoop.Fins)
                {
                    Face testFace = flatFin.FlatFace.SourceFace.GetAdjacentFace(flatFin.SourceFin.Edge);
                    if (testFace == null)                      // one-sided (laminar) edge
                    {
                        continue;
                    }
                    if (!FlatPattern.FlatFaceExists(testFace))
                    {
                        openFins.Add(flatFin);
                    }

                    List <FlatFin> removeFins = new List <FlatFin>();
                    foreach (FlatFin baseFin in openFins)
                    {
                        if (baseFin.SourceFin.Edge.Equals(flatFin.SourceFin.Edge) && !baseFin.FlatFace.Equals(flatFace))
                        {
                            removeFins.Add(baseFin);
                        }
                    }
                    foreach (FlatFin removeFin in removeFins)
                    {
                        openFins.Remove(removeFin);
                    }
                }
            }

            openFins.Sort(new FlatFin.FlatFinComparer());              // get longest fin --TBD use sorted list structure?
            openFins.Reverse();

            if (flatPattern.IsDetectingIntersections)
            {
                Body body = flatFace.CreateUnfoldedFaceBody();
                if (flatBodyShape == null)
                {
                    flatBodyShape = body;
                }
                else
                {
                    try {
                        flatBodyShape.Unite(new Body[] { body });
                    }
                    catch {
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "flatBodyShape", flatBodyShape);
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "tool", body);
                        Debug.Fail("Boolean failed when merging flatBodyShape.");
                    }
                }
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        protected void CreateDesignBodies(Body gearBody, Body pitchCircleBody, Body addendumBody, Body dedendumBody)
        {
            Debug.Assert(gearBody != null);
            Debug.Assert(pitchCircleBody != null);
            Debug.Assert(addendumBody != null);
            Debug.Assert(dedendumBody != null);

            // Fillets
            var roundEdges         = new List <KeyValuePair <Edge, EdgeRound> >();
            FixedRadiusRound round = new FixedRadiusRound(GearData.Module * GearData.DedendumClearance);

            foreach (Edge edge in gearBody.Edges)
            {
                if (edge.Faces.Count == 2 && Accuracy.AngleIsNegative(edge.GetAngle()))
                {
                    roundEdges.Add(new KeyValuePair <Edge, EdgeRound>(edge, round));
                }
            }
            //		if (!GearData.IsSmallDedendum)////////tdb
            gearBody.RoundEdges(roundEdges);

            GearDesBody       = DesignBody.Create(Part, Resources.GearNameSimple, gearBody);
            GearDesBody.Layer = GearLayer;

            PitchCircleDesBody       = DesignBody.Create(Part, Resources.PitchCircleSurfaceName, pitchCircleBody);
            PitchCircleDesBody.Layer = PitchCircleLayer;

            var    alignmentPlanes = new List <Body>();
            Matrix trans;

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

            // Alignment planes
            foreach (Body alignmentBody in alignmentPlanes)
            {
                DesignBody desBody = DesignBody.Create(AlignmentPart, Resources.AlignmentPlaneBodyName, alignmentBody);
                desBody.Layer = AlignmentLayer;
                AlignmentDesBodies.Add(desBody);
            }

            foreach (Body visualizationBody in CreateVisualizationBodies())
            {
                DesignBody desBody = DesignBody.Create(Part, Resources.VisualizationBodyName, visualizationBody);
                desBody.Layer = VisualizationLayer;
            }
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        private void CreatePart(Body firstBody)
        {
#if DEBUG
            // create new part to hold the result
            var uniteDoc  = Document.Create();
            var unitePart = uniteDoc.MainPart;
            var pieces    = firstBody.SeparatePieces().Where(x => x.IsManifold);
            var i         = 0;
            foreach (var thisPiece in pieces)
            {
                DesignBody.Create(unitePart, "Unite " + i++, thisPiece);
            }
#endif
        }
Exemplo n.º 16
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();
        }
Exemplo n.º 17
0
        public static DesignBody CylinderPtPt(Part part)
        {
            Point  point1   = Point.Create(0.00, 0.01, 0.00);
            Point  point2   = Point.Create(0.03, 0.05, 0.04);
            double diameter = 0.004;
            double radi     = diameter / 2;

            Vector heightVector = point2 - point1;
            Frame  frame        = Frame.Create(point1, heightVector.Direction);
            Plane  plane        = Plane.Create(frame);


            Body cylinder4 = Body.ExtrudeProfile(new CircleProfile(plane, radi), heightVector.Magnitude);

            return(DesignBody.Create(part, "Cylinder3", cylinder4));
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        public static void Print(this Body body, Part part = null)
        {
            body = body.Copy();

            if (body.PieceCount > 1)
            {
                ICollection <Body> bodies = body.SeparatePieces();
                Debug.Assert(bodies.Count == body.PieceCount);
                bodies.Print();
                return;
            }

            try {
                DesignBody.Create(part ?? MainPart, GetDebugString(body), body);
            }
            catch { }
        }
Exemplo n.º 20
0
        static void PrintBodies(Queue <Body> bodyQueue, List <Body> bodyList)
        {
            printBodiesCount++;
            foreach (Body body in bodyList)
            {
                Body bodyTrans = body.Copy();
                bodyTrans.Transform(Matrix.CreateTranslation(Vector.Create(printBodiesOffset * printBodiesCount, 0, 0)));
                DesignBody.Create(Window.ActiveWindow.Scene as Part, "Merged", bodyTrans);
            }

            List <Body> bodies = new List <Body>(bodyQueue);

            foreach (Body body in bodies)
            {
                Body bodyTrans = body.Copy();
                bodyTrans.Transform(Matrix.CreateTranslation(Vector.Create(printBodiesOffset * printBodiesCount, 0, 0)));
                DesignBody.Create(Window.ActiveWindow.Scene as Part, "TBD", bodyTrans);
            }
        }
Exemplo n.º 21
0
        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);
        }
        //Function to split the subtracted inner bodies of pipe and then draw them out
        //--------------------------------------------------------------------------

        public static List <DesignBody> drawnbodies(List <Body> db_keepBodies, Matrix db_reverseTrans, Part db_Part, List <Color> chosen_colour)
        {
            //If more than one body subtract one from other
            List <DesignBody> dp_drawnbodies = new List <DesignBody>();

            if (db_keepBodies.Count == 2)
            {
                if (db_keepBodies[0].Volume > db_keepBodies[1].Volume)
                {
                    db_keepBodies[0].Subtract(db_keepBodies[1].Copy());
                    int k = 0;
                    foreach (Body db_bod in db_keepBodies)
                    {
                        db_bod.Transform(db_reverseTrans);
                        dp_drawnbodies.Add(DesignBody.Create(db_Part, "New_Pipe", db_bod));

                        dp_drawnbodies[k].SetColor(null, chosen_colour[k]);
                        k++;
                    }
                }
                else if (db_keepBodies[0].Volume < db_keepBodies[1].Volume)
                {
                    db_keepBodies[1].Subtract(db_keepBodies[0].Copy());
                    int k = 1;
                    foreach (Body bod in db_keepBodies)
                    {
                        bod.Transform(db_reverseTrans);
                        dp_drawnbodies.Add(DesignBody.Create(db_Part, "New_Pipe", bod));
                        dp_drawnbodies[k].SetColor(null, chosen_colour[k]);
                        k--;
                    }
                }
            }

            //else just draw it!
            else
            {
                db_keepBodies[0].Transform(db_reverseTrans);
                dp_drawnbodies.Add(DesignBody.Create(db_Part, "New_Pipe", db_keepBodies[0]));
            }
            return(dp_drawnbodies);
        }
Exemplo n.º 23
0
        private void CreateGeometry()
        {
            Matrix frontTransform = Matrix.Identity;             // TBD example data had no transforms (or much of anything) on back faces, so we don't know whether the transforms are separate yet
            Matrix backTransform  = Matrix.Identity;

            for (int i = 0; i < Elements.Count; i++)
            {
                frontTransform *= Elements[i].Front.Transform;
                Elements[i].Front.GenerateGeometry(Rays, frontTransform);

                backTransform *= Elements[i].Back.Transform;
                Elements[i].Back.GenerateGeometry(Rays, backTransform);
            }

            Document doc      = Document.Create();
            Part     mainPart = doc.MainPart;

            for (int i = 0; i < Elements.Count; i++)
            {
                Part part = Part.Create(doc, string.Format("F{0:00} - {1}", i + 1, Elements[i].Type));
                Component.Create(mainPart, part);

                foreach (Body body in new CppSideData[] { Elements[i].Front, Elements[i].Back }.SelectMany(s => s.Bodies))
                {
                    DesignBody.Create(mainPart, "Surface", body);
                }

                //for (int j = 0; j < Rays; j++)
                //    CreateDesignCurveIfPointsSeparate(mainPart, Elements[i].Front.RayPoints[j], Elements[i].Back.RayPoints[j]);
            }

            for (int i = 0; i < Elements.Count - 1; i++)
            {
                for (int j = 0; j < Rays; j++)
                {
                    //CreateDesignCurveIfPointsSeparate(mainPart, Elements[i].Back.RayPoints[j], Elements[i + 1].Front.RayPoints[j]);
                    CreateDesignCurveIfPointsSeparate(mainPart, Elements[i].Front.RayPoints[j], Elements[i + 1].Front.RayPoints[j]);
                }
            }
        }
        protected override bool OnClickStart(ScreenPoint cursorPos, Line cursorRay)
        {
            DesignEdge designEdge = InteractionContext.Preselection as DesignEdge;

            if (designEdge == null)
            {
                return(false);
            }

            Circle edgeCircle = (Circle)designEdge.Shape.Geometry;
            Frame  frame      = edgeCircle.Frame;
            Face   face       = designEdge.Faces.Where(f => f.Shape.Geometry is Plane).First().Shape;
            Plane  plane      = (Plane)face.Geometry;

            if (frame.DirZ == plane.Frame.DirZ ^ !face.IsReversed)
            {
                frame = Frame.Create(frame.Origin, -frame.DirZ);
            }

            double angle  = apiGroove.Angle;
            double depth  = apiGroove.Depth;
            var    points = new[] {
                Point.Create(apiGroove.InnerDiameter / 2, 0, 0),
                Point.Create(apiGroove.InnerDiameter / 2 + Math.Sin(angle) * depth, 0, -Math.Cos(angle) * depth),
                Point.Create(apiGroove.OuterDiameter / 2 - Math.Sin(angle) * depth, 0, -Math.Cos(angle) * depth),
                Point.Create(apiGroove.OuterDiameter / 2, 0, 0)
            };

            var profile = points.AsPolygon();
            var path    = new[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) };

            WriteBlock.ExecuteTask("Create Profile", () => {
                var body = Body.SweepProfile(Plane.PlaneZX, profile, path);
                body.Transform(Matrix.CreateMapping(frame));
                var cutter = DesignBody.Create(designEdge.Parent.Parent, "temp", body);
                designEdge.Parent.Shape.Subtract(new[] { cutter.Shape });
            });

            return(false);
        }
Exemplo n.º 25
0
        // Creates all Spheres on the points found in method getSpherePoints
        public void createSpheres(List <SpherePoint> points, double multiplier)
        {
            int count = 1;

            foreach (SpherePoint point in points)
            {
                Direction dir   = Direction.Create(1, 1, 0);
                Frame     frame = Frame.Create(Point.Create(point.X, point.Y, point.Z), dir);

                //result += point.radius + ", ";

                Sphere sphere = Sphere.Create(frame, (point.radius * multiplier));

                BoxUV box = new BoxUV();

                Body body1 = Body.CreateSurfaceBody(sphere, box);

                DesignBody designBody = DesignBody.Create(Window.ActiveWindow.Document.MainPart, "Sphere" + count, body1);

                count++;
            }
        }
Exemplo n.º 26
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        protected override void OnExecute(Command command, ExecutionContext context, Rectangle buttonRect)
        {
            try
            {
                Settings set = Settings.Default;
                // Get Coordinates of selected point
                String   coord  = set.activePointCoord;
                String[] coords = coord.Split(';');

                double distance = set.distance;

                // Save force in settings
                set.forces    += "(" + set.activePointName + "," + (Double.Parse(coords[0]) * 1000).ToString() + "," + (Double.Parse(coords[1]) * 1000).ToString() + "," + (Double.Parse(coords[2]) * 1000).ToString() + "," + set.pointForceX + "," + set.pointForceY + "," + set.pointForceZ + ");";
                set.forceCount = set.forceCount + 1;


                if (set.Dimension == 0) // 3D
                {
                    // Check if force is positive or negative for arrow direction
                    bool sign = true;
                    if (set.pointForceY < 0)
                    {
                        sign = false;
                    }
                    else if (set.pointForceY > 0)
                    {
                        sign = true;
                    }


                    Plane pathPlane = null;
                    if (sign)
                    {
                        pathPlane = Plane.Create(Frame.Create(SpaceClaim.Api.V19.Geometry.Point.Create(Double.Parse(coords[0]), Double.Parse(coords[1]), Double.Parse(coords[2])), -Direction.DirY, Direction.DirX)); // Direction of axis need to be set to give the arrow the right direction
                    }
                    else if (!sign)
                    {
                        pathPlane = Plane.Create(Frame.Create(SpaceClaim.Api.V19.Geometry.Point.Create(Double.Parse(coords[0]), (Double.Parse(coords[1]) + ((distance / 1000) - ((distance / 1000) * 0.2))), Double.Parse(coords[2])), Direction.DirY, Direction.DirX)); // Direction of axis need to be set to give the arrow the right direction
                                                                                                                                                                                                                                                                         //MessageBox.Show("" + ( Double.Parse(coords[1]) + ((distance/1000) - ((distance/1000) * 0.2))));
                    }


                    //var profile = new ArrowProfile(pathPlane, 0.0005, 0.00025, 0.0005, 0.00008, 0.0);
                    var profile = new ArrowProfile(pathPlane, (distance / 1000) * 0.4, (distance / 1000) * 0.2, (distance / 1000) * 0.4, (distance / 1000) * 0.1, 0.0);


                    Body body = Body.ExtrudeProfile(profile, 0.0002);

                    // Create arrow
                    DesignBody.Create(Window.ActiveWindow.Document.MainPart, "ExternalForce" + set.activePointName, body);

                    // Set color of arrow
                    foreach (DesignBody b in Window.ActiveWindow.Document.MainPart.Bodies)
                    {
                        if (b.Name.Equals("ExternalForce" + set.activePointName))
                        {
                            b.SetColor(null, System.Drawing.Color.Red);
                        }
                    }
                }
                else if (set.Dimension == 1) // 2D
                {
                    // Check if force is positive or negative for arrow direction
                    bool sign = true;
                    if (set.pointForceZ < 0)
                    {
                        sign = false;
                    }
                    else if (set.pointForceZ > 0)
                    {
                        sign = true;
                    }


                    Plane pathPlane = null;
                    if (sign)
                    {
                        pathPlane = Plane.Create(Frame.Create(SpaceClaim.Api.V19.Geometry.Point.Create(Double.Parse(coords[0]), Double.Parse(coords[1]), Double.Parse(coords[2]) + ((distance / 1000) - ((distance / 1000) * 0.2))), Direction.DirZ, Direction.DirX)); // Direction of axis need to be set to give the arrow the right direction
                    }
                    else if (!sign)
                    {
                        pathPlane = Plane.Create(Frame.Create(SpaceClaim.Api.V19.Geometry.Point.Create(Double.Parse(coords[0]), Double.Parse(coords[1]), Double.Parse(coords[2]) /* + ((distance / 1000) - ((distance / 1000) * 0.2))*/), -Direction.DirZ, Direction.DirX)); // Direction of axis need to be set to give the arrow the right direction
                                                                                                                                                                                                                                                                             //MessageBox.Show("" + ( Double.Parse(coords[1]) + ((distance/1000) - ((distance/1000) * 0.2))));
                    }


                    //var profile = new ArrowProfile(pathPlane, 0.0005, 0.00025, 0.0005, 0.00008, 0.0);
                    var profile = new ArrowProfile(pathPlane, (distance / 1000) * 0.4, (distance / 1000) * 0.2, (distance / 1000) * 0.4, (distance / 1000) * 0.1, 0.0);


                    Body body = Body.ExtrudeProfile(profile, 0.0002);


                    DesignBody.Create(Window.ActiveWindow.Document.MainPart, "ExternalForce" + set.activePointName, body);


                    foreach (DesignBody b in Window.ActiveWindow.Document.MainPart.Bodies)
                    {
                        if (b.Name.Equals("ExternalForce" + set.activePointName))
                        {
                            b.SetColor(null, System.Drawing.Color.Red);
                        }
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Info");
            }
        }
Exemplo n.º 29
0
        public ICollection <DesignBody> CreateCircularTabsOnly(Part mainPart)
        {
            var    bands        = new List <ICollection <Body> >();
            var    cutters      = new List <Body[]>();
            double newScale     = 0.094;
            double cutterHeight = 0.01 / newScale;
            double cutterWidth  = 0.0005 / newScale;

            bool swap = false;

            for (int i = 0; i < iSteps; i++)
            {
                var band = new List <Body>();

                for (int j = 0; j < jSteps; j++)
                {
                    // 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];

                    // Tabs

                    /*            Male      Female      Male
                     * ---p00last-------p00--------p01-------p01next--- v+
                     *       |           |          |           |
                     *       |    pn0    |          |    pn1    |
                     *       |           |          |           |
                     * ---p10last-------p10--------p11-------p11next---
                     *
                     */
                    Point pn0 = (new Point[] { points[i - 1][j], points[i - 1][j + 1] }).Average();
                    Point pn1 = (new Point[] { points[i + 2][j], points[i + 2][j + 1] }).Average();

                    Direction normal0 = Vector.Cross(p01 - pn0, p00 - pn0).Direction;
                    Direction normal1 = Vector.Cross(p10 - pn1, p11 - pn1).Direction;

                    Body tab0 = Tabs.CreateCircularTab(p01, p00, -normal0, tabAngles[i][j], swap);
                    Body tab1 = Tabs.CreateCircularTab(p10, p11, -normal1, tabAngles[i + 1][j], !swap);

                    //	Debug.Assert(b0.Shells.Count == 1);
                    band.Add(tab0);
                    band.Add(tab1);

                    swap = !swap;
                }

                bands.Add(band);
            }

            var    designBands = new List <DesignBody>();
            Matrix scaleMatrix = Matrix.CreateScale(scale, Point.Origin);

            for (int i = 0; i < bands.Count; i++)
            {
                Part part = Part.Create(mainPart.Document, string.Format("Band {0:00}", i));
                Component.Create(mainPart, part);

                HSBColor hsbColor = new HSBColor(0, 100, 200);
                hsbColor.H = (float)((double)i / bands.Count * 360);

                foreach (Body body in bands[i])
                {
                    body.Transform(scaleMatrix);
                    DesignBody designBody = DesignBody.Create(part, "Band", body);
                    designBody.SetColor(null, hsbColor.Color);
                    designBands.Add(designBody);
                }
            }

            return(designBands);
        }
Exemplo n.º 30
0
        public ICollection <DesignBody> CreateSolid(Part mainPart)
        {
            var    bands        = new List <ICollection <Body> >();
            var    cutters      = new List <Body[]>();
            double newScale     = 0.094;
            double cutterHeight = 0.01 / newScale;
            double cutterWidth  = 0.0005 / newScale;

            bool swap = false;

            for (int i = 0; i < iSteps; i++)
            {
                var band = new List <Body>();


                //if (i == 4) {
                //        DesignCurve.Create(Window.ActiveWindow.Scene as Part, CurveSegment.Create(points[i][0], points[i][1]));
                //        DesignCurve.Create(Window.ActiveWindow.Scene as Part, CurveSegment.Create(points[i + iSteps / 2][jSteps / 2], points[i + iSteps / 2][jSteps / 2 + 1]));
                //}


                for (int j = 0; j < jSteps; j++)
                {
                    // 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];

                    Body b0, b1;
                    if ((p00 - p11).Magnitude < (p10 - p01).Magnitude)
                    {
                        b0 = ShapeHelper.CreatePolygon(new Point[] { p00, p01, p11 }, 0);
                        b1 = ShapeHelper.CreatePolygon(new Point[] { p00, p11, p10 }, 0);
                    }
                    else
                    {
                        b0 = ShapeHelper.CreatePolygon(new Point[] { p01, p10, p00 }, 0);
                        b1 = ShapeHelper.CreatePolygon(new Point[] { p01, p11, p10 }, 0);
                    }

                    // Tabs

                    /*            Male      Female      Male
                     * ---p00last-------p00--------p01-------p10next--- v+
                     *       |           |          |           |
                     *       |    pn0    |          |    pn1    |
                     *       |           |          |           |
                     * ---p10last-------p10--------p11-------p11next---
                     *
                     */
                    Point pn0 = (new Point[] { points[i - 1][j], points[i - 1][j + 1] }).Average();
                    Point pn1 = (new Point[] { points[i + 2][j], points[i + 2][j + 1] }).Average();

                    Direction normal0 = Vector.Cross(p01 - pn0, p00 - pn0).Direction;
                    Direction normal1 = Vector.Cross(p10 - pn1, p11 - pn1).Direction;

                    Body tab0 = Tabs.CreateCircularTab(p01, p00, -normal0, tabAngles[i][j], swap);
                    Body tab1 = Tabs.CreateCircularTab(p10, p11, -normal1, tabAngles[i + 1][j], !swap);

                    //DesignBody annotateMe = DesignBody.Create(mainPart, "annotatme", (swap ? tab0 : tab1).Copy());
                    //NoteHelper.AnnotateFace(mainPart, annotateMe.Faces.First(), string.Format("{0},{1}", i, j), 0.02, null);
                    //annotateMe.Delete();

                    //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b0.Copy());
                    //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b1.Copy());
                    //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab0.Copy());
                    //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab1.Copy());

                    try {
                        b0.Unite(new Body[] { b1, tab0, tab1 });
                    }
                    catch {
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b0.Copy());
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b1.Copy());
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab0.Copy());
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab1.Copy());
                        return(null);
                    }

                    //	Debug.Assert(b0.Shells.Count == 1);
                    band.Add(b0);

                    swap = !swap;
                }

                bands.Add(band.TryUnionBodies());

                // Cutters
                Point p0ThisSide0  = points[i][0];
                Point p0ThisSide1  = points[i][1];
                Point p0OtherSide0 = points[i + iSteps / 2][jSteps / 2];
                Point p0OtherSide1 = points[i + iSteps / 2][1 + jSteps / 2];

                Point p1ThisSide0  = points[i + 1][0];
                Point p1ThisSide1  = points[i + 1][1];
                Point p1OtherSide0 = points[i + 1 + iSteps / 2][jSteps / 2];
                Point p1OtherSide1 = points[i + 1 + iSteps / 2][1 + jSteps / 2];

                Point p0 = CurveSegment.Create(p0ThisSide0, p0ThisSide1).GetInBetweenPoint(
                    CurveSegment.Create(p0OtherSide0, p0OtherSide1
                                        ));

                Point p1 = CurveSegment.Create(p1ThisSide0, p1ThisSide1).GetInBetweenPoint(
                    CurveSegment.Create(p1OtherSide0, p1OtherSide1
                                        ));

                //Point p0 = CurveSegment.Create(p0ThisSide0, p0ThisSide1).IntersectCurve(
                //    CurveSegment.Create(p0OtherSide0, p0OtherSide1
                //)).First().Point;

                //Point p1 = CurveSegment.Create(p1ThisSide0, p1ThisSide1).IntersectCurve(
                //    CurveSegment.Create(p1OtherSide0, p1OtherSide1
                //)).First().Point;

                Direction n0 = (p0OtherSide1 - p0OtherSide0).Direction;
                Direction n1 = (p1OtherSide1 - p1OtherSide0).Direction;

                Direction d0 = (p0ThisSide1 - p0ThisSide0).Direction;
                Direction d1 = (p1ThisSide1 - p1ThisSide0).Direction;

                var profiles = new List <ICollection <ITrimmedCurve> >();
                profiles.Add(p0.GetRectanglePointsAround(d0 * cutterHeight, n0 * cutterWidth).GetProfile());
                profiles.Add(p1.GetRectanglePointsAround(d1 * cutterHeight, n1 * cutterWidth).GetProfile());
                Body cutterA = Body.LoftProfiles(profiles, false, true);

                profiles = new List <ICollection <ITrimmedCurve> >();
                profiles.Add(p0.GetRectanglePointsAround(n0 * cutterHeight, d0 * cutterWidth).GetProfile());
                profiles.Add(p1.GetRectanglePointsAround(n1 * cutterHeight, d1 * cutterWidth).GetProfile());
                Body cutterB = Body.LoftProfiles(profiles, false, true);

                cutters.Add(new Body[] { cutterA, cutterB });
            }

            var    designBands = new List <DesignBody>();
            Layer  cutterLayer = NoteHelper.CreateOrGetLayer(mainPart.Document, "Cutters", System.Drawing.Color.DarkViolet);
            Matrix scaleMatrix = Matrix.CreateScale(scale, Point.Origin);

            for (int i = 0; i < bands.Count; i++)
            {
                int whichCutter = i % 2;

                Part part = Part.Create(mainPart.Document, string.Format("Band {0:00}", i));
                Component.Create(mainPart, part);

                int ii = i;
                if (whichCutter == 0)
                {
                    ii = i + iSteps / 2;
                }

                List <Body> mergedCutters = new Body[] {
                    cutters[(ii + iSteps - 1) % iSteps][whichCutter].Copy(),
                    cutters[ii % iSteps][whichCutter].Copy(),
                    cutters[(ii + 1) % iSteps][whichCutter].Copy()
                }.TryUnionBodies().ToList();

                Debug.Assert(mergedCutters.Count == 1, "Couldn't merge cutters");

                double nominalRadius = 0.02;
                double innerRadius   = (nominalRadius - cutterWidth / 2) / newScale;
                double outerRadius   = (nominalRadius + cutterWidth / 2) / newScale;

                var edgeRounds = new List <KeyValuePair <Edge, EdgeRound> >();
                foreach (Edge edge in mergedCutters[0].Edges)
                {
                    if (edge.Length > cutterHeight * 1.1 || edge.Length < cutterHeight * 0.9)
                    {
                        continue;
                    }

                    double angle = edge.GetAngle();
                    if (Math.Abs(angle) > Math.PI / 4 || angle == 0)
                    {
                        continue;
                    }

                    edgeRounds.Add(new KeyValuePair <Edge, EdgeRound>(edge, new FixedRadiusRound(angle > 0 ? outerRadius : innerRadius)));
                }

                mergedCutters[0].RoundEdges(edgeRounds);

                mergedCutters.Add(cutters[(ii - 1 + iSteps / 2) % iSteps][1 - whichCutter].Copy());
                mergedCutters.Add(cutters[(ii + 1 + iSteps / 2) % iSteps][1 - whichCutter].Copy());

                HSBColor hsbColor = new HSBColor(0, 100, 200);
                hsbColor.H = (float)((double)i / bands.Count * 360);

                var cutBand = new List <Body>();
                foreach (Body body in bands[i])
                {
                    foreach (Body cutterBody in mergedCutters)
                    {
                        body.Imprint(cutterBody);
                        foreach (Face face in body.Faces)
                        {
                            if (!IsSpanningBody(face, cutterBody))
                            {
                                continue;
                            }

                            body.DeleteFaces(new Face[] { face }, RepairAction.None);
                            //	DesignBody designBody = DesignBody.Create(part, "Cutter", cutterBody.Copy());
                            //	designBody.SetColor(null, hsbColor.Color);
                        }
                    }

                    cutBand.AddRange(body.SeparatePieces());
                }

                cutBand = cutBand.TryUnionBodies().ToList();

                //foreach (Body body in bands[i]) {
                foreach (Body body in cutBand)
                {
                    body.Transform(scaleMatrix);
                    DesignBody designBody = DesignBody.Create(part, "Band", body);
                    designBody.SetColor(null, hsbColor.Color);
                    designBands.Add(designBody);
                }

                //foreach (Body body in mergedCutters) {
                //    DesignBody designBody = DesignBody.Create(part, "Cutter", body);
                //    designBody.Layer = cutterLayer;
                //    hsbColor.H += 180 * whichCutter;
                //    designBody.SetColor(null, hsbColor.Color);
                ////	designBands[i].Shape.Imprint(designBody.Shape);
                //}
            }

            Trace.WriteLine("vParameters");
            for (int j = 0; j < jSteps; j++)
            {
                for (int i = 0; i < iSteps; i++)
                {
                    Trace.Write(vParameters[i][j] + " ");
                }

                Trace.WriteLine("");
            }

            Trace.WriteLine("tabAngles");
            for (int j = 0; j < jSteps; j++)
            {
                for (int i = 0; i < iSteps; i++)
                {
                    Trace.Write(tabAngles[i][j] + " ");
                }

                Trace.WriteLine("");
            }


            return(designBands);
        }