basic infrastructure

This commit is contained in:
Stefan Tröger
2013-04-25 11:58:21 +02:00
committed by Stefan Tröger
parent 395557b096
commit d50f7f1787
42 changed files with 488 additions and 3460 deletions

View File

@@ -26,9 +26,20 @@
#endif
#include <Base/Placement.h>
#include <Base/Console.h>
#include "ItemPart.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;
@@ -54,6 +65,8 @@ short ItemPart::mustExecute() const
App::DocumentObjectExecReturn *ItemPart::execute(void)
{
Base::Console().Message("Recalculate ItemPart\n");
this->touch();
return App::DocumentObject::StdReturn;
}
@@ -66,7 +79,109 @@ TopoDS_Shape ItemPart::getShape(void) const
}
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::Console().Message("Set new calculated part placement\n");
Base::Placement p = dcm::get<Base::Placement>(part);
Placement.setValue(p);
}
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);
//Base::Console().Message("Already has geometry, nothing added\n");
} 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);
//Base::Console().Message("Fase selected\n");
switch(surface.GetType()) {
case GeomAbs_Plane: {
//Base::Console().Message("plane selected\n");
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::Global);
break;
}
case GeomAbs_Cylinder: {
//Base::Console().Message("cylinder selected\n");
gp_Cylinder cyl = surface.Cylinder();
geometry = m_part->addGeometry3D(cyl, Type, dcm::Global);
break;
}
default:
Base::Console().Message("Unsuported Surface Geometrie Type at selection 1\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::Global);
break;
}
default:
//Base::Console().Message("Unsuported Curve Geometrie Type at selection 1\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::Global);
} else {
Base::Console().Message("Unsuported Topologie Type at selection 1\n");
return boost::shared_ptr< Geometry3D >();
}
};
return geometry;
}
}