PartDesign: refactor positionBySketch
Rename it to positionByPrevious. Rewrite. Rewrite SketchBased::transformPlacement.
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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<Part::Part2DObject*>(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<Part::Feature*>(support);
|
||||
this->Placement.setValue(part->Placement.getValue());
|
||||
} else if (support->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
|
||||
App::Plane *plane = static_cast<App::Plane*>(support);
|
||||
this->Placement.setValue(plane->Placement.getValue());
|
||||
if(support && support->isDerivedFrom(App::GeoFeature::getClassTypeId())) {
|
||||
this->Placement.setValue(static_cast<App::GeoFeature*>(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<Part::Part2DObject*>(Sketch.getValue());
|
||||
if (sketch && sketch->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
|
||||
Part::Feature *part = static_cast<Part::Feature*>(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<TopoDS_Wire> 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<Part::Feature*>(ref);
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user