/////////////////////////////////////////////////////////////////////
// (C) Copyright 1993-2005 by Autodesk, Inc. 
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//
/////////////////////////////////////////////////////////////////////
// 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

#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;
}

#define REGISTER_SYMBOLSTD(pClass,baseName) \
  newSymbolSupport(baseName); \
  if (Acad::eOk != addSymbolStd(pClass,id)) \
    delete pClass;  \
  else { \
    pClass->cInit(); \
    pClass->close(); \
  } \

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();

  AcDbObjectId id;
  AcmSymbolStd *pSymStd;
  pSymStd = new AcmSurfTextStdISO();
  REGISTER_SYMBOLSTD(pSymStd,_T("AcmSurfTextStd"));
  pSymStd = new AcmFCFStdISO();
  REGISTER_SYMBOLSTD(pSymStd,_T("AcmFCFStd"));
  pSymStd = new AcmWeldingStdISO();
  REGISTER_SYMBOLSTD(pSymStd,_T("AcmWeldingStd"));
  pSymStd = new AcmIdStdISO();
  REGISTER_SYMBOLSTD(pSymStd,_T("AcmIdStd"));
  pSymStd = new AcmDatumStdISO();
  REGISTER_SYMBOLSTD(pSymStd,_T("AcmDatumStd"));

  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() const
{
  CTemporaryResourceOverride tmpres;

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

  return pDesc;
}

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;
}
