// Loads an stl file, projects it to the XY plane and calculates a polygon.
void BedShapePanel::load_stl()
{
	t_file_wild_card vec_FILE_WILDCARDS = get_file_wild_card();
    std::vector<std::string> file_types = { "known", "stl", "obj", "amf", "3mf", "prusa" };
    wxString MODEL_WILDCARD;
	for (auto file_type: file_types)
		MODEL_WILDCARD += vec_FILE_WILDCARDS.at(file_type) + "|";

	auto dialog = new wxFileDialog(this, _(L("Choose a file to import bed shape from (STL/OBJ/AMF/3MF/PRUSA):")), "", "",
		MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
	if (dialog->ShowModal() != wxID_OK) {
		dialog->Destroy();
		return;
	}
	wxArrayString input_file;
	dialog->GetPaths(input_file);
	dialog->Destroy();

	std::string file_name = input_file[0].ToStdString();

	Model model;
	try {
		model = Model::read_from_file(file_name);
	}
	catch (std::exception &e) {
		auto msg = _(L("Error! ")) + file_name + " : " + e.what() + ".";
		show_error(this, msg);
		exit(1);
	}

	auto mesh = model.mesh();
	auto expolygons = mesh.horizontal_projection();

	if (expolygons.size() == 0) {
		show_error(this, _(L("The selected file contains no geometry.")));
		return;
	}
	if (expolygons.size() > 1) {
		show_error(this, _(L("The selected file contains several disjoint areas. This is not supported.")));
		return;
	}

	auto polygon = expolygons[0].contour;
	std::vector<Pointf> points;
	for (auto pt : polygon.points)
		points.push_back(Pointf::new_unscale(pt));
	m_canvas->m_bed_shape = points;
	update_preview();
}
Exemple #2
0
// Loads an stl file, projects it to the XY plane and calculates a polygon.
void BedShapePanel::load_stl()
{
	auto dialog = new wxFileDialog(this, _(L("Choose a file to import bed shape from (STL/OBJ/AMF/3MF/PRUSA):")), "", "",
		file_wildcards(FT_MODEL), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
	if (dialog->ShowModal() != wxID_OK) {
		dialog->Destroy();
		return;
	}
	wxArrayString input_file;
	dialog->GetPaths(input_file);
	dialog->Destroy();

	std::string file_name = input_file[0].ToUTF8().data();

	Model model;
	try {
		model = Model::read_from_file(file_name);
	}
	catch (std::exception &e) {
		auto msg = _(L("Error! ")) + file_name + " : " + e.what() + ".";
		show_error(this, msg);
		exit(1);
	}

	auto mesh = model.mesh();
	auto expolygons = mesh.horizontal_projection();

	if (expolygons.size() == 0) {
		show_error(this, _(L("The selected file contains no geometry.")));
		return;
	}
	if (expolygons.size() > 1) {
		show_error(this, _(L("The selected file contains several disjoint areas. This is not supported.")));
		return;
	}

	auto polygon = expolygons[0].contour;
	std::vector<Vec2d> points;
	for (auto pt : polygon.points)
		points.push_back(unscale(pt));
	m_canvas->m_bed_shape = points;
	update_preview();
}