Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 09:17:40

0001 // Copyright (c) 2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _XCAFDoc_LengthUnit_HeaderFile
0015 #define _XCAFDoc_LengthUnit_HeaderFile
0016 
0017 #include <Standard.hxx>
0018 #include <Standard_Type.hxx>
0019 #include <TDF_DerivedAttribute.hxx>
0020 
0021 #include <TCollection_AsciiString.hxx>
0022 #include <TDF_Attribute.hxx>
0023 #include <Standard_OStream.hxx>
0024 #include <Standard_GUID.hxx>
0025 
0026 class TDF_Label;
0027 class TDF_RelocationTable;
0028 
0029 //! Used to define a Length Unit attribute containing a length unit info
0030 class XCAFDoc_LengthUnit : public TDF_Attribute
0031 {
0032 
0033 public:
0034   //! Returns the GUID of the attribute.
0035   Standard_EXPORT static const Standard_GUID& GetID();
0036 
0037   //! Finds or creates a LengthUnit attribute
0038   //! @param theUnitName - name of the unit: mm, m, cm, km, micron, in, min, nin, ft, stat.mile
0039   //! @param theUnitValue - length scale factor to meter
0040   //! The LengthUnit attribute is returned.
0041   Standard_EXPORT static occ::handle<XCAFDoc_LengthUnit> Set(
0042     const TDF_Label&               theLabel,
0043     const TCollection_AsciiString& theUnitName,
0044     const double                   theUnitValue);
0045 
0046   //! Finds or creates a LengthUnit attribute
0047   //! @param theUnitValue - length scale factor to meter
0048   //! The LengthUnit attribute is returned.
0049   Standard_EXPORT static occ::handle<XCAFDoc_LengthUnit> Set(const TDF_Label& theLabel,
0050                                                              const double     theUnitValue);
0051 
0052   //! Finds, or creates, a LengthUnit attribute with explicit user defined GUID
0053   //! @param theUnitName - name of the unit: mm, m, cm, km, micron, in, min, nin, ft, stat.mile
0054   //! @param theUnitValue - length scale factor to meter
0055   //! The LengthUnit attribute is returned
0056   Standard_EXPORT static occ::handle<XCAFDoc_LengthUnit> Set(
0057     const TDF_Label&               theLabel,
0058     const Standard_GUID&           theGUID,
0059     const TCollection_AsciiString& theUnitName,
0060     const double                   theUnitValue);
0061 
0062   //! Creates a LengthUnit attribute
0063   //! @param theUnitName - name of the unit: mm, m, cm, km, micron, in, min, nin, ft, stat.mile
0064   //! @param theUnitValue - length scale factor to meter
0065   Standard_EXPORT void Set(const TCollection_AsciiString& theUnitName, const double theUnitValue);
0066 
0067   //! Length unit description (could be arbitrary text)
0068   const TCollection_AsciiString& GetUnitName() const { return myUnitName; }
0069 
0070   //! Returns length unit scale factor to meter
0071   double GetUnitValue() const { return myUnitScaleValue; }
0072 
0073   Standard_EXPORT bool IsEmpty() const { return myUnitName.IsEmpty(); }
0074 
0075   Standard_EXPORT XCAFDoc_LengthUnit();
0076 
0077   Standard_EXPORT const Standard_GUID& ID() const override;
0078 
0079   Standard_EXPORT void Restore(const occ::handle<TDF_Attribute>& theWith) override;
0080 
0081   Standard_EXPORT void Paste(const occ::handle<TDF_Attribute>&       theInto,
0082                              const occ::handle<TDF_RelocationTable>& theRT) const override;
0083 
0084   Standard_EXPORT Standard_OStream& Dump(Standard_OStream& anOS) const override;
0085 
0086   //! Dumps the content of me into the stream
0087   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override;
0088 
0089   DEFINE_DERIVED_ATTRIBUTE(XCAFDoc_LengthUnit, TDF_Attribute)
0090 
0091 private:
0092   double                  myUnitScaleValue;
0093   TCollection_AsciiString myUnitName;
0094 };
0095 
0096 #endif // _XCAFDoc_LengthUnit_HeaderFile