603 |
603 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
604 |
604 |
f"{sys.exc_info()[-1].tb_lineno}"
|
605 |
605 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
|
606 |
else:
|
|
607 |
from App import App
|
|
608 |
from AppDocData import MessageType
|
|
609 |
|
|
610 |
message = 'There is no xml file'
|
|
611 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
606 |
612 |
|
607 |
613 |
def symbol_to_xml(self, blk_ref_node, id2_bbox, autocad_bbox, mapping_configs: list) -> str:
|
608 |
614 |
"""try to convert block reference element to id2 xml"""
|
... | ... | |
622 |
628 |
scale, offsets)
|
623 |
629 |
angle = round(float(blk_ref_node.attrib['Angle']), 2)
|
624 |
630 |
|
|
631 |
"""check if maxtents or minextents attribute exists"""
|
|
632 |
if 'MaxExtents' not in blk_ref_node.attrib or 'MinExtents' not in blk_ref_node.attrib:
|
|
633 |
return None
|
|
634 |
|
625 |
635 |
min_extents, max_extents = None, None
|
626 |
636 |
tokens = blk_ref_node.attrib['MaxExtents'].strip('()').split(',')
|
627 |
637 |
if 3 == len(tokens):
|
... | ... | |
655 |
665 |
|
656 |
666 |
item = SymbolSvgItem.createItem(symbol.getType(), symbol.getName(), path=svg_file_path)
|
657 |
667 |
loc = [min(min_extents[0], max_extents[0]), min(min_extents[1], max_extents[1])]
|
658 |
|
connPts = None
|
659 |
|
strConnPts = symbol.getConnectionPoint()
|
660 |
|
if strConnPts is not None and strConnPts != '':
|
661 |
|
connPts = [(float(x.split(',')[0]), float(x.split(',')[1])) if len(x.split(',')) == 2 else (
|
662 |
|
x.split(',')[0], float(x.split(',')[1]), float(x.split(',')[2])) \
|
663 |
|
for x in strConnPts.split('/')]
|
664 |
|
|
665 |
|
item.buildItem(name, symbol.getType(), angle, loc, (_width, _height), origin, connPts=connPts,
|
666 |
|
parentSymbol=None, childSymbol=None, hasInstrumentLabel=False, dbUid=uid)
|
|
668 |
item.buildItem(name, symbol.getType(), angle, loc, (_width, _height), origin,
|
|
669 |
connPts=symbol.parse_connection_pts(origin), parentSymbol=None, childSymbol=None,
|
|
670 |
hasInstrumentLabel=False, dbUid=uid)
|
667 |
671 |
item.converted = True
|
668 |
672 |
|
669 |
673 |
app_doc_data = AppDocData.instance()
|
... | ... | |
822 |
826 |
|
823 |
827 |
"""get id2 line type uid"""
|
824 |
828 |
line_type, line_type_cond = get_line_type(layers, line_types, line_node.attrib['Layer'],
|
825 |
|
line_node.attrib['Linetype']), None
|
|
829 |
line_node.attrib['Linetype']), None
|
826 |
830 |
model = self.ui.treeViewLineType.model()
|
827 |
831 |
for row in range(model.rowCount()):
|
828 |
832 |
parent_index = model.index(row, 0)
|
... | ... | |
842 |
846 |
node = None
|
843 |
847 |
for idx in range(len(pts) - 1):
|
844 |
848 |
start, end = pts[idx], pts[idx + 1]
|
|
849 |
dx, dy = end[0] - start[0], end[1] - start[1]
|
845 |
850 |
|
846 |
|
item = QEngineeringLineItem(vertices=[start, end], thickness=5)
|
847 |
|
if item.length() < 40:
|
|
851 |
"""check if length is zero"""
|
|
852 |
length = dx*dx + dy*dy
|
|
853 |
if length == 0:
|
848 |
854 |
continue
|
849 |
|
|
|
855 |
|
|
856 |
item = QEngineeringLineItem(vertices=[start, end], thickness=5)
|
|
857 |
|
850 |
858 |
angle = math.degrees(item.angle())
|
851 |
859 |
if not ((-5 < angle < 5) or (85 < angle < 95) or (175 < angle < 185) or (355 < angle < 365)):
|
852 |
860 |
continue
|
... | ... | |
858 |
866 |
|
859 |
867 |
node = item.toXml()
|
860 |
868 |
|
861 |
|
'''
|
862 |
|
"""create a element for id2"""
|
863 |
|
node = Element('LINE')
|
864 |
|
node.attrib['OWNER'] = 'None'
|
865 |
|
_node = SubElement(node, 'UID')
|
866 |
|
_node.text = str(uuid.uuid4())
|
867 |
|
|
868 |
|
_node = SubElement(node, 'STARTPOINT')
|
869 |
|
_node.text = f"{start[0]},{start[1]}"
|
870 |
|
|
871 |
|
_node = SubElement(node, 'ENDPOINT')
|
872 |
|
_node.text = f"{end[0]},{end[1]}"
|
873 |
|
|
874 |
|
if line_type_cond:
|
875 |
|
_node = SubElement(node, 'TYPE')
|
876 |
|
_node.text = line_type_cond.name
|
877 |
|
_node.attrib['TYPEUID'] = line_type_cond.uid
|
878 |
|
|
879 |
|
_node = SubElement(node, 'AREA')
|
880 |
|
_node.text = 'Drawing'
|
881 |
|
|
882 |
|
_node = SubElement(node, 'THICKNESS')
|
883 |
|
_node.text = '1'
|
884 |
|
|
885 |
|
_node = SubElement(node, 'FLOWMARK')
|
886 |
|
_node.text = 'None'
|
887 |
|
|
888 |
|
_node = SubElement(node, 'CONNECTORS')
|
889 |
|
for conn in range(2):
|
890 |
|
__node = SubElement(_node, 'CONNECTOR')
|
891 |
|
__node.attrib['CONNECTED_AT'] = '0'
|
892 |
|
__node.attrib['UID'] = str(uuid.uuid4())
|
893 |
|
___node = SubElement(__node, 'CONNECTEDITEM')
|
894 |
|
___node.text = 'None'
|
895 |
|
___node = SubElement(__node, 'CONNECTPOINT')
|
896 |
|
___node.text = f"{start[0]},{start[1]}" if conn == 0 else f"{end[0]},{end[1]}"
|
897 |
|
___node = SubElement(__node, 'SCENECONNECTPOINT')
|
898 |
|
___node.text = f"{start[0]},{start[1]}" if conn == 0 else f"{end[0]},{end[1]}"
|
899 |
|
"""up to here"""
|
900 |
|
'''
|
901 |
|
|
902 |
869 |
return node
|
903 |
|
|
904 |
870 |
except Exception as ex:
|
905 |
871 |
from App import App
|
906 |
872 |
from AppDocData import MessageType
|
... | ... | |
910 |
876 |
|
911 |
877 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
912 |
878 |
|
|
879 |
return None
|
|
880 |
|
913 |
881 |
def close(self):
|
914 |
|
QDialog.reject(self)
|
|
882 |
QDialog.reject(self)
|