Macro Select Hovering

From FreeCAD Documentation
Revision as of 20:41, 25 December 2017 by Mario52 (talk | contribs) (create page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

File:Macro Select Hovering Macro Select Hovering

Description
This macro select a choice Face, Edge, Vertex hovering by the mouse.

Macro version: 00.01
Last modified: 2017-12-25
Author: Mario52
Author
Mario52
Download
None
Links
Macro Version
00.01
Date last modified
2017-12-25
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Macro Select Hovering

Description

this macro select a choice Face, Edge, Vertex hovering by the mouse.

How To Use

Hovering element by the mouse.

Icons

The icon must be copied into the same directory as the macro

Script

For prevent many instance the clic on ToolBar button are effect flip/flop (hide/visible) The icon ToolBar Macro Select Hovering Macro Select Hovering.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
#
"""
***************************************************************************
*   Copyright (c) 2017 <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                   *
***************************************************************************
"""
#
#Macro_ 25/12/2017 /_01
#
#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.01"
__date__    = "25/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         ; ui           = ""
global s          ; 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 : " , 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.tableauSurface    = []
        self.tableauSurEdge    = []
        self.tableauSurVertex  = []

    def setupUi(self, MainWindow):
        MainWindow.resize(197, 216)
        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, 46))
        self.GBOX_01_Face.setFont(self.fontGlobal_08)        # pour W L
        self.GBOX_01_Face.setObjectName(_fromUtf8("GBOX_01_Face"))

        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.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.GBOX_02_Edge = QtGui.QGroupBox(self.centralwidget)
        self.GBOX_02_Edge.setGeometry(QtCore.QRect(10, 60, 176, 46))
        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.GBOX_03_Vertex = QtGui.QGroupBox(self.centralwidget)
        self.GBOX_03_Vertex.setGeometry(QtCore.QRect(10, 110, 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, 160, 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(str(self.comptFace))

        self.GBOX_02_Edge.setTitle("Edge")
        self.CB_02_Sel_Edge.setText("Select Edge")
        self.LAB_02_Edge.setText(str(self.comptEdge))

        self.GBOX_03_Vertex.setTitle("Vertex")
        self.CB_03_Sel_Vertex.setText("Select Vertex")
        self.LAB_03_Vertex.setText(str(self.comptVertex))

        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 résident
            self.Stop_Grab = 1
            self.PB_02_Stop_Grab.setText("Pause grab")
            print "Grab active"

    def on_PB_Quit_clicked(self):
        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): # préselection
        global ui
        #####
        if ui.CB_01_Sel_Face.isChecked():
            passFace = 1
            for i in ui.tableauSurface:
                if obj == i[0] and sub == i[1]:
                    passFace = 0
                    break

            if (sub[:4] == "Face") and (passFace == 1):
                Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub)
                ui.comptFace += 1
                ui.LAB_01_Face.setText(str(ui.comptFace))

                ui.tableauSurface.append([obj, sub])
        #####
        if ui.CB_02_Sel_Edge.isChecked():
            passEdge = 1
            for i in ui.tableauSurEdge:
                if obj == i[0] and sub == i[1]:
                    passEdge = 0
                    break

            if (sub[:4] == "Edge") and (passEdge == 1):
                Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub)
                ui.comptEdge += 1
                ui.LAB_02_Edge.setText(str(ui.comptEdge))

                ui.tableauSurEdge.append([obj, sub])
        #####
        if ui.CB_03_Sel_Vertex.isChecked():
            passVertex = 1
            for i in ui.tableauSurVertex:
                if obj == i[0] and sub == i[1]:
                    passVertex = 0
                    break

            if sub[:6] == "Vertex" and (passVertex == 1):
                Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub)
                ui.comptVertex += 1
                ui.LAB_03_Vertex.setText(str(ui.comptVertex))

                ui.tableauSurVertex.append([obj, sub])

    def clearSelection(self,doc):            # Si clic sur l'écran, éffacer la sélection
        ui.comptFace   = 0
        ui.comptEdge   = 0
        ui.comptVertex = 0
        del ui.tableauSurface[:]
        del ui.tableauSurEdge[:]
        del ui.tableauSurVertex[:]
        ui.LAB_01_Face.setText(str(ui.comptFace))
        ui.LAB_02_Edge.setText(str(ui.comptEdge))
        ui.LAB_03_Vertex.setText(str(ui.comptVertex))

s=SelObserver()
FreeCADGui.Selection.addObserver(s)          # installe la fonction en mode résident

###################################################################################################

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

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

Version

ver 00.01 (25/12/2017)  :

Other languages: