2017-07-27 14:25:21 -07:00
/ *
Copyright ( c ) 2017 , Lars Brubaker , John Lewin
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 MatterHackers.Agg ;
2017-08-20 02:34:39 -07:00
using MatterHackers.Agg.Platform ;
2017-07-27 14:25:21 -07:00
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.ActionBar ;
using MatterHackers.MatterControl.PrinterCommunication ;
2017-08-17 05:58:59 -07:00
using MatterHackers.MatterControl.PrintQueue ;
2017-08-07 11:47:21 -07:00
using MatterHackers.MatterControl.SettingsManagement ;
using MatterHackers.MatterControl.SlicerConfiguration ;
2017-07-27 14:25:21 -07:00
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class PlusTabPage : FlowLayoutWidget
{
2017-08-17 05:58:59 -07:00
private TabControl tabControl ;
public PlusTabPage ( TabControl tabControl , PrinterConfig printer , ThemeConfig theme , PrintItemWrapper printItem )
2017-08-04 15:42:23 -07:00
: base ( FlowDirection . TopToBottom )
2017-07-27 14:25:21 -07:00
{
2017-08-07 15:47:27 -07:00
this . HAnchor = HAnchor . Stretch ;
this . VAnchor = VAnchor . Stretch ;
2017-08-07 14:18:02 -07:00
this . Padding = 15 ;
2017-07-27 14:25:21 -07:00
2017-08-17 05:58:59 -07:00
this . tabControl = tabControl ;
2017-08-07 11:47:21 -07:00
BorderDouble buttonSpacing = 3 ;
2017-07-27 14:25:21 -07:00
// put in the add new design stuff
2017-08-04 15:42:23 -07:00
var createItemsSection = CreateSection ( "Create New" . Localize ( ) + ":" ) ;
2017-07-27 14:25:21 -07:00
2017-08-07 11:47:21 -07:00
var createPart = theme . ButtonFactory . Generate ( "Create Part" . Localize ( ) ) ;
createPart . Margin = buttonSpacing ;
2017-08-07 15:47:27 -07:00
createPart . HAnchor = HAnchor . Left ;
2017-08-04 15:42:23 -07:00
createItemsSection . AddChild ( createPart ) ;
2017-08-17 05:58:59 -07:00
createPart . Click + = ( s , e ) = >
{
2017-09-15 09:23:53 -07:00
CreatePartTab ( tabControl , printer , theme , printItem ) ;
2017-08-17 05:58:59 -07:00
} ;
2017-07-27 14:25:21 -07:00
2017-08-07 11:47:21 -07:00
var createPrinter = theme . ButtonFactory . Generate ( "Create Printer" . Localize ( ) ) ;
2017-08-30 13:41:49 -07:00
createPrinter . Name = "Create Printer" ;
2017-08-07 11:47:21 -07:00
createPrinter . Margin = buttonSpacing ;
2017-08-07 15:47:27 -07:00
createPrinter . HAnchor = HAnchor . Left ;
2017-07-27 14:25:21 -07:00
createPrinter . Click + = ( s , e ) = >
{
if ( PrinterConnection . Instance . PrinterIsPrinting
| | PrinterConnection . Instance . PrinterIsPaused )
{
UiThread . RunOnIdle ( ( ) = >
StyledMessageBox . ShowMessageBox ( null , "Please wait until the print has finished and try again." . Localize ( ) , "Can't add printers while printing" . Localize ( ) )
) ;
}
else
{
UiThread . RunOnIdle ( ( ) = >
{
WizardWindow . ShowPrinterSetup ( true ) ;
} ) ;
}
} ;
2017-08-04 15:42:23 -07:00
createItemsSection . AddChild ( createPrinter ) ;
var existingPrinterSection = CreateSection ( "Open Existing" . Localize ( ) + ":" ) ;
2017-09-02 08:36:54 -07:00
var printerSelector = new PrinterSelector ( )
2017-08-04 15:42:23 -07:00
{
Margin = new BorderDouble ( left : 15 )
} ;
existingPrinterSection . AddChild ( printerSelector ) ;
var otherItemsSection = CreateSection ( "Other" . Localize ( ) + ":" ) ;
2017-08-07 11:47:21 -07:00
var redeemDesignCode = theme . ButtonFactory . Generate ( "Redeem Design Code" . Localize ( ) ) ;
2017-08-30 16:43:58 -07:00
redeemDesignCode . Name = "Redeem Design Code Button" ;
2017-08-07 11:47:21 -07:00
redeemDesignCode . Margin = buttonSpacing ;
2017-08-07 15:47:27 -07:00
redeemDesignCode . HAnchor = HAnchor . Left ;
2017-08-04 15:42:23 -07:00
redeemDesignCode . Click + = ( s , e ) = >
{
// Implementation already does RunOnIdle
ApplicationController . Instance . RedeemDesignCode ? . Invoke ( ) ;
} ;
otherItemsSection . AddChild ( redeemDesignCode ) ;
2017-08-07 11:47:21 -07:00
var redeemShareCode = theme . ButtonFactory . Generate ( "Enter Share Code" . Localize ( ) ) ;
2017-08-30 16:43:58 -07:00
redeemShareCode . Name = "Enter Share Code Button" ;
2017-08-07 11:47:21 -07:00
redeemShareCode . Margin = buttonSpacing ;
2017-08-07 15:47:27 -07:00
redeemShareCode . HAnchor = HAnchor . Left ;
2017-08-04 15:42:23 -07:00
redeemShareCode . Click + = ( s , e ) = >
{
// Implementation already does RunOnIdle
ApplicationController . Instance . EnterShareCode ? . Invoke ( ) ;
} ;
otherItemsSection . AddChild ( redeemShareCode ) ;
2017-07-27 14:25:21 -07:00
2017-08-07 11:47:21 -07:00
var importButton = theme . ButtonFactory . Generate ( "Import" . Localize ( ) ) ;
2017-08-07 14:18:02 -07:00
importButton . Margin = buttonSpacing ;
2017-08-07 16:11:26 -07:00
importButton . HAnchor = HAnchor . Left ;
2017-07-28 14:05:02 -07:00
importButton . Click + = ( s , e ) = >
{
2017-08-23 15:51:29 -07:00
UiThread . RunOnIdle ( ( ) = > WizardWindow . Show < ImportSettingsPage > ( ) ) ;
2017-07-28 14:05:02 -07:00
} ;
2017-08-04 15:42:23 -07:00
otherItemsSection . AddChild ( importButton ) ;
2017-08-07 11:47:21 -07:00
if ( OemSettings . Instance . ShowShopButton )
{
2017-08-20 02:34:39 -07:00
var shopButton = theme . ButtonFactory . Generate ( "Buy Materials" . Localize ( ) , AggContext . StaticData . LoadIcon ( "icon_shopping_cart_32x32.png" , 24 , 24 ) ) ;
2017-08-07 11:47:21 -07:00
shopButton . ToolTipText = "Shop online for printing materials" . Localize ( ) ;
shopButton . Name = "Buy Materials Button" ;
2017-08-07 16:11:26 -07:00
shopButton . HAnchor = HAnchor . Left ;
2017-08-07 11:47:21 -07:00
shopButton . Margin = buttonSpacing ;
shopButton . Click + = ( sender , e ) = >
{
double activeFilamentDiameter = 0 ;
if ( ActiveSliceSettings . Instance . PrinterSelected )
{
activeFilamentDiameter = 3 ;
if ( ActiveSliceSettings . Instance . GetValue < double > ( SettingsKey . filament_diameter ) < 2 )
{
activeFilamentDiameter = 1.75 ;
}
}
MatterControlApplication . Instance . LaunchBrowser ( "http://www.matterhackers.com/mc/store/redirect?d={0}&clk=mcs&a={1}" . FormatWith ( activeFilamentDiameter , OemSettings . Instance . AffiliateCode ) ) ;
} ;
otherItemsSection . AddChild ( shopButton ) ;
}
2017-08-04 15:42:23 -07:00
}
2017-07-28 14:05:02 -07:00
2017-09-15 09:23:53 -07:00
internal static void CreatePartTab ( TabControl tabControl , PrinterConfig printer , ThemeConfig theme , PrintItemWrapper printItem , int tabIndex = 1 )
{
var partTab = new PrinterTab (
"New Part" ,
"newPart" + tabControl . TabCount ,
new PrinterTabBase ( printer , theme , printItem , "xxxxx" ) ,
"https://i.imgur.com/nkeYgfU.png" ) ;
theme . SetPrinterTabStyles ( partTab ) ;
var margin = partTab . Margin ;
partTab . Margin = new BorderDouble ( 1 , margin . Bottom , 1 , margin . Top ) ;
tabControl . AddTab ( partTab , tabPosition : tabIndex ) ;
tabControl . SelectedTabIndex = tabIndex ;
}
2017-08-04 15:42:23 -07:00
private FlowLayoutWidget CreateSection ( string headingText )
{
// Add heading
2017-08-07 14:18:02 -07:00
this . AddChild ( new TextWidget ( headingText , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
2017-08-07 16:11:26 -07:00
HAnchor = HAnchor . Left
2017-08-07 14:18:02 -07:00
} ) ;
2017-07-27 14:25:21 -07:00
2017-08-04 15:42:23 -07:00
// Add container
var container = new FlowLayoutWidget ( FlowDirection . TopToBottom )
2017-07-27 14:25:21 -07:00
{
2017-08-07 15:47:27 -07:00
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Fit ,
2017-08-07 11:47:21 -07:00
Margin = new BorderDouble ( 10 , 10 , 10 , 8 ) ,
2017-07-27 14:25:21 -07:00
} ;
2017-08-04 15:42:23 -07:00
this . AddChild ( container ) ;
return container ;
2017-07-27 14:25:21 -07:00
}
}
}