implement ApplyCommand and SetCurrentTool
This commit is contained in:
committed by
Yorik van Havre
parent
fbbd0ce35b
commit
b9362df315
@@ -37,6 +37,8 @@ SET(PathSimulator_SRCS
|
||||
|
||||
generate_from_xml(PathSimPy)
|
||||
|
||||
SOURCE_GROUP("Python" FILES ${Python_SRCS})
|
||||
|
||||
add_library(PathSimulator SHARED ${PathSimulator_SRCS})
|
||||
target_link_libraries(PathSimulator ${PathSimulator_LIBS})
|
||||
|
||||
|
||||
@@ -80,9 +80,24 @@ void PathSim::SetCurrentTool(Tool * tool)
|
||||
}
|
||||
|
||||
|
||||
void PathSim::ApplyCommand(Command * cmd)
|
||||
void PathSim::ApplyCommand(Base::Placement * pos, Command * cmd)
|
||||
{
|
||||
|
||||
Point3D fromPos(*pos);
|
||||
Point3D toPos(cmd->getPlacement());
|
||||
if (cmd->Name == "G0" || cmd->Name == "G1")
|
||||
{
|
||||
m_stock->ApplyLinearTool(fromPos, toPos, *m_tool);
|
||||
}
|
||||
else if (cmd->Name == "G2")
|
||||
{
|
||||
Point3D cent(cmd->getCenter());
|
||||
m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, true);
|
||||
}
|
||||
else if (cmd->Name == "G3")
|
||||
{
|
||||
Point3D cent(cmd->getCenter());
|
||||
m_stock->ApplyCircularTool(fromPos, toPos, cent, *m_tool, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <Base/Vector3D.h>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <Mod/Path/App/PreCompiled.h>
|
||||
#include <Mod/Path/App/Command.h>
|
||||
#include <Mod/Path/App/Tooltable.h>
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
@@ -53,7 +52,7 @@ namespace PathSimulator
|
||||
|
||||
void BeginSimulation(Part::TopoShape * stock, float resolution);
|
||||
void SetCurrentTool(Tool * tool);
|
||||
void ApplyCommand(Command * cmd);
|
||||
void ApplyCommand(Base::Placement * pos, Command * cmd);
|
||||
|
||||
public:
|
||||
cStock * m_stock;
|
||||
|
||||
@@ -39,6 +39,14 @@ Start a simulation process on a box shape stock with given resolution\n</UserDoc
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="ApplyCommand" Keyword='true'>
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
ApplyCommand(placement, command):\n
|
||||
Apply a single path command on the stock starting from placement.\n
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="Tool" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>Return current simulation tool.</UserDocu>
|
||||
|
||||
@@ -23,7 +23,11 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "Mod/Path/PathSimulator/App/PathSim.h"
|
||||
#include <Base/PlacementPy.h>
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Mod/Part/App/TopoShapePy.h>
|
||||
#include <Mod/Path/App/ToolPy.h>
|
||||
#include <Mod/Path/App/CommandPy.h>
|
||||
#include <Mod/Mesh/App/MeshPy.h>
|
||||
|
||||
// inclusion of the generated files (generated out of PathSimPy.xml)
|
||||
@@ -65,10 +69,15 @@ PyObject* PathSimPy::BeginSimulation(PyObject * args, PyObject * kwds)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* PathSimPy::SetCurrentTool(PyObject * /*args*/)
|
||||
PyObject* PathSimPy::SetCurrentTool(PyObject * args)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
|
||||
return 0;
|
||||
PyObject *pObjTool;
|
||||
if (!PyArg_ParseTuple(args, "O!", &(Path::ToolPy::Type), &pObjTool))
|
||||
return 0;
|
||||
PathSim *sim = getPathSimPtr();
|
||||
sim->SetCurrentTool(static_cast<Path::ToolPy*>(pObjTool)->getToolPtr());
|
||||
Py_IncRef(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject* PathSimPy::GetResultMesh(PyObject * args)
|
||||
@@ -83,6 +92,22 @@ PyObject* PathSimPy::GetResultMesh(PyObject * args)
|
||||
return meshpy;
|
||||
}
|
||||
|
||||
|
||||
PyObject* PathSimPy::ApplyCommand(PyObject * args, PyObject * kwds)
|
||||
{
|
||||
static char *kwlist[] = { "position", "command", NULL };
|
||||
PyObject *pObjPlace;
|
||||
PyObject *pObjCmd;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", kwlist, &(Base::PlacementPy::Type), &pObjPlace, &(Path::CommandPy::Type), &pObjCmd))
|
||||
return 0;
|
||||
PathSim *sim = getPathSimPtr();
|
||||
Base::Placement *pos = static_cast<Base::PlacementPy*>(pObjPlace)->getPlacementPtr();
|
||||
Path::Command *cmd = static_cast<Path::CommandPy*>(pObjCmd)->getCommandPtr();
|
||||
sim->ApplyCommand(pos, cmd);
|
||||
Py_IncRef(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/* test script
|
||||
import PathSimulator
|
||||
sim = PathSimulator.PathSim()
|
||||
|
||||
@@ -527,7 +527,7 @@ void cStock::ApplyLinearTool(Point3D & p1, Point3D & p2, cSimTool & tool)
|
||||
cupAngle = 360;
|
||||
|
||||
// end cup
|
||||
for (float r = 0.5; r <= rad; r += SIM_WALK_RES)
|
||||
for (float r = 0.5f; r <= rad; r += (float)SIM_WALK_RES)
|
||||
{
|
||||
Point3D cupCirc(perpDirX * r, perpDirY * r, pi2.z);
|
||||
float rotang = 180 * SIM_WALK_RES / (3.1415926535 * r);
|
||||
@@ -583,7 +583,7 @@ void cStock::ApplyCircularTool(Point3D & p1, Point3D & p2, Point3D & cent, cSimT
|
||||
Point3D cupCirc;
|
||||
float tstep = (float)SIM_WALK_RES / rad;
|
||||
float t = -1;
|
||||
for (float r = crad1; r <= crad2; r += SIM_WALK_RES)
|
||||
for (float r = crad1; r <= crad2; r += (float)SIM_WALK_RES)
|
||||
{
|
||||
cupCirc.x = xynorm.x * r;
|
||||
cupCirc.y = xynorm.y * r;
|
||||
@@ -612,7 +612,7 @@ void cStock::ApplyCircularTool(Point3D & p1, Point3D & p2, Point3D & cent, cSimT
|
||||
// apply end cup
|
||||
xynorm.SetRotationAngleRad(ang);
|
||||
xynorm.Rotate();
|
||||
for (float r = 0.5; r <= rad; r += SIM_WALK_RES)
|
||||
for (float r = 0.5f; r <= rad; r += (float)SIM_WALK_RES)
|
||||
{
|
||||
Point3D cupCirc(xynorm.x * r, xynorm.y * r, 0);
|
||||
float rotang = (float)SIM_WALK_RES / r;
|
||||
|
||||
@@ -37,6 +37,8 @@ struct Point3D
|
||||
{
|
||||
Point3D() {}
|
||||
Point3D(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||
Point3D(Base::Vector3d & vec) : x(vec[0]), y(vec[1]), z(vec[2]) {}
|
||||
Point3D(Base::Placement & pl) : x(pl.getPosition()[0]), y(pl.getPosition()[1]), z(pl.getPosition()[2]) {}
|
||||
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; }
|
||||
@@ -167,7 +169,7 @@ public:
|
||||
void CreatePocket(float x, float y, float rad, float height);
|
||||
void ApplyLinearTool(Point3D & p1, Point3D & p2, cSimTool &tool);
|
||||
void ApplyCircularTool(Point3D & p1, Point3D & p2, Point3D & cent, cSimTool &tool, bool isCCW);
|
||||
inline Point3D & ToInner(Point3D & p) {
|
||||
inline Point3D ToInner(Point3D & p) {
|
||||
return Point3D((p.x - m_px) / m_res, (p.y - m_py) / m_res, p.z);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user