]> Shamusworld >> Repos - architektonas/blobdiff - src/base/grid.cpp
Major refactor of Architektonas: Jettisoning old cruft.
[architektonas] / src / base / grid.cpp
diff --git a/src/base/grid.cpp b/src/base/grid.cpp
deleted file mode 100644 (file)
index bfb9cc8..0000000
+++ /dev/null
@@ -1,460 +0,0 @@
-// grid.cpp
-//
-// Part of the Architektonas Project
-// Originally part of QCad Community Edition by Andrew Mustun
-// Extensively rewritten and refactored by James L. Hammons
-// 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>
-//
-// Who  When        What
-// ---  ----------  -----------------------------------------------------------
-// JLH  05/21/2010  Added this text. :-)
-//
-
-#include "grid.h"
-
-#include "drawing.h"
-#include "graphicview.h"
-#include "settings.h"
-#include "units.h"
-#include "vector.h"
-
-#warning "!!! Clean out all references to RS_GraphicView here and in header !!!"
-/**
- * Constructor.
- */
-Grid::Grid(GraphicView * gv): graphicView(gv), pt(NULL), number(0),
-       metaX(NULL), numMetaX(0), metaY(NULL), numMetaY(0)
-{
-}
-
-/**
- * Destructor.
- */
-Grid::~Grid()
-{
-       if (pt != NULL)
-               delete[] pt;
-
-       if (metaX != NULL)
-               delete[] metaX;
-
-       if (metaY != NULL)
-               delete[] metaY;
-}
-
-/**
- * Updates the grid point array.
- */
-void Grid::update()
-{
-       DEBUG->print("Grid::update");
-
-       if (!graphicView->isGridOn())
-               return;
-
-       Drawing * drawing = graphicView->GetDrawing();
-
-       // auto scale grid?
-       settings.beginGroup("Appearance");
-       bool scaleGrid = settings.value("ScaleGrid", true).toBool();
-       int minGridSpacing = settings.value("MinGridSpacing", 10).toInt();
-       settings.endGroup();
-
-       // get grid setting
-       Vector userGrid;
-
-       if (drawing != NULL)
-               userGrid = drawing->getVariableVector("$GRIDUNIT", Vector(-1.0, -1.0));
-
-       // delete old grid:
-       if (pt != NULL)
-       {
-               delete[] pt;
-               pt = NULL;
-       }
-
-       if (metaX != NULL)
-       {
-               delete[] metaX;
-               metaX = NULL;
-       }
-
-       if (metaY != NULL)
-       {
-               delete[] metaY;
-               metaY = NULL;
-       }
-
-       number = 0;
-       numMetaX = 0;
-       numMetaY = 0;
-
-       DEBUG->print("Grid::update: 001");
-
-       // find out unit:
-       RS2::Unit unit = RS2::None;
-       RS2::LinearFormat format = RS2::Decimal;
-
-       if (drawing != NULL)
-       {
-               unit = drawing->getUnit();
-               format = drawing->getLinearFormat();
-       }
-
-       Vector gridWidth;
-       Vector metaGridWidth;
-
-       DEBUG->print("Grid::update: 002");
-
-       // init grid spacing:
-       // metric grid:
-       if (Units::isMetric(unit) || unit == RS2::None
-               || format == RS2::Decimal || format == RS2::Engineering)
-       {
-               if (userGrid.x > 0.0)
-                       gridWidth.x = userGrid.x;
-               else
-                       gridWidth.x = 0.000001;
-
-               if (userGrid.y > 0.0)
-                       gridWidth.y = userGrid.y;
-               else
-                       gridWidth.y = 0.000001;
-
-               DEBUG->print("Grid::update: 003");
-
-               // auto scale grid
-               if (scaleGrid)
-               {
-                       while (graphicView->toGuiDX(gridWidth.x) < minGridSpacing)
-                               gridWidth.x *= 10;
-
-                       while (graphicView->toGuiDY(gridWidth.y) < minGridSpacing)
-                               gridWidth.y *= 10;
-               }
-
-               metaGridWidth.x = gridWidth.x * 10;
-               metaGridWidth.y = gridWidth.y * 10;
-
-               DEBUG->print("Grid::update: 004");
-       }
-       // imperial grid:
-       else
-       {
-               DEBUG->print("Grid::update: 005");
-
-               if (userGrid.x > 0.0)
-                       gridWidth.x = userGrid.x;
-               else
-                       gridWidth.x = 1.0 / 1024.0;
-
-               if (userGrid.y > 0.0)
-                       gridWidth.y = userGrid.y;
-               else
-                       gridWidth.y = 1.0 / 1024.0;
-
-               DEBUG->print("Grid::update: 006");
-
-               if (unit == RS2::Inch)
-               {
-                       DEBUG->print("Grid::update: 007");
-
-                       // auto scale grid
-                       if (scaleGrid)
-                       {
-                               while (graphicView->toGuiDX(gridWidth.x) < minGridSpacing)
-                               {
-                                       if (Math::round(gridWidth.x) >= 36)
-                                       {
-                                               gridWidth.x *= 2;
-                                       }
-                                       else if (Math::round(gridWidth.x) >= 12)
-                                       {
-                                               gridWidth.x *= 3;
-                                       }
-                                       else if (Math::round(gridWidth.x) >= 4)
-                                       {
-                                               gridWidth.x *= 3;
-                                       }
-                                       else if (Math::round(gridWidth.x) >= 1)
-                                       {
-                                               gridWidth.x *= 2;
-                                       }
-                                       else
-                                       {
-                                               gridWidth.x*=2;
-                                       }
-                               }
-
-                               while (graphicView->toGuiDY(gridWidth.y) < minGridSpacing)
-                               {
-                                       if (Math::round(gridWidth.y) >= 36)
-                                       {
-                                               gridWidth.y *= 2;
-                                       }
-                                       else if (Math::round(gridWidth.y) >= 12)
-                                       {
-                                               gridWidth.y *= 3;
-                                       }
-                                       else if (Math::round(gridWidth.y) >= 4)
-                                       {
-                                               gridWidth.y *= 3;
-                                       }
-                                       else if (Math::round(gridWidth.y) >= 1)
-                                       {
-                                               gridWidth.y *= 2;
-                                       }
-                                       else
-                                       {
-                                               gridWidth.y *= 2;
-                                       }
-                               }
-                       }
-
-                       DEBUG->print("Grid::update: 008");
-
-                       // metagrid X shows inches..
-                       metaGridWidth.x = 1.0;
-
-                       if (graphicView->toGuiDX(metaGridWidth.x) < minGridSpacing * 2)
-                       {
-                               // .. or feet
-                               metaGridWidth.x = 12.0;
-
-                               // .. or yards
-                               if (graphicView->toGuiDX(metaGridWidth.x) < minGridSpacing * 2)
-                               {
-                                       metaGridWidth.x = 36.0;
-
-                                       // .. or miles (not really..)
-                                       //if (graphicView->toGuiDX(metaGridWidth.x)<20) {
-                                       //    metaGridWidth.x = 63360.0;
-                                       //}
-
-                                       // .. or nothing
-                                       if (graphicView->toGuiDX(metaGridWidth.x) < minGridSpacing * 2)
-                                               metaGridWidth.x = -1.0;
-
-                               }
-                       }
-
-                       DEBUG->print("Grid::update: 009");
-
-                       // metagrid Y shows inches..
-                       metaGridWidth.y = 1.0;
-
-                       if (graphicView->toGuiDY(metaGridWidth.y) < minGridSpacing * 2)
-                       {
-                               // .. or feet
-                               metaGridWidth.y = 12.0;
-
-                               // .. or yards
-                               if (graphicView->toGuiDY(metaGridWidth.y) < minGridSpacing * 2)
-                               {
-                                       metaGridWidth.y = 36.0;
-
-                                       // .. or miles (not really..)
-                                       //if (graphicView->toGuiDY(metaGridWidth.y)<20) {
-                                       //    metaGridWidth.y = 63360.0;
-                                       //}
-
-                                       // .. or nothing
-                                       if (graphicView->toGuiDY(metaGridWidth.y) < minGridSpacing * 2)
-                                       {
-                                               metaGridWidth.y = -1.0;
-                                       }
-
-                               }
-                       }
-
-                       DEBUG->print("Grid::update: 010");
-               }
-               else
-               {
-                       DEBUG->print("Grid::update: 011");
-
-                       if (scaleGrid)
-                       {
-                               while (graphicView->toGuiDX(gridWidth.x) < minGridSpacing)
-                               {
-                                       gridWidth.x *= 2;
-                               }
-
-                               metaGridWidth.x = -1.0;
-
-                               while (graphicView->toGuiDY(gridWidth.y) < minGridSpacing)
-                               {
-                                       gridWidth.y *= 2;
-                               }
-
-                               metaGridWidth.y = -1.0;
-                       }
-                       DEBUG->print("Grid::update: 012");
-               }
-               //gridWidth.y = gridWidth.x;
-               //metaGridWidth.y = metaGridWidth.x;
-       }
-
-       DEBUG->print("Grid::update: 013");
-
-       // for grid info:
-       spacing = gridWidth.x;
-       metaSpacing = metaGridWidth.x;
-
-       if (gridWidth.x > 1.0e-6 && gridWidth.y > 1.0e-6
-               && graphicView->toGuiDX(gridWidth.x) > 2
-               && graphicView->toGuiDY(gridWidth.y) > 2)
-       {
-               // find grid boundaries
-               double left = (int)(graphicView->toGraphX(0) / gridWidth.x) * gridWidth.x;
-               double right = (int)(graphicView->toGraphX(graphicView->getWidth())
-                       / gridWidth.x) * gridWidth.x;
-               double top = (int)(graphicView->toGraphY(0) / gridWidth.y) * gridWidth.y;
-               double bottom = (int)(graphicView->toGraphY(graphicView->getHeight())
-                       / gridWidth.y) * gridWidth.y;
-
-               left -= gridWidth.x;
-               right += gridWidth.x;
-               top += gridWidth.y;
-               bottom -= gridWidth.y;
-
-               // calculate number of visible grid points
-               int numberX = (Math::round((right-left) / gridWidth.x) + 1);
-               int numberY = (Math::round((top-bottom) / gridWidth.y) + 1);
-               number = numberX * numberY;
-
-               DEBUG->print("Grid::update: 014");
-
-               // create grid array:
-               if (number > 0 && number < 1000000)
-               {
-                       pt = new Vector[number];
-
-                       int i=0;
-                       for(int y=0; y<numberY; ++y)
-                       {
-                               for(int x=0; x<numberX; ++x)
-                               {
-                                       pt[i++] = Vector(left + x * gridWidth.x, bottom + y * gridWidth.y);
-                               }
-                       }
-               }
-               else
-               {
-                       number = 0;
-                       pt = NULL;
-               }
-
-               DEBUG->print("Grid::update: 015");
-       }
-
-       // find meta grid boundaries
-       if (metaGridWidth.x > 1.0e-6 && metaGridWidth.y > 1.0e-6
-               && graphicView->toGuiDX(metaGridWidth.x) > 2
-               && graphicView->toGuiDY(metaGridWidth.y) > 2)
-       {
-               double mleft = (int)(graphicView->toGraphX(0)
-                       / metaGridWidth.x) * metaGridWidth.x;
-               double mright = (int)(graphicView->toGraphX(graphicView->getWidth())
-                       / metaGridWidth.x) * metaGridWidth.x;
-               double mtop = (int)(graphicView->toGraphY(0)
-                       / metaGridWidth.y) * metaGridWidth.y;
-               double mbottom = (int)(graphicView->toGraphY(graphicView->getHeight())
-                       / metaGridWidth.y) * metaGridWidth.y;
-
-               mleft -= metaGridWidth.x;
-               mright += metaGridWidth.x;
-               mtop += metaGridWidth.y;
-               mbottom -= metaGridWidth.y;
-
-               // calculate number of visible meta grid lines:
-               numMetaX = (Math::round((mright - mleft) / metaGridWidth.x) + 1);
-               numMetaY = (Math::round((mtop - mbottom) / metaGridWidth.y) + 1);
-
-               if (numMetaX > 0 && numMetaY > 0)
-               {
-                       // create meta grid arrays:
-                       metaX = new double[numMetaX];
-                       metaY = new double[numMetaY];
-
-                       int i = 0;
-
-                       for(int x=0; x<numMetaX; ++x)
-                               metaX[i++] = mleft + x * metaGridWidth.x;
-
-                       i = 0;
-
-                       for(int y=0; y<numMetaY; ++y)
-                               metaY[i++] = mbottom + y * metaGridWidth.y;
-               }
-               else
-               {
-                       numMetaX = 0;
-                       metaX = NULL;
-                       numMetaY = 0;
-                       metaY = NULL;
-               }
-       }
-
-       DEBUG->print("Grid::update: OK");
-}
-
-/**
- * @return Array of all visible grid points.
- */
-Vector * Grid::getPoints()
-{
-       return pt;
-}
-
-/**
- * @return Number of visible grid points.
- */
-int Grid::count()
-{
-       return number;
-}
-
-/**
- * @return Grid info for status widget.
- */
-QString Grid::getInfo()
-{
-       return QString("%1 / %2").arg(spacing).arg(metaSpacing);
-}
-
-/**
- * @return Meta grid positions in X.
- */
-double * Grid::getMetaX()
-{
-       return metaX;
-}
-
-/**
- * @return Number of visible meta grid lines in X.
- */
-int Grid::countMetaX()
-{
-       return numMetaX;
-}
-
-/**
-* @return Meta grid positions in Y.
-*/
-double * Grid::getMetaY()
-{
-       return metaY;
-}
-
-/**
-* @return Number of visible meta grid lines in Y.
-*/
-int Grid::countMetaY()
-{
-       return numMetaY;
-}