]> Shamusworld >> Repos - architektonas/commitdiff
Beginnings of new render path (Snapper)...
authorShamus Hammons <jlhamm@acm.org>
Tue, 6 Jul 2010 23:43:10 +0000 (23:43 +0000)
committerShamus Hammons <jlhamm@acm.org>
Tue, 6 Jul 2010 23:43:10 +0000 (23:43 +0000)
src/actions/rs_actiondrawline.cpp
src/base/rs_eventhandler.cpp
src/base/rs_snapper.cpp
src/base/rs_snapper.h
src/mainapp/graphicview.cpp
src/mainapp/graphicview.h
src/mainapp/mdiwindow.cpp
src/widgets/qg_graphicview.cpp
src/widgets/qg_graphicview.h

index c52fc44ed1c6bb782e5ab1b2ca3408cacc58e54e..1c1860af04f88143cb0a84b63d1590c1a1f6b484 100644 (file)
@@ -25,6 +25,10 @@ RS_ActionDrawLine::RS_ActionDrawLine(RS_EntityContainer & container, GraphicView
 {
        RS_DEBUG->print("RS_ActionDrawLine::RS_ActionDrawLine");
        reset();
+       //hm.
+       graphicView.snapper.SetContainer(&container);
+       graphicView.snapper.SetGraphicView(&graphicView);
+       graphicView.snapper.SetVisible();
        RS_DEBUG->print("RS_ActionDrawLine::RS_ActionDrawLine: OK");
 }
 
@@ -77,13 +81,13 @@ void RS_ActionDrawLine::trigger()
                document->endUndoCycle();
        }
 
-       deleteSnapper();                        // XOR off of screen
-       graphicView->moveRelativeZero(Vector(0.0, 0.0));
+//     deleteSnapper();                        // XOR off of screen
+//     graphicView->moveRelativeZero(Vector(0.0, 0.0));
 //This is unnecessary, because we added this to the container...
 //#warning "!!! Here's the trouble... Trying to draw direct !!!"
 //     graphicView->drawEntity(line);
        graphicView->moveRelativeZero(line->getEndpoint());
-       drawSnapper();                          // XOR on screen
+//     drawSnapper();                          // XOR on screen
        RS_DEBUG->print("RS_ActionDrawLine::trigger(): line added: %d", line->getId());
 }
 
@@ -92,7 +96,9 @@ void RS_ActionDrawLine::mouseMoveEvent(QMouseEvent * e)
        RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent begin");
 
        RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: snap point");
-       Vector mouse = snapPoint(e);
+//This used to draw the snapper, but now that's defunct... so, !!! FIX !!!
+//     Vector mouse = snapPoint(e);
+       Vector mouse = graphicView->snapper.snapPoint(e);
        RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: snap point: OK");
 
        if (getStatus() == SetEndpoint && data.startpoint.valid)
@@ -108,6 +114,8 @@ void RS_ActionDrawLine::mouseMoveEvent(QMouseEvent * e)
                xorPreview();                   // XOR on screen
        }
 
+       //hm.
+       graphicView->redraw();
        RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent end");
 }
 
@@ -122,7 +130,7 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e)
        {
                deletePreview();                // XOR off of screen
                clearPreview();                 // Remove entities from the container
-               deleteSnapper();                // XOR off of screen
+//             deleteSnapper();                // XOR off of screen
                init(getStatus() - 1);
        }
 }
index 20e748461fc9e5a390f05125c7754145011c0bc7..d12d76bab277ed44e100cd1a3aaed0725b2f15bc 100644 (file)
@@ -634,14 +634,14 @@ void RS_EventHandler::cleanUp()
        // Resume last used action:
        if (doResume)
        {
-               if (currentActions[resume] != NULL && !currentActions[resume]->isFinished())
+               if (currentActions[resume] && !currentActions[resume]->isFinished())
                {
                        currentActions[resume]->resume();
                        currentActions[resume]->showOptions();
                }
                else
                {
-                       if (defaultAction != NULL)
+                       if (defaultAction)
                        {
                                defaultAction->resume();
                                defaultAction->showOptions();
@@ -658,10 +658,10 @@ void RS_EventHandler::cleanUp()
 void RS_EventHandler::setSnapMode(RS2::SnapMode sm)
 {
        for(int c=0; c<RS_MAXACTIONS; ++c)
-               if (currentActions[c] != NULL)
+               if (currentActions[c])
                        currentActions[c]->setSnapMode(sm);
 
-       if (defaultAction!=NULL)
+       if (defaultAction)
                defaultAction->setSnapMode(sm);
 }
 
@@ -671,10 +671,10 @@ void RS_EventHandler::setSnapMode(RS2::SnapMode sm)
 void RS_EventHandler::setSnapRestriction(RS2::SnapRestriction sr)
 {
        for(int c=0; c<RS_MAXACTIONS; ++c)
-               if (currentActions[c] != NULL)
+               if (currentActions[c])
                        currentActions[c]->setSnapRestriction(sr);
 
-       if (defaultAction != NULL)
+       if (defaultAction)
                defaultAction->setSnapRestriction(sr);
 }
 
index 13d76a92da0e4642819569af28793c790a753fcd..542810eb427a2a1b3f8e4daaa953a7b63bf64f0b 100644 (file)
@@ -20,6 +20,7 @@
 #include "graphicview.h"
 #include "rs_grid.h"
 #include "rs_information.h"
+#include "paintintf.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,6 +79,17 @@ void RS_Snapper::finish()
        finished = true;
 }
 
+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"
@@ -112,10 +134,10 @@ Vector RS_Snapper::snapPoint(QMouseEvent * e)
 {
        RS_DEBUG->print("RS_Snapper::snapPoint");
 
-       deleteSnapper();
+//meh  deleteSnapper();
        snapSpot = Vector(false);
 
-       if (e == NULL)
+       if (!e)
        {
                RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Snapper::snapPoint: event is NULL");
                return snapSpot;
@@ -180,8 +202,8 @@ Vector RS_Snapper::snapPoint(QMouseEvent * e)
                break;
        }
 
-#warning "!!! THIS IS WHERE THE SNAPPER IS BEING DRAWN... !!!"
-       drawSnapper();
+//#warning "!!! THIS IS WHERE THE SNAPPER IS BEING DRAWN... !!!"
+//     drawSnapper();
 
        if (RS_DIALOGFACTORY)
                RS_DIALOGFACTORY->updateCoordinateWidget(snapCoord, snapCoord - graphicView->getRelativeZero());
@@ -234,7 +256,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 +394,9 @@ 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;
+//     Vector ret = Vector(coord.x, rz.y);
+//     return ret;
+       return Vector(coord.x, rz.y);
 }
 
 /**
@@ -386,8 +409,9 @@ 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;
+//     Vector ret = Vector(rz.x, coord.y);
+//     return ret;
+       return Vector(rz.x, coord.y);
 }
 
 /**
@@ -444,7 +468,7 @@ 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();
        snapSpot = snapCoord = Vector(false);
@@ -453,24 +477,24 @@ void RS_Snapper::suspend()
 /**
  * Resumes this snapper after it has been suspended.
  */
-void RS_Snapper::resume()
+/*virtual*/ void RS_Snapper::resume()
 {
        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);
@@ -545,7 +569,7 @@ void RS_Snapper::xorSnapper()
                visible = !visible;
        }
 #else
-       if (finished || !snapSpot.valid || graphicView == NULL)
+       if (finished || !snapSpot.valid || !graphicView)
                return;
 
        graphicView->SetSnapperDraw(true);
@@ -557,14 +581,55 @@ void RS_Snapper::xorSnapper()
 #endif
 }
 
-void RS_Snapper::SetSnapperVisible(bool visibility/*= true*/)
+void RS_Snapper::SetVisible(bool visibility/*= true*/)
 {
-       graphicView->SetSnapperDraw(visibility);
+//     graphicView->SetSnapperDraw(visibility);
+       visible = visibility;
 }
 
-//Hmm, not sure this is necessary...
-#warning "!!! Not sure this is necessary... !!!"
-void RS_Snapper::SetSnapperCoords(Vector snapCoord, Vector snapSpot)
+bool RS_Snapper::Visible(void)
 {
-       graphicView->SetSnapperVars(snapSpot, snapCoord, showCrosshairs);
+//     graphicView->SetSnapperDraw(visibility);
+       return visible;
+}
+
+void RS_Snapper::Draw(GraphicView * view, PaintInterface * painter)
+{
+//printf("RS_Snapper::Draw()...");
+       if (finished || !snapSpot.valid)
+               return;
+//printf("{D}\n");
+
+//meh  painter->setPreviewMode();
+
+//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->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()));
+               }
+       }
+
+       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));
+       }
 }
index 3967d5e7f05ab031f0aa99395b0fbd626a744588..575bd7badfe72890408385943bcf1e396873a563 100644 (file)
@@ -8,6 +8,7 @@
 class RS_Entity;
 class RS_EntityContainer;
 class GraphicView;
+class PaintInterface;
 
 /**
  * This class is used for snapping functions in a graphic view.
@@ -23,11 +24,14 @@ class RS_Snapper
 {
        public:
                RS_Snapper(RS_EntityContainer & container, GraphicView & graphicView);
+               RS_Snapper();
                virtual ~RS_Snapper();
 
                void init();
                void finish();
 
+               void SetContainer(RS_EntityContainer *);
+               void SetGraphicView(GraphicView *);
                RS_Entity * getKeyEntity();
                void setSnapMode(RS2::SnapMode snapMode);
                void setSnapRestriction(RS2::SnapRestriction snapRes);
@@ -83,11 +87,10 @@ void SetSnapperCoords(Vector, Vector)
 
 for setting the coordinates?
 */
-       protected:
-//             void ShowSnapper(void);
-//             void HideSnapper(void);
-               void SetSnapperVisible(bool visibility = true);
-               void SetSnapperCoords(Vector, Vector);
+       public://for now
+               void SetVisible(bool visibility = true);
+               bool Visible(void);
+               void Draw(GraphicView *, PaintInterface *);
 
        private:
                void xorSnapper();
index 90aa44eca6163c2fe568b91527fe4b94a6281760..d3b39cab24ae487a32cd6b3cd3633798dcdfc91e 100644 (file)
@@ -2174,8 +2174,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.
+       //hm.
+       snapper.setSnapMode(sm);
 }
 
 /**
index 8af908b314e60d84dd8ceedb91d82d48ed4655da..e2d7b5456a39912eaee93d74764e3b3d07960c2c 100644 (file)
@@ -4,6 +4,7 @@
 #include <QtGui>
 #include "rs.h"
 #include "rs_color.h"
+#include "rs_snapper.h"
 #include "vector.h"
 
 class Drawing;
@@ -18,7 +19,6 @@ class RS_Preview;
 class RS_Grid;
 class RS_Pen;
 class RS_EventHandler;
-class QG_ScrollBar;
 
 class GraphicView
 {
@@ -283,6 +283,11 @@ class GraphicView
                //! Last position (for rapid move)
                Vector simulationLast;
 
+       public://for now
+               // We use this here instead of deriving ActionInterface from it because
+               // this makes more sense.
+               RS_Snapper snapper;
+
        protected:
                // crap to make painting with update() possible
                RS_Preview * previewEntity;
@@ -298,11 +303,11 @@ class GraphicView
                int lastWidth;
                int lastHeight;
                //! Horizontal scrollbar.
-               QG_ScrollBar * hScrollBar;
+               QScrollBar * hScrollBar;
                //! Vertical scrollbar.
-               QG_ScrollBar * vScrollBar;
-               //! Layout used to fit in the view and the scrollbars.
-               QGridLayout * layout;
+               QScrollBar * vScrollBar;
+//             //! Layout used to fit in the view and the scrollbars.
+//             QGridLayout * layout;
                //! Label for grid spacing.
                QLabel * gridStatus;
                //! CAD mouse cursor
index ee6cc3fe009cef478b21250225c836f19c9b97a8..d260c3cd6a023a77aca1e1afda96a99cc82e9e95 100644 (file)
@@ -42,6 +42,8 @@ MDIWindow::MDIWindow(RS_Document * doc, QWidget * parent, const char * name/*= N
        id = idCounter++;
        parentWindow = NULL;
 
+//not using this anymore
+#if 0
        if (document)
        {
                if (document->getLayerList())
@@ -52,6 +54,7 @@ MDIWindow::MDIWindow(RS_Document * doc, QWidget * parent, const char * name/*= N
                        // Link the graphic view to the block widget
                        document->getBlockList()->addListener(graphicView);
        }
+#endif
 
 //hm.
        setFocus(/*Qt::StrongFocus*/);
@@ -64,11 +67,13 @@ MDIWindow::MDIWindow(RS_Document * doc, QWidget * parent, const char * name/*= N
  */
 MDIWindow::~MDIWindow()
 {
+#if 0
        if (document->getLayerList())
                document->getLayerList()->removeListener(graphicView);
 
        if (document->getBlockList())
                document->getBlockList()->removeListener(graphicView);
+#endif
 
        if (owner && document)
                delete document;
index e306fa608d12511c0efba712c2e0e8f7f6a82a70..57c826758de613121b8ccf96edab7a95310f6724 100644 (file)
@@ -71,14 +71,14 @@ QG_GraphicView::QG_GraphicView(RS_Document * doc, QWidget * parent)
 void QG_GraphicView::CommonInitialization(void)
 {
        setBackground(background);
-       buffer = NULL;
+//meh  buffer = NULL;
        lastWidth = 0;
        lastHeight = 0;
 //hrm.
 painter = NULL;
 
        RS_DEBUG->print("--> Setting up layout...");
-       layout = new QGridLayout(this);
+       QGridLayout * layout = new QGridLayout(this);
        layout->setColumnStretch(0, 1);
        layout->setColumnStretch(1, 0);
        layout->setColumnStretch(2, 0);
@@ -183,11 +183,11 @@ QG_GraphicView::~QG_GraphicView()
        if (painter)
                delete painter;
 
-       if (buffer)
-       {
-               delete buffer;
-               buffer = NULL;
-       }
+//meh  if (buffer)
+//     {
+//             delete buffer;
+//             buffer = NULL;
+//     }
 
        cleanUp();
 }
@@ -899,6 +899,9 @@ What's needed:
        }
 #endif
 
+       if (snapper.Visible())
+               snapper.Draw(this, painter);
+#if 0
        if (snapperDraw)
 //     if (false)
        {
@@ -912,7 +915,7 @@ What's needed:
 //Actually, it looks like buggy painting code in PaintInterface()...
                        painter->drawCircle(toGui(snapCoord1), 4);
 
-#if 1
+       #if 1
                        // crosshairs:
                        if (showCrosshairs1 == true)
                        {
@@ -922,9 +925,9 @@ What's needed:
                                painter->drawLine(Vector(toGuiX(snapCoord1.x), 0),
                                        Vector(toGuiX(snapCoord1.x), getHeight()));
                        }
-#endif
+       #endif
                }
-#if 1
+       #if 1
                if (snapCoord1.valid && snapCoord1 != snapSpot1)
                {
                        painter->drawLine(toGui(snapSpot1) + Vector(-5, 0), toGui(snapSpot1) + Vector(-1, 4));
@@ -932,8 +935,9 @@ What's needed:
                        painter->drawLine(toGui(snapSpot1) + Vector(5, 0), toGui(snapSpot1) + Vector(1, -4));
                        painter->drawLine(toGui(snapSpot1) + Vector(0, -5), toGui(snapSpot1) + Vector(-4, -1));
                }
-#endif
+       #endif
        }
+#endif
 
        delete painter;
        painter = NULL;
index 04d58a1ca0dc0c0e1e61de6b37018838c55045b7..b870809af51e246809d768aaa13defae1bd895d3 100644 (file)
@@ -5,7 +5,6 @@
 #include "graphicview.h"
 #include "rs_layerlistlistener.h"
 #include "rs_blocklistlistener.h"
-#include "qg_scrollbar.h"
 
 class RS_Document;
 class PaintInterface;
@@ -71,20 +70,19 @@ class QG_GraphicView: public QWidget, public GraphicView//, //public Q3FilePrevi
                void slotHScrolled(int value);
                void slotVScrolled(int value);
 
-       private:
-#warning "!!! Double buffering is not necessary anymore !!!"
-               //! Buffer for double-buffering
-               QPixmap * buffer;
+//     private:
+//#warning "!!! Double buffering is not necessary anymore !!!"
+//             //! Buffer for double-buffering
+//             QPixmap * buffer;
 //             int refCount;
 
+#if 0
        protected:
                int lastWidth;
                int lastHeight;
                //! Horizontal scrollbar.
-//             QG_ScrollBar * hScrollBar;
                QScrollBar * hScrollBar;
                //! Vertical scrollbar.
-//             QG_ScrollBar * vScrollBar;
                QScrollBar * vScrollBar;
                //! Layout used to fit in the view and the scrollbars.
                QGridLayout * layout;
@@ -100,6 +98,7 @@ class QG_GraphicView: public QWidget, public GraphicView//, //public Q3FilePrevi
                QCursor * curMagnifier;
                //! Hand mouse cursor
                QCursor * curHand;
+#endif
 };
 
 #endif