diff --git a/src/Mod/Fem/App/PropertyPostDataObject.cpp b/src/Mod/Fem/App/PropertyPostDataObject.cpp index 5aa9f7ec6c..89e6130f68 100644 --- a/src/Mod/Fem/App/PropertyPostDataObject.cpp +++ b/src/Mod/Fem/App/PropertyPostDataObject.cpp @@ -67,9 +67,9 @@ PropertyPostDataObject::~PropertyPostDataObject() { } -void PropertyPostDataObject::scaleDataObject(vtkDataObject* dataObject, double s) +void PropertyPostDataObject::scaleDataObject(vtkDataObject *dataObject, double s) { - auto scalePoints = [](vtkPoints* points, double s) { + auto scalePoints = [](vtkPoints *points, double s) { for (vtkIdType i = 0; i < points->GetNumberOfPoints(); i++) { double xyz[3]; points->GetPoint(i, xyz); @@ -80,24 +80,24 @@ void PropertyPostDataObject::scaleDataObject(vtkDataObject* dataObject, double s }; if (dataObject->GetDataObjectType() == VTK_POLY_DATA) { - vtkPolyData* dataSet = vtkPolyData::SafeDownCast(dataObject); + vtkPolyData *dataSet = vtkPolyData::SafeDownCast(dataObject); scalePoints(dataSet->GetPoints(), s); } else if (dataObject->GetDataObjectType() == VTK_STRUCTURED_GRID) { - vtkStructuredGrid* dataSet = vtkStructuredGrid::SafeDownCast(dataObject); + vtkStructuredGrid *dataSet = vtkStructuredGrid::SafeDownCast(dataObject); scalePoints(dataSet->GetPoints(), s); } else if (dataObject->GetDataObjectType() == VTK_UNSTRUCTURED_GRID) { - vtkUnstructuredGrid* dataSet = vtkUnstructuredGrid::SafeDownCast(dataObject); + vtkUnstructuredGrid *dataSet = vtkUnstructuredGrid::SafeDownCast(dataObject); scalePoints(dataSet->GetPoints(), s); } else if (dataObject->GetDataObjectType() == VTK_MULTIBLOCK_DATA_SET) { - vtkMultiBlockDataSet* dataSet = vtkMultiBlockDataSet::SafeDownCast(dataObject); + vtkMultiBlockDataSet *dataSet = vtkMultiBlockDataSet::SafeDownCast(dataObject); for (unsigned int i = 0; i < dataSet->GetNumberOfBlocks(); i++) scaleDataObject(dataSet->GetBlock(i), s); } else if (dataObject->GetDataObjectType() == VTK_MULTIPIECE_DATA_SET) { - vtkMultiPieceDataSet* dataSet = vtkMultiPieceDataSet::SafeDownCast(dataObject); + vtkMultiPieceDataSet *dataSet = vtkMultiPieceDataSet::SafeDownCast(dataObject); for (unsigned int i = 0; i < dataSet->GetNumberOfPieces(); i++) scaleDataObject(dataSet->GetPiece(i), s); } @@ -112,11 +112,11 @@ void PropertyPostDataObject::scale(double s) } } -void PropertyPostDataObject::setValue(const vtkSmartPointer& ds) +void PropertyPostDataObject::setValue(const vtkSmartPointer &ds) { aboutToSetValue(); - if(ds) { + if (ds) { createDataObjectByExternalType(ds); m_dataObject->DeepCopy(ds); } @@ -127,31 +127,33 @@ void PropertyPostDataObject::setValue(const vtkSmartPointer& ds) hasSetValue(); } -const vtkSmartPointer& PropertyPostDataObject::getValue(void)const +const vtkSmartPointer &PropertyPostDataObject::getValue(void) const { return m_dataObject; } -bool PropertyPostDataObject::isComposite() { +bool PropertyPostDataObject::isComposite() +{ return m_dataObject && !m_dataObject->IsA("vtkDataSet"); } -bool PropertyPostDataObject::isDataSet() { +bool PropertyPostDataObject::isDataSet() +{ return m_dataObject && m_dataObject->IsA("vtkDataSet"); } -int PropertyPostDataObject::getDataType() { +int PropertyPostDataObject::getDataType() +{ - if(!m_dataObject) + if (!m_dataObject) return -1; return m_dataObject->GetDataObjectType(); } - PyObject *PropertyPostDataObject::getPyObject(void) { //TODO: fetch the vtk python object from the data set and return it @@ -174,9 +176,10 @@ App::Property *PropertyPostDataObject::Copy(void) const return prop; } -void PropertyPostDataObject::createDataObjectByExternalType(vtkSmartPointer< vtkDataObject > ex) { +void PropertyPostDataObject::createDataObjectByExternalType(vtkSmartPointer ex) +{ - switch( ex->GetDataObjectType() ) { + switch (ex->GetDataObjectType()) { case VTK_POLY_DATA: m_dataObject = vtkSmartPointer::New(); @@ -211,11 +214,11 @@ void PropertyPostDataObject::createDataObjectByExternalType(vtkSmartPointer< vtk void PropertyPostDataObject::Paste(const App::Property &from) { aboutToSetValue(); - m_dataObject = dynamic_cast(from).m_dataObject; + m_dataObject = dynamic_cast(from).m_dataObject; hasSetValue(); } -unsigned int PropertyPostDataObject::getMemSize (void) const +unsigned int PropertyPostDataObject::getMemSize(void) const { return m_dataObject->GetActualMemorySize(); } @@ -234,13 +237,13 @@ void PropertyPostDataObject::getPaths(std::vector & /*pat // << App::ObjectIdentifier::Component::SimpleComponent(App::ObjectIdentifier::String("Volume"))); } -void PropertyPostDataObject::Save (Base::Writer &writer) const +void PropertyPostDataObject::Save(Base::Writer &writer) const { std::string extension; - if(!m_dataObject) + if (!m_dataObject) return; - switch( m_dataObject->GetDataObjectType() ) { + switch (m_dataObject->GetDataObjectType()) { case VTK_POLY_DATA: extension = "vtp"; @@ -255,9 +258,9 @@ void PropertyPostDataObject::Save (Base::Writer &writer) const extension = "vtu"; break; case VTK_UNIFORM_GRID: - extension = "vti"; //image data + extension = "vti";//image data break; - //TODO:multi-datasets use multiple files, this needs to be implemented specially + //TODO:multi-datasets use multiple files, this needs to be implemented specially // case VTK_COMPOSITE_DATA_SET: // prop->m_dataObject = vtkCompositeDataSet::New(); // break; @@ -271,7 +274,7 @@ void PropertyPostDataObject::Save (Base::Writer &writer) const break; }; - if(!writer.isForceXML()) { + if (!writer.isForceXML()) { std::string file = "Data." + extension; writer.Stream() << writer.ind() << "GetPiece() < 0 || dataGrid->GetNumberOfPoints() <= 0)) { std::cerr << "PropertyPostDataObject::SaveDocFile: ignore empty vtkUnstructuredGrid\n"; return; } #endif - if ( xmlWriter->Write() != 1 ) { + if (xmlWriter->Write() != 1) { // Note: Do NOT throw an exception here because if the tmp. file could // not be created we should not abort. // We only print an error message but continue writing the next files to the // stream... - App::PropertyContainer* father = this->getContainer(); + App::PropertyContainer *father = this->getContainer(); if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) { - App::DocumentObject* obj = static_cast(father); + App::DocumentObject *obj = static_cast(father); Base::Console().Error("Dataset of '%s' cannot be written to vtk file '%s'\n", - obj->Label.getValue(),fi.filePath().c_str()); + obj->Label.getValue(), fi.filePath().c_str()); } else { Base::Console().Error("Cannot save vtk file '%s'\n", fi.filePath().c_str()); @@ -340,8 +343,8 @@ void PropertyPostDataObject::SaveDocFile (Base::Writer &writer) const } Base::ifstream file(fi, std::ios::in | std::ios::binary); - if (file){ - std::streambuf* buf = file.rdbuf(); + if (file) { + std::streambuf *buf = file.rdbuf(); writer.Stream() << buf; } @@ -360,7 +363,7 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader) Base::ofstream file(fi, std::ios::out | std::ios::binary); unsigned long ulSize = 0; if (reader) { - std::streambuf* buf = file.rdbuf(); + std::streambuf *buf = file.rdbuf(); reader >> buf; file.flush(); ulSize = buf->pubseekoff(0, std::ios::cur, std::ios::in); @@ -373,7 +376,7 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader) //TODO: read in of composite data structures need to be coded, including replace of "GetOutputAsDataSet()" vtkSmartPointer xmlReader; - if(extension == "vtp") + if (extension == "vtp") xmlReader = vtkSmartPointer::New(); else if (extension == "vts") xmlReader = vtkSmartPointer::New(); @@ -392,11 +395,11 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader) // not be read it's NOT an indication for an invalid input stream 'reader'. // We only print an error message but continue reading the next files from the // stream... - App::PropertyContainer* father = this->getContainer(); + App::PropertyContainer *father = this->getContainer(); if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) { - App::DocumentObject* obj = static_cast(father); + App::DocumentObject *obj = static_cast(father); Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n", - fi.filePath().c_str(),obj->Label.getValue()); + fi.filePath().c_str(), obj->Label.getValue()); } else { Base::Console().Warning("Loaded Dataset file '%s' seems to be empty\n", fi.filePath().c_str());