개정판 13c6ca24
SymbolEditor 에서 Original, Connection Point 지정 시 int 타입에서 float 타입으로 변경
DTI_PID/DTI_PID/Commands/ConnectionPointCommand.py | ||
---|---|---|
28 | 28 |
|
29 | 29 |
''' |
30 | 30 |
@brief pan image by left click and drag |
31 |
@history 2016.06.12 Jeongwoo Make new point (newScenePos) |
|
31 | 32 |
''' |
32 | 33 |
def execute(self, param): |
33 | 34 |
event = param[1] |
34 | 35 |
scenePos = param[2] |
36 |
|
|
37 |
newScenePos = QPointF(scenePos.x() - (scenePos.x()%0.5), scenePos.y() - (scenePos.y()%0.5)) |
|
35 | 38 |
if 'mousePressEvent' == param[0]: |
36 | 39 |
if event.button() == Qt.LeftButton: |
37 |
#if not self.isSelected: |
|
38 |
image = self.imageViewer.image() |
|
39 |
width = image.width() |
|
40 |
height = image.height() |
|
41 |
|
|
42 |
clickedX = int(scenePos.x()) |
|
43 |
clickedY = int(scenePos.y()) |
|
40 |
#if not self.isSelected: |
|
41 |
#clickedX = int(scenePos.x()) |
|
42 |
#clickedY = int(scenePos.y()) |
|
44 | 43 |
|
45 |
if (clickedX >= 0 and clickedX <= width) and (clickedY >= 0 and clickedY <= height):
|
|
44 |
if self.isOnImage(newScenePos.x(), newScenePos.y()):
|
|
46 | 45 |
## drawCircle Method is static |
47 |
ConnectionPointCommand.drawCircle(self.imageViewer, scenePos.x(), scenePos.y())
|
|
46 |
ConnectionPointCommand.drawCircle(self.imageViewer, newScenePos.x(), newScenePos.y())
|
|
48 | 47 |
#self.isSelected = True |
49 |
text = "{},{}".format(clickedX, clickedY)
|
|
48 |
text = "{},{}".format(newScenePos.x(), newScenePos.y())
|
|
50 | 49 |
self.connectionPointLineEdit.setText(text) |
51 | 50 |
self.connectionPointListWidget.addItem(text) |
52 | 51 |
else: |
... | ... | |
55 | 54 |
elif 'mouseMoveEvent' == param[0]: |
56 | 55 |
#if not self.isSelected: |
57 | 56 |
coords = event.pos() |
58 |
if self.isOnImage(scenePos.x(), scenePos.y()):
|
|
57 |
if self.isOnImage(newScenePos.x(), newScenePos.y()):
|
|
59 | 58 |
self.showGuideline(scenePos) |
60 |
self.connectionPointLineEdit.setText("{},{}".format(int(scenePos.x()), int(scenePos.y())))
|
|
59 |
self.connectionPointLineEdit.setText("{},{}".format(newScenePos.x(), newScenePos.y()))
|
|
61 | 60 |
else: |
62 | 61 |
self.showGuideline(self.initMinPoint) |
63 | 62 |
self.connectionPointLineEdit.setText("") |
... | ... | |
66 | 65 |
|
67 | 66 |
''' |
68 | 67 |
@history 2018.06.11 Jeongwoo Shorten method to add Ellipse |
68 |
2018.06.12 Jeongwoo Modify RectF's coords |
|
69 | 69 |
''' |
70 | 70 |
@staticmethod |
71 | 71 |
def drawCircle(imageViewer, x, y): |
72 |
imageViewer.scene.addEllipse(QRectF(int(x) - 0.5, int(y) - 0.5, 1, 1), QPen(QColor(0, 0, 255)), QBrush(QColor(0, 0, 255)))
|
|
72 |
imageViewer.scene.addEllipse(QRectF(float(x) - (float(x)%0.5) - 0.5, float(y) - (float(y)%0.5) - 0.5, 1, 1), QPen(QColor(0, 0, 255)), QBrush(QColor(0, 0, 255)))
|
|
73 | 73 |
|
74 | 74 |
''' |
75 | 75 |
@history 2018.06.11 Jeongwoo Make area bigger (width/height 1px) |
76 |
2018.06.12 Jeongwoo Make area smaller (width/height 1px) |
|
76 | 77 |
''' |
77 | 78 |
def isOnImage(self, x, y): |
78 |
if (x >= 0 and x <= self.imageWidth + 1) and (y >= 0 and y <= self.imageHeight + 1):
|
|
79 |
if (x >= 0 and x <= self.imageWidth) and (y >= 0 and y <= self.imageHeight):
|
|
79 | 80 |
return True |
80 | 81 |
else: |
81 | 82 |
return False |
DTI_PID/DTI_PID/Commands/OriginalPointCommand.py | ||
---|---|---|
3 | 3 |
try: |
4 | 4 |
from PyQt5.QtCore import Qt, QPoint, QPointF, QRectF, pyqtSignal, QT_VERSION_STR |
5 | 5 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QColor, QPen, QBrush, QTransform, QCursor |
6 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QMessageBox |
|
6 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QMessageBox, QGraphicsEllipseItem
|
|
7 | 7 |
except ImportError: |
8 | 8 |
try: |
9 | 9 |
from PyQt4.QtCore import Qt, QPoint, QPointF, QRectF, pyqtSignal, QT_VERSION_STR |
10 | 10 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QColor, QPen, QBrush, QCursor |
11 |
from PyQt4.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QMessageBox, QGraphicsEllipseItem |
|
11 | 12 |
except ImportError: |
12 | 13 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
13 | 14 |
|
14 | 15 |
import sys |
15 | 16 |
|
16 | 17 |
class OriginalPointCommand(AbstractCommand.AbstractCommand): |
18 |
''' |
|
19 |
@history 2018.06.12 Jeongwoo coords type changed (int → float) |
|
20 |
''' |
|
17 | 21 |
def __init__(self, imageViewer, originalPointLineEdit): |
18 | 22 |
super(OriginalPointCommand, self).__init__(imageViewer) |
19 | 23 |
self.name = 'OriginalPoint' |
... | ... | |
28 | 32 |
coords = self.originalPointLineEdit.text() |
29 | 33 |
if coords: |
30 | 34 |
self.originalPointLineEdit.setText('') |
31 |
x = int(coords.split(",")[0])
|
|
32 |
y = int(coords.split(",")[1])
|
|
35 |
x = float(coords.split(",")[0])
|
|
36 |
y = float(coords.split(",")[1])
|
|
33 | 37 |
OriginalPointCommand.removeCircle(self.imageViewer, x, y) |
34 | 38 |
## Guideline |
35 | 39 |
self.showGuideline(self.initMinPoint) |
36 | 40 |
|
37 | 41 |
''' |
38 | 42 |
@brief pan image by left click and drag |
43 |
@history 2016.06.12 Jeongwoo Make new point (newScenePos) |
|
39 | 44 |
''' |
40 | 45 |
def execute(self, param): |
41 | 46 |
event = param[1] |
42 | 47 |
scenePos = param[2] |
48 |
|
|
49 |
newScenePos = QPointF(scenePos.x() - (scenePos.x()%0.5), scenePos.y() - (scenePos.y()%0.5)) |
|
43 | 50 |
if 'mousePressEvent' == param[0]: |
44 | 51 |
if event.button() == Qt.LeftButton: |
45 | 52 |
if not self.isSelected: |
46 |
clickedX = int(scenePos.x()) |
|
47 |
clickedY = int(scenePos.y()) |
|
53 |
#clickedX = int(scenePos.x())
|
|
54 |
#clickedY = int(scenePos.y())
|
|
48 | 55 |
|
49 |
if self.isOnImage(clickedX, clickedY):
|
|
56 |
if self.isOnImage(newScenePos.x(), newScenePos.y()):
|
|
50 | 57 |
## drawCircle Method is static |
51 |
OriginalPointCommand.drawCircle(self.imageViewer, scenePos.x(), scenePos.y())
|
|
58 |
OriginalPointCommand.drawCircle(self.imageViewer, newScenePos.x(), newScenePos.y())
|
|
52 | 59 |
self.isSelected = True |
53 |
self.originalPointLineEdit.setText("{},{}".format(clickedX, clickedY))
|
|
60 |
self.originalPointLineEdit.setText("{},{}".format(newScenePos.x(), newScenePos.y()))
|
|
54 | 61 |
self.imageViewer.isOriginalPointSelected = True |
55 | 62 |
|
56 | 63 |
## Guideline |
... | ... | |
63 | 70 |
coords = event.pos() |
64 | 71 |
if self.isOnImage(scenePos.x(), scenePos.y()): |
65 | 72 |
self.showGuideline(scenePos) |
66 |
self.originalPointLineEdit.setText("{},{}".format(int(scenePos.x()), int(scenePos.y())))
|
|
73 |
self.originalPointLineEdit.setText("{},{}".format(newScenePos.x(), newScenePos.y()))
|
|
67 | 74 |
else: |
68 | 75 |
self.showGuideline(self.initMinPoint) |
69 | 76 |
self.originalPointLineEdit.setText("") |
... | ... | |
72 | 79 |
|
73 | 80 |
''' |
74 | 81 |
@history 2018.06.11 Jeongwoo Shorten method to add Ellipse |
82 |
2018.06.12 Jeongwoo Modify RectF's coords |
|
75 | 83 |
''' |
76 | 84 |
@staticmethod |
77 | 85 |
def drawCircle(imageViewer, x, y): |
78 |
imageViewer.scene.addEllipse(QRectF(int(x) - 0.5, int(y) - 0.5, 1, 1), QPen(QColor(255, 0, 0)), QBrush(QColor(255, 0, 0)))
|
|
86 |
imageViewer.scene.addEllipse(QRectF(float(x) - (float(x)%0.5) - 0.5, float(y) - (float(y)%0.5) - 0.5, 1, 1), QPen(QColor(255, 0, 0)), QBrush(QColor(255, 0, 0)))
|
|
79 | 87 |
|
88 |
''' |
|
89 |
@history 2018.06.12 Jeongwoo Add conditions for selecting ellipse item |
|
90 |
''' |
|
80 | 91 |
@staticmethod |
81 | 92 |
def removeCircle(imageViewer, x, y): |
82 | 93 |
scenePos = QPointF(x, y) |
83 | 94 |
imageWidth = imageViewer.image().width() |
84 | 95 |
imageHeight = imageViewer.image().height() |
85 |
item = imageViewer.scene.itemAt(QPointF(int(scenePos.x()), int(scenePos.y())), QTransform()) |
|
86 |
if item is not None and item.boundingRect() != QRectF(0, 0, imageWidth, imageHeight): |
|
87 |
imageViewer.scene.removeItem(item) |
|
96 |
items = imageViewer.scene.items(QRectF(float(scenePos.x())-0.5, float(scenePos.y())-0.5, 1, 1)) # QPointF(float(scenePos.x()), float(scenePos.y())), QTransform() |
|
97 |
for item in items: |
|
98 |
if item is not None and item.boundingRect() != QRectF(0, 0, imageWidth, imageHeight) and type(item) is QGraphicsEllipseItem: |
|
99 |
color = item.brush().color().name() |
|
100 |
if color.upper() == '#FF0000' and item.boundingRect().center() == scenePos: |
|
101 |
imageViewer.scene.removeItem(item) |
|
88 | 102 |
|
89 | 103 |
''' |
90 | 104 |
@history 2018.06.11 Jeongwoo Make area bigger (width/height 1px) |
105 |
2018.06.12 Jeongwoo Make area smaller (width/height 1px) |
|
91 | 106 |
''' |
92 | 107 |
def isOnImage(self, x, y): |
93 | 108 |
if (x >= 0 and x <= self.imageWidth + 1) and (y >= 0 and y <= self.imageHeight + 1): |
DTI_PID/DTI_PID/QSymbolEditorDialog.py | ||
---|---|---|
1 | 1 |
# coding: utf-8 |
2 | 2 |
from PyQt5 import QtCore, QtGui, QtWidgets |
3 |
from PyQt5.QtCore import pyqtSlot |
|
3 |
from PyQt5.QtCore import pyqtSlot, QRectF
|
|
4 | 4 |
from PyQt5.QtWidgets import * |
5 | 5 |
from PyQt5.QtGui import * |
6 | 6 |
from QtImageViewer import QtImageViewer |
... | ... | |
261 | 261 |
|
262 | 262 |
''' |
263 | 263 |
@brief remove each ConnectionPoint Circle |
264 |
@history 2018.06.12 Jeongwoo Add conditions for selecting ellipse item |
|
264 | 265 |
''' |
265 | 266 |
def removeConnectionPointCircle(self, circlePoint): |
266 |
self.ui.imageView.scene.removeItem(self.ui.imageView.scene.itemAt(QtCore.QPointF(int(circlePoint.x()), int(circlePoint.y())), QTransform())) |
|
267 |
imageWidth = self.ui.imageView.image().width() |
|
268 |
imageHeight = self.ui.imageView.image().height() |
|
269 |
items = self.ui.imageView.scene.items(QRectF(float(circlePoint.x())-0.5, float(circlePoint.y())-0.5, 1, 1)) |
|
270 |
for item in items: |
|
271 |
if item is not None and item.boundingRect() != QRectF(0, 0, imageWidth, imageHeight) and type(item) is QGraphicsEllipseItem: |
|
272 |
color = item.brush().color().name() |
|
273 |
if color.upper() == '#0000FF' and item.boundingRect().center() == circlePoint: |
|
274 |
self.ui.imageView.scene.removeItem(item) |
|
267 | 275 |
|
268 | 276 |
''' |
269 | 277 |
@brief Display this QDialog |
... | ... | |
455 | 463 |
|
456 | 464 |
AppDocData.instance().updateSymbol(self.selectedSymbol) |
457 | 465 |
|
466 |
''' |
|
467 |
@history 2018.06.12 Jeongwoo coords type changed (int → float) |
|
468 |
''' |
|
458 | 469 |
def keyPressEvent(self, event): |
459 | 470 |
if event.key() == QtCore.Qt.Key_Delete: |
460 | 471 |
if self.ui.connectionPointList.hasFocus(): |
... | ... | |
462 | 473 |
if selectedItems is not None: |
463 | 474 |
for item in selectedItems: |
464 | 475 |
text = item.text() |
465 |
x = int(text.split(",")[0])
|
|
466 |
y = int(text.split(",")[1])
|
|
476 |
x = float(text.split(",")[0])
|
|
477 |
y = float(text.split(",")[1])
|
|
467 | 478 |
self.removeConnectionPointCircle(QtCore.QPointF(x, y)) |
468 | 479 |
self.ui.connectionPointList.takeItem(self.ui.connectionPointList.row(item)) |
469 | 480 |
elif self.ui.additionalSymbolListWidget.hasFocus(): |
... | ... | |
685 | 696 |
def adjustOriginalPoint(self, adjustX, adjustY): |
686 | 697 |
originalPoint = self.ui.originalPointLineEdit.text() |
687 | 698 |
if originalPoint and self.ui.imageView.isOriginalPointSelected: |
688 |
x = int(originalPoint.split(",")[0])
|
|
689 |
y = int(originalPoint.split(",")[1])
|
|
699 |
x = float(originalPoint.split(",")[0])
|
|
700 |
y = float(originalPoint.split(",")[1])
|
|
690 | 701 |
OriginalPointCommand.OriginalPointCommand.removeCircle(self.ui.imageView, x, y) |
691 | 702 |
x = x - adjustX |
692 | 703 |
y = y - adjustY |
... | ... | |
698 | 709 |
for index in range(itemCount): |
699 | 710 |
item = self.ui.connectionPointList.item(index) |
700 | 711 |
text = item.text() |
701 |
x = int(text.split(",")[0])
|
|
702 |
y = int(text.split(",")[1])
|
|
712 |
x = float(text.split(",")[0])
|
|
713 |
y = float(text.split(",")[1])
|
|
703 | 714 |
self.removeConnectionPointCircle(QtCore.QPointF(x, y)) |
704 | 715 |
x = x - adjustX |
705 | 716 |
y = y - adjustY |
내보내기 Unified diff