diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp index 17439750100e6941b44b30ccff9e4f87c9fb0965..541ee8436883cb0c6312bb12632576caa10f4284 100644 --- a/Geo/GFace.cpp +++ b/Geo/GFace.cpp @@ -63,13 +63,15 @@ GFace::~GFace() deleteMesh(); } -int GFace::getMeshingAlgo () const { +int GFace::getMeshingAlgo () const +{ std::map<int,int>::iterator it = CTX::instance()->mesh.algo2d_per_face.find(tag()); return it == CTX::instance()->mesh.algo2d_per_face.end() ? CTX::instance()->mesh.algo2d : it->second ; } -void GFace::setMeshingAlgo (int algo) { +void GFace::setMeshingAlgo (int algo) +{ CTX::instance()->mesh.algo2d_per_face[tag()] = algo; } @@ -927,7 +929,7 @@ void bfgs_callback(const alglib::real_1d_array& x, double& func, alglib::real_1d // Value of the objective GPoint pnt = gf->point(x[0], x[1]); - func = 0.5 * + func = 0.5 * ( p.x() - pnt.x() ) * ( p.x() - pnt.x() ) + ( p.y() - pnt.y() ) * ( p.y() - pnt.y() ) + ( p.z() - pnt.z() ) * ( p.z() - pnt.z() ) ; @@ -935,8 +937,8 @@ void bfgs_callback(const alglib::real_1d_array& x, double& func, alglib::real_1d // Value of the gradient Pair<SVector3, SVector3> der = gf->firstDer(SPoint2(x[0], x[1])); - grad[0] = -(p.x() - pnt.x()) * der.left().x() - (p.y() - pnt.y()) * der.left().y() - (p.z() - pnt.z()) * der.left().z(); - grad[1] = -(p.x() - pnt.x()) * der.right().x() - (p.y() - pnt.y()) * der.right().y() - (p.z() - pnt.z()) * der.right().z(); + grad[0] = -(p.x() - pnt.x()) * der.left().x() - (p.y() - pnt.y()) * der.left().y() - (p.z() - pnt.z()) * der.left().z(); + grad[1] = -(p.x() - pnt.x()) * der.right().x() - (p.y() - pnt.y()) * der.right().y() - (p.z() - pnt.z()) * der.right().z(); // printf("func %22.15E Gradients %22.15E %22.15E der %g %g %g\n",func, grad[0], grad[1],der.left().x(),der.left().y(),der.left().z()); } #endif @@ -993,7 +995,7 @@ GPoint GFace::closestPoint(const SPoint3 &queryPoint, const double initialGuess[ // printf("Initial conditions : %f %f %12.5E\n", min_u, min_v,min_dist); GPoint pnt = point(min_u, min_v); - // printf("Initial conditions (point) : %f %f %f local (%g %g) Looking for %f %f %f DIST = %12.5E\n", + // printf("Initial conditions (point) : %f %f %f local (%g %g) Looking for %f %f %f DIST = %12.5E\n", // pnt.x(), pnt.y(), pnt.z(),min_u,min_v, // queryPoint.x(),queryPoint.y(),queryPoint.z(), // min_dist); @@ -1031,20 +1033,20 @@ GPoint GFace::closestPoint(const SPoint3 &queryPoint, const double initialGuess[ GPoint pntF = point(x[0], x[1]); if (rep.terminationtype != 4){ - // printf("Initial conditions (point) : %f %f %f local (%g %g) Looking for %f %f %f DIST = %12.5E at the end (%f %f) %f %f %f\n", + // printf("Initial conditions (point) : %f %f %f local (%g %g) Looking for %f %f %f DIST = %12.5E at the end (%f %f) %f %f %f\n", // pnt.x(), pnt.y(), pnt.z(),min_u,min_v, // queryPoint.x(),queryPoint.y(),queryPoint.z(), // min_dist,x[0],x[1],pntF.x(), pntF.y(), pntF.z()); - // double DDD = + // double DDD = // ( queryPoint.x() - pntF.x()) * ( queryPoint.x() - pntF.x()) + // ( queryPoint.y() - pntF.y()) * ( queryPoint.y() - pntF.y()) + // ( queryPoint.z() - pntF.z()) * ( queryPoint.z() - pntF.z()); // if (sqrt(DDD) > 1.e-4) /* - printf("Initial conditions (point) : %f %f %f local (%g %g) Looking for %f %f %f DIST = %12.5E at the end (%f %f) %f %f %f termination %d\n", + printf("Initial conditions (point) : %f %f %f local (%g %g) Looking for %f %f %f DIST = %12.5E at the end (%f %f) %f %f %f termination %d\n", pnt.x(), pnt.y(), pnt.z(),min_u,min_v, queryPoint.x(),queryPoint.y(),queryPoint.z(), - min_dist,x[0],x[1],pntF.x(), pntF.y(), pntF.z(),rep.terminationtype); + min_dist,x[0],x[1],pntF.x(), pntF.y(), pntF.z(),rep.terminationtype); */ } return pntF; diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 0c1041b5fc6ab6220bfcb7a17ee3a03dec286d51..f17915de01562d9412bbe0f4e5081935998fed21 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -2082,6 +2082,13 @@ GEdge *GModel::addCircleArcCenter(double x, double y, double z, GVertex *start, return 0; } +GEdge *GModel::addCircleArcCenter(GVertex *start, GVertex *center, GVertex *end) +{ + if(_factory) + return _factory->addCircleArc(this, start, center, end); + return 0; +} + GEdge *GModel::addCircleArc3Points(double x, double y, double z, GVertex *start, GVertex *end) { diff --git a/Geo/GModel.h b/Geo/GModel.h index cedde36c713340069141fb3d8533da5d3e613356..f19bc97bd12e719e3cf10d4e52e714b252633617 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -436,6 +436,7 @@ class GModel GVertex *addVertex(double x, double y, double z, double lc); GEdge *addLine(GVertex *v1, GVertex *v2); GEdge *addCircleArcCenter(double x, double y, double z, GVertex *start, GVertex *end); + GEdge *addCircleArcCenter(GVertex *start, GVertex *center, GVertex *end); GEdge *addCircleArc3Points(double x, double y, double z, GVertex *start, GVertex *end); GEdge *addBezier(GVertex *start, GVertex *end, std::vector<std::vector<double> > points); GEdge *addNURBS(GVertex *start, GVertex *end, diff --git a/Geo/GModelFactory.cpp b/Geo/GModelFactory.cpp index 33fbd044081aa64becceafb4348698b0f09e9c08..c5c06cb65d35b8e5e76347ea5488052c1b565cc0 100644 --- a/Geo/GModelFactory.cpp +++ b/Geo/GModelFactory.cpp @@ -17,7 +17,7 @@ GVertex *GeoFactory::addVertex(GModel *gm, double x, double y, double z, double lc) { int num = gm->getMaxElementaryNumber(0) + 1; - + x *= CTX::instance()->geom.scalingFactor; y *= CTX::instance()->geom.scalingFactor; z *= CTX::instance()->geom.scalingFactor; @@ -28,7 +28,7 @@ GVertex *GeoFactory::addVertex(GModel *gm, double x, double y, double z, double Tree_Add(GModel::current()->getGEOInternals()->Points, &p); p->Typ = MSH_POINT; p->Num = num; - + GVertex *v = new gmshVertex(gm, p); gm->add(v); @@ -43,7 +43,7 @@ GEdge *GeoFactory::addLine(GModel *gm, GVertex *start, GVertex *end) int tagEnd = end->tag(); List_Add(iList, &tagBeg); List_Add(iList, &tagEnd); - + Curve *c = Create_Curve(num, MSH_SEGM_LINE, 1, iList, NULL, -1, -1, 0., 1.); Tree_Add(GModel::current()->getGEOInternals()->Curves, &c); @@ -59,64 +59,36 @@ GEdge *GeoFactory::addLine(GModel *gm, GVertex *start, GVertex *end) } GFace *GeoFactory::addPlanarFace(GModel *gm, std::vector< std::vector<GEdge *> > edges) -{ - // create line loops - // FIXME: having non-ordered lines in the loop triggers a warning; we should - // eventually return an error, but createTopolpgyFromMesh() does not currently - // sort edges in loops; once it does, we can be stricter here. +{ + //create line loops std::vector<EdgeLoop *> vecLoops; int nLoops = edges.size(); - for (int i = 0; i< nLoops; i++){ + for (int i=0; i< nLoops; i++){ int numl = gm->getMaxElementaryNumber(1) + i; while (FindEdgeLoop(numl)){ numl++; + if (!FindEdgeLoop(numl)) break; } - int nl = (int)edges[i].size(); - const GEdge &e0 = *edges[i][0]; - const GVertex *frontV = e0.getBeginVertex(); + int nl=(int)edges[i].size(); List_T *iListl = List_Create(nl, nl, sizeof(int)); - if (nl > 1) { - const GEdge &e1 = *edges[i][1]; - if (e0.getEndVertex() != e1.getBeginVertex() && - e0.getEndVertex() != e1.getEndVertex()) { - frontV = e0.getEndVertex(); - if (e0.getBeginVertex() != e1.getBeginVertex() && - e0.getBeginVertex() != e1.getEndVertex()) { - Msg::Warning("Edges 0 and 1 not consecutive in line loop %d", i); - //return NULL; - } - } - } - const GVertex *firstV = frontV; - for (int j = 0; j < nl; j++){ - const GEdge &e = *edges[i][j]; - int numEdge = e.tag(); - if (frontV == e.getBeginVertex()) { - frontV = e.getEndVertex(); - } - else if (frontV == e.getEndVertex()){ - frontV = e.getBeginVertex(); - numEdge = -numEdge; - } - else { - Msg::Warning("Edge %d out of order in line loop %d", j, i); - //List_Delete(iListl); - //return NULL; - } + for(int j = 0; j < nl; j++){ + int numEdge = edges[i][j]->tag(); List_Add(iListl, &numEdge); } - if (firstV != frontV) { - Msg::Warning("Unordered line loop %d", i); - //List_Delete(iListl); - //return NULL; - } + int type=ENT_LINE; + + select_contour(type, edges[i][0]->tag(), iListl); + + sortEdgesInLoop(numl, iListl); EdgeLoop *l = Create_EdgeLoop(numl, iListl); vecLoops.push_back(l); Tree_Add(GModel::current()->getGEOInternals()->EdgeLoops, &l); l->Num = numl; + + List_Delete(iListl); } - + //create plane surfaces int numf = gm->getMaxElementaryNumber(2) + 1; Surface *s = Create_Surface(numf, MSH_SURF_PLAN); @@ -131,7 +103,7 @@ GFace *GeoFactory::addPlanarFace(GModel *gm, std::vector< std::vector<GEdge *> > s->Typ= MSH_SURF_PLAN; s->Num = numf; List_Delete(iList); - + //gmsh surface GFace *gf = new gmshFace(gm,s); gm->add(gf); @@ -161,7 +133,7 @@ GRegion* GeoFactory::addVolume (GModel *gm, std::vector<std::vector<GFace *> > f Tree_Add(GModel::current()->getGEOInternals()->SurfaceLoops, &l); List_Delete(iListl); } - + //volume int numv = gm->getMaxElementaryNumber(3) + 1; Volume *v = Create_Volume(numv, MSH_VOLUME); @@ -175,14 +147,95 @@ GRegion* GeoFactory::addVolume (GModel *gm, std::vector<std::vector<GFace *> > f Tree_Add(GModel::current()->getGEOInternals()->Volumes, &v); v->Typ = MSH_VOLUME; v->Num = numv; - + //gmsh volume GRegion *gr = new gmshRegion(gm,v); gm->add(gr); - + return gr; } +GEdge* GeoFactory::addCircleArc(GModel *gm,GVertex *begin, GVertex *center, GVertex *end) +{ + int num = gm->getMaxElementaryNumber(1) + 1; + List_T *iList = List_Create(2, 2, sizeof(int)); + int tagBeg = begin->tag(); + int tagMiddle = center->tag(); + int tagEnd = end->tag(); + List_Add(iList, &tagBeg); + List_Add(iList, &tagMiddle); + List_Add(iList, &tagEnd); + + Curve *c = Create_Curve(num, MSH_SEGM_CIRC, 1, iList, NULL, + -1, -1, 0., 1.); + Tree_Add(GModel::current()->getGEOInternals()->Curves, &c); + CreateReversedCurve(c); + List_Delete(iList); + c->Typ = MSH_SEGM_CIRC; + c->Num = num; + + GEdge *e = new gmshEdge(gm, c, begin, end); + gm->add(e); + + return e; +} + +std::vector<GFace *> GeoFactory::addRuledFaces(GModel *gm, + std::vector<std::vector<GEdge *> > edges) +{ + //create line loops + std::vector<EdgeLoop *> vecLoops; + int nLoops = edges.size(); + for (int i=0; i< nLoops; i++){ + int numl = gm->getMaxElementaryNumber(1) + i; + while (FindEdgeLoop(numl)){ + numl++; + if (!FindEdgeLoop(numl)) break; + } + int nl=(int)edges[i].size(); + List_T *iListl = List_Create(nl, nl, sizeof(int)); + for(int j = 0; j < nl; j++){ + int numEdge = edges[i][j]->tag(); + List_Add(iListl, &numEdge); + } + int type=ENT_LINE; + if(select_contour(type, edges[0][0]->tag(), iListl)) + { + sortEdgesInLoop(numl, iListl); + EdgeLoop *l = Create_EdgeLoop(numl, iListl); + vecLoops.push_back(l); + Tree_Add(GModel::current()->getGEOInternals()->EdgeLoops, &l); + l->Num = numl; + } + + List_Delete(iListl); + } + + //create plane surfaces + int numf = gm->getMaxElementaryNumber(2) + 1; + Surface *s = Create_Surface(numf, MSH_SURF_TRIC); + List_T *iList = List_Create(nLoops, nLoops, sizeof(int)); + for (unsigned int i=0; i< vecLoops.size(); i++){ + int numl = vecLoops[i]->Num; + List_Add(iList, &numl); + } + setSurfaceGeneratrices(s, iList); + End_Surface(s); + Tree_Add(GModel::current()->getGEOInternals()->Surfaces, &s); + s->Typ= MSH_SURF_TRIC; + s->Num = numf; + List_Delete(iList); + + //gmsh surface + GFace *gf = new gmshFace(gm,s); + gm->add(gf); + + std::vector<GFace*> faces; + faces.push_back(gf); + + return faces; +} + #if defined(HAVE_OCC) #include "OCCIncludes.h" #include "GModelIO_OCC.h" @@ -223,7 +276,7 @@ GVertex *OCCFactory::addVertex(GModel *gm, double x, double y, double z, double aPnt = gp_Pnt(x, y, z); BRepBuilderAPI_MakeVertex mkVertex(aPnt); TopoDS_Vertex occv = mkVertex.Vertex(); - + return gm->_occ_internals->addVertexToModel(gm, occv); } @@ -236,24 +289,24 @@ GEdge *OCCFactory::addLine(GModel *gm, GVertex *start, GVertex *end) OCCVertex *occv2 = dynamic_cast<OCCVertex*>(end); TopoDS_Edge occEdge; if (occv1 && occv2){ - occEdge = BRepBuilderAPI_MakeEdge(occv1->getShape(), + occEdge = BRepBuilderAPI_MakeEdge(occv1->getShape(), occv2->getShape()).Edge(); } else{ gp_Pnt p1(start->x(),start->y(),start->z()); gp_Pnt p2(end->x(),end->y(),end->z()); TopoDS_Edge occEdge = BRepBuilderAPI_MakeEdge(p1, p2).Edge(); - } + } return gm->_occ_internals->addEdgeToModel(gm,occEdge); } GEdge *OCCFactory::addCircleArc(GModel *gm, const arcCreationMethod &method, - GVertex *start, GVertex *end, + GVertex *start, GVertex *end, const SPoint3 &aPoint) { if (!gm->_occ_internals) gm->_occ_internals = new OCC_Internals; - + gp_Pnt aP1(start->x(), start->y(), start->z()); gp_Pnt aP2(aPoint.x(), aPoint.y(), aPoint.z()); gp_Pnt aP3(end->x(), end->y(), end->z()); @@ -265,9 +318,9 @@ GEdge *OCCFactory::addCircleArc(GModel *gm, const arcCreationMethod &method, if (method == GModelFactory::THREE_POINTS){ GC_MakeArcOfCircle arc(aP1, aP2, aP3); if (occv1 && occv2) - occEdge = BRepBuilderAPI_MakeEdge(arc,occv1->getShape(), - occv2->getShape()).Edge(); - else + occEdge = BRepBuilderAPI_MakeEdge(arc,occv1->getShape(), + occv2->getShape()).Edge(); + else occEdge = BRepBuilderAPI_MakeEdge(arc).Edge(); } else if (method == GModelFactory::CENTER_START_END){ @@ -280,15 +333,15 @@ GEdge *OCCFactory::addCircleArc(GModel *gm, const arcCreationMethod &method, Handle(Geom_TrimmedCurve) arc = new Geom_TrimmedCurve(C, Alpha1, Alpha2, false); if (occv1 && occv2) occEdge = BRepBuilderAPI_MakeEdge(arc, occv1->getShape(), - occv2->getShape()).Edge(); - else + occv2->getShape()).Edge(); + else occEdge = BRepBuilderAPI_MakeEdge(arc).Edge(); } return gm->_occ_internals->addEdgeToModel(gm,occEdge); } GEdge *OCCFactory::addSpline(GModel *gm, const splineType &type, - GVertex *start, GVertex *end, + GVertex *start, GVertex *end, std::vector<std::vector<double> > points) { if (!gm->_occ_internals) @@ -302,43 +355,43 @@ GEdge *OCCFactory::addSpline(GModel *gm, const splineType &type, int nbControlPoints = points.size(); TColgp_Array1OfPnt ctrlPoints(1, nbControlPoints + 2); int index = 1; - ctrlPoints.SetValue(index++, gp_Pnt(start->x(), start->y(), start->z())); + ctrlPoints.SetValue(index++, gp_Pnt(start->x(), start->y(), start->z())); for (int i = 0; i < nbControlPoints; i++) { gp_Pnt aP(points[i][0],points[i][1],points[i][2]); ctrlPoints.SetValue(index++, aP); } - ctrlPoints.SetValue(index++, gp_Pnt(end->x(), end->y(), end->z())); + ctrlPoints.SetValue(index++, gp_Pnt(end->x(), end->y(), end->z())); if (type == BEZIER) { Handle(Geom_BezierCurve) Bez = new Geom_BezierCurve(ctrlPoints); if (occv1 && occv2) - occEdge = BRepBuilderAPI_MakeEdge(Bez,occv1->getShape(),occv2->getShape()).Edge(); + occEdge = BRepBuilderAPI_MakeEdge(Bez,occv1->getShape(),occv2->getShape()).Edge(); else occEdge = BRepBuilderAPI_MakeEdge(Bez).Edge(); - } + } return gm->_occ_internals->addEdgeToModel(gm, occEdge); } GEdge *OCCFactory::addNURBS(GModel *gm, GVertex *start, GVertex *end, - std::vector<std::vector<double> > points, + std::vector<std::vector<double> > points, std::vector<double> knots, - std::vector<double> weights, + std::vector<double> weights, std::vector<int> mult) { - try{ + try{ if (!gm->_occ_internals) gm->_occ_internals = new OCC_Internals; - + OCCVertex *occv1 = dynamic_cast<OCCVertex*>(start); OCCVertex *occv2 = dynamic_cast<OCCVertex*>(end); - + int nbControlPoints = points.size() + 2; TColgp_Array1OfPnt ctrlPoints(1, nbControlPoints); - + TColStd_Array1OfReal _knots(1, knots.size()); TColStd_Array1OfReal _weights(1, weights.size()); TColStd_Array1OfInteger _mult(1, mult.size()); - + for (unsigned i = 0; i < knots.size(); i++) { _knots.SetValue(i+1, knots[i]); } @@ -347,27 +400,27 @@ GEdge *OCCFactory::addNURBS(GModel *gm, GVertex *start, GVertex *end, } int totKnots = 0; for (unsigned i = 0; i < mult.size(); i++) { - _mult.SetValue(i+1, mult[i]); + _mult.SetValue(i+1, mult[i]); totKnots += mult[i]; } const int degree = totKnots - nbControlPoints - 1; Msg::Debug("creation of a nurbs of degree %d with %d control points", degree,nbControlPoints); - + int index = 1; - ctrlPoints.SetValue(index++, gp_Pnt(start->x(), start->y(), start->z())); + ctrlPoints.SetValue(index++, gp_Pnt(start->x(), start->y(), start->z())); for (unsigned i = 0; i < points.size(); i++) { gp_Pnt aP(points[i][0],points[i][1],points[i][2]); ctrlPoints.SetValue(index++, aP); } - ctrlPoints.SetValue(index++, gp_Pnt(end->x(), end->y(), end->z())); + ctrlPoints.SetValue(index++, gp_Pnt(end->x(), end->y(), end->z())); Handle(Geom_BSplineCurve) NURBS = new Geom_BSplineCurve (ctrlPoints, _weights, _knots, _mult, degree, false); TopoDS_Edge occEdge; if (occv1 && occv2) occEdge = BRepBuilderAPI_MakeEdge(NURBS, occv1->getShape(), - occv2->getShape()).Edge(); + occv2->getShape()).Edge(); else occEdge = BRepBuilderAPI_MakeEdge(NURBS).Edge(); return gm->_occ_internals->addEdgeToModel(gm, occEdge); @@ -379,20 +432,20 @@ GEdge *OCCFactory::addNURBS(GModel *gm, GVertex *start, GVertex *end, } /* -GEdge *OCCFactory::addBezierSurface(GModel *gm, +GEdge *OCCFactory::addBezierSurface(GModel *gm, std::vector<GEdge *> & wires, // four edges indeed std::vector<std::vector<double> > points) { TColgp_Array2OfPnt ctrlPoints(1, nbControlPoints + 2); int index = 1; - ctrlPoints.SetValue(index++, gp_Pnt(start->x(), start->y(), start->z())); + ctrlPoints.SetValue(index++, gp_Pnt(start->x(), start->y(), start->z())); for (int i = 0; i < nbControlPoints; i++) { gp_Pnt aP(points[i][0],points[i][1],points[i][2]); ctrlPoints.SetValue(index++, aP); } - - + + BRepBuilderAPI_MakeFace aGenerator (aBezierSurface); BRepBuilderAPI_MakeWire wire_maker; for (unsigned j = 0; j < wires.size(); j++) { @@ -410,7 +463,7 @@ GEdge *OCCFactory::addBezierSurface(GModel *gm, } */ GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, - std::vector<double> p1, + std::vector<double> p1, std::vector<double> p2, double angle) { if (!gm->_occ_internals) @@ -425,7 +478,7 @@ GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, gp_Dir direction(x2 - x1, y2 - y1, z2 - z1); gp_Ax1 axisOfRevolution(gp_Pnt(x1, y1, z1), direction); - BRepPrimAPI_MakeRevol MR(*(TopoDS_Shape*)base->getNativePtr(), + BRepPrimAPI_MakeRevol MR(*(TopoDS_Shape*)base->getNativePtr(), axisOfRevolution, angle, Standard_False); GEntity *ret = 0; if (base->cast2Vertex()){ @@ -459,7 +512,7 @@ GEntity *OCCFactory::extrude(GModel *gm, GEntity* base, gp_Vec direction(gp_Pnt(x1, y1, z1), gp_Pnt(x2, y2, z2)); gp_Ax1 axisOfRevolution(gp_Pnt(x1, y1, z1), direction); - BRepPrimAPI_MakePrism MP(*(TopoDS_Shape*)base->getNativePtr(), direction, + BRepPrimAPI_MakePrism MP(*(TopoDS_Shape*)base->getNativePtr(), direction, Standard_False); GEntity *ret = 0; if (base->cast2Vertex()){ @@ -468,11 +521,11 @@ GEntity *OCCFactory::extrude(GModel *gm, GEntity* base, } if (base->cast2Edge()){ TopoDS_Face result = TopoDS::Face(MP.Shape()); - ret = gm->_occ_internals->addFaceToModel(gm, result); + ret = gm->_occ_internals->addFaceToModel(gm, result); } if (base->cast2Face()){ TopoDS_Solid result = TopoDS::Solid(MP.Shape()); - ret = gm->_occ_internals->addRegionToModel(gm, result); + ret = gm->_occ_internals->addRegionToModel(gm, result); } return ret; } @@ -482,12 +535,12 @@ GEntity *OCCFactory::addSphere(GModel *gm, double xc, double yc, double zc, doub if (!gm->_occ_internals) gm->_occ_internals = new OCC_Internals; - gp_Pnt aP(xc, yc, zc); + gp_Pnt aP(xc, yc, zc); TopoDS_Shape shape = BRepPrimAPI_MakeSphere(aP, radius).Shape(); gm->_occ_internals->buildShapeFromLists(shape); gm->destroy(); gm->_occ_internals->buildLists(); - gm->_occ_internals->buildGModel(gm); + gm->_occ_internals->buildGModel(gm); return getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); } @@ -511,7 +564,7 @@ GEntity *OCCFactory::addCylinder(GModel *gm, std::vector<double> p1, const double z2 = p2[2]; gp_Pnt aP(x1, y1, z1); - const double H = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + + const double H = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)); gp_Vec aV((x2 - x1) / H, (y2 - y1) / H, (z2 - z1) / H); gp_Ax2 anAxes(aP, aV); @@ -529,8 +582,8 @@ GEntity *OCCFactory::addCylinder(GModel *gm, std::vector<double> p1, return getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); } -GEntity *OCCFactory::addTorus(GModel *gm, std::vector<double> p1, - std::vector<double> p2, double radius1, +GEntity *OCCFactory::addTorus(GModel *gm, std::vector<double> p1, + std::vector<double> p2, double radius1, double radius2) { if (!gm->_occ_internals) @@ -544,7 +597,7 @@ GEntity *OCCFactory::addTorus(GModel *gm, std::vector<double> p1, const double z2 = p2[2]; gp_Pnt aP(x1, y1, z1); const double H = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + - (z2 - z1) * (z2 - z1)); + (z2 - z1) * (z2 - z1)); gp_Vec aV((x2 - x1) / H, (y2 - y1) / H, (z2 - z1) / H); gp_Ax2 anAxes(aP, aV); BRepPrimAPI_MakeTorus MC(anAxes, radius1, radius2); @@ -561,8 +614,8 @@ GEntity *OCCFactory::addTorus(GModel *gm, std::vector<double> p1, return getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); } -GEntity *OCCFactory::addCone(GModel *gm, std::vector<double> p1, - std::vector<double> p2, double radius1, +GEntity *OCCFactory::addCone(GModel *gm, std::vector<double> p1, + std::vector<double> p2, double radius1, double radius2) { if (!gm->_occ_internals) @@ -577,7 +630,7 @@ GEntity *OCCFactory::addCone(GModel *gm, std::vector<double> p1, gp_Pnt aP(x1, y1, z1); const double H = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + - (z2 - z1) * (z2 - z1)); + (z2 - z1) * (z2 - z1)); gp_Vec aV((x2 - x1) / H, (y2 - y1) / H, (z2 - z1) / H); gp_Ax2 anAxes(aP, aV); BRepPrimAPI_MakeCone MC(anAxes, radius1, radius2, H); @@ -590,11 +643,11 @@ GEntity *OCCFactory::addCone(GModel *gm, std::vector<double> p1, gm->_occ_internals->buildShapeFromLists(shape); gm->destroy(); gm->_occ_internals->buildLists(); - gm->_occ_internals->buildGModel(gm); + gm->_occ_internals->buildGModel(gm); return getOCCRegionByNativePtr(gm,TopoDS::Solid(shape)); } -GEntity *OCCFactory::addBlock(GModel *gm, std::vector<double> p1, +GEntity *OCCFactory::addBlock(GModel *gm, std::vector<double> p1, std::vector<double> p2) { if (!gm->_occ_internals) @@ -619,12 +672,12 @@ GEntity *OCCFactory::addBlock(GModel *gm, std::vector<double> p1, GModel *OCCFactory::computeBooleanUnion(GModel* obj, GModel* tool, int createNewModel) { - try{ + try{ OCC_Internals *occ_obj = obj->getOCCInternals(); OCC_Internals *occ_tool = tool->getOCCInternals(); - + if (!occ_obj || !occ_tool) return NULL; - + if (createNewModel){ GModel *temp = new GModel; temp->_occ_internals = new OCC_Internals; @@ -640,19 +693,19 @@ GModel *OCCFactory::computeBooleanUnion(GModel* obj, GModel* tool, catch(Standard_Failure &err){ Msg::Error("%s", err.GetMessageString()); } - + return obj; } -GModel *OCCFactory::computeBooleanDifference(GModel* obj, GModel* tool, +GModel *OCCFactory::computeBooleanDifference(GModel* obj, GModel* tool, int createNewModel) { try{ OCC_Internals *occ_obj = obj->getOCCInternals(); OCC_Internals *occ_tool = tool->getOCCInternals(); - + if (!occ_obj || !occ_tool) return NULL; - + if (createNewModel){ GModel *temp = new GModel; temp->_occ_internals = new OCC_Internals; @@ -677,9 +730,9 @@ GModel *OCCFactory::computeBooleanIntersection(GModel* obj, GModel* tool, try{ OCC_Internals *occ_obj = obj->getOCCInternals(); OCC_Internals *occ_tool = tool->getOCCInternals(); - + if (!occ_obj || !occ_tool) return NULL; - + if (createNewModel){ GModel *temp = new GModel; temp->_occ_internals = new OCC_Internals; @@ -712,7 +765,7 @@ void OCCFactory::fillet(GModel *gm, std::vector<int> edges, double radius) gm->_occ_internals->fillet(edgesToFillet, radius); gm->destroy(); gm->_occ_internals->buildLists(); - gm->_occ_internals->buildGModel(gm); + gm->_occ_internals->buildGModel(gm); } catch(Standard_Failure &err){ Msg::Error("%s", err.GetMessageString()); @@ -730,18 +783,18 @@ void OCCFactory::translate(GModel *gm, std::vector<double> dx, int addToTheModel else gm->_occ_internals->buildShapeFromLists(temp); gm->destroy(); gm->_occ_internals->buildLists(); - gm->_occ_internals->buildGModel(gm); + gm->_occ_internals->buildGModel(gm); } void OCCFactory::rotate(GModel *gm, std::vector<double> p1, std::vector<double> p2, double angle, int addToTheModel) { - const double x1 = p1[0]; - const double y1 = p1[1]; - const double z1 = p1[2]; - const double x2 = p2[0]; - const double y2 = p2[1]; - const double z2 = p2[2]; + const double x1 = p1[0]; + const double y1 = p1[1]; + const double z1 = p1[2]; + const double x2 = p2[0]; + const double y2 = p2[1]; + const double z2 = p2[2]; if (!gm->_occ_internals) gm->_occ_internals = new OCC_Internals; @@ -758,10 +811,10 @@ void OCCFactory::rotate(GModel *gm, std::vector<double> p1, std::vector<double> else gm->_occ_internals->buildShapeFromLists(temp); gm->destroy(); gm->_occ_internals->buildLists(); - gm->_occ_internals->buildGModel(gm); + gm->_occ_internals->buildGModel(gm); } -std::vector<GFace *> OCCFactory::addRuledFaces(GModel *gm, +std::vector<GFace *> OCCFactory::addRuledFaces(GModel *gm, std::vector< std::vector<GEdge *> > wires) { std::vector<GFace*> faces; @@ -780,11 +833,11 @@ std::vector<GFace *> OCCFactory::addRuledFaces(GModel *gm, } aGenerator.AddWire (wire_maker.Wire()); } - - aGenerator.CheckCompatibility (Standard_False); + + aGenerator.CheckCompatibility (Standard_False); aGenerator.Build(); - + TopoDS_Shape aResult = aGenerator.Shape(); TopExp_Explorer exp2; @@ -796,7 +849,7 @@ std::vector<GFace *> OCCFactory::addRuledFaces(GModel *gm, return faces; } -GFace *OCCFactory::addFace(GModel *gm, std::vector<GEdge *> edges, +GFace *OCCFactory::addFace(GModel *gm, std::vector<GEdge *> edges, std::vector< std::vector<double > > points) { BRepOffsetAPI_MakeFilling aGenerator; @@ -814,7 +867,7 @@ GFace *OCCFactory::addFace(GModel *gm, std::vector<GEdge *> edges, } aGenerator.Build(); - + TopoDS_Shape aResult = aGenerator.Shape(); return gm->_occ_internals->addFaceToModel(gm, TopoDS::Face(aResult)); } @@ -837,7 +890,7 @@ GFace *OCCFactory::addPlanarFace(GModel *gm, std::vector< std::vector<GEdge *> > for ( ; it != verts.end(); ++it){ points.push_back(SPoint3((*it)->x(), (*it)->y(), (*it)->z())); } - + mean_plane meanPlane; computeMeanPlane(points, meanPlane); @@ -876,7 +929,7 @@ GEntity *OCCFactory::addPipe(GModel *gm, GEntity *base, std::vector<GEdge *> wir } } TopoDS_Wire myWire = wire_maker.Wire(); - + GEntity *ret = 0; if (base->cast2Vertex()){ OCCVertex *occv = dynamic_cast<OCCVertex*>(base); diff --git a/Geo/GModelFactory.h b/Geo/GModelFactory.h index 0d4af3eeb0b92d23d8120e37a09c10a16f6ae6f3..1e9f363141a46968f4c7bb3f0cd1926a3a26e940 100644 --- a/Geo/GModelFactory.h +++ b/Geo/GModelFactory.h @@ -27,31 +27,35 @@ class GModelFactory { // brep primitives enum arcCreationMethod {THREE_POINTS=1, CENTER_START_END=2}; enum splineType {BEZIER=1, BSPLINE=2}; - virtual GVertex *addVertex(GModel *gm, double x, double y, double z, + virtual GVertex *addVertex(GModel *gm, double x, double y, double z, double lc) = 0; virtual GEdge *addLine(GModel *, GVertex *v1, GVertex *v2) = 0; virtual GFace *addPlanarFace(GModel *gm, std::vector<std::vector<GEdge *> > edges) = 0; virtual GRegion*addVolume(GModel *gm, std::vector<std::vector<GFace *> > faces) = 0; - + virtual GEdge *addCircleArc(GModel *gm, GVertex *start, GVertex *center, GVertex *end) + { + Msg::Error("addCircleArc not implemented yet"); + return 0; + } virtual GEdge *addCircleArc(GModel *gm, const arcCreationMethod &method, - GVertex *start, GVertex *end, + GVertex *start, GVertex *end, const SPoint3 &aPoint) { Msg::Error("addCircleArc not implemented yet"); return 0; } virtual GEdge *addSpline(GModel *gm,const splineType &type, - GVertex *start, - GVertex *end, + GVertex *start, + GVertex *end, std::vector<std::vector<double> > controlPoints) { Msg::Error("addSpline not implemented yet"); return 0; } virtual GEdge *addNURBS(GModel *gm, GVertex *start, GVertex *end, - std::vector<std::vector<double> > controlPoints, + std::vector<std::vector<double> > controlPoints, std::vector<double> knots, - std::vector<double> weights, + std::vector<double> weights, std::vector<int> multiplicity) { Msg::Error("addNURBS not implemented yet"); @@ -60,13 +64,13 @@ class GModelFactory { // this one tries to build a model face with one single list of // faces. If boundaries are co-planar, then it's a plane, otherwise, // we tru ruled, sweep or other kind of surfaces - virtual std::vector<GFace *> addRuledFaces(GModel *gm, + virtual std::vector<GFace *> addRuledFaces(GModel *gm, std::vector<std::vector<GEdge *> > edges) { Msg::Error("addRuledFaces not implemented yet"); return std::vector<GFace*>(); } - virtual GFace *addFace(GModel *gm, std::vector<GEdge *> edges, + virtual GFace *addFace(GModel *gm, std::vector<GEdge *> edges, std::vector< std::vector<double > > points) { Msg::Error("addFace not implemented yet"); @@ -74,13 +78,13 @@ class GModelFactory { } // sweep stuff - virtual GEntity *revolve(GModel *gm, GEntity*, std::vector<double> p1, + virtual GEntity *revolve(GModel *gm, GEntity*, std::vector<double> p1, std::vector<double> p2, double angle) { Msg::Error("revolve not implemented yet"); return 0; } - virtual GEntity *extrude(GModel *gm, GEntity*, std::vector<double> p1, + virtual GEntity *extrude(GModel *gm, GEntity*, std::vector<double> p1, std::vector<double> p2) { Msg::Error("extrude not implemented yet"); @@ -93,20 +97,20 @@ class GModelFactory { } // solid primitives - virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz, + virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz, double radius) { Msg::Error("addSphere not implemented yet"); return 0; } - virtual GEntity *addCylinder(GModel *gm, std::vector<double> p1, + virtual GEntity *addCylinder(GModel *gm, std::vector<double> p1, std::vector<double> p2, double radius) { Msg::Error("addCylinder not implemented yet"); return 0; } - virtual GEntity *addTorus(GModel *gm, std::vector<double> p1, - std::vector<double> p2, double radius1, + virtual GEntity *addTorus(GModel *gm, std::vector<double> p1, + std::vector<double> p2, double radius1, double radius2) { Msg::Error("addTorus not implemented yet"); @@ -156,7 +160,7 @@ class GModelFactory { Msg::Error("computeBooleanIntersection not implemented yet"); return 0; } - virtual GModel *computeBooleanDifference(GModel *obj, GModel*tool, + virtual GModel *computeBooleanDifference(GModel *obj, GModel*tool, int createNewModel) { Msg::Error("computeBooleanDifference not implemented yet"); @@ -170,7 +174,9 @@ class GeoFactory : public GModelFactory { GVertex *addVertex(GModel *gm,double x, double y, double z, double lc); GEdge *addLine(GModel *gm,GVertex *v1, GVertex *v2); GFace *addPlanarFace(GModel *gm, std::vector<std::vector<GEdge *> > edges); - GRegion *addVolume(GModel *gm, std::vector<std::vector<GFace *> > faces); + GRegion *addVolume(GModel *gm, std::vector<std::vector<GFace *> > faces); + GEdge *addCircleArc(GModel *gm,GVertex *begin, GVertex *center, GVertex *end); + std::vector<GFace *> addRuledFaces(GModel *gm, std::vector<std::vector<GEdge *> > edges); }; @@ -182,35 +188,35 @@ class OCCFactory : public GModelFactory { GVertex *addVertex(GModel *gm,double x, double y, double z, double lc); GEdge *addLine(GModel *gm,GVertex *v1, GVertex *v2); GEdge *addCircleArc(GModel *gm,const arcCreationMethod &method, - GVertex *start, GVertex *end, + GVertex *start, GVertex *end, const SPoint3 &aPoint); GEdge *addSpline(GModel *gm,const splineType &type, - GVertex *start, GVertex *end, + GVertex *start, GVertex *end, std::vector<std::vector<double> > controlPoints); GEdge *addNURBS(GModel *gm, GVertex *start, GVertex *end, - std::vector<std::vector<double> > controlPoints, + std::vector<std::vector<double> > controlPoints, std::vector<double> knots, - std::vector<double> weights, + std::vector<double> weights, std::vector<int> multiplicity); - GEntity *revolve(GModel *gm, GEntity*,std::vector<double> p1, + GEntity *revolve(GModel *gm, GEntity*,std::vector<double> p1, std::vector<double> p2, double angle); GEntity *extrude(GModel *gm, GEntity*,std::vector<double> p1, std::vector<double> p2); GEntity *addPipe(GModel *gm, GEntity *base, std::vector<GEdge *> wire); - GEntity *addSphere(GModel *gm,double cx, double cy, double cz, double radius); - GEntity *addCylinder(GModel *gm,std::vector<double> p1, std::vector<double> p2, - double radius); - std::vector<GFace *> addRuledFaces(GModel *gm, std::vector<std::vector<GEdge *> > edges); + GEntity *addSphere(GModel *gm,double cx, double cy, double cz, double radius); + GEntity *addCylinder(GModel *gm,std::vector<double> p1, std::vector<double> p2, + double radius); + std::vector<GFace *> addRuledFaces(GModel *gm, std::vector<std::vector<GEdge *> > edges); GFace *addFace(GModel *gm, std::vector<GEdge *> edges, std::vector< std::vector<double > > points); GFace *addPlanarFace(GModel *gm, std::vector<std::vector<GEdge *> > edges); - GRegion *addVolume(GModel *gm, std::vector<std::vector<GFace *> > faces); - GEntity *addTorus(GModel *gm,std::vector<double> p1, std::vector<double> p2, - double radius1, double radius2); - GEntity *addBlock(GModel *gm,std::vector<double> p1, std::vector<double> p2); + GRegion *addVolume(GModel *gm, std::vector<std::vector<GFace *> > faces); + GEntity *addTorus(GModel *gm,std::vector<double> p1, std::vector<double> p2, + double radius1, double radius2); + GEntity *addBlock(GModel *gm,std::vector<double> p1, std::vector<double> p2); GEntity *addCone(GModel *gm,std::vector<double> p1, std::vector<double> p2, - double radius1, double radius2); + double radius1, double radius2); void translate(GModel *gm, std::vector<double> dx, int addToTheModel); void rotate(GModel *gm, std::vector<double> p1,std::vector<double> p2, double angle, int addToTheModel); diff --git a/Geo/Geo.cpp b/Geo/Geo.cpp index 607b60371662152e0c3c5fa654cda96294545277..3f91a450d35a96accbe913599b8275287e9fb7ea 100644 --- a/Geo/Geo.cpp +++ b/Geo/Geo.cpp @@ -3688,3 +3688,31 @@ void GEO_Internals::reset_physicals() List_Action(PhysicalGroups, Free_PhysicalGroup); List_Reset(PhysicalGroups); } + +int select_contour(int type, int num, List_T * List) +{ + int k = 0; + + switch (type) { + case ENT_LINE: + k = allEdgesLinked(num, List); + for(int i = 0; i < List_Nbr(List); i++) { + int ip; + List_Read(List, i, &ip); + GEdge *ge = GModel::current()->getEdgeByTag(abs(ip)); + if(ge) ge->setSelection(1); + } + break; + case ENT_SURFACE: + k = allFacesLinked(num, List); + for(int i = 0; i < List_Nbr(List); i++) { + int ip; + List_Read(List, i, &ip); + GFace *gf = GModel::current()->getFaceByTag(abs(ip)); + if(gf) gf->setSelection(1); + } + break; + } + + return k; +} diff --git a/Geo/Geo.h b/Geo/Geo.h index 3a362afda809b19828b44fbe75a2b6a2d3ba0040..10aa0f74ff47dda8f919f79337d9cc6225823a5b 100644 --- a/Geo/Geo.h +++ b/Geo/Geo.h @@ -14,6 +14,7 @@ #include "TreeUtils.h" #include "SPoint2.h" #include "ExtrudeParams.h" +#include "findLinks.h" #define MSH_POINT 100 #define MSH_POINT_BND_LAYER 101 @@ -314,5 +315,6 @@ void setSurfaceGeneratrices(Surface *s, List_T *loops); void setVolumeSurfaces(Volume *v, List_T *loops); void setSurfaceEmbeddedPoints(Surface *s, List_T *points); void setSurfaceEmbeddedCurves(Surface *s, List_T *curves); +int select_contour(int type, int num, List_T * List); #endif diff --git a/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v1.java b/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v1.java index fa4c26e5d77f9302836bfaa4f70214ef4643d6f6..0c2abbc260bdabc9f4abd0c3962fb947aff6fa65 100755 --- a/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v1.java +++ b/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v1.java @@ -1072,17 +1072,26 @@ public class EssaiGmsh_v1 { f15 = gFact.addPlanarFace(m, edges15); f16 = gFact.addPlanarFace(m, edges16); f17 = gFact.addPlanarFace(m, edges17); - f18 = gFact.addIncurvedFace(m, edges18); + final FaceVector ruledFace1=gFact.addRuledFaces(m, edges18); + f18 = ruledFace1.get(0); // creation of faces of curved tetrahedron - f19 = gFact.addIncurvedFace(m, edges19); - f20 = gFact.addIncurvedFace(m, edges20); - f21 = gFact.addIncurvedFace(m, edges21); - f22 = gFact.addIncurvedFace(m, edges22); - f23 = gFact.addIncurvedFace(m, edges23); - f24 = gFact.addIncurvedFace(m, edges24); - f25 = gFact.addIncurvedFace(m, edges25); - f26 = gFact.addIncurvedFace(m, edges26); + final FaceVector ruledFace2=gFact.addRuledFaces(m, edges19); + final FaceVector ruledFace3=gFact.addRuledFaces(m, edges20); + final FaceVector ruledFace4=gFact.addRuledFaces(m, edges21); + final FaceVector ruledFace5=gFact.addRuledFaces(m, edges22); + final FaceVector ruledFace6=gFact.addRuledFaces(m, edges23); + final FaceVector ruledFace7=gFact.addRuledFaces(m, edges24); + final FaceVector ruledFace8=gFact.addRuledFaces(m, edges25); + final FaceVector ruledFace9=gFact.addRuledFaces(m, edges26); + f19 = ruledFace2.get(0); + f20 = ruledFace3.get(0); + f21 = ruledFace4.get(0); + f22 = ruledFace5.get(0); + f23 = ruledFace6.get(0); + f24 = ruledFace7.get(0); + f25 = ruledFace8.get(0); + f26 = ruledFace9.get(0); // //definition of physical for faces