Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Functions
manipulate.cc File Reference
#include "internal.h"
#include <assert.h>
#include <algorithm>

Go to the source code of this file.

Functions

xorn_object_t xorn_add_object (xorn_revision_t rev, xorn_obtype_t type, void const *data)
 Add a new object to a transient revision. More...
 
int xorn_set_object_data (xorn_revision_t rev, xorn_object_t ob, xorn_obtype_t type, void const *data)
 Set an object in a transient revision to the given object type and data. More...
 
int xorn_relocate_object (xorn_revision_t rev, xorn_object_t ob, xorn_object_t attach_to, xorn_object_t insert_before)
 Change the location of an object in the object structure of a transient revision. More...
 
void xorn_delete_object (xorn_revision_t rev, xorn_object_t ob)
 Delete an object from a transient revision. More...
 
void xorn_delete_selected_objects (xorn_revision_t rev, xorn_selection_t sel)
 Delete some objects from a transient revision. More...
 
xorn_object_t xorn_copy_object (xorn_revision_t dest, xorn_revision_t src, xorn_object_t ob)
 Copy an object to a transient revision. More...
 
xorn_selection_t xorn_copy_objects (xorn_revision_t dest, xorn_revision_t src, xorn_selection_t sel)
 Copy some objects to a transient revision. More...
 

Function Documentation

xorn_object_t xorn_add_object ( xorn_revision_t  rev,
xorn_obtype_t  type,
void const *  data 
)

Add a new object to a transient revision.

The object is appended to the end of the object list.

data must point to a data structure matching the object type indicated by type (e.g., if type is xornsch_obtype_net, then data must point to a xornsch_net structure). The data structure (including referenced strings) will not be accessed after this function has returned.

Returns
Returns the newly created object. If the revision isn't transient, type is not a valid Xorn object type, data is NULL, or there is not enough memory, returns NULL.

Example:

struct xornsch_line line_data;
memset(&line_data, 0, sizeof line_data);
line_data.pos.x = 0;
line_data.pos.y = 0;
line_data.size.x = 100;
line_data.size.y = 100;
line_data.line.width = 1;
ob = xorn_add_object(rev, xornsch_obtype_line, &line_data);
if (ob == NULL)
/* handle error */;
Note
Try not to use this function. There are type-specific functions available (xornsch_add_net etc.) which offer the same functionality but are type-safe.

Definition at line 60 of file manipulate.cc.

xorn_object_t xorn_copy_object ( xorn_revision_t  dest,
xorn_revision_t  src,
xorn_object_t  ob 
)

Copy an object to a transient revision.

Any objects attached to ob are copied as well, their copies being attached to the copy of ob, which is appended to the end of the object list.

Parameters
destDestination revision (must be transient)
srcSource revision (does not need to be transient)
obObject in the source revision which should be copied
Returns
Returns the copy of ob. If the destination revision isn't transient, ob doesn't exist in the source revision, or there is not enough memory, returns NULL.

Definition at line 392 of file manipulate.cc.

xorn_selection_t xorn_copy_objects ( xorn_revision_t  dest,
xorn_revision_t  src,
xorn_selection_t  sel 
)

Copy some objects to a transient revision.

Any objects attached to the objects are copied as well and attached to the corresponding new object. The copied objects are appended to the end of the object list in an unspecified order.

Parameters
destDestination revision (must be transient)
srcSource revision (does not need to be transient)
selObjects in the source revision which should be copied
Returns
Returns a selection containing the copied objects, excluding attached objects. If the destination revision isn't transient or there is not enough memory, returns NULL.
Note
You should free the returned selection using xorn_free_selection once it isn't needed any more.

Definition at line 433 of file manipulate.cc.

void xorn_delete_object ( xorn_revision_t  rev,
xorn_object_t  ob 
)

Delete an object from a transient revision.

Any objects attached to ob are deleted as well.

The deleted object(s) stay valid and can later be re-added using xorn_set_object_data or its type-safe equivalents.

If the revision isn't transient or the object doesn't exist in the revision, nothing is changed.

Definition at line 301 of file manipulate.cc.

void xorn_delete_selected_objects ( xorn_revision_t  rev,
xorn_selection_t  sel 
)

Delete some objects from a transient revision.

Any objects attached to a deleted object are deleted as well.

The deleted objects stay valid and can later be re-added using xorn_set_object_data or its type-safe equivalents.

Objects that don't exist in the revision are ignored. If the revision isn't transient, nothing is changed.

Definition at line 328 of file manipulate.cc.

int xorn_relocate_object ( xorn_revision_t  rev,
xorn_object_t  ob,
xorn_object_t  attach_to,
xorn_object_t  insert_before 
)

Change the location of an object in the object structure of a transient revision.

This function performs two distinct operations:

  1. Change the order in which an object is drawn and written to files as compared to its sibling objects.
  2. Attach a schematic text object to a schematic net or component object. As far as this library is concerned, this will cause the text to be copied and deleted along with the net or component.

If attach_to is NULL, the object becomes un-attached. If ob and insert_before are identical and ob is already attached to attach_to, the revision is left unchanged.

Parameters
revRevision to modify (must be transient)
obThe object which should be reordered and/or attached (must be xornsch_text if attach_to is not NULL)
attach_toThe object to which ob should be attached (must be xornsch_net or xornsch_component, or NULL)
insert_beforeAn object already attached to attach_to before which ob should be inserted, or NULL to append it at the end.
Returns
Returns 0 on success. Returns -1 if
  • the revision isn't transient,
  • ob or (if not NULL) attach_to or insert_before don't exist in the revision,
  • attach_to is not NULL and
    • ob is not a schematic text or
    • attach_to is not a schematic net or schematic component,
  • insert_before is not NULL and not attached to attach_to, or
  • there is not enough memory.

Example:

struct xornsch_text text_data;
memset(&text_data, 0, sizeof text_data);
text_data.text.s = "refdes=R1";
text_data.text.len = strlen(text_data.text.s);
ob = xornsch_add_text(rev, &text_data);
if (ob == NULL)
/* handle error */;
if (xorn_relocate_object(rev, ob, component, NULL) == -1)
/* handle error */;

Definition at line 219 of file manipulate.cc.

int xorn_set_object_data ( xorn_revision_t  rev,
xorn_object_t  ob,
xorn_obtype_t  type,
void const *  data 
)

Set an object in a transient revision to the given object type and data.

If the object does not exist in the revision, it is created and appended to the end of the object list.

Parameters
revRevision to be changed (must be transient)
obAn object which has previously been returned by a Xorn function for either this revision, one of its ancestors, or a revision which has a common ancestor with it.
typeNew object type (may be different from previous one, but must be xornsch_obtype_net or xornsch_obtype_component if there are objects attached to ob, and must be xornsch_obtype_text if ob itself is attached to an object)
dataPointer to a data structure matching the object type indicated by type (e.g., if type is xornsch_obtype_net, a pointer to a xornsch_net structure). The data structure (including referenced strings) will not be accessed after this function has returned.
Returns
Returns 0 if the object has been changed. Returns -1 if
  • the revision isn't transient,
  • type is not a valid Xorn object type,
  • data is NULL,
  • ob is attached to an object but type doesn't permit attaching the object,
  • there are objects attached to ob but type doesn't permit attaching objects, or
  • there is not enough memory.

Example:

struct xornsch_line line_data;
memset(&line_data, 0, sizeof line_data);
line_data.pos.x = 0;
line_data.pos.y = 0;
line_data.size.x = 100;
line_data.size.y = 100;
line_data.line.width = 1;
if (xorn_set_object_data(rev, ob, xornsch_obtype_line, &line_data) == -1)
/* handle error */;
Note
Try not to use this function. There are type-specific functions available (xornsch_set_net_data etc.) which offer the same functionality but are type-safe.

Definition at line 131 of file manipulate.cc.