From 7ff4da5a274212ac7bb4b8ae4e02f5d5c13ded8e Mon Sep 17 00:00:00 2001 From: hlorus <64740362+hlorus@users.noreply.github.com> Date: Mon, 22 Apr 2024 08:11:21 +0200 Subject: [PATCH] [Part/PD] Remove measure tools --- src/Mod/Part/Gui/AppPartGui.cpp | 6 - src/Mod/Part/Gui/CMakeLists.txt | 9 - src/Mod/Part/Gui/Command.cpp | 227 --- src/Mod/Part/Gui/DlgSettingsMeasure.cpp | 91 - src/Mod/Part/Gui/DlgSettingsMeasure.h | 58 - src/Mod/Part/Gui/DlgSettingsMeasure.ui | 279 --- src/Mod/Part/Gui/Resources/Part.qrc | 9 - .../icons/measure/Part_Measure_Angular.svg | 215 -- .../icons/measure/Part_Measure_Linear.svg | 135 -- .../icons/measure/Part_Measure_Refresh.svg | 659 ------ .../measure/Part_Measure_Step_Active.svg | 128 -- .../icons/measure/Part_Measure_Step_Done.svg | 113 -- .../icons/measure/Part_Measure_Toggle_3D.svg | 150 -- .../measure/Part_Measure_Toggle_Delta.svg | 143 -- src/Mod/Part/Gui/TaskDimension.cpp | 1783 ----------------- src/Mod/Part/Gui/TaskDimension.h | 337 ---- src/Mod/Part/Gui/Workbench.cpp | 24 - src/Mod/Part/Gui/WorkbenchManipulator.cpp | 16 - src/Mod/Part/Gui/WorkbenchManipulator.h | 7 - src/Mod/PartDesign/Gui/Workbench.cpp | 27 - 20 files changed, 4416 deletions(-) delete mode 100644 src/Mod/Part/Gui/DlgSettingsMeasure.cpp delete mode 100644 src/Mod/Part/Gui/DlgSettingsMeasure.h delete mode 100644 src/Mod/Part/Gui/DlgSettingsMeasure.ui delete mode 100644 src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Angular.svg delete mode 100644 src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Linear.svg delete mode 100644 src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Refresh.svg delete mode 100644 src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Step_Active.svg delete mode 100644 src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Step_Done.svg delete mode 100644 src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Toggle_3D.svg delete mode 100644 src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Toggle_Delta.svg delete mode 100644 src/Mod/Part/Gui/TaskDimension.cpp delete mode 100644 src/Mod/Part/Gui/TaskDimension.h diff --git a/src/Mod/Part/Gui/AppPartGui.cpp b/src/Mod/Part/Gui/AppPartGui.cpp index 4aef8a4efe..a1895fe0e9 100644 --- a/src/Mod/Part/Gui/AppPartGui.cpp +++ b/src/Mod/Part/Gui/AppPartGui.cpp @@ -39,9 +39,7 @@ #include "PropertyEnumAttacherItem.h" #include "DlgSettings3DViewPartImp.h" #include "DlgSettingsGeneral.h" -#include "DlgSettingsMeasure.h" #include "DlgSettingsObjectColor.h" -#include "TaskDimension.h" #include "SoBrepEdgeSet.h" #include "SoBrepFaceSet.h" #include "SoBrepPointSet.h" @@ -136,7 +134,6 @@ PyMOD_INIT_FUNC(PartGui) Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/booleans")); Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/create")); - Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/measure")); Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/parametric")); Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/tools")); @@ -212,8 +209,6 @@ PyMOD_INIT_FUNC(PartGui) PartGui::ViewProviderRuledSurface ::init(); PartGui::ViewProviderFace ::init(); PartGui::ViewProviderProjectOnSurface ::init(); - PartGui::DimensionLinear ::initClass(); - PartGui::DimensionAngular ::initClass(); PartGui::Workbench ::init(); auto manip = std::make_shared(); @@ -237,7 +232,6 @@ PyMOD_INIT_FUNC(PartGui) (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); - (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Part/Part Design")); (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Import-Export")); (void)new Gui::PrefPageProducer(QT_TRANSLATE_NOOP("QObject", "Import-Export")); Gui::ViewProviderBuilder::add( diff --git a/src/Mod/Part/Gui/CMakeLists.txt b/src/Mod/Part/Gui/CMakeLists.txt index 7cdd529d43..9475aa01fd 100644 --- a/src/Mod/Part/Gui/CMakeLists.txt +++ b/src/Mod/Part/Gui/CMakeLists.txt @@ -57,7 +57,6 @@ set(PartGui_UIC_SRCS DlgRevolution.ui DlgSettings3DViewPart.ui DlgSettingsGeneral.ui - DlgSettingsMeasure.ui DlgSettingsObjectColor.ui DlgProjectionOnSurface.ui SectionCutting.ui @@ -133,15 +132,9 @@ SET(PartGui_SRCS DlgSettingsGeneral.cpp DlgSettingsGeneral.h DlgSettingsGeneral.ui - DlgSettingsMeasure.cpp - DlgSettingsMeasure.h - DlgSettingsMeasure.ui DlgSettingsObjectColor.cpp DlgSettingsObjectColor.h DlgSettingsObjectColor.ui - DlgSettingsMeasure.cpp - DlgSettingsMeasure.h - DlgSettingsMeasure.ui DlgProjectionOnSurface.cpp DlgProjectionOnSurface.h DlgProjectionOnSurface.ui @@ -248,8 +241,6 @@ SET(PartGui_SRCS TaskSweep.ui TaskThickness.cpp TaskThickness.h - TaskDimension.cpp - TaskDimension.h TaskCheckGeometry.cpp TaskCheckGeometry.h TaskAttacher.h diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index 0821411a01..422daa40da 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -63,7 +63,6 @@ #include "Mirroring.h" #include "SectionCutting.h" #include "TaskCheckGeometry.h" -#include "TaskDimension.h" #include "TaskLoft.h" #include "TaskShapeBuilder.h" #include "TaskSweep.h" @@ -2123,225 +2122,6 @@ bool CmdColorPerFace::isActive() return (hasActiveDocument() && !Gui::Control().activeDialog() && objectSelected); } -//=========================================================================== -// Part_Measure_Linear -//=========================================================================== - -DEF_STD_CMD_A(CmdMeasureLinear) - -CmdMeasureLinear::CmdMeasureLinear() - : Command("Part_Measure_Linear") -{ - sAppModule = "Part"; - sGroup = QT_TR_NOOP("Part"); - sMenuText = QT_TR_NOOP("Measure Linear"); - sToolTipText = QT_TR_NOOP("Measure the linear distance between two points;\n" - "if edges or faces are picked, it will measure\n" - "between two vertices of them."); - sWhatsThis = "Part_Measure_Linear"; - sStatusTip = sToolTipText; - sPixmap = "Part_Measure_Linear"; -} - -void CmdMeasureLinear::activated(int iMsg) -{ - Q_UNUSED(iMsg); - PartGui::goDimensionLinearRoot(); -} - -bool CmdMeasureLinear::isActive() -{ - return hasActiveDocument(); -} - -//=========================================================================== -// Part_Measure_Angular -//=========================================================================== - -DEF_STD_CMD_A(CmdMeasureAngular) - -CmdMeasureAngular::CmdMeasureAngular() - : Command("Part_Measure_Angular") -{ - sAppModule = "Part"; - sGroup = QT_TR_NOOP("Part"); - sMenuText = QT_TR_NOOP("Measure Angular"); - sToolTipText = QT_TR_NOOP("Measure the angle between two edges."); - sWhatsThis = "Part_Measure_Angular"; - sStatusTip = sToolTipText; - sPixmap = "Part_Measure_Angular"; -} - -void CmdMeasureAngular::activated(int iMsg) -{ - Q_UNUSED(iMsg); - PartGui::goDimensionAngularRoot(); -} - -bool CmdMeasureAngular::isActive() -{ - return hasActiveDocument(); -} - -//=========================================================================== -// Part_Measure_Refresh -//=========================================================================== - -DEF_STD_CMD_A(CmdMeasureRefresh) - -CmdMeasureRefresh::CmdMeasureRefresh() - : Command("Part_Measure_Refresh") -{ - sAppModule = "Part"; - sGroup = QT_TR_NOOP("Part"); - sMenuText = QT_TR_NOOP("Refresh"); - sToolTipText = QT_TR_NOOP("Recalculate the dimensions\n" - "if the measured points have moved."); - sWhatsThis = "Part_Measure_Refresh"; - sStatusTip = sToolTipText; - sPixmap = "Part_Measure_Refresh"; -} - -void CmdMeasureRefresh::activated(int iMsg) -{ - Q_UNUSED(iMsg); - PartGui::refreshDimensions(); -} - -bool CmdMeasureRefresh::isActive() -{ - return hasActiveDocument(); -} - -//=========================================================================== -// Part_Measure_Clear_All -//=========================================================================== - -DEF_STD_CMD_A(CmdMeasureClearAll) - -CmdMeasureClearAll::CmdMeasureClearAll() - : Command("Part_Measure_Clear_All") -{ - sAppModule = "Part"; - sGroup = QT_TR_NOOP("Part"); - sMenuText = QT_TR_NOOP("Clear All"); - sToolTipText = QT_TR_NOOP("Clear all dimensions from the active 3D view."); - sWhatsThis = "Part_Measure_Clear_All"; - sStatusTip = sToolTipText; - sPixmap = "Part_Measure_Clear_All"; -} - -void CmdMeasureClearAll::activated(int iMsg) -{ - Q_UNUSED(iMsg); - PartGui::eraseAllDimensions(); -} - -bool CmdMeasureClearAll::isActive() -{ - return hasActiveDocument(); -} - -//=========================================================================== -// Part_Measure_Toggle_All -//=========================================================================== - -DEF_STD_CMD_A(CmdMeasureToggleAll) - -CmdMeasureToggleAll::CmdMeasureToggleAll() - : Command("Part_Measure_Toggle_All") -{ - sAppModule = "Part"; - sGroup = QT_TR_NOOP("Part"); - sMenuText = QT_TR_NOOP("Toggle All"); - sToolTipText = QT_TR_NOOP("Toggle on and off " - "all currently visible dimensions,\n" - "direct, orthogonal, and angular."); - sWhatsThis = "Part_Measure_Toggle_All"; - sStatusTip = sToolTipText; - sPixmap = "Part_Measure_Toggle_All"; -} - -void CmdMeasureToggleAll::activated(int iMsg) -{ - Q_UNUSED(iMsg); - ParameterGrp::handle group = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("View"); - bool visibility = group->GetBool("DimensionsVisible", true); - if (visibility) - group->SetBool("DimensionsVisible", false); - else - group->SetBool("DimensionsVisible", true); -} - -bool CmdMeasureToggleAll::isActive() -{ - return hasActiveDocument(); -} - -//=========================================================================== -// Part_Measure_Toggle_3D -//=========================================================================== - -DEF_STD_CMD_A(CmdMeasureToggle3d) - -CmdMeasureToggle3d::CmdMeasureToggle3d() - : Command("Part_Measure_Toggle_3D") -{ - sAppModule = "Part"; - sGroup = QT_TR_NOOP("Part"); - sMenuText = QT_TR_NOOP("Toggle 3D"); - sToolTipText = QT_TR_NOOP("Toggle on and off " - "all direct dimensions,\n" - "including angular."); - sWhatsThis = "Part_Measure_Toggle_3D"; - sStatusTip = sToolTipText; - sPixmap = "Part_Measure_Toggle_3D"; -} - -void CmdMeasureToggle3d::activated(int iMsg) -{ - Q_UNUSED(iMsg); - PartGui::toggle3d(); -} - -bool CmdMeasureToggle3d::isActive() -{ - return hasActiveDocument(); -} - -//=========================================================================== -// Part_Measure_Toggle_Delta -//=========================================================================== - -DEF_STD_CMD_A(CmdMeasureToggleDelta) - -CmdMeasureToggleDelta::CmdMeasureToggleDelta() - : Command("Part_Measure_Toggle_Delta") -{ - sAppModule = "Part"; - sGroup = QT_TR_NOOP("Part"); - sMenuText = QT_TR_NOOP("Toggle Delta"); - sToolTipText = QT_TR_NOOP("Toggle on and off " - "all orthogonal dimensions,\n" - "meaning that a direct dimension will be decomposed\n" - "into its X, Y, and Z components."); - sWhatsThis = "Part_Measure_Toggle_Delta"; - sStatusTip = sToolTipText; - sPixmap = "Part_Measure_Toggle_Delta"; -} - -void CmdMeasureToggleDelta::activated(int iMsg) -{ - Q_UNUSED(iMsg); - PartGui::toggleDelta(); -} - -bool CmdMeasureToggleDelta::isActive() -{ - return hasActiveDocument(); -} - //=========================================================================== // Part_BoxSelection //=========================================================================== @@ -2486,13 +2266,6 @@ void CreatePartCommands() rcCmdMgr.addCommand(new CmdPartThickness()); rcCmdMgr.addCommand(new CmdCheckGeometry()); rcCmdMgr.addCommand(new CmdColorPerFace()); - rcCmdMgr.addCommand(new CmdMeasureLinear()); - rcCmdMgr.addCommand(new CmdMeasureAngular()); - rcCmdMgr.addCommand(new CmdMeasureRefresh()); - rcCmdMgr.addCommand(new CmdMeasureClearAll()); - rcCmdMgr.addCommand(new CmdMeasureToggleAll()); - rcCmdMgr.addCommand(new CmdMeasureToggle3d()); - rcCmdMgr.addCommand(new CmdMeasureToggleDelta()); rcCmdMgr.addCommand(new CmdBoxSelection()); rcCmdMgr.addCommand(new CmdPartProjectionOnSurface()); rcCmdMgr.addCommand(new CmdPartSectionCut()); diff --git a/src/Mod/Part/Gui/DlgSettingsMeasure.cpp b/src/Mod/Part/Gui/DlgSettingsMeasure.cpp deleted file mode 100644 index 7034473b74..0000000000 --- a/src/Mod/Part/Gui/DlgSettingsMeasure.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2022 * - * * - * 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 - -#include "DlgSettingsMeasure.h" -#include "ui_DlgSettingsMeasure.h" - - -using namespace PartGui; - -DlgSettingsMeasure::DlgSettingsMeasure(QWidget* parent) - : PreferencePage(parent) , ui(new Ui_DlgSettingsMeasure) -{ - ui->setupUi(this); - connect(ui->pushButtonRefresh, &QPushButton::clicked, this, &DlgSettingsMeasure::onMeasureRefresh); -} - -/** - * Destroys the object and frees any allocated resources - */ -DlgSettingsMeasure::~DlgSettingsMeasure() = default; - -void DlgSettingsMeasure::saveSettings() -{ - ui->dim3dColorButton->onSave(); - ui->dimDeltaColorButton->onSave(); - ui->dimAngularColorButton->onSave(); - - ui->fontSizeSpinBox->onSave(); - ui->fontNameComboBox->onSave(); - - ui->fontStyleBoldCheckBox->onSave(); - ui->fontStyleItalicCheckBox->onSave(); -} - -void DlgSettingsMeasure::loadSettings() -{ - ui->dim3dColorButton->onRestore(); - ui->dimDeltaColorButton->onRestore(); - ui->dimAngularColorButton->onRestore(); - - ui->fontSizeSpinBox->onRestore(); - ui->fontNameComboBox->onRestore(); - ui->fontNameComboBox->addItems(QStringList({QString::fromUtf8("defaultFont")})); - - ui->fontStyleBoldCheckBox->onRestore(); - ui->fontStyleItalicCheckBox->onRestore(); -} - -/** - * Sets the strings of the subwidgets using the current language. - */ -void DlgSettingsMeasure::changeEvent(QEvent *e) -{ - if (e->type() == QEvent::LanguageChange) { - ui->retranslateUi(this); - } - else { - QWidget::changeEvent(e); - } -} - -void DlgSettingsMeasure::onMeasureRefresh() -{ - DlgSettingsMeasure::saveSettings(); - Gui::Command::runCommand(Gui::Command::Gui, "Gui.runCommand('Part_Measure_Refresh',0)"); -} - -#include "moc_DlgSettingsMeasure.cpp" diff --git a/src/Mod/Part/Gui/DlgSettingsMeasure.h b/src/Mod/Part/Gui/DlgSettingsMeasure.h deleted file mode 100644 index 2f347ef2c2..0000000000 --- a/src/Mod/Part/Gui/DlgSettingsMeasure.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2022 * - * * - * 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_DIALOG_DLGSETTINGSMEASURE_H -#define PARTGUI_DIALOG_DLGSETTINGSMEASURE_H - -#include -#include - -namespace PartGui { -class Ui_DlgSettingsMeasure; - -/** - * The DlgSettingsMeasure class implements a preference page to change color - * and font settings for Measure Dimensions - */ -class DlgSettingsMeasure : public Gui::Dialog::PreferencePage -{ - Q_OBJECT - -public: - explicit DlgSettingsMeasure(QWidget* parent = nullptr); - ~DlgSettingsMeasure() override; - - void saveSettings() override; - void loadSettings() override; - -protected: - void changeEvent(QEvent *e) override; - -private: - std::unique_ptr ui; - void onMeasureRefresh(); -}; - -} // namespace PartGui - -#endif // PARTGUI_DIALOG_DLGSETTINGSMEASURE_H diff --git a/src/Mod/Part/Gui/DlgSettingsMeasure.ui b/src/Mod/Part/Gui/DlgSettingsMeasure.ui deleted file mode 100644 index 27ce62964d..0000000000 --- a/src/Mod/Part/Gui/DlgSettingsMeasure.ui +++ /dev/null @@ -1,279 +0,0 @@ - - - PartGui::DlgSettingsMeasure - - - - 0 - 0 - 400 - 282 - - - - - 0 - 0 - - - - Measure - - - - - - Measurement settings - - - - - - - - - 255 - 0 - 0 - - - - Dimensions3dColor - - - Mod/Part - - - - - - - 3D color - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 255 - 0 - - - - DimensionsDeltaColor - - - Mod/Part - - - - - - - Delta color - - - - - - - - 0 - 0 - 255 - - - - DimensionsAngularColor - - - Mod/Part - - - - - - - Angular color - - - - - - - - - - - - - - - 80 - 28 - - - - 30 - - - DimensionsFontSize - - - Mod/Part - - - - - - - Font size - - - - - - - - 75 - true - - - - Bold - - - DimensionsFontStyleBold - - - Mod/Part - - - - - - - - true - - - - Italic - - - DimensionsFontStyleItalic - - - Mod/Part - - - - - - - defaultFont - - - DimensionsFontName - - - Mod/Part - - - - - - - Font name - - - - - - - - - - - Refresh existing measurements - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Gui::ColorButton - QPushButton -
Gui/Widgets.h
-
- - Gui::PrefSpinBox - QSpinBox -
Gui/PrefWidgets.h
-
- - Gui::PrefColorButton - Gui::ColorButton -
Gui/PrefWidgets.h
-
- - Gui::PrefCheckBox - QCheckBox -
Gui/PrefWidgets.h
-
- - Gui::PrefFontBox - QFontComboBox -
Gui/PrefWidgets.h
-
-
- - -
diff --git a/src/Mod/Part/Gui/Resources/Part.qrc b/src/Mod/Part/Gui/Resources/Part.qrc index ffde8218b6..e4b86645ea 100644 --- a/src/Mod/Part/Gui/Resources/Part.qrc +++ b/src/Mod/Part/Gui/Resources/Part.qrc @@ -30,15 +30,6 @@ icons/create/Part_Torus.svg icons/create/Part_Tube.svg - - icons/measure/Part_Measure_Angular.svg - icons/measure/Part_Measure_Linear.svg - icons/measure/Part_Measure_Refresh.svg - icons/measure/Part_Measure_Step_Active.svg - icons/measure/Part_Measure_Step_Done.svg - icons/measure/Part_Measure_Toggle_3D.svg - icons/measure/Part_Measure_Toggle_Delta.svg - icons/parametric/Part_Box_Parametric.svg icons/parametric/Part_Circle_Parametric.svg diff --git a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Angular.svg b/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Angular.svg deleted file mode 100644 index f0ffba950b..0000000000 --- a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Angular.svg +++ /dev/null @@ -1,215 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - [blobfish] - - - Part_Measure_Angular - 2013-12-17 - https://www.freecad.org/wiki/index.php?title=Artwork - - - FreeCAD - - - FreeCAD/src/Mod/Part/Gui/Resources/icons/Part_Measure_Angular.svg - - - FreeCAD LGPL2+ - - - https://www.gnu.org/copyleft/lesser.html - - - [agryson] Alexander Gryson - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Linear.svg b/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Linear.svg deleted file mode 100644 index bde7662177..0000000000 --- a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Linear.svg +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - [blobfish] - - - Part_Measure_Linear - 2013-12-17 - https://www.freecad.org/wiki/index.php?title=Artwork - - - FreeCAD - - - FreeCAD/src/Mod/Part/Gui/Resources/icons/Part_Measure_Linear.svg - - - FreeCAD LGPL2+ - - - https://www.gnu.org/copyleft/lesser.html - - - [agryson] Alexander Gryson - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Refresh.svg b/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Refresh.svg deleted file mode 100644 index b4b78f6d91..0000000000 --- a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Refresh.svg +++ /dev/null @@ -1,659 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - [blobfish] - - - Part_Measure_Linear - 2013-12-17 - https://www.freecad.org/wiki/index.php?title=Artwork - - - FreeCAD - - - FreeCAD/src/Mod/Part/Gui/Resources/icons/Part_Measure_Linear.svg - - - FreeCAD LGPL2+ - - - https://www.gnu.org/copyleft/lesser.html - - - [agryson] Alexander Gryson - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Step_Active.svg b/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Step_Active.svg deleted file mode 100644 index a52ce279de..0000000000 --- a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Step_Active.svg +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - [blobfish] - - - Part_Measure_Step_Active - 2013-12-17 - https://www.freecad.org/wiki/index.php?title=Artwork - - - FreeCAD - - - FreeCAD/src/Mod/Part/Gui/Resources/icons/Part_Measure_Step_Active.svg - - - FreeCAD LGPL2+ - - - https://www.gnu.org/copyleft/lesser.html - - - [agryson] Alexander Gryson - - - - - - - - - - - - - - - diff --git a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Step_Done.svg b/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Step_Done.svg deleted file mode 100644 index e9edc1e744..0000000000 --- a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Step_Done.svg +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - [blobfish] - - - Part_Measure_Step_Done - 2013-12-17 - https://www.freecad.org/wiki/index.php?title=Artwork - - - FreeCAD - - - FreeCAD/src/Mod/Part/Gui/Resources/icons/Part_Measure_Step_Done.svg - - - FreeCAD LGPL2+ - - - https://www.gnu.org/copyleft/lesser.html - - - [agryson] Alexander Gryson - - - - - - - - - - - - - diff --git a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Toggle_3D.svg b/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Toggle_3D.svg deleted file mode 100644 index a74d1c11bc..0000000000 --- a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Toggle_3D.svg +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - [blobfish] - - - Part_Measure_Toggle_3d - 2013-12-17 - https://www.freecad.org/wiki/index.php?title=Artwork - - - FreeCAD - - - FreeCAD/src/Mod/Part/Gui/Resources/icons/Part_Measure_Toggle_3d.svg - - - FreeCAD LGPL2+ - - - https://www.gnu.org/copyleft/lesser.html - - - [agryson] Alexander Gryson - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Toggle_Delta.svg b/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Toggle_Delta.svg deleted file mode 100644 index 4d9f791774..0000000000 --- a/src/Mod/Part/Gui/Resources/icons/measure/Part_Measure_Toggle_Delta.svg +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - [blobfish] - - - Part_Measure_Toggle_Delta - 2013-12-17 - https://www.freecad.org/wiki/index.php?title=Artwork - - - FreeCAD - - - FreeCAD/src/Mod/Part/Gui/Resources/icons/Part_Measure_Toggle_Delta.svg - - - FreeCAD LGPL2+ - - - https://www.gnu.org/copyleft/lesser.html - - - [agryson] Alexander Gryson - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Mod/Part/Gui/TaskDimension.cpp b/src/Mod/Part/Gui/TaskDimension.cpp deleted file mode 100644 index aba9cff004..0000000000 --- a/src/Mod/Part/Gui/TaskDimension.cpp +++ /dev/null @@ -1,1783 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Thomas Anderson * - * * - * 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 _PreCpmp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -# include -# include -# include -# include -# include - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "TaskDimension.h" - - -namespace sp = std::placeholders; - -static bool _MeasureInfoInited; - -static void slotDeleteDocument(const App::Document &doc); - -struct MeasureInfo { - PartGui::DimSelections sel1; - PartGui::DimSelections sel2; - bool linear; - MeasureInfo(const PartGui::DimSelections &sel1, const PartGui::DimSelections &sel2, bool linear) - :sel1(sel1),sel2(sel2),linear(linear) - { - if(!_MeasureInfoInited) { - _MeasureInfoInited = true; - //NOLINTBEGIN - App::GetApplication().signalDeleteDocument.connect(std::bind(slotDeleteDocument, sp::_1)); - //NOLINTEND - } - } -}; -static std::map > _Measures; - -static void slotDeleteDocument(const App::Document &doc) { - _Measures.erase(doc.getName()); -} - -bool PartGui::getShapeFromStrings(TopoDS_Shape &shapeOut, const std::string &doc, const std::string &object, const std::string &sub, Base::Matrix4D *mat) -{ - App::Document *docPointer = App::GetApplication().getDocument(doc.c_str()); - if (!docPointer) - return false; - App::DocumentObject *objectPointer = docPointer->getObject(object.c_str()); - if (!objectPointer) - return false; - shapeOut = Part::Feature::getShape(objectPointer,sub.c_str(),true,mat); - if (shapeOut.IsNull()) - return false; - return true; -} - -bool PartGui::evaluateLinearPreSelection(TopoDS_Shape &shape1, TopoDS_Shape &shape2) -{ - std::vector selections = Gui::Selection().getSelection(nullptr, Gui::ResolveMode::NoResolve); - if (selections.size() != 2) - return false; - std::vector::iterator it; - std::vector shapes; - DimSelections sels[2]; - - int i=0; - for (it = selections.begin(); it != selections.end(); ++it) - { - TopoDS_Shape shape = Part::Feature::getShape(it->pObject,it->SubName,true); - if (shape.IsNull()) - break; - shapes.push_back(shape); - sels[i].selections.emplace_back(); - auto &sel = sels[i].selections[0]; - ++i; - sel.documentName = it->DocName; - sel.objectName = it->FeatName; - sel.subObjectName = it->SubName; - } - - if (shapes.size() != 2) - return false; - - shape1 = shapes.front(); - shape2 = shapes.back(); - - auto doc = App::GetApplication().getActiveDocument(); - if(doc) - _Measures[doc->getName()].emplace_back(sels[0],sels[1],true); - return true; -} - -void PartGui::goDimensionLinearRoot() -{ - PartGui::ensureSomeDimensionVisible(); - - TopoDS_Shape shape1, shape2; - if(evaluateLinearPreSelection(shape1, shape2)) - { - goDimensionLinearNoTask(shape1, shape2); - Gui::Selection().clearSelection(); - } - else - { - Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); - if (!dlg) - { - Gui::Selection().clearSelection(); - dlg = new PartGui::TaskMeasureLinear(); - } - Gui::Control().showDialog(dlg); - } -} - -void PartGui::goDimensionLinearNoTask(const TopoDS_Shape &shape1, const TopoDS_Shape &shape2) -{ - //Warning: BRepExtrema_DistShapeShape solution array is NOT 0 based. - BRepExtrema_DistShapeShape measure(shape1, shape2); - if (!measure.IsDone() || measure.NbSolution() < 1) - return; - - dumpLinearResults(measure); - addLinearDimensions(measure); - - //if we ever make this a class add viewer to member. - Gui::View3DInventorViewer *viewer = getViewer(); - if (!viewer) - return; -} - -void PartGui::dumpLinearResults(const BRepExtrema_DistShapeShape &measure) -{ - std::ostringstream out; - //switch to initializer list when switch to c++11 - std::vector typeNames; - typeNames.resize(3); - typeNames[0] = "Vertex"; - typeNames[1] = "Edge"; - typeNames[2] = "Face"; - - Base::Quantity quantity(measure.Value(), Base::Unit::Length); - out << std::endl<< std::setprecision(std::numeric_limits::digits10 + 1) << "distance = " << - measure.Value() << "mm unit distance = " << quantity.getUserString().toUtf8().constData() << std::endl << - "solution count: " << measure.NbSolution() << std::endl; - - for (int index = 1; index < measure.NbSolution() + 1; ++index) //not zero based. - { - gp_Pnt point1 = measure.PointOnShape1(index); - gp_Pnt point2 = measure.PointOnShape2(index); - out << " solution " << index << ":" << std::endl << std::setprecision(std::numeric_limits::digits10 + 1) << - " point1 " << point1.X() << " " << point1.Y() << " " << point1.Z() << std::endl << - " point2 " << point2.X() << " " << point2.Y() << " " << point2.Z() << std::endl << - " DeltaX " << fabs(point2.X() - point1.X()) << std::endl << - " DeltaY " << fabs(point2.Y() - point1.Y()) << std::endl << - " DeltaZ " << fabs(point2.Z() - point1.Z()) << std::endl << - " shape type on object1 is: " << typeNames.at(measure.SupportTypeShape1(index)) << std::endl << - " shape type on object2 is: " << typeNames.at(measure.SupportTypeShape2(index)) << std::endl; - } - out << std::endl; - Base::Console().Message(out.str().c_str()); -} - -auto PartGui::getDimensionsFontName() -{ - ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/Mod/Part"); - std::string fontName = group->GetASCII("DimensionsFontName", "defaultFont"); - // if there is only italic, we must output ":Italic", otherwise ":Bold Italic" - if (group->GetBool("DimensionsFontStyleBold")) { - fontName = fontName + " :Bold"; - if (group->GetBool("DimensionsFontStyleItalic")) - fontName = fontName + " Italic"; - } - else { - if (group->GetBool("DimensionsFontStyleItalic")) - fontName = fontName + " :Italic"; - } - return fontName; -} - -auto PartGui::getDimensionsFontSize() -{ - ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/Mod/Part"); - return group->GetInt("DimensionsFontSize", 30); -} - -Gui::View3DInventorViewer * PartGui::getViewer() -{ - Gui::Document *doc = Gui::Application::Instance->activeDocument(); - if (!doc) - return nullptr; - Gui::View3DInventor *view = dynamic_cast(doc->getActiveView()); - if (!view) - return nullptr; - Gui::View3DInventorViewer *viewer = view->getViewer(); - if (!viewer) - return nullptr; - return viewer; -} - -void PartGui::addLinearDimensions(const BRepExtrema_DistShapeShape &measure) -{ - ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/Mod/Part"); - App::Color c((uint32_t) group->GetUnsigned("Dimensions3dColor", 0xFF000000)); - App::Color d((uint32_t) group->GetUnsigned("DimensionsDeltaColor", 0x00FF0000)); - - Gui::View3DInventorViewer *viewer = getViewer(); - if (!viewer) - return; - gp_Pnt point1 = measure.PointOnShape1(1); - gp_Pnt point2 = measure.PointOnShape2(1); - viewer->addDimension3d(createLinearDimension(point1, point2, SbColor(c.r, c.g, c.b))); - - //create deltas. point1 will always be the same. - gp_Pnt temp = point1; - gp_Pnt lastTemp = temp; - temp.SetX(point2.X()); - viewer->addDimensionDelta(createLinearDimension(lastTemp, temp, SbColor(d.r, d.g, d.b))); - lastTemp = temp; - temp.SetY(point2.Y()); - viewer->addDimensionDelta(createLinearDimension(lastTemp, temp, SbColor(d.r, d.g, d.b))); - lastTemp = temp; - temp.SetZ(point2.Z()); - viewer->addDimensionDelta(createLinearDimension(lastTemp, temp, SbColor(d.r, d.g, d.b))); -} - -SoNode* PartGui::createLinearDimension(const gp_Pnt &point1, const gp_Pnt &point2, const SbColor &color) -{ - SbVec3f vec1(point1.X(), point1.Y(), point1.Z()); - SbVec3f vec2(point2.X(), point2.Y(), point2.Z()); - if ((vec2-vec1).length() < FLT_EPSILON) - return new SoSeparator(); //empty object. - PartGui::DimensionLinear *dimension = new PartGui::DimensionLinear(); - dimension->point1.setValue(vec1); - dimension->point2.setValue(vec2); - dimension->setupDimension(); - - Base::Quantity quantity(static_cast((vec2-vec1).length()), Base::Unit::Length); - dimension->text.setValue(quantity.getUserString().toUtf8().constData()); - - dimension->dColor.setValue(color); - return dimension; -} - -void PartGui::eraseAllDimensions() -{ - Gui::Document *doc = Gui::Application::Instance->activeDocument(); - if (!doc) - return; - _Measures.erase(doc->getDocument()->getName()); - Gui::View3DInventor *view = dynamic_cast(doc->getActiveView()); - if (!view) - return; - Gui::View3DInventorViewer *viewer = view->getViewer(); - if (!viewer) - return; - viewer->eraseAllDimensions(); -} - -void PartGui::refreshDimensions() { - auto doc = App::GetApplication().getActiveDocument(); - if(!doc) - return; - auto it = _Measures.find(doc->getName()); - if(it == _Measures.end()) - return; - std::list measures; - measures.swap(it->second); - eraseAllDimensions(); - for(auto &info : measures) { - if(info.linear) - PartGui::TaskMeasureLinear::buildDimension(info.sel1,info.sel2); - else - PartGui::TaskMeasureAngular::buildDimension(info.sel1,info.sel2); - } -} - -void PartGui::toggle3d() -{ - ParameterGrp::handle group = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("View"); - bool visibility = group->GetBool("Dimensions3dVisible", true); - if (visibility) - group->SetBool("Dimensions3dVisible", false); - else - group->SetBool("Dimensions3dVisible", true); -} - -void PartGui::toggleDelta() -{ - ParameterGrp::handle group = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("View"); - bool visibility = group->GetBool("DimensionsDeltaVisible", true); - if (visibility) - group->SetBool("DimensionsDeltaVisible", false); - else - group->SetBool("DimensionsDeltaVisible", true); -} - -void PartGui::ensureSomeDimensionVisible() -{ - ParameterGrp::handle group = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("View"); - bool visibilityAll = group->GetBool("DimensionsVisible", true); - if (!visibilityAll) - group->SetBool("DimensionsVisible", true); - bool visibility3d = group->GetBool("Dimensions3dVisible", true); - bool visibilityDelta = group->GetBool("DimensionsDeltaVisible", true); - - if (!visibility3d && !visibilityDelta) //both turned off. - group->SetBool("Dimensions3dVisible", true); //turn on 3d, so something is visible. -} - -void PartGui::ensure3dDimensionVisible() -{ - ParameterGrp::handle group = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("View"); - bool visibilityAll = group->GetBool("DimensionsVisible", true); - if (!visibilityAll) - group->SetBool("DimensionsVisible", true); - bool visibility3d = group->GetBool("Dimensions3dVisible", true); - - if (!visibility3d) //both turned off. - group->SetBool("Dimensions3dVisible", true); //turn on 3d, so something is visible. -} - - -SO_KIT_SOURCE(PartGui::DimensionLinear) - -void PartGui::DimensionLinear::initClass() -{ - SO_KIT_INIT_CLASS(DimensionLinear, SoSeparatorKit, "SeparatorKit"); -} - -PartGui::DimensionLinear::DimensionLinear() -{ - SO_KIT_CONSTRUCTOR(PartGui::DimensionLinear); - - SO_KIT_ADD_CATALOG_ENTRY(transformation, SoTransform, true, topSeparator,"" , true); - SO_KIT_ADD_CATALOG_ENTRY(annotate, SoAnnotation, true, topSeparator,"" , true); - SO_KIT_ADD_CATALOG_ENTRY(leftArrow, SoShapeKit, true, topSeparator,"" ,true); - SO_KIT_ADD_CATALOG_ENTRY(rightArrow, SoShapeKit, true, topSeparator,"" ,true); - SO_KIT_ADD_CATALOG_ENTRY(line, SoShapeKit, true, annotate,"" ,true); - SO_KIT_ADD_CATALOG_ENTRY(textSep, SoSeparator, true, annotate,"" ,true); - - SO_KIT_INIT_INSTANCE(); - - SO_NODE_ADD_FIELD(rotate, (1.0, 0.0, 0.0, 0.0));//position orientation of the dimension. - SO_NODE_ADD_FIELD(length, (1.0));//turns into dimension length - SO_NODE_ADD_FIELD(origin, (0.0, 0.0, 0.0));//static - SO_NODE_ADD_FIELD(text, ("test"));//dimension text - SO_NODE_ADD_FIELD(dColor, (1.0, 0.0, 0.0));//dimension color. -} - -PartGui::DimensionLinear::~DimensionLinear() = default; - -SbBool PartGui::DimensionLinear::affectsState() const -{ - return false; -} - -void PartGui::DimensionLinear::setupDimension() -{ - //make unpickable - SoPickStyle* ps = static_cast(getPart("pickStyle", true)); - if (ps) - ps->style = SoPickStyle::UNPICKABLE; - - //transformation - SoTransform *trans = static_cast(getPart("transformation", true)); - trans->translation.connectFrom(&point1); - //build engine for vector subtraction and length. - SoCalculator *hyp = new SoCalculator(); - hyp->A.connectFrom(&point1); - hyp->B.connectFrom(&point2); - hyp->expression.set1Value(0, "oA = B-A"); - hyp->expression.set1Value(1, "oB = normalize(oA)"); - hyp->expression.set1Value(2, "oa = length(oA)"); - length.connectFrom(&hyp->oa); - - //build engine for rotation. - SoComposeRotationFromTo *rotationEngine = new SoComposeRotationFromTo(); - rotationEngine->from.setValue(SbVec3f(1.0, 0.0, 0.0)); - rotationEngine->to.connectFrom(&hyp->oB); - trans->rotation.connectFrom(&rotationEngine->rotation); - - //color - SoMaterial *material = new SoMaterial; - material->diffuseColor.connectFrom(&dColor); - - //dimension arrows - float dimLength = (point2.getValue()-point1.getValue()).length(); - float coneHeight = dimLength * 0.06; - float coneRadius = coneHeight * 0.5; - - SoCone *cone = new SoCone(); - cone->bottomRadius.setValue(coneRadius); - cone->height.setValue(coneHeight); - - char lStr[100]; - char rStr[100]; - snprintf(lStr, sizeof(lStr), "translation %.6f 0.0 0.0", coneHeight * 0.5); - snprintf(rStr, sizeof(rStr), "translation 0.0 -%.6f 0.0", coneHeight * 0.5); - - setPart("leftArrow.shape", cone); - set("leftArrow.transform", "rotation 0.0 0.0 1.0 1.5707963"); - set("leftArrow.transform", lStr); - setPart("rightArrow.shape", cone); - set("rightArrow.transform", "rotation 0.0 0.0 -1.0 1.5707963"); //no constant for PI. - //have use local here to do the offset because the main is wired up to length of dimension. - set("rightArrow.localTransform", rStr); - - SoTransform *transform = static_cast(getPart("rightArrow.transform", false)); - if (!transform) - return;//what to do here? - SoComposeVec3f *vec = new SoComposeVec3f; - vec->x.connectFrom(&length); - vec->y.setValue(0.0); - vec->z.setValue(0.0); - transform->translation.connectFrom(&vec->vector); - - setPart("leftArrow.material", material); - setPart("rightArrow.material", material); - - //line - SoConcatenate *catEngine = new SoConcatenate(SoMFVec3f::getClassTypeId()); - //don't know how to get around having this dummy origin. cat engine wants to connectfrom? - catEngine->input[0]->connectFrom(&origin); - catEngine->input[1]->connectFrom(&vec->vector); - - SoVertexProperty *lineVerts = new SoVertexProperty; - lineVerts->vertex.connectFrom(catEngine->output); - - int lineVertexMap[] = {0, 1}; - int lineVertexMapSize(sizeof(lineVertexMap)/sizeof(int)); - SoIndexedLineSet *line = new SoIndexedLineSet; - line->vertexProperty = lineVerts; - line->coordIndex.setValues(0, lineVertexMapSize, lineVertexMap); - - setPart("line.shape", line); - setPart("line.material", material); - - //text - SoSeparator *textSep = static_cast(getPart("textSep", true)); - if (!textSep) - return; - - textSep->addChild(material); - - SoCalculator *textVecCalc = new SoCalculator(); - textVecCalc->A.connectFrom(&vec->vector); - textVecCalc->B.set1Value(0, 0.0, 0.250, 0.0); - textVecCalc->expression.set1Value(0, "oA = (A / 2) + B"); - - SoTransform *textTransform = new SoTransform(); - textTransform->translation.connectFrom(&textVecCalc->oA); - textSep->addChild(textTransform); - - SoFont *fontNode = new SoFont(); - fontNode->name.setValue(getDimensionsFontName().c_str()); - fontNode->size.setValue(getDimensionsFontSize()); - textSep->addChild(fontNode); - - SoText2 *textNode = new SoText2(); - textNode->justification = SoText2::CENTER; - textNode->string.connectFrom(&text); - textSep->addChild(textNode); - - //this prevents the 2d text from screwing up the bounding box for a viewall - SoResetTransform *rTrans = new SoResetTransform; - rTrans->whatToReset = SoResetTransform::BBOX; - textSep->addChild(rTrans); -} - -PartGui::TaskMeasureLinear::TaskMeasureLinear() - : Gui::SelectionObserver(true, Gui::ResolveMode::NoResolve) - , selections1(), selections2(), buttonSelectedIndex(0) -{ - setUpGui(); -} - -PartGui::TaskMeasureLinear::~TaskMeasureLinear() -{ - try { - Gui::Selection().clearSelection(); - } - catch (const Py::Exception&) { - Base::PyException e; // extract the Python error text - e.ReportException(); - } -} - -void PartGui::TaskMeasureLinear::onSelectionChanged(const Gui::SelectionChanges& msg) -{ - if (msg.pSubName[0] == '\0') - return; // ignore whole objects selected in the model tree, e.g. when toggling the visibility of an object - - if (buttonSelectedIndex == 0) - { - if (msg.Type == Gui::SelectionChanges::AddSelection) - { - DimSelections::DimSelection newSelection; - newSelection.shapeType = DimSelections::None; - newSelection.documentName = msg.pDocName; - newSelection.objectName = msg.pObjectName; - newSelection.subObjectName = msg.pSubName; - newSelection.x = msg.x; - newSelection.y = msg.y; - newSelection.z = msg.z; - selections1.selections.clear();//we only want one item. - selections1.selections.push_back(newSelection); - QTimer::singleShot(0, this, &PartGui::TaskMeasureLinear::selectionClearDelayedSlot); - stepped->getButton(1)->setEnabled(true); - stepped->getButton(1)->setChecked(true); - return; - } - } - if (buttonSelectedIndex == 1) - { - if (msg.Type == Gui::SelectionChanges::AddSelection) - { - DimSelections::DimSelection newSelection; - newSelection.shapeType = DimSelections::None; - newSelection.documentName = msg.pDocName; - newSelection.objectName = msg.pObjectName; - newSelection.subObjectName = msg.pSubName; - newSelection.x = msg.x; - newSelection.y = msg.y; - newSelection.z = msg.z; - selections2.selections.clear();//we only want one item. - selections2.selections.push_back(newSelection); - buildDimension(); - clearSelectionStrings(); - QTimer::singleShot(0, this, &PartGui::TaskMeasureLinear::selectionClearDelayedSlot); - stepped->getButton(0)->setChecked(true); - stepped->getButton(1)->setEnabled(false); - return; - } - } -} - -void PartGui::TaskMeasureLinear::selectionClearDelayedSlot() -{ - //hack. - //clearing selections are not working as I hoped. Apparently the observer callback gets called - //before the actual selection takes place. Resulting in selections being left. this addresses this - //by being called from the event loop. - this->blockSelection(true); - Gui::Selection().clearSelection(); - this->blockSelection(false); -} - -void PartGui::TaskMeasureLinear::buildDimension() { - buildDimension(selections1,selections2); -} - -void PartGui::TaskMeasureLinear::buildDimension(const DimSelections &sel1, const DimSelections &sel2) -{ - if(sel1.selections.size() != 1 || sel2.selections.size() != 1) - return; - - DimSelections::DimSelection current1 = sel1.selections.at(0); - DimSelections::DimSelection current2 = sel2.selections.at(0); - - TopoDS_Shape shape1, shape2; - if (!getShapeFromStrings(shape1, current1.documentName, current1.objectName, current1.subObjectName)) - { - Base::Console().Message("\nFailed to get shape\n\n"); - return; - } - if (!getShapeFromStrings(shape2, current2.documentName, current2.objectName, current2.subObjectName)) - { - Base::Console().Message("\nFailed to get shape\n\n"); - return; - } - auto doc = App::GetApplication().getActiveDocument(); - if(doc) - _Measures[doc->getName()].emplace_back(sel1,sel2,true); - goDimensionLinearNoTask(shape1, shape2); -} - -void PartGui::TaskMeasureLinear::clearSelectionStrings() -{ - selections1.selections.clear(); - selections2.selections.clear(); -} - -void PartGui::TaskMeasureLinear::setUpGui() -{ - QPixmap mainIcon = Gui::BitmapFactory().pixmap("Part_Measure_Linear"); - - Gui::TaskView::TaskBox* selectionTaskBox = new Gui::TaskView::TaskBox - (mainIcon, QObject::tr("Selections"), false, nullptr); - QVBoxLayout *selectionLayout = new QVBoxLayout(); - stepped = new SteppedSelection(2, selectionTaskBox); - selectionLayout->addWidget(stepped); - selectionTaskBox->groupLayout()->addLayout(selectionLayout); - - Gui::TaskView::TaskBox* controlTaskBox = new Gui::TaskView::TaskBox - (mainIcon, QObject::tr("Control"), false, nullptr); - QVBoxLayout *controlLayout = new QVBoxLayout(); - - DimensionControl *control = new DimensionControl(controlTaskBox); - controlLayout->addWidget(control); - controlTaskBox->groupLayout()->addLayout(controlLayout); - QObject::connect(control->resetButton, &QPushButton::clicked, this, &TaskMeasureLinear::resetDialogSlot); - - this->setButtonPosition(TaskDialog::North); - Content.push_back(selectionTaskBox); - Content.push_back(controlTaskBox); - - stepped->getButton(0)->setChecked(true);//before wired up. - stepped->getButton(0)->setEnabled(true); - QObject::connect(stepped->getButton(0), &QPushButton::toggled, this, &TaskMeasureLinear::selection1Slot); - QObject::connect(stepped->getButton(1), &QPushButton::toggled, this, &TaskMeasureLinear::selection2Slot); -} - -void PartGui::TaskMeasureLinear::selection1Slot(bool checked) -{ - if (!checked) - { - if (!selections1.selections.empty()) - stepped->setIconDone(0); - return; - } - buttonSelectedIndex = 0; - - this->blockSelection(true); - Gui::Selection().clearSelection(); - //we should only be working with 1 entity, but oh well do the loop anyway. - std::vector::const_iterator it; - for (it = selections1.selections.begin(); it != selections1.selections.end(); ++it) - Gui::Selection().addSelection(it->documentName.c_str(), it->objectName.c_str(), it->subObjectName.c_str()); - this->blockSelection(false); -} - -void PartGui::TaskMeasureLinear::selection2Slot(bool checked) -{ - if (!checked) - return; - buttonSelectedIndex = 1; - this->blockSelection(true); - Gui::Selection().clearSelection(); - std::vector::const_iterator it; - for (it = selections2.selections.begin(); it != selections2.selections.end(); ++it) - Gui::Selection().addSelection(it->documentName.c_str(), it->objectName.c_str(), it->subObjectName.c_str()); - this->blockSelection(false); -} - -void PartGui::TaskMeasureLinear::resetDialogSlot(bool) -{ - clearSelectionStrings(); - this->blockSelection(true); - Gui::Selection().clearSelection(); - stepped->getButton(0)->setChecked(true); - stepped->getButton(1)->setEnabled(false); - this->blockSelection(false); -} - -void PartGui::TaskMeasureLinear::toggle3dSlot(bool) -{ - PartGui::toggle3d(); -} - -void PartGui::TaskMeasureLinear::toggleDeltaSlot(bool) -{ - PartGui::toggleDelta(); -} - -void PartGui::TaskMeasureLinear::clearAllSlot(bool) -{ - PartGui::eraseAllDimensions(); -} - -gp_Vec PartGui::convert(const TopoDS_Vertex &vertex) -{ - gp_Pnt point = BRep_Tool::Pnt(vertex); - gp_Vec out(point.X(), point.Y(), point.Z()); - return out; -} - -void PartGui::goDimensionAngularRoot() -{ - PartGui::ensure3dDimensionVisible(); - - VectorAdapter adapter1, adapter2; - if(PartGui::evaluateAngularPreSelection(adapter1, adapter2)) - goDimensionAngularNoTask(adapter1, adapter2); - else - { - Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); - if (!dlg) - { - Gui::Selection().clearSelection(); - dlg = new PartGui::TaskMeasureAngular(); - } - Gui::Control().showDialog(dlg); - } - Gui::Selection().clearSelection(); -} - -bool PartGui::evaluateAngularPreSelection(VectorAdapter &vector1Out, VectorAdapter &vector2Out) -{ - std::vector selections = Gui::Selection().getSelection(nullptr, Gui::ResolveMode::NoResolve); - if (selections.size() > 4 || selections.size() < 2) - return false; - std::vector::iterator it; - std::vector adapters; - std::vector sels; - TopoDS_Vertex lastVertex; - for (it = selections.begin(); it != selections.end(); ++it) - { - Base::Matrix4D mat; - TopoDS_Shape shape = Part::Feature::getShape(it->pObject,it->SubName,true,&mat); - if (shape.IsNull()) - break; - mat.inverse(); - - if (shape.ShapeType() == TopAbs_VERTEX) - { - if(sels.empty() || - sels.back().selections.back().shapeType!=DimSelections::Vertex || - sels.back().selections.size()==1) - { - sels.emplace_back(); - } - sels.back().selections.emplace_back(); - auto &sel = sels.back().selections.back(); - sel.documentName = it->DocName; - sel.objectName = it->FeatName; - sel.subObjectName = it->SubName; - sel.shapeType = DimSelections::Vertex; - Base::Vector3d v(it->x,it->y,it->z); - v = mat*v; - sel.x = v.x; - sel.y = v.y; - sel.z = v.z; - - TopoDS_Vertex currentVertex = TopoDS::Vertex(shape); - if (!lastVertex.IsNull()) - { - //need something here for 0 length vector. - //create a point half way between to vertices. - adapters.emplace_back(currentVertex, lastVertex); - lastVertex = TopoDS_Vertex(); - } - else - { - lastVertex = currentVertex; - } - continue; - } - //vertices have to be selected in succession. so if we make it here clear the last vertex. - lastVertex = TopoDS_Vertex(); - - gp_Vec pickPoint(it->x, it->y, it->z); - //can't use selections without a pick point. - if (pickPoint.IsEqual(gp_Vec(0.0, 0.0, 0.0), Precision::Confusion(), Precision::Angular())) - { - Base::Console().Message("Can't use selections without a pick point.\n"); - continue; - } - - sels.emplace_back(); - sels.back().selections.emplace_back(); - auto &sel = sels.back().selections.back(); - sel.documentName = it->DocName; - sel.objectName = it->FeatName; - sel.subObjectName = it->SubName; - Base::Vector3d v(it->x,it->y,it->z); - v = mat*v; - sel.x = v.x; - sel.y = v.y; - sel.z = v.z; - - if (shape.ShapeType() == TopAbs_EDGE) - { - sel.shapeType = DimSelections::Edge; - TopoDS_Edge edge = TopoDS::Edge(shape); - // make edge orientation so that end of edge closest to pick is head of vector. - gp_Vec firstPoint = PartGui::convert(TopExp::FirstVertex(edge, Standard_True)); - gp_Vec lastPoint = PartGui::convert(TopExp::LastVertex(edge, Standard_True)); - double firstDistance = (firstPoint - pickPoint).Magnitude(); - double lastDistance = (lastPoint - pickPoint).Magnitude(); - if (lastDistance > firstDistance) - { - if (edge.Orientation() == TopAbs_FORWARD) - edge.Orientation(TopAbs_REVERSED); - else - edge.Orientation(TopAbs_FORWARD); - } - adapters.emplace_back(edge, pickPoint); - continue; - } - - if (shape.ShapeType() == TopAbs_FACE) - { - sel.shapeType = DimSelections::Face; - TopoDS_Face face = TopoDS::Face(shape); - adapters.emplace_back(face, pickPoint); - continue; - } - } - - if (adapters.size() != 2) - return false; - if (!adapters.front().isValid() || !adapters.back().isValid()) - return false; - - vector1Out = adapters.front(); - vector2Out = adapters.back(); - - //making sure pick points are not equal - if ((vector1Out.getPickPoint() - vector2Out.getPickPoint()).Magnitude() < std::numeric_limits::epsilon()) - { - Base::Console().Message("pick points are equal\n"); - return false; - } - - auto doc = App::GetApplication().getActiveDocument(); - if(doc) - _Measures[doc->getName()].emplace_back(sels[0],sels[1],false); - return true; -} - -void PartGui::goDimensionAngularNoTask(const VectorAdapter &vector1Adapter, const VectorAdapter &vector2Adapter) -{ - gp_Vec vector1 = vector1Adapter; - gp_Vec vector2 = vector2Adapter; - double angle = vector1.Angle(vector2); - - std::ostringstream stream; - stream << std::setprecision(std::numeric_limits::digits10 + 1) << std::fixed << std::endl << - "angle in radians is: " << angle << std::endl << - "angle in degrees is: " << 180 * angle / M_PI << std::endl; - if (angle < M_PI / 2.0) - stream << std::setprecision(std::numeric_limits::digits10 + 1) << - "complement in radians is: " << M_PI / 2.0 - angle << std::endl << - "complement in degrees is: " << 90 - 180 * angle / M_PI << std::endl; - //I don't think we get anything over 180, but just in case. - if (angle > M_PI / 2.0 && angle < M_PI) - stream << std::setprecision(std::numeric_limits::digits10 + 1) << - "supplement in radians is: " << M_PI - angle << std::endl << - "supplement in degrees is: " << 180 - 180 * angle / M_PI << std::endl; - Base::Console().Message(stream.str().c_str()); - - SbMatrix dimSys; - double radius; - double displayAngle;//have to fake the angle in the 3d. - - if (vector1.IsParallel(vector2, Precision::Angular())) - { - //take first point project it onto second vector. - Handle(Geom_Curve) heapLine2 = new Geom_Line(vector2Adapter); - gp_Pnt tempPoint(vector1Adapter.getPickPoint().XYZ()); - - GeomAPI_ProjectPointOnCurve projection(tempPoint, heapLine2); - if (projection.NbPoints() < 1) - { - Base::Console().Message("parallel vectors: couldn't project onto line\n"); - return; - } - gp_Vec newPoint2; - newPoint2.SetXYZ(projection.Point(1).XYZ()); - - //if points are colinear, projection doesn't work and returns the same point. - //In this case we just use the original point. - if ((newPoint2 - vector1Adapter.getPickPoint()).Magnitude() < Precision::Confusion()) - newPoint2 = vector2Adapter.getPickPoint(); - - //now get midpoint between for dim origin. - gp_Vec point1 = vector1Adapter.getPickPoint(); - gp_Vec midPointProjection = newPoint2 - point1; - double distance = midPointProjection.Magnitude(); - midPointProjection.Normalize(); - midPointProjection *= distance / 2.0; - - gp_Vec origin = point1 + midPointProjection; - - //yaxis should be the same as vector1, but doing this to eliminate any potential slop from - //using precision::angular. If lines are colinear and we have no plane, we can't establish zAxis from crossing. - //we just the absolute axis. - gp_Vec xAxis = (point1 - origin).Normalized(); - gp_Vec zAxis; - if (xAxis.IsParallel(vector1, Precision::Angular())) - { - if (!xAxis.IsParallel(gp_Vec(0.0, 0.0, 1.0), Precision::Angular())) - zAxis = gp_Vec(0.0, 0.0, 1.0); - else - zAxis = gp_Vec(0.0, 1.0, 0.0); - } - else - zAxis = xAxis.Crossed(vector1).Normalized(); - gp_Vec yAxis = zAxis.Crossed(xAxis).Normalized(); - zAxis = xAxis.Crossed(yAxis).Normalized(); - - dimSys = SbMatrix - ( - xAxis.X(), yAxis.X(), zAxis.X(), origin.X(), - xAxis.Y(), yAxis.Y(), zAxis.Y(), origin.Y(), - xAxis.Z(), yAxis.Z(), zAxis.Z(), origin.Z(), - 0.0, 0.0, 0.0, 1.0 - ); - dimSys = dimSys.transpose(); - - radius = midPointProjection.Magnitude(); - displayAngle = M_PI; - } - else - { - Handle(Geom_Curve) heapLine1 = new Geom_Line(vector1Adapter); - Handle(Geom_Curve) heapLine2 = new Geom_Line(vector2Adapter); - - GeomAPI_ExtremaCurveCurve extrema(heapLine1, heapLine2); - - if (extrema.NbExtrema() < 1) - { - Base::Console().Message("couldn't get extrema\n"); - return; - } - - gp_Pnt extremaPoint1, extremaPoint2, dimensionOriginPoint; - extrema.Points(1, extremaPoint1, extremaPoint2); - if (extremaPoint1.Distance(extremaPoint2) < Precision::Confusion()) - dimensionOriginPoint = extremaPoint1; - else - { - //find halfway point in between extrema points for dimension origin. - gp_Vec vec1(extremaPoint1.XYZ()); - gp_Vec vec2(extremaPoint2.XYZ()); - gp_Vec connection(vec2-vec1); - Standard_Real distance = connection.Magnitude(); - connection.Normalize(); - connection *= (distance / 2.0); - dimensionOriginPoint.SetXYZ((vec1 + connection).XYZ()); - } - - gp_Vec thirdPoint(vector2Adapter.getPickPoint()); - gp_Vec originVector(dimensionOriginPoint.XYZ()); - gp_Vec extrema2Vector(extremaPoint2.XYZ()); - radius = (vector1Adapter.getPickPoint() - originVector).Magnitude(); - double legOne = (extrema2Vector - originVector).Magnitude(); - displayAngle = angle; - if (legOne > Precision::Confusion()) - { - double legTwo = sqrt(pow(radius, 2) - pow(legOne, 2)); - gp_Vec projectionVector(vector2); - projectionVector.Normalize(); - projectionVector *= legTwo; - thirdPoint = extrema2Vector + projectionVector; - gp_Vec hyp(thirdPoint - originVector); - hyp.Normalize(); - gp_Vec otherSide(vector1Adapter.getPickPoint() - originVector); - otherSide.Normalize(); - displayAngle = hyp.Angle(otherSide); - } - - gp_Vec xAxis = (vector1Adapter.getPickPoint() - originVector).Normalized(); - gp_Vec fakeYAxis = (thirdPoint - originVector).Normalized(); - gp_Vec zAxis = (xAxis.Crossed(fakeYAxis)).Normalized(); - gp_Vec yAxis = zAxis.Crossed(xAxis).Normalized(); - - dimSys = SbMatrix - ( - xAxis.X(), yAxis.X(), zAxis.X(), dimensionOriginPoint.X(), - xAxis.Y(), yAxis.Y(), zAxis.Y(), dimensionOriginPoint.Y(), - xAxis.Z(), yAxis.Z(), zAxis.Z(), dimensionOriginPoint.Z(), - 0.0, 0.0, 0.0, 1.0 - ); - - dimSys = dimSys.transpose(); - } - - ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/Mod/Part"); - App::Color c((uint32_t) group->GetUnsigned("DimensionsAngularColor", 0x0000FF00)); - - DimensionAngular *dimension = new DimensionAngular(); - dimension->ref(); - dimension->matrix.setValue(dimSys); - dimension->radius.setValue(radius); - dimension->angle.setValue(static_cast(displayAngle)); - dimension->text.setValue((Base::Quantity(180 * angle / M_PI, Base::Unit::Angle)).getUserString().toUtf8().constData()); - dimension->dColor.setValue(SbColor(c.r, c.g, c.b)); - dimension->setupDimension(); - - Gui::View3DInventorViewer *viewer = getViewer(); - if (viewer) - viewer->addDimension3d(dimension); - dimension->unref(); -} - -SO_KIT_SOURCE(PartGui::DimensionAngular) - -void PartGui::DimensionAngular::initClass() -{ - SO_KIT_INIT_CLASS(DimensionAngular, SoSeparatorKit, "SeparatorKit"); -} - -PartGui::DimensionAngular::DimensionAngular() -{ - SO_KIT_CONSTRUCTOR(PartGui::DimensionAngular); - - SO_KIT_ADD_CATALOG_ENTRY(transformation, SoMatrixTransform, true, topSeparator,"" , true); - SO_KIT_ADD_CATALOG_ENTRY(annotate, SoAnnotation, true, topSeparator,"" , true); - SO_KIT_ADD_CATALOG_ENTRY(arrow1, SoShapeKit, true, topSeparator,"" ,true); - SO_KIT_ADD_CATALOG_ENTRY(arrow2, SoShapeKit, true, topSeparator,"" ,true); - SO_KIT_ADD_CATALOG_ENTRY(arcSep, SoSeparator, true, annotate,"" ,true); - SO_KIT_ADD_CATALOG_ENTRY(textSep, SoSeparator, true, annotate,"" ,true); - - SO_KIT_INIT_INSTANCE(); - - SO_NODE_ADD_FIELD(radius, (10.0)); - SO_NODE_ADD_FIELD(angle, (1.0)); - SO_NODE_ADD_FIELD(text, ("test"));//dimension text - SO_NODE_ADD_FIELD(dColor, (1.0, 0.0, 0.0));//dimension color. - SO_NODE_ADD_FIELD(matrix, (1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0)); -} - -PartGui::DimensionAngular::~DimensionAngular() = default; - -SbBool PartGui::DimensionAngular::affectsState() const -{ - return false; -} - - -void PartGui::DimensionAngular::setupDimension() -{ - //transformation - SoMatrixTransform *trans = static_cast(getPart("transformation", true)); - trans->matrix.connectFrom(&matrix); - - //color - SoMaterial *material = new SoMaterial; - material->ref(); - material->diffuseColor.connectFrom(&dColor); - - // calculate arrow positions - SoTransform *arrow1Transform = new SoTransform(); - SoComposeVec3f *arrow1Compose = new SoComposeVec3f(); - arrow1Compose->x.connectFrom(&radius); - arrow1Compose->y.setValue(0.0f); - arrow1Compose->z.setValue(0.0f); - const float* constFloat = arrow1Compose->x.getValues(0); - auto PositionX1 = *constFloat; - arrow1Transform->translation.connectFrom(&arrow1Compose->vector); - setPart("arrow1.transform", arrow1Transform); - - SoComposeRotation *arrow2Rotation = new SoComposeRotation(); - arrow2Rotation->angle.connectFrom(&angle); - arrow2Rotation->axis.setValue(0.0f, 0.0f, 1.0f); - SoTransform *arrow2Transform = new SoTransform(); - arrow2Transform->rotation.connectFrom(&arrow2Rotation->rotation); - SoCalculator *arrow2LocationCalc = new SoCalculator(); - arrow2LocationCalc->a.connectFrom(&angle); - arrow2LocationCalc->b.connectFrom(&radius); - arrow2LocationCalc->expression.set1Value(0, "oa = cos(a) * b"); //xLocation - arrow2LocationCalc->expression.set1Value(1, "ob = sin(a) * b"); //yLocation - SoComposeVec3f *arrow2Compose = new SoComposeVec3f(); - arrow2Compose->x.connectFrom(&arrow2LocationCalc->oa); - arrow2Compose->y.connectFrom(&arrow2LocationCalc->ob); - arrow2Compose->z.setValue(0.0f); - arrow2Transform->translation.connectFrom(&arrow2Compose->vector); - - // calculate distance between the 2 arrows - constFloat = arrow2Compose->x.getValues(0); - auto PositionX2 = *constFloat; - constFloat = arrow2Compose->y.getValues(0); - auto PositionY2 = *constFloat; - float distance = sqrt((PositionX2 - PositionX1) * (PositionX2 - PositionX1) + PositionY2 * PositionY2); - - // dimension arrows - // the cone size must be scaled with the distance - // we use the same factors as for linear dimensions - float coneHeight = distance * 0.06; - float coneRadius = coneHeight * 0.5; - - SoCone* cone = new SoCone(); - cone->bottomRadius.setValue(coneRadius); - cone->height.setValue(coneHeight); - - // set arrows, their precision and rotation - char str1[100]; - char str2[100]; - snprintf(str1, sizeof(str1), "translation 0.0 %.6f 0.0", coneHeight * 0.5); - snprintf(str2, sizeof(str2), "translation 0.0 -%.6f 0.0", coneHeight * 0.5); - - setPart("arrow1.shape", cone); - set("arrow1.localTransform", "rotation 0.0 0.0 1.0 3.1415927"); - set("arrow1.localTransform", str1); - setPart("arrow2.shape", cone); - set("arrow2.transform", "rotation 0.0 0.0 1.0 0.0"); - set("arrow2.localTransform", str2); - - // now the position - setPart("arrow1.transform", arrow1Transform); - setPart("arrow2.transform", arrow2Transform); - - // finally the material - setPart("arrow1.material", material); - setPart("arrow2.material", material); - - ArcEngine *arcEngine = new ArcEngine(); - arcEngine->angle.connectFrom(&angle); - arcEngine->radius.connectFrom(&radius); - arcEngine->deviation.setValue(0.1f); - - SoCoordinate3 *coordinates = new SoCoordinate3(); - coordinates->point.connectFrom(&arcEngine->points); - - SoLineSet *lineSet = new SoLineSet(); - lineSet->ref(); - lineSet->vertexProperty.setValue(coordinates); - lineSet->numVertices.connectFrom(&arcEngine->pointCount); - lineSet->startIndex.setValue(0); - - SoSeparator *arcSep = static_cast(getPart("arcSep", true)); - if (arcSep) { - arcSep->addChild(material); - arcSep->addChild(lineSet); - } - - //text - SoSeparator *textSep = static_cast(getPart("textSep", true)); - if (!textSep) - return; - - textSep->addChild(material); - - SoCalculator *textVecCalc = new SoCalculator(); - textVecCalc->a.connectFrom(&angle); - textVecCalc->b.connectFrom(&radius); - textVecCalc->expression.set1Value(0, "oa = a / 2.0"); - textVecCalc->expression.set1Value(1, "ob = cos(oa) * b"); //x - textVecCalc->expression.set1Value(2, "oc = sin(oa) * b"); //y - - SoComposeVec3f *textLocation = new SoComposeVec3f(); - textLocation->x.connectFrom(&textVecCalc->ob); - textLocation->y.connectFrom(&textVecCalc->oc); - textLocation->z.setValue(0.0); - - - SoTransform *textTransform = new SoTransform(); - textTransform->translation.connectFrom(&textLocation->vector); - textSep->addChild(textTransform); - - SoFont *fontNode = new SoFont(); - fontNode->name.setValue(getDimensionsFontName().c_str()); - fontNode->size.setValue(getDimensionsFontSize()); - textSep->addChild(fontNode); - - SoText2 *textNode = new SoText2(); - textNode->justification = SoText2::CENTER; - textNode->string.connectFrom(&text); - textSep->addChild(textNode); - - //this prevents the 2d text from screwing up the bounding box for a viewall - SoResetTransform *rTrans = new SoResetTransform; - rTrans->whatToReset = SoResetTransform::BBOX; - textSep->addChild(rTrans); - - lineSet->unref(); - material->unref(); -} - -SO_ENGINE_SOURCE(PartGui::ArcEngine) - -PartGui::ArcEngine::ArcEngine() -{ - SO_ENGINE_CONSTRUCTOR(ArcEngine); - - SO_ENGINE_ADD_INPUT(radius, (10.0)); - SO_ENGINE_ADD_INPUT(angle, (1.0)); - SO_ENGINE_ADD_INPUT(deviation, (0.25)); - - SO_ENGINE_ADD_OUTPUT(points, SoMFVec3f); - SO_ENGINE_ADD_OUTPUT(pointCount, SoSFInt32); -} - -void PartGui::ArcEngine::initClass() -{ - SO_ENGINE_INIT_CLASS(ArcEngine, SoEngine, "Engine"); -} - -void PartGui::ArcEngine::evaluate() -{ - if (radius.getValue() < std::numeric_limits::epsilon() || - angle.getValue() < std::numeric_limits::epsilon() || - deviation.getValue() < std::numeric_limits::epsilon()) - { - defaultValues(); - return; - } - - float deviationAngle(acos((radius.getValue() - deviation.getValue()) / radius.getValue())); - std::vector tempPoints; - int segmentCount; - if (deviationAngle >= angle.getValue()) - segmentCount = 1; - else - { - segmentCount = static_cast(angle.getValue() / deviationAngle) + 1; - if (segmentCount < 2) - { - defaultValues(); - return; - } - } - float angleIncrement = angle.getValue() / static_cast(segmentCount); - for (int index = 0; index < segmentCount + 1; ++index) - { - SbVec3f currentNormal(1.0, 0.0, 0.0); - float currentAngle = index * angleIncrement; - SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), currentAngle); - rotation.multVec(currentNormal, currentNormal); - tempPoints.push_back(currentNormal * radius.getValue()); - } - int tempCount = tempPoints.size(); //for macro. - SO_ENGINE_OUTPUT(points, SoMFVec3f, setNum(tempCount)); - SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(tempCount)); - std::vector::const_iterator it; - for (it = tempPoints.begin(); it != tempPoints.end(); ++it) - { - int currentIndex = it-tempPoints.begin(); //for macro. - SbVec3f temp(*it); //for macro - SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(currentIndex, temp)); - } - -} - -void PartGui::ArcEngine::defaultValues() -{ - //just some non-failing info. - SO_ENGINE_OUTPUT(points, SoMFVec3f, setNum(2)); - SbVec3f point1(10.0, 0.0, 0.0); - SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(0, point1)); - SbVec3f point2(7.07f, 7.07f, 0.0); - SO_ENGINE_OUTPUT(points, SoMFVec3f, set1Value(1, point2)); - SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(2)); -} - -PartGui::SteppedSelection::SteppedSelection(const uint& buttonCountIn, QWidget* parent) - : QWidget(parent) - , stepActive(nullptr) - , stepDone(nullptr) -{ - if (buttonCountIn < 1) - return; - - QVBoxLayout *mainLayout = new QVBoxLayout(); - this->setLayout(mainLayout); - - QButtonGroup *buttonGroup = new QButtonGroup(); - buttonGroup->setExclusive(true); - - for (uint index = 0; index < buttonCountIn; ++index) - { - ButtonIconPairType tempPair; - QString text = QObject::tr("Selection"); - std::ostringstream stream; - stream << text.toStdString() << " " << ((index < 10) ? "0" : "") << index + 1; - QString buttonText = QString::fromStdString(stream.str()); - QPushButton *button = new QPushButton(buttonText, this); - button->setCheckable(true); - button->setEnabled(false); - buttonGroup->addButton(button); - connect(button, &QPushButton::toggled, this, &SteppedSelection::selectionSlot); - - QLabel *label = new QLabel; - - tempPair.first = button; - tempPair.second = label; - buttons.push_back(tempPair); - - QHBoxLayout *layout = new QHBoxLayout(); - mainLayout->addLayout(layout); - layout->addWidget(button); - layout->addSpacing(10); - layout->addWidget(label); - layout->addStretch(); - } - mainLayout->addStretch(); - - buildPixmaps(); //uses button size -} - -PartGui::SteppedSelection::~SteppedSelection() -{ - if(stepActive) - { - delete stepActive; - stepActive = nullptr; - } - if (stepDone) - { - delete stepDone; - stepDone = nullptr; - } -} - -void PartGui::SteppedSelection::buildPixmaps() -{ - assert(buttons.size() > 0); - int iconHeight(buttons.at(0).first->height()-6); - stepActive = new QPixmap(Gui::BitmapFactory().pixmap("Part_Measure_Step_Active").scaled - (iconHeight, iconHeight, Qt::KeepAspectRatio)); - stepDone = new QPixmap(Gui::BitmapFactory().pixmap("Part_Measure_Step_Done").scaled - (iconHeight, iconHeight, Qt::KeepAspectRatio)); -} - -void PartGui::SteppedSelection::selectionSlot(bool checked) -{ - QPushButton *sender = qobject_cast(QObject::sender()); - assert(sender); - std::vector::iterator it; - for (it = buttons.begin(); it != buttons.end(); ++it) - if (it->first == sender) - break; - assert(it != buttons.end()); - - if (checked) - it->second->setPixmap(*stepActive); - else - it->second->setPixmap(QPixmap()); -} - -QPushButton* PartGui::SteppedSelection::getButton(const uint& index) -{ - return buttons.at(index).first; -} - -void PartGui::SteppedSelection::setIconDone(const uint& index) -{ - buttons.at(index).second->setPixmap(*stepDone); -} - -PartGui::DimensionControl::DimensionControl(QWidget* parent): QWidget(parent) -{ - QVBoxLayout *commandLayout = new QVBoxLayout(); - this->setLayout(commandLayout); - - resetButton = new QPushButton(Gui::BitmapFactory().pixmap("Part_Measure_Linear"), - QObject::tr("Reset selection"), this); - commandLayout->addWidget(resetButton); - - QPushButton *toggle3dButton = new QPushButton(Gui::BitmapFactory().pixmap("Part_Measure_Toggle_3D"), - QObject::tr("Toggle direct dimensions"), this); - QObject::connect(toggle3dButton, &QPushButton::clicked, this, &DimensionControl::toggle3dSlot); - commandLayout->addWidget(toggle3dButton); - - QPushButton *toggleDeltaButton = new QPushButton(Gui::BitmapFactory().pixmap("Part_Measure_Toggle_Delta"), - QObject::tr("Toggle orthogonal dimensions"), this); - QObject::connect(toggleDeltaButton, &QPushButton::clicked, this, &DimensionControl::toggleDeltaSlot); - commandLayout->addWidget(toggleDeltaButton); - - QPushButton *clearAllButton = new QPushButton(Gui::BitmapFactory().pixmap("Part_Measure_Clear_All"), - QObject::tr("Clear all dimensions"), this); - QObject::connect(clearAllButton, &QPushButton::clicked, this, &DimensionControl::clearAllSlot); - commandLayout->addWidget(clearAllButton); -} - -void PartGui::DimensionControl::toggle3dSlot(bool) -{ - PartGui::toggle3d(); -} - -void PartGui::DimensionControl::toggleDeltaSlot(bool) -{ - PartGui::toggleDelta(); -} - -void PartGui::DimensionControl::clearAllSlot(bool) -{ - PartGui::eraseAllDimensions(); -} - -PartGui::TaskMeasureAngular::TaskMeasureAngular() - : Gui::SelectionObserver(true, Gui::ResolveMode::NoResolve) - , selections1(), selections2(), buttonSelectedIndex(0) -{ - setUpGui(); -} - -PartGui::TaskMeasureAngular::~TaskMeasureAngular() -{ - try { - Gui::Selection().clearSelection(); - } - catch (const Py::Exception&) { - Base::PyException e; // extract the Python error text - e.ReportException(); - } -} - -void PartGui::TaskMeasureAngular::onSelectionChanged(const Gui::SelectionChanges& msg) -{ - if (msg.pSubName[0] == '\0') - return; // ignore whole objects selected in the model tree, e.g. when toggling the visibility of an object - - TopoDS_Shape shape; - Base::Matrix4D mat; - if (!getShapeFromStrings(shape, std::string(msg.pDocName), - std::string(msg.pObjectName), std::string(msg.pSubName),&mat)) - return; - mat.inverse(); - DimSelections::DimSelection newSelection; - newSelection.shapeType = DimSelections::None; - newSelection.documentName = msg.pDocName; - newSelection.objectName = msg.pObjectName; - newSelection.subObjectName = msg.pSubName; - gp_Vec pickPoint(msg.x, msg.y, msg.z); - Base::Vector3d v(msg.x,msg.y,msg.z); - v = mat*v; - newSelection.x = v.x; - newSelection.y = v.y; - newSelection.z = v.z; - if (buttonSelectedIndex == 0) - { - if (msg.Type == Gui::SelectionChanges::AddSelection) - { - if (shape.ShapeType() == TopAbs_VERTEX) - { - //if we have previous selection it should be only one vertex. - if (selections1.selections.size() > 1) - selections1.selections.clear(); - else if(selections1.selections.size() == 1) - { - //make sure it is a vertex. - if (selections1.selections.at(0).shapeType != DimSelections::Vertex) - selections1.selections.clear(); - } - - newSelection.shapeType = DimSelections::Vertex; - selections1.selections.push_back(newSelection); - if (selections1.selections.size() == 1) - return; - //here we should have 2 vertices, but will check to make sure. - assert(selections1.selections.size() == 2); - assert(selections1.selections.at(0).shapeType == DimSelections::Vertex); - assert(selections1.selections.at(1).shapeType == DimSelections::Vertex); - - QTimer::singleShot(0, this, &PartGui::TaskMeasureAngular::selectionClearDelayedSlot); - stepped->getButton(1)->setEnabled(true); - stepped->getButton(1)->setChecked(true); - return; - } - - //here there should only be one in the selections container. so just clear it. - selections1.selections.clear(); - - if (shape.ShapeType() == TopAbs_EDGE) - { - newSelection.shapeType = DimSelections::Edge; - selections1.selections. push_back(newSelection); - } - - if (shape.ShapeType() == TopAbs_FACE) - { - newSelection.shapeType = DimSelections::Face; - selections1.selections.push_back(newSelection); - } - - QTimer::singleShot(0, this, &PartGui::TaskMeasureAngular::selectionClearDelayedSlot); - stepped->getButton(1)->setEnabled(true); - stepped->getButton(1)->setChecked(true); - return; - } - } - if (buttonSelectedIndex == 1) - { - if (msg.Type == Gui::SelectionChanges::AddSelection) - { - if (shape.ShapeType() == TopAbs_VERTEX) - { - //if we have previous selection it should be only one vertex. - if (selections2.selections.size() > 1) - selections2.selections.clear(); - else if(selections2.selections.size() == 1) - { - //make sure it is a vertex. - if (selections2.selections.at(0).shapeType != DimSelections::Vertex) - selections2.selections.clear(); - } - - newSelection.shapeType = DimSelections::Vertex; - selections2.selections.push_back(newSelection); - if (selections2.selections.size() == 1) - return; - //here we should have 2 vertices, but will check to make sure. - assert(selections2.selections.size() == 2); - assert(selections2.selections.at(0).shapeType == DimSelections::Vertex); - assert(selections2.selections.at(1).shapeType == DimSelections::Vertex); - - buildDimension(); - clearSelection(); - QTimer::singleShot(0, this, &PartGui::TaskMeasureAngular::selectionClearDelayedSlot); - stepped->getButton(0)->setChecked(true); - stepped->getButton(1)->setEnabled(false); - return; - } - //vertices have to be selected in succession. if we get here,clear temp selection. - selections2.selections.clear(); - - if (shape.ShapeType() == TopAbs_EDGE) - { - newSelection.shapeType = DimSelections::Edge; - selections2.selections. push_back(newSelection); - } - - if (shape.ShapeType() == TopAbs_FACE) - { - newSelection.shapeType = DimSelections::Face; - selections2.selections.push_back(newSelection); - } - - buildDimension(); - clearSelection(); - QTimer::singleShot(0, this, &PartGui::TaskMeasureAngular::selectionClearDelayedSlot); - stepped->getButton(0)->setChecked(true); - stepped->getButton(1)->setEnabled(false); - return; - } - } -} - -void PartGui::TaskMeasureAngular::selectionClearDelayedSlot() -{ - //hack. - //clearing selections are not working as I hoped. Apparently the observer callback gets called - //before the actual selection takes place. Resulting in selections being left. this addresses this - //by being called from the event loop. - this->blockSelection(true); - Gui::Selection().clearSelection(); - this->blockSelection(false); -} - -VectorAdapter PartGui::TaskMeasureAngular::buildAdapter(const PartGui::DimSelections& selection) -{ - Base::Matrix4D mat; - assert(selection.selections.size() > 0 && selection.selections.size() < 3); - if (selection.selections.size() == 1) - { - DimSelections::DimSelection current = selection.selections.at(0); - if (current.shapeType == DimSelections::Edge) - { - TopoDS_Shape edgeShape; - if (!getShapeFromStrings(edgeShape, current.documentName, current.objectName, current.subObjectName,&mat)) - return {}; - TopoDS_Edge edge = TopoDS::Edge(edgeShape); - // make edge orientation so that end of edge closest to pick is head of vector. - TopoDS_Vertex firstVertex = TopExp::FirstVertex(edge, Standard_True); - TopoDS_Vertex lastVertex = TopExp::LastVertex(edge, Standard_True); - if (firstVertex.IsNull() || lastVertex.IsNull()) - return {}; - gp_Vec firstPoint = PartGui::convert(firstVertex); - gp_Vec lastPoint = PartGui::convert(lastVertex); - Base::Vector3d v(current.x,current.y,current.z); - v = mat*v; - gp_Vec pickPoint(v.x, v.y, v.z); - double firstDistance = (firstPoint - pickPoint).Magnitude(); - double lastDistance = (lastPoint - pickPoint).Magnitude(); - if (lastDistance > firstDistance) - { - if (edge.Orientation() == TopAbs_FORWARD) - edge.Orientation(TopAbs_REVERSED); - else - edge.Orientation(TopAbs_FORWARD); - } - return VectorAdapter(edge, pickPoint); - } - if (current.shapeType == DimSelections::Face) - { - TopoDS_Shape faceShape; - if (!getShapeFromStrings(faceShape, current.documentName, current.objectName, current.subObjectName,&mat)) - return {}; - - TopoDS_Face face = TopoDS::Face(faceShape); - Base::Vector3d v(current.x,current.y,current.z); - v = mat*v; - gp_Vec pickPoint(v.x, v.y, v.z); - return VectorAdapter(face, pickPoint); - } - } - //selection size == 2. - DimSelections::DimSelection current1 = selection.selections.at(0); - DimSelections::DimSelection current2 = selection.selections.at(1); - assert(current1.shapeType == DimSelections::Vertex); - assert(current2.shapeType == DimSelections::Vertex); - TopoDS_Shape vertexShape1, vertexShape2; - if(!getShapeFromStrings(vertexShape1, current1.documentName, current1.objectName, current1.subObjectName)) - return {}; - if(!getShapeFromStrings(vertexShape2, current2.documentName, current2.objectName, current2.subObjectName)) - return {}; - - TopoDS_Vertex vertex1 = TopoDS::Vertex(vertexShape1); - TopoDS_Vertex vertex2 = TopoDS::Vertex(vertexShape2); - - //build a temp adapter to make sure it is valid. - return VectorAdapter(PartGui::convert(vertex2), PartGui::convert(vertex1)); -} - -void PartGui::TaskMeasureAngular::buildDimension() { - buildDimension(selections1,selections2); -} - -void PartGui::TaskMeasureAngular::buildDimension(const DimSelections &sel1, const DimSelections &sel2) -{ - //build adapters. - VectorAdapter adapt1 = buildAdapter(sel1); - VectorAdapter adapt2 = buildAdapter(sel2); - - if (!adapt1.isValid() || !adapt2.isValid()) - { - Base::Console().Message("\ncouldn't build adapter\n\n"); - return; - } - auto doc = App::GetApplication().getActiveDocument(); - if(doc) - _Measures[doc->getName()].emplace_back(sel1,sel2,false); - goDimensionAngularNoTask(adapt1, adapt2); -} - -void PartGui::TaskMeasureAngular::clearSelection() -{ - selections1.selections.clear(); - selections2.selections.clear(); -} - -void PartGui::TaskMeasureAngular::setUpGui() -{ - QPixmap mainIcon = Gui::BitmapFactory().pixmap("Part_Measure_Angular"); - - Gui::TaskView::TaskBox* selectionTaskBox = new Gui::TaskView::TaskBox - (mainIcon, QObject::tr("Selections"), false, nullptr); - QVBoxLayout *selectionLayout = new QVBoxLayout(); - stepped = new SteppedSelection(2, selectionTaskBox); - selectionLayout->addWidget(stepped); - selectionTaskBox->groupLayout()->addLayout(selectionLayout); - - Gui::TaskView::TaskBox* controlTaskBox = new Gui::TaskView::TaskBox - (mainIcon, QObject::tr("Control"), false, nullptr); - QVBoxLayout *controlLayout = new QVBoxLayout(); - - DimensionControl *control = new DimensionControl(controlTaskBox); - controlLayout->addWidget(control); - controlTaskBox->groupLayout()->addLayout(controlLayout); - QObject::connect(control->resetButton, &QPushButton::clicked, this, &TaskMeasureAngular::resetDialogSlot); - - this->setButtonPosition(TaskDialog::North); - Content.push_back(selectionTaskBox); - Content.push_back(controlTaskBox); - - stepped->getButton(0)->setChecked(true);//before wired up. - stepped->getButton(0)->setEnabled(true); - QObject::connect(stepped->getButton(0), &QPushButton::toggled, this, &TaskMeasureAngular::selection1Slot); - QObject::connect(stepped->getButton(1), &QPushButton::toggled, this, &TaskMeasureAngular::selection2Slot); -} - -void PartGui::TaskMeasureAngular::selection1Slot(bool checked) -{ - if (checked) - { - buttonSelectedIndex = 0; - this->blockSelection(true); - Gui::Selection().clearSelection(); - std::vector::const_iterator it; - for (it = selections1.selections.begin(); it != selections1.selections.end(); ++it) - Gui::Selection().addSelection(it->documentName.c_str(), it->objectName.c_str(), it->subObjectName.c_str()); - this->blockSelection(false); - } - else - { - if (!selections1.selections.empty()) - stepped->setIconDone(0); - } -} - -void PartGui::TaskMeasureAngular::selection2Slot(bool checked) -{ - if (checked) - buttonSelectedIndex = 1; - this->blockSelection(true); - Gui::Selection().clearSelection(); - std::vector::const_iterator it; - for (it = selections2.selections.begin(); it != selections2.selections.end(); ++it) - Gui::Selection().addSelection(it->documentName.c_str(), it->objectName.c_str(), it->subObjectName.c_str()); - this->blockSelection(false); -} - -void PartGui::TaskMeasureAngular::resetDialogSlot(bool) -{ - clearSelection(); - this->blockSelection(true); - Gui::Selection().clearSelection(); - stepped->getButton(0)->setChecked(true); - stepped->getButton(1)->setEnabled(false); - this->blockSelection(false); -} - -void PartGui::TaskMeasureAngular::toggle3dSlot(bool) -{ - PartGui::toggle3d(); -} - -void PartGui::TaskMeasureAngular::toggleDeltaSlot(bool) -{ - PartGui::toggleDelta(); -} - -void PartGui::TaskMeasureAngular::clearAllSlot(bool) -{ - PartGui::eraseAllDimensions(); -} - -#include "moc_TaskDimension.cpp" diff --git a/src/Mod/Part/Gui/TaskDimension.h b/src/Mod/Part/Gui/TaskDimension.h deleted file mode 100644 index 5f17ed8de3..0000000000 --- a/src/Mod/Part/Gui/TaskDimension.h +++ /dev/null @@ -1,337 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Thomas Anderson * - * * - * 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 TASKDIMENSION_H -#define TASKDIMENSION_H - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - -class TopoDS_Shape; -class TopoDS_Face; -class TopoDS_Edge; -class TopoDS_Vertex; -class gp_Pnt; -class BRepExtrema_DistShapeShape; - -class QPushButton; -class QPixmap; -class QLabel; - -using namespace Part; - -namespace Gui{class View3dInventorViewer;} - -namespace PartGui -{ - /*!find shape from selection strings - * @param shapeOut search results. - * @param doc document name to search. - * @param object object name to search. - * @param sub sub-object name to search. - * @return signal if the search was successful. - */ - bool getShapeFromStrings(TopoDS_Shape &shapeOut, const std::string &doc, const std::string &object, const std::string &sub, Base::Matrix4D *mat=nullptr); - /*!examine pre selection - * @param shape1 first shape in current selection - * @param shape2 second shape in current selection - * @return signal if preselection is valid. false means shape1 and shape2 are invalid. - */ - bool evaluateLinearPreSelection(TopoDS_Shape &shape1, TopoDS_Shape &shape2); - /*!start of the measure linear command*/ - void goDimensionLinearRoot(); - /*!does the measure and create dimensions without a dialog - * @param shape1 first shape. - * @param shape2 second shape. - * @todo incorporate some form of "adapt to topods_shape". so we can expand to other types outside OCC. - */ - void goDimensionLinearNoTask(const TopoDS_Shape &shape1, const TopoDS_Shape &shape2); - /*!prints results of measuring to console. - * @param measure object containing the measure information - */ - void dumpLinearResults(const BRepExtrema_DistShapeShape &measure); - /*!convenience function to get the viewer*/ - Gui::View3DInventorViewer* getViewer(); - /*!adds 3d and delta dimensions to the viewer - * @param measure object containing the measure information. - */ - void addLinearDimensions(const BRepExtrema_DistShapeShape &measure); - /*!creates one dimension from points with color - * @param point1 first point - * @param point2 second point - * @param color color of dimension - * @return an inventor node to add to a scenegraph - */ - SoNode* createLinearDimension(const gp_Pnt &point1, const gp_Pnt &point2, const SbColor &color); - /*!erases all the dimensions in the viewer.*/ - void eraseAllDimensions(); - /*!refresh all the dimensions in the viewer.*/ - void refreshDimensions(); - /*!toggles the display status of the 3d dimensions*/ - void toggle3d(); - /*!toggles the display status of the delta dimensions*/ - void toggleDelta(); - /*!make sure measure command isn't working with everything invisible. Confusing the user*/ - void ensureSomeDimensionVisible(); - /*!make sure angle measure command isn't working with 3d off. Confusing the user*/ - void ensure3dDimensionVisible(); - /*convert a vertex to vector*/ - gp_Vec convert(const TopoDS_Vertex &vertex); - - auto getDimensionsFontName(); - auto getDimensionsFontSize(); - -class DimensionLinear : public SoSeparatorKit -{ - SO_KIT_HEADER(DimensionLinear); - - SO_KIT_CATALOG_ENTRY_HEADER(transformation); - SO_KIT_CATALOG_ENTRY_HEADER(annotate); - SO_KIT_CATALOG_ENTRY_HEADER(leftArrow); - SO_KIT_CATALOG_ENTRY_HEADER(rightArrow); - SO_KIT_CATALOG_ENTRY_HEADER(line); - SO_KIT_CATALOG_ENTRY_HEADER(textSep); -public: - DimensionLinear(); - static void initClass(); - SbBool affectsState() const override; - void setupDimension(); - - SoSFVec3f point1; - SoSFVec3f point2; - SoSFString text; - SoSFColor dColor; -protected: - SoSFRotation rotate; - SoSFFloat length; - SoSFVec3f origin; - -private: - ~DimensionLinear() override; -}; - -/*kit for anglular dimensions*/ -class DimensionAngular : public SoSeparatorKit -{ - SO_KIT_HEADER(DimensionAngular); - - SO_KIT_CATALOG_ENTRY_HEADER(transformation); - SO_KIT_CATALOG_ENTRY_HEADER(annotate); - SO_KIT_CATALOG_ENTRY_HEADER(arrow1); - SO_KIT_CATALOG_ENTRY_HEADER(arrow2); - SO_KIT_CATALOG_ENTRY_HEADER(arcSep); - SO_KIT_CATALOG_ENTRY_HEADER(textSep); -public: - DimensionAngular(); - static void initClass(); - SbBool affectsState() const override; - - SoSFFloat radius;//radians. - SoSFFloat angle;//radians. - SoSFString text; - SoSFColor dColor; - SoSFMatrix matrix; - void setupDimension(); -private: - ~DimensionAngular() override; -}; - -/*used for generating points for arc display*/ -class ArcEngine : public SoEngine -{ - SO_ENGINE_HEADER(ArcEngine); -public: - ArcEngine(); - static void initClass(); - - SoSFFloat radius; - SoSFFloat angle; - SoSFFloat deviation; - - SoEngineOutput points; - SoEngineOutput pointCount; -protected: - void evaluate() override; -private: - ~ArcEngine() override = default; - void defaultValues(); //some non error values if something goes wrong. -}; - -/*! a widget with buttons and icons for a controlled selection process*/ -class SteppedSelection : public QWidget -{ - Q_OBJECT -public: - explicit SteppedSelection(const uint &buttonCountIn, QWidget *parent = nullptr); - ~SteppedSelection() override; - QPushButton* getButton(const uint &index); - void setIconDone(const uint &index); - -protected: - using ButtonIconPairType = std::pair; - std::vector buttons; - QPixmap *stepActive; - QPixmap *stepDone; - -private Q_SLOTS: - void selectionSlot(bool checked); - void buildPixmaps(); - -}; - -/*! just convenience container*/ -class DimSelections -{ -public: - enum ShapeType{None, Vertex, Edge, Face}; - struct DimSelection - { - std::string documentName; - std::string objectName; - std::string subObjectName; - float x; - float y; - float z; - ShapeType shapeType; - }; - std::vector selections; -}; - -/*!widget for buttons controlling the display of dimensions*/ -class DimensionControl : public QWidget -{ - Q_OBJECT -public: - explicit DimensionControl(QWidget* parent); - QPushButton *resetButton; -public Q_SLOTS: - void toggle3dSlot(bool); - void toggleDeltaSlot(bool); - void clearAllSlot(bool); -}; - -/*!linear dialog*/ -class TaskMeasureLinear : public Gui::TaskView::TaskDialog, public Gui::SelectionObserver -{ - Q_OBJECT -public: - TaskMeasureLinear(); - ~TaskMeasureLinear() override; - - QDialogButtonBox::StandardButtons getStandardButtons() const override - {return QDialogButtonBox::Close;} - bool isAllowedAlterDocument() const override {return false;} - bool needsFullSpace() const override {return false;} -protected: - void onSelectionChanged(const Gui::SelectionChanges& msg) override; - -protected Q_SLOTS: - void selection1Slot(bool checked); - void selection2Slot(bool checked); - void resetDialogSlot(bool); - void toggle3dSlot(bool); - void toggleDeltaSlot(bool); - void clearAllSlot(bool); - void selectionClearDelayedSlot(); - -public: - static void buildDimension(const DimSelections &sel1, const DimSelections &sel2); - -private: - void setUpGui(); - void buildDimension(); - void clearSelectionStrings(); - DimSelections selections1; - DimSelections selections2; - uint buttonSelectedIndex; - SteppedSelection *stepped; - -}; - - -/*!angular dialog class*/ -class TaskMeasureAngular : public Gui::TaskView::TaskDialog, public Gui::SelectionObserver -{ - Q_OBJECT -public: - TaskMeasureAngular(); - ~TaskMeasureAngular() override; - - QDialogButtonBox::StandardButtons getStandardButtons() const override - {return QDialogButtonBox::Close;} - bool isAllowedAlterDocument() const override {return false;} - bool needsFullSpace() const override {return false;} -protected: - void onSelectionChanged(const Gui::SelectionChanges& msg) override; - -protected Q_SLOTS: - void selection1Slot(bool checked); - void selection2Slot(bool checked); - void resetDialogSlot(bool); - void toggle3dSlot(bool); - void toggleDeltaSlot(bool); - void clearAllSlot(bool); - void selectionClearDelayedSlot(); - -public: - static void buildDimension(const DimSelections &sel1, const DimSelections &sel2); - -private: - void buildDimension(); - void setUpGui(); - void clearSelection(); - DimSelections selections1; - DimSelections selections2; - uint buttonSelectedIndex; - SteppedSelection *stepped; - static VectorAdapter buildAdapter(const DimSelections &selection); -}; - -/*!start of the measure angular command*/ -void goDimensionAngularRoot(); -/*!examine angular pre selection - * @param vector1Out first shape in current selection - * @param vector2Out second shape in current selection - * @return signal if preselection is valid. false means vector1Out and vector2Out are invalid. - */ -bool evaluateAngularPreSelection(VectorAdapter &vector1Out, VectorAdapter &vector2Out); -/*!build angular dimension*/ -void goDimensionAngularNoTask(const VectorAdapter &vector1Adapter, const VectorAdapter &vector2Adapter); -} - -#endif // TASKDIMENSION_H diff --git a/src/Mod/Part/Gui/Workbench.cpp b/src/Mod/Part/Gui/Workbench.cpp index ee7d9e8790..e2a1b4453f 100644 --- a/src/Mod/Part/Gui/Workbench.cpp +++ b/src/Mod/Part/Gui/Workbench.cpp @@ -41,7 +41,6 @@ using namespace PartGui; qApp->translate("Workbench", "Split"); qApp->translate("Workbench", "Compound"); qApp->translate("Workbench", "Create a copy"); - qApp->translate("Workbench", "Measure"); #endif /// @namespace PartGui @class Workbench @@ -140,18 +139,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Separator" << "Part_EditAttachment"; - Gui::MenuItem* measure = new Gui::MenuItem; - root->insertItem(item,measure); - measure->setCommand("Measure"); - *measure << "Part_Measure_Linear" - << "Part_Measure_Angular" - << "Separator" - << "Part_Measure_Refresh" - << "Part_Measure_Clear_All" - << "Part_Measure_Toggle_All" - << "Part_Measure_Toggle_3D" - << "Part_Measure_Toggle_Delta"; - Gui::MenuItem* view = root->findItem("&View"); if (view) { Gui::MenuItem* appr = view->findItem("Std_RandomColor"); @@ -210,17 +197,6 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "Part_CheckGeometry" << "Part_Defeaturing"; - Gui::ToolBarItem* measure = new Gui::ToolBarItem(root); - measure->setCommand("Measure"); - *measure << "Part_Measure_Linear" - << "Part_Measure_Angular" - << "Separator" - << "Part_Measure_Refresh" - << "Part_Measure_Clear_All" - << "Part_Measure_Toggle_All" - << "Part_Measure_Toggle_3D" - << "Part_Measure_Toggle_Delta"; - return root; } diff --git a/src/Mod/Part/Gui/WorkbenchManipulator.cpp b/src/Mod/Part/Gui/WorkbenchManipulator.cpp index d8dc4d6ffc..b6a14976dc 100644 --- a/src/Mod/Part/Gui/WorkbenchManipulator.cpp +++ b/src/Mod/Part/Gui/WorkbenchManipulator.cpp @@ -34,13 +34,6 @@ void WorkbenchManipulator::modifyMenuBar([[maybe_unused]] Gui::MenuItem* menuBar addSectionCut(menuBar); } -void WorkbenchManipulator::modifyContextMenu(const char* recipient, Gui::MenuItem* menuBar) -{ - if (strcmp(recipient, "View") == 0) { - addSelectionFilter(menuBar); - } -} - void WorkbenchManipulator::modifyToolBars(Gui::ToolBarItem* toolBar) { addSelectionFilter(toolBar); @@ -78,12 +71,3 @@ void WorkbenchManipulator::addSelectionFilter(Gui::ToolBarItem* toolBar) } } } - -void WorkbenchManipulator::addSelectionFilter(Gui::MenuItem* menuBar) -{ - if (auto measure = menuBar->findItem("Measure")) { - auto add = new Gui::MenuItem(); // NOLINT - add->setCommand("Part_SelectFilter"); - menuBar->insertItem(measure, add); - } -} diff --git a/src/Mod/Part/Gui/WorkbenchManipulator.h b/src/Mod/Part/Gui/WorkbenchManipulator.h index 745e7556b4..338dd3243d 100644 --- a/src/Mod/Part/Gui/WorkbenchManipulator.h +++ b/src/Mod/Part/Gui/WorkbenchManipulator.h @@ -38,12 +38,6 @@ protected: * The default implementation doesn't change anything.SectionCut */ void modifyMenuBar(Gui::MenuItem* menuBar) override; - /*! - * \brief modifyContextMenu - * Method to manipulate the contextmenu structure of a workbench. - * The default implementation doesn't change anything. - */ - void modifyContextMenu(const char* recipient, Gui::MenuItem* menuBar) override; /*! * \brief modifyToolBars * Method to manipulate the toolbar structure of a workbench @@ -60,7 +54,6 @@ protected: private: static void addSectionCut(Gui::MenuItem* menuBar); static void addSelectionFilter(Gui::ToolBarItem* toolBar); - static void addSelectionFilter(Gui::MenuItem* menuBar); }; } // namespace PartGui diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 408d5b9172..539f856705 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -580,20 +580,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const *part << "Separator" << "PartDesign_WizardShaft"; } - // use Part's measure features also for PartDesign - Gui::MenuItem* measure = new Gui::MenuItem; - root->insertItem(item, measure); - measure->setCommand("Measure"); - - *measure << "Part_Measure_Linear" - << "Part_Measure_Angular" - << "Separator" - << "Part_Measure_Refresh" - << "Part_Measure_Clear_All" - << "Part_Measure_Toggle_All" - << "Part_Measure_Toggle_3D" - << "Part_Measure_Toggle_Delta"; - Gui::MenuItem* view = root->findItem("&View"); if (view) { Gui::MenuItem* appr = view->findItem("Std_RandomColor"); @@ -662,19 +648,6 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "Separator" << "PartDesign_Boolean"; - // use Part's measure features also for PartDesign - Gui::ToolBarItem* measure = new Gui::ToolBarItem(root); - measure->setCommand("Measure"); - - *measure << "Part_Measure_Linear" - << "Part_Measure_Angular" - << "Separator" - << "Part_Measure_Refresh" - << "Part_Measure_Clear_All" - << "Part_Measure_Toggle_All" - << "Part_Measure_Toggle_3D" - << "Part_Measure_Toggle_Delta"; - return root; }