From: eap Date: Wed, 15 Dec 2021 15:36:27 +0000 (+0300) Subject: bos #26454 [EDF] (2021) SMESH: interactive mesh modification X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Focc%2F26454_interactive_modif;p=modules%2Fsmesh.git bos #26454 [EDF] (2021) SMESH: interactive mesh modification --- diff --git a/_stash b/_stash new file mode 100644 index 000000000..2cb3cde9f --- /dev/null +++ b/_stash @@ -0,0 +1,3 @@ +1) partial Fix of QuadFromMedialAxis algo +2) Begin fix 19982 EDF 21954 - Compute mesh fails + \ No newline at end of file diff --git a/doc/salome/examples/modifying_meshes_cut_triangles.py b/doc/salome/examples/modifying_meshes_cut_triangles.py new file mode 100644 index 000000000..250b55952 --- /dev/null +++ b/doc/salome/examples/modifying_meshes_cut_triangles.py @@ -0,0 +1,36 @@ +# Cutting Triangles + +import salome +salome.salome_init_without_session() +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New() + +# create 3 triangles and 1 segment all sharing edge 1-2 +mesh = smesh.Mesh() +n1 = mesh.AddNode( 0, 0, 0) +n2 = mesh.AddNode( 0, 0, -10) +n3 = mesh.AddNode( 10, 0, 0) +n4 = mesh.AddNode( 0, 10, 0) +n5 = mesh.AddNode( 0, -10, 0) +mesh.AddFace([ n1, n2, n3]) +mesh.AddFace([ n1, n2, n4]) +mesh.AddFace([ n1, n2, n5]) +mesh.AddEdge([ n1, n2] ) + +# =========================================================================== +# cut all the triangles and the segment by setting a new node on the segment +# =========================================================================== + +mesh.AddNodeOnSegment( n1, n2, 0.6 ) +assert mesh.NbNodes() == 6 # one new node created +assert mesh.NbTriangles() == 6 # each of the 3 triangles is split into two +assert mesh.NbEdges() == 2 # a segment is split into two + +# =============================================================== +# cut a triangle into three by adding a new node on the triangle +# =============================================================== + +triangleID = 1 +mesh.AddNodeOnFace( triangleID, 2, 0, -6 ) +assert mesh.NbNodes() == 7 # one new node created +assert mesh.NbTriangles() == 8 # the triangles is split into three diff --git a/doc/salome/examples/modifying_meshes_ex11.py b/doc/salome/examples/modifying_meshes_ex11.py index 28b544bc0..16ffe8777 100644 --- a/doc/salome/examples/modifying_meshes_ex11.py +++ b/doc/salome/examples/modifying_meshes_ex11.py @@ -1,10 +1,18 @@ # Removing Nodes import SMESH_mechanic - mesh = SMESH_mechanic.mesh # remove nodes #246 and #255 + res = mesh.RemoveNodes([246, 255]) if res == 1: print("Nodes removing is OK!") else: print("KO nodes removing.") + + +# Removing a Node with Reconnection +# ================================== + +print("Before RemoveNodeWithReconnection(): %s nodes, %s faces" % ( mesh.NbNodes(), mesh.NbFaces())) +mesh.RemoveNodeWithReconnection( 600 ) +print("After RemoveNodeWithReconnection(): %s nodes, %s faces" % ( mesh.NbNodes(), mesh.NbFaces())) diff --git a/doc/salome/gui/SMESH/images/add_node_on_face-dlg.png b/doc/salome/gui/SMESH/images/add_node_on_face-dlg.png new file mode 100644 index 000000000..64dc2257e Binary files /dev/null and b/doc/salome/gui/SMESH/images/add_node_on_face-dlg.png differ diff --git a/doc/salome/gui/SMESH/images/add_node_on_face.png b/doc/salome/gui/SMESH/images/add_node_on_face.png new file mode 100644 index 000000000..84434939f Binary files /dev/null and b/doc/salome/gui/SMESH/images/add_node_on_face.png differ diff --git a/doc/salome/gui/SMESH/images/add_node_on_segment-dlg.png b/doc/salome/gui/SMESH/images/add_node_on_segment-dlg.png new file mode 100644 index 000000000..25cbb08ca Binary files /dev/null and b/doc/salome/gui/SMESH/images/add_node_on_segment-dlg.png differ diff --git a/doc/salome/gui/SMESH/images/add_node_on_segment.png b/doc/salome/gui/SMESH/images/add_node_on_segment.png new file mode 100644 index 000000000..0601b8aef Binary files /dev/null and b/doc/salome/gui/SMESH/images/add_node_on_segment.png differ diff --git a/doc/salome/gui/SMESH/images/mesh_split_diag_interactive.png b/doc/salome/gui/SMESH/images/mesh_split_diag_interactive.png new file mode 100644 index 000000000..1342df96e Binary files /dev/null and b/doc/salome/gui/SMESH/images/mesh_split_diag_interactive.png differ diff --git a/doc/salome/gui/SMESH/images/mesh_split_face_interactive.png b/doc/salome/gui/SMESH/images/mesh_split_face_interactive.png new file mode 100644 index 000000000..5323e3fe7 Binary files /dev/null and b/doc/salome/gui/SMESH/images/mesh_split_face_interactive.png differ diff --git a/doc/salome/gui/SMESH/images/meshtopass1.png b/doc/salome/gui/SMESH/images/meshtopass1.png index 8ea8af795..1705f5e72 100644 Binary files a/doc/salome/gui/SMESH/images/meshtopass1.png and b/doc/salome/gui/SMESH/images/meshtopass1.png differ diff --git a/doc/salome/gui/SMESH/images/meshtopass2.png b/doc/salome/gui/SMESH/images/meshtopass2.png index b0bd28a89..2bb53dcda 100644 Binary files a/doc/salome/gui/SMESH/images/meshtopass2.png and b/doc/salome/gui/SMESH/images/meshtopass2.png differ diff --git a/doc/salome/gui/SMESH/images/meshtopass3.png b/doc/salome/gui/SMESH/images/meshtopass3.png new file mode 100644 index 000000000..bdbf86fac Binary files /dev/null and b/doc/salome/gui/SMESH/images/meshtopass3.png differ diff --git a/doc/salome/gui/SMESH/images/remove_node_reconnection.png b/doc/salome/gui/SMESH/images/remove_node_reconnection.png new file mode 100644 index 000000000..02eef9c0d Binary files /dev/null and b/doc/salome/gui/SMESH/images/remove_node_reconnection.png differ diff --git a/doc/salome/gui/SMESH/images/remove_node_reconnection_dlg.png b/doc/salome/gui/SMESH/images/remove_node_reconnection_dlg.png new file mode 100644 index 000000000..ecc57bd1c Binary files /dev/null and b/doc/salome/gui/SMESH/images/remove_node_reconnection_dlg.png differ diff --git a/doc/salome/gui/SMESH/images/remove_node_reconnection_icon.png b/doc/salome/gui/SMESH/images/remove_node_reconnection_icon.png new file mode 100644 index 000000000..5b35eab87 Binary files /dev/null and b/doc/salome/gui/SMESH/images/remove_node_reconnection_icon.png differ diff --git a/doc/salome/gui/SMESH/input/add_node_on_face.rst b/doc/salome/gui/SMESH/input/add_node_on_face.rst new file mode 100644 index 000000000..1b7cddf9c --- /dev/null +++ b/doc/salome/gui/SMESH/input/add_node_on_face.rst @@ -0,0 +1,37 @@ +.. _add_node_on_face_page: + +***************************** +Cutting a face into triangles +***************************** + +This operation cuts a face into triangles by adding a node on the face and connecting the new node with face nodes. + + .. image:: ../images/add_node_on_face.png + :align: center + +*To cut a face:* + +.. |img| image:: ../images/mesh_split_face_interactive.png + +#. Select a mesh and display it in the 3D Viewer. +#. In the **Modification** menu select the **Add node to triangle** item or click *"Add node to triangle"* button |img| in the toolbar. + + The following dialog box will appear: + + .. image:: ../images/add_node_on_face-dlg.png + :align: center + + +#. Enter an **ID** of the face to split either by picking it in the 3D viewer or by typing its ID. + +#. Press *Selection* button in **Node location by mouse click** group to activate specifying location of a new node. You can specify it + + * by clicking with your mouse on the face in the Viewer, + * by typing coordinates in **X, Y, Z** fields, + * by setting coordinates using arrows of spin boxes. + +#. Activate **Preview** to see a result of the operation. + +#. Click the **Apply** or **Apply and Close** button to confirm the operation. + +**See Also** a sample TUI Script of a :ref:`tui_cutting_triangles` operation. diff --git a/doc/salome/gui/SMESH/input/add_node_on_segment.rst b/doc/salome/gui/SMESH/input/add_node_on_segment.rst new file mode 100644 index 000000000..9ab16bbfb --- /dev/null +++ b/doc/salome/gui/SMESH/input/add_node_on_segment.rst @@ -0,0 +1,37 @@ +.. _add_node_on_segment_page: + +***************** +Cutting triangles +***************** + +This operation cuts triangles into two by adding a node on an edge bounding these triangles. + + .. image:: ../images/add_node_on_segment.png + :align: center + +*To cut triangles:* + +.. |img| image:: ../images/mesh_split_diag_interactive.png + +#. Select a mesh and display it in the 3D Viewer. +#. In the **Modification** menu select the **Add node on segment** item or click *"Add node on segment"* button |img| in the toolbar. + + The following dialog box will appear: + + .. image:: ../images/add_node_on_segment-dlg.png + :align: center + + +#. Enter IDs of nodes forming the edge in the **Edge** field (the node IDs must be separated by a dash) or select the edge in the 3D viewer. + +#. Enter location of a new node on the edge which is defined as a real number in the range between 0.0 and 1.0. You can define it + + * by clicking with your mouse on the edge in the Viewer, + * by typing a number in a field, + * by setting a number using arrows of a spin box. + +#. Activate **Preview** to see a result of the operation. + +#. Click the **Apply** or **Apply and Close** button to confirm the operation. + +**See Also** a sample TUI Script of a :ref:`tui_cutting_triangles` operation. diff --git a/doc/salome/gui/SMESH/input/adding_quadratic_elements.rst b/doc/salome/gui/SMESH/input/adding_quadratic_elements.rst index 2bcba5100..b706aa724 100644 --- a/doc/salome/gui/SMESH/input/adding_quadratic_elements.rst +++ b/doc/salome/gui/SMESH/input/adding_quadratic_elements.rst @@ -28,10 +28,12 @@ There are several ways to create quadratic elements in your mesh: .. image:: ../images/image152.png :align: center -.. note:: + .. note:: All dialogs for adding quadratic element to the mesh provide the possibility to automatically add an element to the specified group or to create the group anew using **Add to group** box, that allows choosing an existing group for the created node or element or giving the name to a new group. By default, the **Add to group** check box is switched off. If the user switches this check box on, the combo box listing all currently existing groups of the corresponding type becomes available. By default, no group is selected. In this case, when the user presses **Apply** or **Apply & Close** button, the warning message box informs the user about the necessity to input a new group name. The combo box lists groups of all the :ref:`three types `: both :ref:`standalone groups `, :ref:`groups on filter `, and :ref:`groups on geometry `. If the user chooses a group on geometry or on filter, he is warned and proposed to convert this group to standalone. If the user rejects conversion operation, it is cancelled and a new node/element is not created! -To create any **Quadratic Element** specify the nodes which will form your element by selecting them in the 3D viewer with pressed Shift button and click *Selection* button to the right of **Corner Nodes** label. Their numbers will appear in the dialog box as **Corner Nodes** (alternatively you can just input numbers in this field without selection; note that to use this way the mesh should be selected before invoking this operation). The edges formed by the corner nodes will appear in the table. To define the middle nodes for each edge, double-click on the respective field and input the number of the node (or pick the node in the viewer). For bi-quadratic and tri-quadratic elements, your also need to specify central nodes. As soon as all needed nodes are specified, a preview of a new quadratic element will be displayed in the 3D viewer. Then you will be able to click **Apply** or **Apply and Close** button to add the element to the mesh. +#. To create any **Quadratic Element** specify the nodes which will form your element by selecting them in the 3D viewer with pressed Shift button and click *Selection* button to the right of **Corner Nodes** label. Their numbers will appear in the dialog box as **Corner Nodes** (alternatively you can just input numbers in this field without selection; note that to use this way the mesh should be selected before invoking this operation). The edges formed by the corner nodes will appear in the table. To define the middle nodes for each edge, double-click on the respective field and input the number of the node (or pick the node in the viewer). For bi-quadratic and tri-quadratic elements, your also need to specify central nodes. As soon as all needed nodes are specified, a preview of a new quadratic element will be displayed in the 3D viewer. + +#. Click **Apply** or **Apply and Close** button to add the element to the mesh. .. image:: ../images/aqt.png :align: center diff --git a/doc/salome/gui/SMESH/input/mesh_through_point.rst b/doc/salome/gui/SMESH/input/mesh_through_point.rst index 0065e2478..47bd8c472 100644 --- a/doc/salome/gui/SMESH/input/mesh_through_point.rst +++ b/doc/salome/gui/SMESH/input/mesh_through_point.rst @@ -8,6 +8,7 @@ In mesh you can define a node at a certain point either * by movement of the node closest to the point or * by movement of a selected node to the point. +* by movement of a selected node to the point specified by mouse click. *To displace a node:* @@ -34,6 +35,11 @@ In mesh you can define a node at a certain point either .. centered:: Automatic node selection + .. image:: ../images/meshtopass3.png + :align: center + + .. centered:: + Manual node selection with mouse location #. Specify the way of node selection: manually (the first radio button) or automatically (the second radio button). diff --git a/doc/salome/gui/SMESH/input/modifying_meshes.rst b/doc/salome/gui/SMESH/input/modifying_meshes.rst index 3c9b7d132..60e5f84a0 100644 --- a/doc/salome/gui/SMESH/input/modifying_meshes.rst +++ b/doc/salome/gui/SMESH/input/modifying_meshes.rst @@ -29,6 +29,8 @@ Salome provides a vast specter of mesh modification and transformation operation * :ref:`Unite two triangles `. * :ref:`Unite several adjacent triangles `. * :ref:`Cut a quadrangle ` into two triangles. +* :ref:`Cut triangles ` into two by adding a node on edge. +* :ref:`Cut a face ` into triangles by adding a node on it. * :ref:`Split ` volumic elements into tetrahedra or prisms. * :ref:`Split bi-quadratic ` elements into linear ones without creation of additional nodes. * :ref:`Smooth ` elements, reducung distortions in them by adjusting the locations of nodes. @@ -67,6 +69,8 @@ Salome provides a vast specter of mesh modification and transformation operation changing_orientation_of_elements.rst reorient_faces.rst cutting_quadrangles.rst + add_node_on_segment.rst + add_node_on_face.rst split_to_tetra.rst split_biquad_to_linear.rst smoothing.rst diff --git a/doc/salome/gui/SMESH/input/modules.rst b/doc/salome/gui/SMESH/input/modules.rst index 41915c4f1..6665aa100 100644 --- a/doc/salome/gui/SMESH/input/modules.rst +++ b/doc/salome/gui/SMESH/input/modules.rst @@ -365,6 +365,7 @@ Removing nodes and elements Mesh.RemoveElements Mesh.RemoveNodes + Mesh.RemoveNodeWithReconnection Mesh.RemoveOrphanNodes Modifying nodes and elements @@ -479,6 +480,8 @@ Cutting elements Mesh.SplitQuadsNearTriangularFacets Mesh.SplitHexaToTetras Mesh.SplitHexaToPrisms + Mesh.AddNodeOnSegment + Mesh.AddNodeOnFace Smoothing ========= diff --git a/doc/salome/gui/SMESH/input/removing_nodes_and_elements.rst b/doc/salome/gui/SMESH/input/removing_nodes_and_elements.rst index bfbb16d0c..6d7281cfc 100644 --- a/doc/salome/gui/SMESH/input/removing_nodes_and_elements.rst +++ b/doc/salome/gui/SMESH/input/removing_nodes_and_elements.rst @@ -7,6 +7,7 @@ Removing nodes and elements In MESH you can remove nodes and all types of cells of your mesh. * :ref:`removing_nodes_anchor` +* :ref:`removing_nodes_reconnect_anchor` * :ref:`removing_orphan_nodes_anchor` * :ref:`removing_elements_anchor` * :ref:`clear_mesh_anchor` @@ -33,7 +34,7 @@ Removing nodes In this dialog box you can specify one or several nodes: * choose mesh nodes with the mouse in the 3D Viewer. It is possible to select a whole area with a mouse frame; or - * input the node IDs directly in **ID Elements** field. The selected nodes will be highlighted in the viewer; or + * input the node IDs directly in **Node IDs** field. The selected nodes will be highlighted in the viewer; or * apply Filters. **Set filter** button allows to apply a filter to the selection of nodes. See more about filters in the :ref:`selection_filter_library_page` page. #. Click **Apply** or **Apply and Close** to confirm deletion of the specified nodes. @@ -42,6 +43,38 @@ Removing nodes Be careful while removing nodes because if you remove a definite node of your mesh all adjacent elements will be also deleted. +.. _removing_nodes_reconnect_anchor: + +Removing node with reconnection +############################### + +This operation removes a node and changes surrounding faces in order to cover a hole appearing in the mesh. This operation applies to 2D triangle mesh only. + + .. image:: ../images/remove_node_reconnection.png + :align: center + +**To remove a node:** + +.. |rmnr| image:: ../images/remove_node_reconnection_icon.png + +#. Select your mesh in the Object Browser or in the 3D viewer. +#. From the **Modification** menu choose **Remove** and from the associated submenu select the **Node with reconnection**, or just click *"Remove node with reconnection"* button |rmnr| in the toolbar. + The following dialog box will appear: + + .. image:: ../images/remove_node_reconnection_dlg.png + :align: center + + + In this dialog box you can specify one node to remove: + + * choose a mesh node with the mouse in the 3D Viewer or + * input the node ID directly in **ID** field. The selected node will be highlighted in the viewer. + + Activate **Preview** to see how faces will change. + +#. Click **Apply** or **Apply and Close** to confirm deletion of the specified node. + + .. _removing_orphan_nodes_anchor: Removing orphan nodes diff --git a/doc/salome/gui/SMESH/input/tui_modifying_meshes.rst b/doc/salome/gui/SMESH/input/tui_modifying_meshes.rst index 1509e8d9f..72e541c4d 100644 --- a/doc/salome/gui/SMESH/input/tui_modifying_meshes.rst +++ b/doc/salome/gui/SMESH/input/tui_modifying_meshes.rst @@ -207,6 +207,16 @@ Cutting Quadrangles :download:`Download this script <../../../examples/modifying_meshes_ex20.py>` +.. _tui_cutting_triangles: + +Cutting Triangles +================= + +.. literalinclude:: ../../../examples/modifying_meshes_cut_triangles.py + :language: python + +:download:`Download this script <../../../examples/modifying_meshes_cut_triangles.py>` + .. _modifying_meshes_split_vol: Split Volumes into Tetrahedra diff --git a/idl/SMESH_MeshEditor.idl b/idl/SMESH_MeshEditor.idl index 69f159dc2..18ebe2a36 100644 --- a/idl/SMESH_MeshEditor.idl +++ b/idl/SMESH_MeshEditor.idl @@ -159,6 +159,13 @@ module SMESH */ smIdType RemoveOrphanNodes() raises (SALOME::SALOME_Exception); + /*! + * \brief Remove a mesh node and change surrounding faces to close a hole + * \param nodeID node identifier + * \throw if mesh is not a triangle one + */ + void RemoveNodeWithReconnection(in smIdType nodeID) raises (SALOME::SALOME_Exception); + /*! * \brief Add a new node. * \param x X coordinate of new node @@ -291,18 +298,44 @@ module SMESH raises (SALOME::SALOME_Exception); + /*! + * \brief Change node location + */ boolean MoveNode(in smIdType NodeID, in double x, in double y, in double z) raises (SALOME::SALOME_Exception); + /*! + * \brief Swap a diagonal of a quadrangle formed by two adjacent triangles + */ boolean InverseDiag(in smIdType NodeID1, in smIdType NodeID2) raises (SALOME::SALOME_Exception); - + /*! + * \brief Delete a diagonal of a quadrangle formed by two adjacent triangles + * so that a new quadrangle appears in place of the triangles + */ boolean DeleteDiag(in smIdType NodeID1, in smIdType NodeID2) raises (SALOME::SALOME_Exception); + /*! + * \brief Replace each triangle bound by Node1-Node2 segment with + * two triangles by connecting a node made on the segment with a node opposite + * to the segment. + */ + void AddNodeOnSegment(in smIdType Node1, in smIdType Node2, in double position) + raises (SALOME::SALOME_Exception); + /*! + * \brief Split a face into triangles by adding a new node onto the face + * and connecting the new node with face nodes + */ + void AddNodeOnFace(in smIdType triangle, in double x, in double y, in double z); + /*! + * \brief Change orientation of cells + */ boolean Reorient(in smIdType_array IDsOfElements) raises (SALOME::SALOME_Exception); - + /*! + * \brief Change orientation of cells + */ boolean ReorientObject(in SMESH_IDSource theObject) raises (SALOME::SALOME_Exception); /*! @@ -408,8 +441,8 @@ module SMESH * \return 1 if 1-3 diagonal is better, 2 if 2-4 * diagonal is better, 0 if error occurs. */ - long BestSplit (in long IDOfQuad, - in NumericalFunctor Criterion) raises (SALOME::SALOME_Exception); + short BestSplit (in smIdType IDOfQuad, + in NumericalFunctor Criterion) raises (SALOME::SALOME_Exception); /*! * \brief Split volumic elements into tetrahedrons diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 7e0d62012..9004064f5 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -121,6 +121,9 @@ SET(SMESH_RESOURCES_FILES mesh_minus.png mesh_move_node.png mesh_move_without_node.png + mesh_move_node_interactive.png + mesh_split_diag_interactive.png + mesh_split_face_interactive.png mesh_multi_edges.png mesh_multi_edges_2d.png mesh_node_to_point.png @@ -157,6 +160,7 @@ SET(SMESH_RESOURCES_FILES mesh_rem_element.png mesh_rem_node.png mesh_rem_orphan_nodes.png + mesh_rem_node_recon.png mesh_remove.png mesh_renumbering_elements.png mesh_renumbering_nodes.png diff --git a/resources/mesh_move_node_interactive.png b/resources/mesh_move_node_interactive.png new file mode 100644 index 000000000..6e28f2822 Binary files /dev/null and b/resources/mesh_move_node_interactive.png differ diff --git a/resources/mesh_rem_node_recon.png b/resources/mesh_rem_node_recon.png new file mode 100644 index 000000000..df07f475e Binary files /dev/null and b/resources/mesh_rem_node_recon.png differ diff --git a/resources/mesh_split_diag_interactive.png b/resources/mesh_split_diag_interactive.png new file mode 100644 index 000000000..1342df96e Binary files /dev/null and b/resources/mesh_split_diag_interactive.png differ diff --git a/resources/mesh_split_face_interactive.png b/resources/mesh_split_face_interactive.png new file mode 100644 index 000000000..5323e3fe7 Binary files /dev/null and b/resources/mesh_split_face_interactive.png differ diff --git a/src/SMDS/SMDS_ElementFactory.cxx b/src/SMDS/SMDS_ElementFactory.cxx index 611511916..dda4337c0 100644 --- a/src/SMDS/SMDS_ElementFactory.cxx +++ b/src/SMDS/SMDS_ElementFactory.cxx @@ -649,6 +649,13 @@ void SMDS_ElementChunk::SetVTKID( const SMDS_MeshElement* e, const vtkIdType vtk } myFactory->mySmdsIDs[ vtkID ] = e->GetID() - 1; } + else + { + if ((size_t) e->GetID() <= myFactory->myVtkIDs.size() ) + myFactory->myVtkIDs[ e->GetID() - 1 ] = vtkID; + if ((size_t) vtkID < myFactory->mySmdsIDs.size() ) + myFactory->mySmdsIDs[ vtkID ] = e->GetID() - 1; + } } //================================================================================ diff --git a/src/SMESH/SMESH_MeshEditor.cxx b/src/SMESH/SMESH_MeshEditor.cxx index 853d59b3e..0ef9f48c7 100644 --- a/src/SMESH/SMESH_MeshEditor.cxx +++ b/src/SMESH/SMESH_MeshEditor.cxx @@ -412,8 +412,8 @@ SMDS_MeshElement* SMESH_MeshEditor::AddElement(const vector & nodeIDs, // Modify a compute state of sub-meshes which become empty //======================================================================= -smIdType SMESH_MeshEditor::Remove (const list< smIdType >& theIDs, - const bool isNodes ) +smIdType SMESH_MeshEditor::Remove (const std::list< smIdType >& theIDs, + const bool isNodes ) { ClearLastCreated(); @@ -474,10 +474,87 @@ smIdType SMESH_MeshEditor::Remove (const list< smIdType >& theIDs, return removed; } +//================================================================================ +/*! + * \brief Remove a node and fill a hole appeared, by changing surrounding faces + */ +//================================================================================ + +void SMESH_MeshEditor::RemoveNodeWithReconnection( const SMDS_MeshNode* node ) +{ + if ( ! node ) + return; + + if ( node->NbInverseElements( SMDSAbs_Volume ) > 0 ) + throw SALOME_Exception( "RemoveNodeWithReconnection() applies to 2D mesh only" ); + + // check that only triangles surround the node + for ( SMDS_ElemIteratorPtr fIt = node->GetInverseElementIterator( SMDSAbs_Face ); fIt->more(); ) + { + const SMDS_MeshElement* face = fIt->next(); + if ( face->GetGeomType() != SMDSGeom_TRIANGLE ) + throw SALOME_Exception( "RemoveNodeWithReconnection() applies to triangle mesh only" ); + if ( face->IsQuadratic() ) + throw SALOME_Exception( "RemoveNodeWithReconnection() applies to linear mesh only" ); + } + + std::vector< const SMDS_MeshNode*> neighbours(2); + SMESH_MeshAlgos::IsOn2DBoundary( node, & neighbours ); + + bool toRemove = ( neighbours.size() > 2 ); // non-manifold ==> just remove + + // if ( neighbours.size() == 2 ) // on boundary + // { + // // check if theNode and neighbours are on a line + // gp_Pnt pN = SMESH_NodeXYZ( node ); + // gp_Pnt p0 = SMESH_NodeXYZ( neighbours[0] ); + // gp_Pnt p1 = SMESH_NodeXYZ( neighbours[1] ); + // double dist01 = p0.Distance( p1 ); + // double tol = 0.01 * dist01; + // double distN = ( gp_Vec( p0, p1 ) ^ gp_Vec( p0, pN )).Magnitude() / dist01; + // bool onLine = distN < tol; + // toRemove = !onLine; + // } + + if ( neighbours.empty() ) // not on boundary + { + TIDSortedElemSet linkedNodes; + GetLinkedNodes( node, linkedNodes, SMDSAbs_Face ); + for ( const SMDS_MeshElement* e : linkedNodes ) neighbours.push_back( cast2Node( e )); + if ( neighbours.empty() ) + toRemove = true; + } + + if ( toRemove ) + { + this->Remove( std::list< smIdType >( 1, node->GetID() ), /*isNode=*/true ); + return; + } + + // choose a node to replace by + const SMDS_MeshNode* nToReplace = nullptr; + SMESH_NodeXYZ nodeXYZ = node; + double minDist = Precision::Infinite(); + for ( const SMDS_MeshNode* n : neighbours ) + { + double dist = nodeXYZ.SquareDistance( n ); + if ( dist < minDist ) + { + minDist = dist; + nToReplace = n; + } + } + + // remove node + replace by nToReplace + std::list< const SMDS_MeshNode* > nodeGroup = { nToReplace, node }; + TListOfListOfNodes nodesToMerge( 1, nodeGroup ); + this->MergeNodes( nodesToMerge ); +} + //================================================================================ /*! * \brief Create 0D elements on all nodes of the given object. - * \param elements - Elements on whose nodes to create 0D elements; if empty, + * \param elements - Elements on whose nodes to create 0D elements; if empty, * the all mesh is treated * \param all0DElems - returns all 0D elements found or created on nodes of \a elements * \param duplicateElements - to add one more 0D element to a node or not @@ -947,24 +1024,24 @@ bool getQuadrangleNodes(const SMDS_MeshNode * theQuadNodes [], { if( tr1->NbNodes() != tr2->NbNodes() ) return false; + // find the 4-th node to insert into tr1 const SMDS_MeshNode* n4 = 0; SMDS_ElemIteratorPtr it = tr2->nodesIterator(); - int i=0; - while ( !n4 && i<3 ) { + for ( int i = 0; !n4 && i < 3; ++i ) + { const SMDS_MeshNode * n = cast2Node( it->next() ); - i++; bool isDiag = ( n == theNode1 || n == theNode2 ); if ( !isDiag ) n4 = n; } + // Make an array of nodes to be in a quadrangle int iNode = 0, iFirstDiag = -1; it = tr1->nodesIterator(); - i=0; - while ( i<3 ) { + for ( int i = 0; i < 3; ++i ) + { const SMDS_MeshNode * n = cast2Node( it->next() ); - i++; bool isDiag = ( n == theNode1 || n == theNode2 ); if ( isDiag ) { if ( iFirstDiag < 0 ) @@ -1079,6 +1156,210 @@ bool SMESH_MeshEditor::DeleteDiag (const SMDS_MeshNode * theNode1, return true; } +//======================================================================= +//function : SplitEdge +//purpose : Replace each triangle bound by theNode1-theNode2 segment with +// two triangles by connecting a node made on the link with a node opposite to the link. +//======================================================================= + +void SMESH_MeshEditor::SplitEdge (const SMDS_MeshNode * theNode1, + const SMDS_MeshNode * theNode2, + double thePosition) +{ + ClearLastCreated(); + + SMESHDS_Mesh * mesh = GetMeshDS(); + + // Get triangles and segments to divide + + std::vector diagNodes = { theNode1, theNode2 }; + std::vector foundElems; + if ( !mesh->GetElementsByNodes( diagNodes, foundElems ) || foundElems.empty() ) + throw SALOME_Exception( SMESH_Comment("No triangle is bound by the edge ") + << theNode1->GetID() << " - " << theNode2->GetID()); + + SMESH_MesherHelper helper( *GetMesh() ); + + for ( const SMDS_MeshElement * elem : foundElems ) + { + SMDSAbs_ElementType type = elem->GetType(); + switch ( type ) { + case SMDSAbs_Volume: + throw SALOME_Exception( "Can't split an edge of a volume"); + break; + + case SMDSAbs_Face: + if ( elem->GetGeomType() != SMDSGeom_TRIANGLE ) + throw SALOME_Exception( "Can't split an edge of a face of type other than triangle"); + if ( elem->IsQuadratic() ) + { + helper.SetIsQuadratic( true ); + helper.AddTLinks( static_cast< const SMDS_MeshFace*>( elem )); + helper.SetIsBiQuadratic( elem->GetEntityType() == SMDSEntity_BiQuad_Triangle ); + } + break; + + case SMDSAbs_Edge: + if ( elem->IsQuadratic() ) + { + helper.SetIsQuadratic( true ); + helper.AddTLinks( static_cast< const SMDS_MeshEdge*>( elem )); + } + break; + default:; + } + } + + // Make a new node + + const SMDS_MeshNode* nodeOnLink = helper.GetMediumNode( theNode1, theNode2,/*force3d=*/false ); + + gp_Pnt newNodeXYZ = ( SMESH_NodeXYZ( theNode1 ) * ( 1 - thePosition ) + + SMESH_NodeXYZ( theNode2 ) * thePosition ); + + const TopoDS_Shape& S = mesh->IndexToShape( nodeOnLink->GetShapeID() ); + if ( !S.IsNull() && S.ShapeType() == TopAbs_FACE ) // find newNodeXYZ by UV on FACE + { + Handle(ShapeAnalysis_Surface) surface = helper.GetSurface( TopoDS::Face( S )); + double tol = 100 * helper.MaxTolerance( S ); + gp_Pnt2d uv = surface->ValueOfUV( newNodeXYZ, tol ); + if ( surface->Gap() < SMESH_NodeXYZ( theNode1 ).Distance( theNode2 )) + { + newNodeXYZ = surface->Value( uv ); + if ( SMDS_FacePositionPtr nPos = nodeOnLink->GetPosition()) + nPos->SetParameters( uv.X(), uv.Y() ); + } + } + if ( !S.IsNull() && S.ShapeType() == TopAbs_EDGE ) // find newNodeXYZ by param on EDGE + { + mesh->MoveNode( nodeOnLink, newNodeXYZ.X(), newNodeXYZ.Y(), newNodeXYZ.Z() ); + double u = Precision::Infinite(), tol = 100 * helper.MaxTolerance( S ), distXYZ[4]; + helper.ToFixNodeParameters( true ); + if ( helper.CheckNodeU( TopoDS::Edge( S ), nodeOnLink, u, tol, /*force3D=*/false, distXYZ )) + newNodeXYZ.SetCoord( distXYZ[1], distXYZ[2], distXYZ[3] ); + } + mesh->MoveNode( nodeOnLink, newNodeXYZ.X(), newNodeXYZ.Y(), newNodeXYZ.Z() ); + + // Split triangles and segments + + std::vector nodes( 7 ); + for ( const SMDS_MeshElement * elem : foundElems ) + { + nodes.assign( elem->begin_nodes(), elem->end_nodes() ); + nodes.resize( elem->NbCornerNodes() + 1 ); + nodes.back() = nodes[0]; + + smIdType id = elem->GetID(); + int shapeID = elem->GetShapeID(); + + const SMDS_MeshNode* centralNode = nullptr; + if ( elem->GetEntityType() == SMDSEntity_BiQuad_Triangle ) + centralNode = elem->GetNode( 6 ); + + mesh->RemoveFreeElement( elem, /*sm=*/0, /*fromGroups=*/false ); + if ( centralNode ) + mesh->RemoveFreeNode( centralNode, /*sm=*/0, /*fromGroups=*/true ); + + for ( size_t i = 1; i < nodes.size(); ++i ) + { + const SMDS_MeshNode* n1 = nodes[i-1]; + const SMDS_MeshNode* n2 = nodes[i]; + const SMDS_MeshElement* newElem; + if ( nodes.size() == 4 ) // triangle + { + bool isDiag1 = ( n1 == theNode1 || n1 == theNode2 ); + bool isDiag2 = ( n2 == theNode1 || n2 == theNode2 ); + if ( isDiag1 && isDiag2 ) + continue; + + newElem = helper.AddFace( n1, n2, nodeOnLink, id ); + } + else // segment + { + newElem = helper.AddEdge( n1, nodeOnLink, id ); + } + myLastCreatedElems.push_back( newElem ); + AddToSameGroups( newElem, elem, mesh ); + if ( shapeID ) + mesh->SetMeshElementOnShape( newElem, shapeID ); + id = 0; + } + } + return; +} + +//======================================================================= +//function : SplitFace +//purpose : Split a face into triangles each formed by two nodes of the +// face and a new node added at the given coordinates. +//======================================================================= + +void SMESH_MeshEditor::SplitFace (const SMDS_MeshElement * theFace, + double theX, + double theY, + double theZ ) +{ + ClearLastCreated(); + + if ( !theFace ) + throw SALOME_Exception("Null face given"); + if ( theFace->GetType() != SMDSAbs_Face ) + throw SALOME_Exception("Not a face given"); + + SMESHDS_Mesh * mesh = GetMeshDS(); + + SMESH_MesherHelper helper( *GetMesh() ); + if ( theFace->IsQuadratic() ) + { + helper.SetIsQuadratic( true ); + helper.AddTLinks( static_cast< const SMDS_MeshFace*>( theFace )); + } + const TopoDS_Shape& shape = mesh->IndexToShape( theFace->GetShapeID() ); + helper.SetSubShape( shape ); + helper.SetElementsOnShape( true ); + + // Make a new node + + const SMDS_MeshNode* centralNode = nullptr; + if ( theFace->GetEntityType() == SMDSEntity_BiQuad_Triangle ) + centralNode = theFace->GetNode( 6 ); + else if ( theFace->GetEntityType() == SMDSEntity_BiQuad_Quadrangle ) + centralNode = theFace->GetNode( 8 ); + + if ( centralNode ) + { + helper.SetIsBiQuadratic( true ); + mesh->MoveNode( centralNode, theX, theY, theZ ); + } + else + centralNode = helper.AddNode( theX, theY, theZ ); + + + // Split theFace + + std::vector nodes( theFace->NbNodes() + 1 ); + nodes.assign( theFace->begin_nodes(), theFace->end_nodes() ); + nodes.resize( theFace->NbCornerNodes() + 1 ); + nodes.back() = nodes[0]; + + smIdType id = theFace->GetID(); + int shapeID = theFace->GetShapeID(); + + mesh->RemoveFreeElement( theFace, /*sm=*/0, /*fromGroups=*/false ); + + for ( size_t i = 1; i < nodes.size(); ++i ) + { + const SMDS_MeshElement* newElem = helper.AddFace( nodes[i-1], nodes[i], centralNode, id ); + + myLastCreatedElems.push_back( newElem ); + AddToSameGroups( newElem, theFace, mesh ); + if ( shapeID ) + mesh->SetMeshElementOnShape( newElem, shapeID ); + id = 0; + } + return; +} + //======================================================================= //function : Reorient //purpose : Reverse theElement orientation diff --git a/src/SMESH/SMESH_MeshEditor.hxx b/src/SMESH/SMESH_MeshEditor.hxx index 6962f2c2d..5bbc914ed 100644 --- a/src/SMESH/SMESH_MeshEditor.hxx +++ b/src/SMESH/SMESH_MeshEditor.hxx @@ -126,6 +126,10 @@ public: */ SMDS_MeshElement* AddElement(const std::vector & nodeIDs, const ElemFeatures& features); + /*! + * \brief Remove a node and fill a hole appeared by changing surrounding faces + */ + void RemoveNodeWithReconnection( const SMDS_MeshNode* node ); smIdType Remove (const std::list< smIdType >& theElemIDs, const bool isNodes); // Remove a node or an element. @@ -155,6 +159,20 @@ public: // with a quadrangle built on the same 4 nodes. // Return false if proper faces not found + void SplitEdge (const SMDS_MeshNode * theNode1, + const SMDS_MeshNode * theNode2, + double thePosition); + // Replace each triangle bound by theNode1-theNode2 link + // with two triangles by connecting a node made on the link with a node opposite to the link. + + void SplitFace (const SMDS_MeshElement * theFace, + double theX, + double theY, + double theZ ); + // Split a face into triangles each formed by two nodes of the face and a new node added + // at the given coordinates. + + bool Reorient (const SMDS_MeshElement * theElement); // Reverse theElement orientation diff --git a/src/SMESHGUI/CMakeLists.txt b/src/SMESHGUI/CMakeLists.txt index 587ee89bd..36a4fd90c 100644 --- a/src/SMESHGUI/CMakeLists.txt +++ b/src/SMESHGUI/CMakeLists.txt @@ -150,6 +150,9 @@ SET(_moc_HEADERS SMESHGUI_PreVisualObj.h SMESHGUI_MG_ADAPTDRIVER.h SMESHGUI_MgAdaptDlg.h + SMESHGUI_RemoveNodeReconnectionDlg.h + SMESHGUI_AddNodeOnSegmentDlg.h + SMESHGUI_AddNodeOnFaceDlg.h ) # header files / no moc processing @@ -267,6 +270,9 @@ SET(_other_SOURCES SMESHGUI_IdPreview.cxx SMESHGUI_MG_ADAPTDRIVER.cxx SMESHGUI_MgAdaptDlg.cxx + SMESHGUI_RemoveNodeReconnectionDlg.cxx + SMESHGUI_AddNodeOnSegmentDlg.cxx + SMESHGUI_AddNodeOnFaceDlg.cxx ) # sources / to compile diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index d7b4ed744..3213fc555 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -32,6 +32,8 @@ #include "SMESHGUI.h" #include "SMESHGUI_Add0DElemsOnAllNodesDlg.h" #include "SMESHGUI_AddMeshElementDlg.h" +#include "SMESHGUI_AddNodeOnSegmentDlg.h" +#include "SMESHGUI_AddNodeOnFaceDlg.h" #include "SMESHGUI_AddQuadraticElementDlg.h" #include "SMESHGUI_BuildCompoundDlg.h" #include "SMESHGUI_ClippingDlg.h" @@ -78,6 +80,7 @@ #include "SMESHGUI_Preferences_ScalarBarDlg.h" #include "SMESHGUI_PropertiesDlg.h" #include "SMESHGUI_RemoveElementsDlg.h" +#include "SMESHGUI_RemoveNodeReconnectionDlg.h" #include "SMESHGUI_RemoveNodesDlg.h" #include "SMESHGUI_RenumberingDlg.h" #include "SMESHGUI_ReorientFacesDlg.h" @@ -3531,6 +3534,14 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) } break; } + case SMESHOp::OpRemoveNodeWithReconn: + { + if(isStudyLocked()) break; + if ( warnOnGeomModif() ) + break; // action forbidden as geometry modified + startOperation( SMESHOp::OpRemoveNodeWithReconn ); + break; + } case SMESHOp::OpRemoveElements: // REMOVES ELEMENTS { if(isStudyLocked()) break; @@ -3789,6 +3800,24 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) startOperation( SMESHOp::OpMoveNode ); break; + case SMESHOp::OpMoveNodeInteractive: + if ( warnOnGeomModif() ) + break; // action forbidden as geometry modified + startOperation( SMESHOp::OpMoveNodeInteractive ); + break; + + case SMESHOp::OpSplitEdgeInteract: + if ( warnOnGeomModif() ) + break; // action forbidden as geometry modified + startOperation( SMESHOp::OpSplitEdgeInteract ); + break; + + case SMESHOp::OpSplitFaceInteract: + if ( warnOnGeomModif() ) + break; // action forbidden as geometry modified + startOperation( SMESHOp::OpSplitFaceInteract ); + break; + case SMESHOp::OpDuplicateNodes: { if(isStudyLocked()) break; @@ -4196,6 +4225,7 @@ void SMESHGUI::initialize( CAM_Application* app ) createSMESHAction( SMESHOp::OpRemoveNodes, "REMOVE_NODES", "ICON_DLG_REM_NODE" ); createSMESHAction( SMESHOp::OpRemoveElements, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" ); createSMESHAction( SMESHOp::OpRemoveOrphanNodes, "REMOVE_ORPHAN_NODES", "ICON_DLG_REM_ORPHAN_NODES" ); + createSMESHAction( SMESHOp::OpRemoveNodeWithReconn, "REMOVE_NODE_RECON", "ICON_REM_NODE_RECON" ); createSMESHAction( SMESHOp::OpClearMesh, "CLEAR_MESH", "ICON_CLEAR_MESH" ); //createSMESHAction( SMESHOp::OpRenumberingNodes, "RENUM_NODES", "ICON_DLG_RENUMBERING_NODES" ); @@ -4210,6 +4240,9 @@ void SMESHGUI::initialize( CAM_Application* app ) createSMESHAction( SMESHOp::OpMergeNodes, "MERGE", "ICON_SMESH_MERGE_NODES" ); createSMESHAction( SMESHOp::OpMergeElements, "MERGE_ELEMENTS", "ICON_DLG_MERGE_ELEMENTS" ); createSMESHAction( SMESHOp::OpMoveNode, "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" ); + createSMESHAction( SMESHOp::OpMoveNodeInteractive, "MOVE_NODE_INTRCT","ICON_DLG_MOVE_NODE_INTERACTIVE" ); + createSMESHAction( SMESHOp::OpSplitEdgeInteract, "SPLIT_DIAG_INTRC","ICON_SPLIT_DIAG_INTERACTIVE" ); + createSMESHAction( SMESHOp::OpSplitFaceInteract, "SPLIT_FACE_INTRC","ICON_SPLIT_FACE_INTERACTIVE" ); createSMESHAction( SMESHOp::OpDuplicateNodes, "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" ); createSMESHAction( SMESHOp::OpDiagonalInversion, "INV", "ICON_DLG_MESH_DIAGONAL" ); createSMESHAction( SMESHOp::OpUnionOfTwoTriangle, "UNION2", "ICON_UNION2TRI" ); @@ -4444,13 +4477,14 @@ void SMESHGUI::initialize( CAM_Application* app ) createMenu( SMESHOp::OpQuadraticHexahedron, addId, -1 ); createMenu( SMESHOp::OpTriQuadraticHexahedron, addId, -1 ); - createMenu( SMESHOp::OpRemoveNodes, removeId, -1 ); - createMenu( SMESHOp::OpRemoveElements, removeId, -1 ); - createMenu( SMESHOp::OpRemoveOrphanNodes, removeId, -1 ); - createMenu( separator(), removeId, -1 ); - createMenu( SMESHOp::OpDeleteGroup, removeId, -1 ); - createMenu( separator(), removeId, -1 ); - createMenu( SMESHOp::OpClearMesh, removeId, -1 ); + createMenu( SMESHOp::OpRemoveNodes, removeId, -1 ); + createMenu( SMESHOp::OpRemoveElements, removeId, -1 ); + createMenu( SMESHOp::OpRemoveOrphanNodes, removeId, -1 ); + createMenu( SMESHOp::OpRemoveNodeWithReconn, removeId, -1 ); + createMenu( separator(), removeId, -1 ); + createMenu( SMESHOp::OpDeleteGroup, removeId, -1 ); + createMenu( separator(), removeId, -1 ); + createMenu( SMESHOp::OpClearMesh, removeId, -1 ); //createMenu( SMESHOp::OpRenumberingNodes, renumId, -1 ); //createMenu( SMESHOp::OpRenumberingElements, renumId, -1 ); @@ -4479,6 +4513,8 @@ void SMESHGUI::initialize( CAM_Application* app ) createMenu( SMESHOp::OpCuttingOfQuadrangles, modifyId, -1 ); createMenu( SMESHOp::OpSplitVolumes, modifyId, -1 ); createMenu( SMESHOp::OpSplitBiQuadratic, modifyId, -1 ); + createMenu( SMESHOp::OpSplitEdgeInteract, modifyId, -1 ); + createMenu( SMESHOp::OpSplitFaceInteract, modifyId, -1 ); createMenu( SMESHOp::OpSmoothing, modifyId, -1 ); createMenu( SMESHOp::OpPatternMapping, modifyId, -1 ); @@ -4631,6 +4667,12 @@ void SMESHGUI::initialize( CAM_Application* app ) createTool( SMESHOp::OpSmoothing, modifyTb ); createTool( SMESHOp::OpPatternMapping, modifyTb ); + int interactTb = createTool( tr( "TB_INTERACT" ), QString( "SMESHInteractiveToolbar" ) ) ; + createTool( SMESHOp::OpMoveNodeInteractive, interactTb ); + createTool( SMESHOp::OpRemoveNodeWithReconn, interactTb ); + createTool( SMESHOp::OpSplitEdgeInteract, interactTb ); + createTool( SMESHOp::OpSplitFaceInteract, interactTb ); + // Adaptation - begin #ifndef DISABLE_MG_ADAPT int adaptTb = createTool( tr( "TB_ADAPTATION" ), QString( "SMESHAdaptationToolbar" ) ) ; @@ -5990,6 +6032,18 @@ LightApp_Operation* SMESHGUI::createOperation( const int id ) const case SMESHOp::OpMoveNode: // Make mesh pass through point op = new SMESHGUI_MakeNodeAtPointOp(); break; + case SMESHOp::OpMoveNodeInteractive: // Make mesh pass through point / by mouse + op = new SMESHGUI_MakeNodeAtPointOp( 2 ); + break; + case SMESHOp::OpRemoveNodeWithReconn: + op = new SMESHGUI_RemoveNodeReconnectionOp(); + break; + case SMESHOp::OpSplitEdgeInteract: + op = new SMESHGUI_AddNodeOnSegmentOp(); + break; + case SMESHOp::OpSplitFaceInteract: + op = new SMESHGUI_AddNodeOnFaceOp(); + break; case SMESHOp::OpElem0DOnElemNodes: // Create 0D elements on all nodes op = new SMESHGUI_Add0DElemsOnAllNodesOp(); break; diff --git a/src/SMESHGUI/SMESHGUI_AddNodeOnFaceDlg.cxx b/src/SMESHGUI/SMESHGUI_AddNodeOnFaceDlg.cxx new file mode 100644 index 000000000..975c5363c --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_AddNodeOnFaceDlg.cxx @@ -0,0 +1,606 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SMESHGUI_AddNodeOnFaceDlg.cxx +// Author : Edward AGAPOV, Open CASCADE S.A.S. +// +#include "SMESHGUI_AddNodeOnFaceDlg.h" + +#include "SMESHGUI.h" +#include "SMESHGUI_Filter.h" +#include "SMESHGUI_IdValidator.h" +#include "SMESHGUI_MeshEditPreview.h" +#include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_SpinBox.h" +#include "SMESHGUI_VTKUtils.h" + +#include +#include +#include +#include + +// SALOME GUI includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// VTK includes +#include + +// IDL includes +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) +#include CORBA_SERVER_HEADER(SMESH_MeshEditor) + +#define SPACING 6 +#define MARGIN 11 + +//======================================================================= +/*! + * \brief Dialog to publish a sub-shape of the mesh main shape + * by selecting mesh elements + */ +//======================================================================= + +SMESHGUI_AddNodeOnFaceDlg::SMESHGUI_AddNodeOnFaceDlg() + : SMESHGUI_Dialog( 0, false, true ) +{ + setWindowTitle(tr("CAPTION")); + + QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame()); + aDlgLay->setMargin(0); + aDlgLay->setSpacing(SPACING); + myMainFrame = createMainFrame(mainFrame()); + + aDlgLay->addWidget(myMainFrame); + + aDlgLay->setStretchFactor(myMainFrame, 1); +} + +//======================================================================= +// function : createMainFrame() +// purpose : Create frame containing dialog's input fields +//======================================================================= + +QWidget* SMESHGUI_AddNodeOnFaceDlg::createMainFrame (QWidget* theParent) +{ + QWidget* aFrame = new QWidget(theParent); + + SUIT_ResourceMgr* rm = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() ); + QPixmap iconSelect( rm->loadPixmap("SMESH", tr("ICON_SELECT"))); + + // Face to split + + QGroupBox* faceGrp = new QGroupBox(tr("FACE_GROUP"), aFrame); + faceGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + QLabel* idLabel = new QLabel(tr("FACE_ID"), faceGrp); + myIdBtn = new QPushButton(faceGrp); + myIdBtn->setIcon(iconSelect); + myIdBtn->setCheckable(true); + myId = new QLineEdit(faceGrp); + myId->setValidator(new SMESHGUI_IdValidator(this, 1)); + + QGridLayout* faceGrpLayout = new QGridLayout(faceGrp); + faceGrpLayout->setSpacing(SPACING); + faceGrpLayout->setMargin(MARGIN); + + faceGrpLayout->addWidget( idLabel, 0, 0 ); + faceGrpLayout->addWidget( myIdBtn, 0, 1 ); + faceGrpLayout->addWidget( myId, 0, 2 ); + + // Node location + + QGroupBox* xyzGrp = new QGroupBox(tr("XYZ_GROUP"), aFrame); + xyzGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + myDestBtn = new QPushButton(xyzGrp); + myDestBtn->setIcon(iconSelect); + myDestBtn->setCheckable(true); + + QLabel* locationXLabel = new QLabel(tr("SMESH_X"), xyzGrp); + myDestinationX = new SMESHGUI_SpinBox(xyzGrp); + QLabel* locationYLabel = new QLabel(tr("SMESH_Y"), xyzGrp); + myDestinationY = new SMESHGUI_SpinBox(xyzGrp); + QLabel* locationZLabel = new QLabel(tr("SMESH_Z"), xyzGrp); + myDestinationZ = new SMESHGUI_SpinBox(xyzGrp); + + myDestinationX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision"); + myDestinationY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision"); + myDestinationZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision"); + + QGridLayout* aDestLayout = new QGridLayout(xyzGrp); + aDestLayout->setMargin(MARGIN); + aDestLayout->setSpacing(SPACING); + aDestLayout->addWidget(myDestBtn, 0, 0); + aDestLayout->addWidget(locationXLabel, 0, 1); + aDestLayout->addWidget(myDestinationX, 0, 2); + aDestLayout->addWidget(locationYLabel, 0, 3); + aDestLayout->addWidget(myDestinationY, 0, 4); + aDestLayout->addWidget(locationZLabel, 0, 5); + aDestLayout->addWidget(myDestinationZ, 0, 6); + aDestLayout->setColumnStretch(2, 1); + aDestLayout->setColumnStretch(4, 1); + aDestLayout->setColumnStretch(6, 1); + + // Preview + + myPreviewChkBox = new QCheckBox( tr("PREVIEW"), aFrame); + myPreviewChkBox->setChecked( true ); + + QVBoxLayout* aLay = new QVBoxLayout(aFrame); + aLay->addWidget(faceGrp); + aLay->addWidget(xyzGrp); + aLay->addWidget(myPreviewChkBox); + + connect(myDestBtn, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool))); + connect(myIdBtn, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool))); + + myIdBtn->setChecked(true); + + return aFrame; +} + +//================================================================================ +/*! + * \brief SLOT called when any button is toggled + * \param bool - on or off + */ +//================================================================================ + +void SMESHGUI_AddNodeOnFaceDlg::ButtonToggled (bool on) +{ + const QObject* aSender = sender(); + if ( on ) { + if ( aSender == myDestBtn ) // button to set coord by node selection + { + if ( myIdBtn->isEnabled() ) + myIdBtn->setChecked( !on ); + } + else if ( aSender == myIdBtn ) // button to select a node to move + { + myDestBtn->setChecked( !on ); + } + } + emit selTypeChanged(); +} + +//================================================================================ +/*! + * \brief Constructor +*/ +//================================================================================ + +SMESHGUI_AddNodeOnFaceOp::SMESHGUI_AddNodeOnFaceOp() +{ + mySimulation = 0; + mySMESHGUI = 0; + myDlg = new SMESHGUI_AddNodeOnFaceDlg; + myHelpFileName = "add_node_on_face.html"; + + myNoPreview = false; + + // connect signals and slots + connect(myDlg->myDestinationX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview())); + connect(myDlg->myDestinationY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview())); + connect(myDlg->myDestinationZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview())); + connect(myDlg->myId, SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview())); + connect(myDlg->myPreviewChkBox, SIGNAL (toggled(bool)), SLOT(redisplayPreview())); + connect(myDlg, SIGNAL (selTypeChanged() ), SLOT(onSelTypeChange())); + connect(myDlg->myId, SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&))); +} + +//================================================================================ +/*! + * \brief SLOT. Called upon change of selection type + */ +//================================================================================ + +void SMESHGUI_AddNodeOnFaceOp::onSelTypeChange() +{ + if ( myDlg->myIdBtn->isChecked() ) + { + setSelectionMode( FaceSelection ); + } + else if ( myDlg->myDestBtn->isChecked() ) + { + // TODO: activate picking a point on a selected face + } + else + { + setSelectionMode( ActorSelection ); + } +} + +//======================================================================= +// function : startOperation() +// purpose : Init dialog fields, connect signals and slots, show dialog +//======================================================================= + +void SMESHGUI_AddNodeOnFaceOp::startOperation() +{ + myNoPreview = false; + myMeshActor = 0; + + // init simulation with a current View + if ( mySimulation ) delete mySimulation; + mySMESHGUI = getSMESHGUI(); + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ) ); + connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView())); + connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView())); + vtkProperty* aProp = vtkProperty::New(); + aProp->SetRepresentationToWireframe(); + aProp->SetColor(250, 0, 250); + aProp->SetPointSize(5); + aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1); + mySimulation->GetActor()->SetProperty(aProp); + aProp->Delete(); + + SMESHGUI_SelectionOp::startOperation(); + myDlg->myId->setText(""); + myDlg->myDestinationX->SetValue(0); + myDlg->myDestinationY->SetValue(0); + myDlg->myDestinationZ->SetValue(0); + + myDlg->show(); + + onSelectionDone(); // init myMeshActor +} + +//================================================================================ +/*! + * \brief Stops operation + */ +//================================================================================ + +void SMESHGUI_AddNodeOnFaceOp::stopOperation() +{ + myNoPreview = true; + if ( mySimulation ) + { + mySimulation->SetVisibility(false); + delete mySimulation; + mySimulation = 0; + } + if ( myMeshActor ) { + myMeshActor = 0; + } + // SMESH::SetPointRepresentation( false ); + // SMESH::RepaintCurrentView(); + + disconnect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView())); + disconnect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView())); + SMESHGUI_SelectionOp::stopOperation(); +} + +//================================================================================ +/*! + * \brief perform it's intention action: split a face + */ +//================================================================================ + +bool SMESHGUI_AddNodeOnFaceOp::onApply() +{ + if( SMESHGUI::isStudyLocked() ) + return false; + + if ( !myMeshActor ) { + SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), tr("INVALID_MESH") ); + dlg()->show(); + return false; + } + + QString msg; + if ( !isValid( msg ) ) { // node id is invalid + if( !msg.isEmpty() ) + SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), tr("INVALID_ID") ); + dlg()->show(); + return false; + } + + QStringList aParameters; + aParameters << myDlg->myDestinationX->text(); + aParameters << myDlg->myDestinationY->text(); + aParameters << myDlg->myDestinationZ->text(); + + try { + SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO()); + if (aMesh->_is_nil()) { + SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), tr("SMESHG_NO_MESH") ); + return true; + } + SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor(); + if (aMeshEditor->_is_nil()) + return true; + + aMesh->SetParameters( aParameters.join(":").toUtf8().constData() ); + + bool ok; + SMESH::smIdType anId = myDlg->myId->text().toLong( &ok ); + + aMeshEditor->AddNodeOnFace( anId, + myDlg->myDestinationX->GetValue(), + myDlg->myDestinationY->GetValue(), + myDlg->myDestinationZ->GetValue() ); + SALOME_ListIO aList; + selectionMgr()->setSelectedObjects(aList,false); + aList.Append(myMeshActor->getIO()); + selectionMgr()->setSelectedObjects(aList,false); + onSelectionDone(); + SMESH::UpdateView(); + SMESHGUI::Modified(); + } + catch (const SALOME::SALOME_Exception& S_ex) { + SalomeApp_Tools::QtCatchCorbaException(S_ex); + } + catch (...) { + } + + return true; +} + +//================================================================================ +/*! + * \brief Check selected face id validity + */ +//================================================================================ + +bool SMESHGUI_AddNodeOnFaceOp::isValid( QString& msg ) +{ + bool ok = false; + if ( myMeshActor ) + { + SMESH::smIdType id = myDlg->myId->text().toLong(); + if ( id > 0 ) + if (SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) + if ( const SMDS_MeshElement* face = aMesh->FindElement( id )) + { + if ( face->GetType() == SMDSAbs_Face ) + ok = true; + else + msg += tr("NOT_FACE") + "\n"; + } + if ( !ok ) + msg += tr("INVALID_ID") + "\n"; + } + + ok = myDlg->myDestinationX->isValid( msg, !myNoPreview ) && ok; + ok = myDlg->myDestinationY->isValid( msg, !myNoPreview ) && ok; + ok = myDlg->myDestinationZ->isValid( msg, !myNoPreview ) && ok; + + return ok; +} + +//================================================================================ +/*! + * \brief SLOT called when selection changed + */ +//================================================================================ + +void SMESHGUI_AddNodeOnFaceOp::onSelectionDone() +{ + if ( !myDlg->isVisible() || !myDlg->isEnabled() ) + return; + + myNoPreview = true; + QString idStr; + try { + SALOME_ListIO aList; + selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type()); + if (aList.Extent() != 1) + return; + Handle(SALOME_InteractiveObject) anIO = aList.First(); + myMeshActor = SMESH::FindActorByEntry(anIO->getEntry()); + + QString aString; + int nbElems = SMESH::GetNameOfSelectedElements(selector(),anIO, aString); + if (nbElems == 1) + if ( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) + if ( const SMDS_MeshElement* face = aMesh->FindElement( aString.toLong() )) + { + idStr = aString; + // set coordinates to face gravity center + gp_XYZ faceGC( 0,0,0 ); + for ( int i = 0; i < face->NbCornerNodes(); ++i ) + faceGC += SMESH_NodeXYZ( face->GetNode( i )); + faceGC /= face->NbCornerNodes(); + myDlg->myDestinationX->SetValue(faceGC.X()); + myDlg->myDestinationY->SetValue(faceGC.Y()); + myDlg->myDestinationZ->SetValue(faceGC.Z()); + } + } catch (...) { + } + myDlg->myId->setText( idStr ); + + myNoPreview = false; + redisplayPreview(); +} + +//================================================================================ +/*! + * \brief update preview + */ +//================================================================================ + +void SMESHGUI_AddNodeOnFaceOp::redisplayPreview() +{ + if ( myNoPreview ) + return; + myNoPreview = true; + + SMESH::MeshPreviewStruct_var aMeshPreviewStruct; + + if ( myMeshActor && myDlg->myPreviewChkBox->isChecked() ) + { + QString msg; + if ( isValid( msg )) + { + try { + SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO()); + if (!aMesh->_is_nil()) { + SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer(); + if (!aPreviewer->_is_nil()) + { + SUIT_OverrideCursor aWaitCursor; + + SMESH::smIdType anId = myDlg->myId->text().toLong(); + aPreviewer->AddNodeOnFace(anId, + myDlg->myDestinationX->GetValue(), + myDlg->myDestinationY->GetValue(), + myDlg->myDestinationZ->GetValue()); + aMeshPreviewStruct = aPreviewer->GetPreviewData(); + } + } + } + catch (...) { + } + } + } + if (!mySimulation) + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI )); + // display data + if ( & aMeshPreviewStruct.in() ) + { + mySimulation->SetData( aMeshPreviewStruct.in() ); + } + else + { + mySimulation->SetVisibility(false); + } + + myNoPreview = false; +} + +//================================================================================= +/*! + * \brief SLOT called when the viewer opened + */ +//================================================================================= + +void SMESHGUI_AddNodeOnFaceOp::onOpenView() +{ + if ( mySimulation ) { + mySimulation->SetVisibility(false); + SMESH::SetPointRepresentation(false); + } + else { + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI )); + } +} + +//================================================================================= +/*! + * \brief SLOT called when the viewer closed + */ +//================================================================================= + +void SMESHGUI_AddNodeOnFaceOp::onCloseView() +{ + delete mySimulation; + mySimulation = 0; +} + +//================================================================================ +/*! + * \brief SLOT called when the face id is manually changed + */ +//================================================================================ + +void SMESHGUI_AddNodeOnFaceOp::onTextChange( const QString& theText ) +{ + if( myMeshActor ) + { + if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() ) + { + Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO(); + SALOME_ListIO aList; + aList.Append( anIO ); + selectionMgr()->setSelectedObjects( aList, false ); + + if( const SMDS_MeshElement* face = aMesh->FindElement( theText.toLong() ) ) + { + SVTK_TVtkIDsMap aListInd; + aListInd.Add( FromSmIdType( face->GetID()) ); + selector()->AddOrRemoveIndex( anIO, aListInd, false ); + if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) ) + aViewWindow->highlight( anIO, true, true ); + } + } + } +} + +//================================================================================ +/*! + * \brief Activate selection + */ +//================================================================================ + +void SMESHGUI_AddNodeOnFaceOp::activateSelection() +{ + selectionMgr()->clearFilters(); + SMESH::SetPointRepresentation( false ); + onSelTypeChange(); +} + +//================================================================================ +/*! + * \brief Destructor +*/ +//================================================================================ + +SMESHGUI_AddNodeOnFaceOp::~SMESHGUI_AddNodeOnFaceOp() +{ + if ( myDlg ) delete myDlg; + if ( mySimulation ) delete mySimulation; +} + +//================================================================================ +/*! + * \brief Gets dialog of this operation + * \retval LightApp_Dialog* - pointer to dialog of this operation + */ +//================================================================================ + +LightApp_Dialog* SMESHGUI_AddNodeOnFaceOp::dlg() const +{ + return myDlg; +} + diff --git a/src/SMESHGUI/SMESHGUI_AddNodeOnFaceDlg.h b/src/SMESHGUI/SMESHGUI_AddNodeOnFaceDlg.h new file mode 100644 index 000000000..7dc88647a --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_AddNodeOnFaceDlg.h @@ -0,0 +1,128 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SMESHGUI_AddNodeOnFaceDlg.h +// Author : Edward AGAPOV, Open CASCADE S.A.S. +// +#ifndef SMESHGUI_AddNodeOnFaceDLG_H +#define SMESHGUI_AddNodeOnFaceDLG_H + +// SMESH includes +#include "SMESH_SMESHGUI.hxx" + +#include "SMESHGUI_Dialog.h" +#include "SMESHGUI_SelectionOp.h" + +class QButtonGroup; +class QCheckBox; +class QGroupBox; +class QLineEdit; +class QPushButton; +class QRadioButton; +class SMESHGUI_SpinBox; +class SMESHGUI_MeshEditPreview; +class SMESHGUI_AddNodeOnFaceDlg; + +/*! + * \brief Operation to split a face into triangles by creating a new node + * on the face and connecting it to the face nodes + */ +class SMESHGUI_EXPORT SMESHGUI_AddNodeOnFaceOp: public SMESHGUI_SelectionOp +{ + Q_OBJECT + +public: + SMESHGUI_AddNodeOnFaceOp(); + virtual ~SMESHGUI_AddNodeOnFaceOp(); + + virtual LightApp_Dialog* dlg() const; + +protected: + + virtual void startOperation(); + virtual void stopOperation(); + + virtual void activateSelection(); + + bool isValid( QString& ); + +protected slots: + virtual bool onApply(); + +private slots: + void onSelectionDone(); + void redisplayPreview(); + void onSelTypeChange(); + void onTextChange( const QString& ); + void onDestCoordChanged(); + void onOpenView(); + void onCloseView(); + +private: + SMESHGUI_AddNodeOnFaceDlg* myDlg; + + SUIT_SelectionFilter* myFilter; + SMESHGUI* mySMESHGUI; + SMESHGUI_MeshEditPreview* mySimulation; + SMESH_Actor* myMeshActor; + bool myNoPreview; + bool myUpdateDestination; + bool myDestCoordChanged; +}; + +/*! + * \brief Dialog to split a face into triangles by creating a new node + * on the face and connecting it to the face nodes + */ + +class SMESHGUI_EXPORT SMESHGUI_AddNodeOnFaceDlg : public SMESHGUI_Dialog +{ + Q_OBJECT + +public: + SMESHGUI_AddNodeOnFaceDlg(); + +private: + QWidget* createMainFrame( QWidget* ); + + QWidget* myMainFrame; + + QPushButton* myDestBtn; + QPushButton* myIdBtn; + QLineEdit* myId; + SMESHGUI_SpinBox* myDestinationX; + SMESHGUI_SpinBox* myDestinationY; + SMESHGUI_SpinBox* myDestinationZ; + QCheckBox* myPreviewChkBox; + + QString myHelpFileName; + + friend class SMESHGUI_AddNodeOnFaceOp; + +signals: + void selTypeChanged(); + + private slots: + void ButtonToggled( bool ); +}; + +#endif // SMESHGUI_AddNodeOnFaceDLG_H diff --git a/src/SMESHGUI/SMESHGUI_AddNodeOnSegmentDlg.cxx b/src/SMESHGUI/SMESHGUI_AddNodeOnSegmentDlg.cxx new file mode 100644 index 000000000..81aac2703 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_AddNodeOnSegmentDlg.cxx @@ -0,0 +1,605 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SMESHGUI_AddNodeOnSegmentDlg.cxx +// Author : Edward AGAPOV, Open CASCADE S.A.S. +// +#include "SMESHGUI_AddNodeOnSegmentDlg.h" + +#include "SMESHGUI.h" +#include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_VTKUtils.h" +#include "SMESHGUI_SpinBox.h" +#include "SMESHGUI_MeshEditPreview.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// VTK includes +#include + +// IDL includes +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) +#include CORBA_SERVER_HEADER(SMESH_MeshEditor) + +#define SPACING 6 +#define MARGIN 11 + +//======================================================================= +/*! + * \brief Dialog to split a diagonal of a quadrangle formed by two adjacent triangles + */ +//======================================================================= + +SMESHGUI_AddNodeOnSegmentDlg::SMESHGUI_AddNodeOnSegmentDlg() +: SMESHGUI_Dialog( 0, false, true ) +{ + setWindowTitle(tr("CAPTION")); + + QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame()); + aDlgLay->setMargin(0); + aDlgLay->setSpacing(SPACING); + QWidget* mainFr = createMainFrame(mainFrame()); + + aDlgLay->addWidget( mainFr ); + + aDlgLay->setStretchFactor( mainFr, 1); +} + +//======================================================================= +// function : createMainFrame() +// purpose : Create frame containing dialog's input fields +//======================================================================= + +QWidget* SMESHGUI_AddNodeOnSegmentDlg::createMainFrame (QWidget* theParent) +{ + QWidget* aFrame = new QWidget(theParent); + + SUIT_ResourceMgr* rm = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() ); + QPixmap iconSelect( rm->loadPixmap("SMESH", tr("ICON_SELECT"))); + + // Segment + + QGroupBox* segmentGrp = new QGroupBox(tr("SEGMENT_GROUP"), aFrame); + segmentGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + QLabel* segmentLabel = new QLabel(tr("SEGMENT"), segmentGrp); + mySegmentBtn = new QPushButton(segmentGrp); + mySegmentBtn->setIcon(iconSelect); + mySegmentBtn->setCheckable(true); + mySegment = new QLineEdit(segmentGrp); + mySegment->setValidator(new QRegExpValidator(QRegExp("[\\d]*-[\\d]*"), this)); + + QGridLayout* segmentGrpLayout = new QGridLayout(segmentGrp); + segmentGrpLayout->setSpacing(SPACING); + segmentGrpLayout->setMargin(MARGIN); + + segmentGrpLayout->addWidget( segmentLabel, 0, 0 ); + segmentGrpLayout->addWidget( mySegmentBtn, 0, 1 ); + segmentGrpLayout->addWidget( mySegment, 0, 2 ); + + // Position on segment + + QGroupBox* positionGrp = new QGroupBox(tr("POSITION_GROUP"), aFrame); + positionGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + myPositionBtn = new QPushButton(positionGrp); + myPositionBtn->setIcon(iconSelect); + myPositionBtn->setCheckable(true); + + QLabel* positionLbl = new QLabel(tr("POSITION"), positionGrp); + + myPositionSpin = new SMESHGUI_SpinBox(positionGrp); + myPositionSpin->setReadOnly(false); + const double tol = 1e-3; + myPositionSpin->RangeStepAndValidator( tol, 1-tol, 0.1, "length_precision"); + + QGridLayout* positionLayout = new QGridLayout(positionGrp); + positionLayout->setMargin(MARGIN); + positionLayout->setSpacing(SPACING); + positionLayout->addWidget(positionLbl, 0, 0); + positionLayout->addWidget(myPositionBtn, 0, 1); + positionLayout->addWidget(myPositionSpin, 0, 2); + positionLayout->setColumnStretch(2, 1); + + // Preview + + myPreviewChkBox = new QCheckBox( tr("PREVIEW"), aFrame); + myPreviewChkBox->setChecked( true ); + + QVBoxLayout* aLay = new QVBoxLayout(aFrame); + aLay->addWidget(segmentGrp); + aLay->addWidget(positionGrp); + aLay->addWidget(myPreviewChkBox); + + connect(myPositionBtn, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool))); + connect(mySegmentBtn, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool))); + + mySegmentBtn->setChecked(true); + + return aFrame; +} + +//================================================================================ +/*! + * \brief SLOT called when any button is toggled + * \param bool - on or off + */ +//================================================================================ + +void SMESHGUI_AddNodeOnSegmentDlg::ButtonToggled (bool on) +{ + const QObject* aSender = sender(); + if ( on ) { + if ( aSender == myPositionBtn ) + { + mySegmentBtn->setChecked( !on ); + } + else if ( aSender == mySegmentBtn ) + { + myPositionBtn->setChecked( !on ); + } + } + emit selTypeChanged(); +} + +//================================================================================ +/*! + * \brief Constructor + */ +//================================================================================ + +SMESHGUI_AddNodeOnSegmentOp::SMESHGUI_AddNodeOnSegmentOp() +{ + mySimulation = 0; + mySMESHGUI = 0; + myDlg = new SMESHGUI_AddNodeOnSegmentDlg; + myHelpFileName = "add_node_on_segment.html"; + + myNoPreview = false; + + // connect signals and slots + connect(myDlg->myPreviewChkBox, SIGNAL (toggled(bool)), SLOT(redisplayPreview())); + connect(myDlg->myPositionSpin, SIGNAL (valueChanged(double)), SLOT(redisplayPreview())); + connect(myDlg->myPositionSpin, SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview())); + connect(myDlg, SIGNAL (selTypeChanged() ), SLOT(onSelTypeChange())); + connect(myDlg->mySegment, SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&))); +} + +//================================================================================ +/*! + * \brief SLOT. Called upon change of selection type + */ +//================================================================================ + +void SMESHGUI_AddNodeOnSegmentOp::onSelTypeChange() +{ + if ( myDlg->mySegmentBtn->isChecked() ) + { + setSelectionMode( EdgeOfCellSelection ); + } + else if ( myDlg->myPositionBtn->isChecked() ) + { + // TODO: activate picking a point on a selected segment + } + else + { + setSelectionMode( ActorSelection ); + } +} + +//======================================================================= +// function : startOperation() +// purpose : Init dialog fields, connect signals and slots, show dialog +//======================================================================= + +void SMESHGUI_AddNodeOnSegmentOp::startOperation() +{ + myNoPreview = false; + myMeshActor = 0; + + // init simulation with a current View + if ( mySimulation ) delete mySimulation; + mySMESHGUI = getSMESHGUI(); + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ) ); + connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView())); + connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView())); + vtkProperty* aProp = vtkProperty::New(); + aProp->SetRepresentationToWireframe(); + aProp->SetColor(250, 0, 250); + aProp->SetPointSize(5); + aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1); + mySimulation->GetActor()->SetProperty(aProp); + aProp->Delete(); + + SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation + myDlg->mySegment->setText(""); + myDlg->myPositionSpin->SetValue(0.5); + myDlg->myPositionSpin->setReadOnly(false); + + myDlg->show(); + + onSelectionDone(); // init myMeshActor +} + +//================================================================================ +/*! + * \brief Stops operation + */ +//================================================================================ + +void SMESHGUI_AddNodeOnSegmentOp::stopOperation() +{ + myNoPreview = true; + if ( mySimulation ) + { + mySimulation->SetVisibility(false); + delete mySimulation; + mySimulation = 0; + } + if ( myMeshActor ) { + myMeshActor = 0; + } + SMESH::SetPointRepresentation( false ); + SMESH::RepaintCurrentView(); + + disconnect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView())); + disconnect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView())); + //selectionMgr()->removeFilter( myFilter ); + SMESHGUI_SelectionOp::stopOperation(); +} + +//================================================================================ +/*! + * \brief perform it's intention action: move or create a node + */ +//================================================================================ + +bool SMESHGUI_AddNodeOnSegmentOp::onApply() +{ + if( SMESHGUI::isStudyLocked() ) + return false; + + QString msg; + SMESH::smIdType node1= 0, node2 = 0; + if ( !isValid( msg, node1, node2 )) + { + SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), + msg.isEmpty() ? tr("INVALID_ID") : msg ); + dlg()->show(); + return false; + } + + QStringList aParameters; + aParameters << myDlg->myPositionSpin->text(); + + try { + SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( myMeshActor->getIO() ); + if (aMesh->_is_nil()) { + SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), tr("INVALID_MESH") ); + return true; + } + SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor(); + if (aMeshEditor->_is_nil()) + return true; + + aMesh->SetParameters( aParameters.join(":").toUtf8().constData() ); + + aMeshEditor->AddNodeOnSegment( node1, node2, myDlg->myPositionSpin->GetValue() ); + + selector()->ClearIndex(); + selector()->ClearCompositeIndex(); + SALOME_ListIO aList; + aList.Append( myMeshActor->getIO() ); + selectionMgr()->setSelectedObjects(aList,false); + onSelectionDone(); + SMESH::UpdateView(); + SMESHGUI::Modified(); + } + catch (const SALOME::SALOME_Exception& S_ex) { + SalomeApp_Tools::QtCatchCorbaException(S_ex); + } + catch (...) { + } + + return true; +} + +//================================================================================ +/*! + * \brief Check selected node id validity + */ +//================================================================================ + +bool SMESHGUI_AddNodeOnSegmentOp::isValid( QString& msg, + SMESH::smIdType & node1, + SMESH::smIdType & node2 ) +{ + bool ok = false; + if ( !myMeshActor ) + { + msg = tr("INVALID_MESH"); + } + else + { + if ( SMDS_Mesh* mesh = myMeshActor->GetObject()->GetMesh() ) + { + QString txt = myDlg->mySegment->text(); + if ( txt.contains('-')) + { + QString str1 = txt.section('-', 0, 0, QString::SectionSkipEmpty); + QString str2 = txt.section('-', 1, 1, QString::SectionSkipEmpty); + node1 = str1.toLong(); + node2 = str2.toLong(); + const SMDS_MeshNode* n1 = mesh->FindNode( node1 ); + const SMDS_MeshNode* n2 = mesh->FindNode( node2 ); + std::vector nodes = { n1, n2 }; + std::vector foundElems; + if ( !mesh->GetElementsByNodes( nodes, foundElems )) + msg = tr("NO_ELEMENTS"); + else + { + for ( const SMDS_MeshElement * elem : foundElems ) + { + if ( elem->GetGeomType() == SMDSGeom_TRIANGLE ) + ok = true; + else + { + if ( elem->GetType() == SMDSAbs_Volume ) + msg = tr("VOLUME_FOUND"); + if ( elem->GetType() == SMDSAbs_Face ) + msg = tr("NOT_TRIANGLE_FACE_FOUND"); + } + } + if ( !msg.isEmpty() ) + ok = false; + } + } + } + } + if ( !ok && msg.isEmpty() ) + { + node1 = node2 = 0; + msg += tr("INVALID_EDGE") + "\n"; + } + + if ( ok && ! myDlg->myPositionSpin->isValid( msg, /*toCorrect=*/false )) + { + msg = tr("BAD_POSITION"); + ok = false; + } + + return ok; +} + +//================================================================================ +/*! + * \brief SLOT called when selection changed + */ +//================================================================================ + +void SMESHGUI_AddNodeOnSegmentOp::onSelectionDone() +{ + if ( !myDlg->isVisible() || !myDlg->isEnabled() ) + return; + + myNoPreview = true; + QString segmentStr; + try { + SALOME_ListIO aList; + selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type()); + if (aList.Extent() != 1) + return; + Handle(SALOME_InteractiveObject) anIO = aList.First(); + if (( myMeshActor = SMESH::FindActorByEntry(anIO->getEntry()) )) + { + SVTK_IndexedMapOfVtkIds IDs; + selector()->GetCompositeIndex( anIO, IDs ); + if ( IDs.Extent() == 1 && IDs(1).size() == 2 ) + { + SMESH::smIdType id1 = IDs(1)[0]; + SMESH::smIdType id2 = IDs(1)[1]; + segmentStr = QString("%1-%2").arg( id1 ).arg( id2 ); + } + } + } catch (...) { + } + myDlg->mySegment->setText( segmentStr ); + + myNoPreview = false; + redisplayPreview(); +} + +//================================================================================ +/*! + * \brief update preview + */ +//================================================================================ + +void SMESHGUI_AddNodeOnSegmentOp::redisplayPreview() +{ + if ( myNoPreview || !myDlg->myPreviewChkBox->isChecked() ) + { + if ( mySimulation ) + mySimulation->SetVisibility(false); + return; + } + myNoPreview = true; + + SMESH::MeshPreviewStruct_var aMeshPreviewStruct; + + QString msg; + SMESH::smIdType node1, node2; + try { + if ( isValid( msg, node1, node2 )) + { + SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO()); + if ( !aMesh->_is_nil() ) + { + SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer(); + if ( !aPreviewer->_is_nil() ) + { + SUIT_OverrideCursor aWaitCursor; + double pos = myDlg->myPositionSpin->value(); + aPreviewer->AddNodeOnSegment( node1, node2, pos ); + + aMeshPreviewStruct = aPreviewer->GetPreviewData(); + } + } + } + } + catch (...) { + } + + if (!mySimulation) + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI )); + // display data + if ( & aMeshPreviewStruct.in() ) + { + mySimulation->SetData( aMeshPreviewStruct.in() ); + } + else + { + mySimulation->SetVisibility(false); + } + + myNoPreview = false; +} + +//================================================================================= +/*! + * \brief SLOT called when the viewer opened + */ +//================================================================================= + +void SMESHGUI_AddNodeOnSegmentOp::onOpenView() +{ + if ( mySimulation ) { + mySimulation->SetVisibility(false); + SMESH::SetPointRepresentation(false); + } + else { + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI )); + } +} + +//================================================================================= +/*! + * \brief SLOT called when the viewer closed + */ +//================================================================================= + +void SMESHGUI_AddNodeOnSegmentOp::onCloseView() +{ + delete mySimulation; + mySimulation = 0; +} + +//================================================================================ +/*! + * \brief SLOT called when the node ids are manually changed + */ +//================================================================================ + +void SMESHGUI_AddNodeOnSegmentOp::onTextChange( const QString& /*theText*/ ) +{ + QString msg; + SMESH::smIdType node1= 0, node2 = 0; + + if (( isValid( msg, node1, node2 )) || + ( node1 && node2 )) // position only can be invalid + { + // highlight entered segment + + Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO(); + SALOME_ListIO aList; + aList.Append( anIO ); + selectionMgr()->setSelectedObjects( aList, false ); + + SVTK_ListOfVtk newIndices = { node1, node2 }; + selector()->AddOrRemoveCompositeIndex( anIO, newIndices, false ); + SMESH::GetViewWindow(mySMESHGUI)->highlight( anIO, true, true ); + } +} + +//================================================================================ +/*! + * \brief Activate Node selection + */ +//================================================================================ + +void SMESHGUI_AddNodeOnSegmentOp::activateSelection() +{ + selectionMgr()->clearFilters(); + SMESH::SetPointRepresentation( false ); + onSelTypeChange(); +} + +//================================================================================ +/*! + * \brief Destructor + */ +//================================================================================ + +SMESHGUI_AddNodeOnSegmentOp::~SMESHGUI_AddNodeOnSegmentOp() +{ + if ( myDlg ) delete myDlg; + if ( mySimulation ) delete mySimulation; +} + +//================================================================================ +/*! + * \brief Gets dialog of this operation + * \retval LightApp_Dialog* - pointer to dialog of this operation + */ +//================================================================================ + +LightApp_Dialog* SMESHGUI_AddNodeOnSegmentOp::dlg() const +{ + return myDlg; +} + diff --git a/src/SMESHGUI/SMESHGUI_AddNodeOnSegmentDlg.h b/src/SMESHGUI/SMESHGUI_AddNodeOnSegmentDlg.h new file mode 100644 index 000000000..7c9caaca8 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_AddNodeOnSegmentDlg.h @@ -0,0 +1,119 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SMESHGUI_AddNodeOnSegmentDlg.h +// Author : Edward AGAPOV, Open CASCADE S.A.S. +// +#ifndef SMESHGUI_AddNodeOnSegmentDLG_H +#define SMESHGUI_AddNodeOnSegmentDLG_H + +#include "SMESHGUI_Dialog.h" +#include "SMESHGUI_SelectionOp.h" + +class QButtonGroup; +class QCheckBox; +class QGroupBox; +class QLineEdit; +class QPushButton; +class QRadioButton; +class SMESHGUI_SpinBox; +class SMESHGUI_MeshEditPreview; +class SMESHGUI_AddNodeOnSegmentDlg; + +/*! + * \brief Operation to make a mesh pass through a point + */ +class SMESHGUI_EXPORT SMESHGUI_AddNodeOnSegmentOp: public SMESHGUI_SelectionOp +{ + Q_OBJECT + +public: + SMESHGUI_AddNodeOnSegmentOp(); + virtual ~SMESHGUI_AddNodeOnSegmentOp(); + + virtual LightApp_Dialog* dlg() const; + +protected: + + virtual void startOperation(); + virtual void stopOperation(); + + virtual void activateSelection(); + + bool isValid( QString&, SMESH::smIdType& n1, SMESH::smIdType& n2 ); + +protected slots: + virtual bool onApply(); + +private slots: + void onSelectionDone(); + void redisplayPreview(); + void onTextChange( const QString& ); + void onPositionClick(); + void onPositionChanged(); + void onSelTypeChange(); + void onOpenView(); + void onCloseView(); + +private: + + SMESHGUI_AddNodeOnSegmentDlg* myDlg; + + SMESHGUI* mySMESHGUI; + SMESHGUI_MeshEditPreview* mySimulation; + SMESH_Actor* myMeshActor; + bool myNoPreview; +}; + +/*! + * \brief Dialog to make a mesh pass through a point + */ + +class SMESHGUI_EXPORT SMESHGUI_AddNodeOnSegmentDlg : public SMESHGUI_Dialog +{ + Q_OBJECT + +public: + SMESHGUI_AddNodeOnSegmentDlg(); + +signals: + + void selTypeChanged(); + +private: + QWidget* createMainFrame( QWidget* ); + + QPushButton* mySegmentBtn; + QLineEdit* mySegment; + QPushButton* myPositionBtn; + SMESHGUI_SpinBox* myPositionSpin; + QCheckBox* myPreviewChkBox; + + QString myHelpFileName; + + friend class SMESHGUI_AddNodeOnSegmentOp; + +private slots: + void ButtonToggled( bool ); +}; + +#endif // SMESHGUI_AddNodeOnSegmentDLG_H diff --git a/src/SMESHGUI/SMESHGUI_MakeNodeAtPointDlg.cxx b/src/SMESHGUI/SMESHGUI_MakeNodeAtPointDlg.cxx index 6b1b7c140..5745d8483 100644 --- a/src/SMESHGUI/SMESHGUI_MakeNodeAtPointDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MakeNodeAtPointDlg.cxx @@ -86,13 +86,16 @@ namespace { - enum { MANUAL_MODE = 0, SEARCH_MODE }; // how a node to move is specified + enum { MANUAL_MODE = 0, SEARCH_MODE, INTERACTIVE_MODE }; } +//======================================================================= /*! * \brief Dialog to publish a sub-shape of the mesh main shape * by selecting mesh elements */ +//======================================================================= + SMESHGUI_MakeNodeAtPointDlg::SMESHGUI_MakeNodeAtPointDlg() : SMESHGUI_Dialog( 0, false, true ) { @@ -112,6 +115,7 @@ SMESHGUI_MakeNodeAtPointDlg::SMESHGUI_MakeNodeAtPointDlg() // function : createMainFrame() // purpose : Create frame containing dialog's input fields //======================================================================= + QWidget* SMESHGUI_MakeNodeAtPointDlg::createMainFrame (QWidget* theParent) { QWidget* aFrame = new QWidget(theParent); @@ -119,6 +123,7 @@ QWidget* SMESHGUI_MakeNodeAtPointDlg::createMainFrame (QWidget* theParent) SUIT_ResourceMgr* rm = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() ); QPixmap iconMoveNode (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE"))); QPixmap iconMoveWithoutNode (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_WITHOUT_NODE"))); + QPixmap iconMoveInteractive (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE_INTERACTIVE"))); QPixmap iconSelect (rm->loadPixmap("SMESH", tr("ICON_SELECT"))); // constructor @@ -129,16 +134,20 @@ QWidget* SMESHGUI_MakeNodeAtPointDlg::createMainFrame (QWidget* theParent) aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING); - myRButNodeToMove = new QRadioButton(aPixGrp); + myRButNodeToMove = new QRadioButton(aPixGrp); myRButMoveWithoutNode = new QRadioButton(aPixGrp); + myRButMoveInteractive = new QRadioButton(aPixGrp); myRButNodeToMove->setIcon(iconMoveNode); myRButMoveWithoutNode->setIcon(iconMoveWithoutNode); + myRButMoveInteractive->setIcon(iconMoveInteractive); myRButNodeToMove->setChecked(true); aPixGrpLayout->addWidget(myRButNodeToMove); aPixGrpLayout->addWidget(myRButMoveWithoutNode); - myButtonGroup->addButton(myRButNodeToMove, 0); + aPixGrpLayout->addWidget(myRButMoveInteractive); + myButtonGroup->addButton(myRButNodeToMove, 0); myButtonGroup->addButton(myRButMoveWithoutNode, 1); + myButtonGroup->addButton(myRButMoveInteractive, 2); // Node to move @@ -302,11 +311,15 @@ void SMESHGUI_MakeNodeAtPointDlg::ButtonToggled (bool on) * \param int - number of the button */ //================================================================================ + void SMESHGUI_MakeNodeAtPointDlg::ConstructorsClicked (int constructorId) { switch (constructorId) { - case 0: + case MANUAL_MODE: + case INTERACTIVE_MODE: { + myUpdateBtn->setVisible( constructorId == MANUAL_MODE ); + myDestinationGrp->setTitle( tr( constructorId == MANUAL_MODE ? "DESTINATION" : "DESTINATION_BY_MOUSE")); myDestDXLabel->show(); myDestDYLabel->show(); myDestDZLabel->show(); @@ -319,7 +332,7 @@ void SMESHGUI_MakeNodeAtPointDlg::ConstructorsClicked (int constructorId) if (!myNodeToMoveGrp->isVisible()) myNodeToMoveGrp->show(); break; } - case 1: + case SEARCH_MODE: { myId->setText(""); myCurrentX->SetValue(0); @@ -336,6 +349,7 @@ void SMESHGUI_MakeNodeAtPointDlg::ConstructorsClicked (int constructorId) break; } } + QApplication::instance()->processEvents(); myMainFrame->hide(); myMainFrame->show(); @@ -349,8 +363,9 @@ void SMESHGUI_MakeNodeAtPointDlg::ConstructorsClicked (int constructorId) */ //================================================================================ -SMESHGUI_MakeNodeAtPointOp::SMESHGUI_MakeNodeAtPointOp() +SMESHGUI_MakeNodeAtPointOp::SMESHGUI_MakeNodeAtPointOp(int defaultConstructor) { + myDefaultConstructor = defaultConstructor; mySimulation = 0; mySMESHGUI = 0; myDlg = new SMESHGUI_MakeNodeAtPointDlg; @@ -378,6 +393,12 @@ SMESHGUI_MakeNodeAtPointOp::SMESHGUI_MakeNodeAtPointOp() connect(myDlg->myUpdateBtn, SIGNAL (clicked()), this, SLOT(onUpdateDestination())); } +//================================================================================ +/*! + * \brief SLOT. Update preview upon [Update destination] clicked + */ +//================================================================================ + void SMESHGUI_MakeNodeAtPointOp::onUpdateDestination() { myUpdateDestination = true; @@ -385,6 +406,12 @@ void SMESHGUI_MakeNodeAtPointOp::onUpdateDestination() myUpdateDestination = false; } +//================================================================================ +/*! + * \brief SLOT. Update preview upon Destination coordinates change + */ +//================================================================================ + void SMESHGUI_MakeNodeAtPointOp::onDestCoordChanged() { myDestCoordChanged = false; @@ -396,6 +423,7 @@ void SMESHGUI_MakeNodeAtPointOp::onDestCoordChanged() // function : startOperation() // purpose : Init dialog fields, connect signals and slots, show dialog //======================================================================= + void SMESHGUI_MakeNodeAtPointOp::startOperation() { myNoPreview = false; @@ -442,6 +470,8 @@ void SMESHGUI_MakeNodeAtPointOp::startOperation() myDlg->myDestDZ->setReadOnly(true); myDlg->myRButNodeToMove->setChecked(true); + if ( myDefaultConstructor == INTERACTIVE_MODE ) + myDlg->myButtonGroup->button( INTERACTIVE_MODE )->setChecked(true); myDlg->ConstructorsClicked( GetConstructorId() ); myDlg->show(); @@ -453,6 +483,7 @@ void SMESHGUI_MakeNodeAtPointOp::startOperation() // function : GetConstructorId() // purpose : //================================================================================= + int SMESHGUI_MakeNodeAtPointOp::GetConstructorId() { return myDlg->myButtonGroup->checkedId(); @@ -828,6 +859,7 @@ void SMESHGUI_MakeNodeAtPointOp::redisplayPreview() * \brief SLOT called when the viewer opened */ //================================================================================= + void SMESHGUI_MakeNodeAtPointOp::onOpenView() { if ( mySimulation ) { @@ -844,6 +876,7 @@ void SMESHGUI_MakeNodeAtPointOp::onOpenView() * \brief SLOT called when the viewer closed */ //================================================================================= + void SMESHGUI_MakeNodeAtPointOp::onCloseView() { delete mySimulation; diff --git a/src/SMESHGUI/SMESHGUI_MakeNodeAtPointDlg.h b/src/SMESHGUI/SMESHGUI_MakeNodeAtPointDlg.h index d1d0f09ba..32cb9f0c1 100644 --- a/src/SMESHGUI/SMESHGUI_MakeNodeAtPointDlg.h +++ b/src/SMESHGUI/SMESHGUI_MakeNodeAtPointDlg.h @@ -50,7 +50,7 @@ class SMESHGUI_EXPORT SMESHGUI_MakeNodeAtPointOp: public SMESHGUI_SelectionOp Q_OBJECT public: - SMESHGUI_MakeNodeAtPointOp(); + SMESHGUI_MakeNodeAtPointOp(int defaultConstructor = 0); virtual ~SMESHGUI_MakeNodeAtPointOp(); virtual LightApp_Dialog* dlg() const; @@ -79,10 +79,10 @@ private slots: private: int GetConstructorId(); + int myDefaultConstructor; SMESHGUI_MakeNodeAtPointDlg* myDlg; SUIT_SelectionFilter* myFilter; - int myMeshOldDisplayMode; SMESHGUI* mySMESHGUI; SMESHGUI_MeshEditPreview* mySimulation; SMESH_Actor* myMeshActor; @@ -110,6 +110,7 @@ private: QButtonGroup* myButtonGroup; QRadioButton* myRButNodeToMove; QRadioButton* myRButMoveWithoutNode; + QRadioButton* myRButMoveInteractive; QPushButton* myDestBtn; QPushButton* myUpdateBtn; QGroupBox* myDestinationGrp; diff --git a/src/SMESHGUI/SMESHGUI_Operations.h b/src/SMESHGUI/SMESHGUI_Operations.h index e24bcd558..5862c4e5e 100644 --- a/src/SMESHGUI/SMESHGUI_Operations.h +++ b/src/SMESHGUI/SMESHGUI_Operations.h @@ -153,6 +153,7 @@ namespace SMESHOp { OpRemoveNodes = 4200, // MENU MODIFICATION - REMOVE - NODE OpRemoveElements = 4201, // MENU MODIFICATION - REMOVE - ELEMENTS OpRemoveOrphanNodes = 4202, // MENU MODIFICATION - REMOVE - ORPHAN NODES + OpRemoveNodeWithReconn = 4203, // MENU MODIFICATION - REMOVE - NODE, WITH RECONNECTION OpDeleteGroup = 4210, // MENU MODIFICATION - REMOVE - DELETE GROUPS WITH CONTENTS OpClearMesh = 4220, // MENU MODIFICATION - REMOVE - CLEAR MESH DATA OpRenumberingNodes = 4300, // MENU MODIFICATION - RENUMBERING - NODES @@ -182,6 +183,9 @@ namespace SMESHOp { OpConvertMeshToQuadratic = 4513, // MENU MODIFICATION - CONVERT TO/FROM QUADRATIC OpCreateBoundaryElements = 4514, // MENU MODIFICATION - CREATE BOUNDARY ELEMENTS OpSplitBiQuadratic = 4515, // MENU MODIFICATION - SPLIT BI-QUADRATIC TO LINEAR + OpMoveNodeInteractive = 4516, // MENU MODIFICATION - MOVE NODE INTERACTIVE + OpSplitEdgeInteract = 4517, // MENU MODIFICATION - INTERACTIVE ADD NODE ON EDGE + OpSplitFaceInteract = 4518, // MENU MODIFICATION - INTERACTIVE ADD NODE ON FACE // Adaptation ---------------------//-------------------------------- OpMGAdapt = 8020, // MENU ADAPTATION - MG-ADAPT // Measurements -------------------//-------------------------------- diff --git a/src/SMESHGUI/SMESHGUI_RemoveNodeReconnectionDlg.cxx b/src/SMESHGUI/SMESHGUI_RemoveNodeReconnectionDlg.cxx new file mode 100644 index 000000000..890c630f2 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_RemoveNodeReconnectionDlg.cxx @@ -0,0 +1,485 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SMESHGUI_MakeNodeAtPointDlg.cxx +// Author : Edward AGAPOV, Open CASCADE S.A.S. +// SMESH includes +// +#include "SMESHGUI_RemoveNodeReconnectionDlg.h" + +#include "SMESHGUI.h" +#include "SMESHGUI_IdValidator.h" +#include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_VTKUtils.h" +#include "SMESHGUI_MeshEditPreview.h" + +#include +#include +#include +#include + +// SALOME GUI includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// VTK includes +#include + +// IDL includes +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) +#include CORBA_SERVER_HEADER(SMESH_MeshEditor) + +#define SPACING 6 +#define MARGIN 11 + +//======================================================================= +/*! + * \brief Dialog to Remove a node with elements re-connection + */ +//======================================================================= + +SMESHGUI_RemoveNodeReconnectionDlg::SMESHGUI_RemoveNodeReconnectionDlg() + : SMESHGUI_Dialog( 0, false, true ) +{ + setWindowTitle(tr("CAPTION")); + + QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame()); + aDlgLay->setMargin(0); + aDlgLay->setSpacing(SPACING); + myMainFrame = createMainFrame(mainFrame()); + + aDlgLay->addWidget(myMainFrame); + + aDlgLay->setStretchFactor(myMainFrame, 1); +} + +//======================================================================= +// function : createMainFrame() +// purpose : Create frame containing dialog's input fields +//======================================================================= + +QWidget* SMESHGUI_RemoveNodeReconnectionDlg::createMainFrame (QWidget* theParent) +{ + QWidget* aFrame = new QWidget(theParent); + + // Node to remove + + myNodeToMoveGrp = new QGroupBox(tr("NODE_2REMOVE"), aFrame); + myNodeToMoveGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + QLabel* idLabel = new QLabel(tr("NODE_2REMOVE_ID"), myNodeToMoveGrp); + myId = new QLineEdit(myNodeToMoveGrp); + myId->setValidator(new SMESHGUI_IdValidator(this, 1)); + + QGridLayout* myNodeToMoveGrpLayout = new QGridLayout(myNodeToMoveGrp); + myNodeToMoveGrpLayout->setSpacing(SPACING); + myNodeToMoveGrpLayout->setMargin(MARGIN); + + myNodeToMoveGrpLayout->addWidget( idLabel, 0, 0 ); + myNodeToMoveGrpLayout->addWidget( myId, 0, 2 ); + + // Preview + + myPreviewChkBox = new QCheckBox( tr("PREVIEW"), aFrame); + + QVBoxLayout* aLay = new QVBoxLayout(aFrame); + aLay->addWidget(myNodeToMoveGrp); + aLay->addWidget(myPreviewChkBox); + + return aFrame; +} + +//================================================================================ +/*! + * \brief Constructor + */ +//================================================================================ + +SMESHGUI_RemoveNodeReconnectionOp::SMESHGUI_RemoveNodeReconnectionOp() +{ + mySimulation = 0; + mySMESHGUI = 0; + myDlg = new SMESHGUI_RemoveNodeReconnectionDlg; + myFilter = 0; + myHelpFileName = "removing_nodes_and_elements.html#removing-nodes-reconnect-anchor"; + + myNoPreview = false; + + // connect signals and slots + connect(myDlg->myId, SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview())); + connect(myDlg->myPreviewChkBox, SIGNAL (toggled(bool)), SLOT(redisplayPreview())); + connect(myDlg->myId, SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&))); +} + +//======================================================================= +// function : startOperation() +// purpose : Init dialog fields, connect signals and slots, show dialog +//======================================================================= + +void SMESHGUI_RemoveNodeReconnectionOp::startOperation() +{ + myNoPreview = false; + myMeshActor = 0; + + // init simulation with a current View + if ( mySimulation ) delete mySimulation; + mySMESHGUI = getSMESHGUI(); + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ) ); + connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView())); + connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView())); + vtkProperty* aProp = vtkProperty::New(); + aProp->SetRepresentationToWireframe(); + aProp->SetColor(250, 0, 250); + aProp->SetPointSize(5); + aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1); + mySimulation->GetActor()->SetProperty(aProp); + aProp->Delete(); + + // SalomeApp_TypeFilter depends on a current study + if ( myFilter ) delete myFilter; + // QList filters; + // filters.append( new SalomeApp_TypeFilter((SalomeApp_Study*)study(), "SMESH" )); + // myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR ); + + // IPAL19360 + SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation + myDlg->myId->setText(""); + + myDlg->show(); + + onSelectionDone(); // init myMeshActor +} + +//================================================================================ +/*! + * \brief Stops operation + */ +//================================================================================ + +void SMESHGUI_RemoveNodeReconnectionOp::stopOperation() +{ + myNoPreview = true; + if ( mySimulation ) + { + mySimulation->SetVisibility(false); + delete mySimulation; + mySimulation = 0; + } + if ( myMeshActor ) { + myMeshActor = 0; + } + SMESH::SetPointRepresentation( false ); + SMESH::RepaintCurrentView(); + + disconnect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView())); + disconnect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView())); + //selectionMgr()->removeFilter( myFilter ); + SMESHGUI_SelectionOp::stopOperation(); +} + +//================================================================================ +/*! + * \brief perform it's intention action: move or create a node + */ +//================================================================================ + +bool SMESHGUI_RemoveNodeReconnectionOp::onApply() +{ + if( SMESHGUI::isStudyLocked() ) + return false; + + if ( !myMeshActor ) { + SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), tr("INVALID_MESH") ); + dlg()->show(); + return false; + } + + QString msg; + if ( !isValid( msg ) ) { // node id is invalid + if ( !msg.isEmpty() ) + SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), tr("INVALID_ID") ); + dlg()->show(); + return false; + } + + try { + SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( myMeshActor->getIO() ); + if ( aMesh->_is_nil() ) + { + SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), tr("SMESHG_NO_MESH") ); + return true; + } + SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor(); + if ( aMeshEditor->_is_nil() ) + return true; + + bool ok; + int anId = myDlg->myId->text().toInt( &ok ); + myDlg->myId->setText( "" ); + + aMeshEditor->RemoveNodeWithReconnection( anId ); + + SALOME_ListIO aList; + selectionMgr()->setSelectedObjects(aList,false); + aList.Append( myMeshActor->getIO() ); + selectionMgr()->setSelectedObjects(aList,false); + SMESH::UpdateView(); + SMESHGUI::Modified(); + + } + catch (const SALOME::SALOME_Exception& S_ex) { + SalomeApp_Tools::QtCatchCorbaException(S_ex); + } + catch (...) { + } + + return true; +} + +//================================================================================ +/*! + * \brief Check selected node id validity + */ +//================================================================================ + +bool SMESHGUI_RemoveNodeReconnectionOp::isValid( QString& msg ) +{ + bool ok = true; + if ( myMeshActor ) + { + ok = false; + int id = myDlg->myId->text().toInt(); + if ( id > 0 ) + if ( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() ) + ok = aMesh->FindNode( id ); + if ( !ok ) + msg += tr("INVALID_ID") + "\n"; + } + + return ok; +} + +//================================================================================ +/*! + * \brief SLOT called when selection changed + */ +//================================================================================ + +void SMESHGUI_RemoveNodeReconnectionOp::onSelectionDone() +{ + if ( !myDlg->isVisible() || !myDlg->isEnabled() ) + return; + + myDlg->myId->setText(""); + myNoPreview = true; + try + { + SALOME_ListIO aList; + selectionMgr()->selectedObjects( aList, SVTK_Viewer::Type() ); + if ( aList.Extent() != 1) + return; + Handle(SALOME_InteractiveObject) anIO = aList.First(); + myMeshActor = SMESH::FindActorByEntry( anIO->getEntry() ); + + QString aString; + int nbElems = SMESH::GetNameOfSelectedElements( selector(), anIO, aString ); + if ( nbElems == 1 ) + myDlg->myId->setText( aString ); + + } catch (...) { + } + + myNoPreview = false; + redisplayPreview(); +} + +//================================================================================ +/*! + * \brief update preview + */ +//================================================================================ + +void SMESHGUI_RemoveNodeReconnectionOp::redisplayPreview() +{ + if ( myNoPreview ) + return; + myNoPreview = true; + + if ( !myMeshActor ) + onSelectionDone(); + + SMESH::MeshPreviewStruct_var aMeshPreviewStruct; + + QString msg; + if ( myMeshActor && isValid( msg ) && myDlg->myPreviewChkBox->isChecked() ) + try { + SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( myMeshActor->getIO() ); + if ( !aMesh->_is_nil() ) + { + SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer(); + if (!aPreviewer->_is_nil()) + { + int anId = myDlg->myId->text().toInt(); + aPreviewer->RemoveNodeWithReconnection( anId ); + aMeshPreviewStruct = aPreviewer->GetPreviewData(); + } + } + } + catch (...) { + } + + if (!mySimulation) + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI )); + + // display data + if ( & aMeshPreviewStruct.in() ) + { + mySimulation->SetData( aMeshPreviewStruct.in() ); + } + else + { + mySimulation->SetVisibility( false ); + } + + myNoPreview = false; +} + +//================================================================================= +/*! + * \brief SLOT called when the viewer opened + */ +//================================================================================= + +void SMESHGUI_RemoveNodeReconnectionOp::onOpenView() +{ + if ( mySimulation ) + { + mySimulation->SetVisibility( false ); + SMESH::SetPointRepresentation( false ); + } + else + { + mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI )); + } +} + +//================================================================================= +/*! + * \brief SLOT called when the viewer closed + */ +//================================================================================= + +void SMESHGUI_RemoveNodeReconnectionOp::onCloseView() +{ + delete mySimulation; + mySimulation = 0; +} + +//================================================================================ +/*! + * \brief SLOT called when the node id is manually changed + */ +//================================================================================ + +void SMESHGUI_RemoveNodeReconnectionOp::onTextChange( const QString& theText ) +{ + if( myMeshActor ) + { + if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() ) + { + Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO(); + SALOME_ListIO aList; + aList.Append( anIO ); + selectionMgr()->setSelectedObjects( aList, false ); + + if ( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() )) + { + SVTK_TVtkIDsMap aListInd; + aListInd.Add( FromSmIdType( aNode->GetID()) ); + selector()->AddOrRemoveIndex( anIO, aListInd, false ); + if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) ) + aViewWindow->highlight( anIO, true, true ); + } + } + } +} + +//================================================================================ +/*! + * \brief Activate Node selection + */ +//================================================================================ + +void SMESHGUI_RemoveNodeReconnectionOp::activateSelection() +{ + selectionMgr()->clearFilters(); + SMESH::SetPointRepresentation( true ); + //selectionMgr()->installFilter( myFilter ); + setSelectionMode( NodeSelection ); +} + +//================================================================================ +/*! + * \brief Destructor + */ +//================================================================================ + +SMESHGUI_RemoveNodeReconnectionOp::~SMESHGUI_RemoveNodeReconnectionOp() +{ + if ( myDlg ) delete myDlg; + if ( mySimulation ) delete mySimulation; + if ( myFilter ) delete myFilter; +} + +//================================================================================ +/*! + * \brief Gets dialog of this operation + * \retval LightApp_Dialog* - pointer to dialog of this operation + */ +//================================================================================ + +LightApp_Dialog* SMESHGUI_RemoveNodeReconnectionOp::dlg() const +{ + return myDlg; +} + diff --git a/src/SMESHGUI/SMESHGUI_RemoveNodeReconnectionDlg.h b/src/SMESHGUI/SMESHGUI_RemoveNodeReconnectionDlg.h new file mode 100644 index 000000000..9f5551952 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_RemoveNodeReconnectionDlg.h @@ -0,0 +1,110 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SMESHGUI_RemoveNodeReconnectionDlg.h +// Author : Edward AGAPOV, Open CASCADE S.A.S. +// +#ifndef __SMESHGUI_RemoveNodeReconnection_HXX__ +#define __SMESHGUI_RemoveNodeReconnection_HXX__ + +#include "SMESHGUI_Dialog.h" +#include "SMESHGUI_SelectionOp.h" + +class QButtonGroup; +class QCheckBox; +class QGroupBox; +class QLineEdit; +class QPushButton; +class QRadioButton; +class SMESHGUI_SpinBox; +class SMESHGUI_MeshEditPreview; +class SMESHGUI_RemoveNodeReconnectionDlg; + +/*! + * \brief Remove a node with elements re-connection + */ +class SMESHGUI_EXPORT SMESHGUI_RemoveNodeReconnectionOp: public SMESHGUI_SelectionOp +{ + Q_OBJECT + +public: + SMESHGUI_RemoveNodeReconnectionOp(); + virtual ~SMESHGUI_RemoveNodeReconnectionOp(); + + virtual LightApp_Dialog* dlg() const; + +protected: + + virtual void startOperation(); + virtual void stopOperation(); + + virtual void activateSelection(); + + bool isValid( QString& ); + +protected slots: + virtual bool onApply(); + +private slots: + void onSelectionDone(); + void redisplayPreview(); + void onTextChange( const QString& ); + void onOpenView(); + void onCloseView(); + +private: + + SMESHGUI_RemoveNodeReconnectionDlg* myDlg; + + SUIT_SelectionFilter* myFilter; + SMESHGUI* mySMESHGUI; + SMESHGUI_MeshEditPreview* mySimulation; + SMESH_Actor* myMeshActor; + bool myNoPreview; +}; + +/*! + * \brief Dialog to make a mesh pass through a point + */ + +class SMESHGUI_EXPORT SMESHGUI_RemoveNodeReconnectionDlg : public SMESHGUI_Dialog +{ + Q_OBJECT + +public: + SMESHGUI_RemoveNodeReconnectionDlg(); + +private: + QWidget* createMainFrame( QWidget* ); + + QWidget* myMainFrame; + QGroupBox* myNodeToMoveGrp; + QLineEdit* myId; + QCheckBox* myPreviewChkBox; + + QString myHelpFileName; + + friend class SMESHGUI_RemoveNodeReconnectionOp; + +}; + +#endif // SMESHGUI_RemoveNodeReconnectionDLG_H diff --git a/src/SMESHGUI/SMESH_images.ts b/src/SMESHGUI/SMESH_images.ts index 74697d463..99842abe5 100644 --- a/src/SMESHGUI/SMESH_images.ts +++ b/src/SMESHGUI/SMESH_images.ts @@ -191,6 +191,18 @@ ICON_DLG_MOVE_WITHOUT_NODE mesh_move_without_node.png + + ICON_DLG_MOVE_NODE_INTERACTIVE + mesh_move_node_interactive.png + + + ICON_SPLIT_DIAG_INTERACTIVE + mesh_split_diag_interactive.png + + + ICON_SPLIT_FACE_INTERACTIVE + mesh_split_face_interactive.png + ICON_DLG_NODE mesh_vertex.png @@ -275,6 +287,10 @@ ICON_DLG_REM_NODE mesh_rem_node.png + + ICON_REM_NODE_RECON + mesh_rem_node_recon.png + ICON_DLG_REM_ORPHAN_NODES mesh_rem_orphan_nodes.png diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index 67ca49fe5..2aa3b7e54 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -884,6 +884,18 @@ MEN_MESH_THROU_POINT Move Node + + MEN_MOVE_NODE_INTRCT + Move node by mouse + + + MEN_SPLIT_DIAG_INTRC + Add node on segment + + + MEN_SPLIT_FACE_INTRC + Add node to triangle + MEN_MIN_ANG Minimum Angle @@ -1076,6 +1088,10 @@ MEN_REMOVE_NODES Nodes + + MEN_REMOVE_NODE_RECON + Node with reconnection + MEN_REMOVE_ORPHAN_NODES Orphan Nodes @@ -3592,6 +3608,18 @@ Use Display Entity menu command to show them. STB_MESH_THROU_POINT Move Node + + STB_MOVE_NODE_INTRCT + Move Node by mouse + + + STB_SPLIT_DIAG_INTRC + Add node on segment + + + STB_SPLIT_FACE_INTRC + Add node to triangle + STB_MIN_ANG Minimum Angle @@ -3680,6 +3708,10 @@ Use Display Entity menu command to show them. STB_REMOVE_NODES Remove nodes + + STB_REMOVE_NODE_RECON + Remove node with reconnection + STB_REMOVE_ORPHAN_NODES Remove orphan nodes @@ -3876,6 +3908,10 @@ Use Display Entity menu command to show them. TB_RENUMBER Renumbering Toolbar + + TB_INTERACT + Interactive modifications Toolbar + TB_TRANSFORM Transformation Toolbar @@ -4280,6 +4316,18 @@ Use Display Entity menu command to show them. TOP_MESH_THROU_POINT Move Node + + TOP_MOVE_NODE_INTRCT + Move node by mouse + + + TOP_SPLIT_DIAG_INTRC + Add node on segment + + + TOP_SPLIT_FACE_INTRC + Add node to triangle + TOP_MIN_ANG Minimum Angle @@ -4368,6 +4416,10 @@ Use Display Entity menu command to show them. TOP_REMOVE_NODES Remove nodes + + TOP_REMOVE_NODE_RECON + Remove node with reconnection + TOP_REMOVE_ORPHAN_NODES Remove orphan nodes @@ -6685,6 +6737,10 @@ Please specify them and try again DESTINATION Destination + + DESTINATION_BY_MOUSE + Destination by mouse click + MOVE_NODE Move node @@ -6713,6 +6769,116 @@ Please specify them and try again Mesh to modify not selected + + SMESHGUI_AddNodeOnSegmentDlg + + CAPTION + Add node to segment + + + SEGMENT_GROUP + Edge between neighboring triangles + + + SEGMENT + Edge + + + POSITION_GROUP + Node on Edge + + + POSITION + Location by mouse click + + + + SMESHGUI_AddNodeOnSegmentOp + + INVALID_EDGE + Edge is invalid + + + INVALID_MESH + Mesh to modify not selected + + + NO_ELEMENTS + Edge belongs to none face + + + VOLUME_FOUND + Can't split an edge of a volume + + + NOT_TRIANGLE_FACE_FOUND + Operation applies to triangles only + + + BAD_POSITION + Position on edge is incorrect + + + + SMESHGUI_AddNodeOnFaceDlg + + CAPTION + Add node to triangle + + + FACE_GROUP + Triangle to split + + + FACE_ID + ID + + + XYZ_GROUP + Node location by mouse click + + + + SMESHGUI_AddNodeOnFaceOp + + INVALID_MESH + Mesh to modify not selected + + + NOT_FACE + Not a face selected + + + INVALID_ID + Face ID is invalid + + + + SMESHGUI_RemoveNodeReconnectionDlg + + CAPTION + Remove Node with Reconnection + + + NODE_2REMOVE_ID + ID + + + NODE_2REMOVE + Node + + + + SMESHGUI_RemoveNodeReconnectionOp + + INVALID_ID + Node ID is invalid + + + INVALID_MESH + Mesh to modify not selected + + SMESHGUI_FindElemByPointDlg diff --git a/src/SMESHUtils/SMESH_MeshAlgos.cxx b/src/SMESHUtils/SMESH_MeshAlgos.cxx index 9f0c88e20..9bc76d69d 100644 --- a/src/SMESHUtils/SMESH_MeshAlgos.cxx +++ b/src/SMESHUtils/SMESH_MeshAlgos.cxx @@ -2252,6 +2252,56 @@ std::vector< const SMDS_MeshNode*> SMESH_MeshAlgos::GetCommonNodes(const SMDS_Me return common; } +//================================================================================ +/*! + * \brief Return true if a node is on a boundary of 2D mesh. + * Optionally returns two neighboring boundary nodes (or more in non-manifold mesh) + */ +//================================================================================ + +bool SMESH_MeshAlgos::IsOn2DBoundary( const SMDS_MeshNode* theNode, + std::vector< const SMDS_MeshNode*> * theNeibors ) +{ + typedef NCollection_DataMap< SMESH_TLink, int, SMESH_TLink > TLinkCountMap; + TLinkCountMap linkCountMap( 10 ); + + int nbFreeLinks = 0; + for ( SMDS_ElemIteratorPtr fIt = theNode->GetInverseElementIterator(SMDSAbs_Face); fIt->more(); ) + { + const SMDS_MeshElement* face = fIt->next(); + const int nbCorners = face->NbCornerNodes(); + + int iN = face->GetNodeIndex( theNode ); + int iPrev = ( iN - 1 + nbCorners ) % nbCorners; + int iNext = ( iN + 1 ) % nbCorners; + + for ( int i : { iPrev, iNext } ) + { + SMESH_TLink link( theNode, face->GetNode( i )); + int* count = linkCountMap.ChangeSeek( link ); + if ( count ) ++( *count ); + else linkCountMap.Bind( link, 1 ); + + if ( !count ) ++nbFreeLinks; + else --nbFreeLinks; + } + } + + if ( theNeibors ) + { + theNeibors->clear(); + theNeibors->reserve( nbFreeLinks ); + for ( TLinkCountMap::Iterator linkIt( linkCountMap ); linkIt.More(); linkIt.Next() ) + if ( linkIt.Value() == 1 ) + { + theNeibors->push_back( linkIt.Key().node1() ); + if ( theNeibors->back() == theNode ) + theNeibors->back() = linkIt.Key().node2(); + } + } + return nbFreeLinks > 0; +} + //================================================================================ /*! * \brief Return true if node1 encounters first in the face and node2, after diff --git a/src/SMESHUtils/SMESH_MeshAlgos.hxx b/src/SMESHUtils/SMESH_MeshAlgos.hxx index 5c5df659b..36bbeeb45 100644 --- a/src/SMESHUtils/SMESH_MeshAlgos.hxx +++ b/src/SMESHUtils/SMESH_MeshAlgos.hxx @@ -199,6 +199,12 @@ namespace SMESH_MeshAlgos SMESHUtils_EXPORT std::vector< const SMDS_MeshNode*> GetCommonNodes(const SMDS_MeshElement* e1, const SMDS_MeshElement* e2); + /*! + * \brief Return true if a node is on a boundary of 2D mesh. + * Optionally returns two neighboring boundary nodes (or more in non-manifold mesh) + */ + SMESHUtils_EXPORT bool IsOn2DBoundary( const SMDS_MeshNode* node, + std::vector< const SMDS_MeshNode*> * neibors = nullptr ); /*! * \brief Return true if node1 encounters first in the face and node2, after. * The nodes are supposed to be neighbor nodes in the face. @@ -225,6 +231,7 @@ namespace SMESH_MeshAlgos /*! * \brief Mark elements given by SMDS_Iterator + * \sa SMDS_Mesh::SetAllNodesNotMarked() and SMDS_Mesh::SetAllCellsNotMarked() */ template< class ElemIter > void MarkElems( ElemIter it, const bool isMarked ) diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index 07b3d3399..8e822d7ff 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -2486,10 +2486,10 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand) static TStringSet sameMethods; if ( sameMethods.empty() ) { const char * names[] = { - "RemoveElements","RemoveNodes","RemoveOrphanNodes", + "RemoveElements","RemoveNodes","RemoveOrphanNodes","RemoveNodeWithReconnection", "AddNode","Add0DElement","AddEdge","AddFace","AddPolygonalFace","AddBall", - "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces", - "MoveNode", "MoveClosestNodeToPoint","InverseDiag","DeleteDiag", + "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","AddNodeOnSegment", + "MoveNode", "MoveClosestNodeToPoint","InverseDiag","DeleteDiag","AddNodeOnFace", "Reorient","ReorientObject","Reorient2DBy3D","Reorient2DByNeighbours", "TriToQuad","TriToQuadObject", "QuadTo4Tri", "SplitQuad","SplitQuadObject", "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject", diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 323a6603a..9efa484ff 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -834,7 +834,7 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::smIdType_array & IDs //============================================================================= /*! - * + * Remove orphan nodes */ //============================================================================= @@ -865,6 +865,58 @@ SMESH::smIdType SMESH_MeshEditor_i::RemoveOrphanNodes() return 0; } +//============================================================================= +/*! + * Remove a node and fill a hole appeared by changing surrounding faces + */ +//============================================================================= + +void SMESH_MeshEditor_i::RemoveNodeWithReconnection( SMESH::smIdType nodeID ) +{ + SMESH_TRY; + initData(); + + const SMDS_MeshNode * node = getMeshDS()->FindNode( nodeID ); + if ( ! node ) + THROW_SALOME_CORBA_EXCEPTION( SMESH_Comment( "Invalid node ID ") << nodeID, + SALOME::BAD_PARAM); + if ( node->NbInverseElements( SMDSAbs_Volume ) > 0 ) + THROW_SALOME_CORBA_EXCEPTION( "RemoveNodeWithReconnection() applies to 2D mesh only", + SALOME::BAD_PARAM); + + if ( myIsPreviewMode ) // make preview data + { + // in a preview mesh, make edges linked to a node + TPreviewMesh& tmpMesh = *getPreviewMesh( SMDSAbs_Edge ); + TIDSortedElemSet linkedNodes; + ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes ); + SMDS_MeshNode *nodeCpy1 = tmpMesh.Copy( node ); + for ( const SMDS_MeshElement* n : linkedNodes ) + { + SMDS_MeshNode *nodeCpy2 = tmpMesh.Copy ( cast2Node( n )); + tmpMesh.GetMeshDS()->AddEdge( nodeCpy1, nodeCpy2 ); + } + // copy surrounding faces + for ( SMDS_ElemIteratorPtr fIt = node->GetInverseElementIterator( SMDSAbs_Face ); fIt->more(); ) + tmpMesh.Copy ( fIt->next() ); + + // remove copied node + if ( nodeCpy1 ) + getEditor().RemoveNodeWithReconnection( nodeCpy1 ); + } + else + { + getEditor().RemoveNodeWithReconnection( node ); + + // Update Python script + TPythonDump() << this << ".RemoveNodeWithReconnection( " << nodeID << " )"; + + declareMeshModified( /*isReComputeSafe=*/ true ); + } + + SMESH_CATCH( SMESH::throwCorbaException ); +} + //============================================================================= /*! * Add a new node. @@ -1567,6 +1619,121 @@ CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(SMESH::smIdType NodeID1, return 0; } +//============================================================================= +/*! + * \brief Split a diagonal of a quadrangle formed by two adjacent triangles + * so that four new triangles appear in place of the two triangles + */ +//============================================================================= + +void SMESH_MeshEditor_i::AddNodeOnSegment(SMESH::smIdType nodeID1, + SMESH::smIdType nodeID2, + CORBA::Double position) +{ + SMESH_TRY; + initData(); + + const SMDS_MeshNode * n1 = getMeshDS()->FindNode( nodeID1 ); + const SMDS_MeshNode * n2 = getMeshDS()->FindNode( nodeID2 ); + if ( !n1 ) + THROW_SALOME_CORBA_EXCEPTION( SMESH_Comment( "Invalid node ID: ") << nodeID1, + SALOME::BAD_PARAM); + if ( !n2 ) + THROW_SALOME_CORBA_EXCEPTION( SMESH_Comment( "Invalid node ID: ") << nodeID2, + SALOME::BAD_PARAM); + + if ( myIsPreviewMode ) // make preview data + { + TPreviewMesh* tmpMesh = getPreviewMesh(); + TIDSortedElemSet elemSet, avoidSet; + TopoDS_Shape shape; + while ( const SMDS_MeshElement* face = SMESH_MeshAlgos::FindFaceInSet( n1, n2, + elemSet, avoidSet )) + { + if ( avoidSet.empty() ) + { + shape = getMeshDS()->IndexToShape( face->GetShapeID() ); + if ( !shape.IsNull() ) + { + tmpMesh->ShapeToMesh( TopoDS_Shape() ); + tmpMesh->ShapeToMesh( shape ); + } + } + SMDS_MeshElement* faceCopy = tmpMesh->Copy ( face ); + avoidSet.insert( face ); + + if ( !shape.IsNull() ) + tmpMesh->GetMeshDS()->SetMeshElementOnShape( faceCopy, shape ); + } + n1 = tmpMesh->GetMeshDS()->FindNode( nodeID1 ); + n2 = tmpMesh->GetMeshDS()->FindNode( nodeID2 ); + + if ( !shape.IsNull() ) + { + tmpMesh->GetMeshDS()->SetMeshElementOnShape( n1, shape ); + tmpMesh->GetMeshDS()->SetMeshElementOnShape( n2, shape ); + } + } + + getEditor().SplitEdge( n1, n2, position ); + + if ( !myIsPreviewMode ) + { + // Update Python script + TPythonDump() << this << ".AddNodeOnSegment( " + << nodeID1 << ", " << nodeID2 << ", " << position << " )"; + + declareMeshModified( /*isReComputeSafe=*/true ); + } + + SMESH_CATCH( SMESH::throwCorbaException ); +} + +//============================================================================= +/*! + * \brief Split a face into triangles by adding a new node onto the face + * and connecting the new node with face nodes + */ +//============================================================================= + +void SMESH_MeshEditor_i::AddNodeOnFace(SMESH::smIdType theFaceID, + CORBA::Double theX, + CORBA::Double theY, + CORBA::Double theZ) +{ + SMESH_TRY; + initData(); + + const SMDS_MeshElement * face = getMeshDS()->FindElement( theFaceID ); + if ( !face ) + THROW_SALOME_CORBA_EXCEPTION( SMESH_Comment( "Invalid face ID: ") << theFaceID, + SALOME::BAD_PARAM); + if ( face->GetType() != SMDSAbs_Face ) + THROW_SALOME_CORBA_EXCEPTION( "The element is not a face ", SALOME::BAD_PARAM ); + + if ( myIsPreviewMode ) // make preview data + { + TPreviewMesh* tmpMesh = getPreviewMesh(); + face = tmpMesh->Copy ( face ); + } + + getEditor().SplitFace( face, theX, theY, theZ ); + + if ( !myIsPreviewMode ) + { + // Update Python script + TPythonDump() << this << ".AddNodeOnFace( " + << theFaceID << ", " + << theX << ", " + << theY << ", " + << theZ << " )"; + + declareMeshModified( /*isReComputeSafe=*/true ); + } + + SMESH_CATCH( SMESH::throwCorbaException ); +} + //============================================================================= /*! * @@ -2065,8 +2232,8 @@ CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr th */ //============================================================================= -CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad, - SMESH::NumericalFunctor_ptr Criterion) +CORBA::Short SMESH_MeshEditor_i::BestSplit (SMESH::smIdType IDOfQuad, + SMESH::NumericalFunctor_ptr Criterion) { SMESH_TRY; initData(); @@ -4489,7 +4656,6 @@ CORBA::Boolean SMESH_MeshEditor_i::MoveNode(SMESH::smIdType NodeID, // move copied node if ( nodeCpy1 ) tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z); - // fill preview data } else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z )); diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index 3d7072ed4..58c55686b 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -100,9 +100,10 @@ public: */ std::string GenerateGroupName(const std::string& thePrefix); - CORBA::Boolean RemoveElements(const SMESH::smIdType_array & IDsOfElements); - CORBA::Boolean RemoveNodes (const SMESH::smIdType_array & IDsOfNodes); - SMESH::smIdType RemoveOrphanNodes(); + CORBA::Boolean RemoveElements(const SMESH::smIdType_array & IDsOfElements); + CORBA::Boolean RemoveNodes (const SMESH::smIdType_array & IDsOfNodes); + SMESH::smIdType RemoveOrphanNodes(); + void RemoveNodeWithReconnection(SMESH::smIdType nodeID); /*! * Methods for creation new elements. @@ -170,15 +171,42 @@ public: */ void SetMeshElementOnShape(SMESH::smIdType ElementID, CORBA::Long ShapeID); - + /*! + * \brief Change node location + */ CORBA::Boolean MoveNode(SMESH::smIdType NodeID, CORBA::Double x, CORBA::Double y, CORBA::Double z); + /*! + * \brief Swap a diagonal of a quadrangle formed by two adjacent triangles + */ CORBA::Boolean InverseDiag(SMESH::smIdType NodeID1, SMESH::smIdType NodeID2); + /*! + * \brief Delete a diagonal of a quadrangle formed by two adjacent triangles + * so that a new quadrangle appears in place of the triangles + */ CORBA::Boolean DeleteDiag(SMESH::smIdType NodeID1, SMESH::smIdType NodeID2); + /*! + * \brief Split a diagonal of a quadrangle formed by two adjacent triangles + * so that four new triangles appear in place of the two triangles + */ + void AddNodeOnSegment(SMESH::smIdType segmentNode1, SMESH::smIdType segmentNode2, + CORBA::Double position); + /*! + * \brief Split a face into triangles by adding a new node onto the face + * and connecting the new node with face nodes + */ + void AddNodeOnFace(SMESH::smIdType triangle, + CORBA::Double x, CORBA::Double y, CORBA::Double z); + + /*! + * \brief Change orientation of cells + */ CORBA::Boolean Reorient(const SMESH::smIdType_array & IDsOfElements); + /*! + * \brief Change orientation of cells + */ CORBA::Boolean ReorientObject(SMESH::SMESH_IDSource_ptr theObject); - /*! * \brief Reorient faces contained in \a the2Dgroup. * \param the2Dgroup - the mesh or its part to reorient @@ -231,7 +259,7 @@ public: CORBA::Boolean Diag13); CORBA::Boolean SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject, CORBA::Boolean Diag13); - CORBA::Long BestSplit (CORBA::Long IDOfQuad, + CORBA::Short BestSplit (SMESH::smIdType IDOfQuad, SMESH::NumericalFunctor_ptr Criterion); void SplitVolumesIntoTetra(SMESH::SMESH_IDSource_ptr elems, CORBA::Short methodFlags); diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index 1d5269c19..80f2c6d21 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -4098,6 +4098,16 @@ class Mesh(metaclass = MeshMeta): return self.editor.RemoveNodes(IDsOfNodes) + def RemoveNodeWithReconnection(self, nodeID ): + """ + Remove a node along with changing surrounding faces to cover a hole. + + Parameters: + nodeID: ID of node to remove + """ + + return self.editor.RemoveNodeWithReconnection( nodeID ) + def RemoveOrphanNodes(self): """ Remove all orphan (free) nodes from mesh @@ -4591,6 +4601,30 @@ class Mesh(metaclass = MeshMeta): return self.editor.DeleteDiag(NodeID1, NodeID2) + def AddNodeOnSegment(self, Node1, Node2, position = 0.5): + """ + Replace each triangle bound by Node1-Node2 segment with + two triangles by connecting a node made on the link with a node + opposite to the link. + + Parameters: + Node1: ID of the first node + Node2: ID of the second node + position: location [0,1] of the new node on the segment + """ + return self.editor.AddNodeOnSegment(Node1, Node2, position) + + def AddNodeOnFace(self, face, x, y, z): + """ + Split a face into triangles by adding a new node onto the face + and connecting the new node with face nodes + + Parameters: + face: ID of the face + x,y,z: coordinates of the new node + """ + return self.editor.AddNodeOnFace(face, x, y, z) + def Reorient(self, IDsOfElements=None): """ Reorient elements by ids