diff --git a/src/Mod/Part/App/PartFeature.h b/src/Mod/Part/App/PartFeature.h index 46898c1233..f984bdc084 100644 --- a/src/Mod/Part/App/PartFeature.h +++ b/src/Mod/Part/App/PartFeature.h @@ -68,9 +68,10 @@ public: virtual PyObject* getPyObject(void); virtual std::vector getPySubObjects(const std::vector&) const; + TopLoc_Location getLocation() const; + protected: void onChanged(const App::Property* prop); - TopLoc_Location getLocation() const; /** * Build a history of changes * MakeShape: The operation that created the changes, e.g. BRepAlgoAPI_Common diff --git a/src/Mod/PartDesign/App/AppPartDesign.cpp b/src/Mod/PartDesign/App/AppPartDesign.cpp index 651889fe0a..2f32c7bf1c 100644 --- a/src/Mod/PartDesign/App/AppPartDesign.cpp +++ b/src/Mod/PartDesign/App/AppPartDesign.cpp @@ -108,7 +108,13 @@ PyMODINIT_FUNC init_PartDesign() PartDesign::Box ::init(); PartDesign::AdditiveBox ::init(); PartDesign::SubtractiveBox ::init(); - + PartDesign::Cylinder ::init(); + PartDesign::AdditiveCylinder ::init(); + PartDesign::SubtractiveCylinder::init(); + PartDesign::Sphere ::init(); + PartDesign::AdditiveSphere ::init(); + PartDesign::SubtractiveSphere ::init(); + PartDesign::Point ::initHints(); PartDesign::Line ::initHints(); PartDesign::Plane ::initHints(); diff --git a/src/Mod/PartDesign/App/DatumCS.cpp b/src/Mod/PartDesign/App/DatumCS.cpp new file mode 100644 index 0000000000..ba8af598cd --- /dev/null +++ b/src/Mod/PartDesign/App/DatumCS.cpp @@ -0,0 +1,193 @@ +/*************************************************************************** + * Copyright (c) 2015 Stefan Tröger * + * * + * 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 "DatumCS.h" +#include "DatumPoint.h" +#include "DatumPlane.h" +#include +#include +#include +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +using namespace PartDesign; + +// Note: We don't distinguish between e.g. datum lines and edges here +#define PLANE QObject::tr("DPLANE") +#define CYLINDER QObject::tr("DCYLINDER") +#define LINE QObject::tr("DLINE") +#define POINT QObject::tr("DPOINT") +#define ANGLE QObject::tr("Angle") +#define CS QObject::tr("DCOORDINATESYSTEM") + +std::map, std::set > CoordinateSystem::hints = std::map, std::set >(); + +void CoordinateSystem::initHints() +{ + std::set DONE; + DONE.insert(QObject::tr("Done")); + + std::multiset key; + std::set value; + key.insert(POINT); + hints[key] = DONE; + + key.clear(); value.clear(); + key.insert(PLANE); + hints[key] = DONE; +} + +// ============================================================================ + +PROPERTY_SOURCE(PartDesign::CoordinateSystem, Part::Datum) + +CoordinateSystem::CoordinateSystem() +{ + // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of + // Sketcher on the PartDesign module + BRepBuilderAPI_MakeFace builder(gp_Pln(gp_Pnt(0,0,0), gp_Dir(0,0,1))); + if (!builder.IsDone()) + return; + Shape.setValue(builder.Shape()); + + References.touch(); +} + +CoordinateSystem::~CoordinateSystem() +{ +} + +void CoordinateSystem::onChanged(const App::Property *prop) +{ + if ((prop == &References) || (prop == &Offset) || (prop == &Offset2) || (prop == &Offset3)) { + + Base::Placement plm; + const std::vector& refs = References.getValues(); + const std::vector& subrefs = References.getSubValues(); + + if (refs.size() != subrefs.size()) + return; + + refTypes.clear(); + for (int r = 0; r < refs.size(); r++) + refTypes.insert(getRefType(refs[r], subrefs[r])); + + std::set hint = getHint(); + if (refs.size() != 0 && !(hint.find(QObject::tr("Done")) != hint.end())) + return; // incomplete references + + //build the placement from the references + bool plane = false; + Base::Vector3d pl_base, pl_normal; + + int count = 0; + for(App::DocumentObject* obj : refs) { + + if (obj->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { + PartDesign::Plane* p = static_cast(obj); + if(!plane) { + pl_base = p->getBasePoint(); + pl_normal = p->getNormal(); + plane=true; + } + } else if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { + PartDesign::Plane* p = static_cast(obj); + if(!plane) { + pl_base = Base::Vector3d(0,0,0); + if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[0]) == 0) + pl_normal = Base::Vector3d(0,0,1); + else if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[2]) == 0) + pl_normal = Base::Vector3d(1,0,0); + else if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[1]) == 0) + pl_normal = Base::Vector3d(0,1,0); + + plane=true; + } + } + + count++; + }; + + if(plane) { + plm = Base::Placement(pl_base, Base::Rotation(Base::Vector3d(0,0,1), pl_normal)); + } + + //add the offsets + Base::Vector3d o1; + plm.multVec(Offset.getValue()*Base::Vector3d(1,0,0), o1); + Base::Vector3d o2; + plm.multVec(Offset2.getValue()*Base::Vector3d(0,1,0), o2); + Base::Vector3d o3; + plm.multVec(Offset3.getValue()*Base::Vector3d(0,0,1), o3); + plm.move(o1+o2+o3); + + Placement.setValue(plm); + } + Part::Datum::onChanged(prop); +} + + +const std::set CoordinateSystem::getHint() const +{ + if (hints.find(refTypes) != hints.end()) + return hints[refTypes]; + else + return std::set(); +} + +const int CoordinateSystem::offsetsAllowed() const +{ + return 3; +} + +Base::Vector3d CoordinateSystem::getXAxis() +{ + Base::Rotation rot = Placement.getValue().getRotation(); + Base::Vector3d normal; + rot.multVec(Base::Vector3d(1,0,0), normal); + return normal; +} + +Base::Vector3d CoordinateSystem::getYAxis() +{ + Base::Rotation rot = Placement.getValue().getRotation(); + Base::Vector3d normal; + rot.multVec(Base::Vector3d(0,1,0), normal); + return normal; +} + +Base::Vector3d CoordinateSystem::getZAxis() +{ + Base::Rotation rot = Placement.getValue().getRotation(); + Base::Vector3d normal; + rot.multVec(Base::Vector3d(0,0,1), normal); + return normal; +} \ No newline at end of file diff --git a/src/Mod/PartDesign/App/DatumCS.h b/src/Mod/PartDesign/App/DatumCS.h new file mode 100644 index 0000000000..1150efaac7 --- /dev/null +++ b/src/Mod/PartDesign/App/DatumCS.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2015 Stefan Tröger * + * * + * 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_DATUMCS_H +#define PARTDESIGN_DATUMCS_H + +#include +#include +#include + +namespace PartDesign +{ + +class PartDesignExport CoordinateSystem : public Part::Datum +{ + PROPERTY_HEADER(PartDesign::CoordinateSystem); + +public: + CoordinateSystem(); + virtual ~CoordinateSystem(); + + const char* getViewProviderName(void) const { + return "PartDesignGui::ViewProviderDatumCoordinateSystem"; + } + + static void initHints(); + const std::set getHint() const; + const int offsetsAllowed() const; + + Base::Vector3d getXAxis(); + Base::Vector3d getYAxis(); + Base::Vector3d getZAxis(); + +protected: + virtual void onChanged(const App::Property* prop); + +private: + // Hints on what further references are required/possible on this feature for a given set of references + static std::map, std::set > hints; +}; + +} //namespace PartDesign + + +#endif // PARTDESIGN_DATUMCS_H diff --git a/src/Mod/PartDesign/App/FeaturePrimitive.cpp b/src/Mod/PartDesign/App/FeaturePrimitive.cpp index 310821bd0a..f50c506971 100644 --- a/src/Mod/PartDesign/App/FeaturePrimitive.cpp +++ b/src/Mod/PartDesign/App/FeaturePrimitive.cpp @@ -28,6 +28,7 @@ #include "FeaturePrimitive.h" #include "DatumPoint.h" +#include "DatumCS.h" #include #include #include @@ -36,6 +37,9 @@ #include #include #include +#include +#include +#include #include using namespace PartDesign; @@ -67,13 +71,18 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri { try { //transform the primitive in the correct coordinance - //BRepBuilderAPI_GTransform mkTrf(primitiveShape, getLocation().Transformation()); - //const TopoDS_Shape primitiveShape = mkTrf.Shape(); + App::DocumentObject* cs = CoordinateSystem.getValue(); + if(cs && cs->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId()) + Placement.setValue(static_cast(cs)->Placement.getValue()); + else + Placement.setValue(Base::Placement()); //if we have no base we just add the standart primitive shape TopoDS_Shape base; try{ - base = getBaseShape(); + //if we have a base shape we need to make sure that it does not get our transformation to + BRepBuilderAPI_Transform trsf(getBaseShape(), getLocation().Transformation().Inverted(), true); + base = trsf.Shape(); } catch(const Base::Exception&) { @@ -128,47 +137,7 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri } void FeaturePrimitive::onChanged(const App::Property* prop) -{/* - if ((prop == &CoordinateSystem)) { - std::multiset refTypes; - std::vector refs = References.getValues(); - std::vector refnames = References.getSubValues(); - if (refs.size() != refnames.size()) - return; - - for (int r = 0; r < refs.size(); r++) - refTypes.insert(getRefType(refs[r], refnames[r])); - - std::set hint; - if (hints.find(refTypes) != hints.end()) - hint = hints[refTypes]; - - if (!((hint.size() == 1) && (hint.find(QObject::tr("Done")) != hint.end()))) - return; // incomplete references - - std::pair origin = {Base::Vector3d(), false}; - std::pair dirX = {Base::Vector3d(), false}; - std::pair dirY = {Base::Vector3d(), false}; - - for (int i = 0; i < refs.size(); i++) { - - if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) { - Base::Vector3d point = static_cast(refs[i])->getPoint(); - if (!origin.second) - origin = {point, true}; - else if(!dirX.second) { - if((point-dirX.first).Sqr() < Precision::Confusion()) - return; - dirX = {point, true}; - } - else if(!dirY.second) { - if((origin.first-dirX.first).Sqr() < Precision::Confusion()) - return; - dirY = {point, true}; - } - } - } - } */ +{ FeatureAddSub::onChanged(prop); } @@ -222,4 +191,97 @@ short int Box::mustExecute() const PROPERTY_SOURCE(PartDesign::AdditiveBox, PartDesign::Box) PROPERTY_SOURCE(PartDesign::SubtractiveBox, PartDesign::Box) + +PROPERTY_SOURCE(PartDesign::Cylinder, PartDesign::FeaturePrimitive) + +Cylinder::Cylinder() +{ + ADD_PROPERTY_TYPE(Radius,(10.0f),"Cylinder",App::Prop_None,"The radius of the cylinder"); + ADD_PROPERTY_TYPE(Angle,(10.0f),"Cylinder",App::Prop_None,"The closing angel of the cylinder "); + ADD_PROPERTY_TYPE(Height,(10.0f),"Cylinder",App::Prop_None,"The height of the cylinder"); + + primitiveType = FeaturePrimitive::Cylinder; +} + +App::DocumentObjectExecReturn* Cylinder::execute(void) +{ + // Build a cylinder + if (Radius.getValue() < Precision::Confusion()) + return new App::DocumentObjectExecReturn("Radius of cylinder too small"); + if (Height.getValue() < Precision::Confusion()) + return new App::DocumentObjectExecReturn("Height of cylinder too small"); + try { + BRepPrimAPI_MakeCylinder mkCylr(Radius.getValue(), + Height.getValue(), + Angle.getValue()/180.0f*M_PI); + + return FeaturePrimitive::execute(mkCylr.Shape()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); + } + + return App::DocumentObject::StdReturn; +} + +short int Cylinder::mustExecute() const +{ + if ( Radius.isTouched() || + Height.isTouched() || + Angle.isTouched() ) + return 1; + + return FeaturePrimitive::mustExecute(); +} + +PROPERTY_SOURCE(PartDesign::AdditiveCylinder, PartDesign::Cylinder) +PROPERTY_SOURCE(PartDesign::SubtractiveCylinder, PartDesign::Cylinder) + + +PROPERTY_SOURCE(PartDesign::Sphere, PartDesign::FeaturePrimitive) + +Sphere::Sphere() +{ + ADD_PROPERTY_TYPE(Radius,(5.0),"Sphere",App::Prop_None,"The radius of the sphere"); + ADD_PROPERTY_TYPE(Angle1,(-90.0f),"Sphere",App::Prop_None,"The angle of the sphere"); + ADD_PROPERTY_TYPE(Angle2,(90.0f),"Sphere",App::Prop_None,"The angle of the sphere"); + ADD_PROPERTY_TYPE(Angle3,(360.0f),"Sphere",App::Prop_None,"The angle of the sphere"); + + primitiveType = FeaturePrimitive::Sphere; +} + +App::DocumentObjectExecReturn* Sphere::execute(void) +{ + // Build a sphere + if (Radius.getValue() < Precision::Confusion()) + return new App::DocumentObjectExecReturn("Radius of sphere too small"); + try { + BRepPrimAPI_MakeSphere mkSphere(Radius.getValue(), + Angle1.getValue()/180.0f*M_PI, + Angle2.getValue()/180.0f*M_PI, + Angle3.getValue()/180.0f*M_PI); + return FeaturePrimitive::execute(mkSphere.Shape()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); + } + + return App::DocumentObject::StdReturn; +} + +short int Sphere::mustExecute() const +{ + if ( Radius.isTouched() || + Angle1.isTouched() || + Angle2.isTouched() || + Angle3.isTouched()) + return 1; + + return FeaturePrimitive::mustExecute(); +} + +PROPERTY_SOURCE(PartDesign::AdditiveSphere, PartDesign::Sphere) +PROPERTY_SOURCE(PartDesign::SubtractiveSphere, PartDesign::Sphere) } diff --git a/src/Mod/PartDesign/App/FeaturePrimitive.h b/src/Mod/PartDesign/App/FeaturePrimitive.h index 34e5226963..d17af1a3b4 100644 --- a/src/Mod/PartDesign/App/FeaturePrimitive.h +++ b/src/Mod/PartDesign/App/FeaturePrimitive.h @@ -97,6 +97,85 @@ class PartDesignExport SubtractiveBox : public Box { } }; + +class PartDesignExport Cylinder : public PartDesign::FeaturePrimitive { + + PROPERTY_HEADER(PartDesign::Cylinder); + +public: + + Cylinder(); + + App::PropertyLength Radius; + App::PropertyLength Height; + App::PropertyAngle Angle; + + /** @name methods override feature */ + //@{ + /// recalculate the Feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + +protected: + +}; + +class PartDesignExport AdditiveCylinder : public Cylinder { + PROPERTY_HEADER(PartDesign::AdditiveCylinder); + + AdditiveCylinder() { + addSubType = FeatureAddSub::Additive; + } +}; + +class PartDesignExport SubtractiveCylinder : public Cylinder { + PROPERTY_HEADER(PartDesign::SubtractiveCylinder); + + SubtractiveCylinder() { + addSubType = FeatureAddSub::Subtractive; + } +}; + + +class PartDesignExport Sphere : public PartDesign::FeaturePrimitive { + + PROPERTY_HEADER(PartDesign::Sphere); + +public: + + Sphere(); + + App::PropertyLength Radius; + App::PropertyAngle Angle1; + App::PropertyAngle Angle2; + App::PropertyAngle Angle3; + + /** @name methods override feature */ + //@{ + /// recalculate the Feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + +protected: + +}; + +class PartDesignExport AdditiveSphere : public Sphere { + PROPERTY_HEADER(PartDesign::AdditiveSphere); + + AdditiveSphere() { + addSubType = FeatureAddSub::Additive; + } +}; + +class PartDesignExport SubtractiveSphere : public Sphere { + PROPERTY_HEADER(PartDesign::SubtractiveSphere); + + SubtractiveSphere() { + addSubType = FeatureAddSub::Subtractive; + } +}; + } //namespace PartDesign diff --git a/src/Mod/PartDesign/Gui/CommandPrimitive.cpp b/src/Mod/PartDesign/Gui/CommandPrimitive.cpp index 56247f2fa5..eddd167314 100644 --- a/src/Mod/PartDesign/Gui/CommandPrimitive.cpp +++ b/src/Mod/PartDesign/Gui/CommandPrimitive.cpp @@ -58,27 +58,51 @@ void CmdPrimtiveCompAdditive::activated(int iMsg) PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true); if (!pcActiveBody) return; + std::string FeatName; + std::string CSName = getUniqueObjectName("CoordinateSystem");; if(iMsg == 0) { - std::string FeatName = getUniqueObjectName("Box"); - std::string CSName = getUniqueObjectName("CoordinateSystem"); - + FeatName = getUniqueObjectName("Box"); + Gui::Command::openCommand("Make additive box"); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::AdditiveBox\',\'%s\')", FeatName.c_str()); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)" - ,pcActiveBody->getNameInDocument(), FeatName.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::CoordinateSystem\',\'%s\')", - CSName.c_str()); - Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)" - ,pcActiveBody->getNameInDocument(), CSName.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.CoordinateSystem=(App.ActiveDocument.%s)", - FeatName.c_str(), CSName.c_str()); - Gui::Command::updateActive(); - - Gui::Command::doCommand(Gui, "Gui.activeDocument().hide(\'%s\')", CSName.c_str()); - Gui::Command::doCommand(Gui, "Gui.activeDocument().setEdit(\'%s\')", FeatName.c_str()); } + else if(iMsg == 1) { + + FeatName = getUniqueObjectName("Cylinder"); + + Gui::Command::openCommand("Make additive cylinder"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::AdditiveCylinder\',\'%s\')", + FeatName.c_str()); + } + else if(iMsg == 3) { + + FeatName = getUniqueObjectName("Sphere"); + + Gui::Command::openCommand("Make additive sphere"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::AdditiveSphere\',\'%s\')", + FeatName.c_str()); + } + + Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)" + ,pcActiveBody->getNameInDocument(), FeatName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::CoordinateSystem\',\'%s\')", + CSName.c_str()); + Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)" + ,pcActiveBody->getNameInDocument(), CSName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.CoordinateSystem=(App.ActiveDocument.%s)", + FeatName.c_str(), CSName.c_str()); + Gui::Command::updateActive(); + + if (isActiveObjectValid() && (pcActiveBody != NULL)) { + App::DocumentObject* prevSolidFeature = pcActiveBody->getPrevSolidFeature(NULL, false); + if (prevSolidFeature != NULL && strcmp(prevSolidFeature->getNameInDocument(), FeatName.c_str())!=0) + doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument()); + } + + Gui::Command::doCommand(Gui, "Gui.activeDocument().hide(\'%s\')", CSName.c_str()); + Gui::Command::doCommand(Gui, "Gui.activeDocument().setEdit(\'%s\')", FeatName.c_str()); } Gui::Action * CmdPrimtiveCompAdditive::createAction(void) @@ -88,9 +112,11 @@ Gui::Action * CmdPrimtiveCompAdditive::createAction(void) applyCommandData(this->className(), pcAction); QAction* p1 = pcAction->addAction(QString()); - p1->setIcon(Gui::BitmapFactory().pixmap("Part_Box")); + p1->setIcon(Gui::BitmapFactory().pixmap("PartDesign_Additive_Box")); QAction* p2 = pcAction->addAction(QString()); - p2->setIcon(Gui::BitmapFactory().pixmap("Part_Cylinder")); + p2->setIcon(Gui::BitmapFactory().pixmap("PartDesign_Additive_Cylinder")); + QAction* p3 = pcAction->addAction(QString()); + p3->setIcon(Gui::BitmapFactory().pixmap("PartDesign_Additive_Sphere")); _pcAction = pcAction; languageChange(); @@ -112,13 +138,17 @@ void CmdPrimtiveCompAdditive::languageChange() QList a = pcAction->actions(); QAction* arc1 = a[0]; - arc1->setText(QApplication::translate("CmdSketcherCompCreateArc","Center and end points")); - arc1->setToolTip(QApplication::translate("Sketcher_CreateArc","Create an arc by its center and by its end points")); - arc1->setStatusTip(QApplication::translate("Sketcher_CreateArc","Create an arc by its center and by its end points")); + arc1->setText(QApplication::translate("CmdPrimtiveCompAdditive","Additive Box")); + arc1->setToolTip(QApplication::translate("PartDesign_CompPrimitiveAdditive","Create an additive box by its with, height and length")); + arc1->setStatusTip(arc1->toolTip()); QAction* arc2 = a[1]; - arc2->setText(QApplication::translate("CmdSketcherCompCreateArc","End points and rim point")); - arc2->setToolTip(QApplication::translate("Sketcher_Create3PointArc","Create an arc by its end points and a point along the arc")); - arc2->setStatusTip(QApplication::translate("Sketcher_Create3PointArc","Create an arc by its end points and a point along the arc")); + arc2->setText(QApplication::translate("CmdPrimtiveCompAdditive","Additive Cylinder")); + arc2->setToolTip(QApplication::translate("PartDesign_CompPrimitiveAdditive","Create an additive cylinder by its radius, height and angle")); + arc2->setStatusTip(arc2->toolTip()); + QAction* arc3 = a[2]; + arc3->setText(QApplication::translate("CmdPrimtiveCompAdditive","Additive Sphere")); + arc3->setToolTip(QApplication::translate("PartDesign_CompPrimitiveAdditive","Create an additive sphere by its radius and varius angles")); + arc3->setStatusTip(arc3->toolTip()); } bool CmdPrimtiveCompAdditive::isActive(void) @@ -148,18 +178,51 @@ void CmdPrimtiveCompSubtractive::activated(int iMsg) PartDesign::Body *pcActiveBody = PartDesignGui::getBody(); if (!pcActiveBody) return; + std::string FeatName; + std::string CSName = getUniqueObjectName("CoordinateSystem"); if(iMsg == 0) { - std::string FeatName = getUniqueObjectName("Box"); - + FeatName = getUniqueObjectName("Box"); + Gui::Command::openCommand("Make subtractive box"); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\'PartDesign::SubtractiveBox\',\'%s\')", + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::SubtractiveBox\',\'%s\')", FeatName.c_str()); - Gui::Command::doCommand(Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)" - ,pcActiveBody->getNameInDocument(), FeatName.c_str()); - Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeDocument().setEdit(\'%s\')", FeatName.c_str()); - Gui::Command::updateActive(); } + else if(iMsg == 1) { + + FeatName = getUniqueObjectName("Cylinder"); + + Gui::Command::openCommand("Make subtractive cylinder"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::SubtractiveCylinder\',\'%s\')", + FeatName.c_str()); + } + else if(iMsg == 2) { + + FeatName = getUniqueObjectName("Sphere"); + + Gui::Command::openCommand("Make subtractive sphere"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::SubtractiveSphere\',\'%s\')", + FeatName.c_str()); + } + + Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)" + ,pcActiveBody->getNameInDocument(), FeatName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::CoordinateSystem\',\'%s\')", + CSName.c_str()); + Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)" + ,pcActiveBody->getNameInDocument(), CSName.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.CoordinateSystem=(App.ActiveDocument.%s)", + FeatName.c_str(), CSName.c_str()); + Gui::Command::updateActive(); + + if (isActiveObjectValid() && (pcActiveBody != NULL)) { + App::DocumentObject* prevSolidFeature = pcActiveBody->getPrevSolidFeature(NULL, false); + if (prevSolidFeature != NULL && strcmp(prevSolidFeature->getNameInDocument(), FeatName.c_str())!=0) + doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument()); + } + + Gui::Command::doCommand(Gui, "Gui.activeDocument().hide(\'%s\')", CSName.c_str()); + Gui::Command::doCommand(Gui, "Gui.activeDocument().setEdit(\'%s\')", FeatName.c_str()); } Gui::Action * CmdPrimtiveCompSubtractive::createAction(void) @@ -169,9 +232,11 @@ Gui::Action * CmdPrimtiveCompSubtractive::createAction(void) applyCommandData(this->className(), pcAction); QAction* p1 = pcAction->addAction(QString()); - p1->setIcon(Gui::BitmapFactory().pixmap("Part_Box")); + p1->setIcon(Gui::BitmapFactory().pixmap("PartDesign_Subtractive_Box")); QAction* p2 = pcAction->addAction(QString()); - p2->setIcon(Gui::BitmapFactory().pixmap("Part_Cylinder")); + p2->setIcon(Gui::BitmapFactory().pixmap("PartDesign_Subtractive_Cylinder")); + QAction* p3 = pcAction->addAction(QString()); + p3->setIcon(Gui::BitmapFactory().pixmap("PartDesign_Subtractive_Sphere")); _pcAction = pcAction; languageChange(); @@ -193,13 +258,17 @@ void CmdPrimtiveCompSubtractive::languageChange() QList a = pcAction->actions(); QAction* arc1 = a[0]; - arc1->setText(QApplication::translate("CmdSketcherCompCreateArc","Center and end points")); - arc1->setToolTip(QApplication::translate("Sketcher_CreateArc","Create an arc by its center and by its end points")); - arc1->setStatusTip(QApplication::translate("Sketcher_CreateArc","Create an arc by its center and by its end points")); + arc1->setText(QApplication::translate("CmdPrimtiveCompSubtractive","Subtractive Box")); + arc1->setToolTip(QApplication::translate("PartDesign_CompPrimitiveSubtractive","Create an subtractive box by its with, height and length")); + arc1->setStatusTip(arc1->toolTip()); QAction* arc2 = a[1]; - arc2->setText(QApplication::translate("CmdSketcherCompCreateArc","End points and rim point")); - arc2->setToolTip(QApplication::translate("Sketcher_Create3PointArc","Create an arc by its end points and a point along the arc")); - arc2->setStatusTip(QApplication::translate("Sketcher_Create3PointArc","Create an arc by its end points and a point along the arc")); + arc2->setText(QApplication::translate("CmdPrimtiveCompSubtractive","Subtractive Cylinder")); + arc2->setToolTip(QApplication::translate("PartDesign_CompPrimitiveSubtractive","Create an subtractive cylinder by its radius, height and angle")); + arc2->setStatusTip(arc2->toolTip()); + QAction* arc3 = a[2]; + arc3->setText(QApplication::translate("CmdPrimtiveCompSubtractive","Subtractive Sphere")); + arc3->setToolTip(QApplication::translate("PartDesign_CompPrimitiveSubtractive","Create an subtractive sphere by its radius and varius angles")); + arc3->setStatusTip(arc3->toolTip()); } bool CmdPrimtiveCompSubtractive::isActive(void) diff --git a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc index 61020f7cd0..7aefa0afd3 100644 --- a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc +++ b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc @@ -18,6 +18,7 @@ icons/PartDesign_Plane.svg icons/PartDesign_Line.svg icons/PartDesign_Point.svg + icons/PartDesign_CoordinateSystem.svg icons/PartDesign_MoveTip.svg icons/Tree_PartDesign_Pad.svg icons/Tree_PartDesign_Revolution.svg @@ -26,6 +27,12 @@ icons/PartDesignWorkbench.svg icons/PartDesign_Body_Create_New.svg icons/PartDesign_Body_Tree.svg + icons/PartDesign_Additive_Box.svg + icons/PartDesign_Additive_Cylinder.svg + icons/PartDesign_Additive_Sphere.svg + icons/PartDesign_Subtractive_Box.svg + icons/PartDesign_Subtractive_Cylinder.svg + icons/PartDesign_Subtractive_Sphere.svg translations/PartDesign_af.qm translations/PartDesign_de.qm translations/PartDesign_fi.qm diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Box.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Box.svg new file mode 100644 index 0000000000..543fe77068 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Box.svg @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Cylinder.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Cylinder.svg new file mode 100644 index 0000000000..2365bf157e --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Cylinder.svg @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Sphere.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Sphere.svg new file mode 100644 index 0000000000..c41a68fe96 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Additive_Sphere.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_CoordinateSystem.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_CoordinateSystem.svg new file mode 100644 index 0000000000..6627724675 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_CoordinateSystem.svg @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Box.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Box.svg new file mode 100644 index 0000000000..7587dc94f6 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Box.svg @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Cylinder.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Cylinder.svg new file mode 100644 index 0000000000..7a14d74569 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Cylinder.svg @@ -0,0 +1,215 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Sphere.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Sphere.svg new file mode 100644 index 0000000000..67a73b5225 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Subtractive_Sphere.svg @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp new file mode 100644 index 0000000000..b04093ff72 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (c) 2015 Stefan Tröger * + * * + * 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 +#endif + +#include "TaskPrimitiveParameters.h" +#include "ViewProviderDatumCS.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace PartDesignGui; + +TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* PrimitiveView) +{ + + assert(PrimitiveView); + + PartDesign::FeaturePrimitive* prm = static_cast(PrimitiveView->getObject()); + cs = static_cast(prm->CoordinateSystem.getValue()); + + //if no coordinate system exist we need to add one, it is highly important that it exists! + if(!cs) { + std::string CSName = App::GetApplication().getActiveDocument()->getUniqueObjectName("CoordinateSystem"); + cs = static_cast( + App::GetApplication().getActiveDocument()->addObject("PartDesign::CoordinateSystem", CSName.c_str())); + prm->CoordinateSystem.setValue(cs); + } + + ViewProviderDatumCoordinateSystem* vp = static_cast( + Gui::Application::Instance->activeDocument()->getViewProvider(cs)); + + assert(vp); + cs_visibility = vp->isVisible(); + vp->Visibility.setValue(true); + parameter = new TaskDatumParameters(vp); + Content.push_back(parameter); +} + +TaskPrimitiveParameters::~TaskPrimitiveParameters() +{ + ViewProviderDatumCoordinateSystem* vp = static_cast( + Gui::Application::Instance->activeDocument()->getViewProvider(cs)); + vp->setVisible(cs_visibility); +} + +bool TaskPrimitiveParameters::accept() +{ + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + + return true; +} + +bool TaskPrimitiveParameters::reject() { + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + return true; +} + +QDialogButtonBox::StandardButtons TaskPrimitiveParameters::getStandardButtons(void) const { + return Gui::TaskView::TaskDialog::getStandardButtons(); +} + + +#include "moc_TaskPrimitiveParameters.cpp" \ No newline at end of file diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h new file mode 100644 index 0000000000..bf99ea8092 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (c) 2015 Stefan Tröger * + * * + * 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 GUI_TASKVIEW_TaskPrimitiveParameters_H +#define GUI_TASKVIEW_TaskPrimitiveParameters_H + +#include +#include +#include + +#include "TaskSketchBasedParameters.h" +#include "ViewProviderPrimitive.h" +#include "TaskDatumParameters.h" +#include +#include + +class Ui_TaskPrimitiveParameters; + +namespace App { +class Property; +} + +namespace Gui { +class ViewProvider; +} + +namespace PartDesignGui { + + +class TaskPrimitiveParameters : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskPrimitiveParameters(ViewProviderPrimitive *PrimitiveView); + ~TaskPrimitiveParameters(); + +protected: + virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const; + + virtual bool accept(); + virtual bool reject(); + +private: + PartGui::DlgPrimitives* widget; + TaskDatumParameters* parameter; + PartDesign::CoordinateSystem* cs; + bool cs_visibility; +}; + +} //namespace PartDesignGui + +#endif // GUI_TASKVIEW_TASKAPPERANCE_H diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp new file mode 100644 index 0000000000..54c2e581f2 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp @@ -0,0 +1,144 @@ +/*************************************************************************** + * Copyright (c) 2015 Stefan Tröger * + * * + * 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 +#endif + +#include "ViewProviderDatumCS.h" +#include "TaskDatumParameters.h" +#include "Workbench.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace PartDesignGui; + +PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumCoordinateSystem,PartDesignGui::ViewProviderDatum) + +ViewProviderDatumCoordinateSystem::ViewProviderDatumCoordinateSystem() +{ + sPixmap = "PartDesign_CoordinateSystem.svg"; + + SoMaterial* material = new SoMaterial(); + material->diffuseColor.setValue(0.9f, 0.9f, 0.13f); + material->transparency.setValue(0.5f); + pShapeSep->addChild(material); +} + +ViewProviderDatumCoordinateSystem::~ViewProviderDatumCoordinateSystem() +{ + +} + +void ViewProviderDatumCoordinateSystem::updateData(const App::Property* prop) +{ + if (strcmp(prop->getName(),"Placement") == 0) { + + + Base::Vector3d base(0,0,0); + Base::Vector3d dir(0,0,1); + Base::Vector3d x, y, z; + getPointForDirection(Base::Vector3d(1,0,0), x); + getPointForDirection(Base::Vector3d(0,1,0), y); + getPointForDirection(Base::Vector3d(0,0,1), z); + + + // Display the line + PartGui::SoBrepEdgeSet* lineSet; + SoCoordinate3* coord; + + if (pShapeSep->getNumChildren() == 1) { + coord = new SoCoordinate3(); + coord->point.setNum(4); + coord->point.set1Value(0, base.x, base.y, base.z); + coord->point.set1Value(1, x.x, x.y, x.z); + coord->point.set1Value(2, y.x, y.y, y.z); + coord->point.set1Value(3, z.x, z.y, z.z); + + pShapeSep->addChild(coord); + lineSet = new PartGui::SoBrepEdgeSet(); + lineSet->coordIndex.setNum(6); + lineSet->coordIndex.set1Value(0, 0); + lineSet->coordIndex.set1Value(1, 1); + lineSet->coordIndex.set1Value(2, 0); + lineSet->coordIndex.set1Value(3, 2); + lineSet->coordIndex.set1Value(4, 0); + lineSet->coordIndex.set1Value(5, 3); + pShapeSep->addChild(lineSet); + } else { + coord = static_cast(pShapeSep->getChild(1)); + coord->point.set1Value(0, base.x, base.y, base.z); + coord->point.set1Value(1, x.x, x.y, x.z); + coord->point.set1Value(2, y.x, y.y, y.z); + coord->point.set1Value(3, z.x, z.y, z.z); + } + } + + ViewProviderDatum::updateData(prop); +} + +void ViewProviderDatumCoordinateSystem::getPointForDirection(Base::Vector3d dir, Base::Vector3d& p) { + + // Gets called whenever a property of the attached object changes + PartDesign::CoordinateSystem* pcDatum = static_cast(this->getObject()); + Base::Placement plm = pcDatum->Placement.getValue(); + plm.invert(); + + Base::Vector3d base(0,0,0); + // Get limits of the line from bounding box of the body + PartDesign::Body* body = static_cast(Part::BodyBase::findBodyOf(this->getObject())); + if (body == NULL) + return; + Base::BoundBox3d bbox = body->getBoundBox(); + bbox = bbox.Transformed(plm.toMatrix()); + bbox.Enlarge(0.1 * bbox.CalcDiagonalLength()); + if (bbox.IsInBox(base)) { + bbox.IntersectionPoint(base, dir, p, Precision::Confusion()); + } else { + Base::Vector3d p2; + if(!bbox.IntersectWithLine(base, dir, p, p2)) { + p = dir*bbox.CalcDiagonalLength(); + } + } +} + diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumCS.h b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.h new file mode 100644 index 0000000000..3b0bc1a2f2 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (c) 2015 Stefan Tröger * + * * + * 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 PARTGUI_ViewProviderDatumCoordinateSystem_H +#define PARTGUI_ViewProviderDatumCoordinateSystem_H + +#include "Gui/ViewProviderGeometryObject.h" +#include "ViewProviderDatum.h" + +namespace PartDesignGui { + +class PartDesignGuiExport ViewProviderDatumCoordinateSystem : public PartDesignGui::ViewProviderDatum +{ + PROPERTY_HEADER(PartDesignGui::ViewProviderDatumCoordinateSystem); + +public: + /// Constructor + ViewProviderDatumCoordinateSystem(); + virtual ~ViewProviderDatumCoordinateSystem(); + + virtual void updateData(const App::Property*); + +private: + void getPointForDirection(Base::Vector3d Dir, Base::Vector3d& p); +}; + +} // namespace PartDesignGui + + +#endif // PARTGUI_ViewProviderDatumCoordinateSystem_H diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp index 010f0ea3b0..9a4a5d9da9 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp @@ -55,6 +55,8 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumLine,PartDesignGui::ViewProvider ViewProviderDatumLine::ViewProviderDatumLine() { + sPixmap = "PartDesign_Line.svg"; + SoMaterial* material = new SoMaterial(); material->diffuseColor.setValue(0.9f, 0.9f, 0.13f); material->transparency.setValue(0.2f); diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp index 4519e714db..d646556404 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp @@ -56,6 +56,8 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumPlane,PartDesignGui::ViewProvide ViewProviderDatumPlane::ViewProviderDatumPlane() { + sPixmap = "PartDesign_Plane.svg"; + SoMaterial* material = new SoMaterial(); material->diffuseColor.setValue(0.9f, 0.9f, 0.13f); material->transparency.setValue(0.5f); diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp index b5ad2eaa05..9aa9ac0941 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp @@ -41,6 +41,8 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumPoint,PartDesignGui::ViewProvide ViewProviderDatumPoint::ViewProviderDatumPoint() { + sPixmap = "PartDesign_Point.svg"; + SoMFVec3f v; v.setNum(1); v.set1Value(0, 0,0,0); diff --git a/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp b/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp index 1c4b39df0e..6a33dfa938 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -43,7 +44,7 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderPrimitive,PartDesignGui::ViewProvider ViewProviderPrimitive::ViewProviderPrimitive() { - sPixmap = "Part_Box.svg"; + } ViewProviderPrimitive::~ViewProviderPrimitive() @@ -94,10 +95,35 @@ bool ViewProviderPrimitive::setEdit(int ModNum) std::vector< App::DocumentObject* > ViewProviderPrimitive::claimChildren(void) const { -// Base::Console().Message("claim children\n"); std::vector< App::DocumentObject* > vec; vec.push_back(static_cast(getObject())->CoordinateSystem.getValue()); return vec; } +QIcon ViewProviderPrimitive::getIcon(void) const { + + QString str = QString::fromAscii("PartDesign_"); + auto* prim = static_cast(getObject()); + if(prim->getAddSubType() == PartDesign::FeatureAddSub::Additive) + str += QString::fromAscii("Additive_"); + else + str += QString::fromAscii("Subtractive_"); + + switch(prim->getPrimitiveType()) { + + case PartDesign::FeaturePrimitive::Box: + str += QString::fromAscii("Box"); + break; + case PartDesign::FeaturePrimitive::Cylinder: + str += QString::fromAscii("Cylinder"); + break; + case PartDesign::FeaturePrimitive::Sphere: + str += QString::fromAscii("Sphere"); + break; + } + + str += QString::fromAscii(".svg"); + return Gui::BitmapFactory().pixmap(str.toStdString().c_str()); +} + diff --git a/src/Mod/PartDesign/Gui/ViewProviderPrimitive.h b/src/Mod/PartDesign/Gui/ViewProviderPrimitive.h index 106688aef1..d1d2f68215 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPrimitive.h +++ b/src/Mod/PartDesign/Gui/ViewProviderPrimitive.h @@ -42,7 +42,8 @@ public: virtual std::vector< App::DocumentObject* > claimChildren(void) const; protected: - virtual bool setEdit(int ModNum); + virtual QIcon getIcon(void) const; + virtual bool setEdit(int ModNum); }; } // namespace PartDesignGui diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 2e2975aa6a..180367b3c7 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -742,12 +742,13 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "PartDesign_Line" << "PartDesign_Point" << "Separator" + << "PartDesign_CompPrimitiveAdditive" + << "PartDesign_CompPrimitiveSubtractive" + << "Separator" << "PartDesign_Pad" << "PartDesign_Pocket" << "PartDesign_Revolution" << "PartDesign_Groove" - << "PartDesign_CompPrimitiveAdditive" - << "PartDesign_CompPrimitiveSubtractive" << "PartDesign_Fillet" << "PartDesign_Chamfer" << "PartDesign_Draft"