Update TechDraw Unit Test set

Allow unit test to run in console mode

Change to unique document names for each unit test

Fix error in CMake install for test files

Correct Py3/Py2 unicode error
This commit is contained in:
WandererFan
2018-01-30 16:30:23 -05:00
committed by wmayer
parent 337619f245
commit 6bd237e41e
14 changed files with 2378 additions and 28 deletions

View File

@@ -41,3 +41,37 @@ INSTALL(
FILES_MATCHING
PATTERN "*.csv*"
)
#unit test files
SET(TDTest_SRCS
TDTest/__init__.py
TDTest/DHatchTest.py
TDTest/DProjGroupTest.py
TDTest/DVAnnoSymImageTest.py
TDTest/DVDimensionTest.py
TDTest/DVPartTest.py
TDTest/DVSectionTest.py
)
SET(TDTestFile_SRCS
TDTest/TestHatch.svg
TDTest/TestImage.png
TDTest/TestSymbol.svg
TDTest/TestTemplate.svg
)
SET(TDAllTest
${TDTest_SRCS}
${TDTestFile_SRCS}
)
ADD_CUSTOM_TARGET(TDTestTarget ALL
SOURCES ${TDAllTest}
)
fc_copy_sources(TDTestTarget "${CMAKE_BINARY_DIR}/Mod/TechDraw" ${TDAllTest})
# install Python packages (for make install)
INSTALL(FILES ${TDTest_SRCS} DESTINATION Mod/TechDraw/TDTest)
INSTALL(FILES ${TDTestFile_SRCS} DESTINATION Mod/TechDraw/TDTest)

View File

@@ -0,0 +1,61 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# test script for TechDraw module
# creates a page and 1 views
# adds a hatch area to view1
from __future__ import print_function
import FreeCAD
import Part
import Measure
import TechDraw
import os
def DHatchTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDHatch path: ' + path)
templateFileSpec = path+'/TestTemplate.svg'
hatchFileSpec = path + '/TestHatch.svg'
FreeCAD.newDocument("TDHatch")
FreeCAD.setActiveDocument("TDHatch")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDHatch")
#make source feature
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
#make a page
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() #unit tests run in console mode
#make Views
view1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
FreeCAD.ActiveDocument.View.Source = [box]
rc = page.addView(view1)
FreeCAD.ActiveDocument.recompute()
#make hatch
print("making hatch")
hatch = FreeCAD.ActiveDocument.addObject('TechDraw::DrawHatch','Hatch')
hatch.Source = (view1,["Face0"])
hatch.HatchPattern = hatchFileSpec #comment out to use default from preferences
print("adding hatch to page")
rc = page.addView(hatch)
print("finished hatch")
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in hatch.State):
rc = True
FreeCAD.closeDocument("TDHatch")
return rc
if __name__ == '__main__':
DHatchTest()

View File

@@ -0,0 +1,79 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# test script for TechDraw module
# creates a Box and a Sphere and makes a Fusions from them
# creates a page
# creates a Projection Group
# adds Front,Left,Top projections to the group
# a template in the source folder
from __future__ import print_function
import FreeCAD
import Part
import Measure
import TechDraw
import os
def DProjGroupTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDGroup path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
FreeCAD.newDocument("TDGroup")
FreeCAD.setActiveDocument("TDGroup")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDGroup")
#make Fusion feature
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
sphere = FreeCAD.ActiveDocument.addObject("Part::Sphere","Sphere")
fusion = FreeCAD.ActiveDocument.addObject("Part::MultiFuse","Fusion")
FreeCAD.ActiveDocument.Fusion.Shapes = [box,sphere]
#make a page
print("making a page")
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
# page.ViewObject.show() #unit tests run in console mode
#make projection group
print("making a projection group")
group = FreeCAD.ActiveDocument.addObject('TechDraw::DrawProjGroup','ProjGroup')
rc = page.addView(group)
group.Source = [fusion]
print("adding views")
leftView = group.addProjection("Left")
print("added Left")
topView = group.addProjection("Top")
print("added Top")
rightView = group.addProjection("Right")
print("added Right")
rearView = group.addProjection("Rear")
print("added Rear")
BottomView = group.addProjection("Bottom")
print("added Bottom")
#remove a view from projection group
#iv = group.removeProjection("Left")
#print("removed Left")
##test getItemByLabel method
print("testing getItemByLabel")
label = "Top"
item = group.getItemByLabel(label)
print("Item Label: " + label + " Item Name: " + item.Name)
print("recomputing document")
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in group.State):
rc = True
FreeCAD.closeDocument("TDGroup")
return rc
if __name__ == '__main__':
DProjGroupTest()

View File

@@ -0,0 +1,65 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# annotation & symbol test script for TechDraw module
# creates a page, 1 annotation and import 1 symbol
from __future__ import print_function
import FreeCAD
import Part
import Measure
import TechDraw
import os
def DVAnnoSymImageTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDTestAnno path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
symbolFileSpec = path + '/TestSymbol.svg'
imageFileSpec = path + '/TestImage.png'
FreeCAD.newDocument("TDAnno")
FreeCAD.setActiveDocument("TDAnno")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDAnno")
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
# page.ViewObject.show() # unit tests run in console mode
#annotation
anno = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewAnnotation','TestAnno')
s = 'Different Text'
sl = list()
sl.append(s)
anno.Text = sl
anno.TextStyle = 'Bold'
rc = page.addView(anno)
anno.X = 30.0
anno.Y = 150.0
#symbol
sym = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSymbol','TestSymbol')
f = open(symbolFileSpec, 'r')
svg = f.read()
f.close()
sym.Symbol = svg
rc = page.addView(sym)
sym.X = 220.0
sym.Y = 150.0
#image
img = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewImage','TestImage')
img.ImageFile = imageFileSpec
rc = page.addView(img)
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in anno.State) and ("Up-to-date" in sym.State) and ("Up-to-date" in img.State):
rc = True
FreeCAD.closeDocument("TDAnno")
return rc
if __name__ == '__main__':
DVAnnoSymImageTest()

View File

@@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# test script for TechDraw module
# creates a page and 2 views
# adds 1 length dimension to view1
# adds 1 radius dimension to view2
from __future__ import print_function
import FreeCAD
import Part
import Measure
import TechDraw
import os
def DVDimensionTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDDim path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
FreeCAD.newDocument("TDDim")
FreeCAD.setActiveDocument("TDDim")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDDim")
#make source feature
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
sphere = FreeCAD.ActiveDocument.addObject("Part::Sphere","Sphere")
#make a page
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
#make Views
view1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
rc = page.addView(view1)
view1.X = 30
view1.Y = 150
view2 = FreeCAD.activeDocument().addObject('TechDraw::DrawViewPart','View001')
FreeCAD.activeDocument().View001.Source = [FreeCAD.activeDocument().Sphere]
rc = page.addView(view2)
view2.X = 220
view2.Y = 150
FreeCAD.ActiveDocument.recompute()
#make length dimension
print("making length dimension")
dim1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewDimension','Dimension')
dim1.Type = "Distance"
objs = list()
objs.append(view1)
subObjs = list()
subObjs.append("Edge1")
dim1.References2D=[(view1, 'Edge1')]
print("adding dim1 to page")
rc = page.addView(dim1)
print("finished length dimension")
#make radius dimension
print("making radius dimension")
dim2 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewDimension','Dimension001')
dim2.Type = "Radius"
dim2.MeasureType = "Projected"
dim2.References2D=[(view2, 'Edge0')]
rc = page.addView(dim2)
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in dim1.State) and ("Up-to-date" in dim2.State):
rc = True
FreeCAD.closeDocument("TDDim")
return rc
if __name__ == '__main__':
DVDimensionTest()

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# basic test script for TechDraw module
# creates a page and 1 view
from __future__ import print_function
import FreeCAD
import Part
import Measure
import TechDraw
import os
def DVPartTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDPart path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
FreeCAD.newDocument("TDPart")
FreeCAD.setActiveDocument("TDPart")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDPart")
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
print("page created")
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
rc = page.addView(view)
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in view.State):
rc = True
FreeCAD.closeDocument("TDPart")
return rc
if __name__ == '__main__':
DVPartTest()

View File

@@ -0,0 +1,60 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# test script for TechDraw module
# creates a page, 1 view and 1 section view
from __future__ import print_function
import FreeCAD
import Part
import Measure
import TechDraw
import os
def DVSectionTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDSection path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
FreeCAD.newDocument("TDSection")
FreeCAD.setActiveDocument("TDSection")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDSection")
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
print("page created")
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
rc = page.addView(view)
view.Source = [box]
view.Direction = (0.0,0.0,1.0)
view.Rotation = 0.0
view.X = 30.0
view.Y = 150.0
print("view created")
section = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSection','Section')
rc = page.addView(section)
section.Source = [box]
section.BaseView = view
section.Direction = (0.0,1.0,0.0)
section.SectionNormal = (0.0,1.0,0.0)
section.SectionOrigin = (5.0,5.0,5.0)
view.touch()
print("section created")
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in view.State) and ("Up-to-date" in section.State):
rc = True
FreeCAD.closeDocument("TDSection")
return rc
if __name__ == '__main__':
DVSectionTest()

View File

@@ -0,0 +1,111 @@
<?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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="svg2985"
version="1.1"
inkscape:version="0.48.3.1 r9886"
width="64"
height="64"
sodipodi:docname="simple.svg">
<metadata
id="metadata2994">
<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>
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1057"
id="namedview2992"
showgrid="true"
inkscape:zoom="10.148731"
inkscape:cx="33.765913"
inkscape:cy="28.771693"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg2985">
<inkscape:grid
type="xygrid"
id="grid2996"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
spacingx="8px"
spacingy="8px" />
</sodipodi:namedview>
<defs
id="defs2987">
<pattern
id="simple"
patternUnits="userSpaceOnUse"
x="0"
y="0"
width=".1"
height=".1">
<g
style="fill:none; stroke:#000000; stroke-width:.005"
id="g3377">
<path
d="M0,0 l.12,.12"
id="path3379" />
</g>
</pattern>
</defs>
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 64,0 0,64"
id="path2998"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 48,0 0,48"
id="path3000"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 16,64 64,16"
id="path3002"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 32,0 0,32"
id="path3004"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 16,0 0,16"
id="path3006"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 64,32 32,64"
id="path3008"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 64,48 48,64"
id="path3010"
inkscape:connector-curvature="0" />
</svg>

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<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"
version="1.1"
width="100"
height="100"
id="svg2">
<defs
id="defs4" />
<metadata
id="metadata7">
<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>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-952.36218)"
id="layer1">
<path
d="m 48.571428,33.57143 a 18.571428,18.571428 0 1 1 -37.142856,0 18.571428,18.571428 0 1 1 37.142856,0 z"
transform="translate(20,968.79075)"
id="path2985"
style="color:#000000;fill:none;stroke:#ff0000;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<rect
width="78.571426"
height="78.571426"
rx="0.14904857"
ry="0.14904857"
x="10.714287"
y="963.07648"
id="rect2989"
style="color:#000000;fill:none;stroke:#0000ff;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<text
x="16.460938"
y="1013.8153"
id="text3761"
xml:space="preserve"
style="font-size:32px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Arial;-inkscape-font-specification:Arial"><tspan
x="16.460938"
y="1013.8153"
id="tspan3763">SVG</tspan><tspan
x="16.460938"
y="1053.8153"
id="tspan3765" /></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 75 KiB

View File

View File

@@ -25,39 +25,64 @@ import TechDraw
import time
App = FreeCAD
from TDTest.DHatchTest import DHatchTest
from TDTest.DProjGroupTest import DProjGroupTest
from TDTest.DVAnnoSymImageTest import DVAnnoSymImageTest
from TDTest.DVDimensionTest import DVDimensionTest
from TDTest.DVPartTest import DVPartTest
from TDTest.DVSectionTest import DVSectionTest
#---------------------------------------------------------------------------
# define the test cases to test the FreeCAD TechDraw module
#---------------------------------------------------------------------------
class TechDrawTestCases(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("TechDrawTest")
def testViewPartCase(self):
print("starting TD DrawViewPart test")
rc = DVPartTest()
if rc:
print("TD DrawViewPart test passed")
else:
print("TD DrawViewPart test failed")
def testPageCase(self):
self.templateFileSpec = App.getResourceDir() + 'Mod/TechDraw/Templates/A4_LandscapeTD.svg'
self.Box = self.Doc.addObject("Part::Box","Box")
self.Page = self.Doc.addObject('TechDraw::DrawPage','Page')
self.Template = self.Doc.addObject('TechDraw::DrawSVGTemplate','Template')
self.Template.Template = self.templateFileSpec
self.Page.Template = self.Template
self.View = self.Doc.addObject('TechDraw::DrawViewPart','View')
rc = self.Page.addView(self.View)
self.View.Source = self.Box
self.Anno = self.Doc.addObject('TechDraw::DrawViewAnnotation','TestAnno')
rc = self.Page.addView(self.Anno)
self.Sect = self.Doc.addObject('TechDraw::DrawViewSection','Section')
self.Sect.Source = self.Box
self.Sect.Direction = FreeCAD.Vector(-1.0,0.0,0.0)
self.Sect.BaseView = self.View
self.Sect.SectionDirection = "Right"
self.Sect.SectionOrigin = FreeCAD.Vector(1.0,1.0,1.0)
self.Sect.SectionNormal = FreeCAD.Vector(-1.0,0.0,0.0)
rc = self.Page.addView(self.Sect)
self.Doc.recompute()
self.failUnless(len(self.Page.Views) == 3)
def testHatchCase(self):
print("starting TD DrawHatch test")
rc = DHatchTest()
if rc:
print("TD DrawHatch test passed")
else:
print("TD DrawHatch test failed")
def testAnnoSymImageCase(self):
print("starting TD DrawAnno/Sym/Image test")
rc = DVAnnoSymImageTest()
if rc:
print("TD DrawAnno/Sym/Image test passed")
else:
print("TD DrawAnno/Sym/Image test failed")
def testProjGroupCase(self):
print("starting TD DrawProjGroup test")
rc = DProjGroupTest()
if rc:
print("TD DrawProjGroup test passed")
else:
print("TD DrawProjGroup test failed")
def testDimensionCase(self):
print("starting TD DrawViewDimension test")
rc = DVDimensionTest()
if rc:
print("TD DrawViewDimension test passed")
else:
print("TD DrawViewDimension test failed")
def testSectionCase(self):
print("starting TD DrawViewSection test")
rc = DVSectionTest()
if rc:
print("TD DrawViewSection test passed")
else:
print("TD DrawViewSection test failed")
def tearDown(self):
#closing doc
FreeCAD.closeDocument("TechDrawTest")
#print ("omit closing document for debugging")

View File

@@ -0,0 +1,51 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# move Views from Drawing Page to TechDraw Page in the current document
# usage: select 1 Drawing Page and 1 TechDraw Page, run moveViews macro
# outcome: Content of Drawing Page will be inserted into TechDraw Page as DrawViewSymbol
# (ie an SVG symbol)
import FreeCAD
import Part
import Drawing
import TechDraw
svgHead = "<svg\n" + " xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n" + " xmlns:freecad=\"http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace\">\n"
svgTail = "\n</svg>"
def moveViews():
s = FreeCADGui.Selection.getSelection()
if len(s) != 2:
print "Please select 1 Drawing Page and 1 TechDraw Page"
return
print "First object in selection is a: ", s[0].TypeId
print "Second object in selection is a: ", s[1].TypeId
if s[0].isDerivedFrom("Drawing::FeaturePage") and \
s[1].isDerivedFrom("TechDraw::DrawPage"):
dPage = s[0]
tPage = s[1]
elif s[0].isDerivedFrom("TechDraw::DrawPage") and \
s[1].isDerivedFrom("Drawing::FeaturePage"):
tPage = s[0]
dPage = s[1]
else:
print "Please select 1 Drawing Page and 1 TechDraw Page"
return
i = 1
for o in dPage.OutList:
newName = "DraftView" + str(i).zfill(3)
print "moving " + o.Name + " to " + newName
svg = svgHead + o.ViewResult + svgTail
no = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSymbol',newName)
no.Symbol = svg
tPage.addView(no)
i += 1
print "moveViews moved " + str(i-1) + " views"
if __name__ == '__main__':
moveViews()