Skip to content

Commit

Permalink
Merge pull request #2457 from dubstar-04/feature/tooltable
Browse files Browse the repository at this point in the history
[Path] Manage multiple tool tables
  • Loading branch information
sliptonic committed Aug 29, 2019
2 parents d54bff6 + a6a7e04 commit 174f13e
Show file tree
Hide file tree
Showing 13 changed files with 1,265 additions and 734 deletions.
1 change: 1 addition & 0 deletions src/Mod/Path/App/AppPath.cpp
Expand Up @@ -34,6 +34,7 @@
#include "CommandPy.h"
#include "Path.h"
#include "PathPy.h"
#include "Tool.h"
#include "Tooltable.h"
#include "ToolPy.h"
#include "TooltablePy.h"
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Path/App/CMakeLists.txt
Expand Up @@ -43,6 +43,7 @@ SET(Python_SRCS
PathPy.xml
PathPyImp.cpp
ToolPy.xml
ToolPyImp.cpp
TooltablePy.xml
TooltablePyImp.cpp
FeaturePathCompoundPy.xml
Expand All @@ -65,6 +66,8 @@ SET(Path_SRCS
Command.h
Path.cpp
Path.h
Tool.cpp
Tool.h
Tooltable.cpp
Tooltable.h
PropertyPath.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/App/PropertyTool.h
Expand Up @@ -24,7 +24,7 @@
#ifndef PROPERTYTOOL_H
#define PROPERTYTOOL_H

#include "Tooltable.h"
#include "Tool.h"
#include <App/Property.h>

namespace Path
Expand Down
258 changes: 258 additions & 0 deletions src/Mod/Path/App/Tool.cpp
@@ -0,0 +1,258 @@
/***************************************************************************
* Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 *
* *
* 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/Writer.h>
#include <Base/Reader.h>
#include <Base/Exception.h>
#include "Tool.h"

using namespace Base;
using namespace Path;

TYPESYSTEM_SOURCE(Path::Tool , Base::Persistence);

// Constructors & destructors

Tool::Tool(const char* name,
ToolType type,
ToolMaterial /*material*/,
double diameter,
double lengthoffset,
double flatradius,
double cornerradius,
double cuttingedgeangle,
double cuttingedgeheight)
:Name(name),Type(type),Material(MATUNDEFINED),Diameter(diameter),LengthOffset(lengthoffset),
FlatRadius(flatradius),CornerRadius(cornerradius),CuttingEdgeAngle(cuttingedgeangle),
CuttingEdgeHeight(cuttingedgeheight)
{
}

Tool::Tool()
{
Type = UNDEFINED;
Material = MATUNDEFINED;
Diameter = 0;
LengthOffset = 0;
FlatRadius = 0;
CornerRadius = 0;
CuttingEdgeAngle = 180;
CuttingEdgeHeight = 0;
}

Tool::~Tool()
{
}

// Reimplemented from base class
unsigned int Tool::getMemSize (void) const
{
return 0;
}

void Tool::Save (Writer &writer) const
{
writer.Stream() << writer.ind() << "<Tool "
<< "name=\"" << encodeAttribute(Name) << "\" "
<< "diameter=\"" << Diameter << "\" "
<< "length=\"" << LengthOffset << "\" "
<< "flat=\"" << FlatRadius << "\" "
<< "corner=\"" << CornerRadius << "\" "
<< "angle=\"" << CuttingEdgeAngle << "\" "
<< "height=\"" << CuttingEdgeHeight << "\" "
<< "type=\"" << TypeName(Type) << "\" "
<< "mat=\"" << MaterialName(Material) << "\" "
<< "/>" << std::endl;
}

void Tool::Restore(XMLReader &reader)
{
reader.readElement("Tool");
Name = reader.getAttribute("name");
Diameter = reader.hasAttribute("diameter") ? (double) reader.getAttributeAsFloat("diameter") : 0.0;
LengthOffset = reader.hasAttribute("length") ? (double) reader.getAttributeAsFloat("length") : 0.0;
FlatRadius = reader.hasAttribute("flat") ? (double) reader.getAttributeAsFloat("flat") : 0.0;
CornerRadius = reader.hasAttribute("corner") ? (double) reader.getAttributeAsFloat("corner") : 0.0;
CuttingEdgeAngle = reader.hasAttribute("angle") ? (double) reader.getAttributeAsFloat("angle") : 180.0;
CuttingEdgeHeight = reader.hasAttribute("height") ? (double) reader.getAttributeAsFloat("height") : 0.0;
std::string type = reader.hasAttribute("type") ? reader.getAttribute("type") : "";
std::string mat = reader.hasAttribute("mat") ? reader.getAttribute("mat") : "";

Type = getToolType(type);
Material = getToolMaterial(mat);


}

const std::vector<std::string> Tool::ToolTypes(void)
{
std::vector<std::string> toolTypes(13);
toolTypes[0] ="EndMill";
toolTypes[1] ="Drill";
toolTypes[2] ="CenterDrill";
toolTypes[3] ="CounterSink";
toolTypes[4] ="CounterBore";
toolTypes[5] ="FlyCutter";
toolTypes[6] ="Reamer";
toolTypes[7] ="Tap";
toolTypes[8] ="SlotCutter";
toolTypes[9] ="BallEndMill";
toolTypes[10] ="ChamferMill";
toolTypes[11] ="CornerRound";
toolTypes[12] ="Engraver";
return toolTypes;

}

const std::vector<std::string> Tool::ToolMaterials(void)
{
std::vector<std::string> toolMat(7);
toolMat[0] ="Carbide";
toolMat[1] ="HighSpeedSteel";
toolMat[2] ="HighCarbonToolSteel";
toolMat[3] ="CastAlloy";
toolMat[4] ="Ceramics";
toolMat[5] ="Diamond";
toolMat[6] ="Sialon";
return toolMat;

}

Tool::ToolType Tool::getToolType(std::string type)
{
Tool::ToolType Type;
if(type=="EndMill")
Type = Tool::ENDMILL;
else if(type=="Drill")
Type = Tool::DRILL;
else if(type=="CenterDrill")
Type = Tool::CENTERDRILL;
else if(type=="CounterSink")
Type = Tool::COUNTERSINK;
else if(type=="CounterBore")
Type = Tool::COUNTERBORE;
else if(type=="FlyCutter")
Type = Tool::FLYCUTTER;
else if(type=="Reamer")
Type = Tool::REAMER;
else if(type=="Tap")
Type = Tool::TAP;
else if(type=="SlotCutter")
Type = Tool::SLOTCUTTER;
else if(type=="BallEndMill")
Type = Tool::BALLENDMILL;
else if(type=="ChamferMill")
Type = Tool::CHAMFERMILL;
else if(type=="CornerRound")
Type = Tool::CORNERROUND;
else if(type=="Engraver")
Type = Tool::ENGRAVER;
else
Type = Tool::UNDEFINED;

return Type;
}

Tool::ToolMaterial Tool::getToolMaterial(std::string mat)
{
Tool::ToolMaterial Material;
if(mat=="Carbide")
Material = Tool::CARBIDE;
else if(mat=="HighSpeedSteel")
Material = Tool::HIGHSPEEDSTEEL;
else if(mat=="HighCarbonToolSteel")
Material = Tool::HIGHCARBONTOOLSTEEL;
else if(mat=="CastAlloy")
Material = Tool::CASTALLOY;
else if(mat=="Ceramics")
Material = Tool::CERAMICS;
else if(mat=="Diamond")
Material = Tool::DIAMOND;
else if(mat=="Sialon")
Material = Tool::SIALON;
else
Material = Tool::MATUNDEFINED;

return Material;
}

const char* Tool::TypeName(Tool::ToolType typ) {
switch (typ) {
case Tool::DRILL:
return "Drill";
case Tool::CENTERDRILL:
return "CenterDrill";
case Tool::COUNTERSINK:
return "CounterSink";
case Tool::COUNTERBORE:
return "CounterBore";
case Tool::FLYCUTTER:
return "FlyCutter";
case Tool::REAMER:
return "Reamer";
case Tool::TAP:
return "Tap";
case Tool::ENDMILL:
return "EndMill";
case Tool::SLOTCUTTER:
return "SlotCutter";
case Tool::BALLENDMILL:
return "BallEndMill";
case Tool::CHAMFERMILL:
return "ChamferMill";
case Tool::CORNERROUND:
return "CornerRound";
case Tool::ENGRAVER:
return "Engraver";
case Tool::UNDEFINED:
return "Undefined";
}
return "Undefined";
}

const char* Tool::MaterialName(Tool::ToolMaterial mat)
{
switch (mat) {
case Tool::HIGHSPEEDSTEEL:
return "HighSpeedSteel";
case Tool::CARBIDE:
return "Carbide";
case Tool::HIGHCARBONTOOLSTEEL:
return "HighCarbonToolSteel";
case Tool::CASTALLOY:
return "CastAlloy";
case Tool::CERAMICS:
return "Ceramics";
case Tool::DIAMOND:
return "Diamond";
case Tool::SIALON:
return "Sialon";
case Tool::MATUNDEFINED:
return "Undefined";
}
return "Undefined";
}
104 changes: 104 additions & 0 deletions src/Mod/Path/App/Tool.h
@@ -0,0 +1,104 @@
/***************************************************************************
* Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 *
* *
* 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 PATH_TOOL_H
#define PATH_TOOL_H

#include <vector>
#include <string>
#include <map>
#include <Base/Persistence.h>

namespace Path
{

/** The representation of a single tool */
class PathExport Tool : public Base::Persistence
{
TYPESYSTEM_HEADER();

public:
enum ToolType {
UNDEFINED,
DRILL,
CENTERDRILL,
COUNTERSINK,
COUNTERBORE,
FLYCUTTER,
REAMER,
TAP,
ENDMILL,
SLOTCUTTER,
BALLENDMILL,
CHAMFERMILL,
CORNERROUND,
ENGRAVER };

enum ToolMaterial {
MATUNDEFINED,
HIGHSPEEDSTEEL,
HIGHCARBONTOOLSTEEL,
CASTALLOY,
CARBIDE,
CERAMICS,
DIAMOND,
SIALON };

//constructors
Tool();
Tool(const char* name,
ToolType type=Tool::UNDEFINED,
ToolMaterial material=Tool::MATUNDEFINED,
double diameter=10.0,
double lengthoffset=100,
double flatradius=0,
double cornerradius=0,
double cuttingedgeangle=0,
double cuttingedgeheight=0);
~Tool();

// from base class
virtual unsigned int getMemSize (void) const;
virtual void Save (Base::Writer &/*writer*/) const;
virtual void Restore(Base::XMLReader &/*reader*/);

// attributes
std::string Name;
ToolType Type;
ToolMaterial Material;
double Diameter;
double LengthOffset;
double FlatRadius;
double CornerRadius;
double CuttingEdgeAngle;
double CuttingEdgeHeight;

static const std::vector<std::string> ToolTypes(void);
static const std::vector<std::string> ToolMaterials(void);
static const char* TypeName(ToolType typ);
static ToolType getToolType(std::string type);
static ToolMaterial getToolMaterial(std::string mat);
static const char* MaterialName(ToolMaterial mat);
};
} //namespace Path

#endif // PATH_TOOL_H

0 comments on commit 174f13e

Please sign in to comment.