+ 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
This commit is contained in:
logari81 2011-12-13 19:32:19 +00:00
parent ffd390a6af
commit 16b4578667
17 changed files with 581 additions and 959 deletions

View File

@ -23,9 +23,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepFilletAPI_MakeChamfer.hxx>
# include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#endif
#include <Mod/Part/App/TopoShape.h>
@ -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<Part::Feature*>(Base.getValue());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot chamfer invalid shape");
const std::vector<std::string>& 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<std::string>::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;
}
}

View File

@ -24,7 +24,7 @@
#ifndef PARTDESIGN_FEATURECHAMFER_H
#define PARTDESIGN_FEATURECHAMFER_H
#include <App/PropertyUnits.h>
#include <App/PropertyStandard.h>
#include <App/PropertyLinks.h>
#include "FeatureDressUp.h"
@ -38,7 +38,7 @@ class Chamfer : public DressUp
public:
Chamfer();
App::PropertyLength Size;
App::PropertyFloatConstraint Size;
/** @name methods override feature */
//@{

View File

@ -80,7 +80,7 @@ App::DocumentObjectExecReturn *Fillet::execute(void)
for (std::vector<std::string>::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();

View File

@ -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";
}

View File

@ -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"

View File

@ -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

View File

@ -35,7 +35,6 @@
#include <Gui/FileDialog.h>
#include <Mod/Part/App/Part2DObject.h>
#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<Gui::SelectionObject> 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();
}

View File

@ -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 \

View File

@ -1,618 +0,0 @@
/***************************************************************************
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <sstream>
# include <BRep_Tool.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Shape.hxx>
# include <TopExp.hxx>
# include <TopTools_ListOfShape.hxx>
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <QItemDelegate>
# include <QLocale>
# include <QHeaderView>
# include <QMessageBox>
# include <QVBoxLayout>
# include <QItemSelection>
# include <QItemSelectionModel>
# include <boost/signal.hpp>
# include <boost/bind.hpp>
#endif
#include "TaskChamfer.h"
#include "ui_TaskChamfer.h"
#include <Mod/Part/App/PartFeature.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/WaitCursor.h>
#include <Gui/Selection.h>
#include <Gui/SelectionFilter.h>
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<QDoubleSpinBox*>(editor);
spinBox->setValue(value);
}
void ChamferDistanceDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(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; i<model->rowCount(); ++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<int>(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; i<ui->shapeObject->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<Qt::CheckState>(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<App::DocumentObject*> objs = activeDoc->getObjectsOfType
(Part::Feature::getClassTypeId());
int index = 1;
int current_index = 0;
for (std::vector<App::DocumentObject*>::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<QVariant> data;
for (int i=0; i<count; i++) {
text << ui->shapeObject->itemText(i+1);
data << ui->shapeObject->itemData(i+1);
}
ui->retranslateUi(this);
for (int i=0; i<count; i++) {
ui->shapeObject->addItem(text.at(i));
ui->shapeObject->setItemData(i+1, data.at(i));
}
ui->shapeObject->setCurrentIndex(index);
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
count = model->rowCount();
for (int i=0; i<count; i++) {
int id = model->data(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<QStandardItemModel*>(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::Feature*>(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<int> 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<int>::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; i<model->rowCount(); ++i) {
Qt::CheckState checkState = Qt::Checked;
QVariant value(static_cast<int>(checkState));
model->setData(model->index(i,0), value, Qt::CheckStateRole);
}
}
void ChamferWidget::on_selectNoneButton_clicked()
{
QAbstractItemModel* model = ui->treeView->model();
for (int i=0; i<model->rowCount(); ++i) {
Qt::CheckState checkState = Qt::Unchecked;
QVariant value(static_cast<int>(checkState));
model->setData(model->index(i,0), value, Qt::CheckStateRole);
}
}
void ChamferWidget::on_chamferType_activated(int index)
{
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(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; i<model->rowCount(); ++i) {
QVariant value = model->index(i,0).data(Qt::CheckStateRole);
Qt::CheckState checkState = static_cast<Qt::CheckState>(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; i<model->rowCount(); ++i) {
QVariant value = model->index(i,0).data(Qt::CheckStateRole);
Qt::CheckState checkState = static_cast<Qt::CheckState>(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; i<model->rowCount(); ++i) {
QVariant value = model->index(i,0).data(Qt::CheckStateRole);
Qt::CheckState checkState = static_cast<Qt::CheckState>(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"

View File

@ -1,135 +0,0 @@
/***************************************************************************
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Gui/TaskView/TaskDialog.h>
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <QStandardItemModel>
#include <QItemDelegate>
#include <Mod/Part/Gui/ViewProvider.h>
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_TaskChamfer> ui;
std::auto_ptr<ChamferWidgetP> 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

View File

@ -1,172 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartDesignGui::TaskChamfer</class>
<widget class="QWidget" name="PartDesignGui::TaskChamfer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>424</width>
<height>426</height>
</rect>
</property>
<property name="windowTitle">
<string>Chamfer Edges</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Shape</string>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Selected shape:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="shapeObject">
<item>
<property name="text">
<string>No selection</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Chamfer Parameter</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>221</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="selectAllButton">
<property name="text">
<string>All</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="selectNoneButton">
<property name="text">
<string>None</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelChamfer">
<property name="text">
<string>Chamfer type:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="chamferType">
<item>
<property name="text">
<string>Constant Distance</string>
</property>
</item>
<item>
<property name="text">
<string>Variable Distance</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QTreeView" name="treeView"/>
</item>
<item row="3" column="0" colspan="3">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Distance:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="chamferStartDistance">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="chamferEndDistance">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>shapeObject</tabstop>
<tabstop>chamferType</tabstop>
<tabstop>treeView</tabstop>
<tabstop>chamferStartDistance</tabstop>
<tabstop>chamferEndDistance</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,166 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureChamfer.h>
#include <Mod/Sketcher/App/SketchObject.h>
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<PartDesign::Chamfer*>(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<PartDesign::Chamfer*>(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<PartDesign::Chamfer*>(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"

View File

@ -0,0 +1,108 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <Gui/TaskView/TaskDialog.h>
#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

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartDesignGui::TaskChamferParameters</class>
<widget class="QWidget" name="PartDesignGui::TaskChamferParameters">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>135</width>
<height>40</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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; }

View File

@ -0,0 +1,130 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 <Mod/PartDesign/App/FeatureChamfer.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Gui/Control.h>
#include <Gui/Command.h>
#include <Gui/Application.h>
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<TaskDlgChamferParameters *>(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<std::string> &)
{
// get the support and Sketch
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(getObject());
App::DocumentObject *pcSupport;
if (pcChamfer->Base.getValue()){
pcSupport = static_cast<Sketcher::SketchObject*>(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;
}

View File

@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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<std::string> &);
protected:
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
};
} // namespace PartDesignGui
#endif // PARTGUI_ViewProviderChamfer_H