2 * Converts a .3d file to CAD-like formats (DXF, Skencil, SVG) and also Compass
6 /* Copyright (C) 1994-2004,2008,2010,2011,2013,2014,2018 Olly Betts
7 * Copyright (C) 2004 John Pybus (SVG Output code)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "img_hosted.h"
44 #define FMT_DEFAULT FMT_DXF
47 main(int argc
, char **argv
)
52 bool format_set
= false;
54 const char *survey
= NULL
;
55 double grid
= 0.0; /* grid spacing (or 0 for no grid) */
56 double text_height
= DEFAULT_TEXT_HEIGHT
; /* for station labels */
57 double marker_size
= DEFAULT_MARKER_SIZE
; /* for station markers */
67 static const struct option long_opts
[] = {
68 /* const char *name; int has_arg (0 no_argument, 1 required, 2 options_*); int *flag; int val */
69 {"survey", required_argument
, 0, 's'},
70 {"no-crosses", no_argument
, 0, 'c'},
71 {"no-station-names", no_argument
, 0, 'n'},
72 {"no-legs", no_argument
, 0, 'l'},
73 {"grid", optional_argument
, 0, 'g'},
74 {"text-height", required_argument
, 0, 't'},
75 {"marker-size", required_argument
, 0, 'm'},
76 {"elevation", required_argument
, 0, 'e'},
77 {"reduction", required_argument
, 0, 'r'},
78 {"dxf", no_argument
, 0, 'D'},
79 {"skencil", no_argument
, 0, 'S'},
80 {"plt", no_argument
, 0, 'P'},
81 {"svg", no_argument
, 0, 'V'},
82 {"help", no_argument
, 0, HLP_HELP
},
83 {"version", no_argument
, 0, HLP_VERSION
},
84 /* Old name for --skencil: */
85 {"sketch", no_argument
, 0, 'S'},
89 #define short_opts "s:cnlg::t:m:e:r:DSPV"
92 static struct help_msg help
[] = {
94 {HLP_ENCODELONG(0), /*only load the sub-survey with this prefix*/199, 0},
95 {HLP_ENCODELONG(1), /*do not generate station markers*/100, 0},
96 {HLP_ENCODELONG(2), /*do not generate station labels*/101, 0},
97 {HLP_ENCODELONG(3), /*do not generate survey legs*/102, 0},
98 {HLP_ENCODELONG(4), /*generate grid (default %sm)*/148, STRING(DEFAULT_GRID_SPACING
)},
99 {HLP_ENCODELONG(5), /*station labels text height (default %s)*/149, STRING(DEFAULT_TEXT_HEIGHT
)},
100 {HLP_ENCODELONG(6), /*station marker size (default %s)*/152, STRING(DEFAULT_MARKER_SIZE
)},
101 {HLP_ENCODELONG(7), /*produce an elevation view*/103, 0},
102 {HLP_ENCODELONG(8), /*factor to scale down by (default %s)*/155, "500"},
103 {HLP_ENCODELONG(9), /*produce DXF output*/156, 0},
104 /* TRANSLATORS: "Skencil" is the name of a software package, so should not be
106 {HLP_ENCODELONG(10), /*produce Skencil output*/158, 0},
107 /* TRANSLATORS: "Compass" and "Carto" are the names of software packages,
108 * so should not be translated. */
109 {HLP_ENCODELONG(11), /*produce Compass PLT output for Carto*/159, 0},
110 {HLP_ENCODELONG(12), /*produce SVG output*/160, 0},
116 cmdline_init(argc
, argv
, short_opts
, long_opts
, NULL
, help
, 1, 2);
118 int opt
= cmdline_getopt();
119 if (opt
== EOF
) break;
121 case 'e': /* Elevation */
122 tilt
= cmdline_double_arg();
124 case 'c': /* Crosses */
127 case 'n': /* Labels */
128 show_mask
&= ~LABELS
;
135 grid
= cmdline_double_arg();
137 grid
= (double)DEFAULT_GRID_SPACING
;
140 case 'r': /* Reduction factor */
141 scale
= cmdline_double_arg();
143 case 't': /* Text height */
144 text_height
= cmdline_double_arg();
146 case 'm': /* Marker size */
147 marker_size
= cmdline_double_arg();
171 const char* fnm_in
= argv
[optind
++];
172 const char* fnm_out
= argv
[optind
];
176 size_t len
= strlen(fnm_out
);
177 format
= FMT_DEFAULT
;
178 for (i
= 0; i
< FMT_MAX_PLUS_ONE_
; ++i
) {
179 size_t l
= strlen(extension
[i
]);
181 strcasecmp(fnm_out
+ len
- l
, extension
[i
]) == 0) {
182 format
= export_format(i
);
188 char *baseleaf
= baseleaf_from_fnm(fnm_in
);
189 if (!format_set
) format
= FMT_DEFAULT
;
190 /* note : memory allocated by fnm_out gets leaked in this case... */
191 fnm_out
= add_ext(baseleaf
, extension
[format
]);
196 int err
= model
.Load(fnm_in
, survey
);
197 if (err
) fatalerror(err
, fnm_in
);
199 if (!Export(fnm_out
, model
.GetSurveyTitle(),
200 model
.GetDateString(),
202 pan
, tilt
, show_mask
, format
,
204 grid
, text_height
, marker_size
,
206 fatalerror(/*Couldn’t write file “%s”*/402, fnm_out
);