2014-10-16 17:52:21 -07:00
/ *
Copyright ( c ) 2014 , Lars Brubaker
All rights reserved .
Redistribution and use in source and binary forms , with or without
2015-04-08 15:20:10 -07:00
modification , are permitted provided that the following conditions are met :
2014-10-16 17:52:21 -07:00
1. Redistributions of source code must retain the above copyright notice , this
2015-04-08 15:20:10 -07:00
list of conditions and the following disclaimer .
2014-10-16 17:52:21 -07:00
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
2015-04-08 15:20:10 -07:00
and / or other materials provided with the distribution .
2014-10-16 17:52:21 -07:00
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
2015-04-08 15:20:10 -07:00
of the authors and should not be interpreted as representing official policies ,
2014-10-16 17:52:21 -07:00
either expressed or implied , of the FreeBSD Project .
* /
2014-10-24 17:27:38 -07:00
using MatterHackers.Agg.UI ;
2014-10-16 17:52:21 -07:00
using MatterHackers.Localizations ;
using MatterHackers.PolygonMesh ;
2015-04-08 15:20:10 -07:00
using System.ComponentModel ;
using System.Globalization ;
using System.Threading ;
2015-07-21 08:10:05 -07:00
using System.Threading.Tasks ;
2016-02-28 11:54:42 -08:00
using System ;
2014-10-16 17:52:21 -07:00
namespace MatterHackers.MatterControl.PartPreviewWindow
{
2015-04-08 15:20:10 -07:00
public partial class View3DWidget
{
2016-01-20 10:12:01 -08:00
private static string PartsNotPrintableMessage = "Parts are not on the bed or outside the print area.\n\nWould you like to center them on the bed?" . Localize ( ) ;
private static string PartsNotPrintableTitle = "Parts not in print area" . Localize ( ) ;
2015-07-21 08:10:05 -07:00
private void CreateSelectionData ( )
2015-04-08 15:20:10 -07:00
{
2016-03-24 06:52:20 -07:00
processingProgressControl . ProcessType = "Preparing Meshes" . Localize ( ) + ":" ;
2015-04-08 15:20:10 -07:00
Thread . CurrentThread . CurrentCulture = CultureInfo . InvariantCulture ;
PushMeshGroupDataToAsynchLists ( TraceInfoOpperation . DONT_COPY ) ;
2016-02-19 11:27:55 -08:00
asyncPlatingDatas . Clear ( ) ;
double ratioPerMeshGroup = 1.0 / asyncMeshGroups . Count ;
2015-04-08 15:20:10 -07:00
double currentRatioDone = 0 ;
2016-02-19 11:27:55 -08:00
for ( int i = 0 ; i < asyncMeshGroups . Count ; i + + )
2015-04-08 15:20:10 -07:00
{
2016-03-24 06:52:20 -07:00
asyncPlatingDatas . Add ( new PlatingMeshGroupData ( ) ) ;
2015-04-08 15:20:10 -07:00
// create the selection info
2016-02-19 11:27:55 -08:00
PlatingHelper . CreateITraceableForMeshGroup ( asyncPlatingDatas , asyncMeshGroups , i , ( double progress0To1 , string processingState , out bool continueProcessing ) = >
2015-04-08 15:20:10 -07:00
{
2015-07-02 11:23:44 -07:00
ReportProgressChanged ( progress0To1 , processingState , out continueProcessing ) ;
2015-04-08 15:20:10 -07:00
} ) ;
currentRatioDone + = ratioPerMeshGroup ;
}
bool continueProcessing2 ;
2015-07-02 11:23:44 -07:00
ReportProgressChanged ( 1 , "Creating GL Data" , out continueProcessing2 ) ;
2016-02-19 11:27:55 -08:00
meshViewerWidget . CreateGlDataForMeshes ( asyncMeshGroups ) ;
2015-04-08 15:20:10 -07:00
}
2015-07-21 08:10:05 -07:00
private async void EnterEditAndCreateSelectionData ( )
2015-05-30 12:48:16 -07:00
{
if ( enterEditButtonsContainer . Visible = = true )
{
enterEditButtonsContainer . Visible = false ;
}
2015-05-29 15:13:56 -07:00
viewControls3D . ActiveButton = ViewControls3DButtons . PartSelect ;
2015-05-30 12:48:16 -07:00
if ( MeshGroups . Count > 0 )
{
processingProgressControl . Visible = true ;
LockEditControls ( ) ;
viewIsInEditModePreLock = true ;
2015-07-21 11:10:01 -07:00
await Task . Run ( ( System . Action ) CreateSelectionData ) ;
2015-07-21 08:10:05 -07:00
2016-04-25 12:51:29 -07:00
if ( HasBeenClosed )
2015-07-21 08:10:05 -07:00
{
return ;
}
// remove the original mesh and replace it with these new meshes
PullMeshGroupDataFromAsynchLists ( ) ;
SelectedMeshGroupIndex = 0 ;
buttonRightPanel . Visible = true ;
UnlockEditControls ( ) ;
2015-05-29 15:13:56 -07:00
viewControls3D . ActiveButton = ViewControls3DButtons . PartSelect ;
2015-05-30 12:48:16 -07:00
2015-07-21 08:10:05 -07:00
Invalidate ( ) ;
2015-05-30 12:48:16 -07:00
2015-07-21 08:10:05 -07:00
if ( DoAddFileAfterCreatingEditData )
{
FileDialog . OpenFileDialog (
new OpenFileDialogParams ( ApplicationSettings . OpenDesignFileParams , multiSelect : true ) ,
( openParams ) = >
{
LoadAndAddPartsToPlate ( openParams . FileNames ) ;
} ) ;
DoAddFileAfterCreatingEditData = false ;
}
else if ( pendingPartsToLoad . Count > 0 )
{
LoadAndAddPartsToPlate ( pendingPartsToLoad . ToArray ( ) ) ;
2016-01-07 12:41:36 -08:00
pendingPartsToLoad . Clear ( ) ;
2015-07-21 08:10:05 -07:00
}
2015-08-06 15:20:04 -07:00
else
{
if ( ! PartsAreInPrintVolume ( ) )
{
UiThread . RunOnIdle ( ( ) = >
{
StyledMessageBox . ShowMessageBox ( ( doCentering ) = >
{
if ( doCentering )
{
AutoArrangePartsInBackground ( ) ;
}
2016-01-20 10:12:01 -08:00
} , PartsNotPrintableMessage , PartsNotPrintableTitle , StyledMessageBox . MessageType . YES_NO , "Center on Bed" . Localize ( ) , "Cancel" . Localize ( ) ) ;
2015-08-06 15:20:04 -07:00
} ) ;
}
}
2015-05-30 12:48:16 -07:00
}
}
2015-04-08 15:20:10 -07:00
}
}