Changeset 414

Show
Ignore:
Timestamp:
Mon Jun 2 21:09:43 2008
Author:
Brian
Message:

Added reverse role order popup. Don't display role names until they follow correctly.

Files:

Legend:

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

    r411 r414  
    2293 2293         dc.ClearId(self.dcid)  
    2294 2294         if not orm_object: return  # object has probably been undone  
    2295           dc.SetId(self.dcid)  
    2296    
    2297           text = (orm_object.Name or '')  
    2298           if text: text = '[' + text + ']'  
    2299           if debug: print orm_object, 'has name:', text or '--'  
    2300           lines = text.splitlines()  
    2301           sizes = [ self.canvas.GetFullTextExtent(line)[0:2] for line in lines ]  # pull out only w and h  
    2302           w = 5  
    2303           h = 0  
    2304           for line_w,line_h in sizes:  
    2305               w = max(w, line_w)  
    2306               h += line_h  
    2307           box_w = w + 6  
    2308           box_h = h + 6  
    2309           box_x = x - box_w/2  
    2310           box_y = y - box_h/2  
    2311    
    2312   ### don't draw anything  
    2313           if text == '':  
    2314               pen = self.canvas.CachedPen(1, 1, wx.DOT)  
    2315   #            pen = self.canvas.CachedPen(1, 1, wx.SOLID)  
    2316           else:  
    2317               pen = self.canvas.CachedPen(2, 1, wx.SOLID)  
    2318           dc.SetPen(pen)  
    2319   ###            dc.SetBrush(self.RandomBrush())  
    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  
    2337    
    2338           r = wx.Rect(box_x,box_y,box_w,box_h)  
    2339           r.Inflate(pen.GetWidth(),pen.GetWidth())  
    2340           dc.SetIdBounds(self.dcid,r)  
      2295 ##        dc.SetId(self.dcid)  
      2296 ##  
      2297 ##        text = (orm_object.Name or '')  
      2298 ##        if text: text = '[' + text + ']'  
      2299 ##        if debug: print orm_object, 'has name:', text or '--'  
      2300 ##        lines = text.splitlines()  
      2301 ##        sizes = [ self.canvas.GetFullTextExtent(line)[0:2] for line in lines ]  # pull out only w and h  
      2302 ##        w = 5  
      2303 ##        h = 0  
      2304 ##        for line_w,line_h in sizes:  
      2305 ##            w = max(w, line_w)  
      2306 ##            h += line_h  
      2307 ##        box_w = w + 6  
      2308 ##        box_h = h + 6  
      2309 ##        box_x = x - box_w/2  
      2310 ##        box_y = y - box_h/2  
      2311 ##  
      2312 ##### don't draw anything  
      2313 ##        if text == '':  
      2314 ##            pen = self.canvas.CachedPen(1, 1, wx.DOT)  
      2315 ###            pen = self.canvas.CachedPen(1, 1, wx.SOLID)  
      2316 ##        else:  
      2317 ##            pen = self.canvas.CachedPen(2, 1, wx.SOLID)  
      2318 ##        dc.SetPen(pen)  
      2319 #####            dc.SetBrush(self.RandomBrush())  
      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  
      2337 ##  
      2338 ##        r = wx.Rect(box_x,box_y,box_w,box_h)  
      2339 ##        r.Inflate(pen.GetWidth(),pen.GetWidth())  
      2340 ##        dc.SetIdBounds(self.dcid,r)  
    2341 2341  
    2342 2342     def Char(self, char):  
     
    2989 2989                     change = 'Unique'  
    2990 2990                 menu.Append(self.popsID02, "Set as %s" % change)  
      2991                 if target.Nary == 2:  
      2992                     menu.Append(self.popsID03, "Reverse Role Order")  
    2991 2993  
    2992 2994             elif shape.Subtype == 'ORMRoleConnectorShape':  
     
    3043 3045  
    3044 3046     def OnPops03(self, event):  
    3045           self.log.WriteText("Popup seven\n")  
      3047         '''Reverse role order'''  
      3048         l = self.pdc.FindObjects(self.popupx, self.popupy, hitradius)  
      3049         if l:  
      3050             shape = self.dcid_to_shape_xref.get(l[0])  # fact type shape  
      3051             # reverse readings  
      3052             target = shape.Get('Target')  
      3053             if target.Nary != 2: return  
      3054             reading = target.Get('ORMFactReading')  
      3055             if not reading.Reading:  
      3056                 pass  
      3057             elif '/' in reading.Reading:  
      3058                 a, x, b = reading.Reading.partition('/')  
      3059                 if '/' in b:  
      3060                     return  
      3061                 elif a:  
      3062                     reading.Reading = b + '/' + a  
      3063                 else:  
      3064                     reading.Reading = b  
      3065             else:  
      3066                 reading.Reading = '/' + reading.Reading  
      3067  
      3068             # reverse the order of role connectors  
      3069             roles = target.GetList('ORMRole')  
      3070             sorted_roles = sorted(roles, cmp=lambda x,y: cmp(x.Seq, y.Seq), reverse=True)  
      3071             for i, x in enumerate(sorted_roles):  
      3072                 x.Seq = i+1  
      3073             self.RedrawID(shape.dcid)  
      3074             for x in shape.GetFollowers():  
      3075                 self.RedrawID(x.dcid)  
      3076             Data.SetUndo('Reverse role order')  
    3046 3077  
    3047 3078     def OnPops04(self, event):  
     
    3189 3220         '''  
    3190 3221         if debug: print '--> creating node for ', shape  
    3191           shape._SetInShell('canvas', self)  # needed for followers  
      3222         # shape._SetInShell('canvas', self)  # needed for followers  
    3191 3222  
    3192 3223 ##        # add methods to shape object  
     
    4140 4171         for shape in shapes:  
    4141 4172             # if the nodes isn't already created then do it now  
    4142               if debug: print shape.__class__  
    4143               if not shape.canvas:  # if not processed by CreateNode before    #isinstance(shape, ORMShape):  
      4173             if debug: print 'before create of:', shape.__class__  
      4174             if shape.canvas != self:  # if not processed by CreateNode before    #isinstance(shape, ORMShape):  
    4144 4175                 self.CreateNode(dc, shape)  
    4145 4176             self.SetGraphic(dc, shape)  # draw shape on this canvas