개정판 00027421
graphic image extract from cad
Change-Id: I47e04875389948e8ba56ab3b0dacf67893fc8ca3
DTI_PID/DTI_PID/ImportTextFromCADDialog.py | ||
---|---|---|
11 | 11 |
import subprocess |
12 | 12 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree, parse |
13 | 13 |
from SymbolRegiDataListDialog import QSymbolRegiDataListDialog |
14 |
import uuid |
|
15 |
from Drawing import Drawing |
|
14 | 16 |
|
15 | 17 |
import ImportTextFromCAD_UI |
16 | 18 |
|
... | ... | |
685 | 687 |
:return: |
686 | 688 |
""" |
687 | 689 |
project = AppDocData.instance().getCurrentProject() |
690 |
drawing_path = project.getDrawingFilePath() |
|
688 | 691 |
|
689 | 692 |
options = QFileDialog.Options() |
690 | 693 |
options |= QFileDialog.DontUseNativeDialog |
691 | 694 |
files, _ = QFileDialog.getOpenFileNames(self, self.tr('Import', "Select AutoCAD File"), |
692 |
os.path.join(project.getDrawingFilePath(), 'Native'),
|
|
695 |
os.path.join(drawing_path, 'Native'),
|
|
693 | 696 |
"dwg files (*.dwg)", options=options) |
694 | 697 |
if files: |
695 | 698 |
self.ui.lineEditCAD.setText(files[0]) if len(files) == 1 else \ |
... | ... | |
703 | 706 |
if os.path.exists(_file): |
704 | 707 |
try: |
705 | 708 |
file = os.path.normpath(_file) |
709 |
drawing_name = os.path.splitext(os.path.basename(file))[0] |
|
706 | 710 |
executable = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'OdReadExMgd', |
707 | 711 |
'OdReadExMgd.exe') |
708 | 712 |
args = [executable, file, '0', '0', '1', '1' if int(self.ui.checkBoxGenDrawing.checkState()) is int(Qt.Checked) else '0'] |
... | ... | |
721 | 725 |
raise RuntimeError('OdReadExMgd threw error:\n' + str(stderr)) if len(stderr) != 0 else \ |
722 | 726 |
RuntimeError('OdReadExMgd threw error:\n' + str(stdout)) |
723 | 727 |
|
728 |
"""load image for graphic""" |
|
729 |
drawing_file_path = os.path.join(drawing_path, drawing_name + '.PNG') |
|
730 |
if not os.path.exists(drawing_file_path): |
|
731 |
continue |
|
732 |
drawing = Drawing(str(uuid.uuid4()), drawing_name + ".PNG", None) |
|
733 |
_image = drawing.image |
|
734 |
bytesPerLine = _image.shape[1] |
|
735 |
image = QImage(_image.data, _image.shape[1], _image.shape[0], bytesPerLine, QImage.Format_Indexed8) |
|
736 |
id2_bbox = self.get_contents_size_from_image(drawing_file_path) |
|
737 |
"""up to here""" |
|
738 |
|
|
724 | 739 |
"""parse layer, line type and symbol""" |
725 |
autocad_xml_path = os.path.join(os.path.dirname(file), |
|
726 |
os.path.splitext(os.path.basename(file))[0] + '.xml') |
|
740 |
autocad_xml_path = os.path.join(os.path.dirname(file), drawing_name + '.xml') |
|
727 | 741 |
autocad_xml = parse(autocad_xml_path) |
728 | 742 |
autocad_xml_root = autocad_xml.getroot() |
729 | 743 |
|
... | ... | |
741 | 755 |
|
742 | 756 |
self._line_types.append(line_type_tbl_record.attrib['Name']) |
743 | 757 |
|
758 |
for blk_tbl_record in autocad_xml_root.iter('AcDbBlockTableRecord'): |
|
759 |
if blk_tbl_record.attrib['Name'].upper() != '*Model_Space'.upper(): |
|
760 |
continue |
|
761 |
|
|
762 |
min_values = [float(token) for token in |
|
763 |
blk_tbl_record.attrib['MinExtents'].strip('()').split(',')] |
|
764 |
max_values = [float(token) for token in |
|
765 |
blk_tbl_record.attrib['MaxExtents'].strip('()').split(',')] |
|
766 |
autocad_bbox = [min_values[0], min_values[1], |
|
767 |
max_values[0] - min_values[0], max_values[1] - min_values[1]] |
|
768 |
|
|
769 |
if self.ui.checkBoxAuto.isChecked(): |
|
770 |
scale_x = id2_bbox[2] / autocad_bbox[2] |
|
771 |
scale_y = id2_bbox[3] / autocad_bbox[3] |
|
772 |
self.scales = [scale_x, scale_y] |
|
773 |
offsets = [id2_bbox[0] - autocad_bbox[0] * scale_x, id2_bbox[3] + id2_bbox[1]] |
|
774 |
self.offsets = offsets + [autocad_bbox[1]] |
|
775 |
else: |
|
776 |
self.scales = [self.ui.doubleSpinBox.value(), self.ui.doubleSpinBox_2.value()] |
|
777 |
self.offsets = [self.ui.spinBoxTextX.value(), self.ui.spinBoxTextY.value(), id2_bbox[5]] |
|
778 |
|
|
744 | 779 |
for block_ref_record in autocad_xml_root.iter('AcDbBlockReference'): |
745 | 780 |
block_name = block_ref_record.attrib['Name'] |
746 | 781 |
if block_name in self._symbol_types: |
747 | 782 |
continue |
748 |
|
|
783 |
|
|
749 | 784 |
self._symbol_types.append(block_name) |
785 |
|
|
786 |
'''save graphic''' |
|
787 |
node = self.symbol_info(block_ref_record) |
|
788 |
if node and block_name.split('+')[0] == 'Graphic': |
|
789 |
symbolImage = image.copy(round(node[2][0]), round(node[2][1]), math.ceil(node[3] + 2), math.ceil(node[4] + 1)) |
|
790 |
file_name = drawing_name + '++' + block_name + '++' + str(round(node[2][0])) + '++' + str(round(node[2][1])) |
|
791 |
image_file_path = os.path.join(project.getGraphicFilePath(), file_name + '.PNG') |
|
792 |
symbolImage.save(image_file_path, 'PNG') |
|
793 |
'''up to here''' |
|
750 | 794 |
"""up to here""" |
751 | 795 |
|
752 | 796 |
self._dwgs.append(file) |
... | ... | |
843 | 887 |
|
844 | 888 |
def on_import_legend(self): |
845 | 889 |
import XmlGenerator as xg |
846 |
import uuid |
|
847 |
from Drawing import Drawing |
|
848 | 890 |
from App import App |
849 | 891 |
|
850 | 892 |
if not self._dwgs: |
... | ... | |
1177 | 1219 |
QMessageBox.information(self, self.tr('Information'), self.tr('Importing finished!'), |
1178 | 1220 |
QMessageBox.Close) |
1179 | 1221 |
|
1180 |
def symbol_info(self, blk_ref_node) -> str:
|
|
1222 |
def symbol_info(self, blk_ref_node): |
|
1181 | 1223 |
"""try to convert block reference element to id2 xml""" |
1182 | 1224 |
import symbol |
1183 | 1225 |
|
DTI_PID/DTI_PID/Project.py | ||
---|---|---|
69 | 69 |
:return: drawing file path |
70 | 70 |
""" |
71 | 71 |
return os.path.join(self.getPath(), 'drawings') |
72 |
|
|
73 |
def getGraphicFilePath(self) -> str: |
|
74 |
""" |
|
75 |
:return: graphic file path |
|
76 |
""" |
|
77 |
return os.path.join(self.getPath(), 'graphic') |
|
72 | 78 |
|
73 | 79 |
def getOutputPath(self) -> str: |
74 | 80 |
""" |
75 | 81 |
:return: output path |
76 | 82 |
""" |
77 | 83 |
return os.path.join(self.getPath(), 'output') |
78 |
|
|
79 | 84 |
def getImageFilePath(self) -> str: |
80 | 85 |
""" |
81 | 86 |
:return: image file path |
... | ... | |
87 | 92 |
@author Jeongwoo |
88 | 93 |
@date 2018.04.10 |
89 | 94 |
''' |
90 |
|
|
91 | 95 |
def getDbFilePath(self): |
92 | 96 |
return os.path.join(self.getPath(), 'db') |
93 | 97 |
|
... | ... | |
96 | 100 |
@author humkyung |
97 | 101 |
@date 2018.04.08 |
98 | 102 |
''' |
99 |
|
|
100 | 103 |
def getSvgFilePath(self): |
101 | 104 |
return os.path.join(self.getPath(), 'svg') |
102 | 105 |
|
... | ... | |
109 | 112 |
@author euisung |
110 | 113 |
@date 2018.09.28 |
111 | 114 |
''' |
112 |
|
|
113 | 115 |
def getTrainingFilePath(self): |
114 | 116 |
return os.path.join(self.getPath(), 'Training') |
115 | 117 |
|
... | ... | |
139 | 141 |
@author humkyung |
140 | 142 |
@date 2018.04.25 |
141 | 143 |
''' |
142 |
|
|
143 | 144 |
def unit(self): |
144 | 145 |
from AppDocData import AppDocData |
145 | 146 |
res = 'Metric' # default value |
... | ... | |
177 | 178 |
trainingSymbolPath = self.getTrainingSymbolFilePath() |
178 | 179 |
if not os.path.exists(trainingSymbolPath): |
179 | 180 |
os.makedirs(trainingSymbolPath) |
181 |
graphicPath = self.getGraphicFilePath() |
|
182 |
if not os.path.exists(graphicPath): |
|
183 |
os.makedirs(graphicPath) |
|
180 | 184 |
|
181 | 185 |
path = os.path.join(tempDir, 'Tile') |
182 | 186 |
if not os.path.exists(path): |
내보내기 Unified diff