Commit 5b26b61f authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Extracted code for operations requiring a progress bar so allow use elsewhere.

parent 17f75032
This diff is collapsed.
bin_PROGRAMS = ../functy
___functy_SOURCES = function.c function.h function_private.h functy.c functy.h textures.c textures.h utils.c utils.h vis.c vis.h filesave.c filesave.h cartesian.c cartesian.h spherical.c spherical.h shader.c shader.h curve.c curve.h vecsym.c vecsym.h exportply.c exportply.h exportstl.c exportstl.h exportbitmap.c exportbitmap.h exportsvx.c exportsvx.h recall.c recall.h controlvar.c controlvar.h shadow.c shadow.h
___functy_SOURCES = function.c function.h function_private.h functy.c functy.h textures.c textures.h utils.c utils.h vis.c vis.h filesave.c filesave.h cartesian.c cartesian.h spherical.c spherical.h shader.c shader.h curve.c curve.h vecsym.c vecsym.h exportply.c exportply.h exportstl.c exportstl.h exportbitmap.c exportbitmap.h exportsvx.c exportsvx.h recall.c recall.h controlvar.c controlvar.h shadow.c shadow.h longpoll.c longpoll.h
___functy_LDADD = -lm @FUNCTY_LIBS@
......
This diff is collapsed.
......@@ -16,6 +16,7 @@
#include "vis.h"
#include "function.h"
#include "longpoll.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -25,14 +26,23 @@
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef struct _ExportSVXPersist ExportSVXPersist;
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
ExportSVXPersist * NewExportSVXPersist (char const * szFilename, int nResolution, VisPersist * psVisData);
void DeleteExportSVXPersist (ExportSVXPersist * psExportSVXData);
bool ExportModelSVX (char const * szFilename, int nResolution, VisPersist * psVisData);
void FilledCuboidSliceSVX (unsigned char * pcData, int nResolution, int nChannels, Vector3 * avCorners, float fZSlice);
bool ExportStartSVX (LongPollPersist * psLongPollData, void * psData);
bool ExportStepSVX (LongPollPersist * psLongPollData, void * psData);
bool ExportFinishSVX (LongPollPersist * psLongPollData, void * psData);
///////////////////////////////////////////////////////////////////
// Function definitions
......
......@@ -33,8 +33,10 @@
#include "curve.h"
#include "exportply.h"
#include "exportstl.h"
#include "exportsvx.h"
#include "exportbitmap.h"
#include "controlvar.h"
#include "longpoll.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -199,6 +201,7 @@ static gboolean DocumentationShow (GtkWidget * psWidget, gpointer psData);
static gboolean HomepageShow (GtkWidget * psWidget, gpointer psData);
void SetMaterialFill (bool boMaterialFill, FunctyPersist * psFunctyData);
static void ToggleMaterialFill (GtkWidget * psWidget, gpointer psData);
static gboolean TestProgress (GtkWidget * psWidget, gpointer psData);
///////////////////////////////////////////////////////////////////
// Function definitions
......@@ -4135,6 +4138,7 @@ int main (int argc, char *argv[]) {
g_signal_connect (psWidget, "clicked", G_CALLBACK (PlotFunctionCancel), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "Open"));
g_signal_connect (psWidget, "clicked", G_CALLBACK (LoadFilePress), (gpointer)psFunctyData);
//g_signal_connect (psWidget, "clicked", G_CALLBACK (TestProgress), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "SaveAs"));
g_signal_connect (psWidget, "clicked", G_CALLBACK (SaveFilePress), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "ExportModelPLY"));
......@@ -4555,4 +4559,16 @@ gchar * GetTextViewText (GtkWidget * psTextView) {
return szText;
}
static gboolean TestProgress (GtkWidget * psWidget, gpointer psData) {
FunctyPersist * psFunctyData = (FunctyPersist * )psData;
ExportSVXPersist * psExportSVXData;
psExportSVXData = NewExportSVXPersist ("/home/flypig/test.svx", 256, psFunctyData->psVisData);
LongPoll (psFunctyData->psXML, psExportSVXData, ExportStartSVX, ExportStepSVX, ExportFinishSVX, NULL);
return TRUE;
}
///////////////////////////////////////////////////////////////////
// Functy
// 3D graph drawing utility
//
// David Llewellyn-Jones
// http://www.flypig.co.uk
//
// Autumn 2014
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// Includes
#include "longpoll.h"
///////////////////////////////////////////////////////////////////
// Defines
#define LONGPOLL_TIMEOUT (10)
///////////////////////////////////////////////////////////////////
// Structures and enumerations
struct _LongPollPersist {
bool boDone;
float fProgress;
VisPersist * psVisData;
GtkBuilder * psXML;
// Context data
void * psData;
// Virtual functions
LongPollCallback pmStart;
LongPollCallback pmStep;
LongPollCallback pmFinish;
LongPollCallback pmCancel;
};
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
static gboolean LongPollTimeout (gpointer psData);
bool LongPollStart (LongPollPersist * psLongPollData);
///////////////////////////////////////////////////////////////////
// Function definitions
LongPollPersist * NewLongPollPersist (void) {
LongPollPersist * psLongPollData;
psLongPollData = g_new0 (LongPollPersist, 1);
psLongPollData->boDone = FALSE;
psLongPollData->fProgress = 0.0f;
psLongPollData->psXML = NULL;
psLongPollData->psData = NULL;
psLongPollData->pmStart = NULL;
psLongPollData->pmStep = NULL;
psLongPollData->pmFinish = NULL;
psLongPollData->pmCancel = NULL;
return psLongPollData;
}
void DeleteLongPollPersist (LongPollPersist * psLongPollData) {
g_free (psLongPollData);
}
bool LongPoll (GtkBuilder * psXML, void * psData, LongPollCallback pmStart, LongPollCallback pmStep, LongPollCallback pmFinish, LongPollCallback pmCancel) {
LongPollPersist * psLongPollData;
bool boSuccess;
psLongPollData = NewLongPollPersist ();
psLongPollData->psXML = psXML;
psLongPollData->psData = psData;
psLongPollData->pmStart = pmStart;
psLongPollData->pmStep = pmStep;
psLongPollData->pmFinish = pmFinish;
psLongPollData->pmCancel = pmCancel;
boSuccess = LongPollStart (psLongPollData);
return boSuccess;
}
bool LongPollStart (LongPollPersist * psLongPollData) {
GtkDialog * psDialog;
GtkWindow * psParent;
int nResult;
psParent = GTK_WINDOW (gtk_builder_get_object (psLongPollData->psXML, "MainWindow"));
psDialog = GTK_DIALOG (gtk_builder_get_object (psLongPollData->psXML, "ExportDialog"));
gtk_window_set_transient_for (GTK_WINDOW (psDialog), psParent);
if (psLongPollData->pmStart != NULL) {
psLongPollData->pmStart (psLongPollData, psLongPollData->psData);
}
/* int nTimeoutID = */ g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, LONGPOLL_TIMEOUT, LongPollTimeout, psLongPollData, NULL);
nResult = gtk_dialog_run (GTK_DIALOG (psDialog));
printf ("Dialogue result: %d\n", nResult);
gtk_widget_hide (GTK_WIDGET (psDialog));
return TRUE;
}
static gboolean LongPollTimeout (gpointer psData) {
LongPollPersist * psLongPollData = (LongPollPersist *)psData;
bool boContinue;
GtkWidget * psProgress;
GtkDialog * psDialog;
boContinue = TRUE;
if (psLongPollData->pmStep != NULL) {
psLongPollData->pmStep (psLongPollData, psLongPollData->psData);
}
psProgress = GTK_WIDGET (gtk_builder_get_object (psLongPollData->psXML, "ExportProgress"));
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (psProgress), psLongPollData->fProgress);
boContinue = !psLongPollData->boDone;
if (!boContinue) {
if (psLongPollData->pmFinish != NULL) {
psLongPollData->pmFinish (psLongPollData, psLongPollData->psData);
}
psDialog = GTK_DIALOG (gtk_builder_get_object (psLongPollData->psXML, "ExportDialog"));
DeleteLongPollPersist (psLongPollData);
gtk_dialog_response (psDialog, 0);
}
return boContinue;
}
void LongPollSetProgress (float fProgress, LongPollPersist * psLongPollData) {
psLongPollData->fProgress = fProgress;
}
void LongPollDone (LongPollPersist * psLongPollData) {
psLongPollData->boDone = TRUE;
}
///////////////////////////////////////////////////////////////////
// Functy
// 3D graph drawing utility
//
// David Llewellyn-Jones
// http://www.flypig.co.uk
//
// Autumn 2014
///////////////////////////////////////////////////////////////////
#ifndef LONGPOLL_H
#define LONGPOLL_H
///////////////////////////////////////////////////////////////////
// Includes
#include "vis.h"
///////////////////////////////////////////////////////////////////
// Defines
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef struct _LongPollPersist LongPollPersist;
typedef bool (* LongPollCallback) (LongPollPersist * psLongPollData, void * psData);
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
LongPollPersist * NewLongPollPersist (void);
void DeleteLongPollPersist (LongPollPersist * psLongPollData);
bool LongPoll (GtkBuilder * psXML, void * psData, LongPollCallback pmStart, LongPollCallback pmStep, LongPollCallback pmFinish, LongPollCallback pmCancel);
void LongPollSetProgress (float fProgress, LongPollPersist * psLongPollData);
void LongPollDone (LongPollPersist * psLongPollData);
///////////////////////////////////////////////////////////////////
// Function definitions
#endif /* LONGPOLL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment