public LinkStructureToParentCommand(Viking.UI.Controls.SectionViewerControl parent, Structure structure, Location_CanvasViewModel location) : base(parent) { this.putativeStruct = structure; this.putativeLoc = location; StructureType LocType = this.putativeStruct.Type; if (LocType != null) { linecolor = new Microsoft.Xna.Framework.Color(LocType.Color.R, LocType.Color.G, LocType.Color.B, 128); } else { linecolor = Microsoft.Xna.Framework.Color.Green; } //Transform the location position to the correct coordinates transformedPos = parent.SectionToVolume(new GridVector2(putativeLoc.X, putativeLoc.Y)); parent.Cursor = Cursors.Cross; }
public CreateNewStructureCommand(Viking.UI.Controls.SectionViewerControl parent, Structure structure, Location_CanvasViewModel location) : base(parent) { this.newStruct = structure; this.newLoc = location; }
public CreateNewLinkedLocationCommand(Viking.UI.Controls.SectionViewerControl parent, Location_CanvasViewModel existingLoc, Location_CanvasViewModel newLoc) : base(parent) { this.NewLoc = newLoc; this.ExistingLoc = existingLoc; }
protected override void Execute() { try { LocationObj NewLocation = Store.Locations.Create(NewLoc.modelObj, new long[] { ExistingLoc.ID }); LastEditedLocation = new Location_CanvasViewModel(NewLocation); } catch (ArgumentOutOfRangeException ) { MessageBox.Show("The chosen point is outside mappable volume space, location not created", "Recoverable Error"); } base.Execute(); }
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; }
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; }
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; } }
public GridVector2 GetPositionForLocation(Location_CanvasViewModel loc) { GridVector2 pos; bool Success = Locations.TryGetPosition(loc, out pos); if(!Success) throw new ArgumentException("Could not map location: " + loc.ToString()); return pos; }
/* public LocationObj[] GetReferenceLocations() { List<LocationObj> listRefLocations = new List<LocationObj>(); if (Section.ReferenceSectionAbove != null) { listRefLocations.AddRange(Store.Locations.GetLocalObjectsForSection(Section.ReferenceSectionAbove.Number).Values); } if (Section.ReferenceSectionBelow != null) { listRefLocations.AddRange(Store.Locations.GetLocalObjectsForSection(Section.ReferenceSectionBelow.Number).Values); } return listRefLocations.ToArray(); } */ /// <summary> /// Returns the position of the requested locationID in the current transform /// </summary> /// <param name="ID"></param> /// <returns></returns> public bool TryGetPositionForLocation(Location_CanvasViewModel loc, out GridVector2 position) { return Locations.TryGetPosition(loc, out position); //return Locations.TryGetPosition(loc); /* if (!Success) { //Hmm... why don't we have it? Trace.WriteLine("Could not find position for location: " + ID.ToString()); } return position; */ }
/// <summary> /// A key is about to be removed from the location store. Remove it from our cache as well /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RemoveLocations(IEnumerable<LocationObj> listLocations, bool Unsubscribe) { foreach (LocationObj loc in listLocations) { //Trace.WriteLine("RemoveLocation: " + loc.ID.ToString(), "WebAnnotationViewModel"); //Debug.Assert(loc.Section == Section.Number); if (loc.Section == Section.Number) { Location_CanvasViewModel locView = new Location_CanvasViewModel(loc); Location_CanvasViewModel RemovedValue; bool RemoveSuccess = Locations.TryRemove(locView, out RemovedValue); if (RemoveSuccess) { RemovedValue.DeregisterForLocationEvents(); if (Unsubscribe) { UnsubscribeToLocationChangeEvents(loc); } // Debug.Assert(RemoveSuccess); // RemoveLocationLinks(obj); } } ConcurrentDictionary<long, Location_CanvasViewModel> KnownLocationsForStructure = null; bool Success = LocationsForStructure.TryGetValue(loc.ParentID.Value, out KnownLocationsForStructure); if (Success) { Location_CanvasViewModel removedLoc; Success = KnownLocationsForStructure.TryRemove(loc.ID, out removedLoc); if (Success) { if (KnownLocationsForStructure.Count == 0) { LocationsForStructure.TryRemove(loc.ParentID.Value, out KnownLocationsForStructure); } /*PORT: Not thread safe, This proabably all needs to be removed... //Remove entry if it was the last location for that structure if (KnownLocationsForStructure.Count == 0) { LocationsForStructure.TryUpdate(obj.ParentID.Value, null, KnownLocationsForStructure); LocationsForStructure.Remove(obj.ParentID.Value); } */ } } //GridVector2 removeOutParam; //TransformedLocationPositionDict.TryRemove(ID, out removeOutParam); // Trace.WriteLine("End RemoveLocation: " + loc.ID.ToString(), "WebAnnotationViewModel"); } /* if (AnnotationChanged != null && loc != null) AnnotationChanged(obj, new EventArgs()); */ }
/// <summary> /// Add a location to the view model. /// </summary> /// <param name="loc">Location to add</param> /// <param name="Subscribe">Subscribe to the location's change events</param> /// <param name="UpdateVolumeLocations">Return True if the volume position of the location was updated</param> private bool AddLocation(LocationObj loc, bool Subscribe, bool UpdateVolumeLocations) { if (loc.Section != Section.Number) return false; //Trace.WriteLine("AddLocation: " + obj.ToString(), "WebAnnotation"); bool FirstMapping = !loc.VolumePositionHasBeenCalculated; bool UpdatedVolumeLocation = false; GridVector2 original = loc.VolumePosition; bool mapped = MapLocation(loc); if (!mapped) return false; #if SUBMITVOLUMEPOSITION if (UpdateVolumeLocations && FirstMapping) { if (GridVector2.DistanceSquared(original, loc.VolumePosition) > 225.0) { loc.SubmitOnNextUpdate(); UpdatedVolumeLocation = true; } } #endif //Add location if it hasn't been seen before Location_CanvasViewModel locView = new Location_CanvasViewModel(loc); bool Added = Locations.TryAdd(locView.VolumePosition, locView); if (Added) { if (Subscribe) { locView.RegisterForLocationEvents(); SubscribeToLocationChangeEvents(loc); } ConcurrentDictionary<long, Location_CanvasViewModel> KnownLocationsForStructure; KnownLocationsForStructure = LocationsForStructure.GetOrAdd(loc.ParentID.Value, (key) => { return new ConcurrentDictionary<long, Location_CanvasViewModel>(); }); KnownLocationsForStructure.TryAdd(locView.ID, locView); } return UpdatedVolumeLocation; }
/// <summary> /// Returns the same object if it is a valid target to create a link against. Otherwise NULL /// </summary> /// <param name="NearestTarget"></param> /// <returns></returns> protected Location_CanvasViewModel ValidateTarget(Location_CanvasViewModel nearest_target) { if (nearest_target != null) { //Check to make sure it isn't the same structure on the same section if (nearest_target.ParentID == OriginObj.ParentID) { if (nearest_target.Z == OriginObj.Z) { //Not a valid target for a link nearest_target = null; } else { //Make sure the locations aren't already linked foreach (long linkID in OriginObj.Links) { if (linkID == nearest_target.ID) { //They are already linked, so not a valid target nearest_target = null; break; } } } } } return nearest_target; }
protected override void OnMouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { //If we clicked a location from another section then create a new linked section if (selected.Section != this.Parent.Section.Number) { Debug.Assert(selected != null); GridVector2 WorldPos = Parent.ScreenToWorld(e.X, e.Y); //Transform from volume space to section space if we can GridVector2 SectionPos; try { SectionPos = Parent.VolumeToSection(WorldPos); } catch (ArgumentOutOfRangeException ) { Trace.WriteLine("Could not map world point OnMouseUp: " + WorldPos.ToString(), "Command"); return; } LocationObj newLoc = new LocationObj(selected.Parent.modelObj, SectionPos, WorldPos, Parent.Section.Number); Location_CanvasViewModel newLocView = new Location_CanvasViewModel(newLoc); Viking.UI.Commands.Command.EnqueueCommand(typeof(ResizeLocationCommand), new object[] { Parent, selected.Parent.Type, newLocView }); Viking.UI.Commands.Command.EnqueueCommand(typeof(CreateNewLinkedLocationCommand), new object[] { Parent, selected, newLocView }); Viking.UI.State.SelectedObject = null; this.Execute(); } else { //If we've been dragging a location on the same section then relocate the section GridVector2 WorldPos = Parent.ScreenToWorld(e.X, e.Y); //Transform from volume space to section space if we need to GridVector2 SectionPos; try { SectionPos = Parent.VolumeToSection(WorldPos); } catch (ArgumentOutOfRangeException ) { Trace.WriteLine("Could not map world point OnMouseUp: " + WorldPos.ToString(), "Command"); return; } selected.SectionPosition = SectionPos; //Send changes to DB Store.Locations.Save(); this.Deactivated = true; } } else if (e.Button != MouseButtons.Right) { //Any other button other than the right button cancels the command this.Deactivated = true; } base.OnMouseUp(sender, e); }
public LinkAnnotationsCommand(Viking.UI.Controls.SectionViewerControl parent, Location_CanvasViewModel existingLoc) : base(parent) { OriginObj = existingLoc; }
protected void OnContinueLastTrace(GridVector2 WorldPos) { if (CreateNewLinkedLocationCommand.LastEditedLocation != null) { Location_CanvasViewModel template = CreateNewLinkedLocationCommand.LastEditedLocation; if (template.Z != this.Parent.Section.Number) { GridVector2 SectionPos; bool success = _Parent.TryVolumeToSection(WorldPos, _Parent.Section, out SectionPos); Debug.Assert(success); if (!success) return; LocationObj newLoc = new LocationObj(CreateNewLinkedLocationCommand.LastEditedLocation.Parent.modelObj, SectionPos, WorldPos, Parent.Section.Number); Location_CanvasViewModel newLocView = new Location_CanvasViewModel(newLoc); Viking.UI.Commands.Command.EnqueueCommand(typeof(ResizeLocationCommand), new object[] { Parent, template.Parent.Type, newLocView }); Viking.UI.Commands.Command.EnqueueCommand(typeof(CreateNewLinkedLocationCommand), new object[] { Parent, template, newLocView }); Viking.UI.State.SelectedObject = null; CreateNewLinkedLocationCommand.LastEditedLocation = null; } } }
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()); }
/// <summary> /// When the user left clicks the control we create a new structure at that location /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected override void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { //Create a new structure on left click if (e.Button == MouseButtons.Left) { // Debug.Assert(obj == null, "This command should be inactive if Selected Object isn't a StructureTypeObj"); if (Type == null) return; GridVector2 WorldPos = Parent.ScreenToWorld(e.X, e.Y); //Transform from volume space to section space if we need to GridVector2 SectionPos; bool Transformed= Parent.TryVolumeToSection(WorldPos, Parent.Section, out SectionPos); if (!Transformed) { this.Deactivated = true; base.OnMouseClick(sender, e); } 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 }); } Execute(); } else if (e.Button == MouseButtons.Right) { this.Deactivated = true; } base.OnMouseClick(sender, e); }
protected override void OnMouseMove(object sender, MouseEventArgs e) { GridVector2 WorldPos = Parent.ScreenToWorld(e.X, e.Y); // GridVector2 locPosition; SectionLocationsViewModel sectionAnnotations = AnnotationOverlay.GetAnnotationsForSection(Parent.Section.Number); if (sectionAnnotations == null) return; //Find if we are close enough to a location to "snap" the line to the target double distance; nearestParent = Overlay.GetNearestLocation(WorldPos, out distance); base.OnMouseMove(sender, e); Parent.Invalidate(); }
protected override void OnMouseUp(object sender, MouseEventArgs e) { //Figure out if we've clicked another structure and create the structure if (e.Button == MouseButtons.Left) { GridVector2 WorldPos = Parent.ScreenToWorld(e.X, e.Y); SectionLocationsViewModel sectionAnnotations = AnnotationOverlay.GetAnnotationsForSection(Parent.Section.Number); if (sectionAnnotations == null) return; //Find if we are close enough to a location to "snap" the line to the target double distance; NearestTarget = Overlay.GetNearestLocation(WorldPos, out distance); NearestTarget = ValidateTarget(NearestTarget); if(NearestTarget == null) { this.Deactivated = true; return; } if(NearestTarget.ParentID == OriginObj.ParentID) { try { Store.LocationLinks.CreateLink(OriginObj.modelObj.ID, NearestTarget.modelObj.ID); } catch (Exception except) { MessageBox.Show("Could not create link between locations: " + except.Message, "Recoverable Error"); } finally { this.Deactivated = true; } } else { try { StructureLinkObj linkStruct = new StructureLinkObj(OriginObj.ParentID.Value, NearestTarget.ParentID.Value, false); linkStruct = Store.StructureLinks.Create(linkStruct); } catch (Exception except) { MessageBox.Show("Could not create link between structures: " + except.Message, "Recoverable Error"); } finally { this.Deactivated = true; } //HACK: This updates the UI to show the new structure link. It should be automatic, but force it for now... //sectionAnnotations.AddStructureLinks(OriginObj.Parent); //sectionAnnotations.AddStructureLinks(NearestTarget.Parent); } this.Execute(); } base.OnMouseDown(sender, e); }