Base: refactor InventorBuilder
This commit is contained in:
@@ -245,6 +245,30 @@ void InventorFieldWriter::write(const char* fieldName, const std::vector<T>& fie
|
||||
out.write() << "]\n";
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void InventorFieldWriter::write<int>(const char* fieldName, const std::vector<int>& 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<int>& indices)
|
||||
: indices(indices)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FaceSetItem::write(InventorOutput &out) const
|
||||
{
|
||||
out.write() << "FaceSet {\n";
|
||||
out.increaseIndent();
|
||||
InventorFieldWriter writer;
|
||||
writer.write<int>("numVertices", indices, out);
|
||||
out.decreaseIndent();
|
||||
out.write() << "}";
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
IndexedLineSetItem::IndexedLineSetItem(const std::vector<int>& indices)
|
||||
: indices(indices)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IndexedLineSetItem::write(InventorOutput &out) const
|
||||
{
|
||||
out.write() << "IndexedLineSet {\n";
|
||||
out.increaseIndent();
|
||||
InventorFieldWriter writer;
|
||||
writer.write<int>("coordIndex", indices, out);
|
||||
out.decreaseIndent();
|
||||
out.write() << "}";
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
IndexedFaceSetItem::IndexedFaceSetItem(const std::vector<int>& indices)
|
||||
: indices(indices)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IndexedFaceSetItem::write(InventorOutput &out) const
|
||||
{
|
||||
out.write() << "IndexedFaceSet {\n";
|
||||
out.increaseIndent();
|
||||
InventorFieldWriter writer;
|
||||
writer.write<int>("coordIndex", indices, out);
|
||||
out.decreaseIndent();
|
||||
out.write() << "}";
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void NormalItem::setVector(const std::vector<Base::Vector3f>& 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<float>& uKnots,
|
||||
const std::vector<float>& 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<float>("uKnotVector", uKnotVector, out);
|
||||
writer.write<float>("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)
|
||||
{
|
||||
|
||||
@@ -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<int>&);
|
||||
void write(InventorOutput& out) const override;
|
||||
|
||||
private:
|
||||
std::vector<int> indices;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief The IndexedLineSetItem class supports the SoIndexedLineSet node.
|
||||
*/
|
||||
class BaseExport IndexedLineSetItem : public NodeItem
|
||||
{
|
||||
public:
|
||||
IndexedLineSetItem(const std::vector<int>&);
|
||||
void write(InventorOutput& out) const override;
|
||||
|
||||
private:
|
||||
std::vector<int> indices;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief The IndexedFaceSetItem class supports the SoIndexedFaceSet node.
|
||||
*/
|
||||
class BaseExport IndexedFaceSetItem : public NodeItem
|
||||
{
|
||||
public:
|
||||
IndexedFaceSetItem(const std::vector<int>&);
|
||||
void write(InventorOutput& out) const override;
|
||||
|
||||
private:
|
||||
std::vector<int> 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<float>&, const std::vector<float>&);
|
||||
void write(InventorOutput& out) const override;
|
||||
|
||||
private:
|
||||
int numUControlPoints = 0;
|
||||
int numVControlPoints = 0;
|
||||
std::vector<float> uKnotVector;
|
||||
std::vector<float> 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.
|
||||
|
||||
Reference in New Issue
Block a user