DlgFilletEdges.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <algorithm>
00027 # include <BRep_Tool.hxx>
00028 # include <TopoDS.hxx>
00029 # include <TopoDS_Edge.hxx>
00030 # include <TopoDS_Shape.hxx>
00031 # include <TopExp.hxx>
00032 # include <TopTools_ListOfShape.hxx>
00033 # include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00034 # include <TopTools_IndexedMapOfShape.hxx>
00035 # include <QItemDelegate>
00036 # include <QLocale>
00037 # include <QHeaderView>
00038 # include <QMessageBox>
00039 # include <QVBoxLayout>
00040 # include <QItemSelection>
00041 # include <QItemSelectionModel>
00042 # include <boost/signal.hpp>
00043 # include <boost/bind.hpp>
00044 #endif
00045 
00046 #include "DlgFilletEdges.h"
00047 #include "ui_DlgFilletEdges.h"
00048 
00049 #include "../App/PartFeature.h"
00050 #include "../App/FeatureFillet.h"
00051 #include <App/Application.h>
00052 #include <App/Document.h>
00053 #include <App/DocumentObject.h>
00054 #include <Gui/Application.h>
00055 #include <Gui/BitmapFactory.h>
00056 #include <Gui/Command.h>
00057 #include <Gui/WaitCursor.h>
00058 #include <Gui/Selection.h>
00059 #include <Gui/SelectionFilter.h>
00060 #include <Gui/ViewProvider.h>
00061 
00062 using namespace PartGui;
00063 
00064 FilletRadiusDelegate::FilletRadiusDelegate(QObject *parent) : QItemDelegate(parent)
00065 {
00066 }
00067 
00068 QWidget *FilletRadiusDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */,
00069                                             const QModelIndex & index) const
00070 {
00071     if (index.column() < 1)
00072         return 0;
00073 
00074     QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
00075     editor->setMinimum(0.0);
00076     editor->setMaximum(100.0);
00077     editor->setSingleStep(0.1);
00078 
00079     return editor;
00080 }
00081 
00082 void FilletRadiusDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
00083 {
00084     double value = index.model()->data(index, Qt::EditRole).toDouble();
00085 
00086     QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
00087     spinBox->setValue(value);
00088 }
00089 
00090 void FilletRadiusDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
00091                                         const QModelIndex &index) const
00092 {
00093     QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
00094     spinBox->interpretText();
00095     //double value = spinBox->value();
00096     //QString value = QString::fromAscii("%1").arg(spinBox->value(),0,'f',2);
00097     QString value = QLocale::system().toString(spinBox->value(),'f',2);
00098 
00099     model->setData(index, value, Qt::EditRole);
00100 }
00101 
00102 void FilletRadiusDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
00103                                                 const QModelIndex &/* index */) const
00104 {
00105     editor->setGeometry(option.rect);
00106 }
00107 
00108 // --------------------------------------------------------------
00109 
00110 FilletRadiusModel::FilletRadiusModel(QObject * parent) : QStandardItemModel(parent)
00111 {
00112 }
00113 
00114 Qt::ItemFlags FilletRadiusModel::flags (const QModelIndex & index) const
00115 {
00116     Qt::ItemFlags fl = QStandardItemModel::flags(index);
00117     if (index.column() == 0)
00118         fl = fl | Qt::ItemIsUserCheckable;
00119     return fl;
00120 }
00121 
00122 bool FilletRadiusModel::setData (const QModelIndex & index, const QVariant & value, int role)
00123 {
00124     bool ok = QStandardItemModel::setData(index, value, role);
00125     if (role == Qt::CheckStateRole) {
00126         toggleCheckState(index);
00127     }
00128     return ok;
00129 }
00130 
00131 // --------------------------------------------------------------
00132 
00133 namespace PartGui {
00134     class EdgeSelection : public Gui::SelectionFilterGate
00135     {
00136         App::DocumentObject*& object;
00137     public:
00138         EdgeSelection(App::DocumentObject*& obj)
00139             : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), object(obj)
00140         {
00141         }
00142         bool allow(App::Document*pDoc, App::DocumentObject*pObj, const char*sSubName)
00143         {
00144             if (pObj != this->object)
00145                 return false;
00146             if (!sSubName || sSubName[0] == '\0')
00147                 return false;
00148             std::string element(sSubName);
00149             return element.substr(0,4) == "Edge";
00150         }
00151     };
00152     class DlgFilletEdgesP
00153     {
00154     public:
00155         App::DocumentObject* object;
00156         EdgeSelection* selection;
00157         Part::Fillet* fillet;
00158         typedef boost::signals::connection Connection;
00159         Connection connectApplicationDeletedObject;
00160         Connection connectApplicationDeletedDocument;
00161     };
00162 };
00163 
00164 /* TRANSLATOR PartGui::DlgFilletEdges */
00165 
00166 DlgFilletEdges::DlgFilletEdges(Part::Fillet* fillet, QWidget* parent, Qt::WFlags fl)
00167   : QWidget(parent, fl), ui(new Ui_DlgFilletEdges()), d(new DlgFilletEdgesP())
00168 {
00169     ui->setupUi(this);
00170 
00171     d->object = 0;
00172     d->selection = new EdgeSelection(d->object);
00173     Gui::Selection().addSelectionGate(d->selection);
00174 
00175     d->fillet = fillet;
00176     d->connectApplicationDeletedObject = App::GetApplication().signalDeletedObject
00177         .connect(boost::bind(&DlgFilletEdges::onDeleteObject, this, _1));
00178     d->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument
00179         .connect(boost::bind(&DlgFilletEdges::onDeleteDocument, this, _1));
00180     // set tree view with three columns
00181     QStandardItemModel* model = new FilletRadiusModel(this);
00182     connect(model, SIGNAL(toggleCheckState(const QModelIndex&)),
00183             this, SLOT(toggleCheckState(const QModelIndex&)));
00184     model->insertColumns(0,3);
00185     model->setHeaderData(0, Qt::Horizontal, tr("Edges to fillet"), Qt::DisplayRole);
00186     model->setHeaderData(1, Qt::Horizontal, tr("Start radius"), Qt::DisplayRole);
00187     model->setHeaderData(2, Qt::Horizontal, tr("End radius"), Qt::DisplayRole);
00188     ui->treeView->setRootIsDecorated(false);
00189     ui->treeView->setItemDelegate(new FilletRadiusDelegate(this));
00190     ui->treeView->setModel(model);
00191 
00192     QHeaderView* header = ui->treeView->header();
00193     header->setResizeMode(0, QHeaderView::Stretch);
00194     header->setDefaultAlignment(Qt::AlignLeft);
00195     header->setMovable(false);
00196     on_filletType_activated(0);
00197     findShapes();
00198 }
00199 
00200 /*  
00201  *  Destroys the object and frees any allocated resources
00202  */
00203 DlgFilletEdges::~DlgFilletEdges()
00204 {
00205     // no need to delete child widgets, Qt does it all for us
00206     d->connectApplicationDeletedDocument.disconnect();
00207     d->connectApplicationDeletedObject.disconnect();
00208     Gui::Selection().rmvSelectionGate();
00209 }
00210 
00211 void DlgFilletEdges::onSelectionChanged(const Gui::SelectionChanges& msg)
00212 {
00213     // no object selected in the combobox or no sub-element was selected
00214     if (!d->object || !msg.pSubName)
00215         return;
00216     if (msg.Type == Gui::SelectionChanges::AddSelection) {
00217         // when adding a sub-element to the selection check
00218         // whether this is the currently handled object
00219         App::Document* doc = d->object->getDocument();
00220         std::string docname = doc->getName();
00221         std::string objname = d->object->getNameInDocument();
00222         if (docname==msg.pDocName && objname==msg.pObjectName) {
00223             QString subelement = QString::fromAscii(msg.pSubName);
00224             QAbstractItemModel* model = ui->treeView->model();
00225             for (int i=0; i<model->rowCount(); ++i) {
00226                 int id = model->data(model->index(i,0), Qt::UserRole).toInt();
00227                 QString name = QString::fromAscii("Edge%1").arg(id);
00228                 if (name == subelement) {
00229                     // ok, check the selected sub-element
00230                     Qt::CheckState checkState = Qt::Checked;
00231                     QVariant value(static_cast<int>(checkState));
00232                     QModelIndex index = model->index(i,0);
00233                     model->setData(index, value, Qt::CheckStateRole);
00234                     // select the item
00235                     ui->treeView->selectionModel()->setCurrentIndex(index,QItemSelectionModel::NoUpdate);
00236                     QItemSelection selection(index, model->index(i,1));
00237                     ui->treeView->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
00238                     break;
00239                 }
00240             }
00241         }
00242     }
00243 }
00244 
00245 void DlgFilletEdges::onDeleteObject(const App::DocumentObject& obj)
00246 {
00247     if (d->fillet == &obj) {
00248         d->fillet = 0;
00249     }
00250     else if (d->fillet && d->fillet->Base.getValue() == &obj) {
00251         d->fillet = 0;
00252         d->object = 0;
00253         ui->shapeObject->setCurrentIndex(0);
00254         on_shapeObject_activated(0);
00255     }
00256     else if (d->object == &obj) {
00257         d->object = 0;
00258         ui->shapeObject->removeItem(ui->shapeObject->currentIndex());
00259         ui->shapeObject->setCurrentIndex(0);
00260         on_shapeObject_activated(0);
00261     }
00262     else {
00263         QString shape = QString::fromAscii(obj.getNameInDocument());
00264         // start from the second item
00265         for (int i=1; i<ui->shapeObject->count(); i++) {
00266             if (ui->shapeObject->itemData(i).toString() == shape) {
00267                 ui->shapeObject->removeItem(i);
00268                 break;
00269             }
00270         }
00271     }
00272 }
00273 
00274 void DlgFilletEdges::onDeleteDocument(const App::Document& doc)
00275 {
00276     if (d->object) {
00277         if (d->object->getDocument() == &doc) {
00278             ui->shapeObject->setCurrentIndex(0);
00279             on_shapeObject_activated(0);
00280             setEnabled(false);
00281         }
00282     }
00283     else if (App::GetApplication().getActiveDocument() == &doc) {
00284         ui->shapeObject->setCurrentIndex(0);
00285         on_shapeObject_activated(0);
00286         setEnabled(false);
00287     }
00288 }
00289 
00290 void DlgFilletEdges::toggleCheckState(const QModelIndex& index)
00291 {
00292     if (!d->object)
00293         return;
00294     QVariant check = index.data(Qt::CheckStateRole);
00295     int id = index.data(Qt::UserRole).toInt();
00296     QString name = QString::fromAscii("Edge%1").arg(id);
00297     Qt::CheckState checkState = static_cast<Qt::CheckState>(check.toInt());
00298 
00299     bool block = this->blockConnection(false);
00300 
00301     // is item checked
00302     if (checkState & Qt::Checked) {
00303         App::Document* doc = d->object->getDocument();
00304         Gui::Selection().addSelection(doc->getName(),
00305             d->object->getNameInDocument(),
00306             (const char*)name.toAscii());
00307     }
00308     else {
00309         App::Document* doc = d->object->getDocument();
00310         Gui::Selection().rmvSelection(doc->getName(),
00311             d->object->getNameInDocument(),
00312             (const char*)name.toAscii());
00313     }
00314 
00315     this->blockConnection(block);
00316 }
00317 
00318 void DlgFilletEdges::findShapes()
00319 {
00320     App::Document* activeDoc = App::GetApplication().getActiveDocument();
00321     if (!activeDoc) return;
00322 
00323     std::vector<App::DocumentObject*> objs = activeDoc->getObjectsOfType
00324         (Part::Feature::getClassTypeId());
00325     int index = 1;
00326     int current_index = 0;
00327     for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it!=objs.end(); ++it, ++index) {
00328         ui->shapeObject->addItem(QString::fromUtf8((*it)->Label.getValue()));
00329         ui->shapeObject->setItemData(index, QString::fromAscii((*it)->getNameInDocument()));
00330         if (current_index == 0) {
00331             if (Gui::Selection().isSelected(*it)) {
00332                 current_index = index;
00333             }
00334         }
00335     }
00336 
00337     // if only one object is in the document then simply use that
00338     if (objs.size() == 1)
00339         current_index = 1;
00340 
00341     if (current_index > 0) {
00342         ui->shapeObject->setCurrentIndex(current_index);
00343         on_shapeObject_activated(current_index);
00344     }
00345 
00346     // if an existing fillet object is given start the edit mode
00347     if (d->fillet) {
00348         setupFillet(objs);
00349     }
00350 }
00351 
00352 void DlgFilletEdges::setupFillet(const std::vector<App::DocumentObject*>& objs)
00353 {
00354     App::DocumentObject* base = d->fillet->Base.getValue();
00355     const std::vector<Part::FilletElement>& e = d->fillet->Edges.getValues();
00356     std::vector<App::DocumentObject*>::const_iterator it = std::find(objs.begin(), objs.end(), base);
00357     if (it != objs.end()) {
00358         // toggle visibility
00359         Gui::ViewProvider* vp;
00360         vp = Gui::Application::Instance->getViewProvider(d->fillet);
00361         if (vp) vp->hide();
00362         vp = Gui::Application::Instance->getViewProvider(base);
00363         if (vp) vp->show();
00364 
00365         int current_index = (it - objs.begin()) + 1;
00366         ui->shapeObject->setCurrentIndex(current_index);
00367         on_shapeObject_activated(current_index);
00368         ui->shapeObject->setEnabled(false);
00369         QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
00370         for (std::vector<Part::FilletElement>::const_iterator et = e.begin(); et != e.end(); ++et) {
00371             int index = et->edgeid-1;
00372             model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole);
00373             model->setData(model->index(index, 1), QVariant(QLocale::system().toString(et->radius1,'f',2)));
00374             model->setData(model->index(index, 2), QVariant(QLocale::system().toString(et->radius2,'f',2)));
00375         }
00376     }
00377 }
00378 
00382 void DlgFilletEdges::changeEvent(QEvent *e)
00383 {
00384     if (e->type() == QEvent::LanguageChange) {
00385         int index = ui->shapeObject->currentIndex();
00386         // only get the items from index 1 on since the first one will be added automatically
00387         int count = ui->shapeObject->count() - 1;
00388         QStringList text;
00389         QList<QVariant> data;
00390         for (int i=0; i<count; i++) {
00391             text << ui->shapeObject->itemText(i+1);
00392             data << ui->shapeObject->itemData(i+1);
00393         }
00394 
00395         ui->retranslateUi(this);
00396         for (int i=0; i<count; i++) {
00397             ui->shapeObject->addItem(text.at(i));
00398             ui->shapeObject->setItemData(i+1, data.at(i));
00399         }
00400 
00401         ui->shapeObject->setCurrentIndex(index);
00402         QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
00403         count = model->rowCount();
00404         for (int i=0; i<count; i++) {
00405             int id = model->data(model->index(i, 0), Qt::UserRole).toInt();
00406             model->setData(model->index(i, 0), QVariant(tr("Edge%1").arg(id)));
00407         }
00408     }
00409     else {
00410         QWidget::changeEvent(e);
00411     }
00412 }
00413 
00414 void DlgFilletEdges::on_shapeObject_activated(int index)
00415 {
00416     d->object = 0;
00417     QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
00418     model->removeRows(0, model->rowCount());
00419 
00420     QByteArray name = ui->shapeObject->itemData(index).toByteArray();
00421     App::Document* doc = App::GetApplication().getActiveDocument();
00422     if (!doc)
00423         return;
00424     App::DocumentObject* part = doc->getObject((const char*)name);
00425     if (part && part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
00426         d->object = part;
00427         TopoDS_Shape myShape = static_cast<Part::Feature*>(part)->Shape.getValue();
00428         // build up map edge->face
00429         TopTools_IndexedDataMapOfShapeListOfShape edge2Face;
00430         TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, edge2Face);
00431         TopTools_IndexedMapOfShape mapOfShape;
00432         TopExp::MapShapes(myShape, TopAbs_EDGE, mapOfShape);
00433 
00434         // populate the model
00435         std::vector<int> edge_ids;
00436         for (int i=1; i<= edge2Face.Extent(); ++i) {
00437             // set the index value as user data to use it in accept()
00438             const TopTools_ListOfShape& los = edge2Face.FindFromIndex(i);
00439             if (los.Extent() == 2) {
00440                 // set the index value as user data to use it in accept()
00441                 const TopoDS_Shape& edge = edge2Face.FindKey(i);
00442                 const TopTools_ListOfShape& los = edge2Face.FindFromIndex(i);
00443                 if (los.Extent() == 2) {
00444                     // Now check also the continuity to only allow C0-continious
00445                     // faces
00446                     const TopoDS_Shape& face1 = los.First();
00447                     const TopoDS_Shape& face2 = los.Last();
00448                     GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge),
00449                                                                TopoDS::Face(face1),
00450                                                                TopoDS::Face(face2));
00451                     if (cont == GeomAbs_C0) {
00452                         int id = mapOfShape.FindIndex(edge);
00453                         edge_ids.push_back(id);
00454                     }
00455                 }
00456             }
00457         }
00458 
00459         model->insertRows(0, edge_ids.size());
00460         int index = 0;
00461         for (std::vector<int>::iterator it = edge_ids.begin(); it != edge_ids.end(); ++it) {
00462             model->setData(model->index(index, 0), QVariant(tr("Edge%1").arg(*it)));
00463             model->setData(model->index(index, 0), QVariant(*it), Qt::UserRole);
00464             model->setData(model->index(index, 0), Qt::Unchecked, Qt::CheckStateRole);
00465             model->setData(model->index(index, 1), QVariant(QLocale::system().toString(1.0,'f',2)));
00466             model->setData(model->index(index, 2), QVariant(QLocale::system().toString(1.0,'f',2)));
00467             index++;
00468         }
00469     }
00470 }
00471 
00472 void DlgFilletEdges::on_selectAllButton_clicked()
00473 {
00474     QAbstractItemModel* model = ui->treeView->model();
00475     for (int i=0; i<model->rowCount(); ++i) {
00476         Qt::CheckState checkState = Qt::Checked;
00477         QVariant value(static_cast<int>(checkState));
00478         model->setData(model->index(i,0), value, Qt::CheckStateRole);
00479     }
00480 }
00481 
00482 void DlgFilletEdges::on_selectNoneButton_clicked()
00483 {
00484     QAbstractItemModel* model = ui->treeView->model();
00485     for (int i=0; i<model->rowCount(); ++i) {
00486         Qt::CheckState checkState = Qt::Unchecked;
00487         QVariant value(static_cast<int>(checkState));
00488         model->setData(model->index(i,0), value, Qt::CheckStateRole);
00489     }
00490 }
00491 
00492 void DlgFilletEdges::on_filletType_activated(int index)
00493 {
00494     QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
00495     if (index == 0) {
00496         model->setHeaderData(1, Qt::Horizontal, tr("Radius"), Qt::DisplayRole);
00497         ui->treeView->hideColumn(2);
00498         ui->filletEndRadius->hide();
00499     }
00500     else {
00501         model->setHeaderData(1, Qt::Horizontal, tr("Start radius"), Qt::DisplayRole);
00502         ui->treeView->showColumn(2);
00503         ui->filletEndRadius->show();
00504     }
00505 
00506     ui->treeView->resizeColumnToContents(0);
00507     ui->treeView->resizeColumnToContents(1);
00508     ui->treeView->resizeColumnToContents(2);
00509 }
00510 
00511 void DlgFilletEdges::on_filletStartRadius_valueChanged(double radius)
00512 {
00513     QAbstractItemModel* model = ui->treeView->model();
00514     QString text = QLocale::system().toString(radius,'f',2);
00515     for (int i=0; i<model->rowCount(); ++i) {
00516         QVariant value = model->index(i,0).data(Qt::CheckStateRole);
00517         Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
00518 
00519         // is item checked
00520         if (checkState & Qt::Checked) {
00521             model->setData(model->index(i, 1), QVariant(text));
00522         }
00523     }
00524 }
00525 
00526 void DlgFilletEdges::on_filletEndRadius_valueChanged(double radius)
00527 {
00528     QAbstractItemModel* model = ui->treeView->model();
00529     QString text = QLocale::system().toString(radius,'f',2);
00530     for (int i=0; i<model->rowCount(); ++i) {
00531         QVariant value = model->index(i,0).data(Qt::CheckStateRole);
00532         Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
00533 
00534         // is item checked
00535         if (checkState & Qt::Checked) {
00536             model->setData(model->index(i, 2), QVariant(text));
00537         }
00538     }
00539 }
00540 
00541 bool DlgFilletEdges::accept()
00542 {
00543     if (!d->object) {
00544         QMessageBox::warning(this, tr("No shape selected"),
00545             tr("No valid shape is selected.\n"
00546                "Please select a valid shape in the drop-down box first."));
00547         return false;
00548     }
00549     App::Document* activeDoc = App::GetApplication().getActiveDocument();
00550     QAbstractItemModel* model = ui->treeView->model();
00551     bool end_radius = !ui->treeView->isColumnHidden(2);
00552     bool todo = false;
00553 
00554     QString shape, type, name;
00555     int index = ui->shapeObject->currentIndex();
00556     shape = ui->shapeObject->itemData(index).toString();
00557     type = QString::fromAscii("Part::Fillet");
00558 
00559     if (d->fillet)
00560         name = QString::fromAscii(d->fillet->getNameInDocument());
00561     else
00562         name = QString::fromAscii(activeDoc->getUniqueObjectName("Fillet").c_str());
00563 
00564     activeDoc->openTransaction("Fillet");
00565     QString code;
00566     if (!d->fillet) {
00567         code = QString::fromAscii(
00568         "FreeCAD.ActiveDocument.addObject(\"%1\",\"%2\")\n"
00569         "FreeCAD.ActiveDocument.%2.Base = FreeCAD.ActiveDocument.%3\n")
00570         .arg(type).arg(name).arg(shape);
00571     }
00572     code += QString::fromAscii("__fillets__ = []\n");
00573     for (int i=0; i<model->rowCount(); ++i) {
00574         QVariant value = model->index(i,0).data(Qt::CheckStateRole);
00575         Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
00576 
00577         // is item checked
00578         if (checkState & Qt::Checked) {
00579             // the index value of the edge
00580             int id = model->index(i,0).data(Qt::UserRole).toInt();
00581             double r1 = model->index(i,1).data().toDouble();
00582             double r2 = r1;
00583             if (end_radius)
00584                 r2 = model->index(i,2).data().toDouble();
00585             code += QString::fromAscii(
00586                 "__fillets__.append((%1,%2,%3))\n")
00587                 .arg(id).arg(r1,0,'f',2).arg(r2,0,'f',2);
00588             todo = true;
00589         }
00590     }
00591 
00592     if (!todo) {
00593         QMessageBox::warning(this, tr("No edge selected"),
00594             tr("No edge entity is checked to fillet.\n"
00595                "Please check one or more edge entities first."));
00596         return false;
00597     }
00598 
00599     Gui::WaitCursor wc;
00600     code += QString::fromAscii(
00601         "FreeCAD.ActiveDocument.%1.Edges = __fillets__\n"
00602         "del __fillets__\n"
00603         "FreeCADGui.ActiveDocument.%2.Visibility = False\n")
00604         .arg(name).arg(shape);
00605     Gui::Application::Instance->runPythonCode((const char*)code.toAscii());
00606     activeDoc->commitTransaction();
00607     activeDoc->recompute();
00608     if (d->fillet) {
00609         Gui::ViewProvider* vp;
00610         vp = Gui::Application::Instance->getViewProvider(d->fillet);
00611         if (vp) vp->show();
00612     }
00613 
00614     QByteArray to = name.toAscii();
00615     QByteArray from = shape.toAscii();
00616     Gui::Command::copyVisual(to, "ShapeColor", from);
00617     Gui::Command::copyVisual(to, "LineColor", from);
00618     Gui::Command::copyVisual(to, "PointColor", from);
00619     return true;
00620 }
00621 
00622 // ---------------------------------------
00623 
00624 FilletEdgesDialog::FilletEdgesDialog(Part::Fillet* fillet, QWidget* parent, Qt::WFlags fl)
00625   : QDialog(parent, fl)
00626 {
00627     widget = new DlgFilletEdges(fillet, this);
00628     this->setWindowTitle(widget->windowTitle());
00629 
00630     QVBoxLayout* hboxLayout = new QVBoxLayout(this);
00631     QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
00632     buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
00633 
00634     QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
00635     QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
00636 
00637     hboxLayout->addWidget(widget);
00638     hboxLayout->addWidget(buttonBox);
00639 }
00640 
00641 FilletEdgesDialog::~FilletEdgesDialog()
00642 {
00643 }
00644 
00645 void FilletEdgesDialog::accept()
00646 {
00647     if (widget->accept())
00648         QDialog::accept();
00649 }
00650 
00651 // ---------------------------------------
00652 
00653 TaskFilletEdges::TaskFilletEdges(Part::Fillet* fillet)
00654 {
00655     widget = new DlgFilletEdges(fillet);
00656     taskbox = new Gui::TaskView::TaskBox(
00657         Gui::BitmapFactory().pixmap("Part_Fillet"),
00658         widget->windowTitle(), true, 0);
00659     taskbox->groupLayout()->addWidget(widget);
00660     Content.push_back(taskbox);
00661 }
00662 
00663 TaskFilletEdges::~TaskFilletEdges()
00664 {
00665     // automatically deleted in the sub-class
00666 }
00667 
00668 void TaskFilletEdges::open()
00669 {
00670 }
00671 
00672 void TaskFilletEdges::clicked(int)
00673 {
00674 }
00675 
00676 bool TaskFilletEdges::accept()
00677 {
00678     bool ok = widget->accept();
00679     if (ok)
00680         Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00681     return ok;
00682 }
00683 
00684 bool TaskFilletEdges::reject()
00685 {
00686     Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
00687     return true;
00688 }
00689 
00690 #include "moc_DlgFilletEdges.cpp"

Generated on Wed Nov 23 19:00:06 2011 for FreeCAD by  doxygen 1.6.1