def mousePressEvent(self, event): pos = event.scenePos() if self.temp is not None: if event.button() == qc.Qt.LeftButton: self.temp.mousepress(pos) elif self.nextgeometry is not None: if event.button() == qc.Qt.LeftButton: if self.temp is None: if self.nextgeometry == TextParent: textpos = ShapeVertex(qh.to_tuple(pos),scaling = 1/popupcad.view_scaling) text = GenericText('',textpos,font='Courier',fontsize=2) temp = self.nextgeometry(text) self.addItem(temp) temp.editmode() elif self.nextgeometry == DrawingPoint: temp = self.nextgeometry(DrawnPoint(qh.to_tuple(pos),scaling = 1/popupcad.view_scaling)) self.addItem(temp) self.setFocusItem(temp) temp.updatescale() self.childfinished() else: self.temp = self.nextgeometry() self.addItem(self.temp) self.setFocusItem(self.temp) self.temp.mousepress(pos) else: qg.QGraphicsScene.mousePressEvent(self, event) self.leavingeditmode.emit()
def itemChange(self, change, value): if change == self.ItemPositionHasChanged: if self.changed_trigger: self.changed_trigger = False self.scene().savesnapshot.emit() self.generic.pos.setpos(qh.to_tuple(self.pos())) return super(TextParent, self).itemChange(change, value)
def mousepress(self, point): import numpy point = tuple(numpy.array(qh.to_tuple(point)) / popupcad.view_scaling) if not self.temphandle: a = ShapeVertex(point) self.temphandle = a.gen_interactive() self.temphandle.setParentItem(self) self.temphandle.updatescale() if self.generic.len_exterior() == 0: self.addhandle(self.temphandle) a = ShapeVertex(point) self.temphandle = a.gen_interactive() self.temphandle.setParentItem(self) self.temphandle.updatescale() self.updateshape() return elif self.generic.len_exterior() == 1: if self.addhandle(self.temphandle): self.finish_definition() self.updateshape() return else: return else: raise Exception self.finish_definition() self.updateshape() return self.updateshape()
def addvertex(self, qpoint): from popupcad.geometry.vertex import ShapeVertex import numpy v = ShapeVertex(numpy.array(qh.to_tuple(qpoint))/popupcad.view_scaling) self.generic.addvertex_exterior(v, special=True) self.updatehandles() self.refreshview()
def wheelEvent(self, event): p1 = event.pos() p2 = self.mapToScene(p1) if qt.loaded == 'PyQt5': delta = event.angleDelta().y() else: delta = event.delta() if delta < 0: zoom = 1. / popupcad.zoom_scale_factor else: zoom = popupcad.zoom_scale_factor newzoom = zoom * self.zoom() if newzoom > popupcad.zoom_max: zoom = popupcad.zoom_max / self.zoom() elif newzoom < popupcad.zoom_min: zoom = popupcad.zoom_min / self.zoom() self.scale(zoom, zoom) p3 = self.mapToScene(p1) dx = qh.to_tuple(p3 - p2) self.translate(*dx) event.accept()
def mousemove(self, point): import numpy point = tuple(numpy.array(qh.to_tuple(point)) / popupcad.view_scaling) if not not self.temphandle: self.temphandle.generic.setpos(point) self.temphandle.updateshape() self.updateshape()
def mouseMoveEvent(self, event): import numpy if self.changed_trigger: self.changed_trigger = False self.moved_trigger = True self.scene().savesnapshot.emit() dp = event.scenePos() - event.lastScenePos() dp = tuple(numpy.array(qh.to_tuple(dp)) / popupcad.view_scaling) self.generic.constrained_shift(dp, self.constraintsystem()) self.scene().updateshape()
def mousePressEvent(self, event): pos = event.scenePos() if self.temp is not None: if event.button() == qc.Qt.LeftButton: self.temp.mousepress(pos) elif self.nextgeometry is not None: if event.button() == qc.Qt.LeftButton: if self.temp is None: if self.nextgeometry == TextParent: textpos = ShapeVertex(qh.to_tuple(pos), scaling=1 / popupcad.view_scaling) text = GenericText('', textpos, font='Courier New', fontsize=1) temp = self.nextgeometry(text) self.addItem(temp) temp.editmode() elif self.nextgeometry == DrawingPoint: temp = self.nextgeometry( DrawnPoint(qh.to_tuple(pos), scaling=1 / popupcad.view_scaling)) self.addItem(temp) self.setFocusItem(temp) temp.updatescale() self.childfinished() else: self.temp = self.nextgeometry() self.addItem(self.temp) self.setFocusItem(self.temp) self.temp.mousepress(pos) else: qg.QGraphicsScene.mousePressEvent(self, event) self.leavingeditmode.emit()
def addhandle(self, handle): if self.generic.len_exterior() == 0: self.generic.addvertex_exterior(handle.get_generic()) self.temphandle = None return True elif self.generic.len_exterior() == 1: if qh.to_tuple(handle.pos()) != self.generic.get_exterior()[-1].getpos(): if self.checkdist(handle.generic.getpos(scaling=popupcad.view_scaling),self.generic.get_exterior()[-1].getpos(scaling=popupcad.view_scaling)): self.generic.addvertex_exterior(handle.get_generic()) self.temphandle = None return True else: raise Exception self.temphandle = None return True
def addhandle(self, handle): if self.generic.len_exterior() == 0: self.generic.addvertex_exterior(handle.get_generic()) self.temphandle = None return True elif self.generic.len_exterior() == 1: if qh.to_tuple(handle.pos()) != self.generic.get_exterior()[-1].getpos(): if self.checkdist(handle.generic.getpos(scaling=popupcad.view_scaling), self.generic.get_exterior()[-1].getpos(scaling=popupcad.view_scaling)): self.generic.addvertex_exterior(handle.get_generic()) self.temphandle = None return True else: raise Exception self.temphandle = None return True
def mouseMoveEvent(self, event): import numpy if self.connectedinteractive.mode is not None: if self.connectedinteractive.mode == self.connectedinteractive.modes.mode_edit: if self.changed_trigger: self.changed_trigger = False self.moved_trigger = True self.scene().savesnapshot.emit() dp = event.scenePos() - event.lastScenePos() dp = tuple(numpy.array(qh.to_tuple(dp)) / popupcad.view_scaling) self.generic.constrained_shift(dp, self.constraintsystem()) # self.updateshape() # try: # self.connectedinteractive.updateshape() # except AttributeError: # pass self.scene().updateshape()
def mousepress(self, point): import numpy point = tuple(numpy.array(qh.to_tuple(point)) / popupcad.view_scaling) if not self.temphandle: a = ShapeVertex(point) self.temphandle = a.gen_interactive() self.temphandle.setParentItem(self) self.temphandle.updatescale() self.addhandle(self.temphandle) else: self.addhandle(self.temphandle) if not self.temphandle: a = ShapeVertex(point) self.temphandle = a.gen_interactive() self.temphandle.setParentItem(self) self.temphandle.updatescale() self.updateshape()
def wheelEvent(self, event): p1 = event.pos() p2 = self.mapToScene(p1) if event.delta() < 0: zoom = 1. / popupcad.zoom_scale_factor else: zoom = popupcad.zoom_scale_factor newzoom = zoom * self.zoom() if newzoom > popupcad.zoom_max: zoom = popupcad.zoom_max / self.zoom() elif newzoom < popupcad.zoom_min: zoom = popupcad.zoom_min / self.zoom() self.scale(zoom, zoom) p3 = self.mapToScene(p1) dx = qh.to_tuple(p3 - p2) self.translate(*dx) event.accept()
def setPos(self, pos): import numpy pos = tuple(numpy.array(qh.to_tuple(pos)) / popupcad.view_scaling) self.generic.setpos(pos) self.updateshape()