.. role:: blue :class: blue Cutting a Body into Parts ========================= .. _Cutting_a_Body_: .. версия ядра: 118056 The function .. code-block:: cpp MbResultType SolidCutting( const c3d::SolidSPtr & solid, MbeCopyMode sameShell, const MbShellCuttingParams & cuttingParams, c3d::SolidsSPtrVector & results ); cuts off part of a body by an intersecting surface or shell. The input parameters of the function are: - **srcSolid** -- an original body; - **sameShell** -- a copy mode of the original body; - **cuttingParams** -- parameters of the operation. The output parameter of the function is the constructed bodies **results**. The function returns an operation result code from the :blue:`MbResultType` enumeration (see *mb_operation_result.h*). The function is declared in the *action_solid.h* file. To initialize objects **cuttingParams** with operation parameters, the following default constructor is defined in the :blue:`MbShellCuttingParams` class: .. code-block:: cpp MbShellCuttingParams( int part, const MbMergingFlags & mergingFlags, bool cutAsClosed, const MbSNameMaker & snMaker, IProgressIndicator * prog = nullptr ) : cutterData ( ) , booleanFlags( ) , nameMaker ( &snMaker.Duplicate() ) , retainedPart( ts_neutral ) , prolongState( ) , progress ( prog ) { booleanFlags.InitCutting( cutAsClosed ); booleanFlags.SetMerging( mergingFlags ); SetRetainedPart( part ); } - **part** -- a retained part of the original shell (+1, 0, -1), 0 -- keep both parts; - **mergingFlags** -- flags for merging shell elements; - **cutAsClosed** -- a flag for building a closed shell; - **snMaker** -- an operation namer. Cutting a Body by a Flat Contour --------------------------------- .. _Cutting_a_Body_by_a_Flat_Contour_: The function constructs a non-closed shell by extruding in direction **dir** a two-dimensional contour **contour**, located in the XY plane of the local coordinate system **place**, and performs a Boolean intersection operation of the original body **solid** with the non-closed shell. If the vector **dir** equals zero, the contour extrusion is performed along the vector **place.axisZ**. For the operation to execute, the cutting contour must fully intersect the projection of the original body onto the XY plane of the local coordinate system **place** in the direction of the extrusion vector. The extrusion length of the contour is calculated so that the non-closed shell completely intersects the original body. To initialize objects **cuttingParams** of the function with operation parameters, the following contour constructors are defined in the :blue:`MbShellCuttingParams` class: The constructor with the ability to save a part: .. code-block:: cpp MbShellCuttingParams( const MbPlacement3D & place, const MbContour & contour, bool sameContour, const MbVector3D & dir, int part, const MbMergingFlags & mergingFlags, bool cutAsClosed, const MbSNameMaker & snMaker, IProgressIndicator * prog = nullptr ) : cutterData ( place, dir, contour, sameContour ) , booleanFlags( ) , nameMaker ( &snMaker.Duplicate() ) , retainedPart( ts_neutral ) , prolongState( ) , progress ( prog ) { booleanFlags.InitCutting( cutAsClosed ); booleanFlags.SetMerging( mergingFlags ); SetRetainedPart( part ); } The constructor without selecting a saved part (all parts are saved by default): .. code-block:: cpp MbShellCuttingParams( const MbPlacement3D & place, const MbContour & contour, bool sameContour, const MbVector3D & dir, const MbMergingFlags & mergingFlags, bool cutAsClosed, const MbSNameMaker & snMaker, IProgressIndicator * prog = nullptr ) : cutterData ( place, dir, contour, sameContour ) , booleanFlags( ) , nameMaker ( &snMaker.Duplicate() ) , retainedPart( ts_neutral ) , prolongState( ) , progress ( prog ) { booleanFlags.InitCutting( cutAsClosed ); booleanFlags.SetMerging( mergingFlags ); } where - **place** -- a local coordinate system in the XY plane of which the two-dimensional contour is located; - **contour** -- a two-dimensional contour for extrusion is located in the XY plane of the local coordinate system **place**; - **sameContour** -- the flag to use the original contour (true) or its copy (false); - **dir** -- a direction of contour extrusion; - **part** -- a retained part of the original body (+1, 0, -1), 0 -- keep both parts; - **mergingFlags** -- flags for merging shell elements; - **cutAsClosed** -- the flag for building a closed shell; - **snMaker** -- the operation namer. The parameter **part** determines the retained part of the original body **solid**: - if *part* = +1, the part of the body located to the right of the contour is retained when viewing along the contour towards the **place.axisZ** axis; - if *part* = -1, the part of the body located to the left of the contour is retained when viewing along the contour towards the **place.axisZ** axis; - if *part* = 0, both parts of the body are retained. The parameter **mergingFlags** controls the merging of similar faces and edges of the resulting shell. The parameter **cutAsClosed** indicates how the original body **solid** should be treated: as closed or non-closed. When **cutAsClosed** = *true*, the operation is performed on the set of points located inside and on the surface of the body. When **cutAsClosed** = *false*, the operation is performed on the set of points located on the body surface. The parameter **snMaker** provides naming of faces, edges and vertices of the constructed body. Fig. 1 shows the original body **solid**, the cutting contour **contour** and the XY plane of the local coordinate system **place**. .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.8.1.png :width: 9cm :align: center Fig. 1 Fig. 2 shows the constructed body **result** when *part* = +1 and *cutAsClosed* = *true*. Fig. 3 shows the constructed body **result** when *part* = -1 and *cutAsClosed* = *true*: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.8.2.png :width: 8cm :align: center Fig. 2 .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.8.3.png :width: 8cm :align: center Fig. 3 Fig. 4 shows the constructed body **result** when *part* = +1 and *cutAsClosed* = *false*: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.8.4.png :width: 9cm :align: center Fig. 4 When *part* = 0, the function constructs the body **result**, into which all parts of the original body **solid** obtained after cutting are included. To divide the body **result** into parts, use the functions :blue:`DetachParts`\() or :blue:`CreateParts`\(), described in section :ref:`Divide a Body into Disconnected Parts `. When using the constructor by contour: .. code-block:: cpp MbShellCuttingParams( const MbPlacement3D & place, const MbContour & contour, bool sameContour, const MbVector3D & dir, const MbMergingFlags & mergingFlags, bool cutAsClosed, const MbSNameMaker & snMaker, IProgressIndicator * prog = nullptr ); the function :blue:`SolidCutting`\() cuts the body by a surface obtained by extruding a flat contour and constructs separate bodies from all parts. Fig. 5 shows the body **result** constructed in this way when *cutAsClosed* = *true*: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.8.5.png :width: 9cm :align: center Fig. 5 The function :blue:`SolidCutting`\() adds to the history tree of the constructed body the creator :blue:`MbCuttingSolid`, which contains all necessary data for performing the operation. The creator :blue:`MbCuttingSolid` is declared in the file *cr_cutting_solid.h*. In the test application *test.exe*, cutting a body by a flat contour is performed using the menu commands "Create→Solid→Based on a solid→Cut by a 2D-Curve" and "Create→Shell→Based on a shell→Cut by a curve". Cutting a Body by a Surface ---------------------------- .. _Cutting_a_Body_by_a_Surface_: The function constructs a non-closed shell with one face based on the cutting surface **surface** and performs a Boolean intersection operation of the original body **solid** with the non-closed shell. For the operation to execute, the cutting surface must fully intersect the original body. To initialize objects **cuttingParams** of the function with operation parameters, the following surface constructors are defined in the :blue:`MbShellCuttingParams` class: .. code-block:: cpp MbShellCuttingParams( const MbSurface & surface, bool sameSurface, int part, const MbMergingFlags & mergingFlags, bool cutAsClosed, const MbSNameMaker & snMaker, IProgressIndicator * prog = nullptr ) : cutterData ( surface, sameSurface ) , booleanFlags( ) , nameMaker ( &snMaker.Duplicate() ) , retainedPart( ts_neutral ) , prolongState( ) , progress ( prog ) { booleanFlags.InitCutting( cutAsClosed ); booleanFlags.SetMerging( mergingFlags ); SetRetainedPart( part ); } .. code-block:: cpp MbShellCuttingParams( const MbSurface & surface, bool sameSurface, const MbMergingFlags & mergingFlags, bool cutAsClosed, const MbSNameMaker & snMaker, IProgressIndicator * prog = nullptr ) : cutterData ( surface, sameSurface ) , booleanFlags( ) , nameMaker ( &snMaker.Duplicate() ) , retainedPart( ts_neutral ) , prolongState( ) , progress ( prog ) { booleanFlags.InitCutting( cutAsClosed ); booleanFlags.SetMerging( mergingFlags ); } - **surface** -- a cutting surface; - **sameSurface** -- the flag to use the original surface (true) or its copy (false); - **part** -- a retained part of the original body (+1, 0, -1), 0 -- keep both parts; - **mergingFlags** -- flags for merging shell elements; - **cutAsClosed** -- the flag for building a closed shell; - **snMaker** -- the operation namer. The parameter **part** determines the retained part of the original body **solid**: - if **part** = +1, the part of the body located above the surface is retained (on the side towards which the surface normal is directed); - if **part** = -1, the part of the body located below the surface is retained; - if **part** = 0, both parts of the body are retained. The parameter **cutAsClosed** indicates how the original body **solid** should be treated: as closed or non-closed: - if **cutAsClosed** = *true*, the operation is performed on the set of points located inside and on the surface of the body; - if **cutAsClosed** = *false*, the operation is performed on the set of points located on the body surface. The parameter **snMaker** provides naming of faces, edges and vertices of the constructed body. Fig. 6 shows the original body **solid** and the cutting surface **surface**. .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.7.1.png :width: 8cm :align: center Fig. 6 Fig. 7 shows the constructed body **result** when *part* = +1 and *cutAsClosed* = true. Fig. 8 shows the constructed body **result** when *part* = -1 and *cutAsClosed* = true. .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.7.2.png :width: 7cm :align: center Fig. 7 .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.7.3.png :width: 7cm :align: center Fig. 8 Fig. 9 shows the constructed body **result** when *part* = +1 and *cutAsClosed* = false: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.7.4.png :width: 9cm :align: center Fig. 9 When **part** = 0, the function constructs the body **result**, into which all parts of the original body **solid** obtained after cutting are included. To divide the body **result** into parts, use the functions :blue:`DetachParts`\() or :blue:`CreateParts`\(), described in section :ref:`Divide a Body into Disconnected Parts `. When using the surface constructor .. code-block:: cpp MbShellCuttingParams( const MbSurface & surface, bool sameSurface, const MbMergingFlags & mergingFlags, bool cutAsClosed, const MbSNameMaker & snMaker, IProgressIndicator * prog = nullptr ) the function cuts the body by an intersecting surface and constructs separate bodies from all parts. Fig. 10 shows the body **result** constructed in this way when *cutAsClosed* = *true*: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/M.2.7.5.png :width: 9cm :align: center Fig. 10 In the test application *test.exe*, cutting a body by a surface is performed using the menu commands "Create→Solid→Based on a body→Cut by a surface" and "Create→Shell→Based on a shell→Cut by a surface". Cutting a Body by a Shell -------------------------- The function performs cutting of the original body **solid** by an intersecting shell **cutSolid**. For the operation to execute, the cutting shell **cutSolid** must fully intersect the original body **solid**. To initialize objects **cuttingParams** of the function with operation parameters, the following shell constructor is defined in the :blue:`MbShellCuttingParams` class: .. code-block:: cpp MbShellCuttingParams( const MbSolid & solid, bool sameSolid, int part, const MbMergingFlags & mergingFlags, bool cutAsClosed, const MbSNameMaker & snMaker, IProgressIndicator * prog = nullptr ) : cutterData ( solid, sameSolid, true ) , booleanFlags( ) , nameMaker ( &snMaker.Duplicate() ) , retainedPart( ts_neutral ) , prolongState( ) , progress ( prog ) { booleanFlags.InitCutting( cutAsClosed ); booleanFlags.SetMerging( mergingFlags ); SetRetainedPart( part ); } - **solid** -- a cutting shell; - **sameSolid** -- the flag to use the original body (true) or its copy (false); - **part** -- a retained part of the original body (+1, 0, -1), 0 -- keep both parts; - **mergingFlags** -- flags for merging shell elements; - **cutAsClosed** -- the flag for building a closed shell; - **snMaker** -- the namer of the operation. The parameter **part** determines the retained part of the original body **solid**: - if **part** = +1, the part of the body located outside the shell is retained; - if **part** = -1, the part of the body located inside the shell is retained; - if **part** = 0, both parts of the body are retained. The parameter **cutAsClosed** indicates how the original body **solid** should be treated: as closed or non-closed: - if **cutAsClosed** = *true*, the operation is performed on the set of points located inside and on the surface of the body; - if **cutAsClosed** = *false*, the operation is performed on the set of points located on the body surface. The parameter **snMaker** provides naming of faces, edges and vertices of the constructed body. Fig. 11 shows the original body **solid** and the cutting shell **cutSolid**. .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/Cutting_by_shell_1.png :width: 9cm :align: center Fig. 11 Fig. 12 shows the constructed body **result** when *part* = +1 and *cutAsClosed* = *true*. Fig. 13 shows the constructed body **result** when *part* = -1 and *cutAsClosed* = *true*: .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/Cutting_by_shell_2.png :width: 8cm :align: center Fig. 12 .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/Cutting_by_shell_3.png :width: 8cm :align: center Fig. 13 When **part** = 0, the function constructs the body **result**, into which all parts of the original body **solid** obtained after cutting are included (Fig. 14): .. figure:: /MODELER/OPERATIONS_ON_BODIES/pictures/Cutting_by_shell_4.png :width: 9cm :align: center Fig. 14 In the test application *test.exe*, cutting a body by a shell is performed using the menu commands "Create→Solid→Based on a solid→Cut by a shell" and "Create→Shell→Based on a shell→Cut by a shell".