From c3f35d9f05b28300187868ef3749808e12ebbb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Thu, 21 May 2015 07:10:40 +0200 Subject: [PATCH] add part design thickness --- src/Mod/Part/App/PartFeatures.cpp | 4 +- src/Mod/PartDesign/App/AppPartDesign.cpp | 30 +- src/Mod/PartDesign/App/CMakeLists.txt | 2 + src/Mod/PartDesign/App/FeatureThickness.cpp | 96 +++++++ src/Mod/PartDesign/App/FeatureThickness.h | 65 +++++ src/Mod/PartDesign/Gui/AppPartDesignGui.cpp | 2 + src/Mod/PartDesign/Gui/CMakeLists.txt | 7 + src/Mod/PartDesign/Gui/Command.cpp | 103 +++++++ .../PartDesign/Gui/Resources/PartDesign.qrc | 1 + .../Resources/icons/PartDesign_Thickness.svg | 243 ++++++++++++++++ .../Gui/TaskThicknessParameters.cpp | 260 ++++++++++++++++++ .../PartDesign/Gui/TaskThicknessParameters.h | 79 ++++++ .../PartDesign/Gui/TaskThicknessParameters.ui | 139 ++++++++++ .../PartDesign/Gui/ViewProviderThickness.cpp | 69 +++++ .../PartDesign/Gui/ViewProviderThickness.h | 49 ++++ src/Mod/PartDesign/Gui/Workbench.cpp | 4 + 16 files changed, 1136 insertions(+), 17 deletions(-) create mode 100644 src/Mod/PartDesign/App/FeatureThickness.cpp create mode 100644 src/Mod/PartDesign/App/FeatureThickness.h create mode 100644 src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Thickness.svg create mode 100644 src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp create mode 100644 src/Mod/PartDesign/Gui/TaskThicknessParameters.h create mode 100644 src/Mod/PartDesign/Gui/TaskThicknessParameters.ui create mode 100644 src/Mod/PartDesign/Gui/ViewProviderThickness.cpp create mode 100644 src/Mod/PartDesign/Gui/ViewProviderThickness.h diff --git a/src/Mod/Part/App/PartFeatures.cpp b/src/Mod/Part/App/PartFeatures.cpp index df477375b..adc038d1d 100644 --- a/src/Mod/Part/App/PartFeatures.cpp +++ b/src/Mod/Part/App/PartFeatures.cpp @@ -542,14 +542,12 @@ PROPERTY_SOURCE(Part::Thickness, Part::Feature) Thickness::Thickness() { - ADD_PROPERTY_TYPE(Faces,(0),"Thickness",App::Prop_None,"Source shape"); + ADD_PROPERTY_TYPE(Faces,(0),"Thickness",App::Prop_None,"Faces to be removed"); ADD_PROPERTY_TYPE(Value,(1.0),"Thickness",App::Prop_None,"Thickness value"); ADD_PROPERTY_TYPE(Mode,(long(0)),"Thickness",App::Prop_None,"Mode"); Mode.setEnums(ModeEnums); ADD_PROPERTY_TYPE(Join,(long(0)),"Thickness",App::Prop_None,"Join type"); Join.setEnums(JoinEnums); - ADD_PROPERTY_TYPE(Intersection,(false),"Thickness",App::Prop_None,"Intersection"); - ADD_PROPERTY_TYPE(SelfIntersection,(false),"Thickness",App::Prop_None,"Self Intersection"); } short Thickness::mustExecute() const diff --git a/src/Mod/PartDesign/App/AppPartDesign.cpp b/src/Mod/PartDesign/App/AppPartDesign.cpp index 9cef7d2f6..89e9573aa 100644 --- a/src/Mod/PartDesign/App/AppPartDesign.cpp +++ b/src/Mod/PartDesign/App/AppPartDesign.cpp @@ -53,6 +53,7 @@ #include "FeatureBoolean.h" #include "FeaturePrimitive.h" #include "DatumCS.h" +#include "FeatureThickness.h" namespace PartDesign { extern PyObject* initModule(); @@ -99,6 +100,7 @@ PyMODINIT_FUNC init_PartDesign() PartDesign::Groove ::init(); PartDesign::Chamfer ::init(); PartDesign::Draft ::init(); + PartDesign::Thickness ::init(); PartDesign::Plane ::init(); PartDesign::Line ::init(); PartDesign::Point ::init(); @@ -114,21 +116,21 @@ PyMODINIT_FUNC init_PartDesign() PartDesign::Sphere ::init(); PartDesign::AdditiveSphere ::init(); PartDesign::SubtractiveSphere ::init(); - PartDesign::Cone ::init(); - PartDesign::AdditiveCone ::init(); - PartDesign::SubtractiveCone ::init(); - PartDesign::Ellipsoid ::init(); - PartDesign::AdditiveEllipsoid ::init(); + PartDesign::Cone ::init(); + PartDesign::AdditiveCone ::init(); + PartDesign::SubtractiveCone ::init(); + PartDesign::Ellipsoid ::init(); + PartDesign::AdditiveEllipsoid ::init(); PartDesign::SubtractiveEllipsoid ::init(); - PartDesign::Torus ::init(); - PartDesign::AdditiveTorus ::init(); - PartDesign::SubtractiveTorus ::init(); - PartDesign::Prism ::init(); - PartDesign::AdditivePrism ::init(); - PartDesign::SubtractivePrism ::init(); - PartDesign::Wedge ::init(); - PartDesign::AdditiveWedge ::init(); - PartDesign::SubtractiveWedge ::init(); + PartDesign::Torus ::init(); + PartDesign::AdditiveTorus ::init(); + PartDesign::SubtractiveTorus ::init(); + PartDesign::Prism ::init(); + PartDesign::AdditivePrism ::init(); + PartDesign::SubtractivePrism ::init(); + PartDesign::Wedge ::init(); + PartDesign::AdditiveWedge ::init(); + PartDesign::SubtractiveWedge ::init(); PartDesign::Point ::initHints(); PartDesign::Line ::initHints(); diff --git a/src/Mod/PartDesign/App/CMakeLists.txt b/src/Mod/PartDesign/App/CMakeLists.txt index 6cf9b899e..af9d0efa3 100644 --- a/src/Mod/PartDesign/App/CMakeLists.txt +++ b/src/Mod/PartDesign/App/CMakeLists.txt @@ -76,6 +76,8 @@ SET(FeaturesDressUp_SRCS FeatureChamfer.h FeatureDraft.cpp FeatureDraft.h + FeatureThickness.cpp + FeatureThickness.h ) SOURCE_GROUP("DressUpFeatures" FILES ${FeaturesDressUp_SRCS}) diff --git a/src/Mod/PartDesign/App/FeatureThickness.cpp b/src/Mod/PartDesign/App/FeatureThickness.cpp new file mode 100644 index 000000000..81891512c --- /dev/null +++ b/src/Mod/PartDesign/App/FeatureThickness.cpp @@ -0,0 +1,96 @@ +/*************************************************************************** + * 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 "FeatureThickness.h" +#include +#include +#include + +using namespace PartDesign; + +const char* PartDesign::Thickness::ModeEnums[] = {"Skin","Pipe", "RectoVerso",NULL}; +const char* PartDesign::Thickness::JoinEnums[] = {"Arc", "Intersection",NULL}; + +namespace PartDesign { + const App::PropertyQuantityConstraint::Constraints quantityRange = {0.0,FLT_MAX,0.1}; +} + +PROPERTY_SOURCE(PartDesign::Thickness, PartDesign::DressUp) + +Thickness::Thickness() +{ + ADD_PROPERTY_TYPE(Value,(1.0),"Thickness",App::Prop_None,"Thickness value"); + ADD_PROPERTY_TYPE(Mode,(long(0)),"Thickness",App::Prop_None,"Mode"); + Mode.setEnums(ModeEnums); + ADD_PROPERTY_TYPE(Join,(long(0)),"Thickness",App::Prop_None,"Join type"); + Join.setEnums(JoinEnums); + ADD_PROPERTY_TYPE(Reversed,(false),"Thickness",App::Prop_None,"Apply the thickness towards the solids interior"); +} + +short Thickness::mustExecute() const +{ + if (Placement.isTouched() || + Value.isTouched() || + Mode.isTouched() || + Join.isTouched()) + return 1; + return DressUp::mustExecute(); +} + +App::DocumentObjectExecReturn *Thickness::execute(void) +{ + // Base shape + Part::TopoShape TopShape; + try { + TopShape = getBaseShape(); + } catch (Base::Exception& e) { + return new App::DocumentObjectExecReturn(e.what()); + } + + TopTools_ListOfShape closingFaces; + const std::vector& subStrings = Base.getSubValues(); + for (std::vector::const_iterator it = subStrings.begin(); it != subStrings.end(); ++it) { + TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(it->c_str())); + closingFaces.Append(face); + } + + bool reversed = Reversed.getValue(); + double thickness = (reversed ? -1. : 1. )*Value.getValue(); + double tol = Precision::Confusion(); + short mode = (short)Mode.getValue(); + short join = (short)Join.getValue(); + //we do not offer tangent join type + if(join == 1) + join = 2; + + if (fabs(thickness) > 2*tol) + this->Shape.setValue(TopShape.makeThickSolid(closingFaces, thickness, tol, false, false, mode, join)); + else + this->Shape.setValue(TopShape._Shape); + return App::DocumentObject::StdReturn; +} diff --git a/src/Mod/PartDesign/App/FeatureThickness.h b/src/Mod/PartDesign/App/FeatureThickness.h new file mode 100644 index 000000000..20c323dea --- /dev/null +++ b/src/Mod/PartDesign/App/FeatureThickness.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_FEATURETHICKNESS_H +#define PARTDESIGN_FEATURETHICKNESS_H + +#include +#include +#include +#include "FeatureDressUp.h" + +namespace PartDesign +{ + +class PartDesignExport Thickness : public DressUp +{ + PROPERTY_HEADER(PartDesign::Thickness); + +public: + Thickness(); + + App::PropertyLength Value; + App::PropertyBool Reversed; + App::PropertyEnumeration Mode; + App::PropertyEnumeration Join; + + /** @name methods override feature */ + //@{ + /// recalculate the feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + /// returns the type name of the view provider + const char* getViewProviderName(void) const { + return "PartDesignGui::ViewProviderThickness"; + } + //@} +private: + static const char* ModeEnums[]; + static const char* JoinEnums[]; +}; + +} //namespace PartDesign + + +#endif // PARTDESIGN_FEATURETHICKNESS_H diff --git a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp index cbc433bba..29ef11657 100644 --- a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp +++ b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp @@ -56,6 +56,7 @@ #include "ViewProviderBoolean.h" #include "ViewProviderPrimitive.h" #include "ViewProviderDatumCS.h" +#include "ViewProviderThickness.h" // use a different name to CreateCommand() void CreatePartDesignCommands(void); @@ -125,6 +126,7 @@ PyMODINIT_FUNC initPartDesignGui() PartDesignGui::ViewProviderChamfer ::init(); PartDesignGui::ViewProviderFillet ::init(); PartDesignGui::ViewProviderDraft ::init(); + PartDesignGui::ViewProviderThickness ::init(); PartDesignGui::ViewProviderTransformed ::init(); PartDesignGui::ViewProviderMirrored ::init(); PartDesignGui::ViewProviderLinearPattern ::init(); diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index ffe454e5e..dae533040 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -35,6 +35,7 @@ set(PartDesignGui_MOC_HDRS TaskChamferParameters.h TaskFilletParameters.h TaskDraftParameters.h + TaskThicknessParameters.h TaskDressUpParameters.h TaskHoleParameters.h TaskRevolutionParameters.h @@ -62,6 +63,7 @@ set(PartDesignGui_UIC_SRCS TaskChamferParameters.ui TaskFilletParameters.ui TaskDraftParameters.ui + TaskThicknessParameters.ui TaskBooleanParameters.ui TaskHoleParameters.ui TaskRevolutionParameters.ui @@ -94,6 +96,8 @@ SET(PartDesignGuiViewProvider_SRCS CommandPrimitive.cpp ViewProviderFillet.h ViewProviderDraft.cpp ViewProviderDraft.h + ViewProviderThickness.cpp + ViewProviderThickness.h ViewProviderDressUp.cpp ViewProviderDressUp.h ViewProviderRevolution.cpp @@ -152,6 +156,9 @@ SET(PartDesignGuiTaskDlgs_SRCS TaskDraftParameters.ui TaskDraftParameters.cpp TaskDraftParameters.h + TaskThicknessParameters.ui + TaskThicknessParameters.cpp + TaskThicknessParameters.h TaskDressUpParameters.cpp TaskDressUpParameters.h TaskRevolutionParameters.ui diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 67705ddde..dd5484f30 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -1468,6 +1468,108 @@ bool CmdPartDesignDraft::isActive(void) return hasActiveDocument(); } + +//=========================================================================== +// PartDesign_Thickness +//=========================================================================== +DEF_STD_CMD_A(CmdPartDesignThickness); + +CmdPartDesignThickness::CmdPartDesignThickness() + :Command("PartDesign_Thickness") +{ + sAppModule = "PartDesign"; + sGroup = QT_TR_NOOP("PartDesign"); + sMenuText = QT_TR_NOOP("Thickness"); + sToolTipText = QT_TR_NOOP("Make a thick solid"); + sWhatsThis = "PartDesign_Thickness"; + sStatusTip = sToolTipText; + sPixmap = "PartDesign_Thickness"; +} + +void CmdPartDesignThickness::activated(int iMsg) +{ + PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true); + if (!pcActiveBody) return; + + std::vector selection = getSelection().getSelectionEx(); + + if (selection.size() < 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select one or more faces.")); + return; + } + + if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), + QObject::tr("Thickness works only on parts")); + return; + } + + Part::Feature *base = static_cast(selection[0].getObject()); + + if (base != pcActiveBody->getPrevSolidFeature(NULL, true)) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong base feature"), + QObject::tr("Only the current Tip of the active Body can be selected as the base feature")); + return; + } + + const Part::TopoShape& TopShape = base->Shape.getShape(); + if (TopShape._Shape.IsNull()){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Shape of selected Part is empty")); + return; + } + + std::vector SubNames = std::vector(selection[0].getSubNames()); + unsigned int i = 0; + + while(i < SubNames.size()) + { + std::string aSubName = static_cast(SubNames.at(i)); + + if(aSubName.size() > 4 && aSubName.substr(0,4) != "Face") { + // empty name or any other sub-element + SubNames.erase(SubNames.begin()+i); + } + i++; + } + + if (SubNames.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("No thickness possible with selected faces")); + return; + } + + std::string SelString; + SelString += "(App."; + SelString += "ActiveDocument"; + SelString += "."; + SelString += selection[0].getFeatName(); + SelString += ",["; + for(std::vector::const_iterator it = SubNames.begin();it!=SubNames.end();++it){ + SelString += "\""; + SelString += *it; + SelString += "\""; + if(it != --SubNames.end()) + SelString += ","; + } + SelString += "])"; + + std::string FeatName = getUniqueObjectName("Thickness"); + + openCommand("Make Thickness"); + doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Thickness\",\"%s\")",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str()); + doCommand(Doc,"App.activeDocument().%s.Value = %f",FeatName.c_str(), 1.); + + finishFeature(this, FeatName); +} + +bool CmdPartDesignThickness::isActive(void) +{ + return hasActiveDocument(); +} + //=========================================================================== // Common functions for all Transformed features //=========================================================================== @@ -1930,6 +2032,7 @@ void CreatePartDesignCommands(void) rcCmdMgr.addCommand(new CmdPartDesignFillet()); rcCmdMgr.addCommand(new CmdPartDesignDraft()); rcCmdMgr.addCommand(new CmdPartDesignChamfer()); + rcCmdMgr.addCommand(new CmdPartDesignThickness()); rcCmdMgr.addCommand(new CmdPartDesignMirrored()); rcCmdMgr.addCommand(new CmdPartDesignLinearPattern()); diff --git a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc index 73f48e9ef..31d824b76 100644 --- a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc +++ b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc @@ -3,6 +3,7 @@ icons/PartDesign_Chamfer.svg icons/PartDesign_Fillet.svg icons/PartDesign_Draft.svg + icons/PartDesign_Thickness.svg icons/PartDesign_Groove.svg icons/PartDesign_Pad.svg icons/PartDesign_Pocket.svg diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Thickness.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Thickness.svg new file mode 100644 index 000000000..db7357e54 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_Thickness.svg @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp b/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp new file mode 100644 index 000000000..df69dac1c --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp @@ -0,0 +1,260 @@ +/*************************************************************************** + * 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 "ui_TaskThicknessParameters.h" +#include "TaskThicknessParameters.h" +#include "Workbench.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace PartDesignGui; +using namespace Gui; + +/* TRANSLATOR PartDesignGui::TaskThicknessParameters */ + +TaskThicknessParameters::TaskThicknessParameters(ViewProviderDressUp *DressUpView,QWidget *parent) + : TaskDressUpParameters(DressUpView, false, true, parent) +{ + // we need a separate container widget to add all controls to + proxy = new QWidget(this); + ui = new Ui_TaskThicknessParameters(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + connect(ui->Value, SIGNAL(valueChanged(double)), + this, SLOT(onValueChanged(double))); + connect(ui->checkReverse, SIGNAL(toggled(bool)), + this, SLOT(onReversedChanged(bool))); + connect(ui->buttonRefAdd, SIGNAL(toggled(bool)), + this, SLOT(onButtonRefAdd(bool))); + connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), + this, SLOT(onButtonRefRemove(bool))); + connect(ui->modeComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(onModeChanged(int))); + connect(ui->joinComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(onJoinTypeChanged(int))); + + this->groupLayout()->addWidget(proxy); + + PartDesign::Thickness* pcThickness = static_cast(DressUpView->getObject()); + double a = pcThickness->Value.getValue(); + + ui->Value->setMinimum(0.0); + ui->Value->setMaximum(89.99); + ui->Value->setValue(a); + ui->Value->selectAll(); + QMetaObject::invokeMethod(ui->Value, "setFocus", Qt::QueuedConnection); + + bool r = pcThickness->Reversed.getValue(); + ui->checkReverse->setChecked(r); + + std::vector strings = pcThickness->Base.getSubValues(); + for (std::vector::const_iterator i = strings.begin(); i != strings.end(); i++) + { + ui->listWidgetReferences->addItem(QString::fromStdString(*i)); + } + // Create context menu + QAction* action = new QAction(tr("Remove"), this); + ui->listWidgetReferences->addAction(action); + connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted())); + ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); + + int mode = pcThickness->Mode.getValue(); + ui->modeComboBox->setCurrentIndex(mode); + + int join = pcThickness->Join.getValue(); + ui->modeComboBox->setCurrentIndex(join); +} + +void TaskThicknessParameters::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if (selectionMode == none) + return; + + if (msg.Type == Gui::SelectionChanges::AddSelection) { + if (referenceSelected(msg)) { + if (selectionMode == refAdd) + ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName)); + else + removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName); + clearButtons(none); + exitSelectionMode(); + } + } +} + +void TaskThicknessParameters::clearButtons(const selectionModes notThis) +{ + if (notThis != refAdd) ui->buttonRefAdd->setChecked(false); + if (notThis != refRemove) ui->buttonRefRemove->setChecked(false); + DressUpView->highlightReferences(false); +} + +void TaskThicknessParameters::onRefDeleted(void) +{ + PartDesign::Thickness* pcThickness = static_cast(DressUpView->getObject()); + App::DocumentObject* base = pcThickness->Base.getValue(); + std::vector faces = pcThickness->Base.getSubValues(); + faces.erase(faces.begin() + ui->listWidgetReferences->currentRow()); + pcThickness->Base.setValue(base, faces); + ui->listWidgetReferences->model()->removeRow(ui->listWidgetReferences->currentRow()); + pcThickness->getDocument()->recomputeFeature(pcThickness); +} + +void TaskThicknessParameters::onValueChanged(double angle) +{ + clearButtons(none); + PartDesign::Thickness* pcThickness = static_cast(DressUpView->getObject()); + pcThickness->Value.setValue(angle); + pcThickness->getDocument()->recomputeFeature(pcThickness); +} + +void TaskThicknessParameters::onJoinTypeChanged(int join) { + + clearButtons(none); + PartDesign::Thickness* pcThickness = static_cast(DressUpView->getObject()); + pcThickness->Join.setValue(join); + pcThickness->getDocument()->recomputeFeature(pcThickness); +} + +void TaskThicknessParameters::onModeChanged(int mode) { + + clearButtons(none); + PartDesign::Thickness* pcThickness = static_cast(DressUpView->getObject()); + pcThickness->Mode.setValue(mode); + pcThickness->getDocument()->recomputeFeature(pcThickness); +} + + +const double TaskThicknessParameters::getValue(void) const +{ + return ui->Value->value().getValue(); +} + +void TaskThicknessParameters::onReversedChanged(const bool on) { + clearButtons(none); + PartDesign::Thickness* pcThickness = static_cast(DressUpView->getObject()); + pcThickness->Reversed.setValue(on); + pcThickness->getDocument()->recomputeFeature(pcThickness); +} + +const bool TaskThicknessParameters::getReversed(void) const +{ + return ui->checkReverse->isChecked(); +} + +const int TaskThicknessParameters::getJoinType(void) const { + + return ui->joinComboBox->currentIndex(); +} + +const int TaskThicknessParameters::getMode(void) const { + + return ui->modeComboBox->currentIndex(); +} + + +TaskThicknessParameters::~TaskThicknessParameters() +{ + Gui::Selection().rmvSelectionGate(); + delete ui; +} + +void TaskThicknessParameters::changeEvent(QEvent *e) +{ + TaskBox::changeEvent(e); + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(proxy); + } +} + + +//************************************************************************** +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgThicknessParameters::TaskDlgThicknessParameters(ViewProviderThickness *DressUpView) + : TaskDlgDressUpParameters(DressUpView) +{ + parameter = new TaskThicknessParameters(DressUpView); + + Content.push_back(parameter); +} + +TaskDlgThicknessParameters::~TaskDlgThicknessParameters() +{ + +} + +//==== calls from the TaskView =============================================================== + + +//void TaskDlgThicknessParameters::open() +//{ +// // a transaction is already open at creation time of the draft +// if (!Gui::Command::hasPendingCommand()) { +// QString msg = QObject::tr("Edit draft"); +// Gui::Command::openCommand((const char*)msg.toUtf8()); +// } +//} +// +//void TaskDlgThicknessParameters::clicked(int) +//{ +// +//} + +bool TaskDlgThicknessParameters::accept() +{ + parameter->showObject(); + + TaskThicknessParameters* draftparameter = static_cast(parameter); + + std::string name = DressUpView->getObject()->getNameInDocument(); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Value = %f",name.c_str(),draftparameter->getValue()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Mode = %u",name.c_str(),draftparameter->getMode()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Join = %u",name.c_str(),draftparameter->getJoinType()); + + return TaskDlgDressUpParameters::accept(); +} + +#include "moc_TaskThicknessParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskThicknessParameters.h b/src/Mod/PartDesign/Gui/TaskThicknessParameters.h new file mode 100644 index 000000000..b6b959c08 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskThicknessParameters.h @@ -0,0 +1,79 @@ +/*************************************************************************** + * 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_TaskThicknessParameters_H +#define GUI_TASKVIEW_TaskThicknessParameters_H + +#include "TaskDressUpParameters.h" +#include "ViewProviderThickness.h" + +class Ui_TaskThicknessParameters; + +namespace PartDesignGui { + +class TaskThicknessParameters : public TaskDressUpParameters +{ + Q_OBJECT + +public: + TaskThicknessParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0); + ~TaskThicknessParameters(); + + const double getValue(void) const; + const bool getReversed(void) const; + const int getMode(void) const; + const int getJoinType(void) const; + +private Q_SLOTS: + void onValueChanged(double angle); + void onModeChanged(int mode); + void onJoinTypeChanged(int join); + void onReversedChanged(bool reversed); + void onRefDeleted(void); + +protected: + virtual void clearButtons(const selectionModes notThis); + void changeEvent(QEvent *e); + virtual void onSelectionChanged(const Gui::SelectionChanges& msg); + +private: + Ui_TaskThicknessParameters* ui; +}; + +/// simulation dialog for the TaskView +class TaskDlgThicknessParameters : public TaskDlgDressUpParameters +{ + Q_OBJECT + +public: + TaskDlgThicknessParameters(ViewProviderThickness *ThicknessView); + ~TaskDlgThicknessParameters(); + +public: + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); +}; + +} //namespace PartDesignGui + +#endif // GUI_TASKVIEW_TASKAPPERANCE_H diff --git a/src/Mod/PartDesign/Gui/TaskThicknessParameters.ui b/src/Mod/PartDesign/Gui/TaskThicknessParameters.ui new file mode 100644 index 000000000..338b76440 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskThicknessParameters.ui @@ -0,0 +1,139 @@ + + + PartDesignGui::TaskThicknessParameters + + + + 0 + 0 + 321 + 509 + + + + Form + + + + + + + + Add face + + + true + + + + + + + Remove face + + + true + + + + + + + + + + + + + + Draft angle + + + + + + + mm + + + 0.000000000000000 + + + 999999999.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + Mode + + + + + + + Join Type + + + + + + + + Skin + + + + + Pipe + + + + + Recto Verso + + + + + + + + + Arc + + + + + Intersection + + + + + + + + + + Make thickness inwards + + + + + + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+
+ + +
diff --git a/src/Mod/PartDesign/Gui/ViewProviderThickness.cpp b/src/Mod/PartDesign/Gui/ViewProviderThickness.cpp new file mode 100644 index 000000000..f7d3f7da2 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderThickness.cpp @@ -0,0 +1,69 @@ +/*************************************************************************** + * 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 +#endif + +#include "ViewProviderThickness.h" +#include "TaskThicknessParameters.h" +#include +#include +#include +#include +#include + + +using namespace PartDesignGui; + +PROPERTY_SOURCE(PartDesignGui::ViewProviderThickness,PartDesignGui::ViewProviderDressUp) + +bool ViewProviderThickness::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default ) { + TaskDlgDressUpParameters *dressUpDlg = NULL; + + if (checkDlgOpen(dressUpDlg)) { + // always change to PartDesign WB, remember where we come from + oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench"); + + // start the edit dialog + if (dressUpDlg) + Gui::Control().showDialog(dressUpDlg); + else + Gui::Control().showDialog(new TaskDlgThicknessParameters(this)); + + return true; + } else { + return false; + } + } + else { + return ViewProviderDressUp::setEdit(ModNum); + } +} + + diff --git a/src/Mod/PartDesign/Gui/ViewProviderThickness.h b/src/Mod/PartDesign/Gui/ViewProviderThickness.h new file mode 100644 index 000000000..ef1216c85 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderThickness.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * 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_ViewProviderThickness_H +#define PARTGUI_ViewProviderThickness_H + +#include "ViewProviderDressUp.h" + + +namespace PartDesignGui { + +class PartDesignGuiExport ViewProviderThickness : public ViewProviderDressUp +{ + PROPERTY_HEADER(PartDesignGui::ViewProviderThickness); + +public: + /// constructor + ViewProviderThickness() + { featureName = std::string("Thickness"); + sPixmap = "PartDesign_Thickness.svg"; } + +protected: + virtual bool setEdit(int ModNum); +}; + +} // namespace PartDesignGui + + +#endif // PARTGUI_ViewProviderThickness_H diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 180367b3c..2aee6736e 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -494,6 +494,7 @@ void Workbench::activated() "PartDesign_Fillet", "PartDesign_Chamfer", "PartDesign_Draft", + "PartDesign_Thickness", "PartDesign_Plane", "PartDesign_Line", "PartDesign_Point", @@ -587,6 +588,7 @@ void Workbench::activated() "PartDesign_Fillet", "PartDesign_Chamfer", "PartDesign_Draft", + "PartDesign_Thickness", 0}; Watcher.push_back(new Gui::TaskView::TaskWatcherCommands( "SELECT Part::Feature SUBELEMENT Face COUNT 2..", @@ -698,6 +700,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "PartDesign_Fillet" << "PartDesign_Chamfer" << "PartDesign_Draft" + << "PartDesign_Thickness" << "PartDesign_Mirrored" << "PartDesign_LinearPattern" << "PartDesign_PolarPattern" @@ -752,6 +755,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "PartDesign_Fillet" << "PartDesign_Chamfer" << "PartDesign_Draft" + << "PartDesign_Thickness" << "PartDesign_Mirrored" << "PartDesign_LinearPattern" << "PartDesign_PolarPattern"