Getting ViewContext from IViewManager

Hi guys,

 On including the IViewManager.h to my application i got this error msg.

 C:\PROGRA~1\Bentley\MICROS~1\MICROS~1\mdl\MicroStationAPI\interface\IViewManager.h(126) : error C2061: syntax error : identifier 'IRedrawOperation'

I checked the function in the documentation and its like this

void DoElementAgendaDynamics (ElementAgendaP, IRedrawOperation *, ClipDescrP)

and in the header file its like this

MSCORE_EXPORT void DoElementAgendaDynamics (ElementAgendaP, IRedrawOperation*, ClipDescrP);

So both looks same but still getting the error....any idea why?

 Thanks and Regards,

Arpan

Parents
  • Please ignore the last post....i got it working.

    I got the viewPort and still trying to find out how to get the viewContext from that.

    Brien gave some hint about it in http://communities.bentley.com/Products/MicroStation/MicroStation_V8i/MicroStation_V8i_Programming/f/19569/t/47082.aspx but i didnot get what exactly he meant.

    Regards,
    Arpan

  • Arpan:
    output->DrawPointString3d (jmdlEmbeddedDPoint3dArray_getCount(pMyArray), jmdlEmbeddedDPoint3dArray_getPtr(pMyArray, 0), NULL, NULL);

    That line does exactly what you expect: it draws some points to the view. However, your computer is refreshing the screen at 50Hz, so the points are visible for only 20ms.

    If you have unusually acute eyesight, you will spot them before they are erased by your display. Of course, if your eyesight is good enough to see those points, you are probably a super-hero and should be spending your time saving the world rather than writing code.

    Transients exist to get around the problem of temporarily visible objects. As in my example, add your points to a transient pointer (mdlTransient_xxx).

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Jon Summers:
    add your points to a transient pointer (mdlTransient_xxx).

    Was trying to do that only........but not getting the result. In your example you are using mdlTransient_addElement(...) to add the Line and Ellipse elements. But i need to use DrawPointString3d(...) function to add the points. I could not see any mdlTransient_xxx function to add the points. Here is what i did :
    Added these things in struct MyViewTransients:

    DPoint3dVector pts_;
    void FileAddPoint (const DPoint3d& point, DgnModelRefP modelRef = ACTIVEMODEL);  

    FileAddPoint's definition is like this :

    void MyViewTransients::FileAddPoint (const DPoint3d& point, DgnModelRefP modelRef)
    {
    char msg [128];
    sprintf (msg, "AddPoint %.1lf,%.1lf,%.1lf", point.x, point.y, point.z);
    tracer_.Message (msg);
    tracer_.Output ();
    const double UORs = mdlModelRef_getUorPerMaster (modelRef);
    DPoint3d pt;
    mdlVec_scale (static_cast(&pt), static_cast(&point), UORs);
    pts_.push_back (pt);
    }

    Adding the points (DPoint3d *) array to pts_ using FileAddPoint function :

    for(int k =0; k < 100; k++)
    {
    g_oViewTransients.FileAddPoint (PT[k]);
    }

    and in _DrawTransient function doing like this:

    EmbeddedDPoint3dArray *pMyArray;
    pMyArray = jmdlEmbeddedDPoint3dArray_new();
    IViewDrawP output = context->GetIViewDraw();
    jmdlEmbeddedDPoint3dArray_addDPoint3dArray(pMyArray, &pts_[0], pts_.size ());
    IViewManagerR viewManager = Bentley::Ustn::IViewManager::GetManager();
    ViewportP viewPort = viewManager.GetViewport(1);
    output->SetSymbology (viewPort->MakeTrgbColor (200, 100, 100, 0), 0, 1, 0);
    output->DrawPointString3d (jmdlEmbeddedDPoint3dArray_getCount(pMyArray), jmdlEmbeddedDPoint3dArray_getPtr(pMyArray, 0), NULL, NULL);
    jmdlEmbeddedDPoint3dArray_free(pMyArray);

     Is this the correct way to add points to transient and then use those??


    One more question do i have to add points one by one only using the for loop (Which will surely make routine slower again) or is there any way to add all the points on one go itself?

    Thanks and Regards,
    Arpan

  • Arpan:
    EmbeddedDPoint3dArray *pMyArray;
    pMyArray = jmdlEmbeddedDPoint3dArray_new();
    IViewDrawP output = context->GetIViewDraw();
    jmdlEmbeddedDPoint3dArray_addDPoint3dArray(pMyArray, &pts_[0], pts_.size ());
    IViewManagerR viewManager = Bentley::Ustn::IViewManager::GetManager();
    ViewportP viewPort = viewManager.GetViewport(1);
    output->SetSymbology (viewPort->MakeTrgbColor (200, 100, 100, 0), 0, 1, 0);
    output->DrawPointString3d (jmdlEmbeddedDPoint3dArray_getCount(pMyArray), jmdlEmbeddedDPoint3dArray_getPtr(pMyArray, 0), NULL, NULL);
    jmdlEmbeddedDPoint3dArray_free(pMyArray);

    This looks ok, I'd just use std::vector instead of the jmdlEmbedded array stuff. You should always use the viewport from the ViewContext that is supplied to you, context->GetViewport (), and if it's NULL you probably just want to early return because it means we're not drawing to the screen (or you can just skip setting up the symbology). Of course you're not really using the viewport, just a utility method to create a TBGR UInt32 from 0-255 red, green, blue values.

    Do your points still not display AFTER you do a view update (Update View tool)...i.e. is it just the initial display that is the problem...I can tell you how to deal with that.

    The IViewTransient inteface is a replacement for the mdlTransient_api...but it's vastly superior because you don't need to create elements if you just want to draw geometry and you have more control over how/when/why your geometry is displayed. You DO NOT need to use the mdlTransient_ api to display temporary graphics. Stuff drawn by your _DrawTransient method is back-stored just like using mdlTransient_ with DRAW_MODE_Normal.

     -B



  • Brien:

    Do your points still not display after you do a view update (Update View tool) … i.e. is it just the initial display that is the problem … I can tell you how to deal with that.

    Yes, please!

    Brien:

    The IViewTransient interface is a replacement for the mdlTransient_api.. You don't need to create elements if you just want to draw geometry and you have more control over how/when/why your geometry is displayed. You do not need to use the mdlTransient_ api to display temporary graphics. Stuff drawn by your _DrawTransient method is back-stored just like using mdlTransient_ with DRAW_MODE_Normal.

    Bliss: more enlightenment!

    So we can use IDrawGeom->DrawXxx2d and its companions without having to create an MSElement first. What about the case where one wants the geometry to be snappable? mdlTransient_ creates the transient with an option for snappable; is that also available with the vastly superior IViewTransient interface?

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Since an IViewTransient is back-stored, in order to initially display one (or erase one that has been freed) without doing a full view update you need to to trigger a heal of the screen area where you're going to display your geometry.. You can use the RedrawElems class to accomplish this.

    RedrawElems redrawElems;

    redrawElems.SetDrawMode (initialDisplay ? DRAW_MODE_Normal : DRAW_MODE_Erase);
    redrawElems.SetDrawPurpose (DRAW_PURPOSE_TransientChanged);
    redrawElems.SetViews (0xffff);

    redrawElems.DoRedraw (s_myViewTransient, false);

    If you want to display geometry that is changing every dynamics frame/cursor motion you should be using an IViewDecoration and not an IViewTransient. When you use mdlTransient_addElement with DRAW_MODE_TempDraw instead of DRAW_MODE_Normal or DRAW_MODE_Hilite you are actually creating an IViewDecoration.

    Jon Summers:
    So we can use IDrawGeom->DrawXxx2d and its companions without having to create an MSElement first. What about the case where one wants the geometry to be snappable? mdlTransient_ creates the transient with an option for snappable; is that also available with the vastly superior IViewTransient interface?

    Sure, you can make an IViewTransient snappable. To put things in perspective, when you create a TransDescrP using the mdlTransient_api you are just using an IViewTransient that MicroStation has implemented that visits your elements in it's _DrawTransient method...i.e. mdlTransient_ doesn't do anything that you can't do yourself. All that's needed to make something snappable is an elementRef. AFTER Arpan gets something to display we can get into implementation specifics. :)

     -B



  • Brien Bastings:
    Do your points still not display AFTER you do a view update (Update View tool)

    No Brien, on doing Update view and fit view also i cannot see any points.........

    Brien Bastings:
    You can use the RedrawElems class to accomplish this.

    I tried with that also but did not see any points. Heres what changes i made
    Appended these lines in the MdlMain() function

    RedrawElems redrawElems;
    redrawElems.SetDrawMode (g_oViewTransients.InitialDisplay ? DRAW_MODE_Normal : DRAW_MODE_Erase);
    redrawElems.SetDrawPurpose (DRAW_PURPOSE_TransientChanged);
    redrawElems.SetViews (0xffff);
    redrawElems.DoRedraw (g_oViewTransients, false);


    and made following changes in the _DrawTransient() function...

    if(NULL != context->GetViewport())
    {
    output->SetSymbology (context->GetViewport()->MakeTrgbColor (200, 100, 100, 0), 0, 1, 0);
    EmbeddedDPoint3dArray *pMyArray;
    pMyArray = jmdlEmbeddedDPoint3dArray_new();

    jmdlEmbeddedDPoint3dArray_addDPoint3dArray(pMyArray, &pts_[0], pts_.size ());
    output->DrawPointString3d (jmdlEmbeddedDPoint3dArray_getCount(pMyArray), jmdlEmbeddedDPoint3dArray_getPtr(pMyArray, 0), NULL, NULL);
    jmdlEmbeddedDPoint3dArray_free(pMyArray);
    }
    else
    {
    sprintf(msg, "ViewPort NULL");
    mdlOutput_messageCenter(MESSAGE_INFO, msg, msg, FALSE);
    return;
    }

    Brien Bastings:
    You DO NOT need to use the mdlTransient_ api to display temporary graphics.

    So you mean to say i donot need to push the points to a transient pointer?....like i was trying to do here

    for(int k =0; k < 100; k++)
    {
    g_oViewTransients.FileAddPoint (PT[k]);
    }

     

    Brien Bastings:
    AFTER Arpan gets something to display

    Hope to get this soon.
  • Arpan:

    So you mean to say I do not need to push the points to a transient pointer?

    for(int k =0; k < 100; k++)
    {
       g_oViewTransients.FileAddPoint (PT[k]);
    }

    g_oViewTransients is the name of your static variable that holds an instance of your ViewTransients class. That loop is simply adding a set of points to a class variable.

    Brien means the mdlTransient_xxx functions are not needed in this case. But, since you appear not to be using that API, his comment may not apply in your case.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Lets keep things as simple as possible. This should be all the code you need:

    struct ViewTransients : IViewTransients
    {
    void _DrawTransients (ViewContextP context, bool isPreUpdate) override
    {
    if (isPreUpdate)
    return; // Draw AFTER elements...

    IViewDrawP output = context->GetIViewDraw ();

    output->SetSymbology (0x00ff0000, 0, 1, 0); // opaque blue (color is TBGR packed int), weight 1...
    output->DrawPointString3d (pts_.size (), &pts_[0], NULL);
    }
    };

    static ViewTransients s_viewTransients;

    IViewManager::GetManager().AddViewMonitor (&s_viewMonitor);

    If you call AddViewMonitor after the intial update you will need to update the view to see your transients (or use RedrawElems). For now don't worry about the initial display, just set a break point on _DrawTransients and manually update the view, does the break point get hit? What is the full version number for the V8i version you are using?



  • Arpan:
    void MyViewTransients::FileAddPoint (const DPoint3d& point, DgnModelRefP modelRef)
    {
      …
    }

    If you've copied the AddPoint method from the example I posted, you'll need to add code to compensate for the model's global origin. Here's a revised method:

    
    //////////////////////////////////////////////////////////////////////
    //	AddPoint accepts a 3D point as a user would keyin: master units.
    //	Before pushing the point onto the member <vector> DPoint3d collection, 
    //	this method scales it by UORs-per-master and adds the active model's global origin
    void	MyViewTransients::AddPoint			(const DPoint3d&		point,
    DgnModelRefP			modelRef)
    {
      char	msg	[128];
      sprintf (msg, "AddPoint %.1lf,%.1lf,%.1lf", point.x, point.y, point.z);
      tracer_.Message (msg);
      tracer_.Output ();
      const double 	UORs	= mdlModelRef_getUorPerMaster (modelRef);
      DPoint3d		pt;
      mdlVec_scale (static_cast(&pt), static_cast(&point), UORs);
      DPoint3d		go;
      mdlModelRef_getGlobalOrigin  (modelRef, &go);
      mdlVec_addPoint  (&pt, &pt, &go);
      points_.push_back (pt);
    }
    
    

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Again to keep things as simple as possible let's start with a single DPoint3d that you initialize to zero and try calling DrawPointString3d with just the one point...does that display?



Reply Children
No Data