/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Flash an aperture 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="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) { List <int> macroBuilderIDs = new List <int>(); if (isoPlotBuilder == null) { return; } if (stateMachine == null) { return; } // get the macro AM code object for this aperture GerberLine_AMCode workingMacro = GetMacroObject(stateMachine); if (workingMacro == null) { throw new Exception("No macro definition found for name " + MacroName); } //// we run through our primitive list in order and and draw for GCode foreach (GerberMacroPrimitive_Base primObj in workingMacro.MacroPrimitives) { int builderID = primObj.FlashMacroPrimitiveForGCodePlot(this.VariableArray, macroBuilderIDs, isoPlotBuilder, stateMachine, x1, y1, xyComp); if (builderID <= 0) { continue; } macroBuilderIDs.Add(builderID); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// If we fill a shape with the aperture 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="x1">the x center value</param> /// <param name="y1">the y center value</param> /// <returns>z success, nz fail</returns> public override void FlashApertureForGerberPlot(GerberFileStateMachine stateMachine, Graphics graphicsObj, Brush workingBrush, float x1, float y1) { if (graphicsObj == null) { return; } if (workingBrush == null) { return; } if (stateMachine == null) { return; } // get the macro AM code object for this aperture GerberLine_AMCode workingMacro = GetMacroObject(stateMachine); if (workingMacro == null) { throw new Exception("No macro definition found for name " + MacroName); } // get the largest bounding box for all primitives in the macro RectangleF boundingRectF = workingMacro.GetMacroPrimitivesBoundingBox(VariableArray); // note the bottom of this box is not the (0,0) point of any one primitive. It is also not // the (0,0) point of the macro. // convert to screen values, this is still the macro bounding rect though RectangleF boundingRectFInScreenCoord = MiscGraphicsUtils.ConvertRectFToScreenCoordinates(boundingRectF, stateMachine); // set up to create a bitmap we draw our primitives on, we convert our floats to int // the +1 here is to ensure we round up. The bounding box can be bigger, but smaller is bad // we can assume the width and height here are positive. This should have been checked much earlier int boundingWidth = (int)(boundingRectFInScreenCoord.Width) + 1; int boundingHeight = (int)(boundingRectFInScreenCoord.Height) + 1; // create an appropriately sized bitmap Bitmap macroBitmap = new Bitmap(boundingWidth, boundingHeight); // get a graphics object from the bitmap. We use this to draw the macro Graphics macroGraphicsObj = Graphics.FromImage(macroBitmap); // fill the rectangle with a background color not normally used on Gerber plots macroGraphicsObj.FillRectangle(new SolidBrush(ApplicationColorManager.DEFAULT_MACRO_TRANSPARENT_COLOR), 0, 0, boundingWidth, boundingHeight); // for diagnostics //DebugTODO("remove this"); //macroGraphicsObj.DrawEllipse(Pens.Maroon, 0, 0, 25, 25); //// we run through our primitive list in order and and flash foreach (GerberMacroPrimitive_Base primObj in workingMacro.MacroPrimitives) { primObj.FlashMacroPrimitiveForGerberPlot(stateMachine, VariableArray, macroGraphicsObj, workingBrush, boundingRectFInScreenCoord.X, boundingRectFInScreenCoord.Y); } // now we place the newly drawn macroBitmap on the screen, first create an int based rectangle // which describes the screen location in Gerber coord onto which we place the macro bitmap // x1 and y1 are already converted to Gerber coords and are the effective (0,0) point of the macro // however they are not the (0,0) ppoint of the place we draw. The aperture origin does not have to // be in the macro Bitmap // we make this obvious int effectiveDrawPoint_X0 = (int)(x1 + boundingRectFInScreenCoord.X); int effectiveDrawPoint_Y0 = (int)(y1 + boundingRectFInScreenCoord.Y); int effectiveWidth = boundingWidth; // this does not change int effectiveHeight = boundingHeight; // this does not change // create a defining rectangle Rectangle boundingRect = new Rectangle((int)effectiveDrawPoint_X0, effectiveDrawPoint_Y0, effectiveWidth, effectiveHeight); // make the parts that did not get a macro primitive drawn on them transparent macroBitmap.MakeTransparent(ApplicationColorManager.DEFAULT_MACRO_TRANSPARENT_COLOR); // overlay the macro bitmap on our main gerber display graphicsObj.DrawImage(macroBitmap, boundingRect); return; }