Exemple #1
0
	def Create(self):
		""" Create CMD from constructor
		"""
		from Container import ContainerBlock, iPort, oPort
		# new containerBlock model
		self.__m = ContainerBlock(self._label, self._inputs, self._outputs)

		print range(self._inputs)

		# input and output ports
		for id in xrange(self._inputs):
			iport = iPort(label='IPort %d'%(id))
			iport.id = id
			self.__m.AddShape(iport)
			self.__m.nbiPort = id

		for id in xrange(self._outputs):
			oport = oPort(label='OPort %d'%(id))
			oport.id = id
			self.__m.AddShape(oport)
			self.__m.nboPort = id

		self.__m.python_path = self._python_file
		self.__m.model_path = self._model_file

		return self.__m
Exemple #2
0
	def CreateBlock(*argv, **kwargs):
		""" Create Block from python_file and other info coming from wizard.
		"""

		from Container import iPort, oPort, MsgBoxError
		### import are here because the simulator (PyDEVS or PyPDEVS) require it
		from DomainInterface.DomainBehavior import DomainBehavior
		from DomainInterface.DomainStructure import DomainStructure

		python_file = kwargs['python_file']
		canvas = kwargs['canvas'] if 'canvas' in kwargs else None
		x = kwargs['x'] if 'x' in kwargs else None
		y = kwargs['y'] if 'y' in kwargs else None

		# associated python class
		cls = GetClass(python_file)

		if inspect.isclass(cls):
			# adding devs model on good graphical model
			if issubclass(cls, DomainBehavior):
				amd = AMDComponent(*argv, **kwargs)
				m = amd.Create()
				### move AMD model
				if canvas and x and y:
					### convert coordinate depending on the canvas
					x,y = canvas.GetXY(m, x, y)
					# move model from mouse position
					m.move(x, y)
				return m
			elif issubclass(cls, DomainStructure):
				cmd = CMDComponent(*argv, **kwargs)
				m = cmd.Create()
				### move CMD model
				if canvas and x and y:
					### convert coordinate depending on the canvas
					x,y = canvas.GetXY(m, x, y)
					# move model from mouse position
					m.move(x, y)
				return m
			elif  'IPort' in cls.__name__:
				label = kwargs['label']
				iid = kwargs['id'] if 'id' in kwargs else canvas.GetDiagram().GetiPortCount()
				m = iPort(label = "%s %d"%(label,iid))
				m.id = iid
				m.move(x-70, y-70)
				return m
			elif  'OPort' in cls.__name__:
				label = kwargs['label']
				oid = kwargs['id'] if 'id' in kwargs else canvas.GetDiagram().GetoPortCount()
				m = oPort(label = "%s %d"%(label,oid))
				m.id = oid
				m.move(x-70, y-70)
				return m
			else:
				dial = wx.MessageDialog(None, _('Object not instantiated !\n\n Perhaps there is bad imports.'), _('Block Manager'), wx.OK | wx.ICON_EXCLAMATION)
				dial.ShowModal()
				return False

		### inform user of the existance of error and return None
		else:
			MsgBoxError(None, GetActiveWindow(), cls)

		return None