diff --git a/Fltk/contextWindow.cpp b/Fltk/contextWindow.cpp index b59dacccdf8d71ab71c5a1cc214aa9acb826e11f..6c4c89501d1464088695421b3c1ed8884476d267 100644 --- a/Fltk/contextWindow.cpp +++ b/Fltk/contextWindow.cpp @@ -105,6 +105,36 @@ static void elementary_add_point_cb(Fl_Widget *w, void *data) drawContext::global()->draw(); } +static void draw_circle(void *context) +{ + if(!GModel::current()->getOCCInternals()) GModel::current()->createOCCInternals(); + double xc, yc, zc, r, angle1, angle2; + if(!getval(FlGui::instance()->elementaryContext->input[8]->value(), xc)) return; + if(!getval(FlGui::instance()->elementaryContext->input[9]->value(), yc)) return; + if(!getval(FlGui::instance()->elementaryContext->input[10]->value(), zc)) return; + if(!getval(FlGui::instance()->elementaryContext->input[11]->value(), r)) return; + if(!getval(FlGui::instance()->elementaryContext->input[12]->value(), angle1)) return; + if(!getval(FlGui::instance()->elementaryContext->input[13]->value(), angle2)) return; + + if(angle2 <= angle1) return; + glColor4ubv((GLubyte *) & CTX::instance()->color.geom.highlight[0]); + glBegin(GL_LINE_STRIP); + const int N = 30; + for(int i = 0; i < N; i++) { + double t = angle1 + (double)i / (double)(N - 1) * (angle2 - angle1); + double x = xc + r * cos(t); + double y = yc + r * sin(t); + double z = zc; + glVertex3d(x, y, z); + } + glEnd(); +} + +static void elementary_draw_circle_cb(Fl_Widget *w, void *data) +{ + drawContext::setDrawGeomTransientFunction(draw_circle); +} + static void elementary_add_circle_cb(Fl_Widget *w, void *data) { add_circle(GModel::current()->getFileName(), @@ -120,6 +150,36 @@ static void elementary_add_circle_cb(Fl_Widget *w, void *data) drawContext::global()->draw(); } +static void draw_ellipse(void *context) +{ + if(!GModel::current()->getOCCInternals()) GModel::current()->createOCCInternals(); + double xc, yc, zc, rx, ry, angle1, angle2; + if(!getval(FlGui::instance()->elementaryContext->input[14]->value(), xc)) return; + if(!getval(FlGui::instance()->elementaryContext->input[15]->value(), yc)) return; + if(!getval(FlGui::instance()->elementaryContext->input[16]->value(), zc)) return; + if(!getval(FlGui::instance()->elementaryContext->input[17]->value(), rx)) return; + if(!getval(FlGui::instance()->elementaryContext->input[18]->value(), ry)) return; + if(!getval(FlGui::instance()->elementaryContext->input[19]->value(), angle1)) return; + if(!getval(FlGui::instance()->elementaryContext->input[20]->value(), angle2)) return; + if(angle2 <= angle1) return; + glColor4ubv((GLubyte *) & CTX::instance()->color.geom.highlight[0]); + glBegin(GL_LINE_STRIP); + const int N = 30; + for(int i = 0; i < N; i++) { + double t = angle1 + (double)i / (double)(N - 1) * (angle2 - angle1); + double x = xc + rx * cos(t); + double y = yc + ry * sin(t); + double z = zc; + glVertex3d(x, y, z); + } + glEnd(); +} + +static void elementary_draw_ellipse_cb(Fl_Widget *w, void *data) +{ + drawContext::setDrawGeomTransientFunction(draw_ellipse); +} + static void elementary_add_ellipse_cb(Fl_Widget *w, void *data) { add_ellipse(GModel::current()->getFileName(), @@ -550,8 +610,11 @@ elementaryContextWindow::elementaryContextWindow(int deltaFontSize) input[12]->value("0"); input[13] = new Fl_Input(2 * WB, 2 * WB + 6 * BH, IW, BH, "Angle 2"); input[13]->value("2*Pi"); - for(int i = 8; i < 14; i++) + for(int i = 8; i < 14; i++){ input[i]->align(FL_ALIGN_RIGHT); + input[i]->callback(elementary_draw_circle_cb); + input[i]->when(FL_WHEN_CHANGED); + } { Fl_Return_Button *o = new Fl_Return_Button (width - BB - 2 * WB, height - 3 * WB - 2 * BH, BB, BH, "Add"); @@ -571,14 +634,17 @@ elementaryContextWindow::elementaryContextWindow(int deltaFontSize) input[16]->value("0"); input[17] = new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "Radius X"); input[17]->value("1"); - input[18] = new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "Radius Y"); + input[18] = new Fl_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "Radius Y"); input[18]->value("0.5"); - input[19] = new Fl_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "Angle 1"); + input[19] = new Fl_Input(2 * WB, 2 * WB + 6 * BH, IW, BH, "Angle 1"); input[19]->value("0"); - input[20] = new Fl_Input(2 * WB, 2 * WB + 6 * BH, IW, BH, "Angle 2"); + input[20] = new Fl_Input(2 * WB, 2 * WB + 7 * BH, IW, BH, "Angle 2"); input[20]->value("2*Pi"); - for(int i = 14; i < 21; i++) + for(int i = 14; i < 21; i++){ input[i]->align(FL_ALIGN_RIGHT); + input[i]->callback(elementary_draw_ellipse_cb); + input[i]->when(FL_WHEN_CHANGED); + } { Fl_Return_Button *o = new Fl_Return_Button (width - BB - 2 * WB, height - 3 * WB - 2 * BH, BB, BH, "Add"); diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp index d419d8a7edf04db3cd04196800521be426d3dadb..0dcead54a47a8c454aa84d2ea13c68e8fd6bda68 100644 --- a/Geo/GModelIO_OCC.cpp +++ b/Geo/GModelIO_OCC.cpp @@ -743,13 +743,17 @@ bool OCC_Internals::addCircle(int &tag, double x, double y, double z, double r, return true; } -bool OCC_Internals::addEllipse(int &tag, double x, double y, double z, double r1, - double r2, double angle1, double angle2) +bool OCC_Internals::addEllipse(int &tag, double x, double y, double z, double rx, + double ry, double angle1, double angle2) { if(tag >= 0 && _tagEdge.IsBound(tag)){ Msg::Error("OpenCASCADE edge with tag %d already exists", tag); return false; } + if(ry > rx){ + Msg::Error("Major radius rx should be larger than minor radius ry"); + return false; + } TopoDS_Edge result; try{ @@ -757,7 +761,7 @@ bool OCC_Internals::addEllipse(int &tag, double x, double y, double z, double r1 gp_Dir x_dir(1., 0., 0.); gp_Pnt center(x, y, z); gp_Ax2 axis(center, N_dir, x_dir); - gp_Elips elips(axis, r1, r2); + gp_Elips elips(axis, rx, ry); if(angle1 == 0 && angle2 == 2 * M_PI){ result = BRepBuilderAPI_MakeEdge(elips); }