Macro Compound Plus/en: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 2: Line 2:
{{Macro
{{Macro
|Name=Macro Compound Plus
|Name=Macro Compound Plus
|Description={{ColoredText|#ff0000|#ffffff|New version GUI modifyed for the HD dpi (QGridLayout) run only FC version 0.19 and more (PySide2 Qt5)}}<br/><br/>For the precedent version see [https://gist.github.com/mario52a/7be361a8c489deec918f664fdcfc4394/11ae1a55229c84d9aab4e9a36099d90f52909958 Macro_Compound_Plus 00.02] and install it manually.<br/><br/>
|Description=Draf command set in a small macro.
Draft command set in a small macro for the 2D wire example: work with the DXF files. The macro detected : Line, Arc, Circle, Ellipse, BSplineCurve and reproduce the DXF wire in a Draft object. The text is converted in ShapeString.
|Author=Mario52
|Author=Mario52
|Version=00.02
|Version=00.03
|Date=2018-01-24
|Date=2020-05-14
|FCVersion=<= 0.17
|FCVersion= 0.19
|Download=[https://www.freecadweb.org/wiki/images/f/fd/Macro_Compound_Plus.png ToolBar Icon]
|Download=[https://www.freecadweb.org/wiki/images/f/fd/Macro_Compound_Plus.png ToolBar Icon]
}}
}}
Line 12: Line 13:
==Description==
==Description==


Draf command set in a small macro for the 2D sketch example: work with the DXF files
Draft command set in a small macro for the 2D wire example: work with the DXF files. The macro detected : Line, Arc, Circle, Ellipse, BSplineCurve and reproduce the DXF wire in a Draft object. The text is converted in ShapeString.


==Usage==
==Usage==
Line 18: Line 19:
[[File:Macro Compound Plus 00.png|Macro_Compound_Plus_00]]
[[File:Macro Compound Plus 00.png|Macro_Compound_Plus_00]]


===Choice===
*{{KEY|Compound I}} Type I [1 + 1 = 1] : Create one compound unique of all objects selected without history.
*{{KEY|Compound II}} Type II [1 + 1 = A (1 + 1)] : Create one compound of all objects selected with history of all objects. Same "'''Menu > Part > Make compound'''".
*{{Button|[[Image:Part_Compound.svg|16px]] Compound I}} Type I [1 + 1 = 1] : Create one compound unique of all objects selected without history.
*{{Button|[[Image:Part_Compound.svg|16px]] Compound II}} Type II [1 + 1 = A (1 + 1)] : Create one compound of all objects selected with history of all objects. Same "'''Menu → Part → Make compound'''".
*Option lines:

** Line colour : Gives a colour to object.
==={{CheckBox}} Option color===
** Width line : Gives a thickness to line(s).
If it {{CheckBox}} checked the colour to object to work are coloured (edge, vertex)
*{{KEY| Convert (A)}} = convert the text [[File:Draft_Text.png]] in a shape string [[File:Draft_ShapeString.png]] (The thickness of the text converted is respected but the visual result may not be respected, see the Combo view property for confirm)
*{{Button|{{ColoredText|#ff0000|[[Image:Workbench_Image.svg|16px]] Color}} }} : Gives a colour to object. (Default Red 255, 0, 0)
*{{KEY| 8.00 }} : Gives a thickness of the character and font Family.

*{{KEY|Convert Edge}} : This command convert the wire in one line with coordinates. (ex: one compound downgraded does not have coordinates, this function create a line with coordinates)
===Tools===
*For Compound I and Convert Edge
* LineEdit : display (Iindex of Font / Number of font) the path and name of the font.
This section work only with the menus {{KEY|Compound I}}, {{KEY|Convert (A)}} and {{KEY|Convert Edge}}
*{{Button|[[File:Draft_Text.svg|16px]] Convert Text (A)}} : convert the text [[File:Draft_Text.svg|16px]] in a shape string [[File:Draft_ShapeString.svg|16px]] (The height of the text converted is respected but the visual result may not be respected, see the Combo view property for confirm). (A) is Automatic value height of text.
*{{KEY|None}} : Everything originals objects remains as it is.
**{{SpinBox|0,00 Auto}} : If the spinbox is egual 0.0 the heigth of the VALUE of the text is respected, if other of 0.0 the {{Button|[[File:Draft_Text.svg|16px]] Convert Text (A)}} change to {{Button|[[File:Draft_Text.svg|16px]] Convert Text (M)}} manual.
*{{KEY|Hidden original line(s)}} : Hidden the originals lines.

*{{KEY|Delete original line(s)}} : Delete the originals lines.
*{{Button|[[File:Draft_Line.svg|16px]] Convert Wire (A)}} : This command convert the wire in one line with coordinates. (ex: one compound downgraded does not have coordinates, this function create a line with the coordinate as Draft line and reproduce the DXF wire in a Draft object are detected: Line, Arc, Circle, Ellipse, BSplineCurve.
*{{KEY|Reset}} : Reset the macro
**{{SpinBox|0,00 Auto}} : Gives a thickness of the wire. If the spinbox is egual 0.0 the heigth of the VALUE of the text is respected, if other of 0.0 the {{Button|[[Image:Draft_Line.svg|16px]] Convert Wire (A)}} change to {{Button|Convert Wire (M)}} manual.
*{{KEY|DownGrade}} : Downgrade the objects, same [[File:Draft_Downgrade.png]].
*{{CheckBox|[[Image:Draft_BezCurve.svg|16px]] BezierCurve}} : By default the BezierCurve detected is [[Image:Draft_BezCurve.svg|24px]], if it is checked the BezierCurve is Cubic [[Image:Draft_CubicBezCurve.svg|24px]] and the button change {{CheckBox|TRUE|[[Image:Draft_CubicBezCurve.svg|16px]] Cubic BezierCurve}}
*{{KEY|Quit}} : Quit the macro, bye

*{{RadioButton|TRUE|[[Image:Std_DrawStyleFlatLines.svg|16px]] FlatLines}} : The objects created is FlatLines.
*{{RadioButton|[[Image:Std_DrawStyleWireFrame.svg|16px]] Wireframe}} : The objects created is Wireframe.
*{{RadioButton|[[Image:Std_DrawStylePoints.svg|16px]] Points}} : The objects created is Points.
*{{Button|[[File:Draft_Upgrade.svg|16px]] UpGrade}} : UpGrade
*{{Button|[[File:Draft_Downgrade.svg|16px]] DownGrade}} : DownGrade

===For Compound I and Convert Edge===
This section work only with the tools {{Button|[[Image:Part_Compound.svg|16px]] Compound I}}, {{Button|[[File:Draft_Text.svg|16px]] Convert Text (A)}} and {{Button|[[File:Draft_Line.svg|16px]] Convert Wire (A)}}
*{{RadioButton|TRUE|None}} : Everything originals objects remains as it is.
*{{RadioButton|Hidden original objest(s)}} : Hidden the originals objest(s).
*{{RadioButton|Delete original objest(s)}} : Delete the originals objest(s).

===Command===
*ProgressBar
*{{Button|Reset}} : Reset the macro
*{{Button|Quit}} : Quit the macro, bye
*{{Button|Help}} : Display the wiki page in the FreeCAD browser

==Script==
==Script==
The icon for you toolBar [[File:Macro Compound Plus.png]] copy in same directory to the macro
The icon for you toolBar [[File:Macro Compound Plus.png]] copy in same directory to the macro
Line 40: Line 60:


The script to github [https://gist.github.com/mario52a/7be361a8c489deec918f664fdcfc4394 Macro_Compound_Plus.FCMacro]
The script to github [https://gist.github.com/mario52a/7be361a8c489deec918f664fdcfc4394 Macro_Compound_Plus.FCMacro]

<br /><br />'''Macro_Compound_Plus.FCMacro'''<br />
'''Macro_Compound_Plus.FCMacro'''
{{Code|code=

{{MacroCode|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals
"""
"""
***************************************************************************
***************************************************************************
* Copyright (c) 2016 2017 2018 <mario52> *
* Copyright (c) 2016 2017 2018 1019 2020 <mario52> *
* *
* *
* This file is a supplement to the FreeCAD CAx development system. *
* This file is a supplement to the FreeCAD CAx development system. *
Line 55: Line 77:
* the License, or (at your option) any later version. *
* the License, or (at your option) any later version. *
* for detail see the LICENCE text file. *
* for detail see the LICENCE text file. *
* *
** **
* Use at your own risk. The author assumes no liability for data loss. *
* It is advised to backup your data frequently. *
* If you do not trust the software do not use it. *
** **
* This software is distributed in the hope that it will be useful, *
* This software is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
Line 70: Line 96:
***************************************************************************
***************************************************************************
"""
"""
#Macro_Compound_Plus 05/08/2016 /_00 24/01/2018
#Macro_Compound_Plus 05/08/2016 /_00 24/01/2018 /.02 2018-01-24/.03 2020/05/12
#
#
#OS: Windows 10
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.16.6706 (Git)
#Version: 0.19.20802 (Git)
#Build type: Release
#Build type: Release
#Branch: releases/FreeCAD-0-16
#Branch: master
#Hash: f4279f1bea8377a7ef63f7f4c69b67159d498965
#Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0
#Python version: 2.7.8
#Python version: 3.6.8
#Qt version: 4.8.7
#Qt version: 5.12.1
#Coin version: 4.0.0a
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#OCC version: 7.3.0
#Locale: French/Mars (fr_MA)
#
#Icon.fromTheme by FreeCAD
#
#
__title__ = "Macro_Compound_Plus"
__title__ = "Macro_Compound_Plus"
__author__ = "Mario52"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__url__ = "https://wiki.freecadweb.org/Macro_Compound_Plus"
__version__ = "00.02"
__version__ = "00.03"
__date__ = "24/01/2018"
__date__ = "2020/05/14" #YYYYMMDD
__icon__ = "https://wiki.freecadweb.org/images/f/fd/Macro_Compound_Plus.png"
__gistLoc__ = "https://gist.github.com/mario52a/7be361a8c489deec918f664fdcfc4394"
#
import PySide2
from PySide2 import (QtWidgets, QtCore, QtGui)
from PySide2.QtWidgets import (QWidget, QApplication, QSlider, QGraphicsView, QGraphicsScene, QVBoxLayout, QStyle)
from PySide2.QtGui import (QPainter, QColor, QIcon)
from PySide2.QtSvg import *
import PySide2.QtXml


import Draft, Part, PartGui, FreeCADGui, FreeCAD
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
from FreeCAD import Base
from FreeCAD import Vector

import math
from math import sqrt, pi, sin, cos, asin, degrees, radians
import re
import operator
from operator import itemgetter, attrgetter, methodcaller # pour sort
App = FreeCAD
App = FreeCAD
Gui = FreeCADGui
doc = App.activeDocument()


import os, time, sys
try:
import platform
_fromUtf8 = QtCore.QString.fromUtf8
import WebGui
except AttributeError:
def _fromUtf8(s):
return s


global doc ; doc = App.activeDocument()
try:
global ui ; ui = ""
_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)


#### Test FreeCAD.Version simple ############################################################################################################
def errorDialog(msg):
if int(FreeCAD.Version()[1]) < 19: # Version de FreeCAD
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
FreeCAD.Console.PrintError("This version " + __title__ + " rmu work with the FreeCAD 0.19 or higher." + "\n\n")
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide #cette fonction met la fenetre en avant
FreeCAD.Console.PrintError("SOME FUNCTIONS MAY NOT WORK PROPERLY " + "\n\n")
# diag.setWindowModality(QtCore.Qt.ApplicationModal) # la fonction a ete desactivee pour favoriser "WindowStaysOnTopHint"
FreeCAD.Console.PrintError("For the precedent version see the page " + "\n\n")
diag.exec_()
FreeCAD.Console.PrintError("https://gist.github.com/mario52a/7be361a8c489deec918f664fdcfc4394" + "\n\n")
#### Test FreeCAD.Version simple ############################################################################################################
setIconTTF = [
"16 16 6 1",
" c None",
". c #204A87",
"+ c None",
"@ c #729FCF",
"# c #CC0000",
"$ c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++#####++++@@+@",
".+++$#$$$++@+@+@",
".++++#$+++++++@+",
".++++#$#####++++",
".++++#$+$#$$$+++",
".++++#$++#$+++++",
".@++++$++#$+###+",
".@@++++++#$+#$$$",
"..@@+++++#$+#$++",
"...@@+++++$+###+",
"....@@++++++#$$$",
".....@@+++++#$++",
"......@@+++++$++",
"................"]


setIconFON = [
import os, sys, platform
"16 16 6 1",
" c None",
". c #204A87",
"+ c None",
"@ c #F57900",
"# c #CC0000",
"$ c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++###++++++@@+@",
".++#$$$++++@+@+@",
".++#$+++++++++@+",
".++###+###++++++",
".++#$$$#$#$+++++",
".++#$++#$#$+++++",
".@++$++#$#$##+#+",
".@@++++#$#$##$#$",
"..@@+++###$#$##$",
"...@@+++$$$#$##$",
"....@@+++++#$+#$",
".....@@++++#$+#$",
"......@@++++$++$",
"................"]

setIconOTF = [
"16 16 6 1",
" c None",
". c #204A87",
"+ c None",
"@ c #4E9A06",
"# c #CC0000",
"$ c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++###++++++@@+@",
".++#$#$++++@+@+@",
".++#$#$+++++++@+",
".++#$#$###++++++",
".++#$#$+#$$+++++",
".++###$+#$++++++",
".@++$$$+#$+###++",
".@@+++++#$+#$$$+",
"..@@++++#$+#$+++",
"...@@++++$+###++",
"....@@+++++#$$$+",
".....@@++++#$+++",
"......@@++++$+++",
"................"]

setIconPOL = [
"16 16 12 1",
" c None",
". c #204A87",
"+ c None",
"@ c #06989A",
"# c #73D216",
"$ c #000000",
"% c #75507B",
"& c #729FCF",
"* c #CC0000",
"= c #F57900",
"- c #EDD400",
"; c #4E9A06",
".+++++++++++@#$%",
".++++++++$+#++&$",
".++***++++++=@+%",
".++*-*-++++*+&+$",
".++*-*-+++++++*+",
".++***-***++++++",
".++*---*-*-+++++",
".++*-++*-*-+++++",
".$++-++*-*-*++++",
".*@++++*-*-*-+++",
"..#*+++***-*-+++",
"...;#+++---*-+++",
"....%=+++++*-+++",
".....;$++++****+",
"......@%++++----",
"................"]

#path#################################################################
global path #
#path = FreeCAD.ConfigGet("AppHomePath") # path FreeCAD installation
#path = FreeCAD.ConfigGet("UserAppData") # path FreeCAD User data
#path = "your path" # your directory path
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") # macro path
path = param.GetString("MacroPath","") + "/" # macro path
path = path.replace("\\","/") # convert the "\" to "/"
#FreeCAD.Console.PrintMessage( "Path for the icons : " + path + "\n")#
######################################################################

#### matplotlib #################################################################
#import glob
#files_TTF = glob.glob(self.pathFont + "/*.TTF")

##################################
import matplotlib
import matplotlib.font_manager
import matplotlib.font_manager as fontman
import matplotlib.font_manager as fontconfig
from matplotlib.font_manager import FontProperties

#from matplotlib.ft2font import FT2Font
##################################

global newPolicePath
global PolicePath
global PolicePath
global nomPolice
global nomPolice


if platform.system() == "Windows" :
####### detect platform meme dans reset ###################
if platform.system() == "Windows" :
PolicePath = "C:/Windows/Fonts/ARIAL.TTF"
PolicePath = "C:/Windows/Fonts/ARIAL.TTF"
elif platform.system() == "Linux" :
elif platform.system() == "Linux" :
Line 136: Line 298:
PolicePath = "C:/Windows/Fonts/ARIAL.TTF"
PolicePath = "C:/Windows/Fonts/ARIAL.TTF"


nomPolice = os.path.basename(PolicePath).split('.')[0]
nomPolice = os.path.basename(PolicePath).split('.')[0]
newPolicePath = os.path.dirname(PolicePath).split('.')[0]

#### matplotlib #################################################################
#### Config Begin matplotlib font #######################
# # https://en.wikipedia.org/wiki/Web_colors
global setColorTTF ; setColorTTF = "blue" # .TTF color by "extension name" or hexa "#0000FF"
global setColorFON ; setColorFON = "orange" # .FON color by "extension name" or hexa "#FFA500"
global setColorOTF ; setColorOTF = "green" # .OTF color by "extension name" or hexa "#008000"
global setColorPOL ; setColorPOL = "black" # .OTHER color by "extension name" or hexa "#000000"
#####
global switchModeTextList; switchModeTextList= 1 # 0 = mode text normal (et noir) coupe le switchFontComBox
# 1 = permet le switchFontComBox 1 (default)
#####
global switchFontComBox ; switchFontComBox = 1 # 0 = (et switchModeTextList= 1) mode texte (en couleur) dans liste ComboBox plus rapide
# 1 = (et switchModeTextList= 1) fontFamily dans liste ComboBox plus lent mais plus beau! (default)
#####
global setSystemFonts ; setSystemFonts = 1 # 0 = matplotlib.font_manager.findSystemFonts("C:/", "ttf")
# fait toutes les fontes (dans tous les dossiers et sous dossiers du DD) time !!
# 1 = fontman.findSystemFonts(self.pathFont)
# fait toutes les fontes du repertoire (et dans tous les sous dossiers) (default)
#####
global seTtextAlignement ; seTtextAlignement = 0 # 0 = AlignLeft (default)
# 1 = AlignCenter
# 2 = AlignRight
#####
#### Config End matplotlib font #########################

#### matplotlib #################################################################

def createSpace(texte): # detecte majuscule et ajoute un espace devant la lettre
# return createSpace(TexTe) = Tex Te , if createSpace(TEXTE) = TEXTE
if texte.isupper():
stringSpace = texte
else:
try:
stringSpace = texte[0]
for i in texte[1:]:
if re.search(r"[A-Z]", i): i = " " + i
stringSpace += i
except Exception:
stringSpace = texte
return stringSpace

def family(chaine):
# return family(chaine)[1] = Family , family(chaine)[2] = typeCar (form [a, b, c ...]
famille = typeCar = ""
try:
if chaine.find('-') != -1:
famille = chaine[:chaine.find('-')]
typeCar = chaine[chaine.find('-')+1:]
else:
famille = chaine
typeCar = ""
except Exception:
famille = chaine
typeCar = ""
typeCar = str(createSpace(typeCar)).split()
return [createSpace(famille), typeCar]

class MyLabelPatience(): # fenetre image d'attente de chargement
global path
label = QtWidgets.QLabel()
label.setText("<img src=" + path + "Macro_Compound_Plus.png><b><center>Wait please</center> \n\n<center>i search the fonts !\n\n</right></b>")
ecran = FreeCADGui.getMainWindow().frameGeometry()
xF = 250; yF = 120
xW = (ecran.width()/2) - (xF/2)
yW = (ecran.height()/2)- (yF/2)
label.setGeometry(xW, yW, xF, yF)
label.setStyleSheet("QLabel {background-color : #F0C300;font: 12pt; }");
label.setWindowFlags(PySide2.QtCore.Qt.WindowFlags(PySide2.QtCore.Qt.FramelessWindowHint)) # pas de bords
label.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant
#### matplotlib #################################################################

def unsignedDecode(value, mode = 0): # mode 0 = entier, mode 1 = float (a partir de ex: 4283773951)
# 4283773951 = [255 85 51 255] = [red, green, blue, transparent]
value = hex(value)
# print(value)
a1 = value[0:2]
a2 = "000000000" + value[2:]
a2 = a2[len(a2)-8:]
value = a1 + a2
if mode == 0: # for button
red = int(value[2:4 ],16)
green = int(value[4:6 ],16)
blue = int(value[6:8 ],16)
transparent = int(value[8:10],16)
else: # for FreeCAD object
red = float(int(value[2:4 ],16) / 255.0)
green = float(int(value[4:6 ],16) / 255.0)
blue = float(int(value[6:8 ],16) / 255.0)
transparent = float(int(value[8:10],16) / 255.0)
return [red, green, blue, transparent]

def unsignedEncode(red = 0, green = 0, blue = 0, transparent = 255): # convert red, green, blue, transparence to unique number
#(255 *256*256*256 ) + (85 *256*256) + (51 *256) +(255) = 4283773951
value = (red *256*256*256 ) + (green *256*256) + (blue *256) + (transparent)
return value

#write parameter
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/FCMmacro/FCTexture").SetString("Path",pathFile)
#read parameter
#pathFile = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/FCMmacro/FCTexture").GetString("Path")

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s


class Ui_Compound(object):
class Ui_Compound(object):


def __init__(self):
def __init__(self):
#self.path = "Your Path"
global path
global nomPolice
#self.path = FreeCAD.ConfigGet("AppHomePath")

self.path = FreeCAD.ConfigGet("UserAppData")
self.path = path
self.nameL = []
self.nameL = []
self.comP = []
self.comP = []
del self.nameL[:]
del self.nameL[:]
del self.comP[:]
del self.comP[:]
self.red = 255.0
self.green = 0.0
self.blue = 0.0


self.lineWidth = 2.0
self.lineWidth = 0.0
self.font = ""
self.TextLabel = ""
self.TextLabel = ""
self.TextLabelText = ""
self.TextLabelText = ""
Line 159: Line 426:
self.TextFontSize = 8.0
self.TextFontSize = 8.0
self.TextTextColor = ""
self.TextTextColor = ""
self.FontSize = 8.0
self.fonte = ""
self.fonte = ""
self.fontSizeManual= False
self.fontGlobal_08 = "" # pour compatibilite Windows Linux pour tous les textes
self.manuel = False
self.lineSizeManual= False


global PolicePath
####font textEdit
global nomPolice
self.nomPolice = "Arial"
self.FontTextSize = 20
# self.pathFont = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.FontsLocation) # path font search
# self.fonteComp = self.pathFont + "/" + self.nomPolice + ".TTF"
self.fonteComp = ""
# self.fonteComp = self.fonteComp.replace("\\","/")
self.font = QtGui.QFont()
####font textEdit
self.FontSize = 0.0

# for button
self.red = 255 #204.0
self.green = 0 #204.0
self.blue = 0 #204.0
self.alpha = 255 #255 = visibility max (opacity)

# for object FC
self.redFL = 1.0
self.greenFL = 0.0
self.blueFL = 0.0
self.alphaFL = 1.0 # 1.0 = visibility max (opacity)

self.tableau = [] #Index (), [chemin plus nom fichier (nomPathPolice), nom sans extension (nomSimple), nomSimpleExt (nomSimple + Ext)]
self.index = 0 #Index ()

#### font ######################
def searchFont(self,pathSearch):
global setSystemFonts
global seTtextAlignement
global switchFontComBox
global switchModeTextList

MyLabelPatience.label.show()
FreeCADGui.updateGui() # rafraichi l'ecran

files_All_Fonts = ""
##https://matplotlib.org/_modules/matplotlib/font_manager.html
if setSystemFonts == 0:
files_All_Fonts = matplotlib.font_manager.findSystemFonts(pathSearch, "ttf") # fait toutes les fontes ? ()
else:
files_All_Fonts = fontman.findSystemFonts(pathSearch) # fait toutes les fontes (et dans tous les sous dossiers)

if len(files_All_Fonts) > 0:
self.tableau = []
self.index = 0

for fonte in files_All_Fonts:
####
nomPathPolice = nomFichier = nomSimpleExt = nomSimple = nomExtension = nameName = ""

nomPathPolice = fonte.replace("\\","/") # convert the "\" to "/"
nomFichier = nomPathPolice.split("/") # complet split
nomSimpleExt = nomFichier[-1] # nom avec extension
nomSimple = nomFichier[-1][:-4] # nom sans extension
nomExtension = nomSimpleExt[nomSimpleExt.rfind('.')+1:].upper() # extension
####
try:
# nameFamily = matplotlib.font_manager.FontProperties(fname=fonte).get_family() ##['sans-serif']
# nameStyle = matplotlib.font_manager.FontProperties(fname=fonte).get_style() #normal
# nameVariant = matplotlib.font_manager.FontProperties(fname=fonte).get_variant() #normal
# nameWeight = matplotlib.font_manager.FontProperties(fname=fonte).get_weight() #normal
# nameStretch = matplotlib.font_manager.FontProperties(fname=fonte).get_stretch() #normal
# nameFileComp = matplotlib.font_manager.FontProperties(fname=fonte).get_file() ##c:\windows\fonts\NotoNaskhArabicUI-Regular.ttf
# nameSize = matplotlib.font_manager.FontProperties(fname=fonte).get_size() #10.0
nameName = matplotlib.font_manager.FontProperties(fname=fonte).get_name() ##Noto Naskh Arabic UI
# nameSizePoint = matplotlib.font_manager.FontProperties(fname=fonte).get_size_in_points() #10.0
# nameSlant = matplotlib.font_manager.FontProperties(fname=fonte).get_slant() #normal
# namePattern = matplotlib.font_manager.FontProperties(fname=fonte).get_fontconfig_pattern() #:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:file=c:\windows\fonts\NotoNaskhArabicUI-Regular.ttf:size=10.0
except Exception:
nameFamily = nameStyle = nameVariant = nameWeight = nameStretch = nameFileComp = nameSize = nameName = nameSizePoint = nameSlant = namePattern = ""
####
if nameName == "" :
nameName = nomSimple
self.tableau.append([0, nomPathPolice, nomSimple, nomSimpleExt.upper(), nomExtension.upper(), nameName])
self.tableau = sorted(self.tableau, key=itemgetter(3)) # sorted by nomSimple.upper()

try:
for line in range(len(self.tableau)): # enleve les doubles (bon)
if self.tableau[line][2] == self.tableau[line + 1][2]: # enleve les doubles (bon)
del(self.tableau[line + 1]) # enleve les doubles (bon)
except Exception:
None

self.comboBoxPy.clear()
for line in range(len(self.tableau)):
try:
self.tableau[line][0] = line # ajoute le numero de ligne
if self.tableau[line][2].upper() == "ARIAL": # detecte la fonte de base
self.index = line
####Section common color and font begin ######################
model = self.comboBoxPy.model()

if switchModeTextList == 1:
if self.tableau[line][4] == "TTF":
item = QtGui.QStandardItem(QtGui.QPixmap(setIconTTF), str(line))
item.setForeground(QtGui.QColor(setColorTTF))
elif self.tableau[line][4] == "FON":
item = QtGui.QStandardItem(QtGui.QPixmap(setIconFON), str(line))
item.setForeground(QtGui.QColor(setColorFON))
elif self.tableau[line][4] == "OTF":
item = QtGui.QStandardItem(QtGui.QPixmap(setIconOTF), str(line))
item.setForeground(QtGui.QColor(setColorOTF))
else:
item = QtGui.QStandardItem(QtGui.QPixmap(setIconPOL), str(line))
item.setForeground(QtGui.QColor(setColorPOL))

if seTtextAlignement == 0:
item.setTextAlignment(QtCore.Qt.AlignLeft)
elif seTtextAlignement == 1:
item.setTextAlignment(QtCore.Qt.AlignCenter)
elif seTtextAlignement == 2:
item.setTextAlignment(QtCore.Qt.AlignRight)
else:
self.comboBoxPy.addItem(self.tableau[line][2])
model.appendRow(item)
else:
self.comboBoxPy.addItem("")
self.comboBoxPy.setItemText(line, self.tableau[line][2])
####Section item color and font end ##########################
####Section setfont Family switchFontComBox begin#############
if (switchFontComBox == 1) and (switchModeTextList == 1):
typeCar = font = ""
font = QtGui.QFont()
#font = item.font()
typeCar = family(self.tableau[line][2])[1]
font.setBold(False)
font.setItalic(False)
if len(typeCar) > 0:
for option in typeCar:
if option == "Bold":
font.setBold(True)
if (option == "Italic") or (option == "It") or (option == "Slanted"):
font.setItalic(True)
if option == "Oblique":
font.setItalic(True)
#'Bold''Regular''Slanted''Italic''Medium''Extra''Light''Condensed''Black''It''Semibold'
font.setFamily(self.tableau[line][5])
font.setPixelSize(15)
if switchModeTextList == 1:
item.setFont(font)
else:
self.comboBoxPy.addItem("")
####Section setfont Family switchFontComBox end###############

except Exception:
FreeCAD.Console.PrintMessage("searchFont()" + "\n")
None
self.lineEdit_NameFile.setText("(" + str(self.index + 1) + "/" + str(len(self.tableau)) + ") " + self.tableau[self.index][1])
#print(len(self.tableau))
#for i in self.tableau:
# print(i)
self.comboBoxPy.setCurrentIndex(self.index)
self.fonteComp = self.tableau[self.index][1]
MyLabelPatience.label.close()

#### font ######################


def setupUi(self, MainWindow):
def setupUi(self, MainWindow):
global PolicePath
global PolicePath
global nomPolice
global setSystemFonts
global setColorTTF
global setColorFON
global setColorOTF
global setColorPOL
global seTtextAlignement
global switchFontComBox
global switchModeTextList
global ui


self.window = MainWindow
self.window = MainWindow


Compound.setObjectName(_fromUtf8("Compound"))
Compound.setObjectName("Compound")
Compound.resize(250, 440)
Compound.resize(250, 440)
MainWindow.setMinimumSize(QtCore.QSize(250, 440))
# MainWindow.setMinimumSize(QtCore.QSize(250, 440))
MainWindow.setMaximumSize(QtCore.QSize(250, 440))
# MainWindow.setMaximumSize(QtCore.QSize(250, 440))


self.centralwidget = QtGui.QWidget(Compound)
self.centralwidget = QtWidgets.QWidget(Compound)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.centralwidget.setObjectName("centralwidget")


self.groupBox = QtWidgets.QGroupBox()
self.fontGlobal_08 = QtGui.QFont() # pour compatibilite Windows Linux pour tous les textes
self.fontGlobal_08.setFamily("Arial") # pour compatibilite Windows Linux pour tous les textes
self.fontGlobal_08.setPointSize(8.0) # pour compatibilite Windows Linux pour tous les textes


self.PB_01_Compound_01 = QtGui.QPushButton(self.centralwidget)
self.groupBox_Choice = QtWidgets.QGroupBox()

self.PB_01_Compound_01.setGeometry(QtCore.QRect(10, 40, 75, 23))
self.PB_01_Compound_01.setFont(self.fontGlobal_08)
self.PB_01_Compound_01 = QtWidgets.QPushButton()
self.PB_01_Compound_01.setToolTip("Make a compound Block unique")
self.PB_01_Compound_01.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Part_Compound.svg")))
self.PB_01_Compound_01.setObjectName(_fromUtf8("PB_01_Compound_01"))
self.PB_01_Compound_01.clicked.connect(self.on_PB_01_Compound_01) #
self.PB_01_Compound_01.clicked.connect(self.on_PB_01_Compound_01) #


self.PB_02_Compound_02 = QtGui.QPushButton(self.centralwidget)
self.label_02_Type_1 = QtWidgets.QLabel()

self.PB_02_Compound_02.setGeometry(QtCore.QRect(10, 70, 75, 23))
self.PB_02_Compound_02.setFont(self.fontGlobal_08)
self.PB_02_Compound_02 = QtWidgets.QPushButton()
self.PB_02_Compound_02.setToolTip("Make a compound same Part, Menu > Part > Make compound")
self.PB_02_Compound_02.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Part_Compound.svg")))
self.PB_02_Compound_02.setObjectName(_fromUtf8("PB_02_Compound_02"))
self.PB_02_Compound_02.clicked.connect(self.on_PB_02_Compound_02) #
self.PB_02_Compound_02.clicked.connect(self.on_PB_02_Compound_02) #


self.groupBox_00 = QtGui.QGroupBox(self.centralwidget)
self.label_03_Type_2 = QtWidgets.QLabel()

self.groupBox_00.setGeometry(QtCore.QRect(10, 100, 231, 91))
self.groupBox_00.setAlignment(Qt.AlignLeft) # AlignLeft AlignCenter AlignRight
self.groupBox_00 = QtWidgets.QGroupBox()
self.groupBox_00.setFont(self.fontGlobal_08)
# self.groupBox_00.setAlignment(QtWidgets.AlignLeft) # AlignLeft AlignCenter AlignRight
self.groupBox_00.setToolTip("If this box is unchecked the colors attributes and width line\n"
"of the original line(s) are not modified\n"
"This chekBox work only with Compound II\n"
"Same attributes Part, Menu > Part > Make compound")
self.groupBox_00.setCheckable(True)
self.groupBox_00.setCheckable(True)
self.groupBox_00.setObjectName(_fromUtf8("groupBox_00"))
self.groupBox_00.setChecked(False)
self.groupBox_00.clicked.connect(self.on_groupBox_00) #


self.PB_03_Color = QtGui.QPushButton(self.groupBox_00)
self.PB_03_Color = QtWidgets.QPushButton()
self.PB_03_Color.setGeometry(QtCore.QRect(10, 30, 75, 23))
self.PB_03_Color.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/colors.svg")))
self.PB_03_Color.setFont(self.fontGlobal_08)
self.PB_03_Color.setToolTip("Change the color of object(s) selected(s) value by defaut rvb 255,0,0")
self.PB_03_Color.setObjectName(_fromUtf8("PB_03_Color"))
self.PB_03_Color.clicked.connect(self.on_PB_03_Color) #
self.PB_03_Color.clicked.connect(self.on_PB_03_Color) #
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+"); color: cmj("+str(255)+","+str(255)+","+str(255)+")")
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+")")


self.DS_01_Width = QtGui.QDoubleSpinBox(self.groupBox_00)
self.groupBox_Tools = QtWidgets.QGroupBox()
self.DS_01_Width.setGeometry(QtCore.QRect(10, 60, 73, 22))
self.DS_01_Width.setFont(self.fontGlobal_08)
self.DS_01_Width.setToolTip("Give a new width for the line(s) selected(s)")
self.DS_01_Width.setObjectName(_fromUtf8("DS_01_Width"))
self.DS_01_Width.setValue(self.lineWidth)
self.DS_01_Width.valueChanged.connect(self.on_DS_01_Width_valueChanged) #


self.PB_04_Convert = QtGui.QPushButton(self.centralwidget)
self.lineEdit_NameFile = QtWidgets.QLineEdit()
self.PB_04_Convert.setGeometry(QtCore.QRect(10, 200, 75, 23))
self.comboBoxPy = QtWidgets.QComboBox()
####
self.PB_04_Convert.setFont(self.fontGlobal_08)
#self.pathFont = PolicePath[:-10]
self.PB_04_Convert.setToolTip("Convert the selected text in ShapeString\n"
self.pathFont = PolicePath[:len(PolicePath)-(PolicePath[::-1].index("/"))-1]
"By default Convert (A)utomatic use the font preselected and the size of original text\n"
####
"If the values or font is modified the button change of Convert (M)anual\n"
"The label of the texte are modified to SString_original text (max 30 characters)")
self.PB_04_Convert.setObjectName(_fromUtf8("PB_04_Convert"))
self.PB_04_Convert.clicked.connect(self.on_PB_04_Convert) # ""


self.PB_04_Convert_Text = QtWidgets.QPushButton()
if platform.system() == "Windows" :
self.PB_04_Convert_Text.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_Text.svg")))
self.fontComboBox = QtGui.QFontComboBox(self.centralwidget)
self.PB_04_Convert_Text.clicked.connect(self.on_PB_04_Convert_Text) # ""
self.fontComboBox.setGeometry(QtCore.QRect(100, 225, 141, 35))
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)


# self.fontComboBox.setFont(self.fontGlobal_08)
ui.searchFont(self.pathFont)
QtCore.QObject.connect(self.comboBoxPy, QtCore.SIGNAL("currentIndexChanged(int)"), self.on_fontComboBoxPython)
self.fontComboBox.setCurrentFont(font)
self.fontComboBox.setToolTip("New font.\nActual : "+nomPolice)
self.fontComboBox.setObjectName(_fromUtf8("fontComboBox"))
self.fontComboBox.currentFontChanged.connect(self.on_PB_Fonte_Win01) #


self.DS_02_Width_Font = QtGui.QDoubleSpinBox(self.centralwidget)
self.DS_02_Size_Font = QtWidgets.QDoubleSpinBox()
self.DS_02_Width_Font.setGeometry(QtCore.QRect(10, 230, 73, 22))
self.DS_02_Size_Font.setValue(0.0)
self.DS_02_Width_Font.setFont(self.fontGlobal_08)
self.DS_02_Size_Font.setSuffix(" Auto")
self.DS_02_Size_Font.valueChanged.connect(self.on_DS_02_Size_Font_valueChanged) #
self.DS_02_Width_Font.setToolTip("Give a new width for the font")
self.DS_02_Width_Font.setObjectName(_fromUtf8("DS_02_Width_Font"))
self.DS_02_Width_Font.setValue(self.FontSize)
self.DS_02_Width_Font.valueChanged.connect(self.on_DS_02_Width_Font_valueChanged) #


else: # Linux +
self.line = QtWidgets.QFrame()
self.line.setFrameShape(QtWidgets.QFrame.HLine)
import os.path
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
nomPolice = os.path.basename(PolicePath).split('.')[0]
self.PB_Fonte_Linux = QtGui.QPushButton(self.centralwidget)
self.PB_Fonte_Linux.setGeometry(QtCore.QRect(100, 225, 141, 35))
font = QtGui.QFont()
font.setFamily(nomPolice)


self.PB_04c_Convert_Edge = QtWidgets.QPushButton()
font.setPointSize(self.FontSize)
self.PB_04c_Convert_Edge.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_Line.svg")))
self.PB_Fonte_Linux.setFont(font)
self.PB_04c_Convert_Edge.clicked.connect(self.on_PB_04c_Convert_Edge) # ""
self.PB_Fonte_Linux.setToolTip(_fromUtf8("New font.\nActual : "+nomPolice))
self.PB_Fonte_Linux.setAccessibleDescription(_fromUtf8(""))
self.PB_Fonte_Linux.setText(_fromUtf8(nomPolice))
self.PB_Fonte_Linux.setObjectName(_fromUtf8("PB_Fonte_Linux"))
self.PB_Fonte_Linux.clicked.connect(self.on_PB_Fonte_Linux)


self.DS_02_Width_Font = QtGui.QDoubleSpinBox(self.centralwidget)
self.DS_01_Width_Line = QtWidgets.QDoubleSpinBox()
self.DS_02_Width_Font.setGeometry(QtCore.QRect(10, 230, 75, 23))
self.DS_01_Width_Line.setValue(0.0) #self.lineWidth
self.DS_02_Width_Font.setFont(self.fontGlobal_08)
self.DS_01_Width_Line.setSuffix(" Auto")
self.DS_01_Width_Line.valueChanged.connect(self.on_DS_01_Width_Line_valueChanged) #
self.DS_02_Width_Font.setToolTip("Give a new width for the font")
self.DS_02_Width_Font.setObjectName(_fromUtf8("DS_02_Width_Font"))
self.DS_02_Width_Font.setValue(self.FontSize)
self.DS_02_Width_Font.valueChanged.connect(self.on_DS_02_Width_Font_valueChanged) #


self.PB_04c_Convert_Edge = QtGui.QPushButton(self.centralwidget)
self.CB_BezierCurve = QtWidgets.QCheckBox()
self.CB_BezierCurve.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_BezCurve.svg")))
self.PB_04c_Convert_Edge.setGeometry(QtCore.QRect(10, 260, 75, 23))
self.PB_04c_Convert_Edge.setFont(self.fontGlobal_08)
self.CB_BezierCurve.clicked.connect(self.on_CB_BezierCurve_clicked)
self.PB_04c_Convert_Edge.setToolTip("Convert the edge to line with coordinates\n"
"Select the edge(s) in the 3D view")
self.PB_04c_Convert_Edge.setObjectName(_fromUtf8("PB_04c_Convert_Edge"))
self.PB_04c_Convert_Edge.clicked.connect(self.on_PB_04c_Convert_Edge) # ""


self.PB_05_Reset = QtGui.QPushButton(self.centralwidget)
self.RB_01_FlatLines = QtWidgets.QRadioButton()
self.RB_01_FlatLines.setIcon(QtGui.QIcon.fromTheme("Vieuw",QtGui.QIcon(":/icons/DrawStyleFlatLines.svg")))
self.PB_05_Reset.setGeometry(QtCore.QRect(10, 410, 75, 23))
self.PB_05_Reset.setFont(self.fontGlobal_08)
self.RB_01_FlatLines.setChecked(True)
self.PB_05_Reset.setToolTip("Reset the values")
self.RB_02_Wireframe = QtWidgets.QRadioButton()
self.RB_02_Wireframe.setIcon(QtGui.QIcon.fromTheme("Vieuw",QtGui.QIcon(":/icons/DrawStyleWireFrame.svg")))
self.PB_05_Reset.setObjectName(_fromUtf8("PB_05_Reset"))
self.RB_03_Points = QtWidgets.QRadioButton()
self.PB_05_Reset.clicked.connect(self.on_PB_05_Reset) #
self.RB_03_Points.setIcon(QtGui.QIcon.fromTheme("Vieuw",QtGui.QIcon(":/icons/DrawStylePoints.svg")))


self.PB_06_Downgrade = QtGui.QPushButton(self.centralwidget)
self.groupBox_01 = QtWidgets.QGroupBox()
self.PB_06_Downgrade.setGeometry(QtCore.QRect(90, 410, 75, 23))
self.PB_06_Downgrade.setFont(self.fontGlobal_08)
self.PB_06_Downgrade.setToolTip("Downgrade the selected object Same Draft > Downgrade")
self.PB_06_Downgrade.setObjectName(_fromUtf8("PB_06_Downgrade"))
self.PB_06_Downgrade.clicked.connect(self.on_PB_06_Downgrade) #


self.PB_07_Quit = QtGui.QPushButton(self.centralwidget)
self.RB_01_Default = QtWidgets.QRadioButton()
self.PB_07_Quit.setGeometry(QtCore.QRect(170, 410, 75, 23))
self.RB_01_Default.setChecked(True)
self.PB_07_Quit.setFont(self.fontGlobal_08)
self.RB_02_Hidden = QtWidgets.QRadioButton()
self.PB_07_Quit.setToolTip("Quit Compound +")
self.RB_03_Delete = QtWidgets.QRadioButton()
self.RB_03_Delete.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogCancelButton))) #
self.PB_07_Quit.setObjectName(_fromUtf8("PB_06_Quit"))
# self.RB_03_Delete.setChecked(True)
self.PB_07_Quit.clicked.connect(self.on_PB_07_Quit) #


self.label_01_Titre = QtGui.QLabel(self.centralwidget)
self.PB_09_Upgrade = QtWidgets.QPushButton()
self.PB_09_Upgrade.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_Upgrade.svg")))
self.label_01_Titre.setGeometry(QtCore.QRect(10, 10, 231, 16))
self.PB_09_Upgrade.clicked.connect(self.on_PB_09_Upgrade) #
fontTitle = QtGui.QFont()
fontTitle.setPointSize(12)
self.label_01_Titre.setFont(fontTitle)
self.label_01_Titre.setObjectName(_fromUtf8("label_01_Titre"))


self.label_02_Type_1 = QtGui.QLabel(self.centralwidget)
self.PB_06_Downgrade = QtWidgets.QPushButton()
self.PB_06_Downgrade.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_Downgrade.svg")))
self.label_02_Type_1.setGeometry(QtCore.QRect(100, 40, 111, 16))
self.label_02_Type_1.setFont(self.fontGlobal_08)
self.PB_06_Downgrade.clicked.connect(self.on_PB_06_Downgrade) #
self.label_02_Type_1.setObjectName(_fromUtf8("label_02_Type_1"))


self.label_03_Type_2 = QtGui.QLabel(self.centralwidget)
self.groupBox_Command = QtWidgets.QGroupBox()
self.label_03_Type_2.setGeometry(QtCore.QRect(100, 70, 141, 16))
self.label_03_Type_2.setFont(self.fontGlobal_08)
self.label_03_Type_2.setObjectName(_fromUtf8("label_03_Type_2"))


self.label_04_Color = QtGui.QLabel(self.groupBox_00)
self.progressBar = QtWidgets.QProgressBar()
self.label_04_Color.setGeometry(QtCore.QRect(100, 30, 121, 16))
self.progressBar.setValue(0)
self.label_04_Color.setFont(self.fontGlobal_08)
self.progressBar.setAlignment(QtCore.Qt.AlignCenter)
self.label_04_Color.setObjectName(_fromUtf8("label_04_Color"))


self.label_05_DSBox = QtGui.QLabel(self.groupBox_00)
self.PB_05_Reset = QtWidgets.QPushButton()
self.PB_05_Reset.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogResetButton))) #
self.label_05_DSBox.setGeometry(QtCore.QRect(100, 60, 121, 16))
self.label_05_DSBox.setFont(self.fontGlobal_08)
self.PB_05_Reset.clicked.connect(self.on_PB_05_Reset) #
self.label_05_DSBox.setObjectName(_fromUtf8("label_05_DSBox"))


self.label_06_Convert = QtGui.QLabel(self.centralwidget)
self.PB_07_Quit = QtWidgets.QPushButton()
self.PB_07_Quit.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogCloseButton))) #
self.label_06_Convert.setGeometry(QtCore.QRect(100, 200, 141, 16))
self.label_06_Convert.setFont(self.fontGlobal_08)
self.PB_07_Quit.clicked.connect(self.on_PB_07_Quit) #
self.label_06_Convert.setObjectName(_fromUtf8("label_06_Convert"))


self.label_08_Convert_Line = QtGui.QLabel(self.centralwidget)
self.PB_08_Help = QtWidgets.QPushButton()
self.PB_08_Help.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_MessageBoxQuestion))) #
self.label_08_Convert_Line.setGeometry(QtCore.QRect(100, 260, 141, 16))
self.PB_08_Help.clicked.connect(self.on_PB_Help_clicked) #
self.label_08_Convert_Line.setFont(self.fontGlobal_08)
self.label_08_Convert_Line.setObjectName(_fromUtf8("label_08_Convert_Line"))


#### layout ###################################################
self.groupBox_01 = QtGui.QGroupBox(self.centralwidget)
self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.groupBox_01.setGeometry(QtCore.QRect(10, 290, 231, 81))
self.groupBox_01.setFont(self.fontGlobal_08)
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.groupBox_01.setObjectName(_fromUtf8("groupBox_01"))
self.gridLayout.setContentsMargins(10, 10, 10, 10)


self.RB_01_Default = QtGui.QRadioButton(self.groupBox_01)
self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBox)
self.RB_01_Default.setGeometry(QtCore.QRect(10, 20, 141, 17))
self.gridLayout_3.setContentsMargins(10, 10, 10, 10)
self.RB_01_Default.setFont(self.fontGlobal_08)
self.RB_01_Default.setToolTip("The line stay tel quel\n"
"For Compound I and Convert text to String")
self.RB_01_Default.setChecked(True)
self.RB_01_Default.setObjectName(_fromUtf8("RB_01_Default"))


self.RB_02_Hidden = QtGui.QRadioButton(self.groupBox_01)
self.gridLayout_2 = QtWidgets.QGridLayout(self.groupBox_Choice)
self.RB_02_Hidden.setGeometry(QtCore.QRect(10, 40, 141, 17))
self.gridLayout_2.setContentsMargins(10, 10, 10, 10)
self.RB_02_Hidden.setFont(self.fontGlobal_08)
self.gridLayout_2.addWidget(self.PB_01_Compound_01, 0, 0, 1, 1)
self.RB_02_Hidden.setToolTip("The original line are hidden after transform\n"
self.gridLayout_2.addWidget(self.label_02_Type_1, 0, 1, 1, 1)
self.gridLayout_2.addWidget(self.PB_02_Compound_02, 1, 0, 1, 1)
"For Compound I and Convert text to String")
self.RB_02_Hidden.setObjectName(_fromUtf8("RB_02_Hidden"))
self.gridLayout_2.addWidget(self.label_03_Type_2, 1, 1, 1, 1)
self.gridLayout_3.addWidget(self.groupBox_Choice, 0, 0, 1, 1)


self.RB_03_Delete = QtGui.QRadioButton(self.groupBox_01)
self.gridLayout_4 = QtWidgets.QGridLayout(self.groupBox_00)
self.RB_03_Delete.setGeometry(QtCore.QRect(10, 60, 141, 17))
self.gridLayout_4.setContentsMargins(10, 10, 10, 10)
self.RB_03_Delete.setFont(self.fontGlobal_08)
self.gridLayout_4.addWidget(self.PB_03_Color, 0, 0, 1, 1)
self.RB_03_Delete.setToolTip("The original line are deleted after transform\n"
self.gridLayout_3.addWidget(self.groupBox_00, 1, 0, 1, 1)
"For Compound I and Convert text to String")
# self.RB_03_Delete.setChecked(True)
self.RB_03_Delete.setObjectName(_fromUtf8("RB_03_Delete"))


self.progressBar = QtGui.QProgressBar(self.centralwidget)
self.gridLayout_5 = QtWidgets.QGridLayout(self.groupBox_Tools)
self.progressBar.setGeometry(QtCore.QRect(10, 380, 231, 20))
self.gridLayout_5.setContentsMargins(10, 10, 10, 10)
self.progressBar.setFont(self.fontGlobal_08)
self.gridLayout_5.addWidget(self.lineEdit_NameFile, 0, 0, 1, 3)
self.progressBar.setValue(0)
self.gridLayout_5.addWidget(self.comboBoxPy, 1, 0, 1, 3)
self.progressBar.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout_5.addWidget(self.PB_04_Convert_Text, 2, 0, 1, 2)
self.progressBar.setObjectName(_fromUtf8("progressBar"))
self.gridLayout_5.addWidget(self.DS_02_Size_Font, 2, 2, 1, 1)
self.gridLayout_5.addWidget(self.line, 3, 0, 1, 3)
self.gridLayout_5.addWidget(self.PB_04c_Convert_Edge, 4, 0, 1, 2)
self.gridLayout_5.addWidget(self.DS_01_Width_Line, 4, 2, 1, 1)
self.gridLayout_5.addWidget(self.CB_BezierCurve, 5, 0, 1, 1)
self.gridLayout_5.addWidget(self.RB_01_FlatLines, 6, 0, 1, 1)
self.gridLayout_5.addWidget(self.RB_02_Wireframe, 6, 1, 1, 1)
self.gridLayout_5.addWidget(self.RB_03_Points, 6, 2, 1, 1)
self.gridLayout_5.addWidget(self.PB_09_Upgrade, 7, 0, 1, 1)
self.gridLayout_5.addWidget(self.PB_06_Downgrade, 7, 1, 1, 1)
self.gridLayout_3.addWidget(self.groupBox_Tools, 2, 0, 1, 1)

self.gridLayout_7 = QtWidgets.QGridLayout(self.groupBox_01)
self.gridLayout_7.setContentsMargins(10, 10, 10, 10)
self.gridLayout_7.addWidget(self.RB_01_Default, 0, 0, 1, 1)
self.gridLayout_7.addWidget(self.RB_02_Hidden, 0, 1, 1, 1)
self.gridLayout_7.addWidget(self.RB_03_Delete, 1, 0, 1, 1)
self.gridLayout_3.addWidget(self.groupBox_01, 3, 0, 1, 1)

self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBox_Command)
self.gridLayout_6.setContentsMargins(10, 10, 10, 10)
self.gridLayout_6.addWidget(self.progressBar, 0, 0, 1, 3)
self.gridLayout_6.addWidget(self.PB_05_Reset, 1, 0, 1, 1)
self.gridLayout_6.addWidget(self.PB_07_Quit, 1, 1, 1, 1)
self.gridLayout_6.addWidget(self.PB_08_Help, 1, 2, 1, 1)
self.gridLayout_3.addWidget(self.groupBox_Command, 4, 0, 1, 1)
self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 1)
#### layout ###################################################


Compound.setCentralWidget(self.centralwidget)
Compound.setCentralWidget(self.centralwidget)
Line 391: Line 782:


def retranslateUi(self, Compound):
def retranslateUi(self, Compound):
Compound.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant
Compound.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant
Compound.setWindowIcon(QtGui.QIcon(self.path + 'Macro_Compound_Plus.png')) # change l'icone de la fenetre principale
Compound.setWindowIcon(QtGui.QIcon(self.path + 'Macro_Compound_Plus.png')) # change l'icone de la fenetre principale
Compound.setWindowTitle("Compound +")
Compound.setWindowTitle("Compound +")

self.groupBox.setTitle("Version : " + __date__ + " : " + __version__)

self.groupBox_Choice.setTitle("Choice")
self.PB_01_Compound_01.setText("Compound I")
self.PB_01_Compound_01.setText("Compound I")
self.PB_01_Compound_01.setToolTip("Make a compound Block unique")
self.PB_02_Compound_02.setText("Compound II")
self.PB_02_Compound_02.setText("Compound II")
self.PB_02_Compound_02.setToolTip("Make a compound same Part, Menu > Part > Make compound")
self.groupBox_00.setTitle("Options lines")
self.PB_03_Color.setText("Color")
self.PB_04_Convert.setText("Convert (A)")
self.PB_04c_Convert_Edge.setText("Convert Edge")

self.label_01_Titre.setText("Compound +")
self.label_02_Type_1.setText("Type I [ 1 + 1 = 1 ]")
self.label_02_Type_1.setText("Type I [ 1 + 1 = 1 ]")
self.label_03_Type_2.setText("Type II [ 1 + 1 = A (1 + 1) ]")
self.label_03_Type_2.setText("Type II [ 1 + 1 = A (1 + 1) ]")

self.label_04_Color.setText("Line color")
self.label_05_DSBox.setText("Width line")
self.groupBox_00.setTitle("Option color")
self.groupBox_00.setToolTip("If this box is unchecked the colors attributes and width line\n"
self.label_06_Convert.setText("Convert Text to String")
"of the original line(s) are not modified\n"
self.label_08_Convert_Line.setText("Convert Edge to Line")
"This chekBox work with all objects\n")
self.PB_03_Color.setText("Color")
self.PB_03_Color.setToolTip("Change the color of object(s) selected(s) value by defaut rvb 255,0,0")

self.groupBox_Tools.setTitle("Tools")

self.lineEdit_NameFile.setToolTip("(Number index / Number Fonts) Complete path and name of Font file")

self.comboBoxPy.setToolTip("Choice your Font" + "\n" +
"\n" +
"You must modify the configuration of display" + "\n" +
"See in the beginning of the macro section (line 120):" + "\n" +
"####" + "\n" +
"Config Begin matplotlib font" + "\n"
"switchModeTextList= 1\t# 0 = mode text normal (the switchFontComBox is enabled)" + "\n"
"\t\t\t# 1 = switchFontComBox authorized (default)" + "\n"
"\t\t\t#####" + "\n"
"switchFontComBox = 1\t# 0 = mode text in color .. faster" + "\n"
"\t\t\t# 1 = fontFamily listed ComboBox slower but beautiful (default)" + "\n"
"\t\t\t#####" + "\n"
"setSystemFonts = 1\t# 0 = matplotlib.font_manager.findSystemFonts" + "\n"
"\t\t\t# all fonts in System font" + "\n"
"\t\t\t# 1 = fontman.findSystemFonts(self.pathFont) (default)" + "\n"
"\t\t\t# all fonts in all directory and sub directory" + "\n"
"\t\t\t#####" + "\n"
"seTtextAlignement = 0\t# 0 = AlignLeft (default)" + "\n"
"\t\t\t# 1 = AlignCenter" + "\n"
"\t\t\t# 2 = AlignRight" + "\n"
"\t\t\t#####" + "\n"
"Config End matplotlib font" + "\n"
"####" + "\n" +
"Read the info")
self.PB_04_Convert_Text.setText("Convert Text (A)")
self.PB_04_Convert_Text.setToolTip("Convert the selected text in ShapeString\n"
"By default Convert (A)utomatic use the font preselected and the size of original text\n"
"If the values or font is modified the button change of Convert (M)anual\n"
"The label of the texte are modified to SString_original text (max 30 characters)")
self.DS_02_Size_Font.setToolTip("Size of the font of the ShapeString")
self.PB_04c_Convert_Edge.setText("Convert Wire (A)")
self.PB_04c_Convert_Edge.setToolTip("Convert the wire to object Draft" + "\n"
"Select the wire(s) in the 3D view" + "\n\n"
"Are detected : Line, Circle, Arc, Ellipse, BSplineCurve" + "\n"
"BezierCurve, BezierCurve Cubic (if checked)" + "\n\n"
"If the Surface or Point or other wire unknown are detected," + "\n"
"the selection Object is duplicated" + "\n"
"If the values is modified the button change of Convert (M)anual\n")
self.DS_01_Width_Line.setToolTip("Give a new width for the line(s) selected(s)")
self.CB_BezierCurve.setText("BezierCurve")
self.CB_BezierCurve.setToolTip("If checked the BezierCurve is Cubic")

self.RB_01_FlatLines.setText("FlatLines")
self.RB_01_FlatLines.setToolTip("FlatLines")
self.RB_02_Wireframe.setText("Wireframe")
self.RB_02_Wireframe.setToolTip("Wireframe")
self.RB_03_Points.setText("Points")
self.RB_03_Points.setToolTip("Points")

self.PB_09_Upgrade.setText("UpGrade")
self.PB_09_Upgrade.setToolTip("Upgrade the selected object Same Draft > Upgrade")
self.PB_06_Downgrade.setText("DownGrade")
self.PB_06_Downgrade.setToolTip("Downgrade the selected object Same Draft > Downgrade")


self.groupBox_01.setTitle("For Compound I and Convert")
self.groupBox_01.setTitle("For Compound I and Convert")
self.RB_01_Default.setText("None")
self.RB_01_Default.setText("None")
self.RB_02_Hidden.setText("Hidden original line(s) ")
self.RB_01_Default.setToolTip("The object stay as is\n"
"For Compound I and Convert text to String")
self.RB_03_Delete.setText("Delete original line(s)")
self.RB_02_Hidden.setText("Hidden original object(s) ")
self.RB_02_Hidden.setToolTip("The original object are hidden after transform\n"
"For Compound I and Convert text to String")
self.RB_03_Delete.setText("Delete original object(s)")
self.RB_03_Delete.setToolTip("The original object are deleted after transform\n"
"For Compound I and Convert text to String")

self.groupBox_Command.setTitle("Command")
self.PB_05_Reset.setText("Reset")
self.PB_05_Reset.setText("Reset")
self.PB_06_Downgrade.setText("DownGrade")
self.PB_05_Reset.setToolTip("Reset the values")
self.PB_07_Quit.setText("Quit")
self.PB_07_Quit.setText("Quit")
self.PB_07_Quit.setToolTip("Quit Compound +")
self.PB_08_Help.setText("Help")
self.PB_08_Help.setToolTip("Quit Compound +")

def on_fontComboBoxPython(self,indeX): # 0: for fontComboBoxPython
global PolicePath

self.index = indeX
self.lineEdit_NameFile.setText("(" + str(self.index + 1) + "/" + str(len(self.tableau)) + ") " + self.tableau[self.index][1])
PolicePath = self.tableau[self.index][1]

famille = typeCar = self.font = ""
self.font = QtGui.QFont()
typeCar = family(self.tableau[self.index][2])[1]
self.font.setBold(False)
self.font.setItalic(False)

if len(typeCar) > 0:
for option in typeCar:
if option == "Bold":
self.font.setBold(True)
if (option == "Italic") or (option == "It") or (option == "Slanted"):
self.font.setItalic(True)
if option == "Oblique":
self.font.setItalic(True)
#'Bold''Regular''Slanted''Italic''Medium''Extra''Light''Condensed''Black''It''Semibold'#+
self.font.setFamily(self.tableau[self.index][5])
self.font.setPointSize(self.FontTextSize)
####
self.fonteComp = self.tableau[self.index][1]
# FreeCAD.Console.PrintMessage(str(self.index) + " , " + self.tableau[self.index][1] + " , " + self.tableau[self.index][2] + " , ' " + famille + "' , ' " + typeCar + " ' \n")

def on_PB_newPathFont(self):
global ui
global newPolicePath
global setSystemFonts

newPolicePath = str(PySide2.QtWidgets.QFileDialog.getExistingDirectory(None, "Select new font directory", newPolicePath, PySide2.QtWidgets.QFileDialog.ShowDirsOnly))
if newPolicePath:
MyLabelPatience.label.show()
FreeCADGui.updateGui() # rafraichi l'ecran
ui.searchFont(newPolicePath)
setSystemFonts = 1
MyLabelPatience.label.close()

def on_PB_systemPath(self):
global ui
global setSystemFonts

MyLabelPatience.label.show()
FreeCADGui.updateGui() # rafraichi l'ecran
setSystemFonts = 0
ui.searchFont(self.pathFont)
MyLabelPatience.label.close()


def on_PB_01_Compound_01(self):
def on_PB_01_Compound_01(self):
global doc
self.selectionObjects = FreeCADGui.Selection.getSelection()
self.selectionObjects = FreeCADGui.Selection.getSelection()
if len(self.selectionObjects) > 0:
if len(self.selectionObjects) > 0:
Line 434: Line 951:
self.progressBar.setValue(compteur)
self.progressBar.setValue(compteur)
Gui.updateGui()
Gui.updateGui()
print "Object : ",i.Name
print( "Object : ",i.Name)


comp = Part.makeCompound(self.comP)
comp = Part.makeCompound(self.comP)
Part.show(comp)
Part.show(comp)


if self.groupBox_00.isChecked:
if self.groupBox_00.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (self.redFL, self.greenFL, self.blueFL)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (self.redFL, self.greenFL, self.blueFL)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (self.redFL, self.greenFL, self.blueFL)


App.ActiveDocument.ActiveObject.Label = "reproShape_TI"
App.ActiveDocument.ActiveObject.Label = "reproShape_T_I"
if self.RB_01_Default.isChecked():
if self.RB_01_Default.isChecked():
Line 451: Line 968:
if self.RB_02_Hidden.isChecked():
if self.RB_02_Hidden.isChecked():
for i in range(len(self.nameL)):
for i in range(len(self.nameL)):
print "Hidden : ",self.nameL[i]
print( "Hidden : ",self.nameL[i])
FreeCADGui.ActiveDocument.getObject(self.nameL[i]).Visibility = False
FreeCADGui.ActiveDocument.getObject(self.nameL[i]).Visibility = False
if self.RB_03_Delete.isChecked():
try:
for i in range(len(self.nameL)):
if self.RB_03_Delete.isChecked():
print "Delete : ",self.nameL[i]
for i in range(len(self.nameL)):
doc.removeObject(self.nameL[i])
print( "Delete : ",self.nameL[i])
self.progressBar.setValue(0)
doc.removeObject(self.nameL[i])
except Exception:
FreeCAD.Console.PrintError("Error Delete : ",self.nameL[i] + "\n")
except Exception:
except Exception:
FreeCAD.Console.PrintError("Error objects "+"\n")
FreeCAD.Console.PrintError("Error objects "+"\n")
self.progressBar.setValue(0)
FreeCAD.ActiveDocument.recompute()
else:
else:
FreeCAD.Console.PrintError("Not objects selected "+"\n")
FreeCAD.Console.PrintError("Not objects selected "+"\n")
Line 482: Line 1,004:
self.progressBar.setValue(compteur)
self.progressBar.setValue(compteur)
Gui.updateGui()
Gui.updateGui()
print i.Name
print( i.Name)
self.progressBar.setValue(0)
App.activeDocument().Compound.Links = self.nameL
App.activeDocument().Compound.Links = self.nameL
App.activeDocument().recompute()
App.activeDocument().recompute()


if self.groupBox_00.isChecked:
if self.groupBox_00.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (self.redFL, self.greenFL, self.blueFL)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (self.redFL, self.greenFL, self.blueFL)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (self.redFL, self.greenFL, self.blueFL)
# else:

App.ActiveDocument.ActiveObject.Label = "reproShape_TII"
# FreeCADGui.ActiveDocument.ActiveObject.LineWidth =
# FreeCADGui.ActiveDocument.ActiveObject.LineColor =
# FreeCADGui.ActiveDocument.ActiveObject.ShapeColor =
# FreeCADGui.ActiveDocument.ActiveObject.PointColor =
App.ActiveDocument.ActiveObject.Label = "reproShape_T_II"
except Exception:
except Exception:
FreeCAD.Console.PrintError("Error objects "+"\n")
FreeCAD.Console.PrintError("Error objects "+"\n")
self.progressBar.setValue(0)
FreeCAD.ActiveDocument.recompute()
else:
else:
FreeCAD.Console.PrintError("Not objects selected "+"\n")
FreeCAD.Console.PrintError("Not objects selected "+"\n")
Line 502: Line 1,030:


def on_PB_03_Color(self):
def on_PB_03_Color(self):
#p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
#print( p.GetUnsigned("DefaultShapeLineColor"))
self.PB_03_Color.setStyleSheet("background-color: QPalette.Base") # origin system
self.PB_03_Color.setStyleSheet("background-color: QPalette.Base") # origin system
self.window.hide() # hide the window open color
self.window.hide() # hide the window open color
couleur = QtGui.QColorDialog.getColor()
couleur = QtWidgets.QColorDialog.getColor()
if couleur.isValid():
if couleur.isValid():
Line 511: Line 1,041:
self.blue = int(str(couleur.name()[5:7]),16)
self.blue = int(str(couleur.name()[5:7]),16)


self.redFL = float(couleur.redF())
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+"); color: cmj("+str(255)+","+str(255)+","+str(255)+")")
self.greenFL = float(couleur.greenF())
self.blueFL = float(couleur.blueF())
self.alphaFL = float(couleur.alphaF())
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+")")


self.window.show() # show the window and close color
self.window.show() # show the window and close color
# FreeCAD.Console.PrintMessage(str("PB_03_Color ")+"\n")
# FreeCAD.Console.PrintMessage(str("PB_03_Color ")+"\n")


def on_PB_04_Convert(self):
def on_PB_04_Convert_Text(self): # convert Text to ShapeString
global PolicePath
global PolicePath
global nomPolice
global doc

self.selectionObjects = FreeCADGui.Selection.getSelection()
self.selectionObjects = FreeCADGui.Selection.getSelection()

self.progressBar.setMaximum(len(self.selectionObjects))
self.progressBar.setMaximum(len(self.selectionObjects))
compteur = 0
compteur = 0
if len(self.selectionObjects) > 0:
if len(self.selectionObjects) > 0:
objA = self.selectionObjects[0]
#objA = self.selectionObjects[0]
for objA in self.selectionObjects:
for objA in self.selectionObjects:

try:
try:
self.TextLabel = objA.Label
self.TextLabel = objA.Label
self.TextLabelText = objA.LabelText[0]
self.TextLabelText = objA.Text[0] #0.19
self.TextPosition = objA.Position
self.TextPosition = objA.Placement #0.19
self.TextFontSize = objA.ViewObject.FontSize
self.TextFontSize = objA.ViewObject.FontSize


if self.manuel:
if self.fontSizeManual:
self.TextFontSize = self.FontSize
self.TextFontSize = self.FontSize


self.TextTextColor = objA.ViewObject.TextColor
self.TextTextColor = objA.ViewObject.TextColor
texte = unicode(self.TextLabelText)
texte = self.TextLabelText #0.19


ss=Draft.makeShapeString(String = texte, FontFile=PolicePath, Size=float(self.TextFontSize), Tracking=0)
ss=Draft.makeShapeString(String = texte, FontFile=PolicePath, Size=float(self.TextFontSize), Tracking=0)


plm=FreeCAD.Placement()
if self.RB_01_FlatLines.isChecked():
plm.Base=self.TextPosition
ss.ViewObject.DisplayMode = u"Flat Lines"
plm.Rotation.Q=(0.0,-0.0,-0.0,1.0)
if self.RB_02_Wireframe.isChecked():
ss.ViewObject.DisplayMode = u"Wireframe"
if self.RB_03_Points.isChecked():
ss.ViewObject.DisplayMode = u"Points"

plm = self.TextPosition
ss.Placement=plm
ss.Placement=plm
ss.Support=None
ss.Support=None
ss.Label = "SString_"+texte[:30]
ss.Label = "SString_"+texte[:30]
if self.groupBox_00.isChecked():
FreeCADGui.ActiveDocument.getObject(ss.Name).ShapeColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
#### imposted colors
FreeCADGui.ActiveDocument.getObject(ss.Name).LineColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.getObject(ss.Name).PointColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.getObject(ss.Name).ShapeColor = (self.redFL, self.greenFL, self.blueFL)
FreeCADGui.ActiveDocument.getObject(ss.Name).LineColor = (self.redFL, self.greenFL, self.blueFL)
FreeCADGui.ActiveDocument.getObject(ss.Name).PointColor = (self.redFL, self.greenFL, self.blueFL)
else:
# #### preferences colors
# r, b, g, t = unsignedDecode(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor"),1)
# FreeCADGui.ActiveDocument.getObject(ss.Name).ShapeColor = (r, b, g, t)
# r, b, g, t = unsignedDecode(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeLineColor"),1)
# FreeCADGui.ActiveDocument.getObject(ss.Name).LineColor = (r, b, g, t)
# r, b, g, t = unsignedDecode(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeVertexColor"),1)
# FreeCADGui.ActiveDocument.getObject(ss.Name).PointColor = (r, b, g, t)

#### original object colors
FreeCADGui.ActiveDocument.getObject(ss.Name).ShapeColor = objA.ViewObject.TextColor
FreeCADGui.ActiveDocument.getObject(ss.Name).LineColor = objA.ViewObject.LineColor
##FreeCADGui.ActiveDocument.getObject(ss.Name).LineWidth = objA.ViewObject.LineWidth
compteur += 1
compteur += 1
self.progressBar.setValue(compteur)
self.progressBar.setValue(compteur)
Line 556: Line 1,111:
None
None
if self.RB_02_Hidden.isChecked():
if self.RB_02_Hidden.isChecked():
print "Hidden : ",objA.Name
print( "Hidden : ",objA.Name)
FreeCADGui.ActiveDocument.getObject(objA.Name).Visibility = False
FreeCADGui.ActiveDocument.getObject(objA.Name).Visibility = False
if self.RB_03_Delete.isChecked():
try:
print "Delete : ",objA.Name
if self.RB_03_Delete.isChecked():
doc.removeObject(objA.Name)
print( "Delete : ",objA.Name)
doc.removeObject(objA.Name)
except Exception:
FreeCAD.Console.PrintError("Error Delete : ",objA.Name + "\n")


Gui.updateGui()
Gui.updateGui()
Line 570: Line 1,128:
else:
else:
FreeCAD.Console.PrintError("Select one or more objects TEXT" + "\n")
FreeCAD.Console.PrintError("Select one or more objects TEXT" + "\n")
# FreeCAD.Console.PrintMessage(str("on_PB_04_Convert ")+"\n")
# FreeCAD.Console.PrintMessage(str("on_PB_04_Convert_Text ")+"\n")


def on_DS_02_Size_Font_valueChanged(self,value):
def on_PB_Fonte_Win01(self): # New Font Windows (menu deroulant) fonctionne ok
global PolicePath
global nomPolice

Compound.hide()
fonte = self.fontComboBox.currentFont()
nomPolice = fonte.rawName()
self.fontComboBox.setToolTip("New font.\nActual : "+nomPolice)
pathFont = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.FontsLocation) # path font search bon pour Windows
fonteComp = pathFont + "/" + nomPolice + ".TTF"
PolicePath = fonteComp.replace("\\","/")

font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.fontComboBox.setFont(font)

self.PB_04_Convert.setText("Convert (M)")
self.manuel = True
Compound.show()
# App.Console.PrintMessage("New Font " + (PolicePath)+"\n")

def on_DS_02_Width_Font_valueChanged(self,value):
self.FontSize = value
self.FontSize = value
self.PB_04_Convert.setText("Convert (M)")
if self.FontSize != 0:
self.PB_04_Convert_Text.setText("Convert Text (M)")
font = QtGui.QFont()
font.setFamily(nomPolice)
self.DS_02_Size_Font.setSuffix(" mm Size")
font.setPointSize(self.FontSize)
self.fontSizeManual = True

if platform.system() == "Windows" :
self.fontComboBox.setFont(font)
else:
else:
self.PB_Fonte_Linux.setFont(font)
self.PB_04_Convert_Text.setText("Convert Text (A)")
self.PB_Fonte_Linux.setText(_fromUtf8(nomPolice))
self.DS_02_Size_Font.setSuffix(" Auto")
self.fontSizeManual = False
#App.Console.PrintMessage("New FontSize " + str(self.FontSize)+"\n")


def on_PB_04c_Convert_Edge(self): # Convert Edge to line
self.manuel = True
self.selectionObjects = FreeCADGui.Selection.getSelectionEx() # Select an object or sub object
# App.Console.PrintMessage("New FontSize " + str(self.FontSize)+"\n")
self.progressBar.setMaximum(len(self.selectionObjects))
compteur = 0
for selection in self.selectionObjects:
nameObject = selection.Object.Name
countSubName = 0
for selectedEdge in selection.SubObjects:
subName = selection.SubElementNames[countSubName]
compteur += 1
self.progressBar.setValue(compteur)
if (hasattr(selectedEdge,"Surface")) or (hasattr(selectedEdge,"Point")):
Part.show(selectedEdge.copy()) # create repro shape subObject
FreeCAD.Console.PrintMessage("Object Point or Surface duplicated !!" + "\n")
FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
else:
try:
s = selectedEdge
if str(s.Curve) == "<Ellipse object>": # Ellipse
FreeCAD.Console.PrintMessage("Detected : Ellipse" + "\n")
pl=FreeCAD.Placement()
pl.Rotation = FreeCAD.Rotation(s.Curve.XAxis, s.Curve.YAxis, s.Curve.Axis, "ZXY")
pl.Base = s.Curve.Center
ellipse = Draft.makeEllipse(s.Curve.MajorRadius, s.Curve.MinorRadius, placement=pl, face=False, support=None)
FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
edge = selectedEdge
ellipse.FirstAngle = degrees(edge.FirstParameter)
ellipse.LastAngle = degrees(edge.LastParameter)
Draft.autogroup(ellipse)
elif str(s.Curve) == "<Line object>": # Line
FreeCAD.Console.PrintMessage("Detected : Line" + "\n")
points = []
points = selectedEdge.Edges[0].discretize(3) # Dicretize
wire = Draft.makeLine(points[0],points[-1])
FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
Draft.autogroup(wire)
points[:] = []
elif (hasattr(s.Curve,"Center")) and (hasattr(s.Curve,"Radius")):# arc or circle
FreeCAD.Console.PrintMessage("Detected : Arc or Circle" + "\n")
##https://github.com/yorikvanhavre/FreeCAD/blob/master/src/Mod/Draft/Draft.py#L264
pl=FreeCAD.Placement()
pl.Rotation = FreeCAD.Rotation(s.Curve.XAxis, s.Curve.YAxis, s.Curve.Axis, "ZXY")
pl.Base = s.Curve.Center
circle = Draft.makeCircle(radius=s.Curve.Radius, placement=pl, face=False, support=None)
circle.FirstAngle = degrees(selectedEdge.FirstParameter)
circle.LastAngle = degrees(selectedEdge.LastParameter)-360
FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
Draft.autogroup(circle)
elif (str(s.Curve) == "<BSplineCurve object>"):
FreeCAD.Console.PrintMessage("Detected : BSplineCurve" + "\n")
#print(s.Curve.getPoles())
points = []


def on_PB_Fonte_Win02(self): # New Font Windows (menu avec fenetres)
#try:
#points = s.Curve.getPoles() ? # getPoles
global PolicePath
#except Exception:
global nomPolice
bspline = s.Curve

arcs = bspline.toBiArcs(0.001)
Compound.hide()
BsplineNumberElement = len(arcs)
font, ok = QtGui.QFontDialog.getFont(QFont(nomPolice, self.FontSize))
points = selectedEdge.Edges[0].discretize(len(arcs)) # Dicretize
if ok:
spline = Draft.makeBSpline(points, closed=False, face=False, support=None)
FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
Draft.autogroup(spline)
points[:]= []
elif (str(s.Curve) == "<BezierCurve object>"): # BezierCurve
FreeCAD.Console.PrintMessage("Detected : BezierCurve" + "\n")
#print(s.Curve.getPoles())
points = []
try:
points = s.Curve.getPoles() # getPoles
except Exception:
points = selectedEdge.Edges[0].discretize(1000) # Discretize
try:
if self.CB_BezierCurve.isChecked():
bezCurve = Draft.makeBezCurve(points, closed=False, support=None, degree=3) #makeBezCurve3 (cubic) 0.19
FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName + "_(Cub)"
else:
bezCurve = Draft.makeBezCurve(points, closed=False, support=None, degree=None) #makeBezCurve 0.19
FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
Draft.autogroup(bezCurve)
except Exception:
bezCurve = Draft.makeBezCurve(points,closed=False,support=None) #makeBezCurve 0.18
Draft.autogroup(bezCurve)
points[:]= []
fonte = font
else:
nomPolice = fonte.rawName()
FreeCAD.Console.PrintMessage("Object duplicated !" + "\n")
Part.show(selectedEdge.copy()) # create repro shape subObject
self.FontSize = fonte.pointSizeF()
FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName

pathFont = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.FontsLocation) # path font search bon pour Windows
fonteComp = pathFont + "/" + nomPolice + ".TTF"
except Exception:
PolicePath = fonteComp.replace("\\","/")
FreeCAD.Console.PrintMessage("Error !!!" + "\n")

font = QtGui.QFont()
try:
font.setFamily(nomPolice)
if self.RB_01_FlatLines.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.DisplayMode = u"Flat Lines"
font.setPointSize(self.FontSize)
self.label_07_Font.setFont(font)
if self.RB_02_Wireframe.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.DisplayMode = u"Wireframe"

if self.RB_03_Points.isChecked():
self.label_07_Font.setText("Actual (" + str(self.FontSize) + ") " + nomPolice)
FreeCADGui.ActiveDocument.ActiveObject.DisplayMode = u"Points"
self.label_07_Font.setToolTip("Actual (" + str(self.FontSize) + ") " + nomPolice)
except Exception:

self.PB_04_Convert.setText("Convert (M)")
None
self.manuel = True
Compound.show()


def on_PB_Fonte_Linux(self): # New Font Linux
if self.lineWidth != 0.0:
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
global PolicePath
global nomPolice
Compound.hide()
OpenName = ""
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "New Font", PolicePath, "*.ttf") #PySide
try:
if OpenName != "":
PolicePath = str(OpenName)
import os.path
nomPolice = os.path.basename(PolicePath).split('.')[0]
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.PB_Fonte_Linux.setText(nomPolice)
self.PB_Fonte_Linux.setFont(font)
self.PB_Fonte_Linux.setToolTip(_fromUtf8("New font.\nActual : "+nomPolice))

except Exception:
None
Compound.show()

# App.Console.PrintMessage("New Font " + (PolicePath)+"\n")

def on_PB_04c_Convert_Edge(self): # Convert Edge to line
import Draft
points = []
points[:] = []
selectionObjects = FreeCADGui.Selection.getSelectionEx() # Select an object or sub object getSelectionEx
for selection in selectionObjects:
for selectedEdge in selection.SubObjects:
if (str(selectedEdge.Curve)[1:5]) == "Line" :
numberCut = 1 # line
else:
else:
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = selection.Object.ViewObject.LineWidth
numberCut = 20 # not line cut in 20 parts
points = selectedEdge.Edges[0].discretize(int(numberCut + 1)) # Dicretize
try:
if self.groupBox_00.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (self.redFL, self.greenFL, self.blueFL)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (self.redFL, self.greenFL, self.blueFL)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (self.redFL, self.greenFL, self.blueFL)
else:
FreeCADGui.ActiveDocument.ActiveObject.PointSize = selection.Object.ViewObject.PointSize
FreeCADGui.ActiveDocument.ActiveObject.LineColor = selection.Object.ViewObject.LineColor
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = selection.Object.ViewObject.ShapeColor
FreeCADGui.ActiveDocument.ActiveObject.PointColor = selection.Object.ViewObject.PointColor
except Exception:
None
countSubName += 1
if self.RB_01_Default.isChecked():
None
if self.RB_02_Hidden.isChecked():
print( "Hidden : ",nameObject)
FreeCADGui.ActiveDocument.getObject(nameObject).Visibility = False
try:
if self.RB_03_Delete.isChecked():
print( "Delete : ",nameObject)
doc.removeObject(nameObject)
except Exception:
FreeCAD.Console.PrintError("Error Delete : ",str(nameObject) + "\n")


for lin in range(len(points)-1):
self.progressBar.setValue(0)
creaLine = [FreeCAD.Vector(points[lin]),FreeCAD.Vector(points[lin+1])]
wire = Draft.makeLine(FreeCAD.Vector(creaLine[0]),FreeCAD.Vector(creaLine[1]))
if self.groupBox_00.isChecked:
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)

points[:] = []
FreeCAD.ActiveDocument.recompute()
FreeCAD.ActiveDocument.recompute()
# FreeCAD.Console.PrintMessage(str("on_PB_04c_Convert_Edge")+"\n")
# FreeCAD.Console.PrintMessage(str("on_PB_04c_Convert_Edge")+"\n")


def on_DS_01_Width_valueChanged(self,LineWidth):
def on_groupBox_00(self):
if self.groupBox_00.isChecked():
None
else:
None
# FreeCAD.Console.PrintMessage(str("on_groupBox_00")+"\n")

def on_DS_01_Width_Line_valueChanged(self,LineWidth):
self.lineWidth = LineWidth
self.lineWidth = LineWidth
# FreeCAD.Console.PrintMessage(str("on_DS_01_Width_valueChanged ")+str(self.lineWidth)+"\n")
if self.lineWidth != 0.0:
self.DS_01_Width_Line.setSuffix(" mm Width")
self.PB_04c_Convert_Edge.setText("Convert Wire (M)")
else:
self.DS_01_Width_Line.setSuffix(" Auto")
self.PB_04c_Convert_Edge.setText("Convert Wire (A)")
# FreeCAD.Console.PrintMessage(str("on_DS_01_Width_Line_valueChanged ")+str(self.lineWidth)+"\n")

def on_CB_BezierCurve_clicked(self):
if self.CB_BezierCurve.isChecked():
self.CB_BezierCurve.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_CubicBezCurve.svg")))
self.CB_BezierCurve.setText("Cubic BezierCurve")
else:
self.CB_BezierCurve.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_BezCurve.svg")))
self.CB_BezierCurve.setText("BezierCurve")
# FreeCAD.Console.PrintMessage(str("on_CB_BezierCurve_clicked ")+"\n")


def on_PB_05_Reset(self): #
def on_PB_05_Reset(self): #
global ui
global setSystemFonts
global PolicePath
global PolicePath
global nomPolice
global nomPolice
self.red = 255.0
#p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
self.green = 0.0
#print( p.GetUnsigned("DefaultShapeLineColor"))
self.blue = 0.0
self.red = 255 #204 # for button
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+"); color: cmj("+str(255)+","+str(255)+","+str(255)+")")
# self.RB_01_Default.setChecked(True)
self.green = 0 #204
self.RB_03_Delete.setChecked(True)
self.blue = 0 #204
self.lineWidth = 2.0
self.alpha = 255 # 255 = visibility max (opacity)
self.DS_01_Width.setValue(self.lineWidth)
self.redFL = float(255.0 / 255.0) # for object FC
self.FontSize = 8.0
self.greenFL = float(0.0 / 255.0)
self.blueFL = float(0.0 / 255.0)
self.alphaFL = float(255.0 / 255.0) # 1.0 = visibility max (opacity)
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+")")
self.groupBox_00.setChecked(False)
self.RB_01_Default.setChecked(True)
self.lineWidth = 0.0
self.DS_01_Width_Line.setValue(self.lineWidth)
self.DS_02_Size_Font.setValue(0.0)


if platform.system() == "Windows" :
MyLabelPatience.label.show()
FreeCADGui.updateGui() # rafraichi l'ecran
PolicePath = "C:/Windows/Fonts/ARIAL.TTF"
setSystemFonts = 0
ui.searchFont(self.pathFont)
MyLabelPatience.label.close()


self.fontSizeManual = False
nomPolice = os.path.basename(PolicePath).split('.')[0]
self.DS_02_Width_Font.setValue(self.FontSize)
self.PB_04_Convert_Text.setText("Convert Text (A)")
self.FontSize = 0.0

self.DS_02_Size_Font.setValue(self.FontSize)
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.fontComboBox.setCurrentFont(font)

else:
if platform.system() == "Linux" :
PolicePath = "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-M.ttf"
elif platform.system() == "Darwin":
PolicePath = "/Library/Fonts/Arial.ttf"
else:
PolicePath = FreeCAD.ConfigGet("AppHomePath")
self.PB_Fonte_Linux.setText("New Font")

nomPolice = os.path.basename(PolicePath).split('.')[0]

font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.PB_Fonte_Linux.setFont(font)

self.PB_Fonte_Linux.setText(nomPolice)
self.PB_Fonte_Linux.setToolTip(_fromUtf8("New font.\nActual : "+nomPolice))
self.DS_02_Width_Font.setValue(self.FontSize)

self.manuel = False
self.PB_04_Convert.setText("Convert (A)")
self.fonte = PolicePath + "/" + nomPolice + ".TTF"
self.fonte = PolicePath + "/" + nomPolice + ".TTF"
self.CB_BezierCurve.setChecked(False)
self.RB_01_FlatLines.setChecked(True)
# FreeCAD.Console.PrintMessage(str("on_PB_05_Reset ")+"\n")
# FreeCAD.Console.PrintMessage(str("on_PB_05_Reset ")+"\n")

def on_PB_09_Upgrade(self): #
try:
Draft.upgrade(FreeCADGui.Selection.getSelection(), delete=True)
FreeCAD.ActiveDocument.recompute()
except Exception:
None
# FreeCAD.Console.PrintMessage(str("on_PB_06_Downgrade ")+"\n")


def on_PB_06_Downgrade(self): #
def on_PB_06_Downgrade(self): #
try:
try:
import Draft
Draft.downgrade(FreeCADGui.Selection.getSelection(),delete=True)
Draft.downgrade(FreeCADGui.Selection.getSelection(),delete=True)
FreeCAD.ActiveDocument.recompute()
FreeCAD.ActiveDocument.recompute()
print
except Exception:
except Exception:
None
None
Line 756: Line 1,378:
# FreeCAD.Console.PrintMessage(str("on_PB_06_Quit ")+"\n")
# FreeCAD.Console.PrintMessage(str("on_PB_06_Quit ")+"\n")


def on_PB_Help_clicked(self):
Compound = QtGui.QMainWindow()
WebGui.openBrowser("https://wiki.freecadweb.org/Macro_Compound_Plus")
App.Console.PrintMessage("https://wiki.freecadweb.org/Macro_Compound_Plus" + "\n")
# FreeCAD.Console.PrintMessage(str("Help ")+"\n")

###### Read Configuration begin ####
#switchModeTextList = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("switchModeTextList")
#switchFontComBox = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("switchFontComBox")
#setSystemFonts = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("setSystemFonts")
#seTtextAlignement = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetInt("seTtextAlignement")
###### Read Configuration end ####

###### Write Configuration begin ####
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("switchModeTextList", True) # True or False
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("switchFontComBox", True) # True or False
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("setSystemFonts", True) # True or False
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetInt("seTtextAlignement", 0) # 0, 1, or 2
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("Version",__version__ + " (" + __date__ + ")")#
###### Write Configuration end ####

Compound = QtWidgets.QMainWindow()
ui = Ui_Compound()
ui = Ui_Compound()
ui.setupUi(Compound)
ui.setupUi(Compound)
Compound.show()
Compound.show()


}}
}}
Line 766: Line 1,408:
My macros to [https://gist.github.com/mario52a Github]
My macros to [https://gist.github.com/mario52a Github]
==Version==
==Version==
*14/05/2020 ver 00.03 : upgrade pySide2 and Qt5 layout and (matPlotLib Font) and convert Circle, Arc, Ellipse, BezierCurve
*24/01/2018 ver 00.02 : sup "import PyQt4"
*24/01/2018 ver 00.02 : sup "import PyQt4"
*21/11/2016 ver 00.01 :
*21/11/2016 ver 00.01 :

Revision as of 09:56, 23 May 2020

Macro Compound Plus

Description
New version GUI modifyed for the HD dpi (QGridLayout) run only FC version 0.19 and more (PySide2 Qt5)

For the precedent version see Macro_Compound_Plus 00.02 and install it manually.

Draft command set in a small macro for the 2D wire example: work with the DXF files. The macro detected : Line, Arc, Circle, Ellipse, BSplineCurve and reproduce the DXF wire in a Draft object. The text is converted in ShapeString.

Macro version: 00.03
Last modified: 2020-05-14
FreeCAD version: 0.19
Download: ToolBar Icon
Author: Mario52

Author
Mario52
Download
ToolBar Icon
Links
Macro Version
00.03
Date last modified
2020-05-14
FreeCAD Version(s)
0.19
Default shortcut
None
See also
None

Description

Draft command set in a small macro for the 2D wire example: work with the DXF files. The macro detected : Line, Arc, Circle, Ellipse, BSplineCurve and reproduce the DXF wire in a Draft object. The text is converted in ShapeString.

Usage

Macro_Compound_Plus_00

Choice

  • Compound I Type I [1 + 1 = 1] : Create one compound unique of all objects selected without history.
  • Compound II Type II [1 + 1 = A (1 + 1)] : Create one compound of all objects selected with history of all objects. Same "Menu → Part → Make compound".

Option color

If it checked the colour to object to work are coloured (edge, vertex)

  • Color  : Gives a colour to object. (Default Red 255, 0, 0)

Tools

  • LineEdit : display (Iindex of Font / Number of font) the path and name of the font.
  • Convert Text (A) : convert the text in a shape string (The height of the text converted is respected but the visual result may not be respected, see the Combo view property for confirm). (A) is Automatic value height of text.
    • 0,00 Auto  : If the spinbox is egual 0.0 the heigth of the VALUE of the text is respected, if other of 0.0 the Convert Text (A) change to Convert Text (M) manual.
  • Convert Wire (A) : This command convert the wire in one line with coordinates. (ex: one compound downgraded does not have coordinates, this function create a line with the coordinate as Draft line and reproduce the DXF wire in a Draft object are detected: Line, Arc, Circle, Ellipse, BSplineCurve.
    • 0,00 Auto  : Gives a thickness of the wire. If the spinbox is egual 0.0 the heigth of the VALUE of the text is respected, if other of 0.0 the Convert Wire (A) change to Convert Wire (M) manual.
  • BezierCurve : By default the BezierCurve detected is , if it is checked the BezierCurve is Cubic and the button change Cubic BezierCurve
  • FlatLines : The objects created is FlatLines.
  • Wireframe : The objects created is Wireframe.
  • Points : The objects created is Points.
  • UpGrade : UpGrade
  • DownGrade : DownGrade

For Compound I and Convert Edge

This section work only with the tools Compound I, Convert Text (A) and Convert Wire (A)

  • None : Everything originals objects remains as it is.
  • Hidden original objest(s) : Hidden the originals objest(s).
  • Delete original objest(s) : Delete the originals objest(s).

Command

  • ProgressBar
  • Reset : Reset the macro
  • Quit : Quit the macro, bye
  • Help : Display the wiki page in the FreeCAD browser

Script

The icon for you toolBar copy in same directory to the macro

How to Customize Toolbars, How to install macros

The script to github Macro_Compound_Plus.FCMacro

Macro_Compound_Plus.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
*   Copyright (c) 2016 2017 2018 1019 2020 <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.                                 *
**                                                                       **
*   Use at your own risk. The author assumes no liability for data loss.  *
*              It is advised to backup your data frequently.              *
*             If you do not trust the software do not use it.             *
**                                                                       **
*   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_Compound_Plus 05/08/2016 /_00 24/01/2018 /.02 2018-01-24/.03 2020/05/12
#
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.19.20802 (Git)
#Build type: Release
#Branch: master
#Hash: f4279f1bea8377a7ef63f7f4c69b67159d498965
#Python version: 3.6.8
#Qt version: 5.12.1
#Coin version: 4.0.0a
#OCC version: 7.3.0
#Locale: French/Mars (fr_MA)
#
#Icon.fromTheme by FreeCAD
#
__title__   = "Macro_Compound_Plus"
__author__  = "Mario52"
__url__     = "https://wiki.freecadweb.org/Macro_Compound_Plus"
__version__ = "00.03"
__date__    = "2020/05/14"    #YYYYMMDD
__icon__    = "https://wiki.freecadweb.org/images/f/fd/Macro_Compound_Plus.png"
__gistLoc__ = "https://gist.github.com/mario52a/7be361a8c489deec918f664fdcfc4394"
#
import PySide2
from PySide2 import (QtWidgets, QtCore, QtGui)
from PySide2.QtWidgets import (QWidget, QApplication, QSlider, QGraphicsView, QGraphicsScene, QVBoxLayout, QStyle)
from PySide2.QtGui import (QPainter, QColor, QIcon)
from PySide2.QtSvg import *
import PySide2.QtXml

import Draft, Part, PartGui, FreeCADGui, FreeCAD
from FreeCAD import Base
from FreeCAD import Vector
import math
from math import sqrt, pi, sin, cos, asin, degrees, radians
import re
import operator
from operator import itemgetter, attrgetter, methodcaller    # pour sort 
App = FreeCAD
Gui = FreeCADGui

import os, time, sys
import platform
import WebGui

global doc  ; doc = App.activeDocument()
global ui   ; ui         = ""

#### Test FreeCAD.Version simple ############################################################################################################
if int(FreeCAD.Version()[1]) < 19:      # Version de FreeCAD
    FreeCAD.Console.PrintError("This version " + __title__ + " rmu  work with the FreeCAD 0.19 or higher." + "\n\n")
    FreeCAD.Console.PrintError("SOME FUNCTIONS MAY NOT WORK PROPERLY " + "\n\n")
    FreeCAD.Console.PrintError("For the precedent version see the page " + "\n\n")
    FreeCAD.Console.PrintError("https://gist.github.com/mario52a/7be361a8c489deec918f664fdcfc4394" + "\n\n")
#### Test FreeCAD.Version simple ############################################################################################################
 
setIconTTF = [
"16 16 6 1",
" 	c None",
".	c #204A87",
"+	c None",
"@	c #729FCF",
"#	c #CC0000",
"$	c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++#####++++@@+@",
".+++$#$$$++@+@+@",
".++++#$+++++++@+",
".++++#$#####++++",
".++++#$+$#$$$+++",
".++++#$++#$+++++",
".@++++$++#$+###+",
".@@++++++#$+#$$$",
"..@@+++++#$+#$++",
"...@@+++++$+###+",
"....@@++++++#$$$",
".....@@+++++#$++",
"......@@+++++$++",
"................"]

setIconFON = [
"16 16 6 1",
" 	c None",
".	c #204A87",
"+	c None",
"@	c #F57900",
"#	c #CC0000",
"$	c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++###++++++@@+@",
".++#$$$++++@+@+@",
".++#$+++++++++@+",
".++###+###++++++",
".++#$$$#$#$+++++",
".++#$++#$#$+++++",
".@++$++#$#$##+#+",
".@@++++#$#$##$#$",
"..@@+++###$#$##$",
"...@@+++$$$#$##$",
"....@@+++++#$+#$",
".....@@++++#$+#$",
"......@@++++$++$",
"................"]

setIconOTF = [
"16 16 6 1",
" 	c None",
".	c #204A87",
"+	c None",
"@	c #4E9A06",
"#	c #CC0000",
"$	c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++###++++++@@+@",
".++#$#$++++@+@+@",
".++#$#$+++++++@+",
".++#$#$###++++++",
".++#$#$+#$$+++++",
".++###$+#$++++++",
".@++$$$+#$+###++",
".@@+++++#$+#$$$+",
"..@@++++#$+#$+++",
"...@@++++$+###++",
"....@@+++++#$$$+",
".....@@++++#$+++",
"......@@++++$+++",
"................"]

setIconPOL = [
"16 16 12 1",
" 	c None",
".	c #204A87",
"+	c None",
"@	c #06989A",
"#	c #73D216",
"$	c #000000",
"%	c #75507B",
"&	c #729FCF",
"*	c #CC0000",
"=	c #F57900",
"-	c #EDD400",
";	c #4E9A06",
".+++++++++++@#$%",
".++++++++$+#++&$",
".++***++++++=@+%",
".++*-*-++++*+&+$",
".++*-*-+++++++*+",
".++***-***++++++",
".++*---*-*-+++++",
".++*-++*-*-+++++",
".$++-++*-*-*++++",
".*@++++*-*-*-+++",
"..#*+++***-*-+++",
"...;#+++---*-+++",
"....%=+++++*-+++",
".....;$++++****+",
"......@%++++----",
"................"]

#path#################################################################
global path                                                          #
#path  = FreeCAD.ConfigGet("AppHomePath")                             # path FreeCAD installation
#path  = FreeCAD.ConfigGet("UserAppData")                             # path FreeCAD User data
#path  = "your path"                                                  # your directory path
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") # macro path
path  = param.GetString("MacroPath","") + "/"                        # macro path
path  = path.replace("\\","/")                                       # convert the "\" to "/"
#FreeCAD.Console.PrintMessage( "Path for the icons : " + path  + "\n")# 
######################################################################

#### matplotlib #################################################################
#import glob
#files_TTF = glob.glob(self.pathFont + "/*.TTF") 

##################################
import matplotlib
import matplotlib.font_manager
import matplotlib.font_manager as fontman
import matplotlib.font_manager as fontconfig
from matplotlib.font_manager import FontProperties

#from matplotlib.ft2font import FT2Font
##################################

global newPolicePath
global PolicePath
global nomPolice

if platform.system()   == "Windows" :
    PolicePath = "C:/Windows/Fonts/ARIAL.TTF"
elif platform.system() == "Linux" :
    PolicePath = "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-M.ttf"
elif platform.system() == "Darwin":
    PolicePath = "/Library/Fonts/Arial.ttf"
else:
    PolicePath = "C:/Windows/Fonts/ARIAL.TTF"

nomPolice     = os.path.basename(PolicePath).split('.')[0]
newPolicePath = os.path.dirname(PolicePath).split('.')[0]

#### matplotlib #################################################################
#### Config Begin matplotlib font #######################
                                                        # # https://en.wikipedia.org/wiki/Web_colors
global setColorTTF       ; setColorTTF       = "blue"   # .TTF   color by "extension name" or hexa "#0000FF" 
global setColorFON       ; setColorFON       = "orange" # .FON   color by "extension name" or hexa "#FFA500"
global setColorOTF       ; setColorOTF       = "green"  # .OTF   color by "extension name" or hexa "#008000"
global setColorPOL       ; setColorPOL       = "black"  # .OTHER color by "extension name" or hexa "#000000"
                                                      #####
global switchModeTextList; switchModeTextList= 1        # 0 = mode text normal (et noir) coupe le switchFontComBox
                                                        # 1 = permet le switchFontComBox 1 (default)
                                                      #####
global switchFontComBox  ; switchFontComBox  = 1        # 0 = (et switchModeTextList= 1) mode texte (en couleur) dans liste ComboBox plus rapide
                                                        # 1 = (et switchModeTextList= 1) fontFamily dans liste ComboBox plus lent mais plus beau! (default)
                                                      #####
global setSystemFonts    ; setSystemFonts    = 1        # 0 = matplotlib.font_manager.findSystemFonts("C:/", "ttf") 
                                                        #     fait toutes les fontes (dans tous les dossiers et sous dossiers du DD) time !!
                                                        # 1 = fontman.findSystemFonts(self.pathFont)
                                                        #     fait toutes les fontes du repertoire (et dans tous les sous dossiers) (default)
                                                      #####
global seTtextAlignement ; seTtextAlignement = 0        # 0 = AlignLeft (default)
                                                        # 1 = AlignCenter
                                                        # 2 = AlignRight
                                                      #####
#### Config End matplotlib font #########################

#### matplotlib #################################################################

def createSpace(texte):    # detecte majuscule et ajoute un espace devant la lettre
    # return createSpace(TexTe) = Tex Te , if createSpace(TEXTE) = TEXTE
    if texte.isupper():
        stringSpace = texte
    else:
        try:
            stringSpace = texte[0]
            for i in texte[1:]:
                if re.search(r"[A-Z]", i): i = " " +  i
                stringSpace += i
        except Exception:
            stringSpace = texte
    return stringSpace

def family(chaine):
    # return family(chaine)[1] = Family , family(chaine)[2] = typeCar (form [a, b, c ...]
    famille = typeCar = ""
    try:
        if chaine.find('-') != -1:
            famille = chaine[:chaine.find('-')]
            typeCar = chaine[chaine.find('-')+1:]
        else:
            famille = chaine
            typeCar = ""
    except Exception:
        famille = chaine
        typeCar = ""
    typeCar = str(createSpace(typeCar)).split()
    return [createSpace(famille), typeCar]

class MyLabelPatience():        # fenetre image d'attente de chargement
    global path
    label = QtWidgets.QLabel()
    label.setText("<img src=" + path + "Macro_Compound_Plus.png><b><center>Wait please</center> \n\n<center>i search the fonts !\n\n</right></b>")
    ecran = FreeCADGui.getMainWindow().frameGeometry()
    xF = 250; yF = 120
    xW = (ecran.width()/2) - (xF/2)
    yW = (ecran.height()/2)- (yF/2)
    label.setGeometry(xW, yW, xF, yF)
    label.setStyleSheet("QLabel {background-color : #F0C300;font: 12pt; }");
    label.setWindowFlags(PySide2.QtCore.Qt.WindowFlags(PySide2.QtCore.Qt.FramelessWindowHint))        # pas de bords
    label.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint)         # PySide cette fonction met la fenetre en avant
#### matplotlib #################################################################

def unsignedDecode(value, mode = 0): # mode 0 = entier, mode 1 = float (a partir de ex: 4283773951)
                                     # 4283773951 = [255 85 51 255] = [red, green, blue, transparent]
    value = hex(value)
#    print(value)
    a1 = value[0:2]
    a2 = "000000000" + value[2:]
    a2 = a2[len(a2)-8:]
    value = a1 + a2
    if mode == 0:   # for button
        red         = int(value[2:4 ],16)
        green       = int(value[4:6 ],16)
        blue        = int(value[6:8 ],16)
        transparent = int(value[8:10],16)
    else:           # for FreeCAD object
        red         = float(int(value[2:4 ],16) / 255.0)
        green       = float(int(value[4:6 ],16) / 255.0)
        blue        = float(int(value[6:8 ],16) / 255.0)
        transparent = float(int(value[8:10],16) / 255.0)
    return [red, green, blue, transparent]

def unsignedEncode(red = 0, green = 0, blue = 0, transparent = 255): # convert red, green, blue, transparence to unique number
                                                                     #(255 *256*256*256 ) + (85 *256*256) + (51 *256) +(255) = 4283773951
    value = (red *256*256*256 ) + (green *256*256) + (blue *256) + (transparent)
    return value

#write parameter
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/FCMmacro/FCTexture").SetString("Path",pathFile)
#read parameter
#pathFile = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/FCMmacro/FCTexture").GetString("Path")

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

class Ui_Compound(object):

    def __init__(self):
        global path
        global nomPolice

        self.path          = path
        self.nameL         = []
        self.comP          = []
        del        self.nameL[:]
        del         self.comP[:]

        self.lineWidth     = 0.0
        self.TextLabel     = ""
        self.TextLabelText = ""
        self.TextPosition  = ""
        self.TextFontSize  = 8.0
        self.TextTextColor = ""
        self.fonte         = ""
        self.fontSizeManual= False
        self.lineSizeManual= False

        ####font textEdit
        self.nomPolice     = "Arial"
        self.FontTextSize  = 20
        self.fonteComp     = ""
        self.font          = QtGui.QFont()
        ####font textEdit
        self.FontSize      = 0.0

        # for button
        self.red     = 255   #204.0
        self.green   = 0     #204.0
        self.blue    = 0     #204.0
        self.alpha   = 255   #255 = visibility max (opacity)

        # for object FC
        self.redFL   = 1.0
        self.greenFL = 0.0
        self.blueFL  = 0.0
        self.alphaFL = 1.0   # 1.0 = visibility max (opacity)

        self.tableau       = [] #Index (), [chemin plus nom fichier (nomPathPolice), nom sans extension (nomSimple), nomSimpleExt (nomSimple + Ext)]
        self.index         = 0  #Index ()

    #### font ######################
    def searchFont(self,pathSearch):
        global setSystemFonts
        global seTtextAlignement
        global switchFontComBox
        global switchModeTextList

        MyLabelPatience.label.show()
        FreeCADGui.updateGui()                                 # rafraichi l'ecran

        files_All_Fonts = ""
        ##https://matplotlib.org/_modules/matplotlib/font_manager.html
        if setSystemFonts == 0:
            files_All_Fonts = matplotlib.font_manager.findSystemFonts(pathSearch, "ttf")  # fait toutes les fontes ? ()
        else:
            files_All_Fonts = fontman.findSystemFonts(pathSearch)                         # fait toutes les fontes (et dans tous les sous dossiers)

        if len(files_All_Fonts) > 0:           
            self.tableau = []
            self.index = 0

            for fonte in files_All_Fonts:
                ####
                nomPathPolice = nomFichier = nomSimpleExt = nomSimple = nomExtension = nameName = ""

                nomPathPolice = fonte.replace("\\","/")     # convert the "\" to "/"
                nomFichier    = nomPathPolice.split("/")    # complet split
                nomSimpleExt  = nomFichier[-1]              # nom avec extension
                nomSimple     = nomFichier[-1][:-4]         # nom sans extension
                nomExtension  = nomSimpleExt[nomSimpleExt.rfind('.')+1:].upper() # extension
                ####
                try:
#                    nameFamily    = matplotlib.font_manager.FontProperties(fname=fonte).get_family()            ##['sans-serif']
#                    nameStyle     = matplotlib.font_manager.FontProperties(fname=fonte).get_style()              #normal
#                    nameVariant   = matplotlib.font_manager.FontProperties(fname=fonte).get_variant()            #normal
#                    nameWeight    = matplotlib.font_manager.FontProperties(fname=fonte).get_weight()             #normal
#                    nameStretch   = matplotlib.font_manager.FontProperties(fname=fonte).get_stretch()            #normal
#                    nameFileComp  = matplotlib.font_manager.FontProperties(fname=fonte).get_file()              ##c:\windows\fonts\NotoNaskhArabicUI-Regular.ttf
#                    nameSize      = matplotlib.font_manager.FontProperties(fname=fonte).get_size()               #10.0
                    nameName      = matplotlib.font_manager.FontProperties(fname=fonte).get_name()              ##Noto Naskh Arabic UI
#                    nameSizePoint = matplotlib.font_manager.FontProperties(fname=fonte).get_size_in_points()     #10.0
#                    nameSlant     = matplotlib.font_manager.FontProperties(fname=fonte).get_slant()              #normal
#                    namePattern   = matplotlib.font_manager.FontProperties(fname=fonte).get_fontconfig_pattern() #:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:file=c:\windows\fonts\NotoNaskhArabicUI-Regular.ttf:size=10.0
                except Exception:
                    nameFamily = nameStyle = nameVariant = nameWeight = nameStretch = nameFileComp = nameSize = nameName = nameSizePoint = nameSlant = namePattern = ""
                ####
                if nameName == "" :
                    nameName = nomSimple
                self.tableau.append([0, nomPathPolice, nomSimple, nomSimpleExt.upper(), nomExtension.upper(), nameName])
                
            self.tableau = sorted(self.tableau, key=itemgetter(3))          # sorted by nomSimple.upper()

            try:
                for line in range(len(self.tableau)):                       # enleve les doubles (bon)
                    if self.tableau[line][2] == self.tableau[line + 1][2]:  # enleve les doubles (bon)
                        del(self.tableau[line + 1])                         # enleve les doubles (bon)
            except Exception:
                None

            self.comboBoxPy.clear()
            for line in range(len(self.tableau)): 
                try:
                    self.tableau[line][0] = line                 # ajoute le numero de ligne
                    if self.tableau[line][2].upper() == "ARIAL": # detecte la fonte de base
                        self.index = line
    
                    ####Section common color and font begin ######################
                    model = self.comboBoxPy.model()

                    if switchModeTextList == 1:
                        if self.tableau[line][4] == "TTF":
                            item = QtGui.QStandardItem(QtGui.QPixmap(setIconTTF), str(line))
                            item.setForeground(QtGui.QColor(setColorTTF))
                        elif self.tableau[line][4] == "FON":
                            item = QtGui.QStandardItem(QtGui.QPixmap(setIconFON), str(line))
                            item.setForeground(QtGui.QColor(setColorFON))
                        elif self.tableau[line][4] == "OTF":
                            item = QtGui.QStandardItem(QtGui.QPixmap(setIconOTF), str(line))
                            item.setForeground(QtGui.QColor(setColorOTF))
                        else:
                            item = QtGui.QStandardItem(QtGui.QPixmap(setIconPOL), str(line))
                            item.setForeground(QtGui.QColor(setColorPOL))

                        if   seTtextAlignement == 0:
                            item.setTextAlignment(QtCore.Qt.AlignLeft)
                        elif seTtextAlignement == 1:
                            item.setTextAlignment(QtCore.Qt.AlignCenter)
                        elif seTtextAlignement == 2:
                            item.setTextAlignment(QtCore.Qt.AlignRight)
                        else:
                            self.comboBoxPy.addItem(self.tableau[line][2])    
                        model.appendRow(item)
                    else:
                        self.comboBoxPy.addItem("")
                    self.comboBoxPy.setItemText(line, self.tableau[line][2])
                    ####Section item color and font end ##########################
    
                    ####Section setfont Family switchFontComBox begin#############
                    if (switchFontComBox == 1) and (switchModeTextList == 1):
                        typeCar = font = ""
                        font = QtGui.QFont()
                        #font = item.font()
        
                        typeCar   = family(self.tableau[line][2])[1]
                        font.setBold(False)
                        font.setItalic(False)
        
                        if len(typeCar) > 0:
                            for option in typeCar:
                                if option == "Bold":
                                    font.setBold(True)
                                if (option == "Italic") or (option == "It") or (option == "Slanted"):
                                    font.setItalic(True)
                                if option == "Oblique":
                                    font.setItalic(True)
                        #'Bold''Regular''Slanted''Italic''Medium''Extra''Light''Condensed''Black''It''Semibold'
                        
                        font.setFamily(self.tableau[line][5])
                        font.setPixelSize(15)
                        if switchModeTextList == 1:
                            item.setFont(font)
                        else:
                            self.comboBoxPy.addItem("")
                    ####Section setfont Family switchFontComBox end###############

                except Exception:
                    FreeCAD.Console.PrintMessage("searchFont()" + "\n")
                    None
            self.lineEdit_NameFile.setText("(" + str(self.index + 1) + "/" + str(len(self.tableau)) + ") " + self.tableau[self.index][1])
            #print(len(self.tableau))
            #for i in self.tableau:
            #    print(i)
            self.comboBoxPy.setCurrentIndex(self.index)
            self.fonteComp = self.tableau[self.index][1]
            MyLabelPatience.label.close()

    #### font ######################

    def setupUi(self, MainWindow):
        global PolicePath
        global setSystemFonts
        global setColorTTF
        global setColorFON
        global setColorOTF
        global setColorPOL
        global seTtextAlignement
        global switchFontComBox
        global switchModeTextList
        global ui

        self.window = MainWindow

        Compound.setObjectName("Compound")
        Compound.resize(250, 440)
#        MainWindow.setMinimumSize(QtCore.QSize(250, 440))
#        MainWindow.setMaximumSize(QtCore.QSize(250, 440))

        self.centralwidget = QtWidgets.QWidget(Compound)
        self.centralwidget.setObjectName("centralwidget")

        self.groupBox = QtWidgets.QGroupBox()

        self.groupBox_Choice = QtWidgets.QGroupBox()

        self.PB_01_Compound_01 = QtWidgets.QPushButton()
        self.PB_01_Compound_01.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Part_Compound.svg")))
        self.PB_01_Compound_01.clicked.connect(self.on_PB_01_Compound_01)                    # 

        self.label_02_Type_1 = QtWidgets.QLabel()

        self.PB_02_Compound_02 = QtWidgets.QPushButton()
        self.PB_02_Compound_02.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Part_Compound.svg")))
        self.PB_02_Compound_02.clicked.connect(self.on_PB_02_Compound_02)                    # 

        self.label_03_Type_2 = QtWidgets.QLabel()

        self.groupBox_00 = QtWidgets.QGroupBox()
#        self.groupBox_00.setAlignment(QtWidgets.AlignLeft)                    # AlignLeft     AlignCenter      AlignRight
        self.groupBox_00.setCheckable(True)
        self.groupBox_00.setChecked(False)
        self.groupBox_00.clicked.connect(self.on_groupBox_00)                  # 

        self.PB_03_Color = QtWidgets.QPushButton()
        self.PB_03_Color.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/colors.svg")))
        self.PB_03_Color.clicked.connect(self.on_PB_03_Color)                                # 
        self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+")")

        self.groupBox_Tools = QtWidgets.QGroupBox()

        self.lineEdit_NameFile = QtWidgets.QLineEdit()
        self.comboBoxPy = QtWidgets.QComboBox()
        ####
        #self.pathFont = PolicePath[:-10]
        self.pathFont = PolicePath[:len(PolicePath)-(PolicePath[::-1].index("/"))-1]
        ####

        self.PB_04_Convert_Text = QtWidgets.QPushButton()
        self.PB_04_Convert_Text.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_Text.svg")))
        self.PB_04_Convert_Text.clicked.connect(self.on_PB_04_Convert_Text)                            # ""

        ui.searchFont(self.pathFont)
        QtCore.QObject.connect(self.comboBoxPy, QtCore.SIGNAL("currentIndexChanged(int)"), self.on_fontComboBoxPython)

        self.DS_02_Size_Font = QtWidgets.QDoubleSpinBox()
        self.DS_02_Size_Font.setValue(0.0)
        self.DS_02_Size_Font.setSuffix(" Auto")
        self.DS_02_Size_Font.valueChanged.connect(self.on_DS_02_Size_Font_valueChanged)             # 

        self.line = QtWidgets.QFrame()
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)

        self.PB_04c_Convert_Edge = QtWidgets.QPushButton()
        self.PB_04c_Convert_Edge.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_Line.svg")))
        self.PB_04c_Convert_Edge.clicked.connect(self.on_PB_04c_Convert_Edge)                 # ""

        self.DS_01_Width_Line = QtWidgets.QDoubleSpinBox()
        self.DS_01_Width_Line.setValue(0.0) #self.lineWidth
        self.DS_01_Width_Line.setSuffix(" Auto")
        self.DS_01_Width_Line.valueChanged.connect(self.on_DS_01_Width_Line_valueChanged)             # 

        self.CB_BezierCurve = QtWidgets.QCheckBox()
        self.CB_BezierCurve.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_BezCurve.svg")))
        self.CB_BezierCurve.clicked.connect(self.on_CB_BezierCurve_clicked)

        self.RB_01_FlatLines = QtWidgets.QRadioButton()
        self.RB_01_FlatLines.setIcon(QtGui.QIcon.fromTheme("Vieuw",QtGui.QIcon(":/icons/DrawStyleFlatLines.svg")))
        self.RB_01_FlatLines.setChecked(True)
        self.RB_02_Wireframe = QtWidgets.QRadioButton()
        self.RB_02_Wireframe.setIcon(QtGui.QIcon.fromTheme("Vieuw",QtGui.QIcon(":/icons/DrawStyleWireFrame.svg")))
        self.RB_03_Points = QtWidgets.QRadioButton()
        self.RB_03_Points.setIcon(QtGui.QIcon.fromTheme("Vieuw",QtGui.QIcon(":/icons/DrawStylePoints.svg")))

        self.groupBox_01 = QtWidgets.QGroupBox()

        self.RB_01_Default = QtWidgets.QRadioButton()
        self.RB_01_Default.setChecked(True)
        self.RB_02_Hidden = QtWidgets.QRadioButton()
        self.RB_03_Delete = QtWidgets.QRadioButton()
        self.RB_03_Delete.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogCancelButton))) #
#        self.RB_03_Delete.setChecked(True)

        self.PB_09_Upgrade = QtWidgets.QPushButton()
        self.PB_09_Upgrade.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_Upgrade.svg")))
        self.PB_09_Upgrade.clicked.connect(self.on_PB_09_Upgrade)                       # 

        self.PB_06_Downgrade = QtWidgets.QPushButton()
        self.PB_06_Downgrade.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_Downgrade.svg")))
        self.PB_06_Downgrade.clicked.connect(self.on_PB_06_Downgrade)                       # 

        self.groupBox_Command = QtWidgets.QGroupBox()

        self.progressBar = QtWidgets.QProgressBar()
        self.progressBar.setValue(0)
        self.progressBar.setAlignment(QtCore.Qt.AlignCenter)

        self.PB_05_Reset = QtWidgets.QPushButton()
        self.PB_05_Reset.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogResetButton))) #
        self.PB_05_Reset.clicked.connect(self.on_PB_05_Reset)                               # 

        self.PB_07_Quit = QtWidgets.QPushButton()
        self.PB_07_Quit.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogCloseButton))) #
        self.PB_07_Quit.clicked.connect(self.on_PB_07_Quit)                                 # 

        self.PB_08_Help = QtWidgets.QPushButton()
        self.PB_08_Help.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_MessageBoxQuestion))) #
        self.PB_08_Help.clicked.connect(self.on_PB_Help_clicked)                                 # 

        #### layout ###################################################
        self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setContentsMargins(10, 10, 10, 10)

        self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBox)
        self.gridLayout_3.setContentsMargins(10, 10, 10, 10)

        self.gridLayout_2 = QtWidgets.QGridLayout(self.groupBox_Choice)
        self.gridLayout_2.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_2.addWidget(self.PB_01_Compound_01, 0, 0, 1, 1)
        self.gridLayout_2.addWidget(self.label_02_Type_1, 0, 1, 1, 1)
        self.gridLayout_2.addWidget(self.PB_02_Compound_02, 1, 0, 1, 1)
        self.gridLayout_2.addWidget(self.label_03_Type_2, 1, 1, 1, 1)
        self.gridLayout_3.addWidget(self.groupBox_Choice, 0, 0, 1, 1)

        self.gridLayout_4 = QtWidgets.QGridLayout(self.groupBox_00)
        self.gridLayout_4.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_4.addWidget(self.PB_03_Color, 0, 0, 1, 1)
        self.gridLayout_3.addWidget(self.groupBox_00, 1, 0, 1, 1)

        self.gridLayout_5 = QtWidgets.QGridLayout(self.groupBox_Tools)
        self.gridLayout_5.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_5.addWidget(self.lineEdit_NameFile, 0, 0, 1, 3)
        self.gridLayout_5.addWidget(self.comboBoxPy, 1, 0, 1, 3)
        self.gridLayout_5.addWidget(self.PB_04_Convert_Text, 2, 0, 1, 2)
        self.gridLayout_5.addWidget(self.DS_02_Size_Font, 2, 2, 1, 1)
        self.gridLayout_5.addWidget(self.line, 3, 0, 1, 3)
        self.gridLayout_5.addWidget(self.PB_04c_Convert_Edge, 4, 0, 1, 2)
        self.gridLayout_5.addWidget(self.DS_01_Width_Line, 4, 2, 1, 1)
        self.gridLayout_5.addWidget(self.CB_BezierCurve, 5, 0, 1, 1)
        self.gridLayout_5.addWidget(self.RB_01_FlatLines, 6, 0, 1, 1)
        self.gridLayout_5.addWidget(self.RB_02_Wireframe, 6, 1, 1, 1)
        self.gridLayout_5.addWidget(self.RB_03_Points, 6, 2, 1, 1)
        self.gridLayout_5.addWidget(self.PB_09_Upgrade, 7, 0, 1, 1)
        self.gridLayout_5.addWidget(self.PB_06_Downgrade, 7, 1, 1, 1)
        self.gridLayout_3.addWidget(self.groupBox_Tools, 2, 0, 1, 1)

        self.gridLayout_7 = QtWidgets.QGridLayout(self.groupBox_01)
        self.gridLayout_7.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_7.addWidget(self.RB_01_Default, 0, 0, 1, 1)
        self.gridLayout_7.addWidget(self.RB_02_Hidden, 0, 1, 1, 1)
        self.gridLayout_7.addWidget(self.RB_03_Delete, 1, 0, 1, 1)
        self.gridLayout_3.addWidget(self.groupBox_01, 3, 0, 1, 1)

        self.gridLayout_6 = QtWidgets.QGridLayout(self.groupBox_Command)
        self.gridLayout_6.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_6.addWidget(self.progressBar, 0, 0, 1, 3)
        self.gridLayout_6.addWidget(self.PB_05_Reset, 1, 0, 1, 1)
        self.gridLayout_6.addWidget(self.PB_07_Quit, 1, 1, 1, 1)
        self.gridLayout_6.addWidget(self.PB_08_Help, 1, 2, 1, 1)
        self.gridLayout_3.addWidget(self.groupBox_Command, 4, 0, 1, 1)
        self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 1)
        #### layout ###################################################

        Compound.setCentralWidget(self.centralwidget)

        self.retranslateUi(Compound)
        QtCore.QMetaObject.connectSlotsByName(Compound)

    def retranslateUi(self, Compound):
        Compound.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint)                    # PySide cette fonction met la fenetre en avant
        Compound.setWindowIcon(QtGui.QIcon(self.path + 'Macro_Compound_Plus.png'))         # change l'icone de la fenetre principale
        Compound.setWindowTitle("Compound +")

        self.groupBox.setTitle("Version : " + __date__ + " : " + __version__)

        self.groupBox_Choice.setTitle("Choice")
        self.PB_01_Compound_01.setText("Compound I")
        self.PB_01_Compound_01.setToolTip("Make a compound Block unique")
        self.PB_02_Compound_02.setText("Compound II")
        self.PB_02_Compound_02.setToolTip("Make a compound same Part, Menu > Part > Make compound")
        self.label_02_Type_1.setText("Type I [ 1 + 1 = 1 ]")
        self.label_03_Type_2.setText("Type II [ 1 + 1 = A (1 + 1) ]")

        self.groupBox_00.setTitle("Option color")
        self.groupBox_00.setToolTip("If this box is unchecked the colors attributes and width line\n"
                                    "of the original line(s) are not modified\n"
                                    "This chekBox work with all objects\n")
        self.PB_03_Color.setText("Color")
        self.PB_03_Color.setToolTip("Change the color of object(s) selected(s) value by defaut rvb 255,0,0")

        self.groupBox_Tools.setTitle("Tools")

        self.lineEdit_NameFile.setToolTip("(Number index / Number Fonts) Complete path and name of Font file")

        self.comboBoxPy.setToolTip("Choice your Font" + "\n" +
                                   "\n" +
                                   "You must modify the configuration of display" + "\n" +
                                   "See in the beginning of the macro section (line 120):" + "\n" +
                                   "####" + "\n" +
                                   "Config Begin matplotlib font" + "\n" 
                                   "switchModeTextList= 1\t# 0 = mode text normal (the switchFontComBox is enabled)" + "\n"
                                   "\t\t\t# 1 = switchFontComBox authorized (default)" + "\n"
                                   "\t\t\t#####" + "\n"
                                   "switchFontComBox  = 1\t# 0 = mode text in color .. faster" + "\n"
                                   "\t\t\t# 1 = fontFamily listed ComboBox slower but beautiful (default)" + "\n"
                                   "\t\t\t#####" + "\n"
                                   "setSystemFonts    = 1\t# 0 = matplotlib.font_manager.findSystemFonts" + "\n"
                                   "\t\t\t#   all fonts in System font" + "\n"
                                   "\t\t\t# 1 = fontman.findSystemFonts(self.pathFont) (default)" + "\n"
                                   "\t\t\t# all fonts in all directory and sub directory" + "\n"
                                   "\t\t\t#####" + "\n"
                                   "seTtextAlignement = 0\t# 0 = AlignLeft (default)" + "\n"
                                   "\t\t\t# 1 = AlignCenter" + "\n"
                                   "\t\t\t# 2 = AlignRight" + "\n"
                                   "\t\t\t#####" + "\n"
                                   "Config End matplotlib font" + "\n"
                                   "####" + "\n" +
                                   "Read the info")
        self.PB_04_Convert_Text.setText("Convert Text (A)")
        self.PB_04_Convert_Text.setToolTip("Convert the selected text in ShapeString\n"
                                           "By default Convert (A)utomatic use the font preselected and the size of original text\n"
                                           "If the values or font is modified the button change of Convert (M)anual\n"
                                           "The label of the texte are modified to SString_original text (max 30 characters)")
        self.DS_02_Size_Font.setToolTip("Size of the font of the ShapeString")
        self.PB_04c_Convert_Edge.setText("Convert Wire (A)")
        self.PB_04c_Convert_Edge.setToolTip("Convert the wire to object Draft" + "\n"
                                            "Select the wire(s) in the 3D view" + "\n\n"
                                            "Are detected : Line, Circle, Arc, Ellipse, BSplineCurve" + "\n"
                                            "BezierCurve, BezierCurve Cubic (if checked)" + "\n\n"
                                            "If the Surface or Point or other wire unknown are detected," + "\n"
                                            "the selection Object is duplicated" + "\n"
                                            "If the values is modified the button change of Convert (M)anual\n")
        self.DS_01_Width_Line.setToolTip("Give a new width for the line(s) selected(s)")
        self.CB_BezierCurve.setText("BezierCurve")
        self.CB_BezierCurve.setToolTip("If checked the BezierCurve is Cubic")

        self.RB_01_FlatLines.setText("FlatLines")
        self.RB_01_FlatLines.setToolTip("FlatLines")
        self.RB_02_Wireframe.setText("Wireframe")
        self.RB_02_Wireframe.setToolTip("Wireframe")
        self.RB_03_Points.setText("Points")
        self.RB_03_Points.setToolTip("Points")

        self.PB_09_Upgrade.setText("UpGrade")
        self.PB_09_Upgrade.setToolTip("Upgrade the selected object Same Draft > Upgrade")
        self.PB_06_Downgrade.setText("DownGrade")
        self.PB_06_Downgrade.setToolTip("Downgrade the selected object Same Draft > Downgrade")

        self.groupBox_01.setTitle("For Compound I and Convert")
        self.RB_01_Default.setText("None")
        self.RB_01_Default.setToolTip("The object stay as is\n"
                                      "For Compound I and Convert text to String")
        self.RB_02_Hidden.setText("Hidden original object(s) ")
        self.RB_02_Hidden.setToolTip("The original object are hidden after transform\n"
                                     "For Compound I and Convert text to String")
        self.RB_03_Delete.setText("Delete original object(s)")
        self.RB_03_Delete.setToolTip("The original object are deleted after transform\n"
                                     "For Compound I and Convert text to String")

        self.groupBox_Command.setTitle("Command")
        self.PB_05_Reset.setText("Reset")
        self.PB_05_Reset.setToolTip("Reset the values")
        self.PB_07_Quit.setText("Quit")
        self.PB_07_Quit.setToolTip("Quit Compound +")
        self.PB_08_Help.setText("Help")
        self.PB_08_Help.setToolTip("Quit Compound +")

    def on_fontComboBoxPython(self,indeX):                                          # 0: for fontComboBoxPython
        global PolicePath

        self.index = indeX
        self.lineEdit_NameFile.setText("(" + str(self.index + 1) + "/" + str(len(self.tableau)) + ") " + self.tableau[self.index][1])
        PolicePath = self.tableau[self.index][1]

        famille = typeCar = self.font = ""
        self.font = QtGui.QFont()
        typeCar   = family(self.tableau[self.index][2])[1]
        self.font.setBold(False)
        self.font.setItalic(False)

        if len(typeCar) > 0:
            for option in typeCar:
                if option == "Bold":
                    self.font.setBold(True)
                if (option == "Italic") or (option == "It") or (option == "Slanted"):
                    self.font.setItalic(True)
                if option == "Oblique":
                    self.font.setItalic(True)
        #'Bold''Regular''Slanted''Italic''Medium''Extra''Light''Condensed''Black''It''Semibold'#+
        
        self.font.setFamily(self.tableau[self.index][5])
        self.font.setPointSize(self.FontTextSize)
        ####
        self.fonteComp = self.tableau[self.index][1]
#        FreeCAD.Console.PrintMessage(str(self.index) + " , " + self.tableau[self.index][1] + " , " + self.tableau[self.index][2] + " , ' " + famille + "' , ' " + typeCar + " ' \n")

    def on_PB_newPathFont(self):
        global ui
        global newPolicePath
        global setSystemFonts

        newPolicePath = str(PySide2.QtWidgets.QFileDialog.getExistingDirectory(None, "Select new font directory", newPolicePath, PySide2.QtWidgets.QFileDialog.ShowDirsOnly))
        if newPolicePath:
            MyLabelPatience.label.show()
            FreeCADGui.updateGui()                             # rafraichi l'ecran
            ui.searchFont(newPolicePath)
            setSystemFonts = 1
            MyLabelPatience.label.close()

    def on_PB_systemPath(self):
        global ui
        global setSystemFonts

        MyLabelPatience.label.show()
        FreeCADGui.updateGui()                                 # rafraichi l'ecran
        setSystemFonts = 0
        ui.searchFont(self.pathFont)
        MyLabelPatience.label.close()

    def on_PB_01_Compound_01(self):
        global doc
        
        self.selectionObjects = FreeCADGui.Selection.getSelection()
        if len(self.selectionObjects) > 0:
            try:
                self.nameL         = []
                self.comP          = []
                del        self.nameL[:]
                del         self.comP[:]

                self.progressBar.setMaximum(len(self.selectionObjects))
                compteur = 0
                for i in self.selectionObjects:
                    self.nameL.append(i.Name)
                    self.comP.append(i.Shape)
                    compteur += 1
                    self.progressBar.setValue(compteur)
                    Gui.updateGui()
                    print( "Object : ",i.Name)

                comp = Part.makeCompound(self.comP)
                Part.show(comp)

                if self.groupBox_00.isChecked():
                    FreeCADGui.ActiveDocument.ActiveObject.LineWidth  = self.lineWidth
                    FreeCADGui.ActiveDocument.ActiveObject.LineColor  = (self.redFL, self.greenFL, self.blueFL)
                    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (self.redFL, self.greenFL, self.blueFL)
                    FreeCADGui.ActiveDocument.ActiveObject.PointColor = (self.redFL, self.greenFL, self.blueFL)

                App.ActiveDocument.ActiveObject.Label = "reproShape_T_I"
        
                if self.RB_01_Default.isChecked():
                    None
                if self.RB_02_Hidden.isChecked():
                    for i in range(len(self.nameL)):
                        print( "Hidden : ",self.nameL[i])
                        FreeCADGui.ActiveDocument.getObject(self.nameL[i]).Visibility = False
                try:
                    if self.RB_03_Delete.isChecked():
                        for i in range(len(self.nameL)):
                            print( "Delete : ",self.nameL[i])
                            doc.removeObject(self.nameL[i])
                except Exception:
                    FreeCAD.Console.PrintError("Error Delete : ",self.nameL[i] + "\n")
                
            except Exception:
                FreeCAD.Console.PrintError("Error objects "+"\n")
            self.progressBar.setValue(0)
            FreeCAD.ActiveDocument.recompute()
        else:
            FreeCAD.Console.PrintError("Not objects selected "+"\n")
#        FreeCAD.Console.PrintMessage(str("on_PB_01_Compound_01 ")+"\n")

    def on_PB_02_Compound_02(self):
        self.selectionObjects = FreeCADGui.Selection.getSelection()
        if len(self.selectionObjects) > 0:
            try:
                self.nameL         = []
                self.comP          = []
                del        self.nameL[:]
                del         self.comP[:]
                
                App.activeDocument().addObject("Part::Compound","Compound")
                
                self.progressBar.setMaximum(len(self.selectionObjects))
                compteur = 0
                for i in self.selectionObjects:
                    self.nameL.append(App.ActiveDocument.getObject(i.Name))
                    compteur += 1
                    self.progressBar.setValue(compteur)
                    Gui.updateGui()
                    print( i.Name)
                App.activeDocument().Compound.Links = self.nameL
                App.activeDocument().recompute()

                if self.groupBox_00.isChecked():
                    FreeCADGui.ActiveDocument.ActiveObject.LineWidth  = self.lineWidth
                    FreeCADGui.ActiveDocument.ActiveObject.LineColor  = (self.redFL, self.greenFL, self.blueFL)
                    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (self.redFL, self.greenFL, self.blueFL)
                    FreeCADGui.ActiveDocument.ActiveObject.PointColor = (self.redFL, self.greenFL, self.blueFL)
                # else:
                    # FreeCADGui.ActiveDocument.ActiveObject.LineWidth  = 
                    # FreeCADGui.ActiveDocument.ActiveObject.LineColor  = 
                    # FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = 
                    # FreeCADGui.ActiveDocument.ActiveObject.PointColor = 
                
                App.ActiveDocument.ActiveObject.Label = "reproShape_T_II"
        
            except Exception:
                FreeCAD.Console.PrintError("Error objects "+"\n")
            self.progressBar.setValue(0)
            FreeCAD.ActiveDocument.recompute()
        else:
            FreeCAD.Console.PrintError("Not objects selected "+"\n")
#        FreeCAD.Console.PrintMessage(str("on_PB_02_Compound_02 ")+"\n")

    def on_PB_03_Color(self):
        #p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
        #print( p.GetUnsigned("DefaultShapeLineColor"))
        self.PB_03_Color.setStyleSheet("background-color: QPalette.Base")        # origin system
        self.window.hide()                                                       # hide the window open color
        couleur = QtWidgets.QColorDialog.getColor()
        
        if couleur.isValid():
            self.red   = int(str(couleur.name()[1:3]),16)
            self.green = int(str(couleur.name()[3:5]),16)
            self.blue  = int(str(couleur.name()[5:7]),16)

            self.redFL   = float(couleur.redF())
            self.greenFL = float(couleur.greenF())
            self.blueFL  = float(couleur.blueF())
            self.alphaFL = float(couleur.alphaF())
            self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+")")

        self.window.show()                                                        # show the window and close color
#        FreeCAD.Console.PrintMessage(str("PB_03_Color ")+"\n")

    def on_PB_04_Convert_Text(self):        # convert Text to ShapeString
        global PolicePath
        global doc
        
        self.selectionObjects = FreeCADGui.Selection.getSelection()
        self.progressBar.setMaximum(len(self.selectionObjects))
        compteur = 0
        if len(self.selectionObjects) > 0:
            #objA = self.selectionObjects[0]
            for objA in self.selectionObjects:

                try:
                    self.TextLabel     = objA.Label
                    self.TextLabelText = objA.Text[0]      #0.19
                    self.TextPosition  = objA.Placement    #0.19
                    self.TextFontSize  = objA.ViewObject.FontSize 

                    if self.fontSizeManual:
                        self.TextFontSize = self.FontSize

                    self.TextTextColor = objA.ViewObject.TextColor
                    texte = self.TextLabelText #0.19

                    ss=Draft.makeShapeString(String = texte, FontFile=PolicePath, Size=float(self.TextFontSize), Tracking=0)

                    if self.RB_01_FlatLines.isChecked():
                        ss.ViewObject.DisplayMode = u"Flat Lines"
                    if self.RB_02_Wireframe.isChecked():
                        ss.ViewObject.DisplayMode = u"Wireframe"
                    if self.RB_03_Points.isChecked():
                        ss.ViewObject.DisplayMode = u"Points"

                    plm  = self.TextPosition
                    ss.Placement=plm
                    ss.Support=None
                    ss.Label = "SString_"+texte[:30]
                    if self.groupBox_00.isChecked():
                        #### imposted colors
                        FreeCADGui.ActiveDocument.getObject(ss.Name).ShapeColor = (self.redFL, self.greenFL, self.blueFL)
                        FreeCADGui.ActiveDocument.getObject(ss.Name).LineColor  = (self.redFL, self.greenFL, self.blueFL)
                        FreeCADGui.ActiveDocument.getObject(ss.Name).PointColor = (self.redFL, self.greenFL, self.blueFL)
                    else:
#                        #### preferences colors
#                        r, b, g, t = unsignedDecode(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor"),1)
#                        FreeCADGui.ActiveDocument.getObject(ss.Name).ShapeColor = (r, b, g, t)
#                        r, b, g, t = unsignedDecode(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeLineColor"),1)
#                        FreeCADGui.ActiveDocument.getObject(ss.Name).LineColor  = (r, b, g, t)
#                        r, b, g, t = unsignedDecode(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeVertexColor"),1)
#                        FreeCADGui.ActiveDocument.getObject(ss.Name).PointColor = (r, b, g, t)

                        #### original object colors
                        FreeCADGui.ActiveDocument.getObject(ss.Name).ShapeColor = objA.ViewObject.TextColor
                        FreeCADGui.ActiveDocument.getObject(ss.Name).LineColor  = objA.ViewObject.LineColor
                        ##FreeCADGui.ActiveDocument.getObject(ss.Name).LineWidth  = objA.ViewObject.LineWidth
                        
                    compteur += 1
                    self.progressBar.setValue(compteur)

                    if self.RB_01_Default.isChecked():
                        None
                    if self.RB_02_Hidden.isChecked():
                        print( "Hidden : ",objA.Name)
                        FreeCADGui.ActiveDocument.getObject(objA.Name).Visibility = False
                    try:
                        if self.RB_03_Delete.isChecked():
                            print( "Delete : ",objA.Name)
                            doc.removeObject(objA.Name)
                    except Exception:
                        FreeCAD.Console.PrintError("Error Delete : ",objA.Name + "\n")

                    Gui.updateGui()
                except Exception:
                    FreeCAD.Console.PrintError("Not object TEXT or error" + "\n")

            self.progressBar.setValue(0)
            FreeCAD.ActiveDocument.recompute()
        else:
            FreeCAD.Console.PrintError("Select one or more objects TEXT" + "\n")
#        FreeCAD.Console.PrintMessage(str("on_PB_04_Convert_Text ")+"\n")

    def on_DS_02_Size_Font_valueChanged(self,value):
                        
        
        self.FontSize = value
        if self.FontSize != 0:
            self.PB_04_Convert_Text.setText("Convert Text (M)")
            self.DS_02_Size_Font.setSuffix(" mm Size")
            self.fontSizeManual = True
        else:
            self.PB_04_Convert_Text.setText("Convert Text (A)")
            self.DS_02_Size_Font.setSuffix(" Auto")
            self.fontSizeManual = False
        #App.Console.PrintMessage("New FontSize " + str(self.FontSize)+"\n")

    def on_PB_04c_Convert_Edge(self):                                                    # Convert Edge to line
        self.selectionObjects = FreeCADGui.Selection.getSelectionEx()                    # Select an object or sub object
        self.progressBar.setMaximum(len(self.selectionObjects))
        compteur = 0
        for selection in self.selectionObjects:
            nameObject = selection.Object.Name
            countSubName = 0
            for selectedEdge in selection.SubObjects:
                subName = selection.SubElementNames[countSubName]
                compteur += 1
                self.progressBar.setValue(compteur)
                if (hasattr(selectedEdge,"Surface")) or (hasattr(selectedEdge,"Point")):
                    Part.show(selectedEdge.copy())                                       # create repro shape subObject
                    FreeCAD.Console.PrintMessage("Object Point or Surface duplicated !!" + "\n")
                    FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
                else:
                    try:
                        s = selectedEdge
                        if str(s.Curve) == "<Ellipse object>":                           # Ellipse
                            FreeCAD.Console.PrintMessage("Detected : Ellipse" + "\n")
                            pl=FreeCAD.Placement()
                            pl.Rotation = FreeCAD.Rotation(s.Curve.XAxis, s.Curve.YAxis, s.Curve.Axis, "ZXY")
                            pl.Base     = s.Curve.Center
                            ellipse = Draft.makeEllipse(s.Curve.MajorRadius, s.Curve.MinorRadius, placement=pl, face=False, support=None)
                            FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
                            edge  = selectedEdge
                            ellipse.FirstAngle = degrees(edge.FirstParameter)
                            ellipse.LastAngle  = degrees(edge.LastParameter)
                            Draft.autogroup(ellipse)
                
                        elif str(s.Curve) == "<Line object>":                            # Line
                            FreeCAD.Console.PrintMessage("Detected : Line" + "\n")
                            points = []
                            points = selectedEdge.Edges[0].discretize(3)                 # Dicretize
                            wire   =  Draft.makeLine(points[0],points[-1])
                            FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
                            Draft.autogroup(wire)
                            points[:]    = []
                                
                        elif (hasattr(s.Curve,"Center")) and (hasattr(s.Curve,"Radius")):# arc or circle
                            FreeCAD.Console.PrintMessage("Detected : Arc or Circle" + "\n")
                            ##https://github.com/yorikvanhavre/FreeCAD/blob/master/src/Mod/Draft/Draft.py#L264
                            pl=FreeCAD.Placement()
                            pl.Rotation = FreeCAD.Rotation(s.Curve.XAxis, s.Curve.YAxis, s.Curve.Axis, "ZXY")
                            pl.Base     = s.Curve.Center
                            circle = Draft.makeCircle(radius=s.Curve.Radius, placement=pl, face=False, support=None)
                            circle.FirstAngle = degrees(selectedEdge.FirstParameter)
                            circle.LastAngle  = degrees(selectedEdge.LastParameter)-360
                            FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
                            Draft.autogroup(circle)
                
                        elif (str(s.Curve) == "<BSplineCurve object>"):
                            FreeCAD.Console.PrintMessage("Detected : BSplineCurve" + "\n")
                            #print(s.Curve.getPoles())
                            points   = []

                            #try:
                                #points = s.Curve.getPoles() ?                            # getPoles
                            #except Exception:
                            bspline = s.Curve
                            arcs    = bspline.toBiArcs(0.001)
                            BsplineNumberElement = len(arcs)
                            points  = selectedEdge.Edges[0].discretize(len(arcs))        # Dicretize
                            spline   = Draft.makeBSpline(points, closed=False, face=False, support=None)
                            
                            FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
                            Draft.autogroup(spline)
                            points[:]= []
            
                        elif (str(s.Curve) == "<BezierCurve object>"):                   # BezierCurve
                            FreeCAD.Console.PrintMessage("Detected : BezierCurve" + "\n")
                            #print(s.Curve.getPoles())
                            points = []
                            
                            try:
                                points = s.Curve.getPoles()                              # getPoles
                            except Exception:
                                points = selectedEdge.Edges[0].discretize(1000)          # Discretize
                            try:
                                if self.CB_BezierCurve.isChecked():
                                    bezCurve = Draft.makeBezCurve(points, closed=False, support=None, degree=3)     #makeBezCurve3 (cubic) 0.19
                                    FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName + "_(Cub)"
                                else:
                                    bezCurve = Draft.makeBezCurve(points, closed=False, support=None, degree=None)  #makeBezCurve 0.19
                                    FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
                                Draft.autogroup(bezCurve)
                            except Exception:
                                bezCurve = Draft.makeBezCurve(points,closed=False,support=None)  #makeBezCurve 0.18
                                Draft.autogroup(bezCurve)
                            points[:]= []
            
                        else:
                            FreeCAD.Console.PrintMessage("Object duplicated !" + "\n")
                            Part.show(selectedEdge.copy())                               # create repro shape subObject
                            FreeCAD.ActiveDocument.ActiveObject.Label = nameObject + "_" + subName
            
                    except Exception:
                        FreeCAD.Console.PrintMessage("Error !!!" + "\n")
                        
                try:
                    if self.RB_01_FlatLines.isChecked():
                        FreeCADGui.ActiveDocument.ActiveObject.DisplayMode = u"Flat Lines"
                    if self.RB_02_Wireframe.isChecked():
                        FreeCADGui.ActiveDocument.ActiveObject.DisplayMode = u"Wireframe"
                    if self.RB_03_Points.isChecked():
                        FreeCADGui.ActiveDocument.ActiveObject.DisplayMode = u"Points"
                except Exception:
                    None

                if self.lineWidth != 0.0:
                    FreeCADGui.ActiveDocument.ActiveObject.LineWidth  = self.lineWidth
                else:
                    FreeCADGui.ActiveDocument.ActiveObject.LineWidth  = selection.Object.ViewObject.LineWidth
                    
                try:
                    if self.groupBox_00.isChecked():
                                                                                          
                        FreeCADGui.ActiveDocument.ActiveObject.LineColor  = (self.redFL, self.greenFL, self.blueFL)
                        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (self.redFL, self.greenFL, self.blueFL)
                        FreeCADGui.ActiveDocument.ActiveObject.PointColor = (self.redFL, self.greenFL, self.blueFL)
                    else:
                                                                                                                 
                        FreeCADGui.ActiveDocument.ActiveObject.PointSize  = selection.Object.ViewObject.PointSize
                        FreeCADGui.ActiveDocument.ActiveObject.LineColor  = selection.Object.ViewObject.LineColor
                        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = selection.Object.ViewObject.ShapeColor
                        FreeCADGui.ActiveDocument.ActiveObject.PointColor = selection.Object.ViewObject.PointColor
                except Exception:
                    None
                    
                countSubName += 1
                
            if self.RB_01_Default.isChecked():
                None
            if self.RB_02_Hidden.isChecked():
                print( "Hidden : ",nameObject)
                FreeCADGui.ActiveDocument.getObject(nameObject).Visibility = False
            try:
                if self.RB_03_Delete.isChecked():
                    print( "Delete : ",nameObject)
                    doc.removeObject(nameObject)
            except Exception:
                FreeCAD.Console.PrintError("Error Delete : ",str(nameObject) + "\n")

        self.progressBar.setValue(0)
        FreeCAD.ActiveDocument.recompute()
#        FreeCAD.Console.PrintMessage(str("on_PB_04c_Convert_Edge")+"\n")

    def on_groupBox_00(self):
        if self.groupBox_00.isChecked():
            None
        else:
            None
#        FreeCAD.Console.PrintMessage(str("on_groupBox_00")+"\n")

    def on_DS_01_Width_Line_valueChanged(self,LineWidth):
        self.lineWidth = LineWidth
        if self.lineWidth != 0.0:
            self.DS_01_Width_Line.setSuffix(" mm Width")
            self.PB_04c_Convert_Edge.setText("Convert Wire (M)")
        else:
            self.DS_01_Width_Line.setSuffix(" Auto")
            self.PB_04c_Convert_Edge.setText("Convert Wire (A)")
#        FreeCAD.Console.PrintMessage(str("on_DS_01_Width_Line_valueChanged ")+str(self.lineWidth)+"\n")

    def on_CB_BezierCurve_clicked(self):
        if self.CB_BezierCurve.isChecked():
            self.CB_BezierCurve.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_CubicBezCurve.svg")))
            self.CB_BezierCurve.setText("Cubic BezierCurve")
        else:
            self.CB_BezierCurve.setIcon(QtGui.QIcon.fromTheme("Part",QtGui.QIcon(":/icons/Draft_BezCurve.svg")))
            self.CB_BezierCurve.setText("BezierCurve")
#        FreeCAD.Console.PrintMessage(str("on_CB_BezierCurve_clicked ")+"\n")

    def on_PB_05_Reset(self):                     # 
        global ui
        global setSystemFonts
        global PolicePath
        global nomPolice
 
        #p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
        #print( p.GetUnsigned("DefaultShapeLineColor"))
        self.red     = 255   #204               # for button
        self.green   = 0     #204
        self.blue    = 0     #204
        self.alpha   = 255   # 255 = visibility max (opacity)
        self.redFL   = float(255.0 / 255.0)     # for object FC
        self.greenFL = float(0.0   / 255.0)
        self.blueFL  = float(0.0   / 255.0)
        self.alphaFL = float(255.0 / 255.0)     # 1.0 = visibility max (opacity)
        
        self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+")")
        self.groupBox_00.setChecked(False)
        
        self.RB_01_Default.setChecked(True)
        self.lineWidth = 0.0
        self.DS_01_Width_Line.setValue(self.lineWidth)
        self.DS_02_Size_Font.setValue(0.0)

        MyLabelPatience.label.show()
        FreeCADGui.updateGui()                                 # rafraichi l'ecran
        setSystemFonts = 0
        ui.searchFont(self.pathFont)
        MyLabelPatience.label.close()

        self.fontSizeManual    = False
        self.PB_04_Convert_Text.setText("Convert Text (A)")
        self.FontSize  = 0.0
        self.DS_02_Size_Font.setValue(self.FontSize)
        self.fonte     = PolicePath + "/" + nomPolice + ".TTF"
        self.CB_BezierCurve.setChecked(False)
        self.RB_01_FlatLines.setChecked(True)
#        FreeCAD.Console.PrintMessage(str("on_PB_05_Reset ")+"\n")

    def on_PB_09_Upgrade(self):                     # 
        try:
            Draft.upgrade(FreeCADGui.Selection.getSelection(), delete=True)
            FreeCAD.ActiveDocument.recompute()
        except Exception:
            None
#        FreeCAD.Console.PrintMessage(str("on_PB_06_Downgrade ")+"\n")

    def on_PB_06_Downgrade(self):                     # 
        try:
            Draft.downgrade(FreeCADGui.Selection.getSelection(),delete=True)
            FreeCAD.ActiveDocument.recompute()
        except Exception:
            None
#        FreeCAD.Console.PrintMessage(str("on_PB_06_Downgrade ")+"\n")

    def on_PB_07_Quit(self):                     # 
        FreeCAD.Console.PrintMessage("End Compound +"+"\n")
        self.window.hide()
#        FreeCAD.Console.PrintMessage(str("on_PB_06_Quit ")+"\n")

    def on_PB_Help_clicked(self):
        WebGui.openBrowser("https://wiki.freecadweb.org/Macro_Compound_Plus")
        App.Console.PrintMessage("https://wiki.freecadweb.org/Macro_Compound_Plus" + "\n")
#        FreeCAD.Console.PrintMessage(str("Help ")+"\n")

###### Read Configuration begin ####
#switchModeTextList = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("switchModeTextList")
#switchFontComBox   = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("switchFontComBox")
#setSystemFonts     = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("setSystemFonts")
#seTtextAlignement  = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetInt("seTtextAlignement")
###### Read Configuration end   ####

###### Write Configuration begin ####
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("switchModeTextList", True)    # True or False
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("switchFontComBox", True)      # True or False
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("setSystemFonts", True)        # True or False
#FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetInt("seTtextAlignement", 0)         # 0, 1, or 2
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("Version",__version__ + " (" + __date__ + ")")# 
###### Write Configuration end   ####

Compound = QtWidgets.QMainWindow()
ui = Ui_Compound()
ui.setupUi(Compound)
Compound.show()

Links

My macros to Github

Version

  • 14/05/2020 ver 00.03 : upgrade pySide2 and Qt5 layout and (matPlotLib Font) and convert Circle, Arc, Ellipse, BezierCurve
  • 24/01/2018 ver 00.02 : sup "import PyQt4"
  • 21/11/2016 ver 00.01 :