@@ -34,6 +34,34 @@ class EntityDb(BaseDb):
34
34
"""
35
35
def __init__ (self ,dbConnection ):
36
36
BaseDb .__init__ (self )
37
+ self ._entFields = {
38
+ 'pycad_id' :'INTEGER PRIMARY KEY' ,
39
+ 'pycad_entity_id' :'INTEGER' ,
40
+ 'pycad_object_type' :'TEXT' ,
41
+ 'pycad_object_definition' :'TEXT' ,
42
+ 'pycad_object_style' :'TEXT' ,
43
+ 'pycad_security_id' :'INTEGER' ,
44
+ 'pycad_undo_id' :'INTEGER' ,
45
+ 'pycad_entity_state' :'TEXT' ,
46
+ 'pycad_index' :'NUMERIC' ,
47
+ 'pycad_visible' :'INTEGER' ,
48
+ 'pycad_undo_visible' :'INTEGER' ,
49
+ 'pycad_locked' :'INTEGER' ,
50
+ 'pycad_bbox_xmin' :'REAL' ,
51
+ 'pycad_bbox_ymin' :'REAL' ,
52
+ 'pycad_bbox_xmax' :'REAL' ,
53
+ 'pycad_bbox_ymax' :'REAL' ,
54
+ 'pycad_property' :'TEXT'
55
+ }
56
+ def creationFieldsStr ():
57
+ outStr = ''
58
+ for fieldName ,fieldValue in self ._entFields .items ():
59
+ outStr = + '%s %s,' % (str (fieldName ),str (fieldValue ))
60
+ return outStr
61
+ def addTableField (fieldName ,fieldType ):
62
+ sql = "ALTER TABLE pycadent ADD COLUMN %s %s " % (str (fieldName ),str (fieldType ))
63
+ self .makeUpdateInsert (sql )
64
+
37
65
if dbConnection is None :
38
66
self .createConnection ()
39
67
else :
@@ -42,23 +70,15 @@ def __init__(self,dbConnection):
42
70
_table = self .makeSelect (_sqlCheck ).fetchone ()
43
71
if _table is None :
44
72
_sqlCreation = """CREATE TABLE pycadent(
45
- pycad_id INTEGER PRIMARY KEY,
46
- pycad_entity_id INTEGER,
47
- pycad_object_type TEXT,
48
- pycad_object_definition TEXT,
49
- pycad_object_style TEXT,
50
- pycad_security_id INTEGER,
51
- pycad_undo_id INTEGER,
52
- pycad_entity_state TEXT,
53
- pycad_index NUMERIC,
54
- pycad_visible INTEGER,
55
- pycad_undo_visible INTEGER,
56
- pycad_locked INTEGER,
57
- pycad_bbox_xmin REAL,
58
- pycad_bbox_ymin REAL,
59
- pycad_bbox_xmax REAL,
60
- pycad_bbox_ymax REAL)"""
61
- self .makeUpdateInsert (_sqlCreation )
73
+ %s)""" % creationFieldsStr ()
74
+ else :
75
+ rows = self .makeSelect ("pragma table_info('pycadent')" )
76
+ dbColumns = dict ([(row [1 ],row [2 ]) for row in rows ])
77
+ for classColumn in self ._entFields .keys ():
78
+ if not classColumn in dbColumns :
79
+ addTableField (classColumn ,self ._entFields [classColumn ])
80
+
81
+
62
82
self .__revisionIndex = self .getRevisionIndex ()
63
83
64
84
def getRevisionIndex (self ):
@@ -90,6 +110,7 @@ def saveEntity(self,entityObj,undoId):
90
110
_entityId = entityObj .getId ()
91
111
_entityDump = pickle .dumps (entityObj .getConstructionElements ())
92
112
_entityType = entityObj .getEntityType ()
113
+ _property = pickle .dumps (entityObj .properties )
93
114
_entityVisible = entityObj .visible
94
115
_styleObject = pickle .dumps (entityObj .style )
95
116
_xMin ,_yMin ,_xMax ,_yMax = entityObj .getBBox ()
@@ -108,8 +129,9 @@ def saveEntity(self,entityObj,undoId):
108
129
pycad_bbox_ymax,
109
130
pycad_entity_state,
110
131
pycad_index,
111
- pycad_visible) VALUES
112
- (?,?,?,?,?,1,?,?,?,?,?,?,?)"""
132
+ pycad_visible,
133
+ pycad_property) VALUES
134
+ (?,?,?,?,?,1,?,?,?,?,?,?,?,?)"""
113
135
114
136
tupleArg = (
115
137
_entityId ,
@@ -123,7 +145,8 @@ def saveEntity(self,entityObj,undoId):
123
145
_yMax ,
124
146
_revisionState ,
125
147
_revisionIndex ,
126
- _entityVisible )
148
+ _entityVisible ,
149
+ _property )
127
150
self .makeUpdateInsert (_sqlInsert , tupleArg )
128
151
129
152
def getEntityFromTableId (self ,entityTableId ):
@@ -137,7 +160,8 @@ def getEntityFromTableId(self,entityTableId):
137
160
pycad_object_style,
138
161
pycad_entity_state,
139
162
pycad_index,
140
- pycad_visible
163
+ pycad_visible,
164
+ pycad_property
141
165
FROM pycadent
142
166
WHERE pycad_id=%s""" % str (entityTableId )
143
167
_rows = self .makeSelect (_sqlGet )
@@ -150,6 +174,8 @@ def getEntityFromTableId(self,entityTableId):
150
174
_outObj .state = _row [4 ]
151
175
_outObj .index = _row [5 ]
152
176
_outObj .visible = _row [6 ]
177
+ for name ,value in pickle .loads (str (_row [7 ])):
178
+ _outObj .addPropertie (name , value )
153
179
_outObj .updateBBox ()
154
180
return _outObj
155
181
@@ -165,7 +191,8 @@ def getEntityEntityId(self,entityId):
165
191
pycad_object_style,
166
192
pycad_entity_state,
167
193
pycad_index,
168
- pycad_visible
194
+ pycad_visible,
195
+ pycad_property
169
196
FROM pycadent
170
197
WHERE pycad_entity_id=%s ORDER BY pycad_id DESC""" % str (entityId )
171
198
_dbEntRow = self .makeSelect (_sqlGet )
@@ -177,6 +204,8 @@ def getEntityEntityId(self,entityId):
177
204
_entObj .state = _row [5 ]
178
205
_entObj .index = _row [6 ]
179
206
_entObj .visible = _row [7 ]
207
+ for name ,value in pickle .loads (str (_row [8 ])):
208
+ _entObj .addPropertie (name , value )
180
209
_entObj .updateBBox ()
181
210
return _entObj
182
211
@@ -197,7 +226,8 @@ def getEntitysFromStyle(self,styleId):
197
226
pycad_object_style,
198
227
pycad_entity_state,
199
228
pycad_index,
200
- pycad_visible
229
+ pycad_visible,
230
+ pycad_property
201
231
FROM pycadent
202
232
WHERE PyCad_Id IN (
203
233
SELECT max(PyCad_Id)
@@ -213,6 +243,8 @@ def getEntitysFromStyle(self,styleId):
213
243
_objEnt .state = _row [5 ]
214
244
_objEnt .index = _row [6 ]
215
245
_objEnt .visible = _dbEntRow [7 ]
246
+ for name ,value in pickle .loads (str (_row [9 ])):
247
+ _objEnt .addPropertie (name , value )
216
248
_objEnt .updateBBox ()
217
249
_outObj .append (_objEnt )
218
250
return _outObj
@@ -229,7 +261,8 @@ def _getEntInVersion(self, versionIndex):
229
261
pycad_object_style,
230
262
pycad_entity_state,
231
263
pycad_index,
232
- pycad_visible
264
+ pycad_visible,
265
+ pycad_property
233
266
FROM pycadent
234
267
WHERE PyCad_Id IN (
235
268
SELECT max(PyCad_Id)
@@ -269,7 +302,8 @@ def getMultiFilteredEntity(self, visible=1, entityType='ALL', entityTypeArray=No
269
302
pycad_object_style,
270
303
pycad_entity_state,
271
304
pycad_index,
272
- pycad_visible
305
+ pycad_visible,
306
+ pycad_property
273
307
FROM pycadent
274
308
WHERE pycad_id IN (
275
309
SELECT max(pycad_id)
@@ -295,7 +329,10 @@ def getEntityFromType(self,entityType):
295
329
_objEnt .state = _row [5 ]
296
330
_objEnt .index = _row [6 ]
297
331
_objEnt .visible = _row [7 ]
298
- _objEnt .updateBBox ()
332
+ if _row [8 ]!= None :
333
+ for name ,value in pickle .loads (str (_row [8 ])):
334
+ _objEnt .addPropertie (name , value )
335
+ _objEnt .updateBBox ()
299
336
_outObj .append (_objEnt )
300
337
return _outObj
301
338
@@ -321,7 +358,8 @@ def convertRowToDbEnt(self, row):
321
358
pycad_object_style,
322
359
pycad_entity_state,
323
360
pycad_index,
324
- pycad_visible
361
+ pycad_visible,
362
+ pycad_property
325
363
FROM pycadent
326
364
"""
327
365
_style = pickle .loads (str (row [4 ]))
@@ -330,6 +368,9 @@ def convertRowToDbEnt(self, row):
330
368
_objEnt .state = row [5 ]
331
369
_objEnt .index = row [6 ]
332
370
_objEnt .visible = row [7 ]
371
+ if row [8 ]!= None :
372
+ for name ,value in pickle .loads (str (row [8 ])):
373
+ _objEnt .addPropertie (name , value )
333
374
_objEnt .updateBBox ()
334
375
return _objEnt
335
376
@@ -450,6 +491,7 @@ def uptateEntity(self, entityObj):
450
491
_xMin ,_yMin ,_xMax ,_yMax = entityObj .getBBox ()
451
492
_revisionIndex = entityObj .index
452
493
_revisionState = entityObj .state
494
+ _property = pickle .dumps (entityObj .property )
453
495
_sqlInsert = """UPDATE pycadent set
454
496
pycad_object_type="%s",
455
497
pycad_object_definition="%s",
@@ -460,7 +502,8 @@ def uptateEntity(self, entityObj):
460
502
pycad_bbox_ymax=%s,
461
503
pycad_entity_state="%s",
462
504
pycad_index=%s,
463
- pycad_visible=%s
505
+ pycad_visible=%s,
506
+ pycad_property=%s
464
507
WHERE PyCad_Id IN (
465
508
SELECT max(PyCad_Id)
466
509
FROM pycadent
@@ -478,7 +521,8 @@ def uptateEntity(self, entityObj):
478
521
str (_revisionState ),
479
522
str (_revisionIndex ),
480
523
str (_entityVisible ),
481
- str (_entityId ))
524
+ str (_entityId ),
525
+ str (_property ))
482
526
#**************************************
483
527
#**************Attention***************
484
528
#**************************************
0 commit comments