/// <summary> /// Caclulate the start location of the TempPipeline in term of the start comp is spliter /// </summary> private static void CalculateStartLocation() { Component compStart = PipeLineSystem.TempPipeline.CompStart; if (compStart is Spliter) { Spliter sp = (Spliter)compStart; int count = 0; foreach (var p in Network.GetListOfPipeline()) { if (p.CompStart == compStart) { count++; } } if (count == 0) { sp.SetUpperLocation(compStart.GetLocation()); PipeLineSystem.TempPipeline.setStartLocation(sp.GetUpperLocation()); } else { sp.SetLowerLocation(compStart.GetLocation()); PipeLineSystem.TempPipeline.setStartLocation(sp.GetLowerLocation()); } } else { PipeLineSystem.TempPipeline.setStartLocation(compStart.GetLocation()); } }
/// <summary> /// Convert from string to component /// </summary> /// <param name="s"></param> /// <returns></returns> private Component ConvertFromStringToComp(String s) { Component c = null; char[] separators = { '_' }; string[] ComponentInfor = s.Split(separators); string type = ComponentInfor[0]; if (type == "PU") { c = Pump.createPumpFromStringArray(ComponentInfor); } if (type == "SP") { c = Spliter.createSpliterFromStringArray(ComponentInfor); } if (type == "ASP") { c = AdjustableSpliter.createAdjustableSpliterFromStringArray(ComponentInfor); } if (type == "MG") { c = Merger.createMergerFromStringArray(ComponentInfor); } if (type == "SK") { c = Sink.createSinkFromStringArray(ComponentInfor); } return(c); }
/// <summary> /// Convert a information of components into a string /// </summary> /// <param name="component"></param> /// <returns></returns> private String convertComponentToString(Component component) { string result = null; if (component is Pump) { Pump pu = (Pump)component; result = pu.ToString(); } if (component is Sink) { Sink sk = (Sink)component; result = sk.ToString(); } if (component is Merger) { Merger mg = (Merger)component; result = mg.ToString(); } if (component is Spliter) { Spliter spt = (Spliter)component; result = spt.ToString(); } if (component is AdjustableSpliter) { AdjustableSpliter aspt = (AdjustableSpliter)component; result = aspt.ToString(); } return(result); }
/// <summary> /// Create an object of type Spliter from string infors /// </summary> /// <param name="SpliterInfors"></param> /// <returns></returns> public static Spliter createSpliterFromStringArray(string[] SpliterInfors) { Spliter sp = null; int id = Convert.ToInt16(SpliterInfors[1]); int x = Convert.ToInt32(SpliterInfors[2]); int y = Convert.ToInt32(SpliterInfors[3]); Point Location = new Point(x, y); double CurrentFlow = Convert.ToDouble(SpliterInfors[4]); double upperFlow = Convert.ToDouble(SpliterInfors[5]); double lowerFlow = Convert.ToDouble(SpliterInfors[6]); PipeLine inpipeline = new PipeLine(Convert.ToInt32(SpliterInfors[7]), 0); PipeLine outpipeline1 = new PipeLine(Convert.ToInt32(SpliterInfors[8]), 0); PipeLine outpipeline2 = new PipeLine(Convert.ToInt32(SpliterInfors[9]), 0); int upperX = Convert.ToInt32(SpliterInfors[10]); int upperY = Convert.ToInt32(SpliterInfors[11]); Point UpperLocation = new Point(upperX, upperY); int lowerX = Convert.ToInt32(SpliterInfors[12]); int lowerY = Convert.ToInt32(SpliterInfors[13]); Point LowerLocation = new Point(lowerX, lowerY); sp = new Spliter(id, Location, CurrentFlow, upperFlow, lowerFlow, inpipeline, outpipeline1, outpipeline2, UpperLocation, LowerLocation); return(sp); }
/// <summary> /// Update Pipelines of Comps depending type of com /// </summary> /// <param name="c"></param> private void UpdatePipelinesOfComps(Component c) { if (c is Pump) { Pump p = (Pump)c; if (p.getOutPipeLine() != null) { PipeLine outPipeLine = GetPipeline(p.getOutPipeLine().getId()); p.addOutPipeLine(outPipeLine); } else { p.addOutPipeLine(null); } } if (c is Spliter || c is AdjustableSpliter) { Spliter sp = null; sp = (Spliter)c; if (c is AdjustableSpliter) { sp = (AdjustableSpliter)c; } if (sp.getInPipeLine() != null) { PipeLine inPipeLine = GetPipeline(sp.getInPipeLine().getId()); sp.addInPipeLine(inPipeLine); } else { sp.addInPipeLine(null); } if (sp.getOutPipeLine1() != null) { PipeLine outPipeLine1 = GetPipeline(sp.getOutPipeLine1().getId()); sp.addOutPipeLine1(outPipeLine1); } else { sp.addOutPipeLine1(null); } if (sp.getOutPipeLine2() != null) { PipeLine outPipeLine2 = GetPipeline(sp.getOutPipeLine2().getId()); sp.addOutPipeLine2(outPipeLine2); } else { sp.addOutPipeLine2(null); } } if (c is Merger) { Merger mg = (Merger)c; if (mg.getOutPipeLine() != null) { PipeLine outPipeline = GetPipeline(mg.getOutPipeLine().getId()); mg.addOutPipeLine(outPipeline); } else { mg.addOutPipeLine(null); } if (mg.getInPipeLine1() != null) { PipeLine inPipeline1 = GetPipeline(mg.getInPipeLine1().getId()); mg.addInPipeLine1(inPipeline1); } else { mg.addInPipeLine1(null); } if (mg.getInPipeLine2() != null) { PipeLine intPipeline2 = GetPipeline(mg.getInPipeLine2().getId()); mg.addInPipeLine2(intPipeline2); } else { mg.addInPipeLine2(null); } } if (c is Sink) { Sink sk = (Sink)c; if (sk.getInPipeLine() != null) { PipeLine inPipeline = GetPipeline(sk.getInPipeLine().getId()); sk.addInPipeLine(inPipeline); } else { sk.addInPipeLine(null); } } }