<commit_before>/*!
  \copyright (c) RDO-Team, 2003-2012
  \file      app/rdo_studio_mfc/src/model/model.h
  \author      (<EMAIL>)
  \date      20.02.2003
  \brief     
  \indent    4T
*/

#ifndef _RDO_STUDIO_MFC_MODEL_MODEL_H_
#define _RDO_STUDIO_MFC_MODEL_MODEL_H_

// ----------------------------------------------------------------------- INCLUDES
// ----------------------------------------------------------------------- SYNOPSIS
#include "kernel/rdothread.h"
#include "simulator/service/rdosimwin.h"
#include "app/rdo_studio_mfc/src/frame/manager.h"
#include "app/rdo_studio_mfc/src/model/document.h"
#include "app/rdo_studio_mfc/src/model/view.h"
#include "app/rdo_studio_mfc/rdo_process/rdoprocess_childfrm.h"
#include "app/rdo_studio_mfc/rdo_process/rdoprocess_docview.h"
#include "app/rdo_studio_mfc/src/plugins.h"
#include "app/rdo_studio_mfc/rdo_process/rdoprocess_project.h"
#include "app/rdo_studio_mfc/rdo_process/proc2rdo/rdoprocess_method_proc2rdo.h"
#include "app/rdo_studio_mfc/src/application.h"
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
// -------------------- RDOStudioModel
// --------------------------------------------------------------------------------
namespace rdoEditor {
	class RDOEditorTabCtrl;
}

class RDOStudioModel: public RDOThreadGUI
{
friend class RDOStudioModelDoc;
friend class RDOStudioFrameView;
friend class RDOStudioFrameTreeCtrl;
friend class RDOStudioApp;
friend class RDOThreadStudioGUI;
friend class RDOStudioPlugins;

private:
	enum BuildState
	{
		BS_UNDEFINED,
		BS_COMPLETE,
		BS_ERROR
	};

	PTR(CMultiDocTemplate)                 m_pModelDocTemplate;
	PTR(CMultiDocTemplate)                 m_pFlowchartDocTemplate;
	RDOStudioFrameManager                  m_frameManager;

	int                                    m_useTemplate;
	rbool                                  m_autoDeleteDoc;
	rbool                                  m_showCanNotCloseModelMessage;

	rbool                                  m_GUI_HAS_MODEL;
	rbool                                  m_GUI_CAN_RUN;
	rbool                                  m_GUI_IS_RUNING;
	rbool                                  m_GUI_ACTION_NEW;
	rbool                                  m_GUI_ACTION_OPEN;
	rbool                                  m_GUI_ACTION_SAVE;
	rbool                                  m_GUI_ACTION_CLOSE;
	rbool                                  m_GUI_ACTION_BUILD;
	rbool                                  m_GUI_ACTION_RUN;

	SYSTEMTIME                             m_timeStart;
	BuildState                             m_buildState;

	mutable rbool                          m_openError;
	mutable rbool                          m_smrEmptyError;
	mutable rbool                          m_modelClosed;

	rbool                                  m_frmDescribed;
	double                                 m_timeNow;
	double                                 m_speed;
	double                                 m_showRate;
	rbool                                  m_tempPause;
	rdo::runtime::RunTimeMode              m_runtimeMode;
	rdo::runtime::RunTimeMode              m_runtimeModePrev;
	rdo::service::simulation::RDOExitCode  m_exitCode;
	mutable rbool                          m_prevModify;

	void  updateFrmDescribed      ();
	void  newModelFromRepository  ();
	void  openModelFromRepository ();
	void  saveModelToRepository   ();
	void  closeModelFromRepository();
	rbool canCloseModel           ();
	void  afterModelStart         ();

	PTR(RPMethodProc2RDO) getProc2rdo() const
	{
		RPMethodManager::MethodList::const_iterator it = studioApp.getMethodManager().getList().begin();
		while (it != studioApp.getMethodManager().getList().end())
		{
			PTR(rpMethod::RPMethod) pMethod = *it;
			ASSERT(pMethod);
			if (pMethod->getClassName() == _T("RPMethodProc2RDO"))
			{
				PTR(RPMethodProc2RDO) pProc2RDO = dynamic_cast<PTR(RPMethodProc2RDO)>(pMethod);
				ASSERT(pProc2RDO);
				return pProc2RDO;
			}
			it++;
		}
		return NULL;
	}

	PTR(RDOStudioModelDoc) getModelDoc() const
	{
		POSITION pos = m_pModelDocTemplate->GetFirstDocPosition();
		return pos ? static_cast<PTR(RDOStudioModelDoc)>(m_pModelDocTemplate->GetNextDoc(pos)) : NULL;
	}

	struct ModelTemplateItem
	{
		ruint m_resID;
		int   m_position;

		ModelTemplateItem()
			: m_resID   (ruint(~0))
			, m_position(~0       )
		{}
		ModelTemplateItem(CREF(ModelTemplateItem) copy)
			: m_resID   (copy.m_resID   )
			, m_position(copy.m_position)
		{}
		ModelTemplateItem(ruint resID, int position)
			: m_resID   (resID   )
			, m_position(position)
		{}
	};
	typedef  std::map<rdoModelObjects::RDOFileType, ModelTemplateItem>  ModelTemplate;
	typedef  std::map<int, ModelTemplate>                               ModelTemplateList;
	ModelTemplateList m_modelTemplates;

	void show_result();

protected:
	virtual void proc(REF(RDOThread::RDOMessageInfo) msg);

public:
	RDOStudioModel();
	virtual ~RDOStudioModel();

	rbool newModel      (tstring _model_name = _T(""), tstring _model_path = _T(""), const int _useTemplate = -1);
	rbool openModel     (CREF(tstring) modelName = _T("")) const;
	rbool saveModel     () const;
	void  saveAsModel   () const;
	void  saveToXML     ();
	void  loadFromXML   ();
	rbool closeModel    () const;
	rbool buildModel    ();
	rbool runModel      ();
	rbool stopModel     () const;
	void  update        ();
	void  setGUIPause   ();
	void  setGUIContinue();

	PTR(RPDoc) getFlowchartDoc() const
	{
		POSITION pos = m_pFlowchartDocTemplate->GetFirstDocPosition();
		return pos ? static_cast<PTR(RPDoc)>(m_pFlowchartDocTemplate->GetNextDoc(pos)) : NULL;
	}

	tstring getName() const
	{
		PTR(RDOStudioModelDoc) pDoc = getModelDoc();
		return pDoc ? pDoc->getName() : _T("");
	}
	void    setName    (CREF(tstring) str);
	tstring getFullName() const;

	rbool   isModify   () const<commit_msg> - process-gui может отсутствовать<commit_after>/*!
  \copyright (c) RDO-Team, 2003-2012
  \file      app/rdo_studio_mfc/src/model/model.h
  \author      (<EMAIL>)
  \date      20.02.2003
  \brief     
  \indent    4T
*/

#ifndef _RDO_STUDIO_MFC_MODEL_MODEL_H_
#define _RDO_STUDIO_MFC_MODEL_MODEL_H_

// ----------------------------------------------------------------------- INCLUDES
// ----------------------------------------------------------------------- SYNOPSIS
#include "kernel/rdothread.h"
#include "simulator/service/rdosimwin.h"
#include "app/rdo_studio_mfc/src/frame/manager.h"
#include "app/rdo_studio_mfc/src/model/document.h"
#include "app/rdo_studio_mfc/src/model/view.h"
#include "app/rdo_studio_mfc/rdo_process/rdoprocess_childfrm.h"
#include "app/rdo_studio_mfc/rdo_process/rdoprocess_docview.h"
#include "app/rdo_studio_mfc/src/plugins.h"
#include "app/rdo_studio_mfc/rdo_process/rdoprocess_project.h"
#include "app/rdo_studio_mfc/rdo_process/proc2rdo/rdoprocess_method_proc2rdo.h"
#include "app/rdo_studio_mfc/src/application.h"
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
// -------------------- RDOStudioModel
// --------------------------------------------------------------------------------
namespace rdoEditor {
	class RDOEditorTabCtrl;
}

class RDOStudioModel: public RDOThreadGUI
{
friend class RDOStudioModelDoc;
friend class RDOStudioFrameView;
friend class RDOStudioFrameTreeCtrl;
friend class RDOStudioApp;
friend class RDOThreadStudioGUI;
friend class RDOStudioPlugins;

private:
	enum BuildState
	{
		BS_UNDEFINED,
		BS_COMPLETE,
		BS_ERROR
	};

	PTR(CMultiDocTemplate)                 m_pModelDocTemplate;
	PTR(CMultiDocTemplate)                 m_pFlowchartDocTemplate;
	RDOStudioFrameManager                  m_frameManager;

	int                                    m_useTemplate;
	rbool                                  m_autoDeleteDoc;
	rbool                                  m_showCanNotCloseModelMessage;

	rbool                                  m_GUI_HAS_MODEL;
	rbool                                  m_GUI_CAN_RUN;
	rbool                                  m_GUI_IS_RUNING;
	rbool                                  m_GUI_ACTION_NEW;
	rbool                                  m_GUI_ACTION_OPEN;
	rbool                                  m_GUI_ACTION_SAVE;
	rbool                                  m_GUI_ACTION_CLOSE;
	rbool                                  m_GUI_ACTION_BUILD;
	rbool                                  m_GUI_ACTION_RUN;

	SYSTEMTIME                             m_timeStart;
	BuildState                             m_buildState;

	mutable rbool                          m_openError;
	mutable rbool                          m_smrEmptyError;
	mutable rbool                          m_modelClosed;

	rbool                                  m_frmDescribed;
	double                                 m_timeNow;
	double                                 m_speed;
	double                                 m_showRate;
	rbool                                  m_tempPause;
	rdo::runtime::RunTimeMode              m_runtimeMode;
	rdo::runtime::RunTimeMode              m_runtimeModePrev;
	rdo::service::simulation::RDOExitCode  m_exitCode;
	mutable rbool                          m_prevModify;

	void  updateFrmDescribed      ();
	void  newModelFromRepository  ();
	void  openModelFromRepository ();
	void  saveModelToRepository   ();
	void  closeModelFromRepository();
	rbool canCloseModel           ();
	void  afterModelStart         ();

	PTR(RPMethodProc2RDO) getProc2rdo() const
	{
		RPMethodManager::MethodList::const_iterator it = studioApp.getMethodManager().getList().begin();
		while (it != studioApp.getMethodManager().getList().end())
		{
			PTR(rpMethod::RPMethod) pMethod = *it;
			ASSERT(pMethod);
			if (pMethod->getClassName() == _T("RPMethodProc2RDO"))
			{
				PTR(RPMethodProc2RDO) pProc2RDO = dynamic_cast<PTR(RPMethodProc2RDO)>(pMethod);
				ASSERT(pProc2RDO);
				return pProc2RDO;
			}
			it++;
		}
		return NULL;
	}

	PTR(RDOStudioModelDoc) getModelDoc() const
	{
		POSITION pos = m_pModelDocTemplate->GetFirstDocPosition();
		return pos ? static_cast<PTR(RDOStudioModelDoc)>(m_pModelDocTemplate->GetNextDoc(pos)) : NULL;
	}

	struct ModelTemplateItem
	{
		ruint m_resID;
		int   m_position;

		ModelTemplateItem()
			: m_resID   (ruint(~0))
			, m_position(~0       )
		{}
		ModelTemplateItem(CREF(ModelTemplateItem) copy)
			: m_resID   (copy.m_resID   )
			, m_position(copy.m_position)
		{}
		ModelTemplateItem(ruint resID, int position)
			: m_resID   (resID   )
			, m_position(position)
		{}
	};
	typedef  std::map<rdoModelObjects::RDOFileType, ModelTemplateItem>  ModelTemplate;
	typedef  std::map<int, ModelTemplate>                               ModelTemplateList;
	ModelTemplateList m_modelTemplates;

	void show_result();

protected:
	virtual void proc(REF(RDOThread::RDOMessageInfo) msg);

public:
	RDOStudioModel();
	virtual ~RDOStudioModel();

	rbool newModel      (tstring _model_name = _T(""), tstring _model_path = _T(""), const int _useTemplate = -1);
	rbool openModel     (CREF(tstring) modelName = _T("")) const;
	rbool saveModel     () const;
	void  saveAsModel   () const;
	void  saveToXML     ();
	void  loadFromXML   ();
	rbool closeModel    () const;
	rbool buildModel    ();
	rbool runModel      ();
	rbool stopModel     () const;
	void  update        ();
	void  setGUIPause   ();
	void  setGUIContinue();

	PTR(RPDoc) getFlowchartDoc() const
	{
		if (!m_pFlowchartDocTemplate)
			return NULL;
		POSITION pos = m_pFlowchartDocTemplate->GetFirstDocPosition();
		return pos ? static_cast<PTR(RPDoc)>(m_pFlowchartDocTemplate->GetNextDoc(pos)) : NULL;
	}

	tstring getName() const
	{
		PTR(RDOStudioModelDoc) pDoc = getModelDoc();
		return pDoc ? pDoc->getName() : _T("");
	}
	void    setName    (CREF(tstring) str);
	tstring getFullName() const;

	rbool   isModify   () const
{'fraction_non_alphanumeric': 0.1528373266078184, 'fraction_numerical': 0.005044136191677175, 'mean_word_length': 1.9099804305283756, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3736947', 'n_tokens_mistral': 3947, 'n_tokens_neox': 3719, 'n_words': 612}