Commit eaf1d653 authored by Michael Hart's avatar Michael Hart
Browse files

Re #15712 Constructors to apply ParameterMap are now protected

parent 7e0fa0f9
......@@ -48,8 +48,6 @@ public:
/// A string representation of the component type
std::string type() const override { return "DetectorComponent"; }
/// Constructor for parametrized version
Detector(const Detector *base, const ParameterMap *map);
Detector(const std::string &name, int id, IComponent *parent);
Detector(const std::string &name, int id, boost::shared_ptr<Object> shape,
IComponent *parent);
......@@ -91,6 +89,10 @@ private:
const detid_t m_id;
/// Flags if this is a monitor
bool m_isMonitor;
protected:
/// Constructor for parametrized version
Detector(const Detector *base, const ParameterMap *map);
};
} // namespace Geometry
......
......@@ -49,9 +49,6 @@ public:
/// A string representation of the component type
std::string type() const override { return "RectangularDetectorPixel"; }
/// Constructor for parametrized version
RectangularDetectorPixel(const RectangularDetectorPixel *base,
const ParameterMap *map);
RectangularDetectorPixel(const std::string &name, int id,
boost::shared_ptr<Object> shape, IComponent *parent,
RectangularDetector *panel, size_t row, size_t col);
......@@ -66,13 +63,18 @@ public:
const Kernel::V3D getRelativePos() const override;
protected:
private:
/// RectangularDetector that is the parent of this pixel.
RectangularDetector *m_panel;
/// Row of the pixel in the panel (y index)
size_t m_row;
/// Column of the pixel in the panel (x index)
size_t m_col;
protected:
/// Constructor for parametrized version
RectangularDetectorPixel(const RectangularDetectorPixel *base,
const ParameterMap *map);
};
} // namespace Geometry
......
......@@ -53,14 +53,6 @@ ParComponentFactory::createInstrument(boost::shared_ptr<const Instrument> base,
IComponent_sptr
ParComponentFactory::create(boost::shared_ptr<const IComponent> base,
const ParameterMap *map) {
// RectangularDetectorPixel subclasses Detector so it has to be checked
// before.
const RectangularDetectorPixel *rdp =
dynamic_cast<const RectangularDetectorPixel *>(base.get());
if (rdp)
return boost::shared_ptr<IComponent>(
new RectangularDetectorPixel(rdp, map));
boost::shared_ptr<const IDetector> det_sptr =
boost::dynamic_pointer_cast<const IDetector>(base);
if (det_sptr) {
......
......@@ -14,13 +14,13 @@ public:
Detector det("det1", 0, 0);
ParameterMap_sptr pmap(new ParameterMap());
Detector pdet(&det, pmap.get());
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
TS_ASSERT_EQUALS(pdet.getName(), "det1");
TS_ASSERT(!pdet.getParent());
TS_ASSERT_EQUALS(pdet.getID(), 0);
TS_ASSERT(!pdet.isMasked());
TS_ASSERT(!pdet.isMonitor());
TS_ASSERT_EQUALS(pdet->getName(), "det1");
TS_ASSERT(!pdet->getParent());
TS_ASSERT_EQUALS(pdet->getID(), 0);
TS_ASSERT(!pdet->isMasked());
TS_ASSERT(!pdet->isMonitor());
}
void testNameParentConstructor() {
......@@ -28,13 +28,13 @@ public:
Detector det("det1", 0, &parent);
ParameterMap_sptr pmap(new ParameterMap());
Detector pdet(&det, pmap.get());
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
TS_ASSERT_EQUALS(pdet.getName(), "det1");
TS_ASSERT(pdet.getParent());
TS_ASSERT_EQUALS(pdet.getID(), 0);
TS_ASSERT(!pdet.isMasked());
TS_ASSERT(!pdet.isMonitor());
TS_ASSERT_EQUALS(pdet->getName(), "det1");
TS_ASSERT(pdet->getParent());
TS_ASSERT_EQUALS(pdet->getID(), 0);
TS_ASSERT(!pdet->isMasked());
TS_ASSERT(!pdet->isMonitor());
}
void testId() {
......@@ -42,42 +42,42 @@ public:
Detector det("det1", id1, 0);
ParameterMap_sptr pmap(new ParameterMap());
Detector pdet(&det, pmap.get());
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
TS_ASSERT_EQUALS(pdet.getID(), id1);
TS_ASSERT_EQUALS(pdet->getID(), id1);
}
void testType() {
Detector det("det", 0, 0);
ParameterMap_sptr pmap(new ParameterMap());
Detector pdet(&det, pmap.get());
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
TS_ASSERT_EQUALS(pdet.type(), "DetectorComponent");
TS_ASSERT_EQUALS(pdet->type(), "DetectorComponent");
}
void testMasked() {
Detector det("det", 0, 0);
ParameterMap_sptr pmap(new ParameterMap());
Detector pdet(&det, pmap.get());
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
TS_ASSERT(!pdet.isMasked());
TS_ASSERT(!pdet->isMasked());
pmap->addBool(&det, "masked", true);
TS_ASSERT(pdet.isMasked());
TS_ASSERT(pdet->isMasked());
}
void testMonitor() {
Detector det("det", 0, 0);
ParameterMap_sptr pmap(new ParameterMap());
Detector pdet(&det, pmap.get());
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
TS_ASSERT(!pdet.isMonitor());
TS_ASSERT(!pdet->isMonitor());
TS_ASSERT_THROWS_NOTHING(det.markAsMonitor());
TS_ASSERT(pdet.isMonitor());
TS_ASSERT(pdet->isMonitor());
TS_ASSERT_THROWS_NOTHING(det.markAsMonitor(false));
TS_ASSERT(!pdet.isMonitor());
TS_ASSERT(!pdet->isMonitor());
}
void testGetNumberParameter() {
......@@ -85,8 +85,8 @@ public:
ParameterMap_sptr pmap(new ParameterMap());
pmap->add("double", &det, "testparam", 5.0);
Detector pdet(&det, pmap.get());
IDetector *idet = static_cast<IDetector *>(&pdet);
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
IDetector *idet = static_cast<IDetector *>(pdet.get());
TS_ASSERT_EQUALS(idet->getNumberParameter("testparam").size(), 1);
TS_ASSERT_DELTA(idet->getNumberParameter("testparam")[0], 5.0, 1e-08);
......@@ -97,8 +97,8 @@ public:
ParameterMap_sptr pmap(new ParameterMap());
pmap->add("V3D", &det, "testparam", Mantid::Kernel::V3D(0.5, 1.0, 1.5));
Detector pdet(&det, pmap.get());
IDetector *idet = static_cast<IDetector *>(&pdet);
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
IDetector *idet = static_cast<IDetector *>(pdet.get());
std::vector<Mantid::Kernel::V3D> pos =
idet->getPositionParameter("testparam");
......@@ -115,8 +115,8 @@ public:
ParameterMap_sptr pmap(new ParameterMap());
pmap->add("Quat", &det, "testparam",
Mantid::Kernel::Quat(1.0, 0.25, 0.5, 0.75));
Detector pdet(&det, pmap.get());
IDetector *idet = static_cast<IDetector *>(&pdet);
boost::shared_ptr<Detector> pdet(det.cloneParameterized(pmap.get()));
IDetector *idet = static_cast<IDetector *>(pdet.get());
std::vector<Mantid::Kernel::Quat> rot =
idet->getRotationParameter("testparam");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment