////////////////////////////////////////////////////////////////////////////////
//
// Document3DEvent -    3D 
//
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "eventsAuto.h"

#ifndef _DOCUMENT3DEVENT_H
#include "Document3DEvent.h"
#endif

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif  


////////////////////////////////////////////////////////////////////////////////
//
// Document3DEvent -    3D 
//
////////////////////////////////////////////////////////////////////////////////

//-------------------------------------------------------------------------------
//
// ---
Document3DEvent::Document3DEvent( LPUNKNOWN pObject, LPDISPATCH doc, bool selfAdvise /*true*/ )
: BaseEvent( pObject, DIID_ksDocument3DNotify, doc, -1, NULL, selfAdvise )
{
}


//-------------------------------------------------------------------------------
//
// ---
Document3DEvent::~Document3DEvent()
{
}


//-------------------------------------------------------------------------------
//
// ---
BEGIN_EVENTSINK_MAP(Document3DEvent, BaseEvent)
	ON_EVENT (Document3DEvent, (unsigned int)-1, d3BeginRebuild,            BeginRebuild,            VTS_NONE)
	ON_EVENT (Document3DEvent, (unsigned int)-1, d3Rebuild,                 Rebuild,                 VTS_NONE)
	ON_EVENT (Document3DEvent, (unsigned int)-1, d3BeginChoiceMaterial,     BeginChoiceMaterial,     VTS_NONE)
	ON_EVENT (Document3DEvent, (unsigned int)-1, d3ChoiceMaterial,          ChoiceMaterial,          VTS_BSTR VTS_R8)
	ON_EVENT (Document3DEvent, (unsigned int)-1, d3BeginChoiceMarking,      BeginChoiceMarking,      VTS_NONE)
	ON_EVENT (Document3DEvent, (unsigned int)-1, d3ChoiceMarking,           ChoiceMarking,           VTS_BSTR)
	ON_EVENT (Document3DEvent, (unsigned int)-1, d3BeginSetPartFromFile,    BeginSetPartFromFile,    VTS_NONE)
	ON_EVENT (Document3DEvent, (unsigned int)-1, d3BeginCreatePartFromFile, BeginCreatePartFromFile, VTS_BOOL VTS_DISPATCH)
END_EVENTSINK_MAP()


//-------------------------------------------------------------------------------
// d3BeginRebuild -   
// ---
afx_msg VARIANT_BOOL Document3DEvent::BeginRebuild()
{ 
  if ( IsSelfAdvise() && theApp.m_mes_3DDOC )
  {
    CString str( m_libName + " --> Document3DEvent::BeginRebuild" );
    str += "\n  = " + GetDocName();
    return !!kompas->ksYesNo( str.GetBuffer(0) );
  }
  else
    return true;
}


//-------------------------------------------------------------------------------
// d3Rebuild -  
// ---
afx_msg VARIANT_BOOL Document3DEvent::Rebuild()
{   
  if ( IsSelfAdvise() && theApp.m_mes_3DDOC )
  {
    CString str( m_libName + " --> Document3DEvent::Rebuild" );
    str += "\n  = " + GetDocName();
    kompas->ksMessage( str.GetBuffer(0) );
  }
  return true;
}


//-------------------------------------------------------------------------------
// d3BeginChoiceMaterial -   
// ---
afx_msg VARIANT_BOOL Document3DEvent::BeginChoiceMaterial()
{
  bool res = false;
  if ( IsSelfAdvise() && theApp.m_mes_3DDOC )
  {
    CString str( m_libName + " --> Document3DEvent::BeginChoiceMaterial" );
    str += "\n  = " + GetDocName();
    res = !!kompas->ksYesNo( str.GetBuffer(0) );

    if( !res )
    {   
      ksDocument3DPtr doc3D;
      m_doc->QueryInterface( DIID_ksDocument3D, (LPVOID*)&doc3D );
      if( doc3D ) 
      {  
        ksPartPtr partObj( doc3D->GetPart( pTop_Part ) );
        partObj->SetMaterial( "Material", 36.6 );
        partObj->Update();
      }
    }
  }
  return res;
}


//-------------------------------------------------------------------------------
// d3hoiceMaterial -   
// ---
afx_msg VARIANT_BOOL Document3DEvent::ChoiceMaterial( LPCTSTR material, double density )
{
  if ( IsSelfAdvise() && theApp.m_mes_3DDOC )
  {
    CString str;
    str.Format( "%s --> Document3DEvent::ChoiceMaterial\nmaterial = %s\ndensity = %f", m_libName, material, density );
    str += "\n  = " + GetDocName();
    kompas->ksMessage( str.GetBuffer(0) );
  }
  return true;
}


//-------------------------------------------------------------------------------
// d3BeginChoiceMarking -   
// ---
afx_msg VARIANT_BOOL Document3DEvent::BeginChoiceMarking()
{
  bool res = false;
  if ( IsSelfAdvise() && theApp.m_mes_3DDOC )
  {
    CString str( m_libName + " --> Document3DEvent::BeginChoiceMarking" );
    str += "\n  = " + GetDocName();
    res = !!kompas->ksYesNo( str.GetBuffer(0) );

    if( !res )
    {   
      ksDocument3DPtr doc3D;
      m_doc->QueryInterface( DIID_ksDocument3D, (LPVOID*)&doc3D );
      if( doc3D ) 
      {  
        ksPartPtr partObj( doc3D->GetPart( pTop_Part ) );
        partObj->marking = "Marking";
        partObj->Update();
      }
    }
  }
  return res;
}


//-------------------------------------------------------------------------------
// d3hoiceMarking -   
// ---
afx_msg VARIANT_BOOL Document3DEvent::ChoiceMarking( LPCTSTR marking )
{
  if ( IsSelfAdvise() && theApp.m_mes_3DDOC )
  {
    CString str;
    str.Format( "%s --> Document3DEvent::ChoiceMarking\nmarking = %s", m_libName, marking );
    str += "\n  = " + GetDocName();
    kompas->ksMessage( str.GetBuffer(0) );
  }
  return true;
}


//-------------------------------------------------------------------------------
// d3BeginSetPartFromFile    -      (   )
afx_msg VARIANT_BOOL Document3DEvent::BeginSetPartFromFile()
{
  if ( IsSelfAdvise() && theApp.m_mes_3DDOC )
  {
    CString str( m_libName + " --> Document3DEvent::BeginSetPartFromFile" );
    str += "\n  = " + GetDocName();
    return !!kompas->ksYesNo( str.GetBuffer(0) );
  }
  return true;
}


//-------------------------------------------------------------------------------
// d3BeginCreatePartFromFile -      (   )
// ---
afx_msg VARIANT_BOOL Document3DEvent::BeginCreatePartFromFile( BOOL part, ksEntity * plane )
{
  if ( IsSelfAdvise() && theApp.m_mes_3DDOC )
  {
    CString str( m_libName + " --> Document3DEvent::BeginCreatePartFromFile" );
    str += "\n  = " + GetDocName();
    return !!kompas->ksYesNo( str.GetBuffer(0) );
  }
  return true;
}
