개정판 7a47a83c
dev issue #638: scene 좌표에 있는 아이템가져오는 에러로 인하여 로직 변경
DTI_PID/DTI_PID/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
124 | 124 |
@date 2018.07.27 |
125 | 125 |
''' |
126 | 126 |
def mouseReleaseEvent(self, event): |
127 |
import shapely |
|
128 |
if type(self.parent) is QEngineeringLineItem and self._savedPos is not None: |
|
129 |
#item = self.scene().itemAt(event.scenePos(), QTransform()) |
|
130 |
item = self.getItemsAtPoint(event.scenePos()) |
|
131 | ||
132 |
if item is not None and item is not self.parent and type(item) is QEngineeringLineItem: |
|
133 |
length = item.length()*0.5 |
|
134 |
dir = item.perpendicular() |
|
135 |
start = [event.scenePos().x() - dir[0]*length, event.scenePos().y() - dir[1]*length] |
|
136 |
end = [event.scenePos().x() + dir[0]*length, event.scenePos().y() + dir[1]*length] |
|
137 |
pt = item.intersection([start, end]) |
|
138 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
|
139 |
self.setPos((pt.x, pt.y)) |
|
140 |
self.connectedItem = item |
|
141 |
elif item is not None and type(item) is QEngineeringConnectorItem and item is not self: |
|
142 |
self.setPos(item.center()) |
|
143 |
|
|
144 |
if self.connectedItem is not None: |
|
145 |
for connect in self.connectedItem.connectors: |
|
146 |
if connect.connectedItem == self.parent: |
|
147 |
connect.connectedItem = None |
|
148 | ||
149 |
self.connectedItem = item.parent |
|
150 |
item.connectedItem = self.parent |
|
151 |
else: |
|
152 |
other = [connector for connector in self.parent.connectors if connector is not self] |
|
153 |
if other: |
|
154 |
pt = [event.scenePos().x(), event.scenePos().y()] |
|
155 |
dx = abs(pt[0] - other[0].center()[0]) |
|
156 |
dy = abs(pt[1] - other[0].center()[1]) |
|
157 |
if dx < dy: |
|
158 |
pt[0] = other[0].center()[0] |
|
159 |
else: |
|
160 |
pt[1] = other[0].center()[1] |
|
161 | ||
162 |
self.setPos(pt) |
|
163 |
if self.connectedItem is not None: |
|
164 |
for connect in self.connectedItem.connectors: |
|
165 |
if connect.connectedItem == self.parent: |
|
166 |
connect.connectedItem = None |
|
167 | ||
168 |
self.connectedItem = None |
|
169 | ||
170 | ||
127 | 171 |
if type(self.parent) is QEngineeringLineItem: |
128 | 172 |
self._savedPos = None |
129 | 173 |
self._savedConnectedItem = None |
... | ... | |
133 | 177 |
QGraphicsEllipseItem.mouseReleaseEvent(self, event) |
134 | 178 | |
135 | 179 |
''' |
180 |
@brief |
|
181 |
@author kyouho |
|
182 |
@date 2018.08.10 |
|
183 |
''' |
|
184 |
def getItemsAtPoint(self, scenePos): |
|
185 |
itemList = [] |
|
186 |
items = [item for item in self.scene().items() if (type(item) is QEngineeringLineItem or type(item) is QEngineeringConnectorItem)] |
|
187 |
for item in items: |
|
188 |
# Line 아이템만 (자기 자신의 부모 제외) |
|
189 |
if type(item) is QEngineeringLineItem and item is not self.parent and item.contains(scenePos): |
|
190 |
itemList.append(item) |
|
191 |
# connector의 부모가 라인이 아닌 것만 |
|
192 |
elif type(item) is QEngineeringConnectorItem and type(item.parent) is not QEngineeringLineItem: |
|
193 |
rect = item.sceneBoundingRect() |
|
194 |
if rect.contains(scenePos): |
|
195 |
itemList.append(item) |
|
196 |
#if True: |
|
197 |
# pass |
|
198 |
if len(itemList) > 0: |
|
199 |
return itemList[0] |
|
200 |
else: |
|
201 |
return None |
|
202 | ||
203 |
''' |
|
136 | 204 |
@brief move connector's position while mouse drag |
137 | 205 |
@author humkyung |
138 | 206 |
@date 2018.07.27 |
... | ... | |
151 | 219 |
pt = item.intersection([start, end]) |
152 | 220 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
153 | 221 |
self.setPos((pt.x, pt.y)) |
154 |
self.connectedItem = item |
|
155 | 222 |
elif item is not None and type(item) is QEngineeringConnectorItem: |
156 | 223 |
self.setPos(item.center()) |
157 |
self.connectedItem = item |
|
158 | 224 |
else: |
159 | 225 |
other = [connector for connector in self.parent.connectors if connector is not self] |
160 | 226 |
if other: |
... | ... | |
167 | 233 |
pt[1] = other[0].center()[1] |
168 | 234 | |
169 | 235 |
self.setPos(pt) |
170 |
self.connectedItem = None |
|
236 | ||
171 | 237 | |
172 | 238 |
self.update() |
173 | 239 |
내보내기 Unified diff