<commit_before>/*!
  \copyright (c) RDO-Team, 2013
  \file      app/rdo_studio/plugins/game5/src/plugin.cpp
  \author    <NAME> (<EMAIL>)
  \date      22.09.2013
  \brief     
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#include <QMessageBox>
#include <QDir>
#include <sstream>
#include <iostream>
#include <fstream>
// ----------------------------------------------------------------------- SYNOPSIS
#include "app/rdo_studio/src/application.h"
#include "app/rdo_studio/src/main_window.h"
#include "app/rdo_studio/src/model/model_tab_ctrl.h"
#include "app/rdo_studio/plugins/game5/src/plugin_game5_dialog.h"
#include "app/rdo_studio/plugins/game5/src/plugin_game5_tiles_order_dialog.h"
#include "app/rdo_studio/plugins/game5/src/costsetuptable.h"
// --------------------------------------------------------------------------------
game5Dialog::game5Dialog(QWidget * pParent)
: QDialog(pParent, Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
{
	setupUi(this);
	hiddenWidget->setFixedWidth(280);
	hiddenWidget->hide();

	buttonHide->setCheckable(true);
	buttonHide->setDefault(false);

	setFixedHeight(std::max(375, gameBoard->m_boardSizeY + 160));
	adjustSize();
	connect(tableCostValue    ,SIGNAL(itemCheckStateChanged(QTableWidgetItem *)),this      ,SLOT(onItemCheckStateChanged(QTableWidgetItem *)));
	connect(buttonHide        ,SIGNAL(toggled(bool))                            ,this      ,SLOT(onClickHide(bool)));
	connect(buttonSetLineup   ,SIGNAL(clicked())                                ,this      ,SLOT(callDialog()));
	connect(buttonOk          ,SIGNAL(clicked())                                ,this      ,SLOT(onClickOk()));
	connect(buttonRandomLineup,SIGNAL(clicked())                                ,this      ,SLOT(emitSolvabilityCheck()));
	connect(buttonRightLineup ,SIGNAL(clicked())                                ,gameBoard ,SLOT(buildRightLineup()));
	connect(this              ,SIGNAL(buttonRandomClicked(bool))                ,gameBoard ,SLOT(buildRandomLineup(bool)));

	if (pParent) {
		move(pParent->frameGeometry().center() - frameGeometry().center());
	}
}

void game5Dialog::onClickHide(bool state)
{
	hiddenWidget->setVisible(state);
	buttonHide->setText(buttonHide->text() == "<<" ? ">>" : "<<");
	adjustSize();
}

void game5Dialog::onClickOk()
{
	MainWindow* pMainWindow = (MainWindow *)(parent());
	rdo::gui::model::Model* pModel = pMainWindow->getModel();
	if(pModel)
		if (pModel->getTab())
		{
			//pModel->saveModel(); !private
			//QString a = pModel->getFullName(); !RDORepository
			backUpModel(pModel);
			clearAllTabs(pModel);

			pModel->getTab()->getItemEdit(rdoModelObjects::RTP)->appendText(QString::fromStdString(RTPtabText()));
			pModel->getTab()->getItemEdit(rdoModelObjects::RSS)->appendText(QString::fromStdString(RSStabText()));
			pModel->getTab()->getItemEdit(rdoModelObjects::PAT)->appendText(QString::fromStdString(PATtabText()));
			pModel->getTab()->getItemEdit(rdoModelObjects::DPT)->appendText(QString::fromStdString(DPTtabText()));
			pModel->getTab()->getItemEdit(rdoModelObjects::FUN)->appendText(QString::fromStdString(FUNtabText()));

			//pModel->runModel();
		}
		else
			QMessageBox::warning(pMainWindow, "Игра 5",
			                    "Не найден текстовый редактор!\nВозможно не открыта ни одна модель.");
	else
		QMessageBox::warning(pMainWindow, "Игра 5",
		                     "Не найдена модель!\nВозможно не открыта ни одна модель.");
	done(Accepted);
}

void game5Dialog::emitSolvabilityCheck()
{
	emit buttonRandomClicked(solvabilityCheck->isChecked());
}

void game5Dialog::onItemCheckStateChanged(QTableWidgetItem * item)
{
	QTableWidget * parentTable = item->tableWidget();
	if (item->checkState() == Qt::Unchecked)
	{
		item->setFlags(item->flags() & ~Qt::ItemIsEditable);
		item->setText("1");
	}
	else
	{
		item->setFlags(item->flags() | Qt::ItemIsEditable);
		parentTable->edit(parentTable->model()->index(item->row(),item->column()));
	}
}

std::string game5Dialog::evaluateBy()
{
	if (radioButton0->isChecked())
		return "0";
	if (radioButtonQuantity->isChecked())
		return "Кол_во_фишек_не_на_месте()";
	if (radioButtonDistance->isChecked())
		return "Расстояния_фишек_до_мест()";
	if (radioButtonCustom->isChecked())
		return lineEditCustom->text().toStdString();
}

std::string game5Dialog::activityValue(int tableRow)
{
	QString string = tableCostValue->item(tableRow,1)->text() + " " + tableCostValue->item(tableRow,2)->text();
	return string.toStdString();
}

std::string game5Dialog::RTPtabText()
{
	std::stringstream RTPtabTextStream; 
	RTPtabTextStream
	<<	"$Resource_type Фишка : permanent\n"
	<<	"$Parameters\n"
	<<	"	Номер          : integer[1.." << (gameBoard->m_tilesCountX * gameBoard->m_tilesCountY)- 1 << "]\n"
	<<	"	Местоположение : integer[1.." << (gameBoard->m_tilesCountX * gameBoard->m_tilesCountY)    << "]\n"
	<<	"$End\n"
	<<	"\n"
	<<	"$Resource_type Дырка_t : permanent\n"
	<<	"$Parameters\n"
	<<	"\t	Место: integer[1.." << (gameBoard->m_tilesCountX * gameBoard->m_tilesCountY) << "]\n"
	<<	"$End\n";
	return RTPtabTextStream.str();
}

std::string game5Dialog::RSStabText()
{
	std::stringstream RSStabTextStream; 
	RSStabTextStream
	<<	"$Resources\n";
	for (unsigned int i = 1 ; i < gameBoard->getTilesPos().size() ; i++)
	{
		RSStabTextStream << "\tФишка" << i <<"\t: Фишка " << i << " " << gameBoard->getTilesPos()[i] <<"\n";
	}
	RSStabTextStream << "\tДырка\t: Дырка_t " << gameBoard->getTilesPos()[0] << "\n";
	RSStabTextStream <<	"$End\n";
	return RSStabTextStream.str();
}

std::string game5Dialog::PATtabText()
{
	std::stringstream PATtabTextStream; 
	PATtabTextStream
	<<	"$Pattern Перемещение_фишки : rule\n"
	<<	"$Parameters\n"
	<<	"	Куда_перемещать: such_as Место_дырки\n"
	<<	"	На_сколько_перемещать: integer\n"
	<<	"$Relevant_resources\n"
	<<	"	_Фишка: Фишка   Keep\n"
	<<	"	_Дырка: Дырка_t Keep\n"
	<<	"$Body\n"
	<<	"	_Фишка\n"
	<<	"		Choice from Где_дырка(_Фишка.Местоположение) == Куда_перемещать\n"
	<<	"		first\n"<commit_msg> - новый синтаксис создания ресурсов<commit_after>/*!
  \copyright (c) RDO-Team, 2013
  \file      app/rdo_studio/plugins/game5/src/plugin.cpp
  \author    <NAME> (<EMAIL>)
  \date      22.09.2013
  \brief     
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#include <QMessageBox>
#include <QDir>
#include <sstream>
#include <iostream>
#include <fstream>
// ----------------------------------------------------------------------- SYNOPSIS
#include "app/rdo_studio/src/application.h"
#include "app/rdo_studio/src/main_window.h"
#include "app/rdo_studio/src/model/model_tab_ctrl.h"
#include "app/rdo_studio/plugins/game5/src/plugin_game5_dialog.h"
#include "app/rdo_studio/plugins/game5/src/plugin_game5_tiles_order_dialog.h"
#include "app/rdo_studio/plugins/game5/src/costsetuptable.h"
// --------------------------------------------------------------------------------
game5Dialog::game5Dialog(QWidget * pParent)
: QDialog(pParent, Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
{
	setupUi(this);
	hiddenWidget->setFixedWidth(280);
	hiddenWidget->hide();

	buttonHide->setCheckable(true);
	buttonHide->setDefault(false);

	setFixedHeight(std::max(375, gameBoard->m_boardSizeY + 160));
	adjustSize();
	connect(tableCostValue    ,SIGNAL(itemCheckStateChanged(QTableWidgetItem *)),this      ,SLOT(onItemCheckStateChanged(QTableWidgetItem *)));
	connect(buttonHide        ,SIGNAL(toggled(bool))                            ,this      ,SLOT(onClickHide(bool)));
	connect(buttonSetLineup   ,SIGNAL(clicked())                                ,this      ,SLOT(callDialog()));
	connect(buttonOk          ,SIGNAL(clicked())                                ,this      ,SLOT(onClickOk()));
	connect(buttonRandomLineup,SIGNAL(clicked())                                ,this      ,SLOT(emitSolvabilityCheck()));
	connect(buttonRightLineup ,SIGNAL(clicked())                                ,gameBoard ,SLOT(buildRightLineup()));
	connect(this              ,SIGNAL(buttonRandomClicked(bool))                ,gameBoard ,SLOT(buildRandomLineup(bool)));

	if (pParent) {
		move(pParent->frameGeometry().center() - frameGeometry().center());
	}
}

void game5Dialog::onClickHide(bool state)
{
	hiddenWidget->setVisible(state);
	buttonHide->setText(buttonHide->text() == "<<" ? ">>" : "<<");
	adjustSize();
}

void game5Dialog::onClickOk()
{
	MainWindow* pMainWindow = (MainWindow *)(parent());
	rdo::gui::model::Model* pModel = pMainWindow->getModel();
	if(pModel)
		if (pModel->getTab())
		{
			//pModel->saveModel(); !private
			//QString a = pModel->getFullName(); !RDORepository
			backUpModel(pModel);
			clearAllTabs(pModel);

			pModel->getTab()->getItemEdit(rdoModelObjects::RTP)->appendText(QString::fromStdString(RTPtabText()));
			pModel->getTab()->getItemEdit(rdoModelObjects::RSS)->appendText(QString::fromStdString(RSStabText()));
			pModel->getTab()->getItemEdit(rdoModelObjects::PAT)->appendText(QString::fromStdString(PATtabText()));
			pModel->getTab()->getItemEdit(rdoModelObjects::DPT)->appendText(QString::fromStdString(DPTtabText()));
			pModel->getTab()->getItemEdit(rdoModelObjects::FUN)->appendText(QString::fromStdString(FUNtabText()));

			//pModel->runModel();
		}
		else
			QMessageBox::warning(pMainWindow, "Игра 5",
			                    "Не найден текстовый редактор!\nВозможно не открыта ни одна модель.");
	else
		QMessageBox::warning(pMainWindow, "Игра 5",
		                     "Не найдена модель!\nВозможно не открыта ни одна модель.");
	done(Accepted);
}

void game5Dialog::emitSolvabilityCheck()
{
	emit buttonRandomClicked(solvabilityCheck->isChecked());
}

void game5Dialog::onItemCheckStateChanged(QTableWidgetItem * item)
{
	QTableWidget * parentTable = item->tableWidget();
	if (item->checkState() == Qt::Unchecked)
	{
		item->setFlags(item->flags() & ~Qt::ItemIsEditable);
		item->setText("1");
	}
	else
	{
		item->setFlags(item->flags() | Qt::ItemIsEditable);
		parentTable->edit(parentTable->model()->index(item->row(),item->column()));
	}
}

std::string game5Dialog::evaluateBy()
{
	if (radioButton0->isChecked())
		return "0";
	if (radioButtonQuantity->isChecked())
		return "Кол_во_фишек_не_на_месте()";
	if (radioButtonDistance->isChecked())
		return "Расстояния_фишек_до_мест()";
	if (radioButtonCustom->isChecked())
		return lineEditCustom->text().toStdString();
}

std::string game5Dialog::activityValue(int tableRow)
{
	QString string = tableCostValue->item(tableRow,1)->text() + " " + tableCostValue->item(tableRow,2)->text();
	return string.toStdString();
}

std::string game5Dialog::RTPtabText()
{
	std::stringstream RTPtabTextStream; 
	RTPtabTextStream
	<<	"$Resource_type Фишка : permanent\n"
	<<	"$Parameters\n"
	<<	"	Номер          : integer[1.." << (gameBoard->m_tilesCountX * gameBoard->m_tilesCountY)- 1 << "]\n"
	<<	"	Местоположение : integer[1.." << (gameBoard->m_tilesCountX * gameBoard->m_tilesCountY)    << "]\n"
	<<	"$End\n"
	<<	"\n"
	<<	"$Resource_type Дырка_t : permanent\n"
	<<	"$Parameters\n"
	<<	"\t	Место: integer[1.." << (gameBoard->m_tilesCountX * gameBoard->m_tilesCountY) << "]\n"
	<<	"$End\n";
	return RTPtabTextStream.str();
}

std::string game5Dialog::RSStabText()
{
	std::stringstream RSStabTextStream; 
	RSStabTextStream <<	"$Resources\n";
	for (unsigned int i = 1 ; i < gameBoard->getTilesPos().size() ; i++)
	{
		RSStabTextStream << "\tФишка Фишка" << i <<" = new Фишка(" << i << ", " << gameBoard->getTilesPos()[i] << ");\n";
	}
	RSStabTextStream << "\tДырка_t Дырка = new Дырка_t(" << gameBoard->getTilesPos()[0] << ");\n";
	RSStabTextStream <<	"$End\n";
	return RSStabTextStream.str();
}

std::string game5Dialog::PATtabText()
{
	std::stringstream PATtabTextStream; 
	PATtabTextStream
	<<	"$Pattern Перемещение_фишки : rule\n"
	<<	"$Parameters\n"
	<<	"	Куда_перемещать: such_as Место_дырки\n"
	<<	"	На_сколько_перемещать: integer\n"
	<<	"$Relevant_resources\n"
	<<	"	_Фишка: Фишка   Keep\n"
	<<	"	_Дырка: Дырка_t Keep\n"
	<<	"$Body\n"
	<<	"	_Фишка\n"
	<<	"		Choice from Где_дырка(_Фишка.Местоположение) == Куда_перемещать\n"
	<<	"		first\n"
{'fraction_non_alphanumeric': 0.21420463758715744, 'fraction_numerical': 0.008431976649910815, 'mean_word_length': 3.526605504587156, 'pattern_counts': {'":': 0, '<': 183, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4262486', 'n_tokens_mistral': 4520, 'n_tokens_neox': 4461, 'n_words': 578}