From 1867f123d5c52008738a2873abda555d3bd882f3 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Fri, 24 Jul 2015 22:16:07 +0200 Subject: 3D box tool: the shift key must not prevent snapping of the vanishing point. It must only serve to separate the vanishing points, in case of multiple boxes sharing the same vanishing points Fixed bugs: - https://launchpad.net/bugs/1460415 (bzr r14254) --- src/vanishing-point.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/vanishing-point.cpp') diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 46f895c06..553e3a31d 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -130,7 +130,7 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g // FIXME: Do we need to create a new dragger as well? dragger->updateZOrders (); DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_3DBOX, - _("Split vanishing points")); + _("Split vanishing points")); return; } } @@ -175,22 +175,24 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g // as is currently the case. DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_3DBOX, - _("Merge vanishing points")); + _("Merge vanishing points")); return; } } + } - // We didn't snap to another dragger, so we'll try a regular snap - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); - m.unSetup(); - if (s.getSnapped()) { - p = s.getPoint(); - knot->moveto(p); - } + // We didn't hit the return statement above, so we didn't snap to another dragger. Therefore we'll now try a regular snap + // Regardless of the status of the SHIFT key, we will try to snap; Here SHIFT does not disable snapping, as the shift key + // has a different purpose in this context (see above) + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); + m.unSetup(); + if (s.getSnapped()) { + p = s.getPoint(); + knot->moveto(p); } dragger->point = p; // FIXME: Is dragger->point being used at all? @@ -241,7 +243,7 @@ vp_knot_ungrabbed_handler (SPKnot *knot, guint /*state*/, gpointer data) g_return_if_fail (dragger->parent); g_return_if_fail (dragger->parent->document); DocumentUndo::done(dragger->parent->document, SP_VERB_CONTEXT_3DBOX, - _("3D box: Move vanishing point")); + _("3D box: Move vanishing point")); } unsigned int VanishingPoint::global_counter = 0; @@ -630,7 +632,7 @@ VPDrag::updateBoxHandles () // FIXME: Is there a way to update the knots without accessing the // (previously) statically linked function KnotHolder::update_knots? - std::vector sel = selection->itemList(); + std::vector sel = selection->itemList(); if (sel.empty()) return; // no selection -- cgit v1.2.3 From 05e90b229e833b64bee150810953cf1328621b99 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sun, 6 Dec 2015 15:01:35 +0100 Subject: cppification: GSList replaced by vectors (vanishing points) (bzr r14504.1.3) --- src/vanishing-point.cpp | 66 ++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) (limited to 'src/vanishing-point.cpp') diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 553e3a31d..295854787 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -137,8 +137,8 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g if (!(state & GDK_SHIFT_MASK)) { // without Shift; see if we need to snap to another dragger - for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) { - VPDragger *d_new = (VPDragger *) di->data; + for (std::vector::const_iterator di = dragger->parent->draggers.begin(); di != dragger->parent->draggers.end(); ++di) { + VPDragger *d_new = *di; if ((d_new != dragger) && (Geom::L2 (d_new->point - p) < snap_dist)) { if (have_VPs_of_same_perspective (dragger, d_new)) { // this would result in degenerate boxes, which we disallow for the time being @@ -155,7 +155,7 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, g d_new->vps.merge(dragger->vps); // ... delete old dragger ... - drag->draggers = g_list_remove (drag->draggers, dragger); + drag->draggers.erase(std::remove(drag->draggers.begin(), drag->draggers.end(), dragger),drag->draggers.end()); delete dragger; dragger = NULL; @@ -494,8 +494,6 @@ VPDrag::VPDrag (SPDocument *document) this->document = document; this->selection = SP_ACTIVE_DESKTOP->getSelection(); - this->draggers = NULL; - this->lines = NULL; this->show_lines = true; this->front_or_rear_lines = 0x1; @@ -522,17 +520,15 @@ VPDrag::~VPDrag() this->sel_changed_connection.disconnect(); this->sel_modified_connection.disconnect(); - for (GList *l = this->draggers; l != NULL; l = l->next) { - delete ((VPDragger *) l->data); + for (std::vector::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i) { + delete (*i); } - g_list_free (this->draggers); - this->draggers = NULL; + this->draggers.clear(); - for (GSList const *i = this->lines; i != NULL; i = i->next) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(i->data)); + for (std::vector::const_iterator i = this->lines.begin(); i != this->lines.end(); ++i) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(*i)); } - g_slist_free (this->lines); - this->lines = NULL; + this->lines.clear(); } /** @@ -541,8 +537,8 @@ VPDrag::~VPDrag() VPDragger * VPDrag::getDraggerFor (VanishingPoint const &vp) { - for (GList const* i = this->draggers; i != NULL; i = i->next) { - VPDragger *dragger = (VPDragger *) i->data; + for (std::vector::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i) { + VPDragger *dragger = *i; for (std::list::iterator j = dragger->vps.begin(); j != dragger->vps.end(); ++j) { // TODO: Should we compare the pointers or the VPs themselves!?!?!?! if (*j == vp) { @@ -557,8 +553,8 @@ void VPDrag::printDraggers () { g_print ("=== VPDrag info: =================================\n"); - for (GList const* i = this->draggers; i != NULL; i = i->next) { - ((VPDragger *) i->data)->printVPs(); + for (std::vector::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i) { + (*i)->printVPs(); g_print ("========\n"); } g_print ("=================================================\n"); @@ -573,11 +569,10 @@ VPDrag::updateDraggers () if (this->dragging) return; // delete old draggers - for (GList const* i = this->draggers; i != NULL; i = i->next) { - delete ((VPDragger *) i->data); + for (std::vector::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i) { + delete (*i); } - g_list_free (this->draggers); - this->draggers = NULL; + this->draggers.clear(); g_return_if_fail (this->selection != NULL); @@ -603,11 +598,10 @@ void VPDrag::updateLines () { // delete old lines - for (GSList const *i = this->lines; i != NULL; i = i->next) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(i->data)); + for (std::vector::const_iterator i = this->lines.begin(); i != this->lines.end(); ++i) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(*i)); } - g_slist_free (this->lines); - this->lines = NULL; + this->lines.clear(); // do nothing if perspective lines are currently disabled if (this->show_lines == 0) return; @@ -651,8 +645,8 @@ VPDrag::updateBoxHandles () void VPDrag::updateBoxReprs () { - for (GList *i = this->draggers; i != NULL; i = i->next) { - VPDragger *dragger = (VPDragger *) i->data; + for (std::vector::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i) { + VPDragger *dragger = *i; for (std::list::iterator i = dragger->vps.begin(); i != dragger->vps.end(); ++i) { (*i).updateBoxReprs(); } @@ -662,8 +656,8 @@ VPDrag::updateBoxReprs () void VPDrag::updateBoxDisplays () { - for (GList *i = this->draggers; i != NULL; i = i->next) { - VPDragger *dragger = (VPDragger *) i->data; + for (std::vector::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i) { + VPDragger *dragger = *i; for (std::list::iterator i = dragger->vps.begin(); i != dragger->vps.end(); ++i) { (*i).updateBoxDisplays(); } @@ -758,8 +752,8 @@ VPDrag::addDragger (VanishingPoint &vp) } Geom::Point p = vp.get_pos(); - for (GList *i = this->draggers; i != NULL; i = i->next) { - VPDragger *dragger = (VPDragger *) i->data; + for (std::vector::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i) { + VPDragger *dragger = *i; if (Geom::L2 (dragger->point - p) < MERGE_DIST) { // distance is small, merge this draggable into dragger, no need to create new dragger dragger->addVP (vp); @@ -769,16 +763,16 @@ VPDrag::addDragger (VanishingPoint &vp) VPDragger *new_dragger = new VPDragger(this, p, vp); // fixme: draggers should be added AFTER the last one: this way tabbing through them will be from begin to end. - this->draggers = g_list_append (this->draggers, new_dragger); + this->draggers.push_back(new_dragger); } void VPDrag::swap_perspectives_of_VPs(Persp3D *persp2, Persp3D *persp1) { // iterate over all VP in all draggers and replace persp2 with persp1 - for (GList *i = this->draggers; i != NULL; i = i->next) { - for (std::list::iterator j = ((VPDragger *) (i->data))->vps.begin(); - j != ((VPDragger *) (i->data))->vps.end(); ++j) { + for (std::vector::const_iterator i = this->draggers.begin(); i != this->draggers.end(); ++i) { + for (std::list::iterator j = (*i)->vps.begin(); + j != (*i)->vps.end(); ++j) { if ((*j).get_perspective() == persp2) { (*j).set_perspective(persp1); } @@ -790,7 +784,7 @@ void VPDrag::addLine(Geom::Point const &p1, Geom::Point const &p2, Inkscape::Ctr { SPCtrlLine *line = ControlManager::getManager().createControlLine(SP_ACTIVE_DESKTOP->getControls(), p1, p2, type); sp_canvas_item_show(line); - this->lines = g_slist_append(this->lines, line); + this->lines.push_back(line); } } // namespace Box3D -- cgit v1.2.3 From c54db8d887cae2bd6dd326a10f976c726f905e7d Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 7 Dec 2015 21:19:14 +0100 Subject: static code analysis (bzr r14509) --- src/vanishing-point.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/vanishing-point.cpp') diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 553e3a31d..19750bd37 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -259,7 +259,7 @@ std::list VanishingPoint::selectedBoxes(Inkscape::Selection *sel) { std::list sel_boxes; std::vector itemlist=sel->itemList(); - for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) { SPItem *item = *i; SPBox3D *box = dynamic_cast(item); if (box && this->hasBox(box)) { @@ -399,7 +399,7 @@ VPDragger::VPsOfSelectedBoxes() { // FIXME: Should we take the selection from the parent VPDrag? I guess it shouldn't make a difference. Inkscape::Selection *sel = SP_ACTIVE_DESKTOP->getSelection(); std::vector itemlist=sel->itemList(); - for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) { SPItem *item = *i; SPBox3D *box = dynamic_cast(item); if (box) { @@ -582,7 +582,7 @@ VPDrag::updateDraggers () g_return_if_fail (this->selection != NULL); std::vector itemlist=this->selection->itemList(); - for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) { SPItem *item = *i; SPBox3D *box = dynamic_cast(item); if (box) { @@ -615,7 +615,7 @@ VPDrag::updateLines () g_return_if_fail (this->selection != NULL); std::vector itemlist=this->selection->itemList(); - for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) { + for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) { SPItem *item = *i; SPBox3D *box = dynamic_cast(item); if (box) { -- cgit v1.2.3 From e16f1a053c67a8c42172f5186f247f11c3b6e777 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 22 Feb 2016 20:49:03 +0100 Subject: static code analysis (bzr r14664) --- src/vanishing-point.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/vanishing-point.cpp') diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 9ce60fce7..32ccbad93 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -269,15 +269,14 @@ VanishingPoint::selectedBoxes(Inkscape::Selection *sel) { return sel_boxes; } -VPDragger::VPDragger(VPDrag *parent, Geom::Point p, VanishingPoint &vp) +VPDragger::VPDragger(VPDrag *parent, Geom::Point p, VanishingPoint &vp) : + parent(parent), + knot(NULL), + point(p), + point_original(p), + dragging_started(false), + vps() { - this->parent = parent; - - this->point = p; - this->point_original = p; - - this->dragging_started = false; - if (vp.is_finite()) { // create the knot this->knot = new SPKnot(SP_ACTIVE_DESKTOP, NULL); -- cgit v1.2.3