How to get the mouse coords on the scaled dxfimage

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

Moderators: SDS, support, admin

Post Reply
mangchy
Posts: 15
Joined: 08 Nov 2005, 03:06

How to get the mouse coords on the scaled dxfimage

Post by mangchy » 08 Nov 2005, 03:06

Hi!
I use the CADImportVCL.
mouse coords exact display in scale 1.0

TsgDXFImage *sgDXFImage = dynamic_cast<TsgDXFImage *>(sgPaintBox->Picture->Graphic);
RECT vRect = sgPaintBox->PictureRect();
TFPoint vPoint = sgDXFImage->GetCADCoords(X * 1.0 / (vRect.right - vRect.left), 1 - Y * 1.0 / (vRect.bottom - vRect.top));
TVarRec v[] = {vPoint.X, vPoint.Y};
StatusBar1->Panels->Items[1]->Text = Format("(%.3f; %.3f; 0.000)", v, 1);


but I cannot calculate mouse moving coords in the scaled dxfimage.



and I want to make the function such as clip rectangle in ABViewer.

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

Post by support » 08 Nov 2005, 18:56

Hello!

There are some peculiarities for 3D rounded drawings. For example it can be seem that it is not rounded but actually axis OY is directed to you instead of axis OZ.
Could you please send to us CAD file with which problems occur.

CADImportVCL (available on: http://www.cadsofttools.com/download/CADImportVCL.zip) includes in CADImportVCL\Delphi\Demos\Viewer Viewer demo with example of clipping of the rectangle in global drawing coordinates. It starts from the following string in Unit1.pas:

Code: Select all

 procedure TForm1.sbDrawingBoxClick(Sender: TObject);-)
Sergey.

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

mangchy
Posts: 15
Joined: 08 Nov 2005, 03:06

Post by mangchy » 09 Nov 2005, 16:04

thank you, but I ask some question.

I devlope using C++ Builder.
The first, oping a dxf file, I want to get a dxfimage of the over 200 zoomin centering a point.

TPoint tp = MakePoint(200, 100);
ChangeScale(true, 200, tp);

but not display any image.
so, slow zoomin... show image of the exact point..

What to do?
Please help...

and I conversion from delphi code to builder..
but I cannot get the mouse coords of the dxfimage.

//-------------------------------------------------------------------

Code: Select all

TFPoint <b>__fastcall</b> TForm1::GetRealPointUsingsgImagePoint(TsgImage *AsgImage, int X, int Y)
{
    TRect vRect;
    TFPoint Result;

    <b>if</b>(!AsgImage->Picture->Graphic)
    {
      Result = MakeFPoint(0, 0, 0);
      exit;
    }
    vRect = AsgImage->PictureRect();
    <b>if</b>(((TsgDXFImage *)AsgImage->Picture->Graphic)->Converter->IsCrossoverMatrix)
    {
      <b>if</b> (((vRect.Right - vRect.Left) <= AsgImage->Width) || ((vRect.Bottom - vRect.Top) <= AsgImage->Height))
        Result = ((TsgDXFImage *)AsgImage->Picture->Graphic)->GetCADCoords(X / (vRect.Right - vRect.Left),
                                                                    (AsgImage->Height - Y) / (vRect.Bottom - vRect.Top));
      <b>else</b>
        Result = ((TsgDXFImage *)AsgImage->Picture->Graphic)->GetCADCoords((-(vRect.Left  - AsgImage->Left) + X) / (vRect.Right - vRect.Left),
                                                                    1 - (Y - (vRect.Top - AsgImage->Top)) / (vRect.Bottom - vRect.Top));
    }
    <b>else</b>
    {
      <b>if</b> (((vRect.Right - vRect.Left) <= AsgImage->Width) || ((vRect.Bottom - vRect.Top) <= AsgImage->Height))
        Result = ((TsgDXFImage*)AsgImage->Picture->Graphic)->GetCADCoords(X / (vRect.Right - vRect.Left),
                                                                    Y / (vRect.Bottom - vRect.Top));
      <b>else</b>
        Result = ((TsgDXFImage*)AsgImage->Picture->Graphic)->GetCADCoords((-(vRect.Left  - AsgImage->Left) + X) / (vRect.Right - vRect.Left),
                                                                    (Y - (vRect.Top - AsgImage->Top)) / (vRect.Bottom - vRect.Top));
    }

    <b>return</b> Result;
}
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by support</i>
<br />Hello!

There are some peculiarities for 3D rounded drawings. For example it can be seem that it is not rounded but actually axis OY is directed to you instead of axis OZ.
Could you please send to us CAD file with which problems occur.

CADImportVCL (available on: http://www.cadsofttools.com/download/CADImportVCL.zip) includes in CADImportVCL\Delphi\Demos\Viewer Viewer demo with example of clipping of the rectangle in global drawing coordinates. It starts from the following string in Unit1.pas:

Code: Select all

 procedure TForm1.sbDrawingBoxClick(Sender: TObject);-)
Sergey.

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

<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

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

Post by support » 10 Nov 2005, 10:55

Hello,

The following come must help you:

CPP Builder:

Code: Select all

TFPoint GetRealPointUsingsgImagePoint(TsgImage * AsgImage, int X, int Y)
{
  TRect vRect;
  TFPoint res;
  TsgDXFImage * vImg;
  int W, H, L, T;
  bool bMore;

  <b>if</b> (AsgImage->Picture->Graphic->InheritsFrom(<b>__classid</b>(TsgDXFImage)))
  {
    vRect = AsgImage->PictureRect();
    vImg = <b>dynamic_cast</b><TsgDXFImage *>(AsgImage->Picture->Graphic);
    W = vRect.Right - vRect.Left;
    H = vRect.Bottom - vRect.Top;
    L = vRect.Left - AsgImage->Left;
    T = vRect.Top - AsgImage->Top;
    bMore = ((W <= AsgImage->Width) || (H <= AsgImage->Height));
    <b>if</b> (vImg->Converter->IsCrossoverMatrix)
    {
      <b>if</b> (bMore)
        res = vImg->GetCADCoords(float(X) / W, (AsgImage->Height - Y) / float(H));
      <b>else</b>
        res = vImg->GetCADCoords(float(-L + X) / W, 1 - (Y - T) / float(H));
    }
    <b>else</b>
    {
      <b>if</b> (bMore)
        res = vImg->GetCADCoords(float(X) / W, Y / float(H));
      <b>else</b>
        res = vImg->GetCADCoords(float(-L + X) / W, (Y - T) / float(H));
    }
  }
  <b>else</b>
    res = MakeFPoint(0, 0, 0);
  return res;
}
Sergey

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

mangchy
Posts: 15
Joined: 08 Nov 2005, 03:06

Post by mangchy » 10 Nov 2005, 11:16

wow!!!
thank you~
good work!



<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by support</i>
<br />Hello,

The following come must help you:

CPP Builder:

Code: Select all

TFPoint GetRealPointUsingsgImagePoint(TsgImage * AsgImage, int X, int Y)
{
  TRect vRect;
  TFPoint res;
  TsgDXFImage * vImg;
  int W, H, L, T;
  bool bMore;

  <b>if</b> (AsgImage->Picture->Graphic->InheritsFrom(<b>__classid</b>(TsgDXFImage)))
  {
    vRect = AsgImage->PictureRect();
    vImg = <b>dynamic_cast</b><TsgDXFImage *>(AsgImage->Picture->Graphic);
    W = vRect.Right - vRect.Left;
    H = vRect.Bottom - vRect.Top;
    L = vRect.Left - AsgImage->Left;
    T = vRect.Top - AsgImage->Top;
    bMore = ((W <= AsgImage->Width) || (H <= AsgImage->Height));
    <b>if</b> (vImg->Converter->IsCrossoverMatrix)
    {
      <b>if</b> (bMore)
        res = vImg->GetCADCoords(float(X) / W, (AsgImage->Height - Y) / float(H));
      <b>else</b>
        res = vImg->GetCADCoords(float(-L + X) / W, 1 - (Y - T) / float(H));
    }
    <b>else</b>
    {
      <b>if</b> (bMore)
        res = vImg->GetCADCoords(float(X) / W, Y / float(H));
      <b>else</b>
        res = vImg->GetCADCoords(float(-L + X) / W, (Y - T) / float(H));
    }
  }
  <b>else</b>
    res = MakeFPoint(0, 0, 0);
  return res;
}
Sergey

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

[/quote]

Post Reply