Permalink
Browse files

Merge beb28d0 into d0707b7

  • Loading branch information...
global667
global667 committed Dec 8, 2014
2 parents d0707b7 + beb28d0 commit f8bc6237b7cccc74c99260c710a2baa53875da1b
Showing with 61 additions and 57 deletions.
  1. +1 −0 qucs/qucs/components/CMakeLists.txt
  2. +12 −12 qucs/qucs/schematic.cpp
  3. +7 −7 qucs/qucs/schematic.h
  4. +41 −38 qucs/qucs/schematic_element.cpp
@@ -237,6 +237,7 @@ volt_noise.h
vprobe.h
vpulse.h
vrect.h
mutualx.h
)
View
@@ -1040,11 +1040,11 @@ bool Schematic::rotateElements()
int x1=INT_MAX, y1=INT_MAX;
int x2=INT_MIN, y2=INT_MIN;
Q3PtrList<Element> ElementCache;
copyLabels(x1, y1, x2, y2, &ElementCache); // must be first of all !
copyComponents(x1, y1, x2, y2, &ElementCache);
copyWires(x1, y1, x2, y2, &ElementCache);
copyPaintings(x1, y1, x2, y2, &ElementCache);
QList<Element *> ElementCache;
copyLabels(x1, y1, x2, y2, ElementCache); // must be first of all !
copyComponents(x1, y1, x2, y2, ElementCache);
copyWires(x1, y1, x2, y2, ElementCache);
copyPaintings(x1, y1, x2, y2, ElementCache);
if(y1 == INT_MAX) return false; // no element selected
Wires->setAutoDelete(true);
@@ -1060,7 +1060,7 @@ bool Schematic::rotateElements()
Component *pc;
WireLabel *pl;
// re-insert elements
for(Element *pe = ElementCache.first(); pe != 0; pe = ElementCache.next())
foreach(Element *pe, ElementCache)
switch(pe->Type) {
case isComponent:
case isAnalogComponent:
@@ -1136,8 +1136,8 @@ bool Schematic::mirrorXComponents()
Components->setAutoDelete(false);
int x1, y1, x2, y2;
Q3PtrList<Element> ElementCache;
if(!copyComps2WiresPaints(x1, y1, x2, y2, &ElementCache))
QList<Element *> ElementCache;
if(!copyComps2WiresPaints(x1, y1, x2, y2, ElementCache))
return false;
Wires->setAutoDelete(true);
Components->setAutoDelete(true);
@@ -1152,7 +1152,7 @@ bool Schematic::mirrorXComponents()
Component *pc;
WireLabel *pl;
// re-insert elements
for(Element *pe = ElementCache.first(); pe != 0; pe = ElementCache.next())
foreach(Element *pe, ElementCache)
switch(pe->Type) {
case isComponent:
case isAnalogComponent:
@@ -1205,8 +1205,8 @@ bool Schematic::mirrorYComponents()
Components->setAutoDelete(false);
int x1, y1, x2, y2;
Q3PtrList<Element> ElementCache;
if(!copyComps2WiresPaints(x1, y1, x2, y2, &ElementCache))
QList<Element *> ElementCache;
if(!copyComps2WiresPaints(x1, y1, x2, y2, ElementCache))
return false;
Wires->setAutoDelete(true);
Components->setAutoDelete(true);
@@ -1220,7 +1220,7 @@ bool Schematic::mirrorYComponents()
Component *pc;
WireLabel *pl;
// re-insert elements
for(Element *pe = ElementCache.first(); pe != 0; pe = ElementCache.next())
foreach(Element *pe, ElementCache)
switch(pe->Type) {
case isComponent:
case isAnalogComponent:
View
@@ -229,21 +229,21 @@ protected slots:
int placeNodeLabel(WireLabel*);
Element* getWireLabel(Node*);
void insertNodeLabel(WireLabel*);
void copyLabels(int&, int&, int&, int&, Q3PtrList<Element>*);
void copyLabels(int&, int&, int&, int&, QList<Element *>);
Painting* selectedPainting(float, float);
void copyPaintings(int&, int&, int&, int&, Q3PtrList<Element>*);
void copyPaintings(int&, int&, int&, int&, QList<Element *>);
void getSchWidthAndHeight(int& w, int& h, int& xmin_, int& ymin_); // calculates schematic
void getSelAreaWidthAndHeight(int &wsel, int& hsel, int& xmin_sel_, int& ymin_sel_); // and selected area width and height in pixels
private:
void insertComponentNodes(Component*, bool);
int copyWires(int&, int&, int&, int&, Q3PtrList<Element>*);
int copyComponents(int&, int&, int&, int&, Q3PtrList<Element>*);
void copyComponents2(int&, int&, int&, int&, Q3PtrList<Element>*);
bool copyComps2WiresPaints(int&, int&, int&, int&, Q3PtrList<Element>*);
int copyElements(int&, int&, int&, int&, Q3PtrList<Element>*);
int copyWires(int&, int&, int&, int&, QList<Element *>);
int copyComponents(int&, int&, int&, int&, QList<Element *>);
void copyComponents2(int&, int&, int&, int&, QList<Element *>);
bool copyComps2WiresPaints(int&, int&, int&, int&, QList<Element *>);
int copyElements(int&, int&, int&, int&, QList<Element *>);
/* ********************************************************************
@@ -859,7 +859,7 @@ void Schematic::deleteWire(Wire *w)
// ---------------------------------------------------
int Schematic::copyWires(int& x1, int& y1, int& x2, int& y2,
Q3PtrList<Element> *ElementCache)
QList<Element *> ElementCache)
{
int count=0;
Node *pn;
@@ -874,14 +874,14 @@ int Schematic::copyWires(int& x1, int& y1, int& x2, int& y2,
if(pw->y2 > y2) y2 = pw->y2;
count++;
ElementCache->append(pw);
ElementCache.append(pw);
// rescue non-selected node labels
pn = pw->Port1;
if(pn->Label)
if(pn->Connections.count() < 2)
{
ElementCache->append(pn->Label);
ElementCache.append(pn->Label);
// Don't set pn->Label->pOwner=0 , so text position stays unchanged.
// But remember its wire.
@@ -892,7 +892,7 @@ int Schematic::copyWires(int& x1, int& y1, int& x2, int& y2,
if(pn->Label)
if(pn->Connections.count() < 2)
{
ElementCache->append(pn->Label);
ElementCache.append(pn->Label);
// Don't set pn->Label->pOwner=0 , so text position stays unchanged.
// But remember its wire.
@@ -1815,7 +1815,7 @@ int Schematic::copySelectedElements(Q3PtrList<Element> *p)
// ---------------------------------------------------
bool Schematic::copyComps2WiresPaints(int& x1, int& y1, int& x2, int& y2,
Q3PtrList<Element> *ElementCache)
QList<Element *> ElementCache)
{
x1=INT_MAX;
y1=INT_MAX;
@@ -1833,7 +1833,7 @@ bool Schematic::copyComps2WiresPaints(int& x1, int& y1, int& x2, int& y2,
// ---------------------------------------------------
// Used in "aligning()", "distributeHorizontal()", "distributeVertical()".
int Schematic::copyElements(int& x1, int& y1, int& x2, int& y2,
Q3PtrList<Element> *ElementCache)
QList<Element *> ElementCache)
{
int bx1, by1, bx2, by2;
Wires->setAutoDelete(false);
@@ -1859,7 +1859,7 @@ int Schematic::copyElements(int& x1, int& y1, int& x2, int& y2,
if(bx2 > x2) x2 = bx2;
if(by1 < y1) y1 = by1;
if(by2 > y2) y2 = by2;
ElementCache->append(pd);
ElementCache.append(pd);
number++;
}
// find upper most selected painting
@@ -1871,7 +1871,7 @@ int Schematic::copyElements(int& x1, int& y1, int& x2, int& y2,
if(bx2 > x2) x2 = bx2;
if(by1 < y1) y1 = by1;
if(by2 > y2) y2 = by2;
ElementCache->append(pp);
ElementCache.append(pp);
number++;
}
@@ -1996,8 +1996,8 @@ bool Schematic::aligning(int Mode)
{
int x1, y1, x2, y2;
int bx1, by1, bx2, by2, *bx=0, *by=0, *ax=0, *ay=0;
Q3PtrList<Element> ElementCache;
int count = copyElements(x1, y1, x2, y2, &ElementCache);
QList<Element *> ElementCache;
int count = copyElements(x1, y1, x2, y2, ElementCache);
if(count < 1) return false;
@@ -2049,7 +2049,7 @@ bool Schematic::aligning(int Mode)
Component *pc;
// re-insert elements
// Go backwards in order to insert node labels before its component.
for(Element *pe = ElementCache.last(); pe != 0; pe = ElementCache.prev())
foreach(Element *pe, ElementCache)
switch(pe->Type)
{
case isComponent:
@@ -2125,8 +2125,8 @@ bool Schematic::distributeHorizontal()
{
int x1, y1, x2, y2;
int bx1, by1, bx2, by2;
Q3PtrList<Element> ElementCache;
int count = copyElements(x1, y1, x2, y2, &ElementCache);
QList<Element *> ElementCache;
int count = copyElements(x1, y1, x2, y2, ElementCache);
if(count < 1) return false;
Element *pe;
@@ -2139,33 +2139,35 @@ bool Schematic::distributeHorizontal()
}*/
// using bubble sort to get elements x ordered
QListIterator<Element *> elementCacheIter(ElementCache);
if(count > 1)
for(int i = count-1; i>0; i--)
{
pe = ElementCache.first();
for(int j=0; j<i; j++)
{
pe->getCenter(bx1, by1);
pe=ElementCache.next();
//pe=ElementCache.next();
pe=elementCacheIter.next();
pe->getCenter(bx2, by2);
if(bx1 > bx2) // change two elements ?
{
ElementCache.replace(j+1, ElementCache.prev());
ElementCache.replace(j+1, elementCacheIter.previous());
ElementCache.replace(j, pe);
pe = ElementCache.next();
pe = elementCacheIter.next();
}
}
}
ElementCache.getLast()->getCenter(x2, y2);
ElementCache.getFirst()->getCenter(x1, y1);
ElementCache.last()->getCenter(x2, y2);
ElementCache.first()->getCenter(x1, y1);
Wire *pw;
int x = x2;
int dx=0;
if(count > 1) dx = (x2-x1)/(count-1);
// re-insert elements and put them at right position
// Go backwards in order to insert node labels before its component.
for(pe = ElementCache.last(); pe != 0; pe = ElementCache.prev())
for(pe = ElementCache.last(); pe != 0; pe = elementCacheIter.previous())
{
switch(pe->Type)
{
@@ -2234,8 +2236,9 @@ bool Schematic::distributeVertical()
{
int x1, y1, x2, y2;
int bx1, by1, bx2, by2;
Q3PtrList<Element> ElementCache;
int count = copyElements(x1, y1, x2, y2, &ElementCache);
QList<Element *> ElementCache;
QListIterator<Element *> elementCacheIter(ElementCache);
int count = copyElements(x1, y1, x2, y2, ElementCache);
if(count < 1) return false;
// using bubble sort to get elements x ordered
@@ -2247,26 +2250,26 @@ bool Schematic::distributeVertical()
for(int j=0; j<i; j++)
{
pe->getCenter(bx1, by1);
pe=ElementCache.next();
pe=elementCacheIter.next();
pe->getCenter(bx2, by2);
if(by1 > by2) // change two elements ?
{
ElementCache.replace(j+1, ElementCache.prev());
ElementCache.replace(j+1, elementCacheIter.previous());
ElementCache.replace(j, pe);
pe = ElementCache.next();
pe = elementCacheIter.next();
}
}
}
ElementCache.getLast()->getCenter(x2, y2);
ElementCache.getFirst()->getCenter(x1, y1);
ElementCache.last()->getCenter(x2, y2);
ElementCache.first()->getCenter(x1, y1);
Wire *pw;
int y = y2;
int dy=0;
if(count > 1) dy = (y2-y1)/(count-1);
// re-insert elements and put them at right position
// Go backwards in order to insert node labels before its component.
for(pe = ElementCache.last(); pe != 0; pe = ElementCache.prev())
for(pe = ElementCache.last(); pe != 0; pe = elementCacheIter.previous())
{
switch(pe->Type)
{
@@ -2757,7 +2760,7 @@ void Schematic::deleteComp(Component *c)
// ---------------------------------------------------
int Schematic::copyComponents(int& x1, int& y1, int& x2, int& y2,
Q3PtrList<Element> *ElementCache)
QList<Element *> ElementCache)
{
Component *pc;
int bx1, by1, bx2, by2, count=0;
@@ -2773,14 +2776,14 @@ int Schematic::copyComponents(int& x1, int& y1, int& x2, int& y2,
if(by2 > y2) y2 = by2;
count++;
ElementCache->append(pc);
ElementCache.append(pc);
// rescue non-selected node labels
foreach(Port *pp, pc->Ports)
if(pp->Connection->Label)
if(pp->Connection->Connections.count() < 2)
{
ElementCache->append(pp->Connection->Label);
ElementCache.append(pp->Connection->Label);
// Don't set pp->Connection->Label->pOwner=0,
// so text position stays unchanged, but
@@ -2801,7 +2804,7 @@ int Schematic::copyComponents(int& x1, int& y1, int& x2, int& y2,
// ---------------------------------------------------
void Schematic::copyComponents2(int& x1, int& y1, int& x2, int& y2,
Q3PtrList<Element> *ElementCache)
QList<Element *> ElementCache)
{
Component *pc;
// find bounds of all selected components
@@ -2815,14 +2818,14 @@ void Schematic::copyComponents2(int& x1, int& y1, int& x2, int& y2,
if(pc->cy < y1) y1 = pc->cy;
if(pc->cy > y2) y2 = pc->cy;
ElementCache->append(pc);
ElementCache.append(pc);
// rescue non-selected node labels
foreach(Port *pp, pc->Ports)
if(pp->Connection->Label)
if(pp->Connection->Connections.count() < 2)
{
ElementCache->append(pp->Connection->Label);
ElementCache.append(pp->Connection->Label);
pp->Connection->Label = 0;
// Don't set pp->Connection->Label->pOwner=0,
// so text position stays unchanged.
@@ -3022,7 +3025,7 @@ void Schematic::insertNodeLabel(WireLabel *pl)
// ---------------------------------------------------
void Schematic::copyLabels(int& x1, int& y1, int& x2, int& y2,
Q3PtrList<Element> *ElementCache)
QList<Element *> ElementCache)
{
WireLabel *pl;
// find bounds of all selected wires
@@ -3035,7 +3038,7 @@ void Schematic::copyLabels(int& x1, int& y1, int& x2, int& y2,
if(pl->y1-pl->y2 < y1) y1 = pl->y1-pl->y2;
if(pl->x1+pl->x2 > x2) x2 = pl->x1+pl->x2;
if(pl->y1 > y2) y2 = pl->y1;
ElementCache->append(pl);
ElementCache.append(pl);
}
}
@@ -3048,7 +3051,7 @@ void Schematic::copyLabels(int& x1, int& y1, int& x2, int& y2,
if(pl->y1-pl->y2 < y1) y1 = pl->y1-pl->y2;
if(pl->x1+pl->x2 > x2) x2 = pl->x1+pl->x2;
if(pl->y1 > y2) y2 = pl->y1;
ElementCache->append(pl);
ElementCache.append(pl);
pl->pOwner->Label = 0; // erase connection
pl->pOwner = 0;
}
@@ -3075,7 +3078,7 @@ Painting* Schematic::selectedPainting(float fX, float fY)
// ---------------------------------------------------
void Schematic::copyPaintings(int& x1, int& y1, int& x2, int& y2,
Q3PtrList<Element> *ElementCache)
QList<Element *> ElementCache)
{
Painting *pp;
int bx1, by1, bx2, by2;
@@ -3089,7 +3092,7 @@ void Schematic::copyPaintings(int& x1, int& y1, int& x2, int& y2,
if(by1 < y1) y1 = by1;
if(by2 > y2) y2 = by2;
ElementCache->append(pp);
ElementCache.append(pp);
Paintings->take();
pp = Paintings->current();
}

0 comments on commit f8bc623

Please sign in to comment.