def getEntity(self): activeObject = self.getActiveObject() giverObject = activeObject.getGiverObject() # get the first entity from the predecessor # TODO: each MachineManagedJob.getEntity is invoked, # the self.procTime is updated. Have to decide where to assign # the processing time of the assembler activeEntity = MachineManagedJob.getEntity(self) # this is kept so that in the next loop it will not try to re-get this Entity firstObtained = activeEntity # check weather the activeEntity is of type Mould if activeEntity.type == 'Mould': # and return the mould received return activeEntity # otherwise, collect all the entities to be assembled # read the number of basic and secondary components of the moulds capacity = len(activeEntity.order.basicComponentsList\ +activeEntity.order.secondaryComponentsList) # clear the active object queue del activeObject.getActiveObjectQueue()[:] # and set the capacity of the internal queue of the assembler activeObject.updateCapacity(capacity) # append the activeEntity to the activeObjectQueue activeObjectQueue = activeObject.getActiveObjectQueue() activeObjectQueue.append(activeEntity) # loop through the basic/secondary components of the order that is currently obtained # all the components are received at the same time for entity in activeEntity.order.basicComponentsList\ +activeEntity.order.secondaryComponentsList: # continue for the one that is already obtained before if entity is firstObtained: continue self.entityToGet = entity # get the next component activeEntity = MachineManagedJob.getEntity(self) # check whether the activeEntity is of type Mould try: if activeEntity.type == 'Mould': # and return the mould received raise AssembleMouldError( 'Having already received an orderComponent the assembler\ is not supposed to receive an object of type Mould' ) # check if the last component received has the same parent order as the previous one elif not (activeEntity.order is activeObjectQueue[1].order): raise AssembleMouldError( 'The orderComponents received by the assembler must have the\ same parent order') except AssembleMouldError as mouldError: print 'Mould Assembly Error: {0}'.format(mouldError) return False # perform the assembly-action and return the assembled mould activeEntity = activeObject.assemble() return activeEntity
def getEntity(self): activeObject = self.getActiveObject() giverObject = activeObject.getGiverObject() # get the first entity from the predecessor # TODO: each MachineManagedJob.getEntity is invoked, # the self.procTime is updated. Have to decide where to assign # the processing time of the assembler activeEntity=MachineManagedJob.getEntity(self) # this is kept so that in the next loop it will not try to re-get this Entity firstObtained=activeEntity # check weather the activeEntity is of type Mould if activeEntity.type=='Mould': # and return the mould received return activeEntity # otherwise, collect all the entities to be assembled # read the number of basic and secondary components of the moulds capacity = len(activeEntity.order.basicComponentsList\ +activeEntity.order.secondaryComponentsList) # clear the active object queue del activeObject.getActiveObjectQueue()[:] # and set the capacity of the internal queue of the assembler activeObject.updateCapacity(capacity) # append the activeEntity to the activeObjectQueue activeObjectQueue = activeObject.getActiveObjectQueue() activeObjectQueue.append(activeEntity) # loop through the basic/secondary components of the order that is currently obtained # all the components are received at the same time for entity in activeEntity.order.basicComponentsList\ +activeEntity.order.secondaryComponentsList: # continue for the one that is already obtained before if entity is firstObtained: continue self.entityToGet=entity # get the next component activeEntity=MachineManagedJob.getEntity(self) # check whether the activeEntity is of type Mould try: if activeEntity.type=='Mould': # and return the mould received raise AssembleMouldError('Having already received an orderComponent the assembler\ is not supposed to receive an object of type Mould') # check if the last component received has the same parent order as the previous one elif not (activeEntity.order is activeObjectQueue[1].order): raise AssembleMouldError('The orderComponents received by the assembler must have the\ same parent order') except AssembleMouldError as mouldError: print 'Mould Assembly Error: {0}'.format(mouldError) return False # perform the assembly-action and return the assembled mould activeEntity = activeObject.assemble() return activeEntity
def initialize(self): self.mouldParent = None # the mould's to be assembled parent order self.mouldToBeCreated = None # the mould to be assembled MachineManagedJob.initialize(self) # run default behaviour