32 #include <QApplication>
34 #include <QStringList>
36 #include <QTranslator>
38 #include <QMessageBox>
62 QSettings settings(
"qucs",
"qucs");
64 if(settings.contains(
"x"))QucsSettings.
x=settings.value(
"x").toInt();
65 if(settings.contains(
"y"))QucsSettings.
y=settings.value(
"y").toInt();
66 if(settings.contains(
"dx"))QucsSettings.
dx=settings.value(
"dx").toInt();
67 if(settings.contains(
"dy"))QucsSettings.
dy=settings.value(
"dy").toInt();
68 if(settings.contains(
"font"))QucsSettings.
font.fromString(settings.value(
"font").toString());
69 if(settings.contains(
"largeFontSize"))QucsSettings.
largeFontSize=settings.value(
"largeFontSize").toDouble();
70 if(settings.contains(
"maxUndo"))QucsSettings.
maxUndo=settings.value(
"maxUndo").toInt();
71 if(settings.contains(
"NodeWiring"))QucsSettings.
NodeWiring=settings.value(
"NodeWiring").toInt();
72 if(settings.contains(
"BGColor"))QucsSettings.
BGColor.setNamedColor(settings.value(
"BGColor").toString());
73 if(settings.contains(
"Editor"))QucsSettings.
Editor=settings.value(
"Editor").toString();
74 if(settings.contains(
"FileTypes"))QucsSettings.
FileTypes=settings.value(
"FileTypes").toStringList();
75 if(settings.contains(
"Language"))QucsSettings.
Language=settings.value(
"Language").toString();
76 if(settings.contains(
"Comment"))QucsSettings.
Comment.setNamedColor(settings.value(
"Comment").toString());
77 if(settings.contains(
"String"))QucsSettings.
String.setNamedColor(settings.value(
"String").toString());
78 if(settings.contains(
"Integer"))QucsSettings.
Integer.setNamedColor(settings.value(
"Integer").toString());
79 if(settings.contains(
"Real"))QucsSettings.
Real.setNamedColor(settings.value(
"Real").toString());
80 if(settings.contains(
"Character"))QucsSettings.
Character.setNamedColor(settings.value(
"Character").toString());
81 if(settings.contains(
"Type"))QucsSettings.
Type.setNamedColor(settings.value(
"Type").toString());
82 if(settings.contains(
"Attribute"))QucsSettings.
Attribute.setNamedColor(settings.value(
"Attribute").toString());
83 if(settings.contains(
"Directive"))QucsSettings.
Directive.setNamedColor(settings.value(
"Directive").toString());
84 if(settings.contains(
"Task"))QucsSettings.
Comment.setNamedColor(settings.value(
"Task").toString());
86 if(settings.contains(
"Editor"))QucsSettings.
Editor = settings.value(
"Editor").toString();
90 if(settings.contains(
"AdmsXmlBinDir"))QucsSettings.
AdmsXmlBinDir = settings.value(
"AdmsXmlBinDir").toString();
91 if(settings.contains(
"AscoBinDir"))QucsSettings.
AscoBinDir = settings.value(
"AscoBinDir").toString();
95 if(settings.contains(
"OctaveBinDir"))QucsSettings.
OctaveBinDir.setPath(settings.value(
"OctaveBinDir").toString());
96 if(settings.contains(
"QucsHomeDir"))
97 if(settings.value(
"QucsHomeDir").toString() !=
"")
98 QucsSettings.
QucsHomeDir.setPath(settings.value(
"QucsHomeDir").toString());
101 if (settings.contains(
"IngnoreVersion")) QucsSettings.
IgnoreFutureVersion = settings.value(
"IngnoreVersion").toBool();
105 QucsSettings.
RecentDocs = settings.value(
"RecentDocs").toString().split(
"*",QString::SkipEmptyParts);
111 int npaths = settings.beginReadArray(
"Paths");
112 for (
int i = 0; i < npaths; ++i)
114 settings.setArrayIndex(i);
115 QString apath = settings.value(
"path").toString();
129 QSettings settings (
"qucs",
"qucs");
131 settings.setValue(
"x", QucsSettings.
x);
132 settings.setValue(
"y", QucsSettings.
y);
133 settings.setValue(
"dx", QucsSettings.
dx);
134 settings.setValue(
"dy", QucsSettings.
dy);
135 settings.setValue(
"font", QucsSettings.
font.toString());
136 settings.setValue(
"largeFontSize", QucsSettings.
largeFontSize);
137 settings.setValue(
"maxUndo", QucsSettings.
maxUndo);
138 settings.setValue(
"NodeWiring", QucsSettings.
NodeWiring);
139 settings.setValue(
"BGColor", QucsSettings.
BGColor.name());
140 settings.setValue(
"Editor", QucsSettings.
Editor);
141 settings.setValue(
"FileTypes", QucsSettings.
FileTypes);
142 settings.setValue(
"Language", QucsSettings.
Language);
143 settings.setValue(
"Comment", QucsSettings.
Comment.name());
144 settings.setValue(
"String", QucsSettings.
String.name());
145 settings.setValue(
"Integer", QucsSettings.
Integer.name());
146 settings.setValue(
"Real", QucsSettings.
Real.name());
147 settings.setValue(
"Character", QucsSettings.
Character.name());
148 settings.setValue(
"Type", QucsSettings.
Type.name());
149 settings.setValue(
"Attribute", QucsSettings.
Attribute.name());
150 settings.setValue(
"Directive", QucsSettings.
Directive.name());
151 settings.setValue(
"Task", QucsSettings.
Comment.name());
152 settings.setValue(
"Editor", QucsSettings.
Editor);
156 settings.setValue(
"AdmsXmlBinDir", QucsSettings.
AdmsXmlBinDir.canonicalPath());
157 settings.setValue(
"AscoBinDir", QucsSettings.
AscoBinDir.canonicalPath());
161 settings.setValue(
"OctaveBinDir", QucsSettings.
OctaveBinDir.canonicalPath());
162 settings.setValue(
"QucsHomeDir", QucsSettings.
QucsHomeDir.canonicalPath());
167 settings.remove(
"Paths");
168 settings.beginWriteArray(
"Paths");
171 settings.setArrayIndex(i);
172 settings.setValue(
"path", path);
197 fprintf(stderr,
"Debug: %s\n", msg);
200 fprintf(stderr,
"Warning: %s\n", msg);
203 fprintf(stderr,
"Critical: %s\n", msg);
206 fprintf(stderr,
"Fatal: %s\n", msg);
211 OutputDebugStringA(msg);
227 if(fabs(imag) < 1e-250) Text = QString::number(real,
'g',Precision);
229 Text = QString::number(imag,
'g',Precision);
230 if(Text.at(0) ==
'-') {
231 Text.replace(0,1,
'j');
234 else Text =
"+j"+Text;
235 Text = QString::number(real,
'g',Precision) + Text;
243 if(fabs(imag) < 1e-250) Text = QString::number(real,
'g',Precision);
245 Text = QString::number(sqrt(real*real+imag*imag),
'g',Precision) +
" / ";
246 Text += QString::number(180.0/
M_PI*atan2(imag,real),
'g',Precision) + QString::fromUtf8(
"°");
254 if(fabs(imag) < 1e-250) Text = QString::number(real,
'g',Precision);
256 Text = QString::number(sqrt(real*real+imag*imag),
'g',Precision);
257 Text +=
" / " + QString::number(atan2(imag,real),
'g',Precision) +
"rad";
266 char *p, Buffer[512], Format[6] =
"%.00g";
274 Format[2] += Precision / 10;
275 Format[3] += Precision % 10;
277 sprintf(Buffer, Format, num);
278 p = strchr(Buffer,
'e');
281 if(*(p++) ==
'+') { a = 1; }
282 if(*p ==
'0') { a++; p++; }
286 }
while(*(p++) != 0);
289 return QString(Buffer);
295 char Format[6] =
"%.8e";
296 if(fabs(num) < 1e-250)
return QString(
"0");
297 if(fabs(log10(fabs(num))) < 3.0) Format[3] =
'g';
300 char *p, *pe, Buffer[512];
302 sprintf(Buffer, Format, num);
303 p = pe = strchr(Buffer,
'e');
305 if(*(++p) ==
'+') { a = 1; }
306 if(*(++p) ==
'0') { a++; p++; }
310 }
while(*(p++) != 0);
313 p = strchr(Buffer,
'.');
315 if(!pe) pe = Buffer + strlen(Buffer);
318 if((--p) <= Buffer)
break;
320 while( (*(p++) = *(pe++)) != 0 ) ;
324 return QString(Buffer);
328 void str2num(
const QString& s_,
double& Number, QString& Unit,
double& Factor)
330 QString str = s_.stripWhiteSpace();
347 QRegExp Expr( QRegExp(
"[^0-9\\x2E\\x2D\\x2B]") );
348 int i = str.find( Expr );
350 if((str.at(i).latin1() | 0x20) ==
'e') {
351 int j = str.find( Expr , ++i);
356 Number = str.left(i).toDouble();
357 Unit = str.mid(i).stripWhiteSpace();
360 switch(Unit.at(0).latin1()) {
361 case 'T': Factor = 1e12;
break;
362 case 'G': Factor = 1e9;
break;
363 case 'M': Factor = 1e6;
break;
364 case 'k': Factor = 1e3;
break;
365 case 'c': Factor = 1e-2;
break;
366 case 'm': Factor = 1e-3;
break;
367 case 'u': Factor = 1e-6;
break;
368 case 'n': Factor = 1e-9;
break;
369 case 'p': Factor = 1e-12;
break;
370 case 'f': Factor = 1e-15;
break;
372 default: Factor = 1.0;
387 double cal = fabs(Num);
389 cal = log10(cal) / 3.0;
390 if(cal < -0.2) cal -= 0.98;
393 if(Expo >= -5)
if(Expo <= 4)
395 case -5: c =
'f';
break;
396 case -4: c =
'p';
break;
397 case -3: c =
'n';
break;
398 case -2: c =
'u';
break;
399 case -1: c =
'm';
break;
400 case 1: c =
'k';
break;
401 case 2: c =
'M';
break;
402 case 3: c =
'G';
break;
403 case 4: c =
'T';
break;
406 if(c) Num /= pow(10.0,
double(3*Expo));
409 QString Str = QString::number(Num);
422 while((i=Text.find(
"\\x", i)) >= 0) {
424 ch = n.mid(2).toUShort(&ok, 16);
425 if(ok) Text.replace(n, QChar(ch));
428 Text.replace(
"\\n",
"\n");
429 Text.replace(
"\\\\",
"\\");
435 Text.replace(
'\\',
"\\\\");
436 Text.replace(
'\n',
"\\n");
441 while(Text.size()<i) {
442 if(ch > QChar(0x7F)) {
443 sprintf(Str,
"\\x%04X", ch.unicode());
444 Text.replace(ch, Str);
457 if(Info.isRelative())
464 return QDir::cleanPath(s);
470 QFileInfo Info(Name);
471 return Info.fileName();
480 if(Info.extension() ==
"sch")
481 s = s.left(s.length()-4);
482 if(s.at(0) <=
'9')
if(s.at(0) >=
'0')
484 s.replace(QRegExp(
"\\W"),
"_");
485 s.replace(
"__",
"_");
495 if(strtod(td.latin1(), 0) != 0.0) {
501 else if(isalpha(td.latin1()[0])) {
516 double Time = strtod(t.latin1(), &p);
517 while(*p ==
' ') p++;
520 if(strcmp(p,
"fs") == 0)
break;
521 if(strcmp(p,
"ps") == 0)
break;
522 if(strcmp(p,
"ns") == 0)
break;
523 if(strcmp(p,
"us") == 0)
break;
524 if(strcmp(p,
"ms") == 0)
break;
525 if(strcmp(p,
"sec") == 0)
break;
526 if(strcmp(p,
"min") == 0)
break;
527 if(strcmp(p,
"hr") == 0)
break;
529 t = QString::fromUtf8(
"§") + QObject::tr(
"Error: Wrong time format in \"%1\". Use positive number with units").arg(Name)
530 +
" fs, ps, ns, us, ms, sec, min, hr.\n";
534 t = QString::number(Time) +
" " + QString(p);
542 if(strtod(Value.latin1(), 0) != 0.0) {
557 if(strtod(td.latin1(), 0) != 0.0) {
563 else if(isalpha(td.latin1()[0])) {
578 double Time = strtod(t.latin1(), &p);
580 while(*p ==
' ') p++;
583 if(strcmp(p,
"fs") == 0) { factor = 1e-3;
break; }
584 if(strcmp(p,
"ps") == 0) { factor = 1;
break; }
585 if(strcmp(p,
"ns") == 0) { factor = 1e3;
break; }
586 if(strcmp(p,
"us") == 0) { factor = 1e6;
break; }
587 if(strcmp(p,
"ms") == 0) { factor = 1e9;
break; }
588 if(strcmp(p,
"sec") == 0) { factor = 1e12;
break; }
589 if(strcmp(p,
"min") == 0) { factor = 1e12*60;
break; }
590 if(strcmp(p,
"hr") == 0) { factor = 1e12*60*60;
break; }
592 t = QString::fromUtf8(
"§") + QObject::tr(
"Error: Wrong time format in \"%1\". Use positive number with units").arg(Name)
593 +
" fs, ps, ns, us, ms, sec, min, hr.\n";
597 t = QString::number(Time*factor);
604 QStringList sl = QStringList::split(
'.',PACKAGE_VERSION);
605 QStringList ll = QStringList::split(
'.',Line);
606 if (ll.count() != 3 || sl.count() != 3)
608 int sv = (int)sl.at(1).toLongLong()*10000+sl.at(2).toLongLong()*100;
609 int lv = (int)ll.at(1).toLongLong()*10000+ll.at(2).toLongLong()*100;
622 qDebug() <<
"*** try to load schematic :" << schematic;
624 QFile file(schematic);
625 if(file.open(QIODevice::ReadOnly)) {
629 fprintf(stderr,
"Error: Could not load schematic %s\n", schematic.ascii());
641 fprintf(stderr,
"Error: Could not load schematic %s\n", schematic.ascii());
646 qDebug() <<
"*** try to write netlist :" << netlist;
650 QTextEdit *ErrText =
new QTextEdit();
656 NetlistFile.setName(netlist);
657 if(!NetlistFile.open(QIODevice::WriteOnly)) {
658 fprintf(stderr,
"Error: Could not load netlist %s\n", netlist.ascii());
662 Stream.setDevice(&NetlistFile);
667 fprintf(stderr,
"Error: Could not prepare the netlist...\n");
672 for(QStringList::Iterator it = Collect.begin();
673 it != Collect.end(); ++it) {
675 if ((*it).right(4) !=
".lst" &&
676 (*it).right(5) !=
".vhdl" &&
677 (*it).right(4) !=
".vhd" &&
678 (*it).right(2) !=
".v") {
679 Stream << *it <<
'\n';
698 int main(
int argc,
char *argv[])
701 QucsSettings.
font = QFont(
"Helvetica", 12);
707 QApplication a(argc, argv);
708 QDesktopWidget *d = a.desktop();
711 QucsSettings.
x = w/8;
712 QucsSettings.
y = h/8;
713 QucsSettings.
dx = w*3/4;
714 QucsSettings.
dy = h*3/4;
717 char* var = getenv(
"QUCSDIR");
721 QucsDir = QDir(QString(var));
722 qDebug() <<
"QUCSDIR set: " << QucsDir.absolutePath();
726 QString QucsApplicationPath = QCoreApplication::applicationDirPath();
728 QucsDir = QDir(QucsApplicationPath.section(
"/bin",0,0));
730 QucsDir = QDir(QucsApplicationPath.replace(
"/bin",
""));
735 QucsSettings.
BinDir = QucsDir.absolutePath() +
"/bin/";
736 QucsSettings.
LangDir = QucsDir.canonicalPath() +
"/share/qucs/lang/";
737 QucsSettings.
LibDir = QucsDir.canonicalPath() +
"/share/qucs/library/";
738 QucsSettings.
OctaveDir = QucsDir.canonicalPath() +
"/share/qucs/octave/";
739 QucsSettings.
ExamplesDir = QucsDir.canonicalPath() +
"/share/qucs/docs/examples/";
740 QucsSettings.
DocDir = QucsDir.canonicalPath() +
"/share/qucs/docs/";
742 QucsSettings.
Editor =
"qucs";
743 QucsSettings.
QucsHomeDir.setPath(QDir::homeDirPath()+QDir::convertSeparators (
"/.qucs"));
747 var = getenv(
"ADMSXMLBINDIR");
755 admsExec = QDir::toNativeSeparators(QucsSettings.
BinDir+
"/"+
"admsXml.exe");
757 admsExec = QDir::toNativeSeparators(QucsSettings.
BinDir+
"/"+
"admsXml");
759 QFile adms(admsExec);
764 var = getenv(
"ASCOBINDIR");
766 QucsSettings.
AscoBinDir.setPath(QString(var));
772 ascoExec = QDir::toNativeSeparators(QucsSettings.
BinDir+
"/"+
"asco.exe");
774 ascoExec = QDir::toNativeSeparators(QucsSettings.
BinDir+
"/"+
"asco");
776 QFile asco(ascoExec);
781 var = getenv(
"OCTAVEBINDIR");
787 QucsSettings.
OctaveBinDir.setPath(QString(
"C:/Software/Octave-3.6.4/bin/"));
789 QFile octaveExec(
"/usr/bin/octave");
790 if(octaveExec.exists())QucsSettings.
OctaveBinDir.setPath(QString(
"/usr/bin/"));
791 QFile octaveExec1(
"/usr/local/bin/octave");
792 if(octaveExec1.exists()) QucsSettings.
OctaveBinDir.setPath(QString(
"/usr/local/bin/"));
797 if(!QucsSettings.
BGColor.isValid())
798 QucsSettings.
BGColor.setRgb(255, 250, 225);
801 if(!QucsSettings.
Comment.isValid())
802 QucsSettings.
Comment = Qt::gray;
803 if(!QucsSettings.
String.isValid())
804 QucsSettings.
String = Qt::red;
805 if(!QucsSettings.
Integer.isValid())
806 QucsSettings.
Integer = Qt::blue;
807 if(!QucsSettings.
Real.isValid())
808 QucsSettings.
Real = Qt::darkMagenta;
811 if(!QucsSettings.
Type.isValid())
812 QucsSettings.
Type = Qt::darkRed;
817 if(!QucsSettings.
Task.isValid())
818 QucsSettings.
Task = Qt::darkRed;
821 a.setFont(QucsSettings.
font);
824 QTextCodec::setCodecForLocale(QTextCodec::codecForName(
"UTF-8"));
825 QTextCodec::setCodecForTr(QTextCodec::codecForName(
"UTF-8"));
827 QTranslator tor( 0 );
828 QString lang = QucsSettings.
Language;
830 lang = QTextCodec::locale();
831 tor.load( QString(
"qucs_") + lang, QucsSettings.
LangDir);
832 a.installTranslator( &tor );
836 setlocale (LC_NUMERIC,
"C");
844 for (
int i = 1; i < argc; ++i) {
845 if (!strcmp(argv[i],
"-h") || !strcmp(argv[i],
"--help")) {
847 "Usage: %s [OPTION]...\n\n"
848 " -h, --help display this help and exit\n"
849 " -v, --version display version information and exit\n"
850 " -n, --netlist convert Qucs schematic into netlist\n"
851 " -i FILENAME use file as input schematic\n"
852 " -o FILENAME use file as output netlist\n"
856 else if (!strcmp(argv[i],
"-v") || !strcmp(argv[i],
"--version")) {
857 fprintf(stdout,
"Qucs " PACKAGE_VERSION
"\n");
860 else if (!strcmp(argv[i],
"-n") || !strcmp(argv[i],
"--netlist")) {
861 operation =
"netlist";
863 else if (!strcmp(argv[i],
"-i")) {
864 schematic = argv[++i];
866 else if (!strcmp(argv[i],
"-o")) {
870 fprintf(stderr,
"Error: Unknown option: %s\n", argv[i]);
876 if (operation ==
"netlist") {
877 if (schematic.isEmpty()) {
878 fprintf(stderr,
"Error: Expected input schematic file.\n");
881 if (netlist.isEmpty()) {
882 fprintf(stderr,
"Error: Expected output netlist file.\n");
890 a.setMainWidget(QucsMain);
893 int result = a.exec();
void str2num(const QString &s_, double &Number, QString &Unit, double &Factor)
QString properFileName(const QString &Name)
bool VHDL_Delay(QString &td, const QString &Name)
QString Verilog_Param(const QString Value)
tQucsSettings QucsSettings
QString complexDeg(double real, double imag, int Precision)
bool checkVersion(QString &Line)
QString StringNum(double num, char form, int Precision)
static void registerModules(void)
void convert2Unicode(QString &Text)
unsigned int numRecentDocs
bool Verilog_Delay(QString &td, const QString &Name)
Definitions and declarations for the main application.
int doNetlist(QString schematic, QString netlist)
QString StringNiceNum(double num)
QString properAbsFileName(const QString &Name)
QString complexRad(double real, double imag, int Precision)
QString createNetlist(QTextStream &, int)
QString num2str(double Num)
bool Verilog_Time(QString &t, const QString &Name)
bool VHDL_Time(QString &t, const QString &Name)
bool saveApplSettings(QucsApp *qucs)
QString complexRect(double real, double imag, int Precision)
void qucsMessageOutput(QtMsgType type, const char *msg)
qucsMessageOutput handles qDebug, qWarning, qCritical, qFatal.
void convert2ASCII(QString &Text)
int prepareNetlist(QTextStream &, QStringList &, QTextEdit *)
QString properName(const QString &Name)
int main(int argc, char *argv[])