Commit 24c86b59 authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Add an id attribute to an Object

Refs #16044
parent 5914bfee
...@@ -74,9 +74,11 @@ public: ...@@ -74,9 +74,11 @@ public:
/// Return the top rule /// Return the top rule
const Rule *topRule() const { return TopRule.get(); } const Rule *topRule() const { return TopRule.get(); }
void setID(const std::string &id) { m_id = id; }
inline const std::string &id() const { return m_id; }
void setName(const int nx) { ObjName = nx; } ///< Set Name void setName(const int nx) { ObjNum = nx; } ///< Set Name
int getName() const { return ObjName; } ///< Get Name int getName() const { return ObjNum; } ///< Get Name
void setMaterial(const Kernel::Material &material); void setMaterial(const Kernel::Material &material);
const Kernel::Material &material() const; const Kernel::Material &material() const;
...@@ -170,14 +172,10 @@ public: ...@@ -170,14 +172,10 @@ public:
std::string getShapeXML() const; std::string getShapeXML() const;
private: private:
int ObjName; ///< Creation number
std::unique_ptr<Rule> TopRule; ///< Top rule [ Geometric scope of object]
int procPair(std::string &Ln, std::map<int, std::unique_ptr<Rule>> &Rlist, int procPair(std::string &Ln, std::map<int, std::unique_ptr<Rule>> &Rlist,
int &compUnit) const; int &compUnit) const;
std::unique_ptr<CompGrp> procComp(std::unique_ptr<Rule>) const; std::unique_ptr<CompGrp> procComp(std::unique_ptr<Rule>) const;
int checkSurfaceValid(const Kernel::V3D &, const Kernel::V3D &) const; int checkSurfaceValid(const Kernel::V3D &, const Kernel::V3D &) const;
BoundingBox m_boundingBox; ///< Object's bounding box
/// Calculate bounding box using Rule system /// Calculate bounding box using Rule system
void calcBoundingBoxByRule(); void calcBoundingBoxByRule();
...@@ -188,17 +186,6 @@ private: ...@@ -188,17 +186,6 @@ private:
/// Calculate bounding box using object's geometric data /// Calculate bounding box using object's geometric data
void calcBoundingBoxByGeometry(); void calcBoundingBoxByGeometry();
// -- DEPRECATED --
mutable double AABBxMax, ///< xmax of Axis aligned bounding box cache
AABByMax, ///< ymax of Axis aligned bounding box cache
AABBzMax, ///< zmax of Axis aligned bounding box cache
AABBxMin, ///< xmin of Axis aligned bounding box cache
AABByMin, ///< xmin of Axis aligned bounding box cache
AABBzMin; ///< zmin of Axis Aligned Bounding Box Cache
mutable bool boolBounded; ///< flag true if a bounding box exists, either by
/// getBoundingBox or defineBoundingBox
// -- --
int searchForObject(Kernel::V3D &) const; int searchForObject(Kernel::V3D &) const;
double getTriangleSolidAngle(const Kernel::V3D &a, const Kernel::V3D &b, double getTriangleSolidAngle(const Kernel::V3D &a, const Kernel::V3D &b,
const Kernel::V3D &c, const Kernel::V3D &c,
...@@ -217,6 +204,21 @@ private: ...@@ -217,6 +204,21 @@ private:
const Mantid::Kernel::V3D &axis, const double radius, const Mantid::Kernel::V3D &axis, const double radius,
const double height) const; const double height) const;
/// Top rule [ Geometric scope of object]
std::unique_ptr<Rule> TopRule;
/// Object's bounding box
BoundingBox m_boundingBox;
// -- DEPRECATED --
mutable double AABBxMax, ///< xmax of Axis aligned bounding box cache
AABByMax, ///< ymax of Axis aligned bounding box cache
AABBzMax, ///< zmax of Axis aligned bounding box cache
AABBxMin, ///< xmin of Axis aligned bounding box cache
AABByMin, ///< xmin of Axis aligned bounding box cache
AABBzMin; ///< zmin of Axis Aligned Bounding Box Cache
mutable bool boolBounded; ///< flag true if a bounding box exists, either by
/// Creation number
int ObjNum;
/// Geometry Handle for rendering /// Geometry Handle for rendering
boost::shared_ptr<GeometryHandler> handle; boost::shared_ptr<GeometryHandler> handle;
friend class CacheGeometryHandler; friend class CacheGeometryHandler;
...@@ -234,6 +236,8 @@ private: ...@@ -234,6 +236,8 @@ private:
double *getTriangleVertices() const; double *getTriangleVertices() const;
/// original shape xml used to generate this object. /// original shape xml used to generate this object.
std::string m_shapeXML; std::string m_shapeXML;
/// Optional string identifier
std::string m_id;
/// material composition /// material composition
Kernel::Material m_material; Kernel::Material m_material;
......
...@@ -34,28 +34,19 @@ using Kernel::Quat; ...@@ -34,28 +34,19 @@ using Kernel::Quat;
/** /**
* Default constuctor * Default constuctor
*/ */
Object::Object() Object::Object() : Object("") {}
: ObjName(0), TopRule(), m_boundingBox(), AABBxMax(0), AABByMax(0),
AABBzMax(0), AABBxMin(0), AABByMin(0), AABBzMin(0), boolBounded(false),
handle(), bGeometryCaching(false),
vtkCacheReader(boost::shared_ptr<vtkGeometryCacheReader>()),
vtkCacheWriter(boost::shared_ptr<vtkGeometryCacheWriter>()),
m_material() // empty by default
{
handle = boost::make_shared<CacheGeometryHandler>(this);
}
/** /**
* Construct with original shape xml knowledge. * Construct with original shape xml knowledge.
* @param shapeXML : string with original shape xml. * @param shapeXML : string with original shape xml.
*/ */
Object::Object(const std::string &shapeXML) Object::Object(const std::string &shapeXML)
: ObjName(0), TopRule(), m_boundingBox(), AABBxMax(0), AABByMax(0), : TopRule(), m_boundingBox(), AABBxMax(0), AABByMax(0), AABBzMax(0),
AABBzMax(0), AABBxMin(0), AABByMin(0), AABBzMin(0), boolBounded(false), AABBxMin(0), AABByMin(0), AABBzMin(0), boolBounded(false), ObjNum(0),
handle(), bGeometryCaching(false), handle(), bGeometryCaching(false),
vtkCacheReader(boost::shared_ptr<vtkGeometryCacheReader>()), vtkCacheReader(boost::shared_ptr<vtkGeometryCacheReader>()),
vtkCacheWriter(boost::shared_ptr<vtkGeometryCacheWriter>()), vtkCacheWriter(boost::shared_ptr<vtkGeometryCacheWriter>()),
m_shapeXML(shapeXML), m_material() // empty by default m_shapeXML(shapeXML), m_id(), m_material() // empty by default
{ {
handle = boost::make_shared<CacheGeometryHandler>(this); handle = boost::make_shared<CacheGeometryHandler>(this);
} }
...@@ -64,17 +55,7 @@ Object::Object(const std::string &shapeXML) ...@@ -64,17 +55,7 @@ Object::Object(const std::string &shapeXML)
* Copy constructor * Copy constructor
* @param A :: The object to initialise this copy from * @param A :: The object to initialise this copy from
*/ */
Object::Object(const Object &A) Object::Object(const Object &A) : Object() { *this = A; }
: ObjName(A.ObjName), TopRule((A.TopRule) ? A.TopRule->clone() : nullptr),
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),
handle(A.handle->clone()), bGeometryCaching(A.bGeometryCaching),
vtkCacheReader(A.vtkCacheReader), vtkCacheWriter(A.vtkCacheWriter),
m_shapeXML(A.m_shapeXML), m_material(A.m_material) {
if (TopRule)
createSurfaceList();
}
/** /**
* Assignment operator * Assignment operator
...@@ -83,7 +64,6 @@ Object::Object(const Object &A) ...@@ -83,7 +64,6 @@ Object::Object(const Object &A)
*/ */
Object &Object::operator=(const Object &A) { Object &Object::operator=(const Object &A) {
if (this != &A) { if (this != &A) {
ObjName = A.ObjName;
TopRule = (A.TopRule) ? A.TopRule->clone() : nullptr; TopRule = (A.TopRule) ? A.TopRule->clone() : nullptr;
AABBxMax = A.AABBxMax; AABBxMax = A.AABBxMax;
AABByMax = A.AABByMax; AABByMax = A.AABByMax;
...@@ -92,11 +72,13 @@ Object &Object::operator=(const Object &A) { ...@@ -92,11 +72,13 @@ Object &Object::operator=(const Object &A) {
AABByMin = A.AABByMin; AABByMin = A.AABByMin;
AABBzMin = A.AABBzMin; AABBzMin = A.AABBzMin;
boolBounded = A.boolBounded; boolBounded = A.boolBounded;
ObjNum = A.ObjNum;
handle = A.handle->clone(); handle = A.handle->clone();
bGeometryCaching = A.bGeometryCaching; bGeometryCaching = A.bGeometryCaching;
vtkCacheReader = A.vtkCacheReader; vtkCacheReader = A.vtkCacheReader;
vtkCacheWriter = A.vtkCacheWriter; vtkCacheWriter = A.vtkCacheWriter;
m_shapeXML = A.m_shapeXML; m_shapeXML = A.m_shapeXML;
m_id = A.m_id;
m_material = A.m_material; m_material = A.m_material;
if (TopRule) if (TopRule)
...@@ -145,7 +127,7 @@ int Object::setObject(const int ON, const std::string &Ln) { ...@@ -145,7 +127,7 @@ int Object::setObject(const int ON, const std::string &Ln) {
if (procString(Ln)) // this currently does not fail: if (procString(Ln)) // this currently does not fail:
{ {
SurList.clear(); SurList.clear();
ObjName = ON; ObjNum = ON;
return 1; return 1;
} }
...@@ -235,7 +217,7 @@ int Object::complementaryObject(const int Cnum, std::string &Ln) { ...@@ -235,7 +217,7 @@ int Object::complementaryObject(const int Cnum, std::string &Ln) {
std::string Part = Ln.substr(posA, posB - (posA + 1)); std::string Part = Ln.substr(posA, posB - (posA + 1));
ObjName = Cnum; ObjNum = Cnum;
if (procString(Part)) { if (procString(Part)) {
SurList.clear(); SurList.clear();
Ln.erase(posA - 1, posB + 1); // Delete brackets ( Part ) . Ln.erase(posA - 1, posB + 1); // Delete brackets ( Part ) .
...@@ -602,7 +584,7 @@ void Object::print() const { ...@@ -602,7 +584,7 @@ void Object::print() const {
} }
} }
std::cout << "Name == " << ObjName << std::endl; std::cout << "Name == " << ObjNum << std::endl;
std::cout << "Rules == " << Rcount << std::endl; std::cout << "Rules == " << Rcount << std::endl;
std::vector<int>::const_iterator mc; std::vector<int>::const_iterator mc;
std::cout << "Surface included == "; std::cout << "Surface included == ";
...@@ -626,7 +608,7 @@ void Object::makeComplement() { ...@@ -626,7 +608,7 @@ void Object::makeComplement() {
* Displays the rule tree * Displays the rule tree
*/ */
void Object::printTree() const { void Object::printTree() const {
std::cout << "Name == " << ObjName << std::endl; std::cout << "Name == " << ObjNum << std::endl;
std::cout << TopRule->display() << std::endl; std::cout << TopRule->display() << std::endl;
return; return;
} }
...@@ -651,7 +633,7 @@ std::string Object::cellCompStr() const { ...@@ -651,7 +633,7 @@ std::string Object::cellCompStr() const {
std::string Object::str() const { std::string Object::str() const {
std::ostringstream cx; std::ostringstream cx;
if (TopRule) { if (TopRule) {
cx << ObjName << " "; cx << ObjNum << " ";
cx << TopRule->display(); cx << TopRule->display();
} }
return cx.str(); return cx.str();
......
...@@ -55,6 +55,7 @@ public: ...@@ -55,6 +55,7 @@ public:
void testCopyConstructorGivesObjectWithSameAttributes() { void testCopyConstructorGivesObjectWithSameAttributes() {
Object_sptr original = Object_sptr original =
ComponentCreationHelper::createSphere(1.0, V3D(), "sphere"); ComponentCreationHelper::createSphere(1.0, V3D(), "sphere");
original->setID("sp-1");
int objType(-1); int objType(-1);
double radius(-1.0), height(-1.0); double radius(-1.0), height(-1.0);
std::vector<V3D> pts; std::vector<V3D> pts;
...@@ -68,6 +69,7 @@ public: ...@@ -68,6 +69,7 @@ public:
objType = -1; objType = -1;
copy.GetObjectGeom(objType, pts, radius, height); copy.GetObjectGeom(objType, pts, radius, height);
TS_ASSERT_EQUALS("sp-1", copy.id());
TS_ASSERT_EQUALS(2, objType); TS_ASSERT_EQUALS(2, objType);
TS_ASSERT(boost::dynamic_pointer_cast<GluGeometryHandler>( TS_ASSERT(boost::dynamic_pointer_cast<GluGeometryHandler>(
copy.getGeometryHandler())); copy.getGeometryHandler()));
...@@ -80,6 +82,7 @@ public: ...@@ -80,6 +82,7 @@ public:
void testAssignmentOperatorGivesObjectWithSameAttributes() { void testAssignmentOperatorGivesObjectWithSameAttributes() {
Object_sptr original = Object_sptr original =
ComponentCreationHelper::createSphere(1.0, V3D(), "sphere"); ComponentCreationHelper::createSphere(1.0, V3D(), "sphere");
original->setID("sp-1");
int objType(-1); int objType(-1);
double radius(-1.0), height(-1.0); double radius(-1.0), height(-1.0);
std::vector<V3D> pts; std::vector<V3D> pts;
...@@ -94,6 +97,7 @@ public: ...@@ -94,6 +97,7 @@ public:
objType = -1; objType = -1;
lhs.GetObjectGeom(objType, pts, radius, height); lhs.GetObjectGeom(objType, pts, radius, height);
TS_ASSERT_EQUALS("sp-1", lhs.id());
TS_ASSERT_EQUALS(2, objType); TS_ASSERT_EQUALS(2, objType);
TS_ASSERT(boost::dynamic_pointer_cast<GluGeometryHandler>( TS_ASSERT(boost::dynamic_pointer_cast<GluGeometryHandler>(
lhs.getGeometryHandler())); lhs.getGeometryHandler()));
......
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