public override void Update() { io = PubSub.Model.Get(GID) as ConnectivityNode; properties.Update(); measurements.Update(); if (!initialized) { panel.Children.Add(properties.Element); panel.Children.Add(measurements.Element); initialized = true; } }
private ResourceDescription CreateNodeResourceDescription(ConnectivityNode cimCNode) { ResourceDescription rd = null; if (cimCNode != null) { long gid = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.CNODE, importHelper.CheckOutIndexForDMSType(DMSType.CNODE)); rd = new ResourceDescription(gid); importHelper.DefineIDMapping(cimCNode.ID, gid); ////populate ResourceDescription PowerTransformerConverter.PopulateNodeProperties(cimCNode, rd, importHelper, report); } return(rd); }
private ResourceDescription CreateConnectivityNodeResourceDecription(ConnectivityNode cimConnectivityNode) { ResourceDescription rd = null; if (cimConnectivityNode != null) { long gid = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.CONNECTIVITYNODE, importHelper.CheckOutIndexForDMSType(DMSType.CONNECTIVITYNODE)); rd = new ResourceDescription(gid); importHelper.DefineIDMapping(cimConnectivityNode.ID, gid); ////populate ResourceDescription LoadFlowConverter.PopulateConnectivityNodeProperties(cimConnectivityNode, rd); } return(rd); }
public CloneCvor(String id) { foreach (ConnectivityNode conNode in Singleton.Instance().Nodes) { if (conNode.mRID.Equals(id)) { cnode = conNode; break; } } ID = "a" + Guid.NewGuid().ToString().Substring(0, 8); }
private string CheckIfPropertyNeedsId(string updated_property_info_name, object data) { switch (updated_property_info_name) { case "ConnectivityNode.ConnectivityNodeContainer": Circuit c = (Circuit)data; return(c.MRID); case "UsagePoint.ServiceLocation": ServiceLocation sl = (ServiceLocation)data; return(sl.MRID); case "PowerSystemResource.PSRType": PSRType psr = (PSRType)data; return(psr.Name); case "ACLineSegment.PerLengthImpedance": PerLengthImpedance pli = (PerLengthImpedance)data; return(pli.MRID); case "Equipment.EquipmentContainer": EquipmentContainer eq = (EquipmentContainer)data; return(eq.MRID); case "PowerSystemResource.AssetDatasheet": AssetInfo ad = (AssetInfo)data; return(ad.MRID); case "TransformerEnd.Terminal": Terminal t = (Terminal)data; return(t.MRID); case "PowerTransformerEnd.PowerTransformer": PowerTransformer pst = (PowerTransformer)data; return(pst.MRID); case "Terminal.ConductingEquipment": ConductingEquipment ce = (ConductingEquipment)data; return(ce.MRID); case "Terminal.ConnectivityNode": ConnectivityNode cn = (ConnectivityNode)data; return(cn.MRID); } return(""); }
private void traverseClosedSwitches(TopologicalNode.DynamicTopologicalNode dynaNode, ConnectivityNode connNode) { var switchNodes = new Stack<ConnectivityNode>(); switchNodes.Push(connNode); while (switchNodes.Count != 0) { var currentNode = switchNodes.Pop(); dynaNode.Nodes.ConnectivityNodes[currentNode.Name] = currentNode; currentNode.DynamicTopoNode = dynaNode; foreach (ConnectivityNode nextConnNode in currentNode.AdjacentSwitchNodes(false) .Where(x => !ReferenceEquals(x,currentNode))) { switchNodes.Push(nextConnNode); } } }
public override void Update(EObservableMessageType msg) { if (!initialized || msg == EObservableMessageType.NetworkModelChanged) { io = PubSub.Model.Get(GID) as ConnectivityNode; } properties.Update(msg); measurements.Update(msg); if (!initialized) { panel.Children.Add(properties.Element); panel.Children.Add(measurements.Element); initialized = true; } }
public DodajACLine(ConnectivityNode node1, ConnectivityNode node2, String ime, float duzina, float gch, float bch, float r, float x) { als = new ACLineSegment(); Random rand = new Random(); als.name = ime;//linija ime als.length = duzina; als.mRID = rand.Next(1000).ToString(); als.gch = gch; als.bch = bch; als.r = r; als.x = x; term1 = new Terminal() { name = "Terminal 1", ConnectivityNode = node1, ConductingEquipment = new ConductingEquipment(), phases = PhaseCode.AB, sequenceNumber = 1, connected = false, mRID = rand.Next(100).ToString(), aliasName = "A_Terminal 1", description = "opis" }; term2 = new Terminal() { name = "Terminal 2", ConnectivityNode = node2, ConductingEquipment = new ConductingEquipment(), phases = PhaseCode.ABCN, sequenceNumber = 1, connected = false, mRID = rand.Next(100).ToString(), aliasName = "A_Terminal 2", description = "opis" }; als.terminali.Add(term1); als.terminali.Add(term2); }
public static void PopulateNodeProperties(ConnectivityNode cimCNode, ResourceDescription rd, ImportHelper import, TransformAndLoadReport report) { if ((cimCNode != null) && (rd != null)) { PowerTransformerConverter.PopulateIdentifiedObjectProperties(cimCNode, rd); if (cimCNode.DescriptionHasValue) { rd.AddProperty(new Property(ModelCode.CNODE_DESC, cimCNode.Description)); } if (cimCNode.ConnectivityNodeContainerHasValue) { long gid = import.GetMappedGID(cimCNode.ConnectivityNodeContainer.ID); if (gid < 0) { report.Report.Append("WARNING: Convert ").Append(cimCNode.GetType().ToString()).Append(" rdfID = \"").Append(cimCNode.ID); report.Report.Append("\" - Failed to set reference to ConnectivityNodeContainer: rdfID \"").Append(cimCNode.ConnectivityNodeContainer.ID).AppendLine(" \" is not mapped to GID!"); } rd.AddProperty(new Property(ModelCode.CNODE_CNC, gid)); } } }
public void CanApplyDiff_ObjectDeletion() { var deletedObject = new ConnectivityNode { mRID = "123", description = "this is my connectivitivity nodode", name = "Connode" }; var change = new DataSetMember { mRID = Guid.NewGuid().ToString(), Change = new ObjectDeletion(), TargetObject = new TargetObject { @ref = deletedObject.mRID, referenceType = nameof(ConnectivityNode) }, ReverseChange = new ObjectReverseModification() }; var result = _differ.ApplyDiff(new[] { deletedObject }, new[] { change }).ToList(); Assert.That(result.Count, Is.EqualTo(0)); }
public override void Izvrsi() { for (int i = 0; i < Singleton.Instance().Nodes.Count; i++) { if (Singleton.Instance().Nodes[i].mRID.Equals(node.mRID)) { node = Singleton.Instance().Nodes[i]; for (int j = 0; j < Singleton.Instance().Substations.Count; j++) { for (int k = 0; k < Singleton.Instance().Substations[j].connectivityNodes.Count; k++) { if (Singleton.Instance().Substations[j].connectivityNodes[k].mRID.Equals(Singleton.Instance().Nodes[i].mRID)) { foreach (ACLineSegment line in Singleton.Instance().AClines) { foreach (Terminal t in line.terminali) { if (t.ConnectivityNode.mRID.Equals(node.mRID)) { lines.Add(line); Singleton.Instance().AClines.Remove(line); break; } } } Singleton.Instance().Substations[j].connectivityNodes.RemoveAt(k); index = j; break; } } } Singleton.Instance().Nodes.Remove(Singleton.Instance().Nodes[i]); break; } } }
public void CanApplyDiff_ObjectModification() { var target = new ConnectivityNode { mRID = "123", description = "this is my connectivitivity nodode", name = "Connode" }; var change = new DataSetMember { mRID = Guid.NewGuid().ToString(), Change = new ObjectModification { Modifications = new[] { new PropertyModification { Name = "description", Value = "this is my connectivity node (spelning corected)" } } }, // not necessary for this test, but play it realistic ReverseChange = new ObjectReverseModification { Modifications = new[] { new PropertyModification { Name = "description", Value = "this is my connectivitivity nodode" } } }, TargetObject = new TargetObject { @ref = target.mRID, referenceType = nameof(ConnectivityNode) } }; var result = _differ.ApplyDiff(new[] { target }, new[] { change }).First(); Assert.That(result.description, Is.EqualTo("this is my connectivity node (spelning corected)")); }
private void ImportConnectivityNode() { SortedDictionary <string, object> cimConnectivityNodes = concreteModel.GetAllObjectsOfType("FTN.ConnectivityNode"); if (cimConnectivityNodes != null) { foreach (KeyValuePair <string, object> item in cimConnectivityNodes) { ConnectivityNode cimConnectivityNode = item.Value as ConnectivityNode; ResourceDescription rd = CreateConnectivityNodeDescription(cimConnectivityNode); if (rd != null) { delta.AddDeltaOperation(DeltaOpType.Insert, rd, true); report.Report.Append("ConnectivityNode ID = ").Append(cimConnectivityNode.ID).Append(" SUCCESSFULLY converted to GID = ").AppendLine(rd.Id.ToString()); } else { report.Report.Append("ConnectivityNode ID = ").Append(cimConnectivityNode.ID).AppendLine(" FAILED to be converted"); } } report.Report.AppendLine(); } }
private float distance(ConnectivityNode p1, ConnectivityNode p2) { return((float)Math.Sqrt(Math.Pow(p1.position.X - p2.position.X, 2) + Math.Pow(p1.position.Y - p2.position.Y, 2))); }
private ConnectivityPath generateConnectivityPath(ConnectivityNode startNode, ConnectivityNode endNode, SortedVector2List <Platform> platforms, float gravity) { bool straightPath = straightable(platforms, startNode.position, endNode.position, true) && straightable(platforms, startNode.position - new Vector2(0, Game.MEDIUM_ENEMY_HEIGHT / 3), endNode.position - new Vector2(0, Game.MEDIUM_ENEMY_HEIGHT / 3), false) && (endNode.position.X > startNode.position.X + Game.MEDIUM_ENEMY_WIDTH / 2 || straightable(platforms, startNode.position - new Vector2(Game.MEDIUM_ENEMY_WIDTH / 2, Game.MEDIUM_ENEMY_HEIGHT / 3 * 2), endNode.position - new Vector2(-Game.MEDIUM_ENEMY_WIDTH / 2, Game.MEDIUM_ENEMY_HEIGHT / 3 * 2), false)) && (endNode.position.X < startNode.position.X - Game.MEDIUM_ENEMY_WIDTH / 2 || straightable(platforms, startNode.position - new Vector2(-Game.MEDIUM_ENEMY_WIDTH / 2, Game.MEDIUM_ENEMY_HEIGHT / 3 * 2), endNode.position - new Vector2(Game.MEDIUM_ENEMY_WIDTH / 2, Game.MEDIUM_ENEMY_HEIGHT / 3 * 2), false)) && straightable(platforms, startNode.position - new Vector2(0, Game.MEDIUM_ENEMY_HEIGHT), endNode.position - new Vector2(0, Game.MEDIUM_ENEMY_HEIGHT), false); bool largeCharacterStraightPath = straightable(platforms, startNode.position, endNode.position, true) && straightable(platforms, startNode.position - new Vector2(0, Game.LARGE_ENEMY_HEIGHT) / 4, endNode.position - new Vector2(0, Game.LARGE_ENEMY_HEIGHT) / 3, false) && straightable(platforms, startNode.position - new Vector2(0, Game.LARGE_ENEMY_HEIGHT) / 4 * 2, endNode.position - new Vector2(0, Game.LARGE_ENEMY_HEIGHT) / 4 * 2, false) && (endNode.position.X > startNode.position.X + Game.MEDIUM_ENEMY_WIDTH / 2 || straightable(platforms, startNode.position - new Vector2(Game.LARGE_ENEMY_WIDTH / 2, Game.LARGE_ENEMY_HEIGHT / 4 * 3), endNode.position - new Vector2(-Game.LARGE_ENEMY_WIDTH / 2, Game.LARGE_ENEMY_HEIGHT / 4 * 3), false)) && (endNode.position.X < startNode.position.X - Game.MEDIUM_ENEMY_WIDTH / 2 || straightable(platforms, startNode.position - new Vector2(-Game.LARGE_ENEMY_WIDTH / 2, Game.LARGE_ENEMY_HEIGHT / 4 * 3), endNode.position - new Vector2(Game.LARGE_ENEMY_WIDTH / 2, Game.LARGE_ENEMY_HEIGHT / 4 * 3), false)) && straightable(platforms, startNode.position - new Vector2(0, Game.LARGE_ENEMY_HEIGHT), endNode.position - new Vector2(0, Game.LARGE_ENEMY_HEIGHT), false); bool walkable = straightPath && straightable(platforms, new Vector2(startNode.position.X, endNode.position.Y), endNode.position, true); // dy = t * Vy // dy = t * J / 2 // dy = J / g * J / 2 // dy = J^2 / g / 2 // Jmin = sqrt(dy * 2 * g) float[] jumpCosts = new float[Game.ALL_ENEMY_MAX_JUMP_STRENGTH + 1]; bool[] jumpableStrengths = new bool[Game.ALL_ENEMY_MAX_JUMP_STRENGTH + 1]; bool[] largeCharacterJumpable = new bool[Game.ALL_ENEMY_MAX_JUMP_STRENGTH + 1]; int jumpMin = (endNode.position.Y > startNode.position.Y) ? 0 : (int)Math.Sqrt(Math.Abs(endNode.position.Y - startNode.position.Y) * 2 * gravity) + 1; if (Game.ALL_ENEMY_MIN_JUMP_STRENGTH > jumpMin) { jumpMin = Game.ALL_ENEMY_MIN_JUMP_STRENGTH; } for (; jumpMin <= Game.ALL_ENEMY_MAX_JUMP_STRENGTH; jumpMin += 1) { if ((jumpCosts[jumpMin] = jumpable(platforms, gravity, startNode.position, endNode.position, jumpMin)) != -1 && jumpable(platforms, gravity, startNode.position - new Vector2(-Game.MEDIUM_ENEMY_WIDTH / 2, Game.MEDIUM_ENEMY_HEIGHT / 2), endNode.position - new Vector2(-Game.MEDIUM_ENEMY_WIDTH / 2, Game.MEDIUM_ENEMY_HEIGHT / 2), jumpMin) != -1 && jumpable(platforms, gravity, startNode.position - new Vector2(Game.MEDIUM_ENEMY_WIDTH / 2, Game.MEDIUM_ENEMY_HEIGHT / 2), endNode.position - new Vector2(Game.MEDIUM_ENEMY_WIDTH / 2, Game.MEDIUM_ENEMY_HEIGHT / 2), jumpMin) != -1 && jumpable(platforms, gravity, startNode.position - new Vector2(0, Game.MEDIUM_ENEMY_HEIGHT), endNode.position - new Vector2(0, Game.MEDIUM_ENEMY_HEIGHT), jumpMin) != -1) { jumpableStrengths[jumpMin] = true; if (jumpable(platforms, gravity, startNode.position - new Vector2(0, Game.LARGE_ENEMY_HEIGHT), endNode.position - new Vector2(0, Game.LARGE_ENEMY_HEIGHT), jumpMin) != -1) { largeCharacterJumpable[jumpMin] = true; } } } bool jumpPath = false; for (int i = 0; i < jumpableStrengths.Length && !jumpPath; ++i) { jumpPath = true; } if (!jumpPath && !straightPath) { return(null); } return(new ConnectivityPath(startNode, endNode, jumpableStrengths, largeCharacterJumpable, largeCharacterStraightPath, straightPath, walkable, jumpPath, jumpCosts)); }
private PathWaypoint getPath(SortedVector2List <Platform> platforms, CollidableObj start, CollidableObj end, int jumpStrength, int xVelocity, float gravity, PathWaypoint curWapoint = null) { Dictionary <Vector2, ConnectivityNodeWrapper> exploredSet = new Dictionary <Vector2, ConnectivityNodeWrapper>(); Dictionary <Vector2, ConnectivityNodeWrapper> openSet = new Dictionary <Vector2, ConnectivityNodeWrapper>(); MinHeap <ConnectivityNodeWrapper> queue = new MinHeap <ConnectivityNodeWrapper>(delegate(ConnectivityNodeWrapper n1, ConnectivityNodeWrapper n2) { if (n1.heurisitc < n2.heurisitc) { return(-1); } else if (n1.heurisitc == n2.heurisitc) { return(0); } else { return(1); } }); List <Vector2> res; ConnectivityNodeWrapper curNode; if (curWapoint != null && !(connectivityGraph.ContainsKey((int)curWapoint.position.X) && connectivityGraph[(int)curWapoint.position.X].ContainsKey((int)curWapoint.position.Y))) { curWapoint = null; } if (curWapoint != null) { curNode = new ConnectivityNodeWrapper(connectivityGraph[(int)curWapoint.position.X][(int)curWapoint.position.Y], calculateHeuristic(curWapoint.position, end.Position, xVelocity, jumpStrength)); } else { res = getClosestNodeKeyForPosition(platforms, start, start.Position, end.Position, gravity, xVelocity); if (res == null) { return(null); } foreach (Vector2 vec in res) { ConnectivityNodeWrapper cnw = new ConnectivityNodeWrapper(connectivityGraph[(int)vec.X][(int)vec.Y], calculateHeuristic(vec, end.Position, xVelocity, jumpStrength)); queue.add(cnw); openSet.Add(cnw.node.position, cnw); } curNode = queue.peek(); queue.pop(); openSet.Remove(curNode.node.position); } res = getClosestNodeKeyForPosition(platforms, end, end.Position, end.Position, gravity, xVelocity, jumpStrength); if (res == null) { return(null); } ConnectivityNode endNode = connectivityGraph[(int)res[0].X][(int)res[0].Y]; int it = 0; while (curNode != endNode) { foreach (ConnectivityPath path in curNode.node.connections) { if (!exploredSet.ContainsKey(path.endNode.position)) { bool jumpPath = path.jumpPath && path.jumpableStrengths[jumpStrength] && path.minXVel(jumpStrength, gravity) <= xVelocity; bool straightPath = path.straightPath && (path.minXVel(0, gravity) <= xVelocity || path.walkable); if (straightPath) { float h = calculateHeuristic(path.endNode.position, endNode.position, xVelocity, jumpStrength); if (!openSet.ContainsKey(path.endNode.position)) { ConnectivityNodeWrapper cnw = new ConnectivityNodeWrapper(path.endNode, path.getStraightPathCost(xVelocity, gravity), h, curNode, PathType.Straight); queue.add(cnw); openSet.Add(cnw.node.position, cnw); } else if (openSet[path.endNode.position].heurisitc > h) { ConnectivityNodeWrapper cnw = new ConnectivityNodeWrapper(path.endNode, path.getStraightPathCost(xVelocity, gravity), h, curNode, PathType.Straight); queue.add(cnw); openSet[path.endNode.position] = cnw; } } else if (jumpPath) { queue.add(new ConnectivityNodeWrapper(path.endNode, path.jumpCosts[jumpStrength], calculateHeuristic(path.endNode.position, endNode.position, xVelocity, jumpStrength), curNode, PathType.Jump)); } } } exploredSet.Add(curNode.node.position, curNode); ++it; if (it == 20) { return(null); } do { if (queue.empty()) { return(null); } curNode = queue.peek(); queue.pop(); } while (exploredSet.ContainsKey(curNode.node.position)); } PathWaypoint pathWaypoint = new PathWaypoint(new Vector2(end.Position.X, end.getBot()), null, PathType.Free); while (curNode != (object)null) { pathWaypoint = new PathWaypoint(curNode.node.position, pathWaypoint, curNode.pathType); curNode = curNode.parent; } if (curWapoint != null) { pathWaypoint = pathWaypoint.nextWaypoint; } return(pathWaypoint); }
public AIManager(SortedVector2List <Platform> platforms, float gravity, List <Enemy> enemies) { this.enemies = enemies; SortedVector2List <bool> platformAdded = new SortedVector2List <bool>(); foreach (Enemy e in enemies) { platforms.ForAllInRange(e.ai.boundingBox.Center.ToVector2(), e.ai.boundingBox.Width / 2 + Level.MAX_PLATFORM_BOUND, delegate(Platform p) { if (!platformAdded.Exists(p.Position)) { platformAdded.Add(p.Position, true); List <Vector2> positions = p.getConnectivityNodeCoordinates(); for (int i = 0; i < positions.Count; ++i) { ConnectivityNode node = new ConnectivityNode(positions[i] - new Vector2((i == 0) ? 1 : (i == positions.Count - 1) ? -1 : 0, 1)); if (e.ai.inBoundingBox(node.position)) { SortedList <int, ConnectivityNode> nodeYList; if (connectivityGraph.TryGetValue((int)node.position.X, out nodeYList)) { nodeYList.Add((int)node.position.Y, node); } else { connectivityGraph.Add((int)node.position.X, new SortedList <int, ConnectivityNode> { { (int)node.position.Y, node } }); } } } } return(true); }); } /*foreach (SortedList<int, Platform> list in platforms.Values) * foreach (Platform p in list.Values) * { * List<Vector2> positions = p.getConnectivityNodeCoordinates(); * for (int i = 0; i < positions.Count; ++i) * { * ConnectivityNode node = new ConnectivityNode(positions[i] - new Vector2((i == 0) ? 1 : (i == positions.Count - 1) ? -1 : 0, 1)); * SortedList<int, ConnectivityNode> nodeYList; * if (connectivityGraph.TryGetValue((int)node.position.X, out nodeYList)) * nodeYList.Add((int)node.position.Y, node); * else * connectivityGraph.Add((int)node.position.X, new SortedList<int, ConnectivityNode> { { (int)node.position.Y, node } }); * } * }*/ for (int i = 0; i < connectivityGraph.Count; ++i) { for (int ii = 0; ii < connectivityGraph.Values[i].Count; ++ii) { for (int j = i; j < connectivityGraph.Count; ++j) { for (int jj = (j == i) ? ii + 1 : 0; jj < connectivityGraph.Values[j].Count; ++jj) { if (distance(connectivityGraph.Values[i].Values[ii], connectivityGraph.Values[j].Values[jj]) > MAX_NODE_SEARCH_RANGE) { continue; } ConnectivityPath connectivityPath = generateConnectivityPath(connectivityGraph.Values[i].Values[ii], connectivityGraph.Values[j].Values[jj], platforms, gravity); if (connectivityPath != null) { connectivityGraph.Values[i].Values[ii].connections.Add(connectivityPath); } connectivityPath = generateConnectivityPath(connectivityGraph.Values[j].Values[jj], connectivityGraph.Values[i].Values[ii], platforms, gravity); if (connectivityPath != null) { connectivityGraph.Values[j].Values[jj].connections.Add(connectivityPath); } } } } } }
internal TransmissionUnit(ConnectivityNode sourceBus, float baseKV) { DownstreamUnits = new HashSet<TransmissionUnit>(); Node = sourceBus.DynamicTopoNode; V = new Complex[]{baseKV ,baseKV ,baseKV}; I = new Complex[]{ 0, 0, 0 }; BaseKV = baseKV; }
/// <summary> /// Creates entity for specified global inside the container. /// </summary> /// <param name="globalId">Global id of the entity for insert</param> /// <returns>Created entity (identified object).</returns> public IdentifiedObject CreateEntity(long globalId) { short type = ModelCodeHelper.ExtractTypeFromGlobalId(globalId); IdentifiedObject io = null; switch ((DMSType)type) { case DMSType.TERMINAL: io = new Terminal(globalId); break; case DMSType.ANALOG: io = new Analog(globalId); break; case DMSType.ASYNCHRONOUSMACHINE: io = new AsynchronousMachine(globalId); break; case DMSType.BREAKER: io = new Breaker(globalId); break; case DMSType.CONNECTIVITYNODE: io = new ConnectivityNode(globalId); break; case DMSType.DISCONNECTOR: io = new Disconnector(globalId); break; case DMSType.DISCRETE: io = new Discrete(globalId); break; case DMSType.POWERTRANSFORMER: io = new PowerTransformer(globalId); break; case DMSType.RATIOTAPCHANGER: io = new RatioTapChanger(globalId); break; case DMSType.SUBSTATION: io = new Substation(globalId); break; case DMSType.TRANSFORMERWINDING: io = new TransformerWinding(globalId); break; default: string message = String.Format("Failed to create entity because specified type ({0}) is not supported.", type); CommonTrace.WriteTrace(CommonTrace.TraceError, message); throw new Exception(message); } // Add entity to map this.AddEntity(io); return(io); }
public Dictionary <Type, Dictionary <string, IdentifiedObject> > CreateObjectModel(Dictionary <string, DataVertex> globalVertices, Dictionary <string, List <DataEdge> > globalEdges, Dictionary <string, CableConfiguration> globalCableConfiguration, Dictionary <string, SpotLoad> globalSpotLoads) { globalComponentDictionary = new Dictionary <Type, Dictionary <string, IdentifiedObject> >(); terminalPairsContainer = new List <TerminalPair>(); perLengthImpedanceContainer = new Dictionary <string, PerLengthImpedance>(); wireInfoContainer = new Dictionary <string, WireInfo>(); usagePointContainer = new Dictionary <string, SpotLoad>(); powerTransformerEnding = new Dictionary <string, DataVertexTransformer>(); PSRType local_psr_pt = new PSRType(); circuit = new Circuit(); string mrid = Guid.NewGuid().ToString(); PSRType psrTypeCircuit = new PSRType() { MRID = "Feeder", Name = "Feeder" }; circuit.PSRType = psrTypeCircuit; circuit.ID = mrid; circuit.MRID = mrid; circuit.Name = "Feeder_36"; addComponentToGlobalDictionary(circuit, circuit.GetType()); addComponentToGlobalDictionary(psrTypeCircuit, psrTypeCircuit.GetType()); Dictionary <string, ConnectivityNode> connectivityNodeContainer = new Dictionary <string, ConnectivityNode>(); foreach (DataVertex dataVertex in globalVertices.Values) { if (dataVertex.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_VERTEX) { PowerTransformer powerTransformer = new PowerTransformer(); DataVertexTransformer dvt = (DataVertexTransformer)dataVertex; string power_transformer_mrid = Guid.NewGuid().ToString(); powerTransformer.ID = power_transformer_mrid; powerTransformer.MRID = power_transformer_mrid; powerTransformer.Name = "2 winding power transformer"; local_psr_pt = new PSRType() { Name = "Consumer Transformer", MRID = "Consumer Transformer" }; powerTransformer.PSRType = local_psr_pt; powerTransformer.EquipmentContainer = circuit; addComponentToGlobalDictionary(local_psr_pt, local_psr_pt.GetType()); ConnectivityNode w1T_cn = new ConnectivityNode(); string connectivity_node_mrid = Guid.NewGuid().ToString(); w1T_cn.ID = connectivity_node_mrid; w1T_cn.MRID = connectivity_node_mrid; w1T_cn.ConnectivityNodeContainer = circuit; if ((dataVertex as DataVertexTransformer).Line_from == null) { continue; } ; w1T_cn.Name = (dataVertex as DataVertexTransformer).Line_from; connectivityNodeContainer.Add((dataVertex as DataVertexTransformer).Line_from, w1T_cn); addComponentToGlobalDictionary(w1T_cn, w1T_cn.GetType()); ConnectivityNode w2T_cn = new ConnectivityNode(); connectivity_node_mrid = Guid.NewGuid().ToString(); w2T_cn.ID = connectivity_node_mrid; w2T_cn.MRID = connectivity_node_mrid; w2T_cn.ConnectivityNodeContainer = circuit; w2T_cn.Name = (dataVertex as DataVertexTransformer).Line_to; connectivityNodeContainer.Add((dataVertex as DataVertexTransformer).Line_to, w2T_cn); if ((dataVertex as DataVertexTransformer).Line_to == null) { continue; } ; addComponentToGlobalDictionary(w2T_cn, w2T_cn.GetType()); Terminal w1T = new Terminal(); w1T.MRID = power_transformer_mrid + ".W1.T"; w1T.ID = power_transformer_mrid + ".W1.T"; w1T.SequenceNumber = 1; w1T.ConductingEquipment = powerTransformer; w1T.ConnectivityNode = w1T_cn; w1T.Phases = PhaseCode.s2N; w1T.Name = "Transformer end terminal 1"; Terminal w2T = new Terminal(); w2T.MRID = power_transformer_mrid + ".W2.T"; w2T.ID = power_transformer_mrid + ".W2.T"; w2T.SequenceNumber = 2; w2T.ConductingEquipment = powerTransformer; w2T.ConnectivityNode = w2T_cn; w2T.Phases = PhaseCode.s2N; w2T.Name = "Transformer end terminal 2"; terminalPairsContainer.Add(new TerminalPair() { terminalA = w1T, terminalB = w2T }); addComponentToGlobalDictionary(w1T, w1T.GetType()); addComponentToGlobalDictionary(w2T, w2T.GetType()); PowerTransformerEnd powerTransformerEnd1 = new PowerTransformerEnd(); powerTransformerEnd1.ID = power_transformer_mrid + ".W1"; powerTransformerEnd1.MRID = power_transformer_mrid + ".W1"; powerTransformerEnd1.Name = dvt.NameA; powerTransformerEnd1.Terminal = w1T; powerTransformerEnd1.Grounded = false; powerTransformerEnd1.EndNumber = 1; powerTransformerEnd1.PowerTransformer = powerTransformer; powerTransformerEnd1.ConnectionKind = WindingConnection.D; powerTransformerEnd1.PhaseAngleClock = 0; powerTransformerEnd1.RatedS = (float)dvt._kVA_A; powerTransformerEnd1.RatedU = (float)dvt._kV_LowA; PowerTransformerEnd powerTransformerEnd2 = new PowerTransformerEnd(); powerTransformerEnd2.ID = power_transformer_mrid + ".W2"; powerTransformerEnd2.MRID = power_transformer_mrid + ".W2"; powerTransformerEnd2.Name = dvt.NameB; powerTransformerEnd2.Terminal = w2T; powerTransformerEnd2.Grounded = false; powerTransformerEnd2.EndNumber = 1; powerTransformerEnd2.PowerTransformer = powerTransformer; powerTransformerEnd2.ConnectionKind = WindingConnection.D; powerTransformerEnd2.PhaseAngleClock = 0; powerTransformerEnd2.RatedS = (float)dvt._kVA_B; powerTransformerEnd2.RatedU = (float)dvt._kV_LowB; addComponentToGlobalDictionary(powerTransformer, powerTransformer.GetType()); addComponentToGlobalDictionary(powerTransformerEnd1, powerTransformerEnd1.GetType()); addComponentToGlobalDictionary(powerTransformerEnd2, powerTransformerEnd2.GetType()); } if (dataVertex.typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_VERTEX) { string sync_machine = Guid.NewGuid().ToString(); PSRType psr_sync_machine = new PSRType() { MRID = "Generator", Name = "Generator" }; SynchronousMachine sm = new SynchronousMachine() { Name = dataVertex.Text, MRID = sync_machine, ID = sync_machine, EquipmentContainer = circuit }; addComponentToGlobalDictionary(sm, sm.GetType()); addComponentToGlobalDictionary(psr_sync_machine, psr_sync_machine.GetType()); } } foreach (List <DataEdge> dataEdgeCollection in globalEdges.Values) { foreach (DataEdge dataEdge in dataEdgeCollection) { string acLineSegment_mrid = Guid.NewGuid().ToString(); ConnectivityNode T1_cn = new ConnectivityNode(); string connectivity_node_mrid = Guid.NewGuid().ToString(); T1_cn.ID = connectivity_node_mrid; T1_cn.MRID = connectivity_node_mrid; T1_cn.ConnectivityNodeContainer = circuit; T1_cn.Name = (dataEdge.Source as DataVertex).Element_id; if (connectivityNodeContainer.ContainsKey((dataEdge.Source as DataVertex).Element_id) == false) { connectivityNodeContainer.Add(dataEdge.Source.Element_id, T1_cn); addComponentToGlobalDictionary(T1_cn, T1_cn.GetType()); } ConnectivityNode T2_cn = new ConnectivityNode(); connectivity_node_mrid = Guid.NewGuid().ToString(); T2_cn.ID = connectivity_node_mrid; T2_cn.MRID = connectivity_node_mrid; T2_cn.ConnectivityNodeContainer = circuit; T2_cn.Name = (dataEdge.Target as DataVertex).Element_id; if (connectivityNodeContainer.ContainsKey((dataEdge.Target as DataVertex).Element_id) == false) { connectivityNodeContainer.Add(dataEdge.Target.Element_id, T2_cn); addComponentToGlobalDictionary(T2_cn, T2_cn.GetType()); } Terminal T1 = new Terminal(); //string terminal_mrid = Guid.NewGuid().ToString(); T1.ID = acLineSegment_mrid + ".T1"; T1.MRID = acLineSegment_mrid + ".T1"; T1.Name = dataEdge.Source.Element_id; T1.Phases = PhaseCode.ABC; ACDCTerminal acdc_terminal = new ACDCTerminal() { SequenceNumber = 1 }; T1.SequenceNumber = acdc_terminal.SequenceNumber; T1.ConnectivityNode = T1_cn; Terminal T2 = new Terminal(); T2.ID = acLineSegment_mrid + ".T2"; T2.MRID = acLineSegment_mrid + ".T2"; T2.Name = dataEdge.Target.Element_id; T2.Phases = PhaseCode.ABC; ACDCTerminal acdc_terminal2 = new ACDCTerminal() { SequenceNumber = 2 }; T2.SequenceNumber = acdc_terminal2.SequenceNumber; T2.ConnectivityNode = T2_cn; string perLengthImpedance_mrid = Guid.NewGuid().ToString(); PerLengthImpedance pli = createPerLengthImpedanceObject(dataEdge.Configuration, perLengthImpedance_mrid); AssetInfo wi = createWireInfoObject(dataEdge.Configuration, perLengthImpedance_mrid); PSRType acPSRType = new PSRType() { MRID = "Section", Name = "Section" }; if (!globalComponentDictionary[acPSRType.GetType()].ContainsKey(acPSRType.Name)) { addComponentToGlobalDictionary(acPSRType, acPSRType.GetType()); } ACLineSegment acLineSegment = new ACLineSegment() { ID = acLineSegment_mrid, MRID = acLineSegment_mrid, Name = T1.Name.Split(' ').Last() + "-" + T2.Name.Split(' ').Last(), PSRType = acPSRType, EquipmentContainer = circuit, Length = (float)feetsToMeters(dataEdge.Length), PerLengthImpedance = pli, AssetDatasheet = wi }; addComponentToGlobalDictionary(acLineSegment, acLineSegment.GetType()); TerminalPair terminalPair = new TerminalPair() { terminalA = T1, terminalB = T2 }; terminalPairsContainer.Add(terminalPair); addComponentToGlobalDictionary(T1, T1.GetType()); addComponentToGlobalDictionary(T2, T2.GetType()); } } UsagePoint usagePoint = new UsagePoint(); foreach (DataVertex dv in globalVertices.Values) { if (dv.typeOfVertex == DataVertex.TypeOfVertex.SPOT_LOAD_VERTEX) { SpotLoad sl = (SpotLoad)dv; usagePoint = CreateSpotLoad(sl); addComponentToGlobalDictionary(usagePoint, usagePoint.GetType()); } } return(globalComponentDictionary); }
public void SetUp() { entity = new ConnectivityNode(entityGid); }
public IEnumerable <IdentifiedObject> Transform(CimContext context, IEnumerable <IdentifiedObject> input) { HashSet <PhysicalNetworkModel.IdentifiedObject> dropList = new HashSet <IdentifiedObject>(); List <PhysicalNetworkModel.IdentifiedObject> addList = new List <IdentifiedObject>(); foreach (var inputCimObject in input) { // Find connectivity nodes outside substations if (inputCimObject is ConnectivityNode && !dropList.Contains(inputCimObject) && !inputCimObject.IsInsideSubstation(context)) { ConnectivityNode cn = inputCimObject as ConnectivityNode; // Handle that acls cn relationship might have changed var cnNeighborsx = cn.GetNeighborConductingEquipments(context); // If two acls and we are above low voltage, merge them if (cnNeighborsx.Count(o => o.BaseVoltage > 5000) > 0) { // acls <-> acls if (cnNeighborsx.Count(o => o is ACLineSegmentExt) == 2) { var acls = cnNeighborsx.Where(o => o is ACLineSegmentExt).ToList(); var acls1 = acls[0] as ACLineSegment; var acls2 = acls[1] as ACLineSegment; // NEVER MERGE bool theSame = false; // Compate bch if (acls1.bch != null && acls2.bch != null && !CompareAclsValue(acls1.length.Value, acls1.bch.Value, acls2.length.Value, acls2.bch.Value)) { theSame = false; } // Compate b0ch if (acls1.b0ch != null && acls2.b0ch != null && !CompareAclsValue(acls1.length.Value, acls1.b0ch.Value, acls2.length.Value, acls2.b0ch.Value)) { theSame = false; } // Compare gch if (acls1.gch != null && acls2.gch != null && !CompareAclsValue(acls1.length.Value, acls1.gch.Value, acls2.length.Value, acls2.gch.Value)) { theSame = false; } // Compare g0ch if (acls1.g0ch != null && acls2.g0ch != null && !CompareAclsValue(acls1.length.Value, acls1.g0ch.Value, acls2.length.Value, acls2.g0ch.Value)) { theSame = false; } // Compare r if (acls1.r != null && acls2.r != null && !CompareAclsValue(acls1.length.Value, acls1.r.Value, acls2.length.Value, acls2.r.Value)) { theSame = false; } // Compare r0 if (acls1.r0 != null && acls2.r0 != null && !CompareAclsValue(acls1.length.Value, acls1.r0.Value, acls2.length.Value, acls2.r0.Value)) { theSame = false; } // Compare x if (acls1.x != null && acls2.x != null && !CompareAclsValue(acls1.length.Value, acls1.x.Value, acls2.length.Value, acls2.x.Value)) { theSame = false; } // Compare x0 if (acls1.x0 != null && acls2.x0 != null && !CompareAclsValue(acls1.length.Value, acls1.x0.Value, acls2.length.Value, acls2.x0.Value)) { theSame = false; } // If the cables have the same eletrical charastica, merge them if (theSame) { // ACLS 1 will survive, ACLS 2 and the CN will die dropList.Add(cn); dropList.Add(acls2); // drop acls 2 terminals foreach (var tc in context.GetConnections(acls2)) { dropList.Add(tc.Terminal); } var loc1 = context.GetObject <LocationExt>(acls1.Location.@ref); var loc2 = context.GetObject <LocationExt>(acls2.Location.@ref); LineMerger lm = new LineMerger(); // Convert to NTS geometries lm.Add(GetGeometry(loc1)); lm.Add(GetGeometry(loc2)); // Merge the two line strings var mergedLineList = lm.GetMergedLineStrings(); if (mergedLineList.Count != 1) { throw new Exception("Cannot merge ACLS: " + acls1.mRID + " and " + acls2.mRID); } // Overwrite loc 1 coordinated with merged strings loc1.coordinates = GetPoints((ILineString)mergedLineList[0]).ToArray(); // Sum length acls1.length.Value += acls2.length.Value; // Sum bch if (acls1.bch != null && acls2.bch != null) { acls1.bch.Value += acls2.bch.Value; } // Sum b0ch if (acls1.b0ch != null && acls2.b0ch != null) { acls1.b0ch.Value += acls2.b0ch.Value; } // Sum gch if (acls1.gch != null && acls2.gch != null) { acls1.gch.Value += acls2.gch.Value; } // Sum g0ch if (acls1.g0ch != null && acls2.g0ch != null) { acls1.g0ch.Value += acls2.g0ch.Value; } // Sum r if (acls1.r != null && acls2.r != null) { acls1.r.Value += acls2.r.Value; } // Sum r0 if (acls1.r0 != null && acls2.r0 != null) { acls1.r0.Value += acls2.r0.Value; } // Sum x if (acls1.x != null && acls2.x != null) { acls1.x.Value += acls2.x.Value; } // Sum x0 if (acls1.x0 != null && acls2.x0 != null) { acls1.x0.Value += acls2.x0.Value; } // Find cn in the other end of ACLS 2 var acls2otherEndCn = context.GetConnections(acls2).Find(o => o.ConnectivityNode != cn); // Get terminal of ACLS 1 that point to ACLS 2 var acls1Terminal = acls1.GetTerminal(acls2, true, context); // Disconnect ACLS 2 terminals var acls2connections = context.GetConnections(acls2); List <Terminal> terminalsToDisconnect = new List <Terminal>(); foreach (var acls2con in acls2connections) { terminalsToDisconnect.Add(acls2con.Terminal); } foreach (var t2d in terminalsToDisconnect) { context.DisconnectTerminalFromConnectitityNode(t2d); } // Change terminal of ACLS 1 to point to ACLS 2 other end CN context.ConnectTerminalToAnotherConnectitityNode(acls1Terminal, acls2otherEndCn.ConnectivityNode); } else { // Cable are not the same, we need to add a susbstation to act as a junction // Create muffe station var st = new PhysicalNetworkModel.Substation(); st.mRID = Guid.NewGuid().ToString(); st.name = "Junction"; st.PSRType = "Junction"; addList.Add(st); // Create voltage level var vl = new PhysicalNetworkModel.VoltageLevel(); vl.mRID = Guid.NewGuid().ToString(); vl.BaseVoltage = acls1.BaseVoltage; vl.name = "VL"; vl.EquipmentContainer1 = new VoltageLevelEquipmentContainer() { @ref = st.mRID }; addList.Add(vl); // Relate cn to voltage level if (_mappingContext.ConnectivityNodeToVoltageLevel.ContainsKey(cn)) { _mappingContext.ConnectivityNodeToVoltageLevel.Remove(cn); } _mappingContext.ConnectivityNodeToVoltageLevel.Add(cn, vl); } } // <> 2 kabler else { // Create muffe station var st = new PhysicalNetworkModel.Substation(); st.mRID = Guid.NewGuid().ToString(); st.name = "MUFFE"; st.PSRType = "Junction"; addList.Add(st); // Create voltage level var vl = new PhysicalNetworkModel.VoltageLevel(); vl.mRID = Guid.NewGuid().ToString(); vl.BaseVoltage = cnNeighborsx[0].BaseVoltage; vl.name = "VL"; vl.EquipmentContainer1 = new VoltageLevelEquipmentContainer() { @ref = st.mRID }; addList.Add(vl); // Relate cn to voltage level if (_mappingContext.ConnectivityNodeToVoltageLevel.ContainsKey(cn)) { _mappingContext.ConnectivityNodeToVoltageLevel.Remove(cn); } _mappingContext.ConnectivityNodeToVoltageLevel.Add(cn, vl); } } } } // return objects, except the one dropped foreach (var inputObj in input) { if (!dropList.Contains(inputObj)) { yield return(inputObj); } } // yield added objects, foreach (var inputObj in addList) { yield return(inputObj); } }
public IEnumerable <IdentifiedObject> Transform(CimContext context, IEnumerable <IdentifiedObject> inputParam) { FeederInfoContext feederContext = new FeederInfoContext(context); feederContext.CreateFeederObjects(); List <IdentifiedObject> input = inputParam.ToList(); HashSet <PhysicalNetworkModel.IdentifiedObject> dropList = new HashSet <IdentifiedObject>(); List <PhysicalNetworkModel.IdentifiedObject> addList = new List <IdentifiedObject>(); // AssetInfo to Asset ref dictionary Dictionary <string, string> assetInfoToAssetRef = new Dictionary <string, string>(); foreach (var inputCimObject in input) { if (inputCimObject is PhysicalNetworkModel.Asset) { var asset = inputCimObject as PhysicalNetworkModel.Asset; if (asset.AssetInfo != null && !assetInfoToAssetRef.ContainsKey(asset.AssetInfo.@ref)) { assetInfoToAssetRef.Add(asset.AssetInfo.@ref, asset.mRID); } } } // Asset to Equipment ref dictionary Dictionary <string, string> assetToEquipmentRef = new Dictionary <string, string>(); foreach (var inputCimObject in input) { if (inputCimObject is PhysicalNetworkModel.PowerSystemResource) { var psr = inputCimObject as PhysicalNetworkModel.PowerSystemResource; if (psr.Assets != null) { assetToEquipmentRef.Add(psr.Assets.@ref, psr.mRID); } } } // Set busbar names to station + voltagelevel + bay foreach (var inputCimObject in input) { if (inputCimObject is BusbarSection) { var bus = inputCimObject as BusbarSection; var st = bus.GetSubstation(true, context); bus.name = st.name + "_" + GetVoltageLevelStr(bus.BaseVoltage) + "_" + bus.name; var feederInfo = feederContext.GeConductingEquipmentFeederInfo(bus); if (feederInfo != null && feederInfo.Feeders != null && feederInfo.Feeders.Count > 0) { var feeder = feederInfo.Feeders[0]; if (feeder.ConnectionPoint.Substation != null) { bus.description = feeder.ConnectionPoint.Substation.name; } } } } // Set feeder name on junction connectivity nodes between cables foreach (var inputCimObject in input) { if (inputCimObject is ConnectivityNode) { var cn = inputCimObject as ConnectivityNode; if (cn.mRID == "c540b203-e442-7027-824c-bc561b3de47d") { } var cnEqs = context.GetConnections(cn); if (cnEqs.Count > 0) { if (cnEqs.All(e => e.ConductingEquipment is ACLineSegment)) { var eq = cnEqs.First().ConductingEquipment; var feederInfo = feederContext.GeConductingEquipmentFeederInfo(eq); if (feederInfo != null && feederInfo.Feeders != null && feederInfo.Feeders.Count > 0) { var feeder = feederInfo.Feeders[0]; if (feeder.ConnectionPoint.Substation != null) { cn.description = feeder.ConnectionPoint.Substation.name; } } } } } } // Set peterson coil name to station + gis name + min og max foreach (var inputCimObject in input) { if (inputCimObject is PetersenCoil) { var coil = inputCimObject as PetersenCoil; var st = coil.GetSubstation(true, context); if (coil.Asset != null && coil.Asset.AssetInfo != null && coil.Asset.AssetInfo.@ref != null) { var coilInfo = context.GetObject <PetersenCoilInfoExt>(coil.Asset.AssetInfo.@ref); coil.name = st.name + " " + coil.name; if (coilInfo != null && coilInfo.minimumCurrent != null && coilInfo.maximumCurrent != null) { coil.name += " " + (int)coilInfo?.minimumCurrent?.Value + "-" + (int)coilInfo?.maximumCurrent?.Value; } else { Logger.Log(LogLevel.Warning, "Slukkepole på station: " + st.name + " mangler værdier."); } } else { coil.name = st.name + " " + coil.name + " 0-0"; } } } // Set reactor coil (linear shunt compensator) to station + gis name + min og max foreach (var inputCimObject in input) { if (inputCimObject is LinearShuntCompensator) { var coil = inputCimObject as LinearShuntCompensator; var st = coil.GetSubstation(true, context); if (coil.Asset != null && coil.Asset.AssetInfo != null && coil.Asset.AssetInfo.@ref != null) { var coilInfo = context.GetObject <LinearShuntCompensatorInfoExt>(coil.Asset.AssetInfo.@ref); coil.name = st.name + " " + coil.name; if (coilInfo != null && coilInfo.minimumReactivePower != null && coilInfo.maximumReactivePower != null) { coil.name += " " + (int)coilInfo?.minimumReactivePower?.Value + "-" + (int)coilInfo?.maximumReactivePower?.Value; } else { Logger.Log(LogLevel.Warning, "Reaktorspole på station: " + st.name + " mangler værdier."); } } else { coil.name = st.name + " " + coil.name + " 0-0"; } } } // Remove injection > 50 kV foreach (var inputCimObject in input) { if (inputCimObject is ExternalNetworkInjection) { var inj = inputCimObject as ExternalNetworkInjection; if (inj.BaseVoltage > 50000) { dropList.Add(inj); var injConnections = context.GetConnections(inj); foreach (var injCon in injConnections) { dropList.Add(injCon.Terminal); } } } } // Fix and check objects foreach (var inputCimObject in input) { // Remove switch gear busbar asset model information (because PF complain about missing type, and Konstant/Thue says he don't want types into PF for now if (inputCimObject is BusbarSectionInfo) { BusbarSectionInfo bsi = inputCimObject as BusbarSectionInfo; bsi.AssetModel = null; var assetMrid = assetInfoToAssetRef[inputCimObject.mRID]; var asset = context.GetObject <PhysicalNetworkModel.Asset>(assetMrid); asset.type = null; asset.name = null; asset.AssetModel = null; } // Remove asset manufacture information on busbars and switches if (inputCimObject is BusbarSection || inputCimObject is Switch) { ConductingEquipment ci = inputCimObject as ConductingEquipment; var asset = context.GetObject <PhysicalNetworkModel.Asset>(ci.Assets.@ref); asset.type = null; asset.name = null; asset.AssetModel = null; } // Remove measurment current transformer and cts sitting on voltage level < 60 kV if (inputCimObject is CurrentTransformer && !((CurrentTransformer)inputCimObject).PSRType.ToLower().Contains("kundemaaling")) { var ct = inputCimObject as CurrentTransformer; bool ctIsDropped = false; try { var ctTerminal = context.GetObject <Terminal>(ct.Terminal.@ref); var ctEq = context.GetObject <ConductingEquipment>(ctTerminal.ConductingEquipment.@ref); if (ctEq.BaseVoltage < 60000) { dropList.Add(ct); ctIsDropped = true; } } catch (ArgumentException ex) { dropList.Add(ct); ctIsDropped = true; } // Move CT to line end, transformer end var st = ct.GetSubstation(true, context); foreach (var eq in st.GetEquipments(context)) { // If component inside same bay as ct if (eq is ConductingEquipment && eq.EquipmentContainer.@ref == ct.EquipmentContainer.@ref) { var ci = eq as ConductingEquipment; var ciConnections = context.GetConnections(ci); foreach (var ciConnection in ciConnections) { var ciNeighbors = context.GetConnections(ciConnection.ConnectivityNode).Where(c => c.ConductingEquipment != ci).ToList(); if (ciNeighbors.Any(c => c.ConductingEquipment is ACLineSegment)) { ct.Terminal.@ref = ciConnection.Terminal.mRID; } else if (ciNeighbors.Any(c => c.ConductingEquipment is PowerTransformer)) { ct.Terminal.@ref = ciConnection.Terminal.mRID; } else if (ciNeighbors.Count == 0) { ct.Terminal.@ref = ciConnection.Terminal.mRID; } } } } } // Check that current transformer infos has currents if (inputCimObject is CurrentTransformerInfoExt) { var ctInfo = inputCimObject as CurrentTransformerInfoExt; var assetMrid = assetInfoToAssetRef[ctInfo.mRID]; var eqMrid = assetToEquipmentRef[assetMrid]; var ct = context.GetObject <CurrentTransformerExt>(eqMrid); var ctAsset = context.GetObject <PhysicalNetworkModel.Asset>(assetMrid); if (ct.PSRType != null && ct.PSRType == "StromTransformer") { // Make sure primary and secondary current is set, because otherwise PF import fails if (ctInfo.primaryCurrent == null) { var stName = ct.GetSubstation(true, context).name; var bayName = ct.GetBay(true, context).name; Logger.Log(LogLevel.Warning, "CT Missing primary current. Will not be transfered to PF: " + stName + " " + bayName); ctInfo.primaryCurrent = new CurrentFlow() { Value = 0, unit = UnitSymbol.A }; dropList.Add(ct); dropList.Add(ctAsset); dropList.Add(ctInfo); } if (ctInfo.secondaryCurrent == null) { var stName = ct.GetSubstation(true, context).name; var bayName = ct.GetBay(true, context).name; Logger.Log(LogLevel.Warning, "CT Missing secondary current: " + stName + " " + bayName); ctInfo.secondaryCurrent = new CurrentFlow() { Value = 0, unit = UnitSymbol.A }; } } else { dropList.Add(ct); dropList.Add(ctAsset); dropList.Add(ctInfo); } } // Remove potential transformers sitting on voltage level < 60 kV if (inputCimObject is PotentialTransformer) { var pt = inputCimObject as PotentialTransformer; // If terminal point to object we don't have including - i.e. some 400 volt component - don't bother with the CT if (context.GetAllObjects().Exists(o => o.mRID == pt.Terminal.@ref)) { var ptTerminal = context.GetObject <Terminal>(pt.Terminal.@ref); var ptEq = context.GetObject <ConductingEquipment>(ptTerminal.ConductingEquipment.@ref); if (ptEq.BaseVoltage < 60000) { dropList.Add(pt); } } else { dropList.Add(pt); } } // Check that potential transformer info has voltages if (inputCimObject is PotentialTransformerInfoExt) { var vtInfo = inputCimObject as PotentialTransformerInfoExt; var assetMrid = assetInfoToAssetRef[vtInfo.mRID]; var eqMrid = assetToEquipmentRef[assetMrid]; var vtAsset = context.GetObject <PhysicalNetworkModel.Asset>(assetMrid); var vt = context.GetObject <PotentialTransformer>(eqMrid); var vtSt = vt.GetSubstation(true, context); // Make sure primary and secondary voltage is set, because otherwise PF import fails if (vtInfo.primaryVoltage == null) { vtInfo.primaryVoltage = new Voltage() { Value = 0, unit = UnitSymbol.V }; var stName = vt.GetSubstation(true, context).name; var bayName = vt.GetBay(true, context).name; Logger.Log(LogLevel.Warning, "VT Missing primary voltage. VT will not be transfered to PF." + stName + " " + bayName); dropList.Add(vt); dropList.Add(vtAsset); dropList.Add(vtInfo); } else if (vtInfo.secondaryVoltage == null) { vtInfo.secondaryVoltage = new Voltage() { Value = 0, unit = UnitSymbol.V }; var stName = vt.GetSubstation(true, context).name; var bayName = vt.GetBay(true, context).name; Logger.Log(LogLevel.Warning, "VT Missing secondary voltage. VI will not be transfered to PF." + stName + " " + bayName); dropList.Add(vt); dropList.Add(vtAsset); dropList.Add(vtInfo); } } // Set relay names to station + bay if (inputCimObject is ProtectionEquipment) { var relay = inputCimObject as ProtectionEquipment; // get relay station and bay via the switch it is connected to if (relay.ProtectedSwitches != null && relay.ProtectedSwitches.Length > 0) { try { var peSw = context.GetObject <PowerSystemResource>(relay.ProtectedSwitches[0].@ref); var bay = peSw.GetBay(true, context); var st = peSw.GetSubstation(true, context); relay.name = st.name + " " + bay.name; } catch (Exception ex) { Logger.Log(LogLevel.Warning, "Cannot find switch: " + relay.ProtectedSwitches[0].@ref + " connected to replay: " + inputCimObject.mRID); } } else { dropList.Add(inputCimObject); } } // Set electrical values on internal substation cables to 0 if (inputCimObject is ACLineSegment) { var acls = inputCimObject as ACLineSegment; if (acls.PSRType == "InternalCable") { // Set name to internal cable acls.name = "Internal Cable"; // Set length to 1 meter acls.length.Value = 1; // Set value to zero acls.r = new Resistance() { Value = 0 }; acls.r0 = new Resistance() { Value = 0 }; acls.x = new Reactance() { Value = 0 }; acls.x0 = new Reactance() { Value = 0 }; acls.bch = new Susceptance() { Value = 0 }; acls.b0ch = new Susceptance() { Value = 0 }; acls.gch = new Conductance() { Value = 0 }; acls.g0ch = new Conductance() { Value = 0 }; } } // Sæt transformer vikling navn og r,x,b,g værdier på vikling 2 til 0 if (inputCimObject is PowerTransformerEndExt) { var ptEnd = inputCimObject as PowerTransformerEndExt; var pt = context.GetObject <PowerTransformer>(ptEnd.PowerTransformer.@ref); ptEnd.name = pt.Substation.name + "_" + pt.name + "_T" + ptEnd.endNumber; /* Don't calculate r,x,b,g anymore. * if (ptEnd.endNumber == "1") * { * ptEnd.b0 = new Susceptance() { Value = 0 }; * ptEnd.g0 = new Conductance() { Value = 0 }; * * if (ptEnd.ratedU == null || * ptEnd.ratedS == null || * ptEnd.excitingCurrentZero == null || * ptEnd.loss == null || * ptEnd.lossZero == null || * ptEnd.uk == null) * { * // FIX: burde måske logge fejl, men PF skal nok brokke sig * } * else * { * // Beregn r: loss * (ratedU / ratedS * 1000)^2 * ptEnd.r = new Resistance() { Value = ptEnd.loss.Value * Math.Pow((ptEnd.ratedU.Value / (ptEnd.ratedS.Value * 1000)), 2) }; * * // Beregn g: (LossZero / ratedU^2) * double g = ptEnd.lossZero.Value / Math.Pow(ptEnd.ratedU.Value, 2); * ptEnd.g = new Conductance() { Value = g }; * * // Beregn YOC: (excitingCurrentZero*ratedS)/(100 * (ratedU^2)) * double yoc = (ptEnd.excitingCurrentZero.Value * (ptEnd.ratedS.Value * 1000)) / (100 * Math.Pow(ptEnd.ratedU.Value, 2)); * * // Beregn b: SQRT(YOC^2-g^2) * ptEnd.b = new Susceptance() * { * Value = Math.Sqrt(Math.Pow(yoc, 2) - Math.Pow(g, 2)) * }; * * // Beregn Zk: (uk*ratedU^2)/(100*ratedS) * double zk = (ptEnd.uk.Value * Math.Pow(ptEnd.ratedU.Value, 2)) / (100 * (ptEnd.ratedS.Value * 1000)); * * // Beregn x: SQRT(Zk^2-r^2) * ptEnd.x = new Reactance() * { * Value = Math.Sqrt( * Math.Pow(zk, 2) - Math.Pow(ptEnd.r.Value, 2) * ) * }; * } * } */ if (ptEnd.endNumber == "2") { // Set value to zero ptEnd.r = new Resistance() { Value = 0 }; ptEnd.r0 = new Resistance() { Value = 0 }; ptEnd.x = new Reactance() { Value = 0 }; ptEnd.x0 = new Reactance() { Value = 0 }; ptEnd.b = new Susceptance() { Value = 0 }; ptEnd.b0 = new Susceptance() { Value = 0 }; ptEnd.g = new Conductance() { Value = 0 }; ptEnd.g0 = new Conductance() { Value = 0 }; } } // Remove 'TRF' from transformer name if (inputCimObject is PowerTransformer) { inputCimObject.name = inputCimObject.name.Replace("TRF", ""); } // Ensure bay name is max 32 charaters if (inputCimObject is IdentifiedObject && inputCimObject.name != null && inputCimObject.name.Length > 32) { inputCimObject.name = inputCimObject.name.Substring(0, 32); } // Set name of disconnectors to ADSK if (inputCimObject is Disconnector) { inputCimObject.name = "ADSK"; } // Set name of disconnectors to ADSK if (inputCimObject is Fuse) { inputCimObject.name = "SIKRING"; } // Ensure connectivity nodes / busbars have proper names. // Needed by Konstant to support short circuit result extracts etc. PF uses the name of the node/busbar in reports. // Also needed to support time series import (Jakob busbar naming) if (inputCimObject is ConnectivityNode) { var cn = inputCimObject as ConnectivityNode; if (cn.mRID == "1663a3a8-a706-726a-8de5-7f57e2f9e68b") { } if (cn.name == null || cn.name.Length == 0) { var cnNeighbors = cn.GetNeighborConductingEquipments(context); var pt = cnNeighbors.Find(o => o is PowerTransformer) as PowerTransformer; var bus = cnNeighbors.Find(o => o is BusbarSection); if (pt != null) { var stVoltageLevels = context.GetSubstationVoltageLevels(pt.Substation); var ptConnections = context.GetConnections(pt); var ptTerminal = ptConnections.First(c => c.ConnectivityNode == cn); var ptEnds = pt.GetEnds(context); var ptEnd = ptEnds.Find(e => e.Terminal.@ref == ptTerminal.Terminal.mRID); double ptEndVoltageLevel = ptEnd.BaseVoltage; if (pt.name != null) { // HACK SHOULD BE CLEANED UP // Terminal actual exist in source, but get trown away in filter, because nothing connected to it if (!ptConnections.Exists(c => c.Terminal.sequenceNumber == "2")) { Logger.Log(LogLevel.Info, "Station: " + pt.Substation.name + " Trafo: " + pt.name + " mangler secondær skinne. Vil bliver oprettet"); var ptLvCn = new ConnectivityNode() { mRID = Guid.NewGuid().ToString(), name = pt.GetSubstation(true, context).name + "_" + GetVoltageLevelStr(400) + "_" + pt.name.Replace("TRF", "") }; addList.Add(ptLvCn); if (stVoltageLevels.Exists(o => o.BaseVoltage == 400)) { var vl = stVoltageLevels.First(o => o.BaseVoltage == 400); _mappingContext.ConnectivityNodeToVoltageLevel.Add(ptLvCn, vl); } else { var vl = new DAX.CIM.PhysicalNetworkModel.VoltageLevel() { mRID = Guid.NewGuid().ToString(), name = "0,4 kV", EquipmentContainer1 = new VoltageLevelEquipmentContainer() { @ref = pt.Substation.mRID }, BaseVoltage = 400 }; addList.Add(vl); stVoltageLevels.Add(vl); _mappingContext.ConnectivityNodeToVoltageLevel.Add(ptLvCn, vl); } var ptLvTerminal = new Terminal() { mRID = Guid.NewGuid().ToString(), phases = PhaseCode.ABCN, phasesSpecified = true, sequenceNumber = "2", ConnectivityNode = new TerminalConnectivityNode() { @ref = ptLvCn.mRID }, ConductingEquipment = new TerminalConductingEquipment { @ref = pt.mRID } }; var ptEnd2 = context.GetPowerTransformerEnds(pt).First(p => p.endNumber == "2"); ptEnd2.Terminal = new TransformerEndTerminal() { @ref = ptLvTerminal.mRID }; addList.Add(ptLvTerminal); } } // IF the PT END CN is connected to a conducting equipment if (cnNeighbors.Exists(o => !(o is PowerTransformer) && o.BaseVoltage > 0.0)) { ptEndVoltageLevel = cnNeighbors.First(o => !(o is PowerTransformer) && o.BaseVoltage > 0.0).BaseVoltage; if (stVoltageLevels.Exists(o => o.BaseVoltage == ptEndVoltageLevel)) { var vl = stVoltageLevels.First(o => o.BaseVoltage == ptEndVoltageLevel); _mappingContext.ConnectivityNodeToVoltageLevel.Add(cn, vl); } } // IF the PT END CN is *not* connected to anything else { // Set CN to PT END voltage level var vl = stVoltageLevels.First(o => o.BaseVoltage == ptEndVoltageLevel); _mappingContext.ConnectivityNodeToVoltageLevel.Add(cn, vl); // If 60 kV transformer secondary side if (ptEndVoltageLevel < 20000 && ptEndVoltageLevel > 5000) { if (ptEnds.Exists(e => e.BaseVoltage == 60000)) { EnergyConsumer ec = new EnergyConsumer() { mRID = GUIDHelper.CreateDerivedGuid(Guid.Parse(pt.mRID), 1001, true).ToString(), name = pt.GetSubstation(true, context).name + "_" + GetVoltageLevelStr(ptEndVoltageLevel) + "_" + pt.name.Replace("TRF", ""), EquipmentContainer = new EquipmentEquipmentContainer() { @ref = vl.mRID }, BaseVoltage = vl.BaseVoltage }; Terminal ecTerm = new Terminal() { mRID = GUIDHelper.CreateDerivedGuid(Guid.Parse(pt.mRID), 1002, true).ToString(), name = ec.name + "_T1", ConductingEquipment = new TerminalConductingEquipment() { @ref = ec.mRID }, ConnectivityNode = new TerminalConnectivityNode() { @ref = cn.mRID } }; addList.Add(ec); addList.Add(ecTerm); } } } cn.name = pt.GetSubstation(true, context).name + "_" + GetVoltageLevelStr(ptEndVoltageLevel) + "_" + pt.name.Replace("TRF", ""); /* * // Hvis trafo deler node med skinne, eller node er 400 volt, så brug jakob navngivning * if (bus != null || ptEndVoltageLevel == 400) * cn.name = pt.GetSubstation(true, context).name + "_" + GetVoltageLevelStr(ptEndVoltageLevel) + "_" + pt.name.Replace("TRF", ""); * else * cn.name = "CN"; */ } else if (bus != null && bus.name != null) { cn.name = bus.name; cn.description = bus.description; } else { var bay = cn.GetBay(false, context); if (bay != null) { if (cnNeighbors.Count == 1 || cnNeighbors.Exists(n => !(n is Switch))) { cn.name = bay.name + " ENDE"; } else { cn.name = bay.name; } } else { cn.name = "CN"; } } } } } // return objects, except the one dropped foreach (var inputObj in input) { if (!dropList.Contains(inputObj)) { yield return(inputObj); } } // yield added objects, foreach (var inputObj in addList) { yield return(inputObj); } }
/// <summary> /// Creates entity for specified global inside the container. /// </summary> /// <param name="globalId">Global id of the entity for insert</param> /// <returns>Created entity (identified object).</returns> public IdentifiedObject CreateEntity(long globalId) { short type = ModelCodeHelper.ExtractTypeFromGlobalId(globalId); IdentifiedObject io = null; switch ((DMSType)type) { case DMSType.BASEVOLTAGE: { io = new BaseVoltage(globalId); break; } case DMSType.TERMINAL: { io = new Terminal(globalId); break; } case DMSType.CONNECTIVITYNODE: { io = new ConnectivityNode(globalId); break; } case DMSType.POWERTRANSFORMER: { io = new PowerTransformer(globalId); break; } case DMSType.ENERGYSOURCE: { io = new EnergySource(globalId); break; } case DMSType.ENERGYCONSUMER: { io = new EnergyConsumer(globalId); break; } case DMSType.TRANSFORMERWINDING: { io = new TransformerWinding(globalId); break; } case DMSType.FUSE: { io = new Fuse(globalId); break; } case DMSType.DISCONNECTOR: { io = new Disconnector(globalId); break; } case DMSType.BREAKER: { io = new Breaker(globalId); break; } case DMSType.LOADBREAKSWITCH: { io = new LoadBreakSwitch(globalId); break; } case DMSType.ACLINESEGMENT: { io = new ACLineSegment(globalId); break; } case DMSType.DISCRETE: { io = new Discrete(globalId); break; } case DMSType.ANALOG: { io = new Analog(globalId); break; } case DMSType.SYNCHRONOUSMACHINE: { io = new SynchronousMachine(globalId); break; } default: { string message = String.Format("Failed to create entity because specified type ({0}) is not supported.", type); Logger.LogError(message); throw new Exception(message); } } // Add entity to map this.AddEntity(io); return(io); }
/// <summary> /// performs a traversal of all nodes connected to each other by switches /// </summary>t /// <param name="topoNode"></param> /// <param name="connNode"></param> private void traverseSwitches(TopologicalNode.VoltageLevel topoNode, ConnectivityNode connNode) { if(topoNode.Nodes.ConnectivityNodes.ContainsKey(connNode.Name)) { return;} topoNode.Nodes.ConnectivityNodes.Add(connNode.Name, connNode); connNode.StaticTopoNode = topoNode; foreach (ConnectivityNode adjacentNode in connNode.AdjacentSwitchNodes(true)) { traverseSwitches(topoNode, adjacentNode); } }
void PopulateConnectivityNodeProperties(ConnectivityNode x, ResourceDescription rd) { PopulateIdentifiedObjectProperties(x, rd); }
public BrisiCvor(String id) { node = new ConnectivityNode(); node.mRID = id; }
private void PrintLines() { foreach (ACLineSegment l in Singleton.Instance().AClines) { System.Windows.Shapes.Line line = new System.Windows.Shapes.Line(); SolidColorBrush brush = new SolidColorBrush(); brush.Color = Colors.Green; line.StrokeThickness = 1; line.Stroke = brush; ConnectivityNode od = null; //cvor pocetni ConnectivityNode na = null; //dest foreach (Terminal terminal in l.terminali) { if (od == null) { foreach (CIM.IEC61970.Base.Core.Substation s in Singleton.Instance().Substations) { foreach (ConnectivityNode cvor in s.connectivityNodes) { if (cvor.mRID.Equals(terminal.ConnectivityNode.mRID)) { od = cvor; od.X = cvor.x + s.x + (s.connectivityNodes.IndexOf(cvor) * 50) + 10; od.Y = cvor.y + s.y + (s.connectivityNodes.IndexOf(cvor) * 50) + 10; break; } } } } else { foreach (CIM.IEC61970.Base.Core.Substation s in Singleton.Instance().Substations) { foreach (ConnectivityNode cvor1 in s.connectivityNodes) { if (cvor1.mRID.Equals(terminal.ConnectivityNode.mRID)) { na = cvor1; na.X = cvor1.x + s.x + (s.connectivityNodes.IndexOf(cvor1) * 50) + 10; na.Y = cvor1.y + s.y + (s.connectivityNodes.IndexOf(cvor1) * 50) + 10; break; } } } } } BindingOperations.SetBinding(line, System.Windows.Shapes.Line.X1Property, new Binding { Source = od, Path = new PropertyPath("X") }); BindingOperations.SetBinding(line, System.Windows.Shapes.Line.Y1Property, new Binding { Source = od, Path = new PropertyPath("Y") }); BindingOperations.SetBinding(line, System.Windows.Shapes.Line.X2Property, new Binding { Source = na, Path = new PropertyPath("X") }); BindingOperations.SetBinding(line, System.Windows.Shapes.Line.Y2Property, new Binding { Source = na, Path = new PropertyPath("Y") }); viewCanvas.Children.Add(line); } }
public override void Izvrsi() { cnode = (ConnectivityNode)cnode.Clone(); cnode.mRID = ID; Singleton.Instance().Nodes.Add(cnode); }
private void addComponentToGlobalDictionary(IdentifiedObject component, Type type) { if (!globalComponentDictionary.ContainsKey(type)) { globalComponentDictionary.Add(type, new Dictionary <string, IdentifiedObject>()); } if (type.Equals(typeof(ACLineSegment))) { ACLineSegment acl = (ACLineSegment)component; globalComponentDictionary[type].Add(acl.MRID, acl); } else if (type.Equals(typeof(Terminal))) { Terminal tp = (Terminal)component; globalComponentDictionary[tp.GetType()].Add(tp.MRID, tp); } else if (type.Equals(typeof(Circuit))) { Circuit cr = (Circuit)component; globalComponentDictionary[cr.GetType()].Add(cr.MRID, cr); } else if (type.Equals(typeof(WireInfo))) { WireInfo wi = (WireInfo)component; globalComponentDictionary[wi.GetType()].Add(wi.MRID, wi); } else if (type.Equals(typeof(PerLengthSequenceImpedance))) { PerLengthSequenceImpedance pli = (PerLengthSequenceImpedance)component; globalComponentDictionary[pli.GetType()].Add(pli.MRID, pli); } else if (type.Equals(typeof(ConnectivityNode))) { ConnectivityNode cn = (ConnectivityNode)component; globalComponentDictionary[cn.GetType()].Add(cn.MRID, cn); } else if (type.Equals(typeof(PowerTransformer))) { PowerTransformer pt = (PowerTransformer)component; globalComponentDictionary[pt.GetType()].Add(pt.MRID, pt); } else if (type.Equals(typeof(PowerTransformerEnd))) { PowerTransformerEnd pt = (PowerTransformerEnd)component; globalComponentDictionary[pt.GetType()].Add(pt.MRID, pt); } else if (type.Equals(typeof(UsagePoint))) { UsagePoint us = (UsagePoint)component; globalComponentDictionary[us.GetType()].Add(us.MRID, us); } else if (type.Equals(typeof(PSRType))) { PSRType psr = (PSRType)component; globalComponentDictionary[psr.GetType()].Add(psr.Name, psr); } else if (type.Equals(typeof(SynchronousMachine))) { SynchronousMachine sm = (SynchronousMachine)component; globalComponentDictionary[sm.GetType()].Add(sm.Name, sm); } }
public DynamicTopologicalNode(ConnectivityNode firstConnectivityNode,VoltageLevel parent, DateTime time) { nodes.ConnectivityNodes.Add(firstConnectivityNode.Name, firstConnectivityNode); name = parent.name + "d" + parent.DynamicTopoNodeCount.ToString(); parentStaticNode = parent; timeIndex = time; }
private void Ok(object sender, RoutedEventArgs e) { bool ok = true; if (textBox1.Text.Trim().Equals("")) { textBox1.BorderBrush = Brushes.Red; textBox1.BorderThickness = new Thickness(1); ok = false;//length } else { try { float.Parse(textBox1.Text.Trim()); if (float.Parse(textBox1.Text.Trim()) < 5) { textBox1.BorderBrush = Brushes.Red; textBox1.BorderThickness = new Thickness(1); ok = false; } } catch { textBox1.BorderBrush = Brushes.Red; textBox1.BorderThickness = new Thickness(1); ok = false; } } if (textBox_Copy.Text.Trim().Equals(""))//gch { textBox_Copy.BorderBrush = Brushes.Red; textBox_Copy.BorderThickness = new Thickness(1); ok = false;//length } else { try { float.Parse(textBox_Copy.Text.Trim()); if (float.Parse(textBox_Copy.Text.Trim()) < 1) { textBox_Copy.BorderBrush = Brushes.Red; textBox_Copy.BorderThickness = new Thickness(1); ok = false; } } catch { textBox_Copy.BorderBrush = Brushes.Red; textBox_Copy.BorderThickness = new Thickness(1); ok = false; } } if (textBox_Copy1.Text.Trim().Equals(""))//bch { textBox_Copy1.BorderBrush = Brushes.Red; textBox_Copy1.BorderThickness = new Thickness(1); ok = false;//length } else { try { float.Parse(textBox_Copy1.Text.Trim()); if (float.Parse(textBox_Copy1.Text.Trim()) < 1) { textBox_Copy1.BorderBrush = Brushes.Red; textBox_Copy1.BorderThickness = new Thickness(1); ok = false; } } catch { textBox_Copy1.BorderBrush = Brushes.Red; textBox_Copy1.BorderThickness = new Thickness(1); ok = false; } } if (textBox_Copy2.Text.Trim().Equals(""))//r { textBox_Copy2.BorderBrush = Brushes.Red; textBox_Copy2.BorderThickness = new Thickness(1); ok = false;//length } else { try { float.Parse(textBox_Copy2.Text.Trim()); if (float.Parse(textBox_Copy2.Text.Trim()) < 1) { textBox_Copy2.BorderBrush = Brushes.Red; textBox_Copy2.BorderThickness = new Thickness(1); ok = false; } } catch { textBox_Copy2.BorderBrush = Brushes.Red; textBox_Copy2.BorderThickness = new Thickness(1); ok = false; } } if (textBox_Copy3.Text.Trim().Equals(""))//x { textBox_Copy3.BorderBrush = Brushes.Red; textBox_Copy3.BorderThickness = new Thickness(1); ok = false;//length } else { try { float.Parse(textBox_Copy3.Text.Trim()); if (float.Parse(textBox_Copy3.Text.Trim()) < 1) { textBox_Copy3.BorderBrush = Brushes.Red; textBox_Copy3.BorderThickness = new Thickness(1); ok = false; } } catch { textBox_Copy3.BorderBrush = Brushes.Red; textBox_Copy3.BorderThickness = new Thickness(1); ok = false; } } if (textBox.Text.Trim().Equals("")) { textBox.BorderBrush = Brushes.Red; textBox.BorderThickness = new Thickness(1); ok = false;//name } if (comboBox.SelectedItem == null) { ok = false; //node1 } if (comboBox_Copy.SelectedItem == null) { ok = false; //node2 } ConnectivityNode n1 = comboBox.SelectedItem as ConnectivityNode; ConnectivityNode n2 = comboBox_Copy.SelectedItem as ConnectivityNode; bool sameSubstation = false; bool sameSubstation2 = false; foreach (Substation s in Singleton.Instance().Substations) { foreach (ConnectivityNode conNode in s.connectivityNodes) { if (conNode.mRID.Equals(n1.mRID)) { sameSubstation = true; } else if (conNode.mRID.Equals(n2.mRID)) { sameSubstation2 = true; } } if (sameSubstation && sameSubstation2) { break; } sameSubstation = false; sameSubstation2 = false; } if (n1.mRID.Equals(n2.mRID)) { MessageBox.Show("Cvorovi moraju biti razliciti."); ok = false; } else if (n1.m_BaseVoltage.nominalVoltage != n2.m_BaseVoltage.nominalVoltage) { MessageBox.Show("Cvorovi moraju imati isti nominaln napon."); ok = false; } else if (sameSubstation && sameSubstation2) { MessageBox.Show("Cvorovi ne smeju pripadati istoj trafostanici."); ok = false; } if (ok) { DodajACLine dl = new DodajACLine(n1, n2, textBox.Text.Trim(), float.Parse(textBox1.Text.Trim()), float.Parse(textBox_Copy.Text.Trim()), float.Parse(textBox_Copy1.Text.Trim()), float.Parse(textBox_Copy2.Text.Trim()), float.Parse(textBox_Copy3.Text.Trim())); Singleton.Instance().inv.DodajIzvrsi(dl); this.Close(); } }