개정판 d03fbb91
size
Change-Id: I3f59d751ec0e31ea8221860b3c0ed7347fb50134
DTI_PID/DTI_PID/TextItemFactory.py | ||
---|---|---|
354 | 354 |
def isSizeText(self, text, delimiter='X'): |
355 | 355 |
from NominalPipeSize import NominalPipeSizeTable |
356 | 356 | |
357 |
sizeUnit = None |
|
358 |
configs = AppDocData.instance().getConfigs('Project', 'Unit') |
|
359 |
sizeUnit = configs[0].value if 1 == len(configs) else 'Imperial' |
|
360 | ||
361 |
pipe_sizes = NominalPipeSizeTable.instance().pipe_sizes |
|
362 | ||
363 |
text = text.replace("'", '"').replace(' ', '').upper() |
|
364 | ||
365 |
if delimiter != '/' and delimiter in text: |
|
366 |
if len([_text for _text in text.split(delimiter.upper()) if len(_text) > 0]) < 2: |
|
367 |
return False |
|
368 |
if text.count(delimiter) != 1: |
|
369 |
return False |
|
370 | ||
371 |
first, second = None, None |
|
372 |
# for imperial |
|
373 |
if sizeUnit == 'Imperial' and text.find('"') is not -1 and delimiter == '/': |
|
374 |
first = text[:text.find('"') + 1] |
|
375 |
second = text[text.find('"') + 1:].replace(delimiter.upper(), '', |
|
376 |
1).strip() if delimiter is not None else text[text.find('"') + 1:].strip() |
|
377 |
elif sizeUnit == 'Imperial': |
|
378 |
first = text.split(delimiter.upper())[0] |
|
379 |
second = text.split(delimiter.upper())[1] if len(text.split(delimiter.upper())) == 2 else None |
|
380 |
# for metric |
|
381 |
else: |
|
382 |
split_text = text.strip().split(delimiter.upper()) |
|
383 |
if len(split_text) > 2: |
|
384 |
return False |
|
385 |
first = split_text[0] |
|
386 |
second = split_text[1] if len(split_text) is 2 else None |
|
387 | ||
388 |
tokens = [first, second] if second is not None and len(second) is not 0 else [first] |
|
389 |
index = 0 |
|
390 |
for token in tokens: |
|
391 |
matches = [(sizeData.find(token, sizeUnit) if sizeUnit else sizeData.find(token)) for sizeData in pipe_sizes |
|
392 |
if (sizeData.find(token, sizeUnit) if sizeUnit else sizeData.find(token))] |
|
393 |
if matches: |
|
394 |
tokens[index] = matches[0] |
|
357 |
try: |
|
358 |
sizeUnit = None |
|
359 |
configs = AppDocData.instance().getConfigs('Project', 'Unit') |
|
360 |
sizeUnit = configs[0].value if 1 == len(configs) else 'Imperial' |
|
361 | ||
362 |
pipe_sizes = NominalPipeSizeTable.instance().pipe_sizes |
|
363 | ||
364 |
text = text.replace("'", '"').replace(' ', '').upper() |
|
365 | ||
366 |
if delimiter != '/' and delimiter in text: |
|
367 |
if len([_text for _text in text.split(delimiter.upper()) if len(_text) > 0]) < 2: |
|
368 |
return False |
|
369 |
if text.count(delimiter) != 1: |
|
370 |
return False |
|
371 | ||
372 |
first, second = None, None |
|
373 |
# for imperial |
|
374 |
if sizeUnit == 'Imperial' and text.find('"') is not -1 and delimiter == '/': |
|
375 |
first = text[:text.find('"') + 1] |
|
376 |
second = text[text.find('"') + 1:].replace(delimiter.upper(), '', |
|
377 |
1).strip() if delimiter is not None else text[text.find('"') + 1:].strip() |
|
378 |
elif sizeUnit == 'Imperial': |
|
379 |
first = text.split(delimiter.upper())[0] |
|
380 |
second = text.split(delimiter.upper())[1] if len(text.split(delimiter.upper())) == 2 else None |
|
381 |
# for metric |
|
395 | 382 |
else: |
396 |
return False |
|
397 |
index += 1 |
|
383 |
split_text = text.strip().split(delimiter.upper()) |
|
384 |
if len(split_text) > 2: |
|
385 |
return False |
|
386 |
first = split_text[0] |
|
387 |
second = split_text[1] if len(split_text) is 2 else None |
|
388 | ||
389 |
tokens = [first, second] if second is not None and len(second) is not 0 else [first] |
|
390 |
index = 0 |
|
391 |
for token in tokens: |
|
392 |
matches = [(sizeData.find(token, sizeUnit) if sizeUnit else sizeData.find(token)) for sizeData in pipe_sizes |
|
393 |
if (sizeData.find(token, sizeUnit) if sizeUnit else sizeData.find(token))] |
|
394 |
if matches: |
|
395 |
tokens[index] = matches[0] |
|
396 |
else: |
|
397 |
return False |
|
398 |
index += 1 |
|
398 | 399 | |
399 |
if len(tokens) == 2: |
|
400 |
if self.inch_to_number(tokens[0]) < self.inch_to_number(tokens[1]): |
|
401 |
tokens[0], tokens[1] = tokens[1], tokens[0] |
|
402 |
return [delimiter.join(tokens), tokens, delimiter] |
|
400 |
if len(tokens) == 2: |
|
401 |
if self.inch_to_number(tokens[0]) < self.inch_to_number(tokens[1]): |
|
402 |
tokens[0], tokens[1] = tokens[1], tokens[0] |
|
403 |
return [delimiter.join(tokens), tokens, delimiter] |
|
404 |
except Exception as ex: |
|
405 |
from App import App |
|
406 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
407 |
sys.exc_info()[-1].tb_lineno) |
|
408 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
409 |
return False |
|
403 | 410 | |
404 | 411 |
def inch_to_number(self, inch_str): |
405 |
app_doc_data = AppDocData.instance() |
|
406 |
configs = app_doc_data.getConfigs('Size', 'Symbol') |
|
407 |
size_symbols = configs[0].value.replace(' ', '').split(',') if 1 == len(configs) else ['"'] |
|
408 | ||
409 |
inch_str = str(inch_str) |
|
410 |
for symbol in size_symbols: |
|
411 |
inchs = inch_str.replace(symbol, '') |
|
412 |
inchs = inchs.replace('"', '').split('-') |
|
413 | ||
414 |
number = 0 |
|
415 |
for inch in inchs: |
|
416 |
if '/' not in inch: |
|
417 |
number += float(inch) |
|
418 |
else: |
|
419 |
fraction = inch.split('/') |
|
420 |
number += float(fraction[0]) / float(fraction[1]) |
|
412 |
try: |
|
413 |
app_doc_data = AppDocData.instance() |
|
414 |
configs = app_doc_data.getConfigs('Size', 'Symbol') |
|
415 |
size_symbols = configs[0].value.replace(' ', '').split(',') if 1 == len(configs) else ['"'] |
|
416 | ||
417 |
inch_str = str(inch_str) |
|
418 |
for symbol in size_symbols: |
|
419 |
inchs = inch_str.replace(symbol, '') |
|
420 |
inchs = inchs.replace('"', '').split('-') |
|
421 | ||
422 |
number = 0 |
|
423 |
for inch in inchs: |
|
424 |
if '/' not in inch: |
|
425 |
number += float(inch) |
|
426 |
else: |
|
427 |
fraction = inch.split('/') |
|
428 |
number += float(fraction[0]) / float(fraction[1]) |
|
429 |
except Exception as ex: |
|
430 |
from App import App |
|
431 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
432 |
sys.exc_info()[-1].tb_lineno) |
|
433 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
434 | ||
435 |
return 0 |
|
421 | 436 | |
422 | 437 |
return number |
423 | 438 |
내보내기 Unified diff