From 48ce1c1394f8947639ca4a4f4b0df9894aa3f0c5 Mon Sep 17 00:00:00 2001 From: sagittarius89 Date: Thu, 6 Feb 2020 17:47:19 +0100 Subject: [PATCH 1/4] new operations: update, rename profile --- src/profilestab.cpp | 151 ++++++++++++++++++++++++++++++++++++++++++-- src/profilestab.h | 6 ++ 2 files changed, 151 insertions(+), 6 deletions(-) diff --git a/src/profilestab.cpp b/src/profilestab.cpp index f6133925..fff82dd7 100644 --- a/src/profilestab.cpp +++ b/src/profilestab.cpp @@ -38,6 +38,14 @@ ProfilesTab::ProfilesTab( QWidget* parent ): TabBase( parent ) { _newProfile->setFixedSize( MainButtonSize ); _newProfile->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); + _renameProfile->setFont(fontAwesome); + _renameProfile->setFixedSize( MainButtonSize ); + _renameProfile->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); + + _overwriteProfile->setFont(fontAwesome); + _overwriteProfile->setFixedSize( MainButtonSize ); + _overwriteProfile->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); + _deleteProfile->setFont(fontAwesome); _deleteProfile->setFixedSize( MainButtonSize ); _deleteProfile->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); @@ -51,6 +59,8 @@ ProfilesTab::ProfilesTab( QWidget* parent ): TabBase( parent ) { QObject::connect( _importParams, &QPushButton::clicked, this, &ProfilesTab::importParams_clicked ); QObject::connect( _exportParams, &QPushButton::clicked, this, &ProfilesTab::exportParams_clicked ); QObject::connect( _newProfile, &QPushButton::clicked, this, &ProfilesTab::newProfile_clicked ); + QObject::connect( _renameProfile, &QPushButton::clicked, this, &ProfilesTab::renamePProfile_clicked ); + QObject::connect( _overwriteProfile, &QPushButton::clicked, this, &ProfilesTab::updateProfile_clicked ); QObject::connect( _deleteProfile, &QPushButton::clicked, this, &ProfilesTab::deleteProfile_clicked ); QObject::connect( _loadProfile, &QPushButton::clicked, this, &ProfilesTab::loadProfile_clicked ); @@ -60,11 +70,19 @@ ProfilesTab::ProfilesTab( QWidget* parent ): TabBase( parent ) { _exportParams, cpyProfilesUsbBox, cpyStlFilesUsbBox, - _importParams, - _newProfile, - _loadProfile, - _deleteProfile, - nullptr + nullptr, + WrapWidgetsInHBox( + WrapWidgetsInVBox( + _importParams, + _loadProfile, + _deleteProfile + ), + WrapWidgetsInVBox( + _newProfile, + _renameProfile, + _overwriteProfile + ) + ) ), _profilesList ) @@ -98,7 +116,6 @@ void ProfilesTab::_setupProfilesList(QFont font) { _profilesList->setFont( font ); _profilesList->setVisible( true ); _profilesList->setSelectionBehavior( QAbstractItemView::SelectRows ); - _profilesList->setMinimumSize(QSize(MaximalRightHandPaneSize.width(), MaximalRightHandPaneSize.height())); _profilesList->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); } @@ -240,6 +257,61 @@ void ProfilesTab::newProfile_clicked(bool) } } +void ProfilesTab::renamePProfile_clicked(bool) +{ + Window* w = App::mainWindow(); + QRect r = w->geometry(); + + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.move(r.x()+100, r.y()+100); + msgBox.setFont(*_fontAwesome); + + InputDialog* inputDialog = new InputDialog(QString("Entry profile name: ")); + int ret = inputDialog->exec(); + + QString filename = inputDialog->getValue(); + if (ret && !filename.isEmpty()) + { + if(!_renamePProfile(filename)) + { + msgBox.setText("Something went wrong."); + msgBox.exec(); + } + else + { + msgBox.setText("Profile successfuly renamed."); + msgBox.exec(); + } + } +} + +void ProfilesTab::updateProfile_clicked(bool) +{ + Window* w = App::mainWindow(); + QRect r = w->geometry(); + + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.move(r.x()+100, r.y()+100); + msgBox.setFont(*_fontAwesome); + msgBox.setText("Are You sure to update selected profile?"); + int ret = msgBox.exec(); + + switch (ret) { + case QMessageBox::Yes: + if(!_updateProfile()) + { + msgBox.setText("Something went wrong."); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + } + break; + default: + break; + } +} + void ProfilesTab::deleteProfile_clicked(bool) { Window* w = App::mainWindow(); @@ -310,6 +382,73 @@ bool ProfilesTab::_createNewProfile(QString profileName) return true; } +bool ProfilesTab::_renamePProfile(QString profileName) +{ + QModelIndex index = _profilesList->currentIndex(); + + QString oldName = index.data(Qt::DisplayRole).toString(); + _model->setData(index, QVariant(profileName)); + + QVector* c = (QVector*)_printProfileManager->profiles(); + auto iter = std::find_if( c->begin( ), c->end( ), [&oldName] ( PrintProfile* p ) { return oldName == p->profileName( ); } ); + PrintProfile* profile = ( iter != c->end( ) ) ? *iter : nullptr; + + profile->setProfileName(profileName); + + ProfilesJsonParser::saveProfiles(_printProfileManager->profiles()); + + return true; +} + +bool ProfilesTab::_updateProfile() +{ + QModelIndex index = _profilesList->currentIndex(); + QString profileName = index.data(Qt::DisplayRole).toString(); + + QVector* c = (QVector*)_printProfileManager->profiles(); + auto iter = std::find_if( c->begin( ), c->end( ), [&profileName] ( PrintProfile* p ) { return profileName == p->profileName( ); } ); + PrintProfile* profile = ( iter != c->end( ) ) ? *iter : nullptr; + PrintProfile* activeProfile = (PrintProfile*)_printProfileManager->activeProfile(); + + profile->setBaseLayerCount(activeProfile->baseLayerCount()); + profile->setBaseLayersPumpingEnabled(activeProfile->baseLayersPumpingEnabled()); + profile->setBodyLayersPumpingEnabled(activeProfile->bodyLayersPumpingEnabled()); + + PrintPumpingParameters baseParams = activeProfile->baseLayersPumpingParameters(); + PrintPumpingParameters newBaseParams; + + newBaseParams.setPumpUpDistance( baseParams.pumpUpDistance() ); + newBaseParams.setPumpUpTime( baseParams.pumpUpTime() ); + newBaseParams.setPumpUpPause( baseParams.pumpUpPause() ); + newBaseParams.setPumpDownPause( baseParams.pumpDownPause() ); + newBaseParams.setNoPumpUpVelocity( baseParams.noPumpUpVelocity() ); + newBaseParams.setPumpEveryNthLayer( baseParams.pumpEveryNthLayer() ); + newBaseParams.setLayerThickness( baseParams.layerThickness() ); + newBaseParams.setLayerExposureTime( baseParams.layerExposureTime() ); + newBaseParams.setPowerLevel( baseParams.powerLevel() ); + + profile->setBaseLayersPumpingParameters(newBaseParams); + + PrintPumpingParameters bodyParams = activeProfile->bodyLayersPumpingParameters(); + PrintPumpingParameters newBodyParams; + + newBodyParams.setPumpUpDistance( bodyParams.pumpUpDistance() ); + newBodyParams.setPumpUpTime( bodyParams.pumpUpTime() ); + newBodyParams.setPumpUpPause( bodyParams.pumpUpPause() ); + newBodyParams.setPumpDownPause( bodyParams.pumpDownPause() ); + newBodyParams.setNoPumpUpVelocity( bodyParams.noPumpUpVelocity() ); + newBodyParams.setPumpEveryNthLayer( bodyParams.pumpEveryNthLayer() ); + newBodyParams.setLayerThickness( bodyParams.layerThickness() ); + newBodyParams.setLayerExposureTime( bodyParams.layerExposureTime() ); + newBodyParams.setPowerLevel( bodyParams.powerLevel() ); + + profile->setBaseLayersPumpingParameters(bodyParams); + + ProfilesJsonParser::saveProfiles(_printProfileManager->profiles()); + + return true; +} + bool ProfilesTab::_deletePrintProfile() { QModelIndex index = _profilesList->currentIndex(); diff --git a/src/profilestab.h b/src/profilestab.h index 7a37bd6b..48afb2ad 100644 --- a/src/profilestab.h +++ b/src/profilestab.h @@ -27,6 +27,8 @@ class ProfilesTab: public TabBase { QPushButton* _importParams { new QPushButton("Import") }; QPushButton* _exportParams { new QPushButton("Export") }; QPushButton* _newProfile { new QPushButton("Create profile") }; + QPushButton* _renameProfile { new QPushButton("Rename profile") }; + QPushButton* _overwriteProfile { new QPushButton("Update profile") }; QPushButton* _deleteProfile { new QPushButton("Delete selected") }; QPushButton* _loadProfile { new QPushButton("Load selected") }; QCheckBox* _cpyProfilesUsb { new QCheckBox("Copy profiles to USB") }; @@ -37,6 +39,8 @@ class ProfilesTab: public TabBase { void _setupProfilesList(QFont font); bool _createNewProfile(QString profileName); + bool _renamePProfile(QString profileName); + bool _updateProfile(); bool _deletePrintProfile(); bool _loadPrintProfile(); signals: @@ -56,6 +60,8 @@ private slots: void importParams_clicked(bool); void exportParams_clicked(bool); void newProfile_clicked(bool); + void renamePProfile_clicked(bool); + void updateProfile_clicked(bool); void deleteProfile_clicked(bool); void loadProfile_clicked(bool); From 07c474d95100db40e9f338abac65d670612d1e98 Mon Sep 17 00:00:00 2001 From: sagittarius89 Date: Wed, 12 Feb 2020 14:42:15 +0100 Subject: [PATCH 2/4] - first part of changes for "Load folder of images": * copy sliced project tu USB operation * changes on prepare tab gui --- src/preparetab.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++- src/preparetab.h | 16 ++++++- src/window.cpp | 6 ++- 3 files changed, 126 insertions(+), 4 deletions(-) diff --git a/src/preparetab.cpp b/src/preparetab.cpp index d66a1b3b..8bef02df 100644 --- a/src/preparetab.cpp +++ b/src/preparetab.cpp @@ -10,6 +10,9 @@ #include "shepherd.h" #include "svgrenderer.h" #include "timinglogger.h" +#include "usbmountmanager.h" + +#include "iostream" PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixin( parent ) { auto origFont = font( ); @@ -81,6 +84,13 @@ PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixinsetText( "Prepare" ); QObject::connect( _prepareButton, &QPushButton::clicked, this, &PrepareTab::prepareButton_clicked ); + _copyToUSBButton->setEnabled( false ); + _copyToUSBButton->setFixedSize( MainButtonSize ); + _copyToUSBButton->setFont( font22pt ); + _copyToUSBButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); + _copyToUSBButton->setText( "Copy to USB" ); + QObject::connect( _copyToUSBButton, &QPushButton::clicked, this, &PrepareTab::copyToUSB_clicked ); + _optionsContainer->setFixedWidth( MainButtonSize.width( ) ); _optionsContainer->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding ); _optionsContainer->setLayout( WrapWidgetsInVBox( @@ -124,6 +134,7 @@ PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixinsetAlignment( Qt::AlignCenter ); _navigateCurrentLabel->setText( "0/0" ); @@ -145,7 +156,8 @@ PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixinsetContentsMargins( { } ); _layout->addWidget( _optionsContainer, 0, 0, 1, 1 ); _layout->addWidget( _sliceButton, 1, 0, 1, 1 ); - _layout->addWidget( _currentLayerGroup, 0, 1, 2, 1 ); + _layout->addWidget( _copyToUSBButton, 2, 0, 1, 1 ); + _layout->addWidget( _currentLayerGroup, 0, 1, 3, 1 ); _layout->setRowStretch( 0, 4 ); _layout->setRowStretch( 1, 1 ); @@ -177,6 +189,11 @@ void PrepareTab::_initialShowEvent( QShowEvent* event ) { event->accept( ); } +void PrepareTab::_connectUsbMountManager( ) { + QObject::connect( _usbMountManager, &UsbMountManager::filesystemMounted, this, &PrepareTab::usbMountManager_filesystemMounted ); + QObject::connect( _usbMountManager, &UsbMountManager::filesystemUnmounted, this, &PrepareTab::usbMountManager_filesystemUnmounted ); +} + bool PrepareTab::_checkPreSlicedFiles( ) { debug( "+ PrepareTab::_checkPreSlicedFiles\n" ); @@ -271,9 +288,11 @@ bool PrepareTab::_checkJobDirectory( ) { if ( preSliced ) { _navigateCurrentLabel->setText( QString( "1/%1" ).arg( _printJob->layerCount ) ); _sliceButton->setText( "Reslice" ); + _copyToUSBButton->setEnabled( true ); } else { _navigateCurrentLabel->setText( "0/0" ); _sliceButton->setText( "Slice" ); + _copyToUSBButton->setEnabled( false ); } update( ); @@ -468,6 +487,8 @@ void PrepareTab::slicerProcess_finished( int exitCode, QProcess::ExitStatus exit _sliceStatus->setText( "finished" ); _imageGeneratorStatus->setText( "starting" ); + _copyToUSBButton->setEnabled(true); + update( ); _svgRenderer = new SvgRenderer; @@ -695,3 +716,88 @@ void PrepareTab::setPrinterAvailable( bool const value ) { _updatePrepareButtonState( ); } + +void PrepareTab::copyToUSB_clicked( bool ) { + debug( "+ PrepareTab::copyToUSB_clicked\n" ); + + QDir jobDir { _printJob->jobWorkingDirectory }; + QDir _mediaDir { _usbPath }; + + _mediaDir.mkdir(jobDir.dirName()); + QDirIterator it(_printJob->jobWorkingDirectory, QDirIterator::NoIteratorFlags); + while (it.hasNext()) { + QString fileName = it.next(); + QFileInfo fileInfo(fileName); + + QString dest = _usbPath + Slash + jobDir.dirName() + Slash + fileInfo.fileName(); + + QFile::copy(fileName, dest); + + std::cout << dest.toStdString() << std::endl; + } + + update( ); +} + +void PrepareTab::usbMountManager_filesystemMounted( QString const& mountPoint ) { + debug( "+ PrepareTab::usbMountManager_filesystemMounted: mount point '%s'\n", mountPoint.toUtf8( ).data( ) ); + + if ( !_usbPath.isEmpty( ) ) { + debug( " + We already have a USB storage device at '%s' mounted; ignoring new mount\n", _usbPath.toUtf8( ).data( ) ); + return; + } + + QFileInfo usbPathInfo { mountPoint }; + if ( !usbPathInfo.isReadable( ) || !usbPathInfo.isExecutable( ) ) { + debug( " + Unable to access mount point '%s' (uid: %u; gid: %u; mode: 0%03o)\n", _usbPath.toUtf8( ).data( ), usbPathInfo.ownerId( ), usbPathInfo.groupId( ), usbPathInfo.permissions( ) & 07777 ); + return; + } + + _usbPath = mountPoint; + _createUsbFsModel( ); + + update( ); +} + +void PrepareTab::usbMountManager_filesystemUnmounted( QString const& mountPoint ) { + debug( "+ PrepareTab::usbMountManager_filesystemUnmounted: mount point '%s'\n", mountPoint.toUtf8( ).data( ) ); + + if ( mountPoint != _usbPath ) { + debug( " + not our filesystem; ignoring\n", _usbPath.toUtf8( ).data( ) ); + return; + } + + _usbPath.clear( ); + _destroyUsbFsModel( ); + _copyToUSBButton->setEnabled( false ); + + update( ); +} + +void PrepareTab::_destroyUsbFsModel( ) { + if ( _usbFsModel ) { + QObject::disconnect( _usbFsModel ); + _usbFsModel->deleteLater( ); + _usbFsModel = nullptr; + } +} + +void PrepareTab::_createUsbFsModel( ) { + _destroyUsbFsModel( ); + + _usbFsModel = new QFileSystemModel; + _usbFsModel->setFilter( QDir::Dirs ); + _usbFsModel->setNameFilterDisables( false ); + _usbFsModel->setNameFilters( { { "*-50" }, {"-100"} } ); + (void) QObject::connect( _usbFsModel, &QFileSystemModel::directoryLoaded, this, &PrepareTab::usbFsModel_directoryLoaded ); + _usbFsModel->setRootPath( _usbPath ); +} + +void PrepareTab::usbFsModel_directoryLoaded( QString const& /*name*/ ) { + debug( "+ PrepareTab::usbFsModel_directoryLoaded\n" ); + + if(!_sliceButton->isEnabled()) + _copyToUSBButton->setEnabled(true); + + update( ); +} diff --git a/src/preparetab.h b/src/preparetab.h index e02ee3be..dcc159fe 100644 --- a/src/preparetab.h +++ b/src/preparetab.h @@ -25,7 +25,7 @@ class PrepareTab: public InitialShowEventMixin { virtual void _connectPrintManager( ) override; virtual void _connectShepherd( ) override; virtual void _initialShowEvent( QShowEvent* event ) override; - + virtual void _connectUsbMountManager( ) override; private: QProcess* _slicerProcess { }; @@ -49,6 +49,11 @@ class PrepareTab: public InitialShowEventMixin { QLabel* _prepareMessage { new QLabel }; QProgressBar* _prepareProgress { new QProgressBar }; QPushButton* _prepareButton { new QPushButton }; + QPushButton* _copyToUSBButton { new QPushButton }; + QString _usbPath; + QFileSystemModel* _libraryFsModel { new QFileSystemModel }; + QFileSystemModel* _usbFsModel { }; + QPixmap* _warningHotImage { }; QLabel* _warningHotLabel { new QLabel }; @@ -80,6 +85,9 @@ class PrepareTab: public InitialShowEventMixin { void _updatePrepareButtonState( ); void _handlePrepareFailed( ); + void _createUsbFsModel( ); + void _destroyUsbFsModel( ); + void _deleteModel( ); signals: @@ -96,10 +104,14 @@ public slots: void setPrinterAvailable( bool const value ); + protected slots: private slots: + void usbMountManager_filesystemMounted( QString const& mountPoint ); + void usbMountManager_filesystemUnmounted( QString const& mountPoint ); + void printer_online( ); void printer_offline( ); void printer_temperatureReport( double const bedCurrentTemperature, double const bedTargetTemperature, int const bedPwm ); @@ -130,6 +142,8 @@ private slots: void adjustBuildPlatform_complete( bool ); void shepherd_raiseBuildPlatformMoveToComplete( bool const success ); + void copyToUSB_clicked( bool ); + void usbFsModel_directoryLoaded( QString const& /*name*/ ); }; #endif // __PREPARETAB_H__ diff --git a/src/window.cpp b/src/window.cpp index 47ade5ea..8926ff61 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -93,6 +93,7 @@ Window::Window( QWidget* parent ): QMainWindow( parent ) { emit printJobChanged( _printJob ); _fileTab ->setUsbMountManager ( _usbMountManager ); + _prepareTab ->setUsbMountManager ( _usbMountManager ); _advancedTab->setPngDisplayer ( _pngDisplayer ); _profilesTab->setPrintProfileManager( _printProfileManager ); _systemTab ->setUpgradeManager ( _upgradeManager ); @@ -249,8 +250,9 @@ void Window::terminate( ) { } if ( _usbMountManager ) { - _fileTab ->setUsbMountManager( nullptr ); - _systemTab->setUsbMountManager( nullptr ); + _fileTab ->setUsbMountManager( nullptr ); + _prepareTab->setUsbMountManager( nullptr ); + _systemTab ->setUsbMountManager( nullptr ); QObject::disconnect( _usbMountManager ); _usbMountManager->deleteLater( ); From eef97e6df469202c3a24fe3068b87da30b11635b Mon Sep 17 00:00:00 2001 From: sagittarius89 Date: Fri, 14 Feb 2020 18:55:09 +0100 Subject: [PATCH 3/4] Added copying folder of images from USB, end form setup --- src/filetab.cpp | 129 +++++++++++++++++++++++++++++++-------------- src/filetab.h | 18 ++++--- src/preparetab.cpp | 8 ++- src/tabbase.h | 1 + src/window.cpp | 7 +++ 5 files changed, 116 insertions(+), 47 deletions(-) diff --git a/src/filetab.cpp b/src/filetab.cpp index c69b2360..c9b79705 100644 --- a/src/filetab.cpp +++ b/src/filetab.cpp @@ -158,9 +158,10 @@ void FileTab::_createUsbFsModel( ) { _destroyUsbFsModel( ); _usbFsModel = new QFileSystemModel; - _usbFsModel->setFilter( QDir::Files ); + _usbFsModel->setFilter( QDir::Files | QDir::Dirs ); _usbFsModel->setNameFilterDisables( false ); - _usbFsModel->setNameFilters( { { "*.stl" } } ); + //_usbFsModel->setNameFilters( { { "*.stl" } } ); + _usbFsModel->setNameFilters( { { "*.stl" }, { "*-50" }, { "*-100" } } ); (void) QObject::connect( _usbFsModel, &QFileSystemModel::directoryLoaded, this, &FileTab::usbFsModel_directoryLoaded ); _usbFsModel->setRootPath( _usbPath ); } @@ -478,23 +479,33 @@ void FileTab::availableFilesListView_clicked( QModelIndex const& index ) { } _modelSelection = { ( ( _modelsLocation == ModelsLocation::Library ) ? StlModelLibraryPath : _usbPath ) % Slash % index.data( ).toString( ) }; + QFileInfo check_file(_modelSelection.fileName); + _modelSelection.type = check_file.isFile() ? ModelFileType::File : ModelFileType::Directory; + _selectedRow = indexRow; - _availableFilesListView->setEnabled( false ); - _selectButton->setEnabled( false ); - _viewSolid->setEnabled( false ); - _viewWireframe->setEnabled( false ); - _deleteButton->setEnabled( false ); - update( ); + if(_modelSelection.type == ModelFileType::File) + { + _availableFilesListView->setEnabled( false ); + _selectButton->setEnabled( false ); + _viewSolid->setEnabled( false ); + _viewWireframe->setEnabled( false ); + _deleteButton->setEnabled( false ); + update( ); - if ( _processRunner ) { - QObject::disconnect( _processRunner, nullptr, this, nullptr ); - _processRunner->terminate( ); - _processRunner->deleteLater( ); - _processRunner = nullptr; - } + if ( _processRunner ) { + QObject::disconnect( _processRunner, nullptr, this, nullptr ); + _processRunner->terminate( ); + _processRunner->deleteLater( ); + _processRunner = nullptr; + } - _loadModel( _modelSelection.fileName ); + _loadModel( _modelSelection.fileName ); + } + else + { + _selectButton->setEnabled( true ); + } } void FileTab::availableFilesListView_swipeGesture( QGestureEvent* event, QSwipeGesture* gesture ) { @@ -556,33 +567,73 @@ void FileTab::selectButton_clicked( bool ) { emit modelSelected( &_modelSelection ); emit uiStateChanged( TabIndex::File, UiState::SelectCompleted ); } else { - auto fileCopier { new FileCopier }; - auto fileNamePair { FileNamePair { - _modelSelection.fileName, - StlModelLibraryPath % Slash % GetFileBaseName( _modelSelection.fileName ) } - }; - - QObject::connect( fileCopier, &FileCopier::notify, this, [ this ] ( int const index, QString const message ) { - debug( "+ FileTab::selectButton_clicked/lambda for FileCopier::notify: index %d: message '%s'\n", index, message.toUtf8( ).data( ) ); - }, Qt::QueuedConnection ); - - QObject::connect( fileCopier, &FileCopier::finished, this, [ this, fileNamePair ] ( int const copiedFiles, int const skippedFiles ) { - debug( "+ FileTab::selectButton_clicked/lambda for FileCopier::finished: files copied %d, files skipped %d\n", copiedFiles, skippedFiles ); - if ( copiedFiles == 1 ) { - _showLibrary( ); - - auto index = _libraryFsModel->index( fileNamePair.second ); - _availableFilesListView->selectionModel( )->select( index, QItemSelectionModel::ClearAndSelect ); - availableFilesListView_clicked( index ); - } else { - // TODO inform user of failure somehow + if(_modelSelection.type == ModelFileType::File) { + auto fileCopier { new FileCopier }; + auto fileNamePair { FileNamePair { + _modelSelection.fileName, + StlModelLibraryPath % Slash % GetFileBaseName( _modelSelection.fileName ) } + }; + + QObject::connect( fileCopier, &FileCopier::notify, this, [ this ] ( int const index, QString const message ) { + debug( "+ FileTab::selectButton_clicked/lambda for FileCopier::notify: index %d: message '%s'\n", index, message.toUtf8( ).data( ) ); + }, Qt::QueuedConnection ); + + QObject::connect( fileCopier, &FileCopier::finished, this, [ this, fileNamePair ] ( int const copiedFiles, int const skippedFiles ) { + debug( "+ FileTab::selectButton_clicked/lambda for FileCopier::finished: files copied %d, files skipped %d\n", copiedFiles, skippedFiles ); + if ( copiedFiles == 1 ) { + _showLibrary( ); + + auto index = _libraryFsModel->index( fileNamePair.second ); + _availableFilesListView->selectionModel( )->select( index, QItemSelectionModel::ClearAndSelect ); + availableFilesListView_clicked( index ); + } else { + // TODO inform user of failure somehow + } + }, Qt::QueuedConnection ); + + QObject::connect( fileCopier, &FileCopier::finished, fileCopier, &FileCopier::deleteLater, Qt::QueuedConnection ); + + debug( "+ FileTab::selectButton_clicked: copying %s to %s\n", fileNamePair.first.toUtf8( ).data( ), fileNamePair.second.toUtf8( ).data( ) ); + fileCopier->copy( { fileNamePair } ); + } + else if (_modelSelection.type == ModelFileType::Directory) + { + auto fileCopier { new FileCopier }; + FileNamePairList pairList {}; + + + QDir modelLib { JobWorkingDirectoryPath }; + QString folderCpyName = GetFileBaseName( _modelSelection.fileName ); + QString folderCpyPath = JobWorkingDirectoryPath % Slash % folderCpyName; + + modelLib.mkdir(folderCpyName); + + QDirIterator it(_modelSelection.fileName, QDir::Files); + while (it.hasNext()) { + QString fileName = it.next(); + auto fileNamePair { FileNamePair { + fileName, + folderCpyPath % Slash % GetFileBaseName( fileName ) } + }; + + pairList.push_back(fileNamePair); } - }, Qt::QueuedConnection ); - QObject::connect( fileCopier, &FileCopier::finished, fileCopier, &FileCopier::deleteLater, Qt::QueuedConnection ); + QObject::connect( fileCopier, &FileCopier::finished, this, [ this, folderCpyPath ] ( int const copiedFiles, int const skippedFiles ) { + debug( "+ FileTab::selectButton_clicked/lambda for FileCopier::finished: files copied %d, files skipped %d\n", copiedFiles, skippedFiles ); + if ( copiedFiles > 0 ) { + emit uiStateChanged( TabIndex::File, UiState::SelectedDirectory ); + } else { + // TODO inform user of failure somehow + } + }, Qt::QueuedConnection ); - debug( "+ FileTab::selectButton_clicked: copying %s to %s\n", fileNamePair.first.toUtf8( ).data( ), fileNamePair.second.toUtf8( ).data( ) ); - fileCopier->copy( { fileNamePair } ); + QObject::connect( fileCopier, &FileCopier::finished, fileCopier, &FileCopier::deleteLater, Qt::QueuedConnection ); + + + _printJob->jobWorkingDirectory = JobWorkingDirectoryPath % Slash % folderCpyName; + fileCopier->copy( pairList ); + } } update( ); diff --git a/src/filetab.h b/src/filetab.h index 016efbd9..fe8acc24 100644 --- a/src/filetab.h +++ b/src/filetab.h @@ -15,6 +15,11 @@ enum class ModelsLocation { Usb }; +enum class ModelFileType { + File, + Directory +}; + class ModelSelectionInfo { public: @@ -31,12 +36,13 @@ class ModelSelectionInfo { /*empty*/ } - QString fileName; - size_t vertexCount { }; - Coordinate x { }; - Coordinate y { }; - Coordinate z { }; - double estimatedVolume { }; + QString fileName; + ModelFileType type; + size_t vertexCount { }; + Coordinate x { }; + Coordinate y { }; + Coordinate z { }; + double estimatedVolume { }; }; diff --git a/src/preparetab.cpp b/src/preparetab.cpp index 8bef02df..26d09546 100644 --- a/src/preparetab.cpp +++ b/src/preparetab.cpp @@ -156,8 +156,8 @@ PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixinsetContentsMargins( { } ); _layout->addWidget( _optionsContainer, 0, 0, 1, 1 ); _layout->addWidget( _sliceButton, 1, 0, 1, 1 ); - _layout->addWidget( _copyToUSBButton, 2, 0, 1, 1 ); - _layout->addWidget( _currentLayerGroup, 0, 1, 3, 1 ); + //_layout->addWidget( _copyToUSBButton, 2, 0, 1, 1 ); + _layout->addWidget( _currentLayerGroup, 0, 1, /* ^ 3*/ 2, 1 ); _layout->setRowStretch( 0, 4 ); _layout->setRowStretch( 1, 1 ); @@ -671,6 +671,10 @@ void PrepareTab::tab_uiStateChanged( TabIndex const sender, UiState const state setPrinterAvailable( true ); emit printerAvailabilityChanged( true ); break; + case UiState::SelectedDirectory: + _setSliceControlsEnabled( false ); + slicerProcess_finished(0, QProcess::NormalExit); + break; } update( ); diff --git a/src/tabbase.h b/src/tabbase.h index 655a37af..b409e756 100644 --- a/src/tabbase.h +++ b/src/tabbase.h @@ -38,6 +38,7 @@ class TabBase: public QWidget { SliceCompleted, PrintStarted, PrintCompleted, + SelectedDirectory }; Q_ENUM( UiState ); diff --git a/src/window.cpp b/src/window.cpp index 8926ff61..4f3fa642 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -367,6 +367,13 @@ void Window::tab_uiStateChanged( TabIndex const sender, UiState const state ) { case UiState::PrintStarted: case UiState::PrintCompleted: break; + case UiState::SelectedDirectory: + if ( _tabWidget->currentIndex( ) == +TabIndex::File ) { + _tabWidget->setCurrentIndex( +TabIndex::Prepare ); + + update( ); + } + break; } } From db5d3cd7d10fef891eb248c403842d585a1077fe Mon Sep 17 00:00:00 2001 From: sagittarius89 Date: Mon, 17 Feb 2020 16:24:07 +0100 Subject: [PATCH 4/4] - done commit cleanup (warings, dead code etc) - done manual testing - fixed enable/disable slice buttons in each state of GUI - fixed selection of layer thickness after copying folder of images --- src/advancedtab.cpp | 2 ++ src/filetab.cpp | 1 + src/filetab.h | 2 +- src/preparetab.cpp | 50 +++++++++++++++++++-------------------------- src/preparetab.h | 5 +---- src/printtab.cpp | 2 ++ src/profilestab.cpp | 1 + src/statustab.cpp | 2 ++ src/systemtab.cpp | 2 ++ 9 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/advancedtab.cpp b/src/advancedtab.cpp index ba8f7df8..bc5b909e 100644 --- a/src/advancedtab.cpp +++ b/src/advancedtab.cpp @@ -136,6 +136,8 @@ void AdvancedTab::tab_uiStateChanged( TabIndex const sender, UiState const state setPrinterAvailable( true ); emit printerAvailabilityChanged( true ); break; + default: + break; } } diff --git a/src/filetab.cpp b/src/filetab.cpp index c9b79705..ab2f35a1 100644 --- a/src/filetab.cpp +++ b/src/filetab.cpp @@ -270,6 +270,7 @@ void FileTab::tab_uiStateChanged( TabIndex const sender, UiState const state ) { case UiState::SliceCompleted: case UiState::PrintStarted: case UiState::PrintCompleted: + case UiState::SelectedDirectory: break; } } diff --git a/src/filetab.h b/src/filetab.h index fe8acc24..45199f8b 100644 --- a/src/filetab.h +++ b/src/filetab.h @@ -37,7 +37,7 @@ class ModelSelectionInfo { } QString fileName; - ModelFileType type; + ModelFileType type { ModelFileType::File }; size_t vertexCount { }; Coordinate x { }; Coordinate y { }; diff --git a/src/preparetab.cpp b/src/preparetab.cpp index 26d09546..94fede4a 100644 --- a/src/preparetab.cpp +++ b/src/preparetab.cpp @@ -156,8 +156,13 @@ PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixinsetContentsMargins( { } ); _layout->addWidget( _optionsContainer, 0, 0, 1, 1 ); _layout->addWidget( _sliceButton, 1, 0, 1, 1 ); + + /* copy to USB button is turned off now */ + //_layout->addWidget( _copyToUSBButton, 2, 0, 1, 1 ); _layout->addWidget( _currentLayerGroup, 0, 1, /* ^ 3*/ 2, 1 ); + //_layout->addWidget( _copyToUSBButton, 2, 0, 1, 1 ); + //_layout->addWidget( _currentLayerGroup, 0, 1, 3, 1 ); _layout->setRowStretch( 0, 4 ); _layout->setRowStretch( 1, 1 ); @@ -632,6 +637,7 @@ void PrepareTab::tab_uiStateChanged( TabIndex const sender, UiState const state switch ( _uiState ) { case UiState::SelectStarted: + _directoryMode = false; _setSliceControlsEnabled( false ); break; @@ -657,7 +663,8 @@ void PrepareTab::tab_uiStateChanged( TabIndex const sender, UiState const state break; case UiState::SliceCompleted: - _setSliceControlsEnabled( true ); + if(!_directoryMode) + _setSliceControlsEnabled( true ); break; case UiState::PrintStarted: @@ -672,7 +679,18 @@ void PrepareTab::tab_uiStateChanged( TabIndex const sender, UiState const state emit printerAvailabilityChanged( true ); break; case UiState::SelectedDirectory: + _directoryMode = true; _setSliceControlsEnabled( false ); + + if(_printJob->jobWorkingDirectory.endsWith("-100")) + { + _layerThickness100Button->setChecked( true ); + } + else + { + _layerThickness50Button->setChecked( true ); + } + slicerProcess_finished(0, QProcess::NormalExit); break; } @@ -758,8 +776,9 @@ void PrepareTab::usbMountManager_filesystemMounted( QString const& mountPoint ) } _usbPath = mountPoint; - _createUsbFsModel( ); + if(!_directoryMode && _checkPreSlicedFiles( )) + _copyToUSBButton->setEnabled( true ); update( ); } @@ -772,36 +791,9 @@ void PrepareTab::usbMountManager_filesystemUnmounted( QString const& mountPoint } _usbPath.clear( ); - _destroyUsbFsModel( ); _copyToUSBButton->setEnabled( false ); update( ); } -void PrepareTab::_destroyUsbFsModel( ) { - if ( _usbFsModel ) { - QObject::disconnect( _usbFsModel ); - _usbFsModel->deleteLater( ); - _usbFsModel = nullptr; - } -} - -void PrepareTab::_createUsbFsModel( ) { - _destroyUsbFsModel( ); - - _usbFsModel = new QFileSystemModel; - _usbFsModel->setFilter( QDir::Dirs ); - _usbFsModel->setNameFilterDisables( false ); - _usbFsModel->setNameFilters( { { "*-50" }, {"-100"} } ); - (void) QObject::connect( _usbFsModel, &QFileSystemModel::directoryLoaded, this, &PrepareTab::usbFsModel_directoryLoaded ); - _usbFsModel->setRootPath( _usbPath ); -} -void PrepareTab::usbFsModel_directoryLoaded( QString const& /*name*/ ) { - debug( "+ PrepareTab::usbFsModel_directoryLoaded\n" ); - - if(!_sliceButton->isEnabled()) - _copyToUSBButton->setEnabled(true); - - update( ); -} diff --git a/src/preparetab.h b/src/preparetab.h index dcc159fe..97330012 100644 --- a/src/preparetab.h +++ b/src/preparetab.h @@ -35,6 +35,7 @@ class PrepareTab: public InitialShowEventMixin { int _renderedLayers { }; bool _isPrinterOnline { false }; bool _isPrinterAvailable { true }; + bool _directoryMode { false }; /* flag - is selected directory of images */ QLabel* _layerThicknessLabel { new QLabel }; QRadioButton* _layerThickness50Button { new QRadioButton }; @@ -85,9 +86,6 @@ class PrepareTab: public InitialShowEventMixin { void _updatePrepareButtonState( ); void _handlePrepareFailed( ); - void _createUsbFsModel( ); - void _destroyUsbFsModel( ); - void _deleteModel( ); signals: @@ -143,7 +141,6 @@ private slots: void shepherd_raiseBuildPlatformMoveToComplete( bool const success ); void copyToUSB_clicked( bool ); - void usbFsModel_directoryLoaded( QString const& /*name*/ ); }; #endif // __PREPARETAB_H__ diff --git a/src/printtab.cpp b/src/printtab.cpp index 7aaf0fc1..8d693709 100644 --- a/src/printtab.cpp +++ b/src/printtab.cpp @@ -358,6 +358,8 @@ void PrintTab::tab_uiStateChanged( TabIndex const sender, UiState const state ) setPrinterAvailable( true ); emit printerAvailabilityChanged( true ); break; + case UiState::SelectedDirectory: + break; } update( ); diff --git a/src/profilestab.cpp b/src/profilestab.cpp index fff82dd7..746fa013 100644 --- a/src/profilestab.cpp +++ b/src/profilestab.cpp @@ -104,6 +104,7 @@ void ProfilesTab::tab_uiStateChanged( TabIndex const sender, UiState const state case UiState::SliceCompleted: case UiState::PrintStarted: case UiState::PrintCompleted: + case UiState::SelectedDirectory: break; } } diff --git a/src/statustab.cpp b/src/statustab.cpp index 80f237b4..0c44ab99 100644 --- a/src/statustab.cpp +++ b/src/statustab.cpp @@ -561,6 +561,8 @@ void StatusTab::tab_uiStateChanged( TabIndex const sender, UiState const state ) _stopButton->setVisible( false ); _reprintButton->setVisible( true ); break; + case UiState::SelectedDirectory: + break; } _updateReprintButtonState( ); diff --git a/src/systemtab.cpp b/src/systemtab.cpp index 02764e6f..ed264daf 100644 --- a/src/systemtab.cpp +++ b/src/systemtab.cpp @@ -139,6 +139,8 @@ void SystemTab::tab_uiStateChanged( TabIndex const sender, UiState const state ) case UiState::PrintStarted: setPrinterAvailable( false ); break; + case UiState::SelectedDirectory: + break; } }