17 #include <QStringList>
25 QStringList{
"poly"},
"poly",
26 QStringList{
"Salome Hydro polylines (*.poly)"},
27 QStringList{
"Salome Hydro polylines (*.poly)"},
32 bool& exclusive)
const {
47 std::vector<ccPolyline*> candidates;
50 candidates.push_back(
static_cast<ccPolyline*
>(entity));
58 }
catch (
const std::bad_alloc&) {
66 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
69 QTextStream outFile(&file);
70 const int c_precision = 12;
75 for (
size_t i = 0; i < candidates.size(); ++i) {
77 unsigned vertCount = poly ? poly->
size() : 0;
80 CVLog::Warning(QString(
"[Salome Hydro] Polyline '%1' does not have "
83 : QStringLiteral(
"unnamed")));
90 for (
unsigned j = 0; j < vertCount; ++j) {
95 outFile << QString::number(Pg.
x,
'E', c_precision) <<
" ";
96 outFile << QString::number(Pg.
y,
'E', c_precision) <<
" ";
97 outFile << QString::number(Pg.
z,
'E', c_precision)
114 if (!file.open(QFile::ReadOnly)) {
117 QTextStream stream(&file);
121 bool preserveCoordinateShift =
true;
122 bool firstPoint =
true;
127 QString currentLine = stream.readLine().trimmed();
128 if (currentLine.isNull() || currentLine.isEmpty()) {
130 if (currentVertices) {
131 if (currentVertices->
size() < 2) {
132 delete currentVertices;
133 currentVertices =
nullptr;
135 "[Salome Hydro] An invalid polyline (single "
136 "vertex) will be ignored");
143 QString(QString(
"Polyline #%1").arg(++index)));
155 currentVertices =
nullptr;
159 if (currentLine.isNull()) {
164 if (!currentVertices) {
166 if (!firstPoint && preserveCoordinateShift) {
173 if (parts.size() == 3) {
175 CCVector3d P(parts[0].toDouble(), parts[1].toDouble(),
176 parts[2].toDouble());
182 if (preserveCoordinateShift) {
186 "[Salome Hydro] Polylines will be recentered! "
187 "Translation: (%.2f ; %.2f ; %.2f)",
188 Pshift.
x, Pshift.
y, Pshift.
z);
194 if (currentVertices->
size() == currentVertices->
capacity()) {
195 if (!currentVertices->
reserve(currentVertices->
size() +
197 delete currentVertices;
206 "[Salome Hydro] Malformed file: 3 values per line "
214 delete currentVertices;
215 currentVertices =
nullptr;
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
CC_FILE_ERROR
Typical I/O filter errors.
@ CC_FERR_NOT_ENOUGH_MEMORY
QStringList qtCompatSplitRegex(const QString &str, const QString &pattern, Qt::SplitBehavior behavior=Qt::KeepEmptyParts)
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static constexpr float DEFAULT_PRIORITY
static bool HandleGlobalShift(const CCVector3d &P, CCVector3d &Pshift, bool &preserveCoordinateShift, LoadParameters &loadParameters, bool useInputCoordinatesShiftIfPossible=false)
Shortcut to the ecvGlobalShiftManager mechanism specific for files.
virtual CC_FILE_ERROR loadFile(const QString &filename, ccHObject &container, LoadParameters ¶meters) override
Loads one or more entities from a file.
virtual CC_FILE_ERROR saveToFile(ccHObject *entity, const QString &filename, const SaveParameters ¶meters) override
Saves an entity (or a group of) to a file.
virtual bool canSave(CV_CLASS_ENUM type, bool &multiple, bool &exclusive) const override
Returns whether this I/O filter can save the specified type of entity.
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Hierarchical CLOUDVIEWER Object.
unsigned getChildrenNumber() const
Returns the number of children.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
ccHObject * getChild(unsigned childPos) const
Returns the ith child.
virtual QString getName() const
Returns object name.
bool isA(CV_CLASS_ENUM type) const
virtual void setName(const QString &name)
Sets object name.
virtual void setEnabled(bool state)
Sets the "enabled" property.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
void shrinkToFit()
Removes unused capacity.
void set2DMode(bool state)
Defines if the polyline is considered as 2D or 3D.
CCVector3d toGlobal3d(const Vector3Tpl< T > &Plocal) const
Returns the point back-projected into the original coordinates system.
virtual void setGlobalShift(double x, double y, double z)
Sets shift applied to original coordinates (information storage only)
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
unsigned size() const override
unsigned capacity() const
Returns cloud capacity (i.e. reserved size)
virtual bool addPointIndex(unsigned globalIndex)
Point global index insertion mechanism.
unsigned size() const override
Returns the number of points.
virtual bool reserve(unsigned n)
Reserves some memory for hosting the point references.
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
constexpr Qt::SplitBehavior SkipEmptyParts
QTextStream & endl(QTextStream &stream)
Generic loading parameters.
Generic saving parameters.