1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
/**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux
*
* Tulip is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tulip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
#include <tulip/ColorProperty.h>
#include <tulip/BooleanProperty.h>
#include <tulip/SizeProperty.h>
#include <tulip/StringProperty.h>
#include <tulip/ForEach.h>
#include <tulip/IntegerProperty.h>
#include <tulip/DoubleProperty.h>
#include "ParallelCoordinatesGraphProxy.h"
#include "ParallelTools.h"
using namespace std;
namespace tlp {
ParallelCoordinatesGraphProxy::ParallelCoordinatesGraphProxy(Graph *g, const ElementType location):
GraphDecorator(g), graphColorsChanged(false), dataLocation(location), unhighlightedEltsColorAlphaValue(20) {
dataColors = graph_component->getProperty<ColorProperty>("viewColor");
dataColors->addObserver(this);
originalDataColors = new ColorProperty(graph_component);
*originalDataColors = *(graph_component->getProperty<ColorProperty>("viewColor"));
}
ParallelCoordinatesGraphProxy::~ParallelCoordinatesGraphProxy() {
dataColors->removeObserver(this);
Observable::holdObservers();
*dataColors = *originalDataColors;
delete originalDataColors;
originalDataColors = NULL;
Observable::unholdObservers();
}
unsigned int ParallelCoordinatesGraphProxy::getNumberOfSelectedProperties() const {
return selectedProperties.size();
}
vector<string> ParallelCoordinatesGraphProxy::getSelectedProperties() {
vector<string> selectedPropertiesTmp;
vector<string>::iterator it;
// check if one of the selected properties has not been deleted by an undo operation
for (it = selectedProperties.begin() ; it != selectedProperties.end() ; ++it) {
if (existProperty(*it)) {
selectedPropertiesTmp.push_back(*it);
}
}
selectedProperties = selectedPropertiesTmp;
return selectedProperties;
}
void ParallelCoordinatesGraphProxy::setSelectedProperties(const vector<string>& properties) {
selectedProperties = properties;
}
void ParallelCoordinatesGraphProxy::removePropertyFromSelection(const std::string &propertyName) {
vector<string> selectedPropertiesCopy(selectedProperties);
vector<string>::iterator it;
selectedProperties.clear();
for (it = selectedPropertiesCopy.begin() ; it != selectedPropertiesCopy.end() ; ++it) {
if (*it != propertyName) {
selectedProperties.push_back(*it);
}
}
}
ElementType ParallelCoordinatesGraphProxy::getDataLocation() const {
return dataLocation;
}
unsigned int ParallelCoordinatesGraphProxy::getDataCount() const {
if (getDataLocation() == NODE) {
return numberOfNodes();
}
else {
return numberOfEdges();
}
}
Color ParallelCoordinatesGraphProxy::getDataColor(const unsigned int dataId) {
return getPropertyValueForData<ColorProperty, ColorType>("viewColor", dataId);
}
string ParallelCoordinatesGraphProxy::getDataTexture(const unsigned int dataId) {
return getPropertyValueForData<StringProperty, StringType>("viewTexture", dataId);
}
bool ParallelCoordinatesGraphProxy::isDataSelected(const unsigned int dataId) {
return getPropertyValueForData<BooleanProperty, BooleanType>("viewSelection", dataId);
}
void ParallelCoordinatesGraphProxy::setDataSelected(const unsigned int dataId, const bool dataSelected) {
setPropertyValueForData<BooleanProperty, BooleanType>("viewSelection", dataId, dataSelected);
}
Size ParallelCoordinatesGraphProxy::getDataViewSize(const unsigned int dataId) {
return getPropertyValueForData<SizeProperty, SizeType>("viewSize", dataId);
}
string ParallelCoordinatesGraphProxy::getDataLabel(const unsigned int dataId) {
return getPropertyValueForData<StringProperty, StringType>("viewLabel", dataId);
}
void ParallelCoordinatesGraphProxy::resetSelection() {
setPropertyValueForAllData<BooleanProperty, BooleanType>("viewSelection", false);
}
void ParallelCoordinatesGraphProxy::deleteData(const unsigned int dataId) {
if (getDataLocation() == NODE) {
delNode(node(dataId));
}
else {
delEdge(edge(dataId));
}
}
Iterator<unsigned int> *ParallelCoordinatesGraphProxy::getDataIterator() {
if (getDataLocation() == NODE) {
return new ParallelCoordinatesDataIterator<node>(getNodes());
}
else {
return new ParallelCoordinatesDataIterator<edge>(getEdges());
}
}
Iterator<unsigned int> *ParallelCoordinatesGraphProxy::getSelectedDataIterator() {
BooleanProperty *viewSelection = (BooleanProperty *) getProperty("viewSelection");
if (getDataLocation() == NODE) {
return new ParallelCoordinatesDataIterator<node>(viewSelection->getNodesEqualTo(true, graph_component));
}
else {
return new ParallelCoordinatesDataIterator<edge>(viewSelection->getEdgesEqualTo(true, graph_component));
}
}
Iterator<unsigned int> *ParallelCoordinatesGraphProxy::getUnselectedDataIterator() {
BooleanProperty *viewSelection = (BooleanProperty *) getProperty("viewSelection");
if (getDataLocation() == NODE) {
return new ParallelCoordinatesDataIterator<node>(viewSelection->getNodesEqualTo(false));
}
else {
return new ParallelCoordinatesDataIterator<edge>(viewSelection->getEdgesEqualTo(false));
}
}
string ParallelCoordinatesGraphProxy::getToolTipTextforData(const unsigned int dataId) {
string ttipText;
if (getDataLocation() == NODE) {
ttipText = "node ";
}
else {
ttipText = "edge ";
}
ttipText += getStringFromNumber(dataId);
string label = getDataLabel(dataId);
if (!label.empty()) {
ttipText = label + " (" + ttipText +")";
}
return ttipText;
}
void ParallelCoordinatesGraphProxy::addOrRemoveEltToHighlight(const unsigned int eltId) {
if (isDataHighlighted(eltId)) {
highlightedElts.erase(eltId);
}
else {
highlightedElts.insert(eltId);
}
}
void ParallelCoordinatesGraphProxy::unsetHighlightedElts() {
highlightedElts.clear();
}
void ParallelCoordinatesGraphProxy::resetHighlightedElts(const set<unsigned int> &highlightedData) {
highlightedElts.clear();
set<unsigned int>::iterator it;
for (it = highlightedData.begin() ; it != highlightedData.end() ; ++it) {
addOrRemoveEltToHighlight(*it);
}
}
bool ParallelCoordinatesGraphProxy::isDataHighlighted(const unsigned int dataId) {
return highlightedElts.find(dataId) != highlightedElts.end();
}
bool ParallelCoordinatesGraphProxy::highlightedEltsSet() const {
return !highlightedElts.empty();
}
void ParallelCoordinatesGraphProxy::selectHighlightedElements() {
set<unsigned int>::iterator it;
for (it = highlightedElts.begin() ; it != highlightedElts.end() ; ++it) {
setDataSelected(*it, true);
}
}
void ParallelCoordinatesGraphProxy::colorDataAccordingToHighlightedElts() {
static bool lastHighlightedElementsSet = false;
if (originalDataColors == NULL) {
return;
}
graphColorsChanged = false;
// If new colors have been set for the graph elements, backup the change to restore the correct ones
// when unhighlighting
if (highlightedEltsSet()) {
Iterator<unsigned int> *dataIt = getDataIterator();
while (dataIt->hasNext()) {
unsigned int dataId = dataIt->next();
Color currentColor = getPropertyValueForData<ColorProperty, ColorType>("viewColor", dataId);
Color originalColor;
if (getDataLocation() == NODE) {
originalColor = originalDataColors->getNodeValue(node(dataId));
}
else {
originalColor = originalDataColors->getEdgeValue(edge(dataId));
}
if (!isDataHighlighted(dataId) && currentColor.getA() != unhighlightedEltsColorAlphaValue) {
if (getDataLocation() == NODE) {
originalDataColors->setNodeValue(node(dataId), Color(currentColor.getR(), currentColor.getG(), currentColor.getB(), originalColor.getA()));
}
else {
originalDataColors->setEdgeValue(edge(dataId), Color(currentColor.getR(), currentColor.getG(), currentColor.getB(), originalColor.getA()));
}
Color newColor = getOriginalDataColor(dataId);
newColor.setA(unhighlightedEltsColorAlphaValue);
setPropertyValueForData<ColorProperty, ColorType>("viewColor", dataId, newColor);
}
if (highlightedEltsSet() && isDataHighlighted(dataId) && currentColor != originalColor) {
if (getDataLocation() == NODE) {
originalDataColors->setNodeValue(node(dataId), Color(currentColor.getR(), currentColor.getG(), currentColor.getB(), originalColor.getA()));
}
else {
originalDataColors->setEdgeValue(edge(dataId), Color(currentColor.getR(), currentColor.getG(), currentColor.getB(), originalColor.getA()));
}
setPropertyValueForData<ColorProperty, ColorType>("viewColor", dataId, getOriginalDataColor(dataId));
}
}
delete dataIt;
lastHighlightedElementsSet = true;
}
else if (lastHighlightedElementsSet) {
*(graph_component->getProperty<ColorProperty>("viewColor")) = *originalDataColors;
lastHighlightedElementsSet = false;
}
else {
*originalDataColors = *dataColors;
}
}
Color ParallelCoordinatesGraphProxy::getOriginalDataColor(const unsigned int dataId) {
if (getDataLocation() == NODE) {
return originalDataColors->getNodeValue(node(dataId));
}
else {
return originalDataColors->getEdgeValue(edge(dataId));
}
}
void ParallelCoordinatesGraphProxy::removeHighlightedElement(const unsigned int dataId) {
highlightedElts.erase(dataId);
}
void ParallelCoordinatesGraphProxy::update(std::set<Observable *>::iterator begin ,std::set<Observable *>::iterator end) {
(void) begin;
(void) end;
graphColorsChanged = true;
}
}
|