protected override void DrawRectangle(CGContext context, AnnotationPoint startPoint, AnnotationPoint endPoint) { var rect = new System.Drawing.RectangleF(startPoint.X, startPoint.Y, endPoint.X - startPoint.X, endPoint.Y - startPoint.Y); context.AddRect(rect); context.StrokeRect(rect); }
private AnnotationPoint ToAnnotationPoint(PointF pt) { var point = new AnnotationPoint() { X = pt.X, Y = pt.Y }; return(point); }
public void OnNextPoint(AnnotationPoint point) { // translate points from surface size to 0-1 range size var pt = new AnnotationPoint { X = point.X / surfaceSize.Width, Y = point.Y / surfaceSize.Height }; if (pt.X < 0 || pt.Y < 0 || pt.X > 1 || pt.Y > 1) return; // reject this point if outside bounds if (type == AnnotationType.AdHoc) this.annotation.Points.Add(pt); // ad hoc always just adds more points else { // the rest will only have at most two points, the first point and the last point touched if (this.annotation.Points.Count <= 1) this.annotation.Points.Add(pt); else this.annotation.Points[1] = pt; } }
public Node(Location location) { this.ID = location.ID; this.position = location.VolumePosition; this.radius = location.Radius; if (location.Links == null) this.links = new List<long>(); else this.links = location.Links.ToList(); }
public Graph computeGraph(long structureid) { Graph graph = new Graph(); List<long> LocationIds = new List<long>(); LocationIds.Add(structureid); Structure structure = null; Location[] results = new Location[0]; using (AnnotateStructuresClient proxyStructures = State.CreateStructureClient()) { structure = proxyStructures.GetStructureByID(structureid, false); using (AnnotateLocationsClient proxyLocations = State.CreateLocationsClient()) { results = proxyLocations.GetLocationsForStructure(structureid); } proxyStructures.Close(); } using (AnnotateStructureTypesClient proxyStructureType = State.CreateStructureTypeClient()) { StructureType type = proxyStructureType.GetStructureTypeByID(structure.TypeID); if(type != null) graph.DefaultNodeColor = type.Color; proxyStructureType.Close(); } foreach (Location location in results) { AnnotationPoint p = new AnnotationPoint(); p.X = location.VolumePosition.X * 2.18; p.Y = location.VolumePosition.Y * 2.18; p.Z = location.VolumePosition.Z * 90; location.Radius *= 2.18; location.VolumePosition = p; Node node = new Node(location); graph.Nodes.Add(location.ID, node); } graph.originalNodes = new Dictionary<long, Node>(graph.Nodes); graph.createEdges(); graph.generateStats(Convert.ToInt32(structureid)); //FileStream temp = new FileStream("E:\\src\\info.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); //StreamWriter wr = new StreamWriter(temp); //wr.WriteLine(proxy.State); //wr.Close(); temp.Close(); graph.reduceEdges(); graph.createEdgeList(); graph.createSynapses(Convert.ToInt32(structureid)); return graph; }
protected abstract void DrawLine(TContext context, AnnotationPoint startPoint, AnnotationPoint endPoint);
public static AnnotationPoint ConvertFromStandardRangeToSurface(AnnotationPoint point, AnnotationSurfaceSize surface) { return new AnnotationPoint { X = point.X * surface.Width, Y = point.Y * surface.Height }; }
private void PopulateLocation(Location newPos, long parentID) { newPos.ParentID = parentID; AnnotationPoint P = new AnnotationPoint(); P.X = 0; P.Y = 0; P.Z = 0; newPos.Position = P; }
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 }); }
public void TestQueryLocationChanges() { AddPrincipalToThread(); AnnotateService target = new AnnotateService(Parameters.TestDatabaseName); // TODO: Initialize to an appropriate value //Create a structure type, a structure, and some links StructureType t = CreatePopulatedStructureType("Test"); long[] IDs = target.UpdateStructureTypes(new StructureType[] { t }); long StructureTypeID = IDs[0]; //Create structure and location Structure newStruct = new Structure(); newStruct.TypeID = StructureTypeID; Location newPos = new Location(); newPos.ParentID = newStruct.ID; AnnotationPoint P = new AnnotationPoint(); P.X = 0; P.Y = 0; P.Z = 0; newPos.Position = P; CreateStructureRetval retval = target.CreateStructure(newStruct, newPos); long StructureID = retval.structure.ID; long LocationAID = retval.location.ID; //Create a second location for the structure Location B = new Location(); B.ParentID = StructureID; P.Z = 0; B.Position = P; B.DBAction = DBACTION.INSERT; IDs = target.Update(new Location[] { B }); long LocationBID = IDs[0]; //Query the locations Location[] Locations = target.GetLocationsForStructure(StructureID); Assert.IsTrue(Locations.Length == 2); //Create a third location for the structure Location C = new Location(); C.ParentID = StructureID; P.Z = 0; C.Position = P; C.DBAction = DBACTION.INSERT; IDs = target.Update(new Location[] { C }); long LocationCID = IDs[0]; //Query all the structures Location LocationA = target.GetLocationByID(LocationAID); Location LocationB = target.GetLocationByID(LocationBID); Location LocationC = target.GetLocationByID(LocationCID); DateTime UpdateTime = new DateTime(LocationC.LastModified, DateTimeKind.Utc); // UpdateTime = UpdateTime.Subtract(new TimeSpan(TimeSpan.TicksPerMillisecond)); //The server only returns changes after the query System.Diagnostics.Debug.WriteLine("UpdateTime: " + UpdateTime.ToFileTime().ToString()); //Check that location C appears when we ask for locations modified after the updatetime long[] deletedIDs; long queryTimeInTicks; Location[] updatedLocations = target.GetLocationChanges(LocationA.Section, UpdateTime.Ticks, out queryTimeInTicks, out deletedIDs); //Nothing was deleted, so this should be true foreach (long id in deletedIDs) { Assert.IsTrue(id != LocationAID, "Found undeleted ID in deleted list"); Assert.IsTrue(id != LocationBID, "Found undeleted ID in deleted list"); Assert.IsTrue(id != LocationCID, "Found undeleted ID in deleted list"); } //Other people could be changing the database, so check the LocationC is in the array, but not A or B bool CFound = false; foreach(Location loc in updatedLocations) { Assert.IsTrue(loc.ID != LocationAID && loc.ID != LocationBID); if (loc.ID == LocationCID) CFound = true; } Assert.IsTrue(CFound, "Could not find location C"); //This will only be true if the test is run on the server UpdateTime = new DateTime(queryTimeInTicks, DateTimeKind.Utc); System.Diagnostics.Debug.WriteLine("UpdateTime: " + UpdateTime.ToFileTime().ToString()); //Delete location B, and check that it shows up in the deleted IDs LocationB.DBAction = DBACTION.DELETE; target.Update(new Location[] { LocationA, LocationB, LocationC }); //Just so I don't reference it again. LocationB = null; updatedLocations = target.GetLocationChanges(LocationA.Section, UpdateTime.Ticks, out queryTimeInTicks, out deletedIDs); //B was deleted, so make sure it is in the results bool BFound = false; foreach (long id in deletedIDs) { if (id == LocationBID) BFound = true; Assert.IsTrue(id != LocationAID); Assert.IsTrue(id != LocationCID); } Assert.IsTrue(BFound); //Other people could be changing the database, so check that neither A or C is in the updated array foreach (Location loc in updatedLocations) { Assert.IsTrue(loc.ID != LocationAID && loc.ID != LocationCID); } //Update A location and delete C LocationA.OffEdge = true; LocationA.DBAction = DBACTION.UPDATE; LocationC.DBAction = DBACTION.DELETE; target.Update(new Location[] { LocationA, LocationC }); LocationC = null; LocationA = target.GetLocationByID(LocationAID); UpdateTime = new DateTime(LocationA.LastModified, DateTimeKind.Utc); // UpdateTime = UpdateTime.Subtract(new TimeSpan(TimeSpan.TicksPerMillisecond)); //The server only returns changes after the query System.Diagnostics.Debug.WriteLine("UpdateTime: " + LocationA.LastModified.ToString()); updatedLocations = target.GetLocationChanges(LocationA.Section, UpdateTime.Ticks, out queryTimeInTicks, out deletedIDs); //Check to see that we find location C in deletedIDs and LocationA in the updated set //Other people could be changing the database, so check the LocationC is in the array, but not A or B bool AFound = false; foreach (Location loc in updatedLocations) { Assert.IsTrue(loc.ID != LocationBID && loc.ID != LocationCID); if (loc.ID == LocationAID) AFound = true; } Assert.IsTrue(AFound, "Could not find changed row in GetLocationChanges"); //C was deleted, so make sure it is in the results CFound = false; foreach (long id in deletedIDs) { if (id == LocationCID) CFound = true; Assert.IsTrue(id != LocationAID); Assert.IsTrue(id != LocationBID); } Assert.IsTrue(CFound); //Wrap up, delete A LocationA.DBAction = DBACTION.DELETE; target.Update(new Location[] { LocationA }); //Delete the structure newStruct = target.GetStructureByID(StructureID, false); newStruct.DBAction = DBACTION.DELETE; target.UpdateStructures(new Structure[] { newStruct }); //Delete the structure type t = target.GetStructureTypeByID(StructureTypeID); t.DBAction = DBACTION.DELETE; target.UpdateStructureTypes(new StructureType[] { t }); }
public void LocationLinkTest() { AddPrincipalToThread(); AnnotateService target = new AnnotateService(Parameters.TestDatabaseName); // TODO: Initialize to an appropriate value //Create a structure type, a structure, and some links StructureType t = CreatePopulatedStructureType("Test"); long[] IDs = target.UpdateStructureTypes(new StructureType[] { t }); long StructureTypeID = IDs[0]; //Create structure and location Structure newStruct = new Structure(); newStruct.TypeID = StructureTypeID; Location newPos = new Location(); newPos.ParentID = newStruct.ID; AnnotationPoint P = new AnnotationPoint(); P.X = 0; P.Y = 0; P.Z = 0; newPos.Position = P; CreateStructureRetval retval = target.CreateStructure(newStruct, newPos); long StructureID = retval.structure.ID; long LocationAID = retval.location.ID; //Create a second location for the structure, linked to the first Location B = new Location(); B.ParentID = StructureID; P.Z = 1; B.Position = P; B.DBAction = DBACTION.INSERT; IDs = target.Update(new Location[] { B } ); long LocationBID = IDs[0]; target.CreateLocationLink(LocationAID, LocationBID); target.DeleteLocationLink(LocationBID, LocationAID); //Delete the locations Location LocationA = target.GetLocationByID(LocationAID); Location LocationB = target.GetLocationByID(LocationBID); LocationA.DBAction = DBACTION.DELETE; LocationB.DBAction = DBACTION.DELETE; target.Update( new Location[] { LocationA, LocationB}); //Delete the structure newStruct = target.GetStructureByID(StructureID, false); newStruct.DBAction = DBACTION.DELETE; target.UpdateStructures(new Structure[] { newStruct }); //Delete the structure type t = target.GetStructureTypeByID(StructureTypeID); t.DBAction = DBACTION.DELETE; target.UpdateStructureTypes(new StructureType[] { t }); }
public void CreateStructureTest() { AddPrincipalToThread(); AnnotateService target = new AnnotateService(Parameters.TestDatabaseName); // TODO: Initialize to an appropriate value StructureType t = CreatePopulatedStructureType("Test"); long[] IDs = target.UpdateStructureTypes(new StructureType[] { t }); long StructureTypeID = IDs[0]; t = target.GetStructureTypeByID(StructureTypeID); Structure newStruct = new Structure(); newStruct.TypeID = t.ID; Location newPos = new Location(); newPos.ParentID = newStruct.ID; AnnotationPoint P = new AnnotationPoint(); P.X = 0; P.Y = 0; P.Z = 0; newPos.Position = P; CreateStructureRetval retval = target.CreateStructure(newStruct, newPos); Structure dbStruct = target.GetStructureByID(retval.structure.ID, false); Location dbPos = target.GetLocationByID(retval.location.ID); Assert.IsTrue(dbStruct != null && dbStruct.ID == retval.structure.ID); Assert.IsTrue(dbPos != null && dbPos.ID == retval.location.ID); dbPos.DBAction = DBACTION.DELETE; target.Update(new Location[] { dbPos }); //Check to make sure there aren't any locations for the structure long queryTimeInTicks; Location[] structLocs = target.GetLocationsForSection(dbStruct.ID, out queryTimeInTicks); Assert.IsTrue(structLocs.Length == 0); dbStruct.DBAction = DBACTION.DELETE; target.UpdateStructures(new Structure[] { dbStruct }); Structure dbStructNull = target.GetStructureByID(retval.structure.ID, false); Location dbPosNull = target.GetLocationByID(retval.location.ID); Assert.IsNull(dbStructNull); Assert.IsNull(dbPosNull); //Delete the structure type t.DBAction = DBACTION.DELETE; target.UpdateStructureTypes(new StructureType[] { t }); }
protected override void DrawLine(CGContext context, AnnotationPoint startPoint, AnnotationPoint endPoint) { context.MoveTo(startPoint.X, startPoint.Y); context.AddLineToPoint(endPoint.X, endPoint.Y); context.StrokePath(); }
private AnnotationPoint ToAnnotationPoint(PointF pt) { var point = new AnnotationPoint() { X = pt.X, Y = pt.Y }; return point; }