User Tools

Site Tools


snapping_in_pcb

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
snapping_in_pcb [2017/10/29 17:53]
cparker
snapping_in_pcb [2018/06/02 13:31]
cparker [Details]
Line 16: Line 16:
  
 ===== Proposed System ===== ===== Proposed System =====
 +Presently implemented in the home/​cparker/​snapping_overhaul branch.
 +====Overview====
 +The snapping code is presently located in two places: snap.[c,h] and crosshair.c. snap.[c,h] defines several general types that are used to do the snapping. crosshair.c is where the snapping actually occurs and is where all of the snapping functions are implemented.
 +
 +There are three new types in snap.[c,​h]: ​
 +  * SnapSpecType:​ This type is an index type for things that can be snapped to. 
 +  * SnapListType:​ A list of SnapSpecType objects
 +  * SnapType: The result of a snapping test
 +
 +Snapping occurs by iterating through SnapSpecType objects in a SnapListType. Each SnapSpecType object has a "​search"​ function pointer that calls a function to look for the the object type associated with that particular SnapSpecType. These functions are presently defined in crosshair.c. So, for example, there is a SnapSpecType object associated with pins and pads called pin_pad_snap. It has a function associated with it called snap_to_pins_pads that calls SearchObjectByLocation to look for and pins or pads under the cursor, and decide if there is a valid snapping target. If there is, it passes that back to the calling function (as an object, not a pointer).
 +
 +The crosshair structure has two related fields:
 +  * (SnapType*) (*snap)(SnapListType*,​ Coord, Coord): a function pointer to a function that does the snapping
 +  * (SnapListType*) snaps: a pointer to a list of things to try snapping to.
 +
 +Presently, snapping occurs whenever the crosshair is repositioned using MoveCrosshairAbsolute (crosshair.c). This function calls Crosshair.snap(Crosshair.snaps,​ X, Y). If this returns non-null, we found something to snap to, and we reposition the crosshair to those coordinates.
 +
 +Both of the crosshair items are implemented as pointers so that they can be changed dynamically. You could, for example, change the snap list when you go into line drawing mode so that you don't snap to elements or other lines, or do so in a different order. Similarly, you could change the snapping function to one that snaps based on which item is closest as opposed to which has the highest priority.
 +
 +
 +====Details====
 +
 +===SnapSpecType===
 +This type contains information about snapping to something. They are identified by a name string, however, they are sorted in a ''​SnapListType''​ by priority. There is an enable flag that can be used to turn off the snap, and there is a radius of effect. Finally, there is a function pointer to a function that looks for the subject object type.
 +
 +Presently, there are ''​SnapSpecType''​s defined for:
 +  * grid points ​
 +  * pins and pads
 +  * elements
 +  * vias
 +  * lines
 +  * arcs, and
 +  * polygons
 +
 +These are all defined in crosshair.c,​ although eventually if we're ever successful at migrating to a more object oriented structure, these should be defined in their respective type files.
 +
 +''​SnapSpecTypes''​ can be created using the ''​snap_spec_new''​ function which takes the name and priority of the spec, or by the ''​snap_spec_copy''​ function which takes a pointer to another ''​SnapSpecType''​.
 +
 +===SnapListType===
 +''​SnapListType''​ is a container for organizing ''​SnapSpecTypes''​. It allocates an array of ''​SnapSpecTypes''​ and inserts, removes, or changes the order in that array based on the ''​priority''​ of the ''​SnapSpecType''​. This priority was perhaps a silly way of organizing them since the actual number is irrelevant, however, it does make it fairly easy to change their order, or insert new ones at a given place in the list.
 +
 +===== Related Pages =====
 +  * [[PCB Crosshair|PCB Crosshair]]
  
snapping_in_pcb.txt ยท Last modified: 2019/03/21 12:50 by cparker