/** * @brief cwGeometryItersecter::addTriangles * @param object * * Add the object to the itersector */ void cwGeometryItersecter::addObject(const cwGeometryItersecter::Object &object) { switch(object.type()) { case Triangles: addTriangles(object); break; case Lines: addLines(object); break; default: break; } }
// minO and maxO determine the minimum output and maximum output values that should be mapped onto black respectively white bool add2DFunction(double minX, double minY, double maxX, double maxY, Function<double,0,1> &function) { bool ok = true; vector<double> xs,ys; Vector::set(xs,minX,minX,maxX,maxX,minX); Vector::set(ys,minY,maxY,maxY,minY,minY); ok = addLines(xs,ys); Functions functions; functions.minX = minX; functions.minY = minY; functions.maxX = maxX; functions.maxY = maxY; functions.pFunction = &function; mFunctions.push_back(functions); return ok; }
/* * Read commands until we are told to stop. */ static void doCommands(void) { const char *cp; char *endbuf, buf[USERSIZE]; int len, num1, num2; smallint have1, have2; while (TRUE) { /* Returns: * -1 on read errors or EOF, or on bare Ctrl-D. * 0 on ctrl-C, * >0 length of input string, including terminating '\n' */ len = read_line_input(NULL, ": ", buf, sizeof(buf), /*timeout*/ -1); if (len <= 0) return; endbuf = &buf[len - 1]; while ((endbuf > buf) && isblank(endbuf[-1])) endbuf--; *endbuf = '\0'; cp = skip_blank(buf); have1 = FALSE; have2 = FALSE; if ((curNum == 0) && (lastNum > 0)) { curNum = 1; curLine = lines.next; } if (!getNum(&cp, &have1, &num1)) continue; cp = skip_blank(cp); if (*cp == ',') { cp++; if (!getNum(&cp, &have2, &num2)) continue; if (!have1) num1 = 1; if (!have2) num2 = lastNum; have1 = TRUE; have2 = TRUE; } if (!have1) num1 = curNum; if (!have2) num2 = num1; switch (*cp++) { case 'a': addLines(num1 + 1); break; case 'c': deleteLines(num1, num2); addLines(num1); break; case 'd': deleteLines(num1, num2); break; case 'f': if (*cp && !isblank(*cp)) { bb_error_msg("bad file command"); break; } cp = skip_blank(cp); if (*cp == '\0') { if (fileName) printf("\"%s\"\n", fileName); else puts("No file name"); break; } free(fileName); fileName = xstrdup(cp); break; case 'i': addLines(num1); break; case 'k': cp = skip_blank(cp); if ((*cp < 'a') || (*cp > 'z') || cp[1]) { bb_error_msg("bad mark name"); break; } marks[*cp - 'a'] = num2; break; case 'l': printLines(num1, num2, TRUE); break; case 'p': printLines(num1, num2, FALSE); break; case 'q': cp = skip_blank(cp); if (have1 || *cp) { bb_error_msg("bad quit command"); break; } if (!dirty) return; len = read_line_input(NULL, "Really quit? ", buf, 16, /*timeout*/ -1); /* read error/EOF - no way to continue */ if (len < 0) return; cp = skip_blank(buf); if ((*cp | 0x20) == 'y') /* Y or y */ return; break; case 'r': if (*cp && !isblank(*cp)) { bb_error_msg("bad read command"); break; } cp = skip_blank(cp); if (*cp == '\0') { bb_error_msg("no file name"); break; } if (!have1) num1 = lastNum; if (readLines(cp, num1 + 1)) break; if (fileName == NULL) fileName = xstrdup(cp); break; case 's': subCommand(cp, num1, num2); break; case 'w': if (*cp && !isblank(*cp)) { bb_error_msg("bad write command"); break; } cp = skip_blank(cp); if (!have1) { num1 = 1; num2 = lastNum; } if (*cp == '\0') cp = fileName; if (cp == NULL) { bb_error_msg("no file name specified"); break; } writeLines(cp, num1, num2); break; case 'z': switch (*cp) { case '-': printLines(curNum - 21, curNum, FALSE); break; case '.': printLines(curNum - 11, curNum + 10, FALSE); break; default: printLines(curNum, curNum + 21, FALSE); break; } break; case '.': if (have1) { bb_error_msg("no arguments allowed"); break; } printLines(curNum, curNum, FALSE); break; case '-': if (setCurNum(curNum - 1)) printLines(curNum, curNum, FALSE); break; case '=': printf("%d\n", num1); break; case '\0': if (have1) { printLines(num2, num2, FALSE); break; } if (setCurNum(curNum + 1)) printLines(curNum, curNum, FALSE); break; default: bb_error_msg("unimplemented command"); break; } } }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static int isKeydown = false; int wmId, wmEvent; /* int tempX,tempY;*/ switch (message) { case WM_COMMAND: { wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); switch (wmId) { case IDM_EXIT: DestroyWindow(hWnd); break; case IDM_PENCIL: g_mode = modePENCIL; break; case IDM_POINTS: g_mode = modePOINTS; break; case IDM_LINES: g_mode = modeLINES; break; case IDM_Polygon: g_mode = modePOLYGON; break; case IDM_CIRCLE: g_mode = modeCIRCLE; break; case IDM_COLOR: DialogBox(hInst, (LPCTSTR)IDD_COLORBOX, hWnd, (DLGPROC)colorBox); break; case IDM_SIZEBOX: DialogBox(hInst, (LPCTSTR)IDD_DEFAULTWIDTH, hWnd, (DLGPROC)sizeBox); break; case IDM_CLEAR: { vec[0]->clear(); vec[1]->clear(); for(size_t i=2; i < vec.size(); ++i) delete vec[i]; vec.erase(vec.begin() + 2, vec.end()); InvalidateRect(hWnd, NULL, false); break; } case IDM_ADDPOINT: DialogBox(hInst, (LPCTSTR)IDD_ADDPOINT, hWnd, (DLGPROC)addPointBox); break; case IDM_ADDLINE: DialogBox(hInst, (LPCTSTR)IDD_ADDLINES, hWnd, (DLGPROC)addLineBox); break; case IDM_ADDPOLYGON: DialogBox(hInst, (LPCTSTR)IDD_ADDPOLYGON, hWnd, (DLGPROC)addPolygonBox); break; case IDM_ADDCIRCLE: DialogBox(hInst, (LPCTSTR)IDD_ADDCIRCLE, hWnd, (DLGPROC)addCircleBox); break; case IDM_SAVE: save(hWnd); break; case IDM_HELP: DialogBox(hInst, (LPCTSTR)IDD_HELPBOX, hWnd, (DLGPROC)Help); break; case IDM_DELETEPOINT: vec[0]->eraseLast(); break; case IDM_DELETELINE: vec[1]->eraseLast(); break; case IDM_DELETEOTHER: if(vec.size() >2) vec.erase(vec.end() -1); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; } case WM_RBUTTONDOWN: if(!isKeydown || g_mode != modePOLYGON) break; addLastPoint(lParam); break; case WM_MOUSEMOVE: if(!isKeydown) break; switch(g_mode) { case modePENCIL: addLastPoint(lParam); break; case modePOINTS: addPoints(lParam); break; case modeLINES: modifyLastLine(lParam); break; case modePOLYGON: case modeCIRCLE: modifyLastPoint(lParam); break; } InvalidateRect(hWnd,NULL,false); break; case WM_LBUTTONDOWN: isKeydown = true; switch(g_mode) { case modePENCIL: { Point pnt(LOWORD(lParam),g_clientRect.bottom - HIWORD(lParam)); PicElem* p = new Pencil; p->add(pnt, g_defColor,g_defSize); vec.push_back(p); } break; case modePOINTS: addPoints(lParam); break; case modeLINES: addLines(lParam,lParam); break; case modePOLYGON: { Point pnt(LOWORD(lParam),g_clientRect.bottom - HIWORD(lParam)); PicElem* p = new Polygons; p->add(pnt, pnt, g_defColor,g_defSize); p->add(pnt, g_defColor,g_defSize); vec.push_back(p); } break; case modeCIRCLE: { Point pnt(LOWORD(lParam),g_clientRect.bottom - HIWORD(lParam)); PicElem* p = new Circles; p->add(pnt, g_defColor, g_defSize); vec.push_back(p); } } InvalidateRect(hWnd,NULL,false); break; case WM_LBUTTONUP: isKeydown = false; break; case WM_SIZE: { GetClientRect(g_hwnd, &g_clientRect); g_cliWidth = g_clientRect.right - g_clientRect.left; g_cliHeight = g_clientRect.bottom - g_clientRect.top; GetWindowRect(g_hwnd, &g_rect); g_scrWidth = g_rect.right - g_rect.left; g_scrHeight = g_rect.bottom - g_rect.top; if(g_cliWidth > 0 && g_cliHeight > 0) SceneResizeViewport(g_cliWidth, g_cliHeight); } break; case WM_CHAR: switch(wParam) { case '\n': case '\r': glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; case ' ': glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break; } case WM_PAINT: SceneShow(); ValidateRect(hWnd,NULL); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/* * Read commands until we are told to stop. */ static void doCommands(void) { const char *cp; char *endbuf, *newname, buf[USERSIZE]; int len, num1, num2, have1, have2; while (TRUE) { printf(": "); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) return; len = strlen(buf); if (len == 0) return; endbuf = &buf[len - 1]; if (*endbuf != '\n') { bb_error_msg("command line too long"); do { len = fgetc(stdin); } while ((len != EOF) && (len != '\n')); continue; } while ((endbuf > buf) && isblank(endbuf[-1])) endbuf--; *endbuf = '\0'; cp = buf; while (isblank(*cp)) cp++; have1 = FALSE; have2 = FALSE; if ((curNum == 0) && (lastNum > 0)) { curNum = 1; curLine = lines.next; } if (!getNum(&cp, &have1, &num1)) continue; while (isblank(*cp)) cp++; if (*cp == ',') { cp++; if (!getNum(&cp, &have2, &num2)) continue; if (!have1) num1 = 1; if (!have2) num2 = lastNum; have1 = TRUE; have2 = TRUE; } if (!have1) num1 = curNum; if (!have2) num2 = num1; switch (*cp++) { case 'a': addLines(num1 + 1); break; case 'c': deleteLines(num1, num2); addLines(num1); break; case 'd': deleteLines(num1, num2); break; case 'f': if (*cp && !isblank(*cp)) { bb_error_msg("bad file command"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { if (fileName) printf("\"%s\"\n", fileName); else printf("No file name\n"); break; } newname = strdup(cp); if (newname == NULL) { bb_error_msg("no memory for file name"); break; } if (fileName) free(fileName); fileName = newname; break; case 'i': addLines(num1); break; case 'k': while (isblank(*cp)) cp++; if ((*cp < 'a') || (*cp > 'a') || cp[1]) { bb_error_msg("bad mark name"); break; } marks[*cp - 'a'] = num2; break; case 'l': printLines(num1, num2, TRUE); break; case 'p': printLines(num1, num2, FALSE); break; case 'q': while (isblank(*cp)) cp++; if (have1 || *cp) { bb_error_msg("bad quit command"); break; } if (!dirty) return; printf("Really quit? "); fflush(stdout); buf[0] = '\0'; fgets(buf, sizeof(buf), stdin); cp = buf; while (isblank(*cp)) cp++; if ((*cp == 'y') || (*cp == 'Y')) return; break; case 'r': if (*cp && !isblank(*cp)) { bb_error_msg("bad read command"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { bb_error_msg("no file name"); break; } if (!have1) num1 = lastNum; if (readLines(cp, num1 + 1)) break; if (fileName == NULL) fileName = strdup(cp); break; case 's': subCommand(cp, num1, num2); break; case 'w': if (*cp && !isblank(*cp)) { bb_error_msg("bad write command"); break; } while (isblank(*cp)) cp++; if (!have1) { num1 = 1; num2 = lastNum; } if (*cp == '\0') cp = fileName; if (cp == NULL) { bb_error_msg("no file name specified"); break; } writeLines(cp, num1, num2); break; case 'z': switch (*cp) { case '-': printLines(curNum-21, curNum, FALSE); break; case '.': printLines(curNum-11, curNum+10, FALSE); break; default: printLines(curNum, curNum+21, FALSE); break; } break; case '.': if (have1) { bb_error_msg("no arguments allowed"); break; } printLines(curNum, curNum, FALSE); break; case '-': if (setCurNum(curNum - 1)) printLines(curNum, curNum, FALSE); break; case '=': printf("%d\n", num1); break; case '\0': if (have1) { printLines(num2, num2, FALSE); break; } if (setCurNum(curNum + 1)) printLines(curNum, curNum, FALSE); break; default: bb_error_msg("unimplemented command"); break; } } }