| 59 | == Managed FDO API == |
| 60 | |
| 61 | The managed FDO API is a little tricky because it needs to allow the caller create managed child class and implement the coordinate system transformation in its own child class. A solution is to make a VirtualFdoCoordinateSystemTransform which inherits from VirtualObject, a template in OSGeo.Fdo.Common for forwarding unmanaged methods to managed one: |
| 62 | |
| 63 | {{{ |
| 64 | class VirtualFdoCoordinateSystemTransform : public VirtualObject <NAMESPACE_OSGEO_FDO_XML::CoordinateSystemTransform, FdoCoordinateSystemTransform> |
| 65 | { |
| 66 | public: |
| 67 | FdoIDirectPosition* CoordinateSystemTransform(FdoIDirectPosition* sourceGeometry); |
| 68 | |
| 69 | private: |
| 70 | enum WrapperCallBits |
| 71 | { |
| 72 | TransformBit = 0x01, |
| 73 | }; |
| 74 | mutable FdoInt32 wrapperCallBits; |
| 75 | }; |
| 76 | |
| 77 | FdoIDirectPosition* VirtualFdoCoordinateSystemTransform::CoordinateSystemTransform(FdoIDirectPosition* sourceGeometry) |
| 78 | { |
| 79 | if (!WrapperCallWrapper::IsCalling(wrapperCallBits, TransformBit)) |
| 80 | { |
| 81 | WrapperCallWrapper ctx(wrapperCallBits, TransformBit); |
| 82 | |
| 83 | NAMESPACE_OSGEO_GEOMETRY::IDirectPosition ^managedSourceGeometry = gcnew NAMESPACE_OSGEO_GEOMETRY::IDirectPositionImp(IntPtr(sourceGeometry), true); |
| 84 | NAMESPACE_OSGEO_GEOMETRY::IDirectPositionImp^ destGeometry = static_cast<NAMESPACE_OSGEO_GEOMETRY::IDirectPositionImp^>(GetWrapper()->CoordinateSystemTransformPosition(managedSourceGeometry)); |
| 85 | return static_cast<FdoIDirectPosition*>(destGeometry->GetDisposableObject().ToPointer()); |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | return 0; |
| 90 | } |
| 91 | } |
| 92 | }}} |
| 93 | |
| 94 | And the managed !CoordinateSystemTransform can be initialized in this way: |
| 95 | |
| 96 | {{{ |
| 97 | NAMESPACE_OSGEO_FDO_XML::CoordinateSystemTransform::CoordinateSystemTransform() : Disposable(IntPtr(new VirtualFdoCoordinateSystemTransform()), true) |
| 98 | { |
| 99 | static_cast<VirtualFdoCoordinateSystemTransform*>(GetImpObj())->SetWrapper(this); |
| 100 | } |
| 101 | }}} |
| 102 | |
| 103 | By doing this the child class of !CoordinateSystemTransform can do the coordinate system transformation. |
| 104 | |
| 105 | Above is pseudo code as a reference. Currently there is no concrete requirement in managed side, so the managed API is not added and tested. |
| 106 | |