diff --git a/src/Base/Builder3D.cpp b/src/Base/Builder3D.cpp index 40c2ac8f55..6d0af1d0a4 100644 --- a/src/Base/Builder3D.cpp +++ b/src/Base/Builder3D.cpp @@ -245,6 +245,30 @@ void InventorFieldWriter::write(const char* fieldName, const std::vector& fie out.write() << "]\n"; } } + +template<> +void InventorFieldWriter::write(const char* fieldName, const std::vector& fieldData, InventorOutput& out) const +{ + if (fieldData.empty()) + return; + + out.write() << fieldName << " [\n"; + out.increaseIndent(); + std::size_t last_index{fieldData.size()}; + std::size_t index{}; + for (auto it : fieldData) { + if (index % 8 == 0) + out.write(); + if (index < last_index) + out.stream() << it << ", "; + else + out.stream() << it << " ] \n"; + if (++index % 8 == 0) + out.stream() << '\n'; + } + out.decreaseIndent(); + out.write() << "]\n"; +} } // ----------------------------------------------------------------------------- @@ -580,6 +604,60 @@ void PointSetItem::write(InventorOutput& out) const // ----------------------------------------------------------------------------- +FaceSetItem::FaceSetItem(const std::vector& indices) + : indices(indices) +{ + +} + +void FaceSetItem::write(InventorOutput &out) const +{ + out.write() << "FaceSet {\n"; + out.increaseIndent(); + InventorFieldWriter writer; + writer.write("numVertices", indices, out); + out.decreaseIndent(); + out.write() << "}"; +} + +// ----------------------------------------------------------------------------- + +IndexedLineSetItem::IndexedLineSetItem(const std::vector& indices) + : indices(indices) +{ + +} + +void IndexedLineSetItem::write(InventorOutput &out) const +{ + out.write() << "IndexedLineSet {\n"; + out.increaseIndent(); + InventorFieldWriter writer; + writer.write("coordIndex", indices, out); + out.decreaseIndent(); + out.write() << "}"; +} + +// ----------------------------------------------------------------------------- + +IndexedFaceSetItem::IndexedFaceSetItem(const std::vector& indices) + : indices(indices) +{ + +} + +void IndexedFaceSetItem::write(InventorOutput &out) const +{ + out.write() << "IndexedFaceSet {\n"; + out.increaseIndent(); + InventorFieldWriter writer; + writer.write("coordIndex", indices, out); + out.decreaseIndent(); + out.write() << "}"; +} + +// ----------------------------------------------------------------------------- + void NormalItem::setVector(const std::vector& vec) { vector = vec; @@ -670,6 +748,71 @@ void SphereItem::write(InventorOutput& out) const // ----------------------------------------------------------------------------- +void NurbsSurfaceItem::setControlPoints(int numU, int numV) +{ + numUControlPoints = numU; + numVControlPoints = numV; +} + +void NurbsSurfaceItem::setKnotVector(const std::vector& uKnots, + const std::vector& vKnots) +{ + uKnotVector = uKnots; + vKnotVector = vKnots; +} + +void NurbsSurfaceItem::write(InventorOutput& out) const +{ + out.write() << "NurbsSurface {\n"; + out.write() << " numUControlPoints " << numUControlPoints << '\n'; + out.write() << " numVControlPoints " << numVControlPoints << '\n'; + out.increaseIndent(); + InventorFieldWriter writer; + writer.write("uKnotVector", uKnotVector, out); + writer.write("vKnotVector", vKnotVector, out); + out.decreaseIndent(); + out.write() << "}\n"; +} + +// ----------------------------------------------------------------------------- + +Text2Item::Text2Item(const std::string& string) + : string(string) +{ + +} + +void Text2Item::write(InventorOutput& out) const +{ + out.write() << "Text2 { string \" " << string << "\" " << "}\n"; +} + +// ----------------------------------------------------------------------------- + +TransformItem::TransformItem(const Base::Placement& placement) + : placement(placement) +{ + +} + +void TransformItem::write(InventorOutput& out) const +{ + Base::Vector3d translation = placement.getPosition(); + Base::Vector3d rotationaxis; + double angle{}; + placement.getRotation().getValue(rotationaxis, angle); + + out.write() << "Transform {\n"; + out.write() << " translation " + << translation.x << " " << translation.y << " " << translation.z << '\n'; + out.write() << " rotation " + << rotationaxis.x << " " << rotationaxis.y << " " << rotationaxis.z + << " " << angle << '\n'; + out.write() << "}" << '\n'; +} + +// ----------------------------------------------------------------------------- + InventorBuilder::InventorBuilder(std::ostream& output) : result(output) { diff --git a/src/Base/Builder3D.h b/src/Base/Builder3D.h index 788271528e..68e3d584bc 100644 --- a/src/Base/Builder3D.h +++ b/src/Base/Builder3D.h @@ -378,6 +378,45 @@ public: void write(InventorOutput& out) const override; }; +/*! + * \brief The FaceSetItem class supports the SoFaceSet node. + */ +class BaseExport FaceSetItem : public NodeItem +{ +public: + FaceSetItem(const std::vector&); + void write(InventorOutput& out) const override; + +private: + std::vector indices; +}; + +/*! + * \brief The IndexedLineSetItem class supports the SoIndexedLineSet node. + */ +class BaseExport IndexedLineSetItem : public NodeItem +{ +public: + IndexedLineSetItem(const std::vector&); + void write(InventorOutput& out) const override; + +private: + std::vector indices; +}; + +/*! + * \brief The IndexedFaceSetItem class supports the SoIndexedFaceSet node. + */ +class BaseExport IndexedFaceSetItem : public NodeItem +{ +public: + IndexedFaceSetItem(const std::vector&); + void write(InventorOutput& out) const override; + +private: + std::vector indices; +}; + /*! * \brief The NormalItem class supports the SoNormal node. */ @@ -451,6 +490,49 @@ private: float radius = 2.0F; }; +/*! + * \brief The NurbsSurfaceItem class supports the SoNurbsSurface node. + */ +class BaseExport NurbsSurfaceItem : public NodeItem +{ +public: + void setControlPoints(int numU, int numV); + void setKnotVector(const std::vector&, const std::vector&); + void write(InventorOutput& out) const override; + +private: + int numUControlPoints = 0; + int numVControlPoints = 0; + std::vector uKnotVector; + std::vector vKnotVector; +}; + +/*! + * \brief The Text2Item class supports the SoText2 node. + */ +class BaseExport Text2Item : public NodeItem +{ +public: + Text2Item(const std::string&); + void write(InventorOutput& out) const override; + +private: + std::string string; +}; + +/*! + * \brief The TransformItem class supports the SoTransform node. + */ +class BaseExport TransformItem : public NodeItem +{ +public: + TransformItem(const Base::Placement&); + void write(InventorOutput& out) const override; + +private: + Base::Placement placement; +}; + /** * This class does basically the same as Builder3D except that it writes the data * directly into a given stream without buffering the output data in a string stream.