Skip to content

Commit

Permalink
Merge pull request #71 from 85vmh/fixed_vtk_clipping_range
Browse files Browse the repository at this point in the history
Fixed datasource in designer mode
  • Loading branch information
TurBoss authored Feb 3, 2021
2 parents 80dcf6c + 0dc39ef commit 53b477d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
83 changes: 38 additions & 45 deletions qtpyvcp/widgets/display_widgets/vtk_backplot/vtk_backplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 53b477d

Please sign in to comment.