Skip to content

Commit

Permalink
Add cli for outputting svg
Browse files Browse the repository at this point in the history
  • Loading branch information
Timple committed Jan 25, 2023
1 parent 9afa30e commit cf121fa
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion bt_editor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ main(int argc, char *argv[])
"Start in one of these modes: [editor,monitor,replay]",
"mode");
parser.addOption(mode_option);

QCommandLineOption file_option(QStringList() << "file",
"Load a file (only in editor mode)",
"tree.xml");
parser.addOption(file_option);

QCommandLineOption output_svg_option(QStringList() << "output-svg",
"Save the input file to an svg",
"output.svg");
parser.addOption(output_svg_option);
parser.process( app );

QFile styleFile( ":/stylesheet.qss" );
Expand Down Expand Up @@ -75,7 +85,7 @@ main(int argc, char *argv[])
else{
std::cout << "wrong mode passed to --mode. Use on of these: editor / monitor /replay"
<< std::endl;
return 0;
return 1;
}
}
else{
Expand All @@ -89,6 +99,52 @@ main(int argc, char *argv[])
}

MainWindow win( mode );

if( parser.isSet(file_option) )
{
if ( mode != GraphicMode::EDITOR )
{
std::cout << "--file can only be passed in editor mode" << std::endl;
return 1;
}

QString fileName = parser.value(file_option);
std::cout << "Loading file: " << fileName.toStdString() << std::endl;

// Open file
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
{
std::cout << "Cannot open file" << std::endl;
return 1;
}

// Read file to xml
QString xml_text;
QTextStream in(&file);
while (!in.atEnd()) {
xml_text += in.readLine();
}

// Show xml
win.loadFromXML( xml_text );
}


if( parser.isSet(output_svg_option) )
{
if ( !parser.isSet(file_option))
{
std::cout << "--output-svg needs the --file" << std::endl;
return 1;
}
QString svgFile = parser.value(output_svg_option);

std::cout << "Writing to: " << svgFile.toStdString() << std::endl;
win.currentTabInfo()->saveSvgFile(svgFile);
return 0;
}

win.show();
return app.exec();
}
Expand Down

0 comments on commit cf121fa

Please sign in to comment.