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 program 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.
10
# This program 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.
12
# You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
14
from lrzvalchck import LorzeValueCheck
16
class LorzeAttribute():
17
# Element attribute helper object for LORZE erasandcad
19
def __init__(self, parent, options):
23
self.__options= options
25
# default drawing, text
28
# default attributes, text
29
self.__drawdefcolor= ''
30
self.__drawdeflayer= ''
31
self.__drawdefstyle= ''
32
self.__drawdefwidth= ''
34
# global color dictionairys: color name= key / valuedict: 'black':'#000000' / labeldict: 'black':'dark'
35
self.__colorvaluedict= {}
36
self.__colorlabeldict= {}
38
# global layer dictionairy: layer name= key / labeldict: 'demo':'info'
39
self.__layerlabeldict= {}
41
# global line style dictionairys: line style name= key / valuedict: 'dashed':('wx.USER_DASH', [40, 50, 40]) / labeldict: 'dashed':'dashed group A'
42
self.__stylevaluedict= {}
43
self.__stylelabeldict= {}
45
# global line width dictionairys: line width name= key / valuedict: '0,25 mm':0.25 / labeldict: '0,25 mm':Rotring white'
46
self.__widthvaluedict= {}
47
self.__widthlabeldict= {}
49
self.__valchk=LorzeValueCheck()
51
self.AddColorEntry(self.__options.GetDrawDefColor()[0], self.__options.GetDrawDefColor()[1], self.__options.GetDrawDefColor()[2])
52
self.AddLayerEntry(self.__options.GetDrawDefLayer()[0], self.__options.GetDrawDefLayer()[1])
53
self.AddStyleEntry(self.__options.GetDrawDefStyle()[0], self.__options.GetDrawDefStyle()[1], self.__options.GetDrawDefStyle()[2])
54
self.AddWidthEntry(self.__options.GetDrawDefWidth()[0], self.__options.GetDrawDefWidth()[1], self.__options.GetDrawDefWidth()[2])
56
self.SetDefaultColor(self.__options.GetDrawDefColor()[0])
57
self.SetDefaultLayer(self.__options.GetDrawDefLayer()[0])
58
self.SetDefaultStyle(self.__options.GetDrawDefStyle()[0])
59
self.SetDefaultWidth(self.__options.GetDrawDefWidth()[0])
62
def SetDefaultDraw(self, drawing):
64
drawlist= self.__parent.GetDrawings().keys()
67
logtext= 'LorzeAttribute.SetDefaultDraw('+ drawing+ ')'
69
if drawing in drawlist:
70
self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__defdraw)
71
self.__defdraw= drawing
74
logtext+= '|Old= '+ self.__defdraw
75
self.__defdraw= drawlist[0]
76
self.__parent.AddLogEntry('FAIL|drawing not exists, set '+ self.__defdraw+ '|'+ logtext)
78
logtext+= '|Old= '+ self.__defdraw
79
self.__defdraw= 'Drawing'
80
self.__parent.AddDrawing(LorzeDrawing(self.__parent), self.__defdraw)
81
self.__parent.AddLogEntry('FAIL|drawing not exists, create new drawing '+ self.__defdraw+ '|'+ logtext)
84
def SetDefaultColor(self, color):
85
# set default color, string for lorzelog
86
logtext= 'LorzeAttribute.SetDefaultColor('+ color+ ')'
88
if color in self.__colorvaluedict.keys():
89
self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefcolor)
90
self.__drawdefcolor= color
92
self.__parent.AddLogEntry('FAIL|colour not in dictionairy|'+ logtext)
95
def SetDefaultLayer(self, layer):
96
# set default layer, string for lorzelog
97
logtext= 'LorzeAttribute.SetDefaultLayer('+ layer+ ')'
99
if layer in self.__layerlabeldict.keys():
100
self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__drawdeflayer)
101
self.__drawdeflayer= layer
103
self.__parent.AddLogEntry('FAIL|layer not in dictionairy|'+ logtext)
106
def SetDefaultStyle(self, style):
107
# set default line style, string for lorzelog
108
logtext= 'LorzeAttribute.SetDefaultStyle('+ style+ ')'
110
if style in self.__stylevaluedict.keys():
111
self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefstyle)
112
self.__drawdefstyle= style
114
self.__parent.AddLogEntry('FAIL|line style not in dictionairy|'+ logtext)
117
def SetDefaultWidth(self, width):
118
# set default line width, string for lorzelog
119
logtext= 'LorzeAttribute.SetDefaultWidth('+ width+ ')'
121
if width in self.__widthvaluedict.keys():
122
self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefwidth)
123
self.__drawdefwidth= width
125
self.__parent.AddLogEntry('FAIL|line width not in dictionairy|'+ logtext)
128
def GetDefaultDraw(self):
129
return(self.__defdraw)
132
def GetDefaultColor(self):
133
return(self.__drawdefcolor)
136
def GetDefaultLayer(self):
137
return(self.__drawdeflayer)
140
def GetDefaultStyle(self):
141
return(self.__drawdefstyle)
144
def GetDefaultWidth(self):
145
return(self.__drawdefwidth)
148
def AddColorEntry(self, name, value, label):
149
# add new colour to colour dictionairy, name= text, value= RGB text, convert to html color, label= text, string for lorzelog
150
logtext= 'LorzeAttribute.AddColorEntry('+ name+ ', '+ value+ ', '+ label+ ')'
152
if name not in self.__colorvaluedict:
153
self.__colorvaluedict[name]= self.__valchk.RGBtxtToHTMLcol(value)
154
self.__colorlabeldict[name]= label
155
self.__parent.AddLogEntry('OK|'+ logtext)
157
self.__parent.AddLogEntry('FAIL|colour entry already exist|'+ logtext)
160
def AddLayerEntry(self, name, label):
161
# add new layer to colourdictionairy, name= text, label= text, string for lorzelog
162
logtext= 'LorzeAttribute.AddLayerEntry('+ name+ ', '+ label+ ')'
164
if name not in self.__layerlabeldict:
165
self.__layerlabeldict[name]= label
166
self.__parent.AddLogEntry('OK|'+ logtext)
168
self.__parent.AddLogEntry('FAIL|layer entry already exist|'+ logtext)
171
def AddStyleEntry(self, name, value, label):
172
# add new layer to colourdictionairy, name= text, value= text, convert to tupel ('wx.SOLID', []), label= text, string for lorzelog
173
logtext= 'LorzeAttribute.AddStyleEntry('+ name+ ', '+ value+ ', '+ label+ ')'
175
if name not in self.__stylevaluedict:
176
self.__stylevaluedict[name]= self.__valchk.LorzeTextToWxStyle(value)
177
self.__stylelabeldict[name]= label
178
self.__parent.AddLogEntry('OK|'+ logtext)
180
self.__parent.AddLogEntry('FAIL|line style entry already exist|'+ logtext)
183
def AddWidthEntry(self, name, value, label):
184
# add new layer to colourdictionairy, name= text, value= text, convert to float, label= text, string for lorzelog
185
logtext= 'LorzeAttribute.AddWidthEntry('+ name+ ', '+ value+ ', '+ label+ ')'
187
if name not in self.__widthvaluedict:
188
self.__widthvaluedict[name]= float(value)
189
self.__widthlabeldict[name]= label
190
self.__parent.AddLogEntry('OK|'+ logtext)
192
self.__parent.AddLogEntry('FAIL|line width entry already exist|'+ logtext)
195
def GetColorEntry(self, name):
196
# return colour values from colour dictionairy, value, label, convert value to RGB Text before return
197
if name in self.__colorvaluedict:
198
return(self.__valchk.HTMLcolToRGBtxt(self.__colorvaluedict[name]), self.__colorlabeldict[name])
203
def GetLayerEntry(self, name):
204
# return layer values from layer dictionairy, label
205
if name in self.__layerlabeldict:
206
return(self.__layerlabeldict[name])
211
def GetStyleEntry(self, name):
212
# return style values from style dictionairy, value, label, convert value to Lorze text before return
213
if name in self.__stylevaluedict:
214
return(self.__valchk.WxStyleToLorzeText(self.__stylevaluedict[name]), self.__stylelabeldict[name])
219
def GetWidthEntry(self, name):
220
# return width values from width dictionairy, value, label, convert value to text before return
221
if name in self.__widthvaluedict:
222
return(str(self.__widthvaluedict[name]), self.__widthlabeldict[name])
227
def GetAllAttrNames(self):
228
# return all attribute names, colors, layers, styles, widths
229
return(self.__colorvaluedict.keys(), self.__layerlabeldict.keys(), self.__stylevaluedict.keys(), self.__widthvaluedict.keys())
232
def GetUsedAttr(self):
233
# Get lists of uesd attributes from all drawings, get drawings
234
drawings= self.__parent.GetDrawings()
236
# dictionairys to store attributes and in which drawing they are used / key= attribute name, value= drawing
242
for key, draw in drawings.items():
243
# each LorzeDrawing, get amounts of used attributes
244
color, layer, style, width= draw.GetUsedAttributes()
247
if i not in usedcolordict:
248
usedcolordict[i]= key
250
usedcolordict[i]= usedcolordict[i]+ ', '+ key
253
if i not in usedlayerdict:
254
usedlayerdict[i]= key
256
usedlayerdict[i]= usedlayerdict[i]+ ', '+ key
259
if i not in usedstyledict:
260
usedstyledict[i]= key
262
usedstyledict[i]= usedstyledict[i]+ ', '+ key
265
if i not in usedwidthdict:
266
usedwidthdict[i]= key
268
usedwidthdict[i]= usedwidthdict[i]+ ', '+ key
270
# return used dictionairys
271
return(usedcolordict, usedlayerdict, usedstyledict, usedwidthdict)
274
def GetSelectAttr(self):
275
# Get lists of used attributes in selection, get elements from selection, [(lrzid, drawkey), ..]
276
selectionlist= self.__parent.GetSelectElements()
279
drawings= self.__parent.GetDrawings()
281
# dictionairys to store attributes and in which drawing they are used / key= attribute name, value= drawing
293
# search in selectionlist
294
for i in selectionlist:
297
# get first element of elementlist
298
lrzelem= drawings[drawkey].Get([lrzid])[0]
300
color= lrzelem.GetColor()
301
if color not in usedcolordict:
302
usedcolordict[color]= drawkey
304
if drawkey not in usedcolordict[color]:
305
usedcolordict[color]= usedcolordict[color]+ drawkey
307
layer= lrzelem.GetLayer()
308
if color not in usedcolordict:
309
usedcolordict[color]= drawkey
311
if drawkey not in usedcolordict[color]:
312
usedcolordict[color]= usedcolordict[color]+ drawkey
314
style= lrzelem.GetStyle()
315
if color not in usedcolordict:
316
usedcolordict[color]= drawkey
318
if drawkey not in usedcolordict[color]:
319
usedcolordict[color]= usedcolordict[color]+ drawkey
321
width= lrzelem.GetWidth()
322
if color not in usedcolordict:
323
usedcolordict[color]= drawkey
325
if drawkey not in usedcolordict[color]:
326
usedcolordict[color]= usedcolordict[color]+ drawkey
328
# return used dictionairys
329
return(usedcolordict, usedlayerdict, usedstyledict, usedwidthdict)
332
def AmountToList(self, amount):
333
# convert amount in to list, define list
344
def GetWxColor(self, color):
345
if color in self.__colorvaluedict:
346
return(self.__colorvaluedict[color])
348
return(self.__drawdefcolor)
351
def GetWxStyle(self, style):
352
if style in self.__stylevaluedict:
353
return(self.__stylevaluedict[style])
355
return(self.__drawdefstyle)
358
def GetWxWidth(self, width):
359
if width in self.__widthvaluedict:
360
return(self.__widthvaluedict[width])
362
return(self.__drawdefwidth)
368
self.__options= LorzeOptions()
369
self.__log= LorzeLog(self)
370
self.__attr= LorzeAttribute(self, self.__options)
373
print('GetDefaultColor', self.__attr.GetDefaultColor())
374
print('GetDefaultLayer', self.__attr.GetDefaultLayer())
375
print('GetDefaultStyle', self.__attr.GetDefaultStyle())
376
print('GetDefaultWidth', self.__attr.GetDefaultWidth())
378
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')]
379
layer= [('Layer 1', 'default'), ('Layer 2', 'default'), ('Layer 3', 'default'), ('Layer 4', 'default'), ('Layer 5', 'default'), ('Layer 6', 'default')]
380
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')]
381
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')]
383
self.__attr.AddColorEntry(i[0], i[1], i[2])
385
self.__attr.AddLayerEntry(i[0], i[1])
387
self.__attr.AddStyleEntry(i[0], i[1], i[2])
389
self.__attr.AddWidthEntry(i[0], i[1], i[2])
392
print('GetAllAttrNames')
393
for i in self.__attr.GetAllAttrNames():
396
print('Trying to add again Green, Layer 6, Dot dash, 0.7mm / visit the LorzeLog')
397
self.__attr.AddColorEntry(color[2][0], color[2][1], color[2][2])
398
self.__attr.AddLayerEntry(layer[5][0], layer[5][1])
399
self.__attr.AddStyleEntry(style[5][0], style[5][1], style[5][2])
400
self.__attr.AddWidthEntry(width[5][0], width[5][1], width[5][2])
402
print('SetDefault Attributes to Red, Layer 1, Axis 13mm, 0.25mm')
403
self.__attr.SetDefaultColor('Red')
404
self.__attr.SetDefaultLayer('Layer 1')
405
self.__attr.SetDefaultStyle('Axis 13mm')
406
self.__attr.SetDefaultWidth('0.25mm')
407
print('GetDefaultDraw', self.__attr.GetDefaultDraw())
408
print('GetDefaultColor', self.__attr.GetDefaultColor())
409
print('GetDefaultLayer', self.__attr.GetDefaultLayer())
410
print('GetDefaultStyle', self.__attr.GetDefaultStyle())
411
print('GetDefaultWidth', self.__attr.GetDefaultWidth())
413
print('SetDefault Attributes to error, error, error, error')
414
self.__attr.SetDefaultColor('error')
415
self.__attr.SetDefaultLayer('error')
416
self.__attr.SetDefaultStyle('error')
417
self.__attr.SetDefaultWidth('error')
418
print('GetDefaultColor', self.__attr.GetDefaultColor())
419
print('GetDefaultLayer', self.__attr.GetDefaultLayer())
420
print('GetDefaultStyle', self.__attr.GetDefaultStyle())
421
print('GetDefaultWidth', self.__attr.GetDefaultWidth())
423
print('GetColorEntry Blue', self.__attr.GetColorEntry('Blue'))
424
print('GetLayerEntry Layer 3', self.__attr.GetLayerEntry('Layer 3'))
425
print('GetStyleEntry Long dash', self.__attr.GetStyleEntry('Long dash'))
426
print('GetWidthEntry 0.50mm', self.__attr.GetWidthEntry('0.50mm'))
428
print('GetColorEntry error', self.__attr.GetColorEntry('error'))
429
print('GetLayerEntry error', self.__attr.GetLayerEntry('error'))
430
print('GetStyleEntry error', self.__attr.GetStyleEntry('error'))
431
print('GetWidthEntry error', self.__attr.GetWidthEntry('error'))
433
print('GetWxColor Gray', self.__attr.GetWxColor('Gray'))
434
print('GetWxStyle Short dash', self.__attr.GetWxStyle('Short dash'))
435
print('GetWxWidth 0.35mm)', self.__attr.GetWxWidth('0.35mm'))
436
print('GetWxColor error', self.__attr.GetWxColor('error'))
437
print('GetWxStyle error', self.__attr.GetWxStyle('error'))
438
print('GetWxWidth error)', self.__attr.GetWxWidth('error'))
440
for i in self.__log.GetLog():
444
def AddLogEntry(self, logtext):
445
self.__log.AddEntry(logtext)
448
if __name__== '__main__':
449
from lrzoptions import LorzeOptions
450
from lrzlog import LorzeLog