pcb 4.1.1
An interactive printed circuit board layout editor.

crosshair.c File Reference

Crosshair stuff. More...

#include <memory.h>
#include <math.h>
#include "global.h"
#include "hid_draw.h"
#include "crosshair.h"
#include "buffer.h"
#include "data.h"
#include "draw.h"
#include "error.h"
#include "line.h"
#include "misc.h"
#include "mymem.h"
#include "search.h"
#include "polygon.h"
Include dependency graph for crosshair.c:

Go to the source code of this file.

Data Structures

struct  point
struct  snap_data

Functions

static void thindraw_moved_pv (hidGC gc, PinType *pv, Coord x, Coord y)
 Make a copy of the pin structure, moved to the correct position.
static void draw_dashed_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
 Draw a dashed line.
static void XORPolygon (hidGC gc, PolygonType *polygon, Coord dx, Coord dy, int dash_last)
 Creates a tmp polygon with coordinates converted to screen system.
static void XORDrawAttachedArc (hidGC gc, Coord thick)
 Draws the outline of an arc.
static void XORDrawAttachedLine (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2, Coord thick)
 Draws the outline of a line.
static void XORDrawElement (hidGC gc, ElementType *Element, Coord DX, Coord DY)
 Draws the elements of a loaded circuit which is to be merged in.
static void XORDrawBuffer (hidGC gc, BufferType *Buffer)
 Draws all visible and attached objects of the pastebuffer.
static void XORDrawInsertPointObject (hidGC gc)
 Draws the rubberband to insert points into polygons/lines/...
static void XORDrawMoveOrCopyObject (hidGC gc)
 Draws the attached object while in MOVE_MODE or COPY_MODE.
void DrawAttached (hidGC gc)
 Draws additional stuff that follows the crosshair.
void DrawMark (hidGC gc)
 Draw the marker position.
Coord GridFit (Coord x, Coord grid_spacing, Coord grid_offset)
 Returns the nearest grid-point to the given Coord.
void notify_crosshair_change (bool changes_complete)
 Notify the GUI that data relating to the crosshair is being changed.
void notify_mark_change (bool changes_complete)
 Notify the GUI that data relating to the mark is being changed.
void HideCrosshair (void)
 Convenience for plugins using the old {Hide,Restore}Crosshair API.
void RestoreCrosshair (void)
static double square (double x)
 Returns the square of the given number.
static double crosshair_sq_dist (CrosshairType *crosshair, Coord x, Coord y)
static void check_snap_object (struct snap_data *snap_data, Coord x, Coord y, bool prefer_to_grid)
 Snap to a given location if it is the closest thing we found so far.
static void check_snap_offgrid_line (struct snap_data *snap_data, Coord nearest_grid_x, Coord nearest_grid_y)
void FitCrosshairIntoGrid (Coord X, Coord Y)
 Recalculates the passed coordinates to fit the current grid setting.
bool MoveCrosshairAbsolute (Coord X, Coord Y)
 Move crosshair absolute.
void crosshair_update_range (void)
 Update the valid range for the crosshair cursor.
void SetCrosshairRange (Coord MinX, Coord MinY, Coord MaxX, Coord MaxY)
 Sets the valid range for the crosshair cursor.
void InitCrosshair (void)
 Initializes crosshair stuff.
void DestroyCrosshair (void)
 Exits crosshair routines, release GCs.

Detailed Description

Crosshair stuff.


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 crosshair.c.


Function Documentation

static void check_snap_object ( struct snap_data snap_data,
Coord  x,
Coord  y,
bool  prefer_to_grid 
) [static]

Snap to a given location if it is the closest thing we found so far.

If "prefer_to_grid" is set, the passed location will take preference over a closer grid points we already snapped to UNLESS the user is pressing the SHIFT key. If the SHIFT key is pressed, the closest object (including grid points), is always preferred.

Definition at line 884 of file crosshair.c.

References snap_data::crosshair, crosshair_sq_dist(), gui, snap_data::nearest_is_grid, snap_data::nearest_sq_dist, hid_st::shift_is_pressed, x, snap_data::x, y, and snap_data::y.

Referenced by check_snap_offgrid_line(), and FitCrosshairIntoGrid().

Here is the call graph for this function:

static void check_snap_offgrid_line ( struct snap_data snap_data,
Coord  nearest_grid_x,
Coord  nearest_grid_y 
) [static]
static double crosshair_sq_dist ( CrosshairType crosshair,
Coord  x,
Coord  y 
) [static]

Definition at line 862 of file crosshair.c.

References square(), CrosshairType::X, and CrosshairType::Y.

Referenced by check_snap_object(), and FitCrosshairIntoGrid().

Here is the call graph for this function:

void DestroyCrosshair ( void  )

Exits crosshair routines, release GCs.

Definition at line 1350 of file crosshair.c.

References CrosshairType::AttachedPolygon, Crosshair, and FreePolygonMemory().

Here is the call graph for this function:

static void draw_dashed_line ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
) [static]

Draw a dashed line.

Todo:
we need a real geometrical library, using double here is plain wrong.
Todo:
line too short, just draw it -> magic value; with a proper geo lib this would be gone anyway.

Definition at line 83 of file crosshair.c.

References hid_draw_st::draw_line, hid_st::graphics, gui, and n.

Referenced by XORPolygon().

void DrawAttached ( hidGC  gc)

Draws additional stuff that follows the crosshair.

Definition at line 594 of file crosshair.c.

References ARC_MODE, CrosshairType::AttachedBox, CrosshairType::AttachedLine, CrosshairType::AttachedPolygon, PCBType::Bloat, pin_st::Clearance, PCBType::Clipping, COPY_MODE, SettingType::CrossColor, Crosshair, SettingType::CrosshairColor, AttachedLineType::draw, hid_draw_st::draw_arc, hid_draw_st::draw_line, hid_draw_st::draw_rect, pin_st::DrillingHole, hid_st::graphics, gui, INSERTPOINT_MODE, SettingType::Keepaway, LINE_MODE, SettingType::LineThickness, pin_st::Mask, SettingType::Mode, MOVE_MODE, NoFlags, PASTEBUFFER, PASTEBUFFER_MODE, PCB, AttachedBoxType::Point1, AttachedLineType::Point1, AttachedBoxType::Point2, AttachedLineType::Point2, polygon_st::PointN, POLYGON_MODE, POLYGONHOLE_MODE, PCBType::RatDraw, Round_Cap, hid_draw_st::set_color, hid_draw_st::set_draw_xor, hid_draw_st::set_line_cap, hid_draw_st::set_line_width, Settings, AttachedBoxType::State, AttachedLineType::State, STATE_FIRST, STATE_SECOND, STATE_THIRD, TEST_FLAG, pin_st::Thickness, hid_draw_st::thindraw_pcb_pv, Trace_Cap, VIA_MODE, SettingType::ViaDrillingHole, SettingType::ViaThickness, PointType::X, CrosshairType::X, pin_st::X, XORDrawAttachedArc(), XORDrawAttachedLine(), XORDrawBuffer(), XORDrawInsertPointObject(), XORDrawMoveOrCopyObject(), XORPolygon(), PointType::Y, CrosshairType::Y, and pin_st::Y.

Referenced by ghid_drawing_area_expose_cb(), ghid_notify_crosshair_change(), idle_proc(), lesstif_flush_debug_draw(), lesstif_notify_crosshair_change(), and redraw_region().

Here is the call graph for this function:

Coord GridFit ( Coord  x,
Coord  grid_spacing,
Coord  grid_offset 
)

Returns the nearest grid-point to the given Coord.

Definition at line 755 of file crosshair.c.

References x.

Referenced by ActionSelect(), AttachForCopy(), Center(), FitCrosshairIntoGrid(), ghid_draw_grid(), hidgl_draw_grid(), and lesstif_draw_grid().

void HideCrosshair ( void  )

Convenience for plugins using the old {Hide,Restore}Crosshair API.

This links up to notify the GUI of the expected changes using the new APIs.

Use of this old API is deprecated, as the names don't necessarily reflect what all GUIs may do in response to the notifications. Keeping these APIs is aimed at easing transition to the newer API, they will emit a harmless warning at the time of their first use.

Definition at line 823 of file crosshair.c.

References _, Message(), notify_crosshair_change(), and notify_mark_change().

Here is the call graph for this function:

void InitCrosshair ( void  )

Initializes crosshair stuff.

Clears the struct, allocates to graphical contexts.

Definition at line 1332 of file crosshair.c.

References Basic_Crosshair_Shape, Crosshair, Marked, PCBType::MaxHeight, PCBType::MaxWidth, CrosshairType::MaxX, CrosshairType::MaxY, CrosshairType::MinX, CrosshairType::MinY, PCB, CrosshairType::shape, and MarkType::status.

Referenced by main().

bool MoveCrosshairAbsolute ( Coord  X,
Coord  Y 
)

Move crosshair absolute.

Returns:
true if the crosshair was moved from its existing position.

Definition at line 1242 of file crosshair.c.

References Crosshair, FitCrosshairIntoGrid(), notify_crosshair_change(), CrosshairType::X, and CrosshairType::Y.

Referenced by ActionDisplay(), CenterDisplay(), EventMoveCrosshair(), ghid_note_event_location(), and netnode_browse().

Here is the call graph for this function:

void notify_crosshair_change ( bool  changes_complete)

Notify the GUI that data relating to the crosshair is being changed.

The argument passed is false to notify "changes are about to happen", and true to notify "changes have finished".

Each call with a 'false' parameter must be matched with a following one with a 'true' parameter. Unmatched 'true' calls are currently not permitted, but might be allowed in the future.

GUIs should not complain if they receive extra calls with 'true' as parameter. They should initiate a redraw of the crosshair attached objects - which may (if necessary) mean repainting the whole screen if the GUI hasn't tracked the location of existing attached drawing.

Definition at line 781 of file crosshair.c.

References gui, and hid_st::notify_crosshair_change.

Referenced by ActionDisplay(), ActionFreeRotateBuffer(), ActionLoadFrom(), ActionMode(), ActionNew(), ActionPasteBuffer(), ActionPolygon(), ActionRedo(), ActionSelect(), ActionSetSame(), ActionUndo(), ActionUnselect(), AddSelectedToBuffer(), CenterDisplay(), click_cb(), EventMoveCrosshair(), ghid_note_event_location(), HideCrosshair(), mod_changed(), MoveCrosshairAbsolute(), NotifyBlock(), RestoreCrosshair(), run_get_location_loop(), SetMode(), ShowCrosshair(), and work_area_input().

void notify_mark_change ( bool  changes_complete)

Notify the GUI that data relating to the mark is being changed.

The argument passed is false to notify "changes are about to happen", and true to notify "changes have finished".

Each call with a 'false' parameter must be matched with a following one with a 'true' parameter. Unmatched 'true' calls are currently not permitted, but might be allowed in the future.

GUIs should not complain if they receive extra calls with 'true' as parameter. They should initiate a redraw of the mark - which may (if necessary) mean repainting the whole screen if the GUI hasn't tracked the mark's location.

Definition at line 803 of file crosshair.c.

References gui, and hid_st::notify_mark_change.

Referenced by ActionMarkCrosshair(), HideCrosshair(), RestoreCrosshair(), SetLocalRef(), and ShowCrosshair().

void RestoreCrosshair ( void  )

Definition at line 838 of file crosshair.c.

References _, Message(), notify_crosshair_change(), and notify_mark_change().

Here is the call graph for this function:

void SetCrosshairRange ( Coord  MinX,
Coord  MinY,
Coord  MaxX,
Coord  MaxY 
)

Sets the valid range for the crosshair cursor.

Definition at line 1315 of file crosshair.c.

References Crosshair, FitCrosshairIntoGrid(), MAX, PCBType::MaxHeight, PCBType::MaxWidth, CrosshairType::MaxX, CrosshairType::MaxY, MIN, CrosshairType::MinX, CrosshairType::MinY, PCB, CrosshairType::X, and CrosshairType::Y.

Referenced by crosshair_update_range().

Here is the call graph for this function:

static double square ( double  x) [static]

Returns the square of the given number.

Definition at line 856 of file crosshair.c.

References x.

Referenced by crosshair_sq_dist().

static void thindraw_moved_pv ( hidGC  gc,
PinType pv,
Coord  x,
Coord  y 
) [static]

Make a copy of the pin structure, moved to the correct position.

Definition at line 70 of file crosshair.c.

References hid_st::graphics, gui, hid_draw_st::thindraw_pcb_pv, x, pin_st::X, y, and pin_st::Y.

Referenced by XORDrawBuffer(), XORDrawElement(), and XORDrawMoveOrCopyObject().

static void XORDrawAttachedLine ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2,
Coord  thick 
) [static]

Draws the outline of a line.

Definition at line 216 of file crosshair.c.

References abs, hid_draw_st::draw_arc, hid_draw_st::draw_line, hid_st::graphics, gui, pixel_slop, and SGN.

Referenced by DrawAttached(), and XORDrawMoveOrCopyObject().

static void XORDrawElement ( hidGC  gc,
ElementType Element,
Coord  DX,
Coord  DY 
) [static]
static void XORDrawInsertPointObject ( hidGC  gc) [static]

Draws the rubberband to insert points into polygons/lines/...

Definition at line 416 of file crosshair.c.

References CrosshairType::AttachedObject, Crosshair, hid_draw_st::draw_line, hid_st::graphics, gui, line, AttachedObjectType::Ptr2, AttachedObjectType::Ptr3, and AttachedObjectType::Type.

Referenced by DrawAttached().

static void XORPolygon ( hidGC  gc,
PolygonType polygon,
Coord  dx,
Coord  dy,
int  dash_last 
) [static]

Creates a tmp polygon with coordinates converted to screen system.

Definition at line 123 of file crosshair.c.

References draw_dashed_line(), hid_draw_st::draw_line, hid_st::graphics, gui, next_contour_point(), polygon_st::PointN, polygon_st::Points, PointType::X, and PointType::Y.

Referenced by DrawAttached(), XORDrawBuffer(), and XORDrawMoveOrCopyObject().

Here is the call graph for this function: