static void node_update_data(Node *node) { Element *elem = &node->element; DiaObject *obj = &node->element.object; Point p1; real h; text_calc_boundingbox(node->name, NULL); h = elem->corner.y + NODE_TEXT_MARGIN; p1.x = elem->corner.x + NODE_TEXT_MARGIN; p1.y = h + node->name->ascent; /* position of text */ text_set_position(node->name, &p1); h += node->name->height * node->name->numlines; elem->width = MAX(elem->width, node->name->max_width + 2*NODE_TEXT_MARGIN); elem->height = MAX(elem->height, node->name->height * node->name->numlines + 2*NODE_TEXT_MARGIN); /* Update connections: */ element_update_connections_rectangle(elem, node->connections); element_update_boundingbox(elem); /* fix boundingbox for depth: */ obj->bounding_box.top -= NODE_DEPTH; obj->bounding_box.right += NODE_DEPTH; obj->position = elem->corner; element_update_handles(elem); }
static void grid_object_update_data(Grid_Object *grid_object) { Element *elem = &grid_object->element; DiaObject *obj = &elem->object; ElementBBExtras *extra = &elem->extra_spacing; real inset = (grid_object->border_line_width - grid_object->gridline_width)/2.0; real cell_width = (elem->width - 2.0 * inset) / grid_object->grid_cols; real cell_height = (elem->height - 2.0 * inset) / grid_object->grid_rows; int i, j; coord left, top; extra->border_trans = grid_object->border_line_width / 2.0; element_update_boundingbox(elem); element_update_handles(elem); element_update_connections_rectangle(elem, grid_object->base_cps); obj->position = elem->corner; left = obj->position.x; top = obj->position.y; for (i = 0; i < grid_object->grid_cols; ++i) for (j = 0; j < grid_object->grid_rows; ++j) { int cell = grid_cell(i, j, grid_object->grid_rows, grid_object->grid_cols); grid_object->cells[cell].pos.x = left + inset + i*cell_width + cell_width/2.0; grid_object->cells[cell].pos.y = top + inset + j*cell_height + cell_height/2.0; } }
static void basestation_update_data(Basestation *basestation) { Element *elem = &basestation->element; DiaObject *obj = &elem->object; Rectangle text_box; Point p; elem->width = BASESTATION_WIDTH; elem->height = BASESTATION_HEIGHT+basestation->text->height; p = elem->corner; p.x += elem->width/2; p.y += elem->height + basestation->text->ascent; text_set_position(basestation->text, &p); text_calc_boundingbox(basestation->text, &text_box); /* Update connections: */ element_update_connections_rectangle (elem, basestation->connections); element_update_boundingbox(elem); /* Add bounding box for text: */ rectangle_union(&obj->bounding_box, &text_box); obj->position = elem->corner; obj->position.x += elem->width/2.0; obj->position.y += elem->height/2.0; element_update_handles(elem); }
static void note_update_data(Note *note) { Element *elem = ¬e->element; DiaObject *obj = &elem->object; Point p; text_calc_boundingbox(note->text, NULL); elem->width = note->text->max_width + NOTE_MARGIN_X + NOTE_CORNER; elem->height = note->text->height*note->text->numlines + NOTE_MARGIN_Y + NOTE_CORNER; p = elem->corner; p.x += note->line_width/2.0 + NOTE_MARGIN_X; p.y += note->line_width/2.0 + NOTE_CORNER + note->text->ascent; text_set_position(note->text, &p); /* Update connections: */ element_update_connections_rectangle(elem, note->connections); element_update_boundingbox(elem); obj->position = elem->corner; element_update_handles(elem); }
static void _dae_update_data(DiagramAsElement *dae) { struct stat statbuf; Element *elem = &dae->element; DiaObject *obj = &elem->object; static int working = 0; if (working > 2) return; /* protect against infinite recursion */ ++working; if ( strlen(dae->filename) && g_stat(dae->filename, &statbuf) == 0 && dae->mtime != statbuf.st_mtime) { DiaImportFilter *inf; if (dae->data) g_object_unref(dae->data); dae->data = g_object_new (DIA_TYPE_DIAGRAM_DATA, NULL); inf = filter_guess_import_filter(dae->filename); if (inf) { DiaContext *ctx = dia_context_new (diagram_as_element_type.name); dia_context_set_filename (ctx, dae->filename); if (inf->import_func(dae->filename, dae->data, ctx, inf->user_data)) { data_update_extents (dae->data); /* should already be called by importer? */ dae->scale = dae->element.width / (dae->data->extents.right - dae->data->extents.left); dae->element.height = (dae->data->extents.bottom - dae->data->extents.top) * dae->scale; dae->mtime = statbuf.st_mtime; } /* FIXME: where to put the message in case of an error? */ dia_context_release (ctx); } /* invalidate possibly cached image */ if (dae->image) { g_object_unref (dae->image); dae->image = NULL; } } /* fixme - fit the scale to draw the diagram in elements size ?*/ if (dae->scale) dae->scale = dae->element.width / (dae->data->extents.right - dae->data->extents.left); elem->extra_spacing.border_trans = dae->border_line_width/2.0; element_update_boundingbox(elem); element_update_handles(elem); element_update_connections_rectangle(elem, dae->connections); /* adjust objects position, otherwise it'll jump on move */ obj->position = elem->corner; --working; }
static void largepackage_update_data(LargePackage *pkg) { Element *elem = &pkg->element; DiaObject *obj = &elem->object; pkg->stereotype = remove_stereotype_from_string(pkg->stereotype); if (!pkg->st_stereotype) { pkg->st_stereotype = string_to_stereotype(pkg->stereotype); } pkg->topheight = LARGEPACKAGE_FONTHEIGHT + 0.1*2; pkg->topwidth = 2.0; if (pkg->name != NULL) pkg->topwidth = MAX(pkg->topwidth, dia_font_string_width(pkg->name, pkg->font, LARGEPACKAGE_FONTHEIGHT)+2*0.1); if (pkg->st_stereotype != NULL && pkg->st_stereotype[0] != '\0') { pkg->topwidth = MAX(pkg->topwidth, dia_font_string_width(pkg->st_stereotype, pkg->font, LARGEPACKAGE_FONTHEIGHT)+2*0.1); pkg->topheight += LARGEPACKAGE_FONTHEIGHT; } if (elem->width < (pkg->topwidth + 0.2)) elem->width = pkg->topwidth + 0.2; if (elem->height < 1.0) elem->height = 1.0; /* Update connections: */ element_update_connections_rectangle(elem, pkg->connections); element_update_boundingbox(elem); /* fix boundingbox for top rectangle: */ obj->bounding_box.top -= pkg->topheight; obj->position = elem->corner; element_update_handles(elem); }
static void state_update_data(State *state) { real w, h; Element *elem = &state->element; ElementBBExtras *extra = &elem->extra_spacing; DiaObject *obj = &elem->object; w = h = (state->is_final) ? STATE_ENDRATIO: STATE_RATIO; elem->width = w; elem->height = h; extra->border_trans = STATE_LINEWIDTH / 2.0; /* Update connections: */ element_update_connections_rectangle(elem, state->connections); element_update_boundingbox(elem); obj->position = elem->corner; element_update_handles(elem); }
static void objet_update_data(Objet *ob) { Element *elem = &ob->element; DiaObject *obj = &elem->object; DiaFont *font; Point p1, p2; real h, w = 0; text_calc_boundingbox(ob->text, NULL); ob->stereotype = remove_stereotype_from_string(ob->stereotype); if (!ob->st_stereotype) { ob->st_stereotype = string_to_stereotype(ob->stereotype); } font = ob->text->font; h = elem->corner.y + OBJET_MARGIN_Y(ob); if (ob->is_multiple) { h += OBJET_MARGIN_M(ob); } if ((ob->stereotype != NULL) && (ob->stereotype[0] != '\0')) { w = dia_font_string_width(ob->st_stereotype, font, OBJET_FONTHEIGHT(ob)); h += OBJET_FONTHEIGHT(ob); ob->st_pos.y = h; h += OBJET_MARGIN_Y(ob)/2.0; } w = MAX(w, ob->text->max_width); p1.y = h + ob->text->ascent; /* position of text */ h += ob->text->height*ob->text->numlines; if ((ob->exstate != NULL) && (ob->exstate[0] != '\0')) { w = MAX(w, dia_font_string_width(ob->exstate, font, OBJET_FONTHEIGHT(ob))); h += OBJET_FONTHEIGHT(ob); ob->ex_pos.y = h; } h += OBJET_MARGIN_Y(ob); if (ob->show_attributes) { h += OBJET_MARGIN_Y(ob) + ob->attributes->ascent; p2.x = elem->corner.x + OBJET_MARGIN_X(ob); p2.y = h; text_set_position(ob->attributes, &p2); h += ob->attributes->height*ob->attributes->numlines; text_calc_boundingbox(ob->attributes, NULL); w = MAX(w, ob->attributes->max_width); } w += 2*OBJET_MARGIN_X(ob); p1.x = elem->corner.x + w/2.0; text_set_position(ob->text, &p1); ob->ex_pos.x = ob->st_pos.x = p1.x; if (ob->is_multiple) { w += OBJET_MARGIN_M(ob); } elem->width = w; elem->height = h - elem->corner.y; /* Update connections: */ element_update_connections_rectangle(elem, ob->connections); element_update_boundingbox(elem); obj->position = elem->corner; element_update_handles(elem); }