コード例 #1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Flash a macro primitive for a Circle on a GCode Plot
        /// </summary>
        /// <param name="isoPlotBuilder">the builder opbject</param>
        /// <param name="stateMachine">the statemachine</param>
        /// <param name="macroBuilderIDs">a list of builder IDs which have drawn in POSITIVE on this macro</param>
        /// <param name="xyComp">the xy compensation factor</param>
        /// <param name="x1">the first x value</param>
        /// <param name="y1">the first y value</param>
        /// <param name="varArray">the array to get the numbered variables from</param>
        /// <returns>z success, nz fail</returns>
        public override int FlashMacroPrimitiveForGCodePlot(GerberMacroVariableArray varArray, List <int> macroBuilderIDs, IsoPlotBuilder isoPlotBuilder, GerberFileStateMachine stateMachine, int x1, int y1, int xyComp)
        {
            // now do the flash
            int builderID            = 0;
            int workingOuterDiameter = int.MinValue;

            if (isoPlotBuilder == null)
            {
                return(-1);
            }
            if (stateMachine == null)
            {
                return(-1);
            }
            if (macroBuilderIDs == null)
            {
                return(-1);
            }

            // figure out the diameter
            float workingDiameter = GetDiameter(varArray);

            workingOuterDiameter = (int)Math.Round((workingDiameter * stateMachine.IsoPlotPointsPerAppUnit));
            int   workingNumSides = (int)GetNumSides(varArray);
            float rotationAngle   = GetDegreesRotation(varArray);

            // we will need the center point coords
            int primCenterPointInScreenCoords_X = (int)(GetXCenterCoord(varArray) * stateMachine.IsoPlotPointsPerAppUnit);
            int primCenterPointInScreenCoords_Y = (int)(GetYCenterCoord(varArray) * stateMachine.IsoPlotPointsPerAppUnit);

            int effectiveCenter_X = x1 + primCenterPointInScreenCoords_X;
            int effectiveCenter_Y = y1 + primCenterPointInScreenCoords_Y;

            //DebugMessage("efc_X=" + effectiveCenter_X.ToString() + ", " + "efc_Y=" + effectiveCenter_Y.ToString());

            if (GetApertureIsOn(varArray) == true)
            {
                // draw the circle
                int radius = (workingOuterDiameter + xyComp) / 2;
                builderID = isoPlotBuilder.DrawGSPolygonOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, effectiveCenter_X, effectiveCenter_Y, workingNumSides, workingOuterDiameter + xyComp, rotationAngle, stateMachine.BackgroundFillModeAccordingToPolarity);
                // return this, the caller keeps track of these
                return(builderID);
            }
            else
            {
                // draw the circle, we use invert edges here so we draw the circle only if it is on some other background, use no fill. We will erase between it and the hole later
                int radius = (workingOuterDiameter - xyComp) / 2;
                if (radius <= 0)
                {
                    return(-1);
                }
                builderID = isoPlotBuilder.DrawGSPolygonOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, effectiveCenter_X, effectiveCenter_Y, workingNumSides, workingOuterDiameter - xyComp, rotationAngle, GSFillModeEnum.FillMode_NONE);

                // now we have to remove every builderID in the macro in every isoCell under the above object. This is not fast.
                // We know which ones might be there because we have a list

                int newX0 = effectiveCenter_X - radius;
                int newY0 = effectiveCenter_Y - radius;
                int newX1 = effectiveCenter_X + radius;
                int newY1 = effectiveCenter_Y + radius;

                // now remove everything belonging to the macro at this point which is under our transparent flash
                isoPlotBuilder.EraseBuilderIDListFromRegionUsingABuilderIDHoriz(macroBuilderIDs, builderID, newX0, newY0, newX1, newY1, -1);

                // now remove the transparent flash INVERT_EDGE if it is not on something belonging to the macro. This prevents us
                // cutting through non macro material.
                isoPlotBuilder.EraseBuilderIDIfNotOnCellWithIDsInList(macroBuilderIDs, builderID, newX0, newY0, newX1, newY1);

                // we do NOT return the builder ID here only the ones which draw in positive get returned
                return(0);
            }
        }
コード例 #2
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Flash an aperture for a Polygon on a GCode Plot
        /// </summary>
        /// <param name="isoPlotBuilder">the builder opbject</param>
        /// <param name="stateMachine">the statemachine</param>
        /// <param name="xyComp">the xy compensation factor</param>
        /// <param name="x1">the first x value</param>
        /// <param name="y1">the first y value</param>
        /// <returns>z success, nz fail</returns>
        public override void FlashApertureForGCodePlot(IsoPlotBuilder isoPlotBuilder, GerberFileStateMachine stateMachine, int x1, int y1, int xyComp)
        {
            int holeBuilderObjID = 0;
            int hDia;

            if (isoPlotBuilder == null)
            {
                return;
            }
            if (stateMachine == null)
            {
                return;
            }

            if (stateMachine.BackgroundFillModeAccordingToPolarity == GSFillModeEnum.FillMode_BACKGROUND)
            {
                int workingOuterDiameter = (int)Math.Round((OutsideDimension * stateMachine.IsoPlotPointsPerAppUnit));
                int builderID            = isoPlotBuilder.DrawGSPolygonOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, x1, y1, NumSides, workingOuterDiameter + xyComp, DegreesRotation, stateMachine.BackgroundFillModeAccordingToPolarity);
                // do we need to do a hole?
                if (HoleDiameter > 0)
                {
                    // yes we do
                    hDia = (int)Math.Round((HoleDiameter * stateMachine.IsoPlotPointsPerAppUnit));
                    int holeRadius = (hDia - xyComp) / 2;
                    if (holeRadius > 0)
                    {
                        // draw the circle for the hole
                        holeBuilderObjID = isoPlotBuilder.DrawGSCircle(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, x1, y1, holeRadius, GSFillModeEnum.FillMode_BACKGROUND, stateMachine.WantClockWise);

                        // There is more going on here than is immediately obvious
                        // we want the inside of the hole to not be filled with isocells from the holeBuilderObjID
                        // we could just have not filled it and only placed edge isocells
                        // but this causes complications on the erase. It is better to fill it then remove the outer
                        // object then remove the background only pixels of the holeBuilderObjID. This makes sure we
                        // get all of the outer objects isocells rather than relying on hitting the edge to
                        // figure out where to start.

                        // remove everything belonging to the outer circle from the circle we just drew, this
                        // leaves anything else which might be in there in there
                        isoPlotBuilder.EraseABuilderIDFromRegionUsingABuilderID(holeBuilderObjID, builderID, x1 - holeRadius - 1, y1 - holeRadius - 1, x1 + holeRadius + 1, y1 + holeRadius + 1);

                        // remove all background only pixels belonging to the hole circle leaving just the edge pixels
                        isoPlotBuilder.EraseBackgroundOnlyIsoCellsByBuilderID(holeBuilderObjID, x1 - holeRadius - 1, y1 - holeRadius - 1, x1 + holeRadius + 1, y1 + holeRadius + 1);
                    }
                }
            } // bottom of if (stateMachine.BackgroundFillModeAccordingToPolarity == GSFillModeEnum.FillMode_BACKGROUND)
            else if (stateMachine.BackgroundFillModeAccordingToPolarity == GSFillModeEnum.FillMode_ERASE)
            {
                // we have to decide whether we are drawing a hole or not. In Clear Polarity holes do not come in as solid DARK spot like you
                // think they would. Instead they just "do nothing" on the area the contents below them remain there and there is no fill or erase

                if (HoleDiameter > 0)
                {
                    // we are dealing with a erase flash with a transparent hole

                    int workingOuterDiameter = (int)Math.Round((OutsideDimension * stateMachine.IsoPlotPointsPerAppUnit));
                    int builderID            = isoPlotBuilder.DrawGSPolygonOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1, y1, NumSides, workingOuterDiameter + xyComp, DegreesRotation, GSFillModeEnum.FillMode_NONE);

                    // now do the hole we use invert edges so anything we draw over a background will get drawn, there is no fill
                    hDia = (int)Math.Round((HoleDiameter * stateMachine.IsoPlotPointsPerAppUnit));
                    int holeRadius = (hDia - xyComp) / 2;
                    if (holeRadius > 0)
                    {
                        // draw the circle for the hole using no fill. Whatever is in there is in there
                        holeBuilderObjID = isoPlotBuilder.DrawGSCircle(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1, y1, holeRadius, GSFillModeEnum.FillMode_NONE, stateMachine.WantClockWise);
                    }
                    // now erase between the outer and inner circles
                    // we are dealing with a simple erase flash, no hole
                    List <int> builderIDList = new List <int>();
                    builderIDList.Add(builderID);
                    builderIDList.Add(holeBuilderObjID);
                    // now erase the background
                    isoPlotBuilder.BackgroundFillGSByBoundaryComplexVert(builderIDList, IsoPlotObject.DEFAULT_ISOPLOTOBJECT_ID, x1 - workingOuterDiameter - 1, y1 - workingOuterDiameter - 1, x1 + workingOuterDiameter + 1, y1 + workingOuterDiameter + 1, -1);
                }
                else
                {
                    // draw the polygon, we use invert edges here so we draw only if it is on some other background, we still erase everything under it though
                    int workingOuterDiameter = (int)Math.Round((OutsideDimension * stateMachine.IsoPlotPointsPerAppUnit));
                    int builderID            = isoPlotBuilder.DrawGSPolygonOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1, y1, NumSides, workingOuterDiameter + xyComp, DegreesRotation, GSFillModeEnum.FillMode_ERASE);
                }
            }

            return;
        }