unsafe public bool init(IntPtr handle) { if (check_dll() == false) { is_alive = false; return(false); } is_alive = true; GLOBAL.jadro = new Core(); GLOBAL.jadro.InitCore(GLOBAL.package_obj); wnd_id = create_window_render(handle); GLOBAL.plot_id = create_array_render(handle); set_frame(GLOBAL.plot_id, true); wnd_handle = handle; plot_param = new PlotParameters(); RestorePlotParameters(); SetPlotType(plot_param.plot_type); SetPointColor(plot_param.point_color_red, plot_param.point_color_green, plot_param.point_color_blue); SetLineColor(plot_param.line_color_red, plot_param.line_color_green, plot_param.line_color_blue); SetSymbolColor(plot_param.cross_color_red, plot_param.cross_color_green, plot_param.cross_color_blue); SetPointNum(plot_param.point_num); SetSymbolSize(plot_param.figure_size); SetBkgColor(plot_param.background_color_red, plot_param.background_color_green, plot_param.background_color_blue); return(true); }
protected Parameters MakeParameters(PlotParameters parameters, int?forcedEveryNthCycle) { return(new Parameters { MaxPointsPerSeries = parameters?.MaxPointsPerSeries, Simplification = parameters?.Simplification ?? 0, FromCycle = parameters?.FromCycle, ToCycle = parameters?.ToCycle, EveryNthCycle = forcedEveryNthCycle ?? parameters?.EveryNthCycle, CustomCycleFilter = string.IsNullOrWhiteSpace(parameters?.CustomCycleFilter) ? null : new IndexRangeFilter(parameters.CustomCycleFilter), IsChargeEnabled = !(parameters?.DisableCharge ?? false), IsDischargeEnabled = !(parameters?.DisableDischarge ?? false), Threshold = parameters?.Threshold, MinY = parameters?.MinY, MaxY = parameters?.MaxY, CurrentUoM = parameters?.CurrentUoM ?? CurrentUoM.mA, CapacityUoM = parameters?.CapacityUoM ?? CapacityUoM.mAh, TimeUoM = parameters?.TimeUoM ?? TimeUoM.Seconds, PowerUoM = parameters?.PowerUoM ?? PowerUoM.W, EnergyUoM = parameters?.EnergyUoM ?? EnergyUoM.Wh, ResistanceUoM = parameters?.ResistanceUoM ?? ResistanceUoM.Ohm, NormalizeBy = parameters?.NormalizeBy ?? NormalizeBy.None }); }
public Chart Plot(PlotType plotType, PlotParameters parameters, int[] projects, string trace) { var forcedEveryNthCycle = CalcForcedEveryNthCycle(plotType, projects, parameters, trace); var param = MakeParameters(parameters, forcedEveryNthCycle); var chart = CreateChart(plotType, param); chart.ForcedEveryNthCycle = forcedEveryNthCycle; foreach (var pid in projects) { Plot(chart, pid, plotType, param, trace); } return(chart); }
public PlotParameters MergeWithGlobal(string userId, PlotParameters origiParameters) { var globalPreferences = _db.UserPreferences.Find(userId) ?? AppUserPreferences.Default; var deepCopy = JsonConvert.DeserializeObject <PlotParameters>(JsonConvert.SerializeObject(origiParameters)); deepCopy.LegendShowen = deepCopy.LegendShowen ?? globalPreferences.ChartPreferences.LegendShowen; deepCopy.FontFamilyName = string.IsNullOrEmpty(deepCopy.FontFamilyName) ? globalPreferences.ChartPreferences.FontFamilyName : deepCopy.FontFamilyName; deepCopy.FontSize = deepCopy.FontSize <= 0 ? globalPreferences.ChartPreferences.FontSize : deepCopy.FontSize; deepCopy.PointSize = deepCopy.PointSize ?? globalPreferences.ChartPreferences.PointSize; deepCopy.xLineVisible = deepCopy.xLineVisible ?? globalPreferences.ChartPreferences.XLineVisible; deepCopy.yLineVisible = deepCopy.yLineVisible ?? globalPreferences.ChartPreferences.YLineVisible; deepCopy.LegendShowen = deepCopy.LegendShowen ?? globalPreferences.ChartPreferences.LegendShowen; deepCopy.ChartPalette = globalPreferences.ChartPreferences.PaletteColors.ToList(); return(deepCopy); }
//////////////////////////////////////////////////////////// // Protected Methods/Atributes //////////////////////////////////////////////////////////// protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { Projects?.Clear(); Series?.Clear(); PlotParameters = null; YAxisText = null; Projects = null; Series = null; } _disposed = true; }
public PlotParameters MergePlotParameters(PlotParameters origiParameters, PlotParameters mergeParameters) { var deepCopy = JsonConvert.DeserializeObject <PlotParameters>(JsonConvert.SerializeObject(origiParameters)); deepCopy.LegendShowen = mergeParameters.LegendShowen; deepCopy.FontFamilyName = string.IsNullOrEmpty(mergeParameters.FontFamilyName) ? deepCopy.FontFamilyName : mergeParameters.FontFamilyName; deepCopy.FontSize = mergeParameters.FontSize <= 0 ? deepCopy.FontSize : mergeParameters.FontSize; deepCopy.PointSize = mergeParameters.PointSize ?? deepCopy.PointSize; deepCopy.xLineVisible = mergeParameters.xLineVisible ?? deepCopy.xLineVisible; deepCopy.yLineVisible = mergeParameters.yLineVisible ?? deepCopy.yLineVisible; deepCopy.LegendShowen = mergeParameters.LegendShowen ?? deepCopy.LegendShowen; deepCopy.ChartPalette = mergeParameters.ChartPalette; deepCopy.NormalizeBy = mergeParameters.NormalizeBy ?? deepCopy.NormalizeBy; deepCopy.CurrentUoM = mergeParameters.CurrentUoM ?? deepCopy.CurrentUoM; deepCopy.TimeUoM = mergeParameters.TimeUoM ?? deepCopy.TimeUoM; deepCopy.PowerUoM = mergeParameters.PowerUoM ?? deepCopy.PowerUoM; deepCopy.EnergyUoM = mergeParameters.EnergyUoM ?? deepCopy.EnergyUoM; deepCopy.ResistanceUoM = mergeParameters.ResistanceUoM ?? deepCopy.ResistanceUoM; deepCopy.CapacityUoM = mergeParameters.CapacityUoM ?? deepCopy.CapacityUoM; deepCopy.VoltageUoM = mergeParameters.VoltageUoM ?? deepCopy.VoltageUoM; deepCopy.EnergyUoM = mergeParameters.EnergyUoM ?? deepCopy.EnergyUoM; deepCopy.DisableDischarge = mergeParameters.DisableDischarge ?? deepCopy.DisableDischarge; deepCopy.DisableCharge = mergeParameters.DisableCharge ?? deepCopy.DisableCharge; deepCopy.FromCycle = mergeParameters.FromCycle ?? deepCopy.FromCycle; deepCopy.ToCycle = mergeParameters.ToCycle ?? deepCopy.ToCycle; deepCopy.EveryNthCycle = mergeParameters.EveryNthCycle ?? deepCopy.EveryNthCycle; deepCopy.xAxisText = mergeParameters.xAxisText ?? deepCopy.xAxisText; deepCopy.yAxisText = mergeParameters.yAxisText.Any() ? mergeParameters.yAxisText : deepCopy.yAxisText; deepCopy.ChartTitle = mergeParameters.ChartTitle ?? deepCopy.ChartTitle; return(deepCopy); }
private int?CalcForcedEveryNthCycle(PlotType plotType, int[] projects, PlotParameters parameters, string trace) { if (plotType != PlotType.VoltageCapacity && plotType != PlotType.DifferentialVoltage && plotType != PlotType.DifferentialCapacity) { return(null); } var maxCycles = parameters?.MaxCycles ?? 0; if (maxCycles <= 0) { return(null); } var maxCyclesPerProject = Math.Max(maxCycles / projects.Length - 1, 1); var forcedEveryNthCycle = projects.Max(pid => { var cycles = _projectDataRepository.GetCycles(pid, trace).Count; if (!string.IsNullOrEmpty(parameters?.CustomCycleFilter)) { var rangeFilter = new IndexRangeFilter(parameters.CustomCycleFilter).RangesItems; cycles = rangeFilter.Count; var result = cycles / maxCyclesPerProject; if (cycles % maxCyclesPerProject != 0) { result += 1; } return(result); } else { var fromCycle = Math.Max(parameters?.FromCycle ?? 1, 1); var toCycle = Math.Min(parameters?.ToCycle ?? cycles, cycles); cycles = toCycle - fromCycle + 1; var result = cycles / maxCyclesPerProject; if (cycles % maxCyclesPerProject != 0) { result += 1; } return(result); } }); if (forcedEveryNthCycle < 2) { return(null); } if (parameters?.EveryNthCycle != null && parameters.EveryNthCycle.Value >= forcedEveryNthCycle) { return(null); } return(forcedEveryNthCycle); }
public IHttpActionResult GetExportChart( [FromUri] int[] projectId, [FromUri] PlotType plotType, [FromUri] string format = null, [FromUri] string templateIdValue = null, [FromUri] int?maxCycles = null, [FromUri] int?maxPointsPerSeries = null, [FromUri] int?fromCycle = null, [FromUri] int?toCycle = null, [FromUri] int?everyNthCycle = null, [FromUri] string customCycleFilter = null, [FromUri] bool?disableCharge = null, [FromUri] bool?disableDischarge = null, [FromUri] double?threshold = null, [FromUri] double?minY = null, [FromUri] double?maxY = null, [FromUri] CurrentUoM?currentUoM = null, [FromUri] CapacityUoM?capacityUoM = null, [FromUri] TimeUoM?timeUoM = null, [FromUri] PowerUoM?powerUoM = null, [FromUri] EnergyUoM?energyUoM = null, [FromUri] ResistanceUoM?resistanceUoM = null, [FromUri] NormalizeBy?normalizeBy = null, [FromUri] int?pointSize = null, [FromUri] double?chargeFrom = null, [FromUri] double?chargeTo = null) { var result = _selectProjectListQuery.Execute(User.Identity.GetUserId(), projectId); if (result.Status != ProjectStatusDto.Ready) { return(NotFound()); } var timer = Stopwatch.StartNew(); Chart chart; if ((plotType == PlotType.View || plotType == PlotType.Template) && !string.IsNullOrEmpty(templateIdValue)) { int.TryParse(templateIdValue, out var templateId); var item = _plotTemplateService.GetChartTemplate(new ChartOwner(User.Identity.GetUserId(), User.Identity.Name), templateId, result.Projects); if (item == null) { Log.Error($"Template {templateId} not found"); return(NotFound()); } chart = item.Chart; timer.Restart(); } else if (plotType == PlotType.Soc) { var parameters = new PlotParameters { MaxCycles = maxCycles, MaxPointsPerSeries = maxPointsPerSeries, FromCycle = fromCycle, ToCycle = toCycle, EveryNthCycle = everyNthCycle, CustomCycleFilter = customCycleFilter, DisableCharge = disableCharge, DisableDischarge = disableDischarge, Threshold = threshold, MinY = minY, MaxY = maxY, CurrentUoM = currentUoM, CapacityUoM = capacityUoM, TimeUoM = timeUoM, PowerUoM = powerUoM, EnergyUoM = energyUoM, ResistanceUoM = resistanceUoM, NormalizeBy = normalizeBy, PointSize = pointSize }; StateOfCharge stateOfCharge = new StateOfCharge { ChargeFrom = chargeFrom, ChargeTo = chargeTo }; chart = _chartPlotterFactory(PlotType.Soc).Plot(false, new ChartPlotterContext { Parameters = parameters, ProjectIds = projectId, Trace = User.Identity.Name, Data = stateOfCharge }); chart.PlotParameters = parameters; Log.Info($"ChartController.GetExportChart: Plot({plotType}, {parameters}, {projectId}): plot {timer.ElapsedMilliseconds} ms"); } else { PlotParameters parameters = new PlotParameters { MaxCycles = maxCycles, MaxPointsPerSeries = maxPointsPerSeries, FromCycle = fromCycle, ToCycle = toCycle, EveryNthCycle = everyNthCycle, CustomCycleFilter = customCycleFilter, DisableCharge = disableCharge, DisableDischarge = disableDischarge, Threshold = threshold, MinY = minY, MaxY = maxY, CurrentUoM = currentUoM, CapacityUoM = capacityUoM, TimeUoM = timeUoM, PowerUoM = powerUoM, EnergyUoM = energyUoM, ResistanceUoM = resistanceUoM, NormalizeBy = normalizeBy, PointSize = pointSize }; chart = _chartPlotterFactory(plotType).Plot(true, new ChartPlotterContext { Parameters = parameters, ProjectIds = projectId, Trace = User.Identity.Name }); Log.Info($"ChartController.GetExportChart: Plot({plotType}, {parameters}, {projectId}): plot {timer.ElapsedMilliseconds} ms"); chart.PlotParameters = parameters; } var files = HttpContext.Current.Request.Files; Stream imageStream = null; if (files.Count > 0) { imageStream = files[0].InputStream; } return(new ExcelHttpActionResult(_exporter.ToExcel(chart, imageStream))); }
public void SetSettings(string userId, PlotParameters parameters) { _cacheProvider.Set($"PlotParameters_{userId}", parameters); }
private int?CalcForcedEveryNthCycle(bool projectsSumCyclesGreaterThanMax, int[] projects, PlotParameters parameters, string trace) { if (!projectsSumCyclesGreaterThanMax || IsCalcEveryNthCycleForcedDisabled) { return(null); } var maxCycles = parameters?.MaxCycles ?? 0; if (maxCycles <= 0) { return(null); } var maxCyclesPerProject = Math.Max(maxCycles / projects.Length - 1, 1); var forcedEveryNthCycle = projects.Max(pid => { int cycles = ProjectDataRepository.GetCycles(pid, trace).Count; if (parameters != null && string.IsNullOrEmpty(parameters.CustomCycleFilter)) { int fromCycle = Math.Max(parameters.FromCycle ?? 1, 1); int toCycle = Math.Min(parameters.ToCycle ?? cycles, cycles); cycles = toCycle - fromCycle + 1; int result = cycles / maxCyclesPerProject; if (cycles % maxCyclesPerProject != 0) { result += 1; } return(result); } else { if (parameters != null) { var rangeFilter = new IndexRangeFilter(parameters.CustomCycleFilter).RangesItems; cycles = rangeFilter.Count; } int result = cycles / maxCyclesPerProject; if (cycles % maxCyclesPerProject != 0) { result += 1; } return(result); } }); if (forcedEveryNthCycle < 2) { return(null); } if (parameters?.EveryNthCycle != null && parameters.EveryNthCycle.Value >= forcedEveryNthCycle) { return(null); } return(forcedEveryNthCycle); }
public void RestorePlotParameters() { try { XmlSerializer deserializer = new XmlSerializer(typeof(PlotParameters)); string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); dir += "\\config.xml"; using (TextReader reader = new StreamReader(dir)) { plot_param = (PlotParameters)(deserializer.Deserialize(reader)); } } catch (Exception e) { //specifying default parameters plot_param.point_color_red = 1; plot_param.point_color_green = 0; plot_param.point_color_blue = 0; plot_param.line_color_red = 1; plot_param.line_color_green = 0; plot_param.line_color_blue = 0; plot_param.cross_color_red = 0; plot_param.cross_color_green = 0; plot_param.cross_color_blue = 1; plot_param.background_color_red = 1; plot_param.background_color_green = 1; plot_param.background_color_blue = 1; plot_param.plot_type = 0x02; plot_param.figure_size = 12; plot_param.point_num = 1024; SavePlotParameters(); } }
public unsafe bool init(IntPtr handle) { if (check_dll() == false) { is_alive = false; return false; } is_alive = true; GLOBAL.jadro = new Core(); GLOBAL.jadro.InitCore(GLOBAL.package_obj); wnd_id = create_window_render(handle); GLOBAL.plot_id = create_array_render(handle); set_frame(GLOBAL.plot_id, true); wnd_handle = handle; plot_param = new PlotParameters(); RestorePlotParameters(); SetPlotType(plot_param.plot_type); SetPointColor(plot_param.point_color_red, plot_param.point_color_green, plot_param.point_color_blue); SetLineColor(plot_param.line_color_red, plot_param.line_color_green, plot_param.line_color_blue); SetSymbolColor(plot_param.cross_color_red, plot_param.cross_color_green, plot_param.cross_color_blue); SetPointNum(plot_param.point_num); SetSymbolSize(plot_param.figure_size); SetBkgColor(plot_param.background_color_red, plot_param.background_color_green, plot_param.background_color_blue); return true; }
public static void PlotLayout(this Document document, Transaction tr, Layout layout, PlotParameters plotParameters) { var ps = new PlotSettings(layout.ModelType); ps.CopyFrom(layout); ps.PlotPlotStyles = true; var psv = PlotSettingsValidator.Current; psv.SetDefaultPlotConfig(ps); psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents); psv.SetUseStandardScale(ps, true); psv.SetPlotOrigin(ps, plotParameters.PaperFormat.PlotOrigin); // psv.SetPlotRotation(ps, PlotRotation.Degrees090); if (plotParameters.PaperFormat.ShrinkDrawing) { psv.SetStdScaleType(ps, StdScaleType.ScaleToFit); //psv.SetUseStandardScale(ps, false); //psv.SetStdScale(ps, 2); //var Scale = new CustomScale(1, 0.5); //psv.SetCustomPrintScale(ps, Scale); } else { psv.SetStdScaleType(ps, StdScaleType.StdScale1To1); } psv.SetPlotConfigurationName(ps, plotParameters.Pc3Name, plotParameters.PaperFormat.CanonicalMediaName); psv.SetPlotPaperUnits(ps, PlotPaperUnit.Millimeters); var pi = new PlotInfo(); pi.Layout = layout.ObjectId; pi.OverrideSettings = ps; var piv = new PlotInfoValidator(); piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled; piv.Validate(pi); var d = Path.GetDirectoryName(plotParameters.OutputFilePath); if (!Directory.Exists(d)) { Directory.CreateDirectory(d); } using (var pe = PlotFactory.CreatePublishEngine()) using (var ppi = new PlotPageInfo()) { pe.BeginPlot(null, null); pe.BeginDocument(pi, document.Name, null, 1, plotParameters.PlotToFile, plotParameters.OutputFilePath); pe.BeginPage(ppi, pi, true, null); pe.BeginGenerateGraphics(null); pe.EndGenerateGraphics(null); pe.EndPage(null); pe.EndDocument(null); pe.EndPlot(null); } tr.Commit(); }