Skip to content

Commit

Permalink
ui wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Jul 2, 2024
1 parent 068719e commit b80612f
Show file tree
Hide file tree
Showing 20 changed files with 640 additions and 68 deletions.
2 changes: 1 addition & 1 deletion lib/app/include/app/vtx_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace VTX::App

virtual void start( const Args & );
void update( const float p_elapsedTime = 0 );
virtual void stop();
void stop();

inline const Core::System::SystemHandler & getSystemHandler() const { return *_systemHandlerPtr; };
inline Core::System::SystemHandler & getSystemHandler() { return *_systemHandlerPtr; };
Expand Down
5 changes: 3 additions & 2 deletions lib/app/src/app/vtx_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#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>
Expand Down Expand Up @@ -66,8 +67,8 @@ namespace VTX::App

// Internal::initSettings( App::SETTINGS() );

//_currentMode = std::make_unique<App::Mode::Visualization>();
//_currentMode->enter();
_currentMode = std::make_unique<App::Mode::Visualization>();
_currentMode->enter();

onStart();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/io/src/io/reader/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace VTX::IO::Reader
p_molecule.initResidues( p_chemfileStruct.getResidueCount() );
p_molecule.initAtoms( p_chemfileStruct.getAtomCount() );

// VTX::Core::Struct::Frame & modelFrame = p_molecule.trajectory.frames[ 0 ];
// modelFrame.resize( p_chemfileStruct.getAtomCount() );
VTX::Core::Struct::Frame & modelFrame = p_molecule.trajectory.frames[ 0 ];
modelFrame.resize( p_chemfileStruct.getAtomCount() );

for ( size_t residueIdx = 0; residueIdx < p_chemfileStruct.getResidueCount(); ++residueIdx )
{
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace VTX::IO::Reader
default: break;
}

// modelFrame[ atomIndex ] = p_chemfileStruct.getCurrentAtomPosition();
modelFrame[ atomIndex ] = p_chemfileStruct.getCurrentAtomPosition();
}

// TODO: Useless?
Expand Down
8 changes: 4 additions & 4 deletions lib/renderer/bench/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ int main( int, char ** )
Renderer::Proxy::Representation representation1, representation2, representation3;

representation2.radiusFixed = false;
representation3.radiusSphereFixed = 0.1f;
representation3.radiusSphereFixed = 1.5f;

std::vector<Renderer::Proxy::Representation *> representations
= { &representation1, &representation2, &representation3 };
Expand All @@ -147,9 +147,9 @@ int main( int, char ** )
3, 1000.f, 1000.f, 0.5f, COLOR_RED, 1.f, 1, COLOR_BLUE };

// renderer.setProxyRenderSettings( renderSettings );
// renderer.addProxyMolecule( scene.addMolecule( "4hhb" ) );
renderer.addProxyMolecule( scene.addMolecule( "2ama_1_npt.trr" ) );

renderer.addProxyMolecule( scene.addMolecule( "4hhb" ) );
// renderer.addProxyMolecule( scene.addMolecule( "2ama_1_npt.trr" ) );

// Main loop.
while ( isRunning )
Expand Down
4 changes: 2 additions & 2 deletions lib/renderer/bench/src/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ namespace VTX::Bench
return;
}

int i = 0;
static uint currentFrame = 0;
int i = 0;
// static uint currentFrame = 0;

for ( auto & molecule : _molecules )
{
Expand Down
21 changes: 21 additions & 0 deletions lib/ui/include/ui/actions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef __VTX_UI_ACTIONS__
#define __VTX_UI_ACTIONS__

#include <app/core/input/keys.hpp>
#include <string>

namespace VTX::UI
{

struct Action
{
std::string name;
std::optional<std::string> tip = std::nullopt;
std::optional<std::string> icon = std::nullopt;
// callback or vtx action
// std::optional<App::Core::Input::Shortcut> shortcut;
};

} // namespace VTX::UI

#endif
7 changes: 0 additions & 7 deletions lib/ui/include/ui/base_application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ namespace VTX::UI
VTXApp::start( p_args );
_start();
}
void stop() override
{
_stop();

VTXApp::stop();
}

void addMenuAction( const MenuAction & p_ma ) { _mainWindow->addMenuAction( p_ma ); }
void addToolBarAction( const ToolBarAction & p_tba ) { _mainWindow->addToolBarAction( p_tba ); }
Expand All @@ -44,7 +38,6 @@ namespace VTX::UI

virtual void _init( const App::Args & ) = 0;
virtual void _start() = 0;
virtual void _stop() = 0;
};

} // namespace VTX::UI
Expand Down
1 change: 0 additions & 1 deletion lib/ui/include/ui/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace VTX::UI
{

template<typename MW>
concept ConceptMainWindow =
// std::is_base_of<BaseMainWindow, MW>::value &&
Expand Down
1 change: 1 addition & 0 deletions lib/ui/include/ui/descriptors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace VTX::UI
// std::optional<App::Core::Input::Shortcut> shortcut;
};


struct MenuAction
{
WidgetId idMenu;
Expand Down
157 changes: 157 additions & 0 deletions lib/ui/qt/include/qt/actions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#ifndef __VTX_UI_QT_ACTIONS__
#define __VTX_UI_QT_ACTIONS__

#include "resources.hpp"
#include <QAction>
#include <ui/descriptors.hpp>

namespace VTX::UI::QT::Action
{
template<typename W>
concept ConceptAction = std::is_base_of_v<QAction, W>;

// Static map to store all actions.
static std::map<std::string, QAction *> ACTIONS;

class Action : public UI::Action
{
Action()
{
ACTIONS[ name ] = new QAction( name.c_str() );
if ( tip.has_value() )
{
ACTIONS[ name ]->setToolTip( tip.value().c_str() );
}
if ( icon.has_value() )
{
// ACTIONS[ name ]->setIcon( Resources::ICON( icon.value() ) );
}
}

virtual ~Action() { ACTIONS.erase( name ); }

std::optional<QString> icon = std::nullopt;
};

////////////////////////////////////////

struct New : public Action
{
New()
{
name = "New";
tip = "Create a new project";
}
};

struct Download : public UI::Action
{
Download()
{
name = "Download";
tip = "Download structure from PDB id";
}
};

struct Open : public UI::Action
{
Open()
{
name = "Open";
tip = "Open a project or a molecular file";
}
};

struct OpenRecent : public UI::Action
{
OpenRecent() { name = "Open recent"; }
};

struct Save : public UI::Action
{
Save()
{
name = "Save";
tip = "Save project";
}
};

struct SaveAs : public UI::Action
{
SaveAs()
{
name = "Save as...";
tip = "Copy project in a new save";
}
};

struct Import : public UI::Action
{
Import() { name = "Import"; }
};

struct Export : public UI::Action
{
Export() { name = "Export"; }
};

struct Quit : public UI::Action
{
Quit()
{
name = "Quit";
tip = "Exit software";
}
};

struct ChangeProjection : public UI::Action
{
ChangeProjection()
{
name = "Perspective";
tip = "Change projection mode (perspective/orthographic)";
icon = ":/sprite/camera/perspective.png";
}
};

struct Trackball : public UI::Action
{
Trackball()
{
name = "Trackball";
tip = "Use Trackball controller";
icon = ":/sprite/camera/trackball.png";
}
};

struct Freefly : public UI::Action
{
Freefly()
{
name = "Freefly";
tip = "Use Freefly controller";
icon = ":/sprite/camera/freefly.png";
}
};

struct Orient : public UI::Action
{
Orient()
{
name = "Orient";
tip = "Orient camera on selection";
}
};

struct Reset : public UI::Action
{
Reset()
{
name = "Reset";
tip = "Reset camera";
}
};

} // namespace VTX::UI::QT::Action

#endif
8 changes: 5 additions & 3 deletions lib/ui/qt/include/qt/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ namespace VTX::UI::QT
{
public:
Application();
virtual ~Application() {}
virtual ~Application();

protected:
// Override.
void _init( const App::Args & ) override;
void _start() override;
void _stop() override;

private:
QPointer<QApplication> _qApplication;
QPointer<QSplashScreen> _qSplashScreen;
void _loadTheme();

void _loadTheme();
void _saveSettings();
void _restoreSettings();
};

} // namespace VTX::UI::QT
Expand Down
23 changes: 20 additions & 3 deletions lib/ui/qt/include/qt/base_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@
#define __VTX_UI_QT_BASE_WIDGET__

#include <QWidget>
#include <map>
#include <string>
#include <typeinfo>
#include <util/logger.hpp>

namespace VTX::UI::QT
{
template<typename W>
concept ConceptWidget = std::derived_from<W, QWidget>;
concept ConceptWidget = std::is_base_of_v<QWidget, W>;

// Static map to store all widgets.
static std::map<std::string, QWidget *> WIDGETS;

template<ConceptWidget T>
static T * const WIDGET()
{
const std::string name = typeid( T ).name();

assert( WIDGETS.contains( name ) );

return static_cast<T *>( WIDGETS[ name ] );
}

template<typename T, ConceptWidget W>
class BaseWidget : public W
Expand All @@ -17,10 +32,12 @@ namespace VTX::UI::QT
template<typename... Args>
BaseWidget( Args &&... args ) : W( std::forward<Args>( args )... )
{
W::setObjectName( typeid( T ).name() );
const auto name = typeid( T ).name();
W::setObjectName( name );
WIDGETS[ name ] = this;
}

private:
virtual ~BaseWidget() { WIDGETS.erase( typeid( T ).name() ); }
};

} // namespace VTX::UI::QT
Expand Down
Loading

0 comments on commit b80612f

Please sign in to comment.