Skip to content

Commit

Permalink
Merge pull request #523 from ra3xdh/522_fix
Browse files Browse the repository at this point in the history
Fix of #522
  • Loading branch information
guitorri authored Nov 2, 2016
2 parents e92c6f2 + dfd88ce commit b57fb42
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 149 deletions.
109 changes: 59 additions & 50 deletions qucs/qucs/diagrams/diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,63 +91,72 @@ Diagram::~Diagram()
*/
void Diagram::paint(ViewPainter *p)
{
// paint all lines
foreach(Line *pl, Lines) {
p->Painter->setPen(pl->style);
p->drawLine(cx+pl->x1, cy-pl->y1, cx+pl->x2, cy-pl->y2);
}

// paint all arcs (1 pixel larger to compensate for strange circle method)
foreach(Arc *pa, Arcs) {
p->Painter->setPen(pa->style);
p->drawArc(cx+pa->x, cy-pa->y, pa->w, pa->h, pa->angle, pa->arclen);
}

// draw all graphs
foreach(Graph *pg, Graphs)
pg->paint(p, cx, cy);

// keep track of painter state
p->Painter->save();
paintDiagram(p);
paintMarkers(p);
}

// write whole text (axis label inclusively)
QMatrix wm = p->Painter->worldMatrix();
foreach(Text *pt, Texts) {
p->Painter->setWorldMatrix(
QMatrix(pt->mCos, -pt->mSin, pt->mSin, pt->mCos,
p->DX + float(cx+pt->x) * p->Scale,
p->DY + float(cy-pt->y) * p->Scale));
void Diagram::paintDiagram(ViewPainter *p)
{
// paint all lines
foreach(Line *pl, Lines) {
p->Painter->setPen(pl->style);
p->drawLine(cx+pl->x1, cy-pl->y1, cx+pl->x2, cy-pl->y2);
}

p->Painter->setPen(pt->Color);
p->Painter->drawText(0, 0, pt->s);
}
p->Painter->setWorldMatrix(wm);
p->Painter->setWorldMatrixEnabled(false);
// paint all arcs (1 pixel larger to compensate for strange circle method)
foreach(Arc *pa, Arcs) {
p->Painter->setPen(pa->style);
p->drawArc(cx+pa->x, cy-pa->y, pa->w, pa->h, pa->angle, pa->arclen);
}

// restore painter state
p->Painter->restore();
// draw all graphs
foreach(Graph *pg, Graphs)
pg->paint(p, cx, cy);

// draw markers last, so they are at the top of painting layers
foreach(Graph *pg, Graphs)
foreach(Marker *pm, pg->Markers)
pm->paint(p, cx, cy);
// keep track of painter state
p->Painter->save();

// write whole text (axis label inclusively)
QMatrix wm = p->Painter->worldMatrix();
foreach(Text *pt, Texts) {
p->Painter->setWorldMatrix(
QMatrix(pt->mCos, -pt->mSin, pt->mSin, pt->mCos,
p->DX + float(cx+pt->x) * p->Scale,
p->DY + float(cy-pt->y) * p->Scale));

if(isSelected) {
int x_, y_;
float fx_, fy_;
p->map(cx, cy-y2, x_, y_);
fx_ = float(x2)*p->Scale + 10;
fy_ = float(y2)*p->Scale + 10;
p->Painter->setPen(pt->Color);
p->Painter->drawText(0, 0, pt->s);
}
p->Painter->setWorldMatrix(wm);
p->Painter->setWorldMatrixEnabled(false);

// restore painter state
p->Painter->restore();


if(isSelected) {
int x_, y_;
float fx_, fy_;
p->map(cx, cy-y2, x_, y_);
fx_ = float(x2)*p->Scale + 10;
fy_ = float(y2)*p->Scale + 10;

p->Painter->setPen(QPen(Qt::darkGray,3));
p->Painter->drawRect(x_-5, y_-5, TO_INT(fx_), TO_INT(fy_));
p->Painter->setPen(QPen(Qt::darkRed,2));
p->drawResizeRect(cx, cy-y2); // markers for changing the size
p->drawResizeRect(cx, cy);
p->drawResizeRect(cx+x2, cy-y2);
p->drawResizeRect(cx+x2, cy);
}
}

p->Painter->setPen(QPen(Qt::darkGray,3));
p->Painter->drawRect(x_-5, y_-5, TO_INT(fx_), TO_INT(fy_));
p->Painter->setPen(QPen(Qt::darkRed,2));
p->drawResizeRect(cx, cy-y2); // markers for changing the size
p->drawResizeRect(cx, cy);
p->drawResizeRect(cx+x2, cy-y2);
p->drawResizeRect(cx+x2, cy);
}
void Diagram::paintMarkers(ViewPainter *p, bool paintAll)
{
// draw markers last, so they are at the top of painting layers
foreach(Graph *pg, Graphs)
foreach(Marker *pm, pg->Markers)
if ((pm->Type & 1)||paintAll) pm->paint(p, cx, cy);
}

// ------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions qucs/qucs/diagrams/diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Diagram : public Element {
virtual QString extraMarkerText(Marker const*) const {return "";}

virtual void paint(ViewPainter*);
void paintDiagram(ViewPainter* p);
void paintMarkers(ViewPainter* p, bool paintAll = true);
void setCenter(int, int, bool relative=false);
void getCenter(int&, int&);
void paintScheme(Schematic*);
Expand Down
16 changes: 10 additions & 6 deletions qucs/qucs/dialogs/exportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ ExportDialog::ExportDialog(int w, int h, int wsel, int hsel, QString filename_,
connect(cbResolution,SIGNAL(toggled(bool)),cbRatio,SLOT(setDisabled(bool)));
connect(cbResolution,SIGNAL(toggled(bool)),editScale,SLOT(setDisabled(bool)));
connect(cbResolution,SIGNAL(toggled(bool)),this,SLOT(restoreOriginalWtoH()));
cbResolution->setChecked(true);

connect(editResolutionX,SIGNAL(textEdited(QString)),this,SLOT(calcHeight()));
connect(editResolutionY,SIGNAL(textEdited(QString)),this,SLOT(calcWidth()));
Expand All @@ -94,11 +93,11 @@ ExportDialog::ExportDialog(int w, int h, int wsel, int hsel, QString filename_,
connect(cbSelected,SIGNAL(toggled(bool)),this,SLOT(setSelectedWH()));
cbSelected->setChecked(false);
if (noselected) cbSelected->setDisabled(true);


cbResolution->setChecked(true);
//cbResolution->setEnabled(false);
cbRatio->setEnabled(false);


top = new QVBoxLayout;
lower1 = new QHBoxLayout;
lower2 = new QHBoxLayout;
Expand Down Expand Up @@ -227,9 +226,14 @@ void ExportDialog::recalcRatio()
void ExportDialog::restoreOriginalWtoH()
{
if (cbResolution->isChecked()) {
editScale->setText(QString::number(1.0));
editResolutionX->setText(QString::number(dwidth));
editResolutionY->setText(QString::number(dheight));
if (cbSelected->isChecked()) { // Export selected only
editResolutionX->setText(QString::number(dwidthsel));
editResolutionY->setText(QString::number(dheightsel));
} else {
editScale->setText(QString::number(1.0));
editResolutionX->setText(QString::number(dwidth));
editResolutionY->setText(QString::number(dheight));
}
}
}

Expand Down
114 changes: 106 additions & 8 deletions qucs/qucs/imagewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ImageWriter::noGuiPrint(QWidget *doc, QString printFile, QString color)
int w,h,wsel,hsel,
xmin, ymin, xmin_sel, ymin_sel;
getSchWidthAndHeight(sch, w,h,xmin,ymin);
sch->getSelAreaWidthAndHeight(wsel, hsel, xmin_sel, ymin_sel);
getSelAreaWidthAndHeight(sch, wsel, hsel, xmin_sel, ymin_sel);
w += bourder;
h += bourder;
wsel += bourder;
Expand Down Expand Up @@ -135,7 +135,7 @@ int ImageWriter::print(QWidget *doc)
int status = -1;

getSchWidthAndHeight(sch, w, h, xmin, ymin);
sch->getSelAreaWidthAndHeight(wsel, hsel, xmin_sel, ymin_sel);
getSelAreaWidthAndHeight(sch, wsel, hsel, xmin_sel, ymin_sel);
w += border;
h += border;
wsel += border;
Expand Down Expand Up @@ -279,18 +279,116 @@ int ImageWriter::print(QWidget *doc)

void ImageWriter::getSchWidthAndHeight(Schematic *sch, int &w, int &h, int &xmin, int &ymin)
{
xmin = sch->UsedX1;
ymin = sch->UsedY1;
w = abs(sch->UsedX2 - xmin);
h = abs(sch->UsedY2 - ymin);
int xmax,ymax;
sch->sizeOfAll(xmin,ymin,xmax,ymax);
w = abs(xmax - xmin);
h = abs(ymax - ymin);

int f_w, f_h;
if (sch->sizeOfFrame(f_w,f_h)) {
xmin = std::min(0,xmin); // For components
ymin = std::min(0,ymin); // that fall out of frame
w = abs(std::max(f_w,sch->UsedX2) - xmin);
h = abs(std::max(f_h,sch->UsedY2) - ymin);
//w = std::max(w,f_w);
//h = std::max(h,f_h);
}
}

void ImageWriter::getSelAreaWidthAndHeight(Schematic *sch, int &wsel, int &hsel, int& xmin_sel_, int& ymin_sel_)
{
int xmin= INT_MAX,
ymin= INT_MAX,
xmax= INT_MIN,
ymax= INT_MIN;

for(Component *pc = sch->Components->first(); pc != 0; pc = sch->Components->next()) {
if (pc->isSelected) {
int x1,y1,x2,y2;
pc->entireBounds(x1,y1,x2,y2,sch->textCorr());
updateMinMax(xmin,xmax,ymin,ymax,x1,x2,y1,y2);
}
}

for(Wire *pw = sch->Wires->first(); pw != 0; pw = sch->Wires->next()) {

if (pw->isSelected) {
if(pw->x1 < xmin) xmin = pw->x1;
if(pw->x2 > xmax) xmax = pw->x2;
if(pw->y1 < ymin) ymin = pw->y1;
if(pw->y2 > ymax) ymax = pw->y2;
qDebug() << pw->x1 << pw->x2 << pw->y1 << pw->y2;
}
if (pw->Label) {
WireLabel *pl = pw->Label;
if (pl->isSelected) {
int x1,y1,x2,y2;
pl->getLabelBounding(x1,y1,x2,y2);
qDebug()<<x1<<y1<<x2<<y2;
updateMinMax(xmin,xmax,ymin,ymax,x1,x2,y1,y2);
}
}
}

for(Node *pn = sch->Nodes->first(); pn != 0; pn = sch->Nodes->next()) {
WireLabel *pl = pn->Label;
if(pl) { // check position of node label
if (pl->isSelected) {
int x1,x2,y1,y2;
pl->getLabelBounding(x1,y1,x2,y2);
if(x1 < xmin) xmin = x1;
if(x2 > xmax) xmax = x2;
if(y1 < ymin) ymin = y1;
if(y2 > ymax) ymax = y2;
}
}
}

for(Diagram *pd = sch->Diagrams->first(); pd != 0; pd =sch-> Diagrams->next()) {



if (pd->isSelected) {
int x1,y1,x2,y2;
pd->Bounding(x1,y1,x2,y2);
updateMinMax(xmin,xmax,ymin,ymax,x1,x2,y1,y2);

foreach (Graph *pg, pd->Graphs) {
foreach (Marker *pm, pg->Markers) {
if (pm->isSelected) {
int x1,y1,x2,y2;
pm->Bounding(x1,y1,x2,y2);
updateMinMax(xmin,xmax,ymin,ymax,x1,x2,y1,y2);
}
}
}
}
}

for(Painting *pp = sch->Paintings->first(); pp != 0; pp = sch->Paintings->next()) {

if (pp->isSelected) {
int x1,y1,x2,y2;
pp->Bounding(x1,y1,x2,y2);
updateMinMax(xmin,xmax,ymin,ymax,x1,x2,y1,y2);
}
}

wsel = abs(xmax - xmin);
hsel = abs(ymax - ymin);
xmin_sel_ = xmin;
ymin_sel_ = ymin;
}

// Compare object (component, diagram, etc) coordinates and
// current corner coordinates and update it
void ImageWriter::updateMinMax(int &xmin, int &xmax, int &ymin, int &ymax,
int x1, int x2, int y1, int y2)
{
int d1 = std::min(x1,x2);
if (d1<xmin) xmin = d1;
int d2 = std::max(x2,x1);
if (d2>xmax) xmax = d2;
int d3 = std::min(y1,y2);
if (d3<ymin) ymin = d3;
int d4 = std::max(y2,y1);
if (d4>ymax) ymax = d4;
}
2 changes: 2 additions & 0 deletions qucs/qucs/imagewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ImageWriter
QString lastExportFilename;

void getSchWidthAndHeight(Schematic *sch, int &w, int &h, int &xmin, int &ymin);
void getSelAreaWidthAndHeight(Schematic *sch, int &wsel, int& hsel, int& xmin_sel_, int& ymin_sel_);
void updateMinMax(int &xmin, int &xmax, int &ymin, int &ymax, int x1, int x2, int y1m, int y2);
};

#endif
Loading

0 comments on commit b57fb42

Please sign in to comment.