/// <summary> /// Get the object at the hit point /// </summary> /// <param name="p">The point to hit (in document co-ordinates)</param> /// <returns>The object, null if no object under the point</returns> private IGraphObject GetHitObjectInternal(PointF p) { IGraphObject match = null; for (int i = _nodes.Count; i > 0; --i) { GraphNode s = _nodes[i - 1]; if (s.HitTest(p)) { match = s; break; } } if (match == null) { foreach (var l in _lines) { if (l.HitTest(p)) { match = l; break; } } } return(match); }
/// <summary> /// Select an object by point /// </summary> /// <param name="p">The point to select (in document co-ordinates)</param> /// <returns>The graph object selected, null if not nothing selected</returns> private IGraphObject SelectObjectInternal(PointF p) { IGraphObject match = GetHitObjectInternal(p); if (match != null) { SelectedObject = match; if (match is GraphNode) { GraphNode node = (GraphNode)match; _nodes.ForEach(n => n.Z = 0); node.Z = 1; MoveNodeToTop(node); } } else { SelectedObject = null; } Invalidate(); return(match); }
public static object TreatData(object Data, Graph Graph) { if (Data is IDictionary) { Dictionary <string, object> d = Data as Dictionary <string, object>; if (d.ContainsKey("type") && d.ContainsKey("id")) { string id = d["id"] as string; IGraphObject variable = Graph.AssociatedInterlink.GetLinkedVariableByID(id); if (d["type"] as string != variable.GetObjectType()) { throw new Exception("Types for variable " + id + " do not match: " + (d["type"] as string) + " != " + variable.GetObjectType()); } return(variable); } else { throw new Exception("TODO"); } } else { return(Data); } }
private void GraphEditorClass_MouseDown(object sender, MouseEventArgs e) { PointF mousePos = ClientToDocumentPoint(new PointF(e.X, e.Y)); if (_heldButton == MouseButtons.None) { if ((e.Button == MouseButtons.Left) && (ModifierKeys != Keys.Control)) { SelectObjectInternal(mousePos); _lastDragPoint = mousePos; _heldButton = e.Button; _draggingMode = DraggingMode.MoveNode; } else if ((e.Button == MouseButtons.Middle) || ((e.Button == MouseButtons.Left) && (ModifierKeys == Keys.Control))) { IGraphObject s = SelectObjectInternal(mousePos); if ((s != null) && (s is GraphNode)) { _lastDragPoint = mousePos; _heldButton = e.Button; _draggingMode = DraggingMode.DrawLine; } else if (s == null) { _lastDragPoint = mousePos; _heldButton = e.Button; _draggingMode = DraggingMode.ScrollWindow; this.Cursor = Cursors.SizeAll; } } } Focus(); }
private void ShowPublishResult(String message, IGraphObject result, FacebookRequestError error) { String title = null; String alertMessage = null; if (error == null) { title = GetString(Resource.String.success); var cls = Java.Lang.Class.ForName("hellofacebooksample.HelloFacebookSampleAcvitity_GraphObjectWithId"); var obj = (Java.Lang.Object)result.Cast(cls); Java.Lang.Reflect.Method m = obj.Class.GetMethod("getId"); String id = (String)m.Invoke(obj); alertMessage = GetString(Resource.String.successfully_posted_post, message, id); } else { title = GetString(Resource.String.error); alertMessage = error.ErrorMessage; } new AlertDialog.Builder(this) .SetTitle(title) .SetMessage(alertMessage) .SetPositiveButton(Resource.String.ok, (object sender, DialogClickEventArgs e) => {}) .Show(); }
public static string DebugOutput(this IGraphObject obj) { if (obj is IEdge edge) { return($"{edge.Id} ({edge.FromNodeId} -> {edge.ToNodeId})"); } return(obj.Id); }
/// <summary> /// Delete an object from the graph /// </summary> /// <param name="obj">The object to delete</param> public void DeleteObject(IGraphObject obj) { if (obj is GraphLine) { DeleteLine(obj as GraphLine); } else if (obj is GraphNode) { DeleteNode(obj as GraphNode); } }
public static string GetGraphObjectInfo(IGraphObject graphObject) { var sb = new StringBuilder(); sb.AppendLine($"Тип: {graphObject.TypeName}"); sb.AppendLine($"Цвета: "); foreach (var item in graphObject.Colors) { sb.AppendLine($" {item}"); } sb.AppendLine($"Вершины: "); foreach (var item in graphObject.Vertices) { sb.AppendLine($" {item}"); } return(sb.ToString()); }
public static Graph LoadMultipleFiles(IEnumerable <string> resourcePaths, IFileProvider fileProvider, ExternalRessourcesLoadingPolicy loadingPolicy) { if (fileProvider == null) { throw new NullReferenceException("FileProvider implementation is not specified."); } IEnumerable <StreamReader> streams = new List <StreamReader>(); streams = resourcePaths.Select(p => fileProvider.GetFileReader(p)); List <GraphXmlDeserializer> deserializers = new List <GraphXmlDeserializer>(); foreach (StreamReader stream in streams) { XDocument xdoc = XDocument.Load(stream); stream.Close(); GraphXmlDeserializer gds = new GraphXmlDeserializer(); gds.ParseFile(xdoc); deserializers.Add(gds); } GraphXmlDeserializer main = deserializers[0]; for (int i = 1; i < deserializers.Count; i++) { main.Merge(deserializers[i]); } main.ResolveExternalEdges(); main.ResolveAnnotationDeclarations(); Graph g = new Graph(); foreach (IVertex v in main.vertexInstances.Values) { g.AddVertex(v); } foreach (var annotationPair in main.annotationsTable) { IGraphObject target = g.GetElementById(annotationPair.Key); g.AddAnnotations(target, annotationPair.Value); } return(g); }
public IGraphObject GetObjectById(Guid id) { IGraphObject result = null; if (useLookupTable) { object queryResult = connection.ExecuteScalar <ConcreteDbCommand>($"SELECT lookup_table FROM IdType WHERE id = '{id}'"); if (queryResult != null) { string table = queryResult.ToString(); switch (table) { case "Vertex": return(vertexStore.GetElementById(id)); default: return(edgeStore.GetElementById(id, table)); } } } else { try { result = vertexStore.GetElementById(id); } catch { result = edgeStore.GetElementById(id); } if (result == null) { result = edgeStore.GetElementById(id); } } return(result); }
private void ShowPublishResult(String message, IGraphObject result, FacebookRequestError error) { String title = null; String alertMessage = null; if (error == null) { title = GetString(Resource.String.success); String id = ((GraphObjectWithId)result.Cast(Java.Lang.Class.FromType(typeof(GraphObjectWithId)))).Id; alertMessage = GetString(Resource.String.successfully_posted_post, message, id); } else { title = GetString(Resource.String.error); alertMessage = error.ErrorMessage; } new AlertDialog.Builder(this) .SetTitle(title) .SetMessage(alertMessage) .SetPositiveButton(Resource.String.ok, (object sender, DialogClickEventArgs e) => {}) .Show(); }
private void ShowPublishResult(String message, IGraphObject result, FacebookRequestError error) { String title = null; String alertMessage = null; if (error == null) { title = GetString(Resource.String.success); var id = result.GetProperty("id").ToString(); alertMessage = GetString(Resource.String.successfully_posted_post, message, id); } else { title = GetString(Resource.String.error); alertMessage = error.ErrorMessage; } new AlertDialog.Builder(this) .SetTitle(title) .SetMessage(alertMessage) .SetPositiveButton(Resource.String.ok, (object sender, DialogClickEventArgs e) => { OnBackPressed(); }) .Show(); }
public List <Annotation> GetAnnotations(IGraphObject @object) { return(trie.GetAnnotations(@object)); }
private void ShowPublishResult (String message, IGraphObject result, FacebookRequestError error) { String title = null; String alertMessage = null; if (error == null) { title = GetString (Resource.String.success); String id = ((GraphObjectWithId)result.Cast (Java.Lang.Class.FromType (typeof(GraphObjectWithId)))).Id; alertMessage = GetString (Resource.String.successfully_posted_post, message, id); } else { title = GetString (Resource.String.error); alertMessage = error.ErrorMessage; } new AlertDialog.Builder (this) .SetTitle (title) .SetMessage (alertMessage) .SetPositiveButton (Resource.String.ok, (object sender, DialogClickEventArgs e) => {}) .Show (); }
protected override void FinalizeSetUp() { g = new GraphObject(); }
public BasicTraversal(IGraphObject startElement) { _startElement = startElement; }
public IGraphObject AddGraphObject(IGraphObject graphObject) { Nodes.Add(graphObject); return(graphObject); }
private bool IsBatchObject(IGraphObject obj) { return(obj != null && obj.DbUrl == "batch"); }
private void ShowPublishResult (String message, IGraphObject result, FacebookRequestError error) { String title = null; String alertMessage = null; if (error == null) { title = GetString (Resource.String.success); var cls = Java.Lang.Class.ForName ("hellofacebooksample.HelloFacebookSampleAcvitity_GraphObjectWithId"); var obj = (Java.Lang.Object) result.Cast (cls); Java.Lang.Reflect.Method m = obj.Class.GetMethod ("getId"); String id = (String) m.Invoke (obj); alertMessage = GetString (Resource.String.successfully_posted_post, message, id); } else { title = GetString (Resource.String.error); alertMessage = error.ErrorMessage; } new AlertDialog.Builder (this) .SetTitle (title) .SetMessage (alertMessage) .SetPositiveButton (Resource.String.ok, (object sender, DialogClickEventArgs e) => {}) .Show (); }
/// <summary> /// Conducts a undirected Depth First Search (DFS) /// </summary> /// <param name="nodeCriteria"> /// A criteria that is evaluated on nodes visited. /// If true, the node will be included in the result, and all edges (connection to other nodes) will be followed. /// If false, the node will not be included in the result, and the traversal will not folow any more edges from this node. /// </param> /// <returns>Both nodes and edged will be returned in the result.</returns> public List <IGraphObject> UndirectedDFS(long version, Predicate <TNode> nodeCriteria, Predicate <TEdge> edgeCriteria, bool includeNodesWhereCriteriaIsFalse = false) { Queue <IGraphObject> traverseOrder = new Queue <IGraphObject>(); Stack <IGraphObject> stack = new Stack <IGraphObject>(); HashSet <IGraphObject> visited = new HashSet <IGraphObject>(); stack.Push(_startElement); visited.Add(_startElement); while (stack.Count > 0) { IGraphObject p = stack.Pop(); traverseOrder.Enqueue(p); var neighbors = p.NeighborElements(version); foreach (var neighbor in neighbors) { // If we're dealing with an edge if (neighbor is TEdge) { if (!visited.Contains(neighbor)) { visited.Add(neighbor); if (edgeCriteria == null) { stack.Push(neighbor); } else if (edgeCriteria.Invoke((TEdge)neighbor)) { stack.Push(neighbor); } else { if (includeNodesWhereCriteriaIsFalse) { traverseOrder.Enqueue(neighbor); } } } } // We're dealing with a node else { if (!visited.Contains(neighbor)) { visited.Add(neighbor); if (nodeCriteria == null) { stack.Push(neighbor); } else if (nodeCriteria.Invoke((TNode)neighbor)) { stack.Push(neighbor); } else { if (includeNodesWhereCriteriaIsFalse) { traverseOrder.Enqueue(neighbor); } } } } } } return(traverseOrder.ToList()); }
public void RemoveGraphObject(IGraphObject graphObject) { Nodes.Remove(graphObject); }