Isis 3.0 Programmer Reference
Back | Home
IpceTool.cpp
1 #include "IpceTool.h"
2 
3 #include <sstream>
4 #include <vector>
5 #include <iomanip>
6 
7 #include <QBrush>
8 #include <QDebug>
9 #include <QList>
10 #include <QMessageBox>
11 #include <QPainter>
12 #include <QPen>
13 #include <QPoint>
14 #include <QString>
15 
16 #include "Application.h"
17 #include "ControlMeasure.h"
18 #include "ControlNet.h"
19 #include "ControlPoint.h"
20 #include "CubeDnView.h"
21 #include "Directory.h"
22 #include "IException.h"
23 #include "MdiCubeViewport.h"
24 #include "Project.h"
25 #include "SerialNumber.h"
26 #include "ToolPad.h"
27 #include "UniversalGroundMap.h"
28 #include "ViewportMainWindow.h"
29 #include "Workspace.h"
30 
31 using namespace std;
32 
33 namespace Isis {
44  IpceTool::IpceTool (Directory *directory, QWidget *parent) : Tool(parent) {
45 
46  m_directory = directory;
47  m_view = qobject_cast<CubeDnView *>(parent);
48  }
49 
50 
51  IpceTool::~IpceTool () {
52  }
53 
54 
64  QAction *action = new QAction(pad);
65  action->setIcon(QPixmap(toolIconDir()+"/stock_draw-connector-with-arrows.png"));
66  action->setToolTip("Control Point Editor (T)");
67  action->setShortcut(Qt::Key_T);
68 // QObject::connect(action,SIGNAL(triggered(bool)),this,SLOT(showNavWindow(bool)));
69  return action;
70  }
71 
72 
73  void IpceTool::setControlNet(ControlNet *cnet) {
74  m_controlNet = cnet;
75  refresh();
76  }
77 
78 
89  void IpceTool::mouseButtonRelease(QPoint p, Qt::MouseButton s) {
91  if (cvp == NULL) return;
92 
93  // Determine if the cvp is a Shape
94  // Get all ShapeLists from Project
95  bool isGroundSource = m_view->viewportContainsShape(cvp);
96 
97  double samp,line;
98  cvp->viewportToCube(p.x(),p.y(),samp,line);
99  QString sn = SerialNumber::Compose(cvp->cube()->fileName());
100 
101  if (s == Qt::LeftButton) {
102 
103 // if (sn == m_groundSN) {
104 // QString message = "Cannot select point for editing on ground source. Select ";
105 // message += "point using un-projected images or the Navigator Window.";
106 // QMessageBox::critical(m_ipceTool, "Error", message);
107 // return;
108 // }
109 
110  // Find closest control point in network
111  // since we are in a connected slot, we need to handle exceptions thrown by FindClosest
112  try {
113  ControlPoint *point = m_controlNet->FindClosest(sn, samp, line);
114  emit modifyControlPoint(point);
115  }
116  catch (IException &ie) {
117  QString message = "No points exist for editing. Create points using the right mouse";
118  message += " button.";
119  QMessageBox::warning(m_ipceTool, "Warning", message);
120  return;
121  }
122  }
123 
124  else if (s == Qt::MidButton) {
125 
126  if (!m_controlNet || m_controlNet->GetNumPoints() == 0) {
127  QString message = "No points exist for deleting. Create points ";
128  message += "using the right mouse button.";
129  QMessageBox::warning(m_ipceTool, "Warning", message);
130  return;
131  }
132 
133 // if (m_groundOpen && file == m_groundCube->fileName()) {
134 // QString message = "Cannot select point for deleting on ground source. Select ";
135 // message += "point using un-projected images or the Navigator Window.";
136 // QMessageBox::critical(m_ipceTool, "Error", message);
137 // return;
138 // }
139 
140  // Find closest control point in network
141  ControlPoint *point = NULL;
142  try {
143  point = m_controlNet->FindClosest(sn, samp, line);
144 
145  if (point == NULL) {
146  QString message = "No points exist for deleting. Create points ";
147  message += "using the right mouse button.";
148  QMessageBox::warning(m_ipceTool, "Warning", message);
149  return;
150  }
151  }
152  catch (IException &e) {
153  QString message = "Cannot find point on this image for deleting.";
154  QMessageBox::critical(m_ipceTool, "Error", message);
155  return;
156  }
157 
158  emit deleteControlPoint(point);
159  }
160  else if (s == Qt::RightButton) {
161 
162  UniversalGroundMap *gmap = cvp->universalGroundMap();
163  if (!gmap->SetImage(samp,line)) {
164  QString message = "Invalid latitude or longitude at this point. ";
165  QMessageBox::critical(NULL, "Error", message);
166  return;
167  }
168  double lat = gmap->UniversalLatitude();
169  double lon = gmap->UniversalLongitude();
170 // qDebug()<<"IpceTool::mouseButton lat = "<<lat<<" lon = "<<lon;
171  emit createControlPoint(lat, lon, cvp->cube(), isGroundSource);
172 // if (m_groundOpen && file == m_groundCube->fileName()) {
173 // createFixedPoint (lat,lon);
174 // }
175 // else {
176 // createPoint(lat,lon);
177 // }
178  }
179  }
180 
181 
182  void IpceTool::paintViewport(MdiCubeViewport *vp, QPainter *painter) {
183 // qDebug()<<"IpceTool::paintViewport";
184  if (m_controlNet) {
185  drawAllMeasurements(vp, painter);
186  }
187  }
188 
189 
203  void IpceTool::paintAllViewports(QString pointId) {
204 // qDebug()<<"IpceTool::paintAllViewports";
205 
206  // Take care of drawing things on all viewPorts.
207  // Calling update will cause the Tool class to call all registered tools
208  // if point has been deleted, this will remove it from the main window
209  MdiCubeViewport *vp;
210  for (int i=0; i<(int)cubeViewportList()->size(); i++) {
211  vp = (*(cubeViewportList()))[i];
212  vp->viewport()->update();
213  }
214  }
215 
238  void IpceTool::drawAllMeasurements(MdiCubeViewport *vp, QPainter *painter) {
239 // qDebug()<<"IpceTool::drawAllMeasurements m_controlNet = "<<m_controlNet<<" # points = "<<m_controlNet->GetNumPoints();
240  // Without a controlnetwork there are no points, or if new net, no points
241  if (m_controlNet == 0 || m_controlNet->GetNumPoints() == 0) return;
242 
243  // Don't show the measurments on cubes not in the serial number list
244  // TODO: Should we show them anyway
245  // TODO: Should we add the SN to the viewPort
246  QString serialNumber = SerialNumber::Compose(*vp->cube(), true);
247 
248 // if (serialNumber == m_groundSN) {
249 // drawGroundMeasures(vp, painter);
250 // return;
251 // }
252  if (!m_controlNet->GetCubeSerials().contains(
253  serialNumber)) return;
254 // if (!m_serialNumberList->hasSerialNumber(serialNumber)) return;
255  QList<ControlMeasure *> measures =
256  m_controlNet->GetMeasuresInCube(serialNumber);
257  // loop through all measures contained in this cube
258  for (int i = 0; i < measures.count(); i++) {
259  ControlMeasure *m = measures[i];
260  // Find the measurments on the viewport
261  double samp = m->GetSample();
262  double line = m->GetLine();
263  int x, y;
264  vp->cubeToViewport(samp, line, x, y);
265  // if the point is ignored,
266  if (m->Parent()->IsIgnored()) {
267  painter->setPen(QColor(255, 255, 0)); // set point marker yellow
268  }
269  // point is not ignored, but measure matching this image is ignored,
270  else if (m->IsIgnored()) {
271  painter->setPen(QColor(255, 255, 0)); // set point marker yellow
272  }
273  // Neither point nor measure is not ignored and the measure is fixed,
274  else if (m->Parent()->GetType() != ControlPoint::Free) {
275  painter->setPen(Qt::magenta);// set point marker magenta
276  }
277  else {
278  painter->setPen(Qt::green); // set all other point markers green
279  }
280  // draw points
281  painter->drawLine(x - 5, y, x + 5, y);
282  painter->drawLine(x, y - 5, x, y + 5);
283  }
284 // // if IpceTool is open,
285 // if (m_editPoint != NULL) {
286 // // and the selected point is in the image,
287 // if (m_editPoint->HasSerialNumber(serialNumber)) {
288 // // find the measurement
289 // double samp = (*m_editPoint)[serialNumber]->GetSample();
290 // double line = (*m_editPoint)[serialNumber]->GetLine();
291 // int x, y;
292 // vp->cubeToViewport(samp, line, x, y);
293 // // set point marker red
294 // QBrush brush(Qt::red);
295 // // set point marker bold - line width 2
296 // QPen pen(brush, 2);
297 // // draw the selected point in each image last so it's on top of the rest of the points
298 // painter->setPen(pen);
299 // painter->drawLine(x - 5, y, x + 5, y);
300 // painter->drawLine(x, y - 5, x, y + 5);
301 // }
302 // }
303  }
304 
305 
322 // qDebug()<<"IpceTool::refresh control net = "<<m_controlNet;
323 // if (m_editPoint == NULL) {
324 // paintAllViewports("");
325 // }
326 // else {
327 // paintAllViewports(m_editPoint->GetId());
328 // }
329  }
330 }
331 
Cube display widget for certain Isis MDI applications.
PointType GetType() const
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition: Tool.cpp:390
UniversalGroundMap * universalGroundMap() const
Return the universal ground map associated with the cube (NULL implies none)
Definition: CubeViewport.h:243
Universal Ground Map.
$Date$ $Revision$
void refresh()
Refresh all necessary widgets in IpceTool including the PointEditor and CubeViewports.
Definition: IpceTool.cpp:321
void paintViewport(MdiCubeViewport *cvp, QPainter *painter)
Definition: IpceTool.cpp:182
double UniversalLatitude() const
Returns the universal latitude of the camera model or projection.
void mouseButtonRelease(QPoint p, Qt::MouseButton s)
Handle mouse events on CubeViewport.
Definition: IpceTool.cpp:89
A Free point is a Control Point that identifies common measurements between two or more cubes...
Definition: ControlPoint.h:369
static QString Compose(Pvl &label, bool def2filename=false)
Compose a SerialNumber from a PVL.
void paintAllViewports(QString pointId)
This method will repaint the given Point ID in each viewport Note: The pointId parameter is here even...
Definition: IpceTool.cpp:203
QAction * toolPadAction(ToolPad *pad)
Adds the Ipce tool action to the tool pad.
Definition: IpceTool.cpp:63
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition: Tool.h:211
Cube * cube() const
Return the cube associated with viewport.
Definition: CubeViewport.h:228
a control network
Definition: ControlNet.h:207
double UniversalLongitude() const
Returns the universal longitude of the camera model or projection.
A single control point.
Definition: ControlPoint.h:339
void viewportToCube(int x, int y, double &sample, double &line) const
Convert a viewport x/y to a cube sample/line (may be outside the cube)
bool SetImage(double sample, double line)
Returns whether the sample/line postion was set successfully in the camera model or projection...
void drawAllMeasurements(MdiCubeViewport *vp, QPainter *painter)
Draw all measurments which are on this viewPort.
Definition: IpceTool.cpp:238
View that displays cubes in a QView-like way.
Definition: CubeDnView.h:74
void cubeToViewport(double sample, double line, int &x, int &y) const
Convert a cube sample/line to a viewport x/y (may be outside the viewport)
Isis exception class.
Definition: IException.h:99
QString toolIconDir() const
returns the path to the icon directory.
Definition: Tool.h:127
Base class for the Qisis tools.
Definition: Tool.h:81
a control measurement
QString fileName() const
Returns the opened cube&#39;s filename.
Definition: Cube.cpp:1160

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:20:44