Ejemplo n.º 1
0
        /////////////////////////////////////////////////////////////
        // Use: Returns direction of the cone side as Line object.
        //
        /////////////////////////////////////////////////////////////
        public static Line GetConeSideDirection(
            Cone cone,
            UnitVector xAxis)
        {
            UnitVector yAxis = cone.AxisVector;

            double height =
                (cone.IsExpanding ? -1.0 : 1.0)
                * cone.Radius / Math.Tan(cone.HalfAngle);

            Point p1 = _Tg.CreatePoint(
                cone.BasePoint.X + xAxis.X * cone.Radius,
                cone.BasePoint.Y + xAxis.Y * cone.Radius,
                cone.BasePoint.Z + xAxis.Z * cone.Radius);

            Point p2 = _Tg.CreatePoint(
                cone.BasePoint.X + yAxis.X * height,
                cone.BasePoint.Y + yAxis.Y * height,
                cone.BasePoint.Z + yAxis.Z * height);

            return(_Tg.CreateLine(p1, p1.VectorTo(p2)));
        }
Ejemplo n.º 2
0
        /////////////////////////////////////////////////////////////
        // Use: Creates new solid bodies affected by the future
        //      CoilFeature for Standard Thread.
        /////////////////////////////////////////////////////////////
        private static bool CreateCoilBodyStandard(PartDocument doc,
                                                   ThreadInfo threadInfo,
                                                   double minorRad,
                                                   double majorRad,
                                                   bool isInteriorFace)
        {
            try
            {
                PartComponentDefinition compDef =
                    doc.ComponentDefinition;

                Vector direction = threadInfo.ThreadDirection;

                Point basePoint =
                    threadInfo.ThreadBasePoints[1] as Point;

                Point endPoint = _Tg.CreatePoint(
                    basePoint.X + direction.X,
                    basePoint.Y + direction.Y,
                    basePoint.Z + direction.Z);

                UnitVector yAxis = direction.AsUnitVector();

                UnitVector xAxis = Toolkit.GetOrthoVector(yAxis);

                WorkPoint wpt = compDef.WorkPoints.AddFixed(basePoint,
                                                            _ConstructionWorkFeature);

                WorkPlane wpl = compDef.WorkPlanes.AddFixed(basePoint,
                                                            xAxis,
                                                            yAxis,
                                                            _ConstructionWorkFeature);

                WorkAxis xWa = compDef.WorkAxes.AddFixed(basePoint,
                                                         xAxis,
                                                         _ConstructionWorkFeature);

                WorkAxis yWa = compDef.WorkAxes.AddFixed(basePoint,
                                                         yAxis,
                                                         _ConstructionWorkFeature);

                Point sidePt = _Tg.CreatePoint(
                    basePoint.X + xAxis.X * majorRad,
                    basePoint.Y + xAxis.Y * majorRad,
                    basePoint.Z + xAxis.Z * majorRad);

                //Modif
                //double revDepth =
                //    Math.Abs(majorRad - minorRad) *
                //    (isInteriorFace ? -1.0 : 1.0);

                double revDepth = Math.Abs(majorRad - minorRad);

                Line l1 = _Tg.CreateLine(sidePt, yAxis.AsVector());

                Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector());

                Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector());

                Point p1 =
                    l1.IntersectWithCurve(l2, 0.0001)[1] as Point;

                Point p2 =
                    l1.IntersectWithCurve(l3, 0.0001)[1] as Point;

                Point p3 = _Tg.CreatePoint(
                    p2.X - xAxis.X * revDepth,
                    p2.Y - xAxis.Y * revDepth,
                    p2.Z - xAxis.Z * revDepth);

                Point p4 = _Tg.CreatePoint(
                    p1.X - xAxis.X * revDepth,
                    p1.Y - xAxis.Y * revDepth,
                    p1.Z - xAxis.Z * revDepth);


                SketchPoint skp1 = null;
                SketchPoint skp2 = null;
                SketchPoint skp3 = null;
                SketchPoint skp4 = null;

                PlanarSketch sketch  = null;
                Profile      profile = null;

                if (!isInteriorFace)
                {
                    sketch =
                        compDef.Sketches.AddWithOrientation(wpl,
                                                            xWa,
                                                            true,
                                                            true,
                                                            wpt,
                                                            false);

                    skp1 = sketch.SketchPoints.Add(
                        sketch.ModelToSketchSpace(p1), false);

                    skp2 = sketch.SketchPoints.Add(
                        sketch.ModelToSketchSpace(p2), false);

                    skp3 = sketch.SketchPoints.Add(
                        sketch.ModelToSketchSpace(p3), false);

                    skp4 = sketch.SketchPoints.Add(
                        sketch.ModelToSketchSpace(p4), false);

                    sketch.SketchLines.AddByTwoPoints(skp1, skp2);
                    sketch.SketchLines.AddByTwoPoints(skp2, skp3);
                    sketch.SketchLines.AddByTwoPoints(skp3, skp4);
                    sketch.SketchLines.AddByTwoPoints(skp4, skp1);

                    profile =
                        sketch.Profiles.AddForSolid(true, null, null);

                    RevolveFeature rev1 =
                        compDef.Features.RevolveFeatures.AddFull(
                            profile,
                            yWa,
                            PartFeatureOperationEnum.kCutOperation);
                }


                sketch = compDef.Sketches.AddWithOrientation(wpl,
                                                             xWa,
                                                             true,
                                                             true,
                                                             wpt,
                                                             false);

                skp1 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p1), false);

                skp2 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p2), false);

                skp3 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p3), false);

                skp4 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p4), false);

                sketch.SketchLines.AddByTwoPoints(skp1, skp2);
                sketch.SketchLines.AddByTwoPoints(skp2, skp3);
                sketch.SketchLines.AddByTwoPoints(skp3, skp4);
                sketch.SketchLines.AddByTwoPoints(skp4, skp1);

                profile = sketch.Profiles.AddForSolid(true,
                                                      null, null);

                RevolveFeature rev2 =
                    compDef.Features.RevolveFeatures.AddFull(
                        profile,
                        yWa,
                        PartFeatureOperationEnum.kNewBodyOperation);

                return(true);
            }
            catch
            {
                return(false);
            }
        }