graph_item_factory.py
Go to the documentation of this file.
00001 """
00002 Copyright (c) 2013, Cogniteam
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 *   Redistributions of source code must retain the above copyright
00009     notice, this list of conditions and the following disclaimer.
00010 
00011 *   Redistributions in binary form must reproduce the above copyright
00012     notice, this list of conditions and the following disclaimer in the
00013     documentation and/or other materials provided with the distribution.
00014 
00015 *   Neither the name of the Cogniteam nor the
00016     names of its contributors may be used to endorse or promote products
00017     derived from this software without specific prior written permission.
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00023 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 """
00030 
00031 from .edge_item import EdgeItem
00032 from .node_item import NodeItem
00033 from .graph_item import GraphItem
00034 
00035 
00036 class GraphItemFactory(object):
00037 
00038     def __init__(self):
00039         super(GraphItemFactory, self).__init__()
00040         self._color = GraphItem.COLOR
00041         self._pen_width = GraphItem.PEN_WIDTH
00042         self._edge_pen_width = EdgeItem.EDGE_PEN_WIDTH
00043         self._label_pen_width = GraphItem.LABEL_PEN_WIDTH
00044         self._same_label_siblings = False
00045 
00046     def set_color(self, color):
00047         self._color = color
00048 
00049     def color(self):
00050         return self._color()
00051 
00052     def set_pen_width(self, pen_width):
00053         self._pen_width = pen_width
00054 
00055     def pen_width(self):
00056         return self._pen_width
00057 
00058     def set_edge_pen_width(self, edge_pen_width):
00059         self._edge_pen_width = edge_pen_width
00060 
00061     def edge_pen_width(self):
00062         return self._edge_pen_width
00063 
00064     def set_label_pen_width(self, label_pen_width):
00065         self._label_pen_width = label_pen_width
00066 
00067     def label_pen_width(self):
00068         return self._label_pen_width
00069 
00070     def set_same_label_siblings(self, same_label_siblings):
00071         self._same_label_siblings = same_label_siblings
00072 
00073     def same_label_siblings(self):
00074         return self._same_label_siblings
00075 
00076     def create_edge(self, spline, label, label_center, from_node, to_node, parent=None, **kwargs):
00077         self._check_constraints(kwargs, False)
00078         return EdgeItem(spline, label, label_center, from_node, to_node, parent, **kwargs)
00079 
00080     def create_node(self, bounding_box, shape, label, label_pos=None, url=None, parent=None, cluster=False, **kwargs):
00081         self._check_constraints(kwargs)
00082         return NodeItem(bounding_box, shape, label, label_pos, url, parent, **kwargs)
00083 
00084     def _check_constraints(self, dictionary, node=True):
00085         if 'penwidth' not in dictionary:
00086             dictionary['penwidth'] = self._pen_width
00087 
00088         if not node:
00089             if 'edge_pen_width' not in dictionary:
00090                 dictionary['edge_pen_width'] = self._edge_pen_width
00091 
00092         if 'label_pen_width' not in dictionary:
00093             dictionary['label_pen_width'] = self._label_pen_width
00094 
00095         if 'color' not in dictionary:
00096             dictionary['color'] = self._color


rqt_decision_graph
Author(s):
autogenerated on Wed Aug 26 2015 11:16:47