public override void Execute() { ILayoutViewer viewer = _smartSession.SmartWindowManager.ActiveViewer as ILayoutViewer; if (viewer == null) { return; } string fname = null; using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "专题图模版(*.gxt)|*.gxt"; dlg.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "LayoutTemplate\\自定义"; if (dlg.ShowDialog() == DialogResult.OK) { fname = dlg.FileName; } } ILayoutTemplate template = new LayoutTemplate(fname); if (viewer.LayoutHost == null) { return; } viewer.LayoutHost.ApplyTemplate(template); viewer.LayoutHost.Render(); }
/// <summary> /// Loads the template files from the specified startup path /// </summary> /// <param name="sStartupPath">The path containing the templates folder</param> public void LoadLayoutTemplates(string sStartupPath) { var listLayoutTemplates = new List <LayoutTemplate>(); var sLayoutsPath = Path.Combine(sStartupPath, LAYOUT_TEMPLATES_FOLDER); try { if (!Directory.Exists(sLayoutsPath)) { Logger.AddLogLine("LayoutTemplates folder does not exist: {0}".FormatString(sLayoutsPath)); LayoutTemplates = listLayoutTemplates; } var arrayTemplateFiles = Directory.GetFiles(sLayoutsPath, "*.{0}".FormatString(LAYOUT_TEMPLATE_EXTENSION)); LayoutTemplate zTemplate = null; foreach (var sLayoutFilePath in arrayTemplateFiles) { try { SerializationUtils.DeserializeFromXmlFile(sLayoutFilePath, CardMakerConstants.XML_ENCODING, ref zTemplate); listLayoutTemplates.Add(zTemplate); } catch (Exception) { Logger.AddLogLine("Failed to load LayoutTemplate file: {0}".FormatString(sLayoutFilePath)); } } } catch (Exception) { Logger.AddLogLine(string.Format("Failed to access template files in {0}", sLayoutsPath)); } LayoutTemplates = listLayoutTemplates; }
private Image GetOverviewImage(string fname) { string ovFileName = fname.ToLower().Replace(".gxt", ".png"); if (File.Exists(ovFileName)) { using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(ovFileName))) { return(new Bitmap(ms)); } } else { try { using (ILayoutTemplate template = LayoutTemplate.LoadTemplateFrom(fname)) { if (template != null) { Bitmap bitmap = template.GetOverview(new Size(165, 165)); if (bitmap != null) { bitmap.Save(ovFileName, ImageFormat.Png); } return(bitmap); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(null); }
//internal void SetOrbitTimes(string[] orbitTimes) //{ // if (_template == null) // return; // ILayout layout = _template.Layout; // IElement[] dfs = layout.QueryElements((e) => { return e is ILegendElement; }); // List<LegendItem> lg = new List<LegendItem>(); // for (int i = 0; i < orbitTimes.Length; i++) // { // lg.Add(new LegendItem(orbitTimes[i])); // } // ILegendElement legend = dfs[0] as ILegendElement; // legend.LegendItems = lg.ToArray(); //} public string CreateThematicGraphic(string dataFileName, string theme, string gxdFilename, string extInfos, params object[] options) { _template = LayoutTemplate.LoadTemplateFrom(theme); if (_template == null) { return(null); } if (_isNeedFitToTemplateWidth) { using (IRasterDataProvider prd = GeoDataDriver.Open(dataFileName) as IRasterDataProvider) { if (prd != null) { FitTemplateWidth(_template.Layout, prd.Width, prd.Height); } } } IGxdDocument _doc = GetDocument(dataFileName, _aoi, _template, options != null && options.Length > 0 ? options[0] : null); if (_doc == null) { return(null); } _doc.SaveAs(gxdFilename); return(gxdFilename); }
public void LayoutView_Template_Test() { var template = new LayoutTemplate(new SmartAppInfo { Id = ApplicationId }); Assert.Throws <ArgumentNullException>(() => template.TransformText()); }
//保存模板 private void button13_Click(object sender, EventArgs e) { string fname = "e:\\TemplateFile.gxt"; // LayoutToFile.SaveToFile(fname, _host.LayoutRuntime.Layout); ILayoutTemplate template = new LayoutTemplate(_host); // 构造当前的模板对象 template.SaveTo(fname); }
private void button13_Click_1(object sender, EventArgs e) { // Bitmap bm = _host.SaveToBitmap(); ILayoutTemplate template = new LayoutTemplate(_host); Bitmap bm = template.GetOverview(new System.Drawing.Size(165, 165)); bm.Save("e:\\ov.bmp", ImageFormat.Bmp); }
private ILayoutTemplate GetTemplateByArg(string templateName) { ILayoutTemplate t = LayoutTemplate.FindTemplate(templateName); if (t == null) { t = LayoutTemplate.FindTemplate("缺省二值图模版"); } return(t); }
void SelectedListViewItemsChanged(object sender, EventArgs e) { if (_listOverview.SelectedIndex == -1) { return; } if (_templateClicked != null) { _templateClicked(sender, LayoutTemplate.LoadTemplateFrom(_listOverview.SelectedItem.Tag.ToString())); } }
protected override void Render(HtmlTextWriter writer) { WebControl div = new WebControl(HtmlTextWriterTag.Div); LayoutTemplate.InstantiateIn(div); Controls.Clear(); Controls.Add(div); div.CopyBaseAttributes(this); div.CssClass = this.CssClass; div.RenderControl(writer); }
private ILayoutTemplate GetTemplateByName(string fname, string templateName) { ILayoutTemplate t = LayoutTemplate.FindTemplate(templateName); if (t == null) { if (fname.Contains("_DBLV_")) { t = LayoutTemplate.FindTemplate("缺省二值图模版"); } } return(t); }
private void CreateLayoutFile(string layoutsDirectory, LayoutDescription layoutDescription) { LayoutTemplate layoutTemplate = new LayoutTemplate() { Session = new Dictionary <string, object> { ["generator"] = this, ["layoutDescription"] = layoutDescription } }; layoutTemplate.Initialize(); File.WriteAllText($@"{layoutsDirectory}\{layoutDescription.Name}.cs", layoutTemplate.TransformText()); }
/// <summary> /// Deletes the specified layout template /// </summary> /// <param name="sStartupPath">The path containing the templates folder</param> /// <param name="zLayoutTemplate">The template to delete</param> public void DeleteLayoutTemplate(string sStartupPath, LayoutTemplate zLayoutTemplate) { var sLayoutsPath = Path.Combine(sStartupPath, LAYOUT_TEMPLATES_FOLDER); try { var sFileName = ReplaceNonFileSafeCharacters(zLayoutTemplate.Layout.Name); var sFilePath = Path.Combine(sLayoutsPath, sFileName) + "." + LAYOUT_TEMPLATE_EXTENSION; File.Delete(sFilePath); } catch (Exception e) { Logger.AddLogLine("Error deleting LayoutTemplate: {0}".FormatString(e.Message)); } }
private ILayoutTemplate GetTemplateByArg(string templateName) { string[] parts = templateName.Split(':'); if (parts == null || parts.Length < 2) { return(null); } templateName = parts[1]; ILayoutTemplate t = LayoutTemplate.FindTemplate(templateName); if (t == null) { t = LayoutTemplate.FindTemplate("缺省二值图模版"); } return(t); }
//应用模板 private void FromXml_Click(object sender, EventArgs e) { string fname = AppDomain.CurrentDomain.BaseDirectory + "LayoutTemplate\\自定义\\热岛效应强度分布图.gxt"; //fname = @"E:\气象局项目\MAS二期\【控制】代码工程\【控制】UI框架\SMART\bin\Release\LayoutTemplate\通用专题图\陆表温度专题图模板.gxt"; using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "GXT(*.gxt)|*.gxt"; if (dlg.ShowDialog() == DialogResult.OK) { fname = dlg.FileName; } } ILayoutTemplate template = new LayoutTemplate(fname); _host.ApplyTemplate(template); _host.Render(); }
/// <summary> /// Saves the specified layout template /// </summary> /// <param name="sStartupPath">The path containing the templates folder</param> /// <param name="zLayoutTemplate">The template to save</param> /// <returns>true on success, false otherwise</returns> public bool SaveLayoutTemplate(string sStartupPath, LayoutTemplate zLayoutTemplate) { var sLayoutsPath = Path.Combine(sStartupPath, LAYOUT_TEMPLATES_FOLDER); try { if (!Directory.Exists(sLayoutsPath)) { Directory.CreateDirectory(sLayoutsPath); } var sFileName = ReplaceNonFileSafeCharacters(zLayoutTemplate.Layout.Name); var sOutput = Path.Combine(sLayoutsPath, sFileName) + "." + LAYOUT_TEMPLATE_EXTENSION; return(SerializationUtils.SerializeToXmlFile(sOutput, zLayoutTemplate, CardMakerConstants.XML_ENCODING)); } catch (Exception e) { Logger.AddLogLine("Error saving LayoutTemplate: {0}".FormatString(e.Message)); } return(false); }
private void defineAsTemplateLayoutToolStripMenuItem_Click(object sender, EventArgs e) { const string NAME = "name"; //const string COPY_REFS = "copy_refs"; var zQuery = new QueryPanelDialog("Template Name", 450, 80, false); zQuery.SetIcon(Resources.CardMakerIcon); zQuery.AddTextBox("Name", "New Template", false, NAME); // TODO: is there really a case where the refs should be copied? //zQuery.AddCheckBox("Copy References", false, COPY_REFS); if (DialogResult.OK == zQuery.ShowDialog(this)) { var zLayout = new ProjectLayout(); zLayout.DeepCopy((ProjectLayout)treeView.SelectedNode.Tag, /*zQuery.GetBool(COPY_REFS)*/ false); var zTemplate = new LayoutTemplate(zQuery.GetString(NAME), zLayout); if (LayoutTemplateManager.Instance.SaveLayoutTemplate(CardMakerInstance.StartupPath, zTemplate)) { LayoutTemplateManager.Instance.LayoutTemplates.Add(zTemplate); } } }
public override bool Open(string fname, out bool memoryIsNotEnough) { memoryIsNotEnough = false; string text = OpenFileFactory.GetTextByFileName(fname); ILayoutViewer viewer = new LayoutViewer(text); (viewer as LayoutViewer).Tag = fname; (viewer as LayoutViewer).SetSession(_session); _session.SmartWindowManager.DisplayWindow(viewer); if (viewer != null) { string extName = Path.GetExtension(fname).ToUpper(); switch (extName) { case ".GXT": ILayoutTemplate template = LayoutTemplate.LoadTemplateFrom(fname); if (template != null) { viewer.LayoutHost.ApplyTemplate(template); viewer.LayoutHost.ToSuitedSize(); AnsynRefreshData(viewer); _session.UIFrameworkHelper.ActiveTab("专题制图"); } break; case ".GXD": IGxdDocument doc = GxdDocument.LoadFrom(fname); if (doc != null) { viewer.LayoutHost.ApplyGxdDocument(doc); viewer.LayoutHost.ToSuitedSize(); AnsynRefreshData(viewer); //_session.UIFrameworkHelper.ActiveTab("专题制图"); } break; } } return(true); }
public override void Execute() { ILayoutViewer viewer = _smartSession.SmartWindowManager.ActiveViewer as ILayoutViewer; if (viewer == null) { return; } using (SaveFileDialog dlg = new SaveFileDialog()) { dlg.Filter = "专题图模板(*.gxt)|*.gxt"; dlg.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "LayoutTemplate\\自定义"; if (dlg.ShowDialog() == DialogResult.OK) { ILayoutTemplate template = new LayoutTemplate(viewer.LayoutHost); template.Name = template.Text = Path.GetFileNameWithoutExtension(dlg.FileName); template.SaveTo(dlg.FileName); using (System.Drawing.Bitmap bm = viewer.LayoutHost.ExportToBitmap(PixelFormat.Format32bppArgb, new System.Drawing.Size(165, 165))) { bm.Save(dlg.FileName.ToLower().Replace(".gxt", ".png"), ImageFormat.Png); } } } }
private void AddLayout(LayoutTemplate layoutTemplate, Layout <View> parentLayout) { Layout <View> newLayout = null; ScrollView scrollView = null; if (layoutTemplate.ScrollX || layoutTemplate.ScrollY) { scrollView = new ScrollView(); AttributeHelper.ApplyTranslation(scrollView, layoutTemplate.Attributes); if (layoutTemplate.ScrollX && layoutTemplate.ScrollY) { scrollView.Orientation = ScrollOrientation.Both; } else if (layoutTemplate.ScrollY) { scrollView.Orientation = ScrollOrientation.Vertical; } else if (layoutTemplate.ScrollX) { scrollView.Orientation = ScrollOrientation.Horizontal; } if (parentLayout is Grid) { try { (( Grid )parentLayout).Children.Add( newLayout, layoutTemplate.Column, layoutTemplate.Row ); Grid.SetColumnSpan(newLayout, layoutTemplate.ColumnSpan); Grid.SetRowSpan(newLayout, layoutTemplate.RowSpan); } catch { } } else { parentLayout.Children.Add(scrollView); } } if (layoutTemplate.Type == "StackLayout") { var sl = new StackLayout(); sl.Orientation = layoutTemplate.Orientation; if (layoutTemplate.Spacing >= 0) { sl.Spacing = layoutTemplate.Spacing; } newLayout = sl; } else if (layoutTemplate.Type == "Grid") { var g = new Grid(); if (layoutTemplate.Spacing >= 0) { g.RowSpacing = layoutTemplate.Spacing; g.ColumnSpacing = layoutTemplate.Spacing; } var gridConverter = new GridLengthTypeConverter(); var rowDefinitions = layoutTemplate.RowDefinitions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var def in rowDefinitions) { var gridLength = ( GridLength )gridConverter.ConvertFromInvariantString(def); g.RowDefinitions.Add(new RowDefinition { Height = gridLength }); } var columnDefinitions = layoutTemplate.ColumnDefinitions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var def in columnDefinitions) { var gridLength = ( GridLength )gridConverter.ConvertFromInvariantString(def); g.ColumnDefinitions.Add(new ColumnDefinition { Width = gridLength }); } newLayout = g; } if (newLayout == null) { return; } if (scrollView != null) { scrollView.Content = newLayout; } else { if (parentLayout is Grid) { try { (( Grid )parentLayout).Children.Add( newLayout, layoutTemplate.Column, layoutTemplate.Row ); Grid.SetColumnSpan(newLayout, layoutTemplate.ColumnSpan); Grid.SetRowSpan(newLayout, layoutTemplate.RowSpan); } catch { } } else { parentLayout.Children.Add(newLayout); } } layouts.Add(layoutTemplate.Name.ToLower(), newLayout); AttributeHelper.ApplyTranslation(newLayout, layoutTemplate.Attributes); foreach (var child in layoutTemplate.Children) { AddLayout(child, newLayout); } }
private void TransformViewsSharedLayoutTemplate(SmartAppInfo manifest) { var template = new LayoutTemplate(manifest); _writingService.WriteFile(Path.Combine(_context.BasePath, template.OutputPath), template.TransformText()); }
public static string GetLayoutTemplatePath(LayoutTemplate layoutTemplate) { return(GetRootPath() + "/LayoutTemplate/" + layoutTemplate.ImageUri); }
/// <summary> /// Saves the specified layout template /// </summary> /// <param name="sStartupPath">The path containing the templates folder</param> /// <param name="zLayoutTemplate">The template to save</param> /// <returns>true on success, false otherwise</returns> public bool SaveLayoutTemplate(string sStartupPath, LayoutTemplate zLayoutTemplate) { var sLayoutsPath = Path.Combine(sStartupPath, LAYOUT_TEMPLATES_FOLDER); try { if (!Directory.Exists(sLayoutsPath)) { Directory.CreateDirectory(sLayoutsPath); } var sFileName = ReplaceNonFileSafeCharacters(zLayoutTemplate.Layout.Name); var sOutput = Path.Combine(sLayoutsPath, sFileName) + "." + LAYOUT_TEMPLATE_EXTENSION; return SerializationUtils.SerializeToXmlFile(sOutput, zLayoutTemplate, XML_ENCODING); } catch (Exception e) { Logger.AddLogLine("Error saving LayoutTemplate: {0}".FormatString(e.Message)); throw; } return false; }
public void LayoutView_Template_NullParameter_Test() { var template = new LayoutTemplate(null); Assert.Throws <NullReferenceException>(() => template.TransformText()); }
public static void UpdateLegend(ProductColorTable[] colors, Action <int, string> percentProgress) { string path = System.AppDomain.CurrentDomain.BaseDirectory + "LayoutTemplate"; if (!Directory.Exists(path)) { return; } string[] files = Directory.GetFiles(path, "*.gxt", SearchOption.AllDirectories); if (files == null || files.Length == 0) { return; } for (int i = 0; i < files.Length; i++) { string fname = files[i]; ILayoutTemplate template = LayoutTemplate.LoadTemplateFrom(fname); //LayoutTemplate.LoadTemplateFrom(fname); if (template == null) { return; } if (percentProgress != null) { percentProgress((int)((i + 1) * 100f / files.Length), ""); } ILayout layout = template.Layout; bool haUpdate = false; for (int e = 0; e < layout.Elements.Count; e++) { if (layout.Elements[e] is ILegendElement) { ILegendElement legendEle = layout.Elements[e] as ILegendElement; string colotName = legendEle.ColorTableName; if (!string.IsNullOrWhiteSpace(colotName)) { ProductColorTable colorTable = ProductColorTableFactory.GetColorTable(colotName); if (colorTable != null) { List <LegendItem> items = new List <LegendItem>(); foreach (ProductColor pc in colorTable.ProductColors) { if (!pc.DisplayLengend) { continue; } LegendItem item = new LegendItem(pc.LableText, pc.Color); items.Add(item); } legendEle.LegendItems = items.ToArray(); haUpdate = true; } } } } if (haUpdate) { template.SaveTo(fname); } } }
private ILayoutTemplate GetTemplateByName(string templateName) { ILayoutTemplate t = LayoutTemplate.FindTemplate(templateName); return(t); }