28 #include <qfileinfo.h>
40 Description = QObject::tr(
"Component taken from Qucs library");
48 QObject::tr(
"name of qucs library file")));
50 QObject::tr(
"name of component in library")));
57 p->
Props.first()->Value =
Props.first()->Value;
70 if(loadSymbol() > 0) {
71 if(
tx == INT_MIN)
tx =
x1+4;
72 if(
ty == INT_MIN)
ty =
y2+4;
76 Lines.append(
new Line(-15, -15, 15, -15, QPen(QPen::darkBlue,2)));
77 Lines.append(
new Line( 15, -15, 15, 15, QPen(QPen::darkBlue,2)));
78 Lines.append(
new Line(-15, 15, 15, 15, QPen(QPen::darkBlue,2)));
79 Lines.append(
new Line(-15, -15,-15, 15, QPen(QPen::darkBlue,2)));
91 int LibComp::loadSection(
const QString& Name, QString& Section,
92 QStringList *Includes)
95 QFile file(Directory.absFilePath(
Props.first()->Value +
".lib"));
96 if(!file.open(IO_ReadOnly))
99 QTextStream ReadWhole(&file);
100 Section = ReadWhole.read();
104 if(Section.left(14) !=
"<Qucs Library ")
107 int Start,
End = Section.find(
' ', 14);
108 if(End < 15)
return -3;
109 QString
Line = Section.mid(14, End-14);
113 if(Name ==
"Symbol") {
114 Start = Section.find(
"\n<", 14);
116 if(Section.mid(Start+2, 14) ==
"DefaultSymbol>") {
118 End = Section.find(
"\n</DefaultSymbol>", Start);
119 if(End < 0)
return -9;
120 Section = Section.mid(Start, End-Start);
126 Line =
"\n<Component " +
Props.next()->Value +
">";
127 Start = Section.find(Line);
128 if(Start < 0)
return -4;
129 Start = Section.find(
'\n', Start);
130 if(Start < 0)
return -5;
132 End = Section.find(
"\n</Component>", Start);
133 if(End < 0)
return -6;
134 Section = Section.mid(Start, End-Start+1);
139 StartI = Section.find(
"<"+Name+
"Includes");
141 StartI = Section.find(
'"', StartI);
142 if(StartI < 0)
return -10;
143 EndI = Section.find(
'>', StartI);
144 if(EndI < 0)
return -11;
146 QString inc = Section.mid(StartI, EndI-StartI);
147 QStringList f = QStringList::split(QRegExp(
"\"\\s+\""), inc);
148 for(QStringList::Iterator it = f.begin(); it != f.end(); ++it ) {
149 Includes->append(*it);
155 Start = Section.find(
"<"+Name+
">");
156 if(Start < 0)
return -7;
157 Start = Section.find(
'\n', Start);
158 if(Start < 0)
return -8;
159 while(Section.at(++Start) ==
' ') ;
160 End = Section.find(
"</"+Name+
">", Start);
161 if(End < 0)
return -9;
164 Section = Section.mid(Start, End-Start);
171 int LibComp::loadSymbol()
174 QString FileString, Line;
175 z = loadSection(
"Symbol", FileString);
177 if(z != -7)
return z;
181 z = loadSection(
"Model", Line);
185 if(pc == 0)
return -20;
189 pc->
Arcs.setAutoDelete(
false);
190 pc->
Lines.setAutoDelete(
false);
191 pc->
Rects.setAutoDelete(
false);
192 pc->
Ellips.setAutoDelete(
false);
193 pc->
Ports.setAutoDelete(
false);
194 pc->
Texts.setAutoDelete(
false);
195 pc->
Props.setAutoDelete(
false);
206 QTextStream stream(&FileString, IO_ReadOnly);
207 while(!stream.atEnd()) {
208 Line = stream.readLine();
209 Line = Line.stripWhiteSpace();
210 if(Line.isEmpty())
continue;
211 if(Line.at(0) !=
'<')
return -11;
212 if(Line.at(Line.length()-1) !=
'>')
return -12;
213 Line = Line.mid(1, Line.length()-2);
215 if(Result < 0)
return -13;
228 QString FileName = Directory.absFilePath(
Props.first()->Value);
238 QStringList Includes;
240 r = loadSection(
"Model", FileString, &Includes);
242 r = loadSection(
"VHDLModel", FileString, &Includes);
244 r = loadSection(
"VerilogModel", FileString, &Includes);
246 if(r < 0)
return false;
250 for(QStringList::Iterator it = Includes.begin();
251 it != Includes.end(); ++it ) {
253 if(FileList.findIndex(s) >= 0)
continue;
258 if(!file.open(IO_ReadOnly)) {
261 QByteArray FileContent = file.readAll();
263 stream->writeRawBytes(FileContent.data(), FileContent.size());
267 (*stream) <<
"\n" << FileString <<
"\n";
268 return error > 0 ?
false :
true;
272 QString LibComp::createType()
281 QString
s =
"Sub:"+
Name;
285 s +=
" "+p1->Connection->Name;
288 s +=
" Type=\""+createType()+
"\"";
292 s +=
" "+pp->Name+
"=\""+pp->Value+
"\"";
300 QString
s =
" Sub_" + createType() +
" " + Name +
" (";
305 for(pp =
Ports.next(); pp != 0; pp =
Ports.next())
315 QString
s =
" " + Name +
": entity Sub_" + createType() +
" port map (";
320 for(pp =
Ports.next(); pp != 0; pp =
Ports.next())