#include "stdafx.h"
#include "crxedcds.h"
#include "cdscodes.h"
#include "crxdocman.h"
#include "dbents.h"
#include "dbapserv.h"
#include "dbsymtb.h"

#define szRDS _RXST("")

/// <summary>
/// 現在(アクティブ)なファイルのパスを取得する
/// </summary>
/// <returns></returns>
CString getCurrDraftFilePath()
{
	CRxApDocument* pActiveDoc = crxDocManager->mdiActiveDocument();
	CString strFilePath = pActiveDoc->fileName();
	return strFilePath;
}

/// <summary>
/// エンティティを追加する
/// </summary>
/// <param name="pEnt"></param>
/// <returns></returns>
CRxDbObjectId AddToModelSpace(CRxDbEntity* pEnt)
{
	CRxDbBlockTable* pBlockTable;
	crxdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, CRxDb::kForRead);

	CRxDbBlockTableRecord* pBlockTableRecord;
	pBlockTable->getAt(CRXDB_MODEL_SPACE, pBlockTableRecord, CRxDb::kForWrite);

	CRxDbObjectId lineId;
	pBlockTableRecord->appendAcDbEntity(lineId, pEnt);

	pBlockTable->close();
	pBlockTableRecord->close();
	pEnt->close();

	return lineId;
}

/// <summary>
/// 円を作成する
/// </summary>
void CreateCircle()
{
	CRxGePoint3d ptCenter(100, 100, 0);
	CRxGeVector3d vec(0, 0, 1);
	double radius = 20;
	CRxDbCircle* pCircle = new CRxDbCircle(ptCenter, vec, radius);
	CRxDbObjectId circleId;
	circleId = AddToModelSpace(pCircle);
	return;
}

/// <summary>
/// コマンド1処理
/// </summary>
void IroncadCrxSampleCppCommand1()
{
	bool ret;

	AfxMessageBox(getCurrDraftFilePath());

	return;
}


/// <summary>
/// コマンド2処理
/// </summary>
void IroncadCrxSampleCppCommand2()
{
	CreateCircle();

	return;
}

