Dynamic rendering
In the process of CAD drawing graphics, we need to be able to dynamically observe the drawing process, in the process of dynamic drawing will not change the graphics class, but can dynamically set the size and direction of the graphics, which can help users draw the target graphics more quickly.
Dynamic drawing function
In the previous section, we introduced that in the process of drawing graphics we will use the MxCADUiPrBase class to achieve UI interaction, which provides a method setUserDraw(), which is to solve the above requirements to achieve dynamic drawing function.
We set the dynamic drawing call object of the interaction by calling the setUserDraw() method in the MxCADUiPrBase class. There, setUserDraw() has two callback parameters:
currentPoint: currentPoint is a McGePoint3d point object whose return value is the coordinates of the point where the current mouse is located.
PWorldDraw: pWorldDraw object for a McEdGetPointWorldDrawObject dynamic draw calls, can be set up according to user's dynamic target figure drawn, but drawing the image using the object dynamic object in the end the call would be fully cleared.
import { MxCADUiPrPoint, McDbLine } from "mxcad"
const getPoint = new MxCADUiPrPoint()
getPoint.go().then((point)=> {
getPoint.setUserDraw((pt, pw)=> {
// pt:currentPoint is the coordinate of the mouse's position on the drawing
// pw:pWorldDraw is an object that provides some dynamic drawing methods
if(! point) return
const line =new McDbLine(point ,pt)
// A line is drawn dynamically
pw.drawMcDbEntity(line)
})
// The callback function in the dynamic drawing function above executes while waiting for the mouse click
getPoint.go()
})
Function function
We can export functions starting with draw directly from mxcad, and each function corresponds to a dynamic drawing function. These functions have some command line interaction (input parameters, keywords), similar to most CAD drawing functions, we can call these functions through the default command, or you can choose to export calls. Specific operation may refer to command line tutorial.
mxcad provides a list of functions and commands for interactive drawing of corresponding graphs: The | function | command | describes | |------|------|------| | drawLine | Mx_Line | draws a line | | drawArc | Mx_Arc | Draws an arc | | drawCircle | Mx_Circle | draws a circle | | drawEllipse | Mx_Ellipse | Draws the ellipse | | drawEllipticalArc | Mx_EllipseArc | Draws the elliptic arc | | drawMText | | draws multiple lines of text | | drawText | | draws multiple lines of text | | drawPolygon | Mx_Polygon | Draws a regular polygon | | drawPolyLine | Mx_Pline | draws a polyline | | drawRectang | Mx_Rectang | draws the rectangle |
Tip
In the case of ESM modularity, you need to introduce the corresponding function in order to invoke the corresponding command. : : :
Demo
Effect:
On the CLI, enter the Mx_Arc command and press Enter to execute the command
Then draw the arc according to the prompt steps output from the command line