프로젝트

일반

사용자정보

개정판 35d6d96c

ID35d6d96cb41a59dd5f48d4aeba14d44a5b3cb969
상위 dc620556
하위 d076a78e

김정우 이(가) 약 7년 전에 추가함

작업 중

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
68 68
        
69 69
        return res
70 70

  
71
    '''
72
        @brief  get symbol name list
73
    '''
74
    def getSymbolNameList(self):
75
        symbolNametList = []
76

  
77
        try:
78
            conn = sqlite3.connect(DB_NAME)
79
            cursor = conn.cursor()
80
            sql = 'SELECT * FROM SymbolName'
81
            try:
82
                cursor.execute(sql)
83
                rows = cursor.fetchall()
84
                for row in rows:
85
                    symbolNametList.append(row[1]) # Name String
86
            except Exception as ex:
87
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
88
        finally:
89
            conn.close()
90

  
91
        return symbolNametList
92

  
71 93
    pass
DTI_PID/DTI_PID/Commands/ConnectionPointCommand.py
20 20
        self.listItems = self.connectionPointListWidget.items(QMimeData())
21 21
        self.imageViewer.setCursor(QCursor(Qt.CrossCursor))
22 22
        #self.isSelected = False
23
        self.imageWidth = self.imageViewer.image().width()
24
        self.imageHeight = self.imageViewer.image().height()
25
        self.initMinPoint = QPointF(self.imageWidth * -1, self.imageHeight * -1)
26
        self.showGuideline(self.initMinPoint)
27
        self.connectionPointLineEdit.setText("")
23 28
    
24 29
    '''
25 30
        @brief  pan image by left click and drag
......
39 44
                clickedY = int(scenePos.y())
40 45
                
41 46
                if (clickedX >= 0 and clickedX <= width) and (clickedY >= 0 and clickedY <= height):
42
                    self.imageViewer.scene.addItem(self.imageViewer.scene.addEllipse(QRectF(int(scenePos.x()), int(scenePos.y()), 1, 1), QPen(QColor(0, 0, 255)), QBrush(QColor(0, 0, 255))))
47
                    self.imageViewer.scene.addItem(self.imageViewer.scene.addEllipse(QRectF(scenePos.x() - 0.5, scenePos.y() - 0.5, 1, 1), QPen(QColor(0, 0, 255)), QBrush(QColor(0, 0, 255))))
43 48
                    #self.isSelected = True
44
                    text = "{},{}".format(int(scenePos.x()), int(scenePos.y()))
49
                    text = "{},{}".format(clickedX, clickedY)
45 50
                    self.connectionPointLineEdit.setText(text)
46 51
                    self.connectionPointListWidget.addItem(text)
47 52
                else:
......
50 55
        elif 'mouseMoveEvent' == param[0]:
51 56
            #if not self.isSelected:
52 57
            coords = event.pos()
53
            self.connectionPointLineEdit.setText("{},{}".format(int(scenePos.x()), int(scenePos.y())))
58
            if self.isOnImage(scenePos.x(), scenePos.y()):
59
                self.showGuideline(scenePos)
60
                self.connectionPointLineEdit.setText("{},{}".format(int(scenePos.x()), int(scenePos.y())))
61
            else:
62
                self.showGuideline(self.initMinPoint)
63
                self.connectionPointLineEdit.setText("")
54 64
            pass
55 65
        self.isTreated = False
56 66

  
67
    def isOnImage(self, x, y):
68
        if (x >= 0 and x <= self.imageWidth) and (y >= 0 and y <= self.imageHeight):
69
            return True
70
        else:
71
            return False
72
        
73
    def showGuideline(self, pos):
74
        self.imageViewer.crosshairPos = pos
75
        self.imageViewer.scene.update(QRectF(0, 0, self.imageWidth, self.imageHeight))
76

  
57 77
    def undo(self):
58 78
        pass
59 79

  
DTI_PID/DTI_PID/Commands/OriginalPointCommand.py
11 11
    except ImportError:
12 12
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
13 13

  
14
import sys
15

  
14 16
class OriginalPointCommand(AbstractCommand.AbstractCommand):
15 17
    def __init__(self, imageViewer, originalPointLineEdit):
16 18
        super(OriginalPointCommand, self).__init__(imageViewer)
......
19 21
        self.isSelected = False
20 22
        self.imageViewer.setCursor(QCursor(Qt.CrossCursor))
21 23
        self.imageViewer.isOriginalPointSelected = False
24
        self.imageWidth = self.imageViewer.image().width()
25
        self.imageHeight = self.imageViewer.image().height()
26
        self.initMinPoint = QPointF(self.imageWidth * -1, self.imageHeight * -1)
22 27
        
23 28
        coords = self.originalPointLineEdit.text()
24 29
        if coords:
30
            self.originalPointLineEdit.setText('')
25 31
            x = int(coords.split(",")[0])
26 32
            y = int(coords.split(",")[1])
27 33
            self.removeCircle(x, y)
34
            ## Guideline
35
            self.showGuideline(self.initMinPoint)
28 36
    
29 37
    '''
30 38
        @brief  pan image by left click and drag
......
35 43
        scenePos = param[2]
36 44
        if 'mousePressEvent' == param[0]:
37 45
            if event.button() == Qt.LeftButton:
38
                if not self.isSelected:
39
                    image = self.imageViewer.image()
40
                    width = image.width()
41
                    height = image.height()
42
                    
46
                if not self.isSelected:                    
43 47
                    clickedX = int(scenePos.x())
44 48
                    clickedY = int(scenePos.y())
45 49

  
46
                    if (clickedX >= 0 and clickedX <= width) and (clickedY >= 0 and clickedY <= height):
47
                        self.imageViewer.scene.addItem(self.imageViewer.scene.addEllipse(QRectF(clickedX, clickedY, 1, 1), QPen(QColor(255, 0, 0)), QBrush(QColor(255, 0, 0))))
50
                    if self.isOnImage(clickedX, clickedY):
51
                        self.imageViewer.scene.addItem(self.imageViewer.scene.addEllipse(QRectF(scenePos.x() - 0.5, scenePos.y() - 0.5, 1, 1), QPen(QColor(255, 0, 0)), QBrush(QColor(255, 0, 0))))
48 52
                        self.isSelected = True
49 53
                        self.originalPointLineEdit.setText("{},{}".format(clickedX, clickedY))
50 54
                        self.imageViewer.isOriginalPointSelected = True
55

  
56
                        ## Guideline
57
                        self.showGuideline(self.initMinPoint)
51 58
                    else:
52 59
                        QMessageBox.about(self.imageViewer, "알림", "심볼 내부를 선택해주세요.")
53 60
                QGraphicsView.mousePressEvent(self.imageViewer, event)
54 61
        elif 'mouseMoveEvent' == param[0]:
55 62
            if not self.isSelected:
56 63
                coords = event.pos()
57
                self.originalPointLineEdit.setText("{},{}".format(int(scenePos.x()), int(scenePos.y())))
64
                if self.isOnImage(scenePos.x(), scenePos.y()):
65
                    self.showGuideline(scenePos)
66
                    self.originalPointLineEdit.setText("{},{}".format(scenePos.x(), scenePos.y()))
67
                else:
68
                    self.showGuideline(self.initMinPoint)
69
                    self.originalPointLineEdit.setText("")
58 70
            pass
59 71
        self.isTreated = False
60 72

  
61 73
    def removeCircle(self, x, y):
62 74
        scenePos = QPointF(x, y)
63
        self.imageViewer.scene.removeItem(self.imageViewer.scene.itemAt(QPointF(int(scenePos.x()), int(scenePos.y())), QTransform()))
75
        item = self.imageViewer.scene.itemAt(QPointF(int(scenePos.x()), int(scenePos.y())), QTransform())
76
        if item is not None and item.boundingRect() != QRectF(0, 0, self.imageWidth, self.imageHeight):
77
            self.imageViewer.scene.removeItem(item)
78

  
79
    def isOnImage(self, x, y):
80
        if (x >= 0 and x <= self.imageWidth) and (y >= 0 and y <= self.imageHeight):
81
            return True
82
        else:
83
            return False
84
        
85
    def showGuideline(self, pos):
86
        self.imageViewer.crosshairPos = pos
87
        self.imageViewer.scene.update(QRectF(0, 0, self.imageWidth, self.imageHeight))
64 88

  
65 89
    def undo(self):
66 90
        pass
DTI_PID/DTI_PID/QSymbolEditorDialog.py
11 11
import potrace
12 12

  
13 13
import UI_SymbolEditor
14
from AppDocData import AppDocData
15

  
14 16

  
15 17
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands')
16 18
import CropCommand, HandCommand, ZoomCommand, PenCommand, EraserCommand, AreaEraserCommand, OriginalPointCommand, ConnectionPointCommand
......
73 75
        self.ui.addAdditionalSymbolButton.clicked.connect(self.addAdditionalSymbol)
74 76
        self.ui.addOriginalPointButton.clicked.connect(self.addOriginalPoint)
75 77
        self.ui.addConnectionPointButton.clicked.connect(self.addConnectionPoint)
78
        self.initBaseSymbolComboBoxItems()
79
        self.initAdditionalSymbolComboBoxItems()
76 80
        
77 81
    def initContents(self):
78 82
        self.ui.targetDBLineEdit.setText(self.project.getPath()+'/db/ITI_PID.db')
......
81 85
        #self.ui.baseSymbolComboBox
82 86
        #self.initBaseSymbolComboBoxItems()
83 87
        #self.ui.defaultSymbolDirectionComboBox
84
        #self.ui.addtionalSymbolComboBox
88
        #self.ui.additionalSymbolComboBox
85 89

  
86 90
    def initIsOriginDetectComboBoxItems(self):
87 91
        self.ui.isOriginDetectComboBox.addItem("원본 도면", 0)
......
98 102
        self.ui.defaultSymbolDirectionComboBox.addItem("좌", 3)
99 103
        self.ui.defaultSymbolDirectionComboBox.addItem("우", 1)
100 104

  
105
    def initBaseSymbolComboBoxItems(self):
106
        symbolNameList = AppDocData.instance().getSymbolNameList()
107
        symbolNameList.insert(0, "None")
108
        for name in symbolNameList:
109
            self.ui.baseSymbolComboBox.addItem(name)
110

  
111
    def initAdditionalSymbolComboBoxItems(self):
112
        symbolNameList = AppDocData.instance().getSymbolNameList()
113
        symbolNameList.insert(0, "None")
114
        for name in symbolNameList:
115
            self.ui.additionalSymbolComboBox.addItem(name)
116

  
101 117
    def removeConnectionPointCircles(self, circlePointList):
102 118
        for circlePoint in circlePointList:
103 119
            self.removeConnectionPointCircle(circlePoint)
......
139 155
        originalPoint = self.ui.originalPointLineEdit.text()
140 156
        connectionPoint = self.makeConnectionPointListString()
141 157
        ### 기초심볼추가
142
        baseSymbol = None
158
        baseSymbol = self.ui.baseSymbolComboBox.currentText()
143 159
        ### 부가심볼추가
144
        additionalSymbol = None
160
        additionalSymbol = self.makeAdditionalSymbolListString()
145 161

  
146 162
        convertedThreshold = int(threshold) / 100.0
147 163

  
......
150 166

  
151 167
        return newSym
152 168

  
169
    def makeAdditionalSymbolListString(self):
170
        ret = ""
171
        listItems = []
172
        for index in range(self.ui.additionalSymbolListWidget.count()):
173
            listItems.append(self.ui.additionalSymbolListWidget.item(index))
174
        if listItems is not None:
175
            for index in range(len(listItems)):
176
                item = listItems[index]
177
                text = item.text()
178
                if index != 0:
179
                    ret = ret + "/"
180
                ret = ret + text
181
        return ret
182

  
153 183
    def makeConnectionPointListString(self):
154 184
        ret = ""
155 185
        listItems = []
......
248 278

  
249 279
    def addAdditionalSymbol(self, event):
250 280
        print("addAdditionalSymbol")
251
        direction = self.ui.defaultSymbolDirectionComboBox.currentData()
252
        additionalSymbol = self.ui.addtionalSymbolComboBox.currentData()
281
        additionalSymbolIndex = self.ui.additionalSymbolComboBox.currentIndex()
282
        if additionalSymbolIndex != 0:
283
            print("Symbol Selected")
284
            direction = self.ui.defaultSymbolDirectionComboBox.currentText()
285
            symbolName = self.ui.additionalSymbolComboBox.currentText()
286
            text = "{},{}".format(direction, symbolName)
287

  
288
            if self.isAlreadyAdded(text):
289
                QMessageBox.about(self.ui.buttonBox, "알림", "이미 추가된 아이템입니다.")
290
            else:
291
                self.ui.additionalSymbolListWidget.addItem(text)
292

  
293
    def isAlreadyAdded(self, text):
294
        for index in range(self.ui.additionalSymbolListWidget.count()):
295
            item = self.ui.additionalSymbolListWidget.item(index)
296
            if item.text() == text:
297
                return True
298
        return False
253 299

  
254 300
    def addOriginalPoint(self, event):
255 301
        print("addOriginalPoint")
......
279 325
            infoTitle = self.ui.nameLabel.text()
280 326
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
281 327

  
282
        if not self.ui.typeLineEdit.text():
283
            infoTitle = self.ui.typeLabel.text()
284
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
328
        #if not self.ui.typeLineEdit.text():
329
        #    infoTitle = self.ui.typeLabel.text()
330
        #    return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
285 331

  
286 332
        thresholdText = self.ui.thresholdLineEdit.text()
287 333
        threshold = float(thresholdText) if thresholdText else -1
......
295 341
            infoTitle = self.ui.minMatchPointLabel.text()
296 342
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
297 343

  
344
        if self.ui.baseSymbolComboBox.currentIndex() == 0: #default value(None) index
345
            infoTitle = self.ui.baseSymbolLabel.text()
346
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
347

  
348
        #Additional Symbol is Nullable
349

  
298 350
        if not self.ui.originalPointLineEdit.text() or self.ui.imageView.isOriginalPointSelected == False:
299 351
            infoTitle = self.ui.originalPointLabel.text()
300 352
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
DTI_PID/DTI_PID/QtImageViewer.py
49 49
        self.scene = QGraphicsScene()
50 50
        self.setScene(self.scene)
51 51
        self.scene.setBackgroundBrush(Qt.gray)
52
        self.crosshairPos = None
52 53

  
53 54
        self.isPressCtrl = False
54 55
        self.scaleFactor = 1.0
......
281 282
        else:
282 283
            super().wheelEvent(event)
283 284

  
285
    def drawForeground(self, painter, rect):
286
        image = self.image()
287
        if image is not None:
288
            width = image.width()
289
            height = image.height()
290
            if self.crosshairPos is not None:
291
                pen = QPen()
292
                pen.setColor(QColor(80, 80, 80))
293
                pen.setStyle(Qt.DashLine)
294
                pen.setWidthF(0.3)
295
                painter.setPen(pen)
296
                painter.drawLine(self.crosshairPos.x(), 0, self.crosshairPos.x(), height)#Vertical
297
                painter.drawLine(0, self.crosshairPos.y(), width, self.crosshairPos.y())#Horizontal
298
            #else:
299
            #    painter.eraseRect(QRectF(0, 0, width, height))
284 300
            
285 301
    '''
286 302
        @brief  override paint event
DTI_PID/DTI_PID/UI_SymbolEditor.py
165 165
        self.defaultSymbolDirectionComboBox.setMaximumSize(QtCore.QSize(50, 16777215))
166 166
        self.defaultSymbolDirectionComboBox.setObjectName("defaultSymbolDirectionComboBox")
167 167
        self.horizontalLayout_2.addWidget(self.defaultSymbolDirectionComboBox)
168
        self.addtionalSymbolComboBox = QtWidgets.QComboBox(self.formLayoutWidget)
169
        self.addtionalSymbolComboBox.setObjectName("addtionalSymbolComboBox")
170
        self.horizontalLayout_2.addWidget(self.addtionalSymbolComboBox)
168
        self.additionalSymbolComboBox = QtWidgets.QComboBox(self.formLayoutWidget)
169
        self.additionalSymbolComboBox.setObjectName("additionalSymbolComboBox")
170
        self.horizontalLayout_2.addWidget(self.additionalSymbolComboBox)
171 171
        self.addAdditionalSymbolButton = QtWidgets.QPushButton(self.formLayoutWidget)
172 172
        self.addAdditionalSymbolButton.setMaximumSize(QtCore.QSize(40, 16777215))
173 173
        self.addAdditionalSymbolButton.setObjectName("addAdditionalSymbolButton")
174 174
        self.horizontalLayout_2.addWidget(self.addAdditionalSymbolButton)
175 175
        self.formLayout.setLayout(11, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_2)
176
        self.additionalSymbolListView = QtWidgets.QListView(self.formLayoutWidget)
177
        self.additionalSymbolListView.setObjectName("additionalSymbolListView")
178
        self.formLayout.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.additionalSymbolListView)
176
        self.additionalSymbolListWidget = QtWidgets.QListWidget(self.formLayoutWidget)
177
        self.additionalSymbolListWidget.setObjectName("additionalSymbolListWidget")
178
        self.formLayout.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.additionalSymbolListWidget)
179 179
        self.originalPointLabel = QtWidgets.QLabel(self.formLayoutWidget)
180 180
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
181 181
        sizePolicy.setHorizontalStretch(0)
DTI_PID/DTI_PID/potrace.py
41 41
        stdout=subprocess.PIPE,
42 42
        stderr=subprocess.PIPE,
43 43
        shell=False
44
        )
44
    )
45 45
        
46 46
    stdout, stderr = p.communicate(input=binbmp)
47 47
    if len(stderr) != 0:
48 48
        raise RuntimeError('Potrace threw error:\n' + stderr.decode('utf-8'))
49
    
50
    svgData = stdout
51
    #svgData = stdout.decode("utf-8")
52
    #svgData = stdout.decode("utf-16")
53
    #svgData = svgData.replace(u"\u000B", u"")
54
    #svgData = svgData.encode("utf-8")
49 55

  
50
    imgLines = []
51
    # parse svg data and extract lines
52
    svgdom = minidom.parseString(stdout)
53

  
54
    xmlFile = open(destFilePath, "a+")
55
    svgdom.writexml(xmlFile)
56
    xmlFile = open(destFilePath, "wb")#, encoding = "utf-8")
57
    xmlFile.write(svgData)
56 58
    xmlFile.close()
57 59

  
58 60
# extract line from image by using potrace

내보내기 Unified diff

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