Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

StL Data File Viewer

, 5 Mar 2003 GPL3
A simple StereoLithography data file viewer.
// StLViewerDoc.cpp : implementation of the CStLViewerDoc class
//

#include "stdafx.h"
#include "StLViewer.h"

#include "StLViewerDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStLViewerDoc

IMPLEMENT_DYNCREATE(CStLViewerDoc, CDocument)

BEGIN_MESSAGE_MAP(CStLViewerDoc, CDocument)
	//{{AFX_MSG_MAP(CStLViewerDoc)
	ON_COMMAND(ID_READSTL, OnReadstl)
	ON_COMMAND(ID_STLOBJ_COLOR, OnStlobjColor)
	ON_COMMAND(ID_STLOBJ_MATERIAL, OnStlobjMaterial)
	ON_COMMAND(ID_STLOBJ_ERASE, OnStlobjErase)
	ON_COMMAND(ID_STLOBJ_DELETE, OnStlobjDelete)
	ON_COMMAND(ID_SCREEN_DISPLAYALL, OnScreenDisplayall)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

const TCHAR CStLViewerDoc::m_szFilters[] = _T("STL Files (*.stl)|*.stl|All Files (*.*)|*.*||");

/////////////////////////////////////////////////////////////////////////////
// CStLViewerDoc construction/destruction

CStLViewerDoc::CStLViewerDoc()
{
	// TODO: add one-time construction code here
	dContext = new CGLDisplayContext(this);
}

CStLViewerDoc::~CStLViewerDoc()
{
	delete dContext;
}

BOOL CStLViewerDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CStLViewerDoc serialization

void CStLViewerDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CStLViewerDoc diagnostics

#ifdef _DEBUG
void CStLViewerDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CStLViewerDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CStLViewerDoc commands


void CStLViewerDoc::OnReadstl() 
{
	// TODO: Add your command handler code here
	CWaitCursor aWaitCursor;
	CFileDialog dlg(TRUE, _T("stl"), _T("*.stl"),OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
		m_szFilters);
	CString ext, m_stlPathName;
	if(dlg.DoModal()==IDOK)
	{
		m_stlPathName = dlg.GetPathName();
		ext = dlg.GetFileExt();
		if(strcmp("stl",(LPCTSTR)ext)==0 || strcmp("STL",(LPCTSTR)ext)==0)
		{
			CStLReader* m_Reader = new CStLReader(m_stlPathName);
			CStLObject* m_stlObj = new CStLObject(m_Reader);
			dContext->Display(m_stlObj);
			delete m_stlObj;
			delete m_Reader;
		}
		else
			MessageBox(0, "File Format Not Recognized!!","StLViewer Error", MB_OK | MB_ICONERROR);
	}
	UpdateAllViews(NULL);
}

//Popup Menu

void CStLViewerDoc::OnStlobjColor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlg;
	dlg.m_cc.Flags |= CC_RGBINIT;
	dlg.m_cc.rgbResult = RGB(255, 0, 0);
	if(dlg.DoModal()==IDOK)
	{
		COLORREF color = dlg.GetColor();
		GLubyte m_Red = (GLubyte) GetRValue(color);
		GLubyte m_Green = (GLubyte) GetGValue(color);
		GLubyte m_Blue = (GLubyte) GetBValue(color);
		for(dContext->InitSelected(); dContext->MoreSelected(); dContext->NextSelected())
		{
			CGLObject* O = dContext->CurrentSelected();
			O->SetColor(m_Red, m_Green, m_Blue);
		}
		UpdateAllViews(NULL);
	}
}

#include "MaterialDlg.h"
void CStLViewerDoc::OnStlobjMaterial() 
{
	// TODO: Add your command handler code here
	CMaterialDlg dlg;
	if(dlg.DoModal() == IDOK)
	{
		for(dContext->InitSelected(); dContext->MoreSelected(); dContext->NextSelected())
		{
			CGLObject* O = dContext->CurrentSelected();
			O->SetMaterial(dlg.m_Matl);
		}
		UpdateAllViews(NULL);
	}
}

void CStLViewerDoc::OnStlobjErase() 
{
	// TODO: Add your command handler code here
	dContext->EraseSelected();
}

void CStLViewerDoc::OnStlobjDelete() 
{
	// TODO: Add your command handler code here
	dContext->DeleteSelected();
}


void CStLViewerDoc::OnScreenDisplayall() 
{
	// TODO: Add your command handler code here
	dContext->DisplayAll();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Sharjith
Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid