libgeda

o_line_basic.c File Reference

functions for the line object More...

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

Go to the source code of this file.

Functions

OBJECTo_line_new (TOPLEVEL *toplevel, char type, int color, int x1, int y1, int x2, int y2)
 Create and add line OBJECT to list.
OBJECTo_line_copy (TOPLEVEL *toplevel, OBJECT *o_current)
 Create a copy of a line.
void o_line_modify (TOPLEVEL *toplevel, OBJECT *object, int x, int y, int whichone)
 Modify the description of a line OBJECT.
OBJECTo_line_read (TOPLEVEL *toplevel, const char buf[], unsigned int release_ver, unsigned int fileformat_ver, GError **err)
 Create line OBJECT from character string.
char * o_line_save (TOPLEVEL *toplevel, OBJECT *object)
 Create a character string representation of a line OBJECT.
void o_line_translate_world (TOPLEVEL *toplevel, int dx, int dy, OBJECT *object)
 Translate a line position in WORLD coordinates by a delta.
void o_line_rotate_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, int angle, OBJECT *object)
 Rotate Line OBJECT using WORLD coordinates.
void o_line_mirror_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, OBJECT *object)
 Mirror a line using WORLD coordinates.
void o_line_recalc (TOPLEVEL *toplevel, OBJECT *o_current)
 Recalculate line coordinates in SCREEN units.
void world_get_line_bounds (TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom)
 Get line bounding rectangle in WORLD coordinates.
gboolean o_line_get_position (TOPLEVEL *toplevel, gint *x, gint *y, OBJECT *object)
 get the position of the first line point
void o_line_print (TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current, int origin_x, int origin_y)
 Print line to Postscript document.
void o_line_print_solid (TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, int y2, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print a solid line to Postscript document.
void o_line_print_dotted (TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, int y2, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print a dotted line to Postscript document.
void o_line_print_dashed (TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, int y2, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print a dashed line to Postscript document.
void o_line_print_center (TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, int y2, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print a centered line type line to Postscript document.
void o_line_print_phantom (TOPLEVEL *toplevel, FILE *fp, int x1, int y1, int x2, int y2, int color, int line_width, int length, int space, int origin_x, int origin_y)
 Print a phantom line type line to Postscript document.
void o_line_scale_world (TOPLEVEL *toplevel, int x_scale, int y_scale, OBJECT *object)
double o_line_length (OBJECT *object)
 calculate the lenght of a line object
double o_line_shortest_distance (OBJECT *object, int x, int y, int force_solid)
 Calculates the distance between the given point and the closest point on the given line segment.

Detailed Description

Definition in file o_line_basic.c.


Function Documentation

OBJECT* o_line_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 line.

The line is described by its two ends - x1,y1 and x2,y2. The type parameter must be equal to OBJ_LINE. The color parameter 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 line 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]typeMust be OBJ_LINE.
[in]colorCircle line color.
[in]x1Upper x coordinate.
[in]y1Upper y coordinate.
[in]x2Lower x coordinate.
[in]y2Lower y coordinate.
Returns:
A pointer to the new end of the object list.

Definition at line 64 of file o_line_basic.c.

Here is the call graph for this function:

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

Definition at line 103 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_modify ( TOPLEVEL toplevel,
OBJECT object,
int  x,
int  y,
int  whichone 
)
Function Description
This function modifies the coordinates of one of the two ends of the line described by *object. The new coordinates of this end, identified by whichone, are given by x and y in world unit.

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

Parameters:
[in]toplevelThe TOPLEVEL object.
[in,out]objectLine OBJECT to modify.
[in]xNew x coordinate.
[in]yNew y coordinate.
[in]whichoneWhich line parameter to modify.

whichone can have the following values:

*
LINE_END1
*
LINE_END2

Definition at line 162 of file o_line_basic.c.

Here is the call graph for this function:

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

The function returns a pointer on the new last element, that is the added line object.

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

*
the file format used until 20010704 release.
*
the file format used for the releases after 20010704.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]bufCharacter string with line description.
[in]release_verlibgeda release version number.
[in]fileformat_verlibgeda file format version number.
Returns:
A pointer to the new line object, or NULL on error.

Definition at line 209 of file o_line_basic.c.

Here is the call graph for this function:

char* o_line_save ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
The 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 - filling is irrelevant here.
Parameters:
[in]toplevela TOPLEVEL structure.
[in]objectLine OBJECT to create string from.
Returns:
A pointer to the line OBJECT character string.
Note:
Caller must g_free returned character string.

Definition at line 302 of file o_line_basic.c.

void o_line_translate_world ( TOPLEVEL toplevel,
int  dx,
int  dy,
OBJECT object 
)
Function Description
This function applies a translation of (x1,y1) to the line 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]objectLine OBJECT to translate.

Definition at line 341 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_rotate_world ( TOPLEVEL toplevel,
int  world_centerx,
int  world_centery,
int  angle,
OBJECT object 
)
Function Description
This function rotates the line described by *object around the (world_centerx,world_centery) point by angle degrees. The center of rotation is in world units.
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]objectLine OBJECT to rotate.

Definition at line 367 of file o_line_basic.c.

Here is the call graph for this function:

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

The line if 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]objectLine OBJECT to mirror.

Definition at line 422 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_recalc ( TOPLEVEL toplevel,
OBJECT o_current 
)
Function Description
This function recalculate the bounding box of the o_current
Parameters:
[in]toplevelThe TOPLEVEL object.
[in,out]o_currentLine OBJECT to be recalculated.

Definition at line 444 of file o_line_basic.c.

Here is the call graph for this function:

void world_get_line_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 line object described in *line in world units.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]objectLine OBJECT to read coordinates from.
[out]leftLeft line coordinate in WORLD units.
[out]topTop line coordinate in WORLD units.
[out]rightRight line coordinate in WORLD units.
[out]bottomBottom line coordinate in WORLD units.

Definition at line 475 of file o_line_basic.c.

gboolean o_line_get_position ( TOPLEVEL toplevel,
gint *  x,
gint *  y,
OBJECT object 
)
Function Description
This function gets the position of the first point of a line 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 504 of file o_line_basic.c.

void o_line_print ( TOPLEVEL toplevel,
FILE *  fp,
OBJECT o_current,
int  origin_x,
int  origin_y 
)
Function Description
This function prints the line described by the o_current parameter to a Postscript document. The Postscript document is described by the fp file pointer.

Parameters of the line are extracted from object pointed by o_current.

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

Definition at line 528 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_print_solid ( TOPLEVEL toplevel,
FILE *  fp,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints a line when a solid line type is required. The line is defined by the coordinates of its two ends in (x1,y1) and (x2,y2). The Postscript document is defined by the file pointer fp. The parameters length and space are ignored whereas line_width specifies the width of the printed line.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]x1Upper x coordinate.
[in]y1Upper y coordinate.
[in]x2Lower x coordinate.
[in]y2Lower y coordinate.
[in]colorLine color.
[in]line_widthWidth of line.
[in]length(unused).
[in]space(unused).
[in]origin_xPage x coordinate to place line OBJECT.
[in]origin_yPage y coordinate to place line OBJECT.

Definition at line 637 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_print_dotted ( TOPLEVEL toplevel,
FILE *  fp,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints a line when a dotted line type is required. The line is defined by the coordinates of its two ends in (x1,y1) and (x2,y2). The Postscript document is defined by the file pointer fp. The parameter length is ignored whereas line_width specifies the diameter of the dots and space the distance between two dots.

A negative value for space leads to an endless loop.

All dimensions are in mils.

The function sets the color in which the line will be printed with.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]x1Upper x coordinate.
[in]y1Upper y coordinate.
[in]x2Lower x coordinate.
[in]y2Lower y coordinate.
[in]colorLine color.
[in]line_widthWidth of line.
[in]length(unused).
[in]spaceSpace between dots.
[in]origin_xPage x coordinate to place line OBJECT.
[in]origin_yPage y coordinate to place line OBJECT.

Definition at line 678 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_print_dashed ( TOPLEVEL toplevel,
FILE *  fp,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints a line when a dashed line type is required. The line is defined by the coordinates of its two ends in (x1,y1) and (x2,y2). The postscript file is defined by the file pointer fp.

A negative value for space or length leads to an endless loop.

All dimensions are in mils.

The function sets the color in which the line will be printed and the width of the line - that is the width of the dashes.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]x1Upper x coordinate.
[in]y1Upper y coordinate.
[in]x2Lower x coordinate.
[in]y2Lower y coordinate.
[in]colorLine color.
[in]line_widthWidth of line.
[in]lengthLength of a dash.
[in]spaceSpace between dashes.
[in]origin_xPage x coordinate to place line OBJECT.
[in]origin_yPage y coordinate to place line OBJECT.

Definition at line 759 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_print_center ( TOPLEVEL toplevel,
FILE *  fp,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints a line when a centered line type is required. The line is defined by the coordinates of its two ends in (x1,y1) and (x2,y2). The Postscript document is defined by the file pointer fp.

A negative value for space or length leads to an endless loop.

All dimensions are in mils.

The function sets the color in which the line will be printed and the width of the line - that is the width of the dashes and the diameter of the dots.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]x1Upper x coordinate.
[in]y1Upper y coordinate.
[in]x2Lower x coordinate.
[in]y2Lower y coordinate.
[in]colorLine color.
[in]line_widthWidth of line.
[in]lengthLength of a dash.
[in]spaceSpace between dashes.
[in]origin_xPage x coordinate to place line OBJECT.
[in]origin_yPage y coordinate to place line OBJECT.

Definition at line 862 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_print_phantom ( TOPLEVEL toplevel,
FILE *  fp,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  line_width,
int  length,
int  space,
int  origin_x,
int  origin_y 
)
Function Description
This function prints a line when a phantom line type is required. The line is defined by the coordinates of its two ends in (x1,y1) and (x2,y2). The Postscript document is defined by the file pointer fp.

A negative value for space or length leads to an endless loop.

All dimensions are in mils.

The function sets the color in which the line will be printed and the width of the line - that is the width of the dashes and the diameter of the dots.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]x1Upper x coordinate.
[in]y1Upper y coordinate.
[in]x2Lower x coordinate.
[in]y2Lower y coordinate.
[in]colorLine color.
[in]line_widthWidth of line.
[in]lengthLength of a dash.
[in]spaceSpace between dashes.
[in]origin_xPage x coordinate to place line OBJECT.
[in]origin_yPage y coordinate to place line OBJECT.

Definition at line 994 of file o_line_basic.c.

Here is the call graph for this function:

void o_line_scale_world ( TOPLEVEL toplevel,
int  x_scale,
int  y_scale,
OBJECT object 
)
Function Description
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]x_scale
[in]y_scale
[in]object

Definition at line 1131 of file o_line_basic.c.

Here is the call graph for this function:

double o_line_length ( OBJECT object)
Function Description
This function calculates the length of a line object
Parameters:
[in]objecta line OBJECT
Returns:
The length of the line

Definition at line 1153 of file o_line_basic.c.

double o_line_shortest_distance ( OBJECT object,
int  x,
int  y,
int  force_solid 
)

If the closest point on the line resides beyond the line segment's end point, this function returns the distance from the given point to the closest end point.

If the line represents a single point (the endpoints are the same), this function calcualtes the distance to that point.

Parameters:
[in]objectThe line 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 1187 of file o_line_basic.c.

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines