File indexing completed on 2024-12-08 08:10:39

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2005 by David Saxton                               *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef FPNODE_H
0012 #define FPNODE_H
0013 
0014 #include "node.h"
0015 
0016 class FlowPart;
0017 class FlowConnector;
0018 class FlowConnectorList;
0019 
0020 #include "flowconnectorlist.h"
0021 
0022 typedef QList<FlowPart *> FlowPartList;
0023 
0024 /**
0025  * You should use this node for all FlowParts. It ensures that connections between FlowParts are
0026  * always valid (eg not more than two outputs from one node, which makes no sense)
0027  * @short FlowPart node
0028  * @author David Saxton
0029  */
0030 class FPNode : public Node
0031 {
0032     Q_OBJECT
0033 public:
0034     FPNode(ICNDocument *_icnView, Node::node_type type, int dir, const QPoint &pos, QString *id = nullptr);
0035     ~FPNode() override;
0036 
0037     /**
0038      * Returns a pointer to the FlowPart attached to this node if this node isInput, or
0039      * to the other end of the connector (if one exists) if it isOutput()
0040      */
0041     virtual FlowPart *outputFlowPart() const;
0042     /**
0043      * Returns a list of FlowParts attached to the node - either a single-item list containing
0044      * the FlowPart attached to this node if isOutput, or a list of FlowParts connected to the
0045      * input (?) connectors
0046      */
0047     virtual FlowPartList inputFlowParts() const;
0048 
0049     /**
0050      * Sets the node's visibility, as well as updating the visibility of the
0051      * attached connectors as appropriate
0052      */
0053     void setVisible(bool yes) override;
0054 
0055     /**
0056      * Returns true if the node can accept input connections. This will depend
0057      * on the node type and number of input / output connections.
0058      */
0059     virtual bool acceptInput() const = 0;
0060     /**
0061      * Returns true if the node can accept output connections. This will depend
0062      * on the node type and number of input / output connections.
0063      */
0064     virtual bool acceptOutput() const = 0;
0065     /**
0066      * Removes a specific connector
0067      */
0068     void removeConnector(Connector *connector) override;
0069     /**
0070      * Creates a new connector, sets this as the end node to the connector
0071      * (i.e. this node is the connector's input node), and returns a pointer
0072      * to the connector.
0073      */
0074     Connector *createInputConnector(Node *startNode);
0075     /**
0076      * Registers an input connector (i.e. this is the end node) as connected
0077      * to this node.
0078      */
0079     virtual void addInputConnector(Connector *const connector);
0080     /**
0081      * Registers an input connector (i.e. this is the start node) as connected
0082      * to this node.
0083      */
0084     virtual void addOutputConnector(Connector *const connector);
0085     /**
0086      * Returns the total number of connections to the node. This is the number
0087      * of input connectors, the number of output connectors, and the parent
0088      * item connector if it exists and is requested.
0089      * @param includeParentItem Count the parent item as a connector if it exists
0090      * @param includeHiddenConnectors hidden connectors are those as e.g. part of a subcircuit
0091      */
0092     int numCon(bool includeParentItem, bool includeHiddenConnectors) const override;
0093     /**
0094      * Returns true if this node is connected (or is the same as) the node given
0095      * by other connectors or nodes (although not through CNItems)
0096      * checkedNodes is a list of nodes that have already been checked for
0097      * being the connected nodes, and so can simply return if they are in there.
0098      * If it is null, it will assume that it is the first ndoe & will create a list
0099      */
0100     bool isConnected(Node *node, NodeList *checkedNodes = nullptr) override;
0101     /**
0102      * Removes all the NULL connectors
0103      */
0104     void removeNullConnectors() override;
0105 
0106     /**
0107      * Returns a list of the input connectors; implemented inline
0108      */
0109     ConnectorList inputConnectorList() const; /* {
0110            return (ConnectorList)(FlowConnectorList) m_inFlowConnList;  } */
0111     /**
0112      * Returns a list of the output connectors
0113      */
0114     ConnectorList outputConnectorList() const;
0115     /**
0116      * @return the list of all the connectors attached to the node
0117      */
0118     ConnectorList getAllConnectors() const override;
0119 
0120     /**
0121      * For a flownode: returns the first input connector, if it exist, or the fist outptut connector, if it exists.
0122      * For an electric node: returns the first connector
0123      * If the node isn't connected to anyithing, returns null ( 0 )
0124      * @return pointer to the desired connector
0125      */
0126     Connector *getAConnector() const override;
0127 
0128 public slots:
0129 
0130     /**
0131      * what is this? (verifies if the node can be removed; if it can, removes itself (?) )
0132      */
0133     virtual void checkForRemoval(Connector *connector);
0134 
0135     /**
0136      * Draw shape. Note that this has to remain public.
0137      */
0138     void drawShape(QPainter &p) override = 0;
0139 
0140 protected:
0141     /** If this node has precisely two connectors emerging from it, then this
0142      * function will trace the two connectors until the point where they
0143      * diverge; this point is returned. */
0144     QPoint findConnectorDivergePoint(bool *found) override;
0145 
0146     /** (please document this) registers some signals for the node and the new connector (?)
0147      * @return true of the operation was successful or false otherwise
0148      */
0149     bool handleNewConnector(Connector *newConnector);
0150 
0151     FlowConnectorList m_inFlowConnList;
0152     QPointer<FlowConnector> m_outputConnector;
0153 
0154 private:
0155     bool m_isInput;
0156 };
0157 
0158 #endif