Commit 6447a015 by Christophe Geuzaine

interactive highlight of physical entities + better default labels for geom entities

parent ef676b3d
Pipeline #1485 passed with stage
in 38 minutes 34 seconds
......@@ -844,8 +844,8 @@ StringXNumber GeometryOptions_Number[] = {
{ F|O, "HighlightOrphans" , opt_geometry_highlight_orphans, 0. ,
"Highlight orphan entities (lines connected to a single surface, etc.)?" },
{ F|O, "LabelType" , opt_geometry_label_type , 1. ,
"Type of entity label (1=elementary number, 2=physical number)" },
{ F|O, "LabelType" , opt_geometry_label_type , 0. ,
"Type of entity label (0=description, 1=elementary number, 2=physical number)" },
{ F|O, "Light" , opt_geometry_light , 1. ,
"Enable lighting for the geometry" },
{ F|O, "LightTwoSide" , opt_geometry_light_two_side , 1. ,
......
......@@ -4580,13 +4580,13 @@ double opt_geometry_label_type(OPT_ARGS_NUM)
{
if(action & GMSH_SET){
CTX::instance()->geom.labelType = (int)val;
if(CTX::instance()->geom.labelType < 1 || CTX::instance()->geom.labelType > 2)
CTX::instance()->geom.labelType = 1;
if(CTX::instance()->geom.labelType < 0 || CTX::instance()->geom.labelType > 2)
CTX::instance()->geom.labelType = 0;
}
#if defined(HAVE_FLTK)
if(FlGui::available() && (action & GMSH_GUI)){
FlGui::instance()->options->geo.choice[4]->value
(CTX::instance()->geom.labelType - 1);
(CTX::instance()->geom.labelType);
}
#endif
return CTX::instance()->geom.labelType;
......
......@@ -1166,25 +1166,42 @@ static void highlight_physical_group_cb(Fl_Widget *w, void *data)
if(!data) return;
std::string group((char*)data);
if(group.empty()) return;
GModel *m = GModel::current();
int dim = -1, num = -1;
if(group.find("Physical Point") != std::string::npos){
int num = atoi(group.substr(15).c_str());
printf("will highlight physical point %d\n", num);
dim = 0; num = atoi(group.substr(15).c_str());
}
else if(group.find("Physical Curve") != std::string::npos){
int num = atoi(group.substr(15).c_str());
printf("will highlight physical curve %d\n", num);
dim = 1; num = atoi(group.substr(15).c_str());
}
else if(group.find("Physical Surface") != std::string::npos){
int num = atoi(group.substr(17).c_str());
printf("will highlight physical surface %d\n", num);
dim = 2; num = atoi(group.substr(17).c_str());
}
else if(group.find("Physical Volume") != std::string::npos){
int num = atoi(group.substr(16).c_str());
printf("will highlight physical volume %d\n", num);
dim = 3; num = atoi(group.substr(16).c_str());
}
else{
printf("will highlight physical group with name '%s'\n", group.c_str());
for(dim = 3; dim >= 0; dim--){
num = m->getPhysicalNumber(dim, group);
if(num > 0) break;
}
}
if(dim < 0 || num < 0) return; // not found
std::map<int, std::vector<GEntity*> > groups;
m->getPhysicalGroups(dim, groups);
std::vector<GEntity*> entities = groups[num];
for(unsigned int i = 0; i < entities.size(); i++){
entities[i]->setVisibility(1);
if(!entities[i]->getSelection()){
entities[i]->setSelection(2);
}
else
entities[i]->setSelection(0);
}
drawContext::global()->draw();
}
......
......@@ -458,7 +458,7 @@ static void geometry_options_ok_cb(Fl_Widget *w, void *data)
opt_geometry_curve_type(0, GMSH_SET, o->geo.choice[1]->value());
opt_geometry_surface_type(0, GMSH_SET, o->geo.choice[2]->value());
opt_geometry_transform(0, GMSH_SET, o->geo.choice[3]->value());
opt_geometry_label_type(0, GMSH_SET, o->geo.choice[4]->value() + 1);
opt_geometry_label_type(0, GMSH_SET, o->geo.choice[4]->value());
if(CTX::instance()->fastRedraw)
CTX::instance()->post.draw = CTX::instance()->mesh.draw = 0;
......@@ -2023,6 +2023,7 @@ optionWindow::optionWindow(int deltaFontSize)
geo.butt[7]->callback(geometry_options_ok_cb);
static Fl_Menu_Item menu_label_type[] = {
{"Description", 0, 0, 0},
{"Elementary tags", 0, 0, 0},
{"Physical tags", 0, 0, 0},
{0}
......
......@@ -47,19 +47,29 @@ bool GEntity::useColor()
return true;
}
std::string GEntity::getInfoString()
std::string GEntity::getInfoString(bool additional)
{
std::ostringstream sstream;
sstream << getTypeString() << " " << tag();
std::string info = getAdditionalInfoString();
if(info.size()) sstream << " " << info;
if(additional){
std::string info = getAdditionalInfoString();
if(info.size()) sstream << " " << info;
}
if(physicals.size()){
sstream << " (Physical:";
for(unsigned int i = 0; i < physicals.size(); i++)
sstream << ": Physical ";
switch(dim()){
case 0: sstream << "Point "; break;
case 1: sstream << "Curve "; break;
case 2: sstream << "Surface "; break;
case 3: sstream << "Volume "; break;
}
for(unsigned int i = 0; i < physicals.size(); i++){
sstream << " " << physicals[i];
sstream << ")";
std::string name = model()->getPhysicalName(dim(), physicals[i]);
if(name.size()) sstream << " " << "(" << name << ")";
}
}
return sstream.str();
......
......@@ -314,7 +314,7 @@ class GEntity {
virtual bool useColor();
// return an information string for the entity
virtual std::string getInfoString();
virtual std::string getInfoString(bool additional=true);
// return a type-specific additional information string
virtual std::string getAdditionalInfoString() { return std::string(""); }
......
......@@ -306,12 +306,12 @@ GEntity *GModel::getEntityByTag(int dim, int n) const
return 0;
}
std::vector<int> GModel::getTagsForPhysicalName(int dim, const std::string tag)
std::vector<int> GModel::getTagsForPhysicalName(int dim, const std::string &name)
{
std::vector<int> tags;
std::map<int, std::vector<GEntity*> > physicalGroups;
getPhysicalGroups(dim, physicalGroups);
std::vector<GEntity*> entities = physicalGroups[getPhysicalNumber(dim, tag)];
std::vector<GEntity*> entities = physicalGroups[getPhysicalNumber(dim, name)];
for(std::vector<GEntity*>::iterator it = entities.begin(); it != entities.end(); it++){
GEntity *ge = *it;
tags.push_back(ge->tag());
......
......@@ -379,11 +379,11 @@ class GModel {
// get the number of a given physical group of dimension
// "dim" and name "name". return -1 if not found
int getPhysicalNumber(const int &dim, const std::string & name);
int getPhysicalNumber(const int &dim, const std::string &name);
// get all tags of elementary entities associated with a given physical group
// name
std::vector<int> getTagsForPhysicalName(int dim, const std::string name);
std::vector<int> getTagsForPhysicalName(int dim, const std::string &name);
// deprecated
std::vector<int> getEdgesByStringTag(const std::string name)
{
......
......@@ -15,8 +15,11 @@
static void drawEntityLabel(drawContext *ctx, GEntity *e,
double x, double y, double z, double offset)
{
char str[256];
if(CTX::instance()->geom.labelType == 1){
char str[1024];
if(CTX::instance()->geom.labelType == 0){
strcpy(str, e->getInfoString(false).c_str());
}
else if(CTX::instance()->geom.labelType == 1){
sprintf(str, "%d", e->tag());
}
else{
......@@ -84,7 +87,7 @@ class drawGVertex {
double x = v->x(), y = v->y(), z = v->z();
_ctx->transform(x, y, z);
if(CTX::instance()->geom.points) {
if(CTX::instance()->geom.points || v->getSelection() > 1) {
if(CTX::instance()->geom.pointType > 0) {
if(v->getSelection())
_ctx->drawSphere(sps, x, y, z, CTX::instance()->geom.light);
......@@ -98,7 +101,7 @@ class drawGVertex {
}
}
if(CTX::instance()->geom.pointsNum) {
if(CTX::instance()->geom.pointsNum || v->getSelection() > 1) {
double offset = (0.5 * ps +
0.1 * CTX::instance()->glFontSize) * _ctx->pixel_equiv_x;
drawEntityLabel(_ctx, v, x, y, z, offset);
......@@ -157,7 +160,7 @@ class drawGEdge {
double t_min = t_bounds.low();
double t_max = t_bounds.high();
if(CTX::instance()->geom.curves) {
if(CTX::instance()->geom.curves || e->getSelection() > 1) {
int N = e->minimumDrawSegments() + 1;
if(CTX::instance()->geom.curveType > 0) {
for(int i = 0; i < N - 1; i++) {
......@@ -188,7 +191,7 @@ class drawGEdge {
}
}
if(CTX::instance()->geom.curvesNum) {
if(CTX::instance()->geom.curvesNum || e->getSelection() > 1) {
GPoint p = e->point(t_min + 0.5 * (t_max - t_min));
double offset = (0.5 * CTX::instance()->geom.curveWidth +
0.1 * CTX::instance()->glFontSize) * _ctx->pixel_equiv_x;
......@@ -280,7 +283,7 @@ class drawGFace {
double u2 = 0.5 * (ubounds.high() + ubounds.low());
double v2 = 0.5 * (vbounds.high() + vbounds.low());
if(CTX::instance()->geom.surfaces){
if(CTX::instance()->geom.surfaces || f->getSelection() > 1){
if(CTX::instance()->geom.surfaceType > 0 && f->va_geom_triangles){
bool selected = false;
if (f->getSelection())
......@@ -330,7 +333,7 @@ class drawGFace {
}
}
if(CTX::instance()->geom.surfacesNum) {
if(CTX::instance()->geom.surfacesNum || f->getSelection() > 1) {
GPoint p = f->point(uav, vav);
double offset = 0.1 * CTX::instance()->glFontSize * _ctx->pixel_equiv_x;
double x = p.x(), y = p.y(), z = p.z();
......@@ -360,7 +363,7 @@ class drawGFace {
CTX::instance()->geom.surfacesNum || CTX::instance()->geom.normals)
f->buildRepresentationCross();
if(CTX::instance()->geom.surfaces) {
if(CTX::instance()->geom.surfaces || f->getSelection() > 1){
//bool selected = false;
if(CTX::instance()->geom.surfaceType > 0 && f->va_geom_triangles){
_drawVertexArray(f->va_geom_triangles, CTX::instance()->geom.light,
......@@ -384,7 +387,7 @@ class drawGFace {
if(f->cross.size() < 2) return;
if(CTX::instance()->geom.surfacesNum) {
if(CTX::instance()->geom.surfacesNum || f->getSelection() > 1) {
double offset = 0.1 * CTX::instance()->glFontSize * _ctx->pixel_equiv_x;
double x = 0.5 * (f->cross[0].x() + f->cross[1].x());
double y = 0.5 * (f->cross[0].y() + f->cross[1].y());
......@@ -488,10 +491,10 @@ class drawGRegion {
double x = p.x(), y = p.y(), z = p.z();
_ctx->transform(x, y, z);
if(CTX::instance()->geom.volumes)
if(CTX::instance()->geom.volumes || r->getSelection() > 1)
_ctx->drawSphere(size, x, y, z, CTX::instance()->geom.light);
if(CTX::instance()->geom.volumesNum){
if(CTX::instance()->geom.volumesNum || r->getSelection() > 1){
double offset = (0.5 * size + 0.1 * CTX::instance()->glFontSize) *
_ctx->pixel_equiv_x;
drawEntityLabel(_ctx, r, x, y, z, offset);
......@@ -520,17 +523,10 @@ void drawContext::drawGeom()
for(unsigned int i = 0; i < GModel::list.size(); i++){
GModel *m = GModel::list[i];
if(m->getVisibility() && isVisible(m)){
if(CTX::instance()->geom.points || CTX::instance()->geom.pointsNum)
std::for_each(m->firstVertex(), m->lastVertex(), drawGVertex(this));
if(CTX::instance()->geom.curves || CTX::instance()->geom.curvesNum ||
CTX::instance()->geom.tangents)
std::for_each(m->firstEdge(), m->lastEdge(), drawGEdge(this));
if(CTX::instance()->geom.surfaces || CTX::instance()->geom.surfacesNum ||
CTX::instance()->geom.normals) {
std::for_each(m->firstFace(), m->lastFace(), drawGFace(this));
}
if(CTX::instance()->geom.volumes || CTX::instance()->geom.volumesNum)
std::for_each(m->firstRegion(), m->lastRegion(), drawGRegion(this));
std::for_each(m->firstVertex(), m->lastVertex(), drawGVertex(this));
std::for_each(m->firstEdge(), m->lastEdge(), drawGEdge(this));
std::for_each(m->firstFace(), m->lastFace(), drawGFace(this));
std::for_each(m->firstRegion(), m->lastRegion(), drawGRegion(this));
}
}
......
......@@ -38,7 +38,7 @@ Saved in: @code{General.OptionsFileName}
@item General.BuildOptions
Gmsh build options (read-only)@*
Default value: @code{" 64Bit Ann Bamg Bfgs Blas(VecLib) Blossom DIntegration Dlopen Fltk GMP Gmm Jpeg(Fltk) Kbipack Lapack(VecLib) MathEx Med Mesh Metis Mmg3d Mpeg NativeFileChooser Netgen ONELAB ONELABMetamodel OpenCASCADE OpenGL OptHom PETSc Parser Plugins Png(Fltk) Post SLEPc Solver TetGen/BR Voro++ Zlib"}@*
Default value: @code{" 64Bit Ann Bamg Bfgs Blas(VecLib) Blossom DIntegration Dlopen Fltk GMP Gmm Hxt Jpeg(Fltk) Kbipack Lapack(VecLib) MathEx Med Mesh Metis Mmg3d Mpeg NativeFileChooser Netgen ONELAB ONELABMetamodel OpenCASCADE OpenGL OptHom PETSc Parser Plugins Png(Fltk) Post SLEPc Solver TetGen/BR Voro++ Zlib"}@*
Saved in: @code{-}
@item General.DefaultFileName
......
......@@ -67,8 +67,8 @@ Default value: @code{0}@*
Saved in: @code{General.OptionsFileName}
@item Geometry.LabelType
Type of entity label (1=elementary number, 2=physical number)@*
Default value: @code{1}@*
Type of entity label (0=description, 1=elementary number, 2=physical number)@*
Default value: @code{0}@*
Saved in: @code{General.OptionsFileName}
@item Geometry.Light
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment