(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP")
(FILECREATED "12-Apr-88 17:27:24" {QV}<NOTECARDS>1.3LNEXT>PMIPATCH094.;18 24401  

      changes to%:  (FNS NC.GraphAddNode NCP.LocalGlobalLink NC.InsertLinkInGraph NC.GraphAddLabel 
                         NC.InsertEdgeInGraph)
                    (VARS PMIPATCH094COMS)

      previous date%: " 5-Apr-88 18:30:45" {QV}<NOTECARDS>1.3LNEXT>PMIPATCH094.;11)


(* "
Copyright (c) 1988 by Xerox Corporation.  All rights reserved.
")

(PRETTYCOMPRINT PMIPATCH094COMS)

(RPAQQ PMIPATCH094COMS [

(* ;;; "pmi 4/12/88: Changes to make NCToulminCard possible.  The main changes are to allow link icons and labels to be placed in graph cards programmatically.")

                        (DECLARE%: DONTCOPY (PROPS (PMIPATCH094 MAKEFILE-ENVIRONMENT)
                                                   (PMIPATCH094 FILETYPE)))
                        [DECLARE%: DONTEVAL@LOAD FIRST (P (NC.LoadFileFromDirectories 'NCGRAPHCARD]
                        
          
          (* ;; "Changed in NCPROGINT")

                        (FNS NCP.LocalGlobalLink NCP.SelectCards)
                        
          
          (* ;; "Changed in NCGRAPHCARD")

                        (FNS NC.InsertLinkInGraph NC.MakeGraphCard)
                        
          
          (* ;; "New for NCGRAPHCARD")

                        (FNS NC.GraphAddNode NC.GraphAddLabel NC.InsertEdgeInGraph 
                             NC.InsertLabelInGraph)
                        (DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA
                                                                                                )
                                                                                             (NLAML)
                                                                                             (LAMA])



(* ;;; 
"pmi 4/12/88: Changes to make NCToulminCard possible.  The main changes are to allow link icons and labels to be placed in graph cards programmatically."
)

(DECLARE%: DONTCOPY 

(PUTPROPS PMIPATCH094 MAKEFILE-ENVIRONMENT (:PACKAGE "INTERLISP" :READTABLE "INTERLISP"))

(PUTPROPS PMIPATCH094 FILETYPE :BCOMPL)
)
(DECLARE%: DONTEVAL@LOAD FIRST 
(NC.LoadFileFromDirectories 'NCGRAPHCARD)
)



(* ;; "Changed in NCPROGINT")

(DEFINEQ

(NCP.LocalGlobalLink
  [LAMBDA (LinkType SourceCard DestinationCard FromLoc DisplayMode)
                                                             (* ; "Edited  8-Apr-88 15:36 by pmi")
          
          (* ;; 
          "Create a link from within the text of the SourceCard card to the DestinationCard card.")
          
          (* ;; "rht 4/1/85: Changed to handle old-style link display modes.")
          
          (* ;; "rht 11/17/85: Updated to handle new card and notefile objects.")
          
          (* ;; "rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.")
          
          (* ;; "rht 11/16/86: Changed call to NCP.ReportError")
          
          (* ;; "rht 5/27/87: Changed call to NCP.CoerceToLinkDisplayMode slightly.")
          
          (* ;; "pmi 4/8/88: Now checks if the SourceCard is graph-based, and if so, calls NC.InsertLinkInGraph, which now takes a position argument (FromLoc).")

    (DECLARE (GLOBALVARS NC.SubBoxLinkLabel NC.FiledCardLinkLabel))
    (PROG ((CoercedDisplayMode (NCP.CoerceToLinkDisplayMode (OR DisplayMode SourceCard)))
           WasActive NoteFile)
          (if (NULL CoercedDisplayMode)
              then (NCP.ReportError 'NCP.LocalGlobalLink (CONCAT DisplayMode 
                                                                " is invalid link display mode."
                                                                (CHARACTER 13)
                                                                "No link created."))
                   (RETURN NIL))
          (if (NCP.GraphBasedP SourceCard)
              then (if [NOT (FMEMB LinkType (NCP.LinkTypes (SETQ NoteFile (fetch (Card NoteFile)
                                                                             of SourceCard]
                       then (if (NC.AskYesOrNo (CONCAT "That link type hasn't been used in NoteFile "
                                                      (fetch (NoteFile FullFileName) of NoteFile)
                                                      (CHARACTER 13)
                                                      "Want to create a new link type: " LinkType 
                                                      "? ")
                                       "--" NIL T (NC.AttachPromptWindow (WFROMMENU
                                                                          (fetch (NoteFile Menu)
                                                                             of NoteFile)))
                                       NIL NIL)
                                then (NCP.CreateLinkType LinkType NoteFile)
                              else (RETURN NIL)))
                   (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
                       (NCP.CacheCards SourceCard))
                   [RETURN (PROG1 (NC.InsertLinkInGraph SourceCard LinkType DestinationCard 
                                         CoercedDisplayMode FromLoc)
                                  (OR WasActive (NCP.UncacheCards SourceCard T]
            elseif (NCP.TextBasedP SourceCard)
              then (if (EQ LinkType NC.FiledCardLinkLabel)
                       then (if (AND (NOT (NCP.FileBoxP DestinationCard))
                                     (NCP.FileBoxP SourceCard))
                                then (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
                                         (NCP.CacheCards SourceCard))
                                     (NCP.ChangeLoc SourceCard FromLoc)
                                     (NCP.FileCards DestinationCard SourceCard)
                                     [RETURN (PROG1 (CAR (NCP.GetLinks SourceCard DestinationCard 
                                                                NC.FiledCardLinkLabel))
                                                    (OR WasActive (NCP.UncacheCards SourceCard T]
                              else (NCP.ReportError 'NCP.LocalGlobalLink (CONCAT 
                                                       "FiledCard link must be from a box to a card."
                                                                                (CHARACTER 13)
                                                                                "No link created."))
                                   (RETURN NIL)))
                   (if (EQ LinkType NC.SubBoxLinkLabel)
                       then (if (AND (NCP.FileBoxP DestinationCard)
                                     (NCP.FileBoxP SourceCard))
                                then (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
                                         (NCP.CacheCards SourceCard))
                                     (NCP.ChangeLoc SourceCard FromLoc)
                                     (NCP.FileCards DestinationCard SourceCard)
                                     [RETURN (PROG1 (CAR (NCP.GetLinks SourceCard DestinationCard 
                                                                NC.SubBoxLinkLabel))
                                                    (OR WasActive (NCP.UncacheCards SourceCard T]
                              else (NCP.ReportError 'NCP.LocalGlobalLink (CONCAT 
                                                           "SubBox link must be from a box to a box."
                                                                                (CHARACTER 13)
                                                                                "No link created."))
                                   (RETURN NIL)))            (* ; 
                                                    "Inserting non-hierarchical link into a filebox.")

                   (if (NCP.FileBoxP SourceCard)
                       then (NCP.ReportError 'NCP.LocalGlobalLink (CONCAT 
                                     "Local links from fileboxes must be either SubBox or FiledCard."
                                                                         (CHARACTER 13)
                                                                         "No link created."))
                            (RETURN NIL))
                   (if [NOT (FMEMB LinkType (NCP.LinkTypes (SETQ NoteFile (fetch (Card NoteFile)
                                                                             of SourceCard]
                       then (if (NC.AskYesOrNo (CONCAT "That link type hasn't been used in NoteFile "
                                                      (fetch (NoteFile FullFileName) of NoteFile)
                                                      (CHARACTER 13)
                                                      "Want to create a new link type: " LinkType 
                                                      "? ")
                                       "--" NIL T (NC.AttachPromptWindow (WFROMMENU
                                                                          (fetch (NoteFile Menu)
                                                                             of NoteFile)))
                                       NIL NIL)
                                then (NCP.CreateLinkType LinkType NoteFile)
                              else (RETURN NIL)))
                   (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
                       (NCP.CacheCards SourceCard))
                   (AND FromLoc (NCP.ChangeLoc SourceCard FromLoc))
                   (RETURN (PROG1 (NC.InsertLinkInText (NC.FetchSubstance SourceCard)
                                         LinkType DestinationCard SourceCard CoercedDisplayMode)
                                  (OR WasActive (NCP.UncacheCards SourceCard T])

(NCP.SelectCards
  [LAMBDA (InstigatingCardOrWindow SingleCardFlg SelectionPredicate Msg CheckForCancelFlg NewCardFlg)
                                                             (* ; "Edited 31-Mar-88 15:18 by pmi")
          
          (* ;; "Return a list of cards selected.  A menu pops up near the prompt window with 'DONE' and 'CANCEL' buttons.  User selects by clicking in card's title bar.")
          
          (* ;; "rht 11/18/85: Updated to handle new notefile and card object formats.  Now takes optional extra args and passes to NC.SelectNoteCards.")
          
          (* ;; 
          "pmi 12/12/86: Removed obsolete ReturnLinksFlg argument in call to NC.SelectNoteCards.")
          
          (* ;; "rht 3/2/87: Fix to bug #342: Now makes sure instigating card is displayed, else passes NIL to NC.SelectNoteCards.")
          
          (* ;; "rg 4/2/87 added NCP.WithLockedCards wrapper")
          
          (* ;; "pmi 2/26/88: Undid Randy't change of 12/12/86.  Now lets NC.CoerceToInterestedWindow (called from NC.SelectNoteCards) check that the instigating card is displayed.")
          
          (* ;; "pmi 3/31/88: Added NewCardFlg arg.  A non-NIL NewCardFlg signals that the menu with the NewCard option should be passed down to NC.SelectCards.")

    (NCP.WithLockedCards (NC.SelectNoteCards SingleCardFlg SelectionPredicate
                                (if SingleCardFlg
                                    then (if NewCardFlg
                                             then NC.SelectingSingleCardMenu
                                           else NC.SelectingCardMenu)
                                  else NC.SelectingCardsMenu)
                                InstigatingCardOrWindow Msg CheckForCancelFlg])
)



(* ;; "Changed in NCGRAPHCARD")

(DEFINEQ

(NC.InsertLinkInGraph
  [LAMBDA (GraphCard LinkOrLinkLabel DestinationCard DisplayMode Position)
                                                             (* ; "Edited  8-Apr-88 14:47 by pmi")
          
          (* ;; "Insert a Link to DestinationCard in GraphCard at Position")
          
          (* ;; "pmi 4/8/88: Called from NCP.LocalGlobalLink to add a graph node to an existing card at a specified position.  Just sets up the proper ADDNODEFN in graph record, attaches arguments to the graph window, and invokes the grapher editor.")

    (LET ((Window (NCP.CardWindow GraphCard)))
         (WINDOWPROP Window 'NewNodeData (LIST 'SourceCard GraphCard 'LinkOrLinkLabel LinkOrLinkLabel
                                               'DestinationCard DestinationCard 'DisplayMode 
                                               DisplayMode 'Position Position))
         (replace (GRAPH GRAPH.ADDNODEFN) of (WINDOWPROP Window 'GRAPH) with (FUNCTION 
                                                                              NC.GraphAddNode))
         (EDITADDNODE Window Position])

(NC.MakeGraphCard
  [LAMBDA (Card Title NoDisplayFlg)                          (* ; "Edited  5-Apr-88 10:46 by pmi")
          
          (* ;; "Creates a StructEdit card.  Alot like a graph card except that it allows editing of underlying NC structure, and doesn't allow an 'insertlink' operation in title bar menu.")
          
          (* ;; "fgh 11/14/85 Updated to handle Card object.")
          
          (* ;; "rht 5/5/86: Replaced call to NC.SetupTitleBarMenu with Install calls.")
          
          (* ;; "fgh 6/30/86 Added NC.GRAPHERCOPYBUTTONEVENTFN to SHOWGRAPH call")
          
          (* ;; "rht 9/19/86: Mod to above fix.  Now calls NC.MakeNewCardWindow a new fn that creates window and hangs Card off windowprop.")
          
          (* ;; "pmi 6/23/87: Added the GRAPH.CHANGELABELFN NC.GraphChangeLabelFn to the Graph being created, which will then mark the substance dirty when a label is changed.")
          
          (* ;; "pmi 4/5/88: Now passes a NIL TOPJUSTIFYFLG to SHOWGRAPH.  This puts the origin at the lower left, the same as in browsers.")

    (LET (Window Graph CardType)
         (SETQ Graph (create GRAPH
                            GRAPH.ADDNODEFN ← (FUNCTION NC.GraphAddNodeFn)
                            GRAPH.DELETENODEFN ← (FUNCTION NC.GraphDeleteNodeFn)
                            GRAPH.ADDLINKFN ← (FUNCTION NC.GraphAddLinkFn)
                            GRAPH.DELETELINKFN ← (FUNCTION NC.GraphDeleteLinkFn)
                            GRAPH.MOVENODEFN ← (FUNCTION NC.GraphMoveNodeFn)
                            GRAPH.FONTCHANGEFN ← (FUNCTION NC.GraphFontChangeFn)
                            GRAPH.CHANGELABELFN ← (FUNCTION NC.GraphChangeLabelFn)))
         (NC.SetSubstance Card Graph)
         (COND
            ((NOT NoDisplayFlg)
             (SETQ Window (NC.MakeNewCardWindow Card (OR Title "Untitled")))
             (SETQ CardType (NC.RetrieveType Card))
             (SHOWGRAPH Graph Window (FUNCTION NC.GraphCardLeftButtonFn)
                    (FUNCTION NC.GraphCardMiddleButtonFn)
                    NIL T (FUNCTION NC.GRAPHERCOPYBUTTONEVENTFN))
             (WINDOWADDPROP Window 'SHRINKFN (FUNCTION NC.GraphCardShrinkFn))
             (NC.InstallTitleBarButtonEventFn Window (FUNCTION NC.TitleBarButtonEventFn))
             (NC.InstallTitleBarLeftMenu Window CardType)
             (NC.InstallTitleBarMiddleMenu Window CardType)))
         (OR Window Card])
)



(* ;; "New for NCGRAPHCARD")

(DEFINEQ

(NC.GraphAddNode
  [LAMBDA (Graph GraphWindow)                                (* ; "Edited 12-Apr-88 17:26 by pmi")
          
          (* ;; "pmi 4/12/88: Called from Grapher to create a new node for Graph.  This is the addnodefn used by NC.InsertLinkInGraph.")

    (DECLARE (GLOBALVARS NC.MsgDelay))
    (NC.ProtectedCardOperation (NC.CoerceToCard GraphWindow)
           "Add Node" GraphWindow
           (NCP.WithLockedCards (PROG (NewNodeData SourceCard LinkOrLinkLabel DestinationCard 
                                             DisplayMode Position GraphNodeID Card Node)
          
          (* ;; "Get information to add a node from the graph's window.")

                                      (SETQ NewNodeData (WINDOWPROP Window 'NewNodeData))
                                      (SETQ SourceCard (LISTGET NewNodeData 'SourceCard))
                                      (SETQ LinkOrLinkLabel (LISTGET NewNodeData 'LinkOrLinkLabel))
                                      (SETQ DestinationCard (LISTGET NewNodeData 'DestinationCard))
                                      (SETQ DisplayMode (LISTGET NewNodeData 'DisplayMode))
                                      (SETQ Position (LISTGET NewNodeData 'Position))
                                      (if [SETQ Link (COND
                                                        ((type? Link LinkOrLinkLabel)
                                                         LinkOrLinkLabel)
                                                        (T (NC.MakeLink GraphWindow LinkOrLinkLabel 
                                                                  DestinationCard SourceCard 
                                                                  DisplayMode]
                                          then 
          
          (* ;; "Check to see if the node has already been added to the graph.")
                                                             (* ; 
                                                             "Create hash array if haven't already.")

                                               (NC.GetBrowserHashArray SourceCard Graph)
                                               [SETQ GraphNodeID (NC.GetBrowserNodeID
                                                                  SourceCard
                                                                  (SETQ Card (fetch (Link 
                                                                                      DestinationCard
                                                                                          )
                                                                                of Link]
                                               (COND
                                                  ((for GraphNode in (fetch (GRAPH GRAPHNODES)
                                                                        of Graph)
                                                      thereis (EQ GraphNodeID (NC.CoerceToGraphNodeID
                                                                               GraphNode)))
                                                   (NC.PrintMsg Window T "Node for card '"
                                                          (NC.RetrieveTitle Card)
                                                          "' already in graph.")
                                                   (DISMISS NC.MsgDelay)
                                                   (NCP.DeleteLinks Link)
                                                   (RETURN NIL)))
                                               (NC.MarkCardDirty SourceCard)
                                               (SETQ Node
                                                (NODECREATE GraphNodeID (NC.MakeLinkIcon Link)
                                                       (create POSITION
                                                              XCOORD ← -500
                                                              YCOORD ← -500)))
                                               (RETURN Node])

(NC.GraphAddLabel
  [LAMBDA (Graph GraphWindow)                                (* ; "Edited  8-Apr-88 15:12 by pmi")
          
          (* ;; 
        "This builds a label node in the default grapher style except that we force non-boxed nodes.")
          
          (* ;; "pmi 6/23/87: Added call to NC.MarkCardDirty to make sure substance is marked dirty when nodes are created.")
          
          (* ;; "pmi 4/8/88: Now called from Grapher to create a new label node for Graph.  This is the addnodefn used by NC.InsertLabelInGraph.")

    (LET ((GraphCard (NCP.CardFromWindow GraphWindow)))
         (NC.ProtectedCardOperation GraphCard "Add Label" GraphWindow
                (NCP.WithLockedCards (LET (NewLabelData Label Position Font Border LabelShade 
                                                 GraphNodes NodeName)
                                          (SETQ NewLabelData (WINDOWPROP GraphWindow 'NewLabelData))
                                          (SETQ Label (LISTGET NewLabelData 'Label))
                                          (SETQ Position (LISTGET NewLabelData 'Position))
                                          (SETQ Font (LISTGET NewLabelData 'Font))
                                          (SETQ Border (LISTGET NewLabelData 'Border))
                                          (SETQ LabelShade (LISTGET NewLabelData 'LabelShade))
                                          (NC.MarkCardDirty (NC.CoerceToCard GraphWindow))
                                          (SETQ GraphNodes (fetch (GRAPH GRAPHNODES) of Graph))
                                          (while (FASSOC (SETQ NodeName (PACK* Label (GENSYM)))
                                                        GraphNodes))
                                          (NODECREATE NodeName Label
                                                 (create POSITION
                                                        XCOORD ← -500
                                                        YCOORD ← -500)
                                                 NIL NIL (OR Font (CHOOSE.GRAPH.FONT Graph))
                                                 Border LabelShade])

(NC.InsertEdgeInGraph
  [LAMBDA (GraphCard FromNode ToNode)                        (* ; "Edited  8-Apr-88 15:25 by pmi")
          
          (* ;; "Adds a new edge to GraphCard, using FromNode as the source and ToNode as the destination.  Will only allow edge addition if there are currently no edges between the two nodes.")

    (LET* [(Window (NCP.CardWindow GraphCard))
           (Graph (WINDOWPROP Window 'GRAPH]
          (NC.GetBrowserHashArray GraphCard Graph)
          (COND
             ((EQ FromNode ToNode)
              (NC.PrintMsg NIL T "Can't add edge from a node to itself.")
              (FLASHW PROMPTWINDOW))
             ((OR (MEMBTONODES (fetch (GRAPHNODE NODEID) of ToNode)
                         (fetch (GRAPHNODE TONODES) of FromNode))
                  (MEMBTONODES (fetch (GRAPHNODE NODEID) of FromNode)
                         (fetch (GRAPHNODE TONODES) of ToNode)))
              (NC.PrintMsg NIL T "There is already an edge between those two nodes.")
              (FLASHW PROMPTWINDOW))
             (T (NC.MarkCardDirty GraphCard)
                (ADD/AND/DISPLAY/LINK FromNode ToNode Window Graph)))
          NIL])

(NC.InsertLabelInGraph
  [LAMBDA (GraphCard Label Position Font Border LabelShade)  (* ; "Edited  5-Apr-88 17:55 by pmi")
          
          (* ;; "Insert a Label in GraphWindow at Position")
          
          (* ;; "Called from NCP.LocalGlobalLink to add a graph label to an existing card at a specified position.  Just sets up the proper ADDNODEFN in graph record, attaches arguments to the graph window, and invokes the grapher editor.")

    (LET ((Window (NCP.CardWindow GraphCard)))
         (WINDOWPROP Window 'NewLabelData (LIST 'Label Label 'Position Position 'Font Font
                                                'Border Border 'LabelShade LabelShade))
         (replace (GRAPH GRAPH.ADDNODEFN) of (WINDOWPROP Window 'GRAPH) with (FUNCTION 
                                                                              NC.GraphAddLabel))
         (EDITADDNODE Window Position])
)
(DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA )
)
(PUTPROPS PMIPATCH094 COPYRIGHT ("Xerox Corporation" 1988))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (2359 11986 (NCP.LocalGlobalLink 2369 . 10162) (NCP.SelectCards 10164 . 11984)) (12027 
15642 (NC.InsertLinkInGraph 12037 . 13163) (NC.MakeGraphCard 13165 . 15640)) (15680 24185 (
NC.GraphAddNode 15690 . 19835) (NC.GraphAddLabel 19837 . 22047) (NC.InsertEdgeInGraph 22049 . 23252) (
NC.InsertLabelInGraph 23254 . 24183)))))
STOP