00001
00002
00003
00004
00005
00006
00007 #include "CallbackBoundingRects.h"
00008 #include "Document.h"
00009 #include "DocumentModelCoords.h"
00010 #include "DocumentModelGridDisplay.h"
00011 #include "DocumentModelGridRemoval.h"
00012 #include "GridLineLimiter.h"
00013 #include "MainWindowModel.h"
00014 #include <qmath.h>
00015 #include "Transformation.h"
00016
00017 const int DEFAULT_MAXIMUM_GRID_LINES = 25;
00018
00019 GridLineLimiter::GridLineLimiter ()
00020 {
00021 }
00022
00023 QRectF GridLineLimiter::documentBounds (const Document &document,
00024 const Transformation &transformation) const
00025 {
00026
00027 CallbackBoundingRects ftor (transformation);
00028
00029 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00030 &CallbackBoundingRects::callback);
00031 document.iterateThroughCurvePointsAxes (ftorWithCallback);
00032 document.iterateThroughCurvesPointsGraphs (ftorWithCallback);
00033
00034 bool isEmpty;
00035 QRectF boundingRectGraph = ftor.boundingRectGraph(isEmpty);
00036
00037 return boundingRectGraph;
00038 }
00039
00040 void GridLineLimiter::limitForXTheta (const Document &document,
00041 const Transformation &transformation,
00042 const DocumentModelCoords &modelCoords,
00043 const MainWindowModel &modelMainWindow,
00044 const DocumentModelGridDisplay &modelGrid,
00045 double &startX,
00046 double &stepX) const
00047 {
00048 startX = modelGrid.startX();
00049 double stopX = modelGrid.stopX();
00050 stepX = modelGrid.stepX();
00051
00052 if (modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR) {
00053
00054
00055 bool needNewStep = (stepX <= 0);
00056 if (!needNewStep) {
00057 double count = 1.0 + (stopX - startX) / stepX;
00058 needNewStep = ((int) count > modelMainWindow.maximumGridLines());
00059 }
00060
00061 if (needNewStep) {
00062
00063
00064 stepX = (stopX - startX) / (modelMainWindow.maximumGridLines() - 1);
00065
00066 }
00067
00068 } else {
00069
00070
00071 if (startX <= 0) {
00072
00073
00074 QRectF boundingRectGraph = documentBounds (document,
00075 transformation);
00076
00077
00078 startX = boundingRectGraph.left ();
00079 }
00080
00081 bool needNewStep = (stepX <= 1);
00082 if (!needNewStep) {
00083 double count = 1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
00084 needNewStep = ((int) count > modelMainWindow.maximumGridLines());
00085 }
00086
00087 if (needNewStep) {
00088
00089
00090 stepX = qExp ((qLn (stopX) - qLn (startX)) / (modelMainWindow.maximumGridLines() - 1));
00091
00092 }
00093 }
00094 }
00095
00096 void GridLineLimiter::limitForYRadius (const Document &document,
00097 const Transformation &transformation,
00098 const DocumentModelCoords &modelCoords,
00099 const MainWindowModel &modelMainWindow,
00100 const DocumentModelGridDisplay &modelGrid,
00101 double &startY,
00102 double &stepY) const
00103 {
00104 startY = modelGrid.startY();
00105 double stopY = modelGrid.stopY();
00106 stepY = modelGrid.stepY();
00107
00108 if (modelCoords.coordScaleYRadius() == COORD_SCALE_LINEAR) {
00109
00110
00111 bool needNewStep = (stepY <= 0);
00112 if (!needNewStep) {
00113 double count = 1.0 + (stopY - startY) / stepY;
00114 needNewStep = ((int) count > modelMainWindow.maximumGridLines());
00115 }
00116
00117 if (needNewStep) {
00118
00119
00120 stepY = (stopY - startY) / (modelMainWindow.maximumGridLines() - 1);
00121
00122 }
00123
00124 } else {
00125
00126
00127 if (startY <= 0) {
00128
00129
00130 QRectF boundingRectGraph = documentBounds (document,
00131 transformation);
00132
00133
00134 startY = boundingRectGraph.top ();
00135 }
00136
00137 bool needNewStep = (stepY <= 1);
00138 if (!needNewStep) {
00139 double count = 1.0 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
00140 needNewStep = ((int) count > modelMainWindow.maximumGridLines());
00141 }
00142
00143 if (needNewStep) {
00144
00145
00146 stepY = qExp ((qLn (stopY) - qLn (startY)) / (modelMainWindow.maximumGridLines() - 1));
00147
00148 }
00149 }
00150 }