def test_load_gcode_should_read_gcode(self,mock_AsynchronousGcodeReader): viewer = Viewer() test_file = 'test_file.gcode' mock_asynchronous_gcode_reader = mock_AsynchronousGcodeReader.return_value viewer.load_gcode(test_file) self.assertEquals(test_file, mock_AsynchronousGcodeReader.call_args_list[0][0][0]) mock_asynchronous_gcode_reader.start.assert_called_with()
def test_load_gcode_should_read_gcode(self, mock_AsynchronousGcodeReader): viewer = Viewer() test_file = 'test_file.gcode' mock_asynchronous_gcode_reader = mock_AsynchronousGcodeReader.return_value viewer.load_gcode(test_file) self.assertEquals(test_file, mock_AsynchronousGcodeReader.call_args_list[0][0][0]) mock_asynchronous_gcode_reader.start.assert_called_with()
def test_get_layers_returns_all_layers(self, mock_AsynchronousGcodeReader): viewer = Viewer() test_file = 'test_file.gcode' mock_asynchronous_gcode_reader = mock_AsynchronousGcodeReader.return_value viewer.load_gcode(test_file) viewer_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][1] for i in range(0,100): viewer_call_back('Layer: %s' % i) complete_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][2] complete_call_back() layers = viewer.get_layers() self.assertEquals(100,len(layers)) self.assertEquals(layers[0], 'Layer: 0')
def test_get_layers_returns_all_layers(self, mock_AsynchronousGcodeReader): viewer = Viewer() test_file = 'test_file.gcode' mock_asynchronous_gcode_reader = mock_AsynchronousGcodeReader.return_value viewer.load_gcode(test_file) viewer_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][1] for i in range(0, 100): viewer_call_back('Layer: %s' % i) complete_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][ 2] complete_call_back() layers = viewer.get_layers() self.assertEquals(100, len(layers)) self.assertEquals(layers[0], 'Layer: 0')
def __init__(self, parent): self.parent = parent wx.Panel.__init__(self, self.parent, -1, style=wx.RAISED_BORDER) logging.debug("Starting api") self.api = Viewer() self.status = "" self.UpdateEvent, EVT_UPDATE = wx.lib.newevent.NewEvent() self.Bind(EVT_UPDATE, self.updateDisplay) sizer_display_control = wx.BoxSizer(wx.VERTICAL) control_sizer = wx.FlexGridSizer(3, 2, 5, 5) layer_slider_text = wx.StaticText(self, label="Centre Layer") layers_to_display_slider_text = wx.StaticText(self, label="Number of Layers") layer_parse_text = wx.StaticText(self, label="Layers to Hide") self.layer_slider = wx.Slider(self, value=1, minValue=1, maxValue=2) self.layers_slider = wx.Slider(self, value=1, minValue=1, maxValue=2) self.skip_slider = wx.Slider(self, value=50, minValue=1, maxValue=200) control_sizer.Add(layer_slider_text) control_sizer.Add(self.layer_slider, 1, wx.EXPAND) control_sizer.Add(layers_to_display_slider_text) control_sizer.Add(self.layers_slider, 1, wx.EXPAND) control_sizer.Add(layer_parse_text) control_sizer.Add(self.skip_slider, 1, wx.EXPAND) control_sizer.AddGrowableCol(1, 1) sizer_display_control.Add(control_sizer, 0, wx.EXPAND, 5) logging.debug("Starting processor") self.processor = GLProcesser() logging.debug("Starting canvas") self.canvas = GCodeCanvas(self, self.processor) sizer_display_control.Add(self.canvas, 1, wx.ALL | wx.EXPAND, 5) self.SetAutoLayout(True) self.SetSizer(sizer_display_control) self.SetFocus() self.Bind(wx.EVT_SLIDER, self.change_layer)
def test_loading_a_new_file_removes_old_ones_layers( self, mock_AsynchronousGcodeReader): viewer = Viewer() test_file1 = 'test_file1.gcode' test_file2 = 'test_file2.gcode' mock_asynchronous_gcode_reader = mock_AsynchronousGcodeReader.return_value viewer.load_gcode(test_file1) viewer_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][1] for i in range(0, 100): viewer_call_back('Old Layer: %s' % i) complete_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][ 2] complete_call_back() viewer.load_gcode(test_file2) viewer_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][1] for i in range(0, 100): viewer_call_back('New Layer: %s' % i) complete_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][ 2] complete_call_back() layers = viewer.get_layers() self.assertEquals(100, len(layers)) self.assertEquals(layers[0], 'New Layer: 0')
def test_load_gcode_should_call_layer_count_call_back(self,mock_AsynchronousGcodeReader): viewer = Viewer() test_file = 'test_file.gcode' mock_asynchronous_gcode_reader = mock_AsynchronousGcodeReader.return_value calls = [] def test_call_back(layer_count): calls.append(layer_count) viewer.load_gcode(test_file, test_call_back) viewer_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][1] viewer_call_back(1) viewer_call_back(2) viewer_call_back(3) self.assertEquals(3, len(calls)) self.assertEquals([1,2,3], calls)
def test_load_gcode_should_call_layer_count_call_back( self, mock_AsynchronousGcodeReader): viewer = Viewer() test_file = 'test_file.gcode' mock_asynchronous_gcode_reader = mock_AsynchronousGcodeReader.return_value calls = [] def test_call_back(layer_count): calls.append(layer_count) viewer.load_gcode(test_file, test_call_back) viewer_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][1] viewer_call_back(1) viewer_call_back(2) viewer_call_back(3) self.assertEquals(3, len(calls)) self.assertEquals([1, 2, 3], calls)
def __init__(self, parent): self.parent = parent wx.Panel.__init__(self, self.parent, -1, style=wx.RAISED_BORDER) logging.debug("Starting api") self.api = Viewer() self.status = "" self.UpdateEvent, EVT_UPDATE = wx.lib.newevent.NewEvent() self.Bind(EVT_UPDATE, self.updateDisplay) sizer_display_control = wx.BoxSizer(wx.VERTICAL) control_sizer = wx.FlexGridSizer(3,2,5,5) layer_slider_text = wx.StaticText(self, label="Centre Layer") layers_to_display_slider_text = wx.StaticText(self, label="Number of Layers") layer_parse_text = wx.StaticText(self, label="Layers to Hide") self.layer_slider = wx.Slider(self, value = 1, minValue = 1, maxValue = 2) self.layers_slider = wx.Slider(self, value = 1, minValue = 1, maxValue = 2) self.skip_slider = wx.Slider(self, value = 50, minValue = 1, maxValue = 200) control_sizer.Add(layer_slider_text) control_sizer.Add(self.layer_slider,1,wx.EXPAND) control_sizer.Add(layers_to_display_slider_text) control_sizer.Add(self.layers_slider,1,wx.EXPAND) control_sizer.Add(layer_parse_text) control_sizer.Add(self.skip_slider,1,wx.EXPAND) control_sizer.AddGrowableCol(1, 1) sizer_display_control.Add(control_sizer,0,wx.EXPAND,5) logging.debug("Starting processor") self.processor = GLProcesser() logging.debug("Starting canvas") self.canvas = GCodeCanvas(self,self.processor) sizer_display_control.Add(self.canvas,1,wx.ALL|wx.EXPAND, 5) self.SetAutoLayout(True) self.SetSizer(sizer_display_control) self.SetFocus() self.Bind(wx.EVT_SLIDER, self.change_layer)
def test_loading_a_new_file_removes_old_ones_layers(self, mock_AsynchronousGcodeReader): viewer = Viewer() test_file1 = 'test_file1.gcode' test_file2 = 'test_file2.gcode' mock_asynchronous_gcode_reader = mock_AsynchronousGcodeReader.return_value viewer.load_gcode(test_file1) viewer_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][1] for i in range(0,100): viewer_call_back('Old Layer: %s' % i) complete_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][2] complete_call_back() viewer.load_gcode(test_file2) viewer_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][1] for i in range(0,100): viewer_call_back('New Layer: %s' % i) complete_call_back = mock_AsynchronousGcodeReader.call_args_list[0][0][2] complete_call_back() layers = viewer.get_layers() self.assertEquals(100,len(layers)) self.assertEquals(layers[0], 'New Layer: 0')
class DisplayPanel(wx.Panel): def __init__(self, parent): self.parent = parent wx.Panel.__init__(self, self.parent, -1, style=wx.RAISED_BORDER) logging.debug("Starting api") self.api = Viewer() self.status = "" self.UpdateEvent, EVT_UPDATE = wx.lib.newevent.NewEvent() self.Bind(EVT_UPDATE, self.updateDisplay) sizer_display_control = wx.BoxSizer(wx.VERTICAL) control_sizer = wx.FlexGridSizer(3, 2, 5, 5) layer_slider_text = wx.StaticText(self, label="Centre Layer") layers_to_display_slider_text = wx.StaticText(self, label="Number of Layers") layer_parse_text = wx.StaticText(self, label="Layers to Hide") self.layer_slider = wx.Slider(self, value=1, minValue=1, maxValue=2) self.layers_slider = wx.Slider(self, value=1, minValue=1, maxValue=2) self.skip_slider = wx.Slider(self, value=50, minValue=1, maxValue=200) control_sizer.Add(layer_slider_text) control_sizer.Add(self.layer_slider, 1, wx.EXPAND) control_sizer.Add(layers_to_display_slider_text) control_sizer.Add(self.layers_slider, 1, wx.EXPAND) control_sizer.Add(layer_parse_text) control_sizer.Add(self.skip_slider, 1, wx.EXPAND) control_sizer.AddGrowableCol(1, 1) sizer_display_control.Add(control_sizer, 0, wx.EXPAND, 5) logging.debug("Starting processor") self.processor = GLProcesser() logging.debug("Starting canvas") self.canvas = GCodeCanvas(self, self.processor) sizer_display_control.Add(self.canvas, 1, wx.ALL | wx.EXPAND, 5) self.SetAutoLayout(True) self.SetSizer(sizer_display_control) self.SetFocus() self.Bind(wx.EVT_SLIDER, self.change_layer) def change_layer(self, event): bottom = self.layer_slider.GetValue( ) - self.layers_slider.GetValue() / 2 top = self.layer_slider.GetValue() + self.layers_slider.GetValue() / 2 skip = self.skip_slider.GetValue() logging.debug("Data Type: %s" % type(bottom)) self.processor.update(self.api.get_layers(bottom, top, skip)) def load_file(self, afile): self.status = "Loading" logging.info("Loading file") self.api.load_gcode(afile, self._gcode_load_call_back, self._gcode_complete_call_back) def _gcode_load_call_back(self, layers): if layers % 10 == 0: logging.info('Posting GCODE Processing Update') wx.PostEvent(self, self.UpdateEvent(data=layers)) def _gcode_complete_call_back(self, layers): self.status = "Complete" logging.info('Posting GCODE Complete Update') wx.PostEvent(self, self.UpdateEvent(data=layers)) def updateDisplay(self, message): logging.info('Updating display') self.parent.SetStatusText("%s : %s Layers" % (self.status, message.data)) logging.info('Getting Layers') self.layer_slider.SetMax(message.data) self.layers_slider.SetMax(message.data) self.layer_slider.SetValue(message.data / 2) self.layers_slider.SetValue(message.data) self.change_layer(None) logging.info('Got Layers') def shutdown(self): pass
class DisplayPanel(wx.Panel): def __init__(self, parent): self.parent = parent wx.Panel.__init__(self, self.parent, -1, style=wx.RAISED_BORDER) logging.debug("Starting api") self.api = Viewer() self.status = "" self.UpdateEvent, EVT_UPDATE = wx.lib.newevent.NewEvent() self.Bind(EVT_UPDATE, self.updateDisplay) sizer_display_control = wx.BoxSizer(wx.VERTICAL) control_sizer = wx.FlexGridSizer(3,2,5,5) layer_slider_text = wx.StaticText(self, label="Centre Layer") layers_to_display_slider_text = wx.StaticText(self, label="Number of Layers") layer_parse_text = wx.StaticText(self, label="Layers to Hide") self.layer_slider = wx.Slider(self, value = 1, minValue = 1, maxValue = 2) self.layers_slider = wx.Slider(self, value = 1, minValue = 1, maxValue = 2) self.skip_slider = wx.Slider(self, value = 50, minValue = 1, maxValue = 200) control_sizer.Add(layer_slider_text) control_sizer.Add(self.layer_slider,1,wx.EXPAND) control_sizer.Add(layers_to_display_slider_text) control_sizer.Add(self.layers_slider,1,wx.EXPAND) control_sizer.Add(layer_parse_text) control_sizer.Add(self.skip_slider,1,wx.EXPAND) control_sizer.AddGrowableCol(1, 1) sizer_display_control.Add(control_sizer,0,wx.EXPAND,5) logging.debug("Starting processor") self.processor = GLProcesser() logging.debug("Starting canvas") self.canvas = GCodeCanvas(self,self.processor) sizer_display_control.Add(self.canvas,1,wx.ALL|wx.EXPAND, 5) self.SetAutoLayout(True) self.SetSizer(sizer_display_control) self.SetFocus() self.Bind(wx.EVT_SLIDER, self.change_layer) def change_layer(self,event): bottom = self.layer_slider.GetValue() - self.layers_slider.GetValue() / 2 top = self.layer_slider.GetValue() + self.layers_slider.GetValue() / 2 skip = self.skip_slider.GetValue() logging.debug("Data Type: %s" % type(bottom) ) self.processor.update(self.api.get_layers(bottom,top,skip)) def load_file(self, afile): self.status = "Loading" logging.info("Loading file") self.api.load_gcode(afile, self._gcode_load_call_back,self._gcode_complete_call_back) def _gcode_load_call_back(self,layers): if layers % 10 == 0: logging.info('Posting GCODE Processing Update') wx.PostEvent(self, self.UpdateEvent(data = layers)) def _gcode_complete_call_back(self,layers): self.status = "Complete" logging.info('Posting GCODE Complete Update') wx.PostEvent(self, self.UpdateEvent(data = layers)) def updateDisplay(self,message): logging.info('Updating display') self.parent.SetStatusText("%s : %s Layers" % (self.status,message.data)) logging.info('Getting Layers') self.layer_slider.SetMax(message.data) self.layers_slider.SetMax(message.data) self.layer_slider.SetValue(message.data / 2) self.layers_slider.SetValue(message.data) self.change_layer(None) logging.info('Got Layers') def shutdown(self): pass
worst = min( timeit.repeat(stmt=''' skyline = compute(buildings) points = list(complete(skyline))''', setup=''' from skyline2 import pyramid, compute, complete buildings = pyramid({})'''.format(n), repeat=10, number=10)) worst = (100000.0 * worst) / 10 print('{:0}\t{:1.2f}\t{:1.3f}'.format(n, timing, worst)) ####################################################################### if __name__ == '__main__': performance() #buildings = list(read_buildings('rand.txt')) buildings = list(random_set(520, 1000, 100)) buildings = list(pyramid(15)) skyline = compute(buildings) points = list(complete(skyline)) for p in points: print('({},{})'.format(p[0], p[1]), end=' ') print() from api.viewer import Viewer view = Viewer(buildings, points) with open('index.html', 'w') as file: file.write(view.svg.to_text())