// EasyOCView.cpp : implementation of the CEasyOCView class
//

#include "stdafx.h"
#include "EasyOC.h"

#include "EasyOCDoc.h"
#include "EasyOCView.h"

//#ifdef _DEBUG
//#define new DEBUG_NEW
//#endif

#include <BRepPrim_Sphere.hxx> 
#include <BRepPrimAPI_MakeSphere.hxx> 
#include <BRepPrimAPI_MakeBox.hxx> 
#include "AIS_Shape.hxx"
// CEasyOCView

IMPLEMENT_DYNCREATE(CEasyOCView, CView)

BEGIN_MESSAGE_MAP(CEasyOCView, CView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_COMMAND(ID_TOOLS_BOX, &CEasyOCView::OnToolsBox)
END_MESSAGE_MAP()

// CEasyOCView construction/destruction

CEasyOCView::CEasyOCView()
{
	// TODO: add construction code here

}

CEasyOCView::~CEasyOCView()
{
  m_3dView->Remove();
}

BOOL CEasyOCView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

// CEasyOCView drawing

void CEasyOCView::OnDraw(CDC* /*pDC*/)
{
	CEasyOCDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
}


// CEasyOCView printing

BOOL CEasyOCView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEasyOCView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEasyOCView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}


// CEasyOCView diagnostics

#ifdef _DEBUG
void CEasyOCView::AssertValid() const
{
	CView::AssertValid();
}

void CEasyOCView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEasyOCDoc* CEasyOCView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEasyOCDoc)));
	return (CEasyOCDoc*)m_pDocument;
}
#endif //_DEBUG


// CEasyOCView message handlers
void CEasyOCView::OnInitialUpdate()
{
   CView::OnInitialUpdate();

   m_3dView = GetDocument()->m_3dViewer->CreateView();
       m_3dView->SetDegenerateModeOn();

   Handle(WNT_Window) hWindow;
   hWindow = new WNT_Window(((CEasyOCApp*)AfxGetApp())->m_GraphicDevice, 
      GetSafeHwnd());
   m_3dView->SetWindow(hWindow);
   if (!hWindow->IsMapped()) hWindow->Map();

   //::PostMessage(GetSafeHwnd(), WM_SIZE, SIZE_RESTORED, nWidth + nHeight * 65536);
}
void CEasyOCView::OnToolsBox()
{
	Handle_AIS_InteractiveContext myAISContext=	GetDocument()->m_AISContext;
	TopoDS_Shape B1 = BRepPrimAPI_MakeBox (200.,150.,100.);
	Handle(AIS_Shape) aBox1 = new AIS_Shape(B1);
	myAISContext->SetMaterial(aBox1,Graphic3d_NOM_PLASTIC,Standard_False);    
	myAISContext->SetColor(aBox1,Quantity_NOC_GREEN,Standard_False); 
	myAISContext->Display(aBox1,Standard_False);
	TopoDS_Shape B2 = BRepPrimAPI_MakeBox (gp_Ax2(gp_Pnt(-200.,-80.,-70.),
		gp_Dir(1.,2.,1.)),
		80.,90.,120.);
	Handle(AIS_Shape) aBox2 = new AIS_Shape(B2);
	myAISContext->SetMaterial(aBox2,Graphic3d_NOM_PLASTIC,Standard_False);    
	myAISContext->SetColor(aBox2,Quantity_NOC_RED,Standard_False); 
	myAISContext->Display(aBox2,Standard_False);

	m_3dView->FitAll();
}
