X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmainapp%2Fgraphicview.cpp;h=77c74042ec3198c1e1f34f68f00662f54c53cbad;hb=f34fe4370628985ef1a4a4527cfa85165624e27c;hp=90aa44eca6163c2fe568b91527fe4b94a6281760;hpb=c40d19f69539b4afaa2c15e7b314eb7b8c88e943;p=architektonas diff --git a/src/mainapp/graphicview.cpp b/src/mainapp/graphicview.cpp index 90aa44e..77c7404 100644 --- a/src/mainapp/graphicview.cpp +++ b/src/mainapp/graphicview.cpp @@ -3,7 +3,9 @@ // Part of the Architektonas Project // Originally part of QCad Community Edition by Andrew Mustun // Extensively rewritten and refactored by James L. Hammons -// (C) 2010 Underground Software +// Portions copyright (C) 2001-2003 RibbonSoft +// Copyright (C) 2010 Underground Software +// See the README and GPLv2 files for licensing and warranty information // // JLH = James L. Hammons // @@ -19,7 +21,7 @@ #include "rs_eventhandler.h" #include "rs_grid.h" #include "rs_linetypepattern.h" -#include "paintintf.h" +#include "paintinterface.h" #include "settings.h" #include "rs_text.h" #include "rs_units.h" @@ -27,8 +29,7 @@ /** * Constructor. */ -GraphicView::GraphicView(): background(), foreground(), previewMode(false), - previewOffset(Vector(0, 0)), snapperDraw(false) +GraphicView::GraphicView(): background(), foreground() { drawingMode = RS2::ModeFull; printing = false; @@ -46,10 +47,8 @@ GraphicView::GraphicView(): background(), foreground(), previewMode(false), grid = new RS_Grid(this); updateEnabled = 0; zoomFrozen = false; - //gridVisible = true; draftMode = false; painter = NULL; - //drawRecursion = 0; borderLeft = 0; borderTop = 0; @@ -78,8 +77,6 @@ GraphicView::GraphicView(): background(), foreground(), previewMode(false), simulationSmooth = false; simulationRapid = false; simulationRunning = false; - - //currentInsert = NULL; } /** @@ -87,10 +84,6 @@ GraphicView::GraphicView(): background(), foreground(), previewMode(false), */ GraphicView::~GraphicView() { - //delete eventHandler; - if (painter != NULL) - delete painter; - delete grid; } @@ -109,10 +102,10 @@ void GraphicView::cleanUp() */ Drawing * GraphicView::getGraphic() { - if (container != NULL && container->rtti() == RS2::EntityGraphic) - return (Drawing*)container; - else - return NULL; + if (container && container->rtti() == RS2::EntityGraphic) + return (Drawing *)container; + + return NULL; } /** @@ -160,15 +153,6 @@ void GraphicView::adjustZoomControls() { } -/** - * Sets an external painter device. - */ -//void GraphicView::setPainter(RS_Painter * p) -void GraphicView::setPainter(PaintInterface * p) -{ - painter = p; -} - /** * Sets the background color. Note that applying the background * color for the widget is up to the implementing class. @@ -352,7 +336,6 @@ bool GraphicView::isZoomFrozen() void GraphicView::setContainer(RS_EntityContainer * container) { this->container = container; - //adjustOffsetControls(); } /** @@ -378,12 +361,12 @@ void GraphicView::setFactorY(double f) */ bool GraphicView::isGridOn() { - if (container != NULL) + if (container) { - Drawing * g = container->getGraphic(); + Drawing * d = container->getGraphic(); - if (g != NULL) - return g->isGridOn(); + if (d) + return d->isGridOn(); } return true; @@ -449,7 +432,7 @@ void GraphicView::updateView() /** * @return Current action or NULL. */ -RS_ActionInterface * GraphicView::getDefaultAction() +ActionInterface * GraphicView::getDefaultAction() { if (eventHandler != NULL) return eventHandler->getDefaultAction(); @@ -460,18 +443,18 @@ RS_ActionInterface * GraphicView::getDefaultAction() /** * Sets the default action of the event handler. */ -void GraphicView::setDefaultAction(RS_ActionInterface * action) +void GraphicView::setDefaultAction(ActionInterface * action) { - if (eventHandler != NULL) + if (eventHandler) eventHandler->setDefaultAction(action); } /** * @return Current action or NULL. */ -RS_ActionInterface * GraphicView::getCurrentAction() +ActionInterface * GraphicView::getCurrentAction() { - if (eventHandler != NULL) + if (eventHandler) return eventHandler->getCurrentAction(); else return NULL; @@ -480,11 +463,11 @@ RS_ActionInterface * GraphicView::getCurrentAction() /** * Sets the current action of the event handler. */ -void GraphicView::setCurrentAction(RS_ActionInterface * action) +void GraphicView::setCurrentAction(ActionInterface * action) { RS_DEBUG->print("GraphicView::setCurrentAction"); - if (eventHandler != NULL) + if (eventHandler) eventHandler->setCurrentAction(action); RS_DEBUG->print("GraphicView::setCurrentAction: OK"); @@ -553,7 +536,6 @@ void GraphicView::mouseReleaseEvent(QMouseEvent * e) if (e->button() != Qt::RightButton || eventHandler->hasAction()) { eventHandler->mouseReleaseEvent(e); - //e->accept(); } else { @@ -689,14 +671,8 @@ void GraphicView::zoomIn(double f, const Vector & center) if (c.valid == false) c = toGraph(Vector(getWidth() / 2, getHeight() / 2)); - zoomWindow( - toGraph(Vector(0, 0)).scale(c, Vector(1.0 / f, 1.0 / f)), + zoomWindow(toGraph(Vector(0, 0)).scale(c, Vector(1.0 / f, 1.0 / f)), toGraph(Vector(getWidth(), getHeight())).scale(c, Vector(1.0 / f, 1.0 / f))); - - //adjustOffsetControls(); - //adjustZoomControls(); - //updateGrid(); - //redraw(); } /** @@ -1077,8 +1053,6 @@ void GraphicView::zoomWindow(Vector v1, Vector v2, bool keepAspectRatio) */ void GraphicView::zoomPan(int dx, int dy) { - //offsetX+=(int)toGuiDX(v1.x); - //offsetY+=(int)toGuiDY(v1.y); if (simulationRunning) return; @@ -1087,7 +1061,6 @@ void GraphicView::zoomPan(int dx, int dy) disableUpdate(); adjustOffsetControls(); - //adjustZoomControls(); updateGrid(); enableUpdate(); redraw(); @@ -1264,69 +1237,69 @@ void GraphicView::setPenForEntity(RS_Entity * e) if (drawingMode == RS2::ModePreview /*|| draftMode==true*/) return; - // set color of entity - if (painter && !painter->isPreviewMode()) - { - // Getting pen from entity (or layer) - RS_Pen pen = e->getPen(true); - - int w = pen.getWidth(); + if (!painter || painter->isPreviewMode()) + return; - if (w < 0) - w = 0; + // set color of entity + // Getting pen from entity (or layer) + RS_Pen pen = e->getPen(true); - // scale pen width: - if (!draftMode) - { - double uf = 1.0; // unit factor - double wf = 1.0; // width factor - Drawing * graphic = container->getGraphic(); + int w = pen.getWidth(); - if (graphic != NULL) - { - uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit()); + if (w < 0) + w = 0; - if ((isPrinting() || isPrintPreview()) && graphic->getPaperScale() > 1.0e-6) - wf = 1.0 / graphic->getPaperScale(); - } + // scale pen width: + if (!draftMode) + { + double uf = 1.0; // unit factor + double wf = 1.0; // width factor + Drawing * graphic = container->getGraphic(); - pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf)); - } - else + if (graphic) { - //pen.setWidth(RS2::Width00); - pen.setScreenWidth(0); - } + uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit()); - // prevent drawing with 1-width which is slow: - if (RS_Math::round(pen.getScreenWidth()) == 1) - pen.setScreenWidth(0.0); + if ((isPrinting() || isPrintPreview()) && graphic->getPaperScale() > 1.0e-6) + wf = 1.0 / graphic->getPaperScale(); + } - // prevent background color on background drawing: - if (pen.getColor().stripFlags() == background.stripFlags()) - pen.setColor(foreground); + pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf)); + } + else + { + //pen.setWidth(RS2::Width00); + pen.setScreenWidth(0); + } - // this entity is selected: - if (e->isSelected()) - { - pen.setLineType(RS2::DotLine); - //pen.setColor(RS_Color(0xa5,0x47,0x47)); - pen.setColor(selectedColor); - } + // prevent drawing with 1-width which is slow: + if (RS_Math::round(pen.getScreenWidth()) == 1) + pen.setScreenWidth(0.0); - // this entity is highlighted: - if (e->isHighlighted()) - { - //pen.setColor(RS_Color(0x73, 0x93, 0x73)); - pen.setColor(highlightedColor); - } + // prevent background color on background drawing: + if (pen.getColor().stripFlags() == background.stripFlags()) + pen.setColor(foreground); - // deleting not drawing: - if (getDeleteMode()) - pen.setColor(background); + // this entity is selected: + if (e->isSelected()) + { + pen.setLineType(RS2::DotLine); + //pen.setColor(RS_Color(0xa5,0x47,0x47)); + pen.setColor(selectedColor); + } - painter->setPen(pen); + // this entity is highlighted: + if (e->isHighlighted()) + { + //pen.setColor(RS_Color(0x73, 0x93, 0x73)); + pen.setColor(highlightedColor); } + + // deleting not drawing: + if (getDeleteMode()) + pen.setColor(background); + + painter->setPen(pen); } /** @@ -1438,23 +1411,11 @@ void GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db) //RS_DEBUG->print("GraphicView::drawEntity() end"); } -/** - * Deletes an entity with the background color. - * Might be recusively called e.g. for polylines. - */ -void GraphicView::deleteEntity(RS_Entity * e) -{ -#warning "!!! This is part of obsolete rendering !!!" - setDeleteMode(true); - drawEntity(e); - setDeleteMode(false); -} - /** * Draws an entity. * The painter must be initialized and all the attributes (pen) must be set. */ -void GraphicView::drawEntityPlain(RS_Entity * e, double patternOffset) +void GraphicView::drawEntityPlain(RS_Entity * e, double patternOffset/*= 0.0*/) { //Problems can still occur here when passing in a deleted object... It won't be //NULL, but it will cause a segfault here... @@ -1479,8 +1440,6 @@ void GraphicView::simulateIt() simulationRunning = true; simulationLast = Vector(0.0, 0.0); -//jlh destroyPainter(); - painter->erase(); // drawing paper border: @@ -1495,18 +1454,10 @@ void GraphicView::simulateIt() if (!isPrintPreview()) drawGrid(); - //if (draftMode) { - //painter->setPen(RS_Pen(foreground, - // RS2::Width00, RS2::SolidLine)); - //} - // drawing entities: RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine); simulateEntity(container, pen); - //RS_DEBUG->timestamp(); - //RS_DEBUG->print(" draw zero.."); - // drawing zero points: if (!isPrintPreview()) { @@ -1514,14 +1465,6 @@ void GraphicView::simulateIt() drawRelativeZero(); } - //RS_DEBUG->timestamp(); - //RS_DEBUG->print(" draw grid.."); - - //RS_DEBUG->timestamp(); - //RS_DEBUG->print("GraphicView::drawIt() end"); - //if (painterCreated==true) { -//jlh destroyPainter(); - //} simulationRunning = false; } @@ -1532,15 +1475,15 @@ void GraphicView::simulateIt() */ void GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen) { - if (painter == NULL || e == NULL) + if (!painter || !e) return; if (e->isContainer()) { RS_EntityContainer * ec = (RS_EntityContainer *)e; - for(RS_Entity* en=ec->firstEntity(RS2::ResolveNone); - en!=NULL; en = ec->nextEntity(RS2::ResolveNone)) + for(RS_Entity * en=ec->firstEntity(RS2::ResolveNone); + en!=NULL; en=ec->nextEntity(RS2::ResolveNone)) { if (en->isVisible() && en->isUndone() == false) { @@ -1551,9 +1494,7 @@ void GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen) if (sp.distanceTo(simulationLast) > 1.0e-4) { -//jlh createDirectPainter(); RS_Pen rpen(RS_Color(0, 0, 255), RS2::Width00, RS2::SolidLine); - //painter->setPen(pen); RS_Line rapidLine(NULL, RS_LineData(simulationLast, sp)); simulateEntity(&rapidLine, rpen); } @@ -1611,8 +1552,6 @@ void GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen) } else { -//jlh createDirectPainter(); - //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine); painter->setPen(pen); drawEntityPlain(e); } @@ -1721,15 +1660,11 @@ void GraphicView::drawLineSmooth(const Vector & p1, const Vector & p2, const RS_ double lx = p1.x; double ly = p1.y; - //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine); do { if (lx >= 0.0 && lx <= (double)getWidth() && ly >= 0.0 && ly <= (double)getHeight()) { - //if (painter==NULL) { -//jlh createDirectPainter(); - //} painter->setPen(pen); painter->drawGridPoint(Vector(lx, ly)); @@ -1747,13 +1682,8 @@ void GraphicView::drawLineSmooth(const Vector & p1, const Vector & p2, const RS_ void GraphicView::drawArcSmooth(const Vector & center, double radius, double a1, double a2, bool rev, const RS_Pen & pen) { - //int icx = graphic->realToScreenX(cx); - //int icy = graphic->realToScreenY(cy); - //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine); - if (radius <= 1.4) { -//jlh createDirectPainter(); painter->setPen(pen); painter->drawGridPoint(center); } @@ -1786,42 +1716,27 @@ void GraphicView::drawArcSmooth(const Vector & center, double radius, double a1, if (a1 > a2cp - 0.01) a2cp += 2 * M_PI; - //if (painter==NULL) { - //painter->setPen(pen); - //createDirectPainter(); - //} - //painter->moveTo(ix1, iy1); - for(a=a1+aStep; a<=a2cp; a+=aStep) { k2x = RS_Math::round(center.x+cos(a)*radius); k2y = RS_Math::round(center.y-sin(a)*radius); - //if(graphic->isPointOnScreen(k2x, k2y) || - // graphic->isPointOnScreen(k1x, k1y) ) { -//jlh createDirectPainter(); painter->setPen(pen); + if ((k2x >= 0 && k2x <= painter->getWidth() && k2y >= 0 && k2y <= painter->getHeight()) || (k1x >= 0 && k1x <= painter->getWidth() && k1y >= 0 && k1y <= painter->getHeight())) { - //painter->lineTo(k2x, k2y); painter->drawLine(Vector(k1x, k1y), Vector(k2x, k2y)); simulationDelay(); - //graphic->simulationDelay(); } - //createDirectPainter(); - //painter->setPen(pen); - //painter->moveTo(k2x, k2y); k1x = k2x; k1y = k2y; } -//jlh createDirectPainter(); painter->setPen(pen); painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2)); - //painter->lineTo(ix2, iy2); } else { @@ -1830,36 +1745,26 @@ void GraphicView::drawArcSmooth(const Vector & center, double radius, double a1, if (a1 < a2cp + 0.01) a2cp -= 2 * M_PI; - //createDirectPainter(); - //painter->setPen(pen); - //painter->moveTo(ix1, iy1); for(a=a1-aStep; a>=a2cp; a-=aStep) { k2x = RS_Math::round(center.x + cos(a) * radius); k2y = RS_Math::round(center.y - sin(a) * radius); - //if(graphic->isPointOnScreen(k2x, k2y) || - // graphic->isPointOnScreen(k1x, k1y) ) { -//jlh createDirectPainter(); painter->setPen(pen); + if ((k2x >=0 && k2x <= painter->getWidth() && k2y >= 0 && k2y <= painter->getHeight()) || (k1x >= 0 && k1x <= painter->getWidth() && k1y >= 0 && k1y <= painter->getHeight())) { - //painter->lineTo(k2x, k2y); painter->drawLine(Vector(k1x, k1y), Vector(k2x, k2y)); simulationDelay(); } - //createDirectPainter(); - //painter->setPen(pen); - //painter->moveTo(k2x, k2y); + k1x = k2x; k1y = k2y; } -//jlh createDirectPainter(); painter->setPen(pen); - //painter->lineTo(ix2, iy2); painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2)); } } @@ -1968,8 +1873,6 @@ void GraphicView::drawAbsoluteZero() int zr = 20; -// RS_Pen pen(metaGridColor, RS2::Width00, RS2::SolidLine); -// painter->setPen(pen); // RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine); //Using Qt::red doesn't seem to work here... //It's because Qt colors and RS_Color are not 100% compatible... @@ -1992,7 +1895,6 @@ void GraphicView::drawAbsoluteZero() */ void GraphicView::drawRelativeZero() { -// PROBLEM: relativeZero IS NOT VALID!!! if (!relativeZero.valid || !painter) #if 1 return; @@ -2008,23 +1910,23 @@ void GraphicView::drawRelativeZero() } #endif -// RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine); -// p.setScreenWidth(0); //Using Qt::red doesn't seem to work here... RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine); painter->setPen(p); - painter->setXORMode(); +//This doesn't work--this is NOT a QPainter! +// painter->setBrush(Qt::NoBrush); +// painter->setBackgroundMode(Qt::TransparentMode); // will that do it??? + painter->disableBrush(); +// painter->setXORMode(); int zr = 5; painter->drawLine(Vector(toGuiX(relativeZero.x) - zr, toGuiY(relativeZero.y)), Vector(toGuiX(relativeZero.x) + zr, toGuiY(relativeZero.y))); - painter->drawLine(Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) - zr), Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) + zr)); - painter->drawCircle(toGui(relativeZero), zr); - painter->setNormalMode(); +// painter->setNormalMode(); } /** @@ -2113,7 +2015,7 @@ void GraphicView::drawGrid() */ void GraphicView::drawMetaGrid() { - if (!grid || isGridOn() == false /*|| grid->getMetaSpacing()<0.0*/) + if (!grid || isGridOn() == false) return; if (!painter) @@ -2174,8 +2076,14 @@ void GraphicView::setDefaultSnapMode(RS2::SnapMode sm) { defaultSnapMode = sm; - if (eventHandler != NULL) + if (eventHandler) eventHandler->setSnapMode(sm); + + //OK, the above sets the snap mode in the snapper that's derived from + //the RS_ActionInterface and RS_Snapper. So the following should fix + //us up, hm notwithstanding. [and it does. :-)] + //hm. + snapper.setSnapMode(sm); } /** @@ -2202,7 +2110,7 @@ Vector GraphicView::toGui(Vector v) * @param visible Pointer to a boolean which will contain true * after the call if the coordinate is within the visible range. */ -double GraphicView::toGuiX(double x, bool * visible) +double GraphicView::toGuiX(double x, bool * visible/*= NULL*/) { if (visible != NULL) { @@ -2332,15 +2240,7 @@ void GraphicView::setRelativeZero(const Vector & pos) */ void GraphicView::moveRelativeZero(const Vector & pos) { -//this is crap. we're taking this shit out. -//#warning "!!! GraphicView::moveRelativeZero(): Bad render path !!!" -// if (!painter) -// return; - - //painter->setXORMode(); -// drawRelativeZero(); setRelativeZero(pos); -// drawRelativeZero(); } RS_EventHandler * GraphicView::getEventHandler() @@ -2429,32 +2329,3 @@ bool GraphicView::getSimulationRapid() { return simulationRapid; } - -// These functions are here because of the focacta way that this -// program set up its rendering... -void GraphicView::SetPreviewMode(bool mode/*= true*/) -{ - previewMode = mode; -} - -void GraphicView::SetPreviewEntity(RS_Preview * p) -{ - previewEntity = p; -} - -void GraphicView::SetPreviewOffset(Vector o) -{ - previewOffset = o; -} - -void GraphicView::SetSnapperDraw(bool mode) -{ - snapperDraw = mode; -} - -void GraphicView::SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs) -{ - snapSpot1 = snapSpot; - snapCoord1 = snapCoord; - showCrosshairs1 = showCrosshairs; -}