[dia] format: update the GRAFCET objects, add missing case to switches
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] format: update the GRAFCET objects, add missing case to switches
- Date: Wed, 29 Jan 2020 00:43:02 +0000 (UTC)
commit d2256c5096c14050a442f4a84fdda3f302424ff0
Author: Zander Brown <zbrown gnome org>
Date: Wed Jan 29 00:31:15 2020 +0000
format: update the GRAFCET objects, add missing case to switches
objects/GRAFCET/condition.c | 236 ++++++++++++++---------
objects/GRAFCET/grafcet.c | 23 +--
objects/GRAFCET/grafcet.h | 7 +-
objects/GRAFCET/step.c | 418 ++++++++++++++++++++++++-----------------
objects/GRAFCET/transition.c | 279 +++++++++++++++------------
objects/GRAFCET/vergent.c | 438 ++++++++++++++++++++++++-------------------
6 files changed, 810 insertions(+), 591 deletions(-)
---
diff --git a/objects/GRAFCET/condition.c b/objects/GRAFCET/condition.c
index 3d7e19d9..33cc036c 100644
--- a/objects/GRAFCET/condition.c
+++ b/objects/GRAFCET/condition.c
@@ -48,6 +48,7 @@
#define CONDITION_ARROW_SIZE 0.0 /* XXX The norm says there's no arrow head.
a lot of people do put it, though. */
+
typedef struct _Condition {
Connection connection;
@@ -62,42 +63,51 @@ typedef struct _Condition {
DiaRectangle labelbb;
} Condition;
-static ObjectChange* condition_move_handle(Condition *condition, Handle *handle,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason, ModifierKeys modifiers);
-static ObjectChange* condition_move(Condition *condition, Point *to);
-static void condition_select(Condition *condition, Point *clicked_point,
- DiaRenderer *interactive_renderer);
-static void condition_draw(Condition *condition, DiaRenderer *renderer);
-static DiaObject *condition_create(Point *startpoint,
- void *user_data,
- Handle **handle1,
- Handle **handle2);
-static real condition_distance_from(Condition *condition, Point *point);
-static void condition_update_data(Condition *condition);
-static void condition_destroy(Condition *condition);
-static DiaObject *condition_load(ObjectNode obj_node, int version,
- DiaContext *context);
-static PropDescription *condition_describe_props(Condition *condition);
-static void condition_get_props(Condition *condition,
- GPtrArray *props);
-static void condition_set_props(Condition *condition,
- GPtrArray *props);
-
-static ObjectTypeOps condition_type_ops =
-{
- (CreateFunc)condition_create, /* create */
- (LoadFunc) condition_load, /* load */
- (SaveFunc) object_save_using_properties, /* save */
+
+static ObjectChange *condition_move_handle (Condition *condition,
+ Handle *handle,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers);
+static ObjectChange *condition_move (Condition *condition,
+ Point *to);
+static void condition_select (Condition *condition,
+ Point *clicked_point,
+ DiaRenderer *renderer);
+static void condition_draw (Condition *condition,
+ DiaRenderer *renderer);
+static DiaObject *condition_create (Point *startpoint,
+ void *user_data,
+ Handle **handle1,
+ Handle **handle2);
+static real condition_distance_from (Condition *condition,
+ Point *point);
+static void condition_update_data (Condition *condition);
+static void condition_destroy (Condition *condition);
+static DiaObject *condition_load (ObjectNode obj_node,
+ int version,
+ DiaContext *context);
+static PropDescription *condition_describe_props (Condition *condition);
+static void condition_get_props (Condition *condition,
+ GPtrArray *props);
+static void condition_set_props (Condition *condition,
+ GPtrArray *props);
+
+
+static ObjectTypeOps condition_type_ops = {
+ (CreateFunc) condition_create, /* create */
+ (LoadFunc) condition_load, /* load */
+ (SaveFunc) object_save_using_properties, /* save */
(GetDefaultsFunc) NULL,
(ApplyDefaultsFunc) NULL
};
-DiaObjectType condition_type =
-{
- "GRAFCET - Condition", /* name */
- 0, /* version */
- condition_xpm, /* pixmap */
+
+DiaObjectType condition_type = {
+ "GRAFCET - Condition", /* name */
+ 0, /* version */
+ condition_xpm, /* pixmap */
&condition_type_ops /* ops */
};
@@ -135,33 +145,37 @@ static PropDescription condition_props[] = {
PROP_DESC_END
};
+
static PropDescription *
-condition_describe_props(Condition *condition)
+condition_describe_props (Condition *condition)
{
if (condition_props[0].quark == 0) {
- prop_desc_list_calculate_quarks(condition_props);
+ prop_desc_list_calculate_quarks (condition_props);
}
return condition_props;
}
+
static PropOffset condition_offsets[] = {
CONNECTION_COMMON_PROPERTIES_OFFSETS,
- {"condition",PROP_TYPE_STRING,offsetof(Condition,cond_value)},
- {"cond_font",PROP_TYPE_FONT,offsetof(Condition,cond_font)},
- {"cond_fontheight",PROP_TYPE_REAL,offsetof(Condition,cond_fontheight)},
- {"cond_color",PROP_TYPE_COLOUR,offsetof(Condition,cond_color)},
+ {"condition", PROP_TYPE_STRING, offsetof (Condition, cond_value)},
+ {"cond_font", PROP_TYPE_FONT, offsetof (Condition, cond_font)},
+ {"cond_fontheight", PROP_TYPE_REAL, offsetof (Condition, cond_fontheight)},
+ {"cond_color", PROP_TYPE_COLOUR, offsetof (Condition, cond_color)},
{ NULL,0,0 }
};
+
static void
-condition_get_props(Condition *condition, GPtrArray *props)
+condition_get_props (Condition *condition, GPtrArray *props)
{
- object_get_props_from_offsets(&condition->connection.object,
- condition_offsets,props);
+ object_get_props_from_offsets (DIA_OBJECT (condition),
+ condition_offsets,props);
}
+
static void
-condition_set_props(Condition *condition, GPtrArray *props)
+condition_set_props (Condition *condition, GPtrArray *props)
{
object_set_props_from_offsets (&condition->connection.object,
condition_offsets,props);
@@ -174,73 +188,115 @@ condition_set_props(Condition *condition, GPtrArray *props)
condition_update_data (condition);
}
+
static real
-condition_distance_from(Condition *condition, Point *point)
+condition_distance_from (Condition *condition, Point *point)
{
Connection *conn = &condition->connection;
real dist;
- dist = distance_rectangle_point(&condition->labelbb,point);
- dist = MIN(dist,distance_line_point(&conn->endpoints[0],
- &conn->endpoints[1],
- CONDITION_LINE_WIDTH,point));
+ dist = distance_rectangle_point (&condition->labelbb, point);
+ dist = MIN (dist,
+ distance_line_point (&conn->endpoints[0],
+ &conn->endpoints[1],
+ CONDITION_LINE_WIDTH,
+ point));
return dist;
}
+
static void
-condition_select(Condition *condition, Point *clicked_point,
- DiaRenderer *interactive_renderer)
+condition_select (Condition *condition,
+ Point *clicked_point,
+ DiaRenderer *interactive_renderer)
{
- condition_update_data(condition);
+ condition_update_data (condition);
}
+
static ObjectChange*
-condition_move_handle(Condition *condition, Handle *handle,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason, ModifierKeys modifiers)
+condition_move_handle (Condition *condition,
+ Handle *handle,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers)
{
Point s,e,v;
int horiz;
- g_assert(condition!=NULL);
- g_assert(handle!=NULL);
- g_assert(to!=NULL);
+ g_return_val_if_fail (condition!= NULL, NULL);
+ g_return_val_if_fail (handle != NULL, NULL);
+ g_return_val_if_fail (to != NULL, NULL);
switch (handle->id) {
- case HANDLE_MOVE_STARTPOINT:
- point_copy(&s,to);
- point_copy(&e,&condition->connection.endpoints[1]);
- point_copy(&v,&e);
- point_sub(&v,&s);
-
- horiz = ABS(v.x) > ABS(v.y);
- if (horiz) {
- v.y = 0.0;
- } else {
- v.x = 0.0;
- }
-
- point_copy(&s,&e);
- point_sub(&s,&v);
- /* XXX: fix e to make it look good (what's good ?) V is a good hint ? */
- connection_move_handle(&condition->connection, HANDLE_MOVE_STARTPOINT,
- &s, cp, reason, modifiers);
- break;
- case HANDLE_MOVE_ENDPOINT:
- point_copy(&s,&condition->connection.endpoints[0]);
- point_copy(&e,&condition->connection.endpoints[1]);
- point_copy(&v,&e);
- point_sub(&v,&s);
- connection_move_handle(&condition->connection, HANDLE_MOVE_ENDPOINT,
- to, cp, reason, modifiers);
- point_copy(&s,to);
- point_sub(&s,&v);
- connection_move_handle(&condition->connection, HANDLE_MOVE_STARTPOINT,
- &s, NULL, reason, 0);
- break;
- default:
- g_assert_not_reached();
+ case HANDLE_MOVE_STARTPOINT:
+ point_copy (&s, to);
+ point_copy (&e, &condition->connection.endpoints[1]);
+ point_copy (&v, &e);
+ point_sub (&v, &s);
+
+ horiz = ABS (v.x) > ABS (v.y);
+ if (horiz) {
+ v.y = 0.0;
+ } else {
+ v.x = 0.0;
+ }
+
+ point_copy (&s,&e);
+ point_sub (&s,&v);
+
+ /* XXX: fix e to make it look good (what's good ?) V is a good hint ? */
+ connection_move_handle (&condition->connection,
+ HANDLE_MOVE_STARTPOINT,
+ &s,
+ cp,
+ reason,
+ modifiers);
+
+ break;
+ case HANDLE_MOVE_ENDPOINT:
+ point_copy (&s, &condition->connection.endpoints[0]);
+ point_copy (&e, &condition->connection.endpoints[1]);
+ point_copy (&v, &e);
+ point_sub (&v, &s);
+ connection_move_handle (&condition->connection,
+ HANDLE_MOVE_ENDPOINT,
+ to,
+ cp,
+ reason,
+ modifiers);
+ point_copy (&s,to);
+ point_sub (&s,&v);
+ connection_move_handle (&condition->connection,
+ HANDLE_MOVE_STARTPOINT,
+ &s,
+ NULL,
+ reason,
+ 0);
+ break;
+ case HANDLE_RESIZE_NW:
+ case HANDLE_RESIZE_N:
+ case HANDLE_RESIZE_NE:
+ case HANDLE_RESIZE_W:
+ case HANDLE_RESIZE_E:
+ case HANDLE_RESIZE_SW:
+ case HANDLE_RESIZE_S:
+ case HANDLE_RESIZE_SE:
+ case HANDLE_CUSTOM1:
+ case HANDLE_CUSTOM2:
+ case HANDLE_CUSTOM3:
+ case HANDLE_CUSTOM4:
+ case HANDLE_CUSTOM5:
+ case HANDLE_CUSTOM6:
+ case HANDLE_CUSTOM7:
+ case HANDLE_CUSTOM8:
+ case HANDLE_CUSTOM9:
+ default:
+ g_return_val_if_reached (NULL);
+ break;
}
- condition_update_data(condition);
+
+ condition_update_data (condition);
return NULL;
}
diff --git a/objects/GRAFCET/grafcet.c b/objects/GRAFCET/grafcet.c
index f031fd6a..7582bb3d 100644
--- a/objects/GRAFCET/grafcet.c
+++ b/objects/GRAFCET/grafcet.c
@@ -37,21 +37,22 @@ extern DiaObjectType condition_type;
DIA_PLUGIN_CHECK_INIT
+
PluginInitResult
-dia_plugin_init(PluginInfo *info)
+dia_plugin_init (PluginInfo *info)
{
- if (!dia_plugin_info_init(info, "GRAFCET", _("GRAFCET diagram objects"),
- NULL, NULL))
+ if (!dia_plugin_info_init (info, "GRAFCET", _("GRAFCET diagram objects"),
+ NULL, NULL)) {
return DIA_PLUGIN_INIT_ERROR;
+ }
- object_register_type(&step_type);
- object_register_type(&action_type);
- object_register_type(&transition_type);
- object_register_type(&vergent_type);
- object_register_type(&grafcet_arc_type);
- object_register_type(&old_arc_type);
- object_register_type(&condition_type);
+ object_register_type (&step_type);
+ object_register_type (&action_type);
+ object_register_type (&transition_type);
+ object_register_type (&vergent_type);
+ object_register_type (&grafcet_arc_type);
+ object_register_type (&old_arc_type);
+ object_register_type (&condition_type);
return DIA_PLUGIN_INIT_OK;
}
-
diff --git a/objects/GRAFCET/grafcet.h b/objects/GRAFCET/grafcet.h
index e511892f..2e852bba 100644
--- a/objects/GRAFCET/grafcet.h
+++ b/objects/GRAFCET/grafcet.h
@@ -18,11 +18,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef GRAFCET_H
-#define GRAFCET_H
+
+#pragma once
#define GRAFCET_GENERAL_LINE_WIDTH 0.1
#define GRAFCET_GENERAL_FONT_SIZE 1.0
-
-#endif /* GRAFCET_H */
-
diff --git a/objects/GRAFCET/step.c b/objects/GRAFCET/step.c
index 067d1cbd..5967e9f0 100644
--- a/objects/GRAFCET/step.c
+++ b/objects/GRAFCET/step.c
@@ -59,6 +59,7 @@ typedef enum {
STEP_MACROCALL,
STEP_SUBPCALL} StepType;
+
typedef struct _Step {
Element element;
@@ -72,41 +73,48 @@ typedef struct _Step {
real font_size;
Color font_color;
- Handle north,south;
- Point SD1,SD2,NU1,NU2;
+ Handle north, south;
+ Point SD1, SD2, NU1, NU2;
/* These are useful points for drawing.
Must be in sequence, A first, Z last. */
- Point A,B,C,D,E,F,G,H,I,J,Z;
+ Point A, B, C, D, E, F, G, H, I, J, Z;
} Step;
-static real step_distance_from(Step *step, Point *point);
-static void step_select(Step *step, Point *clicked_point,
- DiaRenderer *interactive_renderer);
-static ObjectChange* step_move_handle(Step *step, Handle *handle,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason, ModifierKeys modifiers);
-static ObjectChange* step_move(Step *step, Point *to);
-static void step_draw(Step *step, DiaRenderer *renderer);
-static void step_update_data(Step *step);
-static DiaObject *step_create(Point *startpoint,
- void *user_data,
- Handle **handle1,
- Handle **handle2);
-static void step_destroy(Step *step);
-
-static void step_been_renamed(const gchar *sid);
-
-static DiaObject *step_load(ObjectNode obj_node, int version,
- DiaContext *ctx);
-static PropDescription *step_describe_props(Step *step);
-static void step_get_props(Step *step,
- GPtrArray *props);
-static void step_set_props(Step *step,
- GPtrArray *props);
-
-static ObjectTypeOps step_type_ops =
-{
+
+static real step_distance_from (Step *step,
+ Point *point);
+static void step_select (Step *step,
+ Point *clicked_point,
+ DiaRenderer *interactive_renderer);
+static ObjectChange *step_move_handle (Step *step,
+ Handle *handle,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers);
+static ObjectChange *step_move (Step *step,
+ Point *to);
+static void step_draw (Step *step,
+ DiaRenderer *renderer);
+static void step_update_data (Step *step);
+static DiaObject *step_create (Point *startpoint,
+ void *user_data,
+ Handle **handle1,
+ Handle **handle2);
+static void step_destroy (Step *step);
+static void step_been_renamed (const gchar *sid);
+static DiaObject *step_load (ObjectNode obj_node,
+ int version,
+ DiaContext *ctx);
+static PropDescription *step_describe_props (Step *step);
+static void step_get_props (Step *step,
+ GPtrArray *props);
+static void step_set_props (Step *step,
+ GPtrArray *props);
+
+
+static ObjectTypeOps step_type_ops = {
(CreateFunc) step_create,
(LoadFunc) step_load,
(SaveFunc) object_save_using_properties,
@@ -114,14 +122,15 @@ static ObjectTypeOps step_type_ops =
(ApplyDefaultsFunc) NULL,
};
-DiaObjectType step_type =
-{
+
+DiaObjectType step_type = {
"GRAFCET - Step", /* name */
0, /* version */
etape_xpm, /* pixmap */
&step_type_ops /* ops */
};
+
static ObjectOps step_ops = {
(DestroyFunc) step_destroy,
(DrawFunc) step_draw,
@@ -147,7 +156,9 @@ PropEnumData step_style[] = {
{ N_("Macro exit step"),STEP_MACROEXIT },
{ N_("Macro call step"),STEP_MACROCALL },
{ N_("Subprogram call step"), STEP_SUBPCALL },
- { NULL }};
+ { NULL }
+};
+
static PropDescription step_props[] = {
ELEMENT_COMMON_PROPERTIES,
@@ -170,61 +181,75 @@ static PropDescription step_props[] = {
PROP_DESC_END
};
+
static PropDescription *
-step_describe_props(Step *step)
+step_describe_props (Step *step)
{
if (step_props[0].quark == 0) {
- prop_desc_list_calculate_quarks(step_props);
+ prop_desc_list_calculate_quarks (step_props);
}
return step_props;
}
+
static PropOffset step_offsets[] = {
ELEMENT_COMMON_PROPERTIES_OFFSETS,
- { "id", PROP_TYPE_STRING, offsetof(Step,id)},
- { "type", PROP_TYPE_ENUM, offsetof(Step,type)},
- { "active", PROP_TYPE_BOOL, offsetof(Step,active)},
- { "font", PROP_TYPE_FONT, offsetof(Step,font)},
- { "font_size", PROP_TYPE_FONTSIZE, offsetof(Step,font_size)},
- { "font_color", PROP_TYPE_COLOUR, offsetof(Step,font_color)},
- { "north_pos", PROP_TYPE_POINT, offsetof(Step,north.pos)},
- { "south_pos", PROP_TYPE_POINT, offsetof(Step,south.pos)},
+ { "id", PROP_TYPE_STRING, offsetof (Step, id)},
+ { "type", PROP_TYPE_ENUM, offsetof (Step, type)},
+ { "active", PROP_TYPE_BOOL, offsetof (Step, active)},
+ { "font", PROP_TYPE_FONT, offsetof (Step, font)},
+ { "font_size", PROP_TYPE_FONTSIZE, offsetof (Step, font_size)},
+ { "font_color", PROP_TYPE_COLOUR, offsetof (Step, font_color)},
+ { "north_pos", PROP_TYPE_POINT, offsetof (Step, north.pos)},
+ { "south_pos", PROP_TYPE_POINT, offsetof (Step, south.pos)},
{ NULL,0,0 }
};
+
static void
-step_get_props(Step *step, GPtrArray *props)
+step_get_props (Step *step, GPtrArray *props)
{
- object_get_props_from_offsets(&step->element.object,
- step_offsets,props);
+ object_get_props_from_offsets (DIA_OBJECT (step),
+ step_offsets,
+ props);
}
+
static void
-step_set_props(Step *step, GPtrArray *props)
+step_set_props (Step *step, GPtrArray *props)
{
- object_set_props_from_offsets(&step->element.object,
- step_offsets,props);
- step_been_renamed(step->id);
- step_update_data(step);
+ object_set_props_from_offsets (DIA_OBJECT (step),
+ step_offsets,
+ props);
+ step_been_renamed (step->id);
+ step_update_data (step);
}
+
/* the following two functions try to be clever when allocating
step numbers */
static int __stepnum = 0;
static int __Astyle = 0;
-static gchar *new_step_name()
+
+
+static gchar *
+new_step_name (void)
{
char snum[16];
char *p = snum;
- if (__Astyle) *p++ = 'A';
+ if (__Astyle) {
+ *p++ = 'A';
+ }
- g_snprintf(p,sizeof(snum)-2,"%d",__stepnum++);
- return g_strdup(snum);
+ g_snprintf (p, sizeof (snum)-2, "%d", __stepnum++);
+ return g_strdup (snum);
}
-static void step_been_renamed(const gchar *sid)
+
+static void
+step_been_renamed (const gchar *sid)
{
gchar *endptr;
long int snum;
@@ -236,84 +261,126 @@ static void step_been_renamed(const gchar *sid)
__Astyle = 0;
}
endptr = NULL;
- snum = strtol(sid,&endptr,10);
- if (*endptr == '\0') __stepnum = snum + 1;
+ snum = strtol (sid, &endptr, 10);
+ if (*endptr == '\0') {
+ __stepnum = snum + 1;
+ }
}
+
static Color color_red = { 1.0f, 0.0f, 0.0f, 1.0f };
+
static real
-step_distance_from(Step *step, Point *point)
+step_distance_from (Step *step, Point *point)
{
Element *elem = &step->element;
DiaRectangle rect;
real dist;
- dist = distance_line_point(&step->north.pos,&step->NU1,
- STEP_LINE_WIDTH,point);
- dist = MIN(dist,distance_line_point(&step->NU1,&step->NU2,
- STEP_LINE_WIDTH,point));
- dist = MIN(dist,distance_line_point(&step->NU2,&step->A,
- STEP_LINE_WIDTH,point));
- dist = MIN(dist,distance_line_point(&step->D,&step->SD1,
- STEP_LINE_WIDTH,point));
- dist = MIN(dist,distance_line_point(&step->SD1,&step->SD2,
- STEP_LINE_WIDTH,point));
- dist = MIN(dist,distance_line_point(&step->SD2,&step->south.pos,
- STEP_LINE_WIDTH,point));
+ dist = distance_line_point (&step->north.pos, &step->NU1,
+ STEP_LINE_WIDTH, point);
+ dist = MIN (dist,
+ distance_line_point (&step->NU1, &step->NU2,
+ STEP_LINE_WIDTH, point));
+ dist = MIN (dist,
+ distance_line_point (&step->NU2, &step->A,
+ STEP_LINE_WIDTH, point));
+ dist = MIN (dist,
+ distance_line_point (&step->D, &step->SD1,
+ STEP_LINE_WIDTH, point));
+ dist = MIN (dist,
+ distance_line_point (&step->SD1, &step->SD2,
+ STEP_LINE_WIDTH, point));
+ dist = MIN (dist,
+ distance_line_point (&step->SD2, &step->south.pos,
+ STEP_LINE_WIDTH, point));
rect.left = elem->corner.x;
rect.right = elem->corner.x + elem->width;
rect.top = elem->corner.y;
rect.bottom = elem->corner.y + elem->height;
- dist = MIN(dist,distance_rectangle_point(&rect, point));
+ dist = MIN (dist, distance_rectangle_point (&rect, point));
return dist;
}
+
static void
-step_select(Step *step, Point *clicked_point,
- DiaRenderer *interactive_renderer)
+step_select (Step *step,
+ Point *clicked_point,
+ DiaRenderer *interactive_renderer)
{
- element_update_handles(&step->element);
+ element_update_handles (&step->element);
}
+
static ObjectChange*
-step_move_handle(Step *step, Handle *handle,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason, ModifierKeys modifiers)
+step_move_handle (Step *step,
+ Handle *handle,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers)
{
- assert(step!=NULL);
- assert(handle!=NULL);
- assert(to!=NULL);
+ g_return_val_if_fail (step != NULL, NULL);
+ g_return_val_if_fail (handle != NULL, NULL);
+ g_return_val_if_fail (to != NULL, NULL);
switch(handle->id) {
- case HANDLE_NORTH:
- step->north.pos = *to;
- if (step->north.pos.y > step->A.y) step->north.pos.y = step->A.y;
- break;
- case HANDLE_SOUTH:
- step->south.pos = *to;
- if (step->south.pos.y < step->D.y) step->south.pos.y = step->D.y;
- break;
- default:
- element_move_handle(&step->element, handle->id, to, cp, reason, modifiers);
+ case HANDLE_NORTH:
+ step->north.pos = *to;
+ if (step->north.pos.y > step->A.y) {
+ step->north.pos.y = step->A.y;
+ }
+ break;
+ case HANDLE_SOUTH:
+ step->south.pos = *to;
+ if (step->south.pos.y < step->D.y) {
+ step->south.pos.y = step->D.y;
+ }
+ break;
+ case HANDLE_MOVE_STARTPOINT:
+ case HANDLE_MOVE_ENDPOINT:
+ case HANDLE_RESIZE_NW:
+ case HANDLE_RESIZE_N:
+ case HANDLE_RESIZE_NE:
+ case HANDLE_RESIZE_W:
+ case HANDLE_RESIZE_E:
+ case HANDLE_RESIZE_SW:
+ case HANDLE_RESIZE_S:
+ case HANDLE_RESIZE_SE:
+ case HANDLE_CUSTOM3:
+ case HANDLE_CUSTOM4:
+ case HANDLE_CUSTOM5:
+ case HANDLE_CUSTOM6:
+ case HANDLE_CUSTOM7:
+ case HANDLE_CUSTOM8:
+ case HANDLE_CUSTOM9:
+ default:
+ element_move_handle (&step->element,
+ handle->id,
+ to,
+ cp,
+ reason,
+ modifiers);
}
- step_update_data(step);
+ step_update_data (step);
return NULL;
}
+
static ObjectChange*
-step_move(Step *step, Point *to)
+step_move (Step *step, Point *to)
{
Point delta = *to;
- point_sub(&delta,&step->element.corner);
+ point_sub (&delta, &step->element.corner);
step->element.corner = *to;
- point_add(&step->north.pos,&delta);
- point_add(&step->south.pos,&delta);
+ point_add (&step->north.pos, &delta);
+ point_add (&step->south.pos, &delta);
- step_update_data(step);
+ step_update_data (step);
return NULL;
}
@@ -323,8 +390,8 @@ static void
step_draw (Step *step, DiaRenderer *renderer)
{
Point pts[4];
- assert(step != NULL);
- assert(renderer != NULL);
+ g_return_if_fail (step != NULL);
+ g_return_if_fail (renderer != NULL);
dia_renderer_set_fillstyle (renderer, FILLSTYLE_SOLID);
dia_renderer_set_linewidth (renderer, STEP_LINE_WIDTH);
@@ -380,8 +447,9 @@ step_draw (Step *step, DiaRenderer *renderer)
}
}
+
static void
-step_update_data(Step *step)
+step_update_data (Step *step)
{
Element *elem = &step->element;
DiaObject *obj = &elem->object;
@@ -398,41 +466,44 @@ step_update_data(Step *step)
step->F.x = STEP_WIDTH; step->F.y = STEP_HEIGHT- 0.5;
- switch(step->type) {
- case STEP_INITIAL:
- step->I.x = step->E.x - 2 * STEP_LINE_WIDTH;
- step->I.y = step->E.y - 2 * STEP_LINE_WIDTH;
- step->J.x = step->F.x + 2 * STEP_LINE_WIDTH;
- step->J.y = step->F.y + 2 * STEP_LINE_WIDTH;
-
- step->B.x = step->A.x; step->B.y = step->I.y;
- step->C.x = step->D.x; step->C.y = step->J.y;
- step->Z.x = step->J.x; step->Z.y = STEP_HEIGHT / 2;
- break;
- case STEP_MACROCALL:
- step->I.x = step->E.x;
- step->I.y = step->E.y - 2 * STEP_LINE_WIDTH;
- step->J.x = step->F.x;
- step->J.y = step->F.y + 2 * STEP_LINE_WIDTH;
-
- step->B.x = step->A.x; step->B.y = step->I.y;
- step->C.x = step->D.x; step->C.y = step->J.y;
- step->Z.x = step->J.x; step->Z.y = STEP_HEIGHT / 2;
- break;
- case STEP_SUBPCALL:
- step->I.x = step->E.x - 2 * STEP_LINE_WIDTH;
- step->I.y = step->E.y;
- step->J.x = step->F.x + 2 * STEP_LINE_WIDTH;
- step->J.y = step->F.y;
-
- step->B.x = step->A.x; step->B.y = step->I.y;
- step->C.x = step->D.x; step->C.y = step->J.y;
- step->Z.x = step->J.x; step->Z.y = STEP_HEIGHT / 2;
- break;
- default: /* regular or macro end steps */
- step->B.x = step->A.x; step->B.y = step->E.y;
- step->C.x = step->D.x; step->C.y = step->F.y;
- step->Z.x = step->F.x; step->Z.y = STEP_HEIGHT / 2;
+ switch (step->type) {
+ case STEP_INITIAL:
+ step->I.x = step->E.x - 2 * STEP_LINE_WIDTH;
+ step->I.y = step->E.y - 2 * STEP_LINE_WIDTH;
+ step->J.x = step->F.x + 2 * STEP_LINE_WIDTH;
+ step->J.y = step->F.y + 2 * STEP_LINE_WIDTH;
+
+ step->B.x = step->A.x; step->B.y = step->I.y;
+ step->C.x = step->D.x; step->C.y = step->J.y;
+ step->Z.x = step->J.x; step->Z.y = STEP_HEIGHT / 2;
+ break;
+ case STEP_MACROCALL:
+ step->I.x = step->E.x;
+ step->I.y = step->E.y - 2 * STEP_LINE_WIDTH;
+ step->J.x = step->F.x;
+ step->J.y = step->F.y + 2 * STEP_LINE_WIDTH;
+
+ step->B.x = step->A.x; step->B.y = step->I.y;
+ step->C.x = step->D.x; step->C.y = step->J.y;
+ step->Z.x = step->J.x; step->Z.y = STEP_HEIGHT / 2;
+ break;
+ case STEP_SUBPCALL:
+ step->I.x = step->E.x - 2 * STEP_LINE_WIDTH;
+ step->I.y = step->E.y;
+ step->J.x = step->F.x + 2 * STEP_LINE_WIDTH;
+ step->J.y = step->F.y;
+
+ step->B.x = step->A.x; step->B.y = step->I.y;
+ step->C.x = step->D.x; step->C.y = step->J.y;
+ step->Z.x = step->J.x; step->Z.y = STEP_HEIGHT / 2;
+ break;
+ case STEP_NORMAL:
+ case STEP_MACROENTRY:
+ case STEP_MACROEXIT:
+ default: /* regular or macro end steps */
+ step->B.x = step->A.x; step->B.y = step->E.y;
+ step->C.x = step->D.x; step->C.y = step->F.y;
+ step->Z.x = step->F.x; step->Z.y = STEP_HEIGHT / 2;
}
step->G.x = step->A.x;
@@ -440,8 +511,9 @@ step_update_data(Step *step)
step->H.x = step->E.x + (1.2 * STEP_DOT_RADIUS);
step->H.y = step->F.y - (1.2 * STEP_DOT_RADIUS);
- for (p=&(step->A); p<=&(step->Z) ; p++)
- point_add(p,&ulc);
+ for (p = &(step->A); p <= &(step->Z); p++) {
+ point_add (p, &ulc);
+ }
/* Update handles: */
if (step->north.pos.x == -65536.0) {
@@ -472,20 +544,21 @@ step_update_data(Step *step)
extra->border_trans = STEP_LINE_WIDTH / 2;
}
- element_update_boundingbox(elem);
- rectangle_add_point(&obj->bounding_box,&step->north.pos);
- rectangle_add_point(&obj->bounding_box,&step->south.pos);
+ element_update_boundingbox (elem);
+ rectangle_add_point (&obj->bounding_box, &step->north.pos);
+ rectangle_add_point (&obj->bounding_box, &step->south.pos);
obj->position = elem->corner;
- element_update_handles(elem);
+ element_update_handles (elem);
}
+
static DiaObject *
-step_create(Point *startpoint,
- void *user_data,
- Handle **handle1,
- Handle **handle2)
+step_create (Point *startpoint,
+ void *user_data,
+ Handle **handle1,
+ Handle **handle2)
{
Step *step;
Element *elem;
@@ -493,7 +566,7 @@ step_create(Point *startpoint,
int i;
int type;
- step = g_new0(Step,1);
+ step = g_new0 (Step, 1);
elem = &step->element;
obj = &elem->object;
@@ -504,36 +577,36 @@ step_create(Point *startpoint,
elem->width = STEP_DECLAREDWIDTH;
elem->height = STEP_HEIGHT;
- element_init(elem, 10, 4);
+ element_init (elem, 10, 4);
- for (i=0;i<4;i++) {
+ for (i = 0; i < 4; i++) {
obj->connections[i] = &step->connections[i];
step->connections[i].object = obj;
step->connections[i].connected = NULL;
}
- step->id = new_step_name();
+ step->id = new_step_name ();
step->active = 0;
- step->font = dia_font_new_from_style (STEP_FONT,STEP_FONT_HEIGHT);
+ step->font = dia_font_new_from_style (STEP_FONT, STEP_FONT_HEIGHT);
step->font_size = STEP_FONT_HEIGHT;
step->font_color = color_black;
- type = GPOINTER_TO_INT(user_data);
- switch(type) {
- case STEP_NORMAL:
- case STEP_INITIAL:
- case STEP_MACROENTRY:
- case STEP_MACROEXIT:
- case STEP_MACROCALL:
- case STEP_SUBPCALL:
- step->type = type;
- break;
- default:
- step->type = STEP_NORMAL;
+ type = GPOINTER_TO_INT (user_data);
+ switch (type) {
+ case STEP_NORMAL:
+ case STEP_INITIAL:
+ case STEP_MACROENTRY:
+ case STEP_MACROEXIT:
+ case STEP_MACROCALL:
+ case STEP_SUBPCALL:
+ step->type = type;
+ break;
+ default:
+ step->type = STEP_NORMAL;
}
- for (i=0;i<8;i++) {
+ for (i = 0; i < 8; i++) {
obj->handles[i]->type = HANDLE_NON_MOVABLE;
}
obj->handles[8] = &step->north;
@@ -546,13 +619,15 @@ step_create(Point *startpoint,
step->south.id = HANDLE_SOUTH;
step->north.pos.x = -65536.0; /* magic */
- step_update_data(step);
+ step_update_data (step);
*handle1 = NULL;
*handle2 = obj->handles[0];
+
return &step->element.object;
}
+
static void
step_destroy (Step *step)
{
@@ -561,15 +636,12 @@ step_destroy (Step *step)
element_destroy (&step->element);
}
+
static DiaObject *
-step_load(ObjectNode obj_node, int version, DiaContext *ctx)
+step_load (ObjectNode obj_node, int version, DiaContext *ctx)
{
- return object_load_using_properties(&step_type,
- obj_node,version,ctx);
+ return object_load_using_properties (&step_type,
+ obj_node,
+ version,
+ ctx);
}
-
-
-
-
-
-
diff --git a/objects/GRAFCET/transition.c b/objects/GRAFCET/transition.c
index 919b761c..884d2c3a 100644
--- a/objects/GRAFCET/transition.c
+++ b/objects/GRAFCET/transition.c
@@ -54,6 +54,7 @@
#define TRANSITION_HEIGHT .5
#define TRANSITION_WIDTH 1.5
+
typedef struct _Transition {
Element element;
@@ -65,38 +66,46 @@ typedef struct _Transition {
ConnectionPoint connections[2];
Handle north,south;
- Point SD1,SD2,NU1,NU2;
+ Point SD1, SD2, NU1, NU2;
/* computed values : */
DiaRectangle rceptbb; /* The bounding box of the receptivity */
- Point A,B,C,D,Z;
+ Point A, B, C, D, Z;
} Transition;
-static ObjectChange* transition_move_handle(Transition *transition, Handle *handle,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason, ModifierKeys modifiers);
-static ObjectChange* transition_move(Transition *transition, Point *to);
-static void transition_select(Transition *transition, Point *clicked_point,
- DiaRenderer *interactive_renderer);
-static void transition_draw(Transition *transition, DiaRenderer *renderer);
-static DiaObject *transition_create(Point *startpoint,
- void *user_data,
- Handle **handle1,
- Handle **handle2);
-static real transition_distance_from(Transition *transition, Point *point);
-static void transition_update_data(Transition *transition);
-static void transition_destroy(Transition *transition);
-
-static DiaObject *transition_load(ObjectNode obj_node, int version,
- DiaContext *ctx);
-static PropDescription *transition_describe_props(Transition *transition);
-static void transition_get_props(Transition *transition,
- GPtrArray *props);
-static void transition_set_props(Transition *transition,
- GPtrArray *props);
-
-static ObjectTypeOps transition_type_ops =
-{
+
+static ObjectChange *transition_move_handle (Transition *transition,
+ Handle *handle,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers);
+static ObjectChange *transition_move (Transition *transition,
+ Point *to);
+static void transition_select (Transition *transition,
+ Point *clicked_point,
+ DiaRenderer *interactive_renderer);
+static void transition_draw (Transition *transition,
+ DiaRenderer *renderer);
+static DiaObject *transition_create (Point *startpoint,
+ void *user_data,
+ Handle **handle1,
+ Handle **handle2);
+static real transition_distance_from (Transition *transition,
+ Point *point);
+static void transition_update_data (Transition *transition);
+static void transition_destroy (Transition *transition);
+static DiaObject *transition_load (ObjectNode obj_node,
+ int version,
+ DiaContext *ctx);
+static PropDescription *transition_describe_props (Transition *transition);
+static void transition_get_props (Transition *transition,
+ GPtrArray *props);
+static void transition_set_props (Transition *transition,
+ GPtrArray *props);
+
+
+static ObjectTypeOps transition_type_ops = {
(CreateFunc)transition_create, /* create */
(LoadFunc) transition_load,
(SaveFunc) object_save_using_properties, /* save */
@@ -104,6 +113,7 @@ static ObjectTypeOps transition_type_ops =
(ApplyDefaultsFunc) NULL
};
+
DiaObjectType transition_type =
{
"GRAFCET - Transition", /* name */
@@ -147,15 +157,17 @@ static PropDescription transition_props[] = {
PROP_DESC_END
};
+
static PropDescription *
-transition_describe_props(Transition *transition)
+transition_describe_props (Transition *transition)
{
if (transition_props[0].quark == 0) {
- prop_desc_list_calculate_quarks(transition_props);
+ prop_desc_list_calculate_quarks (transition_props);
}
return transition_props;
}
+
static PropOffset transition_offsets[] = {
ELEMENT_COMMON_PROPERTIES_OFFSETS,
{"receptivity",PROP_TYPE_STRING,offsetof(Transition,rcep_value)},
@@ -167,15 +179,17 @@ static PropOffset transition_offsets[] = {
{ NULL,0,0 }
};
+
static void
-transition_get_props(Transition *transition, GPtrArray *props)
+transition_get_props (Transition *transition, GPtrArray *props)
{
- object_get_props_from_offsets(&transition->element.object,
- transition_offsets,props);
+ object_get_props_from_offsets (&transition->element.object,
+ transition_offsets,props);
}
+
static void
-transition_set_props(Transition *transition, GPtrArray *props)
+transition_set_props (Transition *transition, GPtrArray *props)
{
object_set_props_from_offsets (&transition->element.object,
transition_offsets,
@@ -187,11 +201,12 @@ transition_set_props(Transition *transition, GPtrArray *props)
transition->receptivity->fontheight = transition->rcep_fontheight;
transition->receptivity->color = transition->rcep_color;
- transition_update_data(transition);
+ transition_update_data (transition);
}
+
static void
-transition_update_data(Transition *transition)
+transition_update_data (Transition *transition)
{
Element *elem = &transition->element;
DiaObject *obj = &elem->object;
@@ -217,11 +232,12 @@ transition_update_data(Transition *transition)
+ (.3 * transition->receptivity->fontheight);
transition->Z.x = transition->D.x +
- dia_font_string_width("_",transition->receptivity->font,
- transition->receptivity->fontheight);
+ dia_font_string_width ("_", transition->receptivity->font,
+ transition->receptivity->fontheight);
- for (p = &transition->A; p <= &transition->Z; p++)
- point_add(p,&elem->corner);
+ for (p = &transition->A; p <= &transition->Z; p++) {
+ point_add (p,&elem->corner);
+ }
transition->receptivity->pos = transition->Z;
@@ -246,91 +262,122 @@ transition_update_data(Transition *transition)
obj->connections[1]->directions = DIR_EAST|DIR_WEST;
- element_update_boundingbox(elem);
+ element_update_boundingbox (elem);
- rectangle_add_point(&obj->bounding_box,&transition->north.pos);
- rectangle_add_point(&obj->bounding_box,&transition->south.pos);
+ rectangle_add_point (&obj->bounding_box,&transition->north.pos);
+ rectangle_add_point (&obj->bounding_box,&transition->south.pos);
/* compute the rcept's width and bounding box, then merge. */
- boolequation_calc_boundingbox(transition->receptivity,&transition->rceptbb);
- rectangle_union(&obj->bounding_box,&transition->rceptbb);
+ boolequation_calc_boundingbox (transition->receptivity,
+ &transition->rceptbb);
+ rectangle_union (&obj->bounding_box, &transition->rceptbb);
- element_update_handles(elem);
+ element_update_handles (elem);
}
+
static real
-transition_distance_from(Transition *transition, Point *point)
+transition_distance_from (Transition *transition, Point *point)
{
real dist;
- dist = distance_rectangle_point(&transition->rceptbb,point);
- dist = MIN(dist,distance_line_point(&transition->C,&transition->D,
- TRANSITION_LINE_WIDTH,point));
- dist = MIN(dist,distance_line_point(&transition->north.pos,&transition->NU1,
- TRANSITION_LINE_WIDTH,point));
- dist = MIN(dist,distance_line_point(&transition->NU1,&transition->NU2,
- TRANSITION_LINE_WIDTH,point));
- dist = MIN(dist,distance_line_point(&transition->NU2,&transition->SD1,
- TRANSITION_LINE_WIDTH,point));
+ dist = distance_rectangle_point (&transition->rceptbb, point);
+ dist = MIN (dist,
+ distance_line_point (&transition->C, &transition->D,
+ TRANSITION_LINE_WIDTH, point));
+ dist = MIN (dist,
+ distance_line_point (&transition->north.pos, &transition->NU1,
+ TRANSITION_LINE_WIDTH, point));
+ dist = MIN (dist,
+ distance_line_point (&transition->NU1, &transition->NU2,
+ TRANSITION_LINE_WIDTH, point));
+ dist = MIN (dist,
+ distance_line_point (&transition->NU2, &transition->SD1,
+ TRANSITION_LINE_WIDTH, point));
/* A and B are on the [NU2; SD1] segment. */
- dist = MIN(dist,distance_line_point(&transition->SD1,&transition->SD2,
- TRANSITION_LINE_WIDTH,point));
- dist = MIN(dist,distance_line_point(&transition->SD2,&transition->south.pos,
- TRANSITION_LINE_WIDTH,point));
+ dist = MIN (dist,
+ distance_line_point (&transition->SD1, &transition->SD2,
+ TRANSITION_LINE_WIDTH, point));
+ dist = MIN (dist,
+ distance_line_point (&transition->SD2, &transition->south.pos,
+ TRANSITION_LINE_WIDTH, point));
return dist;
}
+
static void
-transition_select(Transition *transition, Point *clicked_point,
- DiaRenderer *interactive_renderer)
+transition_select (Transition *transition,
+ Point *clicked_point,
+ DiaRenderer *interactive_renderer)
{
- transition_update_data(transition);
+ transition_update_data (transition);
}
+
static ObjectChange*
-transition_move_handle(Transition *transition, Handle *handle,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason,
- ModifierKeys modifiers)
+transition_move_handle (Transition *transition,
+ Handle *handle,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers)
{
- g_assert(transition!=NULL);
- g_assert(handle!=NULL);
- g_assert(to!=NULL);
-
- switch(handle->id) {
- case HANDLE_NORTH:
- transition->north.pos = *to;
- if (transition->north.pos.y > transition->A.y)
- transition->north.pos.y = transition->A.y;
- break;
- case HANDLE_SOUTH:
- transition->south.pos = *to;
- if (transition->south.pos.y < transition->B.y)
- transition->south.pos.y = transition->B.y;
- break;
- default:
- element_move_handle(&transition->element, handle->id, to, cp,
- reason, modifiers);
+ g_return_val_if_fail (transition != NULL, NULL);
+ g_return_val_if_fail (handle != NULL, NULL);
+ g_return_val_if_fail (to != NULL, NULL);
+
+ switch (handle->id) {
+ case HANDLE_NORTH:
+ transition->north.pos = *to;
+ if (transition->north.pos.y > transition->A.y)
+ transition->north.pos.y = transition->A.y;
+ break;
+ case HANDLE_SOUTH:
+ transition->south.pos = *to;
+ if (transition->south.pos.y < transition->B.y)
+ transition->south.pos.y = transition->B.y;
+ break;
+ case HANDLE_MOVE_STARTPOINT:
+ case HANDLE_MOVE_ENDPOINT:
+ case HANDLE_RESIZE_NW:
+ case HANDLE_RESIZE_N:
+ case HANDLE_RESIZE_NE:
+ case HANDLE_RESIZE_W:
+ case HANDLE_RESIZE_E:
+ case HANDLE_RESIZE_SW:
+ case HANDLE_RESIZE_S:
+ case HANDLE_RESIZE_SE:
+ case HANDLE_CUSTOM3:
+ case HANDLE_CUSTOM4:
+ case HANDLE_CUSTOM5:
+ case HANDLE_CUSTOM6:
+ case HANDLE_CUSTOM7:
+ case HANDLE_CUSTOM8:
+ case HANDLE_CUSTOM9:
+ default:
+ element_move_handle (&transition->element,
+ handle->id, to, cp,
+ reason, modifiers);
}
- transition_update_data(transition);
+ transition_update_data (transition);
return NULL;
}
static ObjectChange*
-transition_move(Transition *transition, Point *to)
+transition_move (Transition *transition, Point *to)
{
Point delta = *to;
Element *elem = &transition->element;
- point_sub(&delta,&transition->element.corner);
+ point_sub (&delta,&transition->element.corner);
transition->element.corner = *to;
- point_add(&transition->north.pos,&delta);
- point_add(&transition->south.pos,&delta);
+ point_add (&transition->north.pos,&delta);
+ point_add (&transition->south.pos,&delta);
- element_update_handles(elem);
- transition_update_data(transition);
+ element_update_handles (elem);
+ transition_update_data (transition);
return NULL;
}
@@ -363,11 +410,12 @@ transition_draw (Transition *transition, DiaRenderer *renderer)
boolequation_draw (transition->receptivity,renderer);
}
+
static DiaObject *
-transition_create(Point *startpoint,
- void *user_data,
- Handle **handle1,
- Handle **handle2)
+transition_create (Point *startpoint,
+ void *user_data,
+ Handle **handle1,
+ Handle **handle2)
{
Transition *transition;
DiaObject *obj;
@@ -377,7 +425,7 @@ transition_create(Point *startpoint,
real default_fontheight;
Color fg_color;
- transition = g_malloc0(sizeof(Transition));
+ transition = g_new0 (Transition, 1);
elem = &transition->element;
obj = &elem->object;
@@ -388,18 +436,18 @@ transition_create(Point *startpoint,
elem->width = TRANSITION_DECLAREDWIDTH;
elem->height = TRANSITION_DECLAREDHEIGHT;
- element_init(elem, 10,2);
+ element_init (elem, 10, 2);
- attributes_get_default_font(&default_font,&default_fontheight);
- fg_color = attributes_get_foreground();
+ attributes_get_default_font (&default_font, &default_fontheight);
+ fg_color = attributes_get_foreground ();
transition->receptivity =
- boolequation_create("",
- default_font,
- default_fontheight,
- &fg_color);
+ boolequation_create ("",
+ default_font,
+ default_fontheight,
+ &fg_color);
- transition->rcep_value = g_strdup("");
+ transition->rcep_value = g_strdup ("");
transition->rcep_font = g_object_ref (default_font);
transition->rcep_fontheight = default_fontheight;
transition->rcep_color = fg_color;
@@ -420,20 +468,21 @@ transition_create(Point *startpoint,
transition->south.id = HANDLE_SOUTH;
transition->north.pos.x = -65536.0; /* magic */
- for (i=0;i<2;i++) {
+ for (i = 0; i < 2; i++) {
obj->connections[i] = &transition->connections[i];
obj->connections[i]->object = obj;
obj->connections[i]->connected = NULL;
}
- transition_update_data(transition);
+ transition_update_data (transition);
*handle1 = NULL;
*handle2 = obj->handles[0];
- return &transition->element.object;
+ return DIA_OBJECT (transition);
}
+
static void
transition_destroy (Transition *transition)
{
@@ -443,18 +492,10 @@ transition_destroy (Transition *transition)
element_destroy (&transition->element);
}
+
static DiaObject *
-transition_load(ObjectNode obj_node, int version, DiaContext *ctx)
+transition_load (ObjectNode obj_node, int version, DiaContext *ctx)
{
- return object_load_using_properties(&transition_type,
- obj_node,version,ctx);
+ return object_load_using_properties (&transition_type,
+ obj_node,version,ctx);
}
-
-
-
-
-
-
-
-
-
diff --git a/objects/GRAFCET/vergent.c b/objects/GRAFCET/vergent.c
index a4c0b0b7..e85c62eb 100644
--- a/objects/GRAFCET/vergent.c
+++ b/objects/GRAFCET/vergent.c
@@ -41,44 +41,53 @@
#define VERGENT_LINE_WIDTH (GRAFCET_GENERAL_LINE_WIDTH * 1.5)
+
typedef enum { VERGENT_OR, VERGENT_AND } VergentType;
typedef struct _Vergent {
Connection connection;
- ConnectionPoint northeast,northwest,southwest,southeast;
- ConnPointLine *north,*south;
+ ConnectionPoint northeast, northwest, southwest, southeast;
+ ConnPointLine *north, *south;
VergentType type;
} Vergent;
-static ObjectChange* vergent_move_handle(Vergent *vergent, Handle *handle,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason,
- ModifierKeys modifiers);
-static ObjectChange* vergent_move(Vergent *vergent, Point *to);
-static void vergent_select(Vergent *vergent, Point *clicked_point,
- DiaRenderer *interactive_renderer);
-static void vergent_draw(Vergent *vergent, DiaRenderer *renderer);
-static DiaObject *vergent_create(Point *startpoint,
- void *user_data,
- Handle **handle1,
- Handle **handle2);
-static real vergent_distance_from(Vergent *vergent, Point *point);
-static void vergent_update_data(Vergent *vergent);
-static void vergent_destroy(Vergent *vergent);
-static DiaObject *vergent_load(ObjectNode obj_node, int version,DiaContext *ctx);
-static PropDescription *vergent_describe_props(Vergent *vergent);
-static void vergent_get_props(Vergent *vergent,
- GPtrArray *props);
-static void vergent_set_props(Vergent *vergent,
- GPtrArray *props);
-
-static DiaMenu *vergent_get_object_menu(Vergent *vergent,
- Point *clickedpoint);
-
-static ObjectTypeOps vergent_type_ops =
-{
+
+static ObjectChange *vergent_move_handle (Vergent *vergent,
+ Handle *handle,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers);
+static ObjectChange *vergent_move (Vergent *vergent,
+ Point *to);
+static void vergent_select (Vergent *vergent,
+ Point *clicked_point,
+ DiaRenderer *interactive_renderer);
+static void vergent_draw (Vergent *vergent,
+ DiaRenderer *renderer);
+static DiaObject *vergent_create (Point *startpoint,
+ void *user_data,
+ Handle **handle1,
+ Handle **handle2);
+static real vergent_distance_from (Vergent *vergent,
+ Point *point);
+static void vergent_update_data (Vergent *vergent);
+static void vergent_destroy (Vergent *vergent);
+static DiaObject *vergent_load (ObjectNode obj_node,
+ int version,
+ DiaContext *ctx);
+static PropDescription *vergent_describe_props (Vergent *vergent);
+static void vergent_get_props (Vergent *vergent,
+ GPtrArray *props);
+static void vergent_set_props (Vergent *vergent,
+ GPtrArray *props);
+static DiaMenu *vergent_get_object_menu (Vergent *vergent,
+ Point *clickedpoint);
+
+
+static ObjectTypeOps vergent_type_ops = {
(CreateFunc)vergent_create, /* create */
(LoadFunc) vergent_load,/*using properties*/ /* load */
(SaveFunc) object_save_using_properties, /* save */
@@ -86,8 +95,8 @@ static ObjectTypeOps vergent_type_ops =
(ApplyDefaultsFunc) NULL
};
-DiaObjectType vergent_type =
-{
+
+DiaObjectType vergent_type = {
"GRAFCET - Vergent", /* name */
0, /* version */
vergent_xpm, /* pixmap */
@@ -111,61 +120,67 @@ static ObjectOps vergent_ops = {
(SetPropsFunc) vergent_set_props,
(TextEditFunc) 0,
(ApplyPropertiesListFunc) object_apply_props,
-
};
+
static PropEnumData prop_vtype_data[] = {
{ N_("OR"), VERGENT_OR },
{ N_("AND"), VERGENT_AND },
{ NULL, 0 }
};
+
static PropDescription vergent_props[] = {
CONNECTION_COMMON_PROPERTIES,
- { "cpl_north",PROP_TYPE_CONNPOINT_LINE, 0,
+ { "cpl_north", PROP_TYPE_CONNPOINT_LINE, 0,
"cpl_north","cpl_north"},
- { "cpl_south",PROP_TYPE_CONNPOINT_LINE, 0,
+ { "cpl_south", PROP_TYPE_CONNPOINT_LINE, 0,
"cpl_south","cpl_south"},
{ "vtype", PROP_TYPE_ENUM, PROP_FLAG_VISIBLE|PROP_FLAG_NO_DEFAULTS,
- N_("Vergent type:"),NULL, prop_vtype_data},
+ N_("Vergent type:"), NULL, prop_vtype_data},
PROP_DESC_END
};
+
static PropDescription *
-vergent_describe_props(Vergent *vergent)
+vergent_describe_props (Vergent *vergent)
{
if (vergent_props[0].quark == 0) {
- prop_desc_list_calculate_quarks(vergent_props);
+ prop_desc_list_calculate_quarks (vergent_props);
}
+
return vergent_props;
}
+
static PropOffset vergent_offsets[] = {
CONNECTION_COMMON_PROPERTIES_OFFSETS,
- {"cpl_north",PROP_TYPE_CONNPOINT_LINE,offsetof(Vergent,north)},
- {"cpl_south",PROP_TYPE_CONNPOINT_LINE,offsetof(Vergent,south)},
- {"vtype",PROP_TYPE_ENUM,offsetof(Vergent,type)},
- { NULL,0,0 }
+ { "cpl_north", PROP_TYPE_CONNPOINT_LINE, offsetof (Vergent, north)},
+ { "cpl_south", PROP_TYPE_CONNPOINT_LINE, offsetof (Vergent, south)},
+ { "vtype", PROP_TYPE_ENUM, offsetof (Vergent, type)},
+ { NULL, 0, 0 }
};
+
static void
vergent_get_props(Vergent *vergent, GPtrArray *props)
{
- object_get_props_from_offsets(&vergent->connection.object,
- vergent_offsets,props);
+ object_get_props_from_offsets (DIA_OBJECT (vergent),
+ vergent_offsets,props);
}
+
static void
-vergent_set_props(Vergent *vergent, GPtrArray *props)
+vergent_set_props (Vergent *vergent, GPtrArray *props)
{
- object_set_props_from_offsets(&vergent->connection.object,
- vergent_offsets,props);
- vergent_update_data(vergent);
+ object_set_props_from_offsets (DIA_OBJECT (vergent),
+ vergent_offsets,props);
+ vergent_update_data (vergent);
}
static real
-vergent_distance_from(Vergent *vergent, Point *point)
+vergent_distance_from (Vergent *vergent, Point *point)
{
Connection *conn = &vergent->connection;
DiaRectangle rectangle;
@@ -173,64 +188,82 @@ vergent_distance_from(Vergent *vergent, Point *point)
rectangle.left = conn->endpoints[0].x;
rectangle.right = conn->endpoints[1].x;
rectangle.top = conn->endpoints[0].y;
+
switch (vergent->type) {
- case VERGENT_OR:
- rectangle.top -= .5 * VERGENT_LINE_WIDTH;
- rectangle.bottom = rectangle.top + VERGENT_LINE_WIDTH;
- break;
- case VERGENT_AND:
- rectangle.top -= 1.5 * VERGENT_LINE_WIDTH;
- rectangle.bottom = rectangle.top + (3.0 * VERGENT_LINE_WIDTH);
- break;
+ case VERGENT_OR:
+ rectangle.top -= .5 * VERGENT_LINE_WIDTH;
+ rectangle.bottom = rectangle.top + VERGENT_LINE_WIDTH;
+ break;
+ case VERGENT_AND:
+ rectangle.top -= 1.5 * VERGENT_LINE_WIDTH;
+ rectangle.bottom = rectangle.top + (3.0 * VERGENT_LINE_WIDTH);
+ break;
+ default:
+ g_return_val_if_reached (0.0);
}
- return distance_rectangle_point(&rectangle,point);
+
+ return distance_rectangle_point (&rectangle,point);
}
+
static void
-vergent_select(Vergent *vergent, Point *clicked_point,
- DiaRenderer *interactive_renderer)
+vergent_select (Vergent *vergent,
+ Point *clicked_point,
+ DiaRenderer *interactive_renderer)
{
- vergent_update_data(vergent);
+ vergent_update_data (vergent);
}
+
static ObjectChange*
-vergent_move_handle(Vergent *vergent, Handle *handle,
- Point *to, ConnectionPoint *cp,
- HandleMoveReason reason, ModifierKeys modifiers)
+vergent_move_handle (Vergent *vergent,
+ Handle *handle,
+ Point *to,
+ ConnectionPoint *cp,
+ HandleMoveReason reason,
+ ModifierKeys modifiers)
{
- g_assert(vergent!=NULL);
- g_assert(handle!=NULL);
- g_assert(to!=NULL);
+ g_return_val_if_fail (vergent != NULL, NULL);
+ g_return_val_if_fail (handle != NULL, NULL);
+ g_return_val_if_fail (to != NULL, NULL);
if (handle->id == HANDLE_MOVE_ENDPOINT) {
Point to2;
to2.x = to->x;
to2.y = vergent->connection.endpoints[0].y;
- connection_move_handle(&vergent->connection, HANDLE_MOVE_ENDPOINT,
- &to2, NULL, reason, 0);
+ connection_move_handle (&vergent->connection,
+ HANDLE_MOVE_ENDPOINT,
+ &to2,
+ NULL,
+ reason,
+ 0);
}
- connection_move_handle(&vergent->connection, handle->id, to, cp,
- reason, modifiers);
- vergent_update_data(vergent);
+ connection_move_handle (&vergent->connection,
+ handle->id,
+ to,
+ cp,
+ reason,
+ modifiers);
+ vergent_update_data (vergent);
return NULL;
}
static ObjectChange*
-vergent_move(Vergent *vergent, Point *to)
+vergent_move (Vergent *vergent, Point *to)
{
Point start_to_end;
Point *endpoints = &vergent->connection.endpoints[0];
start_to_end = endpoints[1];
- point_sub(&start_to_end, &endpoints[0]);
+ point_sub (&start_to_end, &endpoints[0]);
endpoints[1] = endpoints[0] = *to;
- point_add(&endpoints[1], &start_to_end);
+ point_add (&endpoints[1], &start_to_end);
- vergent_update_data(vergent);
+ vergent_update_data (vergent);
return NULL;
}
@@ -262,15 +295,18 @@ vergent_draw (Vergent *vergent, DiaRenderer *renderer)
p1.x = conn->endpoints[0].x;
p2.x = conn->endpoints[1].x;
p1.y = p2.y = conn->endpoints[0].y - VERGENT_LINE_WIDTH;
- dia_renderer_draw_line (renderer,&p1,&p2,&color_black);
+ dia_renderer_draw_line (renderer, &p1, &p2, &color_black);
p1.y = p2.y = conn->endpoints[0].y + VERGENT_LINE_WIDTH;
- dia_renderer_draw_line (renderer,&p1,&p2,&color_black);
+ dia_renderer_draw_line (renderer, &p1, &p2, &color_black);
break;
+ default:
+ g_return_if_reached ();
}
}
+
static void
-vergent_update_data(Vergent *vergent)
+vergent_update_data (Vergent *vergent)
{
Connection *conn = &vergent->connection;
LineBBExtras *extra = &conn->extra_spacing;
@@ -287,54 +323,57 @@ vergent_update_data(Vergent *vergent)
p1.x = conn->endpoints[1].x - 1.0;
p0.y = p1.y = conn->endpoints[0].y;
- switch(vergent->type) {
- case VERGENT_OR:
- extra->start_trans =
+ switch (vergent->type) {
+ case VERGENT_OR:
+ extra->start_trans =
+ extra->start_long =
+ extra->end_trans =
+ extra->end_long = VERGENT_LINE_WIDTH / 2.0;
+ connection_update_boundingbox (conn);
+
+ /* place the connection point lines */
+ connpointline_update (vergent->north);
+ connpointline_putonaline (vergent->north, &p0, &p1, DIR_NORTH);
+ vergent->northwest.pos = p0;
+ vergent->northwest.directions = DIR_NORTH;
+ vergent->northeast.pos = p1;
+ vergent->northeast.directions = DIR_NORTH;
+ connpointline_update (vergent->south);
+ connpointline_putonaline (vergent->south, &p0, &p1, DIR_SOUTH);
+ vergent->southwest.pos = p0;
+ vergent->southwest.directions = DIR_SOUTH;
+ vergent->southeast.pos = p1;
+ vergent->southeast.directions = DIR_SOUTH;
+ break;
+ case VERGENT_AND:
+ extra->start_trans =
+ extra->end_trans = (3 * VERGENT_LINE_WIDTH) / 2.0;
extra->start_long =
- extra->end_trans =
- extra->end_long = VERGENT_LINE_WIDTH/2.0;
- connection_update_boundingbox(conn);
-
- /* place the connection point lines */
- connpointline_update(vergent->north);
- connpointline_putonaline(vergent->north,&p0,&p1,DIR_NORTH);
- vergent->northwest.pos = p0;
- vergent->northwest.directions = DIR_NORTH;
- vergent->northeast.pos = p1;
- vergent->northeast.directions = DIR_NORTH;
- connpointline_update(vergent->south);
- connpointline_putonaline(vergent->south,&p0,&p1,DIR_SOUTH);
- vergent->southwest.pos = p0;
- vergent->southwest.directions = DIR_SOUTH;
- vergent->southeast.pos = p1;
- vergent->southeast.directions = DIR_SOUTH;
- break;
- case VERGENT_AND:
- extra->start_trans =
- extra->end_trans = (3 * VERGENT_LINE_WIDTH)/2.0;
- extra->start_long =
- extra->end_long = VERGENT_LINE_WIDTH/2.0;
- connection_update_boundingbox(conn);
- connection_update_boundingbox(conn);
-
- /* place the connection point lines */
- p0.y = p1.y = p0.y - VERGENT_LINE_WIDTH;
- connpointline_update(vergent->north);
- connpointline_putonaline(vergent->north,&p0,&p1,DIR_NORTH);
- vergent->northwest.pos = p0;
- vergent->northwest.directions = DIR_NORTH;
- vergent->northeast.pos = p1;
- vergent->northeast.directions = DIR_NORTH;
- p0.y = p1.y = p0.y + 2.0 *VERGENT_LINE_WIDTH;
- connpointline_update(vergent->south);
- connpointline_putonaline(vergent->south,&p0,&p1,DIR_SOUTH);
- vergent->southwest.pos = p0;
- vergent->southwest.directions = DIR_SOUTH;
- vergent->southeast.pos = p1;
- vergent->southeast.directions = DIR_SOUTH;
- break;
+ extra->end_long = VERGENT_LINE_WIDTH / 2.0;
+ connection_update_boundingbox (conn);
+ connection_update_boundingbox (conn);
+
+ /* place the connection point lines */
+ p0.y = p1.y = p0.y - VERGENT_LINE_WIDTH;
+ connpointline_update (vergent->north);
+ connpointline_putonaline (vergent->north, &p0, &p1, DIR_NORTH);
+ vergent->northwest.pos = p0;
+ vergent->northwest.directions = DIR_NORTH;
+ vergent->northeast.pos = p1;
+ vergent->northeast.directions = DIR_NORTH;
+ p0.y = p1.y = p0.y + 2.0 *VERGENT_LINE_WIDTH;
+ connpointline_update (vergent->south);
+ connpointline_putonaline (vergent->south, &p0, &p1, DIR_SOUTH);
+ vergent->southwest.pos = p0;
+ vergent->southwest.directions = DIR_SOUTH;
+ vergent->southeast.pos = p1;
+ vergent->southeast.directions = DIR_SOUTH;
+ break;
+ default:
+ g_return_if_reached ();
}
- connection_update_handles(conn);
+
+ connection_update_handles (conn);
}
/* DiaObject menu handling */
@@ -345,76 +384,96 @@ typedef struct {
ObjectChange *north,*south;
} VergentChange;
-static void vergent_change_apply(VergentChange *change, DiaObject *obj)
+
+static void
+vergent_change_apply (VergentChange *change, DiaObject *obj)
{
- change->north->apply(change->north,obj);
- change->south->apply(change->south,obj);
+ change->north->apply (change->north, obj);
+ change->south->apply (change->south, obj);
}
-static void vergent_change_revert(VergentChange *change, DiaObject *obj)
+
+static void
+vergent_change_revert (VergentChange *change, DiaObject *obj)
{
- change->north->revert(change->north,obj);
- change->south->revert(change->south,obj);
+ change->north->revert (change->north,obj);
+ change->south->revert (change->south,obj);
}
-static void vergent_change_free(VergentChange *change)
+
+static void
+vergent_change_free (VergentChange *change)
{
- if (change->north->free) change->north->free(change->north);
- g_free(change->north);
- if (change->south->free) change->south->free(change->south);
- g_free(change->south);
+ if (change->north->free) {
+ change->north->free (change->north);
+ }
+ g_clear_pointer (&change->north, g_free);
+
+ if (change->south->free) {
+ change->south->free (change->south);
+ }
+ g_clear_pointer (&change->south, g_free);
}
+
static ObjectChange *
-vergent_create_change(Vergent *vergent, int add, Point *clicked)
+vergent_create_change (Vergent *vergent, int add, Point *clicked)
{
VergentChange *vc;
- vc = g_new0(VergentChange,1);
- vc->obj_change.apply = (ObjectChangeApplyFunc)vergent_change_apply;
- vc->obj_change.revert = (ObjectChangeRevertFunc)vergent_change_revert;
- vc->obj_change.free = (ObjectChangeFreeFunc)vergent_change_free;
+ vc = g_new0 (VergentChange,1);
+ vc->obj_change.apply = (ObjectChangeApplyFunc) vergent_change_apply;
+ vc->obj_change.revert = (ObjectChangeRevertFunc) vergent_change_revert;
+ vc->obj_change.free = (ObjectChangeFreeFunc) vergent_change_free;
if (add) {
- vc->north = connpointline_add_point(vergent->north,clicked);
- vc->south = connpointline_add_point(vergent->south,clicked);
+ vc->north = connpointline_add_point (vergent->north,clicked);
+ vc->south = connpointline_add_point (vergent->south,clicked);
} else {
- vc->north = connpointline_remove_point(vergent->north,clicked);
- vc->south = connpointline_remove_point(vergent->south,clicked);
+ vc->north = connpointline_remove_point (vergent->north,clicked);
+ vc->south = connpointline_remove_point (vergent->south,clicked);
}
- vergent_update_data(vergent);
- return (ObjectChange *)vc;
+
+ vergent_update_data (vergent);
+
+ return (ObjectChange *) vc;
}
+
static ObjectChange *
-vergent_add_cp_callback(DiaObject *obj, Point *clicked, gpointer data)
+vergent_add_cp_callback (DiaObject *obj, Point *clicked, gpointer data)
{
- return vergent_create_change((Vergent *)obj,1,clicked);
+ return vergent_create_change ((Vergent *) obj, 1, clicked);
}
+
static ObjectChange *
-vergent_delete_cp_callback(DiaObject *obj, Point *clicked, gpointer data)
+vergent_delete_cp_callback (DiaObject *obj, Point *clicked, gpointer data)
{
- return vergent_create_change((Vergent *)obj,0,clicked);
+ return vergent_create_change ((Vergent *) obj, 0, clicked);
}
+
static DiaMenuItem object_menu_items[] = {
{ N_("Add connection point"), vergent_add_cp_callback, NULL, 1 },
{ N_("Delete connection point"), vergent_delete_cp_callback, NULL, 1 },
};
+
static DiaMenu object_menu = {
N_("GRAFCET OR/AND vergent"),
- sizeof(object_menu_items)/sizeof(DiaMenuItem),
+ sizeof (object_menu_items) / sizeof (DiaMenuItem),
object_menu_items,
NULL
};
+
static DiaMenu *
-vergent_get_object_menu(Vergent *vergent, Point *clickedpoint)
+vergent_get_object_menu (Vergent *vergent, Point *clickedpoint)
{
/* Set entries sensitive/selected etc here */
- g_assert(vergent->north->num_connections == vergent->south->num_connections);
+ g_return_val_if_fail (vergent->north->num_connections == vergent->south->num_connections,
+ NULL);
object_menu_items[0].active = 1;
object_menu_items[1].active = (vergent->north->num_connections > 1);
@@ -422,30 +481,31 @@ vergent_get_object_menu(Vergent *vergent, Point *clickedpoint)
return &object_menu;
}
+
static DiaObject *
-vergent_create(Point *startpoint,
- void *user_data,
- Handle **handle1,
- Handle **handle2)
+vergent_create (Point *startpoint,
+ void *user_data,
+ Handle **handle1,
+ Handle **handle2)
{
Vergent *vergent;
Connection *conn;
DiaObject *obj;
int i;
- Point defaultlen = {6.0,0.0};
+ Point defaultlen = { 6.0, 0.0 };
- vergent = g_malloc0(sizeof(Vergent));
+ vergent = g_new0 (Vergent, 1);
conn = &vergent->connection;
- obj = &conn->object;
+ obj = DIA_OBJECT (conn);
obj->type = &vergent_type;
obj->ops = &vergent_ops;
conn->endpoints[0] = *startpoint;
conn->endpoints[1] = *startpoint;
- point_add(&conn->endpoints[1], &defaultlen);
+ point_add (&conn->endpoints[1], &defaultlen);
- connection_init(conn, 2, 4);
+ connection_init (conn, 2, 4);
obj->connections[0] = &vergent->northeast;
obj->connections[1] = &vergent->northwest;
@@ -456,20 +516,20 @@ vergent_create(Point *startpoint,
obj->connections[i]->connected = NULL;
}
- vergent->north = connpointline_create(obj,1);
- vergent->south = connpointline_create(obj,1);
-
- switch(GPOINTER_TO_INT(user_data)) {
- case VERGENT_OR:
- case VERGENT_AND:
- vergent->type = GPOINTER_TO_INT(user_data);
- break;
- default:
- g_warning("in vergent_create(): incorrect user_data %p",user_data);
- vergent->type = VERGENT_OR;
+ vergent->north = connpointline_create (obj,1);
+ vergent->south = connpointline_create (obj,1);
+
+ switch (GPOINTER_TO_INT (user_data)) {
+ case VERGENT_OR:
+ case VERGENT_AND:
+ vergent->type = GPOINTER_TO_INT (user_data);
+ break;
+ default:
+ g_warning ("in vergent_create(): incorrect user_data %p", user_data);
+ vergent->type = VERGENT_OR;
}
- vergent_update_data(vergent);
+ vergent_update_data (vergent);
*handle1 = &conn->endpoint_handles[0];
*handle2 = &conn->endpoint_handles[1];
@@ -477,29 +537,21 @@ vergent_create(Point *startpoint,
return &vergent->connection.object;
}
+
static void
-vergent_destroy(Vergent *vergent)
+vergent_destroy (Vergent *vergent)
{
- connpointline_destroy(vergent->south);
- connpointline_destroy(vergent->north);
- connection_destroy(&vergent->connection);
+ connpointline_destroy (vergent->south);
+ connpointline_destroy (vergent->north);
+ connection_destroy (&vergent->connection);
}
+
static DiaObject *
-vergent_load(ObjectNode obj_node, int version,DiaContext *ctx)
+vergent_load (ObjectNode obj_node, int version, DiaContext *ctx)
{
- return object_load_using_properties(&vergent_type,
- obj_node,version,ctx);
+ return object_load_using_properties (&vergent_type,
+ obj_node,
+ version,
+ ctx);
}
-
-
-
-
-
-
-
-
-
-
-
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]