+ remove feature classes to import/export points

This commit is contained in:
wmayer 2015-12-30 15:16:22 +01:00
parent ad2c4c23d0
commit 4e3856acc8
10 changed files with 66 additions and 259 deletions

View File

@ -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"

View File

@ -44,7 +44,7 @@
#include "Points.h"
#include "PointsPy.h"
#include "PointsAlgos.h"
#include "FeaturePointsImportAscii.h"
#include "PointsFeature.h"
using namespace Points;

View File

@ -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

View File

@ -1,69 +0,0 @@
/***************************************************************************
* Copyright (c) Juergen 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 *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
#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;
}

View File

@ -1,59 +0,0 @@
/***************************************************************************
* Copyright (c) Juergen 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 FEATURE_Points_IMPORT_Ascii_H
#define FEATURE_Points_IMPORT_Ascii_H
#include "PointsFeature.h"
#include <App/PropertyStandard.h>
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

View File

@ -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<App::DocumentObject*>& features = Sources.getValues();
for ( std::vector<App::DocumentObject*>::const_iterator it = features.begin(); it != features.end(); ++it )
{
Feature *pcFeat = dynamic_cast<Feature*>(*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 {

View File

@ -75,28 +75,6 @@ public:
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<Feature> FeaturePython;
} //namespace Points

View File

@ -161,6 +161,17 @@ unsigned int PropertyPointKernel::getMemSize (void) const
return sizeof(Base::Vector3f) * this->_cPoints->size();
}
PointKernel* PropertyPointKernel::startEditing()
{
aboutToSetValue();
return static_cast<PointKernel*>(_cPoints);
}
void PropertyPointKernel::finishEditing()
{
hasSetValue();
}
void PropertyPointKernel::removeIndices( const std::vector<unsigned long>& uIndices )
{
// We need a sorted array

View File

@ -83,6 +83,8 @@ public:
/** @name Modification */
//@{
PointKernel* startEditing();
void finishEditing();
/// Transform the real 3d point kernel
void transformGeometry(const Base::Matrix4D &rclMat);
void removeIndices( const std::vector<unsigned long>& );

View File

@ -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())
return;
if (! fn.isEmpty() )
{
QFileInfo fi;
fi.setFile(fn);
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();
}
openCommand("Import points");
QByteArray name = fi.baseName().toLatin1();
Points::Feature* pts = static_cast<Points::Feature*>(getActiveGuiDocument()->getDocument()->
addObject("Points::Feature", static_cast<const char*>(name)));
Points::PointKernel* kernel = pts->Points.startEditing();
kernel->load(static_cast<const char*>(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<App::DocumentObject*> 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<App::DocumentObject*>::const_iterator it = points.begin(); it != points.end(); ++it )
{
doCommand(Doc,"l.append(App.ActiveDocument.getObject(\"%s\"))",(*it)->getNameInDocument());
}
for (std::vector<App::DocumentObject*>::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;
doCommand(Doc,"f.Sources = l");
commitCommand();
updateActive();
}
if (!fn.isEmpty()) {
QFileInfo fi;
fi.setFile(fn);
Points::Feature* pts = static_cast<Points::Feature*>(*it);
pts->Points.getValue().save(static_cast<const char*>(fn.toLatin1()));
}
}
}
bool CmdPointsExport::isActive(void)
{
return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0;
return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0;
}
DEF_STD_CMD_A(CmdPointsTransform);