Example #1
0
	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
Example #2
0
	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]
Example #3
0
 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
Example #4
0
    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]
Example #5
0
	def SetViewSize(self, maxX, maxY):
		self.maxWidth  = maxX
		self.maxHeight = maxY
		if '@view' in self.storage.graph_data.keys():
			self.storage.graph_data['@view'].width = maxX
			self.storage.graph_data['@view'].height = maxY
		else:
			shi = DecaShape('@view')
			shi.Tag = '@view'
			shi.width = maxX
			shi.height = maxY
			self.storage.graph_data['@view'] = shi
		scale = getattr(self.storage.graph_data['@view'], 'scale', 1.0)
		self.SetScale(scale, scale)
Example #6
0
    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
Example #7
0
	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
Example #8
0
	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
Example #9
0
	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)
Example #10
0
	def __init__(self, parent, layerName, frame): #, log, frame
		ogl.ShapeCanvas.__init__(self, parent)
		Deca.Layer.__init__(self, Deca.world, layerName)

		self.log = wx.GetApp().GetLog()
		self.frame = frame
		self.Selection = []
		self._scripts = {}
		self.last_x = self.last_y = 0

		wid = 200
		hei = 200
		if '@view' in self.storage.graph_data.keys():
			wid = self.storage.graph_data['@view'].width
			hei = self.storage.graph_data['@view'].height
		else:
			shi = DecaShape('@view')
			shi.Tag = '@view'
			shi.width = wid
			shi.height = hei
			shi.scale = 1.0
			self.storage.graph_data['@view'] = shi
		sc = getattr(self.storage.graph_data['@view'], 'scale', 1.0)
		self.SetViewSize(wid, hei)
		self.SetScale(sc, sc)

		self.SetBackgroundColour(wx.WHITE) #"LIGHT BLUE") #
		self.diagram = ogl.Diagram()
		self.SetDiagram(self.diagram)
		self.diagram.SetCanvas(self)
		self.shapes = {}
		self.pen = wx.Pen(wx.BLACK)
		self.brush = wx.Brush(wx.BLACK)
		obj_len = len(self.storage.graph_data)
		if obj_len > 1000:
			wxres = wx.MessageBox(_("View contains of %i objects? It may take awhile to draw them all.\nAre you sure to draw objects?") % obj_len,
			                      _("Sampo Framework"), wx.YES_NO|wx.ICON_QUESTION)
		else:
			wxres = wx.ID_YES
		if wxres == wx.ID_YES:
			# add objects
			self.Freeze()
			self.diagram.SetQuickEditMode(True)
			obj_curr = 2
			frame.SetStatus(_("Draw elements"))
			frame.SetStatusProgressRange(obj_len)
			self.RebuildDrawing()
			# for oid, shp in self.storage.graph_data.items():
			# 	if getattr(shp, 'Tag') == 'object':
			# 		s = self.AddObjectShape(self.storage.objects[oid], shp.xpos, shp.ypos, shp)
			# 		s.SetPen(CreatePen(getattr(shp, 'pen', ()), self.pen))
			# 		s.SetBrush(CreateBrush(getattr(shp, 'brush', ()), self.brush))
			# 		s.SetWidth(shp.width)
			# 		s.SetHeight(shp.height)
			# 		obj_curr += 1
			# 		frame.SetStatusProgress(obj_curr)
			# 		wx.Yield()
			# #add links
			# for oid, shp in self.storage.graph_data.items():
			# 	if getattr(shp, 'Tag') == 'link':
			# 		lnk = self.GetLinks(lambda ln: ln.StartObject == shp.start and ln.FinishObject == shp.finish)
			# 		if len(lnk) > 0:
			# 			#lnk = lnk[0]
			# 			lnk = self.AddLinkShape(lnk[0], shp)
			# 			lnk.SetPen(CreatePen(getattr(shp, 'pen', ()), self.pen))
			# 			lnk.SetBrush(CreateBrush(getattr(shp, 'brush', ()), self.brush))
			# 			obj_curr += 1
			# 			frame.SetStatusProgress(obj_curr)
			# 			wx.Yield()
			self.diagram.SetQuickEditMode(False)
			frame.SetStatus(_("Ready"))
			self.Thaw()
		# objects redraw done
		self.Bind(wx.EVT_MENU, self.OnScript)
		#self.Bind(wx.EVT_MOUSEWHEEL, self.OnWheel)
		wx.CallAfter(self.Update)
Example #11
0
    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
Example #12
0
 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)