예제 #1
0
        public static Gear Create(IPart parent, GearData gearData, GearData conjugateGearData, ToothProfile toothProfile, double helicalAngle, double hypoidAngle, double hypoidOffset, double hypoidKneeRatio, double depth)
        {
            Gear gear = new HypoidGear(parent, gearData, conjugateGearData, toothProfile, helicalAngle, hypoidAngle, hypoidOffset, hypoidKneeRatio, depth);

            BuildGear(gear);
            return(gear);
        }
예제 #2
0
 public static Gear Create(IPart parent, GearData gearData, GearData conjugateGearData, ToothProfile toothProfile, double helicalAngle, double hypoidAngle, double hypoidOffset, double hypoidKneeRatio, double depth)
 {
     Gear gear = new HypoidGear(parent, gearData, conjugateGearData, toothProfile, helicalAngle, hypoidAngle, hypoidOffset, hypoidKneeRatio, depth);
     BuildGear(gear);
     return gear;
 }
예제 #3
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            double lengthConversion = ActiveWindow.Units.Length.ConversionFactor;

            int  numberOfTeethL = (int)Values[Resources.NumberOfTeethLText].Value;
            int  numberOfTeethR = (int)Values[Resources.NumberOfTeethRText].Value;
            bool isInternalL    = numberOfTeethL < 0;
            bool isInternalR    = numberOfTeethR < 0;

            numberOfTeethL = Math.Abs(numberOfTeethL);
            numberOfTeethR = Math.Abs(numberOfTeethR);

            double pressureAngle     = Values[Resources.PressureAngleText].Value * Math.PI / 180;
            double module            = Values[Resources.ModuleText].Value / lengthConversion;
            double dedendumClearance = Values[Resources.DedendumClearanceText].Value;
            double depth             = Values[Resources.DepthText].Value / lengthConversion;

            bool useTrochoidalInterferenceRemoval = Booleans[Resources.UseTrochoidalText].Value;
            bool addDedendumClearance             = Booleans[Resources.AddDedendumClearance].Value;

            if (!addDedendumClearance)
            {
                dedendumClearance = 0;
            }

            bool   isBevel        = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].IsEnabledCommandBoolean.Value;
            double bevelAngle     = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].Values[Resources.BevelAngleText].Value * Math.PI / 180;
            double bevelKneeRatio = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsBevelText].Values[Resources.BevelKneeRatioText].Value;

            bool   isHelical    = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHelicalText].IsEnabledCommandBoolean.Value;
            double helicalAngle = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHelicalText].Values[Resources.HelicalAngleText].Value * Math.PI / 180;

            if (!isHelical)
            {
                helicalAngle = 0;
            }

            bool   isScrew          = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].IsEnabledCommandBoolean.Value;
            double screwAngle       = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].Values[Resources.ScrewAngleText].Value * Math.PI / 180;
            double screwAngleOffset = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsScrewText].Values[Resources.ScrewAngleBiasText].Value * Math.PI / 180;

            if (!isScrew)
            {
                screwAngle       = 0;
                screwAngleOffset = 0;
            }

            double screwAngleAverage = screwAngle / 2;
            double screwAngleL       = screwAngleAverage + screwAngleOffset;
            double screwAngleR       = screwAngleAverage - screwAngleOffset;

            bool   isHypoid     = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].IsEnabledCommandBoolean.Value;
            double hypoidAngle  = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].Values[Resources.HypoidAngleText].Value * Math.PI / 180;
            double hypoidOffset = RibbonBooleanGroupCapsule.BooleanGroupCapsules[Resources.IsHypoidText].Values[Resources.HypoidOffsetText].Value / lengthConversion;

            if (!isHypoid)
            {
                hypoidAngle  = 0;
                hypoidOffset = 0;
            }

            Frame frame = Frame.World;
            //Circle circle = SelectedCircle(ActiveWindow);
            //if (circle != null)
            //    frame = circle.Frame;

            List <ITrimmedCurve> selectedCurves = ActiveWindow.GetAllSelectedITrimmedCurves().ToList();

            if (selectedCurves.Count == 2 && selectedCurves[0].Geometry is Circle && selectedCurves[0].Geometry is Circle)
            {
                Circle     circle0    = (Circle)selectedCurves[0].Geometry;
                Circle     circle1    = (Circle)selectedCurves[1].Geometry;
                Separation separation = circle0.Axis.GetClosestSeparation(circle1.Axis);

                if (Accuracy.LengthIsZero(separation.Distance))
                {
                    throw new NotImplementedException("Distance between axes is zero; only hypoid implemented.");
                }

                isHypoid     = true;
                hypoidAngle  = AddInHelper.AngleBetween(circle0.Axis.Direction, circle1.Axis.Direction);
                hypoidOffset = ((circle0.Frame.Origin - separation.PointA).Magnitude - depth / 2) / Math.Cos(hypoidAngle / 2);

                double radiusAApprox = separation.Distance * circle0.Radius / (circle0.Radius + circle1.Radius);
                double radiusBApprox = separation.Distance - radiusAApprox;
                numberOfTeethR = (int)Math.Round((double)numberOfTeethL / radiusAApprox * radiusBApprox);
                module         = radiusAApprox * 2 / numberOfTeethL;

                Point     midpoint = separation.PointA + (separation.PointA - separation.PointB) * numberOfTeethL / numberOfTeethR;
                Direction sideSide = (circle0.Frame.Origin - circle1.Frame.Origin).Direction;
                frame = Frame.Create(midpoint, Direction.Cross(sideSide, -(midpoint - circle0.GetClosestSeparation(circle1).PointA).Direction), sideSide);
            }

            double hypoidAngleL = Math.Atan(Math.Sin(hypoidAngle) / (Math.Cos(hypoidAngle) + (double)numberOfTeethR / numberOfTeethL));
            double hypoidAngleR = Math.Atan(Math.Sin(hypoidAngle) / (Math.Cos(hypoidAngle) + (double)numberOfTeethL / numberOfTeethR));

            Gear gearL = null;
            Gear gearR = null;

            var          gearDataL     = new GearData(numberOfTeethL, pressureAngle, module, dedendumClearance, isInternalL, screwAngleL);
            var          gearDataR     = new GearData(numberOfTeethR, pressureAngle, module, dedendumClearance, isInternalR, screwAngleR);
            ToothProfile toothProfileL = GetGearProfileFromOptions(gearDataL, gearDataR, useTrochoidalInterferenceRemoval, addDedendumClearance);
            ToothProfile toothProfileR = GetGearProfileFromOptions(gearDataR, gearDataL, useTrochoidalInterferenceRemoval, addDedendumClearance);

            if (isBevel)
            {
                gearL = BevelGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, bevelAngle, bevelKneeRatio, depth);
                gearR = BevelGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, bevelAngle, bevelKneeRatio, depth);
            }
            else if (isHypoid)
            {
                gearL = HypoidGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, hypoidAngleL, hypoidOffset, bevelKneeRatio, depth);
                gearR = HypoidGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, hypoidAngleR, hypoidOffset, bevelKneeRatio, depth);
            }
            else
            {
                gearL = StraightGear.Create(ActiveIPart, gearDataL, gearDataR, toothProfileL, helicalAngle, screwAngleL, depth);
                gearR = StraightGear.Create(ActiveIPart, gearDataR, gearDataL, toothProfileR, -helicalAngle, screwAngleR, depth);
            }

            Line zAxis = Line.Create(Point.Origin, Direction.DirZ);

            gearL.Component.Transform(
                Matrix.CreateMapping(frame) *
                Matrix.CreateRotation(zAxis, Math.PI) *
                gearL.TransformToTangent *
                Matrix.CreateRotation(zAxis, gearDataL.PitchAngle * ((double)1 / 2 + (gearDataL.NumberOfTeeth % 2 == 0 && !isHypoid ? -1 : 0)))
                );

            gearR.Component.Transform(
                Matrix.CreateMapping(frame) *
                gearR.TransformToTangent *
                Matrix.CreateRotation(zAxis, gearDataR.PitchAngle * ((double)1 / 2 + (gearDataR.NumberOfTeeth % 2 == 0 && !isHypoid ? -1 : 0)))
                );


            //		if (gearDataR.NumberOfTeeth % 2 == 0)
            //			gearR.Component.Transform(Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirZ), gearDataR.PitchAngle));

            //gearR.Component.Transform(gearR.TransformToTangent);

            Part        parent       = ActiveIPart.Master;
            IDesignFace pitchCircleL = gearL.Component.Content.Bodies.Where(b => b.Master == gearL.PitchCircleDesBody).First().Faces.First();
            IDesignFace pitchCircleR = gearR.Component.Content.Bodies.Where(b => b.Master == gearR.PitchCircleDesBody).First().Faces.First();

            Part        gearMountPart      = Part.Create(parent.Document, String.Format(Resources.GearMountPartName, gearDataL.NumberOfTeeth, gearDataR.NumberOfTeeth));
            Component   gearMountComponent = Component.Create(parent, gearMountPart);
            DesignBody  mountBodyL         = DesignBody.Create(gearMountPart, string.Format(Resources.MountBodyName, gearDataL.NumberOfTeeth), pitchCircleL.Master.Shape.Body.CreateTransformedCopy(pitchCircleL.TransformToMaster.Inverse));
            DesignBody  mountBodyR         = DesignBody.Create(gearMountPart, string.Format(Resources.MountBodyName, gearDataR.NumberOfTeeth), pitchCircleR.Master.Shape.Body.CreateTransformedCopy(pitchCircleR.TransformToMaster.Inverse));
            IDesignFace mountCircleL       = gearMountComponent.Content.Bodies.Where(b => b.Master == mountBodyL).First().Faces.First();
            IDesignFace mountCircleR       = gearMountComponent.Content.Bodies.Where(b => b.Master == mountBodyR).First().Faces.First();

            Layer mountLayer = NoteHelper.CreateOrGetLayer(ActiveDocument, Resources.GearMountAlignmentCircleLayer, System.Drawing.Color.LightGray);

            mountLayer.SetVisible(null, false);
            mountBodyL.Layer = mountLayer;
            mountBodyR.Layer = mountLayer;

            MatingCondition matingCondition;

            matingCondition = AnchorCondition.Create(parent, gearMountComponent);
            matingCondition = AlignCondition.Create(parent, mountCircleL, pitchCircleL);
            matingCondition = AlignCondition.Create(parent, mountCircleR, pitchCircleR);
            //		matingCondition = TangentCondition.Create(parent, pitchCircleL, pitchCircleR);
            GearCondition gearCondition = GearCondition.Create(parent, pitchCircleL, pitchCircleR);

            if (gearDataL.IsInternal ^ gearDataR.IsInternal)
            {
                gearCondition.IsBelt = true;
            }

            ActiveWindow.InteractionMode = InteractionMode.Solid;

            Settings.Default.NumberOfTeethL       = numberOfTeethL;
            Settings.Default.NumberOfTeethR       = numberOfTeethR;
            Settings.Default.PressureAngleDegrees = pressureAngle * 180 / Math.PI;
            Settings.Default.Module            = module;
            Settings.Default.Depth             = depth;
            Settings.Default.DedendumClearance = dedendumClearance;

            Settings.Default.UseTrochoidalInterferenceRemoval = useTrochoidalInterferenceRemoval;
            Settings.Default.AddDedendumClearace = addDedendumClearance;

            Settings.Default.IsBevel = isBevel;
            if (isBevel)
            {
                Settings.Default.BevelAngle     = bevelAngle * 180 / Math.PI;
                Settings.Default.BevelKneeRatio = bevelKneeRatio;
            }

            Settings.Default.IsHelical    = isHelical;
            Settings.Default.HelicalAngle = helicalAngle * 180 / Math.PI;

            Settings.Default.IsScrew          = isScrew;
            Settings.Default.ScrewAngle       = screwAngle * 180 / Math.PI;
            Settings.Default.ScrewAngleOffset = screwAngleOffset * 180 / Math.PI;

            Settings.Default.IsHypoid     = isHypoid;
            Settings.Default.HypoidAngle  = hypoidAngle * 180 / Math.PI;
            Settings.Default.HypoidOffset = hypoidOffset * lengthConversion;

            Settings.Default.Save();
        }