Skip to content

Commit 91000c4

Browse files
Data Exchange, STEP Export - General Attributes (#634)
- Adds metadata writing capability through new `MetadataMode` flag and `writeMetadata` method - Exports string metadata as STEP `property_definition` entities linked to product definitions - Integrates metadata writing into the main transfer workflow alongside existing property writing
1 parent 711fbc4 commit 91000c4

15 files changed

Lines changed: 400 additions & 156 deletions

File tree

src/DataExchange/TKDESTEP/DESTEP/DESTEP_ConfigurationNode.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ bool DESTEP_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theRe
190190
theResource->BooleanVal("write.layer", InternalParameters.WriteLayer, aScope);
191191
InternalParameters.WriteProps =
192192
theResource->BooleanVal("write.props", InternalParameters.WriteProps, aScope);
193+
InternalParameters.WriteMetadata =
194+
theResource->BooleanVal("write.metadata", InternalParameters.WriteMetadata, aScope);
193195
InternalParameters.WriteMaterial =
194196
theResource->BooleanVal("write.material", InternalParameters.WriteMaterial, aScope);
195197
InternalParameters.WriteVisMaterial =
@@ -562,6 +564,13 @@ TCollection_AsciiString DESTEP_ConfigurationNode::Save() const
562564
aResult += aScope + "write.props :\t " + InternalParameters.WriteProps + "\n";
563565
aResult += "!\n";
564566

567+
aResult += "!\n";
568+
aResult += "!Setting up the write.metadata parameter which is used to indicate "
569+
"write Metadata or not\n";
570+
aResult += "!Default value: +. Available values: \"-\", \"+\"\n";
571+
aResult += aScope + "write.metadata :\t " + InternalParameters.WriteMetadata + "\n";
572+
aResult += "!\n";
573+
565574
aResult += "!\n";
566575
aResult += "!Setting up the write.material parameter which is used to indicate write "
567576
"Material properties or not\n";

src/DataExchange/TKDESTEP/DESTEP/DESTEP_Parameters.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public:
199199
bool WriteName = true; //<! NameMode is used to indicate write Name or not
200200
bool WriteLayer = true; //<! LayerMode is used to indicate write Layers or not
201201
bool WriteProps = true; //<! PropsMode is used to indicate write Validation properties or not
202+
bool WriteMetadata = true; //<! MetadataMode is used to indicate write metadata properties or not.
202203
bool WriteMaterial = true; //<! MaterialMode is used to indicate write Material or not
203204
bool WriteVisMaterial = false; //<! VisMaterialMode is used to indicate write Visual Material or not
204205
STEPControl_StepModelType WriteModelType = STEPControl_AsIs; //<! Gives you the choice of translation mode for an Open CASCADE shape that is being translated to STEP

src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Writer.cxx

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
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>
@@ -104,10 +106,12 @@
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+
16091814
static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession)& theWS,
16101815
const STEPCAFControl_DataMapOfLabelShape& theLabels,
16111816
const TDF_Label& theLabel,

src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Writer.hxx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class XSControl_WorkSession;
4040
class TDocStd_Document;
4141
class STEPCAFControl_ExternFile;
4242
class TopoDS_Shape;
43+
class StepShape_ShapeDefinitionRepresentation;
4344

4445
//! Provides a tool to write DECAF document to the
4546
//! STEP file. Besides transfer of shapes (including
@@ -211,6 +212,11 @@ public:
211212

212213
Standard_Boolean GetPropsMode() const { return myPropsMode; }
213214

215+
//! Set MetadataMode for indicate write metadata or not.
216+
void SetMetadataMode(const Standard_Boolean theMetadataMode) { myMetadataMode = theMetadataMode; }
217+
218+
Standard_Boolean GetMetadataMode() const { return myMetadataMode; }
219+
214220
//! Set SHUO mode for indicate write SHUO or not.
215221
void SetSHUOMode(const Standard_Boolean theSHUOMode) { mySHUOMode = theSHUOMode; }
216222

@@ -316,6 +322,28 @@ protected:
316322
Standard_Boolean writeNames(const Handle(XSControl_WorkSession)& theWS,
317323
const TDF_LabelSequence& theLabels) const;
318324

325+
//! Write metadata assigned to specified labels, to STEP model
326+
Standard_Boolean writeMetadata(const Handle(XSControl_WorkSession)& theWS,
327+
const TDF_LabelSequence& theLabels) const;
328+
329+
//! Write metadata assigned to specified label, to STEP model.
330+
// Also recursively writes metadata for children labels.
331+
Standard_Boolean writeMetadataForLabel(const Handle(XSControl_WorkSession)& theWS,
332+
const TDF_Label& theLabel) const;
333+
334+
//! Write metadata representation item to STEP model.
335+
//! @param theKey The key for metadata item.
336+
//! @param theModel The STEP model to write to.
337+
//! @param theShapeDefRep The shape definition representation.
338+
//! @param theProdDef The product definition.
339+
//! @param theItem The representation item to write.
340+
void writeMetadataRepresentationItem(
341+
const TCollection_AsciiString& theKey,
342+
const Handle(StepData_StepModel)& theModel,
343+
const Handle(StepShape_ShapeDefinitionRepresentation) theShapeDefRep,
344+
const Handle(StepBasic_ProductDefinition)& theProdDef,
345+
const Handle(StepRepr_RepresentationItem)& theItem) const;
346+
319347
//! Write D&GTs assigned to specified labels, to STEP model
320348
Standard_Boolean writeDGTs(const Handle(XSControl_WorkSession)& theWS,
321349
const TDF_LabelSequence& theLabels) const;
@@ -398,6 +426,7 @@ private:
398426
Standard_Boolean myNameMode;
399427
Standard_Boolean myLayerMode;
400428
Standard_Boolean myPropsMode;
429+
Standard_Boolean myMetadataMode;
401430
Standard_Boolean mySHUOMode;
402431
MoniTool_DataMapOfShapeTransient myMapCompMDGPR;
403432
Standard_Boolean myGDTMode;

tests/de_wrapper/configuration/A3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ provider.STEP.OCC.write.name : 1
196196
provider.STEP.OCC.write.layer : 1
197197
provider.STEP.OCC.write.material : 1
198198
provider.STEP.OCC.write.vismaterial : 0
199+
provider.STEP.OCC.write.metadata : 1
199200
provider.STEP.OCC.write.props : 1
200201
provider.STEP.OCC.write.model.type : 0
201202
provider.STEP.OCC.write.cleanduplicates : 0

tests/de_wrapper/configuration/A4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ provider.STEP.OCC.write.layer : 1
141141
provider.STEP.OCC.write.props : 1
142142
provider.STEP.OCC.write.material : 1
143143
provider.STEP.OCC.write.vismaterial : 0
144+
provider.STEP.OCC.write.metadata : 1
144145
provider.STEP.OCC.write.model.type : 0
145146
provider.STEP.OCC.write.cleanduplicates : 0
146147
provider.STEP.OCC.write.scaling.trsf : 1

tests/metadata/step/A1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# !!!! This file is generated automatically, do not edit manually! See end script
22
set filename bug28345_30338.stp
3-
4-
set ref_data {
5-
Property for [0:1:1:1]:
3+
set ref_size 41611
4+
set check_metadata 1
5+
set ref_metadata {Property for [0:1:1:1]:
66
H_CIP : 55.545955351400004
77
ProductID : MVE0300X02S030_ASM
88
ProductName : MVE0300X02S030_ASM
@@ -35,5 +35,4 @@ MODELED_BY :
3535
ProductID : NOCUT_MVE0300X02S030
3636
ProductName : NOCUT_MVE0300X02S030
3737
Description : NOT SPECIFIED
38-
3938
}

0 commit comments

Comments
 (0)