DependencyGraph: grouping & unflatten is optional

Property group "User parameter:BaseApp/Preferences/DependencyGraph" has two booleans to enable subgraphing and unflatten (by default on): "Unflatten", "GeoFeatureSubgraphs"
This commit is contained in:
Stefan Tröger
2017-01-31 07:22:14 +01:00
committed by wmayer
parent 25df3c549d
commit bbabe833e9
2 changed files with 94 additions and 53 deletions

View File

@@ -325,20 +325,22 @@ void Document::exportGraphviz(std::ostream& out) const
/**
* @brief addExpressionSubgraphIfNeeded Add a subgraph to the main graph if it is needed, i.e there are defined at least one expression in hte
* document object, or other objects are referencing properties in it.
* @param obj DocumentObject to assess.
* @param CSSubgraphs Boolean if the GeoFeatureGroups are created as subgraphs
*/
void addExpressionSubgraphIfNeeded(DocumentObject * obj) {
//coordinate systems already have a subgraph
*/
void addExpressionSubgraphIfNeeded(DocumentObject * obj, bool CSsubgraphs) {
boost::unordered_map<const App::ObjectIdentifier, const PropertyExpressionEngine::ExpressionInfo> expressions = obj->ExpressionEngine.getExpressions();
if (expressions.size() > 0) {
if (expressions.size() > 0) {
Graph* graph;
if(CSsubgraphs) {
auto group = GeoFeatureGroupExtension::getGroupOfObject(obj);
graph = group ? GraphList[group] : &DepList;
}
else
graph = &DepList;
@@ -359,7 +361,15 @@ void Document::exportGraphviz(std::ostream& out) const
while (j != deps.end()) {
DocumentObject * o = j->getDocumentObject();
// Doesn't exist already?
// Doesn't exist already?
if (!GraphList[o]) {
if(CSsubgraphs) {
auto group = GeoFeatureGroupExtension::getGroupOfObject(o);
auto graph2 = group ? GraphList[group] : &DepList;
GraphList[o] = &graph2->create_subgraph();
}
else
GraphList[o] = &graph->create_subgraph();
setGraphAttributes(o);
@@ -375,7 +385,7 @@ void Document::exportGraphviz(std::ostream& out) const
* @brief add Add @docObj to the graph, including all expressions (and dependencies) it includes.
* @param docObj The document object to add.
* @param name Name of node.
*/
*/
void add(DocumentObject * docObj, const std::string & name, const std::string & label, bool CSSubgraphs) {
@@ -384,15 +394,17 @@ void Document::exportGraphviz(std::ostream& out) const
return;
//find the correct graph to add the vertex too. Check first expressions graphs, afterwards
//the parent CS and origin graphs
Graph * sgraph = GraphList[docObj];
if(!sgraph) {
auto group = GeoFeatureGroupExtension::getGroupOfObject(docObj);
//the parent CS and origin graphs
Graph * sgraph = GraphList[docObj];
if(CSSubgraphs) {
if(!sgraph) {
auto group = GeoFeatureGroupExtension::getGroupOfObject(docObj);
if(group)
sgraph = GraphList[group];
}
if(!sgraph) {
if(docObj->isDerivedFrom(OriginFeature::getClassTypeId()))
sgraph = GraphList[static_cast<OriginFeature*>(docObj)->getOrigin()];
sgraph = GraphList[group];
}
if(!sgraph) {
if(docObj->isDerivedFrom(OriginFeature::getClassTypeId()))
}
}
if(!sgraph)
@@ -500,15 +512,20 @@ void Document::exportGraphviz(std::ostream& out) const
}
}
void addSubgraphs() {
//first build up the coordinate system subgraphs
for (auto objectIt : d->objectArray) {
void addSubgraphs() {
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DependencyGraph");
bool CSSubgraphs = depGrp->GetBool("GeoFeatureSubgraphs", true);
if(CSSubgraphs) {
//first build up the coordinate system subgraphs
for (auto objectIt : d->objectArray) {
if (objectIt->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId()) && objectIt->getInList().empty())
recursiveCSSubgraphs(objectIt, nullptr);
}
}
// Internal document objects
// Internal document objects
for (std::map<std::string,DocumentObject*>::const_iterator It = d->objectMap.begin(); It != d->objectMap.end();++It)
addExpressionSubgraphIfNeeded(It->second, CSSubgraphs);
@@ -518,7 +535,7 @@ void Document::exportGraphviz(std::ostream& out) const
for (std::vector<DocumentObject*>::const_iterator It2=OutList.begin();It2!=OutList.end();++It2) {
if (*It2) {
std::map<std::string,Vertex>::const_iterator item = GlobalVertexList.find(getId(*It2));
if (item == GlobalVertexList.end())
addExpressionSubgraphIfNeeded(*It2, CSSubgraphs);
}
@@ -526,9 +543,13 @@ void Document::exportGraphviz(std::ostream& out) const
}
}
// Filling up the adjacency List
void buildAdjacencyList() {
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DependencyGraph");
bool CSSubgraphs = depGrp->GetBool("GeoFeatureSubgraphs", true);
// Add internal document objects
// Add internal document objects
for (std::map<std::string,DocumentObject*>::const_iterator It = d->objectMap.begin(); It != d->objectMap.end();++It)
add(It->second, It->second->getNameInDocument(), It->second->Label.getValue(), CSSubgraphs);
@@ -540,7 +561,8 @@ void Document::exportGraphviz(std::ostream& out) const
std::map<std::string,Vertex>::const_iterator item = GlobalVertexList.find(getId(*It2));
if (item == GlobalVertexList.end())
add(*It2,
add(*It2,
std::string((*It2)->getDocument()->getName()) + "#" + (*It2)->getNameInDocument(),
std::string((*It2)->getDocument()->getName()) + "#" + (*It2)->Label.getValue(),
CSSubgraphs);
}
@@ -588,16 +610,21 @@ void Document::exportGraphviz(std::ostream& out) const
++i;
}
++j;
}
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DependencyGraph");
bool omitGeoFeatureGroups = depGrp->GetBool("GeoFeatureSubgraphs", true);
// Add edges between document objects
for (std::map<std::string, DocumentObject*>::const_iterator It = d->objectMap.begin(); It != d->objectMap.end();++It) {
//coordinate systems are represented by subgraphs
if(It->second->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId()))
continue;
//as well as origins
// Add edges between document objects
for (std::map<std::string, DocumentObject*>::const_iterator It = d->objectMap.begin(); It != d->objectMap.end();++It) {
if(omitGeoFeatureGroups) {
//coordinate systems are represented by subgraphs
if(It->second->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId()))
continue;
//as well as origins
if(It->second->isDerivedFrom(Origin::getClassTypeId()))
continue;
}

View File

@@ -99,13 +99,20 @@ public:
}
void run() {
// Write data to unflatten process
unflattenProc.write(str);
unflattenProc.closeWriteChannel();
QByteArray preprocessed = str;
//no error handling: unflatten is optional
unflattenProc.waitForFinished();
preprocessed = unflattenProc.readAll();
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DependencyGraph");
if(hGrp->GetBool("Unflatten", true)) {
// Write data to unflatten process
unflattenProc.write(str);
unflattenProc.closeWriteChannel();
//no error handling: unflatten is optional
unflattenProc.waitForFinished();
preprocessed = unflattenProc.readAll();
} else {
unflattenProc.closeWriteChannel();
unflattenProc.waitForFinished();
}
dotProc.write(preprocessed);
dotProc.closeWriteChannel();
@@ -193,7 +200,7 @@ void GraphvizView::updateSvgItem(const App::Document &doc)
QProcess * flatProc = thread->unflattenProcess();
QStringList args, flatArgs;
args << QLatin1String("-Tsvg");
flatArgs << QLatin1String("-c2 -l3");
flatArgs << QLatin1String("-c2 -l2");
#ifdef FC_OS_LINUX
QString path = QString::fromUtf8(hGrp->GetASCII("Graphviz", "/usr/bin").c_str());
@@ -302,7 +309,7 @@ QByteArray GraphvizView::exportGraph(const QString& format)
QProcess dotProc, flatProc;
QStringList args, flatArgs;
args << QString::fromLatin1("-T%1").arg(format);
flatArgs << QLatin1String("-c2 -l3");
flatArgs << QLatin1String("-c2 -l2");
#ifdef FC_OS_LINUX
QString path = QString::fromUtf8(hGrp->GetASCII("Graphviz", "/usr/bin").c_str());
@@ -317,23 +324,30 @@ QByteArray GraphvizView::exportGraph(const QString& format)
QString exe = QString::fromLatin1("%1/dot").arg(path);
QString unflatten = QString::fromLatin1("%1/unflatten").arg(path);
#endif
flatProc.setEnvironment(QProcess::systemEnvironment());
flatProc.start(unflatten, flatArgs);
if (!flatProc.waitForStarted()) {
return QByteArray();
}
flatProc.write(graphCode.c_str(), graphCode.size());
flatProc.closeWriteChannel();
if (!flatProc.waitForFinished())
return QByteArray();
dotProc.setEnvironment(QProcess::systemEnvironment());
dotProc.start(exe, args);
if (!dotProc.waitForStarted()) {
return QByteArray();
}
dotProc.write(flatProc.readAll());
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DependencyGraph");
if(depGrp->GetBool("Unflatten", true)) {
flatProc.setEnvironment(QProcess::systemEnvironment());
flatProc.start(unflatten, flatArgs);
if (!flatProc.waitForStarted()) {
return QByteArray();
}
flatProc.write(graphCode.c_str(), graphCode.size());
flatProc.closeWriteChannel();
if (!flatProc.waitForFinished())
return QByteArray();
dotProc.write(flatProc.readAll());
}
else
dotProc.write(graphCode.c_str(), graphCode.size());
dotProc.closeWriteChannel();
if (!dotProc.waitForFinished())
return QByteArray();