diff --git a/src/Mod/Assembly/App/Constraint.cpp b/src/Mod/Assembly/App/Constraint.cpp index 84772447e..0343a39f7 100644 --- a/src/Mod/Assembly/App/Constraint.cpp +++ b/src/Mod/Assembly/App/Constraint.cpp @@ -79,7 +79,7 @@ App::DocumentObjectExecReturn *Constraint::execute(void) return App::DocumentObject::StdReturn; } -boost::shared_ptr Constraint::initLink(ItemAssembly* ass, App::PropertyLinkSub& link) { +boost::shared_ptr Constraint::initLink(App::PropertyLinkSub& link) { //check if we have Assembly::ItemPart if( link.getValue()->getTypeId() != ItemPart::getClassTypeId() ) { @@ -92,27 +92,16 @@ boost::shared_ptr Constraint::initLink(ItemAssembly* ass, App::Prope return boost::shared_ptr(); //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(); - - boost::shared_ptr solver = p_ass->m_solver; - if(!solver) - return boost::shared_ptr(); - - if(!solver->hasPart(part->Uid.getValueStr())) { - part->m_part = solver->createPart(part->Placement.getValue(), part->Uid.getValueStr()); - part->m_part->connectSignal(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) diff --git a/src/Mod/Assembly/App/Constraint.h b/src/Mod/Assembly/App/Constraint.h index 2be02e756..c6d00f23e 100644 --- a/src/Mod/Assembly/App/Constraint.h +++ b/src/Mod/Assembly/App/Constraint.h @@ -45,7 +45,7 @@ protected: boost::shared_ptr m_constraint; boost::shared_ptr 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 diff --git a/src/Mod/Assembly/App/ConstraintAlignment.cpp b/src/Mod/Assembly/App/ConstraintAlignment.cpp index f2ad98cd3..dd08b205f 100644 --- a/src/Mod/Assembly/App/ConstraintAlignment.cpp +++ b/src/Mod/Assembly/App/ConstraintAlignment.cpp @@ -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); diff --git a/src/Mod/Assembly/App/ConstraintAlignment.h b/src/Mod/Assembly/App/ConstraintAlignment.h index 7e5dfc235..b9ba6279b 100644 --- a/src/Mod/Assembly/App/ConstraintAlignment.h +++ b/src/Mod/Assembly/App/ConstraintAlignment.h @@ -52,7 +52,7 @@ public: } //@} - virtual void init(ItemAssembly* ass); + virtual void init(Assembly::ItemAssembly* ass); }; } //namespace PartDesign diff --git a/src/Mod/Assembly/App/ConstraintAngle.cpp b/src/Mod/Assembly/App/ConstraintAngle.cpp index 69fa6479f..f7c19bd3d 100644 --- a/src/Mod/Assembly/App/ConstraintAngle.cpp +++ b/src/Mod/Assembly/App/ConstraintAngle.cpp @@ -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); diff --git a/src/Mod/Assembly/App/ConstraintAngle.h b/src/Mod/Assembly/App/ConstraintAngle.h index 29bce3e25..60ffd110f 100644 --- a/src/Mod/Assembly/App/ConstraintAngle.h +++ b/src/Mod/Assembly/App/ConstraintAngle.h @@ -51,7 +51,7 @@ public: } //@} - virtual void init(ItemAssembly* ass); + virtual void init(Assembly::ItemAssembly* ass); }; } //namespace Assembly diff --git a/src/Mod/Assembly/App/ConstraintCoincidence.cpp b/src/Mod/Assembly/App/ConstraintCoincidence.cpp index f0ec83382..326787e62 100644 --- a/src/Mod/Assembly/App/ConstraintCoincidence.cpp +++ b/src/Mod/Assembly/App/ConstraintCoincidence.cpp @@ -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); diff --git a/src/Mod/Assembly/App/ConstraintCoincidence.h b/src/Mod/Assembly/App/ConstraintCoincidence.h index 180d9bd4f..c20e4a75d 100644 --- a/src/Mod/Assembly/App/ConstraintCoincidence.h +++ b/src/Mod/Assembly/App/ConstraintCoincidence.h @@ -51,7 +51,7 @@ public: } //@} - virtual void init(ItemAssembly* ass); + virtual void init(Assembly::ItemAssembly* ass); }; } //namespace Assembly diff --git a/src/Mod/Assembly/App/ConstraintDistance.cpp b/src/Mod/Assembly/App/ConstraintDistance.cpp index 10ef64745..7d79923b6 100644 --- a/src/Mod/Assembly/App/ConstraintDistance.cpp +++ b/src/Mod/Assembly/App/ConstraintDistance.cpp @@ -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); diff --git a/src/Mod/Assembly/App/ConstraintDistance.h b/src/Mod/Assembly/App/ConstraintDistance.h index e3f3f22fb..549e0e434 100644 --- a/src/Mod/Assembly/App/ConstraintDistance.h +++ b/src/Mod/Assembly/App/ConstraintDistance.h @@ -53,7 +53,7 @@ public: } //@} - virtual void init(ItemAssembly* ass); + virtual void init(Assembly::ItemAssembly* ass); }; } //namespace Assembly diff --git a/src/Mod/Assembly/App/ConstraintFix.cpp b/src/Mod/Assembly/App/ConstraintFix.cpp index 06771fd07..fe05bb32b 100644 --- a/src/Mod/Assembly/App/ConstraintFix.cpp +++ b/src/Mod/Assembly/App/ConstraintFix.cpp @@ -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(First.getValue()); diff --git a/src/Mod/Assembly/App/ConstraintFix.h b/src/Mod/Assembly/App/ConstraintFix.h index 8e2a4c59c..6c0f92564 100644 --- a/src/Mod/Assembly/App/ConstraintFix.h +++ b/src/Mod/Assembly/App/ConstraintFix.h @@ -50,7 +50,7 @@ public: } //@} - virtual void init(ItemAssembly* ass); + virtual void init(Assembly::ItemAssembly* ass); }; } //namespace Assembly diff --git a/src/Mod/Assembly/App/ConstraintGroup.h b/src/Mod/Assembly/App/ConstraintGroup.h index 8c671ab60..efd6c734d 100644 --- a/src/Mod/Assembly/App/ConstraintGroup.h +++ b/src/Mod/Assembly/App/ConstraintGroup.h @@ -57,7 +57,7 @@ public: } //@} - void init(ItemAssembly* ass); + void init(Assembly::ItemAssembly* ass); }; } //namespace Assembly diff --git a/src/Mod/Assembly/App/ConstraintOrientation.cpp b/src/Mod/Assembly/App/ConstraintOrientation.cpp index 56728dbc9..0150a6d8f 100644 --- a/src/Mod/Assembly/App/ConstraintOrientation.cpp +++ b/src/Mod/Assembly/App/ConstraintOrientation.cpp @@ -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); diff --git a/src/Mod/Assembly/App/ConstraintOrientation.h b/src/Mod/Assembly/App/ConstraintOrientation.h index 9c356bca9..14be36897 100644 --- a/src/Mod/Assembly/App/ConstraintOrientation.h +++ b/src/Mod/Assembly/App/ConstraintOrientation.h @@ -51,7 +51,7 @@ public: } //@} - virtual void init(ItemAssembly* ass); + virtual void init(Assembly::ItemAssembly* ass); }; } //namespace Assembly diff --git a/src/Mod/Assembly/App/ItemAssembly.cpp b/src/Mod/Assembly/App/ItemAssembly.cpp index 44e95c995..e7f54efff 100644 --- a/src/Mod/Assembly/App/ItemAssembly.cpp +++ b/src/Mod/Assembly/App/ItemAssembly.cpp @@ -33,6 +33,7 @@ #include #include "ItemAssembly.h" +#include "ItemPart.h" #include "ConstraintGroup.h" #include @@ -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(new Solver); - init(boost::shared_ptr()); - - //get the constraint group and init the constraints - typedef std::vector::const_iterator iter; - - const std::vector& vector = Annotations.getValues(); - for(iter it=vector.begin(); it != vector.end(); it++) { - - if((*it)->getTypeId() == Assembly::ConstraintGroup::getClassTypeId()) - static_cast(*it)->init(this); - }; + m_downstream_placement = Base::Placement(Base::Vector3(0,0,0), Base::Rotation()); + Base::Placement dummy; + initSolver(boost::shared_ptr(), dummy, false); + initConstraints(boost::shared_ptr()); //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()); - - } 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()); + + } + catch(dcm::solving_error& e) { Base::Console().Error("Solver failed with error %i: %s", *boost::get_error_info(e), boost::get_error_info(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(e), boost::get_error_info(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(*it)->getParentAssembly(part); - if(assembly) - return assembly; } + else + if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) { + + Assembly::ItemAssembly* assembly = static_cast(*it)->getParentAssembly(part); + if(assembly) + return assembly; + } }; return (ItemAssembly*)NULL; @@ -178,22 +178,32 @@ std::pair ItemAssembly::getContainingPart(App::Documen if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId()) { if(static_cast(*it)->holdsObject(obj)) return std::make_pair(static_cast(*it), this); - } else if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) { - - std::pair part = static_cast(*it)->getContainingPart(obj); - if(part.first && part.second) - return part; } + else + if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) { + + std::pair part = static_cast(*it)->getContainingPart(obj); + if(part.first && part.second) + return part; + } }; return std::pair(NULL, NULL); } -void ItemAssembly::init(boost::shared_ptr parent) { +void ItemAssembly::initSolver(boost::shared_ptr parent, Base::Placement& PL_downstream, bool stopped) { if(parent) { - m_solver = boost::shared_ptr(parent->createSubsystem()); - m_solver->setTransformation(this->Placement.getValue()); + if(Rigid.getValue() || stopped) { + m_solver = boost::shared_ptr(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::const_iterator iter; @@ -203,19 +213,45 @@ void ItemAssembly::init(boost::shared_ptr parent) { if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) { - static_cast(*it)->init(m_solver); + static_cast(*it)->initSolver(m_solver, PL_downstream, stopped); } }; } +void ItemAssembly::initConstraints(boost::shared_ptr parent) { + + + if(!parent || !Rigid.getValue()) { + //get the constraint group and init the constraints + typedef std::vector::const_iterator iter; + + const std::vector& vector = Annotations.getValues(); + for(iter it=vector.begin(); it != vector.end(); it++) { + + if((*it)->getTypeId() == Assembly::ConstraintGroup::getClassTypeId()) + static_cast(*it)->init(this); + }; + + // iterate down as long as a non-rigid subsystem exists + const std::vector& vector2 = Items.getValues(); + for(iter it=vector2.begin(); it != vector2.end(); it++) { + + if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) + static_cast(*it)->initConstraints(m_solver); + + }; + } +} + //no signals for subsystems, we need to extract the placement by hand void ItemAssembly::finish(boost::shared_ptr parent) { - if(parent) { - Base::Placement p = m_solver->getTransformation(); - this->Placement.setValue(p); + if(parent && Rigid.getValue()) { + Base::Placement p = m_solver->getTransformation(); + this->Placement.setValue(p); } + typedef std::vector::const_iterator iter; const std::vector& vector = Items.getValues(); @@ -226,6 +262,7 @@ void ItemAssembly::finish(boost::shared_ptr parent) { static_cast(*it)->finish(m_solver); } }; + } diff --git a/src/Mod/Assembly/App/ItemAssembly.h b/src/Mod/Assembly/App/ItemAssembly.h index 9a7c2a2cc..37912d0fe 100644 --- a/src/Mod/Assembly/App/ItemAssembly.h +++ b/src/Mod/Assembly/App/ItemAssembly.h @@ -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 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 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 parent); + + //read the downstream itemassemblys and set their placement to the propertyplacement void finish(boost::shared_ptr parent); boost::shared_ptr m_solver; + Base::Placement m_downstream_placement; }; } //namespace Assembly diff --git a/src/Mod/Assembly/App/ItemPart.cpp b/src/Mod/Assembly/App/ItemPart.cpp index f138668e6..ee3a67d3e 100644 --- a/src/Mod/Assembly/App/ItemPart.cpp +++ b/src/Mod/Assembly/App/ItemPart.cpp @@ -29,6 +29,7 @@ #include #include "ItemPart.h" +#include "ItemAssembly.h" #include #include #include @@ -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(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(Model.getValue()); const std::vector& 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(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::const_iterator iter; + + const std::vector& vector = getInList(); + for(iter it=vector.begin(); it != vector.end(); it++) { + + if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) + return static_cast(*it); + }; + + return (ItemAssembly*)NULL; +} + +void ItemPart::ensureInitialisation() { + + ItemAssembly* ass = getParentAssembly(); + if(!ass) + throw AssemblyItemException(); + + boost::shared_ptr 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(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 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(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(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; } -} \ No newline at end of file +} diff --git a/src/Mod/Assembly/App/ItemPart.h b/src/Mod/Assembly/App/ItemPart.h index c19e82740..ac6a3e030 100644 --- a/src/Mod/Assembly/App/ItemPart.h +++ b/src/Mod/Assembly/App/ItemPart.h @@ -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 m_part; virtual boost::shared_ptr getGeometry3D(const char* Type ); diff --git a/src/Mod/Assembly/Gui/CommandConstraints.cpp b/src/Mod/Assembly/Gui/CommandConstraints.cpp index 98653c51c..ead8bd81b 100644 --- a/src/Mod/Assembly/Gui/CommandConstraints.cpp +++ b/src/Mod/Assembly/Gui/CommandConstraints.cpp @@ -35,6 +35,7 @@ #include "ui_AlignmentDialog.h" #include +#include #include diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp index b26e2cc55..b93bda783 100644 --- a/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #include "ViewProviderConstraint.h" #include "Mod/Assembly/App/Constraint.h" +#include "Mod/Assembly/App/ItemPart.h" #include #include #include diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintFix.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraintFix.cpp index 5c673ac9f..5e03f755b 100644 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintFix.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderConstraintFix.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #include "ViewProviderConstraintFix.h" #include "Mod/Assembly/App/ConstraintFix.h" +#include "Mod/Assembly/App/ItemPart.h" #include using namespace AssemblyGui;