Example #1
0
        private void UpdateStructureLoc(View theView, int newX, int newY)
        {
            StructureObj theStruct = StructureForView(theView);

            if (theStruct != null)
            {
                theStruct.xLoc = newX;
                theStruct.yLoc = newY;
                PhabrikServer.UpdateStructureLoc(theStruct);
                isDirty = true;
            }
        }
Example #2
0
        private void UpdateStructureLoc(StructureObj theStruct, View theView)
        {
            var cellsize = structureGrid.Width / 10;

            if (cellsize == 0)
            {
                cellsize = Resources.DisplayMetrics.WidthPixels / 10;
            }

            var gridLayout = new FrameLayout.LayoutParams(cellsize * theStruct.xSize, cellsize * theStruct.ySize);

            gridLayout.SetMargins(cellsize * theStruct.xLoc, cellsize * theStruct.yLoc, 0, 0);
            theView.LayoutParameters = gridLayout;
        }
Example #3
0
        private View AddStructureToView(StructureObj newStruct, bool checkOverlap)
        {
            int  width  = newStruct.xSize;
            int  height = newStruct.ySize;
            bool fits   = false;

            if (!checkOverlap)
            {
                fits = true;
            }
            else
            {
                for (int curX = 0; curX < 9 - width; curX++)
                {
                    for (int curY = 0; curY < 9 - height; curY++)
                    {
                        if (RectInWhichStructure(curX, curY, width, height, newStruct) == null)
                        {
                            fits = true;
                            break;
                        }
                    }
                    if (fits)
                    {
                        break;
                    }
                }
            }

            if (fits)
            {
                ImageView newView = new ImageView(this.Activity);
                newView.SetScaleType(ImageView.ScaleType.FitXy);
                newView.Tag = newStruct.Id;
                this.Activity.RunOnUiThread(() =>
                {
                    structureGrid.AddView(newView);

                    Koush.UrlImageViewHelper.SetUrlDrawable(newView, newStruct.imageURL, Resource.Drawable.Icon);
                    UpdateStructureLoc(newStruct, newView);
                });

                return(newView);
            }
            else
            {
                RefundPurchase(newStruct);
                return(null);
            }
        }
        protected override void OnShowObject(object Object)
        {
            this.Obj = Object as StructureObj;
            Debug.Assert(this.Obj != null);

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

            this.checkVerified.Checked = this.Obj.Verified;

            this.numConfidence.Value = System.Convert.ToDecimal(this.Obj.Confidence);

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

            this.listTags.Items.AddRange(this.Obj.Tags);
        }
Example #5
0
        private void HandlePurchase(StructureTypeObj theObj)
        {
            System.Console.WriteLine("Purchased item " + theObj.structurename);
            StructureObj newStruct = StructureObj.Instantiate(theObj);

            if (parent.pop.curSector != null)
            {
                parent.pop.curSector.structures.Add(newStruct);
                newStruct.sectorId = parent.pop.curSector.Id;
                newStruct.ownerId  = PhabrikServer.CurrentUser.Id;
                PhabrikServer.SaveNewStructure(newStruct, (newId) =>
                {
                    View newView = AddStructureToView(newStruct, true);
                    if (newView != null)
                    {
                        isDirty = true;
                    }
                });
            }
        }
Example #6
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 #7
0
        void StructureGrid_Touch(object sender, View.TouchEventArgs e)
        {
            int cellsize = structureGrid.Width / 10;

            if (e.Event.Action == MotionEventActions.Down)
            {
                Console.WriteLine("starting drag");
                startX = e.Event.GetX();
                startY = e.Event.GetY();


                lastX = startX;
                lastY = startY;


                var newDragView = FindViewAtLoc((int)(lastX / cellsize), (int)(lastY / cellsize), 1, 1);
                SetSelectedView(newDragView);
                if (dragView != null)
                {
                    StructureObj theStruct = StructureForView(dragView);
                    lastXLoc   = theStruct.xLoc;
                    lastYLoc   = theStruct.yLoc;
                    dx         = startX - dragView.Left;
                    dy         = startY - dragView.Top;
                    dragWidth  = dragView.Width;
                    dragHeight = dragView.Height;
                    xWidth     = dragWidth / cellsize;
                    yWidth     = dragHeight / cellsize;
                    lastX      = startX - dx;
                    lastY      = startY - dy;
                    isDragging = true;
                    int newLeft = (int)(lastX / cellsize) * cellsize;
                    int newTop  = (int)(lastY / cellsize) * cellsize;
                    maxX = 10 - xWidth;
                    maxY = 10 - yWidth;

                    selectionRect.Visibility = ViewStates.Visible;
                    selectionRect.BringToFront();
                    //selectionRect.Layout(newLeft, newTop, newLeft + dragWidth, newTop + dragHeight);

                    FrameLayout.LayoutParams gridLayout = (FrameLayout.LayoutParams)selectionRect.LayoutParameters;
                    gridLayout.SetMargins(newLeft, newTop, 0, 0);
                    gridLayout.Width  = dragWidth;
                    gridLayout.Height = dragHeight;
                    selectionRect.LayoutParameters = gridLayout;
                    selectionRect.ForceLayout();
                    selectionRect.SetBackgroundColor(new Color(0, 255, 0, 128));

                    selectionFrame.Visibility = ViewStates.Invisible;
                    selectionFrame.BringToFront();
                    //selectionFrame.Layout(newLeft-2, newTop-2, newLeft + dragWidth+2, newTop + dragHeight+2);
                }
            }
            else if (e.Event.Action == MotionEventActions.Move)
            {
                if (isDragging)
                {
                    lastX = e.Event.GetX() - dx;
                    lastY = e.Event.GetY() - dy;
                    dragView.Layout((int)lastX, (int)lastY, (int)lastX + dragWidth, (int)lastY + dragHeight);
                    int newLeft = (int)(lastX / cellsize);
                    int newTop  = (int)(lastY / cellsize);
                    if (newLeft > maxX)
                    {
                        newLeft = maxX;
                    }
                    if (newTop > maxY)
                    {
                        newTop = maxY;
                    }
                    newLeft *= cellsize;
                    newTop  *= cellsize;
                    Console.WriteLine(string.Format("dragging - {0}, {1}", lastX, lastY));
                    selectionRect.Layout(newLeft, newTop, newLeft + dragWidth, newTop + dragHeight);
                    hitView = FindViewAtLoc((int)(lastX / cellsize), (int)(lastY / cellsize), xWidth, yWidth, dragView);
                    if (hitView == null)
                    {
                        selectionRect.SetBackgroundColor(new Color(0, 255, 0, 128));
                    }
                    else
                    {
                        selectionRect.SetBackgroundColor(new Color(255, 0, 0, 128));
                    }

                    selectionFrame.Visibility = ViewStates.Invisible;
                }
            }
            else if (e.Event.Action == MotionEventActions.Up)
            {
                if (isDragging)
                {
                    isDragging = false;

                    int newX = (int)(lastX / cellsize);
                    int newY = (int)(lastY / cellsize);
                    if (newX > maxX)
                    {
                        newX = maxX;
                    }
                    if (newY > maxY)
                    {
                        newY = maxY;
                    }

                    if (hitView != null)
                    {
                        newX = lastXLoc;
                        newY = lastYLoc;
                    }
                    FrameLayout.LayoutParams gridLayout = (FrameLayout.LayoutParams)dragView.LayoutParameters;
                    gridLayout.SetMargins(newX * cellsize, newY * cellsize, 0, 0);
                    dragView.LayoutParameters = gridLayout;
                    dragView.ForceLayout();

                    Console.WriteLine(string.Format("end drag - {0}, {1}", lastX, lastY));
                    if (newX != lastXLoc || newY != lastYLoc)
                    {
                        UpdateStructureLoc(dragView, newX, newY);
                        isDirty = true;
                    }
                    gridLayout = (FrameLayout.LayoutParams)selectionFrame.LayoutParameters;
                    gridLayout.SetMargins(newX * cellsize - 2, newY * cellsize - 2, 0, 0);
                    gridLayout.Width  = dragWidth + 4;
                    gridLayout.Height = dragHeight + 4;
                    selectionFrame.LayoutParameters = gridLayout;
                    selectionFrame.ForceLayout();
                    selectionFrame.Visibility = ViewStates.Visible;



                    hitView = null;
                    selectionRect.Visibility = ViewStates.Invisible;
                }
            }
            else
            {
                selectionRect.Visibility = ViewStates.Invisible;
                dragView   = null;
                hitView    = null;
                isDragging = false;
                SetSelectedView(null);
            }

            e.Handled = true;
        }
Example #8
0
 private void RefundPurchase(StructureObj newStruct)
 {
     // todo - refund it because it doesn't fit
 }
Example #9
0
 private StructureObj RectInWhichStructure(int xLoc, int yLoc, int width, int height, StructureObj stopStruct)
 {
     foreach (StructureObj curStruct in parent.pop.curSector.structures)
     {
         if ((!(xLoc > curStruct.xLoc + curStruct.xSize || xLoc + width < curStruct.xLoc)) &&
             (!(yLoc > curStruct.yLoc + curStruct.ySize || yLoc + height < curStruct.yLoc)) &&
             (curStruct != stopStruct))
         {
             return(curStruct);
         }
     }
     return(null);
 }
Example #10
0
 private View ViewForStructure(StructureObj theStruct)
 {
     return(structureGrid.FindViewWithTag(theStruct.Id));
 }
Example #11
0
        /// <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);
        }
Example #12
0
        /// <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>
        public override void OnMouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            //Create a new structure on left click
            if (e.Button == MouseButtons.Left)
            {
                WebAnnotation.Objects.StructureTypeObj obj = Viking.UI.State.SelectedObject as WebAnnotation.Objects.StructureTypeObj;
            //  Debug.Assert(obj == null, "This command should be inactive if Selected Object isn't a StructureTypeObj");
                if(obj == null)
                    return;

                GridVector2 WorldPos = Parent.ScreenToWorld(e.X, e.Y);

                //Transform from volume space to section space if we need to
                GridVector2 SectionPos = Parent.Section.VolumeToSection(WorldPos);

                StructureObj newStruct = new StructureObj(obj);

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

                if (obj.Parent == null)
                {
                    StructureStore.CreateStructure(newStruct, newLocation);
                }
                else
                {
                    Parent.CurrentCommand = new LinkStructureToParentCommand(Parent, newStruct, newLocation);
                }

            }
            else if (e.Button == MouseButtons.Right)
            {
                this.Deactivated = true;
            }

            base.OnMouseClick(sender, e);
        }
        private void AddStructureLink(StructureObj SourceObj, SortedList<long, GridVector2> SourcePositions, long TargetStructID)
        {
            ConcurrentDictionary<long, LocationObj> LinkedLocationsOnSection;
            bool success = LocationsForStructure.TryGetValue(TargetStructID, out LinkedLocationsOnSection);
            if (success == false)
                return;

            SortedList<long, GridVector2> TargetPositions = new SortedList<long, GridVector2>(LinkedLocationsOnSection.Count);

            foreach (long locID in LinkedLocationsOnSection.Keys)
            {
                GridVector2 position;
                bool Success = TransformedLocationPositionDict.TryGetValue(locID, out position);

                if (Success)
                    TargetPositions.Add(locID, position);
            }

            long BestSourceLocID = -1;
            long BestTargetLocID = -1;
            GridVector2 Origin = new GridVector2();
            GridVector2 Destination = new GridVector2();
            double MinDistance = double.MaxValue;

            //Brute force a search for the shortest distance between the two structures.
            foreach (long SourceID in SourcePositions.Keys)
            {
                GridVector2 SourcePos = SourcePositions[SourceID];

                foreach (long TargetID in TargetPositions.Keys)
                {
                    GridVector2 TargetPos = TargetPositions[TargetID];

                    double dist = GridVector2.Distance(SourcePos, TargetPos);
                    if (dist < MinDistance)
                    {
                        BestSourceLocID = SourceID;
                        BestTargetLocID = TargetID;
                        Origin = SourcePos;
                        Destination = TargetPos;
                        MinDistance = dist;
                    }
                }
            }

            //Could not find a pair
            if (MinDistance == double.MaxValue)
                return;

            StructureObj TargetStruct = Store.Structures.GetObjectByID(TargetStructID);
            GridLineSegment lineSegment = new GridLineSegment(Origin, Destination);
            StructureLinkObj StructLink = new StructureLinkObj(SourceObj.ID, TargetStructID,
                                                               Locations[BestSourceLocID],
                                                               Locations[BestTargetLocID],
                                                               lineSegment);

            StructLink.AfterDelete += StructureLinkDeletedEventHandler;

            if (StructureLinksSearch.Contains(lineSegment))
            {
                StructureLinkObj oldLink = StructureLinksSearch[lineSegment];
                oldLink.AfterDelete -= StructureLinkDeletedEventHandler;
                StructureLinksSearch.Remove(lineSegment);
            }

            StructureLinksSearch.Add(lineSegment, StructLink);
        }
        /// <summary>
        /// All locations which are linked get a line between them
        /// </summary>
        internal void AddStructureLinks(StructureObj obj)
        {
            if (obj.Links.Length == 0 && obj.ParentID == null)
                return;

            lock (LockObject)
            {
                //The link may have been created to a structure on an adjacent section
                ConcurrentDictionary<long, LocationObj> LocationsOnSection = null;
                bool Success = LocationsForStructure.TryGetValue(obj.ID, out LocationsOnSection);
                if (Success == false)
                    return;

                SortedList<long, GridVector2> SourcePositions = new SortedList<long, GridVector2>();

                foreach (long locID in LocationsOnSection.Keys)
                {
                    GridVector2 position;
                    Success = TransformedLocationPositionDict.TryGetValue(locID, out position);
                    if (Success)
                        SourcePositions.Add(locID, TransformedLocationPositionDict[locID]);
                }

                if (obj.ParentID != null)
                {
                    if (obj.ParentID.HasValue)
                    {
                        AddStructureLink(obj, SourcePositions, obj.ParentID.Value);
                    }
                }

                foreach (WebAnnotation.Service.StructureLink link in obj.Links)
                {
                    //Just look for links where this structure is the source, cuts search in half
                    if (link.TargetID == obj.ID)
                        continue;

                    AddStructureLink(obj, SourcePositions, link.TargetID);

                }
            }
        }