00001
00002
00003
00004
00005
00006
00007 #include "CallbackGatherXThetaValuesFunctions.h"
00008 #include "CmdMediator.h"
00009 #include "Curve.h"
00010 #include "CurveConnectAs.h"
00011 #include "CurveStyle.h"
00012 #include "EngaugeAssert.h"
00013 #include "GeometryModel.h"
00014 #include "GeometryWindow.h"
00015 #include "Logger.h"
00016 #include "MainWindow.h"
00017 #include <QApplication>
00018 #include <QClipboard>
00019 #include <QItemSelectionModel>
00020 #include <QTextStream>
00021 #include "WindowTable.h"
00022
00023
00024
00025
00026 const QString TokenName (QObject::tr ("CurveName:"));
00027 const QString TokenFunctionArea (QObject::tr ("FunctionArea:"));
00028 const QString TokenPolygonArea (QObject::tr ("PolygonArea:"));
00029 const QString TokenX (QObject::tr ("X"));
00030 const QString TokenY (QObject::tr ("Y"));
00031 const QString TokenIndex (QObject::tr ("Index"));
00032 const QString TokenDistanceGraph (QObject::tr ("Distance"));
00033 const QString TokenDistancePercent (QObject::tr ("Percent"));
00034
00035 GeometryWindow::GeometryWindow (MainWindow *mainWindow) :
00036 WindowAbstractBase (mainWindow)
00037 {
00038 setVisible (false);
00039 setAllowedAreas (Qt::AllDockWidgetAreas);
00040 setWindowTitle (tr ("Geometry Window"));
00041 setStatusTip (tr ("Geometry Window"));
00042 setWhatsThis (tr ("Geometry Window\n\n"
00043 "This table displays the following geometry data for the currently selected curve:\n\n"
00044 "Function area = Area under the curve if it is a function\n\n"
00045 "Polygon area = Area inside the curve if it is a relation. This value is only correct "
00046 "if none of the curve lines intersect each other\n\n"
00047 "X = X coordinate of each point\n\n"
00048 "Y = Y coordinate of each point\n\n"
00049 "Index = Point number\n\n"
00050 "Distance = Distance along the curve in forward or backward direction, in either graph units "
00051 "or as a percentage\n\n"
00052 "If drag-and-drop is disabled, a rectangular set of cells may be selected by clicking and dragging. Otherwise, if "
00053 "drag-and-drop is enabled, a rectangular set of cells may be selected using Click then Shift+Click, since click and drag "
00054 "starts the dragging operation. Drag-and-drop mode is set in the Main Window settings"));
00055
00056 createWidgets (mainWindow);
00057 loadStrategies();
00058 initializeHeader ();
00059 }
00060
00061 GeometryWindow::~GeometryWindow()
00062 {
00063 }
00064
00065 void GeometryWindow::clear ()
00066 {
00067
00068 resizeTable (NUM_HEADER_ROWS);
00069
00070
00071 for (int row = 0; row < NUM_HEADER_ROWS - 1; row++) {
00072 m_model->setItem (row, COLUMN_HEADER_VALUE, new QStandardItem (""));
00073 }
00074 }
00075
00076 void GeometryWindow::closeEvent(QCloseEvent * )
00077 {
00078 LOG4CPP_INFO_S ((*mainCat)) << "GeometryWindow::closeEvent";
00079
00080 emit signalGeometryWindowClosed();
00081 }
00082
00083 int GeometryWindow::columnBodyPointIdentifiers ()
00084 {
00085 return COLUMN_BODY_POINT_IDENTIFIERS;
00086 }
00087
00088 void GeometryWindow::createWidgets (MainWindow *mainWindow)
00089 {
00090 m_model = new GeometryModel;
00091
00092 m_view = new WindowTable (*m_model);
00093 connect (m_view, SIGNAL (signalTableStatusChange ()),
00094 mainWindow, SLOT (slotTableStatusChange ()));
00095
00096 setWidget (m_view);
00097 }
00098
00099 void GeometryWindow::doCopy ()
00100 {
00101 LOG4CPP_INFO_S ((*mainCat)) << "GeometryWindow::doCopy";
00102
00103 QString text = m_model->selectionAsText (m_modelExport.delimiter());
00104
00105 if (!text.isEmpty ()) {
00106
00107
00108 QApplication::clipboard ()->setText (text);
00109
00110 }
00111 }
00112
00113 void GeometryWindow::initializeHeader ()
00114 {
00115 LOG4CPP_INFO_S ((*mainCat)) << "GeometryWindow::initializeHeader";
00116
00117 resizeTable (NUM_HEADER_ROWS);
00118
00119 m_model->setItem (HEADER_ROW_NAME, COLUMN_HEADER_LABEL, new QStandardItem (TokenName));
00120 m_model->setItem (HEADER_ROW_FUNC_AREA, COLUMN_HEADER_LABEL, new QStandardItem (TokenFunctionArea));
00121 m_model->setItem (HEADER_ROW_POLY_AREA, COLUMN_HEADER_LABEL, new QStandardItem (TokenPolygonArea));
00122 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_X, new QStandardItem (TokenX));
00123 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_Y, new QStandardItem (TokenY));
00124 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_INDEX, new QStandardItem (TokenIndex));
00125 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_DISTANCE_GRAPH_FORWARD, new QStandardItem (TokenDistanceGraph));
00126 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_DISTANCE_PERCENT_FORWARD, new QStandardItem (TokenDistancePercent));
00127 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_DISTANCE_GRAPH_BACKWARD, new QStandardItem (TokenDistanceGraph));
00128 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_DISTANCE_PERCENT_BACKWARD, new QStandardItem (TokenDistancePercent));
00129 }
00130
00131 void GeometryWindow::loadStrategies ()
00132 {
00133 LOG4CPP_INFO_S ((*mainCat)) << "GeometryWindow::loadStrategies";
00134 }
00135
00136 void GeometryWindow::resizeTable (int rowCount)
00137 {
00138 LOG4CPP_INFO_S ((*mainCat)) << "GeometryWindow::resizeTable";
00139
00140 unselectAll();
00141
00142 m_model->setRowCount (rowCount);
00143 m_model->setColumnCount (NUM_BODY_COLUMNS);
00144
00145 }
00146
00147 void GeometryWindow::slotPointHoverEnter (QString pointIdentifier)
00148 {
00149 m_model->setCurrentPointIdentifier (pointIdentifier);
00150 }
00151
00152 void GeometryWindow::slotPointHoverLeave (QString )
00153 {
00154 m_model->setCurrentPointIdentifier ("");
00155 }
00156
00157 void GeometryWindow::unselectAll ()
00158 {
00159 QItemSelectionModel *selectionModel = m_view->selectionModel ();
00160
00161 selectionModel->clearSelection ();
00162 }
00163
00164 void GeometryWindow::update (const CmdMediator &cmdMediator,
00165 const MainWindowModel &modelMainWindow,
00166 const QString &curveSelected,
00167 const Transformation &transformation)
00168 {
00169 LOG4CPP_INFO_S ((*mainCat)) << "GeometryWindow::update";
00170
00171
00172 m_modelExport = cmdMediator.document().modelExport();
00173 m_model->setDelimiter (m_modelExport.delimiter());
00174 m_view->setDragEnabled (modelMainWindow.dragDropExport());
00175
00176
00177 const Curve *curve = cmdMediator.document().curveForCurveName (curveSelected);
00178
00179 ENGAUGE_CHECK_PTR (curve);
00180
00181 const Points points = curve->points();
00182
00183 QString funcArea, polyArea;
00184 QVector<QString> x, y, distanceGraphForward, distancePercentForward, distanceGraphBackward, distancePercentBackward;
00185
00186 CurveStyle curveStyle = cmdMediator.document().modelCurveStyles().curveStyle (curveSelected);
00187 m_geometryStrategyContext.calculateGeometry (points,
00188 cmdMediator.document().modelCoords(),
00189 cmdMediator.document().modelGeneral(),
00190 modelMainWindow,
00191 transformation,
00192 curveStyle.lineStyle().curveConnectAs(),
00193 funcArea,
00194 polyArea,
00195 x,
00196 y,
00197 distanceGraphForward,
00198 distancePercentForward,
00199 distanceGraphBackward,
00200 distancePercentBackward);
00201
00202
00203 resizeTable (NUM_HEADER_ROWS + points.count());
00204
00205 m_model->setItem (HEADER_ROW_NAME, COLUMN_HEADER_VALUE, new QStandardItem (curveSelected));
00206 m_model->setItem (HEADER_ROW_FUNC_AREA, COLUMN_HEADER_VALUE, new QStandardItem (funcArea));
00207 m_model->setItem (HEADER_ROW_POLY_AREA, COLUMN_HEADER_VALUE, new QStandardItem (polyArea));
00208
00209 if (transformation.transformIsDefined()) {
00210
00211 int row = NUM_HEADER_ROWS;
00212 int index = 0;
00213 for (; index < points.count(); row++, index++) {
00214
00215 const Point &point = points.at (index);
00216
00217 QPointF posGraph;
00218 transformation.transformScreenToRawGraph (point.posScreen (),
00219 posGraph);
00220
00221 m_model->setItem (row, COLUMN_BODY_X, new QStandardItem (x [index]));
00222 m_model->setItem (row, COLUMN_BODY_Y, new QStandardItem (y [index]));
00223 m_model->setItem (row, COLUMN_BODY_INDEX, new QStandardItem (QString::number (index + 1)));
00224 m_model->setItem (row, COLUMN_BODY_DISTANCE_GRAPH_FORWARD, new QStandardItem (distanceGraphForward [index]));
00225 m_model->setItem (row, COLUMN_BODY_DISTANCE_PERCENT_FORWARD, new QStandardItem (distancePercentForward [index]));
00226 m_model->setItem (row, COLUMN_BODY_DISTANCE_GRAPH_BACKWARD, new QStandardItem (distanceGraphBackward [index]));
00227 m_model->setItem (row, COLUMN_BODY_DISTANCE_PERCENT_BACKWARD, new QStandardItem (distancePercentBackward [index]));
00228 m_model->setItem (row, COLUMN_BODY_POINT_IDENTIFIERS, new QStandardItem (point.identifier()));
00229 }
00230 }
00231
00232
00233 unselectAll ();
00234
00235
00236 m_view->setColumnHidden (COLUMN_BODY_POINT_IDENTIFIERS, true);
00237 }
00238
00239 QTableView *GeometryWindow::view () const
00240 {
00241 return dynamic_cast<QTableView*> (m_view);
00242 }