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 = 100;
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,
00047 double &stopX) const
00048 {
00049 startX = modelGrid.startX();
00050 stopX = modelGrid.stopX();
00051 stepX = modelGrid.stepX();
00052 int countX = modelGrid.countX();
00053
00054 bool needReduction = (countX > modelMainWindow.maximumGridLines());
00055
00056 if (modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR) {
00057
00058
00059 if (!needReduction) {
00060 if (stepX <= 0) {
00061 stepX = 0;
00062 needReduction = true;
00063 } else {
00064 countX = 1.0 + (stopX - startX) / stepX;
00065 needReduction = (countX > modelMainWindow.maximumGridLines());
00066 }
00067 }
00068
00069 if (needReduction) {
00070 stopX = startX + stepX * (modelMainWindow.maximumGridLines() - 1);
00071 }
00072
00073 } else {
00074
00075
00076 if (startX <= 0) {
00077
00078
00079 QRectF boundingRectGraph = documentBounds (document,
00080 transformation);
00081
00082
00083 startX = boundingRectGraph.left ();
00084 }
00085
00086 if (!needReduction) {
00087 if (stepX <= 1) {
00088 stepX = 1;
00089 needReduction = true;
00090 } else {
00091 countX = 1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
00092 needReduction = (countX > modelMainWindow.maximumGridLines());
00093 }
00094 }
00095
00096 if (needReduction) {
00097 stopX = qExp (qLn (startX) + qLn (stepX) * (modelMainWindow.maximumGridLines() - 1));
00098 }
00099 }
00100 }
00101
00102 void GridLineLimiter::limitForYRadius (const Document &document,
00103 const Transformation &transformation,
00104 const DocumentModelCoords &modelCoords,
00105 const MainWindowModel &modelMainWindow,
00106 const DocumentModelGridDisplay &modelGrid,
00107 double &startY,
00108 double &stepY,
00109 double &stopY) const
00110 {
00111 startY = modelGrid.startY();
00112 stopY = modelGrid.stopY();
00113 stepY = modelGrid.stepY();
00114 int countY = modelGrid.countY();
00115
00116 bool needReduction = (countY > modelMainWindow.maximumGridLines());
00117
00118 if (modelCoords.coordScaleYRadius() == COORD_SCALE_LINEAR) {
00119
00120
00121 if (!needReduction) {
00122 if (stepY <= 0) {
00123 stepY = 0;
00124 needReduction = true;
00125 } else {
00126 countY = 1.0 + (stopY - startY) / stepY;
00127 needReduction = (countY > modelMainWindow.maximumGridLines());
00128 }
00129 }
00130
00131 if (needReduction) {
00132 stopY = startY + stepY * (modelMainWindow.maximumGridLines() - 1);
00133 }
00134
00135 } else {
00136
00137
00138 if (startY <= 0) {
00139
00140
00141 QRectF boundingRectGraph = documentBounds (document,
00142 transformation);
00143
00144
00145 startY = boundingRectGraph.top ();
00146 }
00147
00148 if (!needReduction) {
00149 if (stepY <= 1) {
00150 stepY = 1;
00151 needReduction = true;
00152 } else {
00153 countY = 1.0 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
00154 needReduction = (countY > modelMainWindow.maximumGridLines());
00155 }
00156 }
00157
00158 if (needReduction) {
00159 stopY = qExp (qLn (startY) + qLn (stepY) * (modelMainWindow.maximumGridLines() - 1));
00160 }
00161 }
00162 }