public void DisplayPlacements()
{
try
{
Project oPrj = new ProjectManager().OpenProject("$(MD_PROJECTS)\\ESS_Sample_Project.elk");
if (oPrj == null || !oPrj.IsOpen)
{
return;
}
Page[] arrPages = oPrj.Pages;
Placement[] arrPlacements = null;
foreach (Page oPage in arrPages)
{
if (oPage.AllPlacements.Length > 0)
{
arrPlacements = oPage.AllPlacements;
break;
}
}
if (arrPlacements != null)
{
PreviewForm frm = new PreviewForm();
frm.Placements = arrPlacements;
frm.ShowDialog();
}
}
catch (Eplan.EplApi.Base.BaseException e)
{
Console.Out.WriteLine(e.Message);
}
}
/////////////////////
// PreviewForm.cs //
/////////////////////
internal class PreviewForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Panel pnlPreview;
private System.Windows.Forms.Panel pnlCtrls;
private Eplan.EplApi.DataModel.Placement[] _arrPalcements = null; //array of Placements to preview
private System.Windows.Forms.ToolBarButton btnZoomAll;
private System.Windows.Forms.ToolBarButton btnZoomIn;
private System.Windows.Forms.ToolBarButton btnZoomOut;
private System.Windows.Forms.ToolBarButton separator;
private System.Windows.Forms.ToolBar toolBarPreview;
private System.Windows.Forms.ToolBarButton btnDrawConenctions;
private System.Windows.Forms.ToolBarButton btnBlackWhite;
private Eplan.EplApi.HEServices.DrawingService dwgService = new Eplan.EplApi.HEServices.DrawingService();
public Eplan.EplApi.DataModel.Placement[] Placements
{
get
{
return _arrPalcements;
}
set
{
_arrPalcements = value;
if (value != null)
dwgService.CreateDisplayList(value);
}
}
public PreviewForm()
{
InitializeComponent();
this.btnZoomAll.Text = "Zoom all";
this.btnZoomIn.Text = "Zoom in";
this.btnZoomOut.Text = "Zoom out";
this.separator.Text = "Separator";
this.btnDrawConenctions.Text = "Draw connections";
this.btnBlackWhite.Text = "Black white";
}
/// Clean up any resources being used.
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
private void InitializeComponent()
{
this.pnlPreview = new System.Windows.Forms.Panel();
this.pnlCtrls = new System.Windows.Forms.Panel();
this.toolBarPreview = new System.Windows.Forms.ToolBar();
this.btnZoomAll = new System.Windows.Forms.ToolBarButton();
this.btnZoomIn = new System.Windows.Forms.ToolBarButton();
this.btnZoomOut = new System.Windows.Forms.ToolBarButton();
this.separator = new System.Windows.Forms.ToolBarButton();
this.btnDrawConenctions = new System.Windows.Forms.ToolBarButton();
this.btnBlackWhite = new System.Windows.Forms.ToolBarButton();
this.pnlCtrls.SuspendLayout();
this.SuspendLayout();
this.Resize += new System.EventHandler(this.ResizeEndHandler);
//
// pnlPreview
//
this.pnlPreview.BackColor = System.Drawing.Color.WhiteSmoke;
this.pnlPreview.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlPreview.Location = new System.Drawing.Point(0, 0);
this.pnlPreview.Name = "pnlPreview";
this.pnlPreview.Size = new System.Drawing.Size(292, 266);
this.pnlPreview.TabIndex = 0;
this.pnlPreview.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlPreview_Paint);
//
// pnlCtrls
//
this.pnlCtrls.Controls.Add(this.toolBarPreview);
this.pnlCtrls.Dock = System.Windows.Forms.DockStyle.Top;
this.pnlCtrls.Location = new System.Drawing.Point(0, 0);
this.pnlCtrls.Name = "pnlCtrls";
this.pnlCtrls.Size = new System.Drawing.Size(292, 40);
this.pnlCtrls.TabIndex = 1;
//
// toolBarPreview
//
this.toolBarPreview.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.btnZoomAll,
this.btnZoomIn,
this.btnZoomOut,
this.separator,
this.btnDrawConenctions,
this.btnBlackWhite});
this.toolBarPreview.DropDownArrows = true;
this.toolBarPreview.Location = new System.Drawing.Point(0, 0);
this.toolBarPreview.Name = "toolBarPreview";
this.toolBarPreview.ShowToolTips = true;
this.toolBarPreview.Size = new System.Drawing.Size(292, 28);
this.toolBarPreview.TabIndex = 0;
this.toolBarPreview.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBarPreview_ButtonClick);
//
// separator
//
this.separator.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// btnDrawConenctions
//
this.btnDrawConenctions.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
//
// btnBlackWhite
//
this.btnBlackWhite.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
//
// PreviewForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.pnlCtrls);
this.Controls.Add(this.pnlPreview);
this.Name = "PreviewForm";
this.Text = "Preview";
this.pnlCtrls.ResumeLayout(false);
this.ResumeLayout(false);
}
private void ResizeEndHandler(object sender, EventArgs e)
{
this.Invalidate();
this.Refresh();
}
private void pnlPreview_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (_arrPalcements != null)
{
dwgService.DrawDisplayList(e, this.ClientRectangle);
}
}
private void toolBarPreview_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button == this.btnZoomAll)
{
dwgService.ZoomAll();
}
else if (e.Button == this.btnZoomIn)
{
dwgService.ZoomIn(2.0);
}
else if (e.Button == this.btnZoomOut)
{
dwgService.ZoomOut(2.0);
}
else if (e.Button == this.btnDrawConenctions)
{
dwgService.DrawConnections = this.btnDrawConenctions.Pushed;
if (_arrPalcements != null)
dwgService.CreateDisplayList(_arrPalcements);
}
else if (e.Button == this.btnBlackWhite)
{
dwgService.DrawBlackAndWhite = this.btnBlackWhite.Pushed;
if (_arrPalcements != null)
dwgService.CreateDisplayList(_arrPalcements);
}
pnlPreview.Refresh();
}
}