// // snap_plugin.c // // Created by Parker, Charles W. on 2018-06-03. // #include #include "globalconst.h" #include "global.h" // types #include "crosshair.h" #include "snap.h" /* Snap to elements */ static SnapType snap_to_element_centers(Coord x, Coord y, Coord r) { SnapType snap; void *p1, *p2, *p3; snap.valid = false; /* if we're not drawing rats, check for elements first */ if (PCB->RatDraw) return snap; snap.obj_type = SearchObjectByLocation (ELEMENT_TYPE, &p1, &p2, &p3, x, y, r); if (snap.obj_type & ELEMENT_TYPE) { /* if we found an element, check to see if we should snap to it */ ElementType *el = (ElementType *) p1; snap.loc.X = (el->BoundingBox.X1 - el->BoundingBox.X2) / 2; snap.loc.Y = (el->BoundingBox.Y1 - el->BoundingBox.Y2) / 2; snap.distsq = square(snap.loc.X - x) + square(snap.loc.Y - y); snap.valid = true; } return snap; } static SnapSpecType element_center_snap = { "Snap to element centers",// Name &snap_to_element_centers, // Function pointer true, // enabled 15, // priority 1000000, // radius (nm) 0 // object type }; void pcb_plugin_init() { printf("Loading plugin: snap to element centers\n"); snap_list_add_snap(Crosshair.snaps, &element_center_snap); }