public List <INodeItem> PickUpInOutItem(INodeParent item) { this.pickedUpItem = item; List <INodeItem> olditems = new List <INodeItem>(); if (connectedNodes.ContainsKey(item)) { List <INodeItem> needClear = new List <INodeItem>(); for (int i = 0; i < connectedNodes[item].Count; i++) { INodeItem nodeItem = connectedNodes[item][i]; needClear.Add(nodeItem); INodeItem target = nodeItem.ConnectedNode; connectedNodes[target.Body].Remove(target); Debug.Log(connectedNodes[item][i].Detach()); olditems.Add(nodeItem); olditems.Add(target); } for (int i = 0; i < needClear.Count; i++) { connectedNodes[item].Remove(needClear[i]); } } return(olditems); }
void BuildViewCtrl_Populated(INodeItem nodeItem, NodeItemView node, bool bPopulatedFieldsOnly) { if (null == nodeItem) { return; } ISchemaItem item = nodeItem.Schema; NodeItemView subNode = null; if ((item.IsGroup && nodeItem.AnySubItemHasRepetition) || item.IsMessage || (!item.RepetitionContainerNode && !item.StructureDefOnlyNode)) { if (null == item) { return;//dead end } subNode = new NodeItemView(); FillViewInfo(nodeItem, subNode); BuildViewCtrl_Fields(nodeItem, subNode, bPopulatedFieldsOnly); node.Nodes.Add(subNode); } else { subNode = node; } foreach (INodeItem sub in nodeItem.Nodes) { BuildViewCtrl_Populated(sub, subNode, bPopulatedFieldsOnly); } }
void BuildViewCtrl_Schema(INodeItem nodeItem, NodeItemView node) { if (null == nodeItem) { return; } ISchemaItem item = nodeItem.Schema; NodeItemView subNode = null; if (!item.RepetitionContainerNode && (item.StructureDefOnlyNode || item.IsMessage)) { if (null == item) { return;//dead end } subNode = new NodeItemView(); FillViewInfo(nodeItem, subNode); BuildViewCtrl_Fields(nodeItem, subNode, false); node.Nodes.Add(subNode); } else { subNode = node; } foreach (INodeItem sub in nodeItem.Nodes) { BuildViewCtrl_Schema(sub, subNode); } }
public static void Add(INodeItem item) { if (item is Sensor) { if (_sensors.Contains(item)) return; _sensors.Add(item as Sensor); } }
public INodeItem Detach() { INodeItem outItem = ConnectedNode; if (ConnectedNode != null) { ConnectedNode.ConnectedNode = null; ConnectedNode = null; } return(outItem); }
public void AddValue(INodeItem nodeItem) { if (!(nodeItem is Sensor)) return; Sensor sensor = (Sensor)nodeItem; try { string query = "SELECT Id FROM Sensors WHERE Name = @name"; SqlCommand cmd = new SqlCommand(query, _connection); cmd.Parameters.AddWithValue("name", sensor.Name); var sensorId = cmd.ExecuteScalar(); if (sensorId == null) { string insertQuery = "INSERT INTO Sensors (Name, Description, Type) VALUES (@name, @description, @type)"; SqlCommand insertCmd = new SqlCommand(insertQuery, _connection); insertCmd.Parameters.AddWithValue("name", sensor.Name); insertCmd.Parameters.AddWithValue("description", sensor.Description); insertCmd.Parameters.AddWithValue("type", sensor.Type); insertCmd.ExecuteNonQuery(); sensorId = cmd.ExecuteScalar(); } string readingQuery = "INSERT INTO Readings (SensorId, Time, Value) VALUES (@sensorId, @time, @value)"; SqlCommand readingCmd = new SqlCommand(readingQuery, _connection); readingCmd.Parameters.AddWithValue("sensorId", sensorId); readingCmd.Parameters.AddWithValue("time", sensor.Time); readingCmd.Parameters.AddWithValue("value", sensor.Value); readingCmd.ExecuteNonQuery(); } catch (Exception ex) { string msg = string.Format("Unable to insert reading into database for sensor {0}.", sensor.Name); ErrorLogger.LogException(LogLevel.Error, msg, ex); return; } }
void BuildViewCtrl_All(INodeItem nodeItem, NodeItemView node) { if (null == nodeItem) { return; } ISchemaItem item = nodeItem.Schema; NodeItemView subNode = null; bool IsSchemaItem = (!item.RepetitionContainerNode && (item.StructureDefOnlyNode || item.IsMessage)); bool IsContentItem = ((item.IsGroup && nodeItem.AnySubItemHasRepetition) || item.IsMessage || (!item.RepetitionContainerNode && !item.StructureDefOnlyNode)); bool ParentContainsContentRep = false; if (nodeItem.ParentItem != null) { if (nodeItem.ParentItem.Schema.RepetitionContainerNode) { ParentContainsContentRep = nodeItem.ParentItem.Nodes.Count > 1; } } if ((IsSchemaItem && !ParentContainsContentRep) || IsContentItem) { if (null == item) { return;//dead end } subNode = new NodeItemView(); FillViewInfo(nodeItem, subNode); BuildViewCtrl_Fields(nodeItem, subNode, false); node.Nodes.Add(subNode); } else { subNode = node; } foreach (INodeItem sub in nodeItem.Nodes) { BuildViewCtrl_All(sub, subNode); } }
public bool FindConnectableObject() { if (pickedUpItem != null) { INodeItem tempNode; foreach (var item in pickedUpItem.ChildNodes) { if (FindInstallableNode(item, out tempNode)) { activeNode = item; targetNode = tempNode; return(true); } } } activeNode = null; targetNode = null; return(false); }
void FillViewInfo(INodeItem nodeItem, NodeItemView tvc) { if (null == nodeItem) { return; } ISchemaItem schema = nodeItem.Schema; tvc.Name = schema.ItemName; tvc.Text = schema.ItemName; tvc.Tag = null; tvc.Model = this; if (schema.IsGroup || schema.IsMessage) { tvc.Expand = true; } }
private bool FindInstallableNode(INodeItem item, out INodeItem node) { Collider[] colliders = Physics.OverlapSphere(item.Pos, sphereRange, LayerMask.GetMask(LayerConst.nodeLayer)); if (colliders != null && colliders.Length > 0) { foreach (var collider in colliders) { NodeItemBehaiver tempNode = collider.GetComponent <NodeItemBehaiver>(); //主被动动连接点,非自身点,相同名,没有建立连接 if (tempNode.Body != item.Body && tempNode.Info.nodeName == item.Info.nodeName && tempNode.ConnectedNode == null) { if (tempNode.connectAble.Find((x) => x.itemName == item.Body.Name && x.nodeId == item.Info.nodeID) != null) { node = tempNode; return(true); } } } } node = null; return(false); }
public void PutDownInOutItem(bool connected) { if (connected) { if (!connectedNodes.ContainsKey(pickedUpItem)) { connectedNodes[pickedUpItem] = new List <INodeItem>(); } connectedNodes[pickedUpItem].Add(activeNode); if (!connectedNodes.ContainsKey(TargetNode.Body)) { connectedNodes[TargetNode.Body] = new List <INodeItem>(); } connectedNodes[TargetNode.Body].Add(targetNode); } pickedUpItem = null; targetNode = null; activeNode = null; }
public bool Attach(INodeItem item) { item.ConnectedNode = this; ConnectedNode = item; return(true); }
void BuildViewCtrl_Fields(INodeItem nodeItem, NodeItemView node, bool bPopulatedFieldsOnly) { for (int seq = 0; seq < nodeItem.Fields.Count; seq++) { if (!bPopulatedFieldsOnly) { if (nodeItem.Fields[seq].Repetitions.Count == 0) { NodeItemView subNode = new NodeItemView(); subNode.Name = nodeItem.Schema.ItemName + "-" + (seq + 1); subNode.Text = nodeItem.Schema.ItemName + "-" + (seq + 1); subNode.Text += " (" + nodeItem.Fields[seq].FieldFactory.NameFromType + ")"; subNode.Value = ""; subNode.Tag = nodeItem.Fields[seq]; subNode.Model = this; subNode.DataType = nodeItem.Fields[seq].FieldFactory.NameFromType; subNode.NodeType = "field"; subNode.IsPopulated = false; node.Nodes.Add(subNode); } } for (int rep = 0; rep < nodeItem.Fields[seq].Repetitions.Count; rep++) { bool subcomphasvalue = false; NodeItemView subNode = new NodeItemView(); subNode.Name = nodeItem.Schema.ItemName + "-" + (seq + 1); subNode.Text = nodeItem.Schema.ItemName + "-" + (seq + 1); IField f = nodeItem.Fields[seq].Repetitions[rep]; if (!f.IsEmpty) { if (!f.HasSubComponents) { subNode.NodeType = "field"; } subNode.IsPopulated = true; if (rep > 0) { subNode.Text += "(rep " + rep + ")" + ": " + f.Value; } else { subNode.Text += ": " + f.Value; } subNode.Rep = rep; subNode.Value = f.Value; subNode.Tag = f; subNode.Model = this; } if (f.HasSubComponents) { //add parent's wholesome value { string DeepValue = f.DeepValue; if (!string.IsNullOrEmpty(DeepValue)) { subNode.IsPopulated = true; if (rep > 0) { subNode.Text += "(rep " + rep + ")" + ": " + DeepValue; } else { subNode.Text += ": " + DeepValue; } subNode.Rep = rep; subNode.Value = DeepValue; subNode.Tag = f; subNode.Model = this; } } for (int subcomp = 0; subcomp < f.Components.Length; subcomp++) { NodeItemView subcompNode = new NodeItemView(); subcompNode.Name = nodeItem.Schema.ItemName + "-" + (seq + 1) + "-" + (subcomp + 1).ToString(); subcompNode.Text = nodeItem.Schema.ItemName + "-" + (seq + 1) + "-" + (subcomp + 1).ToString(); subcompNode.Tag = f.Components[subcomp]; subcompNode.Model = this; if (!f.Components[subcomp].IsEmpty) { subcompNode.NodeType = "field"; subcompNode.IsPopulated = true; if (rep > 0) { subcompNode.Text += "(rep " + rep + ")" + ": " + f.Components[subcomp].Value; } else { subcompNode.Text += ": " + f.Components[subcomp].Value; } subcompNode.Rep = rep; subcompNode.Value = f.Components[subcomp].Value; subcompNode.Tag = f; subcompNode.Model = this; subcomphasvalue = true; } subNode.Nodes.Add(subcompNode); // if (f.Components[subcomp].HasSubComponents) { for (int subcomp1 = 0; subcomp1 < f.Components[subcomp].Components.Length; subcomp1++) { NodeItemView subcompNode1 = new NodeItemView(); subcompNode1.Name = nodeItem.Schema.ItemName + "-" + (seq + 1) + "-" + subcomp + "-" + subcomp1; subcompNode1.Text = nodeItem.Schema.ItemName + "-" + (seq + 1) + "-" + subcomp + "-" + subcomp1; subcompNode1.Tag = f.Components[subcomp].Components[subcomp1]; subcompNode1.Model = this; if (!f.Components[subcomp].Components[subcomp1].IsEmpty) { subcompNode.NodeType = "field"; subcompNode.IsPopulated = true; if (rep > 0) { subcompNode.Text += "(rep " + rep + ")" + ": " + f.Components[subcomp].Components[subcomp1].Value; } else { subcompNode.Text += ": " + f.Components[subcomp].Components[subcomp1].Value; } subcompNode.Rep = rep; subcompNode.Value = f.Components[subcomp].Components[subcomp1].Value; subcompNode.Tag = f; subcompNode.Model = this; subcomphasvalue = true; } subcompNode.Nodes.Add(subcompNode1); } } } } subNode.Text += " (" + nodeItem.Fields[seq].FieldFactory.NameFromType + ")"; subNode.DataType = nodeItem.Fields[seq].FieldFactory.NameFromType; if (!f.IsEmpty || !bPopulatedFieldsOnly || subcomphasvalue) { node.Nodes.Add(subNode); } } } }