/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Flash a macro primitive for a CLine 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; if (isoPlotBuilder == null) { return(-1); } if (stateMachine == null) { return(-1); } if (macroBuilderIDs == null) { return(-1); } // figure out width and height float workingWidth = GetWidth(varArray); int lineWidthInScreenCoords = (int)Math.Round(workingWidth * stateMachine.IsoPlotPointsPerAppUnit); float workingHeight = GetLineLength(varArray); int lineHeightInScreenCoords = (int)Math.Round(workingHeight * stateMachine.IsoPlotPointsPerAppUnit); //DebugMessage("efc_X=" + effectiveCenter_X.ToString() + ", " + "efc_Y=" + effectiveCenter_Y.ToString()); // figure out the xyComp in plot coords, it comes in as screen coords here // we need it to feed into the rotation calculations float xyCompInPlotCoords = ((float)xyComp) / stateMachine.IsoPlotPointsPerAppUnit; xyCompInPlotCoords /= 2; // draw the line outline, is the polarity on? if (GetApertureIsOn(varArray) == false) { // we will need the center point coords PointF centerPoint = GetCenterPoint(varArray); int primCenterPointInScreenCoords_X = (int)(centerPoint.X * stateMachine.IsoPlotPointsPerAppUnit); int primCenterPointInScreenCoords_Y = (int)(centerPoint.Y * stateMachine.IsoPlotPointsPerAppUnit); int effectiveCenter_X = x1 + primCenterPointInScreenCoords_X; int effectiveCenter_Y = y1 + primCenterPointInScreenCoords_Y; // get the center points PointF centerPointLeft = this.GetLeftCenterCoord(varArray, xyCompInPlotCoords, true); PointF centerPointRight = this.GetRightCenterCoord(varArray, xyCompInPlotCoords, true); // convert them to screen coords int leftCenterPointInScreenCoords_X = (int)(centerPointLeft.X * stateMachine.IsoPlotPointsPerAppUnit); int leftCenterPointInScreenCoords_Y = (int)(centerPointLeft.Y * stateMachine.IsoPlotPointsPerAppUnit); int rightCenterPointInScreenCoords_X = (int)(centerPointRight.X * stateMachine.IsoPlotPointsPerAppUnit); int rightCenterPointInScreenCoords_Y = (int)(centerPointRight.Y * stateMachine.IsoPlotPointsPerAppUnit); // now calc the effective draw points int effectiveLeftCenterPoint_X = x1 + leftCenterPointInScreenCoords_X; int effectiveLeftCenterPoint_Y = y1 + leftCenterPointInScreenCoords_Y; int effectiveRightCenterPoint_X = x1 + rightCenterPointInScreenCoords_X; int effectiveRightCenterPoint_Y = y1 + rightCenterPointInScreenCoords_Y; // adjust the line height for the XY comp, the width was compensated earlier int lineHeightInScreenCoordsXYCompensated = lineHeightInScreenCoords - (xyComp); // clear polarity builderID = isoPlotBuilder.DrawGSLineOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, effectiveLeftCenterPoint_X, effectiveLeftCenterPoint_Y, effectiveRightCenterPoint_X, effectiveRightCenterPoint_Y, lineHeightInScreenCoordsXYCompensated, stateMachine.BackgroundFillModeAccordingToPolarity); // get the bounding box of this primitive RectangleF primBoundingBox = GetMacroPrimitiveBoundingBox(varArray); // convert to screen values, this is still the primitive bounding rect though RectangleF primBoundingBoxInScreenCoords = MiscGraphicsUtils.ConvertRectFToScreenCoordinates(primBoundingBox, stateMachine); // the bounding box is relative to the center coords we adjust to absolute int newX0 = (int)(effectiveCenter_X - (primBoundingBoxInScreenCoords.Width / 2)); int newY0 = (int)(effectiveCenter_Y - (primBoundingBoxInScreenCoords.Height / 2)); int newX1 = (int)(newX0 + primBoundingBoxInScreenCoords.Width); int newY1 = (int)(newY0 + primBoundingBoxInScreenCoords.Height); // 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); } else { // get the center points PointF centerPointLeft = this.GetLeftCenterCoord(varArray, xyCompInPlotCoords, false); PointF centerPointRight = this.GetRightCenterCoord(varArray, xyCompInPlotCoords, false); // convert them to screen coords int leftCenterPointInScreenCoords_X = (int)(centerPointLeft.X * stateMachine.IsoPlotPointsPerAppUnit); int leftCenterPointInScreenCoords_Y = (int)(centerPointLeft.Y * stateMachine.IsoPlotPointsPerAppUnit); int rightCenterPointInScreenCoords_X = (int)(centerPointRight.X * stateMachine.IsoPlotPointsPerAppUnit); int rightCenterPointInScreenCoords_Y = (int)(centerPointRight.Y * stateMachine.IsoPlotPointsPerAppUnit); // now calc the effective draw points int effectiveLeftCenterPoint_X = x1 + leftCenterPointInScreenCoords_X; int effectiveLeftCenterPoint_Y = y1 + leftCenterPointInScreenCoords_Y; int effectiveRightCenterPoint_X = x1 + rightCenterPointInScreenCoords_X; int effectiveRightCenterPoint_Y = y1 + rightCenterPointInScreenCoords_Y; // adjust the line height for the XY comp, the width was compensated earlier int lineHeightInScreenCoordsXYCompensated = lineHeightInScreenCoords + (xyComp); // dark polarity builderID = isoPlotBuilder.DrawGSLineOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, effectiveLeftCenterPoint_X, effectiveLeftCenterPoint_Y, effectiveRightCenterPoint_X, effectiveRightCenterPoint_Y, lineHeightInScreenCoordsXYCompensated, stateMachine.BackgroundFillModeAccordingToPolarity); return(builderID); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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; if (isoPlotBuilder == null) { return(-1); } if (stateMachine == null) { return(-1); } if (macroBuilderIDs == null) { return(-1); } // get the VertexPointArray converted and rotated PointF[] tmpPointArray = GetPointArrayAsPointFArray(varArray); // collect the vertexPoints we operate on here PointF[] vertexPoints = new PointF[vertexPointArray.Length]; // loop through the tmpPointArray for (int i = 0; i < tmpPointArray.Length; i++) { //DebugMessage("rawPoint=" + tmpPointArray[i].ToString()); // we will need them as screen coords float primPointInScreenCoords_X = tmpPointArray[i].X * stateMachine.IsoPlotPointsPerAppUnit; float primPointInScreenCoords_Y = tmpPointArray[i].Y * stateMachine.IsoPlotPointsPerAppUnit; // we can calc the effective draw point of the current primitive, we do it out here to make this obvious float effectiveDrawPoint_X = x1 + primPointInScreenCoords_X; float effectiveDrawPoint_Y = y1 + primPointInScreenCoords_Y; // create a new point and stuff it in the array vertexPoints[i] = new PointF(effectiveDrawPoint_X, effectiveDrawPoint_Y); //DebugMessage(" vertexPoint=" + vertexPoints[i].ToString()); } if (GetApertureIsOn(varArray) == true) { // draw the circle builderID = isoPlotBuilder.DrawGSOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_NORMALEDGE, vertexPoints, 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 builderID = isoPlotBuilder.DrawGSOutLine(IsoPlotUsageTagFlagEnum.IsoPlotUsageTagFlag_INVERTEDGE, vertexPoints, 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 // 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; // get the bounding box of this primitive RectangleF primBoundingBox = GetMacroPrimitiveBoundingBox(varArray); // convert to screen values, this is still the primitive bounding rect though RectangleF primBoundingBoxInScreenCoords = MiscGraphicsUtils.ConvertRectFToScreenCoordinates(primBoundingBox, stateMachine); // the bounding box is relative to the center coords we adjust to absolute int newX0 = (int)(effectiveCenter_X - (primBoundingBoxInScreenCoords.Width / 2)); int newY0 = (int)(effectiveCenter_Y - (primBoundingBoxInScreenCoords.Height / 2)); int newX1 = (int)(newX0 + primBoundingBoxInScreenCoords.Width); int newY1 = (int)(newY0 + primBoundingBoxInScreenCoords.Height); // 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); } }