개정판 56332ce8
issue #1362: add a function to place dimension - revised2
Change-Id: Ic009f02863f2216922f5f91314a802a523d19252
HYTOS/HYTOS/Shapes/EngineeringDimensionItem.py | ||
---|---|---|
67 | 67 |
def create_path(self, pts): |
68 | 68 |
"""create a path""" |
69 | 69 |
import math |
70 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
71 | 70 |
|
72 |
#self.resetTransform() |
|
73 | 71 |
path = QPainterPath() |
74 | 72 |
if pts: |
75 | 73 |
if 1 == len(pts): |
76 | 74 |
pts.append(QPointF(pts[0].x() + 10, pts[0].y() + 10)) |
77 | 75 |
|
76 |
# draw dimension line |
|
78 | 77 |
path.moveTo(pts[0]) |
79 | 78 |
path.lineTo(pts[1]) |
79 |
# up to here |
|
80 | 80 |
|
81 | 81 |
dx = pts[1].x() - pts[0].x() |
82 | 82 |
dy = pts[1].y() - pts[0].y() |
... | ... | |
87 | 87 |
arrow_size = QEngineeringDimensionItem.ARROW_SIZE * 0.25 |
88 | 88 |
|
89 | 89 |
perpendicular = (-_dir[1], _dir[0]) |
90 |
# right arrow |
|
90 | 91 |
polygon = QPolygonF() |
91 | 92 |
polygon.append(QPointF( |
92 | 93 |
pts[1].x() - _dir[0] * QEngineeringDimensionItem.ARROW_SIZE + perpendicular[0] * arrow_size, |
... | ... | |
98 | 99 |
polygon.append(polygon[0]) |
99 | 100 |
|
100 | 101 |
path.addPolygon(polygon) |
102 |
# up to here |
|
101 | 103 |
|
104 |
# left arrow |
|
102 | 105 |
polygon = QPolygonF() |
103 | 106 |
polygon.append(QPointF( |
104 | 107 |
pts[0].x() + _dir[0] * QEngineeringDimensionItem.ARROW_SIZE + perpendicular[0] * arrow_size, |
... | ... | |
109 | 112 |
polygon.append(pts[0]) |
110 | 113 |
polygon.append(polygon[0]) |
111 | 114 |
|
115 |
path.addPolygon(polygon) |
|
116 |
# up to here |
|
117 |
|
|
112 | 118 |
path.moveTo(pts[0].x() - perpendicular[0]*5, pts[0].y() - perpendicular[1]*5) |
113 | 119 |
path.lineTo(pts[0].x() + perpendicular[0]*QEngineeringDimensionItem.DIMENSION_DEPTH, |
114 | 120 |
pts[0].y() + perpendicular[1]*QEngineeringDimensionItem.DIMENSION_DEPTH) |
... | ... | |
117 | 123 |
path.lineTo(pts[1].x() + perpendicular[0] * QEngineeringDimensionItem.DIMENSION_DEPTH, |
118 | 124 |
pts[1].y() + perpendicular[1] * QEngineeringDimensionItem.DIMENSION_DEPTH) |
119 | 125 |
|
120 |
path.addPolygon(polygon) |
|
121 |
|
|
122 |
path.addEllipse(pts[0], 4, 4) |
|
123 |
path.addEllipse(pts[1], 4, 4) |
|
124 |
|
|
125 |
""" |
|
126 |
if not self.connectors: |
|
127 |
conn = QEngineeringConnectorItem(uid=None, parent=self, index=0) |
|
128 |
conn.setFlags( |
|
129 |
QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable) |
|
130 |
conn.transfer.onPosChanged.connect(self.on_connector_pos_changed) |
|
131 |
self.connectors.append(conn) |
|
132 |
conn = QEngineeringConnectorItem(uid=None, parent=self, index=1) |
|
133 |
conn.setFlags( |
|
134 |
QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable) |
|
135 |
conn.transfer.onPosChanged.connect(self.on_connector_pos_changed) |
|
136 |
self.connectors.append(conn) |
|
137 |
|
|
138 |
self.connectors[0].setPos((self._pts[0].x(), self._pts[0].y())) |
|
139 |
self.connectors[1].setPos((self._pts[1].x(), self._pts[1].y())) |
|
140 |
""" |
|
126 |
path.addEllipse(pts[0], 2, 2) |
|
127 |
path.addEllipse(pts[1], 2, 2) |
|
141 | 128 |
|
142 | 129 |
return path |
143 | 130 |
|
... | ... | |
204 | 191 |
"""reshape dimension""" |
205 | 192 |
|
206 | 193 |
if event.buttons() == Qt.LeftButton and (self._selected_idx == 0 or self._selected_idx == 1): |
207 |
path = self.mapToScene(self.path()) |
|
194 |
path = self.path() # self.mapToScene(self.path())
|
|
208 | 195 |
pts = [QPointF(path.elementAt(0).x, path.elementAt(0).y), QPointF(path.elementAt(1).x, path.elementAt(1).y)] |
209 |
pts[self._selected_idx] = event.scenePos() |
|
196 |
pts[self._selected_idx] = event.pos() |
|
197 |
|
|
198 |
# try to align to x or y axis |
|
199 |
toler = 10 |
|
200 |
dx, dy = abs(pts[1].x() - pts[0].x()), abs(pts[1].y() - pts[0].y()) |
|
201 |
if dx < toler: |
|
202 |
pts[self._selected_idx].setX(pts[(self._selected_idx + 1) % 2].x()) |
|
203 |
elif dy < toler: |
|
204 |
pts[self._selected_idx].setY(pts[(self._selected_idx + 1) % 2].y()) |
|
205 |
# up to here |
|
206 |
|
|
210 | 207 |
self.setPath(self.create_path(pts)) |
211 | 208 |
return |
212 | 209 |
|
... | ... | |
219 | 216 |
def itemChange(self, change, value): |
220 | 217 |
if change == QGraphicsItem.ItemSelectedChange: |
221 | 218 |
pass |
219 |
elif change == QGraphicsItem.ItemPositionHasChanged: |
|
220 |
pass |
|
222 | 221 |
return value |
223 | 222 |
|
224 | 223 |
def setColor(self, color): |
... | ... | |
240 | 239 |
_type = componentInfos[0]['Type'] # Type@SymbolType |
241 | 240 |
name = componentInfos[0]['Symbol_Name'] # Name@Symbols |
242 | 241 |
originalPoint = componentInfos[0]['OriginalPoint'] # OriginalPoint@Symbols |
243 |
x = componentInfos[0]['Comp_X'] # X@Components |
|
244 |
y = componentInfos[0]['Comp_Y'] # Y@Components |
|
242 |
start_x = componentInfos[0]['Comp_X'] # X@Components
|
|
243 |
start_y = componentInfos[0]['Comp_Y'] # Y@Components
|
|
245 | 244 |
angle = componentInfos[0]['Rotation'] # Rotation@Components |
246 | 245 |
scale = componentInfos[0]['Scale'] # Scale@Components |
246 |
end_x, end_y = componentInfos[0]['X'], componentInfos[0]['Y'] |
|
247 | 247 |
|
248 |
pt = QPointF(float(x), float(y))
|
|
249 |
item = PlaceDimensionCommand.create_item(pt) |
|
248 |
pts = [QPointF(float(start_x), float(start_y)), QPointF(float(end_x), float(end_y))]
|
|
249 |
item = PlaceDimensionCommand.create_item(pts)
|
|
250 | 250 |
except Exception as ex: |
251 | 251 |
from App import App |
252 | 252 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
... | ... | |
264 | 264 |
|
265 | 265 |
try: |
266 | 266 |
cols = ['UID', 'Symbols_UID', 'Name', 'X', 'Y'] |
267 |
values = ['?', "(select uid from Symbols where Name='Callout')", '?', '?', '?'] |
|
267 |
values = ['?', "(select uid from Symbols where Name='Dimension')", '?', '?', '?'] |
|
268 |
|
|
269 |
path = self.mapToScene(self.path()) |
|
270 |
pts = [QPointF(path.elementAt(0).x, path.elementAt(0).y), QPointF(path.elementAt(1).x, path.elementAt(1).y)] |
|
268 | 271 |
|
269 |
param = [str(self.uid), self.toHtml(), self.pos().x(), self.pos().y()]
|
|
272 |
param = [str(self.uid), self.type, pts[0].x(), pts[0].y()]
|
|
270 | 273 |
sql = f"insert or replace into Components({','.join(cols)}) values({','.join(values)})" |
271 | 274 |
res.append((sql, tuple(param))) |
272 | 275 |
|
273 | 276 |
cols, values = ['UID', 'Components_UID', '[Index]', 'X', 'Y'], ['?', '?', '?', '?', '?'] |
274 |
param = [str(self.uid), str(self.uid), 0, self.pos().x(), self.pos().y()]
|
|
277 |
param = [str(self.uid), str(self.uid), 0, pts[1].x(), pts[1].y()]
|
|
275 | 278 |
sql = 'insert or replace into Points({}) values({})'.format(','.join(cols), ','.join(values)) |
276 | 279 |
res.append((sql, tuple(param))) |
277 |
|
|
278 | 280 |
except Exception as ex: |
279 | 281 |
from App import App |
280 | 282 |
from AppDocData import MessageType |
내보내기 Unified diff