pcb 4.1.1
An interactive printed circuit board layout editor.

relocate.c

Go to the documentation of this file.
00001 
00013 #include <stdio.h>
00014 
00015 #include "config.h"
00016 #include "global.h"
00017 #include "data.h"
00018 #include "hid.h"
00019 #include "misc.h"
00020 #include "create.h"
00021 #include "rtree.h"
00022 #include "undo.h"
00023 #include "move.h"
00024 #include "draw.h"
00025 #include "set.h"
00026 
00027 
00028 /* %start-doc actions Relocate
00029 
00030 The @code{Relocate()} action in pcb that will take all selected elements
00031 and stack them up at the current crosshairs.
00032 This works well when starting a new layout and you have hundreds of
00033 parts on your workspace and you're just starting to do your component
00034 placement.
00035 Use Select Element by Name (refdes) to select the elements you want to
00036 move, and then use :Relocate() to set the position of those elements to
00037 where ever your crosshair is.
00038 
00039 TODO: Right now, if multiple elements are selected, they are all are
00040 stacked up on top of each other.
00041 Instead make them spread out the way Disperse Elements does.
00042 
00043 
00044 %end-doc */
00045 static int
00046 relocate (int argc, char **argv, Coord x, Coord y)
00047 {
00048   Coord origin_x;
00049   Coord origin_y;
00050   Coord dx;
00051   Coord dy;
00052 
00053   /* get crosshair location and make this our "origin". */
00054   origin_x = Crosshair.X;
00055   origin_y = Crosshair.Y;
00056 
00057   /* loop over all elements, and move selected elements to crosshair
00058    * location. */
00059   ELEMENT_LOOP (PCB->Data);
00060   {
00061     /* only affect selected elements. */
00062       if (TEST_FLAG (SELECTEDFLAG, element))
00063       {
00064         /* how far does the element need to move? */
00065         dx = origin_x - element->BoundingBox.X1;
00066         dy = origin_y - element->BoundingBox.Y1;
00067 
00068         /* snap to grid. */
00069         dx -= (element->MarkX + dx) % PCB->Grid;
00070         dx += PCB->Grid;
00071         dy -= (element->MarkY + dy) % PCB->Grid;
00072         dy += PCB->Grid;
00073 
00074         /* move the element. */
00075         MoveElementLowLevel (PCB->Data, element, dx, dy);
00076 
00077         /* add to the undo list. */
00078         AddObjectToMoveUndoList (ELEMENT_TYPE, NULL, NULL, element, dx, dy);
00079       }
00080   }
00081   END_LOOP;
00082 
00083   /* done with our action, so increment the undo # .*/
00084   IncrementUndoSerialNumber ();
00085 
00086   Redraw ();
00087   SetChangedFlag (true);
00088 
00089   return 0;
00090 }
00091 
00092 
00093 static HID_Action relocate_action_list[] =
00094 {
00095   { "Relocate", NULL, relocate, NULL, NULL}
00096 };
00097 
00098 REGISTER_ACTIONS(relocate_action_list)
00099 
00100 void hid_relocate_init()
00101 {
00102   register_relocate_action_list();
00103 }