Skip to content

Commit

Permalink
Merge branch 'FreeCAD:main' into concise_toolbars
Browse files Browse the repository at this point in the history
  • Loading branch information
obelisk79 authored Jan 1, 2024
2 parents 744da6b + ef15fbf commit d1ec52b
Show file tree
Hide file tree
Showing 16 changed files with 687 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/Gui/CommandMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ StdCmdMacroStepInto::StdCmdMacroStepInto()
sGroup = "Macro";
sMenuText = QT_TR_NOOP("Step into");
sToolTipText = QT_TR_NOOP("Step to the next line executed");
//sWhatsThis = "Std_MacroStepOver";
sWhatsThis = "Std_MacroStepInto";
sStatusTip = QT_TR_NOOP("Step to the next line executed");
sPixmap = nullptr;
sAccel = "F11";
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Fem/femmesh/meshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ def get_ref_facenodes_table(
# try to use getccxVolumesByFace() to get the volume ids
# of element with elementfaces on the ref_face
# --> should work for tetra4 and tetra10
# list of tupels (mv, ccx_face_nr)
# list of tuples (mv, ccx_face_nr)
ref_face_volume_elements = femmesh.getccxVolumesByFace(ref_face)
if ref_face_volume_elements: # mesh with tetras
FreeCAD.Console.PrintLog(
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Import/App/dxf/dxf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ void CDxfRead::OnReadArc(double start_angle,

void CDxfRead::OnReadCircle(const double* center, double radius, bool hidden)
{
// OnReadCircle wants a start point, so we pick an arbitrary point on the circunference
// OnReadCircle wants a start point, so we pick an arbitrary point on the circumference
double s[3] = {center[0] + radius, center[1], center[2]};

OnReadCircle(s,
Expand Down
24 changes: 0 additions & 24 deletions src/Mod/Path/InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,30 +267,6 @@ def Initialize(self):
)
Log("Loading Path workbench... done\n")

# Warn user if current schema doesn't use minute for time in velocity
if not Path.Preferences.suppressVelocity():
velString = FreeCAD.Units.Quantity(
1, FreeCAD.Units.Velocity
).getUserPreferred()[2][3:]

if velString != "min":
current_schema = FreeCAD.Units.listSchemas(FreeCAD.Units.getSchema())

msg = translate(
"Path",
"The currently selected unit schema: \n '{}'\n Does not use 'minutes' for velocity values. \n \nCNC machines require feed rate to be expressed in \nunit/minute. To ensure correct G-code: \nSelect a minute-based schema in preferences.\nFor example:\n 'Metric, Small Parts & CNC'\n 'US Customary'\n 'Imperial Decimal'",
).format(current_schema)
header = translate("Path", "Warning")
msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, header, msg)

msgbox.addButton(translate("Path", "Ok"), QtGui.QMessageBox.AcceptRole)
msgbox.addButton(
translate("Path", "Don't Show This Anymore"),
QtGui.QMessageBox.ActionRole,
)
if msgbox.exec_() == 1:
preferences().SetBool("WarningSuppressVelocity", True)

def GetClassName(self):
return "Gui::PythonWorkbench"

Expand Down
28 changes: 28 additions & 0 deletions src/Mod/Path/Path/Main/Gui/JobDlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ class JobCreate:
DataObject = QtCore.Qt.ItemDataRole.UserRole

def __init__(self, parent=None, sel=None):
# Warn user if current schema doesn't use minute for time in velocity
if not Path.Preferences.suppressVelocity():
schemes = FreeCAD.Units.listSchemas()
for idx, val in enumerate(schemes):
if FreeCAD.ActiveDocument.UnitSystem == FreeCAD.Units.listSchemas(idx):
current_schema = FreeCAD.Units.listSchemas(idx)
if idx not in [2, 3, 6]:
msg = translate(
"Path",
"The currently selected unit schema: \n '{}' for this document\n Does not use 'minutes' for velocity values. \n \nCNC machines require feed rate to be expressed in \nunit/minute. To ensure correct G-code: \nSelect a minute-based schema in preferences.\nFor example:\n 'Metric, Small Parts & CNC'\n 'US Customary'\n 'Imperial Decimal'",
).format(current_schema)
header = translate("Path", "Warning")
msgbox = QtGui.QMessageBox(
QtGui.QMessageBox.Warning, header, msg
)

msgbox.addButton(
translate("Path", "Ok"), QtGui.QMessageBox.AcceptRole
)
msgbox.addButton(
translate("Path", "Don't Show This Anymore"),
QtGui.QMessageBox.ActionRole,
)
if msgbox.exec_() == 1:
from Path.Preferences import preferences

preferences().SetBool("WarningSuppressVelocity", True)

self.dialog = FreeCADGui.PySideUic.loadUi(":/panels/DlgJobCreate.ui")
self.itemsSolid = QtGui.QStandardItem(translate("Path_Job", "Solids"))
self.items2D = QtGui.QStandardItem(translate("Path_Job", "2D"))
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Show/mTempoVis.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ def restore(self, ultimate=True):

# <stack interface>
def _inserted(self, stack, index):
"""calles when this tv is inserted into a stack"""
"""called when this tv is inserted into a stack"""
self.stack = stack

def _withdrawn(self, stack, index):
"""calles when this tv is withdrawn from a stack"""
"""called when this tv is withdrawn from a stack"""
self.stack = None

@property
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void DlgPrefsTechDrawAnnotationImp::loadSettings()
if (ui->pcbLineStandard->count() > Preferences::lineStandard()) {
ui->pcbLineStandard->setCurrentIndex(Preferences::lineStandard());
}
// we have to connect the slot after the inital load or the current standard will
// we have to connect the slot after the initial load or the current standard will
// be set to index 0 when the widget is created
connect(ui->pcbLineStandard, qOverload<int>(&QComboBox::currentIndexChanged),
this, &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged);
Expand Down
14 changes: 7 additions & 7 deletions src/Mod/TechDraw/Gui/QGIView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
if(change == ItemPositionChange && scene()) {
newPos = value.toPointF(); //position within parent!
if(m_locked){
// ignore position change for locked items
newPos.setX(pos().x());
newPos.setY(pos().y());
return newPos;
}

TechDraw::DrawView *viewObj = getViewObject();

// TODO find a better data structure for this
// this is just a pair isn't it?
if (viewObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
// restrict movements of secondary views.
TechDraw::DrawProjGroupItem* dpgi = static_cast<TechDraw::DrawProjGroupItem*>(viewObj);
TechDraw::DrawProjGroup* dpg = dpgi->getPGroup();
if (dpg) {
Expand All @@ -186,11 +186,11 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
}
}
}
} else {
Gui::ViewProvider *vp = getViewProvider(viewObj);
if (vp && !vp->isRestoring()) {
viewObj->setPosition(Rez::appX(newPos.x()), Rez::appX(-newPos.y()));
}
}
// tell the feature that we have moved
Gui::ViewProvider *vp = getViewProvider(viewObj);
if (vp && !vp->isRestoring()) {
viewObj->setPosition(Rez::appX(newPos.x()), Rez::appX(-newPos.y()));
}

return newPos;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def getSelEdges(nEdge=1, nSel=0):
def getCoordinateVectors(view):
'''
(px,py,pz) = getCoordinateVectors(view)
view ... selcted view
view ... selected view
(px,py,pz) ... returned tuple of vectors (App.Vector)
calculate projected vectors of x-, y- and z-axis
'''
Expand Down
5 changes: 5 additions & 0 deletions tests/src/Mod/Part/App/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ target_sources(
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/TopoShape.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeCache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartCommon.cpp
${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartCut.cpp
${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartFuse.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/FeatureFillet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/PartTestHelpers.cpp
)
201 changes: 201 additions & 0 deletions tests/src/Mod/Part/App/FeaturePartCommon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
// SPDX-License-Identifier: LGPL-2.1-or-later

#include "gtest/gtest.h"

#include "Mod/Part/App/FeaturePartCommon.h"
#include <src/App/InitApplication.h>

#include "PartTestHelpers.h"

class FeaturePartCommonTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
{
protected:
static void SetUpTestSuite()
{
tests::initApplication();
}


void SetUp() override
{
createTestDoc();
_common = dynamic_cast<Part::Common*>(_doc->addObject("Part::Common"));
}

void TearDown() override
{}

Part::Common* _common = nullptr; // NOLINT Can't be private in a test framework
};

TEST_F(FeaturePartCommonTest, testIntersecting)
{
// Arrange
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[1]);

// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();

// Assert
EXPECT_DOUBLE_EQ(volume, 3.0);
// double check using bounds:
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
EXPECT_DOUBLE_EQ(bb.MinY, 1.0);
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}

TEST_F(FeaturePartCommonTest, testNonIntersecting)
{
// Arrange
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[2]);

// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();

// Assert
EXPECT_FALSE(bb.IsValid());
EXPECT_DOUBLE_EQ(volume, 0.0);
}

TEST_F(FeaturePartCommonTest, testTouching)
{
// Arrange
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[3]);

// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();

// Assert
EXPECT_FALSE(bb.IsValid());
EXPECT_DOUBLE_EQ(volume, 0.0);
}

TEST_F(FeaturePartCommonTest, testAlmostTouching)
{
// Arrange
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[4]);

// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();

// Assert
EXPECT_FALSE(bb.IsValid());
EXPECT_DOUBLE_EQ(volume, 0.0);
}

TEST_F(FeaturePartCommonTest, testBarelyIntersecting)
{
// Arrange
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[5]); // NOLINT magic number

// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
double target = PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume
Base::BoundBox3d bb = ts.getBoundBox();

// Assert
// Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07
// rather than 1e15 See
// https://google.github.io/googletest/reference/assertions.html#floating-point
EXPECT_FLOAT_EQ(volume, target); // Should be approximately 0.00029999999999996696
// double check using bounds:
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
EXPECT_DOUBLE_EQ(bb.MinY, 2.0 - PartTestHelpers::minimalDistance);
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}

TEST_F(FeaturePartCommonTest, testMustExecute)
{
// Assert initially we don't need to execute
EXPECT_FALSE(_common->mustExecute());
// Act to change one property
_common->Base.setValue(_boxes[0]);
// Assert we still can't execute
EXPECT_FALSE(_common->mustExecute());
// Act to complete the properties we need
_common->Tool.setValue(_boxes[1]);
// Assert that we now must execute
EXPECT_TRUE(_common->mustExecute());
// Act to execute
_doc->recompute();
// Assert we don't need to execute anymore
EXPECT_FALSE(_common->mustExecute());
}

TEST_F(FeaturePartCommonTest, testGetProviderName)
{
// Act
_common->execute();
const char* name = _common->getViewProviderName();
// Assert
EXPECT_STREQ(name, "PartGui::ViewProviderBoolean");
}

TEST_F(FeaturePartCommonTest, testHistory)
{
// Arrange
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[1]);
// Manually create the histories classically generated by FreeCAD for comparison
using MapList = std::map<int, std::vector<int>>;
using List = std::vector<int>;
MapList compare1 = {{0, List {0}},
{1, List {5}}, // NOLINT magic number
{2, List()},
{3, List {2}},
{4, List {3}},
{5, List {1}}}; // NOLINT magic number
MapList compare2 = {{0, List {0}},
{1, List {5}}, // NOLINT magic number
{2, List {4}},
{3, List()},
{4, List {3}},
{5, List {1}}}; // NOLINT magic number

// Act and Assert no histories yet
std::vector<Part::ShapeHistory> hist = _common->History.getValues();
EXPECT_EQ(hist.size(), 0);

// Act to generate histories
_common->execute();
hist = _common->History.getValues();
// Assert
ASSERT_EQ(hist.size(), 2);
EXPECT_EQ(hist[0].shapeMap, compare1);
EXPECT_EQ(hist[1].shapeMap, compare2);

// Act to reverse the histories
_common->Base.setValue(_boxes[1]);
_common->Tool.setValue(_boxes[0]);
_common->execute();
hist = _common->History.getValues();
// Assert
ASSERT_EQ(hist.size(), 2);
EXPECT_EQ(hist[0].shapeMap, compare2);
EXPECT_EQ(hist[1].shapeMap, compare1);
}
Loading

0 comments on commit d1ec52b

Please sign in to comment.