Fixed conflicts after merge with master

This commit is contained in:
enricoturri1966 2020-04-01 15:06:30 +02:00
commit f598c2d5d8
229 changed files with 27582 additions and 16304 deletions

View file

@ -104,33 +104,7 @@ endif ()
# Add the Slic3r GUI library, libcurl, OpenGL and GLU libraries.
if (SLIC3R_GUI)
# target_link_libraries(PrusaSlicer ws2_32 uxtheme setupapi libslic3r_gui ${wxWidgets_LIBRARIES})
target_link_libraries(PrusaSlicer libslic3r_gui ${wxWidgets_LIBRARIES})
# Configure libcurl and its dependencies OpenSSL & zlib
find_package(CURL REQUIRED)
if (NOT WIN32)
# Required by libcurl
find_package(ZLIB REQUIRED)
endif()
target_include_directories(PrusaSlicer PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(PrusaSlicer ${CURL_LIBRARIES} ${ZLIB_LIBRARIES})
if (SLIC3R_STATIC)
if (NOT APPLE)
# libcurl is always linked dynamically to the system libcurl on OSX.
# On other systems, libcurl is linked statically if SLIC3R_STATIC is set.
target_compile_definitions(PrusaSlicer PRIVATE CURL_STATICLIB)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# As of now, our build system produces a statically linked libcurl,
# which links the OpenSSL library dynamically.
find_package(OpenSSL REQUIRED)
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
target_include_directories(PrusaSlicer PRIVATE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(PrusaSlicer ${OPENSSL_LIBRARIES})
endif()
endif()
target_link_libraries(PrusaSlicer libslic3r_gui)
if (MSVC)
# Generate debug symbols even in release mode.
target_link_options(PrusaSlicer PUBLIC "$<$<CONFIG:RELEASE>:/DEBUG>")

View file

@ -132,14 +132,18 @@ int CLI::run(int argc, char **argv)
Model model;
try {
// When loading an AMF or 3MF, config is imported as well, including the printer technology.
model = Model::read_from_file(file, &m_print_config, true);
PrinterTechnology other_printer_technology = get_printer_technology(m_print_config);
DynamicPrintConfig config;
model = Model::read_from_file(file, &config, true);
PrinterTechnology other_printer_technology = get_printer_technology(config);
if (printer_technology == ptUnknown) {
printer_technology = other_printer_technology;
} else if (printer_technology != other_printer_technology && other_printer_technology != ptUnknown) {
boost::nowide::cerr << "Mixing configurations for FFF and SLA technologies" << std::endl;
return 1;
}
// config is applied to m_print_config before the current m_config values.
config += std::move(m_print_config);
m_print_config = std::move(config);
} catch (std::exception &e) {
boost::nowide::cerr << file << ": " << e.what() << std::endl;
return 1;
@ -527,8 +531,10 @@ int CLI::run(int argc, char **argv)
gui->mainframe->load_config(m_extra_config);
});
int result = wxEntry(argc, argv);
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
//FIXME this is a workaround for the PrusaSlicer 2.1 release.
_3DScene::destroy();
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
return result;
#else /* SLIC3R_GUI */
// No GUI support. Just print out a help.
@ -640,6 +646,14 @@ void CLI::print_help(bool include_print_options, PrinterTechnology printer_techn
<< "Other options:" << std::endl;
cli_misc_config_def.print_cli_help(boost::nowide::cout, false);
boost::nowide::cout
<< std::endl
<< "Print options are processed in the following order:" << std::endl
<< "\t1) Config keys from the command line, for example --fill-pattern=stars" << std::endl
<< "\t (highest priority, overwrites everything below)" << std::endl
<< "\t2) Config files loaded with --load" << std::endl
<< "\t3) Config values loaded from amf or 3mf files" << std::endl;
if (include_print_options) {
boost::nowide::cout << std::endl;
print_config_def.print_cli_help(boost::nowide::cout, true, [printer_technology](const ConfigOptionDef &def)

View file

@ -159,7 +159,7 @@ static int hid_wrapper_udev_init()
{
// Error, close the shared library handle and finish.
hid_wrapper_udev_close();
return -1;
return -2;
}
// Success.

5
src/imgui/README.md Normal file
View file

@ -0,0 +1,5 @@
** Dear ImGui is a bloat-free graphical user interface library for C++.**
For more information go to https://github.com/ocornut/imgui
THIS DIRECTORY CONTAINS THE imgui-1.75 58b3e02 SOURCE DISTRIBUTION.

View file

@ -3,10 +3,10 @@
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
// A) You may edit imconfig.h (and not overwrite it when updating imgui, or maintain a patch/branch with your modifications to imconfig.h)
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/branch with your modifications to imconfig.h)
// B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ dear imgui is used, which include
// the imgui*.cpp files but also _any_ of your code that uses imgui. This is because some compile-time options have an affect on data structures.
// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include
// the imgui*.cpp files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------
@ -14,25 +14,32 @@
#pragma once
//---- Define assertion handler. Defaults to calling assert().
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )
//---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty)
//---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp.
//#define IMGUI_DISABLE_DEMO_WINDOWS
//---- Disable all of Dear ImGui or don't implement standard windows.
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable debug/metrics window: ShowMetricsWindow() will be empty.
//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
//#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf.
//#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h.
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
//---- Include imgui_user.h at the end of imgui.h as a convenience
@ -48,6 +55,10 @@
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
//---- Unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined, use the much faster STB sprintf library implementation of vsnprintf instead of the one from the default C library.
// Note that stb_sprintf.h is meant to be provided by the user and available in the include path at compile time. Also, the compatibility checks of the arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
// #define IMGUI_USE_STB_SPRINTF
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
/*
@ -60,9 +71,31 @@
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/
//---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it.
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
// Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bit indices).
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
//#define ImDrawIdx unsigned int
//---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly)
//struct ImDrawList;
//struct ImDrawCmd;
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
//#define ImDrawCallback MyImDrawCallback
//---- Debug Tools: Macro to break in Debugger
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
//#define IM_DEBUG_BREAK IM_ASSERT(0)
//#define IM_DEBUG_BREAK __debugbreak()
//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
// This adds a small runtime cost which is why it is not enabled by default.
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
//---- Debug Tools: Enable slower asserts
//#define IMGUI_DEBUG_PARANOID
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
/*
namespace ImGui

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,10 @@
// stb_rect_pack.h - v0.11 - public domain - rectangle packing
// [DEAR IMGUI]
// This is a slightly modified version of stb_rect_pack.h 1.00.
// Those changes would need to be pushed into nothings/stb:
// - Added STBRP__CDECL
// Grep for [DEAR IMGUI] to find the changes.
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
// Sean Barrett 2014
//
// Useful for e.g. packing rectangular textures into an atlas.
@ -31,9 +37,12 @@
//
// Bugfixes / warning fixes
// Jeremy Jaussaud
// Fabian Giesen
//
// Version history:
//
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
// 0.99 (2019-02-07) warning fixes
// 0.11 (2017-03-03) return packing success/fail result
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
// 0.09 (2016-08-27) fix compiler warnings
@ -204,6 +213,7 @@ struct stbrp_context
#define STBRP_ASSERT assert
#endif
// [DEAR IMGUI] Added STBRP__CDECL
#ifdef _MSC_VER
#define STBRP__NOTUSED(v) (void)(v)
#define STBRP__CDECL __cdecl
@ -349,6 +359,13 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
width -= width % c->align;
STBRP_ASSERT(width % c->align == 0);
// if it can't possibly fit, bail immediately
if (width > c->width || height > c->height) {
fr.prev_link = NULL;
fr.x = fr.y = 0;
return fr;
}
node = c->active_head;
prev = &c->active_head;
while (node->x + width <= c->width) {
@ -412,7 +429,7 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
}
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
if (y + height < c->height) {
if (y + height <= c->height) {
if (y <= best_y) {
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
best_x = xpos;
@ -512,6 +529,7 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
return res;
}
// [DEAR IMGUI] Added STBRP__CDECL
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
{
const stbrp_rect *p = (const stbrp_rect *) a;
@ -523,6 +541,7 @@ static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
return (p->w > q->w) ? -1 : (p->w < q->w);
}
// [DEAR IMGUI] Added STBRP__CDECL
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
{
const stbrp_rect *p = (const stbrp_rect *) a;
@ -543,9 +562,6 @@ STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int nu
// we use the 'was_packed' field internally to allow sorting/unsorting
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = i;
#ifndef STBRP_LARGE_RECTS
STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
#endif
}
// sort according to heuristic

View file

@ -1,9 +1,10 @@
// [ImGui] this is a slightly modified version of stb_textedit.h 1.12. Those changes would need to be pushed into nothings/stb
// [ImGui] - 2018-06: fixed undo/redo after pasting large amount of text (over 32 kb). Redo will still fail when undo buffers are exhausted, but text won't be corrupted (see nothings/stb issue #620)
// [ImGui] - 2018-06: fix in stb_textedit_discard_redo (see https://github.com/nothings/stb/issues/321)
// [ImGui] - fixed some minor warnings
// [DEAR IMGUI]
// This is a slightly modified version of stb_textedit.h 1.13.
// Those changes would need to be pushed into nothings/stb:
// - Fix in stb_textedit_discard_redo (see https://github.com/nothings/stb/issues/321)
// Grep for [DEAR IMGUI] to find the changes.
// stb_textedit.h - v1.12 - public domain - Sean Barrett
// stb_textedit.h - v1.13 - public domain - Sean Barrett
// Development of this library was sponsored by RAD Game Tools
//
// This C header file implements the guts of a multi-line text-editing
@ -34,6 +35,7 @@
//
// VERSION HISTORY
//
// 1.13 (2019-02-07) fix bug in undo size management
// 1.12 (2018-01-29) user can change STB_TEXTEDIT_KEYTYPE, fix redo to avoid crash
// 1.11 (2017-03-03) fix HOME on last line, dragging off single-line textfield
// 1.10 (2016-10-25) supress warnings about casting away const with -Wcast-qual
@ -563,7 +565,6 @@ static void stb_textedit_find_charpos(StbFindState *find, STB_TEXTEDIT_STRING *s
// now scan to find xpos
find->x = r.x0;
i = 0;
for (i=0; first+i < n; ++i)
find->x += STB_TEXTEDIT_GETWIDTH(str, first, i);
}
@ -693,7 +694,7 @@ static void stb_textedit_prep_selection_at_cursor(STB_TexteditState *state)
static int stb_textedit_cut(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
{
if (STB_TEXT_HAS_SELECTION(state)) {
stb_textedit_delete_selection(str,state); // implicity clamps
stb_textedit_delete_selection(str,state); // implicitly clamps
state->has_preferred_x = 0;
return 1;
}
@ -745,7 +746,7 @@ retry:
state->has_preferred_x = 0;
}
} else {
stb_textedit_delete_selection(str,state); // implicity clamps
stb_textedit_delete_selection(str,state); // implicitly clamps
if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
stb_text_makeundo_insert(state, state->cursor, 1);
++state->cursor;
@ -1133,7 +1134,14 @@ static void stb_textedit_discard_redo(StbUndoState *state)
state->undo_rec[i].char_storage += n;
}
// now move all the redo records towards the end of the buffer; the first one is at 'redo_point'
STB_TEXTEDIT_memmove(state->undo_rec + state->redo_point+1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0])));
// {DEAR IMGUI]
size_t move_size = (size_t)((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point - 1) * sizeof(state->undo_rec[0]));
const char* buf_begin = (char*)state->undo_rec; (void)buf_begin;
const char* buf_end = (char*)state->undo_rec + sizeof(state->undo_rec); (void)buf_end;
IM_ASSERT(((char*)(state->undo_rec + state->redo_point)) >= buf_begin);
IM_ASSERT(((char*)(state->undo_rec + state->redo_point + 1) + move_size) <= buf_end);
STB_TEXTEDIT_memmove(state->undo_rec + state->redo_point+1, state->undo_rec + state->redo_point, move_size);
// now move redo_point to point to the new one
++state->redo_point;
}

View file

@ -1,4 +1,9 @@
// stb_truetype.h - v1.19 - public domain
// [DEAR IMGUI]
// This is a slightly modified version of stb_truetype.h 1.20.
// Mostly fixing for compiler and static analyzer warnings.
// Grep for [DEAR IMGUI] to find the changes.
// stb_truetype.h - v1.20 - public domain
// authored from 2009-2016 by Sean Barrett / RAD Game Tools
//
// This library processes TrueType files:
@ -49,6 +54,7 @@
//
// VERSION HISTORY
//
// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics()
// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
// 1.18 (2018-01-29) add missing function
// 1.17 (2017-07-23) make more arguments const; doc fix
@ -75,7 +81,7 @@
//
// USAGE
//
// Include this file in whatever places neeed to refer to it. In ONE C/C++
// Include this file in whatever places need to refer to it. In ONE C/C++
// file, write:
// #define STB_TRUETYPE_IMPLEMENTATION
// before the #include of this file. This expands out the actual
@ -247,8 +253,8 @@
// Documentation & header file 520 LOC \___ 660 LOC documentation
// Sample code 140 LOC /
// Truetype parsing 620 LOC ---- 620 LOC TrueType
// Software rasterization 240 LOC \ .
// Curve tesselation 120 LOC \__ 550 LOC Bitmap creation
// Software rasterization 240 LOC \.
// Curve tessellation 120 LOC \__ 550 LOC Bitmap creation
// Bitmap management 100 LOC /
// Baked bitmap interface 70 LOC /
// Font name matching & access 150 LOC ---- 150
@ -556,6 +562,8 @@ STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int p
//
// It's inefficient; you might want to c&p it and optimize it.
STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap);
// Query the font vertical metrics without having to create a font first.
//////////////////////////////////////////////////////////////////////////////
@ -641,6 +649,12 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h
// To use with PackFontRangesGather etc., you must set it before calls
// call to PackFontRangesGatherRects.
STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip);
// If skip != 0, this tells stb_truetype to skip any codepoints for which
// there is no corresponding glyph. If skip=0, which is the default, then
// codepoints without a glyph recived the font's "missing character" glyph,
// typically an empty box by convention.
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above
int char_index, // character to display
float *xpos, float *ypos, // pointers to current position in screen pixel space
@ -669,6 +683,7 @@ struct stbtt_pack_context {
int height;
int stride_in_bytes;
int padding;
int skip_missing;
unsigned int h_oversample, v_oversample;
unsigned char *pixels;
void *nodes;
@ -694,7 +709,7 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);
// file will only define one font and it always be at offset 0, so it will
// return '0' for index 0, and -1 for all other indices.
// The following structure is defined publically so you can declare one on
// The following structure is defined publicly so you can declare one on
// the stack or as a global or etc, but you should treat it as opaque.
struct stbtt_fontinfo
{
@ -733,6 +748,7 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
// and you want a speed-up, call this function with the character you're
// going to process, then use glyph-based functions instead of the
// codepoint-based functions.
// Returns 0 if the character codepoint is not defined in the font.
//////////////////////////////////////////////////////////////////////////////
@ -820,7 +836,7 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s
// returns # of vertices and fills *vertices with the pointer to them
// these are expressed in "unscaled" coordinates
//
// The shape is a series of countours. Each one starts with
// The shape is a series of contours. Each one starts with
// a STBTT_moveto, then consists of a series of mixed
// STBTT_lineto and STBTT_curveto segments. A lineto
// draws a line from previous endpoint to its x,y; a curveto
@ -916,7 +932,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff);
// These functions compute a discretized SDF field for a single character, suitable for storing
// in a single-channel texture, sampling with bilinear filtering, and testing against
// larger than some threshhold to produce scalable fonts.
// larger than some threshold to produce scalable fonts.
// info -- the font
// scale -- controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap
// glyph/codepoint -- the character to generate the SDF for
@ -1825,7 +1841,7 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
if (comp_verts) STBTT_free(comp_verts, info->userdata);
return 0;
}
if (num_vertices > 0) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex));
if (num_vertices > 0) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex)); //-V595
STBTT_memcpy(tmp+num_vertices, comp_verts, comp_num_verts*sizeof(stbtt_vertex));
if (vertices) STBTT_free(vertices, info->userdata);
vertices = tmp;
@ -2196,7 +2212,7 @@ static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, st
} break;
default:
if (b0 != 255 && b0 != 28 && (b0 < 32 || b0 > 254))
if (b0 != 255 && b0 != 28 && (b0 < 32 || b0 > 254)) //-V560
return STBTT__CSERR("reserved operator");
// push immediate
@ -2368,7 +2384,8 @@ static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph)
if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount)
return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID));
classDefTable = classDef1ValueArray + 2 * glyphCount;
// [DEAR IMGUI] Commented to fix static analyzer warning
//classDefTable = classDef1ValueArray + 2 * glyphCount;
} break;
case 2: {
@ -2392,7 +2409,8 @@ static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph)
return (stbtt_int32)ttUSHORT(classRangeRecord + 4);
}
classDefTable = classRangeRecords + 6 * classRangeCount;
// [DEAR IMGUI] Commented to fix static analyzer warning
//classDefTable = classRangeRecords + 6 * classRangeCount;
} break;
default: {
@ -3024,6 +3042,8 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
dx = -dx;
dy = -dy;
t = x0, x0 = xb, xb = t;
// [DEAR IMGUI] Fix static analyzer warning
(void)dx; // [ImGui: fix static analyzer warning]
}
x1 = (int) x_top;
@ -3161,7 +3181,13 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
if (e->y0 != e->y1) {
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
if (z != NULL) {
STBTT_assert(z->ey >= scan_y_top);
if (j == 0 && off_y != 0) {
if (z->ey < scan_y_top) {
// this can happen due to subpixel positioning and some kind of fp rounding error i think
z->ey = scan_y_top;
}
}
STBTT_assert(z->ey >= scan_y_top); // if we get really unlucky a tiny bit of an edge can be out of bounds
// insert at front
z->next = active;
active = z;
@ -3230,7 +3256,7 @@ static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n)
static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n)
{
/* threshhold for transitioning to insertion sort */
/* threshold for transitioning to insertion sort */
while (n > 12) {
stbtt__edge t;
int c01,c12,c,m,i,j;
@ -3365,7 +3391,7 @@ static void stbtt__add_point(stbtt__point *points, int n, float x, float y)
points[n].y = y;
}
// tesselate until threshhold p is happy... @TODO warped to compensate for non-linear stretching
// tessellate until threshold p is happy... @TODO warped to compensate for non-linear stretching
static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float objspace_flatness_squared, int n)
{
// midpoint
@ -3790,6 +3816,7 @@ STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, in
spc->stride_in_bytes = stride_in_bytes != 0 ? stride_in_bytes : pw;
spc->h_oversample = 1;
spc->v_oversample = 1;
spc->skip_missing = 0;
stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes);
@ -3815,6 +3842,11 @@ STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h
spc->v_oversample = v_oversample;
}
STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip)
{
spc->skip_missing = skip;
}
#define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1)
static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width)
@ -3968,13 +4000,17 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb
int x0,y0,x1,y1;
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
int glyph = stbtt_FindGlyphIndex(info, codepoint);
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
scale * spc->h_oversample,
scale * spc->v_oversample,
0,0,
&x0,&y0,&x1,&y1);
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
if (glyph == 0 && spc->skip_missing) {
rects[k].w = rects[k].h = 0;
} else {
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
scale * spc->h_oversample,
scale * spc->v_oversample,
0,0,
&x0,&y0,&x1,&y1);
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
}
++k;
}
}
@ -4027,7 +4063,7 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const
sub_y = stbtt__oversample_shift(spc->v_oversample);
for (j=0; j < ranges[i].num_chars; ++j) {
stbrp_rect *r = &rects[k];
if (r->was_packed) {
if (r->was_packed && r->w != 0 && r->h != 0) {
stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
int advance, lsb, x0,y0,x1,y1;
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
@ -4141,6 +4177,19 @@ STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *
return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);
}
STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap)
{
int i_ascent, i_descent, i_lineGap;
float scale;
stbtt_fontinfo info;
stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata, index));
scale = size > 0 ? stbtt_ScaleForPixelHeight(&info, size) : stbtt_ScaleForMappingEmToPixels(&info, -size);
stbtt_GetFontVMetrics(&info, &i_ascent, &i_descent, &i_lineGap);
*ascent = (float) i_ascent * scale;
*descent = (float) i_descent * scale;
*lineGap = (float) i_lineGap * scale;
}
STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
{
float ipw = 1.0f / pw, iph = 1.0f / ph;
@ -4253,7 +4302,7 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex
int winding = 0;
orig[0] = x;
orig[1] = y;
//orig[1] = y; // [DEAR IMGUI] commmented double assignment
// make sure y never passes through a vertex of the shape
y_frac = (float) STBTT_fmod(y, 1.0f);

View file

@ -278,6 +278,8 @@ template<class RawShape> class EdgeCache {
inline Vertex coords(const ContourCache& cache, double distance) const {
assert(distance >= .0 && distance <= 1.0);
if (cache.distances.empty() || cache.emap.empty()) return Vertex{};
if (distance > 1.0) distance = std::fmod(distance, 1.0);
// distance is from 0.0 to 1.0, we scale it up to the full length of
// the circumference

View file

@ -43,7 +43,10 @@ protected:
Placer p{bin};
p.configure(pcfg);
if (itm.area() <= 0 || !p.pack(cpy)) it = c.erase(it);
if (itm.area() <= 0 || !p.pack(cpy)) {
static_cast<Item&>(*it).binId(BIN_ID_UNSET);
it = c.erase(it);
}
else it++;
}
}

View file

@ -577,7 +577,7 @@ void _arrange(
std::function<bool()> stopfn)
{
// Integer ceiling the min distance from the bed perimeters
coord_t md = minobjd - 2 * scaled(0.1 + EPSILON);
coord_t md = minobjd;
md = (md % 2) ? md / 2 + 1 : md / 2;
auto corrected_bin = bin;

View file

@ -64,6 +64,7 @@ add_library(libslic3r STATIC
Fill/FillRectilinear3.hpp
Flow.cpp
Flow.hpp
format.hpp
Format/3mf.cpp
Format/3mf.hpp
Format/AMF.cpp

View file

@ -1,4 +1,5 @@
#include "Config.hpp"
#include "format.hpp"
#include "Utils.hpp"
#include <assert.h>
#include <fstream>
@ -464,7 +465,7 @@ bool ConfigBase::set_deserialize_nothrow(const t_config_option_key &opt_key_src,
void ConfigBase::set_deserialize(const t_config_option_key &opt_key_src, const std::string &value_src, bool append)
{
if (! this->set_deserialize_nothrow(opt_key_src, value_src, append))
throw BadOptionTypeException("ConfigBase::set_deserialize() failed");
throw BadOptionTypeException(format("ConfigBase::set_deserialize() failed for parameter \"%1%\", value \"%2%\"", opt_key_src, value_src));
}
void ConfigBase::set_deserialize(std::initializer_list<SetDeserializeItem> items)
@ -620,7 +621,7 @@ void ConfigBase::load_from_gcode_file(const std::string &file)
size_t key_value_pairs = load_from_gcode_string(data.data());
if (key_value_pairs < 80)
throw std::runtime_error((boost::format("Suspiciously low number of configuration values extracted from %1%: %2%") % file % key_value_pairs).str());
throw std::runtime_error(format("Suspiciously low number of configuration values extracted from %1%: %2%", file, key_value_pairs));
}
// Load the config keys from the given string.

View file

@ -56,10 +56,9 @@ public:
class BadOptionTypeException : public std::runtime_error
{
public:
BadOptionTypeException() :
std::runtime_error("Bad option type exception") {}
BadOptionTypeException(const char* message) :
std::runtime_error(message) {}
BadOptionTypeException() : std::runtime_error("Bad option type exception") {}
BadOptionTypeException(const std::string &message) : std::runtime_error(message) {}
BadOptionTypeException(const char* message) : std::runtime_error(message) {}
};
// Type of a configuration value.

View file

@ -62,7 +62,8 @@ std::vector<std::pair<double, unsigned int>> custom_tool_changes(const Info& cus
for (const Item& custom_gcode : custom_gcode_per_print_z.gcodes)
if (custom_gcode.gcode == ToolChangeCode) {
// If extruder count in PrinterSettings was changed, use default (0) extruder for extruders, more than num_extruders
custom_tool_changes.emplace_back(custom_gcode.print_z, static_cast<unsigned int>(custom_gcode.extruder > num_extruders ? 1 : custom_gcode.extruder));
assert(custom_gcode.extruder >= 0);
custom_tool_changes.emplace_back(custom_gcode.print_z, static_cast<unsigned int>(size_t(custom_gcode.extruder) > num_extruders ? 1 : custom_gcode.extruder));
}
return custom_tool_changes;
}

View file

@ -1147,7 +1147,7 @@ EdgeGrid::Grid::ClosestPointResult EdgeGrid::Grid::closest_point(const Point &pt
}
}
}
if (result.contour_idx != -1 && d_min <= double(search_radius)) {
if (result.contour_idx != size_t(-1) && d_min <= double(search_radius)) {
result.distance = d_min * sign_min;
result.t /= l2_seg_min;
assert(result.t >= 0. && result.t < 1.);

View file

@ -218,10 +218,10 @@ public:
bbox.min /= m_resolution;
bbox.max /= m_resolution;
// Trim with the cells.
bbox.min.x() = std::max(bbox.min.x(), 0);
bbox.min.y() = std::max(bbox.min.y(), 0);
bbox.max.x() = std::min(bbox.max.x(), (coord_t)m_cols - 1);
bbox.max.y() = std::min(bbox.max.y(), (coord_t)m_rows - 1);
bbox.min.x() = std::max<coord_t>(bbox.min.x(), 0);
bbox.min.y() = std::max<coord_t>(bbox.min.y(), 0);
bbox.max.x() = std::min<coord_t>(bbox.max.x(), (coord_t)m_cols - 1);
bbox.max.y() = std::min<coord_t>(bbox.max.y(), (coord_t)m_rows - 1);
for (coord_t iy = bbox.min.y(); iy <= bbox.max.y(); ++ iy)
for (coord_t ix = bbox.min.x(); ix <= bbox.max.x(); ++ ix)
if (! visitor(iy, ix))

View file

@ -40,7 +40,7 @@ public:
~ExtrusionEntityCollection() { clear(); }
explicit operator ExtrusionPaths() const;
bool is_collection() const { return true; }
bool is_collection() const override { return true; }
ExtrusionRole role() const override {
ExtrusionRole out = erNone;
for (const ExtrusionEntity *ee : entities) {
@ -49,7 +49,7 @@ public:
}
return out;
}
bool can_reverse() const { return !this->no_sort; }
bool can_reverse() const override { return !this->no_sort; }
bool empty() const { return this->entities.empty(); }
void clear();
void swap (ExtrusionEntityCollection &c);
@ -83,9 +83,9 @@ public:
static ExtrusionEntityCollection chained_path_from(const ExtrusionEntitiesPtr &extrusion_entities, const Point &start_near, ExtrusionRole role = erMixed);
ExtrusionEntityCollection chained_path_from(const Point &start_near, ExtrusionRole role = erMixed) const
{ return this->no_sort ? *this : chained_path_from(this->entities, start_near, role); }
void reverse();
const Point& first_point() const { return this->entities.front()->first_point(); }
const Point& last_point() const { return this->entities.back()->last_point(); }
void reverse() override;
const Point& first_point() const override { return this->entities.front()->first_point(); }
const Point& last_point() const override { return this->entities.back()->last_point(); }
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width.
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
void polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const override;
@ -102,11 +102,11 @@ public:
/// You should be iterating over flatten().entities if you are interested in the underlying ExtrusionEntities (and don't care about hierarchy).
/// \param preserve_ordering Flag to method that will flatten if and only if the underlying collection is sortable when True (default: False).
ExtrusionEntityCollection flatten(bool preserve_ordering = false) const;
double min_mm3_per_mm() const;
double min_mm3_per_mm() const override;
double total_volume() const override { double volume=0.; for (const auto& ent : entities) volume+=ent->total_volume(); return volume; }
// Following methods shall never be called on an ExtrusionEntityCollection.
Polyline as_polyline() const {
Polyline as_polyline() const override {
throw std::runtime_error("Calling as_polyline() on a ExtrusionEntityCollection");
return Polyline();
};

View file

@ -114,7 +114,7 @@ std::vector<SurfaceFill> group_fills(const Layer &layer)
if (surface.surface_type == stInternalVoid)
has_internal_voids = true;
else {
FlowRole extrusion_role = (surface.surface_type == stTop) ? frTopSolidInfill : (surface.is_solid() ? frSolidInfill : frInfill);
FlowRole extrusion_role = surface.is_top() ? frTopSolidInfill : (surface.is_solid() ? frSolidInfill : frInfill);
bool is_bridge = layer.id() > 0 && surface.is_bridge();
params.extruder = layerm.region()->extruder(extrusion_role);
params.pattern = layerm.region()->config().fill_pattern.value;
@ -132,7 +132,7 @@ std::vector<SurfaceFill> group_fills(const Layer &layer)
is_bridge ?
erBridgeInfill :
(surface.is_solid() ?
((surface.surface_type == stTop) ? erTopSolidInfill : erSolidInfill) :
(surface.is_top() ? erTopSolidInfill : erSolidInfill) :
erInternalInfill);
params.bridge_angle = float(surface.bridge_angle);
params.angle = float(Geometry::deg2rad(layerm.region()->config().fill_angle.value));

View file

@ -611,7 +611,7 @@ static inline SegmentPoint clip_start_segment_and_point(const Points &polyline,
SegmentPoint out;
if (polyline.size() >= 2) {
Vec2d pt_prev = polyline.front().cast<double>();
for (int i = 1; i < polyline.size(); ++ i) {
for (size_t i = 1; i < polyline.size(); ++ i) {
Vec2d pt = polyline[i].cast<double>();
Vec2d v = pt - pt_prev;
double l2 = v.squaredNorm();
@ -674,7 +674,7 @@ static inline double segment_point_distance_squared(const Vec2d &p1a, const Vec2
if (l2 < EPSILON)
// p1a == p1b
return (p2 - p1a).squaredNorm();
return segment_point_distance_squared(p1a, p1b, v, v.squaredNorm(), p2);
return segment_point_distance_squared(p1a, p1b, v, v.squaredNorm(), p2);
}
// Distance to the closest point of line.
@ -692,7 +692,7 @@ static inline double min_distance_of_segments(const Vec2d &p1a, const Vec2d &p1b
// p2a == p2b: Return distance of p2a from the (p1a, p1b) segment.
return segment_point_distance_squared(p1a, p1b, v1, l1_2, p2a);
return std::min(
return std::min(
std::min(segment_point_distance_squared(p1a, p1b, v1, l1_2, p2a), segment_point_distance_squared(p1a, p1b, v1, l1_2, p2b)),
std::min(segment_point_distance_squared(p2a, p2b, v2, l2_2, p1a), segment_point_distance_squared(p2a, p2b, v2, l2_2, p1b)));
}

View file

@ -156,7 +156,7 @@ void FillGyroid::_fill_surface_single(
Polylines &polylines_out)
{
float infill_angle = this->angle + (CorrectionAngle * 2*M_PI) / 360.;
if(abs(infill_angle) >= EPSILON)
if(std::abs(infill_angle) >= EPSILON)
expolygon.rotate(-infill_angle);
BoundingBox bb = expolygon.contour.bounding_box();
@ -197,8 +197,9 @@ void FillGyroid::_fill_surface_single(
append(polylines_out, std::move(polylines));
else
this->connect_infill(std::move(polylines), expolygon, polylines_out, this->spacing, params);
// new paths must be rotated back
if (abs(infill_angle) >= EPSILON) {
if (std::abs(infill_angle) >= EPSILON) {
for (auto it = polylines_out.begin() + polylines_out_first_idx; it != polylines_out.end(); ++ it)
it->rotate(infill_angle);
}

View file

@ -3,9 +3,7 @@
#include "../Utils.hpp"
#include "../GCode.hpp"
#include "../Geometry.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
#include "../GCode/ThumbnailData.hpp"
#endif // ENABLE_THUMBNAIL_GENERATOR
#include "../I18N.hpp"
@ -47,9 +45,7 @@ const std::string MODEL_EXTENSION = ".model";
const std::string MODEL_FILE = "3D/3dmodel.model"; // << this is the only format of the string which works with CURA
const std::string CONTENT_TYPES_FILE = "[Content_Types].xml";
const std::string RELATIONSHIPS_FILE = "_rels/.rels";
#if ENABLE_THUMBNAIL_GENERATOR
const std::string THUMBNAIL_FILE = "Metadata/thumbnail.png";
#endif // ENABLE_THUMBNAIL_GENERATOR
const std::string PRINT_CONFIG_FILE = "Metadata/Slic3r_PE.config";
const std::string MODEL_CONFIG_FILE = "Metadata/Slic3r_PE_model.config";
const std::string LAYER_HEIGHTS_PROFILE_FILE = "Metadata/Slic3r_PE_layer_heights_profile.txt";
@ -1722,7 +1718,7 @@ namespace Slic3r {
}
// Added because of github #3435, currently not used by PrusaSlicer
int instances_count_id = get_attribute_value_int(attributes, num_attributes, INSTANCESCOUNT_ATTR);
// int instances_count_id = get_attribute_value_int(attributes, num_attributes, INSTANCESCOUNT_ATTR);
m_objects_metadata.insert(IdToMetadataMap::value_type(object_id, ObjectMetadata()));
m_curr_config.object_id = object_id;
@ -1969,22 +1965,12 @@ namespace Slic3r {
bool m_fullpath_sources{ true };
public:
#if ENABLE_THUMBNAIL_GENERATOR
bool save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data = nullptr);
#else
bool save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources);
#endif // ENABLE_THUMBNAIL_GENERATOR
private:
#if ENABLE_THUMBNAIL_GENERATOR
bool _save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, const ThumbnailData* thumbnail_data);
#else
bool _save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config);
#endif // ENABLE_THUMBNAIL_GENERATOR
bool _add_content_types_file_to_archive(mz_zip_archive& archive);
#if ENABLE_THUMBNAIL_GENERATOR
bool _add_thumbnail_file_to_archive(mz_zip_archive& archive, const ThumbnailData& thumbnail_data);
#endif // ENABLE_THUMBNAIL_GENERATOR
bool _add_relationships_file_to_archive(mz_zip_archive& archive);
bool _add_model_file_to_archive(mz_zip_archive& archive, const Model& model, IdToObjectDataMap &objects_data);
bool _add_object_to_model_stream(std::stringstream& stream, unsigned int& object_id, ModelObject& object, BuildItemsList& build_items, VolumeToOffsetsMap& volumes_offsets);
@ -1999,26 +1985,14 @@ namespace Slic3r {
bool _add_custom_gcode_per_print_z_file_to_archive(mz_zip_archive& archive, Model& model);
};
#if ENABLE_THUMBNAIL_GENERATOR
bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data)
{
clear_errors();
m_fullpath_sources = fullpath_sources;
return _save_model_to_file(filename, model, config, thumbnail_data);
}
#else
bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources)
{
clear_errors();
return _save_model_to_file(filename, model, config);
}
#endif // ENABLE_THUMBNAIL_GENERATOR
#if ENABLE_THUMBNAIL_GENERATOR
bool _3MF_Exporter::_save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, const ThumbnailData* thumbnail_data)
#else
bool _3MF_Exporter::_save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config)
#endif // ENABLE_THUMBNAIL_GENERATOR
{
mz_zip_archive archive;
mz_zip_zero_struct(&archive);
@ -2037,7 +2011,6 @@ namespace Slic3r {
return false;
}
#if ENABLE_THUMBNAIL_GENERATOR
if ((thumbnail_data != nullptr) && thumbnail_data->is_valid())
{
// Adds the file Metadata/thumbnail.png.
@ -2048,7 +2021,6 @@ namespace Slic3r {
return false;
}
}
#endif // ENABLE_THUMBNAIL_GENERATOR
// Adds relationships file ("_rels/.rels").
// The content of this file is the same for each PrusaSlicer 3mf.
@ -2160,9 +2132,7 @@ namespace Slic3r {
stream << "<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">\n";
stream << " <Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\" />\n";
stream << " <Default Extension=\"model\" ContentType=\"application/vnd.ms-package.3dmanufacturing-3dmodel+xml\" />\n";
#if ENABLE_THUMBNAIL_GENERATOR
stream << " <Default Extension=\"png\" ContentType=\"image/png\" />\n";
#endif // ENABLE_THUMBNAIL_GENERATOR
stream << "</Types>";
std::string out = stream.str();
@ -2176,7 +2146,6 @@ namespace Slic3r {
return true;
}
#if ENABLE_THUMBNAIL_GENERATOR
bool _3MF_Exporter::_add_thumbnail_file_to_archive(mz_zip_archive& archive, const ThumbnailData& thumbnail_data)
{
bool res = false;
@ -2194,7 +2163,6 @@ namespace Slic3r {
return res;
}
#endif // ENABLE_THUMBNAIL_GENERATOR
bool _3MF_Exporter::_add_relationships_file_to_archive(mz_zip_archive& archive)
{
@ -2202,9 +2170,7 @@ namespace Slic3r {
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
stream << "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\n";
stream << " <Relationship Target=\"/" << MODEL_FILE << "\" Id=\"rel-1\" Type=\"http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel\" />\n";
#if ENABLE_THUMBNAIL_GENERATOR
stream << " <Relationship Target=\"/" << THUMBNAIL_FILE << "\" Id=\"rel-2\" Type=\"http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail\" />\n";
#endif // ENABLE_THUMBNAIL_GENERATOR
stream << "</Relationships>";
std::string out = stream.str();
@ -2795,22 +2761,13 @@ bool load_3mf(const char* path, DynamicPrintConfig* config, Model* model, bool c
return res;
}
#if ENABLE_THUMBNAIL_GENERATOR
bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data)
#else
bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources)
#endif // ENABLE_THUMBNAIL_GENERATOR
{
if ((path == nullptr) || (model == nullptr))
return false;
_3MF_Exporter exporter;
#if ENABLE_THUMBNAIL_GENERATOR
bool res = exporter.save_model_to_file(path, *model, config, fullpath_sources, thumbnail_data);
#else
bool res = exporter.save_model_to_file(path, *model, config, fullpath_sources);
#endif // ENABLE_THUMBNAIL_GENERATOR
if (!res)
exporter.log_errors();

View file

@ -26,20 +26,14 @@ namespace Slic3r {
class Model;
class DynamicPrintConfig;
#if ENABLE_THUMBNAIL_GENERATOR
struct ThumbnailData;
#endif // ENABLE_THUMBNAIL_GENERATOR
// Load the content of a 3mf file into the given model and preset bundle.
extern bool load_3mf(const char* path, DynamicPrintConfig* config, Model* model, bool check_version);
// Save the given model and the config data contained in the given Print into a 3mf file.
// The model could be modified during the export process if meshes are not repaired or have no shared vertices
#if ENABLE_THUMBNAIL_GENERATOR
extern bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data = nullptr);
#else
extern bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources);
#endif // ENABLE_THUMBNAIL_GENERATOR
}; // namespace Slic3r

View file

@ -20,9 +20,7 @@
#include <boost/foreach.hpp>
#include <boost/filesystem.hpp>
#include <boost/log/trivial.hpp>
#if ENABLE_THUMBNAIL_GENERATOR
#include <boost/beast/core/detail/base64.hpp>
#endif // ENABLE_THUMBNAIL_GENERATOR
#include <boost/nowide/iostream.hpp>
#include <boost/nowide/cstdio.hpp>
@ -291,7 +289,7 @@ std::string WipeTowerIntegration::append_tcr(GCode &gcodegen, const WipeTower::T
std::string gcode;
// Toolchangeresult.gcode assumes the wipe tower corner is at the origin
// Toolchangeresult.gcode assumes the wipe tower corner is at the origin (except for priming lines)
// We want to rotate and shift all extrusions (gcode postprocessing) and starting and ending position
float alpha = m_wipe_tower_rotation/180.f * float(M_PI);
Vec2f start_pos = tcr.start_pos;
@ -431,7 +429,6 @@ std::string WipeTowerIntegration::post_process_wipe_tower_moves(const WipeTower:
Vec2f pos = tcr.start_pos;
Vec2f transformed_pos = pos;
Vec2f old_pos(-1000.1f, -1000.1f);
std::string never_skip_tag = WipeTower::never_skip_tag();
while (gcode_str) {
std::getline(gcode_str, line); // we read the gcode line by line
@ -441,11 +438,11 @@ std::string WipeTowerIntegration::post_process_wipe_tower_moves(const WipeTower:
// WT generator can override this by appending the never_skip_tag
if (line.find("G1 ") == 0) {
bool never_skip = false;
auto it = line.find(never_skip_tag);
auto it = line.find(WipeTower::never_skip_tag());
if (it != std::string::npos) {
// remove the tag and remember we saw it
never_skip = true;
line.erase(it, it+never_skip_tag.size());
line.erase(it, it+WipeTower::never_skip_tag().size());
}
std::ostringstream line_out;
std::istringstream line_str(line);
@ -632,13 +629,16 @@ std::vector<GCode::LayerToPrint> GCode::collect_layers_to_print(const PrintObjec
// Negative support_contact_z is not taken into account, it can result in false positives in cases
// where previous layer has object extrusions too (https://github.com/prusa3d/PrusaSlicer/issues/2752)
// Only check this layer in case it has some extrusions.
bool has_extrusions = (layer_to_print.object_layer && layer_to_print.object_layer->has_extrusions())
|| (layer_to_print.support_layer && layer_to_print.support_layer->has_extrusions());
if (layer_to_print.print_z() > maximal_print_z + 2. * EPSILON)
if (has_extrusions && layer_to_print.print_z() > maximal_print_z + 2. * EPSILON)
throw std::runtime_error(_(L("Empty layers detected, the output would not be printable.")) + "\n\n" +
_(L("Object name")) + ": " + object.model_object()->name + "\n" + _(L("Print z")) + ": " +
std::to_string(layers_to_print.back().print_z()) + "\n\n" + _(L("This is "
"usually caused by negligibly small extrusions or by a faulty model. Try to repair "
" the model or change its orientation on the bed.")));
"the model or change its orientation on the bed.")));
// Remember last layer with extrusions.
last_extrusion_layer = &layers_to_print.back();
}
@ -698,11 +698,7 @@ std::vector<std::pair<coordf_t, std::vector<GCode::LayerToPrint>>> GCode::collec
return layers_to_print;
}
#if ENABLE_THUMBNAIL_GENERATOR
void GCode::do_export(Print* print, const char* path, GCodePreviewData* preview_data, ThumbnailsGeneratorCallback thumbnail_cb)
#else
void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_data)
#endif // ENABLE_THUMBNAIL_GENERATOR
{
PROFILE_CLEAR();
@ -728,11 +724,7 @@ void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_
try {
m_placeholder_parser_failed_templates.clear();
#if ENABLE_THUMBNAIL_GENERATOR
this->_do_export(*print, file, thumbnail_cb);
#else
this->_do_export(*print, file);
#endif // ENABLE_THUMBNAIL_GENERATOR
fflush(file);
if (ferror(file)) {
fclose(file);
@ -972,7 +964,6 @@ namespace DoExport {
}
}
#if ENABLE_THUMBNAIL_GENERATOR
template<typename WriteToOutput, typename ThrowIfCanceledCallback>
static void export_thumbnails_to_file(ThumbnailsGeneratorCallback &thumbnail_cb, const std::vector<Vec2d> &sizes, WriteToOutput output, ThrowIfCanceledCallback throw_if_canceled)
{
@ -1016,7 +1007,6 @@ namespace DoExport {
}
}
}
#endif // ENABLE_THUMBNAIL_GENERATOR
// Fill in print_statistics and return formatted string containing filament statistics to be inserted into G-code comment section.
static std::string update_print_stats_and_format_filament_stats(
@ -1122,11 +1112,7 @@ std::vector<const PrintInstance*> sort_object_instances_by_model_order(const Pri
return instances;
}
#if ENABLE_THUMBNAIL_GENERATOR
void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thumbnail_cb)
#else
void GCode::_do_export(Print& print, FILE* file)
#endif // ENABLE_THUMBNAIL_GENERATOR
{
PROFILE_FUNC();
@ -1749,7 +1735,6 @@ std::vector<GCode::InstanceToPrint> GCode::sort_print_object_instances(
std::sort(sorted.begin(), sorted.end());
if (! sorted.empty()) {
const Print &print = *sorted.front().first->print();
out.reserve(sorted.size());
for (const PrintInstance *instance : *ordering) {
const PrintObject &print_object = *instance->print_object;
@ -1795,13 +1780,14 @@ namespace ProcessLayer
// we should add or not colorprint_change in respect to nozzle_diameter count instead of really used extruders count
if (color_change || tool_change)
{
assert(m600_extruder_before_layer >= 0);
// Color Change or Tool Change as Color Change.
// add tag for analyzer
gcode += "; " + GCodeAnalyzer::Color_Change_Tag + ",T" + std::to_string(m600_extruder_before_layer) + "\n";
// add tag for time estimator
gcode += "; " + GCodeTimeEstimator::Color_Change_Tag + "\n";
if (!single_extruder_printer && m600_extruder_before_layer >= 0 && first_extruder_id != m600_extruder_before_layer
if (!single_extruder_printer && m600_extruder_before_layer >= 0 && first_extruder_id != (unsigned)m600_extruder_before_layer
// && !MMU1
) {
//! FIXME_in_fw show message during print pause
@ -2877,11 +2863,12 @@ std::string GCode::extrude_path(ExtrusionPath path, std::string description, dou
std::string GCode::extrude_perimeters(const Print &print, const std::vector<ObjectByExtruder::Island::Region> &by_region, std::unique_ptr<EdgeGrid::Grid> &lower_layer_edge_grid)
{
std::string gcode;
for (const ObjectByExtruder::Island::Region &region : by_region) {
m_config.apply(print.regions()[&region - &by_region.front()]->config());
for (const ExtrusionEntity *ee : region.perimeters)
gcode += this->extrude_entity(*ee, "perimeter", -1., &lower_layer_edge_grid);
}
for (const ObjectByExtruder::Island::Region &region : by_region)
if (! region.perimeters.empty()) {
m_config.apply(print.regions()[&region - &by_region.front()]->config());
for (const ExtrusionEntity *ee : region.perimeters)
gcode += this->extrude_entity(*ee, "perimeter", -1., &lower_layer_edge_grid);
}
return gcode;
}
@ -2889,19 +2876,20 @@ std::string GCode::extrude_perimeters(const Print &print, const std::vector<Obje
std::string GCode::extrude_infill(const Print &print, const std::vector<ObjectByExtruder::Island::Region> &by_region)
{
std::string gcode;
for (const ObjectByExtruder::Island::Region &region : by_region) {
m_config.apply(print.regions()[&region - &by_region.front()]->config());
ExtrusionEntitiesPtr extrusions { region.infills };
chain_and_reorder_extrusion_entities(extrusions, &m_last_pos);
for (const ExtrusionEntity *fill : extrusions) {
auto *eec = dynamic_cast<const ExtrusionEntityCollection*>(fill);
if (eec) {
for (ExtrusionEntity *ee : eec->chained_path_from(m_last_pos).entities)
gcode += this->extrude_entity(*ee, "infill");
} else
gcode += this->extrude_entity(*fill, "infill");
for (const ObjectByExtruder::Island::Region &region : by_region)
if (! region.infills.empty()) {
m_config.apply(print.regions()[&region - &by_region.front()]->config());
ExtrusionEntitiesPtr extrusions { region.infills };
chain_and_reorder_extrusion_entities(extrusions, &m_last_pos);
for (const ExtrusionEntity *fill : extrusions) {
auto *eec = dynamic_cast<const ExtrusionEntityCollection*>(fill);
if (eec) {
for (ExtrusionEntity *ee : eec->chained_path_from(m_last_pos).entities)
gcode += this->extrude_entity(*ee, "infill");
} else
gcode += this->extrude_entity(*fill, "infill");
}
}
}
return gcode;
}
@ -3367,17 +3355,18 @@ const std::vector<GCode::ObjectByExtruder::Island::Region>& GCode::ObjectByExtru
has_overrides = true;
break;
}
// Data is cleared, but the memory is not.
by_region_per_copy_cache.clear();
if (! has_overrides)
// Simple case. No need to copy the regions.
return this->by_region;
return wiping_entities ? by_region_per_copy_cache : this->by_region;
// Complex case. Some of the extrusions of some object instances are to be printed first - those are the wiping extrusions.
// Some of the extrusions of some object instances are printed later - those are the clean print extrusions.
// Filter out the extrusions based on the infill_overrides / perimeter_overrides:
// Data is cleared, but the memory is not.
by_region_per_copy_cache.clear();
for (const auto& reg : by_region) {
by_region_per_copy_cache.emplace_back(); // creates a region in the newly created Island
@ -3438,15 +3427,17 @@ void GCode::ObjectByExtruder::Island::Region::append(const Type type, const Extr
// First we append the entities, there are eec->entities.size() of them:
size_t old_size = perimeters_or_infills->size();
perimeters_or_infills->reserve(perimeters_or_infills->size() + eec->entities.size());
size_t new_size = old_size + eec->entities.size();
perimeters_or_infills->reserve(new_size);
for (auto* ee : eec->entities)
perimeters_or_infills->emplace_back(ee);
if (copies_extruder != nullptr) {
perimeters_or_infills_overrides->reserve(old_size + eec->entities.size());
perimeters_or_infills_overrides->resize(old_size, nullptr);
for (unsigned int i = 0; i < eec->entities.size(); ++ i)
perimeters_or_infills_overrides->emplace_back(copies_extruder);
// Don't reallocate overrides if not needed.
// Missing overrides are implicitely considered non-overridden.
perimeters_or_infills_overrides->reserve(new_size);
perimeters_or_infills_overrides->resize(old_size, nullptr);
perimeters_or_infills_overrides->resize(new_size, copies_extruder);
}
}

View file

@ -17,9 +17,7 @@
#include "GCodeTimeEstimator.hpp"
#include "EdgeGrid.hpp"
#include "GCode/Analyzer.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
#include "GCode/ThumbnailData.hpp"
#endif // ENABLE_THUMBNAIL_GENERATOR
#include <memory>
#include <string>
@ -166,11 +164,7 @@ public:
// throws std::runtime_exception on error,
// throws CanceledException through print->throw_if_canceled().
#if ENABLE_THUMBNAIL_GENERATOR
void do_export(Print* print, const char* path, GCodePreviewData* preview_data = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr);
#else
void do_export(Print *print, const char *path, GCodePreviewData *preview_data = nullptr);
#endif // ENABLE_THUMBNAIL_GENERATOR
// Exported for the helper classes (OozePrevention, Wipe) and for the Perl binding for unit tests.
const Vec2d& origin() const { return m_origin; }
@ -210,11 +204,7 @@ public:
};
private:
#if ENABLE_THUMBNAIL_GENERATOR
void _do_export(Print &print, FILE *file, ThumbnailsGeneratorCallback thumbnail_cb);
#else
void _do_export(Print &print, FILE *file);
#endif //ENABLE_THUMBNAIL_GENERATOR
static std::vector<LayerToPrint> collect_layers_to_print(const PrintObject &object);
static std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> collect_layers_to_print(const Print &print);

View file

@ -444,8 +444,10 @@ void GCodeAnalyzer::_processG92(const GCodeReader::GCodeLine& line)
anyFound = true;
}
if (!anyFound)
if (!anyFound && ! line.has_unknown_axis())
{
// The G92 may be called for axes that PrusaSlicer does not recognize, for example see GH issue #3510,
// where G92 A0 B0 is called although the extruder axis is till E.
for (unsigned char a = X; a < Num_Axis; ++a)
{
_set_axis_origin((EAxis)a, _get_axis_position((EAxis)a));
@ -470,7 +472,7 @@ void GCodeAnalyzer::_processM106(const GCodeReader::GCodeLine& line)
// The absence of P means the print cooling fan, so ignore anything else.
float new_fan_speed;
if (line.has_value('S', new_fan_speed))
_set_fan_speed((100.0f / 256.0f) * new_fan_speed);
_set_fan_speed((100.0f / 255.0f) * new_fan_speed);
else
_set_fan_speed(100.0f);
}
@ -644,7 +646,7 @@ bool GCodeAnalyzer::_process_tags(const GCodeReader::GCodeLine& line)
if (pos != comment.npos)
{
pos = comment.find_last_of(",T");
int extruder = pos == comment.npos ? 0 : std::atoi(comment.substr(pos + 1, comment.npos).c_str());
unsigned extruder = pos == comment.npos ? 0 : std::stoi(comment.substr(pos + 1, comment.npos));
_process_color_change_tag(extruder);
return true;
}
@ -702,7 +704,7 @@ void GCodeAnalyzer::_process_height_tag(const std::string& comment, size_t pos)
_set_height((float)::strtod(comment.substr(pos + Height_Tag.length()).c_str(), nullptr));
}
void GCodeAnalyzer::_process_color_change_tag(int extruder)
void GCodeAnalyzer::_process_color_change_tag(unsigned extruder)
{
m_extruder_color[extruder] = m_extruders_count + m_state.cp_color_counter; // color_change position in list of color for preview
m_state.cp_color_counter++;

View file

@ -220,7 +220,7 @@ private:
void _process_height_tag(const std::string& comment, size_t pos);
// Processes color change tag
void _process_color_change_tag(int extruder);
void _process_color_change_tag(unsigned extruder);
// Processes pause print and custom gcode tag
void _process_pause_print_or_custom_code_tag();

View file

@ -72,7 +72,7 @@ Color GCodePreviewData::RangeBase::get_color_at(float value) const
{
// Input value scaled to the color range
float step = step_size();
const float global_t = (step != 0.0f) ? std::max(0.0f, value - min()) / step_size() : 0.0f; // lower limit of 0.0f
const float global_t = (step != 0.0f) ? std::max(0.0f, value - min()) / step : 0.0f; // lower limit of 0.0f
constexpr std::size_t color_max_idx = range_rainbow_colors.size() - 1;
@ -241,6 +241,7 @@ void GCodePreviewData::reset()
ranges.width.reset();
ranges.height.reset();
ranges.feedrate.reset();
ranges.fan_speed.reset();
ranges.volumetric_rate.reset();
extrusion.layers.clear();
travel.polylines.clear();

View file

@ -1,8 +1,6 @@
#include "libslic3r/libslic3r.h"
#include "ThumbnailData.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
namespace Slic3r {
void ThumbnailData::set(unsigned int w, unsigned int h)
@ -32,5 +30,3 @@ bool ThumbnailData::is_valid() const
}
} // namespace Slic3r
#endif // ENABLE_THUMBNAIL_GENERATOR

View file

@ -1,8 +1,6 @@
#ifndef slic3r_ThumbnailData_hpp_
#define slic3r_ThumbnailData_hpp_
#if ENABLE_THUMBNAIL_GENERATOR
#include <vector>
#include "libslic3r/Point.hpp"
@ -26,6 +24,4 @@ typedef std::function<void(ThumbnailsList & thumbnails, const Vec2ds & sizes, bo
} // namespace Slic3r
#endif // ENABLE_THUMBNAIL_GENERATOR
#endif // slic3r_ThumbnailData_hpp_

View file

@ -94,7 +94,7 @@ ToolOrdering::ToolOrdering(const PrintObject &object, unsigned int first_extrude
// Reorder the extruders to minimize tool switches.
this->reorder_extruders(first_extruder);
this->fill_wipe_tower_partitions(object.print()->config(), object.layers().front()->print_z - object.layers().front()->height);
this->fill_wipe_tower_partitions(object.print()->config(), object.layers().front()->print_z - object.layers().front()->height, object.config().layer_height);
this->collect_extruder_statistics(prime_multi_material);
}
@ -107,6 +107,7 @@ ToolOrdering::ToolOrdering(const Print &print, unsigned int first_extruder, bool
// Initialize the print layers for all objects and all layers.
coordf_t object_bottom_z = 0.;
coordf_t max_layer_height = 0.;
{
std::vector<coordf_t> zs;
for (auto object : print.objects()) {
@ -122,6 +123,8 @@ ToolOrdering::ToolOrdering(const Print &print, unsigned int first_extruder, bool
object_bottom_z = layer->print_z - layer->height;
break;
}
max_layer_height = std::max(max_layer_height, object->config().layer_height.value);
}
this->initialize_layers(zs);
}
@ -144,7 +147,7 @@ ToolOrdering::ToolOrdering(const Print &print, unsigned int first_extruder, bool
// Reorder the extruders to minimize tool switches.
this->reorder_extruders(first_extruder);
this->fill_wipe_tower_partitions(print.config(), object_bottom_z);
this->fill_wipe_tower_partitions(print.config(), object_bottom_z, max_layer_height);
this->collect_extruder_statistics(prime_multi_material);
}
@ -212,10 +215,8 @@ void ToolOrdering::collect_extruders(const PrintObject &object, const std::vecto
if (m_print_config_ptr) { // in this case complete_objects is false (see ToolOrdering constructors)
something_nonoverriddable = false;
for (const auto& eec : layerm->perimeters.entities) // let's check if there are nonoverriddable entities
if (!layer_tools.wiping_extrusions().is_overriddable_and_mark(dynamic_cast<const ExtrusionEntityCollection&>(*eec), *m_print_config_ptr, object, region)) {
if (!layer_tools.wiping_extrusions().is_overriddable_and_mark(dynamic_cast<const ExtrusionEntityCollection&>(*eec), *m_print_config_ptr, object, region))
something_nonoverriddable = true;
break;
}
}
if (something_nonoverriddable)
@ -237,7 +238,7 @@ void ToolOrdering::collect_extruders(const PrintObject &object, const std::vecto
has_infill = true;
if (m_print_config_ptr) {
if (!something_nonoverriddable && !layer_tools.wiping_extrusions().is_overriddable_and_mark(*fill, *m_print_config_ptr, object, region))
if (! layer_tools.wiping_extrusions().is_overriddable_and_mark(*fill, *m_print_config_ptr, object, region))
something_nonoverriddable = true;
}
}
@ -320,7 +321,7 @@ void ToolOrdering::reorder_extruders(unsigned int last_extruder_id)
}
}
void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z)
void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z, coordf_t max_object_layer_height)
{
if (m_layer_tools.empty())
return;
@ -353,6 +354,10 @@ void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_
mlh = 0.75 * config.nozzle_diameter.values[i];
max_layer_height = std::min(max_layer_height, mlh);
}
// The Prusa3D Fast (0.35mm layer height) print profile sets a higher layer height than what is normally allowed
// by the nozzle. This is a hack and it works by increasing extrusion width.
max_layer_height = std::max(max_layer_height, max_object_layer_height);
for (size_t i = 0; i + 1 < m_layer_tools.size(); ++ i) {
const LayerTools &lt = m_layer_tools[i];
const LayerTools &lt_next = m_layer_tools[i + 1];
@ -395,21 +400,47 @@ void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_
// and maybe other problems. We will therefore go through layer_tools and detect and fix this.
// So, if there is a non-object layer starting with different extruder than the last one ended with (or containing more than one extruder),
// we'll mark it with has_wipe tower.
for (unsigned int i=0; i+1<m_layer_tools.size(); ++i) {
LayerTools& lt = m_layer_tools[i];
LayerTools& lt_next = m_layer_tools[i+1];
if (lt.extruders.empty() || lt_next.extruders.empty())
break;
if (!lt_next.has_wipe_tower && (lt_next.extruders.front() != lt.extruders.back() || lt_next.extruders.size() > 1))
lt_next.has_wipe_tower = true;
// We should also check that the next wipe tower layer is no further than max_layer_height:
unsigned int j = i+1;
double last_wipe_tower_print_z = lt_next.print_z;
while (++j < m_layer_tools.size()-1 && !m_layer_tools[j].has_wipe_tower)
if (m_layer_tools[j+1].print_z - last_wipe_tower_print_z > max_layer_height) {
m_layer_tools[j].has_wipe_tower = true;
last_wipe_tower_print_z = m_layer_tools[j].print_z;
assert(! m_layer_tools.empty() && m_layer_tools.front().has_wipe_tower);
if (! m_layer_tools.empty() && m_layer_tools.front().has_wipe_tower) {
for (size_t i = 0; i + 1 < m_layer_tools.size();) {
const LayerTools &lt = m_layer_tools[i];
assert(lt.has_wipe_tower);
assert(! lt.extruders.empty());
// Find the next layer with wipe tower or mark a layer as such.
size_t j = i + 1;
for (; j < m_layer_tools.size() && ! m_layer_tools[j].has_wipe_tower; ++ j) {
LayerTools &lt_next = m_layer_tools[j];
if (lt_next.extruders.empty()) {
//FIXME Vojtech: Lukasi, proc?
j = m_layer_tools.size();
break;
}
if (lt_next.extruders.front() != lt.extruders.back() || lt_next.extruders.size() > 1) {
// Support only layer, soluble layers? Otherwise the layer should have been already marked as having wipe tower.
assert(lt_next.has_support && ! lt_next.has_object);
lt_next.has_wipe_tower = true;
break;
}
}
if (j == m_layer_tools.size())
// No wipe tower above layer i, therefore no need to add any wipe tower layer above i.
break;
// We should also check that the next wipe tower layer is no further than max_layer_height.
// This algorith may in theory create very thin wipe layer j if layer closely below j is marked as wipe tower.
// This may happen if printing with non-soluble break away supports.
// On the other side it should not hurt as there will be no wipe, just perimeter and sparse infill printed
// at that particular wipe tower layer without extruder change.
double last_wipe_tower_print_z = lt.print_z;
assert(m_layer_tools[j].has_wipe_tower);
for (size_t k = i + 1; k < j; ++k) {
assert(! m_layer_tools[k].has_wipe_tower);
if (m_layer_tools[k + 1].print_z - last_wipe_tower_print_z > max_layer_height + EPSILON) {
m_layer_tools[k].has_wipe_tower = true;
last_wipe_tower_print_z = m_layer_tools[k].print_z;
}
}
i = j;
}
}
// Calculate the wipe_tower_layer_height values.

View file

@ -30,14 +30,6 @@ public:
// When allocating extruder overrides of an object's ExtrusionEntity, overrides for maximum 3 copies are allocated in place.
typedef boost::container::small_vector<int32_t, 3> ExtruderPerCopy;
class ExtruderOverrides
{
public:
ExtruderOverrides(const ExtruderPerCopy *overrides, const int correct_extruder_id) : m_overrides(overrides) {}
private:
const ExtruderPerCopy *m_overrides;
};
// This is called from GCode::process_layer - see implementation for further comments:
const ExtruderPerCopy* get_extruder_overrides(const ExtrusionEntity* entity, int correct_extruder_id, size_t num_of_copies);
@ -72,7 +64,7 @@ private:
std::map<const ExtrusionEntity*, ExtruderPerCopy> entity_map; // to keep track of who prints what
bool something_overridable = false;
bool something_overridden = false;
const LayerTools* m_layer_tools; // so we know which LayerTools object this belongs to
const LayerTools* m_layer_tools = nullptr; // so we know which LayerTools object this belongs to
};
@ -174,7 +166,7 @@ private:
void initialize_layers(std::vector<coordf_t> &zs);
void collect_extruders(const PrintObject &object, const std::vector<std::pair<double, unsigned int>> &per_layer_extruder_switches);
void reorder_extruders(unsigned int last_extruder_id);
void fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z);
void fill_wipe_tower_partitions(const PrintConfig &config, coordf_t object_bottom_z, coordf_t max_layer_height);
void collect_extruder_statistics(bool prime_multi_material);
std::vector<LayerTools> m_layer_tools;

View file

@ -492,6 +492,9 @@ WipeTower::WipeTower(const PrintConfig& config, const std::vector<std::vector<fl
const std::vector<Vec2d>& bed_points = config.bed_shape.values;
m_bed_shape = (bed_points.size() == 4 ? RectangularBed : CircularBed);
m_bed_width = float(BoundingBoxf(bed_points).size().x());
m_bed_bottom_left = m_bed_shape == RectangularBed
? Vec2f(bed_points.front().x(), bed_points.front().y())
: Vec2f::Zero();
}
@ -566,6 +569,8 @@ std::vector<WipeTower::ToolChangeResult> WipeTower::prime(
// In case of a circular bed, place it so it goes across the diameter and hope it will fit
if (m_bed_shape == CircularBed)
cleaning_box.translate(-m_bed_width/2 + m_bed_width * 0.03f, -m_bed_width * 0.12f);
if (m_bed_shape == RectangularBed)
cleaning_box.translate(m_bed_bottom_left);
std::vector<ToolChangeResult> results;

View file

@ -21,7 +21,7 @@ enum GCodeFlavor : unsigned char;
class WipeTower
{
public:
static char const* never_skip_tag() { return "_GCODE_WIPE_TOWER_NEVER_SKIP_TAG"; }
static const std::string never_skip_tag() { return "_GCODE_WIPE_TOWER_NEVER_SKIP_TAG"; }
struct Extrusion
{
@ -189,8 +189,6 @@ public:
};
private:
WipeTower();
enum wipe_shape // A fill-in direction
{
SHAPE_NORMAL = 1,
@ -236,6 +234,7 @@ private:
CircularBed
} m_bed_shape;
float m_bed_width; // width of the bed bounding box
Vec2f m_bed_bottom_left; // bottom-left corner coordinates (for rectangular beds)
float m_perimeter_width = 0.4f * Width_To_Nozzle_Ratio; // Width of an extrusion line, also a perimeter spacing for 100% infill.
float m_extrusion_flow = 0.038f; //0.029f;// Extrusion flow is derived from m_perimeter_width, layer height and filament diameter.

View file

@ -40,7 +40,7 @@ const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline,
if (is_end_of_gcode_line(*c))
break;
// Check the name of the axis.
Axis axis = NUM_AXES;
Axis axis = NUM_AXES_WITH_UNKNOWN;
switch (*c) {
case 'X': axis = X; break;
case 'Y': axis = Y; break;
@ -49,15 +49,19 @@ const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline,
default:
if (*c == m_extrusion_axis)
axis = E;
else if (*c >= 'A' && *c <= 'Z')
// Unknown axis, but we still want to remember that such a axis was seen.
axis = UNKNOWN_AXIS;
break;
}
if (axis != NUM_AXES) {
if (axis != NUM_AXES_WITH_UNKNOWN) {
// Try to parse the numeric value.
char *pend = nullptr;
double v = strtod(++ c, &pend);
if (pend != nullptr && is_end_of_word(*pend)) {
// The axis value has been parsed correctly.
gline.m_axis[int(axis)] = float(v);
if (axis != UNKNOWN_AXIS)
gline.m_axis[int(axis)] = float(v);
gline.m_mask |= 1 << int(axis);
c = pend;
} else

View file

@ -58,6 +58,7 @@ public:
bool has_z() const { return this->has(Z); }
bool has_e() const { return this->has(E); }
bool has_f() const { return this->has(F); }
bool has_unknown_axis() const { return this->has(UNKNOWN_AXIS); }
float x() const { return m_axis[X]; }
float y() const { return m_axis[Y]; }
float z() const { return m_axis[Z]; }

View file

@ -184,11 +184,8 @@ namespace Slic3r {
{
PROFILE_FUNC();
if (start_from_beginning)
{
_reset_time();
m_last_st_synchronized_block_id = -1;
}
_calculate_time();
_calculate_time(0);
if (m_needs_custom_gcode_times && (m_custom_gcode_time_cache != 0.0f))
m_custom_gcode_times.push_back({ cgtColorChange, m_custom_gcode_time_cache });
@ -198,6 +195,7 @@ namespace Slic3r {
#endif // ENABLE_MOVE_STATS
}
#if 0
void GCodeTimeEstimator::calculate_time_from_text(const std::string& gcode)
{
reset();
@ -206,7 +204,7 @@ namespace Slic3r {
[this](GCodeReader &reader, const GCodeReader::GCodeLine &line)
{ this->_process_gcode_line(reader, line); });
_calculate_time();
_calculate_time(0);
if (m_needs_custom_gcode_times && (m_custom_gcode_time_cache != 0.0f))
m_custom_gcode_times.push_back({ cgtColorChange, m_custom_gcode_time_cache });
@ -221,7 +219,7 @@ namespace Slic3r {
reset();
m_parser.parse_file(file, boost::bind(&GCodeTimeEstimator::_process_gcode_line, this, _1, _2));
_calculate_time();
_calculate_time(0);
if (m_needs_custom_gcode_times && (m_custom_gcode_time_cache != 0.0f))
m_custom_gcode_times.push_back({ cgtColorChange, m_custom_gcode_time_cache });
@ -239,7 +237,7 @@ namespace Slic3r {
{ this->_process_gcode_line(reader, line); };
for (const std::string& line : gcode_lines)
m_parser.parse_line(line, action);
_calculate_time();
_calculate_time(0);
if (m_needs_custom_gcode_times && (m_custom_gcode_time_cache != 0.0f))
m_custom_gcode_times.push_back({ cgtColorChange, m_custom_gcode_time_cache});
@ -248,6 +246,7 @@ namespace Slic3r {
_log_moves_stats();
#endif // ENABLE_MOVE_STATS
}
#endif
bool GCodeTimeEstimator::post_process(const std::string& filename, float interval_sec, const PostProcessData* const normal_mode, const PostProcessData* const silent_mode)
{
@ -294,25 +293,25 @@ namespace Slic3r {
if (data == nullptr)
return;
assert((g1_line_id >= (int)data->g1_line_ids.size()) || (data->g1_line_ids[g1_line_id].first >= g1_lines_count));
const Block* block = nullptr;
if (g1_line_id < (int)data->g1_line_ids.size())
assert((g1_line_id >= (int)data->g1_times.size()) || (data->g1_times[g1_line_id].first >= (int)g1_lines_count));
float elapsed_time = -1.0f;
if (g1_line_id < (int)data->g1_times.size())
{
const G1LineIdToBlockId& map_item = data->g1_line_ids[g1_line_id];
const G1LineIdTime& map_item = data->g1_times[g1_line_id];
if (map_item.first == g1_lines_count)
{
if (line.has_e() && (map_item.second < (unsigned int)data->blocks.size()))
block = &data->blocks[map_item.second];
if (line.has_e())
elapsed_time = map_item.second;
++g1_line_id;
}
}
if ((block != nullptr) && (block->elapsed_time != -1.0f))
if (elapsed_time != -1.0f)
{
float block_remaining_time = data->time - block->elapsed_time;
float block_remaining_time = data->time - elapsed_time;
if (std::abs(last_recorded_time - block_remaining_time) > interval_sec)
{
sprintf(line_M73, time_mask.c_str(), std::to_string((int)(100.0f * block->elapsed_time / data->time)).c_str(), _get_time_minutes(block_remaining_time).c_str());
sprintf(line_M73, time_mask.c_str(), std::to_string((int)(100.0f * elapsed_time / data->time)).c_str(), _get_time_minutes(block_remaining_time).c_str());
gcode_line += line_M73;
last_recorded_time = block_remaining_time;
@ -620,22 +619,6 @@ namespace Slic3r {
m_state.extruder_id = m_state.extruder_id_unloaded;
}
void GCodeTimeEstimator::add_additional_time(float timeSec)
{
PROFILE_FUNC();
m_state.additional_time += timeSec;
}
void GCodeTimeEstimator::set_additional_time(float timeSec)
{
m_state.additional_time = timeSec;
}
float GCodeTimeEstimator::get_additional_time() const
{
return m_state.additional_time;
}
void GCodeTimeEstimator::set_default()
{
set_units(Millimeters);
@ -765,7 +748,7 @@ namespace Slic3r {
{
size_t out = sizeof(*this);
out += SLIC3R_STDVEC_MEMSIZE(this->m_blocks, Block);
out += SLIC3R_STDVEC_MEMSIZE(this->m_g1_line_ids, G1LineIdToBlockId);
out += SLIC3R_STDVEC_MEMSIZE(this->m_g1_times, G1LineIdTime);
return out;
}
@ -784,13 +767,9 @@ namespace Slic3r {
if (get_e_local_positioning_type() == Absolute)
set_axis_position(E, 0.0f);
set_additional_time(0.0f);
reset_extruder_id();
reset_g1_line_id();
m_g1_line_ids.clear();
m_last_st_synchronized_block_id = -1;
m_g1_times.clear();
m_needs_custom_gcode_times = false;
m_custom_gcode_times.clear();
@ -807,18 +786,19 @@ namespace Slic3r {
m_blocks.clear();
}
void GCodeTimeEstimator::_calculate_time()
void GCodeTimeEstimator::_calculate_time(size_t keep_last_n_blocks)
{
PROFILE_FUNC();
assert(keep_last_n_blocks <= m_blocks.size());
_forward_pass();
_reverse_pass();
_recalculate_trapezoids();
m_time += get_additional_time();
m_custom_gcode_time_cache += get_additional_time();
for (int i = m_last_st_synchronized_block_id + 1; i < (int)m_blocks.size(); ++i)
size_t n_blocks_process = m_blocks.size() - keep_last_n_blocks;
m_g1_times.reserve(m_g1_times.size() + n_blocks_process);
for (size_t i = 0; i < n_blocks_process; ++ i)
{
Block& block = m_blocks[i];
float block_time = 0.0f;
@ -826,7 +806,8 @@ namespace Slic3r {
block_time += block.cruise_time();
block_time += block.deceleration_time();
m_time += block_time;
block.elapsed_time = m_time;
if (block.g1_line_id >= 0)
m_g1_times.emplace_back(block.g1_line_id, m_time);
#if ENABLE_MOVE_STATS
MovesStatsMap::iterator it = _moves_stats.find(block.move_type);
@ -840,9 +821,10 @@ namespace Slic3r {
m_custom_gcode_time_cache += block_time;
}
m_last_st_synchronized_block_id = (int)m_blocks.size() - 1;
// The additional time has been consumed (added to the total time), reset it to zero.
set_additional_time(0.);
if (keep_last_n_blocks)
m_blocks.erase(m_blocks.begin(), m_blocks.begin() + n_blocks_process);
else
m_blocks.clear();
}
void GCodeTimeEstimator::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line)
@ -1196,8 +1178,11 @@ namespace Slic3r {
#endif // ENABLE_MOVE_STATS
// adds block to blocks list
block.g1_line_id = this->get_g1_line_id();
m_blocks.emplace_back(block);
m_g1_line_ids.emplace_back(G1LineIdToBlockIdMap::value_type(get_g1_line_id(), (unsigned int)m_blocks.size() - 1));
if (m_blocks.size() > planner_refresh_if_larger)
_calculate_time(planner_queue_size);
}
void GCodeTimeEstimator::_processG4(const GCodeReader::GCodeLine& line)
@ -1206,8 +1191,9 @@ namespace Slic3r {
GCodeFlavor dialect = get_dialect();
float value;
float extra_time = 0.f;
if (line.has_value('P', value))
add_additional_time(value * MILLISEC_TO_SEC);
extra_time += value * MILLISEC_TO_SEC;
// see: http://reprap.org/wiki/G-code#G4:_Dwell
if ((dialect == gcfRepetier) ||
@ -1216,10 +1202,10 @@ namespace Slic3r {
(dialect == gcfRepRap))
{
if (line.has_value('S', value))
add_additional_time(value);
extra_time += value;
}
_simulate_st_synchronize();
_simulate_st_synchronize(extra_time);
}
void GCodeTimeEstimator::_processG20(const GCodeReader::GCodeLine& line)
@ -1284,7 +1270,7 @@ namespace Slic3r {
anyFound = true;
}
else
_simulate_st_synchronize();
_simulate_st_synchronize(0.f);
if (!anyFound)
{
@ -1298,7 +1284,7 @@ namespace Slic3r {
void GCodeTimeEstimator::_processM1(const GCodeReader::GCodeLine& line)
{
PROFILE_FUNC();
_simulate_st_synchronize();
_simulate_st_synchronize(0.f);
}
void GCodeTimeEstimator::_processM82(const GCodeReader::GCodeLine& line)
@ -1450,9 +1436,9 @@ namespace Slic3r {
// MK3 MMU2 specific M code:
// M702 C is expected to be sent by the custom end G-code when finalizing a print.
// The MK3 unit shall unload and park the active filament into the MMU2 unit.
add_additional_time(get_filament_unload_time(get_extruder_id()));
float extra_time = get_filament_unload_time(get_extruder_id());
reset_extruder_id();
_simulate_st_synchronize();
_simulate_st_synchronize(extra_time);
}
}
@ -1466,10 +1452,10 @@ namespace Slic3r {
{
// Specific to the MK3 MMU2: The initial extruder ID is set to -1 indicating
// that the filament is parked in the MMU2 unit and there is nothing to be unloaded yet.
add_additional_time(get_filament_unload_time(get_extruder_id()));
float extra_time = get_filament_unload_time(get_extruder_id());
set_extruder_id(id);
add_additional_time(get_filament_load_time(get_extruder_id()));
_simulate_st_synchronize();
extra_time += get_filament_load_time(get_extruder_id());
_simulate_st_synchronize(extra_time);
}
}
}
@ -1501,7 +1487,9 @@ namespace Slic3r {
{
PROFILE_FUNC();
m_needs_custom_gcode_times = true;
_calculate_time();
//FIXME this simulates st_synchronize! is it correct?
// The estimated time may be longer than the real print time.
_simulate_st_synchronize(0.f);
if (m_custom_gcode_time_cache != 0.0f)
{
m_custom_gcode_times.push_back({code, m_custom_gcode_time_cache});
@ -1509,34 +1497,26 @@ namespace Slic3r {
}
}
void GCodeTimeEstimator::_simulate_st_synchronize()
void GCodeTimeEstimator::_simulate_st_synchronize(float extra_time)
{
PROFILE_FUNC();
_calculate_time();
m_time += extra_time;
m_custom_gcode_time_cache += extra_time;
_calculate_time(0);
}
void GCodeTimeEstimator::_forward_pass()
{
PROFILE_FUNC();
if (m_blocks.size() > 1)
{
for (int i = m_last_st_synchronized_block_id + 1; i < (int)m_blocks.size() - 1; ++i)
{
_planner_forward_pass_kernel(m_blocks[i], m_blocks[i + 1]);
}
}
for (int i = 0; i + 1 < (int)m_blocks.size(); ++i)
_planner_forward_pass_kernel(m_blocks[i], m_blocks[i + 1]);
}
void GCodeTimeEstimator::_reverse_pass()
{
PROFILE_FUNC();
if (m_blocks.size() > 1)
{
for (int i = (int)m_blocks.size() - 1; i >= m_last_st_synchronized_block_id + 2; --i)
{
_planner_reverse_pass_kernel(m_blocks[i - 1], m_blocks[i]);
}
}
for (int i = (int)m_blocks.size() - 1; i > 0; -- i)
_planner_reverse_pass_kernel(m_blocks[i - 1], m_blocks[i]);
}
void GCodeTimeEstimator::_planner_forward_pass_kernel(Block& prev, Block& curr)
@ -1586,7 +1566,7 @@ namespace Slic3r {
Block* curr = nullptr;
Block* next = nullptr;
for (int i = m_last_st_synchronized_block_id + 1; i < (int)m_blocks.size(); ++i)
for (size_t i = 0; i < m_blocks.size(); ++ i)
{
Block& b = m_blocks[i];
@ -1645,7 +1625,7 @@ namespace Slic3r {
{
char buffer[64];
int minutes = std::round(time_in_secs / 60.);
int minutes = int(std::round(time_in_secs / 60.));
if (minutes <= 0) {
::sprintf(buffer, "%ds", (int)time_in_secs);
} else {

View file

@ -85,7 +85,6 @@ namespace Slic3r {
// hard limit for the acceleration, to which the firmware will clamp.
float max_acceleration; // mm/s^2
float retract_acceleration; // mm/s^2
float additional_time; // s
float minimum_feedrate; // mm/s
float minimum_travel_feedrate; // mm/s
float extrude_factor_override_percentage;
@ -159,7 +158,9 @@ namespace Slic3r {
FeedrateProfile feedrate;
Trapezoid trapezoid;
float elapsed_time;
// Ordnary index of this G1 line in the file.
int g1_line_id { -1 };
// Returns the time spent accelerating toward cruise speed, in seconds
float acceleration_time() const;
@ -205,16 +206,13 @@ namespace Slic3r {
#endif // ENABLE_MOVE_STATS
public:
typedef std::pair<unsigned int, unsigned int> G1LineIdToBlockId;
typedef std::vector<G1LineIdToBlockId> G1LineIdToBlockIdMap;
typedef std::pair<int, float> G1LineIdTime;
typedef std::vector<G1LineIdTime> G1LineIdsTimes;
struct PostProcessData
{
const G1LineIdToBlockIdMap& g1_line_ids;
const BlocksList& blocks;
const G1LineIdsTimes& g1_times;
float time;
PostProcessData(const G1LineIdToBlockIdMap& g1_line_ids, const BlocksList& blocks, float time) : g1_line_ids(g1_line_ids), blocks(blocks), time(time) {}
};
private:
@ -224,10 +222,14 @@ namespace Slic3r {
Feedrates m_curr;
Feedrates m_prev;
BlocksList m_blocks;
// Map between g1 line id and blocks id, used to speed up export of remaining times
G1LineIdToBlockIdMap m_g1_line_ids;
// Index of the last block already st_synchronized
int m_last_st_synchronized_block_id;
// Size of the firmware planner queue. The old 8-bit Marlins usually just managed 16 trapezoidal blocks.
// Let's be conservative and plan for newer boards with more memory.
static constexpr size_t planner_queue_size = 64;
// The firmware recalculates last planner_queue_size trapezoidal blocks each time a new block is added.
// We are not simulating the firmware exactly, we calculate a sequence of blocks once a reasonable number of blocks accumulate.
static constexpr size_t planner_refresh_if_larger = planner_queue_size * 4;
// Map from g1 line id to its elapsed time from the start of the print.
G1LineIdsTimes m_g1_times;
float m_time; // s
// data to calculate custom code times
@ -255,13 +257,13 @@ namespace Slic3r {
void calculate_time(bool start_from_beginning);
// Calculates the time estimate from the given gcode in string format
void calculate_time_from_text(const std::string& gcode);
//void calculate_time_from_text(const std::string& gcode);
// Calculates the time estimate from the gcode contained in the file with the given filename
void calculate_time_from_file(const std::string& file);
//void calculate_time_from_file(const std::string& file);
// Calculates the time estimate from the gcode contained in given list of gcode lines
void calculate_time_from_lines(const std::vector<std::string>& gcode_lines);
//void calculate_time_from_lines(const std::vector<std::string>& gcode_lines);
// Process the gcode contained in the file with the given filename,
// replacing placeholders with correspondent new lines M73
@ -338,10 +340,6 @@ namespace Slic3r {
unsigned int get_extruder_id() const;
void reset_extruder_id();
void add_additional_time(float timeSec);
void set_additional_time(float timeSec);
float get_additional_time() const;
void set_default();
// Call this method before to start adding lines using add_gcode_line() when reusing an instance of GCodeTimeEstimator
@ -377,7 +375,7 @@ namespace Slic3r {
// Return an estimate of the memory consumed by the time estimator.
size_t memory_used() const;
PostProcessData get_post_process_data() const { return PostProcessData(m_g1_line_ids, m_blocks, m_time); }
PostProcessData get_post_process_data() const { return PostProcessData{ m_g1_times, m_time }; }
private:
void _reset();
@ -385,7 +383,7 @@ namespace Slic3r {
void _reset_blocks();
// Calculates the time estimate
void _calculate_time();
void _calculate_time(size_t keep_last_n_blocks);
// Processes the given gcode line
void _process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line);
@ -458,7 +456,7 @@ namespace Slic3r {
void _process_custom_gcode_tag(CustomGcodeType code);
// Simulates firmware st_synchronize() call
void _simulate_st_synchronize();
void _simulate_st_synchronize(float additional_time);
void _forward_pass();
void _reverse_pass();

View file

@ -112,72 +112,82 @@ void Layer::make_perimeters()
// keep track of regions whose perimeters we have already generated
std::vector<unsigned char> done(m_regions.size(), false);
for (LayerRegionPtrs::iterator layerm = m_regions.begin(); layerm != m_regions.end(); ++ layerm) {
size_t region_id = layerm - m_regions.begin();
if (done[region_id])
continue;
BOOST_LOG_TRIVIAL(trace) << "Generating perimeters for layer " << this->id() << ", region " << region_id;
done[region_id] = true;
const PrintRegionConfig &config = (*layerm)->region()->config();
// find compatible regions
LayerRegionPtrs layerms;
layerms.push_back(*layerm);
for (LayerRegionPtrs::const_iterator it = layerm + 1; it != m_regions.end(); ++it) {
LayerRegion* other_layerm = *it;
const PrintRegionConfig &other_config = other_layerm->region()->config();
if (config.perimeter_extruder == other_config.perimeter_extruder
&& config.perimeters == other_config.perimeters
&& config.perimeter_speed == other_config.perimeter_speed
&& config.external_perimeter_speed == other_config.external_perimeter_speed
&& config.gap_fill_speed == other_config.gap_fill_speed
&& config.overhangs == other_config.overhangs
&& config.opt_serialize("perimeter_extrusion_width") == other_config.opt_serialize("perimeter_extrusion_width")
&& config.thin_walls == other_config.thin_walls
&& config.external_perimeters_first == other_config.external_perimeters_first
&& config.infill_overlap == other_config.infill_overlap) {
layerms.push_back(other_layerm);
done[it - m_regions.begin()] = true;
}
}
if (layerms.size() == 1) { // optimization
(*layerm)->fill_surfaces.surfaces.clear();
(*layerm)->make_perimeters((*layerm)->slices, &(*layerm)->fill_surfaces);
(*layerm)->fill_expolygons = to_expolygons((*layerm)->fill_surfaces.surfaces);
} else {
SurfaceCollection new_slices;
// Use the region with highest infill rate, as the make_perimeters() function below decides on the gap fill based on the infill existence.
LayerRegion *layerm_config = layerms.front();
{
// group slices (surfaces) according to number of extra perimeters
std::map<unsigned short, Surfaces> slices; // extra_perimeters => [ surface, surface... ]
for (LayerRegion *layerm : layerms) {
for (Surface &surface : layerm->slices.surfaces)
slices[surface.extra_perimeters].emplace_back(surface);
if (layerm->region()->config().fill_density > layerm_config->region()->config().fill_density)
layerm_config = layerm;
}
// merge the surfaces assigned to each group
for (std::pair<const unsigned short,Surfaces> &surfaces_with_extra_perimeters : slices)
new_slices.append(union_ex(surfaces_with_extra_perimeters.second, true), surfaces_with_extra_perimeters.second.front());
}
// make perimeters
SurfaceCollection fill_surfaces;
layerm_config->make_perimeters(new_slices, &fill_surfaces);
for (LayerRegionPtrs::iterator layerm = m_regions.begin(); layerm != m_regions.end(); ++ layerm)
if ((*layerm)->slices.empty()) {
(*layerm)->perimeters.clear();
(*layerm)->fills.clear();
(*layerm)->thin_fills.clear();
} else {
size_t region_id = layerm - m_regions.begin();
if (done[region_id])
continue;
BOOST_LOG_TRIVIAL(trace) << "Generating perimeters for layer " << this->id() << ", region " << region_id;
done[region_id] = true;
const PrintRegionConfig &config = (*layerm)->region()->config();
// find compatible regions
LayerRegionPtrs layerms;
layerms.push_back(*layerm);
for (LayerRegionPtrs::const_iterator it = layerm + 1; it != m_regions.end(); ++it)
if (! (*it)->slices.empty()) {
LayerRegion* other_layerm = *it;
const PrintRegionConfig &other_config = other_layerm->region()->config();
if (config.perimeter_extruder == other_config.perimeter_extruder
&& config.perimeters == other_config.perimeters
&& config.perimeter_speed == other_config.perimeter_speed
&& config.external_perimeter_speed == other_config.external_perimeter_speed
&& config.gap_fill_speed == other_config.gap_fill_speed
&& config.overhangs == other_config.overhangs
&& config.opt_serialize("perimeter_extrusion_width") == other_config.opt_serialize("perimeter_extrusion_width")
&& config.thin_walls == other_config.thin_walls
&& config.external_perimeters_first == other_config.external_perimeters_first
&& config.infill_overlap == other_config.infill_overlap)
{
other_layerm->perimeters.clear();
other_layerm->fills.clear();
other_layerm->thin_fills.clear();
layerms.push_back(other_layerm);
done[it - m_regions.begin()] = true;
}
}
if (layerms.size() == 1) { // optimization
(*layerm)->fill_surfaces.surfaces.clear();
(*layerm)->make_perimeters((*layerm)->slices, &(*layerm)->fill_surfaces);
(*layerm)->fill_expolygons = to_expolygons((*layerm)->fill_surfaces.surfaces);
} else {
SurfaceCollection new_slices;
// Use the region with highest infill rate, as the make_perimeters() function below decides on the gap fill based on the infill existence.
LayerRegion *layerm_config = layerms.front();
{
// group slices (surfaces) according to number of extra perimeters
std::map<unsigned short, Surfaces> slices; // extra_perimeters => [ surface, surface... ]
for (LayerRegion *layerm : layerms) {
for (Surface &surface : layerm->slices.surfaces)
slices[surface.extra_perimeters].emplace_back(surface);
if (layerm->region()->config().fill_density > layerm_config->region()->config().fill_density)
layerm_config = layerm;
}
// merge the surfaces assigned to each group
for (std::pair<const unsigned short,Surfaces> &surfaces_with_extra_perimeters : slices)
new_slices.append(union_ex(surfaces_with_extra_perimeters.second, true), surfaces_with_extra_perimeters.second.front());
}
// make perimeters
SurfaceCollection fill_surfaces;
layerm_config->make_perimeters(new_slices, &fill_surfaces);
// assign fill_surfaces to each layer
if (!fill_surfaces.surfaces.empty()) {
for (LayerRegionPtrs::iterator l = layerms.begin(); l != layerms.end(); ++l) {
// Separate the fill surfaces.
ExPolygons expp = intersection_ex(to_polygons(fill_surfaces), (*l)->slices);
(*l)->fill_expolygons = expp;
(*l)->fill_surfaces.set(std::move(expp), fill_surfaces.surfaces.front());
}
}
}
}
// assign fill_surfaces to each layer
if (!fill_surfaces.surfaces.empty()) {
for (LayerRegionPtrs::iterator l = layerms.begin(); l != layerms.end(); ++l) {
// Separate the fill surfaces.
ExPolygons expp = intersection_ex(to_polygons(fill_surfaces), (*l)->slices);
(*l)->fill_expolygons = expp;
(*l)->fill_surfaces.set(std::move(expp), fill_surfaces.surfaces.front());
}
}
}
}
BOOST_LOG_TRIVIAL(trace) << "Generating perimeters for layer " << this->id() << " - Done";
}

View file

@ -117,7 +117,7 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly
// Voids are sparse infills if infill rate is zero.
Polygons voids;
for (const Surface &surface : this->fill_surfaces.surfaces) {
if (surface.surface_type == stTop) {
if (surface.is_top()) {
// Collect the top surfaces, inflate them and trim them by the bottom surfaces.
// This gives the priority to bottom surfaces.
surfaces_append(top, offset_ex(surface.expolygon, margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS), surface);
@ -313,7 +313,7 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly
s2.clear();
}
}
if (s1.surface_type == stTop)
if (s1.is_top())
// Trim the top surfaces by the bottom surfaces. This gives the priority to the bottom surfaces.
polys = diff(polys, bottom_polygons);
surfaces_append(

View file

@ -29,7 +29,7 @@ TriangleMesh eigen_to_triangle_mesh(const EigenMesh &emesh)
auto &VC = emesh.first; auto &FC = emesh.second;
Pointf3s points(size_t(VC.rows()));
std::vector<Vec3crd> facets(size_t(FC.rows()));
std::vector<Vec3i> facets(size_t(FC.rows()));
for (Eigen::Index i = 0; i < VC.rows(); ++i)
points[size_t(i)] = VC.row(i);
@ -154,7 +154,7 @@ inline Vec3d to_vec3d(const _EpecMesh::Point &v)
template<class _Mesh> TriangleMesh cgal_to_triangle_mesh(const _Mesh &cgalmesh)
{
Pointf3s points;
std::vector<Vec3crd> facets;
std::vector<Vec3i> facets;
points.reserve(cgalmesh.num_vertices());
facets.reserve(cgalmesh.num_faces());
@ -166,7 +166,7 @@ template<class _Mesh> TriangleMesh cgal_to_triangle_mesh(const _Mesh &cgalmesh)
for (auto &face : cgalmesh.faces()) {
auto vtc = cgalmesh.vertices_around_face(cgalmesh.halfedge(face));
int i = 0;
Vec3crd trface;
Vec3i trface;
for (auto v : vtc) trface(i++) = static_cast<int>(v);
facets.emplace_back(trface);
}

View file

@ -419,7 +419,7 @@ bool Model::arrange_objects(coordf_t dist, const BoundingBoxf* bb)
if (input[i].bed_idx != 0) ret = false;
if (input[i].bed_idx >= 0) {
input[i].translation += Vec2crd{input[i].bed_idx * stride, 0};
instances[i]->apply_arrange_result(input[i].translation,
instances[i]->apply_arrange_result(input[i].translation.cast<double>(),
input[i].rotation);
}
}

View file

@ -668,7 +668,7 @@ public:
arrangement::ArrangePolygon get_arrange_polygon() const;
// Apply the arrange result on the ModelInstance
void apply_arrange_result(const Vec2crd& offs, double rotation)
void apply_arrange_result(const Vec2d& offs, double rotation)
{
// write the transformation data into the model instance
set_rotation(Z, rotation);

View file

@ -24,7 +24,9 @@ typedef Eigen::Matrix<coord_t, 2, 1, Eigen::DontAlign> Vec2crd;
typedef Eigen::Matrix<coord_t, 3, 1, Eigen::DontAlign> Vec3crd;
typedef Eigen::Matrix<int, 2, 1, Eigen::DontAlign> Vec2i;
typedef Eigen::Matrix<int, 3, 1, Eigen::DontAlign> Vec3i;
typedef Eigen::Matrix<int32_t, 2, 1, Eigen::DontAlign> Vec2i32;
typedef Eigen::Matrix<int64_t, 2, 1, Eigen::DontAlign> Vec2i64;
typedef Eigen::Matrix<int32_t, 3, 1, Eigen::DontAlign> Vec3i32;
typedef Eigen::Matrix<int64_t, 3, 1, Eigen::DontAlign> Vec3i64;
// Vector types with a double coordinate base type.
@ -53,12 +55,12 @@ typedef Eigen::Transform<double, 3, Eigen::Affine, Eigen::DontAlign> Transform3d
inline bool operator<(const Vec2d &lhs, const Vec2d &rhs) { return lhs(0) < rhs(0) || (lhs(0) == rhs(0) && lhs(1) < rhs(1)); }
inline int32_t cross2(const Vec2i32 &v1, const Vec2i32 &v2) { return v1(0) * v2(1) - v1(1) * v2(0); }
inline int64_t cross2(const Vec2i64 &v1, const Vec2i64 &v2) { return v1(0) * v2(1) - v1(1) * v2(0); }
inline coord_t cross2(const Vec2crd &v1, const Vec2crd &v2) { return v1(0) * v2(1) - v1(1) * v2(0); }
inline float cross2(const Vec2f &v1, const Vec2f &v2) { return v1(0) * v2(1) - v1(1) * v2(0); }
inline double cross2(const Vec2d &v1, const Vec2d &v2) { return v1(0) * v2(1) - v1(1) * v2(0); }
inline Vec2crd to_2d(const Vec3crd &pt3) { return Vec2crd(pt3(0), pt3(1)); }
inline Vec2i32 to_2d(const Vec2i32 &pt3) { return Vec2i32(pt3(0), pt3(1)); }
inline Vec2i64 to_2d(const Vec3i64 &pt3) { return Vec2i64(pt3(0), pt3(1)); }
inline Vec2f to_2d(const Vec3f &pt3) { return Vec2f (pt3(0), pt3(1)); }
inline Vec2d to_2d(const Vec3d &pt3) { return Vec2d (pt3(0), pt3(1)); }
@ -89,8 +91,8 @@ public:
typedef coord_t coord_type;
Point() : Vec2crd(0, 0) {}
Point(coord_t x, coord_t y) : Vec2crd(x, y) {}
Point(int64_t x, int64_t y) : Vec2crd(coord_t(x), coord_t(y)) {} // for Clipper
Point(int32_t x, int32_t y) : Vec2crd(coord_t(x), coord_t(y)) {}
Point(int64_t x, int64_t y) : Vec2crd(coord_t(x), coord_t(y)) {}
Point(double x, double y) : Vec2crd(coord_t(lrint(x)), coord_t(lrint(y))) {}
Point(const Point &rhs) { *this = rhs; }
explicit Point(const Vec2d& rhs) : Vec2crd(coord_t(lrint(rhs.x())), coord_t(lrint(rhs.y()))) {}

View file

@ -39,7 +39,7 @@ public:
// last point == first point for polygons
const Point& last_point() const override { return this->points.front(); }
virtual Lines lines() const;
Lines lines() const override;
Polyline split_at_vertex(const Point &point) const;
// Split a closed polygon into an open polyline, with the split point duplicated at both ends.
Polyline split_at_index(int index) const;

View file

@ -65,7 +65,7 @@ public:
const Point& last_point() const override { return this->points.back(); }
const Point& leftmost_point() const;
virtual Lines lines() const;
Lines lines() const override;
void clip_end(double distance);
void clip_start(double distance);
void extend_end(double distance);

View file

@ -161,6 +161,7 @@ bool Print::invalidate_state_by_config_options(const std::vector<t_config_option
} else if (
opt_key == "skirts"
|| opt_key == "skirt_height"
|| opt_key == "draft_shield"
|| opt_key == "skirt_distance"
|| opt_key == "min_skirt_length"
|| opt_key == "ooze_prevention"
@ -1146,14 +1147,12 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
bool Print::has_infinite_skirt() const
{
return (m_config.skirt_height == -1 && m_config.skirts > 0)
|| (m_config.ooze_prevention && this->extruders().size() > 1);
return (m_config.draft_shield && m_config.skirts > 0) || (m_config.ooze_prevention && this->extruders().size() > 1);
}
bool Print::has_skirt() const
{
return (m_config.skirt_height > 0 && m_config.skirts > 0)
|| this->has_infinite_skirt();
return (m_config.skirt_height > 0 && m_config.skirts > 0) || this->has_infinite_skirt();
}
static inline bool sequential_print_horizontal_clearance_valid(const Print &print)
@ -1623,11 +1622,7 @@ void Print::process()
// The export_gcode may die for various reasons (fails to process output_filename_format,
// write error into the G-code, cannot execute post-processing scripts).
// It is up to the caller to show an error message.
#if ENABLE_THUMBNAIL_GENERATOR
std::string Print::export_gcode(const std::string& path_template, GCodePreviewData* preview_data, ThumbnailsGeneratorCallback thumbnail_cb)
#else
std::string Print::export_gcode(const std::string &path_template, GCodePreviewData *preview_data)
#endif // ENABLE_THUMBNAIL_GENERATOR
{
// output everything to a G-code file
// The following call may die if the output_filename_format template substitution fails.
@ -1644,11 +1639,7 @@ std::string Print::export_gcode(const std::string &path_template, GCodePreviewDa
// The following line may die for multiple reasons.
GCode gcode;
#if ENABLE_THUMBNAIL_GENERATOR
gcode.do_export(this, path.c_str(), preview_data, thumbnail_cb);
#else
gcode.do_export(this, path.c_str(), preview_data);
#endif // ENABLE_THUMBNAIL_GENERATOR
return path.c_str();
}
@ -1936,7 +1927,7 @@ void Print::_make_brim()
// Find all pieces that the initial loop was split into.
size_t j = i + 1;
for (; j < loops_trimmed_order.size() && loops_trimmed_order[i].second == loops_trimmed_order[j].second; ++ j) ;
const ClipperLib_Z::Path &first_path = *loops_trimmed_order[i].first;
const ClipperLib_Z::Path &first_path = *loops_trimmed_order[i].first;
if (i + 1 == j && first_path.size() > 3 && first_path.front().X == first_path.back().X && first_path.front().Y == first_path.back().Y) {
auto *loop = new ExtrusionLoop();
m_brim.entities.emplace_back(loop);
@ -2138,6 +2129,7 @@ std::string Print::output_filename(const std::string &filename_base) const
// Set the placeholders for the data know first after the G-code export is finished.
// These values will be just propagated into the output file name.
DynamicConfig config = this->finished() ? this->print_statistics().config() : this->print_statistics().placeholders();
config.set_key_value("num_extruders", new ConfigOptionInt((int)m_config.nozzle_diameter.size()));
return this->PrintBase::output_filename(m_config.output_filename_format.value, ".gcode", filename_base, &config);
}

View file

@ -11,9 +11,7 @@
#include "Slicing.hpp"
#include "GCode/ToolOrdering.hpp"
#include "GCode/WipeTower.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
#include "GCode/ThumbnailData.hpp"
#endif // ENABLE_THUMBNAIL_GENERATOR
#include "libslic3r.h"
@ -349,7 +347,7 @@ public:
Print() = default;
virtual ~Print() { this->clear(); }
PrinterTechnology technology() const noexcept { return ptFFF; }
PrinterTechnology technology() const noexcept override { return ptFFF; }
// Methods, which change the state of Print / PrintObject / PrintRegion.
// The following methods are synchronized with process() and export_gcode(),
@ -364,11 +362,7 @@ public:
void process() override;
// Exports G-code into a file name based on the path_template, returns the file path of the generated G-code file.
// If preview_data is not null, the preview_data is filled in for the G-code visualization (not used by the command line Slic3r).
#if ENABLE_THUMBNAIL_GENERATOR
std::string export_gcode(const std::string& path_template, GCodePreviewData* preview_data, ThumbnailsGeneratorCallback thumbnail_cb = nullptr);
#else
std::string export_gcode(const std::string &path_template, GCodePreviewData *preview_data);
#endif // ENABLE_THUMBNAIL_GENERATOR
// methods for handling state
bool is_step_done(PrintStep step) const { return Inherited::is_step_done(step); }

View file

@ -254,7 +254,7 @@ void PrintConfigDef::init_fff_params()
"to clip the overlapping object parts one by the other "
"(2nd part will be clipped by the 1st, 3rd part will be clipped by the 1st and 2nd etc).");
def->mode = comExpert;
def->set_default_value(new ConfigOptionBool(false));
def->set_default_value(new ConfigOptionBool(true));
def = this->add("colorprint_heights", coFloats);
def->label = L("Colorprint height");
@ -1691,6 +1691,13 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionInt(1));
def = this->add("draft_shield", coBool);
def->label = L("Draft shield");
def->tooltip = L("If enabled, the skirt will be as tall as a highest printed object. "
"This is useful to protect an ABS or ASA print from warping and detaching from print bed due to wind draft.");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBool(false));
def = this->add("skirts", coInt);
def->label = L("Loops (minimum)");
def->full_label = L("Skirt Loops");
@ -2998,6 +3005,11 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
} else if (opt_key == "support_material_pattern" && value == "pillars") {
// Slic3r PE does not support the pillars. They never worked well.
value = "rectilinear";
} else if (opt_key == "skirt_height" && value == "-1") {
// PrusaSlicer no more accepts skirt_height == -1 to print a draft shield to the top of the highest object.
// A new "draft_shield" boolean config value is used instead.
opt_key = "draft_shield";
value = "1";
} else if (opt_key == "octoprint_host") {
opt_key = "print_host";
} else if (opt_key == "octoprint_cafile") {
@ -3206,7 +3218,7 @@ std::string FullPrintConfig::validate()
return "Invalid value for --infill-every-layers";
// --skirt-height
if (this->skirt_height < -1) // -1 means as tall as the object
if (this->skirt_height < 0)
return "Invalid value for --skirt-height";
// --bridge-flow-ratio

View file

@ -800,6 +800,7 @@ public:
ConfigOptionBools retract_layer_change;
ConfigOptionFloat skirt_distance;
ConfigOptionInt skirt_height;
ConfigOptionBool draft_shield;
ConfigOptionInt skirts;
ConfigOptionInts slowdown_below_layer_time;
ConfigOptionBool spiral_vase;
@ -872,6 +873,7 @@ protected:
OPT_PTR(retract_layer_change);
OPT_PTR(skirt_distance);
OPT_PTR(skirt_height);
OPT_PTR(draft_shield);
OPT_PTR(skirts);
OPT_PTR(slowdown_below_layer_time);
OPT_PTR(spiral_vase);

View file

@ -817,11 +817,12 @@ void PrintObject::detect_surfaces_type()
m_layers[idx_layer]->m_regions[idx_region]->slices.surfaces = std::move(surfaces_new[idx_layer]);
}
if (spiral_vase && num_layers > 1) {
// Turn the last bottom layer infill to a top infill, so it will be extruded with a proper pattern.
Surfaces &surfaces = m_layers[num_layers - 1]->m_regions[idx_region]->slices.surfaces;
for (Surface &surface : surfaces)
surface.surface_type = stTop;
if (spiral_vase) {
if (num_layers > 1)
// Turn the last bottom layer infill to a top infill, so it will be extruded with a proper pattern.
m_layers[num_layers - 1]->m_regions[idx_region]->slices.set_type(stTop);
for (size_t i = num_layers; i < m_layers.size(); ++ i)
m_layers[i]->m_regions[idx_region]->slices.set_type(stInternal);
}
BOOST_LOG_TRIVIAL(debug) << "Detecting solid surfaces for region " << idx_region << " - clipping in parallel - start";

View file

@ -228,7 +228,7 @@ void to_eigen_mesh(const TriangleMesh &tmesh, Eigen::MatrixXd &V, Eigen::MatrixX
void to_triangle_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, TriangleMesh &out)
{
Pointf3s points(size_t(V.rows()));
std::vector<Vec3crd> facets(size_t(F.rows()));
std::vector<Vec3i> facets(size_t(F.rows()));
for (Eigen::Index i = 0; i < V.rows(); ++i)
points[size_t(i)] = V.row(i);

View file

@ -101,6 +101,9 @@ public:
// Iterates over hits and holes and returns the true hit, possibly
// on the inside of a hole.
// This function is currently not used anywhere, it was written when the
// holes were subtracted on slices, that is, before we started using CGAL
// to actually cut the holes into the mesh.
hit_result filter_hits(const std::vector<EigenMesh3D::hit_result>& obj_hits) const;
class si_result {

View file

@ -48,9 +48,8 @@ Contour3D sphere(double rho, Portion portion, double fa) {
vertices.emplace_back(Vec3d(b(0), b(1), z));
if (sbegin == 0)
facets.emplace_back((i == 0) ?
Vec3crd(coord_t(ring.size()), 0, 1) :
Vec3crd(id - 1, 0, id));
(i == 0) ? facets.emplace_back(coord_t(ring.size()), 0, 1) :
facets.emplace_back(id - 1, 0, id);
++id;
}
@ -66,12 +65,11 @@ Contour3D sphere(double rho, Portion portion, double fa) {
auto id_ringsize = coord_t(id - int(ring.size()));
if (i == 0) {
// wrap around
facets.emplace_back(Vec3crd(id - 1, id,
id + coord_t(ring.size() - 1)));
facets.emplace_back(Vec3crd(id - 1, id_ringsize, id));
facets.emplace_back(id - 1, id, id + coord_t(ring.size() - 1) );
facets.emplace_back(id - 1, id_ringsize, id);
} else {
facets.emplace_back(Vec3crd(id_ringsize - 1, id_ringsize, id));
facets.emplace_back(Vec3crd(id - 1, id_ringsize - 1, id));
facets.emplace_back(id_ringsize - 1, id_ringsize, id);
facets.emplace_back(id - 1, id_ringsize - 1, id);
}
id++;
}
@ -85,10 +83,10 @@ Contour3D sphere(double rho, Portion portion, double fa) {
auto id_ringsize = coord_t(id - int(ring.size()));
if (i == 0) {
// third vertex is on the other side of the ring.
facets.emplace_back(Vec3crd(id - 1, id_ringsize, id));
facets.emplace_back(id - 1, id_ringsize, id);
} else {
auto ci = coord_t(id_ringsize + coord_t(i));
facets.emplace_back(Vec3crd(ci - 1, ci, id));
facets.emplace_back(ci - 1, ci, id);
}
}
}

View file

@ -34,6 +34,10 @@ public:
void remove_type(const SurfaceType type);
void remove_types(const SurfaceType *types, int ntypes);
void filter_by_type(SurfaceType type, Polygons* polygons);
void set_type(SurfaceType type) {
for (Surface &surface : this->surfaces)
surface.surface_type = type;
}
void clear() { surfaces.clear(); }
bool empty() const { return surfaces.empty(); }

View file

@ -1,5 +1,5 @@
#ifndef _technologies_h_
#define _technologies_h_
#ifndef _prusaslicer_technologies_h_
#define _prusaslicer_technologies_h_
//============
// debug techs
@ -17,37 +17,44 @@
#define ENABLE_CAMERA_STATISTICS 0
// Render the picking pass instead of the main scene (use [T] key to toggle between regular rendering and picking pass only rendering)
#define ENABLE_RENDER_PICKING_PASS 0
//====================
// 1.42.0.alpha1 techs
//====================
#define ENABLE_1_42_0_ALPHA1 1
// Enable extracting thumbnails from selected gcode and save them as png files
#define ENABLE_THUMBNAIL_GENERATOR_DEBUG 0
// Disable synchronization of unselected instances
#define DISABLE_INSTANCES_SYNCH (0 && ENABLE_1_42_0_ALPHA1)
#define DISABLE_INSTANCES_SYNCH 0
// Use wxDataViewRender instead of wxDataViewCustomRenderer
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0_ALPHA1)
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING 0
//====================
// 2.2.0.alpha1 techs
//====================
#define ENABLE_2_2_0_ALPHA1 1
// Enable thumbnail generator
// When removing this technology, remove it also from stable branch,
// where it has been partially copied for patch 2.1.1
#define ENABLE_THUMBNAIL_GENERATOR (1 && ENABLE_2_2_0_ALPHA1)
#define ENABLE_THUMBNAIL_GENERATOR_DEBUG (0 && ENABLE_THUMBNAIL_GENERATOR)
//==================
//================
// 2.2.0.rc1 techs
//==================
//================
#define ENABLE_2_2_0_RC1 1
// Enable hack to remove crash when closing on OSX 10.9.5
#define ENABLE_HACK_CLOSING_ON_OSX_10_9_5 (1 && ENABLE_2_2_0_RC1)
#endif // _technologies_h_
//==================
// 2.2.0.final techs
//==================
#define ENABLE_2_2_0_FINAL 1
// Enable tooltips for GLCanvas3D using ImGUI
#define ENABLE_CANVAS_TOOLTIP_USING_IMGUI (1 && ENABLE_2_2_0_FINAL)
// Enable fix for dragging mouse event handling for gizmobar
#define ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX (1 && ENABLE_2_2_0_FINAL)
//===================
// 2.3.0.alpha1 techs
//===================
#define ENABLE_2_3_0_ALPHA1 1
// Enable rendering of objects colored by facets' slope
#define ENABLE_SLOPE_RENDERING (1 && ENABLE_2_3_0_ALPHA1)
// Moves GLCanvas3DManager from being a static member of _3DScene to be a normal member of GUI_App
#define ENABLE_NON_STATIC_CANVAS_MANAGER (1 && ENABLE_2_3_0_ALPHA1)
#endif // _prusaslicer_technologies_h_

View file

@ -42,7 +42,7 @@
namespace Slic3r {
TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector<Vec3crd>& facets) : repaired(false)
TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector<Vec3i> &facets) : repaired(false)
{
stl_file &stl = this->stl;
stl.stats.type = inmemory;
@ -600,7 +600,7 @@ TriangleMesh TriangleMesh::convex_hull_3d() const
// Let's collect results:
Pointf3s dst_vertices;
std::vector<Vec3crd> facets;
std::vector<Vec3i> facets;
auto facet_list = qhull.facetList().toStdVector();
for (const orgQhull::QhullFacet& facet : facet_list)
{ // iterate through facets
@ -1931,22 +1931,18 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower)
// Generate the vertex list for a cube solid of arbitrary size in X/Y/Z.
TriangleMesh make_cube(double x, double y, double z)
{
Vec3d pv[8] = {
Vec3d(x, y, 0), Vec3d(x, 0, 0), Vec3d(0, 0, 0),
Vec3d(0, y, 0), Vec3d(x, y, z), Vec3d(0, y, z),
Vec3d(0, 0, z), Vec3d(x, 0, z)
};
Vec3crd fv[12] = {
Vec3crd(0, 1, 2), Vec3crd(0, 2, 3), Vec3crd(4, 5, 6),
Vec3crd(4, 6, 7), Vec3crd(0, 4, 7), Vec3crd(0, 7, 1),
Vec3crd(1, 7, 6), Vec3crd(1, 6, 2), Vec3crd(2, 6, 5),
Vec3crd(2, 5, 3), Vec3crd(4, 0, 3), Vec3crd(4, 3, 5)
};
std::vector<Vec3crd> facets(&fv[0], &fv[0]+12);
Pointf3s vertices(&pv[0], &pv[0]+8);
TriangleMesh mesh(vertices ,facets);
TriangleMesh mesh(
{
{x, y, 0}, {x, 0, 0}, {0, 0, 0},
{0, y, 0}, {x, y, z}, {0, y, z},
{0, 0, z}, {x, 0, z}
},
{
{0, 1, 2}, {0, 2, 3}, {4, 5, 6},
{4, 6, 7}, {0, 4, 7}, {0, 7, 1},
{1, 7, 6}, {1, 6, 2}, {2, 6, 5},
{2, 5, 3}, {4, 0, 3}, {4, 3, 5}
});
mesh.repair();
return mesh;
}
@ -1959,8 +1955,8 @@ TriangleMesh make_cylinder(double r, double h, double fa)
size_t n_steps = (size_t)ceil(2. * PI / fa);
double angle_step = 2. * PI / n_steps;
Pointf3s vertices;
std::vector<Vec3crd> facets;
Pointf3s vertices;
std::vector<Vec3i> facets;
vertices.reserve(2 * n_steps + 2);
facets.reserve(4 * n_steps);
@ -1980,17 +1976,17 @@ TriangleMesh make_cylinder(double r, double h, double fa)
vertices.emplace_back(Vec3d(p(0), p(1), 0.));
vertices.emplace_back(Vec3d(p(0), p(1), h));
int id = (int)vertices.size() - 1;
facets.emplace_back(Vec3crd( 0, id - 1, id - 3)); // top
facets.emplace_back(Vec3crd(id, 1, id - 2)); // bottom
facets.emplace_back(Vec3crd(id, id - 2, id - 3)); // upper-right of side
facets.emplace_back(Vec3crd(id, id - 3, id - 1)); // bottom-left of side
facets.emplace_back( 0, id - 1, id - 3); // top
facets.emplace_back(id, 1, id - 2); // bottom
facets.emplace_back(id, id - 2, id - 3); // upper-right of side
facets.emplace_back(id, id - 3, id - 1); // bottom-left of side
}
// Connect the last set of vertices with the first.
int id = (int)vertices.size() - 1;
facets.emplace_back(Vec3crd( 0, 2, id - 1));
facets.emplace_back(Vec3crd( 3, 1, id));
facets.emplace_back(Vec3crd(id, 2, 3));
facets.emplace_back(Vec3crd(id, id - 1, 2));
facets.emplace_back( 0, 2, id - 1);
facets.emplace_back( 3, 1, id);
facets.emplace_back(id, 2, 3);
facets.emplace_back(id, id - 1, 2);
TriangleMesh mesh(std::move(vertices), std::move(facets));
mesh.repair();
@ -2025,7 +2021,7 @@ TriangleMesh make_sphere(double radius, double fa)
}
}
std::vector<Vec3crd> facets;
std::vector<Vec3i> facets;
facets.reserve(2 * (stackCount - 1) * sectorCount);
for (int i = 0; i < stackCount; ++ i) {
// Beginning of current stack.
@ -2040,11 +2036,11 @@ TriangleMesh make_sphere(double radius, double fa)
int k2_next = k2;
if (i != 0) {
k1_next = (j + 1 == sectorCount) ? k1_first : (k1 + 1);
facets.emplace_back(Vec3crd(k1, k2, k1_next));
facets.emplace_back(k1, k2, k1_next);
}
if (i + 1 != stackCount) {
k2_next = (j + 1 == sectorCount) ? k2_first : (k2 + 1);
facets.emplace_back(Vec3crd(k1_next, k2, k2_next));
facets.emplace_back(k1_next, k2, k2_next);
}
k1 = k1_next;
k2 = k2_next;

View file

@ -22,7 +22,7 @@ class TriangleMesh
{
public:
TriangleMesh() : repaired(false) {}
TriangleMesh(const Pointf3s &points, const std::vector<Vec3crd> &facets);
TriangleMesh(const Pointf3s &points, const std::vector<Vec3i> &facets);
explicit TriangleMesh(const indexed_triangle_set &M);
void clear() { this->stl.clear(); this->its.clear(); this->repaired = false; }
bool ReadSTLFile(const char* input_file) { return stl_open(&stl, input_file); }

57
src/libslic3r/format.hpp Normal file
View file

@ -0,0 +1,57 @@
#ifndef slic3r_format_hpp_
#define slic3r_format_hpp_
// Functional wrapper around boost::format.
// One day we may replace this wrapper with C++20 format
// https://en.cppreference.com/w/cpp/utility/format/format
// though C++20 format uses a different template pattern for position independent parameters.
//
// Boost::format works around the missing variadic templates by an ugly % chaining operator. The usage of boost::format looks like this:
// (boost::format("template") % arg1 %arg2).str()
// This wrapper allows for a nicer syntax:
// Slic3r::format("template", arg1, arg2)
// One can also override Slic3r::internal::format::cook() function to convert a Slic3r::format() argument to something that
// boost::format may convert to string, see slic3r/GUI/I18N.hpp for a "cook" function to convert wxString to UTF8.
#include <boost/format.hpp>
namespace Slic3r {
// https://gist.github.com/gchudnov/6a90d51af004d97337ec
namespace internal {
namespace format {
// Default "cook" function - just forward.
template<typename T>
inline T&& cook(T&& arg) {
return std::forward<T>(arg);
}
// End of the recursive chain.
inline std::string format_recursive(boost::format& message) {
return message.str();
}
template<typename TValue, typename... TArgs>
std::string format_recursive(boost::format& message, TValue&& arg, TArgs&&... args) {
// Format, possibly convert the argument by the "cook" function.
message % cook(std::forward<TValue>(arg));
return format_recursive(message, std::forward<TArgs>(args)...);
}
}
};
template<typename... TArgs>
inline std::string format(const char* fmt, TArgs&&... args) {
boost::format message(fmt);
return internal::format::format_recursive(message, std::forward<TArgs>(args)...);
}
template<typename... TArgs>
inline std::string format(const std::string& fmt, TArgs&&... args) {
boost::format message(fmt);
return internal::format::format_recursive(message, std::forward<TArgs>(args)...);
}
} // namespace Slic3r
#endif // slic3r_format_hpp_

View file

@ -21,7 +21,13 @@
#include "Technologies.hpp"
#include "Semver.hpp"
#if 1
// Saves around 32% RAM after slicing step, 6.7% after G-code export (tested on PrusaSlicer 2.2.0 final).
typedef int32_t coord_t;
#else
typedef int64_t coord_t;
#endif
typedef double coordf_t;
//FIXME This epsilon value is used for many non-related purposes:
@ -33,6 +39,7 @@ typedef double coordf_t;
// This scaling generates a following fixed point representation with for a 32bit integer:
// 0..4294mm with 1nm resolution
// int32_t fits an interval of (-2147.48mm, +2147.48mm)
// with int64_t we don't have to worry anymore about the size of the int.
#define SCALING_FACTOR 0.000001
// RESOLUTION, SCALED_RESOLUTION: Used as an error threshold for a Douglas-Peucker polyline simplification algorithm.
#define RESOLUTION 0.0125
@ -98,7 +105,17 @@ extern Semver SEMVER;
template<typename T, typename Q>
inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); }
enum Axis { X=0, Y, Z, E, F, NUM_AXES };
enum Axis {
X=0,
Y,
Z,
E,
F,
NUM_AXES,
// For the GCodeReader to mark a parsed axis, which is not in "XYZEF", it was parsed correctly.
UNKNOWN_AXIS = NUM_AXES,
NUM_AXES_WITH_UNKNOWN,
};
template <class T>
inline void append_to(std::vector<T> &dst, const std::vector<T> &src)

View file

@ -111,6 +111,7 @@
#include "BoundingBox.hpp"
#include "ClipperUtils.hpp"
#include "Config.hpp"
#include "format.hpp"
#include "I18N.hpp"
#include "MultiPoint.hpp"
#include "Point.hpp"

View file

@ -12,7 +12,7 @@ PRODUCTVERSION @SLIC3R_RC_VERSION@
VALUE "ProductName", "@SLIC3R_APP_NAME@"
VALUE "ProductVersion", "@SLIC3R_BUILD_ID@"
VALUE "InternalName", "@SLIC3R_APP_NAME@"
VALUE "LegalCopyright", "Copyright \251 2016-2019 Prusa Research, \251 2011-2018 Alessandro Ranelucci"
VALUE "LegalCopyright", "Copyright \251 2016-2020 Prusa Research, \251 2011-2018 Alessandro Ranelucci"
VALUE "OriginalFilename", "prusa-slicer.exe"
}
}

View file

@ -5,7 +5,7 @@
<key>CFBundleExecutable</key>
<string>@SLIC3R_APP_KEY@</string>
<key>CFBundleGetInfoString</key>
<string>@SLIC3R_APP_NAME@ Copyright (C) 2011-2019 Alessandro Ranellucci, (C) 2016-2019 Prusa Reseach</string>
<string>@SLIC3R_APP_NAME@ Copyright (C) 2011-2019 Alessandro Ranellucci, (C) 2016-2020 Prusa Reseach</string>
<key>CFBundleIconFile</key>
<string>PrusaSlicer.icns</string>
<key>CFBundleName</key>

View file

@ -22,6 +22,7 @@ set(SLIC3R_GUI_SOURCES
GUI/ConfigSnapshotDialog.hpp
GUI/3DScene.cpp
GUI/3DScene.hpp
GUI/format.hpp
GUI/GLShader.cpp
GUI/GLShader.hpp
GUI/GLCanvas3D.hpp
@ -191,12 +192,16 @@ add_library(libslic3r_gui STATIC ${SLIC3R_GUI_SOURCES})
encoding_check(libslic3r_gui)
target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL OpenGL::GLU hidapi)
target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL OpenGL::GLU hidapi libcurl ${wxWidgets_LIBRARIES})
if(APPLE)
target_link_libraries(libslic3r_gui ${DISKARBITRATION_LIBRARY})
endif()
if (SLIC3R_STATIC AND UNIX AND NOT APPLE)
target_compile_definitions(libslic3r_gui PRIVATE OPENSSL_CERT_OVERRIDE)
endif ()
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE)
endif ()

View file

@ -5,11 +5,12 @@
#include <time.h>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/nowide/cstdio.hpp>
#include <boost/nowide/fstream.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#include <boost/filesystem/operations.hpp>
#include "libslic3r/libslic3r.h"
#include "libslic3r/Time.hpp"

View file

@ -6,7 +6,7 @@
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include "libslic3r/Semver.hpp"
#include "Version.hpp"
@ -18,7 +18,6 @@ class AppConfig;
namespace GUI {
namespace Config {
class Index;
// A snapshot contains:
// Slic3r.ini

View file

@ -2,8 +2,7 @@
#include <cctype>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/nowide/fstream.hpp>
#include "libslic3r/libslic3r.h"

View file

@ -4,7 +4,7 @@
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include "libslic3r/FileParserError.hpp"
#include "libslic3r/Semver.hpp"
@ -54,7 +54,7 @@ struct Version
class Index
{
public:
typedef std::vector<Version>::const_iterator const_iterator;
typedef std::vector<Version>::const_iterator const_iterator;
// Read a config index file in the simple format described in the Index class comment.
// Throws Slic3r::file_parser_error and the standard std file access exceptions.
size_t load(const boost::filesystem::path &path);

View file

@ -166,4 +166,4 @@ void Bed_2D::set_pos(const Vec2d& pos)
}
} // GUI
} // Slic3r
} // Slic3r

View file

@ -8,7 +8,6 @@
#include "GUI_App.hpp"
#include "PresetBundle.hpp"
#include "Gizmos/GLGizmoBase.hpp"
#include "GLCanvas3D.hpp"
#include <GL/glew.h>
@ -630,4 +629,4 @@ void Bed3D::reset()
}
} // GUI
} // Slic3r
} // Slic3r

View file

@ -17,23 +17,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <assert.h>
#include <boost/log/trivial.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/nowide/cstdio.hpp>
#include <tbb/parallel_for.h>
#include <tbb/spin_mutex.h>
#include <Eigen/Dense>
#include "GUI.hpp"
#ifdef HAS_GLSAFE
void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char *function_name)
{
@ -400,6 +394,7 @@ void GLVolume::render() const
glFrontFace(GL_CCW);
}
#if !ENABLE_SLOPE_RENDERING
void GLVolume::render(int color_id, int detection_id, int worldmatrix_id) const
{
if (color_id >= 0)
@ -415,6 +410,7 @@ void GLVolume::render(int color_id, int detection_id, int worldmatrix_id) const
render();
}
#endif // !ENABLE_SLOPE_RENDERING
bool GLVolume::is_sla_support() const { return this->composite_id.volume_id == -int(slaposSupportTree); }
bool GLVolume::is_sla_pad() const { return this->composite_id.volume_id == -int(slaposPad); }
@ -541,16 +537,16 @@ int GLVolumeCollection::load_wipe_tower_preview(
// We'll now create the box with jagged edge. y-coordinates of the pre-generated model are shifted so that the front
// edge has y=0 and centerline of the back edge has y=depth:
Pointf3s points;
std::vector<Vec3crd> facets;
std::vector<Vec3i> facets;
float out_points_idx[][3] = { { 0, -depth, 0 }, { 0, 0, 0 }, { 38.453f, 0, 0 }, { 61.547f, 0, 0 }, { 100.0f, 0, 0 }, { 100.0f, -depth, 0 }, { 55.7735f, -10.0f, 0 }, { 44.2265f, 10.0f, 0 },
{ 38.453f, 0, 1 }, { 0, 0, 1 }, { 0, -depth, 1 }, { 100.0f, -depth, 1 }, { 100.0f, 0, 1 }, { 61.547f, 0, 1 }, { 55.7735f, -10.0f, 1 }, { 44.2265f, 10.0f, 1 } };
int out_facets_idx[][3] = { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 5, 0 }, { 3, 5, 6 }, { 6, 2, 7 }, { 6, 0, 2 }, { 8, 9, 10 }, { 11, 12, 13 }, { 10, 11, 14 }, { 14, 11, 13 }, { 15, 8, 14 },
{8, 10, 14}, {3, 12, 4}, {3, 13, 12}, {6, 13, 3}, {6, 14, 13}, {7, 14, 6}, {7, 15, 14}, {2, 15, 7}, {2, 8, 15}, {1, 8, 2}, {1, 9, 8},
{0, 9, 1}, {0, 10, 9}, {5, 10, 0}, {5, 11, 10}, {4, 11, 5}, {4, 12, 11} };
for (int i = 0; i < 16; ++i)
points.push_back(Vec3d(out_points_idx[i][0] / (100.f / min_width), out_points_idx[i][1] + depth, out_points_idx[i][2]));
points.emplace_back(out_points_idx[i][0] / (100.f / min_width), out_points_idx[i][1] + depth, out_points_idx[i][2]);
for (int i = 0; i < 28; ++i)
facets.push_back(Vec3crd(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2]));
facets.emplace_back(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2]);
TriangleMesh tooth_mesh(points, facets);
// We have the mesh ready. It has one tooth and width of min_width. We will now append several of these together until we are close to
@ -656,28 +652,64 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1;
GLint z_range_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "z_range") : -1;
GLint clipping_plane_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "clipping_plane") : -1;
GLint print_box_min_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.min") : -1;
GLint print_box_max_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.max") : -1;
GLint print_box_detection_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_detection") : -1;
GLint print_box_active_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.actived") : -1;
GLint print_box_worldmatrix_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_world_matrix") : -1;
#if ENABLE_SLOPE_RENDERING
GLint slope_active_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "slope.actived") : -1;
GLint slope_normal_matrix_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "slope.volume_world_normal_matrix") : -1;
GLint slope_z_range_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "slope.z_range") : -1;
#endif // ENABLE_SLOPE_RENDERING
glcheck();
if (print_box_min_id != -1)
glsafe(::glUniform3fv(print_box_min_id, 1, (const GLfloat*)print_box_min));
glsafe(::glUniform3fv(print_box_min_id, 1, (const GLfloat*)m_print_box_min));
if (print_box_max_id != -1)
glsafe(::glUniform3fv(print_box_max_id, 1, (const GLfloat*)print_box_max));
glsafe(::glUniform3fv(print_box_max_id, 1, (const GLfloat*)m_print_box_max));
if (z_range_id != -1)
glsafe(::glUniform2fv(z_range_id, 1, (const GLfloat*)z_range));
glsafe(::glUniform2fv(z_range_id, 1, (const GLfloat*)m_z_range));
if (clipping_plane_id != -1)
glsafe(::glUniform4fv(clipping_plane_id, 1, (const GLfloat*)clipping_plane));
glsafe(::glUniform4fv(clipping_plane_id, 1, (const GLfloat*)m_clipping_plane));
#if ENABLE_SLOPE_RENDERING
if (slope_z_range_id != -1)
glsafe(::glUniform2fv(slope_z_range_id, 1, (const GLfloat*)m_slope.z_range.data()));
#endif // ENABLE_SLOPE_RENDERING
GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func);
for (GLVolumeWithIdAndZ& volume : to_render) {
volume.first->set_render_color();
#if ENABLE_SLOPE_RENDERING
if (color_id >= 0)
glsafe(::glUniform4fv(color_id, 1, (const GLfloat*)volume.first->render_color));
else
glsafe(::glColor4fv(volume.first->render_color));
if (print_box_active_id != -1)
glsafe(::glUniform1i(print_box_active_id, volume.first->shader_outside_printer_detection_enabled ? 1 : 0));
if (print_box_worldmatrix_id != -1)
glsafe(::glUniformMatrix4fv(print_box_worldmatrix_id, 1, GL_FALSE, (const GLfloat*)volume.first->world_matrix().cast<float>().data()));
if (slope_active_id != -1)
glsafe(::glUniform1i(slope_active_id, m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower ? 1 : 0));
if (slope_normal_matrix_id != -1)
{
Matrix3f normal_matrix = volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast<float>();
glsafe(::glUniformMatrix3fv(slope_normal_matrix_id, 1, GL_FALSE, (const GLfloat*)normal_matrix.data()));
}
volume.first->render();
#else
volume.first->render(color_id, print_box_detection_id, print_box_worldmatrix_id);
#endif // ENABLE_SLOPE_RENDERING
}
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
@ -1822,7 +1854,9 @@ void _3DScene::point3_to_verts(const Vec3crd& point, double width, double height
thick_point_to_verts(point, width, height, volume);
}
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
GUI::GLCanvas3DManager _3DScene::s_canvas_mgr;
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
GLModel::GLModel()
: m_filename("")
@ -1891,7 +1925,16 @@ void GLModel::render() const
GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1;
glcheck();
#if ENABLE_SLOPE_RENDERING
if (color_id >= 0)
glsafe(::glUniform4fv(color_id, 1, (const GLfloat*)m_volume.render_color));
else
glsafe(::glColor4fv(m_volume.render_color));
m_volume.render();
#else
m_volume.render(color_id, -1, -1);
#endif // ENABLE_SLOPE_RENDERING
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
@ -1905,7 +1948,7 @@ void GLModel::render() const
bool GLArrow::on_init()
{
Pointf3s vertices;
std::vector<Vec3crd> triangles;
std::vector<Vec3i> triangles;
// bottom face
vertices.emplace_back(0.5, 0.0, -0.1);
@ -1971,7 +2014,7 @@ GLCurvedArrow::GLCurvedArrow(unsigned int resolution)
bool GLCurvedArrow::on_init()
{
Pointf3s vertices;
std::vector<Vec3crd> triangles;
std::vector<Vec3i> triangles;
double ext_radius = 2.5;
double int_radius = 1.5;
@ -2105,6 +2148,7 @@ bool GLBed::on_init_from_file(const std::string& filename)
return true;
}
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
std::string _3DScene::get_gl_info(bool format_as_html, bool extensions)
{
return Slic3r::GUI::GLCanvas3DManager::get_gl_info().to_string(format_as_html, extensions);
@ -2139,5 +2183,6 @@ GUI::GLCanvas3D* _3DScene::get_canvas(wxGLCanvas* canvas)
{
return s_canvas_mgr.get_canvas(canvas);
}
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
} // namespace Slic3r

View file

@ -7,10 +7,11 @@
#include "libslic3r/TriangleMesh.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/Model.hpp"
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
#include "slic3r/GUI/GLCanvas3DManager.hpp"
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
#include <functional>
#include <memory>
#ifndef NDEBUG
#define HAS_GLSAFE
@ -34,13 +35,8 @@ struct Camera;
class GLToolbar;
} // namespace GUI
class Print;
class PrintObject;
class SLAPrint;
class SLAPrintObject;
enum SLAPrintObjectStep : unsigned int;
class Model;
class ModelObject;
class DynamicPrintConfig;
class ExtrusionPath;
class ExtrusionMultiPath;
@ -449,7 +445,9 @@ public:
void set_range(double low, double high);
void render() const;
#if !ENABLE_SLOPE_RENDERING
void render(int color_id, int detection_id, int worldmatrix_id) const;
#endif // !ENABLE_SLOPE_RENDERING
void finalize_geometry(bool opengl_initialized) { this->indexed_vertex_array.finalize_geometry(opengl_initialized); }
void release_geometry() { this->indexed_vertex_array.release_geometry(); }
@ -485,20 +483,36 @@ public:
private:
// min and max vertex of the print box volume
float print_box_min[3];
float print_box_max[3];
float m_print_box_min[3];
float m_print_box_max[3];
// z range for clipping in shaders
float z_range[2];
float m_z_range[2];
// plane coeffs for clipping in shaders
float clipping_plane[4];
float m_clipping_plane[4];
#if ENABLE_SLOPE_RENDERING
struct Slope
{
// toggle for slope rendering
bool active{ false };
// [0] = yellow, [1] = red
std::array<float, 2> z_range;
};
Slope m_slope;
#endif // ENABLE_SLOPE_RENDERING
public:
GLVolumePtrs volumes;
GLVolumeCollection() {};
~GLVolumeCollection() { clear(); };
#if ENABLE_SLOPE_RENDERING
GLVolumeCollection() { set_default_slope_z_range(); }
#else
GLVolumeCollection() = default;
#endif // ENABLE_SLOPE_RENDERING
~GLVolumeCollection() { clear(); }
std::vector<int> load_object(
const ModelObject *model_object,
@ -549,12 +563,21 @@ public:
void set_range(double low, double high) { for (GLVolume *vol : this->volumes) vol->set_range(low, high); }
void set_print_box(float min_x, float min_y, float min_z, float max_x, float max_y, float max_z) {
print_box_min[0] = min_x; print_box_min[1] = min_y; print_box_min[2] = min_z;
print_box_max[0] = max_x; print_box_max[1] = max_y; print_box_max[2] = max_z;
m_print_box_min[0] = min_x; m_print_box_min[1] = min_y; m_print_box_min[2] = min_z;
m_print_box_max[0] = max_x; m_print_box_max[1] = max_y; m_print_box_max[2] = max_z;
}
void set_z_range(float min_z, float max_z) { z_range[0] = min_z; z_range[1] = max_z; }
void set_clipping_plane(const double* coeffs) { clipping_plane[0] = coeffs[0]; clipping_plane[1] = coeffs[1]; clipping_plane[2] = coeffs[2]; clipping_plane[3] = coeffs[3]; }
void set_z_range(float min_z, float max_z) { m_z_range[0] = min_z; m_z_range[1] = max_z; }
void set_clipping_plane(const double* coeffs) { m_clipping_plane[0] = coeffs[0]; m_clipping_plane[1] = coeffs[1]; m_clipping_plane[2] = coeffs[2]; m_clipping_plane[3] = coeffs[3]; }
#if ENABLE_SLOPE_RENDERING
bool is_slope_active() const { return m_slope.active; }
void set_slope_active(bool active) { m_slope.active = active; }
const std::array<float, 2>& get_slope_z_range() const { return m_slope.z_range; }
void set_slope_z_range(const std::array<float, 2>& range) { m_slope.z_range = range; }
void set_default_slope_z_range() { m_slope.z_range = { -::cos(Geometry::deg2rad(90.0f - 45.0f)), -::cos(Geometry::deg2rad(90.0f - 70.0f)) }; }
#endif // ENABLE_SLOPE_RENDERING
// returns true if all the volumes are completely contained in the print volume
// returns the containment state in the given out_state, if non-null
@ -645,10 +668,17 @@ protected:
bool on_init_from_file(const std::string& filename) override;
};
#if ENABLE_NON_STATIC_CANVAS_MANAGER
struct _3DScene
#else
class _3DScene
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
{
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
static GUI::GLCanvas3DManager s_canvas_mgr;
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
public:
static std::string get_gl_info(bool format_as_html, bool extensions);
@ -660,6 +690,7 @@ public:
static void destroy();
static GUI::GLCanvas3D* get_canvas(wxGLCanvas* canvas);
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
static void thick_lines_to_verts(const Lines& lines, const std::vector<double>& widths, const std::vector<double>& heights, bool closed, double top_z, GLVolume& volume);
static void thick_lines_to_verts(const Lines3& lines, const std::vector<double>& widths, const std::vector<double>& heights, bool closed, GLVolume& volume);

View file

@ -2,8 +2,9 @@
#include "I18N.hpp"
#include "libslic3r/Utils.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "wxExtensions.hpp"
namespace Slic3r {
namespace GUI {
@ -266,7 +267,7 @@ AboutDialog::AboutDialog()
"<html>"
"<body bgcolor= %1% link= %2%>"
"<font color=%3%>"
"%4% &copy; 2016-2019 Prusa Research. <br />"
"%4% &copy; 2016-2020 Prusa Research. <br />"
"%5% &copy; 2011-2018 Alessandro Ranellucci. <br />"
"<a href=\"http://slic3r.org/\">Slic3r</a> %6% "
"<a href=\"http://www.gnu.org/licenses/agpl-3.0.html\">%7%</a>."

View file

@ -1,8 +1,6 @@
#ifndef slic3r_GUI_AboutDialog_hpp_
#define slic3r_GUI_AboutDialog_hpp_
#include "GUI.hpp"
#include <wx/wx.h>
#include <wx/intl.h>
#include <wx/html/htmlwin.h>

View file

@ -2,22 +2,18 @@
#include "libslic3r/Utils.hpp"
#include "AppConfig.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <assert.h>
#include <vector>
#include <stdexcept>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/nowide/cenv.hpp>
#include <boost/nowide/fstream.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/exceptions.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/format.hpp>
#include <boost/format/format_fwd.hpp>
#include <wx/string.h>
#include "I18N.hpp"
@ -76,7 +72,7 @@ void AppConfig::set_defaults()
if (get("remember_output_path").empty())
set("remember_output_path", "1");
if (get("remember_output_path_removable").empty())
if (get("remember_output_path_removable").empty())
set("remember_output_path_removable", "1");
if (get("use_custom_toolbar_size").empty())
@ -280,7 +276,7 @@ void AppConfig::set_recent_projects(const std::vector<std::string>& recent_proje
}
}
void AppConfig::set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed)
void AppConfig::set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed, bool swap_yz)
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
@ -293,81 +289,18 @@ void AppConfig::set_mouse_device(const std::string& name, double translation_spe
it->second["rotation_speed"] = std::to_string(rotation_speed);
it->second["rotation_deadzone"] = std::to_string(rotation_deadzone);
it->second["zoom_speed"] = std::to_string(zoom_speed);
it->second["swap_yz"] = swap_yz ? "1" : "0";
}
bool AppConfig::get_mouse_device_translation_speed(const std::string& name, double& speed)
std::vector<std::string> AppConfig::get_mouse_device_names() const
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
if (it == m_storage.end())
return false;
auto it_val = it->second.find("translation_speed");
if (it_val == it->second.end())
return false;
speed = ::atof(it_val->second.c_str());
return true;
}
bool AppConfig::get_mouse_device_translation_deadzone(const std::string& name, double& deadzone)
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
if (it == m_storage.end())
return false;
auto it_val = it->second.find("translation_deadzone");
if (it_val == it->second.end())
return false;
deadzone = ::atof(it_val->second.c_str());
return true;
}
bool AppConfig::get_mouse_device_rotation_speed(const std::string& name, float& speed)
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
if (it == m_storage.end())
return false;
auto it_val = it->second.find("rotation_speed");
if (it_val == it->second.end())
return false;
speed = (float)::atof(it_val->second.c_str());
return true;
}
bool AppConfig::get_mouse_device_rotation_deadzone(const std::string& name, float& deadzone)
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
if (it == m_storage.end())
return false;
auto it_val = it->second.find("rotation_deadzone");
if (it_val == it->second.end())
return false;
deadzone = (float)::atof(it_val->second.c_str());
return true;
}
bool AppConfig::get_mouse_device_zoom_speed(const std::string& name, double& speed)
{
std::string key = std::string("mouse_device:") + name;
auto it = m_storage.find(key);
if (it == m_storage.end())
return false;
auto it_val = it->second.find("zoom_speed");
if (it_val == it->second.end())
return false;
speed = (float)::atof(it_val->second.c_str());
return true;
static constexpr char *prefix = "mouse_device:";
static constexpr size_t prefix_len = 13; // strlen(prefix); reports error C2131: expression did not evaluate to a constant on VS2019
std::vector<std::string> out;
for (const std::pair<std::string, std::map<std::string, std::string>>& key_value_pair : m_storage)
if (boost::starts_with(key_value_pair.first, "mouse_device:") && key_value_pair.first.size() > prefix_len)
out.emplace_back(key_value_pair.first.substr(prefix_len));
return out;
}
void AppConfig::update_config_dir(const std::string &dir)

View file

@ -5,6 +5,8 @@
#include <map>
#include <string>
#include <boost/algorithm/string/trim_all.hpp>
#include "libslic3r/Config.hpp"
#include "libslic3r/Semver.hpp"
@ -52,7 +54,13 @@ public:
std::string get(const std::string &key) const
{ std::string value; this->get("", key, value); return value; }
void set(const std::string &section, const std::string &key, const std::string &value)
{
{
#ifndef _NDEBUG
std::string key_trimmed = key;
boost::trim_all(key_trimmed);
assert(key_trimmed == key);
assert(! key_trimmed.empty());
#endif _NDEBUG
std::string &old = m_storage[section][key];
if (old != value) {
old = value;
@ -133,17 +141,39 @@ public:
std::vector<std::string> get_recent_projects() const;
void set_recent_projects(const std::vector<std::string>& recent_projects);
void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed);
bool get_mouse_device_translation_speed(const std::string& name, double& speed);
bool get_mouse_device_translation_deadzone(const std::string& name, double& deadzone);
bool get_mouse_device_rotation_speed(const std::string& name, float& speed);
bool get_mouse_device_rotation_deadzone(const std::string& name, float& deadzone);
bool get_mouse_device_zoom_speed(const std::string& name, double& speed);
void set_mouse_device(const std::string& name, double translation_speed, double translation_deadzone, float rotation_speed, float rotation_deadzone, double zoom_speed, bool swap_yz);
std::vector<std::string> get_mouse_device_names() const;
bool get_mouse_device_translation_speed(const std::string& name, double& speed) const
{ return get_3dmouse_device_numeric_value(name, "translation_speed", speed); }
bool get_mouse_device_translation_deadzone(const std::string& name, double& deadzone) const
{ return get_3dmouse_device_numeric_value(name, "translation_deadzone", deadzone); }
bool get_mouse_device_rotation_speed(const std::string& name, float& speed) const
{ return get_3dmouse_device_numeric_value(name, "rotation_speed", speed); }
bool get_mouse_device_rotation_deadzone(const std::string& name, float& deadzone) const
{ return get_3dmouse_device_numeric_value(name, "rotation_deadzone", deadzone); }
bool get_mouse_device_zoom_speed(const std::string& name, double& speed) const
{ return get_3dmouse_device_numeric_value(name, "zoom_speed", speed); }
bool get_mouse_device_swap_yz(const std::string& name, bool& swap) const
{ return get_3dmouse_device_numeric_value(name, "swap_yz", swap); }
static const std::string SECTION_FILAMENTS;
static const std::string SECTION_MATERIALS;
private:
template<typename T>
bool get_3dmouse_device_numeric_value(const std::string &device_name, const char *parameter_name, T &out) const
{
std::string key = std::string("mouse_device:") + device_name;
auto it = m_storage.find(key);
if (it == m_storage.end())
return false;
auto it_val = it->second.find(parameter_name);
if (it_val == it->second.end())
return false;
out = T(::atof(it_val->second.c_str()));
return true;
}
// Map of section, name -> value
std::map<std::string, std::map<std::string, std::string>> m_storage;
// Map of enabled vendors / models / variants

View file

@ -11,9 +11,7 @@
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
#if ENABLE_THUMBNAIL_GENERATOR
#include <miniz.h>
#endif // ENABLE_THUMBNAIL_GENERATOR
// Print now includes tbb, and tbb includes Windows. This breaks compilation of wxWidgets if included before wx.
#include "libslic3r/Print.hpp"
@ -26,17 +24,16 @@
#include <cassert>
#include <stdexcept>
#include <cctype>
#include <algorithm>
#include <boost/format.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem.hpp>
#include <boost/format/format_fwd.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/log/trivial.hpp>
#include <boost/nowide/cstdio.hpp>
#include "I18N.hpp"
#include "GUI.hpp"
#include "RemovableDriveManager.hpp"
#include "slic3r/Utils/Thread.hpp"
namespace Slic3r {
BackgroundSlicingProcess::BackgroundSlicingProcess()
@ -90,21 +87,15 @@ void BackgroundSlicingProcess::process_fff()
assert(m_print == m_fff_print);
m_print->process();
wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, new wxCommandEvent(m_event_slicing_completed_id));
#if ENABLE_THUMBNAIL_GENERATOR
m_fff_print->export_gcode(m_temp_output_path, m_gcode_preview_data, m_thumbnail_cb);
#else
m_fff_print->export_gcode(m_temp_output_path, m_gcode_preview_data);
#endif // ENABLE_THUMBNAIL_GENERATOR
if (this->set_step_started(bspsGCodeFinalize)) {
if (! m_export_path.empty()) {
//FIXME localize the messages
// Perform the final post-processing of the export path by applying the print statistics over the file name.
std::string export_path = m_fff_print->print_statistics().finalize_output_path(m_export_path);
GUI::RemovableDriveManager::get_instance().update();
bool with_check = GUI::RemovableDriveManager::get_instance().is_path_on_removable_drive(export_path);
int copy_ret_val = copy_file(m_temp_output_path, export_path, with_check);
switch (copy_ret_val){
int copy_ret_val = copy_file(m_temp_output_path, export_path, m_export_path_on_removable_media);
switch (copy_ret_val) {
case SUCCESS: break; // no error
case FAIL_COPY_FILE:
throw std::runtime_error(_utf8(L("Copying of the temporary G-code to the output G-code failed. Maybe the SD card is write locked?")));
@ -138,7 +129,6 @@ void BackgroundSlicingProcess::process_fff()
}
}
#if ENABLE_THUMBNAIL_GENERATOR
static void write_thumbnail(Zipper& zipper, const ThumbnailData& data)
{
size_t png_size = 0;
@ -149,7 +139,6 @@ static void write_thumbnail(Zipper& zipper, const ThumbnailData& data)
mz_free(png_data);
}
}
#endif // ENABLE_THUMBNAIL_GENERATOR
void BackgroundSlicingProcess::process_sla()
{
@ -162,7 +151,6 @@ void BackgroundSlicingProcess::process_sla()
Zipper zipper(export_path);
m_sla_print->export_raster(zipper);
#if ENABLE_THUMBNAIL_GENERATOR
if (m_thumbnail_cb != nullptr)
{
ThumbnailsList thumbnails;
@ -174,7 +162,6 @@ void BackgroundSlicingProcess::process_sla()
write_thumbnail(zipper, data);
}
}
#endif // ENABLE_THUMBNAIL_GENERATOR
zipper.finalize();
@ -236,7 +223,7 @@ void BackgroundSlicingProcess::thread_proc()
// Only post the canceled event, if canceled by user.
// Don't post the canceled event, if canceled from Print::apply().
wxCommandEvent evt(m_event_finished_id);
evt.SetString(error);
evt.SetString(GUI::from_u8(error));
evt.SetInt(m_print->canceled() ? -1 : (error.empty() ? 1 : 0));
wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, evt.Clone());
}
@ -403,7 +390,7 @@ void BackgroundSlicingProcess::set_task(const PrintBase::TaskParams &params)
}
// Set the output path of the G-code.
void BackgroundSlicingProcess::schedule_export(const std::string &path)
void BackgroundSlicingProcess::schedule_export(const std::string &path, bool export_path_on_removable_media)
{
assert(m_export_path.empty());
if (! m_export_path.empty())
@ -413,6 +400,7 @@ void BackgroundSlicingProcess::schedule_export(const std::string &path)
tbb::mutex::scoped_lock lock(m_print->state_mutex());
this->invalidate_step(bspsGCodeFinalize);
m_export_path = path;
m_export_path_on_removable_media = export_path_on_removable_media;
}
void BackgroundSlicingProcess::schedule_upload(Slic3r::PrintHostJob upload_job)
@ -433,6 +421,7 @@ void BackgroundSlicingProcess::reset_export()
assert(! this->running());
if (! this->running()) {
m_export_path.clear();
m_export_path_on_removable_media = false;
// invalidate_step expects the mutex to be locked.
tbb::mutex::scoped_lock lock(m_print->state_mutex());
this->invalidate_step(bspsGCodeFinalize);
@ -487,7 +476,6 @@ void BackgroundSlicingProcess::prepare_upload()
Zipper zipper{source_path.string()};
m_sla_print->export_raster(zipper, m_upload_job.upload_data.upload_path.string());
#if ENABLE_THUMBNAIL_GENERATOR
if (m_thumbnail_cb != nullptr)
{
ThumbnailsList thumbnails;
@ -499,7 +487,6 @@ void BackgroundSlicingProcess::prepare_upload()
write_thumbnail(zipper, data);
}
}
#endif // ENABLE_THUMBNAIL_GENERATOR
zipper.finalize();
}

View file

@ -5,13 +5,13 @@
#include <condition_variable>
#include <mutex>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <wx/event.h>
#include "libslic3r/Print.hpp"
#include "slic3r/Utils/PrintHost.hpp"
#include "slic3r/Utils/Thread.hpp"
namespace Slic3r {
@ -49,9 +49,7 @@ public:
void set_fff_print(Print *print) { m_fff_print = print; }
void set_sla_print(SLAPrint *print) { m_sla_print = print; }
void set_gcode_preview_data(GCodePreviewData *gpd) { m_gcode_preview_data = gpd; }
#if ENABLE_THUMBNAIL_GENERATOR
void set_thumbnail_cb(ThumbnailsGeneratorCallback cb) { m_thumbnail_cb = cb; }
#endif // ENABLE_THUMBNAIL_GENERATOR
// The following wxCommandEvent will be sent to the UI thread / Plater window, when the slicing is finished
// and the background processing will transition into G-code export.
@ -98,7 +96,7 @@ public:
// Set the export path of the G-code.
// Once the path is set, the G-code
void schedule_export(const std::string &path);
void schedule_export(const std::string &path, bool export_path_on_removable_media);
// Set print host upload job data to be enqueued to the PrintHostJobQueue
// after current print slicing is complete
void schedule_upload(Slic3r::PrintHostJob upload_job);
@ -155,15 +153,14 @@ private:
SLAPrint *m_sla_print = nullptr;
// Data structure, to which the G-code export writes its annotations.
GCodePreviewData *m_gcode_preview_data = nullptr;
#if ENABLE_THUMBNAIL_GENERATOR
// Callback function, used to write thumbnails into gcode.
ThumbnailsGeneratorCallback m_thumbnail_cb = nullptr;
#endif // ENABLE_THUMBNAIL_GENERATOR
ThumbnailsGeneratorCallback m_thumbnail_cb = nullptr;
// Temporary G-code, there is one defined for the BackgroundSlicingProcess, differentiated from the other processes by a process ID.
std::string m_temp_output_path;
// Output path provided by the user. The output path may be set even if the slicing is running,
// but once set, it cannot be re-set.
std::string m_export_path;
bool m_export_path_on_removable_media = false;
// Print host upload job to schedule after slicing is complete, used by schedule_upload(),
// empty by default (ie. no upload to schedule)
PrintHostJob m_upload_job;

View file

@ -1,9 +1,6 @@
#include "libslic3r/libslic3r.h"
#include "Camera.hpp"
#if !ENABLE_THUMBNAIL_GENERATOR
#include "3DScene.hpp"
#endif // !ENABLE_THUMBNAIL_GENERATOR
#include "GUI_App.hpp"
#include "AppConfig.hpp"
#if ENABLE_CAMERA_STATISTICS
@ -25,10 +22,8 @@ namespace Slic3r {
namespace GUI {
const double Camera::DefaultDistance = 1000.0;
#if ENABLE_THUMBNAIL_GENERATOR
const double Camera::DefaultZoomToBoxMarginFactor = 1.025;
const double Camera::DefaultZoomToVolumesMarginFactor = 1.025;
#endif // ENABLE_THUMBNAIL_GENERATOR
double Camera::FrustrumMinZRange = 50.0;
double Camera::FrustrumMinNearZ = 100.0;
double Camera::FrustrumZMargin = 10.0;
@ -219,18 +214,10 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa
glsafe(::glMatrixMode(GL_MODELVIEW));
}
#if ENABLE_THUMBNAIL_GENERATOR
void Camera::zoom_to_box(const BoundingBoxf3& box, double margin_factor)
#else
void Camera::zoom_to_box(const BoundingBoxf3& box, int canvas_w, int canvas_h)
#endif // ENABLE_THUMBNAIL_GENERATOR
{
// Calculate the zoom factor needed to adjust the view around the given box.
#if ENABLE_THUMBNAIL_GENERATOR
double zoom = calc_zoom_to_bounding_box_factor(box, margin_factor);
#else
double zoom = calc_zoom_to_bounding_box_factor(box, canvas_w, canvas_h);
#endif // ENABLE_THUMBNAIL_GENERATOR
if (zoom > 0.0)
{
m_zoom = zoom;
@ -239,7 +226,6 @@ void Camera::zoom_to_box(const BoundingBoxf3& box, int canvas_w, int canvas_h)
}
}
#if ENABLE_THUMBNAIL_GENERATOR
void Camera::zoom_to_volumes(const GLVolumePtrs& volumes, double margin_factor)
{
Vec3d center;
@ -251,7 +237,6 @@ void Camera::zoom_to_volumes(const GLVolumePtrs& volumes, double margin_factor)
set_target(center);
}
}
#endif // ENABLE_THUMBNAIL_GENERATOR
#if ENABLE_CAMERA_STATISTICS
void Camera::debug_render() const
@ -260,7 +245,7 @@ void Camera::debug_render() const
imgui.begin(std::string("Camera statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
std::string type = get_type_as_string();
if (wxGetApp().plater()->get_mouse3d_controller().is_running() || (wxGetApp().app_config->get("use_free_camera") == "1"))
if (wxGetApp().plater()->get_mouse3d_controller().connected() || (wxGetApp().app_config->get("use_free_camera") == "1"))
type += "/free";
else
type += "/constrained";
@ -387,11 +372,7 @@ std::pair<double, double> Camera::calc_tight_frustrum_zs_around(const BoundingBo
return ret;
}
#if ENABLE_THUMBNAIL_GENERATOR
double Camera::calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, double margin_factor) const
#else
double Camera::calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, int canvas_w, int canvas_h) const
#endif // ENABLE_THUMBNAIL_GENERATOR
{
double max_bb_size = box.max_size();
if (max_bb_size == 0.0)
@ -423,11 +404,6 @@ double Camera::calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, int ca
double max_x = -DBL_MAX;
double max_y = -DBL_MAX;
#if !ENABLE_THUMBNAIL_GENERATOR
// margin factor to give some empty space around the box
double margin_factor = 1.25;
#endif // !ENABLE_THUMBNAIL_GENERATOR
for (const Vec3d& v : vertices)
{
// project vertex on the plane perpendicular to camera forward axis
@ -458,7 +434,6 @@ double Camera::calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, int ca
return std::min((double)m_viewport[2] / dx, (double)m_viewport[3] / dy);
}
#if ENABLE_THUMBNAIL_GENERATOR
double Camera::calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& center, double margin_factor) const
{
if (volumes.empty())
@ -519,7 +494,6 @@ double Camera::calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& c
return std::min((double)m_viewport[2] / dx, (double)m_viewport[3] / dy);
}
#endif // ENABLE_THUMBNAIL_GENERATOR
void Camera::set_distance(double distance) const
{
@ -537,6 +511,7 @@ void Camera::look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up
Vec3d unit_y = unit_z.cross(unit_x).normalized();
m_target = target;
m_distance = (position - target).norm();
Vec3d new_position = m_target + m_distance * unit_z;
m_view_matrix(0, 0) = unit_x(0);

View file

@ -2,9 +2,7 @@
#define slic3r_Camera_hpp_
#include "libslic3r/BoundingBox.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
#include "3DScene.hpp"
#endif // ENABLE_THUMBNAIL_GENERATOR
#include <array>
namespace Slic3r {
@ -13,10 +11,8 @@ namespace GUI {
struct Camera
{
static const double DefaultDistance;
#if ENABLE_THUMBNAIL_GENERATOR
static const double DefaultZoomToBoxMarginFactor;
static const double DefaultZoomToVolumesMarginFactor;
#endif // ENABLE_THUMBNAIL_GENERATOR
static double FrustrumMinZRange;
static double FrustrumMinNearZ;
static double FrustrumZMargin;
@ -97,12 +93,8 @@ public:
// If larger z span is needed, pass the desired values of near and far z (negative values are ignored)
void apply_projection(const BoundingBoxf3& box, double near_z = -1.0, double far_z = -1.0) const;
#if ENABLE_THUMBNAIL_GENERATOR
void zoom_to_box(const BoundingBoxf3& box, double margin_factor = DefaultZoomToBoxMarginFactor);
void zoom_to_volumes(const GLVolumePtrs& volumes, double margin_factor = DefaultZoomToVolumesMarginFactor);
#else
void zoom_to_box(const BoundingBoxf3& box, int canvas_w, int canvas_h);
#endif // ENABLE_THUMBNAIL_GENERATOR
#if ENABLE_CAMERA_STATISTICS
void debug_render() const;
@ -122,6 +114,15 @@ public:
// returns true if the camera z axis (forward) is pointing in the negative direction of the world z axis
bool is_looking_downward() const { return get_dir_forward().dot(Vec3d::UnitZ()) < 0.0; }
// forces camera right vector to be parallel to XY plane
void recover_from_free_camera()
{
if (std::abs(get_dir_right()(2)) > EPSILON)
look_at(get_position(), m_target, Vec3d::UnitZ());
}
void look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up);
double max_zoom() const { return 100.0; }
double min_zoom() const;
@ -129,15 +130,10 @@ private:
// returns tight values for nearZ and farZ plane around the given bounding box
// the camera MUST be outside of the bounding box in eye coordinate of the given box
std::pair<double, double> calc_tight_frustrum_zs_around(const BoundingBoxf3& box) const;
#if ENABLE_THUMBNAIL_GENERATOR
double calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, double margin_factor = DefaultZoomToBoxMarginFactor) const;
double calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& center, double margin_factor = DefaultZoomToVolumesMarginFactor) const;
#else
double calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, int canvas_w, int canvas_h) const;
#endif // ENABLE_THUMBNAIL_GENERATOR
void set_distance(double distance) const;
void look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up);
void set_default_orientation();
Vec3d validate_target(const Vec3d& target) const;
void update_zenit();

View file

@ -268,8 +268,9 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config)
"bridge_acceleration", "first_layer_acceleration" })
toggle_field(el, have_default_acceleration);
bool have_skirt = config->opt_int("skirts") > 0 || config->opt_float("min_skirt_length") > 0;
for (auto el : { "skirt_distance", "skirt_height" })
bool have_skirt = config->opt_int("skirts") > 0;
toggle_field("skirt_height", have_skirt && !config->opt_bool("draft_shield"));
for (auto el : { "skirt_distance", "draft_shield", "min_skirt_length" })
toggle_field(el, have_skirt);
bool have_brim = config->opt_float("brim_width") > 0;

View file

@ -42,16 +42,27 @@ using Config::SnapshotDB;
// Configuration data structures extensions needed for the wizard
Bundle::Bundle(fs::path source_path, bool is_in_resources, bool is_prusa_bundle)
: preset_bundle(new PresetBundle)
, vendor_profile(nullptr)
, is_in_resources(is_in_resources)
, is_prusa_bundle(is_prusa_bundle)
bool Bundle::load(fs::path source_path, bool ais_in_resources, bool ais_prusa_bundle)
{
preset_bundle->load_configbundle(source_path.string(), PresetBundle::LOAD_CFGBNDLE_SYSTEM);
this->preset_bundle = std::make_unique<PresetBundle>();
this->is_in_resources = ais_in_resources;
this->is_prusa_bundle = ais_prusa_bundle;
std::string path_string = source_path.string();
size_t presets_loaded = preset_bundle->load_configbundle(path_string, PresetBundle::LOAD_CFGBNDLE_SYSTEM);
auto first_vendor = preset_bundle->vendors.begin();
wxCHECK_RET(first_vendor != preset_bundle->vendors.end(), "Failed to load preset bundle");
vendor_profile = &first_vendor->second;
if (first_vendor == preset_bundle->vendors.end()) {
BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No vendor information defined, cannot install.") % path_string;
return false;
}
if (presets_loaded == 0) {
BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No profile loaded.") % path_string;
return false;
}
BOOST_LOG_TRIVIAL(trace) << boost::format("Vendor bundle: `%1%`: %2% profiles loaded.") % path_string % presets_loaded;
this->vendor_profile = &first_vendor->second;
return true;
}
Bundle::Bundle(Bundle &&other)
@ -76,8 +87,11 @@ BundleMap BundleMap::load()
prusa_bundle_path = (rsrc_vendor_dir / PresetBundle::PRUSA_BUNDLE).replace_extension(".ini");
prusa_bundle_rsrc = true;
}
Bundle prusa_bundle(std::move(prusa_bundle_path), prusa_bundle_rsrc, true);
res.emplace(PresetBundle::PRUSA_BUNDLE, std::move(prusa_bundle));
{
Bundle prusa_bundle;
if (prusa_bundle.load(std::move(prusa_bundle_path), prusa_bundle_rsrc, true))
res.emplace(PresetBundle::PRUSA_BUNDLE, std::move(prusa_bundle));
}
// Load the other bundles in the datadir/vendor directory
// and then additionally from resources/profiles.
@ -90,8 +104,9 @@ BundleMap BundleMap::load()
// Don't load this bundle if we've already loaded it.
if (res.find(id) != res.end()) { continue; }
Bundle bundle(dir_entry.path(), is_in_resources);
res.emplace(std::move(id), std::move(bundle));
Bundle bundle;
if (bundle.load(dir_entry.path(), is_in_resources))
res.emplace(std::move(id), std::move(bundle));
}
}
@ -173,7 +188,7 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxSt
wxBitmap bitmap;
int bitmap_width = 0;
const wxString bitmap_file = GUI::from_u8(Slic3r::var((boost::format("printers/%1%_%2%.png") % vendor.id % model.id).str()));
const wxString bitmap_file = GUI::from_u8(Slic3r::resources_dir() + "/profiles/" + vendor.id + "/" + model.id + "_thumbnail.png");
if (wxFileExists(bitmap_file)) {
bitmap.LoadFile(bitmap_file, wxBITMAP_TYPE_PNG);
bitmap_width = bitmap.GetWidth();
@ -435,7 +450,7 @@ PageWelcome::PageWelcome(ConfigWizard *parent)
% _utf8(ConfigWizard::name())).str())
))
, cbox_reset(append(
new wxCheckBox(this, wxID_ANY, _(L("Remove user profiles - install from scratch (a snapshot will be taken beforehand)")))
new wxCheckBox(this, wxID_ANY, _(L("Remove user profiles (a snapshot will be taken beforehand)")))
))
{
welcome_text->Hide();
@ -1458,12 +1473,41 @@ void ConfigWizard::priv::load_vendors()
pair.second.preset_bundle->load_installed_printers(appconfig_new);
}
if (app_config->has_section(AppConfig::SECTION_FILAMENTS)) {
appconfig_new.set_section(AppConfig::SECTION_FILAMENTS, app_config->get_section(AppConfig::SECTION_FILAMENTS));
}
if (app_config->has_section(AppConfig::SECTION_MATERIALS)) {
appconfig_new.set_section(AppConfig::SECTION_MATERIALS, app_config->get_section(AppConfig::SECTION_MATERIALS));
}
// Copy installed filaments and SLA material names from app_config to appconfig_new
// while resolving current names of profiles, which were renamed in the meantime.
for (PrinterTechnology technology : { ptFFF, ptSLA }) {
const std::string &section_name = (technology == ptFFF) ? AppConfig::SECTION_FILAMENTS : AppConfig::SECTION_MATERIALS;
std::map<std::string, std::string> section_new;
if (app_config->has_section(section_name)) {
const std::map<std::string, std::string> &section_old = app_config->get_section(section_name);
for (const std::pair<std::string, std::string> &material_name_and_installed : section_old)
if (material_name_and_installed.second == "1") {
// Material is installed. Resolve it in bundles.
size_t num_found = 0;
const std::string &material_name = material_name_and_installed.first;
for (auto &bundle : bundles) {
const PresetCollection &materials = bundle.second.preset_bundle->materials(technology);
const Preset *preset = materials.find_preset(material_name);
if (preset == nullptr) {
// Not found. Maybe the material preset is there, bu it was was renamed?
const std::string *new_name = materials.get_preset_name_renamed(material_name);
if (new_name != nullptr)
preset = materials.find_preset(*new_name);
}
if (preset != nullptr) {
// Materal preset was found, mark it as installed.
section_new[preset->name] = "1";
++ num_found;
}
}
if (num_found == 0)
BOOST_LOG_TRIVIAL(error) << boost::format("Profile %1% was not found in installed vendor Preset Bundles.") % material_name;
else if (num_found > 1)
BOOST_LOG_TRIVIAL(error) << boost::format("Profile %1% was found in %2% vendor Preset Bundles.") % material_name % num_found;
}
}
appconfig_new.set_section(section_name, section_new);
};
}
void ConfigWizard::priv::add_page(ConfigWizardPage *page)
@ -1627,9 +1671,9 @@ void ConfigWizard::priv::on_printer_pick(PagePrinters *page, const PrinterPicker
}
}
// if at list one printer is selected but there in no one selected material,
// select materials which is default for selected printer(s)
select_default_materials_if_needed(pair.second.vendor_profile, page->technology, evt.model_id);
// When a printer model is picked, but there is no material installed compatible with this printer model,
// install default materials for selected printer model silently.
check_and_install_missing_materials(page->technology, evt.model_id);
}
if (page->technology & T_FFF) {
@ -1639,41 +1683,26 @@ void ConfigWizard::priv::on_printer_pick(PagePrinters *page, const PrinterPicker
}
}
void ConfigWizard::priv::select_default_materials_for_printer_model(const std::vector<VendorProfile::PrinterModel>& models, Technology technology, const std::string& model_id)
void ConfigWizard::priv::select_default_materials_for_printer_model(const VendorProfile::PrinterModel &printer_model, Technology technology)
{
PageMaterials* page_materials = technology & T_FFF ? page_filaments : page_sla_materials;
auto it = std::find_if(models.begin(), models.end(), [model_id](VendorProfile::PrinterModel model) {return model_id == model.id; });
if (it != models.end())
for (const std::string& material : it->default_materials)
appconfig_new.set(page_materials->materials->appconfig_section(), material, "1");
for (const std::string& material : printer_model.default_materials)
appconfig_new.set(page_materials->materials->appconfig_section(), material, "1");
}
void ConfigWizard::priv::select_default_materials_if_needed(VendorProfile* vendor_profile, Technology technology, const std::string& model_id)
void ConfigWizard::priv::select_default_materials_for_printer_models(Technology technology, const std::set<const VendorProfile::PrinterModel*> &printer_models)
{
if ((technology & T_FFF && !any_fff_selected) ||
(technology & T_SLA && !any_sla_selected) ||
check_materials_in_config(technology, false))
return;
PageMaterials *page_materials = technology & T_FFF ? page_filaments : page_sla_materials;
const std::string &appconfig_section = page_materials->materials->appconfig_section();
select_default_materials_for_printer_model(vendor_profile->models, technology, model_id);
}
void ConfigWizard::priv::selected_default_materials(Technology technology)
{
auto select_default_materials_for_printer_page = [this](PagePrinters * page_printers, Technology technology)
auto select_default_materials_for_printer_page = [this, appconfig_section, printer_models](PagePrinters *page_printers, Technology technology)
{
std::set<std::string> selected_models = page_printers->get_selected_models();
const std::string vendor_id = page_printers->get_vendor_id();
const std::string vendor_id = page_printers->get_vendor_id();
for (auto& pair : bundles)
{
if (pair.first != vendor_id)
continue;
for (const std::string& model_id : selected_models)
select_default_materials_for_printer_model(pair.second.vendor_profile->models, technology, model_id);
}
if (pair.first == vendor_id)
for (const VendorProfile::PrinterModel *printer_model : printer_models)
for (const std::string &material : printer_model->default_materials)
appconfig_new.set(appconfig_section, material, "1");
};
PagePrinters* page_printers = technology & T_FFF ? page_fff : page_msla;
@ -1687,7 +1716,7 @@ void ConfigWizard::priv::selected_default_materials(Technology technology)
}
update_materials(technology);
(technology& T_FFF ? page_filaments : page_sla_materials)->reload_presets();
((technology & T_FFF) ? page_filaments : page_sla_materials)->reload_presets();
}
void ConfigWizard::priv::on_3rdparty_install(const VendorProfile *vendor, bool install)
@ -1726,53 +1755,107 @@ bool ConfigWizard::priv::on_bnt_finish()
page_sla_materials->reload_presets();
// theres no need to check that filament is selected if we have only custom printer
if (custom_printer_selected && !any_fff_selected && !any_sla_selected) return true;
if (custom_printer_selected && !any_fff_selected && !any_sla_selected) return true;
// check, that there is selected at least one filament/material
return check_materials_in_config(T_ANY);
return check_and_install_missing_materials(T_ANY);
}
bool ConfigWizard::priv::check_materials_in_config(Technology technology, bool show_info_msg)
// This allmighty method verifies, whether there is at least a single compatible filament or SLA material installed
// for each Printer preset of each Printer Model installed.
//
// In case only_for_model_id is set, then the test is done for that particular printer model only, and the default materials are installed silently.
// Otherwise the user is quieried whether to install the missing default materials or not.
//
// Return true if the tested Printer Models already had materials installed.
// Return false if there were some Printer Models with missing materials, independent from whether the defaults were installed for these
// respective Printer Models or not.
bool ConfigWizard::priv::check_and_install_missing_materials(Technology technology, const std::string &only_for_model_id)
{
const auto exist_preset = [this](const std::string& section, const Materials& materials)
// Walk over all installed Printer presets and verify whether there is a filament or SLA material profile installed at the same PresetBundle,
// which is compatible with it.
const auto printer_models_missing_materials = [this, only_for_model_id](PrinterTechnology technology, const std::string &section)
{
if (appconfig_new.has_section(section) &&
!appconfig_new.get_section(section).empty())
{
const std::map<std::string, std::string>& appconfig_presets = appconfig_new.get_section(section);
for (const auto& preset : appconfig_presets)
if (materials.exist_preset(preset.first))
return true;
const std::map<std::string, std::string> &appconfig_presets = appconfig_new.has_section(section) ? appconfig_new.get_section(section) : std::map<std::string, std::string>();
std::set<const VendorProfile::PrinterModel*> printer_models_without_material;
for (const auto &pair : bundles) {
const PresetCollection &materials = pair.second.preset_bundle->materials(technology);
for (const auto &printer : pair.second.preset_bundle->printers) {
if (printer.is_visible && printer.printer_technology() == technology) {
const VendorProfile::PrinterModel *printer_model = PresetUtils::system_printer_model(printer);
assert(printer_model != nullptr);
if ((only_for_model_id.empty() || only_for_model_id == printer_model->id) &&
printer_models_without_material.find(printer_model) == printer_models_without_material.end()) {
bool has_material = false;
for (const std::pair<std::string, std::string> &preset : appconfig_presets) {
if (preset.second == "1") {
const Preset *material = materials.find_preset(preset.first, false);
if (material != nullptr && is_compatible_with_printer(PresetWithVendorProfile(*material, nullptr), PresetWithVendorProfile(printer, nullptr))) {
has_material = true;
break;
}
}
}
if (! has_material)
printer_models_without_material.insert(printer_model);
}
}
}
}
return false;
assert(printer_models_without_material.empty() || only_for_model_id.empty() || only_for_model_id == (*printer_models_without_material.begin())->id);
return printer_models_without_material;
};
const auto ask_and_selected_default_materials = [this](wxString message, Technology technology)
const auto ask_and_select_default_materials = [this](const wxString &message, const std::set<const VendorProfile::PrinterModel*> &printer_models, Technology technology)
{
wxMessageDialog msg(q, message, _(L("Notice")), wxYES_NO);
if (msg.ShowModal() == wxID_YES)
selected_default_materials(technology);
select_default_materials_for_printer_models(technology, printer_models);
};
if (any_fff_selected && technology & T_FFF && !exist_preset(AppConfig::SECTION_FILAMENTS, filaments))
{
if (show_info_msg)
{
wxString message = _(L("You have to select at least one filament for selected printers")) + "\n\n\t" +
_(L("Do you want to automatic select default filaments?"));
ask_and_selected_default_materials(message, T_FFF);
const auto printer_model_list = [](const std::set<const VendorProfile::PrinterModel*> &printer_models) -> wxString {
wxString out;
for (const VendorProfile::PrinterModel *printer_model : printer_models) {
out += "\t\t";
out += from_u8(printer_model->name);
out += "\n";
}
return out;
};
if (any_fff_selected && (technology & T_FFF)) {
std::set<const VendorProfile::PrinterModel*> printer_models_without_material = printer_models_missing_materials(ptFFF, AppConfig::SECTION_FILAMENTS);
if (! printer_models_without_material.empty()) {
if (only_for_model_id.empty())
ask_and_select_default_materials(
_L("The following FFF printer models have no filament selected:") +
"\n\n\t" +
printer_model_list(printer_models_without_material) +
"\n\n\t" +
_L("Do you want to select default filaments for these FFF printer models?"),
printer_models_without_material,
T_FFF);
else
select_default_materials_for_printer_model(**printer_models_without_material.begin(), T_FFF);
return false;
}
return false;
}
if (any_sla_selected && technology & T_SLA && !exist_preset(AppConfig::SECTION_MATERIALS, sla_materials))
{
if (show_info_msg)
{
wxString message = _(L("You have to select at least one material for selected printers")) + "\n\n\t" +
_(L("Do you want to automatic select default materials?"));
ask_and_selected_default_materials(message, T_SLA);
}
return false;
if (any_sla_selected && (technology & T_SLA)) {
std::set<const VendorProfile::PrinterModel*> printer_models_without_material = printer_models_missing_materials(ptSLA, AppConfig::SECTION_MATERIALS);
if (! printer_models_without_material.empty()) {
if (only_for_model_id.empty())
ask_and_select_default_materials(
_L("The following SLA printer models have no materials selected:") +
"\n\n\t" +
printer_model_list(printer_models_without_material) +
"\n\n\t" +
_L("Do you want to select default SLA materials for these printer models?"),
printer_models_without_material,
T_SLA);
else
select_default_materials_for_printer_model(**printer_models_without_material.begin(), T_SLA);
return false;
}
}
return true;
@ -1911,6 +1994,7 @@ void ConfigWizard::priv::update_presets_in_config(const std::string& section, co
const PresetAliases& aliases = section == AppConfig::SECTION_FILAMENTS ? aliases_fff : aliases_sla;
auto update = [this, add](const std::string& s, const std::string& key) {
assert(! s.empty());
if (add)
appconfig_new.set(s, key, "1");
else
@ -2046,8 +2130,11 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
{
// check, that there is selected at least one filament/material
ConfigWizardPage* active_page = this->p->index->active_page();
if ( (active_page == p->page_filaments || active_page == p->page_sla_materials)
&& !p->check_materials_in_config(dynamic_cast<PageMaterials*>(active_page)->materials->technology))
if (// Leaving the filaments or SLA materials page and
(active_page == p->page_filaments || active_page == p->page_sla_materials) &&
// some Printer models had no filament or SLA material selected.
! p->check_and_install_missing_materials(dynamic_cast<PageMaterials*>(active_page)->materials->technology))
// In that case don't leave the page and the function above queried the user whether to install default materials.
return;
this->p->index->go_next();
});

View file

@ -82,14 +82,6 @@ struct Materials
}
}
bool exist_preset(const std::string& preset_name) const
{
for (const Preset* preset : presets)
if (preset->name == preset_name)
return true;
return false;
}
static const std::string UNKNOWN;
static const std::string& get_filament_type(const Preset *preset);
static const std::string& get_filament_vendor(const Preset *preset);
@ -100,13 +92,16 @@ struct Materials
struct Bundle
{
std::unique_ptr<PresetBundle> preset_bundle;
VendorProfile *vendor_profile;
const bool is_in_resources;
const bool is_prusa_bundle;
VendorProfile *vendor_profile { nullptr };
bool is_in_resources { false };
bool is_prusa_bundle { false };
Bundle(fs::path source_path, bool is_in_resources, bool is_prusa_bundle = false);
Bundle() = default;
Bundle(Bundle &&other);
// Returns false if not loaded. Reason for that is logged as boost::log error.
bool load(fs::path source_path, bool is_in_resources, bool is_prusa_bundle = false);
const std::string& vendor_id() const { return vendor_profile->id; }
};
@ -500,17 +495,12 @@ struct ConfigWizard::priv
void on_custom_setup(const bool custom_wanted);
void on_printer_pick(PagePrinters *page, const PrinterPickerEvent &evt);
void select_default_materials_for_printer_model(const std::vector<VendorProfile::PrinterModel> &models,
Technology technology,
const std::string & model_id);
void select_default_materials_if_needed(VendorProfile* vendor_profile,
Technology technology,
const std::string &model_id);
void selected_default_materials(Technology technology);
void select_default_materials_for_printer_model(const VendorProfile::PrinterModel &printer_model, Technology technology);
void select_default_materials_for_printer_models(Technology technology, const std::set<const VendorProfile::PrinterModel*> &printer_models);
void on_3rdparty_install(const VendorProfile *vendor, bool install);
bool on_bnt_finish();
bool check_materials_in_config(Technology technology, bool show_info_msg = true);
bool check_and_install_missing_materials(Technology technology, const std::string &only_for_model_id = std::string());
void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
// #ys_FIXME_alise
void update_presets_in_config(const std::string& section, const std::string& alias_key, bool add);

View file

@ -20,11 +20,13 @@
#include <cmath>
#include <boost/algorithm/string/replace.hpp>
#include "Field.hpp"
#include "format.hpp"
namespace Slic3r {
using GUI::from_u8;
using GUI::into_u8;
using GUI::format_wxstr;
namespace DoubleSlider {
@ -530,7 +532,7 @@ wxString Control::get_label(int tick) const
const wxString str = m_values.empty() ?
wxNumberFormatter::ToString(m_label_koef*value, 2, wxNumberFormatter::Style_None) :
wxNumberFormatter::ToString(m_values[value], 2, wxNumberFormatter::Style_None);
return from_u8((boost::format("%1%\n(%2%)") % str % (m_values.empty() ? value : value+1)).str());
return format_wxstr("%1%\n(%2%)", str, m_values.empty() ? value : value+1);
}
void Control::draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, bool right_side/*=true*/) const
@ -1001,16 +1003,16 @@ wxString Control::get_tooltip(int tick/*=-1*/)
// Show custom Gcode as a first string of tooltop
tooltip = " ";
tooltip += tick_code_it->gcode == ColorChangeCode ? ( m_mode == t_mode::SingleExtruder ?
from_u8((boost::format(_utf8(L("Color change (\"%1%\")"))) % tick_code_it->gcode ).str()) :
from_u8((boost::format(_utf8(L("Color change (\"%1%\") for Extruder %2%"))) %
tick_code_it->gcode % tick_code_it->extruder).str()) ) :
tick_code_it->gcode == PausePrintCode ?
from_u8((boost::format(_utf8(L("Pause print (\"%1%\")"))) % tick_code_it->gcode ).str()) :
tick_code_it->gcode == ToolChangeCode ?
from_u8((boost::format(_utf8(L("Extruder (tool) is changed to Extruder \"%1%\""))) %
tick_code_it->extruder ).str()) :
from_u8(tick_code_it->gcode);
tooltip +=
tick_code_it->gcode == ColorChangeCode ?
(m_mode == t_mode::SingleExtruder ?
format_wxstr(_L("Color change (\"%1%\")"), tick_code_it->gcode) :
format_wxstr(_L("Color change (\"%1%\") for Extruder %2%"), tick_code_it->gcode, tick_code_it->extruder)) :
tick_code_it->gcode == PausePrintCode ?
format_wxstr(_L("Pause print (\"%1%\")"), tick_code_it->gcode) :
tick_code_it->gcode == ToolChangeCode ?
format_wxstr(_L("Extruder (tool) is changed to Extruder \"%1%\""), tick_code_it->extruder) :
from_u8(tick_code_it->gcode);
// If tick is marked as a conflict (exclamation icon),
// we should to explain why
@ -1176,8 +1178,8 @@ void Control::append_add_color_change_menu_item(wxMenu* menu, bool switch_curren
}
const wxString menu_name = switch_current_code ?
from_u8((boost::format(_utf8(L("Switch code to Color change (%1%) for:"))) % ColorChangeCode).str()) :
from_u8((boost::format(_utf8(L("Add color change (%1%) for:"))) % ColorChangeCode).str());
format_wxstr(_L("Switch code to Color change (%1%) for:"), ColorChangeCode) :
format_wxstr(_L("Add color change (%1%) for:"), ColorChangeCode);
wxMenuItem* add_color_change_menu_item = menu->AppendSubMenu(add_color_change_menu, menu_name, "");
add_color_change_menu_item->SetBitmap(create_scaled_bitmap("colorchange_add_m"));
}
@ -1615,8 +1617,8 @@ static void upgrade_text_entry_dialog(wxTextEntryDialog* dlg, double min = -1.0,
static std::string get_custom_code(const std::string& code_in, double height)
{
wxString msg_text = from_u8(_utf8(L("Enter custom G-code used on current layer"))) + ":";
wxString msg_header = from_u8((boost::format(_utf8(L("Custom G-code on current layer (%1% mm)."))) % height).str());
wxString msg_text = _L("Enter custom G-code used on current layer") + ":";
wxString msg_header = format_wxstr(_L("Custom G-code on current layer (%1% mm)."), height);
// get custom gcode
wxTextEntryDialog dlg(nullptr, msg_text, msg_header, code_in,
@ -1631,8 +1633,8 @@ static std::string get_custom_code(const std::string& code_in, double height)
static std::string get_pause_print_msg(const std::string& msg_in, double height)
{
wxString msg_text = from_u8(_utf8(L("Enter short message shown on Printer display when a print is paused"))) + ":";
wxString msg_header = from_u8((boost::format(_utf8(L("Message for pause print on current layer (%1% mm)."))) % height).str());
wxString msg_text = _L("Enter short message shown on Printer display when a print is paused") + ":";
wxString msg_header = format_wxstr(_L("Message for pause print on current layer (%1% mm)."), height);
// get custom gcode
wxTextEntryDialog dlg(nullptr, msg_text, msg_header, from_u8(msg_in),
@ -1914,8 +1916,8 @@ bool Control::check_ticks_changed_event(const std::string& gcode)
{
wxString message = m_mode == t_mode::SingleExtruder ? (
_(L("The last color change data was saved for a multi extruder printing.")) + "\n\n" +
_(L("Select YES if you want to delete all saved tool changes, \n\t"
"NO if you want all tool changes switch to color changes, \n\t"
_(L("Select YES if you want to delete all saved tool changes, \n"
"NO if you want all tool changes switch to color changes, \n"
"or CANCEL to leave it unchanged.")) + "\n\n\t" +
_(L("Do you want to delete all saved tool changes?"))
) : ( // t_mode::MultiExtruder

View file

@ -40,11 +40,19 @@ template<class T, size_t N> struct ArrayEvent : public wxEvent
return new ArrayEvent<T, N>(GetEventType(), data, GetEventObject());
}
};
template<class T> struct ArrayEvent<T, 1> : public wxEvent
template<class T> struct Event : public wxEvent
{
T data;
ArrayEvent(wxEventType type, T data, wxObject* origin = nullptr)
Event(wxEventType type, const T &data, wxObject* origin = nullptr)
: wxEvent(0, type), data(std::move(data))
{
m_propagationLevel = wxEVENT_PROPAGATE_MAX;
SetEventObject(origin);
}
Event(wxEventType type, T&& data, wxObject* origin = nullptr)
: wxEvent(0, type), data(std::move(data))
{
m_propagationLevel = wxEVENT_PROPAGATE_MAX;
@ -53,13 +61,10 @@ template<class T> struct ArrayEvent<T, 1> : public wxEvent
virtual wxEvent* Clone() const
{
return new ArrayEvent<T, 1>(GetEventType(), data, GetEventObject());
return new Event<T>(GetEventType(), data, GetEventObject());
}
};
template <class T> using Event = ArrayEvent<T, 1>;
}
}

View file

@ -375,12 +375,11 @@ void TextCtrl::BUILD() {
{
e.Skip();
#ifdef __WXOSX__
// OSX issue: For some unknown reason wxEVT_KILL_FOCUS is emitted twice in a row
// OSX issue: For some unknown reason wxEVT_KILL_FOCUS is emitted twice in a row in some cases
// (like when information dialog is shown during an update of the option value)
// Thus, suppress its second call
if (bKilledFocus) {
bKilledFocus = false;
if (bKilledFocus)
return;
}
bKilledFocus = true;
#endif // __WXOSX__
@ -391,6 +390,10 @@ void TextCtrl::BUILD() {
bEnterPressed = false;
else
propagate_value();
#ifdef __WXOSX__
// After processing of KILL_FOCUS event we should to invalidate a bKilledFocus flag
bKilledFocus = false;
#endif // __WXOSX__
}), temp->GetId());
// select all text using Ctrl+A
@ -511,7 +514,7 @@ void TextCtrl::disable() { dynamic_cast<wxTextCtrl*>(window)->Disable(); dynamic
#ifdef __WXGTK__
void TextCtrl::change_field_value(wxEvent& event)
{
if (bChangedValueEvent = (event.GetEventType()==wxEVT_KEY_UP))
if ((bChangedValueEvent = (event.GetEventType()==wxEVT_KEY_UP)))
on_change_field();
event.Skip();
};

View file

@ -284,7 +284,7 @@ public:
TextCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {}
~TextCtrl() {}
void BUILD();
void BUILD() override;
bool value_was_changed();
// Propagate value from field to the OptionGroupe and Config after kill_focus/ENTER
void propagate_value();
@ -303,9 +303,9 @@ public:
void msw_rescale(bool rescale_sidetext = false) override;
virtual void enable();
virtual void disable();
virtual wxWindow* getWindow() { return window; }
void enable() override;
void disable() override;
wxWindow* getWindow() override { return window; }
};
class CheckBox : public Field {

File diff suppressed because it is too large Load diff

View file

@ -3,22 +3,27 @@
#include <stddef.h>
#include <memory>
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#include <chrono>
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#include "3DScene.hpp"
#include "GLToolbar.hpp"
#include "GLShader.hpp"
#include "Event.hpp"
#include "3DBed.hpp"
#include "Camera.hpp"
#include "Selection.hpp"
#include "Gizmos/GLGizmosManager.hpp"
#include "GUI_ObjectLayers.hpp"
#include "GLSelectionRectangle.hpp"
#include "MeshUtils.hpp"
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
#include "Camera.hpp"
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
#include <float.h>
#include <wx/timer.h>
class wxWindow;
class wxSizeEvent;
class wxIdleEvent;
class wxKeyEvent;
@ -26,26 +31,25 @@ class wxMouseEvent;
class wxTimerEvent;
class wxPaintEvent;
class wxGLCanvas;
#if ENABLE_NON_STATIC_CANVAS_MANAGER
class wxGLContext;
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
// Support for Retina OpenGL on Mac OS
#define ENABLE_RETINA_GL __APPLE__
namespace Slic3r {
class GLShader;
class ExPolygon;
class Bed3D;
struct Camera;
class BackgroundSlicingProcess;
class GCodePreviewData;
#if ENABLE_THUMBNAIL_GENERATOR
struct ThumbnailData;
#endif // ENABLE_THUMBNAIL_GENERATOR
struct SlicingParameters;
enum LayerHeightEditActionType : unsigned int;
namespace GUI {
class GLGizmoBase;
#if ENABLE_RETINA_GL
class RetinaHelper;
#endif
@ -113,9 +117,7 @@ wxDECLARE_EVENT(EVT_GLCANVAS_RELOAD_FROM_DISK, SimpleEvent);
class GLCanvas3D
{
#if ENABLE_THUMBNAIL_GENERATOR
static const double DefaultCameraZoomToBoxMarginFactor;
#endif // ENABLE_THUMBNAIL_GENERATOR
public:
struct GCodePreviewVolumeIndex
@ -389,6 +391,42 @@ private:
void render(const std::vector<const ModelInstance*>& sorted_instances) const;
};
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
class Tooltip
{
std::string m_text;
std::chrono::steady_clock::time_point m_start_time;
// Indicator that the mouse is inside an ImGUI dialog, therefore the tooltip should be suppressed.
bool m_in_imgui = false;
public:
bool is_empty() const { return m_text.empty(); }
void set_text(const std::string& text);
void render(const Vec2d& mouse_position, GLCanvas3D& canvas) const;
// Indicates that the mouse is inside an ImGUI dialog, therefore the tooltip should be suppressed.
void set_in_imgui(bool b) { m_in_imgui = b; }
bool is_in_imgui() const { return m_in_imgui; }
};
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_SLOPE_RENDERING
class Slope
{
bool m_enabled{ false };
GLCanvas3D& m_canvas;
GLVolumeCollection& m_volumes;
public:
Slope(GLCanvas3D& canvas, GLVolumeCollection& volumes) : m_canvas(canvas), m_volumes(volumes) {}
void enable(bool enable) { m_enabled = enable; }
bool is_enabled() const { return m_enabled; }
void show(bool show) { m_volumes.set_slope_active(m_enabled ? show : false); }
bool is_shown() const { return m_volumes.is_slope_active(); }
void render() const;
};
#endif // ENABLE_SLOPE_RENDERING
public:
enum ECursorType : unsigned char
{
@ -406,9 +444,11 @@ private:
LegendTexture m_legend_texture;
WarningTexture m_warning_texture;
wxTimer m_timer;
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
Bed3D& m_bed;
Camera& m_camera;
GLToolbar& m_view_toolbar;
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
LayersEditing m_layers_editing;
Shader m_shader;
Mouse m_mouse;
@ -467,11 +507,25 @@ private:
int m_selected_extruder;
Labels m_labels;
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
mutable Tooltip m_tooltip;
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_SLOPE_RENDERING
Slope m_slope;
#endif // ENABLE_SLOPE_RENDERING
public:
#if ENABLE_NON_STATIC_CANVAS_MANAGER
explicit GLCanvas3D(wxGLCanvas* canvas);
#else
GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar);
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
~GLCanvas3D();
#if ENABLE_NON_STATIC_CANVAS_MANAGER
bool is_initialized() const { return m_initialized; }
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
void set_context(wxGLContext* context) { m_context = context; }
wxGLCanvas* get_wxglcanvas() { return m_canvas; }
@ -518,9 +572,14 @@ public:
void set_color_by(const std::string& value);
#if ENABLE_NON_STATIC_CANVAS_MANAGER
void refresh_camera_scene_box();
#else
void refresh_camera_scene_box() { m_camera.set_scene_box(scene_bounding_box()); }
const Camera& get_camera() const { return m_camera; }
const Shader& get_shader() const { return m_shader; }
Camera& get_camera() { return m_camera; }
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
const Shader& get_shader() const { return m_shader; }
BoundingBoxf3 volumes_bounding_box() const;
BoundingBoxf3 scene_bounding_box() const;
@ -544,6 +603,9 @@ public:
void enable_undoredo_toolbar(bool enable);
void enable_dynamic_background(bool enable);
void enable_labels(bool enable) { m_labels.enable(enable); }
#if ENABLE_SLOPE_RENDERING
void enable_slope(bool enable) { m_slope.enable(enable); }
#endif // ENABLE_SLOPE_RENDERING
void allow_multisample(bool allow);
void zoom_to_bed();
@ -556,11 +618,9 @@ public:
bool is_dragging() const { return m_gizmos.is_dragging() || m_moving; }
void render();
#if ENABLE_THUMBNAIL_GENERATOR
// printable_only == false -> render also non printable volumes as grayed
// parts_only == false -> render also sla support and pad
void render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const;
#endif // ENABLE_THUMBNAIL_GENERATOR
void select_all();
void deselect_all();
@ -614,7 +674,9 @@ public:
void update_ui_from_settings();
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
float get_view_toolbar_height() const { return m_view_toolbar.get_height(); }
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
int get_move_volume_id() const { return m_mouse.drag.move_volume_idx; }
int get_first_hover_volume_idx() const { return m_hover_volume_idxs.empty() ? -1 : m_hover_volume_idxs.front(); }
@ -646,7 +708,6 @@ public:
Linef3 mouse_ray(const Point& mouse_pos);
void set_mouse_as_dragging() { m_mouse.dragging = true; }
void refresh_camera_scene_box() { m_camera.set_scene_box(scene_bounding_box()); }
bool is_mouse_dragging() const { return m_mouse.dragging; }
double get_size_proportional_to_max_bed_size(double factor) const;
@ -668,6 +729,11 @@ public:
bool are_labels_shown() const { return m_labels.is_shown(); }
void show_labels(bool show) { m_labels.show(show); }
#if ENABLE_SLOPE_RENDERING
bool is_slope_shown() const { return m_slope.is_shown(); }
void show_slope(bool show) { m_slope.show(show); }
#endif // ENABLE_SLOPE_RENDERING
private:
bool _is_shown_on_screen() const;
@ -681,11 +747,7 @@ private:
BoundingBoxf3 _max_bounding_box(bool include_gizmos, bool include_bed_model) const;
#if ENABLE_THUMBNAIL_GENERATOR
void _zoom_to_box(const BoundingBoxf3& box, double margin_factor = DefaultCameraZoomToBoxMarginFactor);
#else
void _zoom_to_box(const BoundingBoxf3& box);
#endif // ENABLE_THUMBNAIL_GENERATOR
void _update_camera_zoom(double zoom);
void _refresh_if_shown_on_screen();
@ -713,8 +775,7 @@ private:
#endif // ENABLE_SHOW_CAMERA_TARGET
void _render_sla_slices() const;
void _render_selection_sidebar_hints() const;
void _render_undo_redo_stack(const bool is_undo, float pos_x) const;
#if ENABLE_THUMBNAIL_GENERATOR
bool _render_undo_redo_stack(const bool is_undo, float pos_x) const;
void _render_thumbnail_internal(ThumbnailData& thumbnail_data, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const;
// render thumbnail using an off-screen framebuffer
void _render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const;
@ -722,7 +783,6 @@ private:
void _render_thumbnail_framebuffer_ext(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const;
// render thumbnail using the default framebuffer
void _render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const;
#endif // ENABLE_THUMBNAIL_GENERATOR
void _update_volumes_hover_state() const;

View file

@ -1,3 +1,4 @@
#include "libslic3r/libslic3r.h"
#include "GLCanvas3DManager.hpp"
#include "../../slic3r/GUI/GUI.hpp"
#include "../../slic3r/GUI/AppConfig.hpp"
@ -7,7 +8,9 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#if ENABLE_NON_STATIC_CANVAS_MANAGER
#include <boost/log/trivial.hpp>
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
#include <wx/glcanvas.h>
#include <wx/timer.h>
#include <wx/msgdlg.h>
@ -17,8 +20,10 @@
#include <iostream>
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
// Part of temporary hack to remove crash when closing on OSX 10.9.5
#ifdef __APPLE__
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
#include <wx/platinfo.h>
#endif // __APPLE__
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
@ -28,6 +33,7 @@
namespace Slic3r {
namespace GUI {
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
GLCanvas3DManager::GLInfo::GLInfo()
: m_detected(false)
, m_version("")
@ -38,6 +44,7 @@ GLCanvas3DManager::GLInfo::GLInfo()
, m_max_anisotropy(0.0f)
{
}
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
const std::string& GLCanvas3DManager::GLInfo::get_version() const
{
@ -196,27 +203,57 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten
return out.str();
}
GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::MS_Unknown;
bool GLCanvas3DManager::s_compressed_textures_supported = false;
GLCanvas3DManager::EFramebufferType GLCanvas3DManager::s_framebuffers_type = GLCanvas3DManager::FB_None;
GLCanvas3DManager::GLInfo GLCanvas3DManager::s_gl_info;
bool GLCanvas3DManager::s_compressed_textures_supported = false;
#if ENABLE_NON_STATIC_CANVAS_MANAGER
GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::EMultisampleState::Unknown;
GLCanvas3DManager::EFramebufferType GLCanvas3DManager::s_framebuffers_type = GLCanvas3DManager::EFramebufferType::Unknown;
#else
GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::MS_Unknown;
GLCanvas3DManager::EFramebufferType GLCanvas3DManager::s_framebuffers_type = GLCanvas3DManager::FB_None;
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
GLCanvas3DManager::OSInfo GLCanvas3DManager::s_os_info;
#endif // __APPLE__
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
GLCanvas3DManager::GLCanvas3DManager()
: m_context(nullptr)
, m_gl_initialized(false)
{
}
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
GLCanvas3DManager::~GLCanvas3DManager()
{
this->destroy();
#if ENABLE_NON_STATIC_CANVAS_MANAGER
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
// This is an ugly hack needed to solve the crash happening when closing the application on OSX 10.9.5 with newer wxWidgets
// The crash is triggered inside wxGLContext destructor
if (s_os_info.major != 10 || s_os_info.minor != 9 || s_os_info.micro != 5)
{
#endif //__APPLE__
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
if (m_context != nullptr)
delete m_context;
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
}
#endif //__APPLE__
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#else
this->destroy();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
}
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
bool GLCanvas3DManager::add(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar)
{
if (canvas == nullptr)
@ -239,7 +276,7 @@ bool GLCanvas3DManager::add(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLTo
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
// Part of temporary hack to remove crash when closing on OSX 10.9.5
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
s_os_info.major = wxPlatformInfo::Get().GetOSMajorVersion();
s_os_info.minor = wxPlatformInfo::Get().GetOSMinorVersion();
s_os_info.micro = wxPlatformInfo::Get().GetOSMicroVersion();
@ -277,28 +314,50 @@ void GLCanvas3DManager::remove_all()
m_canvases.clear();
}
unsigned int GLCanvas3DManager::count() const
size_t GLCanvas3DManager::count() const
{
return (unsigned int)m_canvases.size();
return m_canvases.size();
}
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
#if ENABLE_NON_STATIC_CANVAS_MANAGER
bool GLCanvas3DManager::init_gl()
#else
void GLCanvas3DManager::init_gl()
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
{
if (!m_gl_initialized)
{
#if ENABLE_NON_STATIC_CANVAS_MANAGER
if (glewInit() != GLEW_OK)
{
BOOST_LOG_TRIVIAL(error) << "Unable to init glew library";
return false;
}
#else
glewInit();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
m_gl_initialized = true;
if (GLEW_EXT_texture_compression_s3tc)
s_compressed_textures_supported = true;
else
s_compressed_textures_supported = false;
#if ENABLE_NON_STATIC_CANVAS_MANAGER
if (GLEW_ARB_framebuffer_object)
s_framebuffers_type = EFramebufferType::Arb;
else if (GLEW_EXT_framebuffer_object)
s_framebuffers_type = EFramebufferType::Ext;
else
s_framebuffers_type = EFramebufferType::Unknown;
#else
if (GLEW_ARB_framebuffer_object)
s_framebuffers_type = FB_Arb;
else if (GLEW_EXT_framebuffer_object)
s_framebuffers_type = FB_Ext;
else
s_framebuffers_type = FB_None;
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
if (! s_gl_info.is_version_greater_or_equal_to(2, 0)) {
// Complain about the OpenGL version.
@ -314,8 +373,31 @@ void GLCanvas3DManager::init_gl()
wxMessageBox(message, wxString("PrusaSlicer - ") + _(L("Unsupported OpenGL version")), wxOK | wxICON_ERROR);
}
}
#if ENABLE_NON_STATIC_CANVAS_MANAGER
return true;
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
}
#if ENABLE_NON_STATIC_CANVAS_MANAGER
wxGLContext* GLCanvas3DManager::init_glcontext(wxGLCanvas& canvas)
{
if (m_context == nullptr)
{
m_context = new wxGLContext(&canvas);
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
s_os_info.major = wxPlatformInfo::Get().GetOSMajorVersion();
s_os_info.minor = wxPlatformInfo::Get().GetOSMinorVersion();
s_os_info.micro = wxPlatformInfo::Get().GetOSMicroVersion();
#endif //__APPLE__
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
}
return m_context;
}
#else
bool GLCanvas3DManager::init(wxGLCanvas* canvas)
{
CanvasesMap::const_iterator it = do_get_canvas(canvas);
@ -331,7 +413,7 @@ void GLCanvas3DManager::destroy()
{
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
// this is a temporary ugly hack to solve the crash happening when closing the application on OSX 10.9.5
// this is an ugly hack needed to solve the crash happening when closing the application on OSX 10.9.5
// the crash is inside wxGLContext destructor
if (s_os_info.major == 10 && s_os_info.minor == 9 && s_os_info.micro == 5)
return;
@ -342,14 +424,21 @@ void GLCanvas3DManager::destroy()
m_context = nullptr;
}
}
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
GLCanvas3D* GLCanvas3DManager::get_canvas(wxGLCanvas* canvas)
{
CanvasesMap::const_iterator it = do_get_canvas(canvas);
return (it != m_canvases.end()) ? it->second : nullptr;
}
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
#if ENABLE_NON_STATIC_CANVAS_MANAGER
wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow& parent)
#else
wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow *parent)
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
{
int attribList[] = {
WX_GL_RGBA,
@ -367,7 +456,11 @@ wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow *parent)
0
};
#if ENABLE_NON_STATIC_CANVAS_MANAGER
if (s_multisample == EMultisampleState::Unknown)
#else
if (s_multisample == MS_Unknown)
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
{
detect_multisample(attribList);
// // debug output
@ -377,9 +470,14 @@ wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow *parent)
if (! can_multisample())
attribList[12] = 0;
#if ENABLE_NON_STATIC_CANVAS_MANAGER
return new wxGLCanvas(&parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS);
#else
return new wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS);
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
}
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::do_get_canvas(wxGLCanvas* canvas)
{
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);
@ -397,12 +495,17 @@ bool GLCanvas3DManager::init(GLCanvas3D& canvas)
return canvas.init();
}
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
void GLCanvas3DManager::detect_multisample(int* attribList)
{
int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER;
bool enable_multisample = wxVersion >= 30003;
#if ENABLE_NON_STATIC_CANVAS_MANAGER
s_multisample = (enable_multisample && wxGLCanvas::IsDisplaySupported(attribList)) ? EMultisampleState::Enabled : EMultisampleState::Disabled;
#else
s_multisample = (enable_multisample && wxGLCanvas::IsDisplaySupported(attribList)) ? MS_Enabled : MS_Disabled;
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
// Alternative method: it was working on previous version of wxWidgets but not with the latest, at least on Windows
// s_multisample = enable_multisample && wxGLCanvas::IsExtensionSupported("WGL_ARB_multisample");
}

View file

@ -23,22 +23,43 @@ class PrintObject;
namespace GUI {
class GLCanvas3D;
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
class Bed3D;
class GLToolbar;
struct Camera;
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
class GLCanvas3DManager
{
public:
#if ENABLE_NON_STATIC_CANVAS_MANAGER
enum class EFramebufferType : unsigned char
{
Unknown,
Arb,
Ext
};
#else
enum EFramebufferType : unsigned char
{
FB_None,
FB_Arb,
FB_Ext
};
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
class GLInfo
{
#if ENABLE_NON_STATIC_CANVAS_MANAGER
mutable bool m_detected{ false };
mutable int m_max_tex_size{ 0 };
mutable float m_max_anisotropy{ 0.0f };
mutable std::string m_version;
mutable std::string m_glsl_version;
mutable std::string m_vendor;
mutable std::string m_renderer;
#else
mutable bool m_detected;
mutable std::string m_version;
@ -48,9 +69,14 @@ public:
mutable int m_max_tex_size;
mutable float m_max_anisotropy;
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
public:
#if ENABLE_NON_STATIC_CANVAS_MANAGER
GLInfo() = default;
#else
GLInfo();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
const std::string& get_version() const;
const std::string& get_glsl_version() const;
@ -70,6 +96,7 @@ public:
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
struct OSInfo
{
int major{ 0 };
@ -80,6 +107,14 @@ public:
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
private:
#if ENABLE_NON_STATIC_CANVAS_MANAGER
enum class EMultisampleState : unsigned char
{
Unknown,
Enabled,
Disabled
};
#else
enum EMultisampleState : unsigned char
{
MS_Unknown,
@ -88,51 +123,85 @@ private:
};
typedef std::map<wxGLCanvas*, GLCanvas3D*> CanvasesMap;
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
CanvasesMap m_canvases;
#if ENABLE_NON_STATIC_CANVAS_MANAGER
bool m_gl_initialized{ false };
wxGLContext* m_context{ nullptr };
#else
wxGLContext* m_context;
bool m_gl_initialized;
CanvasesMap m_canvases;
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
static GLInfo s_gl_info;
#if ENABLE_HACK_CLOSING_ON_OSX_10_9_5
#ifdef __APPLE__
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
static OSInfo s_os_info;
#endif //__APPLE__
#endif // ENABLE_HACK_CLOSING_ON_OSX_10_9_5
bool m_gl_initialized;
static EMultisampleState s_multisample;
static bool s_compressed_textures_supported;
static EMultisampleState s_multisample;
static EFramebufferType s_framebuffers_type;
public:
#if ENABLE_NON_STATIC_CANVAS_MANAGER
GLCanvas3DManager() = default;
#else
GLCanvas3DManager();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
~GLCanvas3DManager();
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
bool add(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar);
bool remove(wxGLCanvas* canvas);
void remove_all();
unsigned int count() const;
size_t count() const;
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
#if ENABLE_NON_STATIC_CANVAS_MANAGER
bool init_gl();
#else
void init_gl();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
#if ENABLE_NON_STATIC_CANVAS_MANAGER
wxGLContext* init_glcontext(wxGLCanvas& canvas);
#else
bool init(wxGLCanvas* canvas);
void destroy();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
GLCanvas3D* get_canvas(wxGLCanvas* canvas);
#endif // !ENABLE_NON_STATIC_CANVAS_MANAGER
static bool can_multisample() { return s_multisample == MS_Enabled; }
static bool are_compressed_textures_supported() { return s_compressed_textures_supported; }
#if ENABLE_NON_STATIC_CANVAS_MANAGER
static bool can_multisample() { return s_multisample == EMultisampleState::Enabled; }
static bool are_framebuffers_supported() { return (s_framebuffers_type != EFramebufferType::Unknown); }
#else
static bool can_multisample() { return s_multisample == MS_Enabled; }
static bool are_framebuffers_supported() { return (s_framebuffers_type != FB_None); }
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
static EFramebufferType get_framebuffers_type() { return s_framebuffers_type; }
#if ENABLE_NON_STATIC_CANVAS_MANAGER
static wxGLCanvas* create_wxglcanvas(wxWindow& parent);
#else
static wxGLCanvas* create_wxglcanvas(wxWindow *parent);
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
static const GLInfo& get_gl_info() { return s_gl_info; }
private:
#if !ENABLE_NON_STATIC_CANVAS_MANAGER
CanvasesMap::iterator do_get_canvas(wxGLCanvas* canvas);
CanvasesMap::const_iterator do_get_canvas(wxGLCanvas* canvas) const;
bool init(GLCanvas3D& canvas);
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
static void detect_multisample(int* attribList);
};

View file

@ -2,6 +2,9 @@
#include "Camera.hpp"
#include "3DScene.hpp"
#include "GLCanvas3D.hpp"
#if ENABLE_NON_STATIC_CANVAS_MANAGER
#include "GUI_App.hpp"
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
#include <GL/glew.h>
@ -35,13 +38,17 @@ namespace GUI {
m_state = Off;
#if ENABLE_NON_STATIC_CANVAS_MANAGER
const Camera& camera = wxGetApp().plater()->get_camera();
#else
const Camera& camera = canvas.get_camera();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
const std::array<int, 4>& viewport = camera.get_viewport();
const Transform3d& modelview_matrix = camera.get_view_matrix();
const Transform3d& projection_matrix = camera.get_projection_matrix();
// bounding box created from the rectangle corners - will take care of order of the corners
BoundingBox rectangle(Points{ Point(m_start_corner.cast<int>()), Point(m_end_corner.cast<int>()) });
BoundingBox rectangle(Points{ Point(m_start_corner.cast<coord_t>()), Point(m_end_corner.cast<coord_t>()) });
// Iterate over all points and determine whether they're in the rectangle.
for (unsigned int i = 0; i<points.size(); ++i) {
@ -68,7 +75,11 @@ namespace GUI {
if (!is_dragging())
return;
#if ENABLE_NON_STATIC_CANVAS_MANAGER
const Camera& camera = wxGetApp().plater()->get_camera();
#else
const Camera& camera = canvas.get_camera();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
float inv_zoom = (float)camera.get_inv_zoom();
Size cnv_size = canvas.get_canvas_size();

View file

@ -2,6 +2,9 @@
#include "GLTexture.hpp"
#include "3DScene.hpp"
#if ENABLE_NON_STATIC_CANVAS_MANAGER
#include "GLCanvas3DManager.hpp"
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
#include <GL/glew.h>

View file

@ -3,9 +3,14 @@
#include "GLToolbar.hpp"
#if ENABLE_NON_STATIC_CANVAS_MANAGER
#include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/Camera.hpp"
#else
#include "../../slic3r/GUI/GLCanvas3D.hpp"
#include <GL/glew.h>
#include "../../slic3r/GUI/Camera.hpp"
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
#include <wx/event.h>
#include <wx/bitmap.h>
@ -16,7 +21,6 @@
namespace Slic3r {
namespace GUI {
wxDEFINE_EVENT(EVT_GLTOOLBAR_ADD, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_DELETE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_DELETE_ALL, SimpleEvent);
@ -86,7 +90,7 @@ bool GLToolbarItem::update_enabled_state()
void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const
{
auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) ->GLTexture::Quad_UVs
auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) -> GLTexture::Quad_UVs
{
assert((tex_width != 0) && (tex_height != 0));
GLTexture::Quad_UVs ret;
@ -154,7 +158,9 @@ GLToolbar::GLToolbar(GLToolbar::EType type, const std::string& name)
, m_name(name)
, m_enabled(false)
, m_icons_texture_dirty(true)
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
, m_tooltip("")
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
, m_pressed_toggable_id(-1)
{
}
@ -358,16 +364,37 @@ int GLToolbar::get_item_id(const std::string& name) const
return -1;
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string GLToolbar::get_tooltip() const
{
std::string tooltip;
for (GLToolbarItem* item : m_items)
{
if (item->is_hovered())
{
tooltip = item->get_tooltip();
if (!item->is_pressed())
{
const std::string& additional_tooltip = item->get_additional_tooltip();
if (!additional_tooltip.empty())
tooltip += "\n" + additional_tooltip;
break;
}
}
}
return tooltip;
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLToolbar::get_additional_tooltip(int item_id, std::string& text)
{
if ((0 <= item_id) && (item_id < (int)m_items.size()))
if (0 <= item_id && item_id < (int)m_items.size())
{
GLToolbarItem* item = m_items[item_id];
if (item != nullptr)
{
text = item->get_additional_tooltip();
return;
}
text = m_items[item_id]->get_additional_tooltip();
return;
}
text.clear();
@ -375,12 +402,8 @@ void GLToolbar::get_additional_tooltip(int item_id, std::string& text)
void GLToolbar::set_additional_tooltip(int item_id, const std::string& text)
{
if ((0 <= item_id) && (item_id < (int)m_items.size()))
{
GLToolbarItem* item = m_items[item_id];
if (item != nullptr)
item->set_additional_tooltip(text);
}
if (0 <= item_id && item_id < (int)m_items.size())
m_items[item_id]->set_additional_tooltip(text);
}
bool GLToolbar::update_items_state()
@ -421,14 +444,62 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
// mouse anywhere
if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && (m_mouse_capture.parent != nullptr))
{
if (m_mouse_capture.any() && (evt.LeftUp() || evt.MiddleUp() || evt.RightUp()))
if (m_mouse_capture.any() && (evt.LeftUp() || evt.MiddleUp() || evt.RightUp())) {
// prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it,
// as when switching between views
processed = true;
m_mouse_capture.reset();
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (contains_mouse(mouse_pos, parent) == -1)
// mouse is outside the toolbar
m_tooltip.clear();
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
return true;
}
m_mouse_capture.reset();
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (evt.Moving())
update_hover_state(mouse_pos, parent);
else if (evt.LeftUp())
{
if (m_mouse_capture.left)
{
processed = true;
m_mouse_capture.left = false;
}
else
return false;
}
else if (evt.MiddleUp())
{
if (m_mouse_capture.middle)
{
processed = true;
m_mouse_capture.middle = false;
}
else
return false;
}
else if (evt.RightUp())
{
if (m_mouse_capture.right)
{
processed = true;
m_mouse_capture.right = false;
}
else
return false;
}
else if (evt.Dragging())
{
if (m_mouse_capture.any())
// if the button down was done on this toolbar, prevent from dragging into the scene
processed = true;
else
return false;
}
#else
if (evt.Moving())
m_tooltip = update_hover_state(mouse_pos, parent);
else if (evt.LeftUp())
@ -440,14 +511,19 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
else if (evt.Dragging() && m_mouse_capture.any())
// if the button down was done on this toolbar, prevent from dragging into the scene
processed = true;
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
int item_id = contains_mouse(mouse_pos, parent);
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (item_id != -1)
#else
if (item_id == -1)
{
// mouse is outside the toolbar
m_tooltip.clear();
}
else
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
// mouse inside toolbar
if (evt.LeftDown() || evt.LeftDClick())
@ -479,8 +555,10 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
parent.set_as_dirty();
}
}
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
else if (evt.LeftUp())
processed = true;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
return processed;
@ -609,6 +687,20 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas
}
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent)
{
if (!m_enabled)
return;
switch (m_layout.type)
{
default:
case Layout::Horizontal: { update_hover_state_horizontal(mouse_pos, parent); break; }
case Layout::Vertical: { update_hover_state_vertical(mouse_pos, parent); break; }
}
}
#else
std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent)
{
if (!m_enabled)
@ -621,12 +713,21 @@ std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& pa
case Layout::Vertical: { return update_hover_state_vertical(mouse_pos, parent); }
}
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent)
#else
std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent)
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
// NB: mouse_pos is already scaled appropriately
#if ENABLE_NON_STATIC_CANVAS_MANAGER
float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom();
#else
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size();
@ -643,8 +744,10 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
float left = m_layout.left + scaled_border;
float top = m_layout.top - scaled_border;
std::string tooltip = "";
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
for (GLToolbarItem* item : m_items)
{
if (!item->is_visible())
@ -659,6 +762,7 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
GLToolbarItem::EState state = item->get_state();
bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top);
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (inside)
{
tooltip = item->get_tooltip();
@ -669,6 +773,7 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
tooltip += "\n" + additional_tooltip;
}
}
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
switch (state)
{
@ -712,25 +817,62 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
break;
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
case GLToolbarItem::Disabled:
{
if (inside)
{
item->set_state(GLToolbarItem::HoverDisabled);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::HoverDisabled:
{
if (!inside)
{
item->set_state(GLToolbarItem::Disabled);
parent.set_as_dirty();
}
break;
}
default:
{
break;
}
#else
default:
case GLToolbarItem::Disabled:
{
break;
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
left += icon_stride;
}
}
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
return tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent)
#else
std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent)
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
{
// NB: mouse_pos is already scaled appropriately
#if ENABLE_NON_STATIC_CANVAS_MANAGER
float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom();
#else
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size();
@ -746,7 +888,9 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
float left = m_layout.left + scaled_border;
float top = m_layout.top - scaled_border;
std::string tooltip = "";
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
std::string tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
for (GLToolbarItem* item : m_items)
{
@ -762,6 +906,7 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
GLToolbarItem::EState state = item->get_state();
bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top);
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
if (inside)
{
tooltip = item->get_tooltip();
@ -772,6 +917,7 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
tooltip += "\n" + additional_tooltip;
}
}
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
switch (state)
{
@ -815,18 +961,47 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
break;
}
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
case GLToolbarItem::Disabled:
{
if (inside)
{
item->set_state(GLToolbarItem::HoverDisabled);
parent.set_as_dirty();
}
break;
}
case GLToolbarItem::HoverDisabled:
{
if (!inside)
{
item->set_state(GLToolbarItem::Disabled);
parent.set_as_dirty();
}
break;
}
default:
{
break;
}
#else
default:
case GLToolbarItem::Disabled:
{
break;
}
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
top -= icon_stride;
}
}
#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
return tooltip;
#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
int GLToolbar::contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const
@ -846,7 +1021,11 @@ int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3
{
// NB: mouse_pos is already scaled appropriately
#if ENABLE_NON_STATIC_CANVAS_MANAGER
float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom();
#else
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size();
@ -919,7 +1098,11 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D&
{
// NB: mouse_pos is already scaled appropriately
#if ENABLE_NON_STATIC_CANVAS_MANAGER
float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom();
#else
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size();
@ -1071,7 +1254,11 @@ void GLToolbar::render_horizontal(const GLCanvas3D& parent) const
int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height();
#if ENABLE_NON_STATIC_CANVAS_MANAGER
float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom();
#else
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
float factor = inv_zoom * m_layout.scale;
float scaled_icons_size = m_layout.icons_size * factor;
@ -1119,7 +1306,11 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const
int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height();
#if ENABLE_NON_STATIC_CANVAS_MANAGER
float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom();
#else
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
#endif // ENABLE_NON_STATIC_CANVAS_MANAGER
float factor = inv_zoom * m_layout.scale;
float scaled_icons_size = m_layout.icons_size * factor;
@ -1175,19 +1366,37 @@ bool GLToolbar::generate_icons_texture() const
std::vector<std::pair<int, bool>> states;
if (m_name == "Top")
{
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
states.push_back({ 1, false }); // Normal
states.push_back({ 0, false }); // Pressed
states.push_back({ 2, false }); // Disabled
states.push_back({ 0, false }); // Hover
states.push_back({ 0, false }); // HoverPressed
states.push_back({ 2, false }); // HoverDisabled
#else
states.push_back(std::make_pair(1, false));
states.push_back(std::make_pair(0, false));
states.push_back(std::make_pair(2, false));
states.push_back(std::make_pair(0, false));
states.push_back(std::make_pair(0, false));
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
else if (m_name == "View")
{
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
states.push_back({ 1, false }); // Normal
states.push_back({ 1, true }); // Pressed
states.push_back({ 1, false }); // Disabled
states.push_back({ 0, false }); // Hover
states.push_back({ 1, true }); // HoverPressed
states.push_back({ 1, false }); // HoverDisabled
#else
states.push_back(std::make_pair(1, false));
states.push_back(std::make_pair(1, true));
states.push_back(std::make_pair(1, false));
states.push_back(std::make_pair(0, false));
states.push_back(std::make_pair(1, true));
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
}
unsigned int sprite_size_px = (unsigned int)(m_layout.icons_size * m_layout.scale);

Some files were not shown because too many files have changed in this diff Show more