pcb 4.1.1
An interactive printed circuit board layout editor.

search.c File Reference

Search routines. More...

#include <math.h>
#include <setjmp.h>
#include "global.h"
#include "box.h"
#include "data.h"
#include "draw.h"
#include "error.h"
#include "find.h"
#include "misc.h"
#include "polygon.h"
#include "rtree.h"
#include "search.h"
Include dependency graph for search.c:

Go to the source code of this file.

Data Structures

struct  ans_info
struct  line_info
struct  arc_info

Functions

static bool SearchLineByLocation (int locked, LayerType **Layer, LineType **Line, LineType **Dummy)
 Searches ordinary line on the SearchLayer.
static bool SearchArcByLocation (int locked, LayerType **Layer, ArcType **Arc, ArcType **Dummy)
 Searches arc on the SearchLayer.
static bool SearchRatLineByLocation (int locked, RatType **Line, RatType **Dummy1, RatType **Dummy2)
 Searches rat lines if they are visible.
static bool SearchTextByLocation (int locked, LayerType **Layer, TextType **Text, TextType **Dummy)
 Searches text on the SearchLayer.
static bool SearchPolygonByLocation (int locked, LayerType **Layer, PolygonType **Polygon, PolygonType **Dummy)
 Searches a polygon on the SearchLayer.
static bool SearchPinByLocation (int locked, ElementType **Element, PinType **Pin, PinType **Dummy)
 Searches a pin.
static bool SearchPadByLocation (int locked, ElementType **Element, PadType **Pad, PadType **Dummy, bool BackToo)
 Searches a pad.
static bool SearchViaByLocation (int locked, PinType **Via, PinType **Dummy1, PinType **Dummy2)
 Searches a via.
static bool SearchElementNameByLocation (int locked, ElementType **Element, TextType **Text, TextType **Dummy, bool BackToo)
 Searches the name of an element.
static bool SearchLinePointByLocation (int locked, LayerType **Layer, LineType **Line, PointType **Point)
 Searches a line-point on all the search layer.
static bool SearchPointByLocation (int locked, LayerType **Layer, PolygonType **Polygon, PointType **Point)
 Searches a polygon-point on all layers that are switched on in layerstack order.
static bool SearchElementByLocation (int locked, ElementType **Element, ElementType **Dummy1, ElementType **Dummy2, bool BackToo)
 Searches an element.
static int pinorvia_callback (const BoxType *box, void *cl)
static int pad_callback (const BoxType *b, void *cl)
static int line_callback (const BoxType *box, void *cl)
static int rat_callback (const BoxType *box, void *cl)
static int arc_callback (const BoxType *box, void *cl)
static int text_callback (const BoxType *box, void *cl)
static int polygon_callback (const BoxType *box, void *cl)
static int linepoint_callback (const BoxType *b, void *cl)
static int arcpoint_callback (const BoxType *b, void *cl)
static bool SearchArcPointByLocation (int locked, LayerType **Layer, ArcType **arc, PointType **Point)
 Searches an arc-point on all the search layer.
static int name_callback (const BoxType *box, void *cl)
static int element_callback (const BoxType *box, void *cl)
bool IsPointOnPin (Coord X, Coord Y, Coord Radius, PinType *pin)
 Checks if a point is on a pin.
bool IsPointOnLineEnd (Coord X, Coord Y, RatType *Line)
 Checks if a rat-line end is on a PV.
bool IsPointOnLine (Coord X, Coord Y, Coord Radius, LineType *Line)
 Checks if a line intersects with a PV.
bool IsLineInRectangle (Coord X1, Coord Y1, Coord X2, Coord Y2, LineType *Line)
 Checks if a line crosses a rectangle.
static int IsPointInQuadrangle (PointType p[4], PointType *l)
 Checks if a point (of null radius) is in a slanted rectangle.
bool IsLineInQuadrangle (PointType p[4], LineType *Line)
 Checks if a line crosses a quadrangle: almost copied from IsLineInRectangle().
bool IsArcInRectangle (Coord X1, Coord Y1, Coord X2, Coord Y2, ArcType *Arc)
 Checks if an arc crosses a square.
bool IsPointInPad (Coord X, Coord Y, Coord Radius, PadType *Pad)
 Check if a circle of Radius with center at (X, Y) intersects a Pad.
bool IsPointInBox (Coord X, Coord Y, BoxType *box, Coord Radius)
 
bool IsPointOnArc (Coord X, Coord Y, Coord Radius, ArcType *Arc)
 
int SearchObjectByLocation (unsigned Type, void **Result1, void **Result2, void **Result3, Coord X, Coord Y, Coord Radius)
 Searches for any kind of object or for a set of object types the calling routine passes two pointers to allocated memory for storing the results.
int SearchObjectByID (DataType *Base, void **Result1, void **Result2, void **Result3, int ID, int type)
 Searches for a object by it's unique ID.
ElementTypeSearchElementByName (DataType *Base, char *Name)
 Searches for an element by its board name.
int SearchLayerByName (DataType *Base, char *Name)
 Searches for an layer by its board name.
int SearchScreen (Coord X, Coord Y, int Type, void **Result1, void **Result2, void **Result3)
 Searches the cursor position for the type.

Variables

static double PosX
static double PosY
static Coord SearchRadius
static BoxType SearchBox
static LayerTypeSearchLayer

Detailed Description

Search routines.

Some of the functions use dummy parameters.


Copyright.


PCB, interactive printed circuit board design

Copyright (C) 1994,1995,1996 Thomas Nau

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Contact addresses for paper mail and Email:

Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany

Thomas.Nau@rz.uni-ulm.de

Definition in file search.c.


Function Documentation

static int arc_callback ( const BoxType box,
void *  cl 
) [static]

Definition at line 340 of file search.c.

References arc_info::Arc, arc_info::Dummy, arc_info::env, IsPointOnArc(), arc_info::locked, PosX, PosY, SearchRadius, and TEST_FLAG.

Referenced by SearchArcByLocation().

Here is the call graph for this function:

static int arcpoint_callback ( const BoxType b,
void *  cl 
) [static]

Definition at line 513 of file search.c.

References arc_info::Arc, Distance(), arc_info::least, arc_info::locked, arc_info::Point, ArcType::Point1, ArcType::Point2, PosX, PosY, TEST_FLAG, PointType::X, and PointType::Y.

Referenced by SearchArcPointByLocation().

Here is the call graph for this function:

static int element_callback ( const BoxType box,
void *  cl 
) [static]
bool IsArcInRectangle ( Coord  X1,
Coord  Y1,
Coord  X2,
Coord  Y2,
ArcType Arc 
)

Checks if an arc crosses a square.

Definition at line 932 of file search.c.

References line, LineArcIntersect(), and NoFlags.

Here is the call graph for this function:

bool IsLineInQuadrangle ( PointType  p[4],
LineType Line 
)

Checks if a line crosses a quadrangle: almost copied from IsLineInRectangle().

Note:
Actually this quadrangle is a slanted rectangle.

Definition at line 891 of file search.c.

References IsPointInQuadrangle(), line, LineLineIntersect(), NoFlags, PointType::X, and PointType::Y.

Referenced by LineLineIntersect().

Here is the call graph for this function:

bool IsLineInRectangle ( Coord  X1,
Coord  Y1,
Coord  X2,
Coord  Y2,
LineType Line 
)

Checks if a line crosses a rectangle.

Definition at line 809 of file search.c.

References line, LineLineIntersect(), and NoFlags.

Referenced by PinLineIntersect().

Here is the call graph for this function:

bool IsPointInBox ( Coord  X,
Coord  Y,
BoxType box,
Coord  Radius 
)

Note:
Assumes box has point1 with numerically lower X and Y coordinates.

Definition at line 1058 of file search.c.

References Distance(), X, BoxType::X1, BoxType::X2, Y, BoxType::Y1, and BoxType::Y2.

Referenced by IsPointOnPin().

Here is the call graph for this function:

bool IsPointInPad ( Coord  X,
Coord  Y,
Coord  Radius,
PadType Pad 
)

Check if a circle of Radius with center at (X, Y) intersects a Pad.

Written to enable arbitrary pad directions; for rounded pads, too.

Definition at line 978 of file search.c.

References Distance(), TEST_FLAG, X, x, and Y.

Referenced by line_callback(), LineArcIntersect(), LineLineIntersect(), pad_callback(), and PinLineIntersect().

Here is the call graph for this function:

static int IsPointInQuadrangle ( PointType  p[4],
PointType l 
) [static]

Checks if a point (of null radius) is in a slanted rectangle.

Definition at line 857 of file search.c.

References PointType::X, x, PointType::Y, and y.

Referenced by IsLineInQuadrangle().

bool IsPointOnArc ( Coord  X,
Coord  Y,
Coord  Radius,
ArcType Arc 
)

Todo:
This code is BROKEN in the case of non-circular arcs, and in the case that the arc thickness is greater than the radius.

Definition at line 1107 of file search.c.

References ArcType::Delta, Distance(), NormalizeAngle(), RAD_TO_DEG, ArcType::StartAngle, ArcType::Thickness, ArcType::Width, ArcType::X, and ArcType::Y.

Referenced by arc_callback(), ArcArcIntersect(), and LineArcIntersect().

Here is the call graph for this function:

bool IsPointOnLine ( Coord  X,
Coord  Y,
Coord  Radius,
LineType Line 
)

Checks if a line intersects with a PV.

 let the point be (X,Y) and the line (X1,Y1)(X2,Y2)
 the length of the line is
   L = ((X2-X1)^2 + (Y2-Y1)^2)^0.5
 let Q be the point of perpendicular projection of (X,Y) onto the line
   QX = X1 + D1*(X2-X1) / L
   QY = Y1 + D1*(Y2-Y1) / L
 with (from vector geometry)
        (Y1-Y)(Y1-Y2)+(X1-X)(X1-X2)
   D1 = ---------------------------
                     L
   D1 < 0   Q is on backward extension of the line
   D1 > L   Q is on forward extension of the line
   else     Q is on the line
 the signed distance from (X,Y) to Q is
        (Y2-Y1)(X-X1)-(X2-X1)(Y-Y1)
   D2 = ----------------------------
                     L
 Finally, D1 and D2 are orthogonal, so we can sum them easily
 by pythagorean theorem.
 

Definition at line 782 of file search.c.

References Distance().

Referenced by InsertPointIntoPolygon(), line_callback(), rat_callback(), and RemoveExcessPolygonPoints().

Here is the call graph for this function:

bool IsPointOnLineEnd ( Coord  X,
Coord  Y,
RatType Line 
)

Checks if a rat-line end is on a PV.

Definition at line 739 of file search.c.

bool IsPointOnPin ( Coord  X,
Coord  Y,
Coord  Radius,
PinType pin 
)

Checks if a point is on a pin.

Definition at line 716 of file search.c.

References Distance(), IsPointInBox(), PIN_SIZE, TEST_FLAG, pin_st::X, BoxType::X1, BoxType::X2, pin_st::Y, BoxType::Y1, and BoxType::Y2.

Referenced by pinorvia_callback(), and PV_TOUCH_PV().

Here is the call graph for this function:

static int line_callback ( const BoxType box,
void *  cl 
) [static]

Definition at line 248 of file search.c.

References line_info::env, IsPointInPad(), line_info::Line, line_info::locked, line_info::Point, PosX, PosY, SearchRadius, and TEST_FLAG.

Referenced by SearchLineByLocation().

Here is the call graph for this function:

static int linepoint_callback ( const BoxType b,
void *  cl 
) [static]

Definition at line 461 of file search.c.

References Distance(), line_info::least, line_info::Line, line, line_info::locked, line_info::Point, PosX, PosY, and TEST_FLAG.

Referenced by SearchLinePointByLocation().

Here is the call graph for this function:

static int name_callback ( const BoxType box,
void *  cl 
) [static]
static int pad_callback ( const BoxType b,
void *  cl 
) [static]
static int pinorvia_callback ( const BoxType box,
void *  cl 
) [static]

Definition at line 112 of file search.c.

References pin_st::Element, ans_info::env, IsPointOnPin(), ans_info::locked, pin, PosX, PosY, ans_info::ptr1, ptr1, ans_info::ptr2, ans_info::ptr3, SearchRadius, and TEST_FLAG.

Referenced by SearchPinByLocation(), and SearchViaByLocation().

Here is the call graph for this function:

static int polygon_callback ( const BoxType box,
void *  cl 
) [static]

Definition at line 420 of file search.c.

References ans_info::env, IsPointInPolygon(), ans_info::locked, PosX, PosY, ans_info::ptr2, ans_info::ptr3, SearchRadius, and TEST_FLAG.

Referenced by SearchPolygonByLocation().

Here is the call graph for this function:

static int rat_callback ( const BoxType box,
void *  cl 
) [static]

Definition at line 289 of file search.c.

References Distance(), ans_info::env, IsPointOnLine(), line, ans_info::locked, PosX, PosY, ans_info::ptr1, ans_info::ptr2, ans_info::ptr3, SearchRadius, and TEST_FLAG.

Referenced by SearchRatLineByLocation().

Here is the call graph for this function:

static bool SearchArcByLocation ( int  locked,
LayerType **  Layer,
ArcType **  Arc,
ArcType **  Dummy 
) [static]

Searches arc on the SearchLayer.

Definition at line 361 of file search.c.

References arc_info::Arc, arc_callback(), LayerType::arc_tree, arc_info::Dummy, arc_info::env, arc_info::locked, r_search(), and SearchLayer.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchArcPointByLocation ( int  locked,
LayerType **  Layer,
ArcType **  arc,
PointType **  Point 
) [static]

Searches an arc-point on all the search layer.

Definition at line 547 of file search.c.

References arc_info::Arc, LayerType::arc_tree, arcpoint_callback(), arc_info::least, arc_info::locked, arc_info::Point, r_search(), SearchLayer, and SearchRadius.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchElementByLocation ( int  locked,
ElementType **  Element,
ElementType **  Dummy1,
ElementType **  Dummy2,
bool  BackToo 
) [static]

Searches an element.

The search starts with the last element and goes back to the beginning.

If more than one element matches, the smallest one is taken.

Definition at line 688 of file search.c.

References ans_info::area, ans_info::BackToo, PCBType::Data, element_callback(), DataType::element_tree, PCBType::ElementOn, PCBType::InvisibleObjectsOn, ans_info::locked, PCB, PCBType::PinOn, ans_info::ptr1, ans_info::ptr2, ans_info::ptr3, r_search(), and SQUARE.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

ElementType* SearchElementByName ( DataType Base,
char *  Name 
)

Searches for an element by its board name.

Returns:
The function returns a pointer to the element, NULL if not found.

Definition at line 1629 of file search.c.

References ELEMENT_LOOP, END_LOOP, and NSTRCMP.

Referenced by FindPad().

static bool SearchElementNameByLocation ( int  locked,
ElementType **  Element,
TextType **  Text,
TextType **  Dummy,
bool  BackToo 
) [static]

Searches the name of an element.

The search starts with the last element and goes back to the beginning.

Definition at line 631 of file search.c.

References ans_info::area, ans_info::BackToo, PCBType::Data, PCBType::ElementOn, PCBType::InvisibleObjectsOn, ans_info::locked, name_callback(), NAME_INDEX, DataType::name_tree, PCB, ans_info::ptr1, ans_info::ptr2, ans_info::ptr3, r_search(), SearchBox, and SQUARE.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

int SearchLayerByName ( DataType Base,
char *  Name 
)

Searches for an layer by its board name.

Returns:
The function returns an index of the layer, -1 if not found.

Definition at line 1653 of file search.c.

References END_LOOP, layer, LAYER_LOOP, max_copper_layer, and NSTRCMP.

Referenced by identify_layer().

static bool SearchLineByLocation ( int  locked,
LayerType **  Layer,
LineType **  Line,
LineType **  Dummy 
) [static]

Searches ordinary line on the SearchLayer.

Definition at line 269 of file search.c.

References line_info::env, line_info::Line, line_callback(), LayerType::line_tree, line_info::locked, line_info::Point, r_search(), and SearchLayer.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchLinePointByLocation ( int  locked,
LayerType **  Layer,
LineType **  Line,
PointType **  Point 
) [static]

Searches a line-point on all the search layer.

Definition at line 496 of file search.c.

References line_info::least, line_info::Line, LayerType::line_tree, linepoint_callback(), line_info::locked, line_info::Point, r_search(), SearchLayer, and SearchRadius.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

int SearchObjectByID ( DataType Base,
void **  Result1,
void **  Result2,
void **  Result3,
int  ID,
int  type 
)

Searches for a object by it's unique ID.

It doesn't matter if the object is visible or not.

The search is performed on a PCB, a buffer or on the remove list.

The calling routine passes two pointers to allocated memory for storing the results.

Returns:
A type value is returned too which is NO_TYPE if no objects has been found.

Definition at line 1425 of file search.c.

References ALLARC_LOOP, ALLLINE_LOOP, ALLPOLYGON_LOOP, ALLTEXT_LOOP, ARC_LOOP, ELEMENT_LOOP, ELEMENTLINE_LOOP, ELEMENTTEXT_LOOP, END_LOOP, ENDALL_LOOP, layer, line, Message(), PAD_LOOP, pin, PIN_LOOP, POLYGONPOINT_LOOP, RAT_LOOP, and VIA_LOOP.

Referenced by GetUndoSlot(), selection_changed_cb(), UndoChange2ndSize(), UndoChangeAngles(), UndoChangeClearSize(), UndoChangeMaskSize(), UndoChangeName(), UndoChangeSize(), UndoClearPoly(), UndoCopyOrCreate(), UndoFlag(), UndoInsertPoint(), UndoMirror(), UndoMove(), UndoMoveToLayer(), UndoRemove(), UndoRemovePoint(), UndoRotate(), UndoSetViaLayers(), and UndoSwapCopiedObject().

Here is the call graph for this function:

int SearchObjectByLocation ( unsigned  Type,
void **  Result1,
void **  Result2,
void **  Result3,
Coord  X,
Coord  Y,
Coord  Radius 
)

Searches for any kind of object or for a set of object types the calling routine passes two pointers to allocated memory for storing the results.

A type value is returned too which is NO_TYPE if no objects has been found.

A set of object types is passed in.

The object is located by it's position.

The layout is checked in the following order: polygon-point, pin, via, line, text, elementname, polygon, element

Note:
That if Type includes LOCKED_TYPE, then the search includes locked items. Otherwise, locked items are ignored.

Definition at line 1179 of file search.c.

References ans_info::area, box, PCBType::Data, PCBType::InvisibleObjectsOn, LAYER_ON_STACK, ans_info::locked, max_copper_layer, LayerType::On, PCB, point_box(), PosX, PosY, PCBType::RatOn, SearchArcByLocation(), SearchArcPointByLocation(), SearchElementByLocation(), SearchElementNameByLocation(), SearchLineByLocation(), SearchLinePointByLocation(), SearchPadByLocation(), SearchPinByLocation(), SearchPointByLocation(), SearchPolygonByLocation(), SearchRadius, SearchRatLineByLocation(), SearchTextByLocation(), SearchViaByLocation(), TEST_FLAG, X, BoxType::X1, BoxType::X2, Y, BoxType::Y1, and BoxType::Y2.

Referenced by ActionUndo(), AddNet(), check_snap_offgrid_line(), describe_location(), FitCrosshairIntoGrid(), LookupConnection(), MoveLineToLayer(), NotifyMode(), and SearchScreen().

Here is the call graph for this function:

static bool SearchPadByLocation ( int  locked,
ElementType **  Element,
PadType **  Pad,
PadType **  Dummy,
bool  BackToo 
) [static]

Searches a pad.

Starts with the newest element.

Definition at line 220 of file search.c.

References ans_info::BackToo, PCBType::Data, ans_info::found_anything, PCBType::InvisibleObjectsOn, ans_info::locked, pad_callback(), DataType::pad_tree, PCB, PCBType::PinOn, ans_info::ptr1, ans_info::ptr2, ans_info::ptr3, and r_search().

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchPinByLocation ( int  locked,
ElementType **  Element,
PinType **  Pin,
PinType **  Dummy 
) [static]

Searches a pin.

Starts with the newest element.

Definition at line 162 of file search.c.

References PCBType::Data, ans_info::env, ans_info::locked, PCB, DataType::pin_tree, PCBType::PinOn, pinorvia_callback(), ans_info::ptr1, ans_info::ptr2, ans_info::ptr3, and r_search().

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchPointByLocation ( int  locked,
LayerType **  Layer,
PolygonType **  Polygon,
PointType **  Point 
) [static]

Searches a polygon-point on all layers that are switched on in layerstack order.

Definition at line 567 of file search.c.

References Distance(), END_LOOP, arc_info::least, POLYGON_LOOP, POLYGONPOINT_LOOP, PosX, PosY, SearchLayer, and SearchRadius.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchPolygonByLocation ( int  locked,
LayerType **  Layer,
PolygonType **  Polygon,
PolygonType **  Dummy 
) [static]

Searches a polygon on the SearchLayer.

Definition at line 441 of file search.c.

References ans_info::env, ans_info::locked, polygon_callback(), LayerType::polygon_tree, ans_info::ptr2, ans_info::ptr3, r_search(), and SearchLayer.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchRatLineByLocation ( int  locked,
RatType **  Line,
RatType **  Dummy1,
RatType **  Dummy2 
) [static]

Searches rat lines if they are visible.

Definition at line 312 of file search.c.

References PCBType::Data, ans_info::env, ans_info::locked, PCB, ans_info::ptr1, ans_info::ptr2, ans_info::ptr3, r_search(), rat_callback(), and DataType::rat_tree.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchTextByLocation ( int  locked,
LayerType **  Layer,
TextType **  Text,
TextType **  Dummy 
) [static]

Searches text on the SearchLayer.

Definition at line 400 of file search.c.

References ans_info::env, ans_info::locked, ans_info::ptr2, ans_info::ptr3, r_search(), SearchLayer, text_callback(), and LayerType::text_tree.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static bool SearchViaByLocation ( int  locked,
PinType **  Via,
PinType **  Dummy1,
PinType **  Dummy2 
) [static]

Searches a via.

Definition at line 133 of file search.c.

References PCBType::Data, ans_info::env, ans_info::locked, PCB, pinorvia_callback(), ans_info::ptr1, ans_info::ptr2, ans_info::ptr3, r_search(), DataType::via_tree, and PCBType::ViaOn.

Referenced by SearchObjectByLocation().

Here is the call graph for this function:

static int text_callback ( const BoxType box,
void *  cl 
) [static]

Variable Documentation

BoxType SearchBox [static]

Definition at line 66 of file search.c.

Referenced by SearchElementNameByLocation().