From d3a32949f1ad8b76715c08553214b0e318f86685 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 26 Aug 2009 05:48:17 +0000
Subject: [PATCH] catch OCC exception in addShape

---
 Geo/GModelIO_OCC.cpp | 91 +++++++++++++++++++++++---------------------
 Geo/GModelIO_OCC.h   |  1 -
 2 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp
index 22063715fe..c67cf69e00 100644
--- a/Geo/GModelIO_OCC.cpp
+++ b/Geo/GModelIO_OCC.cpp
@@ -499,55 +499,60 @@ void GModel::addShape(std::string name, std::vector<double> &p,
   else if(op == "Fuse" || op == "Union") o = OCC_Internals::Fuse;
   else if(op == "Intersection") o = OCC_Internals::Intersection;
   
-  if (name == "Sphere"){
-    if (p.size() != 4){
-      Msg::Error("4 parameters have to be defined for a sphere");
-      return;
-    }
-    _occ_internals->Sphere(SPoint3(p[0],p[1],p[2]),p[3],o);
-  }
-  else if (name == "Cylinder"){
-    if (p.size() != 8){
-      Msg::Error("8 parameters have to be defined for a Cylinder");
-      return;
+  try{
+    if (name == "Sphere"){
+      if (p.size() != 4){
+        Msg::Error("4 parameters have to be defined for a sphere");
+        return;
+      }
+      _occ_internals->Sphere(SPoint3(p[0],p[1],p[2]),p[3],o);
     }
-    _occ_internals->Cylinder(SPoint3(p[0],p[1],p[2]),
-    			     SVector3(p[3],p[4],p[5]),p[6],p[7],o);
-  }
-  else if (name == "Torus"){
-    if (p.size() == 8){
-      _occ_internals->Torus(SPoint3(p[0],p[1],p[2]),
-			    SVector3(p[3],p[4],p[5]),p[6],p[7],o);
+    else if (name == "Cylinder"){
+      if (p.size() != 8){
+        Msg::Error("8 parameters have to be defined for a Cylinder");
+        return;
+      }
+      _occ_internals->Cylinder(SPoint3(p[0],p[1],p[2]),
+                               SVector3(p[3],p[4],p[5]),p[6],p[7],o);
     }
-    else if (p.size() == 9){
-      _occ_internals->Torus(SPoint3(p[0],p[1],p[2]),
-			    SVector3(p[3],p[4],p[5]),p[6],p[7],p[8],o);
+    else if (name == "Torus"){
+      if (p.size() == 8){
+        _occ_internals->Torus(SPoint3(p[0],p[1],p[2]),
+                              SVector3(p[3],p[4],p[5]),p[6],p[7],o);
+      }
+      else if (p.size() == 9){
+        _occ_internals->Torus(SPoint3(p[0],p[1],p[2]),
+                              SVector3(p[3],p[4],p[5]),p[6],p[7],p[8],o);
+      }
+      else{
+        Msg::Error("Wrong number of parameters for a Torus (8 or 9 is OK)");
+        return;
+      }
     }
-    else{
-      Msg::Error("Wrong number of parameters for a Torus (8 or 9 is OK)");
-      return;
+    else if (name == "Cone"){
+      if (p.size() != 9){
+        Msg::Error("9 parameters have to be defined for a Cone");
+        return;
+      }
+      _occ_internals->Cone(SPoint3(p[0],p[1],p[2]),
+                           SVector3(p[3],p[4],p[5]),p[6],p[7],p[8],o);
     }
-  }
-  else if (name == "Cone"){
-    if (p.size() != 9){
-      Msg::Error("9 parameters have to be defined for a Cone");
-      return;
+    else if (name == "Box"){
+      if (p.size() != 6){
+        Msg::Error("6 parameters have to be defined for a Box");
+        return;
+      }
+      _occ_internals->Box(SPoint3(p[0],p[1],p[2]),
+                          SPoint3(p[3],p[4],p[5]),o);
     }
-    _occ_internals->Cone(SPoint3(p[0],p[1],p[2]),
-			 SVector3(p[3],p[4],p[5]),p[6],p[7],p[8],o);
-  }
-  else if (name == "Box"){
-    if (p.size() != 6){
-      Msg::Error("6 parameters have to be defined for a Box");
-      return;
+    else{
+      // we should that at the end, a test now !!
+      _occ_internals->buildLists();
+      _occ_internals->buildGModel(this);
     }
-    _occ_internals->Box(SPoint3(p[0],p[1],p[2]),
-			SPoint3(p[3],p[4],p[5]),o);
   }
-  else{
-    // we should that at the end, a test now !!
-    _occ_internals->buildLists();
-    _occ_internals->buildGModel(this);
+  catch(Standard_Failure &err){
+    Msg::Error("%s", err.GetMessageString());
   }
 }
 
@@ -848,7 +853,7 @@ void OCC_Internals::Cone(const SPoint3 &p, const SVector3 &d, double R1,
   gp_Pnt aP(p.x(), p.y(), p.z());
   gp_Vec aV(d.x(), d.y(), d.z());
   gp_Ax2 anAxes(aP, aV);
-  BRepPrimAPI_MakeCone MC(anAxes, R1, R2,H);
+  BRepPrimAPI_MakeCone MC(anAxes, R1, R2, H);
   MC.Build();
   if (!MC.IsDone()) {
     Msg::Error("Cone can't be computed from the given parameters");
diff --git a/Geo/GModelIO_OCC.h b/Geo/GModelIO_OCC.h
index 3a4470ca86..c66c786344 100644
--- a/Geo/GModelIO_OCC.h
+++ b/Geo/GModelIO_OCC.h
@@ -48,7 +48,6 @@ class OCC_Internals {
   void buildLists();
   void removeAllDuplicates(const double &tolerance);
 
-  void Cone(const SPoint3 &p1, const SPoint3 &p2, const BooleanOperator &op);
   void Box(const SPoint3 &p1, const SPoint3 &p2, const BooleanOperator &op);
   void Sphere(const SPoint3 &center, const double &radius, const BooleanOperator &op);
   void Cylinder(const SPoint3 &bottom_center, const SVector3 &dir, double R, double H,
-- 
GitLab