Commit fc026649 authored by Osama Ahmad's avatar Osama Ahmad Committed by Marc Jeanmougin
Browse files

Refactoring: removing Guide Constraints

Guide constraints/Attachments were apparently a project from 2004 that was never enabled and which consisted on mostly dead code. This commit removes it.
parent ae80b406
Pipeline #275195464 failed with stages
in 56 minutes and 52 seconds
......@@ -63,7 +63,6 @@ set(inkscape_SRC
rdf.cpp
removeoverlap.cpp
rubberband.cpp
satisfied-guide-cns.cpp
selcue.cpp
selection-chemistry.cpp
selection-describer.cpp
......@@ -76,7 +75,6 @@ set(inkscape_SRC
snapped-line.cpp
snapped-point.cpp
snapper.cpp
sp-item-notify-moveto.cpp
style-internal.cpp
style.cpp
text-chemistry.cpp
......@@ -161,10 +159,8 @@ set(inkscape_SRC
proj_pt.h
pure-transform.h
rdf.h
remove-last.h
removeoverlap.h
rubberband.h
satisfied-guide-cns.h
selcue.h
selection-chemistry.h
selection-describer.h
......@@ -179,9 +175,6 @@ set(inkscape_SRC
snapped-line.h
snapped-point.h
snapper.h
sp-guide-attachment.h
sp-guide-constraint.h
sp-item-notify-moveto.h
streq.h
strneq.h
style-enums.h
......
......@@ -201,7 +201,7 @@ namespace XML {}
* - SPFlowline [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h]
* - SPFlowregionbreak [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h]
* - SPGuide [\ref sp-guide.cpp, \ref sp-guide.h]
* - SPItem [\ref sp-item.cpp, \ref sp-item.h, \ref sp-item-notify-moveto.cpp, \ref sp-item-rm-unsatisfied-cns.cpp, \ref sp-item-transform.cpp, \ref sp-item-update-cns.cpp, ]
* - SPItem [\ref sp-item.cpp, \ref sp-item.h, \ref sp-item-transform.cpp, ]
* - SPFlowdiv [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h]
* - SPFlowpara [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h]
* - SPFlowregion [\ref sp-flowregion.cpp, \ref sp-flowregion.h]
......@@ -295,7 +295,7 @@ namespace XML {}
*
* Snapper, GridSnapper, GuideSnapper [\ref snap.cpp, \ref snap.h]
*
* SPGuide [\ref sp-guide.cpp, \ref sp-guide.h, \ref satisfied-guide-cns.cpp, \ref sp-guide-attachment.h, \ref sp-guide-constraint.h]
* SPGuide [\ref sp-guide.cpp, \ref sp-guide.h]
*
* [\ref help.cpp] [\ref inkscape.cpp] [\ref inkscape-stock.cpp]
* [\ref interface.cpp] [\ref main.cpp, \ref winmain.cpp]
......
......@@ -33,9 +33,7 @@ set(object_SRC
sp-hatch.cpp
sp-image.cpp
sp-item-group.cpp
sp-item-rm-unsatisfied-cns.cpp
sp-item-transform.cpp
sp-item-update-cns.cpp
sp-item.cpp
sp-line.cpp
sp-linear-gradient.cpp
......@@ -122,9 +120,7 @@ set(object_SRC
sp-hatch.h
sp-image.h
sp-item-group.h
sp-item-rm-unsatisfied-cns.h
sp-item-transform.h
sp-item-update-cns.h
sp-item.h
sp-line.h
sp-linear-gradient.h
......
......@@ -102,9 +102,7 @@ Other related files:
sp-gradient-spread.h
sp-gradient-units.h
sp-gradient-vector.h
sp-item-rm-unsatisfied-cns.h
sp-item-transform.h
sp-item-update-cns.h
sp-marker-loc.h
sp-mesh-array.h
sp-paint-server-reference.h
......
......@@ -16,7 +16,6 @@
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include <algorithm>
#include <cstring>
#include <vector>
#include <glibmm/i18n.h>
......@@ -27,11 +26,9 @@
#include "document-undo.h"
#include "helper-fns.h"
#include "inkscape.h"
#include "remove-last.h"
#include "verbs.h"
#include "sp-guide.h"
#include "sp-item-notify-moveto.h"
#include "sp-namedview.h"
#include "sp-root.h"
......@@ -253,7 +250,14 @@ SPGuide *SPGuide::createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::P
}
SPGuide *SPGuide::duplicate(){
return SPGuide::createSPGuide(document, point_on_line, Geom::Point(point_on_line[Geom::X] + normal_to_line[Geom::Y],point_on_line[Geom::Y] - normal_to_line[Geom::X]));
return SPGuide::createSPGuide(
document,
point_on_line,
Geom::Point(
point_on_line[Geom::X] + normal_to_line[Geom::Y],
point_on_line[Geom::Y] - normal_to_line[Geom::X]
)
);
}
void sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Point, Geom::Point> > &pts)
......@@ -352,16 +356,6 @@ void SPGuide::sensitize(Inkscape::UI::Widget::Canvas *canvas, bool sensitive)
assert(false);
}
Geom::Point SPGuide::getPositionFrom(Geom::Point const &pt) const
{
return -(pt - point_on_line);
}
double SPGuide::getDistanceFrom(Geom::Point const &pt) const
{
return Geom::dot(pt - point_on_line, normal_to_line);
}
/**
* \arg commit False indicates temporary moveto in response to motion event while dragging,
* true indicates a "committing" version: in response to button release event after
......@@ -405,16 +399,6 @@ void SPGuide::moveto(Geom::Point const point_on_line, bool const commit)
//XML Tree being used here directly while it shouldn't be.
sp_repr_set_point(getRepr(), "position", Geom::Point(newx, newy) );
}
/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
for (std::vector<SPGuideAttachment>::const_iterator i(attached_items.begin()),
iEnd(attached_items.end());
i != iEnd; ++i)
{
SPGuideAttachment const &att = *i;
sp_item_notify_moveto(*att.item, this, att.snappoint_ix, position, commit);
}
*/
}
/**
......@@ -444,16 +428,6 @@ void SPGuide::set_normal(Geom::Point const normal_to_line, bool const commit)
sp_repr_set_point(getRepr(), "orientation", normal);
}
/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
for (std::vector<SPGuideAttachment>::const_iterator i(attached_items.begin()),
iEnd(attached_items.end());
i != iEnd; ++i)
{
SPGuideAttachment const &att = *i;
sp_item_notify_moveto(*att.item, this, att.snappoint_ix, position, commit);
}
*/
}
void SPGuide::set_color(const unsigned r, const unsigned g, const unsigned b, bool const commit)
......@@ -551,15 +525,6 @@ void sp_guide_remove(SPGuide *guide)
{
g_assert(SP_IS_GUIDE(guide));
for (std::vector<SPGuideAttachment>::const_iterator i(guide->attached_items.begin()),
iEnd(guide->attached_items.end());
i != iEnd; ++i)
{
SPGuideAttachment const &att = *i;
remove_last(att.item->constraints, SPGuideConstraint(guide, att.snappoint_ix));
}
guide->attached_items.clear();
//XML Tree being used directly while it shouldn't be.
sp_repr_unparent(guide->getRepr());
}
......
......@@ -18,7 +18,6 @@
#include <vector>
#include "sp-object.h"
#include "sp-guide-attachment.h"
typedef unsigned int guint32;
extern "C" {
......@@ -26,8 +25,6 @@ extern "C" {
}
class SPDesktop;
struct SPCanvasGroup;
struct SPGuideLine;
#define SP_GUIDE(obj) (dynamic_cast<SPGuide*>((SPObject*)obj))
#define SP_IS_GUIDE(obj) (dynamic_cast<const SPGuide*>((SPObject*)obj) != NULL)
......@@ -82,8 +79,6 @@ public:
char* description(bool const verbose = true) const;
double angle() const { return std::atan2( - normal_to_line[Geom::X], normal_to_line[Geom::Y] ); }
double getDistanceFrom(Geom::Point const &pt) const;
Geom::Point getPositionFrom(Geom::Point const &pt) const;
protected:
void build(SPDocument* doc, Inkscape::XML::Node* repr) override;
......@@ -98,8 +93,6 @@ protected:
guint32 color;
guint32 hicolor;
public:
std::vector<SPGuideAttachment> attached_items; // unused
};
// These functions rightfully belong to SPDesktop. What gives?!
......
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* TODO: insert short description here
*//*
* Authors: see git history
*
* Copyright (C) 2018 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include <algorithm>
#include <2geom/coord.h>
#include <vector>
#include "remove-last.h"
#include "sp-guide.h"
#include "sp-item-rm-unsatisfied-cns.h"
void sp_item_rm_unsatisfied_cns(SPItem &item)
{
if (item.constraints.empty()) {
return;
}
std::vector<Inkscape::SnapCandidatePoint> snappoints;
item.getSnappoints(snappoints, nullptr);
for (unsigned i = item.constraints.size(); i--;) {
g_assert( i < item.constraints.size() );
SPGuideConstraint const &cn = item.constraints[i];
int const snappoint_ix = cn.snappoint_ix;
g_assert( snappoint_ix < int(snappoints.size()) );
if (!Geom::are_near(cn.g->getDistanceFrom(snappoints[snappoint_ix].getPoint()), 0, 1e-2)) {
remove_last(cn.g->attached_items, SPGuideAttachment(&item, cn.snappoint_ix));
g_assert( i < item.constraints.size() );
item.constraints.erase(item.constraints.begin() + i);
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* TODO: insert short description here
*//*
* Authors: see git history
*
* Copyright (C) 2018 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H
#define SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H
class SPItem;
void sp_item_rm_unsatisfied_cns(SPItem &item);
#endif // SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* TODO: insert short description here
*//*
* Authors: see git history
*
* Copyright (C) 2018 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include <vector>
#include "satisfied-guide-cns.h"
#include "sp-item-update-cns.h"
#include "sp-guide.h"
void sp_item_update_cns(SPItem &item, SPDesktop const &desktop)
{
std::vector<Inkscape::SnapCandidatePoint> snappoints;
item.getSnappoints(snappoints, nullptr);
/* TODO: Implement the ordering. */
std::vector<SPGuideConstraint> found_cns;
satisfied_guide_cns(desktop, snappoints, found_cns);
/* effic: It might be nice to avoid an n^2 algorithm, but in practice n will be
small enough that it's still usually more efficient. */
for (auto cn : found_cns)
{
if ( std::find(item.constraints.begin(),
item.constraints.end(),
cn)
== item.constraints.end() )
{
item.constraints.push_back(cn);
cn.g->attached_items.emplace_back(&item, cn.snappoint_ix);
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* TODO: insert short description here
*//*
* Authors: see git history
*
* Copyright (C) 2018 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef SEEN_SP_ITEM_UPDATE_CNS_H
#define SEEN_SP_ITEM_UPDATE_CNS_H
#include <2geom/forward.h>
class SPDesktop;
class SPItem;
void sp_item_update_cns(SPItem &item, SPDesktop const &desktop);
#endif // SEEN_SP_ITEM_UPDATE_CNS_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
......@@ -35,7 +35,6 @@
#include "sp-desc.h"
#include "sp-guide.h"
#include "sp-hatch.h"
#include "sp-item-rm-unsatisfied-cns.h"
#include "sp-mask.h"
#include "sp-pattern.h"
#include "sp-rect.h"
......@@ -47,7 +46,6 @@
#include "sp-use.h"
#include "style.h"
#include "uri.h"
#include "util/find-last-if.h"
......@@ -897,8 +895,6 @@ Geom::OptRect SPItem::documentPreferredBounds() const
}
}
Geom::OptRect SPItem::documentGeometricBounds() const
{
return geometricBounds(i2doc_affine());
......@@ -1087,7 +1083,6 @@ bool SPItem::isFiltered() const {
return (style && style->filter.href && style->filter.href->getObject());
}
SPObject* SPItem::isInMask() const {
SPObject* parent = this->parent;
while (parent && !dynamic_cast<SPMask *>(parent)) {
......@@ -1538,7 +1533,8 @@ void SPItem::doWriteTransform(Geom::Affine const &transform, Geom::Affine const
(!preserve && // user did not chose to preserve all transforms
(!clip_ref || !clip_ref->getObject()) && // the object does not have a clippath
(!mask_ref || !mask_ref->getObject()) && // the object does not have a mask
!(!transform.isTranslation() && style && style->getFilter())) // the object does not have a filter, or the transform is translation (which is supposed to not affect filters)
!(!transform.isTranslation() && style && style->getFilter()))
// the object does not have a filter, or the transform is translation (which is supposed to not affect filters)
)
{
transform_attr = this->set_transform(transform);
......@@ -1593,7 +1589,6 @@ void SPItem::set_item_transform(Geom::Affine const &transform_matrix)
/* The SP_OBJECT_USER_MODIFIED_FLAG_B is used to mark the fact that it's only a
transformation. It's apparently not used anywhere else. */
requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_USER_MODIFIED_FLAG_B);
sp_item_rm_unsatisfied_cns(*this);
}
}
......
......@@ -30,8 +30,6 @@
#include "snap-preferences.h"
#include "snap-candidate.h"
//class SPGuideConstraint;
#include "sp-guide-constraint.h"
#include "xml/repr.h"
class SPClipPath;
......@@ -174,8 +172,6 @@ public:
public:
SPItemView *display;
std::vector<SPGuideConstraint> constraints;
sigc::signal<void, Geom::Affine const *, SPItem *> _transformed_signal;
bool isLocked() const;
......
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* TODO: insert short description here
*//*
* Authors: see git history
*
* Copyright (C) 2013 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef __REMOVE_LAST_H__
#define __REMOVE_LAST_H__
#include <algorithm>
#include <vector>
#include <glib.h>
template<class T>
inline void remove_last(std::vector<T> &seq, T const &elem)
{
typename std::vector<T>::reverse_iterator i(find(seq.rbegin(), seq.rend(), elem));
g_assert( i != seq.rend() );
seq.erase(i.base());
}
#endif /* !__REMOVE_LAST_H__ */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* TODO: insert short description here
*//*
* Authors: see git history
*
* Copyright (C) 2018 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include <2geom/coord.h>
#include "satisfied-guide-cns.h"
#include "desktop.h"
#include "object/sp-guide.h"
#include "object/sp-namedview.h"
void satisfied_guide_cns(SPDesktop const &desktop,
std::vector<Inkscape::SnapCandidatePoint> const &snappoints,
std::vector<SPGuideConstraint> &cns)
{
SPNamedView const &nv = *desktop.getNamedView();
for(auto guide : nv.guides) {
SPGuide &g = *guide;
for (unsigned int i = 0; i < snappoints.size(); ++i) {
if (Geom::are_near(g.getDistanceFrom(snappoints[i].getPoint()), 0, 1e-2)) {
cns.emplace_back(&g, i);
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* TODO: insert short description here
*//*
* Authors: see git history
*
* Copyright (C) 2018 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef SEEN_SATISFIED_GUIDE_CNS_H
#define SEEN_SATISFIED_GUIDE_CNS_H
#include <2geom/forward.h>
#include <vector>
#include "snap-candidate.h"
class SPDesktop;
class SPGuideConstraint;
void satisfied_guide_cns(SPDesktop const &desktop,
std::vector<Inkscape::SnapCandidatePoint> const &snappoints,
std::vector<SPGuideConstraint> &cns);
#endif // SEEN_SATISFIED_GUIDE_CNS_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
......@@ -1662,11 +1662,6 @@ void ObjectSet::applyAffine(Geom::Affine const &affine, bool set_i2d, bool compe
if (set_i2d && item->isCenterSet())
old_center = item->getCenter();
#if 0 /* Re-enable this once persistent guides have a graphical indication.
At the time of writing, this is the only place to re-enable. */
sp_item_update_cns(*item, desktop());
#endif
// we're moving both a clone and its original or any ancestor in clone chain?
bool transform_clone_with_original = object_set_contains_original(item, this);
......
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* TODO: insert short description here
*//*
* Authors: see git history
*
* Copyright (C) 2018 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef SEEN_SP_GUIDE_ATTACHMENT_H
#define SEEN_SP_GUIDE_ATTACHMENT_H
#include "object/sp-item.h"
class SPGuideAttachment {
public:
SPItem *item;
int snappoint_ix;
public:
SPGuideAttachment() :
item(static_cast<SPItem *>(nullptr)),
snappoint_ix(0)
{ }
SPGuideAttachment(SPItem *i, int s) :
item(i),
snappoint_ix(s)
{ }
bool operator==(SPGuideAttachment const &o) const {
return ( ( item == o.item )
&& ( snappoint_ix == o.snappoint_ix ) );