0000735: Feature request for better Fillet/Chamfer

This commit is contained in:
wmayer 2013-07-07 16:13:38 +02:00
parent e3b0c111be
commit 2b0757c3a6
8 changed files with 113 additions and 15 deletions

View File

@ -75,7 +75,11 @@ App::DocumentObjectExecReturn *Chamfer::execute(void)
TopoDS_Shape shape = mkChamfer.Shape(); TopoDS_Shape shape = mkChamfer.Shape();
if (shape.IsNull()) if (shape.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null"); return new App::DocumentObjectExecReturn("Resulting shape is null");
ShapeHistory history = buildHistory(mkChamfer, TopAbs_FACE, shape, base->Shape.getValue());
this->Shape.setValue(shape); this->Shape.setValue(shape);
PropertyShapeHistory prop;
prop.setContainer(this);
prop.setValue(history);
return App::DocumentObject::StdReturn; return App::DocumentObject::StdReturn;
} }
catch (Standard_Failure) { catch (Standard_Failure) {

View File

@ -74,7 +74,11 @@ App::DocumentObjectExecReturn *Fillet::execute(void)
TopoDS_Shape shape = mkFillet.Shape(); TopoDS_Shape shape = mkFillet.Shape();
if (shape.IsNull()) if (shape.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null"); return new App::DocumentObjectExecReturn("Resulting shape is null");
ShapeHistory history = buildHistory(mkFillet, TopAbs_FACE, shape, base->Shape.getValue());
this->Shape.setValue(shape); this->Shape.setValue(shape);
PropertyShapeHistory prop;
prop.setContainer(this);
prop.setValue(history);
return App::DocumentObject::StdReturn; return App::DocumentObject::StdReturn;
} }
catch (Standard_Failure) { catch (Standard_Failure) {

View File

@ -703,7 +703,6 @@ bool DlgFilletEdges::accept()
QByteArray to = name.toAscii(); QByteArray to = name.toAscii();
QByteArray from = shape.toAscii(); QByteArray from = shape.toAscii();
Gui::Command::copyVisual(to, "ShapeColor", from);
Gui::Command::copyVisual(to, "LineColor", from); Gui::Command::copyVisual(to, "LineColor", from);
Gui::Command::copyVisual(to, "PointColor", from); Gui::Command::copyVisual(to, "PointColor", from);
return true; return true;

View File

@ -120,6 +120,20 @@ bool ViewProviderPart::doubleClicked(void)
return true; return true;
} }
void ViewProviderPart::applyColor(const Part::ShapeHistory& hist,
const std::vector<App::Color>& colBase,
std::vector<App::Color>& colBool)
{
std::map<int, std::vector<int> >::const_iterator jt;
// apply color from modified faces
for (jt = hist.shapeMap.begin(); jt != hist.shapeMap.end(); ++jt) {
std::vector<int>::const_iterator kt;
for (kt = jt->second.begin(); kt != jt->second.end(); ++kt) {
colBool[*kt] = colBase[jt->first];
}
}
}
#else #else
PROPERTY_SOURCE(PartGui::ViewProviderPart, PartGui::ViewProviderPartBase) PROPERTY_SOURCE(PartGui::ViewProviderPart, PartGui::ViewProviderPartBase)

View File

@ -50,6 +50,8 @@ class SoScale;
// Set this to use the fast rendering of shapes // Set this to use the fast rendering of shapes
#define FC_USE_FAST_SHAPE_RENDERING #define FC_USE_FAST_SHAPE_RENDERING
namespace Part { struct ShapeHistory; }
namespace PartGui { namespace PartGui {
class ViewProviderShapeBuilder : public Gui::ViewProviderBuilder class ViewProviderShapeBuilder : public Gui::ViewProviderBuilder
@ -157,6 +159,11 @@ public:
/// destructor /// destructor
virtual ~ViewProviderPart(); virtual ~ViewProviderPart();
virtual bool doubleClicked(void); virtual bool doubleClicked(void);
protected:
void applyColor(const Part::ShapeHistory& hist,
const std::vector<App::Color>& colBase,
std::vector<App::Color>& colBool);
}; };
#else #else
class PartGuiExport ViewProviderPart : public ViewProviderPartBase class PartGuiExport ViewProviderPart : public ViewProviderPartBase

View File

@ -77,20 +77,6 @@ QIcon ViewProviderBoolean::getIcon(void) const
return ViewProviderPart::getIcon(); return ViewProviderPart::getIcon();
} }
void applyColor(const Part::ShapeHistory& hist,
const std::vector<App::Color>& colBase,
std::vector<App::Color>& colBool)
{
std::map<int, std::vector<int> >::const_iterator jt;
// apply color from modified faces
for (jt = hist.shapeMap.begin(); jt != hist.shapeMap.end(); ++jt) {
std::vector<int>::const_iterator kt;
for (kt = jt->second.begin(); kt != jt->second.end(); ++kt) {
colBool[*kt] = colBase[jt->first];
}
}
}
void ViewProviderBoolean::updateData(const App::Property* prop) void ViewProviderBoolean::updateData(const App::Property* prop)
{ {
PartGui::ViewProviderPart::updateData(prop); PartGui::ViewProviderPart::updateData(prop);

View File

@ -28,6 +28,10 @@
# include <QMenu> # include <QMenu>
# include <QTimer> # include <QTimer>
# include <Standard_math.hxx> # include <Standard_math.hxx>
# include <TopExp.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopTools_ListOfShape.hxx>
# include <TopTools_ListIteratorOfListOfShape.hxx>
# include <Inventor/actions/SoSearchAction.h> # include <Inventor/actions/SoSearchAction.h>
# include <Inventor/draggers/SoDragger.h> # include <Inventor/draggers/SoDragger.h>
# include <Inventor/nodes/SoCoordinate3.h> # include <Inventor/nodes/SoCoordinate3.h>
@ -225,6 +229,45 @@ ViewProviderFillet::~ViewProviderFillet()
{ {
} }
void ViewProviderFillet::updateData(const App::Property* prop)
{
PartGui::ViewProviderPart::updateData(prop);
if (prop->getTypeId() == Part::PropertyShapeHistory::getClassTypeId()) {
const std::vector<Part::ShapeHistory>& hist = static_cast<const Part::PropertyShapeHistory*>
(prop)->getValues();
if (hist.size() != 1)
return;
Part::Fillet* objFill = dynamic_cast<Part::Fillet*>(getObject());
Part::Feature* objBase = dynamic_cast<Part::Feature*>(objFill->Base.getValue());
if (objBase) {
const TopoDS_Shape& baseShape = objBase->Shape.getValue();
const TopoDS_Shape& fillShape = objFill->Shape.getValue();
TopTools_IndexedMapOfShape baseMap, fillMap;
TopExp::MapShapes(baseShape, TopAbs_FACE, baseMap);
TopExp::MapShapes(fillShape, TopAbs_FACE, fillMap);
Gui::ViewProvider* vpBase = Gui::Application::Instance->getViewProvider(objBase);
std::vector<App::Color> colBase = static_cast<PartGui::ViewProviderPart*>(vpBase)->DiffuseColor.getValues();
std::vector<App::Color> colFill;
colFill.resize(fillMap.Extent(), static_cast<PartGui::ViewProviderPart*>(vpBase)->ShapeColor.getValue());
bool setColor=false;
if (colBase.size() == baseMap.Extent()) {
applyColor(hist[0], colBase, colFill);
setColor = true;
}
else if (!colBase.empty() && colBase[0] != this->ShapeColor.getValue()) {
colBase.resize(baseMap.Extent(), colBase[0]);
applyColor(hist[0], colBase, colFill);
setColor = true;
}
if (setColor)
this->DiffuseColor.setValues(colFill);
}
}
}
void ViewProviderFillet::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) void ViewProviderFillet::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{ {
QAction* act; QAction* act;
@ -289,6 +332,45 @@ ViewProviderChamfer::~ViewProviderChamfer()
{ {
} }
void ViewProviderChamfer::updateData(const App::Property* prop)
{
PartGui::ViewProviderPart::updateData(prop);
if (prop->getTypeId() == Part::PropertyShapeHistory::getClassTypeId()) {
const std::vector<Part::ShapeHistory>& hist = static_cast<const Part::PropertyShapeHistory*>
(prop)->getValues();
if (hist.size() != 1)
return;
Part::Chamfer* objCham = dynamic_cast<Part::Chamfer*>(getObject());
Part::Feature* objBase = dynamic_cast<Part::Feature*>(objCham->Base.getValue());
if (objBase) {
const TopoDS_Shape& baseShape = objBase->Shape.getValue();
const TopoDS_Shape& chamShape = objCham->Shape.getValue();
TopTools_IndexedMapOfShape baseMap, chamMap;
TopExp::MapShapes(baseShape, TopAbs_FACE, baseMap);
TopExp::MapShapes(chamShape, TopAbs_FACE, chamMap);
Gui::ViewProvider* vpBase = Gui::Application::Instance->getViewProvider(objBase);
std::vector<App::Color> colBase = static_cast<PartGui::ViewProviderPart*>(vpBase)->DiffuseColor.getValues();
std::vector<App::Color> colCham;
colCham.resize(chamMap.Extent(), static_cast<PartGui::ViewProviderPart*>(vpBase)->ShapeColor.getValue());
bool setColor=false;
if (colBase.size() == baseMap.Extent()) {
applyColor(hist[0], colBase, colCham);
setColor = true;
}
else if (!colBase.empty() && colBase[0] != this->ShapeColor.getValue()) {
colBase.resize(baseMap.Extent(), colBase[0]);
applyColor(hist[0], colBase, colCham);
setColor = true;
}
if (setColor)
this->DiffuseColor.setValues(colCham);
}
}
}
void ViewProviderChamfer::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) void ViewProviderChamfer::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{ {
QAction* act; QAction* act;

View File

@ -70,6 +70,7 @@ public:
bool onDelete(const std::vector<std::string> &); bool onDelete(const std::vector<std::string> &);
protected: protected:
void updateData(const App::Property*);
bool setEdit(int ModNum); bool setEdit(int ModNum);
void unsetEdit(int ModNum); void unsetEdit(int ModNum);
//@} //@}
@ -91,6 +92,7 @@ public:
bool onDelete(const std::vector<std::string> &); bool onDelete(const std::vector<std::string> &);
protected: protected:
void updateData(const App::Property*);
bool setEdit(int ModNum); bool setEdit(int ModNum);
void unsetEdit(int ModNum); void unsetEdit(int ModNum);
//@} //@}