def resetColors(self, vobj): colors = [] for o in groups.get_group_contents(vobj.Object.Objects): if o.isDerivedFrom("Part::Feature"): if len(o.ViewObject.DiffuseColor) > 1: colors.extend(o.ViewObject.DiffuseColor) else: c = o.ViewObject.ShapeColor c = (c[0], c[1], c[2], o.ViewObject.Transparency / 100.0) for f in o.Shape.Faces: # TODO: verify this line colors.append(c) elif o.hasExtension("App::GeoFeatureGroupExtension"): for so in vobj.Object.Group: if so.isDerivedFrom("Part::Feature"): if len(so.ViewObject.DiffuseColor) > 1: colors.extend(so.ViewObject.DiffuseColor) else: c = so.ViewObject.ShapeColor c = (c[0], c[1], c[2], so.ViewObject.Transparency / 100.0) for f in so.Shape.Faces: colors.append(c) if colors: vobj.DiffuseColor = colors
def execute(self, obj): """Execute when the object is created or recomputed.""" result = "" if hasattr(obj, "Source") and obj.Source: if hasattr(obj, "LineStyle"): ls = obj.LineStyle else: ls = None if hasattr(obj, "LineColor"): lc = obj.LineColor else: lc = None if hasattr(obj, "LineSpacing"): lp = obj.LineSpacing else: lp = None if obj.Source.isDerivedFrom("App::DocumentObjectGroup"): svg = "" objs = groups.get_group_contents([obj.Source]) for o in objs: v = o.ViewObject.isVisible() if hasattr(obj, "AlwaysOn") and obj.AlwaysOn: v = True if v: svg += get_svg.get_svg(o, obj.Scale, obj.LineWidth, obj.FontSize.Value, obj.FillStyle, obj.Direction, ls, lc, lp) else: svg = get_svg.get_svg(obj.Source, obj.Scale, obj.LineWidth, obj.FontSize.Value, obj.FillStyle, obj.Direction, ls, lc, lp) result += '<g id="' + obj.Name + '"' result += ' transform="' result += 'rotate(' + str(obj.Rotation) + ',' result += str(obj.X) + ',' + str(obj.Y) result += ') ' result += 'translate(' + str(obj.X) + ',' + str(obj.Y) + ') ' result += 'scale(' + str(obj.Scale) + ',' + str(-obj.Scale) result += ')' result += '">' result += svg result += '</g>' obj.ViewResult = result
def proceed(self): """Continue with the command after a selection has been made.""" if self.call: self.view.removeEventCallback("SoEvent", self.call) self.selected_objects = Gui.Selection.getSelection() self.selected_objects = \ groups.get_group_contents(self.selected_objects, addgroups=True, spaces=True, noarchchild=True) self.selected_subelements = Gui.Selection.getSelectionEx() self.step = 0 self.center = None self.ui.rotateSetCenterUi() self.arctrack = trackers.arcTracker() self.call = self.view.addEventCallback("SoEvent", self.action) _msg(translate("draft", "Pick rotation center"))
def proceed(self): """Proceed with execution of the command after selection.""" if self.call: self.view.removeEventCallback("SoEvent", self.call) self.selected_objects = Gui.Selection.getSelection() self.selected_objects = \ groups.get_group_contents(self.selected_objects) self.selected_subelements = Gui.Selection.getSelectionEx() self.refs = [] self.ui.pointUi(self.name) self.ui.modUi() self.ui.xValue.setFocus() self.ui.xValue.selectAll() self.pickmode = False self.task = None self.call = self.view.addEventCallback("SoEvent", self.action) _msg(translate("draft", "Pick base point"))
def proceed(self): """Continue with the command after a selection has been made.""" if self.call: self.view.removeEventCallback("SoEvent", self.call) self.selected_objects = Gui.Selection.getSelection() self.selected_objects = \ groups.get_group_contents(self.selected_objects, addgroups=True, spaces=True, noarchchild=True) self.selected_subelements = Gui.Selection.getSelectionEx() self.ui.lineUi(self.name, icon="Draft_Move") self.ui.modUi() if self.copymode: self.ui.isCopy.setChecked(True) self.ui.xValue.setFocus() self.ui.xValue.selectAll() self.call = self.view.addEventCallback("SoEvent", self.action) _msg(translate("draft", "Pick start point"))
def Activated(self): """Execute when the command is called. If the selection is a single group, it selects all objects inside this group. In other cases it selects all objects (children) in the OutList of this object, and also all objects (parents) in the InList of this object. For all parents, it also selects the children of these. """ super(SelectGroup, self).Activated() sel = Gui.Selection.getSelection() if len(sel) == 1: if sel[0].isDerivedFrom("App::DocumentObjectGroup"): cts = groups.get_group_contents(Gui.Selection.getSelection()) for o in cts: Gui.Selection.addSelection(o) return for obj in sel: # This selects the objects in the `OutList` # which are actually `parents` but appear below in the tree. # Regular objects usually have an empty `OutList` # so this is skipped. # But for groups, it selects the objects # that it contains under it. for child in obj.OutList: Gui.Selection.addSelection(child) # This selects the upper group that contains `obj`. # Then for this group, it selects the objects in its `OutList`, # which are at the same level as `obj` (brothers). for parent in obj.InList: Gui.Selection.addSelection(parent) for child in parent.OutList: Gui.Selection.addSelection(child)
def execute(self,obj): if not getattr(obj,"AutoUpdate", True): return True import Part, DraftGeomUtils obj.positionBySupport() pl = obj.Placement if obj.Base: if utils.get_type(obj.Base) in ["BuildingPart","SectionPlane"]: objs = [] if utils.get_type(obj.Base) == "SectionPlane": objs = self.excludeNames(obj,obj.Base.Objects) cutplane = obj.Base.Shape else: objs = self.excludeNames(obj,obj.Base.Group) cutplane = Part.makePlane(1000, 1000, App.Vector(-500, -500, 0)) m = 1 if obj.Base.ViewObject and hasattr(obj.Base.ViewObject,"CutMargin"): m = obj.Base.ViewObject.CutMargin.Value cutplane.translate(App.Vector(0,0,m)) cutplane.Placement = cutplane.Placement.multiply(obj.Base.Placement) if objs: onlysolids = True if hasattr(obj.Base,"OnlySolids"): onlysolids = obj.Base.OnlySolids if hasattr(obj,"OnlySolids"): # override base object onlysolids = obj.OnlySolids import Arch objs = groups.get_group_contents(objs, walls=True) if getattr(obj,"VisibleOnly",True): objs = gui_utils.remove_hidden(objs) shapes = [] if getattr(obj,"FuseArch", False): shtypes = {} for o in objs: if utils.get_type(o) in ["Wall","Structure"]: if onlysolids: shtypes.setdefault(o.Material.Name if (hasattr(o,"Material") and o.Material) else "None",[]).extend(o.Shape.Solids) else: shtypes.setdefault(o.Material.Name if (hasattr(o,"Material") and o.Material) else "None",[]).append(o.Shape.copy()) elif hasattr(o,'Shape'): if onlysolids: shapes.extend(o.Shape.Solids) else: shapes.append(o.Shape.copy()) for k, v in shtypes.items(): v1 = v.pop() if v: v1 = v1.multiFuse(v) v1 = v1.removeSplitter() if v1.Solids: shapes.extend(v1.Solids) else: print("Shape2DView: Fusing Arch objects produced non-solid results") shapes.append(v1) else: for o in objs: if hasattr(o,'Shape'): if onlysolids: shapes.extend(o.Shape.Solids) else: shapes.append(o.Shape.copy()) clip = False if hasattr(obj.Base,"Clip"): clip = obj.Base.Clip if hasattr(obj,"Clip"): #override base object clip = obj.Clip depth = None if hasattr(obj.Base,"Depth"): depth = obj.Base.Depth.Value cutp, cutv, iv = Arch.getCutVolume(cutplane, shapes, clip, depth) cuts = [] opl = App.Placement(obj.Base.Placement) proj = opl.Rotation.multVec(App.Vector(0, 0, 1)) if obj.ProjectionMode in ["Solid","Solid faces"]: shapes_to_cut = shapes if obj.ProjectionMode == "Solid faces": shapes_to_cut = [] for s in shapes: shapes_to_cut.extend(s.Faces) for sh in shapes_to_cut: if cutv: if sh.Volume < 0: sh.reverse() #if cutv.BoundBox.intersect(sh.BoundBox): # c = sh.cut(cutv) #else: # c = sh.copy() c = sh.cut(cutv) if onlysolids: cuts.extend(c.Solids) else: cuts.append(c) else: if onlysolids: cuts.extend(sh.Solids) else: cuts.append(sh.copy()) comp = Part.makeCompound(cuts) obj.Shape = self.getProjected(obj,comp,proj) elif obj.ProjectionMode in ["Cutlines", "Cutfaces"]: for sh in shapes: if sh.Volume < 0: sh.reverse() c = sh.section(cutp) if hasattr(obj,"InPlace"): if not obj.InPlace: c = self.getProjected(obj, c, proj) faces = [] if (obj.ProjectionMode == "Cutfaces") and (sh.ShapeType == "Solid"): wires = DraftGeomUtils.findWires(c.Edges) for w in wires: if w.isClosed(): faces.append(Part.Face(w)) if faces: cuts.extend(faces) else: cuts.append(c) comp = Part.makeCompound(cuts) opl = App.Placement(obj.Base.Placement) comp.Placement = opl.inverse() if comp: obj.Shape = comp elif obj.Base.isDerivedFrom("App::DocumentObjectGroup"): shapes = [] objs = self.excludeNames(obj,groups.get_group_contents(obj.Base)) for o in objs: if hasattr(o,'Shape'): if o.Shape: if not o.Shape.isNull(): shapes.append(o.Shape) if shapes: import Part comp = Part.makeCompound(shapes) obj.Shape = self.getProjected(obj,comp,obj.Projection) elif hasattr(obj.Base,'Shape'): if not DraftVecUtils.isNull(obj.Projection): if obj.ProjectionMode == "Solid": obj.Shape = self.getProjected(obj,obj.Base.Shape,obj.Projection) elif obj.ProjectionMode == "Individual Faces": import Part if obj.FaceNumbers: faces = [] for i in obj.FaceNumbers: if len(obj.Base.Shape.Faces) > i: faces.append(obj.Base.Shape.Faces[i]) views = [] for f in faces: views.append(self.getProjected(obj,f,obj.Projection)) if views: obj.Shape = Part.makeCompound(views) else: App.Console.PrintWarning(obj.ProjectionMode+" mode not implemented\n") if not DraftGeomUtils.isNull(pl): obj.Placement = pl