+ padding with support shape can also be a set of solids as intermediate result

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5072 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
wmayer 2011-10-27 09:58:28 +00:00
parent 8fad3bab7a
commit 6eb79ab708
4 changed files with 72 additions and 52 deletions

View File

@ -23,6 +23,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Standard_Failure.hxx>
# include <TopoDS_Solid.hxx>
# include <TopExp_Explorer.hxx>
#endif
@ -39,4 +42,17 @@ Feature::Feature()
{
}
TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape) const
{
if (shape.IsNull())
Standard_Failure::Raise("Shape is null");
TopExp_Explorer xp;
xp.Init(shape,TopAbs_SOLID);
for (;xp.More(); xp.Next()) {
return xp.Current();
}
return TopoDS_Shape();
}
}

View File

@ -44,6 +44,10 @@ public:
Feature();
protected:
/**
* Get a solid of the given shape. If no solid is found an exception is raised.
*/
TopoDS_Shape getSolid(const TopoDS_Shape&) const;
};
} //namespace PartDesign

View File

@ -122,54 +122,60 @@ App::DocumentObjectExecReturn *Pad::execute(void)
// lengthen the vector
SketchOrientationVector *= Length.getValue();
// extrude the face to a solid
gp_Vec vec(SketchOrientationVector.x,SketchOrientationVector.y,SketchOrientationVector.z);
BRepPrimAPI_MakePrism PrismMaker(aFace,vec,0,1);
if (PrismMaker.IsDone()) {
TopoDS_Shape result = TopoDS::Solid(PrismMaker.Shape());
// set the additive shape property for later usage in e.g. pattern
this->AddShape.setValue(result);
// if the sketch has a support fuse them to get one result object (PAD!)
if (SupportObject) {
const TopoDS_Shape& support = SupportObject->Shape.getValue();
bool isSolid = false;
if (!support.IsNull()) {
TopExp_Explorer xp;
xp.Init(support,TopAbs_SOLID);
for (;xp.More(); xp.Next()) {
isSolid = true;
break;
}
}
if (isSolid) {
// Let's call algorithm computing a fuse operation:
BRepAlgoAPI_Fuse mkFuse(support, result);
// Let's check if the fusion has been successful
if (!mkFuse.IsDone())
return new App::DocumentObjectExecReturn("Fusion with support failed");
result = mkFuse.Shape();
// we have to get the solids (fuse create seldomly compounds)
TopExp_Explorer anExplorer;
anExplorer.Init(result,TopAbs_SOLID);
//if(
// get the first
TopoDS_Solid solRes = TopoDS::Solid(anExplorer.Current());
try {
// extrude the face to a solid
gp_Vec vec(SketchOrientationVector.x,SketchOrientationVector.y,SketchOrientationVector.z);
BRepPrimAPI_MakePrism PrismMaker(aFace,vec,0,1);
if (PrismMaker.IsDone()) {
// if the sketch has a support fuse them to get one result object (PAD!)
if (SupportObject) {
// At this point the prism can be a compound
TopoDS_Shape result = PrismMaker.Shape();
// set the additive shape property for later usage in e.g. pattern
this->AddShape.setValue(result);
// lets check if the result is a solid
if (solRes.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
this->Shape.setValue(solRes);
const TopoDS_Shape& support = SupportObject->Shape.getValue();
bool isSolid = false;
if (!support.IsNull()) {
TopExp_Explorer xp;
xp.Init(support,TopAbs_SOLID);
for (;xp.More(); xp.Next()) {
isSolid = true;
break;
}
}
if (isSolid) {
// Let's call algorithm computing a fuse operation:
BRepAlgoAPI_Fuse mkFuse(support, result);
// Let's check if the fusion has been successful
if (!mkFuse.IsDone())
return new App::DocumentObjectExecReturn("Fusion with support failed");
result = mkFuse.Shape();
// we have to get the solids (fuse create seldomly compounds)
TopoDS_Shape solRes = this->getSolid(result);
// lets check if the result is a solid
if (solRes.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
this->Shape.setValue(solRes);
}
else
return new App::DocumentObjectExecReturn("Support is not a solid");
}
else {
TopoDS_Shape result = TopoDS::Solid(PrismMaker.Shape());
// set the additive shape property for later usage in e.g. pattern
this->AddShape.setValue(result);
this->Shape.setValue(result);
}
else
return new App::DocumentObjectExecReturn("Support is not a solid");
}
else
this->Shape.setValue(result);
}
else
return new App::DocumentObjectExecReturn("Could not extrude the sketch!");
return new App::DocumentObjectExecReturn("Could not extrude the sketch!");
return App::DocumentObject::StdReturn;
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}

View File

@ -141,18 +141,12 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
return new App::DocumentObjectExecReturn("Cut with support failed");
// we have to get the solids (fuse create seldomly compounds)
TopExp_Explorer anExplorer;
anExplorer.Init(mkCut.Shape(),TopAbs_SOLID);
TopoDS_Solid solRes = TopoDS::Solid(anExplorer.Current());
TopoDS_Shape solRes = this->getSolid(mkCut.Shape());
if (solRes.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
this->Shape.setValue(solRes);
//this->Shape.setValue(mkCut.Shape());
}
else{
else {
return new App::DocumentObjectExecReturn("Cannot create a tool out of sketch with no support");
}
}