Two questions

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

Moderators: SDS, support, admin

Post Reply
prodriguezdlt
Posts: 49
Joined: 06 Feb 2008, 03:26
Location: Mexico

Two questions

Post by prodriguezdlt » 18 Mar 2008, 04:44

hi sergey, i was wondering, is there any way to select an entity by knowing his layer and his coordinates? i mean without clicking it! just with a function that could select by givin his coord's and parent layer, thanks!

Pavel

Everything is Posible!

prodriguezdlt
Posts: 49
Joined: 06 Feb 2008, 03:26
Location: Mexico

Post by prodriguezdlt » 18 Mar 2008, 04:46

oh and sorry about the topic tittle, it was a mistake :)

Everything is Posible!

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

Post by support » 19 Mar 2008, 16:34

Hi Pavel,

<b>sgSManager.pas</b> - new procedure:

Code: Select all

  TsgSelectionManager = <b>class</b>(TObject)
...
  <b>public</b>
...
    <b>procedure</b> SelectForPavel(<b>const</b> CADPoint: TFPoint; LayerName: <b>String</b>);
...

<b>procedure</b> TsgSelectionManager.SelectForPavel(<b>const</b> CADPoint: TFPoint;
  LayerName: <b>String</b>);
<b>var</b>
  Pos: Integer;
  vCurrentPoint: TFPoint;
  vPoint: TPoint;
  FSelectedObject: TsgDXFEntity;
<b>begin</b>
  vPoint := FImg.GetPoint(CADPoint);
  FSelectedObject := <b>nil</b>;
  ClearSelection;
  FSChanged := False;
  FSelectedObject := FindEntity(vPoint);
  <b>if</b> ((FSelectedObject <> <b>nil</b>) and (FSelectedObject.Layer.Name = LayerName)) <b>then
  begin</b>
    Pos := InList(FSelectedObject);
    <b>if</b> Pos < 0 <b>then</b>
      FEntities.Add(FSelectedObject)
    <b>else
    begin</b>
      FSChanged := False;
      <b>begin</b>
        FEntities.Delete(Pos);
        FEntities.Capacity := FEntities.Capacity - <font color="blue">1</font id="blue">;
        FSChanged := True;
      <b>end</b>;
    <b>end</b>;
  <b>end</b>;
  DrawSelection;
  FSChanged := False;
  FSelection := False;
<b>end</b>;
<b>fMain.pas</b> - new button and OnClick event:

Code: Select all

<b>procedure</b> TfmMain.btnSelectByLayerClick(Sender: TObject);
<b>begin</b>
  FManager.SelectForPavel(MakeFPoint(<font color="blue">840</font id="blue">,<font color="blue">300</font id="blue">,<font color="blue">0</font id="blue">),<font color="blue">'0'</font id="blue">); //<i>MakeFPoint</i> - set here known coordinates
<b>end</b>;
Sergey

prodriguezdlt
Posts: 49
Joined: 06 Feb 2008, 03:26
Location: Mexico

Re: Two questions

Post by prodriguezdlt » 08 May 2008, 07:34

hi... when i select an entity with the mouse and using sgSmanager.pas....i get the entity selectend and then i get his coord's with this :

FPoint:=(Img.GetRealimagePoint(TsgDXFCircle(Entity).Point))

so that way im geting the same coord's as if i load the cad file on Autocad and go to properties and search for the 'x' an 'y' vert...so...its great.

But...the problem is that when i use this procedure "selectforpavel" givin the coords that i gettet with getrealimagepoint it doesnt work....

i modified the selecforpavel procedure and added a message so i can get the coordinetes of the object that manages to select(or that is trying)...with this message:

showmessage(floattostr((FImg.GetRealimagePoint(TsgDXFInsert(FSelectedObject).point)).x)+' , '+floattostr((FImg.GetRealimagePoint(TsgDXFInsert(FSelectedObject).point)).y));

maybe not the best way of getting the coords but the thing is that it doesnt work selectforpavel using GetrealimagePoint ....i must say that i want to use getrealimagepoint coords because are the only that gives me the exact same coords that autocad gives me....
please help me get to work any way to select an object by knowing his coord but using the coords that getrealimagePoint gave me.....

Thanks...Cheers

Pavel
Everything is Posible!

prodriguezdlt
Posts: 49
Joined: 06 Feb 2008, 03:26
Location: Mexico

Re: Two questions

Post by prodriguezdlt » 08 May 2008, 07:41

with the show message i meant to say that i putted in selectforpavel so i can see the result and trying to get why it didnt select the image so select for pavel is as it follows:

Code: Select all

procedure TsgSelectionManager.SelectForPavel(const CADPoint: TFPoint;
  LayerName: String);
var
  Pos: Integer;
  vCurrentPoint: TFPoint;
  vPoint: TPoint;
  FSelectedObject: TsgDXFEntity;
begin
  vPoint := FImg.GetPoint(CADPoint);
  FSelectedObject := nil;
  ClearSelection;

  FSChanged := False;
  FSelectedObject := FindEntity(vPoint);
  if ((FSelectedObject <> nil) and (FSelectedObject.Layer.Name = LayerName)) then
  begin
    showmessage('funciona');
    Pos := InList(FSelectedObject);
    if Pos < 0 then
      FEntities.Add(FSelectedObject)
    else
    begin
      FSChanged := False;
      begin
        FEntities.Delete(Pos);
        FEntities.Capacity := FEntities.Capacity - 1;
        FSChanged := True;
      end;
    end;
  end;
  showmessage(floattostr((FImg.GetRealimagePoint(TsgDXFInsert(FSelectedObject).point)).x)+' F '+floattostr((FImg.GetRealimagePoint(TsgDXFInsert(FSelectedObject).point)).y));
  DrawSelection;
  FSChanged := False;
  FSelection := False;
  Form1.ActGrid(FselectedObject);
end;
the result wher this
if i call selectfor pavel with the coords x:=732642.918137601 y:=2303276.83890593

The messagebox i receive says:

732640.918137601 2303283.81208184


so its definately trying to select another entity or something....please help me Sergey
Everything is Posible!

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

Re: Two questions

Post by support » 12 May 2008, 15:50

Hi Pavel,

We will answer you soon.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

prodriguezdlt
Posts: 49
Joined: 06 Feb 2008, 03:26
Location: Mexico

Re: Two questions

Post by prodriguezdlt » 13 May 2008, 09:47

Ok, thanks :)
Everything is Posible!

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

Re: Two questions

Post by support » 14 May 2008, 09:30

Hi Pavel,
  1. Code example that we gave you uses TsgDXFImage.GetPoint:

    Code: Select all

    vPoint := FImg.GetPoint(CADPoint);
    I think it is not accidental and we use this function because of some reasons.
  2. Function TsgDXFImage.GetRealImagePoint converts incoming point (real CAD point from a drawing) to another one basing on rotation angles of the drawing and the viewport parameters. Thus TsgDXFCircle(Entity).Point gives a center of a circle exactly the same as it is stored in CAD file and FPoint:=(Img.GetRealimagePoint(TsgDXFCircle(Entity).Point)) gives the same point but converted accordingly to mentioned above parameters. This definition does not contradict with your statement that GetRealimagePoint gives you the same point as it is done in AutoCAD. Nobody knows except of AutoCAD programmers team how do inner data is being converted inside of this program and what transformations happen there. We may just make suppositions.
We suppose that using GetRealImagePoint in SelectForPavel is wrong way because of it gives a point which can't be used here.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

prodriguezdlt
Posts: 49
Joined: 06 Feb 2008, 03:26
Location: Mexico

Re: Two questions

Post by prodriguezdlt » 14 May 2008, 10:50

sorry sergey, but then why, again....with GetRealImagePoint im getting the same coords that Autocad, even with the circles, i think this is the best way of getting the coords, simply because there no other way i get the coord, the functions on DrawingNavigator for getting coords arent useful because it varies depending on the scale, on the other hand if i use functions from TSGCadImage, the getdrawing function's results are integer numbers(520,320), and the only one that gives me the floating coordinates (732643.080292438 , 2303277.04893489) is the one im using, or am i missing one? , when i use a geopositioner device and put the txt file with the coords into a dwg with auto cad, they are the same as my geoposition(device) so that are the coordinates that i want to use , because are the real geopositioned one's, and again, they are the same that when i use GetRealImagePoint......I must say in some entities they vary a lit bit(i mean just a minimum )....but most of time theyre acurately...i hope u can understand me...

Please if im missing a different way of getting this geopositioned coords, please tell me!
Everything is Posible!

prodriguezdlt
Posts: 49
Joined: 06 Feb 2008, 03:26
Location: Mexico

Re: Two questions

Post by prodriguezdlt » 14 May 2008, 10:59

I had just realized something......theres no need of usig GetrealImage....for some reason...this function isnt making any change to the coords....this:
TsgDXFCircle(Entity).Point ... i used is the one giving me the coords i need....but still....the select wont work...
Everything is Posible!

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

Re: Two questions

Post by support » 14 May 2008, 14:38

Hello Pavel,

Can you please send us your file for testing (to support@cadsofttools.com)? It is really difficult to search a solution when discussing abstract conceptions.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

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

Re: Two questions

Post by support » 21 May 2008, 15:16

Hello Pavel,

The following function selects a circle by code basing on its center point (added in to unit sgSManager):

Code: Select all

procedure TsgSelectionManager.SelectCircle(const CenterCADPoint: TFPoint;
  LayerName: String);
var
  Pos: Integer;
  FSelectedObject: TsgDXFEntity;

  function SearchCircleByCenterPoint(CADImage: TsgDXFImage; CADPoint: TFPoint): TsgDXFEntity;
  var
    I: Integer;
  begin
    for I := 0 to CADImage.Converter.Counts[csEntities] - 1 do
    begin
      if (CADImage.Converter.Sections[csEntities].Entities[I] is TsgDXFCircle) and
      ((TsgDXFCircle(CADImage.Converter.Sections[csEntities].Entities[I]).Point.X = CADPoint.X) and
      (TsgDXFCircle(CADImage.Converter.Sections[csEntities].Entities[I]).Point.Y = CADPoint.Y)) then
      begin
        Result := TsgDXFEntity((CADImage.Converter.Sections[csEntities]).Entities[I]);
        Exit;
      end
      else
        Result := nil;
    end;
  end;

begin
  FSelectedObject := nil;
  ClearSelection;
  FSChanged := False;
  FSelectedObject := TsgDXFEntity(SearchCircleByCenterPoint(FImg, CenterCADPoint));
  if ((FSelectedObject <> nil) and (FSelectedObject.Layer.Name = LayerName)) then
  begin
    Pos := InList(FSelectedObject);
    if Pos < 0 then
      FEntities.Add(FSelectedObject)
    else
    begin
      FSChanged := False;
      begin
        FEntities.Delete(Pos);
        FEntities.Capacity := FEntities.Capacity - 1;
        FSChanged := True;
      end;
    end;
  end;
  DrawSelection;
  FSChanged := False;
  FSelection := False;
end;
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply