3838#include < StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
3939#include < StepBasic_DerivedUnit.hxx>
4040#include < StepBasic_DerivedUnitElement.hxx>
41+ #include < StepBasic_GeneralProperty.hxx>
42+ #include < StepBasic_GeneralPropertyAssociation.hxx>
4143#include < StepBasic_HArray1OfDerivedUnitElement.hxx>
4244#include < StepBasic_MeasureValueMember.hxx>
4345#include < StepBasic_Product.hxx>
104106#include < StepRepr_DescriptiveRepresentationItem.hxx>
105107#include < StepRepr_FeatureForDatumTargetRelationship.hxx>
106108#include < StepRepr_HArray1OfRepresentationItem.hxx>
109+ #include < StepRepr_IntegerRepresentationItem.hxx>
107110#include < StepRepr_MeasureRepresentationItem.hxx>
108111#include < StepRepr_NextAssemblyUsageOccurrence.hxx>
109112#include < StepRepr_ProductDefinitionShape.hxx>
110113#include < StepRepr_PropertyDefinition.hxx>
114+ #include < StepRepr_RealRepresentationItem.hxx>
111115#include < StepRepr_Representation.hxx>
112116#include < StepRepr_RepresentationItem.hxx>
113117#include < StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
@@ -247,6 +251,7 @@ STEPCAFControl_Writer::STEPCAFControl_Writer()
247251 myNameMode(Standard_True),
248252 myLayerMode(Standard_True),
249253 myPropsMode(Standard_True),
254+ myMetadataMode(Standard_True),
250255 mySHUOMode(Standard_True),
251256 myGDTMode(Standard_True),
252257 myMatMode(Standard_True),
@@ -266,6 +271,7 @@ STEPCAFControl_Writer::STEPCAFControl_Writer(const Handle(XSControl_WorkSession)
266271 myNameMode(Standard_True),
267272 myLayerMode(Standard_True),
268273 myPropsMode(Standard_True),
274+ myMetadataMode(Standard_True),
269275 mySHUOMode(Standard_True),
270276 myGDTMode(Standard_True),
271277 myMatMode(Standard_True),
@@ -786,6 +792,10 @@ Standard_Boolean STEPCAFControl_Writer::transfer(STEPControl_Writer&
786792 if (GetPropsMode ())
787793 writeValProps (theWriter.WS (), aSubLabels, theIsMulti);
788794
795+ // write metadata
796+ if (GetMetadataMode ())
797+ writeMetadata (theWriter.WS (), aSubLabels);
798+
789799 // refresh graph
790800 theWriter.WS ()->ComputeGraph (Standard_True);
791801
@@ -1606,6 +1616,201 @@ Standard_Boolean STEPCAFControl_Writer::writeNames(const Handle(XSControl_WorkSe
16061616
16071617// =================================================================================================
16081618
1619+ Standard_Boolean STEPCAFControl_Writer::writeMetadata (const Handle (XSControl_WorkSession)& theWS,
1620+ const TDF_LabelSequence& theLabels) const
1621+ {
1622+ if (theLabels.IsEmpty ())
1623+ {
1624+ return Standard_False;
1625+ }
1626+
1627+ // Iterate on requested shapes.
1628+ for (TDF_LabelSequence::Iterator aLabelIter (theLabels); aLabelIter.More (); aLabelIter.Next ())
1629+ {
1630+ writeMetadataForLabel (theWS, aLabelIter.Value ());
1631+ }
1632+
1633+ return Standard_True;
1634+ }
1635+
1636+ // =================================================================================================
1637+
1638+ Standard_Boolean STEPCAFControl_Writer::writeMetadataForLabel (
1639+ const Handle (XSControl_WorkSession)& theWS,
1640+ const TDF_Label& theLabel) const
1641+ {
1642+ if (theLabel.IsNull ())
1643+ {
1644+ return Standard_False;
1645+ }
1646+
1647+ // Get working data:
1648+ const Handle (XSControl_TransferWriter)& aTW = theWS->TransferWriter ();
1649+ const Handle (Transfer_FinderProcess)& aFP = aTW->FinderProcess ();
1650+ const Handle (StepData_StepModel)& aModel = Handle (StepData_StepModel)::DownCast (theWS->Model ());
1651+
1652+ // Check if label has metadata (NamedData):
1653+ Handle (TDataStd_NamedData) aNamedData;
1654+ if (!theLabel.FindAttribute (TDataStd_NamedData::GetID (), aNamedData))
1655+ return Standard_False; // No metadata on this label
1656+
1657+ // Find target STEP entity for the current shape:
1658+ if (!myLabels.IsBound (theLabel))
1659+ return Standard_False; // Not recorded as translated, skip
1660+
1661+ const TopoDS_Shape& aShape = myLabels.Find (theLabel);
1662+ Handle (StepShape_ShapeDefinitionRepresentation) aSDR;
1663+ const Handle (TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper (aFP, aShape);
1664+ if (!aFP->FindTypedTransient (aMapper,
1665+ STANDARD_TYPE (StepShape_ShapeDefinitionRepresentation),
1666+ aSDR))
1667+ {
1668+ return Standard_False; // Cannot find STEP representation
1669+ }
1670+
1671+ // Get the product definition from the shape definition representation:
1672+ const Handle (StepRepr_PropertyDefinition) aPropDef = aSDR->Definition ().PropertyDefinition ();
1673+ if (aPropDef.IsNull ())
1674+ return Standard_False;
1675+ const Handle (StepBasic_ProductDefinition) aProdDef = aPropDef->Definition ().ProductDefinition ();
1676+ if (aProdDef.IsNull ())
1677+ return Standard_False;
1678+
1679+ // Export string metadata.
1680+ const TDataStd_DataMapOfStringString& aStringMap = aNamedData->GetStringsContainer ();
1681+ for (TDataStd_DataMapOfStringString::Iterator anIter (aStringMap); anIter.More (); anIter.Next ())
1682+ {
1683+ const TCollection_ExtendedString& aKey = anIter.Key ();
1684+ const TCollection_ExtendedString& aValue = anIter.Value ();
1685+
1686+ // Create descriptive representation item for the value.
1687+ const Handle (StepRepr_DescriptiveRepresentationItem) aDescrItem =
1688+ new StepRepr_DescriptiveRepresentationItem ();
1689+ const Handle (TCollection_HAsciiString) aItemName = new TCollection_HAsciiString (aKey);
1690+ const Handle (TCollection_HAsciiString) aItemValue = new TCollection_HAsciiString (aValue);
1691+ aDescrItem->SetName (aItemName);
1692+ aDescrItem->SetDescription (aItemValue);
1693+
1694+ writeMetadataRepresentationItem (aKey, aModel, aSDR, aProdDef, aDescrItem);
1695+ }
1696+
1697+ // Export integer metadata.
1698+ const TColStd_DataMapOfStringInteger& aIntMap = aNamedData->GetIntegersContainer ();
1699+ for (TColStd_DataMapOfStringInteger::Iterator anIter (aIntMap); anIter.More (); anIter.Next ())
1700+ {
1701+ const TCollection_ExtendedString& aKey = anIter.Key ();
1702+ const Standard_Integer aValue = anIter.Value ();
1703+ // Create integer representation item for the value.
1704+ const Handle (StepRepr_IntegerRepresentationItem) aIntItem =
1705+ new StepRepr_IntegerRepresentationItem ();
1706+ const Handle (TCollection_HAsciiString) aItemName = new TCollection_HAsciiString (aKey);
1707+ aIntItem->Init (aItemName, aValue);
1708+
1709+ writeMetadataRepresentationItem (aKey, aModel, aSDR, aProdDef, aIntItem);
1710+ }
1711+
1712+ // Export real metadata.
1713+ const TDataStd_DataMapOfStringReal& aRealMap = aNamedData->GetRealsContainer ();
1714+ for (TDataStd_DataMapOfStringReal::Iterator anIter (aRealMap); anIter.More (); anIter.Next ())
1715+ {
1716+ const TCollection_ExtendedString& aKey = anIter.Key ();
1717+ const Standard_Real aValue = anIter.Value ();
1718+ // Create real representation item for the value.
1719+ const Handle (StepRepr_RealRepresentationItem) aRealItem = new StepRepr_RealRepresentationItem ();
1720+ const Handle (TCollection_HAsciiString) aItemName = new TCollection_HAsciiString (aKey);
1721+ aRealItem->Init (aItemName, aValue);
1722+
1723+ writeMetadataRepresentationItem (aKey, aModel, aSDR, aProdDef, aRealItem);
1724+ }
1725+
1726+ // Process label children recursively:
1727+ if (theLabel.HasChild ())
1728+ {
1729+ for (Standard_Integer aChildInd = 1 ; aChildInd <= theLabel.NbChildren (); aChildInd++)
1730+ {
1731+ const TDF_Label& aChildLabel = theLabel.FindChild (aChildInd);
1732+ writeMetadataForLabel (theWS, aChildLabel);
1733+ }
1734+ }
1735+
1736+ return Standard_True;
1737+ }
1738+
1739+ // =================================================================================================
1740+
1741+ void STEPCAFControl_Writer::writeMetadataRepresentationItem (
1742+ const TCollection_AsciiString& theKey,
1743+ const Handle (StepData_StepModel)& theModel,
1744+ const Handle(StepShape_ShapeDefinitionRepresentation) theShapeDefRep,
1745+ const Handle(StepBasic_ProductDefinition)& theProdDef,
1746+ const Handle(StepRepr_RepresentationItem)& theItem) const
1747+ {
1748+ // Empty string to use for empty values:
1749+ const Handle (TCollection_HAsciiString) anEmptyStr = new TCollection_HAsciiString (" " );
1750+
1751+ // Create property_definition:
1752+ const Handle (StepRepr_PropertyDefinition) aMetaPropDef = new StepRepr_PropertyDefinition ();
1753+ const Handle (TCollection_HAsciiString) aPropName = new TCollection_HAsciiString (theKey);
1754+ const Handle (TCollection_HAsciiString) aPropDesc =
1755+ new TCollection_HAsciiString (" user defined attribute" );
1756+ aMetaPropDef->SetName (aPropName);
1757+ aMetaPropDef->SetDescription (aPropDesc);
1758+
1759+ // Create a general_property:
1760+ const Handle (StepBasic_GeneralProperty) aGeneralProp = new StepBasic_GeneralProperty ();
1761+ aGeneralProp->SetId (anEmptyStr);
1762+ aGeneralProp->SetName (aPropName);
1763+ aGeneralProp->SetDescription (anEmptyStr);
1764+
1765+ // Create a general_property_association:
1766+ const Handle (StepBasic_GeneralPropertyAssociation) aGeneralPropAssoc =
1767+ new StepBasic_GeneralPropertyAssociation ();
1768+ aGeneralPropAssoc->SetName (anEmptyStr);
1769+ aGeneralPropAssoc->SetDescription (anEmptyStr);
1770+ aGeneralPropAssoc->SetPropertyDefinition (aMetaPropDef);
1771+ aGeneralPropAssoc->SetGeneralProperty (aGeneralProp);
1772+
1773+ // Set the definition to point to the product definition:
1774+ StepRepr_CharacterizedDefinition aCharDef;
1775+ aCharDef.SetValue (theProdDef);
1776+ aMetaPropDef->SetDefinition (aCharDef);
1777+
1778+ // Create property_definition_representation:
1779+ const Handle (StepRepr_PropertyDefinitionRepresentation) aPropDefRepr =
1780+ new StepRepr_PropertyDefinitionRepresentation ();
1781+ StepRepr_RepresentedDefinition aRepDef;
1782+ aRepDef.SetValue (aMetaPropDef);
1783+ aPropDefRepr->SetDefinition (aRepDef);
1784+
1785+ // Create representation with descriptive_representation_item:
1786+ const Handle (StepRepr_Representation) aRepr = new StepRepr_Representation ();
1787+ const Handle (TCollection_HAsciiString) aReprName = new TCollection_HAsciiString (theKey);
1788+ aRepr->SetName (aReprName);
1789+
1790+ // Add item to representation:
1791+ const Handle (StepRepr_HArray1OfRepresentationItem) aItems =
1792+ new StepRepr_HArray1OfRepresentationItem (1 , 1 );
1793+ aItems->SetValue (1 , theItem);
1794+ aRepr->SetItems (aItems);
1795+
1796+ // Set representation context (reuse from shape representation):
1797+ const Handle (StepRepr_RepresentationContext) aRC =
1798+ theShapeDefRep->UsedRepresentation ()->ContextOfItems ();
1799+ aRepr->SetContextOfItems (aRC);
1800+
1801+ aPropDefRepr->SetUsedRepresentation (aRepr);
1802+
1803+ // Add entities to the model:
1804+ theModel->AddWithRefs (aMetaPropDef);
1805+ theModel->AddWithRefs (aGeneralProp);
1806+ theModel->AddWithRefs (aGeneralPropAssoc);
1807+ theModel->AddWithRefs (aPropDefRepr);
1808+ theModel->AddWithRefs (aRepr);
1809+ theModel->AddWithRefs (theItem);
1810+ }
1811+
1812+ // =================================================================================================
1813+
16091814static Standard_Boolean WritePropsForLabel (const Handle (XSControl_WorkSession)& theWS,
16101815 const STEPCAFControl_DataMapOfLabelShape& theLabels,
16111816 const TDF_Label& theLabel,
0 commit comments