How to mirror an CADArc

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
rafaellippert
Posts: 15
Joined: 12 May 2016, 18:00

How to mirror an CADArc

Post by rafaellippert » 03 Oct 2019, 23:29

Hello,
Is it possible to mirror an entire entity?
I tried to do it manually in each entity, but in the arches I have some difficulty. Is there any practical way to do? What would it be like?

Thanks,
RafaelLi

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to mirror an CADArc

Post by support » 04 Oct 2019, 00:15

Hello Rafael,

Yes, it is possible to mirror an entity in the X or Y axis by applying coordinate transformation to CADEntity derivatives. You will need to use the following code:

Code: Select all

public enum CADAxis
{
    OX,
    OY,
    OZ,
}

public static float Mod(double AValue, double ABase)
{
    return (float)(AValue - (Int64)(Math.Truncate(AValue / ABase)) * ABase);
}

public static void MirrorEntityInAxis(CADImage cadImage, CADEntity entity, CADAxis axis)
{
    CADMatrix m = new CADMatrix();
    m.IdentityMat();
    DPoint vector = DPoint.One;
    double angle = 0;

    switch (axis)
    {
        case CADAxis.OX:
            vector = new DPoint(1, -1, 1);
            angle = 180;
            break;
        case CADAxis.OY:
            vector = new DPoint(-1, 1, 1);
            break;
    }
    m = m.Scale(vector);

    switch (entity.EntType)
    {
        case EntityType.Line:
            CADLine line = entity as CADLine;
            line.Point = DPoint.XMat(line.Point, m);
            line.Point1 = DPoint.XMat(line.Point1, m);
            cadImage.Converter.Loads(line);
            break;
        case EntityType.LWPolyline:
            CADLWPolyLine lwPolyline = entity as CADLWPolyLine;
            lwPolyline.Vertexes.ForEach(vertex => (vertex as CADVertex).Point = (vertex as CADVertex).Point.XMat(m));               
            cadImage.Converter.Loads(lwPolyline);
            break;
        case EntityType.Circle:
            CADCircle circle = entity as CADCircle;
            circle.Point = DPoint.XMat(circle.Point, m);
            cadImage.Converter.Loads(circle);
            break;
        case EntityType.Arc:
            CADArc arc = entity as CADArc;
            arc.Point = DPoint.XMat(arc.Point, m);
            cadImage.Converter.Loads(arc);
            arc.Extrusion = new DPoint(arc.Extrusion.X, arc.Extrusion.Y, -arc.Extrusion.Z);
            arc.StartAngle = arc.StartAngle + angle;
            arc.EndAngle = arc.EndAngle + angle;
            cadImage.Converter.Loads(arc);
            break;
        case EntityType.Spline:
            CADSpline spline = entity as CADSpline;
            if (spline.FitCount > 0)
            {
                for (int i = 0; i < spline.FitCount; i++)
                    spline.Fit[i] = DPoint.XMat(spline.Fit[i], m);
            }
            else
            {
                for (int i = 0; i < spline.ControlCount; i++)
                    spline.Controls[i] = DPoint.XMat(spline.Controls[i], m);
            }
            cadImage.Converter.Loads(spline);
            break;
        case EntityType.Insert:
            CADInsert insert = entity as CADInsert;
            insert.Point = DPoint.XMat(insert.Point, m);
            insert.Angle = Mod(-insert.Angle - 180, 360);
            if (axis == CADAxis.OX)
                insert.Scale = new DPoint(-insert.Scale.X, insert.Scale.Y, insert.Scale.Z);
            if (axis == CADAxis.OY)
                insert.Scale = new DPoint(insert.Scale.X, -insert.Scale.Y, insert.Scale.Z);
            cadImage.Converter.Loads(insert);
            break;
    }
}
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

rafaellippert
Posts: 15
Joined: 12 May 2016, 18:00

Re: How to mirror an CADArc

Post by rafaellippert » 04 Oct 2019, 00:45

Thanks!!
but, how to use this example?

Like this: ?
MirrorEntityInAxis(cadImage2, cadImage2.CurrentLayout, CADAxis.OX)

I need to Mirror vertically all the entities contained in cadImage2.CurrentLayout.
An example DXF File is attached.


Thanks,
RafaelLi
Attachments
1101.zip
(374 Bytes) Downloaded 763 times

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to mirror an CADArc

Post by support » 04 Oct 2019, 00:58

Rafael,

You should call the MirrorEntityInAxis method for each CADEntity on the current layout. For example:

Code: Select all

cadImage2.CurrentLayout.Entities.ForEach(entity => MirrorEntityInAxis(cadImage2, entity, CADAxis.OX));
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

rafaellippert
Posts: 15
Joined: 12 May 2016, 18:00

Re: How to mirror an CADArc

Post by rafaellippert » 04 Oct 2019, 01:36

Thansks,
but is now generate with entities with problems. The strokes are misaligning.
The image and DXF File is attached .

Any ideas what it might be?

Thanks,
Attachments
1101.zip
(374 Bytes) Downloaded 707 times
cadimport.png
cadimport.png (23.76 KiB) Viewed 9834 times

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to mirror an CADArc

Post by support » 04 Oct 2019, 02:18

Rafael,

Could you please specify your CAD .NET version? The latest version (14.1.0) gives the correct result (see attached).

Mikhail
Attachments
1101_mirrored.zip
The drawing 1101.dxf mirrored in the X axis using CADImport.dll 14.1.0 and MirrorEntityInAxis method.
(1.72 KiB) Downloaded 749 times
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

rafaellippert
Posts: 15
Joined: 12 May 2016, 18:00

Re: How to mirror an CADArc

Post by rafaellippert » 04 Oct 2019, 02:25

I'm using the version 12.1.20.21127

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to mirror an CADArc

Post by support » 04 Oct 2019, 02:35

rafaellippert wrote:
04 Oct 2019, 02:25
I'm using the version 12.1.20.21127
We couldn't reproduce the problem when using this version. The MirrorEntityInAxis method gives the correct result.

Could you please attach a project which reproduces the problem?

Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

rafaellippert
Posts: 15
Joined: 12 May 2016, 18:00

Re: How to mirror an CADArc

Post by rafaellippert » 04 Oct 2019, 21:05

Hello,
I downloaded the new version CadImport 14 Trial version.
However, it still has the same problem.
Attached is an example in C # with a demo project in the "DEBUG" folder.

What can I be doing wrong?

Thanks
Attachments
Teste_CADImport_EspelharWindows.zip
(939.36 KiB) Downloaded 714 times

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to mirror an CADArc

Post by support » 05 Oct 2019, 00:18

Hello Rafael,

The code I posted requires a CADImage to be drawn on a GDI+ drawing surface (Graphics object) before mirroring an entity. To draw the CADImage on a certain Graphics object, one needs to use a CADImage.Draw method which has the following definition:

Code: Select all

public void Draw(Graphics gr, RectangleF Rect);
public void Draw(Graphics gr, RectangleF Rect, System.Windows.Forms.Control control);
In case of a console application which doesn't have a form or control to draw onto, you may use a GDI+ bitmap (Bitmap object) as the drawing surface:

Code: Select all

var arq = @"1101.dxf";          
var arq2 = @"1101_virou.dxf";
var cadImage2 = CADImage.CreateImageByExtension(arq);
cadImage2.LoadFromFile(arq);

Bitmap bitmap = new Bitmap((int)cadImage2.PureExtents.Width, (int)cadImage2.PureExtents.Height);
cadImage2.Draw(Graphics.FromImage(bitmap), new RectangleF(0, 0, (int)cadImage2.PureExtents.Width, (int)cadImage2.PureExtents.Height));

cadImage2.CurrentLayout.Entities.ForEach(entity => MirrorEntityInAxis(cadImage2, entity, CADAxis.OX));
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

rafaellippert
Posts: 15
Joined: 12 May 2016, 18:00

Re: How to mirror an CADArc

Post by rafaellippert » 05 Oct 2019, 00:33

Perfect!
Now it's Working fine!


Thanks!!

rafaellippert
Posts: 15
Joined: 12 May 2016, 18:00

Re: How to mirror an CADArc

Post by rafaellippert » 05 Oct 2019, 19:48

Hello Mikhail

The example file 1101_mirrored.dxf you created has the same problem (Compacted with SevenZip).

Please see the attached GIF Video.


After clicking on the ARCs they are moved to the old position..


Thanks,
Attachments
cadImport_14_Trial.7z
(1015.27 KiB) Downloaded 724 times

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to mirror an CADArc

Post by support » 07 Oct 2019, 21:31

rafaellippert wrote:
05 Oct 2019, 19:48
Hello Mikhail

The example file 1101_mirrored.dxf you created has the same problem (Compacted with SevenZip).

Please see the attached GIF Video.


After clicking on the ARCs they are moved to the old position..


Thanks,
Thank you for the video, we could reproduce the problem with wrong position of the arcs after moving. Please note that the problem concerns only CAD .NET editor, AutoCAD displays the moved arcs correctly.

Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply