OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
anonymous_namespace{GLGizmoSVG.cpp} Namespace Reference

Classes

struct  Limits
struct  GuiCfg

Enumerations

enum class  IconType : unsigned {
  reset_value , refresh , change_file , bake ,
  save , exclamation , lock , unlock ,
  reflection_x , reflection_y , _count
}
enum class  IconState : unsigned { activable = 0 , hovered , disabled }

Functions

std::string choose_svg_file ()
 Open file dialog with svg files.
double get_tesselation_tolerance (double scale)
EmbossShape select_shape (std::string_view filepath="", double tesselation_tolerance_in_mm=get_tesselation_tolerance(1.))
 Let user to choose file with (S)calable (V)ector (G)raphics - SVG. Than let select contour.
DataBasePtr create_emboss_data_base (std::shared_ptr< std::atomic< bool > > &cancel, ModelVolumeType volume_type, std::string_view filepath="")
 Create new embos data.
std::string get_file_name (const std::string &file_path)
 Separate file name from file path. String after last delimiter and before last point.
std::string volume_name (const EmbossShape &shape)
 Create volume name from shape information.
CreateVolumeParams create_input (GLCanvas3D &canvas, RaycastManager &raycaster, ModelVolumeType volume_type)
 Create input for volume creation.
const IconManager::Icon & get_icon (const IconManager::VIcons &icons, IconType type, IconState state)
GuiCfg create_gui_configuration ()
IconManager::VIcons init_icons (IconManager &mng, const GuiCfg &cfg)
bool draw_clickable (const IconManager::VIcons &icons, IconType type)
bool reset_button (const IconManager::VIcons &icons)
void wu_draw_line_side (Linef line, const std::function< void(int x, int y, float brightess)> &plot)
template<unsigned int N>
void draw_side_outline (const ExPolygons &shape, const std::array< unsigned char, N > &color, std::vector< unsigned char > &data, size_t data_width, double scale)
template<unsigned int N>
void draw_filled (const ExPolygons &shape, const std::array< unsigned char, N > &color, std::vector< unsigned char > &data, size_t data_width, double scale)
 Draw filled ExPolygon into data line by line inspired by: http://alienryderflex.com/polygon_fill/.
ExPolygons union_ex (const ExPolygonsWithIds &shapes)
 Union shape defined by glyphs.
bool init_texture (Texture &texture, const ExPolygonsWithIds &shapes_with_ids, unsigned max_size_px, const std::vector< std::string > &shape_warnings)
bool is_closed (NSVGpath *path)
void add_comma_separated (std::string &result, const std::string &add)
std::string create_fill_warning (const NSVGshape &shape)
std::string create_stroke_warning (const NSVGshape &shape)
std::vector< std::string > create_shape_warnings (const EmbossShape &shape, float scale)
 Create warnings about shape.
void delete_texture (Texture &texture)

Variables

const std::string rotation_snapshot_name = L("SVG rotate")
const std::string move_snapshot_name = L("SVG move")
const struct anonymous_namespace{GLGizmoSVG.cpp}::Limits limits
wxString last_used_directory = wxEmptyString
const float warning_preccission = 1e-4f

Class Documentation

◆ anonymous_namespace{GLGizmoSVG.cpp}::Limits

struct anonymous_namespace{GLGizmoSVG.cpp}::Limits
Collaboration diagram for anonymous_namespace{GLGizmoSVG.cpp}::Limits:
Class Members
MinMax< float > angle {-180.f, 180.f}
MinMax< double > depth {0.01, 1e4}
MinMax< double > relative_scale_ratio {1e-5, 1e4}
MinMax< float > size {0.01f, 1e4f}
MinMax< float > ui_size {5.f, 100.f}
MinMax< float > ui_size_in {.1f, 4.f}

◆ anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg

struct anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg
Collaboration diagram for anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg:
Class Members
bool dark_mode = false
float icon_width = 0.f
float input_offset = 0.f
float input_width = 0.f
float lock_offset = 0.f
float max_tooltip_width = 0.f
double screen_scale = -1.
unsigned texture_max_size_px = 256
Translations translations

Enumeration Type Documentation

◆ IconState

enum class anonymous_namespace{GLGizmoSVG.cpp}::IconState : unsigned
strong
Enumerator
activable 
hovered 
disabled 
189: unsigned { activable = 0, hovered /*1*/, disabled /*2*/ };
@ disabled
Definition GLGizmoEmboss.cpp:223
@ activable
Definition GLGizmoEmboss.cpp:223
@ hovered
Definition GLGizmoEmboss.cpp:223

◆ IconType

enum class anonymous_namespace{GLGizmoSVG.cpp}::IconType : unsigned
strong
Enumerator
reset_value 
refresh 
change_file 
bake 
save 
exclamation 
lock 
unlock 
reflection_x 
reflection_y 
_count 
171 : unsigned {
173 refresh,
175 bake,
176 save,
178 lock,
179 unlock,
182 // automatic calc of icon's count
183 _count
184};
@ exclamation
Definition GLGizmoEmboss.cpp:208
@ save
Definition GLGizmoEmboss.cpp:200
@ unlock
Definition GLGizmoEmboss.cpp:211
@ _count
Definition GLGizmoEmboss.cpp:220
@ lock
Definition GLGizmoEmboss.cpp:209
@ refresh
Definition GLGizmoSVG.cpp:173
@ reflection_y
Definition GLGizmoSVG.cpp:181
@ bake
Definition GLGizmoSVG.cpp:175
@ reset_value
Definition GLGizmoSVG.cpp:172
@ change_file
Definition GLGizmoSVG.cpp:174
@ reflection_x
Definition GLGizmoSVG.cpp:180

Function Documentation

◆ add_comma_separated()

void anonymous_namespace{GLGizmoSVG.cpp}::add_comma_separated ( std::string & result,
const std::string & add )
1050 {
1051 if (!result.empty())
1052 result += ", ";
1053 result += add;
1054}

References add_comma_separated().

Referenced by add_comma_separated(), create_fill_warning(), and create_stroke_warning().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ choose_svg_file()

std::string anonymous_namespace{GLGizmoSVG.cpp}::choose_svg_file ( )

Open file dialog with svg files.

Returns
File path to svg
2208{
2209 wxWindow *parent = nullptr;
2210 wxString message = _L("Choose SVG file for emboss:");
2211 wxString selected_file = wxEmptyString;
2212 wxString wildcard = file_wildcards(FT_SVG);
2213 long style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
2214 wxFileDialog dialog(parent, message, last_used_directory, selected_file, wildcard, style);
2215 if (dialog.ShowModal() != wxID_OK) {
2216 BOOST_LOG_TRIVIAL(warning) << "SVG file for emboss was NOT selected.";
2217 return {};
2218 }
2219
2220 wxArrayString input_files;
2221 dialog.GetPaths(input_files);
2222 if (input_files.IsEmpty()) {
2223 BOOST_LOG_TRIVIAL(warning) << "SVG file dialog result is empty.";
2224 return {};
2225 }
2226
2227 if (input_files.size() != 1)
2228 BOOST_LOG_TRIVIAL(warning) << "SVG file dialog result contain multiple files but only first is used.";
2229
2230 std::string path = into_u8(input_files.front());
2231 if (!boost::filesystem::exists(path)) {
2232 BOOST_LOG_TRIVIAL(warning) << "SVG file dialog return invalid path.";
2233 return {};
2234 }
2235
2236 if (!boost::algorithm::iends_with(path, ".svg")) {
2237 BOOST_LOG_TRIVIAL(warning) << "SVG file dialog return path without '.svg' tail";
2238 return {};
2239 }
2240
2241 last_used_directory = dialog.GetDirectory();
2242 return path;
2243}
#define _L(s)
Definition OBJ.cpp:34
#define style
Definition WipeTowerDialog.cpp:101
@ FT_SVG
Definition GUI_App.hpp:133
wxString file_wildcards(FileType file_type, const std::string &custom_extension)
Definition GUI_App.cpp:695
std::string into_u8(const wxString &str)
Definition GUI.cpp:549
wxString last_used_directory
Definition GLGizmoSVG.cpp:116

References _L, choose_svg_file(), Slic3r::GUI::file_wildcards(), Slic3r::GUI::FT_SVG, Slic3r::GUI::into_u8(), last_used_directory, and style.

Referenced by choose_svg_file(), and select_shape().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_emboss_data_base()

DataBasePtr anonymous_namespace{GLGizmoSVG.cpp}::create_emboss_data_base ( std::shared_ptr< std::atomic< bool > > & cancel,
ModelVolumeType volume_type,
std::string_view filepath = "" )

Create new embos data.

Parameters
cancelCancel for previous job
volume_typeTo distiquish whether it is outside of model
filepathSVG file path
Returns
Base data for emboss SVG
2292{
2293 EmbossShape shape = select_shape(filepath);
2294
2295 if (shape.shapes_with_ids.empty())
2296 // canceled selection of SVG file
2297 return nullptr;
2298
2299 // Cancel previous Job, when it is in process
2300 // worker.cancel(); --> Use less in this case I want cancel only previous EmbossJob no other jobs
2301 // Cancel only EmbossUpdateJob no others
2302 if (cancel != nullptr)
2303 cancel->store(true);
2304 // create new shared ptr to cancel new job
2305 cancel = std::make_shared<std::atomic<bool>>(false);
2306
2307 std::string name = volume_name(shape);
2308
2309 auto result = std::make_unique<DataBase>(name, cancel /*copy*/, std::move(shape));
2310 result->is_outside = volume_type == ModelVolumeType::MODEL_PART;
2311 return result;
2312}
EmbossShape select_shape(std::string_view filepath="", double tesselation_tolerance_in_mm=get_tesselation_tolerance(1.))
Let user to choose file with (S)calable (V)ector (G)raphics - SVG. Than let select contour.
Definition GLGizmoSVG.cpp:2245
std::string volume_name(const EmbossShape &shape)
Create volume name from shape information.
Definition GLGizmoSVG.cpp:2142
Contain plane shape information to be able emboss it and edit it.
Definition EmbossShape.hpp:66
ExPolygonsWithIds shapes_with_ids
Definition EmbossShape.hpp:68

References create_emboss_data_base(), Slic3r::MODEL_PART, select_shape(), Slic3r::EmbossShape::shapes_with_ids, and volume_name().

Referenced by create_emboss_data_base().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_fill_warning()

std::string anonymous_namespace{GLGizmoSVG.cpp}::create_fill_warning ( const NSVGshape & shape)
1057 {
1058 if (!(shape.flags & NSVG_FLAGS_VISIBLE) ||
1059 shape.fill.type == NSVG_PAINT_NONE)
1060 return {}; // not visible
1061
1062 std::string warning;
1063 if ((shape.opacity - 1.f + warning_preccission) <= 0.f)
1064 add_comma_separated(warning, GUI::format(_L("Opacity (%1%)"), shape.opacity));
1065
1066 // if(shape->flags != NSVG_FLAGS_VISIBLE) add_warning(_u8L("Visibility flag"));
1067 bool is_fill_gradient = shape.fillGradient[0] != '\0';
1068 if (is_fill_gradient)
1069 add_comma_separated(warning, GUI::format(_L("Color gradient (%1%)"), shape.fillGradient));
1070
1071 switch (shape.fill.type) {
1072 case NSVG_PAINT_UNDEF: add_comma_separated(warning, _u8L("Undefined fill type")); break;
1073 case NSVG_PAINT_LINEAR_GRADIENT:
1074 if (!is_fill_gradient)
1075 add_comma_separated(warning, _u8L("Linear gradient"));
1076 break;
1077 case NSVG_PAINT_RADIAL_GRADIENT:
1078 if (!is_fill_gradient)
1079 add_comma_separated(warning, _u8L("Radial gradient"));
1080 break;
1081 // case NSVG_PAINT_NONE:
1082 // case NSVG_PAINT_COLOR:
1083 // default: break;
1084 }
1085
1086 // Unfilled is only line which could be opened
1087 if (shape.fill.type != NSVG_PAINT_NONE && !is_closed(shape.paths))
1088 add_comma_separated(warning, _u8L("Open filled path"));
1089 return warning;
1090}
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
bool is_closed(NSVGpath *path)
Definition GLGizmoSVG.cpp:1043
void add_comma_separated(std::string &result, const std::string &add)
Definition GLGizmoSVG.cpp:1050
const float warning_preccission
Definition GLGizmoSVG.cpp:1056
#define _u8L(s)
Definition I18N.hpp:11

References _L, _u8L, add_comma_separated(), create_fill_warning(), Slic3r::GUI::format(), is_closed(), and warning_preccission.

Referenced by create_fill_warning(), and create_shape_warnings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_gui_configuration()

GuiCfg anonymous_namespace{GLGizmoSVG.cpp}::create_gui_configuration ( )
2159 {
2160 GuiCfg cfg; // initialize by default values;
2161
2162 float line_height = ImGui::GetTextLineHeight();
2163 float line_height_with_spacing = ImGui::GetTextLineHeightWithSpacing();
2164
2165 float space = line_height_with_spacing - line_height;
2166
2167 cfg.icon_width = std::max(std::round(line_height/8)*8, 8.f);
2168
2170
2171 float lock_width = cfg.icon_width + 3 * space;
2172 // TRN - Input label. Be short as possible
2173 tr.depth = _u8L("Depth");
2174 // TRN - Input label. Be short as possible
2175 tr.size = _u8L("Size");
2176 // TRN - Input label. Be short as possible
2177 tr.use_surface = _u8L("Use surface");
2178 // TRN - Input label. Be short as possible
2179 tr.distance = _u8L("From surface");
2180 // TRN - Input label. Be short as possible
2181 tr.rotation = _u8L("Rotation");
2182 // TRN - Input label. Be short as possible
2183 tr.mirror = _u8L("Mirror");
2184 float max_tr_width = std::max({
2185 ImGui::CalcTextSize(tr.depth.c_str()).x,
2186 ImGui::CalcTextSize(tr.size.c_str()).x + lock_width,
2187 ImGui::CalcTextSize(tr.use_surface.c_str()).x,
2188 ImGui::CalcTextSize(tr.distance.c_str()).x,
2189 ImGui::CalcTextSize(tr.rotation.c_str()).x + lock_width,
2190 ImGui::CalcTextSize(tr.mirror.c_str()).x,
2191 });
2192
2193 const ImGuiStyle &style = ImGui::GetStyle();
2194 cfg.input_offset = style.WindowPadding.x + max_tr_width + space + cfg.icon_width;
2195 cfg.lock_offset = cfg.input_offset - (cfg.icon_width + 2 * space);
2196
2197 ImVec2 letter_m_size = ImGui::CalcTextSize("M");
2198 const float count_letter_M_in_input = 12.f;
2199 cfg.input_width = letter_m_size.x * count_letter_M_in_input;
2200 cfg.texture_max_size_px = std::round((cfg.input_width + cfg.input_offset + cfg.icon_width + space)/8) * 8;
2201
2202 cfg.max_tooltip_width = ImGui::GetFontSize() * 20.0f;
2203
2204 return cfg;
2205}
std::string depth
Definition GLGizmoSVG.cpp:218
std::string rotation
Definition GLGizmoSVG.cpp:221
std::string distance
Definition GLGizmoSVG.cpp:222
float lock_offset
Definition GLGizmoSVG.cpp:214
float icon_width
Definition GLGizmoSVG.cpp:209
float max_tooltip_width
Definition GLGizmoSVG.cpp:211
float input_width
Definition GLGizmoSVG.cpp:206
std::string use_surface
Definition GLGizmoSVG.cpp:220
std::string size
Definition GLGizmoSVG.cpp:219
float input_offset
Definition GLGizmoSVG.cpp:207
unsigned texture_max_size_px
Definition GLGizmoSVG.cpp:204
std::string mirror
Definition GLGizmoSVG.cpp:223
Translations translations
Definition GLGizmoSVG.cpp:225
Definition GLGizmoSVG.cpp:198

References _u8L, create_gui_configuration(), anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::Translations::depth, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::Translations::distance, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::icon_width, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::input_offset, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::input_width, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::lock_offset, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::max_tooltip_width, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::Translations::mirror, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::Translations::rotation, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::Translations::size, style, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::texture_max_size_px, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::translations, and anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::Translations::use_surface.

Referenced by create_gui_configuration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_input()

CreateVolumeParams anonymous_namespace{GLGizmoSVG.cpp}::create_input ( GLCanvas3D & canvas,
RaycastManager & raycaster,
ModelVolumeType volume_type )

Create input for volume creation.

Parameters
canvasparent of gizmo
raycasterKeep scene
volume_typeType of volume to be created
Returns
Params
2151{
2152 auto gizmo = static_cast<unsigned char>(GLGizmosManager::Svg);
2153 const GLVolume *gl_volume = get_first_hovered_gl_volume(canvas);
2154 Plater *plater = wxGetApp().plater();
2155 return CreateVolumeParams{canvas, plater->get_camera(), plater->build_volume(),
2156 plater->get_ui_job_worker(), volume_type, raycaster, gizmo, gl_volume};
2157}
Definition 3DScene.hpp:90
@ Svg
Definition GLGizmosManager.hpp:100
Definition Plater.hpp:337
shorten params for start_crate_volume functions
Definition EmbossJob.hpp:206
GLVolume * get_first_hovered_gl_volume(const GLCanvas3D &canvas)
Definition GLCanvas3D.cpp:12990
static Plater * plater()
Definition GUI_Factories.cpp:400

References create_input(), Slic3r::GUI::get_first_hovered_gl_volume(), Slic3r::GUI::plater(), and Slic3r::GUI::GLGizmosManager::Svg.

Referenced by create_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_shape_warnings()

std::vector< std::string > anonymous_namespace{GLGizmoSVG.cpp}::create_shape_warnings ( const EmbossShape & shape,
float scale )

Create warnings about shape.

Parameters
imageInput svg loaded to shapes
Returns
Vector of warnings with same size as EmbossShape::shapes_with_ids or Empty when no warnings -> for fast checking that every thing is all right(more common case)
1131 {
1132 const std::shared_ptr<NSVGimage>& image_ptr = shape.svg_file->image;
1133 assert(image_ptr != nullptr);
1134 if (image_ptr == nullptr)
1135 return {std::string{"Uninitialized SVG image"}};
1136
1137 const NSVGimage &image = *image_ptr;
1138 std::vector<std::string> result;
1139 auto add_warning = [&result, &image](size_t index, const std::string &message) {
1140 if (result.empty())
1141 result = std::vector<std::string>(get_shapes_count(image) * 2);
1142 std::string &res = result[index];
1143 if (res.empty())
1144 res = message;
1145 else
1146 res += '\n' + message;
1147 };
1148
1149 if (!shape.final_shape.is_healed) {
1150 for (const ExPolygonsWithId &i : shape.shapes_with_ids)
1151 if (!i.is_healed)
1152 add_warning(i.id, _u8L("Path can't be healed from self-intersection and multiple points."));
1153
1154 // This waning is not connected to NSVGshape. It is about union of paths, but Zero index is shown first
1155 size_t index = 0;
1156 add_warning(index, _u8L("Final shape contains self-intersection or multiple points with same coordinate."));
1157 }
1158
1159 size_t shape_index = 0;
1160 for (NSVGshape *shape = image.shapes; shape != NULL; shape = shape->next, ++shape_index) {
1161 if (!(shape->flags & NSVG_FLAGS_VISIBLE)){
1162 add_warning(shape_index * 2, GUI::format(_L("Shape is marked as invisible (%1%)."), shape->id));
1163 continue;
1164 }
1165
1166 std::string fill_warning = create_fill_warning(*shape);
1167 if (!fill_warning.empty()) {
1168 // TRN: The first placeholder is shape identifier, the second is text describing the problem.
1169 add_warning(shape_index * 2, GUI::format(_L("Fill of shape (%1%) contains unsupported: %2%."), shape->id, fill_warning));
1170 }
1171
1172 float minimal_width_in_mm = 1e-3f;
1173 if (shape->strokeWidth <= minimal_width_in_mm * scale) {
1174 add_warning(shape_index * 2, GUI::format(_L("Stroke of shape (%1%) is too thin (minimal width is %2% mm)."), shape->id, minimal_width_in_mm));
1175 continue;
1176 }
1177 std::string stroke_warning = create_stroke_warning(*shape);
1178 if (!stroke_warning.empty())
1179 add_warning(shape_index * 2 + 1, GUI::format(_L("Stroke of shape (%1%) contains unsupported: %2%."), shape->id, stroke_warning));
1180 }
1181 return result;
1182}
int scale(const int val)
Definition WipeTowerDialog.cpp:58
size_t get_shapes_count(const NSVGimage &image)
Iterate over shapes and calculate count.
Definition NSVGUtils.cpp:155
unsigned id
Definition EmbossShape.hpp:51
bool is_healed
Definition EmbossShape.hpp:58
std::string create_fill_warning(const NSVGshape &shape)
Definition GLGizmoSVG.cpp:1057
std::string create_stroke_warning(const NSVGshape &shape)
Definition GLGizmoSVG.cpp:1092
HealedExPolygons final_shape
Definition EmbossShape.hpp:74
std::optional< SvgFile > svg_file
Definition EmbossShape.hpp:122
bool is_healed
Definition EmbossShape.hpp:40

References _L, _u8L, create_fill_warning(), create_shape_warnings(), create_stroke_warning(), Slic3r::EmbossShape::final_shape, Slic3r::GUI::format(), Slic3r::get_shapes_count(), Slic3r::ExPolygonsWithId::id, Slic3r::ExPolygonsWithId::is_healed, Slic3r::HealedExPolygons::is_healed, scale(), Slic3r::EmbossShape::shapes_with_ids, and Slic3r::EmbossShape::svg_file.

Referenced by create_shape_warnings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_stroke_warning()

std::string anonymous_namespace{GLGizmoSVG.cpp}::create_stroke_warning ( const NSVGshape & shape)
1092 {
1093
1094 std::string warning;
1095 if (!(shape.flags & NSVG_FLAGS_VISIBLE) ||
1096 shape.stroke.type == NSVG_PAINT_NONE ||
1097 shape.strokeWidth <= 1e-5f)
1098 return {}; // not visible
1099
1100 if ((shape.opacity - 1.f + warning_preccission) <= 0.f)
1101 add_comma_separated(warning, GUI::format(_L("Opacity (%1%)"), shape.opacity));
1102
1103 bool is_stroke_gradient = shape.strokeGradient[0] != '\0';
1104 if (is_stroke_gradient)
1105 add_comma_separated(warning, GUI::format(_L("Color gradient (%1%)"), shape.strokeGradient));
1106
1107 switch (shape.stroke.type) {
1108 case NSVG_PAINT_UNDEF: add_comma_separated(warning, _u8L("Undefined stroke type")); break;
1109 case NSVG_PAINT_LINEAR_GRADIENT:
1110 if (!is_stroke_gradient)
1111 add_comma_separated(warning, _u8L("Linear gradient"));
1112 break;
1113 case NSVG_PAINT_RADIAL_GRADIENT:
1114 if (!is_stroke_gradient)
1115 add_comma_separated(warning, _u8L("Radial gradient"));
1116 break;
1117 // case NSVG_PAINT_COLOR:
1118 // case NSVG_PAINT_NONE:
1119 // default: break;
1120 }
1121
1122 return warning;
1123}

References _L, _u8L, add_comma_separated(), create_stroke_warning(), Slic3r::GUI::format(), and warning_preccission.

Referenced by create_shape_warnings(), and create_stroke_warning().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_texture()

void anonymous_namespace{GLGizmoSVG.cpp}::delete_texture ( Texture & texture)
1251 {
1252 if (texture.id != 0) {
1253 glsafe(::glDeleteTextures(1, &texture.id));
1254 texture.id = 0;
1255 }
1256}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
#define glDeleteTextures
Definition gl.h:3587
unsigned id
Definition GLGizmoSVG.hpp:38

References delete_texture(), glDeleteTextures, glsafe, and Slic3r::GUI::Texture::id.

Referenced by delete_texture().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ draw_clickable()

bool anonymous_namespace{GLGizmoSVG.cpp}::draw_clickable ( const IconManager::VIcons & icons,
IconType type )
461{
462 return clickable(get_icon(icons, type, IconState::activable), get_icon(icons, type, IconState::hovered));
463}
bool clickable(const IconManager::Icon &icon, const IconManager::Icon &icon_hover)
Draw icon which change on hover.
Definition IconManager.cpp:399
@ activable
Definition GLGizmoSVG.cpp:189
@ hovered
Definition GLGizmoSVG.cpp:189
const IconManager::Icon & get_icon(const IconManager::VIcons &icons, IconType type, IconState state)
Definition GLGizmoSVG.cpp:191

References activable, Slic3r::GUI::clickable(), draw_clickable(), get_icon(), and hovered.

Referenced by draw_clickable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ draw_filled()

template<unsigned int N>
void anonymous_namespace{GLGizmoSVG.cpp}::draw_filled ( const ExPolygons & shape,
const std::array< unsigned char, N > & color,
std::vector< unsigned char > & data,
size_t data_width,
double scale )

Draw filled ExPolygon into data line by line inspired by: http://alienryderflex.com/polygon_fill/.

Template Parameters
NCount channels for one pixel(RGBA = 4)
Parameters
shapeShape to draw
colorColor of shape contain count of channels(N)
dataImage(2d) stored in 1d array
data_widthCount of pixel on one line(size in data = N x data_width)
scaleShape scale for conversion to pixels
857 {
858 assert(data.size() % N == 0);
859 assert(data.size() % data_width == 0);
860 assert((data.size() % (N*data_width)) == 0);
861
862 BoundingBox bb_unscaled = get_extents(shape);
863
864 Linesf lines = to_linesf(shape);
865 BoundingBoxf bb(
866 bb_unscaled.min.cast<double>(),
867 bb_unscaled.max.cast<double>());
868
869 // scale lines to pixels
870 if (!is_approx(scale, 1.)) {
871 for (Linef &line : lines) {
872 line.a *= scale;
873 line.b *= scale;
874 }
875 bb.min *= scale;
876 bb.max *= scale;
877 }
878
879 int count_lines = data.size() / (N * data_width);
880 size_t data_line = N * data_width;
881 auto get_offset = [count_lines, data_line](int x, int y) {
882 // NOTE: y has opposit direction in texture
883 return (count_lines - y - 1) * data_line + x * N;
884 };
885 auto set_color = [&data, &color, get_offset](int x, int y) {
886 size_t offset = get_offset(x, y);
887 if (data[offset + N - 1] != 0)
888 return; // already setted by line
889 for (unsigned i = 0; i < N; ++i)
890 data[offset + i] = color[i];
891 };
892
893 // anti aliased drawing of lines
894 auto draw = [&data, width = static_cast<int>(data_width), count_lines, get_offset, &color](int x, int y, float brightess) {
895 if (x < 0 || y < 0 || x >= width || y >= count_lines)
896 return; // out of image
897 size_t offset = get_offset(x, y);
898 unsigned char &alpha = data[offset + N - 1];
899 if (alpha == 0){
900 alpha = static_cast<unsigned char>(std::round(brightess * 255));
901 for (size_t i = 0; i < N-1; ++i)
902 data[offset + i] = color[i];
903 } else if (alpha != 255){
904 alpha = static_cast<unsigned char>(std::min(255, int(alpha) + static_cast<int>(std::round(brightess * 255))));
905 }
906 };
907
908 for (const Linef& line: lines)
909 wu_draw_line_side(line, draw);
910
912
913 // range for intersection line
914 double x1 = bb.min.x() - 1.f;
915 double x2 = bb.max.x() + 1.f;
916
917 int max_y = std::min(count_lines, static_cast<int>(std::round(bb.max.y())));
918 for (int y = std::max(0, static_cast<int>(std::round(bb.min.y()))); y < max_y; ++y){
919 double y_f = y + .5; // 0.5 ... intersection in center of pixel of pixel
920 Linef line(Vec2d(x1, y_f), Vec2d(x2, y_f));
921 using Intersection = std::pair<Vec2d, size_t>;
922 using Intersections = std::vector<Intersection>;
923 // sorted .. false
924 // <false, Vec2d, Linef, decltype(tree)>
925 Intersections intersections = Slic3r::AABBTreeLines::get_intersections_with_line<false, Vec2d, Linef>(lines, tree, line);
926 if (intersections.empty())
927 continue;
928
929 assert((intersections.size() % 2) == 0);
930
931 // sort intersections by x
932 std::sort(intersections.begin(), intersections.end(),
933 [](const Intersection &i1, const Intersection &i2) { return i1.first.x() < i2.first.x(); });
934
935 // draw lines
936 for (size_t i = 0; i < intersections.size(); i+=2) {
937 const Vec2d& p2 = intersections[i+1].first;
938 if (p2.x() < 0)
939 continue; // out of data
940
941 const Vec2d& p1 = intersections[i].first;
942 if (p1.x() > data_width)
943 break; // out of data
944
945 // clamp to data
946 int max_x = std::min(static_cast<int>(data_width-1), static_cast<int>(std::round(p2.x())));
947 for (int x = std::max(0, static_cast<int>(std::round(p1.x()))); x <= max_x; ++x)
948 set_color(x, y);
949 }
950 }
951}
PointType max
Definition BoundingBox.hpp:21
PointType min
Definition BoundingBox.hpp:20
Definition BoundingBox.hpp:212
Definition BoundingBox.hpp:257
Definition Line.hpp:255
std::vector< std::pair< VectorType, size_t > > get_intersections_with_line(const std::vector< LineType > &lines, const TreeType &tree, const LineType &line)
Definition AABBTreeLines.hpp:276
AABBTreeIndirect::Tree< LineType::Dim, typename LineType::Scalar > build_aabb_tree_over_indexed_lines(const std::vector< LineType > &lines)
Definition AABBTreeLines.hpp:172
void draw(const IconManager::Icon &icon, const ImVec2 &size, const ImVec4 &tint_col, const ImVec4 &border_col)
Draw imgui image with icon.
Definition IconManager.cpp:373
@ Intersection
Definition GLGizmoMeshBoolean.hpp:28
@ N
Definition CalibrationWizardSavePage.cpp:124
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184
Linesf to_linesf(const ExPolygons &src, uint32_t count_lines=0)
Definition ExPolygon.hpp:154
BoundingBox get_extents(const ExPolygonsWithIds &e)
Definition Emboss.cpp:1374
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:582
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:320
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67
std::vector< Linef > Linesf
Definition Line.hpp:270
void wu_draw_line_side(Linef line, const std::function< void(int x, int y, float brightess)> &plot)
Definition GLGizmoSVG.cpp:606

References Slic3r::Linef::a, Slic3r::Linef::b, Slic3r::AABBTreeLines::build_aabb_tree_over_indexed_lines(), Slic3r::GUI::draw(), draw_filled(), Slic3r::get_extents(), Slic3r::AABBTreeLines::get_intersections_with_line(), Slic3r::is_approx(), Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, Slic3r::GUI::N, Slic3r::offset(), scale(), Slic3r::to_linesf(), and wu_draw_line_side().

Referenced by draw_filled(), and init_texture().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ draw_side_outline()

template<unsigned int N>
void anonymous_namespace{GLGizmoSVG.cpp}::draw_side_outline ( const ExPolygons & shape,
const std::array< unsigned char, N > & color,
std::vector< unsigned char > & data,
size_t data_width,
double scale )
799{
800 int count_lines = data.size() / (N * data_width);
801 size_t data_line = N * data_width;
802 auto get_offset = [count_lines, data_line](int x, int y) {
803 // NOTE: y has opposit direction in texture
804 return (count_lines - y - 1) * data_line + x * N;
805 };
806
807 // overlap color
808 auto draw = [&data, data_width, count_lines, get_offset, &color](int x, int y, float brightess) {
809 if (x < 0 || y < 0 || static_cast<size_t>(x) >= data_width || y >= count_lines)
810 return; // out of image
811 size_t offset = get_offset(x, y);
812 bool change_color = false;
813 for (size_t i = 0; i < N - 1; ++i) {
814 if(data[offset + i] != color[i]){
815 data[offset + i] = color[i];
816 change_color = true;
817 }
818 }
819
820 unsigned char &alpha = data[offset + N - 1];
821 if (alpha == 0 || change_color){
822 alpha = static_cast<unsigned char>(std::round(brightess * 255));
823 } else if (alpha != 255){
824 alpha = static_cast<unsigned char>(std::min(255, int(alpha) + static_cast<int>(std::round(brightess * 255))));
825 }
826 };
827
828 BoundingBox bb_unscaled = get_extents(shape);
829 Linesf lines = to_linesf(shape);
830 BoundingBoxf bb(bb_unscaled.min.cast<double>(), bb_unscaled.max.cast<double>());
831
832 // scale lines to pixels
833 if (!is_approx(scale, 1.)) {
834 for (Linef &line : lines) {
835 line.a *= scale;
836 line.b *= scale;
837 }
838 bb.min *= scale;
839 bb.max *= scale;
840 }
841
842 for (const Linef &line : lines)
843 wu_draw_line_side(line, draw);
844}

References Slic3r::Linef::a, Slic3r::Linef::b, Slic3r::GUI::draw(), draw_side_outline(), Slic3r::get_extents(), Slic3r::is_approx(), Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, Slic3r::GUI::N, Slic3r::offset(), scale(), Slic3r::to_linesf(), and wu_draw_line_side().

Referenced by draw_side_outline(), and init_texture().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_file_name()

std::string anonymous_namespace{GLGizmoSVG.cpp}::get_file_name ( const std::string & file_path)

Separate file name from file path. String after last delimiter and before last point.

Parameters
file_pathpath return by file dialog
Returns
File name without directory path
2118{
2119 if (file_path.empty())
2120 return file_path;
2121
2122 size_t pos_last_delimiter = file_path.find_last_of("/\\");
2123 if (pos_last_delimiter == std::string::npos) {
2124 // should not happend that in path is not delimiter
2125 assert(false);
2126 pos_last_delimiter = 0;
2127 }
2128
2129 size_t pos_point = file_path.find_last_of('.');
2130 if (pos_point == std::string::npos || pos_point < pos_last_delimiter // last point is inside of directory path
2131 ) {
2132 // there is no extension
2133 assert(false);
2134 pos_point = file_path.size();
2135 }
2136
2137 size_t offset = pos_last_delimiter + 1; // result should not contain last delimiter ( +1 )
2138 size_t count = pos_point - pos_last_delimiter - 1; // result should not contain extension point ( -1 )
2139 return file_path.substr(offset, count);
2140}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246

References count, get_file_name(), and Slic3r::offset().

Referenced by get_file_name(), and volume_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_icon()

const IconManager::Icon & anonymous_namespace{GLGizmoSVG.cpp}::get_icon ( const IconManager::VIcons & icons,
IconType type,
IconState state )
191 {
192 return *icons[(unsigned) type][(unsigned) state]; }

References get_icon().

Referenced by draw_clickable(), get_icon(), and reset_button().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tesselation_tolerance()

double anonymous_namespace{GLGizmoSVG.cpp}::get_tesselation_tolerance ( double scale)
124 {
125 double tesselation_tolerance_in_mm = .1; //8e-2;
126 double tesselation_tolerance_scaled = (tesselation_tolerance_in_mm*tesselation_tolerance_in_mm) / SCALING_FACTOR / SCALING_FACTOR;
127 return tesselation_tolerance_scaled / scale / scale;
128}
double SCALING_FACTOR
Definition libslic3r.cpp:3

References get_tesselation_tolerance(), scale(), and SCALING_FACTOR.

Referenced by get_tesselation_tolerance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_icons()

IconManager::VIcons anonymous_namespace{GLGizmoSVG.cpp}::init_icons ( IconManager & mng,
const GuiCfg & cfg )
426{
427 mng.release();
428
429 ImVec2 size(cfg.icon_width, cfg.icon_width);
430 // icon order has to match the enum IconType
431 std::vector<std::string> filenames{
432 "undo.svg", // reset_value
433 "refresh.svg", // refresh
434 "open.svg", // changhe_file
435 "burn.svg", // bake
436 "save.svg", // save
437 "obj_warning.svg", // exclamation // ORCA: use obj_warning instead exclamation. exclamation is not compatible with low res
438 "lock_closed.svg", // lock
439 "lock_open.svg", // unlock
440 "reflection_x.svg", // reflection_x
441 "reflection_y.svg", // reflection_y
442 };
443
444 assert(filenames.size() == static_cast<size_t>(IconType::_count));
445 std::string path = resources_dir() + "/images/";
446 for (std::string &filename : filenames) filename = path + filename;
447
448 auto type = IconManager::RasterType::color_wite_gray;
449 return mng.init(filenames, size, type);
450
451 //IconManager::VIcons vicons = mng.init(init_types);
452 //
454 //IconManager::Icons icons;
455 //icons.reserve(vicons.size());
456 //for (IconManager::Icons &i : vicons)
457 // icons.push_back(i.front());
458 //return icons;
459}
void release()
Release icons which are hold only by this manager May change texture and position of icons.
Definition IconManager.cpp:301
Icons init(const InitTypes &input)
Initialize raster texture on GPU with given images NOTE: Have to be called after OpenGL initializatio...
Definition IconManager.cpp:81
const std::string & resources_dir()
Definition utils.cpp:296

References _count, Slic3r::GUI::IconManager::color_wite_gray, anonymous_namespace{GLGizmoSVG.cpp}::GuiCfg::icon_width, Slic3r::GUI::IconManager::init(), init_icons(), Slic3r::GUI::IconManager::release(), and Slic3r::resources_dir().

Referenced by init_icons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_texture()

bool anonymous_namespace{GLGizmoSVG.cpp}::init_texture ( Texture & texture,
const ExPolygonsWithIds & shapes_with_ids,
unsigned max_size_px,
const std::vector< std::string > & shape_warnings )
967 {
968 BoundingBox bb = get_extents(shapes_with_ids);
969 Point bb_size = bb.size();
970 double bb_width = bb_size.x(); // [in mm]
971 double bb_height = bb_size.y(); // [in mm]
972
973 bool is_widder = bb_size.x() > bb_size.y();
974 double scale = 0.f;
975 if (is_widder) {
976 scale = max_size_px / bb_width;
977 texture.width = max_size_px;
978 texture.height = static_cast<unsigned>(std::ceil(bb_height * scale));
979 } else {
980 scale = max_size_px / bb_height;
981 texture.width = static_cast<unsigned>(std::ceil(bb_width * scale));
982 texture.height = max_size_px;
983 }
984 const int n_pixels = texture.width * texture.height;
985 if (n_pixels <= 0)
986 return false;
987
988 constexpr int channels_count = 4;
989 std::vector<unsigned char> data(n_pixels * channels_count, {0});
990
991 // Union All shapes
992 ExPolygons shape = union_ex(shapes_with_ids);
993
994 // align to texture
995 translate(shape, -bb.min);
996 size_t texture_width = static_cast<size_t>(texture.width);
997 unsigned char alpha = 255; // without transparency
998 std::array<unsigned char, 4> color_shape{201, 201, 201, alpha}; // from degin by @JosefZachar
999 std::array<unsigned char, 4> color_error{237, 28, 36, alpha}; // from icon: resources/icons/flag_red.svg
1000 std::array<unsigned char, 4> color_warning{237, 107, 33, alpha}; // icons orange
1001 // draw unhealedable shape
1002 for (const ExPolygonsWithId &shapes_with_id : shapes_with_ids)
1003 if (!shapes_with_id.is_healed) {
1004 ExPolygons bad_shape = shapes_with_id.expoly; // copy
1005 translate(bad_shape, -bb.min); // align to texture
1006 draw_side_outline<4>(bad_shape, color_error, data, texture_width, scale);
1007 }
1008 // Draw shape with warning
1009 if (!shape_warnings.empty()) {
1010 for (const ExPolygonsWithId &shapes_with_id : shapes_with_ids){
1011 assert(shapes_with_id.id < shape_warnings.size());
1012 if (shapes_with_id.id >= shape_warnings.size())
1013 continue;
1014 if (shape_warnings[shapes_with_id.id].empty())
1015 continue; // no warnings for shape
1016 ExPolygons warn_shape = shapes_with_id.expoly; // copy
1017 translate(warn_shape, -bb.min); // align to texture
1018 draw_side_outline<4>(warn_shape, color_warning, data, texture_width, scale);
1019 }
1020 }
1021
1022 // Draw rest of shape
1023 draw_filled<4>(shape, color_shape, data, texture_width, scale);
1024
1025 // sends data to gpu
1027 if (texture.id != 0)
1028 glsafe(::glDeleteTextures(1, &texture.id));
1029 glsafe(::glGenTextures(1, &texture.id));
1032 (const void *) data.data()));
1033
1037
1038 GLuint NO_TEXTURE_ID = 0;
1039 glsafe(::glBindTexture(GL_TEXTURE_2D, NO_TEXTURE_ID));
1040 return true;
1041}
PointType size() const
Definition BoundingBox.cpp:178
Definition Point.hpp:199
#define GL_TEXTURE_MIN_FILTER
Definition gl.h:1828
#define glPixelStorei
Definition gl.h:4451
#define GL_TEXTURE_MAX_LEVEL
Definition gl.h:1826
#define GL_LINEAR
Definition gl.h:930
#define glTexParameteri
Definition gl.h:4911
#define glTexImage2D
Definition gl.h:4895
#define GL_UNSIGNED_BYTE
Definition gl.h:1937
#define glGenTextures
Definition gl.h:3787
#define GL_UNPACK_ALIGNMENT
Definition gl.h:1924
int GLsizei
Definition gl.h:2065
#define glBindTexture
Definition gl.h:3299
#define GL_RGBA
Definition gl.h:1493
unsigned int GLuint
Definition gl.h:2063
#define GL_TEXTURE_MAG_FILTER
Definition gl.h:1822
#define GL_TEXTURE_2D
Definition gl.h:1739
unsigned width
Definition GLGizmoSVG.hpp:39
unsigned height
Definition GLGizmoSVG.hpp:40
std::vector< ExPolygon > ExPolygons
Definition ExPolygon.hpp:20
void translate(ExPolygonsWithIds &e, const Point &p)
Definition Emboss.cpp:1368
void draw_side_outline(const ExPolygons &shape, const std::array< unsigned char, N > &color, std::vector< unsigned char > &data, size_t data_width, double scale)
Definition GLGizmoSVG.cpp:798
void draw_filled(const ExPolygons &shape, const std::array< unsigned char, N > &color, std::vector< unsigned char > &data, size_t data_width, double scale)
Draw filled ExPolygon into data line by line inspired by: http://alienryderflex.com/polygon_fill/.
Definition GLGizmoSVG.cpp:857
ExPolygons union_ex(const ExPolygonsWithIds &shapes)
Union shape defined by glyphs.
Definition GLGizmoSVG.cpp:954

References draw_filled(), draw_side_outline(), Slic3r::get_extents(), GL_LINEAR, GL_RGBA, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MAX_LEVEL, GL_TEXTURE_MIN_FILTER, GL_UNPACK_ALIGNMENT, GL_UNSIGNED_BYTE, glBindTexture, glDeleteTextures, glGenTextures, glPixelStorei, glsafe, glTexImage2D, glTexParameteri, Slic3r::GUI::Texture::height, Slic3r::GUI::Texture::id, init_texture(), Slic3r::BoundingBoxBase< PointType, APointsType >::min, scale(), Slic3r::BoundingBoxBase< PointType, APointsType >::size(), Slic3r::translate(), Slic3r::union_ex(), and Slic3r::GUI::Texture::width.

Referenced by init_texture().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_closed()

bool anonymous_namespace{GLGizmoSVG.cpp}::is_closed ( NSVGpath * path)
1043 {
1044 for (; path != NULL; path = path->next)
1045 if (path->next == NULL && path->closed)
1046 return true;
1047 return false;
1048}

References is_closed().

Referenced by create_fill_warning(), and is_closed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_button()

bool anonymous_namespace{GLGizmoSVG.cpp}::reset_button ( const IconManager::VIcons & icons)
466{
467 float reset_offset = ImGui::GetStyle().WindowPadding.x;
468 ImGui::SameLine(reset_offset);
469
470 // from GLGizmoCut
471 //std::string label_id = "neco";
472 //std::string btn_label;
473 //btn_label += ImGui::RevertButton;
474 //return ImGui::Button((btn_label + "##" + label_id).c_str());
475
477 return clickable(icon, icon); // ORCA use orange color for both states
478}

References Slic3r::GUI::clickable(), get_icon(), hovered, reset_button(), and reset_value.

Referenced by reset_button().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ select_shape()

EmbossShape anonymous_namespace{GLGizmoSVG.cpp}::select_shape ( std::string_view filepath = "",
double tesselation_tolerance_in_mm = get_tesselation_tolerance(1.) )

Let user to choose file with (S)calable (V)ector (G)raphics - SVG. Than let select contour.

Parameters
filepathSVG file path, when empty promt user to select one
Returns
EmbossShape to create
2246{
2247 EmbossShape shape;
2248 shape.projection.depth = 10.;
2249 shape.projection.use_surface = false;
2250
2252 if (filepath.empty()) {
2253 // When empty open file dialog
2254 svg.path = choose_svg_file();
2255 if (svg.path.empty())
2256 return {}; // file was not selected
2257 } else {
2258 svg.path = filepath; // copy
2259 }
2260
2261
2262 boost::filesystem::path path(svg.path);
2263 if (!boost::filesystem::exists(path)) {
2264 show_error(nullptr, GUI::format(_u8L("File does NOT exist (%1%)."), svg.path));
2265 return {};
2266 }
2267
2268 if (!boost::algorithm::iends_with(svg.path, ".svg")) {
2269 show_error(nullptr, GUI::format(_u8L("Filename has to end with \".svg\" but you selected %1%"), svg.path));
2270 return {};
2271 }
2272
2273 if(init_image(svg) == nullptr) {
2274 show_error(nullptr, GUI::format(_u8L("Nano SVG parser can't load from file (%1%)."), svg.path));
2275 return {};
2276 }
2277
2278 // Set default and unchanging scale
2279 NSVGLineParams params{tesselation_tolerance};
2280 shape.shapes_with_ids = create_shape_with_ids(*svg.image, params);
2281
2282 // Must contain some shapes !!!
2283 if (shape.shapes_with_ids.empty()) {
2284 show_error(nullptr, GUI::format(_u8L("SVG file does NOT contain a single path to be embossed (%1%)."), svg.path));
2285 return {};
2286 }
2287 shape.svg_file = std::move(svg);
2288 return shape;
2289}
void show_error(wxWindow *parent, const wxString &message, bool has_code_excerpts)
Definition GUI.cpp:296
NSVGimage * init_image(EmbossShape::SvgFile &svg_file)
Definition NSVGUtils.cpp:133
ExPolygonsWithIds create_shape_with_ids(const NSVGimage &image, const NSVGLineParams &param)
Convert .svg opened by nanoSvg to shapes stored in expolygons with ids.
Definition NSVGUtils.cpp:38
std::string choose_svg_file()
Open file dialog with svg files.
Definition GLGizmoSVG.cpp:2207
bool use_surface
Definition EmbossShape.hpp:27
double depth
Definition EmbossShape.hpp:23
Definition EmbossShape.hpp:89
std::string path
Definition EmbossShape.hpp:92
std::shared_ptr< NSVGimage > image
Definition EmbossShape.hpp:101
EmbossProjection projection
Definition EmbossShape.hpp:80

References _u8L, choose_svg_file(), Slic3r::create_shape_with_ids(), Slic3r::EmbossProjection::depth, Slic3r::GUI::format(), Slic3r::EmbossShape::SvgFile::image, Slic3r::init_image(), Slic3r::EmbossShape::SvgFile::path, Slic3r::EmbossShape::projection, select_shape(), Slic3r::EmbossShape::shapes_with_ids, Slic3r::GUI::show_error(), Slic3r::EmbossShape::svg_file, and Slic3r::EmbossProjection::use_surface.

Referenced by create_emboss_data_base(), and select_shape().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ union_ex()

ExPolygons anonymous_namespace{GLGizmoSVG.cpp}::union_ex ( const ExPolygonsWithIds & shapes)

Union shape defined by glyphs.

955{
956 // unify to one expolygon
957 ExPolygons result;
958 for (const ExPolygonsWithId &shape : shapes) {
959 if (shape.expoly.empty())
960 continue;
961 expolygons_append(result, shape.expoly);
962 }
963 return union_ex(result);
964}
void expolygons_append(ExPolygons &dst, const ExPolygons &src)
Definition ExPolygon.hpp:447
Definition EmbossShape.hpp:47

References Slic3r::expolygons_append(), and Slic3r::union_ex().

Here is the call graph for this function:

◆ volume_name()

std::string anonymous_namespace{GLGizmoSVG.cpp}::volume_name ( const EmbossShape & shape)

Create volume name from shape information.

Parameters
shapeFile path
Returns
Name for volume
2143{
2144 std::string file_name = get_file_name(shape.svg_file->path);
2145 if (!file_name.empty())
2146 return file_name;
2147 return _u8L("SVG shape");
2148}
std::string get_file_name(const std::string &file_path)
Separate file name from file path. String after last delimiter and before last point.
Definition GLGizmoSVG.cpp:2117

References _u8L, get_file_name(), Slic3r::EmbossShape::svg_file, and volume_name().

Referenced by create_emboss_data_base(), and volume_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wu_draw_line_side()

void anonymous_namespace{GLGizmoSVG.cpp}::wu_draw_line_side ( Linef line,
const std::function< void(int x, int y, float brightess)> & plot )
607 {
608 auto ipart = [](float x) -> int {return static_cast<int>(std::floor(x));};
609 auto round = [](float x) -> float {return std::round(x);};
610 auto fpart = [](float x) -> float {return x - std::floor(x);};
611 auto rfpart = [=](float x) -> float {return 1 - fpart(x);};
612
613 Vec2d d = line.b - line.a;
614 const bool steep = abs(d.y()) > abs(d.x());
615 bool is_full; // identify full brightness pixel
616 if (steep) {
617 is_full = d.y() >= 0;
618 std::swap(line.a.x(), line.a.y());
619 std::swap(line.b.x(), line.b.y());
620 std::swap(d.x(), d.y());
621 }else
622 is_full = d.x() < 0; // opposit direction of y
623
624 if (line.a.x() > line.b.x()) {
625 std::swap(line.a.x(), line.b.x());
626 std::swap(line.a.y(), line.b.y());
627 d *= -1;
628 }
629 const float gradient = (d.x() == 0) ? 1. : d.y() / d.x();
630
631 int xpx11;
632 float intery;
633 {
634 const float xend = round(line.a.x());
635 const float yend = line.a.y() + gradient * (xend - line.a.x());
636 const float xgap = rfpart(line.a.x() + 0.5f);
637 xpx11 = int(xend);
638 const int ypx11 = ipart(yend);
639 if (steep) {
640 plot(ypx11, xpx11, is_full? 1.f : (rfpart(yend) * xgap));
641 plot(ypx11 + 1, xpx11, !is_full? 1.f : ( fpart(yend) * xgap));
642 } else {
643 plot(xpx11, ypx11, is_full? 1.f : (rfpart(yend) * xgap));
644 plot(xpx11, ypx11 + 1,!is_full? 1.f : ( fpart(yend) * xgap));
645 }
646 intery = yend + gradient;
647 }
648
649 int xpx12;
650 {
651 const float xend = round(line.b.x());
652 const float yend = line.b.y() + gradient * (xend - line.b.x());
653 const float xgap = rfpart(line.b.x() + 0.5f);
654 xpx12 = int(xend);
655 const int ypx12 = ipart(yend);
656 if (steep) {
657 plot(ypx12, xpx12, is_full? 1.f : (rfpart(yend) * xgap));
658 plot(ypx12 + 1, xpx12, !is_full? 1.f : ( fpart(yend) * xgap));
659 } else {
660 plot(xpx12, ypx12, is_full? 1.f : (rfpart(yend) * xgap));
661 plot(xpx12, ypx12 + 1, !is_full? 1.f : ( fpart(yend) * xgap));
662 }
663 }
664
665 if (steep) {
666 if (is_full){
667 for (int x = xpx11 + 1; x < xpx12; x++) {
668 plot(ipart(intery), x, 1.f);
669 plot(ipart(intery) + 1, x, fpart(intery));
670 intery += gradient;
671 }
672 } else {
673 for (int x = xpx11 + 1; x < xpx12; x++) {
674 plot(ipart(intery), x, rfpart(intery));
675 plot(ipart(intery) + 1, x, 1.f );
676 intery += gradient;
677 }
678 }
679 } else {
680 if (is_full){
681 for (int x = xpx11 + 1; x < xpx12; x++) {
682 plot(x, ipart(intery), 1.f);
683 plot(x, ipart(intery) + 1, fpart(intery));
684 intery += gradient;
685 }
686 } else {
687 for (int x = xpx11 + 1; x < xpx12; x++) {
688 plot(x, ipart(intery), rfpart(intery));
689 plot(x, ipart(intery) + 1, 1.f);
690 intery += gradient;
691 }
692 }
693 }
694}
Vec2d b
Definition Line.hpp:265
Vec2d a
Definition Line.hpp:264

References Slic3r::Linef::a, Slic3r::Linef::b, and wu_draw_line_side().

Referenced by draw_filled(), draw_side_outline(), and wu_draw_line_side().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ last_used_directory

wxString anonymous_namespace{GLGizmoSVG.cpp}::last_used_directory = wxEmptyString

Referenced by choose_svg_file().

◆ limits

const struct anonymous_namespace{GLGizmoSVG.cpp}::Limits anonymous_namespace{GLGizmoSVG.cpp}::limits

◆ move_snapshot_name

const std::string anonymous_namespace{GLGizmoSVG.cpp}::move_snapshot_name = L("SVG move")

◆ rotation_snapshot_name

const std::string anonymous_namespace{GLGizmoSVG.cpp}::rotation_snapshot_name = L("SVG rotate")

◆ warning_preccission

const float anonymous_namespace{GLGizmoSVG.cpp}::warning_preccission = 1e-4f