Logo ROOT   6.10/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 * GetName() const
Returns name of object.
Definition: TNamed.h:47
void CreateGVNode(GVizAgraph_t *gv)
Create the GraphViz node into the GraphViz data structure gv.
Definition: TGraphNode.cxx:61
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
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 Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:34
const char Option_t
Definition: RtypesCore.h:62
Double_t GetY1() const
Definition: TEllipse.h:50
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
GVizAgnode_t * fGVNode
Graphviz node.
Definition: TGraphNode.h:33
Double_t GetR2() const
Definition: TEllipse.h:52
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)
Set the fill area style.
Definition: TAttFill.h:39
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
Double_t fY
Node&#39;s center Y coordinate.
Definition: TGraphNode.h:35
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:34
TGraphNode()
Graph node default constructor.
Definition: TGraphNode.cxx:29
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:260
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:36
To draw Mathematical Formula.
Definition: TLatex.h:18
void Layout()
Layout this node in the GraphViz space.
Definition: TGraphNode.cxx:106
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition: TLatex.cxx:2042
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
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:347
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:35
Text Attributes class.
Definition: TAttText.h:18
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:232
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
virtual void Paint(Option_t *option="")
Paint this node with its current attributes.
Definition: TGraphNode.cxx:123
Double_t fW
Node width.
Definition: TGraphNode.h:37
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
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:336
A graph node object which can be added in a TGraphStruct.
Definition: TGraphNode.h:27
TText * text
Double_t fH
Node height.
Definition: TGraphNode.h:36
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
Double_t GetX1() const
Definition: TEllipse.h:49
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:24
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
Double_t fX
Node&#39;s center X coordinate.
Definition: TGraphNode.h:34
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Double_t GetR1() const
Definition: TEllipse.h:51
virtual void SavePrimitive(std::ostream &, Option_t *)
Save primitive as a C++ statement(s) on output stream out.
Definition: TGraphNode.cxx:147