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;
}