diff --git a/src/Mod/TechDraw/CMakeLists.txt b/src/Mod/TechDraw/CMakeLists.txt
index 53dd518888..280fabc523 100644
--- a/src/Mod/TechDraw/CMakeLists.txt
+++ b/src/Mod/TechDraw/CMakeLists.txt
@@ -21,6 +21,7 @@ set(TechDraw_ToolsScripts
TechDrawTools/CommandMoveView.py
TechDrawTools/CommandShareView.py
TechDrawTools/CommandAxoLengthDimension.py
+ TechDrawTools/CommandPositionSectionView.py
TechDrawTools/CommandFillTemplateFields.py
TechDrawTools/CommandVertexCreations.py
TechDrawTools/CommandHoleShaftFit.py
diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp
index 9579d7fdf4..7bcbdd00a0 100644
--- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp
+++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp
@@ -1440,83 +1440,6 @@ bool CmdTechDrawExtensionLockUnlockView::isActive()
return (havePage && haveView);
}
-//===========================================================================
-// TechDraw_ExtensionPositionSectionView
-//===========================================================================
-
-DEF_STD_CMD_A(CmdTechDrawExtensionPositionSectionView)
-
-CmdTechDrawExtensionPositionSectionView::CmdTechDrawExtensionPositionSectionView()
- : Command("TechDraw_ExtensionPositionSectionView")
-{
- sAppModule = "TechDraw";
- sGroup = QT_TR_NOOP("TechDraw");
- sMenuText = QT_TR_NOOP("Position Section View");
- sToolTipText = QT_TR_NOOP("Orthogonally align a section view with its source view:
\
-- Select a single section view
\
-- Click this tool");
- sWhatsThis = "TechDraw_ExtensionPositionSectionView";
- sStatusTip = sMenuText;
- sPixmap = "TechDraw_ExtensionPositionSectionView";
-}
-
-void CmdTechDrawExtensionPositionSectionView::activated(int iMsg)
-{
- // position a section view
- Q_UNUSED(iMsg);
- //Base::Console().Message("PositionSectionView started\n");
- auto selection = getSelection().getSelectionEx();
- if (selection.empty()) {
- QMessageBox::warning(Gui::getMainWindow(), QObject::tr("TechDraw Position Section View"),
- QObject::tr("Selection is empty"));
- return;
- }
-
- double xPos = 0.0, yPos = 0.0;
- TechDraw::DrawViewPart* baseView;
- auto objFeat = selection[0].getObject();
- if (objFeat && objFeat->isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId())) {
- TechDraw::DrawViewSection* sectionView = static_cast(objFeat);
- baseView = sectionView->getBaseDVP();
- if (baseView && baseView->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
- std::vector parentViews = baseView->getInList();
- if (!parentViews.empty()) {
- TechDraw::DrawProjGroup* groupBase =
- dynamic_cast(parentViews[0]);
- if (groupBase) {
- xPos = groupBase->X.getValue();
- yPos = groupBase->Y.getValue();
- }
- }
- }
- else if (baseView) {
- xPos = baseView->X.getValue();
- yPos = baseView->Y.getValue();
- }
- std::string direction = sectionView->SectionDirection.getValueAsString();
- if ((direction == "Right") || (direction == "Left"))
- sectionView->Y.setValue(yPos);
- else if ((direction == "Up") || (direction == "Down"))
- sectionView->X.setValue(xPos);
- else if (direction == "Aligned")
- {
- Base::Vector3d pBase(xPos,yPos,0.0);
- Base::Vector3d dirView(sectionView->Direction.getValue());
- Base::Vector3d pSection(sectionView->X.getValue(),sectionView->Y.getValue(),0.0);
- Base::Vector3d newPos = DrawUtil::getTrianglePoint(pBase, dirView, pSection);
- sectionView->X.setValue(newPos.x);
- sectionView->Y.setValue(newPos.y);
- }
- }
-}
-
-bool CmdTechDrawExtensionPositionSectionView::isActive()
-{
- bool havePage = DrawGuiUtil::needPage(this);
- bool haveView = DrawGuiUtil::needView(this);
- return (havePage && haveView);
-}
-
//===========================================================================
// TechDraw_ExtensionExtendLine
//===========================================================================
@@ -2198,7 +2121,7 @@ void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPar
void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge)
{
// set line attributes of a cosmetic edge
- cosEdge->m_format.m_style = 2;
+ cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle();
cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue();
cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue();
cosEdge->m_format.m_lineNumber = _getActiveLineAttributes().getStyle();
@@ -2207,7 +2130,7 @@ void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge)
void _setLineAttributes(TechDraw::CenterLine* cosEdge)
{
// set line attributes of a cosmetic edge
- cosEdge->m_format.m_style = 2;
+ cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle();
cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue();
cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue();
cosEdge->m_format.m_lineNumber = _getActiveLineAttributes().getStyle();
@@ -2216,7 +2139,7 @@ void _setLineAttributes(TechDraw::CenterLine* cosEdge)
void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight, App::Color color)
{
// set line attributes of a cosmetic edge
- cosEdge->m_format.m_style = 2;
+ cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle();
cosEdge->m_format.m_weight = weight;
cosEdge->m_format.m_color = color;
cosEdge->m_format.m_lineNumber = style;
@@ -2225,7 +2148,7 @@ void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight
void _setLineAttributes(TechDraw::CenterLine* cosEdge, int style, float weight, App::Color color)
{
// set line attributes of a centerline
- cosEdge->m_format.m_style = 2;
+ cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle();
cosEdge->m_format.m_lineNumber = style;
cosEdge->m_format.m_weight = weight;
cosEdge->m_format.m_color = color;
@@ -2242,7 +2165,6 @@ void CreateTechDrawCommandsExtensions()
rcCmdMgr.addCommand(new CmdTechDrawExtensionExtendLine());
rcCmdMgr.addCommand(new CmdTechDrawExtensionShortenLine());
rcCmdMgr.addCommand(new CmdTechDrawExtensionLockUnlockView());
- rcCmdMgr.addCommand(new CmdTechDrawExtensionPositionSectionView());
rcCmdMgr.addCommand(new CmdTechDrawExtensionChangeLineAttributes());
rcCmdMgr.addCommand(new CmdTechDrawExtensionCircleCenterLinesGroup());
rcCmdMgr.addCommand(new CmdTechDrawExtensionCircleCenterLines());
diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp
index ecbc67618b..896384243d 100644
--- a/src/Mod/TechDraw/Gui/Workbench.cpp
+++ b/src/Mod/TechDraw/Gui/Workbench.cpp
@@ -126,8 +126,9 @@ Gui::MenuItem* Workbench::setupMenuBar() const
*toolcenter << "TechDraw_ExtensionThreadBoltSide";
*toolcenter << "TechDraw_ExtensionThreadBoltBottom";
*toolcenter << "Separator";
- *toolcenter << "TechDraw_CommandVertexCreationGroup";
- //*toolcenter << "TechDraw_ExtensionVertexAtIntersection";
+ *toolcenter << "TechDraw_ExtensionVertexAtIntersection";
+ *toolcenter << "TechDraw_CommandAddOffsetVertex";
+ *toolcenter << "Separator";
*toolcenter << "TechDraw_ExtensionDrawCosmCircle";
*toolcenter << "TechDraw_ExtensionDrawCosmArc";
*toolcenter << "TechDraw_ExtensionDrawCosmCircle3Points";
diff --git a/src/Mod/TechDraw/TechDrawTools/CommandPositionSectionView.py b/src/Mod/TechDraw/TechDrawTools/CommandPositionSectionView.py
new file mode 100644
index 0000000000..dea569c631
--- /dev/null
+++ b/src/Mod/TechDraw/TechDrawTools/CommandPositionSectionView.py
@@ -0,0 +1,130 @@
+# ***************************************************************************
+# * Copyright (c) 2023 edi *
+# * *
+# * This program is free software; you can redistribute it and/or modify *
+# * it under the terms of the GNU Lesser General Public License (LGPL) *
+# * as published by the Free Software Foundation; either version 2 of *
+# * the License, or (at your option) any later version. *
+# * for detail see the LICENCE text file. *
+# * *
+# * This program 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 program; if not, write to the Free Software *
+# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
+# * USA *
+# * *
+# ***************************************************************************
+"""
+Provides the TechDraw PositionSectionView GuiCommand.
+00.01 2021/03/17 C++ Basic version
+00.02 2023/12/21 Option to select an edge and it's corresponding vertex
+"""
+
+__title__ = "TechDrawTools.CommandPositionSectionView"
+__author__ = "edi"
+__url__ = "https://www.freecad.org"
+__version__ = "00.02"
+__date__ = "2023/12/21"
+
+from PySide.QtCore import QT_TRANSLATE_NOOP
+
+import FreeCAD as App
+import FreeCADGui as Gui
+
+import TechDrawTools.TDToolsUtil as Utils
+
+class CommandPositionSectionView:
+ """Orthogonally align a section view with its source view."""
+
+ def __init__(self):
+ """Initialize variables for the command that must exist at all times."""
+ pass
+
+ def GetResources(self):
+ """Return a dictionary with data that will be used by the button or menu item."""
+ return {'Pixmap': 'TechDraw_ExtensionPositionSectionView.svg',
+ 'Accel': "",
+ 'MenuText': QT_TRANSLATE_NOOP("TechDraw_PositionSectionView", "Position Section View"),
+ 'ToolTip': QT_TRANSLATE_NOOP("TechDraw_PositionSectionView",
+ "Orthogonally align a section view with its source view:
\
+ - Select a single section view
\
+ - Click this tool
\
+ - optional: select one edge in the section view and it's corresponding vertex in the base view
\
+ Click this tool")}
+
+ def Activated(self):
+ """Run the following code when the command is activated (button pressed)."""
+ selection = Gui.Selection.getSelectionEx()
+ if not selection:
+ return
+ if len(selection) == 1:
+ if Utils.getSelView():
+ sectionView = Utils.getSelView()
+ if sectionView.TypeId == 'TechDraw::DrawViewSection':
+ baseView = sectionView.BaseView
+ if baseView.TypeId == "TechDraw::DrawProjGroupItem":
+ baseView = baseView.InList[0]
+ basePoint = App.Vector(baseView.X,baseView.Y,0.0)
+ sectionPoint = App.Vector(sectionView.X,sectionView.Y,0.0)
+ moveVector = sectionPoint.sub(basePoint)
+ if abs(moveVector.x) > abs(moveVector.y):
+ moveVector.x = 0.0
+ else:
+ moveVector.y = 0.0
+ else:
+ return
+
+ elif len(selection) == 2:
+ if Utils.getSelEdges() and Utils.getSelVertexes(1,1):
+ sectionEdge = Utils.getSelEdges()
+ sectionDir = sectionEdge[0].Curve.Direction
+ sectionSel = sectionEdge[0].Vertexes
+ baseSel = Utils.getSelVertexes(1,1)
+ sectionView = Utils.getSelView(0)
+ baseView = Utils.getSelView(1)
+ if baseView.TypeId == "TechDraw::DrawProjGroupItem":
+ baseView = baseView.InList[0]
+
+ basePoint = baseSel[0].Point
+ sectionPoint = sectionSel[0].Point
+ Scale = baseView.Scale
+ centerBase = App.Vector(baseView.X,baseView.Y,0)
+ basePoint = centerBase+basePoint*Scale
+ centerSection = App.Vector(sectionView.X,sectionView.Y,0)
+ sectionPoint = centerSection+sectionPoint*Scale
+ sectionPoint = self.getTrianglePoint(sectionPoint,sectionDir,basePoint)
+ moveVector = sectionPoint.sub(basePoint)
+ else:
+ return
+
+ sectionView.X = sectionView.X.Value-moveVector.x
+ sectionView.Y = sectionView.Y.Value-moveVector.y
+
+ def IsActive(self):
+ """Return True when the command should be active or False when it should be disabled (greyed)."""
+ if App.ActiveDocument:
+ return Utils.havePage() and Utils.haveView()
+ else:
+ return False
+
+ def getTrianglePoint(self,p1,dir,p2):
+ '''
+ Get third point of a perpendicular triangle
+ p1, p2 ...vertexes of hypothenusis, dir ...direction of one kathete, p3 ...3rd vertex
+ '''
+ a = -dir.y
+ b = dir.x
+ c1 = p1.x * a + p1.y * b
+ c2 = -p2.x * b + p2.y * a
+ ab = a * a + b * b
+ x = (c1 * a - c2 * b) / ab
+ y = (c2 * a + c1 * b) / ab
+ return App.Vector(x,y,0.0)
+
+# The command must be "registered" with a unique name by calling its class.
+Gui.addCommand('TechDraw_ExtensionPositionSectionView', CommandPositionSectionView())
+
diff --git a/src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py b/src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py
index cd9f621152..68a6621377 100644
--- a/src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py
+++ b/src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py
@@ -51,32 +51,34 @@ def displayMessage(title,message):
msgBox.exec_()
-def getSelView():
+def getSelView(nSel=0):
'''
view = getSelView()
+ nSel=0 ... number of selected view, 0 = first selected
Return selected view, otherwise return False
'''
if not Gui.Selection.getSelection():
displayMessage('TechDraw_Utils','No view selected')
else:
- view = Gui.Selection.getSelection()[0]
+ view = Gui.Selection.getSelection()[nSel]
return view
-def getSelVertexes(nVertex=1):
+def getSelVertexes(nVertex=1, nSel=0):
'''
vertexes = getSelVertexes(nVertex)
- nVertex ... min. number of selected vertexes
+ nVertex=1 ... min. number of selected vertexes
+ nSel=0 ... number of selected view, 0 = first selected
Return a list of selected vertexes if at least nVertex vertexes are selected, otherwise return False
'''
- if getSelView():
- view = getSelView()
+ if getSelView(nSel):
+ view = getSelView(nSel)
else:
return False
if not Gui.Selection.getSelectionEx():
displayMessage('TechDraw_Utils',
QT_TRANSLATE_NOOP('TechDraw_Utils','No vertex selected'))
return False
- objectList = Gui.Selection.getSelectionEx()[0].SubElementNames
+ objectList = Gui.Selection.getSelectionEx()[nSel].SubElementNames
vertexes = []
for objectString in objectList:
@@ -92,21 +94,22 @@ def getSelVertexes(nVertex=1):
else:
return vertexes
-def getSelEdges(nEdge=1):
+def getSelEdges(nEdge=1, nSel=0):
'''
edges = getSelEdges(nEdge)
- nEdge ... min. number of selected edges
+ nEdge=1 ... min. number of selected edges
+ nSel=0 ... number of selected view, 0 = first selected
Return a list of selected edges if at least nedge edges are selected, otherwise return False
'''
- if getSelView():
- view = getSelView()
+ if getSelView(nSel):
+ view = getSelView(nSel)
else:
return False
if not Gui.Selection.getSelectionEx():
displayMessage('TechDraw_Utils',
QT_TRANSLATE_NOOP('TechDraw_Utils','No edge selected'))
return False
- objectList = Gui.Selection.getSelectionEx()[0].SubElementNames
+ objectList = Gui.Selection.getSelectionEx()[nSel].SubElementNames
edges = []
for objectString in objectList:
diff --git a/src/Mod/TechDraw/TechDrawTools/__init__.py b/src/Mod/TechDraw/TechDrawTools/__init__.py
index f0900fd943..2b67aa1ba6 100644
--- a/src/Mod/TechDraw/TechDrawTools/__init__.py
+++ b/src/Mod/TechDraw/TechDrawTools/__init__.py
@@ -34,6 +34,7 @@ from .TDToolsUtil import *
from .CommandShareView import CommandShareView
from .CommandMoveView import CommandMoveView
from .CommandAxoLengthDimension import CommandAxoLengthDimension
+from .CommandPositionSectionView import CommandPositionSectionView
from .CommandVertexCreations import CommandVertexCreationGroup
from .CommandHoleShaftFit import CommandHoleShaftFit
from .CommandFillTemplateFields import CommandFillTemplateFields