Skip to content
Snippets Groups Projects
Commit ff1de0f8 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

occ ellipse arc

parent 5ab04e2e
Branches
Tags
No related merge requests found
......@@ -37,9 +37,11 @@
#include <BRepOffsetAPI_ThruSections.hxx>
#include <BRepOffsetAPI_MakeThickSolid.hxx>
#include <gce_MakeCirc.hxx>
#include <gce_MakeElips.hxx>
#include <gce_MakePln.hxx>
#include <ElCLib.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
......@@ -301,7 +303,8 @@ void OCC_Internals::addLine(int tag, int startTag, int endTag)
bind(result, tag);
}
void OCC_Internals::addCircleArc(int tag, int startTag, int centerTag, int endTag)
void OCC_Internals::_addArc(int tag, int startTag, int centerTag, int endTag,
int mode)
{
if(tag > 0 && _tagEdge.IsBound(tag)){
Msg::Error("OpenCASCADE edge with tag %d already exists", tag);
......@@ -328,17 +331,36 @@ void OCC_Internals::addCircleArc(int tag, int startTag, int centerTag, int endTa
gp_Pnt aP1 = BRep_Tool::Pnt(start);
gp_Pnt aP2 = BRep_Tool::Pnt(center);
gp_Pnt aP3 = BRep_Tool::Pnt(end);
Handle(Geom_TrimmedCurve) arc;
if(mode == 0){ // circle
Standard_Real Radius = aP1.Distance(aP2);
gce_MakeCirc MC(aP2, gce_MakePln(aP1, aP2, aP3).Value(), Radius);
if(!MC.IsDone()){
Msg::Error("Could not build circle");
return;
}
const gp_Circ &Circ = MC.Value();
Standard_Real Alpha1 = ElCLib::Parameter(Circ, aP1);
Standard_Real Alpha2 = ElCLib::Parameter(Circ, aP3);
Handle(Geom_Circle) C = new Geom_Circle(Circ);
Handle(Geom_TrimmedCurve) arc = new Geom_TrimmedCurve(C, Alpha1, Alpha2, false);
arc = new Geom_TrimmedCurve(C, Alpha1, Alpha2, false);
}
else{
gce_MakeElips ME(aP1, aP3, aP2);
if(!ME.IsDone()){
Msg::Error("Could not build ellipse");
return;
}
const gp_Elips &Elips = ME.Value();
Standard_Real Alpha1 = ElCLib::Parameter(Elips, aP1);
Standard_Real Alpha2 = ElCLib::Parameter(Elips, aP3);
Handle(Geom_Ellipse) E = new Geom_Ellipse(Elips);
arc = new Geom_TrimmedCurve(E, Alpha1, Alpha2, true);
}
BRepBuilderAPI_MakeEdge e(arc, start, end);
e.Build();
if(!e.IsDone()){
Msg::Error("Could not create circle arc");
Msg::Error("Could not create %s arc", mode ? "ellipse" : "circle");
return;
}
result = e.Edge();
......@@ -351,6 +373,16 @@ void OCC_Internals::addCircleArc(int tag, int startTag, int centerTag, int endTa
bind(result, tag);
}
void OCC_Internals::addCircleArc(int tag, int startTag, int centerTag, int endTag)
{
_addArc(tag, startTag, centerTag, endTag, 0);
}
void OCC_Internals::addEllipseArc(int tag, int startTag, int centerTag, int endTag)
{
_addArc(tag, startTag, centerTag, endTag, 1);
}
void OCC_Internals::_addSpline(int tag, std::vector<int> vertexTags, int mode)
{
if(tag > 0 && _tagEdge.IsBound(tag)){
......
......@@ -46,6 +46,9 @@ class OCC_Internals {
// apply a geometrical transformation
void _transform(std::vector<int> inTags[4], BRepBuilderAPI_Transform &tfo);
// add circle or ellipse arc
void _addArc(int tag, int startTag, int centerTag, int endTag, int mode);
// add bezier or bspline
void _addSpline(int tag, std::vector<int> vertexTags, int mode);
......@@ -97,6 +100,7 @@ class OCC_Internals {
void addVertex(int tag, double x, double y, double z);
void addLine(int tag, int startTag, int endTag);
void addCircleArc(int tag, int startTag, int centerTag, int endTag);
void addEllipseArc(int tag, int startTag, int centerTag, int endTag);
void addBezier(int tag, std::vector<int> vertexTags);
void addBSpline(int tag, std::vector<int> vertexTags);
void addLineLoop(int tag, std::vector<int> edgeTags);
......@@ -221,6 +225,7 @@ public:
void addVertex(int tag, double x, double y, double z){}
void addLine(int tag, int startTag, int endTag){}
void addCircleArc(int tag, int startTag, int centerTag, int endTag){}
void addEllipseArc(int tag, int startTag, int centerTag, int endTag){}
void addBezier(int tag, std::vector<int> vertexTags){};
void addBSpline(int tag, std::vector<int> vertexTags){};
void addLineLoop(int tag, std::vector<int> edgeTags){}
......
This diff is collapsed.
......@@ -1933,6 +1933,19 @@ Shape :
if(FindCurve(num)){
yymsg(0, "Curve %d already exists", num);
}
else{
if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
if(List_Nbr($6) == 3 || List_Nbr($6) == 4){
double start, center, end;
List_Read($6, 0, &start); List_Read($6, 1, &center);
if(List_Nbr($6) == 3)
List_Read($6, 2, &end);
else
List_Read($6, 3, &end);
GModel::current()->getOCCInternals()->addEllipseArc
(num, (int)start, (int)center, (int)end);
}
}
else{
List_T *temp = ListOfDouble2ListOfInt($6);
Curve *c = Create_Curve(num, MSH_SEGM_ELLI, 2, temp, NULL,
......@@ -1953,6 +1966,7 @@ Shape :
}
List_Delete(temp);
}
}
List_Delete($6);
$$.Type = MSH_SEGM_ELLI;
$$.Num = num;
......
......@@ -29,26 +29,29 @@ Line(4) = {2,3};
Point(4) = {2,-2,0}; Point(5) = {2.5,-2,0}; Point(6) = {2,-1.5,0};
Circle(5) = {5,4,6};
Point(7) = {3,-2,0}; Point(8) = {3.1,-1.9,0}; Point(9) = {3.2,-1.7,0};
Point(10) = {3.3,-1.8,0}; Point(11) = {3.4,-2,0}; Point(12) = {3.5,-2.1,0};
BSpline(6) = {7:12};
Point(13) = {4,-2,0}; Point(14) = {4.1,-1.9,0};Point(15) = {4.2,-1.7,0};
Point(16) = {4.3,-1.8,0}; Point(17) = {4.4,-2,0}; Point(18) = {4.5,-2.1,0};
Bezier(7) = {13:18};
Point(19) = {0,-2.7,0}; Point(20) = {0.2,-2.5,0}; Point(21) = {0.5,-2.5,0};
Point(22) = {0.1,-3,0}; Point(23) = {0.5,-3,0};
Line(8) = {19,20};
Line(9) = {20,21};
Bezier(10) = {21,23,22,19};
Line Loop(1) = {8,9,10};
Point(7) = {3,-2,0}; Point(8) = {3.8,-2,0}; Point(9) = {3,-1.5,0};
Ellipse(6) = {8,7,9};
Point(100) = {4,-2,0}; Point(101) = {4.1,-1.9,0}; Point(102) = {4.2,-1.7,0};
Point(103) = {4.3,-1.8,0}; Point(104) = {4.4,-2,0}; Point(105) = {4.5,-2.1,0};
BSpline(7) = {100:105};
Point(106) = {5,-2,0}; Point(107) = {5.1,-1.9,0};Point(108) = {5.2,-1.7,0};
Point(109) = {5.3,-1.8,0}; Point(110) = {5.4,-2,0}; Point(111) = {5.5,-2.1,0};
Bezier(8) = {106:111};
Point(112) = {0,-2.7,0}; Point(113) = {0.2,-2.5,0}; Point(114) = {0.5,-2.5,0};
Point(115) = {0.1,-3,0}; Point(116) = {0.5,-3,0};
Line(9) = {112,113};
Line(10) = {113,114};
Bezier(11) = {114,116,115,112};
Line Loop(1) = {9:11};
Plane Surface(4) = {1};
Point(24) = {1,-2.7,0}; Point(25) = {1.2,-2.5,0.2}; Point(26) = {1.5,-2.5,0};
Point(27) = {1.1,-3,0}; Point(28) = {1.5,-3,0.5};
Line(11) = {24,25};
Line(12) = {25,26};
Bezier(13) = {26,28,27,24};
Line Loop(2) = {11,12,13};
Point(117) = {1,-2.7,0}; Point(118) = {1.2,-2.5,0.2}; Point(119) = {1.5,-2.5,0};
Point(120) = {1.1,-3,0}; Point(121) = {1.5,-3,0.5};
Line(12) = {117,118};
Line(13) = {118,119};
Bezier(14) = {119,121,120,117};
Line Loop(2) = {12,13,14};
Ruled Surface(5) = {2};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment