]> Shamusworld >> Repos - architektonas/blobdiff - src/base/rs_snapper.cpp
Fixed Library Browser...
[architektonas] / src / base / rs_snapper.cpp
index 0767b6ecd30593c5be9ae958ea68d35ea38fc8ca..2aa4f25dccabd04d86573bab1b781b554ee82f58 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>
 //
@@ -20,7 +22,7 @@
 #include "graphicview.h"
 #include "rs_grid.h"
 #include "rs_information.h"
-#include "paintintf.h"
+#include "paintinterface.h"
 #include "settings.h"
 
 /**
@@ -92,11 +94,10 @@ void RS_Snapper::SetGraphicView(GraphicView * v)
 }
 
 /**
- * @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 whos end point was caught.
- * If the snap mode didn't require an entity (e.g. free, grid) this
- * method will return NULL.
+ * @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 whos end point was caught. If the snap mode didn't require an
+ * entity (e.g. free, grid) this method will return NULL.
  */
 RS_Entity * RS_Snapper::getKeyEntity()
 {
@@ -115,11 +116,21 @@ void RS_Snapper::setSnapRestriction(RS2::SnapRestriction snapRes)
        this->snapRes = snapRes;
 }
 
+RS2::SnapMode RS_Snapper::getSnapMode(void)
+{
+       return snapMode;
+}
+
+RS2::SnapRestriction RS_Snapper::getSnapRestriction(void)
+{
+       return snapRes;
+}
+
 /**
-* Sets the snap range in pixels for catchEntity().
-*
-* @see catchEntity()
-*/
+ * Sets the snap range in pixels for catchEntity().
+ *
+ * @see catchEntity()
+ */
 void RS_Snapper::setSnapRange(int r)
 {
        snapRange = r;
@@ -229,7 +240,7 @@ Vector RS_Snapper::snapFree(Vector coord)
 Vector RS_Snapper::snapEndpoint(Vector coord)
 {
        Vector vec(false);
-       vec = container->getNearestEndpoint(coord, NULL/*, &keyEntity*/);
+       vec = container->getNearestEndpoint(coord, NULL);
 
        return vec;
 }
@@ -415,7 +426,7 @@ Vector RS_Snapper::restrictVertical(Vector coord)
  *        container
  * @return Pointer to the entity or NULL.
  */
-RS_Entity * RS_Snapper::catchEntity(const Vector& pos, RS2::ResolveLevel level)
+RS_Entity * RS_Snapper::catchEntity(const Vector & pos, RS2::ResolveLevel level)
 {
        RS_DEBUG->print("RS_Snapper::catchEntity");
 
@@ -463,7 +474,8 @@ RS_Entity * RS_Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
  */
 /*virtual*/ void RS_Snapper::suspend()
 {
-       deleteSnapper();
+#warning "!!! This may need to have SetVisibility() called !!!"
+//     deleteSnapper();
        snapSpot = snapCoord = Vector(false);
 }
 
@@ -472,7 +484,8 @@ RS_Entity * RS_Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
  */
 /*virtual*/ void RS_Snapper::resume()
 {
-       drawSnapper();
+#warning "!!! This may need to have SetVisibility() called !!!"
+//     drawSnapper();
 }
 
 /**
@@ -493,88 +506,6 @@ RS_Entity * RS_Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level)
                RS_DIALOGFACTORY->requestSnapDistOptions(distance, true);
 }
 
-/**
- * Draws the snapper on the screen.
- */
-void RS_Snapper::drawSnapper()
-{
-printf("RS_Snapper::drawSnapper(): Using DEPRECATED function!!!\n");
-       if (!visible)
-               xorSnapper();
-}
-
-/**
- * Deletes the snapper from the screen.
- */
-void RS_Snapper::deleteSnapper()
-{
-printf("RS_Snapper::deleteSnapper(): Using DEPRECATED function!!!\n");
-       if (visible)
-       {
-               xorSnapper();
-               snapSpot = Vector(false);
-               snapCoord = Vector(false);
-       }
-}
-
-/**
- * Draws / deletes the current snapper spot.
- */
-void RS_Snapper::xorSnapper()
-{
-#warning "!!! RS_Snapper::xorSnapper() is DEPRECATED !!!"
-//Not completely true...
-//#warning "!!! xorSnapper() not working AT ALL !!!"
-#if 0
-       if (!finished && snapSpot.valid)
-       {
-               RS_Painter * painter = graphicView->createDirectPainter();
-               painter->setPreviewMode();
-
-               if (snapCoord.valid)
-               {
-                       // snap point
-                       painter->drawCircle(graphicView->toGui(snapCoord), 4);
-
-                       // crosshairs:
-                       if (showCrosshairs == true)
-                       {
-                               painter->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width00, RS2::DashLine));
-                               painter->drawLine(Vector(0, graphicView->toGuiY(snapCoord.y)),
-                                       Vector(graphicView->getWidth(), graphicView->toGuiY(snapCoord.y)));
-                               painter->drawLine(Vector(graphicView->toGuiX(snapCoord.x), 0),
-                                       Vector(graphicView->toGuiX(snapCoord.x), graphicView->getHeight()));
-                       }
-               }
-
-               if (snapCoord.valid && snapCoord != snapSpot)
-               {
-                       painter->drawLine(graphicView->toGui(snapSpot) + Vector(-5, 0),
-                               graphicView->toGui(snapSpot) + Vector(-1, 4));
-                       painter->drawLine(graphicView->toGui(snapSpot) + Vector(0, 5),
-                               graphicView->toGui(snapSpot) + Vector(4, 1));
-                       painter->drawLine(graphicView->toGui(snapSpot) + Vector(5, 0),
-                               graphicView->toGui(snapSpot) + Vector(1, -4));
-                       painter->drawLine(graphicView->toGui(snapSpot) + Vector(0, -5),
-                               graphicView->toGui(snapSpot) + Vector(-4, -1));
-               }
-
-               graphicView->destroyPainter();
-               visible = !visible;
-       }
-//#else
-       if (finished || !snapSpot.valid || !graphicView)
-               return;
-
-       graphicView->SetSnapperDraw(true);
-       graphicView->SetSnapperVars(snapSpot, snapCoord, showCrosshairs);
-//Apparently, this gets hit anyway by the preview code...
-//     graphicView->redraw();
-
-       visible = !visible;
-#endif
-}
-
 void RS_Snapper::SetVisible(bool visibility/*= true*/)
 {
        visible = visibility;
@@ -585,32 +516,39 @@ bool RS_Snapper::Visible(void)
        return visible;
 }
 
+/*
+We need to figure out how to kick the GraphicView out of this class. Perhaps we
+need to move the toGuiX/Y() functions into another class as static functions.
+Further inspection seems to rule this out as they are pretty well coupled to the
+GraphicView class... What to do?
+*/
 void RS_Snapper::Draw(GraphicView * view, PaintInterface * painter)
 {
-       if (finished || !snapSpot.valid)
+       if (finished || !snapSpot.valid || !snapCoord.valid)
                return;
 
 //hm, I don't like graphicView kicking around in here, especially since it now
 //lives inside GraphicView... How to !!! FIX !!!?
 //We'll pass it in for now...
-       if (snapCoord.valid)
+//     if (snapCoord.valid)
+//     {
+       // Snap point (need to make sure the brush is NULL!)
+//     painter->setPen(RS_Pen(RS_Color(0, 127, 255), RS2::Width00, RS2::DashLine));
+       painter->setPen(RS_Pen(RS_Color(255, 127, 0), RS2::Width00, RS2::DashLine));
+       painter->drawCircle(view->toGui(snapCoord), 4);
+
+       // Crosshairs
+       if (showCrosshairs)
        {
-               // snap point
-               painter->setPen(RS_Pen(RS_Color(0, 127, 255), RS2::Width00, RS2::DashLine));
-               painter->drawCircle(view->toGui(snapCoord), 4);
-
-               // crosshairs
-               if (showCrosshairs)
-               {
-                       painter->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width00, RS2::DashLine));
-                       painter->drawLine(Vector(0, view->toGuiY(snapCoord.y)),
-                               Vector(view->getWidth(), view->toGuiY(snapCoord.y)));
-                       painter->drawLine(Vector(view->toGuiX(snapCoord.x), 0),
-                               Vector(view->toGuiX(snapCoord.x), view->getHeight()));
-               }
+               painter->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width00, RS2::DashLine));
+               painter->drawLine(Vector(0, view->toGuiY(snapCoord.y)),
+                       Vector(view->getWidth(), view->toGuiY(snapCoord.y)));
+               painter->drawLine(Vector(view->toGuiX(snapCoord.x), 0),
+                       Vector(view->toGuiX(snapCoord.x), view->getHeight()));
        }
+//     }
 
-       if (snapCoord.valid && snapCoord != snapSpot)
+       if (/*snapCoord.valid &&*/ snapCoord != snapSpot)
        {
                painter->drawLine(view->toGui(snapSpot) + Vector(-5, 0),
                        view->toGui(snapSpot) + Vector(-1, 4));