Surface: add command to create surface from sections
This commit is contained in:
@@ -1514,6 +1514,7 @@ PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *k
|
||||
|
||||
/*!
|
||||
* \code
|
||||
import math
|
||||
c = Part.Circle()
|
||||
c.Radius=50
|
||||
c = c.trim(0, math.pi)
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "FeatureCut.h"
|
||||
#include "FeatureGeomFillSurface.h"
|
||||
#include "FeatureExtend.h"
|
||||
#include "FeatureSections.h"
|
||||
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Parameter.h>
|
||||
@@ -80,6 +81,7 @@ PyMOD_INIT_FUNC(Surface)
|
||||
Surface::Cut ::init();
|
||||
Surface::GeomFillSurface ::init();
|
||||
Surface::Extend ::init();
|
||||
Surface::Sections ::init();
|
||||
|
||||
PyMOD_Return(mod);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ SET(Surface_SRCS
|
||||
FeatureGeomFillSurface.h
|
||||
FeatureFilling.cpp
|
||||
FeatureFilling.h
|
||||
FeatureSections.cpp
|
||||
FeatureSections.h
|
||||
FeatureSewing.cpp
|
||||
FeatureSewing.h
|
||||
FeatureCut.cpp
|
||||
|
||||
103
src/Mod/Surface/App/FeatureSections.cpp
Normal file
103
src/Mod/Surface/App/FeatureSections.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepBuilderAPI_MakeFace.hxx>
|
||||
#include <Geom_BSplineSurface.hxx>
|
||||
#include <Geom_TrimmedCurve.hxx>
|
||||
#include <GeomAdaptor_Curve.hxx>
|
||||
#include <GeomFill_NSections.hxx>
|
||||
#include <TopLoc_Location.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <Standard_Version.hxx>
|
||||
#endif
|
||||
|
||||
#include "FeatureSections.h"
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Exception.h>
|
||||
|
||||
using namespace Surface;
|
||||
|
||||
PROPERTY_SOURCE(Surface::Sections, Part::Spline)
|
||||
|
||||
Sections::Sections()
|
||||
{
|
||||
ADD_PROPERTY_TYPE(NSections,(nullptr), "Sections", App::Prop_None, "Section curves");
|
||||
NSections.setScope(App::LinkScope::Global);
|
||||
}
|
||||
|
||||
Sections::~Sections()
|
||||
{
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *Sections::execute(void)
|
||||
{
|
||||
TColGeom_SequenceOfCurve curveSeq;
|
||||
auto edge_obj = NSections.getValues();
|
||||
auto edge_sub = NSections.getSubValues();
|
||||
if (edge_obj.size() == edge_sub.size()) {
|
||||
for (std::size_t index = 0; index < edge_obj.size(); index++) {
|
||||
// get the part object
|
||||
App::DocumentObject* obj = edge_obj[index];
|
||||
const std::string& sub = edge_sub[index];
|
||||
if (obj && obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
// get the sub-edge of the part's shape
|
||||
const Part::TopoShape& shape = static_cast<Part::Feature*>(obj)->Shape.getShape();
|
||||
TopoDS_Shape edge = shape.getSubShape(sub.c_str());
|
||||
if (!edge.IsNull() && edge.ShapeType() == TopAbs_EDGE) {
|
||||
BRepAdaptor_Curve curve_adapt(TopoDS::Edge(edge));
|
||||
const TopLoc_Location& loc = edge.Location();
|
||||
Handle(Geom_TrimmedCurve) hCurve = new Geom_TrimmedCurve(curve_adapt.Curve().Curve(),
|
||||
curve_adapt.FirstParameter(),
|
||||
curve_adapt.LastParameter());
|
||||
if (!loc.IsIdentity()) {
|
||||
hCurve->Transform(loc.Transformation());
|
||||
}
|
||||
curveSeq.Append(hCurve);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (curveSeq.Length() < 2)
|
||||
return new App::DocumentObjectExecReturn("At least two sections are required.");
|
||||
|
||||
GeomFill_NSections fillOp(curveSeq);
|
||||
fillOp.ComputeSurface();
|
||||
|
||||
Handle(Geom_BSplineSurface) aSurf = fillOp.BSplineSurface();
|
||||
if (aSurf.IsNull())
|
||||
return new App::DocumentObjectExecReturn("Failed to create surface from sections.");
|
||||
|
||||
BRepBuilderAPI_MakeFace mkFace(aSurf
|
||||
#if OCC_VERSION_HEX >= 0x060502
|
||||
, Precision::Confusion()
|
||||
#endif
|
||||
);
|
||||
|
||||
Shape.setValue(mkFace.Face());
|
||||
return StdReturn;
|
||||
}
|
||||
54
src/Mod/Surface/App/FeatureSections.h
Normal file
54
src/Mod/Surface/App/FeatureSections.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef SURFACE_FEATURESECTIONS_H
|
||||
#define SURFACE_FEATURESECTIONS_H
|
||||
|
||||
#include <App/PropertyStandard.h>
|
||||
#include <App/PropertyUnits.h>
|
||||
#include <App/PropertyLinks.h>
|
||||
#include <Mod/Part/App/FeaturePartSpline.h>
|
||||
|
||||
namespace Surface
|
||||
{
|
||||
|
||||
class SurfaceExport Sections : public Part::Spline
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(Surface::Sections);
|
||||
|
||||
public:
|
||||
Sections();
|
||||
~Sections();
|
||||
|
||||
App::PropertyLinkSubList NSections;
|
||||
|
||||
// recalculate the feature
|
||||
App::DocumentObjectExecReturn *execute(void) override;
|
||||
/// returns the type name of the view provider
|
||||
const char* getViewProviderName(void) const override {
|
||||
return "SurfaceGui::ViewProviderSections";
|
||||
}
|
||||
};
|
||||
|
||||
}//Namespace Surface
|
||||
|
||||
#endif
|
||||
@@ -61,6 +61,7 @@
|
||||
|
||||
//opencascade
|
||||
#include "OpenCascadeAll.h"
|
||||
#include <GeomFill_NSections.hxx>
|
||||
|
||||
#endif //_PreComp_
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "Workbench.h"
|
||||
#include "TaskGeomFillSurface.h"
|
||||
#include "TaskFilling.h"
|
||||
#include "TaskSections.h"
|
||||
|
||||
// use a different name to CreateCommand()
|
||||
void CreateSurfaceCommands(void);
|
||||
@@ -79,6 +80,7 @@ PyMOD_INIT_FUNC(SurfaceGui)
|
||||
SurfaceGui::Workbench::init();
|
||||
SurfaceGui::ViewProviderGeomFillSurface ::init();
|
||||
SurfaceGui::ViewProviderFilling ::init();
|
||||
SurfaceGui::ViewProviderSections ::init();
|
||||
|
||||
// SurfaceGui::ViewProviderCut::init();
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ set(SurfaceGui_MOC_HDRS
|
||||
TaskFillingUnbound.h
|
||||
TaskFillingVertex.h
|
||||
TaskGeomFillSurface.h
|
||||
TaskSections.h
|
||||
)
|
||||
fc_wrap_cpp(SurfaceGui_MOC_SRCS ${SurfaceGui_MOC_HDRS})
|
||||
SOURCE_GROUP("Moc" FILES ${SurfaceGui_MOC_SRCS})
|
||||
@@ -43,6 +44,7 @@ SET(SurfaceGui_UIC_SRCS
|
||||
TaskFillingUnbound.ui
|
||||
TaskFillingVertex.ui
|
||||
TaskGeomFillSurface.ui
|
||||
TaskSections.ui
|
||||
)
|
||||
|
||||
if (BUILD_QT5)
|
||||
@@ -62,6 +64,8 @@ SET(SurfaceGui_SRCS
|
||||
TaskFillingVertex.h
|
||||
TaskGeomFillSurface.cpp
|
||||
TaskGeomFillSurface.h
|
||||
TaskSections.cpp
|
||||
TaskSections.h
|
||||
AppSurfaceGui.cpp
|
||||
Command.cpp
|
||||
PreCompiled.cpp
|
||||
|
||||
@@ -261,6 +261,35 @@ bool CmdSurfaceExtendFace::isActive(void)
|
||||
return Gui::Selection().countObjectsOfType(Part::Feature::getClassTypeId()) == 1;
|
||||
}
|
||||
|
||||
DEF_STD_CMD_A(CmdSurfaceSections)
|
||||
|
||||
CmdSurfaceSections::CmdSurfaceSections()
|
||||
:Command("Surface_Sections")
|
||||
{
|
||||
sAppModule = "Surface";
|
||||
sGroup = QT_TR_NOOP("Surface");
|
||||
sMenuText = QT_TR_NOOP("Sections...");
|
||||
sToolTipText = QT_TR_NOOP("Creates a surface from a series of section curves");
|
||||
sStatusTip = QT_TR_NOOP("Creates a surface from a series of section curves");
|
||||
sWhatsThis = "Surface_Sections";
|
||||
//sPixmap = "Surface_Sections";
|
||||
}
|
||||
|
||||
void CmdSurfaceSections::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::string FeatName = getUniqueObjectName("Surface");
|
||||
|
||||
openCommand("Create surface");
|
||||
doCommand(Doc, "App.ActiveDocument.addObject(\"Surface::Sections\",\"%s\")", FeatName.c_str());
|
||||
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", FeatName.c_str());
|
||||
}
|
||||
|
||||
bool CmdSurfaceSections::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
}
|
||||
|
||||
void CreateSurfaceCommands(void)
|
||||
{
|
||||
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
@@ -270,4 +299,5 @@ void CreateSurfaceCommands(void)
|
||||
rcCmdMgr.addCommand(new CmdSurfaceGeomFillSurface());
|
||||
rcCmdMgr.addCommand(new CmdSurfaceCurveOnMesh());
|
||||
rcCmdMgr.addCommand(new CmdSurfaceExtendFace());
|
||||
rcCmdMgr.addCommand(new CmdSurfaceSections());
|
||||
}
|
||||
|
||||
603
src/Mod/Surface/Gui/TaskSections.cpp
Normal file
603
src/Mod/Surface/Gui/TaskSections.cpp
Normal file
@@ -0,0 +1,603 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2017 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 "TaskSections.h"
|
||||
#include "ui_TaskSections.h"
|
||||
|
||||
|
||||
using namespace SurfaceGui;
|
||||
|
||||
PROPERTY_SOURCE(SurfaceGui::ViewProviderSections, PartGui::ViewProviderSpline)
|
||||
|
||||
namespace SurfaceGui {
|
||||
|
||||
void ViewProviderSections::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
QAction* act;
|
||||
act = menu->addAction(QObject::tr("Edit sections"), receiver, member);
|
||||
act->setData(QVariant((int)ViewProvider::Default));
|
||||
PartGui::ViewProviderSpline::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderSections::setEdit(int ModNum)
|
||||
{
|
||||
if (ModNum == ViewProvider::Default ) {
|
||||
// When double-clicking on the item for this sketch the
|
||||
// object unsets and sets its edit mode without closing
|
||||
// the task panel
|
||||
|
||||
Surface::Sections* obj = static_cast<Surface::Sections*>(this->getObject());
|
||||
|
||||
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
|
||||
|
||||
// start the edit dialog
|
||||
if (dlg) {
|
||||
TaskSections* tDlg = qobject_cast<TaskSections*>(dlg);
|
||||
if (tDlg)
|
||||
tDlg->setEditedObject(obj);
|
||||
Gui::Control().showDialog(dlg);
|
||||
}
|
||||
else {
|
||||
Gui::Control().showDialog(new TaskSections(this, obj));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return ViewProviderSpline::setEdit(ModNum);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderSections::unsetEdit(int ModNum)
|
||||
{
|
||||
if (ModNum == ViewProvider::Default) {
|
||||
// when pressing ESC make sure to close the dialog
|
||||
QTimer::singleShot(0, &Gui::Control(), SLOT(closeDialog()));
|
||||
}
|
||||
else {
|
||||
PartGui::ViewProviderSpline::unsetEdit(ModNum);
|
||||
}
|
||||
}
|
||||
|
||||
QIcon ViewProviderSections::getIcon(void) const
|
||||
{
|
||||
return Gui::BitmapFactory().pixmap("BSplineSurf");
|
||||
}
|
||||
|
||||
void ViewProviderSections::highlightReferences(ShapeType type, const References& refs, bool on)
|
||||
{
|
||||
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) {
|
||||
switch (type) {
|
||||
case ViewProviderSections::Vertex:
|
||||
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) {
|
||||
// check again that the index is in range because it's possible that the
|
||||
// sub-names are invalid
|
||||
std::size_t idx = static_cast<std::size_t>(std::stoi(jt.substr(6)) - 1);
|
||||
if (idx < colors.size())
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
}
|
||||
|
||||
svp->setHighlightedPoints(colors);
|
||||
}
|
||||
else {
|
||||
svp->unsetHighlightedPoints();
|
||||
}
|
||||
break;
|
||||
case ViewProviderSections::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());
|
||||
|
||||
for (auto jt : it.second) {
|
||||
std::size_t idx = static_cast<std::size_t>(std::stoi(jt.substr(4)) - 1);
|
||||
// check again that the index is in range because it's possible that the
|
||||
// sub-names are invalid
|
||||
if (idx < colors.size())
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
}
|
||||
|
||||
svp->setHighlightedEdges(colors);
|
||||
}
|
||||
else {
|
||||
svp->unsetHighlightedEdges();
|
||||
}
|
||||
break;
|
||||
case ViewProviderSections::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);
|
||||
// check again that the index is in range because it's possible that the
|
||||
// sub-names are invalid
|
||||
if (idx < colors.size())
|
||||
colors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
}
|
||||
|
||||
svp->setHighlightedFaces(colors);
|
||||
}
|
||||
else {
|
||||
svp->unsetHighlightedFaces();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class SectionsPanel::ShapeSelection : public Gui::SelectionFilterGate
|
||||
{
|
||||
public:
|
||||
ShapeSelection(SectionsPanel::SelectionMode& mode, Surface::Sections* editedObject)
|
||||
: Gui::SelectionFilterGate(static_cast<Gui::SelectionFilter*>(nullptr))
|
||||
, mode(mode)
|
||||
, editedObject(editedObject)
|
||||
{
|
||||
}
|
||||
~ShapeSelection()
|
||||
{
|
||||
mode = SectionsPanel::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 SectionsPanel::AppendEdge:
|
||||
return allowEdge(true, pObj, sSubName);
|
||||
case SectionsPanel::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->NSections.getSubListValues();
|
||||
for (auto it : links) {
|
||||
if (it.first == pObj) {
|
||||
for (auto jt : it.second) {
|
||||
if (jt == sSubName)
|
||||
return !appendEdges;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appendEdges;
|
||||
}
|
||||
|
||||
private:
|
||||
SectionsPanel::SelectionMode& mode;
|
||||
Surface::Sections* editedObject;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
SectionsPanel::SectionsPanel(ViewProviderSections* vp, Surface::Sections* obj) : ui(new Ui_Sections())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->statusLabel->clear();
|
||||
|
||||
selectionMode = None;
|
||||
this->vp = vp;
|
||||
checkCommand = true;
|
||||
setEditedObject(obj);
|
||||
|
||||
// Create context menu
|
||||
QAction* action = new QAction(tr("Remove"), this);
|
||||
action->setShortcut(QKeySequence::Delete);
|
||||
ui->listSections->addAction(action);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(onDeleteEdge()));
|
||||
ui->listSections->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
|
||||
connect(ui->listSections->model(),
|
||||
SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)), this, SLOT(onIndexesMoved()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroys the object and frees any allocated resources
|
||||
*/
|
||||
SectionsPanel::~SectionsPanel()
|
||||
{
|
||||
}
|
||||
|
||||
// stores object pointer, its old fill type and adjusts radio buttons according to it.
|
||||
void SectionsPanel::setEditedObject(Surface::Sections* fea)
|
||||
{
|
||||
editedObject = fea;
|
||||
|
||||
// get the section edges
|
||||
auto objects = editedObject->NSections.getValues();
|
||||
auto edges = editedObject->NSections.getSubValues();
|
||||
auto count = objects.size();
|
||||
|
||||
App::Document* doc = editedObject->getDocument();
|
||||
for (std::size_t i=0; i<count; i++) {
|
||||
App::DocumentObject* obj = objects[i];
|
||||
std::string edge = edges[i];
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(ui->listSections);
|
||||
ui->listSections->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
|
||||
QList<QVariant> data;
|
||||
data << QByteArray(doc->getName());
|
||||
data << QByteArray(obj->getNameInDocument());
|
||||
data << QByteArray(edge.c_str());
|
||||
item->setData(Qt::UserRole, data);
|
||||
}
|
||||
|
||||
// attach this document observer
|
||||
attachDocument(Gui::Application::Instance->getDocument(doc));
|
||||
}
|
||||
|
||||
void SectionsPanel::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
else {
|
||||
QWidget::changeEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void SectionsPanel::open()
|
||||
{
|
||||
checkOpenCommand();
|
||||
|
||||
// highlight the boundary edges
|
||||
this->vp->highlightReferences(ViewProviderSections::Edge,
|
||||
editedObject->NSections.getSubListValues(), true);
|
||||
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
|
||||
void SectionsPanel::clearSelection()
|
||||
{
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
|
||||
void SectionsPanel::checkOpenCommand()
|
||||
{
|
||||
if (checkCommand && !Gui::Command::hasPendingCommand()) {
|
||||
std::string Msg("Edit ");
|
||||
Msg += editedObject->Label.getValue();
|
||||
Gui::Command::openCommand(Msg.c_str());
|
||||
checkCommand = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SectionsPanel::slotUndoDocument(const Gui::Document&)
|
||||
{
|
||||
checkCommand = true;
|
||||
}
|
||||
|
||||
void SectionsPanel::slotRedoDocument(const Gui::Document&)
|
||||
{
|
||||
checkCommand = true;
|
||||
}
|
||||
|
||||
void SectionsPanel::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(ViewProviderSections::Edge,
|
||||
editedObject->NSections.getSubListValues(), false);
|
||||
}
|
||||
}
|
||||
|
||||
bool SectionsPanel::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(ViewProviderSections::Edge,
|
||||
editedObject->NSections.getSubListValues(), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SectionsPanel::reject()
|
||||
{
|
||||
this->vp->highlightReferences(ViewProviderSections::Edge,
|
||||
editedObject->NSections.getSubListValues(), false);
|
||||
|
||||
selectionMode = None;
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SectionsPanel::on_buttonEdgeAdd_clicked()
|
||||
{
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject));
|
||||
selectionMode = AppendEdge;
|
||||
}
|
||||
|
||||
void SectionsPanel::on_buttonEdgeRemove_clicked()
|
||||
{
|
||||
// 'selectionMode' is passed by reference and changed when the filter is deleted
|
||||
Gui::Selection().addSelectionGate(new ShapeSelection(selectionMode, editedObject));
|
||||
selectionMode = RemoveEdge;
|
||||
}
|
||||
|
||||
void SectionsPanel::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
{
|
||||
if (selectionMode == None)
|
||||
return;
|
||||
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
checkOpenCommand();
|
||||
if (selectionMode == AppendEdge) {
|
||||
QListWidgetItem* item = new QListWidgetItem(ui->listSections);
|
||||
ui->listSections->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);
|
||||
|
||||
appendCurve(sel.getObject(), msg.pSubName);
|
||||
}
|
||||
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->listSections->count(); i++) {
|
||||
QListWidgetItem* item = ui->listSections->item(i);
|
||||
QList<QVariant> userdata = item->data(Qt::UserRole).toList();
|
||||
if (userdata.mid(0,3) == data) {
|
||||
ui->listSections->takeItem(i);
|
||||
delete item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
removeCurve(sel.getObject(), msg.pSubName);
|
||||
}
|
||||
|
||||
editedObject->recomputeFeature();
|
||||
QTimer::singleShot(50, this, SLOT(clearSelection()));
|
||||
}
|
||||
}
|
||||
|
||||
void SectionsPanel::onDeleteEdge()
|
||||
{
|
||||
int row = ui->listSections->currentRow();
|
||||
QListWidgetItem* item = ui->listSections->takeItem(row);
|
||||
if (item) {
|
||||
checkOpenCommand();
|
||||
QList<QVariant> data;
|
||||
data = item->data(Qt::UserRole).toList();
|
||||
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();
|
||||
|
||||
removeCurve(obj, sub);
|
||||
editedObject->recomputeFeature();
|
||||
}
|
||||
}
|
||||
|
||||
void SectionsPanel::onIndexesMoved()
|
||||
{
|
||||
QAbstractItemModel* model = qobject_cast<QAbstractItemModel*>(sender());
|
||||
if (!model)
|
||||
return;
|
||||
|
||||
std::vector<App::DocumentObject*> objects;
|
||||
std::vector<std::string> element;
|
||||
|
||||
int rows = model->rowCount();
|
||||
for (int i = 0; i < rows; i++) {
|
||||
QModelIndex index = model->index(i, 0);
|
||||
QList<QVariant> data;
|
||||
data = index.data(Qt::UserRole).toList();
|
||||
|
||||
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();
|
||||
|
||||
objects.push_back(obj);
|
||||
element.push_back(sub);
|
||||
}
|
||||
|
||||
editedObject->NSections.setValues(objects, element);
|
||||
editedObject->recomputeFeature();
|
||||
}
|
||||
|
||||
void SectionsPanel::appendCurve(App::DocumentObject* obj, const std::string& subname)
|
||||
{
|
||||
auto objects = editedObject->NSections.getValues();
|
||||
objects.push_back(obj);
|
||||
auto element = editedObject->NSections.getSubValues();
|
||||
element.push_back(subname);
|
||||
editedObject->NSections.setValues(objects, element);
|
||||
|
||||
this->vp->highlightReferences(ViewProviderSections::Edge,
|
||||
editedObject->NSections.getSubListValues(), true);
|
||||
}
|
||||
|
||||
void SectionsPanel::removeCurve(App::DocumentObject* obj, const std::string& subname)
|
||||
{
|
||||
this->vp->highlightReferences(ViewProviderSections::Edge,
|
||||
editedObject->NSections.getSubListValues(), false);
|
||||
|
||||
auto objects = editedObject->NSections.getValues();
|
||||
auto element = editedObject->NSections.getSubValues();
|
||||
|
||||
auto it = objects.begin();
|
||||
auto jt = element.begin();
|
||||
for (; it != objects.end() && jt != element.end(); ++it, ++jt) {
|
||||
if (*it == obj && *jt == subname) {
|
||||
objects.erase(it);
|
||||
element.erase(jt);
|
||||
editedObject->NSections.setValues(objects, element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vp->highlightReferences(ViewProviderSections::Edge,
|
||||
editedObject->NSections.getSubListValues(), true);
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TaskSections::TaskSections(ViewProviderSections* vp, Surface::Sections* obj)
|
||||
{
|
||||
// first task box
|
||||
widget1 = new SectionsPanel(vp, obj);
|
||||
Gui::TaskView::TaskBox* taskbox1 = new Gui::TaskView::TaskBox(
|
||||
Gui::BitmapFactory().pixmap("BezSurf"),
|
||||
widget1->windowTitle(), true, 0);
|
||||
taskbox1->groupLayout()->addWidget(widget1);
|
||||
Content.push_back(taskbox1);
|
||||
}
|
||||
|
||||
TaskSections::~TaskSections()
|
||||
{
|
||||
// automatically deleted in the sub-class
|
||||
}
|
||||
|
||||
void TaskSections::setEditedObject(Surface::Sections* obj)
|
||||
{
|
||||
widget1->setEditedObject(obj);
|
||||
}
|
||||
|
||||
void TaskSections::open()
|
||||
{
|
||||
widget1->open();
|
||||
}
|
||||
|
||||
bool TaskSections::accept()
|
||||
{
|
||||
bool ok = widget1->accept();
|
||||
if (ok) {
|
||||
Gui::Command::commitCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||
Gui::Command::updateActive();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TaskSections::reject()
|
||||
{
|
||||
bool ok = widget1->reject();
|
||||
if (ok) {
|
||||
Gui::Command::abortCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||
Gui::Command::updateActive();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "moc_TaskSections.cpp"
|
||||
128
src/Mod/Surface/Gui/TaskSections.h
Normal file
128
src/Mod/Surface/Gui/TaskSections.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef SURFACEGUI_TASKSECTIONS_H
|
||||
#define SURFACEGUI_TASKSECTIONS_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/FeatureSections.h>
|
||||
#include <memory>
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace SurfaceGui
|
||||
{
|
||||
|
||||
class Ui_Sections;
|
||||
|
||||
class ViewProviderSections : public PartGui::ViewProviderSpline
|
||||
{
|
||||
PROPERTY_HEADER(SurfaceGui::ViewProviderSections);
|
||||
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(ShapeType type, const References& refs, bool on);
|
||||
};
|
||||
|
||||
class SectionsPanel : public QWidget,
|
||||
public Gui::SelectionObserver,
|
||||
public Gui::DocumentObserver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
class ShapeSelection;
|
||||
enum SelectionMode { None, AppendEdge, RemoveEdge };
|
||||
SelectionMode selectionMode;
|
||||
Surface::Sections* editedObject;
|
||||
bool checkCommand;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_Sections> ui;
|
||||
ViewProviderSections* vp;
|
||||
|
||||
public:
|
||||
SectionsPanel(ViewProviderSections* vp, Surface::Sections* obj);
|
||||
~SectionsPanel();
|
||||
|
||||
void open();
|
||||
void checkOpenCommand();
|
||||
bool accept();
|
||||
bool reject();
|
||||
void setEditedObject(Surface::Sections* 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);
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_buttonEdgeAdd_clicked();
|
||||
void on_buttonEdgeRemove_clicked();
|
||||
void onDeleteEdge(void);
|
||||
void clearSelection();
|
||||
void onIndexesMoved();
|
||||
|
||||
private:
|
||||
void appendCurve(App::DocumentObject*, const std::string& subname);
|
||||
void removeCurve(App::DocumentObject*, const std::string& subname);
|
||||
};
|
||||
|
||||
class TaskSections : public Gui::TaskView::TaskDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskSections(ViewProviderSections* vp, Surface::Sections* obj);
|
||||
~TaskSections();
|
||||
void setEditedObject(Surface::Sections* obj);
|
||||
|
||||
public:
|
||||
void open();
|
||||
bool accept();
|
||||
bool reject();
|
||||
|
||||
virtual QDialogButtonBox::StandardButtons getStandardButtons() const
|
||||
{ return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; }
|
||||
|
||||
private:
|
||||
SectionsPanel* widget1;
|
||||
};
|
||||
|
||||
} //namespace SurfaceGui
|
||||
|
||||
#endif // SURFACEGUI_TASKSECTIONS_H
|
||||
83
src/Mod/Surface/Gui/TaskSections.ui
Normal file
83
src/Mod/Surface/Gui/TaskSections.ui
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SurfaceGui::Sections</class>
|
||||
<widget class="QWidget" name="SurfaceGui::Sections">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>293</width>
|
||||
<height>443</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Sections</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Sections</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QListWidget" name="listSections">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>List can be reordered by dragging</p></body></html></string>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonEdgeAdd">
|
||||
<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="buttonEdgeRemove">
|
||||
<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="2">
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="text">
|
||||
<string notr="true">Status messages</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -55,7 +55,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
*surface << "Surface_CurveOnMesh"
|
||||
<< "Surface_ExtendFace"
|
||||
<< "Surface_Filling"
|
||||
<< "Surface_GeomFillSurface";
|
||||
<< "Surface_GeomFillSurface"
|
||||
<< "Surface_Sections";
|
||||
/* *surface << "Surface_Filling";
|
||||
*surface << "Surface_Cut";*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user