~lorzeteam/lorze/trunk

« back to all changes in this revision

Viewing changes to Modules/lrzattribute.py

  • Committer: Andreas Ulrich
  • Date: 2012-12-13 20:54:19 UTC
  • Revision ID: ulrich3110@gmail.com-20121213205419-aucgdskqtqmyrj10
new file structure, new object structure, about dialogue, help dialogue, hep pages in english and german, german translation, ponton5h installer, documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
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
 
7
 
 
8
# This file is part of “LORZE erasandcad“
 
9
 
 
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.
 
11
 
 
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.
 
13
 
 
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/>.
 
15
 
 
16
 
 
17
class LorzeAttribute():
 
18
    # Element attribute helper object for LORZE erasandcad
 
19
 
 
20
    def __init__(self, options, log, valchck):
 
21
        # lorze options
 
22
        self.__options= options
 
23
 
 
24
        # log object
 
25
        self.__log= log
 
26
 
 
27
        # default attributes, text
 
28
        self.__drawdefcolor= ''
 
29
        self.__drawdeflayer= ''
 
30
        self.__drawdefstyle= ''
 
31
        self.__drawdefwidth= ''
 
32
 
 
33
        # global color dictionairys: color name= key / valuedict: 'black':'#000000' / labeldict: 'black':'dark'
 
34
        self.__colorvaluedict= {}
 
35
        self.__colorlabeldict= {}
 
36
 
 
37
        # global layer dictionairy: layer name= key / labeldict: 'demo':'info'
 
38
        self.__layerlabeldict= {}
 
39
 
 
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= {}
 
43
 
 
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= {}
 
47
 
 
48
        self.__valchk= valchck
 
49
 
 
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])
 
54
 
 
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])
 
59
 
 
60
 
 
61
    def SetDefaultColor(self, color):
 
62
        # set default color, string for lorzelog
 
63
        logtext= 'LorzeAttribute.SetDefaultColor('+ color+ ')'
 
64
 
 
65
        if color in self.__colorvaluedict.keys():
 
66
            self.__log.AddEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefcolor)
 
67
            self.__drawdefcolor= color
 
68
        else:
 
69
            self.__log.AddEntry('FAIL|colour not in dictionairy|'+ logtext)
 
70
 
 
71
 
 
72
    def SetDefaultLayer(self, layer):
 
73
        # set default layer, string for lorzelog
 
74
        logtext= 'LorzeAttribute.SetDefaultLayer('+ layer+ ')'
 
75
 
 
76
        if layer in self.__layerlabeldict.keys():
 
77
            self.__log.AddEntry('OK|'+ logtext+ '|Old= '+ self.__drawdeflayer)
 
78
            self.__drawdeflayer= layer
 
79
        else:
 
80
            self.__log.AddEntry('FAIL|layer not in dictionairy|'+ logtext)
 
81
 
 
82
 
 
83
    def SetDefaultStyle(self, style):
 
84
        # set default line style, string for lorzelog
 
85
        logtext= 'LorzeAttribute.SetDefaultStyle('+ style+ ')'
 
86
 
 
87
        if style in self.__stylevaluedict.keys():
 
88
            self.__log.AddEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefstyle)
 
89
            self.__drawdefstyle= style
 
90
        else:
 
91
            self.__log.AddEntry('FAIL|line style not in dictionairy|'+ logtext)
 
92
 
 
93
 
 
94
    def SetDefaultWidth(self, width):
 
95
        # set default line width, string for lorzelog
 
96
        logtext= 'LorzeAttribute.SetDefaultWidth('+ width+ ')'
 
97
 
 
98
        if width in self.__widthvaluedict.keys():
 
99
            self.__log.AddEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefwidth)
 
100
            self.__drawdefwidth= width
 
101
        else:
 
102
            self.__log.AddEntry('FAIL|line width not in dictionairy|'+ logtext)
 
103
 
 
104
 
 
105
    def GetDefaultColor(self):
 
106
        return(self.__drawdefcolor)
 
107
 
 
108
 
 
109
    def GetDefaultLayer(self):
 
110
        return(self.__drawdeflayer)
 
111
 
 
112
 
 
113
    def GetDefaultStyle(self):
 
114
        return(self.__drawdefstyle)
 
115
 
 
116
 
 
117
    def GetDefaultWidth(self):
 
118
        return(self.__drawdefwidth)
 
119
 
 
120
 
 
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+ ')'
 
124
 
 
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)
 
129
        else:
 
130
            self.__log.AddEntry('FAIL|colour entry already exist|'+ logtext)
 
131
 
 
132
 
 
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+ ')'
 
136
 
 
137
        if name not in self.__layerlabeldict:
 
138
            self.__layerlabeldict[name]= label
 
139
            self.__log.AddEntry('OK|'+ logtext)
 
140
        else:
 
141
            self.__log.AddEntry('FAIL|layer entry already exist|'+ logtext)
 
142
 
 
143
 
 
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+ ')'
 
147
 
 
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)
 
152
        else:
 
153
            self.__log.AddEntry('FAIL|line style entry already exist|'+ logtext)
 
154
 
 
155
 
 
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+ ')'
 
159
 
 
160
        if name not in self.__widthvaluedict:
 
161
            self.__widthvaluedict[name]= float(value)
 
162
            self.__widthlabeldict[name]= label
 
163
            self.__log.AddEntry('OK|'+ logtext)
 
164
        else:
 
165
            self.__log.AddEntry('FAIL|line width entry already exist|'+ logtext)
 
166
 
 
167
 
 
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])
 
172
        else:
 
173
            return(None, None)
 
174
 
 
175
 
 
176
    def GetLayerEntry(self, name):
 
177
        # return layer values from layer dictionairy, label
 
178
        if name in self.__layerlabeldict:
 
179
            return(self.__layerlabeldict[name])
 
180
        else:
 
181
            return(None)
 
182
 
 
183
 
 
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])
 
188
        else:
 
189
            return(None, None)
 
190
 
 
191
 
 
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])
 
196
        else:
 
197
            return(None, None)
 
198
 
 
199
 
 
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())
 
203
 
 
204
 
 
205
    def AmountToList(self, amount):
 
206
        # convert amount in to list, define list
 
207
        alist= []
 
208
 
 
209
        # get from amounts
 
210
        for i in amount:
 
211
            alist.append(i)
 
212
 
 
213
        # return list
 
214
        return(alist)
 
215
 
 
216
 
 
217
    def GetWxColor(self, color):
 
218
        if color in self.__colorvaluedict:
 
219
            return(self.__colorvaluedict[color])
 
220
        else:
 
221
            return(self.__drawdefcolor)
 
222
 
 
223
 
 
224
    def GetWxStyle(self, style):
 
225
        if style in self.__stylevaluedict:
 
226
            return(self.__stylevaluedict[style])
 
227
        else:
 
228
            return(self.__drawdefstyle)
 
229
 
 
230
 
 
231
    def GetWxWidth(self, width):
 
232
        if width in self.__widthvaluedict:
 
233
            return(self.__widthvaluedict[width])
 
234
        else:
 
235
            return(self.__drawdefwidth)
 
236
 
 
237
 
 
238
if __name__== '__main__':
 
239
    from lrzoptions import LorzeOptions
 
240
    from lrzlog import LorzeLog
 
241
    from lrzvalchck import LorzeValueCheck
 
242
 
 
243
    options= LorzeOptions()
 
244
    log= LorzeLog()
 
245
    valchck= LorzeValueCheck()
 
246
    attr= LorzeAttribute(options, log, valchck)
 
247
 
 
248
    print('')
 
249
    print('GetDefaultColor', attr.GetDefaultColor())
 
250
    print('GetDefaultLayer', attr.GetDefaultLayer())
 
251
    print('GetDefaultStyle', attr.GetDefaultStyle())
 
252
    print('GetDefaultWidth', attr.GetDefaultWidth())
 
253
 
 
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')]
 
258
    for i in color:
 
259
        attr.AddColorEntry(i[0], i[1], i[2])
 
260
    for i in layer:
 
261
        attr.AddLayerEntry(i[0], i[1])
 
262
    for i in style:
 
263
        attr.AddStyleEntry(i[0], i[1], i[2])
 
264
    for i in width:
 
265
        attr.AddWidthEntry(i[0], i[1], i[2])
 
266
 
 
267
    print('')
 
268
    print('GetAllAttrNames')
 
269
    for i in attr.GetAllAttrNames():
 
270
        print(i)
 
271
    print('')
 
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])
 
277
    print('')
 
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())
 
287
    print('')
 
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())
 
297
    print('')
 
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'))
 
302
    print('')
 
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'))
 
307
    print('')
 
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'))
 
314
    print('LorzeLog')
 
315
    for i in log.GetLog():
 
316
        print(i)