773 |
773 |
raise RuntimeError('OdReadExMgd threw error in ' + drawing_name + ' :\n' + str(stderr)) if len(stderr) != 0 else \
|
774 |
774 |
RuntimeError('OdReadExMgd threw error in ' + drawing_name + ' :\n' + str(stdout))
|
775 |
775 |
|
776 |
|
"""load image for graphic"""
|
|
776 |
"""load content size and image for graphic"""
|
777 |
777 |
drawing_file_path = os.path.join(drawing_path, drawing_name + '.PNG')
|
778 |
778 |
if not os.path.exists(drawing_file_path):
|
779 |
779 |
continue
|
780 |
780 |
drawing = Drawing(str(uuid.uuid4()), drawing_name + ".PNG", None)
|
781 |
|
_image = drawing.image
|
782 |
|
bytesPerLine = _image.shape[1]
|
783 |
|
image = QImage(_image.data, _image.shape[1], _image.shape[0], bytesPerLine, QImage.Format_Indexed8)
|
784 |
|
id2_bbox = self.get_contents_size_from_image(drawing_file_path)
|
|
781 |
#_image = drawing.image
|
|
782 |
#bytesPerLine = _image.shape[1]
|
|
783 |
#image = QImage(_image.data, _image.shape[1], _image.shape[0], bytesPerLine, QImage.Format_Indexed8)
|
|
784 |
#self.id2_bbox = self.get_contents_size_from_image(drawing_file_path)
|
|
785 |
self.id2_bbox = drawing.get_contents_size_from_image()
|
785 |
786 |
"""up to here"""
|
786 |
787 |
|
787 |
788 |
"""parse layer, line type and symbol"""
|
... | ... | |
815 |
816 |
max_values[0] - min_values[0], max_values[1] - min_values[1]]
|
816 |
817 |
|
817 |
818 |
if self.ui.checkBoxAuto.isChecked():
|
818 |
|
scale_x = id2_bbox[2] / autocad_bbox[2]
|
819 |
|
scale_y = id2_bbox[3] / autocad_bbox[3]
|
|
819 |
scale_x = self.id2_bbox[2] / autocad_bbox[2]
|
|
820 |
scale_y = self.id2_bbox[3] / autocad_bbox[3]
|
820 |
821 |
self.scales = [scale_x, scale_y]
|
821 |
|
offsets = [id2_bbox[0] - autocad_bbox[0] * scale_x, id2_bbox[3] + id2_bbox[1]]
|
|
822 |
offsets = [self.id2_bbox[0] - autocad_bbox[0] * scale_x, self.id2_bbox[3] + self.id2_bbox[1]]
|
822 |
823 |
self.offsets = offsets + [autocad_bbox[1]]
|
823 |
824 |
else:
|
824 |
825 |
self.scales = [self.ui.doubleSpinBox.value(), self.ui.doubleSpinBox_2.value()]
|
825 |
|
self.offsets = [self.ui.spinBoxTextX.value(), self.ui.spinBoxTextY.value(), id2_bbox[5]]
|
|
826 |
self.offsets = [self.ui.spinBoxTextX.value(), self.ui.spinBoxTextY.value(), self.id2_bbox[5]]
|
826 |
827 |
|
827 |
828 |
for block_ref_record in autocad_xml_root.iter('AcDbBlockReference'):
|
828 |
829 |
block_name = block_ref_record.attrib['Name']
|
... | ... | |
999 |
1000 |
|
1000 |
1001 |
autocad_xml_root = autocad_xml.getroot()
|
1001 |
1002 |
|
1002 |
|
id2_bbox = self.get_contents_size_from_image(id2_image_file)
|
|
1003 |
#self.id2_bbox = self.get_contents_size_from_image(id2_image_file)
|
|
1004 |
self.id2_bbox = drawing.get_contents_size_from_image()
|
1003 |
1005 |
|
1004 |
1006 |
for blk_tbl_record in autocad_xml_root.iter('AcDbBlockTableRecord'):
|
1005 |
1007 |
if blk_tbl_record.attrib['Name'].upper() != '*Model_Space'.upper():
|
... | ... | |
1013 |
1015 |
max_values[0] - min_values[0], max_values[1] - min_values[1]]
|
1014 |
1016 |
|
1015 |
1017 |
if self.ui.checkBoxAuto.isChecked():
|
1016 |
|
scale_x = id2_bbox[2] / autocad_bbox[2]
|
1017 |
|
scale_y = id2_bbox[3] / autocad_bbox[3]
|
|
1018 |
scale_x = self.id2_bbox[2] / autocad_bbox[2]
|
|
1019 |
scale_y = self.id2_bbox[3] / autocad_bbox[3]
|
1018 |
1020 |
self.scales = [scale_x, scale_y]
|
1019 |
|
offsets = [id2_bbox[0] - autocad_bbox[0] * scale_x, id2_bbox[3] + id2_bbox[1]]
|
|
1021 |
offsets = [self.id2_bbox[0] - autocad_bbox[0] * scale_x, self.id2_bbox[3] + self.id2_bbox[1]]
|
1020 |
1022 |
self.offsets = offsets + [autocad_bbox[1]]
|
1021 |
1023 |
else:
|
1022 |
1024 |
self.scales = [self.ui.doubleSpinBox.value(), self.ui.doubleSpinBox_2.value()]
|
1023 |
|
self.offsets = [self.ui.spinBoxTextX.value(), self.ui.spinBoxTextY.value(), id2_bbox[5]]
|
|
1025 |
self.offsets = [self.ui.spinBoxTextX.value(), self.ui.spinBoxTextY.value(), self.id2_bbox[5]]
|
1024 |
1026 |
|
1025 |
1027 |
for blk_ref in blk_tbl_record.iter('AcDbBlockReference'):
|
1026 |
1028 |
node = self.symbol_info(blk_ref)
|
... | ... | |
1067 |
1069 |
App.mainWnd().symbolTreeWidget.initSymbolTreeView()
|
1068 |
1070 |
QMessageBox.information(self, self.tr('Information'), self.tr('Symbol creation complete. Please click "Symbol Refresh" Button'))
|
1069 |
1071 |
|
1070 |
|
def get_contents_size_from_image(self, img_file_path: str) -> list:
|
1071 |
|
"""get actual size of image from image file"""
|
1072 |
|
from AppDocData import AppDocData
|
1073 |
|
import cv2
|
1074 |
|
|
1075 |
|
min_x, min_y, max_x, max_y, width, height = None, None, None, None, None, None
|
1076 |
|
|
1077 |
|
img = AppDocData.my_imread(file_path=img_file_path)
|
1078 |
|
_width = img.shape[1]
|
1079 |
|
_height = img.shape[0]
|
1080 |
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
1081 |
|
img = cv2.bitwise_not(img) # background should be 'BLACK'
|
1082 |
|
contours, hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
1083 |
|
for cnt in contours:
|
1084 |
|
x, y, width, height = cv2.boundingRect(cnt)
|
1085 |
|
min_x = x if not min_x else min(x, min_x)
|
1086 |
|
min_y = y if not min_y else min(y, min_y)
|
1087 |
|
max_x = x + width if not max_x else max(x + width, max_x)
|
1088 |
|
max_y = y + height if not max_y else max(y + height, max_y)
|
1089 |
|
|
1090 |
|
del img
|
1091 |
|
|
1092 |
|
return min_x, min_y, max_x - min_x, max_y - min_y, _width, _height
|
1093 |
|
|
1094 |
1072 |
def on_import_autocad(self):
|
1095 |
1073 |
"""
|
1096 |
1074 |
import line, text and symbol from autocad
|
... | ... | |
1200 |
1178 |
id2_xml_root = id2_xml.getroot()
|
1201 |
1179 |
|
1202 |
1180 |
#id2_bbox = [0, 0, 9600, 6781]
|
1203 |
|
id2_bbox = self.get_contents_size_from_image(id2_image_file)
|
|
1181 |
drawing = Drawing(str(uuid.uuid4()), file_name + ".PNG", None)
|
|
1182 |
#self.id2_bbox = self.get_contents_size_from_image(id2_image_file)
|
|
1183 |
self.id2_bbox = drawing.get_contents_size_from_image()
|
|
1184 |
|
|
1185 |
content_size_node = id2_xml_root.find(xg.ROOT_CONTENT_SIZE)
|
|
1186 |
if content_size_node is None:
|
|
1187 |
SubElement(id2_xml_root, xg.ROOT_CONTENT_SIZE).text = ','.join([str(num) for num in self.id2_bbox[:-2]])
|
|
1188 |
elif not content_size_node.text:
|
|
1189 |
content_size_node.text = ','.join([str(num) for num in self.id2_bbox[:-2]])
|
1204 |
1190 |
|
1205 |
1191 |
if 'Symbol' in will_be_converted_items:
|
1206 |
1192 |
symbols_node = id2_xml_root.find(xg.SYMBOL_LIST_NODE_NAME)
|
... | ... | |
1260 |
1246 |
max_values[0] - min_values[0], max_values[1] - min_values[1]]
|
1261 |
1247 |
|
1262 |
1248 |
if self.ui.checkBoxAuto.isChecked():
|
1263 |
|
scale_x = id2_bbox[2] / autocad_bbox[2]
|
1264 |
|
scale_y = id2_bbox[3] / autocad_bbox[3]
|
|
1249 |
scale_x = self.id2_bbox[2] / autocad_bbox[2]
|
|
1250 |
scale_y = self.id2_bbox[3] / autocad_bbox[3]
|
1265 |
1251 |
self.scales = [scale_x, scale_y]
|
1266 |
|
offsets = [id2_bbox[0] - autocad_bbox[0] * scale_x, id2_bbox[3] + id2_bbox[1]]
|
|
1252 |
offsets = [self.id2_bbox[0] - autocad_bbox[0] * scale_x, self.id2_bbox[3] + self.id2_bbox[1]]
|
1267 |
1253 |
self.offsets = offsets + [autocad_bbox[1]]
|
1268 |
1254 |
else:
|
1269 |
1255 |
self.scales = [self.ui.doubleSpinBox.value(), self.ui.doubleSpinBox_2.value()]
|
1270 |
|
self.offsets = [self.ui.spinBoxTextX.value(), self.ui.spinBoxTextY.value(), id2_bbox[5]]
|
|
1256 |
self.offsets = [self.ui.spinBoxTextX.value(), self.ui.spinBoxTextY.value(), self.id2_bbox[5]]
|
1271 |
1257 |
|
1272 |
1258 |
if 'Text' in will_be_converted_items:
|
1273 |
1259 |
for record in blk_tbl_record.iter('AcDbText'):
|