프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / DTI_PID / SymbolAttr.py @ 64922e03

이력 | 보기 | 이력해설 | 다운로드 (7.17 KB)

1 9100a182 humkyung
# coding: utf-8
2 7a1f9cf0 humkyung
""" This is Symbol Attribute module """
3 9100a182 humkyung
4 a208ed03 humkyung
class SymbolProp:
5
    """ This is symbol property class """
6
7 d0172482 humkyung
    def __init__(self, UID, Attribute, AttributType, Freeze=False, DisplayAttribute=None, Length=None, Expression=None):
8 a208ed03 humkyung
        import uuid
9
10 e5e77709 esham21
        self.UID = uuid.uuid4() if UID is None else uuid.UUID(UID)
11 d0172482 humkyung
        self.Freeze = Freeze
12 c3a5995f esham21
        self.Attribute = Attribute
13 a208ed03 humkyung
        self.AttributeType = AttributType
14
        self.DisplayAttribute = DisplayAttribute if DisplayAttribute else Attribute
15
        self.Length = Length 
16
        self.Expression = Expression 
17
18
    @property
19
    def is_selectable(self):
20
        """ return if attribute is selectable """
21
        from SymbolAttrEditorDialog import QSymbolAttrEditorDialog
22
23
        return (self.AttributeType in [key for key,value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items() if value == -1])
24
25
    def match_type(self, item):
26
        """ check if given item's attribute type matches """
27
28
        from EngineeringAbstractItem import QEngineeringAbstractItem
29
        from SymbolSvgItem import SymbolSvgItem
30
        from EngineeringLineItem import QEngineeringLineItem
31
32
        if self.AttributeType == 'Comp Item':
33
            return issubclass(type(item), SymbolSvgItem) or type(item) is QEngineeringLineItem
34
        elif self.AttributeType == QEngineeringAbstractItem.assoc_type(item):
35
            return True
36
37
        return False
38
39 60f50aee humkyung
    def parse_record(self, record):
40
        """ parse record for property """
41
        import uuid
42
        
43 e5e77709 esham21
        self.UID = uuid.UUID(record['UID'])
44 60f50aee humkyung
        self.Freeze = record['Freeze'] == 'True' if record['Freeze'] else False
45
        self.Attribute = record['Attribute']
46
        self.AttributeType = record['AttributeType']
47
        self.DisplayAttribute = record['DisplayAttribute']
48
        self.Expression = record['Expression']
49
        self.Length = record['Length']
50
51 a208ed03 humkyung
    def parse_xml(self, node):
52
        """ parse xml node for property """
53
        import uuid
54
        
55 e5e77709 esham21
        self.UID = uuid.UUID(node.attrib['UID'])
56 d0172482 humkyung
        self.Freeze = node.attrib['Freeze'] == 'True' if 'Freeze' in node.attrib else False
57 a208ed03 humkyung
        self.Attribute = node.attrib['Attribute']
58
        self.AttributeType = node.attrib['AttributeType']
59
        self.DisplayAttribute = node.attrib['DisplayAttribute']
60
        self.Expression = node.attrib['Expression']
61
        self.Length = node.attrib['Length']
62
63 8138f238 humkyung
    @staticmethod
64
    def is_valid_uuid(value, version=4):
65
        import uuid
66
        """
67
        Check if uuid_to_test is a valid UUID.
68

69
        Parameters
70
        ----------
71
        uuid_to_test : str
72
        version : {1, 2, 3, 4}
73

74
        Returns
75
        -------
76
        `True` if uuid_to_test is a valid UUID, otherwise `False`.
77

78
        Examples
79
        --------
80
        >>> is_valid_uuid('c9bf9e57-1685-4c89-bafb-ff5af830be8a')
81
        True
82
        >>> is_valid_uuid('c9bf9e58')
83
        False
84
        """
85
        try:
86 e5e77709 esham21
            uuid_obj = uuid.UUID(value)#, version=version)
87 8138f238 humkyung
        except:
88
            return False
89
90
        return str(uuid_obj) == value 
91
92 afd3a6da humkyung
    def parse_value(self, text):
93
        """ parse value of property """
94
        import uuid
95
96
        if self.AttributeType == 'Boolean':
97
            return True if text and text == 'True' else False
98
        else:
99 e5e77709 esham21
            return uuid.UUID(text) if text and SymbolProp.is_valid_uuid(text) else text if text else ''
100 afd3a6da humkyung
101 a208ed03 humkyung
    def toXml(self):
102
        """ generate xml code for symbol property """
103
        from xml.etree.ElementTree import Element, SubElement, dump, ElementTree
104
105
        node = Element('PROPERTY')
106
        node.attrib['UID'] = str(self.UID) if self.UID else ''
107 d0172482 humkyung
        node.attrib['Freeze'] = str(self.Freeze)
108 a208ed03 humkyung
        node.attrib['Attribute'] = self.Attribute if self.Attribute is not None else ''
109
        node.attrib['AttributeType'] = self.AttributeType if self.AttributeType is not None else ''
110
        node.attrib['DisplayAttribute'] = self.DisplayAttribute if self.DisplayAttribute else ''
111
        node.attrib['Expression'] = self.Expression if self.Expression else ''
112
        node.attrib['Length'] = str(self.Length) if self.Length else ''
113
114
        return node
115
116
class SymbolAttr(SymbolProp):
117
    """ This is symbol attribute class """
118 9100a182 humkyung
    def __init__(self):
119 1f78dfb4 esham21
        import uuid
120 a208ed03 humkyung
        SymbolProp.__init__(self, None, None, None)
121
122 1f78dfb4 esham21
        self.UID = uuid.uuid4()
123 d0172482 humkyung
        self.Freeze = False
124 9100a182 humkyung
        self.Attribute = None
125
        self.DisplayAttribute = None
126
        self.AttributeType = None
127
        self.AttrAt = None
128 dd3553d3 humkyung
        self.Expression = None
129 d4c5dd47 esham21
        self.Target = None
130 afabd84e humkyung
        self.Length = None
131 81129f87 esham21
        self.AssocItem = None
132 0d6d3734 humkyung
        self.IsProp = 0  # default value is 0
133 a0b4f83c esham21
        self.Codes = None
134 afabd84e humkyung
135 763f6ba0 humkyung
    @staticmethod
136 2796938f humkyung
    def from_record(record):
137
        """ parse record for property """
138
        import uuid
139
        
140
        attr = SymbolAttr()
141 e5e77709 esham21
        attr.UID = uuid.UUID(record['UID'])
142 f28a350a humkyung
        attr.Freeze = record['Freeze'] == 'True' if record['Freeze'] else False
143 2796938f humkyung
        attr.Attribute = record['Attribute']
144
        attr.DisplayAttribute = record['DisplayAttribute']
145
        attr.AttributeType = record['AttributeType']
146
        attr.AttrAt = record['AttrAt']
147
        attr.Expression = record['Expression']
148 7fb00532 humkyung
        attr.Length = record['Length'] if 'Length' in record else 0
149
        attr.IsProp = int(record['Property']) if record['Property'] else 0
150 e5e77709 esham21
        attr.AssocItem = uuid.UUID(record['Association_UID']) if record['Association_UID'] and record['Association_UID'] != 'None' else None
151 2796938f humkyung
152
        return attr
153
154
    @staticmethod
155 763f6ba0 humkyung
    def fromXml(node):
156 a208ed03 humkyung
        """ generate SymbolAttr instance from xml node """
157
        import uuid
158 763f6ba0 humkyung
159
        attr = SymbolAttr()
160 e5e77709 esham21
        attr.UID = uuid.UUID(node.attrib['UID']) if 'UID' in node.attrib and node.attrib['UID'] != '' else uuid.uuid4()
161 d0172482 humkyung
        attr.Freeze = node.attrib['Freeze'] == 'True' if 'Freeze' in node.attrib else False
162 763f6ba0 humkyung
        attr.Attribute = node.attrib['Attribute']
163
        attr.DisplayAttribute = node.attrib['DisplayAttribute']
164
        attr.AttributeType = node.attrib['AttributeType']
165
        attr.AttrAt = node.attrib['AttrAt']
166
        attr.Expression = node.attrib['Expression']
167
        attr.Length = node.attrib['Length']
168 e5e77709 esham21
        attr.AssocItem = uuid.UUID(node.attrib['AssocItem']) if 'AssocItem' in node.attrib and node.attrib['AssocItem'] != '' else None
169 763f6ba0 humkyung
170
        return attr
171
172 afabd84e humkyung
    def toXml(self):
173 a208ed03 humkyung
        """ generate xml code for symbol attribute """
174 afabd84e humkyung
        from xml.etree.ElementTree import Element, SubElement, dump, ElementTree
175
176
        node = Element('ATTRIBUTE')
177 d0172482 humkyung
        node.attrib['Freeze'] = str(self.Freeze)
178 763f6ba0 humkyung
        node.attrib['UID'] = str(self.UID) if self.UID is not None else ''
179
        node.attrib['Attribute'] = self.Attribute if self.Attribute is not None else ''
180
        node.attrib['DisplayAttribute'] = self.DisplayAttribute if self.DisplayAttribute is not None else ''
181
        node.attrib['AttributeType'] = self.AttributeType if self.AttributeType is not None else ''
182
        node.attrib['AttrAt'] = str(self.AttrAt) if self.AttrAt is not None else ''
183
        node.attrib['Expression'] = self.Expression if self.Expression is not None else ''
184
        node.attrib['Length'] = str(self.Length) if self.Length is not None else ''
185 81129f87 esham21
        node.attrib['AssocItem'] = str(self.AssocItem) if self.AssocItem is not None else ''
186 afabd84e humkyung
187 a208ed03 humkyung
        return node
클립보드 이미지 추가 (최대 크기: 500 MB)