[dia] [autosave] implement diagram_data_clone()



commit fe09bb6dadaa0f59ad19708d30dcbe4097ce11e5
Author: Hans Breuer <hans breuer org>
Date:   Sun Mar 6 14:14:18 2011 +0100

    [autosave] implement diagram_data_clone()
    
    Cloning the diagram in memory should be much faster than
    creating in memory XML and saving to disk.

 lib/diagramdata.c |   38 ++++++++++++++++++++++++++++++++++++++
 lib/diagramdata.h |    2 ++
 lib/libdia.def    |    2 ++
 3 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/lib/diagramdata.c b/lib/diagramdata.c
index f4c3b32..d2b8d5b 100644
--- a/lib/diagramdata.c
+++ b/lib/diagramdata.c
@@ -131,6 +131,7 @@ diagram_data_init(DiagramData *data)
   data->active_text_edit = NULL;
 }
 
+
 /** Deallocate memory owned by a DiagramData object.
  * @param object A DiagramData object to finalize.
  */
@@ -154,6 +155,43 @@ diagram_data_finalize(GObject *object)
   data->selected_count_private = 0;
 }
 
+
+DiagramData *
+diagram_data_clone (DiagramData *data)
+{
+  DiagramData *clone;
+  guint i;
+  
+  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;
+  
+  layer_destroy(g_ptr_array_index(clone->layers, 0));
+  g_ptr_array_remove(clone->layers, clone->active_layer);
+
+  for (i=0; i < data->layers->len; ++i) {
+    Layer *src_layer = g_ptr_array_index(data->layers, i);
+    Layer *dest_layer = new_layer (layer_get_name (src_layer), clone);
+  
+    /* copy layer, init the active one */
+    dest_layer->extents = src_layer->extents;
+    dest_layer->objects = object_copy_list (src_layer->objects);
+    dest_layer->visible = src_layer->visible;
+    dest_layer->connectable = src_layer->connectable;
+    g_ptr_array_add (clone->layers, dest_layer);
+    if (src_layer == data->active_layer)
+      clone->active_layer = dest_layer;
+      
+    /* the rest should be initialized by construction */
+  }
+
+  return clone;  
+}
+
 /** Initialize the DiagramData class data.
  * @param klass The class object to initialize functions for.
  */
diff --git a/lib/diagramdata.h b/lib/diagramdata.h
index 3e3c296..96fe764 100644
--- a/lib/diagramdata.h
+++ b/lib/diagramdata.h
@@ -176,6 +176,8 @@ void layer_render(Layer *layer, DiaRenderer *renderer, Rectangle *update,
 		  gpointer data,
 		  int active_layer);
 
+DiagramData *diagram_data_clone (DiagramData *data);
+
 int layer_object_get_index(Layer *layer, DiaObject *obj);
 DiaObject *layer_object_get_nth(Layer *layer, guint index);
 int layer_object_count(Layer *layer);
diff --git a/lib/libdia.def b/lib/libdia.def
index bca63ea..513a397 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -150,6 +150,8 @@ EXPORTS
  data_enum
  data_filename
  data_font
+
+ diagram_data_clone
  data_foreach_object
  data_get_sorted_selected
  data_get_sorted_selected_remove



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]