qucs_s/qucs/main.cpp

815 lines
26 KiB
C++
Raw Normal View History

2003-10-15 21:32:36 +00:00
/***************************************************************************
2005-06-23 06:06:40 +00:00
main.cpp
----------
begin : Thu Aug 28 2003
2003-10-15 21:32:36 +00:00
copyright : (C) 2003 by Michael Margraf
2004-06-12 12:35:04 +00:00
email : michael.margraf@alumni.tu-berlin.de
2003-10-15 21:32:36 +00:00
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
2014-01-31 16:59:40 +00:00
#include <QtGui>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <locale.h>
2004-11-06 16:29:51 +00:00
#include <QApplication>
#include <QString>
#include <QStringList>
#include <QTextCodec>
#include <QTranslator>
#include <QFile>
#include <QMessageBox>
#include <QRegExp>
2003-10-15 21:32:36 +00:00
#include "qucs.h"
#include "main.h"
#include "node.h"
2004-05-25 19:10:00 +00:00
#include "schematic.h"
#include "module.h"
tQucsSettings QucsSettings;
QucsApp *QucsMain = 0; // the Qucs application itself
2006-07-03 06:02:08 +00:00
QString lastDir; // to remember last directory for several dialogs
QStringList qucsPathList;
2004-05-25 19:10:00 +00:00
// #########################################################################
// Loads the settings file and stores the settings.
bool loadSettings()
{
QSettings settings("qucs","qucs");
if(settings.contains("x"))QucsSettings.x=settings.value("x").toInt();
if(settings.contains("y"))QucsSettings.y=settings.value("y").toInt();
if(settings.contains("dx"))QucsSettings.dx=settings.value("dx").toInt();
if(settings.contains("dy"))QucsSettings.dy=settings.value("dy").toInt();
if(settings.contains("font"))QucsSettings.font.fromString(settings.value("font").toString());
if(settings.contains("largeFontSize"))QucsSettings.largeFontSize=settings.value("largeFontSize").toDouble();
if(settings.contains("maxUndo"))QucsSettings.maxUndo=settings.value("maxUndo").toInt();
if(settings.contains("NodeWiring"))QucsSettings.NodeWiring=settings.value("NodeWiring").toInt();
if(settings.contains("BGColor"))QucsSettings.BGColor.setNamedColor(settings.value("BGColor").toString());
if(settings.contains("Editor"))QucsSettings.Editor=settings.value("Editor").toString();
if(settings.contains("FileTypes"))QucsSettings.FileTypes=settings.value("FileTypes").toStringList();
if(settings.contains("Language"))QucsSettings.Language=settings.value("Language").toString();
if(settings.contains("Comment"))QucsSettings.Comment.setNamedColor(settings.value("Comment").toString());
if(settings.contains("String"))QucsSettings.String.setNamedColor(settings.value("String").toString());
if(settings.contains("Integer"))QucsSettings.Integer.setNamedColor(settings.value("Integer").toString());
if(settings.contains("Real"))QucsSettings.Real.setNamedColor(settings.value("Real").toString());
if(settings.contains("Character"))QucsSettings.Character.setNamedColor(settings.value("Character").toString());
if(settings.contains("Type"))QucsSettings.Type.setNamedColor(settings.value("Type").toString());
if(settings.contains("Attribute"))QucsSettings.Attribute.setNamedColor(settings.value("Attribute").toString());
if(settings.contains("Directive"))QucsSettings.Directive.setNamedColor(settings.value("Directive").toString());
if(settings.contains("Task"))QucsSettings.Comment.setNamedColor(settings.value("Task").toString());
if(settings.contains("Editor"))QucsSettings.Editor = settings.value("Editor").toString();
//if(settings.contains("BinDir"))QucsSettings.BinDir = settings.value("BinDir").toString();
//if(settings.contains("LangDir"))QucsSettings.LangDir = settings.value("LangDir").toString();
//if(settings.contains("LibDir"))QucsSettings.LibDir = settings.value("LibDir").toString();
//if(settings.contains("AscoDir"))QucsSettings.AscoDir = settings.value("AscoDir").toString();
//if(settings.contains("OctaveDir"))QucsSettings.OctaveDir = settings.value("OctaveDir").toString();
//if(settings.contains("ExamplesDir"))QucsSettings.ExamplesDir = settings.value("ExamplesDir").toString();
//if(settings.contains("DocDir"))QucsSettings.DocDir = settings.value("DocDir").toString();
if(settings.contains("OctaveBinDir"))QucsSettings.OctaveBinDir.setPath(settings.value("OctaveBinDir").toString());
if(settings.contains("QucsHomeDir"))
if(settings.value("QucsHomeDir").toString() != "")
QucsSettings.QucsHomeDir.setPath(settings.value("QucsHomeDir").toString());
QucsSettings.QucsWorkDir = QucsSettings.QucsHomeDir;
if (settings.contains("IngnoreVersion")) QucsSettings.IgnoreFutureVersion = settings.value("IngnoreVersion").toBool();
else QucsSettings.IgnoreFutureVersion = false;
2013-11-08 15:26:22 +04:00
2013-11-08 19:28:40 +04:00
QucsSettings.RecentDocs = settings.value("RecentDocs").toString().split("*",QString::SkipEmptyParts);
QucsSettings.numRecentDocs = QucsSettings.RecentDocs.count();
2013-11-08 15:26:22 +04:00
// If present read in the list of directory paths in which Qucs should
2013-10-01 12:04:31 +01:00
// search for subcircuit schematics
int npaths = settings.beginReadArray("Paths");
for (int i = 0; i < npaths; ++i)
{
2013-10-01 12:04:31 +01:00
settings.setArrayIndex(i);
QString apath = settings.value("path").toString();
qucsPathList.append(apath);
}
2013-10-01 12:04:31 +01:00
settings.endArray();
2013-11-08 15:26:22 +04:00
QucsSettings.numRecentDocs = 0;
return true;
2004-05-25 19:10:00 +00:00
}
// #########################################################################
// Saves the settings in the settings file.
2004-05-29 13:05:04 +00:00
bool saveApplSettings(QucsApp *qucs)
2004-05-25 19:10:00 +00:00
{
QSettings settings ("qucs","qucs");
settings.setValue("x", QucsSettings.x);
settings.setValue("y", QucsSettings.y);
settings.setValue("dx", QucsSettings.dx);
settings.setValue("dy", QucsSettings.dy);
settings.setValue("font", QucsSettings.font.toString());
settings.setValue("largeFontSize", QucsSettings.largeFontSize);
settings.setValue("maxUndo", QucsSettings.maxUndo);
settings.setValue("NodeWiring", QucsSettings.NodeWiring);
settings.setValue("BGColor", QucsSettings.BGColor.name());
settings.setValue("Editor", QucsSettings.Editor);
settings.setValue("FileTypes", QucsSettings.FileTypes);
settings.setValue("Language", QucsSettings.Language);
settings.setValue("Comment", QucsSettings.Comment.name());
settings.setValue("String", QucsSettings.String.name());
settings.setValue("Integer", QucsSettings.Integer.name());
settings.setValue("Real", QucsSettings.Real.name());
settings.setValue("Character", QucsSettings.Character.name());
settings.setValue("Type", QucsSettings.Type.name());
settings.setValue("Attribute", QucsSettings.Attribute.name());
settings.setValue("Directive", QucsSettings.Directive.name());
settings.setValue("Task", QucsSettings.Comment.name());
settings.setValue("Editor", QucsSettings.Editor);
//settings.setValue("BinDir", QucsSettings.BinDir);
//settings.setValue("LangDir", QucsSettings.LangDir);
//settings.setValue("LibDir", QucsSettings.LibDir);
//settings.setValue("AscoDir", QucsSettings.AscoDir);
//settings.setValue("OctaveDir", QucsSettings.OctaveDir);
//settings.setValue("ExamplesDir", QucsSettings.ExamplesDir);
//settings.setValue("DocDir", QucsSettings.DocDir);
settings.setValue("OctaveBinDir", QucsSettings.OctaveBinDir.canonicalPath());
settings.setValue("QucsHomeDir", QucsSettings.QucsHomeDir.canonicalPath());
settings.setValue("IngnoreVersion",QucsSettings.IgnoreFutureVersion);
// Copy the list of directory paths in which Qucs should
// search for subcircuit schematics from qucsPathList
2013-10-01 12:04:31 +01:00
settings.remove("Paths");
settings.beginWriteArray("Paths");
int i = 0;
foreach(QString path, qucsPathList) {
settings.setArrayIndex(i);
settings.setValue("path", path);
i++;
}
settings.endArray();
2004-05-25 19:10:00 +00:00
return true;
2004-05-25 19:10:00 +00:00
}
2004-06-16 17:41:33 +00:00
// #########################################################################
// #########################################################################
// ########## ##########
// ########## MOVE SOMEWHERE ELSE START ##########
// ########## ##########
// #########################################################################
2004-06-16 17:41:33 +00:00
QString complexRect(double real, double imag, int Precision)
{
QString Text;
if(fabs(imag) < 1e-250) Text = QString::number(real,'g',Precision);
else {
Text = QString::number(imag,'g',Precision);
if(Text.at(0) == '-') {
Text.replace(0,1,'j');
2004-06-16 17:41:33 +00:00
Text = '-'+Text;
}
else Text = "+j"+Text;
Text = QString::number(real,'g',Precision) + Text;
}
return Text;
}
QString complexDeg(double real, double imag, int Precision)
{
QString Text;
if(fabs(imag) < 1e-250) Text = QString::number(real,'g',Precision);
else {
2004-08-15 16:24:35 +00:00
Text = QString::number(sqrt(real*real+imag*imag),'g',Precision) + " / ";
Text += QString::number(180.0/M_PI*atan2(imag,real),'g',Precision) + QString::fromUtf8("°");
2004-06-16 17:41:33 +00:00
}
return Text;
}
QString complexRad (double real, double imag, int Precision)
{
QString Text;
if(fabs(imag) < 1e-250) Text = QString::number(real,'g',Precision);
else {
Text = QString::number(sqrt(real*real+imag*imag),'g',Precision);
2004-08-15 16:24:35 +00:00
Text += " / " + QString::number(atan2(imag,real),'g',Precision) + "rad";
2004-06-16 17:41:33 +00:00
}
return Text;
}
2004-10-10 16:06:55 +00:00
// #########################################################################
QString StringNum(double num, char form, int Precision)
{
int a = 0;
char *p, Buffer[512], Format[6] = "%.00g";
2005-01-16 14:21:24 +00:00
if(Precision < 0) {
Format[1] = form;
Format[2] = 0;
}
else {
Format[4] = form;
Format[2] += Precision / 10;
Format[3] += Precision % 10;
}
2004-10-10 16:06:55 +00:00
sprintf(Buffer, Format, num);
p = strchr(Buffer, 'e');
if(p) {
p++;
2004-12-19 16:06:24 +00:00
if(*(p++) == '+') { a = 1; } // remove '+' of exponent
if(*p == '0') { a++; p++; } // remove leading zeros of exponent
2004-10-10 16:06:55 +00:00
if(a > 0)
do {
*(p-a) = *p;
2004-12-19 16:06:24 +00:00
} while(*(p++) != 0); // override characters not needed
2004-10-10 16:06:55 +00:00
}
2005-06-23 06:06:40 +00:00
return QString(Buffer);
}
// #########################################################################
QString StringNiceNum(double num)
{
char Format[6] = "%.8e";
if(fabs(num) < 1e-250) return QString("0"); // avoid many problems
if(fabs(log10(fabs(num))) < 3.0) Format[3] = 'g';
int a = 0;
char *p, *pe, Buffer[512];
sprintf(Buffer, Format, num);
p = pe = strchr(Buffer, 'e');
if(p) {
if(*(++p) == '+') { a = 1; } // remove '+' of exponent
if(*(++p) == '0') { a++; p++; } // remove leading zeros of exponent
if(a > 0)
do {
*(p-a) = *p;
} while(*(p++) != 0); // override characters not needed
// In 'g' format, trailing zeros are already cut off !!!
p = strchr(Buffer, '.');
if(p) {
if(!pe) pe = Buffer + strlen(Buffer);
p = pe-1;
while(*p == '0') // looking for unneccessary zero characters
if((--p) <= Buffer) break;
if(*p != '.') p++; // no digit after decimal point ?
while( (*(p++) = *(pe++)) != 0 ) ; // overwrite zero characters
}
}
return QString(Buffer);
2004-10-10 16:06:55 +00:00
}
2004-12-27 18:37:29 +00:00
// #########################################################################
void str2num(const QString& s_, double& Number, QString& Unit, double& Factor)
{
QString str = s_.stripWhiteSpace();
/* int i=0;
bool neg = false;
if(str[0] == '-') { // check sign
neg = true;
i++;
}
else if(str[0] == '+') i++;
double num = 0.0;
for(;;) {
if(str[i] >= '0') if(str[i] <= '9') {
num = 10.0*num + double(str[i]-'0');
}
}*/
QRegExp Expr( QRegExp("[^0-9\\x2E\\x2D\\x2B]") );
int i = str.find( Expr );
if(i >= 0)
if((str.at(i).latin1() | 0x20) == 'e') {
int j = str.find( Expr , ++i);
if(j == i) j--;
i = j;
}
Number = str.left(i).toDouble();
Unit = str.mid(i).stripWhiteSpace();
2012-12-03 14:19:01 +01:00
if(Unit.length()>0)
{
switch(Unit.at(0).latin1()) {
case 'T': Factor = 1e12; break;
case 'G': Factor = 1e9; break;
case 'M': Factor = 1e6; break;
case 'k': Factor = 1e3; break;
case 'c': Factor = 1e-2; break;
case 'm': Factor = 1e-3; break;
case 'u': Factor = 1e-6; break;
case 'n': Factor = 1e-9; break;
case 'p': Factor = 1e-12; break;
case 'f': Factor = 1e-15; break;
// case 'd':
default: Factor = 1.0;
}
}
else
{
Factor = 1.0;
2004-12-27 18:37:29 +00:00
}
return;
}
2005-08-01 06:08:52 +00:00
// #########################################################################
QString num2str(double Num)
{
char c = 0;
2005-08-15 06:04:52 +00:00
double cal = fabs(Num);
if(cal > 1e-20) {
cal = log10(cal) / 3.0;
if(cal < -0.2) cal -= 0.98;
int Expo = int(cal);
if(Expo >= -5) if(Expo <= 4)
switch(Expo) {
case -5: c = 'f'; break;
case -4: c = 'p'; break;
case -3: c = 'n'; break;
case -2: c = 'u'; break;
case -1: c = 'm'; break;
case 1: c = 'k'; break;
case 2: c = 'M'; break;
case 3: c = 'G'; break;
case 4: c = 'T'; break;
}
if(c) Num /= pow(10.0, double(3*Expo));
}
2005-08-01 06:08:52 +00:00
QString Str = QString::number(Num);
if(c) Str += c;
2005-08-01 06:08:52 +00:00
return Str;
}
2005-07-15 06:00:30 +00:00
// #########################################################################
void convert2Unicode(QString& Text)
{
bool ok;
int i = 0;
QString n;
unsigned short ch;
while((i=Text.find("\\x", i)) >= 0) {
n = Text.mid(i, 6);
ch = n.mid(2).toUShort(&ok, 16);
if(ok) Text.replace(n, QChar(ch));
i++;
}
Text.replace("\\n", "\n");
Text.replace("\\\\", "\\");
}
2005-10-24 06:10:35 +00:00
// #########################################################################
2006-12-18 06:57:24 +00:00
void convert2ASCII(QString& Text)
{
Text.replace('\\', "\\\\");
Text.replace('\n', "\\n");
int i = 0;
QChar ch;
char Str[8];
2012-11-01 11:29:46 +01:00
while(Text.size()<i) { // convert special characters
2006-12-18 06:57:24 +00:00
if(ch > QChar(0x7F)) {
sprintf(Str, "\\x%04X", ch.unicode());
Text.replace(ch, Str);
}
}
}
// #########################################################################
// Converts a path to an absolute path and resolves paths relative to the
// Qucs home directory
QString properAbsFileName(const QString& Name)
{
QString s = Name;
QFileInfo Info(s);
if(Info.isRelative())
{
// if it's a relative file, look for it relative to the
// working directory (the qucs home directory)
s = QucsSettings.QucsWorkDir.filePath(s);
}
// return the clean path
return QDir::cleanPath(s);
}
// #########################################################################
QString properFileName(const QString& Name)
{
QFileInfo Info(Name);
return Info.fileName();
}
2006-12-18 06:57:24 +00:00
// #########################################################################
2005-10-24 06:10:35 +00:00
// Takes a file name (with path) and replaces all special characters.
QString properName(const QString& Name)
2005-10-24 06:10:35 +00:00
{
QString s = Name;
QFileInfo Info(s);
if(Info.extension() == "sch")
s = s.left(s.length()-4);
if(s.at(0) <= '9') if(s.at(0) >= '0')
s = 'n' + s;
s.replace(QRegExp("\\W"), "_"); // none [a-zA-Z0-9] into "_"
s.replace("__", "_"); // '__' not allowed in VHDL
if(s.at(0) == '_')
s = 'n' + s;
return s;
}
// #########################################################################
// Creates and returns delay time for VHDL entities.
bool VHDL_Delay(QString& td, const QString& Name)
{
if(strtod(td.latin1(), 0) != 0.0) { // delay time property
if(!VHDL_Time(td, Name))
return false; // time has not VHDL format
td = " after " + td;
return true;
}
else if(isalpha(td.latin1()[0])) {
td = " after " + td;
return true;
}
else {
td = "";
return true;
}
}
2006-01-16 07:19:57 +00:00
// #########################################################################
// Checks and corrects a time (number & unit) according VHDL standard.
bool VHDL_Time(QString& t, const QString& Name)
{
char *p;
double Time = strtod(t.latin1(), &p);
while(*p == ' ') p++;
for(;;) {
if(Time >= 0.0) {
if(strcmp(p, "fs") == 0) break;
if(strcmp(p, "ps") == 0) break;
if(strcmp(p, "ns") == 0) break;
if(strcmp(p, "us") == 0) break;
if(strcmp(p, "ms") == 0) break;
if(strcmp(p, "sec") == 0) break;
if(strcmp(p, "min") == 0) break;
if(strcmp(p, "hr") == 0) break;
}
t = QString::fromUtf8("§") + QObject::tr("Error: Wrong time format in \"%1\". Use positive number with units").arg(Name)
2006-01-16 07:19:57 +00:00
+ " fs, ps, ns, us, ms, sec, min, hr.\n";
return false;
}
t = QString::number(Time) + " " + QString(p); // the space is mandatory !
return true;
}
// #########################################################################
// Returns parameters for Verilog modules.
QString Verilog_Param(const QString Value)
{
if(strtod(Value.latin1(), 0) != 0.0) {
QString td = Value;
if(!Verilog_Time(td, "parameter"))
return Value;
else
return td;
}
else
return Value;
}
// #########################################################################
// Creates and returns delay time for Verilog modules.
bool Verilog_Delay(QString& td, const QString& Name)
{
if(strtod(td.latin1(), 0) != 0.0) { // delay time property
if(!Verilog_Time(td, Name))
return false; // time has not Verilog format
td = " #" + td;
return true;
}
else if(isalpha(td.latin1()[0])) {
td = " #" + td;
return true;
}
else {
td = "";
return true;
}
}
// #########################################################################
// Checks and corrects a time (number & unit) according Verilog standard.
bool Verilog_Time(QString& t, const QString& Name)
{
char *p;
double Time = strtod(t.latin1(), &p);
double factor = 1.0;
while(*p == ' ') p++;
for(;;) {
if(Time >= 0.0) {
if(strcmp(p, "fs") == 0) { factor = 1e-3; break; }
if(strcmp(p, "ps") == 0) { factor = 1; break; }
if(strcmp(p, "ns") == 0) { factor = 1e3; break; }
if(strcmp(p, "us") == 0) { factor = 1e6; break; }
if(strcmp(p, "ms") == 0) { factor = 1e9; break; }
if(strcmp(p, "sec") == 0) { factor = 1e12; break; }
if(strcmp(p, "min") == 0) { factor = 1e12*60; break; }
if(strcmp(p, "hr") == 0) { factor = 1e12*60*60; break; }
}
t = QString::fromUtf8("§") + QObject::tr("Error: Wrong time format in \"%1\". Use positive number with units").arg(Name)
+ " fs, ps, ns, us, ms, sec, min, hr.\n";
return false;
}
t = QString::number(Time*factor);
return true;
}
// #########################################################################
bool checkVersion(QString& Line)
{
QStringList sl = QStringList::split('.',PACKAGE_VERSION);
QStringList ll = QStringList::split('.',Line);
if (ll.count() != 3 || sl.count() != 3)
return false;
int sv = (int)sl.at(1).toLongLong()*10000+sl.at(2).toLongLong()*100;
int lv = (int)ll.at(1).toLongLong()*10000+ll.at(2).toLongLong()*100;
if(lv > sv) // wrong version number ? (only backward compatible)
return false;
return true;
}
// #########################################################################
// ########## ##########
// ########## MOVE SOMEWHERE ELSE END ##########
// ########## ##########
// #########################################################################
int doNetlist(QString schematic, QString netlist)
{
qDebug() << "*** try to load schematic :" << schematic;
QFile file(schematic); // save simulator messages
if(file.open(QIODevice::ReadOnly)) {
file.close();
}
else {
fprintf(stderr, "Error: Could not load schematic %s\n", schematic.ascii());
return 1;
}
// populate Modules list
Module::registerModules ();
// new schematic from file
Schematic *sch = new Schematic(0, schematic);
// load schematic file if possible
if(!sch->loadDocument()) {
fprintf(stderr, "Error: Could not load schematic %s\n", schematic.ascii());
delete sch;
return 1;
}
qDebug() << "*** try to write netlist :" << netlist;
QStringList Collect;
QTextEdit *ProgText = new QTextEdit(); //dummy, not used
QTextEdit *ErrText = new QTextEdit(); //dummy
QFile NetlistFile;
QTextStream Stream;
Collect.clear(); // clear list for NodeSets, SPICE components etc.
NetlistFile.setName(netlist);
if(!NetlistFile.open(QIODevice::WriteOnly)) {
fprintf(stderr, "Error: Could not load netlist %s\n", netlist.ascii());
return -1;
}
Stream.setDevice(&NetlistFile);
int SimPorts = sch->prepareNetlist(Stream, Collect, ErrText);
if(SimPorts < -5) {
NetlistFile.close();
fprintf(stderr, "Error: Could not prepare the netlist...\n");
return 1;
}
// output NodeSets, SPICE simulations etc.
for(QStringList::Iterator it = Collect.begin();
it != Collect.end(); ++it) {
// don't put library includes into netlist...
if ((*it).right(4) != ".lst" &&
(*it).right(5) != ".vhdl" &&
(*it).right(4) != ".vhd" &&
(*it).right(2) != ".v") {
Stream << *it << '\n';
}
}
Stream << '\n';
QString SimTime = sch->createNetlist(Stream, SimPorts);
NetlistFile.close();
return 0;
}
2004-06-26 07:05:47 +00:00
2004-05-25 19:10:00 +00:00
// #########################################################################
// ########## ##########
// ########## Program Start ##########
// ########## ##########
// #########################################################################
2003-10-15 21:32:36 +00:00
int main(int argc, char *argv[])
{
// apply default settings
QucsSettings.font = QFont("Helvetica", 12);
QucsSettings.largeFontSize = 16.0;
QucsSettings.maxUndo = 20;
QucsSettings.NodeWiring = 0;
// initially center the application
QApplication a(argc, argv);
QDesktopWidget *d = a.desktop();
int w = d->width();
int h = d->height();
QucsSettings.x = w/8;
QucsSettings.y = h/8;
QucsSettings.dx = w*3/4;
QucsSettings.dy = h*3/4;
// check for relocation env variable
char* var = getenv("QUCSDIR");
QDir QucsDir;
if (var!= NULL)
{
QucsDir = QDir(var);
}
else
{
QString QucsApplicationPath = QCoreApplication::applicationDirPath();
2013-07-03 13:23:28 +02:00
#ifdef __APPLE__
2013-07-03 12:51:24 +02:00
QucsDir = QDir(QucsApplicationPath.section("/bin",0,0));
2013-07-03 13:23:28 +02:00
#else
QucsDir = QDir(QucsApplicationPath.replace("/bin",""));
#endif
}
QucsSettings.BinDir = QucsDir.canonicalPath() + "/bin/";
QucsSettings.LangDir =QucsDir.canonicalPath() + "/share/qucs/lang/";
QucsSettings.LibDir =QucsDir.canonicalPath() + "/share/qucs/library/";
QucsSettings.OctaveDir =QucsDir.canonicalPath() + "/share/qucs/octave/";
QucsSettings.ExamplesDir = QucsDir.canonicalPath() + "/share/qucs/docs/examples/";
QucsSettings.DocDir = QucsDir.canonicalPath() + "/share/qucs/docs/";
2013-12-11 09:32:01 +00:00
QucsSettings.Editor = "qucs";
QucsSettings.QucsHomeDir.setPath(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs"));
QucsSettings.QucsWorkDir.setPath(QucsSettings.QucsHomeDir.canonicalPath());
var = getenv("OCTAVEBINDIR");
if(var != NULL)
{
QucsSettings.OctaveBinDir.setPath(var);
}
else
{
#ifdef __MINGW32__
QucsSettings.OctaveBinDir.setPath("C:/Software/Octave-3.6.4/bin/");
#else
QFile octaveExec("/usr/bin/octave");
if(octaveExec.exists())QucsSettings.OctaveBinDir.setPath("/usr/bin/");
QFile octaveExec1("/usr/local/bin/octave");
if(octaveExec1.exists()) QucsSettings.OctaveBinDir.setPath("/usr/local/bin/");
#endif
}
2004-05-25 19:10:00 +00:00
loadSettings();
2006-07-03 06:02:08 +00:00
if(!QucsSettings.BGColor.isValid())
QucsSettings.BGColor.setRgb(255, 250, 225);
// syntax highlighting
if(!QucsSettings.Comment.isValid())
QucsSettings.Comment = Qt::gray;
if(!QucsSettings.String.isValid())
QucsSettings.String = Qt::red;
if(!QucsSettings.Integer.isValid())
QucsSettings.Integer = Qt::blue;
if(!QucsSettings.Real.isValid())
QucsSettings.Real = Qt::darkMagenta;
if(!QucsSettings.Character.isValid())
QucsSettings.Character = Qt::magenta;
if(!QucsSettings.Type.isValid())
QucsSettings.Type = Qt::darkRed;
if(!QucsSettings.Attribute.isValid())
QucsSettings.Attribute = Qt::darkCyan;
if(!QucsSettings.Directive.isValid())
QucsSettings.Directive = Qt::darkCyan;
if(!QucsSettings.Task.isValid())
QucsSettings.Task = Qt::darkRed;
2006-07-03 06:02:08 +00:00
QucsSettings.AscoDir = QucsSettings.BinDir;
2006-07-03 06:02:08 +00:00
2004-05-25 19:10:00 +00:00
a.setFont(QucsSettings.font);
2003-10-15 21:32:36 +00:00
QTranslator tor( 0 );
2006-02-14 07:25:27 +00:00
QString lang = QucsSettings.Language;
if(lang.isEmpty())
lang = QTextCodec::locale();
tor.load( QString("qucs_") + lang, QucsSettings.LangDir);
2003-12-07 15:21:31 +00:00
a.installTranslator( &tor );
2004-05-25 19:10:00 +00:00
2006-07-24 06:12:23 +00:00
// This seems to be neccessary on a few system to make strtod()
// work properly !???!
setlocale (LC_NUMERIC, "C");
2006-07-24 06:12:23 +00:00
QString schematic;
QString netlist;
QString operation;
// simple command line parser
for (int i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
fprintf(stdout,
"Usage: %s [OPTION]...\n\n"
" -h, --help display this help and exit\n"
" -v, --version display version information and exit\n"
" -n, --netlist convert Qucs schematic into netlist\n"
" -i FILENAME use file as input schematic\n"
" -o FILENAME use file as output netlist\n"
, argv[0]);
return 0;
}
else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
fprintf(stdout, "Qucs " PACKAGE_VERSION "\n");
return 0;
}
else if (!strcmp(argv[i], "-n") || !strcmp(argv[i], "--netlist")) {
operation = "netlist";
}
else if (!strcmp(argv[i], "-i")) {
schematic = argv[++i];
}
else if (!strcmp(argv[i], "-o")) {
netlist = argv[++i];
}
else {
fprintf(stderr, "Error: Unknown option: %s\n", argv[i]);
return -1;
}
}
// check operation and its required arguments
if (operation == "netlist") {
if (schematic.isEmpty()) {
fprintf(stderr, "Error: Expected input schematic file.\n");
return -1;
}
if (netlist.isEmpty()) {
fprintf(stderr, "Error: Expected output netlist file.\n");
return -1;
}
// create netlist from schematic
return doNetlist(schematic, netlist);
}
2004-12-04 18:41:22 +00:00
QucsMain = new QucsApp();
a.setMainWidget(QucsMain);
QucsMain->show();
2004-06-12 12:35:04 +00:00
int result = a.exec();
//saveApplSettings(QucsMain);
2004-06-12 12:35:04 +00:00
return result;
2003-10-15 21:32:36 +00:00
}