Navigation Menu

Skip to content

Commit

Permalink
fixes #2512 Allow multi-face part design tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ickby authored and wwmayer committed May 18, 2016
1 parent 4f8973f commit 83ce80f
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureBoolean.cpp
Expand Up @@ -165,7 +165,7 @@ App::DocumentObjectExecReturn *Boolean::execute(void)
result = mkTrf.Shape();
}

this->Shape.setValue(result);
this->Shape.setValue(getSolid(result));
return App::DocumentObject::StdReturn;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureChamfer.cpp
Expand Up @@ -115,7 +115,7 @@ App::DocumentObjectExecReturn *Chamfer::execute(void)
return new App::DocumentObjectExecReturn("Resulting shape is invalid");
}

this->Shape.setValue(shape);
this->Shape.setValue(getSolid(shape));
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureDraft.cpp
Expand Up @@ -302,7 +302,7 @@ App::DocumentObjectExecReturn *Draft::execute(void)
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null");

this->Shape.setValue(shape);
this->Shape.setValue(getSolid(shape));
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureFillet.cpp
Expand Up @@ -106,7 +106,7 @@ App::DocumentObjectExecReturn *Fillet::execute(void)
return new App::DocumentObjectExecReturn("Resulting shape is invalid");
}

this->Shape.setValue(shape);
this->Shape.setValue(getSolid(shape));
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Expand Down
13 changes: 9 additions & 4 deletions src/Mod/PartDesign/App/FeatureGroove.cpp
Expand Up @@ -129,9 +129,14 @@ App::DocumentObjectExecReturn *Groove::execute(void)
sketchshape.Move(invObjLoc);

// Check distance between sketchshape and axis - to avoid failures and crashes
if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(sketchshape)))
return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");

TopExp_Explorer xp;
xp.Init(sketchshape, TopAbs_FACE);
for (;xp.More(); xp.Next()) {

if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(xp.Current())))
return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");
}

// revolve the face to a solid
BRepPrimAPI_MakeRevol RevolMaker(sketchshape, gp_Ax1(pnt, dir), angle);

Expand Down Expand Up @@ -164,7 +169,7 @@ App::DocumentObjectExecReturn *Groove::execute(void)
Handle_Standard_Failure e = Standard_Failure::Caught();
if (std::string(e->GetMessageString()) == "TopoDS::Face")
return new App::DocumentObjectExecReturn("Could not create face from sketch.\n"
"Intersecting sketch entities or multiple faces in a sketch are not allowed.");
"Intersecting sketch entities in a sketch are not allowed.");
else
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/PartDesign/App/FeatureHole.cpp
Expand Up @@ -136,7 +136,7 @@ App::DocumentObjectExecReturn *Hole::execute(void)
// // if the sketch has a support fuse them to get one result object (PAD!)
// if (SupportObject) {
// // Set the subtractive shape property for later usage in e.g. pattern
// this->SubShape.setValue(PrismMaker.Shape());
// this->SubShape.setValue(getSolid(PrismMaker.Shape()));
// const TopoDS_Shape& support = SupportObject->Shape.getValue();
// if (support.IsNull())
// return new App::DocumentObjectExecReturn("Support shape is invalid");
Expand All @@ -148,7 +148,7 @@ App::DocumentObjectExecReturn *Hole::execute(void)
// // Let's check if the fusion has been successful
// if (!mkCut.IsDone())
// return new App::DocumentObjectExecReturn("Cut with support failed");
// this->Shape.setValue(mkCut.Shape());
// this->Shape.setValue(getSolid(mkCut.Shape()));
// }
// else{
// return new App::DocumentObjectExecReturn("Cannot create a tool out of sketch with no support");
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/PartDesign/App/FeatureLoft.cpp
Expand Up @@ -178,7 +178,7 @@ App::DocumentObjectExecReturn *Loft::execute(void)
AddSubShape.setValue(result);

if(base.IsNull()) {
Shape.setValue(result);
Shape.setValue(getSolid(result));
return App::DocumentObject::StdReturn;
}

Expand All @@ -194,7 +194,7 @@ App::DocumentObjectExecReturn *Loft::execute(void)
return new App::DocumentObjectExecReturn("Loft: Resulting shape is not a solid");

boolOp = refineShapeIfActive(boolOp);
Shape.setValue(boolOp);
Shape.setValue(getSolid(boolOp));
}
else if(getAddSubType() == FeatureAddSub::Subtractive) {

Expand All @@ -208,7 +208,7 @@ App::DocumentObjectExecReturn *Loft::execute(void)
return new App::DocumentObjectExecReturn("Loft: Resulting shape is not a solid");

boolOp = refineShapeIfActive(boolOp);
Shape.setValue(boolOp);
Shape.setValue(getSolid(boolOp));
}

return App::DocumentObject::StdReturn;
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/PartDesign/App/FeaturePad.cpp
Expand Up @@ -213,7 +213,7 @@ App::DocumentObjectExecReturn *Pad::execute(void)

if (!base.IsNull()) {
// auto obj = getDocument()->addObject("Part::Feature", "prism");
// static_cast<Part::Feature*>(obj)->Shape.setValue(prism);
// static_cast<Part::Feature*>(obj)->Shape.setValue(getSolid(prism));
// Let's call algorithm computing a fuse operation:
BRepAlgoAPI_Fuse mkFuse(base, prism);
// Let's check if the fusion has been successful
Expand All @@ -226,9 +226,9 @@ App::DocumentObjectExecReturn *Pad::execute(void)
if (solRes.IsNull())
return new App::DocumentObjectExecReturn("Pad: Resulting shape is not a solid");
solRes = refineShapeIfActive(solRes);
this->Shape.setValue(solRes);
this->Shape.setValue(getSolid(solRes));
} else {
this->Shape.setValue(prism);
this->Shape.setValue(getSolid(prism));
}

return App::DocumentObject::StdReturn;
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/PartDesign/App/FeaturePipe.cpp
Expand Up @@ -285,7 +285,7 @@ App::DocumentObjectExecReturn *Pipe::execute(void)
AddSubShape.setValue(result);

if(base.IsNull()) {
Shape.setValue(result);
Shape.setValue(getSolid(result));
return App::DocumentObject::StdReturn;
}

Expand All @@ -301,7 +301,7 @@ App::DocumentObjectExecReturn *Pipe::execute(void)
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");

boolOp = refineShapeIfActive(boolOp);
Shape.setValue(boolOp);
Shape.setValue(getSolid(boolOp));
}
else if(getAddSubType() == FeatureAddSub::Subtractive) {

Expand All @@ -315,7 +315,7 @@ App::DocumentObjectExecReturn *Pipe::execute(void)
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");

boolOp = refineShapeIfActive(boolOp);
Shape.setValue(boolOp);
Shape.setValue(getSolid(boolOp));
}

return App::DocumentObject::StdReturn;
Expand Down
18 changes: 9 additions & 9 deletions src/Mod/PartDesign/App/FeaturePocket.cpp
Expand Up @@ -94,10 +94,10 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
return new App::DocumentObjectExecReturn("Pocket: Length of pocket too small");

Part::Feature* obj = 0;
TopoDS_Face face;
TopoDS_Shape profileshape;
try {
obj = getVerifiedObject();
face = getVerifiedFace();
profileshape = getVerifiedFace();
} catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
Expand Down Expand Up @@ -126,9 +126,9 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
gp_Dir dir(SketchVector.x,SketchVector.y,SketchVector.z);
dir.Transform(invObjLoc.Transformation());

if (face.IsNull())
if (profileshape.IsNull())
return new App::DocumentObjectExecReturn("Pocket: Creating a face from sketch failed");
face.Move(invObjLoc);
profileshape.Move(invObjLoc);

std::string method(Type.getValueAsString());
if (method == "UpToFirst" || method == "UpToFace") {
Expand All @@ -148,7 +148,7 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
getUpToFaceFromLinkSub(upToFace, UpToFace);
upToFace.Move(invObjLoc);
}
getUpToFace(upToFace, base, supportface, face, method, dir, Offset.getValue());
getUpToFace(upToFace, base, supportface, profileshape, method, dir, Offset.getValue());

// BRepFeat_MakePrism(..., 2, 1) in combination with PerForm(upToFace) is buggy when the
// prism that is being created is contained completely inside the base solid
Expand All @@ -161,7 +161,7 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
if (!Ex.More())
supportface = TopoDS_Face();
BRepFeat_MakePrism PrismMaker;
PrismMaker.Init(base, face, supportface, dir, 0, 1);
PrismMaker.Init(base, profileshape, supportface, dir, 0, 1);
PrismMaker.Perform(upToFace);

if (!PrismMaker.IsDone())
Expand All @@ -175,10 +175,10 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
// FIXME: In some cases this affects the Shape property: It is set to the same shape as the SubShape!!!!
TopoDS_Shape result = refineShapeIfActive(mkCut.Shape());
this->AddSubShape.setValue(result);
this->Shape.setValue(prism);
this->Shape.setValue(getSolid(prism));
} else {
TopoDS_Shape prism;
generatePrism(prism, face, method, dir, L, 0.0,
generatePrism(prism, profileshape, method, dir, L, 0.0,
Midplane.getValue(), Reversed.getValue());
if (prism.IsNull())
return new App::DocumentObjectExecReturn("Pocket: Resulting shape is empty");
Expand All @@ -198,7 +198,7 @@ App::DocumentObjectExecReturn *Pocket::execute(void)
return new App::DocumentObjectExecReturn("Pocket: Resulting shape is not a solid");
solRes = refineShapeIfActive(solRes);
remapSupportShape(solRes);
this->Shape.setValue(solRes);
this->Shape.setValue(getSolid(solRes));
}

return App::DocumentObject::StdReturn;
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/PartDesign/App/FeaturePrimitive.cpp
Expand Up @@ -103,7 +103,7 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri
AddSubShape.setValue(primitiveShape);

if(getAddSubType() == FeatureAddSub::Additive)
Shape.setValue(primitiveShape);
Shape.setValue(getSolid(primitiveShape));
else
return new App::DocumentObjectExecReturn("Cannot subtract primitive feature without base feature");

Expand All @@ -122,7 +122,7 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");

boolOp = refineShapeIfActive(boolOp);
Shape.setValue(boolOp);
Shape.setValue(getSolid(boolOp));
AddSubShape.setValue(primitiveShape);
}
else if(getAddSubType() == FeatureAddSub::Subtractive) {
Expand All @@ -137,7 +137,7 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");

boolOp = refineShapeIfActive(boolOp);
Shape.setValue(boolOp);
Shape.setValue(getSolid(boolOp));
AddSubShape.setValue(primitiveShape);
}

Expand Down
12 changes: 8 additions & 4 deletions src/Mod/PartDesign/App/FeatureRevolution.cpp
Expand Up @@ -131,8 +131,12 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
sketchshape.Move(invObjLoc);

// Check distance between sketchshape and axis - to avoid failures and crashes
if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(sketchshape)))
return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");
TopExp_Explorer xp;
xp.Init(sketchshape, TopAbs_FACE);
for (;xp.More(); xp.Next()) {
if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(xp.Current())))
return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");
}

// revolve the face to a solid
BRepPrimAPI_MakeRevol RevolMaker(sketchshape, gp_Ax1(pnt, dir), angle);
Expand All @@ -153,7 +157,7 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
result = refineShapeIfActive(result);
}

this->Shape.setValue(result);
this->Shape.setValue(getSolid(result));
}
else
return new App::DocumentObjectExecReturn("Could not revolve the sketch!");
Expand All @@ -164,7 +168,7 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
Handle_Standard_Failure e = Standard_Failure::Caught();
if (std::string(e->GetMessageString()) == "TopoDS::Face")
return new App::DocumentObjectExecReturn("Could not create face from sketch.\n"
"Intersecting sketch entities or multiple faces in a sketch are not allowed.");
"Intersecting sketch entities in a sketch are not allowed.");
else
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
Expand Down
26 changes: 14 additions & 12 deletions src/Mod/PartDesign/App/FeatureSketchBased.cpp
Expand Up @@ -192,7 +192,7 @@ Part::Feature* ProfileBased::getVerifiedObject(bool silent) const {
return static_cast<Part::Feature*>(result);
}

TopoDS_Face ProfileBased::getVerifiedFace(bool silent) const {
TopoDS_Shape ProfileBased::getVerifiedFace(bool silent) const {

App::DocumentObject* result = Profile.getValue();
const char* err = nullptr;
Expand All @@ -203,7 +203,7 @@ TopoDS_Face ProfileBased::getVerifiedFace(bool silent) const {
if (result->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {

auto wires = getProfileWires();
return TopoDS::Face(makeFace(wires));
return makeFace(wires);
}
else if(result->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if(Profile.getSubValues().empty())
Expand Down Expand Up @@ -1233,16 +1233,18 @@ Base::Vector3d ProfileBased::getProfileNormal() const {
SketchOrientation.multVec(SketchVector,SketchVector);
}
else {
TopoDS_Face face = getVerifiedFace(true);
BRepAdaptor_Surface adapt(face);
double u = adapt.FirstUParameter() + (adapt.LastUParameter() - adapt.FirstUParameter())/2.;
double v = adapt.FirstVParameter() + (adapt.LastVParameter() - adapt.FirstVParameter())/2.;
BRepLProp_SLProps prop(adapt,u,v,2,Precision::Confusion());
if(prop.IsNormalDefined()) {
gp_Pnt pnt; gp_Vec vec;
// handles the orientation state of the shape
BRepGProp_Face(face).Normal(u,v,pnt,vec);
SketchVector = Base::Vector3d(vec.X(), vec.Y(), vec.Z());
TopoDS_Shape shape = getVerifiedFace(true);
if(shape.ShapeType() == TopAbs_FACE) {
BRepAdaptor_Surface adapt(TopoDS::Face(shape));
double u = adapt.FirstUParameter() + (adapt.LastUParameter() - adapt.FirstUParameter())/2.;
double v = adapt.FirstVParameter() + (adapt.LastVParameter() - adapt.FirstVParameter())/2.;
BRepLProp_SLProps prop(adapt,u,v,2,Precision::Confusion());
if(prop.IsNormalDefined()) {
gp_Pnt pnt; gp_Vec vec;
// handles the orientation state of the shape
BRepGProp_Face(TopoDS::Face(shape)).Normal(u,v,pnt,vec);
SketchVector = Base::Vector3d(vec.X(), vec.Y(), vec.Z());
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Mod/PartDesign/App/FeatureSketchBased.h
Expand Up @@ -85,11 +85,11 @@ class PartDesignExport ProfileBased : public PartDesign::FeatureAddSub

/**
* Verifies the linked Object and returns the shape used as profile
* @param silent if profile property is malformed and the parameter is true
* @param silent if profirle property is malformed and the parameter is true
* silently returns nullptr, otherwice throw a Base::Exception.
* Default is false.
*/
TopoDS_Face getVerifiedFace(bool silent = false) const;
TopoDS_Shape getVerifiedFace(bool silent = false) const;

/// Returns the wires the sketch is composed of
std::vector<TopoDS_Wire> getProfileWires() const;
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/PartDesign/App/FeatureThickness.cpp
Expand Up @@ -85,8 +85,8 @@ App::DocumentObjectExecReturn *Thickness::execute(void)
join = 2;

if (fabs(thickness) > 2*tol)
this->Shape.setValue(TopShape.makeThickSolid(closingFaces, thickness, tol, false, false, mode, join));
this->Shape.setValue(getSolid(TopShape.makeThickSolid(closingFaces, thickness, tol, false, false, mode, join)));
else
this->Shape.setValue(TopShape._Shape);
this->Shape.setValue(getSolid(TopShape._Shape));
return App::DocumentObject::StdReturn;
}
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/App/FeatureTransformed.cpp
Expand Up @@ -358,7 +358,7 @@ App::DocumentObjectExecReturn *Transformed::execute(void)
for (trsf_it::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
rejected[it->first].push_back(**it2);

this->Shape.setValue(support);
this->Shape.setValue(getSolid(support));
return App::DocumentObject::StdReturn;
}

Expand Down

0 comments on commit 83ce80f

Please sign in to comment.