Changeset 427

Show
Ignore:
Timestamp:
Fri Jun 6 20:56:21 2008
Author:
Brian
Message:

Add objectified fact types

Files:

Legend:

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

    r425 r427  
    1   # Copyright 2007 by Brian C. Christensen  
      1 # Copyright 2007, 2008 by Brian C. Christensen  
    1 1  
    2 2 # uses FlagNotebook to control placement of the notebook pages on the screen  
     
    1346 1346         object_id = nodea.Get('Target').ID   # same target as nodea  
    1347 1347 ##        nodea.Get('Target').ORMRoleNameID = object_id  # pointer back  
      1348     elif shape_type == 'ORMObjectTypeShape':  
      1349         model['Type'] = 'Entity'  
      1350         object_id = Data.Update(model)['ID']  
    1348 1351  
    1349 1352     graphic = {'Table': 'GraphicObject', 'ProjectID': projectid, 'ReportID': report_object.ID,  
     
    2017 2020         nodea = self.Get('NodeA')  # these objects might not already be in the diagram  
    2018 2021         nodeb = self.Get('NodeB')  
    2019           # if not already in the diagram , then create the nodes  
    2020           print 'nodea type', nodea.__class__  
    2021           if not isinstance(nodea, ORMShape):  
    2022               self.canvas.CreateNode(self.canvas.pdc, nodea)  
    2023           print 'nodeb type', nodeb.__class__  
    2024           if not isinstance(nodeb, ORMShape):  
    2025               self.canvas.CreateNode(self.canvas.pdc, nodeb)  
      2022 ##        # if not already in the diagram , then create the nodes  
      2023 ##        print 'nodea type', nodea.__class__  
      2024 ##        if not isinstance(nodea, ORMShape):  
      2025 ##            self.canvas.CreateNode(self.canvas.pdc, nodea)  
      2026 ##        print 'nodeb type', nodeb.__class__  
      2027 ##        if not isinstance(nodeb, ORMShape):  
      2028 ##            self.canvas.CreateNode(self.canvas.pdc, nodeb)  
    2026 2029         nodea.AddFollower(self)  # must be the right subtype to have this method  
    2027 2030         nodeb.AddFollower(self)  
     
    2030 2033     def Follow(self):  
    2031 2034         nodea = self.Get('NodeA')  # these objects might not already be in the diagram  
    2032           # if not already in the diagram , then create the nodes  
    2033           print 'nodea type', nodea.__class__  
    2034           if not isinstance(nodea, ORMShape):  
    2035               self.canvas.CreateNode(self.canvas.pdc, nodea)  
      2035 ##        # if not already in the diagram , then create the nodes  
      2036 ##        print 'nodea type', nodea.__class__  
      2037 ##        if not isinstance(nodea, ORMShape):  
      2038 ##            self.canvas.CreateNode(self.canvas.pdc, nodea)  
    2036 2039         nodea.AddFollower(self)  # must be the right subtype to have this method  
    2037 2040  
    2038 2041 class ORMObjectTypeShape(ORMBox):  
      2042     def Follow(self):  
      2043         nodea = self.Get('NodeA')  
      2044         if nodea:  # if objectified fact type  
      2045             nodea.AddFollower(self)  
      2046          
      2047     def CommitPos(self):  # if self moved while fact type was not selected  
      2048         ORMBox.CommitPos(self)  
      2049         if self.NodeA:  
      2050             self.NodeA.CommitPos()  
      2051  
    2039 2052     def Draw(self, dc):  
    2040 2053         orm_object = self.Get('Target')  
    2041 2054         x, y = self.GetPos()  
    2042   ##        x = self.PosX  # treat this as the center of the shape  
    2043   ##        y = self.PosY  
    2044 2055  
    2045 2056         dc.ClearId(self.dcid)  
     
    2058 2069         if orm_object.Derived:  
    2059 2070             text += " " + orm_object.Derived  
      2071         if self.NodeA:  # objectified fact type  
      2072             text = '"' + text + '"'  
    2060 2073         lines = text.splitlines()  
    2061 2074         word = orm_object.RefMode or ''  
     
    2074 2087             w = max(w, line_w)  
    2075 2088             h += line_h  
    2076           box_w = w + left_margin + right_margin # 8  
    2077           box_h = h + top_margin + bottom_margin # 6  
    2078 2089  
    2079 2090         if orm_object.Type == 'Entity':  
     
    2090 2101             dc.SetBrush(self.canvas.CachedBrush((254,254,254,128)))  
    2091 2102             # dc.SetBrush(self.canvas.CachedBrush('White'))  
    2092   ##        if debug: print 'round rectangle dimensions',x, y, box_w, box_h  
    2093           box_x = x - box_w/2  
    2094           box_y = y - box_h/2  
    2095   #            dc.DrawRoundedRectangle(box_x,box_y,box_w,box_h,8)  
    2096           dc.DrawRoundedRectangle(box_x,box_y,box_w,box_h,5)  # 6  
      2103  
      2104         if self.NodeA:  # objectified fact type  
      2105             box_w = role_box_width * self.NodeA.Target.Nary + left_margin + right_margin + 4  
      2106             box_h = role_box_width + top_margin + bottom_margin  
      2107  
      2108             box_x = x - box_w/2  
      2109             box_y = y - box_h/2 + 3  
      2110     #            dc.DrawRoundedRectangle(box_x,box_y,box_w,box_h,8)  
      2111             dc.DrawRoundedRectangle(box_x,box_y,box_w,box_h,5)  
      2112             start_text = top_margin + h  # start text this far above the box  
      2113             yy = box_y - start_text  
      2114         else:  
      2115             box_w = w + left_margin + right_margin  
      2116             box_h = h + top_margin + bottom_margin  
      2117  
      2118             box_x = x - box_w/2  
      2119             box_y = y - box_h/2  
      2120     #            dc.DrawRoundedRectangle(box_x,box_y,box_w,box_h,8)  
      2121             dc.DrawRoundedRectangle(box_x,box_y,box_w,box_h,5)  
      2122             start_text = 0  # only for objectified fact types  
      2123             yy = box_y + top_margin  
    2097 2124  
    2098 2125         dc.SetFont(self.canvas.GetFont())  
     
    2101 2128         dc.SetTextForeground('Black')  
    2102 2129         dc.SetTextBackground('White')  
    2103           yy = box_y + top_margin  
    2104 2130         for i in range(len(lines)):  
    2105 2131             dc.DrawText(lines[i], x - sizes[i][0]/2, yy)  # center text in box  
     
    2107 2133             yy += sizes[i][1]  
    2108 2134  
    2109           r = wx.Rect(box_x,box_y,box_w,box_h)  
      2135         width_adj = max(w - box_w, 0)  # if the text is wider that the box  
      2136         r = wx.Rect(box_x - width_adj //2,box_y - start_text,box_w + width_adj,box_h + start_text)  
    2110 2137 #        r.Inflate(pen.GetWidth(),pen.GetWidth())  
    2111 2138         dc.SetIdBounds(self.dcid,r)  # bounds inclose all of the drawing??  
     
    2192 2219         return ax, ay  
    2193 2220  
      2221     def GetCenter(self):  
      2222         x, y = self.GetPos()  
      2223         y += role_box_height // 2  
      2224         x += role_box_width * self.Target.Nary // 2  
      2225         return x, y  
      2226  
    2194 2227     def Draw(self, dc):  
    2195 2228         orm_object = self.Get('Target')  
     
    2377 2410             return True  
    2378 2411  
      2412     def OnTop(self):  
      2413         print 'started ontop'  
      2414         followers = self.GetFollowers()  
      2415         object_type_shape = None  
      2416         for f in followers:  
      2417             if f.Subtype == 'ORMObjectTypeShape':  
      2418                 object_type_shape = f  
      2419                 break  
      2420         if object_type_shape:  
      2421             print 'found objectified'  
      2422             if self.dcid < object_type_shape.dcid:  
      2423                 print 'reseting fact dcid'  
      2424                 dc = self.canvas.pdc  
      2425                 dc.RemoveId(self.dcid)  # clear the old id  
      2426                 self.canvas.SetGraphic(dc, self, newid=True)  # create new one  
      2427             for f in followers:  
      2428                 print 'looking at', f  
      2429                 if debug:  
      2430                     print "object dcid, other dcid", f.dcid, object_type_shape.dcid  
      2431                 if f.dcid < object_type_shape.dcid:  # if behind object type shape  
      2432                     dc.RemoveId(f.dcid)  # clear the old id  
      2433                     self.canvas.SetGraphic(dc, f, newid=True)  # create new one  
      2434  
    2379 2435 class ORMFactReadingShape(ORMFollowText):  
    2380 2436     def Draw(self, dc):  
     
    3335 3391             elif shape.Subtype == 'ORMFactTypeShape':  
    3336 3392                 target = shape.Get('Target')  
    3337   ##                if target.Unique:  
    3338   ##                    change = 'Not Spanning Unique'  
    3339   ##                else:  
    3340   ##                    change = 'Spanning Unique'  
    3341 3393                 menu.AppendCheckItem(self.popsID02, "Set as Spanning Unique")  
    3342 3394                 menu.Check(self.popsID02, bool(target.Unique))  
     
    3347 3399                     menu.AppendSeparator()  
    3348 3400                     self.RoleMenu(role, menu)  
      3401                 menu.AppendSeparator()  
      3402                 menu.AppendCheckItem(self.popsID04, "Objectify Fact Type")  
      3403                 menu.Check(self.popsID04, bool(target.GetList('ORMObjectType')))  
    3349 3404  
    3350 3405             elif shape.Subtype == 'ORMRoleConnectorShape':  
     
    3429 3484             Data.SetUndo('Reverse role order')  
    3430 3485  
    3431       def OnPops04(self, event):  
    3432           self.log.WriteText("Popup seven\n")  
      3486     def ObjectifyFact(self, event):  
      3487         l = self.pdc.FindObjects(self.popupx, self.popupy, hitradius)  
      3488         if l:  
      3489             fact_shape = self.dcid_to_shape_xref.get(l[0])  
      3490             fact_mo = fact_shape.Target  
      3491             if fact_mo.GetList('ORMObjectType'):  
      3492                 if debug: print "trying to objectify an objectified fact type"  
      3493                 return  # already objectified  
      3494 #            object_shape = self.AddNode('ORMObjectTypeShape', self.popupx, self.popupy)  
      3495             object_shape = self.AddFollower('ORMObjectTypeShape', fact_shape)  
      3496             x, y = fact_shape.GetCenter()  # posx and posy should be the center, but aren't  
      3497             object_shape.SetTempPos(x, y)  
      3498             object_shape.CommitPos()  
      3499 ##            object_mo = object_shape.Target  
      3500 ##            object_shape.NodeAID = fact_shape.ID  
      3501 ##            object_mo.FactTypeID = fact_mo.ID  
      3502             fact_shape.OnTop()  # move object type behind fact type  
      3503             Data.SetUndo('Objectify Fact Type')  
      3504             self.RedrawID(fact_shape.dcid)  
      3505             self.RedrawID(object_shape.dcid)  
      3506  
      3507     def UnObjectifyFact(self, event):  
      3508         pass  
      3509  
      3510     def OnPops04(self, event):  # objectify fact type  
      3511         if event.IsChecked():  
      3512             self.ObjectifyFact(event)  
      3513         else:  
      3514             self.UnObjectifyFact(event)  
    3433 3515  
    3434 3516     def OnPops05(self, event):  
     
    3689 3771         dc = self.pdc  
    3690 3772         dc.BeginDrawing()  
    3691           self.CreateNode(dc, shape)  
      3773         self.CreateNode(dc, shape)  # sets follower behavior  
    3691 3773         source.Draw(dc)  
    3692 3774         dc.EndDrawing()  
    3693 3775         return shape  
    3694 3776  
    3695       def SetGraphic(self, dc, shape):  
    3696           if self != shape.canvas or not shape.dcid:  
      3777     def SetGraphic(self, dc, shape, newid=False):  
      3778         if self != shape.canvas or not shape.dcid or newid:  
    3697 3779             id = wx.NewId()  
    3698 3780             # need to remember which dc id belongs to which shape  
     
    4471 4553  
    4472 4554     def MoveSelection(self, dx, dy):  
    4473           for id in self.GetSelection():  
    4474               self.MoveID(id, dx, dy)  
      4555         for dcid in self.GetSelection():  
      4556  
      4557             # special handling of objectified fact types  
      4558             # because moving object type should move the fact type, too  
      4559             shape = self.dcid_to_shape_xref.get(dcid)  
      4560             if shape.Subtype == 'ORMObjectTypeShape' and shape.NodeA:  
      4561                 if self.InSelection(shape.NodeA.dcid):  
      4562                     pass  # move because follow is surpressed when both are selected  
      4563                 else:  # move fact type  
      4564                     self.MoveID(shape.NodeA.dcid, dx, dy)  
      4565                     continue  
      4566  
      4567             self.MoveID(dcid, dx, dy)  
    4475 4568  
    4476 4569     def MoveID(self, dcid, dx, dy, follow=0):