summaryrefslogtreecommitdiff
path: root/lib/extensions/flip.py
blob: 0864da8518a36f5be6551798b600255167ca25b0 (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
import inkex
import cubicsuperpath

from .base import InkstitchExtension
from ..i18n import _
from ..elements import SatinColumn


class Flip(InkstitchExtension):
    def flip(self, satin):
        csp = satin.path

        if len(csp) > 1:
            first, second = satin.rail_indices
            csp[first], csp[second] = csp[second], csp[first]

            satin.node.set("d", cubicsuperpath.formatPath(csp))

    def effect(self):
        if not self.get_elements():
            return

        if not self.selected:
            inkex.errormsg(_("Please select one or more satin columns to flip."))
            return

        for element in self.elements:
            if isinstance(element, SatinColumn):
                self.flip(element)