#include "FITKComponentManager.h" #include "FITKModelSet.h" #include "FITKMeshSurface.h" #include "FITKAssElement.h" namespace Interface { QList FITKComponentManager::getModelSet(FITKModelEnum::FITKModelSetType t) { QList sets; //获取数据个数 const int n = this->getDataCount(); for (int i=0;i(this->getDataByIndex(i)); //空指针不操作 if(set == nullptr) continue; //类型一致则记录 if (set->getModelSetType() == t) sets.append(set); //复合集合展开 if( !set->isCombination()) continue; const int nSub = set->getDataCount(); for (int j =0;j < nSub;++j) { FITKModelSet* subSet = set->getDataByIndex(j); if (subSet == nullptr) continue; //类型一致则记录 if (subSet->getModelSetType() == t) sets.append(subSet); } } return sets; } QList FITKComponentManager::getUnInternalModelSet(FITKModelEnum::FITKModelSetType t) { //获取类型符合要求的集合 QList sets = this->getModelSet(t); QList unSets; for (auto s : sets) { if(s == nullptr) continue; //内部集合标记判断 bool isIn = s->isInternal(); if (isIn) continue; unSets.append(s); } return unSets; } QList FITKComponentManager::getMeshSurface(MeshSurfaceType t) { QList surfs; //获取数据个数 const int n = this->getDataCount(); for (int i = 0; i < n; ++i) { FITKMeshSurface* surf = dynamic_cast(this->getDataByIndex(i)); //空指针不操作 if (surf == nullptr) continue; //类型一致则记录 if (surf->getMeshSurfaceType() == t) surfs.append(surf); } return surfs; } QList FITKComponentManager::getUnInternalMeshSurface(MeshSurfaceType t) { //获取类型符合要求的集合 QList surfs = this->getMeshSurface(t); QList unSurfs; for (auto s : surfs) { if (s == nullptr) continue; //内部集合标记判断 bool isIn = s->isInternal(); if (isIn) continue; unSurfs.append(s); } return unSurfs; } bool FITKComponentManager::isModelSet(int index) { auto set = this->getAsModelSet(index); return set != nullptr; } FITKModelSet* FITKComponentManager::getAsModelSet(int index) { return dynamic_cast(this->getDataByIndex(index)); } FITKMeshSurface* FITKComponentManager::getAsMeshSurf(int index) { return dynamic_cast(this->getDataByIndex(index)); } QList FITKComponentManager::getAllSet(bool rec) { QList sets; const int n = getDataCount(); //不递归 if (!rec) { for (int i = 0; i < n; i++) { auto s = this->getAsModelSet(i); if (s == nullptr) continue; sets.append(s); } return sets; } for (int i = 0; i < n; i++) { auto s = this->getAsModelSet(i); if(s == nullptr) continue; //复合集合取出子集合 if (s->isCombination()) { const int nsub = s->getDataCount(); for (int i = 0; i < nsub; ++i) { Interface::FITKModelSet* sub = s->getDataByIndex(i); if (sub) sets.append(sub); } } //不是复合集合 else if (s) sets.append(s); } return sets; } QList FITKComponentManager::getAllSurface() { QList surf; const int n = getDataCount(); for (int i = 0; i < n; i++) { auto s = this->getAsMeshSurf(i); if (s) surf.append(s); } return surf; } void FITKComponentManager::appendDataObj(FITKAbstractDataObject* item) { //是表面,直接添加 FITKMeshSurface* surf = dynamic_cast(item); if (surf) { Core::FITKAbstractDataManager::appendDataObj(item); return; } //装配体单元集合直接添加 FITKAssemblyElementSet* ele = dynamic_cast(item); if (ele) { Core::FITKAbstractDataManager::appendDataObj(item); return; } //强制类型判断 FITKModelSet* set = dynamic_cast(item); if (set == nullptr) return; const QString name = set->getDataObjectName(); //已经存在的set FITKModelSet* existSet = dynamic_cast (this->getDataByName(name)); if (existSet == nullptr) Core::FITKAbstractDataManager::appendDataObj(item); else //已经存在的则合并 mergeSameNameSet(existSet, set); } void FITKComponentManager::insertDataObj(int index, FITKAbstractDataObject* item) { //是表面,直接添加 FITKMeshSurface* surf = dynamic_cast(item); if (surf) { Core::FITKAbstractDataManager::insertDataObj(index,item); return; } //装配体单元集合直接添加 FITKAssemblyElementSet* ele = dynamic_cast(item); if (ele) { Core::FITKAbstractDataManager::appendDataObj(item); return; } //强制类型判断 FITKModelSet* set = dynamic_cast(item); if (set == nullptr) return; const QString name = set->getDataObjectName(); //已经存在的set FITKModelSet* existSet = dynamic_cast (this->getDataByName(name)); if (existSet == nullptr) Core::FITKAbstractDataManager::insertDataObj(index, item); else //已经存在的则合并 mergeSameNameSet(existSet, set); } FITKAbstractModelComponent* FITKComponentManager::getDataByID(const int id) { //首先遍历最外层 FITKAbstractModelComponent* comp = Core::FITKAbstractDataManager::getDataByID(id); if (comp) return comp; for ( FITKAbstractDataObject* data :_dataList) { FITKModelSet* set = dynamic_cast(data); if(set == nullptr) continue; //不是复合集合已经在最外层遍历过 if(!set->isCombination()) continue; const int nsub = set->getDataCount(); //查找set的子集合 comp = set->getDataByID(id); if (comp) return comp; } //没有找到 return nullptr; } FITKModelSet* FITKComponentManager::getModelSetByMember(FITKModelEnum::FITKModelSetType t, const int modelID, const QList &member) { if (member.isEmpty()) return nullptr; QList sets = this->getModelSet(t); //查找相同成员的集合 for (FITKModelSet* set : sets) { if(set == nullptr) continue; if (set->getAbsModelID() != modelID) continue; QList absmem = set->getAbsoluteMember(); if (absmem == member) return set; } //没有找到,创建新的集合 FITKModelSet* set = new FITKModelSet(t); set->setInternal(true); set->setModel(modelID); for (int i : member) set->appendMember(i); set->setDataObjectName(this->checkName("Set-1")); this->appendDataObj(set); return set; } FITKModelSet* FITKComponentManager::getSingleNodeSet(const int modelID, const int memID) { //全部节点集合 QList sets = this->getModelSet(FITKModelEnum::FITKModelSetType::FMSNode); for (auto set :sets) { //父对象判断 if(set->getAbsModelID() != modelID) continue; QList mem = set->getMember(); //只有一个成员 if (mem.size() == 1 && mem.at(0) == memID) return set; } return nullptr; } void FITKComponentManager::mergeSameNameSet(FITKModelSet* existSet, FITKModelSet* newSet) { if (existSet == nullptr || newSet == nullptr) return; //已经存在的是复合集合,直接追加 if (existSet->isCombination()) { existSet->appendDataObj(newSet); return; } //创建新的,并合并已有集合与新集合 FITKModelSet* comSet = new FITKModelSet; comSet->setModelSetType(FITKModelEnum::FITKModelSetType::FMSComb); comSet->setDataObjectName(existSet->getDataObjectName()); comSet->setModel(this->getMParentDataIDM()); //从原有管理器移除,追加到set中 int index = this->getDataIndex(existSet); this->removeDataObjWithoutRelease(existSet); comSet->appendDataObj(existSet); comSet->appendDataObj(newSet); //新的复合集合追加到管理器 Core::FITKAbstractDataManager::insertDataObj(index,comSet); } }