示例#1
0
        public static void executeWorkOrder(GCodeWorkOrder wo)
        {
            //  finally, the rubber meets the road!
            GCodeGenerator gpin = new GCodeGenerator(wo);

            File.WriteAllText(Path.Combine(wo.fileInfo.directory, wo.fileInfo.fileName),
                              gpin.generateMainMill(!wo.useToothMill));
            if (wo.useToothMill)
            {
                File.WriteAllText(Path.Combine(wo.fileInfo.directory, wo.fileInfo.toothFileName),
                                  gpin.generateToothMill());
            }
        }
示例#2
0
        private GCodeWorkOrder[] makeWorkOrders()
        {
            string         error    = "";
            string         kind     = "pinion";
            GCodeWorkOrder woPinion = new GCodeWorkOrder();
            GCodeWorkOrder woGear   = new GCodeWorkOrder();

            if (!gatherWorkOrder(true, ref woPinion))
            {
                goto showError;
            }
            Control errControl;

            if (!verifyWorkOrder(woPinion, ref error, out errControl))
            {
                if (errControl is TextBox)
                {
                    (errControl as TextBox).SelectAll();
                }
                goto showError;
            }
            kind  = "gear";
            error = "";
            if (!gatherWorkOrder(false, ref woGear))
            {
                goto showError;
            }
            if (!verifyWorkOrder(woGear, ref error, out errControl))
            {
                if (errControl != null)
                {
                    if (errControl is TextBox)
                    {
                        (errControl as TextBox).SelectAll();
                    }
                }
                goto showError;
            }
            return(new GCodeWorkOrder[] { woPinion, woGear });

showError:
            MessageBox.Show(
                "Cannot create Gcode for the " + kind + " because of incorrect parameters.\nPlease correct the error and try again.\n" + error,
                "Incorrect parameter");
            return(null);
        }
示例#3
0
 internal bool gatherWorkOrder(bool pinion, ref GCodeWorkOrder wo)
 {
     wo.ok   = false;
     wo.info = info_;
     if (!wo.info.ok)
     {
         return(false);
     }
     wo.calc = pinion ? calcPinion_ : calcGear_;
     if (!wo.calc.ok)
     {
         return(false);
     }
     wo.profile = pinion ? profileA_ : profileB_;
     if (wo.profile == null)
     {
         return(false);
     }
     wo.numTeeth = pinion ? info_.aNumTeeth : info_.bNumTeeth;
     if (!getDimensions(ref wo.dimensions))
     {
         return(false);
     }
     if (!getMillInfo(ref wo.mainMill))
     {
         return(false);
     }
     wo.useToothMill = checkUseToothMill.Checked;
     if (wo.useToothMill)
     {
         if (!getToothMillInfo(ref wo.toothMill))
         {
             return(false);
         }
     }
     getFileInfo(pinion, ref wo.fileInfo);
     wo.ok = true;
     return(true);
 }
示例#4
0
        internal bool verifyWorkOrder(GCodeWorkOrder wo, ref string error, out Control errControl)
        {
            errControl = null;
            error      = "";

            //  verify that the various circular features can fit
            double baseDiameter = wo.calc.radius - wo.calc.dedendum;
            double circularSum  = wo.dimensions.ridgeMargin + wo.dimensions.ridgeThickness +
                                  wo.dimensions.holeWallThickness + wo.dimensions.holeDiameter * 0.5f;

            if (circularSum > baseDiameter)
            {
                error = "The specified ridge, wall, hole and margin thicknesses sum up ("
                        + circularSum.ToString("#.##") + ") to more than the base diameter ("
                        + baseDiameter.ToString("#.##") + ").";
                errControl = textRidgeThickness;
                return(false);
            }

            //  verify that the end mill can cut deep enough
            if (wo.dimensions.holeDiameter > 0 && wo.mainMill.cuttingDepth < wo.dimensions.stockThickness)
            {
                error      = "The end mill cannot cut through the stock, and a hole is specified.";
                errControl = textHoleDiameter;
                return(false);
            }
            double ridgeTop = wo.dimensions.plateThickness + wo.dimensions.toothThickness +
                              wo.dimensions.ridgeHeight;

            if (wo.dimensions.stockThickness - ridgeTop > wo.mainMill.cuttingDepth)
            {
                error      = "The end mill cannot cut down to the top of the ridge features or teeth.";
                errControl = textMaxCuttingDepth;
                return(false);
            }
            if (wo.dimensions.ridgeHeight > wo.mainMill.cuttingDepth)
            {
                error      = "The end mill cannot cut down the extent of the ridge height.";
                errControl = textRidgeHeight;
                return(false);
            }
            if (wo.dimensions.toothThickness > wo.mainMill.cuttingDepth)
            {
                error      = "The end mill cannot cut down the extent of the teeth.";
                errControl = textToothThickness;
                return(false);
            }
            if (wo.dimensions.plateThickness + wo.dimensions.toothThickness > wo.mainMill.cuttingDepth)
            {
                error      = "The end mill cannot cut down the extent of the plate and tooth depth.";
                errControl = textPlateThickness;
                return(false);
            }
            if (wo.dimensions.plateThickness + wo.dimensions.toothThickness + wo.dimensions.ridgeHeight -
                wo.dimensions.ridgeMargin > wo.mainMill.cuttingDepth)
            {
                error = "The end mill cannot cut down the extent of ridge plus tooth plus plate, " +
                        "and enough ridge margin is not specified.";
                errControl = textRidgeMargin;
                return(false);
            }

            //  verify that face milling will work
            if (wo.dimensions.faceMilling != FaceMilling.DoNotMill)
            {
                if (wo.calc.radius - wo.calc.dedendum - wo.dimensions.ridgeMargin - wo.dimensions.ridgeThickness
                    - wo.dimensions.holeWallThickness - wo.dimensions.holeDiameter * 0.5f <
                    wo.mainMill.diameter)
                {
                    error      = "The end mill is bigger than the face width, and face milling is specified.";
                    errControl = comboFaceMilling;
                    return(false);
                }
            }
            if (wo.dimensions.faceMilling == FaceMilling.MillToPlate && wo.dimensions.plateThickness == 0)
            {
                error      = "Face milling is set to mill to plate, but no plate thickness is specified.";
                errControl = comboFaceMilling;
                return(false);
            }
            if (wo.dimensions.faceMilling == FaceMilling.MillToPlate &&
                wo.dimensions.holeWallThickness > 0 &&
                wo.mainMill.cuttingDepth < wo.dimensions.stockThickness - wo.dimensions.plateThickness)
            {
                error      = "Face milling is set to mill to plate, and a hole wall is specified, but the end mill cannot cut the stock down to the plate.";
                errControl = comboFaceMilling;
                return(false);
            }
            if (wo.dimensions.faceMilling == FaceMilling.MillToPlate &&
                wo.dimensions.ridgeHeight + wo.dimensions.toothThickness > wo.mainMill.cuttingDepth)
            {
                error      = "Face milling is set to mill to plate, but the end mill cannot cut the extent of the ridge height plus tooth height.";
                errControl = comboFaceMilling;
                return(false);
            }

            //  verify that hole milling will work
            if (wo.dimensions.holeDiameter > 0 && wo.mainMill.diameter > wo.dimensions.holeDiameter)
            {
                error      = "The end mill is bigger than the specified hole.";
                errControl = textHoleDiameter;
                return(false);
            }

            //  verify that tooth milling has a chance of working
            double oneThirdToothSpacing = (wo.calc.radius - wo.calc.dedendum) * 2 * Math.PI / wo.calc.numTeeth / 3;

            if (!wo.useToothMill && wo.mainMill.diameter > oneThirdToothSpacing)
            {
                error = "The end mill is bigger than one-third the tooth spacing ("
                        + oneThirdToothSpacing.ToString("#.##") + "), and no tooth specific mill is specified.";
                errControl = textBoxEndMillDiameter;
                return(false);
            }
            if (!wo.useToothMill &&
                wo.mainMill.cuttingDepth + wo.dimensions.ridgeMargin < wo.dimensions.toothThickness + wo.dimensions.ridgeHeight)
            {
                error      = "There is not sufficient clearance for the mill between the tooth and the ridge.";
                errControl = textRidgeMargin;
                return(false);
            }
            if (wo.useToothMill && wo.toothMill.diameter > oneThirdToothSpacing)
            {
                error = "The tooth mill is bigger than one-third the tooth spacing ("
                        + oneThirdToothSpacing.ToString("#.##") + ") and cannot reliably mill tooth shapes.";
                errControl = textToothMillDiameter;
                return(false);
            }
            if (wo.useToothMill && wo.toothMill.cuttingDepth < wo.dimensions.toothThickness)
            {
                error      = "The tooth mill cannot cut the full tooth thickness.";
                errControl = textToothCuttingDepth;
                return(false);
            }
            if (wo.useToothMill &&
                wo.toothMill.cuttingDepth + wo.dimensions.ridgeMargin < wo.dimensions.toothThickness + wo.dimensions.ridgeHeight)
            {
                error      = "There is not sufficient clearance for the tooth mill to the ridge.";
                errControl = textRidgeMargin;
                return(false);
            }

            if (wo.useToothMill && wo.toothMill.diameter.ToString(".##") == wo.mainMill.diameter.ToString(".##"))
            {
                error      = "The tooth mill diameter is the same as the main mill diameter.";
                errControl = textToothMillDiameter;
                return(false);
            }

            //  verify feeds and speeds (just loosely)
            if (wo.mainMill.feed < 0.1f || wo.mainMill.feed > 50)
            {
                error      = "The feed is out of range [0.1, 50].";
                errControl = textMillFeed;
                return(false);
            }
            if (wo.mainMill.speed < 250 || wo.mainMill.speed > 25000)
            {
                error      = "The speed is out of range [250, 25000].";
                errControl = textMillSpeed;
                return(false);
            }

            if (wo.useToothMill && (wo.mainMill.feed < 0.1f || wo.mainMill.feed > 50))
            {
                error      = "The tooth mill feed is out of range [0.1, 50].";
                errControl = textToothFeed;
                return(false);
            }
            if (wo.useToothMill && (wo.mainMill.speed < 250 || wo.mainMill.speed > 25000))
            {
                error      = "The tooth mill speed is out of range [250, 25000].";
                errControl = textToothSpeed;
                return(false);
            }

            if (!Directory.Exists(wo.fileInfo.directory))
            {
                error      = "The output directory does not exist.\n" + wo.fileInfo.directory;
                errControl = buttonDirectory;
                return(false);
            }

            return(true);
        }
示例#5
0
 internal bool gatherWorkOrder(bool pinion, ref GCodeWorkOrder wo)
 {
     wo.ok = false;
     wo.info = info_;
     if (!wo.info.ok)
     {
         return false;
     }
     wo.calc = pinion ? calcPinion_ : calcGear_;
     if (!wo.calc.ok)
     {
         return false;
     }
     wo.profile = pinion ? profileA_ : profileB_;
     if (wo.profile == null)
     {
         return false;
     }
     wo.numTeeth = pinion ? info_.aNumTeeth : info_.bNumTeeth;
     if (!getDimensions(ref wo.dimensions))
     {
         return false;
     }
     if (!getMillInfo(ref wo.mainMill))
     {
         return false;
     }
     wo.useToothMill = checkUseToothMill.Checked;
     if (wo.useToothMill)
     {
         if (!getToothMillInfo(ref wo.toothMill))
         {
             return false;
         }
     }
     getFileInfo(pinion, ref wo.fileInfo);
     wo.ok = true;
     return true;
 }
示例#6
0
 public static void executeWorkOrder(GCodeWorkOrder wo)
 {
     //  finally, the rubber meets the road!
     GCodeGenerator gpin = new GCodeGenerator(wo);
     File.WriteAllText(Path.Combine(wo.fileInfo.directory, wo.fileInfo.fileName),
         gpin.generateMainMill(!wo.useToothMill));
     if (wo.useToothMill)
     {
         File.WriteAllText(Path.Combine(wo.fileInfo.directory, wo.fileInfo.toothFileName),
             gpin.generateToothMill());
     }
 }
示例#7
0
        internal bool verifyWorkOrder(GCodeWorkOrder wo, ref string error, out Control errControl)
        {
            errControl = null;
            error = "";

            //  verify that the various circular features can fit
            double baseDiameter = wo.calc.radius - wo.calc.dedendum;
            double circularSum = wo.dimensions.ridgeMargin + wo.dimensions.ridgeThickness + 
                wo.dimensions.holeWallThickness + wo.dimensions.holeDiameter * 0.5f;
            if (circularSum > baseDiameter)
            {
                error = "The specified ridge, wall, hole and margin thicknesses sum up ("
                    + circularSum.ToString("#.##") + ") to more than the base diameter (" 
                    + baseDiameter.ToString("#.##") + ").";
                errControl = textRidgeThickness;
                return false;
            }

            //  verify that the end mill can cut deep enough
            if (wo.dimensions.holeDiameter > 0 && wo.mainMill.cuttingDepth < wo.dimensions.stockThickness)
            {
                error = "The end mill cannot cut through the stock, and a hole is specified.";
                errControl = textHoleDiameter;
                return false;
            }
            double ridgeTop = wo.dimensions.plateThickness + wo.dimensions.toothThickness +
                wo.dimensions.ridgeHeight;
            if (wo.dimensions.stockThickness - ridgeTop > wo.mainMill.cuttingDepth)
            {
                error = "The end mill cannot cut down to the top of the ridge features or teeth.";
                errControl = textMaxCuttingDepth;
                return false;
            }
            if (wo.dimensions.ridgeHeight > wo.mainMill.cuttingDepth)
            {
                error = "The end mill cannot cut down the extent of the ridge height.";
                errControl = textRidgeHeight;
                return false;
            }
            if (wo.dimensions.toothThickness > wo.mainMill.cuttingDepth)
            {
                error = "The end mill cannot cut down the extent of the teeth.";
                errControl = textToothThickness;
                return false;
            }
            if (wo.dimensions.plateThickness + wo.dimensions.toothThickness > wo.mainMill.cuttingDepth)
            {
                error = "The end mill cannot cut down the extent of the plate and tooth depth.";
                errControl = textPlateThickness;
                return false;
            }
            if (wo.dimensions.plateThickness + wo.dimensions.toothThickness + wo.dimensions.ridgeHeight -
                wo.dimensions.ridgeMargin > wo.mainMill.cuttingDepth)
            {
                error = "The end mill cannot cut down the extent of ridge plus tooth plus plate, " +
                    "and enough ridge margin is not specified.";
                errControl = textRidgeMargin;
                return false;
            }

            //  verify that face milling will work
            if (wo.dimensions.faceMilling != FaceMilling.DoNotMill)
            {
                if (wo.calc.radius - wo.calc.dedendum - wo.dimensions.ridgeMargin - wo.dimensions.ridgeThickness
                    - wo.dimensions.holeWallThickness - wo.dimensions.holeDiameter * 0.5f <
                    wo.mainMill.diameter)
                {
                    error = "The end mill is bigger than the face width, and face milling is specified.";
                    errControl = comboFaceMilling;
                    return false;
                }
            }
            if (wo.dimensions.faceMilling == FaceMilling.MillToPlate && wo.dimensions.plateThickness == 0)
            {
                error = "Face milling is set to mill to plate, but no plate thickness is specified.";
                errControl = comboFaceMilling;
                return false;
            }
            if (wo.dimensions.faceMilling == FaceMilling.MillToPlate && 
                wo.dimensions.holeWallThickness > 0 &&
                wo.mainMill.cuttingDepth < wo.dimensions.stockThickness - wo.dimensions.plateThickness)
            {
                error = "Face milling is set to mill to plate, and a hole wall is specified, but the end mill cannot cut the stock down to the plate.";
                errControl = comboFaceMilling;
                return false;
            }
            if (wo.dimensions.faceMilling == FaceMilling.MillToPlate &&
                wo.dimensions.ridgeHeight + wo.dimensions.toothThickness > wo.mainMill.cuttingDepth)
            {
                error = "Face milling is set to mill to plate, but the end mill cannot cut the extent of the ridge height plus tooth height.";
                errControl = comboFaceMilling;
                return false;
            } 

            //  verify that hole milling will work
            if (wo.dimensions.holeDiameter > 0 && wo.mainMill.diameter > wo.dimensions.holeDiameter)
            {
                error = "The end mill is bigger than the specified hole.";
                errControl = textHoleDiameter;
                return false;
            }

            //  verify that tooth milling has a chance of working
            double oneThirdToothSpacing = (wo.calc.radius - wo.calc.dedendum) * 2 * Math.PI / wo.calc.numTeeth / 3;
            if (!wo.useToothMill && wo.mainMill.diameter > oneThirdToothSpacing)
            {
                error = "The end mill is bigger than one-third the tooth spacing ("
                    + oneThirdToothSpacing.ToString("#.##") +"), and no tooth specific mill is specified.";
                errControl = textBoxEndMillDiameter;
                return false;
            }
            if (!wo.useToothMill &&
                wo.mainMill.cuttingDepth + wo.dimensions.ridgeMargin < wo.dimensions.toothThickness + wo.dimensions.ridgeHeight)
            {
                error = "There is not sufficient clearance for the mill between the tooth and the ridge.";
                errControl = textRidgeMargin;
                return false;
            }
            if (wo.useToothMill && wo.toothMill.diameter > oneThirdToothSpacing)
            {
                error = "The tooth mill is bigger than one-third the tooth spacing ("
                    + oneThirdToothSpacing.ToString("#.##") + ") and cannot reliably mill tooth shapes.";
                errControl = textToothMillDiameter;
                return false;
            }
            if (wo.useToothMill && wo.toothMill.cuttingDepth < wo.dimensions.toothThickness)
            {
                error = "The tooth mill cannot cut the full tooth thickness.";
                errControl = textToothCuttingDepth;
                return false;
            }
            if (wo.useToothMill &&
                wo.toothMill.cuttingDepth + wo.dimensions.ridgeMargin < wo.dimensions.toothThickness + wo.dimensions.ridgeHeight)
            {
                error = "There is not sufficient clearance for the tooth mill to the ridge.";
                errControl = textRidgeMargin;
                return false;
            }

            if (wo.useToothMill && wo.toothMill.diameter.ToString(".##") == wo.mainMill.diameter.ToString(".##"))
            {
                error = "The tooth mill diameter is the same as the main mill diameter.";
                errControl = textToothMillDiameter;
                return false;
            }

            //  verify feeds and speeds (just loosely)
            if (wo.mainMill.feed < 0.1f || wo.mainMill.feed > 50)
            {
                error = "The feed is out of range [0.1, 50].";
                errControl = textMillFeed;
                return false;
            }
            if (wo.mainMill.speed < 250 || wo.mainMill.speed > 25000)
            {
                error = "The speed is out of range [250, 25000].";
                errControl = textMillSpeed;
                return false;
            }

            if (wo.useToothMill && (wo.mainMill.feed < 0.1f || wo.mainMill.feed > 50))
            {
                error = "The tooth mill feed is out of range [0.1, 50].";
                errControl = textToothFeed;
                return false;
            }
            if (wo.useToothMill && (wo.mainMill.speed < 250 || wo.mainMill.speed > 25000))
            {
                error = "The tooth mill speed is out of range [250, 25000].";
                errControl = textToothSpeed;
                return false;
            }

            if (!Directory.Exists(wo.fileInfo.directory))
            {
                error = "The output directory does not exist.\n" + wo.fileInfo.directory;
                errControl = buttonDirectory;
                return false;
            }

            return true;
        }
示例#8
0
 private GCodeWorkOrder[] makeWorkOrders()
 {
     string error = "";
     string kind = "pinion";
     GCodeWorkOrder woPinion = new GCodeWorkOrder();
     GCodeWorkOrder woGear = new GCodeWorkOrder();
     if (!gatherWorkOrder(true, ref woPinion))
     {
         goto showError;
     }
     Control errControl;
     if (!verifyWorkOrder(woPinion, ref error, out errControl))
     {
         if (errControl is TextBox)
         {
             (errControl as TextBox).SelectAll();
         }
         goto showError;
     }
     kind = "gear";
     error = "";
     if (!gatherWorkOrder(false, ref woGear))
     {
         goto showError;
     }
     if (!verifyWorkOrder(woGear, ref error, out errControl))
     {
         if (errControl != null)
         {
             if (errControl is TextBox)
             {
                 (errControl as TextBox).SelectAll();
             }
         }
         goto showError;
     }
     return new GCodeWorkOrder[] { woPinion, woGear };
 showError:
     MessageBox.Show(
         "Cannot create Gcode for the " + kind + " because of incorrect parameters.\nPlease correct the error and try again.\n" + error,
         "Incorrect parameter");
     return null;
 }
示例#9
0
 private bool executeWorkOrders(GCodeWorkOrder[] orders)
 {
     try
     {
         foreach (GCodeWorkOrder wo in orders)
         {
             executeWorkOrder(wo);
         }
     }
     catch (System.Exception x)
     {
         MessageBox.Show(
             "Could not export gcode.\n" + x.Message,
             "Error Exporting");
         return false;
     }
     return true;
 }
示例#10
0
 public GCodeGenerator(GCodeWorkOrder wo)
 {
     this.work = wo;
 }
示例#11
0
 public GCodeGenerator(GCodeWorkOrder wo)
 {
     this.work = wo;
 }