Exemplo n.º 1
0
        private Aperture ParseMacro()
        {
            if (data_Macro[0].StartsWith("4"))  // macro outline

            {
                int    i   = 0;
                string str = "";
                // on test en comptant le nombre de virgule
                if (count(',', data_Macro[1]) > 2)
                {
                    MacroOutline macroOutline = new MacroOutline();

                    // il faut ajouter l'angle de rotation de la macro

                    //Console.Write(data_Macro[data_Macro.Count-1].Remove(1));
                    for (int k = 1; k < data_Macro.Count - 1; k++)
                    {
                        foreach (char ch in data_Macro[k])
                        {
                            str += ch;
                            if (ch.Equals(','))
                            {
                                i += 1;
                                if (i % 2 == 0)
                                {
                                    string [] points = str.Split(',');

                                    macroOutline.addPoint(new Point(Convert.ToSingle(points[0].Replace('.', ',')), Convert.ToSingle(points[1].Replace('.', ','))));

                                    str = "";
                                }
                            }
                        }
                    }


                    return(macroOutline);
                }


                else
                {
                    MacroOutline macroOutline = new MacroOutline();
                    for (int k = 1; k < data_Macro.Count - 1; k++)
                    {
                        string[] points = data_Macro[k].Split(',');

                        macroOutline.addPoint(new Point(Convert.ToSingle(points[0].Replace('.', ',')), Convert.ToSingle(points[1].Replace('.', ','))));
                    }
                    return(macroOutline);
                }
            }



            return(macro);
        }
Exemplo n.º 2
0
      public override void render(Graphics g)
      {
          // flash circle

          if (GetAperture() is MyLibGerber.Circle)
          {
              float      diameter  = Math.Max(GetAperture().getDiameter(), 0);
              float      r         = diameter / 2;
              RectangleF rectangle = new RectangleF(getX() - r, getY() - r, diameter, diameter);
              g.FillEllipse(brush, rectangle);
          }
          // flash rectangle
          if (GetAperture() is MyLibGerber.Rectangle)
          {
              Rectangle  aperRect  = (Rectangle)GetAperture();
              float      width     = Math.Max(aperRect.getDimension()[0], 0);
              float      height    = Math.Max(aperRect.getDimension()[1], 0);
              RectangleF rectangle = new RectangleF(getX() - aperRect.getDimension()[0] / 2, getY() - aperRect.getDimension()[1] / 2, width, height);

              g.FillRectangle(brush, rectangle);
          }

          // flash Polygon

          if (GetAperture() is MyLibGerber.Polygon)
          {
              Polygon polygon = (Polygon)GetAperture();

              int   vertices = polygon.Vertice;
              float diameter = polygon.getDiameter() / 2;

              PointF[] pointFs      = new PointF[vertices];
              float    angle_depart = (float)(Math.PI / 2.0 - Math.PI / vertices);
              float    angle_cote   = (float)(2.0 * Math.PI / vertices);

              for (int i = 0; i < vertices; i++)
              {
                  float  x      = (float)(diameter * Math.Cos(angle_depart + i * angle_cote) + getX());
                  float  y      = (float)(diameter * Math.Sin(angle_depart + i * angle_cote) + getY());
                  PointF pointF = new PointF(x, y);
                  pointFs.SetValue(pointF, i);
              }

              g.FillPolygon(brush, pointFs);
          }

          // flash Obround
          if (GetAperture() is MyLibGerber.Obround)
          {
              Obround    obround    = (Obround)GetAperture();
              float      width      = Math.Max(obround.getDimension()[0], 0);
              float      height     = Math.Max(obround.getDimension()[1], 0);
              RectangleF rectangleF = new RectangleF(getX() - obround.getDimension()[0] / 2, getY() - obround.getDimension()[1] / 2, width, height);


              //System.Drawing.Rectangle round = new System.Drawing.Rectangle(rectangleF);

              //this.DrawRoundedRectangle(g, rectangleF,5, brush);
              g.FillRectangle(brush, rectangleF);
          }

          // Macro start
          if (GetAperture() is MyLibGerber.MacroOutline)
          {
              MacroOutline outline = (MacroOutline)GetAperture();
              int          size    = outline.getPoints().Count;
              PointF[]     pointFs = new PointF[size];

              float x, y;
              for (int i = 0; i < size; i++)
              {
                  x = outline.getPoints()[i].getX() + getX();
                  y = outline.getPoints()[i].getY() + getY();
                  PointF pointF = new PointF(x, y);
                  pointFs.SetValue(pointF, i);
              }

              g.FillPolygon(brush, pointFs);
          }
      }  // end render