コード例 #1
0
bool 
DXMAnchor::AddAnchor(MObject& site, const MString& longAnchorName, const MString& shortAnchorName, DXMAnchor* anchor)
{
	DXCC_ASSERT( DXMAnchor::GetAnchor(site, shortAnchorName) == NULL );

	DXCC_ASSERT(anchor != NULL);
	DXCC_ASSERT(anchor->GetSite().isNull());
	DXCC_ASSERT(anchor->GetPoint().length() == 0);

	DXCC_ASSERT(longAnchorName.length() > 0);
	DXCC_ASSERT(shortAnchorName.length() > 0);
	DXCC_ASSERT(!site.isNull());

	MFnDependencyNode depNode(site);
	MString name= depNode.name();
#ifdef DEBUG
	anchor->Name= name.asChar();
#endif

	if( g_DebugBasic )
	{
		DXCC_DPFA_REPORT("%s", name.asChar());
	}

	//this attribute may exist if you had asked for this node to be duplicated or instanced :(
	if( depNode.attribute( shortAnchorName ).isNull() )
	{
		MFnNumericAttribute numeric;
		MObject anchorAttrib= numeric.create(longAnchorName, shortAnchorName, MFnNumericData::kInt, 0);
		numeric.setReadable(false);
		numeric.setWritable(false);
		numeric.setConnectable(false);
		numeric.setStorable(false);
		numeric.setCached(true);
		numeric.setArray(false);
		numeric.setKeyable(false);
		numeric.setHidden(true);
		numeric.setUsedAsColor(false);
		numeric.setIndeterminant(true);
		numeric.setRenderSource(false);
		numeric.setInternal(false);

		DXCC_ASSERT(!anchorAttrib.isNull());
		DXCHECK_MSTATUS( depNode.addAttribute(anchorAttrib) );
	}

	MPlug anchorPlug= depNode.findPlug( shortAnchorName );
	DXCC_ASSERT(!anchorPlug.isNull());

	anchorPlug.setValue( *reinterpret_cast<int*>(&anchor) );

	anchor->AnchorSite= site;
	anchor->AnchorPoint= shortAnchorName;
	
//	anchor->NodeDestroyedCID= MNodeMessage::addNodeDestroyedCallback(site, DXMAnchor::DispatchNodeDestroyed, anchor);
//	anchor->AboutToDeleteCID= MNodeMessage::addNodeAboutToDeleteCallback(site, DXMAnchor::DispatchAboutToDelete, anchor);



	anchor->OnPostAddAnchor(longAnchorName, shortAnchorName);

	return true;
}