diff --git a/qtpyvcp/widgets/display_widgets/vtk_backplot/linuxcnc_datasource.py b/qtpyvcp/widgets/display_widgets/vtk_backplot/linuxcnc_datasource.py index bb7f165af..6fab84e66 100644 --- a/qtpyvcp/widgets/display_widgets/vtk_backplot/linuxcnc_datasource.py +++ b/qtpyvcp/widgets/display_widgets/vtk_backplot/linuxcnc_datasource.py @@ -10,6 +10,7 @@ LOG = logger.getLogger(__name__) from PyQt5.QtCore import QObject +IN_DESIGNER = os.getenv('DESIGNER', False) """ This class acts as a datasource for the VTK components. It abstracts all the linuxcnc specific logic and exposes simple methods that could be eventually @@ -154,9 +155,12 @@ def getActiveWcsOffsets(self): return tuple(xy) def __getRotationOfActiveWcs(self): - current_wcs = self.getWcsOffsets()[self.getActiveWcsIndex()] - LOG.debug("-----current_wcs index: {}".format(current_wcs)) - return current_wcs[9] + if not IN_DESIGNER: + current_wcs = self.getWcsOffsets()[self.getActiveWcsIndex()] + LOG.debug("-----current_wcs index: {}".format(current_wcs)) + return current_wcs[9] + else: + return 0 def getG92_offset(self): return self._status.stat.g92_offset diff --git a/qtpyvcp/widgets/display_widgets/vtk_backplot/vtk_backplot.py b/qtpyvcp/widgets/display_widgets/vtk_backplot/vtk_backplot.py index 622117cde..551ac912e 100644 --- a/qtpyvcp/widgets/display_widgets/vtk_backplot/vtk_backplot.py +++ b/qtpyvcp/widgets/display_widgets/vtk_backplot/vtk_backplot.py @@ -46,16 +46,6 @@ class VTKBackPlot(QVTKRenderWindowInteractor, VCPWidget, BaseBackPlot): def __init__(self, parent=None): super(VTKBackPlot, self).__init__(parent) LOG.debug("---------using refactored vtk code") - - - # properties - self._background_color = QColor(0, 0, 0) - self._background_color2 = QColor(0, 0, 0) - self._enableProgramTicks = True - - if IN_DESIGNER: - return - self._datasource = LinuxCncDataSource() self.canon_class = VTKCanon @@ -72,6 +62,11 @@ def __init__(self, parent=None): # assume that we are standing upright and compute azimuth around that axis self.natural_view_up = (0, 0, 1) + # properties + self._background_color = QColor(0, 0, 0) + self._background_color2 = QColor(0, 0, 0) + self._enableProgramTicks = True + self.active_wcs_index = self._datasource.getActiveWcsIndex() self.wcs_offsets = self._datasource.getWcsOffsets() self.active_wcs_offset = self._datasource.getActiveWcsOffsets() @@ -96,9 +91,9 @@ def __init__(self, parent=None): self.clipping_range_near = 0.01 self.clipping_range_far = 10000.0 #TODO: check this value else: - self.position_mult = 10 + self.position_mult = 100 self.clipping_range_near = 0.001 - self.clipping_range_far = 100.0 #TODO: check this value + self.clipping_range_far = 1000.0 #TODO: check this value self.camera.SetClippingRange(self.clipping_range_near, self.clipping_range_far) self.renderer = vtk.vtkRenderer() @@ -633,56 +628,63 @@ def setView(self, view): @Slot() def setViewP(self): self.active_view = 'P' + position = self.wcs_offsets[self.active_wcs_index] self.camera.SetPosition(self.position_mult, -self.position_mult, self.position_mult) + self.camera.SetFocalPoint(position[:3]) self.camera.SetViewUp(0, 0, 1) - self.__setFocalPoint() self.__doCommonSetViewWork() @Slot() def setViewX(self): self.active_view = 'X' - self.camera.SetPosition(0, -self.position_mult, 0) + position = self.wcs_offsets[self.active_wcs_index] + self.camera.SetPosition(position[0], position[1] - self.position_mult, position[2]) + self.camera.SetFocalPoint(position[:3]) self.camera.SetViewUp(0, 0, 1) - self.__setFocalPoint() self.__doCommonSetViewWork() @Slot() def setViewXZ(self): self.active_view = 'XZ' - self.camera.SetPosition(0, self.position_mult, 0) + position = self.wcs_offsets[self.active_wcs_index] + self.camera.SetPosition(position[0], position[1] + self.position_mult, position[2]) + self.camera.SetFocalPoint(position[:3]) self.camera.SetViewUp(1, 0, 0) - self.__setFocalPoint() self.__doCommonSetViewWork() @Slot() def setViewXZ2(self): self.active_view = 'XZ2' - self.camera.SetPosition(0, -self.position_mult, 0) + position = self.wcs_offsets[self.active_wcs_index] + self.camera.SetPosition(position[0], position[1] - self.position_mult, position[2]) + self.camera.SetFocalPoint(position[:3]) self.camera.SetViewUp(-1, 0, 0) - self.__setFocalPoint() self.__doCommonSetViewWork() @Slot() def setViewY(self): self.active_view = 'Y' - self.camera.SetPosition(self.position_mult, 0, 0) + position = self.wcs_offsets[self.active_wcs_index] + self.camera.SetPosition(position[0] + self.position_mult, position[1], position[2]) + self.camera.SetFocalPoint(position[:3]) self.camera.SetViewUp(0, 0, 1) - self.__setFocalPoint() self.__doCommonSetViewWork() @Slot() def setViewZ(self): self.active_view = 'Z' - self.camera.SetPosition(0, 0, self.position_mult) + position = self.wcs_offsets[self.active_wcs_index] + self.camera.SetPosition(position[0], position[1], position[2] + self.position_mult) + self.camera.SetFocalPoint(position[:3]) self.camera.SetViewUp(0, 1, 0) - self.__setFocalPoint() self.__doCommonSetViewWork() @Slot() def setViewZ2(self): - self.camera.SetPosition(0, 0, self.position_mult) + position = self.wcs_offsets[self.active_wcs_index] + self.camera.SetPosition(position[0], position[1], position[2] + self.position_mult) + self.camera.SetFocalPoint(position[:3]) self.camera.SetViewUp(1, 0, 0) - self.__setFocalPoint() self.__doCommonSetViewWork() @Slot() @@ -714,20 +716,14 @@ def setViewMachine(self): @Slot() def setViewPath(self): LOG.debug('-----setViewPath') - self.__setFocalPoint() - position = self.wcs_offsets[self.active_wcs_index] self.camera.SetPosition(position[0] + self.position_mult, - -(position[0] + self.position_mult), - position[0] + self.position_mult) + -(position[1] + self.position_mult), + position[2] + self.position_mult) + self.camera.SetFocalPoint(position[:3]) self.camera.SetViewUp(0, 0, 1) self.__doCommonSetViewWork() - def __setFocalPoint(self): - position = self.wcs_offsets[self.active_wcs_index] - LOG.debug('-----focal point: {}'.format(position)) - self.camera.SetFocalPoint(position[:3]) - def __doCommonSetViewWork(self): # This is common logic for all setView**** methods. self.camera.SetClippingRange(self.clipping_range_near, self.clipping_range_far) @@ -896,9 +892,8 @@ def backgroundColor(self): def backgroundColor(self, color): self._background_color = color - if not IN_DESIGNER: - self.renderer.SetBackground(color.getRgbF()[:3]) - self.renderer_window.Render() + self.renderer.SetBackground(color.getRgbF()[:3]) + self.renderer_window.Render() @Property(QColor) def backgroundColor2(self): @@ -907,19 +902,17 @@ def backgroundColor2(self): @backgroundColor2.setter def backgroundColor2(self, color2): self._background_color2 = color2 - - if not IN_DESIGNER: - self.renderer.GradientBackgroundOn() - self.renderer.SetBackground2(color2.getRgbF()[:3]) - self.renderer_window.Render() + + self.renderer.GradientBackgroundOn() + self.renderer.SetBackground2(color2.getRgbF()[:3]) + self.renderer_window.Render() @backgroundColor2.reset def backgroundColor2(self): self._background_color2 = QColor(0, 0, 0) - if not IN_DESIGNER: - self.renderer.GradientBackgroundOff() - self.renderer_window.Render() + self.renderer.GradientBackgroundOff() + self.renderer_window.Render() @Property(bool) def enableProgramTicks(self):