AcGiSubEntityTraits::setLayer() and line weight, transparency and plottable

AcGiSubEntityTraits::setLayer() and line weight, transparency and plottable

maisoui
Advocate Advocate
1,421 Views
7 Replies
Message 1 of 8

AcGiSubEntityTraits::setLayer() and line weight, transparency and plottable

maisoui
Advocate
Advocate

Hi,

 

In the worlddraw/viewportdraw of my custom entity, I call AcGiSubEntityTraits::setLayer() several times to change drawing properties of primitives. But, only color and lineType are applied from layer. What about line weight, transparency and plottable/frozen/inactive?

 

Do I need to manually "sync" these properties? Something like this:

wd->subEntityTraits().setLayer(idLayer);
AcDbLayerTableRecordPointer pLayer(idLayer, AcDb::kForRead);
if(pLayer.openStatus() == Acad::eOk)
{
	wd->subEntityTraits().setLineWeight(pLayer->lineWeight());
	wd->subEntityTraits().set...
}

Note: I use layers as properties for my custom entity because it's very user convenient (layer = container of multiple properties).

 

Best regards,

--
Jonathan
0 Likes
1,422 Views
7 Replies
Replies (7)
Message 2 of 8

owenwengerd
Advisor
Advisor

Are all those other properties set to "bylayer"?

--
Owen Wengerd
ManuSoft
0 Likes
Message 3 of 8

maisoui
Advocate
Advocate

Yes for sure.

If I change these properties on the layer (of my custom entity), it is applied to all primitives which are yet another layer (i.e. subEntityTraits()->setLayer()).

A couple of illustrations:

 

layers1.png

result1.png

 

 

layers2.png

result2.png

 

Code to reproduce:

Adesk::Boolean BcEntity::subWorldDraw(AcGiWorldDraw * wd)
{
	assertReadEnabled();

	if(wd->regenAbort() == Adesk::kTrue)
		return Adesk::kTrue;

	wd->geometry().circle(AcGePoint3d::kOrigin, 600, m_normal);

	AcDbLayerTablePointer pLayerTable(database() == NULL ? curDatabase() : database(), AcDb::kForRead);
	if(pLayerTable.openStatus() == Acad::eOk)
	{
		AcDbObjectId idLayer;

		if(pLayerTable->getAt(_T("1"), idLayer) == Acad::eOk)
		{
			wd->subEntityTraits().setLayer(idLayer);
			wd->geometry().circle(AcGePoint3d::kOrigin, 500, m_normal);
		}

		if(pLayerTable->getAt(_T("2"), idLayer) == Acad::eOk)
		{
			wd->subEntityTraits().setLayer(idLayer);
			wd->geometry().circle(AcGePoint3d::kOrigin, 400, m_normal);
		}

		if(pLayerTable->getAt(_T("3"), idLayer) == Acad::eOk)
		{
			wd->subEntityTraits().setLayer(idLayer);
			wd->geometry().circle(AcGePoint3d::kOrigin, 300, m_normal);
		}

		if(pLayerTable->getAt(_T("4"), idLayer) == Acad::eOk)
		{
			wd->subEntityTraits().setLayer(idLayer);
			wd->geometry().circle(AcGePoint3d::kOrigin, 200, m_normal);
		}

		if(pLayerTable->getAt(_T("5"), idLayer) == Acad::eOk)
		{
			wd->subEntityTraits().setLayer(idLayer);
			wd->geometry().circle(AcGePoint3d::kOrigin, 100, m_normal);
		}
	}

	return Adesk::kTrue;
}

Best regards

--
Jonathan
0 Likes
Message 4 of 8

Anonymous
Not applicable

What Owen commented is about something like this:

Adesk::Boolean MyCustomObject::subWorldDraw (AcGiWorldDraw *mode) {
	assertReadEnabled () ;
	
	//if(mode->regenAbort() == Adesk::kTrue)
	//return Adesk::kTrue;

	AcGeVector3d normal = AcGeVector3d::kZAxis;
	AcCmTransparency transparency;
	transparency.setMethod(AcCmTransparency::kByLayer);

	mode->geometry().circle(AcGePoint3d::kOrigin, 600, normal);

	AcDbLayerTablePointer pLayerTable(acdbHostApplicationServices()->workingDatabase(), AcDb::kForRead);
	if(pLayerTable.openStatus() == Acad::eOk)
	{
		AcDbObjectId idLayer;

		if(pLayerTable->getAt(_T("1"), idLayer) == Acad::eOk)
		{
			mode->subEntityTraits().setLayer(idLayer);
			mode->subEntityTraits().setLineWeight(AcDb::kLnWtByLayer);
			mode->subEntityTraits().setTransparency(transparency);
			mode->geometry().circle(AcGePoint3d::kOrigin, 500, normal);
		}

		if(pLayerTable->getAt(_T("2"), idLayer) == Acad::eOk)
		{
			mode->subEntityTraits().setLayer(idLayer);
			mode->subEntityTraits().setLineWeight(AcDb::kLnWtByLayer);
			mode->subEntityTraits().setTransparency(transparency);
			mode->geometry().circle(AcGePoint3d::kOrigin, 400, normal);
		}

		if(pLayerTable->getAt(_T("3"), idLayer) == Acad::eOk)
		{
			mode->subEntityTraits().setLayer(idLayer);
			mode->subEntityTraits().setLineWeight(AcDb::kLnWtByLayer);
			mode->subEntityTraits().setTransparency(transparency);
			mode->geometry().circle(AcGePoint3d::kOrigin, 300, normal);
		}

		if(pLayerTable->getAt(_T("4"), idLayer) == Acad::eOk)
		{
			mode->subEntityTraits().setLayer(idLayer);
			mode->subEntityTraits().setLineWeight(AcDb::kLnWtByLayer);
			mode->subEntityTraits().setTransparency(transparency);
			mode->geometry().circle(AcGePoint3d::kOrigin, 200, normal);
		}

		if(pLayerTable->getAt(_T("5"), idLayer) == Acad::eOk)
		{
			mode->subEntityTraits().setLayer(idLayer);
			mode->subEntityTraits().setLineWeight(AcDb::kLnWtByLayer);
			mode->subEntityTraits().setTransparency(transparency);
			mode->geometry().circle(AcGePoint3d::kOrigin, 100, normal);
		}
	}

	return (AcDbEntity::subWorldDraw (mode)) ;
}

hth.-

Message 5 of 8

maisoui
Advocate
Advocate

Oh perfect, it works. I had not realized I had to do it after each setLayer().

And what about the plottable property? Do you have an idea?

 

Thank you for your help.

--
Jonathan
0 Likes
Message 6 of 8

Anonymous
Not applicable

for the plottable part, i would do something like this, on each of the desired layers:

		if(pLayerTable->getAt(_T("1"), idLayer) == Acad::eOk)
		{
			AcGiContext* context = mode->context();
			if (context->isPlotGeneration() == Adesk::kTrue)
			{
				AcDbLayerTableRecordPointer pLayer(idLayer, AcDb::kForRead);
				if (pLayer.openStatus() == Acad::eOk && pLayer->isPlottable()) 
				{
					mode->subEntityTraits().setLayer(idLayer);
					mode->subEntityTraits().setLineWeight(AcDb::kLnWtByLayer);
					mode->subEntityTraits().setTransparency(transparency);
					mode->geometry().circle(AcGePoint3d::kOrigin, 500, normal);
				}
			}
			else
			{
				mode->subEntityTraits().setLayer(idLayer);
				mode->subEntityTraits().setLineWeight(AcDb::kLnWtByLayer);
				mode->subEntityTraits().setTransparency(transparency);
				mode->geometry().circle(AcGePoint3d::kOrigin, 500, normal);
			}
		}

hth.-

0 Likes
Message 7 of 8

maisoui
Advocate
Advocate

I thought of a solution like this. But It's a "manual approach". I think the API should manage it for me.

Thank you for your help.

Regards,

--
Jonathan
0 Likes
Message 8 of 8

Anonymous
Not applicable

Yes, i used this in the past, and i see what you mean, as to why not currently the part of mode->subEntityTraits().setLayer(idLayer); does not takes care of updating the entity as (just for testing purposes), one can get by using AcGiDrawable's and get the effect without doing any of the subEntityTraits().setXXXX calls.

in example:

AcDbCircle* circle = new AcDbCircle(AcGePoint3d::kOrigin, normal, 500);	
circle->setLayer(idLayer);
mode->geometry().draw(circle);

even without testing for isPlotting()...

0 Likes