diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 4f953e58b358d6bc16d6a6130940b1fdf0942669..e7b7f1590a70f5bfdf71cbce0f7a6d2c809d4990 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1461,19 +1461,17 @@ GEdge *GModel::addBezier(GVertex *start, GVertex *end, return 0; } -GEntity *GModel::revolve(GEntity *e, double angle, fullMatrix<double> *axis) +GEntity *GModel::revolve(GEntity *e, std::vector<double> p1, std::vector<double> p2, double angle) { if(_factory) - return _factory->revolve(this, e, (*axis)(0, 0), (*axis)(0, 1), (*axis)(0, 2), - (*axis)(1, 0), (*axis)(1, 1), (*axis)(1, 2), angle); + return _factory->revolve(this, e, p1, p2, angle); return 0; } -GEntity *GModel::extrude(GEntity *e, fullMatrix<double> *axis) +GEntity *GModel::extrude(GEntity *e, std::vector<double> p1, std::vector<double> p2) { if(_factory) - return _factory->extrude(this, e, (*axis)(0, 0), (*axis)(0, 1), (*axis)(0, 2), - (*axis)(1, 0), (*axis)(1, 1), (*axis)(1, 2)); + return _factory->extrude(this, e, p1, p2); return 0; } @@ -1833,13 +1831,11 @@ void GModel::registerBindings(binding *b) cm->setArgNames("x", "y", "z", "v1", "v2", NULL); cm = cb->addMethod("revolve", &GModel::revolve); cm->setDescription("revolve an entity of a given angle. Axis is defined by 2 " - "points " - "in a full Matrix(2,3)"); - cm->setArgNames("entity", "angle", "axis", NULL); + "points"); + cm->setArgNames("entity", "{x1,y1,z1}", "{x2,y2,z2}", "angle", NULL); cm = cb->addMethod("extrude", &GModel::extrude); - cm->setDescription("extrudes an entity. Axis is defined by 2 points in a full " - "Matrix(2,3)"); - cm->setArgNames("entity", "axis", NULL); + cm->setDescription("extrudes an entity. Axis is defined by 2 points"); + cm->setArgNames("entity", "{x1,y1,z1}", "{x2,y2,z2}", NULL); cm = cb->addMethod("addSphere", &GModel::addSphere); cm->setDescription("add a sphere"); cm->setArgNames("xc", "yc", "zc", "radius", NULL); @@ -1871,8 +1867,9 @@ void GModel::registerBindings(binding *b) cm->setArgNames("tool","createNewGModel",NULL); cm = cb->addMethod("glue", &GModel::glue); cm->setDescription("glue the geometric model using geometric tolerance eps"); - cm->setArgNames("eps", NULL); - + cm->setArgNames("eps",NULL); + cm = cb->addMethod("setAsCurrent", &GModel::setAsCurrent); + cm->setDescription("set the model as the current (active) one"); cm = cb->setConstructor<GModel>(); cm->setDescription("Create an empty GModel"); } diff --git a/Geo/GModel.h b/Geo/GModel.h index 9d70d4563ccb04d24cc4c5bc896a1634858d10a8..65d2af4850c21b78b005f1769bcc81e1b8fa13a8 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -133,6 +133,7 @@ class GModel // sets a model to current static int setCurrent(GModel *m); + int setAsCurrent(){ return setCurrent(this); } // find a model by name static GModel *findByName(std::string name); @@ -354,8 +355,8 @@ class GModel GEdge *addCircleArcCenter(double x, double y, double z, GVertex *start, GVertex *end); GEdge *addCircleArc3Points(double x, double y, double z, GVertex *start, GVertex *end); GEdge *addBezier(GVertex *start, GVertex *end, fullMatrix<double> *controlPoints); - GEntity *revolve(GEntity *e, double angle, fullMatrix<double> *axis); - GEntity *extrude(GEntity *e, fullMatrix<double> *axis); + GEntity *revolve(GEntity *e, std::vector<double> p1, std::vector<double> p2, double angle); + GEntity *extrude(GEntity *e, std::vector<double> p1, std::vector<double> p2); // create solid geometry primitives using the factory GEntity *addSphere(double cx, double cy, double cz, double radius); diff --git a/Geo/GModelFactory.cpp b/Geo/GModelFactory.cpp index 1ef30f0b8d4cb60d6064e51279fde5e5def53839..cc89b6f58ea7fcaaeb1fe7f19b383bed05456ceb 100644 --- a/Geo/GModelFactory.cpp +++ b/Geo/GModelFactory.cpp @@ -98,7 +98,7 @@ GEdge *OCCFactory::addSpline(GModel *gm, const splineType &type, OCCEdge *occEd = 0; int nbControlPoints = points->size1(); - TColgp_Array1OfPnt ctrlPoints (1, nbControlPoints + 2); + TColgp_Array1OfPnt ctrlPoints(1, nbControlPoints + 2); int index = 1; ctrlPoints.SetValue(index++, gp_Pnt(start->x(), start->y(), start->z())); for (int i = 0; i < nbControlPoints; i++) { @@ -115,14 +115,19 @@ GEdge *OCCFactory::addSpline(GModel *gm, const splineType &type, return 0; } -GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, - double x1, double y1, double z1, - double x2, double y2, double z2, - double angle) +GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, std::vector<double> p1, + std::vector<double> p2, double angle) { if (!gm->_occ_internals) gm->_occ_internals = new OCC_Internals; + 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]; + 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(), @@ -144,13 +149,19 @@ GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, return ret; } -GEntity *OCCFactory::extrude(GModel *gm, GEntity* base, - double x1, double y1, double z1, - double x2, double y2, double z2) +GEntity *OCCFactory::extrude(GModel *gm, GEntity* base, std::vector<double> p1, + std::vector<double> p2) { if (!gm->_occ_internals) gm->_occ_internals = new OCC_Internals; + 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]; + gp_Vec direction(gp_Pnt(x1, y1, z1), gp_Pnt(x2, y2, z2)); gp_Ax1 axisOfRevolution(gp_Pnt(x1, y1, z1), direction); diff --git a/Geo/GModelFactory.h b/Geo/GModelFactory.h index 218ae2cc874ce241b45f5c1176fa1c2672845ec5..c4bbbc28ba0f0d5b73ca39f720cf4789cb9d874d 100644 --- a/Geo/GModelFactory.h +++ b/Geo/GModelFactory.h @@ -34,10 +34,10 @@ class GModelFactory { virtual GEdge *addSpline(GModel *gm, const splineType &type, GVertex *start, GVertex *end, fullMatrix<double> *controlPoints) = 0; - virtual GEntity *revolve(GModel *gm, GEntity*, double x1, double y1, double z1, - double x2, double y2, double z2, double angle) = 0; - virtual GEntity *extrude(GModel *gm, GEntity*, double x1, double y1, double z1, - double x2, double y2, double z2) = 0; + virtual GEntity *revolve(GModel *gm, GEntity*, std::vector<double> p1, + std::vector<double> p2, double angle) = 0; + virtual GEntity *extrude(GModel *gm, GEntity*, std::vector<double> p1, + std::vector<double> p2) = 0; // solid primitives virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz, @@ -77,10 +77,10 @@ class OCCFactory : public GModelFactory { virtual GEdge *addSpline(GModel *gm, const splineType &type, GVertex *start, GVertex *end, fullMatrix<double> *controlPoints); - virtual GEntity *revolve(GModel *gm, GEntity*, double x1, double y1, double z1, - double x2, double y2, double z2, double angle); - virtual GEntity *extrude(GModel *gm, GEntity*, double x1, double y1, double z1, - double x2, double y2, double z2); + virtual GEntity *revolve(GModel *gm, GEntity*, std::vector<double> p1, + std::vector<double> p2, double angle); + virtual GEntity *extrude(GModel *gm, GEntity*, std::vector<double> p1, + std::vector<double> p2); virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz, double radius) ; virtual GEntity *addCylinder(GModel *gm, std::vector<double> p1, diff --git a/benchmarks/boolean/square2.lua b/benchmarks/boolean/square2.lua index ff0236efcd9d79871d1abb3d6950927ed388f031..32d2c748c3aa13b78400bfe52b44fe2da9d68d74 100644 --- a/benchmarks/boolean/square2.lua +++ b/benchmarks/boolean/square2.lua @@ -3,13 +3,5 @@ g = GModel() v1 = g:addVertex(0, 0, 0, 1) v2 = g:addVertex(1, 0, 0, 1) e1 = g:addLine(v1, v2) - -dir = fullMatrix(2,3) -dir:set(0,0, 0); -dir:set(0,1, 0); -dir:set(0,2, 0); -dir:set(1,0, 0); -dir:set(1,1, 1); -dir:set(1,2, 0); -f1 = g:extrude(e1, dir) +f1 = g:extrude(e1, {0,0,0}, {0,1,0}) diff --git a/benchmarks/boolean/wikipedia.lua b/benchmarks/boolean/wikipedia.lua index b6494b4320b081dbe7a8330194a1ef99756f8371..bd1ee4e9b56f403e2ca28a3d1162b6e613dd7d15 100644 --- a/benchmarks/boolean/wikipedia.lua +++ b/benchmarks/boolean/wikipedia.lua @@ -24,3 +24,4 @@ myModel2:computeUnion(myTool2,0); myModel2:computeUnion(myTool3,0); myModel:computeDifference(myModel2,0); +myModel:setAsCurrent();