Skip to content

Commit

Permalink
Replaced concatenation of directory + filename strings with Glib::bui…
Browse files Browse the repository at this point in the history
…ld_filename
  • Loading branch information
corna committed Apr 7, 2015
1 parent c9a645d commit da2ef6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
27 changes: 9 additions & 18 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ using Glib::ustring;
#include <glibmm/init.h>
#include <gdkmm/wrap_init.h>

#include <glibmm/miscutils.h>
using Glib::build_filename;

#include "gerberimporter.hpp"
#include "surface.hpp"
#include "ngc_exporter.hpp"
Expand Down Expand Up @@ -105,22 +108,10 @@ int main(int argc, char* argv[]) {

unit = vm["metric"].as<bool>() ? (1. / 25.4) : 1;

//---------------------------------------------------------------------------
//add trailing /

string outputdir = vm["output-dir"].as<string>();

#ifdef __unix__
if ( !outputdir.empty() && *outputdir.rbegin() != '/' )
outputdir += '/';
#else
if ( !outputdir.empty() && *outputdir.rbegin() != '/' && *outputdir.rbegin() != '\\' )
outputdir += '\\';
#endif

//---------------------------------------------------------------------------
//prepare environment:

const string outputdir = vm["output-dir"].as<string>();
shared_ptr<Isolator> isolator;

if (vm.count("front") || vm.count("back")) {
Expand Down Expand Up @@ -318,7 +309,7 @@ int main(int argc, char* argv[]) {

if (vm.count("svg")) {
cout << "Create SVG File ... " << vm["svg"].as<string>() << endl;
svgexpo->create_svg(outputdir + vm["svg"].as<string>());
svgexpo->create_svg( build_filename(outputdir, vm["svg"].as<string>()) );
}

shared_ptr<NGC_Exporter> exporter(new NGC_Exporter(board));
Expand Down Expand Up @@ -398,12 +389,12 @@ int main(int argc, char* argv[]) {
cout << "DONE.\n";

if (vm["milldrill"].as<bool>()) {
ep.export_ngc(outputdir + vm["drill-output"].as<string>(), cutter,
!vm["drill-front"].as<bool>(), vm["mirror-absolute"].as<bool>(),
ep.export_ngc( build_filename(outputdir, vm["drill-output"].as<string>()),
cutter, !vm["drill-front"].as<bool>(), vm["mirror-absolute"].as<bool>(),
vm["onedrill"].as<bool>());
} else {
ep.export_ngc(outputdir + vm["drill-output"].as<string>(), driller,
vm["drill-front"].as<bool>(), vm["mirror-absolute"].as<bool>(),
ep.export_ngc( build_filename(outputdir, vm["drill-output"].as<string>()),
driller, vm["drill-front"].as<bool>(), vm["mirror-absolute"].as<bool>(),
vm["onedrill"].as<bool>(), vm["nog81"].as<bool>());
}

Expand Down
13 changes: 4 additions & 9 deletions ngc_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
#include <iomanip>
using namespace std;

#include <glibmm/miscutils.h>
using Glib::build_filename;

/******************************************************************************/
/*
*/
Expand Down Expand Up @@ -95,14 +98,6 @@ void NGC_Exporter::export_all(boost::program_options::variables_map& options) {

//set imperial/metric conversion factor for output coordinates depending on metricoutput option
cfactor = bMetricoutput ? 25.4 : 1;

#ifdef __unix__
if ( !outputdir.empty() && *outputdir.rbegin() != '/' )
outputdir += '/';
#else
if ( !outputdir.empty() && *outputdir.rbegin() != '/' && *outputdir.rbegin() != '\\' )
outputdir += '\\';
#endif

if( options["zero-start"].as<bool>() )
{
Expand Down Expand Up @@ -134,7 +129,7 @@ void NGC_Exporter::export_all(boost::program_options::variables_map& options) {
BOOST_FOREACH( string layername, board->list_layers() ) {
std::stringstream option_name;
option_name << layername << "-output";
string of_name = outputdir + options[option_name.str()].as<string>();
string of_name = build_filename(outputdir, options[option_name.str()].as<string>());
cerr << "Exporting " << layername << "... ";
export_layer(board->get_layer(layername), of_name);
cerr << "DONE." << " (Height: " << board->get_height() * cfactor
Expand Down
7 changes: 5 additions & 2 deletions surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include "surface.hpp"
using std::pair;

#include <glibmm/miscutils.h>
using Glib::build_filename;

// color definitions for the ARGB32 format used

#define OPAQUE 0xFF000000
Expand Down Expand Up @@ -650,8 +653,8 @@ void Surface::save_debug_image(string message) {
static unsigned int debug_image_index = 0;

opacify(pixbuf);
pixbuf->save(outputdir +
(boost::format("outp%1%_%2%.png") % debug_image_index % message).str(),
pixbuf->save( build_filename(outputdir,
(boost::format("outp%1%_%2%.png") % debug_image_index % message).str() ),
"png");
debug_image_index++;
}
Expand Down

0 comments on commit da2ef6e

Please sign in to comment.