Remove FileVersion from RestoreDocFile, convert point data back to floats

This commit is contained in:
wmayer 2013-03-29 15:23:51 +01:00
parent 15573eea04
commit b24f0efbc1
43 changed files with 896 additions and 141 deletions

View File

@ -327,7 +327,7 @@ void PropertyFileIncluded::SaveDocFile (Base::Writer &writer) const
}
}
void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
{
Base::ofstream to(Base::FileInfo(_cValue.c_str()));
if (!to)

View File

@ -91,7 +91,7 @@ public:
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader, const int FileVersion);
virtual void RestoreDocFile(Base::Reader &reader);
virtual Property *Copy(void) const;
virtual void Paste(const Property &from);

View File

@ -301,14 +301,23 @@ void PropertyVectorList::SaveDocFile (Base::Writer &writer) const
}
}
void PropertyVectorList::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyVectorList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;
str >> uCt;
std::vector<Base::Vector3d> values(uCt);
for (std::vector<Base::Vector3d>::iterator it = values.begin(); it != values.end(); ++it) {
str >> it->x >> it->y >> it->z;
if (reader.getFileVersion() > 0) {
for (std::vector<Base::Vector3d>::iterator it = values.begin(); it != values.end(); ++it) {
str >> it->x >> it->y >> it->z;
}
}
else {
float x,y,z;
for (std::vector<Base::Vector3d>::iterator it = values.begin(); it != values.end(); ++it) {
str >> x >> y >> z;
it->Set(x, y, z);
}
}
setValues(values);
}

View File

@ -147,7 +147,7 @@ public:
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader, const int FileVersion);
virtual void RestoreDocFile(Base::Reader &reader);
virtual Property *Copy(void) const;
virtual void Paste(const Property &from);

View File

@ -372,7 +372,7 @@ void PropertyPythonObject::SaveDocFile (Base::Writer &writer) const
writer.Stream().put(*it);
}
void PropertyPythonObject::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyPythonObject::RestoreDocFile(Base::Reader &reader)
{
aboutToSetValue();
std::string buffer;

View File

@ -63,7 +63,7 @@ public:
/** Use Python's pickle module to restore the object */
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader, const int FileVersion);
virtual void RestoreDocFile(Base::Reader &reader);
virtual unsigned int getMemSize (void) const;
virtual Property *Copy(void) const;

View File

@ -1127,16 +1127,19 @@ void PropertyFloatList::SaveDocFile (Base::Writer &writer) const
}
}
void PropertyFloatList::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyFloatList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;
str >> uCt;
std::vector<double> values(uCt);
for (std::vector<double>::iterator it = values.begin(); it != values.end(); ++it) {
if (FileVersion > 0) {
if (reader.getFileVersion() > 0) {
for (std::vector<double>::iterator it = values.begin(); it != values.end(); ++it) {
str >> *it;
} else {
}
}
else {
for (std::vector<double>::iterator it = values.begin(); it != values.end(); ++it) {
float val;
str >> val;
(*it) = val;
@ -2090,7 +2093,7 @@ void PropertyColorList::SaveDocFile (Base::Writer &writer) const
}
}
void PropertyColorList::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyColorList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;

View File

@ -537,7 +537,7 @@ public:
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader, const int FileVersion);
virtual void RestoreDocFile(Base::Reader &reader);
virtual Property *Copy(void) const;
virtual void Paste(const Property &from);
@ -830,7 +830,7 @@ public:
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader, const int FileVersion);
virtual void RestoreDocFile(Base::Reader &reader);
virtual Property *Copy(void) const;
virtual void Paste(const Property &from);

View File

@ -65,6 +65,6 @@ void Persistence::SaveDocFile (Writer &/*writer*/) const
{
}
void Persistence::RestoreDocFile(Reader &/*reader*/, const int FileVersion)
void Persistence::RestoreDocFile(Reader &/*reader*/)
{
}

View File

@ -33,7 +33,7 @@
namespace Base
{
typedef std::istream Reader;
class Reader;
class Writer;
class XMLReader;
@ -145,7 +145,7 @@ public:
* \endcode
* @see Base::Reader,Base::XMLReader
*/
virtual void RestoreDocFile(Reader &/*reader*/, const int FileVersion);
virtual void RestoreDocFile(Reader &/*reader*/);
};
} //namespace Base

View File

@ -60,7 +60,7 @@ using namespace std;
// ---------------------------------------------------------------------------
Base::XMLReader::XMLReader(const char* FileName, std::istream& str)
: DocumentSchema(0), Level(0), _File(FileName)
: DocumentSchema(0), ProgramVersion(""), FileVersion(0), Level(0), _File(FileName)
{
#ifdef _MSC_VER
str.imbue(std::locale::empty());
@ -304,7 +304,7 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const
// no file name for the current entry in the zip was registered.
if (jt != FileList.end()) {
try {
jt->Object->RestoreDocFile(zipstream, FileVersion);
jt->Object->RestoreDocFile(Base::Reader(zipstream, FileVersion));
}
catch(...) {
// For any exception we just continue with the next file.
@ -472,3 +472,21 @@ void Base::XMLReader::warning(const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseExcep
void Base::XMLReader::resetErrors()
{
}
// ----------------------------------------------------------
Base::Reader::Reader(std::istream& str, int version)
: std::istream(str.rdbuf()), _str(str), fileVersion(version)
{
}
int Base::Reader::getFileVersion() const
{
return fileVersion;
}
std::istream& Base::Reader::getStream()
{
return this->_str;
}

View File

@ -232,6 +232,18 @@ protected:
std::vector<std::string> FileNames;
};
class BaseExport Reader : public std::istream
{
public:
Reader(std::istream&, int version);
int getFileVersion() const;
std::istream& getStream();
private:
std::istream& _str;
int fileVersion;
};
}

View File

@ -674,10 +674,11 @@ void Document::Restore(Base::XMLReader &reader)
/**
* Restores the properties of the view providers.
*/
void Document::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void Document::RestoreDocFile(Base::Reader &reader)
{
// We must create an XML parser to read from the input stream
Base::XMLReader xmlReader("GuiDocument.xml", reader);
xmlReader.FileVersion = reader.getFileVersion();
int i,Cnt;
@ -722,7 +723,7 @@ void Document::RestoreDocFile(Base::Reader &reader, const int FileVersion)
// In the file GuiDocument.xml new data files might be added
if (!xmlReader.getFilenames().empty())
xmlReader.readFiles(static_cast<zipios::ZipInputStream&>(reader));
xmlReader.readFiles(static_cast<zipios::ZipInputStream&>(reader.getStream()));
// reset modified flag
setModified(false);

View File

@ -119,7 +119,7 @@ public:
/// This method is used to save large amounts of data to a binary file.
virtual void SaveDocFile (Base::Writer &writer) const;
/// This method is used to restore large amounts of data from a binary file.
virtual void RestoreDocFile(Base::Reader &reader, const int FileVersion);
virtual void RestoreDocFile(Base::Reader &reader);
void exportObjects(const std::vector<App::DocumentObject*>&, Base::Writer&);
void importObjects(const std::vector<App::DocumentObject*>&, Base::Reader&);
//@}

View File

@ -160,7 +160,7 @@ void MergeDocuments::SaveDocFile (Base::Writer & w) const
document->exportObjects(objects, w);
}
void MergeDocuments::RestoreDocFile(Base::Reader & reader, const int FileVersion)
void MergeDocuments::RestoreDocFile(Base::Reader & reader)
{
std::vector<App::DocumentObject*> obj = objects;
// We must create an XML parser to read from the input stream
@ -199,5 +199,5 @@ void MergeDocuments::RestoreDocFile(Base::Reader & reader, const int FileVersion
// In the file GuiDocument.xml new data files might be added
if (!xmlReader.getFilenames().empty())
xmlReader.readFiles(static_cast<zipios::ZipInputStream&>(reader));
xmlReader.readFiles(static_cast<zipios::ZipInputStream&>(reader.getStream()));
}

View File

@ -49,7 +49,7 @@ public:
void Save (Base::Writer & w) const;
void Restore(Base::XMLReader &r);
void SaveDocFile (Base::Writer & w) const;
void RestoreDocFile(Base::Reader & r, const int FileVersion);
void RestoreDocFile(Base::Reader & r);
private:
zipios::ZipInputStream* stream;

View File

@ -110,6 +110,6 @@ void Thumbnail::SaveDocFile (Base::Writer &writer) const
writer.Stream().write(ba.constData(), ba.length());
}
void Thumbnail::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void Thumbnail::RestoreDocFile(Base::Reader &reader)
{
}

View File

@ -50,7 +50,7 @@ public:
/// This method is used to save large amounts of data to a binary file.
void SaveDocFile (Base::Writer &writer) const;
/// This method is used to restore large amounts of data from a binary file.
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
//@}
private:

View File

@ -744,7 +744,7 @@ void FemMesh::SaveDocFile (Base::Writer &writer) const
fi.deleteFile();
}
void FemMesh::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void FemMesh::RestoreDocFile(Base::Reader &reader)
{
// create a temporary file and copy the content from the zip stream
Base::FileInfo fi(Base::FileInfo::getTempFileName().c_str());

View File

@ -65,7 +65,7 @@ public:
virtual void Save (Base::Writer &/*writer*/) const;
virtual void Restore(Base::XMLReader &/*reader*/);
void SaveDocFile (Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
/** @name Subelement management */
//@{

View File

@ -162,9 +162,9 @@ void PropertyFemMesh::SaveDocFile (Base::Writer &writer) const
_FemMesh->SaveDocFile(writer);
}
void PropertyFemMesh::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyFemMesh::RestoreDocFile(Base::Reader &reader)
{
aboutToSetValue();
_FemMesh->RestoreDocFile(reader, FileVersion);
_FemMesh->RestoreDocFile(reader);
hasSetValue();
}

View File

@ -77,7 +77,7 @@ public:
void Save (Base::Writer &writer) const;
void Restore(Base::XMLReader &reader);
void SaveDocFile (Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
App::Property *Copy(void) const;
void Paste(const App::Property &from);

View File

@ -47,8 +47,9 @@ void InspectionExport initInspection() {
(void) Py_InitModule3("Inspection", Inspection_methods, module_Inspection_doc); /* mod name, table ptr */
Base::Console().Log("Loading Inspection module... done\n");
Inspection::Feature ::init();
Inspection::Group ::init();
Inspection::PropertyDistanceList ::init();
Inspection::Feature ::init();
Inspection::Group ::init();
}
} // extern "C"

View File

@ -442,6 +442,151 @@ float InspectNominalShape::getDistance(const Base::Vector3f& point)
// ----------------------------------------------------------------
TYPESYSTEM_SOURCE(Inspection::PropertyDistanceList, App::PropertyLists);
PropertyDistanceList::PropertyDistanceList()
{
}
PropertyDistanceList::~PropertyDistanceList()
{
}
void PropertyDistanceList::setSize(int newSize)
{
_lValueList.resize(newSize);
}
int PropertyDistanceList::getSize(void) const
{
return static_cast<int>(_lValueList.size());
}
void PropertyDistanceList::setValue(float lValue)
{
aboutToSetValue();
_lValueList.resize(1);
_lValueList[0]=lValue;
hasSetValue();
}
void PropertyDistanceList::setValues(const std::vector<float>& values)
{
aboutToSetValue();
_lValueList = values;
hasSetValue();
}
PyObject *PropertyDistanceList::getPyObject(void)
{
PyObject* list = PyList_New(getSize());
for (int i = 0;i<getSize(); i++)
PyList_SetItem( list, i, PyFloat_FromDouble(_lValueList[i]));
return list;
}
void PropertyDistanceList::setPyObject(PyObject *value)
{
if (PyList_Check(value)) {
Py_ssize_t nSize = PyList_Size(value);
std::vector<float> values;
values.resize(nSize);
for (Py_ssize_t i=0; i<nSize;++i) {
PyObject* item = PyList_GetItem(value, i);
if (!PyFloat_Check(item)) {
std::string error = std::string("type in list must be float, not ");
error += item->ob_type->tp_name;
throw Py::TypeError(error);
}
values[i] = (float)PyFloat_AsDouble(item);
}
setValues(values);
}
else if (PyFloat_Check(value)) {
setValue((float)PyFloat_AsDouble(value));
}
else {
std::string error = std::string("type must be float or list of float, not ");
error += value->ob_type->tp_name;
throw Py::TypeError(error);
}
}
void PropertyDistanceList::Save (Base::Writer &writer) const
{
if (writer.isForceXML()) {
writer.Stream() << writer.ind() << "<FloatList count=\"" << getSize() <<"\">" << endl;
writer.incInd();
for(int i = 0;i<getSize(); i++)
writer.Stream() << writer.ind() << "<F v=\"" << _lValueList[i] <<"\"/>" << endl; ;
writer.decInd();
writer.Stream() << writer.ind() <<"</FloatList>" << endl ;
}
else {
writer.Stream() << writer.ind() << "<FloatList file=\"" <<
writer.addFile(getName(), this) << "\"/>" << std::endl;
}
}
void PropertyDistanceList::Restore(Base::XMLReader &reader)
{
reader.readElement("FloatList");
std::string file (reader.getAttribute("file") );
if (!file.empty()) {
// initate a file read
reader.addFile(file.c_str(),this);
}
}
void PropertyDistanceList::SaveDocFile (Base::Writer &writer) const
{
Base::OutputStream str(writer.Stream());
uint32_t uCt = (uint32_t)getSize();
str << uCt;
for (std::vector<float>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) {
str << *it;
}
}
void PropertyDistanceList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;
str >> uCt;
std::vector<float> values(uCt);
for (std::vector<float>::iterator it = values.begin(); it != values.end(); ++it) {
str >> *it;
}
setValues(values);
}
App::Property *PropertyDistanceList::Copy(void) const
{
PropertyDistanceList *p= new PropertyDistanceList();
p->_lValueList = _lValueList;
return p;
}
void PropertyDistanceList::Paste(const App::Property &from)
{
aboutToSetValue();
_lValueList = dynamic_cast<const PropertyDistanceList&>(from)._lValueList;
hasSetValue();
}
unsigned int PropertyDistanceList::getMemSize (void) const
{
return static_cast<unsigned int>(_lValueList.size() * sizeof(float));
}
// ----------------------------------------------------------------
// helper class to use Qt's concurrent framework
struct DistanceInspection
{
@ -575,7 +720,7 @@ App::DocumentObjectExecReturn* Feature::execute(void)
str << "Inspecting " << this->Label.getValue() << "...";
Base::SequencerLauncher seq(str.str().c_str(), count);
std::vector<double> vals(count);
std::vector<float> vals(count);
for (unsigned long index = 0; index < count; index++) {
Base::Vector3f pnt = actual->getPoint(index);
@ -599,7 +744,7 @@ App::DocumentObjectExecReturn* Feature::execute(void)
float fRMS = 0;
int countRMS = 0;
for (std::vector<double>::iterator it = vals.begin(); it != vals.end(); ++it) {
for (std::vector<float>::iterator it = vals.begin(); it != vals.end(); ++it) {
if (fabs(*it) < FLT_MAX) {
fRMS += (*it) * (*it);
countRMS++;

View File

@ -153,6 +153,56 @@ private:
const TopoDS_Shape& _rShape;
};
class InspectionExport PropertyDistanceList: public App::PropertyLists
{
TYPESYSTEM_HEADER();
public:
/**
* A constructor.
* A more elaborate description of the constructor.
*/
PropertyDistanceList();
/**
* A destructor.
* A more elaborate description of the destructor.
*/
virtual ~PropertyDistanceList();
virtual void setSize(int newSize);
virtual int getSize(void) const;
/** Sets the property
*/
void setValue(float);
/// index operator
float operator[] (const int idx) const {return _lValueList.operator[] (idx);}
void set1Value (const int idx, float value){_lValueList.operator[] (idx) = value;}
void setValues (const std::vector<float>& values);
const std::vector<float> &getValues(void) const{return _lValueList;}
virtual PyObject *getPyObject(void);
virtual void setPyObject(PyObject *);
virtual void Save (Base::Writer &writer) const;
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader);
virtual Property *Copy(void) const;
virtual void Paste(const Property &from);
virtual unsigned int getMemSize (void) const;
private:
std::vector<float> _lValueList;
};
// ----------------------------------------------------------------
/** The inspection feature.
@ -173,7 +223,7 @@ public:
App::PropertyFloat Thickness;
App::PropertyLink Actual;
App::PropertyLinkList Nominals;
App::PropertyFloatList Distances;
PropertyDistanceList Distances;
//@}
/** @name Actions */

View File

@ -256,7 +256,7 @@ void ViewProviderInspection::updateData(const App::Property* prop)
}
}
}
else if (prop->getTypeId() == App::PropertyFloatList::getClassTypeId()) {
else if (prop->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) {
// force an update of the Inventor data nodes
if (this->pcObject) {
App::Property* link = this->pcObject->getPropertyByName("Actual");
@ -286,14 +286,14 @@ void ViewProviderInspection::setDistances()
SoDebugError::post("ViewProviderInspection::setDistances", "Unknown property 'Distances'");
return;
}
if (pDistances->getTypeId() != App::PropertyFloatList::getClassTypeId()) {
if (pDistances->getTypeId() != Inspection::PropertyDistanceList::getClassTypeId()) {
SoDebugError::post("ViewProviderInspection::setDistances",
"Property 'Distances' has type %s (App::PropertyFloatList was expected)", pDistances->getTypeId().getName());
"Property 'Distances' has type %s (Inspection::PropertyDistanceList was expected)", pDistances->getTypeId().getName());
return;
}
// distance values
const std::vector<double>& fValues = ((App::PropertyFloatList*)pDistances)->getValues();
const std::vector<float>& fValues = static_cast<Inspection::PropertyDistanceList*>(pDistances)->getValues();
if ((int)fValues.size() != this->pcCoords->point.getNum()) {
pcMatBinding->value = SoMaterialBinding::OVERALL;
return;
@ -308,7 +308,7 @@ void ViewProviderInspection::setDistances()
float * tran = pcColorMat->transparency.startEditing();
unsigned long j=0;
for (std::vector<double>::const_iterator jt = fValues.begin(); jt != fValues.end(); ++jt, j++) {
for (std::vector<float>::const_iterator jt = fValues.begin(); jt != fValues.end(); ++jt, j++) {
App::Color col = pcColorBar->getColor(*jt);
cols[j] = SbColor(col.r, col.g, col.b);
if (pcColorBar->isVisible(*jt))
@ -528,8 +528,8 @@ QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const
// get the distances of the three points of the picked facet
const SoFaceDetail * facedetail = static_cast<const SoFaceDetail*>(detail);
App::Property* pDistance = this->pcObject->getPropertyByName("Distances");
if (pDistance && pDistance->getTypeId() == App::PropertyFloatList::getClassTypeId()) {
App::PropertyFloatList* dist = (App::PropertyFloatList*)pDistance;
if (pDistance && pDistance->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) {
Inspection::PropertyDistanceList* dist = static_cast<Inspection::PropertyDistanceList*>(pDistance);
int index1 = facedetail->getPoint(0)->getCoordinateIndex();
int index2 = facedetail->getPoint(1)->getCoordinateIndex();
int index3 = facedetail->getPoint(2)->getCoordinateIndex();
@ -567,8 +567,8 @@ QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const
// get the distance of the picked point
int index = pointdetail->getCoordinateIndex();
App::Property* prop = this->pcObject->getPropertyByName("Distances");
if ( prop && prop->getTypeId() == App::PropertyFloatList::getClassTypeId() ) {
App::PropertyFloatList* dist = (App::PropertyFloatList*)prop;
if (prop && prop->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) {
Inspection::PropertyDistanceList* dist = static_cast<Inspection::PropertyDistanceList*>(prop);
float fVal = (*dist)[index];
info = QObject::tr("Distance: %1").arg(fVal);
}

View File

@ -297,7 +297,7 @@ void MeshObject::Restore(Base::XMLReader &reader)
// this is handled by the property class
}
void MeshObject::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void MeshObject::RestoreDocFile(Base::Reader &reader)
{
load(reader);
}

View File

@ -141,7 +141,7 @@ public:
void Save (Base::Writer &writer) const;
void SaveDocFile (Base::Writer &writer) const;
void Restore(Base::XMLReader &reader);
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
void save(const char* file,MeshCore::MeshIO::Format f=MeshCore::MeshIO::Undefined,
const MeshCore::Material* mat = 0) const;
void save(std::ostream&) const;

View File

@ -31,6 +31,7 @@
#include <Base/Writer.h>
#include <Base/Reader.h>
#include <Base/Stream.h>
#include <Base/VectorPy.h>
#include "Core/MeshKernel.h"
#include "Core/MeshIO.h"
@ -42,10 +43,155 @@
using namespace Mesh;
TYPESYSTEM_SOURCE(Mesh::PropertyNormalList, App::PropertyVectorList);
TYPESYSTEM_SOURCE(Mesh::PropertyNormalList, App::PropertyLists);
TYPESYSTEM_SOURCE(Mesh::PropertyCurvatureList , App::PropertyLists);
TYPESYSTEM_SOURCE(Mesh::PropertyMeshKernel , App::PropertyComplexGeoData);
PropertyNormalList::PropertyNormalList()
{
}
PropertyNormalList::~PropertyNormalList()
{
}
void PropertyNormalList::setSize(int newSize)
{
_lValueList.resize(newSize);
}
int PropertyNormalList::getSize(void) const
{
return static_cast<int>(_lValueList.size());
}
void PropertyNormalList::setValue(const Base::Vector3f& lValue)
{
aboutToSetValue();
_lValueList.resize(1);
_lValueList[0]=lValue;
hasSetValue();
}
void PropertyNormalList::setValue(float x, float y, float z)
{
aboutToSetValue();
_lValueList.resize(1);
_lValueList[0].Set(x,y,z);
hasSetValue();
}
void PropertyNormalList::setValues(const std::vector<Base::Vector3f>& values)
{
aboutToSetValue();
_lValueList = values;
hasSetValue();
}
PyObject *PropertyNormalList::getPyObject(void)
{
PyObject* list = PyList_New(getSize());
for (int i = 0;i<getSize(); i++)
PyList_SetItem(list, i, new Base::VectorPy(_lValueList[i]));
return list;
}
void PropertyNormalList::setPyObject(PyObject *value)
{
if (PyList_Check(value)) {
Py_ssize_t nSize = PyList_Size(value);
std::vector<Base::Vector3f> values;
values.resize(nSize);
for (Py_ssize_t i=0; i<nSize;++i) {
PyObject* item = PyList_GetItem(value, i);
App::PropertyVector val;
val.setPyObject( item );
values[i] = Base::convertTo<Base::Vector3f>(val.getValue());
}
setValues(values);
}
else if (PyObject_TypeCheck(value, &(Base::VectorPy::Type))) {
Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(value);
Base::Vector3d* val = pcObject->getVectorPtr();
setValue(Base::convertTo<Base::Vector3f>(*val));
}
else if (PyTuple_Check(value) && PyTuple_Size(value) == 3) {
App::PropertyVector val;
val.setPyObject( value );
setValue(Base::convertTo<Base::Vector3f>(val.getValue()));
}
else {
std::string error = std::string("type must be 'Vector' or list of 'Vector', not ");
error += value->ob_type->tp_name;
throw Py::TypeError(error);
}
}
void PropertyNormalList::Save (Base::Writer &writer) const
{
if (!writer.isForceXML()) {
writer.Stream() << writer.ind() << "<VectorList file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl;
}
}
void PropertyNormalList::Restore(Base::XMLReader &reader)
{
reader.readElement("VectorList");
std::string file (reader.getAttribute("file") );
if (!file.empty()) {
// initate a file read
reader.addFile(file.c_str(),this);
}
}
void PropertyNormalList::SaveDocFile (Base::Writer &writer) const
{
Base::OutputStream str(writer.Stream());
uint32_t uCt = (uint32_t)getSize();
str << uCt;
for (std::vector<Base::Vector3f>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) {
str << it->x << it->y << it->z;
}
}
void PropertyNormalList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;
str >> uCt;
std::vector<Base::Vector3f> values(uCt);
for (std::vector<Base::Vector3f>::iterator it = values.begin(); it != values.end(); ++it) {
str >> it->x >> it->y >> it->z;
}
setValues(values);
}
App::Property *PropertyNormalList::Copy(void) const
{
PropertyNormalList *p= new PropertyNormalList();
p->_lValueList = _lValueList;
return p;
}
void PropertyNormalList::Paste(const App::Property &from)
{
aboutToSetValue();
_lValueList = dynamic_cast<const PropertyNormalList&>(from)._lValueList;
hasSetValue();
}
unsigned int PropertyNormalList::getMemSize (void) const
{
return static_cast<unsigned int>(_lValueList.size() * sizeof(Base::Vector3f));
}
void PropertyNormalList::transform(const Base::Matrix4D &mat)
{
// A normal vector is only a direction with unit length, so we only need to rotate it
@ -221,7 +367,7 @@ void PropertyCurvatureList::SaveDocFile (Base::Writer &writer) const
}
}
void PropertyCurvatureList::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyCurvatureList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;
@ -478,7 +624,7 @@ void PropertyMeshKernel::SaveDocFile (Base::Writer &writer) const
_meshObject->save(writer.Stream());
}
void PropertyMeshKernel::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyMeshKernel::RestoreDocFile(Base::Reader &reader)
{
aboutToSetValue();
_meshObject->load(reader);

View File

@ -50,18 +50,52 @@ class MeshPy;
* Note: We need an own class for that to distinguish from the base vector list.
* @author Werner Mayer
*/
class MeshExport PropertyNormalList : public App::PropertyVectorList
class MeshExport PropertyNormalList: public App::PropertyLists
{
TYPESYSTEM_HEADER();
public:
PropertyNormalList()
{
PropertyNormalList();
~PropertyNormalList();
virtual void setSize(int newSize);
virtual int getSize(void) const;
void setValue(const Base::Vector3f&);
void setValue(float x, float y, float z);
const Base::Vector3f& operator[] (const int idx) const {
return _lValueList.operator[] (idx);
}
virtual ~PropertyNormalList()
{
void set1Value (const int idx, const Base::Vector3f& value) {
_lValueList.operator[] (idx) = value;
}
void setValues (const std::vector<Base::Vector3f>& values);
const std::vector<Base::Vector3f> &getValues(void) const {
return _lValueList;
}
virtual PyObject *getPyObject(void);
virtual void setPyObject(PyObject *);
virtual void Save (Base::Writer &writer) const;
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader);
virtual App::Property *Copy(void) const;
virtual void Paste(const App::Property &from);
virtual unsigned int getMemSize (void) const;
void transform(const Base::Matrix4D &rclMat);
private:
std::vector<Base::Vector3f> _lValueList;
};
/** Curvature information. */
@ -107,7 +141,7 @@ public:
void Restore(Base::XMLReader &reader);
void SaveDocFile (Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
/** @name Python interface */
//@{
@ -205,7 +239,7 @@ public:
void Restore(Base::XMLReader &reader);
void SaveDocFile (Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
App::Property *Copy(void) const;
void Paste(const App::Property &from);

View File

@ -304,7 +304,7 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
fi.deleteFile();
}
void PropertyPartShape::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyPartShape::RestoreDocFile(Base::Reader &reader)
{
BRep_Builder builder;
@ -397,7 +397,7 @@ void PropertyShapeHistory::SaveDocFile (Base::Writer &writer) const
{
}
void PropertyShapeHistory::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyShapeHistory::RestoreDocFile(Base::Reader &reader)
{
}
@ -505,7 +505,7 @@ void PropertyFilletEdges::SaveDocFile (Base::Writer &writer) const
}
}
void PropertyFilletEdges::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyFilletEdges::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;

View File

@ -87,7 +87,7 @@ public:
void Restore(Base::XMLReader &reader);
void SaveDocFile (Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
App::Property *Copy(void) const;
void Paste(const App::Property &from);
@ -138,7 +138,7 @@ public:
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader, const int FileVersion);
virtual void RestoreDocFile(Base::Reader &reader);
virtual Property *Copy(void) const;
virtual void Paste(const Property &from);
@ -191,7 +191,7 @@ public:
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader, const int FileVersion);
virtual void RestoreDocFile(Base::Reader &reader);
virtual Property *Copy(void) const;
virtual void Paste(const Property &from);

View File

@ -939,7 +939,7 @@ void TopoShape::SaveDocFile (Base::Writer &writer) const
{
}
void TopoShape::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void TopoShape::RestoreDocFile(Base::Reader &reader)
{
}

View File

@ -111,7 +111,7 @@ public:
void Restore(Base::XMLReader &reader);
void SaveDocFile (Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
unsigned int getMemSize (void) const;
//@}

View File

@ -70,8 +70,8 @@ Data::Segment* PointKernel::getSubElement(const char* Type, unsigned long n) con
void PointKernel::transformGeometry(const Base::Matrix4D &rclMat)
{
std::vector<Base::Vector3d>& kernel = getBasicPoints();
for (std::vector<Base::Vector3d>::iterator it = kernel.begin(); it != kernel.end(); ++it)
std::vector<Base::Vector3f>& kernel = getBasicPoints();
for (std::vector<Base::Vector3f>::iterator it = kernel.begin(); it != kernel.end(); ++it)
*it = rclMat * (*it);
}
@ -112,7 +112,7 @@ void PointKernel::SaveDocFile (Base::Writer &writer) const
uint32_t uCt = (uint32_t)size();
str << uCt;
// store the data without transforming it
for (std::vector<Base::Vector3d>::const_iterator it = _Points.begin(); it != _Points.end(); ++it) {
for (std::vector<Base::Vector3f>::const_iterator it = _Points.begin(); it != _Points.end(); ++it) {
str << it->x << it->y << it->z;
}
}
@ -134,22 +134,16 @@ void PointKernel::Restore(Base::XMLReader &reader)
}
}
void PointKernel::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PointKernel::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt = 0;
str >> uCt;
_Points.resize(uCt);
for (unsigned long i=0; i < uCt; i++) {
if (FileVersion > 0) {
double x, y, z;
str >> x >> y >> z;
_Points[i].Set(x,y,z);
} else {
float x, y, z;
str >> x >> y >> z;
_Points[i].Set(x,y,z);
}
float x, y, z;
str >> x >> y >> z;
_Points[i].Set(x,y,z);
}
}
@ -182,7 +176,7 @@ void PointKernel::getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet
// ----------------------------------------------------------------------------
PointKernel::const_point_iterator::const_point_iterator
(const PointKernel* kernel, std::vector<Base::Vector3d>::const_iterator index)
(const PointKernel* kernel, std::vector<Base::Vector3f>::const_iterator index)
: _kernel(kernel), _p_it(index)
{
if(_p_it != kernel->_Points.end())

View File

@ -46,6 +46,8 @@ class PointsExport PointKernel : public Data::ComplexGeoData
TYPESYSTEM_HEADER();
public:
typedef Base::Vector3f value_type;
PointKernel(void)
{
}
@ -73,9 +75,9 @@ public:
inline void setTransform(const Base::Matrix4D& rclTrf){_Mtrx = rclTrf;}
inline Base::Matrix4D getTransform(void) const{return _Mtrx;}
std::vector<Base::Vector3d>& getBasicPoints()
std::vector<value_type>& getBasicPoints()
{ return this->_Points; }
const std::vector<Base::Vector3d>& getBasicPoints() const
const std::vector<value_type>& getBasicPoints() const
{ return this->_Points; }
void getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &Topo,
float Accuracy, uint16_t flags=0) const;
@ -90,7 +92,7 @@ public:
void Save (Base::Writer &writer) const;
void SaveDocFile (Base::Writer &writer) const;
void Restore(Base::XMLReader &reader);
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
void save(const char* file) const;
void save(std::ostream&) const;
void load(const char* file);
@ -99,11 +101,11 @@ public:
private:
Base::Matrix4D _Mtrx;
std::vector<Base::Vector3d> _Points;
std::vector<value_type> _Points;
public:
typedef std::vector<Base::Vector3d>::difference_type difference_type;
typedef std::vector<Base::Vector3d>::size_type size_type;
typedef std::vector<value_type>::difference_type difference_type;
typedef std::vector<value_type>::size_type size_type;
/// number of points stored
size_type size(void) const {return this->_Points.size();}
@ -118,34 +120,35 @@ public:
/// get the points
inline const Base::Vector3d getPoint(const int idx) const {
return transformToOutside3d(_Points[idx]);
return transformToOutside(_Points[idx]);
}
/// set the points
inline void setPoint(const int idx,const Base::Vector3d& point) {
_Points[idx] = transformToInside3d(point);
_Points[idx] = transformToInside(point);
}
/// insert the points
inline void push_back(const Base::Vector3d& point) {
_Points.push_back(transformToInside3d(point));
_Points.push_back(transformToInside(point));
}
class PointsExport const_point_iterator
{
public:
typedef std::vector<Base::Vector3d>::const_iterator iter_type;
typedef Base::Vector3f value_single;
typedef Base::Vector3d value_type;
typedef std::vector<value_single>::const_iterator iter_type;
typedef iter_type::difference_type difference_type;
typedef iter_type::iterator_category iterator_category;
typedef const Base::Vector3d* pointer;
typedef const Base::Vector3d& reference;
typedef Base::Vector3d value_type;
typedef const value_type* pointer;
typedef const value_type& reference;
const_point_iterator(const PointKernel*, std::vector<Base::Vector3d>::const_iterator index);
const_point_iterator(const PointKernel*, std::vector<value_single>::const_iterator index);
const_point_iterator(const const_point_iterator& pi);
//~const_point_iterator();
const_point_iterator& operator=(const const_point_iterator& fi);
const Base::Vector3d& operator*();
const Base::Vector3d* operator->();
const value_type& operator*();
const value_type* operator->();
bool operator==(const const_point_iterator& fi) const;
bool operator!=(const const_point_iterator& fi) const;
const_point_iterator& operator++();
@ -160,8 +163,8 @@ public:
private:
void dereference();
const PointKernel* _kernel;
Base::Vector3d _point;
std::vector<Base::Vector3d>::const_iterator _p_it;
value_type _point;
std::vector<value_single>::const_iterator _p_it;
};
typedef const_point_iterator const_iterator;

View File

@ -64,10 +64,10 @@ void Feature::Restore(Base::XMLReader &reader)
GeoFeature::Restore(reader);
}
void Feature::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void Feature::RestoreDocFile(Base::Reader &reader)
{
// This gets only invoked if a points file has been added from Restore()
Points.RestoreDocFile(reader, FileVersion);
Points.RestoreDocFile(reader);
}
void Feature::onChanged(const App::Property* prop)

View File

@ -60,7 +60,7 @@ public:
/** @name methods overide Feature */
//@{
void Restore(Base::XMLReader &reader);
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
/// recalculate the Feature
virtual App::DocumentObjectExecReturn *execute(void);
/// returns the type name of the ViewProvider

View File

@ -33,6 +33,7 @@
#include <Base/Persistence.h>
#include <Base/Stream.h>
#include <Base/Writer.h>
#include <Base/VectorPy.h>
#include "Points.h"
#include "Properties.h"
@ -42,28 +43,168 @@ using namespace Points;
using namespace std;
TYPESYSTEM_SOURCE(Points::PropertyGreyValue, App::PropertyFloat);
TYPESYSTEM_SOURCE(Points::PropertyGreyValueList, App::PropertyFloatList);
TYPESYSTEM_SOURCE(Points::PropertyNormalList, App::PropertyVectorList);
TYPESYSTEM_SOURCE(Points::PropertyGreyValueList, App::PropertyLists);
TYPESYSTEM_SOURCE(Points::PropertyNormalList, App::PropertyLists);
TYPESYSTEM_SOURCE(Points::PropertyCurvatureList , App::PropertyLists);
PropertyGreyValueList::PropertyGreyValueList()
{
}
PropertyGreyValueList::~PropertyGreyValueList()
{
}
void PropertyGreyValueList::setSize(int newSize)
{
_lValueList.resize(newSize);
}
int PropertyGreyValueList::getSize(void) const
{
return static_cast<int>(_lValueList.size());
}
void PropertyGreyValueList::setValue(float lValue)
{
aboutToSetValue();
_lValueList.resize(1);
_lValueList[0]=lValue;
hasSetValue();
}
void PropertyGreyValueList::setValues(const std::vector<float>& values)
{
aboutToSetValue();
_lValueList = values;
hasSetValue();
}
PyObject *PropertyGreyValueList::getPyObject(void)
{
PyObject* list = PyList_New(getSize());
for (int i = 0;i<getSize(); i++)
PyList_SetItem( list, i, PyFloat_FromDouble(_lValueList[i]));
return list;
}
void PropertyGreyValueList::setPyObject(PyObject *value)
{
if (PyList_Check(value)) {
Py_ssize_t nSize = PyList_Size(value);
std::vector<float> values;
values.resize(nSize);
for (Py_ssize_t i=0; i<nSize;++i) {
PyObject* item = PyList_GetItem(value, i);
if (!PyFloat_Check(item)) {
std::string error = std::string("type in list must be float, not ");
error += item->ob_type->tp_name;
throw Py::TypeError(error);
}
values[i] = (float)PyFloat_AsDouble(item);
}
setValues(values);
}
else if (PyFloat_Check(value)) {
setValue((float)PyFloat_AsDouble(value));
}
else {
std::string error = std::string("type must be float or list of float, not ");
error += value->ob_type->tp_name;
throw Py::TypeError(error);
}
}
void PropertyGreyValueList::Save (Base::Writer &writer) const
{
if (writer.isForceXML()) {
writer.Stream() << writer.ind() << "<FloatList count=\"" << getSize() <<"\">" << endl;
writer.incInd();
for(int i = 0;i<getSize(); i++)
writer.Stream() << writer.ind() << "<F v=\"" << _lValueList[i] <<"\"/>" << endl; ;
writer.decInd();
writer.Stream() << writer.ind() <<"</FloatList>" << endl ;
}
else {
writer.Stream() << writer.ind() << "<FloatList file=\"" <<
writer.addFile(getName(), this) << "\"/>" << std::endl;
}
}
void PropertyGreyValueList::Restore(Base::XMLReader &reader)
{
reader.readElement("FloatList");
string file (reader.getAttribute("file") );
if (!file.empty()) {
// initate a file read
reader.addFile(file.c_str(),this);
}
}
void PropertyGreyValueList::SaveDocFile (Base::Writer &writer) const
{
Base::OutputStream str(writer.Stream());
uint32_t uCt = (uint32_t)getSize();
str << uCt;
for (std::vector<float>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) {
str << *it;
}
}
void PropertyGreyValueList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;
str >> uCt;
std::vector<float> values(uCt);
for (std::vector<float>::iterator it = values.begin(); it != values.end(); ++it) {
str >> *it;
}
setValues(values);
}
App::Property *PropertyGreyValueList::Copy(void) const
{
PropertyGreyValueList *p= new PropertyGreyValueList();
p->_lValueList = _lValueList;
return p;
}
void PropertyGreyValueList::Paste(const App::Property &from)
{
aboutToSetValue();
_lValueList = dynamic_cast<const PropertyGreyValueList&>(from)._lValueList;
hasSetValue();
}
unsigned int PropertyGreyValueList::getMemSize (void) const
{
return static_cast<unsigned int>(_lValueList.size() * sizeof(float));
}
void PropertyGreyValueList::removeIndices( const std::vector<unsigned long>& uIndices )
{
#if 0
// We need a sorted array
std::vector<unsigned long> uSortedInds = uIndices;
std::sort(uSortedInds.begin(), uSortedInds.end());
const std::vector<double>& rValueList = getValues();
const std::vector<float>& rValueList = getValues();
assert( uSortedInds.size() <= rValueList.size() );
if ( uSortedInds.size() > rValueList.size() )
return;
std::vector<double> remainValue;
std::vector<float> remainValue;
remainValue.reserve(rValueList.size() - uSortedInds.size());
std::vector<unsigned long>::iterator pos = uSortedInds.begin();
for ( std::vector<double>::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) {
for ( std::vector<float>::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) {
unsigned long index = it - rValueList.begin();
if (pos == uSortedInds.end())
remainValue.push_back( *it );
@ -74,7 +215,151 @@ void PropertyGreyValueList::removeIndices( const std::vector<unsigned long>& uIn
}
setValues(remainValue);
#endif
}
PropertyNormalList::PropertyNormalList()
{
}
PropertyNormalList::~PropertyNormalList()
{
}
void PropertyNormalList::setSize(int newSize)
{
_lValueList.resize(newSize);
}
int PropertyNormalList::getSize(void) const
{
return static_cast<int>(_lValueList.size());
}
void PropertyNormalList::setValue(const Base::Vector3f& lValue)
{
aboutToSetValue();
_lValueList.resize(1);
_lValueList[0]=lValue;
hasSetValue();
}
void PropertyNormalList::setValue(float x, float y, float z)
{
aboutToSetValue();
_lValueList.resize(1);
_lValueList[0].Set(x,y,z);
hasSetValue();
}
void PropertyNormalList::setValues(const std::vector<Base::Vector3f>& values)
{
aboutToSetValue();
_lValueList = values;
hasSetValue();
}
PyObject *PropertyNormalList::getPyObject(void)
{
PyObject* list = PyList_New(getSize());
for (int i = 0;i<getSize(); i++)
PyList_SetItem(list, i, new Base::VectorPy(_lValueList[i]));
return list;
}
void PropertyNormalList::setPyObject(PyObject *value)
{
if (PyList_Check(value)) {
Py_ssize_t nSize = PyList_Size(value);
std::vector<Base::Vector3f> values;
values.resize(nSize);
for (Py_ssize_t i=0; i<nSize;++i) {
PyObject* item = PyList_GetItem(value, i);
App::PropertyVector val;
val.setPyObject( item );
values[i] = Base::convertTo<Base::Vector3f>(val.getValue());
}
setValues(values);
}
else if (PyObject_TypeCheck(value, &(Base::VectorPy::Type))) {
Base::VectorPy *pcObject = static_cast<Base::VectorPy*>(value);
Base::Vector3d* val = pcObject->getVectorPtr();
setValue(Base::convertTo<Base::Vector3f>(*val));
}
else if (PyTuple_Check(value) && PyTuple_Size(value) == 3) {
App::PropertyVector val;
val.setPyObject( value );
setValue(Base::convertTo<Base::Vector3f>(val.getValue()));
}
else {
std::string error = std::string("type must be 'Vector' or list of 'Vector', not ");
error += value->ob_type->tp_name;
throw Py::TypeError(error);
}
}
void PropertyNormalList::Save (Base::Writer &writer) const
{
if (!writer.isForceXML()) {
writer.Stream() << writer.ind() << "<VectorList file=\"" << writer.addFile(getName(), this) << "\"/>" << std::endl;
}
}
void PropertyNormalList::Restore(Base::XMLReader &reader)
{
reader.readElement("VectorList");
std::string file (reader.getAttribute("file") );
if (!file.empty()) {
// initate a file read
reader.addFile(file.c_str(),this);
}
}
void PropertyNormalList::SaveDocFile (Base::Writer &writer) const
{
Base::OutputStream str(writer.Stream());
uint32_t uCt = (uint32_t)getSize();
str << uCt;
for (std::vector<Base::Vector3f>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) {
str << it->x << it->y << it->z;
}
}
void PropertyNormalList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;
str >> uCt;
std::vector<Base::Vector3f> values(uCt);
for (std::vector<Base::Vector3f>::iterator it = values.begin(); it != values.end(); ++it) {
str >> it->x >> it->y >> it->z;
}
setValues(values);
}
App::Property *PropertyNormalList::Copy(void) const
{
PropertyNormalList *p= new PropertyNormalList();
p->_lValueList = _lValueList;
return p;
}
void PropertyNormalList::Paste(const App::Property &from)
{
aboutToSetValue();
_lValueList = dynamic_cast<const PropertyNormalList&>(from)._lValueList;
hasSetValue();
}
unsigned int PropertyNormalList::getMemSize (void) const
{
return static_cast<unsigned int>(_lValueList.size() * sizeof(Base::Vector3f));
}
void PropertyNormalList::transform(const Base::Matrix4D &mat)
@ -111,17 +396,17 @@ void PropertyNormalList::removeIndices( const std::vector<unsigned long>& uIndic
std::vector<unsigned long> uSortedInds = uIndices;
std::sort(uSortedInds.begin(), uSortedInds.end());
const std::vector<Base::Vector3d>& rValueList = getValues();
const std::vector<Base::Vector3f>& rValueList = getValues();
assert( uSortedInds.size() <= rValueList.size() );
if ( uSortedInds.size() > rValueList.size() )
return;
std::vector<Base::Vector3d> remainValue;
std::vector<Base::Vector3f> remainValue;
remainValue.reserve(rValueList.size() - uSortedInds.size());
std::vector<unsigned long>::iterator pos = uSortedInds.begin();
for ( std::vector<Base::Vector3d>::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) {
for ( std::vector<Base::Vector3f>::const_iterator it = rValueList.begin(); it != rValueList.end(); ++it ) {
unsigned long index = it - rValueList.begin();
if (pos == uSortedInds.end())
remainValue.push_back( *it );
@ -291,7 +576,7 @@ void PropertyCurvatureList::SaveDocFile (Base::Writer &writer) const
}
}
void PropertyCurvatureList::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyCurvatureList::RestoreDocFile(Base::Reader &reader)
{
Base::InputStream str(reader);
uint32_t uCt=0;

View File

@ -55,47 +55,101 @@ public:
}
};
/**
* Own class to distinguish from real float list
*/
class PointsExport PropertyGreyValueList : public App::PropertyFloatList
class PointsExport PropertyGreyValueList: public App::PropertyLists
{
TYPESYSTEM_HEADER();
public:
PropertyGreyValueList()
{
}
virtual ~PropertyGreyValueList()
{
}
PropertyGreyValueList();
virtual ~PropertyGreyValueList();
virtual void setSize(int newSize);
virtual int getSize(void) const;
/** Sets the property
*/
void setValue(float);
/// index operator
float operator[] (const int idx) const {return _lValueList.operator[] (idx);}
void set1Value (const int idx, float value){_lValueList.operator[] (idx) = value;}
void setValues (const std::vector<float>& values);
const std::vector<float> &getValues(void) const{return _lValueList;}
virtual PyObject *getPyObject(void);
virtual void setPyObject(PyObject *);
virtual void Save (Base::Writer &writer) const;
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader);
virtual App::Property *Copy(void) const;
virtual void Paste(const App::Property &from);
virtual unsigned int getMemSize (void) const;
/** @name Modify */
//@{
void removeIndices( const std::vector<unsigned long>& );
//@}
private:
std::vector<float> _lValueList;
};
/**
* Own class to distinguish from real vector list
*/
class PointsExport PropertyNormalList : public App::PropertyVectorList
class PointsExport PropertyNormalList: public App::PropertyLists
{
TYPESYSTEM_HEADER();
public:
PropertyNormalList()
{
PropertyNormalList();
~PropertyNormalList();
virtual void setSize(int newSize);
virtual int getSize(void) const;
void setValue(const Base::Vector3f&);
void setValue(float x, float y, float z);
const Base::Vector3f& operator[] (const int idx) const {
return _lValueList.operator[] (idx);
}
virtual ~PropertyNormalList()
{
void set1Value (const int idx, const Base::Vector3f& value) {
_lValueList.operator[] (idx) = value;
}
void setValues (const std::vector<Base::Vector3f>& values);
const std::vector<Base::Vector3f> &getValues(void) const {
return _lValueList;
}
virtual PyObject *getPyObject(void);
virtual void setPyObject(PyObject *);
virtual void Save (Base::Writer &writer) const;
virtual void Restore(Base::XMLReader &reader);
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader);
virtual App::Property *Copy(void) const;
virtual void Paste(const App::Property &from);
virtual unsigned int getMemSize (void) const;
/** @name Modify */
//@{
void transform(const Base::Matrix4D &rclMat);
void removeIndices( const std::vector<unsigned long>& );
//@}
private:
std::vector<Base::Vector3f> _lValueList;
};
/** Curvature information. */
@ -141,7 +195,7 @@ public:
void Restore(Base::XMLReader &reader);
void SaveDocFile (Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
//@}
/** @name Undo/Redo */

View File

@ -134,10 +134,10 @@ void PropertyPointKernel::SaveDocFile (Base::Writer &writer) const
// does nothing
}
void PropertyPointKernel::RestoreDocFile(Base::Reader &reader, const int FileVersion)
void PropertyPointKernel::RestoreDocFile(Base::Reader &reader)
{
aboutToSetValue();
_cPoints->RestoreDocFile(reader, FileVersion);
_cPoints->RestoreDocFile(reader);
hasSetValue();
}

View File

@ -78,7 +78,7 @@ public:
void Save (Base::Writer &writer) const;
void Restore(Base::XMLReader &reader);
void SaveDocFile (Base::Writer &writer) const;
void RestoreDocFile(Base::Reader &reader, const int FileVersion);
void RestoreDocFile(Base::Reader &reader);
//@}
/** @name Modification */

View File

@ -125,14 +125,14 @@ void ViewProviderPoints::setVertexColorMode(App::PropertyColorList* pcProperty)
void ViewProviderPoints::setVertexGreyvalueMode(Points::PropertyGreyValueList* pcProperty)
{
const std::vector<double>& val = pcProperty->getValues();
const std::vector<float>& val = pcProperty->getValues();
unsigned long i=0;
pcColorMat->enableNotify(false);
pcColorMat->diffuseColor.deleteValues(0);
pcColorMat->diffuseColor.setNum(val.size());
for ( std::vector<double>::const_iterator it = val.begin(); it != val.end(); ++it ) {
for ( std::vector<float>::const_iterator it = val.begin(); it != val.end(); ++it ) {
pcColorMat->diffuseColor.set1Value(i++, SbColor(*it, *it, *it));
}
@ -142,14 +142,14 @@ void ViewProviderPoints::setVertexGreyvalueMode(Points::PropertyGreyValueList* p
void ViewProviderPoints::setVertexNormalMode(Points::PropertyNormalList* pcProperty)
{
const std::vector<Base::Vector3d>& val = pcProperty->getValues();
const std::vector<Base::Vector3f>& val = pcProperty->getValues();
unsigned long i=0;
pcPointsNormal->enableNotify(false);
pcPointsNormal->vector.deleteValues(0);
pcPointsNormal->vector.setNum(val.size());
for ( std::vector<Base::Vector3d>::const_iterator it = val.begin(); it != val.end(); ++it ) {
for ( std::vector<Base::Vector3f>::const_iterator it = val.begin(); it != val.end(); ++it ) {
pcPointsNormal->vector.set1Value(i++, it->x, it->y, it->z);
}
@ -469,8 +469,8 @@ void ViewProviderPointsBuilder::createPoints(const App::Property* prop, SoCoordi
// get all points
int idx=0;
const std::vector<Base::Vector3d>& kernel = cPts.getBasicPoints();
for (std::vector<Base::Vector3d>::const_iterator it = kernel.begin(); it != kernel.end(); ++it, idx++) {
const std::vector<Points::PointKernel::value_type>& kernel = cPts.getBasicPoints();
for (std::vector<Points::PointKernel::value_type>::const_iterator it = kernel.begin(); it != kernel.end(); ++it, idx++) {
coords->point.set1Value(idx, (float)it->x, (float)it->y, (float)it->z);
}