Changeset 372

Show
Ignore:
Timestamp:
Thu Jan 31 12:37:04 2008
Author:
Brian
Message:

Fix dependend selection and dependent formating

Files:

Legend:

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

    r371 r372  
    1836 1836     def AddFollower(self, follower_shape):  
    1837 1837         self.followers.append(follower_shape)  
    1838       def GetFollowers(self):  # use this instead of accessing followers directly  
      1838     def GetFollowers(self, filter=''):  # use this instead of accessing followers directly  
      1839         if filter:  
      1840             return [ x for x in self.followers if x.TableName == filter ]  
    1839 1841         return self.followers  # returned value can be iterated over  
    1840 1842     def RemoveFollower(self, follower_shape):  
     
    3313 3315         if debug: print 'AddDependentsToSelection'  
    3314 3316         shape = self.dcid_to_shape_xref.get(id)  
    3315           if shape.NodeAID:  # relation  
      3317         if shape.TableName == 'ORMRole':  # relation  
    3315 3317             self.AddToSelection(shape.dcid)  
    3316 3318             self.AddToSelection(shape.Get('NodeA').dcid)  
    3317 3319             self.AddToSelection(shape.Get('NodeB').dcid)  
    3318           elif shape.Get('Target').Nary:  # fact type  
      3320         elif shape.TableName == 'ORMFactType':  
    3318 3320             # fact -> roles -> objects (all of them?)  
    3319               print shape.GetFollowers()  
    3320               for role in shape.GetFollowers():  
    3321                   if role.NodeAID:  # relation (role)  
    3322                       if debug: print 'follower id %s' % role.NodeAID  
    3323                       leaf = role.Get('NodeA')  # should be the fact  
    3324                       if leaf.ID == shape.ID:  
    3325                           leaf = role.Get('NodeB')  
    3326                       if debug: print 'leaf followers %s' % leaf.GetFollowers()  
    3327                       # if len(leaf.GetFollowers()) == 1:  # should filter out notes -- TODO!  
    3328                       self.AddToSelection(role.dcid)  
    3329                       self.AddToSelection(leaf.dcid)  
    3330                   else:  # -- are they always relations?  
    3331                       pass  
    3332           elif shape.Get('Target').Name:  # object type -- better test?  
      3321             if debug: print 'fact followers', shape.GetFollowers()  
      3322             for role in shape.GetFollowers('ORMRole'):  
      3323                 leaf = role.Get('NodeB')  
      3324                 self.AddToSelection(role.dcid)  
      3325                 self.AddToSelection(leaf.dcid)  
      3326         elif shape.TableName == 'ORMObjectType':  
    3333 3327             # object type -> role -> fact -> out_role -> leaf_object  
    3334               for role in shape.GetFollowers():  
    3335                   if not role.NodeAID: continue  # relation (role)  
    3336                   if debug: print 'role id %s' % role.NodeAID  
      3328             for role in shape.GetFollowers('ORMRole'):  
    3337 3329                 fact = role.Get('NodeA')  # find the other end  
    3338                   if fact.ID == shape.ID:  
    3339                       fact = role.Get('NodeB')  
    3340                   if debug: print 'fact followers %s' % fact.GetFollowers()  
    3341                   out_roles = fact.GetFollowers()  
      3330                 out_roles = fact.GetFollowers('ORMRole')  
    3342 3331                 if len(out_roles) == 1:  # nary = 1  
    3343 3332                     if debug: print 'nary = 1'  
    3344 3333                     self.AddToSelection(role.dcid)  
    3345 3334                     self.AddToSelection(fact.dcid)  
    3346                   elif len(out_roles) == 2:  # should filter out notes -- TODO!  
    3347                       out_role = out_roles[0]  # should be the fact  
      3335                 elif len(out_roles) == 2:  #  
      3336                     out_role = out_roles[0]  # find the other object type  
    3348 3337                     if out_role.ID == role.ID:  
    3349 3338                         out_role = out_roles[1]  
    3350                       leaf = out_role.Get('NodeA')  # should be the fact  
    3351                       if leaf.ID == fact.ID:  
    3352                           leaf = out_role.Get('NodeB')  
    3353                       if len(leaf.GetFollowers()) == 1:  # should filter out notes -- TODO!  
      3339                     leaf = out_role.Get('NodeB')  
      3340                     if len(leaf.GetFollowers('ORMRole')) == 1:  # should filter out notes -- TODO!  
    3354 3341                         self.AddToSelection(role.dcid)  
    3355 3342                         self.AddToSelection(fact.dcid)  
    3356 3343                         self.AddToSelection(out_role.dcid)  
    3357 3344                         self.AddToSelection(leaf.dcid)  
    3358                       elif len(shape.GetFollowers()) == 1:  
    3359                           self.AddToSelection(role.dcid)  
    3360                           self.AddToSelection(fact.dcid)  
      3345 ##                    elif len(shape.GetFollowers('ORMRole')) == 1:  
      3346 ##                        self.AddToSelection(role.dcid)  
      3347 ##                        self.AddToSelection(fact.dcid)  
    3361 3348  
    3362 3349         self.AddToSelection(id)  # last to make sure it is target of keyboard  
     
    3369 3356         shape = self.dcid_to_shape_xref.get(id)  
    3370 3357         grid = []  
    3371           if shape.NodeAID:  # relation  
    3372               self.AddToSelection(shape.dcid)  
    3373               self.AddToSelection(shape.Get('NodeA').dcid)  
    3374               self.AddToSelection(shape.Get('NodeB').dcid)  
    3375           elif shape.Get('Target').Nary:  # fact type  
    3376               # fact -> roles -> objects (all of them?)  
    3377               print shape.GetFollowers()  
    3378               for role in shape.GetFollowers():  
    3379                   if role.NodeAID:  # relation (role)  
    3380                       if debug: print 'follower id %s' % role.NodeAID  
    3381                       leaf = role.Get('NodeA')  # should be the fact  
    3382                       if leaf.ID == shape.ID:  
    3383                           leaf = role.Get('NodeB')  
    3384                       if debug: print 'leaf followers %s' % leaf.GetFollowers()  
    3385                       # if len(leaf.GetFollowers()) == 1:  # should filter out notes -- TODO!  
    3386                       self.AddToSelection(role.dcid)  
    3387                       self.AddToSelection(leaf.dcid)  
    3388                   else:  # -- are they always relations?  
    3389                       pass  
    3390           elif shape.Get('Target').Name:  # object type -- better test?  
      3358         if shape.TableName == 'ORMRelation':  # relation  
      3359             pass  
      3360 ##            self.AddToSelection(shape.dcid)  
      3361 ##            self.AddToSelection(shape.Get('NodeA').dcid)  
      3362 ##            self.AddToSelection(shape.Get('NodeB').dcid)  
      3363         elif shape.TableName == 'ORMFactType':  # fact type  
      3364             pass  
      3365 ##            # fact -> roles -> objects (all of them?)  
      3366 ##            for role in shape.GetFollowers('ORMRole'):  
      3367 ##                leaf = role.Get('NodeB')  
      3368 ##                self.AddToSelection(role.dcid)  
      3369 ##                self.AddToSelection(leaf.dcid)  
      3370         elif shape.TableName == 'ORMObjectType':  
    3391 3371             # object type -> role -> fact -> out_role -> leaf_object  
    3392               for role in shape.GetFollowers():  
    3393                   if not role.NodeAID: continue  # relation (role)  
    3394                   if debug: print 'role id %s' % role.NodeAID  
      3372             for role in shape.GetFollowers('ORMRole'):  
    3395 3373                 fact = role.Get('NodeA')  # find the other end  
    3396                   if fact.ID == shape.ID:  
    3397                       fact = role.Get('NodeB')  
    3398                   if debug: print 'fact followers %s' % fact.GetFollowers()  
    3399                   out_roles = fact.GetFollowers()  
      3374                 out_roles = fact.GetFollowers('ORMRole')  
    3400 3375                 if len(out_roles) == 1:  # nary = 1  
    3401 3376                     if debug: print 'nary = 1'  
     
    3407 3382                     if out_role.ID == role.ID:  
    3408 3383                         out_role = out_roles[1]  
    3409                       leaf = out_role.Get('NodeA')  # should be the fact  
    3410                       if leaf.ID == fact.ID:  
    3411                           leaf = out_role.Get('NodeB')  
    3412                       if len(leaf.GetFollowers()) == 1:  # should filter out notes -- TODO!  
      3384                     leaf = out_role.Get('NodeB')  # should be the fact  
      3385                     if len(leaf.GetFollowers('ORMRole')) == 1:  # should filter out notes -- TODO!  
    3413 3386                         self.AddToSelection(role.dcid)  
    3414 3387                         self.AddToSelection(fact.dcid)  
     
    3416 3389                         self.AddToSelection(leaf.dcid)  
    3417 3390                         grid.append([role, fact, out_role, leaf])  
    3418                       elif len(shape.GetFollowers()) == 1:  
    3419                           self.AddToSelection(role.dcid)  
    3420                           self.AddToSelection(fact.dcid)  
    3421                           grid.append([role, fact])  
      3391 ##                    elif len(shape.GetFollowers()) == 1:  
      3392 ##                        self.AddToSelection(role.dcid)  
      3393 ##                        self.AddToSelection(fact.dcid)  
      3394 ##                        grid.append([role, fact])  
    3422 3395  
    3423 3396         self.AddToSelection(id)  # last to make sure it is target of keyboard  
     
    3459 3432                 node = branch[1]  
    3460 3433                 x += offsetX * direction  
    3461                   self.MoveID(node.dcid, x-node.PosX, y-node.PosY-4)  # -4 = half height  
      3434                 self.MoveID(node.dcid, x-node.PosX, y-node.PosY-5)  # -4 = half height  
    3461 3434                 self.CommitPositionID(node.dcid)  
    3462 3435                 if len(branch) == 4:  
     
    3920 3893         if self.keyboard_target_dcid:  
    3921 3894             shape = self.dcid_to_shape_xref.get(self.keyboard_target_dcid)  
    3922               if uk == 18:  
      3895             if uk == 18:  # ctrl-r  
    3922 3895                 x, y = shape.GetPos()  
    3923 3896                 yvals = []  
    3924 3897                 if shape.TableName == 'ORMFactType':  
      3898                     yvals = [xx.Get('NodeB').PosY for xx in shape.GetFollowers()  
      3899                              if xx.TableName == 'ORMRole' and xx.Get('NodeA').PosX > x]  
    3925 3900                     x += 40  
    3926                       yvals = [xx.Get('NodeB').GetPos()[1] for xx in shape.GetFollowers() if xx.TableName == 'ORMRole']  
      3901                     y += 5  
    3926 3901                 elif shape.TableName == 'ORMObjectType':  
    3927                       y -= 4  
    3928                       yvals = [xx.Get('NodeA').GetPos()[1] for xx in shape.GetFollowers() if xx.TableName == 'ORMRole']  
      3902                     yvals = [xx.Get('NodeA').PosY for xx in shape.GetFollowers()  
      3903                              if xx.TableName == 'ORMRole' and xx.Get('NodeA').PosX > x]  
      3904                     y -= 5  
    3929 3905                 if yvals:  
    3930 3906                     maxy = max(yvals)  
    3931                       y = maxy + 30  
      3907                     y = maxy + 35  
    3931 3907                 self.InferTarget(shape, x + 70, y)  
    3932 3908                 return