Skip to content

Commit

Permalink
PartDesign changes
Browse files Browse the repository at this point in the history
* Mostly for supporting in-place editing

* Add new SubShapeBinder that support cross coordinate system,
  external, and sub-object binding
  • Loading branch information
realthunder committed Jul 14, 2019
1 parent 08180a9 commit 926ea50
Show file tree
Hide file tree
Showing 55 changed files with 1,935 additions and 755 deletions.
1 change: 1 addition & 0 deletions src/Mod/PartDesign/App/AppPartDesign.cpp
Expand Up @@ -117,6 +117,7 @@ PyMOD_INIT_FUNC(_PartDesign)
PartDesign::AdditiveLoft ::init();
PartDesign::SubtractiveLoft ::init();
PartDesign::ShapeBinder ::init();
PartDesign::SubShapeBinder ::init();
PartDesign::Plane ::init();
PartDesign::Line ::init();
PartDesign::Point ::init();
Expand Down
45 changes: 28 additions & 17 deletions src/Mod/PartDesign/App/Body.cpp
Expand Up @@ -116,21 +116,6 @@ short Body::mustExecute() const
return Part::BodyBase::mustExecute();
}

App::DocumentObject* Body::getPrevFeature(App::DocumentObject *start) const
{
std::vector<App::DocumentObject*> features = Group.getValues();
if (features.empty()) return NULL;
App::DocumentObject* st = (start == NULL ? Tip.getValue() : start);
if (st == NULL)
return st; // Tip is NULL

std::vector<App::DocumentObject*>::iterator it = std::find(features.begin(), features.end(), st);
if (it == features.end()) return NULL; // Invalid start object

it--;
return *it;
}

App::DocumentObject* Body::getPrevSolidFeature(App::DocumentObject *start)
{
if (!start) { // default to tip
Expand Down Expand Up @@ -246,7 +231,8 @@ bool Body::isAllowed(const App::DocumentObject* f)
f->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()) ||
// TODO Shouldn't we replace it with Sketcher::SketchObject? (2015-08-13, Fat-Zer)
f->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId()) ||
f->getTypeId().isDerivedFrom(PartDesign::ShapeBinder::getClassTypeId())
f->getTypeId().isDerivedFrom(PartDesign::ShapeBinder::getClassTypeId()) ||
f->getTypeId().isDerivedFrom(PartDesign::SubShapeBinder::getClassTypeId())
// TODO Why this lines was here? why should we allow anything of those? (2015-08-13, Fat-Zer)
//f->getTypeId().isDerivedFrom(Part::FeaturePython::getClassTypeId()) // trouble with this line on Windows!? Linker fails to find getClassTypeId() of the Part::FeaturePython...
//f->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())
Expand Down Expand Up @@ -281,6 +267,17 @@ std::vector<App::DocumentObject*> Body::addObject(App::DocumentObject *feature)
if (isSolidFeature(feature)) {
Tip.setValue (feature);
}

if(feature->Visibility.getValue()
&& feature->isDerivedFrom(PartDesign::Feature::getClassTypeId()))
{
for(auto obj : Group.getValues()) {
if(obj->Visibility.getValue()
&& obj!=feature
&& obj->isDerivedFrom(PartDesign::Feature::getClassTypeId()))
obj->Visibility.setValue(false);
}
}

std::vector<App::DocumentObject*> result = {feature};
return result;
Expand Down Expand Up @@ -330,6 +327,9 @@ void Body::insertObject(App::DocumentObject* feature, App::DocumentObject* targe

Group.setValues (model);

if(feature->isDerivedFrom(PartDesign::Feature::getClassTypeId()))
static_cast<PartDesign::Feature*>(feature)->_Body.setValue(this);

// Set the BaseFeature property
setBaseProperty(feature);
}
Expand Down Expand Up @@ -445,7 +445,9 @@ void Body::onSettingDocument() {

void Body::onChanged (const App::Property* prop) {
// we neither load a project nor perform undo/redo
if (!this->isRestoring() && !this->getDocument()->isPerformingTransaction()) {
if (!this->isRestoring()
&& this->getDocument()
&& !this->getDocument()->isPerformingTransaction()) {
if (prop == &BaseFeature) {
FeatureBase* bf = nullptr;
auto first = Group.getValues().empty() ? nullptr : Group.getValues().front();
Expand Down Expand Up @@ -523,3 +525,12 @@ App::DocumentObject *Body::getSubObject(const char *subname,
*pmat *= Placement.getValue().toMatrix();
return const_cast<Body*>(this);
}

void Body::onDocumentRestored()
{
for(auto obj : Group.getValues()) {
if(obj->isDerivedFrom(PartDesign::Feature::getClassTypeId()))
static_cast<PartDesign::Feature*>(obj)->_Body.setValue(this);
}
DocumentObject::onDocumentRestored();
}
17 changes: 8 additions & 9 deletions src/Mod/PartDesign/App/Body.h
Expand Up @@ -61,9 +61,6 @@ class PartDesignExport Body : public Part::BodyBase
}
//@}

/// Return the previous feature
App::DocumentObject* getPrevFeature(App::DocumentObject *start = NULL) const;

/**
* Add the feature into the body at the current insert point.
* The insertion poin is the before next solid after the Tip feature
Expand Down Expand Up @@ -128,12 +125,6 @@ class PartDesignExport Body : public Part::BodyBase
showTip = enable;
}

protected:
virtual void onSettingDocument() override;

/// Adjusts the first solid's feature's base on BaseFeature getting set
virtual void onChanged (const App::Property* prop) override;

/**
* Return the solid feature before the given feature, or before the Tip feature
* That is, sketches and datum features are skipped
Expand All @@ -146,11 +137,19 @@ class PartDesignExport Body : public Part::BodyBase
*/
App::DocumentObject *getNextSolidFeature(App::DocumentObject* start = NULL);

protected:
virtual void onSettingDocument() override;

/// Adjusts the first solid's feature's base on BaseFeature getting set
virtual void onChanged (const App::Property* prop) override;

/// Creates the corresponding Origin object
virtual void setupObject () override;
/// Removes all planes and axis if they are still linked to the document
virtual void unsetupObject () override;

virtual void onDocumentRestored() override;

private:
boost::signals2::scoped_connection connection;
bool showTip = false;
Expand Down
13 changes: 11 additions & 2 deletions src/Mod/PartDesign/App/Feature.cpp
Expand Up @@ -45,6 +45,7 @@
#include "Mod/Part/App/DatumFeature.h"

#include <Base/Console.h>
FC_LOG_LEVEL_INIT("PartDesign",true,true)


namespace PartDesign {
Expand All @@ -55,6 +56,8 @@ PROPERTY_SOURCE(PartDesign::Feature,Part::Feature)
Feature::Feature()
{
ADD_PROPERTY(BaseFeature,(0));
ADD_PROPERTY_TYPE(_Body,(0),"Base",(App::PropertyType)(
App::Prop_ReadOnly|App::Prop_Hidden|App::Prop_Output|App::Prop_Transient),0);
Placement.setStatus(App::Property::Hidden, true);
BaseFeature.setStatus(App::Property::Hidden, true);
}
Expand Down Expand Up @@ -136,7 +139,9 @@ Part::Feature* Feature::getBaseObject(bool silent) const {
const TopoDS_Shape& Feature::getBaseShape() const {
const Part::Feature* BaseObject = getBaseObject();

if (BaseObject->isDerivedFrom(PartDesign::ShapeBinder::getClassTypeId())) {
if (BaseObject->isDerivedFrom(PartDesign::ShapeBinder::getClassTypeId())||
BaseObject->isDerivedFrom(PartDesign::SubShapeBinder::getClassTypeId()))
{
throw Base::ValueError("Base shape of shape binder cannot be used");
}

Expand Down Expand Up @@ -201,7 +206,11 @@ TopoDS_Shape Feature::makeShapeFromPlane(const App::DocumentObject* obj)
return builder.Shape();
}

Body* Feature::getFeatureBody() {
Body* Feature::getFeatureBody() const {

auto body = Base::freecad_dynamic_cast<Body>(_Body.getValue());
if(body)
return body;

auto list = getInList();
for (auto in : list) {
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/PartDesign/App/Feature.h
Expand Up @@ -35,6 +35,8 @@ class gp_Pln;
namespace PartDesign
{

typedef Part::TopoShape TopoShape;

class Body;

/** PartDesign feature
Expand All @@ -50,14 +52,15 @@ class PartDesignExport Feature : public Part::Feature

/// Base feature which this feature will be fused into or cut out of
App::PropertyLink BaseFeature;
App::PropertyLinkHidden _Body;

short mustExecute() const;

/// Check whether the given feature is a datum feature
static bool isDatum(const App::DocumentObject* feature);

/// Returns the body the feature is in, or none
Body* getFeatureBody();
Body* getFeatureBody() const;

/**
* Returns the BaseFeature property's object (if any)
Expand Down

0 comments on commit 926ea50

Please sign in to comment.