From 48dbdacdbd64118b0b553feaa54c64c03893904f Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Fri, 20 Sep 2024 10:46:01 +0200 Subject: [PATCH] Part: add datum objects and commands to create them. --- src/App/Datums.cpp | 25 ++- src/App/Datums.h | 25 ++- src/Gui/CommandStructure.cpp | 4 +- src/Mod/Part/App/AppPart.cpp | 5 + src/Mod/Part/App/AttachExtension.h | 1 - src/Mod/Part/App/CMakeLists.txt | 2 + src/Mod/Part/App/Datums.cpp | 63 ++++++ src/Mod/Part/App/Datums.h | 84 ++++++++ src/Mod/Part/Gui/AppPartGui.cpp | 5 + src/Mod/Part/Gui/CMakeLists.txt | 2 + src/Mod/Part/Gui/Command.cpp | 196 ++++++++++++++++++ .../Part/Gui/ViewProviderAttachExtension.cpp | 4 + .../Part/Gui/ViewProviderAttachExtension.h | 1 - src/Mod/Part/Gui/ViewProviderDatum.cpp | 94 +++++++++ src/Mod/Part/Gui/ViewProviderDatum.h | 84 ++++++++ src/Mod/Part/Gui/WorkbenchManipulator.cpp | 16 ++ src/Mod/Part/Gui/WorkbenchManipulator.h | 1 + src/Mod/PartDesign/App/Body.cpp | 4 +- src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 24 ++- src/Mod/PartDesign/Gui/ViewProviderDatum.cpp | 25 ++- src/Mod/PartDesign/Gui/ViewProviderDatum.h | 25 ++- 21 files changed, 626 insertions(+), 64 deletions(-) create mode 100644 src/Mod/Part/App/Datums.cpp create mode 100644 src/Mod/Part/App/Datums.h create mode 100644 src/Mod/Part/Gui/ViewProviderDatum.cpp create mode 100644 src/Mod/Part/Gui/ViewProviderDatum.h diff --git a/src/App/Datums.cpp b/src/App/Datums.cpp index c58c34b72f..3157ea4cd3 100644 --- a/src/App/Datums.cpp +++ b/src/App/Datums.cpp @@ -3,22 +3,21 @@ * Copyright (c) 2015 Alexander Golubev (Fat-Zer) * * Copyright (c) 2024 Ondsel (PL Boyer) * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * 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. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 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. * + * FreeCAD 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 * + * Lesser 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 * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * ***************************************************************************/ diff --git a/src/App/Datums.h b/src/App/Datums.h index 002790e78b..286e7353f3 100644 --- a/src/App/Datums.h +++ b/src/App/Datums.h @@ -3,22 +3,21 @@ * Copyright (c) 2015 Alexander Golubev (Fat-Zer) * * Copyright (c) 2024 Ondsel (PL Boyer) * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * 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. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 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. * + * FreeCAD 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 * + * Lesser 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 * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * ***************************************************************************/ diff --git a/src/Gui/CommandStructure.cpp b/src/Gui/CommandStructure.cpp index 1b14ce5069..3e5f38ae44 100644 --- a/src/Gui/CommandStructure.cpp +++ b/src/Gui/CommandStructure.cpp @@ -156,9 +156,9 @@ void StdCmdVarSet::activated(int iMsg) // add the varset to a group if it is selected auto sels = Selection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), - ResolveMode::OldStyleElement, true); + ResolveMode::OldStyleElement, true); if (sels.size() == 1) { - App::DocumentObject *obj = sels[0].getObject(); + App::DocumentObject* obj = sels[0].getObject(); auto group = obj->getExtension(); if (group) { Gui::Document* docGui = Application::Instance->activeDocument(); diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 105076054a..c244d033a5 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -58,6 +58,7 @@ #include "ConicPy.h" #include "CustomFeature.h" #include "CylinderPy.h" +#include "Datums.h" #include "DatumFeature.h" #include "EllipsePy.h" #include "FaceMaker.h" @@ -534,6 +535,10 @@ PyMOD_INIT_FUNC(Part) Part::GeomSurfaceOfRevolution ::init(); Part::GeomSurfaceOfExtrusion ::init(); Part::Datum ::init(); + Part::DatumPlane ::init(); + Part::DatumLine ::init(); + Part::DatumPoint ::init(); + Part::LocalCoordinateSystem ::init(); // Geometry2d types Part::Geometry2d ::init(); diff --git a/src/Mod/Part/App/AttachExtension.h b/src/Mod/Part/App/AttachExtension.h index e2c3f480d1..a86abb5947 100644 --- a/src/Mod/Part/App/AttachExtension.h +++ b/src/Mod/Part/App/AttachExtension.h @@ -35,7 +35,6 @@ #include #include "Attacher.h" -#include "PartFeature.h" namespace Part diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index ecd2760d8d..71bedcac65 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -213,6 +213,8 @@ SET(Features_SRCS CustomFeature.h BodyBase.h BodyBase.cpp + Datums.cpp + Datums.h DatumFeature.cpp DatumFeature.h AttachExtension.h diff --git a/src/Mod/Part/App/Datums.cpp b/src/Mod/Part/App/Datums.cpp new file mode 100644 index 0000000000..1fd53ce669 --- /dev/null +++ b/src/Mod/Part/App/Datums.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (c) 2024 Ondsel (PL Boyer) * + * * + * 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" + +#include "Datums.h" + + +using namespace Part; +using namespace Attacher; + +PROPERTY_SOURCE_WITH_EXTENSIONS(Part::DatumPlane, App::Plane) + +Part::DatumPlane::DatumPlane() +{ + AttachExtension::initExtension(this); + this->setAttacher(new AttachEnginePlane); +} + + +PROPERTY_SOURCE_WITH_EXTENSIONS(Part::DatumLine, App::Line) + +Part::DatumLine::DatumLine() +{ + AttachExtension::initExtension(this); + this->setAttacher(new AttachEngineLine); +} + + +PROPERTY_SOURCE_WITH_EXTENSIONS(Part::DatumPoint, App::Point) + +Part::DatumPoint::DatumPoint() +{ + AttachExtension::initExtension(this); + this->setAttacher(new AttachEnginePoint); +} + + +PROPERTY_SOURCE_WITH_EXTENSIONS(Part::LocalCoordinateSystem, App::LocalCoordinateSystem) + +Part::LocalCoordinateSystem::LocalCoordinateSystem() +{ + AttachExtension::initExtension(this); +} diff --git a/src/Mod/Part/App/Datums.h b/src/Mod/Part/App/Datums.h new file mode 100644 index 0000000000..06f35c865f --- /dev/null +++ b/src/Mod/Part/App/Datums.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (c) 2024 Ondsel (PL Boyer) * + * * + * 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 PART_DATUMS_H +#define PART_DATUMS_H + +#include + +#include "AttachExtension.h" + +namespace Part +{ + +class PartExport DatumPlane : public App::Plane, public AttachExtension +{ + PROPERTY_HEADER_WITH_EXTENSIONS(Part::DatumPlane); + +public: + DatumPlane(); + ~DatumPlane() override = default; + const char* getViewProviderName() const override { + return "PartGui::ViewProviderPlane"; + } +}; + +class PartExport DatumLine : public App::Line, public AttachExtension +{ + PROPERTY_HEADER_WITH_EXTENSIONS(Part::DatumLine); + +public: + DatumLine(); + ~DatumLine() override = default; + const char* getViewProviderName() const override { + return "PartGui::ViewProviderLine"; + } +}; + +class PartExport DatumPoint : public App::Point, public AttachExtension +{ + PROPERTY_HEADER_WITH_EXTENSIONS(Part::DatumPoint); + +public: + DatumPoint(); + ~DatumPoint() override = default; + const char* getViewProviderName() const override { + return "PartGui::ViewProviderPoint"; + } +}; + +class PartExport LocalCoordinateSystem : public App::LocalCoordinateSystem, public AttachExtension +{ + PROPERTY_HEADER_WITH_EXTENSIONS(Part::LocalCoordinateSystem); + +public: + LocalCoordinateSystem(); + ~LocalCoordinateSystem() override = default; + const char* getViewProviderName() const override { + return "PartGui::ViewProviderLCS"; + } +}; + +} //namespace Part + + +#endif // PART_DATUMS_H diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index 998436403e..3c6cc8845f 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -47,6 +47,7 @@ #include "ViewProvider.h" #include "ViewProvider2DObject.h" #include "ViewProviderAttachExtension.h" +#include "ViewProviderDatum.h" #include "ViewProviderGridExtension.h" #include "ViewProviderBoolean.h" #include "ViewProviderBox.h" @@ -167,6 +168,10 @@ PyMOD_INIT_FUNC(PartGui) PartGui::ViewProviderGridExtensionPython ::init(); PartGui::ViewProviderSplineExtension ::init(); PartGui::ViewProviderSplineExtensionPython ::init(); + PartGui::ViewProviderLine ::init(); + PartGui::ViewProviderPlane ::init(); + PartGui::ViewProviderPoint ::init(); + PartGui::ViewProviderLCS ::init(); PartGui::ViewProviderPartExt ::init(); PartGui::ViewProviderPart ::init(); PartGui::ViewProviderPrimitive ::init(); diff --git a/src/Mod/Part/Gui/CMakeLists.txt b/src/Mod/Part/Gui/CMakeLists.txt index 8df4aa8cd2..cc409ada8b 100644 --- a/src/Mod/Part/Gui/CMakeLists.txt +++ b/src/Mod/Part/Gui/CMakeLists.txt @@ -164,6 +164,8 @@ SET(PartGui_SRCS ViewProvider.h ViewProviderAttachExtension.h ViewProviderAttachExtension.cpp + ViewProviderDatum.cpp + ViewProviderDatum.h ViewProviderExt.cpp ViewProviderExt.h ViewProviderReference.cpp diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index 3dee082a43..eed34ee9de 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -32,6 +32,7 @@ #endif #include +#include #include #include #include @@ -51,6 +52,8 @@ #include #include +#include + #include "BoxSelection.h" #include "CrossSections.h" #include "DlgBooleanOperation.h" @@ -2211,6 +2214,193 @@ bool CmdPartSectionCut::isActive() return hasActiveDocument(); } + +//=========================================================================== +// Part_CoordinateSystem +//=========================================================================== + +namespace { + QString getAutoGroupCommandStr() + // Helper function to get the python code to add the newly created object to the active Part/Body object if present + { + App::GeoFeature* activeObj = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); + if (!activeObj) { + activeObj = Gui::Application::Instance->activeView()->getActiveObject(PARTKEY); + } + + if (activeObj) { + QString activeName = QString::fromLatin1(activeObj->getNameInDocument()); + return QString::fromLatin1("App.ActiveDocument.getObject('%1\').addObject(obj)\n").arg(activeName); + } + + return QString::fromLatin1("# Object created at document root."); + } +} + +DEF_STD_CMD_A(CmdPartCoordinateSystem) + +CmdPartCoordinateSystem::CmdPartCoordinateSystem() + : Command("Part_CoordinateSystem") +{ + sGroup = QT_TR_NOOP("Part"); + sMenuText = QT_TR_NOOP("Create a coordinate system"); + sToolTipText = QT_TR_NOOP("A coordinate system object that can be attached to other objects."); + sWhatsThis = "Part_CoordinateSystem"; + sStatusTip = sToolTipText; + sPixmap = "Std_CoordinateSystem"; +} + +void CmdPartCoordinateSystem::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + openCommand(QT_TRANSLATE_NOOP("Command", "Add a coordinate system")); + + std::string name = getUniqueObjectName("LCS"); + doCommand(Doc, "obj = App.activeDocument().addObject('Part::LocalCoordinateSystem','%s')", name.c_str()); + doCommand(Doc, getAutoGroupCommandStr().toUtf8()); + doCommand(Doc, "obj.Visibility = True"); + doCommand(Doc, "obj.ViewObject.doubleClicked()"); +} + +bool CmdPartCoordinateSystem::isActive() +{ + return hasActiveDocument(); +} + +//=========================================================================== +// Part_Plane +//=========================================================================== +DEF_STD_CMD_A(CmdPartPlane) + +CmdPartPlane::CmdPartPlane() + : Command("Part_Plane") +{ + sGroup = QT_TR_NOOP("Part"); + sMenuText = QT_TR_NOOP("Create a datum plane"); + sToolTipText = QT_TR_NOOP("A plane object that can be attached to other objects."); + sWhatsThis = "Part_Plane"; + sStatusTip = sToolTipText; + sPixmap = "Std_Plane"; +} + +void CmdPartPlane::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + openCommand(QT_TRANSLATE_NOOP("Command", "Add a datum plane")); + + std::string name = getUniqueObjectName("Plane"); + doCommand(Doc, "obj = App.activeDocument().addObject('Part::DatumPlane','%s')", name.c_str()); + doCommand(Doc, getAutoGroupCommandStr().toUtf8()); + doCommand(Doc, "obj.ViewObject.doubleClicked()"); +} + +bool CmdPartPlane::isActive() +{ + return hasActiveDocument(); +} + +//=========================================================================== +// Part_Line +//=========================================================================== +DEF_STD_CMD_A(CmdPartLine) + +CmdPartLine::CmdPartLine() + : Command("Part_Line") +{ + sGroup = QT_TR_NOOP("Part"); + sMenuText = QT_TR_NOOP("Create a datum line"); + sToolTipText = QT_TR_NOOP("A line object that can be attached to other objects."); + sWhatsThis = "Part_Line"; + sStatusTip = sToolTipText; + sPixmap = "Std_Axis"; +} + +void CmdPartLine::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + openCommand(QT_TRANSLATE_NOOP("Command", "Add a datum line")); + + std::string name = getUniqueObjectName("Line"); + doCommand(Doc, "obj = App.activeDocument().addObject('Part::DatumLine','%s')", name.c_str()); + doCommand(Doc, getAutoGroupCommandStr().toUtf8()); + doCommand(Doc, "obj.ViewObject.doubleClicked()"); +} + +bool CmdPartLine::isActive() +{ + return hasActiveDocument(); +} + +//=========================================================================== +// Part_Point +//=========================================================================== +DEF_STD_CMD_A(CmdPartPoint) + +CmdPartPoint::CmdPartPoint() + : Command("Part_Point") +{ + sGroup = QT_TR_NOOP("Part"); + sMenuText = QT_TR_NOOP("Create a datum point"); + sToolTipText = QT_TR_NOOP("A point object that can be attached to other objects."); + sWhatsThis = "Part_Point"; + sStatusTip = sToolTipText; + sPixmap = "Std_Point"; +} + +void CmdPartPoint::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + openCommand(QT_TRANSLATE_NOOP("Command", "Add a datum point")); + + std::string name = getUniqueObjectName("Point"); + doCommand(Doc, "obj = App.activeDocument().addObject('Part::DatumPoint','%s')", name.c_str()); + doCommand(Doc, getAutoGroupCommandStr().toUtf8()); + doCommand(Doc, "obj.ViewObject.doubleClicked()"); +} + +bool CmdPartPoint::isActive() +{ + return hasActiveDocument(); +} + + +//=========================================================================== +// Part_Datums +//=========================================================================== +class CmdPartDatums : public Gui::GroupCommand +{ +public: + CmdPartDatums() + : GroupCommand("Part_Datums") + { + sGroup = QT_TR_NOOP("Part"); + sMenuText = QT_TR_NOOP("Create a datum"); + sToolTipText = QT_TR_NOOP("Create a datum object (LCS, Plane, Line, Point) that can be attached to other objects."); + sWhatsThis = "Part_Datums"; + sStatusTip = sToolTipText; + + setCheckable(false); + + addCommand("Part_CoordinateSystem"); + addCommand("Part_Plane"); + addCommand("Part_Line"); + addCommand("Part_Point"); + } + + const char* className() const override + { + return "CmdPartDatums"; + } + + bool isActive() override + { + return hasActiveDocument(); + } +}; //--------------------------------------------------------------- void CreatePartCommands() @@ -2256,4 +2446,10 @@ void CreatePartCommands() rcCmdMgr.addCommand(new CmdBoxSelection()); rcCmdMgr.addCommand(new CmdPartProjectionOnSurface()); rcCmdMgr.addCommand(new CmdPartSectionCut()); + + rcCmdMgr.addCommand(new CmdPartCoordinateSystem()); + rcCmdMgr.addCommand(new CmdPartPlane()); + rcCmdMgr.addCommand(new CmdPartLine()); + rcCmdMgr.addCommand(new CmdPartPoint()); + rcCmdMgr.addCommand(new CmdPartDatums()); } diff --git a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp index 06a2dd377a..af287a1ec5 100644 --- a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp +++ b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp @@ -113,6 +113,10 @@ void ViewProviderAttachExtension::extensionSetupContextMenu(QMenu* menu, QObject void ViewProviderAttachExtension::showAttachmentEditor() { + if (Gui::Control().activeDialog()) { + Gui::Control().closeDialog(); + } + // See PropertyEnumAttacherItem::openTask() Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); TaskDlgAttacher* task; diff --git a/src/Mod/Part/Gui/ViewProviderAttachExtension.h b/src/Mod/Part/Gui/ViewProviderAttachExtension.h index f3a1376c2d..4aaff4ec90 100644 --- a/src/Mod/Part/Gui/ViewProviderAttachExtension.h +++ b/src/Mod/Part/Gui/ViewProviderAttachExtension.h @@ -44,7 +44,6 @@ public: void extensionUpdateData(const App::Property*) override; void extensionSetupContextMenu(QMenu*, QObject*, const char*) override; -private: void showAttachmentEditor(); }; diff --git a/src/Mod/Part/Gui/ViewProviderDatum.cpp b/src/Mod/Part/Gui/ViewProviderDatum.cpp new file mode 100644 index 0000000000..6b7373d1f3 --- /dev/null +++ b/src/Mod/Part/Gui/ViewProviderDatum.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** + * Copyright (c) 2024 Ondsel (PL Boyer) * + * * + * 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 +#include +#include +#include +#include +#include +#include + +#include "ViewProviderDatum.h" + + +using namespace PartGui; + +PROPERTY_SOURCE_WITH_EXTENSIONS(PartGui::ViewProviderLine, Gui::ViewProviderLine) + +ViewProviderLine::ViewProviderLine() +{ + PartGui::ViewProviderAttachExtension::initExtension(this); +} + +bool ViewProviderLine::doubleClicked() +{ + showAttachmentEditor(); + return true; +} + +PROPERTY_SOURCE_WITH_EXTENSIONS(PartGui::ViewProviderPlane, Gui::ViewProviderPlane) + +ViewProviderPlane::ViewProviderPlane() +{ + PartGui::ViewProviderAttachExtension::initExtension(this); +} + +bool ViewProviderPlane::doubleClicked() +{ + showAttachmentEditor(); + return true; +} + + +PROPERTY_SOURCE_WITH_EXTENSIONS(PartGui::ViewProviderPoint, Gui::ViewProviderPoint) + +ViewProviderPoint::ViewProviderPoint() +{ + PartGui::ViewProviderAttachExtension::initExtension(this); +} + +bool ViewProviderPoint::doubleClicked() +{ + showAttachmentEditor(); + return true; +} + + +PROPERTY_SOURCE_WITH_EXTENSIONS(PartGui::ViewProviderLCS, Gui::ViewProviderCoordinateSystem) + +ViewProviderLCS::ViewProviderLCS() +{ + PartGui::ViewProviderAttachExtension::initExtension(this); +} + +bool ViewProviderLCS::doubleClicked() +{ + showAttachmentEditor(); + return true; +} diff --git a/src/Mod/Part/Gui/ViewProviderDatum.h b/src/Mod/Part/Gui/ViewProviderDatum.h new file mode 100644 index 0000000000..46d232e80c --- /dev/null +++ b/src/Mod/Part/Gui/ViewProviderDatum.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (c) 2024 Ondsel (PL Boyer) * + * * + * 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 PARTGUI_ViewProviderDatum_H +#define PARTGUI_ViewProviderDatum_H + +#include +#include +#include +#include +#include + +#include + +namespace PartGui { + +class PartGuiExport ViewProviderLine : public Gui::ViewProviderLine, PartGui::ViewProviderAttachExtension +{ + PROPERTY_HEADER_WITH_EXTENSIONS(PartGui::ViewProviderLine); + +public: + ViewProviderLine(); + ~ViewProviderLine() override = default; + + bool doubleClicked() override; +}; + +class PartGuiExport ViewProviderPlane : public Gui::ViewProviderPlane, PartGui::ViewProviderAttachExtension +{ + PROPERTY_HEADER_WITH_EXTENSIONS(PartGui::ViewProviderPlane); + +public: + ViewProviderPlane(); + ~ViewProviderPlane() override = default; + + bool doubleClicked() override; +}; + +class PartGuiExport ViewProviderPoint : public Gui::ViewProviderPoint, PartGui::ViewProviderAttachExtension +{ + PROPERTY_HEADER_WITH_EXTENSIONS(PartGui::ViewProviderPoint); + +public: + ViewProviderPoint(); + ~ViewProviderPoint() override = default; + + bool doubleClicked() override; +}; + +class PartGuiExport ViewProviderLCS : public Gui::ViewProviderCoordinateSystem, PartGui::ViewProviderAttachExtension +{ + PROPERTY_HEADER_WITH_EXTENSIONS(PartGui::ViewProviderLCS); + +public: + ViewProviderLCS(); + ~ViewProviderLCS() override = default; + + bool doubleClicked() override; +}; + +} // namespace PartGui + + +#endif // PARTGUI_ViewProviderDatum_H diff --git a/src/Mod/Part/Gui/WorkbenchManipulator.cpp b/src/Mod/Part/Gui/WorkbenchManipulator.cpp index b6a14976dc..eee8c4aece 100644 --- a/src/Mod/Part/Gui/WorkbenchManipulator.cpp +++ b/src/Mod/Part/Gui/WorkbenchManipulator.cpp @@ -37,6 +37,7 @@ void WorkbenchManipulator::modifyMenuBar([[maybe_unused]] Gui::MenuItem* menuBar void WorkbenchManipulator::modifyToolBars(Gui::ToolBarItem* toolBar) { addSelectionFilter(toolBar); + addDatums(toolBar); } void WorkbenchManipulator::modifyDockWindows([[maybe_unused]] Gui::DockWindowItems* dockWindow) @@ -71,3 +72,18 @@ void WorkbenchManipulator::addSelectionFilter(Gui::ToolBarItem* toolBar) } } } + +void WorkbenchManipulator::addDatums(Gui::ToolBarItem* toolBar) +{ + if (auto view = toolBar->findItem("Structure")) { + auto add = new Gui::ToolBarItem(); // NOLINT + add->setCommand("Part_Datums"); + auto item = view->findItem("Std_Group"); + if (item) { + view->insertItem(item, add); + } + else { + view->appendItem(add); + } + } +} diff --git a/src/Mod/Part/Gui/WorkbenchManipulator.h b/src/Mod/Part/Gui/WorkbenchManipulator.h index 338dd3243d..623f2cc502 100644 --- a/src/Mod/Part/Gui/WorkbenchManipulator.h +++ b/src/Mod/Part/Gui/WorkbenchManipulator.h @@ -54,6 +54,7 @@ protected: private: static void addSectionCut(Gui::MenuItem* menuBar); static void addSelectionFilter(Gui::ToolBarItem* toolBar); + static void addDatums(Gui::ToolBarItem* toolBar); }; } // namespace PartGui diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 82ce60f2af..dcc6a666cb 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -219,7 +219,9 @@ bool Body::isAllowed(const App::DocumentObject *obj) //obj->isDerivedFrom() // trouble with this line on Windows!? Linker fails to find getClassTypeId() of the Part::FeaturePython... //obj->isDerivedFrom() // allow VarSets for parameterization - obj->isDerivedFrom() + obj->isDerivedFrom() || + obj->isDerivedFrom() || + obj->isDerivedFrom() ); } diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index fc49c5f0f0..604095e3a3 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -342,11 +342,11 @@ bool ViewProviderBody::canDropObjects() const { // if the BaseFeature property is marked as hidden or read-only then // it's not allowed to modify it. - PartDesign::Body* body = getObject(); - if (body->BaseFeature.testStatus(App::Property::Status::Hidden)) - return false; - if (body->BaseFeature.testStatus(App::Property::Status::ReadOnly)) + auto* body = getObject(); + if (body->BaseFeature.testStatus(App::Property::Status::Hidden) + || body->BaseFeature.testStatus(App::Property::Status::ReadOnly)) { return false; + } return true; } @@ -355,7 +355,15 @@ bool ViewProviderBody::canDropObject(App::DocumentObject* obj) const if (obj->isDerivedFrom()) { return true; } - if (!obj->isDerivedFrom(Part::Feature::getClassTypeId())) { + else if (obj->isDerivedFrom(App::DatumElement::getClassTypeId())) { + // accept only datums that are not part of a LCS. + auto* lcs = static_cast(obj)->getLCS(); + return !lcs; + } + else if (obj->isDerivedFrom(App::LocalCoordinateSystem::getClassTypeId())) { + return !obj->isDerivedFrom(App::Origin::getClassTypeId()); + } + else if (!obj->isDerivedFrom(Part::Feature::getClassTypeId())) { return false; } else if (PartDesign::Body::findBodyOf(obj)) { @@ -375,8 +383,10 @@ bool ViewProviderBody::canDropObject(App::DocumentObject* obj) const void ViewProviderBody::dropObject(App::DocumentObject* obj) { - PartDesign::Body* body = getObject(); - if (obj->isDerivedFrom()) { + auto* body = getObject(); + if (obj->isDerivedFrom() + || obj->isDerivedFrom() + || obj->isDerivedFrom()) { body->addObject(obj); } else if (PartDesign::Body::isAllowed(obj) && PartDesignGui::isFeatureMovable(obj)) { diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp index 813257e0b4..e234245bd9 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp @@ -2,22 +2,21 @@ * Copyright (c) 2013 Jan Rheinlaender * * * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * 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. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 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. * + * FreeCAD 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 * + * Lesser 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 * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * ***************************************************************************/ diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatum.h b/src/Mod/PartDesign/Gui/ViewProviderDatum.h index 8187d00ab2..07f5a86765 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatum.h +++ b/src/Mod/PartDesign/Gui/ViewProviderDatum.h @@ -2,22 +2,21 @@ * Copyright (c) 2013 Jan Rheinlaender * * * * * - * This file is part of the FreeCAD CAx development system. * + * This file is part of FreeCAD. * * * - * 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. * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 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. * + * FreeCAD 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 * + * Lesser 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 * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * * * ***************************************************************************/