Macro FCSpring Helix Variable: Difference between revisions
Renatorivo (talk | contribs) (Marked this version for translation) |
Renatorivo (talk | contribs) mNo edit summary |
||
Line 32: | Line 32: | ||
* '''Begin''' : Begin angle of the spring first coil. |
* '''Begin''' : Begin angle of the spring first coil. |
||
* '''End''' : End angle of the spring last 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.<br |
* '''Ch.''' : Check box choice for activate the function Begin and End angle of the coil unchecked by default.<br /> If the function is checked The accuracy is automatically set to 1 (360 points per turn 1 point = 1 degrees) |
||
</translate> |
</translate> |
||
Line 951: | Line 951: | ||
</gallery> |
</gallery> |
||
</center> |
</center> |
||
<br |
<br /> |
||
<center> |
<center> |
||
<gallery widths="400" heights="200"> |
<gallery widths="400" heights="200"> |
||
Line 958: | Line 958: | ||
</gallery> |
</gallery> |
||
</center> |
</center> |
||
<br |
<br /> |
||
<center> |
<center> |
||
<gallery widths="400" heights="200"> |
<gallery widths="400" heights="200"> |
||
Line 965: | Line 965: | ||
</gallery> |
</gallery> |
||
</center> |
</center> |
||
<br |
<br /> |
||
Revision as of 22:49, 13 December 2014
File:Text-x-python Macro FCSpring Helix Variable |
Description |
---|
Creates a spring with helix variable. Author: Mario52 |
Author |
Mario52 |
Download |
None |
Links |
Macros recipes How to install macros How to customize toolbars |
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
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)
- 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.
Third section, coil special length
- Numbering of coil : Numbering of coil to modify. (Defaut : none)
- Pitch of coil : Pitch of coil to modify. (Defaut : none)
- Accept the value modified : Button to accept the modification after select the numbering of coil and modify the pitch of coil.
- Radius of coil : Radius of coil to modify. (Defaut : none)
- Text edit : This window displayed all coil modified.
Commands
- Read : 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.
- 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
Script
Macro_FCSpring_Helix_Variable.FCMacro
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
* Copyright (c) 2014 <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: 32-bit
#Version: 0.14.3700 (Git)
#Branch: releases/FreeCAD-0-14
#Hash: 32f5aae0a64333ec8d5d160dbc46e690510c8fe1
#Python version: 2.6.2
#Qt version: 4.5.2
#Coin version: 3.1.0
#SoQt version: 1.4.1
#
__title__ = "Spring_Helix_Variable"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "01.03"
__date__ = "07/12/2014"
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
from FreeCAD import Base
global path
path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
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
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
self.window = MainWindow
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(270, 560)
MainWindow.setMinimumSize(QtCore.QSize(270, 560))
MainWindow.setMaximumSize(QtCore.QSize(270, 560))
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.groupBox = QtGui.QGroupBox(self.centralWidget)
self.groupBox.setGeometry(QtCore.QRect(10, 40, 251, 231))
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(""))
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(""))
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, 170, 231, 51))
self.groupBox_3.setObjectName(_fromUtf8("groupBox_3"))
self.RA_Wire = QtGui.QRadioButton(self.groupBox_3)
self.RA_Wire.setGeometry(QtCore.QRect(90, 20, 61, 20))
self.RA_Wire.setToolTip(_fromUtf8("Type line BSpline"))
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, 71, 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(160, 20, 61, 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.S_Begin_Angle = QtGui.QSpinBox(self.groupBox)
self.S_Begin_Angle.setEnabled(False)
self.S_Begin_Angle.setGeometry(QtCore.QRect(20, 140, 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, 140, 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, 140, 41, 16))
self.label_9.setObjectName(_fromUtf8("label_9"))
self.label_10 = QtGui.QLabel(self.groupBox)
self.label_10.setGeometry(QtCore.QRect(180, 140, 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, 140, 41, 20))
self.CH_B_E_Angle.setToolTip("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.groupBox_2 = QtGui.QGroupBox(self.centralWidget)
self.groupBox_2.setGeometry(QtCore.QRect(10, 280, 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("Radiuf 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("Radiuf 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, 520, 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, 520, 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(23, 0, 280, 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(" Spring 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, 520, 71, 28))
self.PU_Reset.setToolTip(_fromUtf8("Reset 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, 490, 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, 490, 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.setWindowTitle("Spring Helix Variable")
self.groupBox.setTitle("Configure")
self.label_2.setText("Number of coil")
self.groupBox_3.setTitle("Type line BSpline")
self.RA_Wire.setToolTip("Type line Wire")
self.CH_Points.setText("Points")
self.S_Begin_Angle.setToolTip("Begin angle first coil")
self.S_Begin_Angle.setSuffix("°")
self.S_End_Angle.setToolTip("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.groupBox_2.setTitle("Coil special length")
self.label_7.setText("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
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
# 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.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.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]
# 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)
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_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
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"):
a = ui
a.on_PU_Reset(0)
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)+"\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)+"\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)+"\n")
precision = file.readline().rstrip('\n\r') # 5
precision = float(precision)
self.DS_Precision_Turn.setValue(precision)
App.Console.PrintMessage(str(precision)+"\n")
typeLine = file.readline().rstrip('\n\r') # 6
typeLine = int(typeLine)
if typeLine == 0:
self.RA_BSpline.setChecked(True)
else:
self.RA_Wire.setChecked(True)
if (Header == "FCString2"):
self.CH_Points.setChecked(False) # reset point
affPoint = 0
debutAngle = file.readline().rstrip('\n\r') # 7
self.S_Begin_Angle.setValue(int(debutAngle))
finAngle = file.readline().rstrip('\n\r') # 8
self.S_End_Angle.setValue(int(finAngle))
modifyAngle = file.readline().rstrip('\n\r') # 9
if modifyAngle == 0:
self.CH_B_E_Angle.setChecked(True)
else:
self.CH_B_E_Angle.setChecked(False)
a = ui
a.on_CH_B_E_Angle()
dummy = file.readline().rstrip('\n\r') # 10
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
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
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("FCString2"+"\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)+"\n") # 6
file.write(str(debutAngle)+"\n") # 7
file.write(str(finAngle)+"\n") # 8
file.write(str(modifyAngle)+"\n") # 9
file.write(""+"\n") # 10
file.write("Coil"+"\t"+"Radius"+"\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
doc = FreeCAD.ActiveDocument
if doc == None:
doc = FreeCAD.newDocument()
#### 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): # number spires Helix
pas2 = helixS[spir]
if spir <> numberSpires-1: # pas travail
pastr = ((radiusS[spir + 1]-radiusS[spir]) / (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): #or (spir == numberSpires):
finAngleX = finAngle + int(precision)
for angleTr in range(0,finAngleX,int(precision)): #boucle for 1 turn
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
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
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)
#### 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()
Example
Links
The forum discussion Try to do a Spring
Project
soften fittings
modify diameter to any coil :done
Version
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 !
-
ACCESS VIOLATION
-
TCollection_IndexedDataMap
-
Wrong usage of punctual sections