프로젝트

일반

사용자정보

개정판 7552be56

ID7552be561faeab6bcf2591d805fc631e6dad6aa9
상위 d0172482
하위 4af09bc7, 48a8e97f

백흠경이(가) 약 6년 전에 추가함

issue #567: fixed the function to lock item's attribute

Change-Id: I9582c0c732f614a900d2151c82c760a93b6ceca3

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
1862 1862
        @history    humkyung 2018.10.13 load expression
1863 1863
    '''
1864 1864
    def getSymbolAttribute(self, _type):
1865
        import uuid
1865 1866
        from SymbolAttr import SymbolAttr
1866 1867

  
1867 1868
        result = []
......
1879 1880
            rows = cursor.fetchall()
1880 1881
            for row in rows:
1881 1882
                attr = SymbolAttr()
1882
                attr.UID = row[0]
1883
                attr.UID = uuid.UUID(row[0], version=4)
1883 1884
                attr.Attribute = row[1]
1884 1885
                attr.DisplayAttribute = row[2]
1885 1886
                attr.AttributeType = row[3]
DTI_PID/DTI_PID/ItemPropertyTableWidget.py
55 55
            if widget:
56 56
                widget.setEnabled(False) if state else widget.setEnabled(True)
57 57

  
58
            data = self.table.item(self.row, 1).data(Qt.UserRole)
59
            if data: data.Freeze = self.isChecked()
60

  
58 61
            item = self.table.item(self.row, 3)
59 62
            if item:
60 63
                item.setFlags(Qt.ItemIsEnabled) if state else item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable|Qt.ItemIsSelectable)
......
417 420
                        value_item = QTableWidgetItem(value if value else '')
418 421
                        value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
419 422
                        self.setItem(row, 3, value_item)
423

  
424
                checkbox.state_changed(checkbox.isChecked())
425
                
420 426
                row = row + 1
421 427
        
422 428
    def show_item_attributes(self, item):
......
434 440
                """ show freeze state """
435 441
                checkbox = QCustomCheckBox(self, row, 0)
436 442
                checkbox.setChecked(key.Freeze)
443
                checkbox.stateChanged.connect(checkbox.state_changed)
437 444
                self.setCellWidget(row, 0, checkbox)
438 445

  
439 446
                """ show property name """
......
460 467
                else:
461 468
                    self.setItem(row, 3, value_item)
462 469

  
470
                checkbox.state_changed(checkbox.isChecked())
471

  
463 472
                row = row + 1
464 473

  
465 474
    def show_item_connectors(self, item):
......
688 697
        if items is not None and len(items) == 1:
689 698
            if type(items[0]) is QEngineeringLineNoTextItem:
690 699
                stream_no = self.streamNoComboBox.itemText(param)
691
                items[0].setAttribute(self.streamNoComboBox.tag, stream_no)
700
                items[0].set_attrib(self.streamNoComboBox.tag, stream_no)
692 701
                return
693 702

  
694 703
    '''
......
777 786
                                self._item.set_property(data.Attribute, self.cellWidget(row, column).isChecked())
778 787
                        elif type(data) is SymbolAttr:
779 788
                            if data.AttributeType != 'Boolean':
780
                                self._item.setAttribute(data, self.item(row, column).text())
789
                                self._item.set_attrib(data, self.item(row, column).text())
781 790
                            else:
782
                                self._item.setAttribute(data, self.cellWidget(row, column).isChecked())
791
                                self._item.set_attrib(data, self.cellWidget(row, column).isChecked())
783 792
        except Exception as ex:
784 793
            from App import App
785 794
            from AppDocData import MessageType
DTI_PID/DTI_PID/MainWindow.py
1 1
# coding: utf-8
2
"""
3
This is MainWindow module
4
"""
2
""" This is MainWindow module """
5 3

  
6 4
import sys
7 5
import os
......
217 215
        self.actionVendor.triggered.connect(self.onVendor)
218 216
        self.actionFitWindow.triggered.connect(self.fitWindow)
219 217
        self.actionpdf_to_image.triggered.connect(self.onConvertPDFToImage)
220
        self.graphicsView.scene.changed.connect(self.onSceneChanged)
218
        #self.graphicsView.scene.changed.connect(self.onSceneChanged)
219
        self.graphicsView.scene.contents_changed.connect(self.onSceneChanged)
221 220
        self.graphicsView.scene.selectionChanged.connect(self.onSelectionChanged)
222 221
        self.actionInitialize.triggered.connect(self.onInitializeScene)
223 222
        self.actionSave.triggered.connect(self.actionSaveCliked)
......
1101 1100
                        self.progress.show()
1102 1101

  
1103 1102
                        self.loadRecognitionResultFromXml(path)
1104
                        self.checkAttribute()
1103
                        #self.checkAttribute()
1105 1104
                    finally:
1106 1105
                        self.progress.setValue(self.progress.maximum())
1107 1106
                        self.progress.hide()
......
2245 2244
        from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem
2246 2245

  
2247 2246
        try:
2248
            self.blockSignals(True)
2247
            #self.graphicsView.scene.blockSignals(True)
2249 2248

  
2250 2249
            symbols = []
2251 2250

  
......
2421 2420
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
2422 2421
            self.addMessage.emit(MessageType.Error, message)
2423 2422
        finally:
2424
            self.blockSignals(False)
2423
            pass
2424
            #self.graphicsView.scene.blockSignals(False)
2425 2425

  
2426 2426
    '''
2427 2427
        @brief      Remove added item on same place and Add GraphicsItem
......
2498 2498
        @author     kyoyho
2499 2499
        @date       2018.08.21
2500 2500
    '''
2501
    """
2501 2502
    def checkAttribute(self):
2502 2503
        try:
2503 2504

  
......
2560 2561
        except Exception as ex:
2561 2562
                message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
2562 2563
                self.addMessage.emit(MessageType.Error, message)
2564
    """
2563 2565
    '''
2564 2566
        @brief      Check Number
2565 2567
        @author     kyouho
DTI_PID/DTI_PID/QtImageViewer.py
56 56
        @history    2018.06.27  Jeongwoo    Change zoom rule (Qt.KeepAspectRatioByExpanding → Qt.KeepAspectRatio)
57 57
    '''
58 58
    def __init__(self, mainWindow = None):
59
        from QtImageViewerScene import QtImageViewerScene
60

  
59 61
        QGraphicsView.__init__(self)
60 62

  
61 63
        self.mainWindow = mainWindow
62 64
        # Image is displayed as a QPixmap in a QGraphicsScene attached to this QGraphicsView.
63 65
        self.command = None
64
        self.scene = QGraphicsScene(self)
66
        self.scene = QtImageViewerScene(self)
65 67
        self.setScene(self.scene)
66 68
        self.scene.setBackgroundBrush(Qt.lightGray)
67 69

  
DTI_PID/DTI_PID/QtImageViewerScene.py
1
# coding: utf-8
2
""" This is image viewer scene module """
3

  
4
import sys
5
import os.path
6
try:
7
    from PyQt5.QtCore import *
8
    from PyQt5.QtGui import *
9
    from PyQt5.QtWidgets import *
10
except ImportError:
11
    try:
12
        from PyQt4.QtCore import *
13
        from PyQt4.QtGui import *
14
    except ImportError:
15
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
16
    
17
__author__ = "humkyung <humkyung.doftech.co.kr>"
18
__version__ = '1.0.0'
19

  
20

  
21
class QtImageViewerScene(QGraphicsScene):
22
    """ This is image viewer scene class """
23
    contents_changed = pyqtSignal()
24

  
25
    def __init__(self, viewer):
26
        QGraphicsScene.__init__(self, viewer)
27

  
28
    def addItem(self, item):
29
        """ add given item to scene """
30

  
31
        QGraphicsScene.addItem(self, item)
32
        self.contents_changed.emit()
33

  
34
    def removeItem(self, item):
35
        """ remove given item from scene """
36
        QGraphicsScene.removeItem(self, item)
37
        self.contents_changed.emit()
DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py
138 138

  
139 139
    @staticmethod
140 140
    def assoc_type(item):
141
        """
142
        return association type of given item
143
        """
141
        """ return association type of given item """
144 142
        from EngineeringTextItem import QEngineeringTextItem
145 143
        from SymbolSvgItem import SymbolSvgItem
146 144
        from EngineeringValveOperCodeTextItem import QEngineeringValveOperCodeTextItem
DTI_PID/DTI_PID/Shapes/EngineeringConnectorItem.py
63 63
        """ setup label for connector index """
64 64
        self._label = QGraphicsTextItem('{}'.format(index), self)
65 65
        self._label.setZValue(0)
66
        """
67
        self._label.setFlag(QGraphicsItem.ItemIsEnabled, False)
68
        self._label.setFlag(QGraphicsItem.ItemIsSelectable, False)
69
        """
70 66
        font = QFont('Arial', QEngineeringConnectorItem.SMALL_SIZE)
71 67
        font.setPointSizeF(5)
72 68
        self._label.setFont(font)
......
228 224
            c.setNamedColor(QEngineeringConnectorItem.HIGHLIGHT)
229 225
            self.setPen(Qt.red)
230 226
            self.setBrush(c)
227
            font = self._label.font()
228
            font.setBold(True)
229
            self._label.setFont(font)
231 230
        else:
232 231
            self.setRect(self._loc[0] - round(self.SMALL_SIZE*0.5), self._loc[1] - round(self.SMALL_SIZE*0.5), self.SMALL_SIZE, self.SMALL_SIZE)
233 232
            self.setPen(Qt.black)
234 233
            self.setBrush(Qt.yellow) if self.connectedItem else self.setBrush(Qt.blue)
234
            font = self._label.font()
235
            font.setBold(False)
236
            self._label.setFont(font)
235 237

  
236 238
        if self.parentItem(): self.setZValue(self.parentItem().zValue() + 1)
237 239
        if self.scene().sceneRect().contains(self.sceneBoundingRect()):
DTI_PID/DTI_PID/Shapes/EngineeringInstrumentItem.py
185 185
            App.mainWnd().addMessage.emit(MessageType.Error, message)
186 186

  
187 187
    '''
188
        @brief      get attributes
189
        @author     humkyung
190
        @date       2018.06.14
191
    '''
192
    def getAttributes(self):
193
        _attrs = {}
194
        try:
195
            from AppDocData import AppDocData
196
            from EngineeringAbstractItem import QEngineeringAbstractItem
197
            from EngineeringTextItem import QEngineeringTextItem
198

  
199
            # 해당 Type의 attribute setting
200
            docData = AppDocData.instance()
201
            symbolAttrs = docData.getSymbolAttribute(self.type)
202
            _texts = self.texts()
203
            _symbols = self.symbols()
204
            for attr in symbolAttrs:
205
                if attr.AttributeType == 'Size Text Item' or attr.AttributeType == 'Text Item' or attr.AttributeType == 'Valve Oper Code':
206
                    at = int(attr.AttrAt)
207
                    items = [text for text in _texts if QEngineeringAbstractItem.assoc_type(text) == attr.AttributeType]
208
                    if len(items) > at:
209
                        item = items[at]
210
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
211
                    else:
212
                        _attrs[attr] = ''
213
                elif attr.AttributeType == 'Symbol Item':
214
                    at = int(attr.AttrAt)
215
                    if len(_symbols) > at:
216
                        item = _symbols[at]
217
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
218
                    else:
219
                        _attrs[attr] = ''
220
                else:
221
                    matches = [prop for prop in self.attrs if prop.UID == attr.UID]
222
                    if len(matches) == 1:
223
                        _attrs[matches[0]] = self.attrs[matches[0]]
224
                    else:
225
                        _attrs[attr] = ''
226
        except Exception as ex:
227
            from App import App 
228
            from AppDocData import MessageType
229

  
230
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
231
            App.mainWnd().addMessage.emit(MessageType.Error, message)
232
        
233
        return _attrs
234

  
235
    '''
236 188
        @brief  generate xml code for attribute
237 189
        @author humkyung
238 190
        @date   2018.05.06
DTI_PID/DTI_PID/Shapes/EngineeringLineNoTextItem.py
168 168
        @author     humkyung
169 169
        @date       2018.07.20
170 170
    '''
171
    def setAttribute(self, key, value):
172
        matches = [attr for attr in self.attrs if attr.UID == key.UID]
171
    def set_attrib(self, attrib, value):
172
        matches = [attr for attr in self.attrs if attr.UID == attrib.UID]
173 173
        if len(matches) == 1:
174 174
            self.attrs[matches[0]] = value
175 175
        else:
176
            self.attrs[key] = value
176
            self.attrs[attrib] = value
177 177

  
178 178
    def removeSelfAttr(self, attributeName):
179 179
        pass
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py
153 153

  
154 154
        return None
155 155

  
156
    def setAttribute(self, key, value):
157
        """
158
        set attribute with given value
159
        """
160
        matches = [attr for attr in self.attrs if attr.UID == key.UID]
161
        if len(matches) == 1:
162
            self.attrs[matches[0]] = value
163
        else:
164
            self.attrs[key] = value
156
    def set_attrib(self, attrib, value):
157
        """ set attribute with given value """
158
        matches = [attr for attr,_ in self.attrs.items() if attr.UID == attrib.UID]
159
        if len(matches) == 1: self.attrs[matches[0]] = value
165 160

  
166 161
    def validate(self):
167 162
        '''
......
242 237
        return True if (pt[0] >= minX and pt[0] <= maxX and pt[1] >= minY and pt[1] <= maxY) else False
243 238

  
244 239
    def associations(self):
245
        """
246
        return associated instance
247
        """
240
        """ return associated instance """
248 241
        import uuid
249 242

  
250 243
        res = []
......
288 281
        for key in _attrs.keys():
289 282
            cols = ['UID', 'Components_UID', 'SymbolAttribute_UID', 'Value']
290 283
            values = ['?', '?', '?', '?']
291
            param = [str(uuid.uuid4()), str(self.uid), key.UID, _attrs[key]]
284
            param = [str(uuid.uuid4()), str(self.uid), str(key.UID), str(_attrs[key])]
292 285

  
293 286
            sql = 'insert or replace into Attributes({}) values({})'.format(','.join(cols), ','.join(values))
294 287
            res.append((sql, tuple(param)))
......
704 697
            from EngineeringTextItem import QEngineeringTextItem
705 698
            from EngineeringValveOperCodeTextItem import QEngineeringValveOperCodeTextItem
706 699

  
707
            # 해당 Type의 attribute setting
700
            """ get attributes of item from database """
708 701
            docData = AppDocData.instance()
709 702
            symbolAttrs = docData.getSymbolAttribute(self.type)
710 703

  
711 704
            _texts = self.texts()
712 705
            _symbols = self.symbols()
713 706
            for attr in symbolAttrs:
707
                matches = [_attr for _attr,_ in self.attrs.items() if _attr.UID == attr.UID]
708
                if matches:
709
                    attr.Freeze = matches[0].Freeze         ### update freeze value
710
                    _attrs[attr] = self.attrs[matches[0]]   ### copy attribute value
711
                else:
712
                    _attrs[attr] = ''
713
 
714
                if attr.Freeze: continue    ### do not evalulate value if attribute is frozen
714 715
                if attr.AttributeType == 'Size Text Item' or attr.AttributeType == 'Text Item' or attr.AttributeType == 'Valve Oper Code':
715 716
                    at = int(attr.AttrAt)
716 717
                    items = [text for text in _texts if QEngineeringAbstractItem.assoc_type(text) == attr.AttributeType]
......
726 727
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
727 728
                    else:
728 729
                        _attrs[attr] = ''
729
                else:
730
                    matches = [prop for prop in self.attrs if prop.UID == attr.UID]
731
                    if len(matches) == 1:
732
                        _attrs[matches[0]] = self.attrs[matches[0]]
733
                    else:
734
                        _attrs[attr] = ''
730
            
731
            self.attrs = _attrs ### assign self.attrs
735 732
        except Exception as ex:
736 733
            from App import App 
737 734
            from AppDocData import MessageType
......
739 736
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
740 737
            App.mainWnd().addMessage.emit(MessageType.Error, message)
741 738
        
742
        return _attrs
739
        return self.attrs
743 740

  
744 741
    '''
745 742
        @brief      generate xml code
......
860 857
                    elif attr.AttributeType == 'Spec':
861 858
                        _node.text = str(self.attrs[attr][0]) + ',' + str(self.attrs[attr][1])
862 859
                    attributesNode.append(_node)
863
                #elif type(attr) is tuple and type(self) is QEngineeringSpecBreakItem:
864
                #    attributeNode = Element(attr[0].upper().replace(' ',''))
865
                #    attributeNode.text = str(attr[1] if attr[1] is not None else '')
866
                #    attributesNode.append(attributeNode)
867 860

  
868 861
            node.append(attributesNode)
869 862

  
......
987 980
                                for initKey in item.attrs.keys():
988 981
                                    if initKey.Attribute == 'DownStream':
989 982
                                        item.attrs[initKey] = attr.text
990
                            #elif _attr.Attribute == 'Connected Line':
991
                            #    for initKey in item.attrs.keys():
992
                            #        if initKey.Attribute == 'Connected Line':
993
                            #            item.attrs[initKey] = attr.text
994
                    """
995
                    for attr in attributes.iter('USERINPUTATTRIBUTE'):
996
                        typeUID = attr.find('TYPEUID').text
997
                        typeValue = attr.find('TYPEVALUE').text
998
                        item.attrs.append(UserInputAttribute(typeUID, typeValue))
999
                    """
983
                            
1000 984
                currentPointModeIndex = node.find('CURRENTPOINTMODEINDEX')
1001 985
                if currentPointModeIndex is not None:
1002 986
                    item.currentPointModeIndex = int(currentPointModeIndex.text)
DTI_PID/DTI_PID/SymbolAttr.py
94 94
        import uuid
95 95

  
96 96
        attr = SymbolAttr()
97
        if node.attrib['UID'] != '':
98
            attr.UID = uuid.UUID(node.attrib['UID'], version=4)
99
        else:
100
            attr.UID = ''
97
        attr.UID = uuid.UUID(node.attrib['UID'], version=4) if 'UID' in node.attrib else  uuid.uuid4()
101 98
        attr.Freeze = node.attrib['Freeze'] == 'True' if 'Freeze' in node.attrib else False
102 99
        attr.Attribute = node.attrib['Attribute']
103 100
        attr.DisplayAttribute = node.attrib['DisplayAttribute']

내보내기 Unified diff

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