프로젝트

일반

사용자정보

개정판 d91bc271

IDd91bc271eb52222ade8b6f87e3e307ab983ec325
상위 26a71df4
하위 a566dddc

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

issue #000: add text import and vertical text merge function

Change-Id: Id68036a517c248c9b9304998a0e3e14f8cb35c00

차이점 보기:

DTI_PID/DTI_PID/ImportTextFromCADDialog.py
26 26
        self.ui.toolButton.clicked.connect(self.addID2Click)
27 27
        self.ui.toolButton_2.clicked.connect(self.addCADClick)
28 28
        self.ui.pushButtonImport.clicked.connect(self.importTextFromCAD)
29
        self.ui.pushButtonClose.clicked.connect(self.close)
29 30

  
30 31
        self.height = None
31 32

  
......
48 49
            self.ui.lineEditCAD.setText(selectedDir[0])
49 50
    
50 51
    def importTextFromCAD(self):
52
        project = AppDocData.instance().getCurrentProject()
51 53
        xmlPath = self.ui.lineEditID2.text()
52 54
        dwgPath = self.ui.lineEditCAD.text()
53 55
        xOffset = self.ui.doubleSpinBoxX.value()
......
60 62
                command = filePath + ' {} {} {} {}'.format(dwgPath, xOffset, yOffset, scale)
61 63
                subprocess.call(command, shell = False)
62 64

  
63
                textXmlPath = os.path.join('E:\Projects\DTIPID_GERRIT', dwgPath.split('/')[-1].split('.')[0] + '.xml')
65
                textXmlPath = os.path.join(os.path.join(project.getDrawingFilePath(), 'Native'), dwgPath.split('/')[-1].split('.')[0] + '.xml')
64 66
                textXml = parse(textXmlPath)
65 67
                originXml = parse(xmlPath)
66 68
                textRoot = textXml.getroot()
......
70 72
                textInfo = originRoot.find(xg.TEXT_INFO_LIST_NODE_NAME)
71 73
                textInfo.clear()
72 74
                #for node in textInfo.iter('ATTRIBUTE'):
73
                #    textInfo.remove(node)
75
                #    if node.find('AREA').text == 'None' or node.find('AREA').text == 'Drawing':
76
                #        textInfo.remove(node)
74 77

  
75 78
                noteInfo = originRoot.find(xg.NOTE_TEXT_INFO_LIST_NOTE_NAME)
76 79
                noteInfo.clear()
......
87 90
                
88 91
                originXml.write(xmlPath, encoding="utf-8", xml_declaration=True)
89 92

  
93
                QMessageBox.information(self, self.tr('INFO'), self.tr('Importing Success!'), QMessageBox.Close)
94

  
90 95
            except Exception as ex:
91 96
                from App import App 
92 97
                from AppDocData import MessageType
......
101 106
        loc[1] = self.height - loc[1]
102 107

  
103 108
        text = textNode.find('Value').text
104
        angle = float(textNode.find('Angle').text)
109
        angle = round(float(textNode.find('Angle').text), 2)
105 110

  
106
        height = float(textNode.find('Height').text)
107
        width = float(textNode.find('Width').text)
111
        height = round(float(textNode.find('Height').text))
112
        width = height * len(text) * 2 / 3#round( float(textNode.find('Width').text))
113

  
114
        allowed_error = 0.001
115
        if abs(angle - 1.57) < allowed_error:
116
            height, width = width, height
117
            loc[0], loc[1] = loc[0] - width, loc[1] - height + width
118
        elif abs(angle - 4.71) < allowed_error:
119
            height, width = width, height
120
            loc[0], loc[1] = loc[0] - width, loc[1] + height - width
108 121

  
109 122
        node = Element('ATTRIBUTE')
110 123
        uidNode = Element('UID')
......
150 163
        sceneNode.text = '{},{},{},{}'.format(round(loc[0]), round(loc[1]), round(width), round(height))
151 164
        node.append(sceneNode)
152 165

  
153
        return node
166
        return node
167

  
168
def close(self):
169
    QDialog.reject(self)
DTI_PID/DTI_PID/ItemDataFormatDialog.py
420 420
            docData.saveConfigs(configs)
421 421
            docData.configTable = None
422 422

  
423
        reply = QMessageBox.information(self, self.tr('INFO'), self.tr('Save Success!.'), QMessageBox.Ok, QMessageBox.Cancel)
423
        reply = QMessageBox.information(self, self.tr('INFO'), self.tr('Save Success!'), QMessageBox.Ok, QMessageBox.Cancel)
424 424
        if reply == QMessageBox.Ok:
425 425
            QDialog.accept(self)
426 426

  
DTI_PID/DTI_PID/MainWindow.py
1467 1467
                else:
1468 1468
                    self.onViewDrawingOnly(True)
1469 1469
                    self.actionDrawing_Only.setChecked(True)
1470
                    
1470
            elif event.key() == Qt.Key_M: # merge text as vertical
1471
                from TextInfo import TextInfo
1472

  
1473
                textItems = [text for text in self.graphicsView.scene.selectedItems() if type(text) is QEngineeringTextItem and text.angle == 0]
1474
                textItems = sorted(textItems, key=lambda text: text.loc[1])
1475
                minX = sys.maxsize
1476
                minY = sys.maxsize
1477
                maxX = 0
1478
                maxY = 0
1479
                newText = ''
1480
                for text in textItems:
1481
                    if text.loc[0] < minX: minX = text.loc[0]
1482
                    if text.loc[1] < minY: minY = text.loc[1]
1483
                    if text.loc[0] + text.size[0] > maxX: maxX = text.loc[0] + text.size[0]
1484
                    if text.loc[1] + text.size[1] > maxY: maxY = text.loc[1] + text.size[1]
1485
                    newText = newText + text.text() + "\n"
1486
                    text.transfer.onRemoved.emit(text)
1487
                newText = newText[:-1]
1488
                
1489
                textInfo = TextInfo(newText, minX, minY, maxX - minX, maxY - minY, 0)
1490
                x = textInfo.getX()
1491
                y = textInfo.getY()
1492
                angle = textInfo.getAngle()
1493
                text = textInfo.getText()
1494
                width = textInfo.getW()
1495
                height = textInfo.getH()
1496
                item = TextItemFactory.instance().createTextItem(textInfo)
1497
                if item is not None:
1498
                    item.loc = (x, y)
1499
                    item.size = (width, height)
1500
                    item.angle = angle
1501
                    item.setDefaultTextColor(Qt.blue)
1502
                    item.addTextItemToScene(self.graphicsView.scene)
1503
                    item.transfer.onRemoved.connect(self.itemRemoved)
1504
                
1471 1505
            QMainWindow.keyPressEvent(self, event)
1472 1506
        except Exception as ex:
1473 1507
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
DTI_PID/DTI_PID/Shapes/EngineeringTextItem.py
463 463
            height = float(node.find('HEIGHT').text) if node.find('HEIGHT') is not None else 0
464 464
            angle = float(node.find('ANGLE').text) if node.find('ANGLE') is not None else 0
465 465
            value = node.find('VALUE').text
466
            if len(value.replace('\n', '').replace(' ', '')) == 0:
467
                return None
466 468
            #attributeValue = node.find('ATTRIBUTEVALUE')
467 469
            name = node.find('NAME').text
468 470
            textInfo = TextInfo(value, x, y, width, height, angle)
DTI_PID/DTI_PID/TrainingEditorDialog.py
241 241
        self.boxItem.setText(boxchars)
242 242

  
243 243
        self.isChanged = False
244
        reply = QMessageBox.information(self, self.tr('INFO'), self.tr('Save Success!.'), QMessageBox.Ok, QMessageBox.Cancel)
244
        reply = QMessageBox.information(self, self.tr('INFO'), self.tr('Save Success!'), QMessageBox.Ok, QMessageBox.Cancel)
245 245
        if reply == QMessageBox.Ok:
246 246
            QDialog.reject(self)
247 247

  

내보내기 Unified diff

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