Skip to content

Commit

Permalink
implement ApplyCommand and SetCurrentTool
Browse files Browse the repository at this point in the history
  • Loading branch information
shaise authored and yorikvanhavre committed Oct 31, 2017
1 parent fbbd0ce commit b9362df
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/Mod/Path/PathSimulator/App/CMakeLists.txt
Expand Up @@ -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})

Expand Down
19 changes: 17 additions & 2 deletions src/Mod/Path/PathSimulator/App/PathSim.cpp
Expand Up @@ -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);
}
}


Expand Down
3 changes: 1 addition & 2 deletions src/Mod/Path/PathSimulator/App/PathSim.h
Expand Up @@ -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>
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/Mod/Path/PathSimulator/App/PathSimPy.xml
Expand Up @@ -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>
Expand Down
31 changes: 28 additions & 3 deletions src/Mod/Path/PathSimulator/App/PathSimPyImp.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Path/PathSimulator/App/VolSim.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/Path/PathSimulator/App/VolSim.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -167,7 +169,7 @@ class cStock
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);
}

Expand Down

0 comments on commit b9362df

Please sign in to comment.