Unicode handling:

Removed the Perl dependencies on Encode, Encode::Locale and Unicode::Normalize.
Added dependency on boost::locale.
Added encode_path, decode_path, normalize_utf8 functions to Slic3r.xs

Slic3r.xs has been made mostly utf8 safe by using the boost::nowide library,
thanks to @alexrj for the idea.

Simplified the encode_path / decode_path stuff:
wxWidgets are unicode already, so there is no need to decode_path() from it.
Perl / win32 interfacing is non-unicode, so decode_path() is executed
on ARGV just at the beginning of the perl scripts.
This commit is contained in:
bubnikv 2017-08-03 17:31:31 +02:00
parent 31085fb1d7
commit 1385018724
33 changed files with 236 additions and 186 deletions

View file

@ -27,9 +27,13 @@
#include "stl.h"
static void stl_reverse_facet(stl_file *stl, int facet_num);
static void stl_reverse_vector(float v[]);
int stl_check_normal_vector(stl_file *stl, int facet_num, int normal_fix_flag);
static void stl_reverse_vector(float v[]) {
v[0] *= -1;
v[1] *= -1;
v[2] *= -1;
}
static int stl_check_normal_vector(stl_file *stl, int facet_num, int normal_fix_flag);
static void
stl_reverse_facet(stl_file *stl, int facet_num) {
@ -136,10 +140,8 @@ stl_fix_normal_directions(stl_file *stl) {
/* Reverse the neighboring facets if necessary. */
if(stl->neighbors_start[facet_num].which_vertex_not[j] > 2) {
/* If the facet has a neighbor that is -1, it means that edge isn't shared by another facet */
if(stl->neighbors_start[facet_num].neighbor[j] != -1) {
stl_reverse_facet
(stl, stl->neighbors_start[facet_num].neighbor[j]);
}
if(stl->neighbors_start[facet_num].neighbor[j] != -1)
stl_reverse_facet(stl, stl->neighbors_start[facet_num].neighbor[j]);
}
/* If this edge of the facet is connected: */
if(stl->neighbors_start[facet_num].neighbor[j] != -1) {
@ -193,8 +195,7 @@ stl_fix_normal_directions(stl_file *stl) {
free(norm_sw);
}
int
stl_check_normal_vector(stl_file *stl, int facet_num, int normal_fix_flag) {
static int stl_check_normal_vector(stl_file *stl, int facet_num, int normal_fix_flag) {
/* Returns 0 if the normal is within tolerance */
/* Returns 1 if the normal is not within tolerance, but direction is OK */
/* Returns 2 if the normal is not within tolerance and backwards */
@ -259,26 +260,17 @@ stl_check_normal_vector(stl_file *stl, int facet_num, int normal_fix_flag) {
return 4;
}
static void
stl_reverse_vector(float v[]) {
v[0] *= -1;
v[1] *= -1;
v[2] *= -1;
}
void
stl_calculate_normal(float normal[], stl_facet *facet) {
float v1[3];
float v2[3];
v1[0] = facet->vertex[1].x - facet->vertex[0].x;
v1[1] = facet->vertex[1].y - facet->vertex[0].y;
v1[2] = facet->vertex[1].z - facet->vertex[0].z;
v2[0] = facet->vertex[2].x - facet->vertex[0].x;
v2[1] = facet->vertex[2].y - facet->vertex[0].y;
v2[2] = facet->vertex[2].z - facet->vertex[0].z;
void stl_calculate_normal(float normal[], stl_facet *facet) {
float v1[3] = {
facet->vertex[1].x - facet->vertex[0].x,
facet->vertex[1].y - facet->vertex[0].y,
facet->vertex[1].z - facet->vertex[0].z
};
float v2[3] = {
facet->vertex[2].x - facet->vertex[0].x,
facet->vertex[2].y - facet->vertex[0].y,
facet->vertex[2].z - facet->vertex[0].z
};
normal[0] = (float)((double)v1[1] * (double)v2[2]) - ((double)v1[2] * (double)v2[1]);
normal[1] = (float)((double)v1[2] * (double)v2[0]) - ((double)v1[0] * (double)v2[2]);
normal[2] = (float)((double)v1[0] * (double)v2[1]) - ((double)v1[1] * (double)v2[0]);

View file

@ -23,6 +23,8 @@
#include <stdlib.h>
#include <string.h>
#include <boost/nowide/cstdio.hpp>
#include "stl.h"
void
@ -149,7 +151,7 @@ stl_write_off(stl_file *stl, char *file) {
if (stl->error) return;
/* Open the file */
fp = fopen(file, "w");
fp = boost::nowide::fopen(file, "w");
if(fp == NULL) {
error_msg = (char*)
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
@ -185,7 +187,7 @@ stl_write_vrml(stl_file *stl, char *file) {
if (stl->error) return;
/* Open the file */
fp = fopen(file, "w");
fp = boost::nowide::fopen(file, "w");
if(fp == NULL) {
error_msg = (char*)
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
@ -241,7 +243,7 @@ void stl_write_obj (stl_file *stl, char *file) {
if (stl->error) return;
/* Open the file */
fp = fopen(file, "w");
fp = boost::nowide::fopen(file, "w");
if (fp == NULL) {
char* error_msg = (char*)malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
sprintf(error_msg, "stl_write_ascii: Couldn't open %s for writing", file);

View file

@ -32,10 +32,6 @@
#error "admesh works correctly on little endian machines only!"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define STL_MAX(A,B) ((A)>(B)? (A):(B))
#define STL_MIN(A,B) ((A)<(B)? (A):(B))
#define ABS(X) ((X) < 0 ? -(X) : (X))
@ -223,8 +219,4 @@ extern void stl_clear_error(stl_file *stl);
extern int stl_get_error(stl_file *stl);
extern void stl_exit_on_error(stl_file *stl);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -25,6 +25,8 @@
#include "stl.h"
#include "config.h"
#include <boost/nowide/cstdio.hpp>
#if !defined(SEEK_SET)
#define SEEK_SET 0
#define SEEK_CUR 1
@ -126,13 +128,12 @@ Normals fixed : %5d\n", stl->stats.normals_fixed);
void
stl_write_ascii(stl_file *stl, const char *file, const char *label) {
int i;
FILE *fp;
char *error_msg;
if (stl->error) return;
/* Open the file */
fp = fopen(file, "w");
FILE *fp = boost::nowide::fopen(file, "w");
if(fp == NULL) {
error_msg = (char*)
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
@ -178,7 +179,7 @@ stl_print_neighbors(stl_file *stl, char *file) {
if (stl->error) return;
/* Open the file */
fp = fopen(file, "w");
fp = boost::nowide::fopen(file, "w");
if(fp == NULL) {
error_msg = (char*)
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
@ -212,7 +213,7 @@ stl_write_binary(stl_file *stl, const char *file, const char *label) {
if (stl->error) return;
/* Open the file */
fp = fopen(file, "wb");
fp = boost::nowide::fopen(file, "wb");
if(fp == NULL) {
error_msg = (char*)
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
@ -292,7 +293,7 @@ stl_write_quad_object(stl_file *stl, char *file) {
if (stl->error) return;
/* Open the file */
fp = fopen(file, "w");
fp = boost::nowide::fopen(file, "w");
if(fp == NULL) {
error_msg = (char*)
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
@ -360,7 +361,7 @@ stl_write_dxf(stl_file *stl, char *file, char *label) {
if (stl->error) return;
/* Open the file */
fp = fopen(file, "w");
fp = boost::nowide::fopen(file, "w");
if(fp == NULL) {
error_msg = (char*)
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */

View file

@ -26,6 +26,8 @@
#include <math.h>
#include <assert.h>
#include <boost/nowide/cstdio.hpp>
#include "stl.h"
#ifndef SEEK_SET
@ -62,7 +64,7 @@ stl_count_facets(stl_file *stl, const char *file) {
if (stl->error) return;
/* Open the file in binary mode first */
stl->fp = fopen(file, "rb");
stl->fp = boost::nowide::fopen(file, "rb");
if(stl->fp == NULL) {
error_msg = (char*)
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
@ -121,7 +123,7 @@ stl_count_facets(stl_file *stl, const char *file) {
/* Reopen the file in text mode (for getting correct newlines on Windows) */
// fix to silence a warning about unused return value.
// obviously if it fails we have problems....
stl->fp = freopen(file, "r", stl->fp);
stl->fp = boost::nowide::freopen(file, "r", stl->fp);
// do another null check to be safe
if(stl->fp == NULL) {

View file

@ -186,7 +186,7 @@ static void calculate_normals(stl_file *stl) {
}
void stl_transform(stl_file *stl, float *trafo3x4) {
int i_face, i_vertex, i, j;
int i_face, i_vertex;
if (stl->error)
return;
for (i_face = 0; i_face < stl->stats.number_of_facets; ++ i_face) {
@ -404,7 +404,7 @@ static float get_volume(stl_file *stl) {
n = stl->facet_start[i].normal;
height = (n.x * p.x) + (n.y * p.y) + (n.z * p.z);
area = get_area(&stl->facet_start[i]);
volume += (area * height) / 3.0;
volume += (area * height) / 3.0f;
}
return volume;
}