
#include "system.hpp"

#include "connect.hpp"
#include "modules.hpp"
#include "imports/import_mentor.hpp"

System::System() : mods(nullptr), conns(nullptr)
{
    mods = new Modules();
    conns = new Connections();
}

System::~System()
{
    delete mods;
    delete conns;
}

void System::Load(std::string module_name, std::string file_name, ImportType type)
{
    ImportBase *imp;
    Module *mod = nullptr;
    Parts *prts = nullptr;

    // Creation or retrieval of the module.
    mod = mods->merge(module_name);

    // Parsing of the file based on the import type.
    if (type == ImportType::IMPORT_MENTOR)
    {
        imp = new ImportMentor(file_name);
    } else if (type == ImportType::IMPORT_ALTIUM)
    {
        // imp = new ImportAltium(file_name);
    } else if (type == ImportType::IMPORT_ODS)
    {
        // imp = new ImportOds(file_name);
    }
    else
    {
        throw std::runtime_error("Unknown import type");
    }
    imp->parse(mod->signals);
    prts = imp->parts();
    mod->add(prts);
}