Revision: 76277
          http://sourceforge.net/p/brlcad/code/76277
Author:   starseeker
Date:     2020-07-07 19:05:12 +0000 (Tue, 07 Jul 2020)
Log Message:
-----------
Start looking at what a Tcl-free asc2g will need.  This a tall order and not 
really possible in the general v5 ASC case, since for v5 asc2g makes available 
libtclcad's commands and evaluates the asc file as a Tcl script.  The practical 
approach looks to be:  a) bring over v4 parsing without Tcl, which seems to be 
present in asc2g.  b) identify the subset of commands used by g2asc for v5, and 
implement parsing and evaluation for those commands specifically c)  IFF b 
fails to read a file and Tcl is enabled during compilation, fall back on the 
libtclcad Tcl evaluation to import the file.  Fully executed, we should be able 
to handle anything written out by g2asc without Tcl (assuming there aren't 
actual Tcl syntax evaluations buried in v5 somewhere) and if someone has 
manually altered or created a more complex file that actually hard requires Tcl 
we'll support if if Tcl is enabled.

Added Paths:
-----------
    brlcad/trunk/src/libgcv/plugins/asc/
    brlcad/trunk/src/libgcv/plugins/asc/CMakeLists.txt
    brlcad/trunk/src/libgcv/plugins/asc/asc_read.cpp

Added: brlcad/trunk/src/libgcv/plugins/asc/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libgcv/plugins/asc/CMakeLists.txt                          
(rev 0)
+++ brlcad/trunk/src/libgcv/plugins/asc/CMakeLists.txt  2020-07-07 19:05:12 UTC 
(rev 76277)
@@ -0,0 +1,12 @@
+LIBGCV_ADD_PLUGIN(asc "asc_read.cpp" "librt;libbu")
+
+CMAKEFILES(asc_read.cpp)
+CMAKEFILES(CMakeLists.txt)
+
+# Local Variables:
+# tab-width: 8
+# mode: cmake
+# indent-tabs-mode: t
+# End:
+# ex: shiftwidth=2 tabstop=8
+


Property changes on: brlcad/trunk/src/libgcv/plugins/asc/CMakeLists.txt
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: brlcad/trunk/src/libgcv/plugins/asc/asc_read.cpp
===================================================================
--- brlcad/trunk/src/libgcv/plugins/asc/asc_read.cpp                            
(rev 0)
+++ brlcad/trunk/src/libgcv/plugins/asc/asc_read.cpp    2020-07-07 19:05:12 UTC 
(rev 76277)
@@ -0,0 +1,141 @@
+#include "common.h"
+#include "vmath.h"
+
+#include <cstdio>
+#include <fstream>
+#include <regex>
+#include <sstream>
+#include <string>
+
+#include "gcv/api.h"
+#include "gcv/util.h"
+
+HIDDEN int
+asc_can_read(const char *data)
+{
+    if (!data) return 0;
+    bu_log("asc can read: %s\n", data);
+    return 1;
+}
+
+HIDDEN int
+asc_read_v4(
+       struct gcv_context *UNUSED(c),
+               const struct gcv_opts *UNUSED(o),
+       std::ifstream &fs
+       )
+{
+    std::string sline;
+    bu_log("Reading v4...\n");
+    while (std::getline(fs, sline)) {
+       std::cout << sline << "\n";
+    }
+    return 1;
+
+}
+
+HIDDEN int
+asc_read_v5(
+       struct gcv_context *UNUSED(c),
+               const struct gcv_opts *UNUSED(o),
+       std::ifstream &fs
+       )
+{
+    std::string sline;
+    bu_log("Reading v5...\n");
+    while (std::getline(fs, sline)) {
+       std::cout << sline << "\n";
+    }  
+    return 1;
+}
+
+HIDDEN int
+asc_read(
+       struct gcv_context *c,
+               const struct gcv_opts *o,
+       const void *UNUSED(o_data),
+               const char *spath
+       )
+{
+    struct bu_vls vline = BU_VLS_INIT_ZERO;
+    int fmt = -1;
+    if (!c || !o || !spath) return 0;
+    std::string sline;
+    std::ifstream fs;
+    fs.open(spath);
+    if (!fs.is_open()) {
+       std::cerr << "Unable to open " << spath << " for reading, skipping\n";
+       return 0;
+    }
+
+    // asc2g checked for either title or put as the first line to denote a new
+    // style asc file.
+    struct bu_vls str_title = BU_VLS_INIT_ZERO;
+    struct bu_vls str_put = BU_VLS_INIT_ZERO;
+    bu_vls_strcpy(&str_title, "title");
+    bu_vls_strcpy(&str_put, "put ");
+
+    while (std::getline(fs, sline)) {
+       std::cout << sline << "\n";
+       bu_vls_sprintf(&vline, "%s", sline.c_str());
+       bu_vls_trimspace(&vline);
+       if (!bu_vls_strlen(&vline) || bu_vls_cstr(&vline)[0] == '#') {
+           // Comment line or empty line - skip
+           continue;
+       }
+       if (fmt < 0) {
+           // Don't have format yet - check if this is a v4 asc file or a v5
+           // asc file.  The two are handled differently.
+           if (!bu_vls_strncmp(&vline, &str_title, 5) || 
!bu_vls_strncmp(&vline, &str_put, 4)) {
+               fmt = 5;
+           } else {
+               fmt = 4;
+           }
+       }
+       if (fmt) {
+           switch (fmt) {
+               case 4:
+                   asc_read_v4(c, o, fs);
+                   break;
+               case 5:
+                   fs.seekg(0);
+                   asc_read_v5(c, o, fs);
+                   break;
+               default:
+                   std::cerr << "Unknown asc format version: " << fmt << "\n";
+                   return 0;
+                   break;
+           }
+       }
+    }
+
+    // Not yet implemented - always return failure until we have something 
working...
+    return 1;
+}
+
+extern "C"
+{
+    struct gcv_filter gcv_conv_asc_read =
+    {
+       "ASC Reader",
+       GCV_FILTER_READ,
+       BU_MIME_MODEL_VND_BRLCAD_PLUS_TCL,
+       asc_can_read,
+       NULL,
+       NULL,
+       asc_read
+    };
+
+    static const struct gcv_filter * const filters[] = {&gcv_conv_asc_read, 
NULL};
+    const struct gcv_plugin gcv_plugin_info_s = { filters };
+    COMPILER_DLLEXPORT const struct gcv_plugin *gcv_plugin_info(){return 
&gcv_plugin_info_s;}
+}
+
+// Local Variables:
+// tab-width: 8
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// c-file-style: "stroustrup"
+// End:
+// ex: shiftwidth=4 tabstop=8


Property changes on: brlcad/trunk/src/libgcv/plugins/asc/asc_read.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to