class ControlWorkbench(WorkbenchConnection): def __init__(self, parent): WorkbenchConnection.__init__(self, parent) self.driver = Driver.Instance() self.load() def load(self): #-- Toolbar Configuration self.toolbar.Realize() self.scrollPanel = wx.lib.scrolledpanel.ScrolledPanel(self._panel, size=(290, -1)) self.scrollPanel.SetupScrolling(scroll_x=False, scrollIntoView=False) self.scrollPanel.SetAutoLayout(1) self.controls = ExpandableControl(self.scrollPanel) self.controls.addPanel('camera_control', CameraControl(self.controls)) self.controls.addPanel('laser_control', LaserControl(self.controls)) self.controls.addPanel('ldr_value', LDRControl(self.controls)) self.controls.addPanel('motor_control', MotorControl(self.controls)) self.controls.addPanel('gcode_control', GcodeControl(self.controls)) self.videoView = VideoView(self._panel, self.getFrame, 10) self.videoView.SetBackgroundColour(wx.BLACK) #-- Layout vsbox = wx.BoxSizer(wx.VERTICAL) vsbox.Add(self.controls, 0, wx.ALL | wx.EXPAND, 0) self.scrollPanel.SetSizer(vsbox) vsbox.Fit(self.scrollPanel) self.addToPanel(self.scrollPanel, 0) self.addToPanel(self.videoView, 1) self.Layout() def initialize(self): self.controls.initialize() def getFrame(self): return self.driver.camera.captureImage() def updateToolbarStatus(self, status): if status: if self.IsShown(): self.videoView.play() self.controls.enableContent() else: self.videoView.stop() self.controls.disableContent() def updateProfileToAllControls(self): self.controls.updateProfile()
class ScanningWorkbench(WorkbenchConnection): def __init__(self, parent): WorkbenchConnection.__init__(self, parent) self.scanning = False self.showVideoViews = False self.simpleScan = SimpleScan.Instance() self.textureScan = TextureScan.Instance() self.currentScan = self.simpleScan self.load() self.pointCloudTimer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.onPointCloudTimer, self.pointCloudTimer) def load(self): #-- Toolbar Configuration self.playTool = self.toolbar.AddLabelTool( wx.NewId(), _("Play"), wx.Bitmap(resources.getPathForImage("play.png")), shortHelp=_("Play")) self.stopTool = self.toolbar.AddLabelTool( wx.NewId(), _("Stop"), wx.Bitmap(resources.getPathForImage("stop.png")), shortHelp=_("Stop")) self.pauseTool = self.toolbar.AddLabelTool( wx.NewId(), _("Pause"), wx.Bitmap(resources.getPathForImage("pause.png")), shortHelp=_("Pause")) self.toolbar.Realize() #-- Disable Toolbar Items self.enableLabelTool(self.playTool, False) self.enableLabelTool(self.stopTool, False) self.enableLabelTool(self.pauseTool, False) #-- Bind Toolbar Items self.Bind(wx.EVT_TOOL, self.onPlayToolClicked, self.playTool) self.Bind(wx.EVT_TOOL, self.onStopToolClicked, self.stopTool) self.Bind(wx.EVT_TOOL, self.onPauseToolClicked, self.pauseTool) self.scrollPanel = wx.lib.scrolledpanel.ScrolledPanel(self._panel, size=(290, -1)) self.scrollPanel.SetupScrolling(scroll_x=False, scrollIntoView=False) self.scrollPanel.SetAutoLayout(1) self.controls = ExpandableControl(self.scrollPanel) self.controls.addPanel('scan_parameters', ScanParameters(self.controls)) self.controls.addPanel('rotative_platform', RotativePlatform(self.controls)) self.controls.addPanel('image_acquisition', ImageAcquisition(self.controls)) self.controls.addPanel('image_segmentation', ImageSegmentation(self.controls)) self.controls.addPanel('point_cloud_generation', PointCloudGeneration(self.controls)) self.splitterWindow = wx.SplitterWindow(self._panel) self.videoView = VideoView(self.splitterWindow, self.getFrame, 10) self.sceneView = SceneView(self.splitterWindow) self.videoView.SetBackgroundColour(wx.BLACK) self.sceneView.SetBackgroundColour(wx.BLACK) self.splitterWindow.SplitVertically(self.videoView, self.sceneView) self.splitterWindow.SetMinimumPaneSize(200) #-- Layout vsbox = wx.BoxSizer(wx.VERTICAL) vsbox.Add(self.controls, 0, wx.ALL | wx.EXPAND, 0) self.scrollPanel.SetSizer(vsbox) vsbox.Fit(self.scrollPanel) self.addToPanel(self.scrollPanel, 0) self.addToPanel(self.splitterWindow, 1) #- Video View Selector self.buttonShowVideoViews = wx.BitmapButton( self.videoView, wx.NewId(), wx.Bitmap(resources.getPathForImage("views.png"), wx.BITMAP_TYPE_ANY), (10, 10)) self.comboVideoViews = wx.ComboBox( self.videoView, choices=[_("Laser"), _("Gray"), _("Line"), _("Color")], style=wx.CB_READONLY, pos=(60, 10)) self.buttonShowVideoViews.Hide() self.comboVideoViews.Hide() selectedView = { 'laser': _("Laser"), 'gray': _("Gray"), 'line': _("Line"), 'color': _("Color") } self.comboVideoViews.SetValue( selectedView[profile.getProfileSetting('img_type')]) self.buttonShowVideoViews.Bind(wx.EVT_BUTTON, self.onShowVideoViews) self.comboVideoViews.Bind(wx.EVT_COMBOBOX, self.onComboBoVideoViewsSelect) self.Layout() def initialize(self): self.controls.initialize() def onShow(self, event): if event.GetShow(): self.updateStatus(self.currentScan.driver.isConnected) self.pointCloudTimer.Stop() self.pointCloudTimer.Start(milliseconds=50) else: try: self.pointCloudTimer.Stop() self.videoView.stop() except: pass def onShowVideoViews(self, event): self.showVideoViews = not self.showVideoViews if self.showVideoViews: self.comboVideoViews.Show() else: self.comboVideoViews.Hide() def onComboBoVideoViewsSelect(self, event): selectedView = { _("Laser"): 'laser', _("Gray"): 'gray', _("Line"): 'line', _("Color"): 'color' }.get(self.comboVideoViews.GetValue()) self.currentScan.setImageType(selectedView) profile.putProfileSetting('img_type', selectedView) def getFrame(self): if self.scanning: return self.currentScan.getImage() else: return self.currentScan.getImage(self.driver.camera.captureImage()) def onPointCloudTimer(self, event): pointCloud = self.currentScan.getPointCloudIncrement() if pointCloud is not None: if pointCloud[0] is not None and pointCloud[1] is not None: if len(pointCloud[0]) > 0: self.sceneView.appendPointCloud(pointCloud[0], pointCloud[1]) def onPlayToolClicked(self, event): if self.currentScan.inactive: #-- Resume self.enableLabelTool(self.pauseTool, True) self.enableLabelTool(self.playTool, False) self.currentScan.resume() self.pointCloudTimer.Start(milliseconds=50) else: result = True if self.sceneView._object is not None: dlg = wx.MessageDialog( self, _("Your current model will be erased.\nDo you really want to do it?" ), _("Clear Point Cloud"), wx.YES_NO | wx.ICON_QUESTION) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() if result: value = profile.getProfileSetting('scan_type') print value if value == _("Without Texture"): self.currentScan = self.simpleScan self.driver.camera.setExposure( profile.getProfileSettingInteger( 'laser_exposure_scanning')) elif value == _("With Texture"): self.currentScan = self.textureScan self.driver.camera.setExposure( profile.getProfileSettingInteger( 'color_exposure_scanning')) self.currentScan.setCallbacks( self.beforeScan, None, lambda r: wx.CallAfter(self.afterScan, r)) self.currentScan.start() def beforeScan(self): self.scanning = True self.buttonShowVideoViews.Show() self.enableLabelTool(self.disconnectTool, False) self.enableLabelTool(self.playTool, False) self.enableLabelTool(self.stopTool, True) self.enableLabelTool(self.pauseTool, True) self.sceneView.createDefaultObject() self.videoView.setMilliseconds(200) self.combo.Disable() self.GetParent().menuFile.Enable( self.GetParent().menuLaunchWizard.GetId(), False) self.GetParent().menuFile.Enable( self.GetParent().menuLoadModel.GetId(), False) self.GetParent().menuFile.Enable( self.GetParent().menuSaveModel.GetId(), False) self.GetParent().menuFile.Enable( self.GetParent().menuClearModel.GetId(), False) self.GetParent().menuFile.Enable( self.GetParent().menuOpenProfile.GetId(), False) self.GetParent().menuFile.Enable( self.GetParent().menuSaveProfile.GetId(), False) self.GetParent().menuFile.Enable( self.GetParent().menuResetProfile.GetId(), False) self.pointCloudTimer.Start(milliseconds=50) def afterScan(self, response): ret, result = response if ret: dlg = wx.MessageDialog( self, _("Scanning has finished. If you want to save your point cloud go to File > Save Model" ), _("Scanning finished!"), wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() self.scanning = False self.onScanFinished() def onStopToolClicked(self, event): paused = self.currentScan.inactive self.currentScan.pause() dlg = wx.MessageDialog( self, _("Your current scanning will be stopped.\nDo you really want to do it?" ), _("Stop Scanning"), wx.YES_NO | wx.ICON_QUESTION) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() if result: self.scanning = False self.currentScan.stop() self.onScanFinished() else: if not paused: self.currentScan.resume() def onScanFinished(self): self.buttonShowVideoViews.Hide() self.comboVideoViews.Hide() self.enableLabelTool(self.disconnectTool, True) self.enableLabelTool(self.playTool, True) self.enableLabelTool(self.stopTool, False) self.enableLabelTool(self.pauseTool, False) self.driver.camera.setExposure( profile.getProfileSettingInteger('exposure_scanning')) self.videoView.setMilliseconds(5) self.combo.Enable() self.GetParent().menuFile.Enable( self.GetParent().menuLaunchWizard.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuLoadModel.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuSaveModel.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuClearModel.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuOpenProfile.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuSaveProfile.GetId(), True) self.GetParent().menuFile.Enable( self.GetParent().menuResetProfile.GetId(), True) self.pointCloudTimer.Stop() def onPauseToolClicked(self, event): self.enableLabelTool(self.pauseTool, False) self.enableLabelTool(self.playTool, True) self.currentScan.pause() self.pointCloudTimer.Stop() def updateToolbarStatus(self, status): if status: if self.IsShown(): self.videoView.play() self.enableLabelTool(self.playTool, True) self.enableLabelTool(self.stopTool, False) self.enableLabelTool(self.pauseTool, False) self.controls.enableContent() else: self.videoView.stop() self.enableLabelTool(self.playTool, False) self.enableLabelTool(self.stopTool, False) self.enableLabelTool(self.pauseTool, False) self.controls.disableContent() def updateProfileToAllControls(self): self.controls.updateProfile() self.driver.camera.setExposure( profile.getProfileSettingInteger('exposure_scanning'))
class CalibrationWorkbench(WorkbenchConnection): def __init__(self, parent): WorkbenchConnection.__init__(self, parent) self.calibrating = False self.load() def load(self): #-- Toolbar Configuration self.toolbar.Realize() self.scrollPanel = wx.lib.scrolledpanel.ScrolledPanel(self._panel, size=(290, -1)) self.scrollPanel.SetupScrolling(scroll_x=False, scrollIntoView=False) self.scrollPanel.SetAutoLayout(1) self.controls = ExpandableControl(self.scrollPanel) self.videoView = VideoView(self._panel, self.getFrame, 10) self.videoView.SetBackgroundColour(wx.BLACK) #-- Add Scroll Panels self.controls.addPanel('camera_settings', CameraSettingsPanel(self.controls)) self.controls.addPanel('pattern_settings', PatternSettingsPanel(self.controls)) self.controls.addPanel('laser_settings', LaserSettingsPanel(self.controls)) self.controls.addPanel( 'camera_intrinsics_panel', CameraIntrinsicsPanel( self.controls, buttonStartCallback=self.onCameraIntrinsicsStartCallback)) self.controls.addPanel( 'laser_triangulation_panel', LaserTriangulationPanel( self.controls, buttonStartCallback=self.onLaserTriangulationStartCallback)) self.controls.addPanel( 'platform_extrinsics_panel', PlatformExtrinsicsPanel( self.controls, buttonStartCallback=self.onPlatformExtrinsicsStartCallback)) #-- Add Calibration Pages self.cameraIntrinsicsMainPage = CameraIntrinsicsMainPage( self._panel, afterCancelCallback=self.onCancelCallback, afterCalibrationCallback=self. onCameraIntrinsicsAfterCalibrationCallback) self.cameraIntrinsicsResultPage = CameraIntrinsicsResultPage( self._panel, buttonRejectCallback=self.onCancelCallback, buttonAcceptCallback=self.onCameraIntrinsicsAcceptCallback) self.laserTriangulationMainPage = LaserTriangulationMainPage( self._panel, afterCancelCallback=self.onCancelCallback, afterCalibrationCallback=self. onLaserTriangulationAfterCalibrationCallback) self.laserTriangulationResultPage = LaserTriangulationResultPage( self._panel, buttonRejectCallback=self.onCancelCallback, buttonAcceptCallback=self.onLaserTriangulationAcceptCallback) self.platformExtrinsicsMainPage = PlatformExtrinsicsMainPage( self._panel, afterCancelCallback=self.onCancelCallback, afterCalibrationCallback=self. onPlatformExtrinsicsAfterCalibrationCallback) self.platformExtrinsicsResultPage = PlatformExtrinsicsResultPage( self._panel, buttonRejectCallback=self.onCancelCallback, buttonAcceptCallback=self.onPlatformExtrinsicsAcceptCallback) self.cameraIntrinsicsMainPage.Hide() self.cameraIntrinsicsResultPage.Hide() self.laserTriangulationMainPage.Hide() self.laserTriangulationResultPage.Hide() self.platformExtrinsicsMainPage.Hide() self.platformExtrinsicsResultPage.Hide() #-- Layout vsbox = wx.BoxSizer(wx.VERTICAL) vsbox.Add(self.controls, 0, wx.ALL | wx.EXPAND, 0) self.scrollPanel.SetSizer(vsbox) vsbox.Fit(self.scrollPanel) self.addToPanel(self.scrollPanel, 0) self.addToPanel(self.videoView, 1) self.addToPanel(self.cameraIntrinsicsMainPage, 1) self.addToPanel(self.cameraIntrinsicsResultPage, 1) self.addToPanel(self.laserTriangulationMainPage, 1) self.addToPanel(self.laserTriangulationResultPage, 1) self.addToPanel(self.platformExtrinsicsMainPage, 1) self.addToPanel(self.platformExtrinsicsResultPage, 1) self.Layout() def initialize(self): self.controls.initialize() def getFrame(self): frame = Driver.Instance().camera.captureImage() self.cameraIntrinsics = CameraIntrinsics.Instance() if frame is not None: retval, frame = self.cameraIntrinsics.detectChessboard(frame) return frame def onCameraIntrinsicsStartCallback(self): self.calibrating = True self.enableLabelTool(self.disconnectTool, False) self.controls.setExpandable(False) self.controls.panels['camera_intrinsics_panel'].buttonsPanel.Disable() self.combo.Disable() self.videoView.stop() self.videoView.Hide() self.cameraIntrinsicsMainPage.Show() self.cameraIntrinsicsMainPage.videoView.SetFocus() self.Layout() def onLaserTriangulationStartCallback(self): self.calibrating = True self.enableLabelTool(self.disconnectTool, False) self.controls.setExpandable(False) self.controls.panels['laser_triangulation_panel'].buttonsPanel.Disable( ) self.combo.Disable() self.videoView.stop() self.videoView.Hide() self.laserTriangulationMainPage.Show() self.Layout() def onPlatformExtrinsicsStartCallback(self): self.calibrating = True self.enableLabelTool(self.disconnectTool, False) self.controls.setExpandable(False) self.controls.panels['platform_extrinsics_panel'].buttonsPanel.Disable( ) self.combo.Disable() self.videoView.stop() self.videoView.Hide() self.platformExtrinsicsMainPage.Show() self.Layout() def onCancelCallback(self): self.calibrating = False self.enableLabelTool(self.disconnectTool, True) self.controls.setExpandable(True) self.controls.panels['camera_intrinsics_panel'].buttonsPanel.Enable() self.controls.panels['laser_triangulation_panel'].buttonsPanel.Enable() self.controls.panels['platform_extrinsics_panel'].buttonsPanel.Enable() self.controls.updateProfile() self.combo.Enable() self.cameraIntrinsicsMainPage.Hide() self.cameraIntrinsicsResultPage.Hide() self.laserTriangulationMainPage.Hide() self.laserTriangulationResultPage.Hide() self.platformExtrinsicsMainPage.Hide() self.platformExtrinsicsResultPage.Hide() self.videoView.play() self.videoView.Show() self.Layout() def onCameraIntrinsicsAfterCalibrationCallback(self, result): self.cameraIntrinsicsResultPage.processCalibration(result) if result[0]: self.cameraIntrinsicsMainPage.Hide() self.cameraIntrinsicsResultPage.Show() else: self.cameraIntrinsicsMainPage.initialize() self.Layout() def onCameraIntrinsicsAcceptCallback(self): self.videoView.play() self.calibrating = False self.enableLabelTool(self.disconnectTool, True) self.controls.setExpandable(True) self.controls.panels['camera_intrinsics_panel'].buttonsPanel.Enable() self.controls.panels[ 'camera_intrinsics_panel'].updateAllControlsToProfile() self.combo.Enable() self.cameraIntrinsicsResultPage.Hide() self.videoView.Show() self.Layout() def onLaserTriangulationAfterCalibrationCallback(self, result): self.laserTriangulationResultPage.processCalibration(result) if result[0]: self.laserTriangulationMainPage.Hide() self.laserTriangulationResultPage.Show() else: self.laserTriangulationMainPage.initialize() self.Layout() def onLaserTriangulationAcceptCallback(self): self.videoView.play() self.calibrating = False self.enableLabelTool(self.disconnectTool, True) self.controls.setExpandable(True) self.controls.panels['laser_triangulation_panel'].buttonsPanel.Enable() self.controls.panels[ 'laser_triangulation_panel'].updateAllControlsToProfile() self.combo.Enable() self.laserTriangulationResultPage.Hide() self.videoView.Show() self.Layout() def onPlatformExtrinsicsAfterCalibrationCallback(self, result): self.platformExtrinsicsResultPage.processCalibration(result) if result[0]: self.platformExtrinsicsMainPage.Hide() self.platformExtrinsicsResultPage.Show() else: self.platformExtrinsicsMainPage.initialize() self.Layout() def onPlatformExtrinsicsAcceptCallback(self): self.videoView.play() self.calibrating = False self.enableLabelTool(self.disconnectTool, True) self.controls.setExpandable(True) self.controls.panels['platform_extrinsics_panel'].buttonsPanel.Enable() self.controls.panels[ 'platform_extrinsics_panel'].updateAllControlsToProfile() self.combo.Enable() self.platformExtrinsicsResultPage.Hide() self.videoView.Show() self.Layout() def updateToolbarStatus(self, status): if status: if self.IsShown(): self.videoView.play() self.controls.panels[ 'camera_intrinsics_panel'].buttonsPanel.Enable() self.controls.panels[ 'laser_triangulation_panel'].buttonsPanel.Enable() self.controls.panels[ 'platform_extrinsics_panel'].buttonsPanel.Enable() self.controls.enableContent() else: self.videoView.stop() self.controls.panels[ 'camera_intrinsics_panel'].buttonsPanel.Disable() self.controls.panels[ 'laser_triangulation_panel'].buttonsPanel.Disable() self.controls.panels[ 'platform_extrinsics_panel'].buttonsPanel.Disable() self.controls.disableContent() self.calibrating = False self.combo.Enable() self.controls.setExpandable(True) self.cameraIntrinsicsMainPage.Hide() self.cameraIntrinsicsResultPage.Hide() self.laserTriangulationMainPage.Hide() self.laserTriangulationResultPage.Hide() self.platformExtrinsicsMainPage.Hide() self.platformExtrinsicsResultPage.Hide() self.videoView.Show() def updateProfileToAllControls(self): self.controls.updateProfile()