diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/BitmapGeometryHandler.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/BitmapGeometryHandler.h index 3ac8af1b606719d4a5dffe7f6fa2b07e190db719..ce9fb0e7b1762edcb91f281d3600bd9dbe733700 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/BitmapGeometryHandler.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/BitmapGeometryHandler.h @@ -54,6 +54,8 @@ namespace Mantid private: static Kernel::Logger& PLog; ///< The official logger + boost::shared_ptr<GeometryHandler> clone() const; + /// The RectangularDetector object being plotted. RectangularDetector * mRectDet; diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/CacheGeometryHandler.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/CacheGeometryHandler.h index 01e35e62fa02c52c23e526454e7e533b12154d3d..6aedace35bf7a31b2c75a8abf35e044e71cb7da0 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/CacheGeometryHandler.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/CacheGeometryHandler.h @@ -58,6 +58,7 @@ namespace Mantid CacheGeometryHandler(IObjComponent* obj); ///< Constructor CacheGeometryHandler(boost::shared_ptr<Object> obj); ///< Constructor CacheGeometryHandler(Object* obj); ///< Constructor + boost::shared_ptr<GeometryHandler> clone() const; ~CacheGeometryHandler(); ///< Destructor GeometryHandler* createInstance(IObjComponent *comp); GeometryHandler* createInstance(boost::shared_ptr<Object> obj); diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/GeometryHandler.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/GeometryHandler.h index 4cbcbf27700e92b3d9a5e254fd5498788a0eba18..05e583041acf5d41c5a494107d0031ec1c6fb1db 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/GeometryHandler.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/GeometryHandler.h @@ -58,6 +58,7 @@ namespace Mantid GeometryHandler(IObjComponent *comp); ///< Constructor GeometryHandler(boost::shared_ptr<Object> obj); ///<Constructor GeometryHandler(Object *obj); ///<Constructor + virtual boost::shared_ptr<GeometryHandler> clone() const = 0; ///< Virtual copy constructor virtual ~GeometryHandler(); virtual GeometryHandler* createInstance(IObjComponent *)=0; ///< Create an instance of concrete geometry handler for ObjComponent virtual GeometryHandler* createInstance(boost::shared_ptr<Object> )=0; ///< Create an instance of concrete geometry handler for Object diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/GluGeometryHandler.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/GluGeometryHandler.h index 418a1b8273fe5e430b2b4362dc79a68faafb5c11..b07467b534c89ae3389cddaf81405685f91c1ba0 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/GluGeometryHandler.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/GluGeometryHandler.h @@ -73,6 +73,7 @@ namespace Mantid GluGeometryHandler(IObjComponent* obj); ///< Constructor GluGeometryHandler(boost::shared_ptr<Object> obj); ///< Constructor GluGeometryHandler(Object* obj); ///< Constructor + boost::shared_ptr<GeometryHandler> clone() const; ~GluGeometryHandler(); ///< Destructor GeometryHandler* createInstance(IObjComponent *comp); GeometryHandler* createInstance(boost::shared_ptr<Object> obj); diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/OCGeometryHandler.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/OCGeometryHandler.h index 227c81d079d1cfe7b06c355fdc08e41c3f9dfabb..147a28ebbd3f79a5e3ab1488cb1f4ae9de73e7d2 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/OCGeometryHandler.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Rendering/OCGeometryHandler.h @@ -54,6 +54,7 @@ namespace Mantid OCGeometryHandler(IObjComponent* obj); ///< Constructor OCGeometryHandler(boost::shared_ptr<Object> obj); ///< Constructor OCGeometryHandler(Object* obj); ///< Constructor + boost::shared_ptr<GeometryHandler> clone() const; ///< Virtual copy constructor ~OCGeometryHandler(); ///< Destructor GeometryHandler* createInstance(IObjComponent *comp); GeometryHandler* createInstance(boost::shared_ptr<Object> obj); diff --git a/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp b/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp index dc1681bb00f94fcc0c8b6093c39b6952887bef38..a863dc39f4820f15c0c176ae58c166da8802a76d 100644 --- a/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp +++ b/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp @@ -34,9 +34,9 @@ namespace Mantid */ Object::Object() : ObjName(0), TopRule(0), m_boundingBox(), AABBxMax(0), AABByMax(0), AABBzMax(0), - AABBxMin(0), AABByMin(0), AABBzMin(0), boolBounded(false), bGeometryCaching(false), - vtkCacheReader(boost::shared_ptr<vtkGeometryCacheReader>()), vtkCacheWriter(boost::shared_ptr< - vtkGeometryCacheWriter>()) + AABBxMin(0), AABByMin(0), AABBzMin(0), boolBounded(false), handle(), bGeometryCaching(false), + vtkCacheReader(boost::shared_ptr<vtkGeometryCacheReader>()), + vtkCacheWriter(boost::shared_ptr<vtkGeometryCacheWriter>()) { handle = boost::shared_ptr<GeometryHandler>(new CacheGeometryHandler(this)); } @@ -47,7 +47,7 @@ namespace Mantid */ Object::Object(const std::string& shapeXML) : ObjName(0), TopRule(0), m_boundingBox(), AABBxMax(0), AABByMax(0), AABBzMax(0), - AABBxMin(0), AABByMin(0), AABBzMin(0), boolBounded(false), bGeometryCaching(false), + AABBxMin(0), AABByMin(0), AABBzMin(0), boolBounded(false), handle(), bGeometryCaching(false), vtkCacheReader(boost::shared_ptr<vtkGeometryCacheReader>()), vtkCacheWriter(boost::shared_ptr< vtkGeometryCacheWriter>()), m_shapeXML(shapeXML) { @@ -61,13 +61,11 @@ namespace Mantid Object::Object(const Object& A) : ObjName(A.ObjName), TopRule((A.TopRule) ? A.TopRule->clone() : NULL), m_boundingBox(A.m_boundingBox), AABBxMax(A.AABBxMax), AABByMax(A.AABByMax), AABBzMax(A.AABBzMax), AABBxMin(A.AABBxMin), - AABByMin(A.AABByMin), AABBzMin(A.AABBzMin), boolBounded(A.boolBounded), + AABByMin(A.AABByMin), AABBzMin(A.AABBzMin), boolBounded(A.boolBounded), handle(A.handle->clone()), bGeometryCaching(A.bGeometryCaching), vtkCacheReader(A.vtkCacheReader), vtkCacheWriter(A.vtkCacheWriter), m_shapeXML(A.m_shapeXML) { - handle = boost::shared_ptr<GeometryHandler>(new CacheGeometryHandler(this)); - if (TopRule) createSurfaceList(); } @@ -90,7 +88,7 @@ namespace Mantid AABByMin = A.AABByMin; AABBzMin = A.AABBzMin; boolBounded = A.boolBounded; - handle.reset(A.handle->createInstance(this)); + handle = A.handle->clone(); bGeometryCaching = A.bGeometryCaching; vtkCacheReader = A.vtkCacheReader; vtkCacheWriter = A.vtkCacheWriter; diff --git a/Code/Mantid/Framework/Geometry/src/Rendering/BitmapGeometryHandler.cpp b/Code/Mantid/Framework/Geometry/src/Rendering/BitmapGeometryHandler.cpp index 12f691b42c82aa13fe2dbae14cb894d3e3db0b03..398480627db5e77a9022e9de3c0723720c69587a 100644 --- a/Code/Mantid/Framework/Geometry/src/Rendering/BitmapGeometryHandler.cpp +++ b/Code/Mantid/Framework/Geometry/src/Rendering/BitmapGeometryHandler.cpp @@ -4,12 +4,22 @@ #include <climits> #include <iostream> +#include <boost/make_shared.hpp> + namespace Mantid { namespace Geometry { using Kernel::V3D; + /** + * @return A shared_ptr to a new copy of this object + */ + boost::shared_ptr<GeometryHandler> BitmapGeometryHandler::clone() const + { + return boost::make_shared<BitmapGeometryHandler>(*this); + } + /// Parameter constructor BitmapGeometryHandler::BitmapGeometryHandler(RectangularDetector *comp) : GeometryHandler(dynamic_cast<IObjComponent*>(comp)) diff --git a/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryGenerator.cpp b/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryGenerator.cpp index ec8adc126824d7bbd0c95bf7b892352dbc519fb4..a4ea16d2bcc04d9191ea809b63487f1c6bdea3b9 100644 --- a/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryGenerator.cpp +++ b/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryGenerator.cpp @@ -7,6 +7,8 @@ #include "MantidGeometry/Rendering/GeometryHandler.h" #include "MantidGeometry/Rendering/OCGeometryHandler.h" +#include <boost/make_shared.hpp> + namespace Mantid { diff --git a/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryHandler.cpp b/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryHandler.cpp index f02531276f33b05bbb8ee41295853f70b9bc0aa5..22dcaa365de290de13d0c9e0d3711804ad0f1799 100644 --- a/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryHandler.cpp +++ b/Code/Mantid/Framework/Geometry/src/Rendering/CacheGeometryHandler.cpp @@ -5,6 +5,8 @@ #include "MantidGeometry/Rendering/CacheGeometryRenderer.h" #include "MantidGeometry/Rendering/CacheGeometryGenerator.h" +#include <boost/make_shared.hpp> + namespace Mantid { namespace Geometry @@ -28,6 +30,15 @@ namespace Mantid Renderer =new CacheGeometryRenderer(); } + boost::shared_ptr<GeometryHandler> CacheGeometryHandler::clone() const + { + auto clone = boost::make_shared<CacheGeometryHandler>(*this); + clone->Renderer = new CacheGeometryRenderer(*(this->Renderer)); + if(this->Triangulator) clone->Triangulator = new CacheGeometryGenerator(this->Obj); + else clone->Triangulator = NULL; + return clone; + } + CacheGeometryHandler::~CacheGeometryHandler() { if(Triangulator!=NULL) delete Triangulator; diff --git a/Code/Mantid/Framework/Geometry/src/Rendering/GluGeometryHandler.cpp b/Code/Mantid/Framework/Geometry/src/Rendering/GluGeometryHandler.cpp index 9b4fc9f21e28c9819a0aa153d4e3af0d529c39b6..7bc5b872bdd53b02c23fb9f34b0d2ac27fb720bc 100644 --- a/Code/Mantid/Framework/Geometry/src/Rendering/GluGeometryHandler.cpp +++ b/Code/Mantid/Framework/Geometry/src/Rendering/GluGeometryHandler.cpp @@ -4,6 +4,8 @@ #include "MantidGeometry/Rendering/GluGeometryHandler.h" #include "MantidGeometry/Rendering/GluGeometryRenderer.h" +#include <boost/make_shared.hpp> + namespace Mantid { namespace Geometry @@ -25,6 +27,13 @@ namespace Mantid Renderer =new GluGeometryRenderer(); } + boost::shared_ptr<GeometryHandler> GluGeometryHandler::clone() const + { + auto clone = boost::make_shared<GluGeometryHandler>(*this); + clone->Renderer = new GluGeometryRenderer(); // overwrite the renderer + return clone; + } + GluGeometryHandler::~GluGeometryHandler() { if(Renderer !=NULL) delete Renderer; diff --git a/Code/Mantid/Framework/Geometry/src/Rendering/OCGeometryHandler.cpp b/Code/Mantid/Framework/Geometry/src/Rendering/OCGeometryHandler.cpp index 6d92d211b3246722afdea9931ddda14e37a350d9..10011577f42ac9e812d6b2aa2a3888a33e24b4c5 100644 --- a/Code/Mantid/Framework/Geometry/src/Rendering/OCGeometryHandler.cpp +++ b/Code/Mantid/Framework/Geometry/src/Rendering/OCGeometryHandler.cpp @@ -5,6 +5,8 @@ #include "MantidGeometry/Rendering/OCGeometryGenerator.h" #include "MantidGeometry/Rendering/OCGeometryRenderer.h" +#include <boost/make_shared.hpp> + namespace Mantid { namespace Geometry @@ -27,6 +29,14 @@ namespace Mantid Renderer =new OCGeometryRenderer(); } + boost::shared_ptr<GeometryHandler> OCGeometryHandler::clone() const + { + auto clone = boost::make_shared<OCGeometryHandler>(*this); + clone->Renderer = new OCGeometryRenderer(*(this->Renderer)); + if(this->Triangulator) clone->Triangulator = new OCGeometryGenerator(this->Obj); + return clone; + } + OCGeometryHandler::~OCGeometryHandler() { if(Triangulator!=NULL) delete Triangulator; diff --git a/Code/Mantid/Framework/Geometry/test/ObjectTest.h b/Code/Mantid/Framework/Geometry/test/ObjectTest.h index f32e628f9fa4f44fa751a1bae1c82f8f993d0150..bc51c9c2d46cca0be521e582ec090d301e12df6f 100644 --- a/Code/Mantid/Framework/Geometry/test/ObjectTest.h +++ b/Code/Mantid/Framework/Geometry/test/ObjectTest.h @@ -21,6 +21,9 @@ #include "MantidGeometry/Objects/Track.h" #include "MantidGeometry/Rendering/GluGeometryHandler.h" #include "MantidGeometry/Objects/BoundingBox.h" +#include "MantidGeometry/Objects/ShapeFactory.h" + +#include "MantidTestHelpers/ComponentCreationHelper.h" using namespace Mantid; using namespace Geometry; @@ -31,6 +34,48 @@ class ObjectTest: public CxxTest::TestSuite public: + void testCopyConstructorGivesObjectWithSameAttributes() + { + Object_sptr original = ComponentCreationHelper::createSphere(1.0, V3D(), "sphere"); + int objType(-1); + double radius(-1.0), height(-1.0); + std::vector<V3D> pts; + original->GetObjectGeom(objType, pts, radius, height); + TS_ASSERT_EQUALS(2, objType); + TS_ASSERT(boost::dynamic_pointer_cast<GluGeometryHandler>(original->getGeometryHandler())); + + Object copy(*original); + // The copy should be a primitive object with a GluGeometryHandler + objType = -1; + copy.GetObjectGeom(objType, pts, radius, height); + + TS_ASSERT_EQUALS(2, objType); + TS_ASSERT(boost::dynamic_pointer_cast<GluGeometryHandler>(copy.getGeometryHandler())); + TS_ASSERT_EQUALS(copy.getName(), original->getName()); + // Check the string representation is the same + TS_ASSERT_EQUALS(copy.str(), original->str()); + TS_ASSERT_EQUALS(copy.getSurfaceIndex(), original->getSurfaceIndex()); + } + + void testAssignmentOperatorGivesObjectWithSameAttributes() + { + Object_sptr original = ComponentCreationHelper::createSphere(1.0, V3D(), "sphere"); + int objType(-1); + double radius(-1.0), height(-1.0); + std::vector<V3D> pts; + original->GetObjectGeom(objType, pts, radius, height); + TS_ASSERT_EQUALS(2, objType); + TS_ASSERT(boost::dynamic_pointer_cast<GluGeometryHandler>(original->getGeometryHandler())); + + Object lhs; // initialize + lhs = *original; // assign + // The copy should be a primitive object with a GluGeometryHandler + objType = -1; + lhs.GetObjectGeom(objType, pts, radius, height); + + TS_ASSERT_EQUALS(2, objType); + TS_ASSERT(boost::dynamic_pointer_cast<GluGeometryHandler>(lhs.getGeometryHandler())); + } void testCreateUnitCube() {