def _set_properties(self, vobj): """Set the properties of objects if they don't exist.""" super(ViewProviderWire, self)._set_properties(vobj) if not hasattr(vobj, "EndArrow"): _tip = "Displays a Dimension symbol at the end of the wire." vobj.addProperty("App::PropertyBool", "EndArrow", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) vobj.EndArrow = False if not hasattr(vobj, "ArrowSize"): _tip = "Arrow size" vobj.addProperty("App::PropertyLength", "ArrowSize", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) vobj.ArrowSize = utils.get_param("arrowsize", 0.1) if not hasattr(vobj, "ArrowType"): _tip = "Arrow type" vobj.addProperty("App::PropertyEnumeration", "ArrowType", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) vobj.ArrowType = utils.ARROW_TYPES vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol", 0)]
def set_properties(self, vobj): """Set the properties only if they don't already exist.""" super(ViewProviderText, self).set_properties(vobj) properties = vobj.PropertiesList if "FontSize" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The size of the text") vobj.addProperty("App::PropertyLength", "FontSize", "Text", _tip) vobj.FontSize = utils.get_param("textheight", 1) if "FontName" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The font of the text") vobj.addProperty("App::PropertyFont", "FontName", "Text", _tip) vobj.FontName = utils.get_param("textfont", "sans") if "Justification" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The vertical alignment of the text") vobj.addProperty("App::PropertyEnumeration", "Justification", "Text", _tip) vobj.Justification = ["Left", "Center", "Right"] if "TextColor" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Text color") vobj.addProperty("App::PropertyColor", "TextColor", "Text", _tip) if "LineSpacing" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Line spacing (relative to font size)") vobj.addProperty("App::PropertyFloat", "LineSpacing", "Text", _tip)
def set_properties(self, vobj): vobj.addProperty("App::PropertyFloat","ScaleMultiplier", "Annotation",QT_TRANSLATE_NOOP("App::Property", "Dimension size overall multiplier")) vobj.addProperty("App::PropertyLength","FontSize", "Text",QT_TRANSLATE_NOOP("App::Property", "The size of the text")) vobj.addProperty("App::PropertyFont","FontName", "Text",QT_TRANSLATE_NOOP("App::Property", "The font of the text")) vobj.addProperty("App::PropertyEnumeration","Justification", "Text",QT_TRANSLATE_NOOP("App::Property", "The vertical alignment of the text")) vobj.addProperty("App::PropertyColor","TextColor", "Text",QT_TRANSLATE_NOOP("App::Property", "Text color")) vobj.addProperty("App::PropertyFloat","LineSpacing", "Text",QT_TRANSLATE_NOOP("App::Property", "Line spacing (relative to font size)")) param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") annotation_scale = param.GetFloat("DraftAnnotationScale", 1.0) vobj.ScaleMultiplier = 1 / annotation_scale vobj.Justification = ["Left","Center","Right"] vobj.FontName = utils.get_param("textfont","sans") vobj.FontSize = utils.get_param("textheight",1)
def set_units_properties(self, vobj, properties): """Set unit properties only if they don't already exist.""" if "Decimals" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The number of decimals to show") vobj.addProperty("App::PropertyInteger", "Decimals", "Units", _tip) vobj.Decimals = utils.get_param("dimPrecision", 2) if "ShowUnit" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Show the unit suffix") vobj.addProperty("App::PropertyBool", "ShowUnit", "Units", _tip) vobj.ShowUnit = utils.get_param("showUnit", True) if "UnitOverride" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "A unit to express the measurement.\n" "Leave blank for system default") vobj.addProperty("App::PropertyString", "UnitOverride", "Units", _tip) vobj.UnitOverride = utils.get_param("overrideUnit", '')
def set_text_properties(self, vobj, properties): """Set text properties only if they don't already exist.""" if "TextSize" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The size of the text") vobj.addProperty("App::PropertyLength", "TextSize", "Text", _tip) vobj.TextSize = utils.get_param("textheight", 1) if "TextFont" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The font of the text") vobj.addProperty("App::PropertyFont", "TextFont", "Text", _tip) vobj.TextFont = utils.get_param("textfont") if "TextAlignment" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The vertical alignment of the text") vobj.addProperty("App::PropertyEnumeration", "TextAlignment", "Text", _tip) vobj.TextAlignment = ["Top", "Middle", "Bottom"] vobj.TextAlignment = "Bottom" if "TextColor" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Text color") vobj.addProperty("App::PropertyColor", "TextColor", "Text", _tip) if "MaxChars" not in properties: _tip = QT_TRANSLATE_NOOP( "App::Property", "The maximum number of characters " "on each line of the text box") vobj.addProperty("App::PropertyInteger", "MaxChars", "Text", _tip)
def set_text_properties(self, vobj, properties): """Set text properties only if they don't already exist.""" if "FontName" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Font name") vobj.addProperty("App::PropertyFont", "FontName", "Text", _tip) vobj.FontName = utils.get_param("textfont", "") if "FontSize" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Font size") vobj.addProperty("App::PropertyLength", "FontSize", "Text", _tip) vobj.FontSize = utils.get_param("textheight", 0.20) if "TextSpacing" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Spacing between text and dimension line") vobj.addProperty("App::PropertyLength", "TextSpacing", "Text", _tip) vobj.TextSpacing = utils.get_param("dimspacing", 1) if "FlipText" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Rotate the dimension text 180 degrees") vobj.addProperty("App::PropertyBool", "FlipText", "Text", _tip) vobj.FlipText = False if "TextPosition" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Text Position.\n" "Leave '(0,0,0)' for automatic position") vobj.addProperty("App::PropertyVectorDistance", "TextPosition", "Text", _tip) vobj.TextPosition = App.Vector(0, 0, 0) if "Override" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Text override.\n" "Write '$dim' so that it is replaced by " "the dimension length.") vobj.addProperty("App::PropertyString", "Override", "Text", _tip) vobj.Override = ''
def set_graphics_properties(self, vobj, properties): """Set graphics properties only if they don't already exist.""" if "ArrowSize" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The size of the arrow") vobj.addProperty("App::PropertyLength", "ArrowSize", "Graphics", _tip) vobj.ArrowSize = utils.get_param("arrowsize", 1) if "ArrowType" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The type of arrow of this label") vobj.addProperty("App::PropertyEnumeration", "ArrowType", "Graphics", _tip) vobj.ArrowType = utils.ARROW_TYPES vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol")] if "Frame" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "The type of frame around the text " "of this object") vobj.addProperty("App::PropertyEnumeration", "Frame", "Graphics", _tip) vobj.Frame = ["None", "Rectangle"] if "Line" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Display a leader line or not") vobj.addProperty("App::PropertyBool", "Line", "Graphics", _tip) vobj.Line = True if "LineWidth" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Line width") vobj.addProperty("App::PropertyFloat", "LineWidth", "Graphics", _tip) vobj.LineWidth = utils.get_param("linewidth", 1) if "LineColor" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Line color") vobj.addProperty("App::PropertyColor", "LineColor", "Graphics", _tip)
def set_graphics_properties(self, vobj, properties): """Set graphics properties only if they don't already exist.""" super(ViewProviderDimensionBase, self).set_graphics_properties(vobj, properties) if "ArrowSize" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Arrow size") vobj.addProperty("App::PropertyLength", "ArrowSize", "Graphics", _tip) vobj.ArrowSize = utils.get_param("arrowsize", 1) if "ArrowType" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Arrow type") vobj.addProperty("App::PropertyEnumeration", "ArrowType", "Graphics", _tip) vobj.ArrowType = utils.ARROW_TYPES vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol", 0)] if "FlipArrows" not in properties: _tip = QT_TRANSLATE_NOOP( "App::Property", "Rotate the dimension arrows 180 degrees") vobj.addProperty("App::PropertyBool", "FlipArrows", "Graphics", _tip) vobj.FlipArrows = False if "DimOvershoot" not in properties: _tip = QT_TRANSLATE_NOOP( "App::Property", "The distance the dimension line " "is extended\n" "past the extension lines") vobj.addProperty("App::PropertyDistance", "DimOvershoot", "Graphics", _tip) vobj.DimOvershoot = utils.get_param("dimovershoot", 0) if "ExtLines" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Length of the extension lines") vobj.addProperty("App::PropertyDistance", "ExtLines", "Graphics", _tip) vobj.ExtLines = utils.get_param("extlines", 0.3) if "ExtOvershoot" not in properties: _tip = QT_TRANSLATE_NOOP( "App::Property", "Length of the extension line\n" "above the dimension line") vobj.addProperty("App::PropertyDistance", "ExtOvershoot", "Graphics", _tip) vobj.ExtOvershoot = utils.get_param("extovershoot", 0) if "ShowLine" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Shows the dimension line and arrows") vobj.addProperty("App::PropertyBool", "ShowLine", "Graphics", _tip) vobj.ShowLine = True
def __init__(self, obj): super(BezCurve, self).__init__(obj, "BezCurve") _tip = QT_TRANSLATE_NOOP("App::Property", "The points of the Bezier curve") obj.addProperty("App::PropertyVectorList", "Points", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "The degree of the Bezier function") obj.addProperty("App::PropertyInteger", "Degree", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Continuity") obj.addProperty("App::PropertyIntegerList", "Continuity", "Draft", _tip) _tip = QT_TRANSLATE_NOOP( "App::Property", "If the Bezier curve should be closed or not") obj.addProperty("App::PropertyBool", "Closed", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Create a face if this curve is closed") obj.addProperty("App::PropertyBool", "MakeFace", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "The length of this object") obj.addProperty("App::PropertyLength", "Length", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "The area of this object") obj.addProperty("App::PropertyArea", "Area", "Draft", _tip) obj.MakeFace = utils.get_param("fillmode", True) obj.Closed = False obj.Degree = 3 obj.Continuity = [] #obj.setEditorMode("Degree", 2) obj.setEditorMode("Continuity", 1)
def __init__(self, point=App.Vector(0, 0, 0), size=10, string="", font=""): self.form = Gui.PySideUic.loadUi(":/ui/TaskShapeString.ui") self.form.setObjectName("ShapeStringTaskPanel") self.form.setWindowTitle(translate("draft", "ShapeString")) self.form.setWindowIcon(QtGui.QIcon(":/icons/Draft_ShapeString.svg")) unit_length = App.Units.Quantity( 0.0, App.Units.Length).getUserPreferred()[2] self.form.sbX.setProperty('rawValue', point.x) self.form.sbX.setProperty('unit', unit_length) self.form.sbY.setProperty('rawValue', point.y) self.form.sbY.setProperty('unit', unit_length) self.form.sbZ.setProperty('rawValue', point.z) self.form.sbZ.setProperty('unit', unit_length) self.form.sbHeight.setProperty('rawValue', size) self.form.sbHeight.setProperty('unit', unit_length) self.stringText = string if string else translate("draft", "Default") self.form.leString.setText(self.stringText) self.platWinDialog("Overwrite") self.fileSpec = font if font else get_param("FontFile", "") self.form.fcFontFile.setFileName(self.fileSpec) self.point = point self.pointPicked = False # Default for the "DontUseNativeFontDialog" preference: self.font_dialog_pref = False # Dummy attribute used by gui_tools_utils.getPoint in action method self.node = None QtCore.QObject.connect( self.form.fcFontFile, QtCore.SIGNAL("fileNameSelected(const QString&)"), self.fileSelect) QtCore.QObject.connect(self.form.pbReset, QtCore.SIGNAL("clicked()"), self.resetPoint)
def onChanged(self, vobj, prop): if prop in ["EndArrow", "ArrowSize", "ArrowType", "Visibility"]: rn = vobj.RootNode if hasattr(self, "pt") and hasattr(vobj, "EndArrow"): if vobj.EndArrow and vobj.Visibility: self.pt.removeChild(self.symbol) s = utils.ARROW_TYPES.index(vobj.ArrowType) self.symbol = gui_utils.dim_symbol(s) self.pt.addChild(self.symbol) self.updateData(vobj.Object, "Points") if hasattr(vobj, "ArrowSize"): s = vobj.ArrowSize else: s = utils.get_param("arrowsize", 0.1) self.coords.scaleFactor.setValue((s, s, s)) rn.addChild(self.pt) else: if self.symbol: if self.pt.findChild(self.symbol) != -1: self.pt.removeChild(self.symbol) if rn.findChild(self.pt) != -1: rn.removeChild(self.pt) if prop in ["LineColor"]: if hasattr(self, "pt"): self.pt[0].rgb.setValue(vobj.LineColor[0], vobj.LineColor[1], vobj.LineColor[2]) super(ViewProviderWire, self).onChanged(vobj, prop) return
def __init__(self, obj): super(Rectangle, self).__init__(obj, "Rectangle") _tip = QT_TRANSLATE_NOOP("App::Property", "Length of the rectangle") obj.addProperty("App::PropertyDistance", "Length", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Height of the rectangle") obj.addProperty("App::PropertyDistance", "Height", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Radius to use to fillet the corners") obj.addProperty("App::PropertyLength", "FilletRadius", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Size of the chamfer to give to the corners") obj.addProperty("App::PropertyLength", "ChamferSize", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Create a face") obj.addProperty("App::PropertyBool", "MakeFace", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Horizontal subdivisions of this rectangle") obj.addProperty("App::PropertyInteger", "Rows", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Vertical subdivisions of this rectangle") obj.addProperty("App::PropertyInteger", "Columns", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "The area of this object") obj.addProperty("App::PropertyArea", "Area", "Draft", _tip) obj.MakeFace = get_param("fillmode",True) obj.Length=1 obj.Height=1 obj.Rows=1 obj.Columns=1
def __init__(self, obj): super(Polygon, self).__init__(obj, "Polygon") _tip = QT_TRANSLATE_NOOP("App::Property", "Number of faces") obj.addProperty("App::PropertyInteger", "FacesNumber", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Radius of the control circle") obj.addProperty("App::PropertyLength", "Radius", "Draft", _tip) _tip = QT_TRANSLATE_NOOP( "App::Property", "How the polygon must be drawn from the control circle") obj.addProperty("App::PropertyEnumeration", "DrawMode", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Radius to use to fillet the corners") obj.addProperty("App::PropertyLength", "FilletRadius", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Size of the chamfer to give to the corners") obj.addProperty("App::PropertyLength", "ChamferSize", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Create a face") obj.addProperty("App::PropertyBool", "MakeFace", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "The area of this object") obj.addProperty("App::PropertyArea", "Area", "Draft", _tip) obj.MakeFace = get_param("fillmode", True) obj.DrawMode = ['inscribed', 'circumscribed'] obj.FacesNumber = 0 obj.Radius = 1
def __init__(self, obj): super(Ellipse, self).__init__(obj, "Ellipse") _tip = "Start angle of the elliptical arc" obj.addProperty("App::PropertyAngle", "FirstAngle", "Draft",QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "End angle of the elliptical arc \n\ (for a full circle, give it same value as First Angle)" obj.addProperty("App::PropertyAngle", "LastAngle", "Draft",QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Minor radius of the ellipse" obj.addProperty("App::PropertyLength", "MinorRadius", "Draft",QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Major radius of the ellipse" obj.addProperty("App::PropertyLength", "MajorRadius", "Draft",QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Create a face" obj.addProperty("App::PropertyBool", "MakeFace", "Draft",QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Area of this object" obj.addProperty("App::PropertyArea", "Area", "Draft",QT_TRANSLATE_NOOP("App::Property", _tip)) obj.MakeFace = get_param("fillmode",True)
def Activated(self): """Execute when the command is called.""" super(AddToConstruction, self).Activated() if not hasattr(Gui, "draftToolBar"): return col = Gui.draftToolBar.getDefaultColor("constr") col = (float(col[0]), float(col[1]), float(col[2]), 0.0) # Get the construction group or create it if it doesn't exist grp = self.doc.getObject("Draft_Construction") if not grp: grp = self.doc.addObject("App::DocumentObjectGroup", "Draft_Construction") grp.Label = utils.get_param("constructiongroupname", "Construction") for obj in Gui.Selection.getSelection(): grp.addObject(obj) # Change the appearance to the construction colors vobj = obj.ViewObject if "TextColor" in vobj.PropertiesList: vobj.TextColor = col if "PointColor" in vobj.PropertiesList: vobj.PointColor = col if "LineColor" in vobj.PropertiesList: vobj.LineColor = col if "ShapeColor" in vobj.PropertiesList: vobj.ShapeColor = col if hasattr(vobj, "Transparency"): vobj.Transparency = 80
def make_text(stringslist, point=App.Vector(0, 0, 0), screen=False): """makeText(strings, point, screen) Creates a Text object containing the given strings. The current color and text height and font specified in preferences are used. Parameters ---------- stringlist : List Given list of strings, one string by line (strings can also be one single string) point : App::Vector insert point of the text screen : Bool If screen is True, the text always faces the view direction. """ if not App.ActiveDocument: App.Console.PrintError("No active document. Aborting\n") return utils.type_check([(point, App.Vector)], "makeText") if not isinstance(stringslist, list): stringslist = [stringslist] obj = App.ActiveDocument.addObject("App::FeaturePython", "Text") Text(obj) obj.Text = stringslist obj.Placement.Base = point if App.GuiUp: ViewProviderText(obj.ViewObject) if screen: obj.ViewObject.DisplayMode = "3D text" h = utils.get_param("textheight", 0.20) if screen: h = h * 10 obj.ViewObject.FontSize = h obj.ViewObject.FontName = utils.get_param("textfont", "") obj.ViewObject.LineSpacing = 1 gui_utils.format_object(obj) gui_utils.select(obj) return obj
def getPoint(self, point, info): """Get the point by clicking on the 3D view. Every time the user clicks on the 3D view this method is run. In this case, a point is appended to the list of points, and the tracker is updated. The object is finally created when three points are picked. Parameters ---------- point: Base::Vector The point selected in the 3D view. info: str Some information obtained about the point passed by the Snapper. """ # If there is not point, the command was cancelled # so the command exits. if not point: self.tracker.off() return # Avoid adding the same point twice if point not in self.points: self.points.append(point) if len(self.points) < 3: # If one or two points were picked, set up again the Snapper # to get further points, but update the `last` property # with the last selected point. # # When two points are selected then we can turn on # the arc tracker to show the preview of the final curve. if len(self.points) == 2: self.tracker.on() Gui.Snapper.getPoint(last=self.points[-1], callback=self.getPoint, movecallback=self.drawArc) Gui.Snapper.ui.setTitle(title=translate("draft", "Arc by 3 points"), icon="Draft_Arc_3Points") Gui.Snapper.ui.continueCmd.show() else: # If three points were already picked in the 3D view # proceed with creating the final object. # Draw a simple `Part::Feature` if the parameter is `True`. if utils.get_param("UsePartPrimitives", False): Draft.make_arc_3points( [self.points[0], self.points[1], self.points[2]], primitive=True) else: Draft.make_arc_3points( [self.points[0], self.points[1], self.points[2]], primitive=False) self.tracker.off() self.doc.recompute() if Gui.Snapper.ui.continueMode: self.Activated()
def __init__(self, vobj): super(ViewProviderWire, self).__init__(vobj) _tip = "Displays a Dimension symbol at the end of the wire" vobj.addProperty("App::PropertyBool", "EndArrow", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Arrow size" vobj.addProperty("App::PropertyLength", "ArrowSize", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Arrow type" vobj.addProperty("App::PropertyEnumeration", "ArrowType", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) vobj.ArrowSize = utils.get_param("arrowsize", 0.1) vobj.ArrowType = utils.ARROW_TYPES vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol", 0)]
def __init__(self, obj): super(Wire, self).__init__(obj, "Wire") _tip = "The vertices of the wire" obj.addProperty("App::PropertyVectorList", "Points", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "If the wire is closed or not" obj.addProperty("App::PropertyBool", "Closed", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "The base object is the wire, it's formed from 2 objects" obj.addProperty("App::PropertyLink", "Base", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "The tool object is the wire, it's formed from 2 objects" obj.addProperty("App::PropertyLink", "Tool", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "The start point of this line" obj.addProperty("App::PropertyVectorDistance", "Start", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "The end point of this line" obj.addProperty("App::PropertyVectorDistance", "End", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "The length of this line" obj.addProperty("App::PropertyLength", "Length", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Radius to use to fillet the corners" obj.addProperty("App::PropertyLength", "FilletRadius", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Size of the chamfer to give to the corners" obj.addProperty("App::PropertyLength", "ChamferSize", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "Create a face if this object is closed" obj.addProperty("App::PropertyBool", "MakeFace", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "The number of subdivisions of each edge" obj.addProperty("App::PropertyInteger", "Subdivisions", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) _tip = "The area of this object" obj.addProperty("App::PropertyArea", "Area", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) obj.MakeFace = get_param("fillmode", True) obj.Closed = False
def _set_properties(self, vobj): """Set the properties of objects if they don't exist.""" if not hasattr(vobj, "Pattern"): _tip = "Defines a hatch pattern." vobj.addProperty("App::PropertyEnumeration", "Pattern", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) vobj.Pattern = ["None"] + list(utils.svg_patterns().keys()) if not hasattr(vobj, "PatternSize"): _tip = "Defines the size of the hatch pattern." vobj.addProperty("App::PropertyFloat", "PatternSize", "Draft", QT_TRANSLATE_NOOP("App::Property", _tip)) vobj.PatternSize = utils.get_param("HatchPatternSize", 1)
def __init__(self, obj): super(Circle, self).__init__(obj, "Circle") _tip = QT_TRANSLATE_NOOP("App::Property", "Start angle of the arc") obj.addProperty("App::PropertyAngle", "FirstAngle", "Draft", _tip) _tip = QT_TRANSLATE_NOOP( "App::Property", "End angle of the arc (for a full circle, \ give it same value as First Angle)") obj.addProperty("App::PropertyAngle", "LastAngle", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Radius of the circle") obj.addProperty("App::PropertyLength", "Radius", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Create a face") obj.addProperty("App::PropertyBool", "MakeFace", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "The area of this object") obj.addProperty("App::PropertyArea", "Area", "Draft", _tip) obj.MakeFace = utils.get_param("fillmode", True)
def __init__(self, obj): super(BSpline, self).__init__(obj, "BSpline") _tip = QT_TRANSLATE_NOOP("App::Property", "The points of the B-spline") obj.addProperty("App::PropertyVectorList", "Points", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "If the B-spline is closed or not") obj.addProperty("App::PropertyBool", "Closed", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "Create a face if this spline is closed") obj.addProperty("App::PropertyBool", "MakeFace", "Draft", _tip) _tip = QT_TRANSLATE_NOOP("App::Property", "The area of this object") obj.addProperty("App::PropertyArea", "Area", "Draft", _tip) obj.MakeFace = get_param("fillmode", True) obj.Closed = False obj.Points = [] self.assureProperties(obj)
def updateData(self, obj, prop): if hasattr(self, "arc"): from pivy import coin import Part, DraftGeomUtils import DraftGui arcsegs = 24 # calculate the arc data if DraftVecUtils.isNull(obj.Normal): norm = App.Vector(0, 0, 1) else: norm = obj.Normal radius = (obj.Dimline.sub(obj.Center)).Length self.circle = Part.makeCircle(radius, obj.Center, norm, obj.FirstAngle.Value, obj.LastAngle.Value) self.p2 = self.circle.Vertexes[0].Point self.p3 = self.circle.Vertexes[-1].Point mp = DraftGeomUtils.findMidpoint(self.circle.Edges[0]) ray = mp.sub(obj.Center) # set text value if obj.LastAngle.Value > obj.FirstAngle.Value: a = obj.LastAngle.Value - obj.FirstAngle.Value else: a = (360 - obj.FirstAngle.Value) + obj.LastAngle.Value su = True if hasattr(obj.ViewObject, "ShowUnit"): su = obj.ViewObject.ShowUnit if hasattr(obj.ViewObject, "Decimals"): self.string = DraftGui.displayExternal(a, obj.ViewObject.Decimals, 'Angle', su) else: self.string = DraftGui.displayExternal(a, None, 'Angle', su) if obj.ViewObject.Override: self.string = obj.ViewObject.Override.replace("$dim",\ self.string) self.text.string = self.text3d.string = utils.string_encode_coin( self.string) # check display mode try: m = obj.ViewObject.DisplayMode except: # swallow all exceptions here since it always fails on first run (Displaymode enum no set yet) m = ["2D", "3D"][utils.get_param("dimstyle", 0)] # set the arc if m == "3D": # calculate the spacing of the text spacing = (len(self.string) * obj.ViewObject.FontSize.Value) / 8.0 pts1 = [] cut = None pts2 = [] for i in range(arcsegs + 1): p = self.circle.valueAt(self.circle.FirstParameter + ( (self.circle.LastParameter - self.circle.FirstParameter) / arcsegs) * i) if (p.sub(mp)).Length <= spacing: if cut is None: cut = i else: if cut is None: pts1.append([p.x, p.y, p.z]) else: pts2.append([p.x, p.y, p.z]) self.coords.point.setValues(pts1 + pts2) i1 = len(pts1) i2 = i1 + len(pts2) self.arc.coordIndex.setValues( 0, len(pts1) + len(pts2) + 1, list(range(len(pts1))) + [-1] + list(range(i1, i2))) if (len(pts1) >= 3) and (len(pts2) >= 3): self.circle1 = Part.Arc( App.Vector(pts1[0][0], pts1[0][1], pts1[0][2]), App.Vector(pts1[1][0], pts1[1][1], pts1[1][2]), App.Vector(pts1[-1][0], pts1[-1][1], pts1[-1][2])).toShape() self.circle2 = Part.Arc( App.Vector(pts2[0][0], pts2[0][1], pts2[0][2]), App.Vector(pts2[1][0], pts2[1][1], pts2[1][2]), App.Vector(pts2[-1][0], pts2[-1][1], pts2[-1][2])).toShape() else: pts = [] for i in range(arcsegs + 1): p = self.circle.valueAt(self.circle.FirstParameter + ( (self.circle.LastParameter - self.circle.FirstParameter) / arcsegs) * i) pts.append([p.x, p.y, p.z]) self.coords.point.setValues(pts) self.arc.coordIndex.setValues(0, arcsegs + 1, list(range(arcsegs + 1))) # set the arrow coords and rotation self.trans1.translation.setValue((self.p2.x, self.p2.y, self.p2.z)) self.coord1.point.setValue((self.p2.x, self.p2.y, self.p2.z)) self.trans2.translation.setValue((self.p3.x, self.p3.y, self.p3.z)) self.coord2.point.setValue((self.p3.x, self.p3.y, self.p3.z)) # calculate small chords to make arrows look better arrowlength = 4 * obj.ViewObject.ArrowSize.Value u1 = (self.circle.valueAt(self.circle.FirstParameter + arrowlength) ).sub(self.circle.valueAt( self.circle.FirstParameter)).normalize() u2 = (self.circle.valueAt(self.circle.LastParameter)).sub( self.circle.valueAt(self.circle.LastParameter - arrowlength)).normalize() if hasattr(obj.ViewObject, "FlipArrows"): if obj.ViewObject.FlipArrows: u1 = u1.negative() u2 = u2.negative() w2 = self.circle.Curve.Axis w1 = w2.negative() v1 = w1.cross(u1) v2 = w2.cross(u2) q1 = App.Placement(DraftVecUtils.getPlaneRotation(u1, v1, w1)).Rotation.Q q2 = App.Placement(DraftVecUtils.getPlaneRotation(u2, v2, w2)).Rotation.Q self.trans1.rotation.setValue((q1[0], q1[1], q1[2], q1[3])) self.trans2.rotation.setValue((q2[0], q2[1], q2[2], q2[3])) # setting text pos & rot self.tbase = mp if hasattr(obj.ViewObject, "TextPosition"): if not DraftVecUtils.isNull(obj.ViewObject.TextPosition): self.tbase = obj.ViewObject.TextPosition u3 = ray.cross(norm).normalize() v3 = norm.cross(u3) r = App.Placement(DraftVecUtils.getPlaneRotation(u3, v3, norm)).Rotation offset = r.multVec(App.Vector(0, 1, 0)) if hasattr(obj.ViewObject, "TextSpacing"): offset = DraftVecUtils.scaleTo( offset, obj.ViewObject.TextSpacing.Value) else: offset = DraftVecUtils.scaleTo(offset, 0.05) if m == "3D": offset = offset.negative() self.tbase = self.tbase.add(offset) q = r.Q self.textpos.translation.setValue( [self.tbase.x, self.tbase.y, self.tbase.z]) self.textpos.rotation = coin.SbRotation(q[0], q[1], q[2], q[3]) # set the angle property if round(obj.Angle, utils.precision()) != round( a, utils.precision()): obj.Angle = a
def updateData(self, obj, prop): """called when the base object is changed""" import DraftGui if prop in ["Start", "End", "Dimline", "Direction"]: if obj.Start == obj.End: return if not hasattr(self, "node"): return import Part, DraftGeomUtils from pivy import coin # calculate the 4 points self.p1 = obj.Start self.p4 = obj.End base = None if hasattr(obj, "Direction"): if not DraftVecUtils.isNull(obj.Direction): v2 = self.p1.sub(obj.Dimline) v3 = self.p4.sub(obj.Dimline) v2 = DraftVecUtils.project(v2, obj.Direction) v3 = DraftVecUtils.project(v3, obj.Direction) self.p2 = obj.Dimline.add(v2) self.p3 = obj.Dimline.add(v3) if DraftVecUtils.equals(self.p2, self.p3): base = None proj = None else: base = Part.LineSegment(self.p2, self.p3).toShape() proj = DraftGeomUtils.findDistance(self.p1, base) if proj: proj = proj.negative() if not base: if DraftVecUtils.equals(self.p1, self.p4): base = None proj = None else: base = Part.LineSegment(self.p1, self.p4).toShape() proj = DraftGeomUtils.findDistance(obj.Dimline, base) if proj: self.p2 = self.p1.add(proj.negative()) self.p3 = self.p4.add(proj.negative()) else: self.p2 = self.p1 self.p3 = self.p4 if proj: if hasattr(obj.ViewObject, "ExtLines") and hasattr( obj.ViewObject, "ScaleMultiplier"): dmax = obj.ViewObject.ExtLines.Value * obj.ViewObject.ScaleMultiplier if dmax and (proj.Length > dmax): if (dmax > 0): self.p1 = self.p2.add( DraftVecUtils.scaleTo(proj, dmax)) self.p4 = self.p3.add( DraftVecUtils.scaleTo(proj, dmax)) else: rest = proj.Length + dmax self.p1 = self.p2.add( DraftVecUtils.scaleTo(proj, rest)) self.p4 = self.p3.add( DraftVecUtils.scaleTo(proj, rest)) else: proj = (self.p3.sub(self.p2)).cross(App.Vector(0, 0, 1)) # calculate the arrows positions self.trans1.translation.setValue((self.p2.x, self.p2.y, self.p2.z)) self.coord1.point.setValue((self.p2.x, self.p2.y, self.p2.z)) self.trans2.translation.setValue((self.p3.x, self.p3.y, self.p3.z)) self.coord2.point.setValue((self.p3.x, self.p3.y, self.p3.z)) # calculate dimension and extension lines overshoots positions self.transDimOvershoot1.translation.setValue( (self.p2.x, self.p2.y, self.p2.z)) self.transDimOvershoot2.translation.setValue( (self.p3.x, self.p3.y, self.p3.z)) self.transExtOvershoot1.translation.setValue( (self.p2.x, self.p2.y, self.p2.z)) self.transExtOvershoot2.translation.setValue( (self.p3.x, self.p3.y, self.p3.z)) # calculate the text position and orientation if hasattr(obj, "Normal"): if DraftVecUtils.isNull(obj.Normal): if proj: norm = (self.p3.sub(self.p2).cross(proj)).negative() else: norm = App.Vector(0, 0, 1) else: norm = App.Vector(obj.Normal) else: if proj: norm = (self.p3.sub(self.p2).cross(proj)).negative() else: norm = App.Vector(0, 0, 1) if not DraftVecUtils.isNull(norm): norm.normalize() u = self.p3.sub(self.p2) u.normalize() v1 = norm.cross(u) rot1 = App.Placement(DraftVecUtils.getPlaneRotation( u, v1, norm)).Rotation.Q self.transDimOvershoot1.rotation.setValue( (rot1[0], rot1[1], rot1[2], rot1[3])) self.transDimOvershoot2.rotation.setValue( (rot1[0], rot1[1], rot1[2], rot1[3])) if hasattr(obj.ViewObject, "FlipArrows"): if obj.ViewObject.FlipArrows: u = u.negative() v2 = norm.cross(u) rot2 = App.Placement(DraftVecUtils.getPlaneRotation( u, v2, norm)).Rotation.Q self.trans1.rotation.setValue((rot2[0], rot2[1], rot2[2], rot2[3])) self.trans2.rotation.setValue((rot2[0], rot2[1], rot2[2], rot2[3])) if self.p1 != self.p2: u3 = self.p1.sub(self.p2) u3.normalize() v3 = norm.cross(u3) rot3 = App.Placement( DraftVecUtils.getPlaneRotation(u3, v3, norm)).Rotation.Q self.transExtOvershoot1.rotation.setValue( (rot3[0], rot3[1], rot3[2], rot3[3])) self.transExtOvershoot2.rotation.setValue( (rot3[0], rot3[1], rot3[2], rot3[3])) if hasattr(obj.ViewObject, "TextSpacing") and hasattr( obj.ViewObject, "ScaleMultiplier"): ts = obj.ViewObject.TextSpacing.Value * obj.ViewObject.ScaleMultiplier offset = DraftVecUtils.scaleTo(v1, ts) else: offset = DraftVecUtils.scaleTo(v1, 0.05) rott = rot1 if hasattr(obj.ViewObject, "FlipText"): if obj.ViewObject.FlipText: rott = App.Rotation(*rott).multiply(App.Rotation( norm, 180)).Q offset = offset.negative() # setting text try: m = obj.ViewObject.DisplayMode except: # swallow all exceptions here since it always fails on first run (Displaymode enum no set yet) m = ["2D", "3D"][utils.get_param("dimstyle", 0)] if m == "3D": offset = offset.negative() self.tbase = (self.p2.add( (self.p3.sub(self.p2).multiply(0.5)))).add(offset) if hasattr(obj.ViewObject, "TextPosition"): if not DraftVecUtils.isNull(obj.ViewObject.TextPosition): self.tbase = obj.ViewObject.TextPosition self.textpos.translation.setValue( [self.tbase.x, self.tbase.y, self.tbase.z]) self.textpos.rotation = coin.SbRotation(rott[0], rott[1], rott[2], rott[3]) su = True if hasattr(obj.ViewObject, "ShowUnit"): su = obj.ViewObject.ShowUnit # set text value l = self.p3.sub(self.p2).Length unit = None if hasattr(obj.ViewObject, "UnitOverride"): unit = obj.ViewObject.UnitOverride # special representation if "Building US" scheme if App.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt( "UserSchema", 0) == 5: s = App.Units.Quantity(l, App.Units.Length).UserString self.string = s.replace("' ", "'- ") self.string = s.replace("+", " ") elif hasattr(obj.ViewObject, "Decimals"): self.string = DraftGui.displayExternal(l, obj.ViewObject.Decimals, 'Length', su, unit) else: self.string = DraftGui.displayExternal(l, None, 'Length', su, unit) if hasattr(obj.ViewObject, "Override"): if obj.ViewObject.Override: self.string = obj.ViewObject.Override.replace("$dim",\ self.string) self.text.string = self.text3d.string = utils.string_encode_coin( self.string) # set the lines if m == "3D": # calculate the spacing of the text textsize = (len(self.string) * obj.ViewObject.FontSize.Value) / 4.0 spacing = ((self.p3.sub(self.p2)).Length / 2.0) - textsize self.p2a = self.p2.add( DraftVecUtils.scaleTo(self.p3.sub(self.p2), spacing)) self.p2b = self.p3.add( DraftVecUtils.scaleTo(self.p2.sub(self.p3), spacing)) self.coords.point.setValues( [[self.p1.x, self.p1.y, self.p1.z], [self.p2.x, self.p2.y, self.p2.z], [self.p2a.x, self.p2a.y, self.p2a.z], [self.p2b.x, self.p2b.y, self.p2b.z], [self.p3.x, self.p3.y, self.p3.z], [self.p4.x, self.p4.y, self.p4.z]]) #self.line.numVertices.setValues([3,3]) self.line.coordIndex.setValues(0, 7, (0, 1, 2, -1, 3, 4, 5)) else: self.coords.point.setValues([[self.p1.x, self.p1.y, self.p1.z], [self.p2.x, self.p2.y, self.p2.z], [self.p3.x, self.p3.y, self.p3.z], [self.p4.x, self.p4.y, self.p4.z]]) #self.line.numVertices.setValue(4) self.line.coordIndex.setValues(0, 4, (0, 1, 2, 3))
def getDefaultDisplayMode(self): if hasattr(self, "defaultmode"): return self.defaultmode else: return ["2D", "3D"][utils.get_param("dimstyle", 0)]
def scale(objectslist, scale=App.Vector(1, 1, 1), center=App.Vector(0, 0, 0), copy=False): """scale(objects, scale, [center], copy) Scales the objects contained in objects (that can be a list of objects or an object) of the given around given center. Parameters ---------- objectlist : list scale : Base.Vector Scale factors defined by a given vector (in X, Y, Z directions). objectlist : Base.Vector Center of the scale operation. copy : bool If copy is True, the actual objects are not scaled, but copies are created instead. Return ---------- The objects (or their copies) are returned. """ if not isinstance(objectslist, list): objectslist = [objectslist] newobjlist = [] for obj in objectslist: if copy: newobj = make_copy.make_copy(obj) else: newobj = obj if hasattr(obj, 'Shape'): scaled_shape = obj.Shape.copy() m = App.Matrix() m.move(center.negative()) m.scale(scale.x, scale.y, scale.z) m.move(center) scaled_shape = scaled_shape.transformGeometry(m) if utils.get_type(obj) == "Rectangle": p = [] for v in scaled_shape.Vertexes: p.append(v.Point) pl = obj.Placement.copy() pl.Base = p[0] diag = p[2].sub(p[0]) bb = p[1].sub(p[0]) bh = p[3].sub(p[0]) nb = DraftVecUtils.project(diag, bb) nh = DraftVecUtils.project(diag, bh) if obj.Length < 0: l = -nb.Length else: l = nb.Length if obj.Height < 0: h = -nh.Length else: h = nh.Length newobj.Length = l newobj.Height = h tr = p[0].sub(obj.Shape.Vertexes[0].Point) # unused? newobj.Placement = pl elif utils.get_type(obj) == "Wire" or utils.get_type(obj) == "BSpline": for index, point in enumerate(newobj.Points): scale_vertex(newobj, index, scale, center) elif hasattr(obj, 'Shape'): newobj.Shape = scaled_shape elif (obj.TypeId == "App::Annotation"): factor = scale.y * obj.ViewObject.FontSize newobj.ViewObject.FontSize = factor d = obj.Position.sub(center) newobj.Position = center.add( App.Vector(d.x * scale.x, d.y * scale.y, d.z * scale.z)) if copy: gui_utils.format_object(newobj, obj) newobjlist.append(newobj) if copy and utils.get_param("selectBaseObjects", False): gui_utils.select(objectslist) else: gui_utils.select(newobjlist) if len(newobjlist) == 1: return newobjlist[0] return newobjlist
def onChanged(self, vobj, prop): """Run when a view property is changed. Override this method to handle the behavior of the view provider depending on changes that occur to its properties such as line color, line width, point color, point size, draw style, shape color, transparency, and others. This method updates the texture and pattern if the properties `TextureImage`, `Pattern`, `DiffuseColor`, and `PatternSize` change. Parameters ---------- vobj : the view provider of the scripted object. This is `obj.ViewObject`. prop : str Name of the property that was modified. """ # treatment of patterns and image textures if prop in ("TextureImage", "Pattern", "DiffuseColor"): if hasattr(self.Object, "Shape"): if self.Object.Shape.Faces: path = None if hasattr(vobj, "TextureImage"): if vobj.TextureImage: path = vobj.TextureImage if not path: if hasattr(vobj, "Pattern"): if str(vobj.Pattern) in list(utils.svg_patterns().keys()): path = utils.svg_patterns()[vobj.Pattern][1] else: path = "None" if path and vobj.RootNode: if vobj.RootNode.getChildren().getLength() > 2: if vobj.RootNode.getChild(2).getChildren().getLength() > 0: if vobj.RootNode.getChild(2).getChild(0).getChildren().getLength() > 2: r = vobj.RootNode.getChild(2).getChild(0).getChild(2) i = QtCore.QFileInfo(path) if self.texture: r.removeChild(self.texture) self.texture = None if self.texcoords: r.removeChild(self.texcoords) self.texcoords = None if i.exists(): size = None if ".SVG" in path.upper(): size = utils.get_param("HatchPatternResolution", 128) if not size: size = 128 im = gui_utils.load_texture(path, size) if im: self.texture = coin.SoTexture2() self.texture.image = im r.insertChild(self.texture, 1) if size: s = 1 if hasattr(vobj, "PatternSize"): if vobj.PatternSize: s = vobj.PatternSize self.texcoords = coin.SoTextureCoordinatePlane() self.texcoords.directionS.setValue(s, 0, 0) self.texcoords.directionT.setValue(0, s, 0) r.insertChild(self.texcoords, 2) elif prop == "PatternSize": if hasattr(self, "texcoords"): if self.texcoords: s = 1 if vobj.PatternSize: s = vobj.PatternSize vS = App.Vector(self.texcoords.directionS.getValue().getValue()) vT = App.Vector(self.texcoords.directionT.getValue().getValue()) vS.Length = s vT.Length = s self.texcoords.directionS.setValue(vS.x, vS.y, vS.z) self.texcoords.directionT.setValue(vT.x, vT.y, vT.z) return
def dim_symbol(symbol=None, invert=False): """Return the specified dimension symbol. Parameters ---------- symbol: int, optional It defaults to `None`, in which it gets the value from the parameter database, `get_param("dimsymbol", 0)`. A numerical value defines different markers * 0, `SoSphere` * 1, `SoMarkerSet` with a circle * 2, `SoSeparator` with a `soCone` * 3, `SoSeparator` with a `SoFaceSet` * 4, `SoSeparator` with a `SoLineSet`, calling `dim_dash` * Otherwise, `SoSphere` invert: bool, optional It defaults to `False`. If it is `True` and `symbol=2`, the cone will be rotated -90 degrees around the Z axis, otherwise the rotation is positive, +90 degrees. Returns ------- Coin.SoNode A `Coin.SoSphere`, or `Coin.SoMarkerSet` (circle), or `Coin.SoSeparator` (cone, face, line) that will be used as a dimension symbol. """ if symbol is None: symbol = utils.get_param("dimsymbol", 0) if symbol == 0: # marker = coin.SoMarkerSet() # marker.markerIndex = 80 # Returning a sphere means that the bounding box will # be 3-dimensional; a marker will always be planar seen from any # orientation but it currently doesn't work correctly marker = coin.SoSphere() return marker elif symbol == 1: marker = coin.SoMarkerSet() # Should be the same as # marker.markerIndex = 10 marker.markerIndex = Gui.getMarkerIndex("circle", 9) return marker elif symbol == 2: marker = coin.SoSeparator() t = coin.SoTransform() t.translation.setValue((0, -2, 0)) t.center.setValue((0, 2, 0)) if invert: t.rotation.setValue(coin.SbVec3f((0, 0, 1)), -math.pi/2) else: t.rotation.setValue(coin.SbVec3f((0, 0, 1)), math.pi/2) c = coin.SoCone() c.height.setValue(4) marker.addChild(t) marker.addChild(c) return marker elif symbol == 3: marker = coin.SoSeparator() c = coin.SoCoordinate3() c.point.setValues([(-1, -2, 0), (0, 2, 0), (1, 2, 0), (0, -2, 0)]) f = coin.SoFaceSet() marker.addChild(c) marker.addChild(f) return marker elif symbol == 4: return dimDash((-1.5, -1.5, 0), (1.5, 1.5, 0)) else: _wrn(_tr("Symbol not implemented. Use a default symbol.")) return coin.SoSphere()
def format_object(target, origin=None): """Apply visual properties from the Draft toolbar or another object. This function only works if the graphical interface is available as the visual properties are attributes of the view provider (`obj.ViewObject`). Parameters ---------- target: App::DocumentObject Any type of scripted object. This object will adopt the applicable visual properties, `FontSize`, `TextColor`, `LineWidth`, `PointColor`, `LineColor`, and `ShapeColor`, defined in the Draft toolbar (`Gui.draftToolBar`) or will adopt the properties from the `origin` object. The `target` is also placed in the construction group if the construction mode in the Draft toolbar is active. origin: App::DocumentObject, optional It defaults to `None`. If it exists, it will provide the visual properties to assign to `target`, with the exception of `BoundingBox`, `Proxy`, `RootNode` and `Visibility`. """ if not target: return obrep = target.ViewObject if not obrep: return ui = None if App.GuiUp: if hasattr(Gui, "draftToolBar"): ui = Gui.draftToolBar if ui: doc = App.ActiveDocument if ui.isConstructionMode(): col = fcol = ui.getDefaultColor("constr") grp = doc.getObject("Draft_Construction") if not grp: grp = doc.addObject("App::DocumentObjectGroup", "Draft_Construction") grp.Label = utils.get_param("constructiongroupname", "Construction") grp.addObject(target) if hasattr(obrep, "Transparency"): obrep.Transparency = 80 else: col = ui.getDefaultColor("ui") fcol = ui.getDefaultColor("face") col = (float(col[0]), float(col[1]), float(col[2]), 0.0) fcol = (float(fcol[0]), float(fcol[1]), float(fcol[2]), 0.0) lw = ui.linewidth fs = ui.fontsize if not origin or not hasattr(origin, 'ViewObject'): if "FontSize" in obrep.PropertiesList: obrep.FontSize = fs if "TextSize" in obrep.PropertiesList: obrep.TextSize = fs if "TextColor" in obrep.PropertiesList: obrep.TextColor = col if "LineWidth" in obrep.PropertiesList: obrep.LineWidth = lw if "PointColor" in obrep.PropertiesList: obrep.PointColor = col if "LineColor" in obrep.PropertiesList: obrep.LineColor = col if "ShapeColor" in obrep.PropertiesList: obrep.ShapeColor = fcol else: matchrep = origin.ViewObject for p in matchrep.PropertiesList: if p not in ("DisplayMode", "BoundingBox", "Proxy", "RootNode", "Visibility"): if p in obrep.PropertiesList: if not obrep.getEditorMode(p): if hasattr(getattr(matchrep, p), "Value"): val = getattr(matchrep, p).Value else: val = getattr(matchrep, p) try: setattr(obrep, p, val) except Exception: pass if matchrep.DisplayMode in obrep.listDisplayModes(): obrep.DisplayMode = matchrep.DisplayMode if (hasattr(matchrep, "DiffuseColor") and hasattr(obrep, "DiffuseColor")): obrep.DiffuseColor = matchrep.DiffuseColor
def make_clone(obj, delta=None, forcedraft=False): """clone(obj,[delta,forcedraft]) Makes a clone of the given object(s). The clone is an exact, linked copy of the given object. If the original object changes, the final object changes too. Parameters ---------- obj : delta : Base.Vector Delta Vector to move the clone from the original position. forcedraft : bool If forcedraft is True, the resulting object is a Draft clone even if the input object is an Arch object. """ prefix = get_param("ClonePrefix", "") cl = None if prefix: prefix = prefix.strip() + " " if not isinstance(obj, list): obj = [obj] if (len(obj) == 1) and obj[0].isDerivedFrom("Part::Part2DObject"): cl = App.ActiveDocument.addObject("Part::Part2DObjectPython", "Clone2D") cl.Label = prefix + obj[0].Label + " (2D)" elif (len(obj) == 1) and (hasattr(obj[0], "CloneOf") or (get_type( obj[0]) == "BuildingPart")) and (not forcedraft): # arch objects can be clones import Arch if get_type(obj[0]) == "BuildingPart": cl = Arch.makeComponent() else: try: clonefunc = getattr(Arch, "make" + obj[0].Proxy.Type) except: pass # not a standard Arch object... Fall back to Draft mode else: cl = clonefunc() if cl: base = getCloneBase(obj[0]) cl.Label = prefix + base.Label cl.CloneOf = base if hasattr(cl, "Material") and hasattr(obj[0], "Material"): cl.Material = obj[0].Material if get_type(obj[0]) != "BuildingPart": cl.Placement = obj[0].Placement try: cl.Role = base.Role cl.Description = base.Description cl.Tag = base.Tag except: pass if App.GuiUp: format_object(cl, base) cl.ViewObject.DiffuseColor = base.ViewObject.DiffuseColor if get_type(obj[0]) in ["Window", "BuildingPart"]: ToDo.delay(Arch.recolorize, cl) select(cl) return cl # fall back to Draft clone mode if not cl: cl = App.ActiveDocument.addObject("Part::FeaturePython", "Clone") cl.addExtension("Part::AttachExtensionPython", None) cl.Label = prefix + obj[0].Label Clone(cl) if App.GuiUp: ViewProviderClone(cl.ViewObject) cl.Objects = obj if delta: cl.Placement.move(delta) elif (len(obj) == 1) and hasattr(obj[0], "Placement"): cl.Placement = obj[0].Placement format_object(cl, obj[0]) if hasattr(cl, "LongName") and hasattr(obj[0], "LongName"): cl.LongName = obj[0].LongName if App.GuiUp and (len(obj) > 1): cl.ViewObject.Proxy.resetColors(cl.ViewObject) select(cl) return cl