File: HistogramInteractors.cpp

package info (click to toggle)
tulip 4.8.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 179,264 kB
  • ctags: 64,517
  • sloc: cpp: 600,444; ansic: 36,311; makefile: 22,136; python: 1,304; sh: 946; yacc: 522; xml: 337; pascal: 157; php: 66; lex: 55
file content (207 lines) | stat: -rw-r--r-- 12,593 bytes parent folder | download
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
/**
*
* 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/MouseInteractors.h>
#include <tulip/MouseShowElementInfos.h>
#include <tulip/GraphElementModel.h>

#include "HistogramMetricMapping.h"
#include "HistogramStatistics.h"
#include "HistogramInteractors.h"
#include "HistogramViewNavigator.h"
#include "HistoStatsConfigWidget.h"
#include "HistogramView.h"

#include "../../utils/StandardInteractorPriority.h"
#include "../../utils/ViewNames.h"

namespace tlp {

HistogramInteractor::HistogramInteractor(const QString &iconPath, const QString &text) : NodeLinkDiagramComponentInteractor(iconPath, text) {}

bool HistogramInteractor::isCompatible(const std::string &viewName) const {
  return (viewName == ViewName::HistogramViewName);
}

PLUGIN(HistogramInteractorNavigation)
PLUGIN(HistogramInteractorMetricMapping)
PLUGIN(HistogramInteractorStatistics)
PLUGIN(HistogramInteractorGetInformation)

HistogramInteractorNavigation::HistogramInteractorNavigation(const PluginContext *) : HistogramInteractor(":/tulip/gui/icons/i_navigation.png", "Navigate in view") {
  setConfigurationWidgetText(QString("<html><head><title></title></head><body><h3>View navigation interactor</h3>")
                             +"<p>This interactor allows to navigate in the histogram view.</p>"
                             +"<p>When there is more than one graph properties selected, the corresponding histograms previews are generated and displayed in a matrix form. By <b>double clicking on an histogram,"
                             +"this one is displayed in fullscreen </b> in a more detailed way and the others interactors become available. To go back to the histograms previews matrix, double click anywhere in the view.</p>"
                             +"<p>Otherwise, this interactor offers the same functionnalities as the one in the \"Node Link Diagram view\". The commands are described below :</p>"
                             +"<b>Ctrl + Mouse up/down</b> : zoom<br>"
                             +"<b>Ctrl + Mouse left/right</b> : z rotation<br>"
                             +"<b>Shift + Mouse</b> : rotation<br>"
                             +"<b>Key up/down</b> : up/down<br>"
                             +"<b>Key left/right</b> : left/right<br>"
                             +"<b>Key page up/down</b> : zoom<br>"
                             +"<b>Key insert</b> : rotate<br>"
                             +"</body></html>");
  setPriority(StandardInteractorPriority::Navigation);
}

void HistogramInteractorNavigation::construct() {
  push_back(new HistogramViewNavigator);
  push_back(new MouseNKeysNavigator);
}

HistogramInteractorMetricMapping::HistogramInteractorMetricMapping(const PluginContext* ) : HistogramInteractor(":/i_histo_color_mapping.png", "Metric Mapping") {
  setConfigurationWidgetText(QString ("<html><head><title></title></head><body>")
                             +"<h3>Metric mapping interactor</h3>"
                             +"<p>This interactor allows to perform a metric mapping on nodes colors, nodes borders colors, nodes sizes, nodes borders widths or nodes glyphs in a visual way.</p>"
                             +"<p>To select the mapping type, do a right click on the scale located at the left of the histogram vertical axis and pick the one wanted in the popup menu which appears.</p>"
                             +"<p>To configure the metric mapping, double click on the scale located at the left of the histogram vertical axis and use the dialog which appears.</p>"
                             +"<h4>Color mapping configuration</h4>"
                             +"<p>The configuration dialog for the color mapping is illustrated below.<br />"
                             +"<img src=\":/ColorScaleConfigDialog.png\" width=\"280\" height=\"260\" border=\"0\" alt=\"\"><br />"
                             +"The first tab of this dialog allows to manually define a color scale. To do so, start by picking the number of colors to use by using the spinbox located above the colors table. "
                             +"To select the colors to use, double click on the cells of the colors table and a color picker dialog will appear. A preview of the built color scale is displayed at the right of the color table.<br />"
                             +"The built color scale can be saved using the \"Save color scale\" button.<br /><br />"
                             +"<img src=\":/ColorScaleConfigDialog2.png\" width=\"280\" height=\"260\" border=\"0\" alt=\"\"><br />"
                             +"The second tab of the dialog allow to load a previously saved color scale and give also the possibility to load a color scale from an image file (the color scale must be defined in the vertical dimension of the image). "
                             +"Previously saved color scale can be reedit by double clicking on it. <br />"
                             +"Once the color scale to use has been selected or configured, press the \"Ok\" button.</p>"
                             +"<h4>Size mapping configuration</h4>"
                             +"<p>The configuration dialog for the size mapping is illustrated below.<br />"
                             +"<img src=\":/SizeScaleConfigDialog.png\" width=\"280\" height=\"280\" border=\"0\" alt=\"\"><br />"
                             +"The top part of the dialog allows to select on which size property the mapping has to be performed : <i>viewSize</i> or <i>viewBorderWidth</i>.<br />"
                             +"The middle part of the dialog aims to configure the minimum and maximum size to use for the mapping.<br />"
                             +"The bottom part of the dialog allows to select on which dimensions the size mapping has to be applied when it is performed on the viewSize property.<br />"
                             +"Once the wanted parameters have been set, press the \"OK\" button to apply them.</p>"
                             +"<h4>Glyph mapping configuration</h4>"
                             +"<p>The configuration dialog for the size mapping is illustrated below.<br />"
                             +"<img src=\":/GlyphScaleConfigDialog.png\" width=\"280\" height=\"280\" border=\"0\" alt=\"\"><br />"
                             +"Use the spin box located at the top of the dialog to define the number of nodes glyphs to use for the mapping. <br/>"
                             +"Select the glyphs to use by the help of the combo boxes contained in the cells of the table.<br />"
                             +"Press the \"OK\" button to apply the settings. </p>"
                             +"<h4>Metric mapping instructions</h4>"
                             +"<p>The metric mapping is done with the help of the editable curve drawn on top of the histogram. By double clicking on it, control points are created which allow to modify the curve shape (by drag and drop them) and so the metric mapping. The created control points can also be removed by double clicking on them. </p>"
                             +"<p>The mapping performed can be visually interpreted as followed. For each node of the graph, get the value of the metric property associated with the current displayed histogram. "
                             +"Take the line perpendicular to the horizontal axis of the histogram (the metric axis) which passes by the point on the metric axis associated with the node metric value. "
                             +"Then take the intersection point between this line and the curve controlling the mapping. The value of the metric is then mapped on the node visual property associated to the y coordinates of this intersection point according to the scale located at the left of the histogram vertical axis (which can be a color, a size or a glyph scale). <br />"
                             +"The corresponding mapping on the whole graph metric is materialized by the scale located under the histogram horizontal axis. "
                             +"For example, if the curve is a straight line between the bottom left corner and the top right corner of the histogram, a linear mapping is performed on the metric. "
                             +"More complex mapping can be performed like the color mapping illustrated below.<br />"
                             +"<img src=\":/HistoColorMapping.png\" width=\"280\" height=\"260\" border=\"0\" alt=\"\"><br />"
                             +"</p>"
                             +"</body></html>");
  setPriority(StandardInteractorPriority::ViewInteractor1);
}

void HistogramInteractorMetricMapping::construct() {

  push_back(new HistogramMetricMapping);
  push_back(new MousePanNZoomNavigator);
}

HistogramInteractorStatistics::HistogramInteractorStatistics(const PluginContext *) : HistogramInteractor(":/i_histo_statistics.png", "Statistics"),histoStatsConfigWidget(NULL), histoStatistics(NULL) {
  setPriority(StandardInteractorPriority::ViewInteractor2);
}

HistogramInteractorStatistics::~HistogramInteractorStatistics() {
  delete histoStatsConfigWidget;
}

void HistogramInteractorStatistics::construct() {
  histoStatsConfigWidget = new HistoStatsConfigWidget();
  histoStatistics = new HistogramStatistics(histoStatsConfigWidget);
  push_back(histoStatistics);
  push_back(new MousePanNZoomNavigator);
}

QWidget *HistogramInteractorStatistics::configurationWidget() const {
  return histoStatsConfigWidget;
}

void HistogramInteractorStatistics::install(QObject *target) {
  if(target!=NULL) {
    histoStatistics->computeInteractor();
  }
}

/**
 * We define a specific interactor to show element graph infos
 */
class HistogramMouseShowElementInfos : public MouseShowElementInfos {
  HistogramView* hView;
public:
  HistogramMouseShowElementInfos()
    :MouseShowElementInfos(), hView(NULL) {}
  ~HistogramMouseShowElementInfos() {}


  void viewChanged(View *v) {
    hView = (HistogramView *) v;
    MouseShowElementInfos::viewChanged(v);
  }

protected:
  /**
   * @brief buildModel create and returns the model to visualize edit elements parameters.
   * @param elementType the type of the element can be NODE or EDGE
   * @param elementId elementId the id of the element
   * @param parent the parent for the model creation.
   * @return
   */
  virtual QAbstractItemModel* buildModel(ElementType elementType, unsigned int elementId, QObject *parent) const {
    if (hView->getDataLocation() == EDGE) {
      elementId = hView->getMappedId(elementId);
      return new GraphEdgeElementModel(hView->graph(), elementId, parent);
    }

    return MouseShowElementInfos::buildModel(elementType, elementId, parent);
  }

  /**
   * @brief elementName returns the title of the element.
   * @param elementType the type of the element can be NODE or EDGE
   * @param elementId the id of the element
   * @return
   */
  virtual QString elementName(ElementType elementType, unsigned int elementId) const {
    if (hView->getDataLocation() == EDGE) {
      elementId = hView->getMappedId(elementId);
      return QString("Edge") + " #" + QString::number(elementId);
    }

    return MouseShowElementInfos::elementName(elementType, elementId);
  }
};

HistogramInteractorGetInformation::HistogramInteractorGetInformation(const tlp::PluginContext*):NodeLinkDiagramComponentInteractor(":/tulip/gui/icons/i_select.png","Display node or edge properties") {
  setPriority(StandardInteractorPriority::GetInformation);
  setConfigurationWidgetText(QString("<h3>Display node or edge properties</h3>")+
                             "<b>Mouse left click</b> on an element to display its properties.<br/>then <b>Mouse left click</b> on a row to edit the corresponding value.");
}

void HistogramInteractorGetInformation::construct() {
  push_back(new MousePanNZoomNavigator);
  push_back(new HistogramMouseShowElementInfos);
}

bool HistogramInteractorGetInformation::isCompatible(const std::string &viewName) const {
  return (viewName==ViewName::HistogramViewName);
}

}