hytos / DTI_PID / DTI_PID / ReplaceSymbolDialog.py @ e1d8a5de
이력 | 보기 | 이력해설 | 다운로드 (4.38 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is text item edit dialog module """
|
3 |
|
4 |
import os |
5 |
import sys |
6 |
from PyQt5.QtCore import * |
7 |
from PyQt5.QtGui import * |
8 |
from PyQt5.QtWidgets import * |
9 |
from AppDocData import AppDocData |
10 |
import ReplaceSymbol_UI |
11 |
from EngineeringTextItem import QEngineeringTextItem |
12 |
from SymbolSvgItem import SymbolSvgItem |
13 |
from EngineeringLineItem import QEngineeringLineItem |
14 |
from EngineeringVendorItem import QEngineeringVendorItem |
15 |
|
16 |
class QReplaceSymbolDialog(QDialog): |
17 |
""" This is symbol item replace and insert dialog class """
|
18 |
|
19 |
CONDITION_REPLACE = {'radioButtonHasCon':['item.has_connection'], 'radioButtonHasNoCon':['not item.has_connection'], 'radioButtonConLine':['False'], 'radioButtonAll':['True']} |
20 |
CONDITION_INSERT = {'radioButtonHasCon':['conn.connetionItem'], 'radioButtonHasNoCon':['not conn.connectedItem'], 'radioButtonConLine':['conn.connectedItem and type(conn.connectedItem) is QEngineeringLineItem'], 'radioButtonAll':['True']} |
21 |
|
22 |
def __init__(self, parent): |
23 |
QDialog.__init__(self, parent)
|
24 |
|
25 |
self.mainWindow = parent
|
26 |
self.view = self.mainWindow.graphicsView |
27 |
self.ui = ReplaceSymbol_UI.Ui_ReplaceSymbolDialog()
|
28 |
self.ui.setupUi(self) |
29 |
|
30 |
self.ui.pushButtonRun.clicked.connect(self.run) |
31 |
self.ui.buttonBox.rejected.connect(self.reject) |
32 |
|
33 |
self.init_symbol_list()
|
34 |
|
35 |
def init_symbol_list(self): |
36 |
app_doc_data = AppDocData.instance() |
37 |
symbol_list = app_doc_data.getTargetSymbolList(all=True)
|
38 |
|
39 |
# for nozzle and equipment package
|
40 |
self.ui.comboBoxFind.addItem('Equipment Package') |
41 |
for symbol in symbol_list: |
42 |
self.ui.comboBoxFind.addItem(symbol.getName())
|
43 |
self.ui.comboBoxReplace.addItem(symbol.getName())
|
44 |
|
45 |
def run(self): |
46 |
find_symbol = self.ui.comboBoxFind.currentText()
|
47 |
replace_symbol = self.ui.comboBoxReplace.currentText()
|
48 |
|
49 |
condition = self.ui.buttonGroup_2.checkedButton().objectName()
|
50 |
if condition == 'radioButtonCustom': |
51 |
conditions = [text for text in self.ui.plainTextEdit.toPlainText().split('\n')] |
52 |
else:
|
53 |
conditions = QReplaceSymbolDialog.CONDITION_REPLACE[condition] if self.ui.radioButtonReplace.isChecked() else QReplaceSymbolDialog.CONDITION_INSERT[condition] |
54 |
|
55 |
symbol_items = [item for item in self.view.scene().items() |
56 |
if issubclass(type(item), SymbolSvgItem) and find_symbol == item.name] if find_symbol != 'Equipment Package' |
57 |
else [item for item in self.view.scene().items() |
58 |
if issubclass(type(item), QEngineeringVendorItem) and item.pack_type == 'Equipment Package'] |
59 |
|
60 |
new_symbols = [] |
61 |
if self.ui.radioButtonReplace.isChecked() and find_symbol != 'Equipment Package': |
62 |
# replace
|
63 |
for item in reversed(symbol_items): |
64 |
for condition in conditions: |
65 |
if condition and not eval(condition): |
66 |
symbol_items.remove(item) |
67 |
break
|
68 |
|
69 |
if not symbol_items: |
70 |
return
|
71 |
|
72 |
for item in symbol_items: |
73 |
scenePos = item.mapToScene(item.transformOriginPoint()) |
74 |
item.transfer.onRemoved.emit(item) |
75 |
|
76 |
svg = self.view.createSymbolObject(replace_symbol)
|
77 |
new_symbols.append([svg, scenePos, item.angle, item.flip]) |
78 |
|
79 |
for item in new_symbols: |
80 |
self.view.matchSymbolToLine(item[0], item[1], angle=item[2], flip=item[3]) |
81 |
item[0].bind_close_items()
|
82 |
|
83 |
elif not self.ui.radioButtonReplace.isChecked() and find_symbol != 'Equipment Package': |
84 |
# insert
|
85 |
if not symbol_items: |
86 |
return
|
87 |
|
88 |
for item in symbol_items: |
89 |
for conn in item.connectors: |
90 |
for condition in conditions: |
91 |
if condition and eval(condition): |
92 |
scenePos = conn.sceneBoundingRect().center() |
93 |
svg = self.view.createSymbolObject(replace_symbol)
|
94 |
new_symbols.append([svg, scenePos]) |
95 |
|
96 |
for item in new_symbols: |
97 |
self.view.matchSymbolToLine(item[0], item[1]) |
98 |
elif not self.ui.radioButtonReplace.isChecked() and find_symbol == 'Equipment Package': |
99 |
pass
|
100 |
|
101 |
|
102 |
def reject(self): |
103 |
"""close a dialog"""
|
104 |
QDialog.reject(self)
|