public CsgNodeTreeViewItem(ObjectTreeView owner, CsgNodeWrapper node) { this.owner = owner; this.node = node; Header = new TreeViewItemHeader(node, "DisplayName", HeaderImage); AllowDrop = false; }
private void AddNode(CsgNode node) { if (root == null) { return; } CsgNodeWrapper wrapper = root.Node.Repository.GetWrapper(node); CsgNodeTreeViewItem item = nodeView.SelectedItem as CsgNodeTreeViewItem; CsgGroupWrapper selected = null; while (item != null) { selected = item.Node as CsgGroupWrapper; if (selected != null) { break; } item = item.Parent as CsgNodeTreeViewItem; } if (selected == null) { selected = root.Node as CsgGroupWrapper; } if (selected != null) { selected.AddChild(wrapper); } }
private void UpdateProperties(CsgNodeWrapper node) { foreach (UIElement element in PropertiesPanel.Children) { ClearBindings(element); } PropertiesPanel.Children.Clear(); if (node == null) { return; } foreach (PropertyInfo property in node.GetType().GetProperties().OrderBy(x => x.Name)) { if (!property.CanWrite || !property.CanRead) { continue; } DockPanel panel = new DockPanel(); panel.Margin = new Thickness(5, 5, 5, 0); Label label = new Label(); label.Content = property.Name; label.SetValue(DockPanel.DockProperty, Dock.Left); label.Margin = new Thickness(0, 0, 10, 0); label.HorizontalContentAlignment = HorizontalAlignment.Right; label.VerticalContentAlignment = VerticalAlignment.Center; label.Width = 100; panel.Children.Add(label); UIElement control = CreateControl(node, property); panel.Children.Add(control); PropertiesPanel.Children.Add(panel); } }
private bool CanDrop(string idString) { string[] ids = (idString ?? string.Empty).Split('|'); if (ids.Length == 2) { CsgNodeWrapper wrapper = Node.Repository.GetWrapperById(ids[0]); if (wrapper != null) { CsgNodeTreeViewItem item = this; while (item != null) { if (item.Node == wrapper) { return(false); } item = item.Parent as CsgNodeTreeViewItem; } if (item == null) { return(true); } } } return(false); }
private void DeleteClick(object sender, RoutedEventArgs e) { CsgNodeWrapper selected = objectList.SelectedItem as CsgNodeWrapper; if (selected != null) { selected.IsObjectRoot = false; } }
private void StartDrag(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { CsgNodeWrapper selected = objectList.SelectedItem as CsgNodeWrapper; if (selected != null) { DragDrop.DoDragDrop(objectList, selected.Id + "|0", DragDropEffects.Link); e.Handled = true; } } }
protected override void UpdateModel() { CsgNodeWrapper node = SelectedItem; if (node == null) { timer.IsEnabled = false; } else { physics.SetRootNode(node.Node); timer.IsEnabled = true; } base.UpdateModel(); }
protected override void OnDrop(DragEventArgs e) { string[] ids = (e.Data.GetData(DataFormats.Text) as string ?? string.Empty).Split('|'); e.Handled = true; if (ids.Length == 2) { CsgNodeWrapper wrapper = Node.Repository.GetWrapperById(ids[0]); if (e.Effects == DragDropEffects.Move) { CsgGroupWrapper parent = Node.Repository.GetWrapperById(ids[1]) as CsgGroupWrapper; if (wrapper != null && parent != null) { CsgNodeTreeViewItem item = this; while (item != null) { if (item.Node == wrapper) { return; } item = item.Parent as CsgNodeTreeViewItem; } if (parent.RemoveChild(wrapper)) { if (!Group.AddChild(wrapper)) { parent.AddChild(wrapper); } } IsSelected = true; } } else if (e.Effects == DragDropEffects.Link) { if (wrapper != null) { Group.AddChild(wrapper); IsSelected = true; } } } base.OnDrop(e); }
private UIElement CreateControl(CsgNodeWrapper wrapper, PropertyInfo property) { if (property.PropertyType == typeof(bool)) { CheckBox check = new CheckBox(); check.SetBinding(CheckBox.IsCheckedProperty, new Binding(property.Name) { Source = wrapper, Mode = BindingMode.TwoWay }); return(check); } TextBox text = new TextBox(); text.SetBinding(TextBox.TextProperty, new Binding(property.Name) { Source = wrapper, Mode = BindingMode.TwoWay }); return(text); }
private void DuplicateNode() { CsgNodeTreeViewItem item = nodeView.SelectedItem as CsgNodeTreeViewItem; if (item == null) { return; } CsgGroupTreeViewItem parent = item.Parent as CsgGroupTreeViewItem; if (parent == null) { return; } int newIndex; for (newIndex = parent.Group.ChildrenCount - 1; newIndex >= 0; newIndex--) { if (parent.Group.Group[newIndex] == item.Node.Node) { break; } } if (newIndex < 0) { newIndex = parent.Group.ChildrenCount; } else { newIndex++; } CsgNodeWrapper clone = item.Node.Clone(); parent.Group.AddChild(clone); if (newIndex != (parent.Group.ChildrenCount - 1)) { parent.Group.MoveChild(clone, newIndex); } parent.Items.Cast <CsgNodeTreeViewItem>().First(x => x.Node == clone).IsSelected = true; }
protected virtual void UpdateModel() { while (viewport.Children.Count > 1) { viewport.Children.RemoveAt(1); } CsgNodeWrapper wrapper = null; bool resetView = lastModel == null; if (LockToggle.IsChecked.GetValueOrDefault()) { wrapper = lastModel; lastModel.IsViewing = true; } else if (lastModel != null) { lastModel.IsViewing = false; } if (wrapper == null) { wrapper = SelectedItem; } if (lastModel != null) { lastModel.MeshChanged -= ModelMeshChanged; lastModel = null; } if (wrapper == null) { return; } CsgNode root = wrapper.Node; lastModel = wrapper; lastModel.MeshChanged += ModelMeshChanged; modelMin = new Point3D(double.MaxValue, double.MaxValue, double.MaxValue); modelMax = new Point3D(double.MinValue, double.MinValue, double.MinValue); meshGeometry.Clear(); foreach (Mesh3 mesh in GetMeshes()) { mesh.CalculateNormals(); viewport.Children.Add(new ModelVisual3D() { Content = meshGeometry[mesh] = new GeometryModel3D() { Material = defaultMaterial, Geometry = new MeshGeometry3D() { TriangleIndices = new Int32Collection(mesh.TriangleIndices), Normals = new Vector3DCollection(mesh.VertexNormals.Select(x => new Vector3D(x.X, x.Y, x.Z)).ToArray()), Positions = new Point3DCollection(mesh.Vertices.Select(x => { Vector3 transformed = mesh.Transform.Transform(x) + mesh.Position; if (transformed.X < modelMin.X) { modelMin.X = transformed.X; } if (transformed.X > modelMax.X) { modelMax.X = transformed.X; } if (transformed.Y < modelMin.Y) { modelMin.Y = transformed.Y; } if (transformed.Y > modelMax.Y) { modelMax.Y = transformed.Y; } if (transformed.Z < modelMin.Z) { modelMin.Z = transformed.Z; } if (transformed.Z > modelMax.Z) { modelMax.Z = transformed.Z; } return(new Point3D(x.X, x.Y, x.Z)); }).ToArray()) }, Transform = new MatrixTransform3D(mesh.Transform.ToMatrix3D(mesh.Position)) } }); } if (resetView) { ResetView(); } }