Zoom to selection
Moderators: SDS, support, admin
Zoom to selection
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.
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.
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
<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
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.
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.
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]:
[sgSManager.pas]:
Sergey.
please post questions to the forum or write to support@cadsofttools.com
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>;
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>;
please post questions to the forum or write to support@cadsofttools.com
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
<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