# OPM中提供属性分类

BEGIN_OPMPROP_MAP()
OPMPROP_ENTRY(0, DispID, PROPCAT_Data,0, 0, 0, “”, 0, 1, IID_NULL, IID_NULL, “”)
END_OPMPROP_MAP()

STDMETHODIMP GetCategoryName(
/* [in] */ PROPCAT propcat,
/* [in] */ LCID lcid,
/* [out] */ BSTR* pbstrName)
{
if (propcat == 1)
{
*pbstrName = ::SysAllocString(L”SQSize”);
return S_OK;
}
else
return S_FALSE;
}

AsdkSquareWrapper例程里没写清楚地好像就是这些了。我的表达能力不好，希望大家能看明白。

# OPM中属性的下拉列表的支持

    public IOPMPropertyExtensionImpl

//OPM calls this function for each property to obtain a list of strings and cookies if they are available.
//For our textstyle property we would like to display all the textstyles currently available in the database.
//This function is declared on the IPerPropertyBrowsing interface. Our IOPMPropertyExtensionImpl
//class implements this member by reading the values in the OPM property map. (You set this up in your
//head file when you use BEGIN_OPMPROP_MAP, OPMPROP_ENTRY, END_OPMPROP_MAP macros.)
//Since we need a dynamic list of entries in this drop down list and a static map cannot implement this,
//we need to override this function a provide dynamic list of text styles to OPM.
STDMETHOD(GetPredefinedStrings)(
/* [in] */ DISPID dispID,
/* [out] */ CALPOLESTR *pCaStringsOut,

//OPM calls this function when the user selects an element from a drop down list. OPM provides
//the cookie that we associated with the element in the GetPredefinedStrings function. We are
//responsible for mapping this cookie back to a value that the properties corresponding put_ function
//can understand.
//In this particular case all we need to do is to provide the name of the text style as
//the put_TextStyle method needs that.
STDMETHOD(GetPredefinedValue)(
/* [in] */ DISPID dispID,
/* [out] */ VARIANT *pVarOut);

# How to create a polyline-like vertex edit with a spin control in OPM?

The following snippets of code can be used to implement a polyline-like vertex edit in OPM (Object Property Manager) using IOPMPropertyExpander interface for a custom entity.

Lets assume the custom object (called AsDkRings) has two new variables to reflect an array of vertices:

AcGePoint3d m_polyline[5];

int m_numbervertices;

For simplicity, lets say the custom entity has a maximum of five vertices.

The custom class also has two corresponding access functions. (Note the vertex number parameter):

Acad::ErrorStatus AsDkRings::polyline(AcGePoint3d& vertex, int vertexNumber)

Acad::ErrorStatus AsDkRings::setPolyline(AcGePoint3d vertex,int vertexNumber)

In AsDkRings:: subWoldDraw(), we draw a polyline connecting the five vertices.

The key to getting a spin control in OPM is to return a grouping number. This number will determine the number of elements to group together.

//IOPMPropertyExpander

STDMETHODIMP CRings::GetElementGrouping(

/* [in] */ DISPID dispID,

/* [out] */ short *groupingNumber)

{

.............

.............

} else if (dispID == 5)

{

*groupingNumber = 4;

return S_OK;

}

return E_NOTIMPL;

}

A grouping number of 4 means there is one entry (called "Vertex") plus 3 entries (Vertex X, Y and Z) to group together into one property. What this would do is put a spin control into the first item (vertex in this case), so that this could be used to traverse an array of 3 remaining grouped items (which is Vertex X, Y and Z).

Next, we should specify the number of items that the property is going to display. Here this would be the number of vertices = 5. This would mean that the spin contol can go up to a maximum of 5 steps, for five vertices.

//IOPMPropertyExpander

STDMETHODIMP CRings::GetGroupCount(

/* [in] */ DISPID dispID,

/* [out] */ long *nGroupCnt)

{

................

...............

} else if (dispID == 5)

{

*nGroupCnt = m_numbervertices; // Number of vertices

return S_OK;

}

return E_NOTIMPL;

}

Next, we set the string to display in the OPM.

//IOPMPropertyExpander

STDMETHODIMP CRings::GetElementStrings(

/* [in] */ DISPID dispID,

/* [out] */ OPMLPOLESTR __RPC_FAR *pCaStringsOut,

/* [out] */ OPMDWORD __RPC_FAR *pCaCookiesOut)

{

................................

................................

} else if (dispID == 5)

{

// For the Vertices

pCaStringsOut->cElems = 4;

pCaStringsOut->pElems[0] = SysAllocString(L"Vertex");

pCaStringsOut->pElems[1] = SysAllocString(L"Vertex X");

pCaStringsOut->pElems[2] = SysAllocString(L"Vertex Y");

pCaStringsOut->pElems[3] = SysAllocString(L"Vertex Z");

return S_OK;

}

return E_NOTIMPL;

}

The cookies count is the unique identifier for each property item that will be used to get and set values. The table below will give you an idea of cookie value for each vertex value. Please remember that vertex entry has a spin control that goes like 1, 2, 3, 4.........and so on.

Vertex = 1 Vertex = 2 Vertex = 3 Vertex = 4 ....and so on
Vertex 0 4 8 12 ....and so on
Vertex X 1 5 9 13 ....and so on
Vertex Y 2 6 10 14 ....and so on
Vertex Z 3 7 11 15 ....and so on

So just by using the cookie values, you must get the vertex number and find out if it is an x, y, or z coordinate. The following code does that.

// Get the coordinate index (x=0, y= 1, z=2) from dwCookie

for (int i = 1; i < 4; i++) {

vertex = (double(dwCookie) - i) / 4;

if( vertex == (double(dwCookie) - i) / 4) {

index = i -1;

break;

}

}

index will return 0 for vertex X, 1 for vertex Y and 2 for vertex Z for the corrosponding cookie values.

So this is all that is needed to implement a poly-line vertex edit.

posted @ 2014-08-07 17:29 kevinzhwl 阅读(...) 评论(...) 编辑 收藏