/* Title : MOVEBY.ulp Purpose : Moves group by displacement. Author : Cameron Nicks License : Creative Commons Attribution-ShareAlike 4.0 International : CC BY-SA 4.0 : https://creativecommons.org/licenses/by-sa/4.0/ ******************************************************************************* * Copyright (c) 2017 Cameron Nicks * ******************************************************************************* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Version: 1.0 02/09/18 - Fixed copy mode grid rounding issue. - Added debug mode flag 0.9 06/30/17 - Added copy mode. Makes a copy of group displaced by move amounts. CN Bug: If copy then undo, must regroup again. Distances don't get updated for some reason. 0.81 06/01/17 - Swapped out license block for Creative Commons. - Restructured revision and feature list. - Added context install routines from Rachael Peterson. Thanks :) [X] - Store last used values as default. Use cfgset() and cfgget() to save and load from eagerc.usr 0.8 05/12/17 - Basic operation. Enter values to move by. BUGS: To-Do Feature List: [ ] - Add absolute for objects (single, multi?). Force all x or y coordinates to a certain value. [ ] - Add reference location (used for relative) [ ] - Add relative move from mark and move to absolute point. [ ] - Add copy amount for step and repeat [ ] - Add independent last used values support for each editor. [ ] - Undo argument (inverts previously used values, --u argument) [ ] - Add apply button to make move and recall ulp. [ ] - Filter out any objects that are locked. That way copying a group with lock parts will not throw a backannotation error. [ ] - Change input boxes to drop down lists to see last x settings used [ ] - Add command line argument handling. Only open dialog if no arguments present. (RUN MOVEBY x y)(see CFGTOGGLE) [ ] - Rotate option (scale too, see rotate-scale.ulp) [ ] - Repeat mode: Repeats the last move amounts without the dialog popping up. [ ] - Get and display units, use list box to override. (can already enter units in any unit) [ ]? - Box to enter single components? Context menu? Absolute option for single element move to? [ ]? - Handle MARK as the reference origin. Move distance from Mark. How would this handle groups? Single elements only? (where you want the offset should start from, would be handy in library creation from datasheet dimensions) [ ]x - INPUT CHANGE: Increment mode. Numbers entered multiplied by the grid step. With a 0.1mm grid size, 5 entered as the move by value would move 0.5mm. This could also be used combined with previosly used value and repeat mode to make move by step shortcuts on the arrow keys. */ int debug = 0; #usage "en: Move group by x,y displacement. Define a group, enter values, enter.

" "Moves the group by the amounts entered. Unit is optional.\n" "Make copy checkbox makes a copy at the sistances entered.\n" "run MOVEBY --install - Installs the utility to the board context menus.\n" "run MOVEBY --version - Shows the version number of the ULP being called.\n" "run MOVEBY --locate-ulp - Shows the location of the ULP being called (Useful for debug).\n" "Author: Cameron.Nicks+Layout@gmail.com" "Author: cnicks@phaseivengr.com" // Input box Defaults // Load last used values string xVal = cfgget("moveby.value.x", "0"); string yVal = cfgget("moveby.value.y", "0"); string copy = cfgget("moveby.mode.copy" "0"); string VERSION = "1.0 (09-Feb-2018)"; if (argv[1] == "--install") { exit("edit .brd; set context element 'Move By...' 'run MOVEBY';"); //'run MOVEBY --context' // TO-DO: Add schematic context: BUG Reported: https://goo.gl/vA6Mfq }else if (argv[1] == "--version"){ string tmp = "ULP Version: " + VERSION; dlgMessageBox(tmp); exit(0); } else if (argv[1] == "--locate-ulp"){ dlgMessageBox(argv[0]); exit(0); } else { // Define variables string cmd=""; int result; int mode = strtol(cfgget("moveby.mode.copy")); int Result = dlgDialog("Move By Displacement") { dlgHBoxLayout { dlgStretch(1); dlgLabel("Move Group By..."); dlgStretch(1); } dlgHBoxLayout { dlgLabel("X:"); dlgStringEdit(xVal); dlgLabel("Y:"); dlgStringEdit(yVal); } dlgHBoxLayout { dlgCheckBox("&Make Copy", mode); } dlgHBoxLayout { // dlgStretch(1); dlgPushButton("+OK") dlgAccept(); dlgPushButton("-Cancel") dlgReject(); // Without the -, escape key acted like ok } }; if (Result == 0) exit (0); if (Result) { // Save last used values to eaglerc.usr string cfg = ""; string amt = ""; cfgset("moveby.value.x", xVal); cfgset("moveby.value.y", yVal); //int settings need to be converted to string to store with cfgset sprintf(cfg, "%d", mode); cfgset("moveby.mode.copy", cfg); //Output Commands if (mode == 0){ cmd += "MOVE"; } else if (mode == 1) { cmd += "COPY"; } sprintf(amt, " (>0 0) (%s %s);\n", xVal, yVal); cmd += amt; if (debug) {dlgMessageBox(cmd);}//Debug // Output command to editor exit(cmd); } // else {exit(0)} }