프로젝트

일반

사용자정보

개정판 f01c72e0

IDf01c72e0c33093960b48b072055ceca4057e89a9
상위 a566dddc
하위 2634dac1

함의성이(가) 5년 이상 전에 추가함

issue #000: add text import batch

Change-Id: I070bb51216b1711b0b3b81f74a61a505111d0e6d

차이점 보기:

DTI_PID/DTI_PID/ImportTextFromCADDialog.py
35 35

  
36 36
        options = QFileDialog.Options()
37 37
        options |= QFileDialog.DontUseNativeDialog
38
        selectedDir = QFileDialog.getOpenFileName(self, self.tr('Import', "Select ID2 xml File"), project.getTempPath(), "xml files (*.xml)", options=options)
38
        selectedDir = QFileDialog.getOpenFileNames(self, self.tr('Import', "Select ID2 xml File"), project.getTempPath(), "xml files (*.xml)", options=options)
39 39
        if selectedDir:
40
            self.ui.lineEditID2.setText(selectedDir[0])
40
            self.ui.lineEditID2.setText(selectedDir[0]) if type(selectedDir[0]) is str else self.ui.lineEditID2.setText(str(len(selectedDir[0])) + ' files')
41
            self.xmls = selectedDir[0]
41 42

  
42 43
    def addCADClick(self):
43 44
        project = AppDocData.instance().getCurrentProject()
44 45

  
45 46
        options = QFileDialog.Options()
46 47
        options |= QFileDialog.DontUseNativeDialog
47
        selectedDir = QFileDialog.getOpenFileName(self, self.tr('Import', "Select CAD File"), os.path.join(project.getDrawingFilePath(), 'Native'), "dwg files (*.dwg)", options=options)
48
        selectedDir = QFileDialog.getOpenFileNames(self, self.tr('Import', "Select CAD File"), os.path.join(project.getDrawingFilePath(), 'Native'), "dwg files (*.dwg)", options=options)
48 49
        if selectedDir:
49
            self.ui.lineEditCAD.setText(selectedDir[0])
50
            self.ui.lineEditCAD.setText(selectedDir[0]) if type(selectedDir[0]) is str else self.ui.lineEditCAD.setText(str(len(selectedDir[0])) + ' files')
51
            self.dwgs = selectedDir[0]
50 52
    
51 53
    def importTextFromCAD(self):
52 54
        project = AppDocData.instance().getCurrentProject()
53
        xmlPath = self.ui.lineEditID2.text()
54
        dwgPath = self.ui.lineEditCAD.text()
55
        xmlPaths = self.xmls
56
        dwgPaths = self.dwgs
55 57
        xOffset = self.ui.doubleSpinBoxX.value()
56 58
        yOffset = self.ui.doubleSpinBoxY.value()
57 59
        scale = self.ui.doubleSpinBoxS.value()
58
        if os.path.exists(xmlPath) and os.path.exists(dwgPath) and scale > 0.001:
59
            try:
60
                #filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)) , 'bin64', 'OdReadExMgd.exe')
61
                filePath = os.path.join('E:\Projects\OdReadExMgd\\bin\\x86\Debug', 'OdReadExMgd.exe')
62
                command = filePath + ' {} {} {} {}'.format(dwgPath, xOffset, yOffset, scale)
63
                subprocess.call(command, shell = False)
64

  
65
                textXmlPath = os.path.join(os.path.join(project.getDrawingFilePath(), 'Native'), dwgPath.split('/')[-1].split('.')[0] + '.xml')
66
                textXml = parse(textXmlPath)
67
                originXml = parse(xmlPath)
68
                textRoot = textXml.getroot()
69
                originRoot = originXml.getroot()
70
                self.height = int(originRoot.find('SIZE').text.split(',')[1])
71

  
72
                textInfo = originRoot.find(xg.TEXT_INFO_LIST_NODE_NAME)
73
                textInfo.clear()
74
                #for node in textInfo.iter('ATTRIBUTE'):
75
                #    if node.find('AREA').text == 'None' or node.find('AREA').text == 'Drawing':
76
                #        textInfo.remove(node)
77

  
78
                noteInfo = originRoot.find(xg.NOTE_TEXT_INFO_LIST_NOTE_NAME)
79
                noteInfo.clear()
80
                #for node in noteInfo.iter('ATTRIBUTE'):
81
                #    noteInfo.remove(node)
82
                lineNoInfo = originRoot.find(xg.LINE_NOS_NODE_NAME)
83
                lineNoInfo.clear()
84
                #for node in lineNoInfo.iter('LINE_NO'):
85
                #    lineNoInfo.remove(node)
60

  
61
        if len(xmlPaths) != len(dwgPaths):
62
            QMessageBox.Warning(self, self.tr('Warning'), self.tr('Please check files'), QMessageBox.Close)
63
            return
64

  
65
        for index in range(len(xmlPaths)):
66
            xmlPath = xmlPaths[index]
67
            dwgPath = dwgPaths[index]
68
            if os.path.exists(xmlPath) and os.path.exists(dwgPath) and scale > 0.001:
69
                try:
70
                    #filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)) , 'bin64', 'OdReadExMgd.exe')
71
                    filePath = os.path.join('E:\Projects\OdReadExMgd\\bin\\x86\Debug', 'OdReadExMgd.exe')
72
                    command = filePath + ' {} {} {} {}'.format(dwgPath, xOffset, yOffset, scale)
73
                    subprocess.call(command, shell = False)
74

  
75
                    textXmlPath = os.path.join(os.path.join(project.getDrawingFilePath(), 'Native'), dwgPath.split('/')[-1].split('.')[0] + '.xml')
76
                    textXml = parse(textXmlPath)
77
                    originXml = parse(xmlPath)
78
                    textRoot = textXml.getroot()
79
                    originRoot = originXml.getroot()
80
                    self.height = int(originRoot.find('SIZE').text.split(',')[1])
81

  
82
                    textInfo = originRoot.find(xg.TEXT_INFO_LIST_NODE_NAME)
83
                    textInfo.clear()
84
                    #for node in textInfo.iter('ATTRIBUTE'):
85
                    #    if node.find('AREA').text == 'None' or node.find('AREA').text == 'Drawing':
86
                    #        textInfo.remove(node)
87

  
88
                    noteInfo = originRoot.find(xg.NOTE_TEXT_INFO_LIST_NOTE_NAME)
89
                    noteInfo.clear()
90
                    #for node in noteInfo.iter('ATTRIBUTE'):
91
                    #    noteInfo.remove(node)
92
                    lineNoInfo = originRoot.find(xg.LINE_NOS_NODE_NAME)
93
                    lineNoInfo.clear()
94
                    #for node in lineNoInfo.iter('LINE_NO'):
95
                    #    lineNoInfo.remove(node)
86 96
                
87
                for textNode in textRoot.iter('Text'):
88
                    node = self.toXml(textNode)
89
                    textInfo.append(node)
97
                    for textNode in textRoot.iter('Text'):
98
                        node = self.toXml(textNode)
99
                        textInfo.append(node)
90 100
                
91
                originXml.write(xmlPath, encoding="utf-8", xml_declaration=True)
101
                    originXml.write(xmlPath, encoding="utf-8", xml_declaration=True)
92 102

  
93
                QMessageBox.information(self, self.tr('INFO'), self.tr('Importing Success!'), QMessageBox.Close)
103
                except Exception as ex:
104
                    from App import App 
105
                    from AppDocData import MessageType
94 106

  
95
            except Exception as ex:
96
                from App import App 
97
                from AppDocData import MessageType
107
                    message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
108
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
98 109

  
99
                message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
100
                App.mainWnd().addMessage.emit(MessageType.Error, message)
110
        QMessageBox.information(self, self.tr('INFO'), self.tr('Importing Success!'), QMessageBox.Close)
101 111
    
102 112
    def toXml(self, textNode):
103 113
        import uuid

내보내기 Unified diff

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