// 依存関係が存在する入れ子オブジェクトを監視する void ReconnectNested() { foreach (var nest in WireInfo.GetNestPropertyNames()) { ReconnectNested(nest); } }
private AssetInfo createWireInfoObject(CableConfiguration configuration, string mRID) { WireInfo wi = new WireInfo(); if (!wireInfoContainer.ContainsKey(configuration.Name)) { if (configuration.Name != "xfm_1") { string wi_mrid = mRID + "_WI"; wi.ID = wi_mrid; wi.MRID = wi_mrid; wi.Name = configuration.Name; wi.Material = (WireMaterialKind)((int)configuration.Cable.MaterialKind); wi.SizeDescription = configuration.Cable.SizeDescription; wi.Gmr = (float)0.001; wi.Radius = 0; wi.RatedCurrent = 0; wireInfoContainer.Add(configuration.Name, wi); addComponentToGlobalDictionary(wi, wi.GetType()); } //RADIUS and RATED_CURRENT are going to have values } else { wi = wireInfoContainer[configuration.Name]; return(wi); } return(wi); }
public IHttpActionResult PutWireInfo(int id, WireInfo wireInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != wireInfo.WireId) { return(BadRequest()); } db.Entry(wireInfo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WireInfoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public List <WireInfo> GetWiring() { List <WireInfo> list = new List <WireInfo>(); XElement element = _doc.Element("AlarmSystem"); if (element != null) { element = element.Element("Wiring"); if (element != null) { foreach (var wire in element.Elements("Wire")) { WireInfo newInfo = new WireInfo() { Type = wire.Attribute("type").Value ?? string.Empty, Source = wire.Attribute("source").Value ?? string.Empty, Sink = wire.Attribute("sink").Value ?? string.Empty }; list.Add(newInfo); } } } return(list); }
// Targetに入れ子になったオブジェクト内のプロパティが変更された場合のイベントハンドラ private void Nested_PropertyChanged(object sender, PropertyChangedEventArgs e) { // どのプロパティのオブジェクトからの通知なのか判断 var nestedPropName = NestHolderBack[sender as INotifyPropertyChanged]; // 依存関係を解決してINPC発行 WireInfo.ResolveDependency(Target, nestedPropName, e.PropertyName); }
public IHttpActionResult GetWireInfo(int id) { WireInfo wireInfo = db.WireInfoes.Find(id); if (wireInfo == null) { return(NotFound()); } return(Ok(wireInfo)); }
// Target直下のプロパティが変更された場合のイベントハンドラ private void Target_PropertyChanged(object sender, PropertyChangedEventArgs e) { // 依存関係を解決してINPC発行 WireInfo.ResolveDependency(Target, e.PropertyName, null); if (WireInfo.IsNestedDependency(e.PropertyName)) { // 今差し変わったオブジェクト配下のプロパティへ依存があるなら、 // 新しい方のオブジェクトのINPCを購読する ReconnectNested(e.PropertyName); } }
public IHttpActionResult PostWireInfo(WireInfo wireInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.WireInfoes.Add(wireInfo); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = wireInfo.WireId }, wireInfo)); }
public IHttpActionResult DeleteWireInfo(int id) { WireInfo wireInfo = db.WireInfoes.Find(id); if (wireInfo == null) { return(NotFound()); } db.WireInfoes.Remove(wireInfo); db.SaveChanges(); return(Ok(wireInfo)); }
public List<WireInfo> GetWiring() { List<WireInfo> list = new List<WireInfo>(); XElement element = _doc.Element("AlarmSystem"); if (element != null) { element = element.Element("Wiring"); if (element != null) { foreach (var wire in element.Elements("Wire")) { WireInfo newInfo = new WireInfo() { Type = wire.Attribute("type").Value ?? string.Empty, Source = wire.Attribute("source").Value ?? string.Empty, Sink = wire.Attribute("sink").Value ?? string.Empty }; list.Add(newInfo); } } } return list; }
private IEnumerator Initialize() { yield return(null); var retries = 0; retry: // // STEP 1: Decide on all the arrows, filled stars and LED states // _arrows = new Arrow[ArrowMeshes.Length]; for (int i = 0; i < ArrowMeshes.Length; i++) { _arrows[i] = (Arrow)((Rnd.Range(0, 4) << 0) | (Rnd.Range(0, 5) << 2)); ArrowMeshes[i].material.mainTexture = Arrows[(int)_arrows[i]]; ArrowCB[i].text = "RGBYP".Substring((int)(_arrows[i] & Arrow.ColorMask) >> 2, 1); } _filledStars = new bool[StarMeshes.Length]; for (int i = 0; i < StarMeshes.Length; i++) { _filledStars[i] = Rnd.Range(0, 2) != 0; StarMeshes[i].material.mainTexture = Stars[_filledStars[i] ? 1 : 0]; } _ledsOn = new bool[LedMeshes.Length]; for (int i = 0; i < LedMeshes.Length; i++) { _ledsOn[i] = Rnd.Range(0, 2) != 0; LedMeshes[i].material = LedMaterials[_ledsOn[i] ? 1 : 0]; } // // STEP 2: Assign the wires to their connectors and decide their colors // var shuffledBottom = Enumerable.Range(0, 6).ToList().Shuffle(); for (int i = 0; i < 6; i++) { _wires[i] = new WireInfo { TopConnector = i < 4 ? i : Rnd.Range(0, 4), BottomConnector = shuffledBottom[i], Color = (WireColor)Rnd.Range(0, 8), Level = 1, HasBeenCut = false }; WireCB[_wires[i].BottomConnector].text = "RYBWGOPK".Substring((int)_wires[i].Color, 1); for (int j = 0; j < i; j++) { if ((_wires[j].TopConnector > _wires[i].TopConnector && _wires[j].BottomConnector < _wires[i].BottomConnector) || (_wires[j].TopConnector <_wires[i].TopConnector && _wires[j].BottomConnector> _wires[i].BottomConnector)) { _wires[i].Level = Math.Max(_wires[i].Level, _wires[j].Level + 1); } } } // // STEP 3: Determine the solution. Make sure that at least one wire needs to be cut. // const string rules = "LWIPMVIFIUCCFRHHTVUDLRJBQWBPJTQD"; var colorsForRedRule = new[] { WireColor.Red, WireColor.Yellow, WireColor.Blue, WireColor.White }; for (int i = 0; i < 6; i++) { var applicable = new List <string>(); var rule = 0; var arrowColor = _arrows[_wires[i].BottomConnector] & Arrow.ColorMask; // Red: The wire is red, yellow, blue, or white. if (colorsForRedRule.Contains(_wires[i].Color)) { rule += 8; applicable.Add("Red"); } // Orange: The wire shares the same color as its arrow. if ((_wires[i].Color == WireColor.Red && arrowColor == Arrow.Red) || (_wires[i].Color == WireColor.Green && arrowColor == Arrow.Green) || (_wires[i].Color == WireColor.Blue && arrowColor == Arrow.Blue) || (_wires[i].Color == WireColor.Yellow && arrowColor == Arrow.Yellow) || (_wires[i].Color == WireColor.Purple && arrowColor == Arrow.Purple)) { rule += 16; applicable.Add("Orange"); } // Yellow: The wire’s star is black. if (_filledStars[_wires[i].TopConnector]) { rule += 2; applicable.Add("Yellow"); } // Green: The wire’s position on the bottom is even. if (_wires[i].BottomConnector % 2 != 0) { rule += 4; applicable.Add("Green"); } // Blue: The wire crosses over another wire. if (_wires.Any(w => (w.BottomConnector > _wires[i].BottomConnector && w.TopConnector < _wires[i].TopConnector) || (w.BottomConnector <_wires[i].BottomConnector && w.TopConnector> _wires[i].TopConnector))) { rule += 1; applicable.Add("Blue"); } _wires[i].VennColors = applicable.ToArray(); _wires[i].Reason = rules[rule]; var dir = (_arrows[_wires[i].BottomConnector] & Arrow.DirectionMask); switch (rules[rule]) { // C: Cut the wire. case 'C': _wires[i].CutRule = CutRule.Cut; break; // F: Always cut the wire, but only cut it first. case 'F': _wires[i].CutRule = CutRule.CutFirst; break; // L: Always cut the wire, but only cut it last. case 'L': _wires[i].CutRule = CutRule.CutLast; break; // W: Cut the wire if more of the LEDs are on than off. case 'W': _wires[i].CutRule = _ledsOn.Count(l => l) > 1 ? CutRule.Cut : CutRule.DontCut; break; // T: Cut the wire if the first LED is on. case 'T': _wires[i].CutRule = _ledsOn[0] ? CutRule.Cut : CutRule.DontCut; break; // U: Cut the wire if its arrow points up or down. case 'U': _wires[i].CutRule = dir == Arrow.Up || dir == Arrow.Down ? CutRule.Cut : CutRule.DontCut; break; // M: Cut the wire if the arrow points down or right. case 'M': _wires[i].CutRule = dir == Arrow.Right || dir == Arrow.Down ? CutRule.Cut : CutRule.DontCut; break; // H: Cut the wire if the wire shares a star with another wire. case 'H': _wires[i].CutRule = _wires.Where((w, ix) => ix != i).Any(w => w.TopConnector == _wires[i].TopConnector) ? CutRule.Cut : CutRule.DontCut; break; // P: Cut the wire if its position at the bottom is equal to the number of ports. case 'P': _wires[i].CutRule = _wires[i].BottomConnector + 1 == Bomb.GetPortCount() ? CutRule.Cut : CutRule.DontCut; break; // B: Cut the wire if its position at the bottom is equal to the number of batteries. case 'B': _wires[i].CutRule = _wires[i].BottomConnector + 1 == Bomb.GetBatteryCount() ? CutRule.Cut : CutRule.DontCut; break; // I: Cut the wire if its position at the bottom is equal to the number of indicators. case 'I': _wires[i].CutRule = _wires[i].BottomConnector + 1 == Bomb.GetIndicators().Count() ? CutRule.Cut : CutRule.DontCut; break; // Q: Cut the wire if the color of the wire is unique. case 'Q': _wires[i].CutRule = _wires.Where((w, ix) => ix != i).Any(w => w.Color == _wires[i].Color) ? CutRule.DontCut : CutRule.Cut; break; // J: Cut the wire if, at the bottom, it is adjacent to an orange or purple wire. case 'J': _wires[i].CutRule = _wires.Any(w => (w.BottomConnector == _wires[i].BottomConnector - 1 || w.BottomConnector == _wires[i].BottomConnector + 1) && (w.Color == WireColor.Orange || w.Color == WireColor.Purple)) ? CutRule.Cut : CutRule.DontCut; break; // V: Cut the wire if the serial number has a vowel, or if the bomb has a USB port. case 'V': _wires[i].CutRule = Bomb.GetSerialNumberLetters().Any(ch => "AEIOU".Contains(ch)) || Bomb.GetPortCount("USB") > 0 ? CutRule.Cut : CutRule.DontCut; break; // R: Cut the wire if its arrow direction is unique. case 'R': _wires[i].CutRule = _arrows.Where((a, ix) => ix != _wires[i].BottomConnector).Any(a => (a & Arrow.DirectionMask) == dir) ? CutRule.DontCut : CutRule.Cut; break; // D: Do not cut the wire. case 'D': _wires[i].CutRule = CutRule.DontCut; break; } } if (_wires.All(w => w.CutRule == CutRule.DontCut)) { retries++; goto retry; } Array.Sort(_wires, (w1, w2) => w1.BottomConnector.CompareTo(w2.BottomConnector)); for (int i = 0; i < StarMeshes.Length; i++) { Debug.LogFormat("[Perplexing Wires #{0}] (h) Star #{1} is {2}.", _moduleId, i + 1, _filledStars[i] ? "filled" : "empty"); } for (int i = 0; i < ArrowMeshes.Length; i++) { Debug.LogFormat("[Perplexing Wires #{0}] (h) Arrow #{1} is {2} and pointing {3}.", _moduleId, i + 1, arrowColorStr(_arrows[i]), arrowDirStr(_arrows[i])); } for (int i = 0; i < LedMeshes.Length; i++) { Debug.LogFormat("[Perplexing Wires #{0}] (h) LED #{1} is {2}.", _moduleId, i + 1, _ledsOn[i] ? "on" : "off"); } // // STEP 4: Generate the actual wire meshes. (This also logs the wire states and rules.) // var wiresParent = Module.transform.Find("Wires"); for (int wIx = 0; wIx < _wires.Length; wIx++) { var wireObj = wiresParent.Find("Wire" + (wIx + 1)).gameObject; // Determine the “original” control points and raise height. var topConnector = Module.transform.Find("Strip2").Find("Connector" + (_wires[wIx].TopConnector + 1)); var topControl = topConnector.Find("Control"); topControl.localPosition = new Vector3(0, .2f, 0); var bottomConnector = Module.transform.Find("Strip1").Find("Connector" + (_wires[wIx].BottomConnector + 1)); var bottomControl = bottomConnector.Find("Control"); var raiseBy = 1.5 * (_wires[wIx].Level - 1) * (Pt)(transform.InverseTransformPoint(bottomControl.position) - transform.InverseTransformPoint(bottomConnector.position) + transform.InverseTransformPoint(topControl.position) - transform.InverseTransformPoint(topConnector.position)); // Slightly move the control point at the top connector to mitigate the incidence of wire collisions. var topControlX = 0f; if (_wires.Any(w => w.TopConnector == _wires[wIx].TopConnector && w.BottomConnector < _wires[wIx].BottomConnector) && !_wires.Any(w => w.TopConnector == _wires[wIx].TopConnector && w.BottomConnector > _wires[wIx].BottomConnector)) { topControlX = -.07f; } else if (_wires.Any(w => w.TopConnector == _wires[wIx].TopConnector && w.BottomConnector > _wires[wIx].BottomConnector) && !_wires.Any(w => w.TopConnector == _wires[wIx].TopConnector && w.BottomConnector < _wires[wIx].BottomConnector)) { topControlX = .07f; } var topControlZ = 0f; if (_wires.Any(w => Math.Sign(w.TopConnector - _wires[wIx].TopConnector) != Math.Sign(w.BottomConnector - _wires[wIx].BottomConnector) && w.Level < _wires[wIx].Level)) { topControlZ = .05f; } else if (_wires.Any(w => Math.Sign(w.TopConnector - _wires[wIx].TopConnector) != Math.Sign(w.BottomConnector - _wires[wIx].BottomConnector) && w.Level > _wires[wIx].Level)) { topControlZ = -.05f; } topControl.localPosition = new Vector3(topControlX, .2f, topControlZ); // Generate the meshes for this wire. var seed = Rnd.Range(0, int.MaxValue); var mesh = MeshGenerator.GenerateWire( transform.InverseTransformPoint(topConnector.position), transform.InverseTransformPoint(topControl.position), transform.InverseTransformPoint(bottomControl.position), transform.InverseTransformPoint(bottomConnector.position), 5, MeshGenerator.WirePiece.Uncut, MeshGenerator.Mode.Wire, seed, raiseBy); _wires[wIx].MeshFilter = wireObj.GetComponent <MeshFilter>(); _wires[wIx].MeshFilter.mesh = mesh; wireObj.GetComponent <MeshRenderer>().material = WireMaterials[(int)_wires[wIx].Color]; _wires[wIx].CutMesh = MeshGenerator.GenerateWire( transform.InverseTransformPoint(topConnector.position), transform.InverseTransformPoint(topControl.position), transform.InverseTransformPoint(bottomControl.position), transform.InverseTransformPoint(bottomConnector.position), 5, MeshGenerator.WirePiece.Cut, MeshGenerator.Mode.Wire, seed, raiseBy); _wires[wIx].CutHighlightMesh = MeshGenerator.GenerateWire( transform.InverseTransformPoint(topConnector.position), transform.InverseTransformPoint(topControl.position), transform.InverseTransformPoint(bottomControl.position), transform.InverseTransformPoint(bottomConnector.position), 5, MeshGenerator.WirePiece.Cut, MeshGenerator.Mode.Highlight, seed, raiseBy); _wires[wIx].CopperMesh = MeshGenerator.GenerateWire( transform.InverseTransformPoint(topConnector.position), transform.InverseTransformPoint(topControl.position), transform.InverseTransformPoint(bottomControl.position), transform.InverseTransformPoint(bottomConnector.position), 5, MeshGenerator.WirePiece.Copper, MeshGenerator.Mode.Wire, seed, raiseBy); var highlightMesh = MeshGenerator.GenerateWire( transform.InverseTransformPoint(topConnector.position), transform.InverseTransformPoint(topControl.position), transform.InverseTransformPoint(bottomControl.position), transform.InverseTransformPoint(bottomConnector.position), 5, MeshGenerator.WirePiece.Uncut, MeshGenerator.Mode.Highlight, seed, raiseBy); var highlight = wireObj.transform.Find("Highlight"); _wires[wIx].HighlightMeshFilter = highlight.GetComponent <MeshFilter>(); _wires[wIx].HighlightMeshFilter.mesh = highlightMesh; var highlight2 = highlight.Find("Highlight(Clone)"); if (highlight2 != null) { _wires[wIx].HighlightMeshFilter = highlight2.GetComponent <MeshFilter>(); _wires[wIx].HighlightMeshFilter.mesh = highlightMesh; } wireObj.GetComponent <MeshCollider>().sharedMesh = MeshGenerator.GenerateWire( transform.InverseTransformPoint(topConnector.position), transform.InverseTransformPoint(topControl.position), transform.InverseTransformPoint(bottomControl.position), transform.InverseTransformPoint(bottomConnector.position), 5, MeshGenerator.WirePiece.Uncut, MeshGenerator.Mode.Collider, seed, raiseBy); // Fix for a possible bug in Unity wireObj.GetComponent <MeshCollider>().enabled = true; wireObj.GetComponent <MeshCollider>().enabled = false; Debug.LogFormat("[Perplexing Wires #{6}] (h) Wire {0} to {1} is {2}: {3} (Venn: {4} = {5})", _wires[wIx].TopConnector + 1, _wires[wIx].BottomConnector + 1, _wires[wIx].Color, cutRuleStr(_wires[wIx].CutRule), _wires[wIx].VennColors.Length == 0 ? "none" : _wires[wIx].VennColors.JoinString("+"), _wires[wIx].Reason, _moduleId); _wires[wIx].Selectable = wireObj.GetComponent <KMSelectable>(); _wires[wIx].Selectable.OnInteract = getWireHandler(wIx); } // Output the generated SVG to the logfile. var svg = new StringBuilder(); var starsCoordsX = new[] { 123.3 - 5, 161 - 5, 198.5 - 5, 236 - 5 }; var starsCoordsY = new[] { 36.2, 50, 63.6, 77.2 }; var starsConnectorCoordsX = new[] { 115.6 - 5, 153.2 - 5, 190.8 - 5, 228.4 - 5 }; var starsConnectorCoordsY = new[] { 69.8, 83.5, 97.2, 111 }; // Wires for (var i = 0; i < 6; i++) { svg.AppendFormat( "<path d='M{0} 250 {0} 200 {1} {2} {3} {4}' stroke='#543' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/>" + "<path d='M{0} 250 {0} 200 {1} {2} {3} {4}' stroke='{5}' stroke-linecap='round' stroke-linejoin='round' stroke-width='13'/>" + "<text x='{0}' y='370' text-anchor='middle'>{6}</text>" + "<text x='{0}' y='390' text-anchor='middle' stroke='none' fill='{7}'>{8}</text>", /* {0} */ 40 + 40 * i, /* {1} */ starsConnectorCoordsX[_wires[i].TopConnector], /* {2} */ starsConnectorCoordsY[_wires[i].TopConnector], /* {3} */ starsCoordsX[_wires[i].TopConnector], /* {4} */ starsCoordsY[_wires[i].TopConnector], /* {5} */ colorSvg(_wires[i].Color), /* {6} */ _wires[i].Reason, /* {7} */ _wires[i].CutRule == CutRule.DontCut ? "#a00" : "#080", /* {8} */ cutRuleSvg(_wires[i].CutRule) ); } // Lettering at the bottom var vennColors = new[] { "#eb1414", "#ffb100", "#ee0", "#00be00", "#09f" }; var vennColorNames = new[] { "Red", "Orange", "Yellow", "Green", "Blue" }; for (var i = 0; i < 6; i++) { for (var cIx = 0; cIx < _wires[i].VennColors.Length; cIx++) { var c = Array.IndexOf(vennColorNames, _wires[i].VennColors[cIx]); svg.AppendFormat("<rect x='{0}' y='{1}' width='20' height='10' stroke='none' fill='{2}'/>", 30 + 40 * i, 275 + 15 * c, vennColors[c]); } } // Frames svg.Append( "<path d='M10 10h50v110H10z'/>" + // LEDs frame "<path d='M95.5 10l169.2 61.7-10.2 28.2L85.3 38.2z' fill='#fff'/>" + // stars "<path d='M10 230h260v40H10z' fill='#fff'/>"); // arrows // LEDs svg.AppendFormat("<path d='M35 22 l8.7 4 2.2 9.6-6 7.6H30l-6-7.6 2-9.5z' fill='{0}'/>", _ledsOn[0] ? "lime" : "#234"); svg.AppendFormat("<path d='M35 54.5l8.7 4 2.2 9.5-6 7.7H30L24 68l2-9.4z' fill='{0}'/>", _ledsOn[1] ? "lime" : "#234"); svg.AppendFormat("<path d='M35 86.8l8.7 4.3 2.2 9.5-6 7.5H30l-6-7.5 2-9.7z' fill='{0}'/>", _ledsOn[2] ? "lime" : "#234"); // Stars for (var i = 0; i < 4; i++) { svg.AppendFormat("<path transform='translate({0}, {1}) rotate(20)' d='M0-10l2.2 7h7.3l-6 4.2 2.4 7-6-4.4-6 4.3 2.4-6.8-6-4.3H-2z' fill='{2}'/>", starsCoordsX[i], starsCoordsY[i], _filledStars[i] ? "black" : "white"); } // Arrows for (var i = 0; i < 6; i++) { svg.AppendFormat("<path transform='translate({0}, 250) rotate({1})' d='M0-15L11 0H5.7v15H-5.7v-15H-11z' fill='{2}'/>", 40 + 40 * i, arrowDirSvg(_arrows[i]), colorSvg(_arrows[i])); } Debug.LogFormat("[Perplexing Wires #{0}]=svg[Module:]<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 462 400' fill='none' stroke='#000' stroke-width='2' font-family='Trebuchet MS'>{1}</svg>", _moduleId, svg.ToString()); // Finally, get rid of the extra Wire objects that only exist to hold the colored materials. var dwIx = _wires.Length; while (true) { var wireObj = wiresParent.Find("Wire" + (dwIx + 1)); if (wireObj == null) { break; } Destroy(wireObj.gameObject); dwIx++; } // Object that will be cloned to create the wire copper when a wire is cut. _wireCopper = wiresParent.Find("WireCopper").gameObject; _wireCopper.SetActive(false); MainSelectable.Children = _wires.Select(w => w.Selectable).ToArray(); MainSelectable.UpdateChildren(); if (ColorblindMode.ColorblindModeActive) { ActivateColorblindMode(); } }
//-------------------------------------------------------------------------------------------------- bool _DoBuildWireList(MakeContext context) { context.Wires = new List <WireInfo>(); context.AllWiresClosed = true; var edgeCount = 0; for (int opIndex = 0; opIndex < Operands.Count; opIndex++) { var sourceBrep = GetOperandBRep(opIndex); var wires = sourceBrep?.Wires(); if (wires?.Count == 0) { continue; } if (wires.Count > 1) { Messages.Warning($"The loft can be build only through one wire per section, but the operand {opIndex} has more than one wire:"); } var currentEdgeCount = wires[0].Edges().Count; if (edgeCount == 0) { edgeCount = currentEdgeCount; } else if (currentEdgeCount != edgeCount) { Messages.Error($"The sketches of all sections must have the same count of segments. The segment count of operand {opIndex} is {currentEdgeCount}, but must be {edgeCount}"); return(false); } // Reset location, burn it into geometry var shapeFix = new ShapeFix_Shape(wires[0]); shapeFix.Perform(); shapeFix.FixWireTool().Perform(); var wire = shapeFix.Shape().ToWire(); // BRepLib.BuildCurves3d(wire); if (!wire.Closed()) { context.AllWiresClosed = false; } var wi = new WireInfo { Wire = wire, CoordinateSystem = wires[0].Location().ToAx3() }; // Just append if we do not have at least 2 wires if (context.Wires.Count < 2) { context.Wires.Add(wi); continue; } // Insert at front, if the wire lies behind var ownLocation = wi.CoordinateSystem.Location; var refLocation = context.Wires[0].CoordinateSystem.Location; var dirRef = new Vec(refLocation, context.Wires[1].CoordinateSystem.Location); if (new Vec(refLocation, ownLocation).IsOpposite(dirRef, Maths.HalfPI)) { // Is behind context.Wires.Insert(0, wi); continue; } // Sort in int insertAt = context.Wires.Count; for (int i = 0; i < context.Wires.Count - 1; i++) { refLocation = context.Wires[i].CoordinateSystem.Location; var distToCur = new Vec(refLocation, ownLocation).SquareMagnitude(); if (distToCur == 0) { Messages.Warning("The sketches of two sections do have the same location. One of the section is skipped."); continue; } // Sort by distance var nextDistance = new Vec(refLocation, context.Wires[i + 1].CoordinateSystem.Location).SquareMagnitude(); if (distToCur < nextDistance) { insertAt = i + 1; break; } } context.Wires.Insert(insertAt, wi); } return(true); }
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); } }