TGraphEdge.cxx

Go to the documentation of this file.
00001 // @(#)root/hist:$Id: TGraphEdge.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 "TGraph.h"
00013 #include "TArrow.h"
00014 #include "TPolyLine.h"
00015 #include "TGraphEdge.h"
00016 #include "TGraphNode.h"  
00017 
00018 #include <gvc.h>
00019 
00020 ClassImp(TGraphEdge)
00021 
00022 //______________________________________________________________________________
00023 /* Begin_Html
00024 <center><h2>Graph Edge class</h2></center>
00025 TGraphEdge is an edge object connecting two nodes which can be added in a
00026 TGraphStruct.
00027 End_Html */
00028 
00029 
00030 //______________________________________________________________________________
00031 TGraphEdge::TGraphEdge(): TObject(), TAttLine()
00032 {
00033    // Graph Edge default constructor.
00034 
00035    fNode1  = 0;
00036    fNode2  = 0;
00037    fGVEdge = 0;
00038    fX      = 0;
00039    fY      = 0;
00040    fN      = 0;
00041    fArrX   = 0;
00042    fArrY   = 0;
00043 }
00044 
00045 
00046 //______________________________________________________________________________
00047 TGraphEdge::TGraphEdge(TGraphNode *n1, TGraphNode *n2)
00048            :TObject(), TAttLine()
00049 {
00050    // Graph Edge normal constructor.
00051 
00052    fNode1  = n1;
00053    fNode2  = n2;
00054    fGVEdge = 0;
00055    fX      = 0;
00056    fY      = 0;
00057    fN      = 0;
00058    fArrX   = 0;
00059    fArrY   = 0;
00060 }
00061 
00062 
00063 //______________________________________________________________________________
00064 TGraphEdge::~TGraphEdge()
00065 {
00066    // Graph Edge default destructor.
00067 
00068    if (fNode1) delete fNode1;
00069    if (fNode2) delete fNode2;
00070    if (fX) delete [] fX; fX = 0;
00071    if (fY) delete [] fY; fY = 0;
00072    if (fN) delete [] fN; fN = 0;
00073 }
00074 
00075 
00076 //______________________________________________________________________________
00077 void TGraphEdge::CreateGVEdge(Agraph_t *gv)
00078 {
00079    // Create the GraphViz edge into the GraphViz data structure gv.           
00080 
00081    if (gv) {
00082       Agnode_t *n1 = fNode1->GetGVNode();
00083       Agnode_t *n2 = fNode2->GetGVNode();
00084       fGVEdge = agedge(gv, n1, n2);
00085    } else {
00086       Error("CreateGVEdge","Invalid graphviz graph");
00087    }
00088 }
00089 
00090 
00091 //______________________________________________________________________________
00092 Int_t TGraphEdge::DistancetoPrimitive(Int_t px, Int_t py)
00093 {
00094    // Compute distance from point px,py to an edge.
00095 
00096    Int_t i,n,a,dist=999;
00097    
00098    TPolyLine *polyline;
00099    a = 0;
00100 
00101    for (i=1; i<=fN[0]; i++) {
00102       n = fN[i];
00103       polyline = new TPolyLine(n, &fX[a], &fY[a], "L");
00104       dist = polyline->DistancetoPrimitive(px, py);
00105       a = a+n;
00106    }
00107 
00108    return dist;
00109 }
00110 
00111 
00112 //______________________________________________________________________________
00113 void TGraphEdge::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00114 {
00115    // Execute action corresponding to one event.
00116 
00117    Int_t i,n,a;
00118 
00119    TPolyLine *polyline;
00120    a = 0;
00121 
00122    for (i=1; i<=fN[0]; i++) {
00123       n = fN[i];
00124       polyline = new TPolyLine(n, &fX[a], &fY[a], "L");
00125       polyline->ExecuteEvent(event, px, py);
00126       a = a+n;
00127    }
00128 }
00129 
00130 
00131 //______________________________________________________________________________
00132 void TGraphEdge::Layout()
00133 {
00134    // Layout this edge in the GraphViz space. This is done after gvLayout
00135    // has been performed.
00136 
00137    bezier bz;
00138    Int_t i,j;
00139 
00140    if (fX) delete [] fX; fX = 0;
00141    if (fY) delete [] fY; fY = 0;
00142    if (fN) delete [] fN; fN = 0;
00143 
00144    Int_t np = ED_spl(fGVEdge)->size;
00145    fN       = new Int_t[np+1];
00146    fN[0]    = np;
00147    Int_t nb = 0;
00148 
00149    // Compute the total size of the splines arrays
00150    for (i=0; i<np; i++) {
00151       bz      = ED_spl(fGVEdge)->list[i];
00152       fN[i+1] = bz.size;
00153       nb      = nb+fN[i+1];
00154    }
00155 
00156    // Create the vectors holding all the splines' points.
00157    fX = new Double_t[nb];
00158    fY = new Double_t[nb];
00159 
00160    // Fill the vectors with the splines' points.
00161    Int_t k=0;
00162    for (i=0; i<np; i++) {
00163       bz    = ED_spl(fGVEdge)->list[i];
00164       fArrX =  bz.ep.x;
00165       fArrY =  bz.ep.y;
00166       for (j=0; j<fN[i+1]; j++) {
00167          fX[k] = bz.list[j].x;
00168          fY[k] = bz.list[j].y;
00169          k++;
00170       }
00171    }
00172 }
00173 
00174 
00175 //______________________________________________________________________________
00176 void TGraphEdge::Paint(Option_t *)
00177 {
00178    // Paint this edge with its current attributes.
00179 
00180    Int_t i,n,a;
00181 
00182    TArrow arrow;
00183    TGraph graph;
00184 
00185    graph.SetLineColor(GetLineColor());
00186    graph.SetLineStyle(GetLineStyle());
00187    graph.SetLineWidth(GetLineWidth());
00188    arrow.SetAngle(38);
00189    arrow.SetFillColor(GetLineColor());
00190    arrow.SetLineColor(GetLineColor());
00191 
00192    a = 0;
00193 
00194    for (i=1; i<=fN[0]; i++) {
00195 
00196       // Draw the edge body
00197       n = fN[i];
00198       graph.PaintGraph(n, &fX[a], &fY[a], "L");
00199 
00200       // Draw the edge arrow
00201       arrow.PaintArrow(fX[a+n-1], fY[a+n-1], fArrX, fArrY, 0.03, "|>");
00202 
00203       a = a+n;
00204    }
00205 }
00206 
00207 
00208 //______________________________________________________________________________
00209 void TGraphEdge::SavePrimitive(ostream &, Option_t *)
00210 {
00211    // Save primitive as a C++ statement(s) on output stream out   
00212 }
00213 
00214 //______________________________________________________________________________
00215 void TGraphEdge::SaveAttributes(ostream &out, const char* name)
00216 {
00217    // Save attributes as a C++ statement(s) on output stream out
00218    // called by TGraphStruct::SavePrimitive.
00219                
00220    SaveLineAttributes(out,name,1,1,1);
00221 }
00222 
00223 
00224 //______________________________________________________________________________
00225 void TGraphEdge::Streamer(TBuffer &/*b*/)
00226 {
00227 }

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