-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypedef_cl.py
135 lines (118 loc) · 6.94 KB
/
typedef_cl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import collections.abc
from enum import IntEnum
#CL class definition
class CL_typeDef():
def __init__(self, book_title = ''):
self.book_title = book_title
self.components = None #список основных компонентов
self.accessories = None #список сопутствующих компонентов
self.substitutes = None #список допустимых замен
class Sublist():
def __init__(self, title = '', entries = None):
self.title = title
self.entries = [] if entries is None else entries
class FlagType(IntEnum):
NONE = 0
OK = 1
WARNING = 2
ERROR = 3
class ComponentEntry():
def __init__(self, designator = None, kind = None, value = None, description = None, package = None, manufacturer = None, quantity = 0, note = None, flag = None):
self.designator = []
self.kind = []
self.value = []
self.description = []
self.package = []
self.manufacturer = []
self.quantity = int(quantity)
self.note = []
self.flag = CL_typeDef.FlagType.NONE
if isinstance(designator, (list, tuple)): self.designator.extend(designator)
else: self.designator.append(designator)
if isinstance(kind, (list, tuple)): self.kind.extend(kind)
else: self.kind.append(kind)
if isinstance(value, (list, tuple)): self.value.extend(value)
else: self.value.append(value)
if isinstance(description, (list, tuple)): self.description.extend(description)
else: self.description.append(description)
if isinstance(package, (list, tuple)): self.package.extend(package)
else: self.package.append(package)
if isinstance(manufacturer, (list, tuple)): self.manufacturer.extend(manufacturer)
else: self.manufacturer.append(manufacturer)
if isinstance(note, (list, tuple)): self.note.extend(note)
else: self.note.append(note)
if flag is not None: self.flag = flag
#добавляет компонент к текущей записи
def add(self, designator, kind, value, description, package, manufacturer, quantity = 1, note = '', flag = None):
if flag == None: flag = CL_typeDef.FlagType.NONE
if flag > self.flag: self.flag = flag
if designator in self.designator:
#если уже есть такой десигнатор то что-то пошло не так
if self.flag < CL_typeDef.FlagType.ERROR: self.flag = CL_typeDef.FlagType.ERROR
self.designator.append(designator)
if kind not in self.kind:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING #если поля не совпадают то это подозрительно
self.kind.append(kind)
if value not in self.value:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
self.value.append(value)
if description not in self.description:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
self.description.append(description)
if package not in self.package:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
self.package.append(package)
if manufacturer not in self.manufacturer:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
self.manufacturer.append(manufacturer)
self.quantity += quantity
if note not in self.note:
#if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
self.note.append(note)
#проверяет текущую запись на ошибки
def check(self):
#десигнатор
if len(self.designator) != len(set(self.designator)): #проверяем есть ли дубликаты
if self.flag < CL_typeDef.FlagType.ERROR: self.flag = CL_typeDef.FlagType.ERROR
#тип
if len(self.kind) > 1:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
#номинал
if len(self.value) > 1:
if self.flag < CL_typeDef.FlagType.ERROR: self.flag = CL_typeDef.FlagType.ERROR
#описание
if len(self.description) > 1:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
#корпус
if len(self.package) > 1:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
#производитель
if len(self.manufacturer) > 1:
if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
#количество
if self.quantity < 0:
if self.flag < CL_typeDef.FlagType.ERROR: self.flag = CL_typeDef.FlagType.ERROR
#примечание
if len(self.note) > 1:
pass #if self.flag < CL_typeDef.FlagType.WARNING: self.flag = CL_typeDef.FlagType.WARNING
class SubstituteEntry():
def __init__(self, primary_value = None, primary_manufacturer = None, primary_quantity = 0, substitute_group = None, flag = None):
self.primary_value = primary_value
self.primary_manufacturer = primary_manufacturer
self.primary_quantity = int(primary_quantity)
self.substitute_group = substitute_group
self.flag = CL_typeDef.FlagType.NONE
if flag is not None: self.flag = flag
class SubstituteGroup():
def __init__(self, designator = None, quantity = 0, substitute = None, flag = None):
self.designator = designator
self.quantity = int(quantity)
self.substitute = substitute
self.flag = CL_typeDef.FlagType.NONE
if flag is not None: self.flag = flag
class Substitute():
def __init__(self, value = None, manufacturer = None, note = None):
self.value = value #номинал
self.manufacturer = manufacturer #производитель
self.note = note #примечание
self.flag = CL_typeDef.FlagType.NONE