QPixmap Texture2DAssetFile::GetIcon() const { String fp = GetImageFilepath(); // Mini cache static Map<std::string, QPixmap> filepath_To_Pixmap; if (!filepath_To_Pixmap.ContainsKey(fp)) { QPixmap pm(QString::fromStdString(fp)); filepath_To_Pixmap[fp] = pm; } return filepath_To_Pixmap[fp]; }
void RectCutCMPT::OnSaveEditOP(wxCommandEvent& event) { wxFileDialog dlg(this, wxT("Save"), wxEmptyString, wxEmptyString, wxT("*_") + FILTER + wxT(".json"), wxFD_SAVE); if (dlg.ShowModal() == wxID_OK) { auto op = std::dynamic_pointer_cast<RectCutOP>(m_editop); Json::Value value; std::string filepath = op->GetImageFilepath(); std::string dir = ee::FileHelper::GetFileDir(dlg.GetPath().ToStdString()); value["image filepath"] = ee::FileHelper::GetRelativePath(dir, filepath); op->GetRectMgr().Store(value); const sm::vec2& center = op->GetCenter(); value["center"]["x"] = center.x; value["center"]["y"] = center.y; for (int i = 0, n = m_part_rects.size(); i < n; ++i) { const sm::rect& r = m_part_rects[i]; value["part_rect"][i]["xmin"] = r.xmin; value["part_rect"][i]["xmax"] = r.xmax; value["part_rect"][i]["ymin"] = r.ymin; value["part_rect"][i]["ymax"] = r.ymax; } std::string filename = ee::FileHelper::GetFilenameAddTag(dlg.GetPath().ToStdString(), FILTER, "json"); Json::StyledStreamWriter writer; std::locale::global(std::locale("")); std::ofstream fout(filename.c_str()); std::locale::global(std::locale("C")); writer.write(fout, value); fout.close(); } }