Move TsgDXFEntity

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

Moderators: SDS, support, admin

Post Reply
Yura
Posts: 8
Joined: 06 May 2006, 11:07

Move TsgDXFEntity

Post by Yura » 06 May 2006, 11:14

I have added by means of AddEntity a TsgDXFSpline on TsgDXFImage.
How I can move this spline on X and Y?

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

Post by support » 08 May 2006, 12:55

Hello Yura,

The following code allows moving TsgDXFSpline entity 20 pixels to the right and 20 pixels to the bottom:

Code: Select all

<b>procedure</b> TForm1.MovingTsgDXFSplineClick(Sender: TObject);
<b>var</b>
  vImg: TsgDXFImage;
  vEnt: TsgDXFEntity;
  I, vCnt: Integer;
  <b>procedure</b> MovingSpline(ASpline: TsgDXFSpline; <b>const</b> APt: TFPoint);
  <b>var</b>
    J: Integer;
    vPt: PFPoint;
  <b>begin
    for</b> J := ASpline.Controls.Count - 1 <b>downto</b> 0 <b>do
    begin</b>
      vPt := ASpline.Controls[J];
      vPt^.X := vPt^.X + APt.X;
      vPt^.Y := vPt^.Y + APt.Y;
      vPt^.Z := vPt^.Z + APt.Z;
    <b>end</b>;
    <b>for</b> J := ASpline.Fit.Count - 1 <b>downto</b> 0 <b>do
    begin</b>
      vPt := ASpline.Fit[J];
      vPt^.X := vPt^.X + APt.X;
      vPt^.Y := vPt^.Y + APt.Y;
      vPt^.Z := vPt^.Z + APt.Z;
    <b>end</b>;
    vImg.Converter.Loads(ASpline);
  <b>end</b>;

<b>begin</b>
  vImg := TsgDXFImage(sgPaintBox.Picture.Graphic);
  <b>if</b> vImg = <b>nil then</b> Exit;
  vCnt :=  vImg.Converter.Counts[csEntities];
  I := 0;
  <b>while</b> I < vCnt <b>do
  begin</b>
    vEnt := vImg.Converter.Sections[csEntities].Entities[I];
    <b>if</b> (vEnt.ClassType = TsgDXFSpline) <b>then</b>
      MovingSpline(TsgDXFSpline(vEnt), MakeFPoint(20,-20,0));
    Inc(I);
  <b>end</b>;
  sgPaintBox.Invalidate;
<b>end</b>;
<b>Note:</b> the code above will be available in a demo programm in the next update of <b>CADImportVCL</b>.

Sergey.

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

Post Reply