Advertisement
DeaD_EyE

vcShuttle

Oct 25th, 2019
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. from itertools import cycle
  2. from collections import namedtuple
  3. from functools import partial
  4. from unittest.mock import Mock
  5.  
  6.  
  7. Path = namedtuple('Path', 'comp frame action')
  8.  
  9.  
  10. class Action(object):
  11.     wp = 'WP'
  12.     stop = 'STOP'
  13.  
  14.  
  15. class vcShuttle(object):
  16.  
  17.     def __init__(self, compname):
  18.         print('Added', compname)
  19.         self.comp = Mock()
  20.         self.simvehicle = Mock()
  21.         self.simvehicle.clearMovement()
  22.  
  23.     def add(self, path):
  24.         frame = self.comp.findProperty(path.frame)
  25.         self.simvehicle.addCurrentWaypointAtEnd(frame)
  26.  
  27.  
  28. class Shuttle(object):
  29.     sid = 0
  30.  
  31.     @classmethod
  32.     def _enumerate(cls):
  33.         cls.sid += 10
  34.         return cls.sid
  35.  
  36.     def __init__(self, compname, paths, sid=None, initial=0):
  37.         self.current = initial
  38.         self.sid = sid or self._enumerate()
  39.         self.paths = iter(cycle(paths))
  40.         [next(self.paths) for _ in range(initial)]
  41.         self.vcShuttle = vcShuttle(compname)
  42.         self.trigger()
  43.  
  44.     def trigger(self):
  45.         for path in self.paths:
  46.             print(
  47.                 f'ShuttleID: {self.sid} | '
  48.                 f'Comp: {path.comp} | '
  49.                 f'Frame: {path.frame} | '
  50.                 f'Action: {path.action}'
  51.                 )
  52.             self.vcShuttle.add(path)
  53.             if path.action == Action.stop:
  54.                 break
  55.  
  56.  
  57. TPath = partial(Path, 'Transfersystem')
  58. paths = [
  59.     TPath('Frame1', Action.wp),
  60.     TPath('Frame2', Action.wp),
  61.     TPath('Frame3', Action.stop),
  62.     TPath('Frame4', Action.stop),
  63.     TPath('Frame5', Action.stop)
  64. ]
  65. PShuttle = partial(Shuttle, paths=paths)
  66.  
  67. shuttle0 = PShuttle('vcShuttle 10', initial=0)
  68. shuttle1 = PShuttle('vcShuttle 20', initial=1)
  69. shuttle2 = PShuttle('vcShuttle 30', initial=2)
  70. shuttle3 = PShuttle('vcShuttle 40', initial=3)
  71. shuttle4 = PShuttle('vcShuttle 50', initial=4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement