From 09a77a1c8b32350fe0e5c0515a80c421846a7392 Mon Sep 17 00:00:00 2001 From: Vladimir Georgiev Date: Wed, 4 May 2016 17:21:49 +0300 Subject: [PATCH] Update: KML map/model export with name (survey title) and description (length/depth) in the specified language --- thexpmodel.cxx | 41 ++++++++++++++++++++++++++++++++++++----- thexpmodel.h | 4 ++++ thexpuni.cxx | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/thexpmodel.cxx b/thexpmodel.cxx index c63f227..969c43f 100644 --- a/thexpmodel.cxx +++ b/thexpmodel.cxx @@ -44,6 +44,8 @@ #include "thcsdata.h" #include "thproj.h" #include "thcs.h" +#include "thtexfonts.h" +#include "thlang.h" thexpmodel::thexpmodel() { @@ -51,9 +53,14 @@ thexpmodel::thexpmodel() { this->items = TT_EXPMODEL_ITEM_ALL; this->wallsrc = TT_WSRC_ALL; this->encoding = TT_UTF_8; + this->layout = new thlayout; + this->layout->assigndb(&thdb); + this->layout->id = ++thdb.objid; } - +thexpmodel::~thexpmodel() { + delete this->layout; +} void thexpmodel::parse_options(int & argx, int nargs, char ** args) { @@ -1785,14 +1792,38 @@ void thexpmodel::export_kml_file(class thdatabase * dbp) thtext_inline = true; #endif - fprintf(out,"\n\n\n"); - fprintf(out,"Therion KML export\nTherion KML export.\n"); + fprintf(out,"\n\n"); + fprintf(out,"\n"); + + // Get the main survey, which is at level 2 and is different from the fsurveyptr at level 1 + thsurvey * mainsrv = dbp->fsurveyptr; + thdataobject * obj; + for(obj = mainsrv->foptr; obj != NULL; obj = obj->nsptr) + if (obj->get_class_id() == TT_SURVEY_CMD) { + mainsrv = (thsurvey *) obj; + break; + } + // Export cave name and description in the selected language + std::string cavename = ths2txt((strlen(mainsrv->title) > 0) ? mainsrv->title : mainsrv->name, layout->lang); + cavename = replace_all(cavename, "
", "-"); + cavename = replace_all(cavename, "", ""); + cavename = replace_all(cavename, "", ""); + fprintf(out,"%s\n", cavename.c_str()); + double cavedepth = 0; + if (mainsrv->stat.station_top != NULL) { + cavedepth = mainsrv->stat.station_top->z - mainsrv->stat.station_bottom->z; + if (cavedepth > mainsrv->stat.length) + cavedepth = mainsrv->stat.length; + } + layout->units.lang = layout->lang; + fprintf(out,"%s %s %s]]>\n", + thT("title cave length",layout->lang), layout->units.format_length(mainsrv->stat.length), layout->units.format_i18n_length_units(), + thT("title cave depth",layout->lang), layout->units.format_length(cavedepth), layout->units.format_i18n_length_units()); unsigned long last_st = nstat, cur_st, numst, i; double x, y, z; - fprintf(out,"\n"); fprintf(out,"\n"); fprintf(out,"\n"); @@ -1822,7 +1853,7 @@ void thexpmodel::export_kml_file(class thdatabase * dbp) if (numst > 0) fprintf(out,"\n\n"); fprintf(out,"\n"); - fprintf(out,"\n
\n
\n"); + fprintf(out,"\n\n"); fclose(out); #ifdef THDEBUG diff --git a/thexpmodel.h b/thexpmodel.h index 22028e5..29f35a7 100644 --- a/thexpmodel.h +++ b/thexpmodel.h @@ -31,6 +31,7 @@ #include "thexport.h" +#include "thlayout.h" /** @@ -176,6 +177,7 @@ class thexpmodel : public thexport { encoding; ///< Output encoding. unsigned items, wallsrc; + class thlayout * layout; ///< Layout pointer. bool is_leg_exported(class thdb1dl * l); ///< Whether to export leg. @@ -201,6 +203,8 @@ class thexpmodel : public thexport { thexpmodel(); ///< Default constructor. + virtual ~thexpmodel(); ///< Default destructor. + /** * Parse model export options. */ diff --git a/thexpuni.cxx b/thexpuni.cxx index 43d82f0..013baa9 100644 --- a/thexpuni.cxx +++ b/thexpuni.cxx @@ -67,6 +67,8 @@ #include "thexpuni.h" #include "thproj.h" #include "thcs.h" +#include "thtexfonts.h" +#include "thlang.h" static const char * DXFpre = @@ -468,8 +470,34 @@ void thexpmap::export_kml(class thdb2dxm * maps, class thdb2dprj * prj) thscrap * scrap; thexpuni xu; - fprintf(out,"\n\n\n"); - fprintf(out,"Therion KML export\nTherion KML export.\n"); + fprintf(out,"\n\n"); + fprintf(out,"\n"); + + // Get the main survey, which is at level 2 and is different from the fsurveyptr at level 1 + thsurvey * mainsrv = db->fsurveyptr; + thdataobject * obj; + for(obj = mainsrv->foptr; obj != NULL; obj = obj->nsptr) + if (obj->get_class_id() == TT_SURVEY_CMD) { + mainsrv = (thsurvey *) obj; + break; + } + + // Export cave name and description in the selected language + std::string cavename = ths2txt((strlen(mainsrv->title) > 0) ? mainsrv->title : mainsrv->name, layout->lang); + cavename = replace_all(cavename, "
", "-"); + cavename = replace_all(cavename, "", ""); + cavename = replace_all(cavename, "", ""); + fprintf(out,"%s\n", cavename.c_str()); + double cavedepth = 0; + if (mainsrv->stat.station_top != NULL) { + cavedepth = mainsrv->stat.station_top->z - mainsrv->stat.station_bottom->z; + if (cavedepth > mainsrv->stat.length) + cavedepth = mainsrv->stat.length; + } + layout->units.lang = layout->lang; + fprintf(out,"%s %s %s]]>\n", + thT("title cave length",layout->lang), layout->units.format_length(mainsrv->stat.length), layout->units.format_i18n_length_units(), + thT("title cave depth",layout->lang), layout->units.format_length(cavedepth), layout->units.format_i18n_length_units()); int cA, cR, cG, cB; cR = int (255.0 * this->layout->color_map_fg.R + 0.5); @@ -487,7 +515,6 @@ void thexpmap::export_kml(class thdb2dxm * maps, class thdb2dprj * prj) checkc(cG); checkc(cB); - fprintf(out,"\n"); fprintf(out,"\n"); @@ -538,7 +565,7 @@ void thexpmap::export_kml(class thdb2dxm * maps, class thdb2dprj * prj) } fprintf(out,"\n\n"); - fprintf(out,"
\n
\n"); + fprintf(out,"\n"); fclose(out); #ifdef THDEBUG -- 2.6.4.windows.1