/** * @brief Export current configuration to json: this is used to create the JSON files to describe each module */ void Manager::CreateEditorFiles(const string& x_fileName) { try { map<string,vector<string>> moduleCategories; mkjson moduleDescriptionsJson = mkjson::array(); vector<string> moduleTypes; mr_moduleFactory.List(moduleTypes); for(const auto& moduleType : moduleTypes) { ParameterStructure* parameters = mr_parametersFactory.Create(moduleType, moduleType); Module* module = mr_moduleFactory.Create(moduleType, *parameters); moduleCategories[module->GetCategory()].push_back(moduleType); moduleCategories["all"].push_back(moduleType); // JSON file containing all module descriptions moduleDescriptionsJson.push_back(module->Export()); } mkjson moduleCategoriesJson = mkjson::array(); for(const auto& elem : moduleCategories) { mkjson json; json["name"] = elem.first; json["modules"] = mkjson::array(); for(const auto& mod : elem.second) json.at("modules").push_back(mod); moduleCategoriesJson.push_back(json); } // Generate the js files containing ofstream os1("editor/modules/moduleDescriptions.json"); // all module descriptions os1 << multiLine(moduleDescriptionsJson) << endl; os1.close(); ofstream os2("editor/modules/moduleCategories.json"); os2 << multiLine(moduleCategoriesJson) << endl; os2.close(); } catch(MkException& e) { LOG_ERROR(m_logger, "Exception in Manager::Export: "<<e.what()); throw; } }
/** * @brief Export current configuration to xml: this is used to create the XML and JSON files to describe each module */ void Manager::CreateEditorFiles(const string& x_fileName) { try { map<string,vector<string>> categories; Json::Value modules_json; SYSTEM("mkdir -p modules"); vector<string> moduleTypes; mr_moduleFactory.List(moduleTypes); int id = 0; for(const auto& moduleType : moduleTypes) { createEmptyConfigFile("/tmp/config_empty.xml"); ConfigFile config("/tmp/config_empty.xml"); ConfigReader moduleConfig = config.FindRef("application>module[name=\"" + moduleType + "\"]", true); moduleConfig.SetAttribute("id", id); moduleConfig.FindRef("parameters>param[name=\"class\"]", true).SetValue(moduleType); ParameterStructure* parameters = mr_parametersFactory.Create(moduleType, moduleConfig); Module* module = mr_moduleFactory.Create(moduleType, *parameters); modules_json.append(moduleType); // Append to the category categories[module->GetCategory()].push_back(moduleType); categories["all"].push_back(moduleType); // Create the specific XML string file("editor/modules/" + moduleType + ".xml"); ofstream os(file.c_str()); os<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; module->Export(os, 0); delete module; delete parameters; os.close(); id++; } // Generate the js file containing the categories Json::Value categories_json; for(const auto& categ : categories) { for(const auto& mod : categ.second) { categories_json[categ.first].append(mod); } } ofstream of(x_fileName); of << "// This file contain the list of modules and modules categories. Generated automatically and used by the editor" << endl; of << "var availableCategories = " << categories_json << ";" << endl << endl; of << "var availableModules = " << modules_json << ";" << endl << endl; of.close(); } catch(MkException& e) { LOG_ERROR(m_logger, "Exception in Manager::Export: "<<e.what()); throw; } }