Changeset 434

Show
Ignore:
Timestamp:
Sat Jun 7 23:41:26 2008
Author:
Brian
Message:

Renamed orm objects to RoleSequence? and RolePosition?. Made sure that objectified fact type will load with object type graphic behind. Drafted deletion logic (still needs work).

Files:

Legend:

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

    r432 r434  
    1929 1929     def Char(self, char):  
    1930 1930         pass  
    1931           if debug: print "char", ord(char), "'", char, "'"  
      1931         # if debug: print "char", ord(char), "'", char, "'"  
    1931 1931          
    1932 1932     def SetSelected(self):  
     
    1945 1945         return self.NoneSelected() or self.GetSelected()  
    1946 1946  
      1947     def OnBottom(self):  # overridden by ORMObjectTypeShape  
      1948         pass  
      1949  
      1950     def Delete(self):  # overriden in subclasses  
      1951         self.canvas.pdc.RemoveId(self.dcid)  
      1952         self._SetInShell('dcid', None)  
      1953         Data.Object.Delete(self)  
      1954  
    1947 1955     # these are for the autolayout algorithm  
    1948 1956     def SetRelation(self, intensity):  # get the intensity of the relationship -- CHANGE NAME  
     
    2035 2043         if nodea:  # if objectified fact type  
    2036 2044             nodea.AddFollower(self)  
      2045  
      2046     def OnBottom(self):  
      2047         nodea = self.Get('NodeA')  
      2048         if nodea:  # if objectified fact type  
      2049             nodea.OnTop()  
    2037 2050          
    2038 2051     def CommitPos(self):  # if self moved while fact type was not selected  
     
    2185 2198                     orm_object.RefMode = char  
    2186 2199  
      2200     def Delete(self):  
      2201         if self.InDelete: return  
      2202         self._SetInShell('InDelete', True)  
      2203         for shape in self.GetGraphicList('ORMRoleConnectorShape', 'NodeB'):  
      2204             shape.Delete()  
      2205         for shape in self.GetGraphicList('ORMSubtypeConnectorShape', 'NodeA'):  
      2206             shape.Delete()  
      2207         for shape in self.GetGraphicList('ORMSubtypeConnectorShape', 'NodeB'):  
      2208             shape.Delete()  
      2209         if self.Target:  
      2210             self.Target.Delete()  
      2211         self._SetInShell('InDelete', None)  
      2212         ORMShape.Delete(self)  
      2213  
    2187 2214 role_box_height = 8 # 12  
    2188 2215 role_box_width = 12 # 12  
     
    2404 2431             return True  
    2405 2432  
    2406       def OnTop(self):  
    2407           print 'started ontop'  
      2433     def OnTop(self):  # must run after this object has a dcid  
      2434 ##        print 'started ontop'  
    2408 2435         followers = self.GetFollowers()  
    2409 2436         object_type_shape = None  
     
    2413 2440                 break  
    2414 2441         if object_type_shape:  
    2415               print 'found objectified'  
      2442 ##            print 'found objectified'  
    2415 2442             if self.dcid < object_type_shape.dcid:  
    2416 2443                 print 'reseting fact dcid'  
     
    2420 2447                 self.canvas.SetGraphic(dc, self, newid=True)  # create new one  
    2421 2448             for f in followers:  
    2422                   print 'looking at', f  
    2423                   if debug:  
    2424                       print "object dcid, other dcid", f.dcid, object_type_shape.dcid  
      2449 ##                print 'looking at', f  
      2450 ##                if debug:  
      2451 ##                    print "object dcid, other dcid", f.dcid, object_type_shape.dcid  
    2425 2452                 if f.dcid < object_type_shape.dcid:  # if behind object type shape  
    2426 2453                     dc.RemoveId(f.dcid)  # clear the old id  
    2427 2454                     self.canvas.SetGraphic(dc, f, newid=True)  # create new one  
    2428 2455  
      2456     def ResequenceRoles(self):  
      2457         roles = self.GetList('ORMRole').sorted()  # renumber remaining roles  
      2458         for i , r in enumerate(roles):  
      2459             role.Seq = i + 1  
      2460  
      2461     def Delete(self):  
      2462         if self.InDelete: return  
      2463         self._SetInShell('InDelete', True)  
      2464         for shape in self.GetGraphicList('ORMRoleConnectorShape', 'NodeA'):  
      2465             shape.Delete()  
      2466         for shape in self.GetGraphicList('ORMFactReadingShape', 'NodeA'):  
      2467             shape.Delete()  
      2468         if shape.NodeA:  
      2469             shape.NodeA.Delete()  # Objectified fact type  
      2470         if self.Target:  
      2471             for obj in self.Target.GetList('ORMFactReading'):  
      2472                 obj.Delete()  
      2473             self.Target.Delete()  
      2474         self._SetInShell('InDelete', None)  
      2475         ORMShape.Delete(self)  
      2476  
    2429 2477 class ORMFactReadingShape(ORMFollowText):  
    2430 2478     def Draw(self, dc):  
     
    2630 2678                 orm_object.Text = char  
    2631 2679  
      2680     def Delete(self):  
      2681         if self.InDelete: return  
      2682         self._SetInShell('InDelete', True)  
      2683         for shape in self.GetGraphicList('ORMNoteConnectorShape', 'NodeA'):  
      2684             shape.Delete()  
      2685         if self.Target:  
      2686             self.Target.Delete()  
      2687         self._SetInShell('InDelete', None)  
      2688         ORMShape.Delete(self)  
      2689  
    2632 2690 class ORMConstraintShape(ORMCircle):  
    2633 2691     ''' external constraint?'''  
     
    2713 2771 ##            h += line_h  
    2714 2772  
      2773     def Delete(self):  
      2774         if self.InDelete: return  
      2775         self._SetInShell('InDelete', True)  
      2776         for shape in self.GetGraphicList('ORMConstraintConnectorShape', 'NodeB'):  
      2777             shape.Delete()  
      2778         if self.Target:  
      2779             for obj in self.Target.GetList('ORMRoleSequence'):  
      2780                 for pos in obj.GetList('ORMRolePosition'):  
      2781                     pos.Delete()  
      2782                 obj.Delete()  
      2783             self.Target.Delete()  
      2784         self._SetInShell('InDelete', None)  
      2785         ORMShape.Delete(self)  
      2786  
    2715 2787 class ORMSubtypeConstraintShape(ORMCircle):  
    2716 2788     ''' '''  
     
    2768 2840 ##            h += line_h  
    2769 2841  
      2842     def Delete(self):  
      2843         if self.InDelete: return  
      2844         self._SetInShell('InDelete', True)  
      2845         for shape in self.GetGraphicList('ORMSubtypeConstraintConnectorShape', 'NodeA'):  
      2846             shape.Delete()  
      2847         if self.Target:  
      2848             for obj in self.Target.GetList('ORMSubtypeConstraintConnector', 'NodeA'):  
      2849                 obj.Delete()  
      2850             self.Target.Delete()  
      2851         self._SetInShell('InDelete', None)  
      2852         ORMShape.Delete(self)  
      2853  
    2770 2854 class ORMRoleConnectorShape(ORMConnector):  
    2771 2855     def Draw(self, dc):  
     
    2835 2919                 orm_object.Name = char  
    2836 2920  
      2921     def Delete(self):  
      2922         if self.InDelete: return  # prevent loops  
      2923         self._SetInShell('InDelete', True)  
      2924         if self.Target:  
      2925             fact = self.Target.ORMFactType  
      2926             self.Target.Delete()  
      2927             fact.ResequenceRoles()  
      2928         self._SetInShell('InDelete', None)  
      2929         ORMShape.Delete(self)  
      2930  
    2837 2931 class ORMSubtypeConnectorShape(ORMConnector):  
    2838 2932     def Draw(self, dc):  
     
    2928 3022  
    2929 3023         constraintlist = self.Get('Target')  
    2930           cr_list = constraintlist.GetList('ORMConstraintRole')  
      3024         cr_list = constraintlist.GetList('ORMRolePosition')  
    2930 3024         # remove constraint roles that aren't for this fact  
    2931 3025         fact_roles = [cr.ORMRole for cr in cr_list if cr.ORMRole.ORMFactTypeID == nodea.Target.ID]  
     
    3077 3171         font = self.GetFont()  
    3078 3172         if Data.platform == "mac":  
      3173             font.SetPointSize(7)  
    3079 3174             font.SetFaceName('Geneva')  
    3080 3175         else:  
    3081               font.SetPointSize(7)   
      3176             font.SetPointSize(7)  
    3081 3176             font.SetFaceName('Tahoma')  
    3082 3177         # font.SetFamily(wx.wxSWISS)  
     
    3264 3359             menu.Append(self.popsID20, "Add Role Sequence")  
    3265 3360             menu.AppendSeparator()  
    3266           count = len(constraint.GetList('ORMConstraintList'))  
    3267           if count > 0:  
    3268               for x in range(count):  
    3269                   menu.Append(self.popsID41, "Delete Role List %d" % (x + 1))  
    3270                   # we should use EVT_MENU_RANGE (like the Script menu)  
    3271               menu.AppendSeparator()  
    3272 3361         menu.AppendRadioItem(self.popsID21, "Set as Unique")  
    3273 3362         menu.Check(self.popsID21, (constraint.Operator == 'Unique'))  
     
    3291 3380         menu.AppendCheckItem(self.ID_SetAsDeontic, "Set as Deontic")  
    3292 3381         menu.Check(self.ID_SetAsDeontic, bool(constraint.Deontic))  
      3382         count = len(constraint.GetList('ORMRoleSequence'))  
      3383         if count > 0:  
      3384             menu.AppendSeparator()  
      3385             for x in range(count):  
      3386                 menu.Append(self.popsID41, "Delete Role List %d" % (x + 1))  
      3387                 # we should use EVT_MENU_RANGE (like the Script menu)  
    3293 3388  
    3294 3389     def SubtypeConstraintMenu(self, constraint, menu):  
     
    3654 3749         target = shape.Get('Target')  
    3655 3750         # create new constraint list  
    3656           priorlists = target.GetList('ORMConstraintList')  
    3657           clist = shape.db.GetObject('ORMConstraintList')  # new constraint object  
      3751         priorlists = target.GetList('ORMRoleSequence')  
      3752         clist = shape.db.GetObject('ORMRoleSequence')  # new constraint object  
    3658 3753         clist.ORMConstraintID = target.ID  
    3659 3754         clist.Seq = len(priorlists)+1  # next number  
    3660 3755         fact_type_ids = {}  
    3661 3756         for i, role in enumerate(self.rolelist):  
    3662               crole = shape.db.GetObject('ORMConstraintRole')  
    3663               crole.ORMConstraintListID = clist.ID  
      3757             crole = shape.db.GetObject('ORMRolePosition')  
      3758             crole.ORMRoleSequenceID = clist.ID  
    3664 3759             crole.ORMRoleID = role.ID  
    3665 3760             crole.Seq = i + 1  
     
    3723 3818         self.SetRoleConstraint(event, s, 'Undo ' + s)  
    3724 3819  
    3725       def OnPops41(self, event):  
    3726           pass  
      3820     def DeleteRoleSequence(self, event, delete_seq):  
      3821         l = self.pdc.FindObjects(self.popupx, self.popupy, hitradius)  
      3822         if l:  
      3823             shape = self.dcid_to_shape_xref.get(l[0])  
      3824             # get all the connectors that point to the specified role sequence  
      3825             connectors = [x for x in shape.GetGraphicList('ORMConstraintConnectorShape', 'NodeB')  
      3826                           if x.Target and x.Target.Seq == delete_seq]  
      3827             if connectors:  # any of them will do  
      3828                 if debug: print 'connector found'  
      3829                 role_seq = connectors[0].Target  # ORMRoleSequence  
      3830                 for role_pos in role_seq.GetList('ORMRolePosition'):  
      3831                     role_pos.Delete()  
      3832                 role_seq.Delete()  # delete role sequence 1  
      3833             for c_shape in connectors:  
      3834                 c_shape.Delete()  
      3835             Data.SetUndo('Delete Role Sequence %s' % delete_seq)  
      3836 ##            self.RedrawID(shape.dcid)  
      3837  
      3838     def OnPops41(self, event):  # delete role sequence 1  
      3839         if debug: print 'starting delete 1'  
      3840         self.DeleteRoleSequence(event, 1)  
    3727 3841     def OnPops42(self, event):  
    3728           pass  
      3842         self.DeleteRoleSequence(event, 2)  
    3728 3842     def OnPops43(self, event):  
    3729           pass  
      3843         self.DeleteRoleSequence(event, 3)  
    3729 3843     def OnPops44(self, event):  
    3730           pass  
      3844         self.DeleteRoleSequence(event, 4)  
    3730 3844  
    3731 3845     def SubtypeConstraintOperator(self, event, new_value, undo_msg):  
     
    4813 4927                 self.CreateNode(dc, shape)  
    4814 4928             self.SetGraphic(dc, shape)  # draw shape on this canvas  
      4929             shape.OnBottom()  # put objectification behind facttype  
    4815 4930         dc.EndDrawing()  
    4816 4931  
  • ganttpv/trunk/Data.py

    r420 r434  
    665 665             return None  
    666 666  
      667     def Delete(self):  
      668         try:  
      669             rec = self.db.Database[self.Table].get(self.ID)  
      670             if rec:  
      671                 rec.zzStatus = 'deleted'  
      672         except:  
      673             pass  
      674  
    667 675     def Get(self, name=None):  
    668 676         '''  
     
    703 711         return [ self.db.GetObject(table_name, x['ID']) for x in result.itervalues() if x.get('zzStatus') != 'deleted']  
    704 712  
      713     def GetGraphicList(self, subtype_name, attribute=None):  
      714         '''  
      715 returns a list of "table_name type" objects that point to this one  
      716 list_of_assignment_objects = ThisTask.Find('Assignment', 'Prerequisite')  
      717 Returns a list of all assignment objects that point to the original task object  
      718         '''  
      719         if attribute:  
      720             fk = attribute  
      721         else:  
      722             fk = 'GraphicObject'  
      723         table_rows = self.db.Database.get('GraphicObject') or {}  
      724         search = { fk + 'ID': self.ID, 'Subtype': subtype_name }  
      725         result = SearchByColumn(table_rows, search)  # only works w/ current db -- IMPORTANT  
      726         # if debug: print result  
      727         return [ self.db.GetObject(table_name, x['ID']) for x in result.itervalues() if x.get('zzStatus') != 'deleted']  
      728  
    705 729 class DB:  
    706 730     def __init__(self, database):