Skip to content

Commit

Permalink
Merge pull request #449 from looooo/python3-arch
Browse files Browse the repository at this point in the history
Python3 Arch
  • Loading branch information
wwmayer committed Jan 17, 2017
2 parents 636804f + f3fb676 commit c0ec75e
Show file tree
Hide file tree
Showing 28 changed files with 345 additions and 330 deletions.
6 changes: 3 additions & 3 deletions src/App/PropertyGeo.cpp
Expand Up @@ -265,13 +265,13 @@ PyObject *PropertyVectorList::getPyObject(void)

void PropertyVectorList::setPyObject(PyObject *value)
{
if (PyList_Check(value)) {
Py_ssize_t nSize = PyList_Size(value);
if (PySequence_Check(value)) {
Py_ssize_t nSize = PySequence_Size(value);
std::vector<Base::Vector3d> values;
values.resize(nSize);

for (Py_ssize_t i=0; i<nSize;++i) {
PyObject* item = PyList_GetItem(value, i);
PyObject* item = PySequence_GetItem(value, i);
PropertyVector val;
val.setPyObject( item );
values[i] = val.getValue();
Expand Down
36 changes: 18 additions & 18 deletions src/Mod/Arch/ArchCommands.py
Expand Up @@ -293,7 +293,7 @@ def splitMesh(obj,mark=True):

def makeFace(wires,method=2,cleanup=False):
'''makeFace(wires): makes a face from a list of wires, finding which ones are holes'''
#print "makeFace: start:", wires
#print("makeFace: start:", wires)
import Part

if not isinstance(wires,list):
Expand All @@ -308,44 +308,44 @@ def makeFace(wires,method=2,cleanup=False):

wires = wires[:]

#print "makeFace: inner wires found"
#print("makeFace: inner wires found")
ext = None
max_length = 0
# cleaning up rubbish in wires
if cleanup:
for i in range(len(wires)):
wires[i] = DraftGeomUtils.removeInterVertices(wires[i])
#print "makeFace: garbage removed"
#print("makeFace: garbage removed")
for w in wires:
# we assume that the exterior boundary is that one with
# the biggest bounding box
if w.BoundBox.DiagonalLength > max_length:
max_length = w.BoundBox.DiagonalLength
ext = w
#print "makeFace: exterior wire",ext
#print("makeFace: exterior wire", ext)
wires.remove(ext)

if method == 1:
# method 1: reverse inner wires
# all interior wires mark a hole and must reverse
# their orientation, otherwise Part.Face fails
for w in wires:
#print "makeFace: reversing",w
#print("makeFace: reversing", w)
w.reverse()
# make sure that the exterior wires comes as first in the list
wires.insert(0, ext)
#print "makeFace: done sorting", wires
#print("makeFace: done sorting", wires)
if wires:
return Part.Face(wires)
else:
# method 2: use the cut method
mf = Part.Face(ext)
#print "makeFace: external face:",mf
#print("makeFace: external face:", mf)
for w in wires:
f = Part.Face(w)
#print "makeFace: internal face:",f
#print("makeFace: internal face:", f)
mf = mf.cut(f)
#print "makeFace: final face:",mf.Faces
#print("makeFace: final face:", mf.Faces)
return mf.Faces[0]

def closeHole(shape):
Expand Down Expand Up @@ -475,7 +475,7 @@ def getShapeFromMesh(mesh,fast=True,tolerance=0.001,flat=False,cut=True):
# print "getShapeFromMesh: non-solid mesh, using slow method"
faces = []
segments = mesh.getPlanarSegments(tolerance)
#print len(segments)
#print(len(segments))
for i in segments:
if len(i) > 0:
wires = MeshPart.wireFromSegment(mesh, i)
Expand Down Expand Up @@ -581,7 +581,7 @@ def removeShape(objs,mark=True):
if dims:
name = obj.Name
tp = Draft.getType(obj)
print tp
print(tp)
if tp == "Structure":
FreeCAD.ActiveDocument.removeObject(name)
import ArchStructure
Expand Down Expand Up @@ -900,7 +900,7 @@ def makeCompoundFromSelected(objects=None):
Part.show(c)


def cleanArchSplitter(objets=None):
def cleanArchSplitter(objects=None):
"""cleanArchSplitter([objects]): removes the splitters from the base shapes
of the given Arch objects or selected Arch objects if objects is None"""
import FreeCAD,FreeCADGui
Expand All @@ -912,7 +912,7 @@ def cleanArchSplitter(objets=None):
if obj.isDerivedFrom("Part::Feature"):
if hasattr(obj,"Base"):
if obj.Base:
print "Attempting to clean splitters from ",obj.Label
print("Attempting to clean splitters from ", obj.Label)
if obj.Base.isDerivedFrom("Part::Feature"):
if not obj.Base.Shape.isNull():
obj.Base.Shape = obj.Base.Shape.removeSplitter()
Expand All @@ -933,31 +933,31 @@ def rebuildArchShape(objects=None):
if hasattr(obj,"Base"):
if obj.Base:
try:
print "Attempting to rebuild ",obj.Label
print("Attempting to rebuild ", obj.Label)
if obj.Base.isDerivedFrom("Part::Feature"):
if not obj.Base.Shape.isNull():
faces = []
for f in obj.Base.Shape.Faces:
f2 = Part.Face(f.Wires)
#print "rebuilt face: isValid is ",f2.isValid()
#print("rebuilt face: isValid is ", f2.isValid())
faces.append(f2)
if faces:
shell = Part.Shell(faces)
if shell:
#print "rebuilt shell: isValid is ",shell.isValid()
#print("rebuilt shell: isValid is ", shell.isValid())
solid = Part.Solid(shell)
if solid:
if not solid.isValid():
solid.sewShape()
solid = Part.Solid(solid)
#print "rebuilt solid: isValid is ",solid.isValid()
#print("rebuilt solid: isValid is ",solid.isValid())
if solid.isValid():
obj.Base.Shape = solid
success = True
except:
pass
if not success:
print "Failed to rebuild a valid solid for object ",obj.Name
print ("Failed to rebuild a valid solid for object ",obj.Name)
FreeCAD.ActiveDocument.recompute()


Expand Down
12 changes: 6 additions & 6 deletions src/Mod/Arch/ArchComponent.py
Expand Up @@ -470,7 +470,7 @@ def hideSubobjects(self,obj,prop):
def processSubShapes(self,obj,base,placement=None):
"Adds additions and subtractions to a base shape"
import Draft,Part
#print "Processing subshapes of ",obj.Label, " : ",obj.Additions
#print("Processing subshapes of ",obj.Label, " : ",obj.Additions)

if placement:
if placement.isNull():
Expand Down Expand Up @@ -520,7 +520,7 @@ def processSubShapes(self,obj,base,placement=None):
try:
base = base.fuse(s)
except Part.OCCError:
print "Arch: unable to fuse object ",obj.Name, " with ", o.Name
print("Arch: unable to fuse object ", obj.Name, " with ", o.Name)
else:
base = s

Expand Down Expand Up @@ -558,7 +558,7 @@ def processSubShapes(self,obj,base,placement=None):
try:
base = base.cut(s)
except Part.OCCError:
print "Arch: unable to cut object ",o.Name, " from ", obj.Name
print("Arch: unable to cut object ",o.Name, " from ", obj.Name)
return base

def applyShape(self,obj,shape,placement,allowinvalid=False,allownosolid=False):
Expand Down Expand Up @@ -633,7 +633,7 @@ def computeAreas(self,obj):
except Part.OCCError:
# error in computing the areas. Better set them to zero than show a wrong value
if obj.HorizontalArea.Value != 0:
print "Debug: Error computing areas for ",obj.Label,": unable to project face: ",str([v.Point for v in f.Vertexes])," (face normal:",f.normalAt(0,0),")"
print("Debug: Error computing areas for ",obj.Label,": unable to project face: ",str([v.Point for v in f.Vertexes])," (face normal:",f.normalAt(0,0),")")
obj.HorizontalArea = 0
if hasattr(obj,"PerimeterLength"):
if obj.PerimeterLength.Value != 0:
Expand All @@ -659,7 +659,7 @@ def __init__(self,vobj):
self.Object = vobj.Object

def updateData(self,obj,prop):
#print obj.Name," : updating ",prop
#print(obj.Name," : updating ",prop)
if prop == "BaseMaterial":
if obj.BaseMaterial:
if 'DiffuseColor' in obj.BaseMaterial.Material:
Expand Down Expand Up @@ -692,7 +692,7 @@ def getIcon(self):
return ":/icons/Arch_Component.svg"

def onChanged(self,vobj,prop):
#print vobj.Object.Name, " : changing ",prop
#print(vobj.Object.Name, " : changing ",prop)
if prop == "Visibility":
#for obj in vobj.Object.Additions+vobj.Object.Subtractions:
# if (Draft.getType(obj) == "Window") or (Draft.isClone(obj,"Window",True)):
Expand Down
9 changes: 5 additions & 4 deletions src/Mod/Arch/ArchEquipment.py
Expand Up @@ -27,7 +27,8 @@
__author__ = "Yorik van Havre"
__url__ = "http://www.freecadweb.org"

import FreeCAD,Draft,ArchComponent,DraftVecUtils,ArchCommands,Units
import FreeCAD,Draft,ArchComponent,DraftVecUtils,ArchCommands
from FreeCAD import Units
from FreeCAD import Vector
if FreeCAD.GuiUp:
import FreeCADGui
Expand Down Expand Up @@ -121,7 +122,7 @@ def createMeshView(obj,direction=FreeCAD.Vector(0,0,-1),outeronly=False,largesto
# 3. Getting the bigger mesh from the planar segments
if largestonly:
c = cleanmesh.getSeparateComponents()
#print c
#print(c)
cleanmesh = c[0]
segs = cleanmesh.getPlanarSegments(1)
meshes = []
Expand All @@ -141,7 +142,7 @@ def createMeshView(obj,direction=FreeCAD.Vector(0,0,-1),outeronly=False,largesto
shape = None
for f in cleanmesh.Facets:
p = Part.makePolygon(f.Points+[f.Points[0]])
#print p,len(p.Vertexes),p.isClosed()
#print(p,len(p.Vertexes),p.isClosed())
try:
p = Part.Face(p)
if shape:
Expand All @@ -165,7 +166,7 @@ def createMeshView(obj,direction=FreeCAD.Vector(0,0,-1),outeronly=False,largesto
try:
f = Part.Face(w)
except Part.OCCError:
print "Unable to produce a face from the outer wire."
print("Unable to produce a face from the outer wire.")
else:
shape = f

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchFloor.py
Expand Up @@ -147,7 +147,7 @@ def execute(self,obj):
else:
pl = obj.Placement.copy()
if not DraftVecUtils.equals(pl.Base,self.OldPlacement.Base):
print "placement moved"
print("placement moved")
delta = pl.Base.sub(self.OldPlacement.Base)
for o in obj.Group:
if hasattr(o,"Placement"):
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Arch/ArchProfile.py
Expand Up @@ -73,9 +73,9 @@ def readPresets():
Presets.append(r)
bid=bid+1
except ValueError:
print "Skipping bad line: "+str(row)
print("Skipping bad line: "+str(row))
except IOError:
print "Could not open ",profilefile
print("Could not open ",profilefile)
return Presets

def makeProfile(profile=[0,'REC','REC100x100','R',100,100]):
Expand All @@ -93,7 +93,7 @@ def makeProfile(profile=[0,'REC','REC100x100','R',100,100]):
elif profile[3]=="U":
_ProfileU(obj, profile)
else :
print "Profile not supported"
print("Profile not supported")
if FreeCAD.GuiUp:
Draft._ViewProviderDraft(obj.ViewObject)
return obj
Expand Down
12 changes: 6 additions & 6 deletions src/Mod/Arch/ArchRebar.py
Expand Up @@ -136,7 +136,7 @@ def Activated(self):
if len(obj.Support) != 0:
sup = obj.Support[0][0]
else:
print "Arch: error: couldn't extract a base object"
print("Arch: error: couldn't extract a base object")
return
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Rebar"))
FreeCADGui.addModule("Arch")
Expand All @@ -145,7 +145,7 @@ def Activated(self):
FreeCAD.ActiveDocument.recompute()
return
else:
print "Arch: error: couldn't extract a base object"
print("Arch: error: couldn't extract a base object")
return

FreeCAD.Console.PrintMessage(translate("Arch","Please select a base face on a structural object\n"))
Expand Down Expand Up @@ -208,7 +208,7 @@ def execute(self,obj):
father = obj.InList[0]
wire = obj.Base.Shape.Wires[0]
if hasattr(obj,"Rounding"):
#print obj.Rounding
#print(obj.Rounding)
if obj.Rounding:
radius = obj.Rounding * obj.Diameter.Value
import DraftGeomUtils
Expand All @@ -223,8 +223,8 @@ def execute(self,obj):
axis = FreeCAD.Vector(obj.Direction) #.normalize()
# don't normalize so the vector can also be used to determine the distance
size = axis.Length
#print axis
#print size
#print(axis)
#print(size)
if (obj.OffsetStart.Value + obj.OffsetEnd.Value) > size:
return

Expand All @@ -236,7 +236,7 @@ def execute(self,obj):
try:
bar = wire.makePipeShell([circle],True,False,2)
except Part.OCCError:
print "Arch: error sweeping rebar profile along the base sketch"
print("Arch: error sweeping rebar profile along the base sketch")
return
# building final shape
shapes = []
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Arch/ArchRoof.py
Expand Up @@ -647,10 +647,10 @@ def computeAreas(self,obj):
rn += 1
if obj.RidgeLength.Value != rl:
obj.RidgeLength = rl
print str(rn)+" ridge edges in roof "+obj.Name
print(str(rn)+" ridge edges in roof "+obj.Name)
if obj.BorderLength.Value != bl:
obj.BorderLength = bl
print str(bn)+" border edges in roof "+obj.Name
print(str(bn)+" border edges in roof "+obj.Name)
ArchComponent.Component.computeAreas(self,obj)


Expand Down
12 changes: 6 additions & 6 deletions src/Mod/Arch/ArchSchedule.py
Expand Up @@ -112,8 +112,8 @@ def execute(self,obj):
obj.Result.set("A"+str(i+2),obj.Description[i].encode("utf8"))
if verbose:
l= "OPERATION: "+obj.Description[i]
print l
print len(l)*"="
print (l)
print (len(l)*"=")
# get list of objects
objs = obj.Objects[i]
val = obj.Value[i]
Expand Down Expand Up @@ -172,21 +172,21 @@ def execute(self,obj):
if val.upper() == "COUNT":
val = len(objs)
if verbose:
print val, ",".join([o.Label for o in objs])
print (val, ",".join([o.Label for o in objs]))
obj.Result.set("B"+str(i+2),str(val))
else:
vals = val.split(".")
sumval = 0
for o in objs:
if verbose:
l = o.Name+" ("+o.Label+"):"
print l+(40-len(l))*" ",
print (l+(40-len(l))*" ",)
try:
d = o
for v in vals[1:]:
d = getattr(d,v)
if verbose:
print d
print (d)
if hasattr(d,"Value"):
d = d.Value
except:
Expand Down Expand Up @@ -216,7 +216,7 @@ def execute(self,obj):
else:
obj.Result.set("B"+str(i+2),str(val))
if verbose:
print "TOTAL:"+34*" "+str(val)
print ("TOTAL:"+34*" "+str(val))

def __getstate__(self):
return self.Type
Expand Down

0 comments on commit c0ec75e

Please sign in to comment.