App: Apply clang format (part 1)

This commit is contained in:
wmayer
2024-11-15 17:43:49 +01:00
committed by wwmayer
parent 463cc08f3f
commit 6f5259af26
124 changed files with 6733 additions and 4886 deletions

View File

@@ -38,21 +38,22 @@
using namespace App;
using namespace boost;
void Document::writeDependencyGraphViz(std::ostream &out)
void Document::writeDependencyGraphViz(std::ostream& out)
{
// // caching vertex to DocObject
//std::map<Vertex,DocumentObject*> VertexMap;
//for(std::map<DocumentObject*,Vertex>::const_iterator It1= _DepConMap.begin();It1 != _DepConMap.end(); ++It1)
// std::map<Vertex,DocumentObject*> VertexMap;
// for(std::map<DocumentObject*,Vertex>::const_iterator It1= _DepConMap.begin();It1 !=
// _DepConMap.end(); ++It1)
// VertexMap[It1->second] = It1->first;
out << "digraph G {" << std::endl;
out << "\tordering=out;" << std::endl;
out << "\tnode [shape = box];" << std::endl;
for (const auto &It : d->objectMap) {
for (const auto& It : d->objectMap) {
out << "\t" << It.first << ";" << std::endl;
std::vector<DocumentObject*> OutList = It.second->getOutList();
for (const auto &It2 : OutList) {
for (const auto& It2 : OutList) {
if (It2) {
out << "\t" << It.first << "->" << It2->getNameInDocument() << ";" << std::endl;
}
@@ -75,14 +76,19 @@ void Document::exportGraphviz(std::ostream& out) const
{
/* Type defs for a graph with graphviz attributes */
using GraphvizAttributes = std::map<std::string, std::string>;
using Graph = boost::subgraph< adjacency_list<vecS, vecS, directedS,
property<vertex_attribute_t, GraphvizAttributes>,
property<edge_index_t, int, property<edge_attribute_t, GraphvizAttributes> >,
property<graph_name_t, std::string,
property<graph_graph_attribute_t, GraphvizAttributes,
property<graph_vertex_attribute_t, GraphvizAttributes,
property<graph_edge_attribute_t, GraphvizAttributes>
> > > > >;
using Graph = boost::subgraph<adjacency_list<
vecS,
vecS,
directedS,
property<vertex_attribute_t, GraphvizAttributes>,
property<edge_index_t, int, property<edge_attribute_t, GraphvizAttributes>>,
property<graph_name_t,
std::string,
property<graph_graph_attribute_t,
GraphvizAttributes,
property<graph_vertex_attribute_t,
GraphvizAttributes,
property<graph_edge_attribute_t, GraphvizAttributes>>>>>>;
/**
* @brief The GraphCreator class
@@ -91,18 +97,25 @@ void Document::exportGraphviz(std::ostream& out) const
*
*/
class GraphCreator {
class GraphCreator
{
public:
explicit GraphCreator(struct DocumentP* _d) : d(_d), seed(std::random_device()()), distribution(0,255) {
explicit GraphCreator(struct DocumentP* _d)
: d(_d)
, seed(std::random_device()())
, distribution(0, 255)
{
build();
}
const Graph & getGraph() const { return DepList; }
const Graph& getGraph() const
{
return DepList;
}
private:
void build() {
void build()
{
// Set attribute(s) for main graph
get_property(DepList, graph_graph_attribute)["compound"] = "true";
@@ -119,7 +132,8 @@ void Document::exportGraphviz(std::ostream& out) const
* @return A string
*/
std::string getId(const DocumentObject * docObj) {
std::string getId(const DocumentObject* docObj)
{
std::string id;
if (docObj->isAttachedToDocument()) {
auto doc = docObj->getDocument();
@@ -136,25 +150,32 @@ void Document::exportGraphviz(std::ostream& out) const
* @return A string
*/
std::string getId(const ObjectIdentifier & path) {
DocumentObject * docObj = path.getDocumentObject();
if (!docObj)
std::string getId(const ObjectIdentifier& path)
{
DocumentObject* docObj = path.getDocumentObject();
if (!docObj) {
return {};
}
return std::string((docObj)->getDocument()->getName()) + "#" + docObj->getNameInDocument() + "." + path.getPropertyName() + path.getSubPathStr();
return std::string((docObj)->getDocument()->getName()) + "#"
+ docObj->getNameInDocument() + "." + path.getPropertyName() + path.getSubPathStr();
}
std::string getClusterName(const DocumentObject * docObj) const {
std::string getClusterName(const DocumentObject* docObj) const
{
return std::string("cluster") + docObj->getNameInDocument();
}
void setGraphLabel(Graph& g, const DocumentObject* obj) const {
void setGraphLabel(Graph& g, const DocumentObject* obj) const
{
std::string name(obj->getNameInDocument());
std::string label(obj->Label.getValue());
if (name == label)
if (name == label) {
get_property(g, graph_graph_attribute)["label"] = name;
else
}
else {
get_property(g, graph_graph_attribute)["label"] = name + "&#92;n(" + label + ")";
}
}
/**
@@ -162,7 +183,8 @@ void Document::exportGraphviz(std::ostream& out) const
* @param obj DocumentObject
*/
void setGraphAttributes(const DocumentObject * obj) {
void setGraphAttributes(const DocumentObject* obj)
{
assert(GraphList.find(obj) != GraphList.end());
get_property(*GraphList[obj], graph_name) = getClusterName(obj);
@@ -179,7 +201,8 @@ void Document::exportGraphviz(std::ostream& out) const
* @param name Name of node
*/
void setPropertyVertexAttributes(Graph & g, Vertex vertex, const std::string & name) {
void setPropertyVertexAttributes(Graph& g, Vertex vertex, const std::string& name)
{
get(vertex_attribute, g)[vertex]["label"] = name;
get(vertex_attribute, g)[vertex]["shape"] = "box";
get(vertex_attribute, g)[vertex]["style"] = "dashed";
@@ -187,13 +210,15 @@ 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 the document object, or other objects are referencing properties in it.
* @brief addExpressionSubgraphIfNeeded Add a subgraph to the main graph if it is needed,
* i.e. there are defined at least one expression in the 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, bool CSsubgraphs) {
void addExpressionSubgraphIfNeeded(DocumentObject* obj, bool CSsubgraphs)
{
auto expressions = obj->ExpressionEngine.getExpressions();
@@ -205,8 +230,9 @@ void Document::exportGraphviz(std::ostream& out) const
auto group = GeoFeatureGroupExtension::getGroupOfObject(obj);
if (group) {
auto it = GraphList.find(group);
if (it != GraphList.end())
if (it != GraphList.end()) {
graph = it->second;
}
}
}
@@ -216,16 +242,18 @@ void Document::exportGraphviz(std::ostream& out) const
setGraphAttributes(obj);
}
// Create subgraphs for all document objects that it depends on; it will depend on some property there
for (const auto &expr : expressions) {
// Create subgraphs for all document objects that it depends on; it will depend on
// some property there
for (const auto& expr : expressions) {
std::map<ObjectIdentifier, bool> deps;
expr.second->getIdentifiers(deps);
for (const auto &dep : deps) {
if (dep.second)
for (const auto& dep : deps) {
if (dep.second) {
continue;
DocumentObject * o = dep.first.getDocumentObject();
}
DocumentObject* o = dep.first.getDocumentObject();
// Doesn't exist already?
if (o && !GraphList[o]) {
@@ -249,38 +277,48 @@ void Document::exportGraphviz(std::ostream& out) const
}
/**
* @brief add Add @docObj to the graph, including all expressions (and dependencies) it includes.
* @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)
void add(DocumentObject* docObj,
const std::string& name,
const std::string& label,
bool CSSubgraphs)
{
//don't add objects twice
if (std::find(objects.begin(), objects.end(), docObj) != objects.end())
// don't add objects twice
if (std::find(objects.begin(), objects.end(), docObj) != objects.end()) {
return;
}
//find the correct graph to add the vertex to. Check first expression graphs, afterwards
//the parent CS and origin graphs
Graph *sgraph = GraphList[docObj];
// find the correct graph to add the vertex to. Check first expression graphs,
// afterwards the parent CS and origin graphs
Graph* sgraph = GraphList[docObj];
if (CSSubgraphs) {
if (!sgraph) {
auto group = GeoFeatureGroupExtension::getGroupOfObject(docObj);
if (group) {
if (docObj->isDerivedFrom(App::OriginFeature::getClassTypeId()))
sgraph = GraphList[group->getExtensionByType<OriginGroupExtension>()->Origin.getValue()];
else
if (docObj->isDerivedFrom(App::OriginFeature::getClassTypeId())) {
sgraph = GraphList[group->getExtensionByType<OriginGroupExtension>()
->Origin.getValue()];
}
else {
sgraph = GraphList[group];
}
}
}
if (!sgraph) {
if (docObj->isDerivedFrom(OriginFeature::getClassTypeId()))
sgraph = GraphList[static_cast<OriginFeature *>(docObj)->getOrigin()];
if (docObj->isDerivedFrom(OriginFeature::getClassTypeId())) {
sgraph = GraphList[static_cast<OriginFeature*>(docObj)->getOrigin()];
}
}
}
if (!sgraph)
if (!sgraph) {
sgraph = &DepList;
}
// Keep a list of all added document objects.
objects.insert(docObj);
@@ -294,21 +332,25 @@ void Document::exportGraphviz(std::ostream& out) const
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["style"] = "filled";
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["shape"] = "Mrecord";
// Set node label
if (name == label)
if (name == label) {
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["label"] = name;
else
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["label"] = name + "&#92;n(" + label + ")";
}
else {
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["label"] =
name + "&#92;n(" + label + ")";
}
}
else {
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["style"] = "invis";
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["fixedsize"] = "true";
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["fixedsize"] =
"true";
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["width"] = "0";
get(vertex_attribute, *sgraph)[LocalVertexList[getId(docObj)]]["height"] = "0";
}
// Add expressions and its dependencies
auto expressions{docObj->ExpressionEngine.getExpressions()};
for (const auto &expr : expressions) {
auto expressions {docObj->ExpressionEngine.getExpressions()};
for (const auto& expr : expressions) {
auto found = std::as_const(GlobalVertexList).find(getId(expr.first));
if (found == GlobalVertexList.end()) {
int vid = LocalVertexList[getId(expr.first)] = add_vertex(*sgraph);
@@ -318,63 +360,70 @@ void Document::exportGraphviz(std::ostream& out) const
}
// Add all dependencies
for (const auto &expression : expressions) {
for (const auto& expression : expressions) {
// Get dependencies
std::map<ObjectIdentifier, bool> deps;
expression.second->getIdentifiers(deps);
// Create subgraphs for all documentobjects that it depends on; it will depend on some property there
for (const auto &dep : deps) {
// Create subgraphs for all documentobjects that it depends on; it will depend on
// some property there
for (const auto& dep : deps) {
if (dep.second) {
continue;
}
DocumentObject *depObjDoc = dep.first.getDocumentObject();
DocumentObject* depObjDoc = dep.first.getDocumentObject();
auto found = GlobalVertexList.find(getId(dep.first));
if (found == GlobalVertexList.end()) {
Graph *depSgraph = GraphList[depObjDoc] ? GraphList[depObjDoc] : &DepList;
Graph* depSgraph = GraphList[depObjDoc] ? GraphList[depObjDoc] : &DepList;
LocalVertexList[getId(dep.first)] = add_vertex(*depSgraph);
GlobalVertexList[getId(dep.first)] = vertex_no++;
setPropertyVertexAttributes(*depSgraph, LocalVertexList[getId(dep.first)], dep.first.getPropertyName() + dep.first.getSubPathStr());
setPropertyVertexAttributes(*depSgraph,
LocalVertexList[getId(dep.first)],
dep.first.getPropertyName()
+ dep.first.getSubPathStr());
}
}
}
}
void recursiveCSSubgraphs(DocumentObject* cs, DocumentObject* parent) {
void recursiveCSSubgraphs(DocumentObject* cs, DocumentObject* parent)
{
auto graph = parent ? GraphList[parent] : &DepList;
// check if the value for the key 'parent' is null
if (!graph)
if (!graph) {
return;
}
auto& sub = graph->create_subgraph();
GraphList[cs] = &sub;
get_property(sub, graph_name) = getClusterName(cs);
//build random color string
// build random color string
std::stringstream stream;
stream << "#" << std::setfill('0') << std::setw(2)<< std::hex << distribution(seed)
<< std::setfill('0') << std::setw(2)<< std::hex << distribution(seed)
<< std::setfill('0') << std::setw(2)<< std::hex << distribution(seed) << 80;
stream << "#" << std::setfill('0') << std::setw(2) << std::hex << distribution(seed)
<< std::setfill('0') << std::setw(2) << std::hex << distribution(seed)
<< std::setfill('0') << std::setw(2) << std::hex << distribution(seed) << 80;
std::string result(stream.str());
get_property(sub, graph_graph_attribute)["bgcolor"] = result;
get_property(sub, graph_graph_attribute)["style"] = "rounded,filled";
setGraphLabel(sub, cs);
for(auto obj : cs->getOutList()) {
for (auto obj : cs->getOutList()) {
if (obj->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId())) {
// in case of dependencies loops check if obj is already part of the
// map to avoid infinite recursions
auto it = GraphList.find(obj);
if (it == GraphList.end())
if (it == GraphList.end()) {
recursiveCSSubgraphs(obj, cs);
}
}
}
//setup the origin if available
if(cs->hasExtension(App::OriginGroupExtension::getExtensionClassTypeId())) {
// setup the origin if available
if (cs->hasExtension(App::OriginGroupExtension::getExtensionClassTypeId())) {
auto origin = cs->getExtensionByType<OriginGroupExtension>()->Origin.getValue();
if (!origin) {
std::cerr << "Origin feature not found" << std::endl;
@@ -388,67 +437,80 @@ void Document::exportGraphviz(std::ostream& out) const
}
}
void addSubgraphs() {
void addSubgraphs()
{
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DependencyGraph");
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
if (CSSubgraphs) {
// first build up the coordinate system subgraphs
for (auto objectIt : d->objectArray) {
// ignore groups inside other groups, these will be processed in one of the next recursive calls.
// App::Origin now has the GeoFeatureGroupExtension but it should not move its
// group symbol outside its parent
if (!objectIt->isDerivedFrom(Origin::getClassTypeId()) &&
objectIt->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId()) &&
GeoFeatureGroupExtension::getGroupOfObject(objectIt) == nullptr)
{
// ignore groups inside other groups, these will be processed in one of the next
// recursive calls. App::Origin now has the GeoFeatureGroupExtension but it
// should not move its group symbol outside its parent
if (!objectIt->isDerivedFrom(Origin::getClassTypeId())
&& objectIt->hasExtension(
GeoFeatureGroupExtension::getExtensionClassTypeId())
&& GeoFeatureGroupExtension::getGroupOfObject(objectIt) == nullptr) {
recursiveCSSubgraphs(objectIt, nullptr);
}
}
}
// Internal document objects
for (const auto & It : d->objectMap)
for (const auto& It : d->objectMap) {
addExpressionSubgraphIfNeeded(It.second, CSSubgraphs);
}
// Add external document objects
for (const auto & it : d->objectMap) {
for (const auto& it : d->objectMap) {
std::vector<DocumentObject*> OutList = it.second->getOutList();
for (auto obj : OutList) {
if (obj) {
std::map<std::string,Vertex>::const_iterator item = GlobalVertexList.find(getId(obj));
std::map<std::string, Vertex>::const_iterator item =
GlobalVertexList.find(getId(obj));
if (item == GlobalVertexList.end())
if (item == GlobalVertexList.end()) {
addExpressionSubgraphIfNeeded(obj, CSSubgraphs);
}
}
}
}
}
// Filling up the adjacency List
void buildAdjacencyList() {
void buildAdjacencyList()
{
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DependencyGraph");
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/DependencyGraph");
bool CSSubgraphs = depGrp->GetBool("GeoFeatureSubgraphs", true);
// Add internal document objects
for (const auto & It : d->objectMap)
add(It.second, It.second->getNameInDocument(), It.second->Label.getValue(), CSSubgraphs);
for (const auto& It : d->objectMap) {
add(It.second,
It.second->getNameInDocument(),
It.second->Label.getValue(),
CSSubgraphs);
}
// Add external document objects
for (const auto & It : d->objectMap) {
for (const auto& It : d->objectMap) {
std::vector<DocumentObject*> OutList = It.second->getOutList();
for (auto obj : OutList) {
if (obj) {
std::map<std::string,Vertex>::const_iterator item = GlobalVertexList.find(getId(obj));
std::map<std::string, Vertex>::const_iterator item =
GlobalVertexList.find(getId(obj));
if (item == GlobalVertexList.end()) {
if (obj->isAttachedToDocument()) {
add(obj,
std::string(obj->getDocument()->getName()) + "#" + obj->getNameInDocument(),
std::string(obj->getDocument()->getName()) + "#" + obj->Label.getValue(),
std::string(obj->getDocument()->getName()) + "#"
+ obj->getNameInDocument(),
std::string(obj->getDocument()->getName()) + "#"
+ obj->Label.getValue(),
CSSubgraphs);
}
}
@@ -457,31 +519,37 @@ void Document::exportGraphviz(std::ostream& out) const
}
}
void addEdges() {
void addEdges()
{
// Get edge properties for main graph
const boost::property_map<Graph, boost::edge_attribute_t>::type& edgeAttrMap = boost::get(boost::edge_attribute, DepList);
const boost::property_map<Graph, boost::edge_attribute_t>::type& edgeAttrMap =
boost::get(boost::edge_attribute, DepList);
// Track edges between document objects connected by expression dependencies
std::set<std::pair<const DocumentObject*, const DocumentObject*> > existingEdges;
std::set<std::pair<const DocumentObject*, const DocumentObject*>> existingEdges;
// Add edges between properties
for (const auto &docObj : objects) {
for (const auto& docObj : objects) {
// Add expressions and its dependencies
auto expressions = docObj->ExpressionEngine.getExpressions();
for (const auto &expr : expressions) {
for (const auto& expr : expressions) {
std::map<ObjectIdentifier, bool> deps;
expr.second->getIdentifiers(deps);
// Create subgraphs for all documentobjects that it depends on; it will depend on some property there
for (const auto &dep : deps) {
if (dep.second)
// Create subgraphs for all documentobjects that it depends on; it will depend
// on some property there
for (const auto& dep : deps) {
if (dep.second) {
continue;
DocumentObject * depObjDoc = dep.first.getDocumentObject();
}
DocumentObject* depObjDoc = dep.first.getDocumentObject();
Edge edge;
bool inserted;
tie(edge, inserted) = add_edge(GlobalVertexList[getId(expr.first)], GlobalVertexList[getId(dep.first)], DepList);
tie(edge, inserted) = add_edge(GlobalVertexList[getId(expr.first)],
GlobalVertexList[getId(dep.first)],
DepList);
// Add this edge to the set of all expression generated edges
existingEdges.insert(std::make_pair(docObj, depObjDoc));
@@ -493,54 +561,69 @@ void Document::exportGraphviz(std::ostream& out) const
}
}
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/DependencyGraph");
ParameterGrp::handle depGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/DependencyGraph");
bool omitGeoFeatureGroups = depGrp->GetBool("GeoFeatureSubgraphs", true);
// Add edges between document objects
for (const auto & It : d->objectMap) {
for (const auto& It : d->objectMap) {
if(omitGeoFeatureGroups && It.second->isDerivedFrom(Origin::getClassTypeId())) {
if (omitGeoFeatureGroups && It.second->isDerivedFrom(Origin::getClassTypeId())) {
continue;
}
std::map<DocumentObject*, int> dups;
std::vector<DocumentObject*> OutList = It.second->getOutList();
const DocumentObject * docObj = It.second;
const bool docObj_is_group = docObj->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId());
const DocumentObject* docObj = It.second;
const bool docObj_is_group =
docObj->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId());
for (auto obj : OutList) {
if (obj) {
if(omitGeoFeatureGroups && docObj_is_group && GeoFeatureGroupExtension::getGroupOfObject(obj) == docObj) {
if (omitGeoFeatureGroups && docObj_is_group
&& GeoFeatureGroupExtension::getGroupOfObject(obj) == docObj) {
continue;
}
// Count duplicate edges
bool inserted = edge(GlobalVertexList[getId(docObj)], GlobalVertexList[getId(obj)], DepList).second;
bool inserted = edge(GlobalVertexList[getId(docObj)],
GlobalVertexList[getId(obj)],
DepList)
.second;
if (inserted) {
dups[obj]++;
continue;
}
// Skip edge if an expression edge already exists
if (existingEdges.find(std::make_pair(docObj, obj)) != existingEdges.end())
if (existingEdges.find(std::make_pair(docObj, obj))
!= existingEdges.end()) {
continue;
}
// Add edge
Edge edge;
tie(edge, inserted) = add_edge(GlobalVertexList[getId(docObj)], GlobalVertexList[getId(obj)], DepList);
tie(edge, inserted) = add_edge(GlobalVertexList[getId(docObj)],
GlobalVertexList[getId(obj)],
DepList);
// Set properties to make arrows go between subgraphs if needed
if (GraphList[docObj])
if (GraphList[docObj]) {
edgeAttrMap[edge]["ltail"] = getClusterName(docObj);
if (GraphList[obj])
}
if (GraphList[obj]) {
edgeAttrMap[edge]["lhead"] = getClusterName(obj);
}
}
}
// Set labels for duplicate edges
for (const auto & dup : dups) {
Edge e(edge(GlobalVertexList[getId(It.second)], GlobalVertexList[getId(dup.first)], DepList).first);
for (const auto& dup : dups) {
Edge e(edge(GlobalVertexList[getId(It.second)],
GlobalVertexList[getId(dup.first)],
DepList)
.first);
std::stringstream s;
s << " " << (dup.second + 1) << "x";
edgeAttrMap[e]["label"] = s.str();
@@ -550,10 +633,11 @@ void Document::exportGraphviz(std::ostream& out) const
using EdgeMap = std::unordered_multimap<Vertex, Edge>;
void removeEdges(EdgeMap & in_edges,
EdgeMap & out_edges,
std::pair<EdgeMap::iterator, EdgeMap::iterator > i_pair,
std::function<Vertex (const Edge&)> select_vertex) {
void removeEdges(EdgeMap& in_edges,
EdgeMap& out_edges,
std::pair<EdgeMap::iterator, EdgeMap::iterator> i_pair,
std::function<Vertex(const Edge&)> select_vertex)
{
auto i = i_pair.first;
while (i != i_pair.second) {
@@ -562,10 +646,12 @@ void Document::exportGraphviz(std::ostream& out) const
auto in_i = in_i_pair.first;
while (in_i != in_i_pair.second) {
if (in_i->second == i->second)
if (in_i->second == i->second) {
in_i = in_edges.erase(in_i);
else
}
else {
++in_i;
}
}
// Remove node from out_edges
@@ -574,12 +660,13 @@ void Document::exportGraphviz(std::ostream& out) const
}
#if defined(__clang__)
#elif defined (__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
void markCycles() {
void markCycles()
{
bool changed = true;
std::unordered_set<Vertex> in_use;
EdgeMap in_edges;
@@ -588,8 +675,9 @@ void Document::exportGraphviz(std::ostream& out) const
// Add all vertices to the in_use set
graph_traits<Graph>::vertex_iterator vi, vi_end;
tie(vi, vi_end) = vertices(DepList);
for (; vi != vi_end; ++vi)
for (; vi != vi_end; ++vi) {
in_use.insert(*vi);
}
// Add all edges to the in_edges and out_edges multimaps
graph_traits<Graph>::edge_iterator ei, ei_end;
@@ -616,21 +704,26 @@ void Document::exportGraphviz(std::ostream& out) const
auto i_in_deg_pair = in_edges.equal_range(*uvi);
auto i_out_deg_pair = out_edges.equal_range(*uvi);
if (i_in_deg_pair.first == in_edges.end() && i_out_deg_pair.first == out_edges.end()) {
if (i_in_deg_pair.first == in_edges.end()
&& i_out_deg_pair.first == out_edges.end()) {
uvi = in_use.erase(uvi);
continue;
}
// Remove out edges of nodes that don't have a single edge in
if (i_in_deg_pair.first == in_edges.end()) {
removeEdges(in_edges, out_edges, i_out_deg_pair, [&](Edge e) { return target(e, DepList); });
removeEdges(in_edges, out_edges, i_out_deg_pair, [&](Edge e) {
return target(e, DepList);
});
changed = true;
i_out_deg_pair = out_edges.equal_range(*uvi);
}
// Remove in edges of nodes that don't have a single edge out
if (i_out_deg_pair.first == out_edges.end()) {
removeEdges(out_edges, in_edges, i_in_deg_pair, [&](Edge e) { return source(e, DepList); });
removeEdges(out_edges, in_edges, i_in_deg_pair, [&](Edge e) {
return source(e, DepList);
});
changed = true;
}
@@ -639,41 +732,48 @@ void Document::exportGraphviz(std::ostream& out) const
}
// Update colors in graph
const boost::property_map<Graph, boost::edge_attribute_t>::type& edgeAttrMap = boost::get(boost::edge_attribute, DepList);
for (auto ei : out_edges)
const boost::property_map<Graph, boost::edge_attribute_t>::type& edgeAttrMap =
boost::get(boost::edge_attribute, DepList);
for (auto ei : out_edges) {
edgeAttrMap[ei.second]["color"] = "red";
}
}
#if defined(__clang__)
#elif defined (__GNUC__)
# pragma GCC diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
void markOutOfScopeLinks() {
const boost::property_map<Graph, boost::edge_attribute_t>::type& edgeAttrMap = boost::get(boost::edge_attribute, DepList);
void markOutOfScopeLinks()
{
const boost::property_map<Graph, boost::edge_attribute_t>::type& edgeAttrMap =
boost::get(boost::edge_attribute, DepList);
for( auto obj : objects) {
for (auto obj : objects) {
std::vector<App::DocumentObject*> invalids;
GeoFeatureGroupExtension::getInvalidLinkObjects(obj, invalids);
//isLinkValid returns true for non-link properties
for(auto linkedObj : invalids) {
// isLinkValid returns true for non-link properties
for (auto linkedObj : invalids) {
auto res = edge(GlobalVertexList[getId(obj)], GlobalVertexList[getId(linkedObj)], DepList);
if(res.second)
auto res = edge(GlobalVertexList[getId(obj)],
GlobalVertexList[getId(linkedObj)],
DepList);
if (res.second) {
edgeAttrMap[res.first]["color"] = "orange";
}
}
}
}
const struct DocumentP* d;
Graph DepList;
int vertex_no{0};
int vertex_no {0};
std::map<std::string, Vertex> LocalVertexList;
std::map<std::string, Vertex> GlobalVertexList;
std::set<const DocumentObject*> objects;
std::map<const DocumentObject*, Graph*> GraphList;
//random color generation
// random color generation
std::mt19937 seed;
std::uniform_int_distribution<int> distribution;
};