diff --git a/src/Mod/Points/App/AppPoints.cpp b/src/Mod/Points/App/AppPoints.cpp index 0dbe7f7d4..47c5cbd83 100644 --- a/src/Mod/Points/App/AppPoints.cpp +++ b/src/Mod/Points/App/AppPoints.cpp @@ -33,6 +33,7 @@ #include "PointsPy.h" #include "Properties.h" #include "PropertyPointKernel.h" +#include "ViewFeature.h" /* registration table */ @@ -61,6 +62,7 @@ void PointsExport initPoints() // add data types Points::Feature ::init(); Points::FeaturePython ::init(); + Points::ViewFeature ::init(); } } // extern "C" diff --git a/src/Mod/Points/App/CMakeLists.txt b/src/Mod/Points/App/CMakeLists.txt index d44853a53..d0c4a25a5 100644 --- a/src/Mod/Points/App/CMakeLists.txt +++ b/src/Mod/Points/App/CMakeLists.txt @@ -47,6 +47,8 @@ SET(Points_SRCS Properties.h PropertyPointKernel.cpp PropertyPointKernel.h + ViewFeature.cpp + ViewFeature.h ) add_library(Points SHARED ${Points_SRCS}) diff --git a/src/Mod/Points/App/ViewFeature.cpp b/src/Mod/Points/App/ViewFeature.cpp new file mode 100644 index 000000000..b837dbe22 --- /dev/null +++ b/src/Mod/Points/App/ViewFeature.cpp @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (c) 2015 Werner Mayer * + * * + * 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 "ViewFeature.h" + +using namespace Points; + + +//=========================================================================== +// ViewFeature +//=========================================================================== +/* +import Points +import random +import math + +r=random.Random() + +p=Points.Points() +pts=[] +for i in range(21): + for j in range(21): + pts.append(App.Vector(i,j,r.gauss(5,0.05))) + +p.addPoints(pts) +doc=App.ActiveDocument +pts=doc.addObject('Points::ViewFeature','View') +pts.Points=p +pts.Width=21 +pts.Height=21 +*/ + +PROPERTY_SOURCE(Points::ViewFeature, Points::Feature) + +ViewFeature::ViewFeature() +{ + App::PropertyType type = static_cast(App::Prop_None); + ADD_PROPERTY_TYPE(Width ,(0), "View", type, "The width of the point view"); + ADD_PROPERTY_TYPE(Height,(0), "View", type, "The height of the point view"); + ADD_PROPERTY_TYPE(Direction ,(Base::Vector3d(0,0,1)), "View", type, "The direction of the point view"); + + Width.StatusBits.set(2, true); + Height.StatusBits.set(2, true); +} + +ViewFeature::~ViewFeature() +{ +} + +App::DocumentObjectExecReturn *ViewFeature::execute(void) +{ + int size = Height.getValue() * Width.getValue(); + if (size != Points.getValue().size()) + throw Base::ValueError("(Width * Height) doesn't match with number of points"); + this->Points.touch(); + return App::DocumentObject::StdReturn; +} diff --git a/src/Mod/Points/App/ViewFeature.h b/src/Mod/Points/App/ViewFeature.h new file mode 100644 index 000000000..a49e65bb6 --- /dev/null +++ b/src/Mod/Points/App/ViewFeature.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (c) 2015 Werner Mayer * + * * + * 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 POINTS_VIEW_FEATURE_H +#define POINTS_VIEW_FEATURE_H + +#include "PointsFeature.h" + + +namespace Points +{ + +/*! For the ViewFeature class it is expected that the Point property has Width*Height vertices + and that with respect to their x,y coordinates they are ordered in a grid structure. + If a point is marked invalid then one of its coordinates is set to NaN. + */ +class PointsExport ViewFeature : public Points::Feature +{ + PROPERTY_HEADER(Points::ViewFeature); + +public: + /// Constructor + ViewFeature(void); + virtual ~ViewFeature(void); + /// recalculate the Feature + virtual App::DocumentObjectExecReturn *execute(void); + //@} + + App::PropertyInteger Width; /**< The width of the view. */ + App::PropertyInteger Height; /**< The height of the view. */ + App::PropertyVector Direction; /**< The direction of the view. */ +}; + +} //namespace Points + + +#endif diff --git a/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp b/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp index d04e9531c..2cad5fc3d 100644 --- a/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp +++ b/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp @@ -345,8 +345,8 @@ Mesh.show(m) int width; int height; - static char* kwds_greedy[] = {"Points", "Width", "Height", NULL}; - if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!|ii", kwds_greedy, + static char* kwds_view[] = {"Points", "Width", "Height", NULL}; + if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!|ii", kwds_view, &(Points::PointsPy::Type), &pts, &width, &height)) throw Py::Exception(); diff --git a/src/Mod/ReverseEngineering/Gui/Command.cpp b/src/Mod/ReverseEngineering/Gui/Command.cpp index a0c3e2c67..1e5143560 100644 --- a/src/Mod/ReverseEngineering/Gui/Command.cpp +++ b/src/Mod/ReverseEngineering/Gui/Command.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -214,10 +214,63 @@ bool CmdPoissonReconstruction::isActive(void) return (hasActiveDocument() && !Gui::Control().activeDialog()); } +DEF_STD_CMD_A(CmdViewTriangulation); + +CmdViewTriangulation::CmdViewTriangulation() + : Command("Reen_ViewTriangulation") +{ + sAppModule = "Reen"; + sGroup = QT_TR_NOOP("Reverse Engineering"); + sMenuText = QT_TR_NOOP("View triangulation"); + sToolTipText = QT_TR_NOOP("View triangulation"); + sToolTipText = QT_TR_NOOP("View triangulation"); + sWhatsThis = "Reen_ViewTriangulation"; +} + +void CmdViewTriangulation::activated(int iMsg) +{ + std::vector obj = Gui::Selection().getObjectsOfType(Points::ViewFeature::getClassTypeId()); + addModule(App,"ReverseEngineering"); + openCommand("View triangulation"); + try { + for (std::vector::iterator it = obj.begin(); it != obj.end(); ++it) { + App::DocumentObjectT objT(*it); + QString document = QString::fromStdString(objT.getDocumentPython()); + QString object = QString::fromStdString(objT.getObjectPython()); + + QString command = QString::fromLatin1("%1.addObject('Mesh::Feature', 'View mesh').Mesh = ReverseEngineering.viewTriangulation(" + "Points=%2.Points," + "Width=%2.Width," + "Height=%2.Height)" + ) + .arg(document) + .arg(object) + ; + doCommand(Doc, command.toLatin1()); + } + + commitCommand(); + updateActive(); + } + catch (const Base::Exception& e) { + abortCommand(); + QMessageBox::warning(Gui::getMainWindow(), + qApp->translate("Reen_ViewTriangulation", "View triangulation failed"), + QString::fromLatin1(e.what()) + ); + } +} + +bool CmdViewTriangulation::isActive(void) +{ + return Gui::Selection().countObjectsOfType(Points::ViewFeature::getClassTypeId()) > 0; +} + void CreateReverseEngineeringCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdApproxSurface()); rcCmdMgr.addCommand(new CmdApproxPlane()); rcCmdMgr.addCommand(new CmdPoissonReconstruction()); + rcCmdMgr.addCommand(new CmdViewTriangulation()); } diff --git a/src/Mod/ReverseEngineering/Gui/Workbench.cpp b/src/Mod/ReverseEngineering/Gui/Workbench.cpp index 67add1247..a6ac472aa 100644 --- a/src/Mod/ReverseEngineering/Gui/Workbench.cpp +++ b/src/Mod/ReverseEngineering/Gui/Workbench.cpp @@ -60,7 +60,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem *reconstruct = new Gui::MenuItem(); reconstruct->setCommand("Surface reconstruction"); - *reconstruct << "Reen_PoissonReconstruction"; + *reconstruct << "Reen_PoissonReconstruction" + << "Reen_ViewTriangulation"; *reen << reconstruct; return root;