Code

- try to use more forward declarations for less dependencies on display/curve.h
[inkscape.git] / src / live_effects / lpegroupbbox.cpp
1 #define INKSCAPE_LPEGROUPBBOX_CPP
3 /*
4  * Copyright (C) Steren Giannini 2008 <steren.giannini@gmail.com>
5  *
6  * Released under GNU GPL, read the file 'COPYING' for more information
7  */
9 #include "live_effects/lpegroupbbox.h"
10 #include "sp-shape.h"
11 #include "sp-item.h"
12 #include "sp-path.h"
13 #include "sp-item-group.h"
14 #include "libnr/n-art-bpath-2geom.h"
15 #include "svg/svg.h"
16 #include "ui/widget/scalar.h"
18 #include <2geom/sbasis.h>
19 #include <2geom/sbasis-geometric.h>
20 #include <2geom/bezier-to-sbasis.h>
21 #include <2geom/sbasis-to-bezier.h>
22 #include <2geom/d2.h>
23 #include <2geom/piecewise.h>
25 #include <algorithm>
27 using std::vector;
29 namespace Inkscape {
30 namespace LivePathEffect {
32 void
33 GroupBBoxEffect::recursive_original_bbox(SPGroup *group, Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2, std::vector<Geom::Path> & temppath)
34 {
35     std::vector<Geom::Path> tempsubpath;
36     GSList const *item_list = sp_item_group_item_list(group);
38     for ( GSList const *iter = item_list; iter; iter = iter->next )
39     {
40         SPObject *subitem = static_cast<SPObject *>(iter->data);
41         if (SP_IS_PATH(subitem))
42         {
43             //if there is not an original-d, just take the d
44             if(SP_OBJECT_REPR(subitem)->attribute("inkscape:original-d") != NULL)      
45                 tempsubpath = SVGD_to_2GeomPath(SP_OBJECT_REPR(subitem)->attribute("inkscape:original-d"));
46             else
47                 tempsubpath = SVGD_to_2GeomPath(SP_OBJECT_REPR(subitem)->attribute("d")); 
48             
49             temppath.insert(temppath.end(), tempsubpath.begin(), tempsubpath.end());
50         } 
51         else if (SP_IS_GROUP(subitem))
52         {
53             recursive_original_bbox(SP_GROUP(subitem), pwd2, temppath);
54         }
55     }
56 }
58 void
59 GroupBBoxEffect::original_bbox(SPLPEItem *lpeitem)
60 {
62     using namespace Geom;
63     Piecewise<D2<SBasis> > pwd2;
64     std::vector<Geom::Path> temppath;  
67     if (SP_IS_PATH(lpeitem))
68     {
69     //TODO : this won't work well with LPE stacking
70         temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(lpeitem)->attribute("inkscape:original-d"));
71     }
72     else if (SP_IS_GROUP(lpeitem))
73     {
74         recursive_original_bbox(SP_GROUP(lpeitem), pwd2, temppath);
75     }
77     for (unsigned int i=0; i < temppath.size(); i++) {
78         pwd2.concat( temppath[i].toPwSb() );
79     }
81     D2<Piecewise<SBasis> > d2pw = make_cuts_independant(pwd2);
82     boundingbox_X = bounds_exact(d2pw[0]);
83     boundingbox_Y = bounds_exact(d2pw[1]);
84 }
86 } // namespace LivePathEffect
87 } /* namespace Inkscape */
89 /*
90   Local Variables:
91   mode:c++
92   c-file-style:"stroustrup"
93   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
94   indent-tabs-mode:nil
95   fill-column:99
96   End:
97 */
98 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :