[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: VTP path questions




=>> I've some questions about VTP paths and selections.

=>> Having the root tree of a ctview, and having selected a subtree (with
=>> the mouse) in that same ctview:

=>> 1. How can I get the selected subtree?

Recall that a selection path may point to more that one subtree. The
function {path}:tree+ returns all subtrees selected by a <path>
(see page 9 of the Path manual).

   ({path}:tree+ <path>) -> <list_of_subtrees>

To recover the list of trees selected by the current selection
within a <ctedit>, use the following two-liner:

(de trees (ctedit)
    ({path}:tree+ 
      ({selection}:path
          (send 'find-selection ctedit '{current})
          )
      )
    )

Caution! This function returns a list of subtrees. You may only
want (car (trees ctedit)) for example.

=>>2. How can I get the path to that subtree with respect to the
=>>   root tree?

Given a <subtree>, you may calculate the path from the root of 
the same tree to the <subtree> with the function {tree}:path
(see page 11 of the Path manual).

   ({tree}:path <subtree>) -> <path>

=>>3. I would like to keep a permanent description of this path in order
=>>   to find again the subtree, even if it is no longer selected (e.g.,
=>>   after having stored and reloaded the root tree in an other
=>>   session)...


1) Let's start off with the question about saving a path in an external
file. No single function exists to do this, but it is possible.
First of all, a path maintains physical pointers to the tree to
which it refers (Notice, for example, that in the {path}:tree+ 
function above there was no need for a tree argument.) The first step
towards saving a path is therefore to remove these physical pointers:

(de {path}:remove-tree-pointers (path)
    ({path}:for-all-leaf 
       path
       (lambda (leaf type) ({leaf}:val leaf ()))
       )
    path
    )

N.B. This function applies to selection paths, not modification paths.

2) Now you may save and restore the path using the standard lelisp 
input/output facilities:

(de {path}:save	(path file)
    ({path}:remove-tree-pointers path)
    (let ((oc (openo file))
          (#:system:print-for-read t)
	  )
      (with ((outchan oc)) (print path)(terpri))
      (close oc)
      )
   )

(de {path}:restore (file)
    (let ((ic (openi file)))
      (prog1
        (with ((inchan ic)) (read))
        (close ic)
        )
      )
    )
     
3) Suppose now that you have a "bare" selection path (pointers 
removed) and a root that you would like it to follow. You may connect the 
two with the following function. (This function works even if the
path is connected to a different root; obviously it then disconnects
the path from the original root.)

(de {path}:set-tree-pointers (path root)
    ({path}:follow-all-leaf path root 0 
      (lambda (leaf-path type subtree)
              ({leaf}:val ({list-started}:started leaf-path) subtree)
              ;;Return the continuation point:
              ({list-started}:list leaf-path)
              )
      )
    path
   ) 	
  
N.B. If the <path> does not correspond to the shape of the <root>,
this function triggers an error. 

Concerning the incongruence between a path and a tree, recall
that part of the centaur "variable" structure's task is to maintain the
coherence between a root and a selection path. You should avoid 
trying to manage a path outside of a variable structure (a tree modification
may cause it to be modified, another tool may want to modify it, etc.).
If you have a path that you would like to attach as the 
current (or other) selection of a root that is within a ctedit 
(that contains a variable structure), use the following function:

(de {path}:store-as-current-in-ctedit (path ctedit)
    (lets ((variable ({ctedit}:subject ctedit))
           (root ({variable}:root variable))
           )
       ({path}:set-tree-pointers path root)
       ({variable}:add-selection variable '{current} path)
       )
    )

N.B. Once you have changed the current selection, you must
update its visual presentation in the ctedit by clicking on
either the [Display] menu [Redraw] button or the [Selections]
menu [Redraw] button.

Let me know if I have satisfactorily answered your questions
or if these functions are bugged.

Ian Jacobs