ROOT logo
// @(#)root/hist:$Id$
// Author: Olivier Couet 13/07/09

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TLatex.h"
#include "TEllipse.h"
#include "TGraphNode.h"

#include <gvc.h>

ClassImp(TGraphNode)

//______________________________________________________________________________
/* Begin_Html
<center><h2>Graph Node class</h2></center>
TGraphNode is a graph node object which can be added in a TGraphStruct.
End_Html */


//______________________________________________________________________________
TGraphNode::TGraphNode(): TNamed(), TAttText()
{
   // Graph node default constructor.

   fGVNode = 0;
   fX      = 0;
   fY      = 0;
   fW      = 0;
   fH      = 0;
}


//______________________________________________________________________________
TGraphNode::TGraphNode(const char *name,const char *title)
           :TNamed(name,title), TAttText()
{
   // Graph node normal constructor.

   fGVNode = 0;
   fX      = 0;
   fY      = 0;
   fW      = 0;
   fH      = 0;
}


//______________________________________________________________________________
TGraphNode::~TGraphNode()
{
   // Graph Node default destructor.
   
}


//______________________________________________________________________________
void TGraphNode::CreateGVNode(GVizAgraph_t *gv)
{
   // Create the GraphViz node into the GraphViz data structure gv.

   if (gv) {
#ifdef WITH_CGRAPH
      fGVNode = (GVizAgnode_t*)agnode((Agraph_t*)gv, (char *)GetName(), 1);
#else
      fGVNode = (GVizAgnode_t*)agnode((Agraph_t*)gv, (char *)GetName());
#endif
   } else {
      Error("CreateGVNode","Invalid graphviz graph");
   }
}


//______________________________________________________________________________
Int_t TGraphNode::DistancetoPrimitive(Int_t px, Int_t py)
{
   // Compute distance from point px,py to a node.

   Int_t dist;

   // The node is drawn as an ellipse
   TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
   ellipse.SetFillColor(1); // in order to pick the ellipse "inside"
   dist =  ellipse.DistancetoPrimitive(px, py);

   return dist;
}


//______________________________________________________________________________
void TGraphNode::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
   // Execute action corresponding to one event.
   
   TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
   ellipse.ExecuteEvent(event,px, py);
   fX = ellipse.GetX1();
   fY = ellipse.GetY1();
   fW = ellipse.GetR1();
   fH = ellipse.GetR2();
}


//______________________________________________________________________________
void TGraphNode::Layout()
{
   // Layout this node in the GraphViz space. This is done after gvLayout
   // has been performed.

#ifdef ND_coord
   fX = ND_coord((Agnode_t*)fGVNode).x;
   fY = ND_coord((Agnode_t*)fGVNode).y;
#endif
#ifdef ND_coord_i
   fX = ND_coord_i((Agnode_t*)fGVNode).x;
   fY = ND_coord_i((Agnode_t*)fGVNode).y;
#endif
   fW = ND_width((Agnode_t*)fGVNode)*36;
   fH = ND_height((Agnode_t*)fGVNode)*36;
}


//______________________________________________________________________________
void TGraphNode::Paint(Option_t *)
{
   // Paint this node with its current attributes.

   TEllipse ellipse;
   TLatex text;
   text.SetTextAlign(22);

   // Draw the node shape as an ellipse
   // ND_shape((Agnode_t*)fGVNode)->name gives the type of shape.
   ellipse.SetFillStyle(GetFillStyle());
   ellipse.SetFillColor(GetFillColor());
   ellipse.SetLineColor(GetLineColor());
   ellipse.SetLineStyle(GetLineStyle());
   ellipse.SetLineWidth(GetLineWidth());
   ellipse.PaintEllipse(fX, fY, fW, fH, 0., 360., 0., "");
   
   // Draw the node title
   text.SetTextColor(GetTextColor());
   text.SetTextFont(GetTextFont());
   text.PaintLatex(fX, fY, 0., GetTextSize(), (char*)GetTitle());
}


//______________________________________________________________________________
void TGraphNode::SavePrimitive(ostream &, Option_t *)
{
   // Save primitive as a C++ statement(s) on output stream out
}


//______________________________________________________________________________
void TGraphNode::SaveAttributes(ostream &out)
{
   // Save attributes as a C++ statement(s) on output stream out
   // called by TGraphStruct::SavePrimitive.

   SaveFillAttributes(out,GetName(),0,1001);
   SaveLineAttributes(out,GetName(),1,1,1);
   SaveTextAttributes(out,GetName(),0,0,0,0,0);
}

//______________________________________________________________________________
void TGraphNode::Streamer(TBuffer &/*b*/)
{
}
 TGraphNode.cxx:1
 TGraphNode.cxx:2
 TGraphNode.cxx:3
 TGraphNode.cxx:4
 TGraphNode.cxx:5
 TGraphNode.cxx:6
 TGraphNode.cxx:7
 TGraphNode.cxx:8
 TGraphNode.cxx:9
 TGraphNode.cxx:10
 TGraphNode.cxx:11
 TGraphNode.cxx:12
 TGraphNode.cxx:13
 TGraphNode.cxx:14
 TGraphNode.cxx:15
 TGraphNode.cxx:16
 TGraphNode.cxx:17
 TGraphNode.cxx:18
 TGraphNode.cxx:19
 TGraphNode.cxx:20
 TGraphNode.cxx:21
 TGraphNode.cxx:22
 TGraphNode.cxx:23
 TGraphNode.cxx:24
 TGraphNode.cxx:25
 TGraphNode.cxx:26
 TGraphNode.cxx:27
 TGraphNode.cxx:28
 TGraphNode.cxx:29
 TGraphNode.cxx:30
 TGraphNode.cxx:31
 TGraphNode.cxx:32
 TGraphNode.cxx:33
 TGraphNode.cxx:34
 TGraphNode.cxx:35
 TGraphNode.cxx:36
 TGraphNode.cxx:37
 TGraphNode.cxx:38
 TGraphNode.cxx:39
 TGraphNode.cxx:40
 TGraphNode.cxx:41
 TGraphNode.cxx:42
 TGraphNode.cxx:43
 TGraphNode.cxx:44
 TGraphNode.cxx:45
 TGraphNode.cxx:46
 TGraphNode.cxx:47
 TGraphNode.cxx:48
 TGraphNode.cxx:49
 TGraphNode.cxx:50
 TGraphNode.cxx:51
 TGraphNode.cxx:52
 TGraphNode.cxx:53
 TGraphNode.cxx:54
 TGraphNode.cxx:55
 TGraphNode.cxx:56
 TGraphNode.cxx:57
 TGraphNode.cxx:58
 TGraphNode.cxx:59
 TGraphNode.cxx:60
 TGraphNode.cxx:61
 TGraphNode.cxx:62
 TGraphNode.cxx:63
 TGraphNode.cxx:64
 TGraphNode.cxx:65
 TGraphNode.cxx:66
 TGraphNode.cxx:67
 TGraphNode.cxx:68
 TGraphNode.cxx:69
 TGraphNode.cxx:70
 TGraphNode.cxx:71
 TGraphNode.cxx:72
 TGraphNode.cxx:73
 TGraphNode.cxx:74
 TGraphNode.cxx:75
 TGraphNode.cxx:76
 TGraphNode.cxx:77
 TGraphNode.cxx:78
 TGraphNode.cxx:79
 TGraphNode.cxx:80
 TGraphNode.cxx:81
 TGraphNode.cxx:82
 TGraphNode.cxx:83
 TGraphNode.cxx:84
 TGraphNode.cxx:85
 TGraphNode.cxx:86
 TGraphNode.cxx:87
 TGraphNode.cxx:88
 TGraphNode.cxx:89
 TGraphNode.cxx:90
 TGraphNode.cxx:91
 TGraphNode.cxx:92
 TGraphNode.cxx:93
 TGraphNode.cxx:94
 TGraphNode.cxx:95
 TGraphNode.cxx:96
 TGraphNode.cxx:97
 TGraphNode.cxx:98
 TGraphNode.cxx:99
 TGraphNode.cxx:100
 TGraphNode.cxx:101
 TGraphNode.cxx:102
 TGraphNode.cxx:103
 TGraphNode.cxx:104
 TGraphNode.cxx:105
 TGraphNode.cxx:106
 TGraphNode.cxx:107
 TGraphNode.cxx:108
 TGraphNode.cxx:109
 TGraphNode.cxx:110
 TGraphNode.cxx:111
 TGraphNode.cxx:112
 TGraphNode.cxx:113
 TGraphNode.cxx:114
 TGraphNode.cxx:115
 TGraphNode.cxx:116
 TGraphNode.cxx:117
 TGraphNode.cxx:118
 TGraphNode.cxx:119
 TGraphNode.cxx:120
 TGraphNode.cxx:121
 TGraphNode.cxx:122
 TGraphNode.cxx:123
 TGraphNode.cxx:124
 TGraphNode.cxx:125
 TGraphNode.cxx:126
 TGraphNode.cxx:127
 TGraphNode.cxx:128
 TGraphNode.cxx:129
 TGraphNode.cxx:130
 TGraphNode.cxx:131
 TGraphNode.cxx:132
 TGraphNode.cxx:133
 TGraphNode.cxx:134
 TGraphNode.cxx:135
 TGraphNode.cxx:136
 TGraphNode.cxx:137
 TGraphNode.cxx:138
 TGraphNode.cxx:139
 TGraphNode.cxx:140
 TGraphNode.cxx:141
 TGraphNode.cxx:142
 TGraphNode.cxx:143
 TGraphNode.cxx:144
 TGraphNode.cxx:145
 TGraphNode.cxx:146
 TGraphNode.cxx:147
 TGraphNode.cxx:148
 TGraphNode.cxx:149
 TGraphNode.cxx:150
 TGraphNode.cxx:151
 TGraphNode.cxx:152
 TGraphNode.cxx:153
 TGraphNode.cxx:154
 TGraphNode.cxx:155
 TGraphNode.cxx:156
 TGraphNode.cxx:157
 TGraphNode.cxx:158
 TGraphNode.cxx:159
 TGraphNode.cxx:160
 TGraphNode.cxx:161
 TGraphNode.cxx:162
 TGraphNode.cxx:163
 TGraphNode.cxx:164
 TGraphNode.cxx:165
 TGraphNode.cxx:166
 TGraphNode.cxx:167
 TGraphNode.cxx:168
 TGraphNode.cxx:169
 TGraphNode.cxx:170
 TGraphNode.cxx:171
 TGraphNode.cxx:172
 TGraphNode.cxx:173
 TGraphNode.cxx:174