ROOT  6.06/09
Reference Guide
TGraphNode.cxx
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: Olivier Couet 13/07/09
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TLatex.h"
13 #include "TEllipse.h"
14 #include "TGraphNode.h"
15 
16 #include <gvc.h>
17 
19 
20 /** \class TGraphNode
21 \ingroup gviz
22 
23 A graph node object which can be added in a TGraphStruct.
24 */
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Graph node default constructor.
28 
30 {
31  fGVNode = 0;
32  fX = 0;
33  fY = 0;
34  fW = 0;
35  fH = 0;
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Graph node normal constructor.
40 
41 TGraphNode::TGraphNode(const char *name,const char *title)
42  :TNamed(name,title), TAttText()
43 {
44  fGVNode = 0;
45  fX = 0;
46  fY = 0;
47  fW = 0;
48  fH = 0;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Graph Node default destructor.
53 
55 {
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Create the GraphViz node into the GraphViz data structure gv.
60 
61 void TGraphNode::CreateGVNode(GVizAgraph_t *gv)
62 {
63  if (gv) {
64 #ifdef WITH_CGRAPH
65  fGVNode = (GVizAgnode_t*)agnode((Agraph_t*)gv, (char *)GetName(), 1);
66 #else
67  fGVNode = (GVizAgnode_t*)agnode((Agraph_t*)gv, (char *)GetName());
68 #endif
69  } else {
70  Error("CreateGVNode","Invalid graphviz graph");
71  }
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Compute distance from point px,py to a node.
76 
78 {
79  Int_t dist;
80 
81  // The node is drawn as an ellipse
82  TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
83  ellipse.SetFillColor(1); // in order to pick the ellipse "inside"
84  dist = ellipse.DistancetoPrimitive(px, py);
85 
86  return dist;
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Execute action corresponding to one event.
91 
93 {
94  TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
95  ellipse.ExecuteEvent(event,px, py);
96  fX = ellipse.GetX1();
97  fY = ellipse.GetY1();
98  fW = ellipse.GetR1();
99  fH = ellipse.GetR2();
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Layout this node in the GraphViz space. This is done after gvLayout
104 /// has been performed.
105 
107 {
108 #ifdef ND_coord
109  fX = ND_coord((Agnode_t*)fGVNode).x;
110  fY = ND_coord((Agnode_t*)fGVNode).y;
111 #endif
112 #ifdef ND_coord_i
113  fX = ND_coord_i((Agnode_t*)fGVNode).x;
114  fY = ND_coord_i((Agnode_t*)fGVNode).y;
115 #endif
116  fW = ND_width((Agnode_t*)fGVNode)*36;
117  fH = ND_height((Agnode_t*)fGVNode)*36;
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Paint this node with its current attributes.
122 
124 {
125  TEllipse ellipse;
126  TLatex text;
127  text.SetTextAlign(22);
128 
129  // Draw the node shape as an ellipse
130  // ND_shape((Agnode_t*)fGVNode)->name gives the type of shape.
131  ellipse.SetFillStyle(GetFillStyle());
132  ellipse.SetFillColor(GetFillColor());
133  ellipse.SetLineColor(GetLineColor());
134  ellipse.SetLineStyle(GetLineStyle());
135  ellipse.SetLineWidth(GetLineWidth());
136  ellipse.PaintEllipse(fX, fY, fW, fH, 0., 360., 0., "");
137 
138  // Draw the node title
139  text.SetTextColor(GetTextColor());
140  text.SetTextFont(GetTextFont());
141  text.PaintLatex(fX, fY, 0., GetTextSize(), (char*)GetTitle());
142 }
143 
144 ////////////////////////////////////////////////////////////////////////////////
145 /// Save primitive as a C++ statement(s) on output stream out
146 
147 void TGraphNode::SavePrimitive(std::ostream &, Option_t *)
148 {
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Save attributes as a C++ statement(s) on output stream out
153 /// called by TGraphStruct::SavePrimitive.
154 
155 void TGraphNode::SaveAttributes(std::ostream &out)
156 {
157  SaveFillAttributes(out,GetName(),0,1001);
158  SaveLineAttributes(out,GetName(),1,1,1);
159  SaveTextAttributes(out,GetName(),0,0,0,0,0);
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 
164 void TGraphNode::Streamer(TBuffer &/*b*/)
165 {
166 }
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TEllipse.cxx:198
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
void CreateGVNode(GVizAgraph_t *gv)
Create the GraphViz node into the GraphViz data structure gv.
Definition: TGraphNode.cxx:61
virtual Style_t GetLineStyle() const
Definition: TAttLine.h:48
virtual Style_t GetFillStyle() const
Definition: TAttFill.h:44
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
virtual void PaintEllipse(Double_t x1, Double_t y1, Double_t r1, Double_t r2, Double_t phimin, Double_t phimax, Double_t theta, Option_t *option="")
Draw this ellipse with new coordinates.
Definition: TEllipse.cxx:527
virtual Font_t GetTextFont() const
Definition: TAttText.h:49
const char Option_t
Definition: RtypesCore.h:62
Double_t GetR1() const
Definition: TEllipse.h:71
Double_t GetY1() const
Definition: TEllipse.h:70
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual Float_t GetTextSize() const
Definition: TAttText.h:50
GVizAgnode_t * fGVNode
Definition: TGraphNode.h:49
int Int_t
Definition: RtypesCore.h:41
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to an ellipse.
Definition: TEllipse.cxx:132
virtual void SetFillStyle(Style_t fstyle)
Definition: TAttFill.h:52
Double_t fY
Definition: TGraphNode.h:51
virtual void SetTextFont(Font_t tfont=62)
Definition: TAttText.h:59
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttLine.cxx:257
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
To draw Mathematical Formula.
Definition: TLatex.h:33
virtual Color_t GetTextColor() const
Definition: TAttText.h:48
void Layout()
Layout this node in the GraphViz space.
Definition: TGraphNode.cxx:106
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition: TLatex.cxx:2025
char * out
Definition: TBase64.cxx:29
virtual void SetTextAlign(Short_t align=11)
Definition: TAttText.h:55
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
virtual ~TGraphNode()
Graph Node default destructor.
Definition: TGraphNode.cxx:54
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition: TAttText.cxx:344
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
Double_t GetX1() const
Definition: TEllipse.h:69
Text Attributes class.
Definition: TAttText.h:32
virtual Color_t GetFillColor() const
Definition: TAttFill.h:43
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition: TAttFill.cxx:229
virtual void Paint(Option_t *option="")
Paint this node with its current attributes.
Definition: TGraphNode.cxx:123
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
Double_t fW
Definition: TGraphNode.h:53
Double_t GetR2() const
Definition: TEllipse.h:72
virtual Color_t GetLineColor() const
Definition: TAttLine.h:47
void SaveAttributes(std::ostream &)
Save attributes as a C++ statement(s) on output stream out called by TGraphStruct::SavePrimitive.
Definition: TGraphNode.cxx:155
#define ClassImp(name)
Definition: Rtypes.h:279
A graph node object which can be added in a TGraphStruct.
Definition: TGraphNode.h:43
TText * text
Double_t fH
Definition: TGraphNode.h:52
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TGraphNode.cxx:92
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a node.
Definition: TGraphNode.cxx:77
Draw Ellipses.
Definition: TEllipse.h:44
virtual void SetLineStyle(Style_t lstyle)
Definition: TAttLine.h:56
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
Double_t fX
Definition: TGraphNode.h:50
virtual Width_t GetLineWidth() const
Definition: TAttLine.h:49
virtual void SavePrimitive(std::ostream &, Option_t *)
Save primitive as a C++ statement(s) on output stream out.
Definition: TGraphNode.cxx:147