commit calepinage (start)

This commit is contained in:
Thomas-Alexandre Moreau 2025-01-27 18:09:49 +01:00
parent 4c05d377d3
commit 840ab3c9dc
2 changed files with 237 additions and 0 deletions

96
Calepinage.FCMacro Normal file
View file

@ -0,0 +1,96 @@
import importSVG
import FreeCAD
import FreeCADGui
import Draft
import os
class WindowDialog():
def __init__(self):
self.ui_file = os.path.join(FreeCAD.getUserMacroDir(True), 'Calepinage/Calepinage.ui')
self.form = FreeCADGui.PySideUic.loadUi(self.ui_file)
self._connect_widgets()
self.form.show()
def _connect_widgets(self):
self.form.pushButtonSVG.pressed.connect(lambda: self.export(False))
self.form.pushButtonCalepinage.pressed.connect(lambda: self.export(True))
# -------- MODIFICATION DE LA MACRO "exportSketchEnMasse-SVG" de Gauthier Brière -------- #
def _exportSketchBasic(self, sketchList):
outputRacine = App.activeDocument().getFileName().rpartition('.')[0]
for __O__ in sketchList:
__obj__ = []
__obj__.append(__O__)
print('Export SVG de : ' + __obj__[0].Label)
oldPlace = __obj__[0].Placement
__obj__[0].Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(1,0,0),0), App.Vector(0,0,0))
fichierSVG = u"" + outputRacine + '--' + __obj__[0].Label + '.svg'
importSVG.export(__obj__, fichierSVG)
__obj__[0].Placement = oldPlace
App.ActiveDocument.removeObject(__O__.Label)
App.activeDocument().recompute()
def _exportSketchCalepinage(self, sketchList, plateLength, plateWidth, spacing, laserSize):
outputRacine = App.activeDocument().getFileName().rpartition('.')[0]
__obj__ = []
for __O__ in sketchList:
__obj__.append(__O__)
print('Export SVG de : ' + __obj__[0].Label)
oldPlace = __obj__[0].Placement
__obj__[0].Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(1,0,0),0), App.Vector(0,0,0))
fichierSVG = u"" + outputRacine + '--' + __obj__[0].Label + '.svg'
importSVG.export(__obj__, fichierSVG)
__obj__[0].Placement = oldPlace
App.ActiveDocument.removeObject(__O__.Label)
print('Export SVG de : ' + __obj__[0].Label)
importSVG.export(__obj__, fichierSVG)
App.activeDocument().recompute()
# -------- END -------- #
# -------- MODIFICATION DE MA MACRO "QuickSVGExport" -------- #
def export(self, isCalepinage):
plateLength = self.form.doubleSpinBoxLength.value()
plateWidth = self.form.doubleSpinBoxWidth.value()
spacing = self.form.doubleSpinBoxSpacing.value()
laserSize = self.form.doubleSpinBoxLaserSize.value()
sketchList = []
for selectedObject in FreeCADGui.Selection.getSelectionEx():
try:
if hasattr(selectedObject.Object, 'Dir'):
sv0 = Draft.make_shape2dview(selectedObject.Object, FreeCAD.Vector(selectedObject.Object.Dir))
elif hasattr(selectedObject.Object, 'Objects'):
for child in selectedObject.Object.Objects:
if hasattr(child, 'Dir'):
sv0 = Draft.make_shape2dview(selectedObject.Object, FreeCAD.Vector(child.Dir))
break
print("FAILURE IF")
FreeCAD.ActiveDocument.recompute()
sk = Draft.make_sketch(sv0, autoconstraints=True)
sk.ViewObject.LineColor = (1.0, 0.0, 0.0)
FreeCAD.ActiveDocument.recompute()
sketchList.append(sk)
if hasattr(sv0, 'Name'):
App.ActiveDocument.removeObject(sv0.Name)
except:
print("FAILURE TRY")
if isCalepinage:
self._exportSketchCalepinage(sketchList, plateLength, plateWidth, spacing, laserSize)
else:
self._exportSketchBasic(sketchList)
# -------- END -------- #
if __name__ == '__main__':
d = WindowDialog()

141
Calepinage/Calepinage.ui Normal file
View file

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Calepinage</class>
<widget class="QWidget" name="Dialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Calepinage</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="locale">
<locale language="French" country="France"/>
</property>
<property name="text">
<string notr="true">Longueur du plateau (mm) :</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLength">
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>50.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label2">
<property name="text">
<string notr="true">Largeur du plateau (mm) :</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxWidth">
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>50.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label3">
<property name="text">
<string notr="true">Espacement (mm) :</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxSpacing">
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>5.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label4">
<property name="text">
<string notr="true">Epaisseur du laser (mm) :</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLaserSize">
<property name="maximum">
<double>999999.000000000000000</double>
</property>
<property name="value">
<double>5.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pushButtonCalepinage">
<property name="text">
<string>Calepinage</string>
</property>
<property name="alignment">
<set>Qt::AlignVCenter</set>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="pushButtonSVG">
<property name="text">
<string>Export en .svg
(sans calepinage)</string>
</property>
<property name="alignment">
<set>Qt::AlignVCenter</set>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>