home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // AutoSpl.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "MfcSplin.h"
- #include "AutoSpl.h" // This class
- #include "SplPage.h" // Property page class
- #include "GxIntf.h" // TurboCAD interfaces (forward declarations)
- #include "Imsigx.h" // TurboCAD interfaces
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- // Standard variants
- COleVariant t(-1L, VT_BOOL);
- COleVariant f(0L, VT_BOOL);
- COleVariant missing((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
-
- /////////////////////////////////////////////////////////////////////////////
- // CAutoSpline
-
- const IID IID_IGraphic =
- {0x6A481109,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- IMPLEMENT_DYNCREATE(CAutoSpline, CCmdTarget)
-
- CAutoSpline::CAutoSpline() :
- m_pSplinePage(NULL)
- {
- EnableAutomation();
-
- // To keep the application running as long as an OLE automation
- // object is active, the constructor calls AfxOleLockApp.
-
- AfxOleLockApp();
- }
-
- CAutoSpline::~CAutoSpline()
- {
- // To terminate the application when all objects created with
- // with OLE automation, the destructor calls AfxOleUnlockApp.
-
- AfxOleUnlockApp();
- }
-
-
- void CAutoSpline::OnFinalRelease()
- {
- // When the last reference for an automation object is released
- // OnFinalRelease is called. The base class will automatically
- // deletes the object. Add additional cleanup required for your
- // object before calling the base class.
-
- CCmdTarget::OnFinalRelease();
- }
-
-
- BEGIN_MESSAGE_MAP(CAutoSpline, CCmdTarget)
- //{{AFX_MSG_MAP(CAutoSpline)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- BEGIN_DISPATCH_MAP(CAutoSpline, CCmdTarget)
- //{{AFX_DISPATCH_MAP(CAutoSpline)
- DISP_PROPERTY_EX(CAutoSpline, "ClassID", GetClassID, SetNotSupported, VT_BSTR)
- DISP_PROPERTY_EX(CAutoSpline, "Description", GetDescription, SetNotSupported, VT_BSTR)
- DISP_FUNCTION(CAutoSpline, "GetPropertyInfo", GetPropertyInfo, VT_I4, VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "GetPageInfo", GetPageInfo, VT_I4, VTS_DISPATCH VTS_PI4 VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "GetWizardInfo", GetWizardInfo, VT_I4, VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "GetEnumNames", GetEnumNames, VT_I4, VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "PageControls", PageControls, VT_BOOL, VTS_DISPATCH VTS_DISPATCH VTS_I4 VTS_BOOL)
- DISP_FUNCTION(CAutoSpline, "PageDone", PageDone, VT_EMPTY, VTS_DISPATCH VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "PropertyPages", PropertyPages, VT_BOOL, VTS_DISPATCH VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "Wizard", Wizard, VT_BOOL, VTS_DISPATCH VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "OnGeometryChanged", OnGeometryChanged, VT_EMPTY, VTS_DISPATCH VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "OnGeometryChanging", OnGeometryChanging, VT_BOOL, VTS_DISPATCH VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "OnNewGraphic", OnNewGraphic, VT_BOOL, VTS_DISPATCH VTS_BOOL)
- DISP_FUNCTION(CAutoSpline, "OnCopyGraphic", OnCopyGraphic, VT_BOOL, VTS_DISPATCH VTS_DISPATCH VTS_VARIANT)
- DISP_FUNCTION(CAutoSpline, "OnPropertyChanged", OnPropertyChanged, VT_EMPTY, VTS_DISPATCH VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "OnPropertyChanging", OnPropertyChanging, VT_BOOL, VTS_DISPATCH VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "OnPropertyGet", OnPropertyGet, VT_EMPTY, VTS_DISPATCH VTS_I4)
- DISP_FUNCTION(CAutoSpline, "Draw", Draw, VT_BOOL, VTS_DISPATCH VTS_DISPATCH VTS_PVARIANT)
- DISP_FUNCTION(CAutoSpline, "Regen", Regen, VT_EMPTY, VTS_DISPATCH)
- DISP_FUNCTION(CAutoSpline, "Initialize", Initialize, VT_BOOL, VTS_DISPATCH)
- //}}AFX_DISPATCH_MAP
- END_DISPATCH_MAP()
-
- // Note: we add support for IID_ISmartObjectServer to support typesafe binding
- // from VBA. This IID must match the GUID that is attached to the
- // dispinterface in the .ODL file.
-
- // {6A481303-E531-11CF-A115-00A024158DAF}
- static const IID IID_ISmartObjectServer =
- {0x6A481303,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- BEGIN_INTERFACE_MAP(CAutoSpline, CCmdTarget)
- INTERFACE_PART(CAutoSpline, IID_ISmartObjectServer, Dispatch)
- END_INTERFACE_MAP()
-
- // {7724BB46-B671-11D0-9B3B-444553540000}
- IMPLEMENT_OLECREATE(CAutoSpline, "MFCSpline.Spline", 0x7724bb46, 0xb671, 0x11d0, 0x9b, 0x3b, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);
-
- /////////////////////////////////////////////////////////////////////////////
- // CAutoSpline message handlers
-
- BSTR CAutoSpline::GetDescription()
- {
- // Get the description from the resource
- CString strResult;
- strResult.LoadString(IDS_AUTOSPLINE_DESCRIPTION);
-
- return strResult.AllocSysString();
- }
-
- BSTR CAutoSpline::GetClassID()
- {
- // Convert our GUID (see IMPLEMENT_OLECREATE macro) to a string
- LPOLESTR olestr;
- HRESULT hRes = ::StringFromCLSID(guid, &olestr);
- if (FAILED(hRes))
- return NULL;
-
- BSTR bstr = ::SysAllocString(olestr);
- CoTaskMemFree(olestr);
- return bstr;
- }
-
- const long VT_INTEGER_ENUM = VT_I2 + 100;
- const long VT_LONG_ENUM = VT_I4 + 100;
- const long VT_STRING_ENUM = VT_BSTR + 100;
-
-
- // define 6 properties for Spline object
- const long nProperties = 6;
-
- enum PropertyIDs
- {
- idSplineType = 1,
- idSegments = 2,
- idShowFrame = 3,
- idShowControlPoints = 4,
- idSmoothing = 5,
- idFrameColor = 6
- };
-
- enum SplineTypes
- {
- typeCubicSpline = 0
- };
-
- long CAutoSpline::GetPropertyInfo(VARIANT FAR* Names, VARIANT FAR* Types, VARIANT FAR* IDs, VARIANT FAR* Defaults)
- {
- ASSERT(Names->vt == (VT_ARRAY|VT_BSTR));
- ASSERT(Types->vt == (VT_ARRAY|VT_I4));
- ASSERT(IDs->vt == (VT_ARRAY|VT_I4));
- ASSERT(Defaults->vt == (VT_ARRAY|VT_VARIANT));
-
- SAFEARRAYBOUND bound = { nProperties, 0 };
- if (FAILED(::SafeArrayRedim(Names->parray, &bound)))
- return 0;
- if (FAILED(::SafeArrayRedim(Types->parray, &bound)))
- return 0;
- if (FAILED(::SafeArrayRedim(IDs->parray, &bound)))
- return 0;
- if (FAILED(::SafeArrayRedim(Defaults->parray, &bound)))
- return 0;
-
- BSTR* rgNames;
- long* rgTypes;
- long* rgIDs;
- VARIANT* rgDefaults;
- long lReturn = 0;
- if (SUCCEEDED(::SafeArrayAccessData(Names->parray, (void**)&rgNames)))
- {
- if (SUCCEEDED(::SafeArrayAccessData(Types->parray, (void**)&rgTypes)))
- {
- if (SUCCEEDED(::SafeArrayAccessData(IDs->parray, (void**)&rgIDs)))
- {
- if (SUCCEEDED(::SafeArrayAccessData(Defaults->parray, (void**)&rgDefaults)))
- {
-
- CString strStr;
- strStr.LoadString(IDS_PROPERTYSPLINETYPE);
- rgNames[0] = ::SysAllocString(strStr.AllocSysString());
- rgTypes[0] = VT_INTEGER_ENUM;
- rgIDs[0] = idSplineType;
- rgDefaults[0].vt = VT_I2;
- rgDefaults[0].iVal = typeCubicSpline;
-
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSEGMENTSCOUNT);
- rgNames[1] = ::SysAllocString(strStr.AllocSysString());
- rgTypes[1] = VT_I4;
- rgIDs[1] = idSegments;
- rgDefaults[1].vt = VT_I4;
- rgDefaults[1].lVal = 16;
-
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSHOWFRAME);
- rgNames[2] = ::SysAllocString(strStr.AllocSysString());
- rgTypes[2] = VT_BOOL;
- rgIDs[2] = idShowFrame;
- rgDefaults[2].vt = VT_BOOL;
- rgDefaults[2].boolVal = FALSE;
-
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSHOWCONTROLPOINTS);
- rgNames[3] = ::SysAllocString(strStr.AllocSysString());
- rgTypes[3] = VT_BOOL;
- rgIDs[3] = idShowControlPoints;
- rgDefaults[3].vt = VT_BOOL;
- rgDefaults[3].boolVal = FALSE;
-
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSMOOTHING);
- rgNames[4] = ::SysAllocString(strStr.AllocSysString());
- rgTypes[4] = VT_BOOL;
- rgIDs[4] = idSmoothing;
- rgDefaults[4].vt = VT_BOOL;
- rgDefaults[4].boolVal = FALSE;
-
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYFRAMECOLOR);
- rgNames[5] = ::SysAllocString(strStr.AllocSysString());
- rgTypes[5] = VT_I4;
- rgIDs[5] = idFrameColor;
- rgDefaults[5].vt = VT_I4;
- rgDefaults[5].lVal = RGB(255, 0, 0);
-
- ::SafeArrayUnaccessData(Defaults->parray);
- strStr.Empty();
-
- lReturn = nProperties;
- }
- ::SafeArrayUnaccessData(IDs->parray);
- }
- ::SafeArrayUnaccessData(Types->parray);
- }
- ::SafeArrayUnaccessData(Names->parray);
- }
- return lReturn;
- }
-
- enum StockPages {
- PP_STOCK_PEN = 1,
- PP_STOCK_BRUSH = 2,
- PP_STOCK_TEXT = 4,
- PP_STOCK_INSERT = 8,
- PP_STOCK_VIEWPORT = 16,
- PP_STOCK_AUTO = 32
- };
-
- long CAutoSpline::GetPageInfo(LPDISPATCH /*AGraphic*/, long* StockPages, VARIANT FAR* Names)
- {
- ASSERT(StockPages != NULL);
- ASSERT(Names->vt == (VT_ARRAY|VT_BSTR));
-
- // Request pen page and auto page
- *StockPages = PP_STOCK_PEN | PP_STOCK_AUTO;
-
- SAFEARRAYBOUND bound = { 1, 0 };
- if (FAILED(::SafeArrayRedim(Names->parray, &bound)))
- return 0;
-
- CString strCaption;
- strCaption.LoadString(IDS_AUTOSPLINE_CAPTION);
- BSTR bstrCaption = strCaption.AllocSysString();
-
- long lIndex = 0;
- if (FAILED(SafeArrayPutElement(Names->parray, &lIndex, (void*)bstrCaption)))
- {
- ::SysFreeString(bstrCaption);
- return 0;
- }
- return 1;
- }
-
- long CAutoSpline::GetWizardInfo(VARIANT FAR* Names)
- {
- // No wizards, nothing to do
- return 0;
- }
-
- long CAutoSpline::GetEnumNames(long PropID, VARIANT FAR* Names, VARIANT FAR* Values)
- {
- if (PropID != idSplineType)
- return 0;
-
- ASSERT(Names->vt == (VT_ARRAY|VT_BSTR));
- ASSERT(Values->vt == (VT_ARRAY|VT_VARIANT));
-
- // TODO: Associate each spline type name and value
- return 0;
- }
-
- BOOL CAutoSpline::PageControls(LPDISPATCH ThisRegenMethod, LPDISPATCH AGraphic, long PageNumber, BOOL SaveProperties)
- {
- IGraphic* pIGraphic = NULL;
- if (FAILED(AGraphic->QueryInterface(IID_IGraphic, (void**)&pIGraphic)))
- return FALSE;
-
- BOOL bReturn = FALSE;
- Properties* pProps = NULL;
- Property* pProp;
- COleVariant varIndex, varValue;
- CString strStr;
-
- if (SUCCEEDED(pIGraphic->get_Properties(&pProps)))
- {
- if (SaveProperties)
- {
- if (m_pSplinePage != NULL)
- {
- // Note: the following can fail (for non-spline graphics)
- strStr.LoadString(IDS_PROPERTYSEGMENTSCOUNT);
- varIndex = LPCTSTR(strStr);
-
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- varValue = (const long)m_pSplinePage->m_nSegments;
- pProp->put_Value(0, &varValue);
- pProp->Release();
- varValue.Clear();
- }
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSHOWCONTROLPOINTS);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- // MFC has no overloaded operator for BOOLs!
- varValue.vt = VT_BOOL;
- varValue.boolVal = m_pSplinePage->m_bControlPoints;
- pProp->put_Value(0, &varValue);
- pProp->Release();
- varValue.Clear();
- }
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSHOWFRAME);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- varValue.vt = VT_BOOL;
- varValue.boolVal = m_pSplinePage->m_bFrame;
- pProp->put_Value(0, &varValue);
- pProp->Release();
- varValue.Clear();
- }
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSMOOTHING);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- varValue.vt = VT_BOOL;
- varValue.boolVal = m_pSplinePage->m_bSmoothing;
- pProp->put_Value(0, &varValue);
- pProp->Release();
- varValue.Clear();
- }
- bReturn = TRUE;
- }
- }
- else
- {
- ASSERT(m_pSplinePage == NULL);
- m_pSplinePage = new CSplinePage();
-
- // Note: the following can fail (for indeterminate values)
- strStr.LoadString(IDS_PROPERTYSEGMENTSCOUNT);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- if (SUCCEEDED(pProp->get_Value(0, &varValue)) &&
- varValue.vt == VT_I4)
- m_pSplinePage->m_nSegments = varValue.lVal;
- pProp->Release();
- varValue.Clear();
- }
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSHOWCONTROLPOINTS);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- if (SUCCEEDED(pProp->get_Value(0, &varValue)) &&
- varValue.vt == VT_BOOL)
- m_pSplinePage->m_bControlPoints = varValue.boolVal;
- pProp->Release();
- varValue.Clear();
- }
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSHOWFRAME);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- if (SUCCEEDED(pProp->get_Value(0, &varValue)) &&
- varValue.vt == VT_BOOL)
- m_pSplinePage->m_bFrame = varValue.boolVal;
- pProp->Release();
- varValue.Clear();
- }
- strStr.Empty();
- strStr.LoadString(IDS_PROPERTYSMOOTHING);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- if (SUCCEEDED(pProp->get_Value(0, &varValue)) &&
- varValue.vt == VT_BOOL)
- m_pSplinePage->m_bSmoothing = varValue.boolVal;
- pProp->Release();
- varValue.Clear();
- }
- bReturn = TRUE;
- }
- pProps->Release();
- }
-
- pIGraphic->Release();
- return bReturn;
- }
-
- void CAutoSpline::PageDone(LPDISPATCH ThisRegenMethod, VARIANT FAR* PageNumber)
- {
- // We're finished with the page
- delete m_pSplinePage;
- m_pSplinePage = NULL;
- }
-
- BOOL CAutoSpline::PropertyPages(LPDISPATCH ThisRegenMethod, VARIANT FAR* PageNumber)
- {
- if (m_pSplinePage == NULL)
- return FALSE;
-
- // Run the dialog and get the results
- int nResult = m_pSplinePage->DoModal();
- return (nResult == IDOK);
- }
-
- BOOL CAutoSpline::Wizard(LPDISPATCH ThisRegenMethod, VARIANT FAR* WizardNumber)
- {
- // No wizards, so just return FALSE.
- return FALSE;
- }
-
- void CAutoSpline::OnGeometryChanged(LPDISPATCH AGraphic, long GeomID, VARIANT FAR* ParamOld, VARIANT FAR* ParamNew)
- {
- }
-
- BOOL CAutoSpline::OnGeometryChanging(LPDISPATCH AGraphic, long GeomID, VARIANT FAR* ParamOld, VARIANT FAR* ParamNew)
- {
- // OK to change our geometry, so just return TRUE.
- return TRUE;
- }
-
- BOOL CAutoSpline::OnNewGraphic(LPDISPATCH AGraphic, BOOL Copy)
- {
- // Return FALSE on failure.
- // For copies, usually do nothing.
- if (Copy)
- return TRUE;
-
- // Add vertices, etc. for new graphic here.
-
- // TODO: Do nothing here.
- IGraphic* pIGraphic = NULL;
- if (FAILED(AGraphic->QueryInterface(IID_IGraphic, (void**)&pIGraphic)))
- return FALSE;
-
- Vertices* pVerts = NULL;
- IVertex* pIVertex = NULL;
-
-
- if (SUCCEEDED(pIGraphic->get_Vertices(&pVerts)))
- {
- COleVariant x;
- COleVariant y;
- COleVariant z(0.0);
-
- BOOL bFirst = TRUE;
- const double points[4*2] = { 0.0, 0.0, 1.0, 1.0, 2.0, 1.0, 3.0, 0.0 };
- for (int i = 0; i < 4*2; )
- {
- x = points[i++];
- y = points[i++];
- if (SUCCEEDED(pVerts->Add(&x, &y, &z,
- bFirst ? &f : &t /*penDown*/,
- &t /*selectable*/,
- &t /*snappable*/,
- &t /*editable*/,
- &t /*linkable*/,
- &f /*calculated*/,
- &missing /*before*/,
- &missing /*after*/,
- &pIVertex)))
- pIVertex->Release();
- bFirst = FALSE;
- }
- }
- pIGraphic->Release();
- return TRUE;
- }
-
- BOOL CAutoSpline::OnCopyGraphic(LPDISPATCH DestGraphic, LPDISPATCH SourceGraphic, VARIANT*)
- {
- // Return FALSE on failure.
- return TRUE;
- }
-
- void CAutoSpline::OnPropertyChanged(LPDISPATCH AGraphic, long PropID, VARIANT FAR* ValueOld, VARIANT FAR* ValueNew)
- {
- }
-
- BOOL CAutoSpline::OnPropertyChanging(LPDISPATCH AGraphic, long PropID, VARIANT FAR* ValueOld, VARIANT FAR* ValueNew)
- {
- // OK to change all of our properties, so just return TRUE.
- return TRUE;
- }
-
- void CAutoSpline::OnPropertyGet(LPDISPATCH AGraphic, long PropID)
- {
- // No special recalculating of properties needed.
- }
-
- BOOL CAutoSpline::Draw(LPDISPATCH AGraphic, LPDISPATCH AView, VARIANT FAR* AMatrix)
- {
- // We don't handle special drawing, so just return FALSE.
- return FALSE;
- }
-
- BOOL GetVertexXYZ(IGraphic* pIGraphic, const long lVertex, double& x, double& y, double& z)
- {
- IVertex* pIVertex = NULL;
- Vertices* pVerts = NULL;
- BOOL bSuccess = FALSE;
- if (SUCCEEDED(pIGraphic->get_Vertices(&pVerts)))
- {
- COleVariant varIndex = lVertex;
- if (SUCCEEDED(pVerts->get_Item(&varIndex, &pIVertex)))
- {
- if (SUCCEEDED(pIVertex->get_X(&x)) &&
- SUCCEEDED(pIVertex->get_Y(&y)) &&
- SUCCEEDED(pIVertex->get_Z(&z)))
- bSuccess = TRUE;
- pIVertex->Release();
- }
- pVerts->Release();
- }
- return bSuccess;
- }
-
- const long GF_COSMETIC = 128;
-
- struct BezierCoeffs
- {
- double t, tSquared, tCubed,
- oneMinusT, oneMinusTSquared, oneMinusTCubed;
- };
-
- double BezierEvaluate(const double v[4], const BezierCoeffs& c)
- {
- double vResult = c.oneMinusTCubed * v[0] +
- 3.0 * c.t * c.oneMinusTSquared * v[1] +
- 3.0 * c.tSquared * c.oneMinusT * v[2] +
- c.tCubed * v[3];
- return vResult;
- }
-
- void CAutoSpline::Regen(LPDISPATCH AGraphic)
- {
- IGraphic* pIGraphic = NULL;
- if (FAILED(AGraphic->QueryInterface(IID_IGraphic, (void**)&pIGraphic)))
- return;
-
- long lockCount = 0;
- CString strStr;
-
- if (SUCCEEDED(pIGraphic->RegenLock(&lockCount)))
- {
- if (lockCount == 0)
- {
- // TODO: All the curve processing goes here
- // build spline
- Graphics* pGraphics = NULL;
- IGraphic* pChild = NULL;
- IVertex* pIVertex = NULL;
- if (SUCCEEDED(pIGraphic->get_Graphics(&pGraphics)))
- {
- COleVariant flags = (const long)GF_COSMETIC;
- // clear all child graphics
- pGraphics->Clear(&flags);
-
- long nSegments = 16;
- Properties* pProps = NULL;
- Property* pProp = NULL;
- COleVariant varIndex, varValue;
- if (SUCCEEDED(pIGraphic->get_Properties(&pProps)))
- {
- // in this example we process only one property (Segments count)
- // add your code to process other properties (ShowFrame, ShowControlPoints,
- // Smoothing, FrameColor)
- strStr.LoadString(IDS_PROPERTYSEGMENTSCOUNT);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- if (SUCCEEDED(pProp->get_Value(0, &varValue)) &&
- varValue.vt == VT_I4)
- {
- nSegments = varValue.lVal;
- if (nSegments > 200)
- nSegments = 200;
- else if (nSegments < 2)
- nSegments = 2;
- }
- pProp->Release();
- }
- pProps->Release();
- }
-
- double px[4] = { 0.0 };
- double py[4] = { 0.0 };
- double pz[4] = { 0.0 };
- for (int i = 0; i < 4; ++i)
- GetVertexXYZ(pIGraphic, i, px[i], py[i], pz[i]);
-
- if (SUCCEEDED(pGraphics->Add(
- &missing /*GraphicType*/,
- &missing /*RegenMethod*/,
- &missing /*Inherit*/,
- &missing /*Style*/,
- &missing /*Before*/,
- &missing /*After*/,
- &pChild)))
- {
- pChild->put_Cosmetic(TRUE);
-
- COleVariant x, y, z;
- Vertices* pVerts = NULL;
- IVertex* pIVertex = NULL;
- if (SUCCEEDED(pChild->get_Vertices(&pVerts)))
- {
- BezierCoeffs c;
- BOOL bFirst = TRUE;
- for (long lt = 0; lt <= nSegments; ++lt)
- {
- c.t = (lt == nSegments) ? 1.0 : (double)lt/double(nSegments);
- c.tSquared = c.t * c.t;
- c.tCubed = c.tSquared * c.t;
- c.oneMinusT = 1.0 - c.t;
- c.oneMinusTSquared = c.oneMinusT * c.oneMinusT;
- c.oneMinusTCubed = c.oneMinusTSquared * c.oneMinusT;
-
- x = BezierEvaluate(px, c);
- y = BezierEvaluate(py, c);
- z = BezierEvaluate(pz, c);
-
- if (SUCCEEDED(pVerts->Add(&x, &y, &z,
- bFirst ? &f : &t /*penDown*/,
- &f /*selectable*/,
- &f /*snappable*/,
- &f /*editable*/,
- &f /*linkable*/,
- &f /*calculated*/,
- &missing /*before*/,
- &missing /*after*/,
- &pIVertex)))
- pIVertex->Release();
- bFirst = FALSE;
- }
- pVerts->Release();
- }
- pChild->Release();
- }
- pGraphics->Release();
- }
- }
- pIGraphic->RegenUnlock(&missing);
- }
- pIGraphic->Release();
- }
-
- BOOL CAutoSpline::Initialize(LPDISPATCH ThisRegenMethod)
- {
- // TODO: Add your dispatch handler code here
- return TRUE;
- }
-
- // DUAL_SUPPORT_START
-
- // delegate standard IDispatch methods to MFC IDispatch implementation
- DELEGATE_DUAL_INTERFACE(CAutoSpline, DualSpline)
-
- // Our method and property functions can generally just
- // delegate back to the methods we generated using
- // ClassWizard. However, if we set up properties to
- // access variables directly, we will need to write the
- // code to get/put the value into the variable.
- STDMETHODIMP CAutoSpline::XDualSpline::get_Description(BSTR FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetDescription();
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::get_ClassID(BSTR FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetClassID();
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::GetPropertyInfo(VARIANT FAR* Names, VARIANT FAR* Types, VARIANT FAR* IDs, VARIANT FAR* Defaults, long FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetPropertyInfo(Names, Types, IDs, Defaults);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::GetPageInfo(IDispatch * AGraphic, long FAR* StockPages, VARIANT FAR* Names, long FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetPageInfo(AGraphic, StockPages, Names);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::GetWizardInfo(VARIANT FAR* Names, long FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetWizardInfo(Names);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::GetEnumNames(long PropID, VARIANT FAR* Names, VARIANT FAR* Values, long FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetEnumNames(PropID, Names, Values);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::PageControls(IDispatch* ThisRegenMethod, IDispatch * AGraphic, long PageNumber, VARIANT_BOOL SaveProperties, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->PageControls(ThisRegenMethod, AGraphic, PageNumber, SaveProperties);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::PageDone(IDispatch * ThisRegenMethod, VARIANT FAR* PageNumber)
- {
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->PageDone(ThisRegenMethod, PageNumber);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::PropertyPages(IDispatch* ThisRegenMethod, VARIANT FAR* PageNumber, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->PropertyPages(ThisRegenMethod, PageNumber);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::Wizard(IDispatch* ThisRegenMethod, VARIANT FAR* WizardNumber, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->Wizard(ThisRegenMethod, WizardNumber);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::OnGeometryChanged(IDispatch * AGraphic, long GeomID, VARIANT FAR* ParamOld, VARIANT FAR* ParamNew)
- {
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->OnGeometryChanged(AGraphic, GeomID, ParamOld, ParamNew);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::OnGeometryChanging(IDispatch * AGraphic, long GeomID, VARIANT FAR* ParamOld, VARIANT FAR* ParamNew, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->OnGeometryChanging(AGraphic, GeomID, ParamOld, ParamNew);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::OnNewGraphic(IDispatch * AGraphic, VARIANT_BOOL Copy, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->OnNewGraphic(AGraphic, Copy);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::OnCopyGraphic(IDispatch* CopyGraphic, IDispatch* SourceGraphic, VARIANT* Matrix, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->OnCopyGraphic(CopyGraphic, SourceGraphic, Matrix);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::OnPropertyChanged(IDispatch * AGraphic, long PropID, VARIANT FAR* ValueOld, VARIANT FAR* ValueNew)
- {
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->OnPropertyChanged(AGraphic, PropID, ValueOld, ValueNew);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::OnPropertyChanging(IDispatch * AGraphic, long PropID, VARIANT FAR* ValueOld, VARIANT FAR* ValueNew, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->OnPropertyChanging(AGraphic, PropID, ValueOld, ValueNew);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::OnPropertyGet(IDispatch * AGraphic, long PropID)
- {
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->OnPropertyGet(AGraphic, PropID);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::Draw(IDispatch * AGraphic, IDispatch * AView, VARIANT FAR* AMatrix, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->Draw(AGraphic, AView, AMatrix);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::Regen(IDispatch* AGraphic)
- {
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->Regen(AGraphic);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoSpline::XDualSpline::Initialize(IDispatch* ThisRegenMethod, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoSpline, DualSpline)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->Initialize(ThisRegenMethod);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
-
- // Implement ISupportErrorInfo to indicate we support the
- // OLE Automation error handler.
- IMPLEMENT_DUAL_ERRORINFO(CAutoSpline, IID_ISmartObjectServer)
-
- // DUAL_SUPPORT_END
-