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

@@ -31,6 +31,8 @@ StepData_FreeFormEntity.cxx
StepData_FreeFormEntity.hxx
StepData_GeneralModule.cxx
StepData_GeneralModule.hxx
StepData_GlobalFactors.cxx
StepData_GlobalFactors.hxx
StepData_GlobalNodeOfWriterLib.hxx
StepData_GlobalNodeOfWriterLib_0.cxx
StepData_HArray1OfField.hxx

View File

@@ -0,0 +1,113 @@
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StepData_GlobalFactors.hxx>
// ============================================================================
// Method : Consturctor
// Purpose:
// ============================================================================
StepData_GlobalFactors::StepData_GlobalFactors()
:myLengthFactor(1.), myPlaneAngleFactor(1.),
mySolidAngleFactor(1.), myFactRD(1.),
myFactDR(1.), myCascadeUnit(1.)
{}
// ============================================================================
// Method : Intance
// Purpose:
// ============================================================================
StepData_GlobalFactors& StepData_GlobalFactors::Intance()
{
static StepData_GlobalFactors THE_FACTORS;
return THE_FACTORS;
}
// ============================================================================
// Method : InitializeFactors
// Purpose:
// ============================================================================
void StepData_GlobalFactors::InitializeFactors(
const Standard_Real theLengthFactor,
const Standard_Real thePlaneAngleFactor,
const Standard_Real theSolidAngleFactor)
{
myLengthFactor = theLengthFactor;
myPlaneAngleFactor = thePlaneAngleFactor;
mySolidAngleFactor = theSolidAngleFactor;
myFactRD = 1. / thePlaneAngleFactor;
myFactDR = thePlaneAngleFactor;
}
// ============================================================================
// Method : LengthFactor
// Purpose:
// ============================================================================
Standard_Real StepData_GlobalFactors::LengthFactor()
{
return myLengthFactor;
}
// ============================================================================
// Method : PlaneAngleFactor
// Purpose:
// ============================================================================
Standard_Real StepData_GlobalFactors::PlaneAngleFactor()
{
return myPlaneAngleFactor;
}
// ============================================================================
// Method : SolidAngleFactor
// Purpose:
// ============================================================================
Standard_Real StepData_GlobalFactors::SolidAngleFactor()
{
return mySolidAngleFactor;
}
// ============================================================================
// Method : FactorRadianDegree
// Purpose:
// ============================================================================
Standard_Real StepData_GlobalFactors::FactorRadianDegree()
{
return myFactRD;
}
// ============================================================================
// Method : FactorDegreeRadian
// Purpose:
// ============================================================================
Standard_Real StepData_GlobalFactors::FactorDegreeRadian()
{
return myFactDR;
}
// ============================================================================
// Method : SetCascadeUnit
// Purpose:
// ============================================================================
void StepData_GlobalFactors::SetCascadeUnit(const Standard_Real theUnit)
{
myCascadeUnit = theUnit;
}
// ============================================================================
// Method : CascadeUnit
// Purpose:
// ============================================================================
Standard_Real StepData_GlobalFactors::CascadeUnit()
{
return myCascadeUnit;
}

View File

@@ -0,0 +1,81 @@
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _StepData_GlobalFactors_HeaderFile
#define _StepData_GlobalFactors_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Real.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Integer.hxx>
//! Class for using global units variables
class StepData_GlobalFactors
{
private:
Standard_EXPORT StepData_GlobalFactors();
public:
DEFINE_STANDARD_ALLOC
//! Returns a global static object
Standard_EXPORT static StepData_GlobalFactors& Intance();
//! Initializes the 3 factors for the conversion of units
Standard_EXPORT void InitializeFactors(
const Standard_Real theLengthFactor,
const Standard_Real thePlaneAngleFactor,
const Standard_Real theSolidAngleFactor);
//! Sets length unit for current transfer process
Standard_EXPORT void SetCascadeUnit(const Standard_Real theUnit);
//! Returns length unit for current transfer process (mm by default)
Standard_EXPORT Standard_Real CascadeUnit();
//! Returns transient length factor for scaling of shapes
//! at one stage of transfer process
Standard_EXPORT Standard_Real LengthFactor();
//! Returns transient plane angle factor for conversion of angles
//! at one stage of transfer process
Standard_EXPORT Standard_Real PlaneAngleFactor();
//! Returns transient solid angle factor for conversion of angles
//! at one stage of transfer process
Standard_EXPORT Standard_Real SolidAngleFactor();
//! Returns transient factor radian degree for conversion of angles
//! at one stage of transfer process
Standard_EXPORT Standard_Real FactorRadianDegree();
//! Returns transient factor degree radian for conversion of angles
//! at one stage of transfer process
Standard_EXPORT Standard_Real FactorDegreeRadian();
private:
Standard_Real myLengthFactor;
Standard_Real myPlaneAngleFactor;
Standard_Real mySolidAngleFactor;
Standard_Real myFactRD;
Standard_Real myFactDR;
Standard_Real myCascadeUnit;
};
#endif // _StepData_GlobalFactors_HeaderFile

View File

@@ -25,6 +25,7 @@
#include <Standard_Type.hxx>
#include <StepData.hxx>
#include <StepData_Protocol.hxx>
#include <StepData_GlobalFactors.hxx>
#include <StepData_StepModel.hxx>
#include <StepData_StepWriter.hxx>
#include <TCollection_HAsciiString.hxx>
@@ -34,8 +35,25 @@
IMPLEMENT_STANDARD_RTTIEXT(StepData_StepModel,Interface_InterfaceModel)
// Entete de fichier : liste d entites
StepData_StepModel::StepData_StepModel () :mySourceCodePage((Resource_FormatType)Interface_Static::IVal("read.step.codepage"))
{}
StepData_StepModel::StepData_StepModel () :mySourceCodePage((Resource_FormatType)Interface_Static::IVal("read.step.codepage")),
myReadUnitIsInitialized(Standard_False), myWriteUnit (1.)
{
switch (Interface_Static::IVal("write.step.unit"))
{
case 1: myWriteUnit = 25.4; break;
case 2: myWriteUnit = 1.; break;
case 4: myWriteUnit = 304.8; break;
case 5: myWriteUnit = 1609344.0; break;
case 6: myWriteUnit = 1000.0; break;
case 7: myWriteUnit = 1000000.0; break;
case 8: myWriteUnit = 0.0254; break;
case 9: myWriteUnit = 0.001; break;
case 10: myWriteUnit = 10.0; break;
case 11: myWriteUnit = 0.0000254; break;
default:
GlobalCheck()->AddWarning("Incorrect write.step.unit parameter, use default value");
}
}
Handle(Standard_Transient) StepData_StepModel::Entity
@@ -193,3 +211,40 @@ Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel
label = new TCollection_HAsciiString(text);
return label;
}
//=======================================================================
//function : SetLocalLengthUnit
//purpose :
//=======================================================================
void StepData_StepModel::SetLocalLengthUnit(const Standard_Real theUnit)
{
StepData_GlobalFactors::Intance().SetCascadeUnit(theUnit);
myReadUnitIsInitialized = Standard_True;
}
//=======================================================================
//function : LocalLengthUnit
//purpose :
//=======================================================================
Standard_Real StepData_StepModel::LocalLengthUnit() const
{
return StepData_GlobalFactors::Intance().CascadeUnit();
}
//=======================================================================
//function : SetLocalLengthUnit
//purpose :
//=======================================================================
void StepData_StepModel::SetWriteLengthUnit(const Standard_Real theUnit)
{
myWriteUnit = theUnit;
}
//=======================================================================
//function : LocalLengthUnit
//purpose :
//=======================================================================
Standard_Real StepData_StepModel::WriteLengthUnit() const
{
return myWriteUnit;
}

View File

@@ -105,6 +105,22 @@ public:
//! Return the encoding of STEP file for converting names into UNICODE.
void SetSourceCodePage (Resource_FormatType theCode) { mySourceCodePage = theCode; }
//! Sets local length unit using for transfer process
Standard_EXPORT void SetLocalLengthUnit(const Standard_Real theUnit);
//! Returns local length unit using for transfer process (1 by default)
Standard_EXPORT Standard_Real LocalLengthUnit() const;
//! Sets length unit using for writing process
Standard_EXPORT void SetWriteLengthUnit(const Standard_Real theUnit);
//! Returns length unit using for writing process (1 by default)
Standard_EXPORT Standard_Real WriteLengthUnit() const;
//! Returns the unit initialization flag
//! True - the unit was initialized
//! False - the unit value was not initialized, the default value is used
Standard_Boolean IsInitializedUnit() const { return myReadUnitIsInitialized; }
DEFINE_STANDARD_RTTIEXT(StepData_StepModel,Interface_InterfaceModel)
@@ -119,6 +135,8 @@ private:
Interface_EntityList theheader;
Handle(TColStd_HArray1OfInteger) theidnums;
Resource_FormatType mySourceCodePage;
Standard_Boolean myReadUnitIsInitialized;
Standard_Real myWriteUnit;
};