From 3e4986f163d10c550d979af056bbe56f0de46055 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Wed, 10 Apr 2013 17:43:28 +0430 Subject: [PATCH] Add skeleton support for datum features --- src/Mod/PartDesign/App/CMakeLists.txt | 7 + src/Mod/PartDesign/App/DatumFeature.cpp | 189 ++++++++++++++++++++++++ src/Mod/PartDesign/App/DatumFeature.h | 109 ++++++++++++++ src/Mod/PartDesign/Gui/Workbench.cpp | 23 +-- src/Mod/PartDesign/Gui/Workbench.h | 2 - 5 files changed, 319 insertions(+), 11 deletions(-) create mode 100644 src/Mod/PartDesign/App/DatumFeature.cpp create mode 100644 src/Mod/PartDesign/App/DatumFeature.h diff --git a/src/Mod/PartDesign/App/CMakeLists.txt b/src/Mod/PartDesign/App/CMakeLists.txt index fce91a476..725c2cc8a 100644 --- a/src/Mod/PartDesign/App/CMakeLists.txt +++ b/src/Mod/PartDesign/App/CMakeLists.txt @@ -38,6 +38,12 @@ SET(Features_SRCS ) SOURCE_GROUP("Features" FILES ${Features_SRCS}) +SET(DatumFeatures_SRCS + DatumFeature.cpp + DatumFeature.h +) +SOURCE_GROUP("DatumFeatures" FILES ${DatumFeatures_SRCS}) + SET(FeaturesTransformed_SRCS FeatureTransformed.h FeatureTransformed.cpp @@ -105,6 +111,7 @@ SOURCE_GROUP("Python" FILES ${Python_SRCS}) SET(PartDesign_SRCS ${Features_SRCS} + ${DatumFeatures_SRCS} ${FeaturesTransformed_SRCS} ${FeaturesSketchBased_SRCS} ${FeaturesDressUp_SRCS} diff --git a/src/Mod/PartDesign/App/DatumFeature.cpp b/src/Mod/PartDesign/App/DatumFeature.cpp new file mode 100644 index 000000000..9eb9fa899 --- /dev/null +++ b/src/Mod/PartDesign/App/DatumFeature.cpp @@ -0,0 +1,189 @@ +/*************************************************************************** + * Copyright (c) 2013 Jan Rheinländer * + * * + * 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_ +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + + +#include "DatumFeature.h" +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + + +namespace PartDesign { + const App::PropertyFloatConstraint::Constraints angleRange = {0.0f,360.0f,1.0f}; +} + +using namespace PartDesign; + + +PROPERTY_SOURCE_ABSTRACT(PartDesign::Datum, PartDesign::Feature) + +Datum::Datum(void) +{ + ADD_PROPERTY_TYPE(References,(0,0),"Vertex",(App::PropertyType)(App::Prop_None),"References defining the vertex"); + touch(); +} + +Datum::~Datum() +{ +} + +short Datum::mustExecute(void) const +{ + if (References.isTouched()) + return 1; + return Feature::mustExecute(); +} + +void Datum::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + try { + App::DocumentObjectExecReturn *ret = recompute(); + delete ret; + } + catch (...) { + } + } + PartDesign::Feature::onChanged(prop); +} + +PROPERTY_SOURCE(PartDesign::Vertex, PartDesign::Datum) + +Vertex::Vertex() +{ +} + +Vertex::~Vertex() +{ +} + +short Vertex::mustExecute() const +{ + return PartDesign::Datum::mustExecute(); +} + +App::DocumentObjectExecReturn *Vertex::execute(void) +{ + gp_Pnt point(0,0,0); + // TODO: Find the point + + BRepBuilderAPI_MakeVertex MakeVertex(point); + const TopoDS_Vertex& vertex = MakeVertex.Vertex(); + this->Shape.setValue(vertex); + + return App::DocumentObject::StdReturn; +} + + +PROPERTY_SOURCE(PartDesign::Line, PartDesign::Datum) + +Line::Line() +{ +} + +Line::~Line() +{ +} + +short Line::mustExecute() const +{ + return PartDesign::Datum::mustExecute(); +} + +App::DocumentObjectExecReturn *Line::execute(void) +{ + gp_Pnt point1(0,0,0); + + gp_Pnt point2(10,10,10); + + BRepBuilderAPI_MakeEdge mkEdge(point1, point2); + if (!mkEdge.IsDone()) + return new App::DocumentObjectExecReturn("Failed to create edge"); + const TopoDS_Edge& edge = mkEdge.Edge(); + this->Shape.setValue(edge); + + return App::DocumentObject::StdReturn; +} + + +PROPERTY_SOURCE(PartDesign::Plane, PartDesign::Datum) + +Plane::Plane() +{ + ADD_PROPERTY_TYPE(Offset,(10.0),"Plane",App::Prop_None,"The offset from the reference"); + ADD_PROPERTY_TYPE(Angle ,(0.0),"Plane",App::Prop_None,"The angle to the reference"); +} + +short Plane::mustExecute() const +{ + if (Offset.isTouched() || + Angle.isTouched() ) + return 1; + return PartDesign::Datum::mustExecute(); +} + +App::DocumentObjectExecReturn *Plane::execute(void) +{ + double O = this->Offset.getValue(); + double A = this->Angle.getValue(); + + if (fabs(A) > 360.0) + return new App::DocumentObjectExecReturn("Angle too large (please use -360.0 .. +360.0)"); + + gp_Pnt pnt(0.0,0.0,0.0); + gp_Dir dir(0.0,0.0,1.0); + Handle_Geom_Plane aPlane = new Geom_Plane(pnt, dir); + BRepBuilderAPI_MakeFace mkFace(aPlane, 0.0, 100.0, 0.0, 100.0 +#if OCC_VERSION_HEX >= 0x060502 + , Precision::Confusion() +#endif + ); + + TopoDS_Shape ResultShape = mkFace.Shape(); + this->Shape.setValue(ResultShape); + + return App::DocumentObject::StdReturn; +} diff --git a/src/Mod/PartDesign/App/DatumFeature.h b/src/Mod/PartDesign/App/DatumFeature.h new file mode 100644 index 000000000..6053abeae --- /dev/null +++ b/src/Mod/PartDesign/App/DatumFeature.h @@ -0,0 +1,109 @@ +/*************************************************************************** + * Copyright (c) 2013 Jan Rheinländer * + * * + * 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 PARTDESIGN_DATUMFEATURE_H +#define PARTDESIGN_DATUMFEATURE_H + +//#include +#include +#include "Feature.h" + +namespace PartDesign +{ + +class PartDesignExport Datum : public PartDesign::Feature +{ + PROPERTY_HEADER(PartDesign::Datum); + +public: + Datum(); + virtual ~Datum(); + + /// The references defining the datum object, e.g. three planes for a point, two planes for a line + App::PropertyLinkSubList References; + + /** @name methods override feature */ + //@{ + /// recalculate the feature + App::DocumentObjectExecReturn *execute(void) = 0; + short mustExecute() const; + //@} + +protected: + void onChanged (const App::Property* prop); +}; + +class PartDesignExport Vertex : public PartDesign::Datum +{ + PROPERTY_HEADER(PartDesign::Vertex); + +public: + Vertex(); + virtual ~Vertex(); + + /** @name methods override feature */ + //@{ + /// recalculate the Feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + //@} +}; + +class PartDesignExport Line : public PartDesign::Datum +{ + PROPERTY_HEADER(PartDesign::Line); + +public: + Line(); + virtual ~Line(); + + /** @name methods override feature */ + //@{ + /// recalculate the Feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + //@} +}; + +class PartDesignExport Plane : public PartDesign::Datum +{ + PROPERTY_HEADER(PartDesign::Plane); + +public: + Plane(); + + App::PropertyFloat Offset; + App::PropertyFloatConstraint Angle; + + /** @name methods override feature */ + //@{ + /// recalculate the feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + //@} +}; + +} //namespace PartDesign + + +#endif // PARTDESIGN_DATUMFEATURE_H diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index d48ab0ddb..5208ab97f 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -84,7 +85,8 @@ void Workbench::setupContextMenu(const char* recipient, Gui::MenuItem* item) con { if (strcmp(recipient,"Tree") == 0) { - if (Gui::Selection().countObjectsOfType(PartDesign::Feature::getClassTypeId()) > 0 ) + if (Gui::Selection().countObjectsOfType(PartDesign::Feature::getClassTypeId()) + + Gui::Selection().countObjectsOfType(Part::Part2DObject::getClassTypeId()) > 0 ) *item << "PartDesign_MoveTip"; } } @@ -131,12 +133,21 @@ void Workbench::activated() "Part_Box" )); - const char* Plane[] = { + const char* Plane1[] = { "PartDesign_NewSketch", 0}; Watcher.push_back(new Gui::TaskView::TaskWatcherCommands( "SELECT App::Plane COUNT 1", - Plane, + Plane1, + "Start Part", + "Part_Box" + )); + const char* Plane2[] = { + "PartDesign_NewSketch", + 0}; + Watcher.push_back(new Gui::TaskView::TaskWatcherCommands( + "SELECT PartDesign::Plane COUNT 1", + Plane2, "Start Part", "Part_Box" )); @@ -225,12 +236,6 @@ void Workbench::activated() void Workbench::deactivated() { removeTaskWatcher(); - // remember the body for later activation - // TODO: Remove this if the IsActive Property of Body works OK - if(PartDesignGui::ActivePartObject) - oldActive = PartDesignGui::ActivePartObject->getNameInDocument(); - else - oldActive = ""; // reset the active Body Gui::Command::doCommand(Gui::Command::Doc,"import PartDesignGui"); Gui::Command::doCommand(Gui::Command::Doc,"PartDesignGui.setActivePart(None)"); diff --git a/src/Mod/PartDesign/Gui/Workbench.h b/src/Mod/PartDesign/Gui/Workbench.h index 0b042a91d..c2e3d0f28 100644 --- a/src/Mod/PartDesign/Gui/Workbench.h +++ b/src/Mod/PartDesign/Gui/Workbench.h @@ -74,8 +74,6 @@ protected: Gui::MenuItem* setupMenuBar() const; Gui::ToolBarItem* setupToolBars() const; Gui::ToolBarItem* setupCommandBars() const; - - std::string oldActive; }; } // namespace PartDesignGui