Logo ROOT   6.18/05
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
23A 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
41TGraphNode::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
61void 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
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
147void 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
155void 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
164void TGraphNode::Streamer(TBuffer &/*b*/)
165{
166}
int Int_t
Definition: RtypesCore.h:41
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
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:234
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:34
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:262
Text Attributes class.
Definition: TAttText.h:18
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:36
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:35
virtual Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:34
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
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
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
Draw Ellipses.
Definition: TEllipse.h:24
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:526
Double_t GetX1() const
Definition: TEllipse.h:49
Double_t GetR2() const
Definition: TEllipse.h:52
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to an ellipse.
Definition: TEllipse.cxx:131
Double_t GetR1() const
Definition: TEllipse.h:51
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TEllipse.cxx:197
Double_t GetY1() const
Definition: TEllipse.h:50
A graph node object which can be added in a TGraphStruct.
Definition: TGraphNode.h:27
GVizAgnode_t * fGVNode
Graphviz node.
Definition: TGraphNode.h:33
Double_t fY
Node's center Y coordinate.
Definition: TGraphNode.h:35
Double_t fW
Node width.
Definition: TGraphNode.h:37
Double_t fH
Node height.
Definition: TGraphNode.h:36
void SaveAttributes(std::ostream &)
Save attributes as a C++ statement(s) on output stream out called by TGraphStruct::SavePrimitive.
Definition: TGraphNode.cxx:155
virtual void Paint(Option_t *option="")
Paint this node with its current attributes.
Definition: TGraphNode.cxx:123
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a node.
Definition: TGraphNode.cxx:77
virtual void SavePrimitive(std::ostream &, Option_t *)
Save primitive as a C++ statement(s) on output stream out.
Definition: TGraphNode.cxx:147
Double_t fX
Node's center X coordinate.
Definition: TGraphNode.h:34
TGraphNode()
Graph node default constructor.
Definition: TGraphNode.cxx:29
virtual ~TGraphNode()
Graph Node default destructor.
Definition: TGraphNode.cxx:54
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TGraphNode.cxx:92
void CreateGVNode(GVizAgraph_t *gv)
Create the GraphViz node into the GraphViz data structure gv.
Definition: TGraphNode.cxx:61
void Layout()
Layout this node in the GraphViz space.
Definition: TGraphNode.cxx:106
To draw Mathematical Formula.
Definition: TLatex.h:18
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
TText * text
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48