//////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2025 Autodesk, Inc.  All rights reserved.
//
//  Use of this software is subject to the terms of the Autodesk license 
//  agreement provided at the time of installation or download, or which 
//  otherwise accompanies this software in either electronic or hard copy form.   
//
//////////////////////////////////////////////////////////////////////////////
// includes from ObjectARX Wizard
#ifdef _DEBUG
#define _DEBUG_WAS_DEFINED
#undef _DEBUG
#endif
#include "stdafx.h"           // MFC stuff
#ifdef _DEBUG_WAS_DEFINED
#define _DEBUG
#undef _DEBUG_WAS_DEFINED
#endif

//import defines for Amdt_stdimpl arx module 
#define STDIMP_DLLSHARE
#define STDIMP_DLLSHARE_DATA   __declspec(dllimport)

#include "acm.h"
#include "acmdef.h"
#include "symbol.h"
#include "leader.h"
#include "symstd.h"
#include "surfsym.h"
#include "fcframe.h"
#include "weldsym.h"
#include "datumtgt.h"
#include "idsym.h"
#include "bomstd.h"
#include "stdISO.h"
#include "stdMgr.h"


#include "ArrowStd.h"
#include "arrowres.h"

extern "C" HINSTANCE _hdllInstance;

//ACRX_DXF_DEFINE_MEMBERS(CLASS_NAME,PARENT_CLASS,PROXY_FLAGS,DXF_NAME,APP)
ACRX_DXF_DEFINE_MEMBERS(TestStandard,AcmStandardISO,AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,0,TESTSTANDARD,_T("TESTAPP"));

LPCTSTR _origName =      _T("TESTSTD");

TestStandard::TestStandard() 
{
}                     

TestStandard::~TestStandard()
{
  // we don't need to clean the dada from std, 
  // because they are destroyed in AcmStandard.
  // If we still need to do this, we have to set up them to NULL
}

LPCTSTR
TestStandard::originalName() const
{
  return _origName;
}

Adesk::Boolean 
TestStandard::acmInit()
{
  // first parrent class - it handles all same part;
  // Within the call of AcmStandard::acmInit() 
  // the TestStandard::initArrowServices() is called.
  AcmStandard::acmInit();

  AcmSymbolStd *pSymStd = nullptr;
  pSymStd = new AcmSurfTextStdISO();
  if (Acad::eOk != registerSymbolStd(pSymStd, _T("AcmSurfTextStd"), Adesk::kTrue, Adesk::kFalse, Adesk::kTrue))
      delete pSymStd;
  else
      pSymStd->close();

  pSymStd = new AcmFCFStdISO();
  if (Acad::eOk != registerSymbolStd(pSymStd,_T("AcmFCFStd"), Adesk::kTrue, Adesk::kFalse, Adesk::kTrue))
      delete pSymStd;
  else
      pSymStd->close();

  pSymStd = new AcmWeldingStdISO();
  if (Acad::eOk != registerSymbolStd(pSymStd,_T("AcmWeldingStd"), Adesk::kTrue, Adesk::kFalse, Adesk::kTrue))
      delete pSymStd;
  else
      pSymStd->close();

  pSymStd = new AcmIdStdISO();
  if (Acad::eOk != registerSymbolStd(pSymStd,_T("AcmIdStd"), Adesk::kTrue, Adesk::kFalse, Adesk::kTrue))
      delete pSymStd;
  else
      pSymStd->close();

  pSymStd = new AcmDatumStdISO();
  if (Acad::eOk != registerSymbolStd(pSymStd,_T("AcmDatumStd"), Adesk::kTrue, Adesk::kFalse, Adesk::kTrue))
      delete pSymStd;
  else
      pSymStd->close();

  return Adesk::kTrue;
}

void
TestStandard::initArrowServices()
{
  // we would use just ISO services and 
  AcmStandardISO::initArrowServices();
  // add new service as this standard service
  registerArrowService( new TestThickLine(this));

}

double 
TestStandard::defaultArrowScale() const
{  
  return 3.5;  
}

Adesk::Boolean 
TestStandard::createDefaultStyle()
{
  // set the default id for text style, just to have there something
  AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
  assert(pDb);
  AcDbTextStyleTable* txtTab;
  // get the textstyle table
  Acad::ErrorStatus es = pDb->getTextStyleTable(txtTab,AcDb::kForWrite);
  Adesk::Boolean setOk = Adesk::kFalse;
  AcDbObjectId styleId;
  es = txtTab->getAt(_T("TESTSTD"), styleId);
  // if not found, than
  if( es == Acad::eKeyNotFound) {
    // create a new text style table record;
    AcDbTextStyleTableRecord* style = new AcDbTextStyleTableRecord;
    assert(style);
    style->setName(_T("TESTSTD"));
    style->setFileName(_T("isocp.shx"));
    style->setTextSize(1.0);
    
    txtTab->upgradeOpen();
    es = txtTab->add(styleId,style);
    if( es == Acad::eOk ) {
      setOk = Adesk::kTrue;
      style->close();
    }
    else
      delete style;
  }
  else if( es == Acad::eOk ) {
    // the record is already there
    setOk = Adesk::kTrue;
  }
  txtTab->close();
  
  if( setOk ) setTextStyleId(styleId);

  return setOk;
}

/////////////////////////////////////////////////////////////////////
// Arrow : Datum ThickLine
/////////////////////////////////////////////////////////////////////
double
TestThickLine::arwHeight() const
{
  return 1.0;
}

double
TestThickLine::arwWidth() const
{
  return 0.2;
}

AcmCArrowDesc*
TestThickLine::getDesc()
{
  CTemporaryResourceOverride tmpres;

  AcmCArrowDesc *pDesc = new AcmCArrowDesc;
  pDesc->setType(serviceType());
  pDesc->setBitmap((HBITMAP)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(bitmapID()), IMAGE_BITMAP, 32, 16, LR_LOADMAP3DCOLORS));

  return pDesc;
}

AcmCArrowDesc*
TestThickLine::getDarkThemeDesc()
{
    //the user class will not support the dark theme
    return getDesc();
}

void
TestThickLine::getSubEnts(AcmCAuxEntArray& entArray) const
{  
  AcGePoint3d p1;
  AcGePoint3dArray points;
  double wd = arwWidth(), hg = arwHeight();
  //points.setLogicalLength(3);
  points.append(p1.set( wd+wd , hg , 0.0 ));
  points.append(p1.set( wd, hg , 0.0 ));
  points.append(p1.set( wd, -hg, 0.0 ));   
  points.append(p1.set( wd+wd , -hg, 0.0 ));

  AcmCAuxPolygon *pRect = new AcmCAuxPolygon(points,kAcGiFillAlways);
  pRect->setProperties(AcDbObjectId::kNull,mpOwner->leaderColor());  
  entArray.append(pRect);  

  AcmCAuxPline *pLine = new AcmCAuxPline(AcGePoint3d(wd+wd,0,0),AcGePoint3d(-1,0,0));
  pLine->setProperties(AcDbObjectId::kNull,mpOwner->leaderColor());  
  entArray.append(pLine);  

}


AcDbObjectId TestThickLine::makeBlock() const
{
  return AcDbObjectId::kNull;
}

Adesk::Boolean TestThickLine::getBlockName(CString& name) const
{
  return kFalse;
}

UINT TestThickLine::bitmapID() const
{
    return IDB_THICKLINE;
}

HINSTANCE TestThickLine::resourceHandle () const
{
    return CTemporaryResourceOverride::GetDefaultResource();
}
