Page 1 of 1

Zoom to selection

Posted: 02 Sep 2006, 01:42
by Laker32
Hi Sergei!

In the editor demo the zoom box feature when you drag de mouse is disabled and a selection manager is created, how can I do to have a button with the "zoom to selection" functionality.

Posted: 04 Sep 2006, 12:53
by support
Hello Laker32!
<br /><b>Preview selected entities</b> window (<b>Selection > Preview (for some TsgDXFEntity classes)...</b> menu item) displays selected entities. For selecting several entities press <b>Shift</b> on the keyboard and select entities by left mouse click. Dragging and zooming works in both windows.
<br />Sorry for the misunderstanding if this is not what you need. If so, would you please describe in details what you have and what you need?
<br />Sergey.

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

Posted: 04 Sep 2006, 18:11
by Laker32
Thanks for the quick answer Sergey,

As you said the zoom works in both windows, but only with the mouse wheel, but the zoom box (the box that is drawn for auto zoom in the other demos) is disabled. What I want to do is to be able to select the entities and zoom to them, I mean, to see the selected entities in big size before I copy them. In this case I think this must be done with an extra button in my form.

I added some code to the sgSManager Unit to get the box I'll zoom to:

var selrect:trect;
...
selrect := GetRealEntityRect(TsgDXFEntity(FEntities[0]))
for I := 1 to FEntities.Count - 1 do
begin
vRect := GetRealEntityRect(TsgDXFEntity(FEntities));
selrect.Left:=min(vrect.Left,selrect.Left);
selrect.Top:=min(vrect.Top,selrect.Top);
selrect.Right:=max(vrect.Right,selrect.Right);
selrect.Bottom:=max(vrect.Bottom,selrect.Bottom);
end;

The next I have to do is to zoom to the selrect rect.

Posted: 06 Sep 2006, 17:06
by support
Hello Laker32!

Please make the following changes to the demo or use updated Editor available in the ..\CADImportVCL_site_beta_010906\Delphi\Demos\Editor\.. folder of the CADImportVCL beta package (avalable on: http://www.cadsofttools.com/download/CA ... 010906.zip)

Add a new button and use the following code:
[fMain.pas]:

Code: Select all

<b>procedure</b> TfmMain.sbZoomSelectionClick(Sender: TObject);
  <b>begin</b>
    FManager.ZoomSelected(sbxImageBox.Width, sbxImageBox.Height);
  <b>end</b>;
[sgSManager.pas]:

Code: Select all

// to access protected fields
  <b>type</b>
    TsgDXFImageAccess = class(TsgDXFImage);
...
<b>procedure</b> TsgSelectionManager.CalcParamsForShowPoint(<b>var</b> Location: TFPoint;
      AsgImage: TsgImage; <b>var</b> APoint: TFPoint; <b>var</b> ARect: TFRect);
<b>var</b>
  vPoint: TPoint;
  vRect: TRect;
  R: Double;
<b>begin</b>
  vPoint := FImg.GetPoint(Location);
  APoint := MakeFPoint(vPoint.X, vPoint.Y, 0);
  vRect := AsgImage.PictureRect;
  <b>if</b> AsgImage.UsePictureRect <b>then
    begin</b>
      vRect.Left := vRect.Left - AsgImage.Left;
      vRect.Right := vRect.Right - AsgImage.Left;
      vRect.Top := vRect.Top - AsgImage.Top;
      vRect.Bottom := vRect.Bottom - AsgImage.Top;
    <b>end</b>;
    ARect := MakeFRect(vRect.Left, vRect.Top, 0, vRect.Right, vRect.Bottom, 0);
    <b>if not</b> AsgImage.UsePictureRect <b>then
    begin</b>
      APoint.X := APoint.X + ARect.Left;
      APoint.Y := APoint.Y + ARect.Top;
    <b>end</b>;
//The TFRect top must be greater than bottom
  R := ARect.Top;
  ARect.Top := ARect.Bottom;
  ARect.Bottom := R;
<b>end</b>;

<b>procedure</b> TsgSelectionManager.ZoomSelected(<b>const</b> AParentWidth, AParentHeight: Double);
<b>var</b>
  vSelRect: TFRect;
  vRect: TRect;
  vPoint: TFPoint;
  vScale: Double;
  I, vRectWidth, vRectHeight: Integer;
<b>begin
  if</b> FEntities.Count < 1 <b>then</b> Exit;
  vSelRect := TsgDXFEntity(FEntities[0]).Box;
  <b>for</b> I := 1 <b>to</b> FEntities.Count - 1 <b>do</b>
    UnionFRect(vSelRect, TsgDXFEntity(FEntities[I]).Box);
  vPoint := MakeFPoint(
      0.5*(vSelRect.Left + vSelRect.Right),
      0.5*(vSelRect.Top + vSelRect.Bottom),
      0.5*(vSelRect.Z2 + vSelRect.Z1));
  vRect := TsgDXFImageAccess(FImg).GetRect(vSelRect);
  vRectHeight :=  (vRect.Bottom - vRect.Top);
  vRectWidth := (vRect.Right - vRect.Left);
  <b>if</b> vRectWidth > vRectHeight <b>then</b>
    vScale := AParentWidth / vRectWidth
  <b>else</b>
    vScale := AParentHeight / vRectHeight;
    vSelRect := FImg.Extents;
    CalcParamsForShowPoint(vPoint, sgImage, vPoint, vSelRect);
    sgImage.ShowPoint(vPoint, 100 * sgImage.Scale * vScale, vSelRect);
  <b>end</b>;
Sergey.

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

Posted: 07 Sep 2006, 21:08
by Laker32
Thanks Again Sergey!

Is just what I wanted to do!

It works fine with some entities but I tried to zoom to certain entities and apear incomplete in the screen and the scrollbars doesn't apear(like we haven't done a zoom). It looks like an update problem or something alike.

Regards,

Laker32

Posted: 08 Sep 2006, 19:07
by support
Hello Laker32!

<b>Editor</b> is a demo application. It serves just to demonstrate abilities of <b>CADImportVCL</b>. That is why is has some restrictions in functionality.
<br />If you have some important for you entities please inform us which are they and we will add their support to the demo.

Sergey.

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