Skip to content

Commit

Permalink
Shared QActions + trigger action + download dialog + move Filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Jul 10, 2024
1 parent b80612f commit 7d10f1b
Show file tree
Hide file tree
Showing 35 changed files with 611 additions and 347 deletions.
4 changes: 2 additions & 2 deletions lib/app/include/app/args.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ___VTX_APP_ARGS___
#define ___VTX_APP_ARGS___
#ifndef __VTX_APP_ARGS__
#define __VTX_APP_ARGS__

#include <string>
#include <vector>
Expand Down
111 changes: 111 additions & 0 deletions lib/app/include/app/filesystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#ifndef __VTX_APP_FILESYSTEM__
#define __VTX_APP_FILESYSTEM__

#include <string>
#include <util/filesystem.hpp>

namespace VTX::App::Filesystem
{

static FilePath EXECUTABLE_ABSOLUTE_PATH = VTX::Util::Filesystem::getExecutableDir();

inline const FilePath getExecutableDir()
{
assert( std::filesystem::exists( EXECUTABLE_ABSOLUTE_PATH ) );
return EXECUTABLE_ABSOLUTE_PATH;
}

// Directories.
inline const FilePath getShadersDir() { return getExecutableDir() / "shaders"; }
inline const FilePath getSnapshotsDir() { return getExecutableDir() / "snapshots"; }
inline const FilePath getRendersDir() { return getExecutableDir() / "renders"; }
inline const FilePath getLogsDir() { return getExecutableDir() / "logs"; }
inline const FilePath getLibrariesDir() { return getExecutableDir() / "libraries"; }
inline const FilePath getRepresentationsLibraryDir() { return getLibrariesDir() / "representations"; }
inline const FilePath getRenderEffectPresetsLibraryDir() { return getLibrariesDir() / "render_effects"; }
inline const FilePath getThemesLibraryDir() { return getLibrariesDir() / "themes"; }
inline const FilePath getInternalDataDir() { return getExecutableDir() / "data"; }
inline const FilePath getResidueDataDir() { return getInternalDataDir() / "residue_data"; }

// Files.
inline const FilePath getConfigIniFile() { return getExecutableDir() / "config.ini"; }
inline const FilePath getSettingJsonFile() { return getExecutableDir() / "setting.json"; }
inline const FilePath getLicenseFile() { return getExecutableDir() / "license.txt"; }

// Dev directories.
static const FilePath SHADERS_DIR_SRC = FilePath( "../src/shader" );
static const FilePath DEFAULT_SAVE_FOLDER = FilePath( "../save" );
static const FilePath DEFAULT_MOLECULE_FOLDER = FilePath( "../data" );

inline const FilePath getShadersPath( const FilePath & p_filename )
{
std::filesystem::create_directory( getShadersDir() );
return FilePath( getShadersDir() / p_filename );
}

inline const FilePath getSnapshotsPath( const FilePath & p_filename )
{
std::filesystem::create_directory( getSnapshotsDir() );
return FilePath( getSnapshotsDir() / p_filename );
}

inline const FilePath getRendersPath( const FilePath & p_filename )
{
std::filesystem::create_directory( getRendersDir() );
return FilePath( getRendersDir() / p_filename );
}

inline const FilePath getLogsPath( const FilePath & p_filename )
{
std::filesystem::create_directory( getLogsDir() );
return FilePath( getLogsDir() / p_filename );
}

inline const FilePath getRepresentationPath( const FilePath & p_filename )
{
std::filesystem::create_directory( getRepresentationsLibraryDir() );
return FilePath( getRepresentationsLibraryDir() / p_filename );
}

inline const FilePath getRenderEffectPath( const FilePath & p_filename )
{
std::filesystem::create_directory( getRenderEffectPresetsLibraryDir() );
return FilePath( getRenderEffectPresetsLibraryDir() / p_filename );
}

inline bool isSessionFile( const FilePath & p_filePath ) { return p_filePath.extension().string() == "vtx"; }

inline FilePath getSceneSaveDirectory( const FilePath & p_savePath )
{
const FilePath projectDirectoryName = FilePath( p_savePath.stem().append( "_data" ) );

return p_savePath.parent_path() / projectDirectoryName;
}

inline FilePath getSceneObjectsSaveDirectory( const FilePath & p_savePath )
{
return getSceneSaveDirectory( p_savePath ) / "obj";
}

inline FilePath getResidueDataFilePath( const std::string & p_residueName )
{
return getResidueDataDir() / p_residueName.substr( 0, 1 );
}

inline void checkSaveDirectoryHierarchy( const FilePath & p_savePath )
{
const FilePath projectDirectory = getSceneSaveDirectory( p_savePath );
if ( std::filesystem::exists( projectDirectory ) == false )
{
std::filesystem::create_directory( projectDirectory );
}

const FilePath objectsPath = getSceneObjectsSaveDirectory( p_savePath );
if ( std::filesystem::exists( objectsPath ) == false )
{
std::filesystem::create_directory( objectsPath );
}
}
} // namespace VTX::App::Filesystem

#endif
8 changes: 4 additions & 4 deletions lib/app/src/app/action/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "app/application/scene.hpp"
#include "app/application/system/serializer.hpp"
#include "app/application/system/settings_system.hpp"
#include "app/filesystem.hpp"
#include "app/internal/io/reader/scene_loader.hpp"
#include "app/internal/io/writer/scene_writer.hpp"
#include "app/internal/serialization/all_serializers.hpp"
#include <io/internal/filesystem.hpp>

namespace VTX::App::Action::Application
{
Expand Down Expand Up @@ -45,17 +45,17 @@ namespace VTX::App::Action::Application
}
void ClearScene::execute() { SCENE().reset(); }

LoadSettings::LoadSettings() : _path( VTX::IO::Internal::Filesystem::getSettingJsonFile() ) {}
LoadSettings::LoadSettings() : _path( VTX::App::Filesystem::getSettingJsonFile() ) {}
void LoadSettings::execute() { SERIALIZER().readObject<App::Application::Settings::Settings>( _path, SETTINGS() ); }
SaveSettings::SaveSettings() : _path( VTX::IO::Internal::Filesystem::getSettingJsonFile() ) {}
SaveSettings::SaveSettings() : _path( VTX::App::Filesystem::getSettingJsonFile() ) {}
void SaveSettings::execute()
{
SERIALIZER().writeObject<App::Application::Settings::Settings>( _path, SETTINGS() );
}
void ReloadSettings::execute()
{
SERIALIZER().readObject<App::Application::Settings::Settings>(
VTX::IO::Internal::Filesystem::getSettingJsonFile(), SETTINGS()
VTX::App::Filesystem::getSettingJsonFile(), SETTINGS()
);
}
void ResetSettings::execute() { SETTINGS().reset(); }
Expand Down
2 changes: 2 additions & 0 deletions lib/app/src/app/application/system/action_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace VTX::App::Application::System
ActionManager::~ActionManager() = default;
void ActionManager::execute( std::unique_ptr<BaseAction> & p_actionPtr )
{
VTX_DEBUG( "ActionManager::execute( {} )", typeid( *p_actionPtr ).name() );
try
{
p_actionPtr->execute();
Expand All @@ -34,6 +35,7 @@ namespace VTX::App::Application::System
}
void ActionManager::execute( std::unique_ptr<BaseActionUndonable> & p_actionPtr )
{
VTX_DEBUG( "ActionManager::execute( {} )", typeid( *p_actionPtr ).name() );
try
{
p_actionPtr->execute();
Expand Down
5 changes: 4 additions & 1 deletion lib/app/src/app/internal/util/molecule.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "app/internal/util/molecule.hpp"
#include "app/filesystem.hpp"
#include <sstream>

namespace VTX::App::Internal::Util::Molecule
Expand All @@ -8,7 +9,9 @@ namespace VTX::App::Internal::Util::Molecule
VTX::IO::Reader::ResidueDataReader reader = IO::Reader::ResidueDataReader();
VTX::IO::Struct::ResidueData residueData;

if ( reader.readResidueData( p_residueSymbol, residueData ) )
if ( reader.readResidueData(
Filesystem::getResidueDataFilePath( p_residueSymbol ), p_residueSymbol, residueData
) )
mapLoadedResidueData.emplace( p_residueSymbol, residueData );
else
mapLoadedResidueData.emplace( p_residueSymbol, IO::Struct::ResidueData::DEFAULT );
Expand Down
12 changes: 8 additions & 4 deletions lib/app/src/app/vtx_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@
#include "app/core/worker/worker_manager.hpp"
#include "app/entity/all_entities.hpp"
#include "app/entity/application/scene_entity.hpp"
#include "app/filesystem.hpp"
#include "app/internal/application/settings.hpp"
#include "app/internal/ecs/setup_entity_director.hpp"
#include "app/internal/monitoring/all_metrics.hpp"
#include "app/internal/serialization/all_serializers.hpp"
#include "app/mode/visualization.hpp"
#include <exception>
#include <io/internal/filesystem.hpp>
#include <util/filesystem.hpp>
#include <util/logger.hpp>

namespace VTX::App
{

VTXApp::VTXApp() { VTX_DEBUG( "VTXApp::VTXApp()" ); }
VTXApp::VTXApp() { VTX_DEBUG( "VTXApp()" ); }

VTXApp::~VTXApp() = default;
VTXApp::~VTXApp() { VTX_DEBUG( "~VTXApp()" ); }

void VTXApp::start( const Args & p_args )
{
VTX_INFO( "Starting application: {}", IO::Internal::Filesystem::EXECUTABLE_ABSOLUTE_PATH.string() );
VTX_INFO( "Starting application: {}", Filesystem::EXECUTABLE_ABSOLUTE_PATH.string() );

//// Create Databases
//_representationLibrary
Expand Down Expand Up @@ -130,8 +131,11 @@ namespace VTX::App
)
);
}

void VTXApp::stop()
{
VTX_DEBUG( "VTXApp::stop()" );

onStop();

_stop();
Expand Down
10 changes: 5 additions & 5 deletions lib/app/test/src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include <app/core/action/base_action.hpp>
#include <app/core/action/base_action_undonable.hpp>
#include <app/core/ecs/base_entity.hpp>
#include <app/filesystem.hpp>
#include <app/internal/application/settings.hpp>
#include <app/vtx_app.hpp>
#include <catch2/benchmark/catch_benchmark.hpp>
#include <catch2/catch_test_macros.hpp>
#include <io/internal/filesystem.hpp>
#include <util/filesystem.hpp>

namespace VTX::App::Test
Expand Down Expand Up @@ -153,12 +153,12 @@ TEST_CASE( "VTX_APP - Action - Application - Settings", "[integration]" )

const App::Application::Settings::Settings modifiedSettings = SETTINGS();

if ( std::filesystem::exists( IO::Internal::Filesystem::getSettingJsonFile() ) )
std::filesystem::remove( IO::Internal::Filesystem::getSettingJsonFile() );
if ( std::filesystem::exists( Filesystem::getSettingJsonFile() ) )
std::filesystem::remove( Filesystem::getSettingJsonFile() );

CHECK( !std::filesystem::exists( IO::Internal::Filesystem::getSettingJsonFile() ) );
CHECK( !std::filesystem::exists( Filesystem::getSettingJsonFile() ) );
VTX_ACTION().execute<Action::Application::SaveSettings>();
CHECK( std::filesystem::exists( IO::Internal::Filesystem::getSettingJsonFile() ) );
CHECK( std::filesystem::exists( Filesystem::getSettingJsonFile() ) );
CHECK( SETTINGS() == modifiedSettings );

VTX_ACTION().execute<Action::Application::ResetSettings>();
Expand Down
6 changes: 3 additions & 3 deletions lib/app/test/src/entt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <app/component/chemistry/residue.hpp>
#include <app/component/render/proxy_molecule.hpp>
#include <app/entity/scene/molecule_entity.hpp>
#include <app/filesystem.hpp>
#include <app/vtx_app.hpp>
#include <catch2/benchmark/catch_benchmark.hpp>
#include <catch2/catch_test_macros.hpp>
#include <entt/entt.hpp>
#include <functional>
#include <io/internal/filesystem.hpp>
#include <renderer/proxy/molecule.hpp>
#include <string>
#include <util/logger.hpp>
Expand Down Expand Up @@ -67,7 +67,7 @@ TEST_CASE( "VTX_APP - Full sequence", "[integration]" )
{ addSceneItemTest.checked = !p_sceneItem.getName().empty(); };

// Create MoleculeEntity
const FilePath moleculePath = IO::Internal::Filesystem::getInternalDataDir() / moleculePathname;
const FilePath moleculePath = App::Filesystem::getInternalDataDir() / moleculePathname;
Action::Scene::LoadMolecule openAction = Action::Scene::LoadMolecule( moleculePath );
openAction.execute();

Expand Down Expand Up @@ -116,7 +116,7 @@ TEST_CASE( "VTX_APP - Benchmark", "[.][perfs]" )
Test::Util::App::initApp();

// Create MoleculeEntity
const FilePath moleculePath = IO::Internal::Filesystem::getInternalDataDir() / moleculePathname;
const FilePath moleculePath = App::Filesystem::getInternalDataDir() / moleculePathname;

Action::Scene::LoadMolecule openAction = Action::Scene::LoadMolecule( moleculePath );
openAction.execute();
Expand Down
4 changes: 2 additions & 2 deletions lib/app/test/src/util/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <app/component/render/camera.hpp>
#include <app/component/render/proxy_camera.hpp>
#include <app/component/render/proxy_color_layout.hpp>
#include <app/filesystem.hpp>
#include <app/vtx_app.hpp>
#include <catch2/catch_test_macros.hpp>
#include <io/internal/filesystem.hpp>
#include <string>

namespace VTX::App::Test::Util
Expand Down Expand Up @@ -47,7 +47,7 @@ namespace VTX::App::Test::Util
void App::loadMolecule( const std::string & p_moleculePath )
{
// Create MoleculeEntity
const FilePath moleculePath = IO::Internal::Filesystem::getInternalDataDir() / p_moleculePath;
const FilePath moleculePath = VTX::App::Filesystem::getInternalDataDir() / p_moleculePath;
Action::Scene::LoadMolecule loadMoleculeAction = Action::Scene::LoadMolecule( moleculePath );
loadMoleculeAction.execute();
}
Expand Down
Loading

0 comments on commit 7d10f1b

Please sign in to comment.