Page 1 of 1

How to amplify an item and put the item to the center of CADEditcontrol

Posted: 02 Jun 2023, 08:47
by Beckhans
Please help me with the follow question
1. I want to highlight an object in CADEditcontrol when I select it in treeview
2. The selected object was in the center of the CADEditcontrol
3. The selected object was amplified 2 times than normal

I write code as follow ,but it didn't work,the center of CADEditcontrol was not the selected object .

var cadImg = this.cadEditorControl1.Image;
var objEntity = cadImg.Layouts[0].Entities.First(ent => ent.Handle == handle);
cadImg.IsWithoutMargins = true;
this.cadEditorControl1.ImageScale =2;
cadImg.ClearSelectCollection();
cadImg.DoSelectEntity(objEntity);
this.cadEditorControl1.Image.Center = objEntity.Box.Center;
cadEditorControl1.InvalidateImage();

How can I do it ?

Re: How to amplify an item and put the item to the center of CADEditcontrol

Posted: 02 Jun 2023, 15:45
by support
Beckhans wrote:
02 Jun 2023, 08:47
Please help me with the follow question
1. I want to highlight an object in CADEditcontrol when I select it in treeview
2. The selected object was in the center of the CADEditcontrol
3. The selected object was amplified 2 times than normal

I write code as follow ,but it didn't work,the center of CADEditcontrol was not the selected object .

var cadImg = this.cadEditorControl1.Image;
var objEntity = cadImg.Layouts[0].Entities.First(ent => ent.Handle == handle);
cadImg.IsWithoutMargins = true;
this.cadEditorControl1.ImageScale =2;
cadImg.ClearSelectCollection();
cadImg.DoSelectEntity(objEntity);
this.cadEditorControl1.Image.Center = objEntity.Box.Center;
cadEditorControl1.InvalidateImage();

How can I do it ?
Hello,
When you assign a new center to a CADImage, you simply ruin this CADImage. In your case, we suggest you look at the ViewBox function in the Editor demo of CAD .NET package (CAD .NET 14\demo_sources\EditorDemo). This function enables to fill the common box of all entities on the current layout in the entire screen. PLease, use the box of the selected entity instead of the box of all entities:

Code: Select all

public void SelectEntArea()
        {
            if (cadImage != null && cadImage.SelectedEntities[0] != null)
            {
                RectangleF r = cadPictBox.ClientRectangle;
                r.Inflate(-0.5f, -0.5f);
                r.Offset(0, -1f);
                ViewBox(cadImage.SelectedEntities[0].Box, r);
            }
        }
The ViewBox function:

Code: Select all

private DRect ViewBox(DRect box, RectangleF clientrect)
        {
            if (cadImage == null) return (DRect)clientrect;
            CADMatrix m;
            if (cadImage.NavigateDrawMatrix)
                m = (CADMatrix)cadImage.Painter.DrawMatrix.Clone();
            else
                m = (CADMatrix)cadImage.GetRealImageMatrix().Clone();
            DRect r = DRect.GetRealBox(box, m);
            double s = clientrect.Width / r.Width;
            if (r.Height * s > clientrect.Height)
                s *= (clientrect.Height / (r.Height * s));
            DPoint scale = new DPoint(s, s, s);
            if (!cadImage.NavigateDrawMatrix)
            {
                if (cadImage.GraphicsOutMode == DrawGraphicsMode.OpenGL)
                    scale.Z = -scale.Z;
                else
                    if (cadImage.Converter.IsCrossoverMatrix)
                    scale.Y = -scale.Y;
            }
            m = m.Scale(scale);
            m.EO = new DPoint(0.5 * (clientrect.Left + clientrect.Right), 0.5 * (clientrect.Top + clientrect.Bottom), 0) - m.AffinePtXMat(box.Center);
            cadImage.Painter.DrawMatrix = m;
            return DRect.GetRealBox(box, m);
        }

Also, you can have a look at the Fit function in the Editor demo.

Catherine.

Re: How to amplify an item and put the item to the center of CADEditcontrol

Posted: 21 Jun 2023, 11:30
by Beckhans
Dear Catherine
I followed your suggestion and modify my code ,but it seems not work.There is nothing change in the cadEditorControl.Shall I call some function to refresh the cadEditorControl?

Code: Select all

	var cadImg = this.cadEditorControl1.Image;
        cadImg.ClearSelectCollection();
        var objEntity = cadImg.Layouts[0].Entities.First(ent => ent.Handle == handle);
        if (objEntity != null && objEntity is CADLWPolyLine)
         {
              cadImg.DoSelectEntity(objEntity);
              RectangleF r = cadEditorControl1.ClientRectangle;
              r.Inflate(-0.5f, -0.5f);
              r.Offset(0, -1f);
              ViewBox(objEntity.Box, r);
          }

Re: How to amplify an item and put the item to the center of CADEditcontrol

Posted: 30 Jun 2023, 12:34
by support
Hello,

Please use a showrect method in CADEditorControl:

var cadImg = this.cadEditorControl.Image;
cadImg.ClearSelectCollection();
var objEntity = cadImg.CurrentLayout.Entities[0];
if (objEntity != null)
{
cadImg.DoSelectEntity(objEntity);
RectangleF r = objEntity.Box;
//r.Inflate(-0.5f, -0.5f);
//r.Offset(0, -1f);
cadEditorControl.ShowRect(r);


Kind regards,
Suraya