【ABD CE 二次开发 C++】修改填充图案,填充区域变了

老师,我采用代码对一部分区域进行了填充,后续做了一个双击修改图案得功能,可是修改后将孔洞也填充了;麻烦老师帮忙看下

void AreaPatternTest(Dpoint3d point)
	{
		if (wcscmp(g_PartTernStrcut.m_wchCellFilePath,L"") == 0)
		{
			mdlDialog_openMessageBox(DIALOGID_MsgBoxOK, L"请浏览单元库文件并选择填充图案进行填充", MessageBoxIconType::Warning);
			return;
		}
		if (wcscmp(g_PartTernStrcut.m_wchGriaphicName, L"") == 0)
		{
			mdlDialog_openMessageBox(DIALOGID_MsgBoxOK, L"请先选择填充图案", MessageBoxIconType::Warning);
			return;
		}
		BeFileName outFileName, inFileName(g_PartTernStrcut.m_wchCellFilePath); // AreaPat.cel is under MS_CELL pointed folder
		mdlCell_attachLibrary(outFileName, &inFileName, NULL, 1);
		PatternParamsPtr params = PatternParams::Create();
		params->SetCellName(g_PartTernStrcut.m_wchGriaphicName);
		
		params->SetPrimarySpacing(g_PartTernStrcut.m_dRowDistance * UOR_PER_MM);
		//设置角度
		double iPartCount = 0.0;
		if (g_PartTernStrcut.m_dAngel != 0)
		{
	       iPartCount = (double)180 /fmod(g_PartTernStrcut.m_dAngel,180);
		   params->SetPrimaryAngle(PI / iPartCount);
		}//设置图案角度的45°
		else 
		{
			params->SetPrimaryAngle(0);
		}		
 		params->SetSecondarySpacing(g_PartTernStrcut.m_dColumnDistance * UOR_PER_MM);
// 		params->SetSecondaryAngle(PI / 3);
 		params->SetScale(g_PartTernStrcut.m_dRatio);
		MSElementDescrP elementDesc = NULL;		
		mdlRegion_floodFillWithHoles(&elementDesc, NULL, EleGraphics.m_AllboundaryElmsEdp, NULL, MASTERFILE, &point, 0xffff, true, 200, -1);
		//mdlRegion_floodFill(&elementDesc, NULL, EleGraphics.m_AllboundaryElmsEdp, NULL, &point, 200, NULL);
		if (elementDesc == NULL)
		{
			return;
		}
		EditElementHandle eeh(elementDesc,true,false,ACTIVEMODEL);
		/*IAreaFillPropertiesEdit * fillEditP = dynamic_cast<IAreaFillPropertiesEdit *>(&eeh.GetHandler());
		if (fillEditP == NULL)
		{
			return;
		}
		fillEditP->AddPattern(eeh, *params, NULL);*/
		
		eeh.AddToModel();
		ElementRefP OldEehRef = eeh.GetElementRef();
		bvector<DependencyRoot> boundaryRoots;
		ElementAgenda boundary;
		boundary.Insert(eeh);
		DependencyRoot depRoot;
		depRoot.elemid = eeh.GetElementId();
		depRoot.refattid = 0;
		depRoot.ref = eeh.GetElementRef();
		boundaryRoots.push_back(depRoot);

		RegionParams paramFill;
		paramFill.SetAssociative(false);
		paramFill.SetDirty(true);
		paramFill.SetInvisibleBoundary(true);
		paramFill.SetType(RegionType::Flood);
		paramFill.SetFloodParams(RegionLoops::Ignore, 0.0001);
		paramFill.SetFlattenBoundary(true, NULL);
		EditElementHandle eehRegion;
		if (SUCCESS != AssocRegionCellHeaderHandler::CreateAssocRegionElement(eehRegion, boundary, &boundaryRoots[0], 1, &point, 1, paramFill, L"MyAssocRegion"))
		{
			mdlDialog_dmsgsPrint(L"Error in creating AssocRegionElement");
			return;
		}
		
		IAreaFillPropertiesEdit * fillEditP = dynamic_cast<IAreaFillPropertiesEdit *>(&eehRegion.GetHandler());
		if (fillEditP == NULL)
		{
			return;
		}
		fillEditP->AddPattern(eehRegion, *params, NULL);

		//添加XAttribute属性
		XAttributeHandlerId handler(Major, Minor);
		
		eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_CELLPATH, sizeof(wchar_t)*(wcslen(g_PartTernStrcut.m_wchCellFilePath)+1), &g_PartTernStrcut.m_wchCellFilePath);
		eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_ANGEL, sizeof(double), &g_PartTernStrcut.m_dAngel);
		eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_Ratio, sizeof(double), &g_PartTernStrcut.m_dRatio);
		eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_ROWDISTANCE, sizeof(double), &g_PartTernStrcut.m_dColumnDistance);
		eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_COLUMNDISTANCE, sizeof(double), &g_PartTernStrcut.m_dColumnDistance);
		eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_CELLNAME, sizeof(wchar_t)*(wcslen(g_PartTernStrcut.m_wchGriaphicName)+1), &g_PartTernStrcut.m_wchGriaphicName);

		//wchar_t name[256] = {0};
		//void* voidPtr = NULL;
		eehRegion.AddToModel();
		//XAttributeHandlerId handler('SR'/*Major*/, 503/*Minor*/);
		//if (XAttributeHandle::HasAttribute(eehRegion.GetElementDescrCP()->h.elementRef, handler, XATTRIBUTE_ID_CELLPATH)) // 通过查找xattribute类型来判断是否为门窗
		//{
		//	XAttributeHandle xah(eehRegion.GetElementDescrCP()->h.elementRef, handler, XATTRIBUTE_ID_CELLPATH);
		//	//voidPtr = const_cast<void*>(xah.PeekData());
		//	wcscpy_s(name, (wchar_t*)(xah.PeekData()));
		//}
		ElementPropertiesSetterPtr remapper = ElementPropertiesSetter::Create();
		remapper->SetTransparency(90);//设置周边线框透明度,不能删除,删除后填充区域线条变成虚线
		remapper->Apply(eeh);
		eeh.ReplaceInModel(OldEehRef);
	}
void ModifyFillGraphics()
{
	BeFileName outFileName, inFileName(g_PartTernStrcutModify.m_wchCellFilePath); // AreaPat.cel is under MS_CELL pointed folder
	mdlCell_attachLibrary(outFileName, &inFileName, NULL, 1);
	PatternParamsPtr params = PatternParams::Create();
	params->SetCellName(g_PartTernStrcutModify.m_wchGriaphicName);

	params->SetPrimarySpacing(g_PartTernStrcutModify.m_dRowDistance * UOR_PER_MM);
	//设置角度
	double iPartCount = 0.0;
	if (g_PartTernStrcutModify.m_dAngel != 0)
	{
		iPartCount = (double)180 / fmod(g_PartTernStrcutModify.m_dAngel, 180);
		params->SetPrimaryAngle(PI / iPartCount);
	}//设置图案角度的45°
	else
	{
		params->SetPrimaryAngle(0);
	}
	params->SetSecondarySpacing(g_PartTernStrcutModify.m_dColumnDistance * UOR_PER_MM);
	// 		params->SetSecondaryAngle(PI / 3);
	params->SetScale(g_PartTernStrcutModify.m_dRatio);
	
	EditElementHandle eehRegion(g_iCurrentId, ACTIVEMODEL);
	ElementRefP odlRefP = eehRegion.GetElementRef();
	IAreaFillPropertiesEdit * fillEditP = dynamic_cast<IAreaFillPropertiesEdit *>(&eehRegion.GetHandler());
	if (fillEditP == NULL)
	{
		return;
	}
	//fillEditP->RemovePattern(eehRegion,0);
	fillEditP->AddPattern(eehRegion, *params, NULL);

	//添加XAttribute属性,先删再加
	XAttributeHandlerId handler(Major, Minor);
	eehRegion.ScheduleDeleteXAttribute(handler, XATTRIBUTE_ID_CELLPATH);
	eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_CELLPATH, sizeof(wchar_t)*(wcslen(g_PartTernStrcutModify.m_wchCellFilePath)+1), &g_PartTernStrcutModify.m_wchCellFilePath);
	eehRegion.ScheduleDeleteXAttribute(handler, XATTRIBUTE_ID_ANGEL);
	eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_ANGEL, sizeof(double), &g_PartTernStrcutModify.m_dAngel);
	eehRegion.ScheduleDeleteXAttribute(handler, XATTRIBUTE_ID_Ratio);
	eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_Ratio, sizeof(double), &g_PartTernStrcutModify.m_dRatio);
	eehRegion.ScheduleDeleteXAttribute(handler, XATTRIBUTE_ID_ROWDISTANCE);
	eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_ROWDISTANCE, sizeof(double), &g_PartTernStrcutModify.m_dColumnDistance);
	eehRegion.ScheduleDeleteXAttribute(handler, XATTRIBUTE_ID_COLUMNDISTANCE);
	eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_COLUMNDISTANCE, sizeof(double), &g_PartTernStrcutModify.m_dColumnDistance);
	eehRegion.ScheduleDeleteXAttribute(handler, XATTRIBUTE_ID_CELLNAME);
	eehRegion.ScheduleWriteXAttribute(handler, XATTRIBUTE_ID_CELLNAME, sizeof(wchar_t)*(wcslen(g_PartTernStrcutModify.m_wchGriaphicName)+1), &g_PartTernStrcutModify.m_wchGriaphicName);

	//eehRegion.AddToModel();
	eehRegion.ReplaceInModel(odlRefP);
}

Parents Reply Children
No Data