#usage "Copies the Placement from parts to other parts

\n" "Author: Oliver Saal http://www.oliver-saal.de/" #include "oslib.inc" string cmd, c; int i; // reference elements // STRUCT { numeric string eleRef[]; // name of reference element numeric string elePlace[]; // name of element to copy the placement string pac[]; // package int ref_x[], ref_y[], ref_angle[], ref_mirror[]; // Position of reference element //int old_x[], old_y[], old_angle[], old_mirror[]; // Old position of the copy element // } int iCount=0; // count of elements string strRefElements; string strRectCopyElements; // Elements that are in rectangles for copy placement int iAutoSelection=1; // 0=No auto selection int iPlaceSelection=1; // 0=All 1=neg. coordinates 2=rect int iOnlyGreaterNumber=1; int iOnlySamePackage=1; int iOnlyLastDigit=0; int iLastDigits=1; // 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 reference elements, selection-index for combo-box int iLayerCopy=5, iLayerCopySel=0; // Layer with rectangles for copy elements, selection-index for combo-box int iPlacement=2; // 0=Left 1=Top 2=Right 3=Bottom numeric string lines[]; // lines for listview string str; int iRefCount=0, iPlaceCount=0; int n=0, iLineCount=0, iListSel=0, iSelFrom=-1, iSelTo=-1, iUnit, iRectCount=0, iDiffX=0, iDiffY=0; string strOffsetX, strOffsetY; int iResult; numeric string eleCopyCandidates[]; int iCandidatesCount=0; void UpdateCopyRectElements() { iLayerCopy = layer_number[iLayerCopySel]; strRectCopyElements = ElementsInRectangle (iLayerCopy); } void RebuildListLine (int iLine) { lines[iLine] = eleRef[iLine] + "\t" + elePlace[iLine]; } int isCopyElement(string name, int idx) { int i; for (i=0; i= 0 && e.y >= 0) return; if (iPlaceSelection == 2 && strstr (strRectCopyElements, " " + e.name + " ") < 0) return; if (iOnlyLastDigit && strsub(e.name, strlen(e.name)-iLastDigits, iLastDigits) != strsub (eleRef[eleRefIdx], strlen(eleRef[eleRefIdx])-iLastDigits, iLastDigits)) return; eleCopyCandidates[iCandidatesCount] = e.name; iCandidatesCount++; } void ClearCandidates () { for (int i=0; iERROR: 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 || L.number == iLayerCopy) { if (L.number == iLayerRef) iLayerRefSel = iLayerCount; if (L.number == iLayerCopy) iLayerCopySel = iLayerCount; layer_number[iLayerCount] = L.number; sprintf (layer_name[iLayerCount++], "%d - %s", L.number, L.name); } } } /////////////////////////////////////////// // First Dialog /////////////////////////////////////////// iResult = dlgDialog("Copy placement (Step 1 of 2)") { dlgGroup("Reference Elements") { dlgLabel("Rectangles which contains the reference elements are on Layer:"); dlgComboBox (layer_name, iLayerRefSel); } dlgGroup("Candidate preselection for copied placement") { dlgCheckBox ("Run auto selection", iAutoSelection); dlgLabel("


"); dlgRadioButton("All elements", iPlaceSelection); dlgRadioButton("Only elements with negative coordinates", iPlaceSelection); dlgHBoxLayout { dlgRadioButton("Only elements in rectangles on layer", iPlaceSelection); dlgComboBox (layer_name, iLayerCopySel); } dlgCheckBox ("Only elements with greater number", iOnlyGreaterNumber); dlgCheckBox ("Only elements with same package", iOnlySamePackage); dlgHBoxLayout { dlgCheckBox ("Only elements with the same ", iOnlyLastDigit); dlgSpinBox(iLastDigits, 1, 5); dlgLabel (" last digits."); dlgStretch(1); } } dlgHBoxLayout { dlgStretch(1); dlgPushButton("+Next >>") dlgAccept(); dlgPushButton("-Cancel") dlgReject(); } }; if (iResult == 0) exit(0); iLayerRef = layer_number[iLayerRefSel]; UpdateCopyRectElements(); /////////////////////////////////////////// // Find reference Elements // (inside rectangles on layer 49) /////////////////////////////////////////// board(B) { B.rectangles(R) { if (R.layer == iLayerRef) { B.elements(E) { if (isElementInRectangle(E, R)) { ref_x[iRefCount] = E.x; ref_y[iRefCount] = E.y; ref_angle[iRefCount] = E.angle; ref_mirror[iRefCount] = E.mirror; eleRef[iRefCount] = E.name; pac[iRefCount] = E.package.name; RebuildListLine(iRefCount); iRefCount++; } } iRectCount++; if (R.x2 - R.x1 > iDiffX) iDiffX = R.x2 - R.x1; if (R.y2 - R.y1 > iDiffY) iDiffY = R.y2 - R.y1; } } strRefElements = " " + strjoin (eleRef, ' ') + " "; } 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 (iRefCount == 0) { dlgMessageBox ("Error! No elements found!

There are no reference elements inside the rectangle(s) on layer '" + layer_name[iLayerRefSel] + "'."); exit(2); } AutoSelection(); /////////////////////////////////////////// // Second Dialog /////////////////////////////////////////// iResult = dlgDialog ("Copy 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 { dlgStringEdit(strOffsetX); dlgStretch(1); } dlgCell(2, 0) dlgLabel("Y:"); dlgCell(2, 1) dlgHBoxLayout { dlgStringEdit(strOffsetY); dlgStretch(1); } } } */ dlgGroup("Placement") { dlgGridLayout { dlgCell (1,0) dlgRadioButton("Left", iPlacement); dlgCell (0,1) dlgRadioButton("Top", iPlacement); dlgCell (1,2) dlgRadioButton("Right", iPlacement); dlgCell (2,1) dlgRadioButton("Bottom", iPlacement); } } dlgGroup("Elements") { dlgLabel ("Double click on an item to change the copyied element.\nUse the options above preselect the candidates."); dlgListView("Reference Placement\tCopy to", lines, iListSel) EditPlacement(); } dlgGroup("Candidate preselection") { dlgRadioButton("All elements", iPlaceSelection); dlgRadioButton("Only elements with negative coordinates", iPlaceSelection); dlgHBoxLayout { dlgRadioButton("Only elements in rectangles on layer", iPlaceSelection); dlgComboBox (layer_name, iLayerCopySel) UpdateCopyRectElements(); } dlgCheckBox ("Only elements with greater number", iOnlyGreaterNumber); dlgCheckBox ("Only elements with same package", iOnlySamePackage); dlgHBoxLayout { dlgCheckBox ("Only elements with the same ", iOnlyLastDigit); dlgSpinBox(iLastDigits, 0, 5); dlgLabel (" last digits."); dlgStretch(1); } } dlgSpacing(10); dlgHBoxLayout { dlgStretch(1); dlgPushButton("Start") dlgAccept(); dlgPushButton("Cancel") dlgReject(); dlgStretch(1); } }; if (iResult == 0) exit(0); int dX=0, dY=0; if (iPlacement == 0) { dX = -iDiffX; dY = 0; } else if (iPlacement == 1) { dX = 0; dY = iDiffY; } else if (iPlacement == 2) { dX = iDiffX; dY = 0; } else if (iPlacement == 3) { dX = 0; dY = -iDiffY; } /* /////////////////////////////////////////// // Copy old places, layers to the arrays /////////////////////////////////////////// board(B) { B.elements(E) { for (i=0; i