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

more work on new cad creation stuff

parent 945ff17b
No related branches found
No related tags found
No related merge requests found
...@@ -1461,19 +1461,17 @@ GEdge *GModel::addBezier(GVertex *start, GVertex *end, ...@@ -1461,19 +1461,17 @@ GEdge *GModel::addBezier(GVertex *start, GVertex *end,
return 0; 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) if(_factory)
return _factory->revolve(this, e, (*axis)(0, 0), (*axis)(0, 1), (*axis)(0, 2), return _factory->revolve(this, e, p1, p2, angle);
(*axis)(1, 0), (*axis)(1, 1), (*axis)(1, 2), angle);
return 0; 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) if(_factory)
return _factory->extrude(this, e, (*axis)(0, 0), (*axis)(0, 1), (*axis)(0, 2), return _factory->extrude(this, e, p1, p2);
(*axis)(1, 0), (*axis)(1, 1), (*axis)(1, 2));
return 0; return 0;
} }
...@@ -1833,13 +1831,11 @@ void GModel::registerBindings(binding *b) ...@@ -1833,13 +1831,11 @@ void GModel::registerBindings(binding *b)
cm->setArgNames("x", "y", "z", "v1", "v2", NULL); cm->setArgNames("x", "y", "z", "v1", "v2", NULL);
cm = cb->addMethod("revolve", &GModel::revolve); cm = cb->addMethod("revolve", &GModel::revolve);
cm->setDescription("revolve an entity of a given angle. Axis is defined by 2 " cm->setDescription("revolve an entity of a given angle. Axis is defined by 2 "
"points " "points");
"in a full Matrix(2,3)"); cm->setArgNames("entity", "{x1,y1,z1}", "{x2,y2,z2}", "angle", NULL);
cm->setArgNames("entity", "angle", "axis", NULL);
cm = cb->addMethod("extrude", &GModel::extrude); cm = cb->addMethod("extrude", &GModel::extrude);
cm->setDescription("extrudes an entity. Axis is defined by 2 points in a full " cm->setDescription("extrudes an entity. Axis is defined by 2 points");
"Matrix(2,3)"); cm->setArgNames("entity", "{x1,y1,z1}", "{x2,y2,z2}", NULL);
cm->setArgNames("entity", "axis", NULL);
cm = cb->addMethod("addSphere", &GModel::addSphere); cm = cb->addMethod("addSphere", &GModel::addSphere);
cm->setDescription("add a sphere"); cm->setDescription("add a sphere");
cm->setArgNames("xc", "yc", "zc", "radius", NULL); cm->setArgNames("xc", "yc", "zc", "radius", NULL);
...@@ -1872,7 +1868,8 @@ void GModel::registerBindings(binding *b) ...@@ -1872,7 +1868,8 @@ void GModel::registerBindings(binding *b)
cm = cb->addMethod("glue", &GModel::glue); cm = cb->addMethod("glue", &GModel::glue);
cm->setDescription("glue the geometric model using geometric tolerance eps"); 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 = cb->setConstructor<GModel>();
cm->setDescription("Create an empty GModel"); cm->setDescription("Create an empty GModel");
} }
...@@ -133,6 +133,7 @@ class GModel ...@@ -133,6 +133,7 @@ class GModel
// sets a model to current // sets a model to current
static int setCurrent(GModel *m); static int setCurrent(GModel *m);
int setAsCurrent(){ return setCurrent(this); }
// find a model by name // find a model by name
static GModel *findByName(std::string name); static GModel *findByName(std::string name);
...@@ -354,8 +355,8 @@ class GModel ...@@ -354,8 +355,8 @@ class GModel
GEdge *addCircleArcCenter(double x, double y, double z, GVertex *start, GVertex *end); 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 *addCircleArc3Points(double x, double y, double z, GVertex *start, GVertex *end);
GEdge *addBezier(GVertex *start, GVertex *end, fullMatrix<double> *controlPoints); GEdge *addBezier(GVertex *start, GVertex *end, fullMatrix<double> *controlPoints);
GEntity *revolve(GEntity *e, double angle, fullMatrix<double> *axis); GEntity *revolve(GEntity *e, std::vector<double> p1, std::vector<double> p2, double angle);
GEntity *extrude(GEntity *e, fullMatrix<double> *axis); GEntity *extrude(GEntity *e, std::vector<double> p1, std::vector<double> p2);
// create solid geometry primitives using the factory // create solid geometry primitives using the factory
GEntity *addSphere(double cx, double cy, double cz, double radius); GEntity *addSphere(double cx, double cy, double cz, double radius);
... ...
......
...@@ -115,14 +115,19 @@ GEdge *OCCFactory::addSpline(GModel *gm, const splineType &type, ...@@ -115,14 +115,19 @@ GEdge *OCCFactory::addSpline(GModel *gm, const splineType &type,
return 0; return 0;
} }
GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, std::vector<double> p1,
double x1, double y1, double z1, std::vector<double> p2, double angle)
double x2, double y2, double z2,
double angle)
{ {
if (!gm->_occ_internals) if (!gm->_occ_internals)
gm->_occ_internals = new 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_Dir direction(x2 - x1, y2 - y1, z2 - z1);
gp_Ax1 axisOfRevolution(gp_Pnt(x1, y1, z1), direction); gp_Ax1 axisOfRevolution(gp_Pnt(x1, y1, z1), direction);
BRepPrimAPI_MakeRevol MR(*(TopoDS_Shape*)base->getNativePtr(), BRepPrimAPI_MakeRevol MR(*(TopoDS_Shape*)base->getNativePtr(),
...@@ -144,13 +149,19 @@ GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, ...@@ -144,13 +149,19 @@ GEntity *OCCFactory::revolve(GModel *gm, GEntity* base,
return ret; return ret;
} }
GEntity *OCCFactory::extrude(GModel *gm, GEntity* base, GEntity *OCCFactory::extrude(GModel *gm, GEntity* base, std::vector<double> p1,
double x1, double y1, double z1, std::vector<double> p2)
double x2, double y2, double z2)
{ {
if (!gm->_occ_internals) if (!gm->_occ_internals)
gm->_occ_internals = new 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_Vec direction(gp_Pnt(x1, y1, z1), gp_Pnt(x2, y2, z2));
gp_Ax1 axisOfRevolution(gp_Pnt(x1, y1, z1), direction); gp_Ax1 axisOfRevolution(gp_Pnt(x1, y1, z1), direction);
... ...
......
...@@ -34,10 +34,10 @@ class GModelFactory { ...@@ -34,10 +34,10 @@ class GModelFactory {
virtual GEdge *addSpline(GModel *gm, const splineType &type, virtual GEdge *addSpline(GModel *gm, const splineType &type,
GVertex *start, GVertex *end, GVertex *start, GVertex *end,
fullMatrix<double> *controlPoints) = 0; fullMatrix<double> *controlPoints) = 0;
virtual GEntity *revolve(GModel *gm, GEntity*, double x1, double y1, double z1, virtual GEntity *revolve(GModel *gm, GEntity*, std::vector<double> p1,
double x2, double y2, double z2, double angle) = 0; std::vector<double> p2, double angle) = 0;
virtual GEntity *extrude(GModel *gm, GEntity*, double x1, double y1, double z1, virtual GEntity *extrude(GModel *gm, GEntity*, std::vector<double> p1,
double x2, double y2, double z2) = 0; std::vector<double> p2) = 0;
// solid primitives // solid primitives
virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz, virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz,
...@@ -77,10 +77,10 @@ class OCCFactory : public GModelFactory { ...@@ -77,10 +77,10 @@ class OCCFactory : public GModelFactory {
virtual GEdge *addSpline(GModel *gm, const splineType &type, virtual GEdge *addSpline(GModel *gm, const splineType &type,
GVertex *start, GVertex *end, GVertex *start, GVertex *end,
fullMatrix<double> *controlPoints); fullMatrix<double> *controlPoints);
virtual GEntity *revolve(GModel *gm, GEntity*, double x1, double y1, double z1, virtual GEntity *revolve(GModel *gm, GEntity*, std::vector<double> p1,
double x2, double y2, double z2, double angle); std::vector<double> p2, double angle);
virtual GEntity *extrude(GModel *gm, GEntity*, double x1, double y1, double z1, virtual GEntity *extrude(GModel *gm, GEntity*, std::vector<double> p1,
double x2, double y2, double z2); std::vector<double> p2);
virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz, virtual GEntity *addSphere(GModel *gm, double cx, double cy, double cz,
double radius) ; double radius) ;
virtual GEntity *addCylinder(GModel *gm, std::vector<double> p1, virtual GEntity *addCylinder(GModel *gm, std::vector<double> p1,
... ...
......
...@@ -3,13 +3,5 @@ g = GModel() ...@@ -3,13 +3,5 @@ g = GModel()
v1 = g:addVertex(0, 0, 0, 1) v1 = g:addVertex(0, 0, 0, 1)
v2 = g:addVertex(1, 0, 0, 1) v2 = g:addVertex(1, 0, 0, 1)
e1 = g:addLine(v1, v2) e1 = g:addLine(v1, v2)
f1 = g:extrude(e1, {0,0,0}, {0,1,0})
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)
...@@ -24,3 +24,4 @@ myModel2:computeUnion(myTool2,0); ...@@ -24,3 +24,4 @@ myModel2:computeUnion(myTool2,0);
myModel2:computeUnion(myTool3,0); myModel2:computeUnion(myTool3,0);
myModel:computeDifference(myModel2,0); myModel:computeDifference(myModel2,0);
myModel:setAsCurrent();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment