Changeset 345

Show
Ignore:
Timestamp:
Sat Oct 20 11:18:22 2007
Author:
Brian
Message:

ORM - Move the follow behavior into the connector class.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • scripts/trunk/ORM/Open ORM Window.py

    r344 r345  
    2666 2666         return self.GetPos()  
    2667 2667  
      2668     def Follow(self):  
      2669         nodea = self.Get('NodeA')  # these objects might not already be in the diagram  
      2670         nodeb = self.Get('NodeB')  
      2671         # if not already in the diagram , then create the nodes  
      2672         print 'nodea type', nodea.__class__  
      2673         if not isinstance(nodea, ORMShape):  
      2674             self.canvas.CreateNode(self.canvas.pdc, nodea)  
      2675         print 'nodeb type', nodeb.__class__  
      2676         if not isinstance(nodeb, ORMShape):  
      2677             self.canvas.CreateNode(self.canvas.pdc, nodeb)  
      2678         nodea.AddFollower(self)  # must be the right subtype to have this method  
      2679         nodeb.AddFollower(self)  
      2680  
    2668 2681 class ORMObjectShape(ORMBox):  
    2669 2682     def Draw(self, dc):  
     
    2833 2846  
    2834 2847 class ORMRoleShape(ORMConnector):  
    2835       def Follow(self):  
      2848     def Draw(self, dc):  
      2849         orm_object = self.Get('Target')  
      2850         x = self.PosX  # treat this as the center of the shape  
      2851         y = self.PosY  
    2836 2852         nodea = self.Get('NodeA')  # these objects might not already be in the diagram  
    2837 2853         nodeb = self.Get('NodeB')  
    2838           # if not already in the diagram , then create the nodes  
    2839           print 'nodea type', nodea.__class__  
    2840           if not isinstance(nodea, ORMShape):  
    2841               self.canvas.CreateNode(self.canvas.pdc, nodea)  
    2842           print 'nodeb type', nodeb.__class__  
    2843           if not isinstance(nodeb, ORMShape):  
    2844               self.canvas.CreateNode(self.canvas.pdc, nodeb)  
    2845           nodea.AddFollower(self)  # must be the right subtype to have this method  
    2846           nodeb.AddFollower(self)  
    2847 2854  
      2855         enda = (nodea.PosX, nodea.PosY)  
      2856         endb = (nodeb.PosX, nodeb.PosY)  
      2857         enda, endb = nodea.AdjustEnd(endb), nodeb.AdjustEnd(enda)  
      2858  
      2859         dc.ClearId(self.dcid)  
      2860         dc.SetId(self.dcid)  
      2861          
      2862         minx = min(enda[0], endb[0])  
      2863         maxx = max(enda[0], endb[0])  
      2864         miny = min(enda[1], endb[1])  
      2865         maxy = max(enda[1], endb[1])  
      2866          
      2867         box_w = maxx - minx + 6  
      2868         box_h = maxy - miny + 6  
      2869  
      2870         pen = self.canvas.CachedPen(1, 1, wx.SOLID)  
      2871         dc.SetPen(pen)  
      2872         dc.DrawLine(enda[0], enda[1], endb[0], endb[1])  
      2873         self.SetTempPos((enda[0]+endb[0]) / 2, (enda[1] + endb[1]) / 2)  
      2874         # need to add logic to draw the role name  
      2875         # need to save the calculated PosX and PosY  
      2876  
      2877         # place mandatory participation  
      2878         if 1: # mandatory  
      2879             dot_size = 3  
      2880             if 1: # one end  
      2881                 dot = wx.lib.ogl.GetPointOnLine(enda[0], enda[1], endb[0], endb[1], dot_size)  
      2882             else:  
      2883                 dot = wx.lib.ogl.GetPointOnLine(endb[0], endb[1], enda[0], enda[1], dot_size)  
      2884             pen = self.canvas.CachedPen(1, 1, wx.SOLID)  
      2885             dc.SetPen(pen)  
      2886             dc.SetBrush(self.canvas.CachedBrush('Blue'))  
      2887             dc.DrawCircle(int(dot[0]),int(dot[1]),dot_size)  
      2888  
      2889         r = wx.Rect(minx,miny,box_w,box_h)  
      2890         r.Inflate(pen.GetWidth(),pen.GetWidth())  
      2891         dc.SetIdBounds(self.dcid,r)  
      2892  
      2893 class ORMSubTypeShape(ORMConnector):  
    2848 2894     def Draw(self, dc):  
    2849 2895         orm_object = self.Get('Target')  
     
    2874 2920         # need to add logic to draw the role name  
    2875 2921         # need to save the calculated PosX and PosY  
    2876            
      2922  
      2923         # subtype arrow  
      2924         arrow_length = 3  
      2925         arrow_width = 3  
      2926         arrow = wx.lib.ogl.GetArrowPoints(enda[0], enda[1], endb[0], endb[1], arrow_length, arrow_width)  
      2927         pen = self.canvas.CachedPen(1, 1, wx.SOLID)  
      2928         dc.SetPen(pen)  
      2929         dc.SetBrush(self.canvas.CachedBrush('Blue'))  
      2930         dc.DrawPolygon(arrow)  # will this work?? -- change to match required parameters  
      2931  
    2877 2932         r = wx.Rect(minx,miny,box_w,box_h)  
    2878 2933         r.Inflate(pen.GetWidth(),pen.GetWidth())  
     
    2880 2935  
    2881 2936 class ORMNoteConnectorShape(ORMConnector):  
    2882       def Follow(self):  
    2883           nodea = self.Get('NodeA')  
    2884           nodeb = self.Get('NodeB')  
    2885           # if not already in the diagram , then create the nodes  
    2886           if not isinstance(nodea, ORMShape):  
    2887               shape.canvas.CreateNode(self.canvas.pdc, nodea)  
    2888           if not isinstance(nodeb, ORMShape):  
    2889               shape.canvas.CreateNode(self.canvas.pdc, nodeb)  
    2890           nodea.AddFollower(self)  # must be the right subtype to have this method  
    2891           nodeb.AddFollower(self)  
    2892    
    2893 2937     def Draw(self, dc):  
    2894 2938         orm_object = self.Get('Target')  
     
    2923 2967  
    2924 2968 class ORMConstraintConnectorShape(ORMConnector):  
    2925       def Follow(self):  
    2926           nodea = self.Get('NodeA')  
    2927           nodeb = self.Get('NodeB')  
    2928           # if not already in the diagram , then create the nodes  
    2929           if not isinstance(nodea, ORMShape):  
    2930               shape.canvas.CreateNode(self.canvas.pdc, nodea)  
    2931           if not isinstance(nodeb, ORMShape):  
    2932               shape.canvas.CreateNode(self.canvas.pdc, nodeb)  
    2933           nodea.AddFollower(self)  # must be the right subtype to have this method  
    2934           nodeb.AddFollower(self)  
    2935    
    2936 2969     def Draw(self, dc):  
    2937 2970         orm_object = self.Get('Target')  
     
    3479 3512         random.seed()  
    3480 3513         self.objids = []  
    3481           self.shapeid_to_dcid_xref = {}  # xrefs between shapes and dc_ids  
      3514 #        self.shapeid_to_dcid_xref = {}  # NOT NEEDED - xrefs between shapes and dc_ids  
    3481 3514         self.dcid_to_shape_xref = {}     # inverse of shapeid_to_dcid_xref  
    3482           self.followers = {}  # followers[leader_shape.ID] => list of follower shapes  
      3515 #        self.followers = {}  # followers[leader_shape.ID] => list of follower shapes  
    3482 3515         self.boundsdict = {}  
    3483 3516         dc.BeginDrawing()  
     
    3496 3529         dc.EndDrawing()  
    3497 3530  
    3498           if debug: print self.shapeid_to_dcid_xref  
    3499           if debug: print self.followers  
      3531 #        if debug: print self.shapeid_to_dcid_xref  
      3532 #        if debug: print self.followers  
    3500 3533 ##    def DoDrawing(self, dc):  
    3501 3534 ##        random.seed()