Last active
January 11, 2024 22:01
-
-
Save mario52a/7ebe6b3fd047441114d9d0e08ceddd63 to your computer and use it in GitHub Desktop.
This macro select a choice Face, Edge, Vertex hovering by the mouse.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
# | |
""" | |
*************************************************************************** | |
* Copyright (c) 2017 2018 2019 2020 2023 2024 <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_ _01-25/12/2017 02-26/12/2017 03-26/12/2017 03b-28/10/2020 04-15/12/2023 11/01/2024 | |
# | |
#OS: Windows 10 build 19045 | |
#Word size of FreeCAD: 64-bit | |
#Version: 0.22.0dev.35554 (Git) | |
#Build type: Release | |
#Branch: main | |
#Hash: 8e2ab9f76888ac4da971f9d5069cec7bcc2b572f | |
#Python 3.10.13, Qt 5.15.8, Coin 4.0.2, Vtk 9.2.6, OCC 7.6.3 | |
#Locale: French/Mars (fr_MA) | |
# | |
# | |
__title__ = "Select_Hovering" | |
__author__ = "Mario52" | |
__url__ = "http://www.freecadweb.org/index-fr.html" | |
__wiki__ = "http://www.freecadweb.org/wiki/index.php?title=Macro_Select_Hovering" | |
__icon__ = "https://wiki.freecad.org/images/d/d8/Macro_Select_Hovering.png" | |
__version__ = "00.04" | |
__date__ = "2024/01/11" #YYYY/MM/DD | |
# | |
# icon by FreeCAD | |
import PySide2 | |
from PySide2 import QtWidgets, QtGui ,QtCore | |
from PySide2.QtWidgets import * | |
from PySide2.QtGui import * | |
from PySide2.QtCore import * | |
import Draft, Part, PartGui, FreeCADGui, FreeCAD | |
Gui = FreeCADGui | |
App = FreeCAD | |
#### ParamGetSet | |
global FC_Macro_ParamGetSet; FC_Macro_ParamGetSet = FreeCAD.ParamGet(u"User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__) # FC_Macro_ParamGetSet | |
## ex: FC_Macro_ParamGetSet.GetBool(u"switchVersionSearch") | |
FC_Macro_ParamGetSet.SetString("Version",__version__ + " (" + __date__ + ")")# | |
#### geomery | |
global setMainWindowMoveX ; setMainWindowMoveX = 950 # position X macro window | |
global setMainWindowMoveY ; setMainWindowMoveY = 200 # position Y macro window | |
global setFrameWindowSizeX ; setFrameWindowSizeX = 340 # dimension X macro window | |
global setFrameWindowSizeY ; setFrameWindowSizeY = 540 # dimension Y macro window | |
setMainWindowMoveX = FC_Macro_ParamGetSet.GetInt("setMainWindowMoveX") | |
setMainWindowMoveY = FC_Macro_ParamGetSet.GetInt("setMainWindowMoveY") | |
setFrameWindowSizeX= FC_Macro_ParamGetSet.GetInt("setFrameWindowSizeX", setFrameWindowSizeX) | |
FC_Macro_ParamGetSet.SetInt("setFrameWindowSizeX", setFrameWindowSizeX) | |
setFrameWindowSizeY= FC_Macro_ParamGetSet.GetInt("setFrameWindowSizeY", setFrameWindowSizeY) | |
FC_Macro_ParamGetSet.SetInt("setFrameWindowSizeY", setFrameWindowSizeY) | |
#### geomery | |
FC_Macro_ParamGetSet.SetString(u"Version", __version__ + " (" + __date__ + ")") | |
## | |
global seTTextHeigthValue #; seTTextHeigthValue = 11 # heigth Text value | |
seTTextHeigthValue = FC_Macro_ParamGetSet.GetInt(u"seTTextHeigthValue") | |
if seTTextHeigthValue == 0: seTTextHeigthValue = 10 | |
FC_Macro_ParamGetSet.SetInt(u"seTTextHeigthValue", seTTextHeigthValue) # 11 | |
#### | |
global ui ; ui = "" | |
global s ; s = "" | |
global objectsListing ; objectsListing = [] | |
global objectsListingA ; objectsListingA = [] | |
global objectsMemo ; objectsMemo = [] | |
global objectsMemoA ; objectsMemoA = [] | |
global toolTipCBBox_Memo;toolTipCBBox_Memo = [] | |
global compt_Memo ; compt_Memo = 0 | |
global toolTip_Memo ; toolTip_Memo = [] | |
global CB_ResetMode ; CB_ResetMode = 0 | |
global cTB ; | |
global oTB ; | |
global vTB ; | |
global position ; position = "" | |
global pos2D ; | |
import copy # pour copier 2 tableaux | |
#import re | |
#import time | |
#import operator | |
#from operator import itemgetter, attrgetter, methodcaller # pour sort | |
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 | |
global seTTextHeigthValue | |
################################################################################# | |
#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.macroPath = param.GetString("MacroPath","") + "/" # macro path | |
self.macroPath = self.macroPath.replace("\\","/") | |
# print( "Path for the icons : " , self.macroPath) | |
################################################################################# | |
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(seTTextHeigthValue) # 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 | |
################################################################################# | |
#Gui.Selection.clearSelection() | |
self.comptFace = 0 | |
self.comptEdge = 0 | |
self.comptVertex = 0 | |
self.comptNumbObject = 0 | |
self.comptFaceEdgeVertex = 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): | |
global setMainWindowMoveX | |
global setMainWindowMoveX | |
global setFrameWindowSizeX | |
global setFrameWindowSizeY | |
# MainWindow.resize(197, 307) | |
# MainWindow.setMinimumSize(QtCore.QSize(197, 350)) | |
# MainWindow.setMaximumSize(QtCore.QSize(197, 350)) | |
# MainWindow.move(950, 200) | |
# MainWindow.move(setMainWindowMoveX, setMainWindowMoveX) | |
MainWindow.setGeometry(setMainWindowMoveX, setMainWindowMoveY, setFrameWindowSizeX, setFrameWindowSizeY) | |
self.centralwidget = QtWidgets.QWidget(MainWindow) | |
self.centralwidget.setObjectName(_fromUtf8("centralwidget")) | |
self.GBOX_00 = QtWidgets.QGroupBox() | |
self.GBOX_00.setFont(self.fontGlobal_08) # pour W L | |
self.GBOX_00.setObjectName(_fromUtf8("GBOX_00")) | |
self.GBOX_01_Face = QtWidgets.QGroupBox() | |
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 = QtWidgets.QLineEdit() | |
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 = QtWidgets.QLabel() | |
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 = QtWidgets.QCheckBox() | |
self.CB_01_Sel_Face.setIcon(QtGui.QIcon.fromTheme("Draft",QtGui.QIcon(":/icons/face-selection.svg"))) | |
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 = QtWidgets.QLineEdit() | |
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 = QtWidgets.QLabel() | |
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 = QtWidgets.QLabel() | |
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 = QtWidgets.QGroupBox() | |
self.GBOX_02_Edge.setFont(self.fontGlobal_08) # pour W L | |
self.GBOX_02_Edge.setObjectName(_fromUtf8("GBOX_02_Edge")) | |
self.LAB_02_Edge = QtWidgets.QLabel() | |
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 = QtWidgets.QCheckBox() | |
self.CB_02_Sel_Edge.setIcon(QtGui.QIcon.fromTheme("Draft",QtGui.QIcon(":/icons/edge-selection.svg"))) | |
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 = QtWidgets.QLineEdit() | |
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 = QtWidgets.QLineEdit() | |
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 = QtWidgets.QLabel() | |
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 = QtWidgets.QLabel() | |
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 = QtWidgets.QGroupBox() | |
self.GBOX_03_Vertex.setFont(self.fontGlobal_08) # pour W L | |
self.GBOX_03_Vertex.setObjectName(_fromUtf8("GBOX_03_Vertex")) | |
self.LAB_03_Vertex = QtWidgets.QLabel() | |
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 = QtWidgets.QCheckBox() | |
self.CB_03_Sel_Vertex.setIcon(QtGui.QIcon.fromTheme("Draft",QtGui.QIcon(":/icons/vertex-selection.svg"))) | |
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 = QtWidgets.QGroupBox() | |
self.GBOX_04_Main.setFont(self.fontGlobal_08) # pour W L | |
self.GBOX_04_Main.setObjectName(_fromUtf8("GBOX_04_Main")) | |
self.LE_00_InfoSel = QtWidgets.QLineEdit() | |
self.LE_00_InfoSel.setFont(self.fontGlobal_08) # pour W L | |
self.LE_00_InfoSel.setObjectName(_fromUtf8("LE_00_InfoSel")) | |
self.CBBox_Memo = QtWidgets.QComboBox() | |
self.CBBox_Memo.setMaxVisibleItems(16) | |
QtCore.QObject.connect(self.CBBox_Memo, QtCore.SIGNAL("textActivated (QString)"), self.on_CBBox_Memo_Clicked) | |
self.CBBox_Memo.textHighlighted.connect(self.on_CBBox_Memo_Info_ToolTip) | |
self.PB_05_CBBox_Memo = QtWidgets.QPushButton() | |
self.PB_05_CBBox_Memo.setIcon(QtGui.QIcon.fromTheme("View",QtGui.QIcon(":/icons/edit-copy.svg"))) | |
self.PB_05_CBBox_Memo.setFont(self.fontGlobal_08) # pour W L | |
self.PB_05_CBBox_Memo.setObjectName(_fromUtf8("PB_05_CBBox_Memo")) | |
self.PB_05_CBBox_Memo.clicked.connect(self.on_PB_05_CBBox_Memo_clicked) | |
self.PB_03_Box = QtWidgets.QPushButton() | |
self.PB_03_Box.setIcon(QtGui.QIcon.fromTheme("View",QtGui.QIcon(":/icons/edit-element-select-box.svg"))) | |
self.PB_03_Box.setFont(self.fontGlobal_08) # pour W L | |
self.PB_03_Box.setObjectName(_fromUtf8("PB_03_Box")) | |
self.PB_03_Box.clicked.connect(self.on_PB_03_Box_clicked) | |
self.PB_04_Reset = QtWidgets.QPushButton() | |
self.PB_04_Reset.setIcon(QtGui.QIcon.fromTheme("View",QtGui.QIcon(":/icons/delete.svg"))) | |
self.PB_04_Reset.setFont(self.fontGlobal_08) # pour W L | |
self.PB_04_Reset.setObjectName(_fromUtf8("PB_04_Reset")) | |
self.PB_04_Reset.clicked.connect(self.on_PB_04_Reset_clicked) | |
self.PB_05_Reset_Memo = QtWidgets.QPushButton() | |
self.PB_05_Reset_Memo.setIcon(QtGui.QIcon.fromTheme("View",QtGui.QIcon(":/icons/delete.svg"))) | |
self.PB_05_Reset_Memo.setFont(self.fontGlobal_08) # pour W L | |
self.PB_05_Reset_Memo.setObjectName(_fromUtf8("PB_05_Reset_Memo")) | |
self.PB_05_Reset_Memo.clicked.connect(self.on_PB_05_Reset_Memo_clicked) | |
self.PB_06_removeSelection_Selection = QtWidgets.QPushButton() | |
self.PB_06_removeSelection_Selection.setIcon(QtGui.QIcon.fromTheme("View",QtGui.QIcon(":/icons/delete.svg"))) | |
self.PB_06_removeSelection_Selection.setFont(self.fontGlobal_08) # pour W L | |
self.PB_06_removeSelection_Selection.setObjectName(_fromUtf8("PB_06_removeSelection_Selection")) | |
self.PB_06_removeSelection_Selection.clicked.connect(self.on_PB_06_removeSelection_Selection_clicked) | |
self.PB_01_Quit = QtWidgets.QPushButton() | |
self.PB_01_Quit.setIcon(QtGui.QIcon.fromTheme("View",QtGui.QIcon(":/icons/application-exit.svg"))) | |
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) | |
self.PB_02_Stop_Grab = QtWidgets.QPushButton() | |
self.PB_02_Stop_Grab.setIcon(QtGui.QIcon.fromTheme("View",QtGui.QIcon(":/icons/view-refresh.svg"))) | |
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) | |
MainWindow.setCentralWidget(self.centralwidget) | |
self.retranslateUi(MainWindow) | |
QtCore.QMetaObject.connectSlotsByName(MainWindow) | |
#### layout ################################################### | |
self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget) # cadre principal | |
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) | |
self.gridLayout.setContentsMargins(10, 10, 10, 10) | |
self.gridLayout_3 = QtWidgets.QGridLayout(self.GBOX_00) | |
self.gridLayout_3.setContentsMargins(10, 10, 10, 10) | |
self.gridLayout_2 = QtWidgets.QGridLayout(self.GBOX_01_Face) | |
self.gridLayout_2.setContentsMargins(10, 10, 10, 10) | |
self.gridLayout_2.addWidget(self.CB_01_Sel_Face, 0, 0, 1, 1) | |
self.gridLayout_2.addWidget(self.LAB_01_Face, 0, 1, 1, 1) | |
self.gridLayout_2.addWidget(self.LAB_04_Area_Total, 1, 0, 1, 1) | |
self.gridLayout_2.addWidget(self.LAB_05_Area_Object, 1, 1, 1, 1) | |
self.gridLayout_2.addWidget(self.LE_01_Area_Total, 2, 0, 1, 1) | |
self.gridLayout_2.addWidget(self.LE_02_Area_Object, 2, 1, 1, 1) | |
self.gridLayout_3.addWidget(self.GBOX_01_Face, 0, 0, 1, 1) | |
self.gridLayout_4 = QtWidgets.QGridLayout(self.GBOX_02_Edge) | |
self.gridLayout_4.setContentsMargins(10, 10, 10, 10) | |
self.gridLayout_4.addWidget(self.CB_02_Sel_Edge, 0, 0, 1, 1) | |
self.gridLayout_4.addWidget(self.LAB_02_Edge, 0, 1, 1, 1) | |
self.gridLayout_4.addWidget(self.LAB_06_Length_Total, 1, 0, 1, 1) | |
self.gridLayout_4.addWidget(self.LAB_07_Length_Obgect, 1, 1, 1, 1) | |
self.gridLayout_4.addWidget(self.LE_03_Length_Total, 2, 0, 1, 1) | |
self.gridLayout_4.addWidget(self.LE_04_Length_Object, 2, 1, 1, 1) | |
self.gridLayout_3.addWidget(self.GBOX_02_Edge, 1, 0, 1, 1) | |
self.gridLayout_5 = QtWidgets.QGridLayout(self.GBOX_03_Vertex) | |
self.gridLayout_5.setContentsMargins(10, 10, 10, 10) | |
self.gridLayout_5.addWidget(self.CB_03_Sel_Vertex, 0, 0, 1, 1) | |
self.gridLayout_5.addWidget(self.LAB_03_Vertex, 0, 1, 1, 1) | |
self.gridLayout_3.addWidget(self.GBOX_03_Vertex, 2, 0, 1, 1) | |
self.gridLayout_7 = QtWidgets.QGridLayout(self.GBOX_04_Main) | |
self.gridLayout_7.setContentsMargins(10, 10, 10, 10) | |
self.gridLayout_7.addWidget(self.LE_00_InfoSel, 0, 0, 1, 2) | |
self.gridLayout_7.addWidget(self.CBBox_Memo, 1, 0, 1, 2) | |
self.gridLayout_7.addWidget(self.PB_05_CBBox_Memo, 2, 0, 1, 2) | |
self.gridLayout_7.addWidget(self.PB_03_Box, 3, 0, 1, 2) | |
self.gridLayout_7.addWidget(self.PB_04_Reset, 4, 0, 1, 1) | |
self.gridLayout_7.addWidget(self.PB_05_Reset_Memo, 4, 1, 1, 1) | |
self.gridLayout_7.addWidget(self.PB_06_removeSelection_Selection, 5, 0, 1, 2) | |
self.gridLayout_7.addWidget(self.PB_01_Quit, 6, 0, 1, 1) | |
self.gridLayout_7.addWidget(self.PB_02_Stop_Grab, 6, 1, 1, 1) | |
self.gridLayout_3.addWidget(self.GBOX_04_Main, 3, 0, 1, 1) | |
self.gridLayout.addWidget(self.GBOX_00, 0, 0, 1, 1) | |
#### layout ################################################### | |
def retranslateUi(self, MainWindow): | |
MainWindow.setWindowTitle("Select_Hovering") | |
MainWindow.setWindowIcon(QtGui.QIcon(self.macroPath + "Macro_" + __title__ + ".png"))# | |
#### | |
self.GBOX_00.setTitle("Version: " + __version__ + " : " + __date__) | |
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_04_Area_Total.setToolTip("Area Total of the faces selected") | |
self.LAB_05_Area_Object.setText("Area Face") | |
self.LAB_05_Area_Object.setToolTip("Area of the latest face selected") | |
self.LE_01_Area_Total.setToolTip("Area Total of the faces selected") | |
self.LE_02_Area_Object.setToolTip("Area of the latest face selected") | |
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_06_Length_Total.setToolTip("Length of the total Edges selected") | |
self.LAB_07_Length_Obgect.setText("Length Edge") | |
self.LAB_07_Length_Obgect.setToolTip("Length of the latest Edge selected") | |
self.LE_03_Length_Total.setToolTip("Length of the total Edges selected") | |
self.LE_04_Length_Object.setToolTip("Length of the latest Edges selected") | |
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.CBBox_Memo.setToolTip("\n" + "Detail of label ex:" + "\n\n" | |
"2: ( 15 sel. )( Obj. 2, Fa. 5, Ed. 10, Ve. 4)" + "\n\n" | |
"2: \t: item ComboBox" + "\n" | |
"15 sel. \t: number of selection(s)" + "\n" | |
"Obj. 2\t: number of different object(s)" + "\n" | |
"Fa. 5\t: number total of Face(s)" + "\n" | |
"Ed. 6\t: number total of Edge(s)" + "\n" | |
"Ve. 4\t: number total of Vertex(s)" + "\n" | |
""+ "\n") | |
self.PB_05_CBBox_Memo.setText("Memo selection") | |
self.PB_05_CBBox_Memo.setToolTip("Store the selection(s)" + "\n" | |
"If sveral documents hare open and objects selected:" + "\n" | |
"the macro is upgrade the data of the selection for each document") | |
self.PB_03_Box.setText("Selected by Box") | |
self.PB_03_Box.setToolTip("\n" + "Select all elements (with the option checked) of the object(s) selected" + "\n" + "\n" | |
"Select the objects with the Box tool or the objects already selected" + "\n" + "\n" | |
"Choice your CheckBox 'Select Face', 'Select Edge' or 'Select Vertex'" + "\n" | |
"Click the 'Selected by box' button" + "\n" + "\n" | |
"This feature not select the object but his SubObject ... Face, Edge, Vertex" + "\n" | |
"it may take time depending on the object being worked on" + "\n") | |
self.PB_04_Reset.setText("Reset Data") | |
self.PB_04_Reset.setToolTip("Reset all data information in the macro") | |
self.PB_05_Reset_Memo.setText("Reset Memo") | |
self.PB_05_Reset_Memo.setToolTip("Reset all memorised data") | |
self.PB_06_removeSelection_Selection.setText("Remove Selection") | |
self.PB_06_removeSelection_Selection.setToolTip("Remove Selection of active document" + "\n" | |
"If you click in the 3Dview" + "\n" | |
" ! all objects selected in all document open hare removed" + "\n") | |
self.PB_01_Quit.setText("Quit") | |
self.PB_02_Stop_Grab.setText("Pause grab / Refresh") | |
self.PB_02_Stop_Grab.setToolTip("\n" + "Use CTRL + click mouse" + "\n" | |
"for select or unselect object(s)" + "\n" | |
"or validate in the macro the objects selected in 3Dview" + "\n" | |
"Ex: objects selectet before starting the macro or refresh") | |
MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant | |
def around(self, number): | |
return round(number, 5) | |
def displayOnWindow(self): | |
self.LAB_01_Face.setText(str(self.comptFace)) | |
self.LE_01_Area_Total.setText(str(self.around(self.comptSurfaceTotal))) | |
self.LE_02_Area_Object.setText(str(self.around(self.comptSurfaceFace))) | |
self.LAB_02_Edge.setText(str(self.comptEdge)) | |
self.LE_03_Length_Total.setText(str(self.around(self.comptLengthTotal))) | |
self.LE_04_Length_Object.setText(str(self.around(self.comptLengthObject))) | |
self.LAB_03_Vertex.setText(str(self.comptVertex)) | |
self.comptFaceEdgeVertex = self.comptFace + self.comptEdge + self.comptVertex | |
self.GBOX_04_Main.setTitle("Main ( Obj: " + str(self.comptNumbObject) + " ) ( Sub: " + str(self.comptFaceEdgeVertex) + " ) ( Tot: " + str(self.comptNumbObject + self.comptFaceEdgeVertex) + " )") | |
if self.comptFace != 0 : self.GBOX_01_Face.setEnabled(True) # cas selection hors de la macro (pause grab) | |
if self.comptEdge != 0 : self.GBOX_02_Edge.setEnabled(True) # cas selection hors de la macro (pause grab) | |
if self.comptVertex != 0 : self.GBOX_03_Vertex.setEnabled(True) # cas selection hors de la macro (pause grab) | |
def selectSelection(self): # one subObjects | |
global objectsListing | |
global objectsMemoA | |
count = self.comptFace = self.comptSurfaceFace = self.comptSurfaceTotal = 0 | |
count = self.comptEdge = self.comptLengthObject = self.comptLengthTotal = 0 | |
count = self.comptVertex = 0 | |
objets = [] | |
objectsMemoA = [] | |
for i in range(len(objectsListing)): | |
selected = FreeCAD.ActiveDocument.getObject(objectsListing[i]) #<PartDesign::AdditivePipe> | |
try: | |
if str(selected) != "<body object>": | |
typeID = selected.TypeId # 'PartDesign::AdditivePipe' | |
if "PartDesign" in typeID: | |
parentNamePaDe = selected.getParent().Name # 'Body001' | |
subNamePaDe = selected.Name # 'Additivepipe001' | |
count = 0 | |
for ii in selected.Parents[0][0].Shape.Faces: | |
count += 1 | |
faceSel = "Face" + str(count) | |
faceA = "" | |
faceA = Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + faceSel) | |
if faceA == True: | |
objectsMemoA.append((objectsListing[i], faceSel)) | |
self.comptFace += 1 | |
self.comptSurfaceFace = FreeCAD.ActiveDocument.getObject(parentNamePaDe).Shape.getElement(faceSel).Area | |
self.comptSurfaceTotal += self.comptSurfaceFace | |
count = 0 | |
for ii in selected.Parents[0][0].Shape.Edges: | |
count += 1 | |
edgeSel = "Edge" + str(count) | |
edgeA = "" | |
edgeA = Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + edgeSel) | |
if edgeA == True: | |
objectsMemoA.append((objectsListing[i], edgeSel)) | |
self.comptEdge += 1 | |
self.comptLengthObject = FreeCAD.ActiveDocument.getObject(parentNamePaDe).Shape.getElement(edgeSel).Length | |
self.comptLengthTotal += self.comptLengthObject | |
count = 0 | |
for ii in selected.Parents[0][0].Shape.Vertexes: # search Vertexes | |
count += 1 | |
vertexSel = "Vertex" + str(count) | |
vertexA = "" | |
vertexA = Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + vertexSel) | |
if vertexA == True: # isSelected | |
objectsMemoA.append((objectsListing[i], vertexSel)) | |
self.comptVertex += 1 | |
count = 0 | |
else: | |
count = 0 | |
for j in FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Faces: # search Faces | |
count += 1 | |
faceSel = "Face" + str(count) | |
if "Sketcher" in typeID: # Sketcher | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(objectsListing[i]).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Name # 'Additivepipe001' | |
#sub # Edge26 | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + faceSel): | |
objectsMemoA.append((objectsListing[i], faceSel)) | |
self.comptFace += 1 | |
self.comptSurfaceFace = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Faces[count-1].Area | |
self.comptSurfaceTotal += self.comptSurfaceFace | |
except Exception: | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(objectsListing[i]), faceSel): # isSelected | |
objectsMemoA.append((objectsListing[i], faceSel)) | |
self.comptFace += 1 | |
self.comptSurfaceFace = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Faces[count-1].Area | |
self.comptSurfaceTotal += self.comptSurfaceFace | |
else: | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(objectsListing[i]), faceSel): # isSelected | |
objectsMemoA.append((objectsListing[i], faceSel)) | |
self.comptFace += 1 | |
self.comptSurfaceFace = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Faces[count-1].Area | |
self.comptSurfaceTotal += self.comptSurfaceFace | |
count = 0 | |
for j in FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Edges: # search Edges | |
count += 1 | |
edgeSel = "Edge" + str(count) | |
if "Sketcher" in typeID: # Sketcher | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(objectsListing[i]).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Name # 'Additivepipe001' | |
#sub # Edge26 | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + edgeSel): | |
objectsMemoA.append((objectsListing[i], edgeSel)) | |
self.comptEdge += 1 | |
self.comptLengthObject = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Edges[count-1].Length | |
self.comptLengthTotal += self.comptLengthObject | |
except Exception: | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(objectsListing[i]), edgeSel): # isSelected | |
objectsMemoA.append((objectsListing[i], edgeSel)) | |
self.comptEdge += 1 | |
self.comptLengthObject = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Edges[count-1].Length | |
self.comptLengthTotal += self.comptLengthObject | |
else: | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(objectsListing[i]), edgeSel): # isSelected | |
objectsMemoA.append((objectsListing[i], edgeSel)) | |
self.comptEdge += 1 | |
self.comptLengthObject = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Edges[count-1].Length | |
self.comptLengthTotal += self.comptLengthObject | |
count = 0 | |
for j in FreeCAD.ActiveDocument.getObject(objectsListing[i]).Shape.Vertexes: # search Vertexes | |
count += 1 | |
vertexSel = "Vertex" + str(count) | |
if "Sketcher" in typeID: # Sketcher | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(objectsListing[i]).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(objectsListing[i]).Name # 'Additivepipe001' | |
#sub # Edge26 | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + vertexSel): | |
objectsMemoA.append((objectsListing[i], vertexSel)) | |
self.comptVertex += 1 | |
except Exception: | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(objectsListing[i]), vertexSel): # isSelected | |
objectsMemoA.append((objectsListing[i], vertexSel)) | |
self.comptVertex += 1 | |
else: | |
if Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(objectsListing[i]), vertexSel): # isSelected | |
objectsMemoA.append((objectsListing[i], vertexSel)) | |
self.comptVertex += 1 | |
count = 0 | |
except Exception: | |
None | |
self.comptNumbObject = len(objectsListing) | |
self.displayOnWindow() | |
FreeCAD.ActiveDocument.recompute(None,True,True) | |
def on_PB_03_Box_clicked(self): # all subObjects checked | |
global objectsListing | |
##https://forum.freecad.org/viewtopic.php?p=722362#p722362 | |
##Feature Request: Preselection Order Priority. | |
objectsListing = [] | |
sel=Gui.Selection.getSelection() | |
if (self.CB_01_Sel_Face.isChecked() or self.CB_02_Sel_Edge.isChecked() or self.CB_03_Sel_Vertex.isChecked()) and (len(sel) != 0): | |
self.LE_00_InfoSel.setText("(Face: " + str(self.CB_01_Sel_Face.isChecked()) + ") (Edge: " + str(self.CB_02_Sel_Edge.isChecked()) + ") (Vertex: " + str(self.CB_03_Sel_Vertex.isChecked()) + ")") | |
for i in range(len(sel)): | |
if self.CB_01_Sel_Face.isChecked(): # search Faces | |
for j in enumerate(sel[i].Shape.Faces): | |
#objetSelect = Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(sel[i].Name), 'Face'+str(j[0]+1)) | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(sel[i].Name).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(sel[i].Name).Name # 'Additivepipe001' | |
#sub # Edge26 | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + 'Face'+str(j[0]+1)) | |
except Exception: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(sel[i].Name), 'Face'+str(j[0]+1)) | |
if self.CB_02_Sel_Edge.isChecked(): # search Edges | |
for j in enumerate(sel[i].Shape.Edges): | |
#objetSelect = Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(sel[i].Name), 'Edge'+str(j[0]+1)) | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(sel[i].Name).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(sel[i].Name).Name # 'Additivepipe001' | |
#sub # Edge26 | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + 'Edge'+str(j[0]+1)) | |
except Exception: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(sel[i].Name), 'Edge'+str(j[0]+1)) | |
if self.CB_03_Sel_Vertex.isChecked(): # search Vertexes | |
for j in enumerate(sel[i].Shape.Vertexes): | |
#objetSelect = Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(sel[i].Name), 'Vertex'+str(j[0]+1)) | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(sel[i].Name).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(sel[i].Name).Name # 'Additivepipe001' | |
#sub # Edge26 | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + 'Vertex'+str(j[0]+1)) | |
except Exception: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(sel[i].Name), 'Vertex'+str(j[0]+1)) | |
objectsListing.append(sel[i].Name) | |
self.selectSelection() | |
else: | |
if (len(sel) == 0): | |
self.LE_00_InfoSel.setText("Not object selected") | |
def on_PB_04_Reset_clicked(self): | |
global objectsListing | |
global CB_ResetMode | |
objectsListing = [] | |
self.comptFace = 0 | |
self.comptEdge = 0 | |
self.comptVertex = 0 | |
self.comptNumbObject = 0 | |
self.comptSurfaceFace = 0.0 | |
self.comptSurfaceTotal = 0.0 | |
self.comptLengthObject = 0.0 | |
self.comptLengthTotal = 0.0 | |
if CB_ResetMode == 0: | |
self.CB_01_Sel_Face.setChecked(False) | |
self.CB_02_Sel_Edge.setChecked(False) | |
self.CB_03_Sel_Vertex.setChecked(False) | |
CB_ResetMode = 0 | |
self.LAB_01_Face.setText(str(self.comptFace)) | |
self.LAB_02_Edge.setText(str(self.comptEdge)) | |
self.LAB_03_Vertex.setText(str(self.comptVertex)) | |
self.LE_01_Area_Total.setText(str(self.comptSurfaceTotal)) | |
self.LE_02_Area_Object.setText(str(self.comptSurfaceFace)) | |
self.LE_03_Length_Total.setText(str(self.comptLengthTotal)) | |
self.LE_04_Length_Object.setText(str(self.comptLengthObject)) | |
self.selectSelection() | |
self.LE_00_InfoSel.setText("(Face: " + str(self.CB_01_Sel_Face.isChecked()) + ") (Edge: " + str(self.CB_02_Sel_Edge.isChecked()) + ") (Vertex: " + str(self.CB_03_Sel_Vertex.isChecked()) + ")") | |
def on_PB_05_Reset_Memo_clicked(self): | |
global objectsMemo | |
global objectsMemoA | |
global compt_Memo | |
global toolTipCBBox_Memo | |
try: | |
self.CBBox_Memo.clear() | |
except Exception: | |
None | |
objectsMemo = [] | |
objectsMemoA = [] | |
toolTipCBBox_Memo = [] | |
compt_Memo = 0 | |
self.PB_05_CBBox_Memo.setText("Memo selection (" + str(compt_Memo) + ")") | |
self.on_PB_04_Reset_clicked() | |
def on_PB_02_Stop_Grab_clicked(self): | |
global s | |
global objectsListing | |
global objectsListingA | |
if self.Stop_Grab == 1: | |
FreeCADGui.Selection.removeObserver(s) # desinstalle la fonction residente SelObserver | |
self.Stop_Grab = 0 | |
self.PB_02_Stop_Grab.setText("Return / Refresh") | |
self.GBOX_01_Face.setEnabled(False) | |
self.GBOX_02_Edge.setEnabled(False) | |
self.GBOX_03_Vertex.setEnabled(False) | |
self.PB_03_Box.setEnabled(False) | |
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 / Refresh") | |
self.GBOX_01_Face.setEnabled(True) | |
self.GBOX_02_Edge.setEnabled(True) | |
self.GBOX_03_Vertex.setEnabled(True) | |
self.PB_03_Box.setEnabled(True) | |
sel=Gui.Selection.getSelection() | |
objectsListing = [] | |
objectsListingA = [] | |
for i in sel: | |
try: | |
objectsListingA.append(i.Name) | |
except Exception: | |
objectsListingA.append(i) | |
for i in objectsListingA: # elimine les doublons | |
if i not in objectsListing: | |
objectsListing.append(i) | |
if len(sel) == 0: | |
self.on_PB_04_Reset_clicked() | |
else: | |
self.CB_01_Sel_Face.setChecked(True) # cas selection hors de la macro (pause grab) | |
self.CB_02_Sel_Edge.setChecked(True) # cas selection hors de la macro (pause grab) | |
self.CB_03_Sel_Vertex.setChecked(True) # cas selection hors de la macro (pause grab) | |
self.selectSelection() | |
def on_CBBox_Memo_Info_ToolTip(self, text): | |
global objectsMemoA | |
global toolTipCBBox_Memo | |
if len(objectsMemoA) != 0: | |
itemFile = self.CBBox_Memo.currentIndex() | |
self.CBBox_Memo.setItemData(itemFile, toolTipCBBox_Memo[itemFile], QtCore.Qt.ToolTipRole) | |
def on_CBBox_Memo_Clicked(self, text): # object memorised in CBBox | |
global objectsListing | |
global objectsMemo | |
try: | |
dummy = self.CBBox_Memo.currentText().split()[0] | |
if dummy == FreeCAD.ActiveDocument.Name: | |
if len(objectsMemo) != 0: | |
objectsListing = [] | |
itemFile = self.CBBox_Memo.currentIndex() | |
self.on_PB_03_Box_clicked() | |
position = [0,0,0] # controler !! | |
for obj, sub in objectsMemo[itemFile]: | |
try: | |
typeID = FreeCAD.ActiveDocument.getObject(obj).TypeId # 'PartDesign::AdditivePipe' | |
except Exception: | |
typeID = "" | |
if ("Sketcher" in typeID) or ("PartDesign" in typeID): | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(obj).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(obj).Name # 'Additivepipe001' | |
#sub # Edge26 | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + sub, position[0], position[1], position[2]) | |
except Exception: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2]) | |
else: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2]) | |
if obj not in objectsListing: # filtre les noms | |
objectsListing.append(obj) | |
self.selectSelection() | |
else: | |
self.LE_00_InfoSel.setText("Wrong document: actual: " + FreeCAD.ActiveDocument.Name) | |
#print("Wrong document") | |
except Exception: | |
None | |
def on_PB_05_CBBox_Memo_clicked(self): # store the objects selected | |
global objectsMemo | |
global objectsMemoA | |
global compt_Memo | |
global toolTip_Memo | |
global toolTipCBBox_Memo | |
dummy = [] | |
toolTip_Memo = [] | |
objets = [] | |
Fc = Ed = Ve = 0 | |
subElements = "" | |
if len(objectsMemoA) != 0: | |
for i in objectsMemoA: # elimine les doublons () | |
if i not in dummy: | |
dummy.append(i) | |
if "Face" in i[1]: | |
Fc += 1 | |
if "Edge" in i[1]: | |
Ed += 1 | |
if "Vertex" in i[1]: | |
Ve += 1 | |
for i in dummy: | |
if i[0] not in objets: # elimine les doublons (nom) | |
objets.append(i[0]) # number objects | |
self.comptNumbObject = len(objets) | |
self.CBBox_Memo.addItem( FreeCAD.ActiveDocument.Name + " : " + str(compt_Memo + 1) + " : ( " + str(len(dummy)) + " sel. ) ( Obj. " + str(self.comptNumbObject) + ", Fa. " + str(Fc) + ", Ed. " + str(Ed) + ", Ve. " + str(Ve) + " )") # text in comboBox | |
objectsMemo += [copy.deepcopy(dummy)] | |
toolTipCBo = "" | |
toolTipCBo = "\n" + FreeCAD.ActiveDocument.Name + "\n\n" | |
for i in objectsMemo[compt_Memo]: | |
toolTipCBo += str(i) + "\n" | |
toolTipCBBox_Memo += [toolTipCBo] | |
self.CBBox_Memo.setItemData(compt_Memo, toolTipCBBox_Memo[compt_Memo], QtCore.Qt.ToolTipRole) | |
compt_Memo += 1 | |
else: | |
self.LE_00_InfoSel.setText("Not object selected") | |
self.PB_05_CBBox_Memo.setText("Memo selection (" + str(compt_Memo) + ")") | |
dummy = [] | |
objets = [] | |
def on_PB_06_removeSelection_Selection_clicked(self): | |
try: | |
for obj in FreeCAD.ActiveDocument.Objects: | |
FreeCADGui.Selection.removeSelection(FreeCAD.ActiveDocument.Name, obj.Name) | |
self.on_PB_04_Reset_clicked() | |
except Exception: | |
None | |
def on_PB_Quit_clicked(self): | |
global s | |
global vTB | |
global cTB | |
global obs | |
global oTB | |
global FC_Macro_ParamGetSet | |
global setMainWindowMoveX | |
global setMainWindowMoveY | |
global setFrameWindowSizeX | |
global setFrameWindowSizeY | |
FreeCADGui.Selection.removeObserver(s) # desinstalle la fonction residente SelObserver | |
vTB.removeEventCallback("SoEvent",cTB) # close event observation | |
vTB.removeEventCallback("SoEvent",oTB.logPosition) # | |
App.removeDocumentObserver(obs) # desinstalle la fonction residente | |
#### geometry | |
positionWindowXY = MainWindow.geometry() | |
setMainWindowMoveX = positionWindowXY.x() | |
setMainWindowMoveY = positionWindowXY.y() | |
positionWindowXY = MainWindow.size() | |
setFrameWindowSizeX = positionWindowXY.width() | |
setFrameWindowSizeY = positionWindowXY.height() | |
FC_Macro_ParamGetSet.SetInt("setMainWindowMoveX", setMainWindowMoveX) # setMainWindowMoveX | |
FC_Macro_ParamGetSet.SetInt("setMainWindowMoveY", setMainWindowMoveY) # setMainWindowMoveY | |
FC_Macro_ParamGetSet.SetInt("setFrameWindowSizeX", setFrameWindowSizeX) # setFrameWindowSizeX | |
FC_Macro_ParamGetSet.SetInt("setFrameWindowSizeY", setFrameWindowSizeY) # setFrameWindowSizeY | |
#### geometry | |
try: | |
self.window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True) # destroy | |
self.window.deleteLater() # destroy | |
self.window.destroy() # destroy | |
except Exception: | |
self.window.hide() # hide the window and close the macro | |
print( "Quit ",__title__, " Bye") | |
### section Observer begin ###################### | |
global cTB | |
global oTB | |
global vTB; vTB=Gui.activeDocument().activeView() | |
global obs | |
class DocObserver: # document Observer | |
def slotActivateDocument(self,doc): | |
global cTB | |
global oTB | |
global vTB | |
global ui | |
try: | |
vTB.removeEventCallback("SoEvent",cTB) # close event observation | |
except Exception: None | |
ui.Stop_Grab = 0 | |
ui.on_PB_02_Stop_Grab_clicked() | |
ui.LE_00_InfoSel.setText(doc.Name) | |
try: | |
vTB=Gui.activeDocument().activeView() | |
oTB = ViewObserver(vTB) | |
cTB = vTB.addEventCallback("SoEvent",oTB.logPosition) | |
except Exception: None | |
obs=DocObserver() | |
App.addDocumentObserver(obs) | |
#App.removeDocumentObserver(obs) # desinstalle la fonction residente | |
#### | |
vTB=Gui.activeDocument().activeView() | |
class ViewObserver: # vue souris Observer | |
def __init__(self, view): | |
self.view = view | |
def logPosition(self, info): | |
global cTB | |
global oTB | |
global vTB | |
global position | |
global pos2D | |
try: | |
vTB=Gui.activeDocument().activeView() | |
objectSurvol = vTB.getObjectInfo(vTB.getCursorPos()) # here for objectSurvol preselected | |
position = FreeCAD.Vector(float(objectSurvol["x"]),float(objectSurvol["y"]),float(objectSurvol["z"]))# vector on position mouse to objectSurvol | |
except Exception: | |
None | |
oTB = ViewObserver(vTB) | |
cTB = vTB.addEventCallback("SoEvent",oTB.logPosition) | |
#vTB.removeEventCallback("SoEvent",cTB) # close event observation | |
### section Observer end ###################### | |
class SelObserver: # selection Observer | |
global ui | |
def setPreselection(self, doc, obj, sub): # preselection## self, coin_carre, AdditivePipe001, Edge26 #dans body | |
global ui | |
global objectsListingA | |
global objectsListing | |
global position | |
global vTB | |
try: | |
if (ui.Stop_Grab == 1) and (position != ""): | |
typeID = FreeCAD.ActiveDocument.getObject(obj).TypeId # 'PartDesign::AdditivePipe' | |
if typeID != "NoneType": | |
ui.LE_00_InfoSel.setText(FreeCAD.ActiveDocument.Name + ": " + str(obj) + ". " + str(sub) + " (" + str(round(position[0],2)) + "," + str(round(position[1],2)) + "," + str(round(position[2],2)) + ")") | |
if ui.CB_01_Sel_Face.isChecked(): | |
if (sub[:4] == "Face") and (Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(obj), sub) == False): | |
if "Sketcher" in typeID: | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(obj).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(obj).Name # 'Additivepipe001' | |
#sub # Edge26 | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + sub, position[0], position[1], position[2]) | |
except Exception: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2]) | |
else: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2]) | |
objectsListingA.append(obj) | |
if ui.CB_02_Sel_Edge.isChecked(): | |
if (sub[:4] == "Edge") and (Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(obj), sub) == False): | |
if "Sketcher" in typeID: | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(obj).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(obj).Name # 'Additivepipe001' | |
#sub # Edge26 | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + sub, position[0], position[1], position[2]) | |
except Exception: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2]) | |
else: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2]) | |
objectsListingA.append(obj) | |
if (ui.CB_03_Sel_Vertex.isChecked()) and (position != ""): | |
if sub[:6] == "Vertex" and (Gui.Selection.isSelected(FreeCAD.ActiveDocument.getObject(obj), sub) == False): | |
if "Sketcher" in typeID: | |
try: | |
parentNamePaDe = FreeCAD.ActiveDocument.getObject(obj).getParent().Name # 'Body001' | |
subNamePaDe = FreeCAD.ActiveDocument.getObject(obj).Name # 'Additivepipe001' | |
#sub # Edge26 | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(parentNamePaDe), subNamePaDe + "." + sub, position[0], position[1], position[2]) | |
except Exception: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2]) | |
else: | |
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2]) | |
objectsListingA.append(obj) | |
#### elimine les doublons | |
for i in objectsListingA: # elimine les doublons | |
if i in objectsListing: | |
None | |
else: | |
objectsListing.append(i) | |
#### | |
objectsListingA = [] | |
ui.selectSelection() | |
except Exception: | |
None | |
# 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 | |
global CB_ResetMode | |
try: | |
CB_ResetMode = 1 | |
ui.on_PB_04_Reset_clicked() | |
except Exception: | |
None | |
s=SelObserver() | |
FreeCADGui.Selection.addObserver(s) # installe la fonction en mode resident | |
#FreeCADGui.Selection.removeObserver(s) | |
### section Observer end ###################### | |
doc = FreeCAD.ActiveDocument | |
if doc == None: | |
doc = FreeCAD.newDocument() | |
MainWindow = QtWidgets.QMainWindow() | |
ui = Ui_MainWindow(MainWindow) | |
ui.setupUi(MainWindow) | |
MainWindow.show() |
Hi Jules-V
the new version 00.04 is available
the picked Vertex bellow the cursor mouse work very well with HandBspline of Curve WorkBench
BUT if you select all Vertex with the "Selected by Box" button ... this give on error as the old version SelectHovering
i work for adapt it also (i not make this i was happy to make the new version quickly ) now i will work slowly
I think this "edit mode" have to be more obvious for the user and should always display its shortcuts in the corner of the screen when activated. I don't know who's in charge and where i can send that suggestion ?
no idea i use not CurveWorkBench the best is in the forum Curves workbench
mario
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
Ok all is good
i adding (in setPreselection):
Gui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(obj), sub, position[0], position[1], position[2])
seems to work well and now work also with the Body object and correction recalculate the selection after Pause grab/return macro
Thank you Mario, and I'm curious to try the new version of the macro !
here one screenshot (a few more days)
thanks
mario