OpenLexocad  27.0
GraphBuilder.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Core/ExecObject.h>
4 #include <Core/core_defines2.h>
5 #include <time.h>
6 
7 #include <algorithm>
8 #include <boost/graph/adjacency_list.hpp>
9 #include <boost/graph/depth_first_search.hpp>
10 #include <boost/graph/dijkstra_shortest_paths.hpp>
11 #include <boost/graph/graph_utility.hpp>
12 #include <boost/graph/graphviz.hpp>
13 #include <boost/graph/isomorphism.hpp>
14 #include <boost/graph/properties.hpp>
15 #include <boost/graph/topological_sort.hpp>
16 #include <boost/graph/visitors.hpp>
17 #include <boost/utility.hpp>
18 #include <iostream>
19 #include <iterator>
20 #include <list>
21 #include <map>
22 #include <set>
23 #include <vector>
24 #include <string>
25 
26 
27 
28 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, boost::property<boost::vertex_name_t, std::string> > ObjectGraph_Type;
29 
30 /*
31 typedef boost::adjacency_list<
32  boost::listS,
33  boost::listS,
34  boost::bidirectionalS,
35  boost::property<boost::vertex_index_t, long,
36  boost::property<boost::vertex_name_t, std::string >>
37  > ObjectGraph_Type;
38 */
39 
40 
41 typedef ObjectGraph_Type::vertex_descriptor Object_Vertex;
42 
43 
44 
45 namespace Core
46 {
48 {
49 public:
50  ObjectGraph();
51  // Copy constructor
52  ObjectGraph(const ObjectGraph& rhs);
53 
54  ObjectGraph(std::vector<Core::DocObject*> objs, bool ignoreLinksToTemporaryObjects = false);
55  ~ObjectGraph();
56 
57  void clear();
58  bool addObject(const Core::DocObject* o);
59  bool removeObject(const Core::DocObject* o);
60  bool updateObject(const Core::DocObject* o);
61  bool hasObject(const Core::DocObject* o) const;
62 
63 
64  bool recreate(std::vector<const Core::DocObject*> toDelete);
65  bool allLinksConnected();
66 
67  bool updateObject_BackLink(const Core::DocObject* o);
68 
69  std::vector<Core::DocObject*> build_SubGraph(const std::vector<Core::DocObject*>& featureSet);
70 
71  std::vector<const Core::DocObject*> getInner(const Core::DocObject* o, std::function<bool(const Core::DocObject*)>* allowToAddObject = 0);
72  std::vector<const Core::DocObject*> getOuter(const Core::DocObject* o);
73 
74 
75  std::vector<const Core::DocObject*> getTopologicalSorted();
76 
77  std::vector<const Core::DocObject*> getLinksToMe(const Core::DocObject* o);
78  std::vector<const Core::DocObject*> getLinksFromMe(const Core::DocObject* o);
79 
80  std::vector<const Core::DocObject*> getBackLinksToMe(const Core::DocObject* o);
81  std::vector<const Core::DocObject*> getBackLinksFromMe(const Core::DocObject* o);
82 
83  bool checkForCycle();
84  std::string dump();
85  std::vector< std::string > getErrors();
86 
87 private:
88  bool addObjectLinks(const Core::DocObject* o);
89  std::string dumpSort(ObjectGraph_Type g);
90  ObjectGraph_Type build(const std::vector<Core::DocObject*>& featureSet, std::map<size_t, Core::DocObject*>& myFeaturemap);
91 
92  void getOuter(Object_Vertex& vertex, std::vector<const Core::DocObject*>& behindobjects);
93  void getInner(Object_Vertex& vertex,
94  std::set<const Core::DocObject*>& beforeobjects,
95  std::function<bool(const Core::DocObject*)>* allowToAddObject);
96  void getInner(Object_Vertex& vertex,
97  std::vector<const Core::DocObject*>& beforeobjects,
98  std::function<bool(const Core::DocObject*)>* allowToAddObject);
99  boost::unordered_map<Object_Vertex, const Core::DocObject*> _vertex_to_object;
100  boost::unordered_map<const Core::DocObject*, Object_Vertex> _object_to_vertex;
101 
102  boost::unordered_map<Object_Vertex, const Core::DocObject*> _vertex_to_object_BackLink;
103  boost::unordered_map<const Core::DocObject*, Object_Vertex> _object_to_vertex_BackLink;
104 
105  ObjectGraph_Type* _objectGraph;
106  ObjectGraph_Type* _objectGraphBackLinks;
107  bool _ignoreLinksToTemporaryObjects = false;
108 
109  std::vector< std::string > mErrors;
110 
111 };
112 
113 
114 
115 } // namespace Core
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, boost::property< boost::vertex_name_t, std::string > > ObjectGraph_Type
Definition: GraphBuilder.h:28
#define CORE_EXPORT
Definition: core_defines2.h:10
void removeObject(Core::DocObject *e)
Removes an object from the document.
ObjectGraph_Type::vertex_descriptor Object_Vertex
Definition: GraphBuilder.h:41
std::vector< const Core::DocObject * > getInner(const Core::DocObject *me, std::function< bool(const Core::DocObject *)> *allowToAddObject=0)
Get ALL Links to me, also indirect.
bool addObject(Core::DocObject *e)
Adds an existing object to the document.
std::vector< const Core::DocObject * > getBackLinksFromMe(const Core::DocObject *o)
Returns all objects 'o' directly linked from 'o'.
Definition: Base.h:19
std::vector< const Core::DocObject * > getBackLinksToMe(const Core::DocObject *o)
Returns all objects that directly linked to 'o'.
std::vector< const Core::DocObject * > getOuter(const Core::DocObject *me)
Get ALL Links from me, also indirect.
std::vector< const Core::DocObject * > getLinksFromMe(const Core::DocObject *o)
Returns all objects 'o' directly linked from 'o'.
std::vector< const Core::DocObject * > getLinksToMe(const Core::DocObject *o)
Returns all objects that directly linked to 'o'.
Definition: GraphBuilder.h:47
Definition: DocObject.h:28