1 /*
2  *
3  *  Copyright (C) 2008-2012, OFFIS e.V. and ICSMED AG, Oldenburg, Germany
4  *  Copyright (C) 2013-2017, J. Riesmeier, Oldenburg, Germany
5  *  All rights reserved.  See COPYRIGHT file for details.
6  *
7  *  Source file for class DRTExposureSequence
8  *
9  *  Generated automatically from DICOM PS 3.3-2017e
10  *  File created on 2017-12-05 09:30:54
11  *
12  */
13 
14 
15 #include "dcmtk/config/osconfig.h"     // make sure OS specific configuration is included first
16 
17 #include "dcmtk/dcmrt/seq/drtes.h"
18 
19 
20 // --- item class ---
21 
Item(const OFBool emptyDefaultItem)22 DRTExposureSequence::Item::Item(const OFBool emptyDefaultItem)
23   : EmptyDefaultItem(emptyDefaultItem),
24     ApplicatorSequence(emptyDefaultItem /*emptyDefaultSequence*/),
25     BeamLimitingDeviceAngle(DCM_BeamLimitingDeviceAngle),
26     BeamLimitingDeviceSequence(emptyDefaultItem /*emptyDefaultSequence*/),
27     BlockSequence(emptyDefaultItem /*emptyDefaultSequence*/),
28     DiaphragmPosition(DCM_DiaphragmPosition),
29     ExposureTime(DCM_ExposureTime),
30     ExposureTimeInms(DCM_ExposureTimeInms),
31     GantryAngle(DCM_GantryAngle),
32     GantryPitchAngle(DCM_GantryPitchAngle),
33     GeneralAccessorySequence(emptyDefaultItem /*emptyDefaultSequence*/),
34     KVP(DCM_KVP),
35     MetersetExposure(DCM_MetersetExposure),
36     NumberOfBlocks(DCM_NumberOfBlocks),
37     PatientSupportAngle(DCM_PatientSupportAngle),
38     PrimaryFluenceModeSequence(emptyDefaultItem /*emptyDefaultSequence*/),
39     ReferencedFrameNumber(DCM_ReferencedFrameNumber),
40     TableTopLateralPosition(DCM_TableTopLateralPosition),
41     TableTopLongitudinalPosition(DCM_TableTopLongitudinalPosition),
42     TableTopPitchAngle(DCM_TableTopPitchAngle),
43     TableTopRollAngle(DCM_TableTopRollAngle),
44     TableTopVerticalPosition(DCM_TableTopVerticalPosition),
45     XRayTubeCurrent(DCM_XRayTubeCurrent),
46     XRayTubeCurrentInmA(DCM_XRayTubeCurrentInmA)
47 {
48 }
49 
50 
Item(const Item & copy)51 DRTExposureSequence::Item::Item(const Item &copy)
52   : EmptyDefaultItem(copy.EmptyDefaultItem),
53     ApplicatorSequence(copy.ApplicatorSequence),
54     BeamLimitingDeviceAngle(copy.BeamLimitingDeviceAngle),
55     BeamLimitingDeviceSequence(copy.BeamLimitingDeviceSequence),
56     BlockSequence(copy.BlockSequence),
57     DiaphragmPosition(copy.DiaphragmPosition),
58     ExposureTime(copy.ExposureTime),
59     ExposureTimeInms(copy.ExposureTimeInms),
60     GantryAngle(copy.GantryAngle),
61     GantryPitchAngle(copy.GantryPitchAngle),
62     GeneralAccessorySequence(copy.GeneralAccessorySequence),
63     KVP(copy.KVP),
64     MetersetExposure(copy.MetersetExposure),
65     NumberOfBlocks(copy.NumberOfBlocks),
66     PatientSupportAngle(copy.PatientSupportAngle),
67     PrimaryFluenceModeSequence(copy.PrimaryFluenceModeSequence),
68     ReferencedFrameNumber(copy.ReferencedFrameNumber),
69     TableTopLateralPosition(copy.TableTopLateralPosition),
70     TableTopLongitudinalPosition(copy.TableTopLongitudinalPosition),
71     TableTopPitchAngle(copy.TableTopPitchAngle),
72     TableTopRollAngle(copy.TableTopRollAngle),
73     TableTopVerticalPosition(copy.TableTopVerticalPosition),
74     XRayTubeCurrent(copy.XRayTubeCurrent),
75     XRayTubeCurrentInmA(copy.XRayTubeCurrentInmA)
76 {
77 }
78 
79 
~Item()80 DRTExposureSequence::Item::~Item()
81 {
82 }
83 
84 
operator =(const Item & copy)85 DRTExposureSequence::Item &DRTExposureSequence::Item::operator=(const Item &copy)
86 {
87     if (this != &copy)
88     {
89         EmptyDefaultItem = copy.EmptyDefaultItem;
90         ApplicatorSequence = copy.ApplicatorSequence;
91         BeamLimitingDeviceAngle = copy.BeamLimitingDeviceAngle;
92         BeamLimitingDeviceSequence = copy.BeamLimitingDeviceSequence;
93         BlockSequence = copy.BlockSequence;
94         DiaphragmPosition = copy.DiaphragmPosition;
95         ExposureTime = copy.ExposureTime;
96         ExposureTimeInms = copy.ExposureTimeInms;
97         GantryAngle = copy.GantryAngle;
98         GantryPitchAngle = copy.GantryPitchAngle;
99         GeneralAccessorySequence = copy.GeneralAccessorySequence;
100         KVP = copy.KVP;
101         MetersetExposure = copy.MetersetExposure;
102         NumberOfBlocks = copy.NumberOfBlocks;
103         PatientSupportAngle = copy.PatientSupportAngle;
104         PrimaryFluenceModeSequence = copy.PrimaryFluenceModeSequence;
105         ReferencedFrameNumber = copy.ReferencedFrameNumber;
106         TableTopLateralPosition = copy.TableTopLateralPosition;
107         TableTopLongitudinalPosition = copy.TableTopLongitudinalPosition;
108         TableTopPitchAngle = copy.TableTopPitchAngle;
109         TableTopRollAngle = copy.TableTopRollAngle;
110         TableTopVerticalPosition = copy.TableTopVerticalPosition;
111         XRayTubeCurrent = copy.XRayTubeCurrent;
112         XRayTubeCurrentInmA = copy.XRayTubeCurrentInmA;
113     }
114     return *this;
115 }
116 
117 
clear()118 void DRTExposureSequence::Item::clear()
119 {
120     if (!EmptyDefaultItem)
121     {
122         /* clear all DICOM attributes */
123         ReferencedFrameNumber.clear();
124         KVP.clear();
125         PrimaryFluenceModeSequence.clear();
126         XRayTubeCurrent.clear();
127         XRayTubeCurrentInmA.clear();
128         ExposureTime.clear();
129         ExposureTimeInms.clear();
130         MetersetExposure.clear();
131         DiaphragmPosition.clear();
132         BeamLimitingDeviceSequence.clear();
133         GantryAngle.clear();
134         GantryPitchAngle.clear();
135         BeamLimitingDeviceAngle.clear();
136         PatientSupportAngle.clear();
137         TableTopPitchAngle.clear();
138         TableTopRollAngle.clear();
139         TableTopVerticalPosition.clear();
140         TableTopLongitudinalPosition.clear();
141         TableTopLateralPosition.clear();
142         ApplicatorSequence.clear();
143         GeneralAccessorySequence.clear();
144         NumberOfBlocks.clear();
145         BlockSequence.clear();
146     }
147 }
148 
149 
isEmpty()150 OFBool DRTExposureSequence::Item::isEmpty()
151 {
152     return ReferencedFrameNumber.isEmpty() &&
153            KVP.isEmpty() &&
154            PrimaryFluenceModeSequence.isEmpty() &&
155            XRayTubeCurrent.isEmpty() &&
156            XRayTubeCurrentInmA.isEmpty() &&
157            ExposureTime.isEmpty() &&
158            ExposureTimeInms.isEmpty() &&
159            MetersetExposure.isEmpty() &&
160            DiaphragmPosition.isEmpty() &&
161            BeamLimitingDeviceSequence.isEmpty() &&
162            GantryAngle.isEmpty() &&
163            GantryPitchAngle.isEmpty() &&
164            BeamLimitingDeviceAngle.isEmpty() &&
165            PatientSupportAngle.isEmpty() &&
166            TableTopPitchAngle.isEmpty() &&
167            TableTopRollAngle.isEmpty() &&
168            TableTopVerticalPosition.isEmpty() &&
169            TableTopLongitudinalPosition.isEmpty() &&
170            TableTopLateralPosition.isEmpty() &&
171            ApplicatorSequence.isEmpty() &&
172            GeneralAccessorySequence.isEmpty() &&
173            NumberOfBlocks.isEmpty() &&
174            BlockSequence.isEmpty();
175 }
176 
177 
isValid() const178 OFBool DRTExposureSequence::Item::isValid() const
179 {
180     return !EmptyDefaultItem;
181 }
182 
183 
read(DcmItem & item)184 OFCondition DRTExposureSequence::Item::read(DcmItem &item)
185 {
186     OFCondition result = EC_IllegalCall;
187     if (!EmptyDefaultItem)
188     {
189         /* re-initialize object */
190         clear();
191         getAndCheckElementFromDataset(item, ReferencedFrameNumber, "1-n", "1C", "ExposureSequence");
192         getAndCheckElementFromDataset(item, KVP, "1", "2C", "ExposureSequence");
193         PrimaryFluenceModeSequence.read(item, "1-n", "3", "ExposureSequence");
194         getAndCheckElementFromDataset(item, XRayTubeCurrent, "1", "2C", "ExposureSequence");
195         getAndCheckElementFromDataset(item, XRayTubeCurrentInmA, "1", "3", "ExposureSequence");
196         getAndCheckElementFromDataset(item, ExposureTime, "1", "2C", "ExposureSequence");
197         getAndCheckElementFromDataset(item, ExposureTimeInms, "1", "3", "ExposureSequence");
198         getAndCheckElementFromDataset(item, MetersetExposure, "1", "2C", "ExposureSequence");
199         getAndCheckElementFromDataset(item, DiaphragmPosition, "4", "3", "ExposureSequence");
200         BeamLimitingDeviceSequence.read(item, "1-n", "3", "ExposureSequence");
201         getAndCheckElementFromDataset(item, GantryAngle, "1", "3", "ExposureSequence");
202         getAndCheckElementFromDataset(item, GantryPitchAngle, "1", "3", "ExposureSequence");
203         getAndCheckElementFromDataset(item, BeamLimitingDeviceAngle, "1", "3", "ExposureSequence");
204         getAndCheckElementFromDataset(item, PatientSupportAngle, "1", "3", "ExposureSequence");
205         getAndCheckElementFromDataset(item, TableTopPitchAngle, "1", "3", "ExposureSequence");
206         getAndCheckElementFromDataset(item, TableTopRollAngle, "1", "3", "ExposureSequence");
207         getAndCheckElementFromDataset(item, TableTopVerticalPosition, "1", "3", "ExposureSequence");
208         getAndCheckElementFromDataset(item, TableTopLongitudinalPosition, "1", "3", "ExposureSequence");
209         getAndCheckElementFromDataset(item, TableTopLateralPosition, "1", "3", "ExposureSequence");
210         ApplicatorSequence.read(item, "1-n", "3", "ExposureSequence");
211         GeneralAccessorySequence.read(item, "1-n", "3", "ExposureSequence");
212         getAndCheckElementFromDataset(item, NumberOfBlocks, "1", "1", "ExposureSequence");
213         BlockSequence.read(item, "1-n", "2C", "ExposureSequence");
214         result = EC_Normal;
215     }
216     return result;
217 }
218 
219 
write(DcmItem & item)220 OFCondition DRTExposureSequence::Item::write(DcmItem &item)
221 {
222     OFCondition result = EC_IllegalCall;
223     if (!EmptyDefaultItem)
224     {
225         result = EC_Normal;
226         addElementToDataset(result, item, new DcmIntegerString(ReferencedFrameNumber), "1-n", "1C", "ExposureSequence");
227         addElementToDataset(result, item, new DcmDecimalString(KVP), "1", "2C", "ExposureSequence");
228         if (result.good()) result = PrimaryFluenceModeSequence.write(item, "1-n", "3", "ExposureSequence");
229         addElementToDataset(result, item, new DcmIntegerString(XRayTubeCurrent), "1", "2C", "ExposureSequence");
230         addElementToDataset(result, item, new DcmFloatingPointDouble(XRayTubeCurrentInmA), "1", "3", "ExposureSequence");
231         addElementToDataset(result, item, new DcmIntegerString(ExposureTime), "1", "2C", "ExposureSequence");
232         addElementToDataset(result, item, new DcmFloatingPointDouble(ExposureTimeInms), "1", "3", "ExposureSequence");
233         addElementToDataset(result, item, new DcmDecimalString(MetersetExposure), "1", "2C", "ExposureSequence");
234         addElementToDataset(result, item, new DcmDecimalString(DiaphragmPosition), "4", "3", "ExposureSequence");
235         if (result.good()) result = BeamLimitingDeviceSequence.write(item, "1-n", "3", "ExposureSequence");
236         addElementToDataset(result, item, new DcmDecimalString(GantryAngle), "1", "3", "ExposureSequence");
237         addElementToDataset(result, item, new DcmFloatingPointSingle(GantryPitchAngle), "1", "3", "ExposureSequence");
238         addElementToDataset(result, item, new DcmDecimalString(BeamLimitingDeviceAngle), "1", "3", "ExposureSequence");
239         addElementToDataset(result, item, new DcmDecimalString(PatientSupportAngle), "1", "3", "ExposureSequence");
240         addElementToDataset(result, item, new DcmFloatingPointSingle(TableTopPitchAngle), "1", "3", "ExposureSequence");
241         addElementToDataset(result, item, new DcmFloatingPointSingle(TableTopRollAngle), "1", "3", "ExposureSequence");
242         addElementToDataset(result, item, new DcmDecimalString(TableTopVerticalPosition), "1", "3", "ExposureSequence");
243         addElementToDataset(result, item, new DcmDecimalString(TableTopLongitudinalPosition), "1", "3", "ExposureSequence");
244         addElementToDataset(result, item, new DcmDecimalString(TableTopLateralPosition), "1", "3", "ExposureSequence");
245         if (result.good()) result = ApplicatorSequence.write(item, "1-n", "3", "ExposureSequence");
246         if (result.good()) result = GeneralAccessorySequence.write(item, "1-n", "3", "ExposureSequence");
247         addElementToDataset(result, item, new DcmIntegerString(NumberOfBlocks), "1", "1", "ExposureSequence");
248         if (result.good()) result = BlockSequence.write(item, "1-n", "2C", "ExposureSequence");
249     }
250     return result;
251 }
252 
253 
getBeamLimitingDeviceAngle(OFString & value,const signed long pos) const254 OFCondition DRTExposureSequence::Item::getBeamLimitingDeviceAngle(OFString &value, const signed long pos) const
255 {
256     if (EmptyDefaultItem)
257         return EC_IllegalCall;
258     else
259         return getStringValueFromElement(BeamLimitingDeviceAngle, value, pos);
260 }
261 
262 
getBeamLimitingDeviceAngle(Float64 & value,const unsigned long pos) const263 OFCondition DRTExposureSequence::Item::getBeamLimitingDeviceAngle(Float64 &value, const unsigned long pos) const
264 {
265     if (EmptyDefaultItem)
266         return EC_IllegalCall;
267     else
268         return OFconst_cast(DcmDecimalString &, BeamLimitingDeviceAngle).getFloat64(value, pos);
269 }
270 
271 
getDiaphragmPosition(OFString & value,const signed long pos) const272 OFCondition DRTExposureSequence::Item::getDiaphragmPosition(OFString &value, const signed long pos) const
273 {
274     if (EmptyDefaultItem)
275         return EC_IllegalCall;
276     else
277         return getStringValueFromElement(DiaphragmPosition, value, pos);
278 }
279 
280 
getDiaphragmPosition(Float64 & value,const unsigned long pos) const281 OFCondition DRTExposureSequence::Item::getDiaphragmPosition(Float64 &value, const unsigned long pos) const
282 {
283     if (EmptyDefaultItem)
284         return EC_IllegalCall;
285     else
286         return OFconst_cast(DcmDecimalString &, DiaphragmPosition).getFloat64(value, pos);
287 }
288 
289 
getDiaphragmPosition(OFVector<Float64> & value) const290 OFCondition DRTExposureSequence::Item::getDiaphragmPosition(OFVector<Float64> &value) const
291 {
292     if (EmptyDefaultItem)
293         return EC_IllegalCall;
294     else
295         return OFconst_cast(DcmDecimalString &, DiaphragmPosition).getFloat64Vector(value);
296 }
297 
298 
getExposureTime(OFString & value,const signed long pos) const299 OFCondition DRTExposureSequence::Item::getExposureTime(OFString &value, const signed long pos) const
300 {
301     if (EmptyDefaultItem)
302         return EC_IllegalCall;
303     else
304         return getStringValueFromElement(ExposureTime, value, pos);
305 }
306 
307 
getExposureTime(Sint32 & value,const unsigned long pos) const308 OFCondition DRTExposureSequence::Item::getExposureTime(Sint32 &value, const unsigned long pos) const
309 {
310     if (EmptyDefaultItem)
311         return EC_IllegalCall;
312     else
313         return OFconst_cast(DcmIntegerString &, ExposureTime).getSint32(value, pos);
314 }
315 
316 
getExposureTimeInms(Float64 & value,const unsigned long pos) const317 OFCondition DRTExposureSequence::Item::getExposureTimeInms(Float64 &value, const unsigned long pos) const
318 {
319     if (EmptyDefaultItem)
320         return EC_IllegalCall;
321     else
322         return OFconst_cast(DcmFloatingPointDouble &, ExposureTimeInms).getFloat64(value, pos);
323 }
324 
325 
getGantryAngle(OFString & value,const signed long pos) const326 OFCondition DRTExposureSequence::Item::getGantryAngle(OFString &value, const signed long pos) const
327 {
328     if (EmptyDefaultItem)
329         return EC_IllegalCall;
330     else
331         return getStringValueFromElement(GantryAngle, value, pos);
332 }
333 
334 
getGantryAngle(Float64 & value,const unsigned long pos) const335 OFCondition DRTExposureSequence::Item::getGantryAngle(Float64 &value, const unsigned long pos) const
336 {
337     if (EmptyDefaultItem)
338         return EC_IllegalCall;
339     else
340         return OFconst_cast(DcmDecimalString &, GantryAngle).getFloat64(value, pos);
341 }
342 
343 
getGantryPitchAngle(Float32 & value,const unsigned long pos) const344 OFCondition DRTExposureSequence::Item::getGantryPitchAngle(Float32 &value, const unsigned long pos) const
345 {
346     if (EmptyDefaultItem)
347         return EC_IllegalCall;
348     else
349         return OFconst_cast(DcmFloatingPointSingle &, GantryPitchAngle).getFloat32(value, pos);
350 }
351 
352 
getKVP(OFString & value,const signed long pos) const353 OFCondition DRTExposureSequence::Item::getKVP(OFString &value, const signed long pos) const
354 {
355     if (EmptyDefaultItem)
356         return EC_IllegalCall;
357     else
358         return getStringValueFromElement(KVP, value, pos);
359 }
360 
361 
getKVP(Float64 & value,const unsigned long pos) const362 OFCondition DRTExposureSequence::Item::getKVP(Float64 &value, const unsigned long pos) const
363 {
364     if (EmptyDefaultItem)
365         return EC_IllegalCall;
366     else
367         return OFconst_cast(DcmDecimalString &, KVP).getFloat64(value, pos);
368 }
369 
370 
getMetersetExposure(OFString & value,const signed long pos) const371 OFCondition DRTExposureSequence::Item::getMetersetExposure(OFString &value, const signed long pos) const
372 {
373     if (EmptyDefaultItem)
374         return EC_IllegalCall;
375     else
376         return getStringValueFromElement(MetersetExposure, value, pos);
377 }
378 
379 
getMetersetExposure(Float64 & value,const unsigned long pos) const380 OFCondition DRTExposureSequence::Item::getMetersetExposure(Float64 &value, const unsigned long pos) const
381 {
382     if (EmptyDefaultItem)
383         return EC_IllegalCall;
384     else
385         return OFconst_cast(DcmDecimalString &, MetersetExposure).getFloat64(value, pos);
386 }
387 
388 
getNumberOfBlocks(OFString & value,const signed long pos) const389 OFCondition DRTExposureSequence::Item::getNumberOfBlocks(OFString &value, const signed long pos) const
390 {
391     if (EmptyDefaultItem)
392         return EC_IllegalCall;
393     else
394         return getStringValueFromElement(NumberOfBlocks, value, pos);
395 }
396 
397 
getNumberOfBlocks(Sint32 & value,const unsigned long pos) const398 OFCondition DRTExposureSequence::Item::getNumberOfBlocks(Sint32 &value, const unsigned long pos) const
399 {
400     if (EmptyDefaultItem)
401         return EC_IllegalCall;
402     else
403         return OFconst_cast(DcmIntegerString &, NumberOfBlocks).getSint32(value, pos);
404 }
405 
406 
getPatientSupportAngle(OFString & value,const signed long pos) const407 OFCondition DRTExposureSequence::Item::getPatientSupportAngle(OFString &value, const signed long pos) const
408 {
409     if (EmptyDefaultItem)
410         return EC_IllegalCall;
411     else
412         return getStringValueFromElement(PatientSupportAngle, value, pos);
413 }
414 
415 
getPatientSupportAngle(Float64 & value,const unsigned long pos) const416 OFCondition DRTExposureSequence::Item::getPatientSupportAngle(Float64 &value, const unsigned long pos) const
417 {
418     if (EmptyDefaultItem)
419         return EC_IllegalCall;
420     else
421         return OFconst_cast(DcmDecimalString &, PatientSupportAngle).getFloat64(value, pos);
422 }
423 
424 
getReferencedFrameNumber(OFString & value,const signed long pos) const425 OFCondition DRTExposureSequence::Item::getReferencedFrameNumber(OFString &value, const signed long pos) const
426 {
427     if (EmptyDefaultItem)
428         return EC_IllegalCall;
429     else
430         return getStringValueFromElement(ReferencedFrameNumber, value, pos);
431 }
432 
433 
getReferencedFrameNumber(Sint32 & value,const unsigned long pos) const434 OFCondition DRTExposureSequence::Item::getReferencedFrameNumber(Sint32 &value, const unsigned long pos) const
435 {
436     if (EmptyDefaultItem)
437         return EC_IllegalCall;
438     else
439         return OFconst_cast(DcmIntegerString &, ReferencedFrameNumber).getSint32(value, pos);
440 }
441 
442 
getTableTopLateralPosition(OFString & value,const signed long pos) const443 OFCondition DRTExposureSequence::Item::getTableTopLateralPosition(OFString &value, const signed long pos) const
444 {
445     if (EmptyDefaultItem)
446         return EC_IllegalCall;
447     else
448         return getStringValueFromElement(TableTopLateralPosition, value, pos);
449 }
450 
451 
getTableTopLateralPosition(Float64 & value,const unsigned long pos) const452 OFCondition DRTExposureSequence::Item::getTableTopLateralPosition(Float64 &value, const unsigned long pos) const
453 {
454     if (EmptyDefaultItem)
455         return EC_IllegalCall;
456     else
457         return OFconst_cast(DcmDecimalString &, TableTopLateralPosition).getFloat64(value, pos);
458 }
459 
460 
getTableTopLongitudinalPosition(OFString & value,const signed long pos) const461 OFCondition DRTExposureSequence::Item::getTableTopLongitudinalPosition(OFString &value, const signed long pos) const
462 {
463     if (EmptyDefaultItem)
464         return EC_IllegalCall;
465     else
466         return getStringValueFromElement(TableTopLongitudinalPosition, value, pos);
467 }
468 
469 
getTableTopLongitudinalPosition(Float64 & value,const unsigned long pos) const470 OFCondition DRTExposureSequence::Item::getTableTopLongitudinalPosition(Float64 &value, const unsigned long pos) const
471 {
472     if (EmptyDefaultItem)
473         return EC_IllegalCall;
474     else
475         return OFconst_cast(DcmDecimalString &, TableTopLongitudinalPosition).getFloat64(value, pos);
476 }
477 
478 
getTableTopPitchAngle(Float32 & value,const unsigned long pos) const479 OFCondition DRTExposureSequence::Item::getTableTopPitchAngle(Float32 &value, const unsigned long pos) const
480 {
481     if (EmptyDefaultItem)
482         return EC_IllegalCall;
483     else
484         return OFconst_cast(DcmFloatingPointSingle &, TableTopPitchAngle).getFloat32(value, pos);
485 }
486 
487 
getTableTopRollAngle(Float32 & value,const unsigned long pos) const488 OFCondition DRTExposureSequence::Item::getTableTopRollAngle(Float32 &value, const unsigned long pos) const
489 {
490     if (EmptyDefaultItem)
491         return EC_IllegalCall;
492     else
493         return OFconst_cast(DcmFloatingPointSingle &, TableTopRollAngle).getFloat32(value, pos);
494 }
495 
496 
getTableTopVerticalPosition(OFString & value,const signed long pos) const497 OFCondition DRTExposureSequence::Item::getTableTopVerticalPosition(OFString &value, const signed long pos) const
498 {
499     if (EmptyDefaultItem)
500         return EC_IllegalCall;
501     else
502         return getStringValueFromElement(TableTopVerticalPosition, value, pos);
503 }
504 
505 
getTableTopVerticalPosition(Float64 & value,const unsigned long pos) const506 OFCondition DRTExposureSequence::Item::getTableTopVerticalPosition(Float64 &value, const unsigned long pos) const
507 {
508     if (EmptyDefaultItem)
509         return EC_IllegalCall;
510     else
511         return OFconst_cast(DcmDecimalString &, TableTopVerticalPosition).getFloat64(value, pos);
512 }
513 
514 
getXRayTubeCurrent(OFString & value,const signed long pos) const515 OFCondition DRTExposureSequence::Item::getXRayTubeCurrent(OFString &value, const signed long pos) const
516 {
517     if (EmptyDefaultItem)
518         return EC_IllegalCall;
519     else
520         return getStringValueFromElement(XRayTubeCurrent, value, pos);
521 }
522 
523 
getXRayTubeCurrent(Sint32 & value,const unsigned long pos) const524 OFCondition DRTExposureSequence::Item::getXRayTubeCurrent(Sint32 &value, const unsigned long pos) const
525 {
526     if (EmptyDefaultItem)
527         return EC_IllegalCall;
528     else
529         return OFconst_cast(DcmIntegerString &, XRayTubeCurrent).getSint32(value, pos);
530 }
531 
532 
getXRayTubeCurrentInmA(Float64 & value,const unsigned long pos) const533 OFCondition DRTExposureSequence::Item::getXRayTubeCurrentInmA(Float64 &value, const unsigned long pos) const
534 {
535     if (EmptyDefaultItem)
536         return EC_IllegalCall;
537     else
538         return OFconst_cast(DcmFloatingPointDouble &, XRayTubeCurrentInmA).getFloat64(value, pos);
539 }
540 
541 
setBeamLimitingDeviceAngle(const OFString & value,const OFBool check)542 OFCondition DRTExposureSequence::Item::setBeamLimitingDeviceAngle(const OFString &value, const OFBool check)
543 {
544     OFCondition result = EC_IllegalCall;
545     if (!EmptyDefaultItem)
546     {
547         result = (check) ? DcmDecimalString::checkStringValue(value, "1") : EC_Normal;
548         if (result.good())
549             result = BeamLimitingDeviceAngle.putOFStringArray(value);
550     }
551     return result;
552 }
553 
554 
setDiaphragmPosition(const OFString & value,const OFBool check)555 OFCondition DRTExposureSequence::Item::setDiaphragmPosition(const OFString &value, const OFBool check)
556 {
557     OFCondition result = EC_IllegalCall;
558     if (!EmptyDefaultItem)
559     {
560         result = (check) ? DcmDecimalString::checkStringValue(value, "4") : EC_Normal;
561         if (result.good())
562             result = DiaphragmPosition.putOFStringArray(value);
563     }
564     return result;
565 }
566 
567 
setExposureTime(const OFString & value,const OFBool check)568 OFCondition DRTExposureSequence::Item::setExposureTime(const OFString &value, const OFBool check)
569 {
570     OFCondition result = EC_IllegalCall;
571     if (!EmptyDefaultItem)
572     {
573         result = (check) ? DcmIntegerString::checkStringValue(value, "1") : EC_Normal;
574         if (result.good())
575             result = ExposureTime.putOFStringArray(value);
576     }
577     return result;
578 }
579 
580 
setExposureTimeInms(const Float64 value,const unsigned long pos)581 OFCondition DRTExposureSequence::Item::setExposureTimeInms(const Float64 value, const unsigned long pos)
582 {
583     if (EmptyDefaultItem)
584         return EC_IllegalCall;
585     else
586         return ExposureTimeInms.putFloat64(value, pos);
587 }
588 
589 
setGantryAngle(const OFString & value,const OFBool check)590 OFCondition DRTExposureSequence::Item::setGantryAngle(const OFString &value, const OFBool check)
591 {
592     OFCondition result = EC_IllegalCall;
593     if (!EmptyDefaultItem)
594     {
595         result = (check) ? DcmDecimalString::checkStringValue(value, "1") : EC_Normal;
596         if (result.good())
597             result = GantryAngle.putOFStringArray(value);
598     }
599     return result;
600 }
601 
602 
setGantryPitchAngle(const Float32 value,const unsigned long pos)603 OFCondition DRTExposureSequence::Item::setGantryPitchAngle(const Float32 value, const unsigned long pos)
604 {
605     if (EmptyDefaultItem)
606         return EC_IllegalCall;
607     else
608         return GantryPitchAngle.putFloat32(value, pos);
609 }
610 
611 
setKVP(const OFString & value,const OFBool check)612 OFCondition DRTExposureSequence::Item::setKVP(const OFString &value, const OFBool check)
613 {
614     OFCondition result = EC_IllegalCall;
615     if (!EmptyDefaultItem)
616     {
617         result = (check) ? DcmDecimalString::checkStringValue(value, "1") : EC_Normal;
618         if (result.good())
619             result = KVP.putOFStringArray(value);
620     }
621     return result;
622 }
623 
624 
setMetersetExposure(const OFString & value,const OFBool check)625 OFCondition DRTExposureSequence::Item::setMetersetExposure(const OFString &value, const OFBool check)
626 {
627     OFCondition result = EC_IllegalCall;
628     if (!EmptyDefaultItem)
629     {
630         result = (check) ? DcmDecimalString::checkStringValue(value, "1") : EC_Normal;
631         if (result.good())
632             result = MetersetExposure.putOFStringArray(value);
633     }
634     return result;
635 }
636 
637 
setNumberOfBlocks(const OFString & value,const OFBool check)638 OFCondition DRTExposureSequence::Item::setNumberOfBlocks(const OFString &value, const OFBool check)
639 {
640     OFCondition result = EC_IllegalCall;
641     if (!EmptyDefaultItem)
642     {
643         result = (check) ? DcmIntegerString::checkStringValue(value, "1") : EC_Normal;
644         if (result.good())
645             result = NumberOfBlocks.putOFStringArray(value);
646     }
647     return result;
648 }
649 
650 
setPatientSupportAngle(const OFString & value,const OFBool check)651 OFCondition DRTExposureSequence::Item::setPatientSupportAngle(const OFString &value, const OFBool check)
652 {
653     OFCondition result = EC_IllegalCall;
654     if (!EmptyDefaultItem)
655     {
656         result = (check) ? DcmDecimalString::checkStringValue(value, "1") : EC_Normal;
657         if (result.good())
658             result = PatientSupportAngle.putOFStringArray(value);
659     }
660     return result;
661 }
662 
663 
setReferencedFrameNumber(const OFString & value,const OFBool check)664 OFCondition DRTExposureSequence::Item::setReferencedFrameNumber(const OFString &value, const OFBool check)
665 {
666     OFCondition result = EC_IllegalCall;
667     if (!EmptyDefaultItem)
668     {
669         result = (check) ? DcmIntegerString::checkStringValue(value, "1-n") : EC_Normal;
670         if (result.good())
671             result = ReferencedFrameNumber.putOFStringArray(value);
672     }
673     return result;
674 }
675 
676 
setTableTopLateralPosition(const OFString & value,const OFBool check)677 OFCondition DRTExposureSequence::Item::setTableTopLateralPosition(const OFString &value, const OFBool check)
678 {
679     OFCondition result = EC_IllegalCall;
680     if (!EmptyDefaultItem)
681     {
682         result = (check) ? DcmDecimalString::checkStringValue(value, "1") : EC_Normal;
683         if (result.good())
684             result = TableTopLateralPosition.putOFStringArray(value);
685     }
686     return result;
687 }
688 
689 
setTableTopLongitudinalPosition(const OFString & value,const OFBool check)690 OFCondition DRTExposureSequence::Item::setTableTopLongitudinalPosition(const OFString &value, const OFBool check)
691 {
692     OFCondition result = EC_IllegalCall;
693     if (!EmptyDefaultItem)
694     {
695         result = (check) ? DcmDecimalString::checkStringValue(value, "1") : EC_Normal;
696         if (result.good())
697             result = TableTopLongitudinalPosition.putOFStringArray(value);
698     }
699     return result;
700 }
701 
702 
setTableTopPitchAngle(const Float32 value,const unsigned long pos)703 OFCondition DRTExposureSequence::Item::setTableTopPitchAngle(const Float32 value, const unsigned long pos)
704 {
705     if (EmptyDefaultItem)
706         return EC_IllegalCall;
707     else
708         return TableTopPitchAngle.putFloat32(value, pos);
709 }
710 
711 
setTableTopRollAngle(const Float32 value,const unsigned long pos)712 OFCondition DRTExposureSequence::Item::setTableTopRollAngle(const Float32 value, const unsigned long pos)
713 {
714     if (EmptyDefaultItem)
715         return EC_IllegalCall;
716     else
717         return TableTopRollAngle.putFloat32(value, pos);
718 }
719 
720 
setTableTopVerticalPosition(const OFString & value,const OFBool check)721 OFCondition DRTExposureSequence::Item::setTableTopVerticalPosition(const OFString &value, const OFBool check)
722 {
723     OFCondition result = EC_IllegalCall;
724     if (!EmptyDefaultItem)
725     {
726         result = (check) ? DcmDecimalString::checkStringValue(value, "1") : EC_Normal;
727         if (result.good())
728             result = TableTopVerticalPosition.putOFStringArray(value);
729     }
730     return result;
731 }
732 
733 
setXRayTubeCurrent(const OFString & value,const OFBool check)734 OFCondition DRTExposureSequence::Item::setXRayTubeCurrent(const OFString &value, const OFBool check)
735 {
736     OFCondition result = EC_IllegalCall;
737     if (!EmptyDefaultItem)
738     {
739         result = (check) ? DcmIntegerString::checkStringValue(value, "1") : EC_Normal;
740         if (result.good())
741             result = XRayTubeCurrent.putOFStringArray(value);
742     }
743     return result;
744 }
745 
746 
setXRayTubeCurrentInmA(const Float64 value,const unsigned long pos)747 OFCondition DRTExposureSequence::Item::setXRayTubeCurrentInmA(const Float64 value, const unsigned long pos)
748 {
749     if (EmptyDefaultItem)
750         return EC_IllegalCall;
751     else
752         return XRayTubeCurrentInmA.putFloat64(value, pos);
753 }
754 
755 
756 // --- sequence class ---
757 
DRTExposureSequence(const OFBool emptyDefaultSequence)758 DRTExposureSequence::DRTExposureSequence(const OFBool emptyDefaultSequence)
759   : EmptyDefaultSequence(emptyDefaultSequence),
760     SequenceOfItems(),
761     CurrentItem(),
762     EmptyItem(OFTrue /*emptyDefaultItem*/)
763 {
764     CurrentItem = SequenceOfItems.end();
765 }
766 
767 
DRTExposureSequence(const DRTExposureSequence & copy)768 DRTExposureSequence::DRTExposureSequence(const DRTExposureSequence &copy)
769   : EmptyDefaultSequence(copy.EmptyDefaultSequence),
770     SequenceOfItems(),
771     CurrentItem(),
772     EmptyItem(OFTrue /*emptyDefaultItem*/)
773 {
774     /* create a copy of the internal sequence of items */
775     Item *item = NULL;
776     OFListConstIterator(Item *) current = copy.SequenceOfItems.begin();
777     const OFListConstIterator(Item *) last = copy.SequenceOfItems.end();
778     while (current != last)
779     {
780         item = new Item(**current);
781         if (item != NULL)
782         {
783             SequenceOfItems.push_back(item);
784         } else {
785             /* memory exhausted, there is nothing we can do about it */
786             break;
787         }
788         ++current;
789     }
790     CurrentItem = SequenceOfItems.begin();
791 }
792 
793 
operator =(const DRTExposureSequence & copy)794 DRTExposureSequence &DRTExposureSequence::operator=(const DRTExposureSequence &copy)
795 {
796     if (this != &copy)
797     {
798         clear();
799         EmptyDefaultSequence = copy.EmptyDefaultSequence;
800         /* create a copy of the internal sequence of items */
801         Item *item = NULL;
802         OFListConstIterator(Item *) current = copy.SequenceOfItems.begin();
803         const OFListConstIterator(Item *) last = copy.SequenceOfItems.end();
804         while (current != last)
805         {
806             item = new Item(**current);
807             if (item != NULL)
808             {
809                 SequenceOfItems.push_back(item);
810             } else {
811                 /* memory exhausted, there is nothing we can do about it */
812                 break;
813             }
814             ++current;
815         }
816         CurrentItem = SequenceOfItems.begin();
817     }
818     return *this;
819 }
820 
821 
~DRTExposureSequence()822 DRTExposureSequence::~DRTExposureSequence()
823 {
824     clear();
825 }
826 
827 
clear()828 void DRTExposureSequence::clear()
829 {
830     if (!EmptyDefaultSequence)
831     {
832         CurrentItem = SequenceOfItems.begin();
833         const OFListConstIterator(Item *) last = SequenceOfItems.end();
834         /* delete all items and free memory */
835         while (CurrentItem != last)
836         {
837             delete (*CurrentItem);
838             CurrentItem = SequenceOfItems.erase(CurrentItem);
839         }
840         /* make sure that the list is empty */
841         SequenceOfItems.clear();
842         CurrentItem = SequenceOfItems.end();
843     }
844 }
845 
846 
isEmpty()847 OFBool DRTExposureSequence::isEmpty()
848 {
849     return SequenceOfItems.empty();
850 }
851 
852 
isValid() const853 OFBool DRTExposureSequence::isValid() const
854 {
855     return !EmptyDefaultSequence;
856 }
857 
858 
getNumberOfItems() const859 size_t DRTExposureSequence::getNumberOfItems() const
860 {
861     return SequenceOfItems.size();
862 }
863 
864 
gotoFirstItem()865 OFCondition DRTExposureSequence::gotoFirstItem()
866 {
867     OFCondition result = EC_IllegalCall;
868     if (!SequenceOfItems.empty())
869     {
870         CurrentItem = SequenceOfItems.begin();
871         result = EC_Normal;
872     }
873     return result;
874 }
875 
876 
gotoNextItem()877 OFCondition DRTExposureSequence::gotoNextItem()
878 {
879     OFCondition result = EC_IllegalCall;
880     if (CurrentItem != SequenceOfItems.end())
881     {
882         ++CurrentItem;
883         result = EC_Normal;
884     }
885     return result;
886 }
887 
888 
gotoItem(const size_t num,OFListIterator (Item *)& iterator)889 OFCondition DRTExposureSequence::gotoItem(const size_t num, OFListIterator(Item *) &iterator)
890 {
891     OFCondition result = EC_IllegalCall;
892     if (!SequenceOfItems.empty())
893     {
894         size_t idx = num + 1;
895         iterator = SequenceOfItems.begin();
896         const OFListConstIterator(Item *) last = SequenceOfItems.end();
897         while ((--idx > 0) && (iterator != last))
898             ++iterator;
899         /* specified list item found? */
900         if ((idx == 0) && (iterator != last))
901             result = EC_Normal;
902         else
903             result = EC_IllegalParameter;
904     }
905     return result;
906 }
907 
908 
gotoItem(const size_t num,OFListConstIterator (Item *)& iterator) const909 OFCondition DRTExposureSequence::gotoItem(const size_t num, OFListConstIterator(Item *) &iterator) const
910 {
911     OFCondition result = EC_IllegalCall;
912     if (!SequenceOfItems.empty())
913     {
914         size_t idx = num + 1;
915         iterator = SequenceOfItems.begin();
916         const OFListConstIterator(Item *) last = SequenceOfItems.end();
917         while ((--idx > 0) && (iterator != last))
918             ++iterator;
919         /* specified list item found? */
920         if ((idx == 0) && (iterator != last))
921             result = EC_Normal;
922         else
923             result = EC_IllegalParameter;
924     }
925     return result;
926 }
927 
928 
gotoItem(const size_t num)929 OFCondition DRTExposureSequence::gotoItem(const size_t num)
930 {
931     return gotoItem(num, CurrentItem);
932 }
933 
934 
getCurrentItem(Item * & item) const935 OFCondition DRTExposureSequence::getCurrentItem(Item *&item) const
936 {
937     OFCondition result = EC_IllegalCall;
938     if (CurrentItem != SequenceOfItems.end())
939     {
940         item = *CurrentItem;
941         result = EC_Normal;
942     }
943     return result;
944 }
945 
946 
getCurrentItem()947 DRTExposureSequence::Item &DRTExposureSequence::getCurrentItem()
948 {
949     if (CurrentItem != SequenceOfItems.end())
950         return **CurrentItem;
951     else
952         return EmptyItem;
953 }
954 
955 
getCurrentItem() const956 const DRTExposureSequence::Item &DRTExposureSequence::getCurrentItem() const
957 {
958     if (CurrentItem != SequenceOfItems.end())
959         return **CurrentItem;
960     else
961         return EmptyItem;
962 }
963 
964 
getItem(const size_t num,Item * & item)965 OFCondition DRTExposureSequence::getItem(const size_t num, Item *&item)
966 {
967     OFListIterator(Item *) iterator;
968     OFCondition result = gotoItem(num, iterator);
969     if (result.good())
970         item = *iterator;
971     return result;
972 }
973 
974 
getItem(const size_t num)975 DRTExposureSequence::Item &DRTExposureSequence::getItem(const size_t num)
976 {
977     OFListIterator(Item *) iterator;
978     if (gotoItem(num, iterator).good())
979         return **iterator;
980     else
981         return EmptyItem;
982 }
983 
984 
getItem(const size_t num) const985 const DRTExposureSequence::Item &DRTExposureSequence::getItem(const size_t num) const
986 {
987     OFListConstIterator(Item *) iterator;
988     if (gotoItem(num, iterator).good())
989         return **iterator;
990     else
991         return EmptyItem;
992 }
993 
994 
operator [](const size_t num)995 DRTExposureSequence::Item &DRTExposureSequence::operator[](const size_t num)
996 {
997     return getItem(num);
998 }
999 
1000 
operator [](const size_t num) const1001 const DRTExposureSequence::Item &DRTExposureSequence::operator[](const size_t num) const
1002 {
1003     return getItem(num);
1004 }
1005 
1006 
addItem(Item * & item)1007 OFCondition DRTExposureSequence::addItem(Item *&item)
1008 {
1009     OFCondition result = EC_IllegalCall;
1010     if (!EmptyDefaultSequence)
1011     {
1012         item = new Item();
1013         if (item != NULL)
1014         {
1015             SequenceOfItems.push_back(item);
1016             result = EC_Normal;
1017         } else
1018             result = EC_MemoryExhausted;
1019     }
1020     return result;
1021 }
1022 
1023 
insertItem(const size_t pos,Item * & item)1024 OFCondition DRTExposureSequence::insertItem(const size_t pos, Item *&item)
1025 {
1026     OFCondition result = EC_IllegalCall;
1027     if (!EmptyDefaultSequence)
1028     {
1029         OFListIterator(Item *) iterator;
1030         result = gotoItem(pos, iterator);
1031         if (result.good())
1032         {
1033             item = new Item();
1034             if (item != NULL)
1035             {
1036                 SequenceOfItems.insert(iterator, 1, item);
1037                 result = EC_Normal;
1038             } else
1039                 result = EC_MemoryExhausted;
1040         } else
1041             result = addItem(item);
1042     }
1043     return result;
1044 }
1045 
1046 
removeItem(const size_t pos)1047 OFCondition DRTExposureSequence::removeItem(const size_t pos)
1048 {
1049     OFCondition result = EC_IllegalCall;
1050     if (!EmptyDefaultSequence)
1051     {
1052         OFListIterator(Item *) iterator;
1053         if (gotoItem(pos, iterator).good())
1054         {
1055             delete *iterator;
1056             iterator = SequenceOfItems.erase(iterator);
1057             result = EC_Normal;
1058         } else
1059             result = EC_IllegalParameter;
1060     }
1061     return result;
1062 }
1063 
1064 
read(DcmItem & dataset,const OFString & card,const OFString & type,const char * moduleName)1065 OFCondition DRTExposureSequence::read(DcmItem &dataset,
1066                                       const OFString &card,
1067                                       const OFString &type,
1068                                       const char *moduleName)
1069 {
1070     OFCondition result = EC_IllegalCall;
1071     if (!EmptyDefaultSequence)
1072     {
1073         /* re-initialize object */
1074         clear();
1075         /* retrieve sequence element from dataset */
1076         DcmSequenceOfItems *sequence;
1077         result = dataset.findAndGetSequence(DCM_ExposureSequence, sequence);
1078         if (sequence != NULL)
1079         {
1080             if (checkElementValue(*sequence, card, type, result, moduleName))
1081             {
1082                 DcmStack stack;
1083                 OFBool first = OFTrue;
1084                 /* iterate over all sequence items */
1085                 while (result.good() && sequence->nextObject(stack, first /*intoSub*/).good())
1086                 {
1087                     DcmItem *ditem = OFstatic_cast(DcmItem *, stack.top());
1088                     if (ditem != NULL)
1089                     {
1090                         Item *item = new Item();
1091                         if (item != NULL)
1092                         {
1093                             result = item->read(*ditem);
1094                             if (result.good())
1095                             {
1096                                 /* append new item to the end of the list */
1097                                 SequenceOfItems.push_back(item);
1098                                 first = OFFalse;
1099                             }
1100                         } else
1101                             result = EC_MemoryExhausted;
1102                     } else
1103                         result = EC_CorruptedData;
1104                 }
1105             }
1106         } else {
1107             DcmSequenceOfItems element(DCM_ExposureSequence);
1108             checkElementValue(element, card, type, result, moduleName);
1109         }
1110     }
1111     return result;
1112 }
1113 
1114 
write(DcmItem & dataset,const OFString & card,const OFString & type,const char * moduleName)1115 OFCondition DRTExposureSequence::write(DcmItem &dataset,
1116                                        const OFString &card,
1117                                        const OFString &type,
1118                                        const char *moduleName)
1119 {
1120     OFCondition result = EC_IllegalCall;
1121     if (!EmptyDefaultSequence)
1122     {
1123         result = EC_MemoryExhausted;
1124         DcmSequenceOfItems *sequence = new DcmSequenceOfItems(DCM_ExposureSequence);
1125         if (sequence != NULL)
1126         {
1127             result = EC_Normal;
1128             /* an empty optional sequence is not written */
1129             if ((type == "2") || !SequenceOfItems.empty())
1130             {
1131                 OFListIterator(Item *) iterator = SequenceOfItems.begin();
1132                 const OFListConstIterator(Item *) last = SequenceOfItems.end();
1133                 /* iterate over all sequence items */
1134                 while (result.good() && (iterator != last))
1135                 {
1136                     DcmItem *item = new DcmItem();
1137                     if (item != NULL)
1138                     {
1139                         /* append new item to the end of the sequence */
1140                         result = sequence->append(item);
1141                         if (result.good())
1142                         {
1143                             result = (*iterator)->write(*item);
1144                             ++iterator;
1145                         } else
1146                             delete item;
1147                     } else
1148                         result = EC_MemoryExhausted;
1149                 }
1150                 if (result.good())
1151                 {
1152                     /* insert sequence element into the dataset */
1153                     result = dataset.insert(sequence, OFTrue /*replaceOld*/);
1154                 }
1155                 if (DCM_dcmrtLogger.isEnabledFor(OFLogger::WARN_LOG_LEVEL))
1156                     checkElementValue(*sequence, card, type, result, moduleName);
1157                 if (result.good())
1158                 {
1159                     /* forget reference to sequence object (avoid deletion below) */
1160                     sequence = NULL;
1161                 }
1162             }
1163             else if (type == "1")
1164             {
1165                 /* empty type 1 sequence not allowed */
1166                 result = RT_EC_InvalidValue;
1167                 if (DCM_dcmrtLogger.isEnabledFor(OFLogger::WARN_LOG_LEVEL))
1168                     checkElementValue(*sequence, card, type, result, moduleName);
1169             }
1170             /* delete sequence (if not inserted into the dataset) */
1171             delete sequence;
1172         }
1173     }
1174     return result;
1175 }
1176 
1177 
1178 // end of source file
1179