- minor solver fix for msvc compilation
authorNils Thuerey <nils@thuerey.de>
Mon, 10 Oct 2005 11:31:06 +0000 (11:31 +0000)
committerNils Thuerey <nils@thuerey.de>
Mon, 10 Oct 2005 11:31:06 +0000 (11:31 +0000)
- added pop up menues for fluid sim bake with no
  fluid objects or without valid output dir settings
- fixed 3d view redraw for fluidsim buttons

intern/elbeem/intern/lbmfsgrsolver.h
source/blender/include/butspace.h
source/blender/src/buttons_object.c
source/blender/src/fluidsim.c

index febfe5da59c213733c732eb105d41d73dfc68ae1..cf199f46603c00be675e38a3c1eb375db50a9f48 100644 (file)
@@ -2698,26 +2698,26 @@ LbmFsgrSolver<D>::stepMain()
   // do some formatting 
   if(!D::mSilent){ 
                string sepStr(""); // DEBUG
+#ifndef USE_MSVC6FIXES
+               int avgcls = (int)(mAvgNumUsedCells/(long long int)D::mStepCnt);
+#else
+               int avgcls = (int)(mAvgNumUsedCells/(_int64)D::mStepCnt);
+#endif
                debMsgDirect( 
                        "mlsups(curr:"<<D::mMLSUPS<<
                        " avg:"<<(mAvgMLSUPS/mAvgMLSUPSCnt)<<"), "<< sepStr<<
                        " totcls:"<<(D::mNumUsedCells)<< sepStr<<
-#ifndef USE_MSVC6FIXES
-                       " avgcls:"<< (int)(mAvgNumUsedCells/(long long int)D::mStepCnt)<< sepStr<<
-#endif
+                       " avgcls:"<< avgcls<< sepStr<<
                        " intd:"<<mNumInterdCells<< sepStr<<
                        " invif:"<<mNumInvIfCells<< sepStr<<
                        " invift:"<<mNumInvIfTotal<< sepStr<<
                        " fsgrcs:"<<mNumFsgrChanges<< sepStr<<
                        " filled:"<<D::mNumFilledCells<<", emptied:"<<D::mNumEmptiedCells<< sepStr<<
                        " mMxv:"<<mMxvx<<","<<mMxvy<<","<<mMxvz<<", tscnts:"<<mTimeSwitchCounts<< sepStr<<
-                       /*" rhoMax:"<<mRhoMax<<", rhoMin:"<<mRhoMin<<", vlenMax:"<<mMaxVlen<<", "*/
                        " probs:"<<mNumProblems<< sepStr<<
                        " simt:"<<mSimulationTime<< sepStr<<
                        " for '"<<D::mName<<"' " );
 
-               //wrong?
-               //debMsgDirect(", dccd:"<< mCurrentMass<<"/"<<mCurrentVolume<<"(fix:"<<D::mFixMass<<",ini:"<<mInitialMass<<") ");
                debMsgDirect(std::endl);
                debMsgDirect(D::mStepCnt<<": dccd="<< mCurrentMass<<"/"<<mCurrentVolume<<"(fix="<<D::mFixMass<<",ini="<<mInitialMass<<") ");
                debMsgDirect(std::endl);
index 39182debc677fd3a6bb5719c7c3b92c38e373bfb..e6e206dccd52864c1c5cadbdc8b5235c496674bb 100644 (file)
@@ -236,8 +236,9 @@ void test_idbutton_cb(void *namev, void *arg2_unused);
 #define B_SELEFFECT    1430    
 
 /* Fluidsim button defines */
-#define B_FLUIDSIM_BAKE          1450
-#define B_FLUIDSIM_SELDIR      1451
+#define B_FLUIDSIM_BAKE                1450
+#define B_FLUIDSIM_SELDIR            1451
+#define B_FLUIDSIM_FORCEREDRAW 1452
 
 
 /* *********************** */
index be5b64d86b960022f1affc1dc610263f46f62116..54024d0dee994e8f0d1e7d29a1e1436b0f442dbc 100644 (file)
@@ -1330,8 +1330,14 @@ void do_object_panels(unsigned short event)
                        /* chosse dir for surface files */
                        areawinset(sa->win);
                        activate_fileselect(FILE_SPECIAL, "Select Directory", str, fluidsimFilesel);
-                       allqueue(REDRAWBUTSOBJECT, 0);
+                       // continue with redraw... so no brake here!
+               }
+       case B_FLUIDSIM_FORCEREDRAW: {
+                       // force redraw
+                       allqueue(REDRAWBUTSEDIT, 0);
                        allqueue(REDRAWVIEW3D, 0);
+                       countall();
+                       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
                }
                break;
                
@@ -1927,16 +1933,16 @@ static void object_panel_fluidsim(Object *ob)
                                        yline -= 2*separateHeight;
 
                                        uiDefBut(block, LABEL,   0, "Disp.-Qual.:",              0,yline, 90,objHeight, NULL, 0.0, 0, 0, 0, "");
-                                       uiDefButS(block, MENU, REDRAWVIEW3D, "GuiDisplayMode%t|Geometry %x1|Preview %x2|Final %x3",     
+                                       uiDefButS(block, MENU, B_FLUIDSIM_FORCEREDRAW, "GuiDisplayMode%t|Geometry %x1|Preview %x2|Final %x3",   
                                                         90,yline,105,objHeight, &fss->guiDisplayMode, 0, 0, 0, 0, "How to display the fluid mesh in the blender gui.");
-                                       uiDefButS(block, MENU, REDRAWVIEW3D, "RenderDisplayMode%t|Geometry %x1|Preview %x2|Final %x3",  
+                                       uiDefButS(block, MENU, B_DIFF, "RenderDisplayMode%t|Geometry %x1|Preview %x2|Final %x3",        
                                                        195,yline,105,objHeight, &fss->renderDisplayMode, 0, 0, 0, 0, "How to display the fluid mesh for rendering.");
                                        yline -= lineHeight;
                                        yline -= 1*separateHeight;
 
-                                       uiDefIconBut(block, BUT, B_FLUIDSIM_SELDIR, ICON_FILESEL,          0, yline, 20, objHeight,      0, 0, 0, 0, 0,   "Select Directory (and/or filenames) to store baked fluid simulation files in");
-                                       uiDefBut(block, TEX,   0,"",    20, yline, 200, objHeight,fss->surfdataDir, 0.0,79.0, 0, 0, "Enter Directory (and/or filenames) to store baked fluid simulation files in");
-                                       uiDefBut(block, TEX,   0,"", 220, yline,  80, objHeight,fss->surfdataPrefix, 0.0,79.0, 0, 0, "Enter Filename-Prefix to store baked fluid simulation files with");
+                                       uiDefIconBut(block, BUT, B_FLUIDSIM_SELDIR, ICON_FILESEL,          0, yline,  20, objHeight,                     0, 0, 0, 0, 0,  "Select Directory (and/or filenames) to store baked fluid simulation files in");
+                                       uiDefBut(block, TEX,     B_FLUIDSIM_FORCEREDRAW,"",             20, yline, 200, objHeight,fss->surfdataDir,    0.0,79.0, 0, 0, "Enter Directory to store baked fluid simulation files in");
+                                       uiDefBut(block, TEX,     B_FLUIDSIM_FORCEREDRAW,"",        220, yline,  80, objHeight,fss->surfdataPrefix, 0.0,79.0, 0, 0, "Enter Filename-Prefix to store baked fluid simulation files with");
                                        // FIXME what is the 79.0 above?
                                } else {
                                        // advanced options
index bec2e28f8b1bf5a2a2e0ec92a3890ee1a2036697..c0ab26b77338ba3a071ca74483fd2d89837271a0 100644 (file)
@@ -75,6 +75,8 @@
 #include "BIF_screen.h"
 #include "BIF_space.h"
 #include "BIF_cursors.h"
+#include "BIF_interface.h"
+#include "BSE_headerbuttons.h"
 
 #include "mydevice.h"
 
@@ -135,7 +137,7 @@ typedef struct {
 /* allocates and initializes general main data */
 FluidsimSettings *fluidsimSettingsNew(struct Object *srcob)
 {
-       char blendDir[FILE_MAXDIR], blendFile[FILE_MAXFILE];
+       //char blendDir[FILE_MAXDIR], blendFile[FILE_MAXFILE];
        FluidsimSettings *fss;
        fss= MEM_callocN( sizeof(FluidsimSettings), "fluidsimsettings memory");
        
@@ -167,9 +169,10 @@ FluidsimSettings *fluidsimSettingsNew(struct Object *srcob)
 
        strcpy(fss->surfdataDir,"//"); // current dir
        // fss->surfdataPrefix take from .blend filename
-       strcpy(blendDir, G.sce);
-       BLI_splitdirstring(blendDir, blendFile);
-       snprintf(fss->surfdataPrefix,FILE_MAXFILE,"%s_%s", blendFile, srcob->id.name);
+       //strcpy(blendDir, G.sce);
+       //BLI_splitdirstring(blendDir, blendFile);
+       //snprintf(fss->surfdataPrefix,FILE_MAXFILE,"%s_%s", blendFile, srcob->id.name);
+       strcpy(fss->surfdataPrefix,""); // init upon first bake
        
        fss->orgMesh = (Mesh *)srcob->data;
        return fss;
@@ -230,11 +233,11 @@ void fluidsimBake(struct Object *ob)
        const int maxRes = 200;
        int gridlevels = 0;
 
-       const char *strEnvName = "BLENDER_ELBEEMDEBUG"; // from blendercall.cpp
+       char outDir[FILE_MAXDIR], outPrefix[FILE_MAXFILE]; // store & modify output settings
+       int  outStringsChanged = 0;                        // modified? copy back before baking
+       int  haveSomeFluid = 0;                            // check if any fluid objects are set
 
-       // test section
-       // int nr= pupmenu("Continue?%t|Yes%x1|No%x0");
-       // if(nr==0) return;
+       const char *strEnvName = "BLENDER_ELBEEMDEBUG"; // from blendercall.cpp
 
        if(getenv(strEnvName)) {
                int dlevel = atoi(getenv(strEnvName));
@@ -288,6 +291,21 @@ void fluidsimBake(struct Object *ob)
        snprintf(debugStrBuffer,256,"fluidsimBake::msg: Baking %s, refine: %d\n", fsDomain->id.name , gridlevels ); 
        elbeemDebugOut(debugStrBuffer);
        
+       // check if theres any fluid
+       // abort baking if not...
+       for(obit= G.main->object.first; obit; obit= obit->id.next) {
+               if( (obit->fluidsimFlag & OB_FLUIDSIM_ENABLE) && 
+                               (obit->type==OB_MESH) && (
+                         (obit->fluidsimSettings->type == OB_FLUIDSIM_FLUID) ||
+                         (obit->fluidsimSettings->type == OB_FLUIDSIM_INFLOW) )
+                               ) {
+                       haveSomeFluid = 1;
+               }
+       }
+       if(!haveSomeFluid) {
+               pupmenu("Fluidsim Bake Error%t|No fluid objects in scene... Aborted%x0");
+               return;
+       }
 
        // prepare names...
        strcpy(curWd, G.sce);
@@ -295,55 +313,81 @@ void fluidsimBake(struct Object *ob)
        if(strlen(curWd)<1) {
                BLI_getwdN(curWd);
        }
-       if(strlen(fsDomain->fluidsimSettings->surfdataPrefix)<1) {
+       // work on these vars here... copy back later
+       strncpy(outDir,    fsDomain->fluidsimSettings->surfdataDir,    FILE_MAXDIR);
+       strncpy(outPrefix, fsDomain->fluidsimSettings->surfdataPrefix, FILE_MAXFILE);
+       if(strlen(outPrefix)<1) {
                // make new from current .blend filename , and domain object name
                strcpy(blendDir, G.sce);
                BLI_splitdirstring(blendDir, blendFile);
                // todo... strip .blend 
-               snprintf(fsDomain->fluidsimSettings->surfdataPrefix,FILE_MAXFILE,"%s_%s", blendFile, fsDomain->id.name);
-               snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output prefix to '%s'\n", fsDomain->fluidsimSettings->surfdataPrefix); 
+               snprintf(outPrefix,FILE_MAXFILE,"%s_%s", blendFile, fsDomain->id.name);
+               snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output prefix to '%s'\n", outPrefix); 
                elbeemDebugOut(debugStrBuffer);
+               outStringsChanged=1;
        }
 
        // check selected directory
 #ifdef WIN32
        // windows workaroung because stat seems to be broken...
        // simply try to open cfg file for writing
-       snprintf(fnameCfg,FILE_MAXFILE,"%s.cfg", fsDomain->fluidsimSettings->surfdataPrefix);
-       BLI_make_file_string(curWd, fnameCfgPath, fsDomain->fluidsimSettings->surfdataDir, fnameCfg);
+       snprintf(fnameCfg,FILE_MAXFILE,"%s.cfg", outPrefix);
+       BLI_make_file_string(curWd, fnameCfgPath, outDir, fnameCfg);
        fileCfg = fopen(fnameCfgPath, "w");
        if(fileCfg) {
                dirExist = 1;
                fclose(fileCfg);
        }
 #else // WIN32
-       BLI_make_file_string(curWd, fnameCfgPath, fsDomain->fluidsimSettings->surfdataDir, "");
+       BLI_make_file_string(curWd, fnameCfgPath, outDir, "");
        if(S_ISDIR(BLI_exist(fnameCfgPath))) dirExist = 1;
 #endif // WIN32
 
-       if((strlen(fsDomain->fluidsimSettings->surfdataDir)<1) || (!dirExist)) {
+       if((strlen(outDir)<1) || (!dirExist)) {
                // invalid dir, reset to current
-               strcpy(fsDomain->fluidsimSettings->surfdataDir, "//");
-               snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output dir to '%s'\n", fsDomain->fluidsimSettings->surfdataDir);
+               strcpy(outDir, "//");
+               snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output dir to '%s'\n", outDir);
                elbeemDebugOut(debugStrBuffer);
+               outStringsChanged=1;
+       }
+
+       // check if modified output dir is ok
+       if(outStringsChanged) {
+               char dispmsg[FILE_MAXDIR+FILE_MAXFILE+256];
+               int  selection=0;
+               strcpy(dispmsg,"Output settings set to: '");
+               strcat(dispmsg, outDir);
+               if(dispmsg[ strlen(dispmsg)-1 ]!='/') strcat(dispmsg,"/");
+               strcat(dispmsg, outPrefix);
+               //snprintf(dispmsg, FILE_MAXDIR+FILE_MAXFILE+10, "%s '%s'", changeMsg, fnameCfgPath);
+               strcat(dispmsg, "'%t|Continue with changed settings%x1|Discard and abort%x0");
+
+               // ask user if thats what he/she wants...
+               selection = pupmenu(dispmsg);
+               if(selection==0) return;
        }
        
        // dump data for frame 0
   G.scene->r.cfra = 0;
   scene_update_for_newframe(G.scene, G.scene->lay);
 
-       snprintf(fnameCfg,FILE_MAXFILE,"%s.cfg", fsDomain->fluidsimSettings->surfdataPrefix);
-       BLI_make_file_string(curWd, fnameCfgPath, fsDomain->fluidsimSettings->surfdataDir, fnameCfg);
+       snprintf(fnameCfg,FILE_MAXFILE,"%s.cfg", outPrefix);
+       BLI_make_file_string(curWd, fnameCfgPath, outDir, fnameCfg);
 
        // start writing
        fileCfg = fopen(fnameCfgPath, "w");
        if(!fileCfg) {
                snprintf(debugStrBuffer,256,"fluidsimBake::error - Unable to open file for writing '%s'\n", fnameCfgPath); 
                elbeemDebugOut(debugStrBuffer);
+       
+               pupmenu("Fluidsim Bake Error%t|Unable to output files... Aborted%x0");
                return;
        }
 
        fprintf(fileCfg, "# Blender ElBeem File , Source %s , Frame %d, to %s \n\n\n", G.sce, -1, fnameCfg );
+       // valid settings -> store
+       strncpy(fsDomain->fluidsimSettings->surfdataDir,    outDir,    FILE_MAXDIR);
+       strncpy(fsDomain->fluidsimSettings->surfdataPrefix, outPrefix, FILE_MAXFILE);
 
        // FIXME set aniframetime from no. frames and duration
        /* output simulation  settings */
@@ -468,8 +512,8 @@ void fluidsimBake(struct Object *ob)
                char   fnamePreview[FILE_MAXFILE];
                char   fnamePreviewPath[FILE_MAXFILE+FILE_MAXDIR];
 
-               snprintf(fnamePreview,FILE_MAXFILE,"%s_surface", fsDomain->fluidsimSettings->surfdataPrefix );
-               BLI_make_file_string(curWd, fnamePreviewPath, fsDomain->fluidsimSettings->surfdataDir, fnamePreview);
+               snprintf(fnamePreview,FILE_MAXFILE,"%s_surface", outPrefix );
+               BLI_make_file_string(curWd, fnamePreviewPath, outDir, fnamePreview);
                resx = G.scene->r.xsch;
                resy = G.scene->r.ysch;
                if((cam) && (cam->type == OB_CAMERA)) {
@@ -575,8 +619,8 @@ void fluidsimBake(struct Object *ob)
                                        (obit->type==OB_MESH) &&
                                  (obit->fluidsimSettings->type != OB_FLUIDSIM_DOMAIN)
                                ) {
-                                       getGeometryObjFilename(obit, fnameObjdat, fsDomain->fluidsimSettings->surfdataPrefix);
-                                       BLI_make_file_string(curWd, bobjPath, fsDomain->fluidsimSettings->surfdataDir, fnameObjdat);
+                                       getGeometryObjFilename(obit, fnameObjdat, outPrefix);
+                                       BLI_make_file_string(curWd, bobjPath, outDir, fnameObjdat);
                                        fprintf(fileCfg, objectStringStart, obit->id.name ); // abs path
                                        if(obit->fluidsimSettings->type == OB_FLUIDSIM_FLUID) {
                                                fprintf(fileCfg, fluidString, "fluid", bobjPath, // do use absolute paths?