void diagram_update_extents(Diagram *dia) { gfloat cur_scale = dia->data->paper.scaling; /* anropar update_scrollbars() */ if (data_update_extents(dia->data)) { /* Update scrollbars because extents were changed: */ GSList *l; DDisplay *ddisp; l = dia->displays; while (l!=NULL) { ddisp = (DDisplay *) l->data; ddisplay_update_scrollbars(ddisp); l = g_slist_next(l); } if (cur_scale != dia->data->paper.scaling) { diagram_add_update_all(dia); diagram_flush(dia); } } }
/*! * \brief Create a new diagram data object only containing the selected objects * \memberof _DiagramData */ DiagramData * diagram_data_clone_selected (DiagramData *data) { DiagramData *clone; Layer *dest_layer; GList *sorted; clone = g_object_new (DIA_TYPE_DIAGRAM_DATA, NULL); clone->extents = data->extents; clone->bg_color = data->bg_color; clone->paper = data->paper; /* so ugly */ clone->paper.name = g_strdup (data->paper.name); clone->is_compressed = data->is_compressed; /* the selection - if any - can only be on the active layer */ dest_layer = g_ptr_array_index(clone->layers, 0); g_free (dest_layer->name); dest_layer->name = layer_get_name (data->active_layer); sorted = data_get_sorted_selected (data); dest_layer->objects = object_copy_list (sorted); g_list_free (sorted); dest_layer->visible = data->active_layer->visible; dest_layer->connectable = data->active_layer->connectable; data_update_extents (clone); return clone; }
/** Add a layer object to a diagram. * @param data The diagram to add the layer to. * @param layer The layer to add. */ void data_add_layer(DiagramData *data, Layer *layer) { g_ptr_array_add(data->layers, layer); layer->parent_diagram = data; layer_update_extents(layer); data_update_extents(data); }
void dia::DiagramData::update_extents () { g_return_if_fail(self != NULL); data_update_extents(self); // conceptionally const, i.e. read-only *const_cast< ::Rectangle* >(&extents) = self->extents; }
/* * "real" member function implementaion ? */ static PyObject * PyDiaDiagramData_UpdateExtents(PyDiaDiagramData *self, PyObject *args) { if (!PyArg_ParseTuple(args, ":DiagramData.update_extents")) return NULL; data_update_extents(self->data); Py_INCREF(Py_None); return Py_None; }
/*! * \brief Add a layer object to a diagram. * @param data The diagram to add the layer to. * @param layer The layer to add. * \memberof _DiagramData */ void data_add_layer(DiagramData *data, Layer *layer) { g_ptr_array_add(data->layers, layer); layer->parent_diagram = data; data_emit (data, layer, NULL, "object_add"); layer_update_extents(layer); data_update_extents(data); }
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; }
void data_add_layer_at(DiagramData *data, Layer *layer, int pos) { int len; int i; g_ptr_array_add(data->layers, layer); len = data->layers->len; if ( (pos>=0) && (pos < len)) { for (i=len-1;i>pos;i--) { g_ptr_array_index(data->layers, i) = g_ptr_array_index(data->layers, i-1); } g_ptr_array_index(data->layers, pos) = layer; } layer->parent_diagram = data; layer_update_extents(layer); data_update_extents(data); }
/** Convert infname to outfname, using input filter inf and export filter * ef. If either is null, try to guess them. * size might be NULL. */ static gboolean do_convert(const char *infname, const char *outfname, DiaExportFilter *ef, const char *size, char *show_layers) { DiaImportFilter *inf; DiagramData *diagdata = NULL; DiaContext *ctx; inf = filter_guess_import_filter(infname); if (!inf) inf = &dia_import_filter; if (ef == NULL) { ef = filter_guess_export_filter(outfname); if (!ef) { g_critical(_("%s error: don't know how to export into %s\n"), argv0,outfname); exit(1); } } dia_is_interactive = FALSE; if (0==strcmp(infname,outfname)) { g_critical(_("%s error: input and output filenames are identical: %s"), argv0, infname); exit(1); } diagdata = g_object_new (DIA_TYPE_DIAGRAM_DATA, NULL); ctx = dia_context_new(_("Import")); if (!inf->import_func(infname, diagdata, ctx, inf->user_data)) { g_critical(_("%s error: need valid input file %s\n"), argv0, infname); exit(1); } /* Apply --show-layers */ if (show_layers) handle_show_layers(diagdata, show_layers); /* recalculate before export */ data_update_extents(diagdata); /* Do our best in providing the size to the filter, but don't abuse user_data * too much for it. It _must not_ be changed after initialization and there * are quite some filter selecting their output format by it. --hb */ if (size) { if (ef == filter_export_get_by_name ("png-libart")) /* the warning we get is appropriate, don't cast */ ef->export_func(diagdata, ctx, outfname, infname, size); else { g_warning ("--size parameter unsupported for %s filter", ef->unique_name ? ef->unique_name : "selected"); ef->export_func(diagdata, ctx, outfname, infname, ef->user_data); } } else ef->export_func(diagdata, ctx, outfname, infname, ef->user_data); /* if (!quiet) */ fprintf(stdout, _("%s --> %s\n"), infname,outfname); g_object_unref(diagdata); dia_context_release(ctx); return TRUE; }