~lorzeteam/lorze/trunk

« back to all changes in this revision

Viewing changes to Scripts/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 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.
9
 
 
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.
11
 
 
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/>.
13
 
 
14
 
from lrzvalchck import LorzeValueCheck
15
 
 
16
 
class LorzeAttribute():
17
 
    # Element attribute helper object for LORZE erasandcad
18
 
 
19
 
    def __init__(self, parent, options):
20
 
        self.__parent= parent
21
 
 
22
 
        # lorze options
23
 
        self.__options= options
24
 
 
25
 
        # default drawing, text
26
 
        self.__defdraw= ''
27
 
 
28
 
        # default attributes, text
29
 
        self.__drawdefcolor= ''
30
 
        self.__drawdeflayer= ''
31
 
        self.__drawdefstyle= ''
32
 
        self.__drawdefwidth= ''
33
 
 
34
 
        # global color dictionairys: color name= key / valuedict: 'black':'#000000' / labeldict: 'black':'dark'
35
 
        self.__colorvaluedict= {}
36
 
        self.__colorlabeldict= {}
37
 
 
38
 
        # global layer dictionairy: layer name= key / labeldict: 'demo':'info'
39
 
        self.__layerlabeldict= {}
40
 
 
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= {}
44
 
 
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= {}
48
 
 
49
 
        self.__valchk=LorzeValueCheck()
50
 
 
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])
55
 
 
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])
60
 
 
61
 
 
62
 
    def SetDefaultDraw(self, drawing):
63
 
        # set default drawing
64
 
        drawlist= self.__parent.GetDrawings().keys()
65
 
 
66
 
        # string for lorzelog
67
 
        logtext= 'LorzeAttribute.SetDefaultDraw('+ drawing+ ')'
68
 
 
69
 
        if drawing in drawlist:
70
 
            self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__defdraw)
71
 
            self.__defdraw= drawing
72
 
        else:
73
 
            if drawlist> 0:
74
 
                logtext+= '|Old= '+ self.__defdraw
75
 
                self.__defdraw= drawlist[0]
76
 
                self.__parent.AddLogEntry('FAIL|drawing not exists, set '+ self.__defdraw+ '|'+ logtext)
77
 
            else:
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)
82
 
 
83
 
 
84
 
    def SetDefaultColor(self, color):
85
 
        # set default color, string for lorzelog
86
 
        logtext= 'LorzeAttribute.SetDefaultColor('+ color+ ')'
87
 
 
88
 
        if color in self.__colorvaluedict.keys():
89
 
            self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefcolor)
90
 
            self.__drawdefcolor= color
91
 
        else:
92
 
            self.__parent.AddLogEntry('FAIL|colour not in dictionairy|'+ logtext)
93
 
 
94
 
 
95
 
    def SetDefaultLayer(self, layer):
96
 
        # set default layer, string for lorzelog
97
 
        logtext= 'LorzeAttribute.SetDefaultLayer('+ layer+ ')'
98
 
 
99
 
        if layer in self.__layerlabeldict.keys():
100
 
            self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__drawdeflayer)
101
 
            self.__drawdeflayer= layer
102
 
        else:
103
 
            self.__parent.AddLogEntry('FAIL|layer not in dictionairy|'+ logtext)
104
 
 
105
 
 
106
 
    def SetDefaultStyle(self, style):
107
 
        # set default line style, string for lorzelog
108
 
        logtext= 'LorzeAttribute.SetDefaultStyle('+ style+ ')'
109
 
 
110
 
        if style in self.__stylevaluedict.keys():
111
 
            self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefstyle)
112
 
            self.__drawdefstyle= style
113
 
        else:
114
 
            self.__parent.AddLogEntry('FAIL|line style not in dictionairy|'+ logtext)
115
 
 
116
 
 
117
 
    def SetDefaultWidth(self, width):
118
 
        # set default line width, string for lorzelog
119
 
        logtext= 'LorzeAttribute.SetDefaultWidth('+ width+ ')'
120
 
 
121
 
        if width in self.__widthvaluedict.keys():
122
 
            self.__parent.AddLogEntry('OK|'+ logtext+ '|Old= '+ self.__drawdefwidth)
123
 
            self.__drawdefwidth= width
124
 
        else:
125
 
            self.__parent.AddLogEntry('FAIL|line width not in dictionairy|'+ logtext)
126
 
 
127
 
 
128
 
    def GetDefaultDraw(self):
129
 
        return(self.__defdraw)
130
 
 
131
 
 
132
 
    def GetDefaultColor(self):
133
 
        return(self.__drawdefcolor)
134
 
 
135
 
 
136
 
    def GetDefaultLayer(self):
137
 
        return(self.__drawdeflayer)
138
 
 
139
 
 
140
 
    def GetDefaultStyle(self):
141
 
        return(self.__drawdefstyle)
142
 
 
143
 
 
144
 
    def GetDefaultWidth(self):
145
 
        return(self.__drawdefwidth)
146
 
 
147
 
 
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+ ')'
151
 
 
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)
156
 
        else:
157
 
            self.__parent.AddLogEntry('FAIL|colour entry already exist|'+ logtext)
158
 
 
159
 
 
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+ ')'
163
 
 
164
 
        if name not in self.__layerlabeldict:
165
 
            self.__layerlabeldict[name]= label
166
 
            self.__parent.AddLogEntry('OK|'+ logtext)
167
 
        else:
168
 
            self.__parent.AddLogEntry('FAIL|layer entry already exist|'+ logtext)
169
 
 
170
 
 
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+ ')'
174
 
 
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)
179
 
        else:
180
 
            self.__parent.AddLogEntry('FAIL|line style entry already exist|'+ logtext)
181
 
 
182
 
 
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+ ')'
186
 
 
187
 
        if name not in self.__widthvaluedict:
188
 
            self.__widthvaluedict[name]= float(value)
189
 
            self.__widthlabeldict[name]= label
190
 
            self.__parent.AddLogEntry('OK|'+ logtext)
191
 
        else:
192
 
            self.__parent.AddLogEntry('FAIL|line width entry already exist|'+ logtext)
193
 
 
194
 
 
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])
199
 
        else:
200
 
            return(None, None)
201
 
 
202
 
 
203
 
    def GetLayerEntry(self, name):
204
 
        # return layer values from layer dictionairy, label
205
 
        if name in self.__layerlabeldict:
206
 
            return(self.__layerlabeldict[name])
207
 
        else:
208
 
            return(None)
209
 
 
210
 
 
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])
215
 
        else:
216
 
            return(None, None)
217
 
 
218
 
 
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])
223
 
        else:
224
 
            return(None, None)
225
 
 
226
 
 
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())
230
 
 
231
 
 
232
 
    def GetUsedAttr(self):
233
 
        # Get lists of uesd attributes from all drawings, get drawings
234
 
        drawings= self.__parent.GetDrawings()
235
 
 
236
 
        # dictionairys to store attributes and in which drawing they are used / key= attribute name, value= drawing
237
 
        usedcolordict= {}
238
 
        usedlayerdict= {}
239
 
        usedstyledict= {}
240
 
        usedwidthdict= {}
241
 
 
242
 
        for key, draw in drawings.items():
243
 
            # each LorzeDrawing, get amounts of used attributes
244
 
            color, layer, style, width= draw.GetUsedAttributes()
245
 
 
246
 
            for i in color:
247
 
                if i not in usedcolordict:
248
 
                    usedcolordict[i]= key
249
 
                else:
250
 
                    usedcolordict[i]= usedcolordict[i]+ ', '+ key
251
 
 
252
 
            for i in layer:
253
 
                if i not in usedlayerdict:
254
 
                    usedlayerdict[i]= key
255
 
                else:
256
 
                    usedlayerdict[i]= usedlayerdict[i]+ ', '+ key
257
 
 
258
 
            for i in style:
259
 
                if i not in usedstyledict:
260
 
                    usedstyledict[i]= key
261
 
                else:
262
 
                    usedstyledict[i]= usedstyledict[i]+ ', '+ key
263
 
 
264
 
            for i in width:
265
 
                if i not in usedwidthdict:
266
 
                    usedwidthdict[i]= key
267
 
                else:
268
 
                    usedwidthdict[i]= usedwidthdict[i]+ ', '+ key
269
 
 
270
 
        # return used dictionairys
271
 
        return(usedcolordict, usedlayerdict, usedstyledict, usedwidthdict)
272
 
 
273
 
 
274
 
    def GetSelectAttr(self):
275
 
        # Get lists of used attributes in selection, get elements from selection, [(lrzid, drawkey), ..]
276
 
        selectionlist= self.__parent.GetSelectElements()
277
 
 
278
 
        # get drawings
279
 
        drawings= self.__parent.GetDrawings()
280
 
 
281
 
        # dictionairys to store attributes and in which drawing they are used / key= attribute name, value= drawing
282
 
        usedcolordict= {}
283
 
        usedlayerdict= {}
284
 
        usedstyledict= {}
285
 
        usedwidthdict= {}
286
 
 
287
 
        # define amounts
288
 
        color= set()
289
 
        layer= set()
290
 
        style= set()
291
 
        width= set()
292
 
 
293
 
        # search in selectionlist
294
 
        for i in selectionlist:
295
 
            lrzid, drawkey= i
296
 
 
297
 
            # get first element of elementlist
298
 
            lrzelem= drawings[drawkey].Get([lrzid])[0]
299
 
 
300
 
            color= lrzelem.GetColor()
301
 
            if color not in usedcolordict:
302
 
                    usedcolordict[color]= drawkey
303
 
            else:
304
 
                if drawkey not in usedcolordict[color]:
305
 
                    usedcolordict[color]= usedcolordict[color]+ drawkey
306
 
 
307
 
            layer= lrzelem.GetLayer()
308
 
            if color not in usedcolordict:
309
 
                    usedcolordict[color]= drawkey
310
 
            else:
311
 
                if drawkey not in usedcolordict[color]:
312
 
                    usedcolordict[color]= usedcolordict[color]+ drawkey
313
 
 
314
 
            style= lrzelem.GetStyle()
315
 
            if color not in usedcolordict:
316
 
                    usedcolordict[color]= drawkey
317
 
            else:
318
 
                if drawkey not in usedcolordict[color]:
319
 
                    usedcolordict[color]= usedcolordict[color]+ drawkey
320
 
 
321
 
            width= lrzelem.GetWidth()
322
 
            if color not in usedcolordict:
323
 
                    usedcolordict[color]= drawkey
324
 
            else:
325
 
                if drawkey not in usedcolordict[color]:
326
 
                    usedcolordict[color]= usedcolordict[color]+ drawkey
327
 
 
328
 
        # return used dictionairys
329
 
        return(usedcolordict, usedlayerdict, usedstyledict, usedwidthdict)
330
 
 
331
 
 
332
 
    def AmountToList(self, amount):
333
 
        # convert amount in to list, define list
334
 
        alist= []
335
 
 
336
 
        # get from amounts
337
 
        for i in amount:
338
 
            alist.append(i)
339
 
 
340
 
        # return list
341
 
        return(alist)
342
 
 
343
 
 
344
 
    def GetWxColor(self, color):
345
 
        if color in self.__colorvaluedict:
346
 
            return(self.__colorvaluedict[color])
347
 
        else:
348
 
            return(self.__drawdefcolor)
349
 
 
350
 
 
351
 
    def GetWxStyle(self, style):
352
 
        if style in self.__stylevaluedict:
353
 
            return(self.__stylevaluedict[style])
354
 
        else:
355
 
            return(self.__drawdefstyle)
356
 
 
357
 
 
358
 
    def GetWxWidth(self, width):
359
 
        if width in self.__widthvaluedict:
360
 
            return(self.__widthvaluedict[width])
361
 
        else:
362
 
            return(self.__drawdefwidth)
363
 
 
364
 
 
365
 
class TestParent():
366
 
 
367
 
    def __init__(self):
368
 
        self.__options= LorzeOptions()
369
 
        self.__log= LorzeLog(self)
370
 
        self.__attr= LorzeAttribute(self, self.__options)
371
 
 
372
 
        print('')
373
 
        print('GetDefaultColor', self.__attr.GetDefaultColor())
374
 
        print('GetDefaultLayer', self.__attr.GetDefaultLayer())
375
 
        print('GetDefaultStyle', self.__attr.GetDefaultStyle())
376
 
        print('GetDefaultWidth', self.__attr.GetDefaultWidth())
377
 
 
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')]
382
 
        for i in color:
383
 
            self.__attr.AddColorEntry(i[0], i[1], i[2])
384
 
        for i in layer:
385
 
            self.__attr.AddLayerEntry(i[0], i[1])
386
 
        for i in style:
387
 
            self.__attr.AddStyleEntry(i[0], i[1], i[2])
388
 
        for i in width:
389
 
            self.__attr.AddWidthEntry(i[0], i[1], i[2])
390
 
 
391
 
        print('')
392
 
        print('GetAllAttrNames')
393
 
        for i in self.__attr.GetAllAttrNames():
394
 
            print(i)
395
 
        print('')
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])
401
 
        print('')
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())
412
 
        print('')
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())
422
 
        print('')
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'))
427
 
        print('')
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'))
432
 
        print('')
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'))
439
 
        print('LorzeLog')
440
 
        for i in self.__log.GetLog():
441
 
            print(i)
442
 
 
443
 
 
444
 
    def AddLogEntry(self, logtext):
445
 
        self.__log.AddEntry(logtext)
446
 
 
447
 
 
448
 
if __name__== '__main__':
449
 
    from lrzoptions import LorzeOptions
450
 
    from lrzlog import LorzeLog
451
 
 
452
 
    a= TestParent()