Property/fr: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
mNo edit summary
(30 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<div class="mw-translate-fuzzy">
{{Property/fr}}
</div>


== Introduction ==
Properties play a very important part in FreeCAD, since it has been designed to work with parametric objects, which are objects defined only by their properties.


Une [[Property/fr|propriété]] est une information, telle qu'un nombre ou une chaîne de texte, attachée à un document FreeCAD ou à un objet d'un document. Les propriétés peuvent être visualisées et modifiées avec l'[[Property editor/fr|éditeur de propriétés]].
Custom [[scripted objects]] in FreeCAD can have properties of the following types:


Les propriétés jouent un rôle très important dans FreeCAD. Comme les objets dans FreeCAD sont "paramétriques", cela signifie que leur comportement est défini par leurs propriétés et par la manière dont ces propriétés sont utilisées comme entrée pour leurs méthodes de classe. Voir aussi [[PropertyLink:_InList_and_OutList/fr|PropertyLink:_InList_and_OutList]]

== Tous les types de propriétés ==

Les [[scripted objects/fr|Objets créés par script]] personnalisés dans FreeCAD peuvent avoir des propriétés des types suivants :
{{Code|code=
{{Code|code=
Bool
Boolean
Float
Float
FloatList
FloatList
FloatConstraint
FloatConstraint
Angle
Angle
Distance
Distance
ExpressionEngine
Integer
Integer
IntegerConstraint
IntegerConstraint
Percent
Percent
Enumeration
Enumeration
IntegerList
IntegerList
String
String
StringList
StringList
Link
Length
LinkList
Link
Matrix
LinkList
Vector
LinkSubList
VectorList
Matrix
Placement
Vector
PlacementLink
VectorList
Color
VectorDistance
ColorList
Placement
Material
PlacementLink
Path
PythonObject
File
Color
FileIncluded
ColorList
PartShape
Material
FilletContour
Path
Circle
File
FileIncluded
PartShape
FilletContour
Circle
}}
}}


En interne, le nom de la propriété est préfixé par {{incode|App::Property}}:
{{docnav/fr|Personnaliser l'interface|Travailler avec les ateliers}}
{{Code|code=
App::PropertyBool
App::PropertyFloat
App::PropertyFloatList
...
}}


Rappelez-vous qu'il s'agit de propriétés {{Emphasis|types}}. Un même objet peut avoir plusieurs propriétés du même type, mais avec des noms différents.
[[Category:User Documentation/fr]]


par exemple:
[[Category:Base]]

{{Code|code=
obj.addProperty("App::PropertyFloat", "Length")
obj.addProperty("App::PropertyFloat", "Width")
obj.addProperty("App::PropertyFloat", "Height")
}}

Cela indique un objet avec trois propriétés de type "Float", nommées respectivement "Length", "Width" et "Height".

== Scrip ==

{{Emphasis|See also:}} [[FreeCAD Scripting Basics/fr|FreeCAD scrip de base]]

Un [[scripted objects/fr|objet scripté]] est créé en premier, puis les propriétés lui sont attribuées.
{{Code|code=
obj = App.ActiveDocument.addObject("Part::Feature", "CustomObject")

obj.addProperty("App::PropertyFloat", "Velocity", "Parameter", "Body speed")
obj.addProperty("App::PropertyBool", "VelocityEnabled", "Parameter", "Enable body speed")
}}

En général, les propriétés {{Emphasis|Data}} sont affectées à l'aide de la méthode {{incode|addProperty()}} de l'objet. D'autre part, les propriétés {{Emphasis|View}} sont normalement fournies automatiquement par l'objet parent à partir duquel l'objet scripté est dérivé.

Par exemple:
* Dériver de {{incode|App::FeaturePython}} fournit uniquement 4 propriétés {{Emphasis|View}}: "Display Mode", "On Top When Selected", "Show In Tree" et "Visibility".
* Dériver de {{incode|Part::Feature}} fournit 17 propriétés {{Emphasis|View}}: les quatre précédentes, plus "Angular Deflection", "Zone de sélection", "Deviation", "Draw Style", "Lighting", "Line Color", "Line Width", "Point Color", "Point Size", "Selectable", "Selection Style", "Shape Color", et "Transparency".

Néanmoins, les propriétés {{Emphasis|View}} peuvent également être affectées à l'aide de la méthode {{incode|addProperty()}} de l'objet fournisseur de vue.
{{Code|code=
obj.ViewObject.addProperty("App::PropertyBool", "SuperVisibility", "Base", "Make the object glow")
}}

== Code source ==

Dans le code source, les propriétés se trouvent dans divers fichiers {{FileName|src/App/Property*}} .

Ils sont importés et initialisés dans {{incode|[https://github.com/FreeCAD/FreeCAD/blob/9c27f1078e5ec516fe882aac1a27f5c6c6174554/src/App/Application.cpp#L1681-L1758 src/App/Application.cpp]}}.
{{Code|lang=cpp|code=
#include "Property.h"
#include "PropertyContainer.h"
#include "PropertyUnits.h"
#include "PropertyFile.h"
#include "PropertyLinks.h"
#include "PropertyPythonObject.h"
#include "PropertyExpressionEngine.h"
}}


{{Powerdocnavi{{#translation:}}}}
[[Category:Developer Documentation{{#translation:}}]]
[[Category:Python Code{{#translation:}}]]
{{clear}}
{{clear}}

Revision as of 09:40, 12 April 2021

Introduction

Une propriété est une information, telle qu'un nombre ou une chaîne de texte, attachée à un document FreeCAD ou à un objet d'un document. Les propriétés peuvent être visualisées et modifiées avec l'éditeur de propriétés.

Les propriétés jouent un rôle très important dans FreeCAD. Comme les objets dans FreeCAD sont "paramétriques", cela signifie que leur comportement est défini par leurs propriétés et par la manière dont ces propriétés sont utilisées comme entrée pour leurs méthodes de classe. Voir aussi PropertyLink:_InList_and_OutList

Tous les types de propriétés

Les Objets créés par script personnalisés dans FreeCAD peuvent avoir des propriétés des types suivants :

Bool
Float
FloatList
FloatConstraint
Angle
Distance
ExpressionEngine
Integer
IntegerConstraint
Percent
Enumeration
IntegerList
String
StringList
Length
Link
LinkList
LinkSubList
Matrix
Vector
VectorList
VectorDistance
Placement
PlacementLink
PythonObject
Color
ColorList
Material
Path
File
FileIncluded
PartShape
FilletContour
Circle

En interne, le nom de la propriété est préfixé par App::Property:

App::PropertyBool
App::PropertyFloat
App::PropertyFloatList
...

Rappelez-vous qu'il s'agit de propriétés types. Un même objet peut avoir plusieurs propriétés du même type, mais avec des noms différents.

par exemple:

obj.addProperty("App::PropertyFloat", "Length")
obj.addProperty("App::PropertyFloat", "Width")
obj.addProperty("App::PropertyFloat", "Height")

Cela indique un objet avec trois propriétés de type "Float", nommées respectivement "Length", "Width" et "Height".

Scrip

See also: FreeCAD scrip de base

Un objet scripté est créé en premier, puis les propriétés lui sont attribuées.

obj = App.ActiveDocument.addObject("Part::Feature", "CustomObject")

obj.addProperty("App::PropertyFloat", "Velocity", "Parameter", "Body speed")
obj.addProperty("App::PropertyBool", "VelocityEnabled", "Parameter", "Enable body speed")

En général, les propriétés Data sont affectées à l'aide de la méthode addProperty() de l'objet. D'autre part, les propriétés View sont normalement fournies automatiquement par l'objet parent à partir duquel l'objet scripté est dérivé.

Par exemple:

  • Dériver de App::FeaturePython fournit uniquement 4 propriétés View: "Display Mode", "On Top When Selected", "Show In Tree" et "Visibility".
  • Dériver de Part::Feature fournit 17 propriétés View: les quatre précédentes, plus "Angular Deflection", "Zone de sélection", "Deviation", "Draw Style", "Lighting", "Line Color", "Line Width", "Point Color", "Point Size", "Selectable", "Selection Style", "Shape Color", et "Transparency".

Néanmoins, les propriétés View peuvent également être affectées à l'aide de la méthode addProperty() de l'objet fournisseur de vue.

obj.ViewObject.addProperty("App::PropertyBool", "SuperVisibility", "Base", "Make the object glow")

Code source

Dans le code source, les propriétés se trouvent dans divers fichiers src/App/Property* .

Ils sont importés et initialisés dans src/App/Application.cpp.

#include "Property.h"
#include "PropertyContainer.h"
#include "PropertyUnits.h"
#include "PropertyFile.h"
#include "PropertyLinks.h"
#include "PropertyPythonObject.h"
#include "PropertyExpressionEngine.h"