[TD] Add Command Axo Length Dimension

Co-authored-by: Benjamin Bræstrup Sayoc <[email protected]>
This commit is contained in:
edi271
2023-02-05 14:50:44 -08:00
committed by WandererFan
co-authored by Benjamin Bræstrup Sayoc
parent f09d038ff5
commit 2c931a88b0
6 changed files with 389 additions and 0 deletions
+1
View File
@@ -20,6 +20,7 @@ set(TechDraw_ToolsScripts
TechDrawTools/__init__.py
TechDrawTools/CommandMoveView.py
TechDrawTools/CommandShareView.py
TechDrawTools/CommandAxoLengthDimension.py
TechDrawTools/TaskMoveView.py
TechDrawTools/TaskShareView.py
TechDrawTools/TDToolsUtil.py
@@ -28,6 +28,7 @@
<file>icons/actions/TechDraw_Line2Points.svg</file>
<file>icons/actions/TechDraw_Midpoints.svg</file>
<file>icons/actions/TechDraw_MoveView.svg</file>
<file>icons/actions/TechDraw_AxoLengthDimension.svg</file>
<file>icons/actions/TechDraw_Multiview.svg</file>
<file>icons/actions/TechDraw_PageDefault.svg</file>
<file>icons/actions/TechDraw_PageTemplate.svg</file>
@@ -0,0 +1,259 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
id="svg5821"
height="64px"
width="64px">
<defs
id="defs5823">
<linearGradient
id="linearGradient3026">
<stop
style="stop-color:#c4a000;stop-opacity:1"
offset="0"
id="stop3028" />
<stop
style="stop-color:#fce94f;stop-opacity:1"
offset="1"
id="stop3030" />
</linearGradient>
<linearGradient
id="linearGradient3014">
<stop
style="stop-color:#c4a000;stop-opacity:1"
offset="0"
id="stop3016" />
<stop
style="stop-color:#fce94f;stop-opacity:1"
offset="1"
id="stop3018" />
</linearGradient>
<linearGradient
id="linearGradient6349">
<stop
id="stop6351"
offset="0"
style="stop-color:#000000;stop-opacity:1;" />
<stop
id="stop6353"
offset="1"
style="stop-color:#000000;stop-opacity:0;" />
</linearGradient>
<linearGradient
id="linearGradient3377">
<stop
id="stop3379"
offset="0"
style="stop-color:#0019a3;stop-opacity:1;" />
<stop
id="stop3381"
offset="1"
style="stop-color:#0069ff;stop-opacity:1;" />
</linearGradient>
<linearGradient
gradientTransform="matrix(-1,0,0,1,2199.356,0)"
gradientUnits="userSpaceOnUse"
y2="1190.875"
x2="1267.9062"
y1="1190.875"
x1="901.1875"
id="linearGradient3383"
xlink:href="#linearGradient3377" />
<radialGradient
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-1.4307499,-1.3605156e-7,-1.202713e-8,0.1264801,2674.7488,1244.2826)"
r="194.40614"
fy="1424.4465"
fx="1103.6399"
cy="1424.4465"
cx="1103.6399"
id="radialGradient6355"
xlink:href="#linearGradient6349" />
<linearGradient
gradientUnits="userSpaceOnUse"
y2="16"
x2="31"
y1="50"
x1="35"
id="linearGradient3899"
xlink:href="#linearGradient3893" />
<linearGradient
id="linearGradient3893">
<stop
id="stop3895"
offset="0"
style="stop-color:#d3d7cf;stop-opacity:1" />
<stop
id="stop3897"
offset="1"
style="stop-color:#ffffff;stop-opacity:1" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient3014"
id="linearGradient4075"
gradientUnits="userSpaceOnUse"
x1="43.288891"
y1="40.227509"
x2="25.445223"
y2="28.399185"
gradientTransform="matrix(0.79379811,0.51612921,-0.5053281,0.80071737,36.935227,-10.31149)" />
<linearGradient
gradientUnits="userSpaceOnUse"
y2="4.7365441"
x2="21.564972"
y1="10.393398"
x1="39.949749"
id="linearGradient3907-7"
xlink:href="#linearGradient3893-4"
gradientTransform="matrix(0.70710678,0.70710678,-0.70710678,0.70710678,34.704127,-9.9426796)" />
<linearGradient
id="linearGradient3893-4">
<stop
id="stop3895-0"
offset="0"
style="stop-color:#d3d7cf;stop-opacity:1" />
<stop
id="stop3897-9"
offset="1"
style="stop-color:#ffffff;stop-opacity:1" />
</linearGradient>
<linearGradient
y2="4.7365441"
x2="21.564972"
y1="10.393398"
x1="39.949749"
gradientTransform="rotate(45,2.9067431,-25.399527)"
gradientUnits="userSpaceOnUse"
id="linearGradient2592"
xlink:href="#linearGradient3026" />
<linearGradient
y2="4.7365441"
x2="21.564972"
y1="10.393398"
x1="39.949749"
gradientTransform="rotate(45,2.9067431,-25.399527)"
gradientUnits="userSpaceOnUse"
id="linearGradient2614"
xlink:href="#linearGradient3026" />
<radialGradient
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.36236392,0,18.561168)"
r="17.582031"
fy="29.109344"
fx="-12.099726"
cy="29.109344"
cx="-12.099726"
id="radialGradient2643"
xlink:href="#linearGradient3026" />
<linearGradient
gradientTransform="translate(-8.8768642,-21.6292)"
gradientUnits="userSpaceOnUse"
y2="45.847584"
x2="58.249027"
y1="45.847584"
x1="10.628253"
id="linearGradient1587"
xlink:href="#linearGradient3026" />
<linearGradient
y2="45.847584"
x2="58.249027"
y1="45.847584"
x1="10.628253"
gradientTransform="translate(-10.511801,-23.988397)"
gradientUnits="userSpaceOnUse"
id="linearGradient2339"
xlink:href="#linearGradient3026" />
</defs>
<metadata
id="metadata5826">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:creator>
<cc:Agent>
<dc:title>[WandererFan]</dc:title>
</cc:Agent>
</dc:creator>
<dc:title>TechDraw_Dimension</dc:title>
<dc:date>2016-04-27</dc:date>
<dc:relation>http://www.freecadweb.org/wiki/index.php?title=Artwork</dc:relation>
<dc:publisher>
<cc:Agent>
<dc:title>FreeCAD</dc:title>
</cc:Agent>
</dc:publisher>
<dc:identifier>FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Dimension.svg</dc:identifier>
<dc:rights>
<cc:Agent>
<dc:title>FreeCAD LGPL2+</dc:title>
</cc:Agent>
</dc:rights>
<cc:license
rdf:resource="https://www.gnu.org/licenses/lgpl-3.0.en.html">https://www.gnu.org/copyleft/lesser.html</cc:license>
<dc:contributor>
<cc:Agent>
<dc:title>[agryson] Alexander Gryson</dc:title>
</cc:Agent>
</dc:contributor>
<dc:subject>
<rdf:Bag>
<rdf:li>arrow</rdf:li>
<rdf:li>double arrow</rdf:li>
<rdf:li>diagonal</rdf:li>
</rdf:Bag>
</dc:subject>
<dc:description>Double arrow at an angle between two diagonal lines</dc:description>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(2.0532964,6.9603974)"
id="g2395">
<path
style="fill:url(#linearGradient2339);fill-opacity:1;stroke:#302b00;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 1.116452,30.859187 H 23.283739 L 23.045821,1.4353944 28.997493,1.3164354 29.235411,28.0748 40.168497,9.3164362 44.833924,12.554354 29.949166,36.572942 1.116452,36.691901 Z"
id="path1575" />
<g
id="g2384"
transform="translate(0.59479557,-1.070632)">
<path
id="path3770-1"
d="m 46.16829,19.406804 3.175193,2.064518 -11.117219,17.615783 -3.175192,-2.064519 c 0.86541,3.950541 0.937023,7.384951 0.720164,9.502516 l -0.216858,2.117563 1.804454,-1.085304 c 1.804454,-1.085306 4.908034,-2.4552 8.805414,-3.308964 l -3.175193,-2.064518 11.117218,-17.615782 3.175193,2.064518 C 56.416054,22.682074 56.344441,19.247664 56.5613,17.130099 l 0.216857,-2.117563 -1.804453,1.085304 c -1.804455,1.085307 -4.908035,2.4552 -8.805414,3.308964 z"
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;baseline-shift:baseline;text-anchor:start;display:inline;overflow:visible;visibility:visible;fill:url(#linearGradient4075);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;enable-background:accumulate" />
<path
id="path3864"
d="m 54.142071,17.645379 -6.207159,2.739789"
style="fill:none;stroke:#fce94f;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path3864-4"
d="M 36.781892,44.923666 36.720553,38.61818"
style="fill:none;stroke:#fce94f;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path3866"
d="M 54.973704,16.09784 35.269787,47.251482"
style="fill:none;stroke:#fce94f;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path3868"
d="m 49.343483,21.471322 3.10358,-1.369893"
style="fill:none;stroke:#fce94f;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path3868-8"
d="m 38.226264,39.087105 0.07161,3.434409"
style="fill:none;stroke:#fce94f;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path3770-9"
d="m 46.273973,18.800417 3.402354,2.179571 -11.987638,18.712942 -3.402353,-2.179572 c 0.917088,4.186444 0.983587,7.827993 0.744389,10.074063 l -0.239196,2.246067 1.940373,-1.156282 c 1.940373,-1.156285 5.276227,-2.618264 9.462671,-3.535351 l -3.402354,-2.179571 11.987636,-18.712941 3.402354,2.179571 C 57.265122,22.24247 57.198622,18.600921 57.437819,16.354851 l 0.239197,-2.246068 -1.940373,1.156282 c -1.940374,1.156286 -5.276227,2.618264 -9.46267,3.535352 z"
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;baseline-shift:baseline;text-anchor:start;display:inline;overflow:visible;visibility:visible;fill:none;stroke:#302b00;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;enable-background:accumulate" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 10 KiB

+3
View File
@@ -152,6 +152,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
*annotations << "TechDraw_Annotation";
*annotations << "TechDraw_RichTextAnnotation";
*annotations << "TechDraw_Balloon";
*annotations << "TechDraw_AxoLengthDimension";
// stacking
Gui::MenuItem* stacking = new Gui::MenuItem;
@@ -280,6 +281,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
// *dims << "TechDraw_VerticalExtentDimension";
*dims << "TechDraw_LinkDimension";
*dims << "TechDraw_Balloon";
*dims << "TechDraw_AxoLengthDimension";
*dims << "TechDraw_LandmarkDimension";
// *dims << "TechDraw_Dimension"
*dims << "TechDraw_DimensionRepair";
@@ -428,6 +430,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const
// *dims << "TechDraw_VerticalExtentDimension";
*dims << "TechDraw_LinkDimension";
*dims << "TechDraw_Balloon";
*dims << "TechDraw_AxoLengthDimension";
*dims << "TechDraw_LandmarkDimension";
// *dims << "TechDraw_Dimension";
*dims << "TechDraw_DimensionRepair";
@@ -0,0 +1,124 @@
# ***************************************************************************
# * Copyright (c) 2023 edi <[email protected]> *
# * *
# * 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 AxoLengthDimension GuiCommand."""
__title__ = "TechDrawTools.CommandAxoLengthDimension"
__author__ = "edi"
__url__ = "https://www.freecadweb.org"
__version__ = "00.01"
__date__ = "2023/02/01"
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD as App
import FreeCADGui as Gui
import TechDrawTools
import TechDraw
from math import degrees
class CommandAxoLengthDimension:
"""Creates a 3D length dimension."""
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': 'actions/TechDraw_AxoLengthDimension.svg',
'Accel': "",
'MenuText': QT_TRANSLATE_NOOP("TechDraw_AxoLengthDimension", "Axonometric length dimension"),
'ToolTip': QT_TRANSLATE_NOOP("TechDraw_AxoLengthDimension", "Create an axonometric length dimension<br>\
- select first edge to define direction and length of the dimension line<br>\
- select second edge to define the direction of the extension lines<br>\
- optional: select two more vertexes which define the measurement instead of the length<br>\
of the first selected edge")}
def Activated(self):
"""Run the following code when the command is activated (button press)."""
if self.selectionTest():
(edges,vertexes) = self.selectionTest()
view = Gui.Selection.getSelection()[0]
StartPt, EndPt = edges[1].Vertexes[0].Point, edges[1].Vertexes[1].Point
extLineVec = EndPt.sub(StartPt)
StartPt, EndPt = edges[0].Vertexes[0].Point, edges[0].Vertexes[1].Point
dimLineVec = EndPt.sub(StartPt)
xAxis = App.Vector(1,0,0)
extAngle = degrees(extLineVec.getAngle(xAxis))
lineAngle = degrees(dimLineVec.getAngle(xAxis))
if extLineVec.y < 0.0:
extAngle = 180-extAngle
if dimLineVec.y < 0.0:
lineAngle = 180-lineAngle
if abs(extAngle-lineAngle)>0.1:
distanceDim=TechDraw.makeDistanceDim(view,'Distance',vertexes[0].Point,vertexes[1].Point)
distanceDim.AngleOverride = True
distanceDim.LineAngle = lineAngle
distanceDim.ExtensionAngle = extAngle
distanceDim.X = (vertexes[0].Point.x+vertexes[1].Point.x)/2
distanceDim.Y = (vertexes[0].Point.y+vertexes[1].Point.y)/2
distanceDim.recompute()
view.requestPaint()
Gui.Selection.clearSelection()
def IsActive(self):
"""Return True when the command should be active or False when it should be disabled (greyed)."""
if App.ActiveDocument:
return TechDrawTools.TDToolsUtil.havePage() and TechDrawTools.TDToolsUtil.haveView()
else:
return False
def selectionTest(self):
'''test correct selection'''
if not Gui.Selection.getSelection():
return False
view = Gui.Selection.getSelection()[0]
if not Gui.Selection.getSelectionEx():
return False
objectList = Gui.Selection.getSelectionEx()[0].SubElementNames
if not len(objectList)>=2:
return False
edges = []
vertexes = []
for objectString in objectList:
if objectString[0:4] == 'Edge':
edges.append(view.getEdgeBySelection(objectString))
elif objectString[0:6] == 'Vertex':
vertexes.append(view.getVertexBySelection(objectString))
if not len(edges) >= 2:
return False
if len(vertexes)<2:
vertexes = []
vertexes.append(edges[0].Vertexes[0])
vertexes.append(edges[0].Vertexes[1])
return(edges,vertexes)
#
# The command must be "registered" with a unique name by calling its class.
Gui.addCommand('TechDraw_AxoLengthDimension', CommandAxoLengthDimension())
@@ -33,5 +33,6 @@ from .TDToolsMovers import *
from .TDToolsUtil import *
from .CommandShareView import CommandShareView
from .CommandMoveView import CommandMoveView
from .CommandAxoLengthDimension import CommandAxoLengthDimension
from .TaskShareView import TaskShareView
from .TaskMoveView import TaskMoveView