Page 1 of 1

Creating a solid circle

Posted: 11 May 2018, 00:11
by marym
I created this method to create a hollow circle. How can I modify it to fill it in with color?

Code: Select all

void CadSoftToolsH::AddCircle(double xCtr, double yCtr, double radius, String LayerName, const Graphics::TColor color)
{
	TsgDXFCircle * vCircle = new TsgDXFArc();
	vCircle->Radius = radius;
	vCircle->Point = MakeFPoint(xCtr, yCtr, 0);
	vCircle->Color = color;
	vCircle->Layer = pDrawing->Converter->LayerByName(LayerName);
	if(!PlaceEntity(vCircle))
		delete vCircle;
}

bool CadSoftToolsH::PlaceEntity(TsgDXFEntity *AEntity, const AnsiString ALayoutName )
{
	bool result = false;
	TsgDXFLayout *vLayout;
	if (ALayoutName == "") {
		vLayout = pDrawing->Converter->Layouts[0];
	}
	else
		vLayout = pDrawing->Converter->LayoutByName(ALayoutName);
	if (vLayout)
	{
		pDrawing->Converter->Loads(AEntity);
		if (pDrawing->Converter->OnCreate)
			pDrawing->Converter->OnCreate(AEntity);
		vLayout->AddEntity(AEntity);
		result = true;
	}
	return result;
}

protected:
	TsgDWGImage *pDrawing;




Re: Creating a solid circle

Posted: 11 May 2018, 22:57
by support
Hello Mary,

You can add a filling to a circle by using TsgCADCurvePolygon and Tsg2DArc objects:

Code: Select all

void CadSoftToolsH::AddFilling(TsgDXFCircle *ACircle, const Graphics::TColor AColor)
{
   Tsg2DArc *v2DArc = new Tsg2DArc();
   v2DArc->CenterPoint = MakeF2DPointFrom3D(ACircle->Point);
   v2DArc->Radius = ACircle->Radius;
   v2DArc->StartParam = 0;
   v2DArc->EndParam = 360;

   TsgCADCurvePolygon *vCADCurvePolygon = new TsgCADCurvePolygon();
   vCADCurvePolygon->AddBoundaryList(1);
   vCADCurvePolygon->BoundaryData[0]->Add(v2DArc);
   vCADCurvePolygon->Layer = ACircle->Layer;
   vCADCurvePolygon->Color = AColor;

   if (!PlaceEntity(vCADCurvePolygon))
      delete vCADCurvePolygon;
}
The purpose of the Tsg2DArc object is to replicate the circle boundary. Notice that Tsg2DArc and other Tsg2DCurve derivatives are auxiliary objects, they are not added directly to pDrawing->Converter and not visible on the drawing. Their purpose is to make up the boundary of filling or hatch.

The filling may be added right after creating a hollow circle, as follows:

Code: Select all

void CadSoftToolsH::AddCircle(double xCtr, double yCtr, double radius, String LayerName, const Graphics::TColor color)
{
   TsgDXFCircle *vCircle = new TsgDXFCircle();
   vCircle->Radius = radius;
   vCircle->Point = MakeFPoint(xCtr, yCtr, 0);
   vCircle->Color = color;
   vCircle->Layer = pDrawing->Converter->LayerByName(LayerName);

   if(!PlaceEntity(vCircle))
      delete vCircle;
   else
      AddFilling(vCircle, color);
}
Mikhail

Re: Creating a solid circle

Posted: 14 May 2018, 16:16
by marym
Works perfectly. Thank you!