mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-23 13:29:12 -06:00
Finished testing new save-settings-to-profile feature
This commit is contained in:
@@ -114,6 +114,7 @@ private:
|
||||
void runGlobalCustomizationScripts();
|
||||
void configureLogging();
|
||||
std::string generateFilePath(std::string openspaceRelativePath);
|
||||
void resetPropertyChangeFlagsOfSubowners(openspace::properties::PropertyOwner* po);
|
||||
|
||||
std::unique_ptr<Scene> _scene;
|
||||
std::unique_ptr<AssetManager> _assetManager;
|
||||
|
||||
@@ -45,6 +45,8 @@ namespace openspace {
|
||||
namespace documentation { struct Documentation; }
|
||||
namespace scripting { struct LuaLibrary; }
|
||||
|
||||
const std::string profileFormatVersion = "1.0";
|
||||
|
||||
class Profile {
|
||||
public:
|
||||
enum class AssetEventType {
|
||||
@@ -68,6 +70,10 @@ public:
|
||||
|
||||
virtual ~Profile() {};
|
||||
|
||||
const std::string formatVersion() {
|
||||
return profileFormatVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all current settings, starting from the profile that was loaded at startup,
|
||||
* and all of the property & asset changes that were made since startup.
|
||||
@@ -106,14 +112,17 @@ public:
|
||||
*/
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
|
||||
protected:
|
||||
std::string _profileBaseDirectory = "${ASSETS}";
|
||||
|
||||
private:
|
||||
struct AllAssetDetails {
|
||||
std::vector<AssetEvent> base;
|
||||
std::vector<AssetEvent> changed;
|
||||
};
|
||||
|
||||
virtual bool usingProfile();
|
||||
virtual std::string initialProfile();
|
||||
virtual std::string profileBaseDirectory();
|
||||
virtual std::vector<AssetEvent> listOfAllAssetEvents();
|
||||
ProfileFile collateBaseWithChanges();
|
||||
std::string convertToScene_assets(ProfileFile& pf);
|
||||
@@ -124,15 +133,18 @@ private:
|
||||
std::string convertToScene_time(ProfileFile& pf);
|
||||
std::string convertToScene_camera(ProfileFile& pf);
|
||||
|
||||
void updateToCurrentFormatVersion(ProfileFile& pf);
|
||||
std::vector<AssetEvent> modifyAssetsToReflectChanges(ProfileFile& pf);
|
||||
void parseAssetFileLines(std::vector<AssetEvent>& results, ProfileFile& pf);
|
||||
void handleChangedAdd(std::vector<AssetEvent>& base, unsigned int changedIdx,
|
||||
std::vector<AssetEvent>& changed, std::string asset);
|
||||
void handleChangedRemove(std::vector<AssetEvent>& base, unsigned int changedIdx,
|
||||
std::vector<AssetEvent>& changed, std::string asset);
|
||||
void handleChangedRemove(std::vector<AssetEvent>& base, std::string asset);
|
||||
void addAssetsToProfileFile(std::vector<AssetEvent>& allAssets, ProfileFile& pf);
|
||||
void modifyPropertiesToReflectChanges(ProfileFile& pf);
|
||||
virtual std::vector<openspace::properties::Property*> getChangedProperties();
|
||||
void checkForChangedProps(std::vector<openspace::properties::Property*>& changedList,
|
||||
openspace::properties::PropertyOwner* po);
|
||||
std::string getFullPropertyPath(openspace::properties::Property* prop);
|
||||
virtual std::vector<std::string> getChangedPropertiesFormatted();
|
||||
virtual std::string getCurrentTimeUTC();
|
||||
virtual interaction::NavigationHandler::NavigationState getCurrentCameraState();
|
||||
|
||||
@@ -211,11 +211,17 @@ public:
|
||||
void addMarkNodesLine(const std::string line);
|
||||
|
||||
/**
|
||||
* Returns the version number (profiles syntax version) string
|
||||
* Returns the format version number (profiles syntax version) string
|
||||
* \return The version string
|
||||
*/
|
||||
const std::string getVersion() const;
|
||||
|
||||
/**
|
||||
* Sets the format version number (profiles syntax version) string
|
||||
* \param The version string to set
|
||||
*/
|
||||
void setVersion(std::string);
|
||||
|
||||
/**
|
||||
* Returns the profile's time string. See updateTime comment header for notes on
|
||||
* syntax of this time string
|
||||
|
||||
@@ -83,6 +83,7 @@ void registerCoreClasses(scripting::ScriptEngine& engine) {
|
||||
engine.addLibrary(ParallelPeer::luaLibrary());
|
||||
engine.addLibrary(RenderEngine::luaLibrary());
|
||||
engine.addLibrary(SpiceManager::luaLibrary());
|
||||
engine.addLibrary(Profile::luaLibrary());
|
||||
engine.addLibrary(Scene::luaLibrary());
|
||||
engine.addLibrary(Time::luaLibrary());
|
||||
engine.addLibrary(interaction::KeybindingManager::luaLibrary());
|
||||
|
||||
@@ -306,14 +306,21 @@ void OpenSpaceEngine::initialize() {
|
||||
std::string outputAsset = outputScenePath + "/" + global::configuration.profile
|
||||
+ ".asset";
|
||||
|
||||
global::profile.convertToSceneFile(inputProfile, outputAsset);
|
||||
if (!FileSys.fileExists(inputProfile)) {
|
||||
LERROR(fmt::format(
|
||||
"Could not load profile '{}': File does not exist", inputProfile)
|
||||
);
|
||||
}
|
||||
else {
|
||||
global::profile.convertToSceneFile(inputProfile, outputAsset);
|
||||
|
||||
// Set asset name to that of the profile because a new scene file will be
|
||||
// created with that name, and also because the profile name will override
|
||||
// an asset name if both are provided.
|
||||
global::configuration.asset =
|
||||
absPath("${TEMPORARY}/") + global::configuration.profile;
|
||||
global::configuration.usingProfile = true;
|
||||
// Set asset name to that of the profile because a new scene file will be
|
||||
// created with that name, and also because the profile name will override
|
||||
// an asset name if both are provided.
|
||||
global::configuration.asset =
|
||||
absPath("${TEMPORARY}/") + global::configuration.profile;
|
||||
global::configuration.usingProfile = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Set up asset loader
|
||||
@@ -1297,10 +1304,18 @@ void OpenSpaceEngine::resetPropertyChangeFlags() {
|
||||
std::vector<SceneGraphNode*> nodes =
|
||||
global::renderEngine.scene()->allSceneGraphNodes();
|
||||
for (auto n : nodes) {
|
||||
std::vector<openspace::properties::Property*> props = n->properties();
|
||||
for (auto p : props) {
|
||||
p->resetToUnchanged();
|
||||
}
|
||||
resetPropertyChangeFlagsOfSubowners(n);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::resetPropertyChangeFlagsOfSubowners(
|
||||
openspace::properties::PropertyOwner* po)
|
||||
{
|
||||
for (auto subOwner : po->propertySubOwners()) {
|
||||
resetPropertyChangeFlagsOfSubowners(subOwner);
|
||||
}
|
||||
for (auto p : po->properties()) {
|
||||
p->resetToUnchanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/util/timemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
@@ -80,6 +81,10 @@ std::vector<Profile::AssetEvent> Profile::listOfAllAssetEvents() {
|
||||
return global::openSpaceEngine.listOfAllAssetEvents();
|
||||
}
|
||||
|
||||
std::string Profile::profileBaseDirectory() {
|
||||
return _profileBaseDirectory;
|
||||
}
|
||||
|
||||
ProfileFile Profile::collateBaseWithChanges() {
|
||||
if (! usingProfile()) {
|
||||
std::string errorMessage = "Program was not started using a profile, "
|
||||
@@ -87,7 +92,10 @@ ProfileFile Profile::collateBaseWithChanges() {
|
||||
LERROR(errorMessage);
|
||||
}
|
||||
std::string initProfile = initialProfile();
|
||||
ProfileFile pf(initProfile);
|
||||
std::string inputProfilePath = absPath(_profileBaseDirectory) + "/" + initProfile
|
||||
+ ".profile";
|
||||
ProfileFile pf(inputProfilePath);
|
||||
updateToCurrentFormatVersion(pf);
|
||||
std::vector<AssetEvent> ass = modifyAssetsToReflectChanges(pf);
|
||||
addAssetsToProfileFile(ass, pf);
|
||||
modifyPropertiesToReflectChanges(pf);
|
||||
@@ -96,6 +104,10 @@ ProfileFile Profile::collateBaseWithChanges() {
|
||||
return pf;
|
||||
}
|
||||
|
||||
void Profile::updateToCurrentFormatVersion(ProfileFile& pf) {
|
||||
pf.setVersion(profileFormatVersion);
|
||||
}
|
||||
|
||||
std::vector<Profile::AssetEvent> Profile::modifyAssetsToReflectChanges(ProfileFile& pf) {
|
||||
std::vector<AssetEvent> a;
|
||||
parseAssetFileLines(a, pf);
|
||||
@@ -111,7 +123,7 @@ std::vector<Profile::AssetEvent> Profile::modifyAssetsToReflectChanges(ProfileFi
|
||||
handleChangedAdd(assetDetails.base, i, assetDetails.changed, event.name);
|
||||
}
|
||||
else if (event.eventType == AssetEventType::remove) {
|
||||
handleChangedRemove(assetDetails.base, i, assetDetails.changed, event.name);
|
||||
handleChangedRemove(assetDetails.base, event.name);
|
||||
}
|
||||
}
|
||||
return assetDetails.base;
|
||||
@@ -147,24 +159,9 @@ void Profile::handleChangedAdd(std::vector<AssetEvent>& base, unsigned int chang
|
||||
}
|
||||
}
|
||||
|
||||
void Profile::handleChangedRemove(std::vector<AssetEvent>& base, unsigned int changedIdx,
|
||||
std::vector<AssetEvent>& changed, std::string asset)
|
||||
void Profile::handleChangedRemove(std::vector<AssetEvent>& base, std::string asset)
|
||||
{
|
||||
//Blank-out any base profile entries where this asset was required/requested
|
||||
for (unsigned int i = 0; i < base.size(); i++) {
|
||||
if (base[i].name == asset) {
|
||||
base[i].name = "";
|
||||
base[i].eventType = AssetEventType::ignore;
|
||||
}
|
||||
}
|
||||
|
||||
//Blank-out any changes profile entries where this asset was required/requested
|
||||
for (unsigned int i = 0; i < changedIdx; i++) {
|
||||
if (changed[i].name == asset) {
|
||||
changed[i].name = "";
|
||||
changed[i].eventType = AssetEventType::ignore;
|
||||
}
|
||||
}
|
||||
base.push_back({asset, AssetEventType::remove});
|
||||
}
|
||||
|
||||
void Profile::addAssetsToProfileFile(std::vector<AssetEvent>& allAssets, ProfileFile& pf)
|
||||
@@ -226,13 +223,44 @@ std::vector<std::string> Profile::getChangedPropertiesFormatted() {
|
||||
|
||||
for (auto prop : changedProps) {
|
||||
std::string newLine = "setPropertyValueSingle\t";
|
||||
newLine += prop->identifier() + "\t";
|
||||
newLine += prop->getStringValue() + "\n";
|
||||
newLine += getFullPropertyPath(prop) + "\t";
|
||||
newLine += prop->getStringValue();
|
||||
formattedLines.push_back(newLine);
|
||||
}
|
||||
return formattedLines;
|
||||
}
|
||||
|
||||
std::string recurseForFullName(openspace::properties::PropertyOwner* po) {
|
||||
std::string path;
|
||||
if (po != nullptr) {
|
||||
std::string name = recurseForFullName(po->owner()) + po->identifier();
|
||||
if (!name.empty()) {
|
||||
path = name + ".";
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string Profile::getFullPropertyPath(openspace::properties::Property* prop) {
|
||||
return recurseForFullName(prop->owner()) + prop->identifier();
|
||||
}
|
||||
|
||||
void Profile::checkForChangedProps(
|
||||
std::vector<openspace::properties::Property*>& changedList,
|
||||
openspace::properties::PropertyOwner* po)
|
||||
{
|
||||
if (po != nullptr) {
|
||||
for (auto subOwner : po->propertySubOwners()) {
|
||||
checkForChangedProps(changedList, subOwner);
|
||||
}
|
||||
for (auto p : po->properties()) {
|
||||
if (p->hasChanged()) {
|
||||
changedList.push_back(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<openspace::properties::Property*> Profile::getChangedProperties()
|
||||
{
|
||||
ZoneScoped
|
||||
@@ -242,25 +270,18 @@ std::vector<openspace::properties::Property*> Profile::getChangedProperties()
|
||||
std::vector<openspace::properties::Property*> changedProps;
|
||||
|
||||
for (auto n : nodes) {
|
||||
if (n != nullptr) {
|
||||
std::vector<openspace::properties::Property*> props = n->properties();
|
||||
for (auto p : props) {
|
||||
if (p->hasChanged()) {
|
||||
changedProps.push_back(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
checkForChangedProps(changedProps, n);
|
||||
}
|
||||
return changedProps;
|
||||
}
|
||||
|
||||
std::string Profile::getCurrentTimeUTC() {
|
||||
return global::timeManager.time().UTC();
|
||||
return global::timeManager.time().ISO8601();
|
||||
}
|
||||
|
||||
void Profile::addCurrentTimeToProfileFile(ProfileFile& pf) {
|
||||
std::string t = getCurrentTimeUTC();
|
||||
std::string update = "absolute\t" + t + "\n";
|
||||
std::string update = "absolute\t" + t;
|
||||
pf.updateTime(update);
|
||||
}
|
||||
|
||||
@@ -272,9 +293,9 @@ void Profile::addCurrentCameraToProfileFile(ProfileFile& pf) {
|
||||
std::string update = "setNavigationState\t";
|
||||
interaction::NavigationHandler::NavigationState nav;
|
||||
nav = getCurrentCameraState();
|
||||
update += nav.anchor + "\t";
|
||||
update += nav.aim + "\t";
|
||||
update += nav.referenceFrame + "\t";
|
||||
update += "\"" + nav.anchor + "\"\t";
|
||||
update += "\"" + nav.aim + "\"\t";
|
||||
update += "\"" + nav.referenceFrame + "\"\t";
|
||||
update += std::to_string(nav.position.x) + ",";
|
||||
update += std::to_string(nav.position.y) + ",";
|
||||
update += std::to_string(nav.position.z) + "\t";
|
||||
@@ -287,7 +308,7 @@ void Profile::addCurrentCameraToProfileFile(ProfileFile& pf) {
|
||||
}
|
||||
update += "\t";
|
||||
update += std::to_string(nav.yaw) + "\t";
|
||||
update += std::to_string(nav.pitch) + "\n";
|
||||
update += std::to_string(nav.pitch);
|
||||
|
||||
pf.updateCamera(update);
|
||||
}
|
||||
@@ -304,21 +325,24 @@ void Profile::convertToSceneFile(const std::string inProfilePath,
|
||||
outFile.open(outFilePath, std::ofstream::out);
|
||||
}
|
||||
catch (std::ofstream::failure& e) {
|
||||
LERROR("Exception opening profile file for write: " + outFilePath);
|
||||
LERROR("Exception opening scene file for write: " + outFilePath
|
||||
+ " (" + e.what() + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
outFile << convertToScene(pf);
|
||||
}
|
||||
catch (std::ofstream::failure& e) {
|
||||
LERROR("Data write error to file: " + outFilePath);
|
||||
LERROR("Data write error to scene file: " + outFilePath
|
||||
+ " (" + e.what() + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
outFile.close();
|
||||
}
|
||||
catch (std::ofstream::failure& e) {
|
||||
LERROR("Exception closing profile file after write: " + outFilePath);
|
||||
LERROR("Exception closing scene file after write: " + outFilePath
|
||||
+ " (" + e.what() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,11 @@ void ProfileFile::readIn(std::string filename) {
|
||||
std::ifstream inFile;
|
||||
|
||||
try {
|
||||
inFile.open(filename, std::_Ios_Openmode::_S_in);
|
||||
inFile.open(filename, std::ifstream::in);
|
||||
}
|
||||
catch (std::ifstream::failure& e) {
|
||||
throw ghoul::RuntimeError("Exception opening profile file for read: "
|
||||
+ filename, "profileFile");
|
||||
+ filename + " (" + e.what() + ")", "profileFile");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -72,16 +72,16 @@ void ProfileFile::readIn(std::string filename) {
|
||||
});
|
||||
}
|
||||
catch (std::ifstream::failure& e) {
|
||||
throw ghoul::RuntimeError(errorString("Read error using getline"),
|
||||
"profileFile");
|
||||
throw ghoul::RuntimeError(errorString("Read error using getline in: "
|
||||
+ filename + " (" + e.what() + ")"), "profileFile");
|
||||
}
|
||||
|
||||
try {
|
||||
inFile.close();
|
||||
}
|
||||
catch (std::ifstream::failure& e) {
|
||||
throw ghoul::RuntimeError("Exception closing profile file after read: "
|
||||
+ filename, "profileFile");
|
||||
throw ghoul::RuntimeError("Exception closing profile file after read in: "
|
||||
+ filename + " (" + e.what() + ")", "profileFile");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,26 +116,51 @@ void ProfileFile::processIndividualLine(bool& insideSection, std::string line) {
|
||||
}
|
||||
|
||||
void ProfileFile::writeToFile(const std::string filename) {
|
||||
if (filename.find("/") != std::string::npos) {
|
||||
LERROR("Profile filename must not contain path (/) elements");
|
||||
return;
|
||||
}
|
||||
else if (filename.find(":") != std::string::npos) {
|
||||
LERROR("Profile filename must not contain path (:) elements");
|
||||
return;
|
||||
}
|
||||
else if (filename.find(".") != std::string::npos) {
|
||||
LERROR("Only provide the filename to save without file extension");
|
||||
return;
|
||||
}
|
||||
const std::string absFilename = absPath("${ASSETS}/" + filename + ".profile");
|
||||
|
||||
if (FileSys.fileExists(absFilename)) {
|
||||
LERROR(fmt::format(
|
||||
"Unable to save profile '{}'. File of same name already exists.",
|
||||
absFilename.c_str()
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
std::ofstream outFile;
|
||||
try {
|
||||
outFile.open(filename, std::ofstream::out | std::ofstream::app);
|
||||
outFile.open(absFilename, std::ofstream::out);
|
||||
}
|
||||
catch (std::ofstream::failure& e) {
|
||||
LERROR("Exception opening profile file for write: " + filename);
|
||||
LERROR("Exception opening profile file for write: "
|
||||
+ absFilename + " (" + e.what() + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
outFile << writeToString();
|
||||
}
|
||||
catch (std::ofstream::failure& e) {
|
||||
LERROR("Data write error to file: " + filename);
|
||||
LERROR("Data write error to file: "
|
||||
+ absFilename + " (" + e.what() + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
outFile.close();
|
||||
}
|
||||
catch (std::ofstream::failure& e) {
|
||||
LERROR("Exception closing profile file after write: " + filename);
|
||||
LERROR("Exception closing profile file after write: "
|
||||
+ absFilename + " (" + e.what() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +194,10 @@ const std::string ProfileFile::getVersion() const {
|
||||
return _version;
|
||||
}
|
||||
|
||||
void ProfileFile::setVersion(std::string v) {
|
||||
_version = v;
|
||||
}
|
||||
|
||||
void ProfileFile::addAllElements(std::string& str, std::vector<std::string>& list) {
|
||||
for (auto s : list) {
|
||||
str += s + '\n';
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace openspace;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace openspace;
|
||||
@@ -421,7 +422,7 @@ end)";
|
||||
|
||||
const std::string detectChangedPropsResult_1 = "\
|
||||
#Version\n\
|
||||
1.0\n\
|
||||
" + profileFormatVersion + "\n\
|
||||
\n\
|
||||
#Module\n\
|
||||
\n\
|
||||
@@ -443,10 +444,8 @@ initialized fourth\tfalse.\n\
|
||||
#Time\n\
|
||||
absolute\t2020-02-29T01:23:45.00\n\
|
||||
\n\
|
||||
\n\
|
||||
#Camera\n\
|
||||
setNavigationState\tEarth\tSun\troot\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
setNavigationState\t\"Earth\"\t\"Sun\"\t\"root\"\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
#MarkNodes\n\
|
||||
Earth\n\
|
||||
@@ -457,7 +456,7 @@ Sun\n\
|
||||
|
||||
const std::string detectChangedAssetsResult_1 = "\
|
||||
#Version\n\
|
||||
1.0\n\
|
||||
" + profileFormatVersion + "\n\
|
||||
\n\
|
||||
#Module\n\
|
||||
\n\
|
||||
@@ -478,10 +477,8 @@ setPropertyValueSingle\tScene.Charon.Renderable.Enabled\tfalse\n\
|
||||
#Time\n\
|
||||
absolute\t2020-02-29T01:23:45.00\n\
|
||||
\n\
|
||||
\n\
|
||||
#Camera\n\
|
||||
setNavigationState\tEarth\tSun\troot\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
setNavigationState\t\"Earth\"\t\"Sun\"\t\"root\"\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
#MarkNodes\n\
|
||||
Earth\n\
|
||||
@@ -492,7 +489,7 @@ Sun\n\
|
||||
|
||||
const std::string detectChangedAssetsResult_2 = "\
|
||||
#Version\n\
|
||||
1.0\n\
|
||||
" + profileFormatVersion + "\n\
|
||||
\n\
|
||||
#Module\n\
|
||||
\n\
|
||||
@@ -512,10 +509,8 @@ setPropertyValueSingle\tScene.Charon.Renderable.Enabled\tfalse\n\
|
||||
#Time\n\
|
||||
absolute\t2020-02-29T01:23:45.00\n\
|
||||
\n\
|
||||
\n\
|
||||
#Camera\n\
|
||||
setNavigationState\tEarth\tSun\troot\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
setNavigationState\t\"Earth\"\t\"Sun\"\t\"root\"\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
#MarkNodes\n\
|
||||
Earth\n\
|
||||
@@ -526,7 +521,7 @@ Sun\n\
|
||||
|
||||
const std::string detectChangedAssetsResult_3 = "\
|
||||
#Version\n\
|
||||
1.0\n\
|
||||
" + profileFormatVersion + "\n\
|
||||
\n\
|
||||
#Module\n\
|
||||
\n\
|
||||
@@ -546,10 +541,8 @@ setPropertyValueSingle\tScene.Charon.Renderable.Enabled\tfalse\n\
|
||||
#Time\n\
|
||||
absolute\t2020-02-29T01:23:45.00\n\
|
||||
\n\
|
||||
\n\
|
||||
#Camera\n\
|
||||
setNavigationState\tEarth\tSun\troot\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
setNavigationState\t\"Earth\"\t\"Sun\"\t\"root\"\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
#MarkNodes\n\
|
||||
Earth\n\
|
||||
@@ -560,7 +553,7 @@ Sun\n\
|
||||
|
||||
const std::string detectChangedAssetsResult_4 = "\
|
||||
#Version\n\
|
||||
1.0\n\
|
||||
" + profileFormatVersion + "\n\
|
||||
\n\
|
||||
#Module\n\
|
||||
\n\
|
||||
@@ -580,10 +573,8 @@ setPropertyValueSingle\tScene.Charon.Renderable.Enabled\tfalse\n\
|
||||
#Time\n\
|
||||
absolute\t2020-02-29T01:23:45.00\n\
|
||||
\n\
|
||||
\n\
|
||||
#Camera\n\
|
||||
setNavigationState\tEarth\tSun\troot\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
setNavigationState\t\"Earth\"\t\"Sun\"\t\"root\"\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
#MarkNodes\n\
|
||||
Earth\n\
|
||||
@@ -594,13 +585,16 @@ Sun\n\
|
||||
|
||||
const std::string detectChangedAssetsResult_5 = "\
|
||||
#Version\n\
|
||||
1.0\n\
|
||||
" + profileFormatVersion + "\n\
|
||||
\n\
|
||||
#Module\n\
|
||||
\n\
|
||||
#Asset\n\
|
||||
scene/solarsystem/planets/earth/earth\trequired\n\
|
||||
scene/solarsystem/planets/earth/satellites/satellites\trequired\n\
|
||||
test2\trequested\n\
|
||||
test4\trequested\n\
|
||||
test5\tremoved\n\
|
||||
\n\
|
||||
#Property\n\
|
||||
setPropertyValue\t{earth_satellites}.Renderable.Enabled\tfalse\n\
|
||||
@@ -612,10 +606,42 @@ setPropertyValueSingle\tScene.Charon.Renderable.Enabled\tfalse\n\
|
||||
#Time\n\
|
||||
absolute\t2020-02-29T01:23:45.00\n\
|
||||
\n\
|
||||
#Camera\n\
|
||||
setNavigationState\t\"Earth\"\t\"Sun\"\t\"root\"\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
#MarkNodes\n\
|
||||
Earth\n\
|
||||
Mars\n\
|
||||
Moon\n\
|
||||
Sun\n\
|
||||
";
|
||||
|
||||
const std::string detectChangedAssetsResult_6 = "\
|
||||
#Version\n\
|
||||
" + profileFormatVersion + "\n\
|
||||
\n\
|
||||
#Module\n\
|
||||
\n\
|
||||
#Asset\n\
|
||||
scene/solarsystem/planets/earth/earth\trequired\n\
|
||||
scene/solarsystem/planets/earth/satellites/satellites\trequired\n\
|
||||
test2\trequested\n\
|
||||
test4\trequested\n\
|
||||
scene/solarsystem/planets/earth/earth\tremoved\n\
|
||||
scene/solarsystem/planets/earth/satellites/satellites\tremoved\n\
|
||||
\n\
|
||||
#Property\n\
|
||||
setPropertyValue\t{earth_satellites}.Renderable.Enabled\tfalse\n\
|
||||
setPropertyValueSingle\tScene.Pluto.Renderable.Enabled\tfalse\n\
|
||||
setPropertyValueSingle\tScene.Charon.Renderable.Enabled\tfalse\n\
|
||||
\n\
|
||||
#Keybinding\n\
|
||||
\n\
|
||||
#Time\n\
|
||||
absolute\t2020-02-29T01:23:45.00\n\
|
||||
\n\
|
||||
#Camera\n\
|
||||
setNavigationState\tEarth\tSun\troot\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
setNavigationState\t\"Earth\"\t\"Sun\"\t\"root\"\t-1.000000,-2.000000,-3.000000\t0.000000,0.000000,1.000000\t0.000000\t0.000000\n\
|
||||
\n\
|
||||
#MarkNodes\n\
|
||||
Earth\n\
|
||||
|
||||
@@ -92,6 +92,9 @@ public:
|
||||
std::vector<Profile::AssetEvent> listOfAllAssetEvents() override {
|
||||
return _assLoader.listOfAllAssetEvents();
|
||||
}
|
||||
void setProfileBaseDirectory(std::string dir) {
|
||||
_profileBaseDirectory = dir;
|
||||
}
|
||||
private:
|
||||
std::vector<std::string> _scenegraphProps;
|
||||
std::string _initProfile;
|
||||
@@ -102,8 +105,6 @@ static void addLineHeaderForFailureMessage(std::string& s, size_t lineNumber) {
|
||||
s = "@line " + std::to_string(lineNumber) + ": '" + s + "'";
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("profile: Convert profileFile to asset", "[profile]") {
|
||||
testProfileFormat test = buildTestProfile1();
|
||||
std::string testFull_string = stringFromTestProfileFormat(test);
|
||||
@@ -140,21 +141,24 @@ TEST_CASE("profile: Verify conversion to scene", "[profile]") {
|
||||
REQUIRE_NOTHROW(
|
||||
result = p.convertToScene(pf)
|
||||
);
|
||||
|
||||
if (result != newHorizonsExpectedSceneOutput) {
|
||||
std::string testing, comparing;
|
||||
StringPerLineReader sr_result(result);
|
||||
StringPerLineReader sr_standard(newHorizonsExpectedSceneOutput);
|
||||
|
||||
std::string testing, comparing;
|
||||
StringPerLineReader sr_result(result);
|
||||
StringPerLineReader sr_standard(newHorizonsExpectedSceneOutput);
|
||||
|
||||
size_t lineN = 1;
|
||||
while (sr_result.getNextLine(testing)) {
|
||||
sr_standard.getNextLine(comparing);
|
||||
addLineHeaderForFailureMessage(testing, lineN);
|
||||
addLineHeaderForFailureMessage(comparing, lineN);
|
||||
REQUIRE(testing == comparing);
|
||||
lineN++;
|
||||
size_t lineN = 1;
|
||||
while (sr_result.getNextLine(testing)) {
|
||||
sr_standard.getNextLine(comparing);
|
||||
addLineHeaderForFailureMessage(testing, lineN);
|
||||
addLineHeaderForFailureMessage(comparing, lineN);
|
||||
REQUIRE(testing == comparing);
|
||||
lineN++;
|
||||
}
|
||||
//If this fails there are extra lines in the comparison string that weren't in result
|
||||
REQUIRE(sr_standard.getNextLine(comparing) == false);
|
||||
}
|
||||
//If this fails there are extra lines in the comparison string that weren't in result
|
||||
REQUIRE(sr_standard.getNextLine(comparing) == false);
|
||||
//REQUIRE(result == newHorizonsExpectedSceneOutput);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect new properties", "[profile]") {
|
||||
@@ -173,7 +177,8 @@ TEST_CASE("profile: Detect new properties", "[profile]") {
|
||||
lua_setglobal(*state, "passTest");
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setInitialProfile(FileSys.absolutePath("${TESTDIR}/profile/test2.profile"));
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
p.addPropertiesMarkedAsChanged("initialized 1st\t123");
|
||||
p.addPropertiesMarkedAsChanged("initialized 2nd\t3.14159");
|
||||
p.addPropertiesMarkedAsChanged("initialized 3rd\ttested.");
|
||||
@@ -205,7 +210,8 @@ TEST_CASE("profile: Detect new added assets", "[profile]") {
|
||||
asset3->initialize();
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setInitialProfile(FileSys.absolutePath("${TESTDIR}/profile/test2.profile"));
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_1);
|
||||
}
|
||||
@@ -236,7 +242,8 @@ TEST_CASE("profile: Detect new added assets after reset", "[profile]") {
|
||||
asset4->initialize();
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setInitialProfile(FileSys.absolutePath("${TESTDIR}/profile/test2.profile"));
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_2);
|
||||
}
|
||||
@@ -264,7 +271,8 @@ TEST_CASE("profile: Detect repeat added assets from new", "[profile]") {
|
||||
asset3->initialize();
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setInitialProfile(FileSys.absolutePath("${TESTDIR}/profile/test2.profile"));
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_3);
|
||||
}
|
||||
@@ -292,7 +300,8 @@ TEST_CASE("profile: Detect repeat added assets from base", "[profile]") {
|
||||
asset3->initialize();
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setInitialProfile(FileSys.absolutePath("${TESTDIR}/profile/test2.profile"));
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_4);
|
||||
}
|
||||
@@ -319,9 +328,10 @@ TEST_CASE("profile: Detect removed assets not already loaded", "[profile]") {
|
||||
assetLoader.remove("test5");
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setInitialProfile(FileSys.absolutePath("${TESTDIR}/profile/test2.profile"));
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_4);
|
||||
REQUIRE(output == detectChangedAssetsResult_5);
|
||||
}
|
||||
|
||||
TEST_CASE("profile: Detect removed assets from already loaded", "[profile]") {
|
||||
@@ -347,7 +357,8 @@ TEST_CASE("profile: Detect removed assets from already loaded", "[profile]") {
|
||||
assetLoader.remove("scene/solarsystem/planets/earth/satellites/satellites");
|
||||
|
||||
Profile2 p(assetLoader);
|
||||
p.setInitialProfile(FileSys.absolutePath("${TESTDIR}/profile/test2.profile"));
|
||||
p.setProfileBaseDirectory("${TESTDIR}/profile");
|
||||
p.setInitialProfile("test2");
|
||||
std::string output = p.saveCurrentSettingsToProfile_string();
|
||||
REQUIRE(output == detectChangedAssetsResult_5);
|
||||
REQUIRE(output == detectChangedAssetsResult_6);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user