From 97b32d6eb94967c475ff89d1fa4c88d1935502b0 Mon Sep 17 00:00:00 2001 From: jriegel Date: Thu, 29 Aug 2013 22:15:14 +0200 Subject: [PATCH] change node attribute to a id:vector3d dictionary and changes the scripts --- src/Mod/Fem/App/FemMeshPy.xml | 23 ++++++++----- src/Mod/Fem/App/FemMeshPyImp.cpp | 33 ++++++++++++++++--- .../Machining_Distortion/MachDistAlignment.py | 2 +- .../Machining_Distortion/MachDistIsostatic.py | 12 +++---- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/Mod/Fem/App/FemMeshPy.xml b/src/Mod/Fem/App/FemMeshPy.xml index 3a8958d50..3f388a742 100755 --- a/src/Mod/Fem/App/FemMeshPy.xml +++ b/src/Mod/Fem/App/FemMeshPy.xml @@ -78,17 +78,22 @@ Use a Placement object to perform a translation or rotation - - - - Make a copy of this FEM mesh. - - - + + + + Make a copy of this FEM mesh. + + + + + Get the node position vector by an Node-ID + + + - Tuple of node points. + Dictionary of Nodes by ID (int ID:Vector()) - + diff --git a/src/Mod/Fem/App/FemMeshPyImp.cpp b/src/Mod/Fem/App/FemMeshPyImp.cpp index d614fdee7..6a925e56b 100755 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -460,12 +460,34 @@ PyObject* FemMeshPy::setTransform(PyObject *args) Py_Return; } +PyObject* FemMeshPy::getNodeById(PyObject *args) +{ + int id; + if (!PyArg_ParseTuple(args, "i", &id)) + return 0; + + Base::Matrix4D Mtrx = getFemMeshPtr()->getTransform(); + const SMDS_MeshNode* aNode = getFemMeshPtr()->getSMesh()->GetMeshDS()->FindNode(id); + + if(aNode){ + Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z()); + vec = Mtrx * vec; + return new Base::VectorPy( vec ); + }else{ + PyErr_SetString(PyExc_Exception, "No valid ID"); + return 0; + } +} + + // ===== Atributes ============================================================ -Py::Tuple FemMeshPy::getNodes(void) const +Py::Dict FemMeshPy::getNodes(void) const { - int count = getFemMeshPtr()->getSMesh()->GetMeshDS()->NbNodes(); - Py::Tuple tup(count); + //int count = getFemMeshPtr()->getSMesh()->GetMeshDS()->NbNodes(); + //Py::Tuple tup(count); + Py::Dict dict; + // get the actuall transform of the FemMesh Base::Matrix4D Mtrx = getFemMeshPtr()->getTransform(); @@ -475,11 +497,12 @@ Py::Tuple FemMeshPy::getNodes(void) const Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z()); // Apply the matrix to hold the BoundBox in absolute space. vec = Mtrx * vec; + int id = aNode->GetID(); - tup.setItem(i, Py::asObject(new Base::VectorPy( vec ))); + dict[Py::Int(id)] = Py::asObject(new Base::VectorPy( vec )); } - return tup; + return dict; } Py::Int FemMeshPy::getNodeCount(void) const diff --git a/src/Mod/Machining_Distortion/MachDistAlignment.py b/src/Mod/Machining_Distortion/MachDistAlignment.py index 17dd792de..24f77e913 100644 --- a/src/Mod/Machining_Distortion/MachDistAlignment.py +++ b/src/Mod/Machining_Distortion/MachDistAlignment.py @@ -99,7 +99,7 @@ class _AlignTaskPanel: QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor) import Mesh # find the eigen axis - self.obj.Placement = Mesh.calculateEigenTransform(self.obj.FemMesh.Nodes) + self.obj.Placement = Mesh.calculateEigenTransform(self.obj.FemMesh.Nodes.values()) # make the first alignment persistent m = Fem.FemMesh(self.obj.FemMesh) diff --git a/src/Mod/Machining_Distortion/MachDistIsostatic.py b/src/Mod/Machining_Distortion/MachDistIsostatic.py index ac437017b..1028891c9 100644 --- a/src/Mod/Machining_Distortion/MachDistIsostatic.py +++ b/src/Mod/Machining_Distortion/MachDistIsostatic.py @@ -44,23 +44,23 @@ def getBoundaryCoditions(Mesh): SecondIndex = -1 ThirdLength = 10000.0 ThirdIndex = -1 - Index = 0 - for i in Mesh.Nodes: + + for id,i in Mesh.Nodes.items(): l = (i-FreeCAD.Vector(BndBox.XMin,BndBox.YMin,BndBox.ZMin)).Length if FirstLength > l: FirstLength = l - FirstIndex = Index + FirstIndex = id l = (i-FreeCAD.Vector(BndBox.XMax,BndBox.YMin,BndBox.ZMin)).Length if SecondLength > l: SecondLength = l - SecondIndex = Index + SecondIndex = id l = (i-FreeCAD.Vector(BndBox.XMin,BndBox.YMax,BndBox.ZMin)).Length if ThirdLength > l: ThirdLength = l - ThirdIndex = Index - Index = Index + 1 + ThirdIndex = id + print FirstIndex,SecondIndex,ThirdIndex return (FirstIndex,SecondIndex,ThirdIndex)