summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9424d13)
raw | patch | inline | side by side (parent: 9424d13)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Fri, 20 Apr 2007 15:48:51 +0000 (15:48 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Fri, 20 Apr 2007 15:48:51 +0000 (15:48 +0000) |
diff --git a/src/desktop.cpp b/src/desktop.cpp
index bd403139ec824bf61dc996dff10c8d6039050586..d9f82934c039c13550c69a7dbee1635c0cba5bde 100644 (file)
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
} else {
//there is no grid present at the moment. add a rectangular grid and make it visible
Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview);
- Inkscape::CanvasGrid::writeNewGridToRepr(repr, "xygrid");
+ Inkscape::CanvasGrid::writeNewGridToRepr(repr, Inkscape::GRID_RECTANGULAR);
grids_visible = true;
sp_canvas_item_show(SP_CANVAS_ITEM(gridgroup));
}
index ddc0c772384287aa1b0523cce5fdd7c0c3df3451..30c858dcc6fe1219d88b9a1e243ca936a56722de 100644 (file)
#define DEFAULTGRIDCOLOR 0x0000FF20
#define DEFAULTGRIDEMPCOLOR 0x0000FF40
+const gchar *grid_name [] = {
+ N_("Rectangular grid"),
+ N_("Axonometric grid")
+};
+const gchar *grid_svgname [] = {
+ "xygrid",
+ "axonomgrid"
+};
+
+// ##########################################################
+// Grid CanvasItem
static void grid_canvasitem_class_init (GridCanvasItemClass *klass);
static void grid_canvasitem_init (GridCanvasItem *grid);
static void grid_canvasitem_destroy (GtkObject *object);
}
}
+
+
+const char *
+CanvasGrid::getName(GridType type)
+{
+ return _(grid_name[type]);
+}
+
+const char *
+CanvasGrid::getSVGName(GridType type)
+{
+ return grid_svgname[type];
+}
+
+GridType
+CanvasGrid::getGridTypeFromSVGName(const char * typestr)
+{
+ if (!typestr) return GRID_RECTANGULAR;
+
+ gint t = 0;
+ for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
+ if (!strcmp(typestr, grid_svgname[t])) break;
+ }
+ return (GridType) t;
+}
+
+GridType
+CanvasGrid::getGridTypeFromName(const char * typestr)
+{
+ if (!typestr) return GRID_RECTANGULAR;
+
+ gint t = 0;
+ for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
+ if (!strcmp(typestr, _(grid_name[t]))) break;
+ }
+ return (GridType) t;
+}
+
+
/*
* writes an <inkscape:grid> child to repr.
*/
void
-CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype)
+CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, GridType gridtype)
{
if (!repr) return;
- if (!gridtype) return;
+ if (gridtype > GRID_MAXTYPENR) return;
// first create the child xml node, then hook it to repr. This order is important, to not set off listeners to repr before the new node is complete.
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(sp_desktop_document(SP_ACTIVE_DESKTOP));
Inkscape::XML::Node *newnode;
newnode = xml_doc->createElement("inkscape:grid");
- newnode->setAttribute("type",gridtype);
+ newnode->setAttribute("type", getSVGName(gridtype));
repr->appendChild(newnode);
@@ -189,15 +239,15 @@ CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype
* Creates a new CanvasGrid object of type gridtype
*/
CanvasGrid*
-CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, const char * gridtype)
+CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, GridType gridtype)
{
if (!in_repr) return NULL;
- if (!gridtype) return NULL;
- if (!strcmp(gridtype,"xygrid")) {
- return (CanvasGrid*) new CanvasXYGrid(nv, in_repr);
- } else if (!strcmp(gridtype,"axonometric")) {
- return (CanvasGrid*) new CanvasAxonomGrid(nv, in_repr);
+ switch (gridtype) {
+ case GRID_RECTANGULAR:
+ return (CanvasGrid*) new CanvasXYGrid(nv, in_repr);
+ case GRID_AXONOMETRIC:
+ return (CanvasGrid*) new CanvasAxonomGrid(nv, in_repr);
}
return NULL;
index 0dde36935169803a8668d8a6ebfba574bd75f629..046653df2e3ae98e20cb153e2afab9b3dcf757bd 100644 (file)
namespace Inkscape {
+
+enum GridType {
+ GRID_RECTANGULAR = 0,
+ GRID_AXONOMETRIC = 1
+};
+#define GRID_MAXTYPENR 1
+
#define INKSCAPE_TYPE_GRID_CANVASITEM (Inkscape::grid_canvasitem_get_type ())
#define INKSCAPE_GRID_CANVASITEM(obj) (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
#define INKSCAPE_GRID_CANVASITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr);
virtual ~CanvasGrid();
- static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, const char * gridtype);
- static void writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype);
+ static const char * getName(GridType type);
+ static const char * getSVGName(GridType type);
+ static GridType getGridTypeFromSVGName(const char * typestr);
+ static GridType getGridTypeFromName(const char * typestr);
+
+ static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, GridType gridtype);
+ static void writeNewGridToRepr(Inkscape::XML::Node * repr, GridType gridtype);
GridCanvasItem * createCanvasItem(SPDesktop * desktop);
diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp
index d8215eaa256707720dd5e22eb7891bd72252180c..809f138a8d28d526dc8b1bfd8412d2197f32e1d3 100644 (file)
--- a/src/sp-namedview.cpp
+++ b/src/sp-namedview.cpp
@@ -430,11 +430,7 @@ sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *des
if (!grid) {
//create grid object
- const char * gridtype = repr->attribute("type");
- if (!gridtype) {
- gridtype = "xygrid"; // use this as default gridtype when none is specified
- repr->setAttribute("type", gridtype);
- }
+ Inkscape::GridType gridtype = Inkscape::CanvasGrid::getGridTypeFromSVGName(repr->attribute("type"));
grid = Inkscape::CanvasGrid::NewGrid(nv, repr, gridtype);
nv->grids = g_slist_append(nv->grids, grid);
}
index f84b1192071d4276df337c34392abd0e65343d29..4a57c6bfc5013b449ce4330138ac6957bedc333e 100644 (file)
Gtk::Label* label_crea_type = manage (new Gtk::Label);
label_crea_type->set_markup (_("Gridtype"));
- _grids_combo_gridtype.append_text(Glib::ustring("xygrid"));
- _grids_combo_gridtype.append_text(Glib::ustring("axonometric"));
- _grids_combo_gridtype.set_active_text(Glib::ustring("xygrid"));
+ for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
+ _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
+ }
+ _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
Gtk::Label* label_def = manage (new Gtk::Label);
label_def->set_markup (_("<b>Defined grids</b>"));
Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
- CanvasGrid::writeNewGridToRepr(repr, typestring.c_str());
+ CanvasGrid::writeNewGridToRepr(repr, CanvasGrid::getGridTypeFromName(typestring.c_str()));
}