Surface WB: add a Gui widget for unbound edges to the Filling tool.
This commit is contained in:
@@ -25,6 +25,7 @@ set(SurfaceGui_LIBS
|
||||
|
||||
set(SurfaceGui_MOC_HDRS
|
||||
TaskFilling.h
|
||||
TaskFillingUnbound.h
|
||||
TaskFillingVertex.h
|
||||
TaskGeomFillSurface.h
|
||||
)
|
||||
@@ -39,6 +40,7 @@ endif()
|
||||
|
||||
SET(SurfaceGui_UIC_SRCS
|
||||
TaskFilling.ui
|
||||
TaskFillingUnbound.ui
|
||||
TaskFillingVertex.ui
|
||||
TaskGeomFillSurface.ui
|
||||
)
|
||||
@@ -54,6 +56,8 @@ SET(SurfaceGui_SRCS
|
||||
${SurfaceGui_UIC_HDRS}
|
||||
TaskFilling.cpp
|
||||
TaskFilling.h
|
||||
TaskFillingUnbound.cpp
|
||||
TaskFillingUnbound.h
|
||||
TaskFillingVertex.cpp
|
||||
TaskFillingVertex.h
|
||||
TaskGeomFillSurface.cpp
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <Mod/Part/Gui/ViewProvider.h>
|
||||
|
||||
#include "TaskFilling.h"
|
||||
#include "TaskFillingUnbound.h"
|
||||
#include "TaskFillingVertex.h"
|
||||
#include "ui_TaskFilling.h"
|
||||
|
||||
@@ -823,12 +824,20 @@ TaskFilling::TaskFilling(ViewProviderFilling* vp, Surface::Filling* obj)
|
||||
Content.push_back(taskbox1);
|
||||
|
||||
// second task box
|
||||
widget2 = new FillingVertexPanel(vp, obj);
|
||||
widget2 = new FillingUnboundPanel(vp, obj);
|
||||
Gui::TaskView::TaskBox* taskbox2 = new Gui::TaskView::TaskBox(
|
||||
QPixmap(), widget2->windowTitle(), true, 0);
|
||||
taskbox2->groupLayout()->addWidget(widget2);
|
||||
Content.push_back(taskbox2);
|
||||
taskbox2->hideGroupBox();
|
||||
|
||||
// third task box
|
||||
widget3 = new FillingVertexPanel(vp, obj);
|
||||
Gui::TaskView::TaskBox* taskbox3 = new Gui::TaskView::TaskBox(
|
||||
QPixmap(), widget3->windowTitle(), true, 0);
|
||||
taskbox3->groupLayout()->addWidget(widget3);
|
||||
Content.push_back(taskbox3);
|
||||
taskbox3->hideGroupBox();
|
||||
}
|
||||
|
||||
TaskFilling::~TaskFilling()
|
||||
@@ -845,6 +854,7 @@ void TaskFilling::open()
|
||||
{
|
||||
widget1->open();
|
||||
widget2->open();
|
||||
widget3->open();
|
||||
}
|
||||
|
||||
bool TaskFilling::accept()
|
||||
@@ -852,6 +862,7 @@ bool TaskFilling::accept()
|
||||
bool ok = widget1->accept();
|
||||
if (ok) {
|
||||
widget2->reject();
|
||||
widget3->reject();
|
||||
Gui::Command::commitCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||
Gui::Command::updateActive();
|
||||
@@ -865,6 +876,7 @@ bool TaskFilling::reject()
|
||||
bool ok = widget1->reject();
|
||||
if (ok) {
|
||||
widget2->reject();
|
||||
widget3->reject();
|
||||
Gui::Command::abortCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||
Gui::Command::updateActive();
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace SurfaceGui
|
||||
{
|
||||
|
||||
class FillingVertexPanel;
|
||||
class FillingUnboundPanel;
|
||||
class Ui_TaskFilling;
|
||||
|
||||
class ViewProviderFilling : public PartGui::ViewProviderSpline
|
||||
@@ -122,7 +123,8 @@ public:
|
||||
|
||||
private:
|
||||
FillingPanel* widget1;
|
||||
FillingVertexPanel* widget2;
|
||||
FillingUnboundPanel* widget2;
|
||||
FillingVertexPanel* widget3;
|
||||
};
|
||||
|
||||
} //namespace SurfaceGui
|
||||
|
||||
593
src/Mod/Surface/Gui/TaskFillingUnbound.cpp
Normal file
593
src/Mod/Surface/Gui/TaskFillingUnbound.cpp
Normal file
@@ -0,0 +1,593 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2017 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* Christophe Grellier <cg[at]grellier.fr> *
|
||||
* *
|
||||
* 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"
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <GeomAbs_Shape.hxx>
|
||||
#include <TopExp.hxx>
|
||||
#include <TopTools_IndexedMapOfShape.hxx>
|
||||
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
|
||||
#include <TopTools_ListIteratorOfListOfShape.hxx>
|
||||
|
||||
#include <Gui/ViewProvider.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/SelectionObject.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Mod/Part/Gui/ViewProvider.h>
|
||||
|
||||
#include "TaskFillingUnbound.h"
|
||||
#include "ui_TaskFillingUnbound.h"
|
||||
#include "TaskFilling.h"
|
||||
|
||||
|
||||
using namespace SurfaceGui;
|
||||
|
||||
namespace SurfaceGui {
|
||||
|
||||
class FillingUnboundPanel::ShapeSelection : public Gui::SelectionFilterGate
|
||||
{
|
||||
public:
|
||||
ShapeSelection(FillingUnboundPanel::SelectionMode& mode, Surface::Filling* editedObject)
|
||||
: Gui::SelectionFilterGate(static_cast<Gui::SelectionFilter*>(nullptr))
|
||||
, mode(mode)
|
||||
, editedObject(editedObject)
|
||||
{
|
||||
}
|
||||
~ShapeSelection()
|
||||
{
|
||||
mode = FillingUnboundPanel::None;
|
||||
}
|
||||
/**
|
||||
* Allow the user to pick only edges.
|
||||
*/
|
||||
bool allow(App::Document*, App::DocumentObject* pObj, const char* sSubName)
|
||||
{
|
||||
// don't allow references to itself
|
||||
if (pObj == editedObject)
|
||||
return false;
|
||||
if (!pObj->isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
return false;
|
||||
|
||||
if (!sSubName || sSubName[0] == '\0')
|
||||
return false;
|
||||
|
||||
switch (mode) {
|
||||
case FillingUnboundPanel::AppendEdge:
|
||||
return allowEdge(true, pObj, sSubName);
|
||||
case FillingUnboundPanel::RemoveEdge:
|
||||
return allowEdge(false, pObj, sSubName);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool allowEdge(bool appendEdges, App::DocumentObject* pObj, const char* sSubName)
|
||||
{
|
||||
std::string element(sSubName);
|
||||
if (element.substr(0,4) != "Edge")
|
||||
return false;
|
||||
|
||||
auto links = editedObject->UnboundEdges.getSubListValues();
|
||||
for (auto it : links) {
|
||||
if (it.first == pObj) {
|
||||
for (auto jt : it.second) {
|
||||
if (jt == sSubName)
|
||||
return !appendEdges;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appendEdges;
|
||||
}
|
||||
|
||||
private:
|
||||
FillingUnboundPanel::SelectionMode& mode;
|
||||
Surface::Filling* editedObject;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
FillingUnboundPanel::FillingUnboundPanel(ViewProviderFilling* vp, Surface::Filling* obj)
|
||||
{
|
||||
ui = new Ui_TaskFillingUnbound();
|
||||
ui->setupUi(this);
|
||||
|
||||
selectionMode = None;
|
||||
this->vp = vp;
|
||||
checkCommand = true;
|
||||
setEditedObject(obj);
|
||||
|
||||
// Create context menu
|
||||
QAction* action = new QAction(tr("Remove"), this);
|
||||
action->setShortcut(QString::fromLatin1("Del"));
|
||||
ui->listUnbound->addAction(action);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(onDeleteUnboundEdge()));
|
||||
ui->listUnbound->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroys the object and frees any allocated resources
|
||||
*/
|
||||
FillingUnboundPanel::~FillingUnboundPanel()
|
||||
{
|
||||
// no need to delete child widgets, Qt does it all for us
|
||||
delete ui;
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
}
|
||||
|
||||
// stores object pointer, its old fill type and adjusts radio buttons according to it.
|
||||
void FillingUnboundPanel::setEditedObject(Surface::Filling* obj)
|
||||
{
|
||||
editedObject = obj;
|
||||
|
||||
// get the unbound edges, if set their adjacent faces and continuities
|
||||
auto objects = editedObject->UnboundEdges.getValues();
|
||||
auto edges = editedObject->UnboundEdges.getSubValues();
|
||||
auto count = objects.size();
|
||||
|
||||
// fill up faces if wrong size
|
||||
auto faces = editedObject->UnboundFaces.getValues();
|
||||
if (faces.size() != edges.size()) {
|
||||
faces.resize(edges.size());
|
||||
std::fill(faces.begin(), faces.end(), std::string());
|
||||
}
|
||||
|
||||
// fill up continuities if wrong size
|
||||
auto conts = editedObject->UnboundOrder.getValues();
|
||||
if (edges.size() != conts.size()) {
|
||||
conts.resize(edges.size());
|
||||
std::fill(conts.begin(), conts.end(), static_cast<long>(GeomAbs_C0));
|
||||
}
|
||||
|
||||
App::Document* doc = editedObject->getDocument();
|
||||
for (std::size_t i=0; i<count; i++) {
|
||||
App::DocumentObject* obj = objects[i];
|
||||
std::string edge = edges[i];
|
||||
std::string face = faces[i];
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(ui->listUnbound);
|
||||
ui->listUnbound->addItem(item);
|
||||
|
||||
QString text = QString::fromLatin1("%1.%2")
|
||||
.arg(QString::fromUtf8(obj->Label.getValue()))
|
||||
.arg(QString::fromStdString(edge));
|
||||
item->setText(text);
|
||||
|
||||
// The user data field of a list widget item
|
||||
// is a list of five elementa:
|
||||
// 1. document name
|
||||
// 2. object name
|
||||
// 3. sub-element name of the edge
|
||||
// 4. sub-element of an adjacent face or empty string
|
||||
// 5. the continuity as int
|
||||
QList<QVariant> data;
|
||||
data << QByteArray(doc->getName());
|
||||
data << QByteArray(obj->getNameInDocument());
|
||||
data << QByteArray(edge.c_str());
|
||||
data << QByteArray(face.c_str());
|
||||
data << static_cast<int>(conts[i]);
|
||||
item->setData(Qt::UserRole, data);
|
||||
}
|
||||
|
||||
// attach this document observer
|
||||
attachDocument(Gui::Application::Instance->getDocument(doc));
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
else {
|
||||
QWidget::changeEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::open()
|
||||
{
|
||||
checkOpenCommand();
|
||||
|
||||
// highlight the boundary edges
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), true);
|
||||
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::clearSelection()
|
||||
{
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::checkOpenCommand()
|
||||
{
|
||||
if (checkCommand && !Gui::Command::hasPendingCommand()) {
|
||||
std::string Msg("Edit ");
|
||||
Msg += editedObject->Label.getValue();
|
||||
Gui::Command::openCommand(Msg.c_str());
|
||||
checkCommand = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::slotUndoDocument(const Gui::Document&)
|
||||
{
|
||||
checkCommand = true;
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::slotRedoDocument(const Gui::Document&)
|
||||
{
|
||||
checkCommand = true;
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj)
|
||||
{
|
||||
// If this view provider is being deleted then reset the colors of
|
||||
// referenced part objects. The dialog will be deleted later.
|
||||
if (this->vp == &Obj) {
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), false);
|
||||
}
|
||||
}
|
||||
|
||||
bool FillingUnboundPanel::accept()
|
||||
{
|
||||
selectionMode = None;
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
|
||||
if (editedObject->mustExecute())
|
||||
editedObject->recomputeFeature();
|
||||
if (!editedObject->isValid()) {
|
||||
QMessageBox::warning(this, tr("Invalid object"),
|
||||
QString::fromLatin1(editedObject->getStatusString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FillingUnboundPanel::reject()
|
||||
{
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), false);
|
||||
|
||||
selectionMode = None;
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::on_buttonUnboundEdgeAdd_clicked()
|
||||
{
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject));
|
||||
selectionMode = AppendEdge;
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::on_buttonUnboundEdgeRemove_clicked()
|
||||
{
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject));
|
||||
selectionMode = RemoveEdge;
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::on_listUnbound_itemDoubleClicked(QListWidgetItem* item)
|
||||
{
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
selectionMode = None;
|
||||
|
||||
ui->comboBoxUnboundFaces->clear();
|
||||
ui->comboBoxUnboundCont->clear();
|
||||
|
||||
if (item) {
|
||||
QList<QVariant> data;
|
||||
data = item->data(Qt::UserRole).toList();
|
||||
|
||||
try {
|
||||
App::Document* doc = App::GetApplication().getDocument(data[0].toByteArray());
|
||||
App::DocumentObject* obj = doc ? doc->getObject(data[1].toByteArray()) : nullptr;
|
||||
if (obj && obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
const Part::TopoShape& shape = static_cast<Part::Feature*>(obj)->Shape.getShape();
|
||||
TopoDS_Shape edge = shape.getSubShape(data[2].toByteArray());
|
||||
|
||||
// build up map edge->face
|
||||
TopTools_IndexedMapOfShape faces;
|
||||
TopExp::MapShapes(shape.getShape(), TopAbs_FACE, faces);
|
||||
TopTools_IndexedDataMapOfShapeListOfShape edge2Face;
|
||||
TopExp::MapShapesAndAncestors(shape.getShape(), TopAbs_EDGE, TopAbs_FACE, edge2Face);
|
||||
const TopTools_ListOfShape& adj_faces = edge2Face.FindFromKey(edge);
|
||||
if (adj_faces.Extent() > 0) {
|
||||
int n = adj_faces.Extent();
|
||||
ui->statusLabel->setText(tr("Edge has %n adjacent face(s)", 0, n));
|
||||
|
||||
// fill up the combo boxes
|
||||
modifyBoundary(true);
|
||||
ui->comboBoxUnboundFaces->addItem(tr("None"), QByteArray(""));
|
||||
ui->comboBoxUnboundCont->addItem(QString::fromLatin1("C0"), static_cast<int>(GeomAbs_C0));
|
||||
ui->comboBoxUnboundCont->addItem(QString::fromLatin1("G1"), static_cast<int>(GeomAbs_G1));
|
||||
ui->comboBoxUnboundCont->addItem(QString::fromLatin1("G2"), static_cast<int>(GeomAbs_G2));
|
||||
TopTools_ListIteratorOfListOfShape it(adj_faces);
|
||||
for (; it.More(); it.Next()) {
|
||||
const TopoDS_Shape& F = it.Value();
|
||||
int index = faces.FindIndex(F);
|
||||
QString text = QString::fromLatin1("Face%1").arg(index);
|
||||
ui->comboBoxUnboundFaces->addItem(text, text.toLatin1());
|
||||
}
|
||||
|
||||
// activate face and continuity
|
||||
if (data.size() == 5) {
|
||||
int index = ui->comboBoxUnboundFaces->findData(data[3]);
|
||||
ui->comboBoxUnboundFaces->setCurrentIndex(index);
|
||||
index = ui->comboBoxUnboundCont->findData(data[4]);
|
||||
ui->comboBoxUnboundCont->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->statusLabel->setText(tr("Edge has no adjacent faces"));
|
||||
}
|
||||
}
|
||||
|
||||
Gui::Selection().addSelection(data[0].toByteArray(),
|
||||
data[1].toByteArray(),
|
||||
data[2].toByteArray());
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
{
|
||||
if (selectionMode == None)
|
||||
return;
|
||||
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
checkOpenCommand();
|
||||
if (selectionMode == AppendEdge) {
|
||||
QListWidgetItem* item = new QListWidgetItem(ui->listUnbound);
|
||||
ui->listUnbound->addItem(item);
|
||||
|
||||
Gui::SelectionObject sel(msg);
|
||||
QString text = QString::fromLatin1("%1.%2")
|
||||
.arg(QString::fromUtf8(sel.getObject()->Label.getValue()))
|
||||
.arg(QString::fromLatin1(msg.pSubName));
|
||||
item->setText(text);
|
||||
|
||||
QList<QVariant> data;
|
||||
data << QByteArray(msg.pDocName);
|
||||
data << QByteArray(msg.pObjectName);
|
||||
data << QByteArray(msg.pSubName);
|
||||
data << QByteArray("");
|
||||
data << static_cast<int>(GeomAbs_C0);
|
||||
item->setData(Qt::UserRole, data);
|
||||
|
||||
auto objects = editedObject->UnboundEdges.getValues();
|
||||
std::size_t count = objects.size();
|
||||
objects.push_back(sel.getObject());
|
||||
auto element = editedObject->UnboundEdges.getSubValues();
|
||||
element.push_back(msg.pSubName);
|
||||
editedObject->UnboundEdges.setValues(objects, element);
|
||||
|
||||
// extend faces and continuities lists if needed
|
||||
auto faces = editedObject->UnboundFaces.getValues();
|
||||
if (count == faces.size()) {
|
||||
faces.push_back(std::string());
|
||||
editedObject->UnboundFaces.setValues(faces);
|
||||
}
|
||||
auto conts = editedObject->UnboundOrder.getValues();
|
||||
if (count == conts.size()) {
|
||||
conts.push_back(static_cast<long>(GeomAbs_C0));
|
||||
editedObject->UnboundOrder.setValues(conts);
|
||||
}
|
||||
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), true);
|
||||
}
|
||||
else if (selectionMode == RemoveEdge) {
|
||||
Gui::SelectionObject sel(msg);
|
||||
QList<QVariant> data;
|
||||
data << QByteArray(msg.pDocName);
|
||||
data << QByteArray(msg.pObjectName);
|
||||
data << QByteArray(msg.pSubName);
|
||||
|
||||
// only the three first elements must match
|
||||
for (int i=0; i<ui->listUnbound->count(); i++) {
|
||||
QListWidgetItem* item = ui->listUnbound->item(i);
|
||||
QList<QVariant> userdata = item->data(Qt::UserRole).toList();
|
||||
if (userdata.mid(0,3) == data) {
|
||||
ui->listUnbound->takeItem(i);
|
||||
delete item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), false);
|
||||
App::DocumentObject* obj = sel.getObject();
|
||||
std::string sub = msg.pSubName;
|
||||
auto objects = editedObject->UnboundEdges.getValues();
|
||||
auto element = editedObject->UnboundEdges.getSubValues();
|
||||
auto it = objects.begin();
|
||||
auto jt = element.begin();
|
||||
|
||||
for (; it != objects.end() && jt != element.end(); ++it, ++jt) {
|
||||
if (*it == obj && *jt == sub) {
|
||||
std::size_t index = std::distance(objects.begin(), it);
|
||||
|
||||
objects.erase(it);
|
||||
element.erase(jt);
|
||||
editedObject->UnboundEdges.setValues(objects, element);
|
||||
|
||||
// try to remove the item also from the faces
|
||||
auto faces = editedObject->UnboundFaces.getValues();
|
||||
if (index < faces.size()) {
|
||||
faces.erase(faces.begin() + index);
|
||||
editedObject->UnboundFaces.setValues(faces);
|
||||
}
|
||||
|
||||
// try to remove the item also from the orders
|
||||
auto order = editedObject->UnboundOrder.getValues();
|
||||
if (index < order.size()) {
|
||||
order.erase(order.begin() + index);
|
||||
editedObject->UnboundOrder.setValues(order);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), true);
|
||||
}
|
||||
|
||||
editedObject->recomputeFeature();
|
||||
QTimer::singleShot(50, this, SLOT(clearSelection()));
|
||||
}
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::onDeleteUnboundEdge()
|
||||
{
|
||||
int row = ui->listUnbound->currentRow();
|
||||
QListWidgetItem* item = ui->listUnbound->item(row);
|
||||
if (item) {
|
||||
checkOpenCommand();
|
||||
QList<QVariant> data;
|
||||
data = item->data(Qt::UserRole).toList();
|
||||
ui->listUnbound->takeItem(row);
|
||||
delete item;
|
||||
|
||||
App::Document* doc = App::GetApplication().getDocument(data[0].toByteArray());
|
||||
App::DocumentObject* obj = doc ? doc->getObject(data[1].toByteArray()) : nullptr;
|
||||
std::string sub = data[2].toByteArray().constData();
|
||||
auto objects = editedObject->UnboundEdges.getValues();
|
||||
auto element = editedObject->UnboundEdges.getSubValues();
|
||||
auto it = objects.begin();
|
||||
auto jt = element.begin();
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), false);
|
||||
for (; it != objects.end() && jt != element.end(); ++it, ++jt) {
|
||||
if (*it == obj && *jt == sub) {
|
||||
std::size_t index = std::distance(objects.begin(), it);
|
||||
|
||||
objects.erase(it);
|
||||
element.erase(jt);
|
||||
editedObject->UnboundEdges.setValues(objects, element);
|
||||
|
||||
// try to remove the item also from the faces
|
||||
auto faces = editedObject->UnboundFaces.getValues();
|
||||
if (index < faces.size()) {
|
||||
faces.erase(faces.begin() + index);
|
||||
editedObject->UnboundFaces.setValues(faces);
|
||||
}
|
||||
|
||||
// try to remove the item also from the orders
|
||||
auto order = editedObject->UnboundOrder.getValues();
|
||||
if (index < order.size()) {
|
||||
order.erase(order.begin() + index);
|
||||
editedObject->UnboundOrder.setValues(order);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->UnboundEdges.getSubListValues(), true);
|
||||
|
||||
editedObject->recomputeFeature();
|
||||
}
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::on_buttonUnboundAccept_clicked()
|
||||
{
|
||||
QListWidgetItem* item = ui->listUnbound->currentItem();
|
||||
if (item) {
|
||||
QList<QVariant> data;
|
||||
data = item->data(Qt::UserRole).toList();
|
||||
|
||||
QVariant face = ui->comboBoxUnboundFaces->itemData(ui->comboBoxUnboundFaces->currentIndex());
|
||||
QVariant cont = ui->comboBoxUnboundCont->itemData(ui->comboBoxUnboundCont->currentIndex());
|
||||
if (data.size() == 5) {
|
||||
data[3] = face;
|
||||
data[4] = cont;
|
||||
}
|
||||
else {
|
||||
data << face;
|
||||
data << cont;
|
||||
}
|
||||
|
||||
item->setData(Qt::UserRole, data);
|
||||
|
||||
std::size_t index = ui->listUnbound->row(item);
|
||||
|
||||
// try to set the item of the faces
|
||||
auto faces = editedObject->UnboundFaces.getValues();
|
||||
if (index < faces.size()) {
|
||||
faces[index] = face.toByteArray().data();
|
||||
editedObject->UnboundFaces.setValues(faces);
|
||||
}
|
||||
|
||||
// try to set the item of the orders
|
||||
auto order = editedObject->UnboundOrder.getValues();
|
||||
if (index < order.size()) {
|
||||
order[index] = cont.toInt();
|
||||
editedObject->UnboundOrder.setValues(order);
|
||||
}
|
||||
}
|
||||
|
||||
modifyBoundary(false);
|
||||
ui->comboBoxUnboundFaces->clear();
|
||||
ui->comboBoxUnboundCont->clear();
|
||||
ui->statusLabel->clear();
|
||||
|
||||
editedObject->recomputeFeature();
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::on_buttonUnboundIgnore_clicked()
|
||||
{
|
||||
modifyBoundary(false);
|
||||
ui->comboBoxUnboundFaces->clear();
|
||||
ui->comboBoxUnboundCont->clear();
|
||||
ui->statusLabel->clear();
|
||||
}
|
||||
|
||||
void FillingUnboundPanel::modifyBoundary(bool on)
|
||||
{
|
||||
ui->buttonUnboundEdgeAdd->setDisabled(on);
|
||||
ui->buttonUnboundEdgeRemove->setDisabled(on);
|
||||
ui->listUnbound->setDisabled(on);
|
||||
|
||||
ui->comboBoxUnboundFaces->setEnabled(on);
|
||||
ui->comboBoxUnboundCont->setEnabled(on);
|
||||
ui->buttonUnboundAccept->setEnabled(on);
|
||||
ui->buttonUnboundIgnore->setEnabled(on);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_TaskFillingUnbound.cpp"
|
||||
93
src/Mod/Surface/Gui/TaskFillingUnbound.h
Normal file
93
src/Mod/Surface/Gui/TaskFillingUnbound.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2017 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* Christophe Grellier <cg[at]grellier.fr> *
|
||||
* *
|
||||
* 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 SURFACEGUI_TASKFILLINGUNBOUND_H
|
||||
#define SURFACEGUI_TASKFILLINGUNBOUND_H
|
||||
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/SelectionFilter.h>
|
||||
#include <Gui/DocumentObserver.h>
|
||||
#include <Base/BoundBox.h>
|
||||
#include <Mod/Part/Gui/ViewProviderSpline.h>
|
||||
#include <Mod/Surface/App/FeatureFilling.h>
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace SurfaceGui
|
||||
{
|
||||
|
||||
class ViewProviderFilling;
|
||||
class Ui_TaskFillingUnbound;
|
||||
|
||||
class FillingUnboundPanel : public QWidget,
|
||||
public Gui::SelectionObserver,
|
||||
public Gui::DocumentObserver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
class ShapeSelection;
|
||||
enum SelectionMode { None, AppendEdge, RemoveEdge };
|
||||
SelectionMode selectionMode;
|
||||
Surface::Filling* editedObject;
|
||||
bool checkCommand;
|
||||
|
||||
private:
|
||||
Ui_TaskFillingUnbound* ui;
|
||||
ViewProviderFilling* vp;
|
||||
|
||||
public:
|
||||
FillingUnboundPanel(ViewProviderFilling* vp, Surface::Filling* obj);
|
||||
~FillingUnboundPanel();
|
||||
|
||||
void open();
|
||||
void checkOpenCommand();
|
||||
bool accept();
|
||||
bool reject();
|
||||
void setEditedObject(Surface::Filling* obj);
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
|
||||
/** Notifies on undo */
|
||||
virtual void slotUndoDocument(const Gui::Document& Doc);
|
||||
/** Notifies on redo */
|
||||
virtual void slotRedoDocument(const Gui::Document& Doc);
|
||||
/** Notifies when the object is about to be removed. */
|
||||
virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj);
|
||||
void modifyBoundary(bool);
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_buttonUnboundEdgeAdd_clicked();
|
||||
void on_buttonUnboundEdgeRemove_clicked();
|
||||
void on_listUnbound_itemDoubleClicked(QListWidgetItem*);
|
||||
void on_buttonUnboundAccept_clicked();
|
||||
void on_buttonUnboundIgnore_clicked();
|
||||
void onDeleteUnboundEdge(void);
|
||||
void clearSelection();
|
||||
};
|
||||
|
||||
} //namespace SurfaceGui
|
||||
|
||||
#endif // SURFACEGUI_TASKFILLINGUNBOUND_H
|
||||
159
src/Mod/Surface/Gui/TaskFillingUnbound.ui
Normal file
159
src/Mod/Surface/Gui/TaskFillingUnbound.ui
Normal file
@@ -0,0 +1,159 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SurfaceGui::TaskFillingUnbound</class>
|
||||
<widget class="QWidget" name="SurfaceGui::TaskFillingUnbound">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>360</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Unbound Edges</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Unbound Edges</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QListWidget" name="listUnbound"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Faces:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="comboBoxUnboundFaces">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Continuity:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="comboBoxUnboundCont">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Maximum</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>74</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QPushButton" name="buttonUnboundAccept">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Accept</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QPushButton" name="buttonUnboundIgnore">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ignore</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonUnboundEdgeAdd">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add Edge</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonUnboundEdgeRemove">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove Edge</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="text">
|
||||
<string notr="true">Status messages</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user