Exemplo n.º 1
0
void CScriptView::OnScriptUpdateMipmodels() 
{
	// find document with same name
  CModelerDoc *pDoc = (CModelerDoc *) GetDocument();
  CTFileName fnScriptName = CTString(pDoc->GetPathName());
  CTFileName fnModelName = fnScriptName.FileDir() + fnScriptName.FileName() + ".mdl";

	POSITION pos = theApp.m_pdtModelDocTemplate->GetFirstDocPosition();
  while (pos!=NULL)
  {
    CModelerDoc *pmdCurrent = (CModelerDoc *)theApp.m_pdtModelDocTemplate->GetNextDoc(pos);
    if( CTFileName( CTString(pmdCurrent->GetPathName())) == fnModelName)
    {
      POSITION pos = pmdCurrent->GetFirstViewPosition();
      CView *pView = pmdCurrent->GetNextView( pos);
      if( DYNAMIC_DOWNCAST(CModelerView, pView) != NULL)
      {
        CModelerView* pModelerView = (CModelerView *) pView;
        if(pModelerView != NULL)
        {
          pModelerView->OnScriptUpdateMipmodels();
          pModelerView->SetActiveWindow();
          pModelerView->SetFocus();
          CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
          pMainFrame->MDIActivate(pModelerView->GetParentFrame());
        }
      }
      break;
    }
  }
}
Exemplo n.º 2
0
BOOL CModelerDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
  CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
	//return CDocument::OnSaveDocument(lpszPathName);
  CTFileName fnModelFile = CTString(lpszPathName);
  try
  {
    fnModelFile.RemoveApplicationPath_t();
  }
  catch( char *err_str)
  {
    AfxMessageBox( err_str);
    return FALSE;
  }

#if BUILD_PUBLISHER
  WarningMessage(
    "Saving is disabled in this version!");
  return FALSE;
#else
  try
  {
  	m_emEditModel.Save_t( fnModelFile);
    m_emEditModel.SaveMapping_t( fnModelFile.NoExt()+".map", 0);
  }
  catch( char *err_str)
  {
    MessageBoxA(pMainFrame->m_hWnd, err_str, "Warning! Model Save failed.", MB_OK|MB_ICONHAND|MB_SYSTEMMODAL);
    return FALSE;
  }
  SetModifiedFlag( FALSE);

  CModelerView *pModelerView = CModelerView::GetActiveView();
  if( pModelerView != NULL)
  {
    pModelerView->SaveThumbnail();
  }

  // reload attachments of all loaded models 
  POSITION pos = theApp.m_pdtModelDocTemplate->GetFirstDocPosition();
  while (pos!=NULL)
  {
    CModelerDoc *pmdCurrent = (CModelerDoc *)theApp.m_pdtModelDocTemplate->GetNextDoc(pos);
    if( pmdCurrent != this)
    {
      BOOL bUpdateAttachments = TRUE;
      
      // if document is modified
      if( pmdCurrent->IsModified())
      {
        CTString strMessage;
        CTFileName fnDoc = CTString(pmdCurrent->GetPathName());
        strMessage.PrintF("Do you want to save model \"%s\" before reloading its attachments?", fnDoc.FileName() );
        if( ::MessageBox( pMainFrame->m_hWnd, strMessage,
                        "Warning !", MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON1 | 
                        MB_TASKMODAL | MB_TOPMOST) != IDYES)
        {
          bUpdateAttachments = FALSE;
        }
        // save document
        else
        {
          pmdCurrent->OnSaveDocument(pmdCurrent->GetPathName());
        }
      }

      if( bUpdateAttachments)
      {
        POSITION pos = pmdCurrent->GetFirstViewPosition();
        while (pos != NULL)
        {
          CView* pView = GetNextView(pos);
          ((CModelerView *)pView)->m_ModelObject.AutoSetAttachments();
          
          //CModelData *pmd = (CModelData *) ((CModelerView *)pView)->m_ModelObject.GetData();
          //pmd->Reload();
        }
      }
    }
  }


  return TRUE;
#endif
}
Exemplo n.º 3
0
void CScriptView::OnScriptMakeModel() 
{
	// First we save script file
  CModelerDoc *pDoc = (CModelerDoc *) GetDocument();
  CTFileName fnScriptName = CTString(pDoc->GetPathName());

  CTFileName fnModelName = fnScriptName.FileDir() + fnScriptName.FileName() + ".mdl";
  try
  {
    fnScriptName.RemoveApplicationPath_t();
  }
  catch( char *err_str)
  {
    AfxMessageBox( err_str);
    return;
  }
  pDoc->OnSaveDocument( pDoc->GetPathName());

	// close mdl document with same name
  POSITION pos = theApp.m_pdtModelDocTemplate->GetFirstDocPosition();
  while (pos!=NULL)
  {
    CModelerDoc *pmdCurrent = (CModelerDoc *)theApp.m_pdtModelDocTemplate->GetNextDoc(pos);
    if( CTFileName( CTString(pmdCurrent->GetPathName())) == fnModelName)
    {
      pmdCurrent->OnCloseDocument();
      break;
    }
  }

	// Now we will create one instance of new document of type CModelerDoc
  CDocument* pDocument = theApp.m_pdtModelDocTemplate->CreateNewDocument();
 	if (pDocument == NULL)
	{
		TRACE0("CDocTemplate::CreateNewDocument returned NULL.\n");
		AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
		return;
	}
	ASSERT_VALID(pDocument);
	
  BOOL bAutoDelete = pDocument->m_bAutoDelete;
	pDocument->m_bAutoDelete = FALSE;   // don't destroy if something goes wrong
	CFrameWnd* pFrame = theApp.m_pdtModelDocTemplate->CreateNewFrame(pDocument, NULL);
	pDocument->m_bAutoDelete = bAutoDelete;
	if (pFrame == NULL)
	{
		AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
		delete pDocument;       // explicit delete on error
		return;
	}
	ASSERT_VALID(pFrame);

  pDocument->SetPathName( fnModelName, FALSE);
  pDocument->SetTitle( fnModelName.FileName() + fnModelName.FileExt());
  
  char strError[ 256];
  if( !((CModelerDoc *)pDocument)->CreateModelFromScriptFile( fnScriptName, strError))
  {
    pDocument->OnCloseDocument();
    AfxMessageBox( strError);
    return;
  }
	theApp.m_pdtModelDocTemplate->InitialUpdateFrame(pFrame, pDocument, TRUE);
  ((CModelerDoc *)pDocument)->m_emEditModel.edm_md.md_bPreparedForRendering = FALSE;
  pDocument->SetModifiedFlag();

  // add textures from .ini file
  CTFileName fnIniFileName = fnScriptName.NoExt() + ".ini";
  try
  {
    ((CModelerDoc *)pDocument)->m_emEditModel.CSerial::Load_t(fnIniFileName);
  }
  catch( char *strError)
  {
    // ignore errors
    (void) strError;
  }
}