Documentation of all program constructs¶
-
class
Ohmcha::Branch: public Ohmcha::Component¶ - #include <component.h>
An electrical branch.
Public Functions
-
Branch()¶ A default branch, equivalent to a short circuit.
-
Branch(const Branch &branch1, const Branch &branch2)¶ Create a branch by merging two branches that contain a common node.
- Exceptions
TODO..if: they don’t have a common node
-
Branch(RowVector3f A, float B)¶
-
void
setA(const RowVector3f &matrix)¶
-
void
setB(float x)¶
-
RowVector3f
getA() const¶
-
float
getB() const¶
-
int
getTerminalCount() const override¶
Protected Attributes
-
Node *
node1= {}¶ Current flows through this object from node 1 to node 2. Consequently, the reference voltage is positive if node 1 is at a higher potential than node 2.
-
RowVector3f
A¶ A branch has three quantities: V1 (potential at node1), V2 (potential at node2), I (current from node1 to node2). to represent a linear branch, we require an equation A * transpose([ V1 V2 I ]) = B.
-
float
B¶
-
-
class
Ohmcha::CircuitView: public QGraphicsView Public Types
-
enum
Mode Values:
-
enumerator
Idle
-
enumerator
InsertDragDrop
-
enumerator
InsertPoints
-
enumerator
Public Functions
-
CircuitView(QWidget *parent = nullptr)
-
CircuitView(QWidget *parent, Schematic *schematic)
-
~CircuitView()
-
void
initialize()
-
void
initiateInsertComponent(GraphicComponent *component, Mode insertMode)
-
void
solve()
-
void
showValues(bool show = true)
-
void
load(Schematic *schematic)
-
void
zoomIn(float scale = 1.2)
-
void
resetZoom()
-
CircuitViewScene *
scene()
-
void
setGridVisibility(bool visibility) Show/hide the grid.
-
void
setSnap(bool state) Enable/disable snap to grid.
-
void
setComponentPreview(ComponentPreview *componentPreview)
-
void
setZoomLevel(float zoom)
-
QPointF
getCursorPosition() Return the cursor position with any snap-to-grid applied.
-
ComponentPreview *
getComponentPreview()
-
Schematic *
getSchematic() Return the Schematic representation of this circuit. The result is guaranteed to be non-null.
-
float
getZoomLevel() const
Signals
-
void
componentSelected(GraphicComponent*) Emitted when a component is selected individually.
-
void
itemDeleted(GraphicComponent*)
Private Functions
-
void
wheelEvent(QWheelEvent *event) override
-
void
mousePressEvent(QMouseEvent *event) override
-
void
mouseReleaseEvent(QMouseEvent *event) override
-
void
mouseMoveEvent(QMouseEvent *event) override
-
void
keyPressEvent(QKeyEvent *event) override
-
void
resizeEvent(QResizeEvent *event) override
-
void
updateCursorGuides() Update cursor guides’ position based on the current cursor position.
-
void
snapToGrid() Change the internally tracked cursor position to make it snap to grid.
Private Members
-
float
zoomLevel= 1
-
QGraphicsLineItem *
hGuide= {}
-
QGraphicsLineItem *
vGuide= {}
-
GraphicComponent *
pendingInsert= {}
-
ComponentPreview *
componentPreview= {}
-
Schematic *
schematic= {}
-
QList<QGraphicsItem*>
results
-
QPointF
rawCursorPos
-
QPointF
cursorPos
-
float
gridSpacingX= 20
-
float
gridSpacingY= 20
-
bool
snapOn= false
-
bool
showGrid= true
-
bool
_selectionModeDetermined= false
-
QPointF
_dragPos
-
bool
_dragging= false
Friends
- friend class CircuitViewScene
-
enum
-
class
Ohmcha::CircuitViewScene: public QGraphicsScene¶ Public Functions
-
CircuitViewScene(CircuitView *circuitView)¶
-
void
clear()¶
-
bool
isInsertingComponent() const¶
-
void
mouseMoveEvent(QGraphicsSceneMouseEvent *event) override¶
-
void
mousePressEvent(QGraphicsSceneMouseEvent *event) override¶
-
void
keyPressEvent(QKeyEvent *event) override¶
-
void
terminalClickEvent(GraphicComponent *source, QPointF terminal)¶
Private Slots
-
void
on_selectionChanged()¶
-
-
class
Ohmcha::Component¶ Subclassed by Ohmcha::Branch, Ohmcha::CurrentSource, Ohmcha::Emf, Ohmcha::Node, Ohmcha::Resistor
Public Functions
-
void
setName(const std::string &name)¶
-
void
setPosition(Pos *position)¶ Set the position of this component in the schematic. If position is null, the position is considered arbitrary.
-
void
setAngle(float angle)¶
-
void
setTextAngle(float angle)¶
-
void
setTextOrientationIndependent(bool flag)¶
-
void
setTextAnchor(int anchor)¶
-
std::string
getName() const¶ - Return
Name given by the user.
-
float
getAngle() const¶
-
float
getTextAngle() const¶
-
bool
isTextOrientationIndependent() const¶
-
int
getTextAnchor() const¶
-
int
getTerminalCount() const = 0¶
Public Static Functions
-
void
-
class
Ohmcha::ComponentPreview: public QWidget¶ Public Functions
-
ComponentPreview(QWidget *parent = nullptr)¶
-
~ComponentPreview()¶
-
void
initialize()¶ Connect this preview to the active circuit view. Call this when first showing this widget or when the active circuit view changes.
-
void
initializeNewComponent(const QString &type)¶ Create a new GraphicComponent, with the same properties as the previous component.
-
void
synchronize()¶ Synchronize the contents of the text boxes and buttons with the actual properties of component.
-
void
setCircuitView(CircuitView *cv)¶
-
void
setComponentType(const QString &type)¶
Public Slots
-
void
setEditExisting(GraphicComponent *component)¶
Private Functions
-
void
updatePreview()¶ Call this when component is modified.
Private Members
-
GraphicComponent *
component= nullptr¶ component is guaranteed to be non-null whenever this widget is visible.
-
QString
lastComponentType¶
-
QString
selectedComponentType¶
-
CircuitView *
circuitView= nullptr¶ The circuit view that is currently active in the window
-
QRadioButton
anchors[3][3]¶ A 3x3 grid of buttons used to choose the text anchor
-
QButtonGroup *
anchorGroup= {}¶
Private Slots
-
void
on_selectionChanged()¶ Called when the selection in the circuit view changes
-
void
on_itemDeleted(GraphicComponent *component)¶
-
void
on_textAnchorPicked(int id)¶
-
void
on_textIndependencePicked(int id)¶
-
void
on_btnAdd_clicked()¶
-
void
on_editAngle_textEdited(const QString &s)¶
-
void
on_editText_textEdited(const QString &s)¶
-
void
on_editTextAngle_textEdited(const QString &s)¶
-
void
on_editTextX_textEdited(const QString &s)¶
-
void
on_editTextY_textEdited(const QString &s)¶
-
void
on_editValue_textEdited(const QString &s)¶
-
-
class
Ohmcha::CurrentSource: public Ohmcha::Component¶ Public Functions
-
CurrentSource()¶
-
CurrentSource(float current)¶
-
void
setCurrent(float current)¶
-
int
getTerminalCount() const override¶
-
float
getCurrent() const¶
-
Pos
getTextPos() const override¶
Private Members
-
float
current= 1¶
-
-
class
Ohmcha::Emf: public Ohmcha::Component¶ Public Functions
-
Emf()¶
-
Emf(float emf)¶
-
void
setEmf(float emf)¶
-
int
getTerminalCount() const override¶
-
float
getEmf() const¶
-
Pos
getTextPos() const override¶
Private Members
-
float
emf= 1¶
-
-
class
Ohmcha::GraphicBranch: public Ohmcha::GraphicComponent¶ Public Functions
-
GraphicBranch()¶
-
GraphicBranch(const GraphicBranch &original)¶
-
~GraphicBranch()¶
-
void
paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override¶
-
QRectF
boundingRect() const override¶
-
QPainterPath
shape() const override¶
-
void
swapTerminals()¶
-
GraphicComponent *
copy() const override¶
-
void
split(QPointF point)¶ Create a node at point and split the branch into two branches connected to that node. Point is specified in local coordinates.
-
void
setFirstAnchor(GraphicComponent *item, const QPointF &point)¶ Point is specified in item’s coordinate system. If item is null, then the point is specified in scene coordinates. This is useful in the interim while connecting two components together.
-
void
setSecondAnchor(GraphicComponent *item, const QPointF &point)¶ See setFirstAnchor
-
GraphicComponent *
getFirstAnchor() const¶
-
QPointF
getFirstAnchorPoint() const¶
-
QPointF
getSecondAnchorPoint() const¶
-
GraphicComponent *
getSecondAnchor() const¶
-
bool
isConnectedTo(GraphicComponent *item) const¶
-
void
mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override¶
Private Members
-
GraphicComponent *
first= {}¶ The components to which this branch is attached
-
GraphicComponent *
second= {}¶
-
QPointF
pFirst¶ The points on first/second to which this branch is attached, in their respective coordinate systems.
-
QPointF
pSecond¶
-
QPen
pen¶
-
-
class
Ohmcha::GraphicComponent: public QGraphicsItem¶ Subclassed by Ohmcha::GraphicBranch, Ohmcha::GraphicCurrentSource, Ohmcha::GraphicEmf, Ohmcha::GraphicNode, Ohmcha::GraphicResistor
Public Types
Public Functions
-
GraphicComponent()¶
-
GraphicComponent(const GraphicComponent &original)¶
-
const QPointF *
findNearestTerminal(QPointF point) const¶ Return the terminal that is within a certain distance to the specified point. If there is no such terminal, return null. The point is specified in this item’s coordinate system.
-
GraphicComponent *
copy() const = 0¶
-
void
synchronize()¶
-
QVariant
itemChange(GraphicsItemChange change, const QVariant &value) override¶
-
void
setName(QString name)¶
-
void
setCenter(QPointF center)¶
-
void
setRotation(float angle)¶
-
void
setTextPosition(QPointF pos)¶
-
void
setTextRotation(float angle)¶
-
void
setTextRotationIndependent(bool independent)¶
-
QSizeF
getSize() const¶
-
QString
getName() const¶
-
QPointF
getCenter() const¶
-
QPointF
getTextPosition() const¶
-
float
getTextRotation() const¶
-
bool
isTextRotationIndependent() const¶
-
CircuitViewScene *
getScene() const¶
-
int
getTerminalId(const QPointF &terminal) const¶
-
QList<QPointF>
getTerminals() const¶
-
void
onTerminalClicked(QPointF position)¶
-
void
hoverEnterEvent(QGraphicsSceneHoverEvent *event) override¶
-
void
hoverMoveEvent(QGraphicsSceneHoverEvent *event) override¶
-
void
hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override¶
-
void
mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override¶
Public Static Functions
-
GraphicComponent *
newFromComponent(Component *component)¶ Dynamically allocate a GraphicComponent wrapper around the specified Component. The type of the resulting object is determined based on the type of Component. TODO: implement.
Protected Functions
-
void
applyColors(QPainter *painter, const QStyleOptionGraphicsItem *option)¶
-
void
drawText(QPainter *painter)¶
Protected Attributes
-
QList<QPointF>
terminals¶
-
bool
branch1= false¶
-
bool
branch2= false¶
-
QSizeF
size¶
-
QPointF
textPos¶
-
float
textAngle= 0¶
-
bool
textRotationIndependent= false¶
-
const QPointF *
_selectedTerminal= nullptr¶
Friends
- friend class GraphicBranch
- friend class CircuitView
-
-
class
Ohmcha::GraphicCurrentSource: public Ohmcha::GraphicComponent¶ Public Functions
-
GraphicCurrentSource()¶
-
GraphicCurrentSource(CurrentSource *source)¶
-
GraphicCurrentSource(const GraphicCurrentSource &original)¶
-
QRectF
boundingRect() const override¶
-
void
paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override¶
-
GraphicComponent *
copy() const override¶
Private Members
-
QPen
pen¶
-
-
class
Ohmcha::GraphicEmf: public Ohmcha::GraphicComponent¶ Public Functions
-
GraphicEmf()¶
-
GraphicEmf(const GraphicEmf &original)¶
-
QRectF
boundingRect() const override¶
-
void
paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override¶
-
GraphicComponent *
copy() const override¶
Private Members
-
QPen
pen¶
-
-
class
Ohmcha::GraphicNode: public Ohmcha::GraphicComponent¶ Public Functions
-
GraphicNode()¶
-
GraphicNode(const GraphicNode &original)¶
-
~GraphicNode()¶
-
void
paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override¶
-
QRectF
boundingRect() const override¶
-
GraphicComponent *
copy() const override¶
-
void
mousePressEvent(QGraphicsSceneMouseEvent *event) override¶
-
-
class
Ohmcha::GraphicResistor: public Ohmcha::GraphicComponent¶ Public Functions
-
GraphicResistor()¶
-
GraphicResistor(QPointF node1, QPointF node2)¶
-
GraphicResistor(const GraphicResistor &original)¶
-
QRectF
boundingRect() const override¶
-
void
paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override¶
-
GraphicComponent *
copy() const override¶
-
void
setCenter(QPointF center) override¶
-
-
class
Ohmcha::MainWindow: public QMainWindow¶ Public Functions
-
MainWindow(QWidget *parent = nullptr)¶
-
~MainWindow()¶
-
CircuitView *
getCircuitView()¶ - Return
The currently displayed Circuit View.
Private Functions
-
void
initializeComponentList()¶ Refers to the component list in the docked widget.
-
-
struct
Ohmcha::Component::MetaInfo¶ - #include <component.h>
Additional information that is not relevant for algorithms.
-
class
Ohmcha::Node: public Ohmcha::Component¶ - #include <component.h>
An electrical node, i.e. a point at which two or more branches meet.
-
class
Ohmcha::Resistor: public Ohmcha::Component¶ Public Functions
-
Resistor()¶
-
Resistor(float resistance)¶
-
void
setResistance(float r)¶
-
int
getTerminalCount() const override¶
-
float
getResistance() const¶
-
Pos
getTextPos() const override¶
Private Members
-
float
resistance= 1¶
-
-
namespace
Ohmcha¶ All entities of Ohmcha are part of this namespace. This makes it possible to use the project as a library for other projects.
Typedefs
-
typedef std::vector<std::vector<float>>
Matrix¶
Functions
-
float
parseValue(const std::string &text)¶
-
QString
xmlConvertCurrentSource(CurrentSource *source)¶
-
typedef std::vector<std::vector<float>>
-
namespace
Ui¶
-
file
circuitview.h - #include “graphic_component.h”#include “component_preview.h”#include “graphic_branch.h”#include “src/model/schematic.h”#include <QWidget>#include <QGraphicsView>#include <QGraphicsItem>
-
file
component.h - #include <vector>#include <Eigen/Dense>
-
file
component_preview.h - #include <QRadioButton>#include <QWidget>#include “circuitview.h”#include “graphic_component.h”
-
file
graph.h - #include “component.h”
-
file
graphic_branch.h - #include “graphic_component.h”
-
file
graphic_component.h - #include <QObject>#include <QGraphicsItem>#include <QPen>#include “src/model/component.h”
-
file
graphic_currentsource.h - #include “graphic_component.h”
-
file
graphic_emf.h - #include “graphic_component.h”
-
file
graphic_node.h - #include “graphic_component.h”
-
file
graphic_resistor.h - #include “graphic_component.h”
-
file
kirchhoff.h - #include <Eigen/Dense>#include “component.h”#include “schematic.h”
-
file
main.cpp - #include <iostream>#include <vector>#include <Eigen/Dense>#include <map>#include “program/program.h”#include “test/test.h”#include “ui/mainwindow.h”#include <QApplication>#include “model/component.h”#include “model/kirchhoff.h”#include “fileio/xml.h”
Functions
-
int
execute_command(const arglist_iter &it_arg, const arglist_iter &end)¶ Execute a command, or print a message if it does not exist.
- Return
Status code of the executed command.
- Parameters
it_arg: Iterator to the first argument in the list.end: - End of the argument list
-
int
start_gui(int argc, char *argv[])¶
-
int
main(int argc, char *argv[])¶
Variables
-
std::map<std::string, int (*)(const arglist_iter&, const arglist_iter&)>
commands= {}¶
-
int
-
file
mainwindow.h - #include “circuitview.h”#include <QMainWindow>#include <QListWidgetItem>
-
file
program.h - #include <vector>#include <string>#include <iostream>#include <sstream>
Defines
-
is_opt(s, o1, o2)¶
-
eval(function)¶ Execute ‘function’. If it returns a non-zero value, an error has occurred, exit the calling function with the same error code.
This is to be used when a command calls a sub-command.
Typedefs
-
typedef std::vector<std::string>
arglist¶
-
typedef std::vector<std::string>::iterator
arglist_iter¶
Functions
-
arglist
read_line()¶ Read a line from std::cin and parse it into a vector of strings Delimiter used for parsing is any type of whitespace.
Text enclosed in double quotes is considered a single word even if it contains whitespace, and the quotes are not included in the result.
-
void
unrecognized_opt_cmd(const std::string &opt)¶
-
-
file
schematic.h - #include “component.h”
-
file
test.h Functions
-
int
test()¶
-
int
-
file
xml.h - #include <QtXml>#include <QFile>#include <string>#include “src/model/component.h”#include “src/model/schematic.h”
-
dir
fileio
-
dir
model
-
dir
program
-
dir
src
-
dir
test
-
dir
ui