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,6 +66,8 @@
#include <Standard_Failure.hxx> #include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
namespace
{
//============================================================================= //=============================================================================
/*! /*!
* GetShape() * GetShape()
@ -312,6 +314,53 @@ 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 //function : GetID
//purpose : //purpose :
@ -377,21 +426,8 @@ Standard_Integer STEPPlugin_ImportDriver::Execute( TFunction_Logbook& log ) cons
TColStd_SequenceOfAsciiString anUnitSolidAngleNames; TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames); aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
if (anUnitLengthNames.Length() > 0) { if (anUnitLengthNames.Length() > 0) {
TCollection_AsciiString aLenUnits = anUnitLengthNames.First(); TCollection_AsciiString aLenUnits = ToOcctUnit(anUnitLengthNames.First(), anError);
if (aLenUnits == "millimetre") Interface_Static::SetCVal("xstep.cascade.unit", aLenUnits.ToCString());
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", "???");
} }
} }
else { else {
@ -551,7 +587,7 @@ STEPPlugin_ImportDriver::GetValue( const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theParameterName, const TCollection_AsciiString& theParameterName,
TCollection_AsciiString& theError ) TCollection_AsciiString& theError )
{ {
Handle(TCollection_HAsciiString) aValue; TCollection_AsciiString aValue;
if (theParameterName != "LEN_UNITS") { if (theParameterName != "LEN_UNITS") {
theError = theParameterName + " parameter reading is not supported by STEP plugin"; 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 anUnitAngleNames;
TColStd_SequenceOfAsciiString anUnitSolidAngleNames; TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames); aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
if (anUnitLengthNames.Length() > 0) { if (anUnitLengthNames.Length() > 0)
aValue = new TCollection_HAsciiString( anUnitLengthNames.First() ); aValue = ToNamedUnit( 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 ("");
*/
}
} }
else { else {
theError = theFileName + " reading failed"; theError = theFileName + " reading failed";
@ -601,10 +622,7 @@ STEPPlugin_ImportDriver::GetValue( const TCollection_AsciiString& theFileName,
Handle(Standard_Failure) aFail = Standard_Failure::Caught(); Handle(Standard_Failure) aFail = Standard_Failure::Caught();
theError = aFail->GetMessageString(); theError = aFail->GetMessageString();
} }
if (!aValue.IsNull()) return aValue;
return aValue->String();
else
return TCollection_AsciiString();
} }