Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/advancedtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ void AdvancedTab::tab_uiStateChanged( TabIndex const sender, UiState const state
setPrinterAvailable( true );
emit printerAvailabilityChanged( true );
break;
default:
break;
}
}

Expand Down
130 changes: 91 additions & 39 deletions src/filetab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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( );
Expand Down
18 changes: 12 additions & 6 deletions src/filetab.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ enum class ModelsLocation {
Usb
};

enum class ModelFileType {
File,
Directory
};

class ModelSelectionInfo {

public:
Expand All @@ -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 { };

};

Expand Down
106 changes: 104 additions & 2 deletions src/preparetab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "shepherd.h"
#include "svgrenderer.h"
#include "timinglogger.h"
#include "usbmountmanager.h"

#include "iostream"

PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixin<PrepareTab, TabBase>( parent ) {
auto origFont = font( );
Expand Down Expand Up @@ -81,6 +84,13 @@ PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixin<PrepareTab, Tab
_prepareButton->setText( "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(
Expand Down Expand Up @@ -124,6 +134,7 @@ PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixin<PrepareTab, Tab
QObject::connect( _navigateNext, &QPushButton::clicked, this, &PrepareTab::navigateNext_clicked );
QObject::connect( _navigateLast, &QPushButton::clicked, this, &PrepareTab::navigateLast_clicked );


_navigateCurrentLabel->setAlignment( Qt::AlignCenter );
_navigateCurrentLabel->setText( "0/0" );

Expand All @@ -145,7 +156,13 @@ PrepareTab::PrepareTab( QWidget* parent ): InitialShowEventMixin<PrepareTab, Tab
_layout->setContentsMargins( { } );
_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 );

Expand Down Expand Up @@ -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" );

Expand Down Expand Up @@ -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( );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -611,6 +637,7 @@ void PrepareTab::tab_uiStateChanged( TabIndex const sender, UiState const state

switch ( _uiState ) {
case UiState::SelectStarted:
_directoryMode = false;
_setSliceControlsEnabled( false );
break;

Expand All @@ -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:
Expand All @@ -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( );
Expand Down Expand Up @@ -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( );
}


Loading