void MainHost::LoadProjectFile(const QString &filename) { if(!programsModel->userWantsToUnloadProject()) return; QString name = filename; if(name.isEmpty()) { QString lastDir = GetSetting("lastProjectDir").toString(); name = QFileDialog::getOpenFileName(mainWindow, tr("Open a Project file"), lastDir, tr("Project Files (*.%1)").arg(PROJECT_FILE_EXTENSION)); } if(name.isEmpty()) return; undoStack.clear(); if(ProjectFile::LoadFromFile(this,name)) { ConfigDialog::AddRecentProjectFile(name,this); currentProjectFile = name; } else { ConfigDialog::RemoveRecentProjectFile(name,this); ClearProject(); } emit currentFileChanged(); }
//--------------------------------------------------------------------------- void __fastcall TNewEn::btnOpenClick(TObject *Sender) { OpenDialog->Filter = "Model File|*.xml"; OpenDialog->DefaultExt = "*.XML"; OpenDialog->FileName = "*.XML"; if(g_pProject->m_bModified) { switch (Application->MessageBox("Model File has been modified, save£¿","Hint",MB_YESNOCANCEL)) { case ID_YES : SaveCommand(); break; case ID_CANCEL : return; } } ClearProject(); InitialProject(); if(OpenDialog->Execute()) { g_pProject->m_strFileName=OpenDialog->FileName; AnsiString exten = ExtractFileExt(OpenDialog->FileName); exten = exten.UpperCase(); if(exten == ".XML") { g_pProject->XMLDoc = XMLDocument1; g_pProject->LoadFromXML(g_pProject->m_strFileName); if( graphic==NULL) graphic=new Graphics::TBitmap(); if(g_pProject->m_strLayout.Length()>2) { try { graphic->LoadFromFile(g_pProject->m_strLayout); } catch (Exception &e) { ShowMessage(e.Message);delete graphic;graphic=NULL; } } this->Caption="Smart Environment----"+g_pProject->m_strFileName; } else { return; } FrameProperty->RefreshProjectTree(); Refresh(); } }
bool Application::LoadProject(std::string a_file) { ClearProject(); std::ifstream fs; fs.open(a_file); if (!fs.good()) { printf("Failed to open file '%s'!\n", a_file.c_str()); return false; } Json::Value root; fs >> root; Json::Value node = root["State"]; if (!node.isNull()) { Json::Value val = node["useUpdaterColor"]; if (!val.isNull()) m_projData.parSysOpts[0].useUpdaterColor = val.asBool(); val = node["useUpdaterRelativeForce"]; if (!val.isNull()) m_projData.parSysOpts[0].useUpdaterRelativeForce = val.asBool(); val = node["useUpdaterSize"]; if (!val.isNull()) m_projData.parSysOpts[0].useUpdaterSize = val.asBool(); } InitParticleSystem(); node = root["Emitters"]; if (!node.isNull()) { for (int i = 0; i < (int)node.size(); ++i) { EDataItem e; Json::Value val = node[i]["ID"]; if (!val.isNull()) e.first.ID = val.asInt(); val = node[i]["type"]; if (!val.isNull()) e.first.type = val.asInt(); val = node[i]["on"]; if (!val.isNull()) e.first.on = val.asBool(); val = node[i]["posGenMethod"]; if (!val.isNull()) e.first.posGenMethod = val.asInt(); val = node[i]["velGenMethod"]; if (!val.isNull()) e.first.velGenMethod = val.asInt(); val = node[i]["relativeForce"]; if (!val.isNull()) e.first.relativeForce = val.asFloat(); val = node[i]["velocity"]; if (!val.isNull()) e.first.velocity = val.asFloat(); val = node[i]["rate"]; if (!val.isNull()) e.first.rate = val.asFloat(); val = node[i]["life"]; if (!val.isNull()) e.first.life = val.asFloat(); val = node[i]["transform"]; if (!val.isNull()) { std::vector<float> t; Dg::StringToNumberList(val.asString(), ',', std::dec, t); if (t.size() == 7) memcpy(e.first.transform, t.data(), 7 * sizeof(float)); } val = node[i]["boxDim"]; if (!val.isNull()) { std::vector<float> t; Dg::StringToNumberList(val.asString(), ',', std::dec, t); if (t.size() == 3) memcpy(e.first.boxDim, t.data(), 3 * sizeof(float)); } val = node[i]["velCone"]; if (!val.isNull()) { std::vector<float> t; Dg::StringToNumberList(val.asString(), ',', std::dec, t); if (t.size() == 3) memcpy(e.first.velCone, t.data(), 3 * sizeof(float)); } val = node[i]["colors"]; if (!val.isNull()) { std::vector<float> t; Dg::StringToNumberList(val.asString(), ',', std::dec, t); if (t.size() == 8) memcpy(e.first.colors, t.data(), 8 * sizeof(float)); } val = node[i]["sizes"]; if (!val.isNull()) { std::vector<float> t; Dg::StringToNumberList(val.asString(), ',', std::dec, t); if (t.size() == 2) memcpy(e.first.sizes, t.data(), 2 * sizeof(float)); } memcpy(&e.second, &e.first, sizeof(EmitterData)); m_projData.eData.push_back(e); m_IDManager.MarkAsUsed(e.first.ID); EmitterFactory eFact; m_particleSystem.AddEmitter(e.first.ID, eFact(e.first)); m_projData.emitterFocus = 0; } } node = root["Attractors"]; if (!node.isNull()) { for (int i = 0; i < (int)node.size(); ++i) { ADataItem a; Json::Value val; val = node[i]["ID"]; if (!val.isNull()) a.first.ID = val.asInt(); val = node[i]["attenuationMethod"]; if (!val.isNull()) a.first.attenuationMethod = val.asInt(); val = node[i]["maxAppliedAccelMag"]; if (!val.isNull()) a.first.maxAppliedAccelMag = val.asFloat(); val = node[i]["show"]; if (!val.isNull()) a.first.show = val.asBool(); val = node[i]["strength"]; if (!val.isNull()) a.first.strength = val.asFloat(); val = node[i]["type"]; if (!val.isNull()) a.first.type = val.asInt(); val = node[i]["transform"]; if (!val.isNull()) { std::vector<float> t; Dg::StringToNumberList(val.asString(), ',', std::dec, t); if (t.size() == 6) memcpy(a.first.transform, t.data(), 6 * sizeof(float)); } memcpy(&a.second, &a.first, sizeof(AttractorData)); m_projData.aData.push_back(a); m_IDManager.MarkAsUsed(a.first.ID); AttractorFactory aFact; m_particleSystem.AddUpdater(a.first.ID, aFact(a.first)); m_projData.attrFocus = 0; } } UpdateProjectTitle(a_file); m_projData.dirty = false; return true; }