Entity Highlight and Fit to Zoom
![]() 12/2/2011 9:18 AM
|
---|
Hi,
two questions:
1) Is possible (End exists examples) implements entity highlight on mouse over?
2) How to implement a 'Fit to screen' function that maximize zoom for current control size? I want to use this function at loading time to show correctly the dwg and also add a 'Fit to screen' button as user tool.
Thank's very much,
marc.
|
![]() 12/2/2011 2:17 PM
|
---|
Hi Marc,
regarding your second question
Marcellus Zebra wrote:
2) How to implement a 'Fit to screen' function that maximize zoom for current control size? I want to use this function at loading time to show correctly the dwg and also add a 'Fit to screen' button as user tool.
That is simple. Calculate the bounds of the current view, possibly including a transformation matrix if the view is rotated or projected perspectively. Use C# Code: int width, height; |
![]() 12/5/2011 11:02 AM
|
---|
Hi,
Assuming you are working with Win Forms:
About 1), there is currently no canned solution to this, but there have been a few enhancements in CadLib 4.0 this week that make this easier. First you have to find out which entity the mouse is over, you can use the EntitySelector for this (already exists). Then you can use the new WireframeGraphicsCache class that's a drawables container for entities. You'll have to change the WireframeGraphicsCache.Config to use a fixed foreground color.
C# Code:       WireframeGraphicsCache wireframeGraphicsCache = new WireframeGraphicsCache( C# Code:       IWireframeGraphicsFactory graphicsFactory = gdiGraphics3D. C# Code:       WireframeGraphicsCache wireframeGraphicsCache = new WireframeGraphicsCache( |
![]() 12/5/2011 11:17 AM
|
---|
Hi rammi,
thank's very mutch.
Sorry but it is first time I works with cad and my questions can be really stupids.
I Used your code in WinFormsExtendedViewExample as:
C# Code: public void FitToScreen( |
![]() 12/5/2011 1:22 PM
|
---|
Hi Marcellus,
my fault, not yours. I mixed together two examples, but didn't test the code.
Use
C# Code:         Matrix4D scaleTransform = WW. |
![]() 12/5/2011 2:10 PM
|
---|
Thank's very mutch rammi.
Now work's good.
But, how to fix the transformation?
I apply calculated transofr with gdiGraphics3D.To2DTransform = transform; but now if I pan or zom all start from previous view!
Thank's
marc.
|
![]() 12/6/2011 5:39 PM
|
---|
Yes, if panning and zooming use the standard code of the examples each of the operations will set To2DTransform without regards of the intermediate transformation. So you'd have to rewrite that, too.
Please excuse, but in order to be more general I'll elaborate a bit now, hopefully giving more users the chance to brew their own implementation.
Linear Algebra
Let's starting with a bit of linear algebra background, I'll add a simple example later. It's usually a good idea to think of the transformation from the model space of the DXF file to the screen space of the final display as not one complex transformation, but a chain of simpler one. So if we call the matrix used for To2DTransform M, it is build from simpler transformations (eg translations, rotations and scalings):
  M = Mn * ... * M2 * M1
You'll note that the indexes are running backward, the reason for that is that CadLib is using column orders, so the order in which transformations in the chain above are applied is right to left.
It's helpful to imagine that you are in model space at the right border, and then go step by step to the left, until you reach screen space:
  screen space ← Mn ← ... ← M2 ← M1 ← model space
(you could go the other way round if you invert each transformation)
One main property of matrixes and transformations is that their multiplication (chaining) is not commutative, so in general for two matixes A and B:
  A * B ≠ B * A
  
which makes math a bit unusual, but not really complicated, you'll just need some new tricks in your toolbox.
No you want to change the transformation M, and this changes usually either happen in screen space (eg panning three pixels to the right) or in model space (panning from one entity to another). It's crucial to be clear about this space in which the change happens.
If a changing transformation C happens in screen space, this means that the previous transformation is multiplied from the left, so you get
  Mnew = Cscreen * M
If it happens in model space, it is multiplied from the right:
  Mnew = M * Cmodel
But how to apply this to a chain of transformations? As said before, you'll usually have simpler transformations put together in your chain, and if C is eg a translation, you'll want to combine it with the translation matrix in your chain. Let's call this matrix of interest T, multiply all matrixes left of it together to get a matrix L, multiply all matrixes right of it together to get a matrix R, we have the situation
  M = L * T * R
This is still perfectly general, but in some case L or R might be the indenty matrix, and could be left away.
Now back to a transformation happening in screen space:
  Mnew = C * M = C * L * T * R
This is what we have. But what we want is
  Mnew = L * Tnew * R
i.e. only T is influenced by C, the rest stays as it was before.
So we have to solve this equation
  C * L * T * R = L * Tnew * R
Remember that we cannot just exchange C and L on the left side, because that is not allowed for matrixes. But we can multiply with the inverse of R (i.e. R-1) from right on both sides, which will remove R from the equation, because R * R-1 is the identity matrix:
  C * L * T  = L * Tnew
Now we use the same trick to remove L from the right side of the equation: multiply both sides with L-1 from left (and switch sides to get a more pleasing equation):
  Tnew = L-1 * C * L * T
That is how we calculate a new matrix  Tnew in our chain when a transformation happens in screen space:
|
![]() 11/1/2016 7:47 PM
|
---|
Hello Marc
If you want to reset the object transform this is my code:
C# Code: int width = this. |
![]() 3/29/2017 6:53 PM
|
---|
Hi,
I knew this thread is old but I didn't find my issue.
At first some images:
1. with the fiting method above
2. if I perform pan
Most code is from the exmaples with some fitting to my purposes. I think the problem will come from the transformation provider and the scaling. For now it's nearly impossible to find that point where it happens (using VS2017CE) maybe with the ep edtion it esay to find ..
Rammi mentioned above "Yes, if panning and zooming use the standard code of the examples each of the operations will set To2DTransform without regards of the intermediate transformation. So you'd have to rewrite that, too."
I think this snippet is the cause of my problem:
C# Code: private Matrix4D CalculateTo2DTransform( |
![]() 3/29/2017 7:02 PM
|
---|
Which TransformationProvider are you using? The 2D one or the 3D? The 3D has some margin around the drawing by default to allow for 3D rotation within the window.
- Wout
|