diff --git a/src/Mod/Part/App/DatumFeature.cpp b/src/Mod/Part/App/DatumFeature.cpp index 407288be04..05ec5bf480 100644 --- a/src/Mod/Part/App/DatumFeature.cpp +++ b/src/Mod/Part/App/DatumFeature.cpp @@ -100,3 +100,9 @@ void Datum::onDocumentRestored() Part::Feature::onDocumentRestored(); } +TopoDS_Shape Datum::getShape() const +{ + Part::TopoShape sh = Shape.getShape(); + sh.setPlacement(Placement.getValue()); + return sh._Shape; +} diff --git a/src/Mod/Part/App/DatumFeature.h b/src/Mod/Part/App/DatumFeature.h index c10126138a..d2796b6eda 100644 --- a/src/Mod/Part/App/DatumFeature.h +++ b/src/Mod/Part/App/DatumFeature.h @@ -57,8 +57,8 @@ public: virtual const std::set getHint() = 0; - /// Return a shape representing the datum feature - //virtual const TopoDS_Shape getShape() const = 0; + /// Return a shape including Placement representing the datum feature + TopoDS_Shape getShape() const; protected: void onChanged (const App::Property* prop); diff --git a/src/Mod/PartDesign/App/Feature.h b/src/Mod/PartDesign/App/Feature.h index 050a73cea9..ab5309c1d3 100644 --- a/src/Mod/PartDesign/App/Feature.h +++ b/src/Mod/PartDesign/App/Feature.h @@ -52,6 +52,9 @@ public: short mustExecute() const; + /// Check whether the given feature is a datum feature + static bool isDatum(const App::DocumentObject* feature); + protected: /// Returns the BaseFeature property's shape (if any) const TopoDS_Shape& getBaseShape() const; @@ -62,10 +65,7 @@ protected: static TopoDS_Shape getSolid(const TopoDS_Shape&); /// Grab any point from the given face - static const gp_Pnt getPointFromFace(const TopoDS_Face& f); - - /// Check whether the given feature is a datum feature - static bool isDatum(const App::DocumentObject* feature); + static const gp_Pnt getPointFromFace(const TopoDS_Face& f); }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/App/FeatureGroove.cpp b/src/Mod/PartDesign/App/FeatureGroove.cpp index a126fcbd88..ede3a980ed 100644 --- a/src/Mod/PartDesign/App/FeatureGroove.cpp +++ b/src/Mod/PartDesign/App/FeatureGroove.cpp @@ -93,24 +93,17 @@ App::DocumentObjectExecReturn *Groove::execute(void) return new App::DocumentObjectExecReturn(e.what()); } - // Get the sketch support - TopoDS_Shape support; - try { - support = getSupportShape(); - } catch (const Base::Exception&) { - // ignore, because support isn't mandatory any more - support = TopoDS_Shape(); - } - - // Get the base shape + // if the Base property has a valid shape, fuse the prism into it TopoDS_Shape base; try { base = getBaseShape(); } catch (const Base::Exception&) { - // fall back to support (for legacy features) - base = support; - if (base.IsNull()) + try { + // fall back to support (for legacy features) + base = getSupportShape(); + } catch (const Base::Exception&) { return new App::DocumentObjectExecReturn("No sketch support and no base shape: Please tell me where to remove the material of the groove!"); + } } updateAxis(); @@ -138,7 +131,6 @@ App::DocumentObjectExecReturn *Groove::execute(void) TopLoc_Location invObjLoc = this->getLocation().Inverted(); pnt.Transform(invObjLoc.Transformation()); dir.Transform(invObjLoc.Transformation()); - support.Move(invObjLoc); base.Move(invObjLoc); sketchshape.Move(invObjLoc); diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index ebc414eb96..9859c9726d 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -96,17 +96,23 @@ App::DocumentObjectExecReturn *Pad::execute(void) return new App::DocumentObjectExecReturn(e.what()); } - TopoDS_Shape support; + // if the Base property has a valid shape, fuse the prism into it + TopoDS_Shape base; try { - support = getSupportShape(); + base = getBaseShape(); } catch (const Base::Exception&) { - // ignore, because support isn't mandatory - support = TopoDS_Shape(); + try { + // fall back to support (for legacy features) + base = getSupportShape(); + } catch (const Base::Exception&) { + // ignore, because support isn't mandatory + base = TopoDS_Shape(); + } } /* // Find Body feature which owns this Pad and get the shape of the feature preceding this one for fusing - // This method was rejected in favour of the Base property because it makes the feature atomic (independent of the + // This method was rejected in favour of the BaseFeature property because that makes the feature atomic (independent of the // Body object). See // https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=19&t=3831 // https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=19&t=3855 @@ -138,7 +144,7 @@ App::DocumentObjectExecReturn *Pad::execute(void) TopLoc_Location invObjLoc = this->getLocation().Inverted(); try { - support.Move(invObjLoc); + base.Move(invObjLoc); gp_Dir dir(SketchVector.x,SketchVector.y,SketchVector.z); dir.Transform(invObjLoc.Transformation()); @@ -151,42 +157,36 @@ App::DocumentObjectExecReturn *Pad::execute(void) TopoDS_Shape prism; std::string method(Type.getValueAsString()); if (method == "UpToFirst" || method == "UpToLast" || method == "UpToFace") { + // Note: This will throw an exception if the sketch is located on a datum plane TopoDS_Face supportface = getSupportFace(); supportface.Move(invObjLoc); if (Reversed.getValue()) dir.Reverse(); - // Find a valid face to extrude up to + // Find a valid face or datum plane to extrude up to TopoDS_Face upToFace; if (method == "UpToFace") { getUpToFaceFromLinkSub(upToFace, UpToFace); upToFace.Move(invObjLoc); } - getUpToFace(upToFace, support, supportface, sketchshape, method, dir); + getUpToFace(upToFace, base, supportface, sketchshape, method, dir); // A support object is always required and we need to use BRepFeat_MakePrism // Problem: For Pocket/UpToFirst (or an equivalent Pocket/UpToFace) the resulting shape is invalid // because the feature does not add any material. This only happens with the "2" option, though // Note: It might be possible to pass a shell or a compound containing multiple faces // as the Until parameter of Perform() - // Note: Multiple independent wires are not supported, that's why we have to iterate over them. - TopoDS_Compound comp; - BRep_Builder builder; - builder.MakeCompound(comp); - + // Note: Multiple independent wires are not supported, we should check for that and + // warn the user // FIXME: If the support shape is not the previous solid in the tree, then there will be unexpected results - for (TopExp_Explorer xp(sketchshape, TopAbs_FACE); xp.More(); xp.Next()) { - BRepFeat_MakePrism PrismMaker; - PrismMaker.Init(support, xp.Current(), supportface, dir, 2, 1); - PrismMaker.Perform(upToFace); + BRepFeat_MakePrism PrismMaker; + PrismMaker.Init(base, sketchshape, supportface, dir, 2, 1); + PrismMaker.Perform(upToFace); - if (!PrismMaker.IsDone()) - return new App::DocumentObjectExecReturn("Pad: Up to face: Could not extrude the sketch!"); - builder.Add(comp, PrismMaker.Shape()); - } - - prism = comp; + if (!PrismMaker.IsDone()) + return new App::DocumentObjectExecReturn("Pad: Up to face: Could not extrude the sketch!"); + prism = PrismMaker.Shape(); } else { generatePrism(prism, sketchshape, method, dir, L, L2, Midplane.getValue(), Reversed.getValue()); @@ -197,17 +197,7 @@ App::DocumentObjectExecReturn *Pad::execute(void) // set the additive shape property for later usage in e.g. pattern prism = refineShapeIfActive(prism); - this->AddShape.setValue(prism); - - // if the Base property has a valid shape, fuse the prism into it - TopoDS_Shape base; - try { - base = getBaseShape(); - base.Move(invObjLoc); - } catch (const Base::Exception&) { - // fall back to support (for legacy features) - base = support; - } + this->AddShape.setValue(prism); if (!base.IsNull()) { // Let's call algorithm computing a fuse operation: diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index 17374f5e88..e57e7aa442 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -96,24 +96,17 @@ App::DocumentObjectExecReturn *Pocket::execute(void) return new App::DocumentObjectExecReturn(e.what()); } - // Get the sketch support - TopoDS_Shape support; - try { - support = getSupportShape(); - } catch (const Base::Exception&) { - // ignore, because support isn't mandatory any more - support = TopoDS_Shape(); - } - - // Get the base shape + // if the Base property has a valid shape, fuse the prism into it TopoDS_Shape base; try { base = getBaseShape(); } catch (const Base::Exception&) { - // fall back to support (for legacy features) - base = support; - if (base.IsNull()) + try { + // fall back to support (for legacy features) + base = getSupportShape(); + } catch (const Base::Exception&) { return new App::DocumentObjectExecReturn("No sketch support and no base shape: Please tell me where to remove the material of the pocket!"); + } } // get the Sketch plane @@ -129,7 +122,6 @@ App::DocumentObjectExecReturn *Pocket::execute(void) TopLoc_Location invObjLoc = this->getLocation().Inverted(); try { - support.Move(invObjLoc); base.Move(invObjLoc); gp_Dir dir(SketchVector.x,SketchVector.y,SketchVector.z); @@ -142,45 +134,37 @@ App::DocumentObjectExecReturn *Pocket::execute(void) std::string method(Type.getValueAsString()); if (method == "UpToFirst" || method == "UpToFace") { + // Note: This will throw an exception if the sketch is located on a datum plane TopoDS_Face supportface = getSupportFace(); supportface.Move(invObjLoc); if (Reversed.getValue()) dir.Reverse(); - // Find a valid face to extrude up to + // Find a valid face or datum plane to extrude up to TopoDS_Face upToFace; if (method == "UpToFace") { getUpToFaceFromLinkSub(upToFace, UpToFace); upToFace.Move(invObjLoc); } - getUpToFace(upToFace, support, supportface, sketchshape, method, dir); + getUpToFace(upToFace, base, supportface, sketchshape, method, dir); - // #0001655: When 'supportshape' consists of several faces BRepFeat_MakePrism uses only the first face. - // Thus, we have to iterate over the faces and use the algorithm for each of them. - TopoDS_Shape prism = support; - for (TopExp_Explorer xp(sketchshape, TopAbs_FACE); xp.More(); xp.Next()) { - // Special treatment because often the created stand-alone prism is invalid (empty) because - // BRepFeat_MakePrism(..., 2, 1) is buggy - // FIXME: If the support shape is not the previous solid in the tree, then there will be unexpected results - BRepFeat_MakePrism PrismMaker; - PrismMaker.Init(prism, xp.Current(), supportface, dir, 0, 1); - PrismMaker.Perform(upToFace); + // Special treatment because often the created stand-alone prism is invalid (empty) because + // BRepFeat_MakePrism(..., 2, 1) is buggy + BRepFeat_MakePrism PrismMaker; + PrismMaker.Init(base, sketchshape, supportface, dir, 0, 1); + PrismMaker.Perform(upToFace); - if (!PrismMaker.IsDone()) - return new App::DocumentObjectExecReturn("Pocket: Up to face: Could not extrude the sketch!"); - prism = PrismMaker.Shape(); - } - - prism = refineShapeIfActive(prism); + if (!PrismMaker.IsDone()) + return new App::DocumentObjectExecReturn("Pocket: Up to face: Could not extrude the sketch!"); + TopoDS_Shape prism = PrismMaker.Shape(); // And the really expensive way to get the SubShape... - BRepAlgoAPI_Cut mkCut(support, prism); + BRepAlgoAPI_Cut mkCut(base, prism); if (!mkCut.IsDone()) return new App::DocumentObjectExecReturn("Pocket: Up to face: Could not get SubShape!"); // 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->SubShape.setValue(result); + this->SubShape.setValue(mkCut.Shape()); this->Shape.setValue(prism); } else { TopoDS_Shape prism; diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index fe3a470321..ca217b1ae3 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -65,11 +65,13 @@ #include #include +#include #include #include #include #include #include "FeatureSketchBased.h" +#include "DatumPlane.h" using namespace PartDesign; @@ -180,9 +182,13 @@ std::vector SketchBased::getSketchWires() const { // this method, it becomes null! const TopoDS_Face SketchBased::getSupportFace() const { const App::PropertyLinkSub& Support = static_cast(Sketch.getValue())->Support; + App::DocumentObject* ref = Support.getValue(); + if (ref->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) || + ref->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) + throw Base::Exception("Sketch must be located on a face of a solid for this feature to work"); Part::Feature *part = static_cast(Support.getValue()); if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) - throw Base::Exception("Sketch has no support shape"); + throw Base::Exception("No support in sketch"); const std::vector &sub = Support.getSubValues(); assert(sub.size()==1); @@ -449,6 +455,25 @@ void SketchBased::getUpToFaceFromLinkSub(TopoDS_Face& upToFace, if (ref == NULL) throw Base::Exception("SketchBased: Up to face: No face selected"); + + if (ref->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { + App::Plane* plane = static_cast(ref); + Base::Rotation rot = plane->Placement.getValue().getRotation(); + Base::Vector3d normal(0,0,1); + rot.multVec(normal, normal); + BRepBuilderAPI_MakeFace builder(gp_Pln(gp_Pnt(0,0,0), gp_Dir(normal.x,normal.y,normal.z))); + if (!builder.IsDone()) + throw Base::Exception("SketchBased: Up to face: Could not create shape from base plane"); + upToFace = TopoDS::Face(builder.Shape()); + return; + } + + if (ref->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { + Part::Datum* datum = static_cast(ref); + upToFace = TopoDS::Face(datum->getShape()); + return; + } + if (!ref->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) throw Base::Exception("SketchBased: Up to face: Must be face of a feature"); Part::TopoShape baseShape = static_cast(ref)->Shape.getShape(); @@ -472,7 +497,7 @@ void SketchBased::getUpToFace(TopoDS_Face& upToFace, if ((method == "UpToLast") || (method == "UpToFirst")) { // Check for valid support object if (support.IsNull()) - throw Base::Exception("SketchBased: Up to face: No support in Sketch!"); + throw Base::Exception("SketchBased: Up to face: No support in Sketch and no base feature!"); std::vector cfaces = Part::findAllFacesCutBy(support, sketchshape, dir); if (cfaces.empty()) @@ -489,33 +514,37 @@ void SketchBased::getUpToFace(TopoDS_Face& upToFace, upToFace = (method == "UpToLast" ? it_far->face : it_near->face); } - // Remove the limits of the upToFace so that the extrusion works even if sketchshape is larger - // than the upToFace - bool remove_limits = false; - TopExp_Explorer Ex; - for (Ex.Init(sketchshape,TopAbs_FACE); Ex.More(); Ex.Next()) { - // Get outermost wire of sketch face - TopoDS_Face sketchface = TopoDS::Face(Ex.Current()); - TopoDS_Wire outerWire = ShapeAnalysis::OuterWire(sketchface); - if (!checkWireInsideFace(outerWire, upToFace, dir)) { - remove_limits = true; - break; + // Check whether the face has limits or not. Unlimited faces have no wire + // Note: Datum planes are always unlimited + TopExp_Explorer Ex(upToFace,TopAbs_WIRE); + if (Ex.More()) { + // Remove the limits of the upToFace so that the extrusion works even if sketchshape is larger + // than the upToFace + bool remove_limits = false; + for (Ex.Init(sketchshape,TopAbs_FACE); Ex.More(); Ex.Next()) { + // Get outermost wire of sketch face + TopoDS_Face sketchface = TopoDS::Face(Ex.Current()); + TopoDS_Wire outerWire = ShapeAnalysis::OuterWire(sketchface); + if (!checkWireInsideFace(outerWire, upToFace, dir)) { + remove_limits = true; + break; + } } - } - if (remove_limits) { - // Note: Using an unlimited face every time gives unnecessary failures for concave faces - TopLoc_Location loc = upToFace.Location(); - BRepAdaptor_Surface adapt(upToFace, Standard_False); - BRepBuilderAPI_MakeFace mkFace(adapt.Surface().Surface() -#if OCC_VERSION_HEX >= 0x060502 - , Precision::Confusion() -#endif - ); - if (!mkFace.IsDone()) - throw Base::Exception("SketchBased: Up To Face: Failed to create unlimited face"); - upToFace = TopoDS::Face(mkFace.Shape()); - upToFace.Location(loc); + if (remove_limits) { + // Note: Using an unlimited face every time gives unnecessary failures for concave faces + TopLoc_Location loc = upToFace.Location(); + BRepAdaptor_Surface adapt(upToFace, Standard_False); + BRepBuilderAPI_MakeFace mkFace(adapt.Surface().Surface() + #if OCC_VERSION_HEX >= 0x060502 + , Precision::Confusion() + #endif + ); + if (!mkFace.IsDone()) + throw Base::Exception("SketchBased: Up To Face: Failed to create unlimited face"); + upToFace = TopoDS::Face(mkFace.Shape()); + upToFace.Location(loc); + } } // Check that the upToFace does not intersect the sketch face and diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.h b/src/Mod/PartDesign/App/FeatureSketchBased.h index d56b97b0a1..2a86eaa8d1 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.h +++ b/src/Mod/PartDesign/App/FeatureSketchBased.h @@ -46,9 +46,9 @@ public: // Common properties for all sketch based features /// Sketch used to create this feature - App::PropertyLink Sketch; + App::PropertyLink Sketch; /// Reverse extrusion direction - App::PropertyBool Reversed; + App::PropertyBool Reversed; /// Make extrusion symmetric to sketch plane App::PropertyBool Midplane; /// Face to extrude up to @@ -71,8 +71,6 @@ public: std::vector getSketchWires() const; /// Returns the face of the sketch support (if any) const TopoDS_Face getSupportFace() const; - /// Returns the sketch support feature or NULL - Part::Feature* getSupport() const; /// Returns the sketch support shape (if any) const TopoDS_Shape& getSupportShape() const; /// Check whether the sketch support is a datum plane @@ -127,6 +125,9 @@ protected: private: class Wire_Compare; + + /// Returns the sketch support feature or NULL + Part::Feature* getSupport() const; }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp index 60b25bf12c..3b6450afce 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -52,7 +52,7 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c return true; if (pObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { - // Allow selecting Part::Datum features + // Allow selecting Part::Datum features from the active Body if (!ActivePartObject->hasFeature(pObj)) return false; diff --git a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp index 51ff1cfc9f..48b80a001c 100644 --- a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp @@ -103,6 +103,7 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,bool newObj, QWidg bool reversed = pcPad->Reversed.getValue(); Base::Quantity l2 = pcPad->Length2.getQuantityValue(); int index = pcPad->Type.getValue(); // must extract value here, clear() kills it! + App::DocumentObject* obj = pcPad->UpToFace.getValue(); std::vector subStrings = pcPad->UpToFace.getSubValues(); std::string upToFace; int faceId = -1; @@ -128,12 +129,13 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,bool newObj, QWidg // According to bug #0000521 the reversed option // shouldn't be de-activated if the pad has a support face ui->checkBoxReversed->setChecked(reversed); -#if QT_VERSION >= 0x040700 - ui->lineFaceName->setPlaceholderText(tr("No face selected")); -#endif - ui->lineFaceName->setText(faceId >= 0 ? - tr("Face") + QString::number(faceId) : - QString()); + if (PartDesign::Feature::isDatum(obj)) + ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument())); + else if (faceId >= 0) + ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument()) + tr("Face") + + QString::number(faceId)); + else + ui->lineFaceName->setText(tr("No face selected")); ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace.c_str())); ui->changeMode->clear(); ui->changeMode->insertItem(0, tr("Dimension")); @@ -195,7 +197,7 @@ void TaskPadParameters::updateUI(int index) ui->lineFaceName->setEnabled(true); QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection); // Go into reference selection mode if no face has been selected yet - if (ui->lineFaceName->text().isEmpty()) + if (ui->lineFaceName->text().isEmpty() || (ui->lineFaceName->text() == tr("No face selected"))) onButtonFace(true); } else { // two dimensions ui->lengthEdit->setEnabled(true); @@ -332,7 +334,10 @@ int TaskPadParameters::getMode(void) const QByteArray TaskPadParameters::getFaceName(void) const { - return ui->lineFaceName->property("FaceName").toByteArray(); + if ((getMode() >= 1) || (getMode() <= 3)) + return getFaceReference(ui->lineFaceName->text(), ui->lineFaceName->property("FaceName").toString()).toLatin1(); + else + return ""; } const bool TaskPadParameters::updateView() const @@ -363,7 +368,8 @@ void TaskPadParameters::changeEvent(QEvent *e) ui->changeMode->addItem(tr("Two dimensions")); ui->changeMode->setCurrentIndex(index); - QByteArray upToFace = this->getFaceName(); + QStringList parts = ui->lineFaceName->text().split(QChar::fromAscii(':')); + QByteArray upToFace = ui->lineFaceName->property("FaceName").toByteArray(); int faceId = -1; bool ok = false; if (upToFace.indexOf("Face") == 0) { @@ -373,7 +379,7 @@ void TaskPadParameters::changeEvent(QEvent *e) ui->lineFaceName->setPlaceholderText(tr("No face selected")); #endif ui->lineFaceName->setText(ok ? - tr("Face") + QString::number(faceId) : + parts[0] + tr(":Face") + QString::number(faceId) : QString()); ui->lengthEdit->blockSignals(false); ui->lengthEdit2->blockSignals(false); @@ -403,14 +409,9 @@ void TaskPadParameters::apply() Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",cname,getMode()); std::string facename = getFaceName().data(); - PartDesign::Pad* pcPad = static_cast(vp->getObject()); - Part::Feature* support = pcPad->getSupport(); - if (support != NULL && !facename.empty()) { - QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); - buf = buf.arg(QString::fromUtf8(support->getNameInDocument())); - buf = buf.arg(QString::fromStdString(facename)); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", cname, buf.toStdString().c_str()); + if (!facename.empty()) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), facename.c_str()); } else Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", cname); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp index 6c126d077c..a117fc6e5b 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp @@ -96,6 +96,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge bool midplane = pcPocket->Midplane.getValue(); bool reversed = pcPocket->Reversed.getValue(); int index = pcPocket->Type.getValue(); // must extract value here, clear() kills it! + App::DocumentObject* obj = pcPocket->UpToFace.getValue(); std::vector subStrings = pcPocket->UpToFace.getSubValues(); std::string upToFace; int faceId = -1; @@ -111,9 +112,13 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge ui->pocketLength->setValue(l); ui->checkBoxMidplane->setChecked(midplane); ui->checkBoxReversed->setChecked(reversed); - ui->lineFaceName->setText(faceId >= 0 ? - tr("Face") + QString::number(faceId) : - tr("No face selected")); + if (PartDesign::Feature::isDatum(obj)) + ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument())); + else if (faceId >= 0) + ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument()) + tr("Face") + + QString::number(faceId)); + else + ui->lineFaceName->setText(tr("No face selected")); ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace.c_str())); ui->changeMode->clear(); ui->changeMode->insertItem(0, tr("Dimension")); @@ -185,7 +190,7 @@ void TaskPocketParameters::updateUI(int index) ui->lineFaceName->setEnabled(true); QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection); // Go into reference selection mode if no face has been selected yet - if (ui->lineFaceName->text().isEmpty()) + if (ui->lineFaceName->text().isEmpty() || (ui->lineFaceName->text() == tr("No face selected"))) onButtonFace(true); } } @@ -309,7 +314,10 @@ int TaskPocketParameters::getMode(void) const QByteArray TaskPocketParameters::getFaceName(void) const { - return ui->lineFaceName->property("FaceName").toByteArray(); + if ((getMode() >= 1) || (getMode() <= 3)) + return getFaceReference(ui->lineFaceName->text(), ui->lineFaceName->property("FaceName").toString()).toLatin1(); + else + return ""; } const bool TaskPocketParameters::updateView() const @@ -338,14 +346,15 @@ void TaskPocketParameters::changeEvent(QEvent *e) ui->changeMode->addItem(tr("Up to face")); ui->changeMode->setCurrentIndex(index); - QByteArray upToFace = this->getFaceName(); + QStringList parts = ui->lineFaceName->text().split(QChar::fromAscii(':')); + QByteArray upToFace = ui->lineFaceName->property("FaceName").toByteArray(); int faceId = -1; bool ok = false; if (upToFace.indexOf("Face") == 0) { faceId = upToFace.remove(0,4).toInt(&ok); } ui->lineFaceName->setText(ok ? - tr("Face") + QString::number(faceId) : + parts[0] + tr(":Face") + QString::number(faceId) : tr("No face selected")); ui->pocketLength->blockSignals(false); ui->lineFaceName->blockSignals(false); @@ -361,13 +370,9 @@ void TaskPocketParameters::apply() ui->pocketLength->apply(); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),getMode()); std::string facename = getFaceName().data(); - PartDesign::Pocket* pcPocket = static_cast(vp->getObject()); - Part::Feature* support = pcPocket->getSupport(); - if (support != NULL && !facename.empty()) { - QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); - buf = buf.arg(QString::fromUtf8(support->getNameInDocument())); - buf = buf.arg(QString::fromStdString(facename)); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), buf.toStdString().c_str()); + + if (!facename.empty()) { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), facename.c_str()); } else Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i", name.c_str(), getReversed()?1:0); diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 318d2e044e..1a0ca7cfed 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -3085,7 +3085,7 @@ void SketchObject::rebuildExternalGeometry(void) if (Obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { const Part::Datum* datum = static_cast(Obj); - refSubShape = datum->Shape.getValue(); + refSubShape = datum->getShape(); } else if (Obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { try { const Part::Feature *refObj=static_cast(Obj);