diff --git a/include/openspace/scene/profile.h b/include/openspace/scene/profile.h index e42705d56f..2bf8ede6fd 100644 --- a/include/openspace/scene/profile.h +++ b/include/openspace/scene/profile.h @@ -165,44 +165,13 @@ public: static scripting::LuaLibrary luaLibrary(); ProfileData profile; - -protected: - std::string _profileBaseDirectory = "${ASSETS}"; - -private: - struct AllAssetDetails { - std::vector base; - std::vector changed; - }; - virtual std::string initialProfile() const; - virtual std::string profileBaseDirectory() const; - virtual std::vector assetEvents() const; - - std::vector modifyAssetsToReflectChanges(ProfileData& ps); - void parseAssetFileLines(std::vector& results, ProfileData& ps); - - void modifyPropertiesToReflectChanges(ProfileData& ps); - virtual std::vector changedProperties(); - virtual interaction::NavigationHandler::NavigationState currentCameraState() const; }; - std::string serialize(const ProfileData& ps); ProfileData deserialize(const std::vector& content); std::string convertToSceneFile(const ProfileData& ps); -/** - * Reads in a .profile file, converts it to scene/asset equivalent syntax, and - * writes the result to the specified output path. - * \param inProfilePath The .profile file to be converted - * \param outFilePath The output file path that will be written with the converted - * contents (in an .asset file) - */ -void convertProfileToScene(const std::string& inProfilePath, - const std::string& outFilePath); - - } // namespace openspace #endif // __OPENSPACE_CORE___PROFILE___H__ diff --git a/src/scene/profile.cpp b/src/scene/profile.cpp index 4faa969b58..58d3713629 100644 --- a/src/scene/profile.cpp +++ b/src/scene/profile.cpp @@ -431,6 +431,43 @@ namespace { [[ nodiscard ]] std::string parseMarkNodes(const std::string& line, int) { return line; } + + std::vector modifyAssetsToReflectChanges(ProfileData& ps) { + std::vector results; + for (ProfileData::Asset& a : ps.assets) { + Profile::AssetEvent assetEvent; + assetEvent.name = a.path; + assetEvent.eventType = [](ProfileData::Asset::Type type) { + switch (type) { + case ProfileData::Asset::Type::Request: + return Profile::AssetEventType::Request; + case ProfileData::Asset::Type::Require: + return Profile::AssetEventType::Require; + default: throw ghoul::MissingCaseException(); + } + }(a.type); + results.push_back(assetEvent); + } + struct { + std::vector base; + std::vector changed; + } assetDetails; + + assetDetails.base = results; + assetDetails.changed = global::openSpaceEngine.assetEvents(); + + for (unsigned int i = 0; i < assetDetails.changed.size(); i++) { + Profile::AssetEvent event = assetDetails.changed[i]; + + if (event.eventType == Profile::AssetEventType::Add) { + handleChangedAdd(assetDetails.base, i, assetDetails.changed, event.name); + } + else if (event.eventType == Profile::AssetEventType::Remove) { + assetDetails.base.push_back({ event.name, Profile::AssetEventType::Remove }); + } + } + return assetDetails.base; + } } // namespace Profile::Profile(const std::string& filename) { @@ -440,18 +477,43 @@ Profile::Profile(const std::string& filename) { void Profile::saveCurrentSettingsToProfile() { profile.version = ProfileData::CurrentVersion; + // + // Update assets + // std::vector ass = modifyAssetsToReflectChanges(profile); addAssetsToProfileFile(profile, ass); - modifyPropertiesToReflectChanges(profile); + // + // Update properties + // + std::vector nodes = + global::renderEngine.scene()->allSceneGraphNodes(); + std::vector changedProps; + + for (SceneGraphNode* n : nodes) { + checkForChangedProps(changedProps, n); + } + std::vector formattedLines; + + for (properties::Property* prop : changedProps) { + ProfileData::Property p; + p.setType = ProfileData::Property::SetType::SetPropertyValueSingle; + p.name = recurseForFullName(prop->owner()) + prop->identifier(); + p.value = prop->getStringValue(); + profile.properties.push_back(std::move(p)); + } + + // // add current time to profile file + // ProfileData::Time time; time.time = global::timeManager.time().ISO8601(); time.type = ProfileData::Time::Type::Absolute; profile.time = std::move(time); // Camera - interaction::NavigationHandler::NavigationState nav = currentCameraState(); + interaction::NavigationHandler::NavigationState nav = + global::navigationHandler.navigationState(); ProfileData::CameraNavState camera; camera.anchor = nav.anchor; @@ -472,111 +534,6 @@ void Profile::saveCurrentSettingsToProfile() { profile.camera = std::move(camera); } -std::string Profile::initialProfile() const { - return global::configuration.profile; -} - -std::vector Profile::assetEvents() const { - return global::openSpaceEngine.assetEvents(); -} - -std::string Profile::profileBaseDirectory() const { - return _profileBaseDirectory; -} - -std::vector Profile::modifyAssetsToReflectChanges(ProfileData& ps) { - std::vector a; - parseAssetFileLines(a, ps); - AllAssetDetails assetDetails; - - assetDetails.base = a; - assetDetails.changed = assetEvents(); - - for (unsigned int i = 0; i < assetDetails.changed.size(); i++) { - AssetEvent event = assetDetails.changed[i]; - - if (event.eventType == AssetEventType::Add) { - handleChangedAdd(assetDetails.base, i, assetDetails.changed, event.name); - } - else if (event.eventType == AssetEventType::Remove) { - assetDetails.base.push_back({ event.name, Profile::AssetEventType::Remove }); - } - } - return assetDetails.base; -} - -void Profile::parseAssetFileLines(std::vector& results, ProfileData& ps) { - for (ProfileData::Asset& a : ps.assets) { - AssetEvent assetEvent; - assetEvent.name = a.path; - assetEvent.eventType = [](ProfileData::Asset::Type type) { - switch (type) { - case ProfileData::Asset::Type::Request: return AssetEventType::Request; - case ProfileData::Asset::Type::Require: return AssetEventType::Require; - default: throw ghoul::MissingCaseException(); - } - }(a.type); - results.push_back(assetEvent); - } -} - -void Profile::modifyPropertiesToReflectChanges(ProfileData& ps) { - std::vector changedProps = changedProperties(); - std::vector formattedLines; - - for (properties::Property* prop : changedProps) { - ProfileData::Property p; - p.setType = ProfileData::Property::SetType::SetPropertyValueSingle; - p.name = recurseForFullName(prop->owner()) + prop->identifier(); - p.value = prop->getStringValue(); - ps.properties.push_back(std::move(p)); - } -} - -std::vector Profile::changedProperties() { - ZoneScoped - - std::vector nodes = - global::renderEngine.scene()->allSceneGraphNodes(); - std::vector changedProps; - - for (SceneGraphNode* n : nodes) { - checkForChangedProps(changedProps, n); - } - return changedProps; -} - -interaction::NavigationHandler::NavigationState Profile::currentCameraState() const { - return global::navigationHandler.navigationState(); -} - -void convertProfileToScene(const std::string& inProfilePath, - const std::string& outFilePath) -{ - ZoneScoped - - ProfileData ps = readFromFile(inProfilePath); - - std::ofstream outFile; - try { - outFile.open(outFilePath, std::ofstream::out); - } - catch (const std::ofstream::failure& e) { - LERROR(fmt::format( - "Exception opening scene file for write: {} ({})", outFilePath, e.what() - )); - } - - try { - outFile << openspace::convertToSceneFile(ps); - } - catch (const std::ofstream::failure& e) { - LERROR(fmt::format( - "Data write error to scene file: {} ({})", outFilePath, e.what() - )); - } -} - scripting::LuaLibrary Profile::luaLibrary() { return { "", diff --git a/src/scene/profile_lua.inl b/src/scene/profile_lua.inl index e66986380d..99dae7b938 100644 --- a/src/scene/profile_lua.inl +++ b/src/scene/profile_lua.inl @@ -91,7 +91,7 @@ int saveSettingsToProfile(lua_State* L) { } const std::string absFilename = absPath("${ASSETS}/" + saveFilePath + ".profile"); - const bool overwrite = (n == 2) ? ghoul::lua::value< bool>(L, 2) : false; + const bool overwrite = (n == 2) ? ghoul::lua::value(L, 2) : false; LINFOC("3", ghoul::lua::stackInformation(L)); if (FileSys.fileExists(absFilename) && !overwrite) {