📄 test6view.cpp
字号:
// test6View.cpp :implementation of the Ctest6View class
//
// Standard includes
#include "StdAfx.h"
#include "Resource.h"
#include <afxtempl.h>
#include "hc.h"
#include "HStream.h"
#include "HOpcodeHandler.h"
#include "Htest6SelectionSet.h"
#include "test6.h"
#include "test6View.h"
#include "test6Doc.h"
#include "CHoopsFrm.h"
// HOOPS/MVO includes
#include "Htest6View.h"
#include "Htest6Model.h"
#include "HGlobals.h"
#include "vlist.h"
#include "HBaseOperator.h"
#include "HEventInfo.h"
#include "HBaseView.h"
#include "HBaseOperator.h"
#include "HOpCameraPan.h"
#include "HOpCameraZoom.h"
#include "HOpCameraOrbit.h"
#include "HOpCameraZoomBox.h"
#include "HOpSelectArea.h"
#include "HEventInfo.h"
#include "HModelInfo.h"
#include "HUtilityLocaleString.h"
#include "HOpCreateSolidSphere.h"
#include "HOpcodeShell.h"
#include "MainFrm.h"
#include "Htest6SelectionSet.h"
#include "HUtility.h"
extern Ctest6App theApp;
/////////////////////////////////////////////////////////////////////////////
// Ctest6View
IMPLEMENT_DYNCREATE(Ctest6View, CHoopsView)
Ctest6View::Ctest6View()
{
}
Ctest6View::~Ctest6View()
{
CleanUp();
}
void Ctest6View::CleanUp()
{
delete m_pHView;
m_pHView = 0;
}
BEGIN_MESSAGE_MAP(Ctest6View, CHoopsView)
//{{AFX_MSG_MAP(Ctest6View)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_COMMAND(ID_ZOOM, OnZoom)
ON_COMMAND(ID_ZOOM_TO_EXTENTS, OnZoomToExtents)
ON_COMMAND(ID_ZOOM_TO_WINDOW, OnZoomToWindow)
ON_COMMAND(ID_ORBIT, OnOrbit)
ON_COMMAND(ID_PAN, OnPan)
ON_COMMAND(ID_WINDOW_SELECT, OnWindowSelect)
ON_UPDATE_COMMAND_UI(ID_WINDOW_SELECT, OnUpdateWindowSelect)
ON_COMMAND(ID_SELECTION_DELETESELECTION, OnSelectionDeleteselection)
ON_UPDATE_COMMAND_UI(ID_SELECTION_DELETESELECTION, OnUpdateSelectionDeleteselection)
ON_COMMAND(ID_CREATE_SPHERE, OnCreateSphere)
ON_UPDATE_COMMAND_UI(ID_CREATE_SPHERE, OnUpdateCreateSphere)
ON_UPDATE_COMMAND_UI(ID_ORBIT, OnUpdateOrbit)
ON_UPDATE_COMMAND_UI(ID_PAN, OnUpdatePan)
ON_UPDATE_COMMAND_UI(ID_ZOOM, OnUpdateZoom)
ON_UPDATE_COMMAND_UI(ID_ZOOM_TO_WINDOW, OnUpdateZoomToWindow)
ON_COMMAND(ID_TOOLS_RENDERMODE_GOURAUDSHADED, OnToolsRendermodeGouraudshaded)
ON_COMMAND(ID_TOOLS_RENDERMODE_HIDDENLINE, OnToolsRendermodeHiddenline)
ON_COMMAND(ID_TOOLS_RENDERMODE_WIREFRAME, OnToolsRendermodeWireframe)
ON_UPDATE_COMMAND_UI(ID_TOOLS_RENDERMODE_WIREFRAME, OnUpdateToolsRendermodeWireframe)
ON_UPDATE_COMMAND_UI(ID_TOOLS_RENDERMODE_GOURAUDSHADED, OnUpdateToolsRendermodeGouraudshaded)
ON_UPDATE_COMMAND_UI(ID_TOOLS_RENDERMODE_HIDDENLINE, OnUpdateToolsRendermodeHiddenline)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Ctest6View diagnostics
#ifdef _DEBUG
void Ctest6View::AssertValid() const
{
CHoopsView::AssertValid();
}
void Ctest6View::Dump(CDumpContext& dc) const
{
CHoopsView::Dump(dc);
}
#endif //_DEBUG
void Ctest6View::LocalSetOperator(HBaseOperator * NewOperator)
{
HBaseOperator * op = GetSolidView()->GetOperator();
if (op)
delete op;
GetSolidView()->SetOperator(NewOperator);
}
/////////////////////////////////////////////////////////////////////////////
// Ctest6View message handlers
void Ctest6View::OnFileSaveAs()
{
CString filter;
CString vanilla_filter = "HOOPS Stream File (*.hsf)|*.hsf|HOOPS Metafile (*.hmf)|*.hmf||";
// Agreements/Contracts do not want acispartviewer to publish hsf,hmf and html formats.
// hiding the same from the user - Rajesh B (10-Oct-01)
vanilla_filter = "TIFF Image File (*.tif)|*.tif||";
CString solid_mod_filter = "Acis Part file (*.sat)|*.sat||";
// IMPORTANT - the def_file_ext is purposely NULL, so that file dialog doesn't add .sat
// when somebody types foo.hsf - we still wanna developers/customers be able to save .hsf files "under the table"
char* def_file_ext = 0;
if (!((Htest6Model *)(m_pHView->GetModel()))->IsSolidModel())
filter = vanilla_filter;
else
filter = solid_mod_filter;
CFileDialog my_dlg(FALSE, H_TEXT(def_file_ext), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN,
filter , NULL);
if (my_dlg.DoModal() != IDOK)
return;
SaveFile( my_dlg.GetPathName());
}
bool Ctest6View::SaveFile( LPCTSTR csFilePathName )
{
assert( CString(csFilePathName).IsEmpty() == FALSE );
int width = 500, height = 500;
Ctest6Doc * pDoc = (Ctest6Doc *)GetDocument();
HC_Control_Update_By_Key (m_pHView->GetViewKey(), "redraw everything");
m_pHView->Update();
char extension[1024];
unsigned int i;
extension[0]='\0';
HC_Parse_String(H_ASCII_TEXT(csFilePathName), ".", -1, extension);
// make it lower case
for(i = 0; i < strlen(extension); i++)
extension[i] = (char) tolower(extension[i]);
if(_tcscmp(csFilePathName, _T("")))
{
char extension[1024];
unsigned int i;
bool result = true;
extension[0]='\0';
HC_Parse_String(H_ASCII_TEXT(csFilePathName), ".", -1, extension);
for(i = 0; i < strlen(extension); i++)
extension[i] = (char) tolower(extension[i]);
if (streq(extension, "hsf")) // Write HOOPS Stream File
{
HC_Open_Segment_By_Key(m_pHView->GetModel()->GetModelKey());
HStreamFileToolkit *mytool = new HStreamFileToolkit;
if (((Htest6Model *)m_pHView->GetModel())->IsSolidModel())
{
HC_Set_User_Value(1L);
}
if (HTK_Write_Stream_File(H_ASCII_TEXT(csFilePathName),mytool) == TK_Error)
result = false;
delete mytool;
HC_Close_Segment();
}
else
((Htest6Model*)pDoc->m_pHoopsModel)->Write(H_ASCII_TEXT(csFilePathName), m_pHView, 0, width, height);
AfxGetApp()->AddToRecentFileList(csFilePathName);
}
return true;
}
// resets the camera to view the world space extents of the model
void Ctest6View::OnZoomToExtents()
{
m_pHView->ZoomToExtents();
m_pHView->Update();
}
void Ctest6View::OnZoom()
{
LocalSetOperator(new HOpCameraZoom(m_pHView));
((HOpCameraZoom *)m_pHView->GetOperator())->SetLightFollowsCamera(true);
}
void Ctest6View::OnZoomToWindow()
{
LocalSetOperator(new HOpCameraZoomBox(m_pHView));
((HOpCameraZoomBox *)m_pHView->GetOperator())->SetLightFollowsCamera(true);
}
void Ctest6View::OnOrbit()
{
LocalSetOperator(new HOpCameraOrbit(m_pHView));
((HOpCameraOrbit *)m_pHView->GetOperator())->SetLightFollowsCamera(true);
}
void Ctest6View::OnPan()
{
LocalSetOperator(new HOpCameraPan(m_pHView));
}
void Ctest6View::OnWindowSelect()
{
LocalSetOperator(new HOpSelectArea(m_pHView));
}
void Ctest6View::OnSelectionDeleteselection()
{
m_pHView->DeleteSelectionList(true);
m_pHView->Update();
}
void Ctest6View::OnUpdateSelectionDeleteselection(CCmdUI* pCmdUI)
{
Htest6SelectionSet* sel_set = (Htest6SelectionSet*) m_pHView->GetSelection();
if((sel_set->GetSelectLevel() == BODY_TYPE) && (sel_set->GetSize() > 0))
pCmdUI->Enable(1);
else
pCmdUI->Enable(0);
}
void Ctest6View::OnUpdateGouraud(CCmdUI* pCmdUI)
{
if (m_pHView->GetRenderMode() == HRenderGouraud)
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnUpdateHiddenLine(CCmdUI* pCmdUI)
{
if (m_pHView->GetRenderMode() == HRenderHiddenLine)
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnUpdateOrbit(CCmdUI* pCmdUI)
{
if (streq(m_pHView->GetOperator()->GetName(), "HOpCameraOrbit"))
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnUpdatePan(CCmdUI* pCmdUI)
{
if (streq(m_pHView->GetOperator()->GetName(), "HOpCameraPan"))
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnUpdateZoom(CCmdUI* pCmdUI)
{
if (streq(m_pHView->GetOperator()->GetName(),"HOpCameraZoom"))
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnUpdateZoomToWindow(CCmdUI* pCmdUI)
{
if (streq(m_pHView->GetOperator()->GetName(), "HOpCameraZoomBox"))
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnUpdateWindowSelect(CCmdUI* pCmdUI)
{
if (streq(m_pHView->GetOperator()->GetName(), "HOpSelectArea"))
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnCreateSphere()
{
LocalSetOperator(new HOpCreateSolidSphere(m_pHView));
}
void Ctest6View::OnUpdateCreateSphere(CCmdUI* pCmdUI)
{
if (streq(m_pHView->GetOperator()->GetName(), "HOpCreateSolidSphere"))
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
// this functions creates a new Htest6View Object, and initializes its camera,
// render mode, query dialog, and operator
void Ctest6View::OnInitialUpdate()
{
char szTemp[256];
// we must call the base class initialization first to get the proper palette for this view
// (either the same palette is shared among all views, or this view has a unique palette)
CHoopsView::OnInitialUpdate();
// create the the Hoops View object to be associated with this MFC View
// as well as a generic HOOPS segment hierarchy
Ctest6Doc * pDoc = (Ctest6Doc *)GetDocument();
ASSERT_VALID(pDoc);
HBaseModel * hmodel = pDoc->GetHoopsModel();
// create the HOOPS ParaView object corresponding with this MFC View, passing in the
// Model Object, the MFC View's window handle, and palette
m_pHView = new Htest6View(hmodel, 0, "opengl", 0, (void *) m_hWnd, (void *)(HPALETTE)*(GetPalette()));
// initialize and set the default conditions viz. operator, rendermode etc.
((Htest6View *)m_pHView)->Init();
// set the DEBUG_NO_WINDOWS_HOOK debug bit since the app will manage
// all palette and update messages
long debug_flags = DEBUG_NO_WINDOWS_HOOK;
// since memory on gfx cards is often limited let's use a 16 bit OpenGL z-buffer
// (with OpenGL we're double buffering and often running on true color devices)
if (streq(m_pHView->GetDriverType(), "opengl"))
debug_flags |= DEBUG_16BIT_ZBUFFER;
sprintf (szTemp, "debug = %u", debug_flags);
HC_Open_Segment_By_Key(m_pHView->GetViewKey());
HC_Set_Driver_Options(szTemp);
HC_Set_Driver_Options("special events, update interrupts");
HC_Control_Update(".", "redraw everything");
HC_Close_Segment();
LocalSetOperator(new HOpCameraOrbit(m_pHView));
((HOpCameraOrbit *)m_pHView->GetOperator())->SetLightFollowsCamera(true);
m_pHView->RenderGouraud(); // set the render mode to gouraud
m_pHView->FitWorld(); // fit the camera to the scene extents
m_pHView->CameraPositionChanged();
//we need to adjust the axis window outside the mvo class as the calculation of the window
//extents is mfc specific
AdjustAxisWindow();
}
void Ctest6View::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// The default color of lines and edges is white, need to re-set them to
// a different color so that they will be visibile when printed. Since
// the color is set in the parent segment, the new color setting will only
// affect geometry which has not got a color set explicitly.
HC_Open_Segment_By_Key(GetSceneKey());
HC_Set_Color_By_Index("edges, lines, text", 4);
HC_Close_Segment();
CHoopsView::OnPrint(pDC, pInfo);
// reset edge/line colors back to their orignial state
HC_Open_Segment_By_Key(GetSceneKey());
HC_Set_Color_By_Index("edges, lines, text", 1);
HC_Close_Segment();
m_pHView->Update();
}
void Ctest6View::OnToolsRendermodeGouraudshaded()
{
m_pHView->SetRenderMode(HRenderGouraud, true);
m_pHView->Update();
}
void Ctest6View::OnUpdateToolsRendermodeGouraudshaded(CCmdUI* pCmdUI)
{
if (m_pHView->GetRenderMode() == HRenderGouraud)
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnToolsRendermodeHiddenline()
{
m_pHView->SetRenderMode(HRenderHiddenLine, true);
m_pHView->Update();
}
void Ctest6View::OnUpdateToolsRendermodeHiddenline(CCmdUI* pCmdUI)
{
if (m_pHView->GetRenderMode() == HRenderHiddenLine || m_pHView->GetRenderMode() == HRenderHiddenLineHOOPS)
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnToolsRendermodeWireframe()
{
m_pHView->SetRenderMode(HRenderWireframe, true);
m_pHView->Update();
}
void Ctest6View::OnUpdateToolsRendermodeWireframe(CCmdUI* pCmdUI)
{
if (m_pHView->GetRenderMode() == HRenderWireframe)
pCmdUI->SetCheck (1);
else
pCmdUI->SetCheck (0);
}
void Ctest6View::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
if (!bActivate)
{
HOpCameraOrbit *op = (HOpCameraOrbit *)m_pHView->GetOperator();
if (strcmp(op->GetName(),"HOpCameraOrbit")==0)
op->m_Angle1 = op->m_Angle2 = op->m_Angle3 = 0;
if( GetFirstUpdate() == true)
m_pHView->Update();
}
Ctest6View *act = (Ctest6View *)pActivateView;
Ctest6View *deact = (Ctest6View *)pDeactiveView;
CHoopsView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -