프로젝트

일반

사용자정보

개정판 c61d4ce0

IDc61d4ce0dad0b08a572bdafa69858309c2034e61
상위 cdfc1f96
하위 8d6386dd

함의성이(가) 약 일년 전에 추가함

add content_size to xml

Change-Id: I188e4c5cc3e757160e527e56d1b5c628b6738402

차이점 보기:

DTI_PID/DTI_PID/Commands/SaveWorkCommand.py
92 92
        app_doc_data = AppDocData.instance()
93 93
        path = os.path.join(app_doc_data.getCurrentProject().getTempPath(), app_doc_data.imgName + '.xml')
94 94
        xml, result = xg.write_to_xml(path, app_doc_data.activeDrawing.width, app_doc_data.activeDrawing.height,
95
                                    allItems, app_doc_data.tracerLineNos + [app_doc_data._connected_items_lists])
95
                                    allItems, app_doc_data.tracerLineNos + [app_doc_data._connected_items_lists], ','.join([str(num) for num in app_doc_data.activeDrawing.get_contents_size_from_image()[:-2]]))
96 96
        if xml:
97 97
            from xml.etree import ElementTree
98 98
            ElementTree.ElementTree(xml).write(path)
DTI_PID/DTI_PID/Drawing.py
221 221

  
222 222
        self._image = None
223 223

  
224
    def get_contents_size_from_image(self) -> list:
225
        """get actual size of image from image file"""
226
        import cv2
227

  
228
        min_x, min_y, max_x, max_y, width, height = None, None, None, None, None, None
229

  
230
        img = self.image.copy()
231
        _width = img.shape[1]
232
        _height = img.shape[0]
233
        #img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
234
        img = cv2.bitwise_not(img)  # background should be 'BLACK'
235
        contours, hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
236
        for cnt in contours:
237
            x, y, width, height = cv2.boundingRect(cnt)
238
            min_x = x if not min_x else min(x, min_x)
239
            min_y = y if not min_y else min(y, min_y)
240
            max_x = x + width if not max_x else max(x + width, max_x)
241
            max_y = y + height if not max_y else max(y + height, max_y)
242

  
243
        return min_x, min_y, max_x - min_x, max_y - min_y, _width, _height
244

  
224 245
    '''
225 246
        @brief  getter of attrs
226 247
        @author humkyung
227 248
        @date   2018.07.07
228 249
    '''
229

  
230 250
    @property
231 251
    def attrs(self):
232 252
        return self._attrs
DTI_PID/DTI_PID/ImportTextFromCADDialog.py
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'):
DTI_PID/DTI_PID/XmlGenerator.py
13 13
ROOT_NODE_NAME = "DWG"
14 14
ROOT_DWGNAME_NODE_NAME = "DWGNAME"
15 15
ROOT_SIZE_NODE_NAME = "SIZE"
16
ROOT_CONTENT_SIZE = "CONTENT_SIZE"
16 17

  
17 18
SYMBOL_LIST_NODE_NAME = "SYMBOLS"
18 19
TEXT_INFO_LIST_NODE_NAME = "TEXTINFOS"
......
387 388

  
388 389
    ElementTree(root).write(xmlPath)
389 390

  
390
def write_to_xml(path, pidWidth, pidHeight, items, tracer_line_nos):
391
def write_to_xml(path, pidWidth, pidHeight, items, tracer_line_nos, contentSize=''):
391 392
    """write xml data"""
392 393
    from EngineeringAbstractItem import QEngineeringAbstractItem
393 394
    from EngineeringNoteItem import QEngineeringNoteItem
......
417 418

  
418 419
    SubElement(xml, ROOT_DWGNAME_NODE_NAME).text = os.path.splitext(os.path.basename(path))[0]
419 420
    SubElement(xml, ROOT_SIZE_NODE_NAME).text = str(pidWidth) + "," + str(pidHeight)
421
    SubElement(xml, ROOT_CONTENT_SIZE).text = contentSize
420 422
    symbolListNode = Element(SYMBOL_LIST_NODE_NAME)  # Symbol List Node
421 423
    textInfoListNode = Element(TEXT_INFO_LIST_NODE_NAME)  # Text Info List Node
422 424
    noteTextInfoListNode = Element(NOTE_TEXT_INFO_LIST_NOTE_NAME)

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)