API Help
Eplan.EplApi.HEServices Namespace / DrawingService Class
Members Example

In This Topic
    DrawingService Class
    In This Topic
    This class allows the user to create previews of macros and other DataModel objects.
    Inheritance Hierarchy

    System.Object
       Eplan.EplApi.HEServices.DrawingService

    Syntax
    public class DrawingService 
    public ref class DrawingService 
    Remarks
    In UsingEplanAssemblies, please make sure to clean up. The DrawingService object before calling Eplan::EplApi::System::EplApplication:. The finalizer of DrawingService needs the API to be initialized for freeing the internal display list.
    Example
    The example shows how to use DrawingService for a macro preview. The example shows how the DrawingService can be used. Basically to draw EP8 objects one needs to gather objects to draw, set the properties that control service behavior and implement control's Paint event. This application displays a form with a toolbar by which the DrawingService properties (like zoom, colors, etc) can be affected.
    //prepare window macro
    WindowMacro oWindowMacro = new WindowMacro();
    oWindowMacro.Open("$(MD_MACROS)\\ENT.11043516.ema", m_oTestProject);
    
    //prepare DrawingService
    DrawingService oDrawingService = new DrawingService();
    oDrawingService.MacroPreview = true;
    oDrawingService.CreateDisplayList(oWindowMacro);
    
    //prepare preview form
    Form oForm = new Form();
    Panel oPanel = new Panel();
    oPanel.Dock = DockStyle.Fill;
    oPanel.Size = new System.Drawing.Size((int)oWindowMacro.Size.X, (int)oWindowMacro.Size.Y);
    oForm.Controls.Add(oPanel);
    oPanel.Paint += delegate(object sender, PaintEventArgs e) { oDrawingService.DrawDisplayList(e, oForm.ClientRectangle); };
    
    //show preview
    oForm.Show();
    
    
    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();
        }
    }
    
    
    
    Public Constructors
     NameDescription
    Public Constructordefault constructor.  
    Top
    Public Properties
     NameDescription
    Public PropertyIs the preview centered or not?  
    Public PropertyGets/Sets whether the preview is created with or without background.  
    Public PropertyShould the preview be shown in color or black-and-white? Warning: images are always colored, independently on a value of the property  
    Public PropertyShould the auto-connecting lines be drawn in a macro preview or not?  
    Public PropertyDetermines, whether cross references should be displayed or not.  
    Public PropertyDetermines, that the preview should show invisible objects or not ?  
    Public PropertyDetermines, that the preview should look similar to the macro preview in the GUI or not  
    Public PropertyUse of the stored thumbnail bitmap for preview macro files or not ?  
    Top
    Public Methods
     NameDescription
    Public MethodOverloaded. Creates a display list for a symbol variant. Removes the representation of previously displayed objects when creating a new list. If parameter bReturnSymbolConnectionPointsData is TRUE, return also a structure with information about the symbol variant's connection points  
    Public MethodDefault destructor.  
    Public MethodOverloaded. Draws a display list on a window. The preview is fit to the window, while keeping its aspect ratio. Only the rectangle specified by the parameter rcClientRect will be used  
    Public MethodGets the coordinates of the viewport region  
    Public MethodResets all settings of the class to standard values.  
    Public MethodAdjusts viewport to the bounding box of the objects from drawing list  
    Public MethodSets resolution of the drawn image to 100x100.  
    Public MethodFor internal use.  
    Public MethodSets the coordinates of the viewport region  
    Public MethodOverloaded. Defines resolution of the drawn image.  
    Public MethodFor internal use.  
    Public MethodFor internal use.  
    Public MethodRecalculates the view port so the complete image is displayed.  
    Public MethodRecalculates the view port to zoom into the image.  
    Public MethodRecalculates the view port to zoom out of the image.  
    Top
    See Also