예제 #1
0
    def effect(self):
        """ Main function, called when the extension is run.
        """
        # construct dictionary containing styles
        self.create_styles_dict()

        # get paths for selected origami pattern
        self.generate_path_tree()

        # ~ accuracy = self.options.accuracy
        # ~ unit_factor = self.calc_unit_factor()
        # what page are we on
        # page_id = self.options.active_tab # sometimes wrong the very first time

        # Translate according to translate attribute
        g_attribs = {
            inkex.addNS('label', 'inkscape'):
            '{} Origami pattern'.format(self.options.pattern),
            # inkex.addNS('transform-center-x','inkscape'): str(-bbox_center[0]),
            # inkex.addNS('transform-center-y','inkscape'): str(-bbox_center[1]),
            inkex.addNS('transform-center-x', 'inkscape'):
            str(0),
            inkex.addNS('transform-center-y', 'inkscape'):
            str(0),
            'transform':
            'translate(%s,%s)' % self.translate
        }

        # add the group to the document's current layer
        if type(self.path_tree) == list and len(self.path_tree) != 1:
            self.topgroup = etree.SubElement(self.get_layer(), 'g', g_attribs)
        else:
            self.topgroup = self.get_layer()

        if len(self.edge_points) == 0:
            Path.draw_paths_recursively(self.path_tree, self.topgroup,
                                        self.styles_dict)
        elif self.options.edge_single_path:
            edges = Path(self.edge_points, 'e', closed=True)
            Path.draw_paths_recursively(self.path_tree + [edges],
                                        self.topgroup, self.styles_dict)
        else:
            edges = Path.generate_separated_paths(self.edge_points,
                                                  'e',
                                                  closed=True)
            Path.draw_paths_recursively(self.path_tree + edges, self.topgroup,
                                        self.styles_dict)
예제 #2
0
    def effect(self):
        """ Main function, called when the extension is run.
        """
        # bypass most style options if simulation mode is choosen
        self.check_simulation_mode()

        # check if any selected to print only some of the crease types:
        bool_only_list = [
            self.options.mountain_bool_only, self.options.valley_bool_only,
            self.options.edge_bool_only, self.options.universal_bool_only,
            self.options.semicrease_bool_only, self.options.cut_bool_only,
            self.options.vertex_bool_only
        ]
        if sum(bool_only_list) > 0:
            self.options.mountain_bool = self.options.mountain_bool and self.options.mountain_bool_only
            self.options.valley_bool = self.options.valley_bool and self.options.valley_bool_only
            self.options.edge_bool = self.options.edge_bool and self.options.edge_bool_only
            self.options.universal_bool = self.options.universal_bool and self.options.universal_bool_only
            self.options.semicrease_bool = self.options.semicrease_bool and self.options.semicrease_bool_only
            self.options.cut_bool = self.options.cut_bool and self.options.cut_bool_only
            self.options.vertex_bool = self.options.vertex_bool and self.options.vertex_bool_only

        # construct dictionary containing styles
        self.create_styles_dict()

        # get paths for selected origami pattern
        self.generate_path_tree()

        # ~ accuracy = self.options.accuracy
        # ~ unit_factor = self.calc_unit_factor()
        # what page are we on
        # page_id = self.options.active_tab # sometimes wrong the very first time

        # get vertex points and add them to path tree
        vertex_radius = self.options.vertex_radius * self.calc_unit_factor()
        vertices = []
        self.vertex_points = list(set([i for i in self.vertex_points
                                       ]))  # remove duplicates
        for vertex_point in self.vertex_points:
            vertices.append(Path(vertex_point, style='p',
                                 radius=vertex_radius))
        self.path_tree.append(vertices)

        # Translate according to translate attribute
        g_attribs = {
            inkex.addNS('label', 'inkscape'):
            '{} Origami pattern'.format(self.options.pattern),
            # inkex.addNS('transform-center-x','inkscape'): str(-bbox_center[0]),
            # inkex.addNS('transform-center-y','inkscape'): str(-bbox_center[1]),
            inkex.addNS('transform-center-x', 'inkscape'):
            str(0),
            inkex.addNS('transform-center-y', 'inkscape'):
            str(0),
            'transform':
            'translate(%s,%s)' % self.translate
        }

        # add the group to the document's current layer
        if type(self.path_tree) == list and len(self.path_tree) != 1:
            self.topgroup = inkex.etree.SubElement(self.get_layer(), 'g',
                                                   g_attribs)
        else:
            self.topgroup = self.get_layer()

        if len(self.edge_points) == 0:
            Path.draw_paths_recursively(self.path_tree, self.topgroup,
                                        self.styles_dict)
        elif self.options.edge_single_path:
            edges = Path(self.edge_points, 'e', closed=True)
            Path.draw_paths_recursively(self.path_tree + [edges],
                                        self.topgroup, self.styles_dict)
        else:
            edges = Path.generate_separated_paths(self.edge_points,
                                                  'e',
                                                  closed=True)
            Path.draw_paths_recursively(self.path_tree + edges, self.topgroup,
                                        self.styles_dict)