part number is missing inside the shape's information

Hello, I'm reading the shapes information from a stp file and I'm trying to find the "part number" (or "product number", the identification code of a part or an assemlby) but the part/product name is what i get (the nomenclature string). I can see that if the .stp file contain, for a given product, only the part number, it is loaded correctly inside the shape information, instead, if "name" and "part number" are both present inside the the .stp file, for a given document, only the name is loaded inside the shape. This is how I read the name from the label:

TDF_LabelSequence l_comps = TDF_LabelSequence();
std::string nameOfElem = "";
static Standard_Boolean b = aShapeTool->GetComponents(lab, l_comps);
Handle(TDataStd_Name) N;
if (b && lab.FindAttribute(TDataStd_Name::GetID(), N)) {
    TCollection_ExtendedString name = N->Get();
	nameOfElem = TCollection_AsciiString(name).ToCString();
    std::cout << nameOfElem << std::endl;
}

Based on this hierarchy

the code print the part name for the first highlighted item and the part number for the second highlighted item in the image. This is a part of the step file content

Where the first highlighted item has a part name and a part number (but the part name is used as name inside the shape structure) and the second highlighted item has only the part number (which is used as name).

I would like to access the part number because this is the string I need.

Dmitrii Pasukhin's picture

Hello, currect version of STEP reader support by default "name". If there is no "name" used "part number" instead. We don't give the API to configure the behavior. But you are free to modify source code to import what you need. You need to modify "STEPCAFControl_Reader::ReadNames". We have some plans on options for this kind of information, but it will not a part of closed release. There is just a original source code:

//=======================================================================
//function : ReadNames
//purpose  : 
//=======================================================================

Standard_Boolean STEPCAFControl_Reader::ReadNames(const Handle(XSControl_WorkSession) &WS,
                                                  const Handle(TDocStd_Document)& Doc,
                                                  const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const
{
  // get starting data
  const Handle(Interface_InterfaceModel) &Model = WS->Model();
  const Handle(XSControl_TransferReader) &TR = WS->TransferReader();
  const Handle(Transfer_TransientProcess) &TP = TR->TransientProcess();
  Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
  if (STool.IsNull()) return Standard_False;
  STEPConstruct_Tool Tool(WS);

  // iterate on model to find all SDRs and CDSRs
  Standard_Integer nb = Model->NbEntities();
  Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
  Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
  Handle(Standard_Type) tPDWAD = STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments);
  Handle(TCollection_HAsciiString) name;
  TDF_Label L;
  for (Standard_Integer i = 1; i <= nb; i++) {
    Handle(Standard_Transient) enti = Model->Value(i);

    // get description of NAUO
    if (enti->DynamicType() == tNAUO) {
      L.Nullify();
      Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
        Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
      if (NAUO.IsNull()) continue;
      Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
      for (subs.Start(); subs.More(); subs.Next()) {
        Handle(StepRepr_ProductDefinitionShape) PDS =
          Handle(StepRepr_ProductDefinitionShape)::DownCast(subs.Value());
        if (PDS.IsNull()) continue;
        Handle(StepBasic_ProductDefinitionRelationship) PDR = PDS->Definition().ProductDefinitionRelationship();
        if (PDR.IsNull()) continue;
        if (PDR->HasDescription() &&
          PDR->Description()->UsefullLength() > 0) name = PDR->Description();
        else if (!PDR->Name().IsNull() && PDR->Name()->UsefullLength() > 0) name = PDR->Name();
        else if (!PDR->Id().IsNull()) name = PDR->Id();
        else name = new TCollection_HAsciiString;
      }
      // find proper label
      L = FindInstance(NAUO, STool, Tool, myMap);
      if (L.IsNull()) continue;

      TCollection_ExtendedString str = convertName (name->String());
      TDataStd_Name::Set(L, str);
    }

    // for PD get name of associated product
    if (enti->DynamicType() == tPD || enti->DynamicType() == tPDWAD) {
      L.Nullify();
      Handle(StepBasic_ProductDefinition) PD =
        Handle(StepBasic_ProductDefinition)::DownCast(enti);
      if (PD.IsNull()) continue;
      Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
      if (Prod.IsNull())
        name = new TCollection_HAsciiString;
      else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
        name = Prod->Name();
      else if (!Prod->Id().IsNull())
        name = Prod->Id();
      else
        name = new TCollection_HAsciiString;
      L = GetLabelFromPD(PD, STool, TP, PDFileMap, myMap);
      if (L.IsNull()) continue;
      TCollection_ExtendedString str = convertName (name->String());
      TDataStd_Name::Set(L, str);
    }
    // set a name to the document
    //TCollection_ExtendedString str = convertName (name->String());
    //TDataStd_Name::Set ( L, str );
  }

  return Standard_True;
}

Besr regards, Dmitrii.

Alessandro Gabrielli's picture

thank you