Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DYN-7923] CurveMapper node #15745

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// to distinguish one build from another. AssemblyFileVersion is specified
// in AssemblyVersionInfo.cs so that it can be easily incremented by the
// automated build process.
[assembly: AssemblyVersion("3.5.0.6885")]
[assembly: AssemblyVersion("3.5.0.7373")]


// By default, the "Product version" shown in the file properties window is
Expand All @@ -64,4 +64,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("3.5.0.6885")]
[assembly: AssemblyFileVersion("3.5.0.7373")]
82 changes: 82 additions & 0 deletions src/DynamoCoreWpf/Controls/CurveMapperControlPoint.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<Thumb x:Class="Dynamo.Wpf.Controls.CurveMapperControlPoint"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf"
xmlns:local="clr-namespace:Dynamo.Wpf.Controls"
d:DesignHeight="12"
d:DesignWidth="12"
DragCompleted="Thumb_DragCompleted"
DragDelta="Thumb_DragDelta"
DragStarted="Thumb_DragStarted"
mc:Ignorable="d">
<Thumb.Resources>
<local:HalfWidthConverter x:Key="HalfWidthConverter" />
<Style x:Key="GenericToolTipLight" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="MaxWidth" Value="300" />
<Setter Property="HorizontalOffset"
Value="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource HalfWidthConverter}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Grid x:Name="PopupGrid">
<Grid x:Name="ShadowBackground" Background="Transparent">
<Path Width="20"
Height="6"
Margin="5,0,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Data="M0,6 L6,0 12,6Z"
Fill="White"
Stretch="None"
Stroke="Gray" />
<Border Margin="16,5,9,0"
Padding="10,8"
Background="white"
BorderBrush="#999999"
BorderThickness="1,0,1,1"
CornerRadius="3">
<ContentPresenter />
</Border>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="ContentPresenter">
<Style.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementRegular}" />
<Setter Property="FontSize" Value="12px" />
<Setter Property="Foreground" Value="#232323" />
</Style>
</Style.Resources>
</Style>
</Style.Resources>
</Style>
</Thumb.Resources>

<Thumb.Template>
<ControlTemplate>
<Ellipse Width="12"
Height="12"
Fill="#ffffff"
Stroke="#B385F2"
StrokeThickness="3">
<Ellipse.ToolTip>
<ToolTip Style="{StaticResource GenericToolTipLight}">
<StackPanel>
<TextBlock FontWeight="Bold">Control Point (10, 10)</TextBlock>
<!-- Show the actual values (scaled to inputs)-->
<TextBlock>Drag to modify the curve.</TextBlock>
</StackPanel>
</ToolTip>
</Ellipse.ToolTip>
</Ellipse>
</ControlTemplate>
</Thumb.Template>
</Thumb>
161 changes: 161 additions & 0 deletions src/DynamoCoreWpf/Controls/CurveMapperControlPoint.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using Dynamo.Wpf.Controls.SubControls;
using Newtonsoft.Json;
using System.Globalization;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace Dynamo.Wpf.Controls
{
/// <summary>
/// Interaction logic for CurveMapperControlPoint.xaml
/// </summary>
public partial class CurveMapperControlPoint : Thumb
{
private const double offsetValue = 6; // thumb size * 0.5
public CrossHair CrossHairHorizontal { get; set; }
public CrossHair CrossHairVertical { get; set; }
public UVCoordText uvText { get; set; }

public double LimitWidth { get; set; }
public double LimitHeight { get; set; }

private Point point;
[JsonIgnore]
public Point Point
{
get { return point; }
set
{
if (point != value)
{
point = value;
Canvas.SetLeft(this, point.X - offsetValue);
Canvas.SetTop(this, point.Y - offsetValue);
}
}
}

public CurveLinear CurveLinear { get; set; }
// add Bezier here...

/// <summary>
/// Initializes a control point with a specific position, movement boundaries, and a high z-index for canvas rendering.
/// </summary>
/// <param name="position"></param>
/// <param name="limitWidth"></param>
/// <param name="limitHeight"></param>
public CurveMapperControlPoint(Point position, double limitWidth, double limitHeight)
{
InitializeComponent();

Point = position;

Canvas.SetLeft(this, position.X - offsetValue);
Canvas.SetTop(this, position.Y - offsetValue);

LimitWidth = limitWidth;
LimitHeight = limitHeight;

Canvas.SetZIndex(this, 1000);
}

private void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
{
// Calculate new positions for X and Y based on drag changes
double newX = Canvas.GetLeft(this) + e.HorizontalChange + offsetValue;
double newY = Canvas.GetTop(this) + e.VerticalChange + offsetValue;

// Clamp X position within boundaries
if (newX < 0)
{
newX = 0;
}
else if (newX > LimitWidth)
{
newX = LimitWidth;
}

// Clamp Y position within boundaries
if (newY < 0)
{
newY = 0;
}
else if (newY > LimitHeight)
{
newY = LimitHeight;
}

// Update the logical position
Point = new Point(newX, newY);

// Update the visual position on the canvas
Canvas.SetLeft(this, newX - offsetValue);
Canvas.SetTop(this, newY - offsetValue);

// Regenerate associated linear curve if applicable
if (CurveLinear != null)
{
CurveLinear.Regenerate();
}

//// Additional regenerations (commented out for now)
//if (clinebez != null)
//{
// clinebez.Regenerate(this);
//}
//if (curvebez != null)
//{
// curvebez.Regenerate(this);
//}

// Regenerate associated horizontal and vertical crossHairs
if (CrossHairHorizontal != null)
{
CrossHairHorizontal.Regenerate(this);
}
if (CrossHairVertical != null)
{
CrossHairVertical.Regenerate(this);
}

// Regenerate associated UV text display
if (uvText != null)
{
uvText.Regenerate(Point);
}
}

private void Thumb_DragStarted(object sender, DragStartedEventArgs e)
{
}

private void Thumb_DragCompleted(object sender, DragCompletedEventArgs e)
{
}

public override string ToString()
{
return Point.X.ToString() + "," + Point.Y.ToString();
}
}

public class HalfWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double width)
{
return -width / 2; // Negative to offset correctly
}
return DependencyProperty.UnsetValue;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Loading
Loading