Integrating Boolean Functionality with Pre-Populated Body IDs in Visualize-Parasolid

Hello,

I am working with the Boolean functionality in Parasolid, referencing the following resources:

Currently, the Boolean function relies on selecting the target and tool bodies in the interface, which then populates the following variables:

HPS::Component targetComp = m_pCmdOp->GetTargetComponent();
HPS::ComponentArray toolCompArr = m_pCmdOp->GetToolComponents();

However, I want to modify the Boolean function to work directly with pre-populated body IDs stored in:

std::vector<PK_BODY_t> TargetBodyIDArray;
std::vector<PK_BODY_t> ToolBodyIDArray;

This would allow integration with other functions without requiring manual selection of target and tool bodies.

The primary issue occurs when deleting the tool body from the map , registering it as a deleted model and deleting tool component because the function currently relies on toolCompArr. The problematic section is in the following code:

void BooleanDlg::OnOK()
{
	auto t0 = std::chrono::system_clock::now();

	m_pCmdOp->Unhighlight();

	UpdateData(true);
	int iBoolType = m_iTBoolype;

	HPS::Component targetComp = m_pCmdOp->GetTargetComponent();
	HPS::ComponentArray toolCompArr = m_pCmdOp->GetToolComponents();

	if (HPS::Type::None != targetComp.Type() && 0 < toolCompArr.size())
	{
		HPS::Component::DeleteMode deleteMode = HPS::Component::DeleteMode::Standard;

#ifdef USING_EXCHANGE_PARASOLID
		PK_BODY_t targetBody = ((HPS::Parasolid::Component)targetComp).GetParasolidEntity();
		std::vector<PK_BODY_t> toolBodyArr;
		for (int i = 0; i < toolCompArr.size(); i++)
		{
			toolBodyArr.push_back(((HPS::Parasolid::Component)toolCompArr[i]).GetParasolidEntity());
		}

		int resBodyCnt = 0;
		PK_BODY_t* resBodies;
		if (!m_pProcess->Boolean((PsBoolType)m_iTBoolype, targetBody, toolBodyArr.size(), toolBodyArr.data(), resBodyCnt, resBodies))
			return;

		for (int i = 0; i < resBodyCnt; i++)
		{
			PK_BODY_t resBody = resBodies[i];
			if (resBody == targetBody)
			{
				// Tessellate
				((HPS::Parasolid::Component)targetComp).Tessellate(
					HPS::Parasolid::FacetTessellationKit::GetDefault(),
					HPS::Parasolid::LineTessellationKit::GetDefault());

				// Register target body as updated model
				HPS::Exchange::Component ownerComp = view->GetOwnerBrepModel(targetComp);
				A3DRiBrepModel* pRiBrepModel = ownerComp.GetExchangeEntity();
				m_pProcess->RegisterUpdatedBody(pRiBrepModel, targetBody);

				// Update Ps component map
				view->InitPsBodyMap((int)targetBody, targetComp);
			}
			else
			{
				// Add new body
				view->AddBody(resBody);
			}
		}

		for (int i = 0; i < toolBodyArr.size(); i++)
		{
			// Delete toolbody from map
			view->DeletePsBodyMap(toolBodyArr[i]);

			// Register tool body as deleted model
			HPS::Exchange::Component ownerComp = view->GetOwnerBrepModel(toolCompArr[i]);
			A3DRiBrepModel* pRiBrepModel = ownerComp.GetExchangeEntity();
			m_pProcess->RegisterDeleteBody(pRiBrepModel);
		}

#else
		A3DRiBrepModel* pTargetBrep = ((HPS::Exchange::Component)targetComp).GetExchangeEntity();
		std::vector< A3DRiBrepModel*> pToolBrepArr;
		for (int i = 0; i < toolCompArr.size(); i++)
			pToolBrepArr.push_back(((HPS::Exchange::Component)toolCompArr[i]).GetExchangeEntity());

		if (!m_pProcess->Boolean((PsBoolType)m_iTBoolype, pTargetBrep, pToolBrepArr.size(), pToolBrepArr.data()))
			return;

		// Reload target component
		HPS::Exchange::ReloadNotifier notifier = ((HPS::Exchange::Component)targetComp).Reload();
		notifier.Wait();

		deleteMode = HPS::Component::DeleteMode::StandardAndExchange;
#endif
		// Delete tool component
		for (int i = 0; i < toolCompArr.size(); i++)
			toolCompArr[i].Delete(deleteMode);

		view->GetCanvas().Update();

		// Show process time
		auto t1 = std::chrono::system_clock::now();

		auto dur1 = t1 - t0;
		auto msec1 = std::chrono::duration_cast<std::chrono::milliseconds>(dur1).count();

		wchar_t wcsbuf[256];
		swprintf(wcsbuf, sizeof(wcsbuf), L"Process time: %d msec", msec1);
		view->ShowMessage(wcsbuf);
	}
	DestroyWindow();
}

Since toolCompArr[i] is not available when using directly passed body IDs, I need a way to handle this correctly.

Would you have any suggestions on how to properly map and delete the tool bodies when working with pre-populated body IDs instead of selected components?

Any insights would be greatly appreciated.

Kind regards,
Kazi

Hi Kahmed,

This sample maps a Parasolid PK_BODY to an HPS::Component in HOOPS Visualize.
In HPS operations, the selected target component and tool components identify the corresponding PK_BODY through GetParasolidEntity or GetExchangeEntity API.
When a Boolean operation is performed, the tool bodies are automatically deleted within Parasolid, but the corresponding HPS components are not removed and must be deleted manually.
Even in an integrated environment of HPS and Parasolid, where PK_BODYs are not directly selected during the operation, the components corresponding to the tool bodies should still be removed after the Boolean operation.
How about preparing a custom map that allows you to identify the HPS component from a PK_BODY? (Traversing HPS Components and make a map of PK_BODY using GetParasolidEntity or GetExchangeEntity API)

Toshi


1 Like

Hi Toshi,

It worked! I was to able to map and identify the HPS component from a PK_BODY and it went through deletion. Thank you very much again for your guidance!

Kazi

1 Like