<commit_before>﻿<Window x:Class="DynaApp.MainWindow"
        x:Name="mainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="{Binding Path=Title}"
        Height="800" Width="500"
        FocusManager.FocusedElement="{Binding ElementName=modelControl}"
        xmlns:views="clr-namespace:DynaApp.Views"
        xmlns:viewModels="clr-namespace:DynaApp.ViewModels"
        xmlns:controls="clr-namespace:DynaApp.Controls"
        Icon="Images/AppIcon.ico"
        >

    <Window.Resources>
        <ResourceDictionary>

        <!-- UI commands. -->
        <RoutedUICommand x:Key="Commands.DeleteSelectedGraphics" />
        <RoutedUICommand x:Key="Commands.DeleteVariable" />
        <RoutedUICommand x:Key="Commands.DeleteDomain" />
        <RoutedUICommand x:Key="Commands.DeleteConstraint" />

        <!-- 
        Template for the button that is used to delete nodes and connections in the graph.
        This button is displayed in an adorner when the user hovers the mouse over a node or connection.
        -->
        <ControlTemplate 
                x:Key="deleteButtonTemplate"
                TargetType="{x:Type Button}"
                >
            <Grid
                x:Name="grid"
                >
                <Grid.RenderTransform>
                    <ScaleTransform
                        ScaleX="1"
                        ScaleY="1"
                        CenterX="10"
                        CenterY="10"
                        />
                </Grid.RenderTransform>
                <Ellipse
                    x:Name="shadow"
                    VerticalAlignment="Stretch"
                    HorizontalAlignment="Stretch"
                    Fill="Gray"
                    >
                    <Ellipse.RenderTransform>
                        <TranslateTransform
                            X="1.5"
                            Y="1.5"
                            />
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse
                    x:Name="ellipse"
                    Stroke="Black"
                    VerticalAlignment="Stretch"
                    HorizontalAlignment="Stretch"
                    Fill="White"
                    />
                <Image
                    Source="/Images/scissors.png" 
                    Margin="2"
                    />
            </Grid>
            <ControlTemplate.Triggers>
                <EventTrigger
                    RoutedEvent="Mouse.MouseEnter"
                    >
                    <!-- 
                    Make the 'delete connection button' larger when the mouse 
                    cursor is hovered over it.
                    -->
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="grid"
                                Storyboard.TargetProperty="RenderTransform.ScaleX"
                                To="1.3"
                                Duration="0:0:0.25"
                                />
                            <DoubleAnimation
                                Storyboard.TargetName="grid"
                                Storyboard.TargetProperty="RenderTransform.ScaleY"
                                To="1.3"
                                Duration="0:0:0.25"
                                />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>

                <EventTrigger
                        RoutedEvent="Mouse.MouseLeave"
                        >
                    <!-- 
                        Return the 'delete connection button' to normal size when the mouse
                        cursor is moved away.
                        -->
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="grid"
                                Storyboard.TargetProperty="RenderTransform.ScaleX"
                                To="1"
                                Duration="0:0:0.05"
                                />
                            <DoubleAnimation
                                Storyboard.TargetName="grid"
                                Storyboard.TargetProperty="RenderTransform.ScaleY"
                                To="1"
                                Duration="0:0:0.05"
                                />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </ControlTemplate.Triggers>

        </ControlTemplate>

        <DataTemplate DataType="{x:Type viewModels:WorkspaceViewModel}">
            <StackPanel>

                <!-- Workspace mode selector -->
                <ComboBox 
                    x:Name="workspaceViewSelector"
                    ItemsSource="{Binding AvailableDisplayModes}"
                    SelectedItem="{Binding SelectedDisplayMode, Mode=TwoWay}"
                    />

                <ContentPresenter x:Name="contentView" Content="{Binding SelectedDisplayViewModel}"/>

            </StackPanel>
        </DataTemplate>
            
        <DataTemplate DataType="{x:Type viewModels:ModelViewModel}">
            <!--
            The ScrollViewer displays scrollbars when the content is too big to fit in the viewport. 
            Focusable is set to False because it is only that ModelView that I want to be focusable.
            -->
            <ScrollViewer
                x:Name="contentViewer"
                HorizontalScrollBarVisibility="Auto"
                Focusable="False">

                <!--
                We need to nest the ModelView inside an AdornerDecorator so that adorners 
                work correctly.
                -->
                <AdornerDecorator>
                    
                    <views:ModelView 
                        x:Name="modelControl"
                        Width="2000" Height="2000"
                        VariablesSource="{Binding Variables}"
                        DomainsSource="{Binding Domains}"
                        ConstraintsSource="{Binding Constraints}"
                        />

                </AdornerDecorator>

            </ScrollViewer>
        </DataTemplate>

        <DataTemplate DataType="{x:Type viewModels:SolutionViewModel}">
            <ListView x:Name="valuesListBox"
                      ItemsSource="{Binding Values}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Name" 
                                        DisplayMemberBinding="{Binding VariableName}"/>
                        <GridViewColumn Header="Value" 
                                        DisplayMemberBinding="{Binding Value}"/>
                    </GridView>
                </ListView.View>
            </ListView>
        </DataTemplate>

        <!--
        Define the visual style for a 'VariableItem'.
        
        Binds 'X' and 'Y' in the view-model (the 'VariableViewModel' class)
        to 'X' and 'Y' in the VariableItem class.
        
        This sets the position of the variable within the Canvas.
        -->
        <Style TargetType="{x:Type controls:VariableItem}">
            <Setter
                Property="X"
                Value="{Binding X}"
                />
            <Setter
                Property="Y"
                Value="{Binding Y}"
                />
            <Setter
                Property="IsSelected"
                Value="{Binding IsSelected}"
                />
        </Style>

        <!--
        Define the visual style for a DomainItem.
        -->
        <Style TargetType="{x:Type controls:DomainItem}">
            <Setter
                Property="X"
                Value="{Binding X}"
                />
            <Setter
                Property="Y"
                Value="{Binding Y}"
                />
            <Setter
                Property="IsSelected"
                Value="{Binding IsSelected}"
                />
        </Style>

        <!--
        Define the visual style for a ConstraintItem.
        -->
        <Style TargetType="{x:Type controls:ConstraintItem}">
            <Setter
                Property="X"
                Value="{Binding X}"
                />
            <Setter
                Property="Y"
                Value="{Binding Y}"
                />
            <Setter
                Property="IsSelected"
                Value="{Binding IsSelected}"
                />
        </Style>

        <!-- 
        Define a data-template for the 'VariableViewModel' class.
        This generates the UI for each variable.
        -->
        <DataTemplate
            DataType="{x:Type viewModels:VariableViewModel}"
            >

            <Canvas Width="120" Height="60"> 
                <!-- Left hand '<' -->
                <Line
                    X1="0"
                    Y1="30"
                    X2="30"
                    Y2="0"
                    Stroke="Black"
                    StrokeThickness="2"
                    />
                <Line
                    X1="0"
                    Y1="30"
                    X2="30"
                    Y2="60"
                    Stroke="Black"
                    StrokeThickness="2"
                    />

                <!-- Display the variable name -->
                <Viewbox 
                    Stretch="Uniform" 
                    Width="40"
                    Height="50"
                    Canvas.Left="40"
                    Canvas.Top="5"
                    >

                    <!-- The name of the variable. -->
                    <controls:EditableTextBlock
                        Text="{Binding Name, Mode=TwoWay}" 
                        IsInEditMode="{Binding IsNameEditing, Mode=TwoWay}"
                        FontFamily="Courier New"
                        FontWeight="Bold"
                        FontStyle="Italic"
                        />

                </Viewbox>

                <!-- Right hand '>' -->
                <Line
                    X1="120"
                    Y1="30"
                    X2="90"
                    Y2="0"
                    Stroke="Black"
                    StrokeThickness="2"
                    />
                <Line
                    X1="120"
                    Y1="30"
                    X2="90"
                    Y2="60"
                    Stroke="Black"
                    StrokeThickness="2"
                    />

            </Canvas>

        </DataTemplate>

        <!--
        Define a data-template for the DomainExpressionViewModel class.
        -->
        <DataTemplate DataType="{x:Type viewModels:DomainExpressionViewModel}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Name="LeftGraphicRow" Width="20"/>
                    <ColumnDefinition x:Name="DomainExpressionRow" Width="*"/>
                    <ColumnDefinition x:Name="RightGraphicRow" Width="20"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Source="Images/LeftCurlyBracket.png"/>

                <!-- The domain expression text. -->
                <controls:EditableTextBlock
                    Text="{Binding Path=Text, Mode=TwoWay}"
                    IsInEditMode="{Binding IsExpressionEditing, Mode=TwoWay}"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Grid.Column="1"
                    MinWidth="40"
                    MinHeight="50"/>

                <Image Grid.Column="2" Source="Images/RightCurlyBracket.png"/>
            </Grid>
        </DataTemplate>
            
        <!-- 
        Define a data-template for the DomainViewModel class.
        -->
        <DataTemplate DataType="{x:Type viewModels:DomainViewModel}">
            <Canvas Width="120" Height="60">
                <Viewbox
                    Stretch="Uniform" 
                    Width="40"
                    Height="50"
                    Canvas.Left="0"
                    Canvas.Top="0">

                    <!-- The name of the domain. -->
                    <controls:EditableTextBlock
                        x:Name="nameEditor"
                        Text="{Binding Name, Mode=TwoWay}"
                        IsInEditMode="{Binding IsNameEditing, Mode=TwoWay}"
                        FontFamily="Courier New"
                        FontWeight="Bold"
                        FontSize="24"
                        FontStyle="Italic"/>
                </Viewbox>

                <ContentPresenter x:Name="expressionEditor"
                                  Width="100"
                                  Height="50"
                                  Canvas.Left="40"
                                  Canvas.Top="10"
                                  Content="{Binding Expression}"/>
            </Canvas>
        </DataTemplate>

        <!-- 
        Define a data-template for the ConstraintViewModel class.
        This generates the UI for each constraint.
        -->
        <DataTemplate DataType="{x:Type viewModels:ConstraintViewModel}">
            <!-- 
            An adorned control is used, to represent the node. 
            When the user hovers the mouse cursor over the node, the 
            'delete node' adorner pops up and allows them to delete the node.
            -->
            <controls:AdornedControl
                HorizontalAdornerPlacement="Outside"
                VerticalAdornerPlacement="Outside"
                AdornerOffsetX="-12"
                AdornerOffsetY="8"
                IsMouseOverShowEnabled="{Binding ElementName=modelControl, Path=IsNotDragging}"
                >

                <Grid
                    Width="120"
                    Height="60"
                    >

                <!-- This polygon is the main visual for the constraint. -->
                <Polygon
                    Points="0,60 120,60 60,0 0,60"
                    Stroke="Black"
                    Fill="White"
                    />

                <!-- 
                This grid contains the domain's name and connectors.
                The margin is negative so that the connectors overlap the body of the variable and it's selection border.
                -->
                <Grid Margin="-8">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" MinWidth="10" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <!-- The name of the constraint. -->
                    <TextBox
                        Grid.Column="1"
                        Grid.Row="1"
                        FontWeight="Bold"
                        Text="{Binding Name, Mode=TwoWay}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        />

                    <!-- The constraint expression text. -->
                    <TextBox
                        Grid.Column="1"
                        Grid.Row="2"
                        Text="{Binding Path=Expression.Text, Mode=TwoWay}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        />

                </Grid>
            </Grid>

            <controls:AdornedControl.AdornerContent>

                <!-- 
                This is the adorner that pops up when the user hovers the mouse over the variable.
                It displays a button that the user can click to delete the variable.
                -->
                <Canvas
                    x:Name="variableAdornerCanvas"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top"
                    Width="30"
                    Height="30"
                    >
                    <Line
                        X1="0"
                        Y1="30"
                        X2="15"
                        Y2="15"
                        Stroke="Black"
                        StrokeThickness="1"
                        />
                    <Button
                        x:Name="deleteConstraintButton"
                        Canvas.Left="10"
                        Canvas.Top="0"
                        Width="20"
                        Height="20"
                        Cursor="Hand"
                        Focusable="False"
                        Command="{StaticResource Commands.DeleteConstraint}"
                        CommandParameter="{Binding}"
                        Template="{StaticResource deleteButtonTemplate}"
                        />
                    </Canvas>
                </controls:AdornedControl.AdornerContent>
            </controls:AdornedControl>
        </DataTemplate>
            
        </ResourceDictionary>
    </Window.Resources>
    
    <Window.InputBindings>

        <!-- Bind input to commands. -->
        <KeyBinding
			Key="Delete"
			Command="{StaticResource Commands.DeleteSelectedGraphics}" />

    </Window.InputBindings>

    <Window.CommandBindings>

        <!-- Bind commands to event handlers. -->
        <CommandBinding 
            Command="{StaticResource Commands.DeleteSelectedGraphics}" 
            Executed="DeleteSelectedGraphics_Executed" 
            />
        <CommandBinding 
            Command="{StaticResource Commands.DeleteVariable}" 
            Executed="DeleteVariable_Executed" 
            />
        <CommandBinding 
            Command="{StaticResource Commands.DeleteDomain}" 
            Executed="DeleteDomain_Executed" 
            />
        <CommandBinding 
            Command="{StaticResource Commands.DeleteConstraint}" 
            Executed="DeleteConstraint_Executed" 
            />

    </Window.CommandBindings>

    <Window.ContextMenu>

        <ContextMenu>

            <MenuItem
                Header="Create Variable"
                Command="{Binding AddVariableCommand}"
                ToolTip="Create a new variable" />

        </ContextMenu>

    </Window.ContextMenu>

    <Window.DataContext>
        <viewModels:MainWindowViewModel />
    </Window.DataContext>

    <DockPanel LastChildFill="True">

        <Menu DockPanel.Dock="Top">
            <MenuItem Header="File">
                <MenuItem Header="New" Command="{Binding NewCommand}">
                    <MenuItem.Icon>
                        <Image Source="Images/Transparent.png"  />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Open" Command="{Binding OpenCommand}">
                    <MenuItem.Icon>
                        <Image Source="Images/Transparent.png"  />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Save" Command="{Binding SaveCommand}">
                    <MenuItem.Icon>
                        <Image Source="Images/Transparent.png"  />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Save As..." Command="{Binding SaveAsCommand}">
                    <MenuItem.Icon>
                        <Image Source="Images/Transparent.png"  />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Exit" Command="{Binding ExitCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
            <MenuItem Header="Edit">
            </MenuItem>
            <MenuItem Header="Model">
                <MenuItem Header="Solve..." Command="{Binding SolveCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Add Variable" Command="{Binding AddVariableCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Add Constraint" Command="{Binding AddConstraintCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Add Domain" Command="{Binding AddDomainCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>

        <ContentPresenter x:Name="workspaceView" Content="{Binding Workspace}"/>
    </DockPanel>
</Window>
<commit_msg>Converts the domain graphic to use a grid for layout.<commit_after>﻿<Window x:Class="DynaApp.MainWindow"
        x:Name="mainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="{Binding Path=Title}"
        Height="800" Width="500"
        FocusManager.FocusedElement="{Binding ElementName=modelControl}"
        xmlns:views="clr-namespace:DynaApp.Views"
        xmlns:viewModels="clr-namespace:DynaApp.ViewModels"
        xmlns:controls="clr-namespace:DynaApp.Controls"
        Icon="Images/AppIcon.ico"
        >

    <Window.Resources>
        <ResourceDictionary>

        <!-- UI commands. -->
        <RoutedUICommand x:Key="Commands.DeleteSelectedGraphics" />
        <RoutedUICommand x:Key="Commands.DeleteVariable" />
        <RoutedUICommand x:Key="Commands.DeleteDomain" />
        <RoutedUICommand x:Key="Commands.DeleteConstraint" />

        <!-- 
        Template for the button that is used to delete nodes and connections in the graph.
        This button is displayed in an adorner when the user hovers the mouse over a node or connection.
        -->
        <ControlTemplate 
                x:Key="deleteButtonTemplate"
                TargetType="{x:Type Button}"
                >
            <Grid
                x:Name="grid"
                >
                <Grid.RenderTransform>
                    <ScaleTransform
                        ScaleX="1"
                        ScaleY="1"
                        CenterX="10"
                        CenterY="10"
                        />
                </Grid.RenderTransform>
                <Ellipse
                    x:Name="shadow"
                    VerticalAlignment="Stretch"
                    HorizontalAlignment="Stretch"
                    Fill="Gray"
                    >
                    <Ellipse.RenderTransform>
                        <TranslateTransform
                            X="1.5"
                            Y="1.5"
                            />
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse
                    x:Name="ellipse"
                    Stroke="Black"
                    VerticalAlignment="Stretch"
                    HorizontalAlignment="Stretch"
                    Fill="White"
                    />
                <Image
                    Source="/Images/scissors.png" 
                    Margin="2"
                    />
            </Grid>
            <ControlTemplate.Triggers>
                <EventTrigger
                    RoutedEvent="Mouse.MouseEnter"
                    >
                    <!-- 
                    Make the 'delete connection button' larger when the mouse 
                    cursor is hovered over it.
                    -->
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="grid"
                                Storyboard.TargetProperty="RenderTransform.ScaleX"
                                To="1.3"
                                Duration="0:0:0.25"
                                />
                            <DoubleAnimation
                                Storyboard.TargetName="grid"
                                Storyboard.TargetProperty="RenderTransform.ScaleY"
                                To="1.3"
                                Duration="0:0:0.25"
                                />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>

                <EventTrigger
                        RoutedEvent="Mouse.MouseLeave"
                        >
                    <!-- 
                        Return the 'delete connection button' to normal size when the mouse
                        cursor is moved away.
                        -->
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="grid"
                                Storyboard.TargetProperty="RenderTransform.ScaleX"
                                To="1"
                                Duration="0:0:0.05"
                                />
                            <DoubleAnimation
                                Storyboard.TargetName="grid"
                                Storyboard.TargetProperty="RenderTransform.ScaleY"
                                To="1"
                                Duration="0:0:0.05"
                                />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </ControlTemplate.Triggers>

        </ControlTemplate>

        <DataTemplate DataType="{x:Type viewModels:WorkspaceViewModel}">
            <StackPanel>

                <!-- Workspace mode selector -->
                <ComboBox 
                    x:Name="workspaceViewSelector"
                    ItemsSource="{Binding AvailableDisplayModes}"
                    SelectedItem="{Binding SelectedDisplayMode, Mode=TwoWay}"
                    />

                <ContentPresenter x:Name="contentView" 
                                  Content="{Binding SelectedDisplayViewModel}"/>

            </StackPanel>
        </DataTemplate>
            
        <DataTemplate DataType="{x:Type viewModels:ModelViewModel}">
            <!--
            The ScrollViewer displays scrollbars when the content is too big to fit in the viewport. 
            Focusable is set to False because it is only that ModelView that I want to be focusable.
            -->
            <ScrollViewer
                x:Name="contentViewer"
                HorizontalScrollBarVisibility="Auto"
                Focusable="False">

                <!--
                We need to nest the ModelView inside an AdornerDecorator so that adorners 
                work correctly.
                -->
                <AdornerDecorator>
                    
                    <views:ModelView 
                        x:Name="modelControl"
                        Width="2000" Height="2000"
                        VariablesSource="{Binding Variables}"
                        DomainsSource="{Binding Domains}"
                        ConstraintsSource="{Binding Constraints}"
                        />

                </AdornerDecorator>

            </ScrollViewer>
        </DataTemplate>

        <DataTemplate DataType="{x:Type viewModels:SolutionViewModel}">
            <ListView x:Name="valuesListBox"
                      ItemsSource="{Binding Values}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Name" 
                                        DisplayMemberBinding="{Binding VariableName}"/>
                        <GridViewColumn Header="Value" 
                                        DisplayMemberBinding="{Binding Value}"/>
                    </GridView>
                </ListView.View>
            </ListView>
        </DataTemplate>

        <!--
        Define the visual style for a 'VariableItem'.
        
        Binds 'X' and 'Y' in the view-model (the 'VariableViewModel' class)
        to 'X' and 'Y' in the VariableItem class.
        
        This sets the position of the variable within the Canvas.
        -->
        <Style TargetType="{x:Type controls:VariableItem}">
            <Setter
                Property="X"
                Value="{Binding X}"
                />
            <Setter
                Property="Y"
                Value="{Binding Y}"
                />
            <Setter
                Property="IsSelected"
                Value="{Binding IsSelected}"
                />
        </Style>

        <!--
        Define the visual style for a DomainItem.
        -->
        <Style TargetType="{x:Type controls:DomainItem}">
            <Setter
                Property="X"
                Value="{Binding X}"
                />
            <Setter
                Property="Y"
                Value="{Binding Y}"
                />
            <Setter
                Property="IsSelected"
                Value="{Binding IsSelected}"
                />
        </Style>

        <!--
        Define the visual style for a ConstraintItem.
        -->
        <Style TargetType="{x:Type controls:ConstraintItem}">
            <Setter
                Property="X"
                Value="{Binding X}"
                />
            <Setter
                Property="Y"
                Value="{Binding Y}"
                />
            <Setter
                Property="IsSelected"
                Value="{Binding IsSelected}"
                />
        </Style>

        <!-- 
        Define a data-template for the 'VariableViewModel' class.
        This generates the UI for each variable.
        -->
        <DataTemplate
            DataType="{x:Type viewModels:VariableViewModel}"
            >

            <Canvas Width="120" Height="60"> 
                <!-- Left hand '<' -->
                <Line
                    X1="0"
                    Y1="30"
                    X2="30"
                    Y2="0"
                    Stroke="Black"
                    StrokeThickness="2"
                    />
                <Line
                    X1="0"
                    Y1="30"
                    X2="30"
                    Y2="60"
                    Stroke="Black"
                    StrokeThickness="2"
                    />

                <!-- Display the variable name -->
                <Viewbox 
                    Stretch="Uniform" 
                    Width="40"
                    Height="50"
                    Canvas.Left="40"
                    Canvas.Top="5"
                    >

                    <!-- The name of the variable. -->
                    <controls:EditableTextBlock
                        Text="{Binding Name, Mode=TwoWay}" 
                        IsInEditMode="{Binding IsNameEditing, Mode=TwoWay}"
                        FontFamily="Courier New"
                        FontWeight="Bold"
                        FontStyle="Italic"
                        />

                </Viewbox>

                <!-- Right hand '>' -->
                <Line
                    X1="120"
                    Y1="30"
                    X2="90"
                    Y2="0"
                    Stroke="Black"
                    StrokeThickness="2"
                    />
                <Line
                    X1="120"
                    Y1="30"
                    X2="90"
                    Y2="60"
                    Stroke="Black"
                    StrokeThickness="2"
                    />

            </Canvas>

        </DataTemplate>

        <!--
        Define a data-template for the DomainExpressionViewModel class.
        -->
        <DataTemplate DataType="{x:Type viewModels:DomainExpressionViewModel}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Name="LeftGraphicRow" Width="20"/>
                    <ColumnDefinition x:Name="DomainExpressionRow" Width="*"/>
                    <ColumnDefinition x:Name="RightGraphicRow" Width="20"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Source="Images/LeftCurlyBracket.png"/>

                <!-- The domain expression text. -->
                <controls:EditableTextBlock
                    Text="{Binding Path=Text, Mode=TwoWay}"
                    IsInEditMode="{Binding IsExpressionEditing, Mode=TwoWay}"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Grid.Column="1"
                    MinWidth="40"
                    MinHeight="50"/>

                <Image Grid.Column="2" Source="Images/RightCurlyBracket.png"/>
            </Grid>
        </DataTemplate>
            
        <!-- 
        Define a data-template for the DomainViewModel class.
        -->
        <DataTemplate DataType="{x:Type viewModels:DomainViewModel}">
            <Grid Width="120" Height="60">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Name="DomainNameRow" Width="40"/>
                    <ColumnDefinition x:Name="DomainExpressionRow" Width="*"/>
                </Grid.ColumnDefinitions>

                <!-- The name of the domain. -->
                <controls:EditableTextBlock
                    x:Name="nameEditor"
                    Text="{Binding Name, Mode=TwoWay}"
                    IsInEditMode="{Binding IsNameEditing, Mode=TwoWay}"
                    FontFamily="Courier New"
                    FontWeight="Bold"
                    FontSize="24"
                    FontStyle="Italic"/>

                <ContentPresenter x:Name="expressionEditor"
                                  Grid.Column="1"
                                  Content="{Binding Expression}"/>
            </Grid>
        </DataTemplate>

        <!-- 
        Define a data-template for the ConstraintViewModel class.
        This generates the UI for each constraint.
        -->
        <DataTemplate DataType="{x:Type viewModels:ConstraintViewModel}">
            <!-- 
            An adorned control is used, to represent the node. 
            When the user hovers the mouse cursor over the node, the 
            'delete node' adorner pops up and allows them to delete the node.
            -->
            <controls:AdornedControl
                HorizontalAdornerPlacement="Outside"
                VerticalAdornerPlacement="Outside"
                AdornerOffsetX="-12"
                AdornerOffsetY="8"
                IsMouseOverShowEnabled="{Binding ElementName=modelControl, Path=IsNotDragging}"
                >

                <Grid
                    Width="120"
                    Height="60"
                    >

                <!-- This polygon is the main visual for the constraint. -->
                <Polygon
                    Points="0,60 120,60 60,0 0,60"
                    Stroke="Black"
                    Fill="White"
                    />

                <!-- 
                This grid contains the domain's name and connectors.
                The margin is negative so that the connectors overlap the body of the variable and it's selection border.
                -->
                <Grid Margin="-8">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" MinWidth="10" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <!-- The name of the constraint. -->
                    <TextBox
                        Grid.Column="1"
                        Grid.Row="1"
                        FontWeight="Bold"
                        Text="{Binding Name, Mode=TwoWay}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        />

                    <!-- The constraint expression text. -->
                    <TextBox
                        Grid.Column="1"
                        Grid.Row="2"
                        Text="{Binding Path=Expression.Text, Mode=TwoWay}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        />

                </Grid>
            </Grid>

            <controls:AdornedControl.AdornerContent>

                <!-- 
                This is the adorner that pops up when the user hovers the mouse over the variable.
                It displays a button that the user can click to delete the variable.
                -->
                <Canvas
                    x:Name="variableAdornerCanvas"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top"
                    Width="30"
                    Height="30"
                    >
                    <Line
                        X1="0"
                        Y1="30"
                        X2="15"
                        Y2="15"
                        Stroke="Black"
                        StrokeThickness="1"
                        />
                    <Button
                        x:Name="deleteConstraintButton"
                        Canvas.Left="10"
                        Canvas.Top="0"
                        Width="20"
                        Height="20"
                        Cursor="Hand"
                        Focusable="False"
                        Command="{StaticResource Commands.DeleteConstraint}"
                        CommandParameter="{Binding}"
                        Template="{StaticResource deleteButtonTemplate}"
                        />
                    </Canvas>
                </controls:AdornedControl.AdornerContent>
            </controls:AdornedControl>
        </DataTemplate>
            
        </ResourceDictionary>
    </Window.Resources>
    
    <Window.InputBindings>

        <!-- Bind input to commands. -->
        <KeyBinding
			Key="Delete"
			Command="{StaticResource Commands.DeleteSelectedGraphics}" />

    </Window.InputBindings>

    <Window.CommandBindings>

        <!-- Bind commands to event handlers. -->
        <CommandBinding 
            Command="{StaticResource Commands.DeleteSelectedGraphics}" 
            Executed="DeleteSelectedGraphics_Executed" 
            />
        <CommandBinding 
            Command="{StaticResource Commands.DeleteVariable}" 
            Executed="DeleteVariable_Executed" 
            />
        <CommandBinding 
            Command="{StaticResource Commands.DeleteDomain}" 
            Executed="DeleteDomain_Executed" 
            />
        <CommandBinding 
            Command="{StaticResource Commands.DeleteConstraint}" 
            Executed="DeleteConstraint_Executed" 
            />

    </Window.CommandBindings>

    <Window.ContextMenu>

        <ContextMenu>

            <MenuItem
                Header="Create Variable"
                Command="{Binding AddVariableCommand}"
                ToolTip="Create a new variable" />

        </ContextMenu>

    </Window.ContextMenu>

    <Window.DataContext>
        <viewModels:MainWindowViewModel />
    </Window.DataContext>

    <DockPanel LastChildFill="True">

        <Menu DockPanel.Dock="Top">
            <MenuItem Header="File">
                <MenuItem Header="New" Command="{Binding NewCommand}">
                    <MenuItem.Icon>
                        <Image Source="Images/Transparent.png"  />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Open" Command="{Binding OpenCommand}">
                    <MenuItem.Icon>
                        <Image Source="Images/Transparent.png"  />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Save" Command="{Binding SaveCommand}">
                    <MenuItem.Icon>
                        <Image Source="Images/Transparent.png"  />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Save As..." Command="{Binding SaveAsCommand}">
                    <MenuItem.Icon>
                        <Image Source="Images/Transparent.png"  />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Exit" Command="{Binding ExitCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
            <MenuItem Header="Edit">
            </MenuItem>
            <MenuItem Header="Model">
                <MenuItem Header="Solve..." Command="{Binding SolveCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Add Variable" Command="{Binding AddVariableCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Add Constraint" Command="{Binding AddConstraintCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Add Domain" Command="{Binding AddDomainCommand}">
                    <MenuItem.Icon>
                        <Image Source="/Images/Transparent.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>

        <ContentPresenter x:Name="workspaceView" Content="{Binding Workspace}"/>
    </DockPanel>
</Window>

{'fraction_non_alphanumeric': 0.09194699286442405, 'fraction_numerical': 0.009061048816400498, 'mean_word_length': 0.9802628627820392, 'pattern_counts': {'":': 0, '<': 489, '<?xml version=': 0, '>': 489, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4198851', 'n_tokens_mistral': 10844, 'n_tokens_neox': 8931, 'n_words': 1821}