CAD interactive draw straight lines (com Interface)

The user can draw a straight line at an arbitrary position controls viewport.

The main use of Function:

_DMxDrawX::DrawLine

Draw a straight line. Details are as follows:

parameter Explanation

DOUBLE dX1

X-coordinate of the starting point of the line

DOUBLE dY1

Y coordinate of the start point of the line

DOUBLE dX2

X coordinate of the end point of the line

DOUBLE dY2

Y coordinate of the end point of the line

IMxDrawCustomEntity::Draw

On the entity mapped to FIG. When generally used for dynamic drag, drag and drop at the end, to the drawing in FIG.

_DMxDrawXEvents::DynWorldDraw

Dynamic Draw event drag and drop. Details are as follows:

parameter Explanation

DOUBLE dX

X coordinate of the current mouse position

DOUBLE dY

Y coordinates of the current mouse position

IDispatch* pWorldDraw

IMxDrawWorldDraw objects for dynamically rendering

IDispatch* pData

IMxDrawCustomEntity objects, dynamic rendering data

_DMxDrawX::DrawText

Draw a single line of text. Details are as follows:

parameter Explanation

DOUBLE dPosX

X coordinate of the position of the text

DOUBLE dPosY

Y coordinate position of the character

BSTR pszText

Text string

Double dHeight

Text height

DOUBLE dRotation  

The angle of rotation of text

SHORT horizontalMode

Text horizontal alignment, 0 = kTextLeft, 1 = kTextCenter, 2 = kTextRight

SHORT verticalMode

Vertical alignment of the text, 1 = kTextBottom, 2 = kTextVertMid, 3 = kTextTop

c # Code Description implemented:

Dynamic drag and drop drawing event:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

private void DynamicDrawLine()

{

    //点取第一点

    MxDrawUiPrPoint getPt = new MxDrawUiPrPoint();

    getPt.message = "点取第一点:";

    if (getPt.go() != MCAD_McUiPrStatus.mcOk)

        return;

    //点取第二点

    MxDrawUiPrPoint getSecondtPt = new MxDrawUiPrPoint();

    getSecondtPt.message = "点取第二点:";

  

    MxDrawCustomEntity spDrawData = getSecondtPt.InitUserDraw("DrawMyLine");

    //设置point类型的属性。

    spDrawData.SetPoint("startpoint", getPt.value());

    //设置线宽

    spDrawData.SetDouble("linewidth", 5);

  

    if (getSecondtPt.go() != MCAD_McUiPrStatus.mcOk)

        return;

  

    spDrawData.Draw();

}

Dynamic draw a line:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

private void axMxDrawX1_DynWorldDraw(object sender, AxMxDrawXLib._DMxDrawXEvents_DynWorldDrawEvent e)

{

    MxDrawCustomEntity pCustomEntity = (MxDrawCustomEntity)e.pData;

    MxDrawWorldDraw pWorldDraw = (MxDrawWorldDraw)e.pWorldDraw;

    string sGuid = pCustomEntity.Guid;

  

    MxDrawPoint curPoint = new MxDrawPoint();

  

    curPoint.x = e.dX;

    curPoint.y = e.dY;

    if (sGuid == "DrawMyLine")

    {

        MxDrawPoint sPt = pCustomEntity.GetPoint("startpoint");

        double dw = pCustomEntity.GetDouble("linewidth");

        pWorldDraw.LineWidth = dw;

        pWorldDraw.DrawLine(sPt.x, sPt.y, curPoint.x, curPoint.y);

    }                       

}

Show results:

Draw straight lines by clicking on the button, trigger DrawLine () event, the user can take the start line in any position CAD controls the viewport points, and then take the end point draw a straight line. As shown below:

c#dydrawline.png

Guess you like

Origin blog.csdn.net/u013725001/article/details/93471217