allow non-rigid subassemblies
This commit is contained in:
parent
bf8d5e7aa9
commit
e9e1b45280
|
@ -79,7 +79,7 @@ App::DocumentObjectExecReturn *Constraint::execute(void)
|
|||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Geometry3D> Constraint::initLink(ItemAssembly* ass, App::PropertyLinkSub& link) {
|
||||
boost::shared_ptr<Geometry3D> Constraint::initLink(App::PropertyLinkSub& link) {
|
||||
|
||||
//check if we have Assembly::ItemPart
|
||||
if( link.getValue()->getTypeId() != ItemPart::getClassTypeId() ) {
|
||||
|
@ -92,27 +92,16 @@ boost::shared_ptr<Geometry3D> Constraint::initLink(ItemAssembly* ass, App::Prope
|
|||
return boost::shared_ptr<Geometry3D>();
|
||||
|
||||
//get the relevant solver in which the part needs to be added
|
||||
Assembly::ItemAssembly* p_ass = ass->getParentAssembly(part);
|
||||
if(!p_ass)
|
||||
return boost::shared_ptr<Geometry3D>();
|
||||
|
||||
boost::shared_ptr<Solver> solver = p_ass->m_solver;
|
||||
if(!solver)
|
||||
return boost::shared_ptr<Geometry3D>();
|
||||
|
||||
if(!solver->hasPart(part->Uid.getValueStr())) {
|
||||
part->m_part = solver->createPart(part->Placement.getValue(), part->Uid.getValueStr());
|
||||
part->m_part->connectSignal<dcm::recalculated>(boost::bind(&ItemPart::setCalculatedPlacement, part, _1));
|
||||
};
|
||||
part->ensureInitialisation();
|
||||
|
||||
return part->getGeometry3D(link.getSubValues()[0].c_str());
|
||||
}
|
||||
|
||||
|
||||
void Constraint::init(ItemAssembly* ass)
|
||||
void Constraint::init(Assembly::ItemAssembly* ass)
|
||||
{
|
||||
m_first_geom = initLink(ass, First);
|
||||
m_second_geom = initLink(ass, Second);
|
||||
m_first_geom = initLink(First);
|
||||
m_second_geom = initLink(Second);
|
||||
}
|
||||
|
||||
PyObject *Constraint::getPyObject(void)
|
||||
|
|
|
@ -45,7 +45,7 @@ protected:
|
|||
boost::shared_ptr<Constraint3D> m_constraint;
|
||||
boost::shared_ptr<Geometry3D> m_first_geom, m_second_geom;
|
||||
|
||||
boost::shared_ptr< Geometry3D > initLink(Assembly::ItemAssembly* ass, App::PropertyLinkSub& link);
|
||||
boost::shared_ptr< Geometry3D > initLink(App::PropertyLinkSub& link);
|
||||
|
||||
public:
|
||||
Constraint();
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
|
||||
/** @brief initialize the constraint in the assembly solver
|
||||
*/
|
||||
virtual void init(ItemAssembly* ass);
|
||||
virtual void init(Assembly::ItemAssembly* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
|
|
@ -63,7 +63,7 @@ App::DocumentObjectExecReturn *ConstraintAlignment::execute(void)
|
|||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void ConstraintAlignment::init(ItemAssembly* ass) {
|
||||
void ConstraintAlignment::init(Assembly::ItemAssembly* ass) {
|
||||
|
||||
//cant use the base class init as we only need one part
|
||||
Constraint::init(ass);
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
}
|
||||
//@}
|
||||
|
||||
virtual void init(ItemAssembly* ass);
|
||||
virtual void init(Assembly::ItemAssembly* ass);
|
||||
};
|
||||
|
||||
} //namespace PartDesign
|
||||
|
|
|
@ -57,7 +57,7 @@ App::DocumentObjectExecReturn *ConstraintAngle::execute(void)
|
|||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void ConstraintAngle::init(ItemAssembly* ass)
|
||||
void ConstraintAngle::init(Assembly::ItemAssembly* ass)
|
||||
{
|
||||
//init the parts and geometries
|
||||
Constraint::init(ass);
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
}
|
||||
//@}
|
||||
|
||||
virtual void init(ItemAssembly* ass);
|
||||
virtual void init(Assembly::ItemAssembly* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
|
|
@ -63,7 +63,7 @@ App::DocumentObjectExecReturn *ConstraintCoincidence::execute(void)
|
|||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void ConstraintCoincidence::init(ItemAssembly* ass) {
|
||||
void ConstraintCoincidence::init(Assembly::ItemAssembly* ass) {
|
||||
|
||||
//cant use the base class init as we only need one part
|
||||
Constraint::init(ass);
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
}
|
||||
//@}
|
||||
|
||||
virtual void init(ItemAssembly* ass);
|
||||
virtual void init(Assembly::ItemAssembly* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
|
|
@ -70,7 +70,7 @@ App::DocumentObjectExecReturn *ConstraintDistance::execute(void)
|
|||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void ConstraintDistance::init(ItemAssembly* ass)
|
||||
void ConstraintDistance::init(Assembly::ItemAssembly* ass)
|
||||
{
|
||||
//init the parts and geometries
|
||||
Constraint::init(ass);
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
}
|
||||
//@}
|
||||
|
||||
virtual void init(ItemAssembly* ass);
|
||||
virtual void init(Assembly::ItemAssembly* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
|
|
@ -63,10 +63,10 @@ App::DocumentObjectExecReturn* ConstraintFix::execute(void) {
|
|||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void ConstraintFix::init(ItemAssembly* ass) {
|
||||
void ConstraintFix::init(Assembly::ItemAssembly* ass) {
|
||||
|
||||
//cant use the base class init as we only need one part
|
||||
initLink(ass, First);
|
||||
initLink(First);
|
||||
|
||||
//get the part
|
||||
Assembly::ItemPart* part = static_cast<Assembly::ItemPart*>(First.getValue());
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
}
|
||||
//@}
|
||||
|
||||
virtual void init(ItemAssembly* ass);
|
||||
virtual void init(Assembly::ItemAssembly* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
}
|
||||
//@}
|
||||
|
||||
void init(ItemAssembly* ass);
|
||||
void init(Assembly::ItemAssembly* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
|
|
@ -66,7 +66,7 @@ App::DocumentObjectExecReturn* ConstraintOrientation::execute(void) {
|
|||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void ConstraintOrientation::init(ItemAssembly* ass) {
|
||||
void ConstraintOrientation::init(Assembly::ItemAssembly* ass) {
|
||||
//init the parts and geometries
|
||||
Constraint::init(ass);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
}
|
||||
//@}
|
||||
|
||||
virtual void init(ItemAssembly* ass);
|
||||
virtual void init(Assembly::ItemAssembly* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <Base/Exception.h>
|
||||
|
||||
#include "ItemAssembly.h"
|
||||
#include "ItemPart.h"
|
||||
#include "ConstraintGroup.h"
|
||||
#include <ItemAssemblyPy.h>
|
||||
|
||||
|
@ -47,6 +48,7 @@ PROPERTY_SOURCE(Assembly::ItemAssembly, Assembly::Item)
|
|||
ItemAssembly::ItemAssembly() {
|
||||
ADD_PROPERTY(Items,(0));
|
||||
ADD_PROPERTY(Annotations,(0));
|
||||
ADD_PROPERTY(Rigid,(true));
|
||||
}
|
||||
|
||||
short ItemAssembly::mustExecute() const {
|
||||
|
@ -54,35 +56,30 @@ short ItemAssembly::mustExecute() const {
|
|||
}
|
||||
|
||||
App::DocumentObjectExecReturn* ItemAssembly::execute(void) {
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
//create a solver and init all child assemblys with subsolvers
|
||||
m_solver = boost::shared_ptr<Solver>(new Solver);
|
||||
init(boost::shared_ptr<Solver>());
|
||||
|
||||
//get the constraint group and init the constraints
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Annotations.getValues();
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ConstraintGroup::getClassTypeId())
|
||||
static_cast<ConstraintGroup*>(*it)->init(this);
|
||||
};
|
||||
m_downstream_placement = Base::Placement(Base::Vector3<double>(0,0,0), Base::Rotation());
|
||||
Base::Placement dummy;
|
||||
initSolver(boost::shared_ptr<Solver>(), dummy, false);
|
||||
initConstraints(boost::shared_ptr<Solver>());
|
||||
|
||||
//solve the system
|
||||
m_solver->solve();
|
||||
|
||||
//Parts have updated automaticly, however, currently there are no signals
|
||||
//for subsystems. We have to retrieve the product placements therefore by hand
|
||||
finish(boost::shared_ptr<Solver>());
|
||||
|
||||
} catch(dcm::solving_error& e) {
|
||||
|
||||
//Parts have updated automaticly, however, currently there are no signals
|
||||
//for subsystems. We have to retrieve the product placements therefore by hand
|
||||
finish(boost::shared_ptr<Solver>());
|
||||
|
||||
}
|
||||
catch(dcm::solving_error& e) {
|
||||
Base::Console().Error("Solver failed with error %i: %s",
|
||||
*boost::get_error_info<boost::errinfo_errno>(e),
|
||||
boost::get_error_info<dcm::error_message>(e)->c_str());
|
||||
} catch(dcm::creation_error& e) {
|
||||
}
|
||||
catch(dcm::creation_error& e) {
|
||||
Base::Console().Error("Creation failed with error %i: %s",
|
||||
*boost::get_error_info<boost::errinfo_errno>(e),
|
||||
boost::get_error_info<dcm::error_message>(e)->c_str());
|
||||
|
@ -139,7 +136,8 @@ bool ItemAssembly::isParentAssembly(ItemPart* part) {
|
|||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId())
|
||||
if(*it == part) return true;
|
||||
if(*it == part)
|
||||
return true;
|
||||
};
|
||||
|
||||
return false;
|
||||
|
@ -155,12 +153,14 @@ ItemAssembly* ItemAssembly::getParentAssembly(ItemPart* part) {
|
|||
if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId()) {
|
||||
if(*it == part)
|
||||
return this;
|
||||
} else if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
|
||||
Assembly::ItemAssembly* assembly = static_cast<Assembly::ItemAssembly*>(*it)->getParentAssembly(part);
|
||||
if(assembly)
|
||||
return assembly;
|
||||
}
|
||||
else
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
|
||||
Assembly::ItemAssembly* assembly = static_cast<Assembly::ItemAssembly*>(*it)->getParentAssembly(part);
|
||||
if(assembly)
|
||||
return assembly;
|
||||
}
|
||||
};
|
||||
|
||||
return (ItemAssembly*)NULL;
|
||||
|
@ -178,22 +178,32 @@ std::pair<ItemPart*, ItemAssembly*> ItemAssembly::getContainingPart(App::Documen
|
|||
if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId()) {
|
||||
if(static_cast<Assembly::ItemPart*>(*it)->holdsObject(obj))
|
||||
return std::make_pair(static_cast<Assembly::ItemPart*>(*it), this);
|
||||
} else if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
|
||||
std::pair<ItemPart*, ItemAssembly*> part = static_cast<Assembly::ItemAssembly*>(*it)->getContainingPart(obj);
|
||||
if(part.first && part.second)
|
||||
return part;
|
||||
}
|
||||
else
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
|
||||
std::pair<ItemPart*, ItemAssembly*> part = static_cast<Assembly::ItemAssembly*>(*it)->getContainingPart(obj);
|
||||
if(part.first && part.second)
|
||||
return part;
|
||||
}
|
||||
};
|
||||
|
||||
return std::pair<ItemPart*, ItemAssembly*>(NULL, NULL);
|
||||
}
|
||||
|
||||
void ItemAssembly::init(boost::shared_ptr<Solver> parent) {
|
||||
void ItemAssembly::initSolver(boost::shared_ptr<Solver> parent, Base::Placement& PL_downstream, bool stopped) {
|
||||
|
||||
if(parent) {
|
||||
m_solver = boost::shared_ptr<Solver>(parent->createSubsystem());
|
||||
m_solver->setTransformation(this->Placement.getValue());
|
||||
if(Rigid.getValue() || stopped) {
|
||||
m_solver = boost::shared_ptr<Solver>(parent->createSubsystem());
|
||||
m_solver->setTransformation(this->Placement.getValue());
|
||||
stopped = true; //all below belongs to this rigid group
|
||||
}
|
||||
else {
|
||||
m_solver = parent;
|
||||
PL_downstream *= this->Placement.getValue();
|
||||
m_downstream_placement = PL_downstream;
|
||||
}
|
||||
}
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
@ -203,19 +213,45 @@ void ItemAssembly::init(boost::shared_ptr<Solver> parent) {
|
|||
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
|
||||
static_cast<Assembly::ItemAssembly*>(*it)->init(m_solver);
|
||||
static_cast<Assembly::ItemAssembly*>(*it)->initSolver(m_solver, PL_downstream, stopped);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void ItemAssembly::initConstraints(boost::shared_ptr<Solver> parent) {
|
||||
|
||||
|
||||
if(!parent || !Rigid.getValue()) {
|
||||
//get the constraint group and init the constraints
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Annotations.getValues();
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ConstraintGroup::getClassTypeId())
|
||||
static_cast<ConstraintGroup*>(*it)->init(this);
|
||||
};
|
||||
|
||||
// iterate down as long as a non-rigid subsystem exists
|
||||
const std::vector<App::DocumentObject*>& vector2 = Items.getValues();
|
||||
for(iter it=vector2.begin(); it != vector2.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId())
|
||||
static_cast<Assembly::ItemAssembly*>(*it)->initConstraints(m_solver);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//no signals for subsystems, we need to extract the placement by hand
|
||||
void ItemAssembly::finish(boost::shared_ptr<Solver> parent) {
|
||||
|
||||
if(parent) {
|
||||
Base::Placement p = m_solver->getTransformation<Base::Placement>();
|
||||
this->Placement.setValue(p);
|
||||
if(parent && Rigid.getValue()) {
|
||||
Base::Placement p = m_solver->getTransformation<Base::Placement>();
|
||||
this->Placement.setValue(p);
|
||||
}
|
||||
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
@ -226,6 +262,7 @@ void ItemAssembly::finish(boost::shared_ptr<Solver> parent) {
|
|||
static_cast<Assembly::ItemAssembly*>(*it)->finish(m_solver);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,11 +28,12 @@
|
|||
|
||||
#include "Item.h"
|
||||
#include "Solver.h"
|
||||
#include "ItemPart.h"
|
||||
|
||||
namespace Assembly
|
||||
{
|
||||
|
||||
class ItemPart;
|
||||
|
||||
class AssemblyExport ItemAssembly : public Assembly::Item
|
||||
{
|
||||
PROPERTY_HEADER(Assembly::ItemAssembly);
|
||||
|
@ -42,6 +43,7 @@ public:
|
|||
|
||||
App::PropertyLinkList Items;
|
||||
App::PropertyLinkList Annotations;
|
||||
App::PropertyBool Rigid;
|
||||
|
||||
/** @name methods override feature */
|
||||
//@{
|
||||
|
@ -61,10 +63,20 @@ public:
|
|||
ItemAssembly* getParentAssembly(ItemPart* part);
|
||||
|
||||
std::pair< ItemPart*, ItemAssembly* > getContainingPart(App::DocumentObject* obj);
|
||||
void init(boost::shared_ptr<Solver> parent);
|
||||
|
||||
//create a new solver for this assembly and initalise all downstream itemassemblys either with a
|
||||
//subsystem (if they are rigid) or with this solver plus the downstream placement
|
||||
void initSolver(boost::shared_ptr<Solver> parent, Base::Placement& pl_downstream, bool stopped);
|
||||
|
||||
//initialise the oen constraint group and go downstream as long as non-rigid itemassemblys exist,
|
||||
//which need to be initialised too
|
||||
void initConstraints(boost::shared_ptr<Solver> parent);
|
||||
|
||||
//read the downstream itemassemblys and set their placement to the propertyplacement
|
||||
void finish(boost::shared_ptr<Solver> parent);
|
||||
|
||||
boost::shared_ptr<Solver> m_solver;
|
||||
Base::Placement m_downstream_placement;
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <Base/Console.h>
|
||||
|
||||
#include "ItemPart.h"
|
||||
#include "ItemAssembly.h"
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Part/App/BodyBase.h>
|
||||
#include <ItemPartPy.h>
|
||||
|
@ -46,47 +47,47 @@ using namespace Assembly;
|
|||
|
||||
namespace Assembly {
|
||||
|
||||
struct AssemblyItemException : std::exception {
|
||||
const char* what() const throw() { return "Assembly items are in wrong structure";}
|
||||
};
|
||||
|
||||
|
||||
PROPERTY_SOURCE(Assembly::ItemPart, Assembly::Item)
|
||||
|
||||
ItemPart::ItemPart()
|
||||
{
|
||||
ADD_PROPERTY(Model, (0));
|
||||
ItemPart::ItemPart() {
|
||||
ADD_PROPERTY(Model, (0));
|
||||
ADD_PROPERTY(Annotation,(0));
|
||||
}
|
||||
|
||||
short ItemPart::mustExecute() const
|
||||
{
|
||||
short ItemPart::mustExecute() const {
|
||||
//if (Sketch.isTouched() ||
|
||||
// Length.isTouched())
|
||||
// return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *ItemPart::execute(void)
|
||||
{
|
||||
this->touch();
|
||||
return App::DocumentObject::StdReturn;
|
||||
App::DocumentObjectExecReturn* ItemPart::execute(void) {
|
||||
|
||||
this->touch();
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
TopoDS_Shape ItemPart::getShape(void) const
|
||||
{
|
||||
TopoDS_Shape ItemPart::getShape(void) const {
|
||||
App::DocumentObject* obj = Model.getValue();
|
||||
|
||||
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
if(obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
return static_cast<Part::Feature*>(obj)->Shape.getValue();
|
||||
}
|
||||
|
||||
return TopoDS_Shape();
|
||||
}
|
||||
|
||||
PyObject *ItemPart::getPyObject(void)
|
||||
{
|
||||
if (PythonObject.is(Py::_None())){
|
||||
PyObject* ItemPart::getPyObject(void) {
|
||||
if(PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new ItemPartPy(this),true);
|
||||
}
|
||||
return Py::new_reference_to(PythonObject);
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
bool ItemPart::holdsObject(App::DocumentObject* obj) const {
|
||||
|
@ -94,66 +95,114 @@ bool ItemPart::holdsObject(App::DocumentObject* obj) const {
|
|||
//get the body object and the relevant model list
|
||||
Part::BodyBase* base = static_cast<Part::BodyBase*>(Model.getValue());
|
||||
const std::vector<App::DocumentObject*>& vector = base->Model.getValues();
|
||||
|
||||
|
||||
//check if it holds the relevant document object
|
||||
return std::find(vector.begin(), vector.end(), obj)!=vector.end();
|
||||
}
|
||||
|
||||
void ItemPart::setCalculatedPlacement(boost::shared_ptr< Part3D > part) {
|
||||
|
||||
//part is the same as m_part, so it doasn't matter which one we use
|
||||
//part is the same as m_part, so it doasn't matter which one we use
|
||||
Base::Placement p = dcm::get<Base::Placement>(part);
|
||||
Placement.setValue(p);
|
||||
|
||||
ItemAssembly* ass = getParentAssembly();
|
||||
if(!ass)
|
||||
throw AssemblyItemException();
|
||||
|
||||
if(ass->Rigid.getValue())
|
||||
Placement.setValue(p);
|
||||
else
|
||||
Placement.setValue(ass->m_downstream_placement.inverse()*p);
|
||||
}
|
||||
|
||||
ItemAssembly* ItemPart::getParentAssembly() {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = getInList();
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId())
|
||||
return static_cast<Assembly::ItemAssembly*>(*it);
|
||||
};
|
||||
|
||||
return (ItemAssembly*)NULL;
|
||||
}
|
||||
|
||||
void ItemPart::ensureInitialisation() {
|
||||
|
||||
ItemAssembly* ass = getParentAssembly();
|
||||
if(!ass)
|
||||
throw AssemblyItemException();
|
||||
|
||||
boost::shared_ptr<Solver> solver = ass->m_solver;
|
||||
if(!solver)
|
||||
throw AssemblyItemException();
|
||||
|
||||
if(!solver->hasPart(Uid.getValueStr())) {
|
||||
|
||||
//if the assembly is not rigid it was not added to the solver, so we need to incorporate its placement
|
||||
if(ass->Rigid.getValue()) {
|
||||
m_part = solver->createPart(Placement.getValue(), Uid.getValueStr());
|
||||
}
|
||||
else {
|
||||
m_part = solver->createPart(ass->m_downstream_placement*Placement.getValue(), Uid.getValueStr());
|
||||
}
|
||||
m_part->connectSignal<dcm::recalculated>(boost::bind(&ItemPart::setCalculatedPlacement, this, _1));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
boost::shared_ptr< Geometry3D > ItemPart::getGeometry3D(const char* Type)
|
||||
{
|
||||
|
||||
boost::shared_ptr< Geometry3D > ItemPart::getGeometry3D(const char* Type) {
|
||||
|
||||
//check if the item is initialized
|
||||
if(!m_part)
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
|
||||
if(!m_part)
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
|
||||
boost::shared_ptr<Geometry3D> geometry;
|
||||
if(m_part->hasGeometry3D(Type)) {
|
||||
return m_part->getGeometry3D(Type);
|
||||
} else {
|
||||
Part::TopoShape ts;
|
||||
App::DocumentObject* obj = Model.getValue();
|
||||
}
|
||||
else {
|
||||
Part::TopoShape ts;
|
||||
App::DocumentObject* obj = Model.getValue();
|
||||
|
||||
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
ts = static_cast<Part::Feature*>(obj)->Shape.getShape();
|
||||
}
|
||||
else return boost::shared_ptr< Geometry3D >();
|
||||
|
||||
TopoDS_Shape s = ts.getSubShape(Type);
|
||||
if(obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
ts = static_cast<Part::Feature*>(obj)->Shape.getShape();
|
||||
}
|
||||
else
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
|
||||
TopoDS_Shape s = ts.getSubShape(Type);
|
||||
if(s.ShapeType() == TopAbs_FACE) {
|
||||
TopoDS_Face face = TopoDS::Face(s);
|
||||
BRepAdaptor_Surface surface(face);
|
||||
switch(surface.GetType()) {
|
||||
case GeomAbs_Plane: {
|
||||
gp_Pln plane = surface.Plane();
|
||||
if(face.Orientation()==TopAbs_REVERSED) {
|
||||
gp_Dir dir = plane.Axis().Direction();
|
||||
plane = gp_Pln(plane.Location(), dir.Reversed());
|
||||
}
|
||||
geometry = m_part->addGeometry3D(plane, Type, dcm::Local);
|
||||
break;
|
||||
case GeomAbs_Plane: {
|
||||
gp_Pln plane = surface.Plane();
|
||||
if(face.Orientation()==TopAbs_REVERSED) {
|
||||
gp_Dir dir = plane.Axis().Direction();
|
||||
plane = gp_Pln(plane.Location(), dir.Reversed());
|
||||
}
|
||||
case GeomAbs_Cylinder: {
|
||||
gp_Cylinder cyl = surface.Cylinder();
|
||||
geometry = m_part->addGeometry3D(cyl, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Base::Console().Message("Unsuported Surface Geometrie Type at selection\n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
geometry = m_part->addGeometry3D(plane, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
case GeomAbs_Cylinder: {
|
||||
gp_Cylinder cyl = surface.Cylinder();
|
||||
geometry = m_part->addGeometry3D(cyl, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Base::Console().Message("Unsuported Surface Geometrie Type at selection\n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
|
||||
} else if(s.ShapeType() == TopAbs_EDGE) {
|
||||
TopoDS_Edge edge = TopoDS::Edge(s);
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
switch(curve.GetType()) {
|
||||
}
|
||||
else
|
||||
if(s.ShapeType() == TopAbs_EDGE) {
|
||||
TopoDS_Edge edge = TopoDS::Edge(s);
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
switch(curve.GetType()) {
|
||||
case GeomAbs_Line: {
|
||||
gp_Lin line = curve.Line();
|
||||
geometry = m_part->addGeometry3D(line, Type, dcm::Local);
|
||||
|
@ -162,20 +211,23 @@ boost::shared_ptr< Geometry3D > ItemPart::getGeometry3D(const char* Type)
|
|||
default:
|
||||
Base::Console().Message("Unsuported Curve Geometrie Type at selection \n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
if(s.ShapeType() == TopAbs_VERTEX) {
|
||||
TopoDS_Vertex v1 = TopoDS::Vertex(s);
|
||||
gp_Pnt point = BRep_Tool::Pnt(v1);
|
||||
geometry = m_part->addGeometry3D(point, Type, dcm::Local);
|
||||
|
||||
} else if(s.ShapeType() == TopAbs_VERTEX) {
|
||||
TopoDS_Vertex v1 = TopoDS::Vertex(s);
|
||||
gp_Pnt point = BRep_Tool::Pnt(v1);
|
||||
geometry = m_part->addGeometry3D(point, Type, dcm::Local);
|
||||
|
||||
} else {
|
||||
Base::Console().Message("Unsuported Topologie Type at selection\n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Base::Console().Message("Unsuported Topologie Type at selection\n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
namespace Assembly
|
||||
{
|
||||
|
||||
class ItemAssembly;
|
||||
|
||||
class AssemblyExport ItemPart : public Assembly::Item
|
||||
{
|
||||
PROPERTY_HEADER(Assembly::ItemPart);
|
||||
|
@ -57,6 +59,8 @@ public:
|
|||
virtual TopoDS_Shape getShape(void) const;
|
||||
|
||||
bool holdsObject(App::DocumentObject* obj) const;
|
||||
ItemAssembly* getParentAssembly();
|
||||
void ensureInitialisation();
|
||||
|
||||
boost::shared_ptr<Part3D> m_part;
|
||||
virtual boost::shared_ptr<Geometry3D> getGeometry3D(const char* Type );
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "ui_AlignmentDialog.h"
|
||||
|
||||
#include <Mod/Assembly/App/ItemAssembly.h>
|
||||
#include <Mod/Assembly/App/ItemPart.h>
|
||||
#include <Mod/Assembly/App/ConstraintGroup.h>
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "PreCompiled.h"
|
||||
#include "ViewProviderConstraint.h"
|
||||
#include "Mod/Assembly/App/Constraint.h"
|
||||
#include "Mod/Assembly/App/ItemPart.h"
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Base/Console.h>
|
||||
#include <App/Application.h>
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "PreCompiled.h"
|
||||
#include "ViewProviderConstraintFix.h"
|
||||
#include "Mod/Assembly/App/ConstraintFix.h"
|
||||
#include "Mod/Assembly/App/ItemPart.h"
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace AssemblyGui;
|
||||
|
|
Loading…
Reference in New Issue
Block a user