Merge branch 'feature/probemoves' into BugFixes

This commit is contained in:
sliptonic 2016-12-11 12:49:42 -06:00
commit 54242963df
5 changed files with 568 additions and 205 deletions

View File

@ -33,8 +33,8 @@ using namespace PathGui;
/* TRANSLATOR PathGui::DlgSettingsPathColor */
/**
* Constructs a DlgSettingsObjectColor which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
* Constructs a DlgSettingsObjectColor which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
DlgSettingsPathColor::DlgSettingsPathColor(QWidget* parent)
: PreferencePage(parent)
@ -42,7 +42,7 @@ DlgSettingsPathColor::DlgSettingsPathColor(QWidget* parent)
this->setupUi(this);
}
/**
/**
* Destroys the object and frees any allocated resources
*/
DlgSettingsPathColor::~DlgSettingsPathColor()
@ -58,6 +58,8 @@ void DlgSettingsPathColor::saveSettings()
DefaultPathLineWidth->onSave();
DefaultPathMarkerColor->onSave();
DefaultExtentsColor->onSave();
DefaultProbePathColor->onSave();
DefaultHighlightPathColor->onSave();
}
void DlgSettingsPathColor::loadSettings()
@ -68,6 +70,8 @@ void DlgSettingsPathColor::loadSettings()
DefaultPathLineWidth->onRestore();
DefaultPathMarkerColor->onRestore();
DefaultExtentsColor->onRestore();
DefaultProbePathColor->onRestore();
DefaultHighlightPathColor->onRestore();
}
/**

View File

@ -6,192 +6,255 @@
<rect>
<x>0</x>
<y>0</y>
<width>359</width>
<height>282</height>
<width>310</width>
<height>304</height>
</rect>
</property>
<property name="windowTitle">
<string>Path colors</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBoxDefaultColors">
<property name="title">
<string>Default Path colors</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Default normal path color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefColorButton" name="DefaultNormalPathColor">
<property name="toolTip">
<string>The default color for new shapes</string>
</property>
<property name="color">
<color>
<red>0</red>
<green>170</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultNormalPathColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Default pathline width</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefSpinBox" name="DefaultPathLineWidth">
<property name="toolTip">
<string>The default line thickness for new shapes</string>
</property>
<property name="suffix">
<string>px</string>
</property>
<property name="maximum">
<number>9</number>
</property>
<property name="value">
<number>1</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultPathLineWidth</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_10">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Default path marker color</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::PrefColorButton" name="DefaultPathMarkerColor">
<property name="toolTip">
<string>The default line color for new shapes</string>
</property>
<property name="color">
<color>
<red>85</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultPathMarkerColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Rapid path color</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="Gui::PrefColorButton" name="DefaultRapidPathColor">
<property name="toolTip">
<string>The default line color for new shapes</string>
</property>
<property name="color">
<color>
<red>170</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultRapidPathColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Machine extents color</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="Gui::PrefColorButton" name="DefaultExtentsColor">
<property name="prefEntry" stdset="0">
<cstring>DefaultExtentsColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="minimumSize">
<size>
<width>28</width>
<height>20</height>
<width>182</width>
<height>0</height>
</size>
</property>
</spacer>
<property name="text">
<string>Default normal path color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefColorButton" name="DefaultNormalPathColor">
<property name="toolTip">
<string>The default color for new shapes</string>
</property>
<property name="color" stdset="0">
<color>
<red>0</red>
<green>170</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultNormalPathColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Default pathline width</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::PrefSpinBox" name="DefaultPathLineWidth">
<property name="toolTip">
<string>The default line thickness for new shapes</string>
</property>
<property name="suffix">
<string>px</string>
</property>
<property name="maximum">
<number>9</number>
</property>
<property name="value">
<number>1</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultPathLineWidth</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_10">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Default path marker color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefColorButton" name="DefaultPathMarkerColor">
<property name="toolTip">
<string>The default line color for new shapes</string>
</property>
<property name="color" stdset="0">
<color>
<red>85</red>
<green>255</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultPathMarkerColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Rapid path color</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::PrefColorButton" name="DefaultRapidPathColor">
<property name="toolTip">
<string>The default line color for new shapes</string>
</property>
<property name="color" stdset="0">
<color>
<red>170</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultRapidPathColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_8">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Probe Path color</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="Gui::PrefColorButton" name="DefaultProbePathColor">
<property name="toolTip">
<string>The default line color for new shapes</string>
</property>
<property name="color" stdset="0">
<color>
<red>255</red>
<green>255</green>
<blue>5</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultProbePathColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Machine extents color</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="Gui::PrefColorButton" name="DefaultExtentsColor">
<property name="prefEntry" stdset="0">
<cstring>DefaultExtentsColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_11">
<property name="minimumSize">
<size>
<width>182</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Path Highlight Color</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="Gui::PrefColorButton" name="DefaultHighlightPathColor">
<property name="toolTip">
<string>The default line color for new shapes</string>
</property>
<property name="color" stdset="0">
<color>
<red>255</red>
<green>125</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultHighlightPathColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
</layout>
<zorder>label_6</zorder>
<zorder>DefaultNormalPathColor</zorder>
<zorder>label_9</zorder>
<zorder>DefaultPathLineWidth</zorder>
<zorder>label_10</zorder>
<zorder>DefaultPathMarkerColor</zorder>
<zorder>label_7</zorder>
<zorder>DefaultRapidPathColor</zorder>
<zorder>label</zorder>
<zorder>DefaultExtentsColor</zorder>
<zorder>label_8</zorder>
<zorder>DefaultProbePathColor</zorder>
<zorder>label_11</zorder>
<zorder>DefaultHighlightPathColor</zorder>
</widget>
</item>
<item>
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -204,6 +267,19 @@
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>7</width>
<height>220</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>

View File

@ -0,0 +1,210 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>273</width>
<height>287</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>231</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="widget" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>261</width>
<height>231</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Probe Area Shape</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cboProbeAreaShape">
<item>
<property name="text">
<string>BoundBox</string>
</property>
</item>
<item>
<property name="text">
<string>Perimeter</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Probe Distance</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="probeFeedDistance">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>5.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_5" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Probe Feed Rate</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="probeFeedRate">
<property name="value">
<double>50.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Probe Points:</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>X:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="xpoints">
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>77</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="ypoints">
<property name="value">
<number>5</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -83,14 +83,14 @@ ViewProviderPath::ViewProviderPath()
ADD_PROPERTY_TYPE(LineWidth,(lwidth),"Path",App::Prop_None,"The line width of this path");
ADD_PROPERTY_TYPE(ShowFirstRapid,(true),"Path",App::Prop_None,"Turns the display of the first rapid move on/off");
ADD_PROPERTY_TYPE(ShowNodes,(false),"Path",App::Prop_None,"Turns the display of nodes on/off");
pcPathRoot = new Gui::SoFCSelection();
pcPathRoot->style = Gui::SoFCSelection::EMISSIVE;
pcPathRoot->highlightMode = Gui::SoFCSelection::AUTO;
pcPathRoot->selectionMode = Gui::SoFCSelection::SEL_ON;
pcPathRoot->ref();
pcTransform = new SoTransform();
pcTransform->ref();
@ -99,7 +99,7 @@ ViewProviderPath::ViewProviderPath()
pcMarkerCoords = new SoCoordinate3();
pcMarkerCoords->ref();
pcDrawStyle = new SoDrawStyle();
pcDrawStyle->ref();
pcDrawStyle->style = SoDrawStyle::LINES;
@ -108,17 +108,17 @@ ViewProviderPath::ViewProviderPath()
pcLines = new PartGui::SoBrepEdgeSet();
pcLines->ref();
pcLines->coordIndex.setNum(0);
pcLineColor = new SoMaterial;
pcLineColor->ref();
pcMatBind = new SoMaterialBinding;
pcMatBind->ref();
pcMatBind->value = SoMaterialBinding::OVERALL;
pcMarkerColor = new SoBaseColor;
pcMarkerColor->ref();
NormalColor.touch();
MarkerColor.touch();
}
@ -186,12 +186,16 @@ void ViewProviderPath::onChanged(const App::Property* prop)
pcDrawStyle->lineWidth = LineWidth.getValue();
} else if (prop == &NormalColor) {
if (colorindex.size() > 0) {
const App::Color& c = NormalColor.getValue();
const App::Color& c = NormalColor.getValue();
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Path");
unsigned long rcol = hGrp->GetUnsigned("DefaultRapidPathColor",2852126975UL); // dark red (170,0,0)
float rr,rg,rb;
rr = ((rcol >> 24) & 0xff) / 255.0; rg = ((rcol >> 16) & 0xff) / 255.0; rb = ((rcol >> 8) & 0xff) / 255.0;
unsigned long pcol = hGrp->GetUnsigned("DefaultProbePathColor",4293591295UL); // yellow (255,255,5)
float pr,pg,pb;
pr = ((pcol >> 24) & 0xff) / 255.0; pg = ((pcol >> 16) & 0xff) / 255.0; pb = ((pcol >> 8) & 0xff) / 255.0;
pcMatBind->value = SoMaterialBinding::PER_PART;
// resizing and writing the color vector:
pcLineColor->diffuseColor.setNum(colorindex.size());
@ -199,8 +203,10 @@ void ViewProviderPath::onChanged(const App::Property* prop)
for(unsigned int i=0;i<colorindex.size();i++) {
if (colorindex[i] == 0)
colors[i] = SbColor(rr,rg,rb);
else
else if (colorindex[i] == 1)
colors[i] = SbColor(c.r,c.g,c.b);
else
colors[i] = SbColor(pr,pg,pb);
}
pcLineColor->diffuseColor.finishEditing();
}
@ -220,14 +226,14 @@ void ViewProviderPath::updateData(const App::Property* prop)
Path::Feature* pcPathObj = static_cast<Path::Feature*>(pcObject);
if (prop == &pcPathObj->Path) {
const Toolpath &tp = pcPathObj->Path.getValue();
if(tp.getSize()==0) {
pcLineCoords->point.deleteValues(0);
pcMarkerCoords->point.deleteValues(0);
return;
}
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part");
float deviation = hGrp->GetFloat("MeshDeviation",0.2);
std::vector<Base::Vector3d> points;
@ -237,7 +243,7 @@ void ViewProviderPath::updateData(const App::Property* prop)
bool absolute = true;
bool absolutecenter = false;
bool first = true;
for (unsigned int i = 0; i < tp.getSize(); i++) {
Path::Command cmd = tp.getCommand(i);
std::string name = cmd.Name;
@ -250,7 +256,7 @@ void ViewProviderPath::updateData(const App::Property* prop)
next.y = last.y;
if (!cmd.has("Z"))
next.z = last.z;
if ( (name == "G0") || (name == "G00") || (name == "G1") || (name == "G01") ) {
// straight line
if ( (!first) || (ShowFirstRapid.getValue() == true) || (name == "G1") || (name == "G01") ) {
@ -273,12 +279,12 @@ void ViewProviderPath::updateData(const App::Property* prop)
markers.push_back(last); // startpoint of path
}
first = false;
} else if ( (name == "G2") || (name == "G02") || (name == "G3") || (name == "G03") ) {
// arc
Base::Vector3d norm;
Base::Vector3d center;
if ( (name == "G2") || (name == "G02") )
norm.Set(0,0,-1);
else
@ -321,23 +327,23 @@ void ViewProviderPath::updateData(const App::Property* prop)
}
last = next;
colorindex.push_back(1);
} else if (name == "G90") {
// absolute mode
absolute = true;
} else if (name == "G91") {
// relative mode
absolute = false;
} else if (name == "G90.1") {
// absolute mode
absolutecenter = true;
} else if (name == "G91.1") {
// relative mode
absolutecenter = false;
} else if ((name=="G81")||(name=="G82")||(name=="G83")||(name=="G84")||(name=="G85")||(name=="G86")||(name=="G89")){
// drill,tap,bore
double r = 0;
@ -373,9 +379,19 @@ void ViewProviderPath::updateData(const App::Property* prop)
if (ShowNodes.getValue() == true)
markers.push_back(p2);
colorindex.push_back(0);
}
}
} else if ((name=="G38.2")||(name=="38.3")||(name=="G38.4")||(name=="G38.5")){
// Straight probe
Base::Vector3d p1(next.x,next.y,last.z);
points.push_back(p1);
colorindex.push_back(0);
points.push_back(next);
colorindex.push_back(2);
Base::Vector3d p3(next.x,next.y,last.z);
points.push_back(p3);
colorindex.push_back(0);
}}
if (!points.empty()) {
pcLineCoords->point.deleteValues(0);
pcLineCoords->point.setNum(points.size());
@ -387,20 +403,20 @@ void ViewProviderPath::updateData(const App::Property* prop)
int* segs = &ei[0];
pcLines->coordIndex.setNum(points.size());
pcLines->coordIndex.setValues(0,points.size(),(const int32_t*)segs);
pcMarkerCoords->point.deleteValues(0);
pcMarkerCoords->point.setNum(markers.size());
for(unsigned int i=0;i<markers.size();i++)
pcMarkerCoords->point.set1Value(i,markers[i].x,markers[i].y,markers[i].z);
// update the coloring after we changed the color vector
NormalColor.touch();
recomputeBoundingBox();
}
} else if ( prop == &pcPathObj->Placement) {
Base::Placement pl = *(&pcPathObj->Placement.getValue());
Base::Vector3d pos = pl.getPosition();
double q1, q2, q3, q4;

View File

@ -25,7 +25,7 @@
from PySide import QtCore, QtGui
import FreeCAD
import FreeCADGui
import Path
# Qt tanslation handling
try:
_encoding = QtGui.QApplication.UnicodeUTF8
@ -110,11 +110,21 @@ class GCodeHighlighter(QtGui.QSyntaxHighlighter):
class GCodeEditorDialog(QtGui.QDialog):
def __init__(self, parent=FreeCADGui.getMainWindow()):
def __init__(self, PathObj, parent=FreeCADGui.getMainWindow()):
self.PathObj = PathObj
QtGui.QDialog.__init__(self, parent)
layout = QtGui.QVBoxLayout(self)
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
c = p.GetUnsigned("DefaultHighlightPathColor", 4286382335 )
Q = QtGui.QColor(int((c >> 24) & 0xFF), int((c >> 16) & 0xFF), int((c >> 8) & 0xFF))
highlightcolor = (Q.red()/255., Q.green()/255., Q.blue()/255., Q.alpha()/255.)
self.selectionobj = FreeCAD.ActiveDocument.addObject("Path::Feature","selection")
self.selectionobj.ViewObject.LineWidth = 4
self.selectionobj.ViewObject.NormalColor = highlightcolor
self.selectionobj.ViewObject.ShowFirstRapid = False
# nice text editor widget for editing the gcode
self.editor = QtGui.QTextEdit()
font = QtGui.QFont()
@ -140,6 +150,53 @@ class GCodeEditorDialog(QtGui.QDialog):
layout.addWidget(self.buttons)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.editor.selectionChanged.connect(self.hightlightpath)
self.finished.connect(self.cleanup)
def cleanup(self):
FreeCAD.ActiveDocument.removeObject(self.selectionobj.Name)
def hightlightpath(self):
cursor = self.editor.textCursor()
sp = cursor.selectionStart()
ep = cursor.selectionEnd()
cursor.setPosition(sp)
startrow = cursor.blockNumber()
cursor.setPosition(ep)
endrow = cursor.blockNumber()
commands = self.PathObj.Commands
#Derive the starting position for the first selected command
prevX = prevY = prevZ = None
prevcommands = commands[:startrow]
prevcommands.reverse()
for c in prevcommands:
if prevX is None:
if c.Parameters.get("X") is not None:
prevX = c.Parameters.get("X")
if prevY is None:
if c.Parameters.get("Y") is not None:
prevY = c.Parameters.get("Y")
if prevZ is None:
if c.Parameters.get("Z") is not None:
prevZ = c.Parameters.get("Z")
if prevX is not None and prevY is not None and prevZ is not None:
break
if prevX is None:
prevX = 0.0
if prevY is None:
prevY = 0.0
if prevZ is None:
prevZ = 0.0
#Build a new path with selection
p = Path.Path()
firstrapid = Path.Command("G0", {"X": prevX, "Y":prevY, "Z":prevZ})
selectionpath = [firstrapid] + commands[startrow:endrow +1]
p.Commands = selectionpath
self.selectionobj.Path = p
def show(obj):
@ -147,7 +204,7 @@ def show(obj):
if hasattr(obj, "Path"):
if obj.Path:
dia = GCodeEditorDialog()
dia = GCodeEditorDialog(obj.Path)
dia.editor.setText(obj.Path.toGCode())
result = dia.exec_()
# exec_() returns 0 or 1 depending on the button pressed (Ok or