00001
00002
00003
00004
00005
00006
00007 #include "CmdAddScale.h"
00008 #include "CmdMediator.h"
00009 #include "CursorFactory.h"
00010 #include "DigitizeStateScale.h"
00011 #include "DigitizeStateContext.h"
00012 #include "DlgEditScale.h"
00013 #include "Document.h"
00014 #include "EngaugeAssert.h"
00015 #include "GraphicsPoint.h"
00016 #include "GraphicsScene.h"
00017 #include "GraphicsView.h"
00018 #include "Logger.h"
00019 #include "MainWindow.h"
00020 #include "PointStyle.h"
00021 #include <QCursor>
00022 #include <QGraphicsLineItem>
00023 #include <QMessageBox>
00024 #include "QtToString.h"
00025 #include "ZValues.h"
00026
00027 DigitizeStateScale::DigitizeStateScale (DigitizeStateContext &context) :
00028 DigitizeStateAbstractBase (context),
00029 m_temporaryPoint0 (0),
00030 m_temporaryPoint1 (0),
00031 m_line (0)
00032 {
00033 }
00034
00035 DigitizeStateScale::~DigitizeStateScale ()
00036 {
00037 }
00038
00039 QString DigitizeStateScale::activeCurve () const
00040 {
00041 return AXIS_CURVE_NAME;
00042 }
00043
00044 void DigitizeStateScale::begin (CmdMediator *cmdMediator,
00045 DigitizeState )
00046 {
00047 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::begin";
00048
00049 setCursor(cmdMediator);
00050 context().setDragMode(QGraphicsView::NoDrag);
00051 context().mainWindow().updateViewsOfSettings(activeCurve ());
00052 }
00053
00054 bool DigitizeStateScale::canPaste (const Transformation & ,
00055 const QSize & ) const
00056 {
00057 return false;
00058 }
00059
00060 QCursor DigitizeStateScale::cursor(CmdMediator *cmdMediator) const
00061 {
00062 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateScale::cursor";
00063
00064 CursorFactory cursorFactory;
00065 QCursor cursor = cursorFactory.generate (cmdMediator->document().modelDigitizeCurve());
00066
00067 return cursor;
00068 }
00069
00070 void DigitizeStateScale::end ()
00071 {
00072 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::end";
00073 }
00074
00075 void DigitizeStateScale::handleContextMenuEventAxis (CmdMediator * ,
00076 const QString &pointIdentifier)
00077 {
00078 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleContextMenuEventAxis "
00079 << " point=" << pointIdentifier.toLatin1 ().data ();
00080 }
00081
00082 void DigitizeStateScale::handleContextMenuEventGraph (CmdMediator * ,
00083 const QStringList &pointIdentifiers)
00084 {
00085 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleContextMenuEventGraph "
00086 << "points=" << pointIdentifiers.join(",").toLatin1 ().data ();
00087 }
00088
00089 void DigitizeStateScale::handleCurveChange(CmdMediator * )
00090 {
00091 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleCurveChange";
00092 }
00093
00094 void DigitizeStateScale::handleKeyPress (CmdMediator * ,
00095 Qt::Key key,
00096 bool )
00097 {
00098 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleKeyPress"
00099 << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
00100 }
00101
00102 void DigitizeStateScale::handleMouseMove (CmdMediator * ,
00103 QPointF posScreen)
00104 {
00105 if (m_temporaryPoint1 != 0) {
00106
00107 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateScale::handleMouseMove"
00108 << " oldPos=" << QPointFToString (m_temporaryPoint1->pos ()).toLatin1().data()
00109 << " newPos=" << QPointFToString (posScreen).toLatin1().data();
00110
00111 m_temporaryPoint1->setPos (posScreen);
00112
00113 updateLineGeometry();
00114 }
00115 }
00116
00117 void DigitizeStateScale::handleMousePress (CmdMediator *cmdMediator,
00118 QPointF posScreen)
00119 {
00120 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleMousePress";
00121
00122 GeometryWindow *NULL_GEOMETRY_WINDOW = 0;
00123
00124
00125 const Curve &curveAxes = cmdMediator->curveAxes();
00126 PointStyle pointStyleAxes = curveAxes.curveStyle().pointStyle();
00127 m_pointIdentifier0 = Point::temporaryPointIdentifier();
00128 m_pointIdentifier1 = m_pointIdentifier0 + "b";
00129 m_temporaryPoint0 = context().mainWindow().scene().createPoint(m_pointIdentifier0,
00130 pointStyleAxes,
00131 posScreen,
00132 NULL_GEOMETRY_WINDOW);
00133 m_temporaryPoint1 = context().mainWindow().scene().createPoint(m_pointIdentifier1,
00134 pointStyleAxes,
00135 posScreen,
00136 NULL_GEOMETRY_WINDOW);
00137
00138
00139
00140
00141
00142 m_temporaryPoint0->setPassive ();
00143 m_temporaryPoint1->setPassive ();
00144
00145 context().mainWindow().scene().addTemporaryScaleBar (m_temporaryPoint0,
00146 m_temporaryPoint1,
00147 m_pointIdentifier0,
00148 m_pointIdentifier1);
00149
00150 m_line = new QGraphicsLineItem;
00151 context().mainWindow().scene().addItem (m_line);
00152 m_line->setPen (QColor (Qt::red));
00153 m_line->setZValue (Z_VALUE_CURVE);
00154 m_line->setVisible (true);
00155
00156 updateLineGeometry ();
00157
00158
00159
00160
00161
00162
00163 }
00164
00165 void DigitizeStateScale::handleMouseRelease (CmdMediator *cmdMediator,
00166 QPointF )
00167 {
00168 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleMouseRelease";
00169
00170 if (context().mainWindow().transformIsDefined()) {
00171
00172 QMessageBox::warning (0,
00173 QObject::tr ("Engauge Digitizer"),
00174 QObject::tr ("The scale bar has been defined, and another is not needed or allowed."));
00175
00176 removeTemporaryPointsAndLine ();
00177
00178 } else {
00179
00180
00181 DlgEditScale *dlg = new DlgEditScale (context ().mainWindow (),
00182 cmdMediator->document().modelCoords(),
00183 cmdMediator->document().modelGeneral(),
00184 context().mainWindow().modelMainWindow());
00185 int rtn = dlg->exec ();
00186
00187 double scaleLength = dlg->scaleLength ();
00188 QPointF posScreen0 = m_temporaryPoint0->pos ();
00189 QPointF posScreen1 = m_temporaryPoint1->pos ();
00190 delete dlg;
00191
00192 removeTemporaryPointsAndLine ();
00193
00194 if (rtn == QDialog::Accepted) {
00195
00196
00197
00198 int nextOrdinal0 = cmdMediator->document().nextOrdinalForCurve(AXIS_CURVE_NAME);
00199 int nextOrdinal1 = nextOrdinal0 + 1;
00200
00201
00202 Document &document = cmdMediator->document ();
00203 QUndoCommand *cmd = new CmdAddScale (context ().mainWindow(),
00204 document,
00205 posScreen0,
00206 posScreen1,
00207 scaleLength,
00208 nextOrdinal0,
00209 nextOrdinal1);
00210 context().appendNewCmd(cmdMediator,
00211 cmd);
00212 }
00213 }
00214 }
00215
00216 void DigitizeStateScale::removeTemporaryPointsAndLine ()
00217 {
00218 context().mainWindow().scene().removePoint (m_pointIdentifier0);
00219 context().mainWindow().scene().removePoint (m_pointIdentifier1);
00220 context().mainWindow().scene().removeItem (m_line);
00221 delete m_line;
00222 m_temporaryPoint0 = 0;
00223 m_temporaryPoint1 = 0;
00224 m_line = 0;
00225 }
00226
00227 QString DigitizeStateScale::state() const
00228 {
00229 return "DigitizeStateScale";
00230 }
00231
00232 void DigitizeStateScale::updateAfterPointAddition ()
00233 {
00234 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateAfterPointAddition";
00235 }
00236
00237 void DigitizeStateScale::updateLineGeometry ()
00238 {
00239 m_line->setLine (m_temporaryPoint0->pos ().x (),
00240 m_temporaryPoint0->pos ().y (),
00241 m_temporaryPoint1->pos ().x (),
00242 m_temporaryPoint1->pos ().y ());
00243 }
00244
00245 void DigitizeStateScale::updateModelDigitizeCurve (CmdMediator *cmdMediator,
00246 const DocumentModelDigitizeCurve & )
00247 {
00248 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateModelDigitizeCurve";
00249
00250 setCursor(cmdMediator);
00251 }
00252
00253 void DigitizeStateScale::updateModelSegments(const DocumentModelSegments & )
00254 {
00255 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateModelSegments";
00256 }