개정판 7ce0aebd
symbol move test
Change-Id: I2177bfcc66a03db8833fe710086a2052efc3db93
DTI_PID/DTI_PID/LibraryItem.py | ||
---|---|---|
182 | 182 | |
183 | 183 |
drag = QDrag(self) |
184 | 184 |
drag.setMimeData(mime) |
185 |
originalPoint = self._symbol.getOriginalPoint() |
|
185 |
originalPoint = self._symbol.getOriginalPoint() if not self._symbol.getConvertingPoint() else self._symbol.getConvertingPoint()
|
|
186 | 186 |
drag.setHotSpot(QPoint(int(float(originalPoint.split(",")[0])), int(float(originalPoint.split(",")[1])))) |
187 |
drag.setPixmap(self._symbol.pixmap) |
|
187 |
pix = QPixmap(self._symbol.pixmap.size()) |
|
188 |
pix.fill(Qt.transparent) |
|
189 |
painter = QPainter(pix) |
|
190 |
painter.setOpacity(0.3) |
|
191 |
painter.drawPixmap(QPoint(), self._symbol.pixmap) |
|
192 |
painter.end() |
|
193 |
drag.setPixmap(pix) |
|
188 | 194 |
|
189 | 195 |
model = self._symbol_tree_widget.model().sourceModel() |
190 | 196 |
_model = self._symbol_tree_widget.model() |
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
190 | 190 |
@author |
191 | 191 |
@date |
192 | 192 |
''' |
193 | ||
194 | 193 |
def loadImageFromFile(self, drawing): |
195 | 194 |
import cv2 |
196 | 195 |
import numpy as np |
... | ... | |
357 | 356 |
@date |
358 | 357 |
@history block clear selection when right mouse button is clicked |
359 | 358 |
''' |
360 | ||
361 | 359 |
def mousePressEvent(self, event): |
362 | 360 |
try: |
363 | 361 |
if self.command is not None: |
... | ... | |
372 | 370 |
event.accept() |
373 | 371 |
return |
374 | 372 |
except Exception as ex: |
375 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
376 |
sys.exc_info()[-1].tb_lineno)) |
|
373 |
from App import App |
|
374 |
from AppDocData import MessageType |
|
375 | ||
376 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
377 |
sys.exc_info()[-1].tb_lineno) |
|
378 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
377 | 379 | |
378 | 380 |
if event.button() != Qt.RightButton: |
379 | 381 |
QGraphicsView.mousePressEvent(self, event) |
... | ... | |
399 | 401 |
cursor = QCursor(Qt.ArrowCursor) |
400 | 402 |
QApplication.instance().setOverrideCursor(cursor) |
401 | 403 |
return |
404 |
else: |
|
405 |
QGraphicsView.mouseReleaseEvent(self, event) |
|
402 | 406 |
except Exception as ex: |
403 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
404 |
sys.exc_info()[-1].tb_lineno))
|
|
407 |
from App import App
|
|
408 |
from AppDocData import MessageType
|
|
405 | 409 | |
406 |
#QGraphicsView.mouseReleaseEvent(self, event) |
|
410 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
411 |
sys.exc_info()[-1].tb_lineno) |
|
412 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
407 | 413 | |
408 | 414 |
""" |
409 | 415 |
@brief Show entire image. |
... | ... | |
645 | 651 |
@history humkyung 2018.08.23 change scenePos to connector's center when symbol is placed on connector |
646 | 652 |
''' |
647 | 653 |
@staticmethod |
648 |
def matchSymbolToLine(scene, svg, scenePos, angle=None, flip=None, strict=False, auto=False): |
|
654 |
def matchSymbolToLine(scene, svg, scenePos, angle=None, flip=None, strict=False, auto=False, move=False):
|
|
649 | 655 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
650 | 656 |
from EngineeringLineItem import QEngineeringLineItem |
651 | 657 |
from SymbolSvgItem import SymbolSvgItem |
... | ... | |
657 | 663 |
from AppDocData import AppDocData |
658 | 664 | |
659 | 665 |
try: |
660 |
svg.transfer.onRemoved.connect(App.mainWnd().itemRemoved) |
|
666 |
if not svg.scene(): |
|
667 |
svg.transfer.onRemoved.connect(App.mainWnd().itemRemoved) |
|
661 | 668 | |
662 | 669 |
items = [item for item in scene.items(scenePos) if type(item) is not QEngineeringUnknownItem and \ |
663 |
type(item) is not QGraphicsPixmapItem and type(item) is not QGraphicsTextItem] |
|
670 |
type(item) is not QGraphicsPixmapItem and type(item) is not QGraphicsTextItem and item is not svg]
|
|
664 | 671 |
connectors = [] |
665 | 672 |
if len(items) > 0 and type(items[0]) is QEngineeringConnectorItem: |
666 | 673 |
scenePos = QPointF(items[0].center()[0], items[0].center()[1]) |
... | ... | |
674 | 681 |
# (type(item) is QEngineeringLineItem) and (item.distanceTo((scenePos.x(), scenePos.y())) < 20)] |
675 | 682 |
allowed_error = 0.0001 |
676 | 683 |
if len(connectors) == 1 and len(svg.connectors) >= 2 and len(connectors[0].parentItem().connectors): |
684 |
if move: |
|
685 |
svg.scene().removeItem(svg) |
|
686 |
svg.resetPosition() |
|
687 | ||
677 | 688 |
# item assistant with connection |
678 | 689 |
xl = connectors[0].parentItem().symbolOrigin[0] - connectors[0].connectPoint[0] |
679 | 690 |
yl = connectors[0].parentItem().symbolOrigin[1] - connectors[0].connectPoint[1] |
... | ... | |
733 | 744 |
connectors[0].connect(svg) |
734 | 745 |
#connectors[0].highlight(False) |
735 | 746 |
elif not strict and len(items) == 1 and type(items[0]) is QEngineeringLineItem and items[0].length() > svg.size[0] and items[0].length() > svg.size[1]: |
747 |
if move: |
|
748 |
svg.scene().removeItem(svg) |
|
749 |
svg.resetPosition() |
|
750 |
|
|
736 | 751 |
vec = items[0].perpendicular() |
737 | 752 |
line = [(scenePos.x() - vec[0] * 20, scenePos.y() - vec[1] * 20), (scenePos.x() + vec[0] * 20, scenePos.y() + vec[1] * 20)] |
738 | 753 |
origin = items[0].intersection(line) |
... | ... | |
803 | 818 |
scene.addItem(outLine) |
804 | 819 |
items[0].transfer.onRemoved.emit(items[0]) |
805 | 820 |
|
806 |
elif not strict: |
|
821 |
elif not strict and not move:
|
|
807 | 822 |
svg.angle = angle if angle else 0.0 |
808 | 823 |
svg.flip = flip if flip else 0 |
809 | 824 |
configs = AppDocData.instance().getConfigs('Data', 'Grid') |
DTI_PID/DTI_PID/QtImageViewerScene.py | ||
---|---|---|
456 | 456 |
if self._selcted_items and symbols and event.button() == Qt.LeftButton and len(self._selcted_items) == 1 and \ |
457 | 457 |
(event.modifiers() == Qt.AltModifier or event.modifiers() == Qt.ShiftModifier or int(event.modifiers()) == 167772160): |
458 | 458 |
item = self._selcted_items[0] |
459 |
item.scene().removeItem(item)
|
|
460 |
QtImageViewer.matchSymbolToLine(self, item, event.scenePos())
|
|
459 |
if not item.has_connection:
|
|
460 |
QtImageViewer.matchSymbolToLine(self, item, event.scenePos(), move=True)
|
|
461 | 461 | |
462 | 462 |
super(QtImageViewerScene, self).mouseReleaseEvent(event) |
463 | 463 |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
2505 | 2505 |
if self.isSelected(): |
2506 | 2506 |
self.drawFocusRect(painter) |
2507 | 2507 | |
2508 |
def addSvgItemToScene(self, scene, undoable: bool = False, manual=False) -> None: |
|
2509 |
"""Add Svg Item into ImageViewer's Scene""" |
|
2510 |
self.resetTransform() |
|
2511 |
self.setRotation(0) |
|
2508 |
def resetPosition(self): |
|
2509 |
if self.flip: |
|
2510 |
self.flip_symbol() |
|
2511 | ||
2512 |
self.moveBy(-self.origin[0], -self.origin[1]) |
|
2513 |
self.setRotation(math.degrees(-self.angle)) |
|
2514 |
self.moveBy(self.symbolOrigin[0], self.symbolOrigin[1]) |
|
2512 | 2515 |
self.setTransformOriginPoint(QPointF(0, 0)) |
2513 |
scene_origin = self.mapToScene(self.transformOriginPoint()) |
|
2514 |
self.moveBy(-scene_origin.x(), -scene_origin.y()) |
|
2515 | 2516 | |
2517 |
def addSvgItemToScene(self, scene, undoable: bool = False, manual=False) -> None: |
|
2518 |
"""Add Svg Item into ImageViewer's Scene""" |
|
2516 | 2519 |
if self.flip: |
2517 | 2520 |
self.flip_symbol() |
2518 | 2521 |
DTI_PID/DTI_PID/SymbolTreeWidget.py | ||
---|---|---|
467 | 467 |
drag.setMimeData(mime) |
468 | 468 |
originalPoint = symData.getOriginalPoint() if not symData.getConvertingPoint() else symData.getConvertingPoint() |
469 | 469 |
drag.setHotSpot(QPoint(int(float(originalPoint.split(",")[0])), int(float(originalPoint.split(",")[1])))) |
470 |
drag.setPixmap(symData.pixmap) |
|
470 |
pix = QPixmap(symData.pixmap.size()) |
|
471 |
pix.fill(Qt.transparent) |
|
472 |
painter = QPainter(pix) |
|
473 |
painter.setOpacity(0.3) |
|
474 |
painter.drawPixmap(QPoint(), symData.pixmap) |
|
475 |
painter.end() |
|
476 |
drag.setPixmap(pix) |
|
471 | 477 |
drag.exec(Qt.CopyAction) |
472 | 478 |
except Exception as ex: |
473 | 479 |
from App import App |
내보내기 Unified diff