/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// If we draw a line with an aperture it will not always have linear ends /// for example if the aperture is a circle it will have half circle ends. Each /// line that is drawn calls this to make it look right visually /// </summary> /// <param name="graphicsObj">a graphics object to draw on</param> /// <param name="workingBrush">a brush to draw with</param> /// <param name="workingPen">the pen used for the line, we get the width from this</param> /// <param name="x1">the first x value</param> /// <param name="y1">the first y value</param> /// <param name="x2">the second x value</param> /// <param name="y2">the second y value</param> /// <param name="xyComp">the xy compensation factor</param> /// <returns>z success, nz fail</returns> public override void FixupLineEndpointsForGCodePlot(IsoPlotBuilder isoPlotBuilder, GerberFileStateMachine stateMachine, int x1, int y1, int x2, int y2, int radius, int xyComp) { IsoPlotUsageTagFlagEnum usageMode = IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE; if (isoPlotBuilder == null) { return; } if (stateMachine == null) { return; } // set the usage mode if (stateMachine.GerberFileLayerPolarity == GerberLayerPolarityEnum.CLEAR) { usageMode = IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE; } else { usageMode = IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE; } // fix up the two end points isoPlotBuilder.DrawGSCircle(usageMode, x1, y1, radius, stateMachine.BackgroundFillModeAccordingToPolarity, stateMachine.WantClockWise); isoPlotBuilder.DrawGSCircle(usageMode, x2, y2, radius, stateMachine.BackgroundFillModeAccordingToPolarity, stateMachine.WantClockWise); return; }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Perform a circular aperture flash. This is a static call so other things can call it /// if they need to do so. /// </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 static void PerformCircularApertureFlashWithHole(IsoPlotBuilder isoPlotBuilder, GerberFileStateMachine stateMachine, int x1, int y1, int xyComp, int workingOuterDiameter, float holeDia) { int hDia; int holeRadius = 0; int builderID = 0; int holeBuilderObjID = 0; if (stateMachine.BackgroundFillModeAccordingToPolarity == GSFillModeEnum.FillMode_BACKGROUND) { // draw the circle builderID = isoPlotBuilder.DrawGSCircle(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, x1, y1, ((workingOuterDiameter + xyComp) / 2), GSFillModeEnum.FillMode_BACKGROUND, stateMachine.WantClockWise); // do we need to do a hole? if (holeDia > 0) { // yes we do hDia = (int)Math.Round((holeDia * stateMachine.IsoPlotPointsPerAppUnit)); 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); } } } 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 (holeDia > 0) { // we are dealing with a erase flash with a hole // 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 outerRadius = (workingOuterDiameter + xyComp) / 2; builderID = isoPlotBuilder.DrawGSCircle(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1, y1, outerRadius, GSFillModeEnum.FillMode_NONE, stateMachine.WantClockWise); // 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((holeDia * stateMachine.IsoPlotPointsPerAppUnit)); 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); isoPlotBuilder.BackgroundFillGSByBoundaryComplexVert(builderIDList, IsoPlotObject.DEFAULT_ISOPLOTOBJECT_ID, x1 - outerRadius - 1, y1 - outerRadius - 1, x1 + outerRadius + 1, y1 + outerRadius + 1, -1); } else { // draw the circle, we use invert edges here so we draw only if it is on some other background, we still erase everything under it though int outerRadius = (workingOuterDiameter + xyComp) / 2; builderID = isoPlotBuilder.DrawGSCircle(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1, y1, outerRadius, GSFillModeEnum.FillMode_ERASE, stateMachine.WantClockWise); } } return; }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Flash an aperture for a OBRound 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; bool ellipseIsVertical = false; int workingOuterDiameter = int.MinValue; float majorEllipseAxis = float.NegativeInfinity; float minorEllipseAxis = float.NegativeInfinity; float majorEllipseAxisAdjustedForCircle = float.NegativeInfinity; int x1EllipseCompensatedCenterpoint; int y1EllipseCompensatedCenterpoint; int x2EllipseCompensatedCenterpoint; int y2EllipseCompensatedCenterpoint; float circle1StartDegrees = 90; float circle2StartDegrees = 270; float circle1SweepDegrees = 180; float circle2SweepDegrees = 180; int majorEllipseAxisEndpointCompensation = 0; int outerBoundingBoxLL_X = 0; int outerBoundingBoxLL_Y = 0; int outerBoundingBoxUR_X = 0; int outerBoundingBoxUR_Y = 0; if (isoPlotBuilder == null) { return; } if (stateMachine == null) { return; } // NOTE: it is not possible to encode an Oval or Ellipse in GCode, you have to // represent this with a line segment which has two circles at the end // the total length should be equal the longest dimension. The shortest // dimension will be used as the diameter of the circles. // NOTE: we need not deal with ellipses in here which do not have major and minor // axis parallel to the X and Y axis. There is no way to represent this in // Gerber code and they are usually encoded as an AM macro which is a // combination of two circles and a line - just as we are doing (see above) // and for exactly the same reasons. // find the shortest and longest dimensions. NOTE according to the spec OBRounds // cannot have a rotation. They are either Horizontal or Vertical if (xAxisDimension > yAxisDimension) { majorEllipseAxis = xAxisDimension; minorEllipseAxis = yAxisDimension; ellipseIsVertical = false; } else { majorEllipseAxis = yAxisDimension; minorEllipseAxis = xAxisDimension; ellipseIsVertical = true; } // now figure out the length of the line between the circles majorEllipseAxisAdjustedForCircle = majorEllipseAxis - minorEllipseAxis; // sanity checks if (majorEllipseAxisAdjustedForCircle < 0) { // what the hell? we got problems throw new Exception("Cannot draw ellipse adjusted axis less than zero."); } else if (majorEllipseAxisAdjustedForCircle == 0) { // special case, we must be dealing with a circle, just draw one workingOuterDiameter = (int)Math.Round((majorEllipseAxis * stateMachine.IsoPlotPointsPerAppUnit)); // now do the flash GerberAperture_CCode.PerformCircularApertureFlashWithHole(isoPlotBuilder, stateMachine, x1, y1, xyComp, workingOuterDiameter, HoleDiameter); return; } // we are not dealing with a circle. We are dealing with an OBRound // now figure out the diameter of the endpoint circles workingOuterDiameter = (int)Math.Round((minorEllipseAxis * stateMachine.IsoPlotPointsPerAppUnit)); // calc the amount we have to add/subtract on the center point to get to the // endpoints majorEllipseAxisEndpointCompensation = (int)Math.Round(((majorEllipseAxisAdjustedForCircle * stateMachine.IsoPlotPointsPerAppUnit) / 2)); majorEllipseAxisEndpointCompensation += (xyComp / 2); // compensate the endpoints, the way we do this is dependent on whether // the ellipse is horizontal or vertical. NOTE according to the spec OBRounds // cannot have a rotation. They are either Horizontal or Vertical if (ellipseIsVertical == false) { x1EllipseCompensatedCenterpoint = x1 - majorEllipseAxisEndpointCompensation; x2EllipseCompensatedCenterpoint = x1 + majorEllipseAxisEndpointCompensation; y1EllipseCompensatedCenterpoint = y1; y2EllipseCompensatedCenterpoint = y1; circle1StartDegrees = 90; circle1SweepDegrees = 180; circle2StartDegrees = 270; circle2SweepDegrees = 180; } else { x1EllipseCompensatedCenterpoint = x1; x2EllipseCompensatedCenterpoint = x1; y1EllipseCompensatedCenterpoint = y1 - majorEllipseAxisEndpointCompensation; y2EllipseCompensatedCenterpoint = y1 + majorEllipseAxisEndpointCompensation; circle1StartDegrees = 180; circle1SweepDegrees = 180; circle2StartDegrees = 0; circle2SweepDegrees = 180; } // calculate the endpoints of the wide line rectangle. MiscGraphicsUtils.GetWideLineEndPoints(x1EllipseCompensatedCenterpoint, y1EllipseCompensatedCenterpoint, x2EllipseCompensatedCenterpoint, y2EllipseCompensatedCenterpoint, (workingOuterDiameter + xyComp), out Point ptLL, out Point ptUL, out Point ptUR, out Point ptLR); // now set the dimensions of the bounding box if (ellipseIsVertical == false) { outerBoundingBoxLL_X = ptLL.X - x1EllipseCompensatedCenterpoint; outerBoundingBoxLL_Y = ptLL.Y; outerBoundingBoxUR_X = ptUR.X + x2EllipseCompensatedCenterpoint; outerBoundingBoxUR_Y = ptUR.Y; } else { outerBoundingBoxLL_X = ptLL.X; outerBoundingBoxLL_Y = ptLL.Y - y1EllipseCompensatedCenterpoint; outerBoundingBoxUR_X = ptUR.X; outerBoundingBoxUR_Y = ptUR.Y + y2EllipseCompensatedCenterpoint; } // now we draw according to the polarity if (stateMachine.BackgroundFillModeAccordingToPolarity == GSFillModeEnum.FillMode_BACKGROUND) { // draw the first arc int circle1BuilderID = isoPlotBuilder.DrawGSContourArc(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, x1EllipseCompensatedCenterpoint, y1EllipseCompensatedCenterpoint, circle1StartDegrees, circle1SweepDegrees, ((workingOuterDiameter + xyComp) / 2), false, true, false); // draw the second arc int circle2BuilderID = isoPlotBuilder.DrawGSContourArc(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, x2EllipseCompensatedCenterpoint, y2EllipseCompensatedCenterpoint, circle2StartDegrees, circle2SweepDegrees, ((workingOuterDiameter + xyComp) / 2), false, true, false); // draw in the top line int line1BuilderID = isoPlotBuilder.DrawGSLineContourLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, ptUL.X, ptUL.Y, ptUR.X, ptUR.Y); // draw in the bottom line int line2BuilderID = isoPlotBuilder.DrawGSLineContourLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, ptLL.X, ptLL.Y, ptLR.X, ptLR.Y); // create a list of the builder IDs used List <int> builderIDList = new List <int>(); builderIDList.Add(circle1BuilderID); builderIDList.Add(circle2BuilderID); builderIDList.Add(line1BuilderID); builderIDList.Add(line2BuilderID); // now background fill the complex object, note how we only fill with the circle1BuilderID, This will be important when filling in the hole isoPlotBuilder.BackgroundFillGSByBoundaryComplexVert(builderIDList, circle1BuilderID, outerBoundingBoxLL_X, outerBoundingBoxLL_Y, outerBoundingBoxUR_X, outerBoundingBoxUR_Y, -1); // 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 obRoundObj we just drew, note we only filled with circle1BuilderID above so that is all we need to remove isoPlotBuilder.EraseABuilderIDFromRegionUsingABuilderID(holeBuilderObjID, circle1BuilderID, 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 // draw the first arc int circle1BuilderID = isoPlotBuilder.DrawGSContourArc(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1EllipseCompensatedCenterpoint, y1EllipseCompensatedCenterpoint, circle1StartDegrees, circle1SweepDegrees, ((workingOuterDiameter + xyComp) / 2), false, true, false); // draw the second arc int circle2BuilderID = isoPlotBuilder.DrawGSContourArc(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x2EllipseCompensatedCenterpoint, y2EllipseCompensatedCenterpoint, circle2StartDegrees, circle2SweepDegrees, ((workingOuterDiameter + xyComp) / 2), false, true, false); // draw in the top line int line1BuilderID = isoPlotBuilder.DrawGSLineContourLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, ptUL.X, ptUL.Y, ptUR.X, ptUR.Y); // draw in the bottom line int line2BuilderID = isoPlotBuilder.DrawGSLineContourLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, ptLL.X, ptLL.Y, ptLR.X, ptLR.Y); // create a list of the builder IDs used List <int> builderIDList = new List <int>(); builderIDList.Add(circle1BuilderID); builderIDList.Add(circle2BuilderID); builderIDList.Add(line1BuilderID); builderIDList.Add(line2BuilderID); // note that at this point we effectively have an invert edge OBRound with 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); } builderIDList.Add(holeBuilderObjID); // now erase between the outer and inner circles isoPlotBuilder.BackgroundFillGSByBoundaryComplexVert(builderIDList, IsoPlotObject.DEFAULT_ISOPLOTOBJECT_ID, outerBoundingBoxLL_X, outerBoundingBoxLL_Y, outerBoundingBoxUR_X, outerBoundingBoxUR_Y, -1); } else { // draw the obRound, we use invert edges here so we draw only if it is on some other background, we still erase everything under it though // draw the first arc int circle1BuilderID = isoPlotBuilder.DrawGSContourArc(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1EllipseCompensatedCenterpoint, y1EllipseCompensatedCenterpoint, circle1StartDegrees, circle1SweepDegrees, ((workingOuterDiameter + xyComp) / 2), false, true, false); // draw the second arc int circle2BuilderID = isoPlotBuilder.DrawGSContourArc(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x2EllipseCompensatedCenterpoint, y2EllipseCompensatedCenterpoint, circle2StartDegrees, circle2SweepDegrees, ((workingOuterDiameter + xyComp) / 2), false, true, false); // draw in the top line int line1BuilderID = isoPlotBuilder.DrawGSLineContourLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, ptUL.X, ptUL.Y, ptUR.X, ptUR.Y); // draw in the bottom line int line2BuilderID = isoPlotBuilder.DrawGSLineContourLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, ptLL.X, ptLL.Y, ptLR.X, ptLR.Y); // create a list of the builder IDs used List <int> builderIDList = new List <int>(); builderIDList.Add(circle1BuilderID); builderIDList.Add(circle2BuilderID); builderIDList.Add(line1BuilderID); builderIDList.Add(line2BuilderID); // now erase the background isoPlotBuilder.BackgroundFillGSByBoundaryComplexVert(builderIDList, IsoPlotObject.DEFAULT_ISOPLOTOBJECT_ID, outerBoundingBoxLL_X, outerBoundingBoxLL_Y, outerBoundingBoxUR_X, outerBoundingBoxUR_Y, -1); } } /* * DebugMessage(""); * DebugMessage("majorEllipseAxis=" + (majorEllipseAxis * stateMachine.IsoPlotPointsPerAppUnit)); * DebugMessage("minorEllipseAxis =" + (minorEllipseAxis * stateMachine.IsoPlotPointsPerAppUnit).ToString()); * DebugMessage("y1EllipseCompensatedCenterpoint =" + (y1EllipseCompensatedCenterpoint).ToString()); * DebugMessage("y2EllipseCompensatedCenterpoint =" + (y2EllipseCompensatedCenterpoint).ToString()); * DebugMessage("y2EllipseCompensatedCenterpoint-y1EllipseCompensatedCenterpoint =" + (y2EllipseCompensatedCenterpoint - y1EllipseCompensatedCenterpoint).ToString()); * DebugMessage("xyComp =" + xyComp.ToString()); * DebugMessage("workingOuterDiameter =" + workingOuterDiameter.ToString()); * DebugMessage(""); */ return; }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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)); // 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.DrawGSCircle(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, effectiveCenter_X, effectiveCenter_Y, radius, GSFillModeEnum.FillMode_BACKGROUND, stateMachine.WantClockWise); // 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.DrawGSCircle(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, effectiveCenter_X, effectiveCenter_Y, radius, GSFillModeEnum.FillMode_NONE, stateMachine.WantClockWise); // 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); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Flashes the rectangular aperture at a point /// </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; } int xComp = (int)Math.Round(((XAxisDimension * stateMachine.IsoPlotPointsPerAppUnit))); int yComp = (int)Math.Round(((YAxisDimension * stateMachine.IsoPlotPointsPerAppUnit) / 2)); if (stateMachine.BackgroundFillModeAccordingToPolarity == GSFillModeEnum.FillMode_BACKGROUND) { // corrected, courtesy of MaikF int builderID = isoPlotBuilder.DrawGSLineOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, x1, y1 - yComp - xyComp / 2, x1, y1 + yComp + xyComp / 2, xComp + (1 * xyComp), 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 // draw the rectangle, 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 builderID = isoPlotBuilder.DrawGSLineOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1, y1 - yComp - xyComp / 2, x1, y1 + yComp + xyComp / 2, xComp + (1 * xyComp), 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); MiscGraphicsUtils.GetWideLineEndPoints(x1, y1 - yComp - xyComp / 2, x1, y1 + yComp + xyComp / 2, xComp + (1 * xyComp), out Point ptLL, out Point ptUL, out Point ptUR, out Point ptLR); // now erase the background isoPlotBuilder.BackgroundFillGSByBoundaryComplexVert(builderIDList, IsoPlotObject.DEFAULT_ISOPLOTOBJECT_ID, ptLL.X, ptLL.Y, ptUR.X, ptUR.Y, -1); } else { // draw the rectangle, we use invert edges here so we draw only if it is on some other background, we still erase everything under it though int builderID = isoPlotBuilder.DrawGSLineOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, x1, y1 - yComp - xyComp / 2, x1, y1 + yComp + xyComp / 2, xComp + (1 * xyComp), GSFillModeEnum.FillMode_ERASE); } } }