Skip to content

Commit b73528a

Browse files
committed
Add cli for outputting svg
1 parent 32ff4ef commit b73528a

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

bt_editor/main.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ main(int argc, char *argv[])
5656
"Autoconnect to monitor");
5757
parser.addOption(autoconnect_option);
5858

59+
QCommandLineOption file_option(QStringList() << "file",
60+
"Load a file (only in editor mode)",
61+
"tree.xml");
62+
parser.addOption(file_option);
63+
64+
QCommandLineOption output_svg_option(QStringList() << "output-svg",
65+
"Save the input file to an svg",
66+
"output.svg");
67+
parser.addOption(output_svg_option);
68+
5969
parser.process( app );
6070

6171
QFile styleFile( ":/stylesheet.qss" );
@@ -92,7 +102,7 @@ main(int argc, char *argv[])
92102
else{
93103
std::cout << "wrong mode passed to --mode. Use on of these: editor / monitor /replay"
94104
<< std::endl;
95-
return 0;
105+
return 1;
96106
}
97107
}
98108
else{
@@ -114,6 +124,52 @@ main(int argc, char *argv[])
114124
// Start the main application.
115125
MainWindow win( mode, monitor_address, monitor_pub_port,
116126
monitor_srv_port, monitor_autoconnect );
127+
128+
if( parser.isSet(file_option) )
129+
{
130+
if ( mode != GraphicMode::EDITOR )
131+
{
132+
std::cout << "--file can only be passed in editor mode" << std::endl;
133+
return 1;
134+
}
135+
136+
QString fileName = parser.value(file_option);
137+
std::cout << "Loading file: " << fileName.toStdString() << std::endl;
138+
139+
// Open file
140+
QFile file(fileName);
141+
if (!file.open(QIODevice::ReadOnly))
142+
{
143+
std::cout << "Cannot open file" << std::endl;
144+
return 1;
145+
}
146+
147+
// Read file to xml
148+
QString xml_text;
149+
QTextStream in(&file);
150+
while (!in.atEnd()) {
151+
xml_text += in.readLine();
152+
}
153+
154+
// Show xml
155+
win.loadFromXML( xml_text );
156+
}
157+
158+
159+
if( parser.isSet(output_svg_option) )
160+
{
161+
if ( !parser.isSet(file_option))
162+
{
163+
std::cout << "--output-svg needs the --file" << std::endl;
164+
return 1;
165+
}
166+
QString svgFile = parser.value(output_svg_option);
167+
168+
std::cout << "Writing to: " << svgFile.toStdString() << std::endl;
169+
win.currentTabInfo()->saveSvgFile(svgFile);
170+
return 0;
171+
}
172+
117173
win.show();
118174
return app.exec();
119175
}

0 commit comments

Comments
 (0)