hytos / HYTOS / HYTOS / TextItemFactory.py @ 36ccdf0e
이력 | 보기 | 이력해설 | 다운로드 (12.5 KB)
1 | e883edfd | humkyung | """
|
---|---|---|---|
2 | This is TextItemFactor module
|
||
3 | """
|
||
4 | |||
5 | aa1b6842 | 김정우 | from SingletonInstance import SingletonInstane |
6 | 25598176 | gaqhf | import re |
7 | aa1b6842 | 김정우 | try:
|
8 | from PyQt5.QtCore import * |
||
9 | from PyQt5.QtGui import * |
||
10 | from PyQt5.QtWidgets import * |
||
11 | except ImportError: |
||
12 | try:
|
||
13 | from PyQt4.QtCore import * |
||
14 | from PyQt4.QtGui import * |
||
15 | except ImportError: |
||
16 | raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
||
17 | 18e5ca81 | humkyung | from AppDocData import * |
18 | aa1b6842 | 김정우 | import sys, os |
19 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Shapes') |
||
20 | c80d49e6 | humkyung | from EngineeringTextItem import QEngineeringTextItem |
21 | baf331db | humkyung | from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
22 | 24015dc6 | humkyung | from QEngineeringSizeTextItem import QEngineeringSizeTextItem |
23 | eca61950 | humkyung | from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
24 | 74fc4c98 | esham21 | from EngineeringReservedWordTextItem import QEngineeringReservedWordTextItem |
25 | aa1b6842 | 김정우 | |
26 | class TextItemFactory(SingletonInstane): |
||
27 | 8138f238 | humkyung | """ This is TextItemFactor class """
|
28 | aa1b6842 | 김정우 | def __init__(self): |
29 | 87aa9c66 | gaqhf | self.delimiter = '"' |
30 | 67f38d89 | esham21 | self.lineNoDelimiter = '!-!' |
31 | aa1b6842 | 김정우 | |
32 | 99b4d542 | 김정우 | '''
|
33 | @history 2018.04.27 Jeongwoo Add condition on elif-statement (delimiter != '' and lineNoConfig != '')
|
||
34 | 24015dc6 | humkyung | humkyung 2018.05.02 create engineering size text item if condition matches
|
35 | 8c66ce13 | humkyung | humkyung 2018.06.19 set line no's color
|
36 | 87aa9c66 | gaqhf | kyouho 2018.07.04 edit for isLineNo method (add parameter)
|
37 | e65b0bf8 | humkyung | humkyung 2018.08.08 fill linePropertyData and tagSeqNoPattern if given data is None
|
38 | 579f5a34 | esham21 | euisung 2018.11.19 now textitemfactory set plain text in createTextItem() for allowables
|
39 | 87aa9c66 | gaqhf | '''
|
40 | cc747b58 | esham21 | def createTextItem(self, textInfo): |
41 | 49113215 | humkyung | from Configs import LineNoConfig |
42 | f118d8a5 | humkyung | |
43 | aa1b6842 | 김정우 | item = None
|
44 | 6fad8ffd | humkyung | |
45 | try:
|
||
46 | cc747b58 | esham21 | text = textInfo.getText() |
47 | 24015dc6 | humkyung | docData = AppDocData.instance() |
48 | 49ba3f48 | humkyung | |
49 | """ create normal text item if it is not in drawing area """
|
||
50 | area = docData.getArea('Drawing')
|
||
51 | if not area.contains([textInfo.getX(), textInfo.getY()]): |
||
52 | item = QEngineeringTextItem() |
||
53 | item.setToolTip(text) |
||
54 | item.setPlainText(text) |
||
55 | |||
56 | 24015dc6 | humkyung | configs = docData.getConfigs('Size', 'Delimiter') |
57 | sizeDelimiter = configs[0].value.upper() if 1 == len(configs) else None |
||
58 | |||
59 | 49113215 | humkyung | line_no_configs = LineNoConfig.instance() |
60 | if line_no_configs:
|
||
61 | for line_no_config in line_no_configs: |
||
62 | result = line_no_config.parse(text) |
||
63 | 67f38d89 | esham21 | if result[0]: |
64 | 49113215 | humkyung | sizeUnit = line_no_config.unit |
65 | 67f38d89 | esham21 | break
|
66 | else:
|
||
67 | result = (False,)
|
||
68 | 25598176 | gaqhf | |
69 | b73a62df | humkyung | if result[0]: |
70 | afabd84e | humkyung | item = QEngineeringLineNoTextItem() |
71 | 49113215 | humkyung | text = ''.join(result[1]) |
72 | 5a4d5665 | humkyung | item.setToolTip('<b>{}</b><br>LINE NO={}'.format(str(item.uid), text)) |
73 | 579f5a34 | esham21 | item.setPlainText(text) |
74 | 25598176 | gaqhf | |
75 | # get color option
|
||
76 | configs = docData.getConfigs('Line Color', 'Visible Option') |
||
77 | if configs:
|
||
78 | visibleOption = configs[0].value
|
||
79 | else:
|
||
80 | visibleOption = 'Random'
|
||
81 | |||
82 | configs = docData.getConfigs('Color Property', 'State') |
||
83 | if configs:
|
||
84 | aa312985 | humkyung | color_property = configs[0].value
|
85 | 25598176 | gaqhf | |
86 | aa312985 | humkyung | # set line no color
|
87 | 25598176 | gaqhf | if visibleOption == 'Random': |
88 | fd329e57 | esham21 | rgb = docData.colors |
89 | item.change_color(QColor(rgb.red, rgb.green, rgb.blue).name()) |
||
90 | #item.setColor(QColor(rgb.red, rgb.green, rgb.blue).name())
|
||
91 | 25598176 | gaqhf | else:
|
92 | 269a15c8 | gaqhf | configs = docData.getConfigs('Line No', 'Configuration') |
93 | configs = configs[0].value.split(self.delimiter) |
||
94 | |||
95 | 25598176 | gaqhf | values = result[1]
|
96 | aa312985 | humkyung | index = configs.index(color_property) |
97 | fce49e72 | gaqhf | if index >= 0: |
98 | 25598176 | gaqhf | value = values[index] |
99 | aa312985 | humkyung | line_properties = docData.getLinePropertiesByUID(color_property) |
100 | if line_properties[0].Attribute.replace(' ','') == 'NominalDiameter': |
||
101 | 67f38d89 | esham21 | if sizeUnit == "Inch": |
102 | fce49e72 | gaqhf | value = docData.convertInchToMetric(value) |
103 | 25598176 | gaqhf | |
104 | aa312985 | humkyung | configs = docData.getConfigs(color_property, value) |
105 | fce49e72 | gaqhf | if configs:
|
106 | data = configs[0].value
|
||
107 | rgb = data.split(',')
|
||
108 | 835465ff | humkyung | item.change_color(QColor(int(rgb[0]), int(rgb[1]), int(rgb[2])).name()) |
109 | 25598176 | gaqhf | # up to here
|
110 | 4b03b7f7 | esham21 | docData.tracerLineNos.append(item) |
111 | 6fad8ffd | humkyung | else:
|
112 | d6518150 | humkyung | item = self.create_note_no_text(textInfo)
|
113 | if item:
|
||
114 | pass
|
||
115 | elif self.isSizeText(text, sizeDelimiter): |
||
116 | item = QEngineeringSizeTextItem() |
||
117 | 2e2abb58 | esham21 | text = text.replace(' ', '') |
118 | ee195020 | humkyung | item.setToolTip('SIZE = {}'.format(text))
|
119 | d6518150 | humkyung | item.setPlainText(text) |
120 | elif self.isTagNoText(text): |
||
121 | item = QEngineeringTagNoTextItem() |
||
122 | ee195020 | humkyung | item.setToolTip('TAG NO = {}'.format(text))
|
123 | d6518150 | humkyung | item.setPlainText(text) |
124 | a4806b86 | humkyung | elif self.is_valve_operation_code(text): |
125 | item = QEngineeringValveOperCodeTextItem() |
||
126 | item.setToolTip('Valve Operation Code = {}'.format(text))
|
||
127 | item.setPlainText(text) |
||
128 | 74fc4c98 | esham21 | elif self.is_reserved_word(text): |
129 | item = QEngineeringReservedWordTextItem() |
||
130 | item.setToolTip('Reserved Word = {}'.format(text))
|
||
131 | item.setPlainText(text) |
||
132 | d6518150 | humkyung | else:
|
133 | item = QEngineeringTextItem() |
||
134 | item.setToolTip(text) |
||
135 | item.setPlainText(text) |
||
136 | 4b03b7f7 | esham21 | docData.texts.append(item) |
137 | 6fad8ffd | humkyung | except Exception as ex: |
138 | e65b0bf8 | humkyung | from App import App |
139 | |||
140 | ce5ca212 | kim yeonjin | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
141 | e65b0bf8 | humkyung | App.mainWnd().addMessage.emit(MessageType.Error, message) |
142 | 6fad8ffd | humkyung | |
143 | aa1b6842 | 김정우 | return item
|
144 | 87aa9c66 | gaqhf | |
145 | aa1b6842 | 김정우 | '''
|
146 | c71687d5 | gaqhf | @brief Check Text startwith word
|
147 | 87aa9c66 | gaqhf | @author kyouho
|
148 | @date 2018.07.04
|
||
149 | '''
|
||
150 | c71687d5 | gaqhf | def isStartWithWord(self, text, word): |
151 | 579f5a34 | esham21 | sliceText = text[0:len(word[0])] |
152 | if sliceText == word[0]: |
||
153 | return (True, text[len(sliceText):len(text)], word[1]) |
||
154 | 87aa9c66 | gaqhf | else:
|
155 | return (False,) |
||
156 | |||
157 | |||
158 | '''
|
||
159 | c71687d5 | gaqhf | @brief Check Text startwith number
|
160 | @author kyouho
|
||
161 | @date 2018.07.05
|
||
162 | '''
|
||
163 | def isStartWithNumber(self, text): |
||
164 | sliceText = text[0:1] |
||
165 | d2a401b0 | gaqhf | num = ''
|
166 | c71687d5 | gaqhf | if self.isNumber(sliceText): |
167 | text = text[1:len(text)] |
||
168 | d2a401b0 | gaqhf | num += text |
169 | c71687d5 | gaqhf | while len(text) > 0: |
170 | sliceText = text[0:1] |
||
171 | |||
172 | if self.isNumber(sliceText): |
||
173 | text = text[1:len(text)] |
||
174 | d2a401b0 | gaqhf | num += text |
175 | c71687d5 | gaqhf | else:
|
176 | break
|
||
177 | |||
178 | d2a401b0 | gaqhf | return (True, text, num) |
179 | c71687d5 | gaqhf | else:
|
180 | return (False,) |
||
181 | |||
182 | '''
|
||
183 | @brief Check Number
|
||
184 | @author kyouho
|
||
185 | @date 2018.07.05
|
||
186 | 25598176 | gaqhf | @history kyouho 2018.07.09 add Refular Expression
|
187 | c71687d5 | gaqhf | '''
|
188 | def isNumber(self, num): |
||
189 | 7278d3e3 | gaqhf | p = re.compile('(^[0-9]+$)')
|
190 | 510a03fb | gaqhf | result = p.match(num) |
191 | |||
192 | if result:
|
||
193 | c71687d5 | gaqhf | return True |
194 | 510a03fb | gaqhf | else:
|
195 | c71687d5 | gaqhf | return False |
196 | |||
197 | ccb8b051 | gaqhf | '''
|
198 | @brief Check Number
|
||
199 | @author kyouho
|
||
200 | @date 2018.07.05
|
||
201 | '''
|
||
202 | def isTagSeqNo(self, text, pattern): |
||
203 | try:
|
||
204 | if pattern is not None: |
||
205 | attr = text |
||
206 | result = eval(pattern)
|
||
207 | if self.isNumber(result): |
||
208 | sliceText = text[0:len(result)] |
||
209 | return (True, text[len(sliceText):len(text)], sliceText) |
||
210 | else:
|
||
211 | return (False,) |
||
212 | else:
|
||
213 | return (False,) |
||
214 | except Exception as ex: |
||
215 | 5f7d5696 | kim yeonjin | from App import App |
216 | from AppDocData import MessageType |
||
217 | |||
218 | ce5ca212 | kim yeonjin | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
219 | 5f7d5696 | kim yeonjin | App.mainWnd().addMessage.emit(MessageType.Error, message) |
220 | 269a15c8 | gaqhf | |
221 | '''
|
||
222 | @brief Check Number
|
||
223 | @author kyouho
|
||
224 | @date 2018.07.05
|
||
225 | '''
|
||
226 | def isLimitWord(self, text, pattern): |
||
227 | try:
|
||
228 | if pattern is not None: |
||
229 | attr = text |
||
230 | length = pattern[0]
|
||
231 | isNumber = pattern[1]
|
||
232 | |||
233 | acf92f86 | humkyung | if length: # Length가 있으면 Length만큼 문자열을 가져와 길이를 검사한다. |
234 | result = eval('attr[:' + str(length) + ']') |
||
235 | if int(length) != len(result): |
||
236 | return(False,) |
||
237 | elif isNumber:
|
||
238 | match = re.search(re.compile('^[0-9]+'), attr)
|
||
239 | if match:
|
||
240 | result = match.group(match.start()) |
||
241 | else:
|
||
242 | return (False,) |
||
243 | else:
|
||
244 | result = attr |
||
245 | 269a15c8 | gaqhf | |
246 | if isNumber:
|
||
247 | if self.isNumber(result): |
||
248 | sliceText = text[0:len(result)] |
||
249 | return (True, text[len(sliceText):len(text)], sliceText) |
||
250 | else:
|
||
251 | return (False,) |
||
252 | else:
|
||
253 | sliceText = text[0:len(result)] |
||
254 | return (True, text[len(sliceText):len(text)], sliceText) |
||
255 | else:
|
||
256 | return (False,) |
||
257 | except Exception as ex: |
||
258 | 5f7d5696 | kim yeonjin | from App import App |
259 | from AppDocData import MessageType |
||
260 | |||
261 | ce5ca212 | kim yeonjin | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
262 | 5f7d5696 | kim yeonjin | App.mainWnd().addMessage.emit(MessageType.Error, message) |
263 | c71687d5 | gaqhf | |
264 | '''
|
||
265 | aa1b6842 | 김정우 | @brief Check if given text is Note No Text (ex : NOTE 1, NOTE 2, ...)
|
266 | @author Jeongwoo
|
||
267 | @date 2018.04.26
|
||
268 | 73a9aa93 | 김정우 | @history 2018.05.16 Jeongwoo Modify Validator flag
|
269 | aa1b6842 | 김정우 | '''
|
270 | d6518150 | humkyung | def create_note_no_text(self, textInfo): |
271 | item = None
|
||
272 | |||
273 | e883edfd | humkyung | appDocData = AppDocData.instance() |
274 | be3e0c2d | humkyung | configs = appDocData.getConfigs('Note No Tag Rule', 'Note No Expression') |
275 | b73a62df | humkyung | if 1 == len(configs) and configs[0].value: |
276 | be3e0c2d | humkyung | expression = configs[0].value
|
277 | cc747b58 | esham21 | match = re.search(re.compile(expression), textInfo.getText()) |
278 | f48febb9 | esham21 | |
279 | d6518150 | humkyung | if match:
|
280 | configs = appDocData.getConfigs('Note No Tag Rule', 'Note No Symbol Name') |
||
281 | if 1 == len(configs) and configs[0].value: |
||
282 | symbol_names = configs[0].value.split(',') |
||
283 | e0cb1584 | esham21 | for symbol in appDocData.symbols: |
284 | d5876276 | esham21 | if symbol.name in symbol_names and symbol.includes(textInfo.center): |
285 | 7765b508 | humkyung | item = QEngineeringNoteItem(symbol=symbol) |
286 | d6518150 | humkyung | break
|
287 | else:
|
||
288 | item = QEngineeringNoteItem() |
||
289 | |||
290 | if item:
|
||
291 | item.setToolTip(textInfo.getText()) |
||
292 | item.setPlainText(textInfo.getText()) |
||
293 | |||
294 | return item
|
||
295 | 24015dc6 | humkyung | |
296 | '''
|
||
297 | @brief check if given text is size text
|
||
298 | @author humkyung
|
||
299 | @date 2018.05.02
|
||
300 | '''
|
||
301 | def isSizeText(self, text, delimiter=None): |
||
302 | fbc85e2d | humkyung | from NominalPipeSize import NominalPipeSizeTable |
303 | |||
304 | pipe_sizes = NominalPipeSizeTable.instance().pipe_sizes |
||
305 | 24015dc6 | humkyung | |
306 | tokens = text.upper().split(delimiter) if delimiter is not None else [text] |
||
307 | for token in tokens: |
||
308 | fbc85e2d | humkyung | matches = [sizeData for sizeData in pipe_sizes if sizeData.find(token.strip())] |
309 | 24015dc6 | humkyung | if not matches: return False |
310 | |||
311 | return True |
||
312 | eca61950 | humkyung | |
313 | '''
|
||
314 | @brief check if given text is tag no
|
||
315 | @author humkyung
|
||
316 | @date 2018.05.03
|
||
317 | '''
|
||
318 | def isTagNoText(self, text): |
||
319 | 04271a49 | humkyung | from CodeTables import CodeTable |
320 | |||
321 | fbc85e2d | humkyung | found = CodeTable.instance('EqpTagNames').find_starts_with(text)
|
322 | 04271a49 | humkyung | |
323 | return True if found else False |
||
324 | a4806b86 | humkyung | |
325 | def is_valve_operation_code(self, text): |
||
326 | """
|
||
327 | check if given text is valve operation code
|
||
328 | """
|
||
329 | from CodeTables import CodeTable |
||
330 | |||
331 | fbc85e2d | humkyung | found = CodeTable.instance('ValveOperCodes').find_starts_with(text)
|
332 | a4806b86 | humkyung | |
333 | return True if found else False |
||
334 | 74fc4c98 | esham21 | |
335 | ff77e799 | humkyung | def is_reserved_word(self, text): |
336 | """ check if given text is reserved words """
|
||
337 | 74fc4c98 | esham21 | from CodeTables import CodeTable |
338 | |||
339 | found = CodeTable.instance('ReservedWords').find_starts_with(text)
|
||
340 | |||
341 | return True if found else False |