Merge branch 'master' of ssh://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad

This commit is contained in:
wmayer 2012-10-29 20:13:42 +01:00
commit 8d81642838
6 changed files with 87 additions and 91 deletions

View File

@ -82,37 +82,39 @@ App::DocumentObjectExecReturn *Groove::execute(void)
if (Reversed.getValue() && !Midplane.getValue()) if (Reversed.getValue() && !Midplane.getValue())
angle *= (-1.0); angle *= (-1.0);
Part::Part2DObject* pcSketch = 0; Part::Part2DObject* sketch = 0;
std::vector<TopoDS_Wire> wires; std::vector<TopoDS_Wire> wires;
TopoDS_Shape support;
try { try {
pcSketch = getVerifiedSketch(); sketch = getVerifiedSketch();
wires = getSketchWires(); wires = getSketchWires();
support = getSupportShape();
} catch (const Base::Exception& e) { } catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what()); return new App::DocumentObjectExecReturn(e.what());
} }
// get the Sketch plane // get the Sketch plane
Base::Placement SketchPlm = pcSketch->Placement.getValue(); Base::Placement SketchPlm = sketch->Placement.getValue();
// get reference axis // get reference axis
App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue(); App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues(); const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues();
if (pcReferenceAxis && pcReferenceAxis == pcSketch) { if (pcReferenceAxis && pcReferenceAxis == sketch) {
bool hasValidAxis=false; bool hasValidAxis=false;
Base::Axis axis; Base::Axis axis;
if (subReferenceAxis[0] == "V_Axis") { if (subReferenceAxis[0] == "V_Axis") {
hasValidAxis = true; hasValidAxis = true;
axis = pcSketch->getAxis(Part::Part2DObject::V_Axis); axis = sketch->getAxis(Part::Part2DObject::V_Axis);
} }
else if (subReferenceAxis[0] == "H_Axis") { else if (subReferenceAxis[0] == "H_Axis") {
hasValidAxis = true; hasValidAxis = true;
axis = pcSketch->getAxis(Part::Part2DObject::H_Axis); axis = sketch->getAxis(Part::Part2DObject::H_Axis);
} }
else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") { else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") {
int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str()); int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str());
if (AxId >= 0 && AxId < pcSketch->getAxisCount()) { if (AxId >= 0 && AxId < sketch->getAxisCount()) {
hasValidAxis = true; hasValidAxis = true;
axis = pcSketch->getAxis(AxId); axis = sketch->getAxis(AxId);
} }
} }
if (hasValidAxis) { if (hasValidAxis) {
@ -130,12 +132,6 @@ App::DocumentObjectExecReturn *Groove::execute(void)
Base::Vector3f v = Axis.getValue(); Base::Vector3f v = Axis.getValue();
gp_Dir dir(v.x,v.y,v.z); gp_Dir dir(v.x,v.y,v.z);
// get the support of the Sketch if any
App::DocumentObject* pcSupport = pcSketch->Support.getValue();
Part::Feature *SupportObject = 0;
if (pcSupport && pcSupport->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
SupportObject = static_cast<Part::Feature*>(pcSupport);
TopoDS_Shape aFace = makeFace(wires); TopoDS_Shape aFace = makeFace(wires);
if (aFace.IsNull()) if (aFace.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
@ -163,20 +159,18 @@ App::DocumentObjectExecReturn *Groove::execute(void)
// Set the subtractive shape property for later usage in e.g. pattern // Set the subtractive shape property for later usage in e.g. pattern
this->SubShape.setValue(result); this->SubShape.setValue(result);
// if the sketch has a support fuse them to get one result object (PAD!) // cut out groove to get one result object
if (SupportObject) { BRepAlgoAPI_Cut mkCut(support.Moved(invObjLoc), result);
const TopoDS_Shape& support = SupportObject->Shape.getValue(); // Let's check if the fusion has been successful
if (!support.IsNull() && support.ShapeType() == TopAbs_SOLID) { if (!mkCut.IsDone())
// Let's call algorithm computing a fuse operation: throw Base::Exception("Cut out of support failed");
BRepAlgoAPI_Cut mkCut(support.Moved(invObjLoc), result);
// Let's check if the fusion has been successful
if (!mkCut.IsDone())
throw Base::Exception("Cut out of support failed");
result = mkCut.Shape();
}
}
this->Shape.setValue(result); // we have to get the solids (fuse sometimes creates compounds)
TopoDS_Shape solRes = this->getSolid(mkCut.Shape());
if (solRes.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
this->Shape.setValue(solRes);
} }
else else
return new App::DocumentObjectExecReturn("Could not revolve the sketch!"); return new App::DocumentObjectExecReturn("Could not revolve the sketch!");

View File

@ -81,27 +81,29 @@ App::DocumentObjectExecReturn *Pad::execute(void)
if ((std::string(Type.getValueAsString()) == "TwoLengths") && (L < Precision::Confusion())) if ((std::string(Type.getValueAsString()) == "TwoLengths") && (L < Precision::Confusion()))
return new App::DocumentObjectExecReturn("Second length of pad too small"); return new App::DocumentObjectExecReturn("Second length of pad too small");
Part::Part2DObject* pcSketch = 0; Part::Part2DObject* sketch = 0;
std::vector<TopoDS_Wire> wires; std::vector<TopoDS_Wire> wires;
try { try {
pcSketch = getVerifiedSketch(); sketch = getVerifiedSketch();
wires = getSketchWires(); wires = getSketchWires();
} catch (const Base::Exception& e) { } catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what()); return new App::DocumentObjectExecReturn(e.what());
} }
TopoDS_Shape support;
try {
support = getSupportShape();
} catch (const Base::Exception&) {
// ignore, because support isn't mandatory
support = TopoDS_Shape();
}
// get the Sketch plane // get the Sketch plane
Base::Placement SketchPos = pcSketch->Placement.getValue(); Base::Placement SketchPos = sketch->Placement.getValue();
Base::Rotation SketchOrientation = SketchPos.getRotation(); Base::Rotation SketchOrientation = SketchPos.getRotation();
Base::Vector3d SketchVector(0,0,1); Base::Vector3d SketchVector(0,0,1);
SketchOrientation.multVec(SketchVector,SketchVector); SketchOrientation.multVec(SketchVector,SketchVector);
// get the support of the Sketch if any
App::DocumentObject* SupportLink = pcSketch->Support.getValue();
Part::Feature *SupportObject = 0;
if (SupportLink && SupportLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
SupportObject = static_cast<Part::Feature*>(SupportLink);
TopoDS_Shape aFace = makeFace(wires); TopoDS_Shape aFace = makeFace(wires);
if (aFace.IsNull()) if (aFace.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
@ -126,12 +128,8 @@ App::DocumentObjectExecReturn *Pad::execute(void)
(std::string(Type.getValueAsString()) == "UpToFirst")) (std::string(Type.getValueAsString()) == "UpToFirst"))
{ {
// Check for valid support object // Check for valid support object
if (!SupportObject)
return new App::DocumentObjectExecReturn("Cannot extrude up to face: No support in Sketch!");
const TopoDS_Shape& support = SupportObject->Shape.getValue();
if (support.IsNull()) if (support.IsNull())
return new App::DocumentObjectExecReturn("Cannot extrude up to face: Support shape is invalid"); return new App::DocumentObjectExecReturn("Cannot extrude up to face: No valid support in Sketch");
TopExp_Explorer xp (support, TopAbs_SOLID); TopExp_Explorer xp (support, TopAbs_SOLID);
if (!xp.More()) if (!xp.More())
return new App::DocumentObjectExecReturn("Cannot extrude up to face: Support shape is not a solid"); return new App::DocumentObjectExecReturn("Cannot extrude up to face: Support shape is not a solid");
@ -251,12 +249,11 @@ App::DocumentObjectExecReturn *Pad::execute(void)
return new App::DocumentObjectExecReturn("Internal error: Unknown type for Pad feature"); return new App::DocumentObjectExecReturn("Internal error: Unknown type for Pad feature");
} }
// if the sketch has a support fuse them to get one result object (PAD!) // set the additive shape property for later usage in e.g. pattern
if (SupportObject) { this->AddShape.setValue(prism);
// set the additive shape property for later usage in e.g. pattern
this->AddShape.setValue(prism);
const TopoDS_Shape& support = SupportObject->Shape.getValue(); // if the sketch has a support fuse them to get one result object (PAD!)
if (!support.IsNull()) {
if (!isSolidChecked) { // we haven't checked for solid, yet if (!isSolidChecked) { // we haven't checked for solid, yet
if (!support.IsNull()) { if (!support.IsNull()) {

View File

@ -80,37 +80,23 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
if ((std::string(Type.getValueAsString()) == "Length") && (L < Precision::Confusion())) if ((std::string(Type.getValueAsString()) == "Length") && (L < Precision::Confusion()))
return new App::DocumentObjectExecReturn("Pocket: Length of pocket too small"); return new App::DocumentObjectExecReturn("Pocket: Length of pocket too small");
Part::Part2DObject* pcSketch = 0; Part::Part2DObject* sketch = 0;
std::vector<TopoDS_Wire> wires; std::vector<TopoDS_Wire> wires;
TopoDS_Shape support;
try { try {
pcSketch = getVerifiedSketch(); sketch = getVerifiedSketch();
wires = getSketchWires(); wires = getSketchWires();
support = getSupportShape();
} catch (const Base::Exception& e) { } catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what()); return new App::DocumentObjectExecReturn(e.what());
} }
// get the Sketch plane // get the Sketch plane
Base::Placement SketchPos = pcSketch->Placement.getValue(); Base::Placement SketchPos = sketch->Placement.getValue();
Base::Rotation SketchOrientation = SketchPos.getRotation(); Base::Rotation SketchOrientation = SketchPos.getRotation();
Base::Vector3d SketchVector(0,0,1); Base::Vector3d SketchVector(0,0,1);
SketchOrientation.multVec(SketchVector,SketchVector); SketchOrientation.multVec(SketchVector,SketchVector);
// get the support of the Sketch if any
App::DocumentObject* SupportLink = pcSketch->Support.getValue();
Part::Feature *SupportObject = 0;
if (SupportLink && SupportLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
SupportObject = static_cast<Part::Feature*>(SupportLink);
if (!SupportObject)
return new App::DocumentObjectExecReturn("No support in Sketch!");
const TopoDS_Shape& support = SupportObject->Shape.getValue();
if (support.IsNull())
return new App::DocumentObjectExecReturn("Support shape is invalid");
TopExp_Explorer xp (support, TopAbs_SOLID);
if (!xp.More())
return new App::DocumentObjectExecReturn("Support shape is not a solid");
TopoDS_Shape aFace = makeFace(wires); TopoDS_Shape aFace = makeFace(wires);
if (aFace.IsNull()) if (aFace.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); return new App::DocumentObjectExecReturn("Creating a face from sketch failed");

View File

@ -77,37 +77,45 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
if (a > 360.0) if (a > 360.0)
return new App::DocumentObjectExecReturn("Angle of groove too large"); return new App::DocumentObjectExecReturn("Angle of groove too large");
Part::Part2DObject* pcSketch = 0; Part::Part2DObject* sketch = 0;
std::vector<TopoDS_Wire> wires; std::vector<TopoDS_Wire> wires;
try { try {
pcSketch = getVerifiedSketch(); sketch = getVerifiedSketch();
wires = getSketchWires(); wires = getSketchWires();
} catch (const Base::Exception& e) { } catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what()); return new App::DocumentObjectExecReturn(e.what());
} }
TopoDS_Shape support;
try {
support = getSupportShape();
} catch (const Base::Exception&) {
// ignore, because support isn't mandatory
support = TopoDS_Shape();
}
// get the Sketch plane // get the Sketch plane
Base::Placement SketchPlm = pcSketch->Placement.getValue(); Base::Placement SketchPlm = sketch->Placement.getValue();
// get reference axis // get reference axis
App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue(); App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues(); const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues();
if (pcReferenceAxis && pcReferenceAxis == pcSketch) { if (pcReferenceAxis && pcReferenceAxis == sketch) {
bool hasValidAxis=false; bool hasValidAxis=false;
Base::Axis axis; Base::Axis axis;
if (subReferenceAxis[0] == "V_Axis") { if (subReferenceAxis[0] == "V_Axis") {
hasValidAxis = true; hasValidAxis = true;
axis = pcSketch->getAxis(Part::Part2DObject::V_Axis); axis = sketch->getAxis(Part::Part2DObject::V_Axis);
} }
else if (subReferenceAxis[0] == "H_Axis") { else if (subReferenceAxis[0] == "H_Axis") {
hasValidAxis = true; hasValidAxis = true;
axis = pcSketch->getAxis(Part::Part2DObject::H_Axis); axis = sketch->getAxis(Part::Part2DObject::H_Axis);
} }
else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") { else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") {
int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str()); int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str());
if (AxId >= 0 && AxId < pcSketch->getAxisCount()) { if (AxId >= 0 && AxId < sketch->getAxisCount()) {
hasValidAxis = true; hasValidAxis = true;
axis = pcSketch->getAxis(AxId); axis = sketch->getAxis(AxId);
} }
} }
if (hasValidAxis) { if (hasValidAxis) {
@ -125,12 +133,6 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
Base::Vector3f v = Axis.getValue(); Base::Vector3f v = Axis.getValue();
gp_Dir dir(v.x,v.y,v.z); gp_Dir dir(v.x,v.y,v.z);
// get the support of the Sketch if any
App::DocumentObject* pcSupport = pcSketch->Support.getValue();
Part::Feature *SupportObject = 0;
if (pcSupport && pcSupport->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
SupportObject = static_cast<Part::Feature*>(pcSupport);
TopoDS_Shape aFace = makeFace(wires); TopoDS_Shape aFace = makeFace(wires);
if (aFace.IsNull()) if (aFace.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
@ -163,18 +165,13 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
this->AddShape.setValue(result); this->AddShape.setValue(result);
// if the sketch has a support fuse them to get one result object (PAD!) // if the sketch has a support fuse them to get one result object (PAD!)
if (SupportObject) { if (!support.IsNull()) {
const TopoDS_Shape& support = SupportObject->Shape.getValue(); // Let's call algorithm computing a fuse operation:
if (!support.IsNull() && support.ShapeType() == TopAbs_SOLID) { BRepAlgoAPI_Fuse mkFuse(support.Moved(invObjLoc), result);
// set the additive shape property for later usage in e.g. pattern // Let's check if the fusion has been successful
this->AddShape.setValue(result); if (!mkFuse.IsDone())
// Let's call algorithm computing a fuse operation: throw Base::Exception("Fusion with support failed");
BRepAlgoAPI_Fuse mkFuse(support.Moved(invObjLoc), result); result = mkFuse.Shape();
// Let's check if the fusion has been successful
if (!mkFuse.IsDone())
throw Base::Exception("Fusion with support failed");
result = mkFuse.Shape();
}
} }
this->Shape.setValue(result); this->Shape.setValue(result);

View File

@ -136,6 +136,26 @@ std::vector<TopoDS_Wire> SketchBased::getSketchWires() const {
return result; return result;
} }
const TopoDS_Shape& SketchBased::getSupportShape() const {
// get the support of the Sketch if any
App::DocumentObject* SupportLink = static_cast<Part::Part2DObject*>(Sketch.getValue())->Support.getValue();
Part::Feature* SupportObject = NULL;
if (SupportLink && SupportLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
SupportObject = static_cast<Part::Feature*>(SupportLink);
if (SupportObject == NULL)
throw Base::Exception("No support in Sketch!");
const TopoDS_Shape& result = SupportObject->Shape.getValue();
if (result.IsNull())
throw Base::Exception("Support shape is invalid");
TopExp_Explorer xp (result, TopAbs_SOLID);
if (!xp.More())
throw Base::Exception("Support shape is not a solid");
return result;
}
void SketchBased::onChanged(const App::Property* prop) void SketchBased::onChanged(const App::Property* prop)
{ {
if (prop == &Sketch) { if (prop == &Sketch) {

View File

@ -59,6 +59,8 @@ public:
Part::Part2DObject* getVerifiedSketch() const; Part::Part2DObject* getVerifiedSketch() const;
/// Returns the wires the sketch is composed of /// Returns the wires the sketch is composed of
std::vector<TopoDS_Wire> getSketchWires() const; std::vector<TopoDS_Wire> getSketchWires() const;
/// Returns the sketch support shape (if any)
const TopoDS_Shape& getSupportShape() const;
/// retrieves the number of axes in the linked sketch (defined as construction lines) /// retrieves the number of axes in the linked sketch (defined as construction lines)
int getSketchAxisCount(void) const; int getSketchAxisCount(void) const;