Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/candidate-6.8.0' into candidate-…
Browse files Browse the repository at this point in the history
…6.8.x

Conflicts:
	CMakeLists.txt

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
  • Loading branch information
richardkchapman committed Jun 1, 2012
2 parents a224503 + 00efc7c commit 71f2b36
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 72 deletions.
1 change: 1 addition & 0 deletions HPCCSystemsGraphViewControl/DotViewCommon.cpp
Expand Up @@ -41,6 +41,7 @@ CDotViewCommon::CDotViewCommon()
{ {
m_api = NULL; m_api = NULL;
m_g = hpcc::CreateGraph(); m_g = hpcc::CreateGraph();

m_buffer = hpcc::CreateGraphBuffer(0, 0); m_buffer = hpcc::CreateGraphBuffer(0, 0);
m_hotItem = hpcc::CreateGraphHotItem(); m_hotItem = hpcc::CreateGraphHotItem();
m_selection = hpcc::CreateGraphSelectionBag(); m_selection = hpcc::CreateGraphSelectionBag();
Expand Down
2 changes: 0 additions & 2 deletions HPCCSystemsGraphViewControl/DotViewWin.cpp
Expand Up @@ -123,8 +123,6 @@ void CDotView::OnLButtonUp(UINT nFlags, CPoint point)
m_mouseDown = MOUSEDOWN_UNKNOWN; m_mouseDown = MOUSEDOWN_UNKNOWN;
point.Offset(m_ptOffset); point.Offset(m_ptOffset);
hpcc::IGraphItem * selectedItem = m_gr->GetItemAt(point.x, point.y); hpcc::IGraphItem * selectedItem = m_gr->GetItemAt(point.x, point.y);
if (hpcc::IGraph * graph = dynamic_cast<hpcc::IGraph *>(selectedItem))
return;


bool selChanged = false; bool selChanged = false;
if (selectedItem) if (selectedItem)
Expand Down
2 changes: 0 additions & 2 deletions HPCCSystemsGraphViewControl/DotViewX11.cpp
Expand Up @@ -124,8 +124,6 @@ void CDotView::OnLButtonUp(hpcc::PointD point, guint modifierState)
m_mouseDown = MOUSEDOWN_UNKNOWN; m_mouseDown = MOUSEDOWN_UNKNOWN;
point.Offset(m_ptOffset); point.Offset(m_ptOffset);
hpcc::IGraphItem * selectedItem = m_gr->GetItemAt(point.x, point.y); hpcc::IGraphItem * selectedItem = m_gr->GetItemAt(point.x, point.y);
if (hpcc::IGraph * graph = dynamic_cast<hpcc::IGraph *>(selectedItem))
return;


bool selChanged = false; bool selChanged = false;
if (selectedItem) if (selectedItem)
Expand Down
7 changes: 7 additions & 0 deletions graphdb/GraphCluster.cpp
Expand Up @@ -75,6 +75,13 @@ void CCluster::AppendVertex(IVertex * vertex)
m_vertices.insert(vertex); m_vertices.insert(vertex);
} }


void CCluster::RemoveVertex(IVertex * vertex)
{
IVertexSet::const_iterator found = m_vertices.find(vertex);
if (found != m_vertices.end())
m_vertices.erase(found);
}

void CCluster::Walk(IClusterVisitor * visitor) void CCluster::Walk(IClusterVisitor * visitor)
{ {
for(IClusterSet::const_iterator itr = m_clusters.begin(); itr != m_clusters.end(); ++itr) for(IClusterSet::const_iterator itr = m_clusters.begin(); itr != m_clusters.end(); ++itr)
Expand Down
2 changes: 2 additions & 0 deletions graphdb/GraphCluster.h
Expand Up @@ -51,6 +51,7 @@ class CCluster : public ICluster, public CGraphItem
void AppendCluster(ICluster * cluster); void AppendCluster(ICluster * cluster);
void RemoveCluster(ICluster * cluster); void RemoveCluster(ICluster * cluster);
void AppendVertex(IVertex * vertex); void AppendVertex(IVertex * vertex);
void RemoveVertex(IVertex * vertex);


void Walk(IClusterVisitor * visitor); void Walk(IClusterVisitor * visitor);
void Walk(IVertexVisitor * visitor); void Walk(IVertexVisitor * visitor);
Expand All @@ -65,6 +66,7 @@ class CCluster : public ICluster, public CGraphItem
void AppendCluster(ICluster * cluster) { CCluster::AppendCluster(cluster); } \ void AppendCluster(ICluster * cluster) { CCluster::AppendCluster(cluster); } \
void RemoveCluster(ICluster * cluster) { CCluster::RemoveCluster(cluster); } \ void RemoveCluster(ICluster * cluster) { CCluster::RemoveCluster(cluster); } \
void AppendVertex(IVertex * vertex) { CCluster::AppendVertex(vertex); } \ void AppendVertex(IVertex * vertex) { CCluster::AppendVertex(vertex); } \
void RemoveVertex(IVertex * vertex) { CCluster::RemoveVertex(vertex); } \
void Walk(IClusterVisitor * visitor) { CCluster::Walk(visitor); } \ void Walk(IClusterVisitor * visitor) { CCluster::Walk(visitor); } \
void Walk(IVertexVisitor * visitor) { CCluster::Walk(visitor); } \ void Walk(IVertexVisitor * visitor) { CCluster::Walk(visitor); } \
bool OnlyConatinsOneCluster() const { return CCluster::OnlyConatinsOneCluster(); } \ bool OnlyConatinsOneCluster() const { return CCluster::OnlyConatinsOneCluster(); } \
Expand Down
162 changes: 116 additions & 46 deletions graphdb/GraphDB.cpp
Expand Up @@ -43,6 +43,8 @@ const char * const GraphTpl =
//"graph[ranksep=\".3\"];\r\n" //"graph[ranksep=\".3\"];\r\n"
//"graph[pad=\"0.01, 0.01\"];\r\n" //"graph[pad=\"0.01, 0.01\"];\r\n"
"graph[rankdir=\"TB\"%2%];\r\n" "graph[rankdir=\"TB\"%2%];\r\n"
"graph[remincross=true];\r\n"
"graph[mclimit=\"2.0\"];\r\n"
//"graph[sep=\"0.1\"];\r\n" //"graph[sep=\"0.1\"];\r\n"
//"graph[overlap=\"scalexy\"];\r\n" //"graph[overlap=\"scalexy\"];\r\n"
//"graph[smoothing=\"spring\"];\r\n" //"graph[smoothing=\"spring\"];\r\n"
Expand Down Expand Up @@ -154,12 +156,8 @@ void WalkClusters(const ICluster * cluster, std::string & dot, int depth)
} }
} }


const char * WriteDOT(const IGraph * graph, std::string & dot) void WalkEdges(const IGraph * graph, std::string & content)
{ {
dot.clear();
std::string content;
WalkClusters(graph, content, 0);

for(IEdgeSet::const_iterator itr = graph->GetAllEdges().begin(); itr != graph->GetAllEdges().end(); ++itr) for(IEdgeSet::const_iterator itr = graph->GetAllEdges().begin(); itr != graph->GetAllEdges().end(); ++itr)
{ {
IEdge * e = itr->get(); IEdge * e = itr->get();
Expand Down Expand Up @@ -203,6 +201,14 @@ const char * WriteDOT(const IGraph * graph, std::string & dot)
content += (boost::format(EdgeTpl) % from->GetIDString() % to->GetIDString() % e->GetIDString() % e->GetPropertyString(DOT_LABEL) % props.c_str()).str(); content += (boost::format(EdgeTpl) % from->GetIDString() % to->GetIDString() % e->GetIDString() % e->GetPropertyString(DOT_LABEL) % props.c_str()).str();
} }
} }
}

const char * WriteDOT(const IGraph * graph, std::string & dot)
{
dot.clear();
std::string content;
WalkClusters(graph, content, 0);
WalkEdges(graph, content);


std::string layout = graph->GetPropertyString(PROP_LAYOUT); std::string layout = graph->GetPropertyString(PROP_LAYOUT);
std::string props; std::string props;
Expand Down Expand Up @@ -341,63 +347,129 @@ bool decendent(const ICluster * cluster, const ICluster * item)
return decendent(cluster, item->GetParent()); return decendent(cluster, item->GetParent());
} }


const char * WriteLocalisedXGMML(const IGraph * graph, const ICluster * cluster, IGraphItemSet & addedItems, std::string & xgmml) void BuildVertexEdgeString(IEdge * e, IVertex * v, const IVertexSet & visibleVertices, IGraphItemSet & addedItems, const ICluster * cluster, std::string & clusterXgmml, std::string & externalVertices)
{ {
std::string clusterXgmml, externalVertices; if (visibleVertices.find(v) == visibleVertices.end())
clusterXgmml += (boost::format("<node id=\"%1%\"><att><graph>") % cluster->GetProperty("id")).str();
for(IVertexSet::const_iterator itr = cluster->GetVertices().begin(); itr != cluster->GetVertices().end(); ++itr)
{ {
std::string vertexStr, attrStr; if (addedItems.find(v) == addedItems.end())
BuildVertexString(itr->get(), vertexStr, false);
if (addedItems.find(itr->get()) == addedItems.end())
{ {
addedItems.insert(itr->get()); addedItems.insert(v);
clusterXgmml += vertexStr; std::string vertexStr;
BuildVertexString(v, vertexStr, true);
if (decendent(cluster, v->GetParent()))
clusterXgmml += vertexStr;
else
externalVertices += vertexStr;
} }
} }
for(IClusterSet::const_iterator itr = cluster->GetClusters().begin(); itr != cluster->GetClusters().end(); ++itr)
WriteLocalisedXGMML(graph, itr->get(), addedItems, clusterXgmml); if (addedItems.find((IGraphItem *)e) == addedItems.end())
for(IVertexSet::const_iterator v_itr = cluster->GetVertices().begin(); v_itr != cluster->GetVertices().end(); ++v_itr)
{ {
IEdgeSet inEdges = v_itr->get()->GetInEdges(); addedItems.insert((IGraphItem *)e);
for(IEdgeSet::const_iterator itr = inEdges.begin(); itr != inEdges.end(); ++itr) std::string edgeStr;
BuildEdgeString(e, edgeStr);
clusterXgmml += edgeStr;
}
}

typedef std::vector<IClusterPtr> IClusterVector;
void GetAncestors(IVertex * v, IClusterVector & ancestors)
{
ICluster * parent = v->GetParent();
while (parent)
{
ancestors.push_back(parent);
parent = parent->GetParent();
}
}

ICluster * GetCommonAncestor(IVertex * v1, IVertex * v2)
{
IClusterVector v1_ancestors, v2_ancestors;
GetAncestors(v1, v1_ancestors);
GetAncestors(v2, v2_ancestors);
IClusterVector::const_reverse_iterator finger1 = v1_ancestors.rbegin();
IClusterVector::const_reverse_iterator finger2 = v2_ancestors.rbegin();
ICluster * retVal = NULL;
while(finger1 != v1_ancestors.rend() && finger2 != v2_ancestors.rend() && finger1->get() == finger2->get()) {
retVal = finger1->get();
++finger1;
++finger2;
}
return retVal;
}

void CalcVisibility(const ICluster * rootCluster, const ICluster * cluster, IVertexSet & externalVertices, IEdgeSet & edges, std::string & content)
{
std::string childContent;
IVertexSet visibleVertices, pointVertices;
for(IVertexSet::const_iterator itr = cluster->GetVertices().begin(); itr != cluster->GetVertices().end(); ++itr)
{
IVertex * v = itr->get();
bool v_display = false;

IVertexSet adjacentVertices;
v->GetAdjacentVertices(adjacentVertices);
for(IVertexSet::const_iterator adj_itr = adjacentVertices.begin(); adj_itr != adjacentVertices.end(); ++adj_itr)
{ {
IVertex * from = itr->get()->GetFromVertex(); IVertex * v_adjacent = adj_itr->get();
if (!decendent(cluster, from->GetParent())) IEdge * e = v->GetEdge(v_adjacent);
WriteLocalisedXGMML(graph, from, addedItems, externalVertices, DIRECTION_IN, 0);


std::string edgeStr; // Both vertices are inside rootCluster and their edge crosses rootClusters white space.
BuildEdgeString(itr->get(), edgeStr); if (rootCluster == GetCommonAncestor(v, v_adjacent))
if (addedItems.find((IGraphItem *)itr->get()) == addedItems.end()) {
v_display = true;
edges.insert(e);
} // Main vertex is visible and adjacent vertex is external
else if (rootCluster == v->GetParent() && !decendent(rootCluster, v_adjacent->GetParent()))
{
v_display = true;
edges.insert(e);
externalVertices.insert(v_adjacent);
} // both vertices are within a single child cluster of root cluster
else
{ {
addedItems.insert((IGraphItem *)itr->get());
clusterXgmml += edgeStr;
} }
} }


IEdgeSet outEdges = v_itr->get()->GetOutEdges(); if (v_display)
for(IEdgeSet::const_iterator itr = outEdges.begin(); itr != outEdges.end(); ++itr)
{ {
IVertex * to = itr->get()->GetToVertex(); std::string vertexStr;
if (!decendent(cluster, to->GetParent())) BuildVertexString(v, vertexStr, v->GetParent() == rootCluster ? false : true);
WriteLocalisedXGMML(graph, to, addedItems, externalVertices, DIRECTION_OUT, 0); childContent += vertexStr;

std::string edgeStr;
BuildEdgeString(itr->get(), edgeStr);
if (addedItems.find((IGraphItem *)itr->get()) == addedItems.end())
{
addedItems.insert((IGraphItem *)itr->get());
clusterXgmml += edgeStr;
}
} }
} }
clusterXgmml += "</graph></att></node>";
xgmml += externalVertices + clusterXgmml; for(IClusterSet::const_iterator itr = cluster->GetClusters().begin(); itr != cluster->GetClusters().end(); ++itr)
return xgmml.c_str(); {
CalcVisibility(rootCluster, itr->get(), externalVertices, edges, childContent);
}

if (!childContent.empty())
{
content += (boost::format("<node id=\"%1%\"><att><graph>") % cluster->GetProperty("id")).str();
content += childContent;
content += "</graph></att></node>";
}
} }


const char * WriteLocalisedXGMML(const IGraph * graph, std::string & xgmml) const char * WriteLocalisedXGMML(const IGraph * graph, const ICluster * cluster, IGraphItemSet & addedItems, std::string & xgmml)
{ {
IVertexSet externalVertices;
IEdgeSet edges;
CalcVisibility(cluster, cluster, externalVertices, edges, xgmml);
for (IVertexSet::const_iterator itr = externalVertices.begin(); itr != externalVertices.end(); ++itr)
{
std::string vertexStr;
BuildVertexString(itr->get(), vertexStr, true);
xgmml += vertexStr;
}
for(IEdgeSet::const_iterator itr = edges.begin(); itr != edges.end(); ++itr)
{
std::string edgeStr;
BuildEdgeString(itr->get(), edgeStr);
xgmml += edgeStr;
}
return xgmml.c_str(); return xgmml.c_str();
} }


Expand All @@ -408,8 +480,6 @@ GRAPHDB_API const char * WriteLocalisedXGMML(const IGraph * graph, const IGraphI
WriteLocalisedXGMML(graph, vertex, addedItems, xgmml, DIRECTION_UNKNOWN, 3); WriteLocalisedXGMML(graph, vertex, addedItems, xgmml, DIRECTION_UNKNOWN, 3);
else if (const IEdge * edge = dynamic_cast<const IEdge *>(item)) else if (const IEdge * edge = dynamic_cast<const IEdge *>(item))
WriteLocalisedXGMML(graph, edge, addedItems, xgmml, DIRECTION_UNKNOWN, 3); WriteLocalisedXGMML(graph, edge, addedItems, xgmml, DIRECTION_UNKNOWN, 3);
else if (const IGraph * graph = dynamic_cast<const IGraph *>(item))
WriteLocalisedXGMML(graph, xgmml);
else if (const ICluster * cluster = dynamic_cast<const ICluster *>(item)) else if (const ICluster * cluster = dynamic_cast<const ICluster *>(item))
WriteLocalisedXGMML(graph, cluster, addedItems, xgmml); WriteLocalisedXGMML(graph, cluster, addedItems, xgmml);
return xgmml.c_str(); return xgmml.c_str();
Expand Down
24 changes: 19 additions & 5 deletions graphdb/GraphDB.h
Expand Up @@ -26,25 +26,34 @@
namespace hpcc namespace hpcc
{ {
// === Forward Declarations === // === Forward Declarations ===
template<typename T>
struct CompareT
{
bool operator() (const T & l, const T & r) const
{
return l->GetID() < r ->GetID();
}
};

hpcc_interface IGraphItem; hpcc_interface IGraphItem;
typedef CUnknownPtr<IGraphItem> IGraphItemPtr; typedef CUnknownPtr<IGraphItem> IGraphItemPtr;
typedef std::set<IGraphItemPtr> IGraphItemSet; typedef std::set<IGraphItemPtr, CompareT<IGraphItemPtr> > IGraphItemSet;


hpcc_interface IGraph; hpcc_interface IGraph;
typedef CUnknownPtr<IGraph> IGraphPtr; typedef CUnknownPtr<IGraph> IGraphPtr;
typedef std::set<IGraphPtr> IGraphSet; typedef std::set<IGraphPtr, CompareT<IGraphPtr> > IGraphSet;


hpcc_interface ICluster; hpcc_interface ICluster;
typedef CUnknownPtr<ICluster> IClusterPtr; typedef CUnknownPtr<ICluster> IClusterPtr;
typedef std::set<IClusterPtr> IClusterSet; typedef std::set<IClusterPtr, CompareT<IClusterPtr> > IClusterSet;


hpcc_interface IVertex; hpcc_interface IVertex;
typedef CUnknownPtr<IVertex> IVertexPtr; typedef CUnknownPtr<IVertex> IVertexPtr;
typedef std::set<IVertexPtr> IVertexSet; typedef std::set<IVertexPtr, CompareT<IVertexPtr> > IVertexSet;


hpcc_interface IEdge; hpcc_interface IEdge;
typedef CUnknownPtr<IEdge> IEdgePtr; typedef CUnknownPtr<IEdge> IEdgePtr;
typedef std::set<IEdgePtr> IEdgeSet; typedef std::set<IEdgePtr, CompareT<IEdgePtr> > IEdgeSet;


typedef std::map<std::string, std::string> StringStringMap; typedef std::map<std::string, std::string> StringStringMap;


Expand Down Expand Up @@ -115,6 +124,7 @@ hpcc_interface GRAPHDB_API ICluster : public IGraphItem
virtual void AppendCluster(ICluster * cluster) = 0; virtual void AppendCluster(ICluster * cluster) = 0;
virtual void RemoveCluster(ICluster * cluster) = 0; virtual void RemoveCluster(ICluster * cluster) = 0;
virtual void AppendVertex(IVertex * vertex) = 0; virtual void AppendVertex(IVertex * vertex) = 0;
virtual void RemoveVertex(IVertex * vertex) = 0;


virtual void Walk(IClusterVisitor * visitor) = 0; virtual void Walk(IClusterVisitor * visitor) = 0;


Expand All @@ -125,11 +135,15 @@ hpcc_interface GRAPHDB_API ICluster : public IGraphItem
hpcc_interface GRAPHDB_API IVertex : public IGraphItem hpcc_interface GRAPHDB_API IVertex : public IGraphItem
{ {
virtual ICluster * GetParent() const = 0; virtual ICluster * GetParent() const = 0;
virtual void SetParent(ICluster * cluster) = 0;
virtual unsigned int GetInEdgeCount() const = 0; virtual unsigned int GetInEdgeCount() const = 0;
virtual unsigned int GetOutEdgeCount() const = 0; virtual unsigned int GetOutEdgeCount() const = 0;
virtual const IEdgeSet & GetInEdges() const = 0; virtual const IEdgeSet & GetInEdges() const = 0;
virtual const IEdgeSet & GetOutEdges() const = 0; virtual const IEdgeSet & GetOutEdges() const = 0;


virtual unsigned int GetAdjacentVertices(IVertexSet & adjacentVertices) const = 0;
virtual IEdge * GetEdge(IVertex * adjacentVertex) const = 0;

virtual void AppendInEdge(IEdge * edge) = 0; virtual void AppendInEdge(IEdge * edge) = 0;
virtual void AppendOutEdge(IEdge * edge) = 0; virtual void AppendOutEdge(IEdge * edge) = 0;
}; };
Expand Down
2 changes: 2 additions & 0 deletions graphdb/GraphGraph.cpp
Expand Up @@ -44,6 +44,8 @@ void CGraph::Clear()
m_allItems.clear(); m_allItems.clear();
m_externalIDs.clear(); m_externalIDs.clear();
m_rexternalIDs.clear(); m_rexternalIDs.clear();
SetProperty("id", "0");
SetExternalID(hpcc::GRAPH_TYPE_CLUSTER, "0", (ICluster *)(CCluster *)this);
} }


ICluster * CGraph::CreateCluster() ICluster * CGraph::CreateCluster()
Expand Down
34 changes: 34 additions & 0 deletions graphdb/GraphVertex.cpp
Expand Up @@ -37,6 +37,13 @@ ICluster * CVertex::GetParent() const
return m_parent; return m_parent;
} }


void CVertex::SetParent(ICluster * cluster)
{
cluster->AppendVertex(this);
m_parent->RemoveVertex(this);
m_parent = cluster;
}

unsigned int CVertex::GetInEdgeCount() const unsigned int CVertex::GetInEdgeCount() const
{ {
return m_inEdges.size(); return m_inEdges.size();
Expand All @@ -57,6 +64,33 @@ const IEdgeSet & CVertex::GetOutEdges() const
return m_outEdges; return m_outEdges;
} }


unsigned int CVertex::GetAdjacentVertices(IVertexSet & adjacentVertices) const
{
for(IEdgeSet::const_iterator itr = m_inEdges.begin(); itr != m_inEdges.end(); ++itr)
adjacentVertices.insert(itr->get()->GetFromVertex());

for(IEdgeSet::const_iterator itr = m_outEdges.begin(); itr != m_outEdges.end(); ++itr)
adjacentVertices.insert(itr->get()->GetToVertex());

return adjacentVertices.size();
}

IEdge * CVertex::GetEdge(IVertex * adjacentVertex) const
{
for(IEdgeSet::const_iterator itr = m_inEdges.begin(); itr != m_inEdges.end(); ++itr)
{
if (adjacentVertex == itr->get()->GetFromVertex())
return itr->get();
}

for(IEdgeSet::const_iterator itr = m_outEdges.begin(); itr != m_outEdges.end(); ++itr)
{
if (adjacentVertex == itr->get()->GetToVertex())
return itr->get();
}
return NULL;
}

void CVertex::AppendInEdge(IEdge * edge) void CVertex::AppendInEdge(IEdge * edge)
{ {
m_inEdges.insert(edge); m_inEdges.insert(edge);
Expand Down

0 comments on commit 71f2b36

Please sign in to comment.