Skip to content

How to create a new logic element

Rodrigo Torres edited this page Jan 30, 2025 · 1 revision

1. Create the element image

  • Design the vector image in Inkscape (or another vector graphics editor).
  • Save the file in SVG format into wiRedPanda/app/resources/.
  • Depending on the type of logic element, place it in a specific subfolder (e.g., input/, output/, etc.).

2. Modify wiRedPanda code

2.1. Open the wiRedPanda project in Qt Creator.

2.2. Create a new element class

  • Right-click on the app/config/element folder and click on Add New....
  • Select C++ Class and click Choose.
  • Enter the class name, leave the rest as default, and click Next > and then Finish.
  • Write the code for the new element (you can use and.h and and.cpp as reference).

2.3. Create a new logic class

  • Open ElementFactory::buildLogicElement by pressing Ctrl + K and typing : buildLogicElement.
  • Check if you can use an existing LogicElement class (such as LogicInput, LogicOutput, or LogicNone).
  • If none of the existing classes are suitable:
    • Right click on the app/config/logicelement folder and click on Add New....
    • Select C++ Class and click Choose.
    • Enter the class name (prefix it with Logic) and leave the rest as default, then click Next > and Finish.
    • Write the code for the new element (you can use logicand.h and logicand.cpp as reference).

2.4. Add the new element to the menu

  • Open MainWindow::populateLeftMenu by pressing Ctrl + K and typing : populateLeftMenu.
  • Add your new element to the appropriate menu in the method.

2.5. Modify the ElementType enum

  • Open enums.h by pressing Ctrl + K and typing enums.h.
  • Add a new entry in the ElementType enum with the same name as your class created in step 2.2.
  • Assign the highest number in the enum plus one as the new ID for your element.

2.6. Add the image to the resource file

  • Find the .qrc file in the same folder where you saved your image.
  • Right-click on the .qrc file and click Open in Editor.
  • Click the Add Files button to add your image file to the resource file.

2.7. Update ElementFactory::buildLogicElement

  • Open ElementFactory::buildLogicElement by pressing Ctrl + K and typing : buildLogicElement.
  • Add a case for your new class in the switch statement.
  • Ensure to #include your class header from step 2.3 at the beginning of the file.
Clone this wiki locally