// Create an element of the current type CElement* CSketcherView::CreateElement() { // Get a pointer to the document for this view CSketcherDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // Now select the element using the type stored in the document switch( pDoc->GetElementType() ) { case RECTANGLE: return new CRectangle( m_FirstPoint, m_SecondPoint, pDoc->GetElementColor() ); case CIRCLE: return new CCircle( m_FirstPoint, m_SecondPoint, pDoc->GetElementColor() ); case CURVE: return new CCurve( pDoc->GetElementColor() ); case LINE: return new CLine( m_FirstPoint, m_SecondPoint, pDoc->GetElementColor() ); default: // Something's gone wrong AfxMessageBox("Bad Element code", MB_OK ); AfxAbort(); return NULL; } }