Skip to content
9 changes: 9 additions & 0 deletions src/DataExchange/TKDESTEP/DESTEP/DESTEP_ConfigurationNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ bool DESTEP_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theRe
theResource->BooleanVal("write.layer", InternalParameters.WriteLayer, aScope);
InternalParameters.WriteProps =
theResource->BooleanVal("write.props", InternalParameters.WriteProps, aScope);
InternalParameters.WriteMetadata =
theResource->BooleanVal("write.metadata", InternalParameters.WriteMetadata, aScope);
InternalParameters.WriteMaterial =
theResource->BooleanVal("write.material", InternalParameters.WriteMaterial, aScope);
InternalParameters.WriteVisMaterial =
Expand Down Expand Up @@ -562,6 +564,13 @@ TCollection_AsciiString DESTEP_ConfigurationNode::Save() const
aResult += aScope + "write.props :\t " + InternalParameters.WriteProps + "\n";
aResult += "!\n";

aResult += "!\n";
aResult += "!Setting up the write.metadata parameter which is used to indicate "
"write Metadata or not\n";
aResult += "!Default value: +. Available values: \"-\", \"+\"\n";
aResult += aScope + "write.props :\t " + InternalParameters.WriteMetadata + "\n";
aResult += "!\n";

aResult += "!\n";
aResult += "!Setting up the write.material parameter which is used to indicate write "
"Material properties or not\n";
Expand Down
1 change: 1 addition & 0 deletions src/DataExchange/TKDESTEP/DESTEP/DESTEP_Parameters.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public:
bool WriteName = true; //<! NameMode is used to indicate write Name or not
bool WriteLayer = true; //<! LayerMode is used to indicate write Layers or not
bool WriteProps = true; //<! PropsMode is used to indicate write Validation properties or not
bool WriteMetadata = true; //<! MetadataMode is used to indicate write metadata properties or not.
bool WriteMaterial = true; //<! MaterialMode is used to indicate write Material or not
bool WriteVisMaterial = false; //<! VisMaterialMode is used to indicate write Visual Material or not
STEPControl_StepModelType WriteModelType = STEPControl_AsIs; //<! Gives you the choice of translation mode for an Open CASCADE shape that is being translated to STEP
Expand Down
205 changes: 205 additions & 0 deletions src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Writer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
#include <StepBasic_DerivedUnit.hxx>
#include <StepBasic_DerivedUnitElement.hxx>
#include <StepBasic_GeneralProperty.hxx>
#include <StepBasic_GeneralPropertyAssociation.hxx>
#include <StepBasic_HArray1OfDerivedUnitElement.hxx>
#include <StepBasic_MeasureValueMember.hxx>
#include <StepBasic_Product.hxx>
Expand Down Expand Up @@ -104,10 +106,12 @@
#include <StepRepr_DescriptiveRepresentationItem.hxx>
#include <StepRepr_FeatureForDatumTargetRelationship.hxx>
#include <StepRepr_HArray1OfRepresentationItem.hxx>
#include <StepRepr_IntegerRepresentationItem.hxx>
#include <StepRepr_MeasureRepresentationItem.hxx>
#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
#include <StepRepr_ProductDefinitionShape.hxx>
#include <StepRepr_PropertyDefinition.hxx>
#include <StepRepr_RealRepresentationItem.hxx>
#include <StepRepr_Representation.hxx>
#include <StepRepr_RepresentationItem.hxx>
#include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
Expand Down Expand Up @@ -247,6 +251,7 @@ STEPCAFControl_Writer::STEPCAFControl_Writer()
myNameMode(Standard_True),
myLayerMode(Standard_True),
myPropsMode(Standard_True),
myMetadataMode(Standard_True),
mySHUOMode(Standard_True),
myGDTMode(Standard_True),
myMatMode(Standard_True),
Expand All @@ -266,6 +271,7 @@ STEPCAFControl_Writer::STEPCAFControl_Writer(const Handle(XSControl_WorkSession)
myNameMode(Standard_True),
myLayerMode(Standard_True),
myPropsMode(Standard_True),
myMetadataMode(Standard_True),
mySHUOMode(Standard_True),
myGDTMode(Standard_True),
myMatMode(Standard_True),
Expand Down Expand Up @@ -786,6 +792,10 @@ Standard_Boolean STEPCAFControl_Writer::transfer(STEPControl_Writer&
if (GetPropsMode())
writeValProps(theWriter.WS(), aSubLabels, theIsMulti);

// write metadata
if (GetMetadataMode())
writeMetadata(theWriter.WS(), aSubLabels);

// refresh graph
theWriter.WS()->ComputeGraph(Standard_True);

Expand Down Expand Up @@ -1606,6 +1616,201 @@ Standard_Boolean STEPCAFControl_Writer::writeNames(const Handle(XSControl_WorkSe

//=================================================================================================

Standard_Boolean STEPCAFControl_Writer::writeMetadata(const Handle(XSControl_WorkSession)& theWS,
const TDF_LabelSequence& theLabels) const
{
if (theLabels.IsEmpty())
{
return Standard_False;
Comment thread
dpasukhi marked this conversation as resolved.
}

// Iterate on requested shapes.
for (TDF_LabelSequence::Iterator aLabelIter(theLabels); aLabelIter.More(); aLabelIter.Next())
{
writeMetadataForLabel(theWS, aLabelIter.Value());
}

return Standard_True;
}

//=================================================================================================

Standard_Boolean STEPCAFControl_Writer::writeMetadataForLabel(
const Handle(XSControl_WorkSession)& theWS,
const TDF_Label& theLabel) const
{
if (theLabel.IsNull())
{
return Standard_False;
}

// Get working data:
const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess();
const Handle(StepData_StepModel)& aModel = Handle(StepData_StepModel)::DownCast(theWS->Model());

// Check if label has metadata (NamedData):
Handle(TDataStd_NamedData) aNamedData;
if (!theLabel.FindAttribute(TDataStd_NamedData::GetID(), aNamedData))
return Standard_False; // No metadata on this label

// Find target STEP entity for the current shape:
if (!myLabels.IsBound(theLabel))
return Standard_False; // Not recorded as translated, skip

const TopoDS_Shape& aShape = myLabels.Find(theLabel);
Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
const Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, aShape);
if (!aFP->FindTypedTransient(aMapper,
STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation),
aSDR))
{
return Standard_False; // Cannot find STEP representation
}

// Get the product definition from the shape definition representation:
const Handle(StepRepr_PropertyDefinition) aPropDef = aSDR->Definition().PropertyDefinition();
if (aPropDef.IsNull())
return Standard_False;
const Handle(StepBasic_ProductDefinition) aProdDef = aPropDef->Definition().ProductDefinition();
if (aProdDef.IsNull())
return Standard_False;

// Export string metadata.
const TDataStd_DataMapOfStringString& aStringMap = aNamedData->GetStringsContainer();
for (TDataStd_DataMapOfStringString::Iterator anIter(aStringMap); anIter.More(); anIter.Next())
{
const TCollection_ExtendedString& aKey = anIter.Key();
const TCollection_ExtendedString& aValue = anIter.Value();

// Create descriptive representation item for the value.
const Handle(StepRepr_DescriptiveRepresentationItem) aDescrItem =
new StepRepr_DescriptiveRepresentationItem();
const Handle(TCollection_HAsciiString) aItemName = new TCollection_HAsciiString(aKey);
const Handle(TCollection_HAsciiString) aItemValue = new TCollection_HAsciiString(aValue);
aDescrItem->SetName(aItemName);
aDescrItem->SetDescription(aItemValue);

writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aDescrItem);
}

// Export integer metadata.
const TColStd_DataMapOfStringInteger& aIntMap = aNamedData->GetIntegersContainer();
for (TColStd_DataMapOfStringInteger::Iterator anIter(aIntMap); anIter.More(); anIter.Next())
{
const TCollection_ExtendedString& aKey = anIter.Key();
const Standard_Integer aValue = anIter.Value();
// Create integer representation item for the value.
const Handle(StepRepr_IntegerRepresentationItem) aIntItem =
new StepRepr_IntegerRepresentationItem();
const Handle(TCollection_HAsciiString) aItemName = new TCollection_HAsciiString(aKey);
aIntItem->Init(aItemName, aValue);

writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aIntItem);
}

// Export real metadata.
const TDataStd_DataMapOfStringReal& aRealMap = aNamedData->GetRealsContainer();
for (TDataStd_DataMapOfStringReal::Iterator anIter(aRealMap); anIter.More(); anIter.Next())
{
const TCollection_ExtendedString& aKey = anIter.Key();
const Standard_Real aValue = anIter.Value();
// Create real representation item for the value.
const Handle(StepRepr_RealRepresentationItem) aRealItem = new StepRepr_RealRepresentationItem();
const Handle(TCollection_HAsciiString) aItemName = new TCollection_HAsciiString(aKey);
aRealItem->Init(aItemName, aValue);

writeMetadataRepresentationItem(aKey, aModel, aSDR, aProdDef, aRealItem);
}

// Process label children recursively:
if (theLabel.HasChild())
{
for (Standard_Integer aChildInd = 1; aChildInd <= theLabel.NbChildren(); aChildInd++)
{
const TDF_Label& aChildLabel = theLabel.FindChild(aChildInd);
writeMetadataForLabel(theWS, aChildLabel);
}
}

return Standard_True;
}

//=================================================================================================

void STEPCAFControl_Writer::writeMetadataRepresentationItem(
const TCollection_AsciiString& theKey,
const Handle(StepData_StepModel)& theModel,
const Handle(StepShape_ShapeDefinitionRepresentation) theShapeDefRep,
const Handle(StepBasic_ProductDefinition)& theProdDef,
const Handle(StepRepr_RepresentationItem)& theItem) const
{
// Empty string to use for empty values:
const Handle(TCollection_HAsciiString) anEmptyStr = new TCollection_HAsciiString("");

// Create property_definition:
const Handle(StepRepr_PropertyDefinition) aMetaPropDef = new StepRepr_PropertyDefinition();
const Handle(TCollection_HAsciiString) aPropName = new TCollection_HAsciiString(theKey);
const Handle(TCollection_HAsciiString) aPropDesc =
new TCollection_HAsciiString("user defined attribute");
aMetaPropDef->SetName(aPropName);
aMetaPropDef->SetDescription(aPropDesc);

// Create a general_property:
const Handle(StepBasic_GeneralProperty) aGeneralProp = new StepBasic_GeneralProperty();
aGeneralProp->SetId(anEmptyStr);
aGeneralProp->SetName(aPropName);
aGeneralProp->SetDescription(anEmptyStr);

// Create a general_property_association:
const Handle(StepBasic_GeneralPropertyAssociation) aGeneralPropAssoc =
new StepBasic_GeneralPropertyAssociation();
aGeneralPropAssoc->SetName(anEmptyStr);
aGeneralPropAssoc->SetDescription(anEmptyStr);
aGeneralPropAssoc->SetPropertyDefinition(aMetaPropDef);
aGeneralPropAssoc->SetGeneralProperty(aGeneralProp);

// Set the definition to point to the product definition:
StepRepr_CharacterizedDefinition aCharDef;
aCharDef.SetValue(theProdDef);
aMetaPropDef->SetDefinition(aCharDef);

// Create property_definition_representation:
const Handle(StepRepr_PropertyDefinitionRepresentation) aPropDefRepr =
new StepRepr_PropertyDefinitionRepresentation();
StepRepr_RepresentedDefinition aRepDef;
aRepDef.SetValue(aMetaPropDef);
aPropDefRepr->SetDefinition(aRepDef);

// Create representation with descriptive_representation_item:
const Handle(StepRepr_Representation) aRepr = new StepRepr_Representation();
const Handle(TCollection_HAsciiString) aReprName = new TCollection_HAsciiString(theKey);
aRepr->SetName(aReprName);

// Add item to representation:
const Handle(StepRepr_HArray1OfRepresentationItem) aItems =
new StepRepr_HArray1OfRepresentationItem(1, 1);
aItems->SetValue(1, theItem);
aRepr->SetItems(aItems);

// Set representation context (reuse from shape representation):
const Handle(StepRepr_RepresentationContext) aRC =
theShapeDefRep->UsedRepresentation()->ContextOfItems();
aRepr->SetContextOfItems(aRC);

aPropDefRepr->SetUsedRepresentation(aRepr);

// Add entities to the model:
theModel->AddWithRefs(aMetaPropDef);
theModel->AddWithRefs(aGeneralProp);
theModel->AddWithRefs(aGeneralPropAssoc);
theModel->AddWithRefs(aPropDefRepr);
theModel->AddWithRefs(aRepr);
theModel->AddWithRefs(theItem);
}

//=================================================================================================

static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession)& theWS,
const STEPCAFControl_DataMapOfLabelShape& theLabels,
const TDF_Label& theLabel,
Expand Down
29 changes: 29 additions & 0 deletions src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Writer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class XSControl_WorkSession;
class TDocStd_Document;
class STEPCAFControl_ExternFile;
class TopoDS_Shape;
class StepShape_ShapeDefinitionRepresentation;

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

Standard_Boolean GetPropsMode() const { return myPropsMode; }

//! Set MetadataMode for indicate write metadata or not.
void SetMetadataMode(const Standard_Boolean theMetadataMode) { myMetadataMode = theMetadataMode; }

Standard_Boolean GetMetadataMode() const { return myMetadataMode; }

//! Set SHUO mode for indicate write SHUO or not.
void SetSHUOMode(const Standard_Boolean theSHUOMode) { mySHUOMode = theSHUOMode; }

Expand Down Expand Up @@ -316,6 +322,28 @@ protected:
Standard_Boolean writeNames(const Handle(XSControl_WorkSession)& theWS,
const TDF_LabelSequence& theLabels) const;

//! Write metadata assigned to specified labels, to STEP model
Standard_Boolean writeMetadata(const Handle(XSControl_WorkSession)& theWS,
const TDF_LabelSequence& theLabels) const;

//! Write metadata assigned to specified label, to STEP model.
// Also recursively writes metadata for children labels.
Standard_Boolean writeMetadataForLabel(const Handle(XSControl_WorkSession)& theWS,
const TDF_Label& theLabel) const;

//! Write metadata representation item to STEP model.
//! @param theKey The key for metadata item.
//! @param theModel The STEP model to write to.
//! @param theShapeDefRep The shape definition representation.
//! @param theProdDef The product definition.
//! @param theItem The representation item to write.
void writeMetadataRepresentationItem(
const TCollection_AsciiString& theKey,
const Handle(StepData_StepModel)& theModel,
const Handle(StepShape_ShapeDefinitionRepresentation) theShapeDefRep,
const Handle(StepBasic_ProductDefinition)& theProdDef,
const Handle(StepRepr_RepresentationItem)& theItem) const;

//! Write D&GTs assigned to specified labels, to STEP model
Standard_Boolean writeDGTs(const Handle(XSControl_WorkSession)& theWS,
const TDF_LabelSequence& theLabels) const;
Expand Down Expand Up @@ -398,6 +426,7 @@ private:
Standard_Boolean myNameMode;
Standard_Boolean myLayerMode;
Standard_Boolean myPropsMode;
Standard_Boolean myMetadataMode;
Standard_Boolean mySHUOMode;
MoniTool_DataMapOfShapeTransient myMapCompMDGPR;
Standard_Boolean myGDTMode;
Expand Down
7 changes: 3 additions & 4 deletions tests/metadata/step/A1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# !!!! This file is generated automatically, do not edit manually! See end script
set filename bug28345_30338.stp

set ref_data {
Property for [0:1:1:1]:
set ref_size 41611
set check_metadata 1
set ref_metadata {Property for [0:1:1:1]:
H_CIP : 55.545955351400004
ProductID : MVE0300X02S030_ASM
ProductName : MVE0300X02S030_ASM
Expand Down Expand Up @@ -35,5 +35,4 @@ MODELED_BY :
ProductID : NOCUT_MVE0300X02S030
ProductName : NOCUT_MVE0300X02S030
Description : NOT SPECIFIED

}
21 changes: 15 additions & 6 deletions tests/metadata/step/A2
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# !!!! This file is generated automatically, do not edit manually! See end script
set filename bug28389_CONFIDENTIAL_SHEET_METAL_F3D.stp

set ref_data {
Property for [0:1:1:1]:
set ref_size 980255
set check_metadata 1
set ref_metadata {Property for [0:1:1:1]:
yCenterOfGravity : 0.1148447698
Ixz : 9.3210000000000004e-07
Izx : 9.3210000000000004e-07
Expand All @@ -11,11 +11,11 @@ Surface : 0.34595390710000001
Volume : 0.0001375456
Iyz : -1.2030000000000001e-07
zCenterOfGravity : -0.056064514900000001
Iyy : 3.6385e-06
Ixy : 2.044e-07
Iyy : 3.6385e-06
xCenterOfGravity : -0.12673526900000001
Izz : 3.3558999999999999e-06
Density : 1000
Izz : 3.3558999999999999e-06
Ixx : 1.7740000000000001e-06
Izy : -1.2030000000000001e-07
Mass : 0.13754561600000001
Expand All @@ -24,5 +24,14 @@ OriginX : 0
OriginZ : 0
JoggleFormula :
ProductID : SHEET METAL F3D

ProductName : SHEET METAL F3D
Property for [0:1:1:2]:
ProductID : SOLID
ProductName : SOLID
Property for [0:1:1:3]:
ProductID : COMPOUND
ProductName : COMPOUND
Property for [0:1:1:4]:
ProductID : COMPOUND
ProductName : COMPOUND
}
Loading
Loading