This commit is contained in:
Wiesław Šoltés 2015-08-09 15:28:03 +02:00
Родитель c8a49dfecf
Коммит a03f81c1a1
5 изменённых файлов: 176 добавлений и 106 удалений

Просмотреть файл

@ -46,15 +46,12 @@ namespace SpiroNet.Editor
private SpiroPointType _pointType;
private GuidePoint _guidePosition;
private GuidePoint _point0;
private GuidePoint _point1;
private bool _isCaptured;
private double _snapTreshold;
private GuideSnapMode _snapMode;
private double _snapPointRadius;
private GuidePoint _snapPoint;
private bool _haveSnapPoint;
private GuideSnapMode _snapResult;
public EditorState()
{
@ -195,18 +192,6 @@ namespace SpiroNet.Editor
set { Update(ref _guidePosition, value); }
}
public GuidePoint Point0
{
get { return _point0; }
set { Update(ref _point0, value); }
}
public GuidePoint Point1
{
get { return _point1; }
set { Update(ref _point1, value); }
}
public bool IsCaptured
{
get { return _isCaptured; }
@ -242,11 +227,5 @@ namespace SpiroNet.Editor
get { return _haveSnapPoint; }
set { Update(ref _haveSnapPoint, value); }
}
public GuideSnapMode SnapResult
{
get { return _snapResult; }
set { Update(ref _snapResult, value); }
}
}
}

Просмотреть файл

@ -30,6 +30,7 @@ namespace SpiroNet.Editor
public class SpiroEditor : ObservableObject
{
private EditorState _state = null;
private EditorMeasure _measure;
private EditorCommands _commands = null;
private Action _invalidate = null;
private Action _capture = null;
@ -46,6 +47,12 @@ namespace SpiroNet.Editor
set { Update(ref _state, value); }
}
public EditorMeasure Measure
{
get { return _measure; }
set { Update(ref _measure, value); }
}
public EditorCommands Commands
{
get { return _commands; }
@ -632,12 +639,12 @@ namespace SpiroNet.Editor
_drawing.Guides,
_state.SnapMode,
_state.SnapTreshold,
_state.Point1,
_measure.Point1,
out snapPoint,
out snapResult);
_state.SnapPoint = snapPoint;
_state.SnapResult = snapResult;
_measure.SnapResult = snapResult;
}
private bool HitTestForGuideLine(IList<GuideLine> guides, double x, double y, double treshold, out GuideLine hitGuide)
@ -675,33 +682,33 @@ namespace SpiroNet.Editor
if (_state.IsCaptured)
{
_state.Point1 = new GuidePoint(sx, sy);
_measure.Point1 = new GuidePoint(sx, sy);
TryToSnapToGuideLine();
if (_state.HaveSnapPoint)
{
_state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_state.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_measure.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
}
_state.IsCaptured = false;
_release();
_drawing.Guides.Add(new GuideLine(_state.Point0, _state.Point1));
_drawing.Guides.Add(new GuideLine(_measure.Point0, _measure.Point1));
_invalidate();
}
else
{
_state.Point0 = new GuidePoint(sx, sy);
_state.Point1 = new GuidePoint(sx, sy);
_measure.Point0 = new GuidePoint(sx, sy);
_measure.Point1 = new GuidePoint(sx, sy);
TryToSnapToGuideLine();
if (_state.HaveSnapPoint)
{
_state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_state.Point0 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_state.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_measure.Point0 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_measure.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
}
_state.IsCaptured = true;
@ -724,6 +731,15 @@ namespace SpiroNet.Editor
public void GuideRightDown(double x, double y)
{
double sx = _state.EnableSnap && _state.SnapX != 0 ? Snap(x, _state.SnapX) : x;
double sy = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;
_measure.Point0 = new GuidePoint(sx, sy);
_measure.Point1 = new GuidePoint(sx, sy);
_measure.Distance = 0.0;
_measure.Angle = 0.0;
_measure.SnapResult = GuideSnapMode.None;
_state.IsCaptured = false;
_release();
_invalidate();
@ -735,25 +751,19 @@ namespace SpiroNet.Editor
double sy = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;
_state.GuidePosition = new GuidePoint(sx, sy);
_state.Point1 = new GuidePoint(sx, sy);
_measure.Point1 = new GuidePoint(sx, sy);
TryToSnapToGuideLine();
if (_state.HaveSnapPoint)
{
_state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_state.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_measure.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
}
#if DEBUG
double distance = GuideHelpers.Distance(_state.Point0, _state.Point1);
double angle = GuideHelpers.LineSegmentAngle(_state.Point0, _state.Point1);
Debug.Print("X: {0} Y: {1} D: {2} A: {3}, S: {4}",
_state.Point1.X,
_state.Point1.Y,
distance,
angle,
_state.SnapResult);
#endif
_measure.Distance = GuideHelpers.Distance(_measure.Point0, _measure.Point1);
_measure.Angle = GuideHelpers.LineSegmentAngle(_measure.Point0, _measure.Point1);
_invalidate();
}
@ -765,18 +775,30 @@ namespace SpiroNet.Editor
if (_state.EnableSnap)
{
_state.GuidePosition = new GuidePoint(sx, sy);
_state.Point1 = new GuidePoint(x, y);
if (_state.Shape == null)
_measure.Point0 = new GuidePoint(x, y);
_measure.Point1 = new GuidePoint(x, y);
TryToSnapToGuideLine();
if (_state.HaveSnapPoint)
{
_state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_state.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_measure.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
sx = _state.SnapPoint.X;
sy = _state.SnapPoint.Y;
}
if (_state.Shape == null)
_measure.Point0 = new GuidePoint(sx, sy);
_measure.Point1 = new GuidePoint(sx, sy);
_measure.Distance = GuideHelpers.Distance(_measure.Point0, _measure.Point1);
_measure.Angle = GuideHelpers.LineSegmentAngle(_measure.Point0, _measure.Point1);
}
_startX = sx;
@ -842,18 +864,11 @@ namespace SpiroNet.Editor
if (_state.EnableSnap)
{
_state.Point1 = new GuidePoint(x, y);
TryToSnapToGuideLine();
if (_state.HaveSnapPoint)
{
_state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_state.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
sx = _state.SnapPoint.X;
sy = _state.SnapPoint.Y;
}
_measure.Point0 = new GuidePoint(sx, sy);
_measure.Point1 = new GuidePoint(sx, sy);
_measure.Distance = 0.0;
_measure.Angle = 0.0;
_measure.SnapResult = GuideSnapMode.None;
}
if (_state.Shape != null)
@ -888,18 +903,23 @@ namespace SpiroNet.Editor
if (_state.EnableSnap)
{
_state.GuidePosition = new GuidePoint(sx, sy);
_state.Point1 = new GuidePoint(x, y);
_measure.Point1 = new GuidePoint(x, y);
TryToSnapToGuideLine();
if (_state.HaveSnapPoint)
{
_state.GuidePosition = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_state.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
_measure.Point1 = new GuidePoint(_state.SnapPoint.X, _state.SnapPoint.Y);
sx = _state.SnapPoint.X;
sy = _state.SnapPoint.Y;
}
_measure.Point1 = new GuidePoint(sx, sy);
_measure.Distance = GuideHelpers.Distance(_measure.Point0, _measure.Point1);
_measure.Angle = GuideHelpers.LineSegmentAngle(_measure.Point0, _measure.Point1);
}
if (_state.Shape != null)
@ -976,6 +996,10 @@ namespace SpiroNet.Editor
_invalidate();
}
}
else if (_state.Mode == EditorMode.Selected)
{
_invalidate();
}
}
}

Просмотреть файл

@ -46,6 +46,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Contexts\PsBezierContext.cs" />
<Compile Include="Editor\EditorMeasure.cs" />
<Compile Include="Editor\SpiroEditor.cs" />
<Compile Include="Editor\EditorTool.cs" />
<Compile Include="Editor\SpiroKnot.cs" />

Просмотреть файл

@ -48,9 +48,9 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="180"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<Menu Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" Background="{x:Null}">
<MenuItem Header="_File">
@ -65,50 +65,113 @@
<MenuItem Command="{Binding Commands.ExitCommand}" Header="E_xit" InputGestureText="Alt+F4"/>
</MenuItem>
</Menu>
<Grid Width="160"
Grid.Column="0"
Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListBox x:Name="shapesListBox"
ItemsSource="{Binding Drawing.Shapes}"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
BorderBrush="{x:Null}"
BorderThickness="0"
Margin="4,4,4,2"
Grid.Row="0">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="Shape"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox x:Name="dataTextBox"
AcceptsReturn="True"
AcceptsTab="True"
IsReadOnly="True"
BorderBrush="{x:Null}"
BorderThickness="0"
Height="240"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
Margin="4,2,4,4"
Grid.Row="1">
<TextBox.Text>
<MultiBinding Converter="{StaticResource ShapeToDataConverterKey}" FallbackValue="{x:Null}">
<Binding ElementName="shapesListBox" Path="SelectedItem" FallbackValue="{x:Null}"/>
<Binding Path="Data" FallbackValue="{x:Null}"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
</Grid>
<TabControl Grid.Column="0" Grid.Row="1" Margin="4,4,4,4">
<TabItem Header="Shapes">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListBox x:Name="shapesListBox"
ItemsSource="{Binding Drawing.Shapes}"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Margin="4,4,4,4"
Grid.Row="0">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="Shape"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox x:Name="dataTextBox"
AcceptsReturn="True"
AcceptsTab="True"
IsReadOnly="True"
Height="240"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
Margin="4,4,4,4"
Grid.Row="1">
<TextBox.Text>
<MultiBinding Converter="{StaticResource ShapeToDataConverterKey}" FallbackValue="{x:Null}">
<Binding ElementName="shapesListBox" Path="SelectedItem" FallbackValue="{x:Null}"/>
<Binding Path="Data" FallbackValue="{x:Null}"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
</Grid>
</TabItem>
<TabItem Header="Guides">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListBox x:Name="guidesListBox"
ItemsSource="{Binding Drawing.Guides}"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Margin="4,4,4,4">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="Guide"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</TabItem>
<TabItem Header="Measure">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<StackPanel Margin="4">
<TextBlock Text="Point0:" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBox Text="{Binding Measure.Point0, Mode=OneWay}"
TextAlignment="Center"
IsReadOnly="True"
BorderBrush="{x:Null}"
BorderThickness="0"
Margin="4,0,4,0">
</TextBox>
<TextBlock Text="Point1:" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBox Text="{Binding Measure.Point1, Mode=OneWay}"
TextAlignment="Center"
IsReadOnly="True"
BorderBrush="{x:Null}"
BorderThickness="0"
Margin="4,0,4,0">
</TextBox>
<TextBlock Text="Distance:" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBox Text="{Binding Measure.Distance, Mode=OneWay}"
TextAlignment="Center"
IsReadOnly="True"
BorderBrush="{x:Null}"
BorderThickness="0"
Margin="4,0,4,0">
</TextBox>
<TextBlock Text="Angle:" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBox Text="{Binding Measure.Angle, Mode=OneWay}"
TextAlignment="Center"
IsReadOnly="True"
BorderBrush="{x:Null}"
BorderThickness="0"
Margin="4,0,4,0">
</TextBox>
<TextBlock Text="SnapResult:" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBox Text="{Binding Measure.SnapResult, Mode=OneWay}"
TextAlignment="Center"
IsReadOnly="True"
BorderBrush="{x:Null}"
BorderThickness="0"
Margin="4,0,4,0">
</TextBox>
</StackPanel>
</ScrollViewer>
</TabItem>
</TabControl>
<ScrollViewer VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
Grid.Column="1"
Grid.Row="1">
Grid.Row="1"
Margin="0,4,0,4">
<local:EditorCanvas x:Name="canvas"
SpiroEditor="{Binding}"
Width="{Binding Drawing.Width}"
@ -132,7 +195,7 @@
</local:EditorCanvas.InputBindings>
</local:EditorCanvas>
</ScrollViewer>
<TabControl Grid.Column="2" Grid.Row="1" Width="200" Margin="4,0,4,4">
<TabControl Grid.Column="2" Grid.Row="1" Margin="4,4,4,4">
<TabItem Header="State">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<StackPanel>
@ -419,7 +482,7 @@
IsReadOnly="False"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
Margin="4,4,4,0"
Margin="4,4,4,4"
Grid.Row="0">
</TextBox>
<Button Content="Run" Command="{Binding Commands.ExecuteScriptCommand}"
@ -443,15 +506,17 @@
<TextBlock Text="Mouse Right" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Finish Shape" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Insert Point" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Reset Measure" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="Mouse Middle:" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Remove Shape" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Remove Point" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="Guide Tool" FontWeight="Bold" TextAlignment="Center" Margin="4,0,4,0"/>
<TextBlock Text="Mouse Left:" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Begin Line" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Finish Line" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Begin Guide" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Finish Guide" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="Mouse Right" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Cancel Shape" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Cancel Guide" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Reset Measure" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="Mouse Middle:" TextAlignment="Left" Margin="4,0,4,0"/>
<TextBlock Text="- Remove Guide" TextAlignment="Left" Margin="4,0,4,0"/>
</StackPanel>

Просмотреть файл

@ -50,6 +50,7 @@ namespace SpiroNet.Wpf
_editor = new SpiroEditor()
{
State = new EditorState(),
Measure = new EditorMeasure(),
Commands = new EditorCommands(),
Invalidate = () => canvas.InvalidateVisual(),
Capture = () => canvas.CaptureMouse(),