Sorting of Step and Repeat

Hello Everyone,

Some customers are using IPC norm in their companies and need the same PCB order on each panel.
For such sortings we have created an sorter depending on the bounds of each step, this sorter starts in the right down corner of the panel and add the single PCBs in order from right to left and from bottom to top.

Here is the sorter, this one is working for Lists of single PCBs:

#region SRSorter
internal class MySRSorter : IComparer
{
internal MySRSorter()
{
}
public int Compare(IStep.StepAndRepeatClass y, IStep.StepAndRepeatClass x)
{
RectangleD rectX = new RectangleD(0, 0, x.DX, x.DY);
if (x.ANGLE != 0) rectX = IMath.RotateRectangleAndWiden(rectX, -x.ANGLE);
RectangleD rectY = new RectangleD(0, 0, y.DX, y.DY);
if (y.ANGLE != 0) rectY = IMath.RotateRectangleAndWiden(rectY, -y.ANGLE);

if (x.MIRRORX) rectX = new RectangleD(-rectX.X, rectX.Y, rectX.Width, rectX.Height);
if (y.MIRRORX) rectY = new RectangleD(-rectY.X, rectY.Y, rectY.Width, rectY.Height);

rectX.X += x.X;
rectX.Y += x.Y;
rectY.X += y.X;
rectY.Y += y.Y;

if (rectX.Left > rectY.Right)//left
{
if (rectX.Bottom < rectY.Top) //left up
return 1;
else if (rectX.Top > rectY.Bottom) //left down
return -1;
else
return 1;
}
else if (rectX.Right < rectY.Left) //right
{
if (rectX.Bottom < rectY.Top) //right top
return 1;
else if (rectX.Top > rectY.Bottom) //right down
return -1;
else
return -1;
}
//same hight level

if (rectX.Bottom < rectY.Top) // top
return 1;
else if (rectX.Top > rectY.Bottom) // bottom
return -1;
else
{
if (rectX.X < rectY.X)
{
return -1;
}
else if (rectX.X > rectY.X)
return 1;

return 0;
}
}
}
#endregion

Forums: 

In many cases it is easier to use only one point to compare, this method works fine if the outlines are overlapping and the center is on straite lines:

public int Compare(IStep.StepAndRepeatClass y, IStep.StepAndRepeatClass x)
{
RectangleD rectX = new RectangleD(0, 0, x.DX, x.DY);
if (x.ANGLE != 0) rectX = IMath.RotateRectangleAndWiden(rectX, -x.ANGLE);
RectangleD rectY = new RectangleD(0, 0, y.DX, y.DY);
if (y.ANGLE != 0) rectY = IMath.RotateRectangleAndWiden(rectY, -y.ANGLE);

if (x.MIRRORX) rectX = new RectangleD(-rectX.X, rectX.Y, rectX.Width, rectX.Height);
if (y.MIRRORX) rectY = new RectangleD(-rectY.X, rectY.Y, rectY.Width, rectY.Height);

rectX.X += x.X;
rectX.Y += x.Y;
rectY.X += y.X;
rectY.Y += y.Y;

PointD pX = rectX.GetMidPoint();
PointD pY = rectY.GetMidPoint();

if (pX.Y < pY.Y) return 1;
if (pX.Y > pY.Y) return -1;
if (pX.X > pY.X) return 1;
if (pX.X < pY.X) return -1;
return 0;
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.