Skip to content

Commit

Permalink
Add posibility to colors node in cli image generation
Browse files Browse the repository at this point in the history
  • Loading branch information
natir committed Feb 5, 2017
1 parent 5dfec5c commit 53a7917
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions command_line/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -212,6 +232,7 @@ void printImageUsage(QTextStream * out, bool all)
text << "";
text << "Options: --height <int> Image height (default: 1000)";
text << "--width <int> Image width (default: not set)";
text << "--color <file> 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 << "";
Expand All @@ -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);
}

Expand All @@ -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;
}
1 change: 1 addition & 0 deletions command_line/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 53a7917

Please sign in to comment.