forked from Qucs/qucs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce symbol class. (start to) use it in qucslib
- Loading branch information
1 parent
2c08997
commit c15a7a1
Showing
7 changed files
with
150 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "symbol.h" | ||
|
||
/*! | ||
* \brief this library provides symbols. these. | ||
*/ | ||
class QucsLibComponent : public Symbol{ | ||
public: | ||
QucsLibComponent( QString& , const QString&, const QString& ); | ||
|
||
}; | ||
|
||
QucsLibComponent::QucsLibComponent( QString& SymbolString, | ||
const QString& Lib_, const QString& Comp_) | ||
: Symbol(), LibraryName(Lib_), ComponentName(Comp_) | ||
{ | ||
if (SymbolString.isEmpty())//Whenever SymbolString is empty, it tries to load the default symbol | ||
{ | ||
//Load the default symbol for the current Qucs library | ||
ComponentLibrary parsedlib; | ||
QString libpath = QucsSettings.LibDir + Lib_ + ".lib"; | ||
int result = parseComponentLibrary (libpath, parsedlib); | ||
|
||
// BUG: throw if there is an error. don't randomly spawn Messageboxes | ||
// (cleanup later) | ||
switch (result)//Check if the library was properly loaded | ||
{ | ||
case QUCS_COMP_LIB_IO_ERROR: | ||
QMessageBox::critical(0, tr ("Error"), tr("Cannot open \"%1\".").arg (libpath)); | ||
return -1; | ||
case QUCS_COMP_LIB_CORRUPT: | ||
QMessageBox::critical(0, tr("Error"), tr("Library is corrupt.")); | ||
return -1; | ||
default: | ||
break; | ||
} | ||
|
||
// copy the contents of default symbol section to a string | ||
SymbolString = parsedlib.defaultSymbol; | ||
} | ||
} | ||
|
||
QucsLibComponent::draw(Qwidget& w) | ||
{ | ||
w.Arcs.clear(); | ||
w.Lines.clear(); | ||
w.Rects.clear(); | ||
w.Ellips.clear(); | ||
w.Texts.clear(); | ||
|
||
QString Line; | ||
///QString foo = SymbolString; | ||
QTextStream stream(&SymbolString, QIODevice::ReadOnly); | ||
|
||
x1 = y1 = INT_MAX; | ||
x2 = y2 = INT_MIN; | ||
|
||
int z=0, Result; | ||
while(!stream.atEnd()) { | ||
Line = stream.readLine(); | ||
Line = Line.trimmed(); | ||
if(Line.isEmpty()) continue; | ||
|
||
if(Line.at(0) != '<') return -1; // check for start char | ||
if(Line.at(Line.length()-1) != '>') return -1; // check for end char | ||
Line = Line.mid(1, Line.length()-2); // cut off start and end character | ||
Result = analyseLine(Line); | ||
if(Result < 0) return -6; // line format error | ||
z += Result; | ||
} | ||
|
||
x1 -= 4; // enlarge component boundings a little | ||
x2 += 4; | ||
y1 -= 4; | ||
y2 += 4; | ||
cx = -x1 + TextWidth; | ||
cy = -y1; | ||
|
||
int dx = x2-x1 + TextWidth; | ||
if((x2-x1) < DragNDropWidth) | ||
dx = (x2-x1 + DragNDropWidth)/2 + TextWidth; | ||
if(dx < DragNDropWidth) | ||
dx = DragNDropWidth; | ||
setMinimumSize(dx, y2-y1 + TextHeight+4); | ||
if(width() > dx) dx = width(); | ||
resize(dx, y2-y1 + TextHeight+4); | ||
update(); | ||
return z; // return number of ports | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/*************************************************************************** | ||
element.h | ||
----------- | ||
begin : 2016 | ||
copyright : (C) 2016 Felix Salfelder | ||
email : felix@salfelder.org | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
/** \file symbol.h | ||
* \brief Defines symbols for components, to be used in schematics. | ||
* | ||
* a symbol mostly takes care of ports, parameters and connectivity. | ||
* (this is under construction) | ||
* | ||
*/ | ||
|
||
#ifndef SYMBOL_H | ||
#define SYMBOL_H | ||
|
||
/** \class Symbol | ||
* \brief Superclass of all circuit components (except wires). | ||
* | ||
* | ||
*/ | ||
class Symbol { | ||
public: // construct | ||
Symbol(); | ||
virtual ~Symbol(){} | ||
|
||
public: // interface | ||
virtual void draw(Widget&) = 0; | ||
//... more to come | ||
}; | ||
|
||
|
||
#endif |
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! 👍
This template/eye-opener was really needed.
I'll try to help as much as I can. :)
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make it compile? there are some stupid mistakes... symbol.h line 40 must be QWidget (need to include the header). implementation should move to symbol.cpp, makefiles etc...
about Element: this class is confusing. it only holds the type and coordinates. this is not needed: the type is obvious from the type (sic!) and the coordinates are parameters actually. symbols will have parameters anyway...
(will have a look later today.)
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't compile, of course. There are a number of dependencies to be solved.
I'm working on it right now.
Yep, I've realized that it was a mistake :-)
Just in case,... if I understood correctly, here we should use QucsLibComponent instead of Symbol
On the other hand, I am wondering if SymbolWidget should keep the following fields: QString ModelString, VerilogModelString, VHDLModelString;? I mean, to my mind, the purpose of SymbolWidget is to be used by QucsLibComponent instance just to display the part symbol in the dialog, am I right? So, maybe, it would be more appropriate to put these strings in QucsLibComponent class.
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and no. (my code is still wrong.) actually what is needed here is a
Symbol*
pointing to an instance ofQucsLibComponent
. currently, there is no instance and no pointer, but the stupid ad-hoc instanciation...(i think you can fix it by just putting it as you wrote, for now).
yes, an instance of QucsLibComponent should hold all information required/available about that symbol. that's only a question of how far we go right now. proper code is easier to grasp, so moving stuff into place always makes sense, YMMV. do it if you like. it might trigger more code movement... i will definitely review it.
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed my changes to a branch: andresmmera@6a6c7e5
Take a look if you wish, but it is not finished. I guess I'll continue at night...
Meanwhile, I have to figure out how to convert SymbolWidget into QWidget here
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice.
i was expecting that it's possible to draw to a QWidget. maybe that's not entirely correct. will have a look, there should be a way...
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether it is possible or not... but I'll check if there's some sort of QWidget inheritance somewhere else in Qucs
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm it seems to be.
the current code attaches a Painter to the QWidget and simply paints stuff. let me see if i can compile this....
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At worse, we could remove draw(QWidget&) from the base class...
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, painting should not be a problem. but the graphics must be held in the symbols instance. the widget is the wrong place, as it cannot be accessed from within qucs.
i am now wondering, how DragNDropWidth is meant to work. anyway, i will have to check the drag and drop thing: drag and drop should simply transport a const pointer to the symbol being dragged... but the other end does not understand symbols yet (argh).
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will want to draw symbols in other places, too. e.g. in the schematic. or in a pdf. i think this function is vital.
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will have to move some code around but it's pretty clear to me now. expect an update later today.
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll stay tuned for it.
I've moved some headers (and struct definitions, etc...) back and forth. (last commit: andresmmera@dcb1a9b) I think that, apart from the QWidget issue, the rest of the code can be compiled without errors.
c15a7a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have merged dcb1a9b.
updated my branch, it now compiles. there are two constructors for QucsLibComponent. one of them is nonsense, i think. and... i will have to revisit the dragndrop code.
NB: the function i called "draw" now draws. i accidentally put constructor code there in my first pass...
and there is a doSometimg function, i don't know what it does, perhaps it must go to the constructor or to attach.
(looking forward to add the geda symbols...:)