@ -27,7 +27,6 @@ using System.Windows.Media;
using System.Windows.Shapes ;
using System.Windows.Shapes ;
using System.Windows ;
using System.Windows ;
using System.Windows.Controls ;
using System.Windows.Controls ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Diagnostics ;
using System.Linq ;
using System.Linq ;
@ -40,9 +39,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// </summary>
/// </summary>
[ExtensionFor(typeof(Polyline))]
[ExtensionFor(typeof(Polyline))]
[ExtensionFor(typeof(Polygon))]
[ExtensionFor(typeof(Polygon))]
internal class PolyLineHandlerExtension : LineExtensionBase , IKeyDown , IKeyUp
public class PolyLineHandlerExtension : LineExtensionBase , IKeyDown , IKeyUp
{
{
private readonly Dictionary < int , Bounds > _ selectedThumb s = new Dictionary < int , Bounds > ( ) ;
private readonly Dictionary < int , Point > _ selectedPoint s = new Dictionary < int , Point > ( ) ;
private bool _ isDragging ;
private bool _ isDragging ;
ZoomControl _ zoom ;
ZoomControl _ zoom ;
@ -73,14 +72,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if ( rt is DesignerThumb )
if ( rt is DesignerThumb )
( rt as DesignerThumb ) . IsPrimarySelection = true ;
( rt as DesignerThumb ) . IsPrimarySelection = true ;
}
}
_ selectedThumb s . Clear ( ) ;
_ selectedPoint s . Clear ( ) ;
}
}
private void SelectThumb ( MultiPointThumb mprt )
private void SelectThumb ( MultiPointThumb mprt )
{
{
PointCollection points = GetPointCollection ( ) ;
PointCollection points = GetPointCollection ( ) ;
Point p = points [ mprt . Index ] ;
Point p = points [ mprt . Index ] ;
_ selectedThumb s . Add ( mprt . Index , new Bounds { X = p . X , Y = p . Y } ) ;
_ selectedPoint s . Add ( mprt . Index , p ) ;
mprt . IsPrimarySelection = false ;
mprt . IsPrimarySelection = false ;
}
}
@ -119,13 +118,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
else
else
{
{
//if not keyboard ctrl is pressed and selected point is not previously selected, clear selection
//if not keyboard ctrl is pressed and selected point is not previously selected, clear selection
if ( ! _ selectedThumb s . ContainsKey ( mprt . Index ) & ! Keyboard . IsKeyDown ( Key . LeftCtrl ) &
if ( ! _ selectedPoint s . ContainsKey ( mprt . Index ) & ! Keyboard . IsKeyDown ( Key . LeftCtrl ) &
! Keyboard . IsKeyDown ( Key . RightCtrl ) )
! Keyboard . IsKeyDown ( Key . RightCtrl ) )
{
{
ResetThumbs ( ) ;
ResetThumbs ( ) ;
}
}
//add selected thumb, if ctrl pressed this could be all points in poly
//add selected thumb, if ctrl pressed this could be all points in poly
if ( ! _ selectedThumb s . ContainsKey ( mprt . Index ) )
if ( ! _ selectedPoint s . ContainsKey ( mprt . Index ) )
SelectThumb ( mprt ) ;
SelectThumb ( mprt ) ;
_ isDragging = false ;
_ isDragging = false ;
}
}
@ -174,10 +173,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
points = pl . Points ;
points = pl . Points ;
}
}
foreach ( int i in _ selectedThumb s . Keys )
foreach ( int i in _ selectedPoint s . Keys . ToList ( ) )
{
{
_ selectedThumbs [ i ] . X = points [ i ] . X ;
_ selectedPoints [ i ] = points [ i ] ;
_ selectedThumbs [ i ] . Y = points [ i ] . Y ;
}
}
ExtendedItem . Properties . GetProperty ( pl ! = null ? Polyline . PointsProperty : Polygon . PointsProperty ) . SetValue ( points ) ;
ExtendedItem . Properties . GetProperty ( pl ! = null ? Polyline . PointsProperty : Polygon . PointsProperty ) . SetValue ( points ) ;
operation . Commit ( ) ;
operation . Commit ( ) ;
@ -213,8 +211,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
Double theta ;
Double theta ;
//if one point selected snapping angle is calculated in relation to previous point
//if one point selected snapping angle is calculated in relation to previous point
if ( _ selectedThumb s . Count = = 1 & & mprt . Index > 0 ) {
if ( _ selectedPoint s . Count = = 1 & & mprt . Index > 0 ) {
theta = ( 1 8 0 / Math . PI ) * Math . Atan2 ( _ selectedThumb s [ mprt . Index ] . Y + dy - points [ mprt . Index - 1 ] . Y , _ selectedThumb s [ mprt . Index ] . X + dx - points [ mprt . Index - 1 ] . X ) ;
theta = ( 1 8 0 / Math . PI ) * Math . Atan2 ( _ selectedPoint s [ mprt . Index ] . Y + dy - points [ mprt . Index - 1 ] . Y , _ selectedPoint s [ mprt . Index ] . X + dx - points [ mprt . Index - 1 ] . X ) ;
} else { //if multiple points snapping angle is calculated in relation to mouse dragging angle
} else { //if multiple points snapping angle is calculated in relation to mouse dragging angle
theta = ( 1 8 0 / Math . PI ) * Math . Atan2 ( dy , dx ) ;
theta = ( 1 8 0 / Math . PI ) * Math . Atan2 ( dy , dx ) ;
}
}
@ -228,7 +226,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
//if dragging occurs on a point and that point is the only selected, a new node will be added.
//if dragging occurs on a point and that point is the only selected, a new node will be added.
//_isCtrlDragging is needed since this method is called for every x pixel that the mouse moves
//_isCtrlDragging is needed since this method is called for every x pixel that the mouse moves
//so it could be many thousands of times during a single dragging
//so it could be many thousands of times during a single dragging
if ( ! _ isDragging & & _ selectedThumb s . Count = = 1 & & ( Math . Abs ( dx ) > 0 | | Math . Abs ( dy ) > 0 ) )
if ( ! _ isDragging & & _ selectedPoint s . Count = = 1 & & ( Math . Abs ( dx ) > 0 | | Math . Abs ( dy ) > 0 ) )
{
{
//duplicate point that is selected
//duplicate point that is selected
@ -333,29 +331,29 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
PointCollection MovePoints ( PointCollection pc , double displacementX , double displacementY , double theta , int? snapangle )
PointCollection MovePoints ( PointCollection pc , double displacementX , double displacementY , double theta , int? snapangle )
{
{
//iterate all selected points
//iterate all selected points
foreach ( int i in _ selectedThumb s . Keys )
foreach ( int i in _ selectedPoint s . Keys )
{
{
Point p = pc [ i ] ;
Point p = pc [ i ] ;
//x and y is calculated from the currentl point
//x and y is calculated from the currentl point
double x = _ selectedThumb s [ i ] . X + displacementX ;
double x = _ selectedPoint s [ i ] . X + displacementX ;
double y = _ selectedThumb s [ i ] . Y + displacementY ;
double y = _ selectedPoint s [ i ] . Y + displacementY ;
//if snap is applied
//if snap is applied
if ( snapangle ! = null )
if ( snapangle ! = null )
{
{
if ( _ selectedThumb s . Count > 0 )
if ( _ selectedPoint s . Count > 0 )
{
{
//horizontal snap
//horizontal snap
if ( Math . Abs ( theta ) < snapangle | | 1 8 0 - Math . Abs ( theta ) < snapangle )
if ( Math . Abs ( theta ) < snapangle | | 1 8 0 - Math . Abs ( theta ) < snapangle )
{
{
//if one point selected use point before as snap point, else snap to movement
//if one point selected use point before as snap point, else snap to movement
y = _ selectedThumb s . Count = = 1 ? pc [ i - 1 ] . Y : y - displacementY ;
y = _ selectedPoint s . Count = = 1 ? pc [ i - 1 ] . Y : y - displacementY ;
}
}
else if ( Math . Abs ( 9 0 - Math . Abs ( theta ) ) < snapangle ) //vertical snap
else if ( Math . Abs ( 9 0 - Math . Abs ( theta ) ) < snapangle ) //vertical snap
{
{
//if one point selected use point before as snap point, else snap to movement
//if one point selected use point before as snap point, else snap to movement
x = _ selectedThumb s . Count = = 1 ? pc [ i - 1 ] . X : x - displacementX ;
x = _ selectedPoint s . Count = = 1 ? pc [ i - 1 ] . X : x - displacementX ;
}
}
}
}
}
}
@ -371,7 +369,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public bool InvokeDefaultAction
public bool InvokeDefaultAction
{
{
get { return _ selectedThumb s . Count = = 0 | | _ selectedThumb s . Count = = GetPointCollection ( ) . Count - 1 ; }
get { return _ selectedPoint s . Count = = 0 | | _ selectedPoint s . Count = = GetPointCollection ( ) . Count - 1 ; }
}
}
int _ movingDistance ;
int _ movingDistance ;