// SampleViewer3dDoc.cpp : implementation of the CSampleViewer3dDoc class
//
#include "TDF_Tool.hxx"
#include "stdafx.h"
#include "SampleViewer3d.h"

#include "SampleViewer3dDoc.h"
#include "SampleViewer3dView.h"

#include "OCCInterFace.h"
#include "NewBaseBoxDlg.h"
#include "NewBaseCylinderDlg.h"


#include "Boss.h"
#include "BossSelf.h"
#include "SnapHook.h"
#include "SnapRing.h"
#include "PressFit.h"
#include "Hinge.h"
#include "Draft.h"
#include "Holes.h"
#include "PartingPlane.h"
#include "Ribs.h"
#include "Wall.h"
#include "IJBubble.h"
#include "IJBurn.h"
#include "IJCOLD.h"
#include "IJCraze.h"
#include "IJDelam.h"
#include "IJEject.h"
#include "IJFlash.h"
#include "IJImperfect.h"
#include "IJShort.h"
#include "IJSink.h"
#include "IJStreak.h"
#include "IJVariation.h"
#include "IJWarp.h"
#include "IJWeak.h"

#include "MBlister.h"
#include "MBurn.h"
#include "MCrack.h"
#include "MDull.h"
#include "MFlash.h"
#include "MOversize.h"
#include "MPorosity.h"
#include "MStick.h"
#include "MUndersize.h"
#include "MWarp.h"



#include "Recycle.h"
#include "Reuse.h"
#include "Codes.h"
//#ifdef _DEBUG
//#define new DEBUG_NEW
//#undef THIS_FILE
//static char THIS_FILE[] = __FILE__;
//#endif

/////////////////////////////////////////////////////////////////////////////
// CSampleViewer3dDoc

IMPLEMENT_DYNCREATE(CSampleViewer3dDoc, CDocument)

BEGIN_MESSAGE_MAP(CSampleViewer3dDoc, CDocument)
	//{{AFX_MSG_MAP(CSampleViewer3dDoc)
	ON_COMMAND(ID_BOX, OnBox)
	ON_COMMAND(ID_Cylinder, OnCylinder)
	ON_COMMAND(ID_SPHERE, OnSphere)
	ON_COMMAND(ID_ERASEALL, OnEraseall)
	ON_COMMAND(ID_DESIGNFEATURES_BOSSES, OnDesignfeaturesBosses)
	ON_COMMAND(ID_DESIGNFEATURES_BOSSESOFSELF, OnDesignfeaturesBossesofself)
	ON_COMMAND(ID_DESIGNFEATURES_DRAFTANGLE, OnDesignfeaturesDraftangle)
	ON_COMMAND(ID_DESIGNFEATURES_HOLES, OnDesignfeaturesHoles)
	ON_COMMAND(ID_DESIGNFEATURES_PARTINGPLANE, OnDesignfeaturesPartingplane)
	ON_COMMAND(ID_DESIGNFEATURES_RIBS, OnDesignfeaturesRibs)
	ON_COMMAND(ID_DESIGNFEATURES_WALLTHICKNESS, OnDesignfeaturesWallthickness)
	ON_COMMAND(ID_DESIGNFEATURES_BOSSESOFSELF_VISUALISATION, OnDesignfeaturesBossesofselfVisualisation)
	ON_COMMAND(ID_SNAPFIT_SNAPRING, OnSnapfitSnapring)
	ON_COMMAND(ID_SNAPFIT_SNAPHOOK, OnSnapfitSnaphook)
	ON_COMMAND(ID_PRESSFIT_HUBSHAFTTYPE, OnPressfitHubshafttype)
	ON_COMMAND(ID_LIVINGHINGE_POLY, OnLivinghingePoly)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_BLACKSTREAKS, OnManufacturingdefectsInjectBlackstreaks)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_BUBBLES, OnManufacturingdefectsInjectBubbles)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_BURNING, OnManufacturingdefectsInjectBurning)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_COLDSLUG, OnManufacturingdefectsInjectColdslug)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_CRAZING, OnManufacturingdefectsInjectCrazing)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_DELAMINATION, OnManufacturingdefectsInjectDelamination)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_MOULDFLASHING, OnManufacturingdefectsInjectMouldflashing)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_PARTSBREAK, OnManufacturingdefectsInjectPartsbreak)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_SHORTSHOTS, OnManufacturingdefectsInjectShortshots)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_SINKMARKS, OnManufacturingdefectsInjectSinkmarks)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_SURFACEIMPERFECTION, OnManufacturingdefectsInjectSurfaceimperfection)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_VARIATION, OnManufacturingdefectsInjectVariation)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_WARPEDPARTS, OnManufacturingdefectsInjectWarpedparts)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_INJECT_WEAKWELD, OnManufacturingdefectsInjectWeakweld)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_BLISTERS, OnManufacturingdefectsMouldingBlisters)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_BURNEDMARKS, OnManufacturingdefectsMouldingBurnedmarks)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_EXCESSIVEFLASH, OnManufacturingdefectsMouldingExcessiveflash)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_MATERIALSTICK, OnManufacturingdefectsMouldingMaterialstick)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_OVERSIZED, OnManufacturingdefectsMouldingOversized)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_PARTSCRACKED, OnManufacturingdefectsMouldingPartscracked)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_POROSITY, OnManufacturingdefectsMouldingPorosity)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_SURFACEDULL, OnManufacturingdefectsMouldingSurfacedull)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_UNDERSIZED, OnManufacturingdefectsMouldingUndersized)
	ON_COMMAND(ID_MANUFACTURINGDEFECTS_MOULDING_WARPAGE, OnManufacturingdefectsMouldingWarpage)
	ON_COMMAND(ID_ENVIRONMENTALCONCERNS_REUSEPLASTICS, OnEnvironmentalconcernsReuseplastics)
	ON_COMMAND(ID_ENVIRONMENTALCONCERNS_RECYCLING, OnEnvironmentalconcernsRecycling)
	ON_COMMAND(ID_ENVIRONMENTALCONCERNS_PLASTICPACKAGINGCODES, OnEnvironmentalconcernsPlasticpackagingcodes)
	//}}AFX_MSG_MAP
	
	ON_COMMAND(ID_BASE_CYLINDER863, &CSampleViewer3dDoc::OnBaseCylinder863)
	ON_COMMAND(ID_SHAPE_HOLE, &CSampleViewer3dDoc::OnShapeHole)
	ON_COMMAND(ID_BASE_GIBBOSE, &CSampleViewer3dDoc::OnBaseGibbose)
	
	ON_COMMAND(ID_BASE_BOX, &CSampleViewer3dDoc::OnBaseBox)
	ON_COMMAND(ID_BASE_SPHERE, &CSampleViewer3dDoc::OnBaseSphere)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSampleViewer3dDoc construction/destruction

CSampleViewer3dDoc::CSampleViewer3dDoc()
{
	// TODO: add one-time construction code here
	Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice = 
		((CSampleViewer3dApp*)AfxGetApp())->GetGraphicDevice();

	myViewer = new V3d_Viewer(theGraphicDevice,(short *) "Visu3D");
	myViewer->SetDefaultLights();
	myViewer->SetLightOn();

	myAISContext =new AIS_InteractiveContext(myViewer);

    AfxInitRichEdit();
	myResultMessageDlg.Create(CResultMessageDlg::IDD, NULL);

Handle(AIS_Shape) aBaseBox;
	//Handle(AIS_Shape) aBaseBox = new AIS_Shape();

}

CSampleViewer3dDoc::~CSampleViewer3dDoc()
{
}

BOOL CSampleViewer3dDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
//	SetTitle("Viewer");

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CSampleViewer3dDoc serialization

void CSampleViewer3dDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CSampleViewer3dDoc diagnostics

#ifdef _DEBUG
void CSampleViewer3dDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CSampleViewer3dDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSampleViewer3dDoc commands

void CSampleViewer3dDoc::UpdateResultMessageDlg(CString Title, TCollection_AsciiString aMessage)
{
    CString text(aMessage.ToCString());
    myResultMessageDlg.SetText(text);

    myResultMessageDlg.SetTitle(Title);
    myResultMessageDlg.ShowWindow(SW_RESTORE);
}

//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CSampleViewer3dDoc::DragEvent(const Standard_Integer  x        ,
				                  const Standard_Integer  y        ,
				                  const Standard_Integer  TheState ,
                                  const Handle(V3d_View)& aView    )
{

    // TheState == -1  button down
	// TheState ==  0  move
	// TheState ==  1  button up

    static Standard_Integer theButtonDownX=0;
    static Standard_Integer theButtonDownY=0;

	if (TheState == -1)
    {
      theButtonDownX=x;
      theButtonDownY=y;
    }

	if (TheState == 0)
	  myAISContext->Select(theButtonDownX,theButtonDownY,x,y,aView);  
}

//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CSampleViewer3dDoc::InputEvent(const Standard_Integer  x     ,
				                   const Standard_Integer  y     ,
                                   const Handle(V3d_View)& aView ) 
{
    myAISContext->Select(); 
}

//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CSampleViewer3dDoc::MoveEvent(const Standard_Integer  x       ,
                                  const Standard_Integer  y       ,
                                  const Handle(V3d_View)& aView   ) 
{
      myAISContext->MoveTo(x,y,aView);
}

//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CSampleViewer3dDoc::ShiftMoveEvent(const Standard_Integer  x       ,
                                  const Standard_Integer  y       ,
                                  const Handle(V3d_View)& aView   ) 
{
      myAISContext->MoveTo(x,y,aView);
}

//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CSampleViewer3dDoc::ShiftDragEvent(const Standard_Integer  x        ,
									   const Standard_Integer  y        ,
									   const Standard_Integer  TheState ,
                                       const Handle(V3d_View)& aView    ) 
{
    static Standard_Integer theButtonDownX=0;
    static Standard_Integer theButtonDownY=0;

	if (TheState == -1)
    {
      theButtonDownX=x;
      theButtonDownY=y;
    }

	if (TheState == 0)
	  myAISContext->ShiftSelect(theButtonDownX,theButtonDownY,x,y,aView);  
}


//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CSampleViewer3dDoc::ShiftInputEvent(const Standard_Integer  x       ,
									    const Standard_Integer  y       ,
                                        const Handle(V3d_View)& aView   ) 
{
	myAISContext->ShiftSelect(); 
}

//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void  CSampleViewer3dDoc::Popup(const Standard_Integer  x,
							   const Standard_Integer  y ,
                               const Handle(V3d_View)& aView   ) 
{
  Standard_Integer PopupMenuNumber=0;

  CMenu menu;
  VERIFY(menu.LoadMenu(IDR_Popup));
  CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
  ASSERT(pPopup != NULL);
 
  POINT winCoord = { x , y };
  Handle(WNT_Window) aWNTWindow=
  Handle(WNT_Window)::DownCast(aView->Window());
  ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
  pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , 
                         AfxGetMainWnd());
}


void CSampleViewer3dDoc::Fit()
{
	CMDIFrameWnd *pFrame =  (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
	CMDIChildWnd *pChild =  (CMDIChildWnd *) pFrame->GetActiveFrame();
	CSampleViewer3dView *pView = (CSampleViewer3dView *) pChild->GetActiveView();
	pView->Fitall();
}

void CSampleViewer3dDoc::OnBox() 
{
	BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
	Handle(AIS_Shape) aBox = new AIS_Shape(B.Shape());
	myAISContext->Display(aBox);	
}

void CSampleViewer3dDoc::OnCylinder() 
{
	gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
	Handle(AIS_Shape) aCyl = new AIS_Shape(C.Shape());
	myAISContext->SetColor(aCyl,Quantity_NOC_WHITE); 
	myAISContext->SetMaterial(aCyl,Graphic3d_NOM_SHINY_PLASTIC);    
	myAISContext->SetDisplayMode(aCyl,1);
	myAISContext->Display(aCyl);
}

void CSampleViewer3dDoc::OnSphere() 
{
	BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
	Handle(AIS_Shape) aSphere = new AIS_Shape(S.Shape());
	myAISContext->SetMaterial(aSphere,Graphic3d_NOM_SILVER);    
	myAISContext->SetDisplayMode(aSphere,1);
	myAISContext->Display(aSphere);
}

void CSampleViewer3dDoc::OnEraseall() 
{
	myAISContext->EraseAll(Standard_False);
}

void CSampleViewer3dDoc::OnDesignfeaturesBosses() 
{
	// TODO: Add your command handler code here
	CBoss Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnDesignfeaturesBossesofself() 
{
	// TODO: Add your command handler code here;
	CBossSelf Dlg;
	m_BossAA=Dlg.m_BossA;
	m_BossBB=Dlg.m_BossB;


	if (Dlg.DoModal() == IDOK)
	{

	m_BossAA=Dlg.m_BossA;
	m_BossBB=Dlg.m_BossB;

	if ((m_BossAA == 0) || (m_BossBB == 0))
	{
	AfxMessageBox("ERROR!\nNo values entered for a or b.\nPlease ensure values for a and b are entered.");
	CBossSelf Dlg;
	}
	else

	myAISContext->EraseAll(Standard_False);
	
	
	gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape ScrewTop = BRepPrimAPI_MakeCylinder(CylAx2,m_BossAA,(0.3*m_BossAA));
	Handle (AIS_Shape)	ais1 = new AIS_Shape(ScrewTop);
	myAISContext->SetColor(ais1,Quantity_NOC_GREEN);
	myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais1);
	
	gp_Ax2 CylAx3(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape ScrewBottom = BRepPrimAPI_MakeCylinder(CylAx3,(m_BossAA*0.8),(2.5*m_BossAA));
	Handle (AIS_Shape)	ais2 = new AIS_Shape(ScrewBottom);
	myAISContext->SetColor(ais2,Quantity_NOC_YELLOW);
	myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais2);
	

	TopoDS_Shape ScrewFull = BRepAlgoAPI_Fuse(ScrewTop,ScrewBottom);
	
	
	gp_Ax2 CylAx4(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Boss1 = BRepPrimAPI_MakeCylinder(CylAx4,(m_BossAA*2.4),(2.5*m_BossAA));
	Handle (AIS_Shape)	ais3 = new AIS_Shape(Boss1);
	myAISContext->SetColor(ais2,Quantity_NOC_YELLOW);
	myAISContext->SetMaterial(ais3,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais3);


	gp_Pnt P(0,0,(-100+(2.5*m_BossAA)));
	TopoDS_Shape theBox1 = BRepPrimAPI_MakeBox(P,(4*m_BossAA),(4*m_BossAA),m_BossBB);
	Handle (AIS_Shape)	ais4 = new AIS_Shape(theBox1);
	myAISContext->SetColor(ais4,Quantity_NOC_RED);
	myAISContext->SetMaterial(ais4,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais4);

	gp_Pnt P1(0,0,(-100+(2.5*m_BossAA)));
	TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(P1,-(4*m_BossAA),-(4*m_BossAA),m_BossBB);
	Handle (AIS_Shape)	ais5 = new AIS_Shape(theBox2);
	myAISContext->SetColor(ais5,Quantity_NOC_RED);
	myAISContext->SetMaterial(ais5,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais5);

	gp_Pnt P2(0,0,(-100+(2.5*m_BossAA)));
	TopoDS_Shape theBox3 = BRepPrimAPI_MakeBox(P2,-(4*m_BossAA),(4*m_BossAA),m_BossBB);
	Handle (AIS_Shape)	ais6 = new AIS_Shape(theBox3);
	myAISContext->SetColor(ais6,Quantity_NOC_RED);
	myAISContext->SetMaterial(ais6,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais6);

	gp_Pnt P3(0,0,(-100+(2.5*m_BossAA)));
	TopoDS_Shape theBox4 = BRepPrimAPI_MakeBox(P3,(4*m_BossAA),-(4*m_BossAA),m_BossBB);
	Handle (AIS_Shape)	ais7 = new AIS_Shape(theBox4);
	myAISContext->SetColor(ais7,Quantity_NOC_RED);
	myAISContext->SetMaterial(ais7,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais7);

	TopoDS_Shape Bottom = BRepAlgoAPI_Fuse(theBox1,theBox2);
	TopoDS_Shape Bottom2 = BRepAlgoAPI_Fuse(theBox3,theBox4);
	TopoDS_Shape Bottom3 = BRepAlgoAPI_Fuse(Bottom,Bottom2);
	TopoDS_Shape Full = BRepAlgoAPI_Fuse(Bottom3,Boss1);

	TopoDS_Shape Boss2 = BRepAlgoAPI_Cut(Full,ScrewFull);

	myAISContext->Erase(ais1,Standard_True,Standard_False);
	myAISContext->Erase(ais2,Standard_True,Standard_False);
	myAISContext->Erase(ais3,Standard_True,Standard_False);
	myAISContext->Erase(ais4,Standard_True,Standard_False);
	myAISContext->Erase(ais5,Standard_True,Standard_False);
	myAISContext->Erase(ais6,Standard_True,Standard_False);
	myAISContext->Erase(ais7,Standard_True,Standard_False);
	
	Handle (AIS_Shape)	aFusion = new AIS_Shape(Boss2);
	myAISContext->SetDisplayMode(aFusion,1);
	myAISContext->SetColor(aFusion,Quantity_NOC_RED);
	myAISContext->SetMaterial(aFusion,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(aFusion);

	Fit();

	}
	
	
}

void CSampleViewer3dDoc::OnDesignfeaturesDraftangle() 
{
	// TODO: Add your command handler code here
	CDraft Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnDesignfeaturesHoles() 
{
	// TODO: Add your command handler code here

	CHoles Dlg;
	m_HoleAA=Dlg.m_HoleA;
	m_TypeA=Dlg.m_Type;
	m_MouldAA=Dlg.m_Mould;


	if (Dlg.DoModal() == IDOK)
	{

	m_HoleAA=Dlg.m_HoleA;
	m_TypeA=Dlg.m_Type;
	m_MouldAA=Dlg.m_Mould;

	myAISContext->EraseAll(Standard_False);
	
	gp_Ax2 CylAx6(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole = BRepPrimAPI_MakeCylinder(CylAx6,7.95,15.9);
	Handle (AIS_Shape)	ais14 = new AIS_Shape(Hole);
	myAISContext->SetColor(ais14,Quantity_NOC_RED);
	myAISContext->SetMaterial(ais14,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais14);


	gp_Pnt P6(-7.95,-37.95,-100);
	TopoDS_Shape theBox6 = BRepPrimAPI_MakeBox(P6,15.9,15.9,15.9);
	Handle (AIS_Shape)	ais15 = new AIS_Shape(theBox6);
	myAISContext->SetColor(ais15,Quantity_NOC_WHITE);
	myAISContext->SetMaterial(ais15,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais15);


	gp_Pnt P7(-7.95,22.05,-100);
	TopoDS_Shape theBox7 = BRepPrimAPI_MakeBox(P7,15.9,30,15.9);
	Handle (AIS_Shape)	ais16 = new AIS_Shape(theBox7);
	myAISContext->SetColor(ais16,Quantity_NOC_MATRABLUE);
	myAISContext->SetMaterial(ais16,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais16);


	gp_Pnt P8(-27.95,-57.95,-84.1);
	TopoDS_Shape theBox8 = BRepPrimAPI_MakeBox(P8,55.9,120,-40);
	Handle (AIS_Shape)	ais17 = new AIS_Shape(theBox8);
	myAISContext->SetColor(ais17,Quantity_NOC_AZURE);
	myAISContext->SetMaterial(ais17,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais17);

	Fit();

	Sleep(500);

	TopoDS_Shape Cut = BRepAlgoAPI_Cut(theBox8,theBox7);
	TopoDS_Shape Cut2 = BRepAlgoAPI_Cut(Cut,theBox6);
	TopoDS_Shape Cut3 = BRepAlgoAPI_Cut(Cut2,Hole);

	Handle (AIS_Shape)	ais18 = new AIS_Shape(Cut3);
	myAISContext->SetColor(ais18,Quantity_NOC_CORAL2);
	myAISContext->SetMaterial(ais18,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais18);


	myAISContext->Erase(ais14,Standard_True,Standard_False);
	myAISContext->Erase(ais15,Standard_True,Standard_False);
	myAISContext->Erase(ais16,Standard_True,Standard_False);
	myAISContext->Erase(ais17,Standard_True,Standard_False);
	myAISContext->Erase(ais18,Standard_True,Standard_False);

	
	Handle (AIS_Shape)	aFusion2 = new AIS_Shape(Cut3);
	myAISContext->SetDisplayMode(aFusion2,1);
	myAISContext->SetColor(aFusion2,Quantity_NOC_HOTPINK);
	myAISContext->SetMaterial(aFusion2,Graphic3d_NOM_PLASTIC);
	myAISContext->SetTransparency(aFusion2,0.18);
	myAISContext->Display(aFusion2);

	Fit();
	}
}

void CSampleViewer3dDoc::OnDesignfeaturesPartingplane() 
{
	// TODO: Add your command handler code here
	CPartingPlane Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnDesignfeaturesRibs() 
{
	// TODO: Add your command handler code here
	CRibs Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnDesignfeaturesWallthickness() 
{
	// TODO: Add your command handler code here
	CWall Dlg;
	
	if (Dlg.DoModal() == IDOK)
	{

	myAISContext->EraseAll(Standard_False);

	TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,0), gp_Pnt(10,0,0));
	TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(10,0,0), gp_Pnt(10,4,0));
	TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(10,4,0), gp_Pnt(-20,4,0));
	TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(-20,4,0), gp_Pnt(-20,-3,0));
	TopoDS_Edge E5 = BRepBuilderAPI_MakeEdge(gp_Pnt(-20,-3,0), gp_Pnt(-9,-3,0));
	TopoDS_Edge E6 = BRepBuilderAPI_MakeEdge(gp_Pnt(-9,-3,0), gp_Pnt(0,0,0));

	TopoDS_Wire WW = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);

	BRepBuilderAPI_MakeWire MW;
	MW.Add(WW);
	MW.Add(E5);
	MW.Add(E6);

	TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()),MW);

	TopoDS_Shape S4 = BRepPrimAPI_MakePrism(F,gp_Vec(0,0,29));

	Handle (AIS_Shape)	best = new AIS_Shape(S4);
	myAISContext->SetDisplayMode(best,1);
	myAISContext->SetColor(best,Quantity_NOC_CORAL2);
	myAISContext->SetMaterial(best,Graphic3d_NOM_PLASTIC);
	myAISContext->SetTransparency(best,0.13);
	myAISContext->Display(best);

	Fit();
	}

	
}

void CSampleViewer3dDoc::OnDesignfeaturesBossesofselfVisualisation() 
{
	// TODO: Add your command handler code here
	

}

void CSampleViewer3dDoc::OnSnapfitSnapring() 
{
	// TODO: Add your command handler code here
	CSnapRing Dlg;

	if (Dlg.DoModal() == IDOK)
	{

	myAISContext->EraseAll(Standard_False);

	TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(0,0,0),80);
	
	TopoDS_Shape theSphere2 = BRepPrimAPI_MakeSphere(gp_Pnt(0,20,0),69);
	
	TopoDS_Shape Cut = BRepAlgoAPI_Cut(theSphere,theSphere2);


	gp_Ax2 CylAx8(gp_Pnt(0,-69,0), gp_Dir(gp_Vec(gp_Pnt(0,100,0),gp_Pnt(0,-100,0))));
	TopoDS_Shape Hole = BRepPrimAPI_MakeCylinder(CylAx8,29,88);
	

	TopoDS_Shape Cut5 = BRepAlgoAPI_Fuse(Cut,Hole);


	gp_Pnt P7(0,47,0);
	TopoDS_Shape theBox7 = BRepPrimAPI_MakeBox(P7,150,50,150);


	gp_Pnt P8(0,47,0);
	TopoDS_Shape theBox8 = BRepPrimAPI_MakeBox(P8,-150,50,150);


	gp_Pnt P9(0,47,0);
	TopoDS_Shape theBox9 = BRepPrimAPI_MakeBox(P9,-150,50,-150);


	gp_Pnt P5(0,47,0);
	TopoDS_Shape theBox5 = BRepPrimAPI_MakeBox(P5,150,50,-150);


	TopoDS_Shape Block = BRepAlgoAPI_Fuse(theBox7,theBox8);
	TopoDS_Shape Block2 = BRepAlgoAPI_Fuse(Block,theBox9);
	TopoDS_Shape Block3 = BRepAlgoAPI_Fuse(Block2,theBox5);

	
	TopoDS_Shape Cut2 = BRepAlgoAPI_Cut(Cut5,Block3);

	//Holder
	Handle (AIS_Shape)	ais14 = new AIS_Shape(Cut2);
	myAISContext->SetDisplayMode(ais14,1);
	myAISContext->SetColor(ais14,Quantity_NOC_CORAL2,1);
	myAISContext->SetMaterial(ais14,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais14);


	TopoDS_Shape theSphere3 = BRepPrimAPI_MakeSphere(gp_Pnt(0,180,0),67);


	gp_Ax2 CylAx3(gp_Pnt(0,231,0), gp_Dir(gp_Vec(gp_Pnt(0,-100,0),gp_Pnt(0,100,0))));
	TopoDS_Shape Hole2 = BRepPrimAPI_MakeCylinder(CylAx3,29,88);

	TopoDS_Shape Cut3 = BRepAlgoAPI_Fuse(theSphere3,Hole2);

	Handle (AIS_Shape)	ais16 = new AIS_Shape(Cut3);
	myAISContext->SetDisplayMode(ais16,1);
	myAISContext->SetColor(ais16,Quantity_NOC_AZURE,1);
	myAISContext->SetMaterial(ais16,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais16);

	Fit();
	}
}

void CSampleViewer3dDoc::OnSnapfitSnaphook() 
{
	// TODO: Add your command handler code here
	CSnapHook Dlg;
	m_Snaphh=Dlg.m_Snaph;
	m_SnapHH=Dlg.m_SnapH;
	m_SnapLL=Dlg.m_SnapL;


	if (Dlg.DoModal() == IDOK)
	{

	m_Snaphh=Dlg.m_Snaph;
	m_SnapHH=Dlg.m_SnapH;
	m_SnapLL=Dlg.m_SnapL;

	if ((m_Snaphh == 0) || (m_SnapHH == 0) || (m_SnapLL == 0))
	{
	AfxMessageBox("ERROR!\nPlease ensure values for the snap-hook are entered.");
	CSnapHook Dlg;
	}
	else

	myAISContext->EraseAll(Standard_False);

	TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,0), gp_Pnt((m_SnapLL),0,0));
	TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt((m_SnapLL),0,0), gp_Pnt((m_SnapLL),-(m_SnapHH),0));
	TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt((m_SnapLL),-(m_SnapHH),0), gp_Pnt((m_SnapLL+(0.5*m_SnapHH)),-(m_SnapHH),0));
	TopoDS_Edge E7 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,0), gp_Pnt(0,(m_Snaphh),0));
	TopoDS_Edge E6 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,(m_Snaphh),0), gp_Pnt((1.8*m_SnapLL),(m_Snaphh),0));
	TopoDS_Edge E5 = BRepBuilderAPI_MakeEdge(gp_Pnt((1.8*m_SnapLL),(m_Snaphh),0), gp_Pnt((1.8*m_SnapLL),(m_Snaphh)-(0.6*m_Snaphh),0));
	TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt((m_SnapLL+(0.5*m_SnapHH)),-(m_SnapHH),0), gp_Pnt((1.8*m_SnapLL),(m_Snaphh)-(0.6*m_Snaphh),0));
	

	TopoDS_Wire WW = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);


	BRepBuilderAPI_MakeWire MW;
	MW.Add(WW);
	MW.Add(E5);
	MW.Add(E6);
	MW.Add(E7);


	TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()),MW);


	TopoDS_Shape S4 = BRepPrimAPI_MakePrism(F,gp_Vec(0,0,(m_SnapHH+(0.6*m_Snaphh))));


	gp_Pnt P7(0,(2*m_Snaphh),-(m_Snaphh));
	TopoDS_Shape theBox5 = BRepPrimAPI_MakeBox(P7,-(0.6*m_SnapLL),-(3*m_Snaphh),(m_SnapHH+(0.6*m_Snaphh)+(2*m_Snaphh)));
	Handle (AIS_Shape)	ais12 = new AIS_Shape(theBox5);
	myAISContext->SetDisplayMode(ais12,1);
	myAISContext->SetColor(ais12,Quantity_NOC_YELLOW);
	myAISContext->SetMaterial(ais12,Graphic3d_NOM_PLASTIC);
	myAISContext->SetTransparency(ais12,0.1);
	myAISContext->Display(ais12);


	Handle (AIS_Shape)	snap = new AIS_Shape(S4);
	myAISContext->SetDisplayMode(snap,1);
	myAISContext->SetColor(snap,Quantity_NOC_MATRABLUE);
	myAISContext->SetMaterial(snap,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(snap);

	Fit();
	}
}

void CSampleViewer3dDoc::OnPressfitHubshafttype() 
{
	// TODO: Add your command handler code here
	CPressFit Dlg;

	if (Dlg.DoModal() == IDOK)
	{

	myAISContext->EraseAll(Standard_False);

	gp_Ax2 CylAx6(gp_Pnt(0,0,100), gp_Dir(gp_Vec(gp_Pnt(0,0,100),gp_Pnt(0,0,-100))));
	TopoDS_Shape Hole = BRepPrimAPI_MakeCylinder(CylAx6,10,18);

	gp_Ax2 CylAx7(gp_Pnt(0,0,82), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole2 = BRepPrimAPI_MakeCylinder(CylAx7,20,8);

	TopoDS_Shape Hub = BRepAlgoAPI_Fuse(Hole,Hole2);

	gp_Ax2 CylAx8(gp_Pnt(0,0,85), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole5 = BRepPrimAPI_MakeCylinder(CylAx8,18,2);

	gp_Ax2 CylAx3(gp_Pnt(0,0,85), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole6 = BRepPrimAPI_MakeCylinder(CylAx3,30,2);
	
	TopoDS_Shape Hole3 = BRepAlgoAPI_Cut(Hole6,Hole5);
	
	TopoDS_Shape Hub2 = BRepAlgoAPI_Cut(Hub,Hole3);

	gp_Ax2 CylAx2(gp_Pnt(0,0,80), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole4 = BRepPrimAPI_MakeCylinder(CylAx2,6,30);

	TopoDS_Shape Hub3 = BRepAlgoAPI_Cut(Hub2,Hole4);

	Handle (AIS_Shape)	ais15 = new AIS_Shape(Hub3);
	myAISContext->SetDisplayMode(ais15,1);
	myAISContext->SetColor(ais15,Quantity_NOC_WHITE);
	myAISContext->SetMaterial(ais15,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais15);

	//shaft
	gp_Ax2 CylAx5(gp_Pnt(0,0,155), gp_Dir(gp_Vec(gp_Pnt(0,0,100),gp_Pnt(0,0,-100))));
	TopoDS_Shape Shaft = BRepPrimAPI_MakeCylinder(CylAx5,6.6,44);

	Handle (AIS_Shape)	ais16 = new AIS_Shape(Shaft);
	myAISContext->SetDisplayMode(ais16,1);
	myAISContext->SetColor(ais16,Quantity_NOC_MATRABLUE);
	myAISContext->SetMaterial(ais16,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais16);

	Fit();
	}
	
}

void CSampleViewer3dDoc::OnLivinghingePoly() 
{
	// TODO: Add your command handler code here
	CHinge Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectBlackstreaks() 
{
	// TODO: Add your command handler code here
	CIJStreak Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectBubbles() 
{
	// TODO: Add your command handler code here
	CIJBubble Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectBurning() 
{
	// TODO: Add your command handler code here
	CIJBurn Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectColdslug() 
{
	// TODO: Add your command handler code here
	CIJCOLD Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectCrazing() 
{
	// TODO: Add your command handler code here
	CIJCraze Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectDelamination() 
{
	// TODO: Add your command handler code here
	CIJDelam Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectMouldflashing() 
{
	// TODO: Add your command handler code here
	CIJFlash Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectPartsbreak() 
{
	// TODO: Add your command handler code here
	CIJEject Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectShortshots() 
{
	// TODO: Add your command handler code here
	CIJShort Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectSinkmarks() 
{
	// TODO: Add your command handler code here
	CIJSink Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectSurfaceimperfection() 
{
	// TODO: Add your command handler code here
	CIJImperfect Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectVariation() 
{
	// TODO: Add your command handler code here
	CIJVariation Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectWarpedparts() 
{
	// TODO: Add your command handler code here
	CIJWarp Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsInjectWeakweld() 
{
	// TODO: Add your command handler code here
	CIJWeak Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingBlisters() 
{
	// TODO: Add your command handler code here
	CMBlister Dlg;
	Dlg.DoModal();
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingBurnedmarks() 
{
	// TODO: Add your command handler code here
	CMBurn Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingExcessiveflash() 
{
	// TODO: Add your command handler code here
	CMFlash Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingMaterialstick() 
{
	// TODO: Add your command handler code here
	CMStick Dlg;
	Dlg.DoModal();
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingOversized() 
{
	// TODO: Add your command handler code here
	CMOversize Dlg;
	Dlg.DoModal();
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingPartscracked() 
{
	// TODO: Add your command handler code here
	CMCrack Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingPorosity() 
{
	// TODO: Add your command handler code here
	CMPorosity Dlg;
	Dlg.DoModal();
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingSurfacedull() 
{
	// TODO: Add your command handler code here
	CMDull Dlg;
	Dlg.DoModal();
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingUndersized() 
{
	// TODO: Add your command handler code here
	CMUndersize Dlg;
	Dlg.DoModal();
}

void CSampleViewer3dDoc::OnManufacturingdefectsMouldingWarpage() 
{
	// TODO: Add your command handler code here
	CMWarp Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnEnvironmentalconcernsReuseplastics() 
{
	// TODO: Add your command handler code here
	CReuse Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnEnvironmentalconcernsRecycling() 
{
	// TODO: Add your command handler code here
	CRecycle Dlg;
	Dlg.DoModal();
	
}

void CSampleViewer3dDoc::OnEnvironmentalconcernsPlasticpackagingcodes() 
{
	// TODO: Add your command handler code here
	CCodes Dlg;
	Dlg.DoModal();	
	
}




//#include "BRepPrimAPI_MakeSphere.hxx"
void CSampleViewer3dDoc::OnBaseCylinder863()
{
	CNewBaseCylinderDlg Dlg;
	if(Dlg.DoModal()!=IDOK) return;

	myAISContext->EraseAll(Standard_False);

    BRepPrimAPI_MakeCylinder B(((Dlg.m_x, Dlg.m_y, Dlg.m_z),(Dlg.m_x1, Dlg.m_y1, Dlg.m_z1)), Dlg.m_h, Dlg.m_r);

	//CreateCyl B(Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_r, Dlg.m_h, TCollection_ExtendedString(Name));

	Handle(AIS_Shape) aBox = new AIS_Shape(B.Shape());

	//Handle (AIS_Shape)	aBox = new AIS_Shape(Shaft);
	myAISContext->SetDisplayMode(aBox,1);
	//myAISContext->SetColor(aBox,Quantity_NOC_MATRABLUE);
	myAISContext->SetMaterial(aBox,Graphic3d_NOM_PLASTIC);
	myAISContext->SetDisplayMode(aBox,1);
	myAISContext->Display(aBox);


	Fit();
	//UpdateAllViews(NULL);
}

void CSampleViewer3dDoc::OnShapeHole()
{
	/*
	// TODO: Add your command handler code here
	myAISContext->EraseAll(Standard_False);

	TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(0,0,0),80);
	
	TopoDS_Shape theSphere2 = BRepPrimAPI_MakeSphere(gp_Pnt(0,20,0),69);
	
	TopoDS_Shape Cut = BRepAlgoAPI_Cut(theSphere,theSphere2);


	gp_Ax2 CylAx8(gp_Pnt(0,-69,0), gp_Dir(gp_Vec(gp_Pnt(0,100,0),gp_Pnt(0,-100,0))));
	TopoDS_Shape Hole = BRepPrimAPI_MakeCylinder(CylAx8,29,88);
	

	TopoDS_Shape Cut5 = BRepAlgoAPI_Fuse(Cut,Hole);


	gp_Pnt P7(0,47,0);
	TopoDS_Shape theBox7 = BRepPrimAPI_MakeBox(P7,150,50,150);


	gp_Pnt P8(0,47,0);
	TopoDS_Shape theBox8 = BRepPrimAPI_MakeBox(P8,-150,50,150);


	gp_Pnt P9(0,47,0);
	TopoDS_Shape theBox9 = BRepPrimAPI_MakeBox(P9,-150,50,-150);


	gp_Pnt P5(0,47,0);
	TopoDS_Shape theBox5 = BRepPrimAPI_MakeBox(P5,150,50,-150);


	TopoDS_Shape Block = BRepAlgoAPI_Fuse(theBox7,theBox8);
	TopoDS_Shape Block2 = BRepAlgoAPI_Fuse(Block,theBox9);
	TopoDS_Shape Block3 = BRepAlgoAPI_Fuse(Block2,theBox5);

	
	TopoDS_Shape Cut2 = BRepAlgoAPI_Cut(Cut5,Block3);

	//Holder
	Handle (AIS_Shape)	ais14 = new AIS_Shape(Cut2);
	myAISContext->SetDisplayMode(ais14,1);
	myAISContext->SetColor(ais14,Quantity_NOC_CORAL2,1);
	myAISContext->SetMaterial(ais14,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais14);


	TopoDS_Shape theSphere3 = BRepPrimAPI_MakeSphere(gp_Pnt(0,180,0),67);


	gp_Ax2 CylAx3(gp_Pnt(0,231,0), gp_Dir(gp_Vec(gp_Pnt(0,-100,0),gp_Pnt(0,100,0))));
	TopoDS_Shape Hole2 = BRepPrimAPI_MakeCylinder(CylAx3,29,88);

	TopoDS_Shape Cut3 = BRepAlgoAPI_Fuse(theSphere3,Hole2);

	Handle (AIS_Shape)	ais16 = new AIS_Shape(Cut3);
	myAISContext->SetDisplayMode(ais16,1);
	myAISContext->SetColor(ais16,Quantity_NOC_AZURE,1);
	myAISContext->SetMaterial(ais16,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais16);

	Fit();

	*/
/*
	CNewBaseCylinderDlg Dlg;
	if(Dlg.DoModal()!=IDOK) return;

	//myAISContext->EraseAll(Standard_False);

    BRepPrimAPI_MakeCylinder B(((Dlg.m_x, Dlg.m_y, Dlg.m_z),(Dlg.m_x1, Dlg.m_y1, Dlg.m_z1)), Dlg.m_h, Dlg.m_r);

	//CreateCyl B(Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_r, Dlg.m_h, TCollection_ExtendedString(Name));

	Handle(AIS_Shape) aHoleCyl = new AIS_Shape(B.Shape());

	//Handle (AIS_Shape)	aBox = new AIS_Shape(Shaft);
	myAISContext->SetDisplayMode(aHoleCyl,1);
	myAISContext->SetColor(aHoleCyl,Quantity_NOC_MATRABLUE);
	myAISContext->SetMaterial(aHoleCyl,Graphic3d_NOM_PLASTIC);
	myAISContext->SetDisplayMode(aHoleCyl,1);
	myAISContext->Display(aHoleCyl);


	Fit(); 
	*/
	//BRepPrimAPI_MakeBox B(gp_Pnt(0,0,0), 5, 5, 5);
	BRepPrimAPI_MakeBox aHoleCyl(gp_Pnt(0,0,0), 5, 5, 5);
	//Handle(AIS_Shape) aBaseBox = new AIS_Shape(B.Shape());
   // Handle(AIS_Shape) aHoleCyl = new AIS_Shape(B.Shape());
	//myAISContext->SetColor(aHoleCyl,Quantity_NOC_RED);
	
	//myAISContext->SetColor(ais14,Quantity_NOC_RED);
	//myAISContext->SetMaterial(aHoleCyl,Graphic3d_NOM_PLASTIC);

	//myAISContext->SetDisplayMode(aHoleCyl,1);
	//myAISContext->Display(aHoleCyl);

	Fit();

//	TopoDS_Shape Cut = BRepAlgoAPI_Cut(aBaseBox,aHoleCyl);
	Sleep(500);

	//TopoDS_Shape Cut = BRepAlgoAPI_Cut(aBaseBox,aHoleCyl);
	TopoDS_Shape Cut = BRepAlgoAPI_Cut(aBaseBox,aHoleCyl);

	Handle (AIS_Shape)	ais18 = new AIS_Shape(Cut);
	myAISContext->SetColor(ais18,Quantity_NOC_MATRABLUE);
	myAISContext->SetMaterial(ais18,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais18);
	
	Fit();
	
}

void CSampleViewer3dDoc::OnBaseGibbose()
{
	// TODO: Add your command handler code here
	myAISContext->EraseAll(Standard_False);

	gp_Ax2 CylAx6(gp_Pnt(0,0,100), gp_Dir(gp_Vec(gp_Pnt(0,0,100),gp_Pnt(0,0,-100))));
	TopoDS_Shape Hole = BRepPrimAPI_MakeCylinder(CylAx6,10,18);

	gp_Ax2 CylAx7(gp_Pnt(0,0,82), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole2 = BRepPrimAPI_MakeCylinder(CylAx7,20,8);

	TopoDS_Shape Hub = BRepAlgoAPI_Fuse(Hole,Hole2);

	gp_Ax2 CylAx8(gp_Pnt(0,0,85), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole5 = BRepPrimAPI_MakeCylinder(CylAx8,18,2);

	gp_Ax2 CylAx3(gp_Pnt(0,0,85), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole6 = BRepPrimAPI_MakeCylinder(CylAx3,30,2);
	
	TopoDS_Shape Hole3 = BRepAlgoAPI_Cut(Hole6,Hole5);
	
	TopoDS_Shape Hub2 = BRepAlgoAPI_Cut(Hub,Hole3);

	gp_Ax2 CylAx2(gp_Pnt(0,0,80), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
	TopoDS_Shape Hole4 = BRepPrimAPI_MakeCylinder(CylAx2,6,30);

	TopoDS_Shape Hub3 = BRepAlgoAPI_Cut(Hub2,Hole4);

	Handle (AIS_Shape)	ais15 = new AIS_Shape(Hub3);
	myAISContext->SetDisplayMode(ais15,1);
	myAISContext->SetColor(ais15,Quantity_NOC_WHITE);
	myAISContext->SetMaterial(ais15,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais15);

/*	//shaft
	gp_Ax2 CylAx5(gp_Pnt(0,0,155), gp_Dir(gp_Vec(gp_Pnt(0,0,100),gp_Pnt(0,0,-100))));
	TopoDS_Shape Shaft = BRepPrimAPI_MakeCylinder(CylAx5,6.6,44);

	Handle (AIS_Shape)	ais16 = new AIS_Shape(Shaft);
	myAISContext->SetDisplayMode(ais16,1);
	myAISContext->SetColor(ais16,Quantity_NOC_MATRABLUE);
	myAISContext->SetMaterial(ais16,Graphic3d_NOM_PLASTIC);
	myAISContext->Display(ais16);
*/
	Fit();
}


void CSampleViewer3dDoc::OnBaseBox()
{
	// TODO: Add your command handler code here
/*
	myAISContext->EraseAll(Standard_False);
	BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
	Handle(AIS_Shape) aBox = new AIS_Shape(B.Shape());
	myAISContext->SetColor(aBox,Quantity_NOC_MATRABLUE);
	myAISContext->SetDisplayMode(aBox,1);
	myAISContext->Display(aBox);	
*/
   

   
	CNewBaseBoxDlg Dlg;
	if(Dlg.DoModal()!=IDOK) return;

	myAISContext->EraseAll(Standard_False);

   // BRepPrimAPI_MakeBox B(gp_Pnt(Dlg.m_x, Dlg.m_y, Dlg.m_z), Dlg.m_w, Dlg.m_l, Dlg.m_h);
	 BRepPrimAPI_MakeBox aBaseBox(gp_Pnt(Dlg.m_x, Dlg.m_y, Dlg.m_z), Dlg.m_w, Dlg.m_l, Dlg.m_h);
	//Handle(AIS_Shape) aBaseBox = new AIS_Shape(B.Shape());
     // aBaseBox = new AIS_Shape(B.Shape());
	//myAISContext->SetColor(aBaseBox,Quantity_NOC_MATRABLUE);
	//myAISContext->SetColor(ais14,Quantity_NOC_RED);
	//myAISContext->SetMaterial(aBaseBox,Graphic3d_NOM_PLASTIC);

	//myAISContext->SetDisplayMode(aBaseBox,1);
	//myAISContext->Display(aBaseBox);

	Fit();

/*	Handle(TDocStd_Document) D = GetSampleViewer3dDoc();

	// Open a new command (for undo)
	D->NewCommand();
	TSampleViewer3d_Commands TSC(D->Main());

	TCollection_AsciiString Name((Standard_CString)(LPCTSTR)Dlg.m_Name);

	// Create a new box using the CNewBoxDlg Dialog parameters as attributes
	TDF_Label L=TSC.CreateBox(Dlg.m_x, Dlg.m_y, Dlg.m_z, Dlg.m_w, Dlg.m_l, Dlg.m_h, TCollection_ExtendedString(Name));

	// Get the TPrsStd_AISPresentation of the new box TNaming_NamedShape
	Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); 
	// Display it
	prs->Display(1);
	Fit3DViews();
	// Attach an integer attribute to L to memorize it's displayed
	TDataStd_Integer::Set(L, 1);
	myAISContext->UpdateCurrentViewer();

	// Close the command (for undo)
	D->CommitCommand();


		TCollection_AsciiString Message ("\
//  Creation of a new box using Ocaf attributes \n\
 \n\
Handle(TDocStd_Document) D = GetOcafDoc(); \n\
 \n\
//  Openning a new command (for undo/redo) \n\
D->NewCommand(); \n\
 \n\
TOcaf_Commands TSC(D->Main()); \n\
// Look at the TOcaf_Commands::CreateBox() function \n\
TDF_Label L=TSC.CreateBox(m_x, m_y, m_z, m_w, m_l, m_h, Name); \n\
 \n\
// Set the TPrsStd_AISPresentation of the box \n\
Handle(TPrsStd_AISPresentation) prs; \n\
prs= TPrsStd_AISPresentation::Set(L, TNaming_NamedShape::GetID()); \n\
 \n\
//  Displaying the box \n\
prs->Display(1); \n\
 \n\
//  Commint the command (for undo/redo) \n\
D->CommitCommand(); \n\
\n");
*/
	//myCResultDialog.SetTitle(CString("Create box"));
	//CString text(Message.ToCString());
	//myCResultDialog.SetText(text);

}

void CSampleViewer3dDoc::OnBaseSphere()
{
	myAISContext->EraseAll(Standard_False);
	// TODO: Add your command handler code here
	BRepPrimAPI_MakeSphere S(gp_Pnt(0,0,0), 100.);
	Handle(AIS_Shape) aSphere = new AIS_Shape(S.Shape());
	myAISContext->SetMaterial(aSphere,Graphic3d_NOM_COPPER);    
	//myAISContext->SetColor(aSphere,Quantity_NOC_MATRABLUE);
	myAISContext->SetDisplayMode(aSphere,1);
	myAISContext->Display(aSphere);

	Fit();

}
