OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::ModelSettingHelper Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/SkipPartCanvas.hpp>

Inheritance diagram for Slic3r::GUI::ModelSettingHelper:
Collaboration diagram for Slic3r::GUI::ModelSettingHelper:

Classes

struct  ParseContext

Public Member Functions

 ModelSettingHelper (const std::string &path)
bool Parse ()
std::vector< ObjectInfo > GetPlateObjects (int plate_idx)
bool GetLabelObjectEnabled (int plate_idx)
void log_errors ()

Protected Member Functions

void add_error (const std::string &error) const
void clear_errors ()

Private Member Functions

void DataHandler (const XML_Char *s, int len)

Static Private Member Functions

static void XMLCALL StartElementHandler (void *userData, const XML_Char *name, const XML_Char **atts)
static void XMLCALL EndElementHandler (void *userData, const XML_Char *name)

Private Attributes

std::string path_
ParseContext context_
boost::mutex mutex
std::vector< std::string > m_errors

Detailed Description


Class Documentation

◆ Slic3r::GUI::ModelSettingHelper::ParseContext

struct Slic3r::GUI::ModelSettingHelper::ParseContext
Collaboration diagram for Slic3r::GUI::ModelSettingHelper::ParseContext:
Class Members
PlateInfo current_plate
bool in_plate = false
vector< PlateInfo > plates
ObjectInfo temp_object

Constructor & Destructor Documentation

◆ ModelSettingHelper()

Slic3r::GUI::ModelSettingHelper::ModelSettingHelper ( const std::string & path)
626: path_(path) {}
std::string path_
Definition SkipPartCanvas.hpp:170

References path_.

Referenced by EndElementHandler(), and StartElementHandler().

Here is the caller graph for this function:

Member Function Documentation

◆ add_error()

void Slic3r::GUI::_BBS_3MF_Base::add_error ( const std::string & error) const
protectedinherited
614{
615 boost::unique_lock l(mutex);
616 m_errors.push_back(error);
617}
boost::mutex mutex
Definition SkipPartCanvas.hpp:134
std::vector< std::string > m_errors
Definition SkipPartCanvas.hpp:135

References m_errors, and mutex.

Referenced by Slic3r::GUI::ModelSettingHelper::Parse().

Here is the caller graph for this function:

◆ clear_errors()

void Slic3r::GUI::_BBS_3MF_Base::clear_errors ( )
protectedinherited
618{ m_errors.clear(); }

References m_errors.

◆ DataHandler()

void Slic3r::GUI::ModelSettingHelper::DataHandler ( const XML_Char * s,
int len )
private
715{
716 // do nothing
717}

◆ EndElementHandler()

void XMLCALL Slic3r::GUI::ModelSettingHelper::EndElementHandler ( void * userData,
const XML_Char * name )
staticprivate
688{
689 ModelSettingHelper *self = static_cast<ModelSettingHelper *>(userData);
690 if (strcmp(name, "plate") == 0 && self->context_.in_plate) {
691 self->context_.plates.push_back(self->context_.current_plate);
692 self->context_.current_plate = PlateInfo(); // reset
693 self->context_.in_plate = false;
694 }
695}
ModelSettingHelper(const std::string &path)
Definition SkipPartCanvas.cpp:626

References ModelSettingHelper(), context_, Slic3r::GUI::ModelSettingHelper::ParseContext::current_plate, Slic3r::GUI::ModelSettingHelper::ParseContext::in_plate, and Slic3r::GUI::ModelSettingHelper::ParseContext::plates.

Referenced by Parse().

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

◆ GetLabelObjectEnabled()

bool Slic3r::GUI::ModelSettingHelper::GetLabelObjectEnabled ( int plate_idx)
707{
708 for (const auto &plate : context_.plates) {
709 if (plate.index == plate_idx) { return plate.label_object_enabled; }
710 }
711 return false;
712}
ParseContext context_
Definition SkipPartCanvas.hpp:171

References context_.

Referenced by Slic3r::GUI::PartSkipDialog::InitDialogUI().

Here is the caller graph for this function:

◆ GetPlateObjects()

std::vector< ObjectInfo > Slic3r::GUI::ModelSettingHelper::GetPlateObjects ( int plate_idx)
697 {
698 for (const auto &plate : context_.plates) {
699 if (plate.index == plate_idx) {
700 return plate.objects;
701 }
702 }
703 return std::vector<ObjectInfo>();
704}

References context_.

Referenced by Slic3r::GUI::PartSkipDialog::InitDialogUI().

Here is the caller graph for this function:

◆ log_errors()

void Slic3r::GUI::_BBS_3MF_Base::log_errors ( )
inherited
621{
622 for (const std::string &error : m_errors) BOOST_LOG_TRIVIAL(error) << error;
623}

References m_errors.

◆ Parse()

bool Slic3r::GUI::ModelSettingHelper::Parse ( )
629{
630 boost::nowide::fstream fs(path_);
631 if (!fs) {
632 add_error("Failed to open file\n");
633 return false;
634 }
635 XML_Parser parser = XML_ParserCreate(nullptr);
636 if (!parser) {
637 add_error("Unable to create parser");
638 return false;
639 }
640 XML_SetUserData(parser, this);
642
643 try {
644 char buffer[4000];
645 while (fs.read(buffer, sizeof(buffer)) || fs.gcount() > 0) {
646 auto ret = XML_Parse(parser, buffer, static_cast<int>(fs.gcount()), fs.eof());
647 if (ret != XML_STATUS_OK) {
648 add_error("return value of XML_Parse doesn't match XM_STATUS_OK");
649 XML_ParserFree(parser);
650 return false;
651 }
652 }
653 }
654 catch (std::exception& e) {
655 add_error(std::string("exception:") + e.what());
656 XML_ParserFree(parser);
657 return false;
658 }
659 XML_ParserFree(parser);
660 return true;
661}
static void XMLCALL StartElementHandler(void *userData, const XML_Char *name, const XML_Char **atts)
Definition SkipPartCanvas.cpp:663
static void XMLCALL EndElementHandler(void *userData, const XML_Char *name)
Definition SkipPartCanvas.cpp:687
void add_error(const std::string &error) const
Definition SkipPartCanvas.cpp:613

References Slic3r::GUI::_BBS_3MF_Base::add_error(), EndElementHandler(), path_, and StartElementHandler().

Referenced by Slic3r::GUI::PartSkipDialog::InitDialogUI().

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

◆ StartElementHandler()

void XMLCALL Slic3r::GUI::ModelSettingHelper::StartElementHandler ( void * userData,
const XML_Char * name,
const XML_Char ** atts )
staticprivate
664{
665 ModelSettingHelper *self = static_cast<ModelSettingHelper *>(userData);
666 if (strcmp(name, "plate") == 0) {
667 self->context_.current_plate = PlateInfo(); // start a new plate
668 self->context_.in_plate = true;
669 } else if (strcmp(name, "metadata") == 0 && self->context_.in_plate) {
670 std::string key, value;
671 for (int i = 0; atts[i]; i += 2) {
672 if (strcmp(atts[i], "key") == 0) key = atts[i + 1];
673 if (strcmp(atts[i], "value") == 0) value = atts[i + 1];
674 }
675 if (key == "index") { self->context_.current_plate.index = std::stoi(value); }
676 if (key == "label_object_enabled") { self->context_.current_plate.label_object_enabled = value == "true"; }
677 } else if (strcmp(name, "object") == 0 && self->context_.in_plate) {
678 ObjectInfo obj;
679 for (int i = 0; atts[i]; i += 2) {
680 if (strcmp(atts[i], "identify_id") == 0) obj.identify_id = atoi(atts[i + 1]);
681 if (strcmp(atts[i], "name") == 0) obj.name = atts[i + 1];
682 }
683 self->context_.current_plate.objects.push_back(obj);
684 }
685}

References ModelSettingHelper(), context_, Slic3r::GUI::ModelSettingHelper::ParseContext::current_plate, Slic3r::GUI::ObjectInfo::identify_id, Slic3r::GUI::ModelSettingHelper::ParseContext::in_plate, Slic3r::GUI::PlateInfo::index, Slic3r::GUI::PlateInfo::label_object_enabled, Slic3r::GUI::ObjectInfo::name, and Slic3r::GUI::PlateInfo::objects.

Referenced by Parse().

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

Member Data Documentation

◆ context_

ParseContext Slic3r::GUI::ModelSettingHelper::context_
private

◆ m_errors

std::vector<std::string> Slic3r::GUI::_BBS_3MF_Base::m_errors
mutableprivateinherited

Referenced by add_error(), clear_errors(), and log_errors().

◆ mutex

boost::mutex Slic3r::GUI::_BBS_3MF_Base::mutex
mutableprivateinherited

Referenced by add_error().

◆ path_

std::string Slic3r::GUI::ModelSettingHelper::path_
private

Referenced by ModelSettingHelper(), and Parse().


The documentation for this class was generated from the following files: