Help with Modal Renderer



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/06/2003 at 08:31, xxxxxxxx wrote:

    alright I will check them out



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/06/2003 at 08:38, xxxxxxxx wrote:

    Thx for your help. The only thing though is that they don't have any examples of multiple dialog windows open at once, or one GeDialog calling the other.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/06/2003 at 08:44, xxxxxxxx wrote:

    Ok, here is the part of the code that I want to change to GeDialog in case it will help.
      BaseObject* null = doc->GetActiveObject();
      if (!null) return;

    CameraObject* cam = static_cast<CameraObject*>(AllocObject(Ocamera));
      doc->InsertObject(cam, NULL, NULL);

    cam->SetPos(null->GetMg().off); // Set pos. to global pos. of null
      cam->SetRot(Vector(0,0,0)); // Set rotation (radians, HPB)

    // Active the camera
      BaseObject* oldcam = doc->GetRenderBaseDraw()->GetSceneCamera(doc);

    doc->GetRenderBaseDraw()->SetSceneCamera(cam);

    // Create some temporaries for the render
      BaseContainer rdata = doc->GetActiveRenderData()->GetData();
      BaseBitmap* bmp = AllocBaseBitmap();
      bmp->Init(rdata.GetLong(RDATA_XRES),  rdata.GetLong(RDATA_YRES));

    // Set render settings
      rdata.SetFilename(RDATA_PATH, Filename(null->GetName()));

    // 3) delete cameras

    cam->Remove();
      FreeObject(cam);

    // Active the old camera
      doc->GetRenderBaseDraw()->SetSceneCamera(oldcam);

    // 4) display a progress bar showing rendering/view progress.

    ModalRenderer r;
      Bool success = r.Render(doc, rdata, null->GetName(), FALSE);

    class ModalRenderer : private GeModalDialog
    {
    public:
      ModalRenderer() :
          m_doc(NULL),
          m_bmp(NULL),
          m_p(0.0),
          m_result(NOTOK),
          m_showerrors(TRUE),
          m_rt(this) {}

    virtual ~ModalRenderer()
      {
        FreeBaseBitmap(m_bmp);
        ShutdownThread();
      }

    // Render document 'doc' with settings 'rdata',
      // displaying a progress windows with 'title' and
      // optionally not showing error messages.
      Bool Render(BaseDocument* doc, const BaseContainer& rdata,
                  const String& title = String(), Bool showerrors = TRUE)
      {
        if (!doc) return FALSE;
        if (m_rt.IsRunning()) return FALSE;

    m_doc = doc;
        m_rdata = rdata;
        m_title = title;
        m_showerrors = showerrors;

    Bool success = Open();
        ShutdownThread();
        return success && GetResult();
      }

    private:
      BaseDocument* m_doc;
      BaseContainer m_rdata;
      String m_title;
      BaseBitmap* m_bmp;
      Bool m_showerrors;

    Real m_p;
      LONG m_result;

    enum
      {
        SCROLL_GROUP_ID = 100000,
        PREVIEW_AREA_ID,
        DLGGROUP_ID,
        MAIN_GROUP_ID
      };

    // Build the dialog
      virtual Bool CreateLayout()
      {
        if (!InitBitmap()) return FALSE;
       
        SetTitle(m_title);
        GroupBegin(MAIN_GROUP_ID, BFV_SCALEFIT | BFH_SCALEFIT, 1, 0, "", 0);
        {
          GroupSpace(4,4);

    ScrollGroupBegin(SCROLL_GROUP_ID, BFV_SCALEFIT | BFH_SCALEFIT,
                           SCROLLGROUP_STATUSBAR | SCROLLGROUP_BORDERIN |
                           SCROLLGROUP_NOBLIT);
          {
            AddUserArea(PREVIEW_AREA_ID, 0, m_bmp->GetBw(), m_bmp->GetBh());
            AttachImage(PREVIEW_AREA_ID, m_bmp, 0);
          }
          GroupEnd();

    AddDlgGroup(DLG_CANCEL);
        }
        GroupEnd();

    return TRUE;
      }

    // Init dialog and start render
      virtual Bool InitValues()
      {
        UpdatePreview();
        SetTimer(500);

    Bool success = TRUE;
        if (!m_rt.IsRunning())
        {
          success = m_rt.Start(TRUE);
        }

    return success;
      }

    // Ask if the render is running
      virtual Bool AskClose()
      {
        if (!m_rt.IsRunning()) return FALSE;
        return !QuestionDialog("Do you really want to abort the rendering?");
      }

    // Deal with close box and cancel button problems
      virtual LONG Message(const BaseContainer &msg, BaseContainer &result)
      {
        // Workaround for bad base class implementation
        if (msg.GetId() == BFM_ACTION &&
            msg.GetLong(BFM_ACTION_ID) == IDC_CANCEL)
        {
          return Command(IDC_CANCEL, msg);
        }
        else if (msg.GetId() == BFM_CHECKCLOSE)
        {
          return AskClose();
        }
        else
        {
          return GeModalDialog::Message(msg,result);
        }
      }

    // Check for cancel button
      virtual Bool Command(LONG id, const BaseContainer& msg)
      {
        if (id == IDC_CANCEL && !AskClose())
        {
          ShutdownThread();
          return Close(FALSE);
        }
        return FALSE;
      }

    // Run every 500 ms...
      virtual void Timer(const BaseContainer& msg)
      {
        UpdatePreview();
        UpdateStatus();

    CheckFinished();
      }

    // Create preview bitmap
      Bool InitBitmap()
      {
        FreeBaseBitmap(m_bmp);
        m_bmp = AllocBaseBitmap();
        return m_bmp->Init(m_rdata.GetLong(RDATA_XRES),
                           m_rdata.GetLong(RDATA_YRES)) == IMAGE_OK;
      }

    // Tell the preview to redraw itself
      void UpdatePreview()
      {
        GeUserArea* ua = GetUserArea(PREVIEW_AREA_ID);
        if (ua) ua->Redraw(TRUE);
      }

    // Set new statusline text
      void UpdateStatus()
      {
        String txt;
        if (m_p != 1.0)
        {
          txt = "Rendering: " + LongToString(m_p * 100) + "%";
        }
        else
        {
          txt = "Finished!";
        }

    BaseContainer msg(BFM_SETSTATUSBAR);
        msg.SetLong(BFM_STATUSBAR_PROGRESSON, TRUE);
        msg.SetString(BFM_STATUSBAR_TXT, txt);
        msg.SetReal(BFM_STATUSBAR_PROGRESS, m_p);

    SendMessage(SCROLL_GROUP_ID, msg);
      }

    // Wait until render thread is stopped
      void ShutdownThread()
      {
        m_rt.End();
        m_rt.Wait(FALSE);
      }

    // Check if the render is finished
      void CheckFinished()
      {
        if (!m_rt.IsRunning())
        {
          Close(m_result == RAY_OK);
        }
      }

    // Internal class with render thread
      class RenderThread : public Thread
      {
      public:
        RenderThread(ModalRenderer* dlg) : m_dlg(dlg) {}
        virtual ~RenderThread() { m_dlg = NULL; End(); Wait(FALSE); }

    virtual void Main()
        {
          if (!m_dlg) return;

    // Start render
          LONG result =
            RenderDocument(m_dlg->m_doc,                    
                           ProgressFunction, m_dlg,         
                           m_dlg->m_bmp, m_dlg->m_rdata,    
                           TRUE, m_dlg->m_showerrors, this);
         
          if (m_dlg) m_dlg->m_result = result;
        }

    private:
        ModalRenderer* m_dlg;

    // Called by RenderDocument now and then
        static void ProgressFunction(Real p, void* dlg)
        {
          static_cast<ModalRenderer*>(dlg)->m_p = p;
        }
      } m_rt;

    // So that the internal class can access private variables
      friend class RenderThread;
    };



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/06/2003 at 12:24, xxxxxxxx wrote:

    Just wanted to say that I'm not ignoring this message, but just that I haven't got time right now to write any code right now. (See the docs, "The support team will not write code for you. "... ;-)
    Perhaps I'll get time to look into it later and extend the example. Until then you should look into the AsyncTest.cpp example and try to ask more specific questions. Sorry for the inconvenience.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/06/2003 at 13:00, xxxxxxxx wrote:

    no problem, I understand.  At this point the problem is that when I change both dialogs to GeDialogs the parent dialog closes and nothing happens in the child dialog.  I am just trying to figure out what is going on.  I think it may have something to do with the ID that I am using when calling Open(TRUE, ID, -1, -1) on the child.  I am using the same one as the parent.  Thanks for your time.
     
    Nate



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/06/2003 at 13:06, xxxxxxxx wrote:

    You need a unique ID here from Plugincafe for EACH dialog you are creating. Currently there is no other way afaik.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/06/2003 at 13:31, xxxxxxxx wrote:

    Thanks again, I will try that.  I haven't coded in C++ before (only Ada) so getting use to the syntax and functionality of the language slows me down.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/06/2003 at 18:32, xxxxxxxx wrote:

    Ok, I am going to try and be a little more specific with the problem I am having because I think I have a little better handle on it.  I have a plugin X.  Basically what happens is X is a command plugin that calls a (asynchronous)GeDialog Y.  I can have the Dialog  Y create a layout and render a document with a certain set of settings and cameras.  This works perfectly fine.

    Now I create another asynchronous GeDialog  Z in the same plugin (Note I give it an unique ID number but its not registered because I only want one option in the plugin menu).  I now make Z get called in CommandData::Execute by Z.Open(TRUE, ZID, -1, -1).  Z gets some inputs from the user and then calls Y.Open(TRUE, YID, -1, -1).  Ok so now when I run this plugin Z works perfectly and Y almost works.  When I call RenderDocument(....) nothing happens.  The weird thing is that it works when I open Y as a modal dialog or Y.Open(FALSE, YID, -1, -1).
    So what happens is
    X calls Z
    Z calls Y
    Y does everything but Render
    Any thoughts?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/06/2003 at 12:49, xxxxxxxx wrote:

    I am beginning to think that you can only call a thread from a GeModalDialog (or GeDialog that is not asynchronous) if the thread has RenderDocument() in it.  I mean the dialog will work correctly but thread does not seem to execute RenderDocument or it wont wait until it finishes.
    Nate



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 27/06/2003 at 13:40, xxxxxxxx wrote:

    Well after going back to scratch and making my plugin more basic I found my problem.  I was closing the parent dialog too soon and not letting the information flow to the child dialog.  Thanks for all of your help.  Sorry for so many questions.
    Nate


Log in to reply