summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpegroupbbox.cpp
blob: 588d3ec0fa6a767f9827216177deb390d1bd15b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#define INKSCAPE_LPEGROUPBBOX_CPP

/*
 * Copyright (C) Steren Giannini 2008 <steren.giannini@gmail.com>
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include "live_effects/lpegroupbbox.h"
#include "sp-shape.h"
#include "sp-item.h"
#include "sp-path.h"
#include "sp-item-group.h"
#include "display/curve.h"
#include <libnr/n-art-bpath.h>
#include <libnr/nr-matrix-fns.h>
#include "libnr/n-art-bpath-2geom.h"
#include "svg/svg.h"
#include "ui/widget/scalar.h"

#include <2geom/sbasis.h>
#include <2geom/sbasis-geometric.h>
#include <2geom/bezier-to-sbasis.h>
#include <2geom/sbasis-to-bezier.h>
#include <2geom/d2.h>
#include <2geom/piecewise.h>

#include <algorithm>

using std::vector;

namespace Inkscape {
namespace LivePathEffect {

void
GroupBBoxEffect::recursive_original_bbox(SPGroup *group, Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2, std::vector<Geom::Path> & temppath)
{
    std::vector<Geom::Path> tempsubpath;
    GSList const *item_list = sp_item_group_item_list(group);

    for ( GSList const *iter = item_list; iter; iter = iter->next )
    {
        SPObject *subitem = static_cast<SPObject *>(iter->data);
        if (SP_IS_PATH(subitem))
        {
            //if there is not an original-d, just take the d
            if(SP_OBJECT_REPR(subitem)->attribute("inkscape:original-d") != NULL)      
                tempsubpath = SVGD_to_2GeomPath(SP_OBJECT_REPR(subitem)->attribute("inkscape:original-d"));
            else
                tempsubpath = SVGD_to_2GeomPath(SP_OBJECT_REPR(subitem)->attribute("d")); 
            
            temppath.insert(temppath.end(), tempsubpath.begin(), tempsubpath.end());
        } 
        else if (SP_IS_GROUP(subitem))
        {
            recursive_original_bbox(SP_GROUP(subitem), pwd2, temppath);
        }
    }
}

void
GroupBBoxEffect::original_bbox(SPLPEItem *lpeitem)
{

    using namespace Geom;
    Piecewise<D2<SBasis> > pwd2;
    std::vector<Geom::Path> temppath;  


    if (SP_IS_PATH(lpeitem))
    {
    //TODO : this won't work well with LPE stacking
        temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(lpeitem)->attribute("inkscape:original-d"));
    }
    else if (SP_IS_GROUP(lpeitem))
    {
        recursive_original_bbox(SP_GROUP(lpeitem), pwd2, temppath);
    }

    for (unsigned int i=0; i < temppath.size(); i++) {
        pwd2.concat( temppath[i].toPwSb() );
    }

    D2<Piecewise<SBasis> > d2pw = make_cuts_independant(pwd2);
    boundingbox_X = bounds_exact(d2pw[0]);
    boundingbox_Y = bounds_exact(d2pw[1]);
}

} // namespace LivePathEffect
} /* namespace Inkscape */

/*
  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 :