Changeset 420

Show
Ignore:
Timestamp:
Thu Jun 5 09:36:46 2008
Author:
Brian
Message:

Implemented role selection approach that Alex and I discussed. (Alex, thanks for the debugging help.)

Files:

Legend:

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

    r418 r420  
    2159 2159  
    2160 2160         role_unique = False  
      2161         role_unique_alethic = False  
    2161 2162         roles = orm_object.GetList('ORMRole')  
    2162 2163         roles.sort(cmp=lambda x,y: cmp(x.Seq, y.Seq))  
    2163           for i in range(len(roles)):  
    2164               if roles[i].Unique in ('a', 'd'):  
      2164         for i, r in enumerate(roles):  
      2165 ##            print 'role', r  
      2166 ##            print 'rolelist', self.canvas.rolelist  
      2167             if r in self.canvas.rolelist:      # selection numbers to put in role boxes  
      2168                 seq = self.canvas.rolelist.index(r)  
      2169                 dc.SetFont(self.canvas.GetFont())  
      2170                 dc.SetTextForeground('Black')  
      2171                 dc.SetTextBackground('White')  
      2172                 offsetx = i*role_box_width + 2  
      2173                 dc.DrawText(str(seq+1), x + offsetx, y)  
      2174  
      2175             if roles[i].Unique in ('a', 'd'):    # role unique bars  
    2165 2176                 role_unique = True  
    2166 2177                 if roles[i].Unique == 'a':  
      2178                     role_unique_alethic = True  
    2167 2179                     pen = self.canvas.CachedPen(3, 1, wx.SOLID)  
    2168 2180                 else:  # 'd'  
     
    2181 2193         for i in range(len(roles)):  
    2182 2194             if roles[i].UniqueOther in ('ax', 'dx'):  
    2183                   role_spans += 1  
    2184 2195                 if roles[i].UniqueOther == 'ax':  
      2196                     role_spans += 1  
    2185 2197                     pen = self.canvas.CachedPen(3, 1, wx.SOLID)  
    2186 2198                     penx = self.canvas.CachedPen(3, 1, wx.DOT)  
     
    2214 2226                 y1 = y0  
    2215 2227  
    2216           if not role_unique and not role_spans and orm_object.Unique:  
      2228         if not role_unique_alethic and not role_spans and orm_object.Unique:  
    2216 2228             pen = self.canvas.CachedPen(3, 1, wx.SOLID)  
    2217 2229             dc.SetPen(pen)  
    2218 2230             x0 = x+ 1  
    2219               y0 = y  
      2231 ##            y0 = y  
    2219 2231             x1 = x0 + len(roles) * role_box_width - 2  
    2220               y1 = y  
      2232             y1 = y0  
    2220 2232             dc.DrawLine(x0, y0, x1, y1)  
    2221 2233  
     
    2269 2281         return None  
    2270 2282  
      2283     def SetSelected(self):  
      2284         x, y = self.canvas.clickx, self.canvas.clicky  
      2285         role = self.GetRole(x, y)  
      2286         if role: self.canvas.AddRole(role)  
      2287         self._SetInShell('IsSelected', True)  
      2288         self._SetInShell('CharMode', '')  
      2289  
      2290 ##    def ClearSelected(self):  
      2291 ##        x, y = self.canvas.clickx, self.canvas.clicky  
      2292 ##        role = self.GetRole(x, y)  
      2293 ##        if role: self.canvas.RemoveRole(role)  
      2294 ##        if debug: print self.canvas.rolelist  
      2295 ##        if debug: print [ r.ORMFactTypeID == self.Target.ID for r in self.canvas.rolelist ]  
      2296 ##        if not any([ r.ORMFactTypeID == self.ID for r in self.canvas.rolelist ]):  
      2297 ##            self._SetInShell('IsSelected', False)  
      2298  
      2299     def ToggleRole(self):  
      2300         if debug: print 'toggle role'  
      2301         x, y = self.canvas.clickx, self.canvas.clicky  
      2302         role = self.GetRole(x, y)  
      2303         if role in self.canvas.rolelist:  # already on, turn it off  
      2304             self.canvas.RemoveRole(role)  
      2305             return any([ r.ORMFactTypeID == self.Target.ID for r in self.canvas.rolelist ])  
      2306         else:  # not on, turn it on  
      2307             self.canvas.AddRole(role)  
      2308             return True  
      2309  
    2271 2310 class ORMFactReadingShape(ORMFollowText):  
    2272 2311     def Draw(self, dc):  
     
    2805 2844         self.drawing = False  
    2806 2845         self.selection = {}  # keys = selected ids  
      2846         self.rolelist = []   # list of selected roles  
    2807 2847         self.keyboard_nav_dcid = False  
    2808 2848         self.selection_rectangle = False  # fix a run time error  
     
    3498 3538  
    3499 3539     def ClearSelection(self):    # keys = id, values = objects??  
      3540         self.rolelist = []  
    3500 3541         for id in self.GetSelection():  
    3501 3542             self.DropFromSelection(id)  
     
    3522 3563     def ToggleObjectSelect(self, id):  
    3523 3564         if self.InSelection(id):  
    3524               self.DropFromSelection(id)  
      3565             shape = self.dcid_to_shape_xref.get(id)  
      3566             if shape.Subtype == 'ORMFactTypeShape':  
      3567                 if not shape.ToggleRole():  
      3568 ##                    shape.Draw(self.pdc)  
      3569 ##                    self.RedisplayID(id)  
      3570 ##                else:  
      3571                     self.DropFromSelection(id)  # last role turned off  
      3572                 facts = [ x for x in self.Report.GetList('GraphicObject') if x.Subtype == 'ORMFactTypeShape' ]  
      3573                     # a bit blunt (redraws all the facts) but it works  
      3574                 for f in facts:  
      3575                     f.Draw(self.pdc)  
      3576                     self.RedisplayID(f.dcid)  
      3577             else:  
      3578                 self.DropFromSelection(id)  
    3525 3579         else:  
    3526 3580             self.AddToSelection(id)  
     
    3697 3751                 Data.SetUndo('Add %s' % 'Connector')  
    3698 3752  
      3753     def AddRole(self, role):  
      3754         if role in self.rolelist:  
      3755             self.rolelist.remove(role)  
      3756         self.rolelist.append(role)  
      3757  
      3758     def RemoveRole(self, role):  
      3759         if role in self.rolelist:  
      3760             self.rolelist.remove(role)  
      3761  
    3699 3762     # mouse handling  
    3700 3763     # left - select and move; shift - change model; cntl - change selection  
     
    3723 3786     def NewOnMouse(self, event):  
    3724 3787         global hitradius  
      3788         self.clickx = self.clicky = 0  # to identify role clicks  
    3725 3789         if event.LeftDown():  
    3726 3790             x,y = self.ConvertEventCoords(event)  
      3791             self.clickx, self.clicky = x, y  
    3727 3792             l = self.pdc.FindObjects(x, y, hitradius)  
    3728 3793             source = None  
  • ganttpv/trunk/Data.py

    r418 r420  
    632 632         return True  
    633 633  
      634     def __eq__(self, other):  # so the 'in' operator will work  
      635         return (self.ID, self.Table) == (other.ID, other.Table)  
      636  
    634 637     def __setattr__(self, name, value):  
    635 638         # edits