#usage "Extracts the placement from parts to a script

\n" "Author: Oliver Saal http://www.oliver-saal.de/" #include "oslib.inc" string cmd, c; int i; // elements // STRUCT { numeric string element[]; // name of reference element int extract[]; // extract, 0=No, 1=Yes int ref_x[], ref_y[], ref_angle[], ref_mirror[]; // Position of element // } int iCount=0; // count of elements string strRefElements; string strRectCopyElements; // Elements that are in rectangles for copy placement // STRUCT { numeric string layer_name[]; // layer name int layer_number[]; // layer number // } int iLayerCount=0; // layer count int iLayerRef=49, iLayerRefSel=0; // Layer with rectangles for elements, selection-index for combo-box numeric string lines[]; // lines for listview string str; int n=0, iLineCount=0, iListSel=0, iSelFrom=-1, iSelTo=-1, iUnit, iRectCount=0, iDiffX=0, iDiffY=0; int iMinX, iMinY; int iResult; numeric string eleCopyCandidates[]; int iCandidatesCount=0; void RebuildListLine (int iLine) { lines[iLine] = element[iLine] + "\t"; if (extract[iLine]) lines[iLine] += "Yes"; else lines[iLine] += "No"; } void SwitchExtract() { extract[iListSel] = !extract[iListSel]; RebuildListLine (iListSel); } //////////////////////////////////////////////////////////////////////////////////////////////////// /// START //////////////////////////////////////////////////////////////////////////////////////////////////// if (!board) { dlgMessageBox(usage + "


ERROR: No board!

\nThis program can only work in the board editor."); exit(1); } /////////////////////////////////////////// // Create layer list /////////////////////////////////////////// board(B) { B.layers(L) { if (L.used || L.number == iLayerRef) { if (L.number == iLayerRef) iLayerRefSel = iLayerCount; layer_number[iLayerCount] = L.number; sprintf (layer_name[iLayerCount++], "%d - %s", L.number, L.name); } } } /////////////////////////////////////////// // First Dialog /////////////////////////////////////////// iResult = dlgDialog("Extract placement (Step 1 of 2)") { dlgGroup("Elements to extract") { dlgLabel("Rectangles which contains the elements to extract are on Layer:"); dlgComboBox (layer_name, iLayerRefSel); } dlgHBoxLayout { dlgStretch(1); dlgPushButton("+Next >>") dlgAccept(); dlgPushButton("-Cancel") dlgReject(); } }; if (iResult == 0) exit(0); iLayerRef = layer_number[iLayerRefSel]; /////////////////////////////////////////// // Find reference Elements // (inside rectangles on layer 49) /////////////////////////////////////////// board(B) { B.rectangles(R) { if (R.layer == iLayerRef) { B.elements(E) { if (isElementInRectangle(E, R)) { extract[iCount] = 1; ref_x[iCount] = E.x; ref_y[iCount] = E.y; ref_angle[iCount] = E.angle; ref_mirror[iCount] = E.mirror; element[iCount] = E.name; RebuildListLine(iCount); iCount++; if (iCount == 1 || E.x < iMinX) iMinX = E.x; if (iCount == 1 || E.y < iMinY) iMinY = E.x; } } iRectCount++; } } strRefElements = " " + strjoin (element, ' ') + " "; } if (iRectCount == 0) { dlgMessageBox ("Error! No reference rectangle found!

You should draw a rectangle (RECT) on layer '" + layer_name[iLayerRefSel] + "' around the elements whitch are the placement reference."); exit(1); } if (iCount == 0) { dlgMessageBox ("Error! No elements found!

There are no reference elements inside the rectangle(s) on layer '" + layer_name[iLayerRefSel] + "'."); exit(2); } /////////////////////////////////////////// // Second Dialog /////////////////////////////////////////// real rOffsetX=u2mil(iMinX), rOffsetY=u2mil(iMinY); iResult = dlgDialog ("Extract placement (Step 2 of 2)") { dlgGroup("Offset") { dlgGridLayout { /* dlgCell(0, 0) dlgHBoxLayout { dlgLabel("Unit:"); dlgSpacing(10); } dlgCell(0, 1) dlgHBoxLayout { dlgRadioButton("&inch", iUnit); dlgRadioButton("&mil", iUnit); dlgRadioButton("&mm", iUnit); dlgRadioButton("&mic", iUnit); dlgStretch(1); } */ dlgCell(1, 0) dlgLabel("X: "); dlgCell(1, 1) dlgHBoxLayout { dlgRealEdit(rOffsetX); dlgLabel(" mil"); dlgStretch(1); } dlgCell(2, 0) dlgLabel("Y: "); dlgCell(2, 1) dlgHBoxLayout { dlgRealEdit(rOffsetY); dlgLabel(" mil"); dlgStretch(1); } } } dlgGroup("Elements") { dlgLabel ("Double click on an item to select/unselect the element."); dlgListView("Element\tExtract Placement", lines, iListSel) SwitchExtract(); } dlgSpacing(10); dlgHBoxLayout { dlgStretch(1); dlgPushButton("Start") dlgAccept(); dlgPushButton("Cancel") dlgReject(); dlgStretch(1); } }; if (iResult == 0) exit(0); //////////////////////////////////////////////////////////////////////////////////////////////////// /// GENERATE SCRIPT //////////////////////////////////////////////////////////////////////////////////////////////////// string strMirror; cmd = "GRID MIL 100 OFF;\n"; for (i=0; i