Macro FCSpring Helix Variable: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
(ver 1.09)
Line 51: Line 51:
==='''Third section, coil special length''' === <!--T:8-->
==='''Third section, coil special length''' === <!--T:8-->
* '''Numbering of coil''' : Numbering of coil to modify. (Defaut : none)
* '''Numbering of coil''' : Numbering of coil to modify. (Defaut : none)
* '''Smoothing''' This checkBox discover one spinBox for determine the grade of smoothing the maximum value is the precision value -1 (this option is still at the prototype stage and the result can be satisfying or completely wrong)
* '''Pitch of coil''' : Pitch of coil to modify. (Defaut : none)
* '''Pitch of coil''' : Pitch of coil to modify. (Defaut : none)
* {{KEY|Accept the value modified}} : Button to accept the modification after select the numbering of coil and modify the pitch of coil.
* {{KEY|15}} : If the button is pressed the value of the "Pitch of string" is affected of the "Pitch of coil" (This value is automatically aligned of the value Pitch of string)
* '''Radius of coil''' : Radius of coil to modify. (Defaut : none)
* '''Radius of coil''' : Radius of coil to modify. (Defaut : none)
* {{KEY|20}} : If the button is pressed the value of the "Radius of string" is affected of the "Radius of coil" (This value is automatically aligned of the value Radius of string)
* {{KEY|Accept the value modified}} : Button to accept the modification after select the numbering of coil and modify the pitch of coil.
* '''Text edit''' : This window displayed all coil modified.
* '''Text edit''' : This window displayed all coil modified.
</translate>
</translate>
Line 61: Line 64:
<translate>
<translate>
== Commands == <!--T:9-->
== Commands == <!--T:9-->
* {{KEY|Read}} : The Read button open a dialogue box to read a file '''.FCSpring'''.
* {{KEY|Load}} : The Read button open a dialogue box to read a file '''.FCSpring'''.
* {{KEY|Save}} : The Save button open a dialogue box to save a file '''.FCSpring''' with configuration spring modify or not.
* {{KEY|Save}} : The Save button open a dialogue box to save a file '''.FCSpring''' with configuration spring modify or not.
* {{KEY|Load Coordinates}} : Open a dialogue box to read a file '''.FCSpringCoor''' (all coordinates of points of the spring).
* {{KEY|Save Coordinates}} : Open a dialogue box to save a file '''.FCSpringCoor''' (all coordinates of points of the spring).
* {{KEY|Quit}} : Quit the macro.
* {{KEY|Quit}} : Quit the macro.
* {{KEY|Reset}} : Reset the macro to default configuration.
* {{KEY|Reset}} : Reset the macro to default configuration.
Line 92: Line 97:


</translate>
</translate>

[[File:Macro FCSpring Helix Variable 08.png]]
{{clear}}
{{clear}}
<translate>
<translate>
==Icon== <!--T:14-->
==Icon== <!--T:14-->
Download the file image and copy in your macro repertory.
Download the file image and copy in your macro repertory.
[[File:Macro FCSpring Helix Variable 08.png]]


<!--T:15-->
<!--T:15-->
Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."
Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."


[[File:FCSpring Helix Variable.png|left|Button]]
ToolBar button [[File:FCSpring Helix Variable.png|left|Button]]
{{clear}}
Macro icons

[[File:FCSpring_Helix_Variable_Icon_01.png]] [[File:FCSpring_Helix_Variable_Icon_02.png]] [[File:FCSpring_Helix_Variable_Icon_02b.png]] [[File:FCSpring_Helix_Variable_Icon_03.png]] [[File:FCSpring_Helix_Variable_Icon_03b.png]] [[File:FCSpring_Helix_Variable_Icon_04.png]] [[File:FCSpring_Helix_Variable_Icon_05.png]] [[File:FCSpring_Helix_Variable_Icon_06.png]]
{{clear}}
{{clear}}
==Script== <!--T:16-->
==Script== <!--T:16-->
Line 107: Line 117:
<!--T:17-->
<!--T:17-->
'''Macro_FCSpring_Helix_Variable.FCMacro'''
'''Macro_FCSpring_Helix_Variable.FCMacro'''
</translate>


Download the macro to Gist [https://gist.github.com/mario52a/68c81c32a0727a693d3a Macro_FCSpring_Helix_Variable]
{{Code|code=
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import division
"""
***************************************************************************
* Copyright (c) 2014-2015-2016 <mario52> *
* *
* This file is a supplement to the FreeCAD CAx development system. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License (LGPL) *
* as published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* for detail see the LICENCE text file. *
* *
* This software is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this macro; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* USA *
***************************************************************************
* WARNING! All changes in this file will be lost and *
* may cause malfunction of the program *
***************************************************************************
"""
#
#OS: Windows Vista
#Word size of OS: 32-bit
#Word size of FreeCAD: 32-bit
#Version: 0.15.4527 (Git)
#Branch: master
#Hash: 0da2e4c45a9a259c26abd54c2a35393e1c15696f
#Python version: 2.7.8
#Qt version: 4.8.6
#Coin version: 4.0.0a
#OCC version: 6.7.1


__title__ = "FCSpring_Helix_Variable"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "01.08"
__date__ = "16/03/2016"

try:
import PyQt4
from PyQt4 import QtGui ,QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
except Exception:
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
import os, time, sys
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD
from math import sqrt, pi, sin, cos, asin, tan, degrees, radians, sqrt
from FreeCAD import Base

global path
#path = FreeCAD.ConfigGet("AppHomePath")
path = FreeCAD.ConfigGet("UserAppData")
#path = "Your_Path"

global numberSpires ;numberSpires = 10 # number Spires of spring
global rayon ;rayon = 20.0 # radius of spring
global pas ;pas = 15.0 # " ! float " (pas) pitch of spire
global precision ;precision = 5.0 # " ! float " 360/precision number points for 1 turn
global typeLine ;typeLine = 0 # typeLine 0=BSpline or 1=Wire
global helixS ;helixS = 0.0 # tableau
global numberSpiresModified;numberSpiresModified = 1 # number (pas) pitch to modify
global pasSpire ;pasSpire = 0 #pas # (pas) pitch of spire to modify
global radiusS ;radiusS = 0.0 # tableau radius to modify
global rayonSpire ;rayonSpire = 0 #rayon # new radius
global affPoint ;affPoint = 0 # aff points
global debutAngle ;debutAngle = 0 # begin angle rotation
global finAngle ;finAngle = 360 # end angle rotation
global modifyAngle ;modifyAngle = 0 # interrupteur angle
global radius_2_Cone ;radius_2_Cone = rayon # radius_2_Cone en cas d'helice
global spireConeUne ;spireConeUne = 0 # interrupteur cone si une seule spire spireConeUne = 1
global spireConeComp ;spireConeComp = 0 # compensation pour cone
global spireReverse ;spireReverse = 0 # 0 = sens antihoraire si = 1 sens horaire

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)

def errorDialog(msg):
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
try:
diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # cette fonction met la fenêtre en avant
except Exception:
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide #cette fonction met la fenêtre en avant
# diag.setWindowModality(QtCore.Qt.ApplicationModal) # la fonction a été désactivée pour favoriser "WindowStaysOnTopHint"
diag.exec_()

class Ui_MainWindow(object):

def setupUi(self, MainWindow):
global path
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global pasSpire
global radiusS
global spireReverse

self.window = MainWindow

MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(270, 587)
MainWindow.setMinimumSize(QtCore.QSize(270, 35))
MainWindow.setMaximumSize(QtCore.QSize(270, 587))
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))

self.groupBox = QtGui.QGroupBox(self.centralWidget)
self.groupBox.setGeometry(QtCore.QRect(10, 40, 251, 261))
self.groupBox.setToolTip(_fromUtf8(""))
self.groupBox.setFlat(False)
self.groupBox.setObjectName(_fromUtf8("groupBox"))

self.DS_Numb_Spires = QtGui.QSpinBox(self.groupBox)
self.DS_Numb_Spires.setGeometry(QtCore.QRect(20, 20, 91, 22))
self.DS_Numb_Spires.setToolTip(_fromUtf8("Number total of coil of the spring"))
self.DS_Numb_Spires.setMinimum(1)
self.DS_Numb_Spires.setMaximum(9999999)
self.DS_Numb_Spires.setValue(numberSpires)
self.DS_Numb_Spires.setObjectName(_fromUtf8("DS_Numb_Spires"))
self.DS_Numb_Spires.valueChanged.connect(self.on_DS_Numb_Spires) #connection doubleSpinBox

self.DS_Radius_Sping = QtGui.QDoubleSpinBox(self.groupBox)
self.DS_Radius_Sping.setGeometry(QtCore.QRect(20, 80, 91, 22))
self.DS_Radius_Sping.setToolTip(_fromUtf8("Radius of spring"))
self.DS_Radius_Sping.setDecimals(3)
# self.DS_Radius_Sping.setMinimum(0.001)
self.DS_Radius_Sping.setMaximum(9999999.99)
self.DS_Radius_Sping.setValue(rayon)
self.DS_Radius_Sping.setObjectName(_fromUtf8("DS_Radius_Sping"))
self.DS_Radius_Sping.valueChanged.connect(self.on_DS_Radius_Sping) #connection doubleSpinBox

self.DS_Pas_Spring = QtGui.QDoubleSpinBox(self.groupBox)
self.DS_Pas_Spring.setGeometry(QtCore.QRect(20, 50, 91, 22))
self.DS_Pas_Spring.setToolTip(_fromUtf8("Pitch of spring (distance between two vertices)"))
self.DS_Pas_Spring.setDecimals(3)
# self.DS_Pas_Spring.setMinimum(0.001)
self.DS_Pas_Spring.setMaximum(9999999.99)
self.DS_Pas_Spring.setValue(pas)
self.DS_Pas_Spring.setObjectName(_fromUtf8("DS_Pas_Spring"))
self.DS_Pas_Spring.valueChanged.connect(self.on_DS_Pas_Spring) #connection doubleSpinBox

self.DS_Precision_Turn = QtGui.QSpinBox(self.groupBox)
self.DS_Precision_Turn.setGeometry(QtCore.QRect(20, 110, 91, 22))
self.DS_Precision_Turn.setToolTip(_fromUtf8("Precision for the line (points = (360/precision))"))
self.DS_Precision_Turn.setMinimum(1)
self.DS_Precision_Turn.setMaximum(360)
self.DS_Precision_Turn.setValue(precision)
self.DS_Precision_Turn.setObjectName(_fromUtf8("DS_Precision_Turn"))
self.DS_Precision_Turn.valueChanged.connect(self.on_DS_Precision_Turn) #connection doubleSpinBox

self.label_2 = QtGui.QLabel(self.groupBox)
self.label_2.setGeometry(QtCore.QRect(120, 20, 111, 16))
self.label_2.setToolTip(_fromUtf8("Number total of coil of the spring"))
self.label_2.setObjectName(_fromUtf8("label_2"))

self.label_3 = QtGui.QLabel(self.groupBox)
self.label_3.setGeometry(QtCore.QRect(120, 80, 111, 16))
self.label_3.setToolTip(_fromUtf8("Radius of spring"))
self.label_3.setText(_fromUtf8("Radius of spring"))
self.label_3.setObjectName(_fromUtf8("label_3"))

self.label_4 = QtGui.QLabel(self.groupBox)
self.label_4.setGeometry(QtCore.QRect(120, 50, 111, 16))
self.label_4.setToolTip(_fromUtf8("Pitch of spring (distance between two vertices)"))
self.label_4.setText(_fromUtf8("Pitch of spring"))
self.label_4.setObjectName(_fromUtf8("label_4"))

self.label_5 = QtGui.QLabel(self.groupBox)
self.label_5.setGeometry(QtCore.QRect(120, 110, 130, 16)) #111
self.label_5.setToolTip(_fromUtf8("The precision is the number point (360/precision) for create one turn of the spring"))
self.label_5.setText(_fromUtf8("Precision = " + str(360/precision) + " points"))
self.label_5.setObjectName(_fromUtf8("label_5"))

self.groupBox_3 = QtGui.QGroupBox(self.groupBox)
self.groupBox_3.setGeometry(QtCore.QRect(10, 200, 231, 51))
self.groupBox_3.setObjectName(_fromUtf8("groupBox_3"))

self.RA_Wire = QtGui.QRadioButton(self.groupBox_3)
self.RA_Wire.setGeometry(QtCore.QRect(67, 20, 51, 20))
self.RA_Wire.setToolTip(_fromUtf8("Type line Wire"))
self.RA_Wire.setText(_fromUtf8("Wire"))
# self.RA_Wire.setChecked(True)
self.RA_Wire.setObjectName(_fromUtf8("RA_Wire"))
self.RA_Wire.clicked.connect(self.on_RA_Wire) #connection radioButton

self.RA_BSpline = QtGui.QRadioButton(self.groupBox_3)
self.RA_BSpline.setGeometry(QtCore.QRect(10, 20, 61, 20))
self.RA_BSpline.setToolTip(_fromUtf8("Type line BSpline"))
self.RA_BSpline.setText(_fromUtf8("BSpline"))
self.RA_BSpline.setChecked(True)
self.RA_BSpline.setObjectName(_fromUtf8("RA_BSpline"))
self.RA_BSpline.clicked.connect(self.on_RA_BSpline) #connection radioButton

self.CH_Points = QtGui.QCheckBox(self.groupBox_3)
self.CH_Points.setEnabled(True)
self.CH_Points.setGeometry(QtCore.QRect(117, 20, 51, 20))
self.CH_Points.setToolTip(_fromUtf8("Check to create points to alls nodes of the precision of turn"))
self.CH_Points.setText(_fromUtf8("Ch"))
# self.CH_Points.setStatusTip(_fromUtf8(""))
self.CH_Points.setChecked(False)
self.CH_Points.setObjectName(_fromUtf8("CH_Points"))
self.CH_Points.clicked.connect(self.on_CH_Points) #

self.CH_Reverse = QtGui.QCheckBox(self.groupBox_3)
self.CH_Reverse.setEnabled(True)
self.CH_Reverse.setGeometry(QtCore.QRect(172, 20, 61, 20))
self.CH_Reverse.setToolTip(_fromUtf8("Check to create clockwise direction"))
self.CH_Reverse.setText(_fromUtf8("Ch"))
# self.CH_Reverse.setStatusTip(_fromUtf8(""))
self.CH_Reverse.setChecked(False)
self.CH_Reverse.setObjectName(_fromUtf8("CH_Points"))
self.CH_Reverse.clicked.connect(self.on_CH_Reverse) #

self.S_Begin_Angle = QtGui.QSpinBox(self.groupBox)
self.S_Begin_Angle.setEnabled(False)
self.S_Begin_Angle.setGeometry(QtCore.QRect(20, 170, 51, 22))
self.S_Begin_Angle.setMinimum(0)
self.S_Begin_Angle.setMaximum(360)
self.S_Begin_Angle.setValue(0)
self.S_Begin_Angle.setObjectName(_fromUtf8("S_Begin_Angle"))
self.S_Begin_Angle.valueChanged.connect(self.on_S_Begin_Angle) #

self.S_End_Angle = QtGui.QSpinBox(self.groupBox)
self.S_End_Angle.setEnabled(False)
self.S_End_Angle.setGeometry(QtCore.QRect(120, 170, 51, 22))
self.S_End_Angle.setMinimum(1)
self.S_End_Angle.setMaximum(360)
self.S_End_Angle.setValue(360)
self.S_End_Angle.setObjectName(_fromUtf8("S_End_Angle"))
self.S_End_Angle.valueChanged.connect(self.on_S_End_Angle) #

self.label_9 = QtGui.QLabel(self.groupBox)
self.label_9.setGeometry(QtCore.QRect(80, 170, 41, 16))
self.label_9.setObjectName(_fromUtf8("label_9"))

self.label_10 = QtGui.QLabel(self.groupBox)
self.label_10.setGeometry(QtCore.QRect(180, 170, 31, 16))
self.label_10.setObjectName(_fromUtf8("label_10"))

self.CH_B_E_Angle = QtGui.QCheckBox(self.groupBox)
self.CH_B_E_Angle.setGeometry(QtCore.QRect(210, 170, 41, 20))
self.CH_B_E_Angle.setToolTip(_fromUtf8("Check the option modify to begin and ultimate angle of coils"))
self.CH_B_E_Angle.setText(_fromUtf8(""))
self.CH_B_E_Angle.setObjectName(_fromUtf8("CB_B_E_Angle"))
self.CH_B_E_Angle.clicked.connect(self.on_CH_B_E_Angle) #connection radioButton

self.DS_Radius_2_Cone = QtGui.QDoubleSpinBox(self.groupBox)
self.DS_Radius_2_Cone.setEnabled(False)
self.DS_Radius_2_Cone.setGeometry(QtCore.QRect(20, 140, 91, 22))
self.DS_Radius_2_Cone.setToolTip(_fromUtf8("Radius for make a cone\n this radius is always greater than the principal radius"))
self.DS_Radius_2_Cone.setDecimals(3)
self.DS_Radius_2_Cone.setMaximum(9999999.99)
# self.DS_Radius_2_Cone.setMinimum(rayon)
self.DS_Radius_2_Cone.setValue(rayon)
self.DS_Radius_2_Cone.setObjectName(_fromUtf8("DS_Radius_2_Cone"))
self.DS_Radius_2_Cone.valueChanged.connect(self.on_DS_Radius_2_Cone) #

self.CH_Cone = QtGui.QCheckBox(self.groupBox)
self.CH_Cone.setEnabled(True)
self.CH_Cone.setGeometry(QtCore.QRect(120, 140, 121, 20))
self.CH_Cone.setToolTip(_fromUtf8("Check for create one conical helix"))
self.CH_Cone.setObjectName(_fromUtf8("CH_Cone"))
self.CH_Cone.clicked.connect(self.on_CH_Cone) #
self.groupBox_2 = QtGui.QGroupBox(self.centralWidget)
self.groupBox_2.setGeometry(QtCore.QRect(10, 310, 251, 201))
self.groupBox_2.setToolTip(_fromUtf8("This section allows you to adjust the distance from the coil named. EX: 1 spire = 2 mm"))
self.groupBox_2.setCheckable(False)
self.groupBox_2.setChecked(False)
self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))

self.S_Numbering_Spire = QtGui.QSpinBox(self.groupBox_2)
self.S_Numbering_Spire.setGeometry(QtCore.QRect(20, 20, 91, 22))
self.S_Numbering_Spire.setToolTip(_fromUtf8("Numbering of coil for 1 to max = Number of coil ("+str(numberSpires)+")"))
self.S_Numbering_Spire.setMinimum(1)
self.S_Numbering_Spire.setMaximum(numberSpires)
self.S_Numbering_Spire.setObjectName(_fromUtf8("S_Nmbering_Spire"))
self.S_Numbering_Spire.valueChanged.connect(self.on_S_Numbering_Spire) #connection SpinBox

self.DS_Pas_Spire = QtGui.QDoubleSpinBox(self.groupBox_2)
self.DS_Pas_Spire.setGeometry(QtCore.QRect(20, 50, 91, 22))
self.DS_Pas_Spire.setToolTip(_fromUtf8("Pitch of the coil (The pitch is the distance betwen 2 vertices)"))
self.DS_Pas_Spire.setValue(0) #pas
self.DS_Pas_Spire.setDecimals(3)
# self.DS_Pas_Spire.setMinimum(0.001)
self.DS_Pas_Spire.setMaximum(9999999.99)
self.DS_Pas_Spire.setObjectName(_fromUtf8("DS_Pas_Spire"))
self.DS_Pas_Spire.valueChanged.connect(self.on_DS_Pas_Spire) #connection doubleSpinBox

self.label_6 = QtGui.QLabel(self.groupBox_2)
self.label_6.setGeometry(QtCore.QRect(120, 20, 121, 16))
self.label_6.setToolTip(_fromUtf8("Numbering of coil for 1 to max = Number of coil"))
self.label_6.setText(_fromUtf8("Numbering of coil"))
self.label_6.setObjectName(_fromUtf8("label_6"))

self.label_7 = QtGui.QLabel(self.groupBox_2)
self.label_7.setGeometry(QtCore.QRect(120, 50, 121, 16))
self.label_7.setToolTip(_fromUtf8("Pitch of the coil (The pitch is the distance betwen 2 vertices)"))
self.label_7.setObjectName(_fromUtf8("label_7"))

self.PU_Accept_Value = QtGui.QPushButton(self.groupBox_2)
self.PU_Accept_Value.setGeometry(QtCore.QRect(20, 110, 211, 21))
self.PU_Accept_Value.setToolTip(_fromUtf8("Accept the value for the coil "))
self.PU_Accept_Value.setObjectName(_fromUtf8("PU_Accept_Value"))
self.PU_Accept_Value.clicked.connect(self.on_PU_Accept_Value)

self.textEdit = QtGui.QTextEdit(self.groupBox_2)
self.textEdit.setGeometry(QtCore.QRect(20, 140, 211, 51))
self.textEdit.setToolTip(_fromUtf8("List alls modification of coil "))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.textEdit.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)

self.DS_Radius_Spire = QtGui.QDoubleSpinBox(self.groupBox_2)
self.DS_Radius_Spire.setGeometry(QtCore.QRect(20, 80, 91, 22))
self.DS_Radius_Spire.setToolTip(_fromUtf8("Radius of coil "))
self.DS_Radius_Spire.setDecimals(3)
self.DS_Radius_Spire.setValue(0) #rayon
# self.DS_Radius_Spire.setMinimum(0.001)
self.DS_Radius_Spire.setMaximum(9999999.99)
self.DS_Radius_Spire.setObjectName(_fromUtf8("DS_Radius_Spire"))
self.DS_Radius_Spire.valueChanged.connect(self.on_DS_Radius_Spire) #connection doubleSpinBox

self.label_8 = QtGui.QLabel(self.groupBox_2)
self.label_8.setGeometry(QtCore.QRect(120, 80, 121, 16))
self.label_8.setToolTip(_fromUtf8("Radius of coil "))
self.label_8.setText(_fromUtf8("Radius of coil"))
self.label_8.setObjectName(_fromUtf8("label_8"))

self.PU_Quit = QtGui.QPushButton(self.centralWidget)
self.PU_Quit.setGeometry(QtCore.QRect(10, 550, 81, 28))
self.PU_Quit.setToolTip(_fromUtf8("Quit the macro"))
self.PU_Quit.setText(_fromUtf8("Quit"))
self.PU_Quit.setObjectName(_fromUtf8("PU_Quit"))
self.PU_Quit.clicked.connect(self.on_PU_Quit)

self.PU_Launch = QtGui.QPushButton(self.centralWidget)
self.PU_Launch.setGeometry(QtCore.QRect(180, 550, 81, 28))
self.PU_Launch.setToolTip(_fromUtf8("launch the macro and create the spring"))
self.PU_Launch.setText(_fromUtf8("Launch "))
self.PU_Launch.setObjectName(_fromUtf8("PU_Launch"))
self.PU_Launch.clicked.connect(self.on_PU_Launch)

self.label = QtGui.QLabel(self.centralWidget)
self.label.setGeometry(QtCore.QRect(10, 0, 265, 31))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setItalic(True)
font.setUnderline(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setText(_fromUtf8("FCSpring Helix Variable"))
self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralWidget)

self.PU_Reset = QtGui.QPushButton(self.centralWidget)
self.PU_Reset.setGeometry(QtCore.QRect(100, 550, 71, 28))
self.PU_Reset.setToolTip(_fromUtf8("Reset complete the data "))
self.PU_Reset.setObjectName(_fromUtf8("PU_Reset"))
self.PU_Reset.clicked.connect(self.on_PU_Reset)

self.PU_Read = QtGui.QPushButton(self.centralWidget)
self.PU_Read.setGeometry(QtCore.QRect(10, 520, 121, 28))
self.PU_Read.setToolTip(_fromUtf8("Read the file "))
self.PU_Read.setText(_fromUtf8("Read"))
self.PU_Read.setObjectName(_fromUtf8("on_PU_Read"))
self.PU_Read.clicked.connect(self.on_PU_Read)

self.PU_Save = QtGui.QPushButton(self.centralWidget)
self.PU_Save.setGeometry(QtCore.QRect(140, 520, 121, 28))
self.PU_Save.setToolTip(_fromUtf8("Save the file"))
self.PU_Save.setText(_fromUtf8("Save"))
self.PU_Save.setObjectName(_fromUtf8("on_PU_Save"))
self.PU_Save.clicked.connect(self.on_PU_Save)

MainWindow.setCentralWidget(self.centralWidget)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
try:
MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 cette fonction met la fenêtre en avant
except Exception:
MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenêtre en avant

MainWindow.setWindowIcon(QtGui.QIcon(path+'FCSpring_Helix_Variable.png')) # change l'icône de la fenêtre principale
MainWindow.setWindowTitle("FCSpring Helix Variable")
self.groupBox.setTitle("Configure")
self.label_2.setText("Number of coil")
self.groupBox_3.setTitle("Type line")
self.RA_Wire.setToolTip("Type line Wire")

self.CH_Points.setText("Points")
self.CH_Reverse.setText("Reverse")
self.S_Begin_Angle.setToolTip("Begin angle first coil")
self.S_Begin_Angle.setSuffix("°")
self.S_End_Angle.setToolTip(_fromUtf8("End angle ultimate coil"))
self.S_End_Angle.setStatusTip("End angle to ultimate coil")
self.S_End_Angle.setSuffix("°")
self.label_9.setText("Begin")
self.label_10.setText("End")
self.CH_B_E_Angle.setText("Ch.")
self.CH_Cone.setText("Spring conical")
self.groupBox_2.setTitle("Coil special length")
self.label_7.setText("Pitch of coil")
self.label_7.setToolTip(_fromUtf8("Pitch of coil"))
self.PU_Accept_Value.setText("Accept the value modified")
self.textEdit.setText("")
self.PU_Reset.setText("Reset")

def on_PU_Reset(self, zero = 0): # Reset 0=Reset total 1=Reset mise a jour
global numberSpires
global rayon
global pas
global precision
global typeLine
global affPoint
global helixS
global numberSpiresModified
global pasSpire
global radiusS
global rayonSpire
global affPoint
global debutAngle
global finAngle
global modifyAngle
global radius_2_Cone
global spireConeUne
global spireConeComp
global spireReverse
if zero == 0: # Reset total
numberSpires = 10
rayon = 20.0
pas = 15.0
precision = 5.0
typeLine = 0
affPoint = 0
helixS = 0.0
numberSpiresModified = 1
pasSpire = 0 #pas
rayonSpire = 0 #rayon
modifyAngle = 0
radius_2_Cone = rayon
# App.Console.PrintMessage(str("on_PU_Reset T")+"\n")

self.DS_Numb_Spires.setValue(numberSpires)
self.DS_Radius_Sping.setValue(rayon)
self.DS_Pas_Spring.setValue(pas)
self.DS_Precision_Turn.setValue(precision)
self.DS_Precision_Turn.setEnabled(True)
self.label_2.setText("Number of coil")

self.CH_B_E_Angle.setChecked(False)
self.S_Begin_Angle.setEnabled(False)
debutAngle = 0
self.S_Begin_Angle.setValue(debutAngle)
self.S_End_Angle.setEnabled(False)
finAngle = 360
self.S_End_Angle.setValue(finAngle)
modifyAngle = 0

self.CH_Points.setChecked(False)
affPoint = 0
self.CH_Reverse.setChecked(False)
spireReverse = 0

self.S_Numbering_Spire.setValue(numberSpiresModified)
self.DS_Pas_Spire.setValue(0) #pas
self.DS_Radius_Spire.setValue(0) #rayon
self.textEdit.setText("")
self.textEdit.clear()

helixS = []
del helixS[:]
helixS = numberSpires*[pas]
radiusS = []
del radiusS[:]
radiusS = numberSpires*[rayon]

self.CH_Cone.setChecked(False)
self.DS_Radius_2_Cone.setValue(rayon)
self.DS_Radius_2_Cone.setEnabled(False)
spireConeUne = 0
spireConeComp = 0
# App.Console.PrintMessage(str("on_PU_Reset ")+"\n")

def on_DS_Numb_Spires(self,value): # nombre de spire total
global pas
global numberSpires
global helixS
global radiusS
numberSpires = value
a = ui
a.on_PU_Reset(1)
self.S_Numbering_Spire.setToolTip(_fromUtf8("Numbering of coil for 1 to max = Number of spires ("+str(numberSpires)+")"))
# App.Console.PrintMessage(str("on_DS_Numb_Spires ")+str(numberSpires)+"\n")

def on_DS_Radius_Sping(self,value): # rayon axial du ressort
global rayon
rayon = value
a = ui
a.on_PU_Reset(1)
# App.Console.PrintMessage(str("on_DS_Radius_Sping ")+str(rayon)+"\n")

def on_DS_Pas_Spring(self,value): # pas (pitch) du ressort
global pas
global numberSpires
global helixS
global numberSpiresModified
global pasSpire
global radiusS
pas = value
a = ui
a.on_PU_Reset(1)
# App.Console.PrintMessage(str("on_DS_Pas_Spring ")+str(pas)+"\n")

def on_DS_Precision_Turn(self,value): # " ! float " 360/precision number points for 1 turn
global precision
precision = value
self.label_5.setText(_fromUtf8("Precision = " + str(360/precision) + " points"))
# App.Console.PrintMessage(str("on_DS_Precision_Turn ")+str(precision)+"\n")

def on_S_Begin_Angle(self,value): #
global debutAngle
debutAngle = value
# App.Console.PrintMessage(str("on_S_Begin_Angle ")+str(debutAngle)+"\n")

def on_S_End_Angle(self,value): #
global finAngle
finAngle = value
# App.Console.PrintMessage(str("on_S_End_Angle ")+str(finAngle)+"\n")

def on_CH_B_E_Angle(self): #
global debutAngle
global finAngle
global modifyAngle
global precision
if self.CH_B_E_Angle.isChecked():
modifyAngle = 1
self.S_Begin_Angle.setEnabled(True)
self.S_End_Angle.setEnabled(True)
precision = 1
self.label_5.setText(_fromUtf8("Precision = " + str(360/precision) + " points"))
self.DS_Precision_Turn.setValue(precision)
# self.DS_Precision_Turn.setEnabled(False)
self.DS_Precision_Turn.setEnabled(True)
else:
modifyAngle = 0
self.DS_Precision_Turn.setEnabled(True)
self.S_Begin_Angle.setEnabled(False)
self.S_End_Angle.setEnabled(False)
self.CH_B_E_Angle.setChecked(False)
self.S_Begin_Angle.setEnabled(False)
debutAngle = 0
self.S_Begin_Angle.setValue(debutAngle)
self.S_End_Angle.setEnabled(False)
finAngle = 360
self.S_End_Angle.setValue(finAngle)
# App.Console.PrintMessage(str("CB_B_E_Angle ")+"\n")

def on_RA_Wire(self): #
global typeLine
typeLine = 1
# App.Console.PrintMessage(str("on_RA_Wire ")+str(typeLine)+"\n")

def on_RA_BSpline(self): #
global typeLine
typeLine = 0
# App.Console.PrintMessage(str("on_RA_BSpline ")+str(typeLine)+"\n")

def on_CH_Points(self): #
global affPoint
if self.CH_Points.isChecked():
affPoint = 1
else:
affPoint = 0
# App.Console.PrintMessage(str("on_CH_Points ")+"\n")

def on_CH_Reverse(self): #
global spireReverse
if self.CH_Reverse.isChecked():
spireReverse = 1
else:
spireReverse = 0
# App.Console.PrintMessage("on_CH_Reverse " + str(spireReverse)+"\n")

def on_DS_Radius_2_Cone(self,value): # Diametre num 2 , Helix Conique
global rayon
global numberSpires
global helixS
global radiusS
global radius_2_Cone
global spireConeUne
global helixS
global radiusS
global spireConeComp

if self.CH_Cone.isChecked():
numberSpires = self.DS_Numb_Spires.value()

numberSpires += 1
helixS = []
del helixS[:]
helixS = (numberSpires)*[pas]
radiusS = []
del radiusS[:]
radiusS = (numberSpires)*[rayon]

if value < rayon:
radius_2_Cone = value = rayon
radius_2_Cone = value
self.DS_Radius_2_Cone.setValue(radius_2_Cone)
if numberSpires != 1:
spireConeUne = 0
cone = (radius_2_Cone - rayon) / (numberSpires -1)# +1
for i in range(numberSpires):
radiusS[i] = rayon + (cone * (i)) #
else:
spireConeUne = 1
spireConeComp = 1
# App.Console.PrintMessage(str("on_DS_Radius_2_Cone ")+str(radius_2_Cone)+" "+str(spireConeUne)+"\n")

def on_CH_Cone(self): # Cone
global radius_2_Cone
global rayon
if self.CH_Cone.isChecked():
self.DS_Radius_2_Cone.setEnabled(True)
else:
self.DS_Radius_2_Cone.setEnabled(False)
radius_2_Cone = rayon
self.DS_Radius_2_Cone.setValue(radius_2_Cone)
# App.Console.PrintMessage(str("on_CH_Cone")+"\n")

def on_S_Numbering_Spire(self,value): # numero de la spire a modifier
# global numberSpires
global numberSpiresModified
global helixS
global radiusS
self.S_Numbering_Spire.setMaximum(numberSpires)
numberSpiresModified = value
# App.Console.PrintMessage(str("on_S_Nubering_Spire ")+str(numberSpiresModified)+"\n")

def on_DS_Pas_Spire(self,value): # pas (pitch) de la spire a modifier
global pasSpire
pasSpire = value
# App.Console.PrintMessage(str("on_DS_Pas_Spire ")+str(pasSpire)+"\n")

def on_DS_Radius_Spire(self,value): # pas (pitch) du rayon a modifier
global rayonSpire
rayonSpire = value
# App.Console.PrintMessage(str("on_DS_Pas_Spire ")+str(pasSpire)+"\n")

def on_PU_Accept_Value(self): # accepter la modification de la spire
global numberSpiresModified
global pasSpire
global rayonSpire
global helixS
global radiusS
if numberSpiresModified == 1:
helixS[0] = pasSpire
radiusS[0]= rayonSpire
self.textEdit.append("Coil number " + str(numberSpiresModified) + " = " + str(helixS[0]) + " " + str(radiusS[0]))
App.Console.PrintMessage("Coil number " + str(numberSpiresModified) + " = " + str(helixS[0]) + " " + str(radiusS[0])+"\n")
else:
helixS[numberSpiresModified-1] = pasSpire
radiusS[numberSpiresModified-1]= rayonSpire
self.textEdit.append("Coil number " + str(numberSpiresModified) + " = " + str(helixS[numberSpiresModified-1]) + " " + str(radiusS[numberSpiresModified-1]))
App.Console.PrintMessage("Coil number " + str(numberSpiresModified) + " = " + str(helixS[numberSpiresModified-1]) + " " + str(radiusS[numberSpiresModified-1])+"\n")
# App.Console.PrintMessage(str("on_PU_Accept_Value ")+"\n")

def on_PU_Quit(self): # Quit
App.Console.PrintMessage("\n"+"Fin FCSpring_Helix_Variable"+"\n"+"___________________________"+"\n")
self.window.hide()
# App.Console.PrintMessage(str(" ")+str()+"\n")

def on_PU_Read(self): # lecture
global path
global numberSpires
global rayon
global pas
global precision
global typeLine
global affPoint
global helixS
global radiusS
global debutAngle
global finAngle
global modifyAngle
global radius_2_Cone
global spireConeUne
global spireConeComp
global spireReverse

OpenName = ""
try:
OpenName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Read a file FCSpring"),path,"*.FCSpring") # PyQt4
except Exception:
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Read a file FCSpring", path, "*.FCSpring")#PySide
try:
if OpenName != "":
try:
file = open(OpenName, "r") # read
Header = file.readline().rstrip('\n\r') #1
if (Header == "FCString2") or (Header == "FCString") or (Header == "FCString3"):
a = ui
a.on_PU_Reset(0)
App.Console.PrintMessage("____________________"+"\n")

self.textEdit.clear()
App.Console.PrintMessage(str(Header)+"\n")
numberSpires = file.readline().rstrip('\n\r') # 2
numberSpires = int(numberSpires)
self.DS_Numb_Spires.setValue(numberSpires)
App.Console.PrintMessage(str(numberSpires)+"\t"+"Number coil"+"\n")

rayon = file.readline().rstrip('\n\r') # 3
rayon = float(rayon)
radiusS = numberSpires*[rayon]
self.DS_Radius_Sping.setValue(rayon)
App.Console.PrintMessage(str(rayon)+"\t"+"Radius"+"\n")

pas = file.readline().rstrip('\n\r') # 4
pas = float(pas)
helixS = numberSpires*[pas]
self.DS_Pas_Spring.setValue(pas)
App.Console.PrintMessage(str(pas)+"\t"+"Pitch"+"\n")

precision = file.readline().rstrip('\n\r') # 5
precision = float(precision)
self.DS_Precision_Turn.setValue(precision)
App.Console.PrintMessage(str(precision)+"\t"+"Precision"+"\n")

if (Header == "FCString3"):
typeLine, spireReverse = file.readline().rstrip(',\n\r').split() # 6
spireReverse = int(spireReverse)
if spireReverse == 0:
self.CH_Reverse.setChecked(False)
else:
self.CH_Reverse.setChecked(True)
else:
typeLine = file.readline().rstrip('\n\r')

typeLine = int(typeLine)
if typeLine == 0:
self.RA_BSpline.setChecked(True)
else:
self.RA_Wire.setChecked(True)
if (Header == "FCString2") or (Header == "FCString3"):
self.CH_Points.setChecked(False) # reset point
affPoint = 0

debutAngle = int(file.readline().rstrip('\n\r')) # 7
self.S_Begin_Angle.setValue(int(debutAngle))

finAngle = int(file.readline().rstrip('\n\r')) # 8
self.S_End_Angle.setValue(int(finAngle))

modifyAngle = int(file.readline().rstrip('\n\r')) # 9
if modifyAngle == 1:
self.CH_B_E_Angle.setChecked(True)
else:
self.CH_B_E_Angle.setChecked(False)
a = ui
a.on_CH_B_E_Angle()
try:
sp, sc, ra = file.readline().rstrip(',\n\r').split() # 10
spireConeUne = int(sp) # cone
spireConeComp = int(sc) # compensation
radius_2_Cone = float(ra) # radius 2 cone
except Exception:
spireConeUne = 0
spireConeComp = 0
radius_2_Cone = 0

if (spireConeUne == 1) or (spireConeComp == 1):
self.DS_Radius_2_Cone.setEnabled(True)
self.DS_Radius_2_Cone.setValue(radius_2_Cone)
self.CH_Cone.setChecked(True)
self.label_2.setText("Number real ("+str(numberSpires - 1)+")")
self.label_2.setToolTip(_fromUtf8("The number of coil for a spring conical registered\n"
" is number of coil displayed minus 1"))
else:
self.DS_Radius_2_Cone.setEnabled(False)
self.DS_Radius_2_Cone.setValue(rayon)
self.CH_Cone.setChecked(False)
# self.CH_Cone.setEnabled(False)
self.label_2.setText("Number of coil")
self.label_2.setToolTip(_fromUtf8("Number of coil"))
App.Console.PrintMessage(str(spireConeUne)+" "+str(radius_2_Cone)+"\t"+"Radius cone"+"\n")
dummy = file.readline().rstrip('\n\r') # 11

i = 0
for ligne in file:
a , b = ligne.rstrip('\n\r').split()
helixS[i] = float(a)
radiusS[i] = float(b)
App.Console.PrintMessage(str(i+1)+" "+str(helixS[i])+" "+str(radiusS[i])+"\n")
self.textEdit.append("Coil number " + str(i+1) + " = " + str(helixS[i]) + " " + str(radiusS[i]))
i += 1
self.textEdit.verticalScrollBar().setValue(0) #
self.textEdit.verticalScrollBar().setSliderPosition(0) #
else:
App.Console.PrintMessage("Error file not FCSpring or not FCSpring2"+"\n")
errorDialog("Error file not FCSpring or not FCSpring2 "+"\n")
finally:
file.close()
except Exception:
App.Console.PrintMessage("Error in reading the file "+OpenName+"\n")
errorDialog("Error in reading the file "+OpenName)

def on_PU_Save(self): # enregistrement
global path
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global radiusS
global debutAngle
global finAngle
global modifyAngle
global radius_2_Cone
global spireConeUne
global spireConeComp
global spireReverse

SaveName = ""
try:
SaveName = QFileDialog.getSaveFileName(None,QString.fromLocal8Bit("Save a file FCSpring"),path,"*.FCSpring") # PyQt4
except Exception:
SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Save a file FCSpring", path, "*.FCSpring") # PySide
if SaveName == "":
App.Console.PrintMessage("Process aborted"+"\n")
errorDialog("Process aborted")
else:
App.Console.PrintMessage("Registration of "+SaveName+"\n")
try:
file = open(SaveName, 'w') # write
try:
file.write("FCString3"+"\n") # 1
file.write(str(numberSpires)+"\n") # 2
file.write(str(rayon)+"\n") # 3
file.write(str(pas)+"\n") # 4
file.write(str(precision)+"\n") # 5
file.write(str(typeLine)+"\t"+str(spireReverse)+"\n") # 6
file.write(str(debutAngle)+"\n") # 7
file.write(str(finAngle)+"\n") # 8
file.write(str(modifyAngle)+"\n") # 9
file.write(str(spireConeUne)+"\t"+str(spireConeComp)+"\t"+str(radius_2_Cone)+"\n") # 10
file.write("Coil"+"\t"+"Radius"+"\t"+"(If you change the file, always use Tab no space)"+"\n") # 11
for i in range(numberSpires):
file.write(str(helixS[i])+"\t"+str(radiusS[i])+"\n")
finally:
file.close()
except Exception:
App.Console.PrintMessage("Error Registration file "+SaveName+"\n")
errorDialog("Error Registration file "+SaveName)

def on_PU_Launch(self): # Execute
global numberSpires
global rayon
global pas
global precision
global typeLine
global helixS
global pasSpire
global radiusS
global affPoint
global debutAngle
global finAngle
global modifyAngle
global radius_2_Cone
global spireConeUne
global spireConeComp
global spireReverse

doc = FreeCAD.ActiveDocument
if doc == None:
doc = FreeCAD.newDocument()

sel = FreeCADGui.Selection.getSelection()

#### Chrono begin ##################################
depart = time.clock() # chrono begin ##
####################################################

coor_X = coor_Y = coor_Z = 0.0
angleTr = 0
points = []
del points[:]
pas2 = 0.0
App.Console.PrintMessage("List Helix " + str(helixS)+"\n")
App.Console.PrintMessage("List Radius " + str(radiusS)+"\n")
App.Console.PrintMessage("___________________________"+"\n")

for spir in range(numberSpires-spireConeComp): # number spires Helix
pas2 = helixS[spir]

if spir <> numberSpires-1: # pas travail normal
pastr = ((radiusS[spir + 1]-radiusS[spir]) / (360/precision))
elif spireConeUne == 1: # cone une seule spire
pastr = (radius_2_Cone / (360/precision))
else:
pastr = 0.0

pasRadius = radiusS[spir] # pas pour le rayon
i = 0
debutAngleX = 0
finAngleX = 360

if modifyAngle == 1:
if (spir == 0) :
debutAngleX = debutAngle

if (spir == numberSpires - 1 - spireConeComp): #or (spir == numberSpires):
finAngleX = finAngle + int(precision)

for angleTr in range(0,finAngleX,int(precision)): # boucle for 1 turn (360/precision) degrees
pasRadius = radiusS[spir]+((pastr*i))
i+=1
vecligne=[FreeCAD.Vector(0,0,0),FreeCAD.Vector(pasRadius ,0.0,0.0)]
ligne = Draft.makeWire(vecligne,closed=False,face=False,support=None) #creation de la ligne de base

if spireReverse == 0: # counterclockwise
ligne.Placement = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))
else: # clockwise direction
ligne.Placement = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),-angleTr), App.Vector(0,0,0))
a = ligne.Shape.Edges[0].Vertexes[1] # fin de ligne
coor_X = (a.Point.x)
coor_Y = (a.Point.y)

if angleTr >= debutAngleX:
points += [FreeCAD.Vector(coor_X,coor_Y,coor_Z)] # coordinates makeBSpline contener

if (affPoint == 1) and (angleTr >= debutAngleX):
point = Draft.makePoint(coor_X,coor_Y,coor_Z) # create point repere for test
FreeCADGui.activeDocument().getObject(point.Name).PointColor = (1.0,0.0,0.0)

coor_Z += (pas2 / (360/precision)) # pas of spring

App.ActiveDocument.removeObject(ligne.Name) # remove ligne de base directrice


if typeLine == 1:
ressort = Draft.makeWire(points,closed=False,face=False,support=None)# creation spring makeWire
else:
# ressort = Draft.makeBSpline(points,closed=False) # creation spring Draft " makeBSpline "
ressort = Part.BSplineCurve() # creation spring Part " BSplineCurve "
ressort.interpolate(points,False)
ressort0 = Part.Edge(ressort)

Part.show(ressort0)
FreeCAD.ActiveDocument.recompute()

# pl = FreeCAD.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(1,0,0),0), App.Vector(0,0,0)) # create circle
# supp = Draft.makeCircle(rayon,placement=pl,face=True,support=None) # delete circle

#### Chrono end ####################################
arrivee = time.clock() # chrono end
App.Console.PrintMessage("Time : "+str("%.2f" % ((arrivee - depart)/60))+" min"+"\n\n") # chrono end
####################################################
helixS = []
del helixS[:]
helixS = numberSpires*[pas]
radiusS = []
del radiusS[:]
radiusS = numberSpires*[rayon]

MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()

}}

<translate>
==Examples== <!--T:18-->
==Examples== <!--T:18-->



Revision as of 19:35, 4 September 2016

File:FCSpring Helix Variable Macro FCSpring Helix Variable

Description
Creates a spring with helix variable.

Author: Mario52
Author
Mario52
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Description

This macro creates a spring with customizable, any turn may change the spring configuration can be saved in a file with the extension .FCSpring

FCSpring Helix Variable

Use

This section is used to configuration the spring

Schematic detail of spring configuration

Gui

First section, spring configuration

  • Number of coil : Total of coil to spring. Default = 10
  • Radius of spring : Radius of spring. Default = 20.0
  • Pitch of spring : Pitch of spring general. Default = 15.0
  • Precision of turn : Precision of turn the precision correspond the number of point for 1 turn the coil and is calculate : precision (number points) = (pitch / (360/precision)). Default = 5 (72 points)
  • Spring conical : Give the large diameter of the cone that dimension will always be greater than the radius
  • Begin : Begin angle of the spring first coil.
  • End : End angle of the spring last coil.
  • Ch. : Check box choice for activate the function Begin and End angle of the coil unchecked by default.
    If the function is checked The accuracy is automatically set to 1 (360 points per turn 1 point = 1 degrees)

Second section, type line

  • BSpline : Type line BSpline.
  • Wire : Type line Wire.
  • Points : Check box point if the check box is activate one point is create of on each point.
  • Reverse : Check box reverse if the check box is activate the spring changes direction

Third section, coil special length

  • Numbering of coil : Numbering of coil to modify. (Defaut : none)
  • Smoothing This checkBox discover one spinBox for determine the grade of smoothing the maximum value is the precision value -1 (this option is still at the prototype stage and the result can be satisfying or completely wrong)
  • Pitch of coil : Pitch of coil to modify. (Defaut : none)
  • 15 : If the button is pressed the value of the "Pitch of string" is affected of the "Pitch of coil" (This value is automatically aligned of the value Pitch of string)
  • Radius of coil : Radius of coil to modify. (Defaut : none)
  • 20 : If the button is pressed the value of the "Radius of string" is affected of the "Radius of coil" (This value is automatically aligned of the value Radius of string)
  • Accept the value modified : Button to accept the modification after select the numbering of coil and modify the pitch of coil.
  • Text edit : This window displayed all coil modified.

Commands

  • Load : The Read button open a dialogue box to read a file .FCSpring.
  • Save : The Save button open a dialogue box to save a file .FCSpring with configuration spring modify or not.
  • Load Coordinates : Open a dialogue box to read a file .FCSpringCoor (all coordinates of points of the spring).
  • Save Coordinates : Open a dialogue box to save a file .FCSpringCoor (all coordinates of points of the spring).
  • Quit : Quit the macro.
  • Reset : Reset the macro to default configuration.
  • Launch : Launch the macro and create the spring configured.

Report view

The window report view displayed all value modified.

Example spring

Example to spring modified

Example Report view

When the macro is launched full list of turns is displayed in tabular form.

Here the data of the spring above and displayed in the Report view


Icon

Download the file image and copy in your macro repertory.

Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."

ToolBar button

Button
Button

Macro icons

Script

Macro_FCSpring_Helix_Variable.FCMacro

Download the macro to Gist Macro_FCSpring_Helix_Variable

Examples






Links

The forum discussion Try to do a Spring

Project

soften fittings

modify diameter to any coil :done

Version

16/03/2016: ver 01.08 : correct and add "int()" to debutAngle and finAngle (read file)

02/03/2016: ver 01.07 : add option reverse spring

08/02/2016: ver 01.06 : correct bug angle cause "modifyAngle = int(file.readline().rstrip('\n\r')) # 9" modifyAngle is int() not char

07/01/2015: ver 01.05 : adding "Try ...Except" (data cone) for compatibility with old version

07/01/2015: ver 01.04 : adding spring conical and modify the path to "UserAppData" and adding the icone.

07/12/2014: ver 01.03 : new version with radius coil adjustable

17/11/2014: ver 1.02 : new version with GUI and modification any coil and save or load the data to disk.

10/11/2014: (23h20) correction of the modification

ligne.Placement = App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))

10/11/2014: modify line 44 :

a = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))

to

ligne = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(App.Vector(0,0,1),angleTr), App.Vector(0,0,0))

6/11/2014 : adding "makeBSpline" and configuration

Limitations

During sweep tests here are the mistakes I have obtained !



Other languages: