1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0031382: Data Exchange - BinXCAF should preserve length unit information

Possibility for adding LengthUnit info to XCAF document using special class XCAFDoc_LenghtUnit and XCAFDoc_LenghtUnitTool is implemented.
Package UnitsMethods is split: geom methods were placed to new file GeomConvert_Units which is in the toolkit TKXSBase, internal step scale factors was placed to StepData.
Updated UnitMethods to convert scale factor to different unit types.
Now, XSAlgo::XSAlgo_AlgoContainer is used to update unit info from static interface values.
New Draw command "XSetLengthUnit" and "XGetLengthUnit" for set or get XDE attribute.
Upgraded tests for STEP, IGES, OBJ, glTF, VRML formats to check area regressing with used unit.
Upgraded tests\de test cases to use any units in the "loop back" algorithms.
This commit is contained in:
dpasukhi
2020-11-10 07:52:30 +03:00
committed by bugmaster
parent 9592ae247b
commit da80ff68f1
106 changed files with 2258 additions and 662 deletions

View File

@@ -47,6 +47,7 @@
#include <StepBasic_SiUnitAndLengthUnit.hxx>
#include <StepBasic_Unit.hxx>
#include <StepBasic_DocumentFile.hxx>
#include <StepData_GlobalFactors.hxx>
#include <STEPCAFControl_Controller.hxx>
#include <STEPCAFControl_DataMapIteratorOfDataMapOfShapePD.hxx>
#include <STEPCAFControl_DataMapOfPDExternFile.hxx>
@@ -535,6 +536,23 @@ static void FillShapesMap(const TopoDS_Shape &S, TopTools_MapOfShape &map)
FillShapesMap(it.Value(), map);
}
//=======================================================================
//function : prepareUnits
//purpose :
//=======================================================================
void STEPCAFControl_Reader::prepareUnits(const Handle(StepData_StepModel)& theModel,
const Handle(TDocStd_Document)& theDoc) const
{
Standard_Real aScaleFactorMM = 1.;
if (!XCAFDoc_DocumentTool::GetLengthUnit(theDoc, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter))
{
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
aScaleFactorMM = UnitsMethods::GetCasCadeLengthUnit();
// Sets length unit to the document
XCAFDoc_DocumentTool::SetLengthUnit(theDoc, aScaleFactorMM, UnitsMethods_LengthUnit_Millimeter);
}
theModel->SetLocalLengthUnit(aScaleFactorMM);
}
//=======================================================================
//function : Transfer
@@ -549,6 +567,8 @@ Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
const Message_ProgressRange& theProgress)
{
reader.ClearShapes();
Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(reader.Model());
prepareUnits(aModel, doc);
Standard_Integer i;
// Read all shapes
@@ -582,14 +602,13 @@ Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
// from the ones representing hybrid models and shape sets
STEPCAFControl_DataMapOfShapePD ShapePDMap;
STEPCAFControl_DataMapOfPDExternFile PDFileMap;
Handle(Interface_InterfaceModel) Model = reader.Model();
const Handle(Transfer_TransientProcess) &TP = reader.WS()->TransferReader()->TransientProcess();
Standard_Integer nb = Model->NbEntities();
Standard_Integer nb = aModel->NbEntities();
Handle(TColStd_HSequenceOfTransient) SeqPDS = new TColStd_HSequenceOfTransient;
for (i = 1; i <= nb; i++) {
Handle(Standard_Transient) enti = Model->Value(i);
Handle(Standard_Transient) enti = aModel->Value(i);
if (enti->IsKind(STANDARD_TYPE(StepRepr_ProductDefinitionShape))) {
// sequence for acceleration ReadMaterials
SeqPDS->Append(enti);
@@ -752,7 +771,6 @@ Standard_Boolean STEPCAFControl_Reader::Transfer (STEPControl_Reader &reader,
// Update assembly compounds
STool->UpdateAssemblies();
return Standard_True;
}
@@ -1983,7 +2001,7 @@ void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
XSAlgo::AlgoContainer()->PrepareForTransfer();
STEPControl_ActorRead anActor;
anActor.PrepareUnits(aDModel, aTP);
Standard_Real aFact = UnitsMethods::LengthFactor();
Standard_Real aFact = StepData_GlobalFactors::Intance().LengthFactor();
// retrieve AnnotationPlane
Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1);
@@ -2090,7 +2108,7 @@ void readConnectionPoints(const Handle(XSControl_TransferReader)& theTR,
XSAlgo::AlgoContainer()->PrepareForTransfer();
STEPControl_ActorRead anActor;
anActor.PrepareUnits(aSDR, aTP);
aFact = UnitsMethods::LengthFactor();
aFact = StepData_GlobalFactors::Intance().LengthFactor();
}
if (theGDT->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
@@ -4032,7 +4050,7 @@ Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSess
STEPControl_ActorRead anActor;
Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
anActor.PrepareUnits(aDMIA->UsedRepresentation(), aTP);
aFact = UnitsMethods::LengthFactor();
aFact = StepData_GlobalFactors::Intance().LengthFactor();
}
// Presentation
@@ -4196,8 +4214,8 @@ Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_Wor
aDensity = aDensity / (anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor()*anUnitCtx.LengthFactor());
// transfer length value for Density from millimeter to santimeter
// in order to result density has dimension gram/(sm*sm*sm)
aDensity = aDensity*1000. / (UnitsMethods::GetCasCadeLengthUnit()
* UnitsMethods::GetCasCadeLengthUnit() * UnitsMethods::GetCasCadeLengthUnit());
const Standard_Real aCascadeUnit = StepData_GlobalFactors::Intance().CascadeUnit();
aDensity = aDensity*1000. / (aCascadeUnit * aCascadeUnit * aCascadeUnit);
}
if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) {
Standard_Real afact = 1.;

View File

@@ -291,6 +291,11 @@ private:
const Handle(TDocStd_Document)& theDoc,
const Handle(XSControl_WorkSession)& theWS);
//! Prepares units for transfer
void prepareUnits(const Handle(StepData_StepModel)& theModel,
const Handle(TDocStd_Document)& theDoc) const;
private:
STEPControl_Reader myReader;
NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;

View File

@@ -228,6 +228,7 @@
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_GeomTolerance.hxx>
#include <XCAFDoc_GraphNode.hxx>
#include <XCAFDoc_LengthUnit.hxx>
#include <XCAFDoc_LayerTool.hxx>
#include <XCAFDoc_Material.hxx>
#include <XCAFDoc_MaterialTool.hxx>
@@ -240,8 +241,11 @@
#include <XCAFPrs_IndexedDataMapOfShapeStyle.hxx>
#include <XCAFPrs_DataMapOfStyleShape.hxx>
#include <XCAFPrs_Style.hxx>
#include <XSAlgo.hxx>
#include <XSAlgo_AlgoContainer.hxx>
#include <XSControl_TransferWriter.hxx>
#include <XSControl_WorkSession.hxx>
#include <UnitsMethods.hxx>
// added by skl 15.01.2004 for D&GT writing
//#include <StepRepr_CompoundItemDefinition.hxx>
@@ -359,6 +363,25 @@ IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filen
return status;
}
//=======================================================================
//function : prepareUnit
//purpose :
//=======================================================================
void STEPCAFControl_Writer::prepareUnit(const TDF_Label& theLabel,
const Handle(StepData_StepModel)& theModel)
{
Handle(XCAFDoc_LengthUnit) aLengthAttr;
if (!theLabel.IsNull() &&
theLabel.Root().FindAttribute(XCAFDoc_LengthUnit::GetID(), aLengthAttr))
{
theModel->SetLocalLengthUnit(aLengthAttr->GetUnitValue() * 1000); // convert to mm
}
else
{
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
theModel->SetLocalLengthUnit(UnitsMethods::GetCasCadeLengthUnit());
}
}
//=======================================================================
//function : Transfer
@@ -516,6 +539,8 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
Handle(STEPCAFControl_ActorWrite) Actor =
Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() );
const Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(writer.WS()->Model());
prepareUnit(labels.First(), aModel); // set local length unit to the model
// translate free top-level shapes of the DECAF document
Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
TDF_LabelSequence sublabels;
@@ -659,10 +684,9 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
WriteMaterials(writer.WS(),sublabels);
// register all MDGPRs in model
const Handle(Interface_InterfaceModel) &Model = writer.WS()->Model();
MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR);
for (; anItr.More(); anItr.Next())
Model->AddWithRefs( anItr.Value() );
aModel->AddWithRefs( anItr.Value() );
}
if ( multi ) { // external refs

View File

@@ -92,6 +92,12 @@ public:
const Standard_CString multi = 0,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Mehod to writing sequence of root assemblies or part of the file specified by use by one label
Standard_EXPORT Standard_Boolean Transfer (const TDF_LabelSequence& L,
const STEPControl_StepModelType mode = STEPControl_AsIs,
const Standard_CString multi = 0,
const Message_ProgressRange& theProgress = Message_ProgressRange());
Standard_EXPORT Standard_Boolean Perform (const Handle(TDocStd_Document)& doc,
const TCollection_AsciiString& filename,
const Message_ProgressRange& theProgress = Message_ProgressRange());
@@ -155,15 +161,7 @@ public:
Standard_EXPORT Standard_Boolean GetMaterialMode() const;
protected:
//! Mehod to writing sequence of root assemblies or part of the file specified by use by one label
Standard_EXPORT Standard_Boolean Transfer (const TDF_LabelSequence& L,
const STEPControl_StepModelType mode = STEPControl_AsIs,
const Standard_CString multi = 0,
const Message_ProgressRange& theProgress = Message_ProgressRange());
//! Transfers labels to a STEP model
//! Returns True if translation is OK
@@ -215,9 +213,14 @@ protected:
//! Write SHUO assigned to specified component, to STEP model
Standard_EXPORT Standard_Boolean WriteSHUOs (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels);
//! Finds length units located in root of label
//! If it exists, initializes local length unit from it
//! Else initializes according to Cascade length unit
Standard_EXPORT void prepareUnit(const TDF_Label& theLabel,
const Handle(StepData_StepModel)& theModel);
private:
Standard_EXPORT Handle(StepRepr_ShapeAspect) WriteShapeAspect(const Handle(XSControl_WorkSession) &WS,
const TDF_Label theLabel, const TopoDS_Shape theShape, Handle(StepRepr_RepresentationContext)& theRC,
Handle(StepAP242_GeometricItemSpecificUsage)& theGISU);
@@ -236,6 +239,7 @@ private:
const TDF_Label theGeomTolL, const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem,
const Handle(StepRepr_RepresentationContext)& theRC);
private:
STEPControl_Writer myWriter;