summaryrefslogtreecommitdiff
path: root/app/bin/dxfoutput.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/dxfoutput.c')
-rw-r--r--app/bin/dxfoutput.c298
1 files changed, 155 insertions, 143 deletions
diff --git a/app/bin/dxfoutput.c b/app/bin/dxfoutput.c
index 214f63c..3988696 100644
--- a/app/bin/dxfoutput.c
+++ b/app/bin/dxfoutput.c
@@ -17,22 +17,10 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#ifdef WINDOWS
- #include <io.h>
- #include <windows.h>
-#else
- #include <errno.h>
-#endif
-
#include <xtrkcad-config.h>
-#include <locale.h>
-#include <assert.h>
#include <dynstring.h>
@@ -40,199 +28,223 @@
#include "custom.h"
#include "dxfformat.h"
#include "fileio.h"
-#include "i18n.h"
-#include "messages.h"
#include "paths.h"
#include "track.h"
-#include "utility.h"
+#include "draw.h"
+#include "common-ui.h"
static struct wFilSel_t * exportDXFFile_fs;
static void DxfLine(
- drawCmd_p d,
- coOrd p0,
- coOrd p1,
- wDrawWidth width,
- wDrawColor color)
+ drawCmd_p d,
+ coOrd p0,
+ coOrd p1,
+ wDrawWidth width,
+ wDrawColor color)
{
- DynString command = NaS;
- DynStringMalloc(&command, 100);
- DxfLineCommand(&command,
- curTrackLayer + 1,
- p0.x, p0.y,
- p1.x, p1.y,
- ((d->options&DC_DASH) != 0));
- fputs(DynStringToCStr(&command), (FILE *)d->d);
- DynStringFree(&command);
+ long c = wDrawGetRGB( color );
+ long s = d->options & DC_DASH ? 1 : (d->options & DC_DOT ? 2 : 0);
+
+ DynString command = NaS;
+ DynStringMalloc(&command, 100);
+ DxfLineCommand(&command,
+ curTrackLayer + 1,
+ p0.x, p0.y,
+ p1.x, p1.y,
+ s,
+ c);
+ fputs(DynStringToCStr(&command), (FILE *)d->d);
+ DynStringFree(&command);
}
static void DxfArc(
- drawCmd_p d,
- coOrd p,
- DIST_T r,
- ANGLE_T angle0,
- ANGLE_T angle1,
- BOOL_T drawCenter,
- wDrawWidth width,
- wDrawColor color)
+ drawCmd_p d,
+ coOrd p,
+ DIST_T r,
+ ANGLE_T angle0,
+ ANGLE_T angle1,
+ BOOL_T drawCenter,
+ wDrawWidth width,
+ wDrawColor color)
{
- DynString command = NaS;
- DynStringMalloc(&command, 100);
- angle0 = NormalizeAngle(90.0-(angle0+angle1));
-
- if (angle1 >= 360.0) {
- DxfCircleCommand(&command,
- curTrackLayer + 1,
- p.x,
- p.y,
- r,
- ((d->options&DC_DASH) != 0));
- } else {
- DxfArcCommand(&command,
- curTrackLayer + 1,
- p.x,
- p.y,
- r,
- angle0,
- angle1,
- ((d->options&DC_DASH) != 0));
- }
-
- fputs(DynStringToCStr(&command), (FILE *)d->d);
- DynStringFree(&command);
+ long c = wDrawGetRGB( color );
+ long s = d->options & DC_DASH ? 1 : (d->options & DC_DOT ? 2 : 0);
+
+ DynString command = NaS;
+ DynStringMalloc(&command, 100);
+ angle0 = NormalizeAngle(90.0-(angle0+angle1));
+
+ if (angle1 >= 360.0) {
+ DxfCircleCommand(&command,
+ curTrackLayer + 1,
+ p.x,
+ p.y,
+ r,
+ s,
+ c);
+ } else {
+ DxfArcCommand(&command,
+ curTrackLayer + 1,
+ p.x,
+ p.y,
+ r,
+ angle0,
+ angle1,
+ s,
+ c);
+ }
+
+ fputs(DynStringToCStr(&command), (FILE *)d->d);
+ DynStringFree(&command);
}
static void DxfString(
- drawCmd_p d,
- coOrd p,
- ANGLE_T a,
- char * s,
- wFont_p fp,
- FONTSIZE_T fontSize,
- wDrawColor color)
+ drawCmd_p d,
+ coOrd p,
+ ANGLE_T a,
+ char * s,
+ wFont_p fp,
+ FONTSIZE_T fontSize,
+ wDrawColor color)
{
- DynString command = NaS;
- DynStringMalloc(&command, 100);
- DxfTextCommand(&command,
- curTrackLayer + 1,
- p.x,
- p.y,
- fontSize,
- s);
- fputs(DynStringToCStr(&command), (FILE *)d->d);
- DynStringFree(&command);
+ long c = wDrawGetRGB( color );
+
+ DynString command = NaS;
+ DynStringMalloc(&command, 100);
+ DxfTextCommand(&command,
+ curTrackLayer + 1,
+ p.x,
+ p.y,
+ fontSize,
+ s,
+ c);
+ fputs(DynStringToCStr(&command), (FILE *)d->d);
+ DynStringFree(&command);
}
static void DxfBitMap(
- drawCmd_p d,
- coOrd p,
- wDrawBitMap_p bm,
- wDrawColor color)
+ drawCmd_p d,
+ coOrd p,
+ wDrawBitMap_p bm,
+ wDrawColor color)
{
}
-static void DxfFillPoly(
- drawCmd_p d,
- int cnt,
- coOrd * pts,
- int * types,
- wDrawColor color,
- wDrawWidth width,
- int fill,
- int open )
+static void DxfPoly(
+ drawCmd_p d,
+ int cnt,
+ coOrd * pts,
+ int * types,
+ wDrawColor color,
+ wDrawWidth width,
+ drawFill_e eOpts )
{
- int inx;
-
- for (inx=1; inx<cnt; inx++) {
- DxfLine(d, pts[inx-1], pts[inx], width, color);
- }
- if (!open)
- DxfLine(d, pts[cnt-1], pts[0], width, color);
+ int inx;
+
+ for (inx=1; inx<cnt; inx++) {
+ DxfLine(d, pts[inx-1], pts[inx], width, color);
+ }
+ if (eOpts != DRAW_OPEN) {
+ DxfLine(d, pts[cnt-1], pts[0], width, color);
+ }
}
static void DxfFillCircle(drawCmd_p d, coOrd center, DIST_T radius,
wDrawColor color)
{
- DxfArc(d, center, radius, 0.0, 360, FALSE, 0, color);
+ DxfArc(d, center, radius, 0.0, 360, FALSE, 0, color);
+}
+
+
+static void DxfRectangle(drawCmd_p d, coOrd orig, coOrd size, wDrawColor color,
+ drawFill_e eOpts)
+{
+ coOrd p[4];
+ // p1 p2
+ // p0 p3
+ p[0].x = p[1].x = orig.x;
+ p[2].x = p[3].x = orig.x+size.x;
+ p[0].y = p[3].y = orig.y;
+ p[1].y = p[2].y = orig.y+size.y;
+ DxfPoly( d, 4, p, NULL, color, 0, eOpts );
}
static drawFuncs_t dxfDrawFuncs = {
- 0,
- DxfLine,
- DxfArc,
- DxfString,
- DxfBitMap,
- DxfFillPoly,
- DxfFillCircle
+ DxfLine,
+ DxfArc,
+ DxfString,
+ DxfBitMap,
+ DxfPoly,
+ DxfFillCircle,
+ DxfRectangle
};
static drawCmd_t dxfD = {
- NULL, &dxfDrawFuncs, 0, 1.0, 0.0, {0.0,0.0}, {0.0,0.0}, Pix2CoOrd, CoOrd2Pix, 100.0
+ NULL, &dxfDrawFuncs, 0, 1.0, 0.0, {0.0,0.0}, {0.0,0.0}, Pix2CoOrd, CoOrd2Pix, 100.0
};
static int DoExportDXFTracks(
- int cnt,
- char ** fileName,
- void * data)
+ int cnt,
+ char ** fileName,
+ void * data)
{
- time_t clock;
- char *oldLocale;
+ time_t clock;
DynString command = NaS;
FILE * dxfF;
- assert(fileName != NULL);
- assert(cnt == 1);
+ CHECK(fileName != NULL);
+ CHECK(cnt == 1);
DynStringMalloc(&command, 100);
SetCurrentPath(DXFPATHKEY, fileName[ 0 ]);
- dxfF = fopen(fileName[0], "w");
-
- if (dxfF==NULL) {
- NoticeMessage(MSG_OPEN_FAIL, _("Continue"), NULL, "DXF", fileName[0],
- strerror(errno));
- return FALSE;
- }
-
- oldLocale = SaveLocale("C");
- wSetCursor(mainD.d, wCursorWait);
- time(&clock);
-
+ dxfF = fopen(fileName[0], "w");
+
+ if (dxfF==NULL) {
+ NoticeMessage(MSG_OPEN_FAIL, _("Continue"), NULL, "DXF", fileName[0],
+ strerror(errno));
+ return FALSE;
+ }
+
+ SetCLocale();
+ wSetCursor(mainD.d, wCursorWait);
+ time(&clock);
+
DxfPrologue(&command, 10, 0.0, 0.0, mapD.size.x, mapD.size.y);
fputs(DynStringToCStr(&command), dxfF);
dxfD.d = (wDraw_p)dxfF;
- DrawSelectedTracks(&dxfD);
+ DrawSelectedTracks( &dxfD, false );
DynStringClear(&command);
DxfEpilogue(&command);
fputs(DynStringToCStr(&command), dxfF);
- fclose(dxfF);
- RestoreLocale(oldLocale);
- Reset();
- wSetCursor(mainD.d, defaultCursor);
- return TRUE;
+ fclose(dxfF);
+ SetUserLocale();
+ Reset();
+ wSetCursor(mainD.d, defaultCursor);
+ return TRUE;
}
/**
* Create and show the dialog for selected the DXF export filename
*/
-void DoExportDXF(void)
+void DoExportDXF(void* unused )
{
- //if (selectedTrackCount <= 0) {
- // ErrorMessage(MSG_NO_SELECTED_TRK);
- // return;
- //}
- assert(selectedTrackCount > 0);
+ //if (selectedTrackCount <= 0) {
+ // ErrorMessage(MSG_NO_SELECTED_TRK);
+ // return;
+ //}
+ CHECK(selectedTrackCount > 0);
- if (exportDXFFile_fs == NULL)
- exportDXFFile_fs = wFilSelCreate(mainW, FS_SAVE, 0, _("Export to DXF"),
- sDXFFilePattern, DoExportDXFTracks, NULL);
+ if (exportDXFFile_fs == NULL)
+ exportDXFFile_fs = wFilSelCreate(mainW, FS_SAVE, 0, _("Export to DXF"),
+ sDXFFilePattern, DoExportDXFTracks, NULL);
- wFilSelect(exportDXFFile_fs, GetCurrentPath(DXFPATHKEY));
+ wFilSelect(exportDXFFile_fs, GetCurrentPath(DXFPATHKEY));
}