개정판 56332ce8
issue #1362: add a function to place dimension - revised2
Change-Id: Ic009f02863f2216922f5f91314a802a523d19252
HYTOS/HYTOS/AppDocData.py | ||
---|---|---|
844 | 844 |
"values(?,?,?,?,?)" |
845 | 845 |
param = ('c288afbb-2612-4b8e-9932-2a84815cfa4e', 'Callout', 'Callout', |
846 | 846 |
'8502d693-2e13-422f-b81a-67edf19dc07d', '0,0,0,0') |
847 |
|
|
848 |
sql = "insert or replace into Symbols(UID,Name,Display_Name,SymbolType_UID,OriginalPoint) " \ |
|
849 |
"values(?,?,?,?,?)" |
|
850 |
param = ('22384e9d-74d7-4639-b500-73ac6285ff8a', 'Dimension', 'Dimension', |
|
851 |
'8502d693-2e13-422f-b81a-67edf19dc07d', '0,0,0,0') |
|
847 | 852 |
cursor.execute(sql, param) |
848 | 853 |
|
849 | 854 |
conn.commit() |
HYTOS/HYTOS/MainWindow.py | ||
---|---|---|
703 | 703 |
from SymbolSvgItem import SymbolSvgItem |
704 | 704 |
from EngineeringStreamlineItem import QEngineeringStreamlineItem |
705 | 705 |
from EngineeringCalloutTextItem import QEngineeringCalloutTextItem |
706 |
from EngineeringDimensionItem import QEngineeringDimensionItem |
|
706 | 707 |
|
707 | 708 |
try: |
708 | 709 |
app_doc_data = AppDocData.instance() |
... | ... | |
713 | 714 |
|
714 | 715 |
app_doc_data.saveToDatabase([item for item in items |
715 | 716 |
if type(item) is SymbolSvgItem or type(item) is QEngineeringStreamlineItem or |
716 |
type(item) is QEngineeringCalloutTextItem], |
|
717 |
type(item) is QEngineeringCalloutTextItem or type(item) is QEngineeringDimensionItem],
|
|
717 | 718 |
self.progress.setValue) |
718 | 719 |
|
719 | 720 |
if app_doc_data.activeDrawing: |
... | ... | |
2574 | 2575 |
def load_components(self, componentsUID): |
2575 | 2576 |
from EngineeringStreamlineItem import QEngineeringStreamlineItem |
2576 | 2577 |
from EngineeringCalloutTextItem import QEngineeringCalloutTextItem |
2578 |
from EngineeringDimensionItem import QEngineeringDimensionItem |
|
2577 | 2579 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
2578 | 2580 |
|
2579 | 2581 |
try: |
... | ... | |
2600 | 2602 |
item.lost_focus.connect(self.editor_lost_focus) |
2601 | 2603 |
item.selected_change.connect(self.item_selected) |
2602 | 2604 |
self.graphicsView.scene.addItem(item) |
2605 |
elif symbol_name == 'Dimension': |
|
2606 |
item = QEngineeringDimensionItem.fromDatabase(componentInfos) |
|
2607 |
if item: |
|
2608 |
item.transfer.onRemoved.connect(self.on_item_removed) |
|
2609 |
self.graphicsView.scene.addItem(item) |
|
2603 | 2610 |
else: |
2604 | 2611 |
item = SymbolSvgItem.fromDatabase(componentInfos) |
2605 | 2612 |
if item is not None: |
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