/** Valued constructor * @param n :: name of the assembly * @param reference :: the parent Component * * If the reference is an object of class Component, * normal parenting apply. If the reference object is * an assembly itself, then in addition to parenting * this is registered as a children of reference. */ ObjCompAssembly::ObjCompAssembly(const std::string &n, IComponent *reference) : ObjComponent(n, reference) { if (reference) { ICompAssembly *test = dynamic_cast<ICompAssembly *>(reference); if (test) test->add(this); } }
/** Valued constructor * @param n :: name of the assembly * @param reference :: the parent Component * * If the reference is an object of class Component, * normal parenting apply. If the reference object is * an assembly itself, then in addition to parenting * this is registered as a children of reference. */ CompAssembly::CompAssembly(const std::string &n, IComponent *reference) : Component(n, reference), m_children(), m_cachedBoundingBox(NULL) { if (reference) { ICompAssembly *test = dynamic_cast<ICompAssembly *>(reference); if (test) { test->add(this); } } }
size_t InstrumentVisitor::registerComponentAssembly(const ICompAssembly &assembly) { std::vector<IComponent_const_sptr> assemblyChildren; assembly.getChildren(assemblyChildren, false /*is recursive*/); const size_t detectorStart = m_assemblySortedDetectorIndices->size(); const size_t componentStart = m_assemblySortedComponentIndices->size(); std::vector<size_t> children(assemblyChildren.size()); for (size_t i = 0; i < assemblyChildren.size(); ++i) { // register everything under this assembly children[i] = assemblyChildren[i]->registerContents(*this); } const size_t detectorStop = m_assemblySortedDetectorIndices->size(); const size_t componentIndex = commonRegistration(assembly); m_componentType->push_back(Beamline::ComponentType::Unstructured); m_assemblySortedComponentIndices->push_back(componentIndex); // Unless this is the root component this parent is not correct and will be // updated later in the register call of the parent. m_parentComponentIndices->push_back(componentIndex); const size_t componentStop = m_assemblySortedComponentIndices->size(); m_detectorRanges->emplace_back(std::make_pair(detectorStart, detectorStop)); m_componentRanges->emplace_back( std::make_pair(componentStart, componentStop)); // Now that we know what the index of the parent is we can apply it to the // children for (const auto &child : children) { (*m_parentComponentIndices)[child] = componentIndex; } m_children->emplace_back(std::move(children)); return componentIndex; }