From c81b4a521a9b470412f06bb6db168847f2ecc507 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 19:02:28 +0200 Subject: Added "virtual pad" to SPPath. (bzr r11608.1.8) --- src/sp-path.cpp | 186 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 123 insertions(+), 63 deletions(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 107ceac16..d58242a38 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -129,9 +129,9 @@ gint SPPath::nodesInPath() const return _curve ? _curve->nodes_in_path() : 0; } -static gchar * -sp_path_description(SPItem * item) -{ +gchar* CPath::onDescription() { + SPPath* item = this->sppath; + int count = SP_PATH(item)->nodesInPath(); if (SP_IS_LPE_ITEM(item) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) { @@ -157,10 +157,16 @@ sp_path_description(SPItem * item) } } -static void -sp_path_convert_to_guides(SPItem *item) +// CPPIFY: remove +static gchar * +sp_path_description(SPItem * item) { - SPPath *path = SP_PATH(item); + return ((SPPath*)item)->cpath->onDescription(); +} + +void CPath::onConvertToGuides() { + SPPath* item = this->sppath; + SPPath *path = item; if (!path->_curve) { return; @@ -184,12 +190,32 @@ sp_path_convert_to_guides(SPItem *item) sp_guide_pt_pairs_to_guides(item->document, pts); } +// CPPIFY: remove +static void +sp_path_convert_to_guides(SPItem *item) +{ + ((SPPath*)item)->cpath->onConvertToGuides(); +} + +CPath::CPath(SPPath* path) : CShape(path) { + this->sppath = path; +} + +CPath::~CPath() { +} + /** * Initializes an SPPath. */ static void sp_path_init(SPPath *path) { + path->cpath = new CPath(path); + path->cshape = path->cpath; + path->clpeitem = path->cpath; + path->citem = path->cpath; + path->cobject = path->cpath; + new (&path->connEndPair) SPConnEndPair(path); } @@ -201,13 +227,9 @@ sp_path_finalize(GObject *obj) path->connEndPair.~SPConnEndPair(); } -/** - * Given a repr, this sets the data items in the path object such as - * fill & style attributes, markers, and CSS properties. - */ -static void -sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ +void CPath::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPPath* object = this->sppath; + /* Are these calls actually necessary? */ object->readAttr( "marker" ); object->readAttr( "marker-start" ); @@ -216,9 +238,7 @@ sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) sp_conn_end_pair_build(object); - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build(object, document, repr); - } + CShape::onBuild(document, repr); object->readAttr( "inkscape:original-d" ); object->readAttr( "d" ); @@ -230,25 +250,35 @@ sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) } } +// CPPIFY: remove +/** + * Given a repr, this sets the data items in the path object such as + * fill & style attributes, markers, and CSS properties. + */ static void -sp_path_release(SPObject *object) +sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPPath *path = SP_PATH(object); + ((SPPath*)object)->cpath->onBuild(document, repr); +} + +void CPath::onRelease() { + SPPath* object = this->sppath; + SPPath *path = object; path->connEndPair.release(); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); - } + CShape::onRelease(); } -/** - * Sets a value in the path object given by 'key', to 'value'. This is used - * for setting attributes and markers on a path object. - */ +// CPPIFY: remove static void -sp_path_set(SPObject *object, unsigned int key, gchar const *value) +sp_path_release(SPObject *object) { + ((SPPath*)object)->cpath->onRelease(); +} + +void CPath::onSet(unsigned int key, const gchar* value) { + SPPath* object = this->sppath; SPPath *path = (SPPath *) object; switch (key) { @@ -294,21 +324,25 @@ sp_path_set(SPObject *object, unsigned int key, gchar const *value) path->connEndPair.setAttr(key, value); break; default: - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); - } + CShape::onSet(key, value); break; } } +// CPPIFY: remove /** - * - * Writes the path object into a Inkscape::XML::Node + * Sets a value in the path object given by 'key', to 'value'. This is used + * for setting attributes and markers on a path object. */ -static Inkscape::XML::Node * -sp_path_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void +sp_path_set(SPObject *object, unsigned int key, gchar const *value) { - SPShape *shape = (SPShape *) object; + ((SPPath*)object)->cpath->onSet(key, value); +} + +Inkscape::XML::Node* CPath::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPPath* object = this->sppath; + SPShape *shape = (SPShape *) object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); @@ -337,35 +371,45 @@ g_message("sp_path_write writes 'd' attribute"); SP_PATH(shape)->connEndPair.writeRepr(repr); - if (((SPObjectClass *)(parent_class))->write) { - ((SPObjectClass *)(parent_class))->write(object, xml_doc, repr, flags); - } + CShape::onWrite(xml_doc, repr, flags); return repr; } -static void -sp_path_update(SPObject *object, SPCtx *ctx, guint flags) +// CPPIFY: remove +/** + * + * Writes the path object into a Inkscape::XML::Node + */ +static Inkscape::XML::Node * +sp_path_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore - } + return ((SPPath*)object)->cpath->onWrite(xml_doc, repr, flags); +} - if (((SPObjectClass *) parent_class)->update) { - ((SPObjectClass *) parent_class)->update(object, ctx, flags); - } +void CPath::onUpdate(SPCtx *ctx, guint flags) { + SPPath* object = this->sppath; - SPPath *path = SP_PATH(object); - path->connEndPair.update(); -} + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore + } + CShape::onUpdate(ctx, flags); -/** - * Writes the given transform into the repr for the given item. - */ -static Geom::Affine -sp_path_set_transform(SPItem *item, Geom::Affine const &xform) + SPPath *path = SP_PATH(object); + path->connEndPair.update(); +} + +// CPPIFY: remove +static void +sp_path_update(SPObject *object, SPCtx *ctx, guint flags) { + ((SPPath*)object)->cpath->onUpdate(ctx, flags); +} + +Geom::Affine CPath::onSetTransform(Geom::Affine const &transform) { + SPPath* item = this->sppath; + if (!SP_IS_PATH(item)) { return Geom::identity(); } @@ -379,25 +423,25 @@ sp_path_set_transform(SPItem *item, Geom::Affine const &xform) if (path->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(item))) { if (sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(item), Inkscape::LivePathEffect::CLONE_ORIGINAL)) { // if path has the CLONE_ORIGINAL LPE applied, don't write the transform to the pathdata, but write it 'unoptimized' - return xform; + return transform; } else { - path->_curve_before_lpe->transform(xform); + path->_curve_before_lpe->transform(transform); } } else { - path->_curve->transform(xform); + path->_curve->transform(transform); } // Adjust stroke - item->adjust_stroke(xform.descrim()); + item->adjust_stroke(transform.descrim()); // Adjust pattern fill - item->adjust_pattern(xform); + item->adjust_pattern(transform); // Adjust gradient fill - item->adjust_gradient(xform); + item->adjust_gradient(transform); // Adjust LPE - item->adjust_livepatheffect(xform); + item->adjust_livepatheffect(transform); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); @@ -405,11 +449,20 @@ sp_path_set_transform(SPItem *item, Geom::Affine const &xform) return Geom::identity(); } - -static void -sp_path_update_patheffect(SPLPEItem *lpeitem, bool write) +// CPPIFY: remove +/** + * Writes the given transform into the repr for the given item. + */ +static Geom::Affine +sp_path_set_transform(SPItem *item, Geom::Affine const &xform) { + return ((SPPath*)item)->cpath->onSetTransform(xform); +} + +void CPath::onUpdatePatheffect(bool write) { + SPPath* lpeitem = this->sppath; SPShape * const shape = (SPShape *) lpeitem; + Inkscape::XML::Node *repr = shape->getRepr(); #ifdef PATH_VERBOSE @@ -451,6 +504,13 @@ g_message("sp_path_update_patheffect writes 'd' attribute"); } } +// CPPIFY: remove +static void +sp_path_update_patheffect(SPLPEItem *lpeitem, bool write) +{ + ((SPPath*)lpeitem)->cpath->onUpdatePatheffect(write); +} + /** * Adds a original_curve to the path. If owner is specified, a reference -- cgit v1.2.3 From 260c7156ca920232cca2e829782373a805d59cae Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 29 Sep 2012 17:43:15 +0200 Subject: Removed old calls to set_shape and update_patheffect. (bzr r11608.1.45) --- src/sp-path.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index d58242a38..d68e87d29 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -120,7 +120,7 @@ sp_path_class_init(SPPathClass * klass) item_class->set_transform = sp_path_set_transform; item_class->convert_to_guides = sp_path_convert_to_guides; - lpe_item_class->update_patheffect = sp_path_update_patheffect; + //lpe_item_class->update_patheffect = sp_path_update_patheffect; } -- cgit v1.2.3 From 99cb30e28d4ee193f39e23464abbd7630cac8a2d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 6 Oct 2012 23:56:27 +0200 Subject: Added virtual pad to SPFlowtext; removed old calls to virtual SPItem methods. (bzr r11608.1.46) --- src/sp-path.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index d68e87d29..f96e516b7 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -116,9 +116,9 @@ sp_path_class_init(SPPathClass * klass) sp_object_class->write = sp_path_write; sp_object_class->update = sp_path_update; - item_class->description = sp_path_description; - item_class->set_transform = sp_path_set_transform; - item_class->convert_to_guides = sp_path_convert_to_guides; +// item_class->description = sp_path_description; +// item_class->set_transform = sp_path_set_transform; +// item_class->convert_to_guides = sp_path_convert_to_guides; //lpe_item_class->update_patheffect = sp_path_update_patheffect; } -- cgit v1.2.3 From a0a8d020201e0e38a63d9aa3dce228d7d9e6fb35 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 14 Mar 2013 12:42:39 +0100 Subject: Various changes. (bzr r11608.1.48) --- src/sp-path.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index f96e516b7..fd726c9fe 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -110,7 +110,7 @@ sp_path_class_init(SPPathClass * klass) gobject_class->finalize = sp_path_finalize; - sp_object_class->build = sp_path_build; + //sp_object_class->build = sp_path_build; sp_object_class->release = sp_path_release; sp_object_class->set = sp_path_set; sp_object_class->write = sp_path_write; -- cgit v1.2.3 From 957c3e4b7909d42c5a13f1b1dd583f877fc32259 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:46:57 +0100 Subject: Removed function pointers from SPObject and subclasses. Added some missing virtual pads for classes that were hidden by preprocessor macros. (bzr r11608.1.55) --- src/sp-path.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index fd726c9fe..820fbbaf6 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -111,10 +111,10 @@ sp_path_class_init(SPPathClass * klass) gobject_class->finalize = sp_path_finalize; //sp_object_class->build = sp_path_build; - sp_object_class->release = sp_path_release; - sp_object_class->set = sp_path_set; - sp_object_class->write = sp_path_write; - sp_object_class->update = sp_path_update; +// sp_object_class->release = sp_path_release; +// sp_object_class->set = sp_path_set; +// sp_object_class->write = sp_path_write; +// sp_object_class->update = sp_path_update; // item_class->description = sp_path_description; // item_class->set_transform = sp_path_set_transform; -- cgit v1.2.3 From 7df6616da5ea2debb86838366ddf746841549cdb Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:56:13 +0100 Subject: Renamed virtual function names. (bzr r11608.1.57) --- src/sp-path.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index b228781d0..cc469d027 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -73,7 +73,7 @@ gint SPPath::nodesInPath() const return _curve ? _curve->nodes_in_path() : 0; } -gchar* CPath::onDescription() { +gchar* CPath::description() { SPPath* item = this->sppath; int count = SP_PATH(item)->nodesInPath(); @@ -101,7 +101,7 @@ gchar* CPath::onDescription() { } } -void CPath::onConvertToGuides() { +void CPath::convert_to_guides() { SPPath* item = this->sppath; SPPath *path = item; @@ -159,7 +159,7 @@ sp_path_finalize(GObject *obj) path->connEndPair.~SPConnEndPair(); } -void CPath::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { +void CPath::build(SPDocument *document, Inkscape::XML::Node *repr) { SPPath* object = this->sppath; /* Are these calls actually necessary? */ @@ -170,7 +170,7 @@ void CPath::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { sp_conn_end_pair_build(object); - CShape::onBuild(document, repr); + CShape::build(document, repr); object->readAttr( "inkscape:original-d" ); object->readAttr( "d" ); @@ -182,17 +182,17 @@ void CPath::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { } } -void CPath::onRelease() { +void CPath::release() { SPPath* object = this->sppath; SPPath *path = object; path->connEndPair.release(); - CShape::onRelease(); + CShape::release(); } -void CPath::onSet(unsigned int key, const gchar* value) { +void CPath::set(unsigned int key, const gchar* value) { SPPath* object = this->sppath; SPPath *path = (SPPath *) object; @@ -239,12 +239,12 @@ void CPath::onSet(unsigned int key, const gchar* value) { path->connEndPair.setAttr(key, value); break; default: - CShape::onSet(key, value); + CShape::set(key, value); break; } } -Inkscape::XML::Node* CPath::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +Inkscape::XML::Node* CPath::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPPath* object = this->sppath; SPShape *shape = (SPShape *) object; @@ -275,26 +275,26 @@ g_message("sp_path_write writes 'd' attribute"); SP_PATH(shape)->connEndPair.writeRepr(repr); - CShape::onWrite(xml_doc, repr, flags); + CShape::write(xml_doc, repr, flags); return repr; } -void CPath::onUpdate(SPCtx *ctx, guint flags) { +void CPath::update(SPCtx *ctx, guint flags) { SPPath* object = this->sppath; if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } - CShape::onUpdate(ctx, flags); + CShape::update(ctx, flags); SPPath *path = SP_PATH(object); path->connEndPair.update(); } -Geom::Affine CPath::onSetTransform(Geom::Affine const &transform) { +Geom::Affine CPath::set_transform(Geom::Affine const &transform) { SPPath* item = this->sppath; if (!SP_IS_PATH(item)) { @@ -337,7 +337,7 @@ Geom::Affine CPath::onSetTransform(Geom::Affine const &transform) { } -void CPath::onUpdatePatheffect(bool write) { +void CPath::update_patheffect(bool write) { SPPath* lpeitem = this->sppath; SPShape * const shape = (SPShape *) lpeitem; -- cgit v1.2.3 From a5d6e692d661f0bf7648e64e8fcb04588bb8f3ab Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 1 Apr 2013 00:07:00 +0200 Subject: Prepared exchange of casting macros. (bzr r11608.1.63) --- src/sp-path.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index cc469d027..43bf0a6a2 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -141,6 +141,7 @@ static void sp_path_init(SPPath *path) { path->cpath = new CPath(path); + path->typeHierarchy.insert(typeid(SPPath)); delete path->cshape; path->cshape = path->cpath; -- cgit v1.2.3 From 69f3b6f1abb2bb422935d43262e1e99aab359954 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 01:41:30 +0200 Subject: Added constructors to SP classes. (bzr r11608.1.67) --- src/sp-path.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 43bf0a6a2..132415e51 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -53,7 +53,7 @@ static void sp_path_finalize(GObject *obj); -G_DEFINE_TYPE(SPPath, sp_path, SP_TYPE_SHAPE); +G_DEFINE_TYPE(SPPath, sp_path, G_TYPE_OBJECT); /** * Does the object-oriented work of initializing the class structure @@ -134,12 +134,9 @@ CPath::CPath(SPPath* path) : CShape(path) { CPath::~CPath() { } -/** - * Initializes an SPPath. - */ -static void -sp_path_init(SPPath *path) -{ +SPPath::SPPath() : SPShape(), connEndPair(this) { + SPPath* path = this; + path->cpath = new CPath(path); path->typeHierarchy.insert(typeid(SPPath)); @@ -149,7 +146,16 @@ sp_path_init(SPPath *path) path->citem = path->cpath; path->cobject = path->cpath; - new (&path->connEndPair) SPConnEndPair(path); + //new (&path->connEndPair) SPConnEndPair(path); +} + +/** + * Initializes an SPPath. + */ +static void +sp_path_init(SPPath *path) +{ + new (path) SPPath(); } static void -- cgit v1.2.3 From d1af3566872dfff2aeec84859c87f1f8d13f79df Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 19:14:36 +0200 Subject: Registered classes with new factory. Hkern, Vkern and FeFuncX have to be rewritten, as they aren't real classes. (bzr r11608.1.69) --- src/sp-path.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 132415e51..bc6a2cb21 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -51,6 +51,17 @@ #define noPATH_VERBOSE +#include "sp-factory.h" + +namespace { + SPObject* createPath() { + return new SPPath(); + } + + bool pathRegistered = SPFactory::instance().registerObject("svg:path", createPath); +} + + static void sp_path_finalize(GObject *obj); G_DEFINE_TYPE(SPPath, sp_path, G_TYPE_OBJECT); -- cgit v1.2.3 From 8443720ce6429b9beec839e60b8a808595f4ba72 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 23:01:45 +0200 Subject: Cleaned up a bit. Uses some C++11 features. (bzr r11608.1.72) --- src/sp-path.cpp | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index bc6a2cb21..394b815fb 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -61,24 +61,6 @@ namespace { bool pathRegistered = SPFactory::instance().registerObject("svg:path", createPath); } - -static void sp_path_finalize(GObject *obj); - -G_DEFINE_TYPE(SPPath, sp_path, G_TYPE_OBJECT); - -/** - * Does the object-oriented work of initializing the class structure - * including parent class, and registers function pointers for - * the functions build, set, write, and set_transform. - */ -static void -sp_path_class_init(SPPathClass * klass) -{ - GObjectClass *gobject_class = (GObjectClass *) klass; - gobject_class->finalize = sp_path_finalize; -} - - gint SPPath::nodesInPath() const { return _curve ? _curve->nodes_in_path() : 0; @@ -156,25 +138,9 @@ SPPath::SPPath() : SPShape(), connEndPair(this) { path->clpeitem = path->cpath; path->citem = path->cpath; path->cobject = path->cpath; - - //new (&path->connEndPair) SPConnEndPair(path); -} - -/** - * Initializes an SPPath. - */ -static void -sp_path_init(SPPath *path) -{ - new (path) SPPath(); } -static void -sp_path_finalize(GObject *obj) -{ - SPPath *path = (SPPath *) obj; - - path->connEndPair.~SPConnEndPair(); +SPPath::~SPPath() { } void CPath::build(SPDocument *document, Inkscape::XML::Node *repr) { -- cgit v1.2.3 From 748ffce08bb6250c87adabb64f45bff02509e9e7 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 00:27:58 +0200 Subject: Combined some classes. (bzr r11608.1.75) --- src/sp-path.cpp | 250 ++++++++++++++++++++++++++------------------------------ 1 file changed, 114 insertions(+), 136 deletions(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 394b815fb..06167e6dd 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -66,24 +66,26 @@ gint SPPath::nodesInPath() const return _curve ? _curve->nodes_in_path() : 0; } -gchar* CPath::description() { - SPPath* item = this->sppath; - - int count = SP_PATH(item)->nodesInPath(); - if (SP_IS_LPE_ITEM(item) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) { - +gchar* SPPath::description() { + int count = this->nodesInPath(); + + if (sp_lpe_item_has_path_effect(this)) { Glib::ustring s; - - PathEffectList effect_list = sp_lpe_item_get_effect_list(SP_LPE_ITEM(item)); + PathEffectList effect_list = sp_lpe_item_get_effect_list(this); + for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); ++it) { LivePathEffectObject *lpeobj = (*it)->lpeobject; - if (!lpeobj || !lpeobj->get_lpe()) + + if (!lpeobj || !lpeobj->get_lpe()) { break; - if (s.empty()) + } + + if (s.empty()) { s = lpeobj->get_lpe()->getName(); - else + } else { s = s + ", " + lpeobj->get_lpe()->getName(); + } } return g_strdup_printf(ngettext("Path (%i node, path effect: %s)", @@ -94,19 +96,16 @@ gchar* CPath::description() { } } -void CPath::convert_to_guides() { - SPPath* item = this->sppath; - SPPath *path = item; - - if (!path->_curve) { +void SPPath::convert_to_guides() { + if (!this->_curve) { return; } std::list > pts; - Geom::Affine const i2dt(path->i2dt_affine()); - - Geom::PathVector const & pv = path->_curve->get_pathvector(); + Geom::Affine const i2dt(this->i2dt_affine()); + Geom::PathVector const & pv = this->_curve->get_pathvector(); + for(Geom::PathVector::const_iterator pit = pv.begin(); pit != pv.end(); ++pit) { for(Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_default(); ++cit) { // only add curves for straight line segments @@ -117,121 +116,106 @@ void CPath::convert_to_guides() { } } - sp_guide_pt_pairs_to_guides(item->document, pts); + sp_guide_pt_pairs_to_guides(this->document, pts); } -CPath::CPath(SPPath* path) : CShape(path) { - this->sppath = path; -} - -CPath::~CPath() { -} - -SPPath::SPPath() : SPShape(), connEndPair(this) { - SPPath* path = this; - - path->cpath = new CPath(path); - path->typeHierarchy.insert(typeid(SPPath)); - - delete path->cshape; - path->cshape = path->cpath; - path->clpeitem = path->cpath; - path->citem = path->cpath; - path->cobject = path->cpath; +SPPath::SPPath() : SPShape(), CShape(this), connEndPair(this) { + delete this->cshape; + this->cshape = this; + this->clpeitem = this; + this->citem = this; + this->cobject = this; } SPPath::~SPPath() { } -void CPath::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPPath* object = this->sppath; - +void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) { /* Are these calls actually necessary? */ - object->readAttr( "marker" ); - object->readAttr( "marker-start" ); - object->readAttr( "marker-mid" ); - object->readAttr( "marker-end" ); + this->readAttr( "marker" ); + this->readAttr( "marker-start" ); + this->readAttr( "marker-mid" ); + this->readAttr( "marker-end" ); - sp_conn_end_pair_build(object); + sp_conn_end_pair_build(this); CShape::build(document, repr); - object->readAttr( "inkscape:original-d" ); - object->readAttr( "d" ); + this->readAttr( "inkscape:original-d" ); + this->readAttr( "d" ); /* d is a required attribute */ - gchar const *d = object->getAttribute("d", NULL); + gchar const *d = this->getAttribute("d", NULL); + if (d == NULL) { - object->setKeyValue( sp_attribute_lookup("d"), ""); + this->setKeyValue( sp_attribute_lookup("d"), ""); } } -void CPath::release() { - SPPath* object = this->sppath; - SPPath *path = object; - - path->connEndPair.release(); +void SPPath::release() { + this->connEndPair.release(); CShape::release(); } - -void CPath::set(unsigned int key, const gchar* value) { - SPPath* object = this->sppath; - SPPath *path = (SPPath *) object; - +void SPPath::set(unsigned int key, const gchar* value) { switch (key) { case SP_ATTR_INKSCAPE_ORIGINAL_D: - if (value) { - Geom::PathVector pv = sp_svg_read_pathv(value); - SPCurve *curve = new SPCurve(pv); - if (curve) { - path->set_original_curve(curve, TRUE, true); - curve->unref(); - } - } else { - path->set_original_curve(NULL, TRUE, true); - } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + if (value) { + Geom::PathVector pv = sp_svg_read_pathv(value); + SPCurve *curve = new SPCurve(pv); + + if (curve) { + this->set_original_curve(curve, TRUE, true); + curve->unref(); + } + } else { + this->set_original_curve(NULL, TRUE, true); + } + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_D: - if (value) { - Geom::PathVector pv = sp_svg_read_pathv(value); - SPCurve *curve = new SPCurve(pv); - if (curve) { - ((SPShape *) path)->setCurve(curve, TRUE); - curve->unref(); - } - } else { - ((SPShape *) path)->setCurve(NULL, TRUE); - } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + if (value) { + Geom::PathVector pv = sp_svg_read_pathv(value); + SPCurve *curve = new SPCurve(pv); + + if (curve) { + this->setCurve(curve, TRUE); + curve->unref(); + } + } else { + this->setCurve(NULL, TRUE); + } + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_PROP_MARKER: case SP_PROP_MARKER_START: case SP_PROP_MARKER_MID: case SP_PROP_MARKER_END: - sp_shape_set_marker(object, key, value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + sp_shape_set_marker(this, key, value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_CONNECTOR_TYPE: case SP_ATTR_CONNECTOR_CURVATURE: case SP_ATTR_CONNECTION_START: case SP_ATTR_CONNECTION_END: case SP_ATTR_CONNECTION_START_POINT: case SP_ATTR_CONNECTION_END_POINT: - path->connEndPair.setAttr(key, value); + this->connEndPair.setAttr(key, value); break; + default: CShape::set(key, value); break; } } -Inkscape::XML::Node* CPath::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPPath* object = this->sppath; - SPShape *shape = (SPShape *) object; - +Inkscape::XML::Node* SPPath::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); } @@ -239,8 +223,9 @@ Inkscape::XML::Node* CPath::write(Inkscape::XML::Document *xml_doc, Inkscape::XM #ifdef PATH_VERBOSE g_message("sp_path_write writes 'd' attribute"); #endif - if ( shape->_curve != NULL ) { - gchar *str = sp_svg_write_path(shape->_curve->get_pathvector()); + + if ( this->_curve != NULL ) { + gchar *str = sp_svg_write_path(this->_curve->get_pathvector()); repr->setAttribute("d", str); g_free(str); } else { @@ -248,8 +233,8 @@ g_message("sp_path_write writes 'd' attribute"); } if (flags & SP_OBJECT_WRITE_EXT) { - if ( shape->_curve_before_lpe != NULL ) { - gchar *str = sp_svg_write_path(shape->_curve_before_lpe->get_pathvector()); + if ( this->_curve_before_lpe != NULL ) { + gchar *str = sp_svg_write_path(this->_curve_before_lpe->get_pathvector()); repr->setAttribute("inkscape:original-d", str); g_free(str); } else { @@ -257,94 +242,82 @@ g_message("sp_path_write writes 'd' attribute"); } } - SP_PATH(shape)->connEndPair.writeRepr(repr); + this->connEndPair.writeRepr(repr); CShape::write(xml_doc, repr, flags); return repr; } -void CPath::update(SPCtx *ctx, guint flags) { - SPPath* object = this->sppath; - +void SPPath::update(SPCtx *ctx, guint flags) { if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore - } + flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore + } - CShape::update(ctx, flags); + CShape::update(ctx, flags); - SPPath *path = SP_PATH(object); - path->connEndPair.update(); + this->connEndPair.update(); } - -Geom::Affine CPath::set_transform(Geom::Affine const &transform) { - SPPath* item = this->sppath; - - if (!SP_IS_PATH(item)) { +Geom::Affine SPPath::set_transform(Geom::Affine const &transform) { + if (!this->_curve) { // 0 nodes, nothing to transform return Geom::identity(); } - SPPath *path = SP_PATH(item); - if (!path->_curve) { // 0 nodes, nothing to transform - return Geom::identity(); - } - - // Transform the original-d path if this is a valid LPE item, other else the (ordinary) path - if (path->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(item))) { - if (sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(item), Inkscape::LivePathEffect::CLONE_ORIGINAL)) { + // Transform the original-d path if this is a valid LPE this, other else the (ordinary) path + if (this->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(this)) { + if (sp_lpe_item_has_path_effect_of_type(this, Inkscape::LivePathEffect::CLONE_ORIGINAL)) { // if path has the CLONE_ORIGINAL LPE applied, don't write the transform to the pathdata, but write it 'unoptimized' return transform; } else { - path->_curve_before_lpe->transform(transform); + this->_curve_before_lpe->transform(transform); } } else { - path->_curve->transform(transform); + this->_curve->transform(transform); } // Adjust stroke - item->adjust_stroke(transform.descrim()); + this->adjust_stroke(transform.descrim()); // Adjust pattern fill - item->adjust_pattern(transform); + this->adjust_pattern(transform); // Adjust gradient fill - item->adjust_gradient(transform); + this->adjust_gradient(transform); // Adjust LPE - item->adjust_livepatheffect(transform); + this->adjust_livepatheffect(transform); - item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); // nothing remains - we've written all of the transform, so return identity return Geom::identity(); } -void CPath::update_patheffect(bool write) { - SPPath* lpeitem = this->sppath; - SPShape * const shape = (SPShape *) lpeitem; - - Inkscape::XML::Node *repr = shape->getRepr(); +void SPPath::update_patheffect(bool write) { + Inkscape::XML::Node *repr = this->getRepr(); #ifdef PATH_VERBOSE g_message("sp_path_update_patheffect"); #endif - if (shape->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(lpeitem)) { - SPCurve *curve = shape->_curve_before_lpe->copy(); + if (this->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(this)) { + SPCurve *curve = this->_curve_before_lpe->copy(); /* if a path has an lpeitem applied, then reset the curve to the _curve_before_lpe. * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ - shape->setCurveInsync(curve, TRUE); + this->setCurveInsync(curve, TRUE); + + bool success = sp_lpe_item_perform_path_effect(this, curve); - bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM(shape), curve); if (success && write) { - // could also do shape->getRepr()->updateRepr(); but only the d attribute needs updating. + // could also do this->getRepr()->updateRepr(); but only the d attribute needs updating. #ifdef PATH_VERBOSE g_message("sp_path_update_patheffect writes 'd' attribute"); #endif - if ( shape->_curve != NULL ) { - gchar *str = sp_svg_write_path(shape->_curve->get_pathvector()); + + if ( this->_curve != NULL ) { + gchar *str = sp_svg_write_path(this->_curve->get_pathvector()); repr->setAttribute("d", str); g_free(str); } else { @@ -355,13 +328,15 @@ g_message("sp_path_update_patheffect writes 'd' attribute"); if (gchar const * value = repr->attribute("d")) { Geom::PathVector pv = sp_svg_read_pathv(value); SPCurve *oldcurve = new SPCurve(pv); + if (oldcurve) { - shape->setCurve(oldcurve, TRUE); + this->setCurve(oldcurve, TRUE); oldcurve->unref(); } } } - shape->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); curve->unref(); } } @@ -380,6 +355,7 @@ void SPPath::set_original_curve (SPCurve *new_curve, unsigned int owner, bool wr if (_curve_before_lpe) { _curve_before_lpe = _curve_before_lpe->unref(); } + if (new_curve) { if (owner) { _curve_before_lpe = new_curve->ref(); @@ -387,6 +363,7 @@ void SPPath::set_original_curve (SPCurve *new_curve, unsigned int owner, bool wr _curve_before_lpe = new_curve->copy(); } } + sp_lpe_item_update_patheffect(this, true, write); requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } @@ -399,6 +376,7 @@ SPCurve * SPPath::get_original_curve () const if (_curve_before_lpe) { return _curve_before_lpe->copy(); } + return NULL; } -- cgit v1.2.3 From cfe48de7f071e2e07a1f2f2ace3456f7b410e93b Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 15:37:33 +0200 Subject: Merged Shape and subclasses. Cleaned up a bit. (bzr r11608.1.76) --- src/sp-path.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 06167e6dd..a1a084b77 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -119,9 +119,7 @@ void SPPath::convert_to_guides() { sp_guide_pt_pairs_to_guides(this->document, pts); } -SPPath::SPPath() : SPShape(), CShape(this), connEndPair(this) { - delete this->cshape; - this->cshape = this; +SPPath::SPPath() : SPShape(), connEndPair(this) { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -139,7 +137,7 @@ void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) { sp_conn_end_pair_build(this); - CShape::build(document, repr); + SPShape::build(document, repr); this->readAttr( "inkscape:original-d" ); this->readAttr( "d" ); @@ -155,7 +153,7 @@ void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) { void SPPath::release() { this->connEndPair.release(); - CShape::release(); + SPShape::release(); } void SPPath::set(unsigned int key, const gchar* value) { @@ -210,7 +208,7 @@ void SPPath::set(unsigned int key, const gchar* value) { break; default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -244,7 +242,7 @@ g_message("sp_path_write writes 'd' attribute"); this->connEndPair.writeRepr(repr); - CShape::write(xml_doc, repr, flags); + SPShape::write(xml_doc, repr, flags); return repr; } @@ -254,7 +252,7 @@ void SPPath::update(SPCtx *ctx, guint flags) { flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } - CShape::update(ctx, flags); + SPShape::update(ctx, flags); this->connEndPair.update(); } -- cgit v1.2.3 From 19d00efa85cfc42ccae9bd17ef575602f0d22c50 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 19:42:32 +0200 Subject: Merged more classes. (bzr r11608.1.78) --- src/sp-path.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index a1a084b77..5b50eeee6 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -120,7 +120,6 @@ void SPPath::convert_to_guides() { } SPPath::SPPath() : SPShape(), connEndPair(this) { - this->clpeitem = this; this->citem = this; this->cobject = this; } -- cgit v1.2.3 From 8073924aacdda310fb7492750f78d5389b3186af Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 22:45:01 +0200 Subject: Merged Item. (bzr r11608.1.81) --- src/sp-path.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 5b50eeee6..d8c43aa68 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -120,7 +120,6 @@ void SPPath::convert_to_guides() { } SPPath::SPPath() : SPShape(), connEndPair(this) { - this->citem = this; this->cobject = this; } -- cgit v1.2.3 From 27e2102f96a5554bcd5310ec11435d155773b279 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 7 Apr 2013 18:28:22 +0200 Subject: Merge Object and subclasses. Merging of SP- and C-classes complete. (bzr r11608.1.86) --- src/sp-path.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-path.cpp') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index d8c43aa68..105506d6e 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -120,7 +120,6 @@ void SPPath::convert_to_guides() { } SPPath::SPPath() : SPShape(), connEndPair(this) { - this->cobject = this; } SPPath::~SPPath() { -- cgit v1.2.3