MCPcopy Create free account
hub / github.com/NatLabRockies/SAM / SaveDefaults

Method SaveDefaults

src/case.cpp:567–627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565}
566
567bool Case::SaveDefaults(bool quiet)
568{
569 if (!m_config)
570 {
571 return false;
572 }
573 wxString file;
574 file = SamApp::GetRuntimePath() + "/defaults/"
575 + m_config->TechnologyFullName + "_" + m_config->Financing + ".json";
576 if (!quiet && wxNO == wxMessageBox("Save defaults for configuration:\n\n"
577 + m_config->TechnologyFullName + " / " + m_config->Financing,
578 "Save Defaults", wxYES_NO))
579 return false;
580
581
582 rapidjson::Document doc;
583 doc.SetObject();
584
585 for (size_t i = 0; i < m_config->Technology.size(); i++) {
586
587 // set default library_folder_list blank
588 VarValue* vv = m_vals[i].Get("library_folder_list");
589 if (vv) vv->Set(wxString("x"));
590
591 wxArrayString asCalculated, asIndicator;
592 auto& vil = Variables(i);
593 for (auto& var : vil) {
594 if (var.second->Flags & VF_CHANGE_MODEL)
595 continue;
596 else if (var.second->Flags & VF_CALCULATED)
597 asCalculated.push_back(var.first);
598 else if (var.second->Flags & VF_INDICATOR)
599 asIndicator.push_back(var.first);
600 }
601
602 if (m_config->Technology.size()>1) { //hybrid - write out compute module
603 rapidjson::Document json_table(&doc.GetAllocator()); // for table inside of json document.
604 m_vals[i].Write_JSON(json_table, asCalculated, asIndicator);
605 wxString name = m_config->Technology[i];
606 doc.AddMember(rapidjson::Value(name.c_str(), (rapidjson::SizeType)name.size(), doc.GetAllocator()).Move(), json_table.Move(), doc.GetAllocator());
607 }
608 else {
609 m_vals[i].Write_JSON(doc, asCalculated, asIndicator);
610 }
611
612 }
613
614
615 rapidjson::StringBuffer os;
616 rapidjson::PrettyWriter<rapidjson::StringBuffer, rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator, rapidjson::kWriteNanAndInfFlag> writer(os); // MSPT/MP 64MB JSON, 6.7MB txt, JSON Zip 242kB
617 doc.Accept(writer);
618 wxString sfn = file;
619 wxFileName fn(sfn);
620 wxFFileOutputStream out(sfn);
621 out.Write(os.GetString(), os.GetSize());
622 out.Close();
623
624 wxLogStatus("Case: defaults saved for " + file);

Callers 2

fcall_overwrite_defaultsFunction · 0.80
OnInternalCommandMethod · 0.80

Calls 7

SetObjectMethod · 0.80
sizeMethod · 0.80
GetMethod · 0.45
SetMethod · 0.45
Write_JSONMethod · 0.45
WriteMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected