def testSite(self): FreeCAD.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")
def makeStructure(entity,shape=None): "makes a structure in the freecad document" try: if entity.type == "IFCSLAB": typ = "Slab" elif entity.type == "IFCBEAM": typ = "Beam" else: typ = "Column" if DEBUG: print "=====> making struct",entity.id if shape: sh = FreeCAD.ActiveDocument.addObject("Part::Feature","StructureBody") sh.Shape = shape structure = Arch.makeStructure(sh,name=typ+str(entity.id)) if DEBUG: print "made structure object ",entity.id,":",structure return placement = structure = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got window placement",entity.id,":",placement width = entity.getProperty("Width") height = entity.getProperty("Height") for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": wire = getWire(b.SweptArea,placement) structure = Arch.makeStructure(wire,height=b.Depth,name=typ+str(entity.id)) if structure: if DEBUG: print "made structure object ",entity.id,":",structure except: if DEBUG: print "error: skipping structure",entity.id
def __init__(self, platform=None, **kwargs): SConsEnvironment.__init__(self, platform=platform, tools=[]) self._targets = [] ### our build process requires that we run everything from the top level dir self.SConscriptChdir(False) ### extract our specific command line variables commandLineOptions = self.getCommandLineOptions() ### set the arch and compiler independent options, overriding ### defauls with values specified on the command line setBaseVars(self, commandLineOptions) ### now load the architecture specific defaults Arch.updateEnv(self) ### should allow for a mechanism for user to override ### architecture specific defaults. currently we can only ### handle specification of the compiler ### since our build paths depend on the arch/compiler settings ### we can only set these paths now setVersionPaths(self) ### keep the sconsign database local to each build rather ### than polluting the source tree self.SConsignFile('$BUILDVERSIONDIR/sconsign') ### for emacs compile mode SCons.Util.display("scons: Entering directory `%s'" % os.getcwd())
def makeWindow(entity,shape=None): "makes a window in the freecad document" try: typ = "Window" if entity.type == "IFCWINDOW" else "Door" if DEBUG: print "=====> making window",entity.id if shape: window = Arch.makeWindow(name=typ+str(entity.id)) window.Shape = shape if DEBUG: print "made window object ",entity.id,":",window return placement = window = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got window placement",entity.id,":",placement width = entity.getProperty("Width") height = entity.getProperty("Height") for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": wire = getWire(b.SweptArea,placement) window = Arch.makeWindow(wire,width=b.Depth,name=typ+str(entity.id)) if window: if DEBUG: print "made window object ",entity.id,":",window except: if DEBUG: print "error: skipping window",entity.id
def makeWindow(entity, shape=None, name="Window"): "makes a window in the freecad document" try: if shape: # use ifcopenshell if isinstance(shape, Part.Shape): window = Arch.makeWindow(name=name) window.Shape = shape window.Label = name if DEBUG: print "made window object ", entity, ":", window return window # use internal parser if DEBUG: print "=====> making window", entity.id placement = window = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got window placement", entity.id, ":", placement width = entity.getProperty("Width") height = entity.getProperty("Height") for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": wire = getWire(b.SweptArea, placement) window = Arch.makeWindow(wire, width=b.Depth, name=objtype + str(entity.id)) if window: if DEBUG: print "made window object ", entity.id, ":", window return window if DEBUG: print "error: skipping window", entity.id return None except: if DEBUG: print "error: skipping window", entity.id return None
def testWindow(self): FreeCAD.Console.PrintLog('Checking Arch Window...\n') l = Draft.makeLine(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(-2, 0, 0)) w = Arch.makeWall(l) sk = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject', 'Sketch001') sk.Support = (w, ["Face3"]) sk.addGeometry( Part.LineSegment(FreeCAD.Vector(-1.80, 1.30, 0), FreeCAD.Vector(-0.90, 1.30, 0))) sk.addGeometry( Part.LineSegment(FreeCAD.Vector(-0.90, 1.30, 0), FreeCAD.Vector(-0.90, 0.25, 0))) sk.addGeometry( Part.LineSegment(FreeCAD.Vector(-0.90, 0.25, 0), FreeCAD.Vector(-1.80, 0.25, 0))) sk.addGeometry( Part.LineSegment(FreeCAD.Vector(-1.80, 0.25, 0), FreeCAD.Vector(-1.80, 1.30, 0))) sk.addConstraint(Sketcher.Constraint('Coincident', 0, 2, 1, 1)) sk.addConstraint(Sketcher.Constraint('Coincident', 1, 2, 2, 1)) sk.addConstraint(Sketcher.Constraint('Coincident', 2, 2, 3, 1)) sk.addConstraint(Sketcher.Constraint('Coincident', 3, 2, 0, 1)) win = Arch.makeWindow(sk) Arch.removeComponents(win, host=w) self.failUnless(win, "Arch Window failed")
def testSite(self): FreeCAD.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")
def grid_lines(self): if not App.ParamGet("User parameter:BaseApp/Preferences/Mod/Civil").GetBool("draw_grid", True): return gridLines = self._safe.grid_lines() if gridLines is None: return x_grids = gridLines['x'] y_grids = gridLines['y'] b = self.foundation.Shape.BoundBox x_axis_length = b.YLength * 1.2 y_axis_length = b.XLength * 1.2 x_grids_coord = -b.YLength * .1 y_grids_coord = b.XLength * 1 for text, coord in x_grids.items(): ax = Arch.makeAxis(1) ax.Distances = [coord] ax.Length = x_axis_length ax.CustomNumber = str(text) ax.Placement.Base.y = b.YMin Draft.move(ax, App.Vector(0, x_grids_coord, 0), copy=False) ax_gui = ax.ViewObject ax_gui.BubbleSize = 1500 ax_gui.FontSize = 750 for text, coord in y_grids.items(): ax = Arch.makeAxis(1) ax.Length = y_axis_length ax.Placement = App.Placement(App.Vector(0, 0, 0), App.Rotation(App.Vector(0, 0, 1), 90)) ax.Distances = [coord] ax.CustomNumber = str(text) Draft.move(ax, App.Vector(y_grids_coord, 0, 0), copy=False) ax_gui = ax.ViewObject ax_gui.BubbleSize = 1500 ax_gui.FontSize = 750
def drawPanel(rect,steelFrame,flip, thick, material=None, namePanel='Panel'): """ Draws the panel on the steelFrame """ orienX=steelFrame.Placement.Rotation.multVec(FreeCAD.Vector(1,0,0)) if flip==0: place = steelFrame.Placement.Base.add(orienX.multiply(rect.vertI.x)) else: place = steelFrame.Placement.Base.add(orienX.multiply(rect.vertI.x+rect.Length)) orienZ=steelFrame.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1)) place = place.add(orienZ.multiply(rect.vertI.z)) if flip==1: vectorWidth=steelFrame.Placement.Rotation.multVec(FreeCAD.Vector(0,1,0)) place=place.add(vectorWidth.multiply(steelFrame.Width)) ro=FreeCAD.Rotation(0,0,90) if flip==1: ro=FreeCAD.Rotation(180,0,90) rot=steelFrame.Placement.Rotation.multiply(ro) Rect=Draft.makeRectangle(rect.Length, rect.Height, placement=FreeCAD.Placement(place, rot)) if namePanel != '' and namePanel != 'Panel': panel = Arch.makePanel(Rect, thickness=thick, name = namePanel) else: panel = Arch.makePanel(Rect, thickness=thick) if material: panel.Material=material return panel
def makeLShapeRebar(f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation = "Bottom Left", structure = None, facename = None): """ makeLShapeRebar(FrontCover, BottomCover, LeftCover, RightCover, Diameter, TopCover, Rounding, AmountSpacingCheck, AmountSpacingValue, Orientation, Structure, Facename): Adds the L-Shape reinforcement bar to the selected structural object. It takes four different orientations input i.e. 'Bottom Left', 'Bottom Right ', 'Top Left', 'Top Right'. """ if not structure and not facename: selected_obj = FreeCADGui.Selection.getSelectionEx()[0] structure = selected_obj.Object facename = selected_obj.SubElementNames[0] face = structure.Shape.Faces[getFaceNumber(facename) - 1] #StructurePRM = getTrueParametersOfStructure(structure) FacePRM = getParametersOfFace(structure, facename) if not FacePRM: FreeCAD.Console.PrintError("Cannot identified shape or from which base object sturctural element is derived\n") return # Get points of L-Shape rebar points = getpointsOfLShapeRebar(FacePRM, l_cover, r_cover, b_cover, t_cover, orientation) import Part import Arch sketch = FreeCAD.activeDocument().addObject('Sketcher::SketchObject', 'Sketch') sketch.MapMode = "FlatFace" sketch.Support = [(structure, facename)] FreeCAD.ActiveDocument.recompute() sketch.addGeometry(Part.LineSegment(points[0], points[1]), False) sketch.addGeometry(Part.LineSegment(points[1], points[2]), False) import Sketcher if amount_spacing_check: rebar = Arch.makeRebar(structure, sketch, diameter, amount_spacing_value, f_cover) FreeCAD.ActiveDocument.recompute() else: size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length rebar = Arch.makeRebar(structure, sketch, diameter, int((size - diameter) / amount_spacing_value), f_cover) rebar.Rounding = rounding # Adds properties to the rebar object rebar.ViewObject.addProperty("App::PropertyString", "RebarShape", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Shape of rebar")).RebarShape = "LShapeRebar" rebar.ViewObject.setEditorMode("RebarShape", 2) rebar.addProperty("App::PropertyDistance", "FrontCover", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Front cover of rebar")).FrontCover = f_cover rebar.setEditorMode("FrontCover", 2) rebar.addProperty("App::PropertyDistance", "LeftCover", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Left Side cover of rebar")).LeftCover = l_cover rebar.setEditorMode("LeftCover", 2) rebar.addProperty("App::PropertyDistance", "RightCover", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Right Side cover of rebar")).RightCover = r_cover rebar.setEditorMode("RightCover", 2) rebar.addProperty("App::PropertyDistance", "BottomCover", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Bottom cover of rebar")).BottomCover = b_cover rebar.setEditorMode("BottomCover", 2) rebar.addProperty("App::PropertyBool", "AmountCheck", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Amount radio button is checked")).AmountCheck rebar.setEditorMode("AmountCheck", 2) rebar.addProperty("App::PropertyDistance", "TopCover", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Top cover of rebar")).TopCover = t_cover rebar.setEditorMode("TopCover", 2) rebar.addProperty("App::PropertyDistance", "TrueSpacing", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Spacing between of rebars")).TrueSpacing = amount_spacing_value rebar.addProperty("App::PropertyString", "Orientation", "RebarDialog", QT_TRANSLATE_NOOP("App::Property", "Shape of rebar")).Orientation = orientation rebar.setEditorMode("Orientation", 2) rebar.setEditorMode("TrueSpacing", 2) if amount_spacing_check: rebar.AmountCheck = True else: rebar.AmountCheck = False rebar.TrueSpacing = amount_spacing_value rebar.Label = "LShapeRebar" FreeCAD.ActiveDocument.recompute() return rebar
def __init__(self, platform=None, **kwargs): SConsEnvironment.__init__(self, platform=platform, tools=[]) self._targets = [] ### our build process requires that we run everything from the top level dir self.SConscriptChdir(False) ### extract our specific command line variables commandLineOptions = self.getCommandLineOptions() ### set the arch and compiler independent options, overriding ### defauls with values specified on the command line setBaseVars(self,commandLineOptions) ### now load the architecture specific defaults Arch.updateEnv(self) ### should allow for a mechanism for user to override ### architecture specific defaults. currently we can only ### handle specification of the compiler ### since our build paths depend on the arch/compiler settings ### we can only set these paths now setVersionPaths(self) ### keep the sconsign database local to each build rather ### than polluting the source tree self.SConsignFile('$BUILDVERSIONDIR/sconsign') ### for emacs compile mode SCons.Util.display("scons: Entering directory `%s'" % os.getcwd())
def makeWindow(entity,shape=None,name="Window"): "makes a window in the freecad document" try: if shape: # use ifcopenshell if isinstance(shape,Part.Shape): window = Arch.makeWindow(name=name) window.Shape = shape window.Label = name if DEBUG: print "made window object ",entity,":",window return window # use internal parser if DEBUG: print "=====> making window",entity.id placement = window = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got window placement",entity.id,":",placement width = entity.getProperty("Width") height = entity.getProperty("Height") for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": wire = getWire(b.SweptArea,placement) window = Arch.makeWindow(wire,width=b.Depth,name=objtype+str(entity.id)) if window: if DEBUG: print "made window object ",entity.id,":",window return window if DEBUG: print "error: skipping window",entity.id return None except: if DEBUG: print "error: skipping window",entity return None
def makeWindow(entity, shape=None): "makes a window in the freecad document" try: typ = "Window" if entity.type == "IFCWINDOW" else "Door" if DEBUG: print "=====> making window", entity.id if shape: window = Arch.makeWindow(name=typ + str(entity.id)) window.Shape = shape if DEBUG: print "made window object ", entity.id, ":", window return placement = window = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got window placement", entity.id, ":", placement width = entity.getProperty("Width") height = entity.getProperty("Height") for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": wire = getWire(b.SweptArea, placement) window = Arch.makeWindow(wire, width=b.Depth, name=typ + str(entity.id)) if window: if DEBUG: print "made window object ", entity.id, ":", window except: if DEBUG: print "error: skipping window", entity.id
def makeStructure(entity,shape=None,name="Structure"): "makes a structure in the freecad document" try: if shape: # use ifcopenshell sh = FreeCAD.ActiveDocument.addObject("Part::Feature","StructureBody") sh.Shape = shape structure = Arch.makeStructure(sh,name=name) structure.Label = name if DEBUG: print "made structure object ",entity,":",structure return structure # use internal parser if DEBUG: print "=====> making struct",entity.id placement = structure = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got window placement",entity.id,":",placement width = entity.getProperty("Width") height = entity.getProperty("Height") for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": wire = getWire(b.SweptArea,placement) structure = Arch.makeStructure(wire,height=b.Depth,name=objtype+str(entity.id)) if structure: if DEBUG: print "made structure object ",entity.id,":",structure return structure if DEBUG: print "error: skipping structure",entity.id return None except: if DEBUG: print "error: skipping structure",entity.id return None
def makeTimberBeam2(name='TimberBeam'): base = Arch.makeStructure(None, 1000.0, 80.0, 200.0, 'TBStructure') obj = Arch.makeStructure(base, 1, 1, 1, name) obj.setEditorMode("Length", 1) obj.setEditorMode("Width", 1) obj.setEditorMode("Height", 1) obj.setEditorMode("Placement", 1) return obj
def makeTimberBeam2( name = 'TimberBeam' ): base = Arch.makeStructure( None, 1000.0 , 80.0 , 200.0 , 'TBStructure') obj = Arch.makeStructure(base, 1 , 1 , 1 , name) obj.setEditorMode("Length", 1) obj.setEditorMode("Width", 1) obj.setEditorMode("Height", 1) obj.setEditorMode("Placement", 1) return obj
def makeWall(entity, shape=None, name="Wall"): "makes a wall in the freecad document" try: if shape: # use ifcopenshell if isinstance(shape, Part.Shape): body = FreeCAD.ActiveDocument.addObject( "Part::Feature", name + "_body") body.Shape = shape else: body = FreeCAD.ActiveDocument.addObject( "Mesh::Feature", name + "_body") body.Mesh = shape wall = Arch.makeWall(body, name=name) wall.Label = name if DEBUG: print "made wall object ", entity, ":", wall return wall # use internal parser if DEBUG: print "=====> making wall", entity.id placement = wall = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got wall placement", entity.id, ":", placement width = entity.getProperty("Width") height = entity.getProperty("Height") if width and height: if DEBUG: print "got width, height ", entity.id, ":", width, "/", height for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Axis": wire = getWire(r.Items, placement) wall = Arch.makeWall(wire, width, height, align="Center", name="Wall" + str(entity.id)) else: if DEBUG: print "no height or width properties found..." for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": norm = getVector(b.ExtrudedDirection) norm.normalize() wire = getWire(b.SweptArea, placement) wall = Arch.makeWall(wire, width=0, height=b.Depth, name="Wall" + str(entity.id)) wall.Normal = norm if wall: if DEBUG: print "made wall object ", entity.id, ":", wall return wall if DEBUG: print "error: skipping wall", entity.id return None except: if DEBUG: print "error: skipping wall", entity.id return None
def makeWall(entity, shape=None, name="Wall"): "makes a wall in the freecad document" try: if shape: # use ifcopenshell if isinstance(shape, Part.Shape): body = FreeCAD.ActiveDocument.addObject("Part::Feature", name + "_body") body.Shape = shape else: body = FreeCAD.ActiveDocument.addObject("Mesh::Feature", name + "_body") body.Mesh = shape wall = Arch.makeWall(body, name=name) wall.Label = name if IOC_ADVANCED and ADDPLACEMENT: wall.Placement = getPlacement(getAttr(entity, "ObjectPlacement")) if DEBUG: print "made wall object ", entity, ":", wall return wall # use internal parser if DEBUG: print "=====> making wall", entity.id placement = wall = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got wall placement", entity.id, ":", placement width = entity.getProperty("Width") height = entity.getProperty("Height") if width and height: if DEBUG: print "got width, height ", entity.id, ":", width, "/", height for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Axis": wire = getWire(r.Items, placement) wall = Arch.makeWall(wire, width, height, align="Center", name="Wall" + str(entity.id)) else: if DEBUG: print "no height or width properties found..." for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": norm = getVector(b.ExtrudedDirection) norm.normalize() wire = getWire(b.SweptArea, placement) wall = Arch.makeWall(wire, width=0, height=b.Depth, name="Wall" + str(entity.id)) wall.Normal = norm if wall: if DEBUG: print "made wall object ", entity.id, ":", wall return wall if DEBUG: print "error: skipping wall", entity.id return None except: if DEBUG: print "error: skipping wall", entity return None
def execute(self, obj): scale = 1000 * obj.v_scale shapes = [] childrens_name = [] levels = [obj.base_level * scale] real_level = [obj.base_level] lev = self.get_level_text(real_level[-1]) f = Arch.makeFloor(name=f"{obj.levels_name[0]} {lev}") f.ViewObject.FontSize = 200 f.ViewObject.ShowLevel = False f.Placement.Base = FreeCAD.Vector(-2000, -2000, levels[-1]) plane = Part.makePlane(20000, 20000) plane.Placement.Base.z = levels[-1] shapes.append(plane) childrens_name.append(f.Name) for i, height in enumerate(obj.heights): levels.append(levels[-1] + height * scale) real_level.append(real_level[-1] + height) lev = self.get_level_text(real_level[-1]) f = Arch.makeFloor(name=f"{obj.levels_name[i + 1]} {lev}") f.ViewObject.FontSize = 200 f.ViewObject.ShowLevel = False pl = FreeCAD.Vector(-2000, -2000, levels[-1]) f.Placement.Base = pl f.Height = height * scale childrens_name.append(f.Name) plane = Part.makePlane(20000, 20000) plane.Placement.Base.z = levels[-1] shapes.append(plane) com = Part.makeCompound(shapes) obj.Shape = com obj.ViewObject.Transparency = 90 obj.ViewObject.LineColor = (1.00,1.00,1.00) obj.ViewObject.PointColor = (1.00,1.00,1.00) obj.ViewObject.ShapeColor = (0.68,0.95,0.95) obj.levels = real_level old_childrens_name = obj.childrens_name obj.childrens_name = childrens_name for name in old_childrens_name: children = FreeCAD.ActiveDocument.getObject(name) if hasattr(children, "Base") and children.Base: FreeCAD.ActiveDocument.removeObject(children.Base.Name) FreeCAD.ActiveDocument.removeObject(name) for o in FreeCAD.ActiveDocument.Objects: if hasattr(o, "Proxy"): if hasattr(o.Proxy, "Type") and o.Proxy.Type == "ColumnTypes": continue if hasattr(o, "v_scale") and o.v_scale != obj.v_scale: o.v_scale = obj.v_scale if hasattr(o, "base_level") and o.base_level != obj.base_level: o.base_level = obj.base_level if hasattr(o, "composite_deck") and o.composite_deck != obj.composite_deck: o.composite_deck = obj.composite_deck if hasattr(o, "heights") and o.heights == obj.heights: o.heights = obj.heights
def makeStructure(entity, shape=None, ifctype=None, name="Structure"): "makes a structure in the freecad document" try: if shape: # use ifcopenshell if isinstance(shape, Part.Shape): body = FreeCAD.ActiveDocument.addObject( "Part::Feature", name + "_body") body.Shape = shape else: body = FreeCAD.ActiveDocument.addObject( "Mesh::Feature", name + "_body") body.Mesh = shape structure = Arch.makeStructure(body, name=name) structure.Label = name if ifctype == "IfcBeam": structure.Role = "Beam" elif ifctype == "IfcColumn": structure.Role = "Column" elif ifctype == "IfcSlab": structure.Role = "Slab" elif ifctype == "IfcFooting": structure.Role = "Foundation" print "current placement: ", shape.Placement if IOC_ADVANCED and ADDPLACEMENT: structure.Placement = getPlacement( getAttr(entity, "ObjectPlacement")) if DEBUG: print "made structure object ", entity, ":", structure, " (type: ", ifctype, ")" return structure # use internal parser if DEBUG: print "=====> making struct", entity.id placement = structure = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got window placement", entity.id, ":", placement width = entity.getProperty("Width") height = entity.getProperty("Height") for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": wire = getWire(b.SweptArea, placement) structure = Arch.makeStructure(wire, height=b.Depth, name=objtype + str(entity.id)) if structure: if DEBUG: print "made structure object ", entity.id, ":", structure return structure if DEBUG: print "error: skipping structure", entity.id return None except: if DEBUG: print "error: skipping structure", entity return None
def addLevel(self): "adds a building part" import Arch FreeCAD.ActiveDocument.openTransaction("Create BuildingPart") Arch.makeFloor() FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() self.update(False)
def makeStructure(entity, shape=None, ifctype=None, name="Structure"): "makes a structure in the freecad document" try: if shape: # use ifcopenshell if isinstance(shape, Part.Shape): body = FreeCAD.ActiveDocument.addObject("Part::Feature", name + "_body") body.Shape = shape else: body = FreeCAD.ActiveDocument.addObject("Mesh::Feature", name + "_body") body.Mesh = shape structure = Arch.makeStructure(body, name=name) structure.Label = name if ifctype == "IfcBeam": structure.Role = "Beam" elif ifctype == "IfcColumn": structure.Role = "Column" elif ifctype == "IfcSlab": structure.Role = "Slab" elif ifctype == "IfcFooting": structure.Role = "Foundation" print "current placement: ", shape.Placement if IOC_ADVANCED and ADDPLACEMENT: structure.Placement = getPlacement(getAttr(entity, "ObjectPlacement")) if DEBUG: print "made structure object ", entity, ":", structure, " (type: ", ifctype, ")" return structure # use internal parser if DEBUG: print "=====> making struct", entity.id placement = structure = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got window placement", entity.id, ":", placement width = entity.getProperty("Width") height = entity.getProperty("Height") for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": wire = getWire(b.SweptArea, placement) structure = Arch.makeStructure(wire, height=b.Depth, name=objtype + str(entity.id)) if structure: if DEBUG: print "made structure object ", entity.id, ":", structure return structure if DEBUG: print "error: skipping structure", entity.id return None except: if DEBUG: print "error: skipping structure", entity return None
def testRemove(self): FreeCAD.Console.PrintLog ('Checking Arch Remove...\n') l=Draft.makeLine(FreeCAD.Vector(0,0,0),FreeCAD.Vector(2,0,0)) w = Arch.makeWall(l,width=0.2,height=2) sb = Part.makeBox(1,1,1) b = FreeCAD.ActiveDocument.addObject('Part::Feature','Box') b.Shape = sb FreeCAD.ActiveDocument.recompute() Arch.removeComponents(b,w) FreeCAD.ActiveDocument.recompute() r = (w.Shape.Volume < 0.75) self.failUnless(r,"Arch Remove failed")
def wait_trimex(self): #if Gui.Control.activeDialog(): if not Gui.Control.activeDialog(): #print("trimex command in use") #else : self.state = self.states[4] #print("trimex command in OVER!!!") self.parent_obj.ViewObject.Transparency = 0 machining = Arch.makeStructure(self.profil.InList[0]) machining.MoveWithHost = True Arch.removeComponents([machining], self.parent_obj) App.ActiveDocument.recompute()
def testRemove(self): FreeCAD.Console.PrintLog('Checking Arch Remove...\n') l = Draft.makeLine(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(2, 0, 0)) w = Arch.makeWall(l, width=0.2, height=2) sb = Part.makeBox(1, 1, 1) b = FreeCAD.ActiveDocument.addObject('Part::Feature', 'Box') b.Shape = sb FreeCAD.ActiveDocument.recompute() Arch.removeComponents(b, w) FreeCAD.ActiveDocument.recompute() r = (w.Shape.Volume < 0.75) self.failUnless(r, "Arch Remove failed")
def testAdd(self): App.Console.PrintLog('Checking Arch Add...\n') l = Draft.makeLine(App.Vector(0, 0, 0), App.Vector(2, 0, 0)) w = Arch.makeWall(l, width=0.2, height=2) sb = Part.makeBox(1, 1, 1) b = App.ActiveDocument.addObject('Part::Feature', 'Box') b.Shape = sb App.ActiveDocument.recompute() Arch.addComponents(b, w) App.ActiveDocument.recompute() r = (w.Shape.Volume > 1.5) self.failUnless(r, "Arch Add failed")
def testWallMultiMatAlign(self): App.Console.PrintLog( 'Checking Arch Wall with MultiMaterial and 3 alignments...\n') matA = Arch.makeMaterial() matB = Arch.makeMaterial() matMulti = Arch.makeMultiMaterial() matMulti.Materials = [matA, matB] matMulti.Thicknesses = [100, 200] # total width different from default 200 pts = [ App.Vector(0, 0, 0), App.Vector(1000, 0, 0), App.Vector(1000, 1000, 0), App.Vector(2000, 1000, 0) ] # wall based on wire: wire = Draft.makeWire(pts) wallWire = Arch.makeWall(wire) wallWire.Material = matMulti # wall based on sketch: sketch = App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch') sketch.addGeometry([ Part.LineSegment(pts[0], pts[1]), Part.LineSegment(pts[1], pts[2]), Part.LineSegment(pts[2], pts[3]) ]) wallSketch = Arch.makeWall(sketch) wallSketch.Material = matMulti alignLst = ["Left", "Center", "Right"] checkLst = [[App.Vector(0, -300, 0), App.Vector(2000, 1000, 0)], [App.Vector(0, -150, 0), App.Vector(2000, 1150, 0)], [App.Vector(0, 0, 0), App.Vector(2000, 1300, 0)]] for i in range(3): wallWire.Align = alignLst[i] wallSketch.Align = alignLst[i] 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), "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), "Arch Wall with MultiMaterial and 3 alignments failed")
def testRebar(self): FreeCAD.Console.PrintLog ('Checking Arch Rebar...\n') s = Arch.makeStructure(length=2,width=3,height=5) sk = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Sketch') sk.Support = (s,["Face6"]) sk.addGeometry(Part.Line(FreeCAD.Vector(-0.85,1.25,0),FreeCAD.Vector(0.75,1.25,0))) sk.addGeometry(Part.Line(FreeCAD.Vector(0.75,1.25,0),FreeCAD.Vector(0.75,-1.20,0))) sk.addGeometry(Part.Line(FreeCAD.Vector(0.75,-1.20,0),FreeCAD.Vector(-0.85,-1.20,0))) sk.addGeometry(Part.Line(FreeCAD.Vector(-0.85,-1.20,0),FreeCAD.Vector(-0.85,1.25,0))) sk.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1)) sk.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1)) 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")
def accept(self): self.recupererDonnees() distancesListe = [] if self.objetDebut: distancesListe.append(self.decalageDebut) if self.plEspaceRestant == 0: distancesListe.append(self.espaceRestant) if self.plEspaceRestant == 1: distancesListe.append(self.ecartementRegulier-self.decalageDebut) if self.plEspaceRestant == 2: distancesListe.append(self.espaceRestant/2-self.decalageDebut) for i in range(self.qteEcartement-2): distancesListe.append(self.ecartementRegulier) if self.objetFin: if self.plEspaceRestant == 0: distancesListe.append(self.ecartementRegulier-self.decalageFin-self.decalageDebut) if self.plEspaceRestant == 1: distancesListe.append(self.espaceRestant-self.decalageFin) if self.plEspaceRestant == 2: distancesListe.append(self.ecartementRegulier) distancesListe.append((self.espaceRestant/2)-self.decalageFin) repartition = Arch.makeAxis(num=len(distancesListe), name="Repartition") repartition.Length = 1000.00 repartition.Distances= distancesListe self.sel = FreeCADGui.Selection.getSelection() if self.sel: edges = DraftGeomUtils.sortEdges(self.sel[0].Shape.Wires[0].Edges) vec1 = edges[0].Vertexes[-1].Point.sub(edges[0].Vertexes[0].Point) point1 = edges[0].Vertexes[0].Point rot = math.degrees(DraftVecUtils.angle(vec1))*-1 repartition.Placement = FreeCAD.Placement(FreeCAD.Vector(point1),FreeCAD.Rotation(FreeCAD.Vector(0.0,0.0,1.0),rot)) FreeCAD.ActiveDocument.recompute() else: repartition.Placement = FreeCAD.Placement(FreeCAD.Vector(0.0,0.0,0.0),FreeCAD.Rotation(FreeCAD.Vector(0.0,0.0,1.0),0)) m = FreeCADGui.getMainWindow() w = m.findChild(QtGui.QDockWidget,"PartsLibrary") if w: if w.isVisible(): index = w.folder_view.selectedIndexes()[0] path = w.dirmodel.filePath(index) if path.lower().endswith(".stp") or path.lower().endswith(".step") or path.lower().endswith(".brep"): objetRepartit = Part.show(Part.read(path)) else: objetRepartit = FreeCADGui.ActiveDocument.mergeProject(path) repartitionStructurel = Arch.makeStructuralSystem([FreeCAD.ActiveDocument.Objects[-1],],[repartition,], name="RepartitionStructurelle") return True
def circle_hollow(params,document): od = params['D'] t = params['t'] l = params['l'] name = params['name'] id = od - t outer = Part.Wire(Part.makeCircle(0.5*od)) inner = Part.Wire(Part.makeCircle(0.5*id)) face = Part.makeFace([outer, inner], "Part::FaceMakerBullseye") if params['arch']: part = Arch.makeStructure(name=name) prof = document.addObject("Part::Feature","Profile") prof.Shape = face part.Base = prof part.Height = l else: part = document.addObject("Part::Feature","BOLTS_part") part.Label = name beam = face.extrude(Vector(0,0,l)) part.Shape = beam
def testSpace(self): FreeCAD.Console.PrintLog ('Checking Arch Space...\n') sb = Part.makeBox(1,1,1) b = FreeCAD.ActiveDocument.addObject('Part::Feature','Box') b.Shape = sb s = Arch.makeSpace([b]) self.failUnless(s,"Arch Space failed")
def read(filename): "reads the file and creates objects in the active document" z = zipfile.ZipFile(filename) homexml = z.read("Home.xml") handler = SH3DHandler(z) xml.sax.parseString(homexml,handler) FreeCAD.ActiveDocument.recompute() if not handler.makeIndividualWalls: delete = [] walls = [] for k,lines in handler.lines.items(): sk = FreeCAD.ActiveDocument.addObject("Sketcher::SketchObject","Walls_trace") for l in lines: for edge in l.Shape.Edges: sk.addGeometry(edge.Curve) delete.append(l.Name) FreeCAD.ActiveDocument.recompute() k = k.split(";") walls.append(Arch.makeWall(baseobj=sk,width=float(k[0]),height=float(k[1]))) for d in delete: FreeCAD.ActiveDocument.removeObject(d) w = walls.pop() w.Additions = walls w.Subtractions = handler.windows g = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup","Furniture") g.Group = handler.furniture FreeCAD.ActiveDocument.recompute()
def circle_hollow(params, document): od = params['D'] t = params['t'] l = params['l'] name = params['name'] id = od - t outer = Part.Wire(Part.makeCircle(0.5 * od)) inner = Part.Wire(Part.makeCircle(0.5 * id)) face = Part.Face([outer, inner]) if params['arch']: part = Arch.makeStructure(name=name) prof = document.addObject("Part::Feature", "Profile") prof.Shape = face part.Base = prof part.Height = l else: part = document.addObject("Part::Feature", "BOLTS_part") part.Label = name beam = face.extrude(Vector(0, 0, l)) part.Shape = beam
def makeSquareFooting(L, t, num, dia, covering, position): concrete = FreeCAD.ActiveDocument.addObject("Part::Box", "concrete") concrete.Length = L concrete.Width = L concrete.Height = t concrete.Placement.Base = Vector(-L / 2, -L / 2, 0) footing1 = Arch.makeStructure(concrete) footing1.ViewObject.Transparency = 80 FreeCAD.ActiveDocument.recompute() roundFactor = 2 R = roundFactor * dia face1 = getFaceNameFromVector(footing1, Vector(1, 0, 0)) face2 = getFaceNameFromVector(footing1, Vector(0, 1, 0)) face3 = getFaceNameFromVector(footing1, Vector(0, 0, 1)) rebar1 = UShapeRebar.makeUShapeRebar(f_cover=covering+dia/2.+R, \ b_cover=covering+dia/2., t_cover=covering, \ r_cover=covering+dia/2., l_cover=covering+dia/2., diameter=dia, \ rounding=2, amount_spacing_check=True, amount_spacing_value=num, \ orientation = "Bottom", structure = footing1, facename = face1) rebar2 = UShapeRebar.makeUShapeRebar(f_cover=covering+dia/2.+R, \ b_cover=covering+dia/2.+dia, t_cover=covering, \ r_cover=covering+dia/2., l_cover=covering+dia/2., diameter=dia, \ rounding=roundFactor, amount_spacing_check=True, amount_spacing_value=num, \ orientation = "Bottom", structure = footing1, facename = face2) covering1 = covering + dia + 9 / 2. stirrup = Stirrup.makeStirrup(l_cover=covering1, \ r_cover=covering1, t_cover=50+20, \ b_cover=covering1, f_cover=covering1, \ bentAngle=90, bentFactor=6, diameter=9, rounding=2,\ amount_spacing_check=True, amount_spacing_value=1, structure = footing1, facename = face3) FreeCAD.ActiveDocument.recompute()
def testSpace(self): FreeCAD.Console.PrintLog('Checking Arch Space...\n') sb = Part.makeBox(1, 1, 1) b = FreeCAD.ActiveDocument.addObject('Part::Feature', 'Box') b.Shape = sb s = Arch.makeSpace([b]) self.failUnless(s, "Arch Space failed")
def createATypedSharedLibrary(self, target, sources=[], deplibs=[], skip=[], **kwargs): env = self.myClone() nodes = [] for atype in self['ATYPES']: if atype not in skip: libEnv = env.myClone() if Arch.isWindows(): libEnv.AppendUnique(CPPDEFINES=CLVar('BUILDING_' + target.upper())) libTarget = '%s_%s' % (target, atype) libEnv['SHOBJSUFFIX'] = '_%s%s' % (atype, self['SHOBJSUFFIX']) nodes += libEnv.createSharedLibrary(libTarget, sources, deplibs, createPublicHeader=False, targetAType=atype, **kwargs) return nodes
def export(exportList,filename): "called when freecad exports a file" outfile = pythonopen(filename,"wb") ver = FreeCAD.Version() outfile.write("# FreeCAD v" + ver[0] + "." + ver[1] + " build" + ver[2] + " Arch module\n") outfile.write("# http://www.freecadweb.org\n") offset = 1 objectslist = Draft.getGroupContents(exportList,walls=True,addgroups=True) objectslist = Arch.pruneIncluded(objectslist) for obj in objectslist: if obj.isDerivedFrom("Part::Feature"): if obj.ViewObject.isVisible(): vlist,elist,flist = getIndices(obj.Shape,offset) if vlist == None: FreeCAD.Console.PrintError("Unable to export object "+obj.Label+". Skipping.\n") else: offset += len(vlist) outfile.write("o " + obj.Name + "\n") for v in vlist: outfile.write("v" + v + "\n") for e in elist: outfile.write("l" + e + "\n") for f in flist: outfile.write("f" + f + "\n") outfile.close() FreeCAD.Console.PrintMessage(translate("Arch","successfully written ").decode('utf8')+filename+"\n")
def read(filename): "reads the file and creates objects in the active document" z = zipfile.ZipFile(filename) homexml = z.read("Home.xml") handler = SH3DHandler(z) xml.sax.parseString(homexml, handler) FreeCAD.ActiveDocument.recompute() if not handler.makeIndividualWalls: delete = [] walls = [] for k, lines in handler.lines.items(): sk = FreeCAD.ActiveDocument.addObject("Sketcher::SketchObject", "Walls_trace") for l in lines: for edge in l.Shape.Edges: sk.addGeometry(edge.Curve) delete.append(l.Name) FreeCAD.ActiveDocument.recompute() k = k.split(";") walls.append( Arch.makeWall(baseobj=sk, width=float(k[0]), height=float(k[1]))) for d in delete: FreeCAD.ActiveDocument.removeObject(d) w = walls.pop() w.Additions = walls w.Subtractions = handler.windows g = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "Furniture") g.Group = handler.furniture FreeCAD.ActiveDocument.recompute()
def cbeam_parallel_flange(params, document): # key = params['type'] # not used h = params["h"] b = params["b"] tf = params["tf"] tw = params["tw"] r = params["r"] le = params["l"] name = params["name"] # lower flange, starting at the end of web, going counter-clockwise Vlf1 = Vector(0, (-h / 2), 0) Vlf2 = Vector(b, -h / 2, 0) Vlf3 = Vector(b, -h / 2 + tf, 0) Vlf4 = Vector((tw + r), (-h / 2 + tf), 0) Llf1 = makeLine(Vlf1, Vlf2) Llf2 = makeLine(Vlf2, Vlf3) Llf3 = makeLine(Vlf3, Vlf4) # upper flange, starting at the right web fillet, going clockwise Vuf1 = Vector(tw + r, (h / 2 - tf), 0) Vuf2 = Vector(b, (h / 2 - tf), 0) Vuf3 = Vector(b, h / 2, 0) Vuf4 = Vector(0, h / 2, 0) Luf1 = makeLine(Vuf1, Vuf2) Luf2 = makeLine(Vuf2, Vuf3) Luf3 = makeLine(Vuf3, Vuf4) # web, starting right bottom, going counter-clockwise Vw1 = Vector(tw, (-h / 2 + tf + r), 0) Vw2 = Vector(tw, (h / 2 - tf - r), 0) Lw1 = makeLine(Vw1, Vw2) Lw2 = makeLine(Vuf4, Vlf1) # center of the fillets, starting right bottom, going up Vfc1 = Vector((tw + r), (-h / 2 + tf + r), 0) Vfc2 = Vector((tw + r), (h / 2 - tf - r), 0) normal = Vector(0, 0, 1) Cfc1 = makeCircle(r, Vfc1, normal, 180, 270) Cfc2 = makeCircle(r, Vfc2, normal, 90, 180) # putting the segments together make a wire, a face and extrude it W = Part.Wire([Llf1, Llf2, Llf3, Cfc1, Lw1, Cfc2, Luf1, Luf2, Luf3, Lw2]) F = Part.Face(W) if params["arch"]: part = Arch.makeStructure(name=name) prof = document.addObject("Part::Feature", "Profile") prof.Shape = F part.Base = prof part.Height = le else: part = document.addObject("Part::Feature", "BOLTS_part") part.Label = name beam = F.extrude(Vector(0, 0, le)) part.Shape = beam
def cbeam_parallel_flange(params,document): key = params['type'] h = params['h'] b = params['b'] tf = params['tf'] tw = params['tw'] r = params ['r'] l = params['l'] name = params['name'] # lower flange, starting at the end of web, going counter-clockwise Vlf1 = Vector(0,(-h/2),0) Vlf2 = Vector(b,-h/2,0) Vlf3 = Vector(b,-h/2+tf,0) Vlf4 = Vector((tw+r),(-h/2+tf),0) Llf1 = makeLine(Vlf1,Vlf2) Llf2 = makeLine(Vlf2,Vlf3) Llf3 = makeLine(Vlf3,Vlf4) # upper flange, starting at the right web fillet, going clockwise Vuf1 = Vector(tw+r,(h/2-tf),0) Vuf2 = Vector(b,(h/2-tf),0) Vuf3 = Vector(b,h/2,0) Vuf4 = Vector(0,h/2,0) Luf1 = makeLine(Vuf1,Vuf2) Luf2 = makeLine(Vuf2,Vuf3) Luf3 = makeLine(Vuf3,Vuf4) # web, starting right bottom, going counter-clockwise Vw1 = Vector(tw,(-h/2+tf+r),0) Vw2 = Vector(tw,(h/2-tf-r),0) Lw1 = makeLine(Vw1,Vw2) Lw2 = makeLine(Vuf4 ,Vlf1) # center of the fillets, starting right bottom, going up Vfc1 = Vector((tw+r),(-h/2+tf+r),0) Vfc2 = Vector((tw+r),(h/2-tf-r),0) normal = Vector(0,0,1) Cfc1 = makeCircle(r,Vfc1,normal,180,270) Cfc2 = makeCircle(r,Vfc2,normal, 90,180) # putting the segments together make a wire, a face and extrude it W = Part.Wire([Llf1,Llf2,Llf3,Cfc1,Lw1,Cfc2,Luf1,Luf2,Luf3,Lw2]) F = Part.Face(W) if params['arch']: part = Arch.makeStructure(name=name) prof = document.addObject("Part::Feature","Profile") prof.Shape = F part.Base = prof part.Height = l else: part = document.addObject("Part::Feature","BOLTS_part") part.Label = name beam = F.extrude(Vector(0,0,l)) part.Shape = beam
def testWindow(self): FreeCAD.Console.PrintLog ('Checking Arch Window...\n') l=Draft.makeLine(FreeCAD.Vector(0,0,0),FreeCAD.Vector(-2,0,0)) w = Arch.makeWall(l) sk = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Sketch001') sk.Support = (w,["Face3"]) sk.addGeometry(Part.Line(FreeCAD.Vector(-1.80,1.30,0),FreeCAD.Vector(-0.90,1.30,0))) sk.addGeometry(Part.Line(FreeCAD.Vector(-0.90,1.30,0),FreeCAD.Vector(-0.90,0.25,0))) sk.addGeometry(Part.Line(FreeCAD.Vector(-0.90,0.25,0),FreeCAD.Vector(-1.80,0.25,0))) sk.addGeometry(Part.Line(FreeCAD.Vector(-1.80,0.25,0),FreeCAD.Vector(-1.80,1.30,0))) sk.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1)) sk.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1)) sk.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1)) sk.addConstraint(Sketcher.Constraint('Coincident',3,2,0,1)) win = Arch.makeWindow(sk) Arch.removeComponents(win,host=w) self.failUnless(win,"Arch Window failed")
def makeBase(self, obj): base = Arch.makeStructure() base.setEditorMode("Width", 1) base.setEditorMode("Height", 1) base.setEditorMode("Length", 1) base.setEditorMode("Placement", 1) return base """
def testEquipment(self): FreeCAD.Console.PrintLog('Checking Arch Equipment...\n') box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box") box.Length = 500 box.Width = 2000 box.Height = 600 equip = Arch.makeEquipment(box) self.failUnless(equip, "Arch Equipment failed")
def export(exportList,filename,tessellation=1): "called when freecad exports a file" if not checkCollada(): return p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") scale = p.GetFloat("ColladaScalingFactor",1.0) colmesh = collada.Collada() colmesh.assetInfo.upaxis = collada.asset.UP_AXIS.Z_UP effect = collada.material.Effect("effect0", [], "phong", diffuse=(.7,.7,.7), specular=(1,1,1)) mat = collada.material.Material("material0", "mymaterial", effect) colmesh.effects.append(effect) colmesh.materials.append(mat) objind = 0 scenenodes = [] objectslist = Draft.getGroupContents(exportList,walls=True,addgroups=True) objectslist = Arch.pruneIncluded(objectslist) for obj in objectslist: vindex = [] nindex = [] findex = [] m = None if obj.isDerivedFrom("Part::Feature"): print "exporting object ",obj.Name, obj.Shape m = Mesh.Mesh(triangulate(obj.Shape)) elif obj.isDerivedFrom("Mesh::Feature"): print "exporting object ",obj.Name, obj.Mesh m = obj.Mesh if m: # vertex indices for v in m.Topology[0]: vindex.extend([v.x*scale,v.y*scale,v.z*scale]) # normals for f in m.Facets: n = f.Normal nindex.extend([n.x,n.y,n.z]) # face indices for i in range(len(m.Topology[1])): f = m.Topology[1][i] findex.extend([f[0],i,f[1],i,f[2],i]) print len(vindex), " vert indices, ", len(nindex), " norm indices, ", len(findex), " face indices." vert_src = collada.source.FloatSource("cubeverts-array"+str(objind), numpy.array(vindex), ('X', 'Y', 'Z')) normal_src = collada.source.FloatSource("cubenormals-array"+str(objind), numpy.array(nindex), ('X', 'Y', 'Z')) geom = collada.geometry.Geometry(colmesh, "geometry"+str(objind), obj.Name, [vert_src, normal_src]) input_list = collada.source.InputList() input_list.addInput(0, 'VERTEX', "#cubeverts-array"+str(objind)) input_list.addInput(1, 'NORMAL', "#cubenormals-array"+str(objind)) triset = geom.createTriangleSet(numpy.array(findex), input_list, "materialref") geom.primitives.append(triset) colmesh.geometries.append(geom) matnode = collada.scene.MaterialNode("materialref", mat, inputs=[]) geomnode = collada.scene.GeometryNode(geom, [matnode]) node = collada.scene.Node("node"+str(objind), children=[geomnode]) scenenodes.append(node) objind += 1 myscene = collada.scene.Scene("myscene", scenenodes) colmesh.scenes.append(myscene) colmesh.scene = myscene colmesh.write(filename) FreeCAD.Console.PrintMessage(translate("Arch","file %s successfully created.") % filename)
def create_structures(self, areas): areas_thickness = self._safe.get_thickness(areas) structures = {} for key, area in areas.items(): thickness = areas_thickness[key] - 93 structures[key] = Arch.makeStructure(area, height=thickness) Draft.autogroup(structures[key]) Draft.move(structures[key], App.Vector(0, 0, -thickness), copy=False) return structures
def makeWall(entity, shape=None): "makes a wall in the freecad document" try: if DEBUG: print "=====> making wall", entity.id if shape: sh = FreeCAD.ActiveDocument.addObject("Part::Feature", "WallBody") sh.Shape = shape wall = Arch.makeWall(sh, name="Wall" + str(entity.id)) if DEBUG: print "made wall object ", entity.id, ":", wall return placement = wall = wire = body = width = height = None placement = getPlacement(entity.ObjectPlacement) if DEBUG: print "got wall placement", entity.id, ":", placement width = entity.getProperty("Width") height = entity.getProperty("Height") if width and height: if DEBUG: print "got width, height ", entity.id, ":", width, "/", height for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Axis": wire = getWire(r.Items, placement) wall = Arch.makeWall(wire, width, height, align="Center", name="Wall" + str(entity.id)) else: if DEBUG: print "no height or width properties found..." for r in entity.Representation.Representations: if r.RepresentationIdentifier == "Body": for b in r.Items: if b.type == "IFCEXTRUDEDAREASOLID": norm = getVector(b.ExtrudedDirection) norm.normalize() wire = getWire(b.SweptArea, placement) wall = Arch.makeWall(wire, width=0, height=b.Depth, name="Wall" + str(entity.id)) wall.Normal = norm if wall: if DEBUG: print "made wall object ", entity.id, ":", wall except: if DEBUG: print "error: skipping wall", entity.id
def generate(env): cv = get_config_vars() pylib = 'python'+get_python_version() pylibpath = [cv[var] for var in ('LIBDIR', 'LIBPL')] env.Append(CPPPATH=[get_python_inc(),numpy.get_include()]) if Arch.isWindows(): env.Append(LIBS=pylib.replace(".","")) env.Append(LIBPATH=pylibpath) else: env.Append(LIBS=pylib) env.Append(LIBPATH=pylibpath)
def makeRoof(entity,shape=None,name="Roof"): "makes a roof in the freecad document" try: if shape: # use ifcopenshell roof = Arch.makeRoof(name=name) roof.Label = name roof.Shape = shape if DEBUG: print "made roof object ",entity,":",roof return roof except: return None
def makeSite(entity,shape=None,name="Site"): "makes a site in the freecad document" try: if shape: # use ifcopenshell site = Arch.makeSite(name=name) site.Label = name body = FreeCAD.ActiveDocument.addObject("Part::Feature",name+"_body") body.Shape = shape site.Terrain = body if DEBUG: print "made site object ",entity,":",site return site except: return None
def draw_section_view(view, page_name): obj_ref = App.ActiveDocument.getObject(view.obj) view_ref = Arch.makeSectionPlane([obj_ref]) view_ref.Placement = App.Placement(App.Vector(view.x_dir, view.y_dir, view.z_dir), App.Rotation(App.Vector(view.axis_x, view.axis_y, view.axis_z), view.angle2axis)) Draft.makeShape2DView(view_ref) page_ref = App.ActiveDocument.getObject(page_name) draw_ref = Draft.makeDrawingView(view_ref, page_ref) draw_ref.X = view.x_pos draw_ref.Y = view.y_pos draw_ref.Scale = view.scale draw_ref.Rotation = view.rotation App.ActiveDocument.recompute()
def export(exportList,filename): "called when freecad exports a file" try: import ifcWriter except: print "IFC export: ifcWriter not found or unusable" return import Arch,Draft application = "FreeCAD" ver = FreeCAD.Version() version = ver[0]+"."+ver[1]+" build"+ver[2] owner = FreeCAD.ActiveDocument.CreatedBy company = FreeCAD.ActiveDocument.Company project = FreeCAD.ActiveDocument.Name ifc = ifcWriter.IfcDocument(filename,project,owner,company,application,version) for obj in exportList: otype = Draft.getType(obj) gdata = Arch.getExtrusionData(obj) if not data: fdata = Arch.getBrepFacesData(obj) if otype == "Wall": if gdata: ifc.addWall( ifc.addExtrudedPolyline(gdata) ) elif fdata: ifc.addWall( ifc.addFacetedBrep(fdata) ) else: print "IFC export: error retrieving the shape of object ", obj.Name else: print "object type ", otype, " is not supported yet." ifc.write() print "Successfully exported ",filename
def makeSpace(entity,shape=None,name="Space"): "makes a space in the freecad document" try: if shape: # use ifcopenshell if isinstance(shape,Part.Shape): space = Arch.makeSpace(name=name) space.Label = name body = FreeCAD.ActiveDocument.addObject("Part::Feature",name+"_body") body.Shape = shape space.Base = body if DEBUG: print "made space object ",entity,":",space return site except: return None
def setBaseVars(env,cla): for o in optionsList: env[o[0]] = o[1] for k,v in cla.iteritems(): if v in ['True','true']: v = True elif v in ['False', 'false']: v = False env[k] = v env['DEBUG'] = (env['VERSION'] == 'debug') env['PROFILE'] = (env['VERSION'] == 'profile') env['ARCH'] = Arch.getArch() sconstructDir = os.path.abspath(str(env.fs.SConstruct_dir)) #print sconstructDir env['TOPDIR'] = sconstructDir env['SRCDIR'] = '$TOPDIR/src' if env['BUILDDIR'] is None: env['BUILDDIR'] = '$TOPDIR/build' if isinstance(env['ATYPES'],types.StringType): env['ATYPES'] = [atype.lower() for atype in env['ATYPES'].split(',')] # Third-party packages directory variables if env['PACKAGESDIR'] is None: env['PACKAGESDIR'] = '$TOPDIR/packages/$ARCH' env['PACKAGESLIBDIR'] = '$PACKAGESDIR/lib' # Propagate the following env variables for var in ['TMP', 'TEMP', 'LD_LIBRARY_PATH', 'PATH']: if var in os.environ: env['ENV'][var] = os.environ[var] # Redefine command string variables for compact output. if env['COMPACTOUTPUT']: for var in ['SHCXXCOMSTR', 'CXXCOMSTR', 'CCCOMSTR', 'SHCCCOMSTR']: env[var] = 'Compiling $SOURCE' for var in ['SHLINKCOMSTR', 'LINKCOMSTR', 'LDMODULECOMSTR']: env[var] = 'Linking $TARGET' env['SWIGCOMSTR'] = 'Building swig module for $SOURCE'
def createATypedSharedLibrary(self, target, sources=[], deplibs=[], skip=[],**kwargs): env = self.myClone() nodes = [] for atype in self['ATYPES']: if atype not in skip: libEnv = env.myClone() if Arch.isWindows(): libEnv.AppendUnique(CPPDEFINES= CLVar('BUILDING_' + target.upper())) libTarget = '%s_%s' % (target, atype) libEnv['SHOBJSUFFIX'] = '_%s%s' % (atype, self['SHOBJSUFFIX']) nodes += libEnv.createSharedLibrary(libTarget, sources, deplibs, createPublicHeader=False, targetAType=atype, **kwargs) return nodes
def draw_section_view(view): App.ActiveDocument.addObject('Drawing::FeaturePage',view.page) page_ref = App.ActiveDocument.getObject(view.page) # Choose the specific template page_ref.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg' obj_ref = App.ActiveDocument.getObject(view.obj) view_ref = Arch.makeSectionPlane([obj_ref]) section_height = center_of_storey(view.storey) view_ref.Placement = App.Placement(App.Vector(view.x_dir, view.y_dir, section_height), App.Rotation(App.Vector(view.axis_x, view.axis_y, view.axis_z), view.angle2axis)) Draft.makeShape2DView(view_ref) #page_ref = App.ActiveDocument.getObject(page_name) draw_ref = Draft.makeDrawingView(view_ref, page_ref) draw_ref.X = view.x_pos draw_ref.Y = view.y_pos draw_ref.Scale = view.scale draw_ref.Rotation = view.rotation App.ActiveDocument.recompute()