mdlView_setSubstituteElemFunc(...) - Element returned for replacement are not displayed correctly

Hi all,

I have a strange behaviour when using the function "mdlView_setSubstituteElemFunc()". The code hereafter is written in a cpp file and is working except the problem described.

First, I explain what we want to do : In some conditions, when a shape is displayed, we create 5 parallels inside it to enhance its appearance (even if the "line weight" view attribute is off). In my example, the condition has been removed : in this example always a shape is displayed, we add 5 parallels to the original element.

The problem : All seems to work correctly when I execute through with the debugger, I see (in the debugger) all the informations on elements created and their geometry seems to be correct. Anyway, I have checked if pointers are correct and stable all along the process and all are ok. The callback function returns to MicroStation a new element descriptor in replacement of the old one and none of the parallels are displayed.

To verify if the returned element descriptor is taken in account, I have set the symbology of this elemdescr into specific parameters : Only the original element is displayed with the good symbology, all other are not displayed.

I have tried another experience by deleting the original element and adding only parallels: only the first element is displayed (the first parallel).

You can find hereafter the portion of the code need to understand or to check what I have wrote.

Any idea or suggestion about this problem are welcome !

 

//----------------------------------------------------------------------------
// Nom de la fonction : UpdateElement_setFunction
//
// Date : 31 mars 2014
// Auteur : Philippe HALET
// Description : This function set an element update function called
// each times Microstation displays an element in a view.
// If the element is a shape, 5 parallels are created inside.
//
// Retour : void
//
// Paramètre : -> BoolInt bActiver : TRUE to activate
//
// Modification :
//----------------------------------------------------------------------------
Public void UpdateElement_setFunction( BoolInt bActiver )
{
  mdlView_setSubstituteElemFunc( (bActiver==TRUE)?ViewFunc_SubstituteElem)UpdateElement:NULL );
}

//----------------------------------------------------------------------------
// Nom de la fonction : UpdateElement
//
// Date : 31 mars 2014
// Auteur : Philippe HALET
// Description : If the element is a shape, the displayed element is modified
// to have 5 parallel created inside the shape
//
// Retour : always return SUBSTELEM_STATUS_Normal
//
// Paramètre : <- MSElementDescrH ppNewEd :
// Paramètre : <- int* priorityP :
// Paramètre : -> IViewportP viewPortP :
// Paramètre : -> DrawPurpose drawPurpose :
// Paramètre : -> IViewContextP context :
// Paramètre : -> bool allowDefer :
// Paramètre : -> ElemHandleCP elemIterP :
//
// Modification :
//----------------------------------------------------------------------------
Private SubstituteElemStatus UpdateElement( MSElementDescrH ppNewEd, int* priorityP, IViewportP viewPortP, DrawPurpose drawPurpose, IViewContextP context, bool allowDefer, ElemHandleCP elemIterP )
{
  SubstituteElemStatus retVal = SUBSTELEM_STATUS_Normal;

  if( hiliteShapeSession( ppNewEd, elemIterP ) == TRUE )
  {
    //
    // If we are here the "hiliteShapeSession" is returning TRUE. This means that 5 parallels are
    // succesfuly created for a shape element.
    //

    // To graphicaly confirm the replacement of the element to update, we change the symbology to a specific one.
    UInt32 color=144;
    Int32 style=3;
    UInt32 weight=4;
    mdlElmdscr_setSymbology( *ppNewEd, &color, &style, &weight, NULL );
  }

  return retVal; // retVal is not changed and is always set to SUBSTELEM_STATUS_Normal
}

//----------------------------------------------------------------------------
// Nom de la fonction : hiliteShapeSession
//
// Date : 31 mars 2014
// Auteur : Philippe HALET
// Description : This function creates 5 parallels inside each shape
//
// Retour : TRUE if the element is a shape and parallels are succesfuly created
// FALSE in any other cases
//
// Paramètre : <- MSElementDescrH ppNewEd :
// Paramètre : -> MSElement *pEl
//
// Modification :
//----------------------------------------------------------------------------
Private BoolInt hiliteShapeSession( MSElementDescrH ppNewEd, ElemHandleCP elemIterP )
{
  MSElementCP pEl = elemIterP->GetElementCP();

  if( mdlElement_getType( pEl ) == SHAPE_ELM )
  {
    MSElementDescr *pShape = NULL;
    DVector3d dvRange;
    DPoint3d dpCentre;
    double dDistanceMax, dDistance;
    BoolInt bFirstParallel=TRUE;

    mdlElement_extractRange( &dvRange, pEl );

    dpCentre.x = ( dvRange.end.x + dvRange.org.x ) / 2.0;
    dpCentre.y = ( dvRange.end.y + dvRange.org.y ) / 2.0;
    dpCentre.z = ( dvRange.end.z + dvRange.org.z ) / 2.0;

    dDistanceMax = (dvRange.end.x - dvRange.org.x) / 20.0;

    mdlElmdscr_new( &pShape, NULL, pEl );
    mdlElmdscr_duplicate( ppNewEd, elemIterP->GetElemDescrCP( NULL ) );

    for( dDistance = dDistanceMax / 5.0; dDistance < dDistanceMax; dDistance += dDistanceMax / 5.0 )
    {
      MSElementDescr *pShapeParallel = NULL;

      mdlElmdscr_copyParallel( &pShapeParallel, pShape, &dpCentre, dDistance, NULL );

      mdlElmdscr_addToChain( *ppNewEd, pShapeParallel );
    }

    return TRUE; // Element is a shape and parallels are created succesfuly
  }

  return FALSE; // Element is not a shape
}

Many thanks in advance for your help !

Philippe HALET

Parents
  • Unknown said:
    The callback function returns to MicroStation a new element descriptor in replacement of the old one and none of the parallels are displayed

    In some recent discussion on this Forum, Brien Bastings commented that element descriptor chains are a problem.  Not all functions handle descriptor chains uniformly, and Brien discourages their use.

    In your case, you create a chain of parallel element descriptors, which in debug appear to be fine.  It may be that the view update function ignores chains and works only with the first element in the chain.

    Why not create an anonymous cell instead of a descriptor chain?  That way, you substitute a complex element in your view function, which the internal MDL logic should understand.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Philippe HALET 

  • Many thanks Jon! That works perfectly using an orphan cell...

    Regards,

    Philippe HALET


    Philippe HALET 

    CEO at beCAD a Gold Channel Partner

Reply Children
No Data