CadDraw Component for Delphi5 and Kylix

Installation -

CadDraw Component

The CadDraw component is a window for displaying points, lines, and arcs. creates elements in memory for redrawing on the window.

All angle input is in ordinary decimal degrees - not radians.

Angles are measured as 3 o'clock is zero and going counter-clockwise.

This version is limited to 10000 CAD Elements.

Properties -

- Color - The current color for drawing points, lines, and arcs.
- BackgroundColor - The background color of the drawing.
- View:TDView - One of the four standard views - vTOP, vFRONT, vSIDE, vISO
- DrawMode - The current drawing pen mode on the canvas. This can be any of the Windows Delphi defined pen modes: TPenMode = (pmBlack, pmWhite, pmNop, pmNot, pmCopy, pmNotCopy, pmMergePenNot, pmMaskPenNot, pmMergeNotPen, pmMaskNotPen, pmMerge, pmNotMerge, pmMask, pmNotMask, pmXor, pmNotXor)
  The default is pmCopy;
- LineType:Integer - An integer representing one of the Windows LineTypes. The default is 0 which is a solid line;

0,1 =:psSolid;
2 =psDot;
3 =psDashDot;
4 =psDashDotDot;

- CenterX:Double - The center of the draw window in coordinates from the origin. Set this and redraw the window to shift the view in the X direction.
- CenterY:Double - The center of the draw window in coordinates from the origin. Set this and redraw the window to shift the view in the Y direction.
- PickFilter:TDFilter - default fAll; TDFilter=(fAll,fPoints,fLines,fArcs,fPointLine,fPointArc,fLineArc);
- XRotation:Double - Rotates the view around the X Axis (in decimal degrees). Will show at next redraw.
- YRotation:Double - Rotates the view around the Y Axis (in decimal degrees). Will show at next redraw.
- ZRotation:Double - Rotates the view around the Z Axis (in decimal degrees). Will show at next redraw.
- CadType:Integer - The type of CAD file for reading and writing. CDL=1; DXF=2; IGES=3; default=1;

CadDraw supports reading and writing the different file types to different degrees. CADL files are supported best. Supports points, lines, and 3D arcs, colors, line types. These are used by CadKey and most CAM systems.

DXF supports points, lines, 2D arcs, polylines, colors.

IGES supports points, lines, 2D arcs, no colors.

All of these are ascii text files.

- Layer[index]:boolean - CadDraw has drawing layers 1 through 254. You can turn visibility on or off each individual layer. Only the visible layers are draw at the redraw command;
- MousePan:Boolean - This controls whether the drawing pans across the window when the middle mouse button is held down, or the Cntrl-Left Mouse is used. The default true;
- ArcView[Index:integer]:TDView3D - Array of defined arc-views. ArcView=1 is the normal top X,Y view.

In order to draw an arc in any other view than the normal top X,Y view, you have to define that arcview first;

This version is limited to 90 different views;

We will not explain here what an arc view consists of except to say that its the same format found in a CADL text file.

- ElementCount:Integer - Read only. Returns the number of elements in memory;
- ViewSize:Double - The is what zooms the drawing in and out. The number represents the size of height (or width, whichever is smaller) that the window represents in units. For instance, if you set the size to 100 inches you will zoom way out on the drawing. If you set the size to 1 inch, you will zoom way in on the drawing.
- Elements[Index:integer]:TElement - The array of CAD elements in memory. Any element index over ElementCount is undefined.
- IsDeleted[Index:integer]:Boolean - Tags that element as deleted but does not remove it from memory. Elements tagged as deleted are not redrawn. They can be undeleted by setting to false. Deleted elements are not saved to file.

Methods:

These 6 methods only draw in the window, they don't save the elements in memory.

- procedure DrawPoint(x,y,z:double); - Draws a point at coordinates;
- procedure DrawLine(x1,y1,z1,x2,y2,z2:double) Draws a line at coordinates.
- procedure DrawArc(View:Integer;X,Y,Z,Radius,StartAngle,EndAngle:double); - Draws an arc. The View is the defined arc-view. For normal 2D drawing the view=1.
- procedure DrawPointX(Point1:TDPoint) - Same as DrawPoint except input as TDPoint.
- procedure DrawLineX(Line1:TDLine);
- procedure DrawArcX(Arc1:TDArc); 2D arcs only

These 6 methods only create the element in memory, they don't draw anything;

- procedure MakePoint(X,Y,Z:double);
- procedure MakeLine(x1,y1,z1,x2,y2,z2:double);
- procedure MakeArc(View:integer;X,Y,Z,Radius,StartAngle,EndAngle:double);
- procedure MakePointX(Point1:TDPoint);
- procedure MakeLineX(Line1:TDLine);
- procedure MakeArcX(Arc1:TDArc); 2D arcs only.

- procedure LoadFromFile(Filename:string); - Load CAD elements from a CDL, DXF, or IGS file. It uses the file format according to the file extension or the CadType property.
- procedure SaveToFile(Filename:string) - Saves CAD elements to a CDL, DXF, or IGS file. It uses the file format according to the file extension or the CadType property.
- procedure DrawElement(Index:Integer); - Draws the point, line, or arc in the element at that index in the array of elements.
- procedure Redraw - Redraws the window.
- procedure Clear - Erases the windows and draws the background in the background color. doesn't delete any elements in memory.
- procedure RotateView(X,Y,Z:double); - Rotates the drawing view around each axis. Input is in degrees around the X axis, Y axis, Z axis. The center screen coordinates stay the same.
- procedure ViewCenter(X,Y:double); - This is what pans the drawing view. This method redraws the window.
- function PixelToCoord(X,Y:Integer):TDpoint - Function for converting window pixel coordinates to drawing coordinates, according to the current view.
- function CoordToPixel(X,Y,Z:double):TPoint - Function for converting coordinates to window pixel coordinates, according to the current view.
- procedure Pick - Starts the pick procedure. CadDraw will be waiting for a mouse click in the window, and will call the OnPick Event with any element it found. Only available in Top view 1.
- procedure Pan(X,Y:Double) - Moves the drawing view incrementally by these drawing units and redraws the screen.
- procedure ClearElements - Erases all elements and frees the memory.
- procedure DrawAxis - Draws temporary intersecting lines along the X,Y, and Z axis as a visual help to know where the origin is. It is erased at the next redraw.
- procedure ZoomAll - Zooms the drawing to the extents of all the CAD elements.
  procedure ZoomHalf - Zooms out to half the scale of the present area.
- procedure ZoomDouble - Zooms in to cover twice the scale of the present area.
- procedure ZoomLast - Zooms back to whatever the last zoom was.
- procedure ZoomWindow(X1,Y1,X2,Y2:integer) - Zooms in on the drawing to the size of this pixel rectangle in the current window. The new drawing center will be where the center of this rectangle was. You would use this function if you used the mouse to make a window to zoom in.
- procedure SaveBMP(Filename:string) - Saves the drawing on the component as a bitmap file.
- procedure SaveGIF(Filename:string) - Saves the drawing on the component as a GIF bitmap file. Not available in Kylix version.
- procedure SaveJPEG(Filename:string) - Saves the drawing on the component as a JPEG bitmap file. Not available in Kylix version.
- procedure WmfToClipboard - Copies the drawing as a windows metafile to the clipboard. Not available in Kylix version.
- procedure BmpToClipboard - Copies the drawing as a bitmap to the clipboard. Not available in Kylix version.

  Events -

  - OnPick - Event is triggered when mouse button is pressed after the Pick function is called.
  - OnZoom - Event is triggered when any of the zoom commands are finished redrawing the window.
  - OnChangeView - Event is triggered before redrawing when the view is changed;

CadCalc Component

The CadCalc component is not needed for CadDraw to work. The CadCalc component provides convenient geometry calculations for finding the points of intersecting lines and arcs, constructing tangent lines and arcs, and so on.

These are all 2D calculations. In this version, all these arcs are treated as full circles when finding intersections and tangents. So the intersection points can be anywhere on the full circle.

Functions that return an integer return 0 for success and non-zero for error code.

All angle input and output is in decimal degrees.

Methods:

- function PointXYZ(X,Y,Z:double; var Point1:TDPoint):integer - Turns X,Y,Z coordinates into a TDPoint.
- function Point2Lines(Line1,Line2:TDLine; var Point1:TDPoint):Integer - Finds the intersection of two lines.
- function Point2Arcs(Arc1,Arc2:TDArc;PickPoint:TDPoint;var Point1:TDPoint):Integer - Finds the intersection of two arcs. Since there are two possibilities, it returns the point closest to PickPoint.
- function PointLineArc(Line1:TDLine;Arc1:TDArc;PickPoint:TDPoint;var Point1:TDPoint):Integer - Finds the intersection of a line and arc. Since there are two possibilities, it returns the point closest to PickPoint.
- function Points2Arcs(Arc1,Arc2:TDArc;var Point1,Point2:TDPoint):Integer - Finds the intersection of two arcs. It returns both possibilities.
- function PointArcAngle(Arc1:TDArc;Angle:Double;var Point1:TDPoint):Integer - Finds the point on an arc at an angle.
- function PointCenterArc(Arc1:TDArc;var Point1:TDPoint):Integer - Returns the center point of the arc.
- function Line2Points(Point1,Point2:TDPoint;var Line1:TDLine):Integer - Returns the line made from these two points.
- function LinePointAngle(Point1:TDPoint;Angle,Length:double;var Line1:TDLine):Integer - Returns the line starting at point1 and going at an angle for length distance.
- function LineTangentPoint(PickPoint,Point1:TDPoint;Arc1:TDArc;var Line1:TDLine):Integer -
- function LinePerpPoint(Point1:TDPoint;Line1:TDLine;var Line2:TDLine):Integer;
- function LineParPoint(Point1:TDPoint;Line1:TDLine;var Line2:TDLine):Integer;
- function LineTan2Arcs(Arc1,Arc2:TDArc;PickPoint1,PickPoint2:TDPoint;var Line1:TDLine):Integer;
- function LineTanAngle(Arc1:TDArc;Angle,Length:double;var Line1:TDLine):Integer;
- function LineOffset(Line1:TDLine;Distance:double;PickPoint:TDPoint;var Line2:TDLine):Integer;
- function ArcCenterRad(Point1:TDPoint;Radius,StartAngle,EndAngle:double;var Arc1:TDArc):Integer;
- function ArcCenterTanLine(Point1:TDPoint;Line1:TDLine;StartAngle,EndAngle:double;var Arc1:TDArc):Integer;
- function ArcCenterPoint(Point1,Point2:TDPoint;StartAngle,EndAngle:double;var Arc1:TDArc):Integer;
- function ArcCenterTanArc(PickPoint,Point1:TDPoint;Arc1:TDArc;StartAngle,EndAngle:double;var Arc2:TDArc):Integer;
- function Arc3Points(Point1,Point2,Point3:TDPoint;StartAngle,EndAngle:double;var Arc1:TDArc):Integer;
- function ArcTanLinePoint(Line1:TDLine;PickPoint,POint1:TDPoint;Radius,StartAngle,EndAngle:double;var Arc1:TDArc):Integer;
- function ArcTan2Lines(Line1,Line2:TDLine;Radius,StartAngle,EndAngle:double;PickPoint1,PickPoint2:TDPoint;var Arc1:TDArc):Integer;
- function ArcTanLineArc(Line1:TDLine;Arc1:TDArc;Radius,StartAngle,EndAngle:double;PickPoint1,PickPoint2:TDPoint;var Arc2:TDArc):Integer;
- function ArcTan2Arcs(Arc1,Arc2:TDArc;Radius,StartAngle,EndAngle:double;PickPoint1,PickPoint2:TDPoint;var Arc3:TDArc):Integer;
- function ArcTanLine2Points(Line1:TDLine;Point1,Point2:TDPoint;StartAngle,EndAngle:double;var Arc1:TDArc):Integer;
- function ArcTanArcPoint(Arc1:TDArc;PickPoint,POint1:TDPoint;Radius,StartAngle,EndAngle:double;var Arc2:TDArc):Integer;
- function ArcThrough2Points(Point1,Point2:TDPoint;Radius,StartAngle,EndAngle:double;var Arc1,Arc2:TDArc):Integer;
- function ArcBetween2Points(Point1,Point2:TDPoint;StartAngle,EndAngle:double;var Arc1:TDArc):Integer;
- function ArcTan3Lines(Line1,Line2,Line3:TDLine;PickPoint:TDPoint;StartAngle,EndAngle:double;var Arc1:TDArc):Integer;
  //*********************************
- function GetLineLength(Line1:TDLine):double;
- function GetClosestPoint(E:TElement;PickPoint:TDPoint;var Point1:TDPoint):Integer;
- function GetClosestPointLine(Line1:TDLine;PickPoint:TDPoint;var Point1:TDPoint):Integer;
- function GetClosestPointArc(Arc1:TDArc;PickPoint:TDPoint;var Point1:TDPoint):Integer;
- function FixAngle(Angle:double):double; - Changes the angle so it is within 0-360.
- function GetAngle(X1,Y1,X2,Y2:double):double; - Returns the angle from x1,y1 to x2,y2
- function GetAngle2Points(Point1,Point2:TDPoint):double; - Same with points
- function GetAngleLine(Line1:TDLine):double; - Returns angle from first endpoint to second endpoint.
- function Distance(X1,Y1,X2,Y2:double):double; - 2D distance from x1,y1 to x2,y2.
- function Distance2Points(Point1,Point2:TDPoint):double; - Same with points - Z is ignored.
- function Distance3D(Point1,Point2:TDPoint):double; 3D distance.
- function MidPoint(X1,Y1,Z1,X2,Y2,Z2:double):TDPoint; - Returns 3D Point between 2 points.
- function MidPoint2Points(Point1,Point2:TDPoint):TDPoint; - Same with points.
- function PointFromElement(E:TElement):TDPoint; - Returns a point extracted from element. If element is Line then returns first endpoint. If element is arc then returns centerpoint of arc.
- function LineFromElement(E:TElement):TDLine; - Extracts the coord array and puts it in TDLine.
- function ArcFromElement(E:TElement):TDArc; - Extracts the coord array and puts it in TDArc.
- function GetArcEndPoints(Arc1:TDArc;var Point1,Point2:TDPoint):Integer; - Returns the two endpoints of the arc.
- function GetArcLength(Radius,StartAngle,EndAngle:double):double; - Returns the length of an arc.
- function GetArcAngle(StartAngle,EndAngle:double;Direction:Integer):double; - Returns the included angle. Direction is 2=clockwise; 3=counter clockwise; default is counter clockwise;
- function MidArc(Arc1:TDArc):TDPoint; - Returns point halfway around arc.
- function CalcErr(index:integer):string; - Returns error strings for errors 900 and above.

www.i-logic.com