2014-01-29 19:09:30 -08:00
/ *
2018-04-03 08:36:21 -07:00
Copyright ( c ) 2018 , Lars Brubaker , John Lewin
2014-01-29 19:09:30 -08:00
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-01-29 19:09:30 -08: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-01-29 19:09:30 -08: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-01-29 19:09:30 -08: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-01-29 19:09:30 -08:00
either expressed or implied , of the FreeBSD Project .
* /
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Linq ;
using System.Text.RegularExpressions ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg ;
2017-07-10 14:00:27 -07:00
using MatterHackers.Agg.OpenGlGui ;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg.UI ;
2017-03-15 16:17:06 -07:00
using MatterHackers.DataConverters3D ;
2014-10-15 14:11:14 -07:00
using MatterHackers.Localizations ;
2014-10-23 14:40:12 -07:00
using MatterHackers.MatterControl.CustomWidgets ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using MatterHackers.MatterControl.Library ;
2017-09-19 19:59:55 -07:00
using MatterHackers.MatterControl.PrintLibrary ;
2014-01-29 19:09:30 -08:00
using MatterHackers.MeshVisualizer ;
2014-04-15 18:13:27 -07:00
using MatterHackers.PolygonMesh ;
2014-01-29 19:09:30 -08:00
using MatterHackers.RayTracer ;
2014-04-15 18:13:27 -07:00
using MatterHackers.RenderOpenGl ;
using MatterHackers.VectorMath ;
2018-04-03 08:36:21 -07:00
using MatterHackers.VectorMath.TrackBall ;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl.PartPreviewWindow
{
2018-02-07 18:01:49 -08:00
public class View3DWidget : GuiWidget
2015-04-08 15:20:10 -07:00
{
2017-04-05 19:03:04 -07:00
private bool deferEditorTillMouseUp = false ;
2016-02-26 21:54:15 -08:00
public readonly int EditButtonHeight = 44 ;
2017-03-15 16:17:06 -07:00
2015-05-30 12:48:16 -07:00
private bool hasDrawn = false ;
2017-03-15 16:17:06 -07:00
2017-10-31 11:43:25 -07:00
private Color [ ] SelectionColors = new Color [ ] { new Color ( 131 , 4 , 66 ) , new Color ( 227 , 31 , 61 ) , new Color ( 255 , 148 , 1 ) , new Color ( 247 , 224 , 23 ) , new Color ( 143 , 212 , 1 ) } ;
2015-05-30 12:48:16 -07:00
private Stopwatch timeSinceLastSpin = new Stopwatch ( ) ;
private Stopwatch timeSinceReported = new Stopwatch ( ) ;
private Matrix4X4 transformOnMouseDown = Matrix4X4 . Identity ;
2015-04-08 15:20:10 -07:00
2017-06-19 09:17:57 -07:00
private ThemeConfig theme ;
2016-10-06 10:59:51 -07:00
2017-09-05 18:02:19 -07:00
public Vector3 BedCenter
{
get
{
2017-09-15 16:49:21 -07:00
return new Vector3 ( sceneContext . BedCenter ) ;
2017-09-05 18:02:19 -07:00
}
}
2017-09-16 01:28:05 -07:00
private WorldView World = > sceneContext . World ;
2017-07-10 14:00:27 -07:00
2018-02-17 09:17:40 -08:00
private TrackballTumbleWidget trackballTumbleWidget ;
2017-07-10 14:00:27 -07:00
2017-07-11 08:10:57 -07:00
public InteractionLayer InteractionLayer { get ; }
2018-01-30 11:50:22 -08:00
public BedConfig sceneContext ;
2017-09-15 16:49:21 -07:00
2017-10-16 17:09:00 -07:00
private PrinterConfig printer ;
2017-10-30 08:53:53 -07:00
private PrinterTabPage printerTabPage ;
2017-10-16 17:09:00 -07:00
2017-11-07 14:55:45 -08:00
public View3DWidget ( PrinterConfig printer , BedConfig sceneContext , AutoRotate autoRotate , ViewControls3D viewControls3D , ThemeConfig theme , PartTabPage printerTabBase , MeshViewerWidget . EditorType editorType = MeshViewerWidget . EditorType . Part )
2015-05-30 12:48:16 -07:00
{
2017-09-15 16:49:21 -07:00
this . sceneContext = sceneContext ;
2017-10-30 08:53:53 -07:00
this . printerTabPage = printerTabBase as PrinterTabPage ;
2017-10-16 17:09:00 -07:00
this . printer = printer ;
2017-07-10 14:00:27 -07:00
2018-02-05 17:56:17 -08:00
this . InteractionLayer = new InteractionLayer ( this . World , scene . UndoBuffer , scene )
2017-07-11 08:10:57 -07:00
{
Name = "InteractionLayer" ,
} ;
this . InteractionLayer . AnchorAll ( ) ;
2017-07-05 14:34:38 -07:00
this . viewControls3D = viewControls3D ;
2017-06-19 09:17:57 -07:00
this . theme = theme ;
2016-03-01 11:25:15 -08:00
this . Name = "View3DWidget" ;
2018-01-16 22:55:28 -08:00
this . BackgroundColor = theme . ActiveTabColor ;
2018-01-16 21:48:20 -08:00
this . Border = new BorderDouble ( top : 1 ) ;
this . BorderColor = theme . MinimalShade ;
2018-02-17 09:06:49 -08:00
this . HAnchor = HAnchor . Stretch ; // HAnchor.MaxFitOrStretch,
this . VAnchor = VAnchor . Stretch ; // VAnchor.MaxFitOrStretch
2017-05-24 14:19:02 -07:00
2017-08-18 08:34:05 -07:00
autoRotating = allowAutoRotate ;
allowAutoRotate = ( autoRotate = = AutoRotate . Enabled ) ;
2017-05-26 13:46:12 -07:00
viewControls3D . TransformStateChanged + = ViewControls3D_TransformStateChanged ;
2017-08-18 08:34:05 -07:00
// MeshViewer
2017-09-15 16:49:21 -07:00
meshViewerWidget = new MeshViewerWidget ( sceneContext , this . InteractionLayer , editorType : editorType ) ;
2017-07-05 15:37:32 -07:00
meshViewerWidget . AnchorAll ( ) ;
2018-02-17 09:06:49 -08:00
this . AddChild ( meshViewerWidget ) ;
2015-04-08 15:20:10 -07:00
2018-02-20 15:23:55 -08:00
trackballTumbleWidget = new TrackballTumbleWidget ( sceneContext . World , meshViewerWidget )
{
2018-04-03 08:36:21 -07:00
TransformState = TrackBallTransformType . Rotation
2018-02-20 15:23:55 -08:00
} ;
trackballTumbleWidget . AnchorAll ( ) ;
2017-08-18 08:34:05 -07:00
// TumbleWidget
2018-02-17 09:17:40 -08:00
this . InteractionLayer . AddChild ( trackballTumbleWidget ) ;
2017-08-18 12:40:49 -07:00
this . InteractionLayer . SetRenderTarget ( this . meshViewerWidget ) ;
2017-07-10 14:00:27 -07:00
2018-02-17 10:42:58 -08:00
// Add splitter support with the InteractionLayer on the left and resize containers on the right
var splitContainer = new FlowLayoutWidget ( )
{
Name = "SplitContainer" ,
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Stretch ,
} ;
splitContainer . AddChild ( this . InteractionLayer ) ;
this . AddChild ( splitContainer ) ;
2015-04-08 15:20:10 -07:00
2018-02-05 17:56:17 -08:00
scene . SelectionChanged + = Scene_SelectionChanged ;
2015-04-08 15:20:10 -07:00
2017-10-25 17:04:55 -07:00
// if the scene is invalidated invalidate the widget
2018-02-05 17:56:17 -08:00
scene . Invalidated + = ( s , e ) = > Invalidate ( ) ;
2017-10-25 17:04:55 -07:00
2015-04-08 15:20:10 -07:00
this . AnchorAll ( ) ;
2014-01-29 19:09:30 -08:00
2018-04-03 08:36:21 -07:00
trackballTumbleWidget . TransformState = TrackBallTransformType . Rotation ;
2014-03-01 23:27:34 -08:00
2018-02-05 17:56:17 -08:00
selectedObjectPanel = new SelectedObjectPanel ( this , scene , theme , printer )
2017-03-15 16:17:06 -07:00
{
2017-11-27 16:41:52 -08:00
BackgroundColor = theme . InteractionLayerOverlayColor ,
2018-01-05 11:45:11 -08:00
VAnchor = VAnchor . Stretch ,
2017-03-15 16:17:06 -07:00
} ;
2017-10-19 15:29:01 -07:00
2017-10-20 07:26:14 -07:00
selectedObjectContainer = new ResizeContainer ( selectedObjectPanel )
2017-10-19 15:29:01 -07:00
{
2018-01-08 23:53:39 -08:00
Width = printer ? . ViewState . SelectedObjectPanelWidth ? ? 200 ,
2018-01-05 11:45:11 -08:00
VAnchor = VAnchor . Stretch ,
2018-02-17 10:42:58 -08:00
HAnchor = HAnchor . Absolute ,
2017-11-27 16:41:52 -08:00
SpliterBarColor = theme . SplitterBackground ,
SplitterWidth = theme . SplitterWidth ,
2017-10-20 07:26:14 -07:00
Visible = false ,
2017-10-19 15:29:01 -07:00
} ;
2017-10-20 07:26:14 -07:00
selectedObjectContainer . AddChild ( selectedObjectPanel ) ;
2018-02-17 10:42:58 -08:00
splitContainer . AddChild ( selectedObjectContainer ) ;
2017-03-15 16:17:06 -07:00
2017-11-29 16:40:46 -08:00
this . InteractionLayer . AddChild ( new TumbleCubeControl ( this . InteractionLayer )
{
Margin = new BorderDouble ( 50 , 0 , 0 , 50 ) ,
VAnchor = VAnchor . Top ,
HAnchor = HAnchor . Left ,
} ) ;
2015-04-08 15:20:10 -07:00
UiThread . RunOnIdle ( AutoSpin ) ;
2014-05-27 09:16:35 -07:00
2017-07-12 21:57:30 -07:00
var interactionVolumes = this . InteractionLayer . InteractionVolumes ;
interactionVolumes . Add ( new MoveInZControl ( this . InteractionLayer ) ) ;
interactionVolumes . Add ( new SelectionShadow ( this . InteractionLayer ) ) ;
interactionVolumes . Add ( new SnappingIndicators ( this . InteractionLayer , this . CurrentSelectInfo ) ) ;
2015-04-08 15:20:10 -07:00
2017-07-20 00:50:50 -07:00
var interactionVolumePlugins = PluginFinder . CreateInstancesOf < InteractionVolumePlugin > ( ) ;
foreach ( InteractionVolumePlugin plugin in interactionVolumePlugins )
2016-02-21 13:18:29 -08:00
{
2017-07-12 21:57:30 -07:00
interactionVolumes . Add ( plugin . CreateInteractionVolume ( this . InteractionLayer ) ) ;
2016-02-21 13:18:29 -08:00
}
2017-05-31 17:47:12 -07:00
meshViewerWidget . AfterDraw + = AfterDraw3DContent ;
2017-05-29 16:56:56 -07:00
2018-02-05 17:56:17 -08:00
scene . SelectFirstChild ( ) ;
2017-09-15 23:17:03 -07:00
2018-02-05 14:25:52 -08:00
viewControls3D . ActiveButton = ViewControls3DButtons . PartSelect ;
2018-01-14 16:39:30 -08:00
// Make sure the render mode is set correctly
string renderTypeString = UserSettings . Instance . get ( UserSettingsKey . defaultRenderSetting ) ;
if ( renderTypeString = = null )
{
renderTypeString = ( UserSettings . Instance . IsTouchScreen ) ? "Shaded" : "Outlines" ;
UserSettings . Instance . set ( UserSettingsKey . defaultRenderSetting , renderTypeString ) ;
}
RenderTypes renderType ;
bool canParse = Enum . TryParse ( renderTypeString , out renderType ) ;
if ( canParse )
{
meshViewerWidget . RenderType = renderType ;
}
2017-09-20 14:14:11 -07:00
this . InteractionLayer . DrawGlOpaqueContent + = Draw_GlOpaqueContent ;
2017-11-29 07:35:37 -08:00
this . sceneContext . SceneLoaded + = SceneContext_SceneLoaded ;
}
private void SceneContext_SceneLoaded ( object sender , EventArgs e )
{
2017-11-29 17:47:22 -08:00
if ( this . printerTabPage ? . printerActionsBar ? . sliceButton is GuiWidget sliceButton )
2017-11-29 13:50:25 -08:00
{
sliceButton . Enabled = sceneContext . EditableScene ;
}
2018-02-16 18:48:41 -08:00
if ( this . printerTabPage ? . printerActionsBar ? . modelViewButton is GuiWidget button )
2018-02-07 18:43:09 -08:00
{
button . Enabled = sceneContext . EditableScene ;
}
2017-11-29 07:35:37 -08:00
this . Invalidate ( ) ;
2017-03-15 16:17:06 -07:00
}
2017-05-26 13:46:12 -07:00
private void ViewControls3D_TransformStateChanged ( object sender , TransformStateChangedEventArgs e )
{
switch ( e . TransformMode )
{
case ViewControls3DButtons . Rotate :
2018-04-03 08:36:21 -07:00
trackballTumbleWidget . TransformState = TrackBallTransformType . Rotation ;
2017-05-26 13:46:12 -07:00
break ;
case ViewControls3DButtons . Translate :
2018-04-03 08:36:21 -07:00
trackballTumbleWidget . TransformState = TrackBallTransformType . Translation ;
2017-05-26 13:46:12 -07:00
break ;
case ViewControls3DButtons . Scale :
2018-04-03 08:36:21 -07:00
trackballTumbleWidget . TransformState = TrackBallTransformType . Scale ;
2017-05-26 13:46:12 -07:00
break ;
case ViewControls3DButtons . PartSelect :
2018-04-03 08:36:21 -07:00
trackballTumbleWidget . TransformState = TrackBallTransformType . None ;
2017-05-26 13:46:12 -07:00
break ;
}
}
2017-03-15 16:17:06 -07:00
public void SelectAll ( )
{
2018-02-05 17:56:17 -08:00
scene . ClearSelection ( ) ;
foreach ( var child in scene . Children . ToList ( ) )
2017-03-15 16:17:06 -07:00
{
2018-02-05 17:56:17 -08:00
scene . AddToSelection ( child ) ;
2017-03-15 16:17:06 -07:00
}
}
2017-07-01 08:21:29 -07:00
2017-09-20 14:14:11 -07:00
private void Draw_GlOpaqueContent ( object sender , DrawEventArgs e )
2016-03-25 17:32:05 -07:00
{
2017-09-11 10:17:09 -07:00
if ( CurrentSelectInfo . DownOnPart
2018-04-03 08:36:21 -07:00
& & trackballTumbleWidget . TransformState = = TrackBallTransformType . None
2017-09-11 10:17:09 -07:00
& & Keyboard . IsKeyDown ( Keys . ShiftKey ) )
{
// draw marks on the bed to show that the part is constrained to x and y
2018-02-05 17:56:17 -08:00
AxisAlignedBoundingBox selectedBounds = scene . SelectedItem . GetAxisAlignedBoundingBox ( Matrix4X4 . Identity ) ;
2017-09-11 10:17:09 -07:00
var drawCenter = CurrentSelectInfo . PlaneDownHitPos ;
2017-10-31 11:43:25 -07:00
var drawColor = new Color ( Color . Red , 20 ) ;
2017-09-11 10:17:09 -07:00
bool zBuffer = false ;
for ( int i = 0 ; i < 2 ; i + + )
{
GLHelper . Render3DLine ( World ,
drawCenter - new Vector3 ( - 50 , 0 , 0 ) ,
drawCenter - new Vector3 ( 50 , 0 , 0 ) , drawColor , zBuffer , 2 ) ;
GLHelper . Render3DLine ( World ,
drawCenter - new Vector3 ( 0 , - 50 , 0 ) ,
drawCenter - new Vector3 ( 0 , 50 , 0 ) , drawColor , zBuffer , 2 ) ;
2017-10-31 11:43:25 -07:00
drawColor = Color . Black ;
2017-10-31 12:51:16 -07:00
drawCenter . Z = 0 ;
2017-09-11 10:17:09 -07:00
zBuffer = true ;
}
}
2018-03-14 15:23:32 -07:00
// Render 3D GCode if applicable
if ( sceneContext . LoadedGCode ! = null
& & sceneContext . GCodeRenderer ! = null
& & printerTabPage ? . printer . ViewState . ViewMode = = PartViewMode . Layers3D )
2017-07-10 14:00:27 -07:00
{
2018-03-14 15:25:39 -07:00
sceneContext . RenderGCode3D ( e ) ;
2017-07-10 14:00:27 -07:00
}
2018-03-14 15:23:32 -07:00
// This shows the BVH as rects around the scene items
//Scene?.TraceData().RenderBvhRecursive(0, 3);
2015-12-22 15:26:51 -08:00
}
2016-02-27 13:56:57 -08:00
public override void OnKeyDown ( KeyEventArgs keyEvent )
{
2017-06-29 11:42:36 -07:00
// this must be called first to ensure we get the correct Handled state
2017-06-29 11:35:06 -07:00
base . OnKeyDown ( keyEvent ) ;
2016-02-27 13:56:57 -08:00
2017-06-29 11:35:06 -07:00
if ( ! keyEvent . Handled )
2017-06-07 15:56:02 -07:00
{
switch ( keyEvent . KeyCode )
{
case Keys . A :
if ( keyEvent . Control )
{
SelectAll ( ) ;
keyEvent . Handled = true ;
keyEvent . SuppressKeyPress = true ;
}
break ;
2018-02-06 13:31:25 -08:00
case Keys . C :
2017-06-07 15:56:02 -07:00
if ( keyEvent . Control )
{
2018-02-06 13:31:25 -08:00
scene . Copy ( ) ;
keyEvent . Handled = true ;
keyEvent . SuppressKeyPress = true ;
}
break ;
case Keys . S :
if ( keyEvent . Control )
{
2018-02-20 18:27:52 -08:00
ApplicationController . Instance . Tasks . Execute ( "Saving" . Localize ( ) , printer . Bed . SaveChanges ) ;
2018-02-06 13:31:25 -08:00
keyEvent . Handled = true ;
keyEvent . SuppressKeyPress = true ;
}
break ;
case Keys . V :
if ( keyEvent . Control )
{
scene . Paste ( ) ;
keyEvent . Handled = true ;
keyEvent . SuppressKeyPress = true ;
}
break ;
case Keys . X :
if ( keyEvent . Control )
{
scene . Cut ( ) ;
2017-06-07 15:56:02 -07:00
keyEvent . Handled = true ;
keyEvent . SuppressKeyPress = true ;
}
break ;
case Keys . Y :
if ( keyEvent . Control )
{
2018-02-05 17:56:17 -08:00
scene . UndoBuffer . Redo ( ) ;
2017-06-07 15:56:02 -07:00
keyEvent . Handled = true ;
keyEvent . SuppressKeyPress = true ;
}
break ;
2018-02-06 13:31:25 -08:00
case Keys . Z :
if ( keyEvent . Control )
{
scene . UndoBuffer . Undo ( ) ;
keyEvent . Handled = true ;
keyEvent . SuppressKeyPress = true ;
}
break ;
2017-06-07 15:56:02 -07:00
case Keys . Delete :
case Keys . Back :
2018-02-05 17:56:17 -08:00
scene . DeleteSelection ( ) ;
2017-06-07 15:56:02 -07:00
break ;
2016-02-27 13:56:57 -08:00
2017-06-07 15:56:02 -07:00
case Keys . Escape :
if ( CurrentSelectInfo . DownOnPart )
{
CurrentSelectInfo . DownOnPart = false ;
2016-02-27 13:56:57 -08:00
2018-02-05 17:56:17 -08:00
scene . SelectedItem . Matrix = transformOnMouseDown ;
2016-02-27 13:56:57 -08:00
2018-02-05 17:56:17 -08:00
scene . Invalidate ( ) ;
2017-06-07 15:56:02 -07:00
}
break ;
2017-07-11 17:34:22 -07:00
case Keys . Space :
2018-02-05 17:56:17 -08:00
scene . ClearSelection ( ) ;
2017-07-11 17:34:22 -07:00
break ;
2017-06-07 15:56:02 -07:00
}
2016-02-27 13:56:57 -08:00
}
}
2017-03-15 16:17:06 -07:00
public void AddUndoOperation ( IUndoRedoCommand operation )
2016-02-14 17:53:44 -08:00
{
2018-02-05 17:56:17 -08:00
scene . UndoBuffer . Add ( operation ) ;
2016-02-14 17:53:44 -08:00
}
2015-12-22 15:26:51 -08:00
public enum AutoRotate { Enabled , Disabled } ;
2015-04-15 16:39:37 -07:00
2015-05-30 12:48:16 -07:00
public bool DisplayAllValueData { get ; set ; }
2014-12-20 11:12:02 -08:00
2017-03-15 16:17:06 -07:00
public override void OnClosed ( ClosedEventArgs e )
2015-05-30 12:48:16 -07:00
{
2018-01-08 23:53:39 -08:00
if ( printer ! = null )
{
printer . ViewState . SelectedObjectPanelWidth = selectedObjectPanel . Width ;
2018-02-17 09:06:27 -08:00
printer . ViewState . GCodePanelWidth = printerTabPage . gcodeContainer . Width ;
2018-01-08 23:53:39 -08:00
}
2018-01-08 21:25:36 -08:00
2017-05-26 13:46:12 -07:00
viewControls3D . TransformStateChanged - = ViewControls3D_TransformStateChanged ;
2018-02-05 17:56:17 -08:00
scene . SelectionChanged - = Scene_SelectionChanged ;
2017-10-21 18:11:01 -07:00
this . InteractionLayer . DrawGlOpaqueContent - = Draw_GlOpaqueContent ;
2017-11-29 07:35:37 -08:00
this . sceneContext . SceneLoaded - = SceneContext_SceneLoaded ;
2017-10-16 17:09:00 -07:00
2017-07-05 15:43:58 -07:00
if ( meshViewerWidget ! = null )
{
meshViewerWidget . AfterDraw - = AfterDraw3DContent ;
}
2017-03-15 16:17:06 -07:00
base . OnClosed ( e ) ;
2015-05-30 12:48:16 -07:00
}
2017-03-15 16:17:06 -07:00
private GuiWidget topMostParent ;
private PlaneShape bedPlane = new PlaneShape ( Vector3 . UnitZ , 0 , null ) ;
2017-09-19 19:59:55 -07:00
public bool DragOperationActive { get ; private set ; }
2017-10-23 13:36:08 -07:00
public InsertionGroup DragDropObject { get ; private set ; }
2018-02-12 13:55:31 -08:00
public ILibraryAssetStream SceneReplacement { get ; private set ; }
2017-09-19 19:59:55 -07:00
2017-03-15 16:17:06 -07:00
/// <summary>
/// Provides a View3DWidget specific drag implementation
/// </summary>
/// <param name="screenSpaceMousePosition">The screen space mouse position.</param>
2017-09-19 19:59:55 -07:00
public void ExternalDragOver ( Vector2 screenSpaceMousePosition )
2015-04-08 15:20:10 -07:00
{
2017-09-19 19:59:55 -07:00
if ( this . HasBeenClosed )
2017-03-15 16:17:06 -07:00
{
2017-09-19 19:59:55 -07:00
return ;
2017-03-15 16:17:06 -07:00
}
2017-09-19 19:59:55 -07:00
// If the mouse is within the MeshViewer process the Drag move
2017-03-15 16:17:06 -07:00
var meshViewerPosition = this . meshViewerWidget . TransformToScreenSpace ( meshViewerWidget . LocalBounds ) ;
2017-09-19 19:59:55 -07:00
if ( meshViewerPosition . Contains ( screenSpaceMousePosition ) )
2015-05-30 12:48:16 -07:00
{
2017-09-19 19:59:55 -07:00
// If already started, process drag move
if ( this . DragOperationActive )
2015-05-30 12:48:16 -07:00
{
2017-09-19 19:59:55 -07:00
this . DragOver ( screenSpaceMousePosition ) ;
2017-03-15 16:17:06 -07:00
}
2017-09-19 19:59:55 -07:00
else
2017-03-15 16:17:06 -07:00
{
2017-09-19 19:59:55 -07:00
// Otherwise begin an externally started DragDropOperation hard-coded to use LibraryView->SelectedItems
this . StartDragDrop (
// Project from ListViewItem to ILibraryItem
ApplicationController . Instance . Library . ActiveViewWidget . SelectedItems . Select ( l = > l . Model ) ,
screenSpaceMousePosition ) ;
2015-05-30 12:48:16 -07:00
}
}
2017-09-19 19:59:55 -07:00
}
2017-03-15 16:17:06 -07:00
2017-09-19 19:59:55 -07:00
private void DragOver ( Vector2 screenSpaceMousePosition )
{
// Move the object being dragged
if ( this . DragOperationActive
& & this . DragDropObject ! = null )
{
// Move the DropDropObject the target item
2018-04-04 15:58:57 -07:00
DragSelectedObject ( localMousePosition : this . TransformFromParentSpace ( topMostParent , screenSpaceMousePosition ) ) ;
2017-09-19 19:59:55 -07:00
}
2015-04-08 15:20:10 -07:00
}
2017-12-19 14:49:48 -08:00
private void StartDragDrop ( IEnumerable < ILibraryItem > items , Vector2 screenSpaceMousePosition , bool trackSourceFiles = false )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-09-19 19:59:55 -07:00
this . DragOperationActive = true ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-11-29 14:16:21 -08:00
var firstItem = items . FirstOrDefault ( ) ;
2018-02-12 13:55:31 -08:00
if ( ( firstItem is ILibraryAssetStream contentStream
2017-11-29 13:50:25 -08:00
& & contentStream . ContentType = = "gcode" )
2017-11-29 14:16:21 -08:00
| | firstItem is SceneReplacementFileItem )
2017-11-29 13:50:25 -08:00
{
DragDropObject = null ;
2018-02-12 13:55:31 -08:00
this . SceneReplacement = firstItem as ILibraryAssetStream ;
2017-11-29 13:50:25 -08:00
// TODO: Figure out a mechanism to disable View3DWidget with dark overlay, displaying something like "Switch to xxx.gcode", make disappear on mouseLeaveBounds and dragfinish
this . InteractionLayer . BackgroundColor = new Color ( Color . Black , 200 ) ;
return ;
}
2017-09-19 19:59:55 -07:00
// Set the hitplane to the bed plane
CurrentSelectInfo . HitPlane = bedPlane ;
2017-06-05 09:27:30 -07:00
2017-11-29 07:05:48 -08:00
var insertionGroup = new InsertionGroup (
2017-09-28 15:51:31 -07:00
items ,
this ,
2018-02-05 17:56:17 -08:00
scene ,
2017-10-25 17:04:55 -07:00
sceneContext . BedCenter ,
2017-12-19 14:49:48 -08:00
( ) = > this . DragOperationActive ,
trackSourceFiles ) ;
2017-07-11 17:31:50 -07:00
2017-09-19 19:59:55 -07:00
// Find intersection position of the mouse with the bed plane
var intersectInfo = GetIntersectPosition ( screenSpaceMousePosition ) ;
if ( intersectInfo ! = null )
{
2018-01-23 16:56:15 -08:00
CalculateDragStartPosition ( insertionGroup , intersectInfo ) ;
}
else
{
CurrentSelectInfo . LastMoveDelta = Vector3 . PositiveInfinity ;
2017-09-19 19:59:55 -07:00
}
2017-09-16 01:11:44 -07:00
2017-09-19 19:59:55 -07:00
this . deferEditorTillMouseUp = true ;
2015-04-08 15:20:10 -07:00
2017-09-19 19:59:55 -07:00
// Add item to scene and select it
2018-02-05 17:56:17 -08:00
scene . Children . Modify ( list = >
2017-03-15 16:17:06 -07:00
{
2017-11-29 07:05:48 -08:00
list . Add ( insertionGroup ) ;
2017-09-19 19:59:55 -07:00
} ) ;
2018-02-05 17:56:17 -08:00
scene . SelectedItem = insertionGroup ;
2017-03-15 16:17:06 -07:00
2017-11-29 07:05:48 -08:00
this . DragDropObject = insertionGroup ;
2017-09-19 19:59:55 -07:00
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2018-01-23 16:56:15 -08:00
private void CalculateDragStartPosition ( IObject3D insertionGroup , IntersectInfo intersectInfo )
{
// Set the initial transform on the inject part to the current transform mouse position
var sourceItemBounds = insertionGroup . GetAxisAlignedBoundingBox ( Matrix4X4 . Identity ) ;
var center = sourceItemBounds . Center ;
insertionGroup . Matrix * = Matrix4X4 . CreateTranslation ( - center . X , - center . Y , - sourceItemBounds . minXYZ . Z ) ;
insertionGroup . Matrix * = Matrix4X4 . CreateTranslation ( new Vector3 ( intersectInfo . HitPosition ) ) ;
CurrentSelectInfo . PlaneDownHitPos = intersectInfo . HitPosition ;
CurrentSelectInfo . LastMoveDelta = Vector3 . Zero ;
}
2017-09-19 19:59:55 -07:00
internal void FinishDrop ( bool mouseUpInBounds )
{
if ( this . DragOperationActive )
2017-03-15 16:17:06 -07:00
{
2017-11-29 13:50:25 -08:00
this . InteractionLayer . BackgroundColor = Color . Transparent ;
2017-09-19 19:59:55 -07:00
this . DragOperationActive = false ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-09-19 19:59:55 -07:00
if ( mouseUpInBounds )
{
2017-11-29 13:50:25 -08:00
if ( this . DragDropObject = = null
& & this . SceneReplacement ! = null )
2017-10-23 13:36:08 -07:00
{
2017-11-29 13:50:25 -08:00
// Drop handler for special case of GCode or similar (change loaded scene to new context)
sceneContext . LoadContent (
new EditContext ( )
{
SourceItem = this . SceneReplacement ,
2017-11-29 14:16:21 -08:00
// No content store for GCode, otherwise PlatingHistory
ContentStore = ( this . SceneReplacement . ContentType = = "gcode" ) ? null : ApplicationController . Instance . Library . PlatingHistory
2017-11-29 13:50:25 -08:00
} ) . ConfigureAwait ( false ) ;
this . SceneReplacement = null ;
}
else if ( this . DragDropObject . ContentAcquired )
{
2018-02-07 18:43:09 -08:00
// TODO: Unclear when this is needed and how it would be enabled if the content hadn't loaded by FinishDrop (i.e. how would long running InsertionGroup operations be doing the same thing?)
//this.viewControls3D.modelViewButton.Enabled = true;
2017-11-29 13:50:25 -08:00
// Drop handler for InsertionGroup - all normal content
2017-10-23 13:36:08 -07:00
this . DragDropObject . Collapse ( ) ;
}
2017-04-05 19:03:04 -07:00
}
2017-09-19 19:59:55 -07:00
else
2017-04-05 19:03:04 -07:00
{
2018-02-05 17:56:17 -08:00
scene . Children . Modify ( list = > list . Remove ( this . DragDropObject ) ) ;
scene . ClearSelection ( ) ;
2017-09-19 19:59:55 -07:00
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-09-19 19:59:55 -07:00
this . DragDropObject = null ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-09-19 19:59:55 -07:00
this . deferEditorTillMouseUp = false ;
Scene_SelectionChanged ( null , null ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2018-02-05 17:56:17 -08:00
scene . Invalidate ( ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-09-19 19:59:55 -07:00
// Set focus to View3DWidget after drag-drop
UiThread . RunOnIdle ( this . Focus ) ;
2017-03-15 16:17:06 -07:00
2017-09-19 19:59:55 -07:00
}
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-09-19 19:59:55 -07:00
public override void OnLoad ( EventArgs args )
{
topMostParent = this . TopmostParent ( ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-09-19 19:59:55 -07:00
// Set reference on show
var dragDropData = ApplicationController . Instance . DragDropData ;
dragDropData . View3DWidget = this ;
2017-10-05 22:32:23 -07:00
dragDropData . SceneContext = sceneContext ;
2017-06-05 09:27:30 -07:00
2017-09-19 19:59:55 -07:00
base . OnLoad ( args ) ;
2017-03-15 16:17:06 -07:00
}
2016-07-24 17:26:24 -07:00
public override void OnDraw ( Graphics2D graphics2D )
{
2018-02-05 17:56:17 -08:00
var selectedItem = scene . SelectedItem ;
2017-12-21 09:42:30 -08:00
2018-02-05 17:56:17 -08:00
if ( scene . HasSelection
2017-12-21 09:42:30 -08:00
& & selectedItem ! = null )
2015-05-30 12:48:16 -07:00
{
2017-03-15 16:17:06 -07:00
2017-07-11 08:10:57 -07:00
foreach ( InteractionVolume volume in this . InteractionLayer . InteractionVolumes )
2016-02-16 08:30:13 -08:00
{
2017-03-15 16:17:06 -07:00
volume . SetPosition ( selectedItem ) ;
2016-02-16 08:30:13 -08:00
}
2015-04-08 15:20:10 -07:00
}
2014-03-20 18:20:52 -07:00
2015-05-30 12:48:16 -07:00
hasDrawn = true ;
2017-05-29 11:44:53 -07:00
2015-05-30 12:48:16 -07:00
base . OnDraw ( graphics2D ) ;
}
2015-04-08 15:20:10 -07:00
2017-05-31 17:47:12 -07:00
private void AfterDraw3DContent ( object sender , DrawEventArgs e )
2017-05-29 16:56:56 -07:00
{
2017-06-01 09:42:40 -07:00
if ( DragSelectionInProgress )
{
2017-06-05 15:44:52 -07:00
var selectionRectangle = new RectangleDouble ( DragSelectionStartPosition , DragSelectionEndPosition ) ;
2017-10-31 11:43:25 -07:00
e . graphics2D . Rectangle ( selectionRectangle , Color . Red ) ;
2017-06-05 15:44:52 -07:00
}
}
2017-06-06 10:06:38 -07:00
bool foundTriangleInSelectionBounds ;
2017-06-06 10:57:13 -07:00
private void DoRectangleSelection ( DrawEventArgs e )
2017-06-05 15:44:52 -07:00
{
2017-06-05 17:23:55 -07:00
var allResults = new List < BvhIterator > ( ) ;
2018-02-05 17:56:17 -08:00
var matchingSceneChildren = scene . Children . Where ( item = >
2017-06-05 15:44:52 -07:00
{
2017-06-06 10:06:38 -07:00
foundTriangleInSelectionBounds = false ;
2017-06-06 10:57:13 -07:00
// Filter the IPrimitive trace data finding matches as defined in InSelectionBounds
2017-06-06 10:06:38 -07:00
var filteredResults = item . TraceData ( ) . Filter ( InSelectionBounds ) ;
2017-06-05 17:23:55 -07:00
2017-06-06 10:57:13 -07:00
// Accumulate all matching BvhIterator results for debug rendering
2017-06-05 17:23:55 -07:00
allResults . AddRange ( filteredResults ) ;
2017-06-06 10:06:38 -07:00
return foundTriangleInSelectionBounds ;
2017-06-05 15:44:52 -07:00
} ) ;
2017-06-06 10:57:13 -07:00
// Apply selection
if ( matchingSceneChildren . Any ( ) )
2017-06-05 17:23:55 -07:00
{
2017-06-21 15:56:25 -07:00
// If we are actually doing the selection rather than debugging the data
if ( e = = null )
{
2018-02-05 17:56:17 -08:00
scene . ClearSelection ( ) ;
2017-06-05 17:23:55 -07:00
2017-08-22 15:55:52 -07:00
foreach ( var sceneItem in matchingSceneChildren . ToList ( ) )
2017-06-21 15:56:25 -07:00
{
2018-02-05 17:56:17 -08:00
scene . AddToSelection ( sceneItem ) ;
2017-06-21 15:56:25 -07:00
}
}
else
2017-06-05 17:23:55 -07:00
{
2018-01-02 15:25:40 -08:00
InteractionLayer . RenderBounds ( e , World , allResults ) ;
2017-06-05 17:23:55 -07:00
}
}
2017-06-06 10:06:38 -07:00
}
2017-06-05 15:44:52 -07:00
2017-06-06 10:06:38 -07:00
private bool InSelectionBounds ( BvhIterator x )
{
var selectionRectangle = new RectangleDouble ( DragSelectionStartPosition , DragSelectionEndPosition ) ;
2017-06-05 15:44:52 -07:00
2017-06-06 10:06:38 -07:00
Vector2 [ ] traceBottoms = new Vector2 [ 4 ] ;
Vector2 [ ] traceTops = new Vector2 [ 4 ] ;
2017-06-05 15:44:52 -07:00
2017-06-06 10:06:38 -07:00
if ( foundTriangleInSelectionBounds )
{
return false ;
}
if ( x . Bvh is TriangleShape tri )
{
// check if any vertex in screen rect
// calculate all the top and bottom screen positions
for ( int i = 0 ; i < 3 ; i + + )
{
Vector3 bottomStartPosition = Vector3 . Transform ( tri . GetVertex ( i ) , x . TransformToWorld ) ;
2017-07-10 14:00:27 -07:00
traceBottoms [ i ] = this . World . GetScreenPosition ( bottomStartPosition ) ;
2017-06-05 15:44:52 -07:00
}
2017-06-06 10:06:38 -07:00
for ( int i = 0 ; i < 3 ; i + + )
2017-06-05 15:44:52 -07:00
{
2017-06-06 10:06:38 -07:00
if ( selectionRectangle . ClipLine ( traceBottoms [ i ] , traceBottoms [ ( i + 1 ) % 3 ] ) )
2017-06-05 15:44:52 -07:00
{
2017-06-06 10:06:38 -07:00
foundTriangleInSelectionBounds = true ;
return true ;
2017-06-05 15:44:52 -07:00
}
}
2017-06-06 10:06:38 -07:00
}
else
{
// calculate all the top and bottom screen positions
for ( int i = 0 ; i < 4 ; i + + )
2017-06-05 15:44:52 -07:00
{
2017-06-06 10:06:38 -07:00
Vector3 bottomStartPosition = Vector3 . Transform ( x . Bvh . GetAxisAlignedBoundingBox ( ) . GetBottomCorner ( i ) , x . TransformToWorld ) ;
2017-07-10 14:00:27 -07:00
traceBottoms [ i ] = this . World . GetScreenPosition ( bottomStartPosition ) ;
2017-06-06 10:06:38 -07:00
Vector3 topStartPosition = Vector3 . Transform ( x . Bvh . GetAxisAlignedBoundingBox ( ) . GetTopCorner ( i ) , x . TransformToWorld ) ;
2017-07-10 14:00:27 -07:00
traceTops [ i ] = this . World . GetScreenPosition ( topStartPosition ) ;
2017-06-05 15:44:52 -07:00
}
2017-06-01 09:42:40 -07:00
2017-06-06 10:06:38 -07:00
RectangleDouble . OutCode allPoints = RectangleDouble . OutCode . Inside ;
// check if we are inside all the points
for ( int i = 0 ; i < 4 ; i + + )
{
allPoints | = selectionRectangle . ComputeOutCode ( traceBottoms [ i ] ) ;
allPoints | = selectionRectangle . ComputeOutCode ( traceTops [ i ] ) ;
}
if ( allPoints = = RectangleDouble . OutCode . Surrounded )
2017-05-30 17:51:52 -07:00
{
return true ;
}
2017-06-06 10:06:38 -07:00
for ( int i = 0 ; i < 4 ; i + + )
{
if ( selectionRectangle . ClipLine ( traceBottoms [ i ] , traceBottoms [ ( i + 1 ) % 4 ] )
| | selectionRectangle . ClipLine ( traceTops [ i ] , traceTops [ ( i + 1 ) % 4 ] )
| | selectionRectangle . ClipLine ( traceTops [ i ] , traceBottoms [ i ] ) )
{
return true ;
}
}
}
2017-05-31 11:56:25 -07:00
2017-06-06 10:06:38 -07:00
return false ;
}
2017-05-31 11:56:25 -07:00
2015-12-22 15:26:51 -08:00
private ViewControls3DButtons ? activeButtonBeforeMouseOverride = null ;
2015-05-29 15:13:56 -07:00
2015-05-30 12:48:16 -07:00
public override void OnMouseDown ( MouseEventArgs mouseEvent )
2015-04-08 15:20:10 -07:00
{
2015-05-29 15:13:56 -07:00
// Show transform override
2018-02-07 18:01:49 -08:00
if ( activeButtonBeforeMouseOverride = = null
2018-01-18 09:38:57 -08:00
& & ( mouseEvent . Button = = MouseButtons . Right | | Keyboard . IsKeyDown ( Keys . Control ) ) )
2015-05-29 15:13:56 -07:00
{
2018-01-18 09:38:57 -08:00
if ( Keyboard . IsKeyDown ( Keys . Shift ) )
{
activeButtonBeforeMouseOverride = viewControls3D . ActiveButton ;
viewControls3D . ActiveButton = ViewControls3DButtons . Translate ;
}
2018-02-07 18:01:49 -08:00
else if ( Keyboard . IsKeyDown ( Keys . Alt ) )
2018-01-20 22:17:39 -08:00
{
activeButtonBeforeMouseOverride = viewControls3D . ActiveButton ;
viewControls3D . ActiveButton = ViewControls3DButtons . Scale ;
}
2018-01-18 09:38:57 -08:00
else
{
activeButtonBeforeMouseOverride = viewControls3D . ActiveButton ;
viewControls3D . ActiveButton = ViewControls3DButtons . Rotate ;
}
2015-05-29 15:13:56 -07:00
}
else if ( activeButtonBeforeMouseOverride = = null & & mouseEvent . Button = = MouseButtons . Middle )
{
activeButtonBeforeMouseOverride = viewControls3D . ActiveButton ;
viewControls3D . ActiveButton = ViewControls3DButtons . Translate ;
}
2018-02-07 18:01:49 -08:00
if ( mouseEvent . Button = = MouseButtons . Right | |
2017-03-15 16:17:06 -07:00
mouseEvent . Button = = MouseButtons . Middle )
{
meshViewerWidget . SuppressUiVolumes = true ;
}
2015-05-30 12:48:16 -07:00
autoRotating = false ;
base . OnMouseDown ( mouseEvent ) ;
2017-03-15 16:17:06 -07:00
2018-02-17 09:17:40 -08:00
if ( trackballTumbleWidget . UnderMouseState = = UnderMouseState . FirstUnderMouse )
2015-04-08 15:20:10 -07:00
{
2017-03-15 16:17:06 -07:00
if ( mouseEvent . Button = = MouseButtons . Left
2018-01-18 09:38:57 -08:00
& & viewControls3D . ActiveButton = = ViewControls3DButtons . PartSelect
2017-03-15 16:17:06 -07:00
& &
2017-06-06 13:34:42 -07:00
( ModifierKeys = = Keys . Shift | | ModifierKeys = = Keys . Control )
2017-06-06 14:41:49 -07:00
| | (
2018-04-03 08:36:21 -07:00
trackballTumbleWidget . TransformState = = TrackBallTransformType . None
2017-06-06 14:41:49 -07:00
& & ModifierKeys ! = Keys . Control
& & ModifierKeys ! = Keys . Alt ) )
2015-04-08 15:20:10 -07:00
{
2017-07-11 08:10:57 -07:00
if ( ! this . InteractionLayer . MouseDownOnInteractionVolume )
2015-05-30 12:48:16 -07:00
{
2017-03-15 16:17:06 -07:00
meshViewerWidget . SuppressUiVolumes = true ;
2016-02-19 08:29:49 -08:00
IntersectInfo info = new IntersectInfo ( ) ;
2017-03-15 16:17:06 -07:00
IObject3D hitObject = FindHitObject3D ( mouseEvent . Position , ref info ) ;
2017-05-31 17:47:12 -07:00
if ( hitObject = = null )
{
2018-02-05 17:56:17 -08:00
if ( scene . HasSelection )
2017-05-31 17:47:12 -07:00
{
2018-02-05 17:56:17 -08:00
scene . ClearSelection ( ) ;
2017-05-31 17:47:12 -07:00
}
// start a selection rect
DragSelectionStartPosition = mouseEvent . Position - OffsetToMeshViewerWidget ( ) ;
2017-06-05 15:44:52 -07:00
DragSelectionEndPosition = DragSelectionStartPosition ;
2017-05-31 17:47:12 -07:00
DragSelectionInProgress = true ;
}
else
2015-05-30 12:48:16 -07:00
{
2017-10-31 12:51:16 -07:00
CurrentSelectInfo . HitPlane = new PlaneShape ( Vector3 . UnitZ , CurrentSelectInfo . PlaneDownHitPos . Z , null ) ;
2014-03-20 18:20:52 -07:00
2018-02-05 17:56:17 -08:00
if ( hitObject ! = scene . SelectedItem )
2017-03-15 16:17:06 -07:00
{
2018-02-05 17:56:17 -08:00
if ( scene . SelectedItem = = null )
2017-03-15 16:17:06 -07:00
{
// No selection exists
2018-02-05 17:56:17 -08:00
scene . SelectedItem = hitObject ;
2017-03-15 16:17:06 -07:00
}
2017-06-06 13:34:42 -07:00
else if ( ( ModifierKeys = = Keys . Shift | | ModifierKeys = = Keys . Control )
2018-02-05 17:56:17 -08:00
& & ! scene . SelectedItem . Children . Contains ( hitObject ) )
2017-03-15 16:17:06 -07:00
{
2018-02-05 17:56:17 -08:00
scene . AddToSelection ( hitObject ) ;
2017-03-15 16:17:06 -07:00
}
2018-02-05 17:56:17 -08:00
else if ( scene . SelectedItem = = hitObject | | scene . SelectedItem . Children . Contains ( hitObject ) )
2017-03-15 16:17:06 -07:00
{
// Selection should not be cleared and drag should occur
}
else if ( ModifierKeys ! = Keys . Shift )
{
2018-02-05 17:56:17 -08:00
scene . SelectedItem = hitObject ;
2017-03-15 16:17:06 -07:00
}
2017-10-25 17:04:55 -07:00
Invalidate ( ) ;
2017-03-15 16:17:06 -07:00
}
2018-02-05 17:56:17 -08:00
transformOnMouseDown = scene . SelectedItem . Matrix ;
2015-04-08 15:20:10 -07:00
2015-05-30 12:48:16 -07:00
Invalidate ( ) ;
2016-02-19 08:29:49 -08:00
CurrentSelectInfo . DownOnPart = true ;
2018-02-05 17:56:17 -08:00
AxisAlignedBoundingBox selectedBounds = scene . SelectedItem . GetAxisAlignedBoundingBox ( Matrix4X4 . Identity ) ;
2016-02-19 08:29:49 -08:00
2017-10-31 12:51:16 -07:00
if ( info . HitPosition . X < selectedBounds . Center . X )
2016-02-19 08:29:49 -08:00
{
2017-10-31 12:51:16 -07:00
if ( info . HitPosition . Y < selectedBounds . Center . Y )
2016-02-19 08:29:49 -08:00
{
CurrentSelectInfo . HitQuadrant = HitQuadrant . LB ;
}
else
{
CurrentSelectInfo . HitQuadrant = HitQuadrant . LT ;
}
}
else
{
2017-10-31 12:51:16 -07:00
if ( info . HitPosition . Y < selectedBounds . Center . Y )
2016-02-19 08:29:49 -08:00
{
CurrentSelectInfo . HitQuadrant = HitQuadrant . RB ;
}
else
{
CurrentSelectInfo . HitQuadrant = HitQuadrant . RT ;
}
}
2015-05-30 12:48:16 -07:00
}
}
2015-04-08 15:20:10 -07:00
}
2015-05-30 12:48:16 -07:00
}
}
2015-02-27 11:09:37 -08:00
2018-01-19 13:43:39 -08:00
public override void OnMouseMove ( MouseEventArgs mouseEvent )
{
// File system Drop validation
mouseEvent . AcceptDrop = this . AllowDragDrop ( )
& & mouseEvent . DragFiles ? . Count > 0
& & mouseEvent . DragFiles . TrueForAll ( filePath = > ApplicationController . Instance . IsLoadableFile ( filePath ) ) ;
// View3DWidgets Filesystem DropDrop handler
if ( mouseEvent . AcceptDrop
& & this . PositionWithinLocalBounds ( mouseEvent . X , mouseEvent . Y ) )
{
if ( this . DragOperationActive )
{
DragOver ( screenSpaceMousePosition : this . TransformToScreenSpace ( mouseEvent . Position ) ) ;
}
else
{
// Project DragFiles to IEnumerable<FileSystemFileItem>
this . StartDragDrop (
mouseEvent . DragFiles . Select ( path = > new FileSystemFileItem ( path ) ) ,
screenSpaceMousePosition : this . TransformToScreenSpace ( mouseEvent . Position ) ,
trackSourceFiles : true ) ;
}
}
2018-04-03 08:36:21 -07:00
if ( CurrentSelectInfo . DownOnPart & & trackballTumbleWidget . TransformState = = TrackBallTransformType . None )
2018-01-19 13:43:39 -08:00
{
DragSelectedObject ( new Vector2 ( mouseEvent . X , mouseEvent . Y ) ) ;
}
if ( DragSelectionInProgress )
{
DragSelectionEndPosition = mouseEvent . Position - OffsetToMeshViewerWidget ( ) ;
DragSelectionEndPosition = new Vector2 (
2018-03-08 17:23:03 -08:00
Math . Max ( Math . Min ( ( double ) DragSelectionEndPosition . X , meshViewerWidget . LocalBounds . Right ) , meshViewerWidget . LocalBounds . Left ) ,
Math . Max ( Math . Min ( ( double ) DragSelectionEndPosition . Y , meshViewerWidget . LocalBounds . Top ) , meshViewerWidget . LocalBounds . Bottom ) ) ;
2018-01-19 13:43:39 -08:00
Invalidate ( ) ;
}
base . OnMouseMove ( mouseEvent ) ;
}
2017-03-15 16:17:06 -07:00
public IntersectInfo GetIntersectPosition ( Vector2 screenSpacePosition )
{
//Vector2 meshViewerWidgetScreenPosition = meshViewerWidget.TransformFromParentSpace(this, new Vector2(mouseEvent.X, mouseEvent.Y));
2016-02-17 08:23:09 -08:00
2017-03-15 16:17:06 -07:00
// Translate to local
Vector2 localPosition = this . TransformFromScreenSpace ( screenSpacePosition ) ;
2017-07-10 14:00:27 -07:00
Ray ray = this . World . GetRayForLocalBounds ( localPosition ) ;
2017-03-15 16:17:06 -07:00
return CurrentSelectInfo . HitPlane . GetClosestIntersection ( ray ) ;
}
2018-04-04 15:58:57 -07:00
public void DragSelectedObject ( Vector2 localMousePosition )
2015-05-30 12:48:16 -07:00
{
2018-04-04 15:58:57 -07:00
Vector2 meshViewerWidgetScreenPosition = meshViewerWidget . TransformFromParentSpace ( this , localMousePosition ) ;
2017-07-10 14:00:27 -07:00
Ray ray = this . World . GetRayForLocalBounds ( meshViewerWidgetScreenPosition ) ;
2017-03-15 16:17:06 -07:00
IntersectInfo info = CurrentSelectInfo . HitPlane . GetClosestIntersection ( ray ) ;
if ( info ! = null )
2015-05-30 12:48:16 -07:00
{
2018-01-23 16:56:15 -08:00
if ( CurrentSelectInfo . LastMoveDelta = = Vector3 . PositiveInfinity )
{
2018-02-05 17:56:17 -08:00
CalculateDragStartPosition ( scene . SelectedItem , info ) ;
2018-01-23 16:56:15 -08:00
}
2017-03-15 16:17:06 -07:00
// move the mesh back to the start position
{
Matrix4X4 totalTransform = Matrix4X4 . CreateTranslation ( new Vector3 ( - CurrentSelectInfo . LastMoveDelta ) ) ;
2018-02-05 17:56:17 -08:00
scene . SelectedItem . Matrix * = totalTransform ;
2017-12-15 12:20:17 -08:00
// Invalidate the item to account for the position change
2018-02-05 17:56:17 -08:00
scene . SelectedItem . Invalidate ( ) ;
2017-03-15 16:17:06 -07:00
}
2017-06-16 11:12:24 -07:00
Vector3 delta = info . HitPosition - CurrentSelectInfo . PlaneDownHitPos ;
2017-03-15 16:17:06 -07:00
2017-07-11 08:10:57 -07:00
double snapGridDistance = this . InteractionLayer . SnapGridDistance ;
2017-03-15 16:17:06 -07:00
if ( snapGridDistance > 0 )
2015-02-27 11:09:37 -08:00
{
2017-03-15 16:17:06 -07:00
// snap this position to the grid
2018-02-05 17:56:17 -08:00
AxisAlignedBoundingBox selectedBounds = scene . SelectedItem . GetAxisAlignedBoundingBox ( Matrix4X4 . Identity ) ;
2017-03-15 16:17:06 -07:00
2017-10-31 12:51:16 -07:00
double xSnapOffset = selectedBounds . minXYZ . X ;
2017-03-15 16:17:06 -07:00
// snap the x position
if ( CurrentSelectInfo . HitQuadrant = = HitQuadrant . RB
| | CurrentSelectInfo . HitQuadrant = = HitQuadrant . RT )
2016-02-18 09:36:01 -08:00
{
2017-03-15 16:17:06 -07:00
// switch to the other side
2017-10-31 12:51:16 -07:00
xSnapOffset = selectedBounds . maxXYZ . X ;
2016-02-18 09:36:01 -08:00
}
2017-10-31 12:51:16 -07:00
double xToSnap = xSnapOffset + delta . X ;
2016-02-18 09:36:01 -08:00
2017-03-15 16:17:06 -07:00
double snappedX = ( ( int ) ( ( xToSnap / snapGridDistance ) + . 5 ) ) * snapGridDistance ;
2017-10-31 12:51:16 -07:00
delta . X = snappedX - xSnapOffset ;
2015-02-27 11:09:37 -08:00
2017-10-31 12:51:16 -07:00
double ySnapOffset = selectedBounds . minXYZ . Y ;
2017-03-15 16:17:06 -07:00
// snap the y position
if ( CurrentSelectInfo . HitQuadrant = = HitQuadrant . LT
| | CurrentSelectInfo . HitQuadrant = = HitQuadrant . RT )
2016-02-17 08:23:09 -08:00
{
2017-03-15 16:17:06 -07:00
// switch to the other side
2017-10-31 12:51:16 -07:00
ySnapOffset = selectedBounds . maxXYZ . Y ;
2017-03-15 16:17:06 -07:00
}
2017-10-31 12:51:16 -07:00
double yToSnap = ySnapOffset + delta . Y ;
2016-02-17 08:23:09 -08:00
2017-03-15 16:17:06 -07:00
double snappedY = ( ( int ) ( ( yToSnap / snapGridDistance ) + . 5 ) ) * snapGridDistance ;
2017-10-31 12:51:16 -07:00
delta . Y = snappedY - ySnapOffset ;
2017-03-15 16:17:06 -07:00
}
2016-02-17 08:23:09 -08:00
2017-08-15 11:05:32 -07:00
// if the shift key is down only move on the major axis of x or y
2018-02-07 18:01:49 -08:00
if ( Keyboard . IsKeyDown ( Keys . ShiftKey ) )
2017-08-15 11:05:32 -07:00
{
2018-02-07 18:01:49 -08:00
if ( Math . Abs ( delta . X ) < Math . Abs ( delta . Y ) )
2017-08-15 11:05:32 -07:00
{
2017-10-31 12:51:16 -07:00
delta . X = 0 ;
2017-08-15 11:05:32 -07:00
}
else
{
2017-10-31 12:51:16 -07:00
delta . Y = 0 ;
2017-08-15 11:05:32 -07:00
}
}
2017-03-15 16:17:06 -07:00
// move the mesh back to the new position
{
Matrix4X4 totalTransform = Matrix4X4 . CreateTranslation ( new Vector3 ( delta ) ) ;
2015-02-27 11:09:37 -08:00
2018-02-05 17:56:17 -08:00
scene . SelectedItem . Matrix * = totalTransform ;
2016-02-18 09:36:01 -08:00
2017-03-15 16:17:06 -07:00
CurrentSelectInfo . LastMoveDelta = delta ;
}
2016-02-18 09:36:01 -08:00
2017-03-15 16:17:06 -07:00
Invalidate ( ) ;
}
}
2015-02-27 11:09:37 -08:00
2017-05-31 17:47:12 -07:00
Vector2 OffsetToMeshViewerWidget ( )
{
List < GuiWidget > parents = new List < GuiWidget > ( ) ;
GuiWidget parent = meshViewerWidget . Parent ;
while ( parent ! = this )
{
parents . Add ( parent ) ;
parent = parent . Parent ;
}
Vector2 offset = new Vector2 ( ) ;
2018-02-07 18:01:49 -08:00
for ( int i = parents . Count - 1 ; i > = 0 ; i - - )
2017-05-31 17:47:12 -07:00
{
offset + = parents [ i ] . OriginRelativeParent ;
}
return offset ;
}
2017-07-10 14:00:27 -07:00
public void ResetView ( )
{
2018-02-17 09:17:40 -08:00
trackballTumbleWidget . ZeroVelocity ( ) ;
2017-07-10 14:00:27 -07:00
var world = this . World ;
world . Reset ( ) ;
world . Scale = . 03 ;
2017-09-15 16:49:21 -07:00
world . Translate ( - new Vector3 ( sceneContext . BedCenter ) ) ;
2017-11-08 14:45:36 -08:00
world . Rotate ( Quaternion . FromEulerAngles ( new Vector3 ( 0 , 0 , - MathHelper . Tau / 16 ) ) ) ;
world . Rotate ( Quaternion . FromEulerAngles ( new Vector3 ( MathHelper . Tau * . 19 , 0 , 0 ) ) ) ;
2017-07-10 14:00:27 -07:00
}
2015-05-30 12:48:16 -07:00
public override void OnMouseUp ( MouseEventArgs mouseEvent )
2015-04-08 15:20:10 -07:00
{
2017-09-19 19:59:55 -07:00
if ( this . DragOperationActive )
2017-04-05 16:25:43 -07:00
{
2017-09-19 19:59:55 -07:00
this . FinishDrop ( mouseUpInBounds : true ) ;
2017-04-05 16:25:43 -07:00
}
2018-04-03 08:36:21 -07:00
if ( trackballTumbleWidget . TransformState = = TrackBallTransformType . None )
2015-04-08 15:20:10 -07:00
{
2018-02-05 17:56:17 -08:00
if ( scene . SelectedItem ! = null
2017-07-11 12:50:21 -07:00
& & CurrentSelectInfo . DownOnPart
& & CurrentSelectInfo . LastMoveDelta ! = Vector3 . Zero )
2016-02-27 13:56:57 -08:00
{
2017-07-12 21:59:22 -07:00
InteractionLayer . AddTransformSnapshot ( transformOnMouseDown ) ;
2017-05-31 17:47:12 -07:00
}
else if ( DragSelectionInProgress )
{
2017-06-06 10:57:13 -07:00
DoRectangleSelection ( null ) ;
2017-05-31 17:47:12 -07:00
DragSelectionInProgress = false ;
2016-02-27 13:56:57 -08:00
}
2015-05-30 12:48:16 -07:00
}
2015-04-08 15:20:10 -07:00
2017-03-15 16:17:06 -07:00
meshViewerWidget . SuppressUiVolumes = false ;
2016-02-19 08:29:49 -08:00
CurrentSelectInfo . DownOnPart = false ;
2015-04-08 15:20:10 -07:00
2015-05-29 15:13:56 -07:00
if ( activeButtonBeforeMouseOverride ! = null )
{
viewControls3D . ActiveButton = ( ViewControls3DButtons ) activeButtonBeforeMouseOverride ;
activeButtonBeforeMouseOverride = null ;
}
2015-05-30 12:48:16 -07:00
base . OnMouseUp ( mouseEvent ) ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
if ( deferEditorTillMouseUp )
{
this . deferEditorTillMouseUp = false ;
Scene_SelectionChanged ( null , null ) ;
}
2015-05-30 12:48:16 -07:00
}
2015-04-08 15:20:10 -07:00
2017-09-16 01:36:19 -07:00
// TODO: Consider if we should always allow DragDrop or if we should prevent during printer or other scenarios
2017-09-15 22:34:46 -07:00
private bool AllowDragDrop ( ) = > true ;
2015-05-30 12:48:16 -07:00
2015-06-11 12:06:40 -07:00
private void AutoSpin ( )
2015-05-30 12:48:16 -07:00
{
2016-04-25 12:51:29 -07:00
if ( ! HasBeenClosed & & autoRotating )
2015-05-30 12:48:16 -07:00
{
if ( ( ! timeSinceLastSpin . IsRunning | | timeSinceLastSpin . ElapsedMilliseconds > 50 )
& & hasDrawn )
{
hasDrawn = false ;
timeSinceLastSpin . Restart ( ) ;
2017-07-11 08:10:57 -07:00
Quaternion currentRotation = this . World . RotationMatrix . GetRotation ( ) ;
2015-05-30 12:48:16 -07:00
Quaternion invertedRotation = Quaternion . Invert ( currentRotation ) ;
Quaternion rotateAboutZ = Quaternion . FromEulerAngles ( new Vector3 ( 0 , 0 , . 01 ) ) ;
rotateAboutZ = invertedRotation * rotateAboutZ * currentRotation ;
2017-07-10 14:00:27 -07:00
this . World . Rotate ( rotateAboutZ ) ;
2015-05-30 12:48:16 -07:00
Invalidate ( ) ;
}
}
}
2017-03-15 16:17:06 -07:00
private void Scene_SelectionChanged ( object sender , EventArgs e )
{
2018-02-05 17:56:17 -08:00
if ( ! scene . HasSelection )
2017-03-15 16:17:06 -07:00
{
2018-01-09 09:14:12 -08:00
if ( printer ! = null )
{
printer . ViewState . SelectedObjectPanelWidth = selectedObjectPanel . Width ;
}
2017-10-20 07:26:14 -07:00
selectedObjectContainer . Visible = false ;
2017-03-15 16:17:06 -07:00
return ;
}
2015-05-30 12:48:16 -07:00
2017-04-05 19:03:04 -07:00
if ( deferEditorTillMouseUp )
{
return ;
}
2018-02-05 17:56:17 -08:00
var selectedItem = scene . SelectedItem ;
2015-05-30 12:48:16 -07:00
2017-10-18 18:18:10 -07:00
selectedObjectPanel . SetActiveItem ( selectedItem ) ;
2017-03-15 16:17:06 -07:00
}
2015-05-30 12:48:16 -07:00
2016-01-10 10:18:53 -08:00
public static Regex fileNameNumberMatch = new Regex ( "\\(\\d+\\)" , RegexOptions . Compiled ) ;
2017-10-20 07:26:14 -07:00
private SelectedObjectPanel selectedObjectPanel ;
internal GuiWidget selectedObjectContainer ;
2017-10-19 09:04:36 -07:00
2017-05-31 17:47:12 -07:00
public Vector2 DragSelectionStartPosition { get ; private set ; }
public bool DragSelectionInProgress { get ; private set ; }
public Vector2 DragSelectionEndPosition { get ; private set ; }
2018-01-21 21:07:14 -08:00
internal GuiWidget ShowOverflowMenu ( PopupMenu popupMenu )
2017-05-25 17:58:20 -07:00
{
2018-03-16 17:42:34 -07:00
this . ShowBedViewOptions ( popupMenu ) ;
2017-11-09 15:48:05 -08:00
2017-11-09 18:26:32 -08:00
popupMenu . CreateHorizontalLine ( ) ;
2017-05-27 17:48:32 -07:00
2018-02-03 13:49:11 -08:00
void switchToRenderType ( RenderTypes renderType )
{
meshViewerWidget . RenderType = renderType ;
UserSettings . Instance . set ( UserSettingsKey . defaultRenderSetting , renderType . ToString ( ) ) ;
}
2018-03-16 17:44:03 -07:00
var siblingList = new List < GuiWidget > ( ) ;
2018-02-03 13:49:11 -08:00
popupMenu . CreateBoolMenuItem (
2018-03-14 15:23:32 -07:00
"Shaded" . Localize ( ) ,
2018-02-03 13:49:11 -08:00
( ) = > meshViewerWidget . RenderType = = RenderTypes . Shaded ,
( v ) = > switchToRenderType ( RenderTypes . Shaded ) ,
2018-03-16 17:44:03 -07:00
useRadioStyle : true ,
SiblingRadioButtonList : siblingList ) ;
2018-02-03 13:49:11 -08:00
popupMenu . CreateBoolMenuItem (
"Outlines" . Localize ( ) ,
( ) = > meshViewerWidget . RenderType = = RenderTypes . Outlines ,
( v ) = > switchToRenderType ( RenderTypes . Outlines ) ,
2018-03-16 17:44:03 -07:00
useRadioStyle : true ,
SiblingRadioButtonList : siblingList ) ;
2018-02-03 13:49:11 -08:00
popupMenu . CreateBoolMenuItem (
"Polygons" . Localize ( ) ,
( ) = > meshViewerWidget . RenderType = = RenderTypes . Polygons ,
( v ) = > switchToRenderType ( RenderTypes . Polygons ) ,
2018-03-16 17:44:03 -07:00
useRadioStyle : true ,
SiblingRadioButtonList : siblingList ) ;
2018-02-03 13:49:11 -08:00
popupMenu . CreateBoolMenuItem (
2018-02-13 18:35:55 -08:00
"Materials" . Localize ( ) ,
2018-02-03 13:49:11 -08:00
( ) = > meshViewerWidget . RenderType = = RenderTypes . Materials ,
( v ) = > switchToRenderType ( RenderTypes . Materials ) ,
2018-03-16 17:44:03 -07:00
useRadioStyle : true ,
SiblingRadioButtonList : siblingList ) ;
2018-02-03 13:49:11 -08:00
popupMenu . CreateBoolMenuItem (
"Overhang" . Localize ( ) ,
( ) = > meshViewerWidget . RenderType = = RenderTypes . Overhang ,
( value ) = > switchToRenderType ( RenderTypes . Overhang ) ,
2018-03-16 17:44:03 -07:00
useRadioStyle : true ,
SiblingRadioButtonList : siblingList ) ;
2017-05-25 17:58:20 -07:00
2017-11-09 18:26:32 -08:00
popupMenu . CreateHorizontalLine ( ) ;
2017-05-25 17:58:20 -07:00
2017-11-09 18:26:32 -08:00
popupMenu . AddChild ( new GridOptionsPanel ( this . InteractionLayer ) ) ;
2017-05-25 17:58:20 -07:00
2017-11-09 18:26:32 -08:00
return popupMenu ;
2017-11-09 15:48:05 -08:00
}
2017-05-25 17:58:20 -07:00
2018-03-16 17:42:34 -07:00
internal void ShowBedViewOptions ( PopupMenu popupMenu )
{
popupMenu . CreateBoolMenuItem (
"Show Print Bed" . Localize ( ) ,
( ) = > sceneContext . RendererOptions . RenderBed ,
( value ) = >
{
sceneContext . RendererOptions . RenderBed = value ;
} ) ;
if ( sceneContext . BuildHeight > 0
& & printer ? . ViewState . ViewMode ! = PartViewMode . Layers2D )
{
popupMenu . CreateBoolMenuItem (
"Show Print Area" . Localize ( ) ,
2018-04-02 14:55:54 -07:00
( ) = > sceneContext . RendererOptions . RenderBuildVolume ,
( value ) = > sceneContext . RendererOptions . RenderBuildVolume = value ) ;
2018-03-16 17:42:34 -07:00
}
}
2017-07-05 14:34:38 -07:00
protected bool autoRotating = false ;
protected bool allowAutoRotate = false ;
public MeshViewerWidget meshViewerWidget ;
2018-02-05 17:56:17 -08:00
private InteractiveScene scene = > sceneContext . Scene ;
2017-07-05 14:34:38 -07:00
protected ViewControls3D viewControls3D { get ; }
2017-07-12 21:57:30 -07:00
public MeshSelectInfo CurrentSelectInfo { get ; } = new MeshSelectInfo ( ) ;
2017-07-05 14:34:38 -07:00
protected IObject3D FindHitObject3D ( Vector2 screenPosition , ref IntersectInfo intersectionInfo )
{
Vector2 meshViewerWidgetScreenPosition = meshViewerWidget . TransformFromParentSpace ( this , screenPosition ) ;
2017-07-10 14:00:27 -07:00
Ray ray = this . World . GetRayForLocalBounds ( meshViewerWidgetScreenPosition ) ;
2017-07-05 14:34:38 -07:00
2018-02-05 17:56:17 -08:00
intersectionInfo = scene . TraceData ( ) . GetClosestIntersection ( ray ) ;
2017-07-05 14:34:38 -07:00
if ( intersectionInfo ! = null )
{
2018-02-05 17:56:17 -08:00
foreach ( Object3D object3D in scene . Children )
2017-07-05 14:34:38 -07:00
{
2018-01-02 15:25:40 -08:00
if ( object3D . TraceData ( ) . Contains ( intersectionInfo . HitPosition ) )
2017-07-05 14:34:38 -07:00
{
CurrentSelectInfo . PlaneDownHitPos = intersectionInfo . HitPosition ;
CurrentSelectInfo . LastMoveDelta = new Vector3 ( ) ;
return object3D ;
}
}
}
return null ;
}
2018-02-07 18:01:49 -08:00
2016-02-19 08:29:49 -08:00
}
2015-05-30 12:48:16 -07:00
2016-02-19 08:29:49 -08:00
public enum HitQuadrant { LB , LT , RB , RT }
2018-03-01 09:56:50 -08:00
2016-02-19 08:29:49 -08:00
public class MeshSelectInfo
{
public HitQuadrant HitQuadrant ;
public bool DownOnPart ;
public PlaneShape HitPlane ;
public Vector3 LastMoveDelta ;
public Vector3 PlaneDownHitPos ;
2015-04-08 15:20:10 -07:00
}
2017-08-20 02:34:39 -07:00
}