]> Shamusworld >> Repos - architektonas/blobdiff - src/mainapp/graphicview.cpp
In the middle of removing Snapper class/fixing snapper rendering...
[architektonas] / src / mainapp / graphicview.cpp
index a79ce63273ebcee5118871a5e63ee43036e8885a..5b633b2b3a56af1859772b16f4941bf5ac659f10 100644 (file)
@@ -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 <jlhamm@acm.org>
 //
 
 #include "graphicview.h"
 
-#include "rs_dialogfactory.h"
+#include "dialogfactory.h"
 #include "drawing.h"
-#include "rs_eventhandler.h"
-#include "rs_grid.h"
-#include "rs_linetypepattern.h"
-#include "paintintf.h"
+#include "eventhandler.h"
+#include "grid.h"
+#include "linetypepattern.h"
+#include "paintinterface.h"
 #include "settings.h"
-#include "rs_text.h"
-#include "rs_units.h"
+#include "text.h"
+#include "units.h"
 
 /**
  * Constructor.
  */
-GraphicView::GraphicView(): background(), foreground(), previewMode(false),
-       previewOffset(Vector(0, 0))//, snapperDraw(false)
+GraphicView::GraphicView(): background(), foreground()
 {
        drawingMode = RS2::ModeFull;
        printing = false;
@@ -40,16 +41,14 @@ GraphicView::GraphicView(): background(), foreground(), previewMode(false),
        previousOffsetX = 0;
        previousOffsetY = 0;
        container = NULL;
-       eventHandler = new RS_EventHandler(this);
+       eventHandler = new EventHandler(this);
        gridColor = Qt::gray;
-       metaGridColor = RS_Color(64, 64, 64);
-       grid = new RS_Grid(this);
+       metaGridColor = Color(64, 64, 64);
+       grid = new Grid(this);
        updateEnabled = 0;
        zoomFrozen = false;
-       //gridVisible = true;
        draftMode = false;
        painter = NULL;
-       //drawRecursion = 0;
 
        borderLeft = 0;
        borderTop = 0;
@@ -79,7 +78,23 @@ GraphicView::GraphicView(): background(), foreground(), previewMode(false),
        simulationRapid = false;
        simulationRunning = false;
 
-       //currentInsert = NULL;
+       // Snapper settings...
+       snapEntity = NULL;
+       snapSpot = Vector(false);
+       snapCoord = Vector(false);
+       snapperVisible = false;
+       snapDistance = 1.0;
+
+       settings.beginGroup("Snap");
+       snapRange = settings.value("Range", 20).toInt();
+       settings.endGroup();
+       settings.beginGroup("Appearance");
+       showCrosshairs = settings.value("ShowCrosshairs", true).toBool();
+       settings.endGroup();
+
+       // Sanity check for snapRange
+       if (snapRange < 2)
+               snapRange = 20;
 }
 
 /**
@@ -87,10 +102,6 @@ GraphicView::GraphicView(): background(), foreground(), previewMode(false),
  */
 GraphicView::~GraphicView()
 {
-       //delete eventHandler;
-       if (painter)
-               delete painter;
-
        delete grid;
 }
 
@@ -160,38 +171,27 @@ void GraphicView::adjustZoomControls()
 {
 }
 
-#if 0
-/**
- * Sets an external painter device.
- */
-//void GraphicView::setPainter(RS_Painter * p)
-void GraphicView::setPainter(PaintInterface * p)
-{
-       painter = p;
-}
-#endif
-
 /**
  * Sets the background color. Note that applying the background
  * color for the widget is up to the implementing class.
  */
-void GraphicView::setBackground(const RS_Color & bg)
+void GraphicView::setBackground(const Color & bg)
 {
        background = bg;
 
        // bright background:
        if (bg.red() + bg.green() + bg.blue() > 380)
 //             foreground = Qt::black;
-               foreground = RS_Color(0, 0, 0);
+               foreground = Color(0, 0, 0);
        else
 //             foreground = Qt::white;
-               foreground = RS_Color(255, 255, 255);
+               foreground = Color(255, 255, 255);
 }
 
 /**
  * @return Current background color.
  */
-RS_Color GraphicView::getBackground()
+Color GraphicView::getBackground()
 {
        return background;
 }
@@ -199,7 +199,7 @@ RS_Color GraphicView::getBackground()
 /**
  * @return Current foreground color.
  */
-RS_Color GraphicView::getForeground()
+Color GraphicView::getForeground()
 {
        return foreground;
 }
@@ -207,7 +207,7 @@ RS_Color GraphicView::getForeground()
 /**
  * Sets the grid color.
  */
-void GraphicView::setGridColor(const RS_Color & c)
+void GraphicView::setGridColor(const Color & c)
 {
        gridColor = c;
 }
@@ -215,7 +215,7 @@ void GraphicView::setGridColor(const RS_Color & c)
 /**
  * Sets the meta grid color.
  */
-void GraphicView::setMetaGridColor(const RS_Color & c)
+void GraphicView::setMetaGridColor(const Color & c)
 {
        metaGridColor = c;
 }
@@ -223,7 +223,7 @@ void GraphicView::setMetaGridColor(const RS_Color & c)
 /**
  * Sets the selection color.
  */
-void GraphicView::setSelectedColor(const RS_Color & c)
+void GraphicView::setSelectedColor(const Color & c)
 {
        selectedColor = c;
 }
@@ -231,7 +231,7 @@ void GraphicView::setSelectedColor(const RS_Color & c)
 /**
  * Sets the highlight color.
  */
-void GraphicView::setHighlightedColor(const RS_Color & c)
+void GraphicView::setHighlightedColor(const Color & c)
 {
        highlightedColor = c;
 }
@@ -244,7 +244,7 @@ void GraphicView::setMouseCursor(RS2::CursorType /*c*/)
 {
 }
 
-RS_EntityContainer * GraphicView::getContainer()
+EntityContainer * GraphicView::getContainer()
 {
        return container;
 }
@@ -351,10 +351,9 @@ bool GraphicView::isZoomFrozen()
  * Sets the pointer to the graphic which contains the entities
  * which are visualized by this widget.
  */
-void GraphicView::setContainer(RS_EntityContainer * container)
+void GraphicView::setContainer(EntityContainer * container)
 {
        this->container = container;
-       //adjustOffsetControls();
 }
 
 /**
@@ -380,12 +379,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;
@@ -451,7 +450,7 @@ void GraphicView::updateView()
 /**
  * @return Current action or NULL.
  */
-RS_ActionInterface * GraphicView::getDefaultAction()
+ActionInterface * GraphicView::getDefaultAction()
 {
        if (eventHandler != NULL)
                return eventHandler->getDefaultAction();
@@ -462,18 +461,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;
@@ -482,14 +481,14 @@ 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");
+       DEBUG->print("GraphicView::setCurrentAction");
 
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->setCurrentAction(action);
 
-       RS_DEBUG->print("GraphicView::setCurrentAction: OK");
+       DEBUG->print("GraphicView::setCurrentAction: OK");
 }
 
 /**
@@ -518,8 +517,8 @@ void GraphicView::back()
 {
        if (eventHandler && eventHandler->hasAction())
                eventHandler->back();
-       else if (RS_DIALOGFACTORY)
-               RS_DIALOGFACTORY->requestPreviousMenu();
+       else if (DIALOGFACTORY)
+               DIALOGFACTORY->requestPreviousMenu();
 }
 
 /**
@@ -547,7 +546,7 @@ void GraphicView::mousePressEvent(QMouseEvent * e)
  */
 void GraphicView::mouseReleaseEvent(QMouseEvent * e)
 {
-       RS_DEBUG->print("GraphicView::mouseReleaseEvent");
+       DEBUG->print("GraphicView::mouseReleaseEvent");
 
        if (!eventHandler)
                return;
@@ -555,7 +554,6 @@ void GraphicView::mouseReleaseEvent(QMouseEvent * e)
        if (e->button() != Qt::RightButton || eventHandler->hasAction())
        {
                eventHandler->mouseReleaseEvent(e);
-               //e->accept();
        }
        else
        {
@@ -563,7 +561,7 @@ void GraphicView::mouseReleaseEvent(QMouseEvent * e)
                e->accept();
        }
 
-       RS_DEBUG->print("GraphicView::mouseReleaseEvent: OK");
+       DEBUG->print("GraphicView::mouseReleaseEvent: OK");
 }
 
 /**
@@ -572,14 +570,14 @@ void GraphicView::mouseReleaseEvent(QMouseEvent * e)
  */
 void GraphicView::mouseMoveEvent(QMouseEvent * e)
 {
-       RS_DEBUG->print("GraphicView::mouseMoveEvent begin");
+       DEBUG->print("GraphicView::mouseMoveEvent begin");
 
        Drawing * graphic = NULL;
 
        if (container->rtti() == RS2::EntityGraphic)
                graphic = (Drawing *)container;
 
-       RS_DEBUG->print("GraphicView::mouseMoveEvent 001");
+       DEBUG->print("GraphicView::mouseMoveEvent 001");
 
        if (e)
        {
@@ -587,23 +585,23 @@ void GraphicView::mouseMoveEvent(QMouseEvent * e)
                my = e->y();
        }
 
-       RS_DEBUG->print("GraphicView::mouseMoveEvent 002");
+       DEBUG->print("GraphicView::mouseMoveEvent 002");
 
        if (eventHandler)
                eventHandler->mouseMoveEvent(e);
 
-       RS_DEBUG->print("GraphicView::mouseMoveEvent 003");
+       DEBUG->print("GraphicView::mouseMoveEvent 003");
 
        if (!eventHandler || !eventHandler->hasAction() && graphic)
        {
                Vector mouse = toGraph(Vector(mx, my));
                Vector relMouse = mouse - getRelativeZero();
 
-               if (RS_DIALOGFACTORY)
-                       RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
+               if (DIALOGFACTORY)
+                       DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
        }
 
-       RS_DEBUG->print("GraphicView::mouseMoveEvent end");
+       DEBUG->print("GraphicView::mouseMoveEvent end");
 }
 
 /**
@@ -649,7 +647,7 @@ void GraphicView::keyReleaseEvent(QKeyEvent * e)
 /**
  * Called by the actual GUI class which implements a command line.
  */
-void GraphicView::commandEvent(RS_CommandEvent * e)
+void GraphicView::commandEvent(CommandEvent * e)
 {
        if (eventHandler)
                eventHandler->commandEvent(e);
@@ -680,7 +678,7 @@ void GraphicView::zoomIn(double f, const Vector & center)
 {
        if (f < 1.0e-6)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING, "GraphicView::zoomIn: invalid factor");
+               DEBUG->print(Debug::D_WARNING, "GraphicView::zoomIn: invalid factor");
                return;
        }
 
@@ -691,14 +689,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();
 }
 
 /**
@@ -740,7 +732,7 @@ void GraphicView::zoomOut(double f, const Vector & center)
 {
        if (f < 1.0e-6)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING,
+               DEBUG->print(Debug::D_WARNING,
                        "GraphicView::zoomOut: invalid factor");
                return;
        }
@@ -758,7 +750,7 @@ void GraphicView::zoomOutX(double f)
 {
        if (f < 1.0e-6)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING,
+               DEBUG->print(Debug::D_WARNING,
                        "GraphicView::zoomOutX: invalid factor");
                return;
        }
@@ -781,7 +773,7 @@ void GraphicView::zoomOutY(double f)
 {
        if (f < 1.0e-6)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING, "GraphicView::zoomOutY: invalid factor");
+               DEBUG->print(Debug::D_WARNING, "GraphicView::zoomOutY: invalid factor");
                return;
        }
 
@@ -805,7 +797,7 @@ void GraphicView::zoomOutY(double f)
  */
 void GraphicView::zoomAuto(bool axis, bool keepAspectRatio)
 {
-       RS_DEBUG->print("GraphicView::zoomAuto");
+       DEBUG->print("GraphicView::zoomAuto");
 
        if (simulationRunning)
                return;
@@ -840,12 +832,12 @@ void GraphicView::zoomAuto(bool axis, bool keepAspectRatio)
                else
                        fy = 1.0;
 
-               RS_DEBUG->print("f: %f/%f", fx, fy);
+               DEBUG->print("f: %f/%f", fx, fy);
 
                if (keepAspectRatio)
                        fx = fy = std::min(fx, fy);
 
-               RS_DEBUG->print("f: %f/%f", fx, fy);
+               DEBUG->print("f: %f/%f", fx, fy);
 
                if (fx < RS_TOLERANCE)
                        fx = fy = 1.0;
@@ -853,22 +845,22 @@ void GraphicView::zoomAuto(bool axis, bool keepAspectRatio)
                setFactorX(fx);
                setFactorY(fy);
 
-               RS_DEBUG->print("f: %f/%f", fx, fy);
+               DEBUG->print("f: %f/%f", fx, fy);
 
-               RS_DEBUG->print("adjustOffsetControls");
+               DEBUG->print("adjustOffsetControls");
                adjustOffsetControls();
-               RS_DEBUG->print("adjustZoomControls");
+               DEBUG->print("adjustZoomControls");
                adjustZoomControls();
-               RS_DEBUG->print("centerOffsetX");
+               DEBUG->print("centerOffsetX");
                centerOffsetX();
-               RS_DEBUG->print("centerOffsetY");
+               DEBUG->print("centerOffsetY");
                centerOffsetY();
-               RS_DEBUG->print("updateGrid");
+               DEBUG->print("updateGrid");
                updateGrid();
                redraw();
        }
 
-       RS_DEBUG->print("GraphicView::zoomAuto OK");
+       DEBUG->print("GraphicView::zoomAuto OK");
 }
 
 /**
@@ -876,7 +868,7 @@ void GraphicView::zoomAuto(bool axis, bool keepAspectRatio)
  */
 void GraphicView::zoomPrevious()
 {
-       RS_DEBUG->print("GraphicView::zoomPrevious");
+       DEBUG->print("GraphicView::zoomPrevious");
 
        if (simulationRunning)
                return;
@@ -935,17 +927,18 @@ void GraphicView::zoomAutoY(bool axis)
                double maxY = RS_MINDOUBLE;
                bool noChange = false;
 
-               for(RS_Entity * e=container->firstEntity(RS2::ResolveNone);
+               for(Entity * e=container->firstEntity(RS2::ResolveNone);
                        e!=NULL; e = container->nextEntity(RS2::ResolveNone))
                {
                        if (e->rtti() == RS2::EntityLine)
                        {
-                               RS_Line * l = (RS_Line *)e;
+                               Line * l = (Line *)e;
                                double x1, x2;
                                x1 = toGuiX(l->getStartpoint().x);
                                x2 = toGuiX(l->getEndpoint().x);
 
-                               if (x1 > 0.0 && x1 < (double)getWidth() || x2 > 0.0 && x2 < (double)getWidth())
+                               if ((x1 > 0.0 && x1 < (double)getWidth())
+                                       || (x2 > 0.0 && x2 < (double)getWidth()))
                                {
                                        minY = std::min(minY, l->getStartpoint().y);
                                        minY = std::min(minY, l->getEndpoint().y);
@@ -984,7 +977,7 @@ void GraphicView::zoomAutoY(bool axis)
                        updateGrid();
                }
 
-               RS_DEBUG->print("Auto zoom y ok");
+               DEBUG->print("Auto zoom y ok");
        }
 }
 
@@ -1079,8 +1072,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;
 
@@ -1089,7 +1080,6 @@ void GraphicView::zoomPan(int dx, int dy)
 
        disableUpdate();
        adjustOffsetControls();
-       //adjustZoomControls();
        updateGrid();
        enableUpdate();
        redraw();
@@ -1130,7 +1120,7 @@ void GraphicView::zoomScroll(RS2::Direction direction)
  */
 void GraphicView::zoomPage()
 {
-       RS_DEBUG->print("GraphicView::zoomPage");
+       DEBUG->print("GraphicView::zoomPage");
 
        if (container == NULL)
                return;
@@ -1158,11 +1148,11 @@ void GraphicView::zoomPage()
        else
                fy = 1.0;
 
-       RS_DEBUG->print("f: %f/%f", fx, fy);
+       DEBUG->print("f: %f/%f", fx, fy);
 
        fx = fy = std::min(fx, fy);
 
-       RS_DEBUG->print("f: %f/%f", fx, fy);
+       DEBUG->print("f: %f/%f", fx, fy);
 
        if (fx < RS_TOLERANCE)
                fx = fy = 1.0;
@@ -1170,7 +1160,7 @@ void GraphicView::zoomPage()
        setFactorX(fx);
        setFactorY(fy);
 
-       RS_DEBUG->print("f: %f/%f", fx, fy);
+       DEBUG->print("f: %f/%f", fx, fy);
 
        centerOffsetX();
        centerOffsetY();
@@ -1185,14 +1175,14 @@ void GraphicView::zoomPage()
  */
 void GraphicView::drawWindow(Vector v1, Vector v2)
 {
-       RS_DEBUG->print("GraphicView::drawWindow() begin");
+       DEBUG->print("GraphicView::drawWindow() begin");
 
        if (simulationRunning)
                return;
 
        if (container)
        {
-               for(RS_Entity * se=container->firstEntity(RS2::ResolveNone); se!=NULL;
+               for(Entity * se=container->firstEntity(RS2::ResolveNone); se!=NULL;
                        se=container->nextEntity(RS2::ResolveNone))
                {
                        if (se->isInWindow(v1, v2))
@@ -1200,12 +1190,13 @@ void GraphicView::drawWindow(Vector v1, Vector v2)
                }
        }
 
-       RS_DEBUG->print("GraphicView::drawWindow() end");
+       DEBUG->print("GraphicView::drawWindow() end");
 }
 
 /**
  * Draws the entities. If painter is NULL a new painter will
- * be created and destroyed.
+ * be created and destroyed. [NB: Not any more, we don't let the programmer try
+ * to outsmart the toolkit anymore. :-P
  */
 void GraphicView::drawIt()
 {
@@ -1241,7 +1232,7 @@ void GraphicView::drawIt()
                drawMetaGrid();
 
        // drawing entities:
-//#warning "!!! This looks like a bug, no match for 'drawEntity(RS_Entity *, bool) !!!"
+//#warning "!!! This looks like a bug, no match for 'drawEntity(Entity *, bool) !!!"
 // and indeed it *is* a bug... true is converted to 1.0 here. Dumb, dumb, dumb.
        drawEntity(container);//, true);
 
@@ -1261,7 +1252,7 @@ void GraphicView::drawIt()
  * Sets the pen of the painter object to the suitable pen for the given
  * entity.
  */
-void GraphicView::setPenForEntity(RS_Entity * e)
+void GraphicView::setPenForEntity(Entity * e)
 {
        if (drawingMode == RS2::ModePreview /*|| draftMode==true*/)
                return;
@@ -1271,7 +1262,7 @@ void GraphicView::setPenForEntity(RS_Entity * e)
 
        // set color of entity
        // Getting pen from entity (or layer)
-       RS_Pen pen = e->getPen(true);
+       Pen pen = e->getPen(true);
 
        int w = pen.getWidth();
 
@@ -1287,7 +1278,7 @@ void GraphicView::setPenForEntity(RS_Entity * e)
 
                if (graphic)
                {
-                       uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());
+                       uf = Units::convert(1.0, RS2::Millimeter, graphic->getUnit());
 
                        if ((isPrinting() || isPrintPreview()) && graphic->getPaperScale() > 1.0e-6)
                                wf = 1.0 / graphic->getPaperScale();
@@ -1302,7 +1293,7 @@ void GraphicView::setPenForEntity(RS_Entity * e)
        }
 
        // prevent drawing with 1-width which is slow:
-       if (RS_Math::round(pen.getScreenWidth()) == 1)
+       if (Math::round(pen.getScreenWidth()) == 1)
                pen.setScreenWidth(0.0);
 
        // prevent background color on background drawing:
@@ -1313,14 +1304,14 @@ void GraphicView::setPenForEntity(RS_Entity * e)
        if (e->isSelected())
        {
                pen.setLineType(RS2::DotLine);
-               //pen.setColor(RS_Color(0xa5,0x47,0x47));
+               //pen.setColor(Color(0xa5,0x47,0x47));
                pen.setColor(selectedColor);
        }
 
        // this entity is highlighted:
        if (e->isHighlighted())
        {
-               //pen.setColor(RS_Color(0x73, 0x93, 0x73));
+               //pen.setColor(Color(0x73, 0x93, 0x73));
                pen.setColor(highlightedColor);
        }
 
@@ -1340,9 +1331,9 @@ void GraphicView::setPenForEntity(RS_Entity * e)
  *        lines e.g. in splines).
  * @param db Double buffering on (recommended) / off
  */
-void GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db)
+void GraphicView::drawEntity(Entity * e, double patternOffset, bool db)
 {
-       //RS_DEBUG->print("GraphicView::drawEntity() begin");
+       //DEBUG->print("GraphicView::drawEntity() begin");
 
        // update is diabled:
        if (!isUpdateEnabled())
@@ -1367,18 +1358,18 @@ void GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db)
 //}
 
        //drawRecursion++;
-       //RS_DEBUG->print("recursion 1: %d", drawRecursion);
+       //DEBUG->print("recursion 1: %d", drawRecursion);
 
        // set pen (color):
        setPenForEntity(e);
 
-       //RS_DEBUG->print("draw plain");
+       //DEBUG->print("draw plain");
        if (draftMode)
        {
                // large texts as rectangles:
                if (e->rtti() == RS2::EntityText)
                {
-                       if (toGuiDX(((RS_Text *)e)->getHeight()) < 4 || e->countDeep() > 100)
+                       if (toGuiDX(((Text *)e)->getHeight()) < 4 || e->countDeep() > 100)
                                painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
                        else
                                drawEntityPlain(e, patternOffset);
@@ -1407,7 +1398,7 @@ void GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db)
                        for(int i=0; i<s.getNumber(); ++i)
                        {
                                int sz = -1;
-                               RS_Color col = RS_Color(0, 0, 255);
+                               Color col = Color(0, 0, 255);
 
                                if (e->rtti() == RS2::EntityPolyline)
                                {
@@ -1417,13 +1408,13 @@ void GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db)
                                                {
                                                        sz = 4;
 //                                                     col = QColor(0, 64, 255);
-                                                       col = RS_Color(0, 64, 255);
+                                                       col = Color(0, 64, 255);
                                                }
                                                else
                                                {
                                                        sz = 3;
 //                                                     col = QColor(0, 0, 128);
-                                                       col = RS_Color(0, 0, 128);
+                                                       col = Color(0, 0, 128);
                                                }
                                        }
                                }
@@ -1436,27 +1427,15 @@ void GraphicView::drawEntity(RS_Entity * e, double patternOffset, bool db)
                }
        }
 
-       //RS_DEBUG->print("draw plain OK");
-       //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);
+       //DEBUG->print("draw plain OK");
+       //DEBUG->print("GraphicView::drawEntity() end");
 }
 
 /**
  * Draws an entity.
  * The painter must be initialized and all the attributes (pen) must be set.
  */
-void GraphicView::drawEntityPlain(RS_Entity * e, double patternOffset/*= 0.0*/)
+void GraphicView::drawEntityPlain(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...
@@ -1481,8 +1460,6 @@ void GraphicView::simulateIt()
        simulationRunning = true;
        simulationLast = Vector(0.0, 0.0);
 
-//jlh  destroyPainter();
-
        painter->erase();
 
        // drawing paper border:
@@ -1497,18 +1474,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);
+       Pen pen(foreground, RS2::Width00, RS2::SolidLine);
        simulateEntity(container, pen);
 
-       //RS_DEBUG->timestamp();
-       //RS_DEBUG->print(" draw zero..");
-
        // drawing zero points:
        if (!isPrintPreview())
        {
@@ -1516,14 +1485,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,45 +1493,43 @@ void GraphicView::simulateIt()
  *
  * @param smooth If true, the entity will be drawn slowly (pixel by pixel).
  */
-void GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
+void GraphicView::simulateEntity(Entity * e, const Pen & pen)
 {
-       if (painter == NULL || e == NULL)
+       if (!painter || !e)
                return;
 
        if (e->isContainer())
        {
-               RS_EntityContainer * ec = (RS_EntityContainer *)e;
+               EntityContainer * ec = (EntityContainer *)e;
 
-               for(RS_Entity* en=ec->firstEntity(RS2::ResolveNone);
-                               en!=NULL; en = ec->nextEntity(RS2::ResolveNone))
+               for(Entity * en=ec->firstEntity(RS2::ResolveNone);
+                       en!=NULL; en=ec->nextEntity(RS2::ResolveNone))
                {
                        if (en->isVisible() && en->isUndone() == false)
                        {
                                // draw rapid move:
                                if (en->isAtomic() && simulationRapid)
                                {
-                                       Vector sp = ((RS_AtomicEntity *)en)->getStartpoint();
+                                       Vector sp = ((AtomicEntity *)en)->getStartpoint();
 
                                        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));
+                                               Pen rpen(Color(0, 0, 255), RS2::Width00, RS2::SolidLine);
+                                               Line rapidLine(NULL, LineData(simulationLast, sp));
                                                simulateEntity(&rapidLine, rpen);
                                        }
                                }
 
                                if (en->isHighlighted())
                                {
-                                       RS_Pen hpen(highlightedColor, RS2::Width00, RS2::SolidLine);
+                                       Pen hpen(highlightedColor, RS2::Width00, RS2::SolidLine);
                                        simulateEntity(en, hpen);
                                }
                                else
                                        simulateEntity(en, pen);
 
                                if (en->isAtomic())
-                                       simulationLast = ((RS_AtomicEntity *)en)->getEndpoint();
+                                       simulationLast = ((AtomicEntity *)en)->getEndpoint();
 
                                if (!simulationSmooth)
                                        simulationDelay(true);
@@ -1585,7 +1544,7 @@ void GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
                        {
                        case RS2::EntityLine:
                        {
-                               RS_Line * line = (RS_Line *)e;
+                               Line * line = (Line *)e;
                                drawLineSmooth(toGui(line->getStartpoint()), toGui(line->getEndpoint()), pen);
                                        //simulationSpeed);
                        }
@@ -1593,7 +1552,7 @@ void GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
 
                        case RS2::EntityArc:
                        {
-                               RS_Arc * arc = (RS_Arc *)e;
+                               Arc * arc = (Arc *)e;
                                drawArcSmooth(toGui(arc->getCenter()), toGuiDX(arc->getRadius()),
                                        arc->getAngle1(), arc->getAngle2(), arc->isReversed(), pen);
                        }
@@ -1601,7 +1560,7 @@ void GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
 
                        case RS2::EntityCircle:
                        {
-                               RS_Circle * circle = (RS_Circle *)e;
+                               Circle * circle = (Circle *)e;
                                drawArcSmooth(toGui(circle->getCenter()), toGuiDX(circle->getRadius()),
                                        0.0, 2.0 * M_PI, false, pen);
                        }
@@ -1613,8 +1572,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);
                }
@@ -1670,31 +1627,31 @@ void GraphicView::simulationDelay(bool step)
 /**
  * Draws a line slowly from (x1, y1) to (x2, y2). This is used for simulation only.
  */
-void GraphicView::drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen)
+void GraphicView::drawLineSmooth(const Vector & p1, const Vector & p2, const Pen & pen)
 {
        double alpha = p1.angleTo(p2);
        double xStep, yStep;
        bool  xIsOne;
 
-       if (RS_Math::cmpDouble(alpha, 0.0) || RS_Math::cmpDouble(alpha, 2 * M_PI))
+       if (Math::cmpDouble(alpha, 0.0) || Math::cmpDouble(alpha, 2 * M_PI))
        {
                xStep = 1.0;
                yStep = 0.0;
                xIsOne = true;
        }
-       else if (RS_Math::cmpDouble(alpha, M_PI / 2.0))
+       else if (Math::cmpDouble(alpha, M_PI / 2.0))
        {
                xStep = 0.0;
                yStep = 1.0;
                xIsOne = false;
        }
-       else if (RS_Math::cmpDouble(alpha, M_PI))
+       else if (Math::cmpDouble(alpha, M_PI))
        {
                xStep = -1.0;
                yStep = 0.0;
                xIsOne = true;
        }
-       else if (RS_Math::cmpDouble(alpha, M_PI / 2.0 * 3.0))
+       else if (Math::cmpDouble(alpha, M_PI / 2.0 * 3.0))
        {
                xStep = 0.0;
                yStep = -1.0;
@@ -1723,15 +1680,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,24 +1700,19 @@ 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)
+       const 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);
        }
        else
        {
-               int ix1 = RS_Math::round(center.x + cos(a1) * radius);
-               int iy1 = RS_Math::round(center.y - sin(a1) * radius);
-               int ix2 = RS_Math::round(center.x + cos(a2) * radius);
-               int iy2 = RS_Math::round(center.y - sin(a2) * radius);
+               int ix1 = Math::round(center.x + cos(a1) * radius);
+               int iy1 = Math::round(center.y - sin(a1) * radius);
+               int ix2 = Math::round(center.x + cos(a2) * radius);
+               int iy2 = Math::round(center.y - sin(a2) * radius);
                int k2x = 0;            // Next point on circle
                int k2y = 0;            //
                int k1x = ix1;          // Prev point on circle
@@ -1788,42 +1736,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();
+                               k2x = Math::round(center.x+cos(a)*radius);
+                               k2y = Math::round(center.y-sin(a)*radius);
                                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
                {
@@ -1832,36 +1765,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();
+                               k2x = Math::round(center.x + cos(a) * radius);
+                               k2y = Math::round(center.y - sin(a) * radius);
                                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));
                }
        }
@@ -1871,7 +1794,7 @@ void GraphicView::drawArcSmooth(const Vector & center, double radius, double a1,
  * @return Pointer to the static pattern struct that belongs to the
  * given pattern type or NULL.
  */
-RS_LineTypePattern * GraphicView::getPattern(RS2::LineType t)
+LineTypePattern * GraphicView::getPattern(RS2::LineType t)
 {
        switch (t)
        {
@@ -1970,12 +1893,10 @@ 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);
+//     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...
-       RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
+//It's because Qt colors and Color are not 100% compatible...
+       Pen p(Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
        painter->setPen(p);
 
        painter->drawLine(Vector(toGuiX(0.0) - zr, toGuiY(0.0)),
@@ -1994,7 +1915,6 @@ void GraphicView::drawAbsoluteZero()
  */
 void GraphicView::drawRelativeZero()
 {
-// PROBLEM: relativeZero IS NOT VALID!!!
        if (!relativeZero.valid || !painter)
 #if 1
                return;
@@ -2010,23 +1930,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);
+       Pen p(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();
 }
 
 /**
@@ -2051,7 +1971,7 @@ void GraphicView::drawPaper()
                return;
 
        // draw paper:
-       painter->setPen(RS_Pen(Qt::gray));
+       painter->setPen(Pen(Qt::gray));
 
        Vector pinsbase = graphic->getPaperInsertionBase();
        Vector size = graphic->getPaperSize();
@@ -2061,19 +1981,19 @@ void GraphicView::drawPaper()
        Vector v2 = toGui((size - pinsbase) / scale);
 
        // gray background:
-       painter->fillRect(0,0, getWidth(), getHeight(), RS_Color(200, 200, 200));
+       painter->fillRect(0,0, getWidth(), getHeight(), Color(200, 200, 200));
 
        // shadow
        painter->fillRect((int)(v1.x) + 6, (int)(v1.y) + 6,
-               (int)((v2.x - v1.x)), (int)((v2.y - v1.y)), RS_Color(64, 64, 64));
+               (int)((v2.x - v1.x)), (int)((v2.y - v1.y)), Color(64, 64, 64));
 
        // border:
        painter->fillRect((int)(v1.x), (int)(v1.y),
-               (int)((v2.x - v1.x)), (int)((v2.y - v1.y)), RS_Color(64, 64, 64));
+               (int)((v2.x - v1.x)), (int)((v2.y - v1.y)), Color(64, 64, 64));
 
        // paper
        painter->fillRect((int)(v1.x) + 1, (int)(v1.y) - 1,
-               (int)((v2.x - v1.x)) - 2, (int)((v2.y - v1.y)) + 2, RS_Color(255, 255, 255));
+               (int)((v2.x - v1.x)) - 2, (int)((v2.y - v1.y)) + 2, Color(255, 255, 255));
 }
 
 /**
@@ -2115,13 +2035,13 @@ void GraphicView::drawGrid()
  */
 void GraphicView::drawMetaGrid()
 {
-       if (!grid || isGridOn() == false /*|| grid->getMetaSpacing()<0.0*/)
+       if (!grid || isGridOn() == false)
                return;
 
        if (!painter)
                return;
 
-       RS_Pen pen(metaGridColor, RS2::Width00, RS2::DotLine);
+       Pen pen(metaGridColor, RS2::Width00, RS2::DotLine);
        painter->setPen(pen);
 
        // draw meta grid:
@@ -2150,7 +2070,7 @@ void GraphicView::updateGrid()
                grid->update();
 }
 
-RS_Grid * GraphicView::getGrid()
+Grid * GraphicView::getGrid()
 {
        return grid;
 }
@@ -2180,7 +2100,7 @@ void GraphicView::setDefaultSnapMode(RS2::SnapMode sm)
                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
+       //the RS_ActionInterface and Snapper. So the following should fix
        //us up, hm notwithstanding. [and it does. :-)]
        //hm.
        snapper.setSnapMode(sm);
@@ -2210,7 +2130,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)
        {
@@ -2254,7 +2174,7 @@ double GraphicView::toGuiDY(double d)
  */
 Vector GraphicView::toGraph(Vector v)
 {
-       return Vector(toGraphX(RS_Math::round(v.x)), toGraphY(RS_Math::round(v.y)), 0.0);
+       return Vector(toGraphX(Math::round(v.x)), toGraphY(Math::round(v.y)), 0.0);
 }
 
 /**
@@ -2340,18 +2260,10 @@ 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()
+EventHandler * GraphicView::getEventHandler()
 {
        return eventHandler;
 }
@@ -2438,34 +2350,353 @@ 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*/)
+/**
+ * Catches an entity which is close to the given position 'pos'.
+ *
+ * @param pos A graphic coordinate.
+ * @param level The level of resolving for iterating through the entity
+ *        container
+ * @return Pointer to the entity or NULL.
+ */
+Entity * GraphicView::CatchEntity(const Vector & pos, RS2::ResolveLevel level)
+{
+       DEBUG->print("GraphicView::CatchEntity");
+
+       // Set default distance for points inside solids
+       double dist = toGraphDX(snapRange) * 0.9;
+       Entity * entity = container->getNearestEntity(pos, &dist, level);
+
+       // DEBUGGING INFO
+       int idx = -1;
+
+       if (entity && entity->getParent())
+               idx = entity->getParent()->findEntity(entity);
+       // END DEBUGGING INFO
+
+       if (entity && dist <= toGraphDX(snapRange))
+       {
+               // Highlight:
+               DEBUG->print("GraphicView::CatchEntity: found: idx=%d", idx);
+               return entity;
+       }
+
+       DEBUG->print("GraphicView::CatchEntity: not found");
+       return NULL;
+}
+
+/**
+ * Catches an entity which is close to the mouse cursor.
+ *
+ * @param e A mouse event.
+ * @param level The level of resolving for iterating through the entity
+ *              container
+ * @return Pointer to the entity or NULL.
+ */
+Entity * GraphicView::CatchEntity(QMouseEvent * e, RS2::ResolveLevel level)
+{
+       return CatchEntity(Vector(toGraphX(e->x()), toGraphY(e->y())), level);
+}
+
+/**
+ * Snap to a coordinate in the drawing using the current snap mode.
+ *
+ * @param e A mouse event.
+ * @return The coordinates of the point or an invalid vector.
+ */
+Vector GraphicView::SnapPoint(QMouseEvent * e)
+{
+       DEBUG->print("GraphicView::SnapPoint");
+       /*Vector*/ snapSpot = Vector(false);
+
+       if (!e)
+       {
+               DEBUG->print(Debug::D_WARNING, "GraphicView::SnapPoint: QMouseEvent is NULL");
+               return snapSpot;
+       }
+
+       Vector mouseCoord = toGraph(e->x(), e->y());
+
+//     switch (snapMode)
+       switch (defaultSnapMode)
+       {
+       case RS2::SnapFree:
+//             snapSpot = snapFree(mouseCoord);
+               snapEntity = NULL;
+               snapSpot = mouseCoord;
+               break;
+
+       case RS2::SnapEndpoint:
+//             snapSpot = snapEndpoint(mouseCoord);
+               snapSpot = container->getNearestEndpoint(mouseCoord, NULL);
+               break;
+
+       case RS2::SnapGrid:
+               snapSpot = SnapGrid(mouseCoord);
+               break;
+
+       case RS2::SnapOnEntity:
+//             snapSpot = snapOnEntity(mouseCoord);
+               snapSpot = container->getNearestPointOnEntity(mouseCoord, true, NULL, &snapEntity);
+               break;
+
+       case RS2::SnapCenter:
+//             snapSpot = snapCenter(mouseCoord);
+               snapSpot = container->getNearestCenter(mouseCoord, NULL);
+               break;
+
+       case RS2::SnapMiddle:
+//             snapSpot = snapMiddle(mouseCoord);
+               snapSpot = container->getNearestMiddle(mouseCoord, NULL);
+               break;
+
+       case RS2::SnapDist:
+//             snapSpot = snapDist(mouseCoord);
+               snapSpot = container->getNearestDist(snapDistance, mouseCoord, NULL);
+               break;
+
+       case RS2::SnapIntersection:
+//             snapSpot = snapIntersection(mouseCoord);
+               snapSpot = container->getNearestIntersection(mouseCoord, NULL);
+               break;
+
+       default:
+               break;
+       }
+
+       // This is declared here because I really, really hate extraneous braces in
+       // my switch statements. :-P
+       Vector relZero = getRelativeZero();
+       Vector restrictX = Vector(relZero.x, snapSpot.y);
+       Vector restrictY = Vector(snapSpot.x, relZero.y);
+//     Vector snapCoord;
+       // Handle snap restrictions that can be activated in addition to the ones above:
+//     switch (snapRes)
+       switch (defaultSnapRes)
+       {
+       case RS2::RestrictOrthogonal:
+////           snapCoord = restrictOrthogonal(snapSpot);
+//             rz = graphicView->getRelativeZero();
+//             retx = Vector(rz.x, snapSpot.y);
+//             rety = Vector(snapSpot.x, rz.y);
+               snapCoord = (restrictX.distanceTo(snapSpot) < restrictY.distanceTo(snapSpot) ?
+                       restrictX : restrictY);
+               break;
+       case RS2::RestrictHorizontal:
+////           snapCoord = restrictHorizontal(snapSpot);
+//             rz = graphicView->getRelativeZero();
+//             snapCoord = Vector(snapSpot.x, rz.y);
+               snapCoord = restrictY;
+               break;
+       case RS2::RestrictVertical:
+////           snapCoord = restrictVertical(snapSpot);
+//             rz = graphicView->getRelativeZero();
+//             snapCoord = Vector(rz.x, snapSpot.y);
+               snapCoord = restrictX;
+               break;
+       default:
+       case RS2::RestrictNothing:
+               snapCoord = snapSpot;
+               break;
+       }
+
+       if (DIALOGFACTORY)
+               DIALOGFACTORY->updateCoordinateWidget(snapCoord, snapCoord - relZero);
+
+       DEBUG->print("GraphicView::SnapPoint: OK");
+
+       return snapCoord;
+}
+
+/**
+ * Snaps to a grid point.
+ *
+ * @param coord The mouse coordinate.
+ * @return The coordinates of the point or an invalid vector.
+ */
+Vector GraphicView::SnapGrid(Vector coord)
 {
-       previewMode = mode;
+       DEBUG->print("GraphicView::snapGrid begin");
+
+       Vector vec(false);
+       double dist = 0.0;
+
+       DEBUG->print("GraphicView::snapGrid 001");
+
+       if (grid)
+       {
+               DEBUG->print("GraphicView::snapGrid 002");
+               Vector * pts = grid->getPoints();
+               DEBUG->print("GraphicView::snapGrid 003");
+               int closest = -1;
+               dist = 32000.00;
+               DEBUG->print("GraphicView::snapGrid 004");
+
+               for(int i=0; i<grid->count(); ++i)
+               {
+                       double d = pts[i].distanceTo(coord);
+
+                       if (d < dist)
+                       {
+                               closest = i;
+                               dist = d;
+                       }
+               }
+
+               DEBUG->print("GraphicView::snapGrid 005");
+
+               if (closest >= 0)
+                       vec = pts[closest];
+
+               DEBUG->print("GraphicView::snapGrid 006");
+       }
+
+       snapEntity = NULL;
+
+       DEBUG->print("GraphicView::snapGrid end");
+
+       return vec;
 }
 
-void GraphicView::SetPreviewEntity(RS_Preview * p)
+void GraphicView::DrawSnapper(PaintInterface * painter)
 {
-       previewEntity = p;
+//Is "finished" used at all? Seems it's used only in ActionInterface, and it's commented out
+//     if (finished || !snapSpot.valid || !snapCoord.valid)
+       if (!snapSpot.valid || !snapCoord.valid)
+#if 1
+{
+printf("DrawSnapper: snapSpot=%s, snapCoord=%s...\n", (snapSpot.valid ? "valid" : "INVALID"), (snapCoord.valid ? "valid" : "INVALID"));
+#endif
+               return;
+#if 1
+}
+#endif
+
+       // Snap point (need to make sure the brush is NULL!)
+//     painter->setPen(Pen(Color(0, 127, 255), RS2::Width00, RS2::DashLine));
+       painter->setPen(Pen(Color(255, 127, 0), RS2::Width00, RS2::DashLine));
+       painter->drawCircle(toGui(snapCoord), 4);
+
+       // Crosshairs
+       if (showCrosshairs)
+       {
+               painter->setPen(Pen(Color(0, 255, 255), RS2::Width00, RS2::DashLine));
+               painter->drawLine(Vector(0, toGuiY(snapCoord.y)),
+                       Vector(getWidth(), toGuiY(snapCoord.y)));
+               painter->drawLine(Vector(toGuiX(snapCoord.x), 0),
+                       Vector(toGuiX(snapCoord.x), getHeight()));
+       }
+
+       // Cursor
+       if (snapCoord != snapSpot)
+       {
+               painter->drawLine(toGui(snapSpot) + Vector(-5, 0), toGui(snapSpot) + Vector(-1, 4));
+               painter->drawLine(toGui(snapSpot) + Vector(0, 5), toGui(snapSpot) + Vector(4, 1));
+               painter->drawLine(toGui(snapSpot) + Vector(5, 0), toGui(snapSpot) + Vector(1, -4));
+               painter->drawLine(toGui(snapSpot) + Vector(0, -5), toGui(snapSpot) + Vector(-4, -1));
+       }
 }
 
-void GraphicView::SetPreviewOffset(Vector o)
+void GraphicView::SetSnapperVisible(bool visibility/*= true*/)
 {
-       previewOffset = o;
+       snapperVisible = visibility;
+}
+
+bool GraphicView::SnapperVisible(void)
+{
+       return snapperVisible;
 }
 
-//Don't need this no more...
 #if 0
-void GraphicView::SetSnapperDraw(bool mode)
+/*
+only place this is called is in ActionInterface. And its only function is to
+have it not drawn anymore. But, the GraphicView seems to draw it anyway... So
+some other approach is needed...
+*/
+void Snapper::finish()
+{
+       finished = true;
+}
+
+/**
+ * @return Pointer to the entity which was the key entity for the last
+ * successful snapping action. If the snap mode is "end point" the key entity
+ * is the entity whose end point was caught. If the snap mode didn't require an
+ * entity (e.g. free, grid) this method will return NULL.
+ */
+Entity * Snapper::getKeyEntity()
+{
+       return keyEntity;
+}
+
+/** Sets a new snap mode. */
+void Snapper::setSnapMode(RS2::SnapMode snapMode)
 {
-       snapperDraw = mode;
+       this->snapMode = snapMode;
 }
 
-void GraphicView::SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs)
+/** Sets a new snap restriction. */
+void Snapper::setSnapRestriction(RS2::SnapRestriction snapRes)
+{
+       this->snapRes = snapRes;
+}
+
+RS2::SnapMode Snapper::getSnapMode(void)
+{
+       return snapMode;
+}
+
+RS2::SnapRestriction Snapper::getSnapRestriction(void)
+{
+       return snapRes;
+}
+
+/**
+ * Sets the snap range in pixels for catchEntity().
+ *
+ * @see catchEntity()
+ */
+void Snapper::setSnapRange(int r)
+{
+       snapRange = r;
+}
+
+#if 0
+I think that these suspend() & resume() functions are not used anymore...
+#endif
+/**
+ * Suspends this snapper while another action takes place.
+ */
+/*virtual*/ void Snapper::suspend()
+{
+#warning "!!! This may need to have SetVisibility() called !!!"
+//     deleteSnapper();
+       snapSpot = snapCoord = Vector(false);
+}
+
+/**
+ * Resumes this snapper after it has been suspended.
+ */
+/*virtual*/ void Snapper::resume()
+{
+#warning "!!! This may need to have SetVisibility() called !!!"
+//     drawSnapper();
+}
+
+/**
+ * Hides the snapper options.
+ */
+/*virtual*/ void Snapper::hideOptions()
+{
+       if (snapMode == RS2::SnapDist && DIALOGFACTORY)
+               DIALOGFACTORY->requestSnapDistOptions(distance, false);
+}
+
+/**
+ * Shows the snapper options.
+ */
+/*virtual*/ void Snapper::showOptions()
 {
-       snapSpot1 = snapSpot;
-       snapCoord1 = snapCoord;
-       showCrosshairs1 = showCrosshairs;
+       if (snapMode == RS2::SnapDist && DIALOGFACTORY)
+               DIALOGFACTORY->requestSnapDistOptions(distance, true);
 }
 #endif