int CheckAndSave() { //Get the filename if we don't have one if (strlen(cSaveName)<=1) GetSaveFile(cWindow.GetHandle()); //Save the meal & make sure it saved bool okay = 0; while(!okay) { if (!SaveMeal()) { switch(MessageBox(cWindow.GetHandle(), "Failed to save the file, do you wish to try again?", "Error", MB_YESNOCANCEL | MB_ICONERROR)) { case IDYES: GetSaveFile(cWindow.GetHandle()); break; case IDNO: return(0); break; case IDCANCEL: return(-1); break; default: break; } } else { okay = 1; } } return(1); }
void dWMShop_c::buyItem(int item) { static int itemDefs[6][3] = { // Cost, Start Index, Count {1, 0, 1}, {2, 1, 1}, {2, 2, 1}, {3, 3, 1}, {5, 4, 3}, {8, 7, 5} }; int cost = itemDefs[item][0], cash = getUnspentStarCoinCount(); if (cost > cash) { OSReport("Started playing Not Enough\n"); lakituModel->playingNotEnough = true; lakituModel->playAnim("notenough", 1.0f, 1); MapSoundPlayer(SoundRelatedClass, SE_SYS_INVALID, 1); return; } MapSoundPlayer(SoundRelatedClass, SE_SYS_DECIDE, 1); SaveFile *file = GetSaveFile(); SaveBlock *block = file->GetBlock(file->header.current_file); coinsRemaining = cost; // Work out what we need to apply int appliedItems[ITEM_TYPE_COUNT]; for (int i = 0; i < ITEM_TYPE_COUNT; i++) appliedItems[i] = 0; int invStartIndex = itemDefs[item][1], invCount = itemDefs[item][2]; for (int i = 0; i < invCount; i++) appliedItems[(int)Inventory[shopKind][invStartIndex+i]]++; for (int i = 0; i < 8; i++) { block->powerups_available[i] += appliedItems[i]; if (block->powerups_available[i] > 99) block->powerups_available[i] = 99; dScKoopatlas_c::instance->stockItem->newCounts[i] = block->powerups_available[i]; } // Apply lives to everyone for (int i = 0; i < 4; i++) { if (Player_Active[i]) { int id = Player_ID[i]; Player_Lives[id] += appliedItems[(int)ONE_UP]; if (Player_Lives[id] > 99) Player_Lives[id] = 99; } } if (appliedItems[(int)ONE_UP] > 0) MapSoundPlayer(SoundRelatedClass, SE_SYS_100COIN_ONE_UP, 1); state.setState(&StateID_CoinCountdown); HideSelectCursor(SelectCursorPointer, 0); }
void HandleMenu(HWND hWnd, DWORD opt) { switch(opt) { case ID_SCALE_CONNECT: cEditBox.SetText("Trying to communicate with the scale..."); mScale.EditItem(ID_SCALE_CONNECT, "&Connecting...", MF_DISABLED); _beginthread(ScaleConnect, 0, (void*) hWnd); break; case ID_FILE_NEW: if (!bSaved && vMealItems.size() > 0) { switch(MessageBox(hWnd, "You haven't saved the current meal, would you like to?","Hold Up!", MB_YESNOCANCEL | MB_ICONINFORMATION)) { case IDYES: if (CheckAndSave()==-1) break; case IDNO: cListBox.Clear(); vMealItems.clear(); strcpy(cSaveName, ""); cWindow.SetTitle("MealTrack - Untitled"); cButton.SetText("Start Meal"); break; case IDCANCEL: default: break; } } else { cListBox.Clear(); vMealItems.clear(); strcpy(cSaveName, ""); cWindow.SetTitle("MealTrack - Untitled"); cButton.SetText("Start Meal"); } break; case ID_FILE_SAVE: GetSaveFile(hWnd); if (vMealItems.size() >= 1) CheckAndSave(); char tmp[313]; sprintf(tmp, "MealTrack - %s", strrchr(cSaveName,'\\') + 1); cWindow.SetTitle(tmp); break; case ID_FILE_EXIT: PostMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_SCALE_ZERO: if (scale != NULL) scale->Zero(); break; } }
void dWMShop_c::executeState_CoinCountdown() { timerForCoinCountdown--; if (timerForCoinCountdown <= 0) { SaveBlock *save = GetSaveFile()->GetBlock(-1); save->spentStarCoins++; // load the coin count int scCount = getUnspentStarCoinCount(); WriteNumberToTextBox(&scCount, CoinCount, false); WriteNumberToTextBox(&scCount, CoinCountShadow, false); layout.enableNonLoopAnim(COUNT_COIN); VEC3 efPos = { CoinCount->effectiveMtx[0][3], CoinCount->effectiveMtx[1][3], 0.0f}; // ARGHHHHHHHHHHHHHHHHh. if (IsWideScreen()) { float div = 5.0f; if (scCount < 100) div = 3.6f; if (scCount < 10) div = 2.7f; efPos.x -= (CoinCount->size.x / div); efPos.y -= (CoinCount->size.y / 2.0f); } else { float div = 5.8f; if (scCount < 100) div = 8.2f; if (scCount < 10) div = 14.5f; efPos.x += (CoinCount->size.x / div); efPos.y -= (CoinCount->size.y / 2.8f); } VEC3 efScale = {0.7f, 0.7f, 0.7f}; SpawnEffect("Wm_2d_moviecoinvanish", 0, &efPos, 0, &efScale); coinsRemaining--; if (coinsRemaining <= 0) { MapSoundPlayer(SoundRelatedClass, SE_PLY_GET_ITEM_AGAIN, 1); state.setState(&StateID_Wait); } else { MapSoundPlayer(SoundRelatedClass, SE_SYS_STAR_COIN_PAY, 1); beginState_CoinCountdown(); } } }
int savemap(void) { FILE *fp; //#ifdef CRIPPLEWARE // StdCrippleMsg(); //#else if ( (fp=GetSaveFile("Save map as:",".map",WorkDir,mapcurfile))==NULL) return(False); fwrite( (char*) &map,sizeof(mapstruct),MLEN*MWID,fp); fwrite( (char*) &mm,sizeof(monmapstruct),LASTMM,fp); fclose(fp); //#endif return(TRUE); }
bool SolveSpace::GetFilenameAndSave(bool saveAs) { std::string newFile = saveFile; if(saveAs || newFile.empty()) { if(!GetSaveFile(&newFile, SLVS_EXT, SLVS_PATTERN)) return false; } if(SaveToFile(newFile)) { AddToRecentList(newFile); saveFile = newFile; unsaved = false; return true; } else { return false; } }
int getStarCoinCount() { SaveBlock *save = GetSaveFile()->GetBlock(-1); int coinsEarned = 0; for (int w = 0; w < 10; w++) { for (int l = 0; l < 42; l++) { u32 conds = save->GetLevelCondition(w, l); if (conds & COND_COIN1) { coinsEarned++; } if (conds & COND_COIN2) { coinsEarned++; } if (conds & COND_COIN3) { coinsEarned++; } } } return coinsEarned; }
bool SolveSpace::GetFilenameAndSave(bool saveAs) { char newFile[MAX_PATH]; strcpy(newFile, saveFile); if(saveAs || strlen(newFile)==0) { if(!GetSaveFile(newFile, SLVS_EXT, SLVS_PATTERN)) return false; } if(SaveToFile(newFile)) { AddToRecentList(newFile); strcpy(saveFile, newFile); unsaved = false; return true; } else { return false; } }
bool SolveSpaceUI::GetFilenameAndSave(bool saveAs) { std::string prevSaveFile = saveFile; if(saveAs || saveFile.empty()) { if(!GetSaveFile(&saveFile, "", SlvsFileFilter)) return false; // need to get new filename directly into saveFile, since that // determines linkFileRel path } if(SaveToFile(saveFile)) { AddToRecentList(saveFile); RemoveAutosave(); unsaved = false; return true; } else { // don't store an invalid save filename saveFile = prevSaveFile; return false; } }
bool SolveSpace::GetFilenameAndSave(bool saveAs) { char prevSaveFile[MAX_PATH]; strcpy(prevSaveFile, saveFile); if(saveAs || strlen(saveFile)==0) { if(!GetSaveFile(saveFile, SLVS_EXT, SLVS_PATTERN)) return false; // need to get new filename directly into saveFile, since that // determines impFileRel path } if(SaveToFile(saveFile)) { AddToRecentList(saveFile); unsaved = false; return true; } else { // don't store an invalid save filename strcpy(saveFile, prevSaveFile); return false; } }
void dWMShop_c::loadInfo() { SaveBlock *save = GetSaveFile()->GetBlock(-1); leftCol.colourise(save->hudHintH, save->hudHintS, save->hudHintL); midCol.colourise(save->hudHintH, save->hudHintS, save->hudHintL); rightCol.colourise(save->hudHintH, save->hudHintS, save->hudHintL); // find out the shop name dScript::Res_c *bmg = GetBMG(); Newer_WriteBMGToTextBox(Title, bmg, 8000+shopKind+1, 99, 0); Newer_WriteBMGToTextBox(TitleShadow, bmg, 8000+shopKind+1, 99, 0); // load the coin count int scCount = getUnspentStarCoinCount(); WriteNumberToTextBox(&scCount, CoinCount, false); WriteNumberToTextBox(&scCount, CoinCountShadow, false); WriteBMGToTextBox(BackText, GetBMG(), 2, 58, 0); WriteBMGToTextBox(BuyText, GetBMG(), 302, 4, 0); }
void SolveSpace::MenuFile(int id) { if(id >= RECENT_OPEN && id < (RECENT_OPEN+MAX_RECENT)) { if(!SS.OkayToStartNewFile()) return; char newFile[MAX_PATH]; strcpy(newFile, RecentFile[id-RECENT_OPEN]); RemoveFromRecentList(newFile); if(SS.LoadFromFile(newFile)) { strcpy(SS.saveFile, newFile); AddToRecentList(newFile); } else { strcpy(SS.saveFile, ""); SS.NewFile(); } SS.AfterNewFile(); return; } switch(id) { case GraphicsWindow::MNU_NEW: if(!SS.OkayToStartNewFile()) break; strcpy(SS.saveFile, ""); SS.NewFile(); SS.AfterNewFile(); break; case GraphicsWindow::MNU_OPEN: { if(!SS.OkayToStartNewFile()) break; char newFile[MAX_PATH] = ""; if(GetOpenFile(newFile, SLVS_EXT, SLVS_PATTERN)) { if(SS.LoadFromFile(newFile)) { strcpy(SS.saveFile, newFile); AddToRecentList(newFile); } else { strcpy(SS.saveFile, ""); SS.NewFile(); } SS.AfterNewFile(); } break; } case GraphicsWindow::MNU_SAVE: SS.GetFilenameAndSave(false); break; case GraphicsWindow::MNU_SAVE_AS: SS.GetFilenameAndSave(true); break; case GraphicsWindow::MNU_EXPORT_PNG: { char exportFile[MAX_PATH] = ""; if(!GetSaveFile(exportFile, PNG_EXT, PNG_PATTERN)) break; SS.ExportAsPngTo(exportFile); break; } case GraphicsWindow::MNU_EXPORT_VIEW: { char exportFile[MAX_PATH] = ""; if(!GetSaveFile(exportFile, VEC_EXT, VEC_PATTERN)) break; // If the user is exporting something where it would be // inappropriate to include the constraints, then warn. if(SS.GW.showConstraints && (StringEndsIn(exportFile, ".txt") || fabs(SS.exportOffset) > LENGTH_EPS)) { Message("Constraints are currently shown, and will be exported " "in the toolpath. This is probably not what you want; " "hide them by clicking the link at the top of the " "text window."); } SS.ExportViewOrWireframeTo(exportFile, false); break; } case GraphicsWindow::MNU_EXPORT_WIREFRAME: { char exportFile[MAX_PATH] = ""; if(!GetSaveFile(exportFile, V3D_EXT, V3D_PATTERN)) break; SS.ExportViewOrWireframeTo(exportFile, true); break; } case GraphicsWindow::MNU_EXPORT_SECTION: { char exportFile[MAX_PATH] = ""; if(!GetSaveFile(exportFile, VEC_EXT, VEC_PATTERN)) break; SS.ExportSectionTo(exportFile); break; } case GraphicsWindow::MNU_EXPORT_MESH: { char exportFile[MAX_PATH] = ""; if(!GetSaveFile(exportFile, MESH_EXT, MESH_PATTERN)) break; SS.ExportMeshTo(exportFile); break; } case GraphicsWindow::MNU_EXPORT_SURFACES: { char exportFile[MAX_PATH] = ""; if(!GetSaveFile(exportFile, SRF_EXT, SRF_PATTERN)) break; StepFileWriter sfw; ZERO(&sfw); sfw.ExportSurfacesTo(exportFile); break; } case GraphicsWindow::MNU_EXIT: if(!SS.OkayToStartNewFile()) break; SS.Exit(); break; default: oops(); } SS.UpdateWindowTitle(); }
// This function is called by the Windows function DispatchMessage() LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT mMsg, WPARAM wParam, LPARAM lParam) { switch (mMsg) { case WM_CREATE: break; case WM_SIZE: break; case WM_COMMAND: //If handle is the window, handle the menu if (hWnd == cWindow.GetHandle()) HandleMenu(hWnd, LOWORD(wParam)); if (LOWORD(wParam) == IDR_START_BUTTON) { //Check if we have a connection to the scale if (scale != NULL && scale->IsConnected()) { //Check if we just finished a meal as well, if we didn't, start one if (!bMealActive) { //If the meal is not active, start it or reset it if (vMealItems.size() == 0) { _beginthread(Meal, 0, (void*)hWnd); } else { vMealItems.clear(); HandleMenu(hWnd, ID_FILE_NEW); } } else { //Otherwise, stop it if (strlen(cSaveName)<=1) GetSaveFile(hWnd); bMealActive = 0; } } } break; case WM_CLOSE: if (strlen(cSaveName) > 1 && !SaveMeal()) { if (CheckAndSave() == -1) break; } else if (!bSaved && vMealItems.size() > 0) { switch(MessageBox(hWnd, "You haven't saved the current meal, would you like to?","Hold Up!", MB_YESNOCANCEL | MB_ICONINFORMATION)) { case IDYES: if (CheckAndSave() == -1) break; case IDNO: if (scale) delete scale; DestroyWindow(hWnd); hWnd = NULL; break; case IDCANCEL: break; default: break; } } else { if (hWnd != NULL) { if (scale) delete scale; DestroyWindow(hWnd); } } break; case WM_DESTROY: PostQuitMessage(0); break; case WM_UPDATE_READING: //Destroy any spare messages if scale is null if (scale == NULL) break; //Retreive the information and print it on the button char tBuf[32]; sprintf(tBuf, "Connected on %s - %.2f %s %s", scale->GetName(), scale->GetWeight(), scale->GetUnit(), (scale->IsStable()?"":"(unstable)")); cEditBox.SetText(tBuf); hScaleThread = (HANDLE)_beginthread(GetScaleReading, 0, (void*) hWnd); break; case WM_SCALE_CONNECTED: ToggleScaleMenu(1); break; case WM_SCALE_DISCONNECTED: ToggleScaleMenu(0); cEditBox.SetText("Disconnected"); break; default: return DefWindowProc (hWnd, mMsg, wParam, lParam); } return 0; }
void SolveSpaceUI::MenuFile(int id) { if(id >= RECENT_OPEN && id < (RECENT_OPEN+MAX_RECENT)) { if(!SS.OkayToStartNewFile()) return; std::string newFile = RecentFile[id - RECENT_OPEN]; SS.OpenFile(newFile); return; } switch(id) { case GraphicsWindow::MNU_NEW: if(!SS.OkayToStartNewFile()) break; SS.saveFile = ""; SS.NewFile(); SS.AfterNewFile(); break; case GraphicsWindow::MNU_OPEN: { if(!SS.OkayToStartNewFile()) break; std::string newFile; if(GetOpenFile(&newFile, "", SlvsFileFilter)) { SS.OpenFile(newFile); } break; } case GraphicsWindow::MNU_SAVE: SS.GetFilenameAndSave(false); break; case GraphicsWindow::MNU_SAVE_AS: SS.GetFilenameAndSave(true); break; case GraphicsWindow::MNU_EXPORT_PNG: { std::string exportFile; if(!GetSaveFile(&exportFile, "", PngFileFilter)) break; SS.ExportAsPngTo(exportFile); break; } case GraphicsWindow::MNU_EXPORT_VIEW: { std::string exportFile; if(!GetSaveFile(&exportFile, CnfThawString("", "ViewExportFormat"), VectorFileFilter)) break; CnfFreezeString(Extension(exportFile), "ViewExportFormat"); // If the user is exporting something where it would be // inappropriate to include the constraints, then warn. if(SS.GW.showConstraints && (FilenameHasExtension(exportFile, ".txt") || fabs(SS.exportOffset) > LENGTH_EPS)) { Message("Constraints are currently shown, and will be exported " "in the toolpath. This is probably not what you want; " "hide them by clicking the link at the top of the " "text window."); } SS.ExportViewOrWireframeTo(exportFile, false); break; } case GraphicsWindow::MNU_EXPORT_WIREFRAME: { std::string exportFile; if(!GetSaveFile(&exportFile, CnfThawString("", "WireframeExportFormat"), Vector3dFileFilter)) break; CnfFreezeString(Extension(exportFile), "WireframeExportFormat"); SS.ExportViewOrWireframeTo(exportFile, true); break; } case GraphicsWindow::MNU_EXPORT_SECTION: { std::string exportFile; if(!GetSaveFile(&exportFile, CnfThawString("", "SectionExportFormat"), VectorFileFilter)) break; CnfFreezeString(Extension(exportFile), "SectionExportFormat"); SS.ExportSectionTo(exportFile); break; } case GraphicsWindow::MNU_EXPORT_MESH: { std::string exportFile; if(!GetSaveFile(&exportFile, CnfThawString("", "MeshExportFormat"), MeshFileFilter)) break; CnfFreezeString(Extension(exportFile), "MeshExportFormat"); SS.ExportMeshTo(exportFile); break; } case GraphicsWindow::MNU_EXPORT_SURFACES: { std::string exportFile; if(!GetSaveFile(&exportFile, CnfThawString("", "SurfacesExportFormat"), SurfaceFileFilter)) break; CnfFreezeString(Extension(exportFile), "SurfacesExportFormat"); StepFileWriter sfw = {}; sfw.ExportSurfacesTo(exportFile); break; } case GraphicsWindow::MNU_IMPORT: { std::string importFile; if(!GetOpenFile(&importFile, CnfThawString("", "ImportFormat"), ImportableFileFilter)) break; CnfFreezeString(Extension(importFile), "ImportFormat"); if(Extension(importFile) == "dxf") { ImportDxf(importFile); } else if(Extension(importFile) == "dwg") { ImportDwg(importFile); } else oops(); break; } case GraphicsWindow::MNU_EXIT: if(!SS.OkayToStartNewFile()) break; SS.Exit(); break; default: oops(); } SS.UpdateWindowTitle(); }
int getUnspentStarCoinCount() { SaveBlock *save = GetSaveFile()->GetBlock(-1); int coinsSpent = save->spentStarCoins; return getStarCoinCount() - coinsSpent; }
void SolveSpaceUI::MenuAnalyze(int id) { SS.GW.GroupSelection(); #define gs (SS.GW.gs) switch(id) { case GraphicsWindow::MNU_STEP_DIM: if(gs.constraints == 1 && gs.n == 0) { Constraint *c = SK.GetConstraint(gs.constraint[0]); if(c->HasLabel() && !c->reference) { SS.TW.shown.dimFinish = c->valA; SS.TW.shown.dimSteps = 10; SS.TW.shown.dimIsDistance = (c->type != Constraint::ANGLE) && (c->type != Constraint::LENGTH_RATIO) && (c->type != Constraint::LENGTH_DIFFERENCE); SS.TW.shown.constraint = c->h; SS.TW.shown.screen = TextWindow::SCREEN_STEP_DIMENSION; // The step params are specified in the text window, // so force that to be shown. SS.GW.ForceTextWindowShown(); SS.ScheduleShowTW(); SS.GW.ClearSelection(); } else { Error("Constraint must have a label, and must not be " "a reference dimension."); } } else { Error("Bad selection for step dimension; select a constraint."); } break; case GraphicsWindow::MNU_NAKED_EDGES: { SS.nakedEdges.Clear(); Group *g = SK.GetGroup(SS.GW.activeGroup); SMesh *m = &(g->displayMesh); SKdNode *root = SKdNode::From(m); bool inters, leaks; root->MakeCertainEdgesInto(&(SS.nakedEdges), SKdNode::NAKED_OR_SELF_INTER_EDGES, true, &inters, &leaks); InvalidateGraphics(); const char *intersMsg = inters ? "The mesh is self-intersecting (NOT okay, invalid)." : "The mesh is not self-intersecting (okay, valid)."; const char *leaksMsg = leaks ? "The mesh has naked edges (NOT okay, invalid)." : "The mesh is watertight (okay, valid)."; std::string cntMsg = ssprintf("\n\nThe model contains %d triangles, from " "%d surfaces.", g->displayMesh.l.n, g->runningShell.surface.n); if(SS.nakedEdges.l.n == 0) { Message("%s\n\n%s\n\nZero problematic edges, good.%s", intersMsg, leaksMsg, cntMsg.c_str()); } else { Error("%s\n\n%s\n\n%d problematic edges, bad.%s", intersMsg, leaksMsg, SS.nakedEdges.l.n, cntMsg.c_str()); } break; } case GraphicsWindow::MNU_INTERFERENCE: { SS.nakedEdges.Clear(); SMesh *m = &(SK.GetGroup(SS.GW.activeGroup)->displayMesh); SKdNode *root = SKdNode::From(m); bool inters, leaks; root->MakeCertainEdgesInto(&(SS.nakedEdges), SKdNode::SELF_INTER_EDGES, false, &inters, &leaks); InvalidateGraphics(); if(inters) { Error("%d edges interfere with other triangles, bad.", SS.nakedEdges.l.n); } else { Message("The assembly does not interfere, good."); } break; } case GraphicsWindow::MNU_VOLUME: { SMesh *m = &(SK.GetGroup(SS.GW.activeGroup)->displayMesh); double vol = 0; int i; for(i = 0; i < m->l.n; i++) { STriangle tr = m->l.elem[i]; // Translate to place vertex A at (x, y, 0) Vector trans = Vector::From(tr.a.x, tr.a.y, 0); tr.a = (tr.a).Minus(trans); tr.b = (tr.b).Minus(trans); tr.c = (tr.c).Minus(trans); // Rotate to place vertex B on the y-axis. Depending on // whether the triangle is CW or CCW, C is either to the // right or to the left of the y-axis. This handles the // sign of our normal. Vector u = Vector::From(-tr.b.y, tr.b.x, 0); u = u.WithMagnitude(1); Vector v = Vector::From(tr.b.x, tr.b.y, 0); v = v.WithMagnitude(1); Vector n = Vector::From(0, 0, 1); tr.a = (tr.a).DotInToCsys(u, v, n); tr.b = (tr.b).DotInToCsys(u, v, n); tr.c = (tr.c).DotInToCsys(u, v, n); n = tr.Normal().WithMagnitude(1); // Triangles on edge don't contribute if(fabs(n.z) < LENGTH_EPS) continue; // The plane has equation p dot n = a dot n double d = (tr.a).Dot(n); // nx*x + ny*y + nz*z = d // nz*z = d - nx*x - ny*y double A = -n.x/n.z, B = -n.y/n.z, C = d/n.z; double mac = tr.c.y/tr.c.x, mbc = (tr.c.y - tr.b.y)/tr.c.x; double xc = tr.c.x, yb = tr.b.y; // I asked Maple for // int(int(A*x + B*y +C, y=mac*x..(mbc*x + yb)), x=0..xc); double integral = (1.0/3)*( A*(mbc-mac)+ (1.0/2)*B*(mbc*mbc-mac*mac) )*(xc*xc*xc)+ (1.0/2)*(A*yb+B*yb*mbc+C*(mbc-mac))*xc*xc+ C*yb*xc+ (1.0/2)*B*yb*yb*xc; vol += integral; } std::string msg = ssprintf("The volume of the solid model is:\n\n"" %.3f %s^3", vol / pow(SS.MmPerUnit(), 3), SS.UnitName()); if(SS.viewUnits == SolveSpaceUI::UNIT_MM) { msg += ssprintf("\n %.2f mL", vol/(10*10*10)); } msg += "\n\nCurved surfaces have been approximated as triangles.\n" "This introduces error, typically of around 1%."; Message("%s", msg.c_str()); break; } case GraphicsWindow::MNU_AREA: { Group *g = SK.GetGroup(SS.GW.activeGroup); if(g->polyError.how != Group::POLY_GOOD) { Error("This group does not contain a correctly-formed " "2d closed area. It is open, not coplanar, or self-" "intersecting."); break; } SEdgeList sel = {}; g->polyLoops.MakeEdgesInto(&sel); SPolygon sp = {}; sel.AssemblePolygon(&sp, NULL, true); sp.normal = sp.ComputeNormal(); sp.FixContourDirections(); double area = sp.SignedArea(); double scale = SS.MmPerUnit(); Message("The area of the region sketched in this group is:\n\n" " %.3f %s^2\n\n" "Curves have been approximated as piecewise linear.\n" "This introduces error, typically of around 1%%.", area / (scale*scale), SS.UnitName()); sel.Clear(); sp.Clear(); break; } case GraphicsWindow::MNU_SHOW_DOF: // This works like a normal solve, except that it calculates // which variables are free/bound at the same time. SS.GenerateAll(SolveSpaceUI::GENERATE_ALL, true); break; case GraphicsWindow::MNU_TRACE_PT: if(gs.points == 1 && gs.n == 1) { SS.traced.point = gs.point[0]; SS.GW.ClearSelection(); } else { Error("Bad selection for trace; select a single point."); } break; case GraphicsWindow::MNU_STOP_TRACING: { std::string exportFile; if(GetSaveFile(&exportFile, "", CsvFileFilter)) { FILE *f = ssfopen(exportFile, "wb"); if(f) { int i; SContour *sc = &(SS.traced.path); for(i = 0; i < sc->l.n; i++) { Vector p = sc->l.elem[i].p; double s = SS.exportScale; fprintf(f, "%.10f, %.10f, %.10f\r\n", p.x/s, p.y/s, p.z/s); } fclose(f); } else { Error("Couldn't write to '%s'", exportFile.c_str()); } } // Clear the trace, and stop tracing SS.traced.point = Entity::NO_ENTITY; SS.traced.path.l.Clear(); InvalidateGraphics(); break; } default: oops(); } }
extern "C" void FAR PASCAL _export SavePict( pAEvtInfo theEvent, pAObjMessage system) { POINT where; int rVal; OBJECTID pObjectID, dObject; char fName[255]; pObjectID = AFuncGetParameter(1); // the picture object to load New picture // into dObject = NULLOBJECTID; system->message1 = 1; if (AObjCheckType( pObjectID, (TYPEID)OTYPE_PICTURE)) { // if a filename is supplied as input then load that file into the // pict object else open up a file-open dlg (W3.1 - commdlg) if ((dObject = AFuncGetTypedParameter(2, OTYPE_TEXT)) != 0L) { OTextGetToBuffer(dObject, fName, MAXNAME); //tPtr = (LPTEXTOBJECT)AObjLockData(dObject, 1); //_fmemcpy(fName, tPtr, AObjGetDataSize(dObject, 1)); if (strcmp(fName, "\0") == 0) rVal = GetSaveFile(pObjectID, fName); // AObjUnlockData(dObject, 1); } else { fName[0] = '\0'; where.x = 40; where.y = 40; rVal = GetSaveFile(pObjectID, fName); } if (rVal) { PICTOBJECT * pObject = (PICTOBJECT *)GetPictObject(pObjectID); rVal = pObject->SavePictFile((LPSTR)fName); if (!rVal) system->message1 = 2; } else system->message1 = 2; } else system->message1 = 2; I_UNUSED(where); I_UNUSED(theEvent); }