[dia] Improved shape export, allows to draw connection points with special shapes.
- From: Steffen Macke <sdteffen src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Improved shape export, allows to draw connection points with special shapes.
- Date: Thu, 23 Aug 2012 19:37:34 +0000 (UTC)
commit c59645ce83f6983b9c0530dadbf8d1790b841cda
Author: Steffen Macke <sdteffen sdteffen de>
Date: Thu Aug 23 21:36:16 2012 +0200
Improved shape export, allows to draw connection points with special shapes.
configure.in | 1 +
plug-ins/shape/shape-export.c | 97 +++++++++++++++++++------
shapes/Makefile.am | 2 +-
shapes/Shape_Design/Makefile.am | 19 +++++
shapes/Shape_Design/connectionpoint.png | Bin 0 -> 266 bytes
shapes/Shape_Design/connectionpoint.shape | 15 ++++
shapes/Shape_Design/mainconnectionpoint.png | Bin 0 -> 253 bytes
shapes/Shape_Design/mainconnectionpoint.shape | 15 ++++
sheets/Makefile.am | 2 +-
sheets/Shape_Design.sheet.in | 13 ++++
10 files changed, 138 insertions(+), 26 deletions(-)
---
diff --git a/configure.in b/configure.in
index aa5890f..9dce17f 100644
--- a/configure.in
+++ b/configure.in
@@ -651,6 +651,7 @@ shapes/MSE/Makefile
shapes/network/Makefile
shapes/Pneumatic/Makefile
shapes/SDL/Makefile
+shapes/Shape_Design/Makefile
shapes/sybase/Makefile
app/Makefile
app/pixmaps/Makefile
diff --git a/plug-ins/shape/shape-export.c b/plug-ins/shape/shape-export.c
index d330621..e196859 100644
--- a/plug-ins/shape/shape-export.c
+++ b/plug-ins/shape/shape-export.c
@@ -46,6 +46,9 @@
/* this matches the setting `100%' setting in dia. */
#define DPCM 20
+#define CONNECTION_POINT_SHAPE "Shape Design - Connection Point"
+#define MAIN_CONNECTION_POINT_SHAPE "Shape Design - Main Connection Point"
+
#include <libxml/entities.h>
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
@@ -58,6 +61,7 @@
#include "intl.h"
#include "message.h"
#include "diagramdata.h"
+#include "object.h"
G_BEGIN_DECLS
@@ -77,6 +81,8 @@ struct _ShapeRenderer
DiaSvgRenderer parent_instance;
xmlNodePtr connection_root;
+ /* True, if Shape_Design connection points are used */
+ gboolean design_connection;
};
struct _ShapeRendererClass
@@ -94,6 +100,10 @@ static void end_render(DiaRenderer *self);
static void draw_line(DiaRenderer *self,
Point *start, Point *end,
Color *line_colour);
+static void
+draw_object(DiaRenderer *self,
+ DiaObject *object,
+ DiaMatrix *matrix);
static void draw_polyline(DiaRenderer *self,
Point *points, int num_points,
Color *line_colour);
@@ -110,7 +120,8 @@ static void draw_ellipse(DiaRenderer *self,
/* helper functions */
static void add_connection_point(ShapeRenderer *renderer,
- Point *point);
+ Point *point, gboolean design_connection,
+ gboolean main_point);
static void add_rectangle_connection_points(ShapeRenderer *renderer,
Point *ul_corner, Point *lr_corner);
static void add_ellipse_connection_points(ShapeRenderer *renderer,
@@ -122,9 +133,7 @@ new_shape_renderer(DiagramData *data, const char *filename)
{
ShapeRenderer *shape_renderer;
DiaSvgRenderer *renderer;
- FILE *file;
char *point;
- xmlNsPtr name_space;
xmlNodePtr xml_node_ptr;
gint i;
gchar *png_filename;
@@ -147,7 +156,7 @@ new_shape_renderer(DiagramData *data, const char *filename)
renderer->doc = xmlNewDoc((const xmlChar *)"1.0");
renderer->doc->encoding = xmlStrdup((const xmlChar *)"UTF-8");
renderer->root = xmlNewDocNode(renderer->doc, NULL, (const xmlChar *)"shape", NULL);
- name_space = xmlNewNs(renderer->root,
+ xmlNewNs(renderer->root,
(const xmlChar *)"http://www.daa.com.au/~james/dia-shape-ns", NULL);
renderer->svg_name_space = xmlNewNs(renderer->root,
@@ -177,6 +186,7 @@ new_shape_renderer(DiagramData *data, const char *filename)
g_free(basename);
g_free(png_filename);
shape_renderer->connection_root = xmlNewChild(renderer->root, NULL, (const xmlChar *)"connections", NULL);
+ shape_renderer->design_connection = FALSE;
xml_node_ptr = xmlNewChild(renderer->root, NULL, (const xmlChar *)"aspectratio",NULL);
xmlSetProp(xml_node_ptr, (const xmlChar *)"type", (const xmlChar *)"fixed");
renderer->root = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"svg", NULL);
@@ -236,6 +246,7 @@ shape_renderer_class_init (ShapeRendererClass *klass)
/* dia svg renderer overwrites */
renderer_class->end_render = end_render;
renderer_class->draw_line = draw_line;
+ renderer_class->draw_object = draw_object;
renderer_class->draw_polyline = draw_polyline;
renderer_class->draw_polygon = draw_polygon;
renderer_class->draw_rect = draw_rect;
@@ -244,6 +255,28 @@ shape_renderer_class_init (ShapeRendererClass *klass)
/* member implementations */
/* full overwrite */
+static void
+draw_object(DiaRenderer *self,
+ DiaObject *object,
+ DiaMatrix *matrix)
+{
+ Point center;
+ ShapeRenderer *renderer = SHAPE_RENDERER(self);
+ gboolean main_point = (0 == strncmp(MAIN_CONNECTION_POINT_SHAPE,
+ object->type->name, strlen(MAIN_CONNECTION_POINT_SHAPE)));
+
+ if ((0 == strncmp(CONNECTION_POINT_SHAPE, object->type->name,
+ strlen(CONNECTION_POINT_SHAPE))) || main_point) {
+ /* add user defined connection point */
+ center.x = (object->bounding_box.left + object->bounding_box.right)/2;
+ center.y = (object->bounding_box.top + object->bounding_box.bottom)/2;
+ add_connection_point(renderer, ¢er, TRUE, main_point);
+ } else {
+ /* use base class implementation */
+ DIA_RENDERER_CLASS(parent_class)->draw_object (self, object, matrix);
+ }
+}
+
static void
end_render(DiaRenderer *self)
{
@@ -268,16 +301,32 @@ end_render(DiaRenderer *self)
static void
add_connection_point (ShapeRenderer *renderer,
- Point *point)
+ Point *point, gboolean design_connection,
+ gboolean main)
{
xmlNodePtr node;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
+ /* Use connection points, drop the auto ones */
+ if(design_connection && !renderer->design_connection) {
+ renderer->design_connection = design_connection;
+ node = renderer->connection_root->parent;
+ xmlUnlinkNode(renderer->connection_root);
+ xmlFree(renderer->connection_root);
+ xmlNewChild(node, NULL, (const xmlChar *)"connections", NULL);
+ }
+ if(!design_connection && renderer->design_connection)
+ return;
+
node = xmlNewChild(renderer->connection_root, NULL, (const xmlChar *)"point", NULL);
g_ascii_formatd(buf, sizeof(buf), "%g", point->x);
xmlSetProp(node, (const xmlChar *)"x", (xmlChar *) buf);
g_ascii_formatd(buf, sizeof(buf), "%g", point->y);
xmlSetProp(node, (const xmlChar *)"y", (xmlChar *) buf);
+ if (main) {
+ xmlSetProp(node, (const xmlChar *)"main", (xmlChar *)"yes");
+ }
+
}
static void
@@ -292,11 +341,11 @@ draw_line(DiaRenderer *self,
DIA_RENDERER_CLASS(parent_class)->draw_line (self, start, end, line_colour);
/* do our own stuff */
- add_connection_point(renderer, start);
- add_connection_point(renderer, end);
+ add_connection_point(renderer, start, FALSE, FALSE);
+ add_connection_point(renderer, end, FALSE, FALSE);
center.x = (start->x + end->x)/2;
center.y = (start->y + end->y)/2;
- add_connection_point(renderer, ¢er);
+ add_connection_point(renderer, ¢er, FALSE, FALSE);
}
@@ -324,14 +373,14 @@ draw_polyline(DiaRenderer *self,
g_string_append_printf(str, "%s,%s ",
g_ascii_formatd(px_buf, sizeof(px_buf), "%g", points[i].x),
g_ascii_formatd(py_buf, sizeof(py_buf), "%g", points[i].y) );
- add_connection_point(SHAPE_RENDERER(self), &points[i]);
+ add_connection_point(SHAPE_RENDERER(self), &points[i], FALSE, FALSE);
}
xmlSetProp(node, (const xmlChar *)"points", (xmlChar *) str->str);
g_string_free(str, TRUE);
for(i = 1; i < num_points; i++) {
center.x = (points[i].x + points[i-1].x)/2;
center.y = (points[i].y + points[i-1].y)/2;
- add_connection_point(SHAPE_RENDERER(renderer), ¢er);
+ add_connection_point(SHAPE_RENDERER(renderer), ¢er, FALSE, FALSE);
}
}
@@ -360,12 +409,12 @@ draw_polygon(DiaRenderer *self,
g_string_append_printf(str, "%s,%s ",
g_ascii_formatd(px_buf, sizeof(px_buf), "%g", points[i].x),
g_ascii_formatd(py_buf, sizeof(py_buf), "%g", points[i].y) );
- add_connection_point(SHAPE_RENDERER(self), &points[i]);
+ add_connection_point(SHAPE_RENDERER(self), &points[i], FALSE, FALSE);
}
for(i = 1; i < num_points; i++) {
center.x = (points[i].x + points[i-1].x)/2;
center.y = (points[i].y + points[i-1].y)/2;
- add_connection_point(SHAPE_RENDERER(self), ¢er);
+ add_connection_point(SHAPE_RENDERER(self), ¢er, FALSE, FALSE);
}
xmlSetProp(node, (const xmlChar *)"points", (xmlChar *) str->str);
g_string_free(str, TRUE);
@@ -381,25 +430,25 @@ add_rectangle_connection_points (ShapeRenderer *renderer,
center_x = (ul_corner->x + lr_corner->x)/2;
center_y = (ul_corner->y + lr_corner->y)/2;
- add_connection_point(renderer, ul_corner);
- add_connection_point(renderer, lr_corner);
+ add_connection_point(renderer, ul_corner, FALSE, FALSE);
+ add_connection_point(renderer, lr_corner, FALSE, FALSE);
connection.x = ul_corner->x;
connection.y = lr_corner->y;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
connection.y = center_y;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
connection.x = lr_corner->x;
connection.y = ul_corner->y;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
connection.y = center_y;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
connection.x = center_x;
connection.y = lr_corner->y;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
connection.y = ul_corner->y;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
}
@@ -425,15 +474,15 @@ add_ellipse_connection_points (ShapeRenderer *renderer,
connection.x = center->x;
connection.y = center->y + height/2;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
connection.y = center->y - height/2;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
connection.y = center->y;
connection.x = center->x - width/2;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
connection.x = center->x + width/2;
- add_connection_point(renderer, &connection);
+ add_connection_point(renderer, &connection, FALSE, FALSE);
}
static void
diff --git a/shapes/Makefile.am b/shapes/Makefile.am
index e30f234..044ec3c 100644
--- a/shapes/Makefile.am
+++ b/shapes/Makefile.am
@@ -1,7 +1,7 @@
SUBDIRS = Circuit flowchart Contact network Pneumatic Electric \
Civil jigsaw MSE SDL Logic sybase Misc Assorted Cisco \
- Cybernetics Map ChemEng Gane_and_Sarson BPMN Lights
+ Cybernetics Map ChemEng Gane_and_Sarson BPMN Lights Shape_Design
diff --git a/shapes/Shape_Design/Makefile.am b/shapes/Shape_Design/Makefile.am
new file mode 100644
index 0000000..3d7c0ef
--- /dev/null
+++ b/shapes/Shape_Design/Makefile.am
@@ -0,0 +1,19 @@
+
+shapedir = $(pkgdatadir)/Shape_Design
+
+Shape_Designdir = $(shapedir)/Misc
+
+SHAPES = \
+ connectionpoint.png \
+ connectionpoint.shape \
+ mainconnectionpoint.png \
+ mainconnectionpoint.shape
+
+EXTRA_DIST = $(SHAPES)
+
+Shape_Design_DATA = $(SHAPES)
+
+
+
+
+
diff --git a/shapes/Shape_Design/connectionpoint.png b/shapes/Shape_Design/connectionpoint.png
new file mode 100644
index 0000000..16de8f7
Binary files /dev/null and b/shapes/Shape_Design/connectionpoint.png differ
diff --git a/shapes/Shape_Design/connectionpoint.shape b/shapes/Shape_Design/connectionpoint.shape
new file mode 100644
index 0000000..bf20919
--- /dev/null
+++ b/shapes/Shape_Design/connectionpoint.shape
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<shape xmlns="http://www.daa.com.au/~james/dia-shape-ns" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <name>Shape Design - Connection Point</name>
+ <icon>connectionpoint.png</icon>
+ <connections>
+ <point x="1" y="1" main="yes"/>
+ </connections>
+ <default-width>0.5cm</default-width>
+ <default-height>0.5cm</default-height>
+ <aspectratio type="fixed"/>
+ <svg:svg>
+ <svg:line x1="0" y1="0" x2="2" y2="2"/>
+ <svg:line x1="0" y1="2" x2="2" y2="0"/>
+ </svg:svg>
+</shape>
diff --git a/shapes/Shape_Design/mainconnectionpoint.png b/shapes/Shape_Design/mainconnectionpoint.png
new file mode 100644
index 0000000..82a0c1a
Binary files /dev/null and b/shapes/Shape_Design/mainconnectionpoint.png differ
diff --git a/shapes/Shape_Design/mainconnectionpoint.shape b/shapes/Shape_Design/mainconnectionpoint.shape
new file mode 100644
index 0000000..d7dcc26
--- /dev/null
+++ b/shapes/Shape_Design/mainconnectionpoint.shape
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<shape xmlns="http://www.daa.com.au/~james/dia-shape-ns" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <name>Shape Design - Main Connection Point</name>
+ <icon>mainconnectionpoint.png</icon>
+ <connections>
+ <point x="1" y="1" main="yes"/>
+ </connections>
+ <default-width>0.5cm</default-width>
+ <default-height>0.5cm</default-height>
+ <aspectratio type="fixed"/>
+ <svg:svg>
+ <svg:line style="stroke: #ff0000;" x1="0" y1="0" x2="2" y2="2"/>
+ <svg:line style="stroke: #ff0000;" x1="0" y1="2" x2="2" y2="0"/>
+ </svg:svg>
+</shape>
diff --git a/sheets/Makefile.am b/sheets/Makefile.am
index 37a7d45..77f929c 100644
--- a/sheets/Makefile.am
+++ b/sheets/Makefile.am
@@ -13,7 +13,7 @@ sheet_in_files = \
ciscotelephony.sheet.in Cybernetics.sheet.in IsometricMap.sheet.in \
Istar.sheet.in Jackson.sheet.in KAOS.sheet.in ChemEng.sheet.in \
AADL.sheet.in Gane_and_Sarson.sheet.in BPMN.sheet.in \
- Lights.sheet.in Database.sheet.in
+ Lights.sheet.in Database.sheet.in Shape_Design.sheet.in
SHEETS = $(sheet_in_files:.sheet.in=.sheet)
diff --git a/sheets/Shape_Design.sheet.in b/sheets/Shape_Design.sheet.in
new file mode 100644
index 0000000..c3fd25b
--- /dev/null
+++ b/sheets/Shape_Design.sheet.in
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sheet xmlns="http://www.lysator.liu.se/~alla/dia/dia-sheet-ns">
+ <_name>Shape Design</_name>
+ <_description>Design Dia objects with individual connection points</_description>
+ <contents>
+ <object name="Shape Design - Connection Point">
+ <_description>Connection Point</_description>
+ </object>
+ <object name="Shape Design - Main Connection Point">
+ <_description>Main Connection Point</_description>
+ </object>
+ </contents>
+</sheet>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]