개정판 a54e42e4
Modified method to insert item to result tree
DTI_PID/DTI_PID/App.py | ||
---|---|---|
155 | 155 |
self.resultTreeWidget.setCurrentPID(baseName) |
156 | 156 |
|
157 | 157 |
# DEBUG |
158 |
''' |
|
158 | 159 |
if __debug__: |
159 | 160 |
from LineDetector import LineDetector |
160 | 161 |
from LineNoTracer import LineNoTracer |
... | ... | |
222 | 223 |
for text in docData.lineNos: |
223 | 224 |
item = self.resultTreeWidget.addTreeItem(self.resultTreeWidget.root, text) |
224 | 225 |
|
225 |
# iterate connected items |
|
226 |
pool = [] |
|
227 |
visited = [] |
|
228 |
pool.append(text.conns[0]) |
|
229 |
while len(pool) > 0: |
|
230 |
it = pool.pop() |
|
231 |
if type(it) is SymbolSvgItem: self.resultTreeWidget.addTreeItem(item, it) |
|
232 |
visited.append(it) |
|
233 |
for conn in it.conns: |
|
234 |
if (conn is not None) and (conn not in visited): pool.append(conn) |
|
235 |
# up to here |
|
226 |
if 1 == len(text.conns): |
|
227 |
# iterate connected items |
|
228 |
pool = [] |
|
229 |
visited = [] |
|
230 |
pool.append(text.conns[0]) |
|
231 |
while len(pool) > 0: |
|
232 |
it = pool.pop() |
|
233 |
if type(it) is SymbolSvgItem: self.resultTreeWidget.addTreeItem(item, it) |
|
234 |
visited.append(it) |
|
235 |
for conn in it.conns: |
|
236 |
if (conn is not None) and (conn not in visited): pool.append(conn) |
|
237 |
# up to here |
|
236 | 238 |
|
237 | 239 |
# up to here |
238 | 240 |
# up to here |
241 |
''' |
|
239 | 242 |
except Exception as ex: |
240 | 243 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
241 | 244 |
|
... | ... | |
357 | 360 |
for text in docData.lineNos: |
358 | 361 |
item = self.resultTreeWidget.addTreeItem(self.resultTreeWidget.root, text) |
359 | 362 |
|
360 |
# iterate connected items
|
|
361 |
pool = []
|
|
362 |
visited = []
|
|
363 |
pool.append(text.conns[0])
|
|
364 |
while len(pool) > 0:
|
|
365 |
it = pool.pop()
|
|
366 |
if type(it) is SymbolSvgItem: self.resultTreeWidget.addTreeItem(item, it)
|
|
367 |
visited.append(it)
|
|
368 |
for conn in it.conns:
|
|
369 |
if (conn is not None) and (conn not in visited): pool.append(conn)
|
|
370 |
# up to here
|
|
371 |
|
|
363 |
if 1 == len(text.conns):
|
|
364 |
# iterate connected items
|
|
365 |
pool = []
|
|
366 |
visited = []
|
|
367 |
pool.append(text.conns[0])
|
|
368 |
while len(pool) > 0:
|
|
369 |
it = pool.pop()
|
|
370 |
if type(it) is SymbolSvgItem: self.resultTreeWidget.addTreeItem(item, it)
|
|
371 |
visited.append(it)
|
|
372 |
for conn in it.conns:
|
|
373 |
if (conn is not None) and (conn not in visited): pool.append(conn)
|
|
374 |
# up to here |
|
372 | 375 |
# up to here |
373 | 376 |
except Exception as ex: |
374 | 377 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
... | ... | |
443 | 446 |
angle = float(text.find('ANGLE').text) if text.find('ANGLE') is not None else 0 |
444 | 447 |
text = text.find('TEXT').text |
445 | 448 |
item = QEngineeringTextItem() |
449 |
item.loc = (x, y) |
|
450 |
item.size = (width, height) |
|
446 | 451 |
item.setPlainText(text) |
447 | 452 |
item.setDefaultTextColor(Qt.blue) |
448 | 453 |
sx = 1 |
DTI_PID/DTI_PID/QDirTreeWidget.py | ||
---|---|---|
126 | 126 |
|
127 | 127 |
def loadDirectoryInfo(self, startPath, tree): |
128 | 128 |
for element in os.listdir(startPath): |
129 |
pathInfo = startPath + "/" + element
|
|
129 |
pathInfo = os.path.join(startPath, element)
|
|
130 | 130 |
parentItem = QTreeWidgetItem(tree, [os.path.basename(element)]) |
131 | 131 |
if pathInfo.endswith(".png"): |
132 |
#svgPath = pathInfo.replace("/image/", "/svg/") |
|
133 |
#svgPath = svgPath.replace(".png", ".svg") |
|
134 |
#icon = QIcon(svgPath) |
|
135 | 132 |
icon = QIcon(pathInfo) |
136 |
#icon.actualSize(QSize(32, 32)) |
|
137 |
#parentItem.setSizeHint(0, QSize(32, 32)) |
|
138 | 133 |
parentItem.setIcon(0, icon) |
139 | 134 |
parentItem.svgFilePath = pathInfo # save svg file path |
140 | 135 |
if os.path.isdir(pathInfo): |
DTI_PID/DTI_PID/QResultTreeWidget.py | ||
---|---|---|
25 | 25 |
self.imageViewer = imageViewer |
26 | 26 |
self.scene = imageViewer.scene |
27 | 27 |
self.root = None |
28 |
self.sceneItems = [] |
|
29 | 28 |
|
30 | 29 |
''' |
31 | 30 |
@brief Clear TreeWidget and Set Current PID |
... | ... | |
44 | 43 |
''' |
45 | 44 |
def addTreeItem(self, parent, child): |
46 | 45 |
item = None |
47 |
if type(child) is SymbolSvgItem:
|
|
48 |
if child not in self.sceneItems:
|
|
46 |
if (not hasattr(child, 'treeItem')) or (child.treeItem is None):
|
|
47 |
if type(child) is SymbolSvgItem:
|
|
49 | 48 |
item = QTreeWidgetItem(parent, [child.name]) |
50 |
iconPath = AppDocData.instance().getCurrentProject().getSvgFilePath() + "/" + child.type + "/" + child.name + ".svg"
|
|
49 |
iconPath = os.path.join(AppDocData.instance().getCurrentProject().getSvgFilePath(), child.type , child.name + ".svg")
|
|
51 | 50 |
item.setIcon(0, QIcon(iconPath)) |
52 | 51 |
item.setData(0, self.TREE_DATA_ROLE, child) |
53 |
self.sceneItems.append(item) |
|
54 |
elif type(child) is QEngineeringTextItem: |
|
55 |
item = QTreeWidgetItem(parent, [child.text()]) |
|
56 |
item.setFlags(item.flags() | Qt.ItemIsUserCheckable) |
|
57 |
item.setData(0, self.TREE_DATA_ROLE, child) |
|
58 |
item.setCheckState(0, Qt.Unchecked) |
|
52 |
child.treeItem = item |
|
53 |
elif type(child) is QEngineeringTextItem: |
|
54 |
item = QTreeWidgetItem(parent, [child.text()]) |
|
55 |
item.setFlags(item.flags() | Qt.ItemIsUserCheckable) |
|
56 |
item.setData(0, self.TREE_DATA_ROLE, child) |
|
57 |
item.setCheckState(0, Qt.Unchecked) |
|
58 |
child.treeItem = item |
|
59 | 59 |
|
60 | 60 |
return item |
61 | 61 |
|
... | ... | |
67 | 67 |
''' |
68 | 68 |
lastSceneItems = None |
69 | 69 |
def sceneChanged(self, sceneItems): |
70 |
changedSceneItems = [item for item in sceneItems if type(item) is SymbolSvgItem] # Sublist includes SymbolSvgItem |
|
71 |
print("Total Svg Item count : " + str(len(changedSceneItems))) |
|
72 |
if self.sceneItems != changedSceneItems: |
|
73 |
self.initResultTreeWidget(changedSceneItems) |
|
70 |
changedSceneItems = [item for item in sceneItems if (type(item) is SymbolSvgItem) and (not hasattr(item, 'treeItem') or item.treeItem is None)] # Sublist includes SymbolSvgItem |
|
71 |
self.initResultTreeWidget(changedSceneItems) |
|
74 | 72 |
|
75 | 73 |
''' |
76 | 74 |
@brief Initialize TreeWidget |
... | ... | |
81 | 79 |
@history 2018.04.17 humkyung NOT remove child of root |
82 | 80 |
''' |
83 | 81 |
def initResultTreeWidget(self, items): |
84 |
print("initResultTree") |
|
85 | 82 |
for item in items: |
86 | 83 |
if (type(item) is SymbolSvgItem): |
87 |
if item not in self.sceneItems: |
|
88 |
newItem = QTreeWidgetItem([item.name]) |
|
89 |
iconPath = AppDocData.instance().getCurrentProject().getSvgFilePath() + "/" + item.type + "/" + item.name + ".svg" |
|
90 |
newItem.setIcon(0, QIcon(iconPath)) |
|
91 |
newItem.setData(0, self.TREE_DATA_ROLE, item) |
|
92 |
if self.root is not None: |
|
93 |
self.root.addChild(newItem) |
|
94 |
self.sceneItems.append(item) |
|
95 |
#self.expandAll() |
|
84 |
newItem = QTreeWidgetItem([item.name]) |
|
85 |
iconPath = AppDocData.instance().getCurrentProject().getSvgFilePath() + "/" + item.type + "/" + item.name + ".svg" |
|
86 |
newItem.setIcon(0, QIcon(iconPath)) |
|
87 |
newItem.setData(0, self.TREE_DATA_ROLE, item) |
|
88 |
item.treeItem = newItem |
|
89 |
if self.root is not None: |
|
90 |
self.root.addChild(newItem) |
|
91 |
self.expandAll() |
|
96 | 92 |
|
97 | 93 |
''' |
98 | 94 |
@brief TreeWidget Item click listener |
DTI_PID/DTI_PID/Shapes/QEngineeringLineItem.py | ||
---|---|---|
84 | 84 |
line = LineString([(startPt[0], startPt[1]), (endPt[0], endPt[1])]) |
85 | 85 |
dist = line.distance(Point(pt[0], pt[1])) |
86 | 86 |
|
87 |
''' |
|
88 |
vec1 = [endPt[0]-startPt[0], endPt[1]-startPt[1]] |
|
89 |
length = math.sqrt(vec1[0]*vec1[0] + vec1[1]*vec1[1]) |
|
90 |
vec1[0] /= length |
|
91 |
vec1[1] /= length |
|
92 |
vec2 = [pt[0]-startPt[0], pt[1]-startPt[1]] |
|
93 |
dot = self.dotProduct(vec1, vec2) |
|
94 |
tmp = [startPt[0] + dot*vec1[0], startPt[1] + dot*vec1[1]] |
|
95 |
dist = Point(tmp[0], tmp[1]).distance(Point(pt[0], pt[1])) |
|
96 |
''' |
|
97 |
|
|
98 | 87 |
return dist |
99 | 88 |
|
100 | 89 |
''' |
내보내기 Unified diff