<a id="easygauge-difference-legacy"></a>

# Differences with the Legacy API

This section talks about the differences between the [new API](index.html.md) of **EasyGauge** and the [legacy API](legacy_easygauge/index.html.md) and how to port an application that uses the legacy API to the new API.

* There is no internal hierarchy of gauges.
  - To link a gauge to the results of another gauge, convert the results of the parent gauge to a frame and use that frame in the children gauges.
* Calibration is no longer part of the gauge object, refer to [Calibration](../../advanced_operations/camera_calibration/index.html.md) instead.
* The center of the top left pixel of the image has the coordinates (0.5, 0.5) compared to (0, 0) in the legacy API.
* `Measure` now returns the measured shape and throws an exception if not found.
* The classes `ExxxShape` have been removed.
  - Instead, use the geometrical shapes `Exxx`.
* The **EasyGauge** classes inherits from [`EBaseGauge`](../../../doxygen_cpp/classeVision_1_1EBaseGauge.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EBaseGauge.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EBaseGauge.html)

<a id="easygauge-difference-legacy-drawing"></a>

## Differences for Drawing and Graphical Manipulation

* The quick draw and optional draw properties have been removed.
* The property “dragging mode” property has been removed. All the shapes and gauges are dragged in a way that is similar to the [`ERegion`](../../../doxygen_cpp/classeVision_1_1ERegion.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ERegion.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ERegion.html) dragging.
* Zoom and pan are now arguments of `Draw`, `HitTest`… instead of properties of the class.
* The properties “behavior filter”, “selected”, “selectable”, “active” and “visible” have been removed.
* The tolerances are drawn by calling the method `Draw` with the mode [`EDrawingMode_Tolerances`](../../../doxygen_cpp/namespaceeVision.html#a46a5eff0a429fb8f7157564a9c7e620c) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a22d98bfe7b35ea321e8d60e62e838438) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EDrawingMode.html).
  * Before, they were drawn along with the mode [`EDrawingMode_Nominal`](../../../doxygen_cpp/namespaceeVision.html#a46a5eff0a429fb8f7157564a9c7e620c) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a22d98bfe7b35ea321e8d60e62e838438) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EDrawingMode.html).
* The transition types are drawn by calling the method `Draw` with the mode [`EDrawingMode_TransitionType`](../../../doxygen_cpp/namespaceeVision.html#a46a5eff0a429fb8f7157564a9c7e620c) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a22d98bfe7b35ea321e8d60e62e838438) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EDrawingMode.html).
  * Before, they were drawn with the mode [`EDrawingMode_Nominal`](../../../doxygen_cpp/namespaceeVision.html#a46a5eff0a429fb8f7157564a9c7e620c) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a22d98bfe7b35ea321e8d60e62e838438) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EDrawingMode.html) if the optional draw was enabled.
* The `HitHandle` property has been removed.
  * Now, `HitTest` returns an edition mode corresponding to the handle under the mouse.
* The draggable and rotatable properties have been removed.
  * Use the property [`EBaseGauge::SetEditionMode`](../../../doxygen_cpp/classeVision_1_1EBaseGauge.html#a276ae543b5e097a1c1c47d82bdc80970) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EBaseGauge.html#a21b9f2a46ad89240ef3da58d25d9cb8a) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EBaseGauge.html#aa82d197b97aeb164302a0a9c4b85c7bd) to specify the enabled modes of edition.
  * Use [`EBaseGauge::GetAvailableEditionModes`](../../../doxygen_cpp/classeVision_1_1EBaseGauge.html#af0f7fc38e18ac177b387e1b454ed7eca) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EBaseGauge.html#a7ef109c887dc001fbb29abf468f64cc2) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EBaseGauge.html#a43b691978500433c9ea6f4d0430ac526) to get the list of modes supported by the gauge.

<a id="easygauge-difference-legacy-keep-using"></a>

## Keep Using the Legacy Gauge API

To keep using the legacy gauge API, prefix all the **EasyGauge** types that you use:

- In C++: with `Legacy::`
- In Python and .NET: with `Legacy.`

<a id="easygauge-difference-legacy-porting"></a>

## Porting your Application Using the Legacy Application to the New API

You must:

- If you use calibration, recalibrate your setup with [`ECameraCalibration`](../../../doxygen_cpp/classeVision_1_1ECameraCalibration.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ECameraCalibration.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ECameraCalibration.html) instead of [`EWorldShape`](../../../doxygen_cpp/classeVision_1_1Legacy_1_1EWorldShape.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1Legacy_1_1EWorldShape.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1Legacy_1_1EWorldShape.html).
- For each gauge in your hierarchy, create a corresponding new gauge and set all its parameters.
- Perform the measurement of the hierarchy by calling `Measure` on the root gauges to convert their result to a frame. Then call `Measure` on their children gauges with this frame.

For example, the legacy gauge API code

### C++

```cpp
#include <eVision/EasyGauge/Legacy/ERectangleGauge.h>
#include <eVision/EasyGauge/Legacy/ECircleGauge.h>
#include <eVision/EasyGauge/Legacy/EWorldShape.h>
```

```cpp
using namespace eVision;
// Image constructor
EImageBW8 img;
// EWorldShape constructor
Legacy::EWorldShape worldShape;
// Gauges constructor
Legacy::ERectangleGauge rectangleGauge;
Legacy::ECircleGauge circleGauge1, circleGauge2;

// Attach the rectangle gauge to the EWorldShape
rectangleGauge.Attach(&worldShape);
// Attach the circle gauges to the rectangle gauge
circleGauge1.Attach(&rectangleGauge);
circleGauge2.Attach(&rectangleGauge);

// Trigger the measurement of all the
// gauges attached to the EWorldShape
worldShape.Process(&img, true);

// Retrieve the measurement result of the rectangle gauge
float sizeX = rectangleGauge.GetMeasuredRectangle().GetSizeX();

// Retrieve the measurement result of the circle gauges
Legacy::ECircle circ1 = circleGauge1.GetMeasuredCircle();
Legacy::ECircle circ2 = circleGauge2.GetMeasuredCircle();
```

### C#

```cs
using eVision;
using Legacy = eVision.Legacy;
```

```cs
// Image constructor
EImageBW8 img = new EImageBW8();
// EWorldShape constructor
Legacy.EWorldShape worldShape = new Legacy.EWorldShape();
// Gauges constructor
Legacy.ERectangleGauge rectangleGauge = new Legacy.ERectangleGauge();
Legacy.ECircleGauge circleGauge1 = new Legacy.ECircleGauge();
Legacy.ECircleGauge circleGauge2 = new Legacy.ECircleGauge();

// Attach the rectangle gauge to the EWorldShape
rectangleGauge.Attach(worldShape);
// Attach the circle gauges to the rectangle gauge
circleGauge1.Attach(rectangleGauge);
circleGauge2.Attach(rectangleGauge);

// Trigger the measurement of all the
// gauges attached to the EWorldShape
worldShape.Process(img, true);

// Retrieve the measurement result of the rectangle gauge
float sizeX = rectangleGauge.MeasuredRectangle.SizeX;

// Retrieve the measurement result of the circle gauges
Legacy.ECircle circ1 = circleGauge1.MeasuredCircle;
Legacy.ECircle circ2 = circleGauge2.MeasuredCircle;
```

### Python

```py
import eVision
import eVision.Legacy

# Image constructor
img = eVision.EImageBW8()
# EWorldShape constructor
worldShape = eVision.Legacy.EWorldShape()
# Gauges constructor
rectangleGauge = eVision.Legacy.ERectangleGauge()
circleGauge1 = eVision.Legacy.ECircleGauge()
circleGauge2 = eVision.Legacy.ECircleGauge()

# Attach the rectangle gauge to the EWorldShape
rectangleGauge.Attach(worldShape)
# Attach the circle gauges to the rectangle gauge
circleGauge1.Attach(rectangleGauge)
circleGauge2.Attach(rectangleGauge)

# Trigger the measurement of all the
# gauges attached to the EWorldShape
worldShape.Process(img, True)

# Retrieve the measurement result of the rectangle gauge
sizeX = rectangleGauge.MeasuredRectangle.SizeX

# Retrieve the measurement result of the circle gauges
circ1 = circleGauge1.MeasuredCircle
circ1 = circleGauge2.MeasuredCircle
```

is converted to:

### C++

```cpp
#include <eVision/EasyGauge/ERectangleGauge.h>
#include <eVision/EasyGauge/ECircleGauge.h>
#include <eVision/Easy/ECameraCalibration.h>
```

```cpp
using namespace eVision;
// Image constructor
EImageBW8 img;
// Optional if no calibration is needed
ECameraCalibration calibration;

// Gauges constructor
ERectangleGauge rectangleGauge;
ECircleGauge circleGauge1, circleGauge2;

try
{
  ERectangle rect = rectangleGauge.Measure(img, calibration.ToFrame());
  ECircle circ1 = circleGauge1.Measure(img, rect.ToFrame(true, EFrameScaling_NormalizeXY));
  ECircle circ2 = circleGauge2.Measure(img, rect.ToFrame(true, EFrameScaling_NormalizeXY));
}
catch (const EException& e)
{
  // One of the measurement failed.
}
```

### C#

```cs
using eVision;
using Legacy = eVision.Legacy;
```

```cs
// Image constructor
EImageBW8 img = new EImageBW8();
// Optional if no calibration is needed
ECameraCalibration calibration = new ECameraCalibration();

// Gauges constructor
ERectangleGauge rectangleGauge = new ERectangleGauge();
ECircleGauge circleGauge1 = new ECircleGauge();
ECircleGauge circleGauge2 = new ECircleGauge();

try
{
  ERectangle rect = rectangleGauge.Measure(img, calibration.ToFrame());
  ECircle circ1 = circleGauge1.Measure(img, rect.ToFrame(true, EFrameScaling.NormalizeXY));
  ECircle circ2 = circleGauge2.Measure(img, rect.ToFrame(true, EFrameScaling.NormalizeXY));
}
catch (EException e)
{
  // One of the measurement failed.
}
```

### Python

```py
import eVision
# Image constructor
img = eVision.EImageBW8()
# Optional if no calibration is needed
calibration = eVision.ECameraCalibration()

# Gauges constructor
rectangleGauge = eVision.ERectangleGauge()
circleGauge1 = eVision.ECircleGauge()
circleGauge2 = eVision.ECircleGauge()

try:
    rect = rectangleGauge.Measure(img, calibration.ToFrame())
    circ1 = circleGauge1.Measure(img, rect.ToFrame(True, eVision.EFrameScaling.NormalizeXY))
    circ2 = circleGauge2.Measure(img, rect.ToFrame(True, eVision.EFrameScaling.NormalizeXY))
except eVision.EException:
    # One of the measurement failed.
    pass
```
