2014-04-19 11:51:02 -07:00
/ *
Copyright ( c ) 2014 , Kevin Pope
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this
list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies ,
either expressed or implied , of the FreeBSD Project .
* /
using System ;
2014-01-29 19:09:30 -08:00
using System.Collections.Generic ;
using System.IO ;
using MatterHackers.Agg ;
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
2014-03-22 10:04:04 -07:00
using MatterHackers.MatterControl.CreatorPlugins ;
2014-04-17 11:02:38 -07:00
using MatterHackers.MatterControl.DataStorage ;
using MatterHackers.MatterControl.SlicerConfiguration ;
2014-04-23 17:44:49 -07:00
using MatterHackers.MatterControl.SettingsManagement ;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl.PrintQueue
{
2014-04-19 11:51:02 -07:00
public class QueueBottomToolbar : GuiWidget
2014-01-29 19:09:30 -08:00
{
TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory ( ) ;
2014-03-22 10:04:04 -07:00
PluginChooserWindow pluginChooserWindow ;
2014-04-15 18:13:27 -07:00
QueueDataView queueDataView ;
2014-01-29 19:09:30 -08:00
2014-04-21 16:19:41 -07:00
static Button shopButton ;
2014-06-23 09:31:14 -07:00
event EventHandler unregisterEvents ;
2014-04-21 16:19:41 -07:00
2014-04-19 11:51:02 -07:00
public QueueBottomToolbar ( QueueDataView queueDataView )
2014-01-29 19:09:30 -08:00
{
2014-04-15 18:13:27 -07:00
this . queueDataView = queueDataView ;
2014-01-29 19:09:30 -08:00
SetDisplayAttributes ( ) ;
2014-03-21 16:18:47 -07:00
textImageButtonFactory . normalTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . hoverTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . disabledTextColor = ActiveTheme . Instance . PrimaryTextColor ;
textImageButtonFactory . pressedTextColor = ActiveTheme . Instance . PrimaryTextColor ;
2014-01-29 19:09:30 -08:00
textImageButtonFactory . borderWidth = 0 ;
FlowLayoutWidget allControls = new FlowLayoutWidget ( FlowDirection . TopToBottom ) ;
{
{
// Ensure the form opens with no rows selected.
//ActiveQueueList.Instance.ClearSelected();
2014-04-15 18:13:27 -07:00
allControls . AddChild ( queueDataView ) ;
2014-01-29 19:09:30 -08:00
}
FlowLayoutWidget buttonPanel1 = new FlowLayoutWidget ( ) ;
buttonPanel1 . HAnchor = HAnchor . ParentLeftRight ;
buttonPanel1 . Padding = new BorderDouble ( 0 , 3 ) ;
{
2014-04-17 11:02:38 -07:00
Button addToQueueButton = textImageButtonFactory . Generate ( LocalizedString . Get ( "Add" ) , "icon_circle_plus.png" ) ;
2014-01-29 19:09:30 -08:00
buttonPanel1 . AddChild ( addToQueueButton ) ;
addToQueueButton . Margin = new BorderDouble ( 0 , 0 , 3 , 0 ) ;
2014-04-15 18:13:27 -07:00
addToQueueButton . Click + = new ButtonBase . ButtonEventHandler ( addToQueueButton_Click ) ;
2014-01-29 19:09:30 -08:00
2014-04-17 11:02:38 -07:00
// put in the creator button
2014-03-22 10:04:04 -07:00
{
2014-04-17 11:02:38 -07:00
Button runCreator = textImageButtonFactory . Generate ( LocalizedString . Get ( "Create" ) , "icon_creator_white_32x32.png" ) ;
buttonPanel1 . AddChild ( runCreator ) ;
runCreator . Margin = new BorderDouble ( 0 , 0 , 3 , 0 ) ;
runCreator . Click + = ( sender , e ) = >
{
OpenPluginChooserWindow ( ) ;
} ;
}
2014-04-23 17:44:49 -07:00
if ( OemSettings . Instance . ShowShopButton )
2014-04-17 11:02:38 -07:00
{
2014-05-01 14:52:54 -07:00
shopButton = textImageButtonFactory . Generate ( LocalizedString . Get ( "Buy Materials" ) , "icon_shopping_cart_32x32.png" ) ;
2014-09-23 19:23:17 -07:00
//buttonPanel1.AddChild(shopButton);
2014-04-21 16:19:41 -07:00
shopButton . Margin = new BorderDouble ( 0 , 0 , 3 , 0 ) ;
shopButton . Click + = ( sender , e ) = >
2014-04-17 11:02:38 -07:00
{
double activeFilamentDiameter = 0 ;
if ( ActivePrinterProfile . Instance . ActivePrinter ! = null )
{
activeFilamentDiameter = 3 ;
if ( ActiveSliceSettings . Instance . FilamentDiameter < 2 )
{
activeFilamentDiameter = 1.75 ;
}
}
2014-04-23 17:44:49 -07:00
System . Diagnostics . Process . Start ( "http://www.matterhackers.com/mc/store/redirect?d={0}&clk=mcs&a={1}" . FormatWith ( activeFilamentDiameter , OemSettings . Instance . AffiliateCode ) ) ;
2014-04-17 11:02:38 -07:00
} ;
}
2014-03-22 10:04:04 -07:00
2014-04-17 11:02:38 -07:00
Button deleteAllFromQueueButton = textImageButtonFactory . Generate ( LocalizedString . Get ( "Remove All" ) ) ;
2014-01-29 19:09:30 -08:00
deleteAllFromQueueButton . Margin = new BorderDouble ( 3 , 0 ) ;
deleteAllFromQueueButton . Click + = new ButtonBase . ButtonEventHandler ( deleteAllFromQueueButton_Click ) ;
2014-04-17 11:02:38 -07:00
//buttonPanel1.AddChild(deleteAllFromQueueButton);
2014-01-29 19:09:30 -08:00
GuiWidget spacer1 = new GuiWidget ( ) ;
spacer1 . HAnchor = HAnchor . ParentLeftRight ;
buttonPanel1 . AddChild ( spacer1 ) ;
GuiWidget spacer2 = new GuiWidget ( ) ;
spacer2 . HAnchor = HAnchor . ParentLeftRight ;
buttonPanel1 . AddChild ( spacer2 ) ;
2014-06-23 09:31:14 -07:00
FlowLayoutWidget queueMenuSpace = new FlowLayoutWidget ( ) ;
2014-09-23 19:23:17 -07:00
queueMenuSpace . VAnchor = Agg . UI . VAnchor . ParentBottomTop ;
QueueOptionsMenu queueMenu = new QueueOptionsMenu ( ) ;
queueMenuSpace . AddChild ( queueMenu . MenuDropList ) ;
2014-06-23 09:31:14 -07:00
buttonPanel1 . AddChild ( queueMenuSpace ) ;
ActivePrinterProfile . Instance . ActivePrinterChanged . RegisterEvent ( ( object sender , EventArgs e ) = >
{
queueMenuSpace . RemoveAllChildren ( ) ;
// the printer changed reload the queueMenue
queueMenu = new QueueOptionsMenu ( ) ;
2014-09-23 19:23:17 -07:00
queueMenuSpace . AddChild ( queueMenu . MenuDropList ) ;
2014-06-23 09:31:14 -07:00
} , ref unregisterEvents ) ;
2014-01-29 19:09:30 -08:00
}
allControls . AddChild ( buttonPanel1 ) ;
}
allControls . AnchorAll ( ) ;
this . AddChild ( allControls ) ;
}
private void SetDisplayAttributes ( )
{
this . Padding = new BorderDouble ( 3 ) ;
this . BackgroundColor = ActiveTheme . Instance . PrimaryBackgroundColor ;
this . AnchorAll ( ) ;
}
2014-03-22 10:04:04 -07:00
private void OpenPluginChooserWindow ( )
{
if ( pluginChooserWindow = = null )
{
pluginChooserWindow = new PluginChooserWindow ( ) ;
pluginChooserWindow . Closed + = ( sender , e ) = >
{
pluginChooserWindow = null ;
} ;
}
else
{
pluginChooserWindow . BringToFront ( ) ;
}
}
void createPartsSheetsButton_Click ( object sender , MouseEventArgs mouseEvent )
2014-01-29 19:09:30 -08:00
{
2014-04-15 18:13:27 -07:00
List < PrintItem > parts = QueueData . Instance . CreateReadOnlyPartList ( ) ;
2014-01-29 19:09:30 -08:00
2014-08-27 12:02:15 -07:00
string documentsPath = System . Environment . GetFolderPath ( System . Environment . SpecialFolder . Personal ) ;
SaveFileDialogParams saveParams = new SaveFileDialogParams ( "Save Parts Sheet|*.pdf" , initialDirectory : documentsPath ) ;
2014-01-29 19:09:30 -08:00
System . IO . Stream streamToSaveTo = FileDialog . SaveFileDialog ( ref saveParams ) ;
if ( streamToSaveTo ! = null )
{
string partFileName = saveParams . FileName ;
if ( ! partFileName . StartsWith ( "" + Path . DirectorySeparatorChar ) )
{
partFileName = Path . DirectorySeparatorChar + partFileName ;
}
PartsSheet currentPartsInQueue = new PartsSheet ( parts , partFileName ) ;
currentPartsInQueue . SaveSheets ( ) ;
}
}
void exportToSDProcess_UpdateRemainingItems ( object sender , EventArgs e )
{
ExportToFolderProcess exportToSDProcess = ( ExportToFolderProcess ) sender ;
}
void exportQueueButton_Click ( object sender , MouseEventArgs mouseEvent )
{
2014-04-15 18:13:27 -07:00
List < PrintItem > partList = QueueData . Instance . CreateReadOnlyPartList ( ) ;
2014-01-29 19:09:30 -08:00
ProjectFileHandler project = new ProjectFileHandler ( partList ) ;
project . SaveAs ( ) ;
}
void importQueueButton_Click ( object sender , MouseEventArgs mouseEvent )
{
ProjectFileHandler project = new ProjectFileHandler ( null ) ;
List < PrintItem > partFiles = project . OpenFromDialog ( ) ;
if ( partFiles ! = null )
2014-05-04 15:07:07 -07:00
{
2014-01-29 19:09:30 -08:00
foreach ( PrintItem part in partFiles )
{
2014-04-16 12:01:01 -07:00
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( part . Name , part . FileLocation ) ) ) ;
2014-01-29 19:09:30 -08:00
}
}
}
void deleteAllFromQueueButton_Click ( object sender , MouseEventArgs mouseEvent )
{
2014-04-15 18:13:27 -07:00
QueueData . Instance . RemoveAll ( ) ;
2014-01-29 19:09:30 -08:00
}
public override void OnDragEnter ( FileDropEventArgs fileDropEventArgs )
{
foreach ( string file in fileDropEventArgs . DroppedFiles )
{
string extension = Path . GetExtension ( file ) . ToUpper ( ) ;
2014-05-17 11:06:34 -07:00
if ( extension = = ".STL" | | extension = = ".GCODE" | | extension = = ".ZIP" )
2014-01-29 19:09:30 -08:00
{
fileDropEventArgs . AcceptDrop = true ;
}
}
base . OnDragEnter ( fileDropEventArgs ) ;
}
public override void OnDragOver ( FileDropEventArgs fileDropEventArgs )
{
foreach ( string file in fileDropEventArgs . DroppedFiles )
{
string extension = Path . GetExtension ( file ) . ToUpper ( ) ;
2014-05-17 11:06:34 -07:00
if ( extension = = ".STL" | | extension = = ".GCODE" | | extension = = ".ZIP" )
2014-01-29 19:09:30 -08:00
{
fileDropEventArgs . AcceptDrop = true ;
}
}
base . OnDragOver ( fileDropEventArgs ) ;
}
public override void OnDragDrop ( FileDropEventArgs fileDropEventArgs )
{
foreach ( string droppedFileName in fileDropEventArgs . DroppedFiles )
{
string extension = Path . GetExtension ( droppedFileName ) . ToUpper ( ) ;
if ( extension = = ".STL" | | extension = = ".GCODE" )
{
2014-04-16 12:01:01 -07:00
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( Path . GetFileNameWithoutExtension ( droppedFileName ) , Path . GetFullPath ( droppedFileName ) ) ) ) ;
2014-01-29 19:09:30 -08:00
}
2014-05-17 11:06:34 -07:00
else if ( extension = = ".ZIP" )
{
ProjectFileHandler project = new ProjectFileHandler ( null ) ;
List < PrintItem > partFiles = project . ImportFromProjectArchive ( droppedFileName ) ;
if ( partFiles ! = null )
{
foreach ( PrintItem part in partFiles )
{
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( part . Name , part . FileLocation ) ) ) ;
}
}
}
2014-01-29 19:09:30 -08:00
}
base . OnDragDrop ( fileDropEventArgs ) ;
}
2014-04-15 18:13:27 -07:00
void addToQueueButton_Click ( object sender , MouseEventArgs mouseEvent )
2014-01-29 19:09:30 -08:00
{
2014-04-15 18:13:27 -07:00
UiThread . RunOnIdle ( AddItemsToQueue ) ;
2014-01-29 19:09:30 -08:00
}
2014-04-15 18:13:27 -07:00
void AddItemsToQueue ( object state )
2014-01-29 19:09:30 -08:00
{
2014-08-27 14:15:41 -07:00
string documentsPath = System . Environment . GetFolderPath ( System . Environment . SpecialFolder . Personal ) ;
OpenFileDialogParams openParams = new OpenFileDialogParams ( "Select an STL file, Select a GCODE file|*.stl;*.gcode;*.zip" , multiSelect : true , initialDirectory : documentsPath ) ;
2014-01-29 19:09:30 -08:00
openParams . ActionButtonLabel = "Add to Queue" ;
openParams . Title = "MatterControl: Select A File" ;
FileDialog . OpenFileDialog ( ref openParams ) ;
if ( openParams . FileNames ! = null )
{
2014-05-17 11:06:34 -07:00
foreach ( string fileNameToLoad in openParams . FileNames )
2014-01-29 19:09:30 -08:00
{
2014-05-17 11:06:34 -07:00
if ( Path . GetExtension ( fileNameToLoad ) . ToUpper ( ) = = ".ZIP" )
{
ProjectFileHandler project = new ProjectFileHandler ( null ) ;
List < PrintItem > partFiles = project . ImportFromProjectArchive ( fileNameToLoad ) ;
if ( partFiles ! = null )
{
foreach ( PrintItem part in partFiles )
{
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( part . Name , part . FileLocation ) ) ) ;
}
}
}
else
{
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( Path . GetFileNameWithoutExtension ( fileNameToLoad ) , Path . GetFullPath ( fileNameToLoad ) ) ) ) ;
}
2014-01-29 19:09:30 -08:00
}
}
}
}
}