diff --git a/src/Mod/Path/PathSimulator/App/PathSim.cpp b/src/Mod/Path/PathSimulator/App/PathSim.cpp index c7e0a7eabc..b979a8eadb 100644 --- a/src/Mod/Path/PathSimulator/App/PathSim.cpp +++ b/src/Mod/Path/PathSimulator/App/PathSim.cpp @@ -59,8 +59,7 @@ PathSim::~PathSim() void PathSim::BeginSimulation(Part::TopoShape * stock, float resolution) { Base::BoundBox3d & bbox = stock->getBoundBox(); - //m_stock = new cStock(bbox.MinX, bbox.MinY, bbox.MinZ, bbox.LengthX(), bbox.LengthY(), bbox.LengthZ(), resolution); - m_stock = new cStock(0,0,0, bbox.LengthX(), bbox.LengthY(), bbox.LengthZ(), resolution); + m_stock = new cStock(bbox.MinX, bbox.MinY, bbox.MinZ, bbox.LengthX(), bbox.LengthY(), bbox.LengthZ(), resolution); } void PathSim::SetCurrentTool(Tool * tool) @@ -79,14 +78,14 @@ void PathSim::SetCurrentTool(Tool * tool) break; } m_tool = new cSimTool(tp, tool->Diameter / 2.0, angle); - Base::Console().Log("Diam %f\n", tool->Diameter); } -void PathSim::ApplyCommand(Base::Placement * pos, Command * cmd) +Base::Placement * PathSim::ApplyCommand(Base::Placement * pos, Command * cmd) { Point3D fromPos(*pos); - Point3D toPos(cmd->getPlacement()); + Point3D toPos(*pos); + toPos.UpdateCmd(*cmd); if (cmd->Name == "G0" || cmd->Name == "G1") { m_stock->ApplyLinearTool(fromPos, toPos, *m_tool); @@ -94,13 +93,17 @@ void PathSim::ApplyCommand(Base::Placement * pos, Command * cmd) else if (cmd->Name == "G2") { Point3D cent(cmd->getCenter()); - m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, true); + m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, false); } else if (cmd->Name == "G3") { Point3D cent(cmd->getCenter()); - m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, false); + m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, true); } + Base::Placement *plc = new Base::Placement(); + Vector3d vec(toPos.x, toPos.y, toPos.z); + plc->setPosition(vec); + return plc; } diff --git a/src/Mod/Path/PathSimulator/App/PathSim.h b/src/Mod/Path/PathSimulator/App/PathSim.h index aeb05e79bc..5ad93dbb99 100644 --- a/src/Mod/Path/PathSimulator/App/PathSim.h +++ b/src/Mod/Path/PathSimulator/App/PathSim.h @@ -52,7 +52,7 @@ namespace PathSimulator void BeginSimulation(Part::TopoShape * stock, float resolution); void SetCurrentTool(Tool * tool); - void ApplyCommand(Base::Placement * pos, Command * cmd); + Base::Placement * ApplyCommand(Base::Placement * pos, Command * cmd); public: cStock * m_stock; diff --git a/src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp b/src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp index ec71e17886..c8da4261e4 100644 --- a/src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp +++ b/src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp @@ -106,9 +106,11 @@ PyObject* PathSimPy::ApplyCommand(PyObject * args, PyObject * kwds) PathSim *sim = getPathSimPtr(); Base::Placement *pos = static_cast(pObjPlace)->getPlacementPtr(); Path::Command *cmd = static_cast(pObjCmd)->getCommandPtr(); - sim->ApplyCommand(pos, cmd); - Py_IncRef(Py_None); - return Py_None; + Base::Placement *newpos = sim->ApplyCommand(pos, cmd); + //Base::Console().Log("Done...\n"); + //Base::Console().Refresh(); + Base::PlacementPy *newposPy = new Base::PlacementPy(newpos); + return newposPy; } /* test script diff --git a/src/Mod/Path/PathSimulator/App/VolSim.cpp b/src/Mod/Path/PathSimulator/App/VolSim.cpp index cbe4175f6d..f885cf88b4 100644 --- a/src/Mod/Path/PathSimulator/App/VolSim.cpp +++ b/src/Mod/Path/PathSimulator/App/VolSim.cpp @@ -152,7 +152,7 @@ float cStock::FindRectTop(int & xp, int & yp, int & x_size, int & y_size, bool s return z; } -int cStock::TesselTop(Mesh::MeshObject & mesh, int xp, int yp) +int cStock::TesselTop(int xp, int yp) { int x_size, y_size; float z = FindRectTop(xp, yp, x_size, y_size, true); @@ -183,7 +183,7 @@ int cStock::TesselTop(Mesh::MeshObject & mesh, int xp, int yp) Point3D pbr(xp + x_size, yp, z); Point3D ptl(xp, yp + y_size, z); Point3D ptr(xp + x_size, yp + y_size, z); - AddQuad(mesh, pbl, pbr, ptr, ptl); + AddQuad(pbl, pbr, ptr, ptl); } if (farRect) @@ -295,7 +295,7 @@ void cStock::FindRectBot(int & xp, int & yp, int & x_size, int & y_size, bool sc } -int cStock::TesselBot(Mesh::MeshObject & mesh, int xp, int yp) +int cStock::TesselBot(int xp, int yp) { int x_size, y_size; FindRectBot(xp, yp, x_size, y_size, true); @@ -324,7 +324,7 @@ int cStock::TesselBot(Mesh::MeshObject & mesh, int xp, int yp) Point3D pbr(xp + x_size, yp, m_pz); Point3D ptl(xp, yp + y_size, m_pz); Point3D ptr(xp + x_size, yp + y_size, m_pz); - AddQuad(mesh, pbl, ptl, ptr, pbr); + AddQuad(pbl, ptl, ptr, pbr); if (farRect) return -1; @@ -333,7 +333,7 @@ int cStock::TesselBot(Mesh::MeshObject & mesh, int xp, int yp) } -int cStock::TesselSidesX(Mesh::MeshObject & mesh, int yp) +int cStock::TesselSidesX(int yp) { float lastz1 = m_pz; if (yp < m_y) @@ -361,7 +361,7 @@ int cStock::TesselSidesX(Mesh::MeshObject & mesh, int yp) Point3D pbr(x, yp, lastz1); Point3D ptl(lastpoint, yp, lastz2); Point3D ptr(x, yp, lastz2); - AddQuad(mesh, pbl, ptl, ptr, pbr); + AddQuad(pbl, ptl, ptr, pbr); } lastz1 = newz1; lastz2 = newz2; @@ -370,7 +370,7 @@ int cStock::TesselSidesX(Mesh::MeshObject & mesh, int yp) return 0; } -int cStock::TesselSidesY(Mesh::MeshObject & mesh, int xp) +int cStock::TesselSidesY(int xp) { float lastz1 = m_pz; if (xp < m_x) @@ -398,7 +398,7 @@ int cStock::TesselSidesY(Mesh::MeshObject & mesh, int xp) Point3D pbl(xp, y, lastz1); Point3D ptr(xp, lastpoint, lastz2); Point3D ptl(xp, y, lastz2); - AddQuad(mesh, pbl, ptl, ptr, pbr); + AddQuad(pbl, ptl, ptr, pbr); } lastz1 = newz1; lastz2 = newz2; @@ -421,24 +421,31 @@ void cStock::SetFacetPoints(MeshCore::MeshGeomFacet & facet, Point3D & p1, Point facet.CalcNormal(); } -void cStock::AddQuad(Mesh::MeshObject & mesh, Point3D & p1, Point3D & p2, Point3D & p3, Point3D & p4) +void cStock::AddQuad(Point3D & p1, Point3D & p2, Point3D & p3, Point3D & p4) { MeshCore::MeshGeomFacet facet; SetFacetPoints(facet, p1, p2, p3); - mesh.addFacet(facet); + facets.push_back(facet); SetFacetPoints(facet, p1, p3, p4); - mesh.addFacet(facet); + facets.push_back(facet); } void cStock::Tesselate(Mesh::MeshObject & mesh) { + // reset attribs + for (int y = 0; y < m_y; y++) + for (int x = 0; x < m_x; x++) + m_attr[x][y] = 0; + + facets.clear(); + for (int y = 0; y < m_y; y++) { for (int x = 0; x < m_x; x++) { int attr = m_attr[x][y]; if ((attr & SIM_TESSEL_TOP) == 0) - x += TesselTop(mesh, x, y); + x += TesselTop(x, y); } } for (int y = 0; y < m_y; y++) @@ -448,13 +455,15 @@ void cStock::Tesselate(Mesh::MeshObject & mesh) if ((m_stock[x][y] - m_pz) < m_res) m_attr[x][y] |= SIM_TESSEL_BOT; if ((m_attr[x][y] & SIM_TESSEL_BOT) == 0) - x += TesselBot(mesh, x, y); + x += TesselBot(x, y); } } for (int y = 0; y <= m_y; y++) - TesselSidesX(mesh, y); + TesselSidesX(y); for (int x = 0; x <= m_x; x++) - TesselSidesY(mesh, x); + TesselSidesY(x); + mesh.addFacets(facets); + facets.clear(); } @@ -673,6 +682,16 @@ void Point3D::SetRotationAngle(float angle) SetRotationAngleRad(angle * 2 * 3.1415926535 / 360); } +void Point3D::UpdateCmd(Path::Command & cmd) +{ + if (cmd.has("X")) + x = cmd.getPlacement().getPosition()[0]; + if (cmd.has("Y")) + y = cmd.getPlacement().getPosition()[1]; + if (cmd.has("Z")) + z = cmd.getPlacement().getPosition()[2]; +} + //************************************************************************************************************ // Simulation tool //************************************************************************************************************ diff --git a/src/Mod/Path/PathSimulator/App/VolSim.h b/src/Mod/Path/PathSimulator/App/VolSim.h index 42cd117fa7..c3ce9e503a 100644 --- a/src/Mod/Path/PathSimulator/App/VolSim.h +++ b/src/Mod/Path/PathSimulator/App/VolSim.h @@ -28,6 +28,7 @@ #include #include +#include #define SIM_EPSILON 0.00001 #define SIM_TESSEL_TOP 1 @@ -42,6 +43,7 @@ struct Point3D inline void set(float px, float py, float pz) { x = px; y = py; z = pz; } inline void Add(Point3D & p) { x += p.x; y += p.y; z += p.z; } inline void Rotate() { float tx = x; x = x * cosa - y * sina; y = tx * sina + y * cosa; } + void UpdateCmd(Path::Command & cmd); void SetRotationAngle(float angle); void SetRotationAngleRad(float angle); float x, y, z; @@ -177,11 +179,11 @@ private: float FindRectTop(int & xp, int & yp, int & x_size, int & y_size, bool scanHoriz); void FindRectBot(int & xp, int & yp, int & x_size, int & y_size, bool scanHoriz); void SetFacetPoints(MeshCore::MeshGeomFacet & facet, Point3D & p1, Point3D & p2, Point3D & p3); - void AddQuad(Mesh::MeshObject & mesh, Point3D & p1, Point3D & p2, Point3D & p3, Point3D & p4); - int TesselTop(Mesh::MeshObject & mesh, int x, int y); - int TesselBot(Mesh::MeshObject & mesh, int x, int y); - int TesselSidesX(Mesh::MeshObject & mesh, int yp); - int TesselSidesY(Mesh::MeshObject & mesh, int xp); + void AddQuad(Point3D & p1, Point3D & p2, Point3D & p3, Point3D & p4); + int TesselTop(int x, int y); + int TesselBot(int x, int y); + int TesselSidesX(int yp); + int TesselSidesY(int xp); Array2D m_stock; Array2D m_attr; float m_px, m_py, m_pz; // stock zero position @@ -189,6 +191,7 @@ private: float m_res; // resoulution float m_plane; // stock plane height int m_x, m_y; // stock array size + std::vector facets; }; class cVolSim