19 #include <tulip/Graph.h>
20 #include <tulip/Coord.h>
22 template <
typename nodeType,
typename edgeType,
typename propType>
24 tlp::Graph *graph,
const std::string &name, NODE_VALUE NodeMin, NODE_VALUE NodeMax,
25 EDGE_VALUE EdgeMin, EDGE_VALUE EdgeMax)
26 :
AbstractProperty<nodeType, edgeType, propType>(graph, name), _nodeMin(NodeMin),
27 _nodeMax(NodeMax), _edgeMin(EdgeMin), _edgeMax(EdgeMax), needGraphListener(false) {}
29 template <
typename nodeType,
typename edgeType,
typename propType>
33 graph = this->propType::graph;
36 unsigned int graphID = graph->
getId();
37 auto it = minMaxNode.find(graphID);
39 return (it == minMaxNode.end()) ? computeMinMaxNode(graph) : it->second;
42 template <
typename nodeType,
typename edgeType,
typename propType>
46 graph = this->propType::graph;
49 unsigned int graphID = graph->
getId();
50 auto it = minMaxEdge.find(graphID);
52 return (it == minMaxEdge.end()) ? computeMinMaxEdge(graph) : it->second;
55 template <
typename nodeType,
typename edgeType,
typename propType>
56 const MINMAX_PAIR(nodeType) &
59 graph = this->propType::graph;
62 NODE_VALUE maxN2 = _nodeMin, minN2 = _nodeMax;
65 for (
auto n : graph->nodes()) {
66 CONST_NODE_VALUE tmp = this->getNodeValue(n);
76 maxN2 = minN2 = AbstractProperty<nodeType, edgeType, propType>::nodeDefaultValue;
78 unsigned int sgi = graph->getId();
83 if (minMaxNode.find(sgi) == minMaxNode.end() && minMaxEdge.find(sgi) == minMaxEdge.end()) {
85 graph->addListener(
this);
88 return minMaxNode[sgi] = {minN2, maxN2};
91 template <
typename nodeType,
typename edgeType,
typename propType>
92 const MINMAX_PAIR(edgeType) &
94 EDGE_VALUE maxE2 = _edgeMin, minE2 = _edgeMax;
97 for (
auto ite : graph->edges()) {
98 CONST_EDGE_VALUE tmp = this->getEdgeValue(ite);
108 maxE2 = minE2 = AbstractProperty<nodeType, edgeType, propType>::edgeDefaultValue;
110 unsigned int sgi = graph->getId();
115 if (minMaxNode.find(sgi) == minMaxNode.end() && minMaxEdge.find(sgi) == minMaxEdge.end()) {
117 graph->addListener(
this);
120 return minMaxEdge[sgi] = {minE2, maxE2};
123 template <
typename nodeType,
typename edgeType,
typename propType>
134 auto it = minMaxNode.begin();
135 auto ite = minMaxNode.end();
137 for (; it != ite; ++it) {
138 unsigned int gi = it->first;
139 auto itg = minMaxEdge.find(gi);
141 if (itg == minMaxEdge.end()) {
144 Graph *g = (propType::graph->getId() == gi) ? (needGraphListener ?
nullptr : propType::graph)
145 : propType::graph->getDescendantGraph(gi);
156 template <
typename nodeType,
typename edgeType,
typename propType>
167 auto it = minMaxEdge.begin();
168 auto ite = minMaxEdge.end();
170 for (; it != ite; ++it) {
171 unsigned int gi = it->first;
172 auto itg = minMaxNode.find(gi);
174 if (itg == minMaxNode.end()) {
177 Graph *g = (propType::graph->getId() == gi) ? (needGraphListener ?
nullptr : propType::graph)
178 : propType::graph->getDescendantGraph(gi);
189 template <
typename nodeType,
typename edgeType,
typename propType>
191 CONST_NODE_VALUE newValue) {
192 auto it = minMaxNode.begin();
194 if (it != minMaxNode.end()) {
195 CONST_NODE_VALUE oldV = this->getNodeValue(n);
197 if (newValue != oldV) {
199 for (; it != minMaxNode.end(); ++it) {
200 auto sid = it->first;
203 auto sg = this->graph->getDescendantGraph(sid);
205 if (sg && !sg->isElement(n))
210 CONST_NODE_VALUE minV = it->second.first;
211 CONST_NODE_VALUE maxV = it->second.second;
214 if ((newValue < minV) || (newValue > maxV) || (oldV == minV) || (oldV == maxV)) {
215 removeListenersAndClearNodeMap();
223 template <
typename nodeType,
typename edgeType,
typename propType>
225 CONST_EDGE_VALUE newValue) {
226 auto it = minMaxEdge.begin();
228 if (it != minMaxEdge.end()) {
229 CONST_EDGE_VALUE oldV = this->getEdgeValue(e);
231 if (newValue != oldV) {
233 for (; it != minMaxEdge.end(); ++it) {
234 auto sid = it->first;
238 auto sg = this->graph->getDescendantGraph(sid);
239 if (sg && !sg->isElement(e))
244 CONST_EDGE_VALUE minV = it->second.first;
245 CONST_EDGE_VALUE maxV = it->second.second;
248 if ((newValue < minV) || (newValue > maxV) || (oldV == minV) || (oldV == maxV)) {
249 removeListenersAndClearEdgeMap();
257 template <
typename nodeType,
typename edgeType,
typename propType>
259 CONST_NODE_VALUE newValue) {
260 auto it = minMaxNode.begin();
262 MINMAX_PAIR(nodeType) minmax(newValue, newValue);
264 for (; it != minMaxNode.end(); ++it) {
265 unsigned int gid = it->first;
266 minMaxNode[gid] = minmax;
270 template <
typename nodeType,
typename edgeType,
typename propType>
272 CONST_EDGE_VALUE newValue) {
273 auto it = minMaxEdge.begin();
275 MINMAX_PAIR(edgeType) minmax(newValue, newValue);
277 for (; it != minMaxEdge.end(); ++it) {
278 unsigned int gid = it->first;
279 minMaxEdge[gid] = minmax;
283 template <
typename nodeType,
typename edgeType,
typename propType>
290 switch (graphEvent->getType()) {
291 case GraphEvent::TLP_ADD_NODE:
292 removeListenersAndClearNodeMap();
295 case GraphEvent::TLP_BEFORE_DEL_NODE: {
296 unsigned int sgi = graph->
getId();
297 auto it = minMaxNode.find(sgi);
299 if (it != minMaxNode.end()) {
300 CONST_NODE_VALUE oldV = this->getNodeValue(graphEvent->getNode());
303 if ((oldV == it->second.first) || (oldV == it->second.second)) {
304 minMaxNode.erase(it);
306 if ((minMaxEdge.find(sgi) == minMaxEdge.end()) &&
307 (!needGraphListener || (graph != propType::graph)))
316 case GraphEvent::TLP_ADD_EDGE:
317 removeListenersAndClearEdgeMap();
320 case GraphEvent::TLP_BEFORE_DEL_EDGE: {
321 unsigned int sgi = graph->
getId();
322 auto it = minMaxEdge.find(sgi);
324 if (it != minMaxEdge.end()) {
325 EDGE_VALUE oldV = this->getEdgeValue(graphEvent->getEdge());
328 if ((oldV == it->second.first) || (oldV == it->second.second)) {
329 minMaxEdge.erase(it);
331 if ((minMaxNode.find(sgi) == minMaxNode.end()) &&
332 (!needGraphListener || (graph != propType::graph)))
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
bool hasNonDefaultValuatedEdges(const Graph *g=nullptr) const override
Returns whether the property has edges with a non default value. When given a Graph as parameter,...
bool hasNonDefaultValuatedNodes(const Graph *g=nullptr) const override
Returns whether the property has nodes with a non default value. When given a Graph as parameter,...
Event is the base class for all events used in the Observation mechanism.
unsigned int getId() const
Gets the unique identifier of the graph.
Abstracts the computation of minimal and maximal values on node and edge values of properties.
void updateNodeValue(tlp::node n, CONST_NODE_VALUE newValue)
Updates the value on a node, and updates the minimal/maximal cached values if necessary....
MinMaxProperty(tlp::Graph *graph, const std::string &name, NODE_VALUE NodeMin, NODE_VALUE NodeMax, EDGE_VALUE EdgeMin, EDGE_VALUE EdgeMax)
Constructs a MinMaxProperty.
void updateEdgeValue(tlp::edge e, CONST_EDGE_VALUE newValue)
Updates the value on an edge, and updates the minimal/maximal cached values if necessary....
void updateAllEdgesValues(CONST_EDGE_VALUE newValue)
Updates the value of all edges, setting the maximum and minimum values to this. Should be called by s...
void treatEvent(const tlp::Event &ev) override
This function is called when events are sent to the Listeners, and Listeners only.
void updateAllNodesValues(CONST_NODE_VALUE newValue)
Updates the value of all nodes, setting the maximum and minimum values to this. Should be called by s...
void removeListener(Observable *const listener) const
Removes a listener from this object.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.