Requests for Cadlib 2

1
zener
7/2/2006 10:27 AM

Hi again Wout

Thinking about the changes requested in Cadlib, thank you for your responsiveness in those change requests I have already made - such as zooming, panning.

Looking at how I plan to use your component it would be of great value if the following features are added. These are are 'wonderful' to have 'wish list', not showstoppers

1) Zoom in with wheelmouse around the current mouse position (similar to Autocad DWF viewer)

2) A routine to return the displayed rectangle co-ordinates with respect to the overall drawing when zoomed (you can get a new bounding box that changes as you pan and zoom in, but this does not change as you 'zoom out'). At the moment I am using the translation parameters and zoom click level to guess the visible entities displayed under zoomed and panned situations.

3) At any zoom level to be able to draw a primative (in line, circle, square) in GDI on the drawing surface and have that added to the DXF (probably able to be done now if I spend some time to code)

4) As mentioned the ability to work with dwg (opendwg) format

I am using your component in four applications, it is invaluable and critical for me that I carry the entire environment with me when my applications are rolled out.
I always seek to only need .Net 2 framework to be installed for my applications to work- all other necessary files are installed when the application is installed. So he next request would be

5) Do not include any dependancies (as is at present) that need to be installed as a third party application

These are wish list only requests, your CADLIB well meets my current needs

Regards-Gordon


Wout
7/2/2006 11:51 AM

Hi Gordon,

1) Zooming in on current mouse position:
Just zoom like you would normally (always around model center), but afterwards apply a correction to the translation transform. Basically you want to keep a point in model space pinned at the same point in screen space. So the procedure would be:

  • Find the model space point at the mouse position by applying the inverse transform of your complete projection transform. Use an arbitry z-coordinate as input (since rotation doesn't change this doesn't matter). You can get the inverse transform from Matrix4D.GetInverse().
  • Update the scale transform like you would normally.
  • Apply the complete new projection transform to the point you got from the first step. The point is now displaced with respect to the original screen point. By subtracting these you get the extra translation you need to do to keep the point at the same place.
Easy huh? )
Anyways, I have saved you some headache and updated the zoom/pan example: http://www.woutware.com/bin/ZoomPanExample.zip

2) Hmmm, I don't understand entirely what you want to achieve here. You could use the inverse of the projection transform and apply it to the screen corners. Then you get the 2D bounding box in model space (you're missing the z-coordinate of the input, so it's a beam rather than a box). Did you also have a look at the EntitySelector class?

3) Yuck! Again use the inverse transform of the projection transform to draw in model space! If you're in 2D mode it should all be easy.

4) Yup, definitely... will be quite some effort though. But, let me remind you I'm for hire! I have some other stuff lined up the coming period, so will not get to this feature the coming few months probably.

5) Which dependencies are you referring too? Sharp zip lib is currently the only piece of software I got externally, and that's free (but not .NET 2 yet, I'll put that on my todo-list).

Thanks!

Wout

zener
7/2/2006 11:43 PM

Absolutely Brilliiant
Thank you so much, the pan and zoom are an excellent addition

Wout
7/4/2006 11:41 AM

Hi Gordon,

I've redesigned the example a bit and incorporated a demonstration of the EntitySelector.
Download it from http://www.woutware.com/bin/ViewingExample.zip.

Thanks!

Wout

zener
7/4/2006 10:35 PM

Marvelous - really impressive

I suppose the code to get all the entities in the viewport would be something like

IList<IList<DxfEntity>> viewportEntities =
          EntitySelector.GetEntitiesInRectangle(
            model,
            GraphicsConfig.Default,
            gdiGraphics3D.To2DTransform,
             new Rectangle(0,0,ClientSize.Width,ClientSize.Height)
          );

zener
7/4/2006 10:59 PM

Actually I was wrong - I have to use the WW.Maths rectangle2d

 WW.Base.Math.Geometry.Rectangle2D rect = new WW.Base.Math.Geometry.Rectangle2D(1,1,ClientSize.Width,ClientSize.Height);

        IList<IList<DxfEntity>> closestEntities =
          EntitySelector.GetEntitiesInRectangle(
            model,
            GraphicsConfig.Default,
            gdiGraphics3D.To2DTransform,
            rect
          );

zener
7/4/2006 11:11 PM

This component is marvelous.
Is it possible to get the viewport corners in drawing units, they must be calculated by CADLIB to get all elements in the rectangle for the EntitySelector.GetEntitiesInRectangle routine.

Wout
7/4/2006 11:42 PM

Hi Gordon,

Yes, it's very easy D. Same story again: you got the coordinates in screen space, and you want the coordinates in model space. So take the to 2D projection transform, call GetInverse() on it, and apply that to the screen coordinates (EntitySelector also does that internally, that's why it has to know this transformation).

C# Code:
public Point3D ToModelSpace(Matrix4D to2DTransform, Point3D screenPoint)
{
  return to2DTransform.GetInverse() * screenPoint;
}

Note that this will only work if there's no e.g. perspective component in the transform, but your case is probably just a straight forward translation/scaling(/rotation) case.

Thanks!

Wout

zener
7/5/2006 2:08 AM

Wonderful, I will try it after lunch

I am switching between transformations in Cadlib (C#) , recursive file exporting in Progecad (VBA) and behind me a PC is relinking a set of spreadsheets and beeping for my attention every few seconds as a corrupted file is encountered.

My head is spinning and so I need to go and get some food.......

1