def AddLinkShape(self, lnk, shapeTmpl=None): """Add link-shape information to the layer. ShapeTmpl can be given to describe shape's paramenters :param lnk: :class:`Deca.Link` to add shape :param shapeTmpl: :class:`Deca.Shape` describes the drawing parameters :returns: :class:`Deca.Shape` of the created shape """ line = None fromShape = self.storage.graph_data.get(lnk.StartObject, None) toShape = self.storage.graph_data.get(lnk.FinishObject, None) if fromShape and toShape: if shapeTmpl: line = shapeTmpl.copy(shapeTmpl.ID) else: line = DecaShape(lnk.ID) line.Tag = 'link' line.start = lnk.StartObject line.finish = lnk.FinishObject line.direct = lnk.Directional line.label = getattr(lnk, 'Title', '') if not shapeTmpl: line.pen = () line.brush = () if not hasattr(line, 'ControlPoints'): line.ControlPoints = self.GetViewOption('defaultLineCP', 2) line.CPArray = [] if not hasattr(line, 'spline'): line.spline = self.GetViewOption('defaultLineSpline', False) self.storage.graph_data[lnk.ID] = line self.Modified = True # link added return line
def GetViewOption(self, name, defvalue): if '@opts' not in self.storage.graph_data.keys(): shi = DecaShape('@opts') shi.Tag = '@opts' self.storage.graph_data['@opts'] = shi return defvalue if hasattr(self.storage.graph_data['@opts'], name): return getattr(self.storage.graph_data['@opts'], name, defvalue) return defvalue
def GetShape(self, shp_id): """Returns shape for the given identifier. If such shape not in the shapes list, the dummy shape returned """ if not shp_id in self.storage.graph_data.keys(): shape = DecaShape(shp_id) shape.Tag = 'unknown' return shape return self.storage.graph_data[shp_id]
def AddObjectShape(self, obj, xpos=None, ypos=None, shapeTmpl=None): """Add shape information to the layer. If coordinates are None, random position will be selected. ShapeTmpl can be given to describe shape's paramenters :param obj: :class:`Deca.Object` to add shape :param xpos: X coordinate of the shape's center :param ypos: Y coordinate of the shape's center :param shapeTmpl: :class:`Deca.Shape` describes the drawing parameters :returns: :class:`Deca.Shape` of the created shape """ shape = None if isinstance(obj, Deca.Object): if not xpos: if shapeTmpl: xpos = shapeTmpl.xpos else: xpos = randint(0, 500) if not ypos: if shapeTmpl: ypos = shapeTmpl.ypos else: ypos = randint(0, 500) if obj.ID in self.storage.graph_data.keys(): # remove current shape xpos = self.storage.graph_data[obj.ID].xpos ypos = self.storage.graph_data[obj.ID].ypos #self.diagram.RemoveShape(self.shapes[obj.ID]) # create shape info if shapeTmpl: shape = shapeTmpl.copy(shapeTmpl.ID) else: shape = DecaShape(obj.ID) shape.Tag = 'object' shape.xpos = xpos shape.ypos = ypos shape.label = obj.GetTitle() if not shapeTmpl: shape.width = self.GetViewOption('defaultShapeWidth', 100) shape.height = self.GetViewOption('defaultShapeHeight', 50) shape.pen = () shape.brush = () self.storage.graph_data[obj.ID] = shape self.Modified = True return shape
def SetViewOption(self, name, value): if '@opts' not in self.storage.graph_data.keys(): shi = DecaShape('@opts') shi.Tag = '@opts' self.storage.graph_data['@opts'] = shi self.storage.graph_data['@opts'].__setattr__(name, value)