예제 #1
0
파일: Edgex.cs 프로젝트: abordt/Viking
 public Edgex(long SourceParentID, long TargetParentID, StructureLink link, string SourceTypeName)
 {
     this.SourceParentID = SourceParentID;
         this.TargetParentID = TargetParentID;
         this.Link = link;
         this.SourceTypeName = SourceTypeName;
 }
예제 #2
0
파일: Queries.cs 프로젝트: abordt/Viking
        public static SortedDictionary<long, List<StructureLink>> GetLinkedStructures(StructureLink[] LinkedStructures)
        {
            SortedDictionary<long, List<StructureLink>> StructIDToLinks = new SortedDictionary<long, List<StructureLink>>();
            foreach (StructureLink link in LinkedStructures)
            {
                List<StructureLink> SourceIDList = null;
                if (!StructIDToLinks.TryGetValue(link.SourceID, out SourceIDList))
                {
                    SourceIDList = new List<StructureLink>();
                }

                SourceIDList.Add(link);
                StructIDToLinks[link.SourceID] = SourceIDList;

                List<StructureLink> TargetIDList = null;
                if (!StructIDToLinks.TryGetValue(link.TargetID, out TargetIDList))
                {
                    TargetIDList = new List<StructureLink>();
                }

                TargetIDList.Add(link);
                StructIDToLinks[link.TargetID] = TargetIDList;
            }

            return StructIDToLinks;
        }
예제 #3
0
파일: Edge.cs 프로젝트: abordt/Viking
 public Edge(long SourceID, long TargetID, long SourceParentID, long TargetParentID,
             StructureLink Link, string SourceTypeName, float factor )
 {
     this.SourceID = SourceID;
     this.TargetID = TargetID;
     this.SourceParentID = SourceParentID;
     this.TargetParentID = TargetParentID;
     this.Link = Link;
     this.SourceTypeName = SourceTypeName;
     this.Strength = factor;
 }
예제 #4
0
        private void DrawStructureLink(StructureLink link, Matrix ViewProjMatrix, float time_offset)
        {
            int alpha = 128;
            if (LastMouseOverObject == link)
            {
                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)(255),
                (byte)(255),
                (byte)(255),
                (byte)(alpha));

            if (link.Bidirectional)
            {
                _Parent.LineManager.Draw(link.lineGraphic, (float)link.Radius, color,
                                         ViewProjMatrix, time_offset, "AnimatedBidirectional");
            }
            else
            {
                _Parent.LineManager.Draw(link.lineGraphic, (float)link.Radius, color,
                                         ViewProjMatrix, time_offset, "AnimatedLinear");
            }
        }
예제 #5
0
        /// <summary>
        /// All locations which are linked get a line between them
        /// </summary>
        internal void RemoveStructureLinks(IEnumerable<StructureLinkObj> structureLinks)
        {
            if (structureLinks == null)
                return; 

            foreach(StructureLinkObj structLinkObj in structureLinks)
            {
                if (structLinkObj == null)
                    continue;

                StructureLink link = new StructureLink(structLinkObj); 
                GridLineSegment line; 
                if(StructureLinksSearch != null)
                    StructureLinksSearch.TryRemove(link, out line); 

            }
        }
예제 #6
0
        /// <summary>
        /// All locations which are linked get a line between them
        /// </summary>
        internal void AddStructureLinks(IEnumerable<StructureLinkObj> structureLinks)
        {
            foreach(StructureLinkObj structLinkObj in structureLinks)
            {
                if (structLinkObj == null)
                    continue; 
                
                if (structLinkObj.SourceID == structLinkObj.TargetID)
                {
                    Trace.WriteLine("Something is wrong on the server, struct ID links to itself: " + structLinkObj.SourceID.ToString());
                    Store.StructureLinks.Remove(structLinkObj);
                    Store.StructureLinks.Save();
                    continue; //Something is wrong in the database
                }
                //The link may have been created to a structure on an adjacent section
                ConcurrentDictionary<long, Location_CanvasViewModel> SourceLocations = null;
                bool Success = LocationsForStructure.TryGetValue(structLinkObj.SourceID, out SourceLocations);
                if (Success == false)
                    continue;

                ConcurrentDictionary<long, Location_CanvasViewModel> TargetLocations = null;
                Success = LocationsForStructure.TryGetValue(structLinkObj.TargetID, out TargetLocations);
                if (Success == false)
                    continue;

                if(SourceLocations.Count == 0 || TargetLocations.Count == 0)
                    continue; 
                
                //Brute force a search for the shortest distance between the two structures.
                double MinDistance = double.MaxValue;
                Location_CanvasViewModel BestSourceLoc = null; 
                Location_CanvasViewModel BestTargetLoc = null;

                foreach (Location_CanvasViewModel SourceLoc in SourceLocations.Values)
                {
                    foreach (Location_CanvasViewModel TargetLoc in TargetLocations.Values)
                    {
                        double dist = GridVector2.Distance(SourceLoc.VolumePosition, TargetLoc.VolumePosition);
                        if (dist < MinDistance)
                        {
                            BestSourceLoc = SourceLoc;
                            BestTargetLoc = TargetLoc;
                            MinDistance = dist;
                        }
                    }
                }

                //OK, create a StructureLink between the locations
                StructureLink StructLink = new StructureLink(structLinkObj, BestSourceLoc, BestTargetLoc);

                //An error can occur if two structures are linked to each other twicea, once as a source and once as a destination.
                StructureLinksSearch.TryAdd(StructLink.lineSegment, StructLink);
            }
        }
예제 #7
0
        public void CreateStructureLinkTest()
        {
            AddPrincipalToThread();

            AnnotateService target = new AnnotateService(Parameters.TestDatabaseName); // TODO: Initialize to an appropriate value

            StructureType t = CreatePopulatedStructureType(Parameters.TestDatabaseName);

            long[] IDs = target.UpdateStructureTypes(new StructureType[] { t });
            long[] IDsA; //ID's for struct A
            long[] IDsB; //ID's for struct B
            long StructureTypeID = IDs[0];

            t = target.GetStructureTypeByID(StructureTypeID);

            Structure newStructA = new Structure();
            Structure newStructB = new Structure();

            newStructA.TypeID = t.ID;
            newStructB.TypeID = t.ID;

            //Create location A
            Location newPosA = new Location();
            newPosA.ParentID = newStructA.ID;

            AnnotationPoint P = new AnnotationPoint();
            P.X = 0;
            P.Y = 0;
            P.Z = 0;
            newPosA.Position = P;

            CreateStructureRetval retvalA = target.CreateStructure(newStructA, newPosA);

            //CreateLocationB
            Location newPosB = new Location();
            newPosB.ParentID = newStructB.ID;

            AnnotationPoint Pb = new AnnotationPoint();
            Pb.X = -1;
            Pb.Y = -1;
            Pb.Z = -1;
            newPosA.Position = Pb;

            CreateStructureRetval retvalB = target.CreateStructure(newStructB, newPosB);

            Structure dbStructA = target.GetStructureByID(retvalA.structure.ID, false);
            Location dbPosA = target.GetLocationByID(retvalA.location.ID);

            Structure dbStructB = target.GetStructureByID(retvalB.structure.ID, false);
            Location dbPosB = target.GetLocationByID(retvalB.location.ID);

            Assert.IsTrue(dbStructA != null && dbStructA.ID == retvalA.structure.ID);
            Assert.IsTrue(dbPosA != null && dbPosA.ID == retvalA.location.ID);
            Assert.IsTrue(dbStructB != null && dbStructB.ID == retvalB.structure.ID);
            Assert.IsTrue(dbPosB != null && dbPosB.ID == retvalB.location.ID);

            //Link the structures
            StructureLink link = new StructureLink();
            link.SourceID = retvalA.structure.ID;
            link.TargetID = retvalB.structure.ID;

            target.CreateStructureLink(link);

            //Delete the link
            link.DBAction = DBACTION.DELETE;

            target.UpdateStructureLinks(new StructureLink[] { link });

            dbPosA.DBAction = DBACTION.DELETE;
            dbPosB.DBAction = DBACTION.DELETE;
            target.Update(new Location[] { dbPosA, dbPosB });

            //Check to make sure there aren't any locations for the structure
            long queryTimeInTicks;
            Location[] structLocs = target.GetLocationsForSection(dbStructA.ID, out queryTimeInTicks);
            Assert.IsTrue(structLocs.Length == 0);

            dbStructA.DBAction = DBACTION.DELETE;
            dbStructB.DBAction = DBACTION.DELETE;
            target.UpdateStructures(new Structure[] { dbStructA, dbStructB });

            Structure dbStructANull = target.GetStructureByID(retvalA.structure.ID, false);
            Location dbPosANull = target.GetLocationByID(retvalA.location.ID);
            Structure dbStructBNull = target.GetStructureByID(retvalB.structure.ID, false);
            Location dbPosBNull = target.GetLocationByID(retvalB.location.ID);

            Assert.IsNull(dbStructANull);
            Assert.IsNull(dbPosANull);
            Assert.IsNull(dbStructBNull);
            Assert.IsNull(dbPosBNull);

            //Delete the structure type
            t.DBAction = DBACTION.DELETE;
            target.UpdateStructureTypes(new StructureType[] { t });
        }
예제 #8
0
        public StructureLink[] GetLinkedStructuresByID(long ID)
        {
            try
            {
                IQueryable<DBStructureLink> queryResults = from l in db.DBStructureLinks where (l.SourceID == ID || l.TargetID == ID) select l;
                List<StructureLink> retList = new List<StructureLink>(queryResults.Count());
                foreach (DBStructureLink dbl in queryResults)
                {
                    StructureLink link = new StructureLink(dbl);
                    retList.Add(link);
                }
                return retList.ToArray();
            }
            catch (System.ArgumentNullException)
            {
                //This means there was no row with that ID;
                Debug.WriteLine("Could not find StructureLinks for ID: " + ID.ToString());
            }
            catch (System.InvalidOperationException e)
            {
                //This means there was no row with that ID;
                Debug.WriteLine("Could not find StructureLinks for ID: " + ID.ToString());
            }

            return new StructureLink[0];
        }
예제 #9
0
        public StructureLink CreateStructureLink(StructureLink link)
        {
            DBStructureLink newRow = new DBStructureLink();
            link.Sync(newRow);
            db.DBStructureLinks.InsertOnSubmit(newRow);
            db.SubmitChanges();

            StructureLink newLink = new StructureLink(newRow);
            return newLink;
        }
예제 #10
0
        public void UpdateStructureLinks(StructureLink[] links)
        {
            //Stores the ID of each object manipulated for the return value
            try
            {
                for (int iObj = 0; iObj < links.Length; iObj++)
                {
                    StructureLink obj = links[iObj];
                    DBStructureLink DBObj = null;

                    switch (obj.DBAction)
                    {
                        case DBACTION.INSERT:

                            DBObj = new DBStructureLink();
                            obj.Sync(DBObj);
                            db.DBStructureLinks.InsertOnSubmit(DBObj);
                            break;
                        case DBACTION.UPDATE:

                            try
                            {
                                DBObj = (from u in db.DBStructureLinks
                                         where u.SourceID == obj.SourceID &&
                                               u.TargetID == obj.TargetID
                                         select u).Single();
                            }
                            catch (System.ArgumentNullException e)
                            {
                                Debug.WriteLine("Could not find structuretype to update: " + obj.ToString());
                                break;
                            }
                            catch (System.InvalidOperationException e)
                            {
                                Debug.WriteLine("Could not find structuretype to update: " + obj.ToString());
                                break;
                            }

                            obj.Sync(DBObj);
                            //  db.DBStructureTypes.(updateType);
                            break;
                        case DBACTION.DELETE:
                            try
                            {
                                DBObj = (from u in db.DBStructureLinks
                                         where u.SourceID == obj.SourceID &&
                                               u.TargetID == obj.TargetID
                                         select u).Single();
                            }
                            catch (System.ArgumentNullException e)
                            {
                                Debug.WriteLine("Could not find structuretype to delete: " + obj.ToString());
                                break;
                            }
                            catch (System.InvalidOperationException e)
                            {
                                Debug.WriteLine("Could not find structuretype to update: " + obj.ToString());
                                break;
                            }

                            db.DBStructureLinks.DeleteOnSubmit(DBObj);

                            break;
                    }
                }

                db.SubmitChanges();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                throw e;
            }

            //Recover the ID's for new objects
            return;
        }