TGraphNode.cxx

Go to the documentation of this file.
00001 // @(#)root/hist:$Id: TGraphNode.cxx 30240 2009-09-18 08:16:59Z couet $
00002 // Author: Olivier Couet 13/07/09
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TLatex.h"
00013 #include "TEllipse.h"
00014 #include "TGraphNode.h"
00015 
00016 #include <gvc.h>
00017 
00018 ClassImp(TGraphNode)
00019 
00020 //______________________________________________________________________________
00021 /* Begin_Html
00022 <center><h2>Graph Node class</h2></center>
00023 TGraphNode is a graph node object which can be added in a TGraphStruct.
00024 End_Html */
00025 
00026 
00027 //______________________________________________________________________________
00028 TGraphNode::TGraphNode(): TNamed(), TAttText()
00029 {
00030    // Graph node default constructor.
00031 
00032    fGVNode = 0;
00033    fX      = 0;
00034    fY      = 0;
00035    fW      = 0;
00036    fH      = 0;
00037 }
00038 
00039 
00040 //______________________________________________________________________________
00041 TGraphNode::TGraphNode(const char *name,const char *title)
00042            :TNamed(name,title), TAttText()
00043 {
00044    // Graph node normal constructor.
00045 
00046    fGVNode = 0;
00047    fX      = 0;
00048    fY      = 0;
00049    fW      = 0;
00050    fH      = 0;
00051 }
00052 
00053 
00054 //______________________________________________________________________________
00055 TGraphNode::~TGraphNode()
00056 {
00057    // Graph Node default destructor.
00058    
00059 }
00060 
00061 
00062 //______________________________________________________________________________
00063 void TGraphNode::CreateGVNode(Agraph_t *gv)
00064 {
00065    // Create the GraphViz node into the GraphViz data structure gv.
00066 
00067    if (gv) {
00068       fGVNode = agnode(gv, (char *)GetName());
00069    } else {
00070       Error("CreateGVNode","Invalid graphviz graph");
00071    }
00072 }
00073 
00074 
00075 //______________________________________________________________________________
00076 Int_t TGraphNode::DistancetoPrimitive(Int_t px, Int_t py)
00077 {
00078    // Compute distance from point px,py to a node.
00079 
00080    Int_t dist;
00081 
00082    // The node is drawn as an ellipse
00083    TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
00084    ellipse.SetFillColor(1); // in order to pick the ellipse "inside"
00085    dist =  ellipse.DistancetoPrimitive(px, py);
00086 
00087    return dist;
00088 }
00089 
00090 
00091 //______________________________________________________________________________
00092 void TGraphNode::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00093 {
00094    // Execute action corresponding to one event.
00095    
00096    TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
00097    ellipse.ExecuteEvent(event,px, py);
00098    fX = ellipse.GetX1();
00099    fY = ellipse.GetY1();
00100    fW = ellipse.GetR1();
00101    fH = ellipse.GetR2();
00102 }
00103 
00104 
00105 //______________________________________________________________________________
00106 void TGraphNode::Layout()
00107 {
00108    // Layout this node in the GraphViz space. This is done after gvLayout
00109    // has been performed.
00110 
00111 #ifdef ND_coord
00112    fX = ND_coord(fGVNode).x;
00113    fY = ND_coord(fGVNode).y;
00114 #endif
00115 #ifdef ND_coord_i
00116    fX = ND_coord_i(fGVNode).x;
00117    fY = ND_coord_i(fGVNode).y;
00118 #endif
00119    fW = ND_width(fGVNode)*36;
00120    fH = ND_height(fGVNode)*36;
00121 }
00122 
00123 
00124 //______________________________________________________________________________
00125 void TGraphNode::Paint(Option_t *)
00126 {
00127    // Paint this node with its current attributes.
00128 
00129    TEllipse ellipse;
00130    TLatex text;
00131    text.SetTextAlign(22);
00132 
00133    // Draw the node shape as an ellipse
00134    // ND_shape(fGVNode)->name gives the type of shape.
00135    ellipse.SetFillStyle(GetFillStyle());
00136    ellipse.SetFillColor(GetFillColor());
00137    ellipse.SetLineColor(GetLineColor());
00138    ellipse.SetLineStyle(GetLineStyle());
00139    ellipse.SetLineWidth(GetLineWidth());
00140    ellipse.PaintEllipse(fX, fY, fW, fH, 0., 360., 0., "");
00141    
00142    // Draw the node title
00143    text.SetTextColor(GetTextColor());
00144    text.SetTextFont(GetTextFont());
00145    text.PaintLatex(fX, fY, 0., GetTextSize(), (char*)GetTitle());
00146 }
00147 
00148 
00149 //______________________________________________________________________________
00150 void TGraphNode::SavePrimitive(ostream &, Option_t *)
00151 {
00152    // Save primitive as a C++ statement(s) on output stream out
00153 }
00154 
00155 
00156 //______________________________________________________________________________
00157 void TGraphNode::SaveAttributes(ostream &out)
00158 {
00159    // Save attributes as a C++ statement(s) on output stream out
00160    // called by TGraphStruct::SavePrimitive.
00161 
00162    SaveFillAttributes(out,GetName(),0,1001);
00163    SaveLineAttributes(out,GetName(),1,1,1);
00164    SaveTextAttributes(out,GetName(),0,0,0,0,0);
00165 }
00166 
00167 //______________________________________________________________________________
00168 void TGraphNode::Streamer(TBuffer &/*b*/)
00169 {
00170 }

Generated on Tue Jul 5 14:14:29 2011 for ROOT_528-00b_version by  doxygen 1.5.1