// 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 <jlhamm@acm.org>
//
#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"
/**
* Constructor.
*/
-GraphicView::GraphicView(): background(), foreground(), previewMode(false),
- previewOffset(Vector(0, 0)), snapperDraw(false)
+GraphicView::GraphicView(): background(), foreground()
{
drawingMode = RS2::ModeFull;
printing = false;
grid = new RS_Grid(this);
updateEnabled = 0;
zoomFrozen = false;
- //gridVisible = true;
draftMode = false;
painter = NULL;
- //drawRecursion = 0;
borderLeft = 0;
borderTop = 0;
simulationSmooth = false;
simulationRapid = false;
simulationRunning = false;
-
- //currentInsert = NULL;
}
/**
*/
GraphicView::~GraphicView()
{
- //delete eventHandler;
- if (painter != NULL)
- delete painter;
-
delete grid;
}
*/
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;
}
/**
{
}
-/**
- * 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.
void GraphicView::setContainer(RS_EntityContainer * container)
{
this->container = container;
- //adjustOffsetControls();
}
/**
*/
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;
/**
* @return Current action or NULL.
*/
-RS_ActionInterface * GraphicView::getDefaultAction()
+ActionInterface * GraphicView::getDefaultAction()
{
if (eventHandler != NULL)
return eventHandler->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;
/**
* 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");
if (e->button() != Qt::RightButton || eventHandler->hasAction())
{
eventHandler->mouseReleaseEvent(e);
- //e->accept();
}
else
{
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();
}
/**
*/
void GraphicView::zoomPan(int dx, int dy)
{
- //offsetX+=(int)toGuiDX(v1.x);
- //offsetY+=(int)toGuiDY(v1.y);
if (simulationRunning)
return;
disableUpdate();
adjustOffsetControls();
- //adjustZoomControls();
updateGrid();
enableUpdate();
redraw();
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);
}
/**
//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...
simulationRunning = true;
simulationLast = Vector(0.0, 0.0);
-//jlh destroyPainter();
-
painter->erase();
// drawing paper border:
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())
{
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;
}
*/
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)
{
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);
}
}
else
{
-//jlh createDirectPainter();
- //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
painter->setPen(pen);
drawEntityPlain(e);
}
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));
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);
}
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
{
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));
}
}
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...
*/
void GraphicView::drawRelativeZero()
{
-// PROBLEM: relativeZero IS NOT VALID!!!
if (!relativeZero.valid || !painter)
#if 1
return;
}
#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();
}
/**
*/
void GraphicView::drawMetaGrid()
{
- if (!grid || isGridOn() == false /*|| grid->getMetaSpacing()<0.0*/)
+ if (!grid || isGridOn() == false)
return;
if (!painter)
//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.
+ //us up, hm notwithstanding. [and it does. :-)]
//hm.
snapper.setSnapMode(sm);
}
* @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)
{
*/
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()
{
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;
-}