X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Frs_snapper.cpp;h=30e666436d46e44425ac8b54e636ccbc8aed9364;hb=97d3cdae07ec9788cf80e7905abfdb5d67a7747c;hp=13d76a92da0e4642819569af28793c790a753fcd;hpb=c40d19f69539b4afaa2c15e7b314eb7b8c88e943;p=architektonas diff --git a/src/base/rs_snapper.cpp b/src/base/rs_snapper.cpp index 13d76a9..30e6664 100644 --- a/src/base/rs_snapper.cpp +++ b/src/base/rs_snapper.cpp @@ -20,6 +20,7 @@ #include "graphicview.h" #include "rs_grid.h" #include "rs_information.h" +#include "paintinterface.h" #include "settings.h" /** @@ -31,6 +32,12 @@ RS_Snapper::RS_Snapper(RS_EntityContainer & c, GraphicView & gv): init(); } +RS_Snapper::RS_Snapper(void): + container(NULL), graphicView(NULL), finished(false) +{ + init(); +} + /** * Destructor. */ @@ -43,8 +50,12 @@ RS_Snapper::~RS_Snapper() */ void RS_Snapper::init() { - snapMode = graphicView->getDefaultSnapMode(); - snapRes = graphicView->getSnapRestriction(); + if (graphicView) + { + snapMode = graphicView->getDefaultSnapMode(); + snapRes = graphicView->getSnapRestriction(); + } + keyEntity = NULL; snapSpot = Vector(false); snapCoord = Vector(false); @@ -68,12 +79,23 @@ void RS_Snapper::finish() finished = true; } +//bleh +void RS_Snapper::SetContainer(RS_EntityContainer * c) +{ + container = c; +} + +//bleh +void RS_Snapper::SetGraphicView(GraphicView * v) +{ + 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() { @@ -92,11 +114,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; @@ -111,11 +143,9 @@ void RS_Snapper::setSnapRange(int r) Vector RS_Snapper::snapPoint(QMouseEvent * e) { RS_DEBUG->print("RS_Snapper::snapPoint"); - - deleteSnapper(); snapSpot = Vector(false); - if (e == NULL) + if (!e) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Snapper::snapPoint: event is NULL"); return snapSpot; @@ -161,8 +191,7 @@ Vector RS_Snapper::snapPoint(QMouseEvent * e) break; } - // handle snap restrictions that can be activated in addition - // to the ones above: + // Handle snap restrictions that can be activated in addition to the ones above: switch (snapRes) { case RS2::RestrictOrthogonal: @@ -180,9 +209,6 @@ Vector RS_Snapper::snapPoint(QMouseEvent * e) break; } -#warning "!!! THIS IS WHERE THE SNAPPER IS BEING DRAWN... !!!" - drawSnapper(); - if (RS_DIALOGFACTORY) RS_DIALOGFACTORY->updateCoordinateWidget(snapCoord, snapCoord - graphicView->getRelativeZero()); @@ -212,7 +238,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; } @@ -234,7 +260,7 @@ Vector RS_Snapper::snapGrid(Vector coord) RS_DEBUG->print("RS_Snapper::snapGrid 001"); - if (grid != NULL) + if (grid) { RS_DEBUG->print("RS_Snapper::snapGrid 002"); Vector * pts = grid->getPoints(); @@ -372,8 +398,8 @@ Vector RS_Snapper::restrictOrthogonal(Vector coord) Vector RS_Snapper::restrictHorizontal(Vector coord) { Vector rz = graphicView->getRelativeZero(); - Vector ret = Vector(coord.x, rz.y); - return ret; + + return Vector(coord.x, rz.y); } /** @@ -386,8 +412,8 @@ Vector RS_Snapper::restrictHorizontal(Vector coord) Vector RS_Snapper::restrictVertical(Vector coord) { Vector rz = graphicView->getRelativeZero(); - Vector ret = Vector(rz.x, coord.y); - return ret; + + return Vector(rz.x, coord.y); } /** @@ -444,127 +470,84 @@ RS_Entity * RS_Snapper::catchEntity(QMouseEvent * e, RS2::ResolveLevel level) /** * Suspends this snapper while another action takes place. */ -void RS_Snapper::suspend() +/*virtual*/ void RS_Snapper::suspend() { - deleteSnapper(); +#warning "!!! This may need to have SetVisibility() called !!!" +// deleteSnapper(); snapSpot = snapCoord = Vector(false); } /** * Resumes this snapper after it has been suspended. */ -void RS_Snapper::resume() +/*virtual*/ void RS_Snapper::resume() { - drawSnapper(); +#warning "!!! This may need to have SetVisibility() called !!!" +// drawSnapper(); } /** - * Hides the snapper options. Default implementation does nothing. + * Hides the snapper options. */ -void RS_Snapper::hideOptions() +/*virtual*/ void RS_Snapper::hideOptions() { if (snapMode == RS2::SnapDist && RS_DIALOGFACTORY) RS_DIALOGFACTORY->requestSnapDistOptions(distance, false); } /** - * Shows the snapper options. Default implementation does nothing. + * Shows the snapper options. */ -void RS_Snapper::showOptions() +/*virtual*/ void RS_Snapper::showOptions() { if (snapMode == RS2::SnapDist && RS_DIALOGFACTORY) RS_DIALOGFACTORY->requestSnapDistOptions(distance, true); } -/** - * Draws the snapper on the screen. - */ -void RS_Snapper::drawSnapper() +void RS_Snapper::SetVisible(bool visibility/*= true*/) { -printf("RS_Snapper::drawSnapper(): Using DEPRECATED function!!!\n"); - if (!visible) - xorSnapper(); + visible = visibility; } -/** - * Deletes the snapper from the screen. - */ -void RS_Snapper::deleteSnapper() +bool RS_Snapper::Visible(void) { -printf("RS_Snapper::deleteSnapper(): Using DEPRECATED function!!!\n"); - if (visible) - { - xorSnapper(); - snapSpot = Vector(false); - snapCoord = Vector(false); - } + return visible; } -/** - * Draws / deletes the current snapper spot. - */ -void RS_Snapper::xorSnapper() +void RS_Snapper::Draw(GraphicView * view, PaintInterface * painter) { -//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); + if (finished || !snapSpot.valid) + return; - // 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())); - } - } +//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) + { + // snap point + painter->setPen(RS_Pen(RS_Color(0, 127, 255), RS2::Width00, RS2::DashLine)); + painter->drawCircle(view->toGui(snapCoord), 4); - if (snapCoord.valid && snapCoord != snapSpot) + // crosshairs + if (showCrosshairs) { - 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)); + 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())); } - - graphicView->destroyPainter(); - visible = !visible; } -#else - if (finished || !snapSpot.valid || graphicView == NULL) - 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::SetSnapperVisible(bool visibility/*= true*/) -{ - graphicView->SetSnapperDraw(visibility); -} - -//Hmm, not sure this is necessary... -#warning "!!! Not sure this is necessary... !!!" -void RS_Snapper::SetSnapperCoords(Vector snapCoord, Vector snapSpot) -{ - graphicView->SetSnapperVars(snapSpot, snapCoord, showCrosshairs); + if (snapCoord.valid && snapCoord != snapSpot) + { + painter->drawLine(view->toGui(snapSpot) + Vector(-5, 0), + view->toGui(snapSpot) + Vector(-1, 4)); + painter->drawLine(view->toGui(snapSpot) + Vector(0, 5), + view->toGui(snapSpot) + Vector(4, 1)); + painter->drawLine(view->toGui(snapSpot) + Vector(5, 0), + view->toGui(snapSpot) + Vector(1, -4)); + painter->drawLine(view->toGui(snapSpot) + Vector(0, -5), + view->toGui(snapSpot) + Vector(-4, -1)); + } }