Files
OrcaSlicer/src/slic3r/GUI/CrealityDiscoveryDialog.hpp
grant0013 598df9ff0b Add Creality K-series LAN discovery via DNS-SD mDNS
When a user adds a Creality K-series printer (host_type=crealityprint)
and clicks the existing "Browse" button in the Physical Printer dialog,
dispatch to a new CrealityDiscoveryDialog that finds K2 / K2 Plus /
K2 Pro printers on the LAN automatically. For other host types the
button keeps its existing BonjourDialog behaviour.

  CrealityHostDiscovery (src/slic3r/Utils/CrealityHostDiscovery.{hpp,cpp})

    Wraps the vendored cxmdns wrapper from the previous commit:

      static std::vector<CrealityHost> scan(bool probe_info = true);

    Calls cxnet::syncDiscoveryService({"Creality", "creality"}) to find
    K-series printers via DNS-SD, dedupes by IP, then optionally HTTP
    GETs http://<ip>/info on each match to fetch the model code
    (F008 = K2 Plus, F012 = K2 Pro, F021 = K2) and MAC. Returns enriched
    {ip, hostname, model_code, model_name, mac, cfs_capable} entries.

  CrealityDiscoveryDialog (src/slic3r/GUI/CrealityDiscoveryDialog.{hpp,cpp})

    Modal dialog with a wxListView showing Model / Hostname / IP per
    discovered host. Runs CrealityHostDiscovery::scan() synchronously
    with wxBusyCursor + wxWindowDisabler (5-10s total wait). User picks
    one, dialog returns the IP via selected_ip().

  PhysicalPrinterDialog (src/slic3r/GUI/PhysicalPrinterDialog.cpp)

    The "Browse" button's click handler now reads host_type from the
    edited config. If htCrealityPrint, opens CrealityDiscoveryDialog
    and writes "http://<ip>" into the print_host field. Otherwise the
    existing BonjourDialog path runs unchanged -- no behaviour change
    for OctoPrint / Moonraker / Klipper users.

No new UI surface: one existing button now does the right thing per
host_type, mirroring how Creality Print discovers its own printers.
2026-05-19 20:03:54 +00:00

50 lines
1.4 KiB
C++

#ifndef slic3r_CrealityDiscoveryDialog_hpp_
#define slic3r_CrealityDiscoveryDialog_hpp_
#include <wx/dialog.h>
#include <string>
#include <vector>
class wxListView;
class wxStaticText;
namespace Slic3r {
namespace GUI {
// Modal dialog that finds Creality K-series printers on the LAN via DNS-SD
// mDNS (vendored mjansson/mdns + cxmdns wrapper) and lets the user pick one.
//
// Discovery is synchronous (~5 second mDNS listen + ~2-4 sec /info probe per
// host) and runs during ShowModal() with a busy cursor. The user-facing busy
// time is bounded by the mDNS listener's 5-second deadline plus any in-flight
// probes; in practice 5-10 seconds total for a typical LAN with one K2.
//
// After ShowModal() returns wxID_OK, selected_ip() yields the chosen
// printer's IPv4 address. Returns the empty string on Cancel or if no match
// was found.
class CrealityDiscoveryDialog : public wxDialog
{
public:
CrealityDiscoveryDialog(wxWindow* parent);
~CrealityDiscoveryDialog() override = default;
std::string selected_ip() const { return m_selected_ip; }
private:
void run_discovery();
void on_ok();
struct Row { std::string ip; std::string model; std::string hostname; };
wxListView* m_list = nullptr;
wxStaticText* m_status = nullptr;
std::vector<Row> m_rows;
std::string m_selected_ip;
};
} // namespace GUI
} // namespace Slic3r
#endif