File size: 11,065 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | // SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef MESH_MESHPROPERTIES_H
#define MESH_MESHPROPERTIES_H
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <Base/Handle.h>
#include <Base/Matrix.h>
#include <Mod/Mesh/App/Core/MeshIO.h>
#include <Mod/Mesh/App/Core/MeshKernel.h>
#include "Mesh.h"
namespace Mesh
{
class MeshPy;
/** The normals property class.
* Note: We need an own class for that to distinguish from the base vector list.
* @author Werner Mayer
*/
class MeshExport PropertyNormalList: public App::PropertyLists
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
PropertyNormalList();
void setSize(int newSize) override;
int getSize() const override;
void setValue(const Base::Vector3f&);
void setValue(float x, float y, float z);
const Base::Vector3f& operator[](const int idx) const
{
return _lValueList[idx];
}
void set1Value(const int idx, const Base::Vector3f& value)
{
_lValueList[idx] = value;
}
void setValues(const std::vector<Base::Vector3f>& values);
const std::vector<Base::Vector3f>& getValues() const
{
return _lValueList;
}
PyObject* getPyObject() override;
void setPyObject(PyObject*) override;
void Save(Base::Writer& writer) const override;
void Restore(Base::XMLReader& reader) override;
void SaveDocFile(Base::Writer& writer) const override;
void RestoreDocFile(Base::Reader& reader) override;
App::Property* Copy() const override;
void Paste(const App::Property& from) override;
unsigned int getMemSize() const override;
void transformGeometry(const Base::Matrix4D& rclMat);
private:
std::vector<Base::Vector3f> _lValueList;
};
/** Curvature information. */
struct MeshExport CurvatureInfo
{
float fMaxCurvature {0.0F};
float fMinCurvature {0.0F};
Base::Vector3f cMaxCurvDir;
Base::Vector3f cMinCurvDir;
};
/** The Curvature property class.
* @author Werner Mayer
*/
class MeshExport PropertyCurvatureList: public App::PropertyLists
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
enum
{
MeanCurvature = 0, /**< Mean curvature */
GaussCurvature = 1, /**< Gaussian curvature */
MaxCurvature = 2, /**< Maximum curvature */
MinCurvature = 3, /**< Minimum curvature */
AbsCurvature = 4 /**< Absolute curvature */
};
public:
PropertyCurvatureList();
void setSize(int newSize) override
{
_lValueList.resize(newSize);
}
int getSize() const override
{
return _lValueList.size();
}
std::vector<float> getCurvature(int tMode) const;
void setValue(const CurvatureInfo&);
void setValues(const std::vector<CurvatureInfo>&);
/// index operator
const CurvatureInfo& operator[](const int idx) const
{
return _lValueList[idx];
}
void set1Value(const int idx, const CurvatureInfo& value)
{
_lValueList[idx] = value;
}
const std::vector<CurvatureInfo>& getValues() const
{
return _lValueList;
}
void transformGeometry(const Base::Matrix4D& rclMat);
void Save(Base::Writer& writer) const override;
void Restore(Base::XMLReader& reader) override;
void SaveDocFile(Base::Writer& writer) const override;
void RestoreDocFile(Base::Reader& reader) override;
/** @name Python interface */
//@{
PyObject* getPyObject() override;
void setPyObject(PyObject* value) override;
//@}
App::Property* Copy() const override;
void Paste(const App::Property& from) override;
unsigned int getMemSize() const override
{
return _lValueList.size() * sizeof(CurvatureInfo);
}
private:
std::vector<CurvatureInfo> _lValueList;
};
/** Mesh material properties
*/
class MeshExport PropertyMaterial: public App::Property
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
PropertyMaterial() = default;
/** Sets the property
*/
void setValue(const MeshCore::Material& value);
void setAmbientColor(const std::vector<Base::Color>& value);
void setDiffuseColor(const std::vector<Base::Color>& value);
void setSpecularColor(const std::vector<Base::Color>& value);
void setEmissiveColor(const std::vector<Base::Color>& value);
void setShininess(const std::vector<float>&);
void setTransparency(const std::vector<float>&);
void setBinding(MeshCore::MeshIO::Binding);
const MeshCore::Material& getValue() const;
const std::vector<Base::Color>& getAmbientColor() const;
const std::vector<Base::Color>& getDiffuseColor() const;
const std::vector<Base::Color>& getSpecularColor() const;
const std::vector<Base::Color>& getEmissiveColor() const;
const std::vector<float>& getShininess() const;
const std::vector<float>& getTransparency() const;
MeshCore::MeshIO::Binding getBinding() const;
PyObject* getPyObject() override;
void setPyObject(PyObject*) override;
void Save(Base::Writer& writer) const override;
void Restore(Base::XMLReader& reader) override;
void SaveDocFile(Base::Writer& writer) const override;
void RestoreDocFile(Base::Reader& reader) override;
const char* getEditorName() const override;
Property* Copy() const override;
void Paste(const Property& from) override;
unsigned int getMemSize() const override;
bool isSame(const Property& other) const override;
private:
MeshCore::Material _material;
};
/** The mesh kernel property class.
* @author Werner Mayer
*/
class MeshExport PropertyMeshKernel: public App::PropertyComplexGeoData
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
PropertyMeshKernel();
~PropertyMeshKernel() override;
PropertyMeshKernel(const PropertyMeshKernel&) = delete;
PropertyMeshKernel(PropertyMeshKernel&&) = delete;
PropertyMeshKernel& operator=(const PropertyMeshKernel&) = delete;
PropertyMeshKernel& operator=(PropertyMeshKernel&&) = delete;
/** @name Getter/setter */
//@{
/** This method references the passed mesh object and takes possession of it,
* it does NOT create a copy.
* The currently referenced mesh object gets de-referenced and possibly deleted
* if its reference counter becomes zero.
* However, the mesh gets saved before if a transaction is open at this time.
* @note Make sure not to reference the internal mesh pointer pf this class in
* client code. This could lead to crashes if not handled properly.
*/
void setValuePtr(MeshObject* m);
/** This method sets the mesh by copying the data. */
void setValue(const MeshObject& m);
/** This method sets the mesh by copying the data. */
void setValue(const MeshCore::MeshKernel& m);
/** Swaps the mesh data structure. */
void swapMesh(MeshObject&);
/** Swaps the mesh data structure. */
void swapMesh(MeshCore::MeshKernel&);
/** Returns a the attached mesh object by reference. It cannot be modified
* from outside.
*/
const MeshObject& getValue() const;
const MeshObject* getValuePtr() const;
unsigned int getMemSize() const override;
//@}
/** @name Getting basic geometric entities */
//@{
const Data::ComplexGeoData* getComplexData() const override;
/** Returns the bounding box around the underlying mesh kernel */
Base::BoundBox3d getBoundingBox() const override;
//@}
/** @name Modification */
//@{
MeshObject* startEditing();
void finishEditing();
/// Transform the real mesh data
void transformGeometry(const Base::Matrix4D& rclMat) override;
void setPointIndices(const std::vector<std::pair<PointIndex, Base::Vector3f>>&);
void setTransform(const Base::Matrix4D& rclTrf) override;
Base::Matrix4D getTransform() const override;
//@}
/** @name Python interface */
//@{
/** Returns a Python wrapper for the referenced mesh object. It does NOT
* create a copy. However, the Python wrapper is marked as \a immutable so
* that the mesh object cannot be modified from outside.
*/
PyObject* getPyObject() override;
/** This method copies the content, hence creates an new mesh object
* to copy the data. The passed argument can be an instance of the Python
* wrapper for the mesh object or simply a list of triangles, i.e. a list
* of lists of three floats.
*/
void setPyObject(PyObject* value) override;
//@}
const char* getEditorName() const override
{
return "MeshGui::PropertyMeshKernelItem";
}
/** @name Save/restore */
//@{
void Save(Base::Writer& writer) const override;
void Restore(Base::XMLReader& reader) override;
void SaveDocFile(Base::Writer& writer) const override;
void RestoreDocFile(Base::Reader& reader) override;
App::Property* Copy() const override;
void Paste(const App::Property& from) override;
//@}
private:
Base::Reference<MeshObject> _meshObject;
MeshPy* meshPyObject {nullptr};
};
} // namespace Mesh
#endif // MESH_MESHPROPERTIES_H
|