00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00024
00025
00026
00027
00028
00029
00030
00031 TGraphEdge::TGraphEdge(): TObject(), TAttLine()
00032 {
00033
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
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
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
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
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
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
00135
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
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
00157 fX = new Double_t[nb];
00158 fY = new Double_t[nb];
00159
00160
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
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
00197 n = fN[i];
00198 graph.PaintGraph(n, &fX[a], &fY[a], "L");
00199
00200
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
00212 }
00213
00214
00215 void TGraphEdge::SaveAttributes(ostream &out, const char* name)
00216 {
00217
00218
00219
00220 SaveLineAttributes(out,name,1,1,1);
00221 }
00222
00223
00224
00225 void TGraphEdge::Streamer(TBuffer &)
00226 {
00227 }