Skip to content

Commit

Permalink
zoom to selection implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
zergud committed Oct 17, 2023
1 parent 5e5d5ee commit adaefdc
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 1 deletion.
Binary file added qucs/bitmaps/viewmagsel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions qucs/qucs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,13 @@ void QucsApp::slotShowAll()
getDoc()->showAll();
}

// --------------------------------------------------------------
void QucsApp::slotZoomToSelection()
{
slotHideEdit(); // disable text edit of component property
getDoc()->zoomToSelection();
}

// -----------------------------------------------------------
// Sets the scale factor to 1.
void QucsApp::slotShowOne()
Expand Down
3 changes: 2 additions & 1 deletion qucs/qucs.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public slots:
void slotPopHierarchy();

void slotShowAll();
void slotZoomToSelection();
void slotShowOne();
void slotZoomOut(); // Zoom out by 2

Expand Down Expand Up @@ -220,7 +221,7 @@ private slots:
QAction *fileNew, *textNew, *fileNewDpl, *fileOpen, *fileSave, *fileSaveAs,
*fileSaveAll, *fileClose, *fileExamples, *fileSettings, *filePrint, *fileQuit,
*projNew, *projOpen, *projDel, *projClose, *applSettings, *refreshSchPath,
*editCut, *editCopy, *magAll, *magOne, *magMinus, *filePrintFit, *tune,
*editCut, *editCopy, *magAll, *magSel, *magOne, *magMinus, *filePrintFit, *tune,
*symEdit, *intoH, *popH, *simulate, *save_netlist, *dpl_sch, *undo, *redo, *dcbias;

QAction *exportAsImage;
Expand Down
1 change: 1 addition & 0 deletions qucs/qucs.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<file>bitmaps/viewmag+.png</file>
<file>bitmaps/viewmag1.png</file>
<file>bitmaps/viewmagfit.png</file>
<file>bitmaps/viewmagsel.png</file>
<file>bitmaps/vprobe.png</file>
<file>bitmaps/vpulse.png</file>
<file>bitmaps/vrect.png</file>
Expand Down
8 changes: 8 additions & 0 deletions qucs/qucs_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ void QucsApp::initActions()
magAll->setWhatsThis(tr("View All\n\nShows the whole page content"));
connect(magAll, SIGNAL(triggered()), SLOT(slotShowAll()));

magSel = new QAction(QIcon((":/bitmaps/viewmagsel.png")), tr("Zoom to selection"), this);
magSel->setShortcut(tr("Z"));
magSel->setStatusTip(tr("Zoom to selected components"));
magSel->setWhatsThis(tr("Zoom to selection\n\nZoom to selected components"));
connect(magSel, SIGNAL(triggered()), SLOT(slotZoomToSelection()));

magOne = new QAction(QIcon((":/bitmaps/viewmag1.png")), tr("View 1:1"), this);
magOne->setShortcut(Qt::Key_1);
magOne->setStatusTip(tr("Views without magnification"));
Expand Down Expand Up @@ -778,6 +784,7 @@ void QucsApp::initMenuBar()

viewMenu = new QMenu(tr("&View")); // menuBar entry viewMenu
viewMenu->addAction(magAll);
viewMenu->addAction(magSel);
viewMenu->addAction(magOne);
viewMenu->addAction(magPlus);
viewMenu->addAction(magMinus);
Expand Down Expand Up @@ -904,6 +911,7 @@ void QucsApp::initToolBar()
viewToolbar = new QToolBar(tr("View"));
this->addToolBar(viewToolbar);
viewToolbar->addAction(magAll);
viewToolbar->addAction(magSel);
viewToolbar->addAction(magOne);
viewToolbar->addAction(magPlus);
viewToolbar->addAction(magMinus);
Expand Down
1 change: 1 addition & 0 deletions qucs/qucsdoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class QucsDoc {
virtual void becomeCurrent(bool) {};
virtual float zoomBy(float) { return 1.0; };
virtual void showAll() {};
virtual void zoomToSelection() {};
virtual void showNoZoom() {};

static QString fileSuffix (const QString&);
Expand Down
142 changes: 142 additions & 0 deletions qucs/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,30 @@ void Schematic::showAll()
zoom(xScale);
}

// ------------------------------------------------------
void Schematic::zoomToSelection()
{
sizeOfSelection(UsedX1, UsedY1, UsedX2, UsedY2);
if(UsedX1 == 0)
if(UsedX2 == 0)
if(UsedY1 == 0)
if(UsedY2 == 0) {
showAll();
return;
}

float xScale = float(visibleWidth()) / float(UsedX2-UsedX1+80);
float yScale = float(visibleHeight()) / float(UsedY2-UsedY1+80);
if(xScale > yScale) xScale = yScale;
xScale /= Scale;

ViewX1 = UsedX1 - 40;
ViewY1 = UsedY1 - 40;
ViewX2 = UsedX2 + 40;
ViewY2 = UsedY2 + 40;
zoom(xScale);
}

// ---------------------------------------------------
void Schematic::showNoZoom()
{
Expand Down Expand Up @@ -1018,6 +1042,124 @@ void Schematic::sizeOfAll(int& xmin, int& ymin, int& xmax, int& ymax)
}
}

void Schematic::sizeOfSelection(int& xmin, int& ymin, int& xmax, int& ymax)
{
xmin=INT_MAX;
ymin=INT_MAX;
xmax=INT_MIN;
ymax=INT_MIN;
Component *pc;
Diagram *pd;
Wire *pw;
WireLabel *pl;
Painting *pp;

bool isAnySelected = false;

if(Components->isEmpty())
if(Wires->isEmpty())
if(Diagrams->isEmpty())
if(Paintings->isEmpty()) {
xmin = xmax = 0;
ymin = ymax = 0;
return;
}


float Corr = textCorr();
int x1, y1, x2, y2;
// find boundings of all components
for(pc = Components->first(); pc != 0; pc = Components->next()) {
if (!pc->isSelected) {
continue;
}
isAnySelected = true;
pc->entireBounds(x1, y1, x2, y2, Corr);
if(x1 < xmin) xmin = x1;
if(x2 > xmax) xmax = x2;
if(y1 < ymin) ymin = y1;
if(y2 > ymax) ymax = y2;
}

// find boundings of all wires
for(pw = Wires->first(); pw != 0; pw = Wires->next()) {
if (!pw->isSelected) {
continue;
}
isAnySelected = true;
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;

pl = pw->Label;
if(pl) { // check position of wire label
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;
}
}

// find boundings of all node labels
for(Node *pn = Nodes->first(); pn != 0; pn = Nodes->next()) {
if (!pn->isSelected) {
continue;
}
isAnySelected = true;
pl = pn->Label;
if(pl) { // check position of node label
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;
}
}

// find boundings of all diagrams
for(pd = Diagrams->first(); pd != 0; pd = Diagrams->next()) {
if (!pd->isSelected) {
continue;
}
isAnySelected = true;
pd->Bounding(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 (Graph *pg : pd->Graphs)
// test all markers of diagram
for (Marker *pm : pg->Markers) {
pm->Bounding(x1, y1, x2, y2);
if(x1 < xmin) xmin = x1;
if(x2 > xmax) xmax = x2;
if(y1 < ymin) ymin = y1;
if(y2 > ymax) ymax = y2;
}
}

// find boundings of all Paintings
for(pp = Paintings->first(); pp != nullptr; pp = Paintings->next()) {
if (!pp->isSelected) {
continue;
}
isAnySelected = true;
pp->Bounding(x1, y1, x2, y2);
if(x1 < xmin) xmin = x1;
if(x2 > xmax) xmax = x2;
if(y1 < ymin) ymin = y1;
if(y2 > ymax) ymax = y2;
}

if (!isAnySelected) {
xmin = xmax = 0;
ymin = ymax = 0;
}
}

// ---------------------------------------------------
// Rotates all selected components around their midpoint.
bool Schematic::rotateElements()
Expand Down
3 changes: 3 additions & 0 deletions qucs/schematic.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Schematic : public Q3ScrollView, public QucsDoc {
float textCorr();
bool sizeOfFrame(int&, int&);
void sizeOfAll(int&, int&, int&, int&);
void sizeOfSelection(int&, int&, int&, int&);
bool rotateElements();
bool mirrorXComponents();
bool mirrorYComponents();
Expand All @@ -102,6 +103,7 @@ class Schematic : public Q3ScrollView, public QucsDoc {
float zoom(float);
float zoomBy(float);
void showAll();
void zoomToSelection();
void showNoZoom();
void enlargeView(int, int, int, int);
void switchPaintMode();
Expand Down Expand Up @@ -325,6 +327,7 @@ protected slots:
bool isAnalog;
bool isVerilog;
bool creatingLib;

};

#endif

0 comments on commit adaefdc

Please sign in to comment.