Macro FCInfoGlass
File:Macro FCInfoGlass Macro FCInfo |
Description |
---|
Gives a series of information on the form display in the 3D view. Author: Mario52 |
Author |
Mario52 |
Download |
None |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
1.0 |
Date last modified |
None |
FreeCAD Version(s) |
None |
Default shortcut |
None |
See also |
None |
Gives a series of informations about the selected shape and can display a directly in the 3D view
Utilisation
Select an object or launch the application and select an object, and a series of informations appear on the 3D View.
Modify this line to move the data display in the screen (line 115)
MainWindow.setGeometry(400, 200, 500, 500) # positionne la fenetre dans l'ecran
# modify this line for posioned the window
- 400, 200 = position X, Y upper left corner
- 500, 500 = position x, y right corner
It is not possible at the moment to leave the function from the macro or scrolling
One mouse click on the object display the information of the object, two mouse click select the object complete and displayed alls informations
(it is possible you can not see everything informations in the window for the moment)
Script
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
* Copyright (c) 2014 <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 *
***************************************************************************
"""
#
#OS: Windows 8.1
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.15.4671 (Git)
#Branch: releases/FreeCAD-0-15
#Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c
#Python version: 2.7.8
#Qt version: 4.8.6
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#
__title__="FCInfoGlass"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.01"
__date__ = "30/07/2015"
__Comment__ = "displays various information on the screen"
__Web__ = ""
__Wiki__ = ""
__Icon__ = "/usr/lib/freecad/Mod/plugins/icons/.png"
__IconW__ = "C:/Documents and Settings/YourUserName/Application Data/FreeCAD"
__Help__ = ""
__Status__ = "not finished"
__Requires__ = "FreeCAD 0.14.3706"
__Communication__ = "http://www.freecadweb.org/wiki/index.php?title=User:Mario52"
try:
import PyQt4
from PyQt4 import QtGui ,QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
except Exception:
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base
global path
#path = FreeCAD.ConfigGet("AppHomePath")
path = FreeCAD.ConfigGet("UserAppData")
global texteInfo ; texteInfo = ""
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 errorDialog(msg):
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
try:
diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # cette fonction met la fenêtre en avant
except Exception:
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide #cette fonction met la fenêtre en avant
# diag.setWindowModality(QtCore.Qt.ApplicationModal) # la fonction a été désactivée pour favoriser "WindowStaysOnTopHint"
diag.exec_()
class Ui_MainWindow(object):
global path
global texteInfo
def setupUi(self, MainWindow):
self.window = MainWindow
global path
global texteInfo
MainWindow.setObjectName("MainWindow")
MainWindow.setWindowTitle("Fenetre Transparente Info ")
MainWindow.resize(400, 400) # dimenssions exterieures de la fenetre
MainWindow.setMinimumSize(QtCore.QSize(400, 400)) #
MainWindow.setMaximumSize(QtCore.QSize(400, 400)) #
MainWindow.setGeometry(400, 200, 500, 500) # positionne la fenetre dans l'ecran
# modify this line for posionned the window
MainWindow.setWindowOpacity(1) # rend la fenetre +/- opaque
MainWindow.setWindowFlags(QtCore.Qt.FramelessWindowHint) # rend la fenêtre transparente et cache le cadre
MainWindow.setAttribute(QtCore.Qt.WA_TranslucentBackground, True) # ne pas bouger ,True
MainWindow.setStyleSheet("background:transparent;") # rend le fond transparent
self.istransparent = True
################ test bouton
# self.frame = QtGui.QFrame(MainWindow)
# self.frame.setGeometry(QtCore.QRect(10, 370, 381, 24))
# self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
# self.frame.setFrameShadow(QtGui.QFrame.Raised)
# self.frame.setObjectName(_fromUtf8("frame"))
# self.PBQuit = QtGui.QPushButton(self.frame)
# self.PBQuit.setGeometry(QtCore.QRect(0, 0, 101, 23))
# self.PBQuit.setObjectName(_fromUtf8("PBQuit"))
# self.PBQuit.clicked.connect(self.on_PBQuit) ###
###################
#########################################
#cree un cadre aux dimensions MainWindow.resize(400, 400) mais cache la fenetre textEdit OK
# self.centralWidget = QtGui.QWidget(MainWindow)
# self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
# self.tableWidget = QtGui.QTableWidget(self.centralWidget)
# self.tableWidget.setGeometry(QtCore.QRect(0, 0, 400, 400))
##########################################
MainWindow.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) # met la fenetre en avant
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.label = QtGui.QLabel(self.centralWidget)
self.label.setGeometry(QtCore.QRect(10, 10, 400, 400)) # positionne le label
self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralWidget)
self.retranslateUi(MainWindow)
# self.PBQuit.setText("Quit")
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle("Dialog")
# self.PBQuit.setText("Quit")
self.label.setText("")
def on_pushButton_Raf_clicked(self): # affiche le texte concatebe dans la fenetre
global texteInfo
self.label.setText(texteInfo + "\n")
# def on_PBQuit(self):
# App.Console.PrintMessage(str("Fin FCTransparencyInfo ")+"\n")
# self.window.hide()
class SelObserver:
def addSelection(self,document, object, element, position): # Selection
global texteInfo
texteInfo = ""
arondi = 5
def Around(a) :
return round(a,arondi)
sel = FreeCADGui.Selection.getSelection()
try:
Object = Gui.Selection.getSelectionEx()[0].SubObjects[0]
except:
None
# Nom du document
try:
App.Console.PrintMessage("Document name : "+str(FreeCAD.activeDocument().Name)+"\n")
texteInfo += "Document name : "+str(FreeCAD.activeDocument().Name)+"\n"
except:
None
# Label
try:
# object_Label = sel[0].Label
App.Console.PrintMessage("Label name : "+str(sel[0].Label)+"\n")
texteInfo += "Label name : "+str(sel[0].Label)+"\n"
except:
None
# Nom interne de l'objet
try:
# object_Name = sel[0].Name
App.Console.PrintMessage("Object name : "+str(sel[0].Name)+"\n")
texteInfo += "Object name : "+str(sel[0].Name)+"\n"
except:
None
# Nom de l'élément
try:
SubElement = FreeCADGui.Selection.getSelectionEx()
element_ = SubElement[0].SubElementNames[0]
App.Console.PrintMessage("Element name : "+str(element_)+"\n")
texteInfo += "Element name : "+str(element_)+"\n"
except:
None
# Type d'objet
try:
typeObject = sel[0].Shape.ShapeType
App.Console.PrintMessage("Object type : "+typeObject+"\n")
texteInfo += "Object type : "+typeObject+"\n"
except:
None
# longueur Objet
try:
App.Console.PrintMessage("Object lenght : "+str(Gui.Selection.getSelectionEx()[0].SubObjects[0].Length)+"\n")
texteInfo += "Object lenght : "+str(Gui.Selection.getSelectionEx()[0].SubObjects[0].Length)+"\n"
except:
None
# Surface de la face
try:
App.Console.PrintMessage("Face area : "+str(Gui.Selection.getSelectionEx()[0].SubObjects[0].Area)+"\n")
texteInfo += "Face area : "+str(Gui.Selection.getSelectionEx()[0].SubObjects[0].Area)+"\n"
except:
None
# Center Face (mass)
try:
det = Gui.Selection.getSelectionEx()[0].SubObjects[0].CenterOfMass
App.Console.PrintMessage("Face center : "+str(det[0])+", "+str(det[1])+", "+str(det[2])+"\n") # Vector center mass to face
texteInfo += "Face center : "+str(det[0])+", "+str(det[1])+", "+str(det[2])+"\n"
except:
None
######Cas d'une forme############################################################
# volume
try:
App.Console.PrintMessage("Volume : "+str(sel[0].Shape.Volume)+"\n")
texteInfo += "Volume : "+str(sel[0].Shape.Volume)+"\n"
except:
None
# rectangle du BoundBox
# try:
App.Console.PrintMessage("BoundBox Rect : "+str(sel[0].Shape.BoundBox.XLength)+" x "+str(sel[0].Shape.BoundBox.YLength)+" x "+str(sel[0].Shape.BoundBox.ZLength)+"\r\n")
texteInfo += "BoundBox Rect : "+str(sel[0].Shape.BoundBox.XLength)+" x "+str(sel[0].Shape.BoundBox.YLength)+" x "+str(sel[0].Shape.BoundBox.ZLength)+"\r\n"
# except:
# None
# boundinbox (dimensions hors tout)
try:
App.Console.PrintMessage("BoundBox Coor : "+str(sel[0].Shape.BoundBox)+"\n")
texteInfo += "BoundBox Coor : "+str(sel[0].Shape.BoundBox)+"\n"
except:
None
# centre de la forme
try:
det = sel[0].Shape.BoundBox.Center
App.Console.PrintMessage("BounCenter : "+str(det[0])+", "+str(det[1])+", "+str(det[2])+"\n")
texteInfo += "BounCenter : "+str(det[0])+", "+str(det[1])+", "+str(det[2])+"\n"
except:
None
# centre de la masse
try:
App.Console.PrintMessage("CenterMass : "+str(sel[0].Solids[0].CenterOfMass)+"\n")
texteInfo += "CenterMass : "+str(sel[0].Solids[0].CenterOfMass)+"\n"
except:
None
# Vertexes de l'objet
try:
a = Gui.Selection.getSelectionEx()[0].SubObjects[0].Vertexes
aa = 0
for a0 in range(len(a)):
aa += 1
App.Console.PrintMessage("Vertexes Obj : X"+str(aa)+": "+str(a[a0].Point.x)+", Y"+str(aa)+ ": "+str(a[a0].Point.y)+", Z"+str(aa)+ ": "+str(a[a0].Point.z)+"\n")
texteInfo += "Vertexes Obj : X"+str(aa)+": "+str(a[a0].Point.x)+", Y"+str(aa)+ ": "+str(a[a0].Point.y)+", Z"+str(aa)+ ": "+str(a[a0].Point.z)+"\n"
except:
# Vertexes de la forme
try:
compt_E = 0
perimetre = 0.0
for j in enumerate(sel[0].Shape.Edges):
compt_E+=1
perimetre += (sel[0].Shape.Edges[compt_E-1].Length)
a = sel[0].Shape.Edges[compt_E-1].Vertexes[0]
App.Console.PrintMessage("Vertexes Form : "+"X1: "+str(a.Point.x)+" Y1: "+str(a.Point.y)+" Z1: "+str(a.Point.z)+"\n")
texteInfo += "Vertexes Form : "+"X1: "+str(a.Point.x)+" Y1: "+str(a.Point.y)+" Z1: "+str(a.Point.z)+"\n"
a = sel[0].Shape.Edges[compt_E-1].Vertexes[1]
App.Console.PrintMessage(" : "+"X2: "+str(a.Point.x)+" Y2: "+str(a.Point.y)+" Z2: "+str(a.Point.z)+"\n")
texteInfo += " : "+"X2: "+str(a.Point.x)+" Y2: "+str(a.Point.y)+" Z2: "+str(a.Point.z)+"\n"
App.Console.PrintMessage("Perimeter : "+str(perimetre)+"\n")
texteInfo += "Perimeter : "+str(perimetre)+"\n"
except:
None
None
ff = ui
ff.on_pushButton_Raf_clicked()
App.Console.PrintMessage("End_____________________________________________________________"+"\n")
s=SelObserver()
FreeCADGui.Selection.addObserver(s) # installe la fonction en mode résident
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
Links
Version
Prototype not finished