Commits

Anonymous committed 81537b7

Got drag and drop working for adding new cells.

Comments (0)

Files changed (13)

UserProjects/sprucely/CSharp/Composer/Composer/Graph/CellType.cs

 		public virtual int Id { get; set; }
 
 		public virtual string Name { get; set; }
+		public virtual string Description { get; set; }
 		public virtual CellCategory CellCategory { get; set; }
 
 	}

UserProjects/sprucely/CSharp/Composer/Composer/Graph/ComponentDefinition.cs

 
 		public virtual Guid Id { get; set; }
 		public virtual string Name { get; set; }
+		public virtual string Description { get; set; }
 
 		public virtual IList<VertexBase> ChildVertices { get; private set; }
 

UserProjects/sprucely/CSharp/Composer/Composer/Graph/Initialization/CellTypes.cs

 		public static readonly ReadOnlyDictionary<string, CellType> MapNameToCellType
 			= new ReadOnlyDictionary<string, CellType>(_mapNameToCellType);
 
-		public static readonly CellType Undefined = CreateCellType(() => Undefined, (CellCategory)0);
-		public static readonly CellType Effector_Message = CreateEffectorType(() => Effector_Message);
+		public static readonly CellType Undefined = 
+			CreateCellType(
+				() => Undefined, 
+				(CellCategory)0, 
+				"Error: No cell type has been defined");
+		
+		public static readonly CellType Effector_Message = 
+			CreateEffectorType(
+				() => Effector_Message, 
+				"Passes a signal between components");
+
+		public static readonly CellType Effector_DoSomething =
+			CreateEffectorType(
+				() => Effector_DoSomething,
+				"Does something");
 
 		#endregion < Fields >
 
 
 		#region Methods
 
-		private static CellType CreateEffectorType(Expression<Func<CellType>> fieldExpression)
+		private static CellType CreateEffectorType(Expression<Func<CellType>> fieldExpression, string description)
 		{
-			return CreateCellType(fieldExpression, CellCategory.Effector);
+			return CreateCellType(fieldExpression, CellCategory.Effector, description);
 		}
 
-		private static CellType CreateSensorType(Expression<Func<CellType>> fieldExpression)
+		private static CellType CreateSensorType(Expression<Func<CellType>> fieldExpression, string description)
 		{
-			return CreateCellType(fieldExpression, CellCategory.Sensor);
+			return CreateCellType(fieldExpression, CellCategory.Sensor, description);
 		}
 
-		private static CellType CreateHybridType(Expression<Func<CellType>> fieldExpression)
+		private static CellType CreateHybridType(Expression<Func<CellType>> fieldExpression, string description)
 		{
-			return CreateCellType(fieldExpression, CellCategory.Hybrid);
+			return CreateCellType(fieldExpression, CellCategory.Hybrid, description);
 		}
 
 		private static CellType CreateCellType(Expression<Func<CellType>> fieldExpression,
-			CellCategory cellCategory)
+			CellCategory cellCategory, string description)
 		{
 			var cellTypeName = TypeInfo.NameOf(fieldExpression);
 			return _mapNameToCellType.GetOrAdd(cellTypeName, new CellType()
 			{
 				CellCategory = cellCategory,
 				Id = _nextId++,
-				Name = cellTypeName
+				Name = cellTypeName,
+				Description = description
 			});
 		} 
 

UserProjects/sprucely/CSharp/Composer/Composer/Graph/VertexBase.cs

 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.ComponentModel;
+using System.Diagnostics;
 
 namespace Composer.Graph
 {
 
 		public virtual int Id { get; private set; }
 
+		[Browsable(false)]
+		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
+		[EditorBrowsable(EditorBrowsableState.Never)]
 		public virtual VertexType VertexType { get; protected set; }
 
 		public virtual ComponentDefinition ParentComponentDefinition { get; set; }

UserProjects/sprucely/CSharp/Composer/Composer/ORM/Mappings.cs

 				.Unique()
 				.Not.Nullable()
 				.CustomSqlType("VARCHAR(100)");
+			Map(x => x.Description)
+				.Unique()
+				.Not.Nullable()
+				.CustomSqlType("VARCHAR(200)");
 		}
 	}
 
 				.Unique()
 				.Not.Nullable()
 				.CustomSqlType("VARCHAR(100)");
+			Map(x => x.Description)
+				.Unique()
+				.Not.Nullable()
+				.CustomSqlType("VARCHAR(200)");
 
 			HasMany(x => x.ChildVertices)
 				.KeyColumn("Id_Definition_ParentComponent");

UserProjects/sprucely/CSharp/Composer/Composer/ShellView.xaml

         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:converters="clr-namespace:Composer.UI.Converters"
-        xmlns:ctrls="clr-namespace:Composer.UI.Screens"
-        xmlns:graph="clr-namespace:Composer.Graph"
-        xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions">
     <Window.Resources>
 
-        <converters:EdgeRouteToPathConverter x:Key="routeToPathConverter" />
-
-        <Style TargetType="{x:Type graphsharp:EdgeControl}">
-            <Style.Resources>
-                <ToolTip x:Key="ToolTipContent">
-                    <TextBlock Text="Description of a Connection" />
-                </ToolTip>
-            </Style.Resources>
-            <Setter Property="ToolTip" Value="{StaticResource ToolTipContent}" />
-            <Setter Property="Template">
-                <Setter.Value>
-                    <ControlTemplate TargetType="{x:Type graphsharp:EdgeControl}">
-                        <Path Name="edgePath"
-                              MinWidth="1"
-                              MinHeight="1"
-                              Stroke="{TemplateBinding Foreground}"
-                              StrokeThickness="2">
-                            <Path.Data>
-                                <PathGeometry>
-                                    <PathGeometry.Figures>
-                                        <MultiBinding Converter="{StaticResource routeToPathConverter}">
-                                            <Binding Path="Source" RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Path="Target" RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Path="RoutePoints" RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <!--  the following bindings are only necessary to cause this multibinding to update  -->
-                                            <Binding Mode="OneWay"
-                                                     Path="Source.(graphsharp:GraphCanvas.X)"
-                                                     RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Mode="OneWay"
-                                                     Path="Source.(graphsharp:GraphCanvas.Y)"
-                                                     RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Mode="OneWay"
-                                                     Path="Source.ActualWidth"
-                                                     RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Mode="OneWay"
-                                                     Path="Source.ActualHeight"
-                                                     RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Mode="OneWay"
-                                                     Path="Target.(graphsharp:GraphCanvas.X)"
-                                                     RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Mode="OneWay"
-                                                     Path="Target.(graphsharp:GraphCanvas.Y)"
-                                                     RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Mode="OneWay"
-                                                     Path="Target.ActualWidth"
-                                                     RelativeSource="{RelativeSource TemplatedParent}" />
-                                            <Binding Mode="OneWay"
-                                                     Path="Target.ActualHeight"
-                                                     RelativeSource="{RelativeSource TemplatedParent}" />
-                                        </MultiBinding>
-                                    </PathGeometry.Figures>
-                                </PathGeometry>
-                            </Path.Data>
-                        </Path>
-                    </ControlTemplate>
-                </Setter.Value>
-            </Setter>
-        </Style>
-
-        <DataTemplate DataType="{x:Type graph:VertexBase}">
-            <Border Width="50"
-                    Height="50"
-                    Background="Black"
-                    BorderBrush="White"
-                    BorderThickness="1"
-                    CornerRadius="25">
-                <Grid>
-                    <Grid.RowDefinitions>
-                        <RowDefinition />
-                        <RowDefinition />
-                        <RowDefinition />
-                    </Grid.RowDefinitions>
-                    <TextBlock Grid.Row="0"
-                               HorizontalAlignment="Center"
-                               FontSize="8"
-                               Foreground="White"
-                               Padding="2,1,2,1"
-                               Text="100" />
-                    <TextBlock Grid.Row="1"
-                               HorizontalAlignment="Center"
-                               VerticalAlignment="Center"
-                               FontSize="24"
-                               Foreground="White"
-                               Text="+R=" />
-                    <TextBlock Grid.Row="2"
-                               HorizontalAlignment="Center"
-                               FontSize="8"
-                               Foreground="White"
-                               Padding="2,1,2,3"
-                               Text="hello" />
-
-                </Grid>
-                <Border.Effect>
-                    <DropShadowEffect BlurRadius="3"
-                                      Direction="315"
-                                      Opacity="0.3"
-                                      ShadowDepth="3"
-                                      Color="Black" />
-                </Border.Effect>
-            </Border>
-        </DataTemplate>
-
-        <!--  style VertexControl to require DataTemplate to provide all rendering  -->
-        <Style TargetType="{x:Type graphsharp:VertexControl}">
-            <Setter Property="Template">
-                <Setter.Value>
-                    <ControlTemplate TargetType="{x:Type graphsharp:VertexControl}">
-                        <Border>
-                            <ContentPresenter Content="{TemplateBinding Vertex}" />
-                        </Border>
-                    </ControlTemplate>
-                </Setter.Value>
-            </Setter>
-        </Style>
 
 
     </Window.Resources>

UserProjects/sprucely/CSharp/Composer/Composer/ShellViewModel.cs

 			}
 		}
 
+		protected override void OnActivate()
+		{
+			base.OnActivate();
 
+			((IActivate)this._objectExplorer).Activate();
+			((IActivate)this._graphEditor).Activate();
+		}
+
+		protected override void OnDeactivate(bool close)
+		{
+			((IDeactivate)this._objectExplorer).Deactivate(close);
+			((IDeactivate)this._graphEditor).Deactivate(close);
+			base.OnDeactivate(close);
+		}
 	}
 }

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/GraphEditor/ComponentLayout.cs

 {
 	class ComponentLayout : GraphLayout<VertexBase, EdgeBase, ComponentDefinition>
 	{
+		public VertexControl GetVertexControl(VertexBase vertex)
+		{
+			return this.GetOrCreateVertexControl(vertex);
+		}
+
+		public EdgeControl GetEdgeControl(EdgeBase edge)
+		{
+			return this.GetOrCreateEdgeControl(edge);
+		}
 	}
 }

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/GraphEditor/GraphEditorView.xaml

 <UserControl x:Class="Composer.UI.Screens.GraphEditorView"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:converters="clr-namespace:Composer.UI.Converters"
              xmlns:ctrls="clr-namespace:Composer.UI.Screens"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:dnd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
+             xmlns:graph="clr-namespace:Composer.Graph"
+             xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
+             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
              xmlns:impl="clr-namespace:Composer.UI.Screens.GraphEditor"
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
-             xmlns:dnd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
+             Background="#ff656565"
              d:DesignHeight="300"
              d:DesignWidth="300"
-             mc:Ignorable="d"
+             dnd:DragDrop.DropHandler="{Binding}"
              dnd:DragDrop.IsDropTarget="True"
-             dnd:DragDrop.DropHandler="{Binding}"
-             Background="#ff656565">
+             mc:Ignorable="d">
     <UserControl.Resources>
         <impl:LayoutAlgorithmFactory x:Key="layoutAlgorithmFactory" />
+
+        <converters:EdgeRouteToPathConverter x:Key="routeToPathConverter" />
+
+        <Style TargetType="{x:Type graphsharp:EdgeControl}">
+            <Style.Resources>
+                <ToolTip x:Key="ToolTipContent">
+                    <TextBlock Text="Description of a Connection" />
+                </ToolTip>
+            </Style.Resources>
+            <Setter Property="ToolTip" Value="{StaticResource ToolTipContent}" />
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type graphsharp:EdgeControl}">
+                        <Path Name="edgePath"
+                              MinWidth="1"
+                              MinHeight="1"
+                              Stroke="{TemplateBinding Foreground}"
+                              StrokeThickness="2">
+                            <Path.Data>
+                                <PathGeometry>
+                                    <PathGeometry.Figures>
+                                        <MultiBinding Converter="{StaticResource routeToPathConverter}">
+                                            <Binding Path="Source" RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Path="Target" RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Path="RoutePoints" RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <!--  the following bindings are only necessary to cause this multibinding to update  -->
+                                            <Binding Mode="OneWay"
+                                                     Path="Source.(graphsharp:GraphCanvas.X)"
+                                                     RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Mode="OneWay"
+                                                     Path="Source.(graphsharp:GraphCanvas.Y)"
+                                                     RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Mode="OneWay"
+                                                     Path="Source.ActualWidth"
+                                                     RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Mode="OneWay"
+                                                     Path="Source.ActualHeight"
+                                                     RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Mode="OneWay"
+                                                     Path="Target.(graphsharp:GraphCanvas.X)"
+                                                     RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Mode="OneWay"
+                                                     Path="Target.(graphsharp:GraphCanvas.Y)"
+                                                     RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Mode="OneWay"
+                                                     Path="Target.ActualWidth"
+                                                     RelativeSource="{RelativeSource TemplatedParent}" />
+                                            <Binding Mode="OneWay"
+                                                     Path="Target.ActualHeight"
+                                                     RelativeSource="{RelativeSource TemplatedParent}" />
+                                        </MultiBinding>
+                                    </PathGeometry.Figures>
+                                </PathGeometry>
+                            </Path.Data>
+                        </Path>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+
+        <DataTemplate DataType="{x:Type graph:VertexBase}">
+            <Border Width="50"
+                    Height="50"
+                    Background="Black"
+                    BorderBrush="White"
+                    BorderThickness="1"
+                    CornerRadius="25">
+                <Grid>
+                    <Grid.RowDefinitions>
+                        <RowDefinition />
+                        <RowDefinition />
+                        <RowDefinition />
+                    </Grid.RowDefinitions>
+                    <TextBlock Grid.Row="0"
+                               HorizontalAlignment="Center"
+                               FontSize="8"
+                               Foreground="White"
+                               Padding="2,1,2,1"
+                               Text="100" />
+                    <TextBlock Grid.Row="1"
+                               HorizontalAlignment="Center"
+                               VerticalAlignment="Center"
+                               FontSize="24"
+                               Foreground="White"
+                               Text="+R=" />
+                    <TextBlock Grid.Row="2"
+                               HorizontalAlignment="Center"
+                               FontSize="8"
+                               Foreground="White"
+                               Padding="2,1,2,3"
+                               Text="hello" />
+
+                </Grid>
+                <Border.Effect>
+                    <DropShadowEffect BlurRadius="3"
+                                      Direction="315"
+                                      Opacity="0.3"
+                                      ShadowDepth="3"
+                                      Color="Black" />
+                </Border.Effect>
+            </Border>
+        </DataTemplate>
+
+        <!--  style VertexControl to require DataTemplate to provide all rendering  -->
+        <Style TargetType="{x:Type graphsharp:VertexControl}">
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type graphsharp:VertexControl}">
+                        <Border>
+                            <ContentPresenter Content="{TemplateBinding Vertex}" />
+                        </Border>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+
     </UserControl.Resources>
-    
+
     <Grid>
-        <!--<i:Interaction.Behaviors>
+        <!--
+            <i:Interaction.Behaviors>
             <dnd:DragDropBehavior DropProcessor="{Binding DropProcessor}"
-                                  IsDropTarget="True" />
-        </i:Interaction.Behaviors>-->
+            IsDropTarget="True" />
+            </i:Interaction.Behaviors>
+        -->
         <!--
             <zoom:ZoomControl  Grid.Row="1"
             Mode="Original"
                                Margin="10"
                                Graph="{Binding Path=Component}"
                                HighlightAlgorithmType="Simple"
+                               LayoutAlgorithmFactory="{StaticResource layoutAlgorithmFactory}"
                                LayoutAlgorithmType="Manual"
-                              LayoutAlgorithmFactory="{StaticResource layoutAlgorithmFactory}"
                                OverlapRemovalAlgorithmType="FSA" />
         <!--  </zoom:ZoomControl>  -->
 

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/GraphEditor/GraphEditorViewModel.cs

 using GongSolutions.Wpf.DragDrop;
 using System.Windows;
 using System.ComponentModel.Composition;
+using Composer.UI.Screens.ObjectExplorer;
+using GraphSharp.Controls;
 
 namespace Composer.UI.Screens
 {
 	[Export]
-	public class GraphEditorViewModel : ReactiveObject, IDropTarget
+	public class GraphEditorViewModel : Screen, IDropTarget
 	{
 
 		public GraphEditorViewModel()
 
 		public void DragOver(DropInfo dropInfo)
 		{
+			var objectInfo = dropInfo.Data as IObjectInfo;
+			if (objectInfo == null)
+				return;
 			dropInfo.Effects = DragDropEffects.Copy;
 		}
 
 		public void Drop(DropInfo dropInfo)
 		{
 
+			var cellInfo = dropInfo.Data as CellTypeInfo;
+
+
+			if (cellInfo != null)
+				DropCellVertex(dropInfo, cellInfo);
+		}
+
+		private void DropCellVertex(DropInfo dropInfo, CellTypeInfo cellInfo)
+		{
+			var view = this.GetView(null) as GraphEditorView;
+
+			var cellVertex = new CellVertex()
+			{
+				CellType = cellInfo.CellType,
+
+			};
+
+			this._Component.AddVertex(cellVertex);
+
+			if (view == null)
+				return;
+
+			var vertexControl = view.graphLayout.GetVertexControl(cellVertex);
+			GraphLayout.SetX(vertexControl, 100);
+			GraphLayout.SetY(vertexControl, 100);
+
 		}
 
 	}

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/ObjectExplorer/ObjectExplorerView.xaml

     <!--<i:Interaction.Behaviors>
         <bhv:RxDragBehavior />
     </i:Interaction.Behaviors>-->
+    
+    <UserControl.Resources>
+        <DataTemplate x:Key="ObjectInfoTemplate">
+            <TextBlock Text="{Binding Name}" 
+                       ToolTip="{Binding Description}"/>
+        </DataTemplate>
+    </UserControl.Resources>
+    
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="Auto" />
             <RowDefinition Height="*" />
         </Grid.RowDefinitions>
         <Button x:Name="Test" Grid.Row="0">Test</Button>
-        <ListBox Grid.Row="1" ItemsSource="{Binding CellOptions}"
+        <ListBox Grid.Row="1" 
+                 ItemsSource="{Binding AvailableObjects}"
+                 ItemTemplate="{StaticResource ObjectInfoTemplate}"
                  dnd:DragDrop.IsDragSource="True">
             <!--<i:Interaction.Behaviors>
                 <dnd:DragDropBehavior IsDragSource="True" />

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/ObjectExplorer/ObjectExplorerViewModel.cs

 using System.Linq;
 using System.Text;
 
+using Composer.Common;
 using Composer.UI.Framework;
 using Composer.ORM;
 using Composer.UI.Behaviors;
 using Composer.UI.Screens.ObjectExplorer;
 
 using ReactiveUI;
+using Composer.Graph.Initialization;
 
 namespace Composer.UI.Screens
 {
 		{
 			base.OnInitialize();
 
+			AvailableObjects.AddRange(
+				CellTypes.MapNameToCellType.Values
+				.Select(x => new CellTypeInfo(x)));
 		}
 
 		public ReactiveCollection<IObjectInfo> AvailableObjects

UserProjects/sprucely/CSharp/Composer/Composer/UI/Screens/ObjectExplorer/ObjectInfo.cs

 	{
 		public CellType CellType { get; private set; }
 		public string Name { get { return CellType.Name; } }
-		public string Description { get; private set; }
+		public string Description { get { return CellType.Description; } }
+
+		public CellTypeInfo(CellType cellType)
+		{
+			this.CellType = cellType;
+		}
 	}
 
 	[Export("ComponentInfo", typeof(IObjectInfo))]