pcb 4.1.1
An interactive printed circuit board layout editor.

buffer.c File Reference

Functions used by paste- and move/copy buffer. More...

#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include "global.h"
#include "buffer.h"
#include "copy.h"
#include "create.h"
#include "crosshair.h"
#include "data.h"
#include "error.h"
#include "mymem.h"
#include "mirror.h"
#include "misc.h"
#include "parse_l.h"
#include "polygon.h"
#include "rats.h"
#include "rotate.h"
#include "remove.h"
#include "rtree.h"
#include "search.h"
#include "select.h"
#include "set.h"
Include dependency graph for buffer.c:

Go to the source code of this file.

Data Structures

struct  FootprintHashEntry

Defines

#define ARG(n)   (argc > (n) ? argv[n] : 0)
#define MAYBE_WARN()

Functions

static void * AddViaToBuffer (PinType *Via)
 Copies a via to paste buffer.
static void * AddLineToBuffer (LayerType *Layer, LineType *Line)
 Copies a line to buffer.
static void * AddArcToBuffer (LayerType *Layer, ArcType *Arc)
 Copies an arc to buffer.
static void * AddRatToBuffer (RatType *Rat)
 Copies a rat-line to paste buffer.
static void * AddTextToBuffer (LayerType *Layer, TextType *Text)
 Copies a text to buffer.
static void * AddPolygonToBuffer (LayerType *Layer, PolygonType *Polygon)
 Copies a polygon to buffer.
static void * AddElementToBuffer (ElementType *Element)
 Copies a element to buffer.
static void * MoveViaToBuffer (PinType *via)
 Moves a via to paste buffer without allocating memory for the name.
static void * MoveLineToBuffer (LayerType *layer, LineType *line)
 Moves a line to buffer.
static void * MoveArcToBuffer (LayerType *layer, ArcType *arc)
 Moves an arc to buffer.
static void * MoveRatToBuffer (RatType *rat)
 Moves a rat-line to paste buffer.
static void * MoveTextToBuffer (LayerType *layer, TextType *text)
 Moves a text to buffer without allocating memory for the name.
static void * MovePolygonToBuffer (LayerType *layer, PolygonType *polygon)
 Moves a polygon to buffer.
static void * MoveElementToBuffer (ElementType *element)
 Moves a element to buffer without allocating memory for pins/names.
static void SwapBuffer (BufferType *Buffer)
 Flip components/tracks from one side to the other.
void SetBufferBoundingBox (BufferType *Buffer)
 Calculates the bounding box of the buffer.
void ClearBuffer (BufferType *Buffer)
 Clears the contents of the paste buffer.
void AddSelectedToBuffer (BufferType *Buffer, Coord X, Coord Y, bool LeaveSelected)
 Copies all selected and visible objects to the paste buffer.
bool LoadElementToBuffer (BufferType *Buffer, char *Name, bool FromFile)
 Loads element data from file/library into buffer.
void clear_footprint_hash ()
static int footprint_hash_cmp (const void *va, const void *vb)
 Used to sort footprint pointer entries.
void make_footprint_hash ()
FootprintHashEntrysearch_footprint_hash (const char *footprint)
 Searches for the given element by "footprint" name, and loads it into the buffer.
int LoadFootprintByName (BufferType *Buffer, char *Footprint)
 
int LoadFootprint (int argc, char **argv, Coord x, Coord y)
 This action is called from ActionElementAddIf().
bool SmashBufferElement (BufferType *Buffer)
 Break buffer element into pieces.
static int polygon_is_rectangle (PolygonType *poly)
 See if a polygon is a rectangle.
bool ConvertBufferToElement (BufferType *Buffer)
 Convert buffer contents into an element.
bool LoadLayoutToBuffer (BufferType *Buffer, char *Filename)
 Load PCB into buffer.
void RotateBuffer (BufferType *Buffer, BYTE Number)
 Rotates the contents of the pastebuffer.
static void free_rotate (Coord *x, Coord *y, Coord cx, Coord cy, double cosa, double sina)
void FreeRotateElementLowLevel (DataType *Data, ElementType *Element, Coord X, Coord Y, double cosa, double sina, Angle angle)
void FreeRotateBuffer (BufferType *Buffer, Angle angle)
int ActionFreeRotateBuffer (int argc, char **argv, Coord x, Coord y)
void InitBuffers (void)
 Initializes the buffers by allocating memory.
void UninitBuffers (void)
void SwapBuffers (void)
void MirrorBuffer (BufferType *Buffer)
void * MoveObjectToBuffer (DataType *Destination, DataType *Src, int Type, void *Ptr1, void *Ptr2, void *Ptr3)
 Moves the passed object to the passed buffer and removes it from its original place.
void * CopyObjectToBuffer (DataType *Destination, DataType *Src, int Type, void *Ptr1, void *Ptr2, void *Ptr3)
 Adds the passed object to the passed buffer.

Variables

static DataTypeDest
static DataTypeSource
static ObjectFunctionType AddBufferFunctions
static ObjectFunctionType MoveBufferFunctions
static int ExtraFlag = 0
static FootprintHashEntryfootprint_hash = 0
int footprint_hash_size = 0
static const char loadfootprint_syntax []
static const char loadfootprint_help []
static const char freerotatebuffer_syntax []
static const char freerotatebuffer_help []
HID_Action rotate_action_list []

Detailed Description

Functions used by paste- and move/copy buffer.


Copyright.


PCB, interactive printed circuit board design

Copyright (C) 1994,1995,1996, 2005 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 buffer.c.


Define Documentation

#define MAYBE_WARN ( )
Value:
if (onsolder && !hasParts && !warned) \
            { \
              warned = true; \
              Message \
                (_("Warning: All of the pads are on the opposite\n" \
                   "side from the component - that's probably not what\n" \
                   "you wanted\n")); \
            } \

Referenced by ConvertBufferToElement().


Function Documentation

int ActionFreeRotateBuffer ( int  argc,
char **  argv,
Coord  x,
Coord  y 
)

Definition at line 1381 of file buffer.c.

References _, FreeRotateBuffer(), gui, notify_crosshair_change(), PASTEBUFFER, and hid_st::prompt_for.

Here is the call graph for this function:

static void * AddArcToBuffer ( LayerType Layer,
ArcType Arc 
) [static]

Copies an arc to buffer.

Definition at line 164 of file buffer.c.

References ArcType::Clearance, CreateNewArcOnLayer(), ArcType::Delta, ExtraFlag, GetLayerNumber(), ArcType::Height, DataType::Layer, layer, MaskFlags(), ArcType::StartAngle, ArcType::Thickness, ArcType::Width, ArcType::X, and ArcType::Y.

Here is the call graph for this function:

static void * AddElementToBuffer ( ElementType Element) [static]

Copies a element to buffer.

Definition at line 216 of file buffer.c.

References CopyElementLowLevel(), and ExtraFlag.

Here is the call graph for this function:

static void * AddLineToBuffer ( LayerType Layer,
LineType Line 
) [static]

Copies a line to buffer.

Definition at line 145 of file buffer.c.

References CreateNewLineOnLayer(), ExtraFlag, GetLayerNumber(), DataType::Layer, layer, line, MaskFlags(), and LineType::Number.

Here is the call graph for this function:

static void * AddPolygonToBuffer ( LayerType Layer,
PolygonType Polygon 
) [static]

Copies a polygon to buffer.

Definition at line 192 of file buffer.c.

References CLEAR_FLAG, CopyPolygonLowLevel(), CreateNewPolygon(), ExtraFlag, GetLayerNumber(), DataType::Layer, layer, LayerType::polygon_tree, r_create_tree(), and r_insert_entry().

Here is the call graph for this function:

static void * AddRatToBuffer ( RatType Rat) [static]

Copies a rat-line to paste buffer.

Definition at line 133 of file buffer.c.

References CreateNewRat(), ExtraFlag, RatType::group1, RatType::group2, and MaskFlags().

Here is the call graph for this function:

void AddSelectedToBuffer ( BufferType Buffer,
Coord  X,
Coord  Y,
bool  LeaveSelected 
)

Copies all selected and visible objects to the paste buffer.

Returns:
true if any objects have been removed.

Definition at line 443 of file buffer.c.

References Crosshair, BufferType::Data, PCBType::Data, ExtraFlag, notify_crosshair_change(), PCB, SelectedOperation(), CrosshairType::X, X, BufferType::X, CrosshairType::Y, Y, and BufferType::Y.

Referenced by ActionPasteBuffer(), ActionSelect(), and click_cb().

Here is the call graph for this function:

static void * AddTextToBuffer ( LayerType Layer,
TextType Text 
) [static]

Copies a text to buffer.

Definition at line 179 of file buffer.c.

References CreateNewText(), TextType::Direction, ExtraFlag, PCBType::Font, GetLayerNumber(), DataType::Layer, layer, MaskFlags(), PCB, TextType::Scale, TextType::TextString, TextType::X, and TextType::Y.

Here is the call graph for this function:

static void * AddViaToBuffer ( PinType Via) [static]

Copies a via to paste buffer.

Definition at line 122 of file buffer.c.

References pin_st::BuriedFrom, pin_st::BuriedTo, pin_st::Clearance, CreateNewViaEx(), pin_st::DrillingHole, ExtraFlag, pin_st::Mask, MaskFlags(), pin_st::Name, pin_st::Thickness, pin_st::X, and pin_st::Y.

Here is the call graph for this function:

void clear_footprint_hash ( )

Definition at line 541 of file buffer.c.

References footprint_hash_size.

Referenced by make_footprint_hash().

void ClearBuffer ( BufferType Buffer)

Clears the contents of the paste buffer.

Definition at line 428 of file buffer.c.

References BufferType::Data, FreeDataMemory(), PCB, and DataType::pcb.

Referenced by ActionPasteBuffer(), ActionRipUp(), ActionSelect(), click_cb(), ConvertBufferToElement(), LoadElementToBuffer(), LoadLayoutToBuffer(), ReleaseMode(), SmashBufferElement(), and UninitBuffers().

Here is the call graph for this function:

void* CopyObjectToBuffer ( DataType Destination,
DataType Src,
int  Type,
void *  Ptr1,
void *  Ptr2,
void *  Ptr3 
)

Adds the passed object to the passed buffer.

Definition at line 1639 of file buffer.c.

References ObjectOperation().

Referenced by ActionRipUp(), and CopyObjectToUndoList().

Here is the call graph for this function:

static int footprint_hash_cmp ( const void *  va,
const void *  vb 
) [static]

Used to sort footprint pointer entries.

Note:
We include the index numbers so that same-named footprints are sorted by the library search order.

Definition at line 561 of file buffer.c.

References FootprintHashEntry::entry_idx, FootprintHashEntry::footprint, and FootprintHashEntry::menu_idx.

Referenced by make_footprint_hash().

static void free_rotate ( Coord x,
Coord y,
Coord  cx,
Coord  cy,
double  cosa,
double  sina 
) [static]

Definition at line 1228 of file buffer.c.

References cx, cy, px, and py.

Referenced by FreeRotateBuffer(), and FreeRotateElementLowLevel().

void InitBuffers ( void  )

Initializes the buffers by allocating memory.

Definition at line 1400 of file buffer.c.

References Buffers, and CreateNewBuffer().

Referenced by main().

Here is the call graph for this function:

bool LoadElementToBuffer ( BufferType Buffer,
char *  Name,
bool  FromFile 
)

Loads element data from file/library into buffer.

Parse the file with disabled 'PCB mode' (see parser).

Returns:
false on error, if successful, update some other stuff and reposition the pastebuffer.

Definition at line 479 of file buffer.c.

References ClearBuffer(), BufferType::Data, DataType::Element, DataType::ElementN, PCBType::Font, ElementType::MarkX, ElementType::MarkY, MirrorElementCoordinates(), ParseElementFile(), ParseLibraryEntry(), PCB, SetBufferBoundingBox(), SetElementBoundingBox(), Settings, SettingType::ShowBottomSide, SwapBuffer(), BufferType::X, and BufferType::Y.

Referenced by ActionLoadFrom(), libnode_select(), library_window_callback_tree_selection_changed(), and LoadFootprintByName().

Here is the call graph for this function:

int LoadFootprint ( int  argc,
char **  argv,
Coord  x,
Coord  y 
)

This action is called from ActionElementAddIf().

Definition at line 813 of file buffer.c.

References _, AFAIL, ARG, LoadFootprintByName(), Message(), ElementType::Name, PASTEBUFFER, and TextType::TextString.

Referenced by ActionElementList().

Here is the call graph for this function:

bool LoadLayoutToBuffer ( BufferType Buffer,
char *  Filename 
)

Load PCB into buffer.

Parse the file with enabled 'PCB mode' (see parser). If successful, update some other stuff.

Definition at line 1142 of file buffer.c.

References ClearBuffer(), CreateNewPCB(), PCBType::CursorX, PCBType::CursorY, PCBType::Data, BufferType::Data, ParsePCB(), PCB, DataType::pcb, RemovePCB(), BufferType::X, and BufferType::Y.

Referenced by ActionLoadFrom().

Here is the call graph for this function:

static void * MoveArcToBuffer ( LayerType layer,
ArcType arc 
) [static]

Moves an arc to buffer.

Definition at line 295 of file buffer.c.

References LayerType::Arc, LayerType::arc_tree, LayerType::ArcN, CLEAR_FLAG, ClearFromPolygon(), GetLayerNumber(), DataType::Layer, r_create_tree(), r_delete_entry(), r_insert_entry(), and RestoreToPolygon().

Here is the call graph for this function:

static void * MoveElementToBuffer ( ElementType element) [static]

Moves a element to buffer without allocating memory for pins/names.

Definition at line 369 of file buffer.c.

References CLEAR_FLAG, ClearFromPolygon(), DataType::Element, DataType::ElementN, END_LOOP, PCBType::Font, PAD_LOOP, PCB, pin, PIN_LOOP, r_delete_element(), RestoreToPolygon(), and SetElementBoundingBox().

Here is the call graph for this function:

static void * MoveLineToBuffer ( LayerType layer,
LineType line 
) [static]

Moves a line to buffer.

Definition at line 270 of file buffer.c.

References CLEAR_FLAG, ClearFromPolygon(), GetLayerNumber(), DataType::Layer, LayerType::Line, LayerType::line_tree, LayerType::LineN, r_create_tree(), r_delete_entry(), r_insert_entry(), and RestoreToPolygon().

Here is the call graph for this function:

void* MoveObjectToBuffer ( DataType Destination,
DataType Src,
int  Type,
void *  Ptr1,
void *  Ptr2,
void *  Ptr3 
)

Moves the passed object to the passed buffer and removes it from its original place.

Definition at line 1626 of file buffer.c.

References MoveBufferFunctions, and ObjectOperation().

Referenced by ConvertBufferToElement(), MoveObjectToRemoveUndoList(), UndoCopyOrCreate(), UndoRemove(), and UndoSwapCopiedObject().

Here is the call graph for this function:

static void * MovePolygonToBuffer ( LayerType layer,
PolygonType polygon 
) [static]

Moves a polygon to buffer.

Doesn't allocate memory for the points.

Definition at line 345 of file buffer.c.

References CLEAR_FLAG, GetLayerNumber(), DataType::Layer, LayerType::Polygon, LayerType::polygon_tree, LayerType::PolygonN, r_create_tree(), r_delete_entry(), and r_insert_entry().

Here is the call graph for this function:

static void * MoveRatToBuffer ( RatType rat) [static]

Moves a rat-line to paste buffer.

Definition at line 249 of file buffer.c.

References CLEAR_FLAG, r_create_tree(), r_delete_entry(), r_insert_entry(), DataType::Rat, DataType::rat_tree, and DataType::RatN.

Here is the call graph for this function:

static void * MoveTextToBuffer ( LayerType layer,
TextType text 
) [static]

Moves a text to buffer without allocating memory for the name.

Definition at line 320 of file buffer.c.

References ClearFromPolygon(), GetLayerNumber(), DataType::Layer, r_create_tree(), r_delete_entry(), r_insert_entry(), RestoreToPolygon(), LayerType::Text, LayerType::text_tree, and LayerType::TextN.

Here is the call graph for this function:

static void * MoveViaToBuffer ( PinType via) [static]

Moves a via to paste buffer without allocating memory for the name.

Definition at line 226 of file buffer.c.

References CLEAR_FLAG, ClearFromPolygon(), r_create_tree(), r_delete_entry(), r_insert_entry(), RestoreToPolygon(), DataType::Via, DataType::via_tree, and DataType::ViaN.

Here is the call graph for this function:

static int polygon_is_rectangle ( PolygonType poly) [static]

See if a polygon is a rectangle.

If so, canonicalize it.

Definition at line 938 of file buffer.c.

References polygon_st::HoleIndexN, polygon_st::PointN, polygon_st::Points, X, PointType::X, and PointType::Y.

Referenced by ConvertBufferToElement().

FootprintHashEntry* search_footprint_hash ( const char *  footprint)

Searches for the given element by "footprint" name, and loads it into the buffer.

Figuring out which library entry is the one we want is a little tricky. For file-based footprints, it's just a matter of finding the first match in the search list. For m4-based footprints you need to know what magic to pass to the m4 functions. Fortunately, the footprint needed is determined when we build the m4 libraries and stored as a comment in the description, so we can search for that to find the magic we need. We use a hash to store the corresponding footprints and pointers to the library tree so we can quickly find the various bits we need to load a given footprint.

Definition at line 678 of file buffer.c.

References c, footprint_hash_size, max, and min.

Referenced by LoadFootprintByName().

void SetBufferBoundingBox ( BufferType Buffer)

Calculates the bounding box of the buffer.

Definition at line 416 of file buffer.c.

References BufferType::BoundingBox, box, BufferType::Data, and GetDataBoundingBox().

Referenced by ConvertBufferToElement(), crosshair_update_range(), FreeRotateBuffer(), LoadElementToBuffer(), MirrorBuffer(), and SwapBuffer().

Here is the call graph for this function:

void SwapBuffers ( void  )

Definition at line 1421 of file buffer.c.

References Buffers, crosshair_update_range(), and SwapBuffer().

Referenced by SaveBufferElements().

Here is the call graph for this function:

void UninitBuffers ( void  )

Definition at line 1409 of file buffer.c.

References Buffers, and ClearBuffer().

Referenced by pcb_main_uninit().

Here is the call graph for this function:


Variable Documentation

Initial value:

Definition at line 93 of file buffer.c.

DataType* Dest [static]

Definition at line 91 of file buffer.c.

Referenced by CopyElementLowLevel().

Definition at line 537 of file buffer.c.

Definition at line 538 of file buffer.c.

Referenced by clear_footprint_hash(), make_footprint_hash(), and search_footprint_hash().

const char freerotatebuffer_help[] [static]
Initial value:
  N_("Rotates the current paste buffer contents by the specified angle.  The\n"
  "angle is given in degrees.  If no angle is given, the user is prompted\n"
  "for one.\n")

Definition at line 1368 of file buffer.c.

const char freerotatebuffer_syntax[] [static]
Initial value:
  N_("FreeRotateBuffer([Angle])")

Definition at line 1365 of file buffer.c.

const char loadfootprint_help[] [static]
Initial value:
  N_("Loads a single footprint by name.")

Definition at line 798 of file buffer.c.

const char loadfootprint_syntax[] [static]
Initial value:
  N_("LoadFootprint(filename[,refdes,value])")

Definition at line 795 of file buffer.c.

Initial value:

Definition at line 1650 of file buffer.c.

Definition at line 91 of file buffer.c.