From 18babc3089b244fb4a13bbc8dde073fd1167985a Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Mon, 20 Oct 2025 16:34:05 +0100 Subject: [PATCH] =?UTF-8?q?[PartDesign]=20create=20a=20new=20Gui=20Unit=20?= =?UTF-8?q?Test=20for=20the=20creation=20of=20a=20sketch=20=E2=80=A6=20(#2?= =?UTF-8?q?3601)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [PartDesign] create a new Gui Unit Test for the creation of a sketch and... ...improve the Selection Filter syntax error to show where it's being generated from. * [PartDesign] address Lint feedback * PD/Tests: Ensure test file does not exist before SaveAs --------- Co-authored-by: Chris Hennes --- src/Gui/Selection/SelectionFilter.tab.c | 7 ++- src/Mod/PartDesign/TestPartDesignGui.py | 61 +++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/Gui/Selection/SelectionFilter.tab.c b/src/Gui/Selection/SelectionFilter.tab.c index ac1adc85eb..613d725de3 100644 --- a/src/Gui/Selection/SelectionFilter.tab.c +++ b/src/Gui/Selection/SelectionFilter.tab.c @@ -936,7 +936,7 @@ yysyntax_error (char *yyresult, int yystate, int yychar) # endif char *yyfmt; char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyunexpected[] = "Selection Filter: syntax error, unexpected %s"; static char const yyexpecting[] = ", expecting %s"; static char const yyor[] = " or %s"; char yyformat[sizeof yyunexpected @@ -1464,7 +1464,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (YY_("syntax error")); + yyerror (YY_("Selection Filter: syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); @@ -1492,7 +1492,7 @@ yyerrlab: } else { - yyerror (YY_("syntax error")); + yyerror (YY_("Selection Filter: syntax error")); if (yysize != 0) goto yyexhaustedlab; } @@ -1643,4 +1643,3 @@ yyreturn: /* Line 1684 of yacc.c */ #line 61 "SelectionFilter.y" - diff --git a/src/Mod/PartDesign/TestPartDesignGui.py b/src/Mod/PartDesign/TestPartDesignGui.py index e7838e0e98..84f84fb5d6 100644 --- a/src/Mod/PartDesign/TestPartDesignGui.py +++ b/src/Mod/PartDesign/TestPartDesignGui.py @@ -77,6 +77,26 @@ class CallableComboBox: if (cbox is not None): QtCore.QTimer.singleShot(0, dialog, QtCore.SLOT('accept()')) + +class CallableCheckExemptionDialog: + def __init__(self, test): + self.test = test + def __call__(self): + dialog = QApplication.activeModalWidget() + if dialog is not None: + dialogcheck = CallableCheckExemptionDialogWasClosed(self.test) + QtCore.QTimer.singleShot(100, dialogcheck) + QtCore.QTimer.singleShot(0, dialog, QtCore.SLOT('accept()')) + +class CallableCheckExemptionDialogWasClosed: + def __init__(self, test): + self.test = test + def __call__(self): + dialog = QApplication.activeModalWidget() + self.test.assertIsNone(dialog, "Dialog box was not closed by accept()") + + + App = FreeCAD Gui = FreeCADGui #--------------------------------------------------------------------------- @@ -219,9 +239,17 @@ class PartDesignTransformed(unittest.TestCase): #not adding box to the body to imitate undertermined workflow tempDir = tempfile.gettempdir() self.TempDoc = os.path.join(tempDir, 'PartDesignTransformed.FCStd') + if os.path.exists(self.TempDoc): + os.remove(self.TempDoc) App.ActiveDocument.saveAs(self.TempDoc) App.closeDocument("PartDesignTransformed") + def tearDown(self): + #closing doc + if (App.ActiveDocument is not None and App.ActiveDocument.Name == PartDesignTransformed): + App.closeDocument("PartDesignTransformed") + #print ("omit closing document for debugging") + def testMultiTransformCase(self): App.Console.PrintMessage('Testing applying MultiTransform to the Box outside the body\n') App.open(self.TempDoc) @@ -234,11 +262,33 @@ class PartDesignTransformed(unittest.TestCase): App.closeDocument("PartDesignTransformed") - def tearDown(self): - #closing doc - if (App.ActiveDocument is not None and App.ActiveDocument.Name == PartDesignTransformed): - App.closeDocument("PartDesignTransformed") - #print ("omit closing document for debugging") + +class CreateSketch(unittest.TestCase): + + def testPDCreateSketch(self): + App.Console.PrintMessage("Testing the creation of a sketch\n") + param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/PartDesign") + useAttachmentSaved = param.GetBool("NewSketchUseAttachmentDialog", False) + param.SetBool("NewSketchUseAttachmentDialog", False) + App.newDocument() + App.activeDocument().addObject("PartDesign::Body", "Body") + App.ActiveDocument.getObject("Body").Label = "Body" + App.ActiveDocument.getObject("Body").AllowCompound = True + FreeCADGui.activateView("Gui::View3DInventor", True) + FreeCADGui.activeView().setActiveObject("pdbody", App.activeDocument().Body) + FreeCADGui.Selection.clearSelection() + FreeCADGui.Selection.addSelection(App.ActiveDocument.Body) + FreeCADGui.runCommand("Std_OrthographicCamera", 1) + mw = FreeCADGui.getMainWindow() + workflowcheck = CallableCheckExemptionDialog(self) + QtCore.QTimer.singleShot(100, workflowcheck) + FreeCADGui.runCommand("PartDesign_CompSketches", 0) + taskspanel = mw.findChild(QtGui.QWidget,"PartDesignGui__TaskFeaturePick") + self.assertTrue(taskspanel is not None) + if taskspanel is not None: + QtCore.QTimer.singleShot(0, taskspanel, QtCore.SLOT("hide()")) + App.closeDocument(App.ActiveDocument.Name) + param.SetBool("NewSketchUseAttachmentDialog", useAttachmentSaved) #class PartDesignGuiTestCases(unittest.TestCase): # def setUp(self): @@ -338,3 +388,4 @@ class TestDatumPlane(unittest.TestCase): color = int(r * 255.0 + 0.5) << 24 | int(g * 255.0 + 0.5) << 16 | int(b * 255.0 + 0.5) << 8 | int(a * 255.0 + 0.5) self.assertEqual(packed_color, color) +