2
# -*- coding: utf-8 -*-
4
# LORZE erasandcad, a 2D CAD with an intuitive user interface, simple and easy.
5
# http://erasand.jimdo.com/python-programme/lorze/
6
# (C) 2012, Andreas Ulrich
8
# This file is part of “LORZE erasandcad“
10
# “LORZE erasandcad“ is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
12
# “LORZE erasandcad“ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License along with LORZE erasandcad. If not, see <http://www.gnu.org/licenses/>.
17
class LorzeAttribute():
18
# Element attribute helper object for LORZE erasandcad
20
def __init__(self, options, log, valchck):
22
self.__options= options
27
# default attributes, text
28
self.__drawdefcolor= ''
29
self.__drawdeflayer= ''
30
self.__drawdefstyle= ''
31
self.__drawdefwidth= ''
33
# global color dictionairys: color name= key / valuedict: 'black':'#000000' / labeldict: 'black':'dark'
34
self.__colorvaluedict= {}
35
self.__colorlabeldict= {}
37
# global layer dictionairy: layer name= key / labeldict: 'demo':'info'
38
self.__layerlabeldict= {}
40
# global line style dictionairys: line style name= key / valuedict: 'dashed':('wx.USER_DASH', [40, 50, 40]) / labeldict: 'dashed':'dashed group A'
41
self.__stylevaluedict= {}
42
self.__stylelabeldict= {}
44
# global line width dictionairys: line width name= key / valuedict: '0,25 mm':0.25 / labeldict: '0,25 mm':Rotring white'
45
self.__widthvaluedict= {}
46
self.__widthlabeldict= {}
48
self.__valchk= valchck
50
self.AddColorEntry(self.__options.GetDrawDefColor()[0], self.__options.GetDrawDefColor()[1], self.__options.GetDrawDefColor()[2])
51
self.AddLayerEntry(self.__options.GetDrawDefLayer()[0], self.__options.GetDrawDefLayer()[1])
52
self.AddStyleEntry(self.__options.GetDrawDefStyle()[0], self.__options.GetDrawDefStyle()[1], self.__options.GetDrawDefStyle()[2])
53
self.AddWidthEntry(self.__options.GetDrawDefWidth()[0], self.__options.GetDrawDefWidth()[1], self.__options.GetDrawDefWidth()[2])
55
self.SetDefaultColor(self.__options.GetDrawDefColor()[0])
56
self.SetDefaultLayer(self.__options.GetDrawDefLayer()[0])
57
self.SetDefaultStyle(self.__options.GetDrawDefStyle()[0])
58
self.SetDefaultWidth(self.__options.GetDrawDefWidth()[0])
61
def SetDefaultColor(self, color):
62
# set default color, string for lorzelog
63
logtext= 'LorzeAttribute.SetDefaultColor('+ color+ ')'
65
if color in self.__colorvaluedict.keys():
66
self.__log.AddEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefcolor)
67
self.__drawdefcolor= color
69
self.__log.AddEntry('FAIL|colour not in dictionairy|'+ logtext)
72
def SetDefaultLayer(self, layer):
73
# set default layer, string for lorzelog
74
logtext= 'LorzeAttribute.SetDefaultLayer('+ layer+ ')'
76
if layer in self.__layerlabeldict.keys():
77
self.__log.AddEntry('OK|'+ logtext+ '|Old= '+ self.__drawdeflayer)
78
self.__drawdeflayer= layer
80
self.__log.AddEntry('FAIL|layer not in dictionairy|'+ logtext)
83
def SetDefaultStyle(self, style):
84
# set default line style, string for lorzelog
85
logtext= 'LorzeAttribute.SetDefaultStyle('+ style+ ')'
87
if style in self.__stylevaluedict.keys():
88
self.__log.AddEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefstyle)
89
self.__drawdefstyle= style
91
self.__log.AddEntry('FAIL|line style not in dictionairy|'+ logtext)
94
def SetDefaultWidth(self, width):
95
# set default line width, string for lorzelog
96
logtext= 'LorzeAttribute.SetDefaultWidth('+ width+ ')'
98
if width in self.__widthvaluedict.keys():
99
self.__log.AddEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefwidth)
100
self.__drawdefwidth= width
102
self.__log.AddEntry('FAIL|line width not in dictionairy|'+ logtext)
105
def GetDefaultColor(self):
106
return(self.__drawdefcolor)
109
def GetDefaultLayer(self):
110
return(self.__drawdeflayer)
113
def GetDefaultStyle(self):
114
return(self.__drawdefstyle)
117
def GetDefaultWidth(self):
118
return(self.__drawdefwidth)
121
def AddColorEntry(self, name, value, label):
122
# add new colour to colour dictionairy, name= text, value= html color, label= text, string for lorzelog
123
logtext= 'LorzeAttribute.AddColorEntry('+ name+ ', '+ value+ ', '+ label+ ')'
125
if name not in self.__colorvaluedict:
126
self.__colorvaluedict[name]= self.__valchk.RGBtxtToHTMLcol(value)
127
self.__colorlabeldict[name]= label
128
self.__log.AddEntry('OK|'+ logtext)
130
self.__log.AddEntry('FAIL|colour entry already exist|'+ logtext)
133
def AddLayerEntry(self, name, label):
134
# add new layer to colourdictionairy, name= text, label= text, string for lorzelog
135
logtext= 'LorzeAttribute.AddLayerEntry('+ name+ ', '+ label+ ')'
137
if name not in self.__layerlabeldict:
138
self.__layerlabeldict[name]= label
139
self.__log.AddEntry('OK|'+ logtext)
141
self.__log.AddEntry('FAIL|layer entry already exist|'+ logtext)
144
def AddStyleEntry(self, name, value, label):
145
# add new layer to colourdictionairy, name= text, value= text, convert to tupel ('wx.SOLID', []), label= text, string for lorzelog
146
logtext= 'LorzeAttribute.AddStyleEntry('+ name+ ', '+ value+ ', '+ label+ ')'
148
if name not in self.__stylevaluedict:
149
self.__stylevaluedict[name]= self.__valchk.LorzeTextToWxStyle(value)
150
self.__stylelabeldict[name]= label
151
self.__log.AddEntry('OK|'+ logtext)
153
self.__log.AddEntry('FAIL|line style entry already exist|'+ logtext)
156
def AddWidthEntry(self, name, value, label):
157
# add new layer to colourdictionairy, name= text, value= text, convert to float, label= text, string for lorzelog
158
logtext= 'LorzeAttribute.AddWidthEntry('+ name+ ', '+ value+ ', '+ label+ ')'
160
if name not in self.__widthvaluedict:
161
self.__widthvaluedict[name]= float(value)
162
self.__widthlabeldict[name]= label
163
self.__log.AddEntry('OK|'+ logtext)
165
self.__log.AddEntry('FAIL|line width entry already exist|'+ logtext)
168
def GetColorEntry(self, name):
169
# return colour values from colour dictionairy, value, label, convert value to RGB Text before return
170
if name in self.__colorvaluedict:
171
return(self.__valchk.HTMLcolToRGBtxt(self.__colorvaluedict[name]), self.__colorlabeldict[name])
176
def GetLayerEntry(self, name):
177
# return layer values from layer dictionairy, label
178
if name in self.__layerlabeldict:
179
return(self.__layerlabeldict[name])
184
def GetStyleEntry(self, name):
185
# return style values from style dictionairy, value, label, convert value to Lorze text before return
186
if name in self.__stylevaluedict:
187
return(self.__valchk.WxStyleToLorzeText(self.__stylevaluedict[name]), self.__stylelabeldict[name])
192
def GetWidthEntry(self, name):
193
# return width values from width dictionairy, value, label, convert value to text before return
194
if name in self.__widthvaluedict:
195
return(str(self.__widthvaluedict[name]), self.__widthlabeldict[name])
200
def GetAllAttrNames(self):
201
# return all attribute names, colors, layers, styles, widths
202
return(self.__colorvaluedict.keys(), self.__layerlabeldict.keys(), self.__stylevaluedict.keys(), self.__widthvaluedict.keys())
205
def AmountToList(self, amount):
206
# convert amount in to list, define list
217
def GetWxColor(self, color):
218
if color in self.__colorvaluedict:
219
return(self.__colorvaluedict[color])
221
return(self.__drawdefcolor)
224
def GetWxStyle(self, style):
225
if style in self.__stylevaluedict:
226
return(self.__stylevaluedict[style])
228
return(self.__drawdefstyle)
231
def GetWxWidth(self, width):
232
if width in self.__widthvaluedict:
233
return(self.__widthvaluedict[width])
235
return(self.__drawdefwidth)
238
if __name__== '__main__':
239
from lrzoptions import LorzeOptions
240
from lrzlog import LorzeLog
241
from lrzvalchck import LorzeValueCheck
243
options= LorzeOptions()
245
valchck= LorzeValueCheck()
246
attr= LorzeAttribute(options, log, valchck)
249
print('GetDefaultColor', attr.GetDefaultColor())
250
print('GetDefaultLayer', attr.GetDefaultLayer())
251
print('GetDefaultStyle', attr.GetDefaultStyle())
252
print('GetDefaultWidth', attr.GetDefaultWidth())
254
color= [('Red', '255, 0, 0', 'base color'), ('Blue', '0, 0, 255', 'base color'), ('Green', '0, 128, 0', 'base color'), ('Yellow', '255, 255, 0', 'base color'), ('Gray', '128, 128, 128', 'base color'), ('White', '0, 0, 0', 'base color')]
255
layer= [('Layer 1', 'default'), ('Layer 2', 'default'), ('Layer 3', 'default'), ('Layer 4', 'default'), ('Layer 5', 'default'), ('Layer 6', 'default')]
256
style= [('Solid', 'SOLID', 'standard'), ('Dot', 'DOT', 'standard'), ('Long dash', 'LONG_DASH', 'standard'), ('Short dash', 'SHORT_DASH', 'standard'), ('Dot dash', 'DOT_DASH', 'standard'), ('Axis 13mm', '4, 2, 1, 2, 4', 'standard')]
257
width= [('0.13mm', '0.13', 'Rotring'), ('0.18mm', '0.18', 'Rotring'), ('0.25mm', '0.25', 'Rotring'), ('0.35mm', '0.35', 'Rotring'), ('0.50mm', '0.50', 'Rotring'), ('0.70mm', '0.70', 'Rotring')]
259
attr.AddColorEntry(i[0], i[1], i[2])
261
attr.AddLayerEntry(i[0], i[1])
263
attr.AddStyleEntry(i[0], i[1], i[2])
265
attr.AddWidthEntry(i[0], i[1], i[2])
268
print('GetAllAttrNames')
269
for i in attr.GetAllAttrNames():
272
print('Trying to add again Green, Layer 6, Dot dash, 0.7mm / visit the LorzeLog')
273
attr.AddColorEntry(color[2][0], color[2][1], color[2][2])
274
attr.AddLayerEntry(layer[5][0], layer[5][1])
275
attr.AddStyleEntry(style[5][0], style[5][1], style[5][2])
276
attr.AddWidthEntry(width[5][0], width[5][1], width[5][2])
278
print('SetDefault Attributes to Red, Layer 1, Axis 13mm, 0.25mm')
279
attr.SetDefaultColor('Red')
280
attr.SetDefaultLayer('Layer 1')
281
attr.SetDefaultStyle('Axis 13mm')
282
attr.SetDefaultWidth('0.25mm')
283
print('GetDefaultColor', attr.GetDefaultColor())
284
print('GetDefaultLayer', attr.GetDefaultLayer())
285
print('GetDefaultStyle', attr.GetDefaultStyle())
286
print('GetDefaultWidth', attr.GetDefaultWidth())
288
print('SetDefault Attributes to error, error, error, error')
289
attr.SetDefaultColor('error')
290
attr.SetDefaultLayer('error')
291
attr.SetDefaultStyle('error')
292
attr.SetDefaultWidth('error')
293
print('GetDefaultColor', attr.GetDefaultColor())
294
print('GetDefaultLayer', attr.GetDefaultLayer())
295
print('GetDefaultStyle', attr.GetDefaultStyle())
296
print('GetDefaultWidth', attr.GetDefaultWidth())
298
print('GetColorEntry Blue', attr.GetColorEntry('Blue'))
299
print('GetLayerEntry Layer 3', attr.GetLayerEntry('Layer 3'))
300
print('GetStyleEntry Long dash', attr.GetStyleEntry('Long dash'))
301
print('GetWidthEntry 0.50mm', attr.GetWidthEntry('0.50mm'))
303
print('GetColorEntry error', attr.GetColorEntry('error'))
304
print('GetLayerEntry error', attr.GetLayerEntry('error'))
305
print('GetStyleEntry error', attr.GetStyleEntry('error'))
306
print('GetWidthEntry error', attr.GetWidthEntry('error'))
308
print('GetWxColor Gray', attr.GetWxColor('Gray'))
309
print('GetWxStyle Short dash', attr.GetWxStyle('Short dash'))
310
print('GetWxWidth 0.35mm)', attr.GetWxWidth('0.35mm'))
311
print('GetWxColor error', attr.GetWxColor('error'))
312
print('GetWxStyle error', attr.GetWxStyle('error'))
313
print('GetWxWidth error)', attr.GetWxWidth('error'))
315
for i in log.GetLog():