From 4e3856acc8f24e257ab389612fb548f6ebf9203a Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 30 Dec 2015 15:16:22 +0100 Subject: [PATCH] + remove feature classes to import/export points --- src/Mod/Points/App/AppPoints.cpp | 3 - src/Mod/Points/App/AppPointsPy.cpp | 2 +- src/Mod/Points/App/CMakeLists.txt | 2 - .../Points/App/FeaturePointsImportAscii.cpp | 69 ----------- src/Mod/Points/App/FeaturePointsImportAscii.h | 59 --------- src/Mod/Points/App/PointsFeature.cpp | 44 ------- src/Mod/Points/App/PointsFeature.h | 22 ---- src/Mod/Points/App/PropertyPointKernel.cpp | 11 ++ src/Mod/Points/App/PropertyPointKernel.h | 2 + src/Mod/Points/Gui/Command.cpp | 115 ++++++++---------- 10 files changed, 68 insertions(+), 261 deletions(-) delete mode 100644 src/Mod/Points/App/FeaturePointsImportAscii.cpp delete mode 100644 src/Mod/Points/App/FeaturePointsImportAscii.h diff --git a/src/Mod/Points/App/AppPoints.cpp b/src/Mod/Points/App/AppPoints.cpp index a559847e4544..0dbe7f7d4d4e 100644 --- a/src/Mod/Points/App/AppPoints.cpp +++ b/src/Mod/Points/App/AppPoints.cpp @@ -33,7 +33,6 @@ #include "PointsPy.h" #include "Properties.h" #include "PropertyPointKernel.h" -#include "FeaturePointsImportAscii.h" /* registration table */ @@ -62,8 +61,6 @@ void PointsExport initPoints() // add data types Points::Feature ::init(); Points::FeaturePython ::init(); - Points::Export ::init(); - Points::ImportAscii ::init(); } } // extern "C" diff --git a/src/Mod/Points/App/AppPointsPy.cpp b/src/Mod/Points/App/AppPointsPy.cpp index 4c3de60acb00..cf55676cfbdd 100644 --- a/src/Mod/Points/App/AppPointsPy.cpp +++ b/src/Mod/Points/App/AppPointsPy.cpp @@ -44,7 +44,7 @@ #include "Points.h" #include "PointsPy.h" #include "PointsAlgos.h" -#include "FeaturePointsImportAscii.h" +#include "PointsFeature.h" using namespace Points; diff --git a/src/Mod/Points/App/CMakeLists.txt b/src/Mod/Points/App/CMakeLists.txt index 6064b046650d..d44853a53108 100644 --- a/src/Mod/Points/App/CMakeLists.txt +++ b/src/Mod/Points/App/CMakeLists.txt @@ -31,8 +31,6 @@ generate_from_xml(PointsPy) SET(Points_SRCS AppPoints.cpp AppPointsPy.cpp - FeaturePointsImportAscii.cpp - FeaturePointsImportAscii.h Points.cpp Points.h PointsPy.xml diff --git a/src/Mod/Points/App/FeaturePointsImportAscii.cpp b/src/Mod/Points/App/FeaturePointsImportAscii.cpp deleted file mode 100644 index d348d5f01aa0..000000000000 --- a/src/Mod/Points/App/FeaturePointsImportAscii.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (c) Juergen Riegel * - * * - * 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 * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -#endif - -#include -#include -#include - -#include "PointsAlgos.h" -#include "Points.h" -#include "FeaturePointsImportAscii.h" - - -using namespace Points; - -PROPERTY_SOURCE(Points::ImportAscii, Points::Feature) - -ImportAscii::ImportAscii(void) -{ - ADD_PROPERTY(FileName,("")); -} - -short ImportAscii::mustExecute() const -{ - if (FileName.isTouched()) - return 1; - return 0; -} - -App::DocumentObjectExecReturn *ImportAscii::execute(void) -{ - - // ask for read permisson - Base::FileInfo fi(FileName.getValue()); - if (!fi.isReadable()) { - std::string error = std::string("Cannot open file ") + FileName.getValue(); - return new App::DocumentObjectExecReturn(error); - } - - PointKernel kernel; - PointsAlgos::Load(kernel,FileName.getValue()); - Points.setValue(kernel); - - return App::DocumentObject::StdReturn; -} - diff --git a/src/Mod/Points/App/FeaturePointsImportAscii.h b/src/Mod/Points/App/FeaturePointsImportAscii.h deleted file mode 100644 index b76ca90a3e8e..000000000000 --- a/src/Mod/Points/App/FeaturePointsImportAscii.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * Copyright (c) Juergen Riegel * - * * - * 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 FEATURE_Points_IMPORT_Ascii_H -#define FEATURE_Points_IMPORT_Ascii_H - -#include "PointsFeature.h" - -#include - - -namespace Points -{ - -/** - * The FeaturePointsImportAscii class reads the STL Points format - * into the FreeCAD workspace. - * @author Werner Mayer - */ -class ImportAscii : public Points::Feature -{ - PROPERTY_HEADER(Points::ImportAscii); - -public: - ImportAscii(); - - App::PropertyString FileName; - - /** @name methods overide Feature */ - //@{ - /// recalculate the Feature - App::DocumentObjectExecReturn *execute(void); - short mustExecute() const; - //@} -}; - -} - -#endif // FEATURE_Points_IMPORT_STL_H diff --git a/src/Mod/Points/App/PointsFeature.cpp b/src/Mod/Points/App/PointsFeature.cpp index 5001915b82a6..5af36c170b5e 100644 --- a/src/Mod/Points/App/PointsFeature.cpp +++ b/src/Mod/Points/App/PointsFeature.cpp @@ -89,50 +89,6 @@ void Feature::onChanged(const App::Property* prop) GeoFeature::onChanged(prop); } -// ------------------------------------------------------------------ - -PROPERTY_SOURCE(Points::Export, Points::Feature) - -Export::Export(void) -{ - ADD_PROPERTY(Sources ,(0)); - ADD_PROPERTY(FileName,("")); - ADD_PROPERTY(Format ,("")); -} - -App::DocumentObjectExecReturn *Export::execute(void) -{ - // ask for write permission - Base::FileInfo fi(FileName.getValue()); - Base::FileInfo di(fi.dirPath().c_str()); - if ((fi.exists() && !fi.isWritable()) || !di.exists() || !di.isWritable()) - { - return new App::DocumentObjectExecReturn("No write permission for file"); - } - - Base::ofstream str(fi, std::ios::out | std::ios::binary); - - if (fi.hasExtension("asc")) - { - const std::vector& features = Sources.getValues(); - for ( std::vector::const_iterator it = features.begin(); it != features.end(); ++it ) - { - Feature *pcFeat = dynamic_cast(*it); - const PointKernel& kernel = pcFeat->Points.getValue(); - - str << "# " << pcFeat->getNameInDocument() << " Number of points: " << kernel.size() << std::endl; - for ( PointKernel::const_iterator it = kernel.begin(); it != kernel.end(); ++it ) - str << it->x << " " << it->y << " " << it->z << std::endl; - } - } - else - { - return new App::DocumentObjectExecReturn("File format not supported"); - } - - return App::DocumentObject::StdReturn; -} - // --------------------------------------------------------- namespace App { diff --git a/src/Mod/Points/App/PointsFeature.h b/src/Mod/Points/App/PointsFeature.h index 67f0cc9cce2b..512d9e778507 100644 --- a/src/Mod/Points/App/PointsFeature.h +++ b/src/Mod/Points/App/PointsFeature.h @@ -75,28 +75,6 @@ class PointsExport Feature : public App::GeoFeature PropertyPointKernel Points; /**< The point kernel property. */ }; -/** - * The Export class writes a point cloud to a file. - * @author Werner Mayer - */ -class Export : public Feature -{ - PROPERTY_HEADER(Points::Export); - -public: - Export(); - - App::PropertyLinkList Sources; - App::PropertyString FileName; - App::PropertyString Format; - - /** @name methods override Feature */ - //@{ - /// recalculate the Feature - virtual App::DocumentObjectExecReturn *execute(void); - //@} -}; - typedef App::FeaturePythonT FeaturePython; } //namespace Points diff --git a/src/Mod/Points/App/PropertyPointKernel.cpp b/src/Mod/Points/App/PropertyPointKernel.cpp index 8be1e7379925..d47f2b17b769 100644 --- a/src/Mod/Points/App/PropertyPointKernel.cpp +++ b/src/Mod/Points/App/PropertyPointKernel.cpp @@ -161,6 +161,17 @@ unsigned int PropertyPointKernel::getMemSize (void) const return sizeof(Base::Vector3f) * this->_cPoints->size(); } +PointKernel* PropertyPointKernel::startEditing() +{ + aboutToSetValue(); + return static_cast(_cPoints); +} + +void PropertyPointKernel::finishEditing() +{ + hasSetValue(); +} + void PropertyPointKernel::removeIndices( const std::vector& uIndices ) { // We need a sorted array diff --git a/src/Mod/Points/App/PropertyPointKernel.h b/src/Mod/Points/App/PropertyPointKernel.h index 6f08944b54f0..02fcf15cfb32 100644 --- a/src/Mod/Points/App/PropertyPointKernel.h +++ b/src/Mod/Points/App/PropertyPointKernel.h @@ -83,6 +83,8 @@ class PointsExport PropertyPointKernel : public App::PropertyComplexGeoData /** @name Modification */ //@{ + PointKernel* startEditing(); + void finishEditing(); /// Transform the real 3d point kernel void transformGeometry(const Base::Matrix4D &rclMat); void removeIndices( const std::vector& ); diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index ad6b0b23f5a0..1096dbedafde 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -55,94 +55,87 @@ DEF_STD_CMD_A(CmdPointsImport); CmdPointsImport::CmdPointsImport() - :Command("Points_Import") + : Command("Points_Import") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Import points..."); - sToolTipText = QT_TR_NOOP("Imports a point cloud"); - sWhatsThis = QT_TR_NOOP("Imports a point cloud"); - sStatusTip = QT_TR_NOOP("Imports a point cloud"); - sPixmap = "Points_Import_Point_cloud"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Import points..."); + sToolTipText = QT_TR_NOOP("Imports a point cloud"); + sWhatsThis = QT_TR_NOOP("Imports a point cloud"); + sStatusTip = QT_TR_NOOP("Imports a point cloud"); + sPixmap = "Points_Import_Point_cloud"; } void CmdPointsImport::activated(int iMsg) { - QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), + QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString::null, QString(), QString::fromLatin1("%1 (*.asc);;%2 (*.*)") .arg(QObject::tr("Ascii Points")).arg(QObject::tr("All Files"))); - if ( fn.isEmpty() ) - return; - - if (! fn.isEmpty() ) - { - QFileInfo fi; - fi.setFile(fn); - - openCommand("Points Import Create"); - doCommand(Doc,"f = App.ActiveDocument.addObject(\"Points::ImportAscii\",\"%s\")", (const char*)fi.baseName().toAscii()); - doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii()); - commitCommand(); - - updateActive(); - } + if (fn.isEmpty()) + return; + + if (!fn.isEmpty()) { + QFileInfo fi; + fi.setFile(fn); + + openCommand("Import points"); + QByteArray name = fi.baseName().toLatin1(); + Points::Feature* pts = static_cast(getActiveGuiDocument()->getDocument()-> + addObject("Points::Feature", static_cast(name))); + Points::PointKernel* kernel = pts->Points.startEditing(); + kernel->load(static_cast(fn.toLatin1())); + pts->Points.finishEditing(); + commitCommand(); + + updateActive(); + } } bool CmdPointsImport::isActive(void) { - if( getActiveGuiDocument() ) - return true; - else - return false; + if (getActiveGuiDocument()) + return true; + else + return false; } DEF_STD_CMD_A(CmdPointsExport); CmdPointsExport::CmdPointsExport() - :Command("Points_Export") + : Command("Points_Export") { - sAppModule = "Points"; - sGroup = QT_TR_NOOP("Points"); - sMenuText = QT_TR_NOOP("Export points..."); - sToolTipText = QT_TR_NOOP("Exports a point cloud"); - sWhatsThis = QT_TR_NOOP("Exports a point cloud"); - sStatusTip = QT_TR_NOOP("Exports a point cloud"); - sPixmap = "Points_Export_Point_cloud"; + sAppModule = "Points"; + sGroup = QT_TR_NOOP("Points"); + sMenuText = QT_TR_NOOP("Export points..."); + sToolTipText = QT_TR_NOOP("Exports a point cloud"); + sWhatsThis = QT_TR_NOOP("Exports a point cloud"); + sStatusTip = QT_TR_NOOP("Exports a point cloud"); + sPixmap = "Points_Export_Point_cloud"; } void CmdPointsExport::activated(int iMsg) { - QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), - QString::null, QString(), QString::fromLatin1("%1 (*.asc);;%2 (*.*)") - .arg(QObject::tr("Ascii Points")).arg(QObject::tr("All Files"))); - if ( fn.isEmpty() ) - return; - - if (! fn.isEmpty() ) - { - QFileInfo fi; - fi.setFile(fn); - - openCommand("Export Points"); std::vector points = getSelection().getObjectsOfType(Points::Feature::getClassTypeId()); - doCommand(Doc,"f = App.ActiveDocument.addObject(\"Points::Export\",\"%s\")", (const char*)fi.baseName().toAscii()); - doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii()); - doCommand(Doc,"l=list()"); - - for ( std::vector::const_iterator it = points.begin(); it != points.end(); ++it ) - { - doCommand(Doc,"l.append(App.ActiveDocument.getObject(\"%s\"))",(*it)->getNameInDocument()); + for (std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { + QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), + QString::null, QString(), QString::fromLatin1("%1 (*.asc);;%2 (*.*)") + .arg(QObject::tr("Ascii Points")).arg(QObject::tr("All Files"))); + if (fn.isEmpty()) + break; + + if (!fn.isEmpty()) { + QFileInfo fi; + fi.setFile(fn); + + Points::Feature* pts = static_cast(*it); + pts->Points.getValue().save(static_cast(fn.toLatin1())); + } } - - doCommand(Doc,"f.Sources = l"); - commitCommand(); - updateActive(); - } } bool CmdPointsExport::isActive(void) { - return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0; } DEF_STD_CMD_A(CmdPointsTransform);