summaryrefslogtreecommitdiff
path: root/dwr/graph2.hh
blob: 128ba327ec961a8327564e46df59a800022f0ef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef __DWR_GRAPH2_HH__
#define __DWR_GRAPH2_HH__

#include <graphviz/gvc.h>

#include "dw/core.hh"

namespace rtfl {

namespace dw {

class Graph2: public ::dw::core::Widget
{
private:
   class Graph2Iterator: public ::dw::core::Iterator
   {
   private:
      int index;

      Graph2Iterator (Graph2 *graph, ::dw::core::Content::Type mask, int index);

   public:
      Graph2Iterator (Graph2 *graph, ::dw::core::Content::Type mask,
                      bool atEnd);

      lout::object::Object *clone ();
      int compareTo (lout::object::Comparable *other);

      bool next ();
      bool prev ();
      void highlight (int start, int end, ::dw::core::HighlightLayer layer);
      void unhighlight (int direction, ::dw::core::HighlightLayer layer);
      void getAllocation (int start, int end,
                          ::dw::core::Allocation *allocation);
   };

   class Node: public lout::object::Object
   {
   private:
      Graph2 *graph;
      int index;

   public:
      Node (Graph2 *graph, Widget *widget, int index);
      ~Node ();

      void initAg ();
      void cleanupAg ();

      Widget *widget;
      Agnode_t *node;
   };

   class Edge: public lout::object::Object
   {
   private:
      Graph2 *graph;
      int numPointsAlloc, index;

      void cleanupPoints ();

   public:
      Edge (Graph2 *graph, Node *from, Node *to, int index);
      ~Edge ();

      void initAg ();
      void cleanupAg ();

      void setNumPoints (int numPoints);
      void sortPoints ();

      Node *from, *to;
      Agedge_t *edge;
      int numPoints;
      int *pointX, *pointY;
      char *pointType;
      
      int count;
   };

   enum { AHEADLEN = 10 };

   Agraph_t *graph;
   GVC_t *gvc;
   lout::container::typed::Vector<Node> *nodes;
   lout::container::typed::Vector<Edge> *edges;
   bool inDestructor;

   void initAg ();
   void cleanupAg ();

   int searchNodeIndex (Widget *widget);
   inline Node *searchNode (Widget *widget)
   { return nodes->get (searchNodeIndex (widget)); }

protected:
   void sizeRequestImpl (::dw::core::Requisition *requisition);
   void getExtremesImpl (::dw::core::Extremes *extremes);
   void sizeAllocateImpl (::dw::core::Allocation *allocation);

public:
   static int CLASS_ID;

   Graph2 ();
   ~Graph2 ();

   void draw (::dw::core::View *view, ::dw::core::Rectangle *area);
   ::dw::core::Iterator *iterator (::dw::core::Content::Type mask, bool atEnd);
   void removeChild (Widget *child);

   inline void setRefStyle (::dw::core::style::Style *style)
   { /* No need anymore. */ }

   void addNode (Widget *widget);
   void addEdge (::dw::core::Widget *from, ::dw::core::Widget *to);
};

} // namespace rtfl

} // namespace dw

#endif // __DWR_GRAPH2_HH__