Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/layoutwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ int LayoutWriter::write(Block& block, long double const offset_x, long double co

if(data.out_format==".kicad_pcb") write_kicad_pcb(block, f_out, offset_x, offset_y, name);
else if(data.out_format==".kicad_mod") write_kicad_mod(block, f_out, offset_x, offset_y, name);
else if(data.out_format==".svg") write_svg(block, f_out, offset_x, offset_y, name);
else if(data.out_format==".lht") write_lht(block, f_out, offset_x, offset_y, name);
else if(data.out_format==".m") write_m(block, f_out, offset_x, offset_y, name);
if(out_names) out_names->push_back(n_out); // Success message to stdout in GUI mode
Expand Down Expand Up @@ -364,6 +365,46 @@ void LayoutWriter::write_kicad_mod(Block& block, ofstream& f_out, long double co
f_out << ")\n";
}

//******************************************************************************
void LayoutWriter::write_svg(Block& block, ofstream& f_out, long double const offset_x, long double const offset_y, string const& name) const {
f_out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"" << block.margin_boundary[XMAX]+ offset_x << "mm\" height=\"" << block.margin_boundary[YMAX]+offset_y << "mm\">\n";
f_out << "<g transform=\"scale(3.779527559)\">\n";
for(shared_ptr<Element> it : block.elements) {
if(!it->getActive())
continue;

string type = it->getType();
if(type == "SUBST" || type == "MGAP" || type == "MOPEN" || type == "MSTEP") {
//nothing to do
} else if(type == "Pac") {
Pac* pac = dynamic_cast<Pac*>(it.get());
f_out << " <rect x=\"" << it->getX() + offset_x/2 << "\" y=\"" << it->getY() + offset_y << "\" width=\"" << (pac->is_size_set ? it->getW() : 0.01) << "\" height=\"" << (pac->is_size_set ? it->getL() : 0.01) << "\" fill=\"none\" stroke=\"black\"/>\n";
} else if(type == "MCORN" || type == "MCROSS" || type == "MMBEND" || type == "MLIN" || type == "MRSTUB" || type == "MTEE") {
f_out << " <path d=\"";
for(int i = 0; i < it->getNpoint(); i++) {
f_out << (i == 0 ? "M" : "L") << it->getP(i, X, R, ABS) + offset_x/2 << " " << it->getP(i, Y, R, ABS) + offset_y << " ";
}
f_out << "Z\" fill=\"black\" stroke=\"none\"/>\n";
} else if(type == "MCOUPLED") {
f_out << " <path d=\"";
for(int i = 0; i < it->getNpoint() / 2; i++) {
f_out << (i == 0 ? "M" : "L") << it->getP(i, X, R, ABS) + offset_x/2 << " " << it->getP(i, Y, R, ABS) + offset_y << " ";
}
f_out << "Z\" fill=\"black\" stroke=\"none\"/>\n";
f_out << " <path d=\"";
for(int i = it->getNpoint() / 2; i < it->getNpoint(); i++) {
f_out << (i == it->getNpoint() / 2 ? "M" : "L") << it->getP(i, X, R, ABS) + offset_x/2 << " " << it->getP(i, Y, R, ABS) + offset_y << " ";
}
f_out << "Z\" fill=\"black\" stroke=\"none\"/>\n";
} else if(type == "MVIA") {
f_out << " <circle cx=\"" << it->getX() + offset_x/2 << "\" cy=\"" << it->getY() + offset_y << "\" r=\"" << it->getD() / 2 << "\" fill=\"black\" stroke=\"none\"/>\n";
}
}
f_out << "</g>\n";
f_out << "</svg>\n";
}

//******************************************************************************
void LayoutWriter::write_lht(Block& block, ofstream& f_out, long double const offset_x, long double const offset_y, string const& name) const {
string type;
Expand Down
1 change: 1 addition & 0 deletions src/layoutwriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LayoutWriter {
//TODO array<long double, 2> offset ?
void write_kicad_pcb(Block& block, std::ofstream& f_out, long double const offset_x, long double const offset_y, std::string const& name) const;
void write_kicad_mod(Block& block, std::ofstream& f_out, long double const offset_x, long double const offset_y, std::string const& name) const;
void write_svg(Block& block, std::ofstream& f_out, long double const offset_x, long double const offset_y, std::string const& name) const;
void write_lht(Block& block, std::ofstream& f_out, long double const offset_x, long double const offset_y, std::string const& name) const;
void write_m(Block& block, std::ofstream& f_out, long double const offset_x, long double const offset_y, std::string const& name) const;

Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ int main(int argc, char* argv[]) {
for(int i=1;i<argc;i++) {
if(string(argv[i])=="-h" || string(argv[i])=="--help") {
cout << "Usage: " << argv[0] << " -i FILENAME.sch\n"
" " << argv[0] << " -i FILENAME.sch -f [.kicad_pcb|.kicad_mod|.lht]\n"
" " << argv[0] << " -i FILENAME.sch -f [.kicad_pcb|.kicad_mod|.lht] -o DIRNAME\n"
" " << argv[0] << " -i FILENAME.sch -f [.kicad_pcb|.kicad_mod|.lht|.svg]\n"
" " << argv[0] << " -i FILENAME.sch -f [.kicad_pcb|.kicad_mod|.lht|.svg] -o DIRNAME\n"
" " << argv[0] << " -G\n"
"\n"
" -h, --help Display this help and exit.\n"
Expand All @@ -62,6 +62,7 @@ int main(int argc, char* argv[]) {
" - .kicad_mod : KiCad module\n"
" - .lht : pcb-rnd layout\n"
" - .m : OpenEMS Octave script\n"
" - .svg : SVG file\n"
" -n NETLIST Specify a netlist to use instead of calling Qucs to create it from the schematic.\n"
" Useful when Qucs is not installed, if you use QucsStudio for example.\n"
" -q, --qucs PATH Specify Qucs executable to call for netlist creation, otherwise qucs, then qucs-s will\n"
Expand Down Expand Up @@ -102,6 +103,7 @@ int main(int argc, char* argv[]) {
i++;
if(string(argv[i])==".kicad_pcb"
|| string(argv[i])==".kicad_mod"
|| string(argv[i])==".svg"
|| string(argv[i])==".lht"
|| string(argv[i])==".m") {
data.out_format=string(argv[i]);
Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ MainWindow::MainWindow(Data& _data, QWidget* parent) :
ui->cb_format->addItem(tr(".kicad_mod"));
ui->cb_format->addItem(tr(".lht"));
ui->cb_format->addItem(tr(".m"));
ui->cb_format->addItem(tr(".svg"));
ui->cb_format->setCurrentText(out_format);
ui->rb_export_whole->setChecked((_data.export_each_block || _data.export_each_subst) ? false : true);
ui->rb_export_each_subst->setChecked((_data.export_each_subst && !_data.export_each_block) ? true : false);
Expand Down Expand Up @@ -192,7 +193,7 @@ void MainWindow::write() {
}

//******************************************************************************
void MainWindow::on_cb_format_currentIndexChanged(const QString out_format) {
void MainWindow::on_cb_format_currentTextChanged(const QString& out_format) {
ui->gb_oems->setEnabled((out_format==".m") ? true : false);
data.out_format=out_format.toStdString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MainWindow : public QMainWindow, public Loggable {
void log(std::stringstream& in) override;

private slots:
void on_cb_format_currentIndexChanged(QString const out_format);
void on_cb_format_currentTextChanged(const QString& out_format);
void on_cb_specify_netlist_stateChanged(int const state);
void on_cb_oems_pkg_stateChanged(int const state);
void on_cb_oems_sort_metalresmesh_stateChanged(int const state);
Expand Down
2 changes: 1 addition & 1 deletion src/schparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ int SchParser::check_qucsstudio(ifstream& f_sch, string& n_tmp, bool& is_qucsstu

//******************************************************************************
int SchParser::generate_netlist(string const& n_sch, string const& n_net) const {
static constexpr array<string, 2> to_try{"qucs", "qucs-s"};
const array<string, 2> to_try{"qucs", "qucs-s"};
string const args=" -n -i \""+n_sch+"\" -o \""+n_net+"\"";
bool is_done=false;

Expand Down