Show drawing gradually

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
jasonz_2003
Posts: 24
Joined: 13 Apr 2006, 16:20

Show drawing gradually

Post by jasonz_2003 » 13 Apr 2006, 16:26

HI,

I am new to Cbuilder. I am trying to use cadimportvcl5 to develop a CNC control program. In the program, I deen to draw the DXF curves at a set speed to simulate the actual maching toolpath. Could you please guide me by sending me a brief script? Thanks.

Jason

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

Post by support » 17 Apr 2006, 15:35

Hello,

Our product CADImportVCL is created with Delphi. Also it can be used in C++Builder. CADImportVCL includes DXFImage.pas where you can find examples of drawing entities (DrawArc, DrawCircle, DrawSpline etc.). This file lays in correspondent Lib folders:
<ul> <li>for Delphi - ...\cadimportvcl\Delphi\Lib...\.. </li>
<li>for C++Builder - ...\cadimportvcl\CBuilder\BCB...\Lib\.. </li></ul>
We would like you to pay attention on CADImporterDLL (available on: http://www.cadsofttools.com/download/cadimporterdll.zip) if Delphi is not familiar to you. CADImporterDLL gives access to entity's data. The drawing occurs in function DoDraw() (see it in ..\cadimporterdll\Include\sg.cpp).

Sergey.

please post questions to the forum or write to support@cadsofttools.com

jasonz_2003
Posts: 24
Joined: 13 Apr 2006, 16:20

Post by jasonz_2003 » 18 Apr 2006, 18:13

Hi Sergey,

I have checked DoDraw(). But my problem is that since I am doing a simulation of machining toolpath, even with a Line I need the full set of interpolation points (or DashDots) so as to simulate the machine tool going through the Line. When I check DoDraw(), with a Line, even if the Drawmode set to 0, there are still only 2 DashDots. Same with DXFLWPolyline. I guess if I change the Style? of the Line Entity to non_Solid, I wil get the full set of DashDots? If it is true, please guide me how I can change it in the program (hopefully do not change the DXF file itself). Thanks.

Jason

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

Post by support » 20 Apr 2006, 12:12

Hello Jason,

When DoDraw() gets LINE entity DATA.Point1 and DATA.Point2 contain StartPoint and EndPoint. There is no difference what style this line has (solid, dashdot, dashdashdot etc.) These fields have StartPoint and EndPoint EVER.
DATA.DashDots contains a list of segments to which LINE entity is split according to its style (pairs of points: DATA.DashDots and DATA.DashDots[i+1]).
Wneh line is solid:
DATA.Point1 equal DATA.DashDots[0] - StartPoint
DATA.Point2 equal to DATA.DashDots[1] - EndPoint
When line is not solid:
DATA.Point1 equals DATA.DashDots[0]
DATA.Point2 is NOT equal to DATA.DashDots[1]
This is the difference between these fields.

If I'm not mistaken you need a line as set of points (from the StartPoint to the EndPoint) for drawing this line point by point as a machining toolpath. If so we have a similar mechanism of splitting a line to sections according to its style. It is in procedure TsgLines.AddLine in sgLines.pas (in ..\cadimporterdll\DemoDelphi\.. folder).

For drawing a line point by point you may base on the following code:

// StartPoint - start line point
// EndPoint - end line point

// Call GetPoint for start point and end point of the line. GetPoint converts 3d DXFPOINT to 2D TPOINT.

DX = EndPoint.x - StartPoint.x;
DY = EndPoint.y - StartPoint.y;

Len = sqrt(DX*DX + DY*DY);

// line length, Len > 0

Step = 1;
for (int I = 0; I <= Len; I+=Step)
{
NextPoint.x = StartPoint.x + DX * Cur / Len;
NextPoint.y = StartPoint.y + DY * Cur / Len;
// draw line segment here
this->Canvas->MoveTo(StartPoint.x, StartPoint.y);
this->Canvas->LineTo(NextPoint.x, NextPoint.y);
}

Sergey.

please post questions to the forum or write to support@cadsofttools.com

jasonz_2003
Posts: 24
Joined: 13 Apr 2006, 16:20

Post by jasonz_2003 » 20 Apr 2006, 20:31

Hi Sergey,

Thanks for the help. I have got the simulation working. It works fine eith ZOOM etc. But not with Orbit3D. When I use Orbit3D to turn, does not matter in 2D or 3D space, my drawing is always turned in wrong angle and shifted. As I can not find any info about Orbit3D, have to bother you again for help. I am using CadImporterVCl and using Cavas->Polyline to draw. I'll try to shift to the DLL later on. Please help.

Jason

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

Post by support » 21 Apr 2006, 19:21

Hello Jason,

Please use the following code:

Code: Select all

<b>void __fastcall</b> TForm1::sbAnimateClick(TObject *Sender)
{
// StartPoint - start line point
// EndPoint - end line point
  <b>if</b> (sgPaintBox->Picture->Graphic==NULL) <b>return</b>;
  TsgDXFImage *Img;
  TsgDXFLine *vLine;
  <b>int</b> I, DX, DY, DZ;
  <b>double</b> Len, Step, Cur;
  TFPoint EndPoint, StartPoint, NextPoint;
  POINT pt1, pt2;
  TColor Cl = sgPaintBox->Canvas->Pen->Color;
  sgPaintBox->Canvas->Pen->Color = clRed;
  Img = <b>dynamic_cast</b><TsgDXFImage *>(sgPaintBox->Picture->Graphic);
  <b>for</b> (I= 0; I < (Img->Converter->Counts[csEntities]); I++)
  {
    // Animate the first found LINE
    <b>if</b> (Img->Converter->Sections[csEntities]->Entities[I]->ClassType() == <b>__classid</b>(TsgDXFLine))
    {
      vLine = (TsgDXFLine*)Img->Converter->Sections[csEntities]->Entities[I];
      StartPoint = vLine->Point;
      EndPoint = vLine->Point1;
      DX = EndPoint.X - StartPoint.X;
      DY = EndPoint.Y - StartPoint.Y;
      DZ = EndPoint.Z - StartPoint.Z;
      Len = sqrt(DX*DX + DY*DY + DZ*DZ);// line length, Len > 0
      pt1 = Img->GetPoint(StartPoint);
      sgPaintBox->Canvas->MoveTo(pt1.x, pt1.y);
      Step = 0.1*Len;// Step < Len
      <b>for</b> (Cur=0;Cur<=Len+0.01;Cur+=Step)//0.01 - small difference for comparison floating point variables
      {
         NextPoint.X = StartPoint.X + DX * Cur / Len;
         NextPoint.Y = StartPoint.Y + DY * Cur / Len;
         NextPoint.Z = StartPoint.Z + DZ * Cur / Len;
         // draw line segment here
         pt2 = Img->GetPoint(NextPoint);
         sgPaintBox->Canvas->LineTo(pt2.x, pt2.y);
         pt1 = pt2;
         Sleep(500);
      }
      <b>break</b>;
    }
  }
  sgPaintBox->Canvas->Pen->Color = Cl;
}
Sergey.

please post questions to the forum or write to support@cadsofttools.com

jasonz_2003
Posts: 24
Joined: 13 Apr 2006, 16:20

Post by jasonz_2003 » 22 Apr 2006, 17:36

Hi Sergey,

Thanks for your the help. But as I said in my last post, the simuletion I wrote did not work with Orbit3D. Could you please provide some info on this. Thanks..

Jason

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

Post by support » 24 Apr 2006, 19:16

Hi Jason,

3DOrbit is just a user interface for calling:

function TsgDXFImage->Rotate(TsgAxes, long double). This function rotates the whole drawing with its global coordinates. It doesn't change entities coordinates within coordinate system of the drawing. It rotates the drawing with its coordinate system.

function TsgDXFImage->Rotate(TsgAxes, long double);
Description
Performs rotation of the image on specified Angle (in degrees) around one of world coordinate axis: X= axisX , Y= axisY, Z= axisZ.

Sergey.

please post questions to the forum or write to support@cadsofttools.com

jasonz_2003
Posts: 24
Joined: 13 Apr 2006, 16:20

Post by jasonz_2003 » 04 May 2006, 02:01

Hi Sergey,

Thanks for the helps. Now a new question,

I would like the DXF drawing to be shown on a canvas of the size of the maxhining material. That is, If the material is of size 1000mm x 500mm, and the drawing(a circle for example)of size 100mm x 60mm, the circle should be show at corner of a background representing 1000mm x 500mm. The size of material should be setable by the user. I have tried the drawingBox of DXFImage, did not work. Please guide me this can be done. Please also advise How I can draw multiple copies of same DXF image on the same Canvas, as well as how to rotate the actual DXF image and then show the change. Sorry for so many questions. But only a little hint could save me days of effort. Thanks in advance.

Jason

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

Post by support » 05 May 2006, 19:11

Hi Jason,
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I would like the DXF drawing to be shown on a canvas of the size of the maxhining material. That is, If the material is of size 1000mm x 500mm, and the drawing(a circle for example)of size 100mm x 60mm, the circle should be show at corner of a background representing 1000mm x 500mm. The size of material should be setable by the user. I have tried the drawingBox of DXFImage, did not work. Please guide me this can be done.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Could you explain more in detail. Do you need to display a part of the drawing? I mean any area on the drawing (rectangular, round etc.) as VIEWPORT does. DrawingBox allows to do it. But I'd like you pay attention that coordinate are set in World Coordinate System in this case (it means that you have to know exactly what part of the drawing you nee to display).
DrawingBox cuts off everything that lays behind its (DrawingBox) borders.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Please also advise How I can draw multiple copies of same DXF image on the same Canvas, as well as how to rotate the actual DXF image and then show the change. Sorry for so many questions. But only a little hint could save me days of effort. Thanks in advance.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
It is necessary to create TsgDXFImage class object for every necessary copy. It will allow to manage them (rotate, change background color etc.) separately of each others. You can also draw TsgDXFImage.Draw to a specified rectangle. In this case the same TsgDXFImage will draw. And if you rotate a view in one object it will rotate it in all the others.

Sergey.

please post questions to the forum or write to support@cadsofttools.com

Post Reply