Example #1
0
	def __init__(self, mainwin, machine):
		self._mainwin = mainwin
		self._machine = machine

		super(ControlGraphicsView, self).__init__(None)

		self._ui = Ui_GraphicsViewWindow()
		self._ui.setupUi(self)

		self._ui.markOrigin.clicked.connect(self.markOrigin)
		self._ui.gotoXY.clicked.connect(self.gotoXY)
		self._ui.polarFixXY.clicked.connect(self.polarFixXY)
		self._ui.closeButton.clicked.connect(self.close)
Example #2
0
class ControlGraphicsView(QtGui.QDialog):
	closed = QtCore.Signal()

	def __init__(self, mainwin, machine):
		self._mainwin = mainwin
		self._machine = machine

		super(ControlGraphicsView, self).__init__(None)

		self._ui = Ui_GraphicsViewWindow()
		self._ui.setupUi(self)

		self._ui.markOrigin.clicked.connect(self.markOrigin)
		self._ui.gotoXY.clicked.connect(self.gotoXY)
		self._ui.polarFixXY.clicked.connect(self.polarFixXY)
		self._ui.closeButton.clicked.connect(self.close)

	@QtCore.Slot()
	def markOrigin(self):
		(x, y) = self._scene.getCursorPosition()
		self._scene.setCrosshairPosition(x, y)
		self._mainwin.setOriginOffset(x, y)

	@QtCore.Slot()
	def gotoXY(self):
		if isinstance(self._machine.action(), ProgrammedMotionController):
			return
		elif not isinstance(self._machine.action(), ManualMotionController):
			self._machine.setAction(ManualMotionController(self._machine))

		(posX, posY) = self._scene.getCursorPosition()
		(orgX, orgY) = self._scene.getCrosshairPosition()

		(posR, posPhi) = toPolar(posX - orgX, posY - orgY)
		(r, deltaPhi) = self._mainwin.polarCorrection()
		(posX, posY) = fromPolar(posR * r, posPhi + deltaPhi)

		workpiecePos = self._mainwin.workpiecePos()
		self._machine.action().gotoXYZ(posX + workpiecePos[0], posY + workpiecePos[1])

	@QtCore.Slot()
	def polarFixXY(self):
		(orgX, orgY) = self._scene.getCrosshairPosition()
		(posX, posY) = self._scene.getCursorPosition()
		(r1, phi1) = toPolar(posX - orgX, posY - orgY)

		workpiecePos = self._mainwin.workpiecePos()
		posX = self._machine.machineStatus().x() - workpiecePos[0] + orgX
		posY = self._machine.machineStatus().y() - workpiecePos[1] + orgY
		(r2, phi2) = toPolar(posX - orgX, posY - orgY)
		self._mainwin.setPolarCorrection(r2 / r1, phi2 - phi1)

	def closeEvent(self, event):
		self.closed.emit()
		event.accept()

	def render(self, parser):
		self._scene = MyGraphicsScene()

		renderer = SceneRenderer(self._scene)
		renderer.render(parser)

		self._ui.graphicsView.setScene(self._scene)

		bbox = self._scene.itemsBoundingRect()
		bbox.setTop(bbox.top() - bbox.height() * 0.1)
		bbox.setBottom(bbox.bottom() + bbox.height() * 0.1)
		bbox.setLeft(bbox.left() - bbox.width() * 0.1)
		bbox.setRight(bbox.right() + bbox.width() * 0.1)
		self._scene.setSceneRect(bbox)
		self._ui.graphicsView.fitInView(bbox, QtCore.Qt.KeepAspectRatio)
		self._ui.graphicsView.autoconfSizes()  # @fixme wait for initial resize