Dialog with radio buttons for choosing Bezier and b-spline surface fill type

A regular common dialog with apply, cancel and OK buttons allowing
surface fill type selection for Bezier and b-spline surfaces.

The Bezier and b-spline surface functionality now seems to be complete.
This commit is contained in:
balazs-bamer
2015-01-21 16:35:09 +01:00
committed by wmayer
parent 06645251ad
commit 254aa167e4
7 changed files with 106 additions and 65 deletions

View File

@@ -37,7 +37,7 @@ public:
BSplineSurf();
// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
virtual App::DocumentObjectExecReturn *execute(void);
};
}//Namespace Surface
#endif

View File

@@ -44,11 +44,12 @@ public:
App::PropertyInteger filltype; //Fill method (1, 2, or 3 for Stretch, Coons, and Curved)
short mustExecute() const;
virtual App::DocumentObjectExecReturn *execute(void) = 0;
/// returns the type name of the view provider
const char* getViewProviderName(void) const {
return "SurfaceGui::ViewProviderBSurf";
}
const char* getViewProviderName(void) const {
return "SurfaceGui::ViewProviderBSurf";
}
protected:
GeomFill_FillingStyle getFillingStyle();

View File

@@ -37,7 +37,7 @@ public:
BezSurf();
// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
virtual App::DocumentObjectExecReturn *execute(void);
};
}//Namespace Surface
#endif

View File

@@ -29,6 +29,7 @@
#endif
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <Gui/Application.h>
#include "Workbench.h"
@@ -54,12 +55,15 @@ void SurfaceGuiExport initSurfaceGui()
return;
}
SurfaceGui::Workbench::init();
SurfaceGui::ViewProviderBSurf::init();
// Base::Interpreter().runString("import SurfaceGui"); infinite Python recursion comes
Base::Interpreter().runString("import PartGui");
// instanciating the commands
CreateSurfaceCommands();
SurfaceGui::Workbench::init();
SurfaceGui::ViewProviderBSurf::init();
// SurfaceGui::ViewProviderCut::init();
(void) Py_InitModule3("SurfaceGui", SurfaceGui_methods, module_SurfaceGui_doc); /* mod name, table ptr */

View File

@@ -35,6 +35,8 @@
#endif
#include "BSurf.h"
#include "../App/FeatureBSurf.h"
#include "../FillType.h"
#include <Gui/ViewProvider.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
@@ -54,32 +56,35 @@ bool ViewProviderBSurf::setEdit(int ModNum)
// When double-clicking on the item for this sketch the
// object unsets and sets its edit mode without closing
// the task panel
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
TaskBSurf* tDlg = qobject_cast<TaskBSurf*>(dlg);
Surface::BSurf* obj = static_cast<Surface::BSurf*>(this->getObject());
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
TaskBSurf* tDlg = qobject_cast<TaskBSurf*>(dlg);
// start the edit dialog
if(dlg)
Gui::Control().showDialog(tDlg);
{
tDlg->setEditedObject(obj);
Gui::Control().showDialog(tDlg);
}
else
Gui::Control().showDialog(new TaskBSurf(this));
// draw();
{
Gui::Control().showDialog(new TaskBSurf(this, obj));
}
return true;
}
void ViewProviderBSurf::unsetEdit(int ModNum)
{
/*if(!Gui::Selection().isSelected(pcObject) || !Visibility.getValue()) {
internal_vp.switch_node(false);
pcModeSwitch->whichChild = -1;
m_selected = false;
} */
// nothing to do
}
BSurf::BSurf(ViewProviderBSurf* vp)
//: QDialog(parent, fl), bbox(bb)
BSurf::BSurf(ViewProviderBSurf* vp, Surface::BSurf* obj)
{
ui = new Ui_DlgBSurf();
ui->setupUi(this);
vp = new ViewProviderBSurf();
this->vp = vp;
setEditedObject(obj);
}
/*
@@ -89,7 +94,31 @@ BSurf::~BSurf()
{
// no need to delete child widgets, Qt does it all for us
delete ui;
delete vp;
}
// stores object pointer, its old fill type and adjusts radio buttons according to it.
void BSurf::setEditedObject(Surface::BSurf* obj)
{
editedObject = obj;
filltype_t ft = (filltype_t)(editedObject->filltype.getValue());
switch(ft)
{
case StretchStyle:
oldFillType = ft;
ui->fillType_stretch->setChecked(true);
break;
case CoonsStyle:
oldFillType = ft;
ui->fillType_coons->setChecked(true);
break;
case CurvedStyle:
oldFillType = ft;
ui->fillType_curved->setChecked(true);
break;
/*default:
printf("BSurf::setEditedObject: illegal fill type: %d\n", editedObject->filltype.getValue());
Standard_Failure::Raise("BSurf::setEditedObject: illegal fill type.");*/
}
}
filltype_t BSurf::getFillType() const
@@ -101,7 +130,6 @@ filltype_t BSurf::getFillType() const
ret = CoonsStyle;
else
ret = CurvedStyle;
printf("BSurf::getFillType: %d\n", ret);
return ret;
}
@@ -117,43 +145,52 @@ void BSurf::changeEvent(QEvent *e)
void BSurf::accept()
{
printf("accept ");
// applies the changes
apply();
QDialog::accept();
}
void BSurf::reject()
{
// if the object fill type was changed, reset the old one
if(editedObject->filltype.getValue() != oldFillType)
{
editedObject->filltype.setValue(oldFillType);
editedObject->execute();
}
QDialog::reject();
}
void BSurf::apply()
{
printf("apply\n");
// std::vector<App::DocumentObject*> obj = Gui::Selection().
// getObjectsOfType(Part::Feature::getClassTypeId());
////////////////
// apply the change only if it is a real change
if(editedObject->filltype.getValue() != fillType)
{
editedObject->filltype.setValue(fillType);
editedObject->execute();
}
}
void BSurf::on_fillType_stretch_clicked()
{
printf("stretch\n");
fillType = StretchStyle;
}
void BSurf::on_fillType_coons_clicked()
{
printf("coons\n");
fillType = CoonsStyle;
}
void BSurf::on_fillType_curved_clicked()
{
printf("curved\n");
fillType = CurvedStyle;
}
// ---------------------------------------
TaskBSurf::TaskBSurf(ViewProviderBSurf* vp)
TaskBSurf::TaskBSurf(ViewProviderBSurf* vp, Surface::BSurf* obj)
{
widget = new BSurf(vp);
/* taskbox = new Gui::TaskView::TaskBox(
NULL,
widget->windowTitle(), true, 0);
taskbox->groupLayout()->addWidget(widget);*/
widget = new BSurf(vp, obj);
Content.push_back(widget);
}
@@ -162,12 +199,24 @@ TaskBSurf::~TaskBSurf()
// automatically deleted in the sub-class
}
void TaskBSurf::setEditedObject(Surface::BSurf* obj)
{
widget->setEditedObject(obj);
}
bool TaskBSurf::accept()
{
widget->accept();
return (widget->result() == QDialog::Accepted);
}
bool TaskBSurf::reject()
{
widget->reject();
return (widget->result() == QDialog::Rejected);
}
// Apply clicked
void TaskBSurf::clicked(int id)
{
if (id == QDialogButtonBox::Apply) {

View File

@@ -35,6 +35,7 @@
#include "../FillType.h"
#include <Mod/Part/Gui/ViewProvider.h>
#include "ui_BSurf.h"
#include "../App/FeatureBSurf.h"
namespace SurfaceGui
{
@@ -51,13 +52,21 @@ namespace SurfaceGui
{
Q_OBJECT
protected:
filltype_t fillType;
filltype_t fillType, oldFillType;
Surface::BSurf* editedObject;
private:
Ui_DlgBSurf* ui;
Base::BoundBox3d bbox;
ViewProviderBSurf* vp;
public:
BSurf(ViewProviderBSurf* vp);
BSurf(ViewProviderBSurf* vp, Surface::BSurf* obj);
~BSurf();
void accept();
void reject();
void apply();
void setEditedObject(Surface::BSurf* obj);
protected:
void changeEvent(QEvent *e);
@@ -67,19 +76,6 @@ namespace SurfaceGui
void on_fillType_coons_clicked();
void on_fillType_curved_clicked();
filltype_t getFillType() const;
/* private:
std::vector<double> getPlanes() const;
void calcPlane(Plane, double);
void calcPlanes(Plane);
void makePlanes(Plane, const std::vector<double>&, double[4]);
Plane plane() const;*/
private:
Ui_DlgBSurf* ui;
Base::BoundBox3d bbox;
ViewProviderBSurf* vp;
// QPointer<Gui::View3DInventor> view;
};
class TaskBSurf : public Gui::TaskView::TaskDialog
@@ -87,11 +83,13 @@ namespace SurfaceGui
Q_OBJECT
public:
TaskBSurf(ViewProviderBSurf* vp);
TaskBSurf(ViewProviderBSurf* vp, Surface::BSurf* obj);
~TaskBSurf();
void setEditedObject(Surface::BSurf* obj);
public:
bool accept();
bool reject();
void clicked(int id);
virtual QDialogButtonBox::StandardButtons getStandardButtons() const

View File

@@ -165,12 +165,6 @@ CmdSurfaceBezier::CmdSurfaceBezier()
void CmdSurfaceBezier::activated(int iMsg)
{
/*if (!isActive()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select 2, 3 or 4 curves, please."));
return;
}*/
// we take the whole selection and require that all of its members are of the required curve
std::vector<Gui::SelectionObject> Selo = getSelection().getSelectionEx(0);
std::string FeatName = getUniqueObjectName("BezierSurface");
@@ -184,6 +178,7 @@ void CmdSurfaceBezier::activated(int iMsg)
openCommand("Create Bezier surface");
doCommand(Doc,"FreeCAD.ActiveDocument.addObject(\"Surface::BezSurf\",\"%s\")", FeatName.c_str());
doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.filltype=1"); // TODO ask filltype from user and check it
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", FeatName.c_str());
runCommand(Doc, bezListCmd.str().c_str());
updateActive();
commitCommand();
@@ -241,12 +236,6 @@ CmdSurfaceBSpline::CmdSurfaceBSpline()
void CmdSurfaceBSpline::activated(int iMsg)
{
/*Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
if (!dlg) {
dlg = new SurfaceGui::TaskBSurf(new SurfaceGui::ViewProviderBSurf());
}
Gui::Control().showDialog(dlg);*/
// we take the whole selection and require that all of its members are of the required curve
std::vector<Gui::SelectionObject> Selo = getSelection().getSelectionEx(0);
std::string FeatName = getUniqueObjectName("BSplineSurface");