Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import cycle
- from collections import namedtuple
- from functools import partial
- from unittest.mock import Mock
- Path = namedtuple('Path', 'comp frame action')
- class Action(object):
- wp = 'WP'
- stop = 'STOP'
- class vcShuttle(object):
- def __init__(self, compname):
- print('Added', compname)
- self.comp = Mock()
- self.simvehicle = Mock()
- self.simvehicle.clearMovement()
- def add(self, path):
- frame = self.comp.findProperty(path.frame)
- self.simvehicle.addCurrentWaypointAtEnd(frame)
- class Shuttle(object):
- sid = 0
- @classmethod
- def _enumerate(cls):
- cls.sid += 10
- return cls.sid
- def __init__(self, compname, paths, sid=None, initial=0):
- self.current = initial
- self.sid = sid or self._enumerate()
- self.paths = iter(cycle(paths))
- [next(self.paths) for _ in range(initial)]
- self.vcShuttle = vcShuttle(compname)
- self.trigger()
- def trigger(self):
- for path in self.paths:
- print(
- f'ShuttleID: {self.sid} | '
- f'Comp: {path.comp} | '
- f'Frame: {path.frame} | '
- f'Action: {path.action}'
- )
- self.vcShuttle.add(path)
- if path.action == Action.stop:
- break
- TPath = partial(Path, 'Transfersystem')
- paths = [
- TPath('Frame1', Action.wp),
- TPath('Frame2', Action.wp),
- TPath('Frame3', Action.stop),
- TPath('Frame4', Action.stop),
- TPath('Frame5', Action.stop)
- ]
- PShuttle = partial(Shuttle, paths=paths)
- shuttle0 = PShuttle('vcShuttle 10', initial=0)
- shuttle1 = PShuttle('vcShuttle 20', initial=1)
- shuttle2 = PShuttle('vcShuttle 30', initial=2)
- shuttle3 = PShuttle('vcShuttle 40', initial=3)
- shuttle4 = PShuttle('vcShuttle 50', initial=4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement