Showing all of drawing in viewer
zener
11/20/2006 9:51 PM
|
---|
I am using the following code to show a drawing in a display box
____________________________________________________________________________
model = DxfReader.ReadDxf(filename);
gdiGraphics3D = new GDIGraphics3D(GraphicsConfig.Default, BackColor);
gdiGraphics3D.CreateDrawables(model);
bounds = new Bounds3D();
bounds2 = bounds;
gdiGraphics3D.BoundingBox(bounds, modelTransform);
CalculateTo2DTransform();
dxf_loaded = true;
 dxf.Invalidate();
 dxf.Focus();
private Matrix4D CalculateTo2DTransform()
    {
      Matrix4D to2DTransform = Matrix4D.Identity;
      if (bounds != null)
      {
        double halfHeight = dxf.ClientSize.Height / 2;
        double halfWidth = dxf.ClientSize.Width / 2;
        to2DTransform =
          Transformation4D.Translation(translation) *
          Transformation4D.Translation(halfHeight, halfWidth, 0) *
          Transformation4D.Scaling(scaleFactor) *
          Transformation4D.Translation(-halfHeight, -halfWidth, 0) *
          DxfUtil.GetScaleTransform(
            bounds.Corner1,
            bounds.Corner2,
            bounds.Center,
            new Point3D(0d, ClientSize.Height, 0d),
            new Point3D(ClientSize.Width, 0d, 0d),
            new Point3D(ClientSize.Width / 2, ClientSize.Height / 2, 0d)
          );
      }
      gdiGraphics3D.To2DTransform = to2DTransform * modelTransform;
      screenpoint.X = 0;
      screenpoint.Y = 0;
      screenpoint.Z = 1;
      tomodelspace = to2DTransform.GetInverse() * screenpoint;
      lbl_topleft.Text = Convert.ToString((int)tomodelspace.X) + ' , ' + Convert.ToString((int)tomodelspace.Y);
      int tms1x = (int)tomodelspace.X;
      int tms1y = (int)tomodelspace.Y;
      screenpoint.X = 480;
      screenpoint.Y = 480;
      screenpoint.Z = 1;
      tomodelspace = to2DTransform.GetInverse() * screenpoint;
      int tms2x = (int)tomodelspace.X;
      int tms2y = (int)tomodelspace.Y;
      storeX1 = Convert.ToString(tms1x);
      storeX2 = Convert.ToString(tms2x);
      storeY1 = Convert.ToString(tms1y);
      storeY2 = Convert.ToString(tms2y);
      lbl_bottomright.Text = Convert.ToString((int)tomodelspace.X) + ' , ' + Convert.ToString((int)tomodelspace.Y);
      lbl_size.Text = Convert.ToString(tms2x - tms1x) + ' , ' + Convert.ToString(tms1y - tms2y);
      return to2DTransform;
    }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Although the code appears to be identical the amount of an identical drawing shown in the output box (before any mouse scrolling or panning) is around 25% for one application, for a second application around 50%. Is there any way to force a displayed dxf to be shown to the extends in the middle of the vview box, if so how do I alter the above code to achive this. (Box size is 280 by 480 pixels)
Regards  
______________________________________________________________________________
|
zener
11/21/2006 1:55 AM
|
---|
Found it - ;D
new Point3D(0d, dxf.ClientSize.Height, 0d),
new Point3D(dxf.ClientSize.Width, 0d, 0d),
new Point3D(dxf.ClientSize.Width / 2, dxf.ClientSize.Height / 2, 0d)
The ClientSize being used was that of the form (default) not the imagebox I was using to display.
Changed the code as above and all is now spot on
|
Wout
11/21/2006 2:34 AM
|
---|
Ah, great! 8) Seems you're getting the hang of using the 3D transformations!
Wout
|