Extend task panel for filling function
This commit is contained in:
@@ -25,6 +25,7 @@ set(SurfaceGui_LIBS
|
||||
|
||||
set(SurfaceGui_MOC_HDRS
|
||||
TaskFilling.h
|
||||
TaskFillingVertex.h
|
||||
TaskGeomFillSurface.h
|
||||
)
|
||||
fc_wrap_cpp(SurfaceGui_MOC_SRCS ${SurfaceGui_MOC_HDRS})
|
||||
@@ -38,6 +39,7 @@ endif()
|
||||
|
||||
SET(SurfaceGui_UIC_SRCS
|
||||
TaskFilling.ui
|
||||
TaskFillingVertex.ui
|
||||
TaskGeomFillSurface.ui
|
||||
)
|
||||
|
||||
@@ -52,6 +54,8 @@ SET(SurfaceGui_SRCS
|
||||
${SurfaceGui_UIC_HDRS}
|
||||
TaskFilling.cpp
|
||||
TaskFilling.h
|
||||
TaskFillingVertex.cpp
|
||||
TaskFillingVertex.h
|
||||
TaskGeomFillSurface.cpp
|
||||
TaskGeomFillSurface.h
|
||||
AppSurfaceGui.cpp
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <Mod/Part/Gui/ViewProvider.h>
|
||||
|
||||
#include "TaskFilling.h"
|
||||
#include "TaskFillingVertex.h"
|
||||
#include "ui_TaskFilling.h"
|
||||
|
||||
|
||||
@@ -104,32 +105,74 @@ QIcon ViewProviderFilling::getIcon(void) const
|
||||
return Gui::BitmapFactory().pixmap("BSplineSurf");
|
||||
}
|
||||
|
||||
void ViewProviderFilling::highlightReferences(bool on)
|
||||
void ViewProviderFilling::highlightReferences(ShapeType type, const References& refs, bool on)
|
||||
{
|
||||
Surface::Filling* surface = static_cast<Surface::Filling*>(getObject());
|
||||
auto bounds = surface->BoundaryEdges.getSubListValues();
|
||||
for (auto it : bounds) {
|
||||
for (auto it : refs) {
|
||||
Part::Feature* base = dynamic_cast<Part::Feature*>(it.first);
|
||||
if (base) {
|
||||
PartGui::ViewProviderPartExt* svp = dynamic_cast<PartGui::ViewProviderPartExt*>(
|
||||
Gui::Application::Instance->getViewProvider(base));
|
||||
if (svp) {
|
||||
if (on) {
|
||||
std::vector<App::Color> colors;
|
||||
TopTools_IndexedMapOfShape eMap;
|
||||
TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, eMap);
|
||||
colors.resize(eMap.Extent(), svp->LineColor.getValue());
|
||||
switch (type) {
|
||||
case ViewProviderFilling::Vertex:
|
||||
#if 0 //FIXME
|
||||
if (on) {
|
||||
std::vector<App::Color> colors;
|
||||
TopTools_IndexedMapOfShape vMap;
|
||||
TopExp::MapShapes(base->Shape.getValue(), TopAbs_VERTEX, vMap);
|
||||
colors.resize(vMap.Extent(), svp->PointColor.getValue());
|
||||
|
||||
for (auto jt : it.second) {
|
||||
std::size_t idx = static_cast<std::size_t>(std::stoi(jt.substr(4)) - 1);
|
||||
assert (idx < colors.size());
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
for (auto jt : it.second) {
|
||||
std::size_t idx = static_cast<std::size_t>(std::stoi(jt.substr(6)) - 1);
|
||||
assert (idx < colors.size());
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
}
|
||||
|
||||
svp->setHighlightedPoints(colors);
|
||||
}
|
||||
else {
|
||||
svp->unsetHighlightedPoints();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case ViewProviderFilling::Edge:
|
||||
if (on) {
|
||||
std::vector<App::Color> colors;
|
||||
TopTools_IndexedMapOfShape eMap;
|
||||
TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, eMap);
|
||||
colors.resize(eMap.Extent(), svp->LineColor.getValue());
|
||||
|
||||
svp->setHighlightedEdges(colors);
|
||||
}
|
||||
else {
|
||||
svp->unsetHighlightedEdges();
|
||||
for (auto jt : it.second) {
|
||||
std::size_t idx = static_cast<std::size_t>(std::stoi(jt.substr(4)) - 1);
|
||||
assert (idx < colors.size());
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
}
|
||||
|
||||
svp->setHighlightedEdges(colors);
|
||||
}
|
||||
else {
|
||||
svp->unsetHighlightedEdges();
|
||||
}
|
||||
break;
|
||||
case ViewProviderFilling::Face:
|
||||
if (on) {
|
||||
std::vector<App::Color> colors;
|
||||
TopTools_IndexedMapOfShape fMap;
|
||||
TopExp::MapShapes(base->Shape.getValue(), TopAbs_FACE, fMap);
|
||||
colors.resize(fMap.Extent(), svp->ShapeColor.getValue());
|
||||
|
||||
for (auto jt : it.second) {
|
||||
std::size_t idx = static_cast<std::size_t>(std::stoi(jt.substr(4)) - 1);
|
||||
assert (idx < colors.size());
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
}
|
||||
|
||||
svp->setHighlightedFaces(colors);
|
||||
}
|
||||
else {
|
||||
svp->unsetHighlightedFaces();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,12 +184,16 @@ void ViewProviderFilling::highlightReferences(bool on)
|
||||
class FillingPanel::ShapeSelection : public Gui::SelectionFilterGate
|
||||
{
|
||||
public:
|
||||
ShapeSelection(FillingPanel::SelectionMode mode, Surface::Filling* editedObject)
|
||||
ShapeSelection(FillingPanel::SelectionMode& mode, Surface::Filling* editedObject)
|
||||
: Gui::SelectionFilterGate(static_cast<Gui::SelectionFilter*>(nullptr))
|
||||
, mode(mode)
|
||||
, editedObject(editedObject)
|
||||
{
|
||||
}
|
||||
~ShapeSelection()
|
||||
{
|
||||
mode = FillingPanel::None;
|
||||
}
|
||||
/**
|
||||
* Allow the user to pick only edges.
|
||||
*/
|
||||
@@ -201,7 +248,7 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
FillingPanel::SelectionMode mode;
|
||||
FillingPanel::SelectionMode& mode;
|
||||
Surface::Filling* editedObject;
|
||||
};
|
||||
|
||||
@@ -286,7 +333,8 @@ void FillingPanel::changeEvent(QEvent *e)
|
||||
void FillingPanel::open()
|
||||
{
|
||||
checkOpenCommand();
|
||||
this->vp->highlightReferences(true);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->BoundaryEdges.getSubListValues(), true);
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
|
||||
@@ -328,7 +376,8 @@ bool FillingPanel::accept()
|
||||
return false;
|
||||
}
|
||||
|
||||
this->vp->highlightReferences(false);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->BoundaryEdges.getSubListValues(), false);
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||
@@ -338,7 +387,8 @@ bool FillingPanel::accept()
|
||||
|
||||
bool FillingPanel::reject()
|
||||
{
|
||||
this->vp->highlightReferences(false);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->BoundaryEdges.getSubListValues(), false);
|
||||
selectionMode = None;
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
|
||||
@@ -359,20 +409,23 @@ void FillingPanel::on_lineInitFaceName_textChanged(const QString& text)
|
||||
|
||||
void FillingPanel::on_buttonInitFace_clicked()
|
||||
{
|
||||
selectionMode = InitFace;
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject));
|
||||
selectionMode = InitFace;
|
||||
}
|
||||
|
||||
void FillingPanel::on_buttonEdgeAdd_clicked()
|
||||
{
|
||||
selectionMode = AppendEdge;
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject));
|
||||
selectionMode = AppendEdge;
|
||||
}
|
||||
|
||||
void FillingPanel::on_buttonEdgeRemove_clicked()
|
||||
{
|
||||
selectionMode = RemoveEdge;
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject));
|
||||
selectionMode = RemoveEdge;
|
||||
}
|
||||
|
||||
void FillingPanel::on_listBoundary_itemDoubleClicked(QListWidgetItem* item)
|
||||
@@ -457,7 +510,7 @@ void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
std::vector<std::string> subList;
|
||||
subList.push_back(msg.pSubName);
|
||||
editedObject->InitialFace.setValue(sel.getObject(), subList);
|
||||
//this->vp->highlightReferences(true);
|
||||
//this->vp->highlightReferences(..., true);
|
||||
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
selectionMode = None;
|
||||
@@ -483,7 +536,8 @@ void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
auto element = editedObject->BoundaryEdges.getSubValues();
|
||||
element.push_back(msg.pSubName);
|
||||
editedObject->BoundaryEdges.setValues(objects, element);
|
||||
this->vp->highlightReferences(true);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->BoundaryEdges.getSubListValues(), true);
|
||||
}
|
||||
else if (selectionMode == RemoveEdge) {
|
||||
Gui::SelectionObject sel(msg);
|
||||
@@ -499,7 +553,8 @@ void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
}
|
||||
}
|
||||
|
||||
this->vp->highlightReferences(false);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->BoundaryEdges.getSubListValues(), false);
|
||||
App::DocumentObject* obj = sel.getObject();
|
||||
std::string sub = msg.pSubName;
|
||||
auto objects = editedObject->BoundaryEdges.getValues();
|
||||
@@ -514,7 +569,8 @@ void FillingPanel::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vp->highlightReferences(true);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->BoundaryEdges.getSubListValues(), true);
|
||||
}
|
||||
|
||||
editedObject->recomputeFeature();
|
||||
@@ -540,7 +596,8 @@ void FillingPanel::onDeleteEdge()
|
||||
auto element = editedObject->BoundaryEdges.getSubValues();
|
||||
auto it = objects.begin();
|
||||
auto jt = element.begin();
|
||||
this->vp->highlightReferences(false);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->BoundaryEdges.getSubListValues(), false);
|
||||
for (; it != objects.end() && jt != element.end(); ++it, ++jt) {
|
||||
if (*it == obj && *jt == sub) {
|
||||
objects.erase(it);
|
||||
@@ -549,7 +606,8 @@ void FillingPanel::onDeleteEdge()
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vp->highlightReferences(true);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Edge,
|
||||
editedObject->BoundaryEdges.getSubListValues(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,13 +664,21 @@ void FillingPanel::modifyBoundary(bool on)
|
||||
|
||||
TaskFilling::TaskFilling(ViewProviderFilling* vp, Surface::Filling* obj)
|
||||
{
|
||||
widget = new FillingPanel(vp, obj);
|
||||
widget->setWindowTitle(QObject::tr("Surface"));
|
||||
taskbox = new Gui::TaskView::TaskBox(
|
||||
// first task box
|
||||
widget1 = new FillingPanel(vp, obj);
|
||||
Gui::TaskView::TaskBox* taskbox1 = new Gui::TaskView::TaskBox(
|
||||
Gui::BitmapFactory().pixmap("BezSurf"),
|
||||
widget->windowTitle(), true, 0);
|
||||
taskbox->groupLayout()->addWidget(widget);
|
||||
Content.push_back(taskbox);
|
||||
widget1->windowTitle(), true, 0);
|
||||
taskbox1->groupLayout()->addWidget(widget1);
|
||||
Content.push_back(taskbox1);
|
||||
|
||||
// second task box
|
||||
widget2 = new FillingVertexPanel(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();
|
||||
}
|
||||
|
||||
TaskFilling::~TaskFilling()
|
||||
@@ -622,22 +688,22 @@ TaskFilling::~TaskFilling()
|
||||
|
||||
void TaskFilling::setEditedObject(Surface::Filling* obj)
|
||||
{
|
||||
widget->setEditedObject(obj);
|
||||
widget1->setEditedObject(obj);
|
||||
}
|
||||
|
||||
void TaskFilling::open()
|
||||
{
|
||||
widget->open();
|
||||
widget1->open();
|
||||
}
|
||||
|
||||
bool TaskFilling::accept()
|
||||
{
|
||||
return widget->accept();
|
||||
return widget1->accept();
|
||||
}
|
||||
|
||||
bool TaskFilling::reject()
|
||||
{
|
||||
return widget->reject();
|
||||
return widget1->reject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,17 +36,21 @@ class QListWidgetItem;
|
||||
namespace SurfaceGui
|
||||
{
|
||||
|
||||
class FillingVertexPanel;
|
||||
class Ui_TaskFilling;
|
||||
|
||||
class ViewProviderFilling : public PartGui::ViewProviderSpline
|
||||
{
|
||||
PROPERTY_HEADER(SurfaceGui::ViewProviderFilling);
|
||||
typedef std::vector<App::PropertyLinkSubList::SubSet> References;
|
||||
|
||||
public:
|
||||
enum ShapeType {Vertex, Edge, Face};
|
||||
virtual void setupContextMenu(QMenu*, QObject*, const char*);
|
||||
virtual bool setEdit(int ModNum);
|
||||
virtual void unsetEdit(int ModNum);
|
||||
QIcon getIcon(void) const;
|
||||
void highlightReferences(bool on);
|
||||
void highlightReferences(ShapeType type, const References& refs, bool on);
|
||||
};
|
||||
|
||||
class FillingPanel : public QWidget,
|
||||
@@ -115,8 +119,8 @@ public:
|
||||
{ return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; }
|
||||
|
||||
private:
|
||||
FillingPanel* widget;
|
||||
Gui::TaskView::TaskBox* taskbox;
|
||||
FillingPanel* widget1;
|
||||
FillingVertexPanel* widget2;
|
||||
};
|
||||
|
||||
} //namespace SurfaceGui
|
||||
|
||||
340
src/Mod/Surface/Gui/TaskFillingVertex.cpp
Normal file
340
src/Mod/Surface/Gui/TaskFillingVertex.cpp
Normal file
@@ -0,0 +1,340 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Balázs Bámer *
|
||||
* 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"
|
||||
#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 "TaskFillingVertex.h"
|
||||
#include "ui_TaskFillingVertex.h"
|
||||
#include "TaskFilling.h"
|
||||
|
||||
|
||||
using namespace SurfaceGui;
|
||||
|
||||
namespace SurfaceGui {
|
||||
|
||||
class FillingVertexPanel::VertexSelection : public Gui::SelectionFilterGate
|
||||
{
|
||||
public:
|
||||
VertexSelection(FillingVertexPanel::SelectionMode& mode, Surface::Filling* editedObject)
|
||||
: Gui::SelectionFilterGate(static_cast<Gui::SelectionFilter*>(nullptr))
|
||||
, mode(mode)
|
||||
, editedObject(editedObject)
|
||||
{
|
||||
}
|
||||
~VertexSelection()
|
||||
{
|
||||
mode = FillingVertexPanel::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 FillingVertexPanel::AppendVertex:
|
||||
return allowVertex(true, pObj, sSubName);
|
||||
case FillingVertexPanel::RemoveVertex:
|
||||
return allowVertex(false, pObj, sSubName);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool allowVertex(bool appendVertex, App::DocumentObject* pObj, const char* sSubName)
|
||||
{
|
||||
std::string element(sSubName);
|
||||
if (element.substr(0,6) != "Vertex")
|
||||
return false;
|
||||
|
||||
auto links = editedObject->Points.getSubListValues();
|
||||
for (auto it : links) {
|
||||
if (it.first == pObj) {
|
||||
for (auto jt : it.second) {
|
||||
if (jt == sSubName)
|
||||
return !appendVertex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appendVertex;
|
||||
}
|
||||
|
||||
private:
|
||||
FillingVertexPanel::SelectionMode& mode;
|
||||
Surface::Filling* editedObject;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
FillingVertexPanel::FillingVertexPanel(ViewProviderFilling* vp, Surface::Filling* obj)
|
||||
{
|
||||
ui = new Ui_TaskFillingVertex();
|
||||
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->listFreeVertex->addAction(action);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(onDeleteVertex()));
|
||||
ui->listFreeVertex->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroys the object and frees any allocated resources
|
||||
*/
|
||||
FillingVertexPanel::~FillingVertexPanel()
|
||||
{
|
||||
// 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 FillingVertexPanel::setEditedObject(Surface::Filling* obj)
|
||||
{
|
||||
editedObject = obj;
|
||||
|
||||
auto objects = editedObject->Points.getValues();
|
||||
auto element = editedObject->Points.getSubValues();
|
||||
auto it = objects.begin();
|
||||
auto jt = element.begin();
|
||||
|
||||
App::Document* doc = editedObject->getDocument();
|
||||
for (; it != objects.end() && jt != element.end(); ++it, ++jt) {
|
||||
QListWidgetItem* item = new QListWidgetItem(ui->listFreeVertex);
|
||||
ui->listFreeVertex->addItem(item);
|
||||
|
||||
QString text = QString::fromLatin1("%1.%2")
|
||||
.arg(QString::fromUtf8((*it)->Label.getValue()))
|
||||
.arg(QString::fromStdString(*jt));
|
||||
item->setText(text);
|
||||
|
||||
QList<QVariant> data;
|
||||
data << QByteArray(doc->getName());
|
||||
data << QByteArray((*it)->getNameInDocument());
|
||||
data << QByteArray(jt->c_str());
|
||||
item->setData(Qt::UserRole, data);
|
||||
}
|
||||
attachDocument(Gui::Application::Instance->getDocument(doc));
|
||||
}
|
||||
|
||||
void FillingVertexPanel::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
else {
|
||||
QWidget::changeEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void FillingVertexPanel::open()
|
||||
{
|
||||
checkOpenCommand();
|
||||
this->vp->highlightReferences(ViewProviderFilling::Vertex,
|
||||
editedObject->Points.getSubListValues(), true);
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
|
||||
void FillingVertexPanel::clearSelection()
|
||||
{
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
|
||||
void FillingVertexPanel::checkOpenCommand()
|
||||
{
|
||||
if (checkCommand && !Gui::Command::hasPendingCommand()) {
|
||||
std::string Msg("Edit ");
|
||||
Msg += editedObject->Label.getValue();
|
||||
Gui::Command::openCommand(Msg.c_str());
|
||||
checkCommand = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FillingVertexPanel::slotUndoDocument(const Gui::Document&)
|
||||
{
|
||||
checkCommand = true;
|
||||
}
|
||||
|
||||
void FillingVertexPanel::slotRedoDocument(const Gui::Document&)
|
||||
{
|
||||
checkCommand = true;
|
||||
}
|
||||
|
||||
void FillingVertexPanel::on_buttonVertexAdd_clicked()
|
||||
{
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new VertexSelection(selectionMode, editedObject));
|
||||
selectionMode = AppendVertex;
|
||||
}
|
||||
|
||||
void FillingVertexPanel::on_buttonVertexRemove_clicked()
|
||||
{
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new VertexSelection(selectionMode, editedObject));
|
||||
selectionMode = RemoveVertex;
|
||||
}
|
||||
|
||||
void FillingVertexPanel::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
{
|
||||
if (selectionMode == None)
|
||||
return;
|
||||
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
checkOpenCommand();
|
||||
if (selectionMode == AppendVertex) {
|
||||
QListWidgetItem* item = new QListWidgetItem(ui->listFreeVertex);
|
||||
ui->listFreeVertex->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);
|
||||
item->setData(Qt::UserRole, data);
|
||||
|
||||
auto objects = editedObject->Points.getValues();
|
||||
objects.push_back(sel.getObject());
|
||||
auto element = editedObject->Points.getSubValues();
|
||||
element.push_back(msg.pSubName);
|
||||
editedObject->Points.setValues(objects, element);
|
||||
this->vp->highlightReferences(ViewProviderFilling::Vertex,
|
||||
editedObject->Points.getSubListValues(), true);
|
||||
}
|
||||
else if (selectionMode == RemoveVertex) {
|
||||
Gui::SelectionObject sel(msg);
|
||||
QList<QVariant> data;
|
||||
data << QByteArray(msg.pDocName);
|
||||
data << QByteArray(msg.pObjectName);
|
||||
data << QByteArray(msg.pSubName);
|
||||
for (int i=0; i<ui->listFreeVertex->count(); i++) {
|
||||
QListWidgetItem* item = ui->listFreeVertex->item(i);
|
||||
if (item && item->data(Qt::UserRole) == data) {
|
||||
ui->listFreeVertex->takeItem(i);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
this->vp->highlightReferences(ViewProviderFilling::Vertex,
|
||||
editedObject->Points.getSubListValues(), false);
|
||||
App::DocumentObject* obj = sel.getObject();
|
||||
std::string sub = msg.pSubName;
|
||||
auto objects = editedObject->Points.getValues();
|
||||
auto element = editedObject->Points.getSubValues();
|
||||
auto it = objects.begin();
|
||||
auto jt = element.begin();
|
||||
for (; it != objects.end() && jt != element.end(); ++it, ++jt) {
|
||||
if (*it == obj && *jt == sub) {
|
||||
objects.erase(it);
|
||||
element.erase(jt);
|
||||
editedObject->Points.setValues(objects, element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vp->highlightReferences(ViewProviderFilling::Vertex,
|
||||
editedObject->Points.getSubListValues(), false);
|
||||
}
|
||||
|
||||
editedObject->recomputeFeature();
|
||||
QTimer::singleShot(50, this, SLOT(clearSelection()));
|
||||
}
|
||||
}
|
||||
|
||||
void FillingVertexPanel::onDeleteVertex()
|
||||
{
|
||||
int row = ui->listFreeVertex->currentRow();
|
||||
QListWidgetItem* item = ui->listFreeVertex->item(row);
|
||||
if (item) {
|
||||
checkOpenCommand();
|
||||
QList<QVariant> data;
|
||||
data = item->data(Qt::UserRole).toList();
|
||||
ui->listFreeVertex->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->Points.getValues();
|
||||
auto element = editedObject->Points.getSubValues();
|
||||
auto it = objects.begin();
|
||||
auto jt = element.begin();
|
||||
this->vp->highlightReferences(ViewProviderFilling::Vertex,
|
||||
editedObject->Points.getSubListValues(), false);
|
||||
|
||||
for (; it != objects.end() && jt != element.end(); ++it, ++jt) {
|
||||
if (*it == obj && *jt == sub) {
|
||||
objects.erase(it);
|
||||
element.erase(jt);
|
||||
editedObject->Points.setValues(objects, element);
|
||||
editedObject->recomputeFeature();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->vp->highlightReferences(ViewProviderFilling::Vertex,
|
||||
editedObject->Points.getSubListValues(), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "moc_TaskFillingVertex.cpp"
|
||||
84
src/Mod/Surface/Gui/TaskFillingVertex.h
Normal file
84
src/Mod/Surface/Gui/TaskFillingVertex.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Balázs Bámer *
|
||||
* *
|
||||
* 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_TASKFILLINGVERTEX_H
|
||||
#define SURFACEGUI_TASKFILLINGVERTEX_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_TaskFillingVertex;
|
||||
|
||||
class FillingVertexPanel : public QWidget,
|
||||
public Gui::SelectionObserver,
|
||||
public Gui::DocumentObserver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
class VertexSelection;
|
||||
enum SelectionMode { None, AppendVertex, RemoveVertex };
|
||||
SelectionMode selectionMode;
|
||||
Surface::Filling* editedObject;
|
||||
bool checkCommand;
|
||||
|
||||
private:
|
||||
Ui_TaskFillingVertex* ui;
|
||||
ViewProviderFilling* vp;
|
||||
|
||||
public:
|
||||
FillingVertexPanel(ViewProviderFilling* vp, Surface::Filling* obj);
|
||||
~FillingVertexPanel();
|
||||
|
||||
void open();
|
||||
void checkOpenCommand();
|
||||
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);
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_buttonVertexAdd_clicked();
|
||||
void on_buttonVertexRemove_clicked();
|
||||
void onDeleteVertex(void);
|
||||
void clearSelection();
|
||||
};
|
||||
|
||||
} //namespace SurfaceGui
|
||||
|
||||
#endif // SURFACEGUI_TASKFILLINGVERTEX_H
|
||||
75
src/Mod/Surface/Gui/TaskFillingVertex.ui
Normal file
75
src/Mod/Surface/Gui/TaskFillingVertex.ui
Normal file
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SurfaceGui::TaskFillingVertex</class>
|
||||
<widget class="QWidget" name="SurfaceGui::TaskFillingVertex">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>273</width>
|
||||
<height>329</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Vertexes</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Unbound vertexes</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonVertexAdd">
|
||||
<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 Vertex</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonVertexRemove">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove Vertex</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QListWidget" name="listFreeVertex"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user