public void SetRootComp(CompData comp) { rootcomp = comp; Box_Name.value = comp.name; Box_Category.value = comp.catagory; Box_SimCode_FuncName.value = comp.Code_Sim_FuncName; //Box_AfterSimCode_FuncName.value = comp.Code_AfterSim_FuncName; Box_InternalState_Length.value = comp.internalstate_length.ToString(); Box_ClickType.value = rootcomp.IsClickable ? rootcomp.ClickAction_Type.ToString() : ""; OverlayTextBox.value = rootcomp.OverlayText; ComponentValueInputCount.value = rootcomp.valuebox_length.ToString(); CodeBox_Sim.t.Text = comp.Code_Sim; //CodeBox_AfterSim.t.Text = comp.Code_AfterSim; gridpaint.pixel.Clear(); gridpaint.currot = 0; parameterlabels.Clear(); for (int i = 0; i < rootcomp.valuebox_length; i++) { parameterlabels.Add(rootcomp.parameters[i]); } ComponentValueInputCount.MakeValueChanged(); LoadInputCount(); if (rootcomp.pindesc == null) { rootcomp.GeneratePinDesc(); } LoadPinDesc(); RotButtonPressed(rotbuttons[0]); }
/// <summary> /// Inspects data strips around the specified index and combines them into one strip if the data is the same. /// </summary> /// <param name="_index"></param> private void Meld(int _index, MeldDir _dir) { var index = _index; if (index != 0 && (_dir == MeldDir.Front || _dir == MeldDir.Both)) { //Meld to prior index if possible if (DataBlock[index].Data.Equals(DataBlock[index - 1].Data)) { var newCount = DataBlock[index].count + DataBlock[index - 1].count; DataBlock[index - 1] = new CompData <T>(DataBlock[index].Data, newCount); DataBlock.RemoveAt(index); index--; } } if (index != DataBlock.Count - 1 && (_dir == MeldDir.Back || _dir == MeldDir.Both)) { //Meld to following index if possible if (DataBlock[index].Data.Equals(DataBlock[index + 1].Data)) { var newCount = DataBlock[index].count + DataBlock[index + 1].count; DataBlock[index] = new CompData <T>(DataBlock[index].Data, newCount); DataBlock.RemoveAt(index + 1); } } }
public void SetRootcomp(Component rootcomp) { this.rootcomp = rootcomp; inputs.Clear(); CompData compdata = Sim_Component.Components_Data[rootcomp.dataID]; int parmetercount = compdata.valuebox_length; int maxstringlength = (int)Sim_Component.Components_Data[rootcomp.dataID].parameters.Max(x => UI_Handler.genbutconf.font.MeasureString(x + ": ").X); this.Title = Sim_Component.Components_Data[rootcomp.dataID].name + " Parameters"; this.ui_elements.RemoveRange(1, this.ui_elements.Count - 1); if (parmetercount > 0) { this.Add_UI_Elements(new UI_String(new Pos(bezelsize, headheight + bezelsize), new Point(size.X / 2, (int)(UI_Handler.genbutconf.font.MeasureString("Test").Y)), UI_Handler.genbutconf, Sim_Component.Components_Data[rootcomp.dataID].parameters[0] + ": ")); UI_ValueInput curval = new UI_ValueInput(new Pos(maxstringlength, 0, ORIGIN.DEFAULT, ORIGIN.DEFAULT, this.ui_elements[1]), new Point(size.X / 2, (int)(UI_Handler.genbutconf.font.MeasureString("Test").Y)), UI_Handler.genbutconf, 1, 10); this.Add_UI_Elements(curval); inputs.Add(curval); curval.ValueChanged += input_ValueChanged; curval.value = rootcomp.totalstates[compdata.internalstate_length + compdata.OverlaySeg_length].ToString(); for (int i = 2; i < parmetercount + 1; i++) { this.Add_UI_Elements(new UI_String(new Pos(0, 5, ORIGIN.BL, ORIGIN.DEFAULT, this.ui_elements[i * 2 - 3]), new Point(size.X / 2, (int)(UI_Handler.genbutconf.font.MeasureString("Test").Y)), UI_Handler.genbutconf, Sim_Component.Components_Data[rootcomp.dataID].parameters[i - 1] + ": ")); curval = new UI_ValueInput(new Pos(maxstringlength, 0, ORIGIN.DEFAULT, ORIGIN.DEFAULT, this.ui_elements[i * 2 - 1]), new Point(size.X / 2, (int)(UI_Handler.genbutconf.font.MeasureString("Test").Y)), UI_Handler.genbutconf, 1, 10); this.Add_UI_Elements(curval); inputs.Add(curval); curval.ValueChanged += input_ValueChanged; curval.value = rootcomp.totalstates[compdata.internalstate_length + compdata.OverlaySeg_length + i - 1].ToString(); } this.GetsUpdated = this.GetsDrawn = true; } }
public void input_ValueChanged(object sender) { UI_ValueInput cur = sender as UI_ValueInput; int index = inputs.IndexOf(cur); CompData compdata = Sim_Component.Components_Data[rootcomp.dataID]; rootcomp.totalstates[compdata.internalstate_length + compdata.OverlaySeg_length + index] = int.Parse("0" + cur.value); }
public void DrawCompOverlays(SpriteBatch spritebatch) { if (Simulator.worldzoom > 3) { int topleftchunk_X, topleftchunk_Y; Simulator.Screen2worldcoo_int(Vector2.Zero, out topleftchunk_X, out topleftchunk_Y); int bottomrightchunk_X, bottomrightchunk_Y; Simulator.Screen2worldcoo_int(new Vector2(App.Screenwidth, App.Screenheight), out bottomrightchunk_X, out bottomrightchunk_Y); int offset = 20; topleftchunk_X -= offset; topleftchunk_Y -= offset; bottomrightchunk_X += offset; bottomrightchunk_Y += offset; topleftchunk_X = MathHelper.Clamp(topleftchunk_X / 32, 0, Simulator.SIZEX / 32 - 1); topleftchunk_Y = MathHelper.Clamp(topleftchunk_Y / 32, 0, Simulator.SIZEY / 32 - 1); bottomrightchunk_X = MathHelper.Clamp(bottomrightchunk_X / 32, 0, Simulator.SIZEX / 32 - 1); bottomrightchunk_Y = MathHelper.Clamp(bottomrightchunk_Y / 32, 0, Simulator.SIZEY / 32 - 1); for (int x = topleftchunk_X; x <= bottomrightchunk_X; ++x) { for (int y = topleftchunk_Y; y <= bottomrightchunk_Y; ++y) { if (CompOverlayGrid[x, y] != null) { for (int i = 0; i < CompOverlayGrid[x, y].Count; ++i) { int ID = CompOverlayGrid[x, y][i]; CompData compdata = Components_Data[components[ID].dataID]; if (compdata.OverlayText.Length > 0) { Vector2 size = CompData.overlayfont.MeasureString(compdata.OverlayText); Vector2 pos = new Vector2((components[ID].pos.ToVector2().X + compdata.OverlayTextPos[components[ID].rotation].X + 0.5f) * (float)Math.Pow(2, Simulator.worldzoom) + Simulator.worldpos.X, (components[ID].pos.ToVector2().Y + compdata.OverlayTextPos[components[ID].rotation].Y + 0.5f) * (float)Math.Pow(2, Simulator.worldzoom) + Simulator.worldpos.Y); spritebatch.DrawString(CompData.overlayfont, compdata.OverlayText, pos, Color.Black, 0, size / 2, compdata.OverlayTextSize[components[ID].rotation] * (float)Math.Pow(2, Simulator.worldzoom), SpriteEffects.None, 0); } } } } } //for (int i = 0; i < 2000; ++i) // { // if (components[i] != null) // { // CompData compdata = Components_Data[components[i].dataID]; // if (compdata.OverlayText.Length > 0) // { // Vector2 size = CompData.overlayfont.MeasureString(compdata.OverlayText); // Vector2 pos = new Vector2((components[i].pos.ToVector2().X + compdata.OverlayTextPos[components[i].rotation].X + 0.5f) * (float)Math.Pow(2, Simulator.worldzoom) + Simulator.worldpos.X, (components[i].pos.ToVector2().Y + compdata.OverlayTextPos[components[i].rotation].Y + 0.5f) * (float)Math.Pow(2, Simulator.worldzoom) + Simulator.worldpos.Y); // spritebatch.DrawString(CompData.overlayfont, compdata.OverlayText, pos, Color.Black, 0, size / 2, compdata.OverlayTextSize[components[i].rotation] * (float)Math.Pow(2, Simulator.worldzoom), SpriteEffects.None, 0); // } // } // } } }
public void Draw(SpriteBatch spritebatch) { if (Simulator.IsPinDesc && Simulator.worldzoom > 4) { int topleftchunk_X, topleftchunk_Y; Simulator.Screen2worldcoo_int(Vector2.Zero, out topleftchunk_X, out topleftchunk_Y); int bottomrightchunk_X, bottomrightchunk_Y; Simulator.Screen2worldcoo_int(new Vector2(App.Screenwidth, App.Screenheight), out bottomrightchunk_X, out bottomrightchunk_Y); int offset = 20; topleftchunk_X -= offset; topleftchunk_Y -= offset; bottomrightchunk_X += offset; bottomrightchunk_Y += offset; topleftchunk_X = MathHelper.Clamp(topleftchunk_X / 32, 0, Simulator.SIZEX / 32 - 1); topleftchunk_Y = MathHelper.Clamp(topleftchunk_Y / 32, 0, Simulator.SIZEY / 32 - 1); bottomrightchunk_X = MathHelper.Clamp(bottomrightchunk_X / 32, 0, Simulator.SIZEX / 32 - 1); bottomrightchunk_Y = MathHelper.Clamp(bottomrightchunk_Y / 32, 0, Simulator.SIZEY / 32 - 1); for (int x = topleftchunk_X; x <= bottomrightchunk_X; ++x) { for (int y = topleftchunk_Y; y <= bottomrightchunk_Y; ++y) { if (PinDescGrid[x, y] != null) { for (int i = 0; i < PinDescGrid[x, y].Count; ++i) { int ID = PinDescGrid[x, y][i]; CompData compdata = Components_Data[components[ID].dataID]; for (int j = 0; j < compdata.pindesc.Length; ++j) { if (compdata.pindesc[j] != null) { Vector2 size = CompData.overlayfont.MeasureString(compdata.pindesc[j]); float maxsize = Math.Max(size.X, size.Y); float mul = 1.0f; if (maxsize > 140) { mul = 140.0f / maxsize; } Vector2 pos = new Vector2((components[ID].pos.ToVector2().X + compdata.pindescpos[components[ID].rotation, j].X + 0.5f) * (float)Math.Pow(2, Simulator.worldzoom) + Simulator.worldpos.X, (components[ID].pos.ToVector2().Y + compdata.pindescpos[components[ID].rotation, j].Y + 0.5f) * (float)Math.Pow(2, Simulator.worldzoom) + Simulator.worldpos.Y); spritebatch.DrawString(CompData.overlayfont, compdata.pindesc[j], pos, Color.Red, 0, size / 2, 0.0036f * mul * (float)Math.Pow(2, Simulator.worldzoom), SpriteEffects.None, 0); } } //if (compdata.OverlayText.Length > 0) //{ // Vector2 size = CompData.overlayfont.MeasureString(compdata.OverlayText); // Vector2 pos = new Vector2((components[ID].pos.ToVector2().X + compdata.OverlayTextPos[components[ID].rotation].X + 0.5f) * (float)Math.Pow(2, Simulator.worldzoom) + Simulator.worldpos.X, (components[ID].pos.ToVector2().Y + compdata.OverlayTextPos[components[ID].rotation].Y + 0.5f) * (float)Math.Pow(2, Simulator.worldzoom) + Simulator.worldpos.Y); // spritebatch.DrawString(CompData.overlayfont, compdata.OverlayText, pos, Color.Black, 0, size / 2, compdata.OverlayTextSize[components[ID].rotation] * (float)Math.Pow(2, Simulator.worldzoom), SpriteEffects.None, 0); //} } } } } } }
public void EditCompWindow(object sender) { UI_Component comp = sender as UI_Component; UI_Handler.editcompwindow.GetsUpdated = UI_Handler.editcompwindow.GetsDrawn = true; UI_Window.All_Highlight(UI_Handler.editcompwindow); string[] names = comp.ID_Name.Split('|'); CompData compdata = CompLibrary.LibraryWindow_LoadedLibraries.Find(x => x.name == names[0]).Components.Find(x => x.name == names[1]); UI_Handler.editcompwindow.SetRootComp(compdata); }
public void RenameComp_Finish(object sender) { string[] names = UI_Handler.EditComp.ID_Name.Split('|'); CompData comp = CompLibrary.LibraryWindow_LoadedLibraries.Find(x => x.name == names[0]).Components.Find(x => x.name == names[1]); if (RenameBox2.value.Length > 0) { comp.name = RenameBox2.value; } RenameBox2.GetsUpdated = RenameBox2.GetsDrawn = false; Reload_UI(); }
protected override void SolveInstance(IGH_DataAccess DA) { string input = null; if (!DA.GetData(0, ref input)) { return; } var splitInput = input.Split('-').ToList(); DA.SetDataList(0, CompData.GetComponents(splitInput[0].Trim())); }
protected override void DrawSpecific(SpriteBatch spritebatch) { spritebatch.End(); effect.Parameters["logictex"].SetValue(logictex); Matrix matrix = Matrix.Identity; if (App.Render_PreviousMatrix_Index > 0) { matrix = App.Render_PreviousMatrix[App.Render_PreviousMatrix_Index - 1]; } spritebatch.Begin(SpriteSortMode.Deferred, null, null, null, null, effect, matrix); spritebatch.Draw(tex, pos.pos.ToVector2(), Color.White); spritebatch.End(); spritebatch.GraphicsDevice.ScissorRectangle = new Rectangle(absolutpos - parent.absolutpos, size); spritebatch.Begin(SpriteSortMode.Deferred, null, null, null, _rasterizerState, null, matrix); int pincount = 0, ledsegmentcount = 0; if (zoom > 3) { for (int i = 0; i < pixel.Count; ++i) { if (pixel[i].type > Sim_Component.PINOFFSET) { spritebatch.DrawString(conf.font, (pixel[i].type - (Sim_Component.PINOFFSET + 1)).ToString(), absolutpos.ToVector2() + new Vector2((pixel[i].pos.X + Origin.X) * (float)Math.Pow(2, zoom) + worldpos.X + pinpositions[pincount].X, (pixel[i].pos.Y + Origin.Y) * (float)Math.Pow(2, zoom) + worldpos.Y + pinpositions[pincount].Y), Color.Red); pincount++; } else if (pixel[i].type == 4) { spritebatch.DrawString(conf.font, ledsegment_IDs[pixel[i].pos.X + Origin.X, pixel[i].pos.Y + Origin.Y].ToString(), absolutpos.ToVector2() + new Vector2((pixel[i].pos.X + Origin.X) * (float)Math.Pow(2, zoom) + worldpos.X + ledsegmentpositions[ledsegmentcount].X, (pixel[i].pos.Y + Origin.Y) * (float)Math.Pow(2, zoom) + worldpos.Y + ledsegmentpositions[ledsegmentcount].Y), Color.Red); ledsegmentcount++; } } } if (UI_EditComp_Window.rootcomp.OverlayText.Length > 0) { CompData compdata = UI_EditComp_Window.rootcomp; Vector2 size = CompData.overlayfont.MeasureString(compdata.OverlayText); Vector2 pos = absolutpos.ToVector2() + new Vector2((compdata.OverlayTextPos[currot].X + Origin.X + 0.5f) * (float)Math.Pow(2, zoom) + worldpos.X, (compdata.OverlayTextPos[currot].Y + Origin.Y + 0.5f) * (float)Math.Pow(2, zoom) + worldpos.Y); spritebatch.DrawString(CompData.overlayfont, compdata.OverlayText, pos, Color.Black, 0, size / 2, compdata.OverlayTextSize[currot] * (float)Math.Pow(2, zoom), SpriteEffects.None, 0); if (UI_EditComp_Window.IsInOverlayMode) { spritebatch.DrawHollowRectangle(new Rectangle((pos - (size * compdata.OverlayTextSize[currot] * (float)Math.Pow(2, zoom)) / 2).ToPoint(), (size * compdata.OverlayTextSize[currot] * (float)Math.Pow(2, zoom)).ToPoint()), Color.Blue, 2); } } spritebatch.End(); spritebatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, matrix); base.DrawSpecific(spritebatch); }
public void AddComp(object sender) { UI_StringButton pressedElement = sender as UI_StringButton; string startname = "New Component"; string finalname = ""; for (int y = 1; ; y++) { bool DoesExist = false; for (int i = 0; i < CompLibrary.LibraryWindow_LoadedLibraries.Count; ++i) { bool state = CompLibrary.LibraryWindow_LoadedLibraries[i].Components.Exists(x => x.name == startname + y.ToString()); if (state) { DoesExist = true; } } if (!DoesExist) { finalname = startname + y.ToString(); break; } } CompLibrary curlib = CompLibrary.LibraryWindow_LoadedLibraries.Find(x => x.name == pressedElement.parent.ID_Name); CompData newComp = new CompData(finalname, "Other", false, false); curlib.AddComponent(newComp); Reload_UI(); Libraries.ui_elements.ForEach(x => { if (x.pos.parent == Libraries) { x.pos.Y -= 1000000; } }); Libraries.UpdatePos(); Libraries.UpdateSpecific(); UpdatePos(); UI_Component curUIcomp; int libindex_UI = Libraries.ui_elements[0].ui_elements.FindIndex(x => x.cat.ID_Name == pressedElement.parent.ID_Name); curUIcomp = Libraries.ui_elements[0].ui_elements[libindex_UI].Components.ui_elements.Last(); RenameBox2.pos = new Pos(Libraries.pos.X, (curUIcomp.absolutpos.Y - this.pos.Y), ORIGIN.DEFAULT, ORIGIN.DEFAULT, this); RenameBox2.size = curUIcomp.size; RenameBox2.value = finalname; RenameBox2.ID_Name = finalname; RenameBox2.GetsUpdated = RenameBox2.GetsDrawn = true; RenameBox2.Set2Typing(); UI_Handler.EditComp.ID_Name = curlib.name + "|" + finalname; }
private void buttonGetComps_Click(object sender, EventArgs e) { List<CompData> comps = new List<CompData>(); foreach (var item in _users) { CompData comp = new CompData(item); comps.Add(comp); } SearchComp(comps, "main.picompany.ru"); SearchComp(comps, "dsk2.picompany.ru"); saveCompsToTxt(comps); MessageBox.Show("Готово"); }
public Component(int dataID, int ID) { this.dataID = dataID; this.ID = ID; CompData compdata = Sim_Component.Components_Data[dataID]; if (compdata.IsOverlay) { Sim_Component.CompMayneedoverlay.Add(ID); } if (compdata.totalstate_length > 0) { totalstates = new int[compdata.totalstate_length]; } pinNetworkIDs = new int[compdata.pin_num]; }
public static void GenerateSimulationData() { InitSimulation(Sim_Component.Components_Data.Count); int count = 1; line_num = 0; for (int i = 0; i <= Simulator.highestNetworkID; ++i) { if (Simulator.networks[i] != null) { WireMap[i] = count; WireMapInv[count] = i; WireStates_IN[count] = WireStates_OUT[count] = Simulator.networks[i].state; count++; line_num += Simulator.networks[i].lines.Count; } } WireStates_count = count; int compcount = 0, infocount = 0; for (int i = 0; i < Sim_Component.nextComponentID; ++i) { if (Sim_Component.components[i] != null) { Component curcomp = Sim_Component.components[i]; CompID[compcount++] = infocount; CompInfos[infocount++] = curcomp.dataID; CompData compdata = Sim_Component.Components_Data[curcomp.dataID]; for (int j = 0; j < compdata.pin_num; ++j) { CompInfos[infocount++] = WireMap[curcomp.pinNetworkIDs[j]] - 1; } if (compdata.totalstate_length > 0) { IntStatesMap[i] = infocount; for (int j = 0; j < compdata.totalstate_length; ++j) { CompInfos[infocount++] = curcomp.totalstates[j]; } } } } comp_num = compcount; }
public WeaponComponent(Session session, MyCubeBlock myCube, MyStringHash subtype) { Session = session; MyCube = myCube; Slim = myCube.SlimBlock; SubtypeHash = subtype; MaxIntegrity = Slim.MaxIntegrity; var turret = MyCube as IMyLargeTurretBase; if (turret != null) { TurretBase = turret; TurretBase.EnableIdleRotation = false; BaseType = BlockType.Turret; } else if (MyCube is IMyConveyorSorter) { BaseType = BlockType.Sorter; } else { BaseType = BlockType.Fixed; } TerminalBlock = myCube as IMyTerminalBlock; FunctionalBlock = myCube as IMyFunctionalBlock; BlockInventory = (MyInventory)MyCube.GetInventoryBase(); SinkPower = IdlePower; Platform = session.PlatFormPool.Get(); Platform.Setup(this); Monitors = new List <Action <long, int, ulong, long, Vector3D, bool> > [Platform.Weapons.Length]; for (int i = 0; i < Monitors.Length; i++) { Monitors[i] = new List <Action <long, int, ulong, long, Vector3D, bool> >(); } Data = new CompData(this); MyCube.OnClose += Session.CloseComps; }
public void Refresh() { CompData compData = this.compChart.Controller.CompData; ChartType chartType = compData.ChartType; if (chartType == ChartType.KLine) { IStrategyDrawer drawer = drawOperator.GetDrawer_KLine(compData.KlinePeriod); drawer.Refresh(); } else if (chartType == ChartType.TimeLine) { drawOperator.GetDrawer_TimeLine().Refresh(); } else if (chartType == ChartType.Tick) { drawOperator.GetDrawer_Tick().Refresh(); } }
public ComputersSL(GameObject prop) { cd = prop.GetComponent<Computers>().cd; }
protected override void SolveInstance(IGH_DataAccess DA) { string input = null; if (!DA.GetData(0, ref input)) { return; } var RSP = 0; if (!DA.GetData(1, ref RSP)) { return; } var splitInput = input.Split('-').ToList(); var results = CompData.GetWindow(splitInput[0].Trim()); var RSL = int.Parse(splitInput.Last()); var gValue = 0d; var uValue = 0d; decimal repNum = 0; decimal tmp = ((decimal)RSP / (decimal)RSL) - 1; if (RSL != 0 && RSP != 0) { repNum = Math.Ceiling(tmp); } if (repNum < 0) { repNum = 0; } if (repNum == 0) { repNum = 0; } var sumResults = from row in results group row by row.SortCode.Trim() into rowSum select new { SortCodeGrp = rowSum.Key, UBP13EmbodiedSum = rowSum.Sum(x => x.UBP13Embodied), UBP13RepSum = rowSum.Sum(x => (x.UBP13Embodied + x.UBP13EoL) * repNum), UBP13EoLSum = rowSum.Sum(x => x.UBP13EoL), TotalEmbodiedSum = rowSum.Sum(x => x.TotalEmbodied), TotalRepSum = rowSum.Sum(x => (x.TotalEmbodied + x.TotalEoL) * repNum), TotalEoLSum = rowSum.Sum(x => x.TotalEoL), RenewableEmbodiedSum = rowSum.Sum(x => x.RenewableEmbodied), RenewableRepSum = rowSum.Sum(x => (x.RenewableEmbodied + x.RenewableEoL) * repNum), RenewableEoLSum = rowSum.Sum(x => x.RenewableEoL), NonRenewableEmbodiedSum = rowSum.Sum(x => x.NonRenewableEmbodied), NonRenewableRepSum = rowSum.Sum(x => (x.NonRenewableEmbodied + x.NonRenewableEoL) * repNum), NonRenewableEoLSum = rowSum.Sum(x => x.NonRenewableEoL), GHGEmbodiedSum = rowSum.Sum(x => x.GHGEmbodied), GHGRepSum = rowSum.Sum(x => (x.GHGEmbodied + x.GHGEoL) * repNum), GHGEoLEoLSum = rowSum.Sum(x => x.GHGEoL) }; var result = new List <double>(); foreach (var item in results) { uValue = (double)item.Uvalue; gValue = (double)item.Gvalue; } foreach (var item in sumResults) { result.Add(1); result.Add((double)item.UBP13EmbodiedSum); //UBP13Embodied 1 result.Add((double)item.UBP13RepSum); //UBP13Rep 2 result.Add((double)item.UBP13EoLSum); //UBP13EoL 3 result.Add((double)item.TotalEmbodiedSum); //TotalEmbodied 4 result.Add((double)item.TotalRepSum); //TotalRep 5 result.Add((double)item.TotalEoLSum); //TotalEoL 6 result.Add((double)item.RenewableEmbodiedSum); //RenewableEmbodied 7 result.Add((double)item.RenewableRepSum); //RenewableRep 8 result.Add((double)item.RenewableEoLSum); //RenewableRep 9 result.Add((double)item.NonRenewableEmbodiedSum); //NonRenewableEmbodied 10 result.Add((double)item.NonRenewableRepSum); //NonRenewableRep 11 result.Add((double)item.NonRenewableEoLSum); //NonRenewableEoL 12 result.Add((double)item.GHGEmbodiedSum); //GHGEmbodied 13 result.Add((double)item.GHGRepSum); //GHGRep 14 result.Add((double)item.GHGEoLEoLSum); //GHGEoL 15 result.Add(uValue); result.Add(gValue); } DA.SetData(1, result[16]); DA.SetData(2, result[17]); if (result.Any()) { result.RemoveAt(result.Count - 1); } DA.SetDataList(0, result); }
public void DrawLineOverlays(SpriteBatch spritebatch) { int count = 0; for (int i = 0; i < CompMayneedoverlay.Count; ++i) { int compID = CompMayneedoverlay[i]; CompData compdata = Components_Data[components[compID].dataID]; int ovstateID = compdata.internalstate_length; for (int k = 0; k < compdata.OverlaySeg_length; ++k) { int ovstate = Sim_INF_DLL.CompInfos[Sim_INF_DLL.IntStatesMap[compID] + ovstateID + k];// components[compID].internalstates[ovstateID + k]; if (Simulator.cursimframe == 0) { ovstate = 0; } Component comp = components[compID]; List <VertexPositionLine> CompOverlaylines = Components_Data[comp.dataID].overlaylines_vertices[k][comp.rotation]; for (int j = 0; j < CompOverlaylines.Count; ++j) { overlaylines[count] = CompOverlaylines[j]; overlaylines[count].layers = 4 - ovstate; overlaylines[count].Position += new Vector3(components[compID].pos.X, components[compID].pos.Y, 0); count++; } } } if (count > 0) { App.graphics.GraphicsDevice.SetRenderTarget(Comp_target); overlay_effect.Parameters["WorldViewProjection"].SetValue(Simulator.linedrawingmatrix); overlay_effect.CurrentTechnique.Passes[0].Apply(); App.graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, overlaylines, 0, count / 2); App.graphics.GraphicsDevice.SetRenderTarget(null); } bool IsInGrid = Simulator.mo_worldposx > 0 && Simulator.mo_worldposy > 0 && Simulator.mo_worldposx < Simulator.SIZEX - 1 && Simulator.mo_worldposy < Simulator.SIZEY - 1; if (IsInGrid && !Simulator.IsAllHighlight) { int netID = Simulator.WireIDs[Simulator.mo_worldposx / 2, Simulator.mo_worldposy / 2, Simulator.currentlayer]; if (netID > 0 && (Simulator.IsWire[Simulator.mo_worldposx, Simulator.mo_worldposy] & (1 << Simulator.currentlayer)) > 0) { if (curhighlightID != netID) { Network netw = Simulator.networks[netID]; App.graphics.GraphicsDevice.SetRenderTarget(Highlight_target); if (highlight_vertices != null) { highlight_effect.Parameters["highlightvalue"].SetValue(0.0f); highlight_effect.CurrentTechnique.Passes[0].Apply(); App.graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, highlight_vertices, 0, highlight_vertices.Length / 2); } highlight_vertices = new VertexPositionLine[netw.lines.Count * 2]; int count2 = 0; for (int i = 0; i < netw.lines.Count; ++i) { VertexPositionLine l1, l2; Line line = new Line(netw.lines[i].start, netw.lines[i].end); line.Convert2LineVertices(1.0f, out l1, out l2); highlight_vertices[count2++] = l1; highlight_vertices[count2++] = l2; } //App.graphics.GraphicsDevice.Clear(Color.Transparent); highlight_effect.Parameters["highlightvalue"].SetValue(1.0f); highlight_effect.Parameters["WorldViewProjection"].SetValue(Simulator.linedrawingmatrix); highlight_effect.CurrentTechnique.Passes[0].Apply(); App.graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, highlight_vertices, 0, highlight_vertices.Length / 2); App.graphics.GraphicsDevice.SetRenderTarget(null); //System.Threading.Thread.Sleep(100); spritebatch.Begin(); spritebatch.Draw(Simulator.main_target, Vector2.Zero, Color.White); spritebatch.End(); } curhighlightID = netID; } else { if (curhighlightID != 0) { ClearAllHeighlighting(); } curhighlightID = 0; } } }
/// <summary> /// Get parameter data from the base design. /// </summary> /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param> bool GetBaseVariants() { try { IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace; IDXPProject CurrentProject; int LogicalDocumentCount; int LoopIterator; IDXPDocument CurrentSheet; CurrentProject = CurrentWorkspace.DM_FocusedProject(); LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount(); ISch_ServerInterface SchServer = SCH.GlobalVars.SchServer; IClient Client = DXP.GlobalVars.Client; IServerDocument ServerDoc; IDXPDocument ActiveDoc = DXP.GlobalVars.DXPWorkSpace.DM_FocusedDocument(); //Save current open document so it can be reopened after process is done. string RefDes; CompData NewComp; bool DocOpened = false; //iterate through project documents. for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) { CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); //Check for schematic documents. if (CurrentSheet.DM_DocumentKind() == "SCH") { DocOpened = false; //Open documents if (Client.IsDocumentOpen(CurrentSheet.DM_FullPath())) { ServerDoc = Client.GetDocumentByPath(CurrentSheet.DM_FullPath()); DocOpened = true; } else { ServerDoc = Client.OpenDocument("SCH", CurrentSheet.DM_FullPath()); } //Client.ShowDocument(ServerDoc); ISch_Lib SchDoc; SchDoc = SchServer.LoadSchDocumentByPath(CurrentSheet.DM_FullPath()) as ISch_Lib; ISch_Iterator LibraryIterator, PIterator; ISch_Component Component; ISch_Parameter Param; if (SchDoc == null) { return(false); } //Iterate theough all components on the schematic. LibraryIterator = SchDoc.SchIterator_Create(); LibraryIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent)); Component = LibraryIterator.FirstSchObject() as ISch_Component; while (Component != null) { NewComp = new CompData(""); if (Component.GetState_SchDesignator().GetState_Text().Contains("?")) { MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again."); return(false); } RefDes = Component.GetState_SchDesignator().GetState_Text(); NewComp.RefDes = RefDes; NewComp.Base_LibRef = Component.GetState_DesignItemId(); NewComp.UniqueID = Component.GetState_UniqueId(); //Iterate theough all parameters in the component. PIterator = Component.SchIterator_Create(); PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eParameter)); Param = PIterator.FirstSchObject() as ISch_Parameter; while (Param != null) { if (Param.GetState_Name() != null) { //Store specific parameter data. if ("PARTNUMBER" == Param.GetState_Name().ToUpper()) { NewComp.Base_Partnumber = Param.GetState_CalculatedValueString(); } } Param = PIterator.NextSchObject() as ISch_Parameter; } AddPart(NewComp); Component = LibraryIterator.NextSchObject() as ISch_Component; } //if (ServerDoc.GetModified()) // ServerDoc.DoFileSave(""); //Close opend documents. if (!DocOpened) { Client.CloseDocument(ServerDoc); } ServerDoc = null; } } Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); return(true); } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return(false); } }
/// <summary> /// Get parameter data from an existing variant. /// </summary> /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param> bool Get_Variants(string VariantName) { try { IProject project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject; IProjectVariant Variant; IComponentVariation CompVariant; IParameterVariation ParamVariant; CompData NewComp; //VarParam<string, string> Parameters = new VarParam<string, string>(); string RefDes; int l = 0; for (int i = 0; i < project.DM_ProjectVariantCount(); i++) { l++; Variant = project.DM_ProjectVariants(i); //Find the variant that matches the one provided. if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == VariantName) { for (int j = 0; j < Variant.DM_VariationCount(); j++) { NewComp = new CompData(""); CompVariant = Variant.DM_Variations(j); RefDes = CompVariant.DM_PhysicalDesignator(); NewComp.RefDes = RefDes; NewComp.Base_Partnumber = RefCompList[RefDes].Base_Partnumber; if (CompVariant.DM_VariationKind() == TVariationKind.eVariation_Alternate) { if (VariantName.ToUpper() == "VAR_ENG") { NewComp.Var_Eng_LibRef = CompVariant.DM_AlternateLibraryLink().DM_DesignItemID(); } else if (VariantName.ToUpper() == "VAR_FLT") { NewComp.Var_Flt_LibRef = CompVariant.DM_AlternateLibraryLink().DM_DesignItemID(); } } //checking to make sure all components have a refdes assigned. if (RefDes.Contains("?")) { MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again."); return(false); } //Iterate through all parameters for current component variant. for (int k = 0; k < CompVariant.DM_VariationCount(); k++) { if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted) { ParamVariant = CompVariant.DM_Variations(k); if (VariantName.ToUpper() != "VAR_PE") { //Get values of matching parameters. if ("PARTNUMBER" == ParamVariant.DM_ParameterName().ToUpper()) { if (VariantName.ToUpper() == "VAR_ENG") { NewComp.Var_Eng_Partnumber = ParamVariant.DM_VariedValue(); } else if (VariantName.ToUpper() == "VAR_FLT") { NewComp.Var_Flt_Partnumber = ParamVariant.DM_VariedValue(); } } } else { if ("PE_FLT" == ParamVariant.DM_ParameterName().ToUpper()) { NewComp.PE_FLT_Partnumber = (ParamVariant.DM_VariedValue() == null) ? ParamVariant.DM_VariedValue() : ""; } else if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper()) { NewComp.PE_ENG_Partnumber = (ParamVariant.DM_VariedValue() == null) ? ParamVariant.DM_VariedValue() : ""; } } } } AddPart(NewComp); l++; } } } return(true); } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return(false); } }
void AddPart(CompData Component) { RefCompList.Add(Component.RefDes, Component); PartnumberCompList.Add(Component.Base_Partnumber, Component); ///add to each dictionary }
public override void UpdateSpecific() { if (new Rectangle(pos.pos, size).Contains(App.mo_states.New.Position) && !DenyInteraction && !(UI_Handler.IsInScrollable && !UI_Handler.IsInScrollable_Bounds.Contains(App.mo_states.New.Position))) { #region Position and Zoom if (App.kb_states.New.IsKeyDown(Keys.W)) { worldpos.Y += 10; } if (App.kb_states.New.IsKeyDown(Keys.S)) { worldpos.Y -= 10; } if (App.kb_states.New.IsKeyDown(Keys.A)) { worldpos.X += 10; } if (App.kb_states.New.IsKeyDown(Keys.D)) { worldpos.X -= 10; } worldpos.X = (int)(worldpos.X); worldpos.Y = (int)(worldpos.Y); if (App.mo_states.New.ScrollWheelValue != App.mo_states.Old.ScrollWheelValue) { if (App.mo_states.New.ScrollWheelValue < App.mo_states.Old.ScrollWheelValue && zoom > minmaxzoom.X) // Zooming Out { zoom -= 1; Vector2 diff = worldpos - (App.mo_states.New.Position.ToVector2() - pos.pos.ToVector2()); worldpos = (App.mo_states.New.Position.ToVector2() - pos.pos.ToVector2()) + diff / 2; UpdatePinTextPos(); } else if (App.mo_states.New.ScrollWheelValue > App.mo_states.Old.ScrollWheelValue && zoom < minmaxzoom.Y) // Zooming In { zoom += 1; Vector2 diff = worldpos - (App.mo_states.New.Position.ToVector2() - pos.pos.ToVector2()); worldpos += diff; UpdatePinTextPos(); } } int mouse_worldpos_X, mouse_worldpos_Y; Screen2worldcoo_int(App.mo_states.New.Position.ToVector2() - absolutpos.ToVector2(), out mouse_worldpos_X, out mouse_worldpos_Y); if (mouse_worldpos_X >= 0 && mouse_worldpos_X < GridSize && mouse_worldpos_Y >= 0 && mouse_worldpos_Y < GridSize && currot == 0 && !UI_EditComp_Window.IsInOverlayMode) { if (App.mo_states.New.LeftButton == ButtonState.Pressed) { // Place Pixel if (pixel.Exists(x => x.pos.X == mouse_worldpos_X - Origin.X && x.pos.Y == mouse_worldpos_Y - Origin.Y)) { int index = pixel.FindIndex(x => x.pos.X == mouse_worldpos_X - Origin.X && x.pos.Y == mouse_worldpos_Y - Origin.Y); ComponentPixel curtype = pixel[index]; if (MathHelper.Clamp(curtype.type, 0, (Sim_Component.PINOFFSET + 1)) != curplacetype) { int type = curplacetype; if (curtype.type == 4) { int index2 = ledsegmentpixel_pos.FindIndex(x => x.X == (mouse_worldpos_X) && x.Y == (mouse_worldpos_Y)); ledsegmentpixel_pos.RemoveAt(index2); ledsegmentpixel.RemoveAt(index2); } pixel[index] = new ComponentPixel(new Point(mouse_worldpos_X - Origin.X, mouse_worldpos_Y - Origin.Y), (byte)type); if (type == 4) { ledsegmentpixel.Add(0); ledsegmentpixel_pos.Add(new Point(mouse_worldpos_X, mouse_worldpos_Y)); } if (type == 5) { ApplyPixel(true); } else { ApplyPixel(); } } } else { int type = curplacetype; pixel.Add(new ComponentPixel(new Point(mouse_worldpos_X - Origin.X, mouse_worldpos_Y - Origin.Y), (byte)type)); if (type == 4) { ledsegmentpixel.Add(0); ledsegmentpixel_pos.Add(new Point(mouse_worldpos_X, mouse_worldpos_Y)); } if (type == 5) { ApplyPixel(true); } else { ApplyPixel(); } } if (curplacetype == 5) { for (int i = 0; i < 10; ++i) { if (App.kb_states.IsKeyToggleDown(Keys.D0 + i)) { int index = pixel.FindIndex(x => x.pos.X == mouse_worldpos_X - Origin.X && x.pos.Y == mouse_worldpos_Y - Origin.Y); ComponentPixel cur = pixel[index]; if (cur.type > Sim_Component.PINOFFSET) { int val = cur.type - (Sim_Component.PINOFFSET + 1); if (val == 0 && i != 0) { pixel[index] = new ComponentPixel(cur.pos, (byte)MathHelper.Clamp(i + Sim_Component.PINOFFSET + 1, 0, 240)); } else if (val != 0) { pixel[index] = new ComponentPixel(cur.pos, (byte)MathHelper.Clamp(val * 10 + i + Sim_Component.PINOFFSET + 1, 0, 240)); } ApplyPixel(true); } } } if (App.kb_states.IsKeyToggleDown(Keys.Back)) { int index = pixel.FindIndex(x => x.pos.X == mouse_worldpos_X - Origin.X && x.pos.Y == mouse_worldpos_Y - Origin.Y); if (pixel[index].type > Sim_Component.PINOFFSET) { pixel[index] = new ComponentPixel(pixel[index].pos, (byte)((pixel[index].type - (Sim_Component.PINOFFSET + 1)) / 10 + (Sim_Component.PINOFFSET + 1))); ApplyPixel(true); } } else if (App.kb_states.IsKeyToggleDown(Keys.Escape)) { int index = pixel.FindIndex(x => x.pos.X == mouse_worldpos_X - Origin.X && x.pos.Y == mouse_worldpos_Y - Origin.Y); if (pixel[index].type > Sim_Component.PINOFFSET) { pixel[index] = new ComponentPixel(pixel[index].pos, (byte)(Sim_Component.PINOFFSET + 1)); ApplyPixel(true); } } } if (curplacetype == 4) { for (int i = 0; i < 10; ++i) { if (App.kb_states.IsKeyToggleDown(Keys.D0 + i)) { int index = pixel.FindIndex(x => x.pos.X == mouse_worldpos_X - Origin.X && x.pos.Y == mouse_worldpos_Y - Origin.Y); ComponentPixel cur = pixel[index]; if (cur.type == 4) { int val = ledsegment_IDs[mouse_worldpos_X, mouse_worldpos_Y];// cur.type - (Sim_Component.PINOFFSET + 1); int index2 = ledsegmentpixel_pos.FindIndex(x => x.X == mouse_worldpos_X && x.Y == mouse_worldpos_Y); ledsegmentpixel[index2] = (byte)MathHelper.Clamp(val * 10 + i, 0, 240); //ledsegment_IDs[mouse_worldpos_X, mouse_worldpos_Y] = (byte)(val * 10 + i); //if (val == 0 && i != 0) // pixel[index] = new ComponentPixel(cur.pos, (byte)i); //else if (val != 0) // pixel[index] = new ComponentPixel(cur.pos, (byte)(val * 10 + i)); ApplyPixel(); } } } if (App.kb_states.IsKeyToggleDown(Keys.Back)) { int index = pixel.FindIndex(x => x.pos.X == mouse_worldpos_X - Origin.X && x.pos.Y == mouse_worldpos_Y - Origin.Y); if (pixel[index].type == 4) { int index2 = ledsegmentpixel_pos.FindIndex(x => x.X == mouse_worldpos_X && x.Y == mouse_worldpos_Y); ledsegmentpixel[index2] /= 10; ApplyPixel(); } } else if (App.kb_states.IsKeyToggleDown(Keys.Escape)) { int index = pixel.FindIndex(x => x.pos.X == mouse_worldpos_X - Origin.X && x.pos.Y == mouse_worldpos_Y - Origin.Y); if (pixel[index].type == 4) { int index2 = ledsegmentpixel_pos.FindIndex(x => x.X == mouse_worldpos_X && x.Y == mouse_worldpos_Y); ledsegmentpixel[index2] = 0; ApplyPixel(); } } } } if (App.mo_states.New.RightButton == ButtonState.Pressed) { int index = pixel.FindIndex(x => x.pos.X == (mouse_worldpos_X - Origin.X) && x.pos.Y == (mouse_worldpos_Y - Origin.Y)); int curtype = -1; if (index >= 0) { curtype = pixel[index].type; } if (index >= 0) { pixel.RemoveAt(index); } index = ledsegmentpixel_pos.FindIndex(x => x.X == (mouse_worldpos_X) && x.Y == (mouse_worldpos_Y)); if (index >= 0) { ledsegmentpixel_pos.RemoveAt(index); ledsegmentpixel.RemoveAt(index); } if (curtype >= 5) { ApplyPixel(true); } else { ApplyPixel(); } } } else if (UI_EditComp_Window.IsInOverlayMode) { CompData compdata = UI_EditComp_Window.rootcomp; Vector2 size = CompData.overlayfont.MeasureString(compdata.OverlayText) * compdata.OverlayTextSize[currot] * (float)Math.Pow(2, zoom); Vector2 pos = absolutpos.ToVector2() + new Vector2((compdata.OverlayTextPos[currot].X + Origin.X + 0.5f) * (float)Math.Pow(2, zoom) + worldpos.X, (compdata.OverlayTextPos[currot].Y + Origin.Y + 0.5f) * (float)Math.Pow(2, zoom) + worldpos.Y) - size / 2; if (App.mo_states.New.LeftButton == ButtonState.Pressed && App.kb_states.New.IsKeyDown(Keys.LeftControl)) { compdata.OverlayTextSize[currot] += (((float)(App.mo_states.New.Position.Y - App.mo_states.Old.Position.Y)) / (float)Math.Pow(2, zoom)) * 0.01f; } else if ((new Rectangle(pos.ToPoint(), size.ToPoint())).Contains(App.mo_states.New.Position) && App.mo_states.New.LeftButton == ButtonState.Pressed) { compdata.OverlayTextPos[currot] += (App.mo_states.New.Position - App.mo_states.Old.Position).ToVector2() / (float)Math.Pow(2, zoom); } } #endregion effect.Parameters["mousepos_X"].SetValue(mouse_worldpos_X); effect.Parameters["mousepos_Y"].SetValue(mouse_worldpos_Y); } effect.Parameters["zoom"].SetValue((float)Math.Pow(2, zoom)); effect.Parameters["coos"].SetValue(worldpos); base.UpdateSpecific(); }
protected override void SolveInstance(IGH_DataAccess DA) { string input = null; if (!DA.GetData(0, ref input)) { return; } var RSP = 0; if (!DA.GetData(1, ref RSP)) { return; } var splitInput = input.Split('-').ToList(); var resultsDB = CompData.GetGenComponent(splitInput[0].Trim(), null, true); var RSL = int.Parse(splitInput.Last()); decimal repNum = 0; decimal tmp = ((decimal)RSP / (decimal)RSL) - 1; if (RSL != 0 && RSP != 0) { repNum = Math.Ceiling(tmp); } if (repNum < 0) { repNum = 0; } if (repNum == 0) { repNum = 0; } var sumResults = from row in resultsDB group row by row.SortCode.Trim() into rowSum select new { SortCodeGrp = rowSum.Key, UBP13EmbodiedSum = rowSum.Sum(x => x.UBP13Embodied), UBP13RepSum = rowSum.Sum(x => (x.UBP13Embodied + x.UBP13EoL) * repNum), UBP13EoLSum = rowSum.Sum(x => x.UBP13EoL), TotalEmbodiedSum = rowSum.Sum(x => x.TotalEmbodied), TotalRepSum = rowSum.Sum(x => (x.TotalEmbodied + x.TotalEoL) * repNum), TotalEoLSum = rowSum.Sum(x => x.TotalEoL), RenewableEmbodiedSum = rowSum.Sum(x => x.RenewableEmbodied), RenewableRepSum = rowSum.Sum(x => (x.RenewableEmbodied + x.RenewableEoL) * repNum), RenewableEoLSum = rowSum.Sum(x => x.RenewableEoL), NonRenewableEmbodiedSum = rowSum.Sum(x => x.NonRenewableEmbodied), NonRenewableRepSum = rowSum.Sum(x => (x.NonRenewableEmbodied + x.NonRenewableEoL) * repNum), NonRenewableEoLSum = rowSum.Sum(x => x.NonRenewableEoL), GHGEmbodiedSum = rowSum.Sum(x => x.GHGEmbodied), GHGRepSum = rowSum.Sum(x => (x.GHGEmbodied + x.GHGEoL) * repNum), GHGEoLEoLSum = rowSum.Sum(x => x.GHGEoL), ResistanceSum = rowSum.Sum(x => x.Resistance) }; var results = new Dictionary <string, double> { { "UBP13 Embodied (P/m\xB2 a)", 0 }, { "UBP13 Replacements (P/m\xB2 a)", 0 }, { "UBP13 End of Life (P/m\xB2 a)", 0 }, { "Total Embodied (kWh oil-eq)", 0 }, { "Total Replacements (kWh oil-eq)", 0 }, { "Total End of Life (kWh oil-eq)", 0 }, { "Renewable Embodied (kWh oil-eq)", 0 }, { "Renewable Replacements (kWh oil-eq)", 0 }, { "Renewable End of Life (kWh oil-eq)", 0 }, { "Non Renewable Embodied (kWh oil-eq)", 0 }, { "Non Renewable Replacements (kWh oil-eq)", 0 }, { "Non Renewable End of Life (kWh oil-eq)", 0 }, { "Green House Gasses Embodied (kg CO\x2082-eq/m\xB2 a)", 0 }, { "Green House Gasses Replacements (kg CO\x2082-eq/m\xB2 a)", 0 }, { "Green House Gasses End of Life (kg CO\x2082-eq/m\xB2 a)", 0 }, { "R value", 0 } }; foreach (var item in sumResults) { results["UBP13 Embodied (P/m\xB2 a)"] += (double)item.UBP13EmbodiedSum; results["UBP13 Replacements (P/m\xB2 a)"] += (double)item.UBP13RepSum; results["UBP13 End of Life (P/m\xB2 a)"] += (double)item.UBP13EoLSum; results["Total Embodied (kWh oil-eq)"] += (double)item.TotalEmbodiedSum; results["Total Replacements (kWh oil-eq)"] += (double)item.TotalRepSum; results["Total End of Life (kWh oil-eq)"] += (double)item.TotalEoLSum; results["Renewable Embodied (kWh oil-eq)"] += (double)item.RenewableEmbodiedSum; results["Renewable Replacements (kWh oil-eq)"] += (double)item.RenewableRepSum; results["Renewable End of Life (kWh oil-eq)"] += (double)item.RenewableEoLSum; results["Non Renewable Embodied (kWh oil-eq)"] += (double)item.NonRenewableEmbodiedSum; results["Non Renewable Replacements (kWh oil-eq)"] += (double)item.NonRenewableRepSum; results["Non Renewable End of Life (kWh oil-eq)"] += (double)item.NonRenewableEoLSum; results["Green House Gasses Embodied (kg CO\x2082-eq/m\xB2 a)"] += (double)item.GHGEmbodiedSum; results["Green House Gasses Replacements (kg CO\x2082-eq/m\xB2 a)"] += (double)item.GHGRepSum; results["Green House Gasses End of Life (kg CO\x2082-eq/m\xB2 a)"] += (double)item.GHGEoLEoLSum; results["R value"] += (double)item.ResistanceSum; } var resultValues = results.Values.ToList(); DA.SetDataList(0, results); DA.SetDataList(1, resultValues); }
public static void OpenFromPath(string filename) { if (!Simulator.IsSimulating) { try { FileStream stream = new FileStream(filename, FileMode.Open); byte[] intbuffer = new byte[4]; stream.Read(intbuffer, 0, 4); int XGridSize = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int YGridSize = BitConverter.ToInt32(intbuffer, 0); #region Load Tables and Check for Components stream.Read(intbuffer, 0, 4); int library_count = BitConverter.ToInt32(intbuffer, 0); string workingPath = filename; int pathindex = 0; for (int i = workingPath.Length - 1; i >= 0; --i) { if (workingPath[i] == '\\') { pathindex = i; break; } } workingPath = workingPath.Remove(pathindex + 1, workingPath.Length - (pathindex + 1)); //CompLibrary.AllUsedLibraries.Clear(); //Sim_Component.Components_Data.Clear(); List <string> Libraries2Load = new List <string>(); for (int i = 0; i < library_count; ++i) { string relPath = stream.ReadNullTerminated(); if (relPath[0] == '-') { string pathtoexe = Directory.GetCurrentDirectory(); string pathtolibraries = pathtoexe + "\\LIBRARIES\\"; string finalrelPath = relPath.Remove(0, 1); Libraries2Load.Add(pathtolibraries + finalrelPath); } else { string absolutepath = workingPath + relPath; Libraries2Load.Add(absolutepath); } //CompLibrary newlib = new CompLibrary(null, absolutepath); //newlib.Load(); //CompLibrary.AllUsedLibraries.Add(newlib); } bool AllLibrarysLoaded = Sim_INF_DLL.LoadLibrarys(Libraries2Load.ToArray()); if (!AllLibrarysLoaded) { stream.Close(); stream.Dispose(); return; } stream.Read(intbuffer, 0, 4); int compdata_count = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int compdatatypes_count = BitConverter.ToInt32(intbuffer, 0); string[] compdata_names = new string[compdata_count]; List <int> compdatatypes = new List <int>(); for (int i = 0; i < compdata_count; ++i) { compdata_names[i] = stream.ReadNullTerminated(); } for (int i = 0; i < compdatatypes_count; ++i) { stream.Read(intbuffer, 0, 4); compdatatypes.Add(BitConverter.ToInt32(intbuffer, 0)); } // Check if all Components are loaded bool AllLoaded = true; List <string> NotFoundComponents = new List <string>(); int[] compdata_index = new int[compdata_count]; for (int i = 0; i < compdata_count; ++i) { CompData curcomp = Sim_Component.Components_Data.Find(x => x.name == compdata_names[i]); if (curcomp == null && compdatatypes.Exists(x => x == i)) { AllLoaded = false; NotFoundComponents.Add(compdata_names[i]); } else { int index = Sim_Component.Components_Data.IndexOf(curcomp); compdata_index[i] = index; } } if (!AllLoaded) { string message = "Following Components not loaded: "; for (int i = 0; i < NotFoundComponents.Count; ++i) { message += NotFoundComponents[i] + " "; } throw new Exception(message); } #endregion Simulator.SIZEX = Simulator.ProjectSizeX = XGridSize; Simulator.MAXCOO = Simulator.SIZEX - Simulator.BORDERSIZE; Simulator.SIZEY = Simulator.ProjectSizeY = YGridSize; Simulator.linedrawingmatrix = Matrix.CreateOrthographicOffCenter(0, Simulator.SIZEX + 0.01f, Simulator.SIZEY + 0.01f, 0, 0, 1); Simulator.sim_effect.Parameters["worldsizex"].SetValue(Simulator.SIZEX); Simulator.sim_effect.Parameters["worldsizey"].SetValue(Simulator.SIZEY); Sim_Component.components = new Component[Sim_Component.components.Length]; Simulator.networks = new Network[Simulator.networks.Length]; Simulator.IsWire = new byte[Simulator.SIZEX, Simulator.SIZEY]; Simulator.WireIDs = new int[Simulator.SIZEX / 2, Simulator.SIZEY / 2, Simulator.LAYER_NUM]; Simulator.WireIDPs = new int[Simulator.SIZEX, Simulator.SIZEY]; Simulator.CalcGridData = new byte[Simulator.SIZEX, Simulator.SIZEY]; Simulator.CalcGridStat = new byte[Simulator.SIZEX, Simulator.SIZEY]; Simulator.networks = new Network[10000000]; Simulator.emptyNetworkIDs = new int[10000000]; Sim_Component.CompGrid = new int[Simulator.SIZEX / 32, Simulator.SIZEY / 32][]; Sim_Component.CompOverlayGrid = new List <int> [Simulator.SIZEX / 32, Simulator.SIZEY / 32]; Sim_Component.PinDescGrid = new List <int> [Simulator.SIZEX / 32, Simulator.SIZEY / 32]; Sim_Component.CompNetwork = new byte[Simulator.SIZEX, Simulator.SIZEY]; Sim_Component.components = new Component[10000000]; Sim_Component.pins2check = new Point[20000000]; Sim_Component.overlaylines = new VertexPositionLine[1000000]; Sim_Component.emptyComponentID = new int[10000000]; Sim_Component.CompType = new byte[Simulator.SIZEX, Simulator.SIZEY]; Simulator.emptyNetworkIDs_count = 0; Sim_Component.emptyComponentID_count = 0; Sim_Component.CompMayneedoverlay.Clear(); Sim_Component.pins2check_length = 0; Simulator.cursimframe = 0; Simulator.seclogic_target.Dispose(); Simulator.logic_target.Dispose(); Simulator.WireCalc_target.Dispose(); Sim_Component.Comp_target.Dispose(); Sim_Component.Highlight_target.Dispose(); Sim_Component.IsEdge_target.Dispose(); Simulator.seclogic_target = new RenderTarget2D(App.graphics.GraphicsDevice, Simulator.SIZEX, Simulator.SIZEY, false, SurfaceFormat.HalfSingle, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); Simulator.logic_target = new RenderTarget2D(App.graphics.GraphicsDevice, Simulator.SIZEX, Simulator.SIZEY, false, SurfaceFormat.HalfSingle, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); Simulator.WireCalc_target = new RenderTarget2D(App.graphics.GraphicsDevice, Simulator.SIZEX, Simulator.SIZEY, false, SurfaceFormat.HalfSingle, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); Sim_Component.Comp_target = new RenderTarget2D(App.graphics.GraphicsDevice, Simulator.SIZEX, Simulator.SIZEY, false, SurfaceFormat.HalfSingle, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); Sim_Component.Highlight_target = new RenderTarget2D(App.graphics.GraphicsDevice, Simulator.SIZEX, Simulator.SIZEY, false, SurfaceFormat.HalfSingle, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); Sim_Component.IsEdge_target = new RenderTarget2D(App.graphics.GraphicsDevice, Simulator.SIZEX, Simulator.SIZEY, false, SurfaceFormat.HalfSingle, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); Simulator.highestNetworkID = 4; #region LoadWires stream.Read(intbuffer, 0, 4); int wirecount = BitConverter.ToInt32(intbuffer, 0); Simulator.highestNetworkID = 4 + wirecount; for (int i = 4; i < wirecount + 4; ++i) { Network networkbuffer = new Network(i); Simulator.networks[i] = networkbuffer; stream.Read(intbuffer, 0, 4); int linecount = BitConverter.ToInt32(intbuffer, 0); for (int j = 0; j < linecount; ++j) { stream.Read(intbuffer, 0, 1); byte layers = intbuffer[0]; stream.Read(intbuffer, 0, 4); int startx = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int starty = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int endx = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int endy = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int dirx = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int diry = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int length = BitConverter.ToInt32(intbuffer, 0); Line_Netw linebuffer = new Line_Netw(new Point(startx, starty), new Point(endx, endy), new Point(dirx, diry), length, layers); networkbuffer.lines.Add(linebuffer); } networkbuffer.PlaceNetwork(); } #endregion #region LoadComp stream.Read(intbuffer, 0, 4); int compcount = BitConverter.ToInt32(intbuffer, 0); Sim_Component.nextComponentID = compcount + 1; for (int i = 1; i < compcount + 1; ++i) { stream.Read(intbuffer, 0, 4); Component buffercomp = new Component(compdata_index[BitConverter.ToInt32(intbuffer, 0)], i); stream.Read(intbuffer, 0, 4); int posX = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 4); int posY = BitConverter.ToInt32(intbuffer, 0); stream.Read(intbuffer, 0, 1); int rotation = intbuffer[0]; stream.Read(intbuffer, 0, 4); int valuebox_length = BitConverter.ToInt32(intbuffer, 0); CompData compdata = Sim_Component.Components_Data[compdata_index[buffercomp.dataID]]; for (int j = 0; j < valuebox_length; ++j) { stream.Read(intbuffer, 0, 4); int curval = BitConverter.ToInt32(intbuffer, 0); buffercomp.totalstates[compdata.internalstate_length + compdata.OverlaySeg_length + j] = curval; } Sim_Component.components[i] = buffercomp; buffercomp.Place(new Point(posX, posY), (byte)rotation, true); } Network.Delete(Simulator.FoundNetworks); Simulator.FoundNetworks.Clear(); #endregion stream.Close(); stream.Dispose(); Console.WriteLine("Loading suceeded. Filename: {0}", filename); IsUpToDate = true; } catch (Exception exp) { Console.WriteLine("Loading failed:\n{0}", exp); System.Windows.Forms.MessageBox.Show("Loading failed:\n" + exp.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
protected override void SolveInstance(IGH_DataAccess DA) { DA.SetDataList(0, CompData.GetComponentGroupsList()); }
/*public void DebugToCSV(string _path) * { * StringBuilder sb = new StringBuilder(); * for (int y = Dims.y - 1; y >= 0; --y) * { * sb.AppendLine(); * for (int x = 0; x < Dims.x; ++x) * sb.Append(this[x, y] + ","); * } * WriteAllText(_path, sb.ToString()); * }*/ /// <summary> /// Updates the data at _coord to _data /// </summary> /// <param name="_data"></param> /// <param name="_coord"></param> /// <returns></returns> public bool Update(T _data, IVector2 _coord) { if (!CoordInRange(_coord)) { throw new ArgumentOutOfRangeException(GetType().Name + "-- Index out of range: " + _coord); } //Get data at position int dataIndex, dataStripPos; //CompData[] workBlocks = GetDataGroup(_coord, out dataIndex, out dataStripPos); var workBlock = GetData(_coord, out dataIndex, out dataStripPos); //Check for bad index if (workBlock.count == 0) { throw new Exception(GetType().Name + "-- Update: Found zero count DataStrip at index " + dataIndex + "."); } //Check no change condition if (workBlock.Data.Equals(_data)) { return(true); } //Check single item strip condition if (workBlock.count == 1) { var updatedBlock = new CompData <T>(_data, 1); DataBlock[dataIndex] = updatedBlock; Meld(dataIndex, MeldDir.Both); return(true); } //Check middle of strip condition if ((workBlock.count > 2) && (dataStripPos != 0) && (dataStripPos != workBlock.count - 1)) { //Current data strip shrink to data in front var frontStrip = new CompData <T>(workBlock.Data, dataStripPos); //Insert this block var newStrip = new CompData <T>(_data, 1); //Create data in back var backStrip = new CompData <T>(workBlock.Data, workBlock.count - dataStripPos - 1); //Update Data Array DataBlock.Insert(dataIndex + 1, backStrip); DataBlock.Insert(dataIndex + 1, newStrip); DataBlock[dataIndex] = frontStrip; //Meld(dataIndex); return(true); } //Check beginning of strip condition if (dataStripPos == 0) { var newStrip = new CompData <T>(_data, 1); var backStrip = new CompData <T>(workBlock.Data, workBlock.count - 1); DataBlock.Insert(dataIndex + 1, backStrip); DataBlock[dataIndex] = newStrip; Meld(dataIndex, MeldDir.Front); return(true); } //Check end of strip condition if (dataStripPos == DataBlock[dataIndex].count - 1) { var newStrip = new CompData <T>(_data, 1); var frontStrip = new CompData <T>(workBlock.Data, workBlock.count - 1); DataBlock[dataIndex] = newStrip; DataBlock.Insert(dataIndex, frontStrip); Meld(dataIndex + 1, MeldDir.Back); return(true); } return(false); }
public static void SaveToPath(string path) { FileStream s = null; try { FileStream stream = new FileStream(path, FileMode.Create); s = stream; List <byte> bytestosave = new List <byte>(); byte[] bytearray2 = new byte[1]; int compcount = 0; int wirecount = 0; byte[] bytearray; stream.Write(BitConverter.GetBytes(Simulator.ProjectSizeX), 0, 4); stream.Write(BitConverter.GetBytes(Simulator.ProjectSizeY), 0, 4); #region Save Library & Comp Table stream.Write(BitConverter.GetBytes(CompLibrary.AllUsedLibraries.Count), 0, 4); string workingPath = SaveFile; int index = 0; for (int i = workingPath.Length - 1; i >= 0; --i) { if (workingPath[i] == '\\') { index = i; break; } } workingPath = workingPath.Remove(index, workingPath.Length - (index)); for (int i = 0; i < CompLibrary.AllUsedLibraries.Count; ++i) { CompLibrary curlib = CompLibrary.AllUsedLibraries[i]; string relPath = Extensions.MakeRelativePath(workingPath, curlib.SaveFile); string librarypath = Directory.GetCurrentDirectory() + "\\LIBRARIES\\"; bool DoesStartWith = curlib.SaveFile.StartsWith(librarypath); if (DoesStartWith) { relPath = curlib.SaveFile.Remove(0, librarypath.Length); relPath = relPath.Insert(0, "-"); } bytearray = relPath.GetBytesFromString(); stream.Write(bytearray, 0, bytearray.Length); } HashSet <int> compdatatypes = new HashSet <int>(); Sim_Component.components.ForEach(x => { if (x != null) { compdatatypes.Add(x.dataID); } }); int[] compdatatypes_array = compdatatypes.ToArray(); stream.Write(BitConverter.GetBytes(Sim_Component.Components_Data.Count), 0, 4); stream.Write(BitConverter.GetBytes(compdatatypes_array.Length), 0, 4); for (int i = 0; i < Sim_Component.Components_Data.Count; ++i) { bytearray = Sim_Component.Components_Data[i].name.GetBytesFromString(); stream.Write(bytearray, 0, bytearray.Length); } for (int i = 0; i < compdatatypes_array.Length; ++i) { stream.Write(BitConverter.GetBytes(compdatatypes_array[i]), 0, 4); } //for (int i = 0; i < Sim_Component.Components_Data.Count; ++i) //{ // int LibraryID = CompLibrary.AllLibraries.IndexOf(Sim_Component.Components_Data[i].library); // stream.Write(BitConverter.GetBytes(LibraryID), 0, 4); //} #endregion #region Save Wires wirecount = Simulator.networks.Count(x => x != null); stream.Write(BitConverter.GetBytes(wirecount), 0, 4); for (int i = 0; i < Simulator.networks.Length; ++i) { if (Simulator.networks[i] != null) { List <Line_Netw> lines = Simulator.networks[i].lines; stream.Write(BitConverter.GetBytes(lines.Count), 0, 4); for (int j = 0; j < lines.Count; ++j) { stream.Write(new byte[1] { (byte)(lines[j].layers) }, 0, 1); stream.Write(BitConverter.GetBytes(lines[j].start.X), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].start.Y), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].end.X), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].end.Y), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].dir.X), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].dir.Y), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].length), 0, 4); } } } #endregion #region Save Components compcount = Sim_Component.components.Count(x => x != null); stream.Write(BitConverter.GetBytes(compcount), 0, 4); for (int i = 0; i < Sim_Component.components.Length; ++i) { if (Sim_Component.components[i] != null) { stream.Write(BitConverter.GetBytes(Sim_Component.components[i].dataID), 0, 4); stream.Write(BitConverter.GetBytes(Sim_Component.components[i].pos.X), 0, 4); stream.Write(BitConverter.GetBytes(Sim_Component.components[i].pos.Y), 0, 4); bytearray2[0] = Sim_Component.components[i].rotation; stream.Write(bytearray2, 0, 1); CompData compdata = Sim_Component.Components_Data[Sim_Component.components[i].dataID]; stream.Write(BitConverter.GetBytes(compdata.valuebox_length), 0, 4); for (int j = 0; j < compdata.valuebox_length; ++j) { stream.Write(BitConverter.GetBytes(Sim_Component.components[i].totalstates[compdata.internalstate_length + compdata.OverlaySeg_length + j]), 0, 4); } } } #endregion stream.Close(); stream.Dispose(); Console.WriteLine("Saving suceeded. Filename: {0}", path); IsUpToDate = true; } catch (Exception exp) { Console.WriteLine("Saving failed: {0}", exp); if (s != null) { s.Close(); } System.Windows.Forms.MessageBox.Show("Saving failed", null, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void GenerateDllCodeAndCompile() { // Generating DLL Code and DLLs string code_original = File.ReadAllText(@"SIM_CODE\original.c"); int compfuncspos = code_original.IndexOf("#define _COMPFUNCS_"); string code_withcompfuncs = code_original.Remove(compfuncspos, 19); for (int i = 0; i < Sim_Component.Components_Data.Count; ++i) { CompData curdata = Sim_Component.Components_Data[i]; code_withcompfuncs = code_withcompfuncs.Insert(compfuncspos, curdata.Code_Sim); } int initfuncpos = code_withcompfuncs.IndexOf("int _INITFUNCS_;"); string code_withinitfuncs = code_withcompfuncs.Remove(initfuncpos, 16); for (int i = Sim_Component.Components_Data.Count - 1; i >= 0; --i) { CompData curdata = Sim_Component.Components_Data[i]; code_withinitfuncs = code_withinitfuncs.Insert(initfuncpos, "compfuncs[index++] = " + curdata.Code_Sim_FuncName + ";\n"); } //int afterupdatefuncpos = code_withinitfuncs.IndexOf("#define _AFTERUPDATEFUNCS_"); //string code_withafterupdatefuncs = code_withinitfuncs.Remove(afterupdatefuncpos, 26); //for (int i = Sim_Component.Components_Data.Count - 1; i >= 0; --i) //{ // CompData curdata = Sim_Component.Components_Data[i]; // if (curdata.IsUpdateAfterSim) // { // code_withafterupdatefuncs = code_withafterupdatefuncs.Insert(afterupdatefuncpos, curdata.Code_AfterSim); // } //} if (SimDLL_Handle != IntPtr.Zero) { DLL_Methods.FreeLibrary(SimDLL_Handle); SimDLL_Handle = (IntPtr)0; } string pathtoexe = Directory.GetCurrentDirectory(); File.WriteAllText(pathtoexe + @"\SIM_CODE\maincode.c", code_withinitfuncs); string driveletter = Path.GetPathRoot(Environment.SystemDirectory); //string command = "/c " + driveletter + @"GCC\mingw64\bin\g++"; //command += " -c -m64 -DBUILDING_EXAMPLE_DLL "; //command += "\"" + pathtoexe + @"\SIM_CODE\maincode.c" + "\" -o \""; //command += pathtoexe + @"\SIM_CODE\maincode.o" + "\""; //Extensions.ExecuteProgram("cmd", command); string GCC_Path = Path.GetFullPath(Config.GCC_Compiler_PATH); if (GCC_Path.Last() == '\\') { GCC_Path = GCC_Path.Remove(GCC_Path.Length - 1, 1); } string command = "/c " + "\"" + "\"" + GCC_Path + @"\g++" + "\"" + " -m64 -shared \""; command += pathtoexe + @"\SIM_CODE\maincode.dll" + "\" \""; command += pathtoexe + @"\SIM_CODE\maincode.c" + "\"" + "\""; Extensions.ExecuteProgram("cmd", command); LoadSimDLL(); }