#include "BPData.h" BPData::BPData() :/*m_jfp(NULL) ,*/ m_CurrentLayer(-1) , m_Selected(-1) { } //BPData::BPData(FileProcessor* jfp) // :m_jfp(jfp) // , m_CurrentLayer(-1) //{ // if (jfp != nullptr) { // MetaData* pmetadata = m_jfp->GetMetaData(); // pmetadata->LoadLayerByIndex(0); // } //} BPData::~BPData() { /*for (unsigned int i = 0; i < m_Parts.size(); i++) delete m_Parts[i]; m_Parts.clear();*/ for (map::iterator it = m_PartMap.begin(); it != m_PartMap.end(); it++) { Part* part = it->second; delete part; part = NULL; } m_PartMap.clear(); } //void BPData::SetJob(FileProcessor* jfp) //{ // if (jfp == nullptr) // return; // // if (m_JobID == jfp->GetJobUid()) // return; // // m_jfp = jfp; // m_JobID = jfp->GetJobUid(); // // for (map::iterator it = m_PartMap.begin(); it != m_PartMap.end(); it++) { // Part* part = it->second; // delete part; // part = NULL; // } // m_PartMap.clear(); // // /* for (unsigned int i = 0; i < m_Parts.size(); i++) // delete m_Parts[i]; // m_Parts.clear();*/ // vector parts = m_jfp->GetMetaData()->GetPartVec(); // for (size_t i = 0; i < parts.size(); i++) { // Part* part = new Part(parts[i]->id, &parts[i]->partPosBean); // MetaData::Dimensions* dis = parts[i]->dimensions; // //part->SetPartCenter((dis->xmax + dis->xmin) / 2.0, (dis->ymax + dis->ymin) / 2.0); // m_PartMap.insert(pair(part->GetId(), part)); // } // // /* for (int i = 0; i < m_jfp->GetComponentCount(); i++) { // Part* part = new Part(); // MetaData::Dimensions* dis = m_jfp->GetMetaData()->GetPart(i)->dimensions; // part->SetPartCenter((dis->xmax + dis->xmin) / 2.0, (dis->ymax + dis->ymin) / 2.0); // m_PartMap.insert(pair(part->)); // m_Parts.push_back(part); // }*/ // // MetaData* pmetadata = m_jfp->GetMetaData(); // pmetadata->LoadLayerByIndex(0); // //} //Part* BPData::AddPart(MetaData::Part* part) { // if (!part)return nullptr; // MetaData* pmetadata = m_jfp->GetMetaData(); // MetaData::Layer* player = pmetadata->GetPreviewLayer(); // if (player->data_blocks_map.find(part->id) == player->data_blocks_map.end())return nullptr; // Part* temp = new Part(part->id, &part->partPosBean); // //MetaData::Dimensions* dis = part->dimensions; // //temp->SetPartCenter((dis->xmax + dis->xmin) / 2.0, (dis->ymax + dis->ymin) / 2.0); // m_PartMap.insert(pair(temp->GetId(), temp)); // // // // // MetaData::DataBlockList* datas = player->data_blocks_map[part->id]; // // for (unsigned int i = 0; i < datas->size(); ++i) { // BPBinary::BinDataBlock* pdb = pmetadata->GetPreviewData(datas, i); // if (!pdb) continue; // if (pdb->type == BIN_VECTOR) { // for (unsigned int j = 0; j < pdb->point_indexs.size(); ++j) { // BPBinary::VectorPoint* pvp = (BPBinary::VectorPoint*)pdb->point_indexs[j]; // std::vector line; // line.emplace_back(pvp->x1, pvp->y1, 0.0f); // line.emplace_back(pvp->x2, pvp->y2, 0.0f); // temp->AddLine(line); // } // } // else if (pdb->type == BIN_CHAIN) { // //MetaData::ParameterSet *ps = pmetadata->GetParameterSet((*datas)[i]->references->process); // for (unsigned int j = 0; j < pdb->point_indexs.size(); ++j) { // BPBinary::ChainPoint* point = (BPBinary::ChainPoint*)pdb->point_indexs[j]; // std::vector line; // for (unsigned int k = 0; k < point->points.size(); ++k) { // line.emplace_back(point->points[k]->x, point->points[k]->y, 0.0); // } // temp->AddLine(line); // } // } // } // // temp->Update(); // return temp; //} //void BPData::DelPart(MetaData::Part* part) //{ // if (!part)return; // map::iterator it = m_PartMap.find(part->id); // if (it == m_PartMap.end())return; // Part* delpart = m_PartMap[part->id]; // delpart->RemoveData(); // delpart->Update(); // delete delpart; // m_PartMap.erase(part->id); //} //bool BPData::GetLayerData(unsigned int target_layer) //{ // if (m_jfp == NULL) // return false; // // if (target_layer > m_jfp->GetLayerCount()) // return false; // // if (target_layer == m_CurrentLayer) // return true; // m_CurrentLayer = target_layer; // // MetaData* pmetadata = m_jfp->GetMetaData(); // double LayerThickness = m_jfp->GetLayerThickness(); // // MetaData::Layer* player = pmetadata->GetCurrentLayer(); // if (player == NULL || player->index != target_layer) { // if (pmetadata->LoadLayerByIndex(target_layer)) // player = pmetadata->GetCurrentLayer(); // else // return false; // } // // for (map::iterator it = m_PartMap.begin(); it != m_PartMap.end(); it++) { // it->second->RemoveData(); // } // // m_jfp->GetMetaData()->LockMainDB(); // for (std::map::iterator it = player->data_blocks_map.begin(); it != player->data_blocks_map.end(); it++) { // int partid = it->first; // JobMetaData::DataBlockList* datas = it->second; // if (datas == NULL)continue; // // for (unsigned int i = 0; i < datas->size(); ++i) { // BPBinary::BinDataBlock* pdb = pmetadata->GetDataBlock((*datas)[i]); // if (!pdb)break; // if (pdb->type == BIN_VECTOR) { // for (unsigned int j = 0; j < pdb->point_indexs.size(); ++j) { // BPBinary::VectorPoint* pvp = (BPBinary::VectorPoint*)pdb->point_indexs[j]; // std::vector line; // line.emplace_back(pvp->x1, pvp->y1, 0.0); // line.emplace_back(pvp->x2, pvp->y2, 0.0); // m_PartMap[partid]->AddLine(line); // //m_Parts[partid]->AddLine(line); // } // } // else if (pdb->type == BIN_CHAIN) { // //JobMetaData::ParameterSet *ps = pmetadata->GetParameterSet((*datas)[i]->references->process); // //if (!ps)continue; // for (unsigned int j = 0; j < pdb->point_indexs.size(); ++j) { // BPBinary::ChainPoint* point = (BPBinary::ChainPoint*)pdb->point_indexs[j]; // std::vector line; // for (unsigned int k = 0; k < point->points.size(); ++k) { // line.emplace_back(point->points[k]->x, point->points[k]->y, 0.0); // } // m_PartMap[partid]->AddLine(line); // // m_Parts[partid]->AddLine(line); // } // } // } // } // m_jfp->GetMetaData()->UnLockMainDB(); // for (map::iterator it = m_PartMap.begin(); it != m_PartMap.end(); it++) { // it->second->Update(); // } // return true; //} // //bool BPData::GetPrevLayerData(unsigned int target_layer) //{ // if (m_jfp == NULL) // return false; // // if (target_layer > m_jfp->GetLayerCount()) // return false; // // if (target_layer == m_CurrentLayer) // return true; // m_CurrentLayer = target_layer; // // MetaData* pmetadata = m_jfp->GetMetaData(); // double LayerThickness = m_jfp->GetLayerThickness(); // // MetaData::Layer* player = pmetadata->GetPreviewLayer(); // if (player == NULL || player->index != target_layer) { // if (pmetadata->LoadPrevLayerByIndex(target_layer)) // player = pmetadata->GetPreviewLayer(); // else // return false; // } // // for (map::iterator it = m_PartMap.begin(); it != m_PartMap.end(); it++) { // it->second->RemoveData(); // } // // for (std::map::iterator it = player->data_blocks_map.begin(); it != player->data_blocks_map.end(); it++) { // int partid = it->first; // MetaData::DataBlockList* datas = it->second; // if (datas == NULL)continue; // // for (unsigned int i = 0; i < datas->size(); ++i) { // BPBinary::BinDataBlock* pdb = pmetadata->GetPreviewData(datas, i); // if (!pdb) continue; // if (pdb->type == BIN_VECTOR) { // for (unsigned int j = 0; j < pdb->point_indexs.size(); ++j) { // BPBinary::VectorPoint* pvp = (BPBinary::VectorPoint*)pdb->point_indexs[j]; // std::vector line; // line.emplace_back(pvp->x1, pvp->y1, 0.0); // line.emplace_back(pvp->x2, pvp->y2, 0.0); // m_PartMap[partid]->AddLine(line); // } // } // else if (pdb->type == BIN_CHAIN) { // // MetaData::ParameterSet *ps = pmetadata->GetParameterSet((*datas)[i]->references->process); // for (unsigned int j = 0; j < pdb->point_indexs.size(); ++j) { // BPBinary::ChainPoint* point = (BPBinary::ChainPoint*)pdb->point_indexs[j]; // std::vector line; // for (unsigned int k = 0; k < point->points.size(); ++k) { // line.emplace_back(point->points[k]->x, point->points[k]->y, 0.0); // } // m_PartMap[partid]->AddLine(line); // } // } // } // } // // for (map::iterator it = m_PartMap.begin(); it != m_PartMap.end(); it++) { // it->second->Update(); // } // // return true; //} int BPData::Pick(const vl::Actor* actor, double xpos, double ypos) { int rel = -1; for (map::iterator it = m_PartMap.begin(); it != m_PartMap.end(); it++) { Part* part = it->second; if (!part->GetActor()) continue; bool selected = false; if (part->GetActor().get() == actor) { rel = part->GetId(); part->SetLastPos(xpos, ypos); selected = true; } part->SetSelected(selected); } m_Selected = rel; return rel; } Part* BPData::GetSelectedPart(void) { map::iterator it = m_PartMap.find(m_Selected); if (it != m_PartMap.end()) { return m_PartMap[m_Selected]; } else return nullptr; } Part* BPData::GetPart(unsigned int index) { if (m_PartMap.empty())return nullptr; map::iterator it = m_PartMap.find(index); if (it != m_PartMap.end()) { return m_PartMap[index]; } else return nullptr; }