FreeCAD-Doc/localwiki/Macro_Select_Hovering-it.html
2018-07-19 18:47:02 -05:00

446 lines
21 KiB
HTML

<html><head><title>Macro Select Hovering/it</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 Select Hovering/it</h1></div>
<div id="mw-content-text" lang="it" 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="Macro_Select_Hovering"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Select_Hovering.png" class="image"><img alt="Macro Select Hovering.png" src="32px-Macro_Select_Hovering.png" width="32" height="32" srcset="/wiki/images/thumb/d/d8/Macro_Select_Hovering.png/48px-Macro_Select_Hovering.png 1.5x, Macro_Select_Hovering.png 2x" /></a> Macro Select Hovering</span></h3>
</td></tr>
<tr>
<th class="ctOdd">Descrizione
</th></tr>
<tr>
<td class="ctEven left">Questa macro seleziona a scelta una Faccia, Bordo, Vertice passando il mouse.
</td></tr>
<tr>
<th class="ctOdd">Autore
</th></tr>
<tr>
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:Mario52" title="User:Mario52">Mario52</a>
</td></tr>
<tr>
<th class="ctOdd">Link
</th></tr>
<tr>
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/it" title="Macros recipes/it">Esempi di macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/it" title="How to install macros/it">Come installare le Macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/it" title="Customize Toolbars/it">Personalizzare la barra degli strumenti</a>
</td></tr>
<tr>
<th class="ctOdd">Versione
</th></tr>
<tr>
<td class="ctEven macro-version">00.03
</td></tr>
<tr>
<th class="ctOdd">Data ultima modifica
</th></tr>
<tr>
<td class="ctEven macro-date">2017-12-26
</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="#Macro_Select_Hovering"><span class="tocnumber">1</span> <span class="toctext">Macro Select Hovering</span></a></li>
<li class="toclevel-1 tocsection-1"><a href="#Descrizione"><span class="tocnumber">2</span> <span class="toctext">Descrizione</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Utilizzo"><span class="tocnumber">3</span> <span class="toctext">Utilizzo</span></a>
<ul>
<li class="toclevel-2 tocsection-3"><a href="#Icone"><span class="tocnumber">3.1</span> <span class="toctext">Icone</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-4"><a href="#Script"><span class="tocnumber">4</span> <span class="toctext">Script</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#Versioni"><span class="tocnumber">5</span> <span class="toctext">Versioni</span></a></li>
</ul>
</div>
</td></tr>
</table><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Select_Hovering_00.png" class="image" title="Macro Select Hovering"><img alt="Macro Select Hovering" src="Macro_Select_Hovering_00.png" width="199" height="339" /></a>
<h2><span class="mw-headline" id="Descrizione">Descrizione</span></h2>
<p>Questa macro seleziona a scelta una Faccia, Bordo, Vertice passando sopra con il mouse
</p><p>PS: Per deselezionare una faccia (o altro) cliccare <span style="background: #DDDDDD; border: 1px solid #888888; padding: 0px 5px 1px 5px;"> Pause grab</span> e usare la procedura standard: CTRL + Click
</p>
<h2><span class="mw-headline" id="Utilizzo">Utilizzo</span></h2>
<p>Passare sopra agli elementi con il mouse
</p>
<h3><span class="mw-headline" id="Icone">Icone</span></h3>
<p>L'icona deve essere copiata nella stessa directory della macro
</p>
<h2><span class="mw-headline" id="Script">Script</span></h2>
<p>L'icona per la barra degli strumenti <a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Select_Hovering.png" class="image" title="Macro Select Hovering"><img alt="Macro Select Hovering" src="Macro_Select_Hovering.png" width="64" height="64" /></a>
</p><p><b>Macro Select Hovering.FCMacro</b>
</p>
<pre># -*- coding: utf-8 -*-
from __future__ import unicode_literals
#
"""
***************************************************************************
* Copyright (c) 2017 &lt;mario52&gt; *
* *
* 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 *
***************************************************************************
"""
#
#Macro_ _01-25/12/2017 02-26/12/2017 03-26/12/2017
#
#OS: Windows 10
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.16.6712 (Git)
#Build type: Release
#Branch: releases/FreeCAD-0-16
#Hash: da2d364457257a7a8c6fb2137cea12c45becd71a
#Python version: 2.7.8
#Qt version: 4.8.7
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#
__title__ = "Macro_Select_Hovering"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__Wiki__ = "http://www.freecadweb.org/wiki/index.php?title=Macro_Select_Hovering"
__version__ = "00.03"
__date__ = "26/12/2017"
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
import Draft, Part, PartGui, FreeCADGui, FreeCAD
Gui = FreeCADGui
App = FreeCAD
global ui &#160;; ui = ""
global s &#160;; s = ""
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)
class Ui_MainWindow(object):
def __init__(self, MainWindow):
self.window = MainWindow
#################################################################################
#self.path = FreeCAD.ConfigGet("AppHomePath")
#self.path = FreeCAD.ConfigGet("UserAppData")
#self.path = "your path"
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
self.path = param.GetString("MacroPath","") + "/" # macro path
self.path = self.path.replace("\\","/")
# print "Path for the icons&#160;: " , self.path
#################################################################################
self.FontImpost = "Arial"
self.fontGlobal_08 = QtGui.QFont() # pour compatibilite Windows Linux
self.fontGlobal_08.setFamily(self.FontImpost) # pour compatibilite Windows Linux
self.fontGlobal_08.setPointSize(8.0) # pour compatibilite Windows Linux
#self.xxxx.setFont(self.fontGlobal_08) # pour W L
#self.xxxx.setFont(QtGui.QFont(self.FontImpost,weight=QtGui.QFont.Bold)) # Bold
#################################################################################
self.comptFace = 0
self.comptEdge = 0
self.comptVertex = 0
self.Stop_Grab = 1
self.comptSurfaceFace = 0.0
self.comptSurfaceTotal = 0.0
self.comptLengthObject = 0.0
self.comptLengthTotal = 0.0
def setupUi(self, MainWindow):
MainWindow.resize(197, 307)
MainWindow.setMinimumSize(QtCore.QSize(197, 307))
MainWindow.setMaximumSize(QtCore.QSize(197, 307))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.GBOX_01_Face = QtGui.QGroupBox(self.centralwidget)
self.GBOX_01_Face.setGeometry(QtCore.QRect(10, 10, 176, 91))
self.GBOX_01_Face.setFont(self.fontGlobal_08) # pour W L
self.GBOX_01_Face.setObjectName(_fromUtf8("GBOX_01_Face"))
self.LE_02_Area_Object = QtGui.QLineEdit(self.GBOX_01_Face)
self.LE_02_Area_Object.setGeometry(QtCore.QRect(90, 60, 75, 20))
self.LE_02_Area_Object.setFont(self.fontGlobal_08) # pour W L
self.LE_02_Area_Object.setObjectName(_fromUtf8("LE_02_Area_Object"))
self.LAB_05_Area_Object = QtGui.QLabel(self.GBOX_01_Face)
self.LAB_05_Area_Object.setGeometry(QtCore.QRect(90, 40, 71, 16))
self.LAB_05_Area_Object.setFont(self.fontGlobal_08) # pour W L
self.LAB_05_Area_Object.setObjectName(_fromUtf8("LAB_05_Area_Object"))
self.CB_01_Sel_Face = QtGui.QCheckBox(self.GBOX_01_Face)
self.CB_01_Sel_Face.setGeometry(QtCore.QRect(10, 20, 91, 17))
self.CB_01_Sel_Face.setFont(self.fontGlobal_08) # pour W L
self.CB_01_Sel_Face.setObjectName(_fromUtf8("CB_01_Sel_Face"))
self.LE_01_Area_Total = QtGui.QLineEdit(self.GBOX_01_Face)
self.LE_01_Area_Total.setGeometry(QtCore.QRect(10, 60, 75, 20))
self.LE_01_Area_Total.setFont(self.fontGlobal_08) # pour W L
self.LE_01_Area_Total.setObjectName(_fromUtf8("LE_01_Area_Total"))
self.LAB_01_Face = QtGui.QLabel(self.GBOX_01_Face)
self.LAB_01_Face.setGeometry(QtCore.QRect(110, 23, 56, 16))
self.LAB_01_Face.setFont(self.fontGlobal_08) # pour W L
self.LAB_01_Face.setObjectName(_fromUtf8("LAB_01_Face"))
self.LAB_04_Area_Total = QtGui.QLabel(self.GBOX_01_Face)
self.LAB_04_Area_Total.setGeometry(QtCore.QRect(10, 40, 56, 16))
self.LAB_04_Area_Total.setFont(self.fontGlobal_08) # pour W L
self.LAB_04_Area_Total.setObjectName(_fromUtf8("LAB_04_Area_Total"))
self.GBOX_02_Edge = QtGui.QGroupBox(self.centralwidget)
self.GBOX_02_Edge.setGeometry(QtCore.QRect(10, 105, 176, 91))
self.GBOX_02_Edge.setFont(self.fontGlobal_08) # pour W L
self.GBOX_02_Edge.setObjectName(_fromUtf8("GBOX_02_Edge"))
self.LAB_02_Edge = QtGui.QLabel(self.GBOX_02_Edge)
self.LAB_02_Edge.setGeometry(QtCore.QRect(110, 25, 56, 16))
self.LAB_02_Edge.setFont(self.fontGlobal_08) # pour W L
self.LAB_02_Edge.setObjectName(_fromUtf8("LAB_02_Edge"))
self.CB_02_Sel_Edge = QtGui.QCheckBox(self.GBOX_02_Edge)
self.CB_02_Sel_Edge.setGeometry(QtCore.QRect(10, 20, 91, 17))
self.CB_02_Sel_Edge.setFont(self.fontGlobal_08) # pour W L
self.CB_02_Sel_Edge.setObjectName(_fromUtf8("CB_02_Sel_Edge"))
self.LE_03_Length_Total = QtGui.QLineEdit(self.GBOX_02_Edge)
self.LE_03_Length_Total.setGeometry(QtCore.QRect(10, 60, 75, 20))
self.LE_03_Length_Total.setFont(self.fontGlobal_08) # pour W L
self.LE_03_Length_Total.setObjectName(_fromUtf8("LE_03_Length_Total"))
self.LE_04_Length_Object = QtGui.QLineEdit(self.GBOX_02_Edge)
self.LE_04_Length_Object.setGeometry(QtCore.QRect(90, 60, 75, 20))
self.LE_04_Length_Object.setFont(self.fontGlobal_08) # pour W L
self.LE_04_Length_Object.setObjectName(_fromUtf8("LE_04_Length_Object"))
self.LAB_06_Length_Total = QtGui.QLabel(self.GBOX_02_Edge)
self.LAB_06_Length_Total.setGeometry(QtCore.QRect(10, 40, 71, 16))
self.LAB_06_Length_Total.setFont(self.fontGlobal_08) # pour W L
self.LAB_06_Length_Total.setObjectName(_fromUtf8("LAB_06_Length_Total"))
self.LAB_07_Length_Obgect = QtGui.QLabel(self.GBOX_02_Edge)
self.LAB_07_Length_Obgect.setGeometry(QtCore.QRect(90, 40, 71, 16))
self.LAB_07_Length_Obgect.setFont(self.fontGlobal_08) # pour W L
self.LAB_07_Length_Obgect.setObjectName(_fromUtf8("LAB_07_Length_Obgect"))
self.GBOX_03_Vertex = QtGui.QGroupBox(self.centralwidget)
self.GBOX_03_Vertex.setGeometry(QtCore.QRect(10, 200, 176, 46))
self.GBOX_03_Vertex.setFont(self.fontGlobal_08) # pour W L
self.GBOX_03_Vertex.setObjectName(_fromUtf8("GBOX_03_Vertex"))
self.LAB_03_Vertex = QtGui.QLabel(self.GBOX_03_Vertex)
self.LAB_03_Vertex.setGeometry(QtCore.QRect(110, 25, 56, 16))
self.LAB_03_Vertex.setFont(self.fontGlobal_08) # pour W L
self.LAB_03_Vertex.setObjectName(_fromUtf8("LAB_03_Vertex"))
self.CB_03_Sel_Vertex = QtGui.QCheckBox(self.GBOX_03_Vertex)
self.CB_03_Sel_Vertex.setGeometry(QtCore.QRect(10, 22, 91, 17))
self.CB_03_Sel_Vertex.setFont(self.fontGlobal_08) # pour W L
self.CB_03_Sel_Vertex.setObjectName(_fromUtf8("CB_03_Sel_Vertex"))
self.GBOX_04_Main = QtGui.QGroupBox(self.centralwidget)
self.GBOX_04_Main.setGeometry(QtCore.QRect(10, 250, 176, 51))
self.GBOX_04_Main.setFont(self.fontGlobal_08) # pour W L
self.GBOX_04_Main.setObjectName(_fromUtf8("GBOX_04_Main"))
self.PB_02_Stop_Grab = QtGui.QPushButton(self.GBOX_04_Main)
self.PB_02_Stop_Grab.setGeometry(QtCore.QRect(90, 20, 75, 23))
self.PB_02_Stop_Grab.setFont(self.fontGlobal_08) # pour W L
self.PB_02_Stop_Grab.setObjectName(_fromUtf8("PB_02_Stop_Grab"))
self.PB_02_Stop_Grab.clicked.connect(self.on_PB_02_Stop_Grab_clicked)
self.PB_01_Quit = QtGui.QPushButton(self.GBOX_04_Main)
self.PB_01_Quit.setGeometry(QtCore.QRect(5, 20, 75, 23))
self.PB_01_Quit.setFont(self.fontGlobal_08) # pour W L
self.PB_01_Quit.setObjectName(_fromUtf8("PB_01_Quit"))
self.PB_01_Quit.clicked.connect(self.on_PB_Quit_clicked)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle("Select_Hovering")
MainWindow.setWindowIcon(QtGui.QIcon(self.path + __title__ +".png"))#
self.GBOX_01_Face.setTitle("Face")
self.CB_01_Sel_Face.setText("Select Face")
self.LAB_01_Face.setText("0")
self.LAB_04_Area_Total.setText("Area Total")
self.LAB_05_Area_Object.setText("Area Object")
self.GBOX_02_Edge.setTitle("Edge")
self.CB_02_Sel_Edge.setText("Select Edge")
self.LAB_02_Edge.setText("0")
self.LAB_06_Length_Total.setText("Length Total")
self.LAB_07_Length_Obgect.setText("Length Object")
self.GBOX_03_Vertex.setTitle("Vertex")
self.CB_03_Sel_Vertex.setText("Select Vertex")
self.LAB_03_Vertex.setText("0")
self.GBOX_04_Main.setTitle("Main")
self.PB_01_Quit.setText("Quit")
self.PB_02_Stop_Grab.setText("Pause grab")
MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant
def on_PB_02_Stop_Grab_clicked(self):
global s
if self.Stop_Grab == 1:
FreeCADGui.Selection.removeObserver(s) # desinstalle la fonction residente SelObserver
self.Stop_Grab = 0
self.PB_02_Stop_Grab.setText("Active grab")
print "Grab pause"
else:
s=SelObserver()
FreeCADGui.Selection.addObserver(s) # installe la fonction en mode resident
self.Stop_Grab = 1
self.PB_02_Stop_Grab.setText("Pause grab")
print "Grab active"
def on_PB_Quit_clicked(self):
global s
FreeCADGui.Selection.removeObserver(s) # desinstalle la fonction residente SelObserver
self.window.hide() # hide the window and close the macro
print "Quit ",__title__
##################################################################################################
class SelObserver:
global ui
def setPreselection(self,doc,obj,sub): # preselection
global ui
if ui.CB_01_Sel_Face.isChecked():
if (sub[:4] == "Face") and (Gui.Selection.isSelected (FreeCAD.ActiveDocument.getObject(obj), sub) == False):
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub)
ui.comptFace += 1
ui.LAB_01_Face.setText(str(ui.comptFace))
ui.comptSurfaceFace = FreeCAD.ActiveDocument.getObject(obj).Shape.Faces[int(sub[4:])-1].Area
ui.comptSurfaceTotal += ui.comptSurfaceFace
ui.LE_01_Area_Total.setText(str(ui.comptSurfaceTotal))
ui.LE_02_Area_Object.setText(str(ui.comptSurfaceFace))
if ui.CB_02_Sel_Edge.isChecked():
if (sub[:4] == "Edge") and (Gui.Selection.isSelected (FreeCAD.ActiveDocument.getObject(obj), sub) == False):
objetSelect = Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub)
ui.comptEdge += 1
ui.LAB_02_Edge.setText(str(ui.comptEdge))
ui.comptLengthObject = FreeCAD.ActiveDocument.getObject(obj).Shape.Edges[int(sub[4:])-1].Length
ui.comptLengthTotal += ui.comptLengthObject
ui.LE_03_Length_Total.setText(str(ui.comptLengthTotal))
ui.LE_04_Length_Object.setText(str(ui.comptLengthObject))
if ui.CB_03_Sel_Vertex.isChecked():
if sub[:6] == "Vertex" and (Gui.Selection.isSelected (FreeCAD.ActiveDocument.getObject(obj), sub) == False):
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub)
ui.comptVertex += 1
ui.LAB_03_Vertex.setText(str(ui.comptVertex))
# def removePreselection(self,doc,obj,sub) #
# print "removePreselection"
# def addSelection(self,doc,obj,sub,pnt): # Selection
# print "addSelection"
# def removeSelection(self,doc,obj,sub): # Effacer l'objet selectionne
# print "removeSelection"
# def setSelection(self,doc): # Selection dans ComboView
# FreeCADGui.Selection.removeObserver(s)
# print "setSelection quit"
def clearSelection(self,doc): # Si clic sur l'ecran, effacer la selection
global ui
ui.comptFace = 0
ui.comptEdge = 0
ui.comptVertex = 0
ui.comptSurfaceFace = 0.0
ui.comptSurfaceTotal = 0.0
ui.comptLengthObject = 0.0
ui.comptLengthTotal = 0.0
ui.LAB_01_Face.setText(str(ui.comptFace))
ui.LAB_02_Edge.setText(str(ui.comptEdge))
ui.LAB_03_Vertex.setText(str(ui.comptVertex))
ui.LE_01_Area_Total.setText(str(ui.comptSurfaceTotal))
ui.LE_02_Area_Object.setText(str(ui.comptSurfaceFace))
ui.LE_03_Length_Total.setText(str(ui.comptLengthTotal))
ui.LE_04_Length_Object.setText(str(ui.comptLengthObject))
# print "clearSelection"
s=SelObserver()
FreeCADGui.Selection.addObserver(s) # installe la fonction en mode resident
###################################################################################################
doc = FreeCAD.ActiveDocument
if doc == None:
doc = FreeCAD.newDocument()
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow(MainWindow)
ui.setupUi(MainWindow)
MainWindow.show() </pre>
<h2><span class="mw-headline" id="Versioni">Versioni</span></h2>
<p>ver 00.03 (26/12/2017) &#160;: replace test with (FreeCAD.ActiveDocument.getObject(obj), sub) == False)
</p><p>ver 00.02 (26/12/2017) &#160;:
</p><p>ver 00.01 (25/12/2017) &#160;:
</p>
</div>
</div>
</div><div class="printfooter">
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_Select_Hovering/it&amp;oldid=262236">http://www.freecadweb.org/wiki/index.php?title=Macro_Select_Hovering/it&amp;oldid=262236</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>