Skip to content

Commit

Permalink
Improving running of program within simplesim
Browse files Browse the repository at this point in the history
  • Loading branch information
MatV404 committed Sep 19, 2024
1 parent 8755f87 commit 2e61755
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 38 deletions.
13 changes: 7 additions & 6 deletions softwareComponents/simplesimClientLib/include/runmodules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <atoms/util.hpp>

#include <QListWidgetItem>
#include <QDialog>


namespace Ui
Expand All @@ -17,14 +18,16 @@ class RunModules;
namespace rofi::simplesim
{

class RunModules : public QWidget {
class RunModules : public QDialog {
Q_OBJECT

public:
// TODO: Fix passing bool&, it isn't really nice.
RunModules( bool& isRunning, QWidget * parent = nullptr, std::size_t moduleCount = 0 );
RunModules( QWidget * parent = nullptr );

~RunModules();

std::string getProgram();

signals:

private slots:
Expand All @@ -33,9 +36,7 @@ private slots:

private:
std::unique_ptr< Ui::RunModules > _ui;
std::size_t _moduleCount;
// TODO: Fix this, it isn't really nice.
bool& _isRunning;
std::string _program;
};

} // namespace rofi::simplesim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QTimer>
#include <QTreeWidgetItem>
#include <QWidgetItem>
#include <QProcess>


#define vtkTypeMacro_( thisClass, superClass ) \
Expand Down Expand Up @@ -217,6 +218,7 @@ private slots:
int _lastModule = -1;
std::array< double, 3 > _lastColor;
bool _isRunning = false;
std::vector< std::unique_ptr< QProcess > > _moduleProcesses;

std::vector< rofi::configuration::ModuleId > _treeIdMapping;
std::map< rofi::configuration::ModuleId, detail::ModuleRenderInfo > _moduleRenderInfos;
Expand Down
37 changes: 9 additions & 28 deletions softwareComponents/simplesimClientLib/src/runmodules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

using rofi::simplesim::RunModules;

RunModules::RunModules( bool& isRunning, QWidget* parent, std::size_t moduleCount )
: QWidget( parent ), _ui( std::make_unique< Ui::RunModules >() ),
_moduleCount( moduleCount ), _isRunning( isRunning )
RunModules::RunModules( QWidget* parent )
: QDialog( parent ), _ui( std::make_unique< Ui::RunModules >() )
{
_ui->setupUi( this );

Expand All @@ -24,31 +23,13 @@ RunModules::~RunModules() {}
void RunModules::accept()
{
hide();
std::string program = _ui->textEdit->toPlainText().toStdString();
_program = _ui->textEdit->toPlainText().toStdString();
_ui->textEdit->setPlainText( "" );

std::string simplesimPath = std::string(std::getenv("ROFI_BUILD_DIR")) + "/desktop/bin/rofi-simplesim";
std::string programPath = std::string(std::getenv("ROFI_BUILD_DIR")) + "/desktop/bin/" + program;
std::cout << "Running " << programPath << " for " << _moduleCount << " modules in the simulation." << std::endl;
_isRunning = true;

const char* executable = programPath.c_str();

for ( std::size_t i = 0; i < _moduleCount; ++i )
{
std::cout << "Running module " << i << std::endl;
pid_t module_id = fork();
if ( module_id == -1 )
{
std::cerr << "Failed to run module: " << std::strerror( errno ) << std::endl;
return;
}

if ( module_id == 0 )
{
if ( execl( executable, executable, static_cast< char* >( 0 ) ) == -1 ) {
std::cerr << "Failed to run module: " << std::strerror( errno ) << std::endl;
}
}
}
done( QDialog::Accepted );
}

std::string RunModules::getProgram()
{
return _program;
}
25 changes: 23 additions & 2 deletions softwareComponents/simplesimClientLib/src/simplesim_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,30 @@ void SimplesimClient::runModulesWindow()
if ( !_runModulesWindow )
{
_runModulesWindow =
std::make_unique< RunModules >( _isRunning, this, getCurrentConfig()->modules().size() );
std::make_unique< RunModules >( this );
}
// _runModulesWindow->show();
if (_runModulesWindow->exec() != QDialog::Accepted)
{
return;
}
std::string simplesimPath = std::string( std::getenv( "ROFI_BUILD_DIR" ) ) + "/desktop/bin/rofi-simplesim";
std::string program = _runModulesWindow->getProgram();
std::string programPath = std::string( std::getenv( "ROFI_BUILD_DIR" ) ) + "/desktop/bin/" + program;

QString executable = QString::fromStdString( programPath );
QStringList arguments;

std::size_t moduleCount = getCurrentConfig()->modules().size();

for ( std::size_t i = 0; i < moduleCount; ++i )
{
std::cout << "Running module " << i << std::endl;
_moduleProcesses.push_back( std::make_unique< QProcess >( this ) );
_moduleProcesses[i]->start( executable, arguments );

// ToDo: Capture output in a separate console window.
}
_runModulesWindow->show();
}

void SimplesimClient::setCamera( Matrix focalPoint )
Expand Down
4 changes: 2 additions & 2 deletions tools/rofi-run/explorer/explorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void Explorer::clearPath()

void Explorer::reject()
{
done(QDialog::Rejected);
done( QDialog::Rejected );
}

void Explorer::accept()
Expand All @@ -49,7 +49,7 @@ void Explorer::accept()
return;

}
done(QDialog::Accepted);
done( QDialog::Accepted );
}

void Explorer::setAcceptedExtension( std::string extension )
Expand Down

0 comments on commit 2e61755

Please sign in to comment.