/*
 *                            COPYRIGHT
 *
 *  sch-rnd - modular/flexible schematics editor - altium format support
 *  Copyright (C) 2022 Tibor 'Igor2' Palinkas
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 31 Milk Street, # 960789 Boston, MA 02196 USA.
 *
 *  Contact:
 *    Project page: http://repo.hu/projects/sch-rnd
 *    contact lead developer: http://www.repo.hu/projects/sch-rnd/contact.html
 *    mailing list: http://www.repo.hu/projects/sch-rnd/contact.html
 */


#include <stdio.h>
#include <string.h>
#include <librnd/core/plugins.h>
#include <libcschem/config.h>
#include <libcschem/plug_io.h>
#include "read.h"

#include "io_altium_conf.h"
#include "conf_internal.c"

conf_io_altium_t io_altium_conf;
static char altium_cookie[] = "io_altium";

static csch_plug_io_t altium_bin, altium_ascii;

static int io_altium_common_load_prio(const char *fn, const char *fmt, csch_plug_io_type_t type)
{
	if (fmt != NULL) {
		if (!strstr(fmt, "altium") && !strstr(fmt, "schdoc"))
			return 0;
	}
	if (type == CSCH_IOTYP_SHEET)
		return 90;
	return 0;
}

int pplg_check_ver_io_altium(int ver_needed) { return 0; }

void pplg_uninit_io_altium(void)
{
	csch_plug_io_unregister(&altium_bin);
	csch_plug_io_unregister(&altium_ascii);
	rnd_conf_plug_unreg("plugins/io_altium/", io_altium_conf_internal, altium_cookie);
}

int pplg_init_io_altium(void)
{
	RND_API_CHK_VER;

	altium_bin.name = "altium schematics sheet from schdoc (cdf)";
	altium_bin.load_prio = io_altium_common_load_prio;
	altium_bin.load_sheet = io_altium_bin_load_sheet;
	altium_bin.test_parse = io_altium_bin_test_parse;

	altium_bin.ext_save_sheet = "SchDoc";
	csch_plug_io_register(&altium_bin);

	altium_ascii.name = "altium schematics sheet from schdoc (ASCII)";
	altium_ascii.load_prio = io_altium_common_load_prio;
	altium_ascii.load_sheet = io_altium_ascii_load_sheet;
	altium_ascii.test_parse = io_altium_ascii_test_parse;

	altium_ascii.ext_save_sheet = "SchDoc";
	csch_plug_io_register(&altium_ascii);

	rnd_conf_plug_reg(io_altium_conf, io_altium_conf_internal, altium_cookie);
#define conf_reg(field,isarray,type_name,cpath,cname,desc,flags) \
	rnd_conf_reg_field(io_altium_conf, field,isarray,type_name,cpath,cname,desc,flags);
#include "io_altium_conf_fields.h"

	return 0;
}

