mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-26 05:58:48 -05:00
Removing more of ProfileFile
This commit is contained in:
@@ -105,18 +105,18 @@ private:
|
||||
virtual std::string initialProfile() const;
|
||||
virtual std::string profileBaseDirectory() const;
|
||||
virtual std::vector<AssetEvent> assetEvents() const;
|
||||
ProfileFile collateBaseWithChanges();
|
||||
ProfileStruct collateBaseWithChanges();
|
||||
|
||||
std::vector<AssetEvent> modifyAssetsToReflectChanges(ProfileFile& pf);
|
||||
void parseAssetFileLines(std::vector<AssetEvent>& results, ProfileFile& pf);
|
||||
std::vector<AssetEvent> modifyAssetsToReflectChanges(ProfileStruct& ps);
|
||||
void parseAssetFileLines(std::vector<AssetEvent>& results, ProfileStruct& ps);
|
||||
|
||||
void modifyPropertiesToReflectChanges(ProfileFile& pf);
|
||||
void modifyPropertiesToReflectChanges(ProfileStruct& ps);
|
||||
virtual std::vector<openspace::properties::Property*> changedProperties();
|
||||
std::string getFullPropertyPath(openspace::properties::Property* prop);
|
||||
virtual std::vector<std::string> changedPropertiesFormatted();
|
||||
virtual std::string currentTimeUTC() const;
|
||||
virtual interaction::NavigationHandler::NavigationState currentCameraState() const;
|
||||
void addCurrentCameraToProfileFile(ProfileFile& pf) const;
|
||||
void addCurrentCameraToProfileFile(ProfileStruct& ps) const;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -43,46 +43,6 @@ namespace openspace {
|
||||
namespace documentation { struct Documentation; }
|
||||
namespace scripting { struct LuaLibrary; }
|
||||
|
||||
const size_t timeLinesExpected = 1;
|
||||
const size_t cameraLinesExpected = 1;
|
||||
const size_t moduleFieldsExpected = 3;
|
||||
const size_t assetFieldsExpected = 3;
|
||||
const size_t propertyFieldsExpected = 3;
|
||||
const size_t keybindingFieldsExpected = 6;
|
||||
const size_t timeFieldsExpected = 2;
|
||||
const size_t cameraNavigationFieldsExpected = 8;
|
||||
const size_t cameraGeoFieldsExpected = 5;
|
||||
const size_t markNodesFieldsExpected = 1;
|
||||
|
||||
const size_t moduleFieldName = 0;
|
||||
const size_t moduleFieldLoaded = 1;
|
||||
const size_t moduleFieldNotLoaded = 2;
|
||||
const size_t assetFieldName = 0;
|
||||
const size_t assetFieldReqd = 1;
|
||||
const size_t propertyFieldType = 0;
|
||||
const size_t propertyFieldName = 1;
|
||||
const size_t propertyFieldValue = 2;
|
||||
const size_t keybindingFieldKey = 0;
|
||||
const size_t keybindingFieldDoc = 1;
|
||||
const size_t keybindingFieldName = 2;
|
||||
const size_t keybindingFieldGuiPath = 3;
|
||||
const size_t keybindingFieldLocal = 4;
|
||||
const size_t keybindingFieldCommand = 5;
|
||||
const size_t timeFieldType = 0;
|
||||
const size_t timeFieldSet = 1;
|
||||
const size_t cameraFieldType = 0;
|
||||
const size_t cameraNavigationFieldAnchor = 1;
|
||||
const size_t cameraNavigationFieldAim = 2;
|
||||
const size_t cameraNavigationFieldRef = 3;
|
||||
const size_t cameraNavigationFieldPosition = 4;
|
||||
const size_t cameraNavigationFieldUp = 5;
|
||||
const size_t cameraNavigationFieldYaw = 6;
|
||||
const size_t cameraNavigationFieldPitch = 7;
|
||||
const size_t cameraGeoFieldAnchor = 1;
|
||||
const size_t cameraGeoFieldLatitude = 2;
|
||||
const size_t cameraGeoFieldLongitude = 3;
|
||||
const size_t cameraGeoFieldAltitude = 4;
|
||||
|
||||
struct ProfileStruct {
|
||||
// Version
|
||||
struct Version {
|
||||
@@ -173,18 +133,7 @@ ProfileStruct deserialize(const std::vector<std::string>& content);
|
||||
|
||||
std::string convertToSceneFile(const ProfileStruct& ps);
|
||||
|
||||
|
||||
class ProfileFile {
|
||||
public:
|
||||
ProfileStruct profile;
|
||||
/**
|
||||
* Constructs object by reading the contents of a profile file and populates vector
|
||||
* containers for all sections. This only pulls individual line entries into their
|
||||
* proper sections; it does not parse the tab-delimited fields of each line.
|
||||
* \param filename The profile file to read
|
||||
*/
|
||||
ProfileFile(const std::string& filename);
|
||||
};
|
||||
ProfileStruct readFromFile(const std::string& filename);
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
+26
-26
@@ -102,16 +102,16 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
void addAssetsToProfileFile(ProfileFile& pf,
|
||||
void addAssetsToProfileFile(ProfileStruct& ps,
|
||||
const std::vector<Profile::AssetEvent>& allAssets)
|
||||
{
|
||||
pf.profile.assets.clear();
|
||||
ps.assets.clear();
|
||||
for (Profile::AssetEvent a : allAssets) {
|
||||
if (a.eventType != Profile::AssetEventType::Ignore) {
|
||||
ProfileStruct::Asset asset;
|
||||
asset.path = a.name;
|
||||
asset.type = ProfileStruct::Asset::Type::Require;
|
||||
pf.profile.assets.push_back(std::move(asset));
|
||||
ps.assets.push_back(std::move(asset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace {
|
||||
} // namespace
|
||||
|
||||
void Profile::saveCurrentSettingsToProfile(const std::string& filename) {
|
||||
ProfileFile pf = collateBaseWithChanges();
|
||||
ProfileStruct ps = collateBaseWithChanges();
|
||||
|
||||
if (filename.find('/') != std::string::npos) {
|
||||
LERROR("Profile filename must not contain path (/) elements");
|
||||
@@ -182,7 +182,7 @@ void Profile::saveCurrentSettingsToProfile(const std::string& filename) {
|
||||
}
|
||||
|
||||
try {
|
||||
outFile << serialize(pf.profile);
|
||||
outFile << serialize(ps);
|
||||
}
|
||||
catch (const std::ofstream::failure& e) {
|
||||
LERROR("Data write error to file: "
|
||||
@@ -193,8 +193,8 @@ void Profile::saveCurrentSettingsToProfile(const std::string& filename) {
|
||||
}
|
||||
|
||||
std::string Profile::saveCurrentSettingsToProfile_string() {
|
||||
ProfileFile pf = collateBaseWithChanges();
|
||||
return serialize(pf.profile);
|
||||
ProfileStruct ps = collateBaseWithChanges();
|
||||
return serialize(ps);
|
||||
}
|
||||
|
||||
bool Profile::usingProfile() const {
|
||||
@@ -213,7 +213,7 @@ std::string Profile::profileBaseDirectory() const {
|
||||
return _profileBaseDirectory;
|
||||
}
|
||||
|
||||
ProfileFile Profile::collateBaseWithChanges() {
|
||||
ProfileStruct Profile::collateBaseWithChanges() {
|
||||
if (!usingProfile()) {
|
||||
std::string errorMessage = "Program was not started using a profile, "
|
||||
"so cannot use this save-current-settings feature";
|
||||
@@ -222,26 +222,26 @@ ProfileFile Profile::collateBaseWithChanges() {
|
||||
std::string initProfile = initialProfile();
|
||||
std::string inputProfilePath = absPath(_profileBaseDirectory) + "/" + initProfile
|
||||
+ ".profile";
|
||||
ProfileFile pf(inputProfilePath);
|
||||
pf.profile.version = ProfileStruct::Version{};
|
||||
ProfileStruct ps = readFromFile(inputProfilePath);
|
||||
ps.version = ProfileStruct::Version{};
|
||||
|
||||
std::vector<AssetEvent> ass = modifyAssetsToReflectChanges(pf);
|
||||
addAssetsToProfileFile(pf, ass);
|
||||
modifyPropertiesToReflectChanges(pf);
|
||||
std::vector<AssetEvent> ass = modifyAssetsToReflectChanges(ps);
|
||||
addAssetsToProfileFile(ps, ass);
|
||||
modifyPropertiesToReflectChanges(ps);
|
||||
|
||||
// add current time to profile file
|
||||
ProfileStruct::Time time;
|
||||
time.time = currentTimeUTC();
|
||||
time.type = ProfileStruct::Time::Type::Absolute;
|
||||
pf.profile.time = std::move(time);
|
||||
ps.time = std::move(time);
|
||||
|
||||
addCurrentCameraToProfileFile(pf);
|
||||
return pf;
|
||||
addCurrentCameraToProfileFile(ps);
|
||||
return ps;
|
||||
}
|
||||
|
||||
std::vector<Profile::AssetEvent> Profile::modifyAssetsToReflectChanges(ProfileFile& pf) {
|
||||
std::vector<Profile::AssetEvent> Profile::modifyAssetsToReflectChanges(ProfileStruct& ps) {
|
||||
std::vector<AssetEvent> a;
|
||||
parseAssetFileLines(a, pf);
|
||||
parseAssetFileLines(a, ps);
|
||||
AllAssetDetails assetDetails;
|
||||
|
||||
assetDetails.base = a;
|
||||
@@ -260,8 +260,8 @@ std::vector<Profile::AssetEvent> Profile::modifyAssetsToReflectChanges(ProfileFi
|
||||
return assetDetails.base;
|
||||
}
|
||||
|
||||
void Profile::parseAssetFileLines(std::vector<AssetEvent>& results, ProfileFile& pf) {
|
||||
for (ProfileStruct::Asset& a : pf.profile.assets) {
|
||||
void Profile::parseAssetFileLines(std::vector<AssetEvent>& results, ProfileStruct& ps) {
|
||||
for (ProfileStruct::Asset& a : ps.assets) {
|
||||
AssetEvent assetEvent;
|
||||
assetEvent.name = a.path;
|
||||
assetEvent.eventType = [](ProfileStruct::Asset::Type type) {
|
||||
@@ -275,7 +275,7 @@ void Profile::parseAssetFileLines(std::vector<AssetEvent>& results, ProfileFile&
|
||||
}
|
||||
}
|
||||
|
||||
void Profile::modifyPropertiesToReflectChanges(ProfileFile& pf) {
|
||||
void Profile::modifyPropertiesToReflectChanges(ProfileStruct& ps) {
|
||||
std::vector<properties::Property*> changedProps = changedProperties();
|
||||
std::vector<std::string> formattedLines;
|
||||
|
||||
@@ -284,7 +284,7 @@ void Profile::modifyPropertiesToReflectChanges(ProfileFile& pf) {
|
||||
p.setType = ProfileStruct::Property::SetType::SetPropertyValueSingle;
|
||||
p.name = getFullPropertyPath(prop);
|
||||
p.value = prop->getStringValue();
|
||||
pf.profile.properties.push_back(std::move(p));
|
||||
ps.properties.push_back(std::move(p));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ interaction::NavigationHandler::NavigationState Profile::currentCameraState() co
|
||||
return global::navigationHandler.navigationState();
|
||||
}
|
||||
|
||||
void Profile::addCurrentCameraToProfileFile(ProfileFile& pf) const {
|
||||
void Profile::addCurrentCameraToProfileFile(ProfileStruct& ps) const {
|
||||
interaction::NavigationHandler::NavigationState nav = currentCameraState();
|
||||
|
||||
ProfileStruct::CameraNavState camera;
|
||||
@@ -345,7 +345,7 @@ void Profile::addCurrentCameraToProfileFile(ProfileFile& pf) const {
|
||||
}
|
||||
camera.yaw = nav.yaw;
|
||||
camera.pitch = nav.pitch;
|
||||
pf.profile.camera = std::move(camera);
|
||||
ps.camera = std::move(camera);
|
||||
}
|
||||
|
||||
void Profile::convertToSceneFile(const std::string& inProfilePath,
|
||||
@@ -353,7 +353,7 @@ void Profile::convertToSceneFile(const std::string& inProfilePath,
|
||||
{
|
||||
ZoneScoped
|
||||
|
||||
ProfileFile pf(inProfilePath);
|
||||
ProfileStruct ps = readFromFile(inProfilePath);
|
||||
|
||||
std::ofstream outFile;
|
||||
try {
|
||||
@@ -366,7 +366,7 @@ void Profile::convertToSceneFile(const std::string& inProfilePath,
|
||||
}
|
||||
|
||||
try {
|
||||
outFile << openspace::convertToSceneFile(pf.profile);
|
||||
outFile << openspace::convertToSceneFile(ps);
|
||||
}
|
||||
catch (const std::ofstream::failure& e) {
|
||||
LERROR(fmt::format(
|
||||
|
||||
@@ -586,7 +586,7 @@ std::string convertToSceneFile(const ProfileStruct& ps) {
|
||||
return output;
|
||||
}
|
||||
|
||||
ProfileFile::ProfileFile(const std::string& filename) {
|
||||
ProfileStruct readFromFile(const std::string& filename) {
|
||||
std::ifstream inFile;
|
||||
try {
|
||||
inFile.open(filename, std::ifstream::in);
|
||||
@@ -603,7 +603,7 @@ ProfileFile::ProfileFile(const std::string& filename) {
|
||||
content.push_back(std::move(line));
|
||||
}
|
||||
|
||||
profile = deserialize(content);
|
||||
return deserialize(content);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user