Skip to content

Commit

Permalink
fixup options tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Aug 23, 2024
1 parent 9515540 commit 1fc20c5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
23 changes: 19 additions & 4 deletions application/F3DCLIOptionsTools.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#include "F3DCLIOptionsTools.h"

#include "F3DSystemTools.h"
#include "F3DException.h"
#include "F3DConfig.h"

#include "log.h"
#include "engine.h"
#include "interactor.h"

#include "cxxopts.hpp"

#include <sstream>
#include <iomanip>
#include <cassert>
#include <filesystem>

namespace fs = std::filesystem;

namespace
{
//----------------------------------------------------------------------------
Expand All @@ -17,7 +33,7 @@ std::string CollapseName(const std::string& longName, const std::string& shortNa

//----------------------------------------------------------------------------
void PrintHelpPair(
const std::string& key, const std::string& help, int keyWidth, int helpWidth)
const std::string& key, const std::string& help, int keyWidth = 10, int helpWidth = 70)
{
std::stringstream ss;
ss << " " << std::left << std::setw(keyWidth) << key << " " << std::setw(helpWidth) << help;
Expand Down Expand Up @@ -170,7 +186,6 @@ void PrintReadersList()
}
f3d::log::waitForUser();
}
}

// TODO
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -219,11 +234,11 @@ std::vector<std::pair<std::string, std::string>> F3DCLIOptionsTools::ParseCLIOpt
}
}
}
auto result = cxxOptions.parse(argc, srgv);
auto result = cxxOptions.parse(argc, argv);

if (result.count("help") > 0)
{
::PrintHelp(cxxOptions);
::PrintHelp(execName, cxxOptions);
throw F3DExNoProcess("help requested");
}

Expand Down
2 changes: 1 addition & 1 deletion application/F3DCLIOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static inline const app_options_t DefaultAppOptions = {
{"group-geometries", false},
};

static inline const std::map<std::string, std::string> LibOptionNames = {
static inline const std::map<std::string, std::string> LibOptionsNames = {
{"progress", "ui.loader_progress"}};

std::vector<std::pair<std::string, std::string>> ParseCLIOptions(int argc, char** argv);
Expand Down
38 changes: 20 additions & 18 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class F3DStarter::F3DInternals
public:
F3DInternals() = default;

void SetupCamera(const F3DAppOptions& appOptions)
/* void SetupCamera(const F3DAppOptions& appOptions)
{
f3d::camera& cam = this->Engine->getWindow().getCamera();
if (appOptions.CameraPosition.size() == 3)
Expand Down Expand Up @@ -102,7 +102,7 @@ class F3DStarter::F3DInternals
cam.azimuth(appOptions.CameraAzimuthAngle)
.elevation(appOptions.CameraElevationAngle)
.setCurrentAsDefault();
}
}*/

static bool HasHDRIExtension(const std::string& file)
{
Expand Down Expand Up @@ -359,7 +359,7 @@ class F3DStarter::F3DInternals
std::to_string(maxNumberingAttempts) + " attempts");
}

F3DAppOptions AppOptions;
// F3DAppOptions AppOptions;
f3d::options DynamicOptions;
f3d::options FileOptions;
std::unique_ptr<f3d::engine> Engine;
Expand Down Expand Up @@ -402,18 +402,20 @@ int F3DStarter::Start(int argc, char** argv)
// Parse command line options

// Recover CLI Options into a strings vector
std::vector<std::pair<std::string, std::string>> cliOptions = F3DCLIOptionsTools.ParseCLIOptions();
std::vector<std::pair<std::string, std::string>> cliOptions = F3DCLIOptionsTools::ParseCLIOptions(argc, argv);
f3d::options libOptions;

std::map<std::string, app_option_variant_t> appOptions = F3DCLIOptionsTools.DefaultAppOptions();
std::map<std::string, std::string> LibOptionsNames = F3DCLIOptionsTools.LibOptionNames();
// Copy appOptions
std::map<std::string, F3DCLIOptionsTools::app_option_variant_t> appOptions = F3DCLIOptionsTools::DefaultAppOptions;

// Process each CLI option
for (auto cliIter = cliOptions.begin(); cliIter != cliOptions.end();)
{
// Parse App options
auto appIter = appOptions.find(cliIter->first);
if (appIter != appOptions.end())
{
app_option_variant_t& var = appIter->second;
F3DCLIOptionsTools::app_option_variant_t& var = appIter->second;
const std::string& str = cliIter->second;
std::visit([&](auto&& ref)
{
Expand All @@ -425,8 +427,8 @@ int F3DStarter::Start(int argc, char** argv)
// Set libf3d options
else
{
auto libIter = LibOptionsNames.find(cliIter->first);
if (libIter != LibOptionsNames.end())
auto libIter = F3DCLIOptionsTools::LibOptionsNames.find(cliIter->first);
if (libIter != F3DCLIOptionsTools::LibOptionsNames.end())
{
libOptions.setAsString(libIter->second, cliIter->second);
cliIter = cliOptions.erase(cliIter);
Expand Down Expand Up @@ -763,7 +765,7 @@ int F3DStarter::Start(int argc, char** argv)
//----------------------------------------------------------------------------
void F3DStarter::LoadFile(int index, bool relativeIndex)
{
// Make sure the animation is stopped before trying to load any file
/* // Make sure the animation is stopped before trying to load any file
if (!this->Internals->AppOptions.NoRender)
{
this->Internals->Engine->getInteractor().stopAnimation();
Expand Down Expand Up @@ -833,16 +835,16 @@ void F3DStarter::LoadFile(int index, bool relativeIndex)
// Update options for the file to load, using dynamic options as default
this->Internals->FileOptions = this->Internals->DynamicOptions;
F3DAppOptions fileAppOptions = this->Internals->AppOptions;
this->Internals->Parser.UpdateOptions(filePath.string(), fileAppOptions,
this->Internals->FileOptions, this->Internals->UpdateWithCommandLineParsing);
// F3DAppOptions fileAppOptions = this->Internals->AppOptions;
// this->Internals->Parser.UpdateOptions(filePath.string(), fileAppOptions,
// this->Internals->FileOptions, this->Internals->UpdateWithCommandLineParsing);
this->Internals->UpdateWithCommandLineParsing = false; // this is done only once
this->Internals->Engine->setOptions(this->Internals->FileOptions);
this->Internals->LoadedFile = false;
// Load any new plugins the updated app options
this->Internals->Parser.LoadPlugins(fileAppOptions);
// this->Internals->Parser.LoadPlugins(fileAppOptions);
// Check the size of the file before loading it
// Not considered in the context of GroupGeometries
Expand Down Expand Up @@ -912,7 +914,7 @@ void F3DStarter::LoadFile(int index, bool relativeIndex)
if (!this->Internals->AppOptions.NoRender)
{
// Setup the camera according to options
this->Internals->SetupCamera(fileAppOptions);
// this->Internals->SetupCamera(fileAppOptions);
this->Internals->Engine->getWindow().setWindowName(
filePath.filename().string() + " - " + F3D::AppName);
Expand Down Expand Up @@ -941,7 +943,7 @@ void F3DStarter::LoadFile(int index, bool relativeIndex)
f3d::options& options = this->Internals->Engine->getOptions();
options.ui.dropzone = !this->Internals->LoadedFile;
options.ui.filename_info = filenameInfo;
options.ui.filename_info = filenameInfo;*/
}

//----------------------------------------------------------------------------
Expand All @@ -962,7 +964,7 @@ void F3DStarter::Render()
//----------------------------------------------------------------------------
void F3DStarter::SaveScreenshot(const std::string& filenameTemplate, bool minimal)
{

/*
const auto getScreenshotDir = []()
{
for (const char* const& candidate : { "XDG_PICTURES_DIR", "HOME", "USERPROFILE" })
Expand Down Expand Up @@ -1014,7 +1016,7 @@ void F3DStarter::SaveScreenshot(const std::string& filenameTemplate, bool minima
this->Render();
this->Internals->Engine->setOptions(optionsCopy);
this->Render();
this->Render();*/
}

//----------------------------------------------------------------------------
Expand Down

0 comments on commit 1fc20c5

Please sign in to comment.