Start of rework of class structure

This commit is contained in:
jriegel
2014-05-04 16:05:13 +02:00
committed by Stefan Tröger
parent 9d25c717b4
commit 35e35527db
38 changed files with 2590 additions and 1853 deletions

View File

@@ -31,8 +31,9 @@
#include <Base/Interpreter.h>
#include "Item.h"
#include "ItemAssembly.h"
#include "ItemPart.h"
#include "Product.h"
#include "ProductRef.h"
#include "PartRef.h"
#include "Constraint.h"
#include "ConstraintGroup.h"
@@ -69,9 +70,10 @@ void AssemblyExport initAssembly()
// This function is responsible for adding inherited slots from a type's base class.
// Item hirachy
Assembly::Item ::init();
Assembly::ItemAssembly ::init();
Assembly::ItemPart ::init();
Assembly::Item ::init();
Assembly::Product ::init();
Assembly::ProductRef ::init();
Assembly::PartRef ::init();
// constraint hirachy
Assembly::Constraint ::init();

View File

@@ -31,18 +31,20 @@ set(Assembly_LIBS
)
generate_from_xml(ItemPy)
generate_from_xml(ItemAssemblyPy)
generate_from_xml(ItemPartPy)
generate_from_xml(ProductRefPy)
generate_from_xml(PartRefPy)
generate_from_xml(ConstraintPy)
generate_from_xml(ConstraintGroupPy)
SET(Features_SRCS
Item.cpp
Item.h
ItemPart.cpp
ItemPart.h
ItemAssembly.cpp
ItemAssembly.h
PartRef.cpp
PartRef.h
Product.cpp
Product.h
ProductRef.cpp
ProductRef.h
Constraint.cpp
Constraint.h
ConstraintGroup.cpp
@@ -80,10 +82,10 @@ SOURCE_GROUP("Solver" FILES ${Solver_SRC})
SET(Python_SRCS
ItemPy.xml
ItemPyImp.cpp
ItemAssemblyPy.xml
ItemAssemblyPyImp.cpp
ItemPartPy.xml
ItemPartPyImp.cpp
ProductRefPy.xml
ProductRefPyImp.cpp
PartRefPy.xml
PartRefPyImp.cpp
ConstraintPy.xml
ConstraintPyImp.cpp
ConstraintGroupPy.xml

View File

@@ -50,8 +50,8 @@
#include "Constraint.h"
#include "ConstraintPy.h"
#include "Item.h"
#include "ItemPart.h"
#include "ItemAssembly.h"
#include "PartRef.h"
#include "Product.h"
using namespace Assembly;
@@ -129,13 +129,13 @@ boost::shared_ptr<Geometry3D> Constraint::initLink(App::PropertyLinkSub& link) {
if(!link.getValue())
return boost::shared_ptr<Geometry3D>();
//check if we have Assembly::ItemPart
if(link.getValue()->getTypeId() != ItemPart::getClassTypeId()) {
//check if we have Assembly::PartRef
if(link.getValue()->getTypeId() != PartRef::getClassTypeId()) {
throw ConstraintLinkException();
return boost::shared_ptr<Geometry3D>();
};
Assembly::ItemPart* part = static_cast<Assembly::ItemPart*>(link.getValue());
Assembly::PartRef* part = static_cast<Assembly::PartRef*>(link.getValue());
if(!part)
throw ConstraintPartException();
@@ -147,18 +147,18 @@ boost::shared_ptr<Geometry3D> Constraint::initLink(App::PropertyLinkSub& link) {
}
void Constraint::init(Assembly::ItemAssembly* ass)
void Constraint::init(Assembly::Product* ass)
{
Assembly::ItemPart* part1, *part2;
Assembly::PartRef* part1, *part2;
if(First.getValue()) {
m_first_geom = initLink(First);
part1 = static_cast<Assembly::ItemPart*>(First.getValue());
part1 = static_cast<Assembly::PartRef*>(First.getValue());
}
if(Second.getValue()) {
m_second_geom = initLink(Second);
part2= static_cast<Assembly::ItemPart*>(Second.getValue());
part2= static_cast<Assembly::PartRef*>(Second.getValue());
}
//fix constraint

View File

@@ -31,7 +31,7 @@
#include <TopoDS_Shape.hxx>
#include "Solver/Solver.h"
#include "ItemAssembly.h"
#include "Product.h"
namespace Assembly
@@ -52,7 +52,7 @@ public:
App::PropertyLinkSub First;
App::PropertyLinkSub Second;
App::PropertyFloat Value;
App::PropertyFloat Value;
App::PropertyEnumeration Orientation;
App::PropertyEnumeration SolutionSpace;
App::PropertyEnumeration Type;
@@ -70,7 +70,7 @@ public:
/** @brief initialize the constraint in the assembly solver
*/
void init(Assembly::ItemAssembly* ass);
void init(Assembly::Product* ass);
};
} //namespace Assembly

View File

@@ -31,8 +31,8 @@
#include "ConstraintGroupPy.h"
#include "ConstraintGroup.h"
#include "ItemPart.h"
#include "ItemAssembly.h"
#include "PartRef.h"
#include "Product.h"
using namespace Assembly;
@@ -72,7 +72,7 @@ App::DocumentObjectExecReturn *ConstraintGroup::execute(void)
return App::DocumentObject::StdReturn;
}
void ConstraintGroup::init(ItemAssembly* ass) {
void ConstraintGroup::init(Product* ass) {
std::vector<App::DocumentObject*> obj = Constraints.getValues();

View File

@@ -57,7 +57,7 @@ public:
}
//@}
void init(Assembly::ItemAssembly* ass);
void init(Assembly::Product* ass);
};
} //namespace Assembly

View File

@@ -1,28 +0,0 @@
#include "PreCompiled.h"
#include "Mod/Assembly/App/ItemAssembly.h"
// inclusion of the generated files (generated out of ItemAssemblyPy.xml)
#include "ItemAssemblyPy.h"
#include "ItemAssemblyPy.cpp"
#include <ItemPartPy.h>
using namespace Assembly;
// returns a string which represents the object e.g. when printed in python
std::string ItemAssemblyPy::representation(void) const
{
return std::string("<ItemAssembly object>");
}
PyObject *ItemAssemblyPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int ItemAssemblyPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -1,34 +0,0 @@
#include "PreCompiled.h"
#include "Mod/Assembly/App/ItemPart.h"
// inclusion of the generated files (generated out of ItemPartPy.xml)
#include "ItemPartPy.h"
#include "ItemPartPy.cpp"
using namespace Assembly;
// returns a string which represents the object e.g. when printed in python
std::string ItemPartPy::representation(void) const
{
return std::string("<ItemPart object>");
}
PyObject *ItemPartPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int ItemPartPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -1,233 +1,233 @@
/***************************************************************************
* Copyright (c) 2012 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 <Base/Placement.h>
#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>
#include <TopoDS.hxx>
#include <GeomAbs_SurfaceType.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Tool.hxx>
#include <GeomAbs_CurveType.hxx>
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));
ADD_PROPERTY(Annotation,(0));
}
short ItemPart::mustExecute() const {
//if (Sketch.isTouched() ||
// Length.isTouched())
// return 1;
return 0;
}
App::DocumentObjectExecReturn* ItemPart::execute(void) {
this->touch();
return App::DocumentObject::StdReturn;
}
TopoDS_Shape ItemPart::getShape(void) const {
App::DocumentObject* obj = Model.getValue();
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())) {
// ref counter is set to 1
PythonObject = Py::Object(new ItemPartPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
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
Base::Placement p = dcm::get<Base::Placement>(part);
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) {
//check if the item is initialized
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();
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_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()) {
case GeomAbs_Line: {
gp_Lin line = curve.Line();
geometry = m_part->addGeometry3D(line, Type, dcm::Local);
break;
}
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 {
Base::Console().Message("Unsuported Topologie Type at selection\n");
return boost::shared_ptr< Geometry3D >();
}
};
return geometry;
}
}
/***************************************************************************
* Copyright (c) 2012 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 <Base/Placement.h>
#include <Base/Console.h>
#include "PartRef.h"
#include "Product.h"
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/BodyBase.h>
#include <PartRefPy.h>
#include <TopoDS.hxx>
#include <GeomAbs_SurfaceType.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Tool.hxx>
#include <GeomAbs_CurveType.hxx>
using namespace Assembly;
namespace Assembly {
struct AssemblyItemException : std::exception {
const char* what() const throw() { return "Assembly items are in wrong structure";}
};
PROPERTY_SOURCE(Assembly::PartRef, Assembly::Item)
PartRef::PartRef() {
ADD_PROPERTY(Model, (0));
ADD_PROPERTY(Annotation,(0));
}
short PartRef::mustExecute() const {
//if (Sketch.isTouched() ||
// Length.isTouched())
// return 1;
return 0;
}
App::DocumentObjectExecReturn* PartRef::execute(void) {
this->touch();
return App::DocumentObject::StdReturn;
}
TopoDS_Shape PartRef::getShape(void) const {
App::DocumentObject* obj = Model.getValue();
if(obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
return static_cast<Part::Feature*>(obj)->Shape.getValue();
}
return TopoDS_Shape();
}
PyObject* PartRef::getPyObject(void) {
if(PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new PartRefPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
bool PartRef::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 PartRef::setCalculatedPlacement(boost::shared_ptr< Part3D > part) {
//part is the same as m_part, so it doasn't matter which one we use
Base::Placement p = dcm::get<Base::Placement>(part);
Product* ass = getParentAssembly();
if(!ass)
throw AssemblyItemException();
if(ass->Rigid.getValue())
Placement.setValue(p);
else
Placement.setValue(ass->m_downstream_placement.inverse()*p);
}
Product* PartRef::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::Product::getClassTypeId())
return static_cast<Assembly::Product*>(*it);
};
return (Product*)NULL;
}
void PartRef::ensureInitialisation() {
Product* 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(&PartRef::setCalculatedPlacement, this, _1));
};
}
boost::shared_ptr< Geometry3D > PartRef::getGeometry3D(const char* Type) {
//check if the item is initialized
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();
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_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()) {
case GeomAbs_Line: {
gp_Lin line = curve.Line();
geometry = m_part->addGeometry3D(line, Type, dcm::Local);
break;
}
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 {
Base::Console().Message("Unsuported Topologie Type at selection\n");
return boost::shared_ptr< Geometry3D >();
}
};
return geometry;
}
}

View File

@@ -1,73 +1,73 @@
/***************************************************************************
* Copyright (c) 2012 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 *
* *
***************************************************************************/
#ifndef Assembly_ItemPart_H
#define Assembly_ItemPart_H
#include <App/PropertyLinks.h>
#include "Item.h"
#include "Solver/Solver.h"
namespace Assembly
{
class ItemAssembly;
class AssemblyExport ItemPart : public Assembly::Item
{
PROPERTY_HEADER(Assembly::ItemPart);
public:
ItemPart();
App::PropertyLink Model;
App::PropertyLinkList Annotation;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
// returns the type name of the view provider
const char* getViewProviderName(void) const {
return "AssemblyGui::ViewProviderItemPart";
}
PyObject *getPyObject(void);
//@}
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 );
void setCalculatedPlacement( boost::shared_ptr<Part3D> part );
};
} //namespace Assembly
#endif // Assembly_ItemPart_H
/***************************************************************************
* Copyright (c) 2012 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 *
* *
***************************************************************************/
#ifndef Assembly_ItemPart_H
#define Assembly_ItemPart_H
#include <App/PropertyLinks.h>
#include "Item.h"
#include "Solver/Solver.h"
namespace Assembly
{
class Product;
class AssemblyExport PartRef : public Assembly::Item
{
PROPERTY_HEADER(Assembly::PartRef);
public:
PartRef();
App::PropertyLink Model;
App::PropertyLinkList Annotation;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
// returns the type name of the view provider
const char* getViewProviderName(void) const {
return "AssemblyGui::ViewProviderItemPart";
}
PyObject *getPyObject(void);
//@}
virtual TopoDS_Shape getShape(void) const;
bool holdsObject(App::DocumentObject* obj) const;
Product* getParentAssembly();
void ensureInitialisation();
boost::shared_ptr<Part3D> m_part;
virtual boost::shared_ptr<Geometry3D> getGeometry3D(const char* Type );
void setCalculatedPlacement( boost::shared_ptr<Part3D> part );
};
} //namespace Assembly
#endif // Assembly_ItemPart_H

View File

@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ItemPy"
Name="ItemPartPy"
Twin="ItemPart"
TwinPointer="ItemPart"
Include="Mod/Assembly/App/ItemPart.h"
Namespace="Assembly"
FatherInclude="Mod/Assembly/App/ItemPy.h"
FatherNamespace="Assembly">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>Base class of all objects in Assembly</UserDocu>
</Documentation>
</PythonExport>
</GenerateModel>
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ItemPy"
Name="PartRefPy"
Twin="PartRef"
TwinPointer="PartRef"
Include="Mod/Assembly/App/PartRef.h"
Namespace="Assembly"
FatherInclude="Mod/Assembly/App/ItemPy.h"
FatherNamespace="Assembly">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>Base class of all objects in Assembly</UserDocu>
</Documentation>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,34 @@
#include "PreCompiled.h"
#include "Mod/Assembly/App/PartRef.h"
// inclusion of the generated files (generated out of PartRefPy.xml)
#include "PartRefPy.h"
#include "PartRefPy.cpp"
using namespace Assembly;
// returns a string which represents the object e.g. when printed in python
std::string PartRefPy::representation(void) const
{
return std::string("<PartRef object>");
}
PyObject *PartRefPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int PartRefPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -1,346 +1,345 @@
/***************************************************************************
* Copyright (c) 2012 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_
# include <BRep_Builder.hxx>
# include <TopoDS_Compound.hxx>
#include <boost/exception/get_error_info.hpp>
#endif
#include <Base/Placement.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include "ItemAssembly.h"
#include "ItemPart.h"
#include "ConstraintGroup.h"
#include <ItemAssemblyPy.h>
using namespace Assembly;
namespace Assembly {
PROPERTY_SOURCE(Assembly::ItemAssembly, Assembly::Item)
ItemAssembly::ItemAssembly() {
ADD_PROPERTY(Items,(0));
ADD_PROPERTY(Annotations,(0));
ADD_PROPERTY(Rigid,(true));
#ifdef ASSEMBLY_DEBUG_FACILITIES
ADD_PROPERTY(ApplyAtFailure,(false));
ADD_PROPERTY(Precision,(1e-6));
ADD_PROPERTY(SaveState,(false));
ADD_PROPERTY(Iterations,(5e3));
ADD_PROPERTY(LogLevel, (long(1)));
std::vector<std::string> vec;
vec.push_back("iteration");
vec.push_back("solving");
vec.push_back("manipulation");
vec.push_back("information");
vec.push_back("error");
LogLevel.setEnumVector(vec);
#endif
}
short ItemAssembly::mustExecute() const {
return 0;
}
App::DocumentObjectExecReturn* ItemAssembly::execute(void) {
Base::Console().Message("Execute\n");
try {
//create a solver and init all child assemblys with subsolvers
m_solver = boost::shared_ptr<Solver>(new Solver);
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>());
#ifdef ASSEMBLY_DEBUG_FACILITIES
if(ApplyAtFailure.getValue())
m_solver->setOption<dcm::solverfailure>(dcm::ApplyResults);
else
m_solver->setOption<dcm::solverfailure>(dcm::IgnoreResults);
m_solver->setOption<dcm::precision>(Precision.getValue());
m_solver->setOption<dcm::iterations>(Iterations.getValue());
if(SaveState.getValue()) {
ofstream myfile;
myfile.open("solverstate.txt");
m_solver->saveState(myfile);
myfile.close();
};
m_solver->setLoggingFilter(dcm::severity >= (dcm::severity_level)LogLevel.getValue());
#endif
//solve the system
m_solver->solve();
}
catch
(boost::exception& e) {
message.clear();
message << "Solver exception " << *boost::get_error_info<boost::errinfo_errno>(e)
<< "raised: " << boost::get_error_info<dcm::error_message>(e)->c_str() << std::endl;
//throw Base::Exception(message.str().c_str());
Base::Console().Error(message.str().c_str());
}
catch
(std::exception& e) {
message.clear();
message << "Exception raised in assembly solver: " << e.what() << std::endl;
//throw Base::Exception(message.str().c_str());
Base::Console().Error(message.str().c_str());
}
catch(Standard_ConstructionError& e) {
message.clear();
message << "Construction Error raised in assembly solver during execution: ";
message << e.GetMessageString()<< std::endl;
Base::Console().Error(message.str().c_str());
}
catch
(...) {
message.clear();
message << "Unknown Exception raised in assembly solver during execution" << std::endl;
//throw Base::Exception(message.str().c_str());
Base::Console().Error(message.str().c_str());
};
this->touch();
return App::DocumentObject::StdReturn;
}
TopoDS_Shape ItemAssembly::getShape(void) const {
std::vector<TopoDS_Shape> s;
std::vector<App::DocumentObject*> obj = Items.getValues();
std::vector<App::DocumentObject*>::iterator it;
for(it = obj.begin(); it != obj.end(); ++it) {
if((*it)->getTypeId().isDerivedFrom(Assembly::Item::getClassTypeId())) {
TopoDS_Shape aShape = static_cast<Assembly::Item*>(*it)->getShape();
if(!aShape.IsNull())
s.push_back(aShape);
}
}
if(s.size() > 0) {
TopoDS_Compound aRes = TopoDS_Compound();
BRep_Builder aBuilder = BRep_Builder();
aBuilder.MakeCompound(aRes);
for(std::vector<TopoDS_Shape>::iterator it = s.begin(); it != s.end(); ++it) {
aBuilder.Add(aRes, *it);
}
//if (aRes.IsNull())
// throw Base::Exception("Resulting shape is invalid");
return aRes;
}
// set empty shape
return TopoDS_Compound();
}
PyObject* ItemAssembly::getPyObject(void) {
if(PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new ItemAssemblyPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
bool ItemAssembly::isParentAssembly(ItemPart* part) {
typedef std::vector<App::DocumentObject*>::const_iterator iter;
const std::vector<App::DocumentObject*>& vector = Items.getValues();
for(iter it=vector.begin(); it != vector.end(); it++) {
if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId())
if(*it == part)
return true;
};
return false;
}
ItemAssembly* ItemAssembly::getToplevelAssembly() {
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)->getToplevelAssembly();
};
return this;
};
ItemAssembly* ItemAssembly::getParentAssembly(ItemPart* part) {
typedef std::vector<App::DocumentObject*>::const_iterator iter;
const std::vector<App::DocumentObject*>& vector = Items.getValues();
for(iter it=vector.begin(); it != vector.end(); it++) {
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;
}
};
return (ItemAssembly*)NULL;
}
std::pair<ItemPart*, ItemAssembly*> ItemAssembly::getContainingPart(App::DocumentObject* obj, bool isTop) {
typedef std::vector<App::DocumentObject*>::const_iterator iter;
const std::vector<App::DocumentObject*>& vector = Items.getValues();
for(iter it=vector.begin(); it != vector.end(); it++) {
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, false);
if(part.first && part.second) {
if(isTop)
return part;
else
return std::make_pair(part.first, this);
}
}
};
return std::pair<ItemPart*, ItemAssembly*>(NULL, NULL);
}
void ItemAssembly::initSolver(boost::shared_ptr<Solver> parent, Base::Placement& PL_downstream, bool stopped) {
if(parent) {
if(Rigid.getValue() || stopped) {
m_solver = parent->createSubsystem();
m_solver->setTransformation(PL_downstream*this->Placement.getValue());
stopped = true; //all below belongs to this rigid group
//connect the recalculated signal in case we need to update the placement
m_solver->connectSignal<dcm::recalculated>(boost::bind(&ItemAssembly::finish, this, _1));
}
else {
m_solver = parent;
PL_downstream *= this->Placement.getValue();
}
}
//we always need to store the downstream placement as we may be a subassembly in a
//non-rigid subassembly
m_downstream_placement = PL_downstream;
typedef std::vector<App::DocumentObject*>::const_iterator iter;
const std::vector<App::DocumentObject*>& vector = Items.getValues();
for(iter it=vector.begin(); it != vector.end(); it++) {
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
static_cast<Assembly::ItemAssembly*>(*it)->initSolver(m_solver, PL_downstream, stopped);
}
};
}
void ItemAssembly::initConstraints(boost::shared_ptr<Solver> parent) {
//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);
};
};
//the callback for the recalculated signal
void ItemAssembly::finish(boost::shared_ptr<Solver> subsystem) {
//assert(subsystem == m_solver);
Base::Placement p = m_solver->getTransformation<Base::Placement>();
this->Placement.setValue(m_downstream_placement.inverse()*p);
};
} //assembly
/***************************************************************************
* Copyright (c) 2012 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_
# include <BRep_Builder.hxx>
# include <TopoDS_Compound.hxx>
#include <boost/exception/get_error_info.hpp>
#endif
#include <Base/Placement.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include "Product.h"
#include "PartRef.h"
#include "ConstraintGroup.h"
using namespace Assembly;
namespace Assembly {
PROPERTY_SOURCE(Assembly::Product, Assembly::Item)
Product::Product() {
ADD_PROPERTY(Items,(0));
ADD_PROPERTY(Annotations,(0));
ADD_PROPERTY(Rigid,(true));
#ifdef ASSEMBLY_DEBUG_FACILITIES
ADD_PROPERTY(ApplyAtFailure,(false));
ADD_PROPERTY(Precision,(1e-6));
ADD_PROPERTY(SaveState,(false));
ADD_PROPERTY(Iterations,(5e3));
ADD_PROPERTY(LogLevel, (long(1)));
std::vector<std::string> vec;
vec.push_back("iteration");
vec.push_back("solving");
vec.push_back("manipulation");
vec.push_back("information");
vec.push_back("error");
LogLevel.setEnumVector(vec);
#endif
}
short Product::mustExecute() const {
return 0;
}
App::DocumentObjectExecReturn* Product::execute(void) {
Base::Console().Message("Execute\n");
try {
//create a solver and init all child assemblys with subsolvers
m_solver = boost::shared_ptr<Solver>(new Solver);
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>());
#ifdef ASSEMBLY_DEBUG_FACILITIES
if(ApplyAtFailure.getValue())
m_solver->setOption<dcm::solverfailure>(dcm::ApplyResults);
else
m_solver->setOption<dcm::solverfailure>(dcm::IgnoreResults);
m_solver->setOption<dcm::precision>(Precision.getValue());
m_solver->setOption<dcm::iterations>(Iterations.getValue());
if(SaveState.getValue()) {
ofstream myfile;
myfile.open("solverstate.txt");
m_solver->saveState(myfile);
myfile.close();
};
m_solver->setLoggingFilter(dcm::severity >= (dcm::severity_level)LogLevel.getValue());
#endif
//solve the system
m_solver->solve();
}
catch
(boost::exception& e) {
message.clear();
message << "Solver exception " << *boost::get_error_info<boost::errinfo_errno>(e)
<< "raised: " << boost::get_error_info<dcm::error_message>(e)->c_str() << std::endl;
//throw Base::Exception(message.str().c_str());
Base::Console().Error(message.str().c_str());
}
catch
(std::exception& e) {
message.clear();
message << "Exception raised in assembly solver: " << e.what() << std::endl;
//throw Base::Exception(message.str().c_str());
Base::Console().Error(message.str().c_str());
}
catch(Standard_ConstructionError& e) {
message.clear();
message << "Construction Error raised in assembly solver during execution: ";
message << e.GetMessageString()<< std::endl;
Base::Console().Error(message.str().c_str());
}
catch
(...) {
message.clear();
message << "Unknown Exception raised in assembly solver during execution" << std::endl;
//throw Base::Exception(message.str().c_str());
Base::Console().Error(message.str().c_str());
};
this->touch();
return App::DocumentObject::StdReturn;
}
TopoDS_Shape Product::getShape(void) const {
std::vector<TopoDS_Shape> s;
std::vector<App::DocumentObject*> obj = Items.getValues();
std::vector<App::DocumentObject*>::iterator it;
for(it = obj.begin(); it != obj.end(); ++it) {
if((*it)->getTypeId().isDerivedFrom(Assembly::Item::getClassTypeId())) {
TopoDS_Shape aShape = static_cast<Assembly::Item*>(*it)->getShape();
if(!aShape.IsNull())
s.push_back(aShape);
}
}
if(s.size() > 0) {
TopoDS_Compound aRes = TopoDS_Compound();
BRep_Builder aBuilder = BRep_Builder();
aBuilder.MakeCompound(aRes);
for(std::vector<TopoDS_Shape>::iterator it = s.begin(); it != s.end(); ++it) {
aBuilder.Add(aRes, *it);
}
//if (aRes.IsNull())
// throw Base::Exception("Resulting shape is invalid");
return aRes;
}
// set empty shape
return TopoDS_Compound();
}
//PyObject* Product::getPyObject(void) {
// if(PythonObject.is(Py::_None())) {
// // ref counter is set to 1
// PythonObject = Py::Object(new ProductPy(this),true);
// }
//
// return Py::new_reference_to(PythonObject);
//}
bool Product::isParentAssembly(PartRef* part) {
typedef std::vector<App::DocumentObject*>::const_iterator iter;
const std::vector<App::DocumentObject*>& vector = Items.getValues();
for(iter it=vector.begin(); it != vector.end(); it++) {
if((*it)->getTypeId() == Assembly::PartRef::getClassTypeId())
if(*it == part)
return true;
};
return false;
}
Product* Product::getToplevelAssembly() {
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::Product::getClassTypeId())
return static_cast<Assembly::Product*>(*it)->getToplevelAssembly();
};
return this;
};
Product* Product::getParentAssembly(PartRef* part) {
typedef std::vector<App::DocumentObject*>::const_iterator iter;
const std::vector<App::DocumentObject*>& vector = Items.getValues();
for(iter it=vector.begin(); it != vector.end(); it++) {
if((*it)->getTypeId() == Assembly::PartRef::getClassTypeId()) {
if(*it == part)
return this;
}
else if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
Assembly::Product* assembly = static_cast<Assembly::Product*>(*it)->getParentAssembly(part);
if(assembly)
return assembly;
}
};
return (Product*)NULL;
}
std::pair<PartRef*, Product*> Product::getContainingPart(App::DocumentObject* obj, bool isTop) {
typedef std::vector<App::DocumentObject*>::const_iterator iter;
const std::vector<App::DocumentObject*>& vector = Items.getValues();
for(iter it=vector.begin(); it != vector.end(); it++) {
if((*it)->getTypeId() == Assembly::PartRef::getClassTypeId()) {
if(static_cast<Assembly::PartRef*>(*it)->holdsObject(obj))
return std::make_pair(static_cast<Assembly::PartRef*>(*it), this);
}
else if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
std::pair<PartRef*, Product*> part = static_cast<Assembly::Product*>(*it)->getContainingPart(obj, false);
if(part.first && part.second) {
if(isTop)
return part;
else
return std::make_pair(part.first, this);
}
}
};
return std::pair<PartRef*, Product*>(NULL, NULL);
}
void Product::initSolver(boost::shared_ptr<Solver> parent, Base::Placement& PL_downstream, bool stopped) {
if(parent) {
if(Rigid.getValue() || stopped) {
m_solver = parent->createSubsystem();
m_solver->setTransformation(PL_downstream*this->Placement.getValue());
stopped = true; //all below belongs to this rigid group
//connect the recalculated signal in case we need to update the placement
m_solver->connectSignal<dcm::recalculated>(boost::bind(&Product::finish, this, _1));
}
else {
m_solver = parent;
PL_downstream *= this->Placement.getValue();
}
}
//we always need to store the downstream placement as we may be a subassembly in a
//non-rigid subassembly
m_downstream_placement = PL_downstream;
typedef std::vector<App::DocumentObject*>::const_iterator iter;
const std::vector<App::DocumentObject*>& vector = Items.getValues();
for(iter it=vector.begin(); it != vector.end(); it++) {
if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
static_cast<Assembly::Product*>(*it)->initSolver(m_solver, PL_downstream, stopped);
}
};
}
void Product::initConstraints(boost::shared_ptr<Solver> parent) {
//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::Product::getClassTypeId())
static_cast<Assembly::Product*>(*it)->initConstraints(m_solver);
};
};
//the callback for the recalculated signal
void Product::finish(boost::shared_ptr<Solver> subsystem) {
//assert(subsystem == m_solver);
Base::Placement p = m_solver->getTransformation<Base::Placement>();
this->Placement.setValue(m_downstream_placement.inverse()*p);
};
} //assembly

View File

@@ -1,102 +1,102 @@
/***************************************************************************
* Copyright (c) 2012 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 *
* *
***************************************************************************/
#ifndef ItemAssembly_ItemAssembly_H
#define ItemAssembly_ItemAssembly_H
#include <App/PropertyStandard.h>
#include "Item.h"
#include "Solver/Solver.h"
namespace Assembly
{
class ItemPart;
class AssemblyExport ItemAssembly : public Assembly::Item
{
PROPERTY_HEADER(Assembly::ItemAssembly);
public:
ItemAssembly();
App::PropertyLinkList Items;
App::PropertyLinkList Annotations;
App::PropertyBool Rigid;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
/// returns the type name of the view provider
const char* getViewProviderName(void) const {
return "AssemblyGui::ViewProviderItemAssembly";
}
PyObject *getPyObject(void);
//@}
virtual TopoDS_Shape getShape(void) const;
bool isParentAssembly(ItemPart* part);
ItemAssembly* getToplevelAssembly();
ItemAssembly* getParentAssembly(ItemPart* part);
//returns the ItemPart which holds the given document object and the ItemAssembly, which holds
//the this part and is a direct children of this ItemAssembly. The returned ItemAssembly is therefore
//the "TopLevel" Assembly holding the part of all children of this assembly. If this assembly holds
//the children directly, without any subassembly, the returned ItemAssembly is this.
std::pair< ItemPart*, ItemAssembly* > getContainingPart(App::DocumentObject* obj, bool isTop=true);
//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> subsystem);
boost::shared_ptr<Solver> m_solver;
Base::Placement m_downstream_placement;
#ifdef ASSEMBLY_DEBUG_FACILITIES
App::PropertyBool ApplyAtFailure;
App::PropertyFloat Precision;
App::PropertyBool SaveState;
App::PropertyInteger Iterations;
App::PropertyEnumeration LogLevel;
#endif
private:
std::stringstream message;
};
} //namespace Assembly
#endif // Assembly_ItemAssembly_H
/***************************************************************************
* Copyright (c) 2012 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 *
* *
***************************************************************************/
#ifndef ItemAssembly_ItemAssembly_H
#define ItemAssembly_ItemAssembly_H
#include <App/PropertyStandard.h>
#include "Item.h"
#include "Solver/Solver.h"
namespace Assembly
{
class PartRef;
class AssemblyExport Product : public Assembly::Item
{
PROPERTY_HEADER(Assembly::Product);
public:
Product();
App::PropertyLinkList Items;
App::PropertyLinkList Annotations;
App::PropertyBool Rigid;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
/// returns the type name of the view provider
const char* getViewProviderName(void) const {
return "AssemblyGui::ViewProviderProduct";
}
//PyObject *getPyObject(void);
//@}
virtual TopoDS_Shape getShape(void) const;
bool isParentAssembly(PartRef* part);
Product* getToplevelAssembly();
Product* getParentAssembly(PartRef* part);
//returns the PartRef which holds the given document object and the Product, which holds
//the this part and is a direct children of this Product. The returned Product is therefore
//the "TopLevel" Assembly holding the part of all children of this assembly. If this assembly holds
//the children directly, without any subassembly, the returned Product is this.
std::pair< PartRef*, Product* > getContainingPart(App::DocumentObject* obj, bool isTop=true);
//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> subsystem);
boost::shared_ptr<Solver> m_solver;
Base::Placement m_downstream_placement;
#ifdef ASSEMBLY_DEBUG_FACILITIES
App::PropertyBool ApplyAtFailure;
App::PropertyFloat Precision;
App::PropertyBool SaveState;
App::PropertyInteger Iterations;
App::PropertyEnumeration LogLevel;
#endif
private:
std::stringstream message;
};
} //namespace Assembly
#endif // Assembly_ItemAssembly_H

View File

@@ -0,0 +1,76 @@
/***************************************************************************
* Copyright (c) 2012 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_
# include <BRep_Builder.hxx>
# include <TopoDS_Compound.hxx>
#include <boost/exception/get_error_info.hpp>
#endif
#include <Base/Placement.h>
#include <Base/Console.h>
#include <App/Part.h>
#include "ProductRef.h"
#include "PartRef.h"
#include "ConstraintGroup.h"
#include "ProductRefPy.h"
using namespace Assembly;
namespace Assembly {
PROPERTY_SOURCE(Assembly::ProductRef, Assembly::Item)
ProductRef::ProductRef() {
ADD_PROPERTY(Items,(0));
ADD_PROPERTY(Annotations,(0));
ADD_PROPERTY(Rigid,(true));
}
short ProductRef::mustExecute() const {
return 0;
}
App::DocumentObjectExecReturn* ProductRef::execute(void)
{
return App::DocumentObject::StdReturn;
}
PyObject* ProductRef::getPyObject(void) {
if(PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new ProductRefPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
} //assembly

View File

@@ -0,0 +1,71 @@
/***************************************************************************
* Copyright (c) 2012 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 *
* *
***************************************************************************/
#ifndef ProductRef_ProductRef_H
#define ProductRef_ProductRef_H
#include <App/PropertyStandard.h>
#include "Item.h"
#include "PartRef.h"
#include "Solver/Solver.h"
namespace Assembly
{
class ItemPart;
class AssemblyExport ProductRef : public Assembly::Item
{
PROPERTY_HEADER(Assembly::ProductRef);
public:
ProductRef();
App::PropertyLinkList Items;
App::PropertyLinkList Annotations;
App::PropertyBool Rigid;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
/// returns the type name of the view provider
const char* getViewProviderName(void) const {
return "AssemblyGui::ViewProviderProductRef";
}
PyObject *getPyObject(void);
//@}
virtual TopoDS_Shape getShape(void) const {return TopoDS_Shape();}
std::pair< PartRef*, Product* > getContainingPart(App::DocumentObject* obj, bool isTop=true){ return std::pair<PartRef*, Product*>(NULL, NULL);}
};
} //namespace Assembly
#endif // Assembly_ProductRef_H

View File

@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ItemPy"
Name="ItemAssemblyPy"
Twin="ItemAssembly"
TwinPointer="ItemAssembly"
Include="Mod/Assembly/App/ItemAssembly.h"
Namespace="Assembly"
FatherInclude="Mod/Assembly/App/ItemPy.h"
FatherNamespace="Assembly">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>Base class of all objects in Assembly</UserDocu>
</Documentation>
</PythonExport>
</GenerateModel>
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ItemPy"
Name="ProductRefPy"
Twin="ProductRef"
TwinPointer="ProductRef"
Include="Mod/Assembly/App/ProductRef.h"
Namespace="Assembly"
FatherInclude="Mod/Assembly/App/ItemPy.h"
FatherNamespace="Assembly">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>Base class of all objects in Assembly</UserDocu>
</Documentation>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,28 @@
#include "PreCompiled.h"
#include "Mod/Assembly/App/ProductRef.h"
// inclusion of the generated files (generated out of ProductPy.xml)
#include "ProductRefPy.h"
#include "ProductRefPy.cpp"
#include <PartRefPy.h>
using namespace Assembly;
// returns a string which represents the object e.g. when printed in python
std::string ProductRefPy::representation(void) const
{
return std::string("<ProductRef object>");
}
PyObject *ProductRefPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int ProductRefPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}