Read GENERAL_PROPERTY with StepBasic_GeneralProperty

Hi.
How can I read the GENERAL_PROPERTY of each nodes?

Should I use one of this tools?

m_stepData = new STEP_Data(cafReader.Reader());
m_shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
m_colorTool = XCAFDoc_DocumentTool::ColorTool(doc->Main());
m_gdtTool = XCAFDoc_DocumentTool::DimTolTool(doc->Main());
m_viewTool = XCAFDoc_DocumentTool::ViewTool(doc->Main());

Is there an example available?
Here is the file : http://davidemercanti.altervista.org/sources/1M001934.stp
Thankx

Dmitrii Pasukhin's picture

Hello,

Current version of OCCT do not support import of User-Defined Attributes.

But this functionality is planned on one of the next releases.

Best regards, Dmitrii.

davide mercanti's picture

so it is not possible to traverse step model

Handle(StepBasic_GeneralProperty) gp = Handle(StepBasic_GeneralProperty)::DownCast(entity);
string id = gp->Id()->ToCString();
string name = gp->Name()->ToCString();
string desc = gp->Description()->ToCString();

and recover the value of the property and know which instance it is connected to?

Dmitrii Pasukhin's picture

In your case - yes.

But there are a little more step entities and processing ways.

Best regards, Dmitrii.

davide mercanti's picture

Can you show me an example on how to retrieve the value of a userproperty of a specific instance?
Thank you

Dmitrii Pasukhin's picture

Hello, yes. I will attach a new ticket a little later this week. The current functionality will be a part of 7.8.0. It will be a beta version of reading this type of data.

If there will not news on this week, please return to me with new message.

I will include this information(metadata) XCAFDoc_NamedData into  XCAF. Can be extracted from Shape label by ShapeTool.

New realization will include a new flag to read or not metadata and will have only limited functionality(by default this data will not read, you will need to enable the flag). But we will update this in the next release.

Best regards, Dmitrii.

davide mercanti's picture

Hello. Any news about this subject?

Dmitrii Pasukhin's picture

Hello,

The first commit will be on current or next week. 0033530: Data Exchange, Step Import - Implemen GENERAL_PROPERTY support - MantisBT (opencascade.org)

Best regards, Dmitrii.

Josep Fontdecaba i Buj's picture

Dimitrii
I have tried many ways to retrieve color from a shape in a STEP file.
The XCAFDoc_ColorTool does not work. It always returns false.
I have tried looping through the entities, something like
Standard_Integer nb = aModel->NbEntities();
float rgb[3] = { 0,0,0 };
for (int i = 1; i <= nb; i++) {
const Handle(Standard_Transient)& anEntity = aModel->Value(i);
Standard_CString name = aModel->TypeName(anEntity);
Standard_CString classname = aModel->ClassName(name);
if (anEntity->IsKind(STANDARD_TYPE(StepVisual_ColourRgb))) {
Handle(StepVisual_ColourRgb) aPD = Handle(StepVisual_ColourRgb)::DownCast(anEntity);
rgb[0] += aPD->Red();
rgb[1] += aPD->Green();
rgb[2] += aPD->Blue();

but it collects all color entities. I haven't found the way to pick the entities belonging to that shape.
Is there a way to find what entities are descendant of a shape or a label ?
Thanks
Josep

Josep Fontdecaba i Buj's picture

This is the code I have tried


Quantity_Color GetShapeColor(const TDF_Label& label, STEPCAFControl_Reader& STEP_reader)
{
	Quantity_Color color;
	const Handle(StepData_StepModel)& aModel = STEP_reader.Reader().StepModel();
	Standard_Integer nb = aModel->NbEntities();

	// i is internal index
	float rgb[3] = { 0,0,0 };
	int nrgb = 0;
	for (int i = 1; i <= nb; i++) {
		const Handle(Standard_Transient)& anEntity = aModel->Value(i);
		Standard_CString name = aModel->TypeName(anEntity);
		Standard_CString classname = aModel->ClassName(name);
		if (anEntity->IsKind(STANDARD_TYPE(StepVisual_ColourRgb))) {
			Handle(StepVisual_ColourRgb) aPD = Handle(StepVisual_ColourRgb)::DownCast(anEntity);
			rgb[0] += aPD->Red();
			rgb[1] += aPD->Green();
			rgb[2] += aPD->Blue();
			nrgb++;
		}
	}
	if (nrgb > 0) {
		color.SetValues(rgb[0] /= nrgb, rgb[1] /= nrgb, rgb[2] /= nrgb, Quantity_TOC_RGB);
	} else {
		color.SetValues(0,0,0, Quantity_TOC_RGB);
	}
	return color;
}

The GetColor doesn't work

			TDF_Label mainLabel = doc->Main();
			Handle(XCAFDoc_ColorTool) ColorTool = XCAFDoc_DocumentTool::ColorTool(mainLabel);
			. . .
			TDF_LabelSequence shapes;
			myShapeTool->GetComponents(Labels.Value(1), shapes, true);
			int nshapes = shapes.Length();
			int elements_count = _debug_STEPcontents(myShapeTool, Labels, shapes, format);
			if (elements_count > 0) {
				int solids_count = 0;
				for (Standard_Integer i = 1; i <= nshapes; ++i) {
					TDF_Label label = shapes.Value(i);
					TopoDS_Shape shape = myShapeTool->GetShape(label);
					Standard_Boolean ispart = label.IsDescendant(Labels.First();
					if (ispart) {
						TopAbs_ShapeEnum t = shape.ShapeType();
						Quantity_Color color
						ColorTool->GetColor(label, color);
						. . . 

Josep Fontdecaba i Buj's picture

The shape variant does not work either

						ColorTool->GetColor(shape, XCAFDoc_ColorCurv, color);
						ColorTool->GetColor(shape, XCAFDoc_ColorSurf, color);
						ColorTool->GetColor(shape, XCAFDoc_ColorGen, color);

All these calls return false too.

Josep

Dmitrii Pasukhin's picture

Hello,to find each shape with color, you are free to use revert iteration (iterate over colour to find shape labels).

  // =======================================================================
  // function : propagateCuttingLineColor
  // purpose  :
  // =======================================================================
  void propagateCuttingLineColor(const Handle(TDocStd_Document) theDoc)
  {
    if (!theDoc || theDoc->ChangeXdeDoc().IsNull())
    {
      return;
    }
    Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
    Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool(theDoc->Main());
    TDF_LabelSequence aColors;
    aColorTool->GetColors(aColors);

    for (TDF_LabelSequence::Iterator anIter(aColors); anIter.More() && !aIsFind; anIter.Next())
    {
      const TDF_Label& aColorL = anIter.Value();
      Handle(TDataStd_TreeNode) aMainNode;
      // I find only ColorCurv, but there are can be ColorSurd and ColorGen(combination)
      if (!anIter.Value().FindAttribute(XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv), aMainNode))
      {
        continue;
      }
      Handle(TDataStd_TreeNode) aPointNode = aMainNode->First();
      while (!aPointNode.IsNull())
      {
        const TDF_Label aShapeL = aPointNode->Label();
      }
    }
  }

If you need to find shapes that have a "cascade" color(color from father and upper), You can use XCAFPrs::CollectStyleSettings withing XCAFPrs.hxx it helps to connect color with  not-directed color

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

Hello,

Unfortunatelly, according Recommented Practices https://www.mbx-if.org/documents/rec_prac_user_def_attributes_v18.pdf There is a problem to store the data into XCAF.

Because in some cases data has no "key" only "value" on other case they are not connected with geometry. That is why we can't include int into 7.8. But we have a lot of plane for full integartion of "user defined attributes" on one of the next releases.

Best regards, Dmitrii.