Skip to content

Commit

Permalink
Trying to compile QucsLib with Symbol class. Step 1
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmmera committed Aug 19, 2016
1 parent c15a7a1 commit 6a6c7e5
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 48 deletions.
65 changes: 37 additions & 28 deletions qucs/qucs-lib/libcomp.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#include "symbol.h"

#include "qucslib_common.h"
/*!
* \brief this library provides symbols. these.
*/



class QucsLibComponent : public Symbol{
private:
QString SymbolString, LibraryName, ComponentName;
public:
QucsLibComponent( QString& , const QString&, const QString& );

int draw(QWidget&);
};

QucsLibComponent::QucsLibComponent( QString& SymbolString,
extern tQucsSettings QucsSettings;

QucsLibComponent::QucsLibComponent( QString& SymbolString_,
const QString& Lib_, const QString& Comp_)
: Symbol(), LibraryName(Lib_), ComponentName(Comp_)
: SymbolString(SymbolString_), LibraryName(Lib_), ComponentName(Comp_)
{
if (SymbolString.isEmpty())//Whenever SymbolString is empty, it tries to load the default symbol
{
Expand All @@ -25,11 +32,11 @@ QucsLibComponent::QucsLibComponent( QString& SymbolString,
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;
QMessageBox::critical(0, "Error", QString("Cannot open \"%1\".").arg (libpath));
return;
case QUCS_COMP_LIB_CORRUPT:
QMessageBox::critical(0, tr("Error"), tr("Library is corrupt."));
return -1;
QMessageBox::critical(0, "Error", "Library is corrupt.");
return;
default:
break;
}
Expand All @@ -39,7 +46,9 @@ QucsLibComponent::QucsLibComponent( QString& SymbolString,
}
}

QucsLibComponent::draw(Qwidget& w)


int QucsLibComponent::draw(QWidget& w)
{
w.Arcs.clear();
w.Lines.clear();
Expand All @@ -51,8 +60,8 @@ QucsLibComponent::draw(Qwidget& w)
///QString foo = SymbolString;
QTextStream stream(&SymbolString, QIODevice::ReadOnly);

x1 = y1 = INT_MAX;
x2 = y2 = INT_MIN;
w.x1 = w.y1 = INT_MAX;
w.x2 = w.y2 = INT_MIN;

int z=0, Result;
while(!stream.atEnd()) {
Expand All @@ -63,27 +72,27 @@ QucsLibComponent::draw(Qwidget& w)
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);
Result = w.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();
w.x1 -= 4; // enlarge component boundings a little
w.x2 += 4;
w.y1 -= 4;
w.y2 += 4;
w.cx = -w.x1 + w.TextWidth;
w.cy = -w.y1;

int dx = w.x2-w.x1 + w.TextWidth;
if((w.x2-w.x1) < w.DragNDropWidth)
dx = (w.x2-w.x1 + w.DragNDropWidth)/2 + w.TextWidth;
if(dx < w.DragNDropWidth)
dx = w.DragNDropWidth;
w.setMinimumSize(dx, w.y2-w.y1 + w.TextHeight+4);
if(w.width() > dx) dx = w.width();
w.resize(dx, w.y2-w.y1 + w.TextHeight+4);
w.update();
return z; // return number of ports
}

2 changes: 1 addition & 1 deletion qucs/qucs-lib/qucslib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ void QucsLib::slotShowComponent(QListWidgetItem *Item)

// it's a bit late, but without a symbol we cannot draw a symbol to the
// widget... lets create a symbol!
Symbol compSym(content, LibName, Item->text());
QucsLibComponent compSym(content, LibName, Item->text());
compSym.draw(symWidget);

// change currently selected category, so the user will
Expand Down
13 changes: 3 additions & 10 deletions qucs/qucs-lib/qucslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,10 @@
#include <QComboBox>

#include "symbolwidget.h"
#include "libcomp.h"



// Application settings.
struct tQucsSettings {
int x, y, dx, dy; // position and size of main window
QFont font; // font
QString LangDir; // translation directory
QString LibDir; // library directory
QString Language;
QDir QucsWorkDir; // Qucs user directory where user works (usually same as QucsWorkDir
QDir QucsHomeDir; // Qucs user directory where all projects are located
};

extern tQucsSettings QucsSettings;
extern QDir UserLibDir;
Expand Down Expand Up @@ -79,6 +71,7 @@ private slots:
int UserLibCount;
int libCurIdx;
SymbolWidget *symWidget;
QucsLibComponent *SelectedComponent;
QTextEdit *CompDescr;
QVBoxLayout *all;
QLineEdit *CompSearch;
Expand Down
14 changes: 14 additions & 0 deletions qucs/qucs-lib/qucslib_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
#include <QTextStream>
#include <QDebug>

// Application settings.
struct tQucsSettings {
int x, y, dx, dy; // position and size of main window
QFont font; // font
QString LangDir; // translation directory
QString LibDir; // library directory
QString Language;
QDir QucsWorkDir; // Qucs user directory where user works (usually same as QucsWorkDir
QDir QucsHomeDir; // Qucs user directory where all projects are located
};


// global functions and data structures for the processing of
// qucs library files

Expand All @@ -47,6 +59,8 @@ struct ComponentLibrary
} ;


extern tQucsSettings QucsSettings;

// gets the contents of a section from a coponent description
//
// sections are between <secname> </secname> pairs
Expand Down
67 changes: 60 additions & 7 deletions qucs/qucs-lib/symbolwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,59 @@
* \brief Definition of the SymbolWidget class.
*/


class Node;
class QPaintEvent;
class QSizePolicy;


struct Line {
Line(int _x1, int _y1, int _x2, int _y2, QPen _style)
: x1(_x1), y1(_y1), x2(_x2), y2(_y2), style(_style) {};
int x1, y1, x2, y2;
QPen style;
};

struct Arc {
Arc(int _x, int _y, int _w, int _h, int _angle, int _arclen, QPen _style)
: x(_x), y(_y), w(_w), h(_h), angle(_angle),
arclen(_arclen), style(_style) {};
int x, y, w, h, angle, arclen;
QPen style;
};

struct Area {
Area(int _x, int _y, int _w, int _h, QPen _Pen,
QBrush _Brush = QBrush(Qt::NoBrush))
: x(_x), y(_y), w(_w), h(_h), Pen(_Pen), Brush(_Brush) {};
int x, y, w, h;
QPen Pen;
QBrush Brush; // filling style/color
};

struct Port {
Port() {};
Port(int _x, int _y, bool _avail=true) : x(_x), y(_y), avail(_avail) {
Type=""; Connection=0;};
int x, y;
bool avail;
QString Type;
Node *Connection;
};

struct Text {
Text(int _x, int _y, const QString& _s, QColor _Color = QColor(0,0,0),
float _Size = 10.0, float _mCos=1.0, float _mSin=0.0)
: x(_x), y(_y), s(_s), Color(_Color), Size(_Size),
mSin(_mSin), mCos(_mCos) { over = under = false; };
int x, y;
QString s;
QColor Color;
float Size, mSin, mCos; // font size and rotation coefficients
bool over, under; // text attributes
};


class SymbolWidget : public QWidget {
Q_OBJECT
public:
Expand All @@ -52,26 +102,29 @@ class SymbolWidget : public QWidget {
QString Prefix, LibraryName, ComponentName;
QString ModelString, VerilogModelString, VHDLModelString;

QList<Line *> Lines;
QList<Arc *> Arcs;
QList<Area *> Rects, Ellips;
QList<Text *> Texts;
int cx, cy, x1, x2, y1, y2;
int TextWidth, DragNDropWidth, TextHeight;
int analyseLine(const QString&);

protected:
void mouseMoveEvent(QMouseEvent*);

private:
void paintEvent(QPaintEvent*);

int analyseLine(const QString&);


bool getPen (const QString&, QPen&, int);
bool getBrush(const QString&, QBrush&, int);

QString PaintText;
QString DragNDropText;
QString Warning;
int TextWidth, DragNDropWidth, TextHeight;
int cx, cy, x1, x2, y1, y2;
QList<Line *> Lines;
QList<Arc *> Arcs;
QList<Area *> Rects, Ellips;
QList<Text *> Texts;

};

#endif // SYMBOLWIDGET_H
6 changes: 4 additions & 2 deletions qucs/qucs/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* (this is under construction)
*
*/

#include <QWidget>
#ifndef SYMBOL_H
#define SYMBOL_H

Expand All @@ -31,13 +31,15 @@
*
*
*/


class Symbol {
public: // construct
Symbol();
virtual ~Symbol(){}

public: // interface
virtual void draw(Widget&) = 0;
virtual int draw(QWidget&) = 0;
//... more to come
};

Expand Down

0 comments on commit 6a6c7e5

Please sign in to comment.