Replaced Tooltable with Tool in the TC;

Added PropertyTool;
Fixed sanity check.
This commit is contained in:
Markus Lampert
2017-06-04 22:04:42 -07:00
parent 7d39669948
commit c4cb45c1b4
8 changed files with 221 additions and 44 deletions

View File

@@ -39,6 +39,7 @@
#include "TooltablePy.h"
#include "PropertyPath.h"
#include "FeaturePath.h"
#include "PropertyTool.h"
#include "PropertyTooltable.h"
#include "FeaturePathCompound.h"
#include "FeaturePathShape.h"
@@ -81,6 +82,7 @@ PyMOD_INIT_FUNC(Path)
Path::PropertyPath ::init();
Path::Feature ::init();
Path::FeaturePython ::init();
Path::PropertyTool ::init();
Path::PropertyTooltable ::init();
Path::FeatureCompound ::init();
Path::FeatureCompoundPython ::init();

View File

@@ -71,6 +71,8 @@ SET(Path_SRCS
PropertyPath.h
FeaturePath.cpp
FeaturePath.h
PropertyTool.cpp
PropertyTool.h
PropertyTooltable.cpp
PropertyTooltable.h
FeaturePathCompound.cpp

View File

@@ -0,0 +1,116 @@
/***************************************************************************
* 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_
# include <sstream>
#endif
#include <Base/Console.h>
#include <Base/Writer.h>
#include <Base/Reader.h>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
#include <Base/Stream.h>
#include "PropertyTool.h"
#include "ToolPy.h"
using namespace Path;
TYPESYSTEM_SOURCE(Path::PropertyTool, App::Property);
PropertyTool::PropertyTool()
{
}
PropertyTool::~PropertyTool()
{
}
void PropertyTool::setValue(const Tool& tt)
{
aboutToSetValue();
_Tool = tt;
hasSetValue();
}
const Tool &PropertyTool::getValue(void)const
{
return _Tool;
}
PyObject *PropertyTool::getPyObject(void)
{
return new ToolPy(new Tool(_Tool));
}
void PropertyTool::setPyObject(PyObject *value)
{
if (PyObject_TypeCheck(value, &(ToolPy::Type))) {
ToolPy *pcObject = static_cast<ToolPy*>(value);
setValue(*pcObject->getToolPtr());
}
else {
std::string error = std::string("type must be 'Tool', not ");
error += value->ob_type->tp_name;
throw Base::TypeError(error);
}
}
App::Property *PropertyTool::Copy(void) const
{
PropertyTool *prop = new PropertyTool();
prop->_Tool = this->_Tool;
return prop;
}
void PropertyTool::Paste(const App::Property &from)
{
aboutToSetValue();
_Tool = dynamic_cast<const PropertyTool&>(from)._Tool;
hasSetValue();
}
unsigned int PropertyTool::getMemSize (void) const
{
return _Tool.getMemSize();
}
void PropertyTool::Save (Base::Writer &writer) const
{
_Tool.Save(writer);
}
void PropertyTool::Restore(Base::XMLReader &reader)
{
Path::Tool temp;
temp.Restore(reader);
setValue(temp);
}

View File

@@ -0,0 +1,75 @@
/***************************************************************************
* 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 PROPERTYTOOL_H
#define PROPERTYTOOL_H
#include "Tooltable.h"
#include <App/Property.h>
namespace Path
{
/** The tool property class. */
class PathExport PropertyTool : public App::Property
{
TYPESYSTEM_HEADER();
public:
PropertyTool();
~PropertyTool();
/** @name Getter/setter */
//@{
/// set the part shape
void setValue(const Tool&);
/// get the part shape
const Tool &getValue(void) const;
//@}
/** @name Python interface */
//@{
PyObject* getPyObject(void);
void setPyObject(PyObject *value);
//@}
/** @name Save/restore */
//@{
void Save (Base::Writer &writer) const;
void Restore(Base::XMLReader &reader);
App::Property *Copy(void) const;
void Paste(const App::Property &from);
unsigned int getMemSize (void) const;
//@}
private:
Tool _Tool;
};
} //namespace Path
#endif // PROPERTYTOOL_H

View File

@@ -24,18 +24,21 @@
''' Tool Controller defines tool, spindle speed and feed rates for Path Operations '''
import FreeCAD
from FreeCAD import Units
import FreeCADGui
import Path
import Part
import Path
import PathScripts
from PySide import QtCore, QtGui
import PathScripts.PathLog as PathLog
import PathScripts.PathUtils as PathUtils
import PathUtils
LOG_MODULE = 'PathLoadTool'
PathLog.setLevel(PathLog.Level.INFO, LOG_MODULE)
#PathLog.trackModule('PathLoadTool')
from FreeCAD import Units
from PySide import QtCore, QtGui
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# Qt tanslation handling
def translate(context, text, disambig=None):
@@ -48,7 +51,7 @@ class LoadTool():
obj.addProperty("App::PropertyIntegerConstraint", "ToolNumber", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "The active tool"))
obj.ToolNumber = (0, 0, 10000, 1)
obj.addProperty("Path::PropertyTooltable", "Tooltable", "Base", QtCore.QT_TRANSLATE_NOOP("App::Property", "The tooltable used for this CNC program"))
obj.addProperty("Path::PropertyTool", "Tool", "Base", QtCore.QT_TRANSLATE_NOOP("App::Property", "The tool used by this controller"))
obj.addProperty("App::PropertyFloat", "SpindleSpeed", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "The speed of the cutting spindle in RPM"))
obj.addProperty("App::PropertyEnumeration", "SpindleDir", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "Direction of spindle rotation"))
@@ -64,7 +67,6 @@ class LoadTool():
def execute(self, obj):
PathLog.track()
#toolnum = obj.Tooltable.Tools.keys()[0]
commands = ""
commands += "(" + obj.Label + ")"+'\n'
commands += 'M6 T'+str(obj.ToolNumber)+'\n'
@@ -87,24 +89,16 @@ class LoadTool():
if 'Restore' not in obj.State:
if prop == "ToolNumber":
toolitem = obj.Tooltable.Tools.popitem()
oldtoolnum = toolitem[0]
tool = toolitem[1]
obj.Tooltable.deleteTool(oldtoolnum)
obj.Tooltable.setTool(obj.ToolNumber, tool)
else:
job = PathUtils.findParentJob(obj)
if job is not None:
for g in job.Group:
if not(isinstance(g.Proxy, PathScripts.PathLoadTool.LoadTool)):
g.touch()
job = PathUtils.findParentJob(obj)
if job is not None:
for g in job.Group:
if not(isinstance(g.Proxy, PathScripts.PathLoadTool.LoadTool)):
g.touch()
def getTool(self, obj):
'''returns the tool associated with this tool controller'''
PathLog.track()
toolitem = obj.Tooltable.Tools.popitem()
return toolitem[1]
return obj.Tool
class _ViewProviderLoadTool:
@@ -193,9 +187,6 @@ class CommandPathLoadTool:
def Create(jobname=None, assignViewProvider=True, tool=None, toolNumber=1):
PathLog.track("tool: {} with toolNumber: {}".format(tool, toolNumber))
import PathScripts
from PathScripts import PathUtils
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "Default Tool")
PathScripts.PathLoadTool.LoadTool(obj)
if assignViewProvider:
@@ -208,7 +199,7 @@ class CommandPathLoadTool:
tool.CuttingEdgeHeight = 15.0
tool.ToolType = "EndMill"
tool.Material = "HighSpeedSteel"
obj.Tooltable.setTool(toolNumber, tool)
obj.Tool = tool
obj.ToolNumber = toolNumber
PathUtils.addToJob(obj, jobname)
@@ -273,11 +264,9 @@ class TaskPanel:
index = self.form.cboSpindleDirection.findText(self.obj.SpindleDir, QtCore.Qt.MatchFixedString)
if index >= 0:
self.form.cboSpindleDirection.setCurrentIndex(index)
tooltable = self.obj.Tooltable
try:
toolnum = tooltable.Tools.keys()[0]
tool = tooltable.getTool(toolnum)
tool = self.obj.Tool
self.form.txtToolType.setText(tool.ToolType)
self.form.txtToolMaterial.setText(tool.Material)
diam = Units.Quantity(tool.Diameter, FreeCAD.Units.Length)
@@ -345,8 +334,8 @@ class TaskPanel:
return matslist[material]
def editTool(self):
toolnum = self.obj.Tooltable.Tools.keys()[0]
tool = self.obj.Tooltable.getTool(toolnum)
toolnum = self.obj.ToolNumber
tool = self.obj.Tool
editform = FreeCADGui.PySideUic.loadUi(":/panels/ToolEdit.ui")
editform.NameField.setText(tool.Name)
@@ -371,7 +360,7 @@ class TaskPanel:
tool.CornerRadius = FreeCAD.Units.parseQuantity(editform.CornerRadiusField.text())
tool.CuttingEdgeAngle = FreeCAD.Units.Quantity(editform.CuttingEdgeAngleField.text())
tool.CuttingEdgeHeight = FreeCAD.Units.parseQuantity(editform.CuttingEdgeHeightField.text())
self.obj.Tooltable.setTool(toolnum, tool)
self.obj.Tool = tool
self.setFields()

View File

@@ -29,7 +29,6 @@ from __future__ import print_function
from PySide import QtCore, QtGui
import FreeCAD
import FreeCADGui
import PathScripts.PathUtils as PU
# Qt tanslation handling
def translate(context, text, disambig=None):
@@ -40,19 +39,14 @@ def review(obj):
"checks the selected job for common errors"
toolcontrolcount = 0
if len(obj.Tooltable.Tools) == 0:
FreeCAD.Console.PrintWarning(translate("Path_Sanity", "Machine: " + str(obj.Label) + " has no tools defined in the tool table\n"))
if obj.X_Max == obj.X_Min or obj.Y_Max == obj.Y_Min:
FreeCAD.Console.PrintWarning(translate("Path_Sanity", "It appears the machine limits haven't been set. Not able to check path extents.\n"))
for item in obj.Group:
print("Checking: " + item.Label)
if item.Name[:2] == "TC":
if hasattr(item, 'Tool') and hasattr(item, 'SpindleDir'):
toolcontrolcount += 1
if item.ToolNumber == 0:
FreeCAD.Console.PrintWarning(translate("Path_Sanity", "Tool Controller: " + str(item.Label) + " is using ID 0 which the undefined default. Please set a real tool.\n"))
else:
tool = PU.getTool(item, item.ToolNumber)
tool = item.Tool
if tool is None:
FreeCAD.Console.PrintError(translate("Path_Sanity", "Tool Controller: " + str(item.Label) + " is using tool: " + str(item.ToolNumber) + " which is invalid\n"))
elif tool.Diameter == 0:

View File

@@ -554,8 +554,7 @@ class EditorPanel():
PathScripts.PathLoadTool._ViewProviderLoadTool(obj.ViewObject)
PathUtils.addToJob(obj, targetlist)
FreeCAD.activeDocument().recompute()
newtool = tool.copy()
obj.Tooltable.setTool(int(toolnum), newtool)
obj.Tool = tool.copy()
obj.ToolNumber = int(toolnum)
#obj.recompute()
FreeCAD.ActiveDocument.recompute()

View File

@@ -59,7 +59,7 @@ class PathPostTestCases(unittest.TestCase):
tc = FreeCAD.ActiveDocument.addObject("Path::FeaturePython",'TC')
PathScripts.PathLoadTool.LoadTool(tc)
PathScripts.PathUtils.addToJob(tc, "Job")
tc.Tooltable.setTool(2, tool1)
tc.Tool = tool1
tc.ToolNumber = 2
self.failUnless(True)