Пример #1
0
# -*- coding: utf-8 -*-

__title__ = "Split curve"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Splits the selected edge."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/splitcurve.svg'
debug = _utils.debug
#debug = _utils.doNothing


class split:
    """Splits the selected edge."""
    def __init__(self, obj, e):
        obj.addProperty("App::PropertyLinkSub", "Edge", "Split",
                        "Edge to split").Edge = e
        obj.addProperty(
            "App::PropertyEnumeration", "Method", "Split",
            "Splitting method").Method = ['Parameter', 'Distance', 'Percent']
        obj.addProperty("App::PropertyEnumeration", "Output", "Split",
                        "Output type").Output = ['Wire', 'Start', 'End']
        obj.addProperty("App::PropertyFloat", "Value", "Split",
                        "Split at given parameter")
        obj.addProperty("App::PropertyFloat", "Param", "Split", "Parameter")
        obj.setEditorMode("Param", 2)
Пример #2
0
__title__ = "Parametric Gordon surface"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Creates a surface that skins a network of curves."

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/gordon.svg'
#debug = _utils.debug
#debug = _utils.doNothing

def debug(o):
    if isinstance(o,Part.BSplineCurve):
        FreeCAD.Console.PrintWarning("\nBSplineCurve\n")
        FreeCAD.Console.PrintWarning("Degree: %d\n"%(o.Degree))
        FreeCAD.Console.PrintWarning("NbPoles: %d\n"%(o.NbPoles))
        FreeCAD.Console.PrintWarning("Knots: %d (%0.2f - %0.2f)\n"%(o.NbKnots, o.FirstParameter, o.LastParameter))
        FreeCAD.Console.PrintWarning("Mults: %s\n"%(o.getMultiplicities()))
        FreeCAD.Console.PrintWarning("Periodic: %s\n"%(o.isPeriodic()))
    elif isinstance(o,Part.BSplineSurface):
        FreeCAD.Console.PrintWarning("\nBSplineSurface\n************\n")
        try:
            u = o.uIso(o.UKnotSequence[0])
Пример #3
0
# -*- coding: utf-8 -*-

__title__ = "Curve extend"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Extend an edge by a given distance."

import FreeCAD
import FreeCADGui
import Part
import _utils
import curveExtend

TOOL_ICON = _utils.iconsPath() + '/extendcurve.svg'
debug = _utils.debug
debug = _utils.doNothing


class extend:
    """Extends the selected edge"""
    def __init__(self, obj):
        obj.addProperty("App::PropertyLinkSub", "Edge", "Base",
                        "Input edge to extend")
        obj.addProperty("App::PropertyEnumeration", "Output", "Base",
                        "Output shape").Output = ["SingleEdge", "Wire"]

        obj.addProperty("App::PropertyFloat", "LengthStart", "Beginning",
                        "Start Extension Length").LengthStart = 10.0
        obj.addProperty(
            "App::PropertyEnumeration", "TypeStart", "Beginning",
            "Start Extension type").TypeStart = ["Straight", "G2 curve"]
Пример #4
0
# -*- coding: utf-8 -*-

__title__ = "Interpolate"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Interpolate a set of points."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/interpolate.svg'
debug = _utils.debug
#debug = _utils.doNothing


# ********************************************************
# **** Part.BSplineCurve.interpolate() documentation *****
# ********************************************************

#Replaces this B-Spline curve by interpolating a set of points.
#The function accepts keywords as arguments.

#interpolate(Points = list_of_points) 

#Optional arguments :

#PeriodicFlag = bool (False) : Sets the curve closed or opened.
#Tolerance = float (1e-6) : interpolating tolerance
Пример #5
0
# -*- coding: utf-8 -*-

__title__ = "Parametric line"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Parametric line between two vertexes."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/line.svg'
debug = _utils.debug
debug = _utils.doNothing


class line:
    """Creates a parametric line between two vertexes"""
    def __init__(self, obj):
        """Add the properties"""
        obj.addProperty("App::PropertyLinkSub", "Vertex1", "Line",
                        "First Vertex")
        obj.addProperty("App::PropertyLinkSub", "Vertex2", "Line",
                        "Second Vertex")
        obj.Proxy = self

    def execute(self, obj):
        v1 = _utils.getShape(obj, "Vertex1", "Vertex")
        v2 = _utils.getShape(obj, "Vertex2", "Vertex")
        if v1 and v2:
Пример #6
0
# -*- coding: utf-8 -*-

__title__ = "BSpline to script"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Creates a python script to build the selected BSpline curves."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/toconsole.svg'
debug = _utils.debug
#debug = _utils.doNothing


def curve_to_script(i,c):
    com = ["import FreeCAD",
           "from FreeCAD import Vector",
           "import Part",""]
    if isinstance(c,Part.BSplineCurve):
        com.append("poles%d = %r"%(i,c.getPoles()))
        com.append("weights%d = %r"%(i,c.getWeights()))
        com.append("knots%d = %r"%(i,c.getKnots()))
        com.append("mults%d = %r"%(i,c.getMultiplicities()))
        com.append("periodic%d = %r"%(i,c.isPeriodic()))
        com.append("degree%d = %s"%(i,c.Degree))
        com.append("rational%d = %r"%(i,c.isRational()))
        com.append("bs%d = Part.BSplineCurve()"%i)
        #com.append("bs%d.buildFromPolesMultsKnots(poles%d, mults%d, knots%d, periodic%d, degree%d, )"%(i,i,i,i,i,i))
Пример #7
0
__title__ = "Reflect Lines"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = """Creates the reflect lines on a shape, according to a view direction"""

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/reflectLines.svg'

class ReflectLinesFP:
    """Creates the reflect lines on a shape, according to a view direction"""
    def __init__(self, obj, src):
        """Add the properties"""
        obj.addProperty("App::PropertyLink",   "Source",  "ReflectLines", "Source object")
        obj.addProperty("App::PropertyLinkSubList","IndivFaces","ReflectLines", "Individual faces")
        obj.addProperty("App::PropertyVector", "ViewPos", "ReflectLines", "View position")
        obj.addProperty("App::PropertyVector", "ViewDir", "ReflectLines", "View direction")
        obj.addProperty("App::PropertyVector", "UpDir",   "ReflectLines", "Up direction")
        obj.ViewPos = FreeCAD.Vector(0,0,0)
        obj.ViewDir = FreeCAD.Vector(0,0,1)
        obj.UpDir   = FreeCAD.Vector(0,1,0)
        if isinstance(src,(list,tuple)):
            obj.IndivFaces = src
Пример #8
0
# -*- coding: utf-8 -*-

__title__ = "Extract subshape"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Extract selected subshapes from objects."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/extract.svg'

class extract:
    """Extract the selected shapes from objects"""
    def Activated(self):
        s = FreeCADGui.Selection.getSelectionEx()
        for o in s:
            objName = o.ObjectName
            for so,name in zip(o.SubObjects,o.SubElementNames):
                fullname = objName+"_"+name
                newobj = FreeCAD.ActiveDocument.addObject("Part::Feature",fullname)
                if hasattr(o.Object, "getGlobalPlacement"):
                    gpl = o.Object.getGlobalPlacement()
                    so.transformShape(gpl.toMatrix())
                newobj.Shape = so
            o.Object.ViewObject.Visibility = False
        FreeCAD.ActiveDocument.recompute()

    def GetResources(self):
Пример #9
0
# -*- coding: utf-8 -*-

__title__ = 'Pipeshell'
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = 'Creates a PipeShell sweep object'

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/pipeshell.svg'
DEBUG = False


def debug(string):
    if DEBUG:
        FreeCAD.Console.PrintMessage(string)
        FreeCAD.Console.PrintMessage("\n")


class pipeShell:
    "PipeShell featurePython object"

    def __init__(self, obj):
        ''' Add the properties '''
        obj.addProperty("App::PropertyLinkSubList", "Spine", "Main",
                        "Sweep path")
        obj.addProperty("App::PropertyLinkList", "Profiles", "Main",
                        "Profiles that are swept along spine")
Пример #10
0
__title__ = "Blend curve"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Blend curve between two edges."

import FreeCAD
import FreeCADGui
import Part
import _utils

from pivy import coin
import nurbs_tools
import CoinNodes

TOOL_ICON = _utils.iconsPath() + '/blend1.svg'
debug = _utils.debug
#debug = _utils.doNothing

class BlendCurveFP:
    def __init__(self, obj , edges):
        debug("BlendCurve class Init")
        
        obj.addProperty("App::PropertyLinkSub",         "Edge1",      "Edge1", "Edge 1").Edge1 = edges[0]
        obj.addProperty("App::PropertyLinkSub",         "Edge2",      "Edge2", "Edge 2").Edge2 = edges[1]
        obj.addProperty("App::PropertyInteger",         "DegreeMax",  "BlendCurve", "Max degree of the Blend curve").DegreeMax = 9
        obj.addProperty("App::PropertyFloatConstraint", "Parameter1", "Edge1", "Location of blend curve")
        obj.addProperty("App::PropertyFloatConstraint", "Scale1",     "Edge1", "Scale of blend curve")
        obj.addProperty("App::PropertyEnumeration",     "Continuity1","Edge1", "Continuity").Continuity1=["C0","G1","G2","G3","G4"]
        obj.addProperty("App::PropertyFloatConstraint", "Parameter2", "Edge2", "Location of blend curve")
        obj.addProperty("App::PropertyFloatConstraint", "Scale2",     "Edge2", "Scale of blend curve")
Пример #11
0
# -*- coding: utf-8 -*-

__title__ = "Parametric solid"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Make a parametric solid from selected faces."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/solid.svg'

class solid:
    """Make a parametric solid from selected faces"""
    def __init__(self, obj):
        obj.addProperty("App::PropertyLinkSubList", "Faces", "Solid", "List of faces to build the solid")
        obj.Proxy = self

    def execute(self, obj):
        faces = _utils.getShape(obj,"Faces","Face")
        shell = Part.Shell(faces)
        obj.Shape = Part.Solid(shell)

class solidVP:
    def __init__(self,vobj):
        vobj.Proxy = self
       
    def getIcon(self):
        return (TOOL_ICON)
Пример #12
0
__title__ = "Oriented sketch"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = """Sketch normal to an edge, with up vector normal to a face"""

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import Sketcher
import _utils

TOOL_ICON = _utils.iconsPath() + '/oriented_sketch.svg'
#debug = _utils.debug
#debug = _utils.doNothing

props = """
App::PropertyBool
App::PropertyBoolList
App::PropertyFloat
App::PropertyFloatList
App::PropertyFloatConstraint
App::PropertyQuantity
App::PropertyQuantityConstraint
App::PropertyAngle
App::PropertyDistance
App::PropertyLength
App::PropertySpeed
Пример #13
0
# -*- coding: utf-8 -*-

__title__ = "Split curve"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Splits the selected edge."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/splitcurve.svg'
debug = _utils.debug
#debug = _utils.doNothing

class split:
    """Splits the selected edge."""
    def __init__(self, obj, e):
        obj.addProperty("App::PropertyLinkSub",      "Edge",     "Split",  "Edge to split").Edge = e
        obj.addProperty("App::PropertyEnumeration",  "Method",   "Split",  "Splitting method").Method = ['Parameter','Distance','Percent']
        obj.addProperty("App::PropertyEnumeration",  "Output",   "Split",  "Output type").Output = ['Wire','Start','End']
        obj.addProperty("App::PropertyFloat",        "Value",    "Split",  "Split at given parameter")
        obj.addProperty("App::PropertyFloat",        "Param",    "Split",  "Parameter")
        obj.setEditorMode("Param", 2)
        obj.Method = 'Percent'
        obj.Output = 'Wire'
        obj.Value = 50.0
        obj.Proxy = self

    def onChanged(self, fp, prop):
Пример #14
0
import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils
from Part import Geom2d
from math import pi
Vector = FreeCAD.Base.Vector
Vector2d = FreeCAD.Base.Vector2d


TOOL_ICON = _utils.iconsPath() + '/spring.svg'
#debug = _utils.debug
#debug = _utils.doNothing

props = """
App::PropertyBool
App::PropertyBoolList
App::PropertyFloat
App::PropertyFloatList
App::PropertyFloatConstraint
App::PropertyQuantity
App::PropertyQuantityConstraint
App::PropertyAngle
App::PropertyDistance
App::PropertyLength
App::PropertySpeed
Пример #15
0
__title__ = "Blend curve"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Blend curve between two edges."

import FreeCAD
import FreeCADGui
import Part
import _utils

from pivy import coin
import nurbs_tools
import CoinNodes

TOOL_ICON = _utils.iconsPath() + '/blend1.svg'
debug = _utils.debug
#debug = _utils.doNothing


class BlendCurveFP:
    def __init__(self, obj, edges):
        debug("BlendCurve class Init")

        obj.addProperty("App::PropertyLinkSub", "Edge1", "Edge1",
                        "Edge 1").Edge1 = edges[0]
        obj.addProperty("App::PropertyLinkSub", "Edge2", "Edge2",
                        "Edge 2").Edge2 = edges[1]
        obj.addProperty("App::PropertyInteger", "DegreeMax", "BlendCurve",
                        "Max degree of the Blend curve").DegreeMax = 9
        obj.addProperty("App::PropertyFloatConstraint", "Parameter1", "Edge1",
Пример #16
0
# -*- coding: utf-8 -*-

__title__ = "Approximate"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Approximate a set of points."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/approximate.svg'
debug = _utils.debug
debug = _utils.doNothing


# ********************************************************
# **** Part.BSplineCurve.approximate() documentation *****
# ********************************************************

#Replaces this B-Spline curve by approximating a set of points.
#The function accepts keywords as arguments.

#approximate2(Points = list_of_points) 

#Optional arguments :

#DegMin = integer (3) : Minimum degree of the curve.
#DegMax = integer (8) : Maximum degree of the curve.
#Tolerance = float (1e-3) : approximating tolerance.
Пример #17
0
# -*- coding: utf-8 -*-

__title__ = "joinCurves"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Joins the selected edges into BSpline Curves"

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/joincurve.svg'
debug = _utils.debug
#debug = _utils.doNothing

def forceC1Continuity(c,tol):
    mults = [int(m) for m in c.getMultiplicities()]
    for i in range(len(mults))[1:-1]:
        if mults[i] >= c.Degree:
            try:
                rk = c.removeKnot(i+1,c.Degree-1,tol)
            except Part.OCCError:
                debug('failed to increase continuity.')
    return(c)    

def alignedTangents(c0, c1, Tol):
    t0 = c0.tangent(c0.LastParameter)[0]
    t1 = c1.tangent(c1.FirstParameter)[0]
    t0.normalize()
    t1.negative()
Пример #18
0
# -*- coding: utf-8 -*-

__title__ = "Sketch on surface"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Maps a sketch on a surface"

import FreeCAD
import FreeCADGui
import Part
import Sketcher
from FreeCAD import Base
import _utils

TOOL_ICON = _utils.iconsPath() + '/sketch_surf.svg'
debug = _utils.debug
#debug = _utils.doNothing
vec = FreeCAD.Vector

## create a circular face
#circle=Part.makeCircle(4,App.Vector(5,5,0))
#face=Part.Face(Part.Wire(circle.Edges))
#Part.show(face)

## get the pcurve of the boundary edge of the face
#curve=face.curveOnSurface(face.Edges[0]) # curve is a tuple or none!

## convert the face to a nurbs and modify it
#nurbs_face = face.toNurbs()
#nurbs_surf = nurbs_face.Faces[0].Surface
#nurbs_surf.setPole(1,1,App.Vector(0,0,5))
Пример #19
0
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Creates an editable interpolation curve"

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils
import profile_editor
reload(profile_editor)

TOOL_ICON = _utils.iconsPath() + '/editableSpline.svg'
#debug = _utils.debug
#debug = _utils.doNothing

#App::PropertyBool
#App::PropertyBoolList
#App::PropertyFloat
#App::PropertyFloatList
#App::PropertyFloatConstraint
#App::PropertyQuantity
#App::PropertyQuantityConstraint
#App::PropertyAngle
#App::PropertyDistance
#App::PropertyLength
#App::PropertySpeed
#App::PropertyAcceleration
Пример #20
0
# -*- coding: utf-8 -*-

__title__ = "Sublink Editor"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Editor widget for sublink properties of objects"


import FreeCAD
import FreeCADGui
from PySide import QtGui,QtCore
import _utils

TOOL_ICON = _utils.iconsPath() + '/sublink_edit.svg'
debug = _utils.debug

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

Пример #21
0
# -*- coding: utf-8 -*-

__title__ = "Combined projection curve"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Builds a 3D curve as the intersection of 2 projected curves."

import FreeCAD
import FreeCADGui
import Part
import _utils
import approximate_extension

TOOL_ICON = _utils.iconsPath() + '/combined_curve.svg'
debug = _utils.debug
#debug = _utils.doNothing


class CombinedProjectionCurve:
    """Builds a 3D curve as the intersection of 2 projected curves."""
    def __init__(self, sh1, sh2, dir1, dir2):
        self.shape1 = sh1
        self.shape2 = sh2
        if not dir1.Length == 0:
            self.dir1 = dir1
        else:
            raise ValueError("Vector is null")
        if not dir2.Length == 0:
            self.dir2 = dir2
        else:
            raise ValueError("Vector is null")
Пример #22
0
# -*- coding: utf-8 -*-

__title__ = "Curve on surface"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Creates a parametric curve on surface object."

import FreeCAD
import FreeCADGui
import Part
import curveOnSurface
from FreeCAD import Base
import _utils

TOOL_ICON = _utils.iconsPath() + '/curveOnSurface.svg'
debug = _utils.debug
#debug = _utils.doNothing

class cosFP:
    """Creates a parametric curve on surface object."""
    def __init__(self, obj):
        ''' Add the properties '''
        obj.addProperty("App::PropertyLinkSub",    "InputEdge",      "CurveOnSurface",   "Input edge")
        obj.addProperty("App::PropertyLinkSub",    "Face",           "CurveOnSurface",   "Support face")
        obj.addProperty("App::PropertyFloat",      "Tolerance",      "CurveOnSurface",   "Tolerance").Tolerance=0.0001
        obj.addProperty("App::PropertyBool",       "ReverseTangent", "Orientation",   "Reverse tangent").ReverseTangent = False
        obj.addProperty("App::PropertyBool",       "ReverseNormal",  "Orientation",   "Reverse normal").ReverseNormal = False
        obj.addProperty("App::PropertyBool",       "ReverseBinormal","Orientation",   "Reverse binormal").ReverseBinormal = False
        #obj.addProperty("Part::PropertyPartShape", "Shape",          "Base",   "Shape")
        obj.addProperty("App::PropertyEnumeration","Output",         "CurveOnSurface",   "Output type").Output = ["Curve only","Normal face","Binormal face"]
        obj.addProperty("App::PropertyInteger",    "Samples",        "CurveOnSurface", "Number of samples").Samples=100
Пример #23
0
# -*- coding: utf-8 -*-

__title__ = "MultiLoft"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = """Loft profile objects made of multiple faces in parallel"""


import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/multiLoft.svg'
#debug = _utils.debug
#debug = _utils.doNothing

props = """
App::PropertyBool
App::PropertyBoolList
App::PropertyFloat
App::PropertyFloatList
App::PropertyFloatConstraint
App::PropertyQuantity
App::PropertyQuantityConstraint
App::PropertyAngle
App::PropertyDistance
App::PropertyLength
App::PropertySpeed
App::PropertyAcceleration
App::PropertyForce
Пример #24
0
# -*- coding: utf-8 -*-

__title__ = "Curve on surface"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Creates a parametric curve on surface object."

import FreeCAD
import FreeCADGui
import Part
import curveOnSurface
from FreeCAD import Base
import _utils

TOOL_ICON = _utils.iconsPath() + '/curveOnSurface.svg'
debug = _utils.debug
#debug = _utils.doNothing


class cosFP:
    """Creates a parametric curve on surface object."""
    def __init__(self, obj):
        ''' Add the properties '''
        obj.addProperty("App::PropertyLinkSub", "InputEdge", "CurveOnSurface",
                        "Input edge")
        obj.addProperty("App::PropertyLinkSub", "Face", "CurveOnSurface",
                        "Support face")
        obj.addProperty("App::PropertyFloat", "Tolerance", "CurveOnSurface",
                        "Tolerance").Tolerance = 0.0001
        obj.addProperty("App::PropertyBool", "ReverseTangent", "Orientation",
                        "Reverse tangent").ReverseTangent = False
Пример #25
0
# -*- coding: utf-8 -*-

__title__ = "joinCurves"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Joins the selected edges into BSpline Curves"

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/joincurve.svg'
debug = _utils.debug
#debug = _utils.doNothing


def forceC1Continuity(c, tol):
    mults = [int(m) for m in c.getMultiplicities()]
    for i in range(len(mults))[1:-1]:
        if mults[i] >= c.Degree:
            try:
                rk = c.removeKnot(i + 1, c.Degree - 1, tol)
            except Part.OCCError:
                debug('failed to increase continuity.')
    return (c)


def alignedTangents(c0, c1, Tol):
    t0 = c0.tangent(c0.LastParameter)[0]
    t1 = c1.tangent(c1.FirstParameter)[0]
Пример #26
0
# -*- coding: utf-8 -*-

__title__ = "Parametric solid"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Make a parametric solid from selected faces."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/solid.svg'


class solid:
    """Make a parametric solid from selected faces"""
    def __init__(self, obj):
        obj.addProperty("App::PropertyLinkSubList", "Faces", "Solid",
                        "List of faces to build the solid")
        obj.Proxy = self

    def execute(self, obj):
        faces = _utils.getShape(obj, "Faces", "Face")
        shell = Part.Shell(faces)
        solid = Part.Solid(shell)
        if solid.isValid():
            obj.Shape = solid
        elif shell.isValid():
            obj.Shape = shell
        else:
Пример #27
0
# -*- coding: utf-8 -*-

__title__ = "Combined projection curve"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Builds a 3D curve as the intersection of 2 projected curves."

import FreeCAD
import FreeCADGui
import Part
import _utils
import approximate_extension

TOOL_ICON = _utils.iconsPath() + '/combined_curve.svg'
debug = _utils.debug
#debug = _utils.doNothing

class CombinedProjectionCurve:
    """Builds a 3D curve as the intersection of 2 projected curves."""
    def __init__(self, sh1, sh2, dir1, dir2):
        self.shape1 = sh1
        self.shape2 = sh2
        if not dir1.Length == 0:
            self.dir1 = dir1
        else:
            raise ValueError("Vector is null")
        if not dir2.Length == 0:
            self.dir2 = dir2
        else:
            raise ValueError("Vector is null")
    def shape(self):
Пример #28
0
# -*- coding: utf-8 -*-

__title__ = "Comb plot"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = 'Creates a parametric Comb plot on selected edges'

import FreeCAD
import FreeCADGui
import Part
import _utils
from FreeCAD import Base
from pivy import coin

TOOL_ICON = _utils.iconsPath() + '/comb.svg'
DEBUG = False


def debug(string):
    if DEBUG:
        FreeCAD.Console.PrintMessage(string)
        FreeCAD.Console.PrintMessage("\n")


def getEdgeParamList(edge, start=None, end=None, num=64):
    res = []
    if num <= 1:
        num = 2
    if not start:
        start = edge.FirstParameter
    if not end:
Пример #29
0
# -*- coding: utf-8 -*-

__title__ = "BSpline to script"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Creates a python script to build the selected BSpline curves."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/toconsole.svg'
debug = _utils.debug
#debug = _utils.doNothing


def curve_to_script(i, c):
    com = ["import FreeCAD", "from FreeCAD import Vector", "import Part", ""]
    if isinstance(c, Part.BSplineCurve):
        com.append("poles%d = %r" % (i, c.getPoles()))
        com.append("weights%d = %r" % (i, c.getWeights()))
        com.append("knots%d = %r" % (i, c.getKnots()))
        com.append("mults%d = %r" % (i, c.getMultiplicities()))
        com.append("periodic%d = %r" % (i, c.isPeriodic()))
        com.append("degree%d = %s" % (i, c.Degree))
        com.append("rational%d = %r" % (i, c.isRational()))
        com.append("bs%d = Part.BSplineCurve()" % i)
        #com.append("bs%d.buildFromPolesMultsKnots(poles%d, mults%d, knots%d, periodic%d, degree%d, )"%(i,i,i,i,i,i))
        com.append(
            "bs%d.buildFromPolesMultsKnots(poles%d, mults%d, knots%d, periodic%d, degree%d, weights%d, rational%d)"
Пример #30
0
# -*- coding: utf-8 -*-

__title__ = "Sublink Editor"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Editor widget for sublink properties of objects"

import FreeCAD
import FreeCADGui
from PySide import QtGui, QtCore
import _utils

TOOL_ICON = _utils.iconsPath() + '/sublink_edit.svg'
debug = _utils.debug

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:

    def _fromUtf8(s):
        return s


try:
    _encoding = QtGui.QApplication.UnicodeUTF8

    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:

    def _translate(context, text, disambig):
Пример #31
0
# -*- coding: utf-8 -*-

__title__ = "Sketch on surface"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Maps a sketch on a surface"

import FreeCAD
import FreeCADGui
import Part
import Sketcher
from FreeCAD import Base
import _utils

TOOL_ICON = _utils.iconsPath() + '/sketch_surf.svg'
debug = _utils.debug
#debug = _utils.doNothing
vec = FreeCAD.Vector

## create a circular face
#circle=Part.makeCircle(4,App.Vector(5,5,0))
#face=Part.Face(Part.Wire(circle.Edges))
#Part.show(face)

## get the pcurve of the boundary edge of the face
#curve=face.curveOnSurface(face.Edges[0]) # curve is a tuple or none!

## convert the face to a nurbs and modify it
#nurbs_face = face.toNurbs()
#nurbs_surf = nurbs_face.Faces[0].Surface
#nurbs_surf.setPole(1,1,App.Vector(0,0,5))
Пример #32
0
# -*- coding: utf-8 -*-

__title__ = "Interpolate"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Interpolate a set of points."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/interpolate.svg'
debug = _utils.debug
#debug = _utils.doNothing

# ********************************************************
# **** Part.BSplineCurve.interpolate() documentation *****
# ********************************************************

#Replaces this B-Spline curve by interpolating a set of points.
#The function accepts keywords as arguments.

#interpolate(Points = list_of_points)

#Optional arguments :

#PeriodicFlag = bool (False) : Sets the curve closed or opened.
#Tolerance = float (1e-6) : interpolating tolerance

#Parameters : knot sequence of the interpolated points.
Пример #33
0
# -*- coding: utf-8 -*-

__title__ = "Approximate"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Approximate a set of points."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/approximate.svg'
debug = _utils.debug
debug = _utils.doNothing


# ********************************************************
# **** Part.BSplineCurve.approximate() documentation *****
# ********************************************************

#Replaces this B-Spline curve by approximating a set of points.
#The function accepts keywords as arguments.

#approximate2(Points = list_of_points) 

#Optional arguments :

#DegMin = integer (3) : Minimum degree of the curve.
#DegMax = integer (8) : Maximum degree of the curve.
#Tolerance = float (1e-3) : approximating tolerance.
Пример #34
0
__doc__ = """Parametric Compression Spring"""

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils
from Part import Geom2d
from math import pi
Vector = FreeCAD.Base.Vector
Vector2d = FreeCAD.Base.Vector2d

TOOL_ICON = _utils.iconsPath() + '/spring.svg'
#debug = _utils.debug
#debug = _utils.doNothing

props = """
App::PropertyBool
App::PropertyBoolList
App::PropertyFloat
App::PropertyFloatList
App::PropertyFloatConstraint
App::PropertyQuantity
App::PropertyQuantityConstraint
App::PropertyAngle
App::PropertyDistance
App::PropertyLength
App::PropertySpeed
Пример #35
0
# -*- coding: utf-8 -*-

__title__ = 'Pipeshell profile'
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = 'Creates a Profile object for PipeShell'

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/profile.svg'
DEBUG = False


def debug(string):
    if DEBUG:
        FreeCAD.Console.PrintMessage(string)
        FreeCAD.Console.PrintMessage("\n")


class profile:
    "Profile object for PipeShell"

    def __init__(self, obj, source):
        ''' Add the properties '''
        if isinstance(source, (list, tuple)):
            obj.addProperty("App::PropertyLinkSubList", "Profile", "Profile",
                            "SubShapes of the profile")
        else:
Пример #36
0
__title__ = "Segment surface"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = """Segment a surface on isocurves"""

import os
import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = os.path.join(_utils.iconsPath() + '/segment_surface.svg')
#debug = _utils.debug
#debug = _utils.doNothing

props = """
App::PropertyBool
App::PropertyBoolList
App::PropertyFloat
App::PropertyFloatList
App::PropertyFloatConstraint
App::PropertyQuantity
App::PropertyQuantityConstraint
App::PropertyAngle
App::PropertyDistance
App::PropertyLength
App::PropertySpeed
Пример #37
0
__title__ = "Reflect Lines"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = """Creates the reflect lines on a shape, according to a view direction"""

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils
import nurbs_tools

TOOL_ICON = _utils.iconsPath() + '/reflectLines.svg'

class ReflectLinesFP:
    """Creates the reflect lines on a shape, according to a view direction"""
    def __init__(self, obj, src):
        """Add the properties"""
        obj.addProperty("App::PropertyLink",   "Source",  "ReflectLines", "Source object")
        obj.addProperty("App::PropertyLinkSubList","IndivFaces","ReflectLines", "Individual faces")
        obj.addProperty("App::PropertyVector", "ViewPos", "ReflectLines", "View position")
        obj.addProperty("App::PropertyVector", "ViewDir", "ReflectLines", "View direction")
        obj.addProperty("App::PropertyVector", "UpDir",   "ReflectLines", "Up direction")
        obj.addProperty("App::PropertyBool",   "ShapeCleaning","ReflectLines", "Remove duplicate edges").ShapeCleaning = False
        obj.addProperty("App::PropertyInteger", "Samples","CleaningOptions", "Number of edge samples").Samples = 10
        obj.addProperty("App::PropertyQuantity", "Tolerance","CleaningOptions", "Tolerance for duplicate detection").Tolerance = 1e-3
        #obj.Samples = [10,3,999,1]
        obj.ViewPos = FreeCAD.Vector(0,0,0)
Пример #38
0
# -*- coding: utf-8 -*-

__title__ = "Parametric line"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Parametric line between two vertexes."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/line.svg'
debug = _utils.debug
debug = _utils.doNothing

class line:
    """Creates a parametric line between two vertexes"""
    def __init__(self, obj):
        """Add the properties"""
        obj.addProperty("App::PropertyLinkSub", "Vertex1", "Line", "First Vertex")
        obj.addProperty("App::PropertyLinkSub", "Vertex2", "Line", "Second Vertex")
        obj.Proxy = self

    def execute(self, obj):
        v1 = _utils.getShape(obj, "Vertex1", "Vertex")
        v2 = _utils.getShape(obj, "Vertex2", "Vertex")
        if v1 and v2:
            l = Part.LineSegment(v1.Point, v2.Point)
            obj.Shape = l.toShape()
        else:
Пример #39
0
# -*- coding: utf-8 -*-

__title__ = "Discretize"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Discretize an edge or a wire."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/discretize.svg'
debug = _utils.debug
debug = _utils.doNothing


class Discretization:
    def __init__(self, obj, edge):
        debug("Discretization class Init")
        obj.addProperty("App::PropertyLinkSub", "Edge", "Discretization",
                        "Edge").Edge = edge
        obj.addProperty("App::PropertyEnumeration", "Target", "Discretization",
                        "Tool target").Target = ["Edge", "Wire"]
        obj.addProperty("App::PropertyEnumeration", "Algorithm", "Method",
                        "Discretization Method").Algorithm = [
                            "Number", "QuasiNumber", "Distance", "Deflection",
                            "QuasiDeflection", "Angular-Curvature"
                        ]
        obj.addProperty("App::PropertyInteger", "Number", "Method",
                        "Number of edge points").Number = 100
Пример #40
0
# -*- coding: utf-8 -*-

__title__ = "Curve extend"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Extend an edge by a given distance."

import FreeCAD
import FreeCADGui
import Part
import _utils
import curveExtend

TOOL_ICON = _utils.iconsPath() + '/extendcurve.svg'
debug = _utils.debug
debug = _utils.doNothing

class extend:
    """Extends the selected edge"""
    def __init__(self, obj):
        obj.addProperty("App::PropertyLinkSub",      "Edge",       "Base", "Input edge to extend")
        obj.addProperty("App::PropertyEnumeration",  "Output",     "Base", "Output shape").Output = ["SingleEdge","Wire"]

        obj.addProperty("App::PropertyFloat",        "LengthStart","Beginning", "Start Extension Length").LengthStart=10.0
        obj.addProperty("App::PropertyEnumeration",  "TypeStart",  "Beginning", "Start Extension type").TypeStart = ["Straight","G2 curve"]

        obj.addProperty("App::PropertyFloat",        "LengthEnd",  "End", "End Extension Length").LengthEnd=10.0
        obj.addProperty("App::PropertyEnumeration",  "TypeEnd",    "End", "End Extension type").TypeEnd = ["Straight","G2 curve"]
        
        obj.TypeStart = "Straight"
        obj.TypeEnd = "Straight"
Пример #41
0
__title__ = "Parametric Gordon surface"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Creates a surface that skins a network of curves."

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/gordon.svg'
#debug = _utils.debug
#debug = _utils.doNothing


def debug(o):
    if isinstance(o, Part.BSplineCurve):
        FreeCAD.Console.PrintWarning("\nBSplineCurve\n")
        FreeCAD.Console.PrintWarning("Degree: %d\n" % (o.Degree))
        FreeCAD.Console.PrintWarning("NbPoles: %d\n" % (o.NbPoles))
        FreeCAD.Console.PrintWarning(
            "Knots: %d (%0.2f - %0.2f)\n" %
            (o.NbKnots, o.FirstParameter, o.LastParameter))
        FreeCAD.Console.PrintWarning("Mults: %s\n" % (o.getMultiplicities()))
        FreeCAD.Console.PrintWarning("Periodic: %s\n" % (o.isPeriodic()))
    elif isinstance(o, Part.BSplineSurface):
Пример #42
0
# -*- coding: utf-8 -*-

__title__ = "Extract subshape"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Extract selected subshapes from objects."

import FreeCAD
import FreeCADGui
import Part
import _utils

TOOL_ICON = _utils.iconsPath() + '/extract.svg'


class extract:
    """Extract the selected shapes from objects"""
    def Activated(self):
        s = FreeCADGui.Selection.getSelectionEx()
        for o in s:
            objName = o.ObjectName
            for so, name in zip(o.SubObjects, o.SubElementNames):
                fullname = objName + "_" + name
                newobj = FreeCAD.ActiveDocument.addObject(
                    "Part::Feature", fullname)
                if hasattr(o.Object, "getGlobalPlacement"):
                    gpl = o.Object.getGlobalPlacement()
                    so.transformShape(gpl.toMatrix())
                newobj.Shape = so
            o.Object.ViewObject.Visibility = False
        FreeCAD.ActiveDocument.recompute()
Пример #43
0
__title__ = "Outline Curve"
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = """Outline curve of a shape"""

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils
import approximate_extension

TOOL_ICON = _utils.iconsPath() + 'icon.svg'
#debug = _utils.debug
#debug = _utils.doNothing

props = """
App::PropertyBool
App::PropertyBoolList
App::PropertyFloat
App::PropertyFloatList
App::PropertyFloatConstraint
App::PropertyQuantity
App::PropertyQuantityConstraint
App::PropertyAngle
App::PropertyDistance
App::PropertyLength
App::PropertySpeed
Пример #44
0
Select a face in the 3D View.
Then, in Py console:

import IsoCurves
IsoCurves.run()

'''

import FreeCAD as App
if App.GuiUp:
    import FreeCADGui as Gui
import Part
import isocurves
import _utils

TOOL_ICON = _utils.iconsPath() + '/isocurve.svg'
#debug = _utils.debug
debug = _utils.doNothing


def makeIsoCurveFeature():
    '''makeIsoCurveFeature(): makes a IsoCurve parametric feature object. Returns the new object.'''
    selfobj = App.ActiveDocument.addObject("Part::FeaturePython", "IsoCurve")
    IsoCurve(selfobj)
    ViewProviderIsoCurve(selfobj.ViewObject)
    return selfobj


class IsoCurve:
    "The IsoCurve feature object"
Пример #45
0
# -*- coding: utf-8 -*-

__title__ = 'Profile support plane'
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = 'Creates a support plane for sketches'

import FreeCAD
import FreeCADGui
import Part
import _utils
import Sketcher
from pivy.coin import *

TOOL_ICON = _utils.iconsPath() + '/profileSupport.svg'
DEBUG = False

def debug(string):
    if DEBUG:
        FreeCAD.Console.PrintMessage(string)
        FreeCAD.Console.PrintMessage("\n")


class profileSupportFP:
    "creates a profile sketch"
    def __init__(self, obj):
        ''' Add the properties '''
        obj.addProperty("App::PropertyLinkSub",  "Edge1",        "Profile",   "First support edge")
        obj.addProperty("App::PropertyLinkSub",  "Edge2",        "Profile",   "Second support edge")
        obj.addProperty("App::PropertyFloat",    "Parameter1",   "Profile",   "Parameter on first edge")
        obj.addProperty("App::PropertyFloat",    "Parameter2",   "Profile",   "Parameter on second edge")
Пример #46
0
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = """High Quality ruled surface.
The 2 edges (or wires) are reparametrized before surface creation."""

import sys
if sys.version_info.major >= 3:
    from importlib import reload

import FreeCAD
import FreeCADGui
import Part
import _utils
import reparametrize as rp

TOOL_ICON = _utils.iconsPath() + '/ruled_surface.svg'
#debug = _utils.debug
#debug = _utils.doNothing

props = """
App::PropertyBool
App::PropertyBoolList
App::PropertyFloat
App::PropertyFloatList
App::PropertyFloatConstraint
App::PropertyQuantity
App::PropertyQuantityConstraint
App::PropertyAngle
App::PropertyDistance
App::PropertyLength
App::PropertySpeed