개정판 fbc85e2d
issue #901: fixed NominalDiameter table
Change-Id: I0d795e95823b4958e5cd60d1fd2e28354476912f
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
22 | 22 |
|
23 | 23 |
from SingletonInstance import SingletonInstane |
24 | 24 |
import symbol |
25 |
from NominalPipeSize import NominalPipeSize |
|
25 | 26 |
|
26 | 27 |
class Source: |
27 | 28 |
def __init__(self, source): |
... | ... | |
53 | 54 |
self.key = key |
54 | 55 |
self.value = value |
55 | 56 |
|
56 |
class NominalPipeSize: |
|
57 |
def __init__(self, code, metric, inch, inchStr, metricStr): |
|
58 |
self.code = code |
|
59 |
self.metric = metric |
|
60 |
self.inch = inch |
|
61 |
self.inchStr = inchStr |
|
62 |
self.metricStr = metricStr |
|
63 |
self.sizeUnit = 'Metric' |
|
64 |
|
|
65 | 57 |
''' |
66 | 58 |
@brief return size value string |
67 | 59 |
@author humkyung |
... | ... | |
1590 | 1582 |
# Get a cursor object |
1591 | 1583 |
cursor = conn.cursor() |
1592 | 1584 |
|
1593 |
sql = "select Code,Metric,Inch,InchStr,MetricStr from NominalDiameter ORDER BY {} ASC".format(orderStr)
|
|
1585 |
sql = "select UID,Code,Metric,Inch,InchStr,AllowableInchStr,MetricStr,AllowableMetricStr from NominalDiameter ORDER BY {} ASC".format(orderStr)
|
|
1594 | 1586 |
cursor.execute(sql) |
1595 | 1587 |
rows = cursor.fetchall() |
1596 | 1588 |
for row in rows: |
1597 |
pipeSize = NominalPipeSize(row[0], float(row[1]) if row[1] is not None else None, float(row[2]) if row[2] is not None else None, row[3], row[4])
|
|
1589 |
pipeSize = NominalPipeSize(row[0], row[1], float(row[2]) if row[2] is not None else None, float(row[3]) if row[3] is not None else None, row[4], row[5], row[6], row[7])
|
|
1598 | 1590 |
pipeSize.sizeUnit = sizeUnit |
1599 | 1591 |
if forCheckLineNumber: |
1600 | 1592 |
if sizeUnit == 'Inch' and pipeSize.inchStr: |
... | ... | |
1630 | 1622 |
conn = sqlite3.connect(dbPath) |
1631 | 1623 |
# Get a cursor object |
1632 | 1624 |
cursor = conn.cursor() |
1633 |
sql = "INSERT INTO NominalDiameter(Code, Metric, Inch, InchStr, MetricStr) VALUES(?,?,?,?,?)" |
|
1634 | 1625 |
for pipeSize in pipeSizes: |
1635 |
param = (pipeSize.code, pipeSize.metric, pipeSize.inch, pipeSize.inchStr, pipeSize.metricStr) |
|
1636 |
cursor.execute(sql, param) |
|
1626 |
sql = pipeSize.toSql() |
|
1627 |
if type(sql) is list and len(sql) == 1: |
|
1628 |
cursor.execute(sql[0][0], sql[0][1]) |
|
1629 |
|
|
1637 | 1630 |
conn.commit() |
1638 | 1631 |
# Catch the exception |
1639 | 1632 |
except Exception as ex: |
... | ... | |
1644 | 1637 |
# Close the db connection |
1645 | 1638 |
conn.close() |
1646 | 1639 |
|
1647 |
|
|
1648 | 1640 |
''' |
1649 | 1641 |
@brief delete NominalDiameter table |
1650 | 1642 |
@author kyouho |
DTI_PID/DTI_PID/CodeTableDialog.py | ||
---|---|---|
79 | 79 |
''' |
80 | 80 |
def insertTableWidgetNominalPipeSizeRow(self, pipeSizes): |
81 | 81 |
try: |
82 |
self.ui.tableWidgetNominalDiameter.setColumnCount(5)
|
|
83 |
self.ui.tableWidgetNominalDiameter.setHorizontalHeaderLabels(['Code', 'Metric', 'Inch', 'InchStr', 'MetricStr'])
|
|
82 |
self.ui.tableWidgetNominalDiameter.setColumnCount(7)
|
|
83 |
self.ui.tableWidgetNominalDiameter.setHorizontalHeaderLabels(['Code', 'Metric', 'Inch', 'InchStr', 'Allowables', 'MetricStr', 'Allowables'])
|
|
84 | 84 |
self.ui.tableWidgetNominalDiameter.setRowCount(len(pipeSizes)) |
85 | 85 |
row = 0 |
86 | 86 |
for pipeSize in pipeSizes: |
87 |
self.ui.tableWidgetNominalDiameter.setItem(row, 0, QTableWidgetItem(pipeSize.code)) |
|
87 |
item = QTableWidgetItem(pipeSize.code) |
|
88 |
item.setData(Qt.UserRole, pipeSize) |
|
89 |
self.ui.tableWidgetNominalDiameter.setItem(row, 0, item) |
|
88 | 90 |
self.ui.tableWidgetNominalDiameter.setItem(row, 1, QTableWidgetItem('' if pipeSize.metric is None else str(pipeSize.metric))) |
89 | 91 |
self.ui.tableWidgetNominalDiameter.setItem(row, 2, QTableWidgetItem('' if pipeSize.inch is None else str(pipeSize.inch))) |
90 | 92 |
self.ui.tableWidgetNominalDiameter.setItem(row, 3, QTableWidgetItem('' if pipeSize.inchStr is None else pipeSize.inchStr)) |
91 |
self.ui.tableWidgetNominalDiameter.setItem(row, 4, QTableWidgetItem('' if pipeSize.metricStr is None else pipeSize.metricStr)) |
|
93 |
self.ui.tableWidgetNominalDiameter.setItem(row, 4, QTableWidgetItem('' if pipeSize.allowable_inch_str is None else pipeSize.allowable_inch_str)) |
|
94 |
self.ui.tableWidgetNominalDiameter.setItem(row, 5, QTableWidgetItem('' if pipeSize.metricStr is None else pipeSize.metricStr)) |
|
95 |
self.ui.tableWidgetNominalDiameter.setItem(row, 6, QTableWidgetItem('' if pipeSize.allowable_metric_str is None else pipeSize.allowable_metric_str)) |
|
92 | 96 |
row += 1 |
93 | 97 |
|
94 | 98 |
self.ui.tableWidgetNominalDiameter.horizontalHeaderItem(0).setSizeHint(QSize(30, 30)) |
95 | 99 |
except Exception as ex: |
96 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
100 |
from App import App |
|
101 |
|
|
102 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
103 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
97 | 104 |
|
98 | 105 |
''' |
99 | 106 |
@brief Insert row Common Tablewidget |
... | ... | |
111 | 118 |
table.setItem(row, 3, QTableWidgetItem(tableData[3])) # Allowables |
112 | 119 |
row += 1 |
113 | 120 |
except Exception as ex: |
114 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
121 |
from App import App |
|
122 |
|
|
123 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
124 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
115 | 125 |
|
116 | 126 |
''' |
117 | 127 |
@brief Find TableWidget with Name |
... | ... | |
345 | 355 |
pipeSizes = [] |
346 | 356 |
try: |
347 | 357 |
docData = AppDocData.instance() |
348 |
self.deleteNomialPipeSize() |
|
349 | 358 |
|
350 |
from AppDocData import NominalPipeSize
|
|
359 |
from NominalPipeSize import NominalPipeSize
|
|
351 | 360 |
|
352 | 361 |
table = self.ui.tableWidgetNominalDiameter |
353 | 362 |
rowCount = table.rowCount() |
354 | 363 |
for row in range(rowCount): |
355 |
code = table.item(row, 0).text() |
|
356 |
metric = table.item(row, 1).text() |
|
357 |
inch = table.item(row, 2).text() |
|
358 |
inchStr = table.item(row, 3).text() |
|
359 |
metricStr = table.item(row, 4).text() |
|
360 |
|
|
361 |
pipeSize = NominalPipeSize(code, float(metric) if metric != '' else None, float(inch) if inch != '' else None, inchStr, metricStr) |
|
362 |
pipeSizes.append(pipeSize) |
|
364 |
pipe_size = table.item(row, 0).data(Qt.UserRole) |
|
365 |
pipe_size.code = table.item(row, 0).text() |
|
366 |
pipe_size.metric = float(table.item(row, 1).text()) if table.item(row, 1).text() != '' else None |
|
367 |
pipe_size.inch = float(table.item(row, 2).text()) if table.item(row, 2).text() != '' else None |
|
368 |
pipe_size.inchStr = table.item(row, 3).text() |
|
369 |
pipe_size.allowable_inch_str = table.item(row, 4).text() |
|
370 |
pipe_size.metricStr = table.item(row, 5).text() |
|
371 |
pipe_size.allowable_metric_str = table.item(row, 6).text() |
|
372 |
pipeSizes.append(pipe_size) |
|
363 | 373 |
|
364 | 374 |
docData.insertNomialPipeSize(pipeSizes) |
365 | 375 |
|
... | ... | |
367 | 377 |
from App import App |
368 | 378 |
|
369 | 379 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
370 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
371 |
|
|
372 |
''' |
|
373 |
@brief save common code data |
|
374 |
@author kyouho |
|
375 |
@date 2018.07.16 |
|
376 |
''' |
|
377 |
def deleteNomialPipeSize(self): |
|
378 |
docData = AppDocData.instance() |
|
379 |
docData.deleteNomialPipeSize() |
|
380 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
DTI_PID/DTI_PID/CodeTables.py | ||
---|---|---|
6 | 6 |
from AppDocData import AppDocData |
7 | 7 |
|
8 | 8 |
class CodeTable: |
9 |
""" This is code table class """ |
|
10 |
|
|
9 | 11 |
TABLES = {} |
10 | 12 |
|
11 | 13 |
def __init__(self, name, values): |
... | ... | |
15 | 17 |
else: |
16 | 18 |
self.values = values |
17 | 19 |
|
18 |
def find(self, text): |
|
19 |
""" |
|
20 |
find text in table |
|
21 |
""" |
|
20 |
def find_starts_with(self, text, size_unit='Inch'): |
|
21 |
""" find text in table """ |
|
22 | 22 |
if self.name == "NOMINALDIAMETER": |
23 |
matches = [x for x in self.values if text.startswith(x)] |
|
24 |
return matches[0] if matches else None |
|
23 |
""" uid, code, metric, inch, inchstr, allowable_inch_str, metricstr, allowable_metric_str """ |
|
24 |
for value in self.values: |
|
25 |
if size_unit.upper() == 'INCH': |
|
26 |
tokens = [x for x in value[5].split(',') if x and text.startswith(x)] |
|
27 |
if text.startswidth(value[4]) or tokens: return value[4] |
|
28 |
elif size_unit.upper() == 'METRIC': |
|
29 |
tokens = [x for x in value[7].split(',') if x and text.startswith(x)] |
|
30 |
if text.startswidth(value[6]) or tokens: return value[6] |
|
25 | 31 |
else: |
26 | 32 |
for value in self.values: |
27 | 33 |
if text.startswith(value[1]): |
... | ... | |
34 | 40 |
|
35 | 41 |
@staticmethod |
36 | 42 |
def instance(table_name): |
37 |
if table_name not in CodeTable.TABLES: |
|
43 |
""" return instance has given table name """ |
|
44 |
|
|
45 |
from NominalPipeSize import NominalPipeSizeTable |
|
46 |
|
|
47 |
_table_name = table_name.upper().replace(' ','') |
|
48 |
if _table_name == 'NOMINALDIAMETER': |
|
49 |
return NominalPipeSizeTable.instance() |
|
50 |
elif _table_name not in CodeTable.TABLES: |
|
38 | 51 |
appDocData = AppDocData.instance() |
39 |
values = appDocData.getCodeTable(table_name.upper().replace(' ',''), True if table_name.upper().replace(' ','') == "NOMINALDIAMETER" else False)
|
|
40 |
CodeTable.TABLES[table_name.upper().replace(' ', '')] = CodeTable(table_name.upper().replace(' ',''), values)
|
|
52 |
values = appDocData.getCodeTable(_table_name, False)
|
|
53 |
CodeTable.TABLES[_table_name] = CodeTable(_table_name, values)
|
|
41 | 54 |
|
42 |
return CodeTable.TABLES[table_name.upper().replace(' ', '')] |
|
55 |
return CodeTable.TABLES[_table_name] |
DTI_PID/DTI_PID/Configs.py | ||
---|---|---|
21 | 21 |
self.value = value |
22 | 22 |
|
23 | 23 |
def parse(self, text): |
24 |
""" |
|
25 |
return true if successfully parse given text else return false |
|
26 |
""" |
|
24 |
""" return true if successfully parse given text else return false """ |
|
27 | 25 |
import re |
28 | 26 |
|
29 | 27 |
try: |
... | ... | |
41 | 39 |
|
42 | 40 |
if lineType == 'Code Table': |
43 | 41 |
tableName = lineProp[0].Attribute |
44 |
found = CodeTable.instance(tableName).find(_text)
|
|
42 |
found = CodeTable.instance(tableName).find_starts_with(_text, self.unit)
|
|
45 | 43 |
if not found: return (False,) |
46 | 44 |
_text = _text[len(found):len(_text)] |
47 | 45 |
res.append(found) |
DTI_PID/DTI_PID/ConfigurationDialog.py | ||
---|---|---|
561 | 561 |
kyouho 2018.07.04 edit cofiguration new delimiter (self.delimiter) |
562 | 562 |
''' |
563 | 563 |
def accept(self): |
564 |
from NominalPipeSize import NomialPipeSizeTable |
|
564 | 565 |
try: |
565 | 566 |
docData = AppDocData.instance() |
566 | 567 |
|
... | ... | |
648 | 649 |
|
649 | 650 |
docData.saveConfigs(configs) |
650 | 651 |
docData.lineTypeConfigs = None # clear line type configurations |
652 |
NomialPipeSizeTable.instance().pipe_sizes = None # clear nominal pipe size table |
|
651 | 653 |
except Exception as ex: |
652 | 654 |
from App import App |
653 | 655 |
from AppDocData import MessageType |
DTI_PID/DTI_PID/NominalPipeSize.py | ||
---|---|---|
1 |
# coding: utf-8 |
|
2 |
""" This is NominalPipeSize module """ |
|
3 |
|
|
4 |
from SingletonInstance import SingletonInstane |
|
5 |
|
|
6 |
class NominalPipeSizeTable(SingletonInstane): |
|
7 |
""" This is nominal pipe size table class """ |
|
8 |
def __init__(self): |
|
9 |
self._pipe_sizes = None |
|
10 |
|
|
11 |
def find(self, text, size_unit='Inch'): |
|
12 |
""" find given text """ |
|
13 |
|
|
14 |
for pipe_size in self.pipe_sizes: |
|
15 |
if pipe_size.find(text, size_unit): return True |
|
16 |
|
|
17 |
return False |
|
18 |
|
|
19 |
def find_starts_with(self, text, size_unit='Inch'): |
|
20 |
""" find given text starts with """ |
|
21 |
|
|
22 |
for pipe_size in self.pipe_sizes: |
|
23 |
found = pipe_size.find_starts_with(text, size_unit) |
|
24 |
if found: return found |
|
25 |
|
|
26 |
return None |
|
27 |
|
|
28 |
@property |
|
29 |
def pipe_sizes(self): |
|
30 |
""" getter of pipe sizes """ |
|
31 |
from AppDocData import AppDocData |
|
32 |
|
|
33 |
if self._pipe_sizes is None: |
|
34 |
app_doc_data = AppDocData.instance() |
|
35 |
self._pipe_sizes = app_doc_data.getNomialPipeSizeData() |
|
36 |
|
|
37 |
return self._pipe_sizes |
|
38 |
|
|
39 |
@pipe_sizes.setter |
|
40 |
def pipe_sizes(self, value): |
|
41 |
""" setter of pipe sizes """ |
|
42 |
self._pipe_sizes = value |
|
43 |
|
|
44 |
class NominalPipeSize: |
|
45 |
""" This is NominalPipeSize class """ |
|
46 |
def __init__(self, uid, code, metric, inch, inchStr, allowable_inch_str, metricStr, allowable_metric_str): |
|
47 |
self.uid = uid |
|
48 |
self.code = code |
|
49 |
self.metric = metric |
|
50 |
self.inch = inch |
|
51 |
self.inchStr = inchStr |
|
52 |
self.allowable_inch_str = allowable_inch_str |
|
53 |
self.metricStr = metricStr |
|
54 |
self.allowable_metric_str = allowable_metric_str |
|
55 |
self.sizeUnit = 'Metric' |
|
56 |
|
|
57 |
''' |
|
58 |
@brief return size value string |
|
59 |
@author humkyung |
|
60 |
@date 2018.04.24 |
|
61 |
''' |
|
62 |
def find(self, value, size_unit='Inch'): |
|
63 |
if size_unit.upper() == 'INCH': |
|
64 |
return (self.inchStr == value) or (value in self.allowable_inch_str.split(',')) |
|
65 |
elif size_unit.upper() == 'METRIC': |
|
66 |
return (self.metricStr == value) or (value in self.allowable_metric_str.split(',')) |
|
67 |
else: |
|
68 |
return (self.inchStr == value) or (value in self.allowable_inch_str.split(',')) or (self.metricStr == value) or (value in self.allowable_metric_str.split(',')) |
|
69 |
|
|
70 |
def find_starts_with(self, value, size_unit='Inch'): |
|
71 |
""" find text start with """ |
|
72 |
if size_unit.upper() == 'INCH': |
|
73 |
if value.startswith(self.inchStr): |
|
74 |
return self.inchStr |
|
75 |
else: |
|
76 |
matches = [x for x in self.allowable_inch_str.split(',') if value.startswith(x)] |
|
77 |
if matches: return matches[0] |
|
78 |
elif size_unit.upper() == 'METRIC': |
|
79 |
if value.startswith(self.metricStr): |
|
80 |
return self.metricStr |
|
81 |
else: |
|
82 |
matches = [x for x in self.allowable_metric_str.split(',') if value.startswith(x)] |
|
83 |
if matches: return matches[0] |
|
84 |
else: |
|
85 |
if value.startswith(self.inchStr): |
|
86 |
return self.inchStr |
|
87 |
elif value.startswith(self.metricStr): |
|
88 |
return self.metricStr |
|
89 |
else: |
|
90 |
matches = [x for x in self.allowable_inch_str.split(',') if value.startswith(x)] |
|
91 |
if matches: return matches[0] |
|
92 |
|
|
93 |
matches = [x for x in self.allowable_metric_str.split(',') if value.startswith(x)] |
|
94 |
if matches: return matches[0] |
|
95 |
|
|
96 |
return None |
|
97 |
|
|
98 |
def toSql(self): |
|
99 |
""" generate sql string to insert database """ |
|
100 |
res = [] |
|
101 |
|
|
102 |
if not self.uid is None: |
|
103 |
sql = "insert or replace into NominalDiameter(UID, Code, Metric, Inch, InchStr, AllowableInchStr, MetricStr, AllowableMetricStr) VALUES(?,?,?,?,?,?,?,?)" |
|
104 |
param = (self.uid, self.code, self.metric, self.inch, self.inchStr, self.allowable_inch_str, self.metricStr, self.allowable_metric_str) |
|
105 |
res.append((sql, param)) |
|
106 |
else: |
|
107 |
sql = "insert into NominalDiameter(UID, Code, Metric, Inch, InchStr, AllowableInchStr, MetricStr, AllowableMetricStr) VALUES(lower(hex(randomblob(16))),?,?,?,?,?,?,?)" |
|
108 |
param = (self.code, self.metric, self.inch, self.inchStr, self.allowable_inch_str, self.metricStr, self.allow_metric_str) |
|
109 |
res.append((sql, param)) |
|
110 |
|
|
111 |
return res |
DTI_PID/DTI_PID/Shapes/EngineeringTextItem.py | ||
---|---|---|
474 | 474 |
item.size = (width, height) |
475 | 475 |
item.angle = angle |
476 | 476 |
item.setPlainText(value) |
477 |
item.setToolTip('Size = {}'.format(value))
|
|
477 |
item.setToolTip('SIZE = {}'.format(value))
|
|
478 | 478 |
elif name == 'VALVE OPER CODE': |
479 | 479 |
item = QEngineeringValveOperCodeTextItem() |
480 | 480 |
if item is not None: |
DTI_PID/DTI_PID/TextItemFactory.py | ||
---|---|---|
73 | 73 |
if result[0]: |
74 | 74 |
item = QEngineeringLineNoTextItem() |
75 | 75 |
text = ''.join(result[1]) |
76 |
item.setToolTip(text)
|
|
76 |
item.setToolTip('LINE NO={}'.format(text))
|
|
77 | 77 |
item.setPlainText(text) |
78 | 78 |
|
79 | 79 |
# get color option |
... | ... | |
290 | 290 |
@date 2018.05.02 |
291 | 291 |
''' |
292 | 292 |
def isSizeText(self, text, delimiter=None): |
293 |
docData = AppDocData.instance() |
|
294 |
sizeDataList = docData.getNomialPipeSizeData() |
|
293 |
from NominalPipeSize import NominalPipeSizeTable |
|
294 |
|
|
295 |
pipe_sizes = NominalPipeSizeTable.instance().pipe_sizes |
|
295 | 296 |
|
296 | 297 |
tokens = text.upper().split(delimiter) if delimiter is not None else [text] |
297 | 298 |
for token in tokens: |
298 |
matches = [sizeData for sizeData in sizeDataList if sizeData.sizeValue() == token]
|
|
299 |
matches = [sizeData for sizeData in pipe_sizes if sizeData.find(token.strip())]
|
|
299 | 300 |
if not matches: return False |
300 | 301 |
|
301 | 302 |
return True |
... | ... | |
308 | 309 |
def isTagNoText(self, text): |
309 | 310 |
from CodeTables import CodeTable |
310 | 311 |
|
311 |
found = CodeTable.instance('EqpTagNames').find(text) |
|
312 |
found = CodeTable.instance('EqpTagNames').find_starts_with(text)
|
|
312 | 313 |
|
313 | 314 |
return True if found else False |
314 | 315 |
|
... | ... | |
318 | 319 |
""" |
319 | 320 |
from CodeTables import CodeTable |
320 | 321 |
|
321 |
found = CodeTable.instance('ValveOperCodes').find(text) |
|
322 |
found = CodeTable.instance('ValveOperCodes').find_starts_with(text)
|
|
322 | 323 |
|
323 | 324 |
return True if found else False |
내보내기 Unified diff