26 response[
"jsonrpc"] =
"2.0";
27 response[
"result"] = result;
28 if (!requestId.isNull()) {
29 response[
"id"] = requestId;
37 response[
"jsonrpc"] =
"2.0";
39 QJsonObject errorObject;
40 errorObject[
"code"] = code;
41 errorObject[
"message"] = error;
42 response[
"error"] = errorObject;
44 if (!requestId.isNull()) {
45 response[
"id"] = requestId;
52 for (
const QString ¶m : required) {
53 if (!params.contains(param)) {
71 return workspace->
scene();
85 return workspace->
scene();
90 if (!value.isDouble()) {
91 errorMsg = QString(
"Parameter '%1' must be an integer").arg(paramName);
95 int intVal = value.toInt();
97 errorMsg = QString(
"Parameter '%1' must be a positive integer (got %2)").arg(paramName).arg(intVal);
106 if (!value.isDouble()) {
107 errorMsg = QString(
"Parameter '%1' must be an integer").arg(paramName);
111 int intVal = value.toInt();
113 errorMsg = QString(
"Parameter '%1' must be non-negative (got %2)").arg(paramName).arg(intVal);
122 if (!value.isString()) {
123 errorMsg = QString(
"Parameter '%1' must be a string").arg(paramName);
127 QString str = value.toString();
129 errorMsg = QString(
"Parameter '%1' cannot be empty").arg(paramName);
138 if (elementId <= 0) {
139 errorMsg = QString(
"Parameter '%1' must be a positive integer (got %2)").arg(paramName).arg(elementId);
145 errorMsg =
"No active circuit scene available";
149 auto *item = scene->
itemById(elementId);
151 errorMsg = QString(
"Element not found: %1").arg(elementId);
160 if (!value.isDouble()) {
161 errorMsg = QString(
"Parameter '%1' must be a numeric value").arg(paramName);
165 double numVal = value.toDouble();
166 if (std::isnan(numVal) || std::isinf(numVal)) {
167 errorMsg = QString(
"Parameter '%1' must be a finite numeric value").arg(paramName);
177 errorMsg = QString(
"Invalid element for port validation");
182 qsizetype maxPorts = 0;
184 maxPorts = element->
outputs().size();
186 maxPorts = element->
inputs().size();
189 if (portIndex >= maxPorts) {
190 QString portType = isOutput ?
"output" :
"input";
191 errorMsg = QString(
"Parameter '%1' port index %2 is out of range (element has %3 %4 ports)")
207 const int elementId = params.value(paramName).toInt();
214 errorMsg = QString(
"Item %1 is not a graphic element").arg(elementId);
223 errorMsg =
"Element is null";
228 for (
int i = 0; i < inputCount; ++i) {
230 if (port && port->name() == label) {
236 errorMsg = QString(
"Input port '%1' not found on element '%2'. Available input ports: %3")
244 errorMsg =
"Element is null";
249 for (
int i = 0; i < outputCount; ++i) {
251 if (port && port->name() == label) {
257 errorMsg = QString(
"Output port '%1' not found on element '%2'. Available output ports: %3")
265 return "(element is null)";
271 return isOutput ?
"(no output ports)" :
"(no input ports)";
275 for (
int i = 0; i < count; ++i) {
276 auto *port = isOutput ?
static_cast<Port *
>(element->
outputPort(i))
279 QString portName = port->name().isEmpty() ?
"(unnamed)" : port->name();
280 ports.append(QString(
"[%1] %2").arg(i).arg(portName));
282 ports.append(QString(
"[%1] (null)").arg(i));
286 return ports.join(
", ");
Singleton factory for all circuit element types.
Abstract base class for all graphical circuit elements.
Main application window providing menus, toolbars, and tab management.
Port classes: Port (base), InputPort, and OutputPort.
Main circuit editing scene with undo/redo and user interaction.
WorkSpace widget: the complete circuit editing environment for one tab.
bool validatePortRange(GraphicElement *element, int portIndex, bool isOutput, const QString ¶mName, QString &errorMsg) const
const MCPValidator * m_validator
QString availableOutputPorts(GraphicElement *element) const
QJsonObject createSuccessResponse(const QJsonObject &result={}, const QJsonValue &requestId=QJsonValue()) const
bool validateElementId(int elementId, const QString ¶mName, QString &errorMsg) const
QString availablePorts(GraphicElement *element, bool isOutput) const
GraphicElement * validatedElement(const QJsonObject ¶ms, const QString ¶mName, QString &errorMsg)
Validates paramName in params, looks up the element, and returns it.
bool validateNonNegativeInteger(const QJsonValue &value, const QString ¶mName, QString &errorMsg) const
BaseHandler(MainWindow *mainWindow, const MCPValidator *validator)
QJsonObject createErrorResponse(const QString &error, const QJsonValue &requestId=QJsonValue(), int code=JsonRpcError::InternalError) const
MainWindow * m_mainWindow
bool outputPortByLabel(GraphicElement *element, const QString &label, int &portIndex, QString &errorMsg) const
bool validateParameters(const QJsonObject ¶ms, const QStringList &required) const
bool inputPortByLabel(GraphicElement *element, const QString &label, int &portIndex, QString &errorMsg) const
bool validatePositiveInteger(const QJsonValue &value, const QString ¶mName, QString &errorMsg) const
QString availableInputPorts(GraphicElement *element) const
bool validateNonEmptyString(const QJsonValue &value, const QString ¶mName, QString &errorMsg) const
bool validateNumeric(const QJsonValue &value, const QString ¶mName, QString &errorMsg) const
Abstract base class for all graphical circuit elements in wiRedPanda.
int inputSize() const
Returns the current number of input ports.
InputPort * inputPort(const int index=0) const
Returns the input port at index (default 0).
int outputSize() const
Returns the current number of output ports.
OutputPort * outputPort(const int index=0) const
Returns the output port at index (default 0).
const QVector< OutputPort * > & outputs() const
Returns a const reference to the vector of all output ports.
const QVector< InputPort * > & inputs() const
Returns a const reference to the vector of all input ports.
JSON Schema validator for MCP commands and responses using native json-schema-validator.
The top-level application window hosting the tab bar, menus, element palette, and editor.
Abstract base class for circuit element ports (connection endpoints).
Main circuit editing scene.
ItemWithId * itemById(int id) const
Returns the item registered under id, or nullptr if not found.
A widget containing a complete circuit editing environment.
Scene * scene()
Returns the Scene embedded in this workspace.