Source PostScript (tree.pps)

Retour Texte non formaté
/treedefaultdir {down} def /treesep 1 def /levelsep 2 def /treeedge {() ncline} def /treenodesep 0 def /treenodesepjps {treenodesep dup ptojpoint pop} def /equilibrageautomatique false def /autotreesepOn { /equilibrageautomatique true def } def /autotreesepOff { /equilibrageautomatique false def } def /withpar { dup withdir { dup length 2 ge { 2 get xcheck } { false } ifelse } { 0 get xcheck } ifelse } def /withdir { 0 get isnum } def /get_tree_dir { dup 0 get exch 1 get } def %% syntaxe : tree x y put_tree_dir /put_tree_dir { 2 dict begin /A defpoint /arbre exch def arbre 0 A pop put arbre 1 A exch pop put end } def /get_tree_param { 1 dict begin /table exch def table withdir { table 2 get } { table 0 get xcheck { table 0 get } { {} } ifelse } ifelse end } def /put_tree_param { 2 exch put } def %% syntaxe : ssarbre compte_noeuds_sousarbre --> n /compte_noeuds_sousarbre { 3 dict begin /ssarbre exch def /i 0 def /n 0 def ssarbre length { ssarbre i get istreenode { /n n 1 add store } if /i i 1 add store } repeat n end } def %% syntaxe : ssarbre treecdr -> le sous arbre ampute de son premier noeud /treecdr { 3 dict begin /ssarbre exch def /n ssarbre length def ssarbre withdir { ssarbre withpar { %% dir + param } { %% dir, no param } ifelse } { ssarbre withpar { %% no dir, param } { %% no dir, no param } ifelse } ifelse end } def %% 03/02/05 %% %% syntaxe : noeud array ltree %% 03/02/05 %% /tree { %% 03/02/05 %% 3 dict begin %% 03/02/05 %% %% on recupere les donnees %% 03/02/05 %% /table exch def %% 03/02/05 %% /noeud_pere exch def %% 03/02/05 %% %% 03/02/05 %% %% on verifie que le pere a un nom %% 03/02/05 %% /nomA noeud_pere get_name_noeud def %% 03/02/05 %% nomA length 0 eq { %% 03/02/05 %% %% ds le cas contraire on lui en donne 1 %% 03/02/05 %% /nomA (A) store %% 03/02/05 %% noeud_pere nomA put_name_noeud %% 03/02/05 %% } if %% 03/02/05 %% %% affichage du noeud pere %% 03/02/05 %% noeud_pere table noeud_pere %% 03/02/05 %% end %% 03/02/05 %% /treelevelno 0 def %% 03/02/05 %% declare_noeud %% 03/02/05 %% ltree %% 03/02/05 %% [treenodedict {} forall] {currentdict 3 1 roll put} spapply %% 03/02/05 %% } def %% 03/02/05 %% %% 03/02/05 %% %% syntaxe : noeud ssarbre ltree %% 03/02/05 %% /ltree { %% 03/02/05 %% 10 dict begin %% 03/02/05 %% gsave %% 03/02/05 %% %% on recupere les donnees %% 03/02/05 %% /table exch def %% 03/02/05 %% /noeud_pere exch def %% 03/02/05 %% %% on augmente le niveau de profondeur %% 03/02/05 %% /treelevelno treelevelno 1 add store %% 03/02/05 %% %% 03/02/05 %% %% on verifie que le pere a un nom %% 03/02/05 %% /nomA noeud_pere get_name_noeud def %% 03/02/05 %% nomA length 0 eq { %% 03/02/05 %% %% ds le cas contraire on lui en donne 1 %% 03/02/05 %% /nomA (A) store %% 03/02/05 %% noeud_pere nomA put_name_noeud %% 03/02/05 %% } if %% 03/02/05 %% %% 03/02/05 %% %% nb d'elts dans l'arbre %% 03/02/05 %% /n table compte_noeuds_sousarbre def %% 03/02/05 %% /i 0 def %% indice pour explorer le ssarbre %% 03/02/05 %% /nb_noeuds_affiches 0 def %% 03/02/05 %% %% y a-t-il un treehook pour ce niveau ? %% 03/02/05 %% /hookname (treehook) treelevelno 1 sub {(i) append} repeat cvlit def %% 03/02/05 %% hookname where { %% 03/02/05 %% hookname get exec %% 03/02/05 %% } if %% 03/02/05 %% %% les parametres specifies explicitement %% 03/02/05 %% table get_tree_param exec %% 03/02/05 %% %% calcul des vecteurs directions pour les noeuds fils %% 03/02/05 %% noeud_pere get_coordonnees_noeud %% 03/02/05 %% /y_pere exch def %% 03/02/05 %% /x_pere exch def %% 03/02/05 %% table withdir { %% 03/02/05 %% table get_tree_dir %% 03/02/05 %% 2 copy /treedefaultdir defpoint %% 03/02/05 %% } { %% 03/02/05 %% treedefaultdir %% 03/02/05 %% } ifelse %% 03/02/05 %% /u defpoint %% 03/02/05 %% u normal /v defpoint %% 03/02/05 %% %% 03/02/05 %% %% on explore le sous-arbre %% 03/02/05 %% table length { %% 03/02/05 %% table i get xcheck { %% 03/02/05 %% /suivant () def %% 03/02/05 %% } { %% 03/02/05 %% /suivant table i get def %% 03/02/05 %% } ifelse %% 03/02/05 %% %% 03/02/05 %% suivant isarray { %% 03/02/05 %% suivant istreenode { %% 03/02/05 %% %% c'est un nouveau noeud fils %% 03/02/05 %% %% calcul des coordonnees %% 03/02/05 %% x_pere y_pere %% 03/02/05 %% u %% 03/02/05 %% currentdict /thislevelsep known {thislevelsep} {levelsep} ifelse %% 03/02/05 %% mulv addv %% 03/02/05 %% v n 1 sub neg 2 div nb_noeuds_affiches add %% 03/02/05 %% currentdict /thistreesep known {thistreesep} {treesep} ifelse %% 03/02/05 %% mul mulv addv %% 03/02/05 %% /y_fils exch def %% 03/02/05 %% /x_fils exch def %% 03/02/05 %% %% 03/02/05 %% /noeud_fils suivant def %% 03/02/05 %% %% on donne les coordonnees du noeuds fils %% 03/02/05 %% noeud_fils %% 03/02/05 %% x_fils y_fils %% 03/02/05 %% put_coordonnees_noeud %% 03/02/05 %% %% 03/02/05 %% %% on verifie que ce noeud a un nom %% 03/02/05 %% /nomB noeud_fils get_name_noeud def %% 03/02/05 %% nomB length 0 eq { %% 03/02/05 %% %% ds le cas contraire on lui en donne 1 %% 03/02/05 %% /nomB nomA nb_noeuds_affiches chaine cvs append store %% 03/02/05 %% noeud_fils nomB put_name_noeud %% 03/02/05 %% } if %% 03/02/05 %% %% 03/02/05 %% %% on affiche le noeud %% 03/02/05 %% noeud_fils declare_noeud %% 03/02/05 %% /nb_noeuds_affiches nb_noeuds_affiches 1 add store %% 03/02/05 %% noeud_fils get_relie_noeud { %% 03/02/05 %% %% puis on le relie au noeud pere %% 03/02/05 %% noeud_pere get_name_noeud %% 03/02/05 %% noeud_fils get_name_noeud %% 03/02/05 %% treeedge %% 03/02/05 %% } if %% 03/02/05 %% } { %% 03/02/05 %% %% c'est un sous-arbre %% 03/02/05 %% %% on recupere le noeud precedent %% 03/02/05 %% % table i 1 sub get %% 03/02/05 %% precedent %% 03/02/05 %% suivant ltree %% 03/02/05 %% } ifelse %% 03/02/05 %% } { %% 03/02/05 %% } ifelse %% 03/02/05 %% /i i 1 add store %% 03/02/05 %% } repeat %% 03/02/05 %% currentdict /i undef %% 03/02/05 %% currentdict /nomA undef %% 03/02/05 %% % currentdict /nomB undef %% 03/02/05 %% currentdict /x_pere undef %% 03/02/05 %% currentdict /y_pere undef %% 03/02/05 %% currentdict /n undef %% 03/02/05 %% currentdict /u undef %% 03/02/05 %% currentdict /v undef %% 03/02/05 %% currentdict /table undef %% 03/02/05 %% %% currentdict /nomB known { %% 03/02/05 %% %% [nomB (node_dict) append cvlit where pop {} forall] {treenodedict 3 1 roll put} spapply %% 03/02/05 %% %% } if %% 03/02/05 %% %% on redescend le niveau de profondeur %% 03/02/05 %% /treelevelno treelevelno 1 sub store %% 03/02/05 %% grestore %% 03/02/05 %% end %% 03/02/05 %% } def %% syntaxe : noeud array tree* -> comme tree mais avec equilibrage automatique /tree* { 1 dict begin /equilibrageautomatique true def tree /equilibrageautomatique false def end } def %% syntaxe : noeud array tree /tree { 3 dict begin %% on recupere les donnees /table exch def /noeud_pere exch def %% on verifie que le pere a un nom /nomA noeud_pere get_name_noeud def nomA length 0 eq { %% ds le cas contraire on lui en donne 1 /nomA (A) store noeud_pere nomA put_name_noeud } if %% affichage du noeud pere noeud_pere table noeud_pere end /treelevelno 0 def declare_noeud ltree % [treenodedict {} forall] {currentdict 3 1 roll put} spapply } def %% %% syntaxe : noeud ssarbre ltree %% /ltree { %% 10 dict begin %% gsave %% %% on recupere les donnees %% /table exch def %% /noeud_pere exch def %% %% on augmente le niveau de profondeur %% /treelevelno treelevelno 1 add store %% %% %% on verifie que le pere a un nom %% /nomA noeud_pere get_name_noeud def %% nomA length 0 eq { %% %% ds le cas contraire on lui en donne 1 %% /nomA (A) store %% noeud_pere nomA put_name_noeud %% } if %% %% %% nb d'elts dans l'arbre %% /n table compte_noeuds_sousarbre def %% /i 0 def %% indice pour explorer le ssarbre %% /nb_noeuds_affiches 0 def %% %% y a-t-il un treehook pour ce niveau ? %% /hookname (treehook) treelevelno 1 sub {(i) append} repeat cvlit def %% hookname where { %% hookname get exec %% } if %% %% les parametres specifies explicitement %% table withpar {table get_tree_param exec} if %% %% calcul des vecteurs directions pour les noeuds fils %% noeud_pere get_coordonnees_noeud %% /y_pere exch def %% /x_pere exch def %% table withdir { %% table get_tree_dir %% 2 copy /treedefaultdir defpoint %% } { %% treedefaultdir %% } ifelse %% /u defpoint %% u normal /v defpoint %% %% equilibrageautomatique { %% [n {0} repeat] treedefaultdir 0 0 -1 table dimleveltree %% /dimniveau exch def %% /tabledimnodelevel exch def %% } if %% %% %% on explore le sous-arbre %% table length { %% table i get xcheck { %% /suivant () def %% } { %% /suivant table i get def %% } ifelse %% %% suivant isarray { %% suivant istreenode { %% %% c'est un nouveau noeud fils %% %% calcul des coordonnees %% equilibrageautomatique { %% x_pere y_pere %% u %% currentdict /thislevelsep known {thislevelsep} {levelsep} ifelse %% mulv addv %% v dimniveau -2 div %% 1 dict begin %% /i 0 def %% nb_noeuds_affiches { %% tabledimnodelevel i get add %% treenodesepjps add %% /i i 1 add store %% } repeat %% tabledimnodelevel i get 2 div add %% end %% mulv addv %% } { %% x_pere y_pere %% u %% currentdict /thislevelsep known {thislevelsep} {levelsep} ifelse %% mulv addv %% v n 1 sub neg 2 div nb_noeuds_affiches add %% currentdict /thistreesep known {thistreesep} {treesep} ifelse %% mul mulv addv %% } ifelse %% /y_fils exch def %% /x_fils exch def %% %% /noeud_fils suivant def %% %% on donne les coordonnees du noeuds fils %% noeud_fils %% x_fils y_fils %% put_coordonnees_noeud %% %% %% on verifie que ce noeud a un nom %% /nomB noeud_fils get_name_noeud def %% nomB length 0 eq { %% %% ds le cas contraire on lui en donne 1 %% /nomB nomA nb_noeuds_affiches chaine cvs append store %% noeud_fils nomB put_name_noeud %% } if %% %% %% on affiche le noeud %% noeud_fils declare_noeud %% /nb_noeuds_affiches nb_noeuds_affiches 1 add store %% noeud_fils get_relie_noeud { %% %% puis on le relie au noeud pere %% noeud_pere get_name_noeud %% noeud_fils get_name_noeud %% treeedge %% } if %% } { %% %% c'est un sous-arbre %% %% on recupere le noeud precedent %% % table i 1 sub get %% precedent %% suivant ltree %% } ifelse %% } { %% } ifelse %% /i i 1 add store %% } repeat %% currentdict /i undef %% currentdict /nomA undef %% % currentdict /nomB undef %% currentdict /x_pere undef %% currentdict /y_pere undef %% currentdict /n undef %% currentdict /u undef %% currentdict /v undef %% currentdict /table undef %% %% currentdict /nomB known { %% %% [nomB (node_dict) append cvlit where pop {} forall] {treenodedict 3 1 roll put} spapply %% %% } if %% %% on redescend le niveau de profondeur %% /treelevelno treelevelno 1 sub store %% grestore %% end %% } def %% syntaxe : noeud ssarbre ltree /ltree { 10 dict begin gsave %% on recupere les donnees /table exch def /noeud_pere exch def %% on augmente le niveau de profondeur /treelevelno treelevelno 1 add store %% on verifie que le pere a un nom /nomA noeud_pere get_name_noeud def nomA length 0 eq { %% ds le cas contraire on lui en donne 1 /nomA (A) store noeud_pere nomA put_name_noeud } if %% nb d'elts dans l'arbre /n table compte_noeuds_sousarbre def /i 0 def %% indice pour explorer le ssarbre /nb_noeuds_affiches 0 def %% y a-t-il un treehook pour ce niveau ? /hookname (treehook) treelevelno 1 sub {(i) append} repeat cvlit def hookname where { hookname get exec } if %% les parametres specifies explicitement table withpar {table get_tree_param exec} if %% calcul des vecteurs directions pour les noeuds fils noeud_pere get_coordonnees_noeud /y_pere exch def /x_pere exch def table withdir { table get_tree_dir 2 copy /treedefaultdir defpoint } { treedefaultdir } ifelse /u defpoint u normal /v defpoint equilibrageautomatique { [n {0} repeat] treedefaultdir 0 0 -1 table dimleveltree /dimniveau exch def /tabledimnodelevel exch def } if %% on explore le sous-arbre table length { table i get xcheck { /suivant () def } { /suivant table i get def } ifelse suivant isarray { suivant istreenode { %% c'est un nouveau noeud fils %% calcul des coordonnees equilibrageautomatique { x_pere y_pere u currentdict /thislevelsep known {thislevelsep} {levelsep} ifelse mulv addv v dimniveau -2 div 1 dict begin /i 0 def nb_noeuds_affiches { tabledimnodelevel i get add treenodesepjps add /i i 1 add store } repeat tabledimnodelevel i get 2 div add end mulv addv } { x_pere y_pere u currentdict /thislevelsep known {thislevelsep} {levelsep} ifelse mulv addv v n 1 sub neg 2 div nb_noeuds_affiches add currentdict /thistreesep known {thistreesep} {treesep} ifelse mul mulv addv } ifelse /y_fils exch def /x_fils exch def /noeud_fils suivant def %% on donne les coordonnees du noeuds fils noeud_fils x_fils y_fils put_coordonnees_noeud %% on verifie que ce noeud a un nom /nomB noeud_fils get_name_noeud def nomB length 0 eq { %% ds le cas contraire on lui en donne 1 /nomB nomA nb_noeuds_affiches chaine cvs append store noeud_fils nomB put_name_noeud } if %% on affiche le noeud noeud_fils declare_noeud /nb_noeuds_affiches nb_noeuds_affiches 1 add store %% puis on le relie au noeud pere noeud_fils get_relie_noeud { noeud_pere get_name_noeud noeud_fils get_name_noeud treeedge } if %% affichage des labels de liaison 1 dict begin /i 0 def noeud_fils get_liaison_array length { noeud_fils get_liaison_array i get dup isstring not { chargetexlabel } if noeud_fils get_coordonnees_noeud noeud_pere get_coordonnees_noeud milieu noeud_fils get_affliaison_array i get cvx exec /i i 1 add store } repeat end } { %% c'est un sous-arbre %% on recupere le noeud precedent % table i 1 sub get precedent suivant ltree } ifelse } { } ifelse /i i 1 add store } repeat %% 2/3/5 %% currentdict /i undef %% 2/3/5 %% currentdict /nomA undef %% 2/3/5 %% % currentdict /nomB undef %% 2/3/5 %% currentdict /x_pere undef %% 2/3/5 %% currentdict /y_pere undef %% 2/3/5 %% currentdict /n undef %% 2/3/5 %% currentdict /u undef %% 2/3/5 %% currentdict /v undef %% 2/3/5 %% currentdict /table undef %% on redescend le niveau de profondeur /treelevelno treelevelno 1 sub store grestore end } def %% syntaxe : ssarbre firsttnode --> tnode ou ssarbre /firsttnode { 2 dict begin /ssarbre exch def ssarbre withdir { /i 2 def } { /i 0 def } ifelse ssarbre i get xcheck { /i i 1 add store ssarbre i get } { ssarbre i get } ifelse end } def /indicefirsttnode { 2 dict begin /ssarbre exch def ssarbre withdir { /i 2 def } { /i 0 def } ifelse ssarbre i get xcheck { i 1 add } { i } ifelse end } def %% syntaxe : ssarbre compte_noeuds_sousarbre --> n /compte_elts_sousarbre { 3 dict begin /ssarbre exch def /i 0 def /n 0 def ssarbre length { ssarbre i get isarray { /n n 1 add store } if /i i 1 add store } repeat n end } def