#!/usr/bin/env python
"""
debug_sel_nodes - return information about selected nodes

Copyright (C) 2016, su_v <suv-sf@users.sf.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""
# pylint: disable=missing-docstring

# local modules
import inkex
import cubicsuperpath


class SelectedNodes(inkex.Effect):
    def __init__(self):
        inkex.Effect.__init__(self)

        self.OptionParser.add_option("--show_coords",
                                     action="store", type="inkbool",
                                     dest="show_coords", default=False,
                                     help="Coordinates of selected nodes")

    def effect(self):
        # report about selection
        inkex.debug(
            'Number of selected objects: {0}'.format(
                len(self.selected)))
        inkex.debug(
            'Number of paths with selected nodes: {0}'.format(
                len(self.selected_nodes)))
        # report about selected nodes
        for path, sel in self.selected_nodes.iteritems():
            ele = self.getElementById(path)
            csp = cubicsuperpath.parsePath(ele.get('d'))
            for sub in sel:
                inkex.debug(
                    '{0} - selected nodes of subpath {1}: {2}'.format(
                        path, sub, sel[sub]))
                if self.options.show_coords:
                    for node in sel[sub]:
                        coords = csp[sub][node][1]
                        inkex.debug(
                            '{0} - selected node {1}: {2}'.format(
                                path, node, coords))


if __name__ == '__main__':
    ME = SelectedNodes()
    ME.affect()

# vim: et shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=79
