//--------------------------------------------------------------------------- void CFabAtHomeView::OnViewCurrentpath() //--------------------------------------------------------------------------- { CFabAtHomeDoc* pDoc = GetDocument(); int n = pDoc->model.fab.layer.GetSize(); bFollowCurrentLayer = true; UpdateCurrentLayer(); firstlayer = lastlayer; CString msg; msg.Format("Showing layer %d of %d",firstlayer+1,n); pDoc->model.SetStatusMsg(msg); }
LRESULT CALLBACK WndLayersProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; RECT rect; switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rect); DrawLayers(hdc, MARGIN, MARGIN, rect.right - BUTTON_WIDTH, rect.bottom - MARGIN, SendDlgItemMessage(GetDlgItem(GetParent(hWnd), IDC_GRAPH_WINDOW), IDC_RADIO_1, BM_GETCHECK, NULL, NULL)); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: { short y; y = HIWORD(lParam); double snowHeight = CSnow::current()->getSnowHeight(); GetClientRect(hWnd, &rect); double winHeight = rect.bottom; double dy = (winHeight - y)*snowHeight/(winHeight - MARGIN); double h = 0; for (int l = 0; l < CSnow::current()->getLayersNum(); l++) { if (dy < (h = h + CSnow::current()->getLayer(l)->GetHeight())) { CSnow::current()->setSelection(l); //ListView_SetItemState(GetDlgItem(GetParent(hWnd), IDC_LAYERS_LIST), l, ); //ListView_SetSelectionMark(GetDlgItem(GetParent(hWnd), IDC_LAYERS_LIST), l); HWND hListview = GetDlgItem(GetParent(hWnd), IDC_LAYERS_LIST); ListView_SetItemState(hListview, ListView_GetItemCount(hListview) - l - 1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); break; } } UpdateCurrentLayer(); break; } case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
//--------------------------------------------------------------------------- void CFabAtHomeView::DrawScene(void) //--------------------------------------------------------------------------- {// draw the scene m_bDrawing = true; CFabAtHomeDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CSingleLock lockModel(&pDoc->model.m_mutAccess); lockModel.Lock(100); if(!lockModel.IsLocked()) return; CFabAtHomeApp *pApp = (CFabAtHomeApp *) AfxGetApp(); CVec platetop(0,0,0); //get the graphics position (offset by PrinterComponent home from the hardware home (0,0,0). if (pApp->printer.IsDefined()) platetop = pApp->printer.component[3].GetGraphicsRTPos() + pApp->printer.component[3].pmax; // background glClearColor(1,1,1,1); ReportGLError(CString("ClearColor")); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ReportGLError(CString("Clear")); // lighting SetLighting(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); ReportGLError(CString("PolygonMode")); // draw glPushMatrix(); ReportGLError(CString("PushMatrix1")); if(bPanning) { view.x=(eye.x+view.z)/view.z; view.y=(eye.y+view.z)/view.z; } gluLookAt(eye.x, eye.y, eye.z, view.x, view.y, view.z, up.x, up.y, up.z); ReportGLError(CString("gluLookAt")); glMultMatrixd(rotmat); ReportGLError(CString("MultMatrix")); glPushMatrix(); ReportGLError(CString("PushMatrix2")); glEnable(GL_NORMALIZE); ReportGLError(CString("Enable")); if(bShowPrinter) { ((CFabAtHomeApp*) AfxGetApp())->printer.Draw(); ReportGLError(CString("printer.Draw")); } // model glPushMatrix(); ReportGLError(CString("PushMatrix3")); glTranslated(0,0,platetop.z); ReportGLError(CString("Translate")); DrawMainAxes(20); ReportGLError(CString("DrawAxes")); glPushName(1); ReportGLError(CString("PushName1")); glLoadName(NAMESTACK_CHUNK); ReportGLError(CString("LoadName1")); glPushName(NAMESTACK_CHUNK); ReportGLError(CString("PushName")); if (bShowModel) { glColor3d(0.4,0.8,0.2); for (int i=0; i<pDoc->model.chunk.GetSize(); i++) { glLoadName(i); ReportGLError(CString("LoadName2")); pDoc->model.chunk[i].Draw(&pDoc->model, bModelNormals, bShaded); ReportGLError(CString("DrawChunk")); } } glPopName(); ReportGLError(CString("PopName1")); // paths if(bFollowCurrentLayer) { UpdateCurrentLayer(); } pDoc->model.fab.DrawLayers(&pDoc->model, firstlayer, lastlayer, bShowPaths, bShowTrace); ReportGLError(CString("DrawLayers")); glColor3d(1,1,1); ReportGLError(CString("Color3d")); glLineWidth(5); ReportGLError(CString("LineWidth1")); glLineWidth(1); ReportGLError(CString("LineWidth2")); glPopName(); ReportGLError(CString("PopName2")); glPopMatrix(); ReportGLError(CString("PopMatrix1")); glPopMatrix(); ReportGLError(CString("PopMatrix2")); // end glDisable(GL_COLOR_MATERIAL); ReportGLError(CString("Disable")); glPopMatrix(); ReportGLError(CString("PopMatrix3")); glFinish(); ReportGLError(CString("Finish")); HDC localDC = wglGetCurrentDC(); ASSERT(localDC != NULL); SwapBuffers(localDC); ReportGLError(CString("SwapBuffers")); m_bDrawing = false; }