summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter/array.cpp
blob: 98b3db2a5b05ba4aa6a5143d40e19bfeea6297b8 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
#include "live_effects/parameter/array.h"

#include <2geom/coord.h>
#include <2geom/point.h>

#include "helper-fns.h"
#include "live_effects/effect.h"
#include "live_effects/lpeobject.h"

namespace Inkscape {

namespace LivePathEffect {

template <>
double
ArrayParam<double>::readsvg(const gchar * str)
{
    double newx = Geom::infinity();
    sp_svg_number_read_d(str, &newx);
    return newx;
}

template <>
float
ArrayParam<float>::readsvg(const gchar * str)
{
    float newx = Geom::infinity();
    sp_svg_number_read_f(str, &newx);
    return newx;
}

template <>
Geom::Point
ArrayParam<Geom::Point>::readsvg(const gchar * str)
{
    gchar ** strarray = g_strsplit(str, ",", 2);
    double newx, newy;
    unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
    success += sp_svg_number_read_d(strarray[1], &newy);
    g_strfreev (strarray);
    if (success == 2) {
        return Geom::Point(newx, newy);
    }
    return Geom::Point(Geom::infinity(),Geom::infinity());
}

template <>
std::shared_ptr<SatelliteReference> ArrayParam<std::shared_ptr<SatelliteReference>>::readsvg(const gchar *str)
{
    std::shared_ptr<SatelliteReference> satellitereference = nullptr;
    if (!str) {
        return satellitereference;
    }

    gchar **strarray = g_strsplit(str, ",", 2);
    if (strarray[0] != nullptr && g_strstrip(strarray[0])[0] == '#') {
        try {
            bool active = strarray[1] != nullptr;
            satellitereference = std::make_shared<SatelliteReference>(param_effect->getLPEObj(), active);
            satellitereference->attach(Inkscape::URI(g_strstrip(strarray[0])));
            if (active) {
                satellitereference->setActive(strncmp(strarray[1], "1", 1) == 0);
            }
        } catch (Inkscape::BadURIException &e) {
            g_warning("%s (%s)", e.what(), strarray[0]);
            satellitereference->detach();
        }
    }
    g_strfreev(strarray);
    return satellitereference;
}

template <>
std::vector<NodeSatellite> ArrayParam<std::vector<NodeSatellite>>::readsvg(const gchar *str)
{
    std::vector<NodeSatellite> subpath_nodesatellites;
    if (!str) {
        return subpath_nodesatellites;
    }
    gchar ** strarray = g_strsplit(str, "@", 0);
    gchar ** iter = strarray;
    while (*iter != nullptr) {
        gchar ** strsubarray = g_strsplit(*iter, ",", 8);
        if (*strsubarray[7]) {//steps always > 0
            NodeSatellite *nodesatellite = new NodeSatellite();
            nodesatellite->setNodeSatellitesType(g_strstrip(strsubarray[0]));
            nodesatellite->is_time = strncmp(strsubarray[1], "1", 1) == 0;
            nodesatellite->selected = strncmp(strsubarray[2], "1", 1) == 0;
            nodesatellite->has_mirror = strncmp(strsubarray[3], "1", 1) == 0;
            nodesatellite->hidden = strncmp(strsubarray[4], "1", 1) == 0;
            double amount,angle;
            float stepsTmp;
            sp_svg_number_read_d(strsubarray[5], &amount);
            sp_svg_number_read_d(strsubarray[6], &angle);
            sp_svg_number_read_f(g_strstrip(strsubarray[7]), &stepsTmp);
            unsigned int steps = (unsigned int)stepsTmp;
            nodesatellite->amount = amount;
            nodesatellite->angle = angle;
            nodesatellite->steps = steps;
            subpath_nodesatellites.push_back(*nodesatellite);
        }
        g_strfreev (strsubarray);
        iter++;
    }
    g_strfreev (strarray);
    return subpath_nodesatellites;
}

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