From 53a791741d1918051ec9b7638490fe0c3f3994ec Mon Sep 17 00:00:00 2001 From: Marijon Pierre Date: Fri, 3 Feb 2017 15:00:31 +0100 Subject: [PATCH] Add posibility to colors node in cli image generation --- command_line/image.cpp | 36 ++++++++++++++++++++++++++++++++++++ command_line/image.h | 1 + 2 files changed, 37 insertions(+) diff --git a/command_line/image.cpp b/command_line/image.cpp index fcd89861..a8a8505f 100644 --- a/command_line/image.cpp +++ b/command_line/image.cpp @@ -130,6 +130,26 @@ int bandageImage(QStringList arguments) g_settings->startingNodes, "all"); + QString errormsg; + QStringList columns; + bool coloursLoaded = false; + QString csvPath = parseColorsOption(arguments); + if (csvPath != "") + { + if(!g_assemblyGraph->loadCSV(csvPath, &columns, &errormsg, &coloursLoaded)) + { + err << errormsg << endl; + return 1; + } + + if(coloursLoaded == false) + { + err << csvPath << " didn't contains color" << endl; + return 1; + } + g_settings->nodeColourScheme = CUSTOM_COLOURS; + } + if (errorMessage != "") { err << errorMessage << endl; @@ -212,6 +232,7 @@ void printImageUsage(QTextStream * out, bool all) text << ""; text << "Options: --height Image height (default: 1000)"; text << "--width Image width (default: not set)"; + text << "--color csv file with 2 column first the node name second the node color"; text << ""; text << "If only height or width is set, the other will be determined automatically. If both are set, the image will be exactly that size."; text << ""; @@ -232,6 +253,9 @@ QString checkForInvalidImageOptions(QStringList arguments) error = checkOptionForInt("--width", &arguments, IntSetting(0, 1, 32767), false); if (error.length() > 0) return error; + error = checkOptionForString("--colors", &arguments, QStringList(), "a path of csv file"); + if (error.length() > 0) return error; + return checkForInvalidOrExcessSettings(&arguments); } @@ -251,3 +275,15 @@ void parseImageOptions(QStringList arguments, int * width, int * height) parseSettings(arguments); } +//This function parses the command line options. It assumes that the options +//have already been checked for correctness. +QString parseColorsOption(QStringList arguments) +{ + QString path = ""; + if (isOptionPresent("--colors", &arguments)) + path = getStringOption("--colors", &arguments); + + parseSettings(arguments); + + return path; +} diff --git a/command_line/image.h b/command_line/image.h index 41d26291..59af21c9 100644 --- a/command_line/image.h +++ b/command_line/image.h @@ -28,5 +28,6 @@ int bandageImage(QStringList arguments); void printImageUsage(QTextStream * out, bool all); QString checkForInvalidImageOptions(QStringList arguments); void parseImageOptions(QStringList arguments, int * width, int * height); +QString parseColorsOption(QStringList arguments); #endif // IMAGE_H