Skip to content

Commit

Permalink
Merge pull request #35 from natir/master
Browse files Browse the repository at this point in the history
Add posibility to colors node in cli image generation
  • Loading branch information
rrwick authored Mar 18, 2017
2 parents 109c3cb + 53a7917 commit bf1d2ae
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

1 comment on commit bf1d2ae

@DAWells
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text refers to --color but it looks like the actual flag to use is --colors

Please sign in to comment.