Is the sourcecode actually processing CAD layers?

Hi,

I'm using OCCT 7.7.2 and I'm trying to use LayerTool::GetLayer().
As you can see in the source code, right now seems to return the name attribute instead of the actual layer.
Please see attached screenshot to see source code from 7.7.2 and screenshot from inspector in order to verify that sample CAD comes with layers.

Any way to read actual attribute layers from a label?

Kind regards,
Lorenzo Navarro

Dmitrii Pasukhin's picture

hello, which attiributes you want to read?

Best regards, Dmitrii.

Lorenzo Napl's picture

Layers, please see the attached screenshot "layers.png"
As stated in the previous message, the actual implementation of GetLayers from LayerTool is not working.
Right now (v7.7.2), XCADDoc_LayerTool::GetLayer(const TDF_Label& lab, TCollection_ExtendedString& aLayer) const seems that is returning attributes names.

Attachments: 
Dmitrii Pasukhin's picture

You want to find label layer or connected shapes? We have no own class for Layer, only reference and connection + name, color and materials.

Best regards, Dmitrii.

Dmitrii Pasukhin's picture
  //! Return sequanese of shape labels that assigned with layers to <ShLabels>.
  Standard_EXPORT static void GetShapesOfLayer (const TDF_Label& theLayerL, TDF_LabelSequence& theShLabels);

Helps you to get connected shapes

  //! Returns a sequence of Layers currently stored
  //! in the Layertable
  Standard_EXPORT void GetLayerLabels (TDF_LabelSequence& Labels) const;

Helps to get any layer labels.

Best regards, Dmitrii.

Lorenzo Napl's picture

I want to get the layer that appears as a reference on a label.
Please see attached image "layers.png".
As I understand, In this case the layer 0:1:1:1:22 contains a reference to a layer 0:1:3:2 with name "table".
What I want is to get 0:1:3:2 in order to get the name.

I manage to get it using the following steps:
1- Iterate by all attributes from a label searching for a Layer attribute.
2- Once found get the GraphNode and then get the label associated to it.
3- Get name from that label.

As my understanding, steps 1 and 2 are the ones that XCADDoc_LayerTool::GetLayer(const TDF_Label& lab, TCollection_ExtendedString& aLayer) const should be doing...

Attachments: 
Dmitrii Pasukhin's picture

XCADDoc_LayerTool offer two way of connection: extract each LayerLabels(sequence of 0:1:3:*) or extract layer list connected with specific label.

There is full sample to extract shapes connected to specific layer. Any details in header file or documentation.

Handle(XCAFDoc_LayerTool) aLTool = XCafDoc_DocumentTool::LayerTool(aDoc->Main());
TDF_LabelSequence aLayers;
aLTool->GetLayerLabels(aLayers);
for (const auto& aLayer: aLayers)
{
  TCollection_ExtendedString aLayerName;
  aLTool->GetLayer(aLayer, aLayerName);
  std::cout << "Layer name:" << aLayerName << std::endl;
  TDF_LabelSequence aShapes;
  XCAFDoc_LayerTool::GetShapesOfLayer(aLayer, aShapes);
  auto aShTool = aLTool->ShapeTool();
  for (const auto& aShape: aShapes)
  {
    TopoDS_Shape aShape = aShTool->GetShape(aShape);
  }
}

 

Lorenzo Napl's picture

Sorry but why should I need the shapes in this case? I just want the layer associated with a specific Label.
The first 2 lines inside your for sample doesn't work:

  TCollection_ExtendedString aLayerName;
  aLTool->GetLayer(aLayer, aLayerName);

GetLayer as I said on my first message is returning the name attribute, as you can see in OCCT 7.7.2, and I think that this is incorrect:

//=======================================================================
//function : GetLayer
//purpose  : 
//=======================================================================

Standard_Boolean XCAFDoc_LayerTool::GetLayer(const TDF_Label& lab, TCollection_ExtendedString& aLayer) const
{
  if ( lab.Father() != Label() ) return Standard_False;
//   Handle(XCAFDoc_GraphNode) aGN;
//   if (! lab.FindAttribute (XCAFDoc::LayerRefGUID(), aGN))
//     return Standard_False;
  Handle(TDataStd_Name) aName;
  Standard_Boolean status = Standard_False;
  if ( lab.FindAttribute (TDataStd_Name::GetID(), aName) ) {
    aLayer = aName->Get();
    status = Standard_True;
  }
  return status;
}

Kind regards,
Lorenzo

Dmitrii Pasukhin's picture

Returning name is correct. Please read include file.

Getting layer connected to shape(shapeLabel) is available by "aLTool->GetLayers(const TopoDS_Shape& Sh, TDF_LabelSequence& aLayerLS)

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

My sample was correct with purpose to extract each layer and its connection. If you need to excract layer from connection need another sample. Use my previous message about "aLTool->GetLayers(const TopoDS_Shape& Sh, TDF_LabelSequence& aLayerLS) "