libgeda

o_box_basic.c File Reference

functions for the box object More...

#include <config.h>
#include <math.h>
#include <stdio.h>
#include "libgeda_priv.h"
Include dependency graph for o_box_basic.c:

Go to the source code of this file.

Functions

OBJECTo_box_new (TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2)
 Create a BOX OBJECT.
OBJECTo_box_copy (TOPLEVEL *toplevel, OBJECT *o_current)
 Copy a box to a list.
void o_box_modify_all (TOPLEVEL *toplevel, OBJECT *object, int x1, int y1, int x2, int y2)
 Modify a BOX OBJECT's coordinates.
void o_box_modify (TOPLEVEL *toplevel, OBJECT *object, int x, int y, int whichone)
 Modify a BOX OBJECT's coordinates.
OBJECTo_box_read (TOPLEVEL *toplevel, const char buf[], unsigned int release_ver, unsigned int fileformat_ver, GError **err)
 Create a box from a character string.
char * o_box_save (TOPLEVEL *toplevel, OBJECT *object)
 Create a character string representation of a BOX.
void o_box_translate_world (TOPLEVEL *toplevel, int dx, int dy, OBJECT *object)
 Translate a BOX position in WORLD coordinates by a delta.
void o_box_rotate_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, int angle, OBJECT *object)
 Rotate BOX OBJECT using WORLD coordinates.
void o_box_mirror_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, OBJECT *object)
 Mirror BOX using WORLD coordinates.
void o_box_recalc (TOPLEVEL *toplevel, OBJECT *o_current)
 Recalculate BOX coordinates in WORLD units.
void world_get_box_bounds (TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom)
 Get BOX bounding rectangle in WORLD coordinates.
gboolean o_box_get_position (TOPLEVEL *toplevel, gint *x, gint *y, OBJECT *object)
 get the position of the left bottom point
void o_box_print (TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current, int origin_x, int origin_y)
 Print BOX to Postscript document.
void o_box_print_solid (TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print a solid BOX to Postscript document.
void o_box_print_dotted (TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print a dotted BOX to Postscript document.
void o_box_print_dashed (TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print a dashed BOX to Postscript document.
void o_box_print_center (TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print centered line type BOX to Postscript document.
void o_box_print_phantom (TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print phantom line type BOX to Postscript document.
void o_box_print_filled (TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y)
 Print a solid pattern BOX to Postscript document.
void o_box_print_mesh (TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y)
 Print a mesh pattern BOX to Postscript document.
void o_box_print_hatch (TOPLEVEL *toplevel, FILE *fp, int x, int y, int width, int height, int color, int fill_width, int angle1, int pitch1, int angle2, int pitch2, int origin_x, int origin_y)
 Print a hatch pattern BOX to Postscript document.
double o_box_shortest_distance (OBJECT *object, int x, int y, int force_solid)
 Calculates the distance between the given point and the closest point on the perimeter of the box.

Detailed Description

Definition in file o_box_basic.c.


Function Documentation

OBJECT* o_box_new ( TOPLEVEL toplevel,
char  type,
int  color,
int  x1,
int  y1,
int  x2,
int  y2 
)
Function Description
This function creates a new object representing a box.

The box is described by its upper left corner - x1, y1 - and its lower right corner - x2, y2. The type parameter must be equal to OBJ_BOX. The color corresponds to the color the box will be drawn with. The OBJECT structure is allocated with the s_basic_new_object() function. The structure describing the box is allocated and initialized with the parameters given to the function.

Both the line type and the filling type are set to default values : solid line type with a width of 0, and no filling. It can be changed after with the o_set_line_options() and o_set_fill_options().

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]typeBox type.
[in]colorBox border color.
[in]x1Upper x coordinate.
[in]y1Upper y coordinate.
[in]x2Lower x coordinate.
[in]y2Lower y coordinate.
Returns:
The new OBJECT

Definition at line 60 of file o_box_basic.c.

Here is the call graph for this function:

OBJECT* o_box_copy ( TOPLEVEL toplevel,
OBJECT o_current 
)
Function Description
The function o_box_copy() creates a verbatim copy of the object pointed by o_current describing a box.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]o_currentBOX OBJECT to copy.
Returns:
The new OBJECT

Definition at line 101 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_modify_all ( TOPLEVEL toplevel,
OBJECT object,
int  x1,
int  y1,
int  x2,
int  y2 
)
Function Description
Modifies the coordinates of all four corners of box, by setting the box to the rectangle enclosed by the points (x1, y1) and (x2, y2).
Parameters:
[in]toplevelcurrent TOPLEVEL.
[in,out]objectbox OBJECT to be modified.
[in]x1x coordinate of first corner of box.
[in]y1y coordinate of first corner of box.
[in]x2x coordinate of second corner of box.
[in]y2y coordinate of second corner of box,

Definition at line 151 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_modify ( TOPLEVEL toplevel,
OBJECT object,
int  x,
int  y,
int  whichone 
)
Function Description
This function modifies the coordinates of one of the four corner of the box. The new coordinates of the corner identified by whichone are given by x and y in world unit.

The coordinates of the corner is modified in the world coordinate system. Screen coordinates and boundings are then updated.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in,out]objectBOX OBJECT to be modified.
[in]xx coordinate.
[in]yy coordinate.
[in]whichonecoordinate to change.
Note:
whichone can take the following values:
*
BOX_UPPER_LEFT
*
BOX_LOWER_LEFT
*
BOX_UPPER_RIGHT
*
BOX_LOWER_RIGHT

Definition at line 191 of file o_box_basic.c.

Here is the call graph for this function:

OBJECT* o_box_read ( TOPLEVEL toplevel,
const char  buf[],
unsigned int  release_ver,
unsigned int  fileformat_ver,
GError **  err 
)
Function Description
This function gets the description of a box from the *buf character string.

Depending on *version, the correct file format is considered. Currently two file format revisions are supported :

*
the file format used until 20000704 release
*
the file format used for the releases after 2000704.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]bufCharacter string with box description.
[in]release_verlibgeda release version number.
[in]fileformat_verlibgeda file format version number.
Returns:
The BOX OBJECT that was created, or NULL on error.

Note:
The old geda file format, i.e. releases 20000704 and older, does not handle the line type and the filling of the box object. They are set to default.
The current line format to describe a box is a space separated list of characters and numbers in plain ASCII on a single line. The meaning of each item is described in the file format documentation.
A box is internally described by its lower right and upper left corner whereas the line describe it with the lower left corner and the width and height.

A new object is allocated, initialized and added to the object list. Its filling and line type are set according to the values of the field on the line.

Definition at line 261 of file o_box_basic.c.

Here is the call graph for this function:

char* o_box_save ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
This function formats a string in the buffer *buff to describe the box object *object. It follows the post-20000704 release file format that handle the line type and fill options.
Parameters:
[in]toplevelThe TOPLEVEL structure.
[in]objectThe BOX OBJECT to create string from.
Returns:
A pointer to the BOX character string.
Warning:
Caller must g_free returned character string.

Note:
A box is internally represented by its lower right and upper left corner whereas it is described in the file format as its lower left corner and its width and height.

Definition at line 378 of file o_box_basic.c.

void o_box_translate_world ( TOPLEVEL toplevel,
int  dx,
int  dy,
OBJECT object 
)
Function Description
This function applies a translation of (x1,y1) to the box described by *object. x1 and y1 are in world unit.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]dxx distance to move.
[in]dyy distance to move.
[in,out]objectBOX OBJECT to translate.

Definition at line 442 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_rotate_world ( TOPLEVEL toplevel,
int  world_centerx,
int  world_centery,
int  angle,
OBJECT object 
)
Function Description
The function o_box_rotate_world() rotate the box described by *object around the (world_centerx, world_centery) point by angle degrees. The center of rotation is in world unit.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]world_centerxRotation center x coordinate in WORLD units.
[in]world_centeryRotation center y coordinate in WORLD units.
[in]angleRotation angle in degrees (See note below).
[in,out]objectBOX OBJECT to rotate.

Note:
Only 90 degree multiple and positive angles are allowed.
The center of rotation (world_centerx, world_centery) is translated to the origin. The rotation of the upper left and lower right corner are then performed. Finally, the rotated box is translated back to its previous location.

Definition at line 468 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_mirror_world ( TOPLEVEL toplevel,
int  world_centerx,
int  world_centery,
OBJECT object 
)
Function Description
This function mirrors the box from the point (world_centerx,world_centery) in world unit.

The box is first translated to the origin, then mirrored and finally translated back at its previous position.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]world_centerxOrigin x coordinate in WORLD units.
[in]world_centeryOrigin y coordinate in WORLD units.
[in,out]objectBOX OBJECT to mirror.

Definition at line 533 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_recalc ( TOPLEVEL toplevel,
OBJECT o_current 
)
Function Description
This function recalculates the box coordinates and its bounding are recalculated as well.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in,out]o_currentBOX OBJECT to be recalculated.

Definition at line 577 of file o_box_basic.c.

Here is the call graph for this function:

void world_get_box_bounds ( TOPLEVEL toplevel,
OBJECT object,
int *  left,
int *  top,
int *  right,
int *  bottom 
)
Function Description
This function sets the left, top, right and bottom parameters to the boundings of the box object described in *box in world units.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]objectBOX OBJECT to read coordinates from.
[out]leftLeft box coordinate in WORLD units.
[out]topTop box coordinate in WORLD units.
[out]rightRight box coordinate in WORLD units.
[out]bottomBottom box coordinate in WORLD units.

Definition at line 607 of file o_box_basic.c.

gboolean o_box_get_position ( TOPLEVEL toplevel,
gint *  x,
gint *  y,
OBJECT object 
)
Function Description
This function gets the position of the bottom left point of a box object.
Parameters:
[in]toplevelThe toplevel environment.
[out]xpointer to the x-position
[out]ypointer to the y-position
[in]objectThe object to get the position.
Returns:
TRUE if successfully determined the position, FALSE otherwise

Definition at line 636 of file o_box_basic.c.

void o_box_print ( TOPLEVEL toplevel,
FILE *  fp,
OBJECT o_current,
int  origin_x,
int  origin_y 
)
Function Description
This function prints the box described by the o_current parameter to a Postscript document. It takes into account its line type and fill type. The Postscript document is descibed by the file pointer fp.

The validity of the o_current parameter is verified : a null pointer causes an error message and a return.

The description of the box is extracted from the o_current parameter : the coordinates of the box - upper left corner and width and height of the box -, its line type, its fill type.

The outline and the inside of the box are successively handled by two differend sets of functions.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]o_currentBOX OBJECT to write to document.
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Note:
Depending on the type of the line for this particular box, the appropriate function is chosen among o_box_print_solid(), o_box_print_dotted(), o_box_print_dashed(), o_box_print_center() and o_box_print_phantom().

The needed parameters for each of these type is extracted from the o_current object. Depending on the type, unused parameters are set to -1.

In the eventuality of a length and/or space null, the line is printed solid to avoid and endless loop produced by other functions in such a case.

Note:
If the filling type of the box is not HOLLOW, the appropriate function is chosen among o_box_print_filled(), o_box_print_mesh() and o_box_print_hatch(). The corresponding parameters are extracted from the o_current object and corrected afterward.

The case where pitch1 and pitch2 are null or negative is avoided as it leads to an endless loop in most of the called functions. In such a case, the box is printed filled. Unused parameters for each of these functions are set to -1 or any passive value.

Definition at line 668 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_print_solid ( TOPLEVEL toplevel,
FILE *  fp,
int  x,
int  y,
int  width,
int  height,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints the outline of a box when a solid line type is required. The box is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters. The postscript file is defined by the file pointer fp. The parameters length and space are ignored.

It uses the function o_line_print_solid() to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]xUpper x coordinate of BOX.
[in]yUpper y coordinate of BOX.
[in]widthWidth of BOX.
[in]heightHeight of BOX.
[in]colorBOX color.
[in]line_widthBOX Line width.
[in]lengthDashed line length.
[in]spaceAmount of space between dashes.
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Definition at line 848 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_print_dotted ( TOPLEVEL toplevel,
FILE *  fp,
int  x,
int  y,
int  width,
int  height,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints the outline of a box when a dotted line type is required. The box is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters. The postscript file is defined by the file pointer fp. The parameters length is ignored.

It uses the function o_line_print_dotted() to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]xUpper x coordinate of BOX.
[in]yUpper y coordinate of BOX.
[in]widthWidth of BOX.
[in]heightHeight of BOX.
[in]colorBOX color.
[in]line_widthBOX Line width.
[in]lengthDashed line length.
[in]spaceAmount of space between dashes.
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Definition at line 911 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_print_dashed ( TOPLEVEL toplevel,
FILE *  fp,
int  x,
int  y,
int  width,
int  height,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints the outline of a box when a dashed line type is required. The box is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters. The postscript file is defined by the file pointer fp.

It uses the function o_line_print_dashed() to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]xUpper x coordinate of BOX.
[in]yUpper y coordinate of BOX.
[in]widthWidth of BOX.
[in]heightHeight of BOX.
[in]colorBOX color.
[in]line_widthBOX Line width.
[in]lengthDashed line length.
[in]spaceAmount of space between dashes.
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Definition at line 973 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_print_center ( TOPLEVEL toplevel,
FILE *  fp,
int  x,
int  y,
int  width,
int  height,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints the outline of a box when a centered line type is required. The box is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters. The postscript file is defined by the file pointer fp.

It uses the function o_line_print_center() to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]xUpper x coordinate of BOX.
[in]yUpper y coordinate of BOX.
[in]widthWidth of BOX.
[in]heightHeight of BOX.
[in]colorBOX color.
[in]line_widthBOX Line width.
[in]lengthDashed line length.
[in]spaceAmount of space between dashes.
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Definition at line 1036 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_print_phantom ( TOPLEVEL toplevel,
FILE *  fp,
int  x,
int  y,
int  width,
int  height,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints the outline of a box when a phantom line type is required. The box is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters. The postscript file is defined by the file pointer fp.

It uses the function o_line_print_phantom() to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]xUpper x coordinate of BOX.
[in]yUpper y coordinate of BOX.
[in]widthWidth of BOX.
[in]heightHeight of BOX.
[in]colorBOX color.
[in]line_widthBOX Line width.
[in]lengthDashed line length.
[in]spaceAmount of space between dashes.
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Definition at line 1098 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_print_filled ( TOPLEVEL toplevel,
FILE *  fp,
int  x,
int  y,
int  width,
int  height,
int  color,
int  fill_width,
int  angle1,
int  pitch1,
int  angle2,
int  pitch2,
int  origin_x,
int  origin_y 
)
Function Description
The function prints a filled box with a solid pattern. No outline is printed. The box is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters. The postscript file is defined by the file pointer fp. fill_width, angle1 and pitch1, angle2 and pitch2 parameters are ignored in this functions but kept for compatibility with other fill functions.

It uses the fbox postscript function defined in the prolog to specify a filled box.

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]xUpper x coordinate of BOX.
[in]yUpper y coordinate of BOX.
[in]widthWidth of BOX.
[in]heightHeight of BOX.
[in]colorBOX color.
[in]fill_widthBOX fill width. (unused).
[in]angle1(unused).
[in]pitch1(unused).
[in]angle2(unused).
[in]pitch2(unused).
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Definition at line 1166 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_print_mesh ( TOPLEVEL toplevel,
FILE *  fp,
int  x,
int  y,
int  width,
int  height,
int  color,
int  fill_width,
int  angle1,
int  pitch1,
int  angle2,
int  pitch2,
int  origin_x,
int  origin_y 
)
Function Description
This function prints a meshed box. No outline is printed. The box is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters. The postscript file is defined by the file pointer fp.

The inside mesh is achieved by two successive call to the o_box_print_hatch() function, given angle1 and pitch1 the first time and angle2 and pitch2 the second time.

Negative or null values for pitch1 and/or pitch2 are not allowed as it leads to an endless loop in o_box_print_hatch().

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]xUpper x coordinate of BOX.
[in]yUpper y coordinate of BOX.
[in]widthWidth of BOX.
[in]heightHeight of BOX.
[in]colorBOX color.
[in]fill_widthBOX fill width.
[in]angle11st angle for mesh pattern.
[in]pitch11st pitch for mesh pattern.
[in]angle22nd angle for mesh pattern.
[in]pitch22nd pitch for mesh pattern.
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Definition at line 1218 of file o_box_basic.c.

Here is the call graph for this function:

void o_box_print_hatch ( TOPLEVEL toplevel,
FILE *  fp,
int  x,
int  y,
int  width,
int  height,
int  color,
int  fill_width,
int  angle1,
int  pitch1,
int  angle2,
int  pitch2,
int  origin_x,
int  origin_y 
)
Function Description
The function prints a hatched box. No outline is printed. The box is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters. The postscript file is defined by the file pointer fp. fill_width, angle1, pitch1 parameters define the way the box has to be hatched. angle2 and pitch2 parameters are unused but kept for compatibility with other fill functions.

Negative or null values for pitch1 are not allowed as it leads to an endless loop.

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]xUpper x coordinate of BOX.
[in]yUpper y coordinate of BOX.
[in]widthWidth of BOX.
[in]heightHeight of BOX.
[in]colorBOX color.
[in]fill_widthBOX fill width.
[in]angle1Angle of hatch pattern.
[in]pitch1Pitch of hatch pattern.
[in]angle2(unused).
[in]pitch2(unused).
[in]origin_xPage x coordinate to place BOX OBJECT.
[in]origin_yPage y coordinate to place BOX OBJECT.

Definition at line 1273 of file o_box_basic.c.

Here is the call graph for this function:

double o_box_shortest_distance ( OBJECT object,
int  x,
int  y,
int  force_solid 
)
Parameters:
[in]objectThe box OBJECT.
[in]xThe x coordinate of the given point.
[in]yThe y coordinate of the given point.
[in]force_solidIf true, force treating the object as solid.
Returns:
The shortest distance from the object to the point. With an invalid parameter, this function returns G_MAXDOUBLE.

Definition at line 1325 of file o_box_basic.c.

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines