Example #1
0
        protected void AddNewObjects(ICollection<StructureTypeObj> added)
        {
            //Find all of the root objects
            List<StructureType> listRoots = new List<StructureType>(added.Count);
            Dictionary<long, StructureType> listParents = new Dictionary<long, StructureType>(added.Count);

            foreach (StructureTypeObj newTypeObj in added)
            {
                StructureType newType = new StructureType(newTypeObj);
                if(!newTypeObj.ParentID.HasValue)
                {
                    if (!Tree.Contains(newType))
                        listRoots.Add(newType);
                    else if(!listParents.ContainsKey(newType.ID))
                        listParents.Add(newType.ID, newType);
                }
                else
                {
                    if(!listParents.ContainsKey(newTypeObj.ParentID.Value))
                        listParents.Add(newTypeObj.ParentID.Value, newType.Parent);
                }
            }

            Tree.AddObjects(listRoots);

            foreach(StructureType parent in listParents.Values)
            {
                UpdateNodeChildren(parent);
            }
        }
Example #2
0
        protected override void InitializeTree()
        {
            ICollection<StructureTypeObj> listTypes = Store.StructureTypes.rootObjects.Values;
            List<StructureType> listRootTypes = new List<StructureType>(listTypes.Count);
            foreach (StructureTypeObj type in listTypes)
            {
                StructureType rootType = new StructureType(type);
                listRootTypes.Add(rootType);
            }

            Tree.AddObjects(listRootTypes.ToArray());
        }
        protected override void OnShowObject(object Object)
        {
            this.Obj = Object as StructureType;
            Debug.Assert(this.Obj != null);

            this.textName.Text = this.Obj.Name;

            this.textCode.Text = this.Obj.Code;

            this.textNotes.Text = this.Obj.Notes;

            this.textID.Text = this.Obj.ID.ToString();

            this.btnColor.BackColor = this.Obj.Color;
        }
Example #4
0
        public ResizeLocationCommand(Viking.UI.Controls.SectionViewerControl parent)
            : base(parent)
        {
            selected = Viking.UI.State.SelectedObject as Location_CanvasViewModel;
            Debug.Assert(selected != null);

            LocType = selected.Parent.Type;

            SectionLocationsViewModel sectionAnnotations = AnnotationOverlay.GetAnnotationsForSection(Parent.Section.Number);
            if (sectionAnnotations == null)
                return;

            Origin = sectionAnnotations.GetPositionForLocation(selected);
            parent.Cursor = Cursors.SizeAll;
            SaveToDB = true;
        }
Example #5
0
        public ResizeLocationCommand(Viking.UI.Controls.SectionViewerControl parent, 
                                     StructureType type, 
                                     Location_CanvasViewModel loc)
            : base(parent)
        {
            selected = loc;
            LocType = type;
            this.SaveToDB = false;

            SectionLocationsViewModel sectionAnnotations = AnnotationOverlay.GetAnnotationsForSection(Parent.Section.Number);
            if (sectionAnnotations == null)
                return;

            //Origin = sectionAnnotations.GetPositionForLocation(selected);
            Origin = selected.VolumePosition;
            parent.Cursor = Cursors.SizeAll;
             //           CreationTime = DateTime.Now;
        }
Example #6
0
        public LocationObjCommand(Viking.UI.Controls.SectionViewerControl parent)
            : base(parent)
        {
            selected = Viking.UI.State.SelectedObject as Location_CanvasViewModel;
            Debug.Assert(selected != null);

            if (selected.Parent != null)
            {
                LocType = selected.Parent.Type;
            }

            //Figure out if we've selected a location on the same section or different
            if (selected.Section != this.Parent.Section.Number)
            {
                parent.Cursor = Cursors.Cross;
            }
            else
            {
                parent.Cursor = Cursors.Hand;
            }
        }
Example #7
0
        protected void OnCreateStructure(long TypeID)
        {
            StructureTypeObj typeObj = Store.StructureTypes.GetObjectByID(TypeID);
            if (typeObj != null)
            {
                StructureType type = new StructureType(typeObj);

                System.Drawing.Point ClientPoint = _Parent.PointToClient(System.Windows.Forms.Control.MousePosition);
                GridVector2 WorldPos = _Parent.ScreenToWorld(ClientPoint.X, ClientPoint.Y);
                GridVector2 SectionPos;
                bool success = _Parent.TryVolumeToSection(WorldPos, _Parent.Section, out SectionPos);
                Debug.Assert(success);
                if (!success)
                    return;

                StructureObj newStruct = new StructureObj(type.modelObj);
                LocationObj newLocation = new LocationObj(newStruct,
                                                SectionPos,
                                                WorldPos,
                                                Parent.Section.Number);

                Structure newStructView = new Structure(newStruct);
                Location_CanvasViewModel newLocationView = new Location_CanvasViewModel(newLocation);

                if (type.Parent == null)
                {
                    Viking.UI.Commands.Command.EnqueueCommand(typeof(ResizeLocationCommand), new object[] { Parent, type, newLocationView });
                    Viking.UI.Commands.Command.EnqueueCommand(typeof(CreateNewStructureCommand), new object[] { Parent, newStructView, newLocationView });
                }
                else
                {
                    //Enqueue two commands to resize the location and then select a parent
                    Viking.UI.Commands.Command.EnqueueCommand(typeof(ResizeLocationCommand), new object[] { Parent, type, newLocationView });
                    Viking.UI.Commands.Command.EnqueueCommand(typeof(LinkStructureToParentCommand), new object[] { Parent, newStructView, newLocationView });
                    Viking.UI.Commands.Command.EnqueueCommand(typeof(CreateNewStructureCommand), new object[] { Parent, newStructView, newLocationView });
                }
            }
            else
                Trace.WriteLine("Could not find hotkey ID for type: " + TypeID.ToString());
        }
Example #8
0
        private void DrawLocationLink(LocationLink link, Matrix ViewProjMatrix)
        {
            LocationObj locA = link.A;
            LocationObj locB = link.B;

            if (!link.LinksVisible(_Parent.Downsample))
                return;

            if (!locA.VolumePositionHasBeenCalculated)
                return;
            if (!locB.VolumePositionHasBeenCalculated)
                return;

            //Don't draw if the link falls within the radius of the location we are drawing
            if (link.LinksOverlap(Parent.Section.Number))
                return;

            if (locA.Parent == null)
                return;

            StructureType type = new StructureType(locA.Parent.Type);
            if (type == null)
                return;

            int distanceFactor = link.maxSection - link.minSection;
            if (distanceFactor == 0)
                distanceFactor = 1;

            //Give the colors a nudge towards red or blue depending on the direction to the link
            double directionFactor = 1;
            directionFactor = link.maxSection == _Parent.Section.Number ? 1 : -1;

            Microsoft.Xna.Framework.Color color = GetLocationLinkColor(type.Color, distanceFactor, directionFactor, LastMouseOverObject == link);

            _Parent.LineManager.Draw(link.lineGraphic, (float)link.Radius, color,
                                         ViewProjMatrix, 0, null);
        }
Example #9
0
        private static bool TryDrawLineFromOverlappingLocation(OverlappedLocation OverlappingLocation, RoundLineCode.RoundLineManager lineManager, int section_number, float time_offset)
        {
            if (OverlappingLocation != null)
            {
                LocationLink SelectedLink = OverlappingLocation.link;
                //Give the colors a nudge towards red or blue depending on the direction to the link
                double directionFactor = 1;
                StructureType type = new StructureType(SelectedLink.A.Parent.Type);
                int distanceFactor = SelectedLink.maxSection - SelectedLink.minSection;
                if (distanceFactor == 0)
                    distanceFactor = 1;

                directionFactor = SelectedLink.maxSection == section_number ? 1 : -1;

                int red = (int)((float)(type.Color.R * .5) + (128 * directionFactor));
                red = 255 - (red / distanceFactor);
                red = red > 255 ? 255 : red;
                int blue = (int)((float)(type.Color.B * .5) + (128 * (1 - directionFactor)));
                blue = 255 - (blue / distanceFactor);
                blue = blue > 255 ? 255 : blue;
                int green = (int)((float)type.Color.G);
                green = 255 - (green / distanceFactor);

                int alpha = 85;
                if (LastMouseOverObject == SelectedLink)
                {
                    alpha = 192;
                }

                //If you don't cast to byte the wrong constructor is used and the alpha value is wrong
                Microsoft.Xna.Framework.Color color = new Microsoft.Xna.Framework.Color((byte)(red),
                    (byte)(green),
                    (byte)(blue),
                    (byte)(alpha));

                lineManager.Draw(SelectedLink.lineGraphic, (float)SelectedLink.Radius, color,
                                             basicEffect.View * basicEffect.Projection, time_offset, null);

                return true;
            }

            return false;
        }
Example #10
0
        protected void OnStructureTypeCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            if(InvokeRequired)
            {
                //Ensure UI controls are updated in main thread
                this.Invoke( new Action(() => this.OnStructureTypeCollectionChanged(sender, args)));
                return;
            }
            else
            {
                switch (args.Action)
                {
                    case NotifyCollectionChangedAction.Add:

                        List<StructureTypeObj> newItems = new List<StructureTypeObj>(args.NewItems.Count);
                        //I'd rather case, but can't figure it out with IList interface...
                        foreach(object obj in args.NewItems)
                        {
                            newItems.Add((StructureTypeObj)obj);
                        }

                        AddNewObjects(newItems);
                        /*
                        foreach (object o in args.NewItems)
                        {
                            StructureTypeObj newTypeObj = o as StructureTypeObj;
                            if(newTypeObj != null)
                            {
                                StructureType newType = new StructureType(newTypeObj);
                                if (newType.Parent != null)
                                {
                                    UpdateNodeChildren(newType.Parent);
                                }
                                else
                                    Tree.AddObjects(new IUIObject[] { newType });
                            }
                        }
                         */
                        break;
                    case NotifyCollectionChangedAction.Remove:

                        foreach (object o in args.OldItems)
                        {
                            StructureTypeObj oldTypeObj = o as StructureTypeObj;
                            if (oldTypeObj != null)
                            {
                                StructureType oldType = new StructureType(oldTypeObj);
                                Viking.UI.Controls.GenericTreeNode[] nodes = Tree.GetNodesForObject(oldType);
                                foreach (Viking.UI.Controls.GenericTreeNode node in nodes)
                                {
                                    Tree.RemoveNode(node);
                                }
                            }
                        }
                        break;

                    case NotifyCollectionChangedAction.Replace:
                        foreach (object o in args.OldItems)
                        {
                            StructureTypeObj TypeObj = o as StructureTypeObj;
                            if (TypeObj != null)
                            {
                                StructureType t = new StructureType(TypeObj);
                                if (t.Parent != null)
                                {
                                    UpdateNodeChildren(t);
                                }
                            }
                        }
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        foreach (object o in args.OldItems)
                        {
                            StructureTypeObj TypeObj = o as StructureTypeObj;
                            if (TypeObj != null)
                            {
                                StructureType t = new StructureType(TypeObj);
                                if (t.Parent != null)
                                {
                                    UpdateNodeChildren(t);
                                }
                            }
                        }
                        break;

                }
            }
        }
Example #11
0
        private void OnNewStructureType(object sender, EventArgs e)
        {
            StructureTypeObj newTypeObj = new StructureTypeObj();
            StructureType newType = new StructureType(newTypeObj);

            if (newType.ShowPropertiesDialog(this.ParentForm) == DialogResult.OK)
            {
                newTypeObj = Store.StructureTypes.Create(newTypeObj);
                Store.StructureTypes.Save();

                Viking.UI.State.SelectedObject = new StructureType(newTypeObj);
            }
        }
Example #12
0
 protected void UpdateNodeChildren(StructureType obj)
 {
     GenericTreeNode[] Nodes = Tree.GetNodesForObject(obj);
     foreach (GenericTreeNode node in Nodes)
     {
         node.UpdateChildNodes();
     }
 }
Example #13
0
 public PlaceStructureCommand(Viking.UI.Controls.SectionViewerControl parent, StructureType type)
     : base(parent)
 {
     this.Type = type;
     parent.Cursor = Cursors.Cross;
 }
Example #14
0
 public PlaceStructureCommand(Viking.UI.Controls.SectionViewerControl parent)
     : base(parent)
 {
     this.Type = Viking.UI.State.SelectedObject as StructureType;
     parent.Cursor = Cursors.Cross;
 }
 protected override void OnShowObject(object Object)
 {
     this.Obj = Object as StructureType;
     Debug.Assert(this.Obj != null);
 }
Example #16
0
        protected void ContextMenu_OnNewStructureType(object sender, EventArgs e)
        {
            StructureTypeObj newType = new StructureTypeObj(this.modelObj);
            StructureType newTypeView = new StructureType(newType);
            DialogResult result = Viking.UI.Forms.PropertySheetForm.ShowDialog(newTypeView, null);

            if (result != DialogResult.Cancel)
            {
                newType = Store.StructureTypes.Create(newType);
                Store.StructureTypes.Save();
            }
        }