Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
fix for issue #31 (API parameters consistency): add new Graph::applyP…
Browse files Browse the repository at this point in the history
…ropertyAlgorithm(const std::string &algorithm, PropertyInterface *result, std::string &errorMessage, DataSet *parameters = nullptr, PluginProgress *progress = nullptr) to be consistent with Graph::applyAlgorithm, and deprecate the previously existing version
  • Loading branch information
p-mary committed Jan 9, 2018
1 parent e6914d5 commit f7a3162
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 62 deletions.
36 changes: 20 additions & 16 deletions library/tulip-core/include/tulip/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,13 @@ class TLP_SCOPE Graph : public Observable {
* If an error occurs, a message describing the error should be stored in errorMessage.
*
* @param algorithm The algorithm to apply.
* @param errorMessage A string that will be modified to contain an error message should an error
*occur.
* @param dataSet The parameters to the algorithm. Defaults to nullptr.
* @param progress A PluginProgress to report the progress of the operation, as well as final
*state. Defaults to nullptr.
* @return bool Whether the algorithm was successfully applied.
* @param errorMessage A string that will be modified to contain an error message if an error occurs.
* @param parameters The parameters of the algorithm. Defaults to nullptr.
* @param progress A PluginProgress to report the progress of the operation, as well as the final state. Defaults to nullptr.
* @return bool Whether the algorithm applied successfully or not. If not, check the error message.
**/
bool applyAlgorithm(const std::string &algorithm, std::string &errorMessage,
DataSet *dataSet = nullptr, PluginProgress *progress = nullptr);
DataSet *parameters = nullptr, PluginProgress *progress = nullptr);

//=========================================================================
// Graph hierarchy access and building
Expand Down Expand Up @@ -1426,20 +1424,27 @@ class TLP_SCOPE Graph : public Observable {
* @brief Runs a plugin on the graph, whose result is a property.
*
* @param algorithm The name of the plugin to run.
* @param result The property in which to put the results. All previous values will be erased.
* @param result The property in which to store the computed nodes/edges associated values. All previous values will be erased.
* @param errorMessage Stores the error message if the plugin fails.
* @param progress A means of feedback during the plugin execution. Some plugins support being
* stopped or cancelled through this.
* @param parameters The parameters of the algorithm. Some algorithms use this DataSet to output
* @param progress A PluginProgress to report the progress of the operation, as well as the final state. Defaults to nullptr.
* some additional information.
* @return Whether the plugin executed successfully or not. If not, check the error message.
* @return Whether the plugin applied successfully or not. If not, check the error message.
*
* @see PluginLister::getPluginParameters() to retrieve the list of default parameters for the
* pligin.
* plugin.
*/
bool applyPropertyAlgorithm(const std::string &algorithm, PropertyInterface *result,
std::string &errorMessage, PluginProgress *progress = nullptr,
DataSet *parameters = nullptr);
std::string &errorMessage, DataSet *parameters = nullptr, PluginProgress *progress = nullptr);

/**
* @brief Deprecated, use applyPropertyAlgorithm(const std::string &algorithm, PropertyInterface *result, std::string &errorMessage, DataSet *parameters = nullptr, PluginProgress *progress = nullptr) instead
*/
_DEPRECATED bool applyPropertyAlgorithm(const std::string &algorithm, PropertyInterface *result,
std::string &errorMessage, PluginProgress *progress,
DataSet *parameters = nullptr) {
return applyPropertyAlgorithm(algorithm, result, errorMessage, parameters, progress);
}

// updates management
/**
Expand Down Expand Up @@ -1595,8 +1600,7 @@ class TLP_SCOPE Graph : public Observable {
bool delAllEdge = true);

/**
* @brief deprecated, use createMetaNode(const std::vector<node>&, bool multiEdges = true, bool
* delAllEdge = true) instead
* @brief Deprecated, use createMetaNode(const std::vector<node>&, bool multiEdges = true, bool delAllEdge = true) instead
*/
_DEPRECATED node createMetaNode(const std::set<node> &nodeSet, bool multiEdges = true,
bool delAllEdge = true);
Expand Down
12 changes: 7 additions & 5 deletions library/tulip-core/src/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ Iterator<Graph *> *tlp::getRootGraphs() {
}

bool Graph::applyAlgorithm(const std::string &algorithm, std::string &errorMessage,
DataSet *dataSet, PluginProgress *progress) {
DataSet *parameters, PluginProgress *progress) {
if (!PluginLister::pluginExists(algorithm)) {
tlp::warning() << "libtulip: " << __FUNCTION__ << ": algorithm plugin \"" << algorithm
<< "\" does not exist (or is not loaded)" << endl;
Expand All @@ -687,7 +687,7 @@ bool Graph::applyAlgorithm(const std::string &algorithm, std::string &errorMessa
} else
tmpProgress = progress;

AlgorithmContext *context = new AlgorithmContext(this, dataSet, tmpProgress);
AlgorithmContext *context = new AlgorithmContext(this, parameters, tmpProgress);
Algorithm *newAlgo = PluginLister::instance()->getPluginObject<Algorithm>(algorithm, context);

if ((result = newAlgo->check(errorMessage))) {
Expand All @@ -707,9 +707,11 @@ bool Graph::applyAlgorithm(const std::string &algorithm, std::string &errorMessa
}

//=========================================================
bool tlp::Graph::applyPropertyAlgorithm(const std::string &algorithm, PropertyInterface *prop,
std::string &errorMessage, tlp::PluginProgress *progress,
tlp::DataSet *parameters) {
bool tlp::Graph::applyPropertyAlgorithm(const std::string &algorithm,
PropertyInterface *prop,
std::string &errorMessage,
tlp::DataSet *parameters,
tlp::PluginProgress *progress) {
bool result;
tlp::AlgorithmContext context;

Expand Down
8 changes: 4 additions & 4 deletions plugins/clustering/QuotientClustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ class QuotientClustering : public tlp::Algorithm {
layoutParams.set("Unit edge length", std::max(maxSize[0], maxSize[1]) * 5.0);
cluster->applyPropertyAlgorithm(layoutName,
cluster->getLocalProperty<LayoutProperty>("viewLayout"),
errMsg, nullptr, &layoutParams);
errMsg, &layoutParams);
double border = std::min(minSize[0], minSize[1]);
layoutParams.set("x border", border);
layoutParams.set("y border", border);
cluster->applyPropertyAlgorithm("Fast Overlap Removal",
cluster->getLocalProperty<LayoutProperty>("viewLayout"),
errMsg, nullptr, &layoutParams);
errMsg, &layoutParams);
}
}

Expand Down Expand Up @@ -376,13 +376,13 @@ class QuotientClustering : public tlp::Algorithm {
layoutParams.set("Unit edge length", std::max(maxSize[0], maxSize[1]) * 2.0);
quotientGraph->applyPropertyAlgorithm(
layoutName, quotientGraph->getLocalProperty<LayoutProperty>("viewLayout"), errMsg,
nullptr, &layoutParams);
&layoutParams);
double border = std::min(minSize[0], minSize[1]);
layoutParams.set("x border", border);
layoutParams.set("y border", border);
quotientGraph->applyPropertyAlgorithm(
"Fast Overlap Removal", quotientGraph->getLocalProperty<LayoutProperty>("viewLayout"),
errMsg, nullptr, &layoutParams);
errMsg, &layoutParams);
}

// recursive call if needed
Expand Down
2 changes: 1 addition & 1 deletion plugins/clustering/StrengthClustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ bool StrengthClustering::run() {
string errMsg;
values = new DoubleProperty(graph);

if (!graph->applyPropertyAlgorithm("Strength", values, errMsg, pluginProgress))
if (!graph->applyPropertyAlgorithm("Strength", values, errMsg, nullptr, pluginProgress))
return false;

NumericProperty *metric = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions plugins/import/BibTeX/ImportBibTeX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2078,8 +2078,8 @@ class ImportBibTeX : public ImportModule {
graph->delLocalProperty(fromLabriProp->getName());

string err;
return graph->applyPropertyAlgorithm(
"FM^3 (OGDF)", graph->getProperty<LayoutProperty>("viewLayout"), err, pluginProgress);
return graph->applyPropertyAlgorithm("FM^3 (OGDF)", graph->getProperty<LayoutProperty>("viewLayout"),
err, nullptr, pluginProgress);
}

return true;
Expand Down
3 changes: 1 addition & 2 deletions plugins/import/CompleteTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ class CompleteTree : public ImportModule {

if (needLayout) {
// apply Tree Leaf
DataSet dSet;
string errMsg;
LayoutProperty *layout = graph->getProperty<LayoutProperty>("viewLayout");
return graph->applyPropertyAlgorithm("Tree Leaf", layout, errMsg, pluginProgress, &dSet);
return graph->applyPropertyAlgorithm("Tree Leaf", layout, errMsg, nullptr, pluginProgress);
}

return true;
Expand Down
6 changes: 3 additions & 3 deletions plugins/import/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ class FileSystem : public tlp::ImportModule {
if (_treeLayout) {
const std::string algoName = "Bubble Tree";
tlp::DataSet defaultParameters = getDefaultAlgorithmParameters(algoName, graph);
tlp::LayoutProperty *viewLayout = graph->getProperty<tlp::LayoutProperty>("viewLayout");
std::string errMsg;
graph->applyPropertyAlgorithm(algoName, viewLayout, errMsg, pluginProgress,
&defaultParameters);
tlp::LayoutProperty *viewLayout = graph->getProperty<tlp::LayoutProperty>("viewLayout");
graph->applyPropertyAlgorithm(algoName, viewLayout, errMsg,
&defaultParameters, pluginProgress);
}

return true;
Expand Down
3 changes: 1 addition & 2 deletions plugins/import/RandomTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ class RandomTree : public ImportModule {

if (needLayout) {
// apply Tree Leaf
DataSet dSet;
string errMsg;
LayoutProperty *layout = graph->getProperty<LayoutProperty>("viewLayout");
return graph->applyPropertyAlgorithm("Tree Leaf", layout, errMsg, pluginProgress, &dSet);
return graph->applyPropertyAlgorithm("Tree Leaf", layout, errMsg, nullptr, pluginProgress);
}

return true;
Expand Down
3 changes: 1 addition & 2 deletions plugins/import/RandomTreeGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,9 @@ class RandomTreeGeneral : public ImportModule {

if (needLayout) {
// apply Tree Leaf
DataSet dSet;
string errMsg;
LayoutProperty *layout = graph->getProperty<LayoutProperty>("viewLayout");
return graph->applyPropertyAlgorithm("Tree Leaf", layout, errMsg, pluginProgress, &dSet);
return graph->applyPropertyAlgorithm("Tree Leaf", layout, errMsg, nullptr, pluginProgress);
}

return true;
Expand Down
3 changes: 1 addition & 2 deletions plugins/import/WebImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,8 @@ struct WebImport : public ImportModule {
pluginProgress->setComment("Layouting extracted graph using FM³...");
string errMsg;
// apply FM³
DataSet tmp;
LayoutProperty *layout = graph->getProperty<LayoutProperty>("viewLayout");
return graph->applyPropertyAlgorithm("FM^3 (OGDF)", layout, errMsg, pluginProgress, &tmp);
return graph->applyPropertyAlgorithm("FM^3 (OGDF)", layout, errMsg, nullptr, pluginProgress);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void NodeNeighborhoodView::getNeighbors(node n, unsigned int dist, bool noRecurs
BooleanProperty result(graph_component);
string errorMsg;
graph_component->applyPropertyAlgorithm(tlp::SelectionAlgorithm::ReachableSubGraphSelection,
&result, errorMsg, nullptr, &dataSet);
&result, errorMsg, &dataSet);

graphViewNodes.clear();
graphViewEdges.clear();
Expand Down
2 changes: 1 addition & 1 deletion plugins/layout/BubblePack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool BubblePack::run() {

for (unsigned int i = 0; i < components.size(); ++i) {
Graph *tmp = graph->inducedSubGraph(components[i]);
tmp->applyPropertyAlgorithm("Bubble Pack", result, err, pluginProgress, dataSet);
tmp->applyPropertyAlgorithm("Bubble Pack", result, err, dataSet, pluginProgress);
}

// call connected component packing
Expand Down
6 changes: 3 additions & 3 deletions plugins/layout/BubbleTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,15 @@ bool BubbleTree::run() {

for (unsigned int i = 0; i < components.size(); ++i) {
Graph *tmp = graph->inducedSubGraph(components[i]);
tmp->applyPropertyAlgorithm("Bubble Tree", result, err, pluginProgress, dataSet);
tmp->applyPropertyAlgorithm("Bubble Tree", result, err, dataSet, pluginProgress);
}

// call connected component packing
LayoutProperty tmpLayout(graph);
DataSet tmpdataSet;
tmpdataSet.set("coordinates", result);
graph->applyPropertyAlgorithm("Connected Component Packing", &tmpLayout, err, pluginProgress,
&tmpdataSet);
graph->applyPropertyAlgorithm("Connected Component Packing", &tmpLayout,
err, &tmpdataSet, pluginProgress);
// forget last temporary graph state
graph->pop();
*result = tmpLayout;
Expand Down
6 changes: 3 additions & 3 deletions plugins/layout/GEMLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ bool GEMLayout::run() {

for (size_t i = 0; i < components.size(); ++i) {
Graph *tmp = graph->inducedSubGraph(components[i]);
tmp->applyPropertyAlgorithm("GEM (Frick)", result, err, pluginProgress, dataSet);
tmp->applyPropertyAlgorithm("GEM (Frick)", result, err, dataSet, pluginProgress);
}

// call connected component packing
LayoutProperty tmpLayout(graph);
DataSet ds;
ds.set("coordinates", result);
graph->applyPropertyAlgorithm("Connected Component Packing", &tmpLayout, err, pluginProgress,
&ds);
graph->applyPropertyAlgorithm("Connected Component Packing", &tmpLayout,
err, &ds, pluginProgress);
// forget last temporary graph state
graph->pop();
*result = tmpLayout;
Expand Down
3 changes: 2 additions & 1 deletion plugins/layout/Grip/Grip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ bool Grip::run() {
DataSet tmp;
tmp.set("coordinates", result);
LayoutProperty layout(graph);
graph->applyPropertyAlgorithm("Connected Component Packing", &layout, err, nullptr, &tmp);
graph->applyPropertyAlgorithm("Connected Component Packing", &layout,
err, &tmp);

for (const node &n : graph->nodes()) {
result->setNodeValue(n, layout.getNodeValue(n));
Expand Down
4 changes: 2 additions & 2 deletions plugins/layout/HierarchicalGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ bool HierarchicalGraph::run() {
#ifndef NDEBUG
resultBool =
#endif
mySGraph->applyPropertyAlgorithm("Hierarchical Tree (R-T Extended)", &tmpLayout, erreurMsg,
nullptr, &tmp);
mySGraph->applyPropertyAlgorithm("Hierarchical Tree (R-T Extended)",
&tmpLayout, erreurMsg, &tmp);

if (edgeLength)
delete edgeLength;
Expand Down
4 changes: 2 additions & 2 deletions plugins/layout/MixedModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ bool MixedModel::run() {
LayoutProperty layout(graph);
DataSet tmp;
tmp.set("coordinates", result);
graph->applyPropertyAlgorithm(string("Connected Component Packing"), &layout, err, nullptr,
&tmp);
graph->applyPropertyAlgorithm(string("Connected Component Packing"),
&layout, err, &tmp);

for (const node &n : graph->nodes()) {
result->setNodeValue(n, layout.getNodeValue(n));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void AlgorithmRunnerItem::afterRun(Graph *g, const tlp::DataSet &dataSet) {
cs = ColorScalesManager::getLatestColorScale();

data.set<ColorScale>("color scale", cs);
g->applyPropertyAlgorithm("Color Mapping", color, errMsg, nullptr, &data);
g->applyPropertyAlgorithm("Color Mapping", color, errMsg, &data);
}
} else if (pluginLister->pluginExists<GraphTest>(stdName)) {
bool result = true;
Expand Down
2 changes: 1 addition & 1 deletion plugins/view/TableView/PropertiesEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void PropertiesEditor::toLabels(PropertyInterface *prop, bool nodes, bool edges,
// _graph->push() must be done outside of this method
// to allow call from TabelView.cpp
StringProperty *result = _graph->getProperty<StringProperty>("viewLabel");
_graph->applyPropertyAlgorithm("To labels", result, msg, nullptr, &data);
_graph->applyPropertyAlgorithm("To labels", result, msg, &data);
}

void PropertiesEditor::checkStateChanged(QModelIndex index, Qt::CheckState state) {
Expand Down
10 changes: 5 additions & 5 deletions tests/plugins/BasicLayoutTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void BasicLayoutTest::testDendrogram() {
ds.set("node size", &size);
LayoutProperty layout(graph);
string errorMsg;
bool result = graph->applyPropertyAlgorithm("Dendrogram", &layout, errorMsg, nullptr, &ds);
bool result = graph->applyPropertyAlgorithm("Dendrogram", &layout, errorMsg, &ds);
CPPUNIT_ASSERT(result);
}
//==========================================================
Expand Down Expand Up @@ -122,7 +122,7 @@ void BasicLayoutTest::testMixedModel() {
ds.set("node size", &size);
LayoutProperty layout(graph);
string errorMsg;
bool result = graph->applyPropertyAlgorithm("Mixed Model", &layout, errorMsg, nullptr, &ds);
bool result = graph->applyPropertyAlgorithm("Mixed Model", &layout, errorMsg, &ds);
CPPUNIT_ASSERT(result);
}
//==========================================================
Expand All @@ -141,7 +141,7 @@ void BasicLayoutTest::testSquarifiedTreeMap() {

LayoutProperty layout(graph);
ds.set("metric", &metric);
result = graph->applyPropertyAlgorithm("Squarified Tree Map", &layout, errorMsg, nullptr, &ds);
result = graph->applyPropertyAlgorithm("Squarified Tree Map", &layout, errorMsg, &ds);
CPPUNIT_ASSERT(result);
}
//==========================================================
Expand All @@ -152,7 +152,7 @@ void BasicLayoutTest::testTreeLeaf() {
ds.set("node size", &size);
LayoutProperty layout(graph);
string errorMsg;
bool result = graph->applyPropertyAlgorithm("Tree Leaf", &layout, errorMsg, nullptr, &ds);
bool result = graph->applyPropertyAlgorithm("Tree Leaf", &layout, errorMsg, &ds);
CPPUNIT_ASSERT(result);
}
//==========================================================
Expand Down Expand Up @@ -194,6 +194,6 @@ void BasicLayoutTest::testFastOverlapRemoval() {
ds.set("layout", &layout);
string errorMsg;
bool result =
graph->applyPropertyAlgorithm("Fast Overlap Removal", &layout, errorMsg, nullptr, &ds);
graph->applyPropertyAlgorithm("Fast Overlap Removal", &layout, errorMsg, &ds);
CPPUNIT_ASSERT(result);
}
6 changes: 3 additions & 3 deletions tests/plugins/BasicPluginsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void BasicPluginsTest::testMetricColorMapping() {
DataSet ds;
ds.set("linear/uniform\nproperty", &metric);
ColorProperty color(graph);
result = graph->applyPropertyAlgorithm("Color Mapping", &color, errorMsg, nullptr, &ds);
result = graph->applyPropertyAlgorithm("Color Mapping", &color, errorMsg, &ds, nullptr);
CPPUNIT_ASSERT(result);
}
//==========================================================
Expand Down Expand Up @@ -378,7 +378,7 @@ void BasicPluginsTest::testMetricSizeMapping() {

SizeProperty size(graph);
ds.set("property", &metric);
result = graph->applyPropertyAlgorithm("Size Mapping", &size, errorMsg, nullptr, &ds);
result = graph->applyPropertyAlgorithm("Size Mapping", &size, errorMsg, &ds, nullptr);
CPPUNIT_ASSERT(result);
}
//==========================================================
Expand Down Expand Up @@ -419,7 +419,7 @@ void BasicPluginsTest::testEqualValueClustering() {

PluginProgress *progress = new SimplePluginProgress();
initializeGraph("Planar Graph");
result = graph->applyPropertyAlgorithm("Degree", metric, errorMsg, progress);
result = graph->applyPropertyAlgorithm("Degree", metric, errorMsg, nullptr, progress);
CPPUNIT_ASSERT_MESSAGE(errorMsg, result);
result = graph->applyAlgorithm(algorithmName, errorMsg, &ds);
CPPUNIT_ASSERT_MESSAGE(errorMsg, result);
Expand Down

0 comments on commit f7a3162

Please sign in to comment.