.. role:: blue :class: blue Boolean Operation on Bodies =========================== .. _Boolean_Operation_on_Bodies_: .. версия ядра: 118053 The function .. code-block:: cpp MbResultType BooleanResult( const c3d::SolidSPtr & solid1, MbeCopyMode sameShell1, const c3d::SolidSPtr & solid2, MbeCopyMode sameShell2, const MbBooleanOperationParams & params, c3d::SolidSPtr & result ); constructs a new body by executing a Boolean operation on two solids with the ability to control face and edge merging. The function input parameters are: - **solid1** — the first solid for the Boolean operation; - **sameShell1** — the copy mode for the first solid; - **solid2** — the second solid for the Boolean operation; - **sameShell2** — the copy mode for the second solid; - **params** — the parameters of the Boolean operation. The function output parameter is the **result** object containing the constructed solid. The function returns a result code from the :blue:`MbResultType` enumeration (see *mb_operation_result.h*). The function is declared in the file *action_solid.h*. The function performs union, intersection and difference operations on two solids **solid1** and **solid2**. The parameters **sameShell1** and **sameShell2** control the transfer of faces, edges and vertices from the source solids **solid1** and **solid2** to the constructed solid **result**, and can take one of four values: - *cm_Same* = 0 (the shell is not copied); - *cm_KeepHistory* (the source shell and its copy share common base surfaces, vertices, and faces unchanged by the operation); - *cm_KeepSurface* (the source shell and its copy share common base surfaces); - *cm_Copy* (the source shell and its copy do not share any common data). A detailed description of the :blue:`MbeCopyMode` enumeration is provided in section :ref:`Copying a Set of Faces `. The class :blue:`MbBooleanOperationParams` contains parameters for executing the Boolean operation. When creating an object of class :blue:`MbBooleanOperationParams`, one of the following constructors is used: .. code-block:: cpp MbBooleanOperationParams( OperationType oType, const MbBooleanFlags & flags, const MbSNameMaker & operNames, ProgressIndicator * progress = nullptr ) MbBooleanOperationParams( OperationType oType, bool closed, const MbSNameMaker & operNames, IProgressIndicator * progress = nullptr ) where - **oType** — the type of Boolean operation; - **flags** — control flags for the Boolean operation; - **operNames** — name maker; - **closed** — indicator of closure of the operand shells; - **progress** — progress indicator for operation execution. The variant of :blue:`MbBooleanOperationParams` object with the **closed** parameter works only for non-closed solids and specifies the need to check the result for closure. The parameter **oType** defines the type of Boolean operation and can take three values: *bo_Union*, *bo_Intersect*, *bo_Difference*: - when **oType** = *bo_Union*, the function performs union of solids **solid1** and **solid2**; - when **oType** = *bo_Intersect*, the function performs intersection of solids **solid1** and **solid2**; - when **oType** = *bo_Difference*, the function performs subtraction of **solid2** from **solid1**. The parameter **operNames** is used for naming resulting objects of the Boolean operation. The parameter **flags** contains control flags for the Boolean operation. The object has the following flags, which can be set in the constructor when creating the object, or using separate setter functions: :blue:`bool` **mergeFaces** — merge similar faces; :blue:`bool` **mergeEdges** — merge similar edges; :blue:`bool` **closed** — closure of the operand shells; :blue:`bool` **enclosureCheck** — check shells for nesting; :blue:`bool` **allowNonIntersecting** — output the resulting shell if there are no intersections; :blue:`bool` **cutting** — shell cutting flag when building cuts and sections; :blue:`bool` **repairShellEdges** — shell edge repair flag for source shells. Figure 1 shows the source solids **solid1** and **solid2**: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.1.png :width: 12cm :align: center Рис. 1 Figure 2 shows the result of the Boolean union operation on solids **solid1** and **solid2** shown in Fig. 1: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.2.png :width: 12cm :align: center Рис. 2 Figure 3 shows the result of the Boolean intersection operation on solids **solid1** and **solid2** shown in Fig. 1: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.3.png :width: 12cm :align: center Рис. 3 Figure 4 shows the result of the Boolean difference operation (subtracting **solid2** from **solid1**) on the solids shown in Fig. 1: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.4.png :width: 12cm :align: center Рис. 4 Figure 5 shows the result of the Boolean difference operation (subtracting solid **solid1** from solid **solid2**) on the solids shown in Fig. 1: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.5.png :width: 12cm :align: center Рис. 5 To demonstrate the function's operation with an :blue:`MbBooleanFlags` object with different values of the *mergeFaces* flag, consider Boolean operations on source solids **solid1** and **solid2** shown in Fig. 6: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.6.png :width: 12cm :align: center Рис. 6 Figure 7 shows the result of the union of solids **solid1** and **solid2** when the function operates with the flag *mergeFaces* = *true*: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.7.png :width: 12cm :align: center Рис. 7 Figure 8 shows the result of the union of solids **solid1** and **solid2** when the function operates with the flag *mergeFaces* = *false*. Coinciding faces in Fig. 8 are not merged: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.8.png :width: 12cm :align: center Рис. 8 Figure 9 shows the result of the difference operation (subtracting **solid2** from **solid1**) when the function operates with the parameter *mergeFaces* = *true* (merge similar faces): .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.9.png :width: 12cm :align: center Рис. 9 Figure 10 shows the result of the difference operation (subtracting **solid2** from **solid1**) when the function operates with the parameter *mergeFaces* = *false*. Coinciding faces in Fig. 10 are not merged: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.1.10.png :width: 12cm :align: center Рис. 10 The function :blue:`BooleanResult`\() adds to the constructed solid's history log a builder :blue:`MbBooleanSolid`, which contains all the necessary data to execute the operation. The builder :blue:`MbBooleanSolid` is declared in the file *cr_boolean_solid.h*. Test.exe application executes Boolean operations on bodies using Create→Solid→As union with a solid→Solid, Create→Solid→As subtraction with a solid→Solid, Create→Solid→As intersection with a solid→Solid menu commands.