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

old shape import now behaves as before (imports everything, not just highest dim entities)

parent 9c50ed1a
No related branches found
No related tags found
No related merge requests found
...@@ -138,7 +138,8 @@ void OCC_Internals::unbind(TopoDS_Shape shape, int dim, int tag) ...@@ -138,7 +138,8 @@ void OCC_Internals::unbind(TopoDS_Shape shape, int dim, int tag)
} }
} }
void OCC_Internals::bindHighest(TopoDS_Shape shape, std::vector<int> tags[4], int tag) void OCC_Internals::bind(TopoDS_Shape shape, bool highestDimOnly, int tag,
std::vector<int> outTags[4])
{ {
TopExp_Explorer exp0; TopExp_Explorer exp0;
bool first = true; bool first = true;
...@@ -148,34 +149,34 @@ void OCC_Internals::bindHighest(TopoDS_Shape shape, std::vector<int> tags[4], in ...@@ -148,34 +149,34 @@ void OCC_Internals::bindHighest(TopoDS_Shape shape, std::vector<int> tags[4], in
else if(first){ first = false; } else if(first){ first = false; }
else{ Msg::Error("Cannot bind multiple regions to single tag %d", t); return; } else{ Msg::Error("Cannot bind multiple regions to single tag %d", t); return; }
bind(TopoDS::Solid(exp0.Current()), t); bind(TopoDS::Solid(exp0.Current()), t);
tags[3].push_back(t); outTags[3].push_back(t);
} }
if(tags[3].size()) return; if(highestDimOnly && outTags[3].size()) return;
for(exp0.Init(shape, TopAbs_FACE); exp0.More(); exp0.Next()){ for(exp0.Init(shape, TopAbs_FACE); exp0.More(); exp0.Next()){
int t = tag; int t = tag;
if(t <= 0){ t = getMaxTag(2) + 1; } if(t <= 0){ t = getMaxTag(2) + 1; }
else if(first){ first = false; } else if(first){ first = false; }
else{ Msg::Error("Cannot bind multiple faces to single tag %d", t); return; } else{ Msg::Error("Cannot bind multiple faces to single tag %d", t); return; }
bind(TopoDS::Face(exp0.Current()), t); bind(TopoDS::Face(exp0.Current()), t);
tags[2].push_back(t); outTags[2].push_back(t);
} }
if(tags[2].size()) return; if(highestDimOnly && outTags[2].size()) return;
for(exp0.Init(shape, TopAbs_EDGE); exp0.More(); exp0.Next()){ for(exp0.Init(shape, TopAbs_EDGE); exp0.More(); exp0.Next()){
int t = tag; int t = tag;
if(t <= 0){ t = getMaxTag(1) + 1; } if(t <= 0){ t = getMaxTag(1) + 1; }
else if(first){ first = false; } else if(first){ first = false; }
else{ Msg::Error("Cannot bind multiple edges to single tag %d", t); return; } else{ Msg::Error("Cannot bind multiple edges to single tag %d", t); return; }
bind(TopoDS::Edge(exp0.Current()), t); bind(TopoDS::Edge(exp0.Current()), t);
tags[1].push_back(t); outTags[1].push_back(t);
} }
if(tags[1].size()) return; if(highestDimOnly && outTags[1].size()) return;
for(exp0.Init(shape, TopAbs_VERTEX); exp0.More(); exp0.Next()){ for(exp0.Init(shape, TopAbs_VERTEX); exp0.More(); exp0.Next()){
int t = tag; int t = tag;
if(t <= 0){ t = getMaxTag(0) + 1; } if(t <= 0){ t = getMaxTag(0) + 1; }
else if(first){ first = false; } else if(first){ first = false; }
else{ Msg::Error("Cannot bind multiple vertices to single tag %d", t); return; } else{ Msg::Error("Cannot bind multiple vertices to single tag %d", t); return; }
bind(TopoDS::Edge(exp0.Current()), t); bind(TopoDS::Vertex(exp0.Current()), t);
tags[0].push_back(t); outTags[0].push_back(t);
} }
} }
...@@ -557,9 +558,42 @@ void OCC_Internals::addPlanarFace(int tag, std::vector<int> wireTags) ...@@ -557,9 +558,42 @@ void OCC_Internals::addPlanarFace(int tag, std::vector<int> wireTags)
bind(result, tag); bind(result, tag);
} }
void OCC_Internals::addRuledFace(int tag, std::vector<int> wireTags) void OCC_Internals::addRuledFaces(int tag, std::vector<int> wireTags,
std::vector<int> outTags)
{ {
Msg::Error("OCC TODO Ruled face"); if(tag > 0 && _tagFace.IsBound(tag)){
Msg::Error("OpenCASCADE face with tag %d already exists", tag);
return;
}
TopoDS_Shape result;
try{
Standard_Boolean isSolid = Standard_False;
Standard_Boolean isRuled = Standard_True;
BRepOffsetAPI_ThruSections ts(isSolid, isRuled);
for (unsigned i = 0; i < wireTags.size(); i++) {
if(!_tagWire.IsBound(wireTags[i])){
Msg::Error("Unknown OpenCASCADE line loop with tag %d", wireTags[i]);
return;
}
TopoDS_Wire wire = TopoDS::Wire(_tagWire.Find(wireTags[i]));
ts.AddWire(wire);
}
ts.CheckCompatibility(Standard_False);
ts.Build();
if(!ts.IsDone()){
Msg::Error("Could not create ThruSection");
return;
}
result = ts.Shape();
}
catch(Standard_Failure &err){
Msg::Error("OpenCASCADE exception %s", err.GetMessageString());
return;
}
std::vector<int> out[4];
bind(result, true, tag, out);
outTags = out[2];
} }
void OCC_Internals::addSurfaceLoop(int tag, std::vector<int> faceTags) void OCC_Internals::addSurfaceLoop(int tag, std::vector<int> faceTags)
...@@ -742,7 +776,9 @@ void OCC_Internals::addThruSections(int tag, std::vector<int> wireTags) ...@@ -742,7 +776,9 @@ void OCC_Internals::addThruSections(int tag, std::vector<int> wireTags)
TopoDS_Solid result; TopoDS_Solid result;
try{ try{
BRepOffsetAPI_ThruSections ts(Standard_True); // create solid Standard_Boolean isSolid = Standard_True;
Standard_Boolean isRuled = Standard_False;
BRepOffsetAPI_ThruSections ts(isSolid, isRuled);
for (unsigned i = 0; i < wireTags.size(); i++) { for (unsigned i = 0; i < wireTags.size(); i++) {
if(!_tagWire.IsBound(wireTags[i])){ if(!_tagWire.IsBound(wireTags[i])){
Msg::Error("Unknown OpenCASCADE line loop with tag %d", wireTags[i]); Msg::Error("Unknown OpenCASCADE line loop with tag %d", wireTags[i]);
...@@ -979,7 +1015,7 @@ void OCC_Internals::applyBooleanOperator(int tag, BooleanOperator op, ...@@ -979,7 +1015,7 @@ void OCC_Internals::applyBooleanOperator(int tag, BooleanOperator op,
return; return;
} }
bindHighest(result, outTags, tag); bind(result, true, tag, outTags);
} }
void OCC_Internals::getBoundary(std::vector<int> inTags[4], void OCC_Internals::getBoundary(std::vector<int> inTags[4],
...@@ -1105,9 +1141,8 @@ void OCC_Internals::remove(std::vector<int> inTags[4]) ...@@ -1105,9 +1141,8 @@ void OCC_Internals::remove(std::vector<int> inTags[4])
} }
} }
void OCC_Internals::importShapes(const std::string &fileName, void OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnly,
std::vector<int> outTags[4], std::vector<int> outTags[4], const std::string &format)
const std::string &format)
{ {
std::vector<std::string> split = SplitFileName(fileName); std::vector<std::string> split = SplitFileName(fileName);
TopoDS_Shape result; TopoDS_Shape result;
...@@ -1158,12 +1193,13 @@ void OCC_Internals::importShapes(const std::string &fileName, ...@@ -1158,12 +1193,13 @@ void OCC_Internals::importShapes(const std::string &fileName,
CTX::instance()->geom.occFixSmallFaces, CTX::instance()->geom.occFixSmallFaces,
CTX::instance()->geom.occSewFaces, CTX::instance()->geom.occSewFaces,
false, CTX::instance()->geom.occScaling); false, CTX::instance()->geom.occScaling);
bindHighest(result, outTags); bind(result, highestDimOnly, -1, outTags);
} }
void OCC_Internals::importShapes(const TopoDS_Shape *shape, std::vector<int> outTags[4]) void OCC_Internals::importShapes(const TopoDS_Shape *shape, bool highestDimOnly,
std::vector<int> outTags[4])
{ {
bindHighest(*shape, outTags); bind(*shape, highestDimOnly, -1, outTags);
} }
void OCC_Internals::exportShapes(const std::string &fileName, void OCC_Internals::exportShapes(const std::string &fileName,
...@@ -2263,7 +2299,7 @@ int GModel::readOCCBREP(const std::string &fn) ...@@ -2263,7 +2299,7 @@ int GModel::readOCCBREP(const std::string &fn)
if(!_occ_internals) if(!_occ_internals)
_occ_internals = new OCC_Internals; _occ_internals = new OCC_Internals;
std::vector<int> tags[4]; std::vector<int> tags[4];
_occ_internals->importShapes(fn, tags, "brep"); _occ_internals->importShapes(fn, false, tags, "brep");
_occ_internals->synchronize(this); _occ_internals->synchronize(this);
snapVertices(); snapVertices();
return 1; return 1;
...@@ -2274,7 +2310,7 @@ int GModel::readOCCSTEP(const std::string &fn) ...@@ -2274,7 +2310,7 @@ int GModel::readOCCSTEP(const std::string &fn)
if(!_occ_internals) if(!_occ_internals)
_occ_internals = new OCC_Internals; _occ_internals = new OCC_Internals;
std::vector<int> tags[4]; std::vector<int> tags[4];
_occ_internals->importShapes(fn, tags, "step"); _occ_internals->importShapes(fn, false, tags, "step");
_occ_internals->synchronize(this); _occ_internals->synchronize(this);
return 1; return 1;
} }
...@@ -2284,7 +2320,7 @@ int GModel::readOCCIGES(const std::string &fn) ...@@ -2284,7 +2320,7 @@ int GModel::readOCCIGES(const std::string &fn)
if(!_occ_internals) if(!_occ_internals)
_occ_internals = new OCC_Internals; _occ_internals = new OCC_Internals;
std::vector<int> tags[4]; std::vector<int> tags[4];
_occ_internals->importShapes(fn, tags, "iges"); _occ_internals->importShapes(fn, false, tags, "iges");
_occ_internals->synchronize(this); _occ_internals->synchronize(this);
return 1; return 1;
} }
...@@ -2314,7 +2350,7 @@ int GModel::importOCCShape(const void *shape) ...@@ -2314,7 +2350,7 @@ int GModel::importOCCShape(const void *shape)
if(!_occ_internals) if(!_occ_internals)
_occ_internals = new OCC_Internals; _occ_internals = new OCC_Internals;
std::vector<int> tags[4]; std::vector<int> tags[4];
_occ_internals->importShapes((TopoDS_Shape*)shape, tags); _occ_internals->importShapes((TopoDS_Shape*)shape, false, tags);
_occ_internals->synchronize(this); _occ_internals->synchronize(this);
snapVertices(); snapVertices();
SetBoundingBox(); SetBoundingBox();
......
...@@ -68,10 +68,12 @@ class OCC_Internals { ...@@ -68,10 +68,12 @@ class OCC_Internals {
void unbind(TopoDS_Solid solid, int tag); void unbind(TopoDS_Solid solid, int tag);
void unbind(TopoDS_Shape shape, int dim, int tag); void unbind(TopoDS_Shape shape, int dim, int tag);
// bind highest-dimensional entities in shape (if tag > 0 and a single entity // bind (potentially) mutliple entities in shape and return the tags in
// if found, use it; otherwise assign new tags); assigned tags are returned in // outTags. If tag > 0 and a single entity if found, use that; if
// tags // highestDimOnly is true, only bind the entities of the highest
void bindHighest(TopoDS_Shape shape, std::vector<int> tags[4], int tag=-1); // dimension
void bind(TopoDS_Shape shape, bool highestDimOnly, int tag,
std::vector<int> outTags[4]);
// is the entity of a given dimension and tag bound? // is the entity of a given dimension and tag bound?
bool isBound(int dim, int tag); bool isBound(int dim, int tag);
...@@ -96,7 +98,7 @@ class OCC_Internals { ...@@ -96,7 +98,7 @@ class OCC_Internals {
double x2, double y2, double z2); double x2, double y2, double z2);
void addDisk(int tag, double xc, double yc, double zc, double rx, double ry); void addDisk(int tag, double xc, double yc, double zc, double rx, double ry);
void addPlanarFace(int tag, std::vector<int> wireTags); void addPlanarFace(int tag, std::vector<int> wireTags);
void addRuledFace(int tag, std::vector<int> wireTags); void addRuledFaces(int tag, std::vector<int> wireTags, std::vector<int> outTags);
void addSurfaceLoop(int tag, std::vector<int> faceTags); void addSurfaceLoop(int tag, std::vector<int> faceTags);
void addVolume(int tag, std::vector<int> shellTags); void addVolume(int tag, std::vector<int> shellTags);
void addSphere(int tag, double xc, double yc, double zc, double radius); void addSphere(int tag, double xc, double yc, double zc, double radius);
...@@ -127,11 +129,12 @@ class OCC_Internals { ...@@ -127,11 +129,12 @@ class OCC_Internals {
void remove(std::vector<int> inTags[4]); void remove(std::vector<int> inTags[4]);
// import shapes from file // import shapes from file
void importShapes(const std::string &fileName, std::vector<int> outTags[4], void importShapes(const std::string &fileName, bool highestDimOnly,
const std::string &format=""); std::vector<int> outTags[4], const std::string &format="");
// import shapes from TopoDS_Shape // import shapes from TopoDS_Shape
void importShapes(const TopoDS_Shape *shape, std::vector<int> outTags[4]); void importShapes(const TopoDS_Shape *shape, bool highestDimOnly,
std::vector<int> outTags[4]);
// export all bound shapes to file // export all bound shapes to file
void exportShapes(const std::string &fileName, const std::string &format=""); void exportShapes(const std::string &fileName, const std::string &format="");
...@@ -168,7 +171,7 @@ class OCC_Internals { ...@@ -168,7 +171,7 @@ class OCC_Internals {
void buildGModel(GModel *gm); void buildGModel(GModel *gm);
void loadShape(const TopoDS_Shape *s) void loadShape(const TopoDS_Shape *s)
{ {
std::vector<int> tags[4]; importShapes(s, tags); std::vector<int> tags[4]; importShapes(s, false, tags);
} }
GVertex *addVertexToModel(GModel *model, TopoDS_Vertex v); GVertex *addVertexToModel(GModel *model, TopoDS_Vertex v);
GEdge *addEdgeToModel(GModel *model, TopoDS_Edge e); GEdge *addEdgeToModel(GModel *model, TopoDS_Edge e);
...@@ -195,7 +198,7 @@ public: ...@@ -195,7 +198,7 @@ public:
double x2, double y2, double z2){} double x2, double y2, double z2){}
void addDisk(int tag, double xc, double yc, double zc, double rx, double ry){} void addDisk(int tag, double xc, double yc, double zc, double rx, double ry){}
void addPlanarFace(int tag, std::vector<int> wireTags){} void addPlanarFace(int tag, std::vector<int> wireTags){}
void addRuledFace(int tag, std::vector<int> wireTags){} void addRuledFaces(int tag, std::vector<int> wireTags, std::vector<int> outTags){}
void addSurfaceLoop(int tag, std::vector<int> faceTags){} void addSurfaceLoop(int tag, std::vector<int> faceTags){}
void addVolume(int tag, std::vector<int> shellTags){} void addVolume(int tag, std::vector<int> shellTags){}
void addSphere(int tag, double xc, double yc, double zc, double radius){}; void addSphere(int tag, double xc, double yc, double zc, double radius){};
...@@ -217,8 +220,8 @@ public: ...@@ -217,8 +220,8 @@ public:
double dx, double dy, double dz, double angle){} double dx, double dy, double dz, double angle){}
void copy(std::vector<int> inTags[4], std::vector<int> outTags[4]){} void copy(std::vector<int> inTags[4], std::vector<int> outTags[4]){}
void remove(std::vector<int> inTags[4]){} void remove(std::vector<int> inTags[4]){}
void importShapes(const std::string &fileName, std::vector<int> outTags[4], void importShapes(const std::string &fileName, bool highestDimOnly,
const std::string &format=""){} std::vector<int> outTags[4], const std::string &format=""){}
void exportShapes(const std::string &fileName, const std::string &format=""){} void exportShapes(const std::string &fileName, const std::string &format=""){}
void synchronize(GModel *model){} void synchronize(GModel *model){}
}; };
......
This diff is collapsed.
...@@ -2170,15 +2170,6 @@ Shape : ...@@ -2170,15 +2170,6 @@ Shape :
if(FindSurface(num)){ if(FindSurface(num)){
yymsg(0, "Surface %d already exists", num); yymsg(0, "Surface %d already exists", num);
} }
else{
if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
std::vector<int> wires;
for(int i = 0; i < List_Nbr($7); i++){
double d; List_Read($7, i, &d);
wires.push_back((int)std::abs(d));
}
GModel::current()->getOCCInternals()->addRuledFace(num, wires);
}
else{ else{
double d; double d;
List_Read($7, 0, &d); List_Read($7, 0, &d);
...@@ -2208,7 +2199,6 @@ Shape : ...@@ -2208,7 +2199,6 @@ Shape :
Tree_Add(GModel::current()->getGEOInternals()->Surfaces, &s); Tree_Add(GModel::current()->getGEOInternals()->Surfaces, &s);
} }
} }
}
List_Delete($7); List_Delete($7);
$$.Type = type; $$.Type = type;
$$.Num = num; $$.Num = num;
...@@ -4538,7 +4528,7 @@ Boolean : ...@@ -4538,7 +4528,7 @@ Boolean :
if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){ if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){
std::vector<int> out[4]; std::vector<int> out[4];
std::string tmp = FixRelativePath(gmsh_yyname, $3); std::string tmp = FixRelativePath(gmsh_yyname, $3);
GModel::current()->getOCCInternals()->importShapes(tmp, out); GModel::current()->getOCCInternals()->importShapes(tmp, true, out);
Shape s; Shape s;
for(int dim = 0; dim < 4; dim++){ for(int dim = 0; dim < 4; dim++){
s.Type = (dim == 3) ? MSH_VOLUME_FROM_GMODEL : s.Type = (dim == 3) ? MSH_VOLUME_FROM_GMODEL :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment