home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / ui / change.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-07  |  9.9 KB  |  446 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1986, 1988 Regents of the University of California
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8. /**
  9.    change.c - routines for changing attributes of a node, an edge, or edges
  10.    associated with a node.
  11.  
  12.    Nodes, edges, and the in and out edges of a node can have their attributes 
  13.    set to match the built-in attributes display, or reset to their default
  14.    values.  In addition, nodes and edges can be cycled through all possible
  15.    values of their attributes
  16.  
  17.    An attribute is *never* changed if the built-in attributes display says
  18.    there is no value for that attribute.  So, for example, if the BIAD shows
  19.    a shape of 'circle', a brush of 'no brush', and a color of 'white', a
  20.    set will only set a node's shape and color (and a reset will not reset
  21.    a node's brush!).  The shape attribute, of course, has no affect on
  22.    edges.
  23.  
  24.    For the purposes of cycling, shape can be considered the 'least significant'
  25.    attribute and color the 'most significant'.  So a node will first cycle 
  26.    through all shapes, keeping the same color and brush.  When the shape 
  27.    changes to the first shape (rectangle), the brush changes, too, and so on.  
  28.    This, again, is subject to the restrictions in the previous paragraph; if 
  29.    the current shape is 'no shape', brush becomes the least significant 
  30.    attribute, and if the current brush is 'no brush;, color is the least 
  31.    significant.
  32.  **/
  33.  
  34. #include "attribute.h"
  35. #include "digraph.h"
  36. #include "globals.h"
  37. #include "interf.h"
  38. #include "tedge.h"
  39.  
  40. extern NODE *next_dummy(), *prev_dummy();
  41. extern BOOL edge_on_screen(), on_screen();
  42. extern OUTEDGE *get_edge();
  43.  
  44. void DoCycleEdge()
  45.   /* set an edge's attributes to the 'next' value */
  46. {
  47.     TEDGE* t;
  48.     BRUSH brush;
  49.     COLOR color;
  50.     OUTEDGE* e;
  51.  
  52.     t = (TEDGE *) ICurEdge();
  53.     e = get_edge(digraph, (NODE *) t->fromnode, (NODE *) t->tonode, t->ord);
  54.  
  55.     brush = INextBrush(Brush(e));
  56.  
  57.     if (!IBrushSet() || brush == SOLIDB)
  58.       /* brush has no value or brush has caused a 'carry' */
  59.     {
  60.         color = INextColor(Color(e));
  61.     }
  62.     else 
  63.     {
  64.     color = Color(e);
  65.     }
  66.  
  67.     ChangeEdge((NODE *) t->fromnode, (NODE *) t->tonode, brush, color, t->ord);
  68. }
  69.     
  70. void DoSetEdge()
  71.   /**
  72.      set an edge's attributes to the values displayed in the built-in
  73.      attribute display
  74.    **/
  75. {
  76.     TEDGE* t;
  77.     BRUSH brush;
  78.     COLOR color;
  79.  
  80.     brush = ICurBrush();
  81.     color = ICurColor();
  82.     t = (TEDGE *) ICurEdge();
  83.     ChangeEdge((NODE *) t->fromnode, (NODE *) t->tonode, brush, color, t->ord);
  84. }
  85.  
  86. void DoResetEdge()
  87.   /**
  88.      reset an edge's attributes
  89.    **/
  90. {
  91.     TEDGE *t;
  92.  
  93.     t = (TEDGE *) ICurEdge();
  94.     ChangeEdge((NODE *) t->fromnode, (NODE *) t->tonode, DEFAULT_BRUSH, 
  95.            DEFAULT_COLOR, t->ord);
  96. }
  97.  
  98. ChangeEdge(from, to, brush, color, ord)
  99. NODE *from, *to;
  100. BRUSH brush;
  101. COLOR color;
  102. int ord;
  103.   /**
  104.      Handy edge changing routine:  change the edge from from to to with 
  105.      ordinality ord so it has brush brush and color color (got that?)
  106.      However, don't change the brush if the current brush is 'no brush', or
  107.      the color if the current color is 'no color'.
  108.  
  109.      If the edge is on the screen, it must be redisplayed.  If one of
  110.      the endpoints of the edge is a dummy node, it's only a subedge and
  111.      the rest of it must be changed, also.
  112.    **/
  113. {
  114.     OUTEDGE* e;
  115.  
  116.     e = get_edge(digraph, from, to, ord);
  117.  
  118.     if (IColorSet())
  119.     {
  120.         Color(e) = color;
  121.     }
  122.  
  123.     if (IBrushSet())
  124.     {
  125.         Brush(e) = brush;
  126.     }
  127.  
  128.     if (edge_on_screen(from, to))
  129.     {
  130.     IChangeEdge(from, to, ord, Brush(e), Color(e));
  131.     }
  132.  
  133.     if (Is_dummy(to)) 
  134.     {
  135.         ChangeToDummyEdges(to, ord, Brush(e), Color(e));
  136.     }
  137.  
  138.     if (Is_dummy(from)) 
  139.     {
  140.         ChangeFromDummyEdges(from, ord, Brush(e), Color(e));
  141.     }
  142.  
  143.     graphChanged = TRUE;    /* the times, they are a changin' */
  144.     ckpt_done = FALSE;
  145. }
  146.  
  147. void DoCycleNode()
  148.   /* set a node's attributes to the 'next' value */
  149. {
  150.     NODE *node;
  151.     SHAPE shape;
  152.     BRUSH brush;
  153.     COLOR color;
  154.  
  155.     node = (NODE *) ICurNode();
  156.     shape = INextShape(Shape(node));
  157.  
  158.     if (!IShapeSet() || shape == RECTANGLE)
  159.       /* if the shape doesn't change, or the shape generated a 'carry' */
  160.     {
  161.         brush = INextBrush(Brush(node));
  162.  
  163.     if (!IBrushSet() || brush == SOLIDB)
  164.       /* if the brush doesn't change, or the brush generated a 'carry' */
  165.     {
  166.             color = INextColor(Color(node));
  167.     }
  168.     else
  169.     {
  170.         color = Color(node);
  171.     }
  172.     }
  173.     else
  174.     {
  175.     brush = Brush(node);
  176.     color = Color(node);
  177.     }
  178.  
  179.     ChangeNode(node, shape, brush, color);
  180. }
  181.  
  182. void DoSetNode()
  183.   /**
  184.      set a node's attributes to the values displayed in the built-in
  185.      attribute display
  186.    **/
  187. {
  188.     NODE *node;
  189.     SHAPE shape;
  190.     BRUSH brush;
  191.     COLOR color;
  192.  
  193.     node = (NODE *) ICurNode();
  194.     shape = ICurShape();
  195.     brush = ICurBrush();
  196.     color = ICurColor();
  197.  
  198.     ChangeNode(node, shape, brush, color);
  199. }
  200.  
  201. void DoResetNode()
  202.   /**
  203.      reset a node's attributes
  204.    **/
  205. {
  206.     NODE *node;
  207.  
  208.     node = (NODE *) ICurNode();
  209.  
  210.     ChangeNode(node, DEFAULT_SHAPE, DEFAULT_BRUSH, DEFAULT_COLOR);
  211. }
  212.  
  213. ChangeNode(node, shape, brush, color)
  214. NODE *node;
  215. SHAPE shape;
  216. BRUSH brush;
  217. COLOR color;
  218.   /**
  219.      Handy node changing routine:  change node 
  220.      so it has shape shape, brush brush, and color color (got that?)
  221.      However, don't change the shape if the current shape is 'no shape',
  222.      the brush if the current brush is 'no brush', or
  223.      the color if the current color is 'no color'.
  224.  
  225.      If the node is on the screen, it must be redisplayed (I really wonder
  226.      how it could fail to be so).  
  227.    **/
  228. {
  229.     if (IShapeSet())
  230.     {
  231.         Shape(node) = shape;
  232.     }
  233.  
  234.     if (IColorSet())
  235.     {
  236.         Color(node) = color;
  237.     }
  238.  
  239.     if (IBrushSet())
  240.     {
  241.         Brush(node) = brush;
  242.     }
  243.  
  244.     if (on_screen(node))
  245.     {
  246.     IChangeNode(node, Shape(node), Brush(node), Color(node));
  247.     }
  248.  
  249.     graphChanged = TRUE;    /* I'm a changeling... see me change */
  250.     ckpt_done = FALSE;
  251. }
  252.  
  253. void DoSetEdges()
  254.   /**
  255.      set the attributes of the in/out edges of the current node
  256.      to the values displayed in the built-in attribute display
  257.    **/
  258. {
  259.     NODE *node;
  260.     BRUSH brush;
  261.     COLOR color;
  262.  
  263.     node = (NODE *) ICurNode();
  264.     brush = ICurBrush();
  265.     color = ICurColor();
  266.  
  267.     if (changeOutEdges)
  268.     {
  269.     ChangeOutEdges(node, brush, color);
  270.     }
  271.  
  272.     if (changeInEdges)
  273.     {
  274.     ChangeInEdges(node, brush, color);
  275.     }
  276. }
  277.  
  278. void DoResetEdges()
  279.   /**
  280.      reset the attributes of the in/out edges of the current node
  281.    **/
  282. {
  283.     NODE* node;
  284.  
  285.     node = (NODE *) ICurNode();
  286.  
  287.     if (changeOutEdges) 
  288.     {
  289.     ChangeOutEdges(node, DEFAULT_BRUSH, DEFAULT_COLOR);
  290.     }
  291.  
  292.     if (changeInEdges) 
  293.     {
  294.     ChangeInEdges(node, DEFAULT_BRUSH, DEFAULT_COLOR);
  295.     }
  296. }
  297.  
  298. ChangeOutEdges(node, brush, color)
  299. NODE *node;
  300. BRUSH brush;
  301. COLOR color;
  302.   /**
  303.      Not as easy as it may seem.  You see, the inedges of a node are
  304.      really 'up edges' (edges that go to nodes above this one in the graph).  
  305.      Similarly, outedges are 'down edges'.  And, of course, antecedents and 
  306.      succedents could more aptly be called upstairs and downstairs neighbors.
  307.      So, to find the true in/out edges of a node, you have to look at
  308.      both the antecedent and succedent sets.
  309.  
  310.      Outedges are edges to succedents that aren't reversed and from
  311.      antecedents that are.
  312.    **/
  313. {
  314.     VNO toVno;        /* each succedent node */
  315.     NODE *toNode;
  316.     OUTEDGE *e;
  317.     int i;
  318.  
  319.     each_element(Succ_set(node), toVno)
  320.     loop
  321.     toNode = Node(digraph, toVno);
  322.  
  323.     for (i = max_edges(node, toNode); i > 0; i--)
  324.     {
  325.         if ((e = get_edge(digraph, node, toNode, i)) != NULL &&
  326.         !Edge_reversed(e))
  327.         {
  328.             ChangeEdge(node, toNode, brush, color, i);
  329.         }
  330.     }
  331.     endloop;
  332.  
  333.     each_element(Ante_set(node), toVno)
  334.     loop
  335.     toNode = Node(digraph, toVno);
  336.  
  337.     for (i = max_edges(toNode, node); i > 0; i--)
  338.     {
  339.         if ((e = get_edge(digraph, toNode, node, i)) != NULL &&
  340.         Edge_reversed(e))
  341.         {
  342.             ChangeEdge(toNode, node, brush, color, i);
  343.         }
  344.     }
  345.     endloop;
  346. }
  347.  
  348. ChangeInEdges(node, brush, color)
  349. NODE *node;
  350. BRUSH brush;
  351. COLOR color;
  352.   /**
  353.      See the note to ChangeOutEdges, above.
  354.  
  355.      Inedges are edges to succedents that are reversed and from
  356.      antecedents that aren't.
  357.    **/
  358. {
  359.     VNO fromVno;        /* each antecedent node */
  360.     NODE *fromNode;
  361.     OUTEDGE *e;
  362.     int i;
  363.  
  364.     each_element(Ante_set(node), fromVno)
  365.     loop
  366.     fromNode = Node(digraph, fromVno);
  367.  
  368.     for (i = max_edges(fromNode, node); i > 0; i--)
  369.     {
  370.         if ((e = get_edge(digraph, fromNode, node, i)) != NULL &&
  371.         !Edge_reversed(e))
  372.         {
  373.             ChangeEdge(fromNode, node, brush, color, i);
  374.         }
  375.     }
  376.     endloop;
  377.  
  378.     each_element(Succ_set(node), fromVno)
  379.     loop
  380.     fromNode = Node(digraph, fromVno);
  381.  
  382.     for (i = max_edges(node, fromNode); i > 0; i--)
  383.     {
  384.         if ((e = get_edge(digraph, node, fromNode, i)) != NULL &&
  385.             Edge_reversed(e))
  386.         {
  387.             ChangeEdge(node, fromNode, brush, color, i);
  388.         }
  389.     }
  390.     endloop;
  391. }
  392.  
  393. ChangeToDummyEdges(fromNode, ord, brush, color)
  394. NODE *fromNode;
  395. int ord;
  396. BRUSH brush;
  397. COLOR color;
  398.   /**
  399.      Change the edge from fromNode of ordinality ord until we hit a non-dummy.
  400.      fromNode had better be a dummy node itself.
  401.    **/
  402. {
  403.     NODE *node, *toNode;
  404.  
  405.     node = fromNode;
  406.     toNode = next_dummy(digraph, node);
  407.  
  408.       /* change edge until non-dummy node */
  409.     do
  410.     {
  411.     if (edge_on_screen(node, toNode))
  412.     {
  413.         IChangeEdge(node, toNode, ord, brush, color);
  414.     }
  415.     
  416.     node = toNode;
  417.     toNode = next_dummy(digraph, node);
  418.     } while (Is_dummy(node));
  419. }
  420.  
  421. ChangeFromDummyEdges(node, ord, brush, color)
  422. NODE *node;
  423. int ord;
  424. BRUSH brush;
  425. COLOR color;
  426.   /**
  427.      Change the edge to node of ordinality ord until we hit a non-dummy.
  428.      node had better be a dummy node itself.
  429.    **/
  430. {
  431.     NODE *fromNode;
  432.  
  433.     fromNode = prev_dummy(digraph, node);
  434.  
  435.     do
  436.     {
  437.     if (edge_on_screen(fromNode, node))
  438.     {
  439.             IChangeEdge(fromNode, node, ord, brush, color);
  440.     }
  441.  
  442.     node = fromNode;
  443.     fromNode = prev_dummy(digraph, node);
  444.     } while (Is_dummy(node));
  445. }
  446.