220 lines
11 KiB
HTML
220 lines
11 KiB
HTML
<html><head><title>Macro Image Scaling/fr</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link type='text/css' href='wiki.css' rel='stylesheet'></head><body><h1>Macro Image Scaling/fr</h1></div>
|
||
|
||
<div id="mw-content-text" lang="fr" dir="ltr" class="mw-content-ltr"><hr/><div class="mw-parser-output"><table class="fcinfobox wikitable ct" width="100%" style="float: right; width: 230px; margin-left: 10px;">
|
||
<tr>
|
||
<td class="ctTitle">
|
||
<h3><span class="mw-headline" id="Image_Scaling"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Text-x-python.png" class="image"><img alt="Text-x-python.png" src="32px-Text-x-python.png" width="32" height="32" srcset="/wiki/images/2/2c/Text-x-python.png 1.5x" /></a> Image Scaling</span></h3>
|
||
</td></tr>
|
||
<tr>
|
||
<th class="ctOdd">Description
|
||
</th></tr>
|
||
<tr>
|
||
<td class="ctEven left">Met une image à une échelle voulue
|
||
</td></tr>
|
||
<tr>
|
||
<th class="ctOdd">Auteur
|
||
</th></tr>
|
||
<tr>
|
||
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:JAndersM&action=edit&redlink=1" class="new" title="User:JAndersM (page does not exist)">JAndersM</a>
|
||
</td></tr>
|
||
<tr>
|
||
<th class="ctOdd">Liens
|
||
</th></tr>
|
||
<tr>
|
||
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/fr" title="Macros recipes/fr">Recettes macros</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/fr" title="How to install macros/fr">Comment installer une macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/fr" title="Customize Toolbars/fr">Comment ajouter une barre d'outils</a>
|
||
</td></tr>
|
||
<tr>
|
||
<th class="ctOdd">Version
|
||
</th></tr>
|
||
<tr>
|
||
<td class="ctEven macro-version">1.0
|
||
</td></tr>
|
||
<tr>
|
||
<th class="ctOdd">Date dernière modification
|
||
</th></tr>
|
||
<tr>
|
||
<td class="ctEven macro-date">2016-01-19
|
||
</td></tr>
|
||
<tr>
|
||
<th class="ctOdd">
|
||
</th></tr>
|
||
<tr>
|
||
<td class="ctToc"><br /><div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
|
||
<ul>
|
||
<li class="toclevel-1"><a href="#Image_Scaling"><span class="tocnumber">1</span> <span class="toctext">Image Scaling</span></a></li>
|
||
<li class="toclevel-1 tocsection-1"><a href="#Description"><span class="tocnumber">2</span> <span class="toctext">Description</span></a></li>
|
||
<li class="toclevel-1 tocsection-2"><a href="#Utilisation"><span class="tocnumber">3</span> <span class="toctext">Utilisation</span></a></li>
|
||
<li class="toclevel-1 tocsection-3"><a href="#Script"><span class="tocnumber">4</span> <span class="toctext">Script</span></a></li>
|
||
<li class="toclevel-1 tocsection-4"><a href="#Liens"><span class="tocnumber">5</span> <span class="toctext">Liens</span></a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
</td></tr>
|
||
</table>
|
||
<p><br />
|
||
</p>
|
||
<h2><span class="mw-headline" id="Description">Description</span></h2>
|
||
<p>Macro pour mettre facilement un dessin à bonne échelle graphiques, diagramme, blueprint, plan et des images 2D en vue de s'en servir comme patron pour pouvoir calquer le dessin avec les outils de FreeCAD. Il fonctionne avec les images importées dans l'espace 3D.
|
||
</p><p>Remarque: Pour les photos, objets ou images il faut garder à l'esprit l'effet de <a rel="nofollow" class="external text" href="https://en.wikipedia.org/wiki/Parallax">Parallaxe</a> (distorsion due à la "différence entre la position apparente d'un objet vu le long de deux lignes différentes à la vue"). Dans le schéma ci-dessous les 2 objets bleus sont coplanaires perpendiculairement au plan du point de vue de l'utilisateur et la mise à l'échelle peut être utilisée:
|
||
</p><p><a href="https://www.freecadweb.org/wiki/index.php?title=File:Perspective.png" class="image"><img alt="Perspective.png" src="Perspective.png" width="355" height="265" /></a>
|
||
</p><p>Dans le second schéma, les objets rouges et verts ne sont pas coplanaires avec les 2 objets bleus et la mise à l'échelle ne peut pas être utilisée. En outre, le fait que l'objet rouge soit co-planaire avec 1 objet bleu il ne peut être déterminé à partir du diagramme uniquement basé au point de vue de l'utilisateur:
|
||
</p><p><a href="https://www.freecadweb.org/wiki/index.php?title=File:Parallax.jpg" class="image"><img alt="Parallax.jpg" src="Parallax.jpg" width="361" height="272" /></a>
|
||
</p>
|
||
<h2><span class="mw-headline" id="Utilisation">Utilisation</span></h2>
|
||
<ul><li> activez la macro</li>
|
||
<li> cliquez deux points sur l'image jusqu’à obtenir la bonne distance recherchée</li>
|
||
<li> Sélectionnez le plan dans la vue3D (XY, XZ, YZ)</li>
|
||
<li> Dans la boîte de dialogue, entrez la bonne distance en mm entre les points et validez en cliquant sur le bouton OK</li>
|
||
<li> L'image est mise à l'échelle et la boîte de dialogue se ferme.</li></ul>
|
||
<h2><span class="mw-headline" id="Script">Script</span></h2>
|
||
<pre>import FreeCADGui, FreeCAD, Part
|
||
import math
|
||
import pivy.coin as pvy
|
||
from PySide import QtCore, QtGui
|
||
import DraftTrackers, Draft
|
||
|
||
__title__ = "Macro Image Scaling"
|
||
__author__ = "JAndersM"
|
||
__url__ = "http://www.freecadweb.org/index-fr.html"
|
||
__version__ = "00.01"
|
||
__date__ = "19/01/2016"
|
||
|
||
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 distance(p1,p2):
|
||
dx=p2[0]-p1[0]
|
||
dy=p2[1]-p1[1]
|
||
dz=p2[2]-p1[2]
|
||
return math.sqrt(dx*dx+dy*dy+dz*dz)
|
||
|
||
class Ui_Dialog(object):
|
||
def setupUi(self, Dialog):
|
||
self.view = FreeCADGui.ActiveDocument.ActiveView
|
||
self.stack = []
|
||
self.callback = self.view.addEventCallbackPivy(pvy.SoMouseButtonEvent.getClassTypeId(),self.getpoint)
|
||
self.callmouse=self.view.addEventCallbackPivy(pvy.SoLocation2Event.getClassTypeId(),self.getmousepoint)
|
||
self.distance=0
|
||
self.dialog=Dialog
|
||
Dialog.setObjectName(_fromUtf8("Dialog"))
|
||
Dialog.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
|
||
Dialog.resize(300, 102)
|
||
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
|
||
self.buttonBox.setGeometry(QtCore.QRect(50, 70, 191, 32))
|
||
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
|
||
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel.__or__(QtGui.QDialogButtonBox.Ok))
|
||
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
|
||
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
|
||
self.label = QtGui.QLabel(Dialog)
|
||
self.label.setGeometry(QtCore.QRect(30, 10, 66, 17))
|
||
self.label.setObjectName(_fromUtf8("label"))
|
||
self.lineEdit = QtGui.QLineEdit(Dialog)
|
||
self.lineEdit.setGeometry(QtCore.QRect(100, 10, 113, 29))
|
||
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
|
||
self.label1 = QtGui.QLabel(Dialog)
|
||
self.label1.setGeometry(QtCore.QRect(20, 45, 260, 17))
|
||
self.label1.setObjectName(_fromUtf8("label1"))
|
||
self.retranslateUi(Dialog)
|
||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), self.accept)
|
||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), self.reject)
|
||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||
self.tracker = DraftTrackers.lineTracker(scolor=(1,0,0))
|
||
self.tracker.raiseTracker()
|
||
self.tracker.on()
|
||
self.dialog.show()
|
||
|
||
def retranslateUi(self, Dialog):
|
||
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
|
||
self.label.setText(_translate("Dialog", "Distance", None))
|
||
self.label1.setText(_translate("Dialog", "Select first point", None))
|
||
|
||
def accept(self):
|
||
sel = FreeCADGui.Selection.getSelection()
|
||
try:
|
||
locale=QtCore.QLocale.system()
|
||
d, ok = locale.toFloat(self.lineEdit.text())
|
||
if not ok:
|
||
raise ValueError
|
||
s=d/self.distance
|
||
sel[0].XSize.Value=sel[0].XSize.Value*s
|
||
sel[0].YSize.Value=sel[0].YSize.Value*s
|
||
FreeCAD.Console.PrintMessage("Scale="+str(s))
|
||
self.tracker.off()
|
||
self.tracker.finalize()
|
||
self.dialog.hide()
|
||
except ValueError, ZeroDivisionError:
|
||
self.label1.setText(_translate("Dialog", "<font color='red'>Enter distance</font>", None))
|
||
return
|
||
except IndexError, AttributeError:
|
||
self.label1.setText(_translate("Dialog", "<font color='red'>Select ImagePlane</font>", None))
|
||
return
|
||
|
||
def reject(self):
|
||
self.stack=[]
|
||
self.view.removeEventCallbackPivy(pvy.SoMouseButtonEvent.getClassTypeId(),self.callback)
|
||
self.view.removeEventCallbackPivy(pvy.SoLocation2Event.getClassTypeId(),self.callmouse)
|
||
self.tracker.off()
|
||
self.tracker.finalize()
|
||
self.dialog.hide()
|
||
|
||
def getmousepoint(self, event_cb):
|
||
event = event_cb.getEvent()
|
||
if len(self.stack)==1:
|
||
pos = event.getPosition()
|
||
point = self.view.getPoint(pos[0],pos[1])
|
||
self.tracker.p2(point)
|
||
|
||
def getpoint(self,event_cb):
|
||
event = event_cb.getEvent()
|
||
if event.getState() == pvy.SoMouseButtonEvent.DOWN:
|
||
pos = event.getPosition()
|
||
point = self.view.getPoint(pos[0],pos[1])
|
||
self.stack.append(point)
|
||
self.label1.setText(_translate("Dialog", "Select second point", None))
|
||
if len(self.stack)==1:
|
||
self.tracker.p1(point)
|
||
elif len(self.stack) == 2:
|
||
self.distance=distance(self.stack[0], self.stack[1])
|
||
self.tracker.p2(point)
|
||
self.view.removeEventCallbackPivy(pvy.SoMouseButtonEvent.getClassTypeId(),self.callback)
|
||
self.view.removeEventCallbackPivy(pvy.SoLocation2Event.getClassTypeId(),self.callmouse)
|
||
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
|
||
self.label1.setText(_translate("Dialog", "Select Image Plane and type distance", None))
|
||
|
||
#Init
|
||
d = QtGui.QWidget()
|
||
ui = Ui_Dialog()
|
||
ui.setupUi(d) </pre>
|
||
<h2><span class="mw-headline" id="Liens">Liens</span></h2>
|
||
<ul><li> [<a rel="nofollow" class="external text" href="http://forum.freecadweb.org/viewtopic.php?f=22&t=13877">Forum discussion</a>]</li>
|
||
<li> [<a rel="nofollow" class="external text" href="http://forum.freecadweb.org/download/file.php?id=19542">téléchargez le zip</a>]</li>
|
||
<li> [<a rel="nofollow" class="external text" href="https://youtu.be/2iFE40uHrA8">Movie created by microelly2</a>]</li></ul>
|
||
<p><br />
|
||
</p>
|
||
<div style="clear:both"></div>
|
||
</div>
|
||
|
||
|
||
|
||
</div>
|
||
|
||
</div><div class="printfooter">
|
||
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_Image_Scaling/fr&oldid=282117">http://www.freecadweb.org/wiki/index.php?title=Macro_Image_Scaling/fr&oldid=282117</a>"</div>
|
||
<div id="catlinks" class="catlinks" data-mw="interface"></div><div class="visualClear"></div>
|
||
</div>
|
||
</div>
|
||
<div id="mw-navigation">
|
||
<h2>Navigation menu</h2>
|
||
|
||
</body></html> |