Import STEP: read more units (all currently supported by OCCT)

This commit is contained in:
vsr 2015-08-25 17:40:04 +03:00
parent 891fb0379d
commit 18906b1406

View File

@ -66,15 +66,17 @@
#include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
//=============================================================================
/*!
namespace
{
//=============================================================================
/*!
* GetShape()
*/
//=============================================================================
//=============================================================================
TopoDS_Shape GetShape(const Handle(Standard_Transient) &theEnti,
TopoDS_Shape GetShape(const Handle(Standard_Transient) &theEnti,
const Handle(Transfer_TransientProcess) &theTP)
{
{
TopoDS_Shape aResult;
Handle(Transfer_Binder) aBinder = theTP->Find(theEnti);
@ -85,18 +87,18 @@ TopoDS_Shape GetShape(const Handle(Standard_Transient) &theEnti,
aResult = TransferBRep::ShapeResult(aBinder);
return aResult;
}
}
//=============================================================================
/*!
//=============================================================================
/*!
* GetLabel()
*/
//=============================================================================
//=============================================================================
TDF_Label GetLabel(const Handle(Standard_Transient) &theEnti,
TDF_Label GetLabel(const Handle(Standard_Transient) &theEnti,
const TDF_Label &theShapeLabel,
const TopoDS_Shape &aShape)
{
{
TDF_Label aResult;
if (theEnti->IsKind
@ -135,19 +137,19 @@ TDF_Label GetLabel(const Handle(Standard_Transient) &theEnti,
}
return aResult;
}
}
//=============================================================================
/*!
//=============================================================================
/*!
* StoreName()
*/
//=============================================================================
//=============================================================================
void StoreName( const Handle(Standard_Transient) &theEnti,
void StoreName( const Handle(Standard_Transient) &theEnti,
const TopTools_IndexedMapOfShape &theIndices,
const Handle(Transfer_TransientProcess) &theTP,
const TDF_Label &theShapeLabel)
{
{
Handle(TCollection_HAsciiString) aName;
if (theEnti->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)) ||
@ -215,19 +217,19 @@ void StoreName( const Handle(Standard_Transient) &theEnti,
}
}
}
}
}
//=============================================================================
/*!
//=============================================================================
/*!
* StoreMaterial()
*/
//=============================================================================
//=============================================================================
void StoreMaterial( const Handle(Standard_Transient) &theEnti,
void StoreMaterial( const Handle(Standard_Transient) &theEnti,
const TopTools_IndexedMapOfShape &theIndices,
const Handle(Transfer_TransientProcess) &theTP,
const TDF_Label &theShapeLabel )
{
{
// Treat Product Definition Shape only.
Handle(StepRepr_ProductDefinitionShape) aPDS =
Handle(StepRepr_ProductDefinitionShape)::DownCast(theEnti);
@ -310,7 +312,54 @@ void StoreMaterial( const Handle(Standard_Transient) &theEnti,
}
}
}
}
}
TCollection_AsciiString ToNamedUnit( const TCollection_AsciiString& unit )
{
TCollection_AsciiString result = unit;
result.LowerCase();
if ( result == "mil" ) result = "milliinch";
return result;
}
TCollection_AsciiString ToOcctUnit( const TCollection_AsciiString& unit, TCollection_AsciiString& error )
{
TCollection_AsciiString result = "M", u = ToNamedUnit(unit);
u.LowerCase();
if (u == "inch")
result = "INCH";
else if (u == "milliinch")
result = "MIL";
else if (u == "microinch")
result = "UIN";
else if (u == "foot")
result = "FT";
else if (u == "mile")
result = "MI";
else if (u == "metre")
result = "M";
else if (u == "kilometre")
result = "KM";
else if (u == "millimetre")
result = "MM";
else if (u == "centimetre")
result = "CM";
else if (u == "micrometre")
result = "UM";
else if (u.IsEmpty())
result = "M";
else
error = "The file contains not supported units";
// TODO (for other units)
// else
// result = "??"
return result;
}
} // end of namespace
//=======================================================================
//function : GetID
@ -377,21 +426,8 @@ Standard_Integer STEPPlugin_ImportDriver::Execute( TFunction_Logbook& log ) cons
TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
if (anUnitLengthNames.Length() > 0) {
TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
if (aLenUnits == "millimetre")
Interface_Static::SetCVal("xstep.cascade.unit", "MM");
else if (aLenUnits == "centimetre")
Interface_Static::SetCVal("xstep.cascade.unit", "CM");
else if (aLenUnits == "metre" || aLenUnits.IsEmpty())
Interface_Static::SetCVal("xstep.cascade.unit", "M");
else if (aLenUnits == "INCH")
Interface_Static::SetCVal("xstep.cascade.unit", "INCH");
else {
anError = "The file contains not supported units.";
}
// TODO (for other units than mm, cm, m or inch)
// else if (aLenUnits == "")
// Interface_Static::SetCVal("xstep.cascade.unit", "???");
TCollection_AsciiString aLenUnits = ToOcctUnit(anUnitLengthNames.First(), anError);
Interface_Static::SetCVal("xstep.cascade.unit", aLenUnits.ToCString());
}
}
else {
@ -551,7 +587,7 @@ STEPPlugin_ImportDriver::GetValue( const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theParameterName,
TCollection_AsciiString& theError )
{
Handle(TCollection_HAsciiString) aValue;
TCollection_AsciiString aValue;
if (theParameterName != "LEN_UNITS") {
theError = theParameterName + " parameter reading is not supported by STEP plugin";
@ -575,23 +611,8 @@ STEPPlugin_ImportDriver::GetValue( const TCollection_AsciiString& theFileName,
TColStd_SequenceOfAsciiString anUnitAngleNames;
TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
if (anUnitLengthNames.Length() > 0) {
aValue = new TCollection_HAsciiString( anUnitLengthNames.First() );
/*
TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
if (aLenUnits == "millimetre")
aValue = new TCollection_HAsciiString ("MM");
else if (aLenUnits == "centimetre")
aValue = new TCollection_HAsciiString ("CM");
else if (aLenUnits == "metre")
aValue = new TCollection_HAsciiString ("M");
else if (aLenUnits == "INCH")
aValue = new TCollection_HAsciiString ("INCH");
// TODO (for other units than mm, cm, m or inch)
//else if (aLenUnits == "")
// aValue = new TCollection_HAsciiString ("");
*/
}
if (anUnitLengthNames.Length() > 0)
aValue = ToNamedUnit( anUnitLengthNames.First() );
}
else {
theError = theFileName + " reading failed";
@ -601,10 +622,7 @@ STEPPlugin_ImportDriver::GetValue( const TCollection_AsciiString& theFileName,
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
theError = aFail->GetMessageString();
}
if (!aValue.IsNull())
return aValue->String();
else
return TCollection_AsciiString();
return aValue;
}