private void writeSVG(Results_implant currentResult, int resultEntry, int numberOfCases)
    {
        string svgFileName = baseFileName;

        string paddingString = "D" + numberOfCases.ToString().Length; // count chars in the number of cases as a string, use that to define padding.

        svgFileName += "_run" + resultEntry.ToString(paddingString) + ".svg";

        SVGBuilder svg = new()
        {
            style =
            {
                brushClr = currentResult.getResistShapes()[0].getColor(),
                penClr   = currentResult.getResistShapes()[0].getColor()
            }
        };

        // Active resist contour
        svg.AddPolygons(currentResult.getResistShapes()[0].getPoints());

        // Background resist contour
        svg.style.brushClr = currentResult.getResistShapes()[1].getColor();
        svg.style.penClr   = currentResult.getResistShapes()[1].getColor();
        svg.AddPolygons(currentResult.getResistShapes()[1].getPoints());

        // Shadow
        svg.style.brushClr = currentResult.getLine(Results_implant.lines.shadow).getColor();
        svg.style.penClr   = currentResult.getLine(Results_implant.lines.shadow).getColor();
        svg.AddPolygons(currentResult.getLine(Results_implant.lines.shadow).getPoints());

        svg.SaveToFile(svgFileName);
    }
    private void writeLayout_implant(Results_implant currentResult, int resultEntry, int numberOfCases, int type)
    {
        string layoutFileName = baseFileName;

        string paddingString = "D" + numberOfCases.ToString().Length; // count chars in the number of cases as a string, use that to define padding.

        layoutFileName += "_run" + resultEntry.ToString(paddingString);

        int     scale = 100; // for 0.01 nm resolution
        GeoCore g     = new();

        g.reset();
        GCDrawingfield drawing_ = new("")
        {
            accyear       = (short)DateTime.Now.Year,
            accmonth      = (short)DateTime.Now.Month,
            accday        = (short)DateTime.Now.Day,
            acchour       = (short)DateTime.Now.Hour,
            accmin        = (short)DateTime.Now.Minute,
            accsec        = (short)DateTime.Now.Second,
            modyear       = (short)DateTime.Now.Year,
            modmonth      = (short)DateTime.Now.Month,
            modday        = (short)DateTime.Now.Day,
            modhour       = (short)DateTime.Now.Hour,
            modmin        = (short)DateTime.Now.Minute,
            modsec        = (short)DateTime.Now.Second,
            databaseunits = 1000 * scale,
            userunits     = 0.001 / scale,
            libname       = "variance"
        };

        GCCell gcell_root = drawing_.addCell();

        gcell_root.accyear  = (short)DateTime.Now.Year;
        gcell_root.accmonth = (short)DateTime.Now.Month;
        gcell_root.accday   = (short)DateTime.Now.Day;
        gcell_root.acchour  = (short)DateTime.Now.Hour;
        gcell_root.accmin   = (short)DateTime.Now.Minute;
        gcell_root.accsec   = (short)DateTime.Now.Second;
        gcell_root.modyear  = (short)DateTime.Now.Year;
        gcell_root.modmonth = (short)DateTime.Now.Month;
        gcell_root.modday   = (short)DateTime.Now.Day;
        gcell_root.modhour  = (short)DateTime.Now.Hour;
        gcell_root.modmin   = (short)DateTime.Now.Minute;
        gcell_root.modsec   = (short)DateTime.Now.Second;
        gcell_root.cellName = "implantCase" + resultEntry;

        // Resist
        for (int i = 0; i < 2; i++)
        {
            List <GeoLibPointF[]> resistPolys = currentResult.getResistShapes()[i].getPoints();
            g.addLayerName("L" + (i + 1) + "D0", "resistPolys" + i);

            foreach (GeoLibPoint[] ePoly in resistPolys.Select(t => GeoWrangler.resize_to_int(t, scale)))
            {
                gcell_root.addPolygon(ePoly.ToArray(), i + 1, 0);
            }
        }

        // Shadowing line
        List <GeoLibPointF[]> shadowLine = currentResult.getLine(Results_implant.lines.shadow).getPoints();

        g.addLayerName("L2D0", "shadowLine");
        foreach (GeoLibPoint[] ePoly in shadowLine.Select(t => GeoWrangler.resize_to_int(t, scale)))
        {
            gcell_root.addPolygon(ePoly.ToArray(), 2, 0);
        }

        g.setDrawing(drawing_);
        g.setValid(true);

        switch (type)
        {
        case (int)CommonVars.external_Type.gds:
            gdsWriter gw = new(g, layoutFileName + ".gds");
            gw.save();
            break;

        case (int)CommonVars.external_Type.oas:
            oasWriter ow = new(g, layoutFileName + ".oas");
            ow.save();
            break;
        }
    }