+ add GUI command for shape refinement
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5307 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
parent
7e0a5ddf37
commit
3b5c2c951f
|
@ -1719,37 +1719,80 @@ bool TopoShape::removeInternalWires(double minArea)
|
|||
return ok;
|
||||
}
|
||||
|
||||
void TopoShape::removeSplitter()
|
||||
TopoDS_Shape TopoShape::removeSplitter() const
|
||||
{
|
||||
if (_Shape.IsNull())
|
||||
Standard_Failure::Raise("Cannot remove splitter from empty shape");
|
||||
|
||||
if (_Shape.ShapeType() == TopAbs_SOLID) {
|
||||
TopoDS_Solid& solid = TopoDS::Solid(_Shape);
|
||||
const TopoDS_Solid& solid = TopoDS::Solid(_Shape);
|
||||
ModelRefine::FaceUniter uniter(solid);
|
||||
if (uniter.process()) {
|
||||
TopoDS_Solid solidMod;
|
||||
if (!uniter.getSolid(solidMod))
|
||||
Standard_Failure::Raise("Getting solid failed");
|
||||
_Shape = solidMod;
|
||||
return solidMod;
|
||||
}
|
||||
else {
|
||||
Standard_Failure::Raise("Removing splitter failed");
|
||||
}
|
||||
}
|
||||
else if (_Shape.ShapeType() == TopAbs_SHELL) {
|
||||
TopoDS_Shell& shell = TopoDS::Shell(_Shape);
|
||||
const TopoDS_Shell& shell = TopoDS::Shell(_Shape);
|
||||
ModelRefine::FaceUniter uniter(shell);
|
||||
if (uniter.process()) {
|
||||
_Shape = uniter.getShell();
|
||||
return uniter.getShell();
|
||||
}
|
||||
else {
|
||||
Standard_Failure::Raise("Removing splitter failed");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Standard_Failure::Raise("Either shell or solid expected");
|
||||
else if (_Shape.ShapeType() == TopAbs_COMPOUND) {
|
||||
BRep_Builder builder;
|
||||
TopoDS_Compound comp;
|
||||
builder.MakeCompound(comp);
|
||||
|
||||
TopExp_Explorer xp;
|
||||
// solids
|
||||
for (xp.Init(_Shape, TopAbs_SOLID); xp.More(); xp.Next()) {
|
||||
const TopoDS_Solid& solid = TopoDS::Solid(xp.Current());
|
||||
ModelRefine::FaceUniter uniter(solid);
|
||||
if (uniter.process()) {
|
||||
TopoDS_Solid solidMod;
|
||||
if (uniter.getSolid(solidMod))
|
||||
builder.Add(comp, solidMod);
|
||||
}
|
||||
}
|
||||
// free shells
|
||||
for (xp.Init(_Shape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next()) {
|
||||
const TopoDS_Shell& shell = TopoDS::Shell(xp.Current());
|
||||
ModelRefine::FaceUniter uniter(shell);
|
||||
if (uniter.process()) {
|
||||
builder.Add(comp, uniter.getShell());
|
||||
}
|
||||
}
|
||||
// the rest
|
||||
for (xp.Init(_Shape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next()) {
|
||||
if (!xp.Current().IsNull())
|
||||
builder.Add(comp, xp.Current());
|
||||
}
|
||||
for (xp.Init(_Shape, TopAbs_WIRE, TopAbs_FACE); xp.More(); xp.Next()) {
|
||||
if (!xp.Current().IsNull())
|
||||
builder.Add(comp, xp.Current());
|
||||
}
|
||||
for (xp.Init(_Shape, TopAbs_EDGE, TopAbs_WIRE); xp.More(); xp.Next()) {
|
||||
if (!xp.Current().IsNull())
|
||||
builder.Add(comp, xp.Current());
|
||||
}
|
||||
for (xp.Init(_Shape, TopAbs_VERTEX, TopAbs_EDGE); xp.More(); xp.Next()) {
|
||||
if (!xp.Current().IsNull())
|
||||
builder.Add(comp, xp.Current());
|
||||
}
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
return _Shape;
|
||||
}
|
||||
|
||||
namespace Part {
|
||||
|
|
|
@ -219,7 +219,7 @@ public:
|
|||
void sewShape();
|
||||
bool fix(double, double, double);
|
||||
bool removeInternalWires(double);
|
||||
void removeSplitter();
|
||||
TopoDS_Shape removeSplitter() const;
|
||||
//@}
|
||||
|
||||
/** @name Getting basic geometric entities */
|
||||
|
|
|
@ -1251,8 +1251,8 @@ PyObject* TopoShapePy::removeSplitter(PyObject *args)
|
|||
|
||||
try {
|
||||
// Remove redundant splitter
|
||||
this->getTopoShapePtr()->removeSplitter();
|
||||
Py_Return;
|
||||
TopoDS_Shape shape = this->getTopoShapePtr()->removeSplitter();
|
||||
return new TopoShapePy(new TopoShape(shape));
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
|
|
|
@ -200,6 +200,49 @@ bool CmdPartSimpleCopy::isActive(void)
|
|||
return Gui::Selection().countObjectsOfType(partid) > 0;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Part_RefineShape
|
||||
//===========================================================================
|
||||
DEF_STD_CMD_A(CmdPartRefineShape);
|
||||
|
||||
CmdPartRefineShape::CmdPartRefineShape()
|
||||
: Command("Part_RefineShape")
|
||||
{
|
||||
sAppModule = "Part";
|
||||
sGroup = QT_TR_NOOP("Part");
|
||||
sMenuText = QT_TR_NOOP("Refine shape");
|
||||
sToolTipText = QT_TR_NOOP("Refine the copy of a shape");
|
||||
sWhatsThis = sToolTipText;
|
||||
sStatusTip = sToolTipText;
|
||||
}
|
||||
|
||||
void CmdPartRefineShape::activated(int iMsg)
|
||||
{
|
||||
Base::Type partid = Base::Type::fromName("Part::Feature");
|
||||
std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType(partid);
|
||||
openCommand("Refine shape");
|
||||
for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
|
||||
doCommand(Doc,"App.ActiveDocument.addObject('Part::Feature','%s').Shape="
|
||||
"App.ActiveDocument.%s.Shape.removeSplitter()\n"
|
||||
"App.ActiveDocument.ActiveObject.Label="
|
||||
"App.ActiveDocument.%s.Label\n",
|
||||
(*it)->getNameInDocument(),
|
||||
(*it)->getNameInDocument(),
|
||||
(*it)->getNameInDocument());
|
||||
copyVisual("ActiveObject", "ShapeColor", (*it)->getNameInDocument());
|
||||
copyVisual("ActiveObject", "LineColor", (*it)->getNameInDocument());
|
||||
copyVisual("ActiveObject", "PointColor", (*it)->getNameInDocument());
|
||||
}
|
||||
commitCommand();
|
||||
updateActive();
|
||||
}
|
||||
|
||||
bool CmdPartRefineShape::isActive(void)
|
||||
{
|
||||
Base::Type partid = Base::Type::fromName("Part::Feature");
|
||||
return Gui::Selection().countObjectsOfType(partid) > 0;
|
||||
}
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
void CreateSimplePartCommands(void)
|
||||
|
@ -208,4 +251,5 @@ void CreateSimplePartCommands(void)
|
|||
rcCmdMgr.addCommand(new CmdPartSimpleCylinder());
|
||||
rcCmdMgr.addCommand(new CmdPartShapeFromMesh());
|
||||
rcCmdMgr.addCommand(new CmdPartSimpleCopy());
|
||||
}
|
||||
rcCmdMgr.addCommand(new CmdPartRefineShape());
|
||||
}
|
||||
|
|
|
@ -63,7 +63,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
|||
part->setCommand("&Part");
|
||||
*part << "Part_Import" << "Part_Export" << "Separator";
|
||||
*part << "Part_Primitives" << "Part_ShapeFromMesh"
|
||||
<< "Part_MakeSolid" << "Part_ReverseShape" << "Part_SimpleCopy" << "Separator"
|
||||
<< "Part_MakeSolid" << "Part_ReverseShape" << "Part_SimpleCopy"
|
||||
<< "Part_RefineShape" << "Separator"
|
||||
<< "Part_Boolean" << "Part_CrossSections" << "Part_Extrude"
|
||||
<< "Part_Revolve" << "Part_Mirror" << "Part_Fillet"
|
||||
<< "Part_RuledSurface" << "Part_Loft"
|
||||
|
|
Loading…
Reference in New Issue
Block a user