/*! Factory function - create default object */ static DiaObject * outline_create (Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Outline *outline; DiaObject *obj; outline = g_new0 (Outline,1); obj = &outline->object; obj->type = &outline_type; obj->ops = &outline_ops; object_init (obj, NUM_HANDLES, 0); obj->position = *startpoint; outline_init_handles (outline); attributes_get_default_font (&outline->font, &outline->font_height); outline->line_width = 0; /* Not: attributes_get_default_linewidth(); it looks ugly */ outline->line_color = attributes_get_foreground(); outline->fill_color = attributes_get_background(); outline->show_background = FALSE; outline->name = g_strdup ("?"); outline->rotation = 0; *handle1 = outline->object.handles[0]; *handle2 = outline->object.handles[1]; outline_update_data (outline); return obj; }
DiaOutputDev::DiaOutputDev (DiagramData *_dia, int _n) : dia(_dia), stroke_color(attributes_get_foreground ()), line_width(attributes_get_default_linewidth()), // favoring member intitialization list over attributes_get_default_line_style() line_style(LINESTYLE_SOLID), dash_length(1.0), line_join(LINEJOIN_MITER), line_caps(LINECAPS_PROJECTING), fill_color(attributes_get_background ()), alignment(ALIGN_LEFT), scale(2.54/72.0), objects(NULL), pageNum(0), page_width(1.0), page_height(1.0), num_pages(_n), font_map_hits(0), pattern(NULL) { font_map = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)dia_font_unref); matrix.xx = matrix.yy = 1.0; matrix.yx = matrix.xy = 0.0; matrix.x0 = matrix.y0 = 0.0; image_cache = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)g_object_unref); }
static DiaPattern * _create_preset_pattern (guint n) { DiaPattern *pat; Color color; g_return_val_if_fail (n < G_N_ELEMENTS (_pattern_presets), NULL); switch (_pattern_presets[n].type) { case DIA_LINEAR_GRADIENT: pat = dia_pattern_new (_pattern_presets[n].type, 0, 0.0, 0.0); if (_pattern_presets[n].flags != 0) dia_pattern_set_point (pat, _pattern_presets[n].flags & LEFT ? 1.0 : 0.0, _pattern_presets[n].flags & DOWN ? 1.0 : 0.0); break; case DIA_RADIAL_GRADIENT: pat = dia_pattern_new (_pattern_presets[n].type, 0, 0.5, 0.5); dia_pattern_set_radius (pat, 0.5); /* set the focal point to the center */ dia_pattern_set_point (pat, 0.5, 0.5); break; default : g_assert_not_reached (); } color = attributes_get_background (); dia_pattern_add_color (pat, 0.0, &color); color = attributes_get_foreground (); dia_pattern_add_color (pat, 1.0, &color); return pat; }
static Object * image_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Image *image; Element *elem; Object *obj; int i; image = g_malloc(sizeof(Image)); elem = (Element *) image; obj = (Object *) image; obj->type = &image_type; obj->ops = &image_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_WIDTH; image_init_defaults(); image->border_width = attributes_get_default_linewidth(); image->border_color = attributes_get_foreground(); image->line_style = default_properties.line_style; element_init(elem, 8, 8); for (i=0;i<8;i++) { obj->connections[i] = &image->connections[i]; image->connections[i].object = obj; image->connections[i].connected = NULL; } if (strcmp(default_properties.file, "")) { image->file = g_strdup(default_properties.file); image->image = dia_image_load(image->file); if (image->image) { elem->width = (elem->width*(float)dia_image_width(image->image))/ (float)dia_image_height(image->image); } } else { image->file = g_strdup(""); image->image = NULL; } image->draw_border = default_properties.draw_border; image->keep_aspect = default_properties.keep_aspect; image_update_data(image); *handle1 = NULL; *handle2 = obj->handles[7]; return (Object *)image; }
static DiaObject * image_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Image *image; Element *elem; DiaObject *obj; int i; image = g_malloc0(sizeof(Image)); elem = &image->element; obj = &elem->object; obj->type = &image_type; obj->ops = &image_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; image->border_width = attributes_get_default_linewidth(); image->border_color = attributes_get_foreground(); attributes_get_default_line_style(&image->line_style, &image->dashlength); element_init(elem, 8, NUM_CONNECTIONS); for (i=0; i<NUM_CONNECTIONS; i++) { obj->connections[i] = &image->connections[i]; image->connections[i].object = obj; image->connections[i].connected = NULL; } image->connections[8].flags = CP_FLAGS_MAIN; if (strcmp(default_properties.file, "")) { image->file = g_strdup(default_properties.file); image->image = dia_image_load(image->file); if (image->image) { elem->width = (elem->width*(float)dia_image_width(image->image))/ (float)dia_image_height(image->image); } } else { image->file = g_strdup(""); image->image = NULL; } image->draw_border = default_properties.draw_border; image->keep_aspect = default_properties.keep_aspect; image_update_data(image); *handle1 = NULL; *handle2 = obj->handles[7]; return &image->element.object; }
static DiaObject * compfeat_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Compfeat *compfeat; OrthConn *orth; DiaObject *obj; Point p; DiaFont *font; font = dia_font_new_from_style(DIA_FONT_MONOSPACE, 0.8); compfeat = g_new0(Compfeat, 1); compfeat->role = compfeat->roletmp = GPOINTER_TO_INT(user_data); compfeat->line_width = 0.1; orth = &compfeat->orth; obj = &orth->object; obj->type = &compfeat_type; obj->ops = &compfeat_ops; orthconn_init(orth, startpoint); p = *startpoint; p.y -= COMPPROP_TEXTOFFSET; compfeat->line_color = attributes_get_foreground(); compfeat->text = new_text("", font, COMPPROP_FONTHEIGHT, &p, &compfeat->line_color, ALIGN_CENTER); dia_font_unref(font); compfeat->text_handle.id = HANDLE_MOVE_TEXT; compfeat->text_handle.type = HANDLE_MINOR_CONTROL; compfeat->text_handle.connect_type = HANDLE_NONCONNECTABLE; compfeat->text_handle.connected_to = NULL; compfeat->text_handle.pos = compfeat->text_pos = p; object_add_handle(obj, &compfeat->text_handle); if (compfeat->role == COMPPROP_FACET || compfeat->role == COMPPROP_EVENTSOURCE) { int pos = obj->num_connections; object_add_connectionpoint(&orth->object, &compfeat->cp); obj->connections[pos] = &compfeat->cp; compfeat->cp.object = obj; compfeat->cp.connected = NULL; } compfeat_update_data(compfeat); *handle1 = orth->handles[0]; *handle2 = orth->handles[orth->numpoints-2]; return &compfeat->orth.object; }
static DiaObject * component_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Component *cmp; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; cmp = g_malloc0(sizeof(Component)); elem = &cmp->element; obj = &elem->object; obj->type = &component_type; obj->ops = &component_ops; obj->flags |= DIA_OBJECT_CAN_PARENT; elem->corner = *startpoint; cmp->line_color = attributes_get_foreground(); cmp->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_SANS, 0.8); p = *startpoint; p.x += COMPONENT_CWIDTH + COMPONENT_MARGIN_X; p.y += 2*COMPONENT_CHEIGHT; cmp->text = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); text_get_attributes(cmp->text,&cmp->attrs); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &cmp->connections[i]; cmp->connections[i].object = obj; cmp->connections[i].connected = NULL; } cmp->connections[10].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = COMPONENT_BORDERWIDTH/2.0; cmp->stereotype = NULL; cmp->st_stereotype = NULL; component_update_data(cmp); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &cmp->element.object; }
static DiaObject * transition_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Transition *transition; OrthConn *orth; DiaObject *obj; Point temp_point; if (transition_font == NULL) { transition_font = dia_font_new_from_style (DIA_FONT_SANS, TRANSITION_FONTHEIGHT); } transition = g_malloc0(sizeof(Transition)); orth = &transition->orth; obj = &orth->object; obj->type = ¨_transition_type; obj->ops = ¨_transition_ops; orthconn_init(orth, startpoint); transition->text_color = color_black; transition->line_color = attributes_get_foreground(); /* Prepare the handles for trigger and guard text */ transition->trigger_text_handle.id = HANDLE_MOVE_TRIGGER_TEXT; transition->trigger_text_handle.type = HANDLE_MINOR_CONTROL; transition->trigger_text_handle.connect_type = HANDLE_NONCONNECTABLE; transition->trigger_text_handle.connected_to = NULL; temp_point = *startpoint; temp_point.y -= TEXT_HANDLE_DISTANCE_FROM_STARTPOINT; transition->trigger_text_pos = temp_point; transition->trigger_text_handle.pos = temp_point; object_add_handle(obj, &transition->trigger_text_handle); transition->guard_text_handle.id = HANDLE_MOVE_GUARD_TEXT; transition->guard_text_handle.type = HANDLE_MINOR_CONTROL; transition->guard_text_handle.connect_type = HANDLE_NONCONNECTABLE; transition->guard_text_handle.connected_to = NULL; temp_point = *startpoint; temp_point.y += TEXT_HANDLE_DISTANCE_FROM_STARTPOINT; transition->guard_text_pos = transition->guard_text_handle.pos = temp_point; object_add_handle(obj, &transition->guard_text_handle); transition->guard_text = NULL; transition->trigger_text = NULL; transition->action_text = NULL; uml_transition_update_data(transition); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return obj; }
static DiaObject * attribute_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Attribute *attribute; Element *elem; DiaObject *obj; int i; attribute = g_malloc0(sizeof(Attribute)); elem = &attribute->element; obj = &elem->object; obj->type = &attribute_type; obj->ops = &attribute_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; attribute->border_width = attributes_get_default_linewidth(); attribute->border_color = attributes_get_foreground(); attribute->inner_color = attributes_get_background(); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &attribute->connections[i]; attribute->connections[i].object = obj; attribute->connections[i].connected = NULL; } attribute->connections[8].flags = CP_FLAGS_MAIN; attribute->key = FALSE; attribute->weakkey = FALSE; attribute->derived = FALSE; attribute->multivalue = FALSE; attribute->font = dia_font_new_from_style(DIA_FONT_MONOSPACE,FONT_HEIGHT); attribute->font_height = FONT_HEIGHT; attribute->name = g_strdup(_("Attribute")); attribute->name_width = dia_font_string_width(attribute->name, attribute->font, attribute->font_height); attribute_update_data(attribute); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = obj->handles[0]; return &attribute->element.object; }
static DiaObject * beziergon_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Beziergon *beziergon; BezierShape *bez; DiaObject *obj; Point defaultx = { 1.0, 0.0 }; Point defaulty = { 0.0, 1.0 }; beziergon = g_new0(Beziergon, 1); bez = &beziergon->bezier; obj = &bez->object; obj->type = &beziergon_type; obj->ops = &beziergon_ops; if (user_data == NULL) { beziershape_init(bez, 3); bez->bezier.points[0].p1 = *startpoint; bez->bezier.points[0].p3 = *startpoint; bez->bezier.points[2].p3 = *startpoint; bez->bezier.points[1].p1 = *startpoint; point_add(&bez->bezier.points[1].p1, &defaultx); bez->bezier.points[2].p2 = *startpoint; point_sub(&bez->bezier.points[2].p2, &defaultx); bez->bezier.points[1].p3 = *startpoint; point_add(&bez->bezier.points[1].p3, &defaulty); bez->bezier.points[1].p2 = bez->bezier.points[1].p3; point_add(&bez->bezier.points[1].p2, &defaultx); bez->bezier.points[2].p1 = bez->bezier.points[1].p3; point_sub(&bez->bezier.points[2].p1, &defaultx); } else { BezierCreateData *bcd = (BezierCreateData*)user_data; beziershape_init(bez, bcd->num_points); beziercommon_set_points (&bez->bezier, bcd->num_points, bcd->points); } beziergon->line_width = attributes_get_default_linewidth(); beziergon->line_color = attributes_get_foreground(); beziergon->inner_color = attributes_get_background(); attributes_get_default_line_style(&beziergon->line_style, &beziergon->dashlength); beziergon->line_join = LINEJOIN_MITER; beziergon->show_background = default_properties.show_background; beziergon_update_data(beziergon); *handle1 = bez->object.handles[5]; *handle2 = bez->object.handles[2]; return &beziergon->bezier.object; }
static DiaObject * wanlink_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { WanLink *wanlink; Connection *conn; DiaObject *obj; int i; Point defaultpoly = {0.0, 0.0}; Point defaultlen = { 5.0, 0.0 }; wanlink = g_malloc0(sizeof(WanLink)); conn = &wanlink->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = (DiaObject *) wanlink; obj->type = &wanlink_type; obj->ops = &wanlink_ops; connection_init(conn, 2, 0); for (i = 0; i < WANLINK_POLY_LEN ; i++) wanlink->poly[i] = defaultpoly; wanlink->width = FLASH_WIDTH; /* both colors where black at the time this was hardcoded ... */ wanlink->line_color = color_black; wanlink->fill_color = color_black; wanlink->line_color = attributes_get_foreground(); wanlink->fill_color = attributes_get_foreground(); wanlink_update_data(wanlink); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return (DiaObject *)wanlink; }
static DiaObject * grid_object_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Grid_Object *grid_object; Element *elem; DiaObject *obj; unsigned i; grid_object = g_new0(Grid_Object,1); elem = &(grid_object->element); obj = &(grid_object->element.object); obj->type = &grid_object_type; obj->ops = &grid_object_ops; elem->corner = *startpoint; elem->width = 4.0; elem->height = 4.0; element_init(elem, 8, 9); grid_object->border_color = attributes_get_foreground(); grid_object->border_line_width = attributes_get_default_linewidth(); grid_object->inner_color = attributes_get_background(); grid_object->show_background = TRUE; grid_object->grid_rows = 3; grid_object->grid_cols = 4; grid_object->gridline_color.red = 0.5; grid_object->gridline_color.green = 0.5; grid_object->gridline_color.blue = 0.5; grid_object->gridline_color.alpha = 1.0; grid_object->gridline_width = attributes_get_default_linewidth(); for (i = 0; i < 9; ++i) { obj->connections[i] = &grid_object->base_cps[i]; grid_object->base_cps[i].object = obj; grid_object->base_cps[i].connected = NULL; } grid_object->base_cps[8].flags = CP_FLAGS_MAIN; grid_object->cells_rows = 0; grid_object->cells_cols = 0; grid_object->cells = NULL; grid_object_reallocate_cells(grid_object); grid_object_update_data(grid_object); *handle1 = NULL; *handle2 = obj->handles[7]; return &grid_object->element.object; }
static DiaObject * message_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Message *message; Connection *conn; LineBBExtras *extra; DiaObject *obj; message = g_malloc0(sizeof(Message)); /* old defaults */ message->font_height = 0.8; message->font = dia_font_new_from_style (DIA_FONT_SANS, message->font_height); message->line_width = 0.1; conn = &message->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; conn->endpoints[1].x += 1.5; obj = &conn->object; extra = &conn->extra_spacing; obj->type = &message_type; obj->ops = &message_ops; connection_init(conn, 3, 0); message->text_color = color_black; message->line_color = attributes_get_foreground(); message->text = g_strdup(""); message->text_width = 0.0; message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y) + 0.5; message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; extra->start_long = extra->start_trans = extra->end_long = message->line_width/2.0; extra->end_trans = MAX(message->line_width,MESSAGE_ARROWLEN)/2.0; message_update_data(message); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &message->connection.object; }
/** user_data is a struct polyline_create_data, containing an array of points and a count. If user_data is NULL, the startpoint is used and a 1x1 line is created. Otherwise, the startpoint is ignored. */ static DiaObject * polyline_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Polyline *polyline; PolyConn *poly; DiaObject *obj; Point defaultlen = { 1.0, 1.0 }; /*polyline_init_defaults();*/ polyline = g_malloc0(sizeof(Polyline)); poly = &polyline->poly; obj = &poly->object; obj->type = &polyline_type; obj->ops = &polyline_ops; if (user_data == NULL) { polyconn_init(poly, 2); poly->points[0] = *startpoint; poly->points[1] = *startpoint; point_add(&poly->points[1], &defaultlen); *handle1 = poly->object.handles[0]; *handle2 = poly->object.handles[1]; } else { MultipointCreateData *pcd = (MultipointCreateData *)user_data; polyconn_init(poly, pcd->num_points); /* Handles are set up by polyconn_init and polyconn_update_data */ polyconn_set_points(poly, pcd->num_points, pcd->points); *handle1 = poly->object.handles[0]; *handle2 = poly->object.handles[pcd->num_points-1]; } polyline->line_width = attributes_get_default_linewidth(); polyline->line_color = attributes_get_foreground(); attributes_get_default_line_style(&polyline->line_style, &polyline->dashlength); polyline->line_join = LINEJOIN_MITER; polyline->line_caps = LINECAPS_BUTT; polyline->start_arrow = attributes_get_default_start_arrow(); polyline->end_arrow = attributes_get_default_end_arrow(); polyline->corner_radius = 0.0; polyline_update_data(polyline); return &polyline->poly.object; }
static DiaObject * usecase_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Usecase *usecase; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; usecase = g_malloc0(sizeof(Usecase)); elem = &usecase->element; obj = &elem->object; obj->type = &usecase_type; obj->ops = &usecase_ops; elem->corner = *startpoint; elem->width = USECASE_WIDTH; elem->height = USECASE_HEIGHT; usecase->line_width = attributes_get_default_linewidth(); usecase->line_color = attributes_get_foreground(); usecase->fill_color = attributes_get_background(); font = dia_font_new_from_style(DIA_FONT_SANS, 0.8); p = *startpoint; p.x += USECASE_WIDTH/2.0; p.y += USECASE_HEIGHT/2.0; usecase->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER); dia_font_unref(font); usecase->text_outside = 0; usecase->collaboration = 0; element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &usecase->connections[i]; usecase->connections[i].object = obj; usecase->connections[i].connected = NULL; } usecase->connections[8].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = 0.0; usecase_update_data(usecase); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &usecase->element.object; }
static DiaObject * largepackage_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { LargePackage *pkg; Element *elem; DiaObject *obj; int i; pkg = g_malloc0(sizeof(LargePackage)); elem = &pkg->element; obj = &elem->object; obj->type = &largepackage_type; obj->ops = &largepackage_ops; obj->flags |= DIA_OBJECT_CAN_PARENT; elem->corner = *startpoint; element_init(elem, 8, NUM_CONNECTIONS); elem->width = 4.0; elem->height = 4.0; pkg->line_width = attributes_get_default_linewidth(); pkg->text_color = color_black; pkg->line_color = attributes_get_foreground(); pkg->fill_color = attributes_get_background(); pkg->font = dia_font_new_from_style(DIA_FONT_MONOSPACE, LARGEPACKAGE_FONTHEIGHT); pkg->stereotype = NULL; pkg->st_stereotype = NULL; pkg->name = g_strdup(""); pkg->topwidth = 2.0; pkg->topheight = LARGEPACKAGE_FONTHEIGHT*2 + 0.1*2; for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &pkg->connections[i]; pkg->connections[i].object = obj; pkg->connections[i].connected = NULL; } pkg->connections[8].flags = CP_FLAGS_MAIN; pkg->element.extra_spacing.border_trans = pkg->line_width/2.0; largepackage_update_data(pkg); *handle1 = NULL; *handle2 = obj->handles[7]; return &pkg->element.object; }
static DiaObject * note_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Note *note; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; note = g_malloc0(sizeof(Note)); elem = ¬e->element; obj = &elem->object; obj->type = ¬e_type; obj->ops = ¬e_ops; elem->corner = *startpoint; note->line_width = attributes_get_default_linewidth(); note->line_color = attributes_get_foreground(); note->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_MONOSPACE, 0.8); p = *startpoint; p.x += note->line_width/2.0 + NOTE_MARGIN_X; p.y += note->line_width/2.0 + NOTE_CORNER + dia_font_ascent("A",font, 0.8); note->text = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = ¬e->connections[i]; note->connections[i].object = obj; note->connections[i].connected = NULL; } note->connections[NUM_CONNECTIONS-1].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = note->line_width/2.0; note_update_data(note); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return ¬e->element.object; }
static DiaObject * bus_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Bus *bus; Connection *conn; LineBBExtras *extra; DiaObject *obj; Point defaultlen = { 5.0, 0.0 }; int i; bus = g_malloc0(sizeof(Bus)); conn = &bus->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = &conn->object; extra = &conn->extra_spacing; obj->type = &bus_type; obj->ops = &bus_ops; bus->num_handles = DEFAULT_NUMHANDLES; connection_init(conn, 2+bus->num_handles, 0); bus->line_color = attributes_get_foreground(); bus->handles = g_malloc(sizeof(Handle *)*bus->num_handles); bus->parallel_points = g_malloc(sizeof(Point)*bus->num_handles); for (i=0;i<bus->num_handles;i++) { bus->handles[i] = g_new0(Handle,1); bus->handles[i]->id = HANDLE_BUS; bus->handles[i]->type = HANDLE_MINOR_CONTROL; bus->handles[i]->connect_type = HANDLE_CONNECTABLE_NOBREAK; bus->handles[i]->connected_to = NULL; bus->handles[i]->pos = *startpoint; bus->handles[i]->pos.x += 5*((real)i+1)/(bus->num_handles+1); bus->handles[i]->pos.y += (i%2==0)?1.0:-1.0; obj->handles[2+i] = bus->handles[i]; } extra->start_trans = extra->end_trans = extra->start_long = extra->end_long = LINE_WIDTH/2.0; bus_update_data(bus); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &bus->connection.object; }
static DiaObject * bezierline_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Bezierline *bezierline; BezierConn *bez; DiaObject *obj; Point defaultlen = { .3, .3 }; bezierline = g_new0(Bezierline, 1); bezierline->bez.object.enclosing_box = g_new0 (Rectangle, 1); bez = &bezierline->bez; obj = &bez->object; obj->type = &bezierline_type; obj->ops = &bezierline_ops; if (user_data == NULL) { bezierconn_init(bez, 2); bez->bezier.points[0].p1 = *startpoint; bez->bezier.points[1].p1 = *startpoint; point_add(&bez->bezier.points[1].p1, &defaultlen); bez->bezier.points[1].p2 = bez->bezier.points[1].p1; point_add(&bez->bezier.points[1].p2, &defaultlen); bez->bezier.points[1].p3 = bez->bezier.points[1].p2; point_add(&bez->bezier.points[1].p3, &defaultlen); } else { BezierCreateData *bcd = (BezierCreateData*)user_data; bezierconn_init(bez, bcd->num_points); beziercommon_set_points (&bez->bezier, bcd->num_points, bcd->points); } bezierline->line_width = attributes_get_default_linewidth(); bezierline->line_color = attributes_get_foreground(); attributes_get_default_line_style(&bezierline->line_style, &bezierline->dashlength); bezierline->line_join = LINEJOIN_MITER; bezierline->line_caps = LINECAPS_BUTT; bezierline->start_arrow = attributes_get_default_start_arrow(); bezierline->end_arrow = attributes_get_default_end_arrow(); *handle1 = bez->object.handles[0]; *handle2 = bez->object.handles[3]; bezierline_update_data(bezierline); return &bezierline->bez.object; }
static DiaObject * ellipse_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Ellipse *ellipse; Element *elem; DiaObject *obj; int i; ellipse = g_malloc0(sizeof(Ellipse)); elem = &ellipse->element; obj = &elem->object; obj->type = &ellipse_type; obj->ops = &ellipse_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; ellipse->border_width = attributes_get_default_linewidth(); ellipse->border_color = attributes_get_foreground(); ellipse->inner_color = attributes_get_background(); attributes_get_default_line_style(&ellipse->line_style, &ellipse->dashlength); ellipse->show_background = default_properties.show_background; ellipse->aspect = default_properties.aspect; element_init(elem, 9, 9); obj->handles[8] = &ellipse->center_handle; obj->handles[8]->id = HANDLE_CUSTOM1; obj->handles[8]->type = HANDLE_MAJOR_CONTROL; obj->handles[8]->connected_to = NULL; obj->handles[8]->connect_type = HANDLE_NONCONNECTABLE; for (i=0;i<9;i++) { obj->connections[i] = &ellipse->connections[i]; ellipse->connections[i].object = obj; ellipse->connections[i].connected = NULL; } ellipse->connections[8].flags = CP_FLAGS_MAIN; ellipse_update_data(ellipse); *handle1 = NULL; *handle2 = obj->handles[7]; return &ellipse->element.object; }
static DiaObject * state_create_activity(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { State *state; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; state = g_malloc0(sizeof(State)); elem = &state->element; obj = &elem->object; obj->type = &activity_type; obj->ops = &state_ops; elem->corner = *startpoint; elem->width = STATE_WIDTH; elem->height = STATE_HEIGHT; state->line_color = attributes_get_foreground(); state->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_SANS, 0.8); p = *startpoint; p.x += STATE_WIDTH/2.0; p.y += STATE_HEIGHT/2.0; state->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER); text_get_attributes(state->text,&state->attrs); element_init(elem, 8, 8); for (i=0;i<8;i++) { obj->connections[i] = &state->connections[i]; state->connections[i].object = obj; state->connections[i].connected = NULL; } elem->extra_spacing.border_trans = 0.0; state_update_data(state); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &state->element.object;; }
static DiaObject * textobj_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Textobj *textobj; DiaObject *obj; Color col; DiaFont *font = NULL; real font_height; textobj = g_malloc0(sizeof(Textobj)); obj = &textobj->object; obj->enclosing_box = g_new0 (Rectangle, 1); obj->type = &textobj_type; obj->ops = &textobj_ops; col = attributes_get_foreground(); attributes_get_default_font(&font, &font_height); textobj->text = new_text("", font, font_height, startpoint, &col, default_properties.alignment ); /* need to initialize to object.position as well, it is used update data */ obj->position = *startpoint; dia_font_unref(font); textobj->vert_align = default_properties.vert_align; /* default visibility must be off to keep compatibility */ textobj->fill_color = attributes_get_background(); textobj->show_background = FALSE; object_init(obj, 1, 0); obj->handles[0] = &textobj->text_handle; textobj->text_handle.id = HANDLE_TEXT; textobj->text_handle.type = HANDLE_MAJOR_CONTROL; textobj->text_handle.connect_type = HANDLE_CONNECTABLE; textobj->text_handle.connected_to = NULL; /* no margin till Dia 0.98 */ textobj->margin = 0.0; textobj_update_data(textobj); *handle1 = NULL; *handle2 = obj->handles[0]; return &textobj->object; }
static DiaObject * constraint_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Constraint *constraint; Connection *conn; DiaObject *obj; Point defaultlen = { 1.0, 1.0 }; constraint = g_malloc0(sizeof(Constraint)); /* old defaults */ constraint->font_height = 0.8; constraint->font = dia_font_new_from_style (DIA_FONT_MONOSPACE, constraint->font_height); constraint->line_width = 0.1; conn = &constraint->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = &conn->object; obj->type = &constraint_type; obj->ops = &constraint_ops; connection_init(conn, 3, 0); constraint->text_color = color_black; constraint->line_color = attributes_get_foreground(); constraint->text = g_strdup(""); constraint->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); constraint->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y) - 0.2; constraint->text_handle.id = HANDLE_MOVE_TEXT; constraint->text_handle.type = HANDLE_MINOR_CONTROL; constraint->text_handle.connect_type = HANDLE_NONCONNECTABLE; constraint->text_handle.connected_to = NULL; obj->handles[2] = &constraint->text_handle; constraint->brtext = NULL; constraint_update_data(constraint); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &constraint->connection.object; }
static DiaObject * compound_create (Point * start_point, void * user_data, Handle **handle1, Handle **handle2) { Compound * comp; DiaObject * obj; Handle * handle; gint num_handles; gint i; comp = g_new0 (Compound, 1); obj = &comp->object; obj->type = &compound_type; obj->ops = &compound_ops; comp->num_arms = DEFAULT_NUMARMS; comp->line_width = attributes_get_default_linewidth (); comp->line_color = attributes_get_foreground (); /* init our mount-point */ setup_mount_point (&comp->mount_point, obj, start_point); num_handles = comp->num_arms + 1; /* init the inherited object */ object_init (obj, num_handles, 1); obj->connections[0] = &comp->mount_point; comp->handles = g_new0 (Handle, num_handles); /* init the handle on the mount-point */ obj->handles[0] = &comp->handles[0]; setup_handle (obj->handles[0], HANDLE_MOUNT_POINT, HANDLE_MAJOR_CONTROL, HANDLE_NONCONNECTABLE); /* now init the rest of the handles */ for (i = 1; i < num_handles; i++) { handle = &comp->handles[i]; obj->handles[i] = handle; setup_handle (handle, HANDLE_ARM, HANDLE_MINOR_CONTROL, HANDLE_CONNECTABLE_NOBREAK); } init_default_handle_positions (comp); compound_update_data (comp); compound_sanity_check (comp, "Created"); *handle1 = &comp->handles[0]; *handle2 = &comp->handles[1]; return &comp->object; }
static DiaObject * realizes_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Realizes *realize; OrthConn *orth; DiaObject *obj; PolyBBExtras *extra; realize = g_malloc0(sizeof(Realizes)); /* old defaults */ realize->font_height = 0.8; realize->font = dia_font_new_from_style (DIA_FONT_MONOSPACE, realize->font_height); realize->line_width = 0.1; orth = &realize->orth; obj = &orth->object; extra = &orth->extra_spacing; obj->type = &realizes_type; obj->ops = &realizes_ops; orthconn_init(orth, startpoint); realize->text_color = color_black; realize->line_color = attributes_get_foreground(); realize->name = NULL; realize->stereotype = NULL; realize->st_stereotype = NULL; realize->text_width = 0; extra->start_trans = realize->line_width/2.0 + REALIZES_TRIANGLESIZE; extra->start_long = extra->middle_trans = extra->end_trans = extra->end_long = realize->line_width/2.0; realizes_update_data(realize); *handle1 = orth->handles[0]; *handle2 = orth->handles[orth->numpoints-2]; return &realize->orth.object; }
static DiaObject * box_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Box *box; Element *elem; DiaObject *obj; int i; box = g_malloc0(sizeof(Box)); elem = &box->element; obj = &elem->object; obj->type = &box_type; obj->ops = &box_ops; elem->corner = *startpoint; elem->width = DEFAULT_WIDTH; elem->height = DEFAULT_HEIGHT; box->border_width = attributes_get_default_linewidth(); box->border_color = attributes_get_foreground(); box->inner_color = attributes_get_background(); attributes_get_default_line_style(&box->line_style, &box->dashlength); box->line_join = LINEJOIN_MITER; /* For non-default objects, this is overridden by the default */ box->show_background = default_properties.show_background; box->corner_radius = default_properties.corner_radius; box->aspect = default_properties.aspect; element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &box->connections[i]; box->connections[i].object = obj; box->connections[i].connected = NULL; } box->connections[8].flags = CP_FLAGS_MAIN; box_update_data(box); *handle1 = NULL; *handle2 = obj->handles[7]; return &box->element.object; }
static DiaObject * state_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { State *state; Element *elem; DiaObject *obj; Point p; int i; state = g_malloc0(sizeof(State)); elem = &state->element; obj = &elem->object; obj->type = &state_term_type; obj->ops = &state_ops; elem->corner = *startpoint; elem->width = STATE_WIDTH; elem->height = STATE_HEIGHT; p = *startpoint; p.x += STATE_WIDTH/2.0; p.y += STATE_HEIGHT/2.0; state->line_color = attributes_get_foreground(); state->fill_color = attributes_get_background(); state->is_final = 0; element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &state->connections[i]; state->connections[i].object = obj; state->connections[i].connected = NULL; } state->connections[8].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = 0.0; state_update_data(state); for (i=0;i<8;i++) { obj->handles[i]->type = HANDLE_NON_MOVABLE; } *handle1 = NULL; *handle2 = NULL; return &state->element.object; }
static DiaObject *node_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Node *node; Element *elem; DiaObject *obj; Point p; DiaFont *font; int i; node = g_malloc0(sizeof(Node)); /* old defaults */ node->line_width = 0.1; elem = &node->element; obj = &elem->object; obj->type = &node_type; obj->ops = &node_ops; elem->corner = *startpoint; node->line_color = attributes_get_foreground(); node->fill_color = attributes_get_background(); font = dia_font_new_from_style (DIA_FONT_SANS, 0.8); /* The text position is recalculated later */ p.x = 0.0; p.y = 0.0; node->name = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT); dia_font_unref(font); element_init(elem, 8, NUM_CONNECTIONS); for (i=0;i<NUM_CONNECTIONS;i++) { obj->connections[i] = &node->connections[i]; node->connections[i].object = obj; node->connections[i].connected = NULL; } node->connections[8].flags = CP_FLAGS_MAIN; elem->extra_spacing.border_trans = node->line_width/2.0; node_update_data(node); *handle1 = NULL; *handle2 = obj->handles[7]; return &node->element.object; }
static DiaObject * zigzagline_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Zigzagline *zigzagline; OrthConn *orth; DiaObject *obj; Point dummy = {0, 0}; /*zigzagline_init_defaults();*/ zigzagline = g_malloc0(sizeof(Zigzagline)); orth = &zigzagline->orth; obj = &orth->object; obj->type = &zigzagline_type; obj->ops = &zigzagline_ops; if (startpoint) orthconn_init(orth, startpoint); else orthconn_init(orth, &dummy); if (user_data) { MultipointCreateData *pcd = (MultipointCreateData *)user_data; orthconn_set_points (orth, pcd->num_points, pcd->points); } zigzagline->line_width = attributes_get_default_linewidth(); zigzagline->line_color = attributes_get_foreground(); attributes_get_default_line_style(&zigzagline->line_style, &zigzagline->dashlength); zigzagline->line_join = LINEJOIN_MITER; zigzagline->line_caps = LINECAPS_BUTT; zigzagline->start_arrow = attributes_get_default_start_arrow(); zigzagline->end_arrow = attributes_get_default_end_arrow(); zigzagline->corner_radius = 0.0; *handle1 = orth->handles[0]; *handle2 = orth->handles[orth->numpoints-2]; zigzagline_update_data(zigzagline); return &zigzagline->orth.object; }
static Object * arc_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Arc *arc; Connection *conn; Object *obj; Point defaultlen = { 1.0, 1.0 }; /*arc_init_defaults();*/ arc = g_malloc(sizeof(Arc)); arc->line_width = attributes_get_default_linewidth(); arc->curve_distance = 1.0; arc->arc_color = attributes_get_foreground(); attributes_get_default_line_style(&arc->line_style, &arc->dashlength); arc->start_arrow = attributes_get_default_start_arrow(); arc->end_arrow = attributes_get_default_end_arrow(); conn = &arc->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = (Object *) arc; obj->type = &arc_type;; obj->ops = &arc_ops; connection_init(conn, 3, 0); obj->handles[2] = &arc->middle_handle; arc->middle_handle.id = HANDLE_MIDDLE; arc->middle_handle.type = HANDLE_MINOR_CONTROL; arc->middle_handle.connect_type = HANDLE_NONCONNECTABLE; arc->middle_handle.connected_to = NULL; arc_update_data(arc); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return (Object *)arc; }