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 c69b2360..ab2f35a1 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 ); } @@ -269,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; } } @@ -478,23 +480,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 +568,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..45199f8b 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 { ModelFileType::File }; + size_t vertexCount { }; + Coordinate x { }; + Coordinate y { }; + Coordinate z { }; + double estimatedVolume { }; }; diff --git a/src/preparetab.cpp b/src/preparetab.cpp index d66a1b3b..94fede4a 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,13 @@ 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 ); + + /* 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 ); @@ -177,6 +194,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 +293,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 +492,8 @@ void PrepareTab::slicerProcess_finished( int exitCode, QProcess::ExitStatus exit _sliceStatus->setText( "finished" ); _imageGeneratorStatus->setText( "starting" ); + _copyToUSBButton->setEnabled(true); + update( ); _svgRenderer = new SvgRenderer; @@ -611,6 +637,7 @@ void PrepareTab::tab_uiStateChanged( TabIndex const sender, UiState const state switch ( _uiState ) { case UiState::SelectStarted: + _directoryMode = false; _setSliceControlsEnabled( false ); break; @@ -636,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: @@ -650,6 +678,21 @@ void PrepareTab::tab_uiStateChanged( TabIndex const sender, UiState const state setPrinterAvailable( true ); 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; } update( ); @@ -695,3 +738,62 @@ 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; + + if(!_directoryMode && _checkPreSlicedFiles( )) + _copyToUSBButton->setEnabled( true ); + 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( ); + _copyToUSBButton->setEnabled( false ); + + update( ); +} + + diff --git a/src/preparetab.h b/src/preparetab.h index e02ee3be..97330012 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 { }; @@ -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 }; @@ -49,6 +50,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 }; @@ -96,10 +102,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 +140,7 @@ private slots: void adjustBuildPlatform_complete( bool ); void shepherd_raiseBuildPlatformMoveToComplete( bool const success ); + void copyToUSB_clicked( bool ); }; #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 f6133925..746fa013 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 ) @@ -86,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; } } @@ -98,7 +117,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 +258,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 +383,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); 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; } } 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 47ade5ea..4f3fa642 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( ); @@ -365,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; } }