diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-04-05 13:37:33 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-04-05 13:37:33 +0000 |
| commit | cfe48de7f071e2e07a1f2f2ace3456f7b410e93b (patch) | |
| tree | 281d760873c84db3a67518ab19e61bb213f1eab7 /src | |
| parent | Combined some classes. (diff) | |
| download | inkscape-cfe48de7f071e2e07a1f2f2ace3456f7b410e93b.tar.gz inkscape-cfe48de7f071e2e07a1f2f2ace3456f7b410e93b.zip | |
Merged Shape and subclasses. Cleaned up a bit.
(bzr r11608.1.76)
Diffstat (limited to 'src')
| -rw-r--r-- | src/box3d-side.cpp | 5 | ||||
| -rw-r--r-- | src/conn-avoid-ref.cpp | 2 | ||||
| -rw-r--r-- | src/knotholder.cpp | 4 | ||||
| -rw-r--r-- | src/sp-ellipse.cpp | 376 | ||||
| -rw-r--r-- | src/sp-ellipse.h | 2 | ||||
| -rw-r--r-- | src/sp-line.cpp | 14 | ||||
| -rw-r--r-- | src/sp-line.h | 2 | ||||
| -rw-r--r-- | src/sp-offset.cpp | 18 | ||||
| -rw-r--r-- | src/sp-offset.h | 2 | ||||
| -rw-r--r-- | src/sp-path.cpp | 14 | ||||
| -rw-r--r-- | src/sp-path.h | 2 | ||||
| -rw-r--r-- | src/sp-polygon.cpp | 12 | ||||
| -rw-r--r-- | src/sp-polygon.h | 2 | ||||
| -rw-r--r-- | src/sp-polyline.cpp | 10 | ||||
| -rw-r--r-- | src/sp-polyline.h | 2 | ||||
| -rw-r--r-- | src/sp-rect.cpp | 12 | ||||
| -rw-r--r-- | src/sp-rect.h | 2 | ||||
| -rw-r--r-- | src/sp-shape.cpp | 366 | ||||
| -rw-r--r-- | src/sp-shape.h | 17 | ||||
| -rw-r--r-- | src/sp-spiral.cpp | 16 | ||||
| -rw-r--r-- | src/sp-spiral.h | 2 | ||||
| -rw-r--r-- | src/sp-star.cpp | 13 | ||||
| -rw-r--r-- | src/spiral-context.cpp | 2 | ||||
| -rw-r--r-- | src/star-context.cpp | 2 |
24 files changed, 452 insertions, 447 deletions
diff --git a/src/box3d-side.cpp b/src/box3d-side.cpp index ca80f91df..240a2ee98 100644 --- a/src/box3d-side.cpp +++ b/src/box3d-side.cpp @@ -37,7 +37,6 @@ namespace { } Box3DSide::Box3DSide() : SPPolygon() { - this->cshape = this; this->clpeitem = this; this->citem = this; this->cobject = this; @@ -68,7 +67,7 @@ Inkscape::XML::Node* Box3DSide::write(Inkscape::XML::Document *xml_doc, Inkscape sp_repr_set_int(repr, "inkscape:box3dsidetype", this->dir1 ^ this->dir2 ^ this->front_or_rear); } - this->setShape(); + this->set_shape(); /* Duplicate the path */ SPCurve const *curve = this->_curve; @@ -127,7 +126,7 @@ void Box3DSide::update(SPCtx* ctx, guint flags) { SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - this->setShape(); + this->set_shape(); } SPPolygon::update(ctx, flags); diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index 15a8392c4..c0d05e3c4 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -260,7 +260,7 @@ static std::vector<Geom::Point> approxItemWithPoints(SPItem const *item, const G } else if (SP_IS_SHAPE(item)) { - SP_SHAPE(item)->setShape(); + SP_SHAPE(item)->set_shape(); SPCurve* item_curve = SP_SHAPE(item)->getCurve(); // make sure it has an associated curve if (item_curve) diff --git a/src/knotholder.cpp b/src/knotholder.cpp index a1ee3082b..62119698f 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -128,7 +128,7 @@ KnotHolder::knot_clicked_handler(SPKnot *knot, guint state) } if (SP_IS_SHAPE(saved_item)) { - SP_SHAPE(saved_item)->setShape(); + SP_SHAPE(saved_item)->set_shape(); } knot_holder->update_knots(); @@ -177,7 +177,7 @@ KnotHolder::knot_moved_handler(SPKnot *knot, Geom::Point const &p, guint state) } if (SP_IS_SHAPE (item)) { - SP_SHAPE (item)->setShape(); + SP_SHAPE (item)->set_shape(); } this->update_knots(); diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index 23a7c91b0..303a0cde6 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -88,9 +88,7 @@ static double sp_round(double x, double y) static gboolean sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::Node *repr); -SPGenericEllipse::SPGenericEllipse() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPGenericEllipse::SPGenericEllipse() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -109,36 +107,34 @@ SPGenericEllipse::~SPGenericEllipse() { } void SPGenericEllipse::update(SPCtx *ctx, guint flags) { - SPGenericEllipse* object = this; - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - SPGenericEllipse *ellipse = (SPGenericEllipse *) object; - SPStyle const *style = object->style; Geom::Rect const &viewbox = ((SPItemCtx const *) ctx)->viewport; double const dx = viewbox.width(); double const dy = viewbox.height(); double const dr = sqrt(dx*dx + dy*dy)/sqrt(2); - double const em = style->font_size.computed; + double const em = this->style->font_size.computed; double const ex = em * 0.5; // fixme: get from pango or libnrtype - ellipse->cx.update(em, ex, dx); - ellipse->cy.update(em, ex, dy); - ellipse->rx.update(em, ex, dr); - ellipse->ry.update(em, ex, dr); - static_cast<SPShape *>(object)->setShape(); + + this->cx.update(em, ex, dx); + this->cy.update(em, ex, dy); + this->rx.update(em, ex, dr); + this->ry.update(em, ex, dr); + + this->set_shape(); } - CShape::update(ctx, flags); + SPShape::update(ctx, flags); } void SPGenericEllipse::update_patheffect(bool write) { - SPShape *shape = this; this->set_shape(); if (write) { - Inkscape::XML::Node *repr = shape->getRepr(); - if ( shape->_curve != NULL ) { - gchar *str = sp_svg_write_path(shape->_curve->get_pathvector()); + Inkscape::XML::Node *repr = this->getRepr(); + + if ( this->_curve != NULL ) { + gchar *str = sp_svg_write_path(this->_curve->get_pathvector()); repr->setAttribute("d", str); g_free(str); } else { @@ -146,23 +142,23 @@ void SPGenericEllipse::update_patheffect(bool write) { } } - ((SPObject *)shape)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } /* fixme: Think (Lauris) */ /* Can't we use arcto in this method? */ void SPGenericEllipse::set_shape() { - SPGenericEllipse* shape = this; - - if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) { + if (sp_lpe_item_has_broken_path_effect(this)) { g_warning ("The ellipse shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as ellipse will remove the bad LPE"); - if (shape->getRepr()->attribute("d")) { + + if (this->getRepr()->attribute("d")) { // unconditionally read the curve from d, if any, to preserve appearance - Geom::PathVector pv = sp_svg_read_pathv(shape->getRepr()->attribute("d")); + Geom::PathVector pv = sp_svg_read_pathv(this->getRepr()->attribute("d")); SPCurve *cold = new SPCurve(pv); - shape->setCurveInsync( cold, TRUE); + this->setCurveInsync( cold, TRUE); cold->unref(); } + return; } @@ -172,33 +168,43 @@ void SPGenericEllipse::set_shape() { gint slice = FALSE; // gint i; - SPGenericEllipse *ellipse = (SPGenericEllipse *) shape; + if ((this->rx.computed < 1e-18) || (this->ry.computed < 1e-18)) { + return; + } - if ((ellipse->rx.computed < 1e-18) || (ellipse->ry.computed < 1e-18)) return; - if (fabs(ellipse->end - ellipse->start) < 1e-9) return; + if (fabs(this->end - this->start) < 1e-9) { + return; + } - sp_genericellipse_normalize(ellipse); + sp_genericellipse_normalize(this); - rx = ellipse->rx.computed; - ry = ellipse->ry.computed; + rx = this->rx.computed; + ry = this->ry.computed; // figure out if we have a slice, guarding against rounding errors - len = fmod(ellipse->end - ellipse->start, SP_2PI); - if (len < 0.0) len += SP_2PI; + len = fmod(this->end - this->start, SP_2PI); + + if (len < 0.0) { + len += SP_2PI; + } + if (fabs(len) < 1e-8 || fabs(len - SP_2PI) < 1e-8) { slice = FALSE; - ellipse->end = ellipse->start + SP_2PI; + this->end = this->start + SP_2PI; } else { slice = TRUE; } SPCurve * curve = new SPCurve(); - curve->moveto(cos(ellipse->start), sin(ellipse->start)); + curve->moveto(cos(this->start), sin(this->start)); - for (s = ellipse->start; s < ellipse->end; s += M_PI_2) { + for (s = this->start; s < this->end; s += M_PI_2) { e = s + M_PI_2; - if (e > ellipse->end) - e = ellipse->end; + + if (e > this->end) { + e = this->end; + } + len = 4*tan((e - s)/4)/3; x0 = cos(s); y0 = sin(s); @@ -215,66 +221,69 @@ void SPGenericEllipse::set_shape() { curve->curveto(x1,y1, x2,y2, x3,y3); } - if (slice && ellipse->closed) { // TODO: is this check for "ellipse->closed" necessary? + if (slice && this->closed) { // TODO: is this check for "ellipse->closed" necessary? curve->lineto(0., 0.); } - if (ellipse->closed) { + + if (this->closed) { curve->closepath(); } - Geom::Affine aff = Geom::Scale(rx, ry) * Geom::Translate(ellipse->cx.computed, ellipse->cy.computed); + Geom::Affine aff = Geom::Scale(rx, ry) * Geom::Translate(this->cx.computed, this->cy.computed); curve->transform(aff); /* Reset the shape's curve to the "original_curve" * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ - shape->setCurveInsync( curve, TRUE); - shape->setCurveBeforeLPE(curve); + this->setCurveInsync( curve, TRUE); + this->setCurveBeforeLPE(curve); - if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) { + if (sp_lpe_item_has_path_effect(this) && sp_lpe_item_path_effects_enabled(this)) { SPCurve *c_lpe = curve->copy(); - bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe); + bool success = sp_lpe_item_perform_path_effect(this, c_lpe); + if (success) { - shape->setCurveInsync( c_lpe, TRUE); + this->setCurveInsync( c_lpe, TRUE); } + c_lpe->unref(); } + curve->unref(); } void SPGenericEllipse::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) { - SPGenericEllipse* item = this; - - g_assert(item != NULL); - g_assert(SP_IS_GENERICELLIPSE(item)); - - SPGenericEllipse *ellipse = SP_GENERICELLIPSE(item); - sp_genericellipse_normalize(ellipse); - Geom::Affine const i2dt = item->i2dt_affine(); + sp_genericellipse_normalize(this); + Geom::Affine const i2dt = this->i2dt_affine(); // figure out if we have a slice, while guarding against rounding errors bool slice = false; - double len = fmod(ellipse->end - ellipse->start, SP_2PI); - if (len < 0.0) len += SP_2PI; + double len = fmod(this->end - this->start, SP_2PI); + + if (len < 0.0) { + len += SP_2PI; + } + if (fabs(len) < 1e-8 || fabs(len - SP_2PI) < 1e-8) { slice = false; - ellipse->end = ellipse->start + SP_2PI; + this->end = this->start + SP_2PI; } else { slice = true; } - double rx = ellipse->rx.computed; - double ry = ellipse->ry.computed; - double cx = ellipse->cx.computed; - double cy = ellipse->cy.computed; + double rx = this->rx.computed; + double ry = this->ry.computed; + double cx = this->cx.computed; + double cy = this->cy.computed; Geom::Point pt; - // Snap to the 4 quadrant points of the ellipse, but only if the arc + // Snap to the 4 quadrant points of the this, but only if the arc // spans far enough to include them if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ELLIPSE_QUADRANT_POINT)) { double angle = 0; + for (angle = 0; angle < SP_2PI; angle += M_PI_2) { - if (angle >= ellipse->start && angle <= ellipse->end) { + if (angle >= this->start && angle <= this->end) { pt = Geom::Point(cx + cos(angle)*rx, cy + sin(angle)*ry) * i2dt; p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_ELLIPSE_QUADRANT_POINT, Inkscape::SNAPTARGET_ELLIPSE_QUADRANT_POINT)); } @@ -282,13 +291,16 @@ void SPGenericEllipse::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, } // Add the centre, if we have a closed slice or when explicitly asked for - bool c1 = snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP) && slice && ellipse->closed; + bool c1 = snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP) && slice && this->closed; bool c2 = snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT); + if (c1 || c2) { pt = Geom::Point(cx, cy) * i2dt; + if (c1) { p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); } + if (c2) { p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT)); } @@ -297,13 +309,14 @@ void SPGenericEllipse::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, // And if we have a slice, also snap to the endpoints if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP) && slice) { // Add the start point, if it's not coincident with a quadrant point - if (fmod(ellipse->start, M_PI_2) != 0.0 ) { - pt = Geom::Point(cx + cos(ellipse->start)*rx, cy + sin(ellipse->start)*ry) * i2dt; + if (fmod(this->start, M_PI_2) != 0.0 ) { + pt = Geom::Point(cx + cos(this->start)*rx, cy + sin(this->start)*ry) * i2dt; p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); } + // Add the end point, if it's not coincident with a quadrant point - if (fmod(ellipse->end, M_PI_2) != 0.0 ) { - pt = Geom::Point(cx + cos(ellipse->end)*rx, cy + sin(ellipse->end)*ry) * i2dt; + if (fmod(this->end, M_PI_2) != 0.0 ) { + pt = Geom::Point(cx + cos(this->end)*rx, cy + sin(this->end)*ry) * i2dt; p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); } } @@ -315,43 +328,44 @@ sp_genericellipse_normalize(SPGenericEllipse *ellipse) ellipse->start = fmod(ellipse->start, SP_2PI); ellipse->end = fmod(ellipse->end, SP_2PI); - if (ellipse->start < 0.0) + if (ellipse->start < 0.0) { ellipse->start += SP_2PI; + } + double diff = ellipse->start - ellipse->end; - if (diff >= 0.0) + + if (diff >= 0.0) { ellipse->end += diff - fmod(diff, SP_2PI) + SP_2PI; + } /* Now we keep: 0 <= start < end <= 2*PI */ } Inkscape::XML::Node* SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPGenericEllipse *ellipse = this; - SPGenericEllipse* object = ellipse; - if (flags & SP_OBJECT_WRITE_EXT) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); } - sp_repr_set_svg_double(repr, "sodipodi:cx", ellipse->cx.computed); - sp_repr_set_svg_double(repr, "sodipodi:cy", ellipse->cy.computed); - sp_repr_set_svg_double(repr, "sodipodi:rx", ellipse->rx.computed); - sp_repr_set_svg_double(repr, "sodipodi:ry", ellipse->ry.computed); + sp_repr_set_svg_double(repr, "sodipodi:cx", this->cx.computed); + sp_repr_set_svg_double(repr, "sodipodi:cy", this->cy.computed); + sp_repr_set_svg_double(repr, "sodipodi:rx", this->rx.computed); + sp_repr_set_svg_double(repr, "sodipodi:ry", this->ry.computed); - if (SP_IS_ARC(ellipse)) { - sp_arc_set_elliptical_path_attribute(SP_ARC(object), object->getRepr()); + if (SP_IS_ARC(this)) { + sp_arc_set_elliptical_path_attribute(SP_ARC(this), this->getRepr()); } } + this->set_shape(); // evaluate SPCurve - CShape::write(xml_doc, repr, flags); + SPShape::write(xml_doc, repr, flags); return repr; } /* SVG <ellipse> element */ SPEllipse::SPEllipse() : SPGenericEllipse() { - this->cshape = this; this->clpeitem = this; this->citem = this; this->cobject = this; @@ -363,25 +377,22 @@ SPEllipse::~SPEllipse() { void SPEllipse::build(SPDocument *document, Inkscape::XML::Node *repr) { SPGenericEllipse::build(document, repr); - SPEllipse* object = this; - object->readAttr( "cx" ); - object->readAttr( "cy" ); - object->readAttr( "rx" ); - object->readAttr( "ry" ); + this->readAttr( "cx" ); + this->readAttr( "cy" ); + this->readAttr( "rx" ); + this->readAttr( "ry" ); } Inkscape::XML::Node* SPEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPGenericEllipse *ellipse = this; - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:ellipse"); } - sp_repr_set_svg_double(repr, "cx", ellipse->cx.computed); - sp_repr_set_svg_double(repr, "cy", ellipse->cy.computed); - sp_repr_set_svg_double(repr, "rx", ellipse->rx.computed); - sp_repr_set_svg_double(repr, "ry", ellipse->ry.computed); + sp_repr_set_svg_double(repr, "cx", this->cx.computed); + sp_repr_set_svg_double(repr, "cy", this->cy.computed); + sp_repr_set_svg_double(repr, "rx", this->rx.computed); + sp_repr_set_svg_double(repr, "ry", this->ry.computed); SPGenericEllipse::write(xml_doc, repr, flags); @@ -390,30 +401,33 @@ Inkscape::XML::Node* SPEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape void SPEllipse::set(unsigned int key, gchar const* value) { - SPEllipse *ellipse = this; - SPEllipse* object = (SPEllipse*)ellipse; - switch (key) { case SP_ATTR_CX: - ellipse->cx.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->cx.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_CY: - ellipse->cy.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->cy.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_RX: - if (!ellipse->rx.read(value) || (ellipse->rx.value <= 0.0)) { - ellipse->rx.unset(); + if (!this->rx.read(value) || (this->rx.value <= 0.0)) { + this->rx.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_RY: - if (!ellipse->ry.read(value) || (ellipse->ry.value <= 0.0)) { - ellipse->ry.unset(); + if (!this->ry.read(value) || (this->ry.value <= 0.0)) { + this->ry.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + default: SPGenericEllipse::set(key, value); break; @@ -445,7 +459,6 @@ sp_ellipse_position_set(SPEllipse *ellipse, gdouble x, gdouble y, gdouble rx, gd /* SVG <circle> element */ SPCircle::SPCircle() : SPGenericEllipse() { - this->cshape = this; this->clpeitem = this; this->citem = this; this->cobject = this; @@ -455,26 +468,22 @@ SPCircle::~SPCircle() { } void SPCircle::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPCircle* object = this; - SPGenericEllipse::build(document, repr); - object->readAttr( "cx" ); - object->readAttr( "cy" ); - object->readAttr( "r" ); + this->readAttr( "cx" ); + this->readAttr( "cy" ); + this->readAttr( "r" ); } Inkscape::XML::Node* SPCircle::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPGenericEllipse *ellipse = this; - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:circle"); } - sp_repr_set_svg_double(repr, "cx", ellipse->cx.computed); - sp_repr_set_svg_double(repr, "cy", ellipse->cy.computed); - sp_repr_set_svg_double(repr, "r", ellipse->rx.computed); + sp_repr_set_svg_double(repr, "cx", this->cx.computed); + sp_repr_set_svg_double(repr, "cy", this->cy.computed); + sp_repr_set_svg_double(repr, "r", this->rx.computed); SPGenericEllipse::write(xml_doc, repr, flags); @@ -482,25 +491,26 @@ Inkscape::XML::Node* SPCircle::write(Inkscape::XML::Document *xml_doc, Inkscape: } void SPCircle::set(unsigned int key, gchar const* value) { - SPGenericEllipse *ge = this; - SPCircle* object = (SPCircle*)ge; - switch (key) { case SP_ATTR_CX: - ge->cx.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->cx.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_CY: - ge->cy.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->cy.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_R: - if (!ge->rx.read(value) || ge->rx.value <= 0.0) { - ge->rx.unset(); + if (!this->rx.read(value) || this->rx.value <= 0.0) { + this->rx.unset(); } - ge->ry = ge->rx; - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->ry = this->rx; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + default: SPGenericEllipse::set(key, value); break; @@ -513,7 +523,6 @@ gchar* SPCircle::description() { /* <path sodipodi:type="arc"> element */ SPArc::SPArc() : SPGenericEllipse() { - this->cshape = this; this->clpeitem = this; this->citem = this; this->cobject = this; @@ -523,18 +532,16 @@ SPArc::~SPArc() { } void SPArc::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPArc* object = this; - SPGenericEllipse::build(document, repr); - object->readAttr( "sodipodi:cx" ); - object->readAttr( "sodipodi:cy" ); - object->readAttr( "sodipodi:rx" ); - object->readAttr( "sodipodi:ry" ); + this->readAttr( "sodipodi:cx" ); + this->readAttr( "sodipodi:cy" ); + this->readAttr( "sodipodi:rx" ); + this->readAttr( "sodipodi:ry" ); - object->readAttr( "sodipodi:start" ); - object->readAttr( "sodipodi:end" ); - object->readAttr( "sodipodi:open" ); + this->readAttr( "sodipodi:start" ); + this->readAttr( "sodipodi:end" ); + this->readAttr( "sodipodi:open" ); } /* @@ -580,28 +587,30 @@ sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::Node *repr) } Inkscape::XML::Node* SPArc::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPArc* object = this; - SPGenericEllipse *ge = object; - SPArc *arc = object; - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); } if (flags & SP_OBJECT_WRITE_EXT) { repr->setAttribute("sodipodi:type", "arc"); - sp_repr_set_svg_double(repr, "sodipodi:cx", ge->cx.computed); - sp_repr_set_svg_double(repr, "sodipodi:cy", ge->cy.computed); - sp_repr_set_svg_double(repr, "sodipodi:rx", ge->rx.computed); - sp_repr_set_svg_double(repr, "sodipodi:ry", ge->ry.computed); + + sp_repr_set_svg_double(repr, "sodipodi:cx", this->cx.computed); + sp_repr_set_svg_double(repr, "sodipodi:cy", this->cy.computed); + sp_repr_set_svg_double(repr, "sodipodi:rx", this->rx.computed); + sp_repr_set_svg_double(repr, "sodipodi:ry", this->ry.computed); // write start and end only if they are non-trivial; otherwise remove - gdouble len = fmod(ge->end - ge->start, SP_2PI); - if (len < 0.0) len += SP_2PI; + gdouble len = fmod(this->end - this->start, SP_2PI); + + if (len < 0.0) { + len += SP_2PI; + } + if (!(fabs(len) < 1e-8 || fabs(len - SP_2PI) < 1e-8)) { - sp_repr_set_svg_double(repr, "sodipodi:start", ge->start); - sp_repr_set_svg_double(repr, "sodipodi:end", ge->end); - repr->setAttribute("sodipodi:open", (!ge->closed) ? "true" : NULL); + sp_repr_set_svg_double(repr, "sodipodi:start", this->start); + sp_repr_set_svg_double(repr, "sodipodi:end", this->end); + + repr->setAttribute("sodipodi:open", (!this->closed) ? "true" : NULL); } else { repr->setAttribute("sodipodi:end", NULL); repr->setAttribute("sodipodi:start", NULL); @@ -610,7 +619,7 @@ Inkscape::XML::Node* SPArc::write(Inkscape::XML::Document *xml_doc, Inkscape::XM } // write d= - sp_arc_set_elliptical_path_attribute(arc, repr); + sp_arc_set_elliptical_path_attribute(this, repr); SPGenericEllipse::write(xml_doc, repr, flags); @@ -618,50 +627,58 @@ Inkscape::XML::Node* SPArc::write(Inkscape::XML::Document *xml_doc, Inkscape::XM } void SPArc::set(unsigned int key, gchar const* value) { - SPArc* object = this; - SPGenericEllipse *ge = object; - switch (key) { case SP_ATTR_SODIPODI_CX: - ge->cx.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->cx.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_CY: - ge->cy.readOrUnset(value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->cy.readOrUnset(value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_RX: - if (!ge->rx.read(value) || ge->rx.computed <= 0.0) { - ge->rx.unset(); + if (!this->rx.read(value) || this->rx.computed <= 0.0) { + this->rx.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_RY: - if (!ge->ry.read(value) || ge->ry.computed <= 0.0) { - ge->ry.unset(); + if (!this->ry.read(value) || this->ry.computed <= 0.0) { + this->ry.unset(); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_START: if (value) { - sp_svg_number_read_d(value, &ge->start); + sp_svg_number_read_d(value, &this->start); } else { - ge->start = 0; + this->start = 0; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_END: if (value) { - sp_svg_number_read_d(value, &ge->end); + sp_svg_number_read_d(value, &this->end); } else { - ge->end = 2 * M_PI; + this->end = 2 * M_PI; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_OPEN: - ge->closed = (!value); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->closed = (!value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + default: SPGenericEllipse::set(key, value); break; @@ -669,10 +686,8 @@ void SPArc::set(unsigned int key, gchar const* value) { } void SPArc::modified(guint flags) { - SPArc* object = this; - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - ((SPShape *) object)->setShape(); + this->set_shape(); } SPGenericEllipse::modified(flags); @@ -680,13 +695,14 @@ void SPArc::modified(guint flags) { gchar* SPArc::description() { - SPArc* item = this; - SPGenericEllipse *ge = item; + gdouble len = fmod(this->end - this->start, SP_2PI); + + if (len < 0.0) { + len += SP_2PI; + } - gdouble len = fmod(ge->end - ge->start, SP_2PI); - if (len < 0.0) len += SP_2PI; if (!(fabs(len) < 1e-8 || fabs(len - SP_2PI) < 1e-8)) { - if (ge->closed) { + if (this->closed) { return g_strdup(_("<b>Segment</b>")); } else { return g_strdup(_("<b>Arc</b>")); diff --git a/src/sp-ellipse.h b/src/sp-ellipse.h index e7bc70aa8..298a7afae 100644 --- a/src/sp-ellipse.h +++ b/src/sp-ellipse.h @@ -21,7 +21,7 @@ #define SP_GENERICELLIPSE(obj) ((SPGenericEllipse*)obj) #define SP_IS_GENERICELLIPSE(obj) (dynamic_cast<const SPGenericEllipse*>((SPObject*)obj)) -class SPGenericEllipse : public SPShape, public CShape { +class SPGenericEllipse : public SPShape { public: SPGenericEllipse(); virtual ~SPGenericEllipse(); diff --git a/src/sp-line.cpp b/src/sp-line.cpp index d60969baa..bb7abda8e 100644 --- a/src/sp-line.cpp +++ b/src/sp-line.cpp @@ -34,9 +34,7 @@ namespace { bool lineRegistered = SPFactory::instance().registerObject("svg:line", createLine); } -SPLine::SPLine() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPLine::SPLine() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -51,7 +49,7 @@ SPLine::~SPLine() { } void SPLine::build(SPDocument * document, Inkscape::XML::Node * repr) { - CShape::build(document, repr); + SPShape::build(document, repr); this->readAttr( "x1" ); this->readAttr( "y1" ); @@ -84,7 +82,7 @@ void SPLine::set(unsigned int key, const gchar* value) { break; default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -103,10 +101,10 @@ void SPLine::update(SPCtx *ctx, guint flags) { this->y1.update(em, ex, h); this->y2.update(em, ex, h); - this->setShape(); + this->set_shape(); } - CShape::update(ctx, flags); + SPShape::update(ctx, flags); } Inkscape::XML::Node* SPLine::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { @@ -123,7 +121,7 @@ Inkscape::XML::Node* SPLine::write(Inkscape::XML::Document *xml_doc, Inkscape::X sp_repr_set_svg_double(repr, "x2", this->x2.computed); sp_repr_set_svg_double(repr, "y2", this->y2.computed); - CShape::write(xml_doc, repr, flags); + SPShape::write(xml_doc, repr, flags); return repr; } diff --git a/src/sp-line.h b/src/sp-line.h index 72c749f43..299fedc4c 100644 --- a/src/sp-line.h +++ b/src/sp-line.h @@ -20,7 +20,7 @@ #define SP_LINE(obj) ((SPLine*)obj) #define SP_IS_LINE(obj) (dynamic_cast<const SPLine*>((SPObject*)obj)) -class SPLine : public SPShape, CShape { +class SPLine : public SPShape { public: SPLine(); virtual ~SPLine(); diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index ede1ab39b..5a8d3e1d0 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -95,9 +95,7 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i // reappearing in offset when the radius becomes too large static bool use_slow_but_correct_offset_method=false; -SPOffset::SPOffset() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPOffset::SPOffset() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -133,7 +131,7 @@ SPOffset::~SPOffset() { } void SPOffset::build(SPDocument *document, Inkscape::XML::Node *repr) { - CShape::build(document, repr); + SPShape::build(document, repr); //XML Tree being used directly here while it shouldn't be. if (this->getRepr()->attribute("inkscape:radius")) { @@ -212,7 +210,7 @@ Inkscape::XML::Node* SPOffset::write(Inkscape::XML::Document *xml_doc, Inkscape: repr->setAttribute("d", d); g_free (d); - CShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); + SPShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } @@ -238,7 +236,7 @@ void SPOffset::release() { this->sourceHref = NULL; this->sourceRef->detach(); - CShape::release(); + SPShape::release(); } void SPOffset::set(unsigned int key, const gchar* value) { @@ -321,7 +319,7 @@ void SPOffset::set(unsigned int key, const gchar* value) { break; default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -337,12 +335,12 @@ void SPOffset::update(SPCtx *ctx, guint flags) { (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - this->setShape (); + this->set_shape(); } this->isUpdating=false; - CShape::update(ctx, flags); + SPShape::update(ctx, flags); } gchar* SPOffset::description() { @@ -697,7 +695,7 @@ void SPOffset::set_shape() { } void SPOffset::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) { - CShape::snappoints(p, snapprefs); + SPShape::snappoints(p, snapprefs); } diff --git a/src/sp-offset.h b/src/sp-offset.h index cc0be839a..f18fd4071 100644 --- a/src/sp-offset.h +++ b/src/sp-offset.h @@ -49,7 +49,7 @@ class SPUseReference; * points, or more precisely one control point, that's enough to define the * radius (look in object-edit). */ -class SPOffset : public SPShape, CShape { +class SPOffset : public SPShape { public: SPOffset(); virtual ~SPOffset(); 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(); } diff --git a/src/sp-path.h b/src/sp-path.h index e475a3f09..89224b958 100644 --- a/src/sp-path.h +++ b/src/sp-path.h @@ -27,7 +27,7 @@ class SPCurve; /** * SVG <path> implementation */ -class SPPath : public SPShape, public CShape { +class SPPath : public SPShape { public: SPPath(); virtual ~SPPath(); diff --git a/src/sp-polygon.cpp b/src/sp-polygon.cpp index 09726703e..5ac5e1714 100644 --- a/src/sp-polygon.cpp +++ b/src/sp-polygon.cpp @@ -35,9 +35,7 @@ namespace { bool polygonRegistered = SPFactory::instance().registerObject("svg:polygon", createPolygon); } -SPPolygon::SPPolygon() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPPolygon::SPPolygon() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -49,7 +47,7 @@ SPPolygon::~SPPolygon() { void SPPolygon::build(SPDocument *document, Inkscape::XML::Node *repr) { SPPolygon* object = this; - CShape::build(document, repr); + SPShape::build(document, repr); object->readAttr( "points" ); } @@ -80,7 +78,7 @@ static gchar *sp_svg_write_polygon(Geom::PathVector const & pathv) Inkscape::XML::Node* SPPolygon::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { // Tolerable workaround: we need to update the object's curve before we set points= // because it's out of sync when e.g. some extension attrs of the polygon or star are changed in XML editor - this->setShape(); + this->set_shape(); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:polygon"); @@ -91,7 +89,7 @@ Inkscape::XML::Node* SPPolygon::write(Inkscape::XML::Document *xml_doc, Inkscape repr->setAttribute("points", str); g_free(str); - CShape::write(xml_doc, repr, flags); + SPShape::write(xml_doc, repr, flags); return repr; } @@ -178,7 +176,7 @@ void SPPolygon::set(unsigned int key, const gchar* value) { break; } default: - CShape::set(key, value); + SPShape::set(key, value); break; } } diff --git a/src/sp-polygon.h b/src/sp-polygon.h index df414eda8..cb6c8a4f8 100644 --- a/src/sp-polygon.h +++ b/src/sp-polygon.h @@ -19,7 +19,7 @@ #define SP_POLYGON(obj) ((SPPolygon*)obj) #define SP_IS_POLYGON(obj) (dynamic_cast<const SPPolygon*>((SPObject*)obj)) -class SPPolygon : public SPShape, public CShape { +class SPPolygon : public SPShape { public: SPPolygon(); virtual ~SPPolygon(); diff --git a/src/sp-polyline.cpp b/src/sp-polyline.cpp index c97b96b73..a85d0d64a 100644 --- a/src/sp-polyline.cpp +++ b/src/sp-polyline.cpp @@ -30,9 +30,7 @@ namespace { bool polyLineRegistered = SPFactory::instance().registerObject("svg:polyline", createPolyLine); } -SPPolyLine::SPPolyLine() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPPolyLine::SPPolyLine() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -42,7 +40,7 @@ SPPolyLine::~SPPolyLine() { } void SPPolyLine::build(SPDocument * document, Inkscape::XML::Node * repr) { - CShape::build(document, repr); + SPShape::build(document, repr); this->readAttr("points"); } @@ -113,7 +111,7 @@ void SPPolyLine::set(unsigned int key, const gchar* value) { break; } default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -127,7 +125,7 @@ Inkscape::XML::Node* SPPolyLine::write(Inkscape::XML::Document *xml_doc, Inkscap repr->mergeFrom(this->getRepr(), "id"); } - CShape::write(xml_doc, repr, flags); + SPShape::write(xml_doc, repr, flags); return repr; } diff --git a/src/sp-polyline.h b/src/sp-polyline.h index 66570d881..91266d985 100644 --- a/src/sp-polyline.h +++ b/src/sp-polyline.h @@ -6,7 +6,7 @@ #define SP_POLYLINE(obj) ((SPPolyLine*)obj) #define SP_IS_POLYLINE(obj) (dynamic_cast<const SPPolyLine*>((SPObject*)obj)) -class SPPolyLine : public SPShape, public CShape { +class SPPolyLine : public SPShape { public: SPPolyLine(); virtual ~SPPolyLine(); diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index aefe2dc8c..6bdfb2c6c 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -38,9 +38,7 @@ namespace { } -SPRect::SPRect() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPRect::SPRect() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -50,7 +48,7 @@ SPRect::~SPRect() { } void SPRect::build(SPDocument* doc, Inkscape::XML::Node* repr) { - CShape::build(doc, repr); + SPShape::build(doc, repr); this->readAttr("x"); this->readAttr("y"); @@ -107,7 +105,7 @@ void SPRect::set(unsigned key, gchar const *value) { break; default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -134,7 +132,7 @@ void SPRect::update(SPCtx* ctx, unsigned int 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); } Inkscape::XML::Node * SPRect::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { @@ -157,7 +155,7 @@ Inkscape::XML::Node * SPRect::write(Inkscape::XML::Document *xml_doc, Inkscape:: sp_repr_set_svg_double(repr, "y", this->y.computed); this->set_shape(); // evaluate SPCurve - CShape::write(xml_doc, repr, flags); + SPShape::write(xml_doc, repr, flags); return repr; } diff --git a/src/sp-rect.h b/src/sp-rect.h index 4e7f9bcdd..36942015a 100644 --- a/src/sp-rect.h +++ b/src/sp-rect.h @@ -22,7 +22,7 @@ #define SP_RECT(obj) ((SPRect*)obj) #define SP_IS_RECT(obj) (dynamic_cast<const SPRect*>((SPObject*)obj)) -class SPRect : public SPShape, public CShape { +class SPRect : public SPShape { public: SPRect(); virtual ~SPRect(); diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index fc80defb3..64e905328 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -53,35 +53,22 @@ #define noSHAPE_VERBOSE -static void sp_shape_finalize (GObject *object); static void sp_shape_update_marker_view (SPShape *shape, Inkscape::DrawingItem *ai); - -CShape::CShape(SPShape* shape) : CLPEItem(shape) { - this->spshape = shape; -} - -CShape::~CShape() { -} - -SPShape::SPShape() : SPLPEItem() { - SPShape* shape = this; - - shape->cshape = new CShape(shape); - shape->typeHierarchy.insert(typeid(SPShape)); - - delete shape->clpeitem; - shape->clpeitem = shape->cshape; - shape->citem = shape->cshape; - shape->cobject = shape->cshape; +SPShape::SPShape() : SPLPEItem(), CLPEItem(this) { + delete this->clpeitem; + this->clpeitem = this; + this->citem = this; + this->cobject = this; for ( int i = 0 ; i < SP_MARKER_LOC_QTY ; i++ ) { - new (&shape->_release_connect[i]) sigc::connection(); - new (&shape->_modified_connect[i]) sigc::connection(); - shape->_marker[i] = NULL; + new (&this->_release_connect[i]) sigc::connection(); + new (&this->_modified_connect[i]) sigc::connection(); + this->_marker[i] = NULL; } - shape->_curve = NULL; - shape->_curve_before_lpe = NULL; + + this->_curve = NULL; + this->_curve_before_lpe = NULL; } SPShape::~SPShape() { @@ -91,13 +78,11 @@ SPShape::~SPShape() { } } -void CShape::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPShape* object = this->spshape; - +void SPShape::build(SPDocument *document, Inkscape::XML::Node *repr) { CLPEItem::build(document, repr); for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) { - sp_shape_set_marker (object, i, object->style->marker[i].value); + sp_shape_set_marker (this, i, this->style->marker[i].value); } } @@ -112,50 +97,45 @@ void CShape::build(SPDocument *document, Inkscape::XML::Node *repr) { * * \see SPObject::release() */ -void CShape::release() { - SPItem *item; - SPShape *shape; +void SPShape::release() { SPItemView *v; int i; - SPShape* object = this->spshape; - - item = (SPItem *) object; - shape = (SPShape *) object; for (i = 0; i < SP_MARKER_LOC_QTY; i++) { - if (shape->_marker[i]) { - for (v = item->display; v != NULL; v = v->next) { - sp_marker_hide ((SPMarker *) shape->_marker[i], v->arenaitem->key() + i); + if (this->_marker[i]) { + + for (v = this->display; v != NULL; v = v->next) { + sp_marker_hide ((SPMarker *) this->_marker[i], v->arenaitem->key() + i); } - shape->_release_connect[i].disconnect(); - shape->_modified_connect[i].disconnect(); - shape->_marker[i] = sp_object_hunref (shape->_marker[i], object); + + this->_release_connect[i].disconnect(); + this->_modified_connect[i].disconnect(); + this->_marker[i] = sp_object_hunref (this->_marker[i], this); } } - if (shape->_curve) { - shape->_curve = shape->_curve->unref(); + + if (this->_curve) { + this->_curve = this->_curve->unref(); } - if (shape->_curve_before_lpe) { - shape->_curve_before_lpe = shape->_curve_before_lpe->unref(); + + if (this->_curve_before_lpe) { + this->_curve_before_lpe = this->_curve_before_lpe->unref(); } CLPEItem::release(); } -void CShape::set(unsigned int key, const gchar* value) { +void SPShape::set(unsigned int key, const gchar* value) { CLPEItem::set(key, value); } -Inkscape::XML::Node* CShape::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +Inkscape::XML::Node* SPShape::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { CLPEItem::write(xml_doc, repr, flags); return repr; } -void CShape::update(SPCtx* ctx, guint flags) { - SPShape* shape = this->spshape; - SPShape* object = shape; - +void SPShape::update(SPCtx* ctx, guint flags) { CLPEItem::update(ctx, flags); /* This stanza checks that an object's marker style agrees with @@ -164,16 +144,18 @@ void CShape::update(SPCtx* ctx, guint flags) { * match the style. */ for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) { - sp_shape_set_marker (object, i, object->style->marker[i].value); - } + sp_shape_set_marker (this, i, this->style->marker[i].value); + } if (flags & (SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - SPStyle *style = object->style; + SPStyle *style = this->style; + if (style->stroke_width.unit == SP_CSS_UNIT_PERCENT) { SPItemCtx *ictx = (SPItemCtx *) ctx; double const aw = 1.0 / ictx->i2vp.descrim(); style->stroke_width.computed = style->stroke_width.value * aw; - for (SPItemView *v = ((SPItem *) (shape))->display; v != NULL; v = v->next) { + + for (SPItemView *v = ((SPItem *) (this))->display; v != NULL; v = v->next) { Inkscape::DrawingShape *sh = dynamic_cast<Inkscape::DrawingShape *>(v->arenaitem); sh->setStyle(style); } @@ -183,32 +165,34 @@ void CShape::update(SPCtx* ctx, guint flags) { if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG)) { /* This is suboptimal, because changing parent style schedules recalculation */ /* But on the other hand - how can we know that parent does not tie style and transform */ - for (SPItemView *v = shape->display; v != NULL; v = v->next) { + for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingShape *sh = dynamic_cast<Inkscape::DrawingShape *>(v->arenaitem); + if (flags & SP_OBJECT_MODIFIED_FLAG) { - sh->setPath(shape->_curve); + sh->setPath(this->_curve); } } } - if (shape->hasMarkers ()) { + if (this->hasMarkers ()) { /* Dimension marker views */ - for (SPItemView *v = shape->display; v != NULL; v = v->next) { + for (SPItemView *v = this->display; v != NULL; v = v->next) { if (!v->arenaitem->key()) { v->arenaitem->setKey(SPItem::display_key_new (SP_MARKER_LOC_QTY)); } + for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) { - if (shape->_marker[i]) { - sp_marker_show_dimension ((SPMarker *) shape->_marker[i], + if (this->_marker[i]) { + sp_marker_show_dimension ((SPMarker *) this->_marker[i], v->arenaitem->key() + i, - shape->numberOfMarkers (i)); + this->numberOfMarkers (i)); } } } /* Update marker views */ - for (SPItemView *v = shape->display; v != NULL; v = v->next) { - sp_shape_update_marker_view (shape, v->arenaitem); + for (SPItemView *v = this->display; v != NULL; v = v->next) { + sp_shape_update_marker_view (this, v->arenaitem); } } } @@ -407,54 +391,61 @@ sp_shape_update_marker_view(SPShape *shape, Inkscape::DrawingItem *ai) } } -void CShape::modified(unsigned int flags) { - SPShape* shape = this->spshape; - +void SPShape::modified(unsigned int flags) { CLPEItem::modified(flags); if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { - for (SPItemView *v = shape->display; v != NULL; v = v->next) { + for (SPItemView *v = this->display; v != NULL; v = v->next) { Inkscape::DrawingShape *sh = dynamic_cast<Inkscape::DrawingShape *>(v->arenaitem); - sh->setStyle(shape->style); + sh->setStyle(this->style); } } } -Geom::OptRect CShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype) { - SPShape const* shape = this->spshape; - SPShape const* item = shape; +Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype) { Geom::OptRect bbox; - if (!shape->_curve) return bbox; - bbox = bounds_exact_transformed(shape->_curve->get_pathvector(), transform); - if (!bbox) return bbox; + if (!this->_curve) { + return bbox; + } + + bbox = bounds_exact_transformed(this->_curve->get_pathvector(), transform); + + if (!bbox) { + return bbox; + } if (bboxtype == SPItem::VISUAL_BBOX) { // convert the stroke to a path and calculate that path's geometric bbox - SPStyle* style = item->style; + SPStyle* style = this->style; + if (!style->stroke.isNone()) { - Geom::PathVector *pathv = item_outline(item, true); // calculate bbox_only + Geom::PathVector *pathv = item_outline(this, true); // calculate bbox_only + if (pathv) { bbox |= bounds_exact_transformed(*pathv, transform); delete pathv; } } + // Union with bboxes of the markers, if any - if ( shape->hasMarkers() && !shape->_curve->get_pathvector().empty() ) { + if ( this->hasMarkers() && !this->_curve->get_pathvector().empty() ) { /** \todo make code prettier! */ - Geom::PathVector const & pathv = shape->_curve->get_pathvector(); + Geom::PathVector const & pathv = this->_curve->get_pathvector(); // START marker for (unsigned i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START - if ( shape->_marker[i] ) { - SPMarker* marker = SP_MARKER (shape->_marker[i]); + if ( this->_marker[i] ) { + SPMarker* marker = SP_MARKER (this->_marker[i]); SPItem* marker_item = sp_item_first_item_child( marker ); if (marker_item) { Geom::Affine tr(sp_shape_marker_get_transform_at_start(pathv.begin()->front())); + if (!marker->orient_auto) { Geom::Point transl = tr.translation(); tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); } + if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { tr = Geom::Scale(style->stroke_width.computed) * tr; } @@ -467,12 +458,19 @@ Geom::OptRect CShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxt } } } + // MID marker for (unsigned i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID - if ( !shape->_marker[i] ) continue; - SPMarker* marker = SP_MARKER (shape->_marker[i]); + if ( !this->_marker[i] ) { + continue; + } + + SPMarker* marker = SP_MARKER (this->_marker[i]); SPItem* marker_item = sp_item_first_item_child( marker ); - if ( !marker_item ) continue; + + if ( !marker_item ) { + continue; + } for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { // START position @@ -480,38 +478,46 @@ Geom::OptRect CShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxt && ! ((path_it == (pathv.end()-1)) && (path_it->size_default() == 0)) ) // if this is the last path and it is a moveto-only, there is no mid marker there { Geom::Affine tr(sp_shape_marker_get_transform_at_start(path_it->front())); + if (!marker->orient_auto) { Geom::Point transl = tr.translation(); tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); } + if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { tr = Geom::Scale(style->stroke_width.computed) * tr; } + tr = marker_item->transform * marker->c2p * tr * transform; bbox |= marker_item->visualBounds(tr); } + // MID position if ( path_it->size_default() > 1) { Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); // outgoing curve + while (curve_it2 != path_it->end_default()) { /* Put marker between curve_it1 and curve_it2. * Loop to end_default (so including closing segment), because when a path is closed, * there should be a midpoint marker between last segment and closing straight line segment */ - SPMarker* marker = SP_MARKER (shape->_marker[i]); + SPMarker* marker = SP_MARKER (this->_marker[i]); SPItem* marker_item = sp_item_first_item_child( marker ); if (marker_item) { Geom::Affine tr(sp_shape_marker_get_transform(*curve_it1, *curve_it2)); + if (!marker->orient_auto) { Geom::Point transl = tr.translation(); tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); } + if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { tr = Geom::Scale(style->stroke_width.computed) * tr; } + tr = marker_item->transform * marker->c2p * tr * transform; bbox |= marker_item->visualBounds(tr); } @@ -520,26 +526,31 @@ Geom::OptRect CShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxt ++curve_it2; } } + // END position if ( path_it != (pathv.end()-1) && !path_it->empty()) { Geom::Curve const &lastcurve = path_it->back_default(); Geom::Affine tr = sp_shape_marker_get_transform_at_end(lastcurve); + if (!marker->orient_auto) { Geom::Point transl = tr.translation(); tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); } + if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { tr = Geom::Scale(style->stroke_width.computed) * tr; } + tr = marker_item->transform * marker->c2p * tr * transform; bbox |= marker_item->visualBounds(tr); } } } + // END marker for (unsigned i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END - if ( shape->_marker[i] ) { - SPMarker* marker = SP_MARKER (shape->_marker[i]); + if ( this->_marker[i] ) { + SPMarker* marker = SP_MARKER (this->_marker[i]); SPItem* marker_item = sp_item_first_item_child( marker ); if (marker_item) { @@ -547,16 +558,20 @@ Geom::OptRect CShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxt * For moveto-only path, this returns the "closing line segment". */ Geom::Path const &path_last = pathv.back(); unsigned int index = path_last.size_default(); + if (index > 0) { index--; } + Geom::Curve const &lastcurve = path_last[index]; Geom::Affine tr = sp_shape_marker_get_transform_at_end(lastcurve); + if (!marker->orient_auto) { Geom::Point transl = tr.translation(); tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl); } + if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { tr = Geom::Scale(style->stroke_width.computed) * tr; } @@ -571,6 +586,7 @@ Geom::OptRect CShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxt } } } + return bbox; } @@ -593,32 +609,35 @@ sp_shape_print_invoke_marker_printing(SPObject *obj, Geom::Affine tr, SPStyle co } } -void CShape::print(SPPrintContext* ctx) { - SPShape *shape = this->spshape; - SPShape* item = shape; - - Geom::OptRect pbox, dbox, bbox; - if (!shape->_curve) return; +void SPShape::print(SPPrintContext* ctx) { + if (!this->_curve) { + return; + } - Geom::PathVector const & pathv = shape->_curve->get_pathvector(); - if (pathv.empty()) return; + Geom::PathVector const & pathv = this->_curve->get_pathvector(); + + if (pathv.empty()) { + return; + } - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint add_comments = prefs->getBool("/printing/debug/add-label-comments"); - if (add_comments) { - gchar * comment = g_strdup_printf("begin '%s'", - item->defaultLabel()); - sp_print_comment(ctx, comment); - g_free(comment); - } + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gint add_comments = prefs->getBool("/printing/debug/add-label-comments"); + + if (add_comments) { + gchar * comment = g_strdup_printf("begin '%s'", this->defaultLabel()); + sp_print_comment(ctx, comment); + g_free(comment); + } /* fixme: Think (Lauris) */ - pbox = item->geometricBounds(); - bbox = item->desktopVisualBounds(); - dbox = Geom::Rect::from_xywh(Geom::Point(0,0), item->document->getDimensions()); - Geom::Affine const i2dt(item->i2dt_affine()); + Geom::OptRect pbox, dbox, bbox; + pbox = this->geometricBounds(); + bbox = this->desktopVisualBounds(); + dbox = Geom::Rect::from_xywh(Geom::Point(0,0), this->document->getDimensions()); + + Geom::Affine const i2dt(this->i2dt_affine()); - SPStyle* style = item->style; + SPStyle* style = this->style; if (!style->fill.isNone()) { sp_print_fill (ctx, pathv, i2dt, style, pbox, dbox, bbox); @@ -631,26 +650,29 @@ void CShape::print(SPPrintContext* ctx) { /** \todo make code prettier */ // START marker for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START - if ( shape->_marker[i] ) { + if ( this->_marker[i] ) { Geom::Affine tr(sp_shape_marker_get_transform_at_start(pathv.begin()->front())); - sp_shape_print_invoke_marker_printing(shape->_marker[i], tr, style, ctx); + sp_shape_print_invoke_marker_printing(this->_marker[i], tr, style, ctx); } } + // MID marker for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID - if (shape->_marker[i]) { + if (this->_marker[i]) { for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { // START position if ( path_it != pathv.begin() && ! ((path_it == (pathv.end()-1)) && (path_it->size_default() == 0)) ) // if this is the last path and it is a moveto-only, there is no mid marker there { Geom::Affine tr(sp_shape_marker_get_transform_at_start(path_it->front())); - sp_shape_print_invoke_marker_printing(shape->_marker[i], tr, style, ctx); + sp_shape_print_invoke_marker_printing(this->_marker[i], tr, style, ctx); } + // MID position if ( path_it->size_default() > 1) { Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); // outgoing curve + while (curve_it2 != path_it->end_default()) { /* Put marker between curve_it1 and curve_it2. @@ -658,55 +680,56 @@ void CShape::print(SPPrintContext* ctx) { * there should be a midpoint marker between last segment and closing straight line segment */ Geom::Affine tr(sp_shape_marker_get_transform(*curve_it1, *curve_it2)); - sp_shape_print_invoke_marker_printing(shape->_marker[i], tr, style, ctx); + sp_shape_print_invoke_marker_printing(this->_marker[i], tr, style, ctx); ++curve_it1; ++curve_it2; } } + if ( path_it != (pathv.end()-1) && !path_it->empty()) { Geom::Curve const &lastcurve = path_it->back_default(); Geom::Affine tr = sp_shape_marker_get_transform_at_end(lastcurve); - sp_shape_print_invoke_marker_printing(shape->_marker[i], tr, style, ctx); + sp_shape_print_invoke_marker_printing(this->_marker[i], tr, style, ctx); } } } } + // END marker - if ( shape->_marker[SP_MARKER_LOC_END] || shape->_marker[SP_MARKER_LOC]) { + if ( this->_marker[SP_MARKER_LOC_END] || this->_marker[SP_MARKER_LOC]) { /* Get reference to last curve in the path. * For moveto-only path, this returns the "closing line segment". */ Geom::Path const &path_last = pathv.back(); unsigned int index = path_last.size_default(); + if (index > 0) { index--; } + Geom::Curve const &lastcurve = path_last[index]; Geom::Affine tr = sp_shape_marker_get_transform_at_end(lastcurve); for (int i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END - if (shape->_marker[i]) { - sp_shape_print_invoke_marker_printing(shape->_marker[i], tr, style, ctx); + if (this->_marker[i]) { + sp_shape_print_invoke_marker_printing(this->_marker[i], tr, style, ctx); } } } - if (add_comments) { - gchar * comment = g_strdup_printf("end '%s'", - item->defaultLabel()); - sp_print_comment(ctx, comment); - g_free(comment); - } + if (add_comments) { + gchar * comment = g_strdup_printf("end '%s'", + this->defaultLabel()); + sp_print_comment(ctx, comment); + g_free(comment); + } } -Inkscape::DrawingItem* CShape::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - SPObject *object = this->spshape; - SPShape *shape = this->spshape; - +Inkscape::DrawingItem* SPShape::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { Inkscape::DrawingShape *s = new Inkscape::DrawingShape(drawing); - s->setStyle(object->style); - s->setPath(shape->_curve); + s->setStyle(this->style); + s->setPath(this->_curve); /* This stanza checks that an object's marker style agrees with * the marker objects it has allocated. sp_shape_set_marker ensures @@ -714,26 +737,25 @@ Inkscape::DrawingItem* CShape::show(Inkscape::Drawing &drawing, unsigned int key * match the style. */ for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) { - sp_shape_set_marker (object, i, object->style->marker[i].value); - } - - if (shape->hasMarkers ()) { + sp_shape_set_marker (this, i, this->style->marker[i].value); + } + if (this->hasMarkers ()) { /* provide key and dimension the marker views */ if (!s->key()) { s->setKey(SPItem::display_key_new (SP_MARKER_LOC_QTY)); } for (int i = 0; i < SP_MARKER_LOC_QTY; i++) { - if (shape->_marker[i]) { - sp_marker_show_dimension ((SPMarker *) shape->_marker[i], + if (this->_marker[i]) { + sp_marker_show_dimension ((SPMarker *) this->_marker[i], s->key() + i, - shape->numberOfMarkers (i)); + this->numberOfMarkers (i)); } } /* Update marker views */ - sp_shape_update_marker_view (shape, s); + sp_shape_update_marker_view (this, s); } return s; @@ -742,25 +764,18 @@ Inkscape::DrawingItem* CShape::show(Inkscape::Drawing &drawing, unsigned int key /** * Sets style, path, and paintbox. Updates marker views, including dimensions. */ -void CShape::hide(unsigned int key) { - SPShape *shape = this->spshape; - SPShape* item = shape; - - SPItemView *v; - int i; - - for (i=0; i<SP_MARKER_LOC_QTY; i++) { - if (shape->_marker[i]) { - for (v = item->display; v != NULL; v = v->next) { - if (key == v->key) { - sp_marker_hide ((SPMarker *) shape->_marker[i], - v->arenaitem->key() + i); - } - } - } - } - -// CLPEItem::onHide(key); +void SPShape::hide(unsigned int key) { + for (int i=0; i<SP_MARKER_LOC_QTY; i++) { + if (this->_marker[i]) { + for (SPItemView* v = this->display; v != NULL; v = v->next) { + if (key == v->key) { + sp_marker_hide ((SPMarker *) this->_marker[i], v->arenaitem->key() + i); + } + } + } + } + + //CLPEItem::onHide(key); } /** @@ -791,6 +806,7 @@ int SPShape::hasMarkers() const int SPShape::numberOfMarkers(int type) { Geom::PathVector const & pathv = this->_curve->get_pathvector(); + if (pathv.size() == 0) { return 0; } @@ -918,7 +934,7 @@ sp_shape_set_marker (SPObject *object, unsigned int key, const gchar *value) } // CPPIFY: make pure virtual -void CShape::set_shape() { +void SPShape::set_shape() { //throw; } @@ -927,10 +943,6 @@ void CShape::set_shape() { /** * Calls any registered handlers for the set_shape action */ -void SPShape::setShape() -{ - this->cshape->set_shape(); -} /** * Adds a curve to the shape. If owner is specified, a reference @@ -943,6 +955,7 @@ void SPShape::setCurve(SPCurve *new_curve, unsigned int owner) if (_curve) { _curve = _curve->unref(); } + if (new_curve) { if (owner) { _curve = new_curve->ref(); @@ -950,6 +963,7 @@ void SPShape::setCurve(SPCurve *new_curve, unsigned int owner) _curve = new_curve->copy(); } } + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } @@ -962,6 +976,7 @@ SPShape::setCurveBeforeLPE (SPCurve *new_curve) if (_curve_before_lpe) { _curve_before_lpe = _curve_before_lpe->unref(); } + if (new_curve) { _curve_before_lpe = new_curve->ref(); } @@ -975,6 +990,7 @@ SPCurve * SPShape::getCurve() const if (_curve) { return _curve->copy(); } + return NULL; } @@ -992,6 +1008,7 @@ SPCurve * SPShape::getCurveBeforeLPE() const return _curve->copy(); } } + return NULL; } @@ -1003,6 +1020,7 @@ void SPShape::setCurveInsync(SPCurve *new_curve, unsigned int owner) if (_curve) { _curve = _curve->unref(); } + if (new_curve) { if (owner) { _curve = new_curve->ref(); @@ -1012,25 +1030,22 @@ void SPShape::setCurveInsync(SPCurve *new_curve, unsigned int owner) } } -void CShape::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) { - SPShape const *shape = this->spshape; - SPShape const *item = shape; - - g_assert(item != NULL); - g_assert(SP_IS_SHAPE(item)); - - if (shape->_curve == NULL) { +void SPShape::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) { + if (this->_curve == NULL) { return; } - Geom::PathVector const &pathv = shape->_curve->get_pathvector(); - if (pathv.empty()) + Geom::PathVector const &pathv = this->_curve->get_pathvector(); + + if (pathv.empty()) { return; + } - Geom::Affine const i2dt (item->i2dt_affine ()); + Geom::Affine const i2dt (this->i2dt_affine ()); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { - Geom::OptRect bbox = item->desktopVisualBounds(); + Geom::OptRect bbox = this->desktopVisualBounds(); + if (bbox) { p.push_back(Inkscape::SnapCandidatePoint(bbox->midpoint(), Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT)); } @@ -1044,6 +1059,7 @@ void CShape::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape:: Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); // outgoing curve + while (curve_it1 != path_it->end_default()) { // For each path: consider midpoints of line segments for snapping @@ -1071,6 +1087,7 @@ void CShape::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape:: if (c1 || c2) { Inkscape::SnapSourceType sst; Inkscape::SnapTargetType stt; + switch (nodetype) { case Geom::NODE_CUSP: sst = Inkscape::SNAPSOURCE_NODE_CUSP; @@ -1086,6 +1103,7 @@ void CShape::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape:: stt = Inkscape::SNAPTARGET_UNDEFINED; break; } + p.push_back(Inkscape::SnapCandidatePoint(curve_it1->finalPoint() * i2dt, sst, stt)); } } @@ -1098,8 +1116,10 @@ void CShape::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape:: // (using "Method 1" as described in Inkscape::ObjectSnapper::_collectNodes()) if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_PATH_INTERSECTION) || snapprefs->isSourceSnappable(Inkscape::SNAPSOURCE_PATH_INTERSECTION)) { Geom::Crossings cs; + try { cs = self_crossings(*path_it); // This can be slow! + if (!cs.empty()) { // There might be multiple intersections... for (Geom::Crossings::const_iterator i = cs.begin(); i != cs.end(); ++i) { Geom::Point p_ix = (*path_it).pointAt((*i).ta); diff --git a/src/sp-shape.h b/src/sp-shape.h index c11ce87f3..1cd10640e 100644 --- a/src/sp-shape.h +++ b/src/sp-shape.h @@ -30,20 +30,14 @@ class SPDesktop; namespace Inkscape { class DrawingItem; } - -class CShape; - /** * Base class for shapes, including <path> element */ -class SPShape : public SPLPEItem { +class SPShape : public SPLPEItem, public CLPEItem { public: SPShape(); virtual ~SPShape(); - CShape* cshape; - - void setShape (); SPCurve * getCurve () const; SPCurve * getCurveBeforeLPE () const; void setCurve (SPCurve *curve, unsigned int owner); @@ -60,12 +54,6 @@ public: SPObject *_marker[SP_MARKER_LOC_QTY]; sigc::connection _release_connect [SP_MARKER_LOC_QTY]; sigc::connection _modified_connect [SP_MARKER_LOC_QTY]; -}; - -class CShape : public CLPEItem { -public: - CShape(SPShape* shape); - virtual ~CShape(); virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual void release(); @@ -84,9 +72,6 @@ public: virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); virtual void set_shape(); - -protected: - SPShape* spshape; }; diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 644f32430..e041e4f7d 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -39,9 +39,7 @@ namespace { bool spiralRegistered = SPFactory::instance().registerObject("spiral", createSpiral); } -SPSpiral::SPSpiral() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPSpiral::SPSpiral() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -59,7 +57,7 @@ SPSpiral::~SPSpiral() { } void SPSpiral::build(SPDocument * document, Inkscape::XML::Node * repr) { - CShape::build(document, repr); + SPShape::build(document, repr); this->readAttr("sodipodi:cx"); this->readAttr("sodipodi:cy"); @@ -101,7 +99,7 @@ Inkscape::XML::Node* SPSpiral::write(Inkscape::XML::Document *xml_doc, Inkscape: repr->setAttribute("d", d); g_free(d); - CShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); + SPShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } @@ -199,7 +197,7 @@ void SPSpiral::set(unsigned int key, gchar const* value) { break; default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -208,10 +206,10 @@ void SPSpiral::update(SPCtx *ctx, guint flags) { SPSpiral* object = this; if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - reinterpret_cast<SPShape *>(object)->setShape(); + reinterpret_cast<SPShape *>(object)->set_shape(); } - CShape::update(ctx, flags); + SPShape::update(ctx, flags); } void SPSpiral::update_patheffect(bool write) { @@ -427,7 +425,7 @@ void SPSpiral::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape Inkscape::SnapPreferences local_snapprefs = *snapprefs; local_snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, false); - CShape::snappoints(p, &local_snapprefs); + SPShape::snappoints(p, &local_snapprefs); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { Geom::Affine const i2dt (this->i2dt_affine ()); diff --git a/src/sp-spiral.h b/src/sp-spiral.h index 4ae6d225d..f6bce7b61 100644 --- a/src/sp-spiral.h +++ b/src/sp-spiral.h @@ -39,7 +39,7 @@ * * \todo Should I remove these attributes? */ -class SPSpiral : public SPShape, public CShape { +class SPSpiral : public SPShape { public: SPSpiral(); virtual ~SPSpiral(); diff --git a/src/sp-star.cpp b/src/sp-star.cpp index 8414c6d9a..68e85c1fd 100644 --- a/src/sp-star.cpp +++ b/src/sp-star.cpp @@ -43,7 +43,6 @@ namespace { } SPStar::SPStar() : SPPolygon() { - this->cshape = this; this->clpeitem = this; this->citem = this; this->cobject = this; @@ -63,7 +62,7 @@ SPStar::~SPStar() { void SPStar::build(SPDocument * document, Inkscape::XML::Node * repr) { // CPPIFY: see header file - CShape::build(document, repr); + SPShape::build(document, repr); this->readAttr( "sodipodi:cx" ); this->readAttr( "sodipodi:cy" ); @@ -103,7 +102,7 @@ Inkscape::XML::Node* SPStar::write(Inkscape::XML::Document *xml_doc, Inkscape::X g_free(d); // CPPIFY: see header file - CShape::write(xml_doc, repr, flags); + SPShape::write(xml_doc, repr, flags); return repr; } @@ -221,7 +220,7 @@ void SPStar::set(unsigned int key, const gchar* value) { default: // CPPIFY: see header file - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -231,11 +230,11 @@ void SPStar::update(SPCtx *ctx, guint flags) { SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - this->setShape(); + this->set_shape(); } // CPPIFY: see header file - CShape::update(ctx, flags); + SPShape::update(ctx, flags); } void SPStar::update_patheffect(bool write) { @@ -512,7 +511,7 @@ void SPStar::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape:: local_snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, false); // CPPIFY: see header file - CShape::snappoints(p, &local_snapprefs); + SPShape::snappoints(p, &local_snapprefs); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { Geom::Affine const i2dt (this->i2dt_affine ()); diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index 253ab6b58..c54e7c487 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -458,7 +458,7 @@ sp_spiral_finish(SPSpiralContext *sc) SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; - SP_SHAPE(spiral)->setShape(); + SP_SHAPE(spiral)->set_shape(); SP_OBJECT(spiral)->updateRepr(SP_OBJECT_WRITE_EXT); desktop->canvas->endForcedFullRedraws(); diff --git a/src/star-context.cpp b/src/star-context.cpp index e2d6961f0..35ea79462 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -479,7 +479,7 @@ sp_star_finish (SPStarContext * sc) SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; SPObject *object = SP_OBJECT(sc->item); - (SP_SHAPE(sc->item))->setShape(); + (SP_SHAPE(sc->item))->set_shape(); object->updateRepr(SP_OBJECT_WRITE_EXT); |
