Skip to content
Snippets Groups Projects
Commit 98ce920f authored by Olivier Couet's avatar Olivier Couet
Browse files

- Implement SavePrimitives(). A pad containing a TGraphStruct can be saved as

  a C file.


git-svn-id: http://root.cern.ch/svn/root/trunk@30177 27541ba8-7e3a-0410-8455-c3a389f83636
parent d3dce3c5
Branches
Tags
No related merge requests found
...@@ -59,8 +59,11 @@ public: ...@@ -59,8 +59,11 @@ public:
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py); virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
void SetGVEdge(Agedge_t *gve) {fGVEdge = gve;} void SetGVEdge(Agedge_t *gve) {fGVEdge = gve;}
Agedge_t *GetGVEdge() {return fGVEdge;} Agedge_t *GetGVEdge() {return fGVEdge;}
TGraphNode *GetNode1() {return fNode1;}
TGraphNode *GetNode2() {return fNode2;}
void Layout(); void Layout();
virtual void Paint(Option_t *option=""); virtual void Paint(Option_t *option="");
virtual void SavePrimitive(ostream &, Option_t *);
ClassDef(TGraphEdge,1) //Graph edge class ClassDef(TGraphEdge,1) //Graph edge class
}; };
......
...@@ -65,6 +65,7 @@ public: ...@@ -65,6 +65,7 @@ public:
Agnode_t *GetGVNode() {return fGVNode;} Agnode_t *GetGVNode() {return fGVNode;}
void Layout(); void Layout();
virtual void Paint(Option_t *option=""); virtual void Paint(Option_t *option="");
virtual void SavePrimitive(ostream &, Option_t *);
ClassDef(TGraphNode,1) //Graph node class ClassDef(TGraphNode,1) //Graph node class
}; };
......
...@@ -37,7 +37,7 @@ struct GVC_s; ...@@ -37,7 +37,7 @@ struct GVC_s;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
class TGraphStruct { class TGraphStruct : public TObject {
protected: protected:
...@@ -52,16 +52,17 @@ public: ...@@ -52,16 +52,17 @@ public:
TGraphStruct(); TGraphStruct();
virtual ~TGraphStruct(); virtual ~TGraphStruct();
void AddEdge(TGraphEdge *edge); void AddEdge(TGraphEdge *edge);
void AddNode(TGraphNode *node); void AddNode(TGraphNode *node);
TGraphEdge *AddEdge(TGraphNode *n1, TGraphNode *n2); TGraphEdge *AddEdge(TGraphNode *n1, TGraphNode *n2);
TGraphNode *AddNode(const char *name, const char *title=""); TGraphNode *AddNode(const char *name, const char *title="");
void Draw(Option_t *option=""); void Draw(Option_t *option="");
void DumpAsDotFile(const char *filename); void DumpAsDotFile(const char *filename);
TList *GetListOfNodes() const { return fNodes; } TList *GetListOfNodes() const { return fNodes; }
TList *GetListOfEdges() const { return fEdges; } TList *GetListOfEdges() const { return fEdges; }
void Layout(); void Layout();
void SetMargin(Double_t m=10) {fMargin = m;} virtual void SavePrimitive(ostream &out, Option_t *option = "");
void SetMargin(Double_t m=10) {fMargin = m;}
ClassDef(TGraphStruct,1) //Graph structure class ClassDef(TGraphStruct,1) //Graph structure class
}; };
......
...@@ -203,6 +203,13 @@ void TGraphEdge::Paint(Option_t *) ...@@ -203,6 +203,13 @@ void TGraphEdge::Paint(Option_t *)
} }
//______________________________________________________________________________
void TGraphEdge::SavePrimitive(ostream &, Option_t *)
{
// Save primitive as a C++ statement(s) on output stream out
}
//______________________________________________________________________________ //______________________________________________________________________________
void TGraphEdge::Streamer(TBuffer &/*b*/) void TGraphEdge::Streamer(TBuffer &/*b*/)
{ {
......
...@@ -76,10 +76,14 @@ Int_t TGraphNode::DistancetoPrimitive(Int_t px, Int_t py) ...@@ -76,10 +76,14 @@ Int_t TGraphNode::DistancetoPrimitive(Int_t px, Int_t py)
{ {
// Compute distance from point px,py to a node. // Compute distance from point px,py to a node.
Int_t dist;
// The node is drawn as an ellipse
TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.); TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
ellipse.SetFillStyle(1001); ellipse.SetFillColor(1); // in order to pick the ellipse "inside"
ellipse.SetFillColor(2); dist = ellipse.DistancetoPrimitive(px, py);
return ellipse.DistancetoPrimitive(px, py);
return dist;
} }
...@@ -125,7 +129,7 @@ void TGraphNode::Paint(Option_t *) ...@@ -125,7 +129,7 @@ void TGraphNode::Paint(Option_t *)
TLatex text; TLatex text;
text.SetTextAlign(22); text.SetTextAlign(22);
// Draw the node shape // Draw the node shape as an ellipse
// ND_shape(fGVNode)->name gives the type of shape. // ND_shape(fGVNode)->name gives the type of shape.
ellipse.SetFillStyle(GetFillStyle()); ellipse.SetFillStyle(GetFillStyle());
ellipse.SetFillColor(GetFillColor()); ellipse.SetFillColor(GetFillColor());
...@@ -134,13 +138,20 @@ void TGraphNode::Paint(Option_t *) ...@@ -134,13 +138,20 @@ void TGraphNode::Paint(Option_t *)
ellipse.SetLineWidth(GetLineWidth()); ellipse.SetLineWidth(GetLineWidth());
ellipse.PaintEllipse(fX, fY, fW, fH, 0., 360., 0., ""); ellipse.PaintEllipse(fX, fY, fW, fH, 0., 360., 0., "");
// Draw the node name // Draw the node title
text.SetTextColor(GetTextColor()); text.SetTextColor(GetTextColor());
text.SetTextFont(GetTextFont()); text.SetTextFont(GetTextFont());
text.PaintLatex(fX, fY, 0., GetTextSize(), (char*)GetTitle()); text.PaintLatex(fX, fY, 0., GetTextSize(), (char*)GetTitle());
} }
//______________________________________________________________________________
void TGraphNode::SavePrimitive(ostream &, Option_t *)
{
// Save primitive as a C++ statement(s) on output stream out
}
//______________________________________________________________________________ //______________________________________________________________________________
void TGraphNode::Streamer(TBuffer &/*b*/) void TGraphNode::Streamer(TBuffer &/*b*/)
{ {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* For the list of contributors see $ROOTSYS/README/CREDITS. * * For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/ *************************************************************************/
#include "Riostream.h"
#include "TPad.h" #include "TPad.h"
#include "TGraphStruct.h" #include "TGraphStruct.h"
...@@ -127,7 +128,7 @@ void TGraphStruct::DumpAsDotFile(const char *filename) ...@@ -127,7 +128,7 @@ void TGraphStruct::DumpAsDotFile(const char *filename)
//______________________________________________________________________________ //______________________________________________________________________________
void TGraphStruct::Draw(Option_t */*option*/) void TGraphStruct::Draw(Option_t *option)
{ {
// Draw the graph // Draw the graph
...@@ -139,22 +140,28 @@ void TGraphStruct::Draw(Option_t */*option*/) ...@@ -139,22 +140,28 @@ void TGraphStruct::Draw(Option_t */*option*/)
GD_bb(fGVGraph).UR.x+fMargin, GD_bb(fGVGraph).UR.y+fMargin); GD_bb(fGVGraph).UR.x+fMargin, GD_bb(fGVGraph).UR.y+fMargin);
} }
AppendPad(option);
// Draw the nodes // Draw the nodes
TGraphNode *node; if (fNodes) {
node = (TGraphNode*) fNodes->First(); TGraphNode *node;
node->Draw(); node = (TGraphNode*) fNodes->First();
for(Int_t i = 1; i < fNodes->GetSize(); i++){
node = (TGraphNode*)fNodes->After(node);
node->Draw(); node->Draw();
for(Int_t i = 1; i < fNodes->GetSize(); i++){
node = (TGraphNode*)fNodes->After(node);
node->Draw();
}
} }
// Draw the edges // Draw the edges
TGraphEdge *edge; if (fEdges) {
edge = (TGraphEdge*) fEdges->First(); TGraphEdge *edge;
edge->Draw(); edge = (TGraphEdge*) fEdges->First();
for(Int_t i = 1; i < fEdges->GetSize(); i++){
edge = (TGraphEdge*)fEdges->After(edge);
edge->Draw(); edge->Draw();
for(Int_t i = 1; i < fEdges->GetSize(); i++){
edge = (TGraphEdge*)fEdges->After(edge);
edge->Draw();
}
} }
} }
...@@ -179,39 +186,88 @@ void TGraphStruct::Layout() ...@@ -179,39 +186,88 @@ void TGraphStruct::Layout()
fGVGraph = agopen((char*)"GVGraph", AGDIGRAPH); fGVGraph = agopen((char*)"GVGraph", AGDIGRAPH);
// Put the GV nodes into the GV graph // Put the GV nodes into the GV graph
node = (TGraphNode*) fNodes->First(); if (fNodes) {
node->CreateGVNode(fGVGraph); node = (TGraphNode*) fNodes->First();
for(Int_t i = 1; i < fNodes->GetSize(); i++){
node = (TGraphNode*)fNodes->After(node);
node->CreateGVNode(fGVGraph); node->CreateGVNode(fGVGraph);
for(Int_t i = 1; i < fNodes->GetSize(); i++){
node = (TGraphNode*)fNodes->After(node);
node->CreateGVNode(fGVGraph);
}
} }
// Put the edges into the graph // Put the edges into the graph
edge = (TGraphEdge*) fEdges->First(); if (fEdges) {
edge->CreateGVEdge(fGVGraph); edge = (TGraphEdge*) fEdges->First();
for(Int_t i = 1; i < fEdges->GetSize(); i++){
edge = (TGraphEdge*)fEdges->After(edge);
edge->CreateGVEdge(fGVGraph); edge->CreateGVEdge(fGVGraph);
for(Int_t i = 1; i < fEdges->GetSize(); i++){
edge = (TGraphEdge*)fEdges->After(edge);
edge->CreateGVEdge(fGVGraph);
}
} }
// Layout the graph // Layout the graph
gvLayout(fGVC, fGVGraph, (char*)"dot"); gvLayout(fGVC, fGVGraph, (char*)"dot");
// Layout the nodes // Layout the nodes
node = (TGraphNode*) fNodes->First(); if (fNodes) {
node->Layout(); node = (TGraphNode*) fNodes->First();
for(Int_t i = 1; i < fNodes->GetSize(); i++){
node = (TGraphNode*)fNodes->After(node);
node->Layout(); node->Layout();
for(Int_t i = 1; i < fNodes->GetSize(); i++){
node = (TGraphNode*)fNodes->After(node);
node->Layout();
}
} }
// Layout the edges // Layout the edges
edge = (TGraphEdge*) fEdges->First(); if (fEdges) {
edge->Layout(); edge = (TGraphEdge*) fEdges->First();
for(Int_t i = 1; i < fEdges->GetSize(); i++){
edge = (TGraphEdge*)fEdges->After(edge);
edge->Layout(); edge->Layout();
for(Int_t i = 1; i < fEdges->GetSize(); i++){
edge = (TGraphEdge*)fEdges->After(edge);
edge->Layout();
}
}
}
//______________________________________________________________________________
void TGraphStruct::SavePrimitive(ostream &out, Option_t * /*= ""*/)
{
// Save primitive as a C++ statement(s) on output stream out
out<<" TGraphStruct *graphstruct = new TGraphStruct();"<<endl;
// Save the nodes
if (fNodes) {
TGraphNode *node;
node = (TGraphNode*) fNodes->First();
out<<" TGraphNode *"<<node->GetName()<<" = graphstruct->AddNode(\""<<
node->GetName()<<"\",\""<<
node->GetTitle()<<"\");"<<endl;
for(Int_t i = 1; i < fNodes->GetSize(); i++){
node = (TGraphNode*)fNodes->After(node);
out<<" TGraphNode *"<<node->GetName()<<" = graphstruct->AddNode(\""<<
node->GetName()<<"\",\""<<
node->GetTitle()<<"\");"<<endl;
}
} }
// Save the edges
if (fEdges) {
TGraphEdge *edge;
edge = (TGraphEdge*) fEdges->First();
out<<" graphstruct->AddEdge("<<
edge->GetNode1()->GetName()<<","<<
edge->GetNode2()->GetName()<<");"<<endl;
for(Int_t i = 1; i < fEdges->GetSize(); i++){
edge = (TGraphEdge*)fEdges->After(edge);
out<<" graphstruct->AddEdge("<<
edge->GetNode1()->GetName()<<","<<
edge->GetNode2()->GetName()<<");"<<endl;
}
}
out<<" graphstruct->Draw();"<<endl;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment