Page 1 of 2

Moving Objects

Posted: 20 Apr 2009, 10:01
by DarkEternal
Can we move objects with mouse which added by procedure AddScaledDXF?

Re: Moving Objects

Posted: 20 Apr 2009, 15:21
by support
Yes, you can.

We recommend to use AddScaledDXFEx for such purposes. It returns TsgDXFInsert object. It contains insert point which is available by Point property. It is necessary to change this point to move the whole XRef.
Here goes a sequence of actions for a common way to solve this task:
  1. convert mouse coordinates to CAD point on a drawing - function GetDrawingCoords;
  2. search an entitiy which contains this CAD point; we recommend to analize Box property of entities whether CAD point is inside;
  3. change entity's coordinates by the constant value;
  4. save changes - call TsgDXFImage.CurrentLayout.Converter.Loads(<CAD entity to be moved>).
Sergey.

Re: Moving Objects

Posted: 20 Apr 2009, 16:25
by DarkEternal
var
....
....
....
DXFInsert : TsgDXFInsert;
begin
.....
.....

DXFInsert :=
vGlobalCADFile.AddScaledDXFex(
TsgDXFImage(vCADFiles[k]), // TsgDXFImage object for inserting
'xx', // Name
vPt, // Position in ACAD coords
MakeFPoint(1, 1, 1), // Scale factor
0.0); // Rotation angle (degrees)


------------------------------

It gives Access Violation Error?

Re: Moving Objects

Posted: 20 Apr 2009, 16:42
by support
As we posted on April, 15th (http://www.cadsofttools.com/forum/viewt ... a4a7#p3264), we recommend to use AddScaledDXFEx if it is needed to add the same files as XRef several times:
... function AddScaledDXFEx has to be used. If a number of intersection points are more then one, the following algorithm should be used:
  1. AddScaledDXFEx returns TsgDXFInsert object, vXRefIns, for instance;
  2. TsgDXFInsert contains TsgDXFBlock;
  3. create new TsgDXFInsert object;
  4. equate vXRefIns.Block to the new TsgDXFInsert.Block;
  5. set new insert point to TsgDXFInsert.Point (next intersection point);
  6. add new TsgDXFInsert object to the file contaner.
It is very important: once loaded external file should not be added more then one time using AddScaledDXFEx.
Sergey.

Re: Moving Objects

Posted: 20 Apr 2009, 17:24
by DarkEternal
I want to use TsgDXFInsert which you suggest.
But I ask you to erro "Access Violation".
Is It wrong?

DXFInsert :=
vGlobalCADFile.AddScaledDXFex(
TsgDXFImage(vCADFiles[k]), // TsgDXFImage object for inserting
'xx', // Name
vPt, // Position in ACAD coords
MakeFPoint(1, 1, 1), // Scale factor
0.0); // Rotation angle (degrees)

Re: Moving Objects

Posted: 21 Apr 2009, 09:12
by support
It is wrong because one of TsgDXFImage(vCADFiles[k]) is nil. Please check this array for a correct usage.

Sergey.

Re: Moving Objects

Posted: 21 Apr 2009, 12:32
by DarkEternal
TsgDXFImage(vCADFiles[k]) is not nil.
I did not send full code.
I put
...
...

vGlobalCADFile.AddScaledDXFex(
TsgDXFImage(vCADFiles[k]), // TsgDXFImage object for inserting
'xx', // Name
vPt, // Position in ACAD coords
MakeFPoint(1, 1, 1), // Scale factor
0.0); // Rotation angle (degrees)

work well with no error.

I am asking to using TsgDXFInsert.

when I use like it gives "Access Violation Error".

var
....
....
....
DXFInsert : TsgDXFInsert;
begin
.....
.....

DXFInsert :=
vGlobalCADFile.AddScaledDXFex(
TsgDXFImage(vCADFiles[k]), // TsgDXFImage object for inserting
'xx', // Name
vPt, // Position in ACAD coords
MakeFPoint(1, 1, 1), // Scale factor
0.0); // Rotation angle (degrees)

---------------------------

Just adding my working code DXFInsert.

Re: Moving Objects

Posted: 21 Apr 2009, 16:10
by support
Hello,

Do you mean that if using:

Code: Select all

vGlobalCADFile.AddScaledDXFEx(...
everything is alright, but if using:

Code: Select all

DXFInsert := vGlobalCADFile.AddScaledDXFEx(...
you get AV?

Sergey.

Re: Moving Objects

Posted: 21 Apr 2009, 16:11
by DarkEternal
Yes?

Re: Moving Objects

Posted: 22 Apr 2009, 10:16
by support
DarkEternal wrote:Yes?
Is this a question or a confirmation?

Sergey.

Re: Moving Objects

Posted: 22 Apr 2009, 12:06
by DarkEternal
When I use Like that
I Get MEssage "ERROR ACCESS VIOLATION"
I am asking why am I get message???

Re: Moving Objects

Posted: 22 Apr 2009, 12:29
by support
Hello,

The following code was tested with your CGM files. It works:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  vFileList: TList;
  vCGMFile: TsgCGMImage;
  FImg, vXRefImg: TsgCADImage;
  I: Integer;

  function AddFileToCrosPoints(vCADContainer: TsgCADImage; vCGMImg: TsgCGMImage):TsgCADImage;
  var
  I, J, entCnt, K, L: Integer;
  ent: TsgDXFEntity;
  entPoly, entPolyCross: TsgDXFPolyline;
  vCrossPoint: TFPoint;
  vXRefIns,vInsert: TsgDXFInsert;
  entPolyVertex1, entPolyVertex2, entPolyCrossVertex1, entPolyCrossVertex2: TsgDXFVertex;

  begin
  vXRefIns := nil;
   entCnt := vCADContainer.Converter.Counts[csEntities];
    for I := 0 to entCnt - 1 do
    begin
      ent := vCADContainer.Converter.Sections[csEntities].Entities[I];
      if ((ent.EntType = cePolyline) and (ent.Color = clRed)) then
      begin
        entPoly := TsgDXFPolyline(ent);
        for J := I+1 to entCnt - 1 do
        begin
          ent := vCADContainer.Converter.Sections[csEntities].Entities[J];
          if ((ent.EntType = cePolyline) and (ent.Color = clRed)) then
          begin
            entPolyCross := TsgDXFPolyline(ent);
            for K := 0 to entPoly.Count - 2 do
            begin
              for L := 0 to entPolyCross.Count - 2 do
              begin
                entPolyVertex1 := TsgDXFVertex(entPoly.Entities[K]);
                entPolyVertex2 := TsgDXFVertex(entPoly.Entities[K+1]);
                entPolyCrossVertex1 := TsgDXFVertex(entPolyCross.Entities[L]);
                entPolyCrossVertex2 := TsgDXFVertex(entPolyCross.Entities[L+1]);
                vCrossPoint := MakeFPoint(0,0,0);
                if (IsCrossSegmentsPts(entPolyVertex1.Point, entPolyVertex2.Point,
                   entPolyCrossVertex1.Point, entPolyCrossVertex2.Point,@vCrossPoint)) then
                   if (vXRefIns = nil) then
                      vXRefIns := TsgDXFInsert(vCADContainer.AddScaledDXFEx(vCGMImg, vCGMImg.FileName,
                        vCrossPoint,
                        MakeFPoint(1,1,1),0.0))
                   else
                   begin
                       vInsert := TsgDXFInsert.Create;
                       vInsert.Block := vXRefIns.Block;
                       vInsert.Point := vCrossPoint;
                       if Assigned(vCADContainer.Converter.OnCreate) then
                         vCADContainer.Converter.OnCreate(vInsert);
                       vCADContainer.Converter.Loads(vInsert);
                       vCADContainer.CurrentLayout.AddEntity(vInsert);
                   end;
                end;
              end;
            end;
          end;
        end;
      end;
      if vInsert <> nil then
        Result := TsgCADImage(vInsert.Block.Xref.CADImage)
      else
        Result := nil;
    end;

begin
  if (FsgPaintBox <> nil) and (FsgPaintBox.Picture.Graphic is TsgCADImage) then
    FImg := TsgCADImage(FsgPaintBox.Picture.Graphic)
  else
    Exit;

  vFileList := TList.Create;

  vCGMFile := TsgCGMImage.Create;
  vCGMFile.LoadFromFile('c:\62982.cgm');
  vFileList.Add(vCGMFile);

  vCGMFile := TsgCGMImage.Create;
  vCGMFile.LoadFromFile('c:\62989.cgm');
  vFileList.Add(vCGMFile);

  vCGMFile := TsgCGMImage.Create;
  vCGMFile.LoadFromFile('c:\62995.cgm');
  vFileList.Add(vCGMFile);

  vCGMFile := TsgCGMImage.Create;
  vCGMFile.LoadFromFile('c:\629990.cgm');
  vFileList.Add(vCGMFile);
//===

  vXRefImg := TsgCADImage(AddFileToCrosPoints(FImg,vFileList[0]));
  for I := 1 to vFileList.Count - 1 do
  begin
    if vXRefImg <> nil then
      vXRefImg := TsgCADImage(AddFileToCrosPoints(vXRefImg, vFileList[I]));
  end;

  FImg.GetExtents;
  vFileList.Free;
end;
Sergey.

Re: Moving Objects

Posted: 22 Apr 2009, 12:58
by DarkEternal
Now I can find my file with that code :

TsgDXFInsert(TsgDXFImage(sgPaintBox.Picture.Graphic).Converter.Sections[csEntities].Entities[1]).Point := MakeFPoint(100,100,0);

But nothing changes on sgPaintBox;

I try sgPaintBox.Refresh Repaint Update .But nothing changed.

If I can change point with this code, I can do moving objects

What do I need for refresh?

Re: Moving Objects

Posted: 22 Apr 2009, 14:17
by support
It is necessary to call

Code: Select all

TsgDXFImage.GetExtents;
Sergey.

Re: Moving Objects

Posted: 22 Apr 2009, 14:36
by DarkEternal
But I use

var
sgPaintBox: TsgDrawingNavigator;

So I try

TsgDXFImage(sgPaintBox.Picture.Graphic).GetExtents;

But again nothing changed?