개정판 85a460a6
issue #622:
- write instrument attributes and owner of text
DTI_PID/DTI_PID/Shapes/EngineeringInstrumentItem.py | ||
---|---|---|
126 | 126 |
for attr in attributes: |
127 | 127 |
if rect.contains(attr.center()): |
128 | 128 |
if issubclass(type(attr), QEngineeringTextItem): |
129 |
attr.owner = self # set owner of text |
|
129 | 130 |
self._texts.append(attr) |
130 | 131 |
elif issubclass(type(attr), SymbolSvgItem): |
132 |
attr._owner = self.uid # set owner of symbol |
|
131 | 133 |
self._symbols.append(attr) |
132 | 134 |
|
133 | 135 |
self._texts = sorted(self._texts, key=lambda attr: attr.loc[1]) # sort by y coordinate |
DTI_PID/DTI_PID/Shapes/EngineeringTextItem.py | ||
---|---|---|
56 | 56 |
''' |
57 | 57 |
@property |
58 | 58 |
def owner(self): |
59 |
import uuid |
|
60 |
|
|
61 |
# find owner with uid |
|
62 |
if self._owner is not None and type(self._owner) is uuid.UUID: |
|
63 |
matches = [x for x in self.scene.items() if hasattr(x, 'uid') and x.uid == self._owner] |
|
64 |
return matches[0] |
|
65 |
# up to here |
|
66 |
|
|
59 | 67 |
return self._owner |
60 | 68 |
|
61 | 69 |
''' |
... | ... | |
418 | 426 |
''' |
419 | 427 |
@staticmethod |
420 | 428 |
def fromXml(node): |
429 |
import uuid |
|
421 | 430 |
from TextItemFactory import TextItemFactory |
422 | 431 |
from AppDocData import AppDocData |
423 | 432 |
from EngineeringNoteItem import QEngineeringNoteItem |
... | ... | |
433 | 442 |
height = float(node.find('HEIGHT').text) if node.find('HEIGHT') is not None else 0 |
434 | 443 |
angle = float(node.find('ANGLE').text) if node.find('ANGLE') is not None else 0 |
435 | 444 |
value = node.find('VALUE').text |
436 |
uid = node.find('UID') |
|
437 | 445 |
attributeValue = node.find('ATTRIBUTEVALUE') |
438 | 446 |
name = node.find('NAME').text |
439 | 447 |
if name == 'TEXT': |
... | ... | |
459 | 467 |
item.setPlainText(value) |
460 | 468 |
item.setToolTip(value) |
461 | 469 |
|
470 |
# set uid and owner of item |
|
471 |
if item is not None: |
|
472 |
item.uid = uuid.UUID(node.find('UID').text) |
|
473 |
|
|
474 |
if node.find('OWNER') is not None: |
|
475 |
item._owner = uuid.UUID(node.find('OWNER').text) |
|
476 |
|
|
462 | 477 |
## assign area |
463 | 478 |
if item is not None: |
464 | 479 |
if node.find('AREA') is None: |
... | ... | |
530 | 545 |
areaNode = Element('AREA') |
531 | 546 |
areaNode.text = self.area |
532 | 547 |
node.append(areaNode) |
548 |
|
|
549 |
# write owner |
|
550 |
if self.owner is not None: |
|
551 |
ownerNode = Element('OWNER') |
|
552 |
ownerNode.text = str(self.owner.uid) |
|
553 |
node.append(ownerNode) |
|
554 |
# up to here |
|
533 | 555 |
except Exception as ex: |
534 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
556 |
from App import App |
|
557 |
from AppDocData import MessageType |
|
558 |
|
|
559 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
560 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
561 |
|
|
535 | 562 |
return str(self.uid) |
536 | 563 |
|
537 | 564 |
return node |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
618 | 618 |
def toXml(self): |
619 | 619 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
620 | 620 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
621 |
from SymbolAttr import SymbolAttr |
|
621 | 622 |
|
622 | 623 |
try: |
623 | 624 |
node = Element('SYMBOL') |
... | ... | |
705 | 706 |
node.append(areaNode) |
706 | 707 |
|
707 | 708 |
attributesNode = Element('SYMBOLATTRIBUTES') |
708 |
for attr in self.attrs: |
|
709 |
if type(attr) is UserInputAttribute: |
|
710 |
attributesNode.append(attr.toXml()) |
|
711 |
elif type(attr) is not tuple: |
|
712 |
attributeNode = Element('SYMBOLATTRIBUTE') |
|
713 |
attributeNode.text = str(attr.uid) |
|
714 |
attributesNode.append(attributeNode) |
|
709 |
_attrs = self.getAttributes() |
|
710 |
for attr in _attrs: |
|
711 |
if type(attr) is SymbolAttr: |
|
712 |
_node = attr.toXml() |
|
713 |
_node.text = _attrs[attr] |
|
714 |
attributesNode.append(_node) |
|
715 | 715 |
elif type(attr) is tuple and type(self) is QEngineeringSpecBreakItem: |
716 | 716 |
attributeNode = Element(attr[0].upper().replace(' ','')) |
717 | 717 |
attributeNode.text = str(attr[1] if attr[1] is not None else '') |
... | ... | |
724 | 724 |
node.append(currentPointModeIndexNode) |
725 | 725 |
|
726 | 726 |
except Exception as ex: |
727 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
727 |
from App import App |
|
728 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
729 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
730 |
|
|
728 | 731 |
return str(self.uid) |
729 | 732 |
|
730 | 733 |
return node |
... | ... | |
742 | 745 |
def fromXml(node): |
743 | 746 |
import uuid |
744 | 747 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
748 |
from SymbolAttr import SymbolAttr |
|
745 | 749 |
item = [None, None] |
746 | 750 |
|
747 | 751 |
try: |
... | ... | |
807 | 811 |
|
808 | 812 |
attributes = node.find('SYMBOLATTRIBUTES') |
809 | 813 |
if attributes is not None: |
810 |
for attr in attributes.iter('SYMBOLATTRIBUTE'): |
|
811 |
item[0].attrs.append(attr.text) |
|
814 |
for attr in attributes.iter('ATTRIBUTE'): |
|
815 |
_attr = SymbolAttr.fromXml(attr) |
|
816 |
item[0].attrs[_attr] = attr.text |
|
812 | 817 |
for attr in attributes.iter('USERINPUTATTRIBUTE'): |
813 | 818 |
typeUID = attr.find('TYPEUID').text |
814 | 819 |
typeValue = attr.find('TYPEVALUE').text |
... | ... | |
831 | 836 |
|
832 | 837 |
item[1] = owner |
833 | 838 |
except Exception as ex: |
834 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
839 |
from App import App |
|
840 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
841 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
835 | 842 |
|
836 | 843 |
return item |
837 | 844 |
|
DTI_PID/DTI_PID/TextDetector.py | ||
---|---|---|
209 | 209 |
y = tInfo.getY() - round(offset[1]) |
210 | 210 |
img = imgOCR[y:y+tInfo.getH(), x:x+tInfo.getW()] |
211 | 211 |
|
212 |
#cv2.imwrite('c:\\temp\\ocr.png', img) |
|
213 |
|
|
214 | 212 |
# set angle 0 if symbol contains the text area is instrumentation |
215 | 213 |
category = None |
216 | 214 |
contains = [symbol for symbol in searchedSymbolList if symbol.contains(tInfo)] |
내보내기 Unified diff