From a437511ffafa0d500d04c4bde06a4140e9c6de02 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 30 Mar 2017 18:43:45 +0100
Subject: [PATCH] interface cylinder and block

---
 Fltk/contextWindow.cpp     | 78 +++++++++++++++++++++++++++++++++++++-
 Fltk/contextWindow.h       |  2 +-
 Fltk/graphicWindow.cpp     | 30 ++++++++++++---
 Geo/GeoStringInterface.cpp | 23 +++++++++++
 Geo/GeoStringInterface.h   |  6 +++
 5 files changed, 131 insertions(+), 8 deletions(-)

diff --git a/Fltk/contextWindow.cpp b/Fltk/contextWindow.cpp
index ece8e5659b..8221a2431c 100644
--- a/Fltk/contextWindow.cpp
+++ b/Fltk/contextWindow.cpp
@@ -116,6 +116,38 @@ static void elementary_add_sphere_cb(Fl_Widget *w, void *data)
   drawContext::global()->draw();
 }
 
+static void elementary_add_cylinder_cb(Fl_Widget *w, void *data)
+{
+  add_cylinder(GModel::current()->getFileName(),
+               FlGui::instance()->elementaryContext->input[39]->value(),
+               FlGui::instance()->elementaryContext->input[40]->value(),
+               FlGui::instance()->elementaryContext->input[41]->value(),
+               FlGui::instance()->elementaryContext->input[42]->value(),
+               FlGui::instance()->elementaryContext->input[43]->value(),
+               FlGui::instance()->elementaryContext->input[44]->value(),
+               FlGui::instance()->elementaryContext->input[45]->value(),
+               FlGui::instance()->elementaryContext->input[46]->value());
+  FlGui::instance()->resetVisibility();
+  GModel::current()->setSelection(0);
+  SetBoundingBox();
+  drawContext::global()->draw();
+}
+
+static void elementary_add_block_cb(Fl_Widget *w, void *data)
+{
+  add_block(GModel::current()->getFileName(),
+            FlGui::instance()->elementaryContext->input[47]->value(),
+            FlGui::instance()->elementaryContext->input[48]->value(),
+            FlGui::instance()->elementaryContext->input[49]->value(),
+            FlGui::instance()->elementaryContext->input[50]->value(),
+            FlGui::instance()->elementaryContext->input[51]->value(),
+            FlGui::instance()->elementaryContext->input[52]->value());
+  FlGui::instance()->resetVisibility();
+  GModel::current()->setSelection(0);
+  SetBoundingBox();
+  drawContext::global()->draw();
+}
+
 static void elementary_switch_tabs_cb(Fl_Widget *w, void *data)
 {
   if(FlGui::instance()->elementaryContext->tab1->visible()){
@@ -336,13 +368,55 @@ elementaryContextWindow::elementaryContextWindow(int deltaFontSize)
     // 7: Cylinder
     {
       group[7] = new Fl_Group
-        (WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Wedge");
+        (WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Cylinder");
+      input[39] = new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "X");
+      input[39]->value("0");
+      input[40] = new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, "Y");
+      input[40]->value("0");
+      input[41] = new Fl_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, "Z");
+      input[41]->value("0");
+      input[42] = new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "DX");
+      input[42]->value("1");
+      input[43] = new Fl_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "DY");
+      input[43]->value("0");
+      input[44] = new Fl_Input(2 * WB, 2 * WB + 6 * BH, IW, BH, "DZ");
+      input[44]->value("0");
+      input[45] = new Fl_Input(2 * WB, 2 * WB + 7 * BH, IW, BH, "Radius");
+      input[45]->value("1");
+      input[46] = new Fl_Input(2 * WB, 2 * WB + 8 * BH, IW, BH, "Angle");
+      input[46]->value("");
+      for(int i = 39; i < 47; i++)
+        input[i]->align(FL_ALIGN_RIGHT);
+      {
+        Fl_Return_Button *o = new Fl_Return_Button
+          (width - BB - 2 * WB, 2 * WB + 8 * BH, BB, BH, "Add");
+        o->callback(elementary_add_cylinder_cb);
+      }
       group[7]->end();
     }
     // 8: Block
     {
       group[8] = new Fl_Group
         (WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Block");
+      input[47] = new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "X");
+      input[47]->value("0");
+      input[48] = new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, "Y");
+      input[48]->value("0");
+      input[49] = new Fl_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, "Z");
+      input[49]->value("0");
+      input[50] = new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "DX");
+      input[50]->value("1");
+      input[51] = new Fl_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "DY");
+      input[51]->value("1");
+      input[52] = new Fl_Input(2 * WB, 2 * WB + 6 * BH, IW, BH, "DZ");
+      input[52]->value("1");
+      for(int i = 47; i < 53; i++)
+        input[i]->align(FL_ALIGN_RIGHT);
+      {
+        Fl_Return_Button *o = new Fl_Return_Button
+          (width - BB - 2 * WB, 2 * WB + 8 * BH, BB, BH, "Add");
+        o->callback(elementary_add_block_cb);
+      }
       group[8]->end();
     }
     // 9: Torus
@@ -399,6 +473,8 @@ void elementaryContextWindow::updatePoint(double pt[3], int which)
         input[21 + i]->value(str);
         input[26 + i]->value(str);
         input[32 + i]->value(str);
+        input[39 + i]->value(str);
+        input[47 + i]->value(str);
       }
     }
   }
diff --git a/Fltk/contextWindow.h b/Fltk/contextWindow.h
index 357f2757a6..ce2b3a4e3e 100644
--- a/Fltk/contextWindow.h
+++ b/Fltk/contextWindow.h
@@ -19,7 +19,7 @@ class elementaryContextWindow{
  public:
   Fl_Window *win;
   Fl_Tabs *tab1, *tab2;
-  Fl_Input *input[50];
+  Fl_Input *input[70];
   Fl_Value_Input *value[10];
   Fl_Group *group[20];
   Fl_Check_Button *_butt[3];
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index 289a515591..c0c0caf6b3 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -718,6 +718,24 @@ static void add_new_point_based_entity(const std::string &what, int pane)
                    FlGui::instance()->elementaryContext->input[38]->value());
         break;
       case 7:
+        add_cylinder(GModel::current()->getFileName(),
+                     FlGui::instance()->elementaryContext->input[39]->value(),
+                     FlGui::instance()->elementaryContext->input[40]->value(),
+                     FlGui::instance()->elementaryContext->input[41]->value(),
+                     FlGui::instance()->elementaryContext->input[42]->value(),
+                     FlGui::instance()->elementaryContext->input[43]->value(),
+                     FlGui::instance()->elementaryContext->input[44]->value(),
+                     FlGui::instance()->elementaryContext->input[45]->value(),
+                     FlGui::instance()->elementaryContext->input[46]->value());
+        break;
+      case 8:
+        add_block(GModel::current()->getFileName(),
+                  FlGui::instance()->elementaryContext->input[47]->value(),
+                  FlGui::instance()->elementaryContext->input[48]->value(),
+                  FlGui::instance()->elementaryContext->input[49]->value(),
+                  FlGui::instance()->elementaryContext->input[50]->value(),
+                  FlGui::instance()->elementaryContext->input[51]->value(),
+                  FlGui::instance()->elementaryContext->input[52]->value());
         break;
       }
       FlGui::instance()->resetVisibility();
@@ -1169,20 +1187,20 @@ static void geometry_elementary_add_new_cb(Fl_Widget *w, void *data)
     add_new_point_based_entity(str, 5);
   else if(str == "Sphere")
     add_new_point_based_entity(str, 6);
-  else if(str == "Block")
+  else if(str == "Cylinder")
     add_new_point_based_entity(str, 7);
-  else if(str == "Torus")
+  else if(str == "Block")
     add_new_point_based_entity(str, 8);
-  else if(str == "Cone")
+  else if(str == "Torus")
     add_new_point_based_entity(str, 9);
-  else if(str == "Wedge")
+  else if(str == "Cone")
     add_new_point_based_entity(str, 10);
+  else if(str == "Wedge")
+    add_new_point_based_entity(str, 11);
   else if(str == "Plane Surface")
     add_new_surface_volume(0);
   else if(str == "Surface")
     add_new_surface_volume(1);
-  else if(str == "Sphere")
-    add_new_point_based_entity(str, 11);
   else if(str == "Volume")
     add_new_surface_volume(2);
   else
diff --git a/Geo/GeoStringInterface.cpp b/Geo/GeoStringInterface.cpp
index 29652d6ebb..6de77b79c7 100644
--- a/Geo/GeoStringInterface.cpp
+++ b/Geo/GeoStringInterface.cpp
@@ -487,6 +487,29 @@ void add_sphere(const std::string &fileName, const std::string &x, const std::st
   add_infile(sstream.str(), fileName);
 }
 
+void add_cylinder(const std::string &fileName, const std::string &x, const std::string &y,
+                  const std::string &z, const std::string &dx, const std::string &dy,
+                  const std::string &dz, const std::string &r, const std::string &alpha)
+{
+  std::ostringstream sstream;
+  sstream << "Cylinder(" << NEWVOLUME() << ") = {" << x << "," << y << "," << z << ","
+          << dx << "," << dy << "," << dz << "," << r;
+  if(alpha.size())
+    sstream << ", " << alpha;
+  sstream << "};";
+  add_infile(sstream.str(), fileName);
+}
+
+void add_block(const std::string &fileName, const std::string &x, const std::string &y,
+               const std::string &z, const std::string &dx, const std::string &dy,
+               const std::string &dz)
+{
+  std::ostringstream sstream;
+  sstream << "Block(" << NEWVOLUME() << ") = {" << x << "," << y << "," << z << ","
+          << dx << "," << dy << "," << dz << "};";
+  add_infile(sstream.str(), fileName);
+}
+
 void translate(int add, List_T *list, const std::string &fileName,
                const std::string &what, const std::string &tx,
                const std::string &ty, const std::string &tz)
diff --git a/Geo/GeoStringInterface.h b/Geo/GeoStringInterface.h
index 8f7596601b..7672b9eb12 100644
--- a/Geo/GeoStringInterface.h
+++ b/Geo/GeoStringInterface.h
@@ -62,6 +62,12 @@ void add_sphere(const std::string &fileName, const std::string &x,
                 const std::string &y, const std::string &z, const std::string &r,
                 const std::string &alpha1, const std::string &alpha2,
                 const std::string &alpha3);
+void add_cylinder(const std::string &fileName, const std::string &x, const std::string &y,
+                  const std::string &z, const std::string &dx, const std::string &dy,
+                  const std::string &dz, const std::string &r, const std::string &alpha);
+void add_block(const std::string &fileName, const std::string &x, const std::string &y,
+               const std::string &z, const std::string &dx, const std::string &dy,
+               const std::string &dz);
 void translate(int add, List_T *list, const std::string &fileName,
                const std::string &what, const std::string &tx, const std::string &ty,
                const std::string &tz);
-- 
GitLab