There are a couple of functions in the MicroStationAPI whose documentation recommends using the ADIM_GETTYPE, ADIM_GETSUB and ADIM_GETSEG macros. For example,
ADIM_GETTYPE
ADIM_GETSUB
ADIM_GETSEG
MSCORE_EXPORT StatusInt mdlHitPath_Dimension_getParameters ( ... UInt32* partName, // complete part identifier for part of dimension located, use // ADIM_GETTYPE, ADIM_GETSUB and ADIM_GETSEG to decompose ... );
However, I don't see those macros anywhere in the MicroStationAPI header files. Is that an omission, or is there a better way to decompose a dimension part identifier?
Bump!
Regards, Jon Summers LA Solutions
Hi Jon,
Thank you for pointing out this regression. We will file a defect and update this response with the defect once filed.For now, you should be able to incorporate the following changes prior to calling, or directly within DimensionElem.h:
// MicroStation V8 SDK - ..\include\mdldim.h:131 (Public API section previously available) #define ADIM_GETTYPE(dimVar) ((byte)((dimVar & 0x000000f0) >> 4)) #define ADIM_GETSUB(dimVar) ((byte)(dimVar & 0x0000000f)) #define ADIM_GETSEG(dimVar) ((byte)((dimVar & 0x0000ff00) >> 8))
// MicroStation CONNECT SDK - ..\include\DgnPlatform\DimensionElem.h (Work-around required in CONNECT - Defect: XXXXXX) #define ADIM_GETTYPE(dimVar) (DimensionPartType)((byte)((dimVar & 0x000000f0) >> 4)) #define ADIM_GETSUB(dimVar) (DimensionPartSubType)((byte)(dimVar & 0x0000000f)) #define ADIM_GETSEG(dimVar) ((byte)((dimVar & 0x0000ff00) >> 8))
Please note the change to using enums for: DimensionPartType and DimensionPartSubType.
Given the above, you can continue to use mdlHitPath_Dimension_getParameters, or replace with e.g. hitPath->GetDimensionParameters called by mdlHitPath_Dimension_getParameters.
HitPathCP hitPath = _DoLocate(ev, true, Bentley::DgnPlatform::ComponentMode::Innermost); hitPath->GetDimensionParameters (pPartName, pPointNo, pSegment, (DimensionPartType*) pPartType, (DimensionPartSubType*) pPartSubType);
HTH,Bob
Answer Verified By: Jon Summers
I would like to add the missing information about the Defect.We have filed Defect # 903233 to address this issue.
Best regards,Artur
#define ADIM_GETTYPE(dimVar) ((byte)((dimVar & 0x000000f0) >> 4)) #define ADIM_GETSUB(dimVar) ((byte)(dimVar & 0x0000000f)) #define ADIM_GETSEG(dimVar) ((byte)((dimVar & 0x0000ff00) >> 8))
Shouldn't we move on with an implementation using C++ 11 functions rather than C-style macros? It's not hard...
byte adim_getType (UInt32 dimVar) { return (dimVar & 0x000000f0) >> 4; } byte adim_getSeg (UInt32 dimVar) { return (dimVar & 0x0000ff00) >> 8; } byte adim_getSub (UInt32 dimVar) { return (dimVar & 0x000000f); }
Wouldn't those functions work equally well in C? What is specific to C++ 11 about them?
--Piers PorterAltiva Software
Piers Porter said:Wouldn't those functions work equally well in C?
Well, I suppose they would, but who is writing MicroStation apps. using C these days? The reason that I suggested the change from macro to function is to encourage idioms that can be checked by the compiler, rather than continue with last-century practises. It's not clear why those were macros in the first place.
Piers Porter said:What is specific to C++ 11 about them?
Nothing! But the C++ compiler may choose to inline them, which is an optimisation not available to a C compiler.
However, the point I hoped to make is that a function is preferable to a macro, for several reasons. Pulling one reason out of a hat, for example, you might decide to make Adim a namespace, resulting in a set of functions similar to this …
namespace Adim { byte GetType (UInt32 dimVar) { return (dimVar & 0x000000f0) >> 4; } … }
You Could then call them like this …
byte aType = Adim::GetType (dimVar);
You can't do that with a macro.
Well, I suppose they would, but who is writing MicroStation apps. using C these days?
Me, for a start. It's the only way to write the same code that works on both MicroStation and PowerDraft.
Piers Porter said: It's the only way to write the same code that works on both MicroStation and PowerDraft.
What? Are you saying that the CONNECT MicroStationAPI doesn't let you produce code that works with PowerDraft?