Fem: Add FemMeshShapeBaseObject and fix FemMeshShapeObject meshing

This commit is contained in:
marioalexis
2024-07-25 13:30:15 -03:00
parent 00990cb1e1
commit 56001d3f74
10 changed files with 160 additions and 166 deletions

View File

@@ -21,32 +21,13 @@
***************************************************************************/
#include "PreCompiled.h"
#include <SMESH_Version.h>
#ifndef _PreComp_
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepTools.hxx>
#include <Python.h>
#include <SMESH_Gen.hxx>
#include <SMESH_Mesh.hxx>
#include <StdMeshers_Deflection1D.hxx>
#include <StdMeshers_Hexa_3D.hxx>
#include <StdMeshers_LocalLength.hxx>
#include <StdMeshers_MaxElementArea.hxx>
#include <StdMeshers_MaxLength.hxx>
#include <StdMeshers_NumberOfSegments.hxx>
#include <StdMeshers_ProjectionSource1D.hxx>
#include <StdMeshers_ProjectionSource2D.hxx>
#include <StdMeshers_ProjectionSource3D.hxx>
#include <StdMeshers_QuadranglePreference.hxx>
#include <StdMeshers_Quadrangle_2D.hxx>
#include <StdMeshers_RadialPrism_3D.hxx>
#include <StdMeshers_Regular_1D.hxx>
#include <StdMeshers_SegmentAroundVertex_0D.hxx>
#include <StdMeshers_StartEndLength.hxx>
#endif
#include <App/DocumentObjectPy.h>
#include <App/FeaturePythonPyImp.h>
#include <App/GeoFeaturePy.h>
#include <Mod/Part/App/PartFeature.h>
#include "FemMesh.h"
@@ -56,10 +37,9 @@
using namespace Fem;
using namespace App;
PROPERTY_SOURCE(Fem::FemMeshShapeObject, Fem::FemMeshObject)
PROPERTY_SOURCE(Fem::FemMeshShapeBaseObject, Fem::FemMeshObject)
FemMeshShapeObject::FemMeshShapeObject()
FemMeshShapeBaseObject::FemMeshShapeBaseObject()
{
ADD_PROPERTY_TYPE(
Shape,
@@ -67,8 +47,18 @@ FemMeshShapeObject::FemMeshShapeObject()
"FEM Mesh",
Prop_None,
"Geometry object, the mesh is made from. The geometry object has to have a Shape.");
Shape.setScope(LinkScope::Global);
}
FemMeshShapeBaseObject::~FemMeshShapeBaseObject() = default;
// ------------------------------------------------------------------------
PROPERTY_SOURCE(Fem::FemMeshShapeObject, Fem::FemMeshShapeBaseObject)
FemMeshShapeObject::FemMeshShapeObject() = default;
FemMeshShapeObject::~FemMeshShapeObject() = default;
App::DocumentObjectExecReturn* FemMeshShapeObject::execute()
@@ -76,83 +66,43 @@ App::DocumentObjectExecReturn* FemMeshShapeObject::execute()
Fem::FemMesh newMesh;
Part::Feature* feat = Shape.getValue<Part::Feature*>();
TopoDS_Shape shape = feat->Shape.getValue();
newMesh.getSMesh()->ShapeToMesh(shape);
SMESH_Gen* myGen = newMesh.getGenerator();
newMesh.setStandardHypotheses();
int hyp = 0;
#if 1 // Surface quad mesh
#if SMESH_VERSION_MAJOR >= 9
SMESH_HypothesisPtr len(new StdMeshers_MaxLength(hyp++, myGen));
static_cast<StdMeshers_MaxLength*>(len.get())->SetLength(1.0);
newMesh.addHypothesis(shape, len);
SMESH_HypothesisPtr loc(new StdMeshers_LocalLength(hyp++, myGen));
static_cast<StdMeshers_LocalLength*>(loc.get())->SetLength(1.0);
newMesh.addHypothesis(shape, loc);
SMESH_HypothesisPtr area(new StdMeshers_MaxElementArea(hyp++, myGen));
static_cast<StdMeshers_MaxElementArea*>(area.get())->SetMaxArea(1.0);
newMesh.addHypothesis(shape, area);
SMESH_HypothesisPtr segm(new StdMeshers_NumberOfSegments(hyp++, myGen));
static_cast<StdMeshers_NumberOfSegments*>(segm.get())->SetNumberOfSegments(1);
newMesh.addHypothesis(shape, segm);
SMESH_HypothesisPtr defl(new StdMeshers_Deflection1D(hyp++, myGen));
static_cast<StdMeshers_Deflection1D*>(defl.get())->SetDeflection(0.01);
newMesh.addHypothesis(shape, defl);
SMESH_HypothesisPtr reg(new StdMeshers_Regular_1D(hyp++, myGen));
newMesh.addHypothesis(shape, reg);
SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++, myGen));
newMesh.addHypothesis(shape, qdp);
SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++, myGen));
newMesh.addHypothesis(shape, q2d);
#else
SMESH_HypothesisPtr len(new StdMeshers_MaxLength(hyp++, 1, myGen));
static_cast<StdMeshers_MaxLength*>(len.get())->SetLength(1.0);
newMesh.addHypothesis(shape, len);
SMESH_HypothesisPtr loc(new StdMeshers_LocalLength(hyp++, 1, myGen));
static_cast<StdMeshers_LocalLength*>(loc.get())->SetLength(1.0);
newMesh.addHypothesis(shape, loc);
SMESH_HypothesisPtr area(new StdMeshers_MaxElementArea(hyp++, 1, myGen));
static_cast<StdMeshers_MaxElementArea*>(area.get())->SetMaxArea(1.0);
newMesh.addHypothesis(shape, area);
SMESH_HypothesisPtr segm(new StdMeshers_NumberOfSegments(hyp++, 1, myGen));
static_cast<StdMeshers_NumberOfSegments*>(segm.get())->SetNumberOfSegments(1);
newMesh.addHypothesis(shape, segm);
SMESH_HypothesisPtr defl(new StdMeshers_Deflection1D(hyp++, 1, myGen));
static_cast<StdMeshers_Deflection1D*>(defl.get())->SetDeflection(0.01);
newMesh.addHypothesis(shape, defl);
SMESH_HypothesisPtr reg(new StdMeshers_Regular_1D(hyp++, 1, myGen));
newMesh.addHypothesis(shape, reg);
SMESH_HypothesisPtr qdp(new StdMeshers_QuadranglePreference(hyp++, 1, myGen));
newMesh.addHypothesis(shape, qdp);
SMESH_HypothesisPtr q2d(new StdMeshers_Quadrangle_2D(hyp++, 1, myGen));
newMesh.addHypothesis(shape, q2d);
#endif
// create mesh
newMesh.compute();
#endif
// set the value to the object
FemMesh.setValue(newMesh);
return App::DocumentObject::StdReturn;
}
// Python feature ---------------------------------------------------------
namespace App
{
PROPERTY_SOURCE_TEMPLATE(Fem::FemMeshShapeBaseObjectPython, Fem::FemMeshShapeBaseObject)
template<>
const char* Fem::FemMeshShapeBaseObjectPython::getViewProviderName() const
{
return "FemGui::ViewProviderFemMeshShapeBasePython";
}
template<>
PyObject* Fem::FemMeshShapeBaseObjectPython::getPyObject()
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::asObject(new App::FeaturePythonPyT<App::GeoFeaturePy>(this));
}
return Py::new_reference_to(PythonObject);
}
// explicit template instantiation
template class FemExport FeaturePythonT<Fem::FemMeshShapeBaseObject>;
} // namespace App