개정판 de3f62c6
issue #49: custom code table setting on going
Change-Id: Id42fb0658f8f61edae93af34af06de62bd312bec
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
2036 | 2036 |
sys.exc_info()[-1].tb_lineno) |
2037 | 2037 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
2038 | 2038 |
|
2039 |
def getCustomTables(self): |
|
2040 |
''' get custom code tables ''' |
|
2041 |
|
|
2042 |
with self.project.database.connect() as conn: |
|
2043 |
try: |
|
2044 |
# Get a cursor object |
|
2045 |
cursor = conn.cursor() |
|
2046 |
|
|
2047 |
sql = self.project.database.to_sql('select UID, Name, Desciption from CustomTables') |
|
2048 |
cursor.execute(sql) |
|
2049 |
rows = cursor.fetchall() |
|
2050 |
for row in rows: |
|
2051 |
attr = SymbolAttr() |
|
2052 |
attr.UID = uuid.UUID(row[0]) |
|
2053 |
attr.Attribute = row[1] |
|
2054 |
attr.DisplayAttribute = row[2] |
|
2055 |
attr.AttributeType = row[3] |
|
2056 |
attr.AttrAt = row[4] |
|
2057 |
attr.Expression = row[5] |
|
2058 |
attr.Target = row[7] |
|
2059 |
attr.IsProp = row[8] |
|
2060 |
attr.Codes = CodeTable.instance('SymbolAttributeCodeTable', row[0]) |
|
2061 |
result.append(attr) |
|
2062 |
# Catch the exception |
|
2063 |
except Exception as ex: |
|
2064 |
from App import App |
|
2065 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
2066 |
sys.exc_info()[-1].tb_lineno) |
|
2067 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
2068 |
|
|
2069 |
return result |
|
2070 |
|
|
2039 | 2071 |
''' |
2040 | 2072 |
@brief get Symbol Attribute |
2041 | 2073 |
@author kyouho |
2042 | 2074 |
@date 2018.07.18 |
2043 | 2075 |
@history humkyung 2018.10.13 load expression |
2044 | 2076 |
''' |
2045 |
|
|
2046 | 2077 |
def getSymbolAttribute(self, _type): |
2047 | 2078 |
import uuid |
2048 | 2079 |
from SymbolAttr import SymbolAttr |
... | ... | |
2147 | 2178 |
@date 2018.08.14 |
2148 | 2179 |
@history humkyung 2018.10.13 save expression |
2149 | 2180 |
''' |
2150 |
|
|
2151 | 2181 |
def saveSymbolAttributes(self, type, attrs, type_str): |
2152 | 2182 |
from CodeTables import CodeTable |
2153 | 2183 |
|
... | ... | |
2224 | 2254 |
self._attributeByType = {} |
2225 | 2255 |
CodeTable.clearTables() |
2226 | 2256 |
|
2257 |
def saveCustomCodes(self, tables): |
|
2258 |
''' save custom code tables and codes ''' |
|
2259 |
|
|
2260 |
from CodeTables import CodeTable |
|
2261 |
|
|
2262 |
conn = self.project.database.connect() |
|
2263 |
with conn: |
|
2264 |
try: |
|
2265 |
# Get a cursor object |
|
2266 |
cursor = conn.cursor() |
|
2267 |
|
|
2268 |
# delete custom codes and tables |
|
2269 |
sql = "delete from CustomCodes" |
|
2270 |
cursor.execute(sql) |
|
2271 |
|
|
2272 |
sql = "delete from CustomTables" |
|
2273 |
cursor.execute(sql) |
|
2274 |
# up to here |
|
2275 |
|
|
2276 |
# update symbol attribute code table data |
|
2277 |
for table in tables: |
|
2278 |
sql = self.project.database.to_sql("insert into CustomTables (UID, Name, Description) VALUES(?,?,?)") |
|
2279 |
param = (table[0], table[1], table[2]) |
|
2280 |
cursor.execute(sql, param) |
|
2281 |
|
|
2282 |
for code in table[3]: |
|
2283 |
sql = self.project.database.to_sql( \ |
|
2284 |
"insert into CustomCodes(UID, Code, Description, Allowables, Table_UID) VALUES(?,?,?,?,?)") |
|
2285 |
param = (code[0], code[1], code[2], ','.join(code[3]), table[0]) |
|
2286 |
cursor.execute(sql, param) |
|
2287 |
# up to here |
|
2288 |
|
|
2289 |
conn.commit() |
|
2290 |
|
|
2291 |
# Catch the exception |
|
2292 |
except Exception as ex: |
|
2293 |
# Roll back any change if something goes wrong |
|
2294 |
conn.rollback() |
|
2295 |
|
|
2296 |
from App import App |
|
2297 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
2298 |
sys.exc_info()[-1].tb_lineno) |
|
2299 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
2300 |
|
|
2301 |
CodeTable.clearTables() |
|
2302 |
|
|
2227 | 2303 |
''' |
2228 | 2304 |
@brief save symbol attributes |
2229 | 2305 |
@author humkyung |
2230 | 2306 |
@date 2018.08.14 |
2231 | 2307 |
''' |
2232 |
|
|
2233 | 2308 |
def saveLineAttributes(self, attrs): |
2234 | 2309 |
conn = self.project.database.connect() |
2235 | 2310 |
with conn: |
... | ... | |
2296 | 2371 |
@date 2018.07.10 |
2297 | 2372 |
''' |
2298 | 2373 |
|
2299 |
def getCodeTable(self, property, forCheckLineNumber=False, symbol_attribute_uid=None): |
|
2374 |
def getCodeTable(self, property, forCheckLineNumber=False, symbol_attribute_uid=None, custom_table_uid=None):
|
|
2300 | 2375 |
result = [] |
2301 | 2376 |
conn = self.project.database.connect() |
2302 | 2377 |
with conn: |
... | ... | |
2319 | 2394 |
rows = cursor.fetchall() |
2320 | 2395 |
if property.upper() in [name[0].upper() for name in rows]: |
2321 | 2396 |
""" |
2322 |
if not symbol_attribute_uid: |
|
2397 |
if not symbol_attribute_uid and not custom_table_uid:
|
|
2323 | 2398 |
sql = 'select uid, code, description, Allowables from [{}] order by code DESC'.format(property) |
2324 |
else:
|
|
2399 |
elif symbol_attribute_uid and not custom_table_uid:
|
|
2325 | 2400 |
sql = "select uid, code, description, Allowables from [{}] where SymbolAttribute_UID='{}' order by code DESC".format(property, symbol_attribute_uid) |
2401 |
elif not symbol_attribute_uid and custom_table_uid: |
|
2402 |
sql = "select uid, code, description, Allowables from [{}] where Table_UID='{}' order by code DESC".format(property, custom_table_uid) |
|
2326 | 2403 |
cursor.execute(sql) |
2327 | 2404 |
rows = cursor.fetchall() |
2328 | 2405 |
for row in rows: |
DTI_PID/DTI_PID/CodeTableDialog.py | ||
---|---|---|
224 | 224 |
@date 2018.07.10 |
225 | 225 |
''' |
226 | 226 |
|
227 |
def settingTable(self, tableName, symbol_attribute_uid=None, tableDatas=None): |
|
227 |
def settingTable(self, tableName, symbol_attribute_uid=None, custom_table_uid=None, tableDatas=None):
|
|
228 | 228 |
try: |
229 | 229 |
tableName = self.replaceText(tableName) |
230 | 230 |
docData = AppDocData.instance() |
... | ... | |
237 | 237 |
tableDatas = docData.getCodeTable(tableName, forCheckLineNumber=False, symbol_attribute_uid=symbol_attribute_uid) |
238 | 238 |
else: |
239 | 239 |
pass |
240 |
elif tableName == 'CustomCodes': |
|
241 |
if tableDatas is None: |
|
242 |
tableDatas = docData.getCodeTable(tableName, forCheckLineNumber=False, custom_table_uid=symbol_attribute_uid) |
|
243 |
else: |
|
244 |
pass |
|
240 | 245 |
else: |
241 | 246 |
tableDatas = docData.getCodeTable(tableName) |
242 | 247 |
|
DTI_PID/DTI_PID/CodeTables.py | ||
---|---|---|
60 | 60 |
return None |
61 | 61 |
|
62 | 62 |
@staticmethod |
63 |
def instance(table_name, symbol_attribute_uid=None): |
|
63 |
def instance(table_name, symbol_attribute_uid=None, custom_table_uid=None):
|
|
64 | 64 |
""" return instance has given table name """ |
65 | 65 |
|
66 | 66 |
from NominalPipeSize import NominalPipeSizeTable |
... | ... | |
68 | 68 |
_table_name = table_name.upper().replace(' ', '') |
69 | 69 |
if symbol_attribute_uid is None and _table_name == 'NOMINALDIAMETER': |
70 | 70 |
return NominalPipeSizeTable.instance() |
71 |
elif symbol_attribute_uid is None and _table_name not in CodeTable.TABLES: |
|
71 |
elif symbol_attribute_uid is None and custom_table_uid is None and _table_name not in CodeTable.TABLES:
|
|
72 | 72 |
appDocData = AppDocData.instance() |
73 | 73 |
values = appDocData.getCodeTable(_table_name, False) |
74 | 74 |
CodeTable.TABLES[_table_name] = CodeTable(_table_name, values) |
... | ... | |
80 | 80 |
values = appDocData.getCodeTable(_table_name, False, symbol_attribute_uid=symbol_attribute_uid) |
81 | 81 |
CodeTable.TABLES[symbol_attribute_uid] = CodeTable(symbol_attribute_uid, values) |
82 | 82 |
return CodeTable.TABLES[symbol_attribute_uid] |
83 |
elif _table_name == 'CUSTOMTABLES' and symbol_attribute_uid: |
|
84 |
if custom_table_uid in CodeTable.TABLES: |
|
85 |
return CodeTable.TABLES[custom_table_uid] |
|
86 |
else: |
|
87 |
appDocData = AppDocData.instance() |
|
88 |
values = appDocData.getCodeTable(_table_name, False, custom_table_uid=custom_table_uid) |
|
89 |
CodeTable.TABLES[custom_table_uid] = CodeTable(custom_table_uid, values) |
|
90 |
return CodeTable.TABLES[custom_table_uid] |
|
83 | 91 |
|
84 | 92 |
return CodeTable.TABLES[_table_name] |
85 | 93 |
|
DTI_PID/DTI_PID/CustomCodeTablesDialog.py | ||
---|---|---|
20 | 20 |
|
21 | 21 |
self.ui.tableWidgetCustomCodeTable.setSortingEnabled(True) |
22 | 22 |
|
23 |
self.ui.tableWidgetCustomCodeTable.setColumnCount(4) |
|
24 |
self.ui.tableWidgetCustomCodeTable.setHorizontalHeaderLabels(['UID', 'Name', 'Description', 'Table']) |
|
25 |
self.ui.tableWidgetCustomCodeTable.hideColumn(0) |
|
26 |
|
|
23 | 27 |
self.isAccepted = False |
24 | 28 |
|
25 | 29 |
self.ui.buttonBox.accepted.connect(self.accept) |
26 | 30 |
self.ui.buttonBox.rejected.connect(self.reject) |
31 |
self.ui.pushButtonAdd.clicked.connect(self.addTable) |
|
32 |
self.ui.pushButtonDelete.clicked.connect(self.delTable) |
|
33 |
self.ui.tableWidgetCustomCodeTable.cellDoubleClicked.connect(self.cell_double_clicked) |
|
34 |
|
|
35 |
def cell_double_clicked(self, row, column): |
|
36 |
from SymbolAttrCodeTableDialog import SymbolAttrCodeTableDialog |
|
37 |
from App import App |
|
38 |
|
|
39 |
try: |
|
40 |
if column == 3: |
|
41 |
dialog = SymbolAttrCodeTableDialog(self, self.ui.tableWidgetCustomCodeTable.item(row, 0).text(), tableDatas=self.ui.tableWidgetCustomCodeTable.item(row, 3).tag, Table_Name='CustomCodes') |
|
42 |
(isAccept, code_data) = dialog.showDialog() |
|
43 |
|
|
44 |
if isAccept: |
|
45 |
self.ui.tableWidgetCustomCodeTable.item(row, 3).tag = code_data |
|
46 |
|
|
47 |
graphicsView = App.mainWnd().graphicsView |
|
48 |
if dialog.code_area: |
|
49 |
if dialog.code_area.scene(): |
|
50 |
graphicsView.scene.removeItem(dialog.code_area) |
|
51 |
if dialog.desc_area: |
|
52 |
if dialog.desc_area.scene(): |
|
53 |
graphicsView.scene.removeItem(dialog.desc_area) |
|
54 |
graphicsView.useDefaultCommand() |
|
55 |
|
|
56 |
except Exception as ex: |
|
57 |
from App import App |
|
58 |
from AppDocData import MessageType |
|
59 |
|
|
60 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
61 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
62 |
|
|
63 |
def addTable(self): |
|
64 |
import uuid |
|
65 |
|
|
66 |
rows = self.ui.tableWidgetCustomCodeTable.rowCount() |
|
67 |
self.ui.tableWidgetCustomCodeTable.setRowCount(rows + 1) |
|
68 |
|
|
69 |
item = QTableWidgetItem('...') |
|
70 |
item.tag = [] |
|
71 |
item.setTextAlignment(Qt.AlignHCenter) |
|
72 |
item.setFlags(Qt.ItemIsEnabled) |
|
73 |
self.ui.tableWidgetCustomCodeTable.setItem(rows, 3, item) |
|
74 |
|
|
75 |
item = QTableWidgetItem(str(uuid.uuid4())) |
|
76 |
self.ui.tableWidgetCustomCodeTable.setItem(rows, 0, item) |
|
77 |
|
|
78 |
def delTable(self): |
|
79 |
model = self.ui.tableWidgetCustomCodeTable.model() |
|
80 |
row = self.ui.tableWidgetCustomCodeTable.currentRow() |
|
81 |
|
|
82 |
if row != -1: |
|
83 |
model.removeRow(row) |
|
27 | 84 |
|
28 | 85 |
''' |
29 | 86 |
@brief accept dialog |
... | ... | |
34 | 91 |
try: |
35 | 92 |
self.isAccepted = False |
36 | 93 |
|
94 |
appDocData = AppDocData.instance() |
|
95 |
|
|
96 |
tables = [] |
|
97 |
table = self.ui.tableWidgetCustomCodeTable |
|
98 |
|
|
99 |
for index in range(table.rowCount()): |
|
100 |
attr = [] |
|
101 |
attr.append(table.item(index, 0).text() if table.item(index, 0) is not None else '') |
|
102 |
attr.append(table.item(index, 1).text() if table.item(index, 1) is not None else '') |
|
103 |
attr.append(table.item(index, 2).text() if table.item(index, 2) is not None else '') |
|
104 |
attr.append(table.item(index, 3).tag if table.item(index, 3) is not None else []) |
|
105 |
tables.append(attr) |
|
106 |
|
|
107 |
appDocData.saveCustomCodes(tables) |
|
108 |
|
|
37 | 109 |
self.isAccepted = True |
38 | 110 |
QDialog.accept(self) |
39 | 111 |
|
DTI_PID/DTI_PID/SymbolAttrCodeTableDialog.py | ||
---|---|---|
31 | 31 |
self.ui.buttonBox.accepted.connect(self.accept) |
32 | 32 |
self.ui.buttonBox.rejected.connect(self.reject) |
33 | 33 |
|
34 |
self.settingTable('SymbolAttributeCodeTable', symbol_attribute_uid=symbol_attribute_uid, tableDatas=tableDatas) |
|
34 |
# for custom code table |
|
35 |
if Table_Name != 'SymbolAttributeCodeTable': |
|
36 |
self.setWindowTitle('Custom Code Table') |
|
37 |
self.ui.tableWidgetSymbolAttributeCodeTable.setObjectName('tableWidget' + Table_Name) |
|
38 |
|
|
39 |
self.settingTable(Table_Name, symbol_attribute_uid=symbol_attribute_uid, tableDatas=tableDatas) |
|
35 | 40 |
|
36 | 41 |
''' |
37 | 42 |
@brief accept dialog |
DTI_PID/DTI_PID/SymbolAttrEditorDialog.py | ||
---|---|---|
85 | 85 |
try: |
86 | 86 |
# code table settting |
87 | 87 |
if column == 7: |
88 |
symbolType = self.ui.comboBoxSymbolType.currentText() |
|
89 |
|
|
90 | 88 |
dialog = SymbolAttrCodeTableDialog(self, str(self.ui.tableWidgetAttr.item(row, 0).tag.UID), tableDatas=self.ui.tableWidgetAttr.item(row, 7).tag) |
91 | 89 |
(isAccept, code_data) = dialog.showDialog() |
92 | 90 |
|
내보내기 Unified diff