Ejemplo n.º 1
0
    def finish(self, closed=False, cont=False):
        """Terminate the operation and close the polyline if asked.

        Parameters
        ----------
        closed: bool, optional
            Close the line if `True`.
        """
        self.removeTemporaryObject()
        if self.oldWP:
            FreeCAD.DraftWorkingPlane = self.oldWP
            if hasattr(Gui, "Snapper"):
                Gui.Snapper.setGrid()
                Gui.Snapper.restack()
        self.oldWP = None

        if len(self.node) > 1:
            points_string = [DraftVecUtils.toString(p) for p in self.node]
            if closed == True:
                points_string.append(DraftVecUtils.toString(self.node[0]))
            cmd_list = ['from safe.punch.beam import make_beam']
            for p1, p2 in zip(points_string[:-1], points_string[1:]):
                cmd_list.append(f'make_beam({p1}, {p2})')
            self.commit(translate("civil", "Create beam"), cmd_list)
        super(Line, self).finish()

        if self.ui and self.ui.continueMode:
            self.Activated()
Ejemplo n.º 2
0
    def create_with_app_measure(self):
        """Create on measurement objects.

        This is used when the selection is an `'App::MeasureDistance'`,
        which is created with the basic tool `Std_MeasureDistance`.
        This object is removed and in its place a `Draft Dimension`
        is created.
        """
        for o in Gui.Selection.getSelection():
            p1 = o.P1
            p2 = o.P2
            _root = o.ViewObject.RootNode
            _ch = _root.getChildren()[1].getChildren()[0].getChildren()[0]
            pt = _ch.getChildren()[3]
            p3 = App.Vector(pt.point.getValues()[2].getValue())

            Gui.addModule("Draft")
            _cmd = 'Draft.make_linear_dimension'
            _cmd += '('
            _cmd += DraftVecUtils.toString(p1) + ', '
            _cmd += DraftVecUtils.toString(p2) + ', '
            _cmd += 'dim_line=' + DraftVecUtils.toString(p3)
            _cmd += ')'
            _rem = 'FreeCAD.ActiveDocument.removeObject("' + o.Name + '")'
            _cmd_list = [
                '_dim_ = ' + _cmd, _rem, 'Draft.autogroup(_dim_)',
                'FreeCAD.ActiveDocument.recompute()'
            ]
            self.commit(translate("draft", "Create Dimension"), _cmd_list)
Ejemplo n.º 3
0
    def rotate_object(self, is_copy):
        """Move the object."""
        plane = App.DraftWorkingPlane

        _doc = 'FreeCAD.ActiveDocument.'
        _selected = self.selected_objects

        objects = '['
        objects += ','.join([_doc + obj.Name for obj in _selected])
        objects += ']'

        _cmd = 'Draft.rotate'
        _cmd += '('
        _cmd += objects + ', '
        _cmd += str(math.degrees(self.angle)) + ', '
        _cmd += DraftVecUtils.toString(self.center) + ', '
        _cmd += 'axis=' + DraftVecUtils.toString(plane.axis) + ', '
        _cmd += 'copy=' + str(is_copy)
        _cmd += ')'
        _cmd_list = [_cmd,
                     'FreeCAD.ActiveDocument.recompute()']

        _mode = "Copy" if is_copy else "Rotate"
        Gui.addModule("Draft")
        self.commit(translate("draft", _mode),
                    _cmd_list)
Ejemplo n.º 4
0
    def build_copy_subelements_command(self):
        """Build the string to commit to copy the subelements."""
        import Part
        plane = App.DraftWorkingPlane

        command = []
        arguments = []
        E = len("Edge")
        for obj in self.selected_subelements:
            for index, subelement in enumerate(obj.SubObjects):
                if not isinstance(subelement, Part.Edge):
                    continue
                _edge_index = int(obj.SubElementNames[index][E:]) - 1
                _cmd = '['
                _cmd += 'FreeCAD.ActiveDocument.'
                _cmd += obj.ObjectName + ', '
                _cmd += str(_edge_index) + ', '
                _cmd += str(math.degrees(self.angle)) + ', '
                _cmd += DraftVecUtils.toString(self.center) + ', '
                _cmd += DraftVecUtils.toString(plane.axis)
                _cmd += ']'
                arguments.append(_cmd)

        all_args = ', '.join(arguments)
        command.append('Draft.copyRotatedEdges([' + all_args + '])')
        command.append('FreeCAD.ActiveDocument.recompute()')
        return command
Ejemplo n.º 5
0
    def build_scale_subelements_command(self):
        """Build the strings to commit to scale the subelements."""
        import Part

        command = []
        V = len("Vertex")
        E = len("Edge")
        for obj in self.selected_subelements:
            for index, subelement in enumerate(obj.SubObjects):
                if isinstance(subelement, Part.Vertex):
                    _vertex_index = int(obj.SubElementNames[index][V:]) - 1
                    _cmd = 'Draft.scaleVertex'
                    _cmd += '('
                    _cmd += 'FreeCAD.ActiveDocument.'
                    _cmd += obj.ObjectName + ', '
                    _cmd += str(_vertex_index) + ', '
                    _cmd += DraftVecUtils.toString(self.delta) + ', '
                    _cmd += DraftVecUtils.toString(self.center)
                    _cmd += ')'
                    command.append(_cmd)
                elif isinstance(subelement, Part.Edge):
                    _edge_index = int(obj.SubElementNames[index][E:]) - 1
                    _cmd = 'Draft.scaleEdge'
                    _cmd += '('
                    _cmd += 'FreeCAD.ActiveDocument.'
                    _cmd += obj.ObjectName + ', '
                    _cmd += str(_edge_index) + ', '
                    _cmd += DraftVecUtils.toString(self.delta) + ', '
                    _cmd += DraftVecUtils.toString(self.center)
                    _cmd += ')'
                    command.append(_cmd)
        command.append('FreeCAD.ActiveDocument.recompute()')
        return command
Ejemplo n.º 6
0
    def create_angle_dimension(self):
        """Create an angular dimension from a center and two angles."""
        normal_str = "None"
        if len(self.edges) == 2:
            v1 = DraftGeomUtils.vec(self.edges[0])
            v2 = DraftGeomUtils.vec(self.edges[1])
            norm = v1.cross(v2)
            norm.normalize()
            normal_str = DraftVecUtils.toString(norm)

        ang1 = math.degrees(self.angledata[1])
        ang2 = math.degrees(self.angledata[0])

        if ang1 > 360:
            ang1 = ang1 - 360
        if ang2 > 360:
            ang2 = ang2 - 360

        _cmd = 'Draft.make_angular_dimension'
        _cmd += '('
        _cmd += 'center=' + DraftVecUtils.toString(self.center) + ', '
        _cmd += 'angles='
        _cmd += '['
        _cmd += str(ang1) + ', '
        _cmd += str(ang2)
        _cmd += '], '
        _cmd += 'dim_line=' + DraftVecUtils.toString(self.node[-1]) + ', '
        _cmd += 'normal=' + normal_str
        _cmd += ')'
        _cmd_list = [
            '_dim_ = ' + _cmd, 'Draft.autogroup(_dim_)',
            'FreeCAD.ActiveDocument.recompute()'
        ]
        self.commit(translate("draft", "Create Dimension"), _cmd_list)
Ejemplo n.º 7
0
    def create_linear_dimension_obj(self, direction=None):
        """Create a linear dimension linked to an edge.

        The `link` attribute has indices of vertices as they appear
        in the list `Shape.Vertexes`, so they start as zero 0.

        The `LinearDimension` class, created by `make_linear_dimension_obj`,
        considers the vertices of a `Shape` which are numbered to start
        with 1, that is, `Vertex1`.
        Therefore the value in `link` has to be incremented by 1.
        """
        _cmd = 'Draft.make_linear_dimension_obj'
        _cmd += '('
        _cmd += 'FreeCAD.ActiveDocument.' + self.link[0].Name + ', '
        _cmd += 'i1=' + str(self.link[1] + 1) + ', '
        _cmd += 'i2=' + str(self.link[2] + 1) + ', '
        _cmd += 'dim_line=' + DraftVecUtils.toString(self.node[2])
        _cmd += ')'
        _cmd_list = ['_dim_ = ' + _cmd]

        plane = App.DraftWorkingPlane
        dir_u = DraftVecUtils.toString(plane.u)
        dir_v = DraftVecUtils.toString(plane.v)
        if direction == "X":
            _cmd_list += ['_dim_.Direction = ' + dir_u]
        elif direction == "Y":
            _cmd_list += ['_dim_.Direction = ' + dir_v]

        _cmd_list += [
            'Draft.autogroup(_dim_)', 'FreeCAD.ActiveDocument.recompute()'
        ]
        self.commit(translate("draft", "Create Dimension"), _cmd_list)
Ejemplo n.º 8
0
 def getPoint(self,point=None,obj=None):
     "this function is called by the snapper when it has a 3D point"
     if self.modeb.isChecked() and (self.bpoint == None):
         self.bpoint = point
         FreeCADGui.Snapper.getPoint(callback=self.getPoint,movecallback=self.update,extradlg=[self.taskbox(),self.precast.form,self.dents.form])
         return
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Structure"))
     FreeCADGui.addModule("Arch")
     if self.Profile is not None:
         if "Precast" in self.Profile:
             # precast concrete
             args = self.precast.getValues()
             args["PrecastType"] = self.Profile.split("_")[1]
             args["Length"] = self.Length
             args["Width"] = self.Width
             args["Height"] = self.Height
             argstring = ""
             # fix for precast placement, since their (0,0) point is the lower left corner
             point = FreeCAD.Vector(point.x-self.Length/2,point.y-self.Width/2,point.z)
             for pair in args.items():
                 argstring += pair[0].lower() + "="
                 if isinstance(pair[1],str):
                     argstring += '"' + pair[1] + '",'
                 else:
                     argstring += str(pair[1]) + ","
             FreeCADGui.addModule("ArchPrecast")
             FreeCADGui.doCommand("s = ArchPrecast.makePrecast("+argstring+")")
         else:
             # metal profile
             FreeCADGui.doCommand('p = Arch.makeProfile('+str(self.Profile)+')')
             if self.Length == self.Profile[4]:
                 # vertical
                 FreeCADGui.doCommand('s = Arch.makeStructure(p,height='+str(self.Height)+')')
             else:
                 # horizontal
                 FreeCADGui.doCommand('s = Arch.makeStructure(p,height='+str(self.Length)+')')
                 if not self.bmode:
                     FreeCADGui.doCommand('s.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)')
             FreeCADGui.doCommand('s.Profile = "'+self.Profile[2]+'"')
     else :
         FreeCADGui.doCommand('s = Arch.makeStructure(length='+str(self.Length)+',width='+str(self.Width)+',height='+str(self.Height)+')')
     if self.bmode and self.bpoint:
         FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(self.bpoint))
     else:
         FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point))
     if self.bmode and self.bpoint:
         rot = FreeCAD.Rotation(Vector(1,0,0),(point.sub(self.bpoint)).normalize())
         FreeCADGui.doCommand('s.Placement.Rotation=FreeCAD.Rotation'+str(rot.Q))
     else:
         FreeCADGui.doCommand('s.Placement.Rotation=s.Placement.Rotation.multiply(FreeCAD.DraftWorkingPlane.getRotation().Rotation)')
     FreeCADGui.addModule("Draft")
     FreeCADGui.doCommand("Draft.autogroup(s)")
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 9
0
 def createObject(self):
     """Create the actual object in the current document."""
     plane = App.DraftWorkingPlane
     p1 = self.node[0]
     p3 = self.node[-1]
     diagonal = p3.sub(p1)
     halfdiag = App.Vector(diagonal).multiply(0.5)
     center = p1.add(halfdiag)
     p2 = p1.add(DraftVecUtils.project(diagonal, plane.v))
     p4 = p1.add(DraftVecUtils.project(diagonal, plane.u))
     r1 = (p4.sub(p1).Length) / 2
     r2 = (p2.sub(p1).Length) / 2
     try:
         # The command to run is built as a series of text strings
         # to be committed through the `draftutils.todo.ToDo` class.
         rot, sup, pts, fil = self.getStrings()
         if r2 > r1:
             r1, r2 = r2, r1
             m = App.Matrix()
             m.rotateZ(math.pi / 2)
             rot1 = App.Rotation()
             rot1.Q = eval(rot)
             rot2 = App.Placement(m)
             rot2 = rot2.Rotation
             rot = str((rot1.multiply(rot2)).Q)
         if utils.getParam("UsePartPrimitives", False):
             # Insert a Part::Primitive object
             Gui.addModule("Part")
             _cmd = 'FreeCAD.ActiveDocument.'
             _cmd += 'addObject("Part::Ellipse", "Ellipse")'
             _cmd_list = [
                 'ellipse = ' + _cmd, 'ellipse.MajorRadius = ' + str(r1),
                 'ellipse.MinorRadius = ' + str(r2),
                 'pl = FreeCAD.Placement()', 'pl.Rotation.Q= ' + rot,
                 'pl.Base = ' + DraftVecUtils.toString(center),
                 'ellipse.Placement = pl', 'Draft.autogroup(ellipse)',
                 'FreeCAD.ActiveDocument.recompute()'
             ]
             self.commit(translate("draft", "Create Ellipse"), _cmd_list)
         else:
             # Insert a Draft ellipse
             Gui.addModule("Draft")
             _cmd = 'Draft.makeEllipse'
             _cmd += '('
             _cmd += str(r1) + ', ' + str(r2) + ', '
             _cmd += 'placement=pl, '
             _cmd += 'face=' + fil + ', '
             _cmd += 'support=' + sup
             _cmd += ')'
             _cmd_list = [
                 'pl = FreeCAD.Placement()', 'pl.Rotation.Q = ' + rot,
                 'pl.Base = ' + DraftVecUtils.toString(center),
                 'ellipse = ' + _cmd, 'Draft.autogroup(ellipse)',
                 'FreeCAD.ActiveDocument.recompute()'
             ]
             self.commit(translate("draft", "Create Ellipse"), _cmd_list)
     except Exception:
         _err("Draft: Error: Unable to create object.")
     self.finish(cont=True)
Ejemplo n.º 10
0
 def createObject(self):
     """Create the final object in the current document."""
     plane = App.DraftWorkingPlane
     p1 = self.node[0]
     p3 = self.node[-1]
     diagonal = p3.sub(p1)
     p2 = p1.add(DraftVecUtils.project(diagonal, plane.v))
     p4 = p1.add(DraftVecUtils.project(diagonal, plane.u))
     length = p4.sub(p1).Length
     if abs(DraftVecUtils.angle(p4.sub(p1), plane.u, plane.axis)) > 1:
         length = -length
     height = p2.sub(p1).Length
     if abs(DraftVecUtils.angle(p2.sub(p1), plane.v, plane.axis)) > 1:
         height = -height
     try:
         # The command to run is built as a series of text strings
         # to be committed through the `draftutils.todo.ToDo` class.
         rot, sup, pts, fil = self.getStrings()
         base = p1
         if length < 0:
             length = -length
             base = base.add((p1.sub(p4)).negative())
         if height < 0:
             height = -height
             base = base.add((p1.sub(p2)).negative())
         Gui.addModule("Draft")
         if utils.getParam("UsePartPrimitives", False):
             # Insert a Part::Primitive object
             _cmd = 'FreeCAD.ActiveDocument.'
             _cmd += 'addObject("Part::Plane", "Plane")'
             _cmd_list = [
                 'plane = ' + _cmd, 'plane.Length = ' + str(length),
                 'plane.Width = ' + str(height), 'pl = FreeCAD.Placement()',
                 'pl.Rotation.Q=' + rot,
                 'pl.Base = ' + DraftVecUtils.toString(base),
                 'plane.Placement = pl', 'Draft.autogroup(plane)',
                 'FreeCAD.ActiveDocument.recompute()'
             ]
             self.commit(translate("draft", "Create Plane"), _cmd_list)
         else:
             _cmd = 'Draft.makeRectangle'
             _cmd += '('
             _cmd += 'length=' + str(length) + ', '
             _cmd += 'height=' + str(height) + ', '
             _cmd += 'placement=pl, '
             _cmd += 'face=' + fil + ', '
             _cmd += 'support=' + sup
             _cmd += ')'
             _cmd_list = [
                 'pl = FreeCAD.Placement()', 'pl.Rotation.Q = ' + rot,
                 'pl.Base = ' + DraftVecUtils.toString(base),
                 'rec = ' + _cmd, 'Draft.autogroup(rec)',
                 'FreeCAD.ActiveDocument.recompute()'
             ]
             self.commit(translate("draft", "Create Rectangle"), _cmd_list)
     except Exception:
         _err("Draft: error delaying commit")
     self.finish(cont=True)
Ejemplo n.º 11
0
    def proceed(self):
        """Proceed with the command if one object was selected."""
        if self.call:
            self.view.removeEventCallback("SoEvent", self.call)

        sel = Gui.Selection.getSelectionEx()
        if len(sel) != 2:
            _err(
                _tr("Please select exactly two objects, "
                    "the base object and the path object, "
                    "before calling this command."))
        else:
            base_object = sel[0].Object
            path_object = sel[1].Object

            count = 4
            extra = App.Vector(0, 0, 0)
            subelements = list(sel[1].SubElementNames)
            align = False
            align_mode = "Original"
            tan_vector = App.Vector(1, 0, 0)
            force_vertical = False
            vertical_vector = App.Vector(0, 0, 1)
            use_link = self.use_link

            _edge_list_str = list()
            _edge_list_str = ["'" + edge + "'" for edge in subelements]
            _sub_str = ", ".join(_edge_list_str)
            subelements_list_str = "[" + _sub_str + "]"

            vertical_vector_str = DraftVecUtils.toString(vertical_vector)

            Gui.addModule("Draft")
            _cmd = "Draft.make_path_array"
            _cmd += "("
            _cmd += "App.ActiveDocument." + base_object.Name + ", "
            _cmd += "App.ActiveDocument." + path_object.Name + ", "
            _cmd += "count=" + str(count) + ", "
            _cmd += "extra=" + DraftVecUtils.toString(extra) + ", "
            _cmd += "subelements=" + subelements_list_str + ", "
            _cmd += "align=" + str(align) + ", "
            _cmd += "align_mode=" + "'" + align_mode + "', "
            _cmd += "tan_vector=" + DraftVecUtils.toString(tan_vector) + ", "
            _cmd += "force_vertical=" + str(force_vertical) + ", "
            _cmd += "vertical_vector=" + vertical_vector_str + ", "
            _cmd += "use_link=" + str(use_link)
            _cmd += ")"

            _cmd_list = [
                "_obj_ = " + _cmd, "Draft.autogroup(_obj_)",
                "App.ActiveDocument.recompute()"
            ]
            self.commit(_tr(self.name), _cmd_list)

        # Commit the transaction and execute the commands
        # through the parent class
        self.finish()
Ejemplo n.º 12
0
    def numericRadius(self, rad):
        """Validate the radius entry field in the user interface.

        This function is called by the toolbar or taskpanel interface
        when a valid radius has been entered in the input field.
        """
        # print("dvec:", self.dvec)
        # print("rad:", rad)
        if self.dvec:
            if isinstance(self.dvec, float):
                if self.mode == "Circle":
                    r1 = self.shape.Edges[0].Curve.Radius
                    r2 = self.ghost.getRadius()
                    if r2 >= r1:
                        rad = r1 + rad
                    else:
                        rad = r1 - rad
                    delta = str(rad)
                else:
                    _err("Draft.Offset error: Unhandled case")
            # to offset bspline
            elif self.mode == "BSpline":
                new_points = []
                for old_point, new_point in zip(self.sel.Points, self.npts):
                    diff_direction = new_point.sub(old_point).normalize()
                    new_points.append(old_point.add(diff_direction * rad))
                delta = DraftVecUtils.toString(new_points)
            else:
                self.dvec.normalize()
                self.dvec.multiply(rad)
                delta = DraftVecUtils.toString(self.dvec)
            copymode = False
            occmode = self.ui.occOffset.isChecked()
            utils.param.SetBool("Offset_OCC", occmode)

            if self.ui.isCopy.isChecked():
                copymode = True
            Gui.addModule("Draft")
            _cmd = 'Draft.offset'
            _cmd += '('
            _cmd += 'FreeCAD.ActiveDocument.'
            _cmd += self.sel.Name + ', '
            _cmd += delta + ', '
            _cmd += 'copy=' + str(copymode) + ', '
            _cmd += 'occ=' + str(occmode)
            _cmd += ')'
            _cmd_list = [
                'offst = ' + _cmd, 'FreeCAD.ActiveDocument.recompute()'
            ]
            self.commit(translate("draft", "Offset"), _cmd_list)
            self.finish()
        else:
            _err(
                translate(
                    "Draft", "Offset direction is not defined. "
                    "Please move the mouse on either side "
                    "of the object first to indicate a direction"))
Ejemplo n.º 13
0
 def create_linear_dimension(self):
     """Create a simple linear dimension, not linked to an edge."""
     _cmd = 'Draft.make_linear_dimension'
     _cmd += '('
     _cmd += DraftVecUtils.toString(self.node[0]) + ', '
     _cmd += DraftVecUtils.toString(self.node[1]) + ', '
     _cmd += 'dim_line=' + DraftVecUtils.toString(self.node[2])
     _cmd += ')'
     _cmd_list = [
         '_dim_ = ' + _cmd, 'Draft.autogroup(_dim_)',
         'FreeCAD.ActiveDocument.recompute()'
     ]
     self.commit(translate("draft", "Create Dimension"), _cmd_list)
Ejemplo n.º 14
0
    def create_object(self):
        """Create the new object.

        At this stage we already tested that the input is correct
        so the necessary attributes are already set.
        Then we proceed with the internal function to create the new object.
        """
        if len(self.selection) == 1:
            sel_obj = self.selection[0]
        else:
            # TODO: this should handle multiple objects.
            # For example, it could take the shapes of all objects,
            # make a compound and then use it as input for the array function.
            sel_obj = self.selection[0]

        # This creates the object immediately
        # obj = Draft.makeArray(sel_obj,
        #                       self.r_distance, self.tan_distance,
        #                       self.axis, self.center,
        #                       self.number, self.symmetry,
        #                       self.use_link)
        # if obj:
        #     obj.Fuse = self.fuse

        # Instead, we build the commands to execute through the parent
        # of this class, the GuiCommand.
        # This is needed to schedule geometry manipulation
        # that would crash Coin3D if done in the event callback.
        _cmd = "draftobjects.circulararray.make_circular_array"
        _cmd += "("
        _cmd += "App.ActiveDocument." + sel_obj.Name + ", "
        _cmd += "r_distance=" + str(self.r_distance) + ", "
        _cmd += "tan_distance=" + str(self.tan_distance) + ", "
        _cmd += "number=" + str(self.number) + ", "
        _cmd += "symmetry=" + str(self.symmetry) + ", "
        _cmd += "axis=" + DraftVecUtils.toString(self.axis) + ", "
        _cmd += "center=" + DraftVecUtils.toString(self.center) + ", "
        _cmd += "use_link=" + str(self.use_link)
        _cmd += ")"

        _cmd_list = [
            "Gui.addModule('Draft')",
            "Gui.addModule('draftobjects.circulararray')", "obj = " + _cmd,
            "obj.Fuse = " + str(self.fuse), "Draft.autogroup(obj)",
            "App.ActiveDocument.recompute()"
        ]

        # We commit the command list through the parent command
        self.source_command.commit(_tr(self.name), _cmd_list)
Ejemplo n.º 15
0
    def create_object(self, selection):
        """Create the actual object"""
        r_d_str = self.form.spinbox_r_distance.text()
        tan_d_str = self.form.spinbox_tan_distance.text()
        self.r_distance = _Quantity(r_d_str).Value
        self.tan_distance = _Quantity(tan_d_str).Value

        self.number = self.form.spinbox_number.value()
        self.symmetry = self.form.spinbox_symmetry.value()
        self.center = self.set_point()

        if len(selection) == 1:
            sel_obj = selection[0]
        else:
            # This can be changed so a compound of multiple
            # selected objects is produced
            sel_obj = selection[0]

        self.fuse = self.form.checkbox_fuse.isChecked()
        self.use_link = self.form.checkbox_link.isChecked()

        # This creates the object immediately
        # obj = Draft.makeArray(sel_obj,
        #                       self.center, self.angle, self.number)
        # if obj:
        #     obj.Fuse = self.fuse

        # Instead, we build the commands to execute through the parent
        # of this class, the GuiCommand.
        # This is needed to schedule geometry manipulation
        # that would crash Coin3D if done in the event callback.
        _cmd = "obj = Draft.makeArray("
        _cmd += "FreeCAD.ActiveDocument." + sel_obj.Name + ", "
        _cmd += "arg1=" + str(self.r_distance) + ", "
        _cmd += "arg2=" + str(self.tan_distance) + ", "
        _cmd += "arg3=" + DraftVecUtils.toString(self.axis) + ", "
        _cmd += "arg4=" + DraftVecUtils.toString(self.center) + ", "
        _cmd += "arg5=" + str(self.number) + ", "
        _cmd += "arg6=" + str(self.symmetry) + ", "
        _cmd += "use_link=" + str(self.use_link)
        _cmd += ")"

        _cmd_list = [
            "FreeCADGui.addModule('Draft')", _cmd,
            "obj.Fuse = " + str(self.fuse), "Draft.autogroup(obj)",
            "FreeCAD.ActiveDocument.recompute()"
        ]
        self.source_command.commit("Circular array", _cmd_list)
Ejemplo n.º 16
0
 def createObject(self):
     """Create the actual object in the current document."""
     txt = '['
     for line in self.text:
         if len(txt) > 1:
             txt += ', '
         if sys.version_info.major < 3:
             # Python2, string needs to be converted to unicode
             line = unicode(line)
             txt += '"' + str(line.encode("utf8")) + '"'
         else:
             # Python3, string is already unicode
             txt += '"' + line + '"'
     txt += ']'
     Gui.addModule("Draft")
     _cmd = 'Draft.makeText'
     _cmd += '('
     _cmd += txt + ', '
     _cmd += 'point=' + DraftVecUtils.toString(self.node[0])
     _cmd += ')'
     _cmd_list = [
         'text = ' + _cmd, 'Draft.autogroup(text)',
         'FreeCAD.ActiveDocument.recompute()'
     ]
     self.commit(translate("draft", "Create Text"), _cmd_list)
     self.finish(cont=True)
Ejemplo n.º 17
0
    def createObject(self):
        """Create the actual object in the current document."""
        text_list = self.text

        # If the last element is an empty string "" we remove it
        if not text_list[-1]:
            text_list.pop()

        # For Python 2 we convert the string to unicode,
        # Python 3 nothing needs to be done
        if sys.version_info.major < 3:
            u_list = [unicode(line) for line in text_list]
            t_list = ['"' + str(line.encode("utf8")) + '"' for line in u_list]
        else:
            t_list = ['"' + line + '"' for line in text_list]

        list_as_text = ", ".join(t_list)

        string = '[' + list_as_text + ']'

        Gui.addModule("Draft")
        _cmd = 'Draft.make_text'
        _cmd += '('
        _cmd += string + ', '
        _cmd += 'placement=' + DraftVecUtils.toString(self.node[0])
        _cmd += ')'
        _cmd_list = [
            '_text_ = ' + _cmd, 'Draft.autogroup(_text_)',
            'FreeCAD.ActiveDocument.recompute()'
        ]
        self.commit(translate("draft", "Create Text"), _cmd_list)
        self.finish(cont=True)
Ejemplo n.º 18
0
    def createObject(self):
        """Create the actual object in the current document."""
        # print("debug: D_T ShapeString.createObject type(self.SString):"
        #       + str(type(self.SString)))

        dquote = '"'
        String = dquote + self.SString + dquote

        # Size and tracking are numbers;
        # they are ASCII so this conversion should always work
        Size = str(self.SSSize)
        Tracking = str(self.SSTrack)
        FFile = dquote + self.FFile + dquote

        try:
            qr, sup, points, fil = self.getStrings()
            Gui.addModule("Draft")
            _cmd = 'Draft.make_shapestring'
            _cmd += '('
            _cmd += 'String=' + String + ', '
            _cmd += 'FontFile=' + FFile + ', '
            _cmd += 'Size=' + Size + ', '
            _cmd += 'Tracking=' + Tracking
            _cmd += ')'
            _cmd_list = [
                'ss = ' + _cmd, 'plm = FreeCAD.Placement()',
                'plm.Base = ' + DraftVecUtils.toString(self.ssBase),
                'plm.Rotation.Q = ' + qr, 'ss.Placement = plm',
                'ss.Support = ' + sup, 'Draft.autogroup(ss)',
                'FreeCAD.ActiveDocument.recompute()'
            ]
            self.commit(translate("draft", "Create ShapeString"), _cmd_list)
        except Exception:
            _err("Draft_ShapeString: error delaying commit")
        self.finish()
Ejemplo n.º 19
0
 def getPoint(self, point=None, obj=None):
     "this function is called by the snapper when it has a 3D point"
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(
         str(translate("Arch", "Create Panel")))
     FreeCADGui.addModule("Arch")
     if self.Profile:
         pr = Presets[self.Profile]
         FreeCADGui.doCommand('p = Arch.makeProfile(' + str(pr[2]) + ',' +
                              str(pr[3]) + ',' + str(pr[4]) + ',' +
                              str(pr[5]) + ')')
         FreeCADGui.doCommand('s = Arch.makePanel(p,thickness=' +
                              str(self.Thickness) + ')')
         #FreeCADGui.doCommand('s.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)')
     else:
         FreeCADGui.doCommand('s = Arch.makePanel(length=' +
                              str(self.Length) + ',width=' +
                              str(self.Width) + ',thickness=' +
                              str(self.Thickness) + ')')
     FreeCADGui.doCommand('s.Placement.Base = ' +
                          DraftVecUtils.toString(point))
     if self.rotated:
         FreeCADGui.doCommand(
             's.Placement.Rotation = FreeCAD.Rotation(FreeCAD.Vector(1.00,0.00,0.00),90.00)'
         )
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 20
0
 def getPoint(self, point=None, obj=None):
     "this function is called by the snapper when it has a 3D point"
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(
         str(translate("Arch", "Create Structure")))
     FreeCADGui.doCommand('import Arch')
     if self.Profile:
         pr = Presets[self.Profile]
         FreeCADGui.doCommand('p = Arch.makeProfile(' + str(pr[2]) + ',' +
                              str(pr[3]) + ',' + str(pr[4]) + ',' +
                              str(pr[5]) + ')')
         if self.Length == pr[2]:
             # vertical
             FreeCADGui.doCommand('s = Arch.makeStructure(p,height=' +
                                  str(self.Height) + ')')
         else:
             # horizontal
             FreeCADGui.doCommand('s = Arch.makeStructure(p,height=' +
                                  str(self.Length) + ')')
             FreeCADGui.doCommand(
                 's.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)'
             )
     else:
         FreeCADGui.doCommand('s = Arch.makeStructure(length=' +
                              str(self.Length) + ',width=' +
                              str(self.Width) + ',height=' +
                              str(self.Height) + ')')
     FreeCADGui.doCommand('s.Placement.Base = ' +
                          DraftVecUtils.toString(point))
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 21
0
    def createObject(self):
        """Create object in the current document."""
        dquote = '"'
        if sys.version_info.major < 3:  # Python3: no more unicode
            String = 'u' + dquote + str(
                self.task.leString.text().encode('unicode_escape')) + dquote
        else:
            String = dquote + self.task.leString.text() + dquote
        FFile = dquote + str(self.fileSpec) + dquote

        Size = str(_Quantity(self.task.sbHeight.text()).Value)
        Tracking = str(0.0)
        x = _Quantity(self.task.sbX.text()).Value
        y = _Quantity(self.task.sbY.text()).Value
        z = _Quantity(self.task.sbZ.text()).Value
        ssBase = App.Vector(x, y, z)
        # this try block is almost identical to the one in DraftTools
        try:
            qr, sup, points, fil = self.sourceCmd.getStrings()
            Gui.addModule("Draft")
            self.sourceCmd.commit(translate("draft", "Create ShapeString"), [
                'ss=Draft.makeShapeString(String=' + String + ',FontFile=' +
                FFile + ',Size=' + Size + ',Tracking=' + Tracking + ')',
                'plm=FreeCAD.Placement()', 'plm.Base=' +
                DraftVecUtils.toString(ssBase), 'plm.Rotation.Q=' + qr,
                'ss.Placement=plm', 'ss.Support=' + sup, 'Draft.autogroup(ss)'
            ])
        except Exception:
            _err("Draft_ShapeString: error delaying commit\n")
Ejemplo n.º 22
0
 def getPoint(self,point=None,obj=None):
     "this function is called by the snapper when it has a 3D point"
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Structure")))
     FreeCADGui.addModule("Arch")
     if self.Profile:
         pr = Presets[self.Profile]
         FreeCADGui.doCommand('p = Arch.makeProfile('+str(pr[2])+','+str(pr[3])+','+str(pr[4])+','+str(pr[5])+')')
         if self.Length == pr[2]:
             # vertical
             FreeCADGui.doCommand('s = Arch.makeStructure(p,height='+str(self.Height)+')')
         else:
             # horizontal
             FreeCADGui.doCommand('s = Arch.makeStructure(p,height='+str(self.Length)+')')
             FreeCADGui.doCommand('s.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)')
         FreeCADGui.doCommand('s.Profile = "'+pr[1]+'"')
     else:
         FreeCADGui.doCommand('s = Arch.makeStructure(length='+str(self.Length)+',width='+str(self.Width)+',height='+str(self.Height)+')')
     FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point))
     FreeCADGui.doCommand('s.Placement.Rotation=FreeCAD.DraftWorkingPlane.getRotation().Rotation')
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 23
0
    def scale_with_clone(self):
        """Scale with clone."""
        if self.task.relative.isChecked():
            self.delta = App.DraftWorkingPlane.getGlobalCoords(self.delta)

        Gui.addModule("Draft")

        _doc = 'FreeCAD.ActiveDocument.'
        _selected = self.selected_objects

        objects = '['
        objects += ', '.join([_doc + obj.Name for obj in _selected])
        objects += ']'

        if self.task.isCopy.isChecked():
            _cmd_name = translate("draft", "Copy")
        else:
            _cmd_name = translate("draft", "Scale")

        _cmd = 'Draft.clone'
        _cmd += '('
        _cmd += objects + ', '
        _cmd += 'forcedraft=True'
        _cmd += ')'
        _cmd_list = [
            'clone = ' + _cmd,
            'clone.Scale = ' + DraftVecUtils.toString(self.delta),
            'FreeCAD.ActiveDocument.recompute()'
        ]
        self.commit(_cmd_name, _cmd_list)
Ejemplo n.º 24
0
    def create_object(self):
        """Create the new object.

        At this stage we already tested that the input is correct
        so the necessary attributes are already set.
        Then we proceed with the internal function to create the new object.
        """
        if len(self.selection) == 1:
            sel_obj = self.selection[0]
        else:
            # TODO: this should handle multiple objects.
            # For example, it could take the shapes of all objects,
            # make a compound and then use it as input for the array function.
            sel_obj = self.selection[0]

        # This creates the object immediately
        # obj = Draft.make_ortho_array(sel_obj,
        #                              self.v_x, self.v_y, self.v_z,
        #                              self.n_x, self.n_y, self.n_z,
        #                              self.use_link)

        # Instead, we build the commands to execute through the caller
        # of this class, the GuiCommand.
        # This is needed to schedule geometry manipulation
        # that would crash Coin3D if done in the event callback.
        _cmd = "Draft.make_ortho_array"
        _cmd += "("
        _cmd += "App.ActiveDocument." + sel_obj.Name + ", "
        _cmd += "v_x=" + DraftVecUtils.toString(self.v_x) + ", "
        _cmd += "v_y=" + DraftVecUtils.toString(self.v_y) + ", "
        _cmd += "v_z=" + DraftVecUtils.toString(self.v_z) + ", "
        _cmd += "n_x=" + str(self.n_x) + ", "
        _cmd += "n_y=" + str(self.n_y) + ", "
        _cmd += "n_z=" + str(self.n_z) + ", "
        _cmd += "use_link=" + str(self.use_link)
        _cmd += ")"

        Gui.addModule('Draft')

        _cmd_list = [
            "_obj_ = " + _cmd, "_obj_.Fuse = " + str(self.fuse),
            "Draft.autogroup(_obj_)", "App.ActiveDocument.recompute()"
        ]

        # We commit the command list through the parent command
        self.source_command.commit(translate("draft", "Orthogonal array"),
                                   _cmd_list)
Ejemplo n.º 25
0
    def finish(self, closed=False, cont=False):
        """Terminate the operation and close the polyline if asked.

        Parameters
        ----------
        closed: bool, optional
            Close the line if `True`.
        """
        self.removeTemporaryObject()
        if self.oldWP:
            App.DraftWorkingPlane.setFromParameters(self.oldWP)
            if hasattr(Gui, "Snapper"):
                Gui.Snapper.setGrid()
                Gui.Snapper.restack()
        self.oldWP = None

        if len(self.node) > 1:
            Gui.addModule("Draft")
            # The command to run is built as a series of text strings
            # to be committed through the `draftutils.todo.ToDo` class.
            if (len(self.node) == 2
                    and utils.getParam("UsePartPrimitives", False)):
                # Insert a Part::Primitive object
                p1 = self.node[0]
                p2 = self.node[-1]

                _cmd = 'FreeCAD.ActiveDocument.'
                _cmd += 'addObject("Part::Line", "Line")'
                _cmd_list = [
                    'line = ' + _cmd, 'line.X1 = ' + str(p1.x),
                    'line.Y1 = ' + str(p1.y), 'line.Z1 = ' + str(p1.z),
                    'line.X2 = ' + str(p2.x), 'line.Y2 = ' + str(p2.y),
                    'line.Z2 = ' + str(p2.z), 'Draft.autogroup(line)',
                    'FreeCAD.ActiveDocument.recompute()'
                ]
                self.commit(translate("draft", "Create Line"), _cmd_list)
            else:
                # Insert a Draft line
                rot, sup, pts, fil = self.getStrings()

                _base = DraftVecUtils.toString(self.node[0])
                _cmd = 'Draft.make_wire'
                _cmd += '('
                _cmd += 'points, '
                _cmd += 'placement=pl, '
                _cmd += 'closed=' + str(closed) + ', '
                _cmd += 'face=' + fil + ', '
                _cmd += 'support=' + sup
                _cmd += ')'
                _cmd_list = [
                    'pl = FreeCAD.Placement()', 'pl.Rotation.Q = ' + rot,
                    'pl.Base = ' + _base, 'points = ' + pts, 'line = ' + _cmd,
                    'Draft.autogroup(line)',
                    'FreeCAD.ActiveDocument.recompute()'
                ]
                self.commit(translate("draft", "Create Wire"), _cmd_list)
        super(Line, self).finish()
        if self.ui and self.ui.continueMode:
            self.Activated()
Ejemplo n.º 26
0
    def scale_object(self):
        """Scale the object."""
        if self.task.relative.isChecked():
            self.delta = App.DraftWorkingPlane.getGlobalCoords(self.delta)
        goods = []
        bads = []
        for obj in self.selected_objects:
            if self.is_scalable(obj):
                goods.append(obj)
            else:
                bads.append(obj)
        if bads:
            if len(bads) == 1:
                m = translate("draft", "Unable to scale object:")
                m += " "
                m += bads[0].Label
            else:
                m = translate("draft", "Unable to scale objects:")
                m += " "
                m += ", ".join([o.Label for o in bads])
            m += " - " + translate(
                "draft",
                "This object type cannot be scaled directly. Please use the clone method."
            )
            _err(m)
        if goods:
            _doc = 'FreeCAD.ActiveDocument.'
            objects = '['
            objects += ', '.join([_doc + obj.Name for obj in goods])
            objects += ']'
            Gui.addModule("Draft")

            if self.task.isCopy.isChecked():
                _cmd_name = translate("draft", "Copy")
            else:
                _cmd_name = translate("draft", "Scale")

            _cmd = 'Draft.scale'
            _cmd += '('
            _cmd += objects + ', '
            _cmd += 'scale=' + DraftVecUtils.toString(self.delta) + ', '
            _cmd += 'center=' + DraftVecUtils.toString(self.center) + ', '
            _cmd += 'copy=' + str(self.task.isCopy.isChecked())
            _cmd += ')'
            _cmd_list = ['ss = ' + _cmd, 'FreeCAD.ActiveDocument.recompute()']
            self.commit(_cmd_name, _cmd_list)
Ejemplo n.º 27
0
 def mirror(self, p1, p2, copy=False):
     """Mirror the real shapes."""
     sel = '['
     for o in self.sel:
         if len(sel) > 1:
             sel += ', '
         sel += 'FreeCAD.ActiveDocument.' + o.Name
     sel += ']'
     Gui.addModule("Draft")
     _cmd = 'Draft.mirror'
     _cmd += '('
     _cmd += sel + ', '
     _cmd += DraftVecUtils.toString(p1) + ', '
     _cmd += DraftVecUtils.toString(p2)
     _cmd += ')'
     _cmd_list = ['m = ' + _cmd, 'FreeCAD.ActiveDocument.recompute()']
     self.commit(translate("draft", "Mirror"), _cmd_list)
Ejemplo n.º 28
0
 def getPoint(self, point=None, obj=None):
     "this function is called by the snapper when it has a 3D point"
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(
         str(translate("Arch", "Create Structure")))
     FreeCADGui.addModule("Arch")
     if self.Profile is not None:
         if "Precast" in self.Profile:
             # precast concrete
             args = self.precast.getValues()
             args["PrecastType"] = self.Profile.split("_")[1]
             args["Length"] = self.Length
             args["Width"] = self.Width
             args["Height"] = self.Height
             argstring = ""
             for pair in args.items():
                 argstring += pair[0].lower() + "="
                 if isinstance(pair[1], str):
                     argstring += '"' + pair[1] + '",'
                 else:
                     argstring += str(pair[1]) + ","
             FreeCADGui.addModule("ArchPrecast")
             FreeCADGui.doCommand("s = ArchPrecast.makePrecast(" +
                                  argstring + ")")
         else:
             # metal profile
             FreeCADGui.doCommand('p = Arch.makeProfile(' +
                                  str(self.Profile) + ')')
             if self.Length == self.Profile[4]:
                 # vertical
                 FreeCADGui.doCommand('s = Arch.makeStructure(p,height=' +
                                      str(self.Height) + ')')
             else:
                 # horizontal
                 FreeCADGui.doCommand('s = Arch.makeStructure(p,height=' +
                                      str(self.Length) + ')')
                 FreeCADGui.doCommand(
                     's.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)'
                 )
             FreeCADGui.doCommand('s.Profile = "' + self.Profile[2] + '"')
     else:
         FreeCADGui.doCommand('s = Arch.makeStructure(length=' +
                              str(self.Length) + ',width=' +
                              str(self.Width) + ',height=' +
                              str(self.Height) + ')')
     FreeCADGui.doCommand('s.Placement.Base = ' +
                          DraftVecUtils.toString(point))
     FreeCADGui.doCommand(
         's.Placement.Rotation=s.Placement.Rotation.multiply(FreeCAD.DraftWorkingPlane.getRotation().Rotation)'
     )
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 29
0
    def create_object(self, selection):
        """Create the actual object."""
        self.v_X, self.v_Y, self.v_Z = self.set_intervals()
        self.n_X, self.n_Y, self.n_Z = self.set_numbers()

        if len(selection) == 1:
            sel_obj = selection[0]
        else:
            # This can be changed so a compound of multiple
            # selected objects is produced
            sel_obj = selection[0]

        self.fuse = self.form.checkbox_fuse.isChecked()
        self.use_link = self.form.checkbox_link.isChecked()

        # This creates the object immediately
        # obj = Draft.makeArray(sel_obj,
        #                       self.v_X, self.v_Y, self.v_Z,
        #                       self.n_X, self.n_Y, self.n_Z)
        # if obj:
        #     obj.Fuse = self.fuse

        # Instead, we build the commands to execute through the parent
        # of this class, the GuiCommand.
        # This is needed to schedule geometry manipulation
        # that would crash Coin3D if done in the event callback.
        _cmd = "obj = Draft.makeArray("
        _cmd += "FreeCAD.ActiveDocument." + sel_obj.Name + ", "
        _cmd += "arg1=" + DraftVecUtils.toString(self.v_X) + ", "
        _cmd += "arg2=" + DraftVecUtils.toString(self.v_Y) + ", "
        _cmd += "arg3=" + DraftVecUtils.toString(self.v_Z) + ", "
        _cmd += "arg4=" + str(self.n_X) + ", "
        _cmd += "arg5=" + str(self.n_Y) + ", "
        _cmd += "arg6=" + str(self.n_Z) + ", "
        _cmd += "use_link=" + str(self.use_link)
        _cmd += ")"

        _cmd_list = [
            "FreeCADGui.addModule('Draft')", _cmd,
            "obj.Fuse = " + str(self.fuse), "Draft.autogroup(obj)",
            "FreeCAD.ActiveDocument.recompute()"
        ]
        self.source_command.commit("Ortho array", _cmd_list)
Ejemplo n.º 30
0
    def scale_with_clone(self):
        """Scale with clone."""
        if self.task.relative.isChecked():
            self.delta = App.DraftWorkingPlane.getGlobalCoords(self.delta)

        Gui.addModule("Draft")

        _doc = 'FreeCAD.ActiveDocument.'
        _selected = self.selected_objects

        objects = '['
        objects += ', '.join([_doc + obj.Name for obj in _selected])
        objects += ']'

        if self.task.isCopy.isChecked():
            _cmd_name = translate("draft", "Copy")
        else:
            _cmd_name = translate("draft", "Scale")

        # the correction translation of the clone placement is
        # (node[0] - clone.Placement.Base) - (node[0] - clone.Placement.Base)\
        #   .scale(delta.x,delta.y,delta.z)
        # equivalent to:
        # (node[0] - clone.Placement.Base)\
        #   .scale(1-delta.x,1-delta.y,1-delta.z)
        str_node0 = DraftVecUtils.toString(self.node[0])
        str_delta = DraftVecUtils.toString(self.delta)
        str_delta_corr = DraftVecUtils.toString(
            App.Vector(1, 1, 1) - self.delta)

        _cmd = 'Draft.clone'
        _cmd += '('
        _cmd += objects + ', '
        _cmd += 'forcedraft=True'
        _cmd += ')'
        _cmd_list = ['clone = ' + _cmd,
                     'clone.Scale = ' + str_delta,
                     'clone_corr = (' + str_node0 + ' - clone.Placement.Base)'\
                        + '.scale(*'+ str_delta_corr + ')',
                     'clone.Placement.move(clone_corr)',
                     'FreeCAD.ActiveDocument.recompute()']
        self.commit(_cmd_name, _cmd_list)
Ejemplo n.º 31
0
 def getPoint(self, point=None, obj=None):
     "this function is called by the snapper when it has a 3D point"
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(str(translate("Arch", "Create Structure")))
     FreeCADGui.addModule("Arch")
     if self.Profile is not None:
         if "Precast" in self.Profile:
             # precast concrete
             args = self.precast.getValues()
             args["PrecastType"] = self.Profile.split("_")[1]
             args["Length"] = self.Length
             args["Width"] = self.Width
             args["Height"] = self.Height
             argstring = ""
             for pair in args.items():
                 argstring += pair[0].lower() + "="
                 if isinstance(pair[1], str):
                     argstring += '"' + pair[1] + '",'
                 else:
                     argstring += str(pair[1]) + ","
             FreeCADGui.addModule("ArchPrecast")
             FreeCADGui.doCommand("s = ArchPrecast.makePrecast(" + argstring + ")")
         else:
             # metal profile
             FreeCADGui.doCommand("p = Arch.makeProfile(" + str(self.Profile) + ")")
             if self.Length == self.Profile[4]:
                 # vertical
                 FreeCADGui.doCommand("s = Arch.makeStructure(p,height=" + str(self.Height) + ")")
             else:
                 # horizontal
                 FreeCADGui.doCommand("s = Arch.makeStructure(p,height=" + str(self.Length) + ")")
                 FreeCADGui.doCommand("s.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)")
             FreeCADGui.doCommand('s.Profile = "' + self.Profile[2] + '"')
     else:
         FreeCADGui.doCommand(
             "s = Arch.makeStructure(length="
             + str(self.Length)
             + ",width="
             + str(self.Width)
             + ",height="
             + str(self.Height)
             + ")"
         )
     FreeCADGui.doCommand("s.Placement.Base = " + DraftVecUtils.toString(point))
     FreeCADGui.doCommand(
         "s.Placement.Rotation=s.Placement.Rotation.multiply(FreeCAD.DraftWorkingPlane.getRotation().Rotation)"
     )
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 32
0
    def proceed(self):
        """Proceed with the command if one object was selected."""
        if self.call:
            self.view.removeEventCallback("SoEvent", self.call)

        faces = []
        objs = []
        vec = Gui.ActiveDocument.ActiveView.getViewDirection().negative()
        sel = Gui.Selection.getSelectionEx()
        for s in sel:
            objs.append(s.Object)
            for e in s.SubElementNames:
                if "Face" in e:
                    faces.append(int(e[4:]) - 1)
        # print(objs, faces)
        commitlist = []
        Gui.addModule("Draft")
        if len(objs) == 1 and faces:
            _cmd = "Draft.makeShape2DView"
            _cmd += "("
            _cmd += "FreeCAD.ActiveDocument." + objs[0].Name + ", "
            _cmd += DraftVecUtils.toString(vec) + ", "
            _cmd += "facenumbers=" + str(faces)
            _cmd += ")"
            commitlist.append("sv = " + _cmd)
        else:
            n = 0
            for o in objs:
                _cmd = "Draft.makeShape2DView"
                _cmd += "("
                _cmd += "FreeCAD.ActiveDocument." + o.Name + ", "
                _cmd += DraftVecUtils.toString(vec)
                _cmd += ")"
                commitlist.append("sv" + str(n) + " = " + _cmd)
                n += 1
        if commitlist:
            commitlist.append("FreeCAD.ActiveDocument.recompute()")
            self.commit(translate("draft", "Create 2D view"),
                        commitlist)
        self.finish()
Ejemplo n.º 33
0
 def getPoint(self,point=None,obj=None):
     "this function is called by the snapper when it has a 3D point"
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Structure")))
     FreeCADGui.doCommand('import Arch')
     FreeCADGui.doCommand('s = Arch.makeStructure(length='+str(self.Length)+',width='+str(self.Width)+',height='+str(self.Height)+')')
     FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point))
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 34
0
 def getPoint(self,point=None,obj=None):
     "this function is called by the snapper when it has a 3D point"
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(str(translate("Timber","Create Timber Beam")))
     FreeCADGui.addModule("Timber")
     FreeCADGui.doCommand('s = Timber.makeTimberBeam(length='+str(self.Length)+',width='+str(self.Width)+',height='+str(self.Height)+')')
     #FreeCADGui.doCommand('s = Timber.makeTimberBeam2()')
     FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point))
     FreeCADGui.doCommand('s.Placement.Rotation=FreeCAD.DraftWorkingPlane.getRotation().Rotation')
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 35
0
 def getPoint(self,point=None,obj=None):
     "this function is called by the snapper when it has a 3D point"
     self.tracker.finalize()
     if point == None:
         return
     FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Panel")))
     FreeCADGui.addModule("Arch")
     if self.Profile:
         pr = Presets[self.Profile]
         FreeCADGui.doCommand('p = Arch.makeProfile('+str(pr[2])+','+str(pr[3])+','+str(pr[4])+','+str(pr[5])+')')
         FreeCADGui.doCommand('s = Arch.makePanel(p,thickness='+str(self.Thickness)+')')
         #FreeCADGui.doCommand('s.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)')
     else:
         FreeCADGui.doCommand('s = Arch.makePanel(length='+str(self.Length)+',width='+str(self.Width)+',thickness='+str(self.Thickness)+')')
     FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point))
     if self.rotated:
         FreeCADGui.doCommand('s.Placement.Rotation = FreeCAD.Rotation(FreeCAD.Vector(1.00,0.00,0.00),90.00)')
     FreeCAD.ActiveDocument.commitTransaction()
     FreeCAD.ActiveDocument.recompute()
     if self.continueCmd:
         self.Activated()
Ejemplo n.º 36
0
    def getPoint(self,point=None,obj=None):

        "this function is called by the snapper when it has a 3D point"

        if self.modeb.isChecked() and (self.bpoint == None):
            self.bpoint = point
            FreeCADGui.Snapper.getPoint(callback=self.getPoint,movecallback=self.update,extradlg=[self.taskbox(),self.precast.form,self.dents.form])
            return
        self.tracker.finalize()
        if point == None:
            return
        FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Structure"))
        FreeCADGui.addModule("Arch")
        if self.Profile is not None:
            if "Precast" in self.Profile:
                # precast concrete
                args = self.precast.getValues()
                args["PrecastType"] = self.Profile.split("_")[1]
                args["Length"] = self.Length
                args["Width"] = self.Width
                args["Height"] = self.Height
                argstring = ""
                # fix for precast placement, since their (0,0) point is the lower left corner
                point = FreeCAD.Vector(point.x-self.Length/2,point.y-self.Width/2,point.z)
                for pair in args.items():
                    argstring += pair[0].lower() + "="
                    if isinstance(pair[1],str):
                        argstring += '"' + pair[1] + '",'
                    else:
                        argstring += str(pair[1]) + ","
                FreeCADGui.addModule("ArchPrecast")
                FreeCADGui.doCommand("s = ArchPrecast.makePrecast("+argstring+")")
            else:
                # metal profile
                FreeCADGui.doCommand('p = Arch.makeProfile('+str(self.Profile)+')')
                if self.Length == self.Profile[4]:
                    # vertical
                    FreeCADGui.doCommand('s = Arch.makeStructure(p,height='+str(self.Height)+')')
                else:
                    # horizontal
                    FreeCADGui.doCommand('s = Arch.makeStructure(p,height='+str(self.Length)+')')
                    if not self.bmode:
                        FreeCADGui.doCommand('s.Placement.Rotation = FreeCAD.Rotation(-0.5,0.5,-0.5,0.5)')
                FreeCADGui.doCommand('s.Profile = "'+self.Profile[2]+'"')
        else :
            FreeCADGui.doCommand('s = Arch.makeStructure(length='+str(self.Length)+',width='+str(self.Width)+',height='+str(self.Height)+')')
        if self.bmode and self.bpoint:
            FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(self.bpoint))
        else:
            FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point))
        if self.bmode and self.bpoint:
            rot = FreeCAD.Rotation(Vector(1,0,0),(point.sub(self.bpoint)).normalize())
            FreeCADGui.doCommand('s.Placement.Rotation=FreeCAD.Rotation'+str(rot.Q))
        else:
            FreeCADGui.doCommand('s.Placement.Rotation=s.Placement.Rotation.multiply(FreeCAD.DraftWorkingPlane.getRotation().Rotation)')
        FreeCADGui.addModule("Draft")
        FreeCADGui.doCommand("Draft.autogroup(s)")
        FreeCAD.ActiveDocument.commitTransaction()
        FreeCAD.ActiveDocument.recompute()
        if self.continueCmd:
            self.Activated()