diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-02-07 00:12:34 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2016-02-07 00:12:34 +0000 |
| commit | 7c5342d04a8c59714becfdf0ceb8ea1de4686736 (patch) | |
| tree | ad0d2e79be2855fc85b209f79697ab11509aab4a /src | |
| parent | Added phantom meassure feature to meassure tool (diff) | |
| download | inkscape-7c5342d04a8c59714becfdf0ceb8ea1de4686736.tar.gz inkscape-7c5342d04a8c59714becfdf0ceb8ea1de4686736.zip | |
Fix for bug 1540518. Improved performance based on previous meassure code comment
Fixed bugs:
- https://launchpad.net/bugs/1540518
(bzr r14635)
Diffstat (limited to 'src')
| -rw-r--r-- | src/document.cpp | 14 | ||||
| -rw-r--r-- | src/document.h | 4 | ||||
| -rw-r--r-- | src/ui/tools/measure-tool.cpp | 105 |
3 files changed, 56 insertions, 67 deletions
diff --git a/src/document.cpp b/src/document.cpp index 70fb56fe8..d4bd29386 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1262,14 +1262,14 @@ static bool overlaps(Geom::Rect const &area, Geom::Rect const &box) } static std::vector<SPItem*> &find_items_in_area(std::vector<SPItem*> &s, SPGroup *group, unsigned int dkey, Geom::Rect const &area, - bool (*test)(Geom::Rect const &, Geom::Rect const &), bool take_insensitive = false) + bool (*test)(Geom::Rect const &, Geom::Rect const &), bool take_insensitive = false, bool into_groups = false) { g_return_val_if_fail(SP_IS_GROUP(group), s); for ( SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { if ( SP_IS_ITEM(o) ) { - if (SP_IS_GROUP(o) && SP_GROUP(o)->effectiveLayerMode(dkey) == SPGroup::LAYER ) { - s = find_items_in_area(s, SP_GROUP(o), dkey, area, test); + if (SP_IS_GROUP(o) && (SP_GROUP(o)->effectiveLayerMode(dkey) == SPGroup::LAYER || into_groups)) { + s = find_items_in_area(s, SP_GROUP(o), dkey, area, test, take_insensitive, into_groups); } else { SPItem *child = SP_ITEM(o); Geom::OptRect box = child->desktopVisualBounds(); @@ -1430,11 +1430,11 @@ static SPItem *find_group_at_point(unsigned int dkey, SPGroup *group, Geom::Poin * Assumes box is normalized (and g_asserts it!) * */ -std::vector<SPItem*> SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box) const +std::vector<SPItem*> SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect const &box, bool into_groups) const { std::vector<SPItem*> x; g_return_val_if_fail(this->priv != NULL, x); - return find_items_in_area(x, SP_GROUP(this->root), dkey, box, is_within); + return find_items_in_area(x, SP_GROUP(this->root), dkey, box, is_within, false, into_groups); } /* @@ -1444,11 +1444,11 @@ std::vector<SPItem*> SPDocument::getItemsInBox(unsigned int dkey, Geom::Rect con * */ -std::vector<SPItem*> SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const +std::vector<SPItem*> SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box, bool into_groups) const { std::vector<SPItem*> x; g_return_val_if_fail(this->priv != NULL, x); - return find_items_in_area(x, SP_GROUP(this->root), dkey, box, overlaps); + return find_items_in_area(x, SP_GROUP(this->root), dkey, box, overlaps, false, into_groups); } std::vector<SPItem*> SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points, bool all_layers, size_t limit) const diff --git a/src/document.h b/src/document.h index cf8ebc3cb..b4a8a8e8e 100644 --- a/src/document.h +++ b/src/document.h @@ -260,8 +260,8 @@ public: bool addResource(char const *key, SPObject *object); bool removeResource(char const *key, SPObject *object); const std::set<SPObject *> getResourceList(char const *key) const; - std::vector<SPItem*> getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; - std::vector<SPItem*> getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; + std::vector<SPItem*> getItemsInBox(unsigned int dkey, Geom::Rect const &box, bool into_groups = false) const; + std::vector<SPItem*> getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box, bool into_groups = false) const; SPItem *getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; std::vector<SPItem*> getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points, bool all_layers = true, size_t limit = 0) const; SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const; diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index bc0ab6d46..c40d2581e 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -1131,63 +1131,50 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, bool to_phantom, } std::vector<SPItem*> items; - Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); - r->setMode(RUBBERBAND_MODE_TOUCHPATH); - if(!show_in_between) { - r->start(desktop,start_p); - r->move(end_p); - items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); - r->stop(); - r->setMode(RUBBERBAND_MODE_TOUCHPATH); - r->start(desktop,end_p); - r->move(start_p); - std::vector<SPItem*> items_reverse = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); - r->stop(); - if(items_reverse.size() == 2 && items_reverse[1] != items[0] && items_reverse[1] != items[1]) { - items.push_back(items_reverse[1]); - } - if(items_reverse.size() >= 1 && items_reverse[0] != items[1]) { - items.push_back(items_reverse[0]); - } - } else { - r->start(desktop,start_p); - r->move(end_p); - items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers); - r->stop(); + SPDocument *doc = desktop->getDocument(); + Geom::Rect rect(start_p, end_p); + items = doc->getItemsPartiallyInBox(desktop->dkey, rect, true); + Inkscape::LayerModel *layer_model = NULL; + SPObject *current_layer = NULL; + if(desktop){ + layer_model = desktop->layers; + current_layer = desktop->currentLayer(); } std::vector<double> intersection_times; for (std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end(); ++i) { SPItem *item = *i; - if (SP_IS_SHAPE(item)) { - calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); - } else { - if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { - Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); - do { - Inkscape::Text::Layout::iterator iter_next = iter; - iter_next.nextGlyph(); // iter_next is one glyph ahead from iter - if (iter == iter_next) { - break; - } - - // get path from iter to iter_next: - SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); - iter = iter_next; // shift to next glyph - if (!curve) { - continue; // error converting this glyph - } - if (curve->is_empty()) { // whitespace glyph? - curve->unref(); - continue; - } - - curve->transform(item->i2doc_affine()); - - calculate_intersections(desktop, item, lineseg, curve, intersection_times); - if (iter == te_get_layout(item)->end()) { - break; - } - } while (true); + if(all_layers || (layer_model && layer_model->layerForObject(item) == current_layer)){ + if (SP_IS_SHAPE(item)) { + calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); + } else { + if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { + Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); + do { + Inkscape::Text::Layout::iterator iter_next = iter; + iter_next.nextGlyph(); // iter_next is one glyph ahead from iter + if (iter == iter_next) { + break; + } + + // get path from iter to iter_next: + SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); + iter = iter_next; // shift to next glyph + if (!curve) { + continue; // error converting this glyph + } + if (curve->is_empty()) { // whitespace glyph? + curve->unref(); + continue; + } + + curve->transform(item->i2doc_affine()); + + calculate_intersections(desktop, item, lineseg, curve, intersection_times); + if (iter == te_get_layout(item)->end()) { + break; + } + } while (true); + } } } } @@ -1204,13 +1191,15 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, bool to_phantom, std::vector<Geom::Point> intersections; std::sort(intersection_times.begin(), intersection_times.end()); for (std::vector<double>::iterator iter_t = intersection_times.begin(); iter_t != intersection_times.end(); ++iter_t) { - if(show_in_between) { - intersections.push_back(lineseg[0].pointAt(*iter_t)); - } + intersections.push_back(lineseg[0].pointAt(*iter_t)); } + if(!show_in_between && intersection_times.size() > 1) { - intersections.push_back(lineseg[0].pointAt(intersection_times[0])); - intersections.push_back(lineseg[0].pointAt(intersection_times[intersection_times.size()-1])); + Geom::Point start = lineseg[0].pointAt(intersection_times[0]); + Geom::Point end = lineseg[0].pointAt(intersection_times[intersection_times.size()-1]); + intersections.clear(); + intersections.push_back(start); + intersections.push_back(end); } if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)) { intersections.insert(intersections.begin(),lineseg[0].pointAt(0)); |
