Made the rest of the PartDesign features aware of the Body

This commit is contained in:
jrheinlaender
2013-04-21 09:24:12 +04:30
committed by Stefan Tröger
parent 4bb14de504
commit 7330d4357e
19 changed files with 923 additions and 746 deletions

View File

@@ -64,12 +64,16 @@ short Chamfer::mustExecute() const
App::DocumentObjectExecReturn *Chamfer::execute(void)
{
App::DocumentObject* link = Base.getValue();
// NOTE: Normally the Base property and the BaseFeature property should point to the same object.
// The only difference is that the Base property also stores the edges that are to be chamfered
App::DocumentObject* link = BaseFeature.getValue();
if (!link)
link = Base.getValue(); // For legacy features
if (!link)
return new App::DocumentObjectExecReturn("No object linked");
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
Part::Feature *base = static_cast<Part::Feature*>(link);
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot chamfer invalid shape");
@@ -80,8 +84,8 @@ App::DocumentObjectExecReturn *Chamfer::execute(void)
double size = Size.getValue();
this->positionByBase();
// create an untransformed copy of the base shape
this->positionByBaseFeature();
// create an untransformed copy of the basefeature shape
Part::TopoShape baseShape(TopShape);
baseShape.setTransform(Base::Matrix4D());
try {

View File

@@ -87,12 +87,14 @@ App::DocumentObjectExecReturn *Draft::execute(void)
{
// Get parameters
// Base shape
App::DocumentObject* link = Base.getValue();
App::DocumentObject* link = BaseFeature.getValue();
if (!link)
link = Base.getValue(); // For legacy features
if (!link)
return new App::DocumentObjectExecReturn("No object linked");
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
Part::Feature *base = static_cast<Part::Feature*>(link);
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot draft invalid shape");
@@ -239,7 +241,7 @@ App::DocumentObjectExecReturn *Draft::execute(void)
if (reversed)
angle *= -1.0;
this->positionByBase();
this->positionByBaseFeature();
// create an untransformed copy of the base shape
Part::TopoShape baseShape(TopShape);
baseShape.setTransform(Base::Matrix4D());

View File

@@ -49,18 +49,18 @@ short DressUp::mustExecute() const
}
void DressUp::positionByBase(void)
void DressUp::positionByBaseFeature(void)
{
Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
Part::Feature *base = static_cast<Part::Feature*>(BaseFeature.getValue());
if (base && base->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
this->Placement.setValue(base->Placement.getValue());
}
void DressUp::onChanged(const App::Property* prop)
{
if (prop == &Base) {
if (prop == &BaseFeature) {
// if attached to a sketch then mark it as read-only
this->Placement.setStatus(App::Property::ReadOnly, Base.getValue() != 0);
this->Placement.setStatus(App::Property::ReadOnly, BaseFeature.getValue() != 0);
}
Feature::onChanged(prop);

View File

@@ -0,0 +1,73 @@
/***************************************************************************
* Copyright (c) 2010 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include "FeatureDressUp.h"
using namespace PartDesign;
namespace PartDesign {
PROPERTY_SOURCE(PartDesign::DressUp, PartDesign::Feature)
DressUp::DressUp()
{
ADD_PROPERTY(Base,(0));
}
short DressUp::mustExecute() const
{
if (Base.getValue() && Base.getValue()->isTouched())
return 1;
return PartDesign::Feature::mustExecute();
}
void DressUp::positionByBaseFeature(void)
{
Part::Feature *base = static_cast<Part::Feature*>(BaseFeature.getValue());
if (base && base->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
this->Placement.setValue(base->Placement.getValue());
}
void DressUp::onChanged(const App::Property* prop)
{
if (prop == &BaseFeature) {
// if attached to a sketch then mark it as read-only
<<<<<<< 9a36c6ffa0c7768669f16ea256e11820bfea6b82
this->Placement.setStatus(App::Property::ReadOnly, Base.getValue() != 0);
=======
this->Placement.StatusBits.set(2, BaseFeature.getValue() != 0);
>>>>>>> Made the rest of the PartDesign features aware of the Body
}
Feature::onChanged(prop);
}
}

View File

@@ -40,8 +40,8 @@ public:
App::PropertyLinkSub Base;
short mustExecute() const;
/// updates the Placement property from the Placement of Base
void positionByBase(void);
/// updates the Placement property from the Placement of the BaseFeature
void positionByBaseFeature(void);
protected:
void onChanged(const App::Property* prop);

View File

@@ -61,12 +61,14 @@ short Fillet::mustExecute() const
App::DocumentObjectExecReturn *Fillet::execute(void)
{
App::DocumentObject* link = Base.getValue();
App::DocumentObject* link = BaseFeature.getValue();
if (!link)
link = Base.getValue(); // For legacy features
if (!link)
return new App::DocumentObjectExecReturn("No object linked");
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
Part::Feature *base = static_cast<Part::Feature*>(link);
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot fillet invalid shape");
@@ -77,7 +79,8 @@ App::DocumentObjectExecReturn *Fillet::execute(void)
double radius = Radius.getValue();
this->positionByBase();
this->positionByBaseFeature();
// create an untransformed copy of the base shape
Part::TopoShape baseShape(TopShape);
baseShape.setTransform(Base::Matrix4D());

View File

@@ -72,10 +72,14 @@ void Transformed::positionBySupport(void)
App::DocumentObject* Transformed::getSupportObject() const
{
if (!Originals.getValues().empty())
return Originals.getValues().front();
else
return NULL;
if (BaseFeature.getValue() != NULL)
return BaseFeature.getValue();
else {
if (!Originals.getValues().empty())
return Originals.getValues().front(); // For legacy features
else
return NULL;
}
}
App::DocumentObject* Transformed::getSketchObject() const
@@ -186,10 +190,9 @@ App::DocumentObjectExecReturn *Transformed::execute(void)
return App::DocumentObject::StdReturn; // No transformations defined, exit silently
// Get the support
// NOTE: Because of the way we define the support, FeatureTransformed can only work on
// one Body feature at a time
// TODO: Currently, the support is simply the first Original. Change this to the Body feature later
Part::Feature* supportFeature = static_cast<Part::Feature*>(getSupportObject());
if (supportFeature == NULL)
return new App::DocumentObjectExecReturn("No support for transformation feature");
const Part::TopoShape& supportTopShape = supportFeature->Shape.getShape();
if (supportTopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot transform invalid support shape");