Isis 3.0 Programmer Reference
Back | Home
ControlCubeGraphNode.cpp
1 #include "IsisDebug.h"
2 
3 #include "ControlCubeGraphNode.h"
4 
5 #include <iostream>
6 
7 #include <QHash>
8 #include <QString>
9 
10 #include "ControlMeasure.h"
11 #include "ControlPoint.h"
12 #include "IException.h"
13 #include "IString.h"
14 
15 
16 namespace Isis {
21  nullify();
22 
23  serialNumber = new QString(sn);
26  }
27 
28 
30  nullify();
31 
32  serialNumber = new QString(*other.serialNumber);
35 
36  *measures = *other.measures;
37  }
38 
39 
40  void ControlCubeGraphNode::nullify() {
41  serialNumber = NULL;
42  measures = NULL;
43  connections = NULL;
44  }
45 
46 
51  if (serialNumber) {
52  delete serialNumber;
53  serialNumber = NULL;
54  }
55 
56  if (measures) {
57  delete measures;
58  measures = NULL;
59  }
60 
61  if (connections) {
62  delete connections;
63  connections = NULL;
64  }
65  }
66 
67 
74  return measures->contains(point);
75  }
76 
77 
84  ASSERT(measure);
85 
86  if (measure->GetCubeSerialNumber() != *serialNumber) {
87  QString msg = "Attempted to add Control Measure with Cube Serial Number ";
88  msg += "[" + measure->GetCubeSerialNumber() + "] does not match Serial ";
89  msg += "Number [" + *serialNumber + "]";
91  }
92 
93  measure->associatedCSN = this;
94  ASSERT(!measures->contains(measure->Parent()));
95  (*measures)[measure->Parent()] = measure;
96  }
97 
98 
99  void ControlCubeGraphNode::removeMeasure(ControlMeasure *measure) {
100 
101  if (measures->remove(measure->Parent()) != 1) {
102  ASSERT(0);
103  }
104 
105  measure->associatedCSN = NULL;
106  }
107 
108 
109  void ControlCubeGraphNode::addConnection(ControlCubeGraphNode *node,
110  ControlPoint *point) {
111  ASSERT(node);
112  ASSERT(point);
113 
114  if (connections->contains(node)) {
115  if (!(*connections)[node].contains(point))
116  (*connections)[node].append(point);
117  }
118  else {
119  QList< ControlPoint * > newConnectionList;
120  newConnectionList.append(point);
121  (*connections)[node] = newConnectionList;
122  }
123  }
124 
125 
126  void ControlCubeGraphNode::removeConnection(ControlCubeGraphNode *node,
127  ControlPoint *point) {
128  ASSERT(node);
129  ASSERT(point);
130  ASSERT(connections);
131 
132  if (connections->contains(node)) {
133  if ((*connections)[node].contains(point)) {
134  (*connections)[node].removeOne(point);
135  if (!(*connections)[node].size())
136  connections->remove(node);
137  }
138  }
139  }
140 
141 
142  int ControlCubeGraphNode::getMeasureCount() const {
143  return measures->size();
144  }
145 
146 
147  QString ControlCubeGraphNode::getSerialNumber() const {
148  return *serialNumber;
149  }
150 
151 
152  QList< ControlMeasure * > ControlCubeGraphNode::getMeasures() const {
153  return measures->values();
154  }
155 
156 
157  QList< ControlMeasure * > ControlCubeGraphNode::getValidMeasures() const {
158  QList< ControlMeasure * > validMeasures;
159 
160  QList< ControlMeasure * > measureList = measures->values();
161  foreach(ControlMeasure * measure, measureList) {
162  if (!measure->IsIgnored())
163  validMeasures.append(measure);
164  }
165 
166  return validMeasures;
167  }
168 
169 
170  QList< ControlCubeGraphNode * > ControlCubeGraphNode::getAdjacentNodes() const {
171  return connections->keys();
172  }
173 
174 
175  bool ControlCubeGraphNode::isConnected(ControlCubeGraphNode *other) const {
176  return connections->contains(other);
177  }
178 
179 
180  ControlMeasure *ControlCubeGraphNode::getMeasure(ControlPoint *point) {
181  if (!measures->contains(point)) {
182  QString msg = "point [";
183  msg += (QString) point->GetId();
184  msg += "] not found in the ControlCubeGraphNode";
185  throw IException(IException::Programmer, msg, _FILEINFO_);
186  }
187 
188  return (*measures)[point];
189  }
190 
191 
192  const ControlMeasure *ControlCubeGraphNode::getMeasure(
193  ControlPoint *point) const {
194  if (!measures->contains(point)) {
195  QString msg = "point [";
196  msg += (QString) point->GetId();
197  msg += "] not found in the ControlCubeGraphNode";
198  throw IException(IException::Programmer, msg, _FILEINFO_);
199  }
200 
201  return measures->value(point);
202  }
203 
204 
205  ControlMeasure *ControlCubeGraphNode::operator[](ControlPoint *point) {
206  return getMeasure(point);
207  }
208 
209 
210  const ControlMeasure *ControlCubeGraphNode::operator[](
211  ControlPoint *point) const {
212  return getMeasure(point);
213  }
214 
215 
216  const ControlCubeGraphNode &ControlCubeGraphNode::operator=(
217  ControlCubeGraphNode other) {
218  if (this == &other)
219  return *this;
220 
221  if (serialNumber) {
222  delete serialNumber;
223  serialNumber = NULL;
224  }
225 
226  if (measures) {
227  delete measures;
228  measures = NULL;
229  }
230 
231  if (connections) {
232  delete connections;
233  connections = NULL;
234  }
235 
236  serialNumber = new QString;
239 
240  *serialNumber = *other.serialNumber;
241  *measures = *other.measures;
242  *connections = *other.connections;
243 
244  return *this;
245  }
246 
247 
248  QString ControlCubeGraphNode::connectionsToString() const {
249  QHashIterator< ControlCubeGraphNode *, QList< ControlPoint * > > i(
250  *connections);
251 
252  QStringList serials;
253  while (i.hasNext()) {
254  i.next();
255  QString line = " " + (QString) i.key()->getSerialNumber();
256  line += " : ";
257  for (int j = 0; j < i.value().size(); j++) {
258  line += (QString) i.value()[j]->GetId();
259  if (j != i.value().size() - 1)
260  line += ", ";
261  }
262  serials << line;
263  }
264  qSort(serials);
265 
266  return serials.join("\n");
267  }
268 
269 }
Serial Number with added functionality for Control Networks.
ControlCubeGraphNode * associatedCSN
Pointer to the Serial Number.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
QHash< ControlCubeGraphNode *, QList< ControlPoint * > > * connections
Stores a list of ControlPoints which establish a conection to the ControlCubeGraphNode that the list ...
QHash< ControlPoint *, ControlMeasure * > * measures
ControlMeasures hashed by ControlPoint.
bool contains(ControlPoint *point) const
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:134
void addMeasure(ControlMeasure *measure)
Adds a measure.
A single control point.
Definition: ControlPoint.h:339
Isis exception class.
Definition: IException.h:99
a control measurement
QString GetCubeSerialNumber() const
Return the serial number of the cube containing the coordinate.
virtual ~ControlCubeGraphNode()
Destroy a SerialNumber object.
ControlCubeGraphNode(QString sn)
Create an empty SerialNumber object.

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:16:14