From 16b457866721ecf7f512ce36e75f9b80500861ff Mon Sep 17 00:00:00 2001 From: logari81 Date: Tue, 13 Dec 2011 19:32:19 +0000 Subject: [PATCH] + synchronize PartDesign/Chamfer version with PartDesign/Fillet git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5299 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 33 +- src/Mod/PartDesign/App/FeatureChamfer.h | 4 +- src/Mod/PartDesign/App/FeatureFillet.cpp | 2 +- src/Mod/PartDesign/App/FeatureFillet.h | 2 +- src/Mod/PartDesign/Gui/AppPartDesignGui.cpp | 2 +- src/Mod/PartDesign/Gui/CMakeLists.txt | 12 +- src/Mod/PartDesign/Gui/Command.cpp | 33 +- src/Mod/PartDesign/Gui/Makefile.am | 12 +- src/Mod/PartDesign/Gui/TaskChamfer.cpp | 618 ------------------ src/Mod/PartDesign/Gui/TaskChamfer.h | 135 ---- src/Mod/PartDesign/Gui/TaskChamfer.ui | 172 ----- .../PartDesign/Gui/TaskChamferParameters.cpp | 166 +++++ .../PartDesign/Gui/TaskChamferParameters.h | 108 +++ .../PartDesign/Gui/TaskChamferParameters.ui | 42 ++ src/Mod/PartDesign/Gui/TaskFilletParameters.h | 11 +- .../PartDesign/Gui/ViewProviderChamfer.cpp | 130 ++++ src/Mod/PartDesign/Gui/ViewProviderChamfer.h | 58 ++ 17 files changed, 581 insertions(+), 959 deletions(-) delete mode 100644 src/Mod/PartDesign/Gui/TaskChamfer.cpp delete mode 100644 src/Mod/PartDesign/Gui/TaskChamfer.h delete mode 100644 src/Mod/PartDesign/Gui/TaskChamfer.ui create mode 100644 src/Mod/PartDesign/Gui/TaskChamferParameters.cpp create mode 100644 src/Mod/PartDesign/Gui/TaskChamferParameters.h create mode 100644 src/Mod/PartDesign/Gui/TaskChamferParameters.ui create mode 100644 src/Mod/PartDesign/Gui/ViewProviderChamfer.cpp create mode 100644 src/Mod/PartDesign/Gui/ViewProviderChamfer.h diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index f984b8c1d..bcda59bcb 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -23,9 +23,13 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include +# include # include # include # include +# include +# include #endif #include @@ -37,10 +41,13 @@ using namespace PartDesign; PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp) + +const App::PropertyFloatConstraint::Constraints floatSize = {0.0f,FLT_MAX,0.1f}; Chamfer::Chamfer() { ADD_PROPERTY(Size,(1.0f)); + Size.setConstraints(&floatSize); } short Chamfer::mustExecute() const @@ -54,29 +61,41 @@ short Chamfer::mustExecute() const App::DocumentObjectExecReturn *Chamfer::execute(void) { - /* App::DocumentObject* link = Base.getValue(); + App::DocumentObject* link = Base.getValue(); if (!link) return new App::DocumentObjectExecReturn("No object linked"); if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) return new App::DocumentObjectExecReturn("Linked object is not a Part object"); Part::Feature *base = static_cast(Base.getValue()); const Part::TopoShape& TopShape = base->Shape.getShape(); + if (TopShape._Shape.IsNull()) + return new App::DocumentObjectExecReturn("Cannot chamfer invalid shape"); const std::vector& SubVals = Base.getSubValuesStartsWith("Edge"); if (SubVals.size() == 0) - return new App::DocumentObjectExecReturn("No Edges specified"); + return new App::DocumentObjectExecReturn("No edges specified"); - float radius = Radius.getValue(); + float size = Size.getValue(); this->positionByBase(); try { - BRepChamferAPI_MakeChamfer mkChamfer(base->Shape.getValue()); + BRepFilletAPI_MakeChamfer mkChamfer(base->Shape.getValue()); + + TopTools_IndexedMapOfShape mapOfEdges; + TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace; + TopExp::MapShapesAndAncestors(base->Shape.getValue(), TopAbs_EDGE, TopAbs_FACE, mapEdgeFace); + TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, mapOfEdges); for (std::vector::const_iterator it= SubVals.begin();it!=SubVals.end();++it) { TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(it->c_str())); - mkChamfer.Add(radius, radius, edge); + const TopoDS_Face& face = TopoDS::Face(mapEdgeFace.FindFromKey(edge).First()); + mkChamfer.Add(size, edge, face); } + mkChamfer.Build(); + if (!mkChamfer.IsDone()) + return new App::DocumentObjectExecReturn("Failed to create chamfer"); + TopoDS_Shape shape = mkChamfer.Shape(); if (shape.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is null"); @@ -89,7 +108,5 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); - }*/ - - return App::DocumentObject::StdReturn; + } } diff --git a/src/Mod/PartDesign/App/FeatureChamfer.h b/src/Mod/PartDesign/App/FeatureChamfer.h index 1f719d0a5..16bbc1246 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.h +++ b/src/Mod/PartDesign/App/FeatureChamfer.h @@ -24,7 +24,7 @@ #ifndef PARTDESIGN_FEATURECHAMFER_H #define PARTDESIGN_FEATURECHAMFER_H -#include +#include #include #include "FeatureDressUp.h" @@ -38,7 +38,7 @@ class Chamfer : public DressUp public: Chamfer(); - App::PropertyLength Size; + App::PropertyFloatConstraint Size; /** @name methods override feature */ //@{ diff --git a/src/Mod/PartDesign/App/FeatureFillet.cpp b/src/Mod/PartDesign/App/FeatureFillet.cpp index aa69d9a6d..8ddaa0854 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.cpp +++ b/src/Mod/PartDesign/App/FeatureFillet.cpp @@ -80,7 +80,7 @@ App::DocumentObjectExecReturn *Fillet::execute(void) for (std::vector::const_iterator it= SubVals.begin();it!=SubVals.end();++it) { TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(it->c_str())); - mkFillet.Add(radius, radius, edge); + mkFillet.Add(radius, edge); } mkFillet.Build(); diff --git a/src/Mod/PartDesign/App/FeatureFillet.h b/src/Mod/PartDesign/App/FeatureFillet.h index 0b5d43f20..53a638c85 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.h +++ b/src/Mod/PartDesign/App/FeatureFillet.h @@ -45,7 +45,7 @@ public: /// recalculate the feature App::DocumentObjectExecReturn *execute(void); short mustExecute() const; - // returns the type name of the view provider + /// returns the type name of the view provider const char* getViewProviderName(void) const { return "PartDesignGui::ViewProviderFillet"; } diff --git a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp index 11dd3a7d0..d86285fbe 100644 --- a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp +++ b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp @@ -34,9 +34,9 @@ #include "Workbench.h" #include "ViewProviderPocket.h" #include "ViewProviderPad.h" +#include "ViewProviderChamfer.h" #include "ViewProviderFillet.h" #include "ViewProviderRevolution.h" -#include "TaskChamfer.h" //#include "resources/qrc_PartDesign.cpp" diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index d12d2d923..23ef7e9b1 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -25,10 +25,10 @@ set(PartDesignGui_LIBS ) set(PartDesignGui_MOC_HDRS - TaskChamfer.h TaskPadParameters.h TaskPatternRectangularParameters.h TaskPocketParameters.h + TaskChamferParameters.h TaskFilletParameters.h TaskHoleParameters.h TaskRevolutionParameters.h @@ -39,10 +39,10 @@ SOURCE_GROUP("Moc" FILES ${PartDesignGui_MOC_SRCS}) qt4_add_resources(PartDesignGui_SRCS Resources/PartDesign.qrc) set(PartDesignGui_UIC_SRCS - TaskChamfer.ui TaskPadParameters.ui TaskPatternRectangularParameters.ui TaskPocketParameters.ui + TaskChamferParameters.ui TaskFilletParameters.ui TaskHoleParameters.ui TaskRevolutionParameters.ui @@ -58,6 +58,8 @@ SET(PartDesignGuiViewProvider_SRCS ViewProviderHole.h ViewProviderPocket.cpp ViewProviderPocket.h + ViewProviderChamfer.cpp + ViewProviderChamfer.h ViewProviderFillet.cpp ViewProviderFillet.h ViewProviderRevolution.cpp @@ -68,9 +70,6 @@ SET(PartDesignGuiViewProvider_SRCS SOURCE_GROUP("ViewProvider" FILES ${PartDesignGuiViewProvider_SRCS}) SET(PartDesignGuiTaskDlgs_SRCS - TaskChamfer.ui - TaskChamfer.cpp - TaskChamfer.h TaskPadParameters.ui TaskPadParameters.cpp TaskPadParameters.h @@ -80,6 +79,9 @@ SET(PartDesignGuiTaskDlgs_SRCS TaskPocketParameters.ui TaskPocketParameters.cpp TaskPocketParameters.h + TaskChamferParameters.ui + TaskChamferParameters.cpp + TaskChamferParameters.h TaskFilletParameters.ui TaskFilletParameters.cpp TaskFilletParameters.h diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 6737140b2..ddf324084 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -35,7 +35,6 @@ #include #include -#include "TaskChamfer.h" using namespace std; @@ -376,8 +375,8 @@ CmdPartDesignChamfer::CmdPartDesignChamfer() :Command("PartDesign_Chamfer") { sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("Part"); - sMenuText = QT_TR_NOOP("Chamfer..."); + sGroup = QT_TR_NOOP("PartDesign"); + sMenuText = QT_TR_NOOP("Chamfer"); sToolTipText = QT_TR_NOOP("Chamfer the selected edges of a shape"); sWhatsThis = sToolTipText; sStatusTip = sToolTipText; @@ -386,12 +385,36 @@ CmdPartDesignChamfer::CmdPartDesignChamfer() void CmdPartDesignChamfer::activated(int iMsg) { - Gui::Control().showDialog(new PartDesignGui::TaskChamfer()); + std::vector selection = getSelection().getSelectionEx(); + + if (selection.size() != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select an edge, face or body. Only one body is allowed.")); + return; + } + + if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), + QObject::tr("Chamfer works only on parts")); + return; + } + std::string SelString = selection[0].getAsPropertyLinkSubString(); + std::string FeatName = getUniqueObjectName("Chamfer"); + + openCommand("Make Chamfer"); + doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Chamfer\",\"%s\")",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str()); + doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName()); + doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); + + copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName()); + copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName()); + copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName()); } bool CmdPartDesignChamfer::isActive(void) { - return (hasActiveDocument() && !Gui::Control().activeDialog()); + return hasActiveDocument(); } diff --git a/src/Mod/PartDesign/Gui/Makefile.am b/src/Mod/PartDesign/Gui/Makefile.am index 34fc27856..f7bbf7054 100644 --- a/src/Mod/PartDesign/Gui/Makefile.am +++ b/src/Mod/PartDesign/Gui/Makefile.am @@ -3,26 +3,26 @@ SUBDIRS=Resources lib_LTLIBRARIES=libPartDesignGui.la PartDesignGui.la BUILT_SOURCES=\ - moc_TaskChamfer.cpp \ moc_TaskPadParameters.cpp \ moc_TaskPatternRectangularParameters.cpp \ moc_TaskPocketParameters.cpp \ + moc_TaskChamferParameters.cpp \ moc_TaskFilletParameters.cpp \ moc_TaskHoleParameters.cpp \ moc_TaskRevolutionParameters.cpp \ - ui_TaskChamfer.h \ ui_TaskPadParameters.h \ ui_TaskPatternRectangularParameters.h \ ui_TaskPocketParameters.h \ + ui_TaskChamferParameters.h \ ui_TaskFilletParameters.h \ ui_TaskHoleParameters.h \ ui_TaskRevolutionParameters.h libPartDesignGui_la_UI=\ - TaskChamfer.ui \ TaskPadParameters.ui \ TaskPatternRectangularParameters.ui \ TaskPocketParameters.ui \ + TaskChamferParameters.ui \ TaskFilletParameters.ui \ TaskHoleParameters.ui \ TaskRevolutionParameters.ui @@ -32,14 +32,14 @@ libPartDesignGui_la_SOURCES=\ Command.cpp \ PreCompiled.cpp \ PreCompiled.h \ - TaskChamfer.cpp \ - TaskChamfer.h \ TaskPadParameters.cpp \ TaskPadParameters.h \ TaskPatternRectangularParameters.cpp \ TaskPatternRectangularParameters.h \ TaskPocketParameters.cpp \ TaskPocketParameters.h \ + TaskChamferParameters.cpp \ + TaskChamferParameters.h \ TaskFilletParameters.cpp \ TaskFilletParameters.h \ TaskRevolutionParameters.cpp \ @@ -54,6 +54,8 @@ libPartDesignGui_la_SOURCES=\ ViewProviderPad.h \ ViewProviderPocket.cpp \ ViewProviderPocket.h \ + ViewProviderChamfer.cpp \ + ViewProviderChamfer.h \ ViewProviderFillet.cpp \ ViewProviderFillet.h \ ViewProviderRevolution.cpp \ diff --git a/src/Mod/PartDesign/Gui/TaskChamfer.cpp b/src/Mod/PartDesign/Gui/TaskChamfer.cpp deleted file mode 100644 index 961e23538..000000000 --- a/src/Mod/PartDesign/Gui/TaskChamfer.cpp +++ /dev/null @@ -1,618 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#endif - -#include "TaskChamfer.h" -#include "ui_TaskChamfer.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace PartDesignGui; - -/* TRANSLATOR PartDesignGui::ChamferDistanceDelegate */ - -ChamferDistanceDelegate::ChamferDistanceDelegate(QObject *parent) : QItemDelegate(parent) -{ -} - -QWidget *ChamferDistanceDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, - const QModelIndex & index) const -{ - if (index.column() < 1) - return 0; - - QDoubleSpinBox *editor = new QDoubleSpinBox(parent); - editor->setMinimum(0.0); - editor->setMaximum(100.0); - editor->setSingleStep(0.1); - - return editor; -} - -void ChamferDistanceDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const -{ - double value = index.model()->data(index, Qt::EditRole).toDouble(); - - QDoubleSpinBox *spinBox = static_cast(editor); - spinBox->setValue(value); -} - -void ChamferDistanceDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const -{ - QDoubleSpinBox *spinBox = static_cast(editor); - spinBox->interpretText(); - //double value = spinBox->value(); - //QString value = QString::fromAscii("%1").arg(spinBox->value(),0,'f',2); - QString value = QLocale::system().toString(spinBox->value(),'f',2); - - model->setData(index, value, Qt::EditRole); -} - -void ChamferDistanceDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, - const QModelIndex &/* index */) const -{ - editor->setGeometry(option.rect); -} - -// -------------------------------------------------------------- - -ChamferDistanceModel::ChamferDistanceModel(QObject * parent) : QStandardItemModel(parent) -{ -} - -Qt::ItemFlags ChamferDistanceModel::flags (const QModelIndex & index) const -{ - Qt::ItemFlags fl = QStandardItemModel::flags(index); - if (index.column() == 0) - fl = fl | Qt::ItemIsUserCheckable; - return fl; -} - -bool ChamferDistanceModel::setData (const QModelIndex & index, const QVariant & value, int role) -{ - bool ok = QStandardItemModel::setData(index, value, role); - if (role == Qt::CheckStateRole) { - toggleCheckState(index); - } - return ok; -} - -// -------------------------------------------------------------- - -namespace PartDesignGui { - class EdgeSelection : public Gui::SelectionFilterGate - { - App::DocumentObject*& object; - public: - EdgeSelection(App::DocumentObject*& obj) - : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), object(obj) - { - } - bool allow(App::Document*pDoc, App::DocumentObject*pObj, const char*sSubName) - { - if (pObj != this->object) - return false; - if (!sSubName || sSubName[0] == '\0') - return false; - std::string element(sSubName); - return element.substr(0,4) == "Edge"; - } - }; - class ChamferWidgetP - { - public: - App::DocumentObject* object; - EdgeSelection* selection; - typedef boost::signals::connection Connection; - Connection connectApplicationDeletedObject; - Connection connectApplicationDeletedDocument; - }; -}; - -/* TRANSLATOR PartDesignGui::ChamferWidget */ - -ChamferWidget::ChamferWidget(QWidget* parent, Qt::WFlags fl) - : QWidget(parent, fl), ui(new Ui_TaskChamfer()), d(new ChamferWidgetP()) -{ - ui->setupUi(this); - - d->object = 0; - d->selection = new EdgeSelection(d->object); - Gui::Selection().addSelectionGate(d->selection); - - d->connectApplicationDeletedObject = App::GetApplication().signalDeletedObject - .connect(boost::bind(&ChamferWidget::onDeleteObject, this, _1)); - d->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument - .connect(boost::bind(&ChamferWidget::onDeleteDocument, this, _1)); - // set tree view with three columns - QStandardItemModel* model = new ChamferDistanceModel(this); - connect(model, SIGNAL(toggleCheckState(const QModelIndex&)), - this, SLOT(toggleCheckState(const QModelIndex&))); - model->insertColumns(0,3); - model->setHeaderData(0, Qt::Horizontal, tr("Edges to chamfer"), Qt::DisplayRole); - model->setHeaderData(1, Qt::Horizontal, tr("Start distance"), Qt::DisplayRole); - model->setHeaderData(2, Qt::Horizontal, tr("End distance"), Qt::DisplayRole); - ui->treeView->setRootIsDecorated(false); - ui->treeView->setItemDelegate(new ChamferDistanceDelegate(this)); - ui->treeView->setModel(model); - - QHeaderView* header = ui->treeView->header(); - header->setResizeMode(0, QHeaderView::Stretch); - header->setDefaultAlignment(Qt::AlignLeft); - header->setMovable(false); - on_chamferType_activated(0); - findShapes(); -} - -/* - * Destroys the object and frees any allocated resources - */ -ChamferWidget::~ChamferWidget() -{ - // no need to delete child widgets, Qt does it all for us - d->connectApplicationDeletedDocument.disconnect(); - d->connectApplicationDeletedObject.disconnect(); - Gui::Selection().rmvSelectionGate(); -} - -void ChamferWidget::onSelectionChanged(const Gui::SelectionChanges& msg) -{ - // no object selected in the combobox or no sub-element was selected - if (!d->object || !msg.pSubName) - return; - if (msg.Type == Gui::SelectionChanges::AddSelection) { - // when adding a sub-element to the selection check - // whether this is the currently handled object - App::Document* doc = d->object->getDocument(); - std::string docname = doc->getName(); - std::string objname = d->object->getNameInDocument(); - if (docname==msg.pDocName && objname==msg.pObjectName) { - QString subelement = QString::fromAscii(msg.pSubName); - QAbstractItemModel* model = ui->treeView->model(); - for (int i=0; irowCount(); ++i) { - int id = model->data(model->index(i,0), Qt::UserRole).toInt(); - QString name = QString::fromAscii("Edge%1").arg(id); - if (name == subelement) { - // ok, check the selected sub-element - Qt::CheckState checkState = Qt::Checked; - QVariant value(static_cast(checkState)); - QModelIndex index = model->index(i,0); - model->setData(index, value, Qt::CheckStateRole); - // select the item - ui->treeView->selectionModel()->setCurrentIndex(index,QItemSelectionModel::NoUpdate); - QItemSelection selection(index, model->index(i,1)); - ui->treeView->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect); - break; - } - } - } - } -} - -void ChamferWidget::onDeleteObject(const App::DocumentObject& obj) -{ - if (d->object == &obj) { - d->object = 0; - ui->shapeObject->removeItem(ui->shapeObject->currentIndex()); - ui->shapeObject->setCurrentIndex(0); - on_shapeObject_activated(0); - } - else { - QString shape = QString::fromAscii(obj.getNameInDocument()); - // start from the second item - for (int i=1; ishapeObject->count(); i++) { - if (ui->shapeObject->itemData(i).toString() == shape) { - ui->shapeObject->removeItem(i); - break; - } - } - } -} - -void ChamferWidget::onDeleteDocument(const App::Document& doc) -{ - if (d->object) { - if (d->object->getDocument() == &doc) { - ui->shapeObject->setCurrentIndex(0); - on_shapeObject_activated(0); - setEnabled(false); - } - } - else if (App::GetApplication().getActiveDocument() == &doc) { - ui->shapeObject->setCurrentIndex(0); - on_shapeObject_activated(0); - setEnabled(false); - } -} - -void ChamferWidget::toggleCheckState(const QModelIndex& index) -{ - if (!d->object) - return; - QVariant check = index.data(Qt::CheckStateRole); - int id = index.data(Qt::UserRole).toInt(); - QString name = QString::fromAscii("Edge%1").arg(id); - Qt::CheckState checkState = static_cast(check.toInt()); - - bool block = this->blockConnection(false); - - // is item checked - if (checkState & Qt::Checked) { - App::Document* doc = d->object->getDocument(); - Gui::Selection().addSelection(doc->getName(), - d->object->getNameInDocument(), - (const char*)name.toAscii()); - } - else { - App::Document* doc = d->object->getDocument(); - Gui::Selection().rmvSelection(doc->getName(), - d->object->getNameInDocument(), - (const char*)name.toAscii()); - } - - this->blockConnection(block); -} - -void ChamferWidget::findShapes() -{ - App::Document* activeDoc = App::GetApplication().getActiveDocument(); - if (!activeDoc) return; - - std::vector objs = activeDoc->getObjectsOfType - (Part::Feature::getClassTypeId()); - int index = 1; - int current_index = 0; - for (std::vector::iterator it = objs.begin(); it!=objs.end(); ++it, ++index) { - ui->shapeObject->addItem(QString::fromUtf8((*it)->Label.getValue())); - ui->shapeObject->setItemData(index, QString::fromAscii((*it)->getNameInDocument())); - if (current_index == 0) { - if (Gui::Selection().isSelected(*it)) { - current_index = index; - } - } - } - - // if only one object is in the document then simply use that - if (objs.size() == 1) - current_index = 1; - - if (current_index > 0) { - ui->shapeObject->setCurrentIndex(current_index); - on_shapeObject_activated(current_index); - } -} - -void ChamferWidget::changeEvent(QEvent *e) -{ - if (e->type() == QEvent::LanguageChange) { - int index = ui->shapeObject->currentIndex(); - // only get the items from index 1 on since the first one will be added automatically - int count = ui->shapeObject->count() - 1; - QStringList text; - QList data; - for (int i=0; ishapeObject->itemText(i+1); - data << ui->shapeObject->itemData(i+1); - } - - ui->retranslateUi(this); - for (int i=0; ishapeObject->addItem(text.at(i)); - ui->shapeObject->setItemData(i+1, data.at(i)); - } - - ui->shapeObject->setCurrentIndex(index); - QStandardItemModel *model = qobject_cast(ui->treeView->model()); - count = model->rowCount(); - for (int i=0; idata(model->index(i, 0), Qt::UserRole).toInt(); - model->setData(model->index(i, 0), QVariant(tr("Edge%1").arg(id))); - } - } - else { - QWidget::changeEvent(e); - } -} - -void ChamferWidget::on_shapeObject_activated(int index) -{ - d->object = 0; - QStandardItemModel *model = qobject_cast(ui->treeView->model()); - model->removeRows(0, model->rowCount()); - - QByteArray name = ui->shapeObject->itemData(index).toByteArray(); - App::Document* doc = App::GetApplication().getActiveDocument(); - if (!doc) - return; - App::DocumentObject* part = doc->getObject((const char*)name); - if (part && part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { - d->object = part; - TopoDS_Shape myShape = static_cast(part)->Shape.getValue(); - // build up map edge->face - TopTools_IndexedDataMapOfShapeListOfShape edge2Face; - TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, edge2Face); - TopTools_IndexedMapOfShape mapOfShape; - TopExp::MapShapes(myShape, TopAbs_EDGE, mapOfShape); - - // populate the model - std::vector edge_ids; - for (int i=1; i<= edge2Face.Extent(); ++i) { - // set the index value as user data to use it in accept() - const TopTools_ListOfShape& los = edge2Face.FindFromIndex(i); - if (los.Extent() == 2) { - // set the index value as user data to use it in accept() - const TopoDS_Shape& edge = edge2Face.FindKey(i); - const TopTools_ListOfShape& los = edge2Face.FindFromIndex(i); - if (los.Extent() == 2) { - // Now check also the continuity to only allow C0-continious - // faces - const TopoDS_Shape& face1 = los.First(); - const TopoDS_Shape& face2 = los.Last(); - GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge), - TopoDS::Face(face1), - TopoDS::Face(face2)); - if (cont == GeomAbs_C0) { - int id = mapOfShape.FindIndex(edge); - edge_ids.push_back(id); - } - } - } - } - - model->insertRows(0, edge_ids.size()); - int index = 0; - for (std::vector::iterator it = edge_ids.begin(); it != edge_ids.end(); ++it) { - model->setData(model->index(index, 0), QVariant(tr("Edge%1").arg(*it))); - model->setData(model->index(index, 0), QVariant(*it), Qt::UserRole); - model->setData(model->index(index, 1), QVariant(QLocale::system().toString(1.0,'f',2))); - model->setData(model->index(index, 2), QVariant(QLocale::system().toString(1.0,'f',2))); - std::stringstream element; - element << "Edge" << *it; - if (Gui::Selection().isSelected(part, element.str().c_str())) - model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole); - else - model->setData(model->index(index, 0), Qt::Unchecked, Qt::CheckStateRole); - index++; - } - } -} - -void ChamferWidget::on_selectAllButton_clicked() -{ - QAbstractItemModel* model = ui->treeView->model(); - for (int i=0; irowCount(); ++i) { - Qt::CheckState checkState = Qt::Checked; - QVariant value(static_cast(checkState)); - model->setData(model->index(i,0), value, Qt::CheckStateRole); - } -} - -void ChamferWidget::on_selectNoneButton_clicked() -{ - QAbstractItemModel* model = ui->treeView->model(); - for (int i=0; irowCount(); ++i) { - Qt::CheckState checkState = Qt::Unchecked; - QVariant value(static_cast(checkState)); - model->setData(model->index(i,0), value, Qt::CheckStateRole); - } -} - -void ChamferWidget::on_chamferType_activated(int index) -{ - QStandardItemModel *model = qobject_cast(ui->treeView->model()); - if (index == 0) { - model->setHeaderData(1, Qt::Horizontal, tr("Distance"), Qt::DisplayRole); - ui->treeView->hideColumn(2); - ui->chamferEndDistance->hide(); - } - else { - model->setHeaderData(1, Qt::Horizontal, tr("Start distance"), Qt::DisplayRole); - ui->treeView->showColumn(2); - ui->chamferEndDistance->show(); - } - - ui->treeView->resizeColumnToContents(0); - ui->treeView->resizeColumnToContents(1); - ui->treeView->resizeColumnToContents(2); -} - -void ChamferWidget::on_chamferStartDistance_valueChanged(double distance) -{ - QAbstractItemModel* model = ui->treeView->model(); - QString text = QLocale::system().toString(distance,'f',2); - for (int i=0; irowCount(); ++i) { - QVariant value = model->index(i,0).data(Qt::CheckStateRole); - Qt::CheckState checkState = static_cast(value.toInt()); - - // is item checked - if (checkState & Qt::Checked) { - model->setData(model->index(i, 1), QVariant(text)); - } - } -} - -void ChamferWidget::on_chamferEndDistance_valueChanged(double distance) -{ - QAbstractItemModel* model = ui->treeView->model(); - QString text = QLocale::system().toString(distance,'f',2); - for (int i=0; irowCount(); ++i) { - QVariant value = model->index(i,0).data(Qt::CheckStateRole); - Qt::CheckState checkState = static_cast(value.toInt()); - - // is item checked - if (checkState & Qt::Checked) { - model->setData(model->index(i, 2), QVariant(text)); - } - } -} - -bool ChamferWidget::accept() -{ - if (!d->object) { - QMessageBox::warning(this, tr("No shape selected"), - tr("No valid shape is selected.\n" - "Please select a valid shape in the drop-down box first.")); - return false; - } - App::Document* activeDoc = App::GetApplication().getActiveDocument(); - QAbstractItemModel* model = ui->treeView->model(); - bool end_distance = !ui->treeView->isColumnHidden(2); - bool todo = false; - - QString shape, type, name; - int index = ui->shapeObject->currentIndex(); - shape = ui->shapeObject->itemData(index).toString(); - type = QString::fromAscii("Part::Chamfer"); - name = QString::fromAscii(activeDoc->getUniqueObjectName("Chamfer").c_str()); - - activeDoc->openTransaction("Chamfer"); - QString code = QString::fromAscii( - "FreeCAD.ActiveDocument.addObject(\"%1\",\"%2\")\n" - "FreeCAD.ActiveDocument.%2.Base = FreeCAD.ActiveDocument.%3\n" - "__chamfers__ = []\n") - .arg(type).arg(name).arg(shape); - for (int i=0; irowCount(); ++i) { - QVariant value = model->index(i,0).data(Qt::CheckStateRole); - Qt::CheckState checkState = static_cast(value.toInt()); - - // is item checked - if (checkState & Qt::Checked) { - // the index value of the edge - int id = model->index(i,0).data(Qt::UserRole).toInt(); - double r1 = model->index(i,1).data().toDouble(); - double r2 = r1; - if (end_distance) - r2 = model->index(i,2).data().toDouble(); - code += QString::fromAscii( - "__chamfers__.append((%1,%2,%3))\n") - .arg(id).arg(r1,0,'f',2).arg(r2,0,'f',2); - todo = true; - } - } - - if (!todo) { - QMessageBox::warning(this, tr("No edge selected"), - tr("No edge entity is checked to chamfer.\n" - "Please check one or more edge entities first.")); - return false; - } - - Gui::WaitCursor wc; - code += QString::fromAscii( - "FreeCAD.ActiveDocument.%1.Edges = __chamfers__\n" - "del __chamfers__\n" - "FreeCADGui.ActiveDocument.%2.Visibility = False\n") - .arg(name).arg(shape); - Gui::Application::Instance->runPythonCode((const char*)code.toAscii()); - activeDoc->commitTransaction(); - activeDoc->recompute(); - - QByteArray to = name.toAscii(); - QByteArray from = shape.toAscii(); - Gui::Command::copyVisual(to, "ShapeColor", from); - Gui::Command::copyVisual(to, "LineColor", from); - Gui::Command::copyVisual(to, "PointColor", from); - - return true; -} - -// --------------------------------------- - -TaskChamfer::TaskChamfer() -{ - widget = new ChamferWidget(); - Gui::TaskView::TaskBox* taskbox = new Gui::TaskView::TaskBox( - Gui::BitmapFactory().pixmap("Part_Chamfer"), - widget->windowTitle(), true, 0); - taskbox->groupLayout()->addWidget(widget); - Content.push_back(taskbox); -} - -TaskChamfer::~TaskChamfer() -{ - // automatically deleted in the sub-class -} - -void TaskChamfer::open() -{ -} - -void TaskChamfer::clicked(int) -{ -} - -bool TaskChamfer::accept() -{ - return widget->accept(); -} - -bool TaskChamfer::reject() -{ - return true; -} - -// --------------------------------------- - -PROPERTY_SOURCE(PartDesignGui::ViewProviderChamfer, PartGui::ViewProviderPart) - -ViewProviderChamfer::ViewProviderChamfer() -{ - sPixmap = "Part_Chamfer"; -} - -ViewProviderChamfer::~ViewProviderChamfer() -{ -} - -#include "moc_TaskChamfer.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskChamfer.h b/src/Mod/PartDesign/Gui/TaskChamfer.h deleted file mode 100644 index dd345f855..000000000 --- a/src/Mod/PartDesign/Gui/TaskChamfer.h +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -#ifndef PARTDESIGNGUI_TASKCHAMFER_H -#define PARTDESIGNGUI_TASKCHAMFER_H - -#include -#include -#include -#include -#include -#include - -namespace PartDesignGui { - -class Ui_TaskChamfer; -class ChamferDistanceDelegate : public QItemDelegate -{ - Q_OBJECT - -public: - ChamferDistanceDelegate(QObject *parent = 0); - - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - void setEditorData(QWidget *editor, const QModelIndex &index) const; - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const; - - void updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &index) const; -}; - -class ChamferDistanceModel : public QStandardItemModel -{ - Q_OBJECT - -public: - ChamferDistanceModel(QObject * parent = 0); - - Qt::ItemFlags flags (const QModelIndex & index) const; - bool setData (const QModelIndex & index, const QVariant & value, - int role = Qt::EditRole); -Q_SIGNALS: - void toggleCheckState(const QModelIndex&); -}; - -class ChamferWidgetP; -class ChamferWidget : public QWidget, public Gui::SelectionObserver -{ - Q_OBJECT - -public: - ChamferWidget(QWidget* parent = 0, Qt::WFlags fl = 0); - ~ChamferWidget(); - bool accept(); - -protected: - void findShapes(); - void changeEvent(QEvent *e); - -private: - void onSelectionChanged(const Gui::SelectionChanges& msg); - void onDeleteObject(const App::DocumentObject&); - void onDeleteDocument(const App::Document&); - -private Q_SLOTS: - void on_shapeObject_activated(int); - void on_selectAllButton_clicked(); - void on_selectNoneButton_clicked(); - void on_chamferType_activated(int); - void on_chamferStartDistance_valueChanged(double); - void on_chamferEndDistance_valueChanged(double); - void toggleCheckState(const QModelIndex&); - -private: - std::auto_ptr ui; - std::auto_ptr d; -}; - -class TaskChamfer : public Gui::TaskView::TaskDialog -{ - Q_OBJECT - -public: - TaskChamfer(); - ~TaskChamfer(); - -public: - virtual void open(); - virtual void clicked(int); - virtual bool accept(); - virtual bool reject(); - - virtual QDialogButtonBox::StandardButtons getStandardButtons() const - { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } - -private: - ChamferWidget* widget; -}; - -class ViewProviderChamfer : public PartGui::ViewProviderPart -{ - PROPERTY_HEADER(PartDesignGui::ViewProviderChamfer); - -public: - /// constructor - ViewProviderChamfer(); - /// destructor - virtual ~ViewProviderChamfer(); -}; - -} // namespace PartDesignGui - -#endif // PARTDESIGNGUI_TASKCHAMFER_H diff --git a/src/Mod/PartDesign/Gui/TaskChamfer.ui b/src/Mod/PartDesign/Gui/TaskChamfer.ui deleted file mode 100644 index 161f68e95..000000000 --- a/src/Mod/PartDesign/Gui/TaskChamfer.ui +++ /dev/null @@ -1,172 +0,0 @@ - - - PartDesignGui::TaskChamfer - - - - 0 - 0 - 424 - 426 - - - - Chamfer Edges - - - - - - Shape - - - - 6 - - - 9 - - - - - Selected shape: - - - - - - - - No selection - - - - - - - - - - - Chamfer Parameter - - - - - - Qt::Horizontal - - - - 221 - 20 - - - - - - - - All - - - - - - - None - - - - - - - Chamfer type: - - - - - - - - Constant Distance - - - - - Variable Distance - - - - - - - - - - - 6 - - - 0 - - - - - Distance: - - - - - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 40 - 20 - - - - - - - - - - - - - shapeObject - chamferType - treeView - chamferStartDistance - chamferEndDistance - - - - diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp new file mode 100644 index 000000000..b081e5c09 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp @@ -0,0 +1,166 @@ +/*************************************************************************** + * Copyright (c) 2011 Juergen Riegel * + * * + * 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_TaskChamferParameters.h" +#include "TaskChamferParameters.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +using namespace PartDesignGui; +using namespace Gui; + +/* TRANSLATOR PartDesignGui::TaskChamferParameters */ + +TaskChamferParameters::TaskChamferParameters(ViewProviderChamfer *ChamferView,QWidget *parent) + : TaskBox(Gui::BitmapFactory().pixmap("Part_Chamfer"),tr("Chamfer parameters"),true, parent),ChamferView(ChamferView) +{ + // we need a separate container widget to add all controls to + proxy = new QWidget(this); + ui = new Ui_TaskChamferParameters(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)), + this, SLOT(onLengthChanged(double))); + + this->groupLayout()->addWidget(proxy); + + PartDesign::Chamfer* pcChamfer = static_cast(ChamferView->getObject()); + double r = pcChamfer->Size.getValue(); + + ui->doubleSpinBox->setMaximum(INT_MAX); + ui->doubleSpinBox->setValue(r); + ui->doubleSpinBox->selectAll(); + QMetaObject::invokeMethod(ui->doubleSpinBox, "setFocus", Qt::QueuedConnection); +} + +void TaskChamferParameters::onLengthChanged(double len) +{ + PartDesign::Chamfer* pcChamfer = static_cast(ChamferView->getObject()); + pcChamfer->Size.setValue((float)len); + pcChamfer->getDocument()->recomputeFeature(pcChamfer); +} + +double TaskChamferParameters::getLength(void) const +{ + return ui->doubleSpinBox->value(); +} + + +TaskChamferParameters::~TaskChamferParameters() +{ + delete ui; +} + +void TaskChamferParameters::changeEvent(QEvent *e) +{ + TaskBox::changeEvent(e); + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(proxy); + } +} + +//************************************************************************** +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgChamferParameters::TaskDlgChamferParameters(ViewProviderChamfer *ChamferView) + : TaskDialog(),ChamferView(ChamferView) +{ + assert(ChamferView); + parameter = new TaskChamferParameters(ChamferView); + + Content.push_back(parameter); +} + +TaskDlgChamferParameters::~TaskDlgChamferParameters() +{ + +} + +//==== calls from the TaskView =============================================================== + + +void TaskDlgChamferParameters::open() +{ + +} + +void TaskDlgChamferParameters::clicked(int) +{ + +} + +bool TaskDlgChamferParameters::accept() +{ + std::string name = ChamferView->getObject()->getNameInDocument(); + + //Gui::Command::openCommand("Chamfer changed"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Size = %f",name.c_str(),parameter->getLength()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::commitCommand(); + + return true; +} + +bool TaskDlgChamferParameters::reject() +{ + // get the support and Sketch + PartDesign::Chamfer* pcChamfer = static_cast(ChamferView->getObject()); + App::DocumentObject *pcSupport; + pcSupport = pcChamfer->Base.getValue(); + + // role back the done things + Gui::Command::abortCommand(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + + // if abort command deleted the object the support is visible again + if (!Gui::Application::Instance->getViewProvider(pcChamfer)) { + if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport)) + Gui::Application::Instance->getViewProvider(pcSupport)->show(); + } + + return true; +} + + + +#include "moc_TaskChamferParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.h b/src/Mod/PartDesign/Gui/TaskChamferParameters.h new file mode 100644 index 000000000..69c476747 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.h @@ -0,0 +1,108 @@ +/*************************************************************************** + * Copyright (c) 2011 Juergen Riegel * + * * + * 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_TaskChamferParameters_H +#define GUI_TASKVIEW_TaskChamferParameters_H + +#include +#include +#include + +#include "ViewProviderChamfer.h" + +class Ui_TaskChamferParameters; + +namespace App { +class Property; +} + +namespace Gui { +class ViewProvider; +} + + +namespace PartDesignGui { + +class TaskChamferParameters : public Gui::TaskView::TaskBox +{ + Q_OBJECT + +public: + TaskChamferParameters(ViewProviderChamfer *ChamferView, QWidget *parent=0); + ~TaskChamferParameters(); + + double getLength(void) const; + +private Q_SLOTS: + void onLengthChanged(double); + +protected: + void changeEvent(QEvent *e); + +private: + +private: + QWidget* proxy; + Ui_TaskChamferParameters* ui; + ViewProviderChamfer *ChamferView; +}; + +/// simulation dialog for the TaskView +class TaskDlgChamferParameters : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgChamferParameters(ViewProviderChamfer *ChamferView); + ~TaskDlgChamferParameters(); + + ViewProviderChamfer* getChamferView() const + { return ChamferView; } + + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual bool isAllowedAlterDocument(void) const + { return false; } + + /// returns for Close and Help button + virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const + { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } + +protected: + ViewProviderChamfer *ChamferView; + + TaskChamferParameters *parameter; +}; + +} //namespace PartDesignGui + +#endif // GUI_TASKVIEW_TaskChamferParameters_H diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.ui b/src/Mod/PartDesign/Gui/TaskChamferParameters.ui new file mode 100644 index 000000000..21bda66f9 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.ui @@ -0,0 +1,42 @@ + + + PartDesignGui::TaskChamferParameters + + + + 0 + 0 + 135 + 40 + + + + Form + + + + + + + + Size: + + + + + + + 0.000000000000000 + + + 999999999.000000000000000 + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/TaskFilletParameters.h b/src/Mod/PartDesign/Gui/TaskFilletParameters.h index 1c63ffc10..1a9d1bbd0 100644 --- a/src/Mod/PartDesign/Gui/TaskFilletParameters.h +++ b/src/Mod/PartDesign/Gui/TaskFilletParameters.h @@ -19,7 +19,7 @@ * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ - + #ifndef GUI_TASKVIEW_TaskFilletParameters_H #define GUI_TASKVIEW_TaskFilletParameters_H @@ -40,16 +40,15 @@ namespace Gui { class ViewProvider; } -namespace PartDesignGui { - +namespace PartDesignGui { class TaskFilletParameters : public Gui::TaskView::TaskBox { Q_OBJECT public: - TaskFilletParameters(ViewProviderFillet *FilletView,QWidget *parent = 0); + TaskFilletParameters(ViewProviderFillet *FilletView, QWidget *parent=0); ~TaskFilletParameters(); double getLength(void) const; @@ -90,11 +89,11 @@ public: virtual bool accept(); /// is called by the framework if the dialog is rejected (Cancel) virtual bool reject(); - /// is called by the framework if the user presses the help button + /// is called by the framework if the user presses the help button virtual bool isAllowedAlterDocument(void) const { return false; } - /// returns for Close and Help button + /// returns for Close and Help button virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } diff --git a/src/Mod/PartDesign/Gui/ViewProviderChamfer.cpp b/src/Mod/PartDesign/Gui/ViewProviderChamfer.cpp new file mode 100644 index 000000000..0b8b0c289 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderChamfer.cpp @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (c) 2011 Juergen Riegel * + * * + * 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 "ViewProviderChamfer.h" +#include "TaskChamferParameters.h" +#include +#include +#include +#include +#include + + +using namespace PartDesignGui; + +PROPERTY_SOURCE(PartDesignGui::ViewProviderChamfer,PartDesignGui::ViewProvider) + +ViewProviderChamfer::ViewProviderChamfer() +{ +} + +ViewProviderChamfer::~ViewProviderChamfer() +{ +} + + +void ViewProviderChamfer::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) +{ + QAction* act; + act = menu->addAction(QObject::tr("Edit pocket"), receiver, member); + act->setData(QVariant((int)ViewProvider::Default)); + PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member); +} + +bool ViewProviderChamfer::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default ) { + // When double-clicking on the item for this chamfer the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgChamferParameters *padDlg = qobject_cast(dlg); + if (padDlg && padDlg->getChamferView() != this) + padDlg = 0; // another pad left open its task panel + if (dlg && !padDlg) { + QMessageBox msgBox; + msgBox.setText(QObject::tr("A dialog is already open in the task panel")); + msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + int ret = msgBox.exec(); + if (ret == QMessageBox::Yes) + Gui::Control().closeDialog(); + else + return false; + } + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + //if(ModNum == 1) + // Gui::Command::openCommand("Change chamfer parameters"); + + // start the edit dialog + if (padDlg) + Gui::Control().showDialog(padDlg); + else + Gui::Control().showDialog(new TaskDlgChamferParameters(this)); + + return true; + } + else { + return PartGui::ViewProviderPart::setEdit(ModNum); + } +} + +void ViewProviderChamfer::unsetEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default ) { + // and update the pad + //getSketchObject()->getDocument()->recompute(); + + // when pressing ESC make sure to close the dialog + Gui::Control().closeDialog(); + } + else { + PartGui::ViewProviderPart::unsetEdit(ModNum); + } +} + +bool ViewProviderChamfer::onDelete(const std::vector &) +{ + // get the support and Sketch + PartDesign::Chamfer* pcChamfer = static_cast(getObject()); + App::DocumentObject *pcSupport; + if (pcChamfer->Base.getValue()){ + pcSupport = static_cast(pcChamfer->Base.getValue()); + } + + // if abort command deleted the object the support is visible again + if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport)) + Gui::Application::Instance->getViewProvider(pcSupport)->show(); + + return true; +} + + diff --git a/src/Mod/PartDesign/Gui/ViewProviderChamfer.h b/src/Mod/PartDesign/Gui/ViewProviderChamfer.h new file mode 100644 index 000000000..4393f9a7d --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderChamfer.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (c) 2011 Juergen Riegel * + * * + * 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_ViewProviderChamfer_H +#define PARTGUI_ViewProviderChamfer_H + +#include "ViewProvider.h" + + +namespace PartDesignGui { + +class PartDesignGuiExport ViewProviderChamfer : public ViewProvider +{ + PROPERTY_HEADER(PartDesignGui::ViewProviderChamfer); + +public: + /// constructor + ViewProviderChamfer(); + /// destructor + virtual ~ViewProviderChamfer(); + + /// grouping handling + void setupContextMenu(QMenu*, QObject*, const char*); + + virtual bool onDelete(const std::vector &); + +protected: + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + +}; + + + +} // namespace PartDesignGui + + +#endif // PARTGUI_ViewProviderChamfer_H