Elimination of compiler warnings
[occt.git] / src / SWDRAW / SWDRAW_ShapeUpgrade.cxx
index c7a7e5a..aa50f2c 100644 (file)
 //pdn,gka 10.06.99 S4189: command DT_ShapeConvertRev added
 
 #include <BRep_Tool.hxx>
+#include <BRep_Builder.hxx>
 #include <BRepBuilderAPI.hxx>
 #include <BRepBuilderAPI_Transform.hxx>
 #include <BRepTools.hxx>
+#include <BRepTools_ReShape.hxx>
 #include <DBRep.hxx>
 #include <Draw.hxx>
 #include <Draw_Interpretor.hxx>
@@ -69,7 +71,7 @@
 #include <TopoDS_Shell.hxx>
 #include <TopoDS_Wire.hxx>
 
-#include <stdio.h>
+#include <stdio.h> 
 //#include <SWDRAW_ShapeUpgrade.hxx>
 //#include <ShapeUpgrade_SupportModification.hxx>
 //#include <ShapeExtend_WireData.hxx>
@@ -1258,7 +1260,7 @@ static Standard_Integer removeloc (Draw_Interpretor& di,
                                    const char** argv)
 {
   if (argc<3) {
-    di << "bad number of arguments. Should be:  removeloc res shape\n";
+    di << "bad number of arguments. Should be:  removeloc res shape [remove_level(see ShapeEnum)]\n";
     return 1;
   }
   
@@ -1266,6 +1268,8 @@ static Standard_Integer removeloc (Draw_Interpretor& di,
   if(aShape.IsNull())
     return 1;
   ShapeUpgrade_RemoveLocations aRemLoc;
+  if (argc > 3)
+    aRemLoc.SetRemoveLevel((TopAbs_ShapeEnum)Draw::Atoi(argv[3]));
   aRemLoc.Remove(aShape);
   TopoDS_Shape aNewShape = aRemLoc.GetResult();
   
@@ -1283,13 +1287,17 @@ static ShapeUpgrade_UnifySameDomain& Unifier() {
 //=======================================================================
 static Standard_Integer unifysamedom(Draw_Interpretor& di, Standard_Integer n, const char** a)
 {
-  if (n < 3 || n > 6)
+  if (n < 3)
   {
-    di << "Use unifysamedom result shape [-f] [-e] [+b]\n";
-    di << "where [-f]. [-e], [+b] is available options\n";
-    di << "[-f] to switch off 'unify-faces' mode \n";
-    di << "[-e] to switch off 'unify-edges' mode\n";
-    di << "[+b] to switch on a 'concat bspline' mode\n";
+    di << "Use unifysamedom result shape [s1 s2 ...] [-f] [-e] [+b] [+i] [-t val] [-a val]\n";
+    di << "options:\n";
+    di << "s1 s2 ... to keep the given edges during unification of faces\n";
+    di << "-f to switch off 'unify-faces' mode \n";
+    di << "-e to switch off 'unify-edges' mode\n";
+    di << "+b to switch on 'concat bspline' mode\n";
+    di << "+i to switch on 'allow internal edges' mode\n";
+    di << "-t val to set linear tolerance\n";
+    di << "-a val to set angular tolerance\n";
     di << "'unify-faces' and 'unify-edges' modes are switched on by default";
     return 1;
   }
@@ -1302,19 +1310,48 @@ static Standard_Integer unifysamedom(Draw_Interpretor& di, Standard_Integer n, c
   Standard_Boolean anUFaces = Standard_True;
   Standard_Boolean anUEdges = Standard_True;
   Standard_Boolean anConBS = Standard_False;
+  Standard_Boolean isAllowInternal = Standard_False;
+  Standard_Real aLinTol = Precision::Confusion();
+  Standard_Real aAngTol = Precision::Angular();
+  TopoDS_Shape aKeepShape;
+  TopTools_MapOfShape aMapOfShapes;
 
   if (n > 3)
     for ( int i = 3; i < n; i++ ) 
     {
-      if ( !strcmp(a[i], "-f")) 
-        anUFaces = Standard_False;
-      else if (!strcmp(a[i], "-e"))
-        anUEdges = Standard_False;
-      else if (!strcmp(a[i], "+b"))
-        anConBS = Standard_True;
+      aKeepShape = DBRep::Get(a[i]);
+      if (!aKeepShape.IsNull()) {
+        aMapOfShapes.Add(aKeepShape);
+      }
+      else {
+        if ( !strcmp(a[i], "-f")) 
+          anUFaces = Standard_False;
+        else if (!strcmp(a[i], "-e"))
+          anUEdges = Standard_False;
+        else if (!strcmp(a[i], "+b"))
+          anConBS = Standard_True;
+        else if (!strcmp(a[i], "+i"))
+          isAllowInternal = Standard_True;
+        else if (!strcmp(a[i], "-t") || !strcmp(a[i], "-a"))
+        {
+          if (++i < n)
+          {
+            (a[i-1][1] == 't' ? aLinTol : aAngTol) = Draw::Atof(a[i]);
+          }
+          else
+          {
+            di << "value expected after " << a[i-1];
+            return 1;
+          }
+        }
+      }
     }
 
   Unifier().Initialize(aShape, anUEdges, anUFaces, anConBS);
+  Unifier().KeepShapes(aMapOfShapes);
+  Unifier().AllowInternalEdges(isAllowInternal);
+  Unifier().SetLinearTolerance(aLinTol);
+  Unifier().SetAngularTolerance(aAngTol);
   Unifier().Build();
   TopoDS_Shape Result = Unifier().Shape();
 
@@ -1322,37 +1359,104 @@ static Standard_Integer unifysamedom(Draw_Interpretor& di, Standard_Integer n, c
   return 0;
 }
 
-Standard_Integer unifysamedomgen (Draw_Interpretor& di, 
-                                  Standard_Integer n, 
-                                  const char** a)
+Standard_Integer unifysamedomgen(Draw_Interpretor& di,
+                                 Standard_Integer n,
+                                 const char** a)
 {
-  if (n!=3) {
-    di << "use unifysamedomgen newshape oldshape";
+  if (n != 3) {
+    di << "use unifysamedomgen newshape oldshape\n";
     return 0;
   }
   TopoDS_Shape aShape;
-  aShape=DBRep::Get(a[2]);
+  aShape = DBRep::Get(a[2]);
   if (aShape.IsNull()) {
-    di<<" null shape is not allowed here\n";
+    di << "Null shape is not allowed here\n";
     return 1;
   }
-  TopoDS_Shape ResShape = Unifier().Generated(aShape);
-  if (ResShape.IsNull()) {
-    di << " null shape\n";
+
+  const TopTools_ListOfShape& aLS = Unifier().Generated(aShape);
+
+  if (aLS.Extent() > 1) {
+    BRep_Builder aBB;
+    TopoDS_Compound aRes;
+    aBB.MakeCompound(aRes);
+    TopTools_ListIteratorOfListOfShape aIt(aLS);
+    for (; aIt.More(); aIt.Next()) {
+      const TopoDS_Shape& aCurrentShape = aIt.Value();
+      aBB.Add(aRes, aCurrentShape);
+    }
+    DBRep::Set(a[1], aRes);
+  }
+  else if (aLS.Extent() == 1) {
+    DBRep::Set(a[1], aLS.First());
   }
   else {
-    DBRep::Set(a[1], ResShape);
+    di << "No shapes were generated from the shape\n";
   }
   return 0;
 }
 
+Standard_Integer unifysamedommod(Draw_Interpretor& di,
+                                 Standard_Integer n,
+                                 const char** a)
+{
+  if (n != 3) {
+    di << "use unifysamedommod newshape oldshape\n";
+    return 0;
+  }
+  TopoDS_Shape aShape;
+  aShape = DBRep::Get(a[2]);
+  if (aShape.IsNull()) {
+    di << "Null shape is not allowed here\n";
+    return 1;
+  }
+
+  const TopTools_ListOfShape& aLS = Unifier().Modified(aShape);
+
+  if (aLS.Extent() > 1) {
+    BRep_Builder aBB;
+    TopoDS_Compound aRes;
+    aBB.MakeCompound(aRes);
+    TopTools_ListIteratorOfListOfShape aIt(aLS);
+    for (; aIt.More(); aIt.Next()) {
+      const TopoDS_Shape& aCurrentShape = aIt.Value();
+      aBB.Add(aRes, aCurrentShape);
+    }
+    DBRep::Set(a[1], aRes);
+  }
+  else if (aLS.Extent() == 1) {
+    DBRep::Set(a[1], aLS.First());
+  }
+  else {
+    di << "The shape has not been modified\n";
+  }
+  return 0;
+}
+
+Standard_Integer unifysamedomisdel(Draw_Interpretor& di,
+                                   Standard_Integer n,
+                                   const char** a)
+{
+  if (n < 2) {
+    di << "Use: unifysamedomisdel shape\n";
+    return 1;
+  }
+  TopoDS_Shape aShape = DBRep::Get(a[1]);
+  if (aShape.IsNull()) {
+    di << "Null shape is not allowed here\n";
+    return 1;
+  }
+  Standard_Boolean IsDeleted = Unifier().IsDeleted(aShape);
+  di << "The shape has" << (IsDeleted ? " " : " not ") << "been deleted" << "\n";
+  return 0;
+}
 
 static Standard_Integer copytranslate(Draw_Interpretor& di, 
                                    Standard_Integer argc, 
                                    const char** argv)
 {
   if (argc<6) {
-    di << "bad number of arguments. Should be:  removeloc res shape dx dyy dz\n";
+    di << "bad number of arguments. Should be:  copytranslate res shape dx dy dz\n";
     return 1;
   }
   TopoDS_Shape aShape = DBRep::Get(argv[2]);
@@ -1371,6 +1475,87 @@ static Standard_Integer copytranslate(Draw_Interpretor& di,
   
 }
 
+Standard_Integer reshape(Draw_Interpretor& di,
+                         Standard_Integer n,
+                         const char** a)
+{
+  if ( n < 3 )
+  {
+    di << "Error: wrong number of arguments. Type 'help " << a[0] << "'\n";
+    return 1;
+  }
+
+  TopoDS_Shape source = DBRep::Get(a[2]);
+  if ( source.IsNull() )
+  {
+    di << "Error: source shape ('" << a[2] << "') is null\n";
+    return 1;
+  }
+
+  Handle(BRepTools_ReShape) ReShaper = new BRepTools_ReShape;
+
+  // Record the requested modifications
+  for ( Standard_Integer i = 1; i < n; ++i )
+  {
+    Standard_CString        arg = a[i];
+    TCollection_AsciiString opt(arg);
+    opt.LowerCase();
+
+    if ( opt == "-replace" )
+    {
+      if ( n - i < 3 )
+      {
+        di << "Error: not enough arguments for replacement\n";
+        return 1;
+      }
+
+      TopoDS_Shape what = DBRep::Get(a[++i]);
+      if ( what.IsNull() )
+      {
+        di << "Error: argument shape ('" << a[i] << "') is null\n";
+        return 1;
+      }
+
+      TopoDS_Shape with = DBRep::Get(a[++i]);
+      if ( with.IsNull() )
+      {
+        di << "Error: replacement shape ('" << a[i] << "') is null\n";
+        return 1;
+      }
+
+      ReShaper->Replace(what, with);
+    }
+    else if ( opt == "-remove" )
+    {
+      if ( n - i < 2 )
+      {
+        di << "Error: not enough arguments for removal\n";
+        return 1;
+      }
+
+      TopoDS_Shape what = DBRep::Get(a[++i]);
+      if ( what.IsNull() )
+      {
+        di << "Error: shape to remove ('" << a[i] << "') is null\n";
+        return 1;
+      }
+
+      ReShaper->Remove(what);
+    }
+  }
+
+  // Apply all the recorded modifications
+  TopoDS_Shape result = ReShaper->Apply(source);
+  if ( result.IsNull() )
+  {
+    di << "Error: result shape is null\n";
+    return 1;
+  }
+
+  DBRep::Set(a[1], result);
+  return 0;
+}
+
 //=======================================================================
 //function : InitCommands
 //purpose  : 
@@ -1466,15 +1651,31 @@ static Standard_Integer copytranslate(Draw_Interpretor& di,
   theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]",
                    __FILE__,removeinternalwires,g);
   
-  theCommands.Add ("removeloc","result shape",__FILE__,removeloc,g);
+  theCommands.Add ("removeloc","result shape [remove_level(see ShapeEnum)]",__FILE__,removeloc,g);
   
   theCommands.Add ("unifysamedom",
-                   "unifysamedom result shape [-f] [-e] [+b]", __FILE__,unifysamedom,g);
-
-  theCommands.Add ("unifysamedomgen",
-                   "unifysamedomgen newshape oldshape : get new shape generated "
-                   "by unifysamedom command from the old one",
-                   __FILE__,unifysamedomgen,g);
+                   "unifysamedom result shape [s1 s2 ...] [-f] [-e] [+b] [+i] [-t val] [-a val]", __FILE__,unifysamedom,g);
+  
+  theCommands.Add("unifysamedomgen",
+                  "unifysamedomgen newshape oldshape : get new shape generated "
+                  "by unifysamedom command from the old one",
+                  __FILE__, unifysamedomgen, g);
+
+  theCommands.Add("unifysamedommod",
+                  "unifysamedommod newshape oldshape : get new shape modified "
+                  "by unifysamedom command from the old one",
+                  __FILE__, unifysamedommod, g);
+
+  theCommands.Add("unifysamedomisdel",
+                  "unifysamedomisdel shape : shape is deleted ",
+                  __FILE__, unifysamedomisdel, g);
   
   theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g);
+
+  theCommands.Add ("reshape",
+    "\n    Basic utility for topological modification: "
+    "\n      '-replace what with'   Replaces 'what' sub-shape with 'with' sub-shape"
+    "\n      '-remove what'         Removes 'what' sub-shape"
+    "\n    Requests '-replace' and '-remove' can be repeated many times.",
+    __FILE__, reshape, g);
 }