コード例 #1
0
ファイル: Program.cs プロジェクト: abordt/Viking
        static void CheckOverlap(DBStructureType t, DBStructure structA, DBStructure structB)
        {
            IQueryable<DBLocation> LocsA = from l in db.DBLocations where l.ParentID == structA.ID select l;
            IQueryable<DBLocation> LocsB = from l in db.DBLocations where l.ParentID == structB.ID select l;

            List<DBLocation> listA = new List<DBLocation>();
            List<DBLocation> listB = new List<DBLocation>();

            List<GridVector3> pointsA = new List<GridVector3>();
            List<GridVector3> pointsB = new List<GridVector3>();

            //Scale values
            double XYScale = 2.18;
            double ZScale = 90;

            foreach(DBLocation l in LocsA)
            {
                listA.Add(l);
                pointsA.Add( new GridVector3(l.VolumeX * XYScale, l.VolumeY * XYScale, l.Z * ZScale) );
            }

            foreach (DBLocation l in LocsB)
            {
                listB.Add(l);
                pointsB.Add(new GridVector3(l.VolumeX * XYScale, l.VolumeY * XYScale, l.Z * ZScale));
            }

            if (listB.Count == 0 || listA.Count == 0)
            {
                return;
            }

            //Find the nearest point
            int iA;
            int iB;
            double distance;
            GridVector3.Nearest(pointsA.ToArray(), pointsB.ToArray(), out iA, out iB, out distance);

            if(distance < listA[iA].Radius + listB[iB].Radius)
            {
                Console.WriteLine("[" + structA.ParentID.ToString() + "] " + listA[iA].ParentID.ToString() + " <-> " + listB[iB].ParentID.ToString() + " distance " + distance.ToString());

                long newParentID = structB.ID;

                foreach (DBLocation l in LocsA)
                {
                    l.ParentID = newParentID;
                }

                IQueryable<DBLocationLink> locLinks = from l in db.DBLocationLinks
                                                      where (l.LinkedFrom == listA[iA].ID && l.LinkedTo == listB[iB].ID) ||
                                                            (l.LinkedFrom == listB[iB].ID && l.LinkedTo == listA[iA].ID)
                                                      select l;

                bool ExistingLinkFound = false;
                foreach (DBLocationLink link in locLinks)
                {
                    ExistingLinkFound = true;
                    break;
                }

                if (ExistingLinkFound == false)
                {
                    DBLocationLink link = new DBLocationLink();
                    link.LinkedFrom = listA[iA].ID;
                    link.LinkedTo = listB[iB].ID;
                    link.Username = "******";

                    db.DBLocationLinks.InsertOnSubmit(link);
                }

                //Update structureLinks
                IQueryable<DBStructureLink> linkFrom = from l in db.DBStructureLinks where l.SourceID == structA.ID select l;
                foreach(DBStructureLink l in linkFrom)
                {
                    DBStructureLink newLink = new DBStructureLink();
                    newLink.SourceID = newParentID;
                    newLink.TargetID = l.TargetID;
                    newLink.Username = l.Username;
                    newLink.Tags = l.Tags;
                    newLink.Bidirectional = l.Bidirectional;

                    db.DBStructureLinks.DeleteOnSubmit(l);

                    DBStructureLink existingLink = (from el in db.DBStructureLinks where el.SourceID == newLink.SourceID && el.TargetID == newLink.TargetID select el).SingleOrDefault<DBStructureLink>();
                    if(existingLink == null)
                        db.DBStructureLinks.InsertOnSubmit(newLink);
                }

                IQueryable<DBStructureLink> linkTo = from l in db.DBStructureLinks where l.TargetID == structA.ID select l;
                foreach(DBStructureLink l in linkTo)
                {
                    DBStructureLink newLink = new DBStructureLink();
                    newLink.SourceID = l.SourceID;
                    newLink.TargetID = newParentID;
                    newLink.Username = l.Username;
                    newLink.Bidirectional = l.Bidirectional;

                    newLink.Tags = l.Tags;

                    db.DBStructureLinks.DeleteOnSubmit(l);

                    DBStructureLink existingLink = (from el in db.DBStructureLinks where el.TargetID == newLink.TargetID && el.SourceID == newLink.SourceID select el).SingleOrDefault<DBStructureLink>();
                    if (existingLink == null)
                        db.DBStructureLinks.InsertOnSubmit(newLink);
                }

                db.DBStructures.DeleteOnSubmit(structA);

                db.SubmitChanges();
            }
        }
コード例 #2
0
ファイル: Annotation.generated.cs プロジェクト: abordt/Viking
		partial void DeleteDBLocationLink(DBLocationLink instance);
コード例 #3
0
ファイル: Annotation.generated.cs プロジェクト: abordt/Viking
		partial void UpdateDBLocationLink(DBLocationLink instance);
コード例 #4
0
ファイル: Annotation.generated.cs プロジェクト: abordt/Viking
		partial void InsertDBLocationLink(DBLocationLink instance);
コード例 #5
0
ファイル: LocationLink.cs プロジェクト: abordt/Viking
 /*
 [DataMember]
 public string Username
 {
     get { return _Username; }
     set { _Username = value; }
 }
 */
 public LocationLink(DBLocationLink link)
 {
     _SourceID = link.LinkedFrom;
     _TargetID = link.LinkedTo;
     _Username = link.Username;
 }
コード例 #6
0
ファイル: AnnotateService.cs プロジェクト: abordt/Viking
        private DBLocationLink _CreateLocationLink(long SourceID, long TargetID, string username)
        {
            if(username == null)
                username = ServiceModelUtil.GetUserForCall();

            DBLocationLink newLink = new DBLocationLink();
            DBLocation Source = null;
            DBLocation Target = null;
            try
            {
                Source = (from u in db.DBLocations where u.ID == SourceID select u).Single();
                Target = (from u in db.DBLocations where u.ID == TargetID select u).Single();
            }
            catch (InvalidOperationException e)
            {
                throw new ArgumentException("CreateLocationLink: The specified source or target does not exist", e);
            }

            if (Source == null || Target == null)
            {
                throw new ArgumentException("CreateLocationLink: The specified source or target does not exist");
            }

            if (Source.ParentID != Target.ParentID)
            {
                throw new ArgumentException("Location links can only be created between locations belonging to the same structure");
            }

            newLink.Username = ServiceModelUtil.GetUserForCall();

            //Source and target are poorly named.  Right now source is always the smaller ID value, links are unidirectional
            if (SourceID < TargetID)
            {
                newLink.SourceLocation = Source;
                newLink.TargetLocation = Target;
            }
            else if (SourceID > TargetID)
            {
                newLink.SourceLocation = Target;
                newLink.TargetLocation = Source;
            }

            newLink.Username = username;

            return newLink;
        }