@@ -34,6 +34,34 @@ class EntityDb(BaseDb):
3434 """
3535 def __init__ (self ,dbConnection ):
3636 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+
3765 if dbConnection is None :
3866 self .createConnection ()
3967 else :
@@ -42,23 +70,15 @@ def __init__(self,dbConnection):
4270 _table = self .makeSelect (_sqlCheck ).fetchone ()
4371 if _table is None :
4472 _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+
6282 self .__revisionIndex = self .getRevisionIndex ()
6383
6484 def getRevisionIndex (self ):
@@ -90,6 +110,7 @@ def saveEntity(self,entityObj,undoId):
90110 _entityId = entityObj .getId ()
91111 _entityDump = pickle .dumps (entityObj .getConstructionElements ())
92112 _entityType = entityObj .getEntityType ()
113+ _property = pickle .dumps (entityObj .properties )
93114 _entityVisible = entityObj .visible
94115 _styleObject = pickle .dumps (entityObj .style )
95116 _xMin ,_yMin ,_xMax ,_yMax = entityObj .getBBox ()
@@ -108,8 +129,9 @@ def saveEntity(self,entityObj,undoId):
108129 pycad_bbox_ymax,
109130 pycad_entity_state,
110131 pycad_index,
111- pycad_visible) VALUES
112- (?,?,?,?,?,1,?,?,?,?,?,?,?)"""
132+ pycad_visible,
133+ pycad_property) VALUES
134+ (?,?,?,?,?,1,?,?,?,?,?,?,?,?)"""
113135
114136 tupleArg = (
115137 _entityId ,
@@ -123,7 +145,8 @@ def saveEntity(self,entityObj,undoId):
123145 _yMax ,
124146 _revisionState ,
125147 _revisionIndex ,
126- _entityVisible )
148+ _entityVisible ,
149+ _property )
127150 self .makeUpdateInsert (_sqlInsert , tupleArg )
128151
129152 def getEntityFromTableId (self ,entityTableId ):
@@ -137,7 +160,8 @@ def getEntityFromTableId(self,entityTableId):
137160 pycad_object_style,
138161 pycad_entity_state,
139162 pycad_index,
140- pycad_visible
163+ pycad_visible,
164+ pycad_property
141165 FROM pycadent
142166 WHERE pycad_id=%s""" % str (entityTableId )
143167 _rows = self .makeSelect (_sqlGet )
@@ -150,6 +174,8 @@ def getEntityFromTableId(self,entityTableId):
150174 _outObj .state = _row [4 ]
151175 _outObj .index = _row [5 ]
152176 _outObj .visible = _row [6 ]
177+ for name ,value in pickle .loads (str (_row [7 ])):
178+ _outObj .addPropertie (name , value )
153179 _outObj .updateBBox ()
154180 return _outObj
155181
@@ -165,7 +191,8 @@ def getEntityEntityId(self,entityId):
165191 pycad_object_style,
166192 pycad_entity_state,
167193 pycad_index,
168- pycad_visible
194+ pycad_visible,
195+ pycad_property
169196 FROM pycadent
170197 WHERE pycad_entity_id=%s ORDER BY pycad_id DESC""" % str (entityId )
171198 _dbEntRow = self .makeSelect (_sqlGet )
@@ -177,6 +204,8 @@ def getEntityEntityId(self,entityId):
177204 _entObj .state = _row [5 ]
178205 _entObj .index = _row [6 ]
179206 _entObj .visible = _row [7 ]
207+ for name ,value in pickle .loads (str (_row [8 ])):
208+ _entObj .addPropertie (name , value )
180209 _entObj .updateBBox ()
181210 return _entObj
182211
@@ -197,7 +226,8 @@ def getEntitysFromStyle(self,styleId):
197226 pycad_object_style,
198227 pycad_entity_state,
199228 pycad_index,
200- pycad_visible
229+ pycad_visible,
230+ pycad_property
201231 FROM pycadent
202232 WHERE PyCad_Id IN (
203233 SELECT max(PyCad_Id)
@@ -213,6 +243,8 @@ def getEntitysFromStyle(self,styleId):
213243 _objEnt .state = _row [5 ]
214244 _objEnt .index = _row [6 ]
215245 _objEnt .visible = _dbEntRow [7 ]
246+ for name ,value in pickle .loads (str (_row [9 ])):
247+ _objEnt .addPropertie (name , value )
216248 _objEnt .updateBBox ()
217249 _outObj .append (_objEnt )
218250 return _outObj
@@ -229,7 +261,8 @@ def _getEntInVersion(self, versionIndex):
229261 pycad_object_style,
230262 pycad_entity_state,
231263 pycad_index,
232- pycad_visible
264+ pycad_visible,
265+ pycad_property
233266 FROM pycadent
234267 WHERE PyCad_Id IN (
235268 SELECT max(PyCad_Id)
@@ -269,7 +302,8 @@ def getMultiFilteredEntity(self, visible=1, entityType='ALL', entityTypeArray=No
269302 pycad_object_style,
270303 pycad_entity_state,
271304 pycad_index,
272- pycad_visible
305+ pycad_visible,
306+ pycad_property
273307 FROM pycadent
274308 WHERE pycad_id IN (
275309 SELECT max(pycad_id)
@@ -295,7 +329,10 @@ def getEntityFromType(self,entityType):
295329 _objEnt .state = _row [5 ]
296330 _objEnt .index = _row [6 ]
297331 _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 ()
299336 _outObj .append (_objEnt )
300337 return _outObj
301338
@@ -321,7 +358,8 @@ def convertRowToDbEnt(self, row):
321358 pycad_object_style,
322359 pycad_entity_state,
323360 pycad_index,
324- pycad_visible
361+ pycad_visible,
362+ pycad_property
325363 FROM pycadent
326364 """
327365 _style = pickle .loads (str (row [4 ]))
@@ -330,6 +368,9 @@ def convertRowToDbEnt(self, row):
330368 _objEnt .state = row [5 ]
331369 _objEnt .index = row [6 ]
332370 _objEnt .visible = row [7 ]
371+ if row [8 ]!= None :
372+ for name ,value in pickle .loads (str (row [8 ])):
373+ _objEnt .addPropertie (name , value )
333374 _objEnt .updateBBox ()
334375 return _objEnt
335376
@@ -450,6 +491,7 @@ def uptateEntity(self, entityObj):
450491 _xMin ,_yMin ,_xMax ,_yMax = entityObj .getBBox ()
451492 _revisionIndex = entityObj .index
452493 _revisionState = entityObj .state
494+ _property = pickle .dumps (entityObj .property )
453495 _sqlInsert = """UPDATE pycadent set
454496 pycad_object_type="%s",
455497 pycad_object_definition="%s",
@@ -460,7 +502,8 @@ def uptateEntity(self, entityObj):
460502 pycad_bbox_ymax=%s,
461503 pycad_entity_state="%s",
462504 pycad_index=%s,
463- pycad_visible=%s
505+ pycad_visible=%s,
506+ pycad_property=%s
464507 WHERE PyCad_Id IN (
465508 SELECT max(PyCad_Id)
466509 FROM pycadent
@@ -478,7 +521,8 @@ def uptateEntity(self, entityObj):
478521 str (_revisionState ),
479522 str (_revisionIndex ),
480523 str (_entityVisible ),
481- str (_entityId ))
524+ str (_entityId ),
525+ str (_property ))
482526 #**************************************
483527 #**************Attention***************
484528 #**************************************
0 commit comments