Skip to content

Commit

Permalink
Merge branch 'annotation_dragging' of https://github.com/hlorus/FreeCAD
Browse files Browse the repository at this point in the history
… into annotation_dragging
  • Loading branch information
hlorus committed Dec 3, 2023
2 parents 7c656e7 + 30679f7 commit d37406e
Show file tree
Hide file tree
Showing 21 changed files with 533 additions and 614 deletions.
41 changes: 21 additions & 20 deletions src/Mod/Arch/TestArch.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def testWall(self):
App.Console.PrintLog ('Checking Arch Wall...\n')
l=Draft.makeLine(App.Vector(0,0,0),App.Vector(-2,0,0))
w = Arch.makeWall(l)
self.failUnless(w,"Arch Wall failed")
self.assertTrue(w,"Arch Wall failed")

def testWallMultiMatAlign(self):
App.Console.PrintLog ('Checking Arch Wall with MultiMaterial and 3 alignments...\n')
Expand Down Expand Up @@ -429,16 +429,16 @@ def testWallMultiMatAlign(self):
App.ActiveDocument.recompute()
for box in [wallWire.Shape.BoundBox, wallSketch.Shape.BoundBox]:
ptMin = App.Vector(box.XMin, box.YMin, 0)
self.failUnless(ptMin.isEqual(checkLst[i][0], 1e-8),
self.assertTrue(ptMin.isEqual(checkLst[i][0], 1e-8),
"Arch Wall with MultiMaterial and 3 alignments failed")
ptMax = App.Vector(box.XMax, box.YMax, 0)
self.failUnless(ptMax.isEqual(checkLst[i][1], 1e-8),
self.assertTrue(ptMax.isEqual(checkLst[i][1], 1e-8),
"Arch Wall with MultiMaterial and 3 alignments failed")

def testStructure(self):
App.Console.PrintLog ('Checking Arch Structure...\n')
s = Arch.makeStructure(length=2,width=3,height=5)
self.failUnless(s,"Arch Structure failed")
self.assertTrue(s,"Arch Structure failed")

def testRebar(self):
App.Console.PrintLog ('Checking Arch Rebar...\n')
Expand All @@ -454,28 +454,28 @@ def testRebar(self):
sk.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1))
sk.addConstraint(Sketcher.Constraint('Coincident',3,2,0,1))
r = Arch.makeRebar(s,sk,diameter=.1,amount=2)
self.failUnless(r,"Arch Rebar failed")
self.assertTrue(r,"Arch Rebar failed")

def testFloor(self):
App.Console.PrintLog ('Checking Arch Floor...\n')
s = Arch.makeStructure(length=2,width=3,height=5)
f = Arch.makeFloor([s])
self.failUnless(f,"Arch Floor failed")
self.assertTrue(f,"Arch Floor failed")

def testBuilding(self):
App.Console.PrintLog ('Checking Arch Building...\n')
s = Arch.makeStructure(length=2,width=3,height=5)
f = Arch.makeFloor([s])
b = Arch.makeBuilding([f])
self.failUnless(b,"Arch Building failed")
self.assertTrue(b,"Arch Building failed")

def testSite(self):
App.Console.PrintLog ('Checking Arch Site...\n')
s = Arch.makeStructure(length=2,width=3,height=5)
f = Arch.makeFloor([s])
b = Arch.makeBuilding([f])
si = Arch.makeSite([b])
self.failUnless(si,"Arch Site failed")
self.assertTrue(si,"Arch Site failed")

def testWindow(self):
operation = "Arch Window"
Expand Down Expand Up @@ -503,7 +503,7 @@ def testRoof(self):
r = Draft.makeRectangle(length=2,height=-1)
r.recompute() # required before calling Arch.makeRoof
ro = Arch.makeRoof(r)
self.failUnless(ro,"Arch Roof failed")
self.assertTrue(ro,"Arch Roof failed")

def testRoof81Permutations(self):
"""Create 81 roofs using a range of arguments.
Expand Down Expand Up @@ -608,20 +608,20 @@ def testRoofSingleEavePoint(self):
def testAxis(self):
App.Console.PrintLog ('Checking Arch Axis...\n')
a = Arch.makeAxis()
self.failUnless(a,"Arch Axis failed")
self.assertTrue(a,"Arch Axis failed")

def testSection(self):
App.Console.PrintLog ('Checking Arch Section...\n')
s = Arch.makeSectionPlane([])
self.failUnless(s,"Arch Section failed")
self.assertTrue(s,"Arch Section failed")

def testSpace(self):
App.Console.PrintLog ('Checking Arch Space...\n')
sb = Part.makeBox(1,1,1)
b = App.ActiveDocument.addObject('Part::Feature','Box')
b.Shape = sb
s = Arch.makeSpace([b])
self.failUnless(s,"Arch Space failed")
self.assertTrue(s,"Arch Space failed")

def testSpaceBBox(self):
shape = Part.Shape()
Expand All @@ -634,19 +634,19 @@ def testSpaceBBox(self):
space.recompute()
bbnew = space.Shape.BoundBox
App.Console.PrintLog ("New BB: "+str(bbnew))
self.failUnless(checkBB(bborig,bbnew),"Arch Space has wrong Placement")
self.assertTrue(checkBB(bborig,bbnew),"Arch Space has wrong Placement")

def testStairs(self):
App.Console.PrintLog ('Checking Arch Stairs...\n')
s = Arch.makeStairs()
self.failUnless(s,"Arch Stairs failed")
self.assertTrue(s,"Arch Stairs failed")

def testFrame(self):
App.Console.PrintLog ('Checking Arch Frame...\n')
l=Draft.makeLine(App.Vector(0,0,0),App.Vector(-2,0,0))
p = Draft.makeRectangle(length=.5,height=.5)
f = Arch.makeFrame(l,p)
self.failUnless(f,"Arch Frame failed")
self.assertTrue(f,"Arch Frame failed")

def testEquipment(self):
App.Console.PrintLog ('Checking Arch Equipment...\n')
Expand All @@ -655,12 +655,12 @@ def testEquipment(self):
box.Width = 2000
box.Height = 600
equip = Arch.makeEquipment(box)
self.failUnless(equip,"Arch Equipment failed")
self.assertTrue(equip,"Arch Equipment failed")

def testPipe(self):
App.Console.PrintLog ('Checking Arch Pipe...\n')
pipe = Arch.makePipe(diameter=120, length=3000)
self.failUnless(pipe,"Arch Pipe failed")
self.assertTrue(pipe,"Arch Pipe failed")

def testAdd(self):
App.Console.PrintLog ('Checking Arch Add...\n')
Expand All @@ -673,7 +673,7 @@ def testAdd(self):
Arch.addComponents(b,w)
App.ActiveDocument.recompute()
r = (w.Shape.Volume > 1.5)
self.failUnless(r,"Arch Add failed")
self.assertTrue(r,"Arch Add failed")

def testRemove(self):
App.Console.PrintLog ('Checking Arch Remove...\n')
Expand All @@ -686,7 +686,7 @@ def testRemove(self):
Arch.removeComponents(b,w)
App.ActiveDocument.recompute()
r = (w.Shape.Volume < 0.75)
self.failUnless(r,"Arch Remove failed")
self.assertTrue(r,"Arch Remove failed")

def testBuildingPart(self):
"""Create a BuildingPart from a wall with a window and check its shape.
Expand Down Expand Up @@ -715,7 +715,8 @@ def testBuildingPart(self):
bp = Arch.makeBuildingPart()
bp.Group = [wall]
App.ActiveDocument.recompute()
self.assertTrue(len(bp.Shape.Faces) == 16, "'{}' failed".format(operation))
# Fails with OCC 7.5
# self.assertTrue(len(bp.Shape.Faces) == 16, "'{}' failed".format(operation))

def tearDown(self):
App.closeDocument("ArchTest")
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/Draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
removeHidden,
remove_hidden,
get_diffuse_color,
apply_current_style,
formatObject,
format_object,
getSelection,
Expand Down
12 changes: 5 additions & 7 deletions src/Mod/Draft/draftguitools/gui_setstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def getValues(self):

def setValues(self,preset):

# For compatibility with V0.21 and earlier some properties, if missing, revert to others:
# For compatibility with <= V0.21 some properties, if missing, reference others:
# 'new' prop -> old prop
# ---------------------------
# PointColor -> LineColor
Expand Down Expand Up @@ -261,12 +261,10 @@ def apply_style_to_obj(self, obj):
if "PointSize" in properties:
vobj.PointSize = self.form.PointSize.value()
if "DrawStyle" in properties:
dstyles = ["Solid", "Dashed", "Dotted", "Dashdot"]
vobj.DrawStyle = dstyles[self.form.DrawStyle.currentIndex()]
vobj.DrawStyle = utils.DRAW_STYLES[self.form.DrawStyle.currentIndex()]
if "DisplayMode" in properties:
dmodes = ["Flat Lines", "Shaded", "Wireframe", "Points"]
dm = dmodes[self.form.DisplayMode.currentIndex()]
if dm in vobj.getEnumerationsOfProperty("DisplayMode"):
dm = utils.DISPLAY_MODES[self.form.DisplayMode.currentIndex()]
if dm in vobj.listDisplayModes():
vobj.DisplayMode = dm
else: # Annotations
if "TextColor" in properties:
Expand All @@ -282,7 +280,7 @@ def apply_style_to_obj(self, obj):
if "LineWidth" in properties:
vobj.LineWidth = self.form.AnnoLineWidth.value()
if "ArrowType" in properties:
vobj.ArrowType = ["Dot", "Circle", "Arrow", "Tick", "Tick-2"][self.form.ArrowStyle.currentIndex()]
vobj.ArrowType = utils.ARROW_TYPES[self.form.ArrowStyle.currentIndex()]
if "ArrowSize" in properties:
vobj.ArrowSize = U.Quantity(self.form.ArrowSize.text()).Value
if "ShowUnit" in properties:
Expand Down
71 changes: 23 additions & 48 deletions src/Mod/Draft/draftguitools/gui_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,66 +32,41 @@
from PySide.QtCore import QT_TRANSLATE_NOOP

import FreeCADGui as Gui
import draftguitools.gui_base_original as gui_base_original

from draftguitools import gui_base_original
from draftutils.translate import translate

from draftutils import groups

class ApplyStyle(gui_base_original.Modifier):
"""Gui Command for the ApplyStyle tool."""

def GetResources(self):
"""Set icon, menu and tooltip."""
return {
"Pixmap": "Draft_Apply",
"MenuText": QT_TRANSLATE_NOOP("Draft_ApplyStyle", "Apply current style"),
"ToolTip": QT_TRANSLATE_NOOP("Draft_ApplyStyle", "Applies the current style defined in the toolbar (line width and colors) to the selected objects and groups.")
}

return {'Pixmap': 'Draft_Apply',
'MenuText': QT_TRANSLATE_NOOP("Draft_ApplyStyle", "Apply current style"),
'ToolTip': QT_TRANSLATE_NOOP("Draft_ApplyStyle", "Applies the current style defined in the toolbar (line width and colors) to the selected objects and groups.")}
def IsActive(self):
return bool(Gui.ActiveDocument and Gui.Selection.getSelection())

def Activated(self):
"""Execute when the command is called.
Activate the specific BSpline tracker.
"""
super(ApplyStyle, self).Activated(name="Apply style")
if self.ui:
self.sel = Gui.Selection.getSelection()
if len(self.sel) > 0:
Gui.addModule("Draft")
_cmd_list = []
for obj in self.sel:
# TODO: instead of `TypeId`, use `utils.get_type`
# to get the type of the object and apply different
# formatting information depending on the type of object.
# The groups may also be things like `App::Parts`
# or `Arch_BuildingParts`.
if obj.TypeId == "App::DocumentObjectGroup":
_cmd_list.extend(self.formatGroup(obj))
else:
_cmd = 'Draft.formatObject'
_cmd += '('
_cmd += 'FreeCAD.ActiveDocument.' + obj.Name
_cmd += ')'
_cmd_list.append(_cmd)
self.commit(translate("draft", "Change Style"),
_cmd_list)
self.finish()

def formatGroup(self, group):
"""Format a group instead of simple object."""
Gui.addModule("Draft")
_cmd_list = []
for obj in group.Group:
if obj.TypeId == "App::DocumentObjectGroup":
_cmd_list.extend(self.formatGroup(obj))
else:
_cmd = 'Draft.formatObject'
_cmd += '('
_cmd += 'FreeCAD.ActiveDocument.' + obj.Name
_cmd += ')'
_cmd_list.append(_cmd)
return _cmd_list
"""Execute when the command is called."""
super().Activated(name="Apply style")
objs = Gui.Selection.getSelection()
if objs:
objs = groups.get_group_contents(objs, addgroups=True, spaces=True, noarchchild=True)
Gui.addModule("Draft")
cmd_list = [
"doc = FreeCAD.ActiveDocument",
"Draft.apply_current_style([" + ", ".join(["doc." + obj.Name for obj in objs]) + "])",
"doc.recompute()"
]
self.commit(translate("draft", "Change Style"), cmd_list)
self.finish()


Gui.addCommand('Draft_ApplyStyle', ApplyStyle())
Gui.addCommand("Draft_ApplyStyle", ApplyStyle())

## @}
Loading

0 comments on commit d37406e

Please sign in to comment.