/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the LR point. Note due to rotations this point may not be /// the actual LR point - you have to check /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public PointF GetLRCoord(GerberMacroVariableArray varArray) { PointF centerPoint = GetCenterPoint(varArray); float workingXCenterCoord = centerPoint.X; float workingYCenterCoord = centerPoint.Y;; float workingDegreesRotation = GetDegreesRotation(varArray); float workingWidth = GetWidth(varArray); float workingHeight = GetLineLength(varArray); // calc this now float xCoord = workingXCenterCoord + (workingWidth / 2); float yCoord = workingYCenterCoord - (workingHeight / 2); // do we have a rotation if (workingDegreesRotation != 0) { PointF pointToRotate = new PointF(xCoord, yCoord); // do the math and return return(MiscGraphicsUtils.RotatePointAboutPointByDegrees(centerPoint, workingDegreesRotation, pointToRotate)); } else { // no just return the existing value return(new PointF(xCoord, yCoord)); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the yCenterCoord. /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float GetYCenterCoord(GerberMacroVariableArray varArray) { if (yCenterCoord == null) { yCenterCoord = new GerberMacroVariable(); } float workingYCenterCoord = yCenterCoord.ProcessVariableStringToFloat(varArray); float workingDegreesRotation = GetDegreesRotation(varArray); // do we have a rotation if (workingDegreesRotation != 0) { // yes, return the converted value if (xCenterCoord == null) { xCenterCoord = new GerberMacroVariable(); } float workingXCenterCoord = xCenterCoord.ProcessVariableStringToFloat(varArray); double angleInRadians = MiscGraphicsUtils.DegreesToRadians(workingDegreesRotation); return((float)((workingYCenterCoord * Math.Cos(angleInRadians)) + workingXCenterCoord * Math.Sin(angleInRadians))); } else { // no just return the eyisting value return(workingYCenterCoord); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the horizontal Right Center point. Note due to rotations this point may not be /// the actual Right Center point (or horizontal) - you have to check /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> /// <param name="xyCompInPlotCoords">the xy compensation in plot coordinates (Gerber not screen coords)</param> /// <param name="wantInverseXYComp">if true we apply the xyComp in inverse</param> public PointF GetRightCenterCoord(GerberMacroVariableArray varArray, float xyCompInPlotCoords, bool wantInverseXYComp) { float workingXCenterCoord = GetXCenterCoord(varArray); float workingYCenterCoord = GetYCenterCoord(varArray); float workingDegreesRotation = GetDegreesRotation(varArray); float workingWidth = GetWidth(varArray); //float workingHeight = GetHeight(varArray); // calc this now float xCoord = 0; if (wantInverseXYComp == true) { xCoord = workingXCenterCoord + (workingWidth / 2) - xyCompInPlotCoords; } else { xCoord = workingXCenterCoord + (workingWidth / 2) + xyCompInPlotCoords; } float yCoord = workingYCenterCoord; // do we have a rotation if (workingDegreesRotation != 0) { PointF pointToRotate = new PointF(xCoord, yCoord); PointF centerPoint = new PointF(workingXCenterCoord, workingYCenterCoord); // do the math and return return(MiscGraphicsUtils.RotatePointAboutPointByDegrees(centerPoint, workingDegreesRotation, pointToRotate)); } else { // no just return the existing value return(new PointF(xCoord, yCoord)); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the width /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float GetWidth(GerberMacroVariableArray varArray) { if (width == null) { width = new GerberMacroVariable(); } return(width.ProcessVariableStringToFloat(varArray)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the degreesRotation in degrees counter clockwise /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float GetDegreesRotation(GerberMacroVariableArray varArray) { if (degreesRotation == null) { degreesRotation = new GerberMacroVariable(); } return(degreesRotation.ProcessVariableStringToFloat(varArray)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the height /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float GetHeight(GerberMacroVariableArray varArray) { if (height == null) { height = new GerberMacroVariable(); } return(height.ProcessVariableStringToFloat(varArray)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the numSides /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float GetNumSides(GerberMacroVariableArray varArray) { if (numSides == null) { numSides = new GerberMacroVariable(); } return(numSides.ProcessVariableStringToFloat(varArray)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the distance from the center to the origin /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float GetCenterDistance(GerberMacroVariableArray varArray) { float xCenter = GetXCenterCoord(varArray); float yCenter = GetYCenterCoord(varArray); // get the distance return(MiscGraphicsUtils.GetDistanceBetweenTwoPoints(new PointF(0, 0), new PointF(xCenter, yCenter))); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the aperture on/off state. This may require using numbered variables /// to resolve this /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public bool GetApertureIsOn(GerberMacroVariableArray varArray) { if (apertureIsOn == null) { apertureIsOn = new GerberMacroVariable(DEFAULT_APERTURE_STATE); } return(Convert.ToBoolean(apertureIsOn.ProcessVariableStringToFloat(varArray))); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the diameter /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float GetDiameter(GerberMacroVariableArray varArray) { if (diameter == null) { diameter = new GerberMacroVariable(); } return(diameter.ProcessVariableStringToFloat(varArray)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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) { // note this type of (pseudo) primitive does not draw. It is essentially a variable assignment. float outVar = VariableOperation.ProcessVariableStringToFloat(varArray); // now we have it, set it varArray[this.VariableNumber] = new GerberMacroVariable(this.VariableNumber, outVar.ToString()); return(0); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// We get a bounding box of the primitive. This is in non-scaled macro coords /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> /// <returns>a rectangle which will bound the primitives drawing</returns> public override RectangleF GetMacroPrimitiveBoundingBox(GerberMacroVariableArray varArray) { PointF ptUR; PointF ptLL; // get the max and min vals GetMaxMinXAndYValuesForPrimitive(varArray, out ptUR, out ptLL); // return the bounding box, note the width and height must always be positive return(new RectangleF(ptLL.X, ptLL.Y, ptUR.X - ptLL.X, ptUR.Y - ptLL.Y)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the center point of the rectangle. /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public PointF GetCenterPoint(GerberMacroVariableArray varArray) { // get the start coords float start_x = GetXStartCoord(varArray); float start_y = GetYStartCoord(varArray); float end_x = GetXEndCoord(varArray); float end_y = GetYEndCoord(varArray); // add them up and divide by two return(new PointF((float)((start_x + end_x) / 2), (float)((start_y + end_y) / 2))); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the pen we use to draw the macro primitive. This depends on the /// aperture on/off state. Remember to dispose of this pen /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public Pen GetDrawPen(GerberFileStateMachine stateMachine, GerberMacroVariableArray varArray, int penWidth) { // gets the draw pen according to the aperture on/off state if (GetApertureIsOn(varArray) == false) { return(new Pen(ApplicationColorManager.DEFAULT_MACRO_TRANSPARENT_COLOR, penWidth)); } else { return(new Pen(stateMachine.GerberForegroundColor, penWidth)); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Calculates the maximum and minimum coords for a primitive. /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> /// <param name="ptLL">lower left point</param> /// <param name="ptUR">upper right point</param> /// <returns>true the coords are set with values, false they are not</returns> public override bool GetMaxMinXAndYValuesForPrimitive(GerberMacroVariableArray varArray, out PointF ptUR, out PointF ptLL) { float radius = GetDiameter(varArray) / 2; float minX = GetXCenterCoord(varArray) - radius; float minY = GetYCenterCoord(varArray) - radius; float maxX = GetXCenterCoord(varArray) + radius; float maxY = GetYCenterCoord(varArray) + radius; ptUR = new PointF(maxX, maxY); ptLL = new PointF(minX, minY); return(true); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// We get a bounding box of the primitive. This is in non-scaled macro coords /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> /// <returns>a rectangle which will bound the primitives drawing</returns> public override RectangleF GetMacroPrimitiveBoundingBox(GerberMacroVariableArray varArray) { float workingDiameter = GetDiameter(varArray); float radius = workingDiameter / 2; float minX = GetXCenterCoord(varArray) - radius; float minY = GetYCenterCoord(varArray) - radius; // return the bounding box, note the width and height must always be positive return(new RectangleF(minX, minY, workingDiameter, workingDiameter)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the brush we use to draw the macro primitive. This depends on the /// aperture on/off state /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public Brush GetDrawBrush(GerberFileStateMachine stateMachine, GerberMacroVariableArray varArray) { // gets the draw brush according to the aperture on/off state if (GetApertureIsOn(varArray) == false) { return(ApplicationColorManager.DEFAULT_MACRO_TRANSPARENT_COLOR_Brush); } else { return(stateMachine.GerberApertureBrush); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets the line length of the rectangle. /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float GetLineLength(GerberMacroVariableArray varArray) { float start_x = GetXStartCoord(varArray); float start_y = GetYStartCoord(varArray); float end_x = GetXEndCoord(varArray); float end_y = GetYEndCoord(varArray); float xLen = end_x - start_x; float yLen = end_y - start_y; // just do the math return((float)Math.Sqrt((xLen * xLen) + (yLen * yLen))); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets a vertexPointArray, as an equivalent array of converted and /// rotated PointFs /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> /// <returns>the vertex point</returns> private PointF[] GetPointArrayAsPointFArray(GerberMacroVariableArray varArray) { PointF[] outArray = new PointF[vertexPointArray.Length]; // loop through the array for (int i = 0; i < vertexPointArray.Length; i++) { // convert and process each one outArray[i] = GetVertexPoint(varArray, i); } // return it return(outArray); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Processes the variable pair into a numeric value. It may need the numbered /// variables to do this /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public PointF ProcessVariablePairToFloat(GerberMacroVariableArray varArray) { if (varArray == null) { return(new PointF(0, 0)); } // these objects know how to translate themselves float xVarlAsFloat = xVar.ProcessVariableStringToFloat(varArray); float yVarlAsFloat = yVar.ProcessVariableStringToFloat(varArray); return(new PointF(xVarlAsFloat, yVarlAsFloat)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Processes the variable string into a numeric value. It may need the numbered /// variables to do this /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public float ProcessVariableStringToFloat(GerberMacroVariableArray varArray) { if (varArray == null) { return(0); } string filledString = VariableString; // sanity checks if (filledString == null) { variableString = DEFAULT_VARIABLE_STRING; } if (filledString == "") { variableString = DEFAULT_VARIABLE_STRING; } // now iteratively replace all of the $vars in the string filledString = FillVariableString(varArray, filledString); // sanity checks if (filledString == null) { variableString = DEFAULT_VARIABLE_STRING; } if (filledString == "") { variableString = DEFAULT_VARIABLE_STRING; } // create a math parser object MathParser parser = new MathParser(); // our parser uses '*' for multiplication filledString = filledString.Replace("x", "*"); filledString = filledString.Replace("X", "*"); // parse it return((float)parser.Parse(filledString)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Calculates the maximum and minimum coords for a primitive. /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> /// <param name="ptLL">lower left point</param> /// <param name="ptUR">upper right point</param> /// <returns>true the coords are set with values, false they are not</returns> public override bool GetMaxMinXAndYValuesForPrimitive(GerberMacroVariableArray varArray, out PointF ptUR, out PointF ptLL) { float minX = float.MaxValue; float minY = float.MaxValue; float maxX = float.MinValue; float maxY = float.MinValue; // 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++) { PointF tmpPT = tmpPointArray[i]; if (minX > tmpPT.X) { minX = tmpPT.X; } if (minY > tmpPT.Y) { minY = tmpPT.Y; } if (maxX < tmpPT.X) { maxX = tmpPT.X; } if (maxY < tmpPT.Y) { maxY = tmpPT.Y; } } // return this ptUR = new PointF(maxX, maxY); ptLL = new PointF(minX, minY); return(true); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets a vertex point from the vertexPointArray, as a converted and /// rotated PointF /// </summary> /// <param name="index">the index into the array</param> /// <param name="varArray">the array to get the numbered variables from</param> /// <returns>the vertex point</returns> private PointF GetVertexPoint(GerberMacroVariableArray varArray, int index) { // get the raw point PointF pointToRotate = vertexPointArray[index].ProcessVariablePairToFloat(varArray); // we willneed the rotation float workingDegreesRotation = GetDegreesRotation(varArray); // do we have a rotation if (workingDegreesRotation != 0) { // yes, return the converted value double angleInRadians = MiscGraphicsUtils.DegreesToRadians(workingDegreesRotation); float newXVal = (float)((pointToRotate.X * Math.Cos(angleInRadians)) - pointToRotate.Y * Math.Sin(angleInRadians)); float newYVal = (float)((pointToRotate.Y * Math.Cos(angleInRadians)) + pointToRotate.X * Math.Sin(angleInRadians)); return(new PointF(newXVal, newYVal)); } else { // no just return the existing value return(pointToRotate); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Fills the variable string by removing all $vars and replacing them with values /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> public string FillVariableString(GerberMacroVariableArray varArray, string stringToFill) { // we do not do this indefinitely for (int iterationCount = 0; iterationCount < GerberMacroVariableArray.MAX_VARIABLE_ITERATION_COUNT; iterationCount++) { // do we need to process further? if (stringToFill.Contains("$") == false) { return(stringToFill); } // yes we do, we could figure out which ones are in there but this is easier for (int index = 0; index < varArray.Count(); index++) { // do the replace for every variable // for example $4 will get replaced with "(<variableString>)" in the stringToFill. If the VariableString also // contains further $vars we will pick them up on the next iteration. We put brackets around them because if there is a // negative value in there our math parser cannot handle "3+-2" but it can handle "3+(-2)" stringToFill = stringToFill.Replace("$" + index.ToString(), "(" + varArray.VariableArray[index].VariableString + ")"); } } // if we get here we did not replace them all throw new Exception("Self referential macro variables found"); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Calculates the maximum and minimum coords for a primitive. /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> /// <param name="ptLL">lower left point</param> /// <param name="ptUR">upper right point</param> /// <returns>true the coords are set with values, false they are not</returns> public override bool GetMaxMinXAndYValuesForPrimitive(GerberMacroVariableArray varArray, out PointF ptUR, out PointF ptLL) { float minX = float.MaxValue; float minY = float.MaxValue; float maxX = float.MinValue; float maxY = float.MinValue; // get our points, note the UR, UL etc are just for notation. // Rotations inherent in the Get.. call can move these around PointF tmpUR = GetURCoord(varArray); PointF tmpUL = GetULCoord(varArray); PointF tmpLR = GetLRCoord(varArray); PointF tmpLL = GetLLCoord(varArray); // minX if (minX > tmpUR.X) { minX = tmpUR.X; } if (minX > tmpUL.X) { minX = tmpUL.X; } if (minX > tmpLR.X) { minX = tmpLR.X; } if (minX > tmpLL.X) { minX = tmpLL.X; } // minY if (minY > tmpUR.Y) { minY = tmpUR.Y; } if (minY > tmpUL.Y) { minY = tmpUL.Y; } if (minY > tmpLR.Y) { minY = tmpLR.Y; } if (minY > tmpLL.Y) { minY = tmpLL.Y; } // maxX if (maxX < tmpUR.X) { maxX = tmpUR.X; } if (maxX < tmpUL.X) { maxX = tmpUL.X; } if (maxX < tmpLR.X) { maxX = tmpLR.X; } if (maxX < tmpLL.X) { maxX = tmpLL.X; } // maxY if (maxY < tmpUR.Y) { maxY = tmpUR.Y; } if (maxY < tmpUL.Y) { maxY = tmpUL.Y; } if (maxY < tmpLR.Y) { maxY = tmpLR.Y; } if (maxY < tmpLL.Y) { maxY = tmpLL.Y; } ptUR = new PointF(maxX, maxY); ptLL = new PointF(minX, minY); return(true); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Calculates the maximum and minimum coords for a primitive. /// </summary> /// <param name="ptLL">lower left point</param> /// <param name="ptUR">upper right point</param> /// <param name="varArray">the array to get the numbered variables from</param> /// <returns>true the coords are set with values, false they are not</returns> public abstract bool GetMaxMinXAndYValuesForPrimitive(GerberMacroVariableArray varArray, out PointF ptUR, out PointF ptLL);
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// We get a bounding box of the primitive. This is in non-scaled macro coords /// </summary> /// <param name="varArray">the array to get the numbered variables from</param> /// <returns>a rectangle which will bound the primitives drawing</returns> public abstract RectangleF GetMacroPrimitiveBoundingBox(GerberMacroVariableArray varArray);
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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="xyComp">the xy compensation factor</param> /// <param name="macroBuilderIDs">a list of builder IDs which have drawn in POSITIVE on this macro</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 abstract int FlashMacroPrimitiveForGCodePlot(GerberMacroVariableArray varArray, List <int> macroBuilderIDs, IsoPlotBuilder isoPlotBuilder, GerberFileStateMachine stateMachine, int x1, int y1, int xyComp);
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// If we fill a shape with the macro at the current coordinates. This /// simulates the aperture flash of a Gerber plotter /// </summary> /// <param name="graphicsObj">a graphics object to draw on</param> /// <param name="workingBrush">a brush to draw with</param> /// <param name="bottomOfGraphicsObjInMacroScreenCoords_X">the macro screen coord which represents the bottom 0 coord of the graphics object</param> /// <param name="bottomOfGraphicsObjInMacroScreenCoords_Y">the macro screen coord which represents the bottom 0 coord of the graphics object</param> /// <param name="varArray">the array to get the numbered variables from</param> /// <returns>z success, nz fail</returns> public abstract void FlashMacroPrimitiveForGerberPlot(GerberFileStateMachine stateMachine, GerberMacroVariableArray varArray, Graphics graphicsObj, Brush workingBrush, float bottomOfGraphicsObjInMacroScreenCoords_X, float bottomOfGraphicsObjInMacroScreenCoords_Y);
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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); } }