aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2019-02-11 12:52:45 -0500
committerFranklin Wei <me@fwei.tk>2019-02-11 12:52:45 -0500
commit291bd26fd8920831181e8207e1fcdf544cd6cd6f (patch)
tree58fc7bac5b018197590af66727ea71e11d00a737
parent8f49ddea98f32dd8e90416012c264d8cc5501bb0 (diff)
downloadfieldviz-291bd26fd8920831181e8207e1fcdf544cd6cd6f.zip
fieldviz-291bd26fd8920831181e8207e1fcdf544cd6cd6f.tar.gz
fieldviz-291bd26fd8920831181e8207e1fcdf544cd6cd6f.tar.bz2
fieldviz-291bd26fd8920831181e8207e1fcdf544cd6cd6f.tar.xz
Reorganize, use readline
-rw-r--r--CMakeLists.txt5
-rw-r--r--src/curve.cpp (renamed from curve.cpp)0
-rw-r--r--src/curve.h (renamed from curve.h)0
-rw-r--r--src/main.cpp (renamed from main.cpp)40
-rw-r--r--src/quat.cpp (renamed from quat.cpp)0
-rw-r--r--src/quat.h (renamed from quat.h)0
-rw-r--r--src/vec3.cpp (renamed from vec3.cpp)0
-rw-r--r--src/vec3.h (renamed from vec3.h)0
8 files changed, 32 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f692f3..30ad684 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,8 @@
cmake_minimum_required (VERSION 2.6)
project (fieldviz)
-add_executable(fieldviz main.cpp curve.cpp quat.cpp vec3.cpp)
+add_executable(fieldviz src/main.cpp src/curve.cpp src/quat.cpp src/vec3.cpp)
+target_link_libraries(fieldviz readline)
-add_definitions(-std=c++14 -O2 -g)
+add_definitions(-std=c++14 -Og -g)
include_directories(lib)
diff --git a/curve.cpp b/src/curve.cpp
index 19ce1a8..19ce1a8 100644
--- a/curve.cpp
+++ b/src/curve.cpp
diff --git a/curve.h b/src/curve.h
index 5f11351..5f11351 100644
--- a/curve.h
+++ b/src/curve.h
diff --git a/main.cpp b/src/main.cpp
index 50abaca..26ed520 100644
--- a/main.cpp
+++ b/src/main.cpp
@@ -1,4 +1,5 @@
#include <cmath>
+#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
@@ -6,6 +7,9 @@
#include <sys/types.h>
#include <vector>
+#include <readline/readline.h>
+#include <readline/history.h>
+
#include "gnuplot_i.hpp"
#include "vec3.h"
@@ -268,18 +272,32 @@ int main(int argc, char *argv[])
Toroid loop(vec3(0, 0, 0), vec3(1, 0, 0), vec3(0, 0, 1), M_PI * 2, .1, 2*M_PI / 10);
//add_current(1, (Curve*)&loop);
- Gnuplot gp;
- gp << "set view equal xyz";
+ Gnuplot *gp = NULL;
+
+ try {
+ gp = new Gnuplot();
+ }
+ catch(GnuplotException e) {
+ Gnuplot::set_terminal_std("dumb");
+ gp = new Gnuplot();
+ }
+
+ *gp << "set view equal xyz";
cout << "Welcome to fieldviz!" << endl << endl;
cout << "Type `help' for a command listing." << endl;
- while(cin)
+ while(1)
{
- cout << "fieldviz> " << flush;
- string line;
- getline(cin, line);
-
+ char *cs = readline("fieldviz> ");
+ if(!cs)
+ return 0;
+ add_history(cs);
+
+ string line(cs);
+
+ free(cs);
+
all_lower(line);
/* parse */
@@ -327,7 +345,7 @@ int main(int argc, char *argv[])
FieldType t = (type == "e") ? FieldType::E : FieldType::B;
ofstream out;
- string fname = gp.create_tmpfile(out);
+ string fname = gp->create_tmpfile(out);
dump_field(out,
t,
@@ -336,7 +354,7 @@ int main(int argc, char *argv[])
out.close();
string cmd = "splot '" + fname + "' w vectors";
- gp << cmd;
+ *gp << cmd;
}
else if(cmd == "draw")
{
@@ -360,13 +378,13 @@ int main(int argc, char *argv[])
e_types |= Entity::CHARGE | Entity::CURRENT;
ofstream out;
- string fname = gp.create_tmpfile(out);
+ string fname = gp->create_tmpfile(out);
int n = dump_entities(out, e_types,
entities);
out.close();
string cmd = "splot for[i = 0:" + itoa(n - 1) + "] '" + fname + "' i i w lines";
- gp << cmd;
+ *gp << cmd;
}
else if(cmd == "help")
print_help();
diff --git a/quat.cpp b/src/quat.cpp
index df117d0..df117d0 100644
--- a/quat.cpp
+++ b/src/quat.cpp
diff --git a/quat.h b/src/quat.h
index 5821f81..5821f81 100644
--- a/quat.h
+++ b/src/quat.h
diff --git a/vec3.cpp b/src/vec3.cpp
index e894a01..e894a01 100644
--- a/vec3.cpp
+++ b/src/vec3.cpp
diff --git a/vec3.h b/src/vec3.h
index df68104..df68104 100644
--- a/vec3.h
+++ b/src/vec3.h