Changeset 411

Show
Ignore:
Timestamp:
Mon Jun 2 18:18:06 2008
Author:
Brian
Message:

Revised the ORM object model. Added subtypes to Data's object api.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • ganttpv/trunk/ORM.py

    r409 r411  
    56 56 # 080129 - Some clean up before the demo  
    57 57 # 080517 - Moved script into GanttPV as ORM.py  
      58 # 080602 - Revised orm object model  
    58 59  
    59 60 import wx  
     
    1192 1193 #---------------------------------------------------------------------------  
    1193 1194  
    1194   def AddNodeToDiagram(report_object, object_type, x, y):  
      1195 def AddNodeToDiagram(report_object, shape_type, x, y):  
    1194 1195     ''' Add report row, add target object'''  
    1195 1196     if debug: print report_object  
     
    1199 1200     today = Data.TodayString()  
    1200 1201  
    1201       model = {'Table': object_type, 'ProjectID': projectid, 'DateAdded': today}  
    1202       if object_type == 'ORMObjectType':  
      1202     object_type = shape_type[:-5]  # default name trims 'shape'  
      1203     model = {'ProjectID': projectid, 'DateAdded': today}  
      1204     if shape_type == 'ORMObjectTypeShape':  
    1203 1205         model['Type'] = 'Entity'  
    1204       elif object_type == 'ORMFactType':  
      1206     elif shape_type == 'ORMFactTypeShape':  # should point to a reading?  
    1204 1206         model['Nary'] = 0  # number of roles  
      1207     elif shape_type == 'ORMNoteShape':  
      1208         pass  
      1209     elif shape_type == 'ORMConstraintShape':  
      1210         pass  
      1211     model['Table'] = object_type  
    1205 1212     object_id = Data.Update(model)['ID']  
    1206 1213  
    1207 1214     graphic = {'Table': 'GraphicObject', 'ProjectID': projectid, 'ReportID': report_object.ID,  
      1215                'Subtype': shape_type,  
    1208 1216                'TableName': object_type, 'TableID': object_id,  
    1209 1217                'PosX': x, 'PosY': y,  
    1210 1218                'Width': 5, 'Height': 5,  # temporary values  
    1211 1219                'DateAdded': today}  
    1212       if object_type == 'ORMFactType':  
      1220     if shape_type == 'ORMFactTypeShape':  
    1212 1220         graphic['Orientation'] = 0  # 0..3  
    1213 1221     newrowid = Data.Update(graphic)['ID']  
     
    1221 1229     return report_object.db.GetObject('GraphicObject', newrowid)  
    1222 1230  
    1223   def AddConnectorToDiagram(report_object, object_type, nodea, nodeb):  
      1231 def AddConnectorToDiagram(report_object, shape_type, nodea, nodeb):  
    1223 1231     ''' Add report row, add target object, connect to end objects'''  
    1224       if debug: print 'adding %s to %s' % (object_type, report_object)  
      1232     if debug: print 'adding %s to %s' % (shape_type, report_object)  
    1224 1232     project = report_object.Get('Project')  
    1225 1233     projectid = project.ID  
     
    1230 1238     # I think that subtype is the only example of linking the same types to each other  
    1231 1239  
    1232       model = {'Table': object_type, 'ProjectID': projectid, 'DateAdded': today}  
      1240     object_type = shape_type[:-5]  # default name trims 'shape'  
      1241     model = {'ProjectID': projectid, 'DateAdded': today}  
    1233 1242     model[nodea.TableName + 'ID'] = nodea.TableID  
    1234       if object_type == 'ORMRole':  
      1243     if shape_type == 'ORMRoleConnectorShape':  
    1234 1243         fact = nodea.Get('Target')  
    1235 1244         fact.Nary += 1  
    1236 1245         model['Seq'] = fact.Nary  
    1237       elif object_type == 'ORMSubtypeArrow':  # what should this be called?  
      1246         object_type = 'ORMRole'  #  
      1247     elif shape_type == 'ORMSubtypeConnectorShape':  # what should this be called?  
    1238 1248         model['ORMSubtypeID'] = nodeb.TableID  
    1239       elif object_type in ('ORMNoteConnector', 'ORMConstraintConnector'):  # may connect to anything  
      1249     elif shape_type in ('ORMNoteConnectorShape', 'ORMConstraintConnectorShape'):  # may connect to anything  
    1239 1249         model['TableName'] = nodeb.TableName  
    1240 1250         model['TableID'] = nodeb.TableID  
    1241 1251     else:  
    1242 1252         model[nodeb.TableName + 'ID'] = nodeb.TableID  
      1253     model['Table'] = object_type  
    1243 1254     object_id = Data.Update(model)['ID']  
    1244 1255  
    1245 1256     graphic = {'Table': 'GraphicObject', 'ProjectID': projectid, 'ReportID': report_object.ID,  
      1257                'Subtype': shape_type,  
    1246 1258                'TableName': object_type, 'TableID': object_id,  
    1247 1259                'NodeAID': nodea.ID, 'NodeBID': nodeb.ID,  # objects pointed to  
     
    1258 1270     return report_object.db.GetObject('GraphicObject', newrowid)  
    1259 1271  
    1260   def AddFollowerToDiagram(report_object, object_type, nodea):  
      1272 def AddFollowerToDiagram(report_object, shape_type, nodea):  
    1260 1272     ''' Add report row, add target object, connect to end objects'''  
    1261       if debug: print 'adding %s to %s' % (object_type, report_object)  
      1273     if debug: print 'adding %s to %s' % (shape_type, report_object)  
    1261 1273     project = report_object.Get('Project')  
    1262 1274     projectid = project.ID  
     
    1267 1279     # I think that subtype is the only example of linking the same types to each other  
    1268 1280  
    1269       model = {'Table': object_type, 'ProjectID': projectid, 'DateAdded': today}  
      1281     object_type = shape_type[:-5]  # default name trims 'shape'  
      1282     model = {'ProjectID': projectid, 'DateAdded': today}  
    1270 1283     model[nodea.TableName + 'ID'] = nodea.TableID  
    1271 1284 #    if object_type == 'ORMFactReading':  
     
    1275 1288 #    else:  
    1276 1289 #        model[nodeb.TableName + 'ID'] = nodeb.TableID  
    1277       object_id = Data.Update(model)['ID']  
    1278       if object_type == 'ORMFactReading':  
      1290     model['Table'] = object_type  
      1291 ##    object_id = Data.Update(model)['ID']  
      1292     if shape_type == 'ORMFactReadingShape':  
      1293         object_id = Data.Update(model)['ID']  
    1279 1294         nodea.Get('Target').ORMFactReadingID = object_id  # pointer back  
    1280       elif object_type == 'ORMRoleLabel':  # is this really needed  
    1281           nodea.Get('Target').ORMRoleLabelID = object_id  # pointer back  
      1295     elif shape_type == 'ORMRoleNameShape':  # is this really needed  
      1296         object_type = 'ORMRole'  
      1297         object_id = nodea.Get('Target').ID   # same target as nodea  
      1298 ##        nodea.Get('Target').ORMRoleNameID = object_id  # pointer back  
    1282 1299  
    1283 1300     graphic = {'Table': 'GraphicObject', 'ProjectID': projectid, 'ReportID': report_object.ID,  
      1301                'Subtype': shape_type,  
    1284 1302                'TableName': object_type, 'TableID': object_id,  
    1285 1303                'NodeAID': nodea.ID, # 'NodeBID': nodeb.ID,  # objects pointed to  
    1286 1304                'PosX': nodea.PosX, 'PosY': nodea.PosY+10,  
    1287 1305                'DateAdded': today}  
      1306     if shape_type == 'ORMRoleNameShape':  
      1307         graphic['ORMRoleID'] = object_id  
    1288 1308     newrowid = Data.Update(graphic)['ID']  
    1289 1309  
     
    2261 2281  
    2262 2282  
    2263   class ORMRoleLabelShape(ORMFollowText):  
      2283 class ORMRoleNameShape(ORMFollowText):  
    2263 2283     def Draw(self, dc):  
    2264           orm_object = self.Get('Target')  
    2265           if not orm_object: return  # object has probably been undone  
    2266           orm_object = orm_object.Get('ORMRole')  # make sure this is there?  
      2284 ##        orm_object = self.Get('Target')  
      2285 ##        if not orm_object: return  # object has probably been undone  
      2286         orm_object = self.Get('ORMRole')  # make sure this is there?  
      2287         if not orm_object:  
      2288             if debug: print 'RoleNameShape not attached to role'  
      2289             return  # object has probably been undone  
    2267 2290         x, y = self.GetPos()  
    2268 2291  
     
    2272 2295         dc.SetId(self.dcid)  
    2273 2296  
    2274           text = orm_object.Name or ''  
      2297         text = (orm_object.Name or '')  
      2298         if text: text = '[' + text + ']'  
      2299         if debug: print orm_object, 'has name:', text or '--'  
    2275 2300         lines = text.splitlines()  
    2276 2301         sizes = [ self.canvas.GetFullTextExtent(line)[0:2] for line in lines ]  # pull out only w and h  
     
    2287 2312 ### don't draw anything  
    2288 2313         if text == '':  
    2289   #            pen = self.canvas.CachedPen(1, 1, wx.DOT)  
    2290               pen = self.canvas.CachedPen(1, 1, wx.SOLID)  
      2314             pen = self.canvas.CachedPen(1, 1, wx.DOT)  
      2315 #            pen = self.canvas.CachedPen(1, 1, wx.SOLID)  
    2291 2316         else:  
    2292 2317             pen = self.canvas.CachedPen(2, 1, wx.SOLID)  
    2293 2318         dc.SetPen(pen)  
    2294 2319 ###            dc.SetBrush(self.RandomBrush())  
    2295   ##        if self.GetSelected():  
    2296   ##            dc.SetBrush(self.canvas.CachedBrush((210,210,210)))  
    2297   ##        else:  
    2298   ##            dc.SetBrush(self.canvas.CachedBrush((254,254,254)))  
    2299   ###        dc.SetBrush(self.canvas.CachedBrush('White'))  
    2300   ##        dc.DrawRectangle(box_x,box_y,box_w,box_h)  
    2301   ##  
    2302   ##        dc.SetFont(self.canvas.GetFont())  
    2303   ###            dc.SetTextForeground(self.RandomColor())  
    2304   ##        dc.SetTextForeground('Black')  
    2305   ##        dc.SetTextBackground('White')  
    2306   ##        w = 3; h = 2  
    2307   ##        for i in range(len(lines)):  
    2308   ##            line = lines[i]  
    2309   ##            line_w, line_h = sizes[i]  
    2310   ##            dc.DrawText(line, box_x+w, box_y+h)  
    2311   ##            h += line_h  
      2320         if self.GetSelected():  
      2321             dc.SetBrush(self.canvas.CachedBrush((210,210,210)))  
      2322         else:  
      2323             dc.SetBrush(self.canvas.CachedBrush((254,254,254)))  
      2324 #        dc.SetBrush(self.canvas.CachedBrush('White'))  
      2325         dc.DrawRectangle(box_x,box_y,box_w,box_h)  
      2326  
      2327         dc.SetFont(self.canvas.GetFont())  
      2328 #            dc.SetTextForeground(self.RandomColor())  
      2329         dc.SetTextForeground('Black')  
      2330         dc.SetTextBackground('White')  
      2331         w = 3; h = 2  
      2332         for i in range(len(lines)):  
      2333             line = lines[i]  
      2334             line_w, line_h = sizes[i]  
      2335             dc.DrawText(line, box_x+w, box_y+h)  
      2336             h += line_h  
    2312 2337  
    2313 2338         r = wx.Rect(box_x,box_y,box_w,box_h)  
     
    2317 2342     def Char(self, char):  
    2318 2343         if debug: print "char", ord(char), "'", char, "'"  
    2319           orm_object = self.Get('Target')  
    2320           orm_object = orm_object.Get('ORMRole')  # make sure this is there?  
      2344         # orm_object = self.Get('Target')  
      2345         orm_object = self.Get('ORMRole')  # make sure this is there?  
    2321 2346         if orm_object.Name:  
    2322 2347             if char == '\x08':  # this is for windows, cross platform?  
     
    2472 2497 ##            h += line_h  
    2473 2498  
    2474   class ORMRoleShape(ORMConnector):  
      2499 class ORMRoleConnectorShape(ORMConnector):  
    2474 2499     def GetFactEnd(self):  # move to fact object??  
    2475 2500         orm_object = self.Get('Target')  
     
    2679 2704         dc.SetIdBounds(self.dcid,r)  
    2680 2705  
      2706 # Register shapes  
      2707 _subtype = {  
      2708     # generic shapes  
      2709 #    'Shape': ORMShape,  # abstract shape (no instances)  
      2710     'Box': ORMBox,  
      2711     'Circle':ORMCircle,  
      2712     'Connector': ORMConnector,  
      2713     'FollowText': ORMFollowText,  
      2714     # ORM shapes  
      2715     'ORMObjectTypeShape': ORMObjectTypeShape,  
      2716     'ORMFactTypeShape': ORMFactTypeShape,  
      2717     'ORMFactReadingShape': ORMFactReadingShape,  
      2718     # 'ORMObjectificationNameShape': ORMObjectificationNameShape,  # ??always above & centered??  
      2719     'ORMRoleNameShape': ORMRoleNameShape,  
      2720     'ORMNoteShape': ORMNoteShape,  
      2721     # 'ORMTextShape': ORMTextShape,  
      2722     # 'ORMSampleDataShape': ORMSampleDataShape,  
      2723     'ORMConstraintShape': ORMConstraintShape,  
      2724     # 'ORMValueConstraintShape': ORMValueConstraintShape,  
      2725     # 'ORMFrequencyConstraintShape': ORMFrequencyConstraintShape,  
      2726     'ORMRoleConnectorShape': ORMRoleConnectorShape,  
      2727     'ORMSubtypeConnectorShape': ORMSubtypeConnectorShape,  
      2728     'ORMNoteConnectorShape': ORMNoteConnectorShape,  
      2729     'ORMConstraintConnectorShape': ORMConstraintConnectorShape,  
      2730 }  
      2731 for k, v in _subtype.iteritems():  
      2732     Data.DB.RegisterSubtype(k, v)  
      2733  
    2681 2734 # -------------  
    2682 2735 class MyCanvas(wx.ScrolledWindow):  
     
    2684 2737         wx.ScrolledWindow.__init__(self, parent, id, (0, 0), size=size, style=wx.WANTS_CHARS | wx.SUNKEN_BORDER)  
    2685 2738  
    2686           self.leftClickType = 'ORMObjectType'  # where to specify behaviors?  
      2739         self.leftClickType = 'ORMObjectTypeShape'  # where to specify behaviors?  
    2686 2739  
    2687 2740         self.Report = report  # report object  
     
    2808 2861  
    2809 2862     def OnPopupOne(self, event):  
    2810           new_shape = self.AddNode('ORMObjectType', self.popupx, self.popupy)  
      2863         new_shape = self.AddNode('ORMObjectTypeShape', self.popupx, self.popupy)  
    2810 2863         self.ClearSelection()  
    2811 2864         self.SelectObject(new_shape.dcid)  
     
    2816 2869  
    2817 2870     def OnPopupTwo(self, event):  
    2818           new_fact = self.AddNode('ORMFactType', self.popupx, self.popupy)  
    2819           new_reading = self.AddFollower('ORMFactReading', new_fact)  
      2871         new_fact = self.AddNode('ORMFactTypeShape', self.popupx, self.popupy)  
      2872         new_reading = self.AddFollower('ORMFactReadingShape', new_fact)  
    2820 2873         self.ClearSelection()  
    2821 2874         self.SelectObject(new_fact.dcid)  
     
    2826 2879  
    2827 2880     def OnPopupThree(self, event):  
    2828           new_shape = self.AddNode('ORMNote', self.popupx, self.popupy)  
      2881         new_shape = self.AddNode('ORMNoteShape', self.popupx, self.popupy)  
    2828 2881         self.ClearSelection()  
    2829 2882         self.SelectObject(new_shape.dcid)  
     
    2834 2887  
    2835 2888     def OnPopupFour(self, event):  
    2836           new_shape = self.AddNode('ORMConstraint', self.popupx, self.popupy)  
      2889         new_shape = self.AddNode('ORMConstraintShape', self.popupx, self.popupy)  
    2836 2889         self.ClearSelection()  
    2837 2890         self.SelectObject(new_shape.dcid)  
     
    2914 2967             shape = self.dcid_to_shape_xref.get(l[0])  
    2915 2968  
    2916               if shape.TableName == 'ORMObjectType':  
      2969             if shape.Subtype == 'ORMObjectTypeShape':  
    2916 2969                 menu.Append(self.popsID06, "Dependent Layout Right")  
    2917 2970                 # make a submenu  
     
    2929 2982                 menu.Append(self.popsID01, "Change to %s Type" % change)  
    2930 2983  
    2931               elif shape.TableName == 'ORMFactType':  
      2984             elif shape.Subtype == 'ORMFactTypeShape':  
    2931 2984                 target = shape.Get('Target')  
    2932 2985                 if target.Unique:  
     
    2937 2990                 menu.Append(self.popsID02, "Set as %s" % change)  
    2938 2991  
    2939               elif shape.TableName == 'ORMRole':  
      2992             elif shape.Subtype == 'ORMRoleConnectorShape':  
    2939 2992                 target = shape.Get('Target')  
    2940 2993                 if target.Mandatory:  
     
    3153 3206         x = shape.PosX  # treat this as the center of the shape  
    3154 3207         y = shape.PosY  
      3208         if debug: print 'posx posy = ', x, y  
    3155 3209  
    3156 3210 ##        if debug: print shape, x, y  
     
    3160 3214 ##            return  
    3161 3215  
    3162           if debug: print 'orm_object table is', orm_object.Table  
    3163    
    3164           # can this logic be moved in to the object factory?  
    3165           if orm_object.Table in ('ORMObjectType'):  
    3166               shape._SetToSubclass(ORMObjectTypeShape)  
    3167               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3168    
    3169           elif orm_object.Table in ('ORMFactType'):  
    3170               shape._SetToSubclass(ORMFactTypeShape)  
    3171               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3172    
    3173           elif orm_object.Table in ('ORMFactReading'):  
    3174               shape._SetToSubclass(ORMFactReadingShape)  
    3175               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3176               shape.Follow()  
    3177    
    3178           elif orm_object.Table in ('ORMNote'):  
    3179               shape._SetToSubclass(ORMNoteShape)  
    3180               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3181                
    3182           elif orm_object.Table in ('ORMConstraint'):  
    3183               shape._SetToSubclass(ORMConstraintShape)  
    3184               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3185    
    3186           elif orm_object.Table in ('ORMConstraintConnector'):  
    3187               shape._SetToSubclass(ORMConstraintConnectorShape)  
    3188               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3189               shape.Follow()  
    3190                
    3191           elif orm_object.Table in ('ORMRole'):  
    3192               shape._SetToSubclass(ORMRoleShape)  
    3193               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3194               shape.Follow()  
    3195                
    3196           elif orm_object.Table in ('ORMRoleLabel'):  
    3197               shape._SetToSubclass(ORMRoleLabelShape)  
    3198               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3199               shape.Follow()  
    3200                
    3201           elif orm_object.Table in ('ORMSubtypeConnector'):  
    3202               shape._SetToSubclass(ORMSubtypeConnectorShape)  
    3203               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3204               shape.Follow()  
    3205                
    3206           elif orm_object.Table in ('ORMNoteConnector'):  
    3207               shape._SetToSubclass(ORMNoteConnectorShape)  
    3208               shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
    3209               shape.Follow()  
      3216 ##        if debug: print 'shape subtype is', shape.Subtype  
      3217 ##  
      3218 ##        # can this logic be moved in to the object factory?  
      3219 ##        if shape.Subtype in ('ORMObjectTypeShape'):  
      3220 ##            shape._SetToSubclass(ORMObjectTypeShape)  
      3221 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3222 ##  
      3223 ##        elif shape.Subtype in ('ORMFactTypeShape'):  
      3224 ##            shape._SetToSubclass(ORMFactTypeShape)  
      3225 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3226 ##  
      3227 ##        elif shape.Subtype in ('ORMFactReadingShape'):  
      3228 ##            shape._SetToSubclass(ORMFactReadingShape)  
      3229 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3230 ##            shape.Follow()  
      3231 ##  
      3232 ##        elif shape.Subtype in ('ORMNoteShape'):  
      3233 ##            shape._SetToSubclass(ORMNoteShape)  
      3234 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3235 ##             
      3236 ##        elif shape.Subtype in ('ORMConstraintShape'):  
      3237 ##            shape._SetToSubclass(ORMConstraintShape)  
      3238 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3239 ##  
      3240 ##        elif shape.Subtype in ('ORMConstraintConnectorShape'):  
      3241 ##            shape._SetToSubclass(ORMConstraintConnectorShape)  
      3242 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3243 ##            shape.Follow()  
      3244 ##             
      3245 ##        elif shape.Subtype in ('ORMRoleConnectorShape'):  
      3246 ##            shape._SetToSubclass(ORMRoleConnectorShape)  
      3247 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3248 ##            shape.Follow()  
      3249 ##             
      3250 ##        elif shape.Subtype in ('ORMRoleNameShape'):  
      3251 ##            shape._SetToSubclass(ORMRoleNameShape)  
      3252 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3253 ##            shape.Follow()  
      3254 ##             
      3255 ##        elif shape.Subtype in ('ORMSubtypeConnectorShape'):  
      3256 ##            shape._SetToSubclass(ORMSubtypeConnectorShape)  
      3257 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3258 ##            shape.Follow()  
      3259 ##             
      3260 ##        elif shape.Subtype in ('ORMNoteConnectorShape'):  
      3261 ##            shape._SetToSubclass(ORMNoteConnectorShape)  
      3262 ##            shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3263 ##            shape.Follow()  
    3210 3264  
      3265         shape.SetTempPos(x,y)  # used to avoid lots of updates while moving  
      3266         shape.Follow()  
    3211 3267         self.SetGraphic(dc, shape)  
    3212 3268  
     
    3241 3297         elif (source.TableName == 'ORMNote'  
    3242 3298             and target.TableName in ('ORMObjectType', 'ORMFactType')):  
    3243               new_shape = self.AddConnector('ORMNoteConnector', source, target)  
      3299             new_shape = self.AddConnector('ORMNoteConnectorShape', source, target)  
    3243 3299         elif (target.TableName == 'ORMNote'  
    3244 3300             and source.TableName in ('ORMObjectType', 'ORMFactType')):  
    3245               new_shape = self.AddConnector('ORMNoteConnector', target, source)  
      3301             new_shape = self.AddConnector('ORMNoteConnectorShape', target, source)  
    3245 3301         elif source.TableName == 'ORMObjectType' and target.TableName == 'ORMFactType':  
    3246               new_shape = self.AddConnector('ORMRole', target, source)  
    3247               new_rolelabel = self.AddFollower('ORMRoleLabel', new_shape)  
      3302             new_shape = self.AddConnector('ORMRoleConnectorShape', target, source)  
      3303             new_rolelabel = self.AddFollower('ORMRoleNameShape', new_shape)  
    3248 3304         elif source.TableName == 'ORMFactType' and target.TableName == 'ORMObjectType':  
    3249               new_shape = self.AddConnector('ORMRole', source, target)  
    3250               new_rolelabel = self.AddFollower('ORMRoleLabel', new_shape)  
      3305             new_shape = self.AddConnector('ORMRoleConnectorShape', source, target)  
      3306             new_rolelabel = self.AddFollower('ORMRoleNameShape', new_shape)  
    3251 3307         elif source.TableName == 'ORMConstraint' and target.TableName == 'ORMRole':  
    3252               new_shape = self.AddConnector('ORMConstraintConnector', source, target)  
      3308             new_shape = self.AddConnector('ORMConstraintConnectorShape', source, target)  
    3252 3308         elif source.TableName == 'ORMConstraint' and target.TableName == 'ORMSubtypeConnector':  
    3253               new_shape = self.AddConnector('ORMConstraintConnector', source, target)  
      3309             new_shape = self.AddConnector('ORMConstraintConnectorShape', source, target)  
    3253 3309         elif source.TableName == 'ORMObjectType' and target.TableName == 'ORMObjectType':  
    3254               new_shape = self.AddConnector('ORMSubtypeConnector', source, target)  
      3310             new_shape = self.AddConnector('ORMSubtypeConnectorShape', source, target)  
    3254 3310         else:  
    3255 3311             return False  
     
    3297 3353  
    3298 3354     def SelectAll(self):  
    3299           report_object = self.Report  
    3300           db = report_object.db  
    3301           shapes = [ db.GetObject('GraphicObject', x) for x in Data.SearchByColumn(db.Database['GraphicObject'], {'ReportID': self.ReportID}) ]  
    3302           for shape in shapes:  
      3355 ##        report_object = self.Report  
      3356 ##        db = report_object.db  
      3357 ##        shapes = [ db.GetObject('GraphicObject', x) for x in Data.SearchByColumn(db.Database['GraphicObject'], {'ReportID': self.ReportID}) ]  
      3358 ##        for shape in shapes:  
      3359         for shape in self.Report.GetList('GraphicObject'):  
    3303 3360             self.AddToSelection(shape.dcid)  
    3304 3361  
     
    3341 3398         if debug: print 'AddDependentsToSelection'  
    3342 3399         shape = self.dcid_to_shape_xref.get(id)  
    3343           if shape.TableName == 'ORMRole':  # relation  
      3400         if shape.Subtype == 'ORMRoleConnectorShape':  # relation  
    3343 3400             self.AddToSelection(shape.dcid)  
    3344 3401             self.AddToSelection(shape.Get('NodeA').dcid)  
    3345 3402             self.AddToSelection(shape.Get('NodeB').dcid)  
    3346           elif shape.TableName == 'ORMFactType':  
      3403         elif shape.Subtype == 'ORMFactTypeShape':  
    3346 3403             # fact -> roles -> objects (all of them?)  
    3347 3404             if debug: print 'fact followers', shape.GetFollowers()  
     
    3352 3409                 self.AddToSelection(role.dcid)  
    3353 3410                 self.AddToSelection(leaf.dcid)  
    3354           elif shape.TableName == 'ORMObjectType':  
      3411         elif shape.Subtype == 'ORMObjectTypeShape':  
    3354 3411             # object type -> role -> fact -> out_role -> leaf_object  
    3355 3412             for role in shape.GetFollowers('ORMRole'):  
     
    3382 3439         shape = self.dcid_to_shape_xref.get(id)  
    3383 3440         grid = []  
    3384           if shape.TableName == 'ORMRelation':  # relation  
      3441         if shape.Subtype == 'ORMRelation':  # relation?? doeesn't exit  
    3384 3441             pass  
    3385 3442 ##            self.AddToSelection(shape.dcid)  
    3386 3443 ##            self.AddToSelection(shape.Get('NodeA').dcid)  
    3387 3444 ##            self.AddToSelection(shape.Get('NodeB').dcid)  
    3388           elif shape.TableName == 'ORMFactType':  # fact type  
      3445         elif shape.Subtype == 'ORMFactTypeShape':  # fact type  
    3388 3445             pass  
    3389 3446 ##            # fact -> roles -> objects (all of them?)  
     
    3394 3451 ##                self.AddToSelection(role.dcid)  
    3395 3452 ##                self.AddToSelection(leaf.dcid)  
    3396           elif shape.TableName == 'ORMObjectType':  
      3453         elif shape.Subtype == 'ORMObjectTypeShape':  
    3396 3453             # object type -> role -> fact -> out_role -> leaf_object  
    3397 3454             for role in shape.GetFollowers('ORMRole'):  
     
    3488 3545         target = None  
    3489 3546         if isinstance(source, ORMObjectTypeShape):  
    3490               target = self.AddNode('ORMFactType', x, y)  
    3491               reading = self.AddFollower('ORMFactReading', target)  
      3547             target = self.AddNode('ORMFactTypeShape', x, y)  
      3548             reading = self.AddFollower('ORMFactReadingShape', target)  
    3492 3549         elif isinstance(source, ORMFactTypeShape):  
    3493               target = self.AddNode('ORMObjectType', x, y)  
      3550             target = self.AddNode('ORMObjectTypeShape', x, y)  
    3493 3550         if not target is None:  
    3494 3551             Data.SetUndo('Add %s' % target.__class__)  
     
    3681 3738 ##                        target = None  
    3682 3739 ##                        if isinstance(source, ORMObjectTypeShape):  
    3683   ##                            target = self.AddNode('ORMFactType', x, y)  
    3684   ##                            reading = self.AddFollower('ORMFactReading', target)  
      3740 ##                            target = self.AddNode('ORMFactTypeShape', x, y)  
      3741 ##                            reading = self.AddFollower('ORMFactReadingShape', target)  
    3685 3742 ##                        elif isinstance(source, ORMFactTypeShape):  
    3686   ##                            target = self.AddNode('ORMObjectType', x, y)  
      3743 ##                            target = self.AddNode('ORMObjectTypeShape', x, y)  
    3686 3743 ##                        if not target is None:  
    3687 3744 ##                            Data.SetUndo('Add %s' % target.__class__)  
     
    3791 3848                         target = None  
    3792 3849                         if isinstance(source, ORMObjectTypeShape):  
    3793                               target = self.AddNode('ORMFactType', x, y)  
      3850                             target = self.AddNode('ORMFactTypeShape', x, y)  
    3793 3850                         elif isinstance(source, ORMFactTypeShape):  
    3794                               target = self.AddNode('ORMObjectType', x, y)  
      3851                             target = self.AddNode('ORMObjectTypeShape', x, y)  
    3794 3851                         if not target is None:  
    3795 3852                             Data.SetUndo('Add %s' % target.__class__)  
     
    3922 3979                 x, y = shape.GetPos()  
    3923 3980                 yvals = []  
    3924                   if shape.TableName == 'ORMFactType':  
      3981                 if shape.Subtype == 'ORMFactTypeShape':  
    3924 3981                     yvals = [xx.Get('NodeB').PosY for xx in shape.GetFollowers()  
    3925 3982                              if xx.TableName == 'ORMRole' and xx.Get('NodeA').PosX > x]  
    3926 3983                     x += 40  
    3927 3984                     y += 5  
    3928                   elif shape.TableName == 'ORMObjectType':  
      3985                 elif shape.Subtype == 'ORMObjectTypeShape':  
    3928 3985                     yvals = [xx.Get('NodeA').PosY for xx in shape.GetFollowers()  
    3929 3986                              if xx.TableName == 'ORMRole' and xx.Get('NodeA').PosX > x]  
     
    3941 3998                 x0, y0 = shape.GetPos()  
    3942 3999                 ends = []  
    3943                   if shape.TableName == 'ORMFactType':  
      4000                 if shape.Subtype == 'ORMFactTypeShape':  
    3943 4000                     ends = [xx.Get('NodeB') for xx in shape.GetFollowers() if xx.TableName == 'ORMRole']  
    3944 4001                     ends.sort(cmp=lambda x,y: cmp(math.atan2(x.PosY, x.PosX), math.atan2(y.PosY, y.PosX)))  
    3945                   elif shape.TableName == 'ORMObjectType':  
      4002                 elif shape.Subtype == 'ORMObjectTypeShape':  
    3945 4002                     ends = [xx.Get('NodeA') for xx in shape.GetFollowers() if xx.TableName == 'ORMRole']  
    3946 4003                     ends.sort(cmp=lambda x,y: cmp(math.atan2(x.PosY-y0, x.PosX-x0), math.atan2(y.PosY-y0, y.PosX-x0)))  
     
    4000 4057 ##            self.RedisplayID(shape.dcid)  
    4001 4058             self.RedrawID(shape.dcid)  
    4002               if shape.TableName in ('ORMObjectType', 'ORMFactType', 'ORMRole'):  # why not for everything??  
      4059             if shape.Subtype in ('ORMObjectTypeShape', 'ORMFactTypeShape', 'ORMRoleConnectorShape'):  # why not for everything??  
    4002 4059                 for follow in shape.GetFollowers():  # when typing into fact  
    4003 4060                     self.RedrawID(follow.dcid)  
     
    4084 4141             # if the nodes isn't already created then do it now  
    4085 4142             if debug: print shape.__class__  
    4086               if not isinstance(shape, ORMShape):  
      4143             if not shape.canvas:  # if not processed by CreateNode before    #isinstance(shape, ORMShape):  
    4086 4143                 self.CreateNode(dc, shape)  
    4087 4144             self.SetGraphic(dc, shape)  # draw shape on this canvas  
  • ganttpv/trunk/Data.py

    r403 r411  
    102 102 # 070731 - Alex - hide assignment or dependency records that point to a deleted task or resource (somewhat ad hoc)  
    103 103 # 080517 - Brian - added object api  
      104 # 080602 - Brian - add subtypes to object api  
    104 105  
    105 106 import datetime, calendar  
     
    658 659 returns an object that this one points to  
    659 660 returns object pointed to by name + ID  
      661 does not create a new object  
    660 662         '''  
    661 663         if not name: return None  
     
    663 665  
    664 666         if self.Table in ('ReportRow', 'GraphicObject') and name == 'Target':  
    665               return self.db.GetObject(self.TableName, self.TableID)  
      667             if self.TableName and self.TableID:  # don't create new  
      668                 return self.db.GetObject(self.TableName, self.TableID)  
      669             else:  
      670                 return None  
    666 671  
    667 672         rec = self.db.Database[self.Table].get(self.ID)  
    668 673         target_id = rec.get(name + 'ID')  # FK value  
    669           return self.db.GetObject(name, target_id)  # object  
      674         if target_id:  # don't create new  
      675             return self.db.GetObject(name, target_id)  # object  
      676         else:  
      677             return None  
    670 678  
    671 679     def GetList(self, table_name, attribute=None):  
    &hel