76 |
76 |
|
77 |
77 |
self.dbUid = None
|
78 |
78 |
self.uid = uuid.uuid4() if uid is None else uuid.UUID(uid, version=4)
|
79 |
|
# self.setElementId(str(self.uid))
|
80 |
79 |
self.name = ''
|
81 |
80 |
self.category = ''
|
82 |
81 |
self.type = ''
|
... | ... | |
89 |
88 |
self.parentSymbol = ''
|
90 |
89 |
self.childSymbol = ''
|
91 |
90 |
self.hasInstrumentLabel = 0
|
92 |
|
self.flip = flip
|
93 |
91 |
# attributeType uid
|
94 |
92 |
self.attribute = {}
|
95 |
|
self._properties = {SymbolProp(None, 'Supplied By', 'String'): None}
|
96 |
93 |
self._tag_no = None
|
|
94 |
self._selected_idx = None
|
97 |
95 |
self.setAcceptDrops(True)
|
98 |
96 |
self.setAcceptHoverEvents(True)
|
99 |
97 |
self.setAcceptedMouseButtons(Qt.LeftButton)
|
... | ... | |
167 |
165 |
self._color = self.DEFAULT_COLOR
|
168 |
166 |
self.setColor(self._color)
|
169 |
167 |
|
170 |
|
@property
|
171 |
|
def properties(self):
|
172 |
|
""" getter of properties """
|
173 |
|
import uuid
|
174 |
|
|
175 |
|
for prop, value in self._properties.items():
|
176 |
|
try:
|
177 |
|
if prop.is_selectable and type(value) is uuid.UUID and self.scene():
|
178 |
|
matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(value)]
|
179 |
|
if matches: self._properties[prop] = matches[0]
|
180 |
|
|
181 |
|
if prop.Expression:
|
182 |
|
item = self._properties[prop] # assign item
|
183 |
|
self._properties[prop] = eval(prop.Expression)
|
184 |
|
except Exception as ex:
|
185 |
|
from App import App
|
186 |
|
|
187 |
|
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
188 |
|
sys.exc_info()[-1].tb_lineno)
|
189 |
|
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
190 |
|
|
191 |
|
return self._properties
|
192 |
|
|
193 |
|
@properties.setter
|
194 |
|
def properties(self, value):
|
195 |
|
""" setter of properties """
|
196 |
|
self._properties = value
|
197 |
|
|
198 |
|
def set_property(self, property, value):
|
199 |
|
""" set property with given value """
|
200 |
|
if issubclass(type(value), QEngineeringAbstractItem): self.add_assoc_item(value, 0)
|
201 |
|
matches = [prop for prop, _ in self._properties.items() if prop.Attribute == property]
|
202 |
|
if matches: self._properties[matches[0]] = value
|
203 |
|
|
204 |
|
def prop(self, name):
|
205 |
|
""" return the value of given property with name """
|
206 |
|
matches = [(prop, value) for prop, value in self.properties.items() if prop.Attribute == name]
|
207 |
|
if matches: return matches[0][1]
|
208 |
|
|
209 |
|
return None
|
210 |
|
|
211 |
168 |
def validate(self):
|
212 |
169 |
"""validate symbol data"""
|
213 |
170 |
|
... | ... | |
220 |
177 |
|
221 |
178 |
return res
|
222 |
179 |
|
223 |
|
def includes(self, pt, margin=0):
|
224 |
|
""" return True if symbol contains given point else return False """
|
|
180 |
@property
|
|
181 |
def corners(self):
|
225 |
182 |
rect = self.sceneBoundingRect()
|
226 |
|
allowed_error = 0.1
|
227 |
|
|
228 |
|
if abs(rect.x() - 0) <= allowed_error and abs(rect.y() - 0) <= allowed_error:
|
229 |
|
# when first recognition step, symbols are not in scene(not yet added) therefore cannot use scenebounding rect
|
230 |
|
minX = self.loc[0] - margin
|
231 |
|
minY = self.loc[1] - margin
|
232 |
|
maxX = minX + self.size[0] + margin
|
233 |
|
maxY = minY + self.size[1] + margin
|
234 |
|
else:
|
235 |
|
minX = rect.x() - margin
|
236 |
|
minY = rect.y() - margin
|
237 |
|
maxX = minX + rect.width() + margin
|
238 |
|
maxY = minY + rect.height() + margin
|
|
183 |
return [rect.topLeft(), rect.bottomLeft(), rect.bottomRight(), rect.topRight()]
|
|
184 |
|
|
185 |
def resize(self, change):
|
|
186 |
""" resize item """
|
|
187 |
try:
|
|
188 |
rect = self.boundingRect()
|
|
189 |
if rect.isValid():
|
|
190 |
self.resetTransform()
|
|
191 |
self.setPos(change.topLeft())
|
|
192 |
scale = min([change.width() / rect.width(), change.height() / rect.height()])
|
|
193 |
# scale the item
|
|
194 |
self.setScale(scale)
|
|
195 |
|
|
196 |
# scale down for label
|
|
197 |
for conn, label in self.desc_labels.items():
|
|
198 |
label.setScale(1/scale)
|
|
199 |
# up to here
|
239 |
200 |
|
240 |
|
return True if (pt[0] >= minX and pt[0] <= maxX and pt[1] >= minY and pt[1] <= maxY) else False
|
|
201 |
self.prepareGeometryChange()
|
|
202 |
self.update()
|
|
203 |
except Exception as ex:
|
|
204 |
from App import App
|
|
205 |
|
|
206 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
207 |
sys.exc_info()[-1].tb_lineno)
|
|
208 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
241 |
209 |
|
242 |
210 |
def toSql(self):
|
243 |
211 |
import uuid
|
... | ... | |
1282 |
1250 |
def center(self):
|
1283 |
1251 |
return self.sceneBoundingRect().center()
|
1284 |
1252 |
|
1285 |
|
'''
|
1286 |
|
@brief highlight connector and attribute
|
1287 |
|
@authro humkyung
|
1288 |
|
@date 2018.05.02
|
1289 |
|
'''
|
1290 |
|
|
1291 |
1253 |
def hoverEnterEvent(self, event):
|
1292 |
|
from Resizer import Resizer
|
1293 |
|
|
1294 |
1254 |
self.highlight(True)
|
1295 |
1255 |
|
1296 |
|
''' 잠시 주석 처리
|
1297 |
|
""" create a resizer """
|
1298 |
|
resizer = Resizer.instance()
|
1299 |
|
resizer.connected = self
|
1300 |
|
resizerWidth = resizer.rect.width() / 2
|
1301 |
|
rect = self.sceneBoundingRect()
|
1302 |
|
resizerOffset = QPointF(resizerWidth, resizerWidth)
|
1303 |
|
resizer.setPos(rect.bottomRight() - resizerOffset)
|
1304 |
|
if resizer.receivers(resizer.resizeSignal) > 0: resizer.resizeSignal.disconnect()
|
1305 |
|
resizer.resizeSignal.connect(self.resize)
|
1306 |
|
try:
|
1307 |
|
self.transfer.on_pos_changed.disconnect(resizer.on_symbol_pos_changed)
|
1308 |
|
except Exception as ex:
|
1309 |
|
pass
|
1310 |
|
self.transfer.on_pos_changed.connect(resizer.on_symbol_pos_changed)
|
1311 |
|
resizer.setVisible(True)
|
1312 |
|
if not resizer.scene(): self.scene().addItem(resizer)
|
1313 |
|
'''
|
1314 |
|
|
1315 |
1256 |
'''
|
1316 |
1257 |
@brief unhighlight connector and attribute
|
1317 |
1258 |
@author humkyung
|
... | ... | |
1364 |
1305 |
def hoverMoveEvent(self, event):
|
1365 |
1306 |
pass
|
1366 |
1307 |
|
1367 |
|
'''
|
1368 |
|
@brief Mouse Press Event
|
1369 |
|
@author Jeongwoo
|
1370 |
|
@date 18.04.11
|
1371 |
|
@history kyouho 2018.07.18 add isClick logic
|
1372 |
|
'''
|
1373 |
|
|
1374 |
1308 |
def mousePressEvent(self, event):
|
|
1309 |
import math
|
|
1310 |
|
1375 |
1311 |
if event.buttons() == Qt.LeftButton:
|
1376 |
|
self.clicked.emit(self)
|
|
1312 |
toler = 10
|
|
1313 |
|
|
1314 |
# try to select corner
|
|
1315 |
self._selected_idx = None
|
|
1316 |
pos = event.scenePos()
|
|
1317 |
for idx, corner in enumerate(self.corners):
|
|
1318 |
dx = corner.x() - pos.x()
|
|
1319 |
dy = corner.y() - pos.y()
|
|
1320 |
if math.sqrt(dx * dx + dy * dy) < toler:
|
|
1321 |
self._selected_idx = idx
|
|
1322 |
break
|
|
1323 |
# up to here
|
1377 |
1324 |
|
1378 |
|
'''
|
1379 |
|
@brief call on_pos_changed signal
|
1380 |
|
@author humkyung
|
1381 |
|
@date 19.07.17
|
1382 |
|
'''
|
|
1325 |
if self._selected_idx is None:
|
|
1326 |
self.clicked.emit(self)
|
|
1327 |
|
|
1328 |
#super(SymbolSvgItem, self).mousePressEvent(event)
|
|
1329 |
|
|
1330 |
def mouseMoveEvent(self, event):
|
|
1331 |
"""reshape dimension"""
|
|
1332 |
|
|
1333 |
if event.buttons() == Qt.LeftButton and self._selected_idx is not None:
|
|
1334 |
corners = [event.scenePos(), self.corners[(self._selected_idx + 2) % 4]]
|
|
1335 |
min_x, min_y = min(corners, key=lambda pt: pt.x()).x(), min(corners, key=lambda pt: pt.y()).y()
|
|
1336 |
max_x, max_y = max(corners, key=lambda pt: pt.x()).x(), max(corners, key=lambda pt: pt.y()).y()
|
|
1337 |
|
|
1338 |
self.resize(QRectF(min_x, min_y, max_x - min_x, max_y - min_y))
|
|
1339 |
return
|
|
1340 |
|
|
1341 |
super(SymbolSvgItem, self).mouseMoveEvent(event)
|
1383 |
1342 |
|
1384 |
1343 |
def mouseReleaseEvent(self, event):
|
1385 |
|
super().mouseReleaseEvent(event)
|
|
1344 |
self._selected_idx = None
|
|
1345 |
super(SymbolSvgItem, self).mouseReleaseEvent(event)
|
1386 |
1346 |
|
1387 |
1347 |
def itemChange(self, change, value):
|
1388 |
1348 |
""" call signals when item's position is changed """
|
... | ... | |
2068 |
2028 |
if self.isSelected():
|
2069 |
2029 |
self.draw_focus_rect(painter)
|
2070 |
2030 |
|
2071 |
|
'''
|
2072 |
|
@brief Add Svg Item into ImageViewer's Scene
|
2073 |
|
@author Jeongwoo
|
2074 |
|
@date 2018.05.03
|
2075 |
|
@history add connectors which's parent is symbol
|
2076 |
|
kyouho 2018.07.30 remove connectors logic
|
2077 |
|
'''
|
2078 |
|
|
2079 |
2031 |
def addSvgItemToScene(self, scene):
|
|
2032 |
"""add svg item to scene"""
|
2080 |
2033 |
transform = QTransform()
|
2081 |
2034 |
|
2082 |
2035 |
transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
|
... | ... | |
2107 |
2060 |
|
2108 |
2061 |
# set label
|
2109 |
2062 |
label = QEngineeringEqpDescTextItem('', self)
|
2110 |
|
#label.setVisible(False)
|
2111 |
2063 |
self.desc_labels[connector] = label
|
2112 |
2064 |
|
2113 |
2065 |
def deleteSvgItemFromScene(self):
|
... | ... | |
2127 |
2079 |
self.transfer.onRemoved.emit(self)
|
2128 |
2080 |
|
2129 |
2081 |
'''
|
2130 |
|
@brief Return real item position
|
2131 |
|
@author Jeongwoo
|
2132 |
|
@date 2018.05.25
|
2133 |
|
'''
|
2134 |
|
|
2135 |
|
def boundingRectOnScene(self):
|
2136 |
|
rect = self.boundingRect()
|
2137 |
|
rect.moveTo(self.loc[0], self.loc[1])
|
2138 |
|
return rect
|
2139 |
|
|
2140 |
|
'''
|
2141 |
2082 |
@brief get standard point
|
2142 |
2083 |
@author kyouho
|
2143 |
2084 |
@date 2018.07.25
|
... | ... | |
2173 |
2114 |
|
2174 |
2115 |
self.loc = [self.loc[0] + self.origin[0] - goPoint.x(), self.loc[1] + self.origin[1] - goPoint.y()]
|
2175 |
2116 |
|
2176 |
|
def resize(self, change):
|
2177 |
|
""" resize item """
|
2178 |
|
# Get the smaller side of the rect
|
2179 |
|
rect = self.sceneBoundingRect()
|
2180 |
|
loc = QPointF(rect.x(), rect.y())
|
2181 |
|
self.resetTransform()
|
2182 |
|
# self.setScale(1)
|
2183 |
|
rect = self.sceneBoundingRect()
|
2184 |
|
scale = [(change.width() - loc.x()) / rect.width(), (change.height() - loc.y()) / rect.height()]
|
2185 |
|
# scale the item
|
2186 |
|
if scale[0] > 0 and scale[1] > 0:
|
2187 |
|
self.setPos(loc)
|
2188 |
|
# self.setScale(scale[0] if scale[0] < scale[1] else scale[1])
|
2189 |
|
trans = QTransform()
|
2190 |
|
trans.scale(scale[0] if scale[0] < scale[1] else scale[1], scale[0] if scale[0] < scale[1] else scale[1])
|
2191 |
|
self.setTransform(trans)
|
2192 |
|
self.prepareGeometryChange()
|
2193 |
|
self.update()
|
2194 |
|
|
2195 |
|
self.transfer.on_size_changed.emit(self)
|
2196 |
|
|
2197 |
2117 |
def moveto(self, to, timeLine=5000, rotation=0):
|
2198 |
2118 |
"""Move the item from one position to one other."""
|
2199 |
2119 |
|