From 4b48362ec668a60dc2fc23b4846310699d40c503 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Tue, 30 Jun 2015 21:13:19 +0300 Subject: [PATCH] PartDesign: refactor positionBySketch Rename it to positionByPrevious. Rewrite. Rewrite SketchBased::transformPlacement. --- src/App/GeoFeature.h | 7 ++++ src/Mod/PartDesign/App/FeatureGroove.cpp | 2 +- src/Mod/PartDesign/App/FeatureLoft.cpp | 4 +- src/Mod/PartDesign/App/FeaturePad.cpp | 2 +- src/Mod/PartDesign/App/FeaturePipe.cpp | 2 +- src/Mod/PartDesign/App/FeaturePocket.cpp | 2 +- src/Mod/PartDesign/App/FeatureRevolution.cpp | 2 +- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 40 +++++++++---------- src/Mod/PartDesign/App/FeatureSketchBased.h | 10 +++-- 9 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/App/GeoFeature.h b/src/App/GeoFeature.h index 6a886c5b3a..f022ef63a2 100644 --- a/src/App/GeoFeature.h +++ b/src/App/GeoFeature.h @@ -46,6 +46,13 @@ public: GeoFeature(void); virtual ~GeoFeature(); + /** + * @brief transformPlacement applies transform to placement of this shape. + * Override this function to propagate the change of placement to base + * features, for example. By the time of writing this comment, the function + * was only called by alignment task (Edit->Alignment) + * @param transform (input). + */ virtual void transformPlacement(const Base::Placement &transform); }; diff --git a/src/Mod/PartDesign/App/FeatureGroove.cpp b/src/Mod/PartDesign/App/FeatureGroove.cpp index b363a056bc..575af788f0 100644 --- a/src/Mod/PartDesign/App/FeatureGroove.cpp +++ b/src/Mod/PartDesign/App/FeatureGroove.cpp @@ -122,7 +122,7 @@ App::DocumentObjectExecReturn *Groove::execute(void) sketchshape.Move(loc); } - this->positionBySketch(); + this->positionByPrevious(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); pnt.Transform(invObjLoc.Transformation()); dir.Transform(invObjLoc.Transformation()); diff --git a/src/Mod/PartDesign/App/FeatureLoft.cpp b/src/Mod/PartDesign/App/FeatureLoft.cpp index b856ccf04f..4900c3f8bb 100644 --- a/src/Mod/PartDesign/App/FeatureLoft.cpp +++ b/src/Mod/PartDesign/App/FeatureLoft.cpp @@ -97,7 +97,7 @@ App::DocumentObjectExecReturn *Loft::execute(void) try { //setup the location - this->positionBySketch(); + this->positionByPrevious(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); if(!base.IsNull()) base.Move(invObjLoc); @@ -235,4 +235,4 @@ AdditiveLoft::AdditiveLoft() { PROPERTY_SOURCE(PartDesign::SubtractiveLoft, PartDesign::Loft) SubtractiveLoft::SubtractiveLoft() { addSubType = Subtractive; -} \ No newline at end of file +} diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index 3c360b5f5d..74fde500d2 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -141,7 +141,7 @@ App::DocumentObjectExecReturn *Pad::execute(void) SketchOrientation.multVec(SketchVector,SketchVector); try { - this->positionBySketch(); + this->positionByPrevious(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); base.Move(invObjLoc); diff --git a/src/Mod/PartDesign/App/FeaturePipe.cpp b/src/Mod/PartDesign/App/FeaturePipe.cpp index defe5a0279..55f111cb2b 100644 --- a/src/Mod/PartDesign/App/FeaturePipe.cpp +++ b/src/Mod/PartDesign/App/FeaturePipe.cpp @@ -136,7 +136,7 @@ App::DocumentObjectExecReturn *Pipe::execute(void) try { //setup the location - this->positionBySketch(); + this->positionByPrevious(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); if(!base.IsNull()) base.Move(invObjLoc); diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index ad2ce488ef..f0317e815e 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -117,7 +117,7 @@ App::DocumentObjectExecReturn *Pocket::execute(void) SketchVector *= -1; try { - this->positionBySketch(); + this->positionByPrevious(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); base.Move(invObjLoc); diff --git a/src/Mod/PartDesign/App/FeatureRevolution.cpp b/src/Mod/PartDesign/App/FeatureRevolution.cpp index 8ff5d93646..2b4107f717 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.cpp +++ b/src/Mod/PartDesign/App/FeatureRevolution.cpp @@ -124,7 +124,7 @@ App::DocumentObjectExecReturn *Revolution::execute(void) sketchshape.Move(loc); } - this->positionBySketch(); + this->positionByPrevious(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); pnt.Transform(invObjLoc.Transformation()); dir.Transform(invObjLoc.Transformation()); diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index dc11f13a34..1fc4af3fbb 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -121,36 +121,34 @@ short SketchBased::mustExecute() const return PartDesign::FeatureAddSub::mustExecute(); } -void SketchBased::positionBySketch(void) +void SketchBased::positionByPrevious(void) { - Part::Part2DObject *sketch = static_cast(Sketch.getValue()); - if (sketch && sketch->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) { + try{ + //use placement of base + Part::Feature* feat = getBaseObject(); + this->Placement.setValue(feat->Placement.getValue()); + } catch (Base::Exception) { + //no base. Use either Sketch support's placement, or sketch's placement itself. + Part::Part2DObject *sketch = getVerifiedSketch(); App::DocumentObject* support = sketch->Support.getValue(); - if (support == NULL) - throw Base::Exception("Sketch with NULL support"); - if (support->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { - Part::Feature *part = static_cast(support); - this->Placement.setValue(part->Placement.getValue()); - } else if (support->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { - App::Plane *plane = static_cast(support); - this->Placement.setValue(plane->Placement.getValue()); + if(support && support->isDerivedFrom(App::GeoFeature::getClassTypeId())) { + this->Placement.setValue(static_cast(support)->Placement.getValue()); } else { - this->Placement.setValue(sketch->Placement.getValue()); + this->Placement.setValue( sketch->Placement.getValue() ); } } } void SketchBased::transformPlacement(const Base::Placement &transform) { - Part::Part2DObject *sketch = static_cast(Sketch.getValue()); - if (sketch && sketch->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) { - Part::Feature *part = static_cast(sketch->Support.getValue()); - if (part && part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) - part->transformPlacement(transform); - else - sketch->transformPlacement(transform); - positionBySketch(); + try{ + Part::Feature* feat = getBaseObject(); + feat->transformPlacement(transform); + } catch (Base::Exception) { + Part::Part2DObject *sketch = getVerifiedSketch(); + sketch->transformPlacement(transform); } + positionByPrevious(); } Part::Part2DObject* SketchBased::getVerifiedSketch() const { @@ -194,7 +192,7 @@ std::vector SketchBased::getSketchWires() const { const TopoDS_Face SketchBased::getSupportFace() const { const Part::Part2DObject* sketch = getVerifiedSketch(); if (sketch->Support.getValue()) { - const App::PropertyLinkSubList& Support = sketch->Support; + const auto &Support = sketch->Support; App::DocumentObject* ref = Support.getValue(); Part::Feature *part = static_cast(ref); diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.h b/src/Mod/PartDesign/App/FeatureSketchBased.h index f3c9780091..4f43d63c1e 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.h +++ b/src/Mod/PartDesign/App/FeatureSketchBased.h @@ -56,10 +56,12 @@ public: short mustExecute() const; - /** calculates and updates the Placement property based on the Sketch - * or its support if it has one - */ - void positionBySketch(void); + /** calculates and updates the Placement property based on the features + * this one is made from: either from Base, if there is one, or from sketch, + * if there is no base. + */ + void positionByPrevious(void); + /** applies a transform on the Placement of the Sketch or its * support if it has one */