LCOV - code coverage report
Current view: top level - geom/OCC - OCCModifyEngine.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 1808 5304 34.1 %
Date: 2020-06-30 00:58:45 Functions: 56 160 35.0 %
Branches: 2977 16084 18.5 %

           Branch data     Line data    Source code
       1                 :            : //-------------------------------------------------------------------------
       2                 :            : //-------------------------------------------------------------------------
       3                 :            : 
       4                 :            : // Filename      : OCCModifyEngine.cpp
       5                 :            : //
       6                 :            : // Purpose       : ModifyEngine for OCC geometry
       7                 :            : //
       8                 :            : // Special Notes : Modeled after GeometryModifyEngine
       9                 :            : //
      10                 :            : // Author        : Jane Hu
      11                 :            : //
      12                 :            : // Creation Date : 1/08
      13                 :            : //
      14                 :            : //-------------------------------------------------------------------------
      15                 :            : #include "gp_Pnt.hxx"
      16                 :            : #include "gp_Ax2.hxx"
      17                 :            : #include "gp_Dir.hxx"
      18                 :            : #include "gp_Hypr.hxx"
      19                 :            : #include "gp_Parab.hxx"
      20                 :            : #include "gp_Elips.hxx"
      21                 :            : #include "gp_Pln.hxx"
      22                 :            : #include "gp_Circ.hxx"
      23                 :            : #include "gp_Cylinder.hxx"
      24                 :            : #include "gp_Cone.hxx"
      25                 :            : #include "gp_Sphere.hxx"
      26                 :            : #include "gp_Torus.hxx"
      27                 :            : #include "BRepOffsetAPI_MakeOffset.hxx"
      28                 :            : #include "BRepBuilderAPI_MakeShell.hxx"
      29                 :            : #include "BRepBuilderAPI_MakeSolid.hxx"
      30                 :            : #include "BRepOffsetAPI_MakeDraft.hxx"
      31                 :            : #include "BRepBuilderAPI_TransitionMode.hxx"
      32                 :            : #include "BRepBuilderAPI_MakeWire.hxx"
      33                 :            : #include "BRepPrimAPI_MakeHalfSpace.hxx"
      34                 :            : #include "BRepBuilderAPI_MakePolygon.hxx"
      35                 :            : #include "BRepBuilderAPI_Sewing.hxx"
      36                 :            : #include "BRepBndLib.hxx"
      37                 :            : #include "IntersectionTool.hpp"
      38                 :            : #include "TopoDS_Shape.hxx"
      39                 :            : #include "TopoDS_Compound.hxx"
      40                 :            : #include "TopAbs_Orientation.hxx"
      41                 :            : #include "TopOpeBRep_Point2d.hxx"
      42                 :            : #include "TColgp_Array1OfPnt.hxx"
      43                 :            : #include "TColgp_HArray1OfPnt.hxx"
      44                 :            : #include "TColStd_HArray1OfBoolean.hxx"
      45                 :            : #include "TColgp_Array1OfVec.hxx"
      46                 :            : #include "TColStd_Array1OfReal.hxx"
      47                 :            : #include "TColStd_Array1OfInteger.hxx"
      48                 :            : #include "GC_MakeArcOfCircle.hxx"
      49                 :            : #include "GC_MakeCircle.hxx"
      50                 :            : #include "Geom_Circle.hxx"
      51                 :            : #include "Geom_SurfaceOfLinearExtrusion.hxx"
      52                 :            : #include "Geom_RectangularTrimmedSurface.hxx"
      53                 :            : #include "Geom_BSplineCurve.hxx"
      54                 :            : #include "Handle_Geom_RectangularTrimmedSurface.hxx"
      55                 :            : #include "GC_MakeArcOfHyperbola.hxx"
      56                 :            : #include "GC_MakeArcOfParabola.hxx"
      57                 :            : #include "GC_MakeArcOfEllipse.hxx"
      58                 :            : #include "GC_MakeSegment.hxx"
      59                 :            : #include "GC_MakeTrimmedCone.hxx"
      60                 :            : #include "GC_MakeTrimmedCylinder.hxx"
      61                 :            : #include "gce_MakeElips.hxx"
      62                 :            : #include "BRepFilletAPI_MakeFillet.hxx"
      63                 :            : #include "BRepFilletAPI_MakeChamfer.hxx"
      64                 :            : #include "BRepAdaptor_CompCurve.hxx"
      65                 :            : #include "GeomAPI_Interpolate.hxx"
      66                 :            : #include "BRepFilletAPI_MakeFillet2d.hxx"
      67                 :            : #include "ChFi2d_ConstructionError.hxx"
      68                 :            : #include "Geom_BezierCurve.hxx"
      69                 :            : #include "BndLib_AddSurface.hxx"
      70                 :            : #include "Handle_Geom_Plane.hxx"
      71                 :            : #include "Handle_Geom_OffsetCurve.hxx"
      72                 :            : #include "Geom_OffsetCurve.hxx"
      73                 :            : #include "BRepExtrema_DistShapeShape.hxx"
      74                 :            : #include "Extrema_ExtPC.hxx"
      75                 :            : #include "BRepPrimAPI_MakePrism.hxx"
      76                 :            : #include "BRepSweep_Revol.hxx"
      77                 :            : #include "BRepPrimAPI_MakeCone.hxx"
      78                 :            : #include "BRepOffsetAPI_ThruSections.hxx"
      79                 :            : #include "BRepLib_FuseEdges.hxx"
      80                 :            : #include "BRepOffsetAPI_MakePipe.hxx"
      81                 :            : #include "BRepPrimAPI_MakeTorus.hxx"
      82                 :            : #include "BRepPrimAPI_MakeCylinder.hxx"
      83                 :            : #include "BRepBuilderAPI_Transform.hxx"
      84                 :            : #include "BRepAdaptor_Curve.hxx"
      85                 :            : #include "GC_MakeEllipse.hxx"
      86                 :            : #include "BRepBuilderAPI_MakeEdge.hxx"
      87                 :            : #include "BRepAdaptor_Surface.hxx"
      88                 :            : #include "BRepBuilderAPI_MakeFace.hxx"
      89                 :            : #include "ShapeExtend_Status.hxx"
      90                 :            : #include "BRepOffsetAPI_MakeThickSolid.hxx"
      91                 :            : #include "BRepBuilderAPI_Sewing.hxx"
      92                 :            : #include "BRepBuilderAPI_Copy.hxx"
      93                 :            : #include "LocOpe_SplitShape.hxx"
      94                 :            : #include "BRep_Tool.hxx"
      95                 :            : #include "BRep_Builder.hxx"
      96                 :            : #include "GProp_GProps.hxx"
      97                 :            : #include "BRepGProp.hxx"
      98                 :            : #include "TopoDS.hxx"
      99                 :            : #include "ShapeFix.hxx"
     100                 :            : #include "TopologyBridge.hpp"
     101                 :            : #include "ProgressTool.hpp"
     102                 :            : #include "BRepAlgoAPI_Fuse.hxx"
     103                 :            : #include "BRepAlgoAPI_Cut.hxx"
     104                 :            : #include "BRepAlgoAPI_Section.hxx"
     105                 :            : #include "BRepAlgoAPI_Common.hxx"
     106                 :            : #include "BRepPrimAPI_MakeSphere.hxx"
     107                 :            : #include "BRepPrimAPI_MakeBox.hxx"
     108                 :            : #include "BRepPrimAPI_MakeWedge.hxx"
     109                 :            : #include "BRepTools_WireExplorer.hxx"
     110                 :            : #include "Handle_Geom_TrimmedCurve.hxx"
     111                 :            : #include "Handle_ShapeBuild_ReShape.hxx"
     112                 :            : #include "ShapeBuild_ReShape.hxx"
     113                 :            : #include "Handle_Geom_RectangularTrimmedSurface.hxx"
     114                 :            : #include "BndLib_Add3dCurve.hxx"
     115                 :            : #include "TopOpeBRep_EdgesIntersector.hxx"
     116                 :            : #include "TopExp_Explorer.hxx"
     117                 :            : #include "TopExp.hxx"
     118                 :            : #ifndef OCC_VERSION_MINOR
     119                 :            : #include "Standard_Version.hxx"
     120                 :            : #endif
     121                 :            : 
     122                 :            : #include "OCCDrawTool.hpp"
     123                 :            : #include "OCCModifyEngine.hpp"
     124                 :            : #include "OCCQueryEngine.hpp"
     125                 :            : #include "CubitMessage.hpp"
     126                 :            : #include "CubitDefines.h"
     127                 :            : #include "TopTools_DataMapOfShapeInteger.hxx"
     128                 :            : #include "BRepFeat_SplitShape.hxx"
     129                 :            : #include "TopOpeBRep_ShapeIntersector.hxx"
     130                 :            : #include "TopTools_ListIteratorOfListOfShape.hxx"
     131                 :            : #include "CubitUtil.hpp"
     132                 :            : #include "GeometryQueryTool.hpp"
     133                 :            : #include "GeometryModifyTool.hpp"
     134                 :            : #include "OCCCoEdge.hpp"
     135                 :            : #include "OCCLoop.hpp"
     136                 :            : #include "OCCSurface.hpp"
     137                 :            : #include "OCCShell.hpp"
     138                 :            : #include "OCCLump.hpp"
     139                 :            : #include "OCCBody.hpp"
     140                 :            : #include "OCCCurve.hpp"
     141                 :            : #include "OCCPoint.hpp"
     142                 :            : #include "OCCAttribSet.hpp"
     143                 :            : #include "CubitFileIOWrapper.hpp"
     144                 :            : #include "Body.hpp"
     145                 :            : #include "GfxDebug.hpp"
     146                 :            : #include "RefFace.hpp"
     147                 :            : #include "CpuTimer.hpp"
     148                 :            : #include "AppUtil.hpp"
     149                 :            : #include "SphereEvaluator.hpp"
     150                 :            : #include "CylinderEvaluator.hpp"
     151                 :            : #include "GfxPreview.hpp"
     152                 :            : #include <vector>
     153                 :            : #include "CGMEngineDynamicLoader.hpp"
     154                 :            : 
     155                 :          0 : CGM_ENGINE_EXPORT_CREATE_GME(OpenCascade)
     156                 :            : {
     157                 :          0 :   return OCCModifyEngine::instance();
     158                 :            : }
     159                 :            : 
     160                 :            : OCCModifyEngine* OCCModifyEngine::instance_ = 0;
     161                 :            : typedef std::map<OCCSurface*, std::pair<CubitVector, int> >::value_type valType;
     162                 :            : typedef std::map<OCCCurve*, std::pair<CubitVector, int> >::value_type valType2;
     163                 :            : #define DEBUG
     164                 :            : double TOL = 0.0;
     165                 :            : //===============================================================================
     166                 :            : // Function   : OCCModifyEngine
     167                 :            : // Member Type: PUBLIC
     168                 :            : // Description: constructor
     169                 :            : // Author     : John Fowler
     170                 :            : // Date       : 10/02
     171                 :            : //===============================================================================
     172                 :       1682 : OCCModifyEngine::OCCModifyEngine()
     173                 :            : {
     174                 :            : //  assert( !instance_ );
     175                 :            : 
     176                 :            :     // add this modify engine to geometrymodifytool
     177 [ +  - ][ +  - ]:        841 :   GeometryModifyTool::instance()->add_gme(this);
     178 [ +  - ][ +  - ]:        841 :   TOL = OCCQueryEngine::instance()->get_sme_resabs_tolerance();
     179                 :        841 : }
     180                 :            : 
     181                 :            : 
     182                 :            : //===============================================================================
     183                 :            : // Function   : ~OCCModifyEngine
     184                 :            : // Member Type: PUBLIC
     185                 :            : // Description: destructor
     186                 :            : // Author     : John Fowler
     187                 :            : // Date       : 10/02
     188                 :            : //===============================================================================
     189                 :        813 : OCCModifyEngine::~OCCModifyEngine() 
     190                 :            : {
     191                 :        271 :         instance_ = 0;
     192         [ -  + ]:        542 : }
     193                 :            : 
     194                 :            : //===============================================================================
     195                 :            : // Function   : make_Point
     196                 :            : // Member Type: PUBLIC
     197                 :            : // Description: make a geometric entity point
     198                 :            : // Author     : Jane Hu 
     199                 :            : // Date       : 10/07
     200                 :            : //===============================================================================
     201                 :        385 : TBPoint* OCCModifyEngine::make_Point( CubitVector const& point) const
     202                 :            : {
     203 [ +  - ][ +  - ]:        385 :   gp_Pnt pt = gp_Pnt( point.x(), point.y(), point.z());
         [ +  - ][ +  - ]
     204 [ +  - ][ +  - ]:        385 :   TopoDS_Vertex theVertex = BRepBuilderAPI_MakeVertex(pt);
                 [ +  - ]
     205                 :            : 
     206                 :            :   // Create a new Point object
     207 [ +  - ][ +  - ]:        385 :   return OCCQueryEngine::instance()->populate_topology_bridge( theVertex, true );
                 [ +  - ]
     208                 :            : }
     209                 :            : 
     210                 :            : //===============================================================================
     211                 :            : // Function   : make_Curve
     212                 :            : //              This function creates a curve given an existing curve, copy. 
     213                 :            : // Member Type: PUBLIC
     214                 :            : // Description: make a curve
     215                 :            : // Author     : Jane Hu
     216                 :            : // Date       : 01/08
     217                 :            : //===============================================================================
     218                 :          0 : Curve* OCCModifyEngine::make_Curve(Curve * curve_ptr, std::map<TopologyBridge*, TopologyBridge*> * /*old_tb_to_new_tb*/) const
     219                 :            : {
     220         [ #  # ]:          0 :   OCCCurve* occ_curve = CAST_TO(curve_ptr, OCCCurve);
     221         [ #  # ]:          0 :   if (!occ_curve)
     222                 :            :   {
     223 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Cannot create an OCC curve from the given curve.\n"
                 [ #  # ]
     224         [ #  # ]:          0 :                  "Possible incompatible geometry engines.\n");
     225                 :          0 :      return (Curve *)NULL;
     226                 :            :   }
     227                 :            :  
     228         [ #  # ]:          0 :   TopoDS_Edge *theEdge = occ_curve->get_TopoDS_Edge();  
     229                 :            :  
     230         [ #  # ]:          0 :   BRepBuilderAPI_Copy api_copy(*theEdge);
     231                 :            : 
     232 [ #  # ][ #  # ]:          0 :   TopoDS_Shape newShape = api_copy.ModifiedShape(*theEdge);
                 [ #  # ]
     233                 :            :  
     234 [ #  # ][ #  # ]:          0 :   TopoDS_Edge newEdge = TopoDS::Edge(newShape);
                 [ #  # ]
     235                 :            : 
     236 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->copy_attributes(*theEdge, newEdge);
     237                 :            : 
     238 [ #  # ][ #  # ]:          0 :   return OCCQueryEngine::instance()->populate_topology_bridge(newEdge, true);
                 [ #  # ]
     239                 :            : }
     240                 :            : 
     241                 :            : //===============================================================================
     242                 :            : // Function   : make_Curve
     243                 :            : // Member Type: PUBLIC
     244                 :            : // Description: make a curve by projecting a straight line defined by 
     245                 :            : //              point1_ptr, and point2_ptr onto face_ptr, third_point
     246                 :            : //              is used for curves that could be periodic to dertermine
     247                 :            : //              the correct direction.
     248                 :            : // Author     : Jane Hu
     249                 :            : // Date       : 01/08
     250                 :            : //===============================================================================
     251                 :        132 : Curve* OCCModifyEngine::make_Curve( TBPoint const* point1_ptr,
     252                 :            :                              TBPoint const* point2_ptr,
     253                 :            :                              Surface* face_ptr,
     254                 :            :                              const CubitVector * third_point) const
     255                 :            : {
     256 [ +  - ][ -  + ]:        132 :   assert (point1_ptr != NULL && point2_ptr != NULL);
     257                 :        132 :   GeometryType type = STRAIGHT_CURVE_TYPE;
     258                 :        132 :   CubitBoolean closed = CUBIT_FALSE;
     259         [ +  - ]:        132 :   DLIList<CubitVector*> mid_points;
     260                 :        132 :   Curve* curve = NULL;
     261         [ +  - ]:        132 :   if (point1_ptr != point2_ptr)
     262         [ +  - ]:        132 :     curve = make_Curve(type, point1_ptr, point2_ptr, mid_points);
     263                 :            :   else //could be a closed shape
     264                 :            :   {
     265 [ #  # ][ #  # ]:          0 :     if(third_point != NULL && face_ptr != NULL) 
     266                 :            :     {
     267                 :          0 :        closed = CUBIT_TRUE;
     268         [ #  # ]:          0 :        TBPoint * Pnt = make_Point(*third_point);
     269         [ #  # ]:          0 :        curve = make_Curve(type, point1_ptr, Pnt, mid_points);
     270                 :            :     }
     271                 :            :     else
     272                 :            :     {
     273 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Cannot create an OCC curve from the given duplicated points.\n");
         [ #  # ][ #  # ]
     274                 :          0 :        return (Curve *)NULL;
     275                 :            :     }
     276                 :            :   }
     277                 :            : 
     278                 :        132 :   Curve* new_curve = NULL;
     279         [ +  - ]:        132 :   if(face_ptr == NULL)
     280                 :        132 :     return curve;
     281                 :            :  
     282 [ #  # ][ #  # ]:          0 :   DLIList<TBPoint*> points;
     283                 :            :   
     284                 :            :   new_curve = 
     285                 :            :     CAST_TO(curve, OCCCurve)->
     286 [ #  # ][ #  # ]:          0 :            project_curve(face_ptr, points, closed, third_point);
     287 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->delete_solid_model_entities( curve );
     288         [ +  - ]:        132 :   return new_curve;
     289                 :            : }
     290                 :            : 
     291                 :            : //===============================================================================
     292                 :            : // Function   : make_Curve
     293                 :            : // Member Type: PUBLIC
     294                 :            : // Description: make a  spline curve by using the points and tangents.
     295                 :            : //              size of point list and tangents must be the same.
     296                 :            : //              values in the tangent list may be null.
     297                 :            : // Author     : Jane Hu
     298                 :            : // Date       : 01/11
     299                 :            : //===============================================================================
     300                 :          0 : Curve* OCCModifyEngine::make_Curve( DLIList<CubitVector*>& point_list,
     301                 :            :                              DLIList<CubitVector*>& point_tangents) const
     302                 :            : {
     303 [ #  # ][ #  # ]:          0 :     if (point_list.size() != point_tangents.size())
                 [ #  # ]
     304                 :            :     {
     305 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("    point list and tangent list must have same size\n");
         [ #  # ][ #  # ]
     306                 :          0 :         return (Curve *)NULL;
     307                 :            :     }
     308                 :            : 
     309 [ #  # ][ #  # ]:          0 :     if(point_list.size() < 2)
     310                 :            :     {
     311 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("    Can't create a curve with less than 2 points\n");
         [ #  # ][ #  # ]
     312                 :          0 :         return (Curve *)NULL;
     313                 :            :     }
     314                 :            : 
     315         [ #  # ]:          0 :     int size = point_list.size();
     316 [ #  # ][ #  # ]:          0 :     Handle(TColgp_HArray1OfPnt) points = new TColgp_HArray1OfPnt(1, size);
                 [ #  # ]
     317 [ #  # ][ #  # ]:          0 :     TColgp_Array1OfVec tangents(1, size);
     318                 :            :     Handle(TColStd_HArray1OfBoolean) tangentFlags = 
     319 [ #  # ][ #  # ]:          0 :                                      new TColStd_HArray1OfBoolean(1,size);
         [ #  # ][ #  # ]
     320 [ #  # ][ #  # ]:          0 :     gp_Pnt pt, pt1;
     321                 :            :     CubitVector *pt_vec, *tangent_vec;
     322         [ #  # ]:          0 :     gp_Vec tangent;
     323         [ #  # ]:          0 :     for (int i = 1 ; i <= size; i++)
     324                 :            :     {
     325         [ #  # ]:          0 :         pt_vec = point_list.get_and_step();
     326 [ #  # ][ #  # ]:          0 :         pt.SetCoord(pt_vec->x(), pt_vec->y(), pt_vec->z()); 
         [ #  # ][ #  # ]
     327         [ #  # ]:          0 :         if(i == 1)
     328                 :          0 :           pt1 = pt; 
     329 [ #  # ][ #  # ]:          0 :         points->SetValue(i, pt);
     330                 :            : 
     331         [ #  # ]:          0 :         tangent_vec = point_tangents.get_and_step();
     332         [ #  # ]:          0 :         if (!tangent_vec)
     333                 :            :         {
     334         [ #  # ]:          0 :           tangents.SetValue(i,tangent);
     335 [ #  # ][ #  # ]:          0 :           tangentFlags->SetValue(i, CUBIT_FALSE);
     336                 :            :         }
     337                 :            :         else 
     338                 :            :         {
     339 [ #  # ][ #  # ]:          0 :           tangent.SetCoord(tangent_vec->x(), tangent_vec->y(),
     340 [ #  # ][ #  # ]:          0 :                            tangent_vec->z());
     341         [ #  # ]:          0 :           tangents.SetValue(i,tangent);
     342 [ #  # ][ #  # ]:          0 :           tangentFlags->SetValue(i, CUBIT_TRUE);
     343                 :            :         }
     344                 :            :     }
     345 [ #  # ][ #  # ]:          0 :     GeomAPI_Interpolate interpolater(points, CUBIT_FALSE, TOL);
     346         [ #  # ]:          0 :     interpolater.Load(tangents, tangentFlags);
     347         [ #  # ]:          0 :     interpolater.Perform() ;
     348 [ #  # ][ #  # ]:          0 :     Handle(Geom_BSplineCurve) pcurve;
     349 [ #  # ][ #  # ]:          0 :     if(interpolater.IsDone())
     350 [ #  # ][ #  # ]:          0 :       pcurve = interpolater.Curve();
     351                 :            :     
     352                 :            :     else
     353                 :            :     {
     354 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Can't create a curve using provided points and tangents.\n");
         [ #  # ][ #  # ]
     355                 :          0 :       return (Curve *)NULL;
     356                 :            :     }
     357                 :            :    
     358 [ #  # ][ #  # ]:          0 :     TopoDS_Edge topo_edge = BRepBuilderAPI_MakeEdge(pcurve, pt1, pt);
         [ #  # ][ #  # ]
     359 [ #  # ][ #  # ]:          0 :     return OCCQueryEngine::instance()->populate_topology_bridge(topo_edge, true);
                 [ #  # ]
     360                 :            : }
     361                 :            : 
     362                 :            : //===============================================================================
     363                 :            : // Function   : make_Curve
     364                 :            : // Member Type: PUBLIC
     365                 :            : // Description: make a  spline curve by using the points on surface.
     366                 :            : // Author     : Jane Hu
     367                 :            : // Date       : 01/08
     368                 :            : //===============================================================================
     369                 :        143 : Curve* OCCModifyEngine::make_Curve( GeometryType curve_type,
     370                 :            :                              TBPoint const* point1_ptr,
     371                 :            :                              TBPoint const* point2_ptr,
     372                 :            :                              DLIList<CubitVector*>& vector_list,
     373                 :            :                              Surface* face_ptr) const
     374                 :            : {
     375 [ +  - ][ -  + ]:        143 :   assert(point1_ptr != NULL && point2_ptr != NULL);
     376                 :            :   
     377         [ +  + ]:        143 :   if (curve_type != SPLINE_CURVE_TYPE
     378         [ -  + ]:        132 :       && curve_type != STRAIGHT_CURVE_TYPE)
     379                 :            :   {
     380 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Cannot create an OCC curve from the given curve_type.\n"
                 [ #  # ]
     381         [ #  # ]:          0 :                  "Candidates are SPLINE_CURVE_TYPE and STRAIGHT_CURVE_TYPE.\n");
     382                 :          0 :      return (Curve *)NULL;
     383                 :            :   }
     384                 :            : 
     385         [ +  + ]:        143 :   if (curve_type == STRAIGHT_CURVE_TYPE)
     386         [ +  - ]:        132 :     return make_Curve(curve_type, point1_ptr, point2_ptr, NULL);
     387                 :            : 
     388         [ -  + ]:         11 :   OCCPoint* occ_point1 = CAST_TO(const_cast<TBPoint*>(point1_ptr), OCCPoint);
     389         [ -  + ]:         11 :   OCCPoint* occ_point2 = CAST_TO(const_cast<TBPoint*>(point2_ptr), OCCPoint);
     390                 :            : 
     391 [ +  - ][ -  + ]:         11 :   if (occ_point1 == NULL || occ_point2 == NULL)
     392                 :            :   {
     393 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Cannot create an OCC curve from the given points.\n"
                 [ #  # ]
     394         [ #  # ]:          0 :                  "Possible incompatible geometry engines.\n");
     395                 :          0 :      return (Curve *)NULL;
     396                 :            :   }
     397                 :            :     
     398                 :            :   //project all points on the surface if possible
     399                 :         11 :   OCCSurface* occ_face = NULL;
     400         [ -  + ]:         11 :   if (face_ptr != NULL)
     401         [ #  # ]:          0 :      occ_face = CAST_TO(face_ptr, OCCSurface);
     402                 :            :  
     403         [ +  - ]:         11 :   gp_Pnt pt;
     404         [ +  - ]:         11 :   int size = vector_list.size();
     405 [ +  - ][ +  - ]:         11 :   Handle(TColgp_HArray1OfPnt) points = new TColgp_HArray1OfPnt(1, size);
                 [ +  - ]
     406         [ +  - ]:         11 :   CubitVector vector;
     407         [ +  - ]:         11 :   CubitVector closest_location;
     408         [ +  + ]:         77 :   for(int i = 1; i <= size; i++)
     409                 :            :   {
     410 [ +  - ][ +  - ]:         66 :      vector = *vector_list.get_and_step();
     411 [ +  - ][ +  - ]:         66 :      pt.SetCoord(vector.x(), vector.y(), vector.z());
         [ +  - ][ +  - ]
     412                 :            : 
     413         [ -  + ]:         66 :      if (occ_face != NULL)
     414                 :            :      {
     415         [ #  # ]:          0 :        occ_face->closest_point(vector, &closest_location);
     416 [ #  # ][ #  # ]:          0 :        pt.SetCoord(closest_location.x(), closest_location.y(), closest_location.z()) ;           
         [ #  # ][ #  # ]
     417                 :            :      }
     418                 :            : 
     419 [ +  - ][ +  - ]:         66 :      points->SetValue(i, pt);
     420                 :            :   }    
     421                 :            :      
     422                 :            :   //make curve according to the curve type.
     423         [ +  - ]:         11 :   if(curve_type == SPLINE_CURVE_TYPE)
     424                 :            :   {
     425         [ -  + ]:         11 :     if (size < 3)
     426                 :            :     {
     427 [ #  # ][ #  # ]:          0 :       PRINT_ERROR(" Must have at least 3 points to make a spline. \n");
         [ #  # ][ #  # ]
     428                 :         11 :       return (Curve*) NULL;
     429                 :            :     }
     430                 :            :   
     431         [ +  - ]:         11 :     GeomAPI_Interpolate spline(points, CUBIT_FALSE, TOL);
     432         [ +  - ]:         11 :     spline.Perform();
     433 [ +  - ][ +  - ]:         11 :     if(spline.IsDone())
     434                 :            :     {
     435 [ +  - ][ +  - ]:         11 :       Handle_Geom_BSplineCurve curve = spline.Curve();
     436         [ +  - ]:         11 :       TopoDS_Vertex * vt1 = occ_point1->get_TopoDS_Vertex();
     437         [ +  - ]:         11 :       TopoDS_Vertex * vt2 = occ_point2->get_TopoDS_Vertex(); 
     438 [ +  - ][ +  - ]:         22 :       TopoDS_Edge new_edge = BRepBuilderAPI_MakeEdge(curve, *vt1, *vt2);
         [ +  - ][ +  - ]
     439 [ +  - ][ +  - ]:         22 :       return OCCQueryEngine::instance()->populate_topology_bridge(new_edge, true); 
         [ +  - ][ +  - ]
                 [ -  + ]
     440                 :          0 :     }
     441                 :            :   }
     442                 :            : 
     443         [ +  - ]:        143 :   return (Curve*) NULL;
     444                 :            : }
     445                 :            : 
     446                 :            : //===============================================================================
     447                 :            : // Function   : make_Curve
     448                 :            : // Member Type: PUBLIC
     449                 :            : // Description: make a curve
     450                 :            : // For STRAIGHT_CURVE_TYPE:
     451                 :            : //    intermediate_point_ptr  is not used
     452                 :            : //
     453                 :            : // For PARABOLA_CURVE_TYPE
     454                 :            : //    intermediate_point_ptr is the tip of the parabola
     455                 :            : //
     456                 :            : // For HYPERBOLA_CURVE_TYPE
     457                 :            : //    intermediate_point_ptr is the center of its two foci
     458                 :            : //
     459                 :            : // For ELLIPSE_CURVE_TYPE
     460                 :            : //    intermediate_point_ptr is the center of the ellipse
     461                 :            : //    the two points are vertices, one gives the major radius, 
     462                 :            : //    the other point gives the minor radius.
     463                 :            : //
     464                 :            : // For ARC_CURVE_TYPE
     465                 :            : //    arc passes three points
     466                 :            : //
     467                 :            : // Author     : Jane Hu 
     468                 :            : // Date       : 01/08
     469                 :            : //===============================================================================
     470                 :        231 : Curve* OCCModifyEngine::make_Curve( GeometryType curve_type,
     471                 :            :                              TBPoint const* point1_ptr,
     472                 :            :                              TBPoint const* point2_ptr,
     473                 :            :                              CubitVector const* intermediate_point_ptr) const
     474                 :            : {
     475 [ +  - ][ -  + ]:        231 :   assert (point1_ptr != NULL && point2_ptr != NULL);
     476         [ +  - ]:        231 :   DLIList<CubitVector*> mid_points;
     477         [ +  + ]:        231 :   if (intermediate_point_ptr)
     478                 :            :   {
     479         [ +  - ]:         77 :     CubitVector mid_point = *intermediate_point_ptr;
     480         [ +  - ]:         77 :     mid_points.append(&mid_point);
     481                 :            :   }
     482                 :            : 
     483         [ +  - ]:        231 :   CubitVector v1(point1_ptr->coordinates());
     484         [ +  - ]:        231 :   CubitVector v2(point2_ptr->coordinates());
     485                 :            : 
     486 [ +  - ][ +  - ]:        231 :   gp_Pnt pt1(v1.x(),v1.y(), v1.z());
         [ +  - ][ +  - ]
     487 [ +  - ][ +  - ]:        231 :   gp_Pnt pt2(v2.x(),v2.y(), v2.z());
         [ +  - ][ +  - ]
     488                 :            : 
     489         [ +  - ]:        231 :   CubitVector v3;
     490         [ +  - ]:        231 :   gp_Pnt pt3;
     491                 :            : 
     492 [ +  - ][ +  - ]:        462 :   Handle(Geom_TrimmedCurve) curve_ptr;
     493         [ +  + ]:        231 :   if(intermediate_point_ptr != NULL)
     494                 :            :   {
     495         [ +  - ]:         77 :     v3 = *intermediate_point_ptr;
     496 [ +  - ][ +  - ]:         77 :     pt3.SetCoord(v3.x(),v3.y(), v3.z());
         [ +  - ][ +  - ]
     497                 :            :   }
     498                 :            : 
     499         [ +  + ]:        231 :   if (curve_type == STRAIGHT_CURVE_TYPE)
     500                 :            :   {
     501                 :            :      //make sure the two points are not coincident
     502 [ +  - ][ -  + ]:        165 :      if(v1.about_equal(v2))
     503                 :            :      {
     504 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Can't create a line from two identical points.\n");
         [ #  # ][ #  # ]
     505                 :          0 :         return (Curve *)NULL;
     506                 :            :      }
     507 [ +  - ][ +  - ]:        165 :      curve_ptr = GC_MakeSegment(pt1,pt2);
         [ +  - ][ +  - ]
                 [ +  - ]
     508                 :            :   }
     509                 :            : 
     510         [ +  + ]:         66 :   else if (curve_type == ARC_CURVE_TYPE)
     511                 :            :   {
     512         [ -  + ]:         33 :      assert(intermediate_point_ptr != NULL);
     513 [ +  - ][ +  - ]:         33 :      curve_ptr = GC_MakeArcOfCircle(pt1, pt3, pt2);
         [ +  - ][ +  - ]
                 [ +  - ]
     514                 :            :   }
     515                 :            : 
     516         [ +  + ]:         33 :   else if (curve_type == ELLIPSE_CURVE_TYPE)
     517                 :            :   {
     518         [ -  + ]:         11 :      assert(intermediate_point_ptr != NULL);
     519                 :            :      
     520 [ +  - ][ +  - ]:         11 :      gp_Pnt center(v3.x(), v3.y(), v3.z());
         [ +  - ][ +  - ]
     521                 :            : 
     522         [ +  - ]:         11 :      gp_Elips ellipse;
     523         [ +  - ]:         11 :      gce_MakeElips ellipse1(pt1 , pt2   , center);
     524 [ +  - ][ +  - ]:         11 :      if(ellipse1.IsDone())
     525         [ +  - ]:         11 :        ellipse = ellipse1.Value();
     526 [ #  # ][ #  # ]:          0 :      else if(!ellipse1.IsDone() && ellipse1.Status() == gce_InvertAxis)
         [ #  # ][ #  # ]
                 [ #  # ]
     527                 :            :      {
     528         [ #  # ]:          0 :         gce_MakeElips ellipse2(pt2, pt1, center);
     529 [ #  # ][ #  # ]:          0 :         if(ellipse2.IsDone())
     530         [ #  # ]:          0 :           ellipse = ellipse2.Value();
     531                 :            :         else
     532                 :            :         {
     533 [ #  # ][ #  # ]:          0 :           PRINT_ERROR("Can't create an ellipse from give 3 points.\n");
         [ #  # ][ #  # ]
     534                 :          0 :           return (Curve *)NULL;
     535                 :            :         }      
     536                 :            :      } 
     537                 :            :      else
     538                 :            :      {
     539 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Can't create an ellipse from give 3 points.\n");
         [ #  # ][ #  # ]
     540                 :          0 :         return (Curve *)NULL;
     541                 :            :      }
     542 [ +  - ][ +  - ]:         11 :      curve_ptr = GC_MakeArcOfEllipse(ellipse, pt1, pt2, CUBIT_TRUE);
         [ +  - ][ +  - ]
                 [ +  - ]
     543                 :            :   }
     544                 :            : 
     545 [ +  + ][ +  - ]:         22 :   else if(curve_type == PARABOLA_CURVE_TYPE || 
     546                 :            :           curve_type == HYPERBOLA_CURVE_TYPE)
     547                 :            :   {
     548         [ -  + ]:         22 :     assert(intermediate_point_ptr != NULL);
     549                 :            : 
     550                 :            :     //find the directrix and focus of the parabola
     551                 :            :     //or the axis, major radius and minor radius of the hyperbola
     552         [ +  - ]:         22 :     CubitVector width_vec = v2 - v1;
     553 [ +  - ][ -  + ]:         22 :     if(width_vec.length_squared() < TOL * TOL)
     554                 :            :     {
     555 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Cannot create a parabola or hyperbola curve from the given points.\n"
                 [ #  # ]
     556         [ #  # ]:          0 :                  "2 end points are the same.\n");
     557                 :          0 :        return (Curve *)NULL;
     558                 :            :     }
     559                 :            : 
     560 [ +  - ][ +  - ]:         22 :     CubitVector midpoint_vec = (v1 + v2)/2.0;
     561         [ +  - ]:         22 :     CubitVector height_vec = midpoint_vec - v3;
     562 [ +  - ][ +  - ]:         22 :     gp_Pnt center(v3.x(), v3.y(), v3.z());
         [ +  - ][ +  - ]
     563                 :            :  
     564 [ +  - ][ -  + ]:         22 :     if (height_vec.length_squared() < TOL * TOL)
     565                 :            :     { 
     566 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Cannot create a parabola or hyperbola curve from the given points.\n"
                 [ #  # ]
     567         [ #  # ]:          0 :                  "3 points are in the same line.\n");
     568                 :          0 :        return (Curve *)NULL;
     569                 :            :     }
     570         [ +  - ]:         22 :     CubitVector x = height_vec;
     571         [ +  - ]:         22 :     x.normalize();
     572 [ +  - ][ +  - ]:         22 :     gp_Dir x_dir(x.x(), x.y(), x.z());
         [ +  - ][ +  - ]
     573                 :            :  
     574 [ +  - ][ +  - ]:         22 :     CubitVector N = x * (v2 - v1);  
     575 [ +  - ][ -  + ]:         22 :     if (N.length_squared() < TOL * TOL)
     576                 :            :     {
     577 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Cannot create a parabola or hyperbola curve from the given points.\n"
                 [ #  # ]
     578         [ #  # ]:          0 :                  "3 points are in the same line.\n");
     579                 :          0 :        return (Curve *)NULL;
     580                 :            :     }
     581         [ +  - ]:         22 :     N.normalize();
     582 [ +  - ][ +  - ]:         22 :     gp_Dir N_dir(N.x(), N.y(), N.z());
         [ +  - ][ +  - ]
     583                 :            : 
     584         [ +  - ]:         22 :     gp_Ax2 axis(center, N_dir, x_dir);  
     585                 :            : 
     586         [ +  + ]:         22 :     if(curve_type == HYPERBOLA_CURVE_TYPE)
     587                 :            :     { 
     588                 :            :        //    (focus2) (v3) . (v2)
     589                 :            :        //          .   .   . (midpoint = focus1)
     590                 :            :        //                  . (v1)
     591 [ +  - ][ +  - ]:         11 :        CubitVector focus2 = 2 * v3 - midpoint_vec;
     592                 :            : 
     593                 :            :        //according to the definition of hyperbola,
     594                 :            :        //2 * a = length(v2 - focus2)-length(v2 - focus1)
     595                 :            : 
     596 [ +  - ][ +  - ]:         11 :        double major = (v2 - focus2).length()/2.0 - (v2 - midpoint_vec).length()/2.0;
         [ +  - ][ +  - ]
     597                 :            : 
     598                 :            :        // if a = 1/2 length major axis, b = 1/2 length minor axis and
     599                 :            :        // c = distance center to focus, then a*a + b*b = c*c
     600                 :            : 
     601 [ +  - ][ +  - ]:         11 :        double c_squared = (midpoint_vec - v3).length_squared();
     602                 :         11 :        double minor = sqrt(c_squared  - major*major );
     603         [ +  - ]:         11 :        gp_Hypr hypt(axis, major, minor);
     604 [ +  - ][ +  - ]:         22 :        curve_ptr =
         [ +  - ][ +  - ]
     605         [ +  - ]:         11 :              GC_MakeArcOfHyperbola(hypt, pt1, pt2, CUBIT_TRUE);
     606                 :            :     }
     607                 :            : 
     608                 :            :     else
     609                 :            :     {
     610                 :            :        // Find the focus of this parabola.
     611                 :            :        // Since for a parabola with its peak at the origin, y = (1/(4*a))*x^2,
     612                 :            :        // and since we have restricted this parabola to be symmetric (per the 
     613                 :            :        // FastQ method, see the FastQ file getwt.f), we can use the following 
     614                 :            :        // relationship to
     615                 :            :        // determine "a", the distance the focus lies from the peak on the line
     616                 :            :        // formed by the peak and the midpoint of the start and end points`
     617 [ +  - ][ +  - ]:         11 :        double a = width_vec.length_squared()/(16. * height_vec.length()); 
     618         [ +  - ]:         11 :        gp_Parab parab(axis, a);
     619 [ +  - ][ +  - ]:         22 :        curve_ptr =
         [ +  - ][ +  - ]
     620         [ +  - ]:         11 :                 GC_MakeArcOfParabola(parab, pt1, pt2, CUBIT_TRUE);
     621                 :         22 :     } 
     622                 :            :   }
     623                 :            : 
     624                 :            :   else
     625                 :            :   {
     626 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("In OCCModifyEngine::make_Curve\n"
                 [ #  # ]
     627         [ #  # ]:          0 :                   "       Invalid curve type.\n");
     628                 :          0 :       return (Curve *)NULL;
     629                 :            :   }
     630                 :            : 
     631         [ -  + ]:        231 :   OCCPoint* occ_pt1 = CAST_TO(const_cast<TBPoint*>(point1_ptr),OCCPoint);
     632         [ -  + ]:        231 :   OCCPoint* occ_pt2 = CAST_TO(const_cast<TBPoint*>(point2_ptr),OCCPoint);
     633         [ +  - ]:        231 :   TopoDS_Vertex * vt1 = occ_pt1->get_TopoDS_Vertex();
     634         [ +  - ]:        231 :   TopoDS_Vertex * vt2 = occ_pt2->get_TopoDS_Vertex();
     635 [ +  - ][ +  - ]:        462 :   TopoDS_Edge new_edge = BRepBuilderAPI_MakeEdge(curve_ptr, *vt1, *vt2);
         [ +  - ][ +  - ]
     636 [ +  - ][ +  - ]:        462 :   return OCCQueryEngine::instance()->populate_topology_bridge(new_edge, true);
                 [ +  - ]
     637                 :            : }
     638                 :            : 
     639                 :         11 : Surface* OCCModifyEngine::make_Surface( Surface *surface_ptr,
     640                 :            :     std::map< TopologyBridge*, TopologyBridge* > * /*old_tb_to_new_tb*/) const
     641                 :            : {
     642                 :            :   // Set extended_from argument to CUBIT_FALSE by default
     643                 :         11 :   return make_Surface(surface_ptr, CUBIT_FALSE);
     644                 :            : }
     645                 :            : 
     646                 :            : //===============================================================================
     647                 :            : // Function   : make_Surface
     648                 :            : //              This function creates a surface given an existing surface, copy.
     649                 :            : // Member Type: PRIVATE
     650                 :            : // Description: make a surface, OCC allows to create a stand along surface,
     651                 :            : //              however the CGM has a design of making all surfaces in a (sheet)
     652                 :            : //              body. This will add complexity on all free surface related 
     653                 :            : //              calculation and modification, and adding potential bugs too. 
     654                 :            : // Author     : Jane Hu
     655                 :            : // Date       : 02/08
     656                 :            : //===============================================================================
     657                 :         11 : Surface* OCCModifyEngine::make_Surface( Surface * surface_ptr,
     658                 :            :                                  CubitBoolean extended_from) const
     659                 :            : {
     660         [ -  + ]:         11 :   OCCSurface* occ_surface = CAST_TO(surface_ptr, OCCSurface);
     661         [ -  + ]:         11 :   if (!occ_surface)
     662                 :            :   {
     663 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Cannot create an OCC surface from the given surface.\n"
                 [ #  # ]
     664         [ #  # ]:          0 :                  "Possible incompatible geometry engines.\n");
     665                 :          0 :      return (Surface *)NULL;
     666                 :            :   }
     667                 :            : 
     668                 :            :   //Start of the codes
     669                 :            :   double UMax, VMax, UMin, VMin;
     670         [ +  - ]:         11 :   occ_surface->get_param_range_U(UMin, UMax);
     671         [ +  - ]:         11 :   occ_surface->get_param_range_V(VMin, VMax);
     672                 :            : 
     673         [ +  - ]:         11 :   TopoDS_Face *theFace = occ_surface->get_TopoDS_Face();
     674                 :            : 
     675         [ -  + ]:         11 :   if( !theFace)
     676                 :            :   {
     677 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Cannot create an OCC surface from the given surface.\n"
                 [ #  # ]
     678         [ #  # ]:          0 :                  "Possible incompatible geometry engines.\n");
     679                 :          0 :      return (Surface *)NULL;
     680                 :            :   }
     681                 :            : 
     682         [ +  - ]:         11 :   TopoDS_Face newFace;
     683 [ +  - ][ +  - ]:         22 :   BRepAdaptor_Surface asurface(*theFace);
     684                 :            : 
     685 [ +  - ][ +  - ]:         22 :   CubitBox bounding_box = GeometryQueryTool::instance()->model_bounding_box();
                 [ +  - ]
     686 [ +  - ][ +  - ]:         11 :   double const height = 2*(bounding_box.diagonal()).length();
     687 [ +  - ][ +  - ]:         22 :   CubitBox box = occ_surface->bounding_box();
     688 [ +  - ][ +  - ]:         11 :   double ratio = height/(box.diagonal().length());
     689                 :            : 
     690                 :         11 :   double middleU = (UMin + UMax)/2.0;
     691                 :         11 :   double middleV = (VMin + VMax)/2.0;
     692                 :         11 :   double U1 = middleU - (UMax-UMin)/2.0 * ratio;
     693                 :         11 :   double U2 = middleU + (UMax-UMin)/2.0 * ratio;
     694                 :         11 :   double V1 = middleV - (VMax - VMin)/2.0 * ratio;
     695                 :         11 :   double V2 = middleV + (VMax - VMin)/2.0 * ratio;
     696                 :            : 
     697         [ -  + ]:         11 :   if (extended_from == CUBIT_TRUE)
     698                 :            :   {
     699                 :            :      // We need to get the type of surface.
     700         [ #  # ]:          0 :      GeometryType type = occ_surface->geometry_type();
     701         [ #  # ]:          0 :      if (type  == PLANE_SURFACE_TYPE)
     702                 :            :      {
     703         [ #  # ]:          0 :         gp_Pln plane = asurface.Plane();
     704 [ #  # ][ #  # ]:          0 :         newFace = BRepBuilderAPI_MakeFace(plane, U1, U2, V1, V2);
         [ #  # ][ #  # ]
                 [ #  # ]
     705                 :            :      }
     706         [ #  # ]:          0 :      else if(type == CONE_SURFACE_TYPE)
     707                 :            :      {
     708                 :            :        //make an infinite cone.
     709                 :            :        //Given this lets create another face that is extended from it.
     710 [ #  # ][ #  # ]:          0 :        if(asurface.GetType() == GeomAbs_Cone)
     711                 :            :        {
     712         [ #  # ]:          0 :          gp_Cone cone = asurface.Cone();
     713                 :            : #if OCC_VERSION_MINOR > 5 
     714 [ #  # ][ #  # ]:          0 :         newFace = BRepBuilderAPI_MakeFace(cone, U1, U2, V1, V2);
         [ #  # ][ #  # ]
                 [ #  # ]
     715                 :            : #else
     716                 :            :          gp_Pnt Apex = cone.Apex();
     717                 :            :          double semi_angle = cone.SemiAngle();
     718                 :            :          gp_Pnt p2;
     719                 :            :          double radius2;
     720                 :            :          gp_XYZ xyz;
     721                 :            :          if (semi_angle > 0)
     722                 :            :            xyz = Apex.XYZ() + cone.Position().Direction().XYZ()*height;
     723                 :            :          else
     724                 :            :            xyz = Apex.XYZ() - cone.Position().Direction().XYZ()*height;
     725                 :            : 
     726                 :            :          p2.SetXYZ(xyz);
     727                 :            :          radius2 = height * tan(fabs(semi_angle));
     728                 :            :          Handle(Geom_RectangularTrimmedSurface) trimmed_cone;
     729                 :            :          trimmed_cone = GC_MakeTrimmedCone(Apex, p2, 0, radius2); 
     730                 :            :   #if OCC_VERSION_MAINTENANCE < 2 
     731                 :            :          newFace = BRepBuilderAPI_MakeFace(trimmed_cone);
     732                 :            :   #else
     733                 :            :          newFace = BRepBuilderAPI_MakeFace(trimmed_cone, TOL);
     734                 :            :   #endif
     735                 :            : #endif
     736                 :            :        }
     737                 :            :        else
     738                 :            :        {
     739         [ #  # ]:          0 :          gp_Cylinder cylinder = asurface.Cylinder();
     740                 :            : #if OCC_VERSION_MINOR > 5
     741 [ #  # ][ #  # ]:          0 :          newFace = BRepBuilderAPI_MakeFace(cylinder, U1, U2, V1, V2);
         [ #  # ][ #  # ]
                 [ #  # ]
     742                 :            : #else
     743                 :            :          double radius = cylinder.Radius();
     744                 :            :          gp_Ax1 axis = cylinder.Axis(); 
     745                 :            :          Handle(Geom_RectangularTrimmedSurface) trimmed_cyl;
     746                 :            :          trimmed_cyl = GC_MakeTrimmedCylinder(axis, radius, height);
     747                 :            :   #if OCC_VERSION_MAINTENANCE < 2 
     748                 :            :          newFace = BRepBuilderAPI_MakeFace(trimmed_cyl);
     749                 :            :   #else
     750                 :            :          newFace = BRepBuilderAPI_MakeFace(trimmed_cyl, TOL);
     751                 :            :   #endif
     752                 :            : #endif
     753                 :            :        } 
     754                 :            :      }
     755         [ #  # ]:          0 :      else if(type == SPHERE_SURFACE_TYPE)
     756                 :            :      {
     757                 :            :        //make a whole sphere.
     758         [ #  # ]:          0 :        gp_Sphere sphere = asurface.Sphere();
     759 [ #  # ][ #  # ]:          0 :        newFace = BRepBuilderAPI_MakeFace(sphere);
         [ #  # ][ #  # ]
                 [ #  # ]
     760                 :            :      }
     761         [ #  # ]:          0 :      else if(type == TORUS_SURFACE_TYPE)
     762                 :            :      {
     763                 :            :        //make a whole torus
     764         [ #  # ]:          0 :        gp_Torus torus = asurface.Torus();
     765 [ #  # ][ #  # ]:          0 :        newFace = BRepBuilderAPI_MakeFace(torus);
         [ #  # ][ #  # ]
                 [ #  # ]
     766                 :            :      }
     767         [ #  # ]:          0 :      else if(type == SPLINE_SURFACE_TYPE ) 
     768                 :            :      {
     769                 :            :        //extend the surfaces using the equation if possible.
     770         [ #  # ]:          0 :        Handle(Geom_BezierSurface) bezier = asurface.Bezier();
     771 [ #  # ][ #  # ]:          0 :        Handle(Geom_Surface) p_surf = bezier;
     772                 :            : #if OCC_VERSION_MINOR > 5
     773 [ #  # ][ #  # ]:          0 :        newFace = BRepBuilderAPI_MakeFace(p_surf, U1, U2, V1, V2, TOL);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     774                 :            : #else
     775                 :            :   #if  OCC_VERSION_MAINTENANCE < 2                           
     776                 :            :        newFace = BRepBuilderAPI_MakeFace(p_surf, U1, U2, V1, V2);
     777                 :            :   #else
     778                 :            :        newFace = BRepBuilderAPI_MakeFace(p_surf, U1, U2, V1, V2, TOL);
     779                 :            :   #endif
     780                 :            : #endif
     781                 :            :      }
     782                 :            :   }
     783                 :            :  
     784                 :            :   else
     785                 :            :   {
     786         [ +  - ]:         11 :     BRepBuilderAPI_Copy api_copy(*theFace);
     787 [ +  - ][ +  - ]:         22 :     TopoDS_Shape newShape = api_copy.ModifiedShape(*theFace);
                 [ +  - ]
     788 [ +  - ][ +  - ]:         22 :     newFace = TopoDS::Face(newShape);
                 [ +  - ]
     789                 :            :   }
     790                 :            :   
     791                 :            :   Surface *surface = OCCQueryEngine::instance()->populate_topology_bridge(
     792 [ +  - ][ +  - ]:         11 :                                newFace, CUBIT_TRUE);
     793                 :            : 
     794         [ +  - ]:         11 :   return surface;
     795                 :            : }
     796                 :            : 
     797                 :            : //===============================================================================
     798                 :            : // Function   : make_Surface
     799                 :            : // Member Type: PUBLIC
     800                 :            : // Description: make a surface of type surface_type, given the list of curves.
     801                 :            : //              check edges option is done in GeometryModifyTool level, so 
     802                 :            : //              disregard this option.
     803                 :            : // Author     : Jane Hu
     804                 :            : // Date       : 02/08
     805                 :            : //===============================================================================
     806                 :         44 : Surface* OCCModifyEngine::make_Surface( GeometryType surface_type,
     807                 :            :                                  DLIList<Curve*>& curve_list,
     808                 :            :                                  Surface * old_surface_ptr,
     809                 :            :                                  bool check_edges) const
     810                 :            : {
     811                 :            :   //Create TopoDS_Edge list to make a surface.
     812         [ +  - ]:         44 :   DLIList<DLIList<TopoDS_Edge*>*> topo_edges_loops;
     813         [ +  - ]:         44 :   curve_list.reset() ;
     814                 :            :     
     815                 :            :   //check no intersections of the TopoDS_Edge's.
     816                 :            :   //need to check that no intersection in the middle of the curves, not at
     817                 :            :   //vertices or out of boundary.
     818                 :            : 
     819                 :         44 :   int count = 0; //intersection point should be the same as curve_list size.
     820 [ +  - ][ +  + ]:        154 :   for ( int i = 0 ; i < curve_list.size()-1 ; i++ )
     821                 :            :   {
     822 [ +  - ][ +  + ]:        319 :      for(int j = i+1; j < curve_list.size(); j ++)
     823                 :            :      {
     824         [ +  - ]:        209 :         DLIList<CubitVector> intscts;
     825                 :        209 :         CubitBoolean bounded = CUBIT_TRUE;//dummy arg.
     826                 :        209 :         CubitBoolean closest = CUBIT_TRUE;//dummy arg.
     827                 :            :         CubitStatus yes_int = 
     828 [ +  - ][ +  - ]:        418 :               OCCQueryEngine::instance()->get_intersections(curve_list[i],
     829 [ +  - ][ +  - ]:        418 :                                 curve_list[j], intscts, bounded, closest);
     830         [ +  - ]:        209 :         if(yes_int)
     831                 :            :         {
     832                 :            :            //check intscts point should be vertex or outside boundary.
     833 [ +  - ][ -  + ]:        209 :            if (intscts.size() > 2 )  
     834                 :            :            {
     835 [ #  # ][ #  # ]:          0 :              PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
                 [ #  # ]
     836         [ #  # ]:          0 :                  "       Cannot make Surface with intersecting curves.\n");
     837                 :          0 :              return (Surface *)NULL;
     838                 :            :            }
     839                 :            :            else
     840                 :            :            {
     841 [ +  - ][ +  + ]:        341 :              for(int k = 0; k < intscts.size(); k++)
         [ +  - ][ +  - ]
     842                 :            :              {
     843         [ +  - ]:        132 :                CubitVector &v = intscts.get_and_step();
     844         [ +  - ]:        132 :                CubitPointContainment is_on = CAST_TO(curve_list[i],OCCCurve)->
     845 [ +  - ][ +  - ]:        132 :                                         point_containment(v);
     846         [ +  - ]:        132 :                if (is_on == CUBIT_PNT_BOUNDARY)
     847                 :            :                {
     848         [ +  - ]:        132 :                  is_on = CAST_TO(curve_list[j],OCCCurve)->
     849 [ +  - ][ +  - ]:        132 :                                 point_containment(v);
     850         [ +  - ]:        132 :                  if (is_on == CUBIT_PNT_BOUNDARY)
     851                 :        132 :                    count++;
     852                 :            :                }
     853         [ #  # ]:          0 :                else if(is_on == CUBIT_PNT_INSIDE)
     854                 :            :                {
     855 [ #  # ][ #  # ]:          0 :                  PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
                 [ #  # ]
     856         [ #  # ]:          0 :                  "       Cannot make Surface with intersecting curves.\n");
     857                 :          0 :                  return (Surface *)NULL;
     858                 :            :                }
     859                 :            :              }
     860                 :            :            }
     861                 :            :         }
     862                 :        209 :      }
     863                 :            :   }
     864                 :            :  
     865 [ +  - ][ -  + ]:         44 :   if (count > curve_list.size()) 
     866                 :            :   {
     867 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
                 [ #  # ]
     868         [ #  # ]:          0 :                 "       Cannot make Surface with intersecting curves.\n");
     869                 :          0 :       return (Surface *)NULL;
     870                 :            :   }
     871                 :            : 
     872 [ +  - ][ +  - ]:         44 :   CubitStatus stat = sort_curves(curve_list, topo_edges_loops); 
                 [ +  - ]
     873         [ +  + ]:         44 :   if( stat == CUBIT_FAILURE ) //case of one disconnected curve , open wires
     874                 :            :   {
     875                 :            :      //loft curves.
     876         [ +  - ]:         11 :      BRepOffsetAPI_ThruSections loft(CUBIT_FALSE);
     877 [ +  - ][ +  - ]:         11 :      CubitStatus stat = do_loft(loft, topo_edges_loops);
                 [ +  - ]
     878 [ +  - ][ +  + ]:         33 :      for (int i = 0; i < topo_edges_loops.size(); i++)
     879                 :            :      {
     880         [ +  - ]:         22 :        DLIList<TopoDS_Edge*>* topo_edges = topo_edges_loops.get_and_step();
     881 [ +  - ][ +  + ]:         44 :        for(int j = 0; j < topo_edges->size(); j++)
     882         [ +  - ]:         22 :          topo_edges->pop();
     883 [ +  - ][ +  - ]:         22 :        delete topo_edges;
     884                 :         22 :        topo_edges = NULL;
     885                 :            :      }
     886         [ -  + ]:         11 :      if(!stat)
     887                 :          0 :        return (Surface*) NULL;
     888                 :            : 
     889 [ +  - ][ +  - ]:         22 :      TopoDS_Shape shape = loft.Shape();
                 [ +  - ]
     890 [ +  - ][ +  - ]:         22 :      TopoDS_Shell shell = TopoDS::Shell(shape);
                 [ +  - ]
     891 [ +  - ][ +  - ]:         22 :      TopExp_Explorer Ex;
     892                 :         11 :      int num_surfaces = 0;
     893 [ +  - ][ +  - ]:         22 :      TopoDS_Face topo_face ;
     894 [ +  - ][ +  - ]:         22 :      for (Ex.Init(shell, TopAbs_FACE); Ex.More(); Ex.Next())
         [ +  - ][ +  + ]
     895                 :            :      {
     896 [ +  - ][ +  - ]:         11 :        topo_face = TopoDS::Face(Ex.Current());
                 [ +  - ]
     897                 :         11 :        num_surfaces ++;
     898                 :            :      }
     899                 :            : 
     900         [ -  + ]:         11 :      if(num_surfaces != 1)
     901                 :            :      {
     902 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("In OCCModifyEngine::skin_surface\n"
                 [ #  # ]
     903         [ #  # ]:          0 :                  "   Cannot create a skin surface for given curves.\n");
     904                 :          0 :        return (Surface*) NULL;
     905                 :            :      }
     906                 :            :    
     907 [ +  - ][ +  - ]:         11 :      Surface* surf = OCCQueryEngine::instance()->populate_topology_bridge(topo_face, CUBIT_TRUE);
     908         [ -  + ]:         11 :      if (surf == NULL)
     909                 :            :      {
     910 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("In OCCModifyEngine::skin_surfaces\n"
                 [ #  # ]
     911         [ #  # ]:          0 :                    "   Cannot create a skin surface for given curves.\n");
     912                 :          0 :        return (Surface*) NULL;
     913                 :            :      }
     914                 :            :  
     915         [ +  - ]:         22 :      return surf;
     916                 :            :   }
     917                 :            : 
     918                 :            :   // Use the topo_edges to make a topo_face
     919                 :            :   TopoDS_Face* topo_face;
     920 [ +  - ][ +  - ]:         33 :   topo_face = make_TopoDS_Face(surface_type,topo_edges_loops, old_surface_ptr);
                 [ +  - ]
     921                 :            :  
     922 [ +  - ][ +  + ]:         66 :   for (int i = 0; i < topo_edges_loops.size(); i++)
     923                 :            :   {
     924         [ +  - ]:         33 :     DLIList<TopoDS_Edge*>* topo_edges = topo_edges_loops.get_and_step();
     925 [ +  - ][ +  + ]:         99 :     for(int j = 0; j < topo_edges->size(); j++)
     926         [ +  - ]:         66 :       topo_edges->pop();
     927 [ +  - ][ +  - ]:         33 :     delete topo_edges;
     928                 :         33 :     topo_edges = NULL;
     929                 :            :   }
     930                 :            :   
     931         [ -  + ]:         33 :   if(!topo_face)
     932                 :            :   {
     933 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("In OCCModifyEngine::make_Surface\n"
                 [ #  # ]
     934         [ #  # ]:          0 :                  "       Cannot make Surface object.\n");
     935                 :          0 :      return (Surface *)NULL;
     936                 :            :   }
     937                 :            : 
     938                 :            :   // make the topology bridges for the face
     939                 :            :   Surface *surface = OCCQueryEngine::instance()->populate_topology_bridge(
     940 [ +  - ][ +  - ]:         33 :                                *topo_face, CUBIT_TRUE); 
     941         [ +  - ]:         33 :   topo_face->Nullify();
     942 [ +  - ][ +  - ]:         33 :   delete topo_face;
                 [ +  - ]
     943                 :         33 :   topo_face = NULL;
     944                 :            : 
     945                 :            :   //Created new surface uses existing OCCPoints on the curves, but created
     946                 :            :   //new curves, so remove the curves from the curvelist on those points.
     947         [ +  - ]:         33 :   if(surface)
     948                 :            :   {
     949 [ +  - ][ +  + ]:        165 :     for(int i = 0; i <  curve_list.size(); i++)
     950                 :            :     {
     951 [ +  - ][ -  + ]:        132 :       OCCCurve* test_c = CAST_TO(curve_list.get_and_step(), OCCCurve);
     952         [ +  - ]:        132 :       DLIList<OCCPoint*> points;
     953 [ -  + ][ +  - ]:        132 :       CAST_TO(surface, OCCSurface)->get_points(points);
     954 [ +  - ][ +  + ]:        660 :       for(int j = 0; j <  points.size(); j ++)
     955 [ +  - ][ +  - ]:        528 :         points.get_and_step()->remove_curve(test_c);      
     956         [ +  - ]:        132 :     }
     957                 :            :   }
     958         [ +  - ]:         44 :   return surface ;
     959                 :            : }
     960                 :            : 
     961                 :         11 : CubitStatus OCCModifyEngine::do_loft(BRepOffsetAPI_ThruSections& loft,
     962                 :            :                                      DLIList<DLIList<TopoDS_Edge*>*> loops) const
     963                 :            : {
     964         [ +  - ]:         11 :    TopoDS_Edge  new_edge;
     965 [ +  - ][ +  + ]:         33 :    for(int i = 0; i < loops.size(); i++)
     966                 :            :    {
     967         [ +  - ]:         22 :      BRepBuilderAPI_MakeWire aWire;
     968 [ +  - ][ +  - ]:         44 :      DLIList<TopoDS_Edge*> edges = *(loops.get_and_step());
                 [ +  - ]
     969                 :            : 
     970 [ +  - ][ +  + ]:         44 :      for(int j = 0; j <  edges.size(); j++)
     971                 :            :      {
     972         [ +  - ]:         22 :        TopoDS_Edge* topo_edge = edges.get_and_step();
     973                 :            : 
     974         [ +  - ]:         22 :        BRepBuilderAPI_Copy api_copy(*topo_edge);
     975 [ +  - ][ +  - ]:         44 :        TopoDS_Shape newShape = api_copy.ModifiedShape(*topo_edge);
                 [ +  - ]
     976 [ +  - ][ +  - ]:         22 :        new_edge = TopoDS::Edge(newShape);
     977         [ +  - ]:         22 :        aWire.Add(new_edge);
     978         [ +  - ]:         22 :      }
     979 [ +  - ][ +  - ]:         22 :      loft.AddWire(aWire.Wire());
     980         [ +  - ]:         22 :    }
     981         [ +  - ]:         11 :    loft.Build();
     982 [ +  - ][ -  + ]:         11 :    if(!loft.IsDone())
     983                 :            :    {
     984 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Curves can't be loft into a surface.\n");
         [ #  # ][ #  # ]
     985                 :          0 :      return CUBIT_FAILURE;
     986                 :            :    }
     987         [ +  - ]:         11 :    return CUBIT_SUCCESS;
     988                 :            : } 
     989                 :            : 
     990                 :            : //===============================================================================
     991                 :            : // Function   : sort_curves
     992                 :            : // Member Type: PROTECTED
     993                 :            : // Description: sort the curves so they are in order and make closed loop 
     994                 :            : // Author     : Jane Hu
     995                 :            : // Date       : 03/08
     996                 :            : //===============================================================================
     997                 :        780 : CubitStatus OCCModifyEngine::sort_curves(DLIList<Curve*> curve_list,
     998                 :            :                         DLIList<DLIList<TopoDS_Edge*>*>& topo_edges_loops)const
     999                 :            : {
    1000         [ +  - ]:        780 :   topo_edges_loops.clean_out();
    1001                 :        780 :   CubitStatus stat = CUBIT_SUCCESS;
    1002 [ +  - ][ +  - ]:        780 :   std::vector< DLIList<TopoDS_Edge*>* > topo_edges(curve_list.size());
    1003         [ +  - ]:        780 :   int size_in = curve_list.size();
    1004         [ +  + ]:       2500 :   for(int i = 0; i < size_in; i++)
    1005 [ +  - ][ +  - ]:       1720 :     topo_edges[i] = new DLIList<TopoDS_Edge*>;
                 [ +  - ]
    1006                 :            : 
    1007         [ +  - ]:        780 :   curve_list.reset() ;
    1008                 :        780 :   Curve const* curve_ptr = NULL ;
    1009                 :        780 :   OCCCurve* occ_curve = NULL;
    1010                 :        780 :   TopoDS_Edge* topo_edge = NULL;
    1011                 :            : 
    1012                 :        780 :   OCCPoint* start = NULL;
    1013                 :        780 :   OCCPoint* end = NULL;
    1014 [ +  - ][ +  - ]:       1560 :   DLIList<OCCPoint*> point_list;
    1015                 :        780 :   CubitBoolean new_end = CUBIT_FALSE;
    1016         [ +  - ]:        780 :   int size = curve_list.size();
    1017                 :            : 
    1018                 :        780 :   int count = 0;
    1019         [ +  + ]:       2544 :   for ( int i = 0 ; i < size ; i++ )
    1020                 :            :   {
    1021         [ +  + ]:       1764 :      if (i == 0)
    1022                 :        844 :        new_end = CUBIT_TRUE;
    1023 [ +  - ][ +  + ]:       1808 :      for(int j = 0; j < curve_list.size(); j ++)
    1024                 :            :      {
    1025         [ +  - ]:       1764 :         curve_ptr = curve_list.get() ; 
    1026         [ -  + ]:       1764 :         occ_curve = CAST_TO(const_cast<Curve*>(curve_ptr), OCCCurve);
    1027                 :            : 
    1028         [ -  + ]:       1764 :         if(occ_curve ==  NULL)
    1029                 :            :         {
    1030 [ #  # ][ #  # ]:          0 :            PRINT_ERROR("In OCCModifyEngine::sort_curves\n"
                 [ #  # ]
    1031         [ #  # ]:          0 :                        "       Got a NULL pointer to OCCCurve\n") ;
    1032                 :          0 :            return CUBIT_FAILURE;
    1033                 :            :         }
    1034                 :            : 
    1035         [ +  - ]:       1764 :         point_list.clean_out();
    1036         [ +  - ]:       1764 :         occ_curve->get_points(point_list);
    1037                 :            :         //assert(point_list.size()==2);
    1038                 :            : 
    1039         [ +  + ]:       1764 :         if (i == 0)
    1040                 :            :         {
    1041         [ +  - ]:        844 :           start = point_list.get();
    1042         [ +  - ]:        844 :           end = point_list.pop();  
    1043                 :        844 :           break;
    1044                 :            :         }
    1045                 :            : 
    1046 [ +  - ][ +  - ]:       1697 :         if(end->is_equal(*(point_list.get()), TOL) ||
         [ +  + ][ +  + ]
                 [ +  + ]
    1047 [ +  - ][ +  - ]:        777 :            end->is_equal(*(point_list.step_and_get()),TOL)) 
    1048                 :            :         {
    1049         [ +  - ]:        338 :            end = point_list.step_and_get();
    1050                 :        338 :            new_end = CUBIT_TRUE;
    1051                 :        338 :            break;
    1052                 :            :         }
    1053                 :            :    
    1054 [ +  - ][ +  - ]:        901 :         else if(start->is_equal(*(point_list.get()), TOL) ||
         [ +  + ][ +  + ]
                 [ +  + ]
    1055 [ +  - ][ +  - ]:        319 :            start->is_equal(*(point_list.step_and_get()),TOL))
    1056                 :            :         {
    1057                 :        538 :            start = end;
    1058         [ +  - ]:        538 :            end = point_list.step_and_get(); 
    1059                 :        538 :            new_end = CUBIT_TRUE;
    1060                 :        538 :            break;
    1061                 :            :         }
    1062         [ +  - ]:         44 :         curve_list.step();
    1063                 :            :      }
    1064                 :            : 
    1065         [ +  + ]:       1764 :      if (new_end)//found next curve 
    1066                 :            :      {
    1067         [ +  - ]:       1720 :         topo_edge = occ_curve->get_TopoDS_Edge();
    1068 [ +  - ][ +  - ]:       1720 :         topo_edges[count]->append(topo_edge);
    1069         [ +  - ]:       1720 :         curve_list.remove();
    1070 [ +  - ][ +  + ]:       1720 :         if(start->is_equal( *end, TOL))  //formed a closed loop
    1071                 :            :         {
    1072                 :        372 :           i = -1;
    1073         [ +  - ]:        372 :           size = curve_list.size() ;
    1074 [ +  - ][ +  - ]:        372 :           topo_edges_loops.append(topo_edges[count]);
    1075                 :        372 :           count++;
    1076                 :            :         }
    1077                 :            :         else
    1078                 :       1720 :           new_end = CUBIT_FALSE;
    1079                 :            :      }
    1080                 :            :      else
    1081                 :            :      {
    1082                 :         44 :         stat = CUBIT_FAILURE; 
    1083                 :         44 :         i = -1;
    1084         [ +  - ]:         44 :         size = curve_list.size();
    1085 [ +  - ][ +  - ]:         44 :         topo_edges_loops.append(topo_edges[count]);
    1086                 :         44 :         count++;
    1087                 :            :      }
    1088                 :            :   }
    1089                 :            : 
    1090         [ +  + ]:        780 :   if( new_end == CUBIT_FALSE ) //case of one disconnected curve
    1091                 :            :   {
    1092 [ +  - ][ +  - ]:        428 :     topo_edges_loops.append(topo_edges[count]); 
    1093                 :        428 :     stat = CUBIT_FAILURE;
    1094                 :            :   }
    1095                 :            : 
    1096         [ +  + ]:       2500 :   for(int i = 0; i < size_in; i++)
    1097                 :            :   {
    1098 [ +  - ][ +  - ]:       1720 :      if(topo_edges[i]->size() == 0)
                 [ +  + ]
    1099                 :            :      {
    1100 [ +  - ][ +  - ]:        876 :        delete topo_edges[i];
                 [ +  - ]
    1101         [ +  - ]:        876 :        topo_edges[i] = NULL;
    1102                 :            :      }
    1103                 :            :   }
    1104         [ +  - ]:       1560 :   return stat;
    1105                 :            : } 
    1106                 :            : //===============================================================================
    1107                 :            : // Function   : make_TopoDS_Face
    1108                 :            : // Member Type: PROTECTED
    1109                 :            : // Description: make a opoDS_Face of type surface_type, given the list of 
    1110                 :            : //              TopoDS_Edge. the TopoDS_Edge's should be in order in loops.
    1111                 :            : //              check edges option is done in GeometryModifyTool level, so
    1112                 :            : //              disregard this option.
    1113                 :            : // Author     : Jane Hu
    1114                 :            : // Date       : 02/08
    1115                 :            : //===============================================================================
    1116                 :         33 : TopoDS_Face* OCCModifyEngine::make_TopoDS_Face(GeometryType surface_type,
    1117                 :            :                               DLIList<DLIList<TopoDS_Edge*>*> topo_edges_list,
    1118                 :            :                               Surface * old_surface_ptr)const
    1119                 :            : {
    1120                 :         33 :   TopoDS_Face* topo_face = NULL;
    1121                 :            :   // Make sure a supported type of surface is being requested.
    1122 [ -  + ][ #  # ]:         33 :   if ( surface_type != PLANE_SURFACE_TYPE  &&
    1123                 :            :        surface_type != BEST_FIT_SURFACE_TYPE)
    1124                 :            :   {
    1125 [ #  # ][ #  # ]:          0 :       PRINT_WARNING("In OCCGeometryEngine::make_TopoDS_Face\n"
                 [ #  # ]
    1126                 :            :                     "       At this time, cannot make a TopoDS_Face that isn't"
    1127         [ #  # ]:          0 :                     " planar or best fit.\n");
    1128                 :          0 :       return topo_face;
    1129                 :            :   }
    1130                 :            :  
    1131                 :            :   // Set the TopoDS_Face pointer, if requested.
    1132                 :         33 :   TopoDS_Face *fit_Face = NULL;
    1133         [ +  - ]:         33 :   Handle_Geom_Surface S;
    1134         [ -  + ]:         33 :   if ( old_surface_ptr != NULL )
    1135                 :            :   {
    1136         [ #  # ]:          0 :       OCCSurface *surf = CAST_TO(old_surface_ptr, OCCSurface );
    1137         [ #  # ]:          0 :       fit_Face = surf->get_TopoDS_Face();
    1138 [ #  # ][ #  # ]:          0 :       S = BRep_Tool::Surface(*fit_Face);
                 [ #  # ]
    1139                 :            :   }
    1140                 :            :  
    1141                 :            :   // Make a wire from the topo_edges.
    1142                 :            :   // Coincident TopoDS_Vertex will be deleted by OCC.
    1143 [ +  - ][ -  + ]:         33 :   if(topo_edges_list.size() == 0)
    1144                 :          0 :       return topo_face;
    1145                 :            : 
    1146 [ +  - ][ +  - ]:         66 :   DLIList<TopoDS_Wire*> wires;
    1147         [ +  - ]:         33 :   GProp_GProps myProps;
    1148                 :         33 :   double max_area  = 0.0;
    1149                 :         33 :   TopoDS_Wire* out_Wire = NULL;
    1150 [ +  - ][ +  - ]:         66 :   TopoDS_Wire test_Wire;
    1151                 :            :   DLIList<TopoDS_Edge*>* topo_edges; 
    1152                 :            :   //check and make sure the outer loop is in the first
    1153 [ +  - ][ +  - ]:         66 :   for(int i = 0; i < topo_edges_list.size() ; i++)
    1154                 :            :   {
    1155         [ +  - ]:         33 :     topo_edges = topo_edges_list.get_and_step();
    1156 [ +  - ][ +  - ]:         33 :     BRepBuilderAPI_MakeWire aWire(*(topo_edges->get()));
    1157 [ +  - ][ +  + ]:        132 :     for(int j = 1; j < topo_edges->size(); j++)
    1158 [ +  - ][ +  - ]:         99 :       aWire.Add(*(topo_edges->step_and_get()));
    1159                 :            : 
    1160 [ +  - ][ +  - ]:         33 :     test_Wire = aWire.Wire();
    1161         [ +  - ]:         33 :     wires.append(&test_Wire);
    1162                 :            :    
    1163 [ +  - ][ +  - ]:         33 :     if (topo_edges_list.size() == 1)
    1164                 :         33 :       break;
    1165                 :            : 
    1166 [ #  # ][ +  - ]:         33 :     BRepBuilderAPI_MakeFace made_face(test_Wire);
              [ -  +  - ]
    1167                 :            : 
    1168 [ #  # ][ #  # ]:          0 :     if (!made_face.IsDone())
    1169                 :            :     {
    1170 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("In OCCModifyEngine::make_TopoDS_Face\n"
                 [ #  # ]
    1171         [ #  # ]:          0 :                    "   Cannot find the best fit surface for given curves.\n");
    1172                 :          0 :        return topo_face;
    1173                 :            :     }
    1174 [ #  # ][ #  # ]:          0 :     TopoDS_Face test_face = made_face.Face();
         [ #  # ][ #  # ]
                 [ #  # ]
    1175         [ #  # ]:          0 :     BRepGProp::SurfaceProperties(test_face, myProps); 
    1176         [ #  # ]:          0 :     double area = myProps.Mass();
    1177         [ #  # ]:          0 :     out_Wire = max_area > area ? out_Wire : &test_Wire;
    1178         [ #  # ]:          0 :     max_area = max_area > area ? max_area : area;
    1179                 :          0 :   } 
    1180                 :            : 
    1181         [ -  + ]:         33 :   if (out_Wire)
    1182                 :            :   {
    1183         [ #  # ]:          0 :     wires.remove(out_Wire);
    1184         [ #  # ]:          0 :     wires.insert_first(out_Wire);
    1185                 :            :   }
    1186                 :            : 
    1187                 :            :   //create the TopoDS_Face
    1188                 :         33 :   CubitBoolean error = CUBIT_FALSE;
    1189                 :            : 
    1190 [ +  - ][ +  + ]:         66 :   for(int i = 0; i < topo_edges_list.size() ; i++)
    1191                 :            :   {
    1192         [ +  - ]:         33 :     TopoDS_Wire *the_wire = wires.get_and_step();
    1193         [ +  - ]:         33 :     if (i == 0)
    1194                 :            :     {
    1195         [ -  + ]:         33 :       if( old_surface_ptr != NULL )
    1196                 :            :       {
    1197         [ #  # ]:          0 :         BRepBuilderAPI_MakeFace made_face(S, *the_wire);
    1198 [ #  # ][ #  # ]:          0 :         if (!made_face.IsDone())
    1199                 :            :         {
    1200                 :          0 :           error = CUBIT_TRUE;
    1201                 :          0 :           break;
    1202                 :            :         }
    1203 [ #  # ][ #  # ]:          0 :         topo_face = new TopoDS_Face(made_face.Face());
         [ #  # ][ #  # ]
                 [ #  # ]
    1204                 :            :       }
    1205                 :            :       else
    1206                 :            :       {
    1207                 :            :         CubitBoolean is_planar = (surface_type == PLANE_SURFACE_TYPE ?
    1208         [ +  - ]:         33 :                                   CUBIT_TRUE : CUBIT_FALSE); 
    1209         [ +  - ]:         33 :         BRepBuilderAPI_MakeFace made_face(*the_wire, is_planar);
    1210 [ +  - ][ -  + ]:         33 :         if (!made_face.IsDone())
    1211                 :            :         {
    1212                 :          0 :           error = CUBIT_TRUE;
    1213                 :          0 :           break;
    1214                 :            :         }
    1215                 :            : 
    1216 [ +  - ][ +  - ]:         33 :         topo_face = new TopoDS_Face(made_face.Face());
         [ +  - ][ +  - ]
                 [ +  - ]
    1217                 :            :       }
    1218                 :            :     }
    1219                 :            :     else
    1220                 :            :     {
    1221         [ #  # ]:          0 :       BRepBuilderAPI_MakeFace made_face(*topo_face, *the_wire);
    1222 [ #  # ][ #  # ]:          0 :       if (!made_face.IsDone())
    1223                 :            :       {
    1224                 :          0 :         error = CUBIT_TRUE;
    1225                 :          0 :         break;
    1226                 :            :       }
    1227 [ #  # ][ #  # ]:          0 :       delete topo_face;
                 [ #  # ]
    1228 [ #  # ][ #  # ]:          0 :       topo_face = new TopoDS_Face(made_face.Face());
         [ #  # ][ #  # ]
                 [ #  # ]
    1229                 :            :     }
    1230                 :            :   } 
    1231                 :            : 
    1232         [ -  + ]:         33 :   if(error)
    1233                 :            :   {
    1234 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("In OCCModifyEngine::make_TopoDS_Face\n"
                 [ #  # ]
    1235         [ #  # ]:          0 :                  "   Cannot find the best fit surface for given curves.\n");
    1236                 :          0 :     return (TopoDS_Face*) NULL;
    1237                 :            :   }
    1238                 :            : 
    1239         [ +  - ]:         66 :   return topo_face;
    1240                 :            : }
    1241                 :            : //===============================================================================
    1242                 :            : // Function   : make_Lump
    1243                 :            : // Member Type: PUBLIC
    1244                 :            : // Description: make a lump of one shell
    1245                 :            : // Author     : Jane Hu
    1246                 :            : // Date       : 02/08
    1247                 :            : //===============================================================================
    1248                 :          0 : Lump* OCCModifyEngine::make_Lump( DLIList<Surface*>& surface_list ) const
    1249                 :            : {
    1250 [ #  # ][ #  # ]:          0 :   if (surface_list.size() < 2) 
    1251                 :          0 :     return (Lump*) NULL;
    1252                 :            : 
    1253                 :            :   //all surfaces should be stand along surface bodies or shell bodies' surface
    1254         [ #  # ]:          0 :   DLIList<BodySM*> body_list;
    1255 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < surface_list.size(); i++)
    1256                 :            :   {
    1257 [ #  # ][ #  # ]:          0 :     OCCSurface* occ_surface = CAST_TO(surface_list.get_and_step(), OCCSurface);
    1258         [ #  # ]:          0 :     if (occ_surface == NULL)
    1259                 :            :     {
    1260 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Cannot create an OCC lump from the given surfaces.\n"
                 [ #  # ]
    1261         [ #  # ]:          0 :                  "Possible incompatible geometry engines.\n");
    1262                 :          0 :        return (Lump *)NULL;
    1263                 :            :     }
    1264         [ #  # ]:          0 :     OCCBody* occ_body = occ_surface->my_body();
    1265         [ #  # ]:          0 :     if(!occ_body)
    1266                 :            :     {
    1267         [ #  # ]:          0 :       OCCShell* occ_shell = occ_surface->my_shell();
    1268         [ #  # ]:          0 :       if(occ_shell)
    1269         [ #  # ]:          0 :         occ_body = occ_shell->my_body();
    1270                 :            :     }
    1271         [ #  # ]:          0 :     if(!occ_body)
    1272                 :            :     {
    1273         [ #  # ]:          0 :       DLIList<OCCBody*> original_bodies;
    1274         [ #  # ]:          0 :       occ_surface->get_bodies(original_bodies);
    1275 [ #  # ][ #  # ]:          0 :       if(original_bodies.size() > 1)
    1276                 :            :       {
    1277 [ #  # ][ #  # ]:          0 :         PRINT_ERROR( "Cannot make lump in non-mainfold solids. \n");
         [ #  # ][ #  # ]
    1278                 :          0 :         return (Lump*) NULL;
    1279                 :            :       }
    1280 [ #  # ][ #  # ]:          0 :       else if(original_bodies.size() == 0)
    1281                 :            :       {
    1282 [ #  # ][ #  # ]:          0 :         PRINT_ERROR( "Interal error: Can't find associated solid. \n");
         [ #  # ][ #  # ]
    1283                 :          0 :         return (Lump*) NULL;
    1284                 :            :       }
    1285         [ #  # ]:          0 :       occ_body = original_bodies.get();
    1286 [ #  # ][ #  # ]:          0 :       assert(occ_body != NULL);
                 [ #  # ]
    1287                 :            :     }
    1288         [ #  # ]:          0 :     DLIList<Lump*> lumps;
    1289 [ #  # ][ #  # ]:          0 :     DLIList<OCCShell*> shells;
                 [ #  # ]
    1290 [ #  # ][ #  # ]:          0 :     DLIList<OCCSurface*> surfaces;
                 [ #  # ]
    1291 [ #  # ][ #  # ]:          0 :     surfaces = occ_body->my_sheet_surfaces();
                 [ #  # ]
    1292 [ #  # ][ #  # ]:          0 :     shells = occ_body->shells();
                 [ #  # ]
    1293 [ #  # ][ #  # ]:          0 :     lumps = occ_body->lumps();
                 [ #  # ]
    1294 [ #  # ][ #  # ]:          0 :     if(lumps.size() > 0 || shells.size() + surfaces.size() > 1)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1295                 :            :     {
    1296 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Cannot create an OCC lump from the given surfaces.\n"
                 [ #  # ]
    1297         [ #  # ]:          0 :                "The surfaces are not free.\n");
    1298                 :          0 :       return (Lump *)NULL;
    1299                 :            :     }
    1300 [ #  # ][ #  # ]:          0 :     body_list.append_unique(occ_body);
                 [ #  # ]
    1301                 :          0 :   }
    1302                 :            : 
    1303 [ #  # ][ #  # ]:          0 :   TopoDS_Shape aShape;
    1304         [ #  # ]:          0 :   CubitStatus stat = stitch_surfs(body_list, aShape);
    1305         [ #  # ]:          0 :   if(!stat)
    1306                 :            :   {
    1307 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("The surfaces are not all connected, can't make a lump. \n");
         [ #  # ][ #  # ]
    1308                 :          0 :     return (Lump*)NULL;
    1309                 :            :   }
    1310                 :            : 
    1311 [ #  # ][ #  # ]:          0 :   TopExp_Explorer Ex, Ex2;
         [ #  # ][ #  # ]
    1312 [ #  # ][ #  # ]:          0 :   TopoDS_Shell aShell ;
    1313 [ #  # ][ #  # ]:          0 :   for (Ex.Init(aShape, TopAbs_SHELL, TopAbs_SOLID); Ex.More()&& stat; Ex.Next())
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1314 [ #  # ][ #  # ]:          0 :     aShell = TopoDS::Shell(Ex.Current());
                 [ #  # ]
    1315                 :            :  
    1316                 :            :   //check to make sure the aShell is closed.
    1317                 :          0 :   int num_edges = 0;
    1318                 :          0 :   int pairs = 0;
    1319                 :            :   //sometimes there's duplicate TopoDS_Edges in the shell.
    1320 [ #  # ][ #  # ]:          0 :   DLIList<TopoDS_Edge*> edge_list;
    1321 [ #  # ][ #  # ]:          0 :   for (Ex.Init(aShell, TopAbs_EDGE); Ex.More()&& stat; Ex.Next())
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1322                 :            :   {
    1323 [ #  # ][ #  # ]:          0 :     TopoDS_Edge edge1 = TopoDS::Edge(Ex.Current());
                 [ #  # ]
    1324 [ #  # ][ #  # ]:          0 :     TopoDS_Edge* new_edge = new TopoDS_Edge(edge1);
    1325         [ #  # ]:          0 :     edge_list.append(new_edge);
    1326         [ #  # ]:          0 :   }
    1327                 :            : 
    1328         [ #  # ]:          0 :   int size = edge_list.size();
    1329         [ #  # ]:          0 :   for (int i = 0; i < size; i++)
    1330                 :            :   {
    1331 [ #  # ][ #  # ]:          0 :     TopoDS_Edge edge1 = *edge_list[i];
    1332                 :          0 :     int same = 0;
    1333 [ #  # ][ #  # ]:          0 :     for (int j = i+1; j < edge_list.size(); j++)
    1334                 :            :     {
    1335 [ #  # ][ #  # ]:          0 :       TopoDS_Edge edge2 = *edge_list[j];
    1336 [ #  # ][ #  # ]:          0 :       if(edge1.IsEqual(edge2))
    1337                 :            :       {
    1338                 :          0 :            same ++;
    1339         [ #  # ]:          0 :            edge_list.remove(&edge1);
    1340                 :          0 :            i--;
    1341                 :          0 :            size--;
    1342 [ #  # ][ #  # ]:          0 :            break;
    1343                 :            :       }
    1344                 :          0 :     }
    1345         [ #  # ]:          0 :     if(same > 0)
    1346                 :          0 :       continue;
    1347                 :            : 
    1348                 :            :     else
    1349                 :          0 :       num_edges++;
    1350                 :            :   
    1351 [ #  # ][ #  # ]:          0 :     for (int j = 0; j < size; j++)  
                 [ #  # ]
    1352                 :            :     {
    1353 [ #  # ][ #  # ]:          0 :       TopoDS_Edge edge2 = *edge_list[j];    
    1354 [ #  # ][ #  # ]:          0 :       if (!edge1.IsEqual(edge2)&& edge1.IsSame(edge2))
         [ #  # ][ #  # ]
                 [ #  # ]
    1355                 :            :       {
    1356                 :          0 :         pairs++;
    1357 [ #  # ][ #  # ]:          0 :         break;
    1358                 :            :       }
    1359                 :          0 :     }
    1360                 :          0 :   }
    1361                 :            : 
    1362 [ #  # ][ #  # ]:          0 :   for (int k = 0; k < edge_list.size(); k++)
    1363                 :            :   {
    1364         [ #  # ]:          0 :     TopoDS_Edge* edge = edge_list.get_and_step();
    1365         [ #  # ]:          0 :     edge->Nullify();
    1366 [ #  # ][ #  # ]:          0 :     delete edge;
                 [ #  # ]
    1367                 :          0 :     edge = NULL;
    1368                 :            :   }
    1369                 :            : 
    1370         [ #  # ]:          0 :   if (num_edges == pairs )
    1371         [ #  # ]:          0 :     aShell.Closed(CUBIT_TRUE);
    1372                 :            : 
    1373                 :            :   else
    1374 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Surfaces must make a water-tight shape to make a lump.\n");
         [ #  # ][ #  # ]
    1375                 :            :   
    1376 [ #  # ][ #  # ]:          0 :   if(aShell.Closed())
    1377                 :            :   {
    1378         [ #  # ]:          0 :     BRepBuilderAPI_MakeSolid aMakeSolid(aShell);
    1379 [ #  # ][ #  # ]:          0 :     if (!aMakeSolid.IsDone())
    1380                 :            :     {
    1381 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Cannot create an OCC Lump from the given surfaces.\n"
                 [ #  # ]
    1382         [ #  # ]:          0 :                    "OCC internal error.\n");
    1383                 :          0 :        return (Lump *)NULL;
    1384                 :            :     }
    1385                 :            : 
    1386 [ #  # ][ #  # ]:          0 :     TopoDS_Solid aSolid = aMakeSolid.Solid();
                 [ #  # ]
    1387                 :            : 
    1388                 :            :     return
    1389 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->populate_topology_bridge(aSolid, CUBIT_TRUE); 
                 [ #  # ]
    1390                 :            :   }
    1391                 :            : 
    1392         [ #  # ]:          0 :   return (Lump*) NULL;
    1393                 :            : }
    1394                 :            : 
    1395                 :            : //===============================================================================
    1396                 :            : // Function   : make_BodySM
    1397                 :            : // Member Type: PUBLIC
    1398                 :            : // Description: make a BodySM from a surface
    1399                 :            : // Author     : Jane Hu
    1400                 :            : // Date       : 02/08
    1401                 :            : //===============================================================================
    1402                 :          0 : BodySM* OCCModifyEngine::make_BodySM( Surface *surface ) const
    1403                 :            : {
    1404         [ #  # ]:          0 :   OCCSurface* occ_surface = CAST_TO(surface, OCCSurface);
    1405         [ #  # ]:          0 :   if(!occ_surface)
    1406                 :            :   {
    1407 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Cannot create an OCC body from the given surface.\n"
                 [ #  # ]
    1408         [ #  # ]:          0 :                  "Possible incompatible geometry engines.\n");
    1409                 :          0 :      return (BodySM *)NULL;
    1410                 :            :   }
    1411                 :            : 
    1412         [ #  # ]:          0 :   OCCBody* occ_body = occ_surface->my_body();
    1413         [ #  # ]:          0 :   TopoDS_Face* face = occ_surface->get_TopoDS_Face();
    1414         [ #  # ]:          0 :   TopoDS_Face newFace;
    1415         [ #  # ]:          0 :   if(!occ_body)
    1416                 :            :   {
    1417         [ #  # ]:          0 :     DLIList<OCCBody*> original_bodies;
    1418         [ #  # ]:          0 :     occ_surface->get_bodies(original_bodies);
    1419 [ #  # ][ #  # ]:          0 :     if(original_bodies.size() > 0)
    1420 [ #  # ][ #  # ]:          0 :       occ_body = original_bodies.get();
    1421                 :            :   }
    1422         [ #  # ]:          0 :   if(occ_body)
    1423                 :            :   {
    1424                 :            :      //copy the surface to make a sheet body.
    1425         [ #  # ]:          0 :      BRepBuilderAPI_Copy api_copy(*face);
    1426 [ #  # ][ #  # ]:          0 :      TopoDS_Shape newShape = api_copy.ModifiedShape(*face);
                 [ #  # ]
    1427 [ #  # ][ #  # ]:          0 :      newFace = TopoDS::Face(newShape);
    1428 [ #  # ][ #  # ]:          0 :      face = new TopoDS_Face(newFace);
                 [ #  # ]
    1429                 :            :   }
    1430                 :            : 
    1431 [ #  # ][ #  # ]:          0 :   surface = OCCQueryEngine::instance()->populate_topology_bridge(*face, CUBIT_TRUE);
    1432                 :            :    
    1433 [ #  # ][ #  # ]:          0 :   return CAST_TO(surface, OCCSurface)->my_body();
                 [ #  # ]
    1434                 :            : }
    1435                 :            : 
    1436                 :            : 
    1437                 :            : 
    1438                 :            : //===============================================================================
    1439                 :            : // Function   : make_BodySM
    1440                 :            : // Member Type: PUBLIC
    1441                 :            : // Description: make a BodySM given a list of Lumps.
    1442                 :            : // Author     : Jane Hu
    1443                 :            : // Date       : 02/08
    1444                 :            : //===============================================================================
    1445                 :          0 : BodySM* OCCModifyEngine::make_BodySM( DLIList<Lump*>& lump_list ) const
    1446                 :            : {
    1447 [ #  # ][ #  # ]:          0 :   if (lump_list.size() == 0)
    1448                 :          0 :     return (BodySM*) NULL;
    1449                 :            : /*
    1450                 :            :   //Create a compsolid shape, copy all BodySM's solids to create new compbody 
    1451                 :            :   DLIList<BodySM*> bodysm_list;
    1452                 :            :   TopoDS_Compound CS;
    1453                 :            :   BRep_Builder B;
    1454                 :            :   B.MakeCompound(CS);
    1455                 :            : 
    1456                 :            :   //Add every shape to the CompSolid
    1457                 :            :   for(int i = 0; i < lump_list.size(); i++)
    1458                 :            :   {
    1459                 :            :      Lump* lump = lump_list.get_and_step();
    1460                 :            :      OCCLump* occ_lump = CAST_TO(lump, OCCLump);
    1461                 :            :      if(!occ_lump)
    1462                 :            :      {
    1463                 :            :         PRINT_ERROR("Cannot create an OCC BodySM from the given lumps.\n"
    1464                 :            :                     "Possible incompatible geometry engines.\n");
    1465                 :            :         return (BodySM *)NULL;
    1466                 :            :      }
    1467                 :            :      TopoDS_Solid* solid = occ_lump->get_TopoDS_Solid();
    1468                 :            :      BRepBuilderAPI_Copy api_copy(*solid);
    1469                 :            :      TopoDS_Shape newShape = api_copy.ModifiedShape(*solid);
    1470                 :            :      B.Add(CS, newShape);
    1471                 :            :   }
    1472                 :            : */
    1473                 :            :  
    1474                 :            :   //check if the lumps are already in some bodies, in this case, have to use 
    1475                 :            :   //unite operation to create compound.
    1476 [ #  # ][ #  # ]:          0 :   for (int i = 0 ; i < lump_list.size(); i++)
    1477                 :            :   {
    1478 [ #  # ][ #  # ]:          0 :     OCCLump* lump = CAST_TO(lump_list.get_and_step(), OCCLump);
    1479         [ #  # ]:          0 :     if(lump == NULL)
    1480                 :            :     {
    1481 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Incompatible engines.\n");
         [ #  # ][ #  # ]
    1482                 :          0 :       return (BodySM*) NULL;
    1483                 :            :     }
    1484         [ #  # ]:          0 :     BodySM* body = lump->get_body();
    1485         [ #  # ]:          0 :     if(body != NULL)
    1486 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->delete_body(body, CUBIT_FALSE);
    1487                 :            :   }
    1488                 :            :   TopoDS_Compound* Co;
    1489         [ #  # ]:          0 :   DLIList<OCCShell*> shells;
    1490 [ #  # ][ #  # ]:          0 :   DLIList<OCCSurface*> surfaces;
    1491         [ #  # ]:          0 :   Co = OCCBody::make_Compound(lump_list, shells, surfaces); 
    1492         [ #  # ]:          0 :   assert (Co != NULL);
    1493 [ #  # ][ #  # ]:          0 :   BodySM* bodysm = OCCQueryEngine::instance()->populate_topology_bridge(*Co);
    1494         [ #  # ]:          0 :   Co->Nullify();
    1495 [ #  # ][ #  # ]:          0 :   delete Co;
                 [ #  # ]
    1496                 :          0 :   Co = NULL;
    1497         [ #  # ]:          0 :   return bodysm;
    1498                 :            : 
    1499                 :            : }
    1500                 :            : 
    1501                 :            : 
    1502                 :            : //===============================================================================
    1503                 :            : // Function   : sphere
    1504                 :            : // Member Type: PUBLIC
    1505                 :            : // Description: build an OCC sphere
    1506                 :            : // Author     : Jane Hu
    1507                 :            : // Date       : 03/08
    1508                 :            : //===============================================================================
    1509                 :        153 : BodySM* OCCModifyEngine::sphere(double radius) const
    1510                 :            : {
    1511         [ -  + ]:        153 :   if (radius <= 0)
    1512                 :          0 :     return (BodySM*) NULL; 
    1513                 :            : 
    1514 [ +  - ][ +  - ]:        153 :   TopoDS_Solid S = BRepPrimAPI_MakeSphere(radius);
                 [ +  - ]
    1515                 :            :   
    1516                 :            :   Lump* lump = OCCQueryEngine::instance()->populate_topology_bridge(S, 
    1517 [ +  - ][ +  - ]:        153 :                                                                 CUBIT_TRUE);
    1518         [ -  + ]:        153 :   if (lump == NULL)
    1519                 :          0 :     return (BodySM*)NULL;
    1520                 :            : 
    1521 [ -  + ][ +  - ]:        153 :   return CAST_TO(lump, OCCLump)->get_body();
                 [ +  - ]
    1522                 :            : }
    1523                 :            : 
    1524                 :            : 
    1525                 :            : //===============================================================================
    1526                 :            : // Function   : brick
    1527                 :            : // Member Type: PUBLIC
    1528                 :            : // Description: build an OCC brick 
    1529                 :            : // Author     : Jane Hu
    1530                 :            : // Date       : 03/08
    1531                 :            : //===============================================================================
    1532                 :        269 : BodySM* OCCModifyEngine::brick( double wid, double dep, double hi ) const
    1533                 :            : {
    1534 [ +  - ][ +  - ]:        269 :   if (wid <= 0 || dep <=0 || hi <= 0)
                 [ -  + ]
    1535                 :          0 :     return (BodySM*)NULL;
    1536                 :            :   
    1537 [ +  - ][ +  - ]:        269 :   TopoDS_Solid S = BRepPrimAPI_MakeBox(wid, dep, hi);
                 [ +  - ]
    1538                 :            : 
    1539                 :            :   Lump* lump = OCCQueryEngine::instance()->populate_topology_bridge(S,
    1540 [ +  - ][ +  - ]:        269 :                                                                 CUBIT_TRUE);
    1541                 :            : 
    1542         [ -  + ]:        269 :   if (lump == NULL)
    1543                 :          0 :     return (BodySM*)NULL;
    1544                 :            : 
    1545 [ -  + ][ +  - ]:        269 :   BodySM* body = CAST_TO(lump, OCCLump)->get_body();
    1546         [ +  - ]:        269 :   if(body)
    1547 [ +  - ][ +  - ]:        269 :     CAST_TO(body,OCCBody)->move(-wid/2.0, -dep/2.0, -hi/2.0);
    1548         [ +  - ]:        269 :   return body;
    1549                 :            : }
    1550                 :            : 
    1551                 :            : 
    1552                 :            : //===============================================================================
    1553                 :            : // Function   : brick
    1554                 :            : // Member Type: PUBLIC
    1555                 :            : // Description: create an OCC brick given center axes and extension
    1556                 :            : //              extension is equvlent to (wid/2, dep/2, hi/2)
    1557                 :            : //              center should be given the coordinates in global system
    1558                 :            : // Author     : Jane Hu
    1559                 :            : // Date       : 03/08
    1560                 :            : //===============================================================================
    1561                 :         11 : BodySM* OCCModifyEngine::brick( const CubitVector& center, 
    1562                 :            :                                 const CubitVector axes[3],
    1563                 :            :                                 const CubitVector &extension) const
    1564                 :            : {
    1565         [ +  - ]:         11 :   gp_Pnt left_point(0,0,0);
    1566 [ +  - ][ +  - ]:         11 :   gp_Dir main_dir(axes[2].x(), axes[2].y(), axes[2].z());
         [ +  - ][ +  - ]
    1567 [ +  - ][ +  - ]:         11 :   gp_Dir x_dir(axes[0].x(), axes[0].y(), axes[0].z());
         [ +  - ][ +  - ]
    1568         [ +  - ]:         11 :   gp_Ax2 Axis(left_point, main_dir, x_dir);
    1569 [ +  - ][ +  - ]:         11 :   TopoDS_Solid S = BRepPrimAPI_MakeBox( Axis, extension.x()*2, extension.y()*2,
    1570 [ +  - ][ +  - ]:         22 :                                         extension.z()*2);
         [ +  - ][ +  - ]
    1571                 :            : 
    1572                 :            :   Lump* lump =  OCCQueryEngine::instance()->populate_topology_bridge(S,
    1573 [ +  - ][ +  - ]:         11 :                                                                 CUBIT_TRUE);
    1574         [ -  + ]:         11 :   if (lump == NULL)
    1575                 :          0 :     return (BodySM*)NULL;
    1576                 :            : 
    1577 [ -  + ][ +  - ]:         11 :   BodySM* body = CAST_TO(lump, OCCLump)->get_body();
    1578         [ +  - ]:         11 :   if(body)
    1579                 :            :   {
    1580         [ +  - ]:         11 :     CubitVector center_point;
    1581                 :            :     double volume;
    1582         [ -  + ]:         11 :     OCCBody* occ_body = CAST_TO(body,OCCBody);
    1583         [ +  - ]:         11 :     occ_body->mass_properties(center_point, volume); 
    1584         [ +  - ]:         11 :     CubitVector move_vec = center - center_point;
    1585 [ +  - ][ +  - ]:         11 :     occ_body->move(move_vec.x(), move_vec.y(), move_vec.z());
         [ +  - ][ +  - ]
    1586                 :         11 :     return body;
    1587                 :            :   }
    1588         [ +  - ]:         11 :   return (BodySM*)NULL;
    1589                 :            : }
    1590                 :            : 
    1591                 :            : //===============================================================================
    1592                 :            : // Function   : prism
    1593                 :            : // Member Type: PUBLIC
    1594                 :            : // Description: create an OCC prism 
    1595                 :            : // Author     : Jane Hu  
    1596                 :            : // Date       : 03/08
    1597                 :            : //===============================================================================
    1598                 :         11 : BodySM* OCCModifyEngine::prism( double height, int sides, double major,
    1599                 :            :                                double minor) const
    1600                 :            : {
    1601 [ +  - ][ +  - ]:         11 :   if(major <= 0. || minor <= 0. || (major - minor) <=  -TOL)
                 [ -  + ]
    1602                 :            :   {
    1603 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Major and minor radii must be greater than zero.\n");
         [ #  # ][ #  # ]
    1604                 :          0 :     return (BodySM*)NULL;
    1605                 :            :   }
    1606                 :            : 
    1607         [ -  + ]:         11 :   if (sides == 4)
    1608         [ #  # ]:          0 :     return brick(2 * major, 2 * minor, height); 
    1609                 :            : 
    1610         [ +  - ]:         11 :   TopoDS_Wire wire ;
    1611         [ +  - ]:         11 :     make_base_for_prim_pyramid(major, minor, height, sides, wire);
    1612                 :            : 
    1613 [ +  - ][ +  - ]:         22 :   TopoDS_Face base = BRepBuilderAPI_MakeFace(wire, Standard_True);
         [ +  - ][ +  - ]
    1614         [ +  - ]:         11 :   gp_Dir main_dir(0.0, 0.0, 1.0);
    1615         [ +  - ]:         11 :   gp_Vec norm(main_dir);
    1616         [ +  - ]:         11 :   norm *= height;
    1617 [ +  - ][ +  - ]:         22 :   BRepSweep_Prism swept(base, norm);
    1618 [ +  - ][ +  - ]:         22 :   TopoDS_Shape new_shape = swept.Shape();
    1619 [ +  - ][ +  - ]:         22 :   DLIList<TopologyBridge*> tbs;
    1620 [ +  - ][ +  - ]:         11 :   tbs += OCCQueryEngine::instance()->populate_topology_bridge(new_shape);
         [ +  - ][ +  - ]
    1621 [ +  - ][ -  + ]:         11 :   assert(tbs.size() == 1);
    1622                 :            : 
    1623 [ +  - ][ -  + ]:         11 :   BodySM* bodysm = CAST_TO(tbs.get(), BodySM);
    1624         [ +  - ]:         11 :   return bodysm;
    1625                 :            : }
    1626                 :            : 
    1627                 :         22 : void OCCModifyEngine::make_base_for_prim_pyramid(double major,
    1628                 :            :                                                  double minor,
    1629                 :            :                                                  double height,
    1630                 :            :                                                  int sides,
    1631                 :            :                                                  TopoDS_Wire& wire)const
    1632                 :            : {
    1633                 :            :   //One of the polygon side will be perpendicular to positive x-axis.
    1634                 :         22 :   double y = major * sin(CUBIT_PI/sides);
    1635                 :         22 :   double x = sqrt(major * major - y * y);
    1636         [ +  - ]:         22 :   gp_Pnt start(x, y, -height/2.0);
    1637                 :            : 
    1638         [ +  - ]:         22 :   DLIList<gp_Pnt> point_list;
    1639                 :         22 :   double theta = 2.0/sides*CUBIT_PI;
    1640         [ +  + ]:        110 :   for(int n =1 ; n < sides; n++)
    1641                 :            :   {
    1642                 :         88 :     double angle = theta * (n + 0.5);
    1643         [ +  - ]:         88 :     gp_Pnt v(major * cos(angle), major * sin(angle), -height/2.0);
    1644         [ +  - ]:         88 :     point_list.append(v);
    1645                 :            :   }
    1646                 :            : 
    1647 [ +  - ][ +  - ]:         44 :   TopoDS_Edge new_edge;
    1648 [ +  - ][ +  - ]:         44 :   BRepBuilderAPI_MakePolygon poly_maker;
    1649         [ +  - ]:         22 :   gp_Dir main_dir(0.0, 0.0, 1.0);
    1650         [ +  - ]:         22 :   point_list.append(start);
    1651                 :            : 
    1652         [ +  - ]:         22 :   if (fabs(major - minor) < TOL)
    1653         [ +  + ]:        132 :     for (int i = 0; i <sides; i++)
    1654 [ +  - ][ +  - ]:        110 :       poly_maker.Add(point_list[i]);
    1655                 :            :   else
    1656                 :            :   {
    1657         [ #  # ]:          0 :     for (int i = 0; i <sides; i++)
    1658                 :            :     {
    1659 [ #  # ][ #  # ]:          0 :       x = point_list[i].X();
    1660 [ #  # ][ #  # ]:          0 :       if((y=point_list[i].Y()) > 0.0)
                 [ #  # ]
    1661                 :          0 :         y = sqrt((1-x*x/major/major)*minor*minor);
    1662                 :            :       else
    1663                 :          0 :         y = -sqrt((1-x*x/major/major)*minor*minor);
    1664 [ #  # ][ #  # ]:          0 :       point_list[i].SetY(y);
    1665 [ #  # ][ #  # ]:          0 :       poly_maker.Add(point_list[i]);
    1666                 :            :     }
    1667                 :            :   }
    1668         [ +  - ]:         22 :   poly_maker.Close();
    1669                 :            : 
    1670 [ +  - ][ +  - ]:         44 :   wire = poly_maker.Wire();
                 [ +  - ]
    1671                 :         22 : }
    1672                 :            : 
    1673                 :            : //===============================================================================
    1674                 :            : // Function   : pyramid
    1675                 :            : // Member Type: PUBLIC
    1676                 :            : // Description: create an OCC pyramid 
    1677                 :            : // Author     : Jane Hu
    1678                 :            : // Date       : 03/08
    1679                 :            : //===============================================================================
    1680                 :         11 : BodySM* OCCModifyEngine::pyramid( double height, int sides, double major,
    1681                 :            :                                  double minor, double top) const
    1682                 :            : {
    1683         [ +  - ]:         11 :   TopoDS_Solid S;
    1684                 :            : 
    1685                 :            :   //build the top and bottom shapes.
    1686 [ +  - ][ +  - ]:         22 :   TopoDS_Wire wire_bottom ; 
    1687         [ +  - ]:         11 :   make_base_for_prim_pyramid(major, minor, height, sides, wire_bottom);
    1688                 :         11 :   double top_minor = top * minor / major;
    1689 [ +  - ][ +  - ]:         22 :   TopoDS_Wire wire_top ; 
    1690 [ +  - ][ +  - ]:         22 :   BRepOffsetAPI_ThruSections builder(CUBIT_TRUE, CUBIT_TRUE);
    1691         [ +  - ]:         11 :   builder.AddWire(wire_bottom);
    1692         [ -  + ]:         11 :   if(top > TOL)
    1693                 :            :   {
    1694         [ #  # ]:          0 :     make_base_for_prim_pyramid(top, top_minor, -height, sides, wire_top); 
    1695         [ #  # ]:          0 :     builder.AddWire(wire_top);
    1696                 :            :   }
    1697                 :            :   else
    1698                 :            :   {
    1699         [ +  - ]:         11 :     gp_Pnt pt = gp_Pnt( 0.0, 0.0, height/2.0);
    1700 [ +  - ][ +  - ]:         11 :     TopoDS_Vertex theVertex = BRepBuilderAPI_MakeVertex(pt);
                 [ +  - ]
    1701 [ +  - ][ +  - ]:         11 :     builder.AddVertex(theVertex);
    1702                 :            :   }
    1703         [ +  - ]:         11 :   builder.Build() ;
    1704 [ +  - ][ +  - ]:         11 :   S = TopoDS::Solid(builder.Shape());
                 [ +  - ]
    1705                 :            :  
    1706                 :            :   Lump* lump =  OCCQueryEngine::instance()->populate_topology_bridge(S,
    1707 [ +  - ][ +  - ]:         11 :                                                                 CUBIT_TRUE);
    1708         [ -  + ]:         11 :   if (lump == NULL)
    1709                 :          0 :     return (BodySM*)NULL;
    1710                 :            : 
    1711 [ -  + ][ +  - ]:         11 :   BodySM* body = CAST_TO(lump, OCCLump)->get_body();
    1712         [ +  - ]:         22 :   return body;
    1713                 :            :   
    1714                 :            : }
    1715                 :            : 
    1716                 :            : //===============================================================================
    1717                 :            : // Function   : cylinder
    1718                 :            : // Member Type: PUBLIC
    1719                 :            : // Description: create an OCC cylinder, its base shape can be ellipse with
    1720                 :            : //              r1, r2 while r3 = 0; or it can be a cone with r1, 
    1721                 :            : //              r3 while r2 = 0. 
    1722                 :            : // Author     : Jane Hu
    1723                 :            : // Date       : 03/08
    1724                 :            : //===============================================================================
    1725                 :         86 : BodySM* OCCModifyEngine::cylinder( double hi, double r1, double r2, double r3 ) const
    1726                 :            : {
    1727         [ +  - ]:         86 :   TopoDS_Solid S;
    1728         [ +  + ]:         86 :   if(r2 != r1)//elliptical based cylinder
    1729                 :            :   {
    1730         [ +  - ]:         11 :     gp_Pnt center(0.0, 0.0, 0.0);
    1731         [ +  - ]:         11 :     gp_Dir main_dir(0.0, 0.0, 1.0);
    1732         [ +  - ]:         11 :     gp_Dir x_dir(1.0, 0.0, 0.0);
    1733         [ +  - ]:         11 :     gp_Ax2 Axis(center, main_dir, x_dir); 
    1734         [ -  + ]:         11 :     if(r1 < r2)
    1735                 :            :     {  
    1736                 :          0 :       double temp_r = r1;
    1737                 :          0 :       r1 = r2;
    1738                 :          0 :       r2 = temp_r;
    1739                 :            :     }
    1740 [ +  - ][ +  - ]:         11 :     Handle(Geom_Curve) curve_ptr = GC_MakeEllipse(Axis, r1, r2); 
         [ +  - ][ +  - ]
                 [ +  - ]
    1741 [ +  - ][ +  - ]:         22 :     TopoDS_Edge new_edge = BRepBuilderAPI_MakeEdge(curve_ptr);
         [ +  - ][ +  - ]
    1742 [ +  - ][ +  - ]:         22 :     BRepBuilderAPI_MakeWire aWire(new_edge);
    1743                 :            : 
    1744 [ +  - ][ +  - ]:         22 :     TopoDS_Wire test_Wire = aWire.Wire();
                 [ +  - ]
    1745                 :            :     
    1746 [ +  - ][ +  - ]:         22 :     BRepOffsetAPI_ThruSections builder(CUBIT_TRUE, CUBIT_TRUE);
    1747         [ +  - ]:         11 :     builder.AddWire(test_Wire);
    1748         [ -  + ]:         11 :     if (r3 == 0)
    1749                 :            :     {
    1750         [ #  # ]:          0 :       gp_Pnt pt = gp_Pnt( 0.0, 0.0, hi);
    1751 [ #  # ][ #  # ]:          0 :       TopoDS_Vertex theVertex = BRepBuilderAPI_MakeVertex(pt);
                 [ #  # ]
    1752 [ #  # ][ #  # ]:          0 :       builder.AddVertex(theVertex);
    1753                 :            :     }
    1754                 :            :     else
    1755                 :            :     {
    1756         [ +  - ]:         11 :       gp_Pnt center2(0.0, 0.0,hi);
    1757         [ +  - ]:         11 :       gp_Ax2 Axis2(center2, main_dir, x_dir);
    1758 [ +  - ][ +  - ]:         11 :       Handle(Geom_Curve) curve_ptr = GC_MakeEllipse(Axis2, r3, r3*r2/r1);
         [ +  - ][ +  - ]
                 [ +  - ]
    1759 [ +  - ][ +  - ]:         22 :       TopoDS_Edge new_edge = BRepBuilderAPI_MakeEdge(curve_ptr);
         [ +  - ][ +  - ]
    1760 [ +  - ][ +  - ]:         22 :       BRepBuilderAPI_MakeWire aWire(new_edge);
    1761 [ +  - ][ +  - ]:         22 :       TopoDS_Wire test_Wire = aWire.Wire();
                 [ +  - ]
    1762 [ +  - ][ +  - ]:         22 :       builder.AddWire(test_Wire);
    1763                 :            :     }
    1764         [ +  - ]:         11 :     builder.Build() ;
    1765 [ +  - ][ +  - ]:         22 :     S = TopoDS::Solid(builder.Shape());
         [ +  - ][ +  - ]
    1766                 :            :   }
    1767                 :            : 
    1768                 :            :   else // cone
    1769                 :            :   {
    1770         [ +  - ]:         75 :     if(r1 == r3) //cylinder
    1771 [ +  - ][ +  - ]:         75 :       S = BRepPrimAPI_MakeCylinder(r1, hi);
         [ +  - ][ +  - ]
                 [ +  - ]
    1772                 :            :     else
    1773 [ #  # ][ #  # ]:          0 :       S = BRepPrimAPI_MakeCone(r1, r3, hi);
         [ #  # ][ #  # ]
                 [ #  # ]
    1774                 :            :   }
    1775                 :            : 
    1776                 :            :   Lump* lump = OCCQueryEngine::instance()->populate_topology_bridge(S,
    1777 [ +  - ][ +  - ]:         86 :                                                                 CUBIT_TRUE);
    1778                 :            : 
    1779         [ -  + ]:         86 :   if (lump == NULL)
    1780                 :            :   {
    1781 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("In OCCModifyEngine::cylinder\n"
                 [ #  # ]
    1782         [ #  # ]:          0 :                 "   Cannot create a cylinder for given radii.\n");
    1783                 :          0 :     return (BodySM*)NULL;
    1784                 :            :   }
    1785                 :            : 
    1786 [ -  + ][ +  - ]:         86 :   BodySM* body = CAST_TO(lump, OCCLump)->get_body();
    1787         [ +  - ]:         86 :   if(body)
    1788 [ +  - ][ +  - ]:         86 :     CAST_TO(body, OCCBody)->move(0, 0, -hi/2.0);
    1789         [ +  - ]:         86 :   return body;
    1790                 :            : }
    1791                 :            : 
    1792                 :            : //===============================================================================
    1793                 :            : // Function   : torus
    1794                 :            : // Member Type: PUBLIC
    1795                 :            : // Description: create an OCC torus
    1796                 :            : // Author     : Jane Hu
    1797                 :            : // Date       : 03/08
    1798                 :            : //===============================================================================
    1799                 :         33 : BodySM* OCCModifyEngine::torus( double r1, double r2 ) const
    1800                 :            : {
    1801 [ +  - ][ -  + ]:         33 :   if (r1 <= 0 || r2 <= 0)
    1802                 :          0 :     return (BodySM*) NULL;
    1803                 :            :  
    1804 [ +  - ][ +  - ]:         33 :   TopoDS_Solid S = BRepPrimAPI_MakeTorus(r1, r2);
                 [ +  - ]
    1805                 :            : 
    1806                 :            :   Lump* lump = OCCQueryEngine::instance()->populate_topology_bridge(S,
    1807 [ +  - ][ +  - ]:         33 :                                                                 CUBIT_TRUE);
    1808                 :            : 
    1809         [ -  + ]:         33 :   if (lump == NULL)
    1810                 :            :   {
    1811 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("In OCCModifyEngine::torus\n"
                 [ #  # ]
    1812         [ #  # ]:          0 :                 "   Cannot create a torus for given radii.\n");
    1813                 :          0 :     return (BodySM*)NULL;
    1814                 :            :   }
    1815                 :            : 
    1816 [ -  + ][ +  - ]:         33 :   return CAST_TO(lump, OCCLump)->get_body();
                 [ +  - ]
    1817                 :            : }
    1818                 :            : 
    1819                 :            : //===============================================================================
    1820                 :            : // Function   : planar_sheet
    1821                 :            : // Member Type: PUBLIC
    1822                 :            : // Description: create an OCC planar_sheet with four vectors. 
    1823                 :            : // Author     : Jane Hu
    1824                 :            : // Date       : 03/08
    1825                 :            : //===============================================================================
    1826                 :         33 : BodySM* OCCModifyEngine::planar_sheet ( const CubitVector& p1,
    1827                 :            :                                        const CubitVector& p2,
    1828                 :            :                                        const CubitVector& p3,
    1829                 :            :                                        const CubitVector& p4) const
    1830                 :            : {
    1831         [ +  - ]:         33 :   TBPoint* point1 = make_Point(p1);
    1832         [ +  - ]:         33 :   TBPoint* point2 = make_Point(p2);
    1833         [ +  - ]:         33 :   TBPoint* point3 = make_Point(p3);
    1834         [ +  - ]:         33 :   TBPoint* point4 = make_Point(p4);
    1835         [ +  - ]:         33 :   Curve * curve1 = make_Curve( point1, point2);
    1836         [ -  + ]:         33 :   if (curve1 == NULL)
    1837                 :          0 :         return (BodySM*) NULL;
    1838         [ +  - ]:         33 :   Curve * curve2 = make_Curve( point2, point3); 
    1839         [ -  + ]:         33 :   if (curve2 == NULL)
    1840                 :          0 :         return (BodySM*) NULL;
    1841         [ +  - ]:         33 :   Curve * curve3 = make_Curve( point3, point4);
    1842         [ -  + ]:         33 :   if (curve3 == NULL)
    1843                 :          0 :         return (BodySM*) NULL;
    1844         [ +  - ]:         33 :   Curve * curve4 = make_Curve( point4, point1);
    1845         [ -  + ]:         33 :   if (curve4 == NULL)
    1846                 :          0 :         return (BodySM*) NULL;
    1847         [ +  - ]:         33 :   DLIList<Curve*> curves;
    1848         [ +  - ]:         33 :   curves.append(curve1);
    1849         [ +  - ]:         33 :   curves.append(curve2);
    1850         [ +  - ]:         33 :   curves.append(curve3);
    1851         [ +  - ]:         33 :   curves.append(curve4);
    1852         [ +  - ]:         33 :   Surface* surface = make_Surface(PLANE_SURFACE_TYPE, curves);
    1853         [ -  + ]:         33 :   if (surface == NULL)
    1854                 :          0 :         return (BodySM*) NULL;
    1855                 :            : 
    1856 [ -  + ][ +  - ]:         33 :   return CAST_TO(surface,OCCSurface)->my_body();
                 [ +  - ]
    1857                 :            : }
    1858                 :            : 
    1859                 :            : //===============================================================================
    1860                 :            : // Function   : copy_body
    1861                 :            : // Member Type: PUBLIC
    1862                 :            : // Description: copy an OCC-based body
    1863                 :            : // Author     : Jane Hu
    1864                 :            : // Date       : 03/08
    1865                 :            : //===============================================================================
    1866                 :        199 : BodySM* OCCModifyEngine::copy_body ( BodySM* bodyPtr, std::map<TopologyBridge*, TopologyBridge*> * /*old_tb_to_new_tb*/ ) const
    1867                 :            : {
    1868                 :        199 :   BodySM* new_body = NULL;
    1869         [ -  + ]:        199 :   OCCBody* occ_body = CAST_TO(bodyPtr, OCCBody);
    1870         [ -  + ]:        199 :   if (!occ_body)
    1871                 :            :   {
    1872 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Cannot create an OCC bodySM from the given bodySM.\n"
                 [ #  # ]
    1873         [ #  # ]:          0 :                  "Possible incompatible geometry engines.\n");
    1874                 :          0 :      return (BodySM *)NULL;
    1875                 :            :   }
    1876                 :            : 
    1877         [ +  - ]:        199 :   DLIList<CubitSimpleAttrib> list;
    1878         [ +  - ]:        199 :   TopoDS_Compound *theCS = occ_body->get_TopoDS_Shape();
    1879                 :            :   
    1880         [ +  + ]:        199 :   if (theCS == NULL) //single lump or shell or surface body
    1881                 :            :   {
    1882         [ +  - ]:        178 :     DLIList<OCCShell*> shells = occ_body->shells();
    1883 [ +  - ][ -  + ]:        178 :     assert(shells.size() < 2);
    1884 [ +  - ][ -  + ]:        178 :     for(int i = 0 ; i < shells.size(); i++)
    1885                 :            :     {
    1886 [ #  # ][ #  # ]:          0 :       TopoDS_Shell* shell = shells.get_and_step()->get_TopoDS_Shell();
    1887         [ #  # ]:          0 :       BRepBuilderAPI_Copy api_copy(*shell);
    1888 [ #  # ][ #  # ]:          0 :       TopoDS_Shape newShape = api_copy.ModifiedShape(*shell);
                 [ #  # ]
    1889 [ #  # ][ #  # ]:          0 :       TopoDS_Shell newShell = TopoDS::Shell(newShape);
                 [ #  # ]
    1890 [ #  # ][ #  # ]:          0 :       new_body = OCCQueryEngine::instance()->populate_topology_bridge(newShell, CUBIT_TRUE)->my_body();
                 [ #  # ]
    1891 [ #  # ][ #  # ]:          0 :       copy_body_attributes((TopoDS_Shape)(*shell), api_copy);
                 [ #  # ]
    1892         [ #  # ]:          0 :     }
    1893                 :            :  
    1894 [ +  - ][ +  - ]:        356 :     DLIList<OCCSurface*> surfaces = occ_body->my_sheet_surfaces();
    1895 [ +  - ][ -  + ]:        178 :     assert(surfaces.size() < 2);
    1896                 :            :     
    1897 [ +  - ][ +  - ]:        178 :     for(int i = 0 ; !new_body && i < surfaces.size(); i++)
         [ -  + ][ -  + ]
    1898                 :            :     {
    1899         [ #  # ]:          0 :       OCCSurface *occ_surface = CAST_TO(surfaces.get_and_step(), OCCSurface);
    1900         [ #  # ]:          0 :       TopoDS_Face *theFace = occ_surface->get_TopoDS_Face();
    1901         [ #  # ]:          0 :       BRepBuilderAPI_Copy api_copy(*theFace);
    1902 [ #  # ][ #  # ]:          0 :       TopoDS_Shape newShape = api_copy.ModifiedShape(*theFace);
                 [ #  # ]
    1903 [ #  # ][ #  # ]:          0 :       TopoDS_Face newFace = TopoDS::Face(newShape);
                 [ #  # ]
    1904                 :            :       Surface* surface = OCCQueryEngine::instance()->populate_topology_bridge(
    1905 [ #  # ][ #  # ]:          0 :                            newFace, CUBIT_TRUE );
    1906         [ #  # ]:          0 :       OCCSurface* occ_surf = CAST_TO(surface, OCCSurface);
    1907         [ #  # ]:          0 :       new_body = occ_surf->my_body();
    1908 [ #  # ][ #  # ]:          0 :       copy_body_attributes((TopoDS_Shape)(*theFace) , api_copy);
                 [ #  # ]
    1909         [ #  # ]:          0 :     }
    1910                 :            : 
    1911                 :            :     //single lump body
    1912         [ +  - ]:        178 :     if (!new_body)
    1913                 :            :     {
    1914 [ +  - ][ +  - ]:        178 :       Lump *lump = occ_body->lumps().get();
                 [ +  - ]
    1915 [ -  + ][ +  - ]:        178 :       TopoDS_Solid solid = *(CAST_TO(lump, OCCLump)->get_TopoDS_Solid());
                 [ +  - ]
    1916 [ +  - ][ +  - ]:        356 :       BRepBuilderAPI_Copy api_copy(solid);
    1917 [ +  - ][ +  - ]:        356 :       TopoDS_Shape newShape = api_copy.ModifiedShape(solid);
                 [ +  - ]
    1918 [ +  - ][ +  - ]:        356 :       TopoDS_Solid newSolid = TopoDS::Solid(newShape);
                 [ +  - ]
    1919                 :            :       lump = OCCQueryEngine::instance()->populate_topology_bridge(newSolid,
    1920 [ +  - ][ +  - ]:        178 :                                                         CUBIT_TRUE);
    1921                 :            : 
    1922 [ -  + ][ +  - ]:        178 :       new_body = CAST_TO(lump, OCCLump)->get_body();
    1923 [ +  - ][ +  - ]:        356 :       copy_body_attributes((TopoDS_Shape)solid, api_copy);
         [ +  - ][ +  - ]
    1924         [ +  - ]:        178 :     }
    1925                 :            :   }
    1926                 :            : 
    1927 [ +  + ][ +  - ]:        220 :   if(!new_body && theCS && !theCS->IsNull() &&
         [ +  - ][ +  - ]
         [ +  - ][ +  + ]
    1928 [ +  - ][ +  - ]:         21 :      OCCQueryEngine::instance()->OCCMap->IsBound(*theCS))
    1929                 :            :   {
    1930         [ +  - ]:         21 :     BRepBuilderAPI_Copy api_copy(*theCS);
    1931                 :            : 
    1932 [ +  - ][ +  - ]:         42 :     TopoDS_Shape newShape = api_copy.ModifiedShape(*theCS);
                 [ +  - ]
    1933                 :            : 
    1934 [ +  - ][ +  - ]:         42 :     TopoDS_Compound newCS = TopoDS::Compound(newShape);
                 [ +  - ]
    1935                 :            : 
    1936 [ +  - ][ +  - ]:         21 :     new_body = OCCQueryEngine::instance()->populate_topology_bridge(newCS);
    1937 [ +  - ][ +  - ]:         21 :     copy_body_attributes((TopoDS_Shape)(*theCS), api_copy);
                 [ +  - ]
    1938         [ +  - ]:         21 :     OCCAttribSet::get_attributes(newCS, list);
    1939 [ +  - ][ +  + ]:         31 :     for(int kk = 0; kk < list.size(); kk++)
    1940 [ +  - ][ +  - ]:         31 :       new_body->append_simple_attribute_virt(list.get_and_step());
                 [ +  - ]
    1941                 :            :   }
    1942                 :            :   
    1943         [ +  - ]:        199 :   return new_body;
    1944                 :            : }
    1945                 :            : 
    1946                 :          0 : BodySM* OCCModifyEngine::create_body( VolumeFacets& volume, 
    1947                 :            :                            std::map<FacetShapes*, GeometryEntity*>& entity_map,
    1948                 :            :                            const FacetPointSet& points, 
    1949                 :            :                            int interp_order) const
    1950                 :            : {
    1951                 :          0 :   return (BodySM*) NULL;
    1952                 :            : }
    1953                 :            : 
    1954                 :        199 : CubitStatus OCCModifyEngine::copy_body_attributes(TopoDS_Shape orig_shape,
    1955                 :            :                                            BRepBuilderAPI_Copy& api_copy)const 
    1956                 :            : {
    1957         [ +  - ]:        199 :   DLIList<CubitSimpleAttrib> list;
    1958 [ +  - ][ +  - ]:        398 :   TopTools_IndexedMapOfShape M;
    1959         [ +  - ]:        199 :   TopExp::MapShapes(orig_shape, TopAbs_SOLID, M);
    1960 [ +  - ][ +  + ]:        485 :   for(int ii=1; ii<=M.Extent(); ii++)
    1961                 :            :   {
    1962 [ +  - ][ +  - ]:        286 :     TopoDS_Solid solid = TopoDS::Solid(M(ii));
                 [ +  - ]
    1963 [ +  - ][ +  - ]:        572 :     TopoDS_Solid new_solid = TopoDS::Solid(api_copy.ModifiedShape(solid));
         [ +  - ][ +  - ]
    1964 [ +  - ][ +  - ]:        286 :     if(!new_solid.IsNull())
    1965 [ +  - ][ +  - ]:        286 :       OCCQueryEngine::instance()->copy_attributes(solid, new_solid);
    1966         [ +  - ]:        286 :     list.clean_out();
    1967         [ +  - ]:        286 :     OCCAttribSet::get_attributes(new_solid,list);
    1968                 :        286 :     OCCLump *lump = NULL;
    1969 [ +  - ][ +  - ]:        286 :     int k = OCCQueryEngine::instance()->OCCMap->Find(new_solid);
    1970 [ +  - ][ +  - ]:        286 :     lump = (OCCLump*) (OCCQueryEngine::instance()->OccToCGM->find(k))->second;         
                 [ +  - ]
    1971 [ +  - ][ -  + ]:        286 :     for(int kk = 0; kk < list.size(); kk++)
    1972 [ #  # ][ #  # ]:          0 :       lump->append_simple_attribute_virt(list.get_and_step());
    1973                 :            :     
    1974 [ +  - ][ +  - ]:        286 :     if (list.size() == 0)
    1975                 :            :     {
    1976 [ +  - ][ +  - ]:        286 :       k = OCCQueryEngine::instance()->OCCMap->Find(solid);
    1977 [ +  - ][ +  - ]:        286 :       OCCLump *orig_lump = (OCCLump*) (OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ +  - ]
    1978         [ +  - ]:        286 :       OCCBody* body = (OCCBody*)orig_lump->get_body();
    1979         [ +  - ]:        286 :       if(body)
    1980                 :            :       {
    1981         [ +  - ]:        286 :         body->get_simple_attribute(list);
    1982 [ +  - ][ +  + ]:        441 :         for (int kk = 0; kk < list.size(); kk++) 
    1983 [ +  - ][ +  - ]:        155 :           lump->get_body()->append_simple_attribute_virt(list.get_and_step()); 
                 [ +  - ]
    1984                 :            :       }
    1985                 :            :     }
    1986         [ +  - ]:        286 :   }
    1987                 :            : 
    1988         [ +  - ]:        199 :   M.Clear();
    1989         [ +  - ]:        199 :   TopExp::MapShapes(orig_shape, TopAbs_FACE, M);
    1990 [ +  - ][ +  + ]:       1218 :   for(int ii=1; ii<=M.Extent(); ii++)
    1991                 :            :   {
    1992 [ +  - ][ +  - ]:       1019 :     TopoDS_Face face = TopoDS::Face(M(ii));
                 [ +  - ]
    1993 [ +  - ][ +  - ]:       2038 :     TopoDS_Face new_face = TopoDS::Face(api_copy.ModifiedShape(face));
         [ +  - ][ +  - ]
    1994 [ +  - ][ +  - ]:       1019 :     if(!new_face.IsNull())
    1995 [ +  - ][ +  - ]:       1019 :       OCCQueryEngine::instance()->copy_attributes(face, new_face);
    1996         [ +  - ]:       1019 :     list.clean_out();
    1997         [ +  - ]:       1019 :     OCCAttribSet::get_attributes(new_face, list);
    1998                 :       1019 :     OCCSurface* surf = NULL;
    1999 [ +  - ][ +  - ]:       1019 :     int k = OCCQueryEngine::instance()->OCCMap->Find(new_face);
    2000 [ +  - ][ +  - ]:       1019 :     surf = (OCCSurface*)(OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ +  - ]
    2001 [ +  - ][ +  + ]:       1379 :     for(int kk = 0; kk < list.size(); kk++)
    2002 [ +  - ][ +  - ]:        360 :       surf->append_simple_attribute_virt(list.get_and_step());
    2003                 :            :   
    2004 [ +  - ][ +  + ]:       1019 :     if(list.size() == 0)
    2005                 :            :     {
    2006 [ +  - ][ +  - ]:        659 :       k = OCCQueryEngine::instance()->OCCMap->Find(orig_shape);
    2007                 :        659 :       OCCBody* body = NULL;
    2008 [ +  - ][ -  + ]:        659 :       if(orig_shape.ShapeType() == TopAbs_FACE)
    2009                 :            :       {
    2010 [ #  # ][ #  # ]:          0 :         OCCSurface *orig_surf = (OCCSurface*) (OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ #  # ]
    2011         [ #  # ]:          0 :         body = orig_surf->my_body();
    2012                 :            :       }
    2013 [ +  - ][ -  + ]:        659 :       else if(orig_shape.ShapeType() == TopAbs_SHELL)
    2014                 :            :       {
    2015 [ #  # ][ #  # ]:          0 :         OCCShell* orig_shell = (OCCShell*) (OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ #  # ]
    2016         [ #  # ]:          0 :         body = orig_shell->my_body();
    2017                 :            :       }
    2018                 :            :       //Solid and Compound case has been considered in the above cases.
    2019         [ -  + ]:        659 :       if(body)
    2020                 :            :       {
    2021         [ #  # ]:          0 :         body->get_simple_attribute(list);
    2022 [ #  # ][ #  # ]:        659 :         for (int kk = 0; kk < list.size(); kk++) 
    2023 [ #  # ][ #  # ]:          0 :           surf->my_body()->append_simple_attribute_virt(list.get_and_step());
                 [ #  # ]
    2024                 :            :       }
    2025                 :            :     }
    2026         [ +  - ]:       1019 :   }
    2027                 :            : 
    2028         [ +  - ]:        199 :   M.Clear();
    2029         [ +  - ]:        199 :   TopExp::MapShapes(orig_shape, TopAbs_EDGE, M);
    2030 [ +  - ][ +  + ]:       2057 :   for(int ii=1; ii<=M.Extent(); ii++)
    2031                 :            :   {
    2032 [ +  - ][ +  - ]:       1858 :     TopoDS_Edge edge = TopoDS::Edge(M(ii));
                 [ +  - ]
    2033 [ +  - ][ +  - ]:       3716 :     TopoDS_Edge new_edge = TopoDS::Edge(api_copy.ModifiedShape(edge));
         [ +  - ][ +  - ]
    2034 [ +  - ][ +  - ]:       1858 :     if(!new_edge.IsNull())
    2035 [ +  - ][ +  - ]:       1858 :       OCCQueryEngine::instance()->copy_attributes(edge, new_edge);
    2036         [ +  - ]:       1858 :     list.clean_out();
    2037         [ +  - ]:       1858 :     OCCAttribSet::get_attributes(new_edge, list);
    2038 [ +  - ][ +  + ]:       1858 :     if(list.size() > 0)
    2039                 :            :     {
    2040 [ +  - ][ +  - ]:        160 :       int k = OCCQueryEngine::instance()->OCCMap->Find(new_edge);
    2041 [ +  - ][ +  - ]:        160 :       OCCCurve* curve = (OCCCurve*) (OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ +  - ]
    2042 [ +  - ][ +  + ]:        320 :       for(int kk = 0; kk < list.size(); kk++)
    2043 [ +  - ][ +  - ]:        160 :         curve->append_simple_attribute_virt(list.get_and_step());
    2044                 :            :     }
    2045         [ +  - ]:       1858 :   }
    2046                 :            : 
    2047         [ +  - ]:        199 :   M.Clear();
    2048         [ +  - ]:        199 :   TopExp::MapShapes(orig_shape, TopAbs_VERTEX, M);
    2049 [ +  - ][ +  + ]:       1423 :   for(int ii=1; ii<=M.Extent(); ii++)
    2050                 :            :   {
    2051 [ +  - ][ +  - ]:       1224 :     TopoDS_Vertex vertex = TopoDS::Vertex(M(ii));
                 [ +  - ]
    2052 [ +  - ][ +  - ]:       2448 :     TopoDS_Vertex new_vertex = TopoDS::Vertex(api_copy.ModifiedShape(vertex));
         [ +  - ][ +  - ]
    2053 [ +  - ][ +  - ]:       1224 :     if(!new_vertex.IsNull())
    2054 [ +  - ][ +  - ]:       1224 :       OCCQueryEngine::instance()->copy_attributes(vertex, new_vertex);
    2055         [ +  - ]:       1224 :     list.clean_out();
    2056         [ +  - ]:       1224 :     OCCAttribSet::get_attributes(new_vertex, list);
    2057 [ +  - ][ +  + ]:       1224 :     if(list.size() > 0)
    2058                 :            :     {
    2059 [ +  - ][ +  - ]:         80 :       int k = OCCQueryEngine::instance()->OCCMap->Find(new_vertex);
    2060 [ +  - ][ +  - ]:         80 :       OCCPoint* point = (OCCPoint*) (OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ +  - ]
    2061 [ +  - ][ +  + ]:        160 :       for(int kk = 0; kk < list.size(); kk++)
    2062 [ +  - ][ +  - ]:         80 :         point->append_simple_attribute_virt(list.get_and_step());
    2063                 :            :     }
    2064         [ +  - ]:       1224 :   }
    2065         [ +  - ]:        199 :   return CUBIT_SUCCESS;
    2066                 :            : }
    2067                 :            : //===============================================================================
    2068                 :            : // Function   : stitch
    2069                 :            : // Member Type: PUBLIC
    2070                 :            : // Description: stitch all surfs and try to make a shell body.
    2071                 :            : //              tighten_gaps and tolerance are not used here.
    2072                 :            : // Author     : Jane Hu
    2073                 :            : // Date       : 03/08
    2074                 :            : //===============================================================================
    2075                 :          0 : CubitStatus OCCModifyEngine::stitch(
    2076                 :            :                       DLIList<BodySM*>& surf_bodies,
    2077                 :            :                       DLIList<BodySM*> &new_bodies,
    2078                 :            :                       bool tighten_gaps,
    2079                 :            :                       double tolerance) const
    2080                 :            : {
    2081 [ #  # ][ #  # ]:          0 :   if (surf_bodies.size()==0)
    2082                 :          0 :     return CUBIT_SUCCESS;
    2083                 :            : 
    2084 [ #  # ][ #  # ]:          0 :   if (surf_bodies.size()==1)
    2085                 :            :   {
    2086         [ #  # ]:          0 :     new_bodies = surf_bodies;
    2087                 :          0 :     return CUBIT_SUCCESS;
    2088                 :            :   }
    2089                 :            : 
    2090         [ #  # ]:          0 :   TopoDS_Shape fuse;
    2091         [ #  # ]:          0 :   CubitStatus stat =  stitch_surfs(surf_bodies, fuse);
    2092                 :            :     
    2093 [ #  # ][ #  # ]:          0 :   TopExp_Explorer Ex;
    2094 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> tbs;
    2095 [ #  # ][ #  # ]:          0 :   for (Ex.Init(fuse, TopAbs_SHELL, TopAbs_SOLID); Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    2096                 :            :   {
    2097 [ #  # ][ #  # ]:          0 :     TopoDS_Shape shape = Ex.Current();
    2098 [ #  # ][ #  # ]:          0 :     tbs += OCCQueryEngine::instance()->populate_topology_bridge(shape);
         [ #  # ][ #  # ]
    2099         [ #  # ]:          0 :   }
    2100                 :            : 
    2101         [ #  # ]:          0 :   if (stat)
    2102                 :            :   {
    2103 [ #  # ][ #  # ]:          0 :     BodySM* body = CAST_TO(tbs.get(), BodySM);
    2104         [ #  # ]:          0 :     new_bodies.append(body);
    2105                 :            :   }
    2106                 :            : 
    2107                 :            :   else
    2108                 :            :   {
    2109 [ #  # ][ #  # ]:          0 :     for(int i= 0; i<tbs.size(); i++)
    2110 [ #  # ][ #  # ]:          0 :       new_bodies.append(CAST_TO(tbs.get_and_step(), OCCBody));
                 [ #  # ]
    2111                 :            :   }
    2112                 :            : 
    2113 [ #  # ][ #  # ]:          0 :   PRINT_WARNING("Occ engine doesn't consider tighten_gaps and tolerance in stitch operation. \n");
         [ #  # ][ #  # ]
    2114         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    2115                 :            : }
    2116                 :            : 
    2117                 :            : //===============================================================================
    2118                 :            : // Function   : stitch_surfs
    2119                 :            : // Member Type: PUBLIC
    2120                 :            : // Description: stitch all surfs and try to make a TopoDS_Shell .
    2121                 :            : //              called by stitch into surface body
    2122                 :            : // Author     : Jane Hu
    2123                 :            : // Date       : 03/08
    2124                 :            : //===============================================================================
    2125                 :          0 : CubitStatus OCCModifyEngine::stitch_surfs(
    2126                 :            :                       DLIList<BodySM*>& surf_bodies,
    2127                 :            :                       TopoDS_Shape& fuse) const
    2128                 :            : {
    2129 [ #  # ][ #  # ]:          0 :   if (surf_bodies.size() < 2)
    2130                 :          0 :     return CUBIT_SUCCESS;
    2131                 :            : 
    2132         [ #  # ]:          0 :   DLIList<TopoDS_Shape*> faces_to_stitch;
    2133 [ #  # ][ #  # ]:          0 :   DLIList<OCCSurface*> original_surfaces;
    2134 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < surf_bodies.size(); i++)
    2135                 :            :   {
    2136         [ #  # ]:          0 :      BodySM * tool_body = surf_bodies.get_and_step();
    2137         [ #  # ]:          0 :      OCCBody* occ_body = CAST_TO(tool_body, OCCBody);
    2138         [ #  # ]:          0 :      DLIList<OCCSurface*> surfaces = occ_body->my_sheet_surfaces();
    2139 [ #  # ][ #  # ]:          0 :      DLIList<OCCShell*> shells = occ_body->shells();
                 [ #  # ]
    2140 [ #  # ][ #  # ]:          0 :      DLIList<Lump*> lumps = occ_body->lumps();
                 [ #  # ]
    2141 [ #  # ][ #  # ]:          0 :      if (surfaces.size()+shells.size() != 1 || lumps.size() > 0)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2142                 :            :      {
    2143 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Can't stitch non-sheet bodySM's. \n");
         [ #  # ][ #  # ]
    2144                 :          0 :        return CUBIT_FAILURE;
    2145                 :            :      }
    2146                 :            : 
    2147         [ #  # ]:          0 :      original_surfaces += surfaces;
    2148 [ #  # ][ #  # ]:          0 :      delete occ_body;
    2149 [ #  # ][ #  # ]:          0 :      OCCQueryEngine::instance()->BodyList->remove(occ_body);
    2150 [ #  # ][ #  # ]:          0 :      if (surfaces.size() == 1)
    2151                 :            :      {
    2152         [ #  # ]:          0 :        OCCSurface* surface = surfaces.get();
    2153 [ #  # ][ #  # ]:          0 :        delete surface->my_shell();
                 [ #  # ]
    2154 [ #  # ][ #  # ]:          0 :        delete surface->my_lump();
                 [ #  # ]
    2155         [ #  # ]:          0 :        surface->set_shell(NULL);
    2156         [ #  # ]:          0 :        surface->set_lump(NULL);
    2157         [ #  # ]:          0 :        surface->set_body(NULL);
    2158                 :            : 
    2159         [ #  # ]:          0 :        TopoDS_Face* topods_face = surface->get_TopoDS_Face();
    2160         [ #  # ]:          0 :        if (topods_face != NULL)
    2161         [ #  # ]:          0 :          faces_to_stitch.append(topods_face);
    2162                 :            :      }
    2163                 :            :      else
    2164                 :            :      {
    2165         [ #  # ]:          0 :        OCCShell* shell = shells.get();
    2166 [ #  # ][ #  # ]:          0 :        delete shell->my_lump();
                 [ #  # ]
    2167         [ #  # ]:          0 :        shell->set_body(NULL);
    2168         [ #  # ]:          0 :        shell->set_lump(NULL);
    2169                 :            : 
    2170         [ #  # ]:          0 :        TopoDS_Shell* topods_shell = shell->get_TopoDS_Shell();
    2171         [ #  # ]:          0 :        if(topods_shell)
    2172 [ #  # ][ #  # ]:          0 :           faces_to_stitch.append(topods_shell);
                 [ #  # ]
    2173                 :            :      }
    2174                 :          0 :   }
    2175                 :            : 
    2176         [ #  # ]:          0 :   faces_to_stitch.reset();
    2177                 :            : 
    2178 [ #  # ][ #  # ]:          0 :   BRepBuilderAPI_Sewing sew;
    2179                 :            : 
    2180 [ #  # ][ #  # ]:          0 :   for( int i = faces_to_stitch.size()-1; i >= 0; i --)
    2181                 :            :   {
    2182         [ #  # ]:          0 :       TopoDS_Shape* face = faces_to_stitch[i];
    2183         [ #  # ]:          0 :       sew.Add(*face);
    2184                 :            :   }
    2185                 :            : 
    2186 [ #  # ][ #  # ]:          0 :   sew.Perform();
                 [ #  # ]
    2187 [ #  # ][ #  # ]:          0 :   TopoDS_Shape sewn_shape=sew.SewedShape();
                 [ #  # ]
    2188                 :            : 
    2189         [ #  # ]:          0 :   fuse=sewn_shape;
    2190                 :            : 
    2191 [ #  # ][ #  # ]:          0 :   TopExp_Explorer Ex;
    2192                 :          0 :   int count_shell = 0;
    2193 [ #  # ][ #  # ]:          0 :   for (Ex.Init(fuse, TopAbs_SHELL, TopAbs_SOLID); Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    2194                 :          0 :     count_shell++;
    2195                 :            : 
    2196         [ #  # ]:          0 :   if ( count_shell != 1)
    2197                 :            :   {
    2198 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Can't stitch all surfaces into one BodySM's. \n");
         [ #  # ][ #  # ]
    2199                 :          0 :      return CUBIT_FAILURE;
    2200                 :            :   }
    2201                 :            : 
    2202 [ #  # ][ #  # ]:          0 :   for( int i = original_surfaces.size()-1; i >= 0; i --)
    2203         [ #  # ]:          0 :     OCCQueryEngine::instance()->
    2204 [ #  # ][ #  # ]:          0 :       delete_solid_model_entities( (Surface*)original_surfaces.pop());
    2205                 :            : 
    2206         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    2207                 :            : }
    2208                 :            : 
    2209                 :            : //===============================================================================
    2210                 :            : // Function   : subtract
    2211                 :            : // Member Type: PUBLIC
    2212                 :            : // Description: subtract boolean operation on OCC-based bodies
    2213                 :            : // Author     : Jane Hu
    2214                 :            : // Date       : 03/08
    2215                 :            : //===============================================================================
    2216                 :         97 : CubitStatus     OCCModifyEngine::subtract(DLIList<BodySM*> &tool_body_list,
    2217                 :            :                                           DLIList<BodySM*> &from_bodies,
    2218                 :            :                                           DLIList<BodySM*> &new_bodies,
    2219                 :            :                                           bool imprint,
    2220                 :            :                                           bool keep_old) const
    2221                 :            : {
    2222                 :            :   // copy the bodies in case keep_old is true
    2223         [ +  - ]:         97 :   DLIList<TopoDS_Shape*> tool_bodies_copy;
    2224                 :            : 
    2225                 :            :   //for subtract function, tool-body has to be solid, 
    2226                 :            :   //otherwise it's just imprint
    2227 [ +  - ][ +  - ]:         97 :   DLIList<CubitBox*>* tool_boxes = new DLIList<CubitBox*>();
    2228 [ +  - ][ +  - ]:        194 :   DLIList<CubitBoolean> is_tool_volume;
    2229                 :            :   //keep the tool_body untouched
    2230                 :            :   CubitStatus stat = 
    2231         [ +  - ]:         97 :     get_shape_list(tool_body_list, tool_bodies_copy, is_tool_volume, CUBIT_TRUE, tool_boxes);
    2232                 :            : 
    2233         [ -  + ]:         97 :   if(!stat)
    2234                 :          0 :     return stat;
    2235                 :            : 
    2236                 :            :   stat = do_subtract(from_bodies, tool_bodies_copy, is_tool_volume,
    2237         [ +  - ]:         97 :                      tool_boxes, new_bodies, keep_old, imprint) ;
    2238                 :            : 
    2239                 :            :   //ok, we're done with all cuts, delete unnecessaries.
    2240                 :         97 :   CubitBoolean delete_tool_boxes = CUBIT_FALSE;
    2241 [ +  - ][ +  - ]:         97 :   if(tool_boxes->size() > 0)
    2242                 :         97 :     delete_tool_boxes = CUBIT_TRUE;
    2243 [ +  - ][ +  + ]:        194 :   while (tool_boxes->size())
    2244 [ +  - ][ +  - ]:         97 :     delete tool_boxes->pop();
                 [ +  - ]
    2245         [ +  - ]:         97 :   if(delete_tool_boxes)
    2246 [ +  - ][ +  - ]:         97 :     delete tool_boxes;
    2247 [ +  - ][ +  + ]:        194 :   while (tool_bodies_copy.size())
    2248 [ +  - ][ +  - ]:         97 :     delete tool_bodies_copy.pop();
         [ +  - ][ +  - ]
    2249         [ +  - ]:         97 :   if(!keep_old) //delete tool_bodies
    2250 [ +  - ][ +  - ]:         97 :     OCCQueryEngine::instance()->delete_solid_model_entities(tool_body_list);
    2251         [ +  - ]:        194 :   return stat;
    2252                 :            : }
    2253                 :            : 
    2254                 :        130 : CubitStatus OCCModifyEngine::do_subtract(DLIList<BodySM*> &from_bodies,
    2255                 :            :                                       DLIList<TopoDS_Shape*> &tool_bodies_copy,
    2256                 :            :                                       DLIList<CubitBoolean> &is_tool_volume,
    2257                 :            :                                       DLIList<CubitBox*>* tool_boxes,
    2258                 :            :                                       DLIList<BodySM*> &new_bodies,
    2259                 :            :                                       bool keep_old,
    2260                 :            :                                       bool imprint) const
    2261                 :            : {
    2262         [ +  - ]:        130 :   DLIList<TopoDS_Shape*> from_bodies_copy;
    2263 [ +  - ][ +  - ]:        260 :   DLIList<CubitBoolean> is_volume;
    2264                 :            :   //get the from_bodies underling shapes
    2265         [ +  - ]:        130 :   CubitStatus stat = get_shape_list(from_bodies, from_bodies_copy, is_volume, keep_old);
    2266         [ -  + ]:        130 :   if(!stat)
    2267                 :            :   {
    2268 [ #  # ][ #  # ]:          0 :     for (int i = 0; i < tool_bodies_copy.size(); i++)
    2269                 :            :     {
    2270         [ #  # ]:          0 :        TopoDS_Shape* shape = tool_bodies_copy.get_and_step();
    2271 [ #  # ][ #  # ]:          0 :        delete shape;
                 [ #  # ]
    2272                 :          0 :        shape = NULL;
    2273                 :            :     }
    2274         [ #  # ]:          0 :     tool_bodies_copy.clean_out();
    2275                 :          0 :     return CUBIT_FAILURE;
    2276                 :            :   } 
    2277                 :            : 
    2278                 :            :   //check that tool_bodies are all solid, shell and surface body can't be used
    2279                 :            :   //for subtracting solids.
    2280 [ +  - ][ -  + ]:        130 :   if(is_tool_volume.is_in_list(CUBIT_FALSE) && !is_volume.is_in_list(CUBIT_FALSE))
         [ #  # ][ #  # ]
                 [ -  + ]
    2281                 :            :   {
    2282 [ #  # ][ #  # ]:          0 :      PRINT_WARNING("Surfaces or Shells can't be used to cut a solid.\n");
         [ #  # ][ #  # ]
    2283 [ #  # ][ #  # ]:          0 :      while (tool_bodies_copy.size())
    2284 [ #  # ][ #  # ]:          0 :        delete tool_bodies_copy.pop();
         [ #  # ][ #  # ]
    2285 [ #  # ][ #  # ]:          0 :      while (from_bodies_copy.size())
    2286 [ #  # ][ #  # ]:          0 :        delete from_bodies_copy.pop(); 
         [ #  # ][ #  # ]
    2287                 :          0 :      return CUBIT_FAILURE;
    2288                 :            :   }
    2289                 :            : 
    2290                 :        130 :   int fraction_remaining = 100;
    2291                 :            : 
    2292                 :            :   // subtract the tool body from each body in the list
    2293                 :            : 
    2294         [ +  - ]:        130 :   TopoDS_Shape*  from_shape = from_bodies_copy.get();
    2295 [ +  - ][ +  - ]:        260 :   DLIList<TopologyBridge*> tbs;
    2296 [ +  - ][ +  + ]:        260 :   for (int i = 0; i < from_bodies_copy.size(); i++)
    2297                 :            :   {
    2298 [ +  - ][ +  - ]:        130 :     CubitBoolean from_volume = is_volume.get_and_step();
    2299         [ +  - ]:        130 :     BodySM* from_body = from_bodies.get();
    2300 [ -  + ][ +  - ]:        130 :     CubitBox box1 = CAST_TO(from_body, OCCBody)->get_bounding_box();
    2301                 :        130 :     int count = 0;  //count for not preforming cut
    2302 [ +  - ][ +  + ]:        260 :     for(int j = 0; j < tool_bodies_copy.size(); j ++)
    2303                 :            :     {
    2304 [ +  - ][ +  - ]:        130 :       CubitBoolean tool_volume = is_tool_volume.get_and_step();
    2305 [ -  + ][ #  # ]:        130 :       if(tool_volume == CUBIT_FALSE && from_volume == CUBIT_TRUE)
    2306                 :            :       {
    2307 [ #  # ][ #  # ]:          0 :         PRINT_WARNING("Surfaces or Shells can't be used to cut a solid.\n");
         [ #  # ][ #  # ]
    2308                 :          0 :         continue;
    2309                 :            :       }
    2310 [ +  - ][ +  - ]:        130 :       if (AppUtil::instance()->interrupt())
                 [ -  + ]
    2311                 :            :       {
    2312 [ #  # ][ #  # ]:          0 :          PRINT_ERROR("Subtraction interrupted.  Aborting...\n");
         [ #  # ][ #  # ]
    2313 [ #  # ][ #  # ]:          0 :          while (tool_bodies_copy.size())
    2314 [ #  # ][ #  # ]:          0 :             delete tool_bodies_copy.pop();
         [ #  # ][ #  # ]
    2315 [ #  # ][ #  # ]:          0 :          while (from_bodies_copy.size())
    2316 [ #  # ][ #  # ]:          0 :             delete from_bodies_copy.pop();
         [ #  # ][ #  # ]
    2317                 :          0 :          return CUBIT_FAILURE;
    2318                 :            :       }
    2319 [ +  - ][ +  - ]:        130 :       CubitBox tool_box = *tool_boxes->get_and_step();  
    2320 [ +  - ][ -  + ]:        130 :       if(!tool_box.overlap(TOL,box1))
    2321                 :            :       {
    2322                 :          0 :         count++;
    2323                 :          0 :         continue;
    2324                 :            :       } 
    2325         [ +  - ]:        130 :       TopoDS_Shape* tool_shape = tool_bodies_copy.get_and_step();
    2326                 :            : 
    2327                 :            :       //bodies overlap, proceed with the subtract
    2328 [ +  - ][ +  - ]:        260 :       BRepAlgoAPI_Cut cutter(*from_shape, *tool_shape);
                 [ +  - ]
    2329 [ +  - ][ +  - ]:        260 :       TopoDS_Shape cut_shape = cutter.Shape(); 
         [ +  - ][ +  - ]
    2330                 :            : 
    2331                 :            :       //compare to see if the from_shape has gotten cut.
    2332                 :        130 :       CubitBoolean has_changed = CUBIT_FALSE;
    2333                 :        130 :       double after_mass = 0.0;
    2334         [ +  - ]:        130 :       GProp_GProps myProps;
    2335 [ +  - ][ +  - ]:        130 :       if(is_volume[i])
                 [ +  - ]
    2336         [ +  - ]:        130 :         BRepGProp::VolumeProperties(cut_shape, myProps);
    2337                 :            : 
    2338                 :            :       else
    2339         [ #  # ]:          0 :         BRepGProp::SurfaceProperties(cut_shape, myProps);
    2340         [ +  - ]:        130 :       after_mass = myProps.Mass();
    2341         [ +  - ]:        130 :       if(after_mass > TOL)
    2342                 :            :         check_operation(cut_shape, from_shape, is_volume[i], has_changed,
    2343 [ +  - ][ +  - ]:        130 :                     &cutter, keep_old);
                 [ +  - ]
    2344                 :            :       else
    2345                 :            :       {
    2346                 :            : /*
    2347                 :            :         if(!keep_old)
    2348                 :            :           OCCQueryEngine::instance()->delete_solid_model_entities(from_body);
    2349                 :            :         from_shape->Nullify();
    2350                 :            : */
    2351                 :          0 :         from_shape = NULL;
    2352                 :            :       }
    2353                 :            : 
    2354                 :            :       int stat;
    2355 [ -  + ][ #  # ]:        130 :       if(!has_changed && from_shape && !from_shape->IsNull())
         [ #  # ][ #  # ]
                 [ -  + ]
    2356                 :            :       {
    2357                 :            :         //Add imprint code here 
    2358         [ #  # ]:          0 :         DLIList<TopoDS_Face*> face_list;
    2359         [ #  # ]:          0 :         if(imprint)
    2360                 :            :         {
    2361         [ #  # ]:          0 :           stat = imprint_toposhapes(from_shape, tool_shape, face_list);
    2362         [ #  # ]:          0 :           if(stat)
    2363                 :            :           {
    2364 [ #  # ][ #  # ]:          0 :             PRINT_ERROR("Can't do imprint operation on the body. \n");
         [ #  # ][ #  # ]
    2365                 :          0 :             count++;
    2366                 :            :           }
    2367 [ #  # ][ #  # ]:          0 :           continue;
    2368 [ +  - ][ +  - ]:        130 :         }
    2369                 :            :       }
    2370                 :        130 :     }
    2371                 :            : 
    2372                 :            :     //ok, we're done with all cuts, construct new Body'
    2373 [ +  - ][ +  - ]:        130 :     if (count < tool_bodies_copy.size() && from_shape && !from_shape->IsNull())
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    2374 [ +  - ][ +  - ]:        130 :       tbs += OCCQueryEngine::instance()->populate_topology_bridge(*from_shape);
         [ +  - ][ +  - ]
    2375 [ #  # ][ #  # ]:          0 :     else if (from_shape && !from_shape->IsNull())
         [ #  # ][ #  # ]
    2376                 :            :     {
    2377 [ #  # ][ #  # ]:          0 :       PRINT_INFO("The %d body did not change because cutting tools are not interscting with it.\n", i+1);
         [ #  # ][ #  # ]
    2378         [ #  # ]:          0 :       from_bodies.change_to(NULL);
    2379                 :            :     }
    2380         [ +  - ]:        130 :     from_bodies.step();
    2381         [ +  - ]:        130 :     from_shape = from_bodies_copy.step_and_get();
    2382                 :            : 
    2383                 :            :     // done with this j iteration; write out count, if necessary
    2384 [ +  - ][ +  - ]:        130 :     if (from_bodies.size() * tool_bodies_copy.size() > 1)
                 [ -  + ]
    2385                 :            :     {
    2386         [ #  # ]:          0 :        int frac_done = (100 * (i+1)) / (from_bodies.size());
    2387         [ #  # ]:          0 :        if ((100 - frac_done) < fraction_remaining)
    2388                 :            :        {
    2389                 :          0 :           fraction_remaining = 100 - frac_done;
    2390 [ #  # ][ #  # ]:        130 :           PRINT_INFO("%d%% remaining.\n ", fraction_remaining+1);
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
    2391                 :            :        }
    2392                 :            :     }
    2393                 :        130 :   }
    2394                 :            : 
    2395 [ +  - ][ +  + ]:        260 :   for (int i = 0; i< tbs.size(); i++)
    2396                 :            :   {
    2397 [ +  - ][ -  + ]:        130 :     BodySM* bodysm = CAST_TO(tbs.get_and_step(), BodySM);
    2398         [ +  - ]:        130 :     if (bodysm)
    2399         [ +  - ]:        130 :       new_bodies.append(bodysm);
    2400                 :            :   }    
    2401                 :            : 
    2402                 :            :   //ok, we're done with all cuts, delete unnecessaries. 
    2403         [ +  + ]:        130 :   if(keep_old)
    2404                 :            :   {
    2405         [ +  - ]:         11 :     int size  = from_bodies_copy.size();
    2406         [ +  + ]:         22 :     for (int i = 0; i < size; i++)
    2407                 :            :     {
    2408         [ +  - ]:         11 :       TopoDS_Shape* shape = from_bodies_copy.pop();
    2409         [ +  - ]:         11 :       if(shape != NULL )
    2410                 :            :       {
    2411         [ +  - ]:         11 :         shape->Nullify();
    2412                 :            :         //delete shape; - Must not be deleted, causes random failure on OSX
    2413                 :         11 :         shape = NULL;
    2414                 :            :       }
    2415                 :            :     }
    2416                 :            :   } 
    2417         [ +  - ]:        260 :   return CUBIT_SUCCESS; 
    2418                 :            : }
    2419                 :            : 
    2420                 :            : //===============================================================================
    2421                 :            : // Function   : imprint_toposhapes
    2422                 :            : // Member Type: PROTECTED
    2423                 :            : // Description: imprint boolean operation on OCC-based bodies.
    2424                 :            : //              from_shape must be TopoDS_Face or above, tool_shape can be
    2425                 :            : //              TopoDS_Edge or above. 
    2426                 :            : //              on_faces works only when tool_shape is an Edge, indicates that
    2427                 :            : //              those edges only imprint on the on_faces.
    2428                 :            : //              success: return 0
    2429                 :            : //              needs intersect-subtract-union boolean: return 1
    2430                 :            : //              fail:     return 2
    2431                 :            : //              needs face intersect for periodic geometry: return 3 
    2432                 :            : //              the cutting surface's topoDS_Face in returned in the
    2433                 :            : //              the last of on_faces list.
    2434                 :            : // Author     : Jane HU
    2435                 :            : // Date       : 03/08
    2436                 :            : //===============================================================================
    2437                 :        228 : int OCCModifyEngine::imprint_toposhapes(TopoDS_Shape*& from_shape, 
    2438                 :            :                                         TopoDS_Shape* tool_shape,
    2439                 :            :                                         DLIList<TopoDS_Face*>&on_faces)const
    2440                 :            : {
    2441                 :        228 :   int count = 0;   //number of imprinting
    2442                 :            :  
    2443                 :            :   //indicate if there's more faces to be imprinted
    2444                 :        228 :   CubitBoolean more_face = CUBIT_TRUE; 
    2445                 :        228 :   CubitBoolean face_created = CUBIT_FALSE;
    2446                 :            : 
    2447                 :            :   //list of face on from_shape that has been imprinted
    2448         [ +  - ]:        228 :   DLIList<TopoDS_Face*> from_faces; 
    2449         [ +  + ]:       1159 :   while( more_face)
    2450                 :            :     {
    2451 [ +  - ][ +  - ]:       1862 :       TopoDS_Face from_face,tool_face;
                 [ +  - ]
           [ +  -  +  - ]
    2452                 :        931 :       TopoDS_Edge* common_edge = NULL;
    2453 [ +  - ][ +  - ]:       1862 :       DLIList<TopoDS_Shape*> tool_faces_edges;
           [ +  -  +  - ]
    2454 [ +  - ][ +  - ]:       1862 :       TopTools_ListOfShape list_of_edges;
           [ +  -  +  - ]
    2455 [ +  - ][ +  - ]:       1862 :       BRepFeat_SplitShape splitor(*from_shape);
           [ +  -  +  - ]
    2456                 :        931 :       CubitBoolean qualified = CUBIT_TRUE;
    2457 [ +  - ][ -  + ]:        931 :       if (tool_shape->ShapeType() == TopAbs_EDGE)
    2458                 :            :         {
    2459         [ #  # ]:          0 :           if(count == 1)
    2460                 :          0 :             break;
    2461                 :            :       
    2462         [ #  # ]:          0 :           DLIList<TopoDS_Face*> faces;
    2463                 :            :           //need to delete TopoDS_Face* in faces
    2464 [ #  # ][ #  # ]:          0 :           common_edge = find_imprinting_edge(*from_shape, TopoDS::Edge(*tool_shape),faces);
    2465         [ #  # ]:          0 :           if (common_edge)
    2466                 :            :             {
    2467 [ #  # ][ #  # ]:          0 :               if (on_faces.size() > 0)
    2468                 :          0 :                 qualified = CUBIT_FALSE;
    2469 [ #  # ][ #  # ]:          0 :               for(int j = 0; j < faces.size(); j++)
    2470                 :            :                 {
    2471 [ #  # ][ #  # ]:          0 :                   from_face = *faces.get();
    2472 [ #  # ][ #  # ]:          0 :                   for (int i = 0; i < on_faces.size(); i++)
    2473                 :            :                     {
    2474 [ #  # ][ #  # ]:          0 :                       if (from_face.IsSame(*(on_faces.get_and_step())))
                 [ #  # ]
    2475                 :            :                         {
    2476                 :          0 :                           qualified = CUBIT_TRUE; 
    2477                 :          0 :                           break;
    2478                 :            :                         }
    2479                 :            :                     }
    2480 [ #  # ][ #  # ]:          0 :                   faces.get()->Nullify();
    2481 [ #  # ][ #  # ]:          0 :                   delete faces.get();
         [ #  # ][ #  # ]
    2482         [ #  # ]:          0 :                   faces.step();
    2483                 :            :                 }
    2484 [ #  # ][ #  # ]:          0 :               if (qualified && (from_faces.size() == 0 || (from_faces.size() && !from_face.IsSame(*from_faces.get()))) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    2485         [ #  # ]:          0 :                 list_of_edges.Append(*common_edge);
    2486                 :            :               else
    2487         [ #  # ]:          0 :                 from_face.Nullify();
    2488         [ #  # ]:          0 :               common_edge->Nullify();
    2489 [ #  # ][ #  # ]:          0 :               delete common_edge;
                 [ #  # ]
    2490                 :          0 :               common_edge = NULL;
    2491         [ #  # ]:          0 :             }
    2492                 :            :         }
    2493                 :            :       else 
    2494                 :            :         {
    2495         [ +  - ]:        931 :           TopOpeBRep_ShapeIntersector intersector;
    2496         [ +  - ]:        931 :           intersector.InitIntersection(*from_shape, *tool_shape);
    2497                 :            : 
    2498                 :            :           //find the intersecting edges and faces.
    2499                 :        931 :           int max_edge = 0;
    2500                 :            :                      
    2501 [ +  - ][ +  + ]:      47124 :           for(; intersector.MoreIntersection(); )
    2502                 :            :             {
    2503         [ +  - ]:      46193 :               TopoDS_Shape face1;
    2504 [ +  - ][ +  - ]:      46193 :               face1 = intersector.ChangeFacesIntersector().Face(1);
                 [ +  - ]
    2505                 :      46193 :               CubitBoolean has_imprinted = CUBIT_FALSE;
    2506 [ +  - ][ +  + ]:     125827 :               for (int j = 0; j < from_faces.size(); j++)
    2507                 :            :                 {
    2508         [ +  - ]:     104527 :                   TopoDS_Face* topo_face = from_faces.get_and_step();
    2509 [ +  - ][ +  + ]:     104527 :                   if(face1.IsSame(*topo_face))
    2510                 :            :                     {
    2511                 :      24893 :                       has_imprinted = CUBIT_TRUE;
    2512                 :      24893 :                       break;
    2513                 :            :                     }
    2514                 :            :                 }
    2515                 :            : 
    2516         [ +  + ]:      46193 :               if (has_imprinted == CUBIT_TRUE)
    2517                 :            :                 {
    2518         [ +  - ]:      24893 :                   intersector.NextIntersection();
    2519                 :      24893 :                   continue;
    2520                 :            :                 }
    2521 [ +  - ][ +  - ]:      67493 :               TopoDS_Shape edge_face;
         [ +  - ][ +  + ]
    2522                 :            : 
    2523 [ +  - ][ +  - ]:      21300 :               edge_face = intersector.ChangeFacesIntersector().Face(2);
                 [ +  - ]
    2524 [ +  - ][ +  - ]:      42600 :               BRepAlgoAPI_Section section(face1, edge_face);
    2525                 :            : 
    2526                 :            :               //intersection edges between face1 and edge_face
    2527 [ +  - ][ +  - ]:      42600 :               TopTools_ListOfShape temp_list_of_edges;
    2528                 :            : #if OCC_VERSION_MINOR > 5
    2529 [ +  - ][ +  - ]:      42600 :               TopoDS_Shape s_shape = section.Shape();
                 [ +  - ]
    2530 [ +  - ][ +  - ]:      42600 :               TopExp_Explorer Ex;
    2531 [ +  - ][ +  - ]:      60765 :               for (Ex.Init(s_shape, TopAbs_EDGE, TopAbs_WIRE); Ex.More(); Ex.Next())
         [ +  - ][ +  + ]
    2532 [ +  - ][ +  - ]:      39465 :                 temp_list_of_edges.Append(TopoDS::Edge( Ex.Current())); 
                 [ +  - ]
    2533                 :            : #else
    2534                 :            :               temp_list_of_edges.Assign(section.SectionEdges());
    2535                 :            : #endif
    2536         [ +  - ]:      21300 :               int num_edges = temp_list_of_edges.Extent();
    2537                 :            :   
    2538         [ +  - ]:      21300 :               CubitBoolean is_same = face1.IsSame(from_face);
    2539                 :      21300 :               CubitBoolean is_same_tool = CUBIT_FALSE;
    2540 [ +  - ][ +  + ]:      53475 :               for (int j = 0; j < tool_faces_edges.size(); j++)
    2541                 :            :                 {
    2542         [ +  - ]:      39803 :                   TopoDS_Shape* topo_face_edge = tool_faces_edges.get_and_step();
    2543 [ +  - ][ +  + ]:      39803 :                   if(edge_face.IsSame(*topo_face_edge))
    2544                 :            :                     {
    2545                 :       7628 :                       is_same_tool = CUBIT_TRUE;
    2546                 :       7628 :                       break;
    2547                 :            :                     }
    2548                 :            :                 }
    2549         [ +  + ]:      21300 :               if (max_edge < num_edges )
    2550                 :            :                 {
    2551         [ +  - ]:        962 :                   list_of_edges.Assign(temp_list_of_edges);  
    2552                 :        962 :                   max_edge =  num_edges ;
    2553 [ +  - ][ +  - ]:        962 :                   from_face = TopoDS::Face(face1);
    2554 [ +  - ][ +  - ]:        962 :                   TopoDS_Shape* topo_shape = new TopoDS_Shape(edge_face);
    2555         [ +  - ]:        962 :                   DLIList<TopoDS_Shape*> shape_list;
    2556 [ +  - ][ +  + ]:       1617 :                   for(int iii = 0; iii < tool_faces_edges.size(); iii++)
    2557                 :            :                     {
    2558         [ +  - ]:        655 :                       int size = shape_list.size();
    2559 [ +  - ][ +  - ]:        655 :                       shape_list.append_unique(tool_faces_edges.get_and_step());
    2560 [ +  - ][ +  - ]:        655 :                       if (size < shape_list.size())
    2561                 :            :                         {
    2562         [ +  - ]:        655 :                           shape_list.last();
    2563 [ +  - ][ +  - ]:        655 :                           shape_list.get()->Nullify();
    2564 [ +  - ][ +  - ]:        655 :                           delete shape_list.get();
         [ +  - ][ +  - ]
    2565                 :            :                         }
    2566                 :            :                     }
    2567         [ +  - ]:        962 :                   tool_faces_edges.clean_out();
    2568         [ +  + ]:       2721 :                   for(int i = 0 ; i < num_edges; i++)
    2569                 :            :                     //later has to use it num_edges times 
    2570 [ +  - ][ +  - ]:       2721 :                     tool_faces_edges.append(topo_shape);
    2571                 :            :                 }
    2572 [ +  + ][ +  + ]:      20338 :               else if(num_edges == max_edge && is_same && !is_same_tool) 
                 [ +  + ]
    2573                 :            :                 //multi tool faces cut the same face
    2574                 :            :                 {
    2575 [ +  - ][ +  - ]:       1458 :                   TopTools_ListIteratorOfListOfShape Itor, temp_Itor;
    2576         [ +  - ]:       1458 :                   temp_Itor.Initialize(temp_list_of_edges);
    2577 [ +  - ][ +  - ]:       2916 :                   for(; temp_Itor.More(); temp_Itor.Next())
                 [ +  + ]
    2578                 :            :                     {
    2579 [ +  - ][ +  - ]:       1458 :                       TopoDS_Edge temp_edge = TopoDS::Edge(temp_Itor.Value());
                 [ +  - ]
    2580         [ +  - ]:       1458 :                       Itor.Initialize(list_of_edges);
    2581                 :       1458 :                       CubitBoolean same_edge = CUBIT_FALSE;
    2582                 :            :               
    2583         [ +  - ]:       1458 :                       GProp_GProps myProps1;
    2584         [ +  - ]:       1458 :                       BRepGProp::LinearProperties(temp_edge, myProps1);
    2585         [ +  - ]:       1458 :                       gp_Pnt center1 = myProps1.CentreOfMass();
    2586 [ +  - ][ +  - ]:       3211 :                       for(; Itor.More(); Itor.Next())
                 [ +  + ]
    2587                 :            :                         {
    2588 [ +  - ][ +  - ]:       1753 :                           TopoDS_Edge edge = TopoDS::Edge(Itor.Value());
                 [ +  - ]
    2589         [ +  - ]:       1753 :                           GProp_GProps myProps2;
    2590         [ +  - ]:       1753 :                           BRepGProp::LinearProperties(edge, myProps2);
    2591         [ +  - ]:       1753 :                           gp_Pnt center2 = myProps2.CentreOfMass();
    2592 [ +  - ][ +  + ]:       1753 :                           if(center1.IsEqual(center2, TOL))
    2593                 :            :                             {
    2594                 :       1062 :                               same_edge = CUBIT_TRUE;
    2595 [ +  - ][ +  + ]:       1753 :                               break;
    2596                 :            :                             }
    2597                 :        691 :                         }
    2598         [ +  + ]:       1458 :                       if(!same_edge)
    2599                 :            :                         {
    2600         [ +  - ]:        396 :                           list_of_edges.Append(temp_edge);
    2601 [ +  - ][ +  - ]:        396 :                           TopoDS_Shape* topo_shape = new TopoDS_Shape(edge_face);
    2602         [ +  - ]:        396 :                           tool_faces_edges.append(topo_shape);
    2603                 :            :                         }
    2604         [ +  - ]:       1458 :                     }//end 'for'
    2605                 :            :                 }//end  'else if'
    2606         [ +  - ]:      21300 :               intersector.NextIntersection();
    2607         [ +  - ]:      47124 :             } //end 'for'
    2608                 :            :         }//end 'else'
    2609 [ +  - ][ +  + ]:        931 :       if (from_face.IsNull())
    2610                 :            :         {
    2611                 :        228 :           more_face = CUBIT_FALSE;
    2612         [ +  - ]:        228 :           DLIList<TopoDS_Shape*> shape_list;
    2613 [ +  - ][ -  + ]:        228 :           for(int iii = 0; iii < tool_faces_edges.size(); iii++)
    2614                 :            :             {
    2615         [ #  # ]:          0 :               int size = shape_list.size();
    2616 [ #  # ][ #  # ]:          0 :               shape_list.append_unique(tool_faces_edges.get_and_step());
    2617 [ #  # ][ #  # ]:          0 :               if (size < shape_list.size())
    2618                 :            :                 {
    2619         [ #  # ]:          0 :                   shape_list.last();
    2620 [ #  # ][ #  # ]:          0 :                   shape_list.get()->Nullify();
    2621 [ #  # ][ #  # ]:          0 :                   delete shape_list.get();
         [ #  # ][ #  # ]
    2622                 :            :                 }
    2623                 :            :             }
    2624         [ +  - ]:        228 :           tool_faces_edges.clean_out();
    2625                 :            : 
    2626 [ +  - ][ +  + ]:        898 :           for (int iii=0; iii < from_faces.size(); iii++)
    2627                 :            :             {
    2628         [ +  - ]:        670 :               TopoDS_Face* topo_face = from_faces.get_and_step();
    2629         [ +  - ]:        670 :               topo_face->Nullify();
    2630 [ +  - ][ +  - ]:        670 :               delete topo_face;
                 [ +  - ]
    2631                 :        670 :               topo_face = NULL;
    2632                 :            :             }
    2633         [ +  - ]:        228 :           continue;
    2634                 :            :         }
    2635                 :            :   
    2636         [ +  - ]:        703 :       TopTools_ListIteratorOfListOfShape Itor;
    2637                 :            : 
    2638                 :            :       //list_of_edges is the intersection edges on tool_faces_edges 
    2639         [ +  - ]:        703 :       Itor.Initialize(list_of_edges);
    2640         [ +  - ]:        703 :       int total_edges = list_of_edges.Extent();
    2641 [ +  - ][ +  - ]:       1634 :       DLIList<Curve*> curve_list;
           [ +  -  +  - ]
    2642 [ +  - ][ +  - ]:       1406 :       DLIList<OCCCurve*> occ_curves;
              [ +  -  + ]
    2643                 :        703 :       CubitBoolean topo_changed = CUBIT_FALSE;
    2644         [ +  - ]:        703 :       tool_faces_edges.reset();
    2645                 :            : 
    2646                 :            :       //check to see if the intersection edge is:
    2647                 :            :       //1. on from_face: if not, skip it
    2648                 :            :       //2. overlap with from_edges : if not, add the edge for splitting face
    2649                 :            :       //3. if overlap, is it the same edge:if not add it for splitting edge
    2650                 :            :       // if yes, skip it too
    2651                 :            : 
    2652                 :        703 :       Surface* face = NULL;
    2653 [ +  - ][ +  - ]:        703 :       if (OCCQueryEngine::instance()->OCCMap->IsBound(from_face))
                 [ +  + ]
    2654                 :            :         {
    2655 [ +  - ][ +  - ]:        637 :           int i = OCCQueryEngine::instance()->OCCMap->Find(from_face);
    2656 [ +  - ][ +  - ]:        637 :           face = (OCCSurface*)(OCCQueryEngine::instance()->OccToCGM->find(i))->second;
                 [ +  - ]
    2657                 :            :         }
    2658         [ +  + ]:        703 :       if (face == NULL)
    2659                 :            :       {
    2660                 :         66 :         face_created = CUBIT_TRUE;
    2661 [ +  - ][ +  - ]:         66 :         face = OCCQueryEngine::instance()->populate_topology_bridge(from_face);
    2662                 :            :       }
    2663         [ -  + ]:        703 :       OCCSurface* occ_face = CAST_TO(face, OCCSurface);
    2664                 :            : 
    2665         [ +  - ]:        703 :       GeometryType type = occ_face->geometry_type();
    2666         [ +  - ]:        703 :       CubitBoolean periodic = occ_face->is_periodic();
    2667                 :            : 
    2668 [ +  - ][ +  - ]:       1406 :       DLIList<Curve*> common_curves;
              [ +  -  + ]
    2669 [ +  - ][ +  - ]:       2203 :       for(; Itor.More(); Itor.Next())
                 [ +  + ]
    2670                 :            :       {
    2671 [ +  - ][ +  - ]:       1500 :         TopoDS_Edge edge = TopoDS::Edge(Itor.Value());
                 [ +  - ]
    2672                 :            : 
    2673                 :            :         //copy the edge for imprinting.
    2674 [ +  - ][ +  - ]:       3000 :         BRepBuilderAPI_Copy api_copy(edge);
    2675 [ +  - ][ +  - ]:       3000 :         TopoDS_Shape newShape = api_copy.ModifiedShape(edge);
                 [ +  - ]
    2676 [ +  - ][ +  - ]:       1500 :         edge = TopoDS::Edge(newShape);
    2677                 :       1500 :         Curve* curve = NULL;
    2678 [ +  - ][ +  - ]:       1500 :         if(!OCCQueryEngine::instance()->OCCMap->IsBound(edge))
                 [ +  - ]
    2679                 :            :         {
    2680 [ +  - ][ +  - ]:       1500 :           curve = OCCQueryEngine::instance()->populate_topology_bridge(edge, true);
    2681         [ +  - ]:       1500 :           DLIList<OCCPoint*> points;
    2682         [ -  + ]:       1500 :           OCCCurve* occ_c = CAST_TO(curve, OCCCurve);
    2683         [ +  - ]:       1500 :           occ_c->get_points(points);
    2684 [ +  - ][ +  + ]:       4340 :           for(int i = 0 ; i <  points.size(); i++)
    2685 [ +  - ][ +  - ]:       4340 :             points.get_and_step()->remove_curve(occ_c);
                 [ +  - ]
    2686                 :            :         }
    2687                 :            :         else
    2688 [ #  # ][ #  # ]:          0 :           curve = OCCQueryEngine::instance()->populate_topology_bridge(edge);
    2689         [ +  - ]:       1500 :         if(curve)
    2690         [ +  - ]:       1500 :           common_curves.append(curve);
    2691         [ +  - ]:       1500 :       }
    2692 [ +  - ][ +  - ]:       1406 :       DLIList<DLIList<TopoDS_Edge*>*> temp_edge_lists;
              [ +  -  + ]
    2693 [ +  - ][ +  - ]:        703 :       if (common_curves.size() >= 1)
    2694 [ +  - ][ +  - ]:        703 :          sort_curves(common_curves, temp_edge_lists);
                 [ +  - ]
    2695                 :            : 
    2696 [ +  - ][ +  + ]:        942 :       if ( common_curves.size() >= 2 && 
         [ +  + ][ +  + ]
    2697 [ +  - ][ +  - ]:        239 :            (type == CONE_SURFACE_TYPE || type == SPHERE_SURFACE_TYPE ||
    2698 [ +  - ][ -  + ]:        239 :             type == TORUS_SURFACE_TYPE ||type == UNDEFINED_SURFACE_TYPE ||
    2699                 :            :             type == SPLINE_SURFACE_TYPE))
    2700                 :            :       {
    2701                 :            :         //if the two shapes has common volume, do boolean operations
    2702         [ +  - ]:         40 :         BRepAlgoAPI_Common intersector(*from_shape, *tool_shape);
    2703 [ +  - ][ +  - ]:         80 :         TopTools_ListOfShape shapes;
                 [ +  - ]
    2704 [ +  - ][ +  - ]:         40 :         shapes.Assign(intersector.Modified(*tool_shape));
    2705                 :            :      
    2706 [ +  - ][ +  - ]:         80 :         TopoDS_Shape common_shape;
                 [ +  - ]
    2707 [ +  - ][ +  - ]:         40 :         if (shapes.IsEmpty())
    2708 [ +  - ][ +  - ]:         40 :           common_shape = intersector.Shape();
    2709                 :            :         else 
    2710 [ #  # ][ #  # ]:          0 :           common_shape = shapes.First();
    2711                 :            : 
    2712 [ +  - ][ +  - ]:         40 :         if(!common_shape.IsNull()) 
    2713                 :            :         { 
    2714         [ +  - ]:         40 :           TopTools_IndexedMapOfShape M;
    2715         [ +  - ]:         40 :           TopExp::MapShapes(common_shape, TopAbs_SOLID, M);
    2716 [ +  - ][ -  + ]:         40 :           if(M.Extent() > 0)
    2717                 :            :           {
    2718         [ #  # ]:          0 :             GProp_GProps myProps;
    2719         [ #  # ]:          0 :             BRepGProp::VolumeProperties(common_shape, myProps);
    2720         [ #  # ]:          0 :             double after_mass = myProps.Mass();
    2721         [ #  # ]:          0 :             BRepGProp::VolumeProperties(*from_shape, myProps);
    2722         [ #  # ]:          0 :             double orig_mass = myProps.Mass();
    2723 [ #  # ][ #  # ]:          0 :             if(fabs(-after_mass + orig_mass) > TOL && after_mass > TOL)
    2724 [ +  - ][ +  - ]:         40 :               return 1; 
    2725 [ +  - ][ +  - ]:         40 :           }
    2726                 :            :           //have to use boolean operation, see 
    2727                 :            :           //http://www.opencascade.org/org/forum/thread_20672/ for more info
    2728                 :         40 :         }
    2729                 :            :       }
    2730                 :            : 
    2731         [ +  - ]:        703 :       list_of_edges.Clear(); 
    2732 [ +  - ][ +  - ]:        703 :       if (common_curves.size() >= 1)
    2733                 :            :         {
    2734                 :            :           DLIList<TopoDS_Edge*>* edge_list;
    2735         [ +  - ]:        703 :           int size = temp_edge_lists.size();
    2736         [ +  + ]:       1426 :           for(int i = 0; i < size; i++)
    2737                 :            :             {
    2738         [ +  - ]:        723 :               edge_list = temp_edge_lists.get_and_step();
    2739                 :            :               //make sure the copied edges are sharing vertices.
    2740         [ +  - ]:        723 :               BRepBuilderAPI_MakeWire myWire;
    2741         [ +  - ]:        723 :               edge_list->reset();
    2742 [ +  - ][ +  + ]:       2223 :               for(int j = 0; j < edge_list->size(); j++)
    2743                 :            :                 {
    2744 [ +  - ][ +  - ]:       1500 :                   TopoDS_Edge e = *(edge_list->get_and_step());
    2745                 :            :                   //Don't include zero length edge.
    2746         [ +  - ]:       1500 :                   GProp_GProps myProps;
    2747         [ +  - ]:       1500 :                   BRepGProp::LinearProperties(e, myProps);
    2748         [ +  - ]:       1500 :                   double d = myProps.Mass();
    2749         [ +  - ]:       1500 :                   if(d > TOL) 
    2750         [ +  - ]:       1500 :                     myWire.Add(e);
    2751         [ +  - ]:       1500 :                 }
    2752 [ +  - ][ +  - ]:       1446 :               TopoDS_Wire wire = myWire.Wire();
                 [ +  - ]
    2753 [ +  - ][ +  - ]:       1446 :               BRepTools_WireExplorer Ex(wire); 
    2754 [ +  - ][ +  - ]:       2163 :               for(; Ex.More(); Ex.Next())
                 [ +  + ]
    2755 [ +  - ][ +  - ]:       1440 :                 list_of_edges.Append(Ex.Current());
    2756         [ +  - ]:        723 :               edge_list->clean_out();
    2757 [ +  - ][ +  - ]:        723 :               delete edge_list;
    2758         [ +  - ]:        723 :             }
    2759                 :            :         }
    2760 [ +  - ][ +  - ]:       2143 :       for(Itor.Initialize(list_of_edges); Itor.More(); Itor.Next())
         [ +  - ][ +  + ]
    2761                 :            :         {
    2762 [ +  - ][ +  - ]:       1440 :           TopoDS_Edge edge = TopoDS::Edge(Itor.Value());
                 [ +  - ]
    2763                 :       1440 :           CubitBoolean added = CUBIT_FALSE;
    2764                 :            :           //check to see if the intersection edge is on from_face
    2765 [ +  - ][ +  - ]:       2880 :           TopExp_Explorer Ex;
                 [ +  + ]
    2766                 :       1440 :           CubitBoolean skipped = CUBIT_FALSE;
    2767         [ +  - ]:       1440 :           GProp_GProps myProps1;
    2768         [ +  - ]:       1440 :           BRepGProp::LinearProperties(edge, myProps1);
    2769         [ +  - ]:       1440 :           double d1 = myProps1.Mass();
    2770                 :       1440 :           Curve* curve = NULL;
    2771                 :            :           //edge should all be bounded, it comes from common_curves
    2772 [ +  - ][ +  - ]:       1440 :           if (OCCQueryEngine::instance()->OCCMap->IsBound(edge))
                 [ +  + ]
    2773                 :            :           {
    2774 [ +  - ][ +  - ]:        703 :             int i = OCCQueryEngine::instance()->OCCMap->Find(edge);
    2775                 :            :             curve = (Curve*)
    2776 [ +  - ][ +  - ]:        703 :                     (OCCQueryEngine::instance()->OccToCGM->find(i))->second;
                 [ +  - ]
    2777                 :            :           }
    2778                 :            :           else 
    2779                 :            :           {
    2780 [ +  - ][ +  - ]:        737 :             curve = OCCQueryEngine::instance()->populate_topology_bridge(edge, true);
    2781         [ +  - ]:        737 :             DLIList<OCCPoint*> points;
    2782         [ -  + ]:        737 :             OCCCurve* occ_c = CAST_TO(curve, OCCCurve);
    2783         [ +  - ]:        737 :             occ_c->get_points(points);
    2784 [ +  - ][ +  + ]:       2191 :             for(int i = 0 ; i <  points.size(); i++)
    2785 [ +  - ][ +  - ]:       2191 :               points.get_and_step()->remove_curve(occ_c);
                 [ +  - ]
    2786                 :            :           }
    2787         [ +  - ]:       1440 :           gp_Pnt pt = myProps1.CentreOfMass();
    2788         [ +  - ]:       1440 :           CubitVector p = curve->center_point();
    2789                 :            : 
    2790         [ +  - ]:       1440 :           CubitVector point_on_surf;
    2791 [ +  - ][ +  - ]:       1440 :           occ_face->closest_point_trimmed(p, point_on_surf);
    2792                 :            : 
    2793 [ +  - ][ -  + ]:       1440 :           if(p.distance_between(point_on_surf) > TOL) //edge not on from_face
    2794                 :            :             {
    2795                 :          0 :               skipped = CUBIT_TRUE;
    2796                 :          0 :               total_edges--;
    2797                 :            :             }
    2798                 :            : 
    2799                 :            :           else 
    2800                 :            :             {
    2801 [ +  - ][ +  - ]:       4304 :               for (Ex.Init(from_face, TopAbs_EDGE); Ex.More(); Ex.Next())
         [ +  - ][ +  + ]
    2802                 :            :                 {
    2803                 :            :                   //check if the edge is on from_face edges, add such edge on existing
    2804                 :            :                   //edge to split it.
    2805 [ +  - ][ +  - ]:       4238 :                   TopoDS_Edge from_edge = TopoDS::Edge(Ex.Current());
                 [ +  - ]
    2806                 :            :          
    2807         [ +  - ]:       4238 :                   GProp_GProps myProps2;
    2808         [ +  - ]:       4238 :                   BRepGProp::LinearProperties(from_edge, myProps2);
    2809         [ +  - ]:       4238 :                   double d2 = myProps2.Mass();
    2810         [ +  - ]:       4238 :                   gp_Pnt pt2 = myProps2.CentreOfMass();
    2811                 :       4238 :                   CubitBoolean found_ = CUBIT_FALSE;
    2812                 :            :                   Curve* from_curve;
    2813 [ +  - ][ +  - ]:       4238 :                   if (OCCQueryEngine::instance()->OCCMap->IsBound(from_edge))
                 [ +  + ]
    2814                 :            :                   {
    2815 [ +  - ][ +  - ]:       3963 :                     int i = OCCQueryEngine::instance()->OCCMap->Find(from_edge);
    2816                 :            :                     from_curve = (OCCCurve*)
    2817 [ +  - ][ +  - ]:       3963 :                         (OCCQueryEngine::instance()->OccToCGM->find(i))->second;
                 [ +  - ]
    2818                 :       3963 :                     found_ = CUBIT_TRUE;
    2819                 :            :                   }
    2820                 :            :                   else
    2821 [ +  - ][ +  - ]:        275 :                     from_curve = OCCQueryEngine::instance()->populate_topology_bridge(from_edge, true);
    2822         [ -  + ]:       4238 :                   if(!from_curve)
    2823                 :          0 :                     continue;
    2824                 :            : 
    2825         [ -  + ]:       4238 :                   OCCCurve* occ_curve = CAST_TO(from_curve, OCCCurve);
    2826                 :            : 
    2827 [ +  - ][ +  + ]:       4238 :                   if(pt.IsEqual(pt2, TOL) && fabs(d2-d1)< TOL) //overlap
         [ +  + ][ +  + ]
    2828                 :            :                   {
    2829                 :       1308 :                     skipped = CUBIT_TRUE;
    2830                 :       1308 :                     total_edges--;
    2831                 :       1308 :                     break;
    2832                 :            :                   }
    2833                 :            : 
    2834                 :       2930 :                   CubitPointContainment pc = CUBIT_PNT_OFF;
    2835         [ +  - ]:       2930 :                   pc = occ_curve->point_containment(p);
    2836 [ +  + ][ +  + ]:       2930 :                   if((d2 - d1) > TOL && pc == CUBIT_PNT_ON) 
    2837                 :            :                   {
    2838                 :         66 :                     added = CUBIT_TRUE;
    2839         [ +  - ]:         66 :                     splitor.Add(edge, from_edge);
    2840                 :         66 :                     total_edges--;
    2841                 :         66 :                     break;
    2842                 :            :                   }
    2843                 :            : 
    2844 [ +  + ][ +  - ]:       2864 :                   if(!found_ && from_curve)
    2845         [ +  - ]:        176 :                     OCCQueryEngine::instance()->
    2846 [ +  - ][ +  - ]:       4238 :                       delete_solid_model_entities(from_curve);
              [ +  -  + ]
    2847                 :       4238 :                 } 
    2848 [ +  - ][ +  + ]:       1440 :               if(list_of_edges.Extent() == 1 && !skipped) 
         [ -  + ][ -  + ]
    2849                 :            :                 {
    2850                 :          0 :                   added = CUBIT_TRUE;
    2851         [ #  # ]:          0 :                   curve_list.append(curve); 
    2852                 :            :                 }
    2853                 :            :             } 
    2854         [ +  + ]:       1440 :           if(added)
    2855                 :            :             {
    2856                 :         66 :               topo_changed = CUBIT_TRUE;
    2857                 :         66 :               continue;
    2858                 :            :             }
    2859         [ +  + ]:       1374 :           if (!skipped)
    2860                 :            :             {
    2861                 :            :               //check if edge's inside from_face by checking bounding boxes  
    2862         [ +  - ]:         66 :               BRepAdaptor_Curve acurve(edge);
    2863 [ +  - ][ +  - ]:        132 :               BRepAdaptor_Surface asurface( from_face);
    2864 [ +  - ][ +  - ]:         66 :               Bnd_Box aBox_edge, aBox_face;
    2865 [ +  - ][ +  - ]:         66 :               BndLib_Add3dCurve::Add(acurve, Precision::Approximation(), aBox_edge);
    2866 [ +  - ][ +  - ]:         66 :               BndLib_AddSurface::Add(asurface, Precision::Approximation(), aBox_face);
    2867                 :            :               double min[3], max[3];
    2868         [ +  - ]:         66 :               aBox_edge.Get( min[0], min[1], min[2], max[0], max[1], max[2]);
    2869 [ +  - ][ +  - ]:        132 :               CubitBox aBox_e(min, max);
    2870         [ +  - ]:         66 :               aBox_face.Get( min[0], min[1], min[2], max[0], max[1], max[2]);
    2871 [ +  - ][ +  - ]:        132 :               CubitBox aBox_f(min, max);
    2872                 :            :               //hexlat3 has tolerance issue where aBox_e.x_min is within 
    2873                 :            :               //tolerance and greater than aBox_f.x_min, causing no edge
    2874                 :            :               //imprint of the faces. change to add consideration of tolerance
    2875                 :            :               // lose the bounding box critiral a little more.
    2876                 :         66 :               int num_satisfied = 0;
    2877                 :            :               
    2878 [ +  - ][ +  - ]:         66 :               if (aBox_f.min_x() >= 0 && aBox_e.min_x() >= aBox_f.min_x() *0.9)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    2879                 :         66 :                   num_satisfied ++;
    2880 [ +  - ][ -  + ]:         66 :               if(aBox_f.min_x() < 0 && aBox_e.min_x() >= aBox_f.min_x() *1.1)
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
    2881                 :          0 :                   num_satisfied ++;
    2882                 :            :      
    2883 [ +  - ][ -  + ]:         66 :               if (aBox_f.min_y() >= 0 && aBox_e.min_y() >= aBox_f.min_y() *0.9)
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
    2884                 :          0 :                   num_satisfied ++;
    2885 [ +  - ][ +  - ]:         66 :               if(aBox_f.min_y() < 0 && aBox_e.min_y() >= aBox_f.min_y() *1.1)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    2886                 :         66 :                   num_satisfied ++;
    2887                 :            : 
    2888 [ +  - ][ -  + ]:         66 :               if(aBox_f.min_z() >= 0 && aBox_e.min_z() >= aBox_f.min_z() *0.9)
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
    2889                 :          0 :                   num_satisfied ++;
    2890 [ +  - ][ +  - ]:         66 :               if (aBox_f.min_z() < 0 && aBox_e.min_z() >= aBox_f.min_z() *1.1)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    2891                 :         66 :                   num_satisfied ++;
    2892                 :            : 
    2893 [ +  - ][ +  - ]:         66 :               if (aBox_f.max_x() > 0  && aBox_e.max_x() <= aBox_f.max_x() *1.1)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    2894                 :         66 :                 num_satisfied ++;
    2895 [ +  - ][ -  + ]:         66 :               if(aBox_f.max_x() <= 0 && aBox_e.max_x() <= aBox_f.max_x() *0.9)
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
    2896                 :          0 :                 num_satisfied ++;
    2897 [ +  - ][ +  - ]:         66 :               if( aBox_f.max_y() > 0 && aBox_e.max_y() <= aBox_f.max_y() *1.1) 
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    2898                 :         66 :                 num_satisfied ++;
    2899 [ +  - ][ -  + ]:         66 :               if( aBox_f.max_y() <= 0 && aBox_e.max_y() <= aBox_f.max_y() *0.9)
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
    2900                 :          0 :                 num_satisfied ++;
    2901 [ +  - ][ +  - ]:         66 :               if( aBox_f.max_z() >= 0 && aBox_e.max_z() <= aBox_f.max_z() *1.1)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    2902                 :         66 :                 num_satisfied ++;  
    2903 [ +  - ][ -  + ]:         66 :               if( aBox_f.max_z() < 0 && aBox_e.max_z() <= aBox_f.max_z() *0.9)
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
    2904                 :          0 :                 num_satisfied ++;
    2905                 :            : 
    2906         [ +  - ]:         66 :               if(num_satisfied == 6) 
    2907                 :            :                 {
    2908         [ +  - ]:         66 :                   curve_list.append_unique(curve);
    2909                 :            :                 }
    2910                 :            :               else
    2911                 :            :               {
    2912         [ #  # ]:          0 :                 curve_list.remove(curve);
    2913 [ #  # ][ #  # ]:          0 :                 OCCQueryEngine::instance()->delete_solid_model_entities( curve );
    2914                 :          0 :                 total_edges--;
    2915 [ +  - ][ +  - ]:       1440 :               }
                 [ +  + ]
    2916                 :            :             }
    2917                 :       1440 :         }
    2918                 :            : 
    2919         [ +  + ]:        703 :       if(face_created)
    2920                 :            :       {
    2921 [ +  - ][ +  - ]:         66 :         OCCQueryEngine::instance()->delete_solid_model_entities(occ_face);
    2922                 :         66 :         face_created = CUBIT_FALSE;
    2923                 :            :       }
    2924 [ +  - ][ +  - ]:       1406 :       DLIList<DLIList<TopoDS_Edge*>*> edge_lists;
              [ +  -  + ]
    2925         [ +  + ]:        703 :       if ( total_edges >= 1) 
    2926                 :            :         {      
    2927                 :         73 :           CubitStatus stat = CUBIT_SUCCESS;
    2928 [ +  - ][ +  + ]:         73 :           if(curve_list.size() > 0)
    2929 [ +  - ][ +  - ]:         33 :             stat = sort_curves(curve_list, edge_lists); 
                 [ +  - ]
    2930                 :            :           else
    2931                 :            :             {
    2932 [ +  - ][ +  - ]:         40 :               TopoDS_Face* topo_face = new TopoDS_Face(from_face);
    2933         [ +  - ]:         40 :               from_faces.append(topo_face);
    2934                 :         40 :               continue;
    2935                 :            :             }
    2936                 :            :           DLIList<TopoDS_Edge*>* edge_list;
    2937         [ +  - ]:         33 :           int size = edge_lists.size();
    2938                 :            :         
    2939                 :            :           //if size > 1 , outer wire first. 
    2940         [ +  - ]:         33 :           DLIList<CubitBox*> bs;
    2941         [ +  - ]:         33 :           edge_lists.reset();
    2942 [ +  - ][ +  - ]:         66 :           CubitBox box;
                 [ +  - ]
    2943 [ +  + ][ +  - ]:         99 :           for(int i = 0; i < size && size > 1; i++)
    2944                 :            :           {
    2945         [ +  - ]:         66 :             edge_list = edge_lists.get_and_step();
    2946 [ +  - ][ +  + ]:        132 :             for(int j = 0; j < edge_list->size(); j++)
    2947                 :            :             {
    2948 [ +  - ][ +  - ]:         66 :               TopoDS_Edge e = *(edge_list->get_and_step());
    2949                 :         66 :               CubitBoolean bound = CUBIT_FALSE;
    2950                 :         66 :               Curve* curve = NULL;
    2951 [ +  - ][ +  - ]:         66 :               if(OCCQueryEngine::instance()->OCCMap->IsBound(e))
                 [ +  - ]
    2952                 :            :               {
    2953 [ +  - ][ +  - ]:         66 :                 int k = OCCQueryEngine::instance()->OCCMap->Find(e);
    2954                 :         66 :                 bound = CUBIT_TRUE;
    2955 [ +  - ][ +  - ]:         66 :                 curve = (Curve*)(OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ +  - ]
    2956                 :            :               }
    2957                 :            :               else
    2958                 :            :                 curve = OCCQueryEngine::instance()->
    2959 [ #  # ][ #  # ]:          0 :                          populate_topology_bridge(e, true);
    2960         [ +  - ]:         66 :               if(j == 0)
    2961 [ +  - ][ +  - ]:         66 :                 box = curve->bounding_box();
                 [ +  - ]
    2962                 :            :               else
    2963 [ #  # ][ #  # ]:          0 :                 box |= curve->bounding_box();
                 [ #  # ]
    2964         [ -  + ]:         66 :               if(!bound)
    2965 [ #  # ][ #  # ]:          0 :                 OCCQueryEngine::instance()->delete_solid_model_entities(curve);
    2966         [ +  - ]:         66 :             }
    2967 [ +  - ][ +  - ]:         66 :             CubitBox* pbox = new CubitBox(box);
    2968         [ +  - ]:         66 :             bs.append(pbox);
    2969                 :            :           }
    2970         [ +  - ]:         33 :           bs.append((CubitBox*) NULL);
    2971                 :            : 
    2972         [ +  + ]:         66 :           for(int i = 0; i < size-1; i++)
    2973                 :            :           {
    2974         [ +  + ]:         66 :             for(int j = i + 1; j < size; j ++)
    2975                 :            :             {
    2976         [ +  - ]:         33 :               edge_lists.reset();
    2977 [ +  - ][ +  - ]:         33 :               if(*bs[j] <= *bs[i])
         [ +  - ][ -  + ]
    2978                 :            :               {
    2979         [ #  # ]:          0 :                 edge_lists.step(j);
    2980 [ #  # ][ #  # ]:          0 :                 edge_lists.get()->clean_out();
    2981 [ #  # ][ #  # ]:          0 :                 delete edge_lists.get();
                 [ #  # ]
    2982         [ #  # ]:          0 :                 edge_lists.change_to((DLIList<TopoDS_Edge*>*)NULL);
    2983                 :          0 :                 continue;
    2984                 :            :               }
    2985 [ +  - ][ +  - ]:         33 :               if(*bs[i] <= *bs[j])
         [ +  - ][ -  + ]
    2986                 :            :               {
    2987         [ #  # ]:          0 :                 edge_lists.step(i);
    2988 [ #  # ][ #  # ]:          0 :                 edge_lists.get()->clean_out();
    2989 [ #  # ][ #  # ]:          0 :                 delete edge_lists.get();
                 [ #  # ]
    2990         [ #  # ]:          0 :                 edge_lists.change_to((DLIList<TopoDS_Edge*>*)NULL);
    2991                 :          0 :                 break;
    2992                 :            :               }
    2993                 :            :             }
    2994                 :            :           }
    2995 [ +  + ][ +  - ]:         99 :           for(int i = 0; i < size && size > 1; i++)
    2996 [ +  - ][ +  + ]:         66 :             delete bs.pop();
                 [ +  - ]
    2997                 :            : 
    2998         [ +  - ]:         33 :           edge_lists.remove_all_with_value((DLIList<TopoDS_Edge*>*)NULL);
    2999                 :            : 
    3000         [ +  - ]:         33 :           size = edge_lists.size();
    3001 [ +  + ][ +  - ]:         99 :           for (int iii = 0; iii < size; iii++)
                 [ +  - ]
    3002                 :            :             {
    3003         [ +  - ]:         66 :               edge_list = edge_lists.pop();
    3004                 :            : 
    3005                 :            :               //check if the edges make a split of the surface, error out if it's
    3006                 :            :               //just a scar on the surface
    3007                 :         66 :               int count_intersection = 0;
    3008         [ +  - ]:         66 :               if (stat == CUBIT_FAILURE) //Open wire
    3009                 :            :                 {
    3010 [ +  - ][ +  - ]:         66 :                   count_intersection = check_intersection(edge_list, from_face);
                 [ +  - ]
    3011                 :            :             
    3012         [ -  + ]:         66 :                   if (count_intersection == 1 )
    3013                 :            :                   {
    3014 [ #  # ][ #  # ]:          0 :                     PRINT_WARNING("Cant make a scar on existing face without splitting it. \n");
         [ #  # ][ #  # ]
    3015         [ #  # ]:          0 :                     edge_list->clean_out();
    3016 [ #  # ][ #  # ]:          0 :                     delete edge_list;
    3017                 :            :                   }
    3018                 :            :                 } 
    3019 [ +  - ][ +  - ]:         66 :               if (stat || count_intersection == 2)
    3020                 :            :                 {
    3021         [ +  - ]:         66 :                   BRepBuilderAPI_MakeWire myWire;
    3022         [ +  - ]:         66 :                   edge_list->reset(); 
    3023 [ +  - ][ +  - ]:        132 :                   DLIList<Curve*> wire_curves;
                 [ +  - ]
    3024 [ +  - ][ +  + ]:        132 :                   for(int i = 0; i < edge_list->size(); i++)
    3025                 :            :                     {
    3026 [ +  - ][ +  - ]:         66 :                       TopoDS_Edge e = *(edge_list->get_and_step());
    3027                 :            :                       //remove curve from its vertice's curve list
    3028 [ +  - ][ +  - ]:         66 :                       if(OCCQueryEngine::instance()->OCCMap->IsBound(e))
                 [ +  - ]
    3029                 :            :                       {
    3030 [ +  - ][ +  - ]:         66 :                         int j = OCCQueryEngine::instance()->OCCMap->Find(e);
    3031 [ +  - ][ +  - ]:         66 :                         Curve* curve = (Curve*)(OCCQueryEngine::instance()->OccToCGM->find(j))->second;
                 [ +  - ]
    3032                 :         66 :                         OCCCurve* curve_to_remove = (OCCCurve*) curve;
    3033         [ +  - ]:         66 :                         wire_curves.append(curve);
    3034         [ +  - ]:         66 :                         DLIList<OCCPoint*> points;
    3035         [ +  - ]:         66 :                         curve_to_remove->get_points(points);
    3036 [ +  - ][ +  + ]:        198 :                         for (int k = 0; k < points.size(); k++)
    3037 [ +  - ][ +  - ]:        198 :                           points.get_and_step()->remove_curve(curve_to_remove);
                 [ +  - ]
    3038                 :            :                       }
    3039 [ #  # ][ #  # ]:          0 :                       else if(periodic && count_intersection != 2)
    3040                 :            :                       {
    3041                 :            :                         Curve* curve = OCCQueryEngine::instance()->
    3042 [ #  # ][ #  # ]:          0 :                                populate_topology_bridge(e,true);
    3043         [ #  # ]:          0 :                         wire_curves.append(curve);
    3044                 :            :                       }
    3045         [ +  - ]:         66 :                       myWire.Add(e); 
    3046         [ +  - ]:         66 :                     }
    3047         [ +  - ]:         66 :                   edge_list->clean_out();
    3048 [ +  - ][ +  - ]:         66 :                   delete edge_list;
    3049 [ -  + ][ #  # ]:         66 :                   if(!periodic || count_intersection == 2 ||
                 [ #  # ]
    3050                 :            :                      type == PLANE_SURFACE_TYPE)
    3051                 :            :                   {
    3052 [ +  - ][ +  - ]:         66 :                     splitor.Add(myWire.Wire(),from_face);
    3053                 :         66 :                     topo_changed = CUBIT_TRUE; 
    3054                 :            :                      
    3055                 :            :                   }
    3056                 :            :                   else 
    3057                 :            :                   {
    3058                 :            :                     //use the myWire to create a surface and webcut the 
    3059                 :            :                     //periodic body.
    3060                 :            :                     Surface *wire_surf = make_Surface(BEST_FIT_SURFACE_TYPE,
    3061         [ #  # ]:          0 :                        wire_curves);
    3062         [ #  # ]:          0 :                     if(wire_surf == NULL)
    3063         [ #  # ]:          0 :                       wire_surf = make_Surface(PLANE_SURFACE_TYPE, wire_curves);
    3064         [ #  # ]:          0 :                     if(wire_surf)
    3065                 :            :                     {
    3066         [ #  # ]:          0 :                       OCCSurface* occ_wire_s = CAST_TO(wire_surf, OCCSurface);
    3067         [ #  # ]:          0 :                       TopoDS_Face *topo_face = occ_wire_s->get_TopoDS_Face();
    3068         [ #  # ]:          0 :                       on_faces.append(topo_face);
    3069 [ +  - ][ +  - ]:         66 :                       return 3; 
    3070                 :            :                     }
    3071                 :         66 :                   } 
    3072                 :            :                 }
    3073                 :         33 :             }
    3074                 :            :         } 
    3075         [ +  + ]:        663 :       if(topo_changed)
    3076                 :            :         {
    3077         [ +  - ]:         33 :           splitor.Build();
    3078                 :         33 :           topo_changed = CUBIT_FALSE;
    3079 [ +  - ][ +  - ]:         33 :           if(splitor.IsDone())
    3080                 :            :             {
    3081                 :            :               //take care of on_faces list first:after operation, the on_faces
    3082                 :            :               // will have at least one face changed, update the pointer.
    3083         [ +  - ]:         33 :               int size = on_faces.size();
    3084         [ -  + ]:         33 :               if (size > 0)
    3085                 :            :                 {
    3086         [ #  # ]:          0 :                   for(int k = 0; k < size; k++)
    3087                 :            :                     {
    3088         [ #  # ]:          0 :                       TopoDS_Face* compare_face = on_faces.get();
    3089         [ #  # ]:          0 :                       TopTools_ListOfShape shapes;
    3090 [ #  # ][ #  # ]:          0 :                       shapes.Assign(splitor.Modified(*compare_face));
    3091 [ #  # ][ #  # ]:          0 :                       if(shapes.Extent() > 0 && 
         [ #  # ][ #  # ]
    3092 [ #  # ][ #  # ]:          0 :                          !compare_face->IsSame(shapes.First()))
    3093                 :            :                       {
    3094         [ #  # ]:          0 :                         on_faces.change_to(NULL);
    3095 [ #  # ][ #  # ]:          0 :                         while(shapes.Extent() > 0)
    3096                 :            :                         {
    3097                 :            :                           TopoDS_Face* face = 
    3098 [ #  # ][ #  # ]:          0 :                                 new TopoDS_Face(TopoDS::Face(shapes.First())); 
         [ #  # ][ #  # ]
    3099         [ #  # ]:          0 :                           shapes.RemoveFirst();
    3100         [ #  # ]:          0 :                           on_faces.append(face);
    3101                 :            :                         }
    3102                 :            :                       }
    3103         [ #  # ]:          0 :                       on_faces.step();
    3104         [ #  # ]:          0 :                     }
    3105         [ #  # ]:          0 :                     on_faces.remove_all_with_value(NULL);
    3106                 :            :                 }
    3107                 :            : 
    3108 [ +  - ][ +  - ]:         33 :               TopoDS_Shape new_from_shape = splitor.Shape();
    3109 [ +  - ][ -  + ]:         33 :               if(from_shape->ShapeType() == TopAbs_COMPOUND)
    3110                 :            :                 {
    3111 [ #  # ][ #  # ]:          0 :                   TopoDS_Compound old_csolid = TopoDS::Compound(*from_shape);
    3112         [ #  # ]:          0 :                   OCCBody::update_OCC_entity(old_csolid, new_from_shape, &splitor);
    3113 [ #  # ][ #  # ]:          0 :                   if(!old_csolid.IsEqual(new_from_shape))
    3114                 :            :                   {
    3115         [ #  # ]:          0 :                      from_shape->Nullify();
    3116         [ #  # ]:          0 :                      *from_shape = new_from_shape;
    3117         [ #  # ]:          0 :                   }                     
    3118                 :            :                 }
    3119                 :            : 
    3120 [ +  - ][ +  - ]:         33 :               else if(from_shape->ShapeType() == TopAbs_SOLID)
    3121                 :            :                 {
    3122 [ +  - ][ +  - ]:         33 :                   TopoDS_Solid old_solid = TopoDS::Solid(*from_shape);
    3123         [ +  - ]:         33 :                   OCCLump::update_OCC_entity(old_solid, new_from_shape, &splitor);
    3124 [ +  - ][ +  - ]:         33 :                   if(!old_solid.IsEqual(new_from_shape))
    3125                 :            :                   { 
    3126         [ +  - ]:         33 :                      from_shape->Nullify();
    3127         [ +  - ]:         33 :                      *from_shape = new_from_shape;
    3128         [ +  - ]:         33 :                   }
    3129                 :            :                 }
    3130 [ #  # ][ #  # ]:          0 :               else if(from_shape->ShapeType() == TopAbs_SHELL)
    3131                 :            :                 {
    3132 [ #  # ][ #  # ]:          0 :                   TopoDS_Shell old_shell = TopoDS::Shell(*from_shape);
    3133         [ #  # ]:          0 :                   OCCShell::update_OCC_entity(old_shell,new_from_shape, &splitor);
    3134 [ #  # ][ #  # ]:          0 :                   if(!old_shell.IsEqual(new_from_shape))
    3135                 :            :                   {
    3136         [ #  # ]:          0 :                      from_shape->Nullify();
    3137         [ #  # ]:          0 :                      *from_shape = new_from_shape;
    3138         [ #  # ]:          0 :                   }
    3139                 :            :                 }
    3140 [ #  # ][ #  # ]:          0 :               else if(from_shape->ShapeType() == TopAbs_FACE)
    3141                 :            :                 {
    3142 [ #  # ][ #  # ]:          0 :                   TopoDS_Face old_face = TopoDS::Face(*from_shape);
    3143         [ #  # ]:          0 :                   OCCSurface::update_OCC_entity(old_face,new_from_shape, &splitor);
    3144 [ #  # ][ #  # ]:          0 :                   if(!old_face.IsEqual(new_from_shape))
    3145                 :            :                   {
    3146         [ #  # ]:          0 :                      from_shape->Nullify();
    3147         [ #  # ]:          0 :                      *from_shape = new_from_shape;
    3148         [ #  # ]:          0 :                   }
    3149                 :            :                 }
    3150                 :            : 
    3151 [ +  - ][ +  - ]:         66 :               TopTools_ListOfShape shapes;
    3152 [ +  - ][ -  + ]:         33 :               for(int i = 0; i < from_faces.size(); i++)
    3153                 :            :                 {
    3154         [ #  # ]:          0 :                   TopoDS_Face* topo_face = from_faces.get();
    3155 [ #  # ][ #  # ]:          0 :                   shapes.Assign(splitor.Modified(*topo_face));
    3156 [ #  # ][ #  # ]:          0 :                   topo_face = new TopoDS_Face(TopoDS::Face(shapes.First()));
         [ #  # ][ #  # ]
    3157 [ #  # ][ #  # ]:          0 :                   from_faces.get()->Nullify();
    3158 [ #  # ][ #  # ]:          0 :                   delete from_faces.get();
         [ #  # ][ #  # ]
    3159         [ #  # ]:          0 :                   from_faces.change_to(topo_face);
    3160         [ #  # ]:          0 :                   from_faces.step();
    3161                 :            :                 } 
    3162         [ +  - ]:         33 :               count++;
    3163                 :            :             }
    3164                 :            :         }
    3165                 :            :       else
    3166                 :            :         {
    3167 [ +  - ][ +  - ]:        630 :           TopoDS_Face* topo_face = new TopoDS_Face(from_face);
    3168 [ +  - ][ +  - ]:        703 :           from_faces.append(topo_face);
              [ +  +  - ]
    3169                 :            :         } 
    3170                 :        931 :     }
    3171                 :            :   
    3172 [ +  - ][ +  - ]:        456 :   TopExp_Explorer Ex;
    3173                 :        228 :   int num_face = 0;
    3174 [ +  - ][ +  - ]:       1728 :   for (Ex.Init(*from_shape, TopAbs_FACE); Ex.More(); Ex.Next())
         [ +  - ][ +  + ]
    3175                 :            :     {
    3176 [ +  - ][ +  - ]:       1500 :       TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ +  - ]
    3177                 :       1500 :       num_face++;
    3178         [ +  - ]:       1500 :     }
    3179                 :            :   
    3180                 :            : #ifdef DEBUG  
    3181 [ +  - ][ +  - ]:        228 :   PRINT_INFO("Total %d cuts performed, with from_shape having %d faces.\n", count, num_face); 
         [ +  - ][ +  - ]
    3182                 :            : #endif
    3183                 :            : 
    3184         [ +  + ]:        228 :   if (count > 0)
    3185                 :         33 :     return 0;
    3186         [ +  - ]:        423 :   return 2;
    3187                 :            : }
    3188                 :            : 
    3189                 :            : //===============================================================================
    3190                 :            : // Function   : find_imprinting_edge
    3191                 :            : // Member Type: PROTECTED
    3192                 :            : // Description: imprint boolean operation on OCC-based bodies.
    3193                 :            : //              from_shape must be TopoDS_Face or above, tool_shape must be
    3194                 :            : //              TopoDS_Edge.
    3195                 :            : // Author     : Jane HU
    3196                 :            : // Date       : 05/08
    3197                 :            : //===============================================================================
    3198                 :          0 : TopoDS_Edge* OCCModifyEngine::find_imprinting_edge(TopoDS_Shape& from_shape,
    3199                 :            :                                         TopoDS_Edge& tool_shape,
    3200                 :            :                                         DLIList<TopoDS_Face*>& from_faces)const
    3201                 :            : {
    3202                 :          0 :   TopoDS_Edge* edge = NULL;
    3203                 :            :   //list of face on from_shape that has been imprinted
    3204         [ #  # ]:          0 :   from_faces.clean_out();
    3205         [ #  # ]:          0 :   BRepAdaptor_Curve acurve(tool_shape);
    3206 [ #  # ][ #  # ]:          0 :   Bnd_Box aBox_edge, aBox_face;
    3207 [ #  # ][ #  # ]:          0 :   BndLib_Add3dCurve::Add(acurve, Precision::Approximation(), aBox_edge);
    3208                 :            : 
    3209 [ #  # ][ #  # ]:          0 :   TopExp_Explorer Ex;
    3210 [ #  # ][ #  # ]:          0 :   for (Ex.Init(from_shape, TopAbs_FACE); Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    3211                 :            :   {
    3212 [ #  # ][ #  # ]:          0 :     TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    3213 [ #  # ][ #  # ]:          0 :     BRepAdaptor_Surface asurface( face);
                 [ #  # ]
    3214         [ #  # ]:          0 :     aBox_face.SetVoid();
    3215 [ #  # ][ #  # ]:          0 :     BndLib_AddSurface::Add(asurface, Precision::Approximation(), aBox_face);
    3216 [ #  # ][ #  # ]:          0 :     if (aBox_face.IsOut(aBox_edge))
    3217                 :          0 :       continue;
    3218                 :            : 
    3219 [ #  # ][ #  # ]:          0 :     BRepAlgoAPI_Common intersector(face, tool_shape);
                 [ #  # ]
    3220 [ #  # ][ #  # ]:          0 :     TopTools_ListOfShape shapes;
                 [ #  # ]
    3221 [ #  # ][ #  # ]:          0 :     shapes.Assign(intersector.Generated(tool_shape));
    3222 [ #  # ][ #  # ]:          0 :     if(shapes.IsEmpty())
    3223 [ #  # ][ #  # ]:          0 :       shapes.Assign(intersector.Modified(tool_shape));
    3224 [ #  # ][ #  # ]:          0 :     if (shapes.IsEmpty())
    3225                 :          0 :       continue;
    3226 [ #  # ][ #  # ]:          0 :     if ( shapes.Extent() > 1)
    3227                 :            :     {
    3228 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Edge has multiple intersection with the shape, make it simpler. \n");
         [ #  # ][ #  # ]
    3229                 :          0 :       continue;
    3230                 :            :     }
    3231 [ #  # ][ #  # ]:          0 :     if (shapes.First().ShapeType() != TopAbs_EDGE  && 
         [ #  # ][ #  # ]
                 [ #  # ]
    3232 [ #  # ][ #  # ]:          0 :         shapes.First().ShapeType() != TopAbs_COMPOUND)
    3233                 :          0 :       continue;
    3234                 :            : 
    3235 [ #  # ][ #  # ]:          0 :     TopoDS_Shape result = shapes.First();
         [ #  # ][ #  # ]
    3236 [ #  # ][ #  # ]:          0 :     TopoDS_Edge common_edge;
                 [ #  # ]
    3237 [ #  # ][ #  # ]:          0 :     if(edge == NULL && result.ShapeType() == TopAbs_EDGE)
         [ #  # ][ #  # ]
    3238 [ #  # ][ #  # ]:          0 :       common_edge = TopoDS::Edge(result);
    3239                 :            :     
    3240 [ #  # ][ #  # ]:          0 :     else if(edge == NULL && 
                 [ #  # ]
    3241         [ #  # ]:          0 :             result.ShapeType() == TopAbs_COMPOUND)
    3242                 :            :     {
    3243         [ #  # ]:          0 :       TopExp_Explorer Ex(result, TopAbs_EDGE);
    3244 [ #  # ][ #  # ]:          0 :       if(Ex.More())
    3245 [ #  # ][ #  # ]:          0 :         common_edge = TopoDS::Edge(Ex.Current());
         [ #  # ][ #  # ]
    3246                 :            :     }  
    3247 [ #  # ][ #  # ]:          0 :     if (common_edge.IsNull())
    3248                 :          0 :       continue;
    3249 [ #  # ][ #  # ]:          0 :     BRepBuilderAPI_Copy api_copy(common_edge);
         [ #  # ][ #  # ]
    3250 [ #  # ][ #  # ]:          0 :     TopoDS_Shape newShape = api_copy.ModifiedShape(common_edge);
                 [ #  # ]
    3251 [ #  # ][ #  # ]:          0 :     edge = new TopoDS_Edge(TopoDS::Edge(newShape));
                 [ #  # ]
    3252                 :            : 
    3253 [ #  # ][ #  # ]:          0 :     from_faces.append(new TopoDS_Face(face));
                 [ #  # ]
    3254                 :          0 :   }
    3255         [ #  # ]:          0 :   return edge;
    3256                 :            : }
    3257                 :            : 
    3258                 :         66 : int OCCModifyEngine::check_intersection(DLIList<TopoDS_Edge*>*& edge_list,
    3259                 :            :                                         TopoDS_Face from_face)const
    3260                 :            : {
    3261                 :         66 :   int  count_intersection = 0;
    3262                 :            : 
    3263 [ +  - ][ +  + ]:        198 :   gp_Pnt newP[2] , p_test ;
                 [ +  - ]
    3264 [ +  - ][ +  + ]:        132 :   for(int kk = 0; kk < edge_list->size(); kk++)
    3265                 :            :   {
    3266         [ +  - ]:         66 :     TopoDS_Edge* edge = edge_list->get_and_step();
    3267         [ +  - ]:         66 :     BRepAdaptor_Curve acurve(*edge);
    3268         [ +  - ]:         66 :     double lower_bound = acurve.FirstParameter();
    3269         [ +  - ]:         66 :     double upper_bound = acurve.LastParameter();
    3270 [ +  - ][ +  - ]:        132 :     TopExp_Explorer Ex;
    3271 [ +  - ][ +  - ]:        308 :     for (Ex.Init(from_face, TopAbs_EDGE); Ex.More(); Ex.Next())
         [ +  - ][ +  - ]
    3272                 :            :     {
    3273 [ +  - ][ +  - ]:        242 :       TopoDS_Edge from_edge = TopoDS::Edge(Ex.Current());
                 [ +  - ]
    3274 [ +  - ][ +  - ]:        484 :       BRepAdaptor_Curve acurve2(from_edge);
                 [ +  + ]
    3275         [ +  - ]:        242 :       double lower_bound2 = acurve2.FirstParameter();
    3276         [ +  - ]:        242 :       double upper_bound2 = acurve2.LastParameter();
    3277 [ +  - ][ +  - ]:        484 :       BRepExtrema_DistShapeShape distShapeShape(*edge, from_edge);
                 [ +  + ]
    3278                 :            : 
    3279 [ +  - ][ +  - ]:        242 :       if (distShapeShape.IsDone() && distShapeShape.Value() < TOL)
         [ +  - ][ +  + ]
                 [ +  + ]
    3280                 :            :       {
    3281                 :            :         //double check that the point is on the edges.
    3282                 :            :         double newVal;
    3283 [ +  - ][ +  + ]:        264 :         for(int j =1; j <= distShapeShape.NbSolution(); j++)
    3284                 :            :         {
    3285         [ -  + ]:        132 :           if(count_intersection == 2)
    3286                 :          0 :             break;
    3287                 :            : 
    3288         [ +  - ]:        132 :           p_test = distShapeShape.PointOnShape1(j);
    3289 [ +  - ][ +  - ]:        132 :           Extrema_ExtPC ext(p_test, acurve, Precision::Approximation());
    3290                 :            :           // At this time, there must be a intersection point at least.
    3291 [ +  - ][ +  - ]:        132 :           if (ext.IsDone() && (ext.NbExt() > 0)) {
         [ +  - ][ +  - ]
                 [ +  - ]
    3292 [ +  - ][ +  + ]:        264 :             for ( int i = 1 ; i <= ext.NbExt() ; i++ ) {
    3293 [ +  - ][ +  - ]:        132 :               newVal = ext.Point(i).Parameter();
    3294 [ +  - ][ +  - ]:        132 :               if ((newVal-lower_bound) >= -TOL &&
    3295                 :        132 :                   (upper_bound - newVal) >= -TOL)
    3296                 :            :               {
    3297 [ +  - ][ +  - ]:        132 :                 Extrema_ExtPC ext(p_test, acurve2, Precision::Approximation());
    3298 [ +  - ][ +  - ]:        132 :                 if (ext.IsDone() && (ext.NbExt() > 0)) {
         [ +  - ][ +  - ]
                 [ +  - ]
    3299 [ +  - ][ +  - ]:        264 :                   for ( int k = 1 ; k <= ext.NbExt() ; k++ ) {
    3300 [ +  - ][ +  - ]:        132 :                     newVal = ext.Point(i).Parameter();
    3301 [ +  - ][ +  - ]:        132 :                     if ((newVal-lower_bound2) >= -TOL &&
    3302                 :        132 :                         (upper_bound2 - newVal) >= -TOL)
    3303                 :            :                     {
    3304                 :        132 :                       newP[count_intersection] = p_test;
    3305                 :        132 :                       count_intersection ++;
    3306                 :        132 :                       break;
    3307                 :            :                     }
    3308                 :            :                   }
    3309         [ +  - ]:        132 :                 }
    3310                 :            :               }
    3311                 :            :             }
    3312                 :            :           }
    3313         [ +  - ]:        132 :         }
    3314                 :            :       }
    3315                 :            : 
    3316         [ +  + ]:        242 :       if (count_intersection == 2)
    3317                 :            :       {
    3318                 :            :          //make sure the two intersect point are not the same one
    3319 [ +  - ][ -  + ]:         66 :          if (newP[0].IsEqual(newP[1], TOL))
    3320                 :          0 :            count_intersection--;
    3321                 :            :       }
    3322         [ +  + ]:        242 :       if (count_intersection == 2)
    3323 [ +  - ][ +  + ]:        242 :         break;
    3324                 :        176 :     } //for loop
    3325         [ +  - ]:         66 :   }
    3326                 :         66 :   return count_intersection;
    3327                 :            : }
    3328                 :            : //===============================================================================
    3329                 :            : // Function   : imprint
    3330                 :            : // Member Type: PUBLIC
    3331                 :            : // Description: imprint boolean operation on OCC-based bodies
    3332                 :            : // Author     : Jane Hu
    3333                 :            : // Date       : 04/08
    3334                 :            : //===============================================================================
    3335                 :         11 : CubitStatus     OCCModifyEngine::imprint(BodySM* BodyPtr1, BodySM* BodyPtr2,
    3336                 :            :                                          BodySM*& newBody1, BodySM*& newBody2,
    3337                 :            :                                          bool  keep_old) const
    3338                 :            : {
    3339                 :         11 :   newBody1 = NULL;
    3340                 :         11 :   newBody2 = NULL;
    3341         [ +  - ]:         11 :   DLIList<TopoDS_Shape*> shape_list;
    3342 [ +  - ][ +  - ]:         22 :   DLIList<CubitBoolean> is_volume;
    3343                 :            :   
    3344 [ +  - ][ +  - ]:         22 :   DLIList<BodySM*> bodysm_list;
    3345         [ +  - ]:         11 :   bodysm_list.append(BodyPtr1);
    3346         [ +  - ]:         11 :   bodysm_list.append(BodyPtr2);
    3347                 :            :   
    3348         [ +  - ]:         11 :   CubitStatus stat = get_shape_list(bodysm_list,shape_list,is_volume,keep_old);
    3349                 :            : 
    3350         [ -  + ]:         11 :   if(!stat)
    3351                 :          0 :     return stat;
    3352                 :            : 
    3353         [ +  - ]:         11 :   TopoDS_Shape* shape1 = shape_list.get();
    3354         [ +  - ]:         11 :   TopoDS_Shape* shape2 = shape_list.step_and_get();
    3355 [ +  - ][ +  - ]:         22 :   DLIList<TopologyBridge*> tbs;
    3356 [ +  - ][ +  - ]:         22 :   DLIList<TopoDS_Face*> face_list;
    3357         [ +  - ]:         11 :   int result = imprint_toposhapes(shape1, shape2, face_list);
    3358         [ -  + ]:         11 :   if(result == 0)
    3359                 :            :   {
    3360 [ #  # ][ #  # ]:          0 :     tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape1); 
         [ #  # ][ #  # ]
    3361 [ #  # ][ #  # ]:          0 :     newBody1 = CAST_TO(tbs.get(),BodySM);
    3362                 :            :   }
    3363                 :            : 
    3364         [ -  + ]:         11 :   else if(result == 1)
    3365                 :            :   {
    3366                 :            :     //for cylinder overlapping cases, doing boolean operation is necessary for 
    3367                 :            :     //now. 10/25/11
    3368         [ #  # ]:          0 :     BodySM* tool_copy = copy_body(BodyPtr2);
    3369                 :            : /*
    3370                 :            :     DLIList<BodySM*> tools;
    3371                 :            :     tools.append(tool_copy);
    3372                 :            :     DLIList<BodySM*> from_bodies ;
    3373                 :            :     BodySM* from_copy = copy_body(BodyPtr1);
    3374                 :            :     from_bodies.append(from_copy);
    3375                 :            :     DLIList<BodySM*> new_bodies;
    3376                 :            :     stat = subtract(tools, from_bodies, new_bodies, false, false);
    3377                 :            :     if (stat)
    3378                 :            :     {
    3379                 :            :       tool_copy = copy_body(BodyPtr2);
    3380                 :            :       from_bodies.clean_out();
    3381                 :            :       from_bodies.append(BodyPtr1);
    3382                 :            :       intersect(tool_copy, from_bodies, new_bodies, false);
    3383                 :            :       if(new_bodies.size() > 1)
    3384                 :            :       {
    3385                 :            :         DLIList<BodySM*> final_bodies;
    3386                 :            :         unite(new_bodies, final_bodies, false); 
    3387                 :            :         newBody1 = final_bodies.get();
    3388                 :            :       }
    3389                 :            :       else
    3390                 :            :         newBody1 = new_bodies.get();
    3391                 :            :     }
    3392                 :            : */
    3393         [ #  # ]:          0 :     stat = result_1_imprint(BodyPtr1, tool_copy, newBody1);
    3394         [ #  # ]:          0 :     if(stat == CUBIT_FAILURE)
    3395                 :          0 :       result = 2;
    3396                 :            :   }
    3397         [ -  + ]:         11 :   else if(result == 3)
    3398                 :            :   {
    3399         [ #  # ]:          0 :     TopoDS_Face* face = face_list.pop();
    3400 [ #  # ][ #  # ]:          0 :     int j = OCCQueryEngine::instance()->OCCMap->Find(*face);
    3401 [ #  # ][ #  # ]:          0 :     OCCSurface* cut_face = (OCCSurface*)(OCCQueryEngine::instance()->OccToCGM->find(j))->second; 
                 [ #  # ]
    3402         [ #  # ]:          0 :     OCCBody* tool_body = cut_face->my_body();
    3403         [ #  # ]:          0 :     stat = result_3_imprint(BodyPtr1,tool_body, newBody1); 
    3404         [ #  # ]:          0 :     if(stat == CUBIT_FAILURE)
    3405                 :          0 :       result = 2;
    3406                 :            :   }
    3407                 :            : 
    3408 [ +  - ][ -  + ]:         11 :   if(result && keep_old)
    3409                 :            :   {
    3410 [ #  # ][ #  # ]:          0 :     delete shape1;
                 [ #  # ]
    3411                 :          0 :     shape1 = NULL;
    3412 [ #  # ][ #  # ]:          0 :     PRINT_INFO("There's no imprint on the first body.\n");
         [ #  # ][ #  # ]
    3413                 :          0 :     newBody1 = BodyPtr1;
    3414                 :            :   }
    3415                 :            : 
    3416         [ +  - ]:         11 :   tbs.clean_out();
    3417         [ +  - ]:         11 :   result = imprint_toposhapes(shape2, shape1, face_list);
    3418         [ -  + ]:         11 :   if(result == 0)
    3419                 :            :   {
    3420 [ #  # ][ #  # ]:          0 :     tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape2);
         [ #  # ][ #  # ]
    3421 [ #  # ][ #  # ]:          0 :     newBody2 = CAST_TO(tbs.get(),BodySM);     
    3422                 :            :   }
    3423                 :            :   
    3424         [ -  + ]:         11 :   else if(result == 1)
    3425                 :            :   {
    3426                 :            :     //for cylinder overlapping cases, doing boolean operation is necessary for 
    3427                 :            :     //now. 10/25/11
    3428         [ #  # ]:          0 :     BodySM* tool_copy = copy_body(BodyPtr1);
    3429                 :            : /*
    3430                 :            :     DLIList<BodySM*> tools;
    3431                 :            :     tools.append(tool_copy);
    3432                 :            :     DLIList<BodySM*> from_bodies ;
    3433                 :            :     BodySM* from_copy = copy_body(BodyPtr2);
    3434                 :            :     from_bodies.append(from_copy);
    3435                 :            :     DLIList<BodySM*> new_bodies;
    3436                 :            :     stat = subtract(tools, from_bodies, new_bodies, false, false);
    3437                 :            :     if (stat)
    3438                 :            :     {
    3439                 :            :       tool_copy = copy_body(BodyPtr1);
    3440                 :            :       from_bodies.clean_out();
    3441                 :            :       from_bodies.append(BodyPtr2);
    3442                 :            :       intersect(tool_copy, from_bodies, new_bodies, false);
    3443                 :            :       if(new_bodies.size() > 1)
    3444                 :            :       {
    3445                 :            :         DLIList<BodySM*> final_bodies;
    3446                 :            :         unite(new_bodies, final_bodies, false);       
    3447                 :            :         newBody2 = final_bodies.get();
    3448                 :            :       }
    3449                 :            :       else
    3450                 :            :         newBody2 = new_bodies.get();
    3451                 :            :     }
    3452                 :            : */
    3453         [ #  # ]:          0 :     stat = result_1_imprint(BodyPtr2, tool_copy, newBody2);
    3454         [ #  # ]:          0 :     if(stat == CUBIT_FAILURE)
    3455                 :          0 :       result = 2; 
    3456                 :            :   }
    3457                 :            : 
    3458         [ -  + ]:         11 :   else if(result == 3)
    3459                 :            :   {
    3460         [ #  # ]:          0 :     TopoDS_Face* face = face_list.pop();
    3461 [ #  # ][ #  # ]:          0 :     int j = OCCQueryEngine::instance()->OCCMap->Find(*face);
    3462 [ #  # ][ #  # ]:          0 :     OCCSurface* cut_face = (OCCSurface*)(OCCQueryEngine::instance()->OccToCGM->find(j))->second; 
                 [ #  # ]
    3463         [ #  # ]:          0 :     OCCBody* tool_body = cut_face->my_body();
    3464         [ #  # ]:          0 :     stat = result_3_imprint(BodyPtr2,tool_body, newBody2); 
    3465         [ #  # ]:          0 :     if(stat == CUBIT_FAILURE)
    3466                 :          0 :       result = 2;
    3467                 :            :   }
    3468                 :            : 
    3469 [ +  - ][ -  + ]:         11 :   if(result && keep_old)
    3470                 :            :   {
    3471 [ #  # ][ #  # ]:          0 :     delete shape2;
                 [ #  # ]
    3472                 :          0 :     shape2 = NULL;
    3473 [ #  # ][ #  # ]:          0 :     PRINT_INFO("There's no imprint on the second body.\n");
         [ #  # ][ #  # ]
    3474                 :          0 :     newBody2 = BodyPtr2;
    3475                 :            :   }
    3476         [ +  - ]:         11 :   return CUBIT_SUCCESS;
    3477                 :            : }
    3478                 :            : 
    3479                 :            : //===============================================================================
    3480                 :            : // Function   : get_shape_list
    3481                 :            : // Member Type: PRIVATE
    3482                 :            : // Description: get the TopoDS_Shape list for imprinting use. 
    3483                 :            : // Author     : Jane Hu
    3484                 :            : // Date       : 05/08
    3485                 :            : //===============================================================================
    3486                 :        454 : CubitStatus OCCModifyEngine::get_shape_list(DLIList<BodySM*>& BodySM_list, 
    3487                 :            :                                          DLIList<TopoDS_Shape*>& shape_list,
    3488                 :            :                                          DLIList<CubitBoolean>& is_volume,
    3489                 :            :                                          bool  keep_old,
    3490                 :            :                                          DLIList<CubitBox*>* b_boxes) const
    3491                 :            : {
    3492                 :        454 :   OCCBody* occ_body = NULL;
    3493                 :        454 :   shape_list.clean_out();
    3494                 :        454 :   is_volume.clean_out();
    3495                 :        454 :   CubitStatus stat = CUBIT_SUCCESS;
    3496         [ +  + ]:       1276 :   for(int i = 0; i <BodySM_list.size(); i++)
    3497                 :            :   {
    3498 [ +  - ][ -  + ]:        822 :     occ_body = CAST_TO(BodySM_list.get_and_step(), OCCBody);
    3499         [ -  + ]:        822 :     if (!occ_body)
    3500                 :         43 :       continue;
    3501                 :            : 
    3502         [ +  + ]:        822 :     if(b_boxes)
    3503                 :            :     {
    3504 [ +  - ][ +  - ]:         97 :       CubitBox *tool_box = new CubitBox(occ_body->get_bounding_box());
    3505         [ +  - ]:         97 :       b_boxes->append(tool_box);
    3506                 :            :     }
    3507                 :            : 
    3508         [ +  - ]:        822 :     TopoDS_Compound* shape = occ_body->get_TopoDS_Shape();
    3509 [ +  + ][ +  - ]:        822 :     if( shape && !shape->IsNull())
         [ +  - ][ +  + ]
    3510                 :            :     {
    3511         [ +  - ]:         43 :       if(keep_old)
    3512                 :            :       {
    3513         [ +  - ]:         43 :         BRepBuilderAPI_Copy api_copy(*shape);
    3514 [ +  - ][ +  - ]:         86 :         TopoDS_Shape newShape = api_copy.ModifiedShape(*shape);
                 [ +  - ]
    3515 [ +  - ][ +  - ]:         43 :         TopoDS_Shape* Shape1 = new TopoDS_Shape(newShape);
    3516 [ +  - ][ +  - ]:         86 :         shape_list.append(Shape1);
    3517                 :            :       }
    3518                 :            :       else
    3519         [ #  # ]:          0 :         shape_list.append_unique(shape);
    3520         [ +  - ]:         43 :       TopExp_Explorer Ex(*shape, TopAbs_SOLID);
    3521 [ +  - ][ +  - ]:         43 :       if(Ex.More())
    3522         [ +  - ]:         43 :         is_volume.append( CUBIT_TRUE);
    3523                 :            :       else
    3524         [ #  # ]:          0 :         is_volume.append( CUBIT_FALSE);
    3525         [ +  - ]:         43 :       continue;
    3526                 :            :     }
    3527                 :            : 
    3528         [ +  - ]:        779 :     DLIList<OCCSurface*> surfaces;
    3529 [ +  - ][ +  - ]:       1558 :     DLIList<OCCShell*>   shells;
                 [ +  - ]
    3530 [ +  - ][ +  - ]:       1558 :     DLIList<OCCCurve*>   curves;    
                 [ +  - ]
    3531                 :            : 
    3532 [ +  - ][ +  - ]:        779 :     surfaces = occ_body->my_sheet_surfaces();
                 [ +  - ]
    3533 [ +  - ][ +  - ]:        779 :     shells = occ_body->shells();
                 [ +  - ]
    3534 [ +  - ][ +  - ]:        779 :     if(surfaces.size() + shells.size() > 1)
                 [ -  + ]
    3535                 :            :     {
    3536 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Can't do boolean operation on multiple-volume body.\n");
         [ #  # ][ #  # ]
    3537                 :          0 :       stat = CUBIT_FAILURE;
    3538                 :          0 :       break;
    3539                 :            :     }
    3540         [ +  - ]:        779 :     is_volume.append( CUBIT_TRUE);
    3541                 :            : 
    3542 [ +  - ][ +  + ]:        779 :     if(surfaces.size() == 1)
    3543                 :            :     {
    3544 [ +  - ][ +  - ]:         22 :       TopoDS_Face* topo_face = surfaces.get()->get_TopoDS_Face();
    3545         [ -  + ]:         22 :       if(!topo_face)
    3546                 :            :       {
    3547                 :          0 :         stat = CUBIT_FAILURE;
    3548                 :          0 :         break;
    3549                 :            :       }
    3550         [ +  - ]:         22 :       if(keep_old)
    3551                 :            :       {
    3552         [ +  - ]:         22 :         BRepBuilderAPI_Copy api_copy(*topo_face);
    3553 [ +  - ][ +  - ]:         44 :         TopoDS_Shape newShape = api_copy.ModifiedShape(*topo_face);
                 [ +  - ]
    3554 [ +  - ][ +  - ]:         22 :         TopoDS_Shape* Shape1 = new TopoDS_Shape(newShape);
    3555 [ +  - ][ +  - ]:         44 :         shape_list.append(Shape1);
    3556                 :            :       }
    3557                 :            :       else
    3558         [ #  # ]:          0 :         shape_list.append(topo_face);
    3559         [ +  - ]:         22 :       is_volume.last();
    3560         [ +  - ]:         22 :       is_volume.change_to( CUBIT_FALSE);
    3561                 :            :     }
    3562 [ +  - ][ -  + ]:        757 :     else if(shells.size() == 1)
    3563                 :            :     {
    3564 [ #  # ][ #  # ]:          0 :       TopoDS_Shell* topo_shell = shells.get()->get_TopoDS_Shell();
    3565         [ #  # ]:          0 :       if(!topo_shell)
    3566                 :            :       {
    3567                 :          0 :         stat = CUBIT_FAILURE;
    3568                 :          0 :         break;
    3569                 :            :       }
    3570         [ #  # ]:          0 :       if(keep_old)
    3571                 :            :       {
    3572         [ #  # ]:          0 :         BRepBuilderAPI_Copy api_copy(*topo_shell);
    3573 [ #  # ][ #  # ]:          0 :         TopoDS_Shape newShape = api_copy.ModifiedShape(*topo_shell);
                 [ #  # ]
    3574 [ #  # ][ #  # ]:          0 :         TopoDS_Shape* Shape1 = new TopoDS_Shape(newShape);
    3575 [ #  # ][ #  # ]:          0 :         shape_list.append(Shape1);
    3576                 :            :       }
    3577                 :            :       else
    3578         [ #  # ]:          0 :         shape_list.append(topo_shell);
    3579         [ #  # ]:          0 :       is_volume.change_to( CUBIT_FALSE);
    3580                 :            :     }
    3581                 :            : 
    3582                 :            :     else 
    3583                 :            :     {
    3584         [ +  - ]:        757 :       DLIList<Lump*> lumps = occ_body->lumps();
    3585 [ +  - ][ -  + ]:        757 :       if (lumps.size() > 1)
    3586                 :            :       {
    3587 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Can't do boolean operation on multi-volumes types. \n");
         [ #  # ][ #  # ]
    3588                 :          0 :         stat = CUBIT_FAILURE;
    3589                 :          0 :         break;
    3590                 :            :       }
    3591                 :            : 
    3592 [ +  - ][ -  + ]:        757 :       TopoDS_Solid* solid = CAST_TO(lumps.get(), OCCLump)->get_TopoDS_Solid();
                 [ +  - ]
    3593         [ -  + ]:        757 :       if(!solid)
    3594                 :            :       {
    3595                 :          0 :         stat = CUBIT_FAILURE;
    3596                 :          0 :         break;
    3597                 :            :       }
    3598         [ +  + ]:        757 :       if(keep_old)
    3599                 :            :       {
    3600         [ +  - ]:        239 :         BRepBuilderAPI_Copy api_copy(*solid);
    3601 [ +  - ][ +  - ]:        478 :         TopoDS_Shape newShape = api_copy.ModifiedShape(*solid);
                 [ +  - ]
    3602 [ +  - ][ +  - ]:        239 :         TopoDS_Shape* Shape1 = new TopoDS_Shape(newShape);
    3603 [ +  - ][ +  - ]:        478 :         shape_list.append(Shape1);
    3604                 :            :       }
    3605                 :            :       else
    3606 [ +  - ][ +  - ]:        779 :         shape_list.append(solid);
         [ +  - ][ +  - ]
                 [ +  - ]
    3607                 :            :     }
    3608                 :        779 :   }
    3609         [ -  + ]:        454 :   if(!stat)
    3610                 :            :   {   
    3611 [ #  # ][ #  # ]:          0 :     for (int i = 0; keep_old && i < shape_list.size(); i++)
                 [ #  # ]
    3612                 :            :     {
    3613                 :          0 :           TopoDS_Shape* shape = shape_list.get_and_step();
    3614         [ #  # ]:          0 :           delete shape;
    3615                 :          0 :           shape = NULL;
    3616                 :            :     }
    3617                 :          0 :     shape_list.clean_out();
    3618                 :          0 :     return CUBIT_FAILURE;
    3619                 :            :   }
    3620                 :        454 :   return CUBIT_SUCCESS;
    3621                 :            : }
    3622                 :            : //===============================================================================
    3623                 :            : // Function   : imprint multiple bodies at once
    3624                 :            : // Member Type: PUBLIC
    3625                 :            : // Description: imprint boolean operation on OCC-based bodies
    3626                 :            : // Author     : Jane HU
    3627                 :            : // Date       : 04/08
    3628                 :            : //===============================================================================
    3629                 :         31 : CubitStatus OCCModifyEngine::imprint(DLIList<BodySM*> &from_body_list ,
    3630                 :            :                                      DLIList<BodySM*> &new_from_body_list,
    3631                 :            :                                      bool keep_old,
    3632                 :            :                                      DLIList<TopologyBridge*>* new_tbs,
    3633                 :            :                                      DLIList<TopologyBridge*>* att_tbs) const
    3634                 :            : {
    3635                 :         31 :   CubitStatus success = CUBIT_SUCCESS;
    3636         [ +  - ]:         31 :   DLIList<TopoDS_Shape*> shape_list;
    3637 [ +  - ][ +  - ]:         62 :   DLIList<CubitBoolean> is_vo;
    3638                 :            : 
    3639                 :            :   //keep record of all vertices and edges and faces in the from_body_list,
    3640                 :            :   //for comparison to generated new_tbs and att_tbs.
    3641 [ +  - ][ +  - ]:         62 :   DLIList<OCCSurface*> surfaces;
    3642 [ +  - ][ +  - ]:         62 :   DLIList<OCCCurve*> curves;
    3643 [ +  - ][ +  - ]:         62 :   DLIList<OCCPoint*> points;
    3644                 :            : 
    3645         [ +  - ]:         31 :   CubitStatus stat = get_shape_list(from_body_list, shape_list, is_vo,keep_old);
    3646                 :            : 
    3647         [ -  + ]:         31 :   if(!stat)
    3648                 :          0 :     return stat;
    3649                 :            :  
    3650         [ +  - ]:         31 :   int size = shape_list.size();
    3651                 :            :   // total number of imprints to be done
    3652                 :         31 :   int total_imprints = size * (size -1);
    3653                 :            : 
    3654         [ +  + ]:         31 :   if( size > 2 )
    3655                 :            :   {
    3656                 :            :      char message[128];
    3657         [ +  - ]:         21 :      sprintf(message, "Imprinting %d OCC Bodies", from_body_list.size() ); 
    3658 [ +  - ][ +  - ]:         21 :      AppUtil::instance()->progress_tool()->start(0, total_imprints, message);
                 [ +  - ]
    3659                 :            :   }
    3660                 :            :   
    3661 [ +  - ][ +  - ]:         62 :   std::map<OCCSurface*, std::pair<CubitVector, int> > surf_property_map;
    3662 [ +  - ][ +  - ]:         62 :   std::map<OCCCurve*, std::pair<CubitVector, int> > curve_property_map;
    3663                 :            : 
    3664         [ +  + ]:        124 :   for(int i = 0; i < size; i++)
    3665                 :            :   {
    3666         [ +  - ]:         93 :     TopoDS_Shape* shape1 = shape_list[i];
    3667                 :         93 :     CubitBoolean modified = CUBIT_FALSE;
    3668                 :            : 
    3669         [ +  - ]:         93 :     DLIList<TopoDS_Face*> face_list;
    3670         [ +  + ]:        299 :     for(int j = i+1; j < size+i; j ++)
    3671                 :            :     {
    3672 [ +  - ][ +  - ]:        206 :        if (AppUtil::instance()->interrupt())
                 [ -  + ]
    3673                 :            :        {
    3674                 :          0 :           success = CUBIT_FAILURE;
    3675                 :          0 :           break;
    3676                 :            :        }
    3677                 :            : 
    3678         [ +  - ]:        206 :        TopoDS_Shape* shape2 = shape_list[j%size];
    3679         [ +  - ]:        206 :        DLIList<TopologyBridge*> tbs;
    3680         [ +  - ]:        206 :        int result = imprint_toposhapes(shape1, shape2, face_list);
    3681         [ +  + ]:        206 :        if(result == 0)
    3682                 :            :        {
    3683         [ +  - ]:         33 :           DLIList<TopologyBridge*> tbs;
    3684 [ +  - ][ +  - ]:         33 :           tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape1);
         [ +  - ][ +  - ]
    3685 [ +  - ][ +  - ]:         33 :           from_body_list[i] = CAST_TO(tbs.get(),BodySM);
                 [ -  + ]
    3686         [ +  - ]:         33 :           modified = CUBIT_TRUE;
    3687                 :            :        }
    3688         [ -  + ]:        173 :        else if(result == 1)
    3689                 :            :        {
    3690                 :            :          //for cylinder overlapping cases, doing boolean operation is necessary for 
    3691                 :            :          //now. 10/25/11
    3692 [ #  # ][ #  # ]:          0 :          BodySM* tool_copy = copy_body(from_body_list[j%size]);
    3693                 :          0 :          BodySM* newBody = NULL;
    3694                 :            : 
    3695 [ #  # ][ #  # ]:          0 :          stat = result_1_imprint(from_body_list[i], tool_copy, newBody);
    3696 [ #  # ][ #  # ]:          0 :          if (stat && newBody)
    3697                 :            :          {
    3698                 :          0 :            modified = CUBIT_TRUE;
    3699         [ #  # ]:          0 :            DLIList<TopoDS_Shape*> shapes;
    3700 [ #  # ][ #  # ]:          0 :            DLIList<CubitBoolean> is_volume;
    3701 [ #  # ][ #  # ]:          0 :            DLIList<BodySM*> new_bodies;
    3702         [ #  # ]:          0 :            new_bodies.append(newBody);
    3703         [ #  # ]:          0 :            get_shape_list(new_bodies, shapes, is_volume,false);
    3704         [ #  # ]:          0 :            shape1 = shapes.get();
    3705                 :            :            //shape_list[i] = shape1;
    3706 [ #  # ][ #  # ]:          0 :            from_body_list[i] = newBody;
    3707                 :            :          }
    3708                 :            :        }
    3709         [ -  + ]:        173 :        else if(result == 3)
    3710                 :            :        {
    3711                 :          0 :          BodySM* newBody = NULL;
    3712         [ #  # ]:          0 :          BodySM* oldBody = from_body_list[i];
    3713         [ #  # ]:          0 :          TopExp_Explorer Ex;
    3714         [ #  # ]:          0 :          Ex.Init(*shape1, TopAbs_SOLID);
    3715                 :          0 :          int nSolid = 0;
    3716 [ #  # ][ #  # ]:          0 :          for(; Ex.More(); Ex.Next())
                 [ #  # ]
    3717                 :          0 :            nSolid++;
    3718         [ #  # ]:          0 :          do
    3719                 :            :          { 
    3720         [ #  # ]:          0 :            TopoDS_Face* face = face_list.pop();
    3721 [ #  # ][ #  # ]:          0 :            int k = OCCQueryEngine::instance()->OCCMap->Find(*face);
    3722 [ #  # ][ #  # ]:          0 :            OCCSurface* cut_face = (OCCSurface*)(OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ #  # ]
    3723         [ #  # ]:          0 :            OCCBody* tool_body = cut_face->my_body();
    3724                 :            : 
    3725         [ #  # ]:          0 :            stat = result_3_imprint(oldBody, tool_body, newBody);
    3726         [ #  # ]:          0 :            if (newBody)
    3727                 :            :            {
    3728                 :          0 :              modified = CUBIT_TRUE;
    3729         [ #  # ]:          0 :              DLIList<TopoDS_Shape*> shapes;
    3730 [ #  # ][ #  # ]:          0 :              DLIList<CubitBoolean> is_volume;
    3731 [ #  # ][ #  # ]:          0 :              DLIList<BodySM*> new_bodies;
    3732         [ #  # ]:          0 :              new_bodies.append(newBody);
    3733         [ #  # ]:          0 :              get_shape_list(new_bodies, shapes, is_volume,false);
    3734         [ #  # ]:          0 :              shape1 = shapes.get();
    3735                 :            :              //shape_list[i] = shape1;
    3736 [ #  # ][ #  # ]:          0 :              from_body_list[i] = newBody;
    3737                 :            :            }
    3738         [ #  # ]:          0 :            if(nSolid == 1)
    3739                 :          0 :              break;
    3740                 :            :            else
    3741                 :          0 :              nSolid --;
    3742         [ #  # ]:          0 :            result = imprint_toposhapes(shape1, shape2, face_list); 
    3743                 :          0 :            oldBody = newBody;
    3744         [ #  # ]:          0 :          }while (result == 3);
    3745                 :            :        }
    3746         [ +  - ]:        206 :     }
    3747         [ +  + ]:         93 :     if(modified)
    3748 [ +  - ][ +  - ]:         22 :       new_from_body_list.append(from_body_list[i]);
    3749                 :            :     
    3750         [ +  - ]:         93 :     shape_list.reset();
    3751         [ +  + ]:         93 :     if( size > 2 )
    3752 [ +  - ][ +  - ]:         73 :       AppUtil::instance()->progress_tool()->step();
                 [ +  - ]
    3753         [ +  - ]:         93 :   }
    3754                 :            : 
    3755         [ +  + ]:         31 :   if( size > 2 )
    3756 [ +  - ][ +  - ]:         21 :     AppUtil::instance()->progress_tool()->end();
                 [ +  - ]
    3757                 :            : 
    3758 [ +  - ][ +  - ]:         31 :   if( AppUtil::instance()->interrupt() )
                 [ -  + ]
    3759 [ #  # ][ #  # ]:          0 :         PRINT_INFO("Imprint aborted.\n");
         [ #  # ][ #  # ]
    3760                 :            : 
    3761         [ +  - ]:         31 :   return success;
    3762                 :            : }
    3763                 :            : 
    3764                 :          0 : CubitStatus OCCModifyEngine::result_3_imprint(BodySM* from_body, 
    3765                 :            :                                               BodySM* tool_body, 
    3766                 :            :                                               BodySM*& newBody)const
    3767                 :            : {
    3768         [ #  # ]:          0 :   DLIList<BodySM*> from_bodies;
    3769         [ #  # ]:          0 :   from_bodies.append(from_body); 
    3770 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> results_list;
    3771 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> neighbor_imprint_list;
    3772                 :            :   CubitStatus stat = webcut(from_bodies, tool_body, neighbor_imprint_list, 
    3773         [ #  # ]:          0 :                             results_list);
    3774 [ #  # ][ #  # ]:          0 :   if(results_list.size() > 1)
    3775                 :            :   {
    3776         [ #  # ]:          0 :     DLIList<BodySM*> bodies;
    3777         [ #  # ]:          0 :     unite(results_list, bodies, false); 
    3778 [ #  # ][ #  # ]:          0 :     newBody = bodies.get();
    3779                 :            :   }
    3780 [ #  # ][ #  # ]:          0 :   else if (results_list.size() == 1)
    3781         [ #  # ]:          0 :     newBody = results_list.get();
    3782                 :            :  
    3783         [ #  # ]:          0 :   return stat;
    3784                 :            : 
    3785                 :            : }
    3786                 :            : 
    3787                 :          0 : CubitStatus OCCModifyEngine::result_1_imprint(BodySM* from_body,  
    3788                 :            :                                               BodySM* tool_body,
    3789                 :            :                                               BodySM*& newBody)const
    3790                 :            : {
    3791                 :            :   //for compound of solids in from_body, try to determine if subtracting or
    3792                 :            :   //intersecting will keep the from_body un-deleted by checking subtracting
    3793                 :            :   //first, if it kept the from_body, don't take any further risk, do intersect
    3794                 :            :   //first, then subtract.
    3795                 :            : 
    3796         [ #  # ]:          0 :   DLIList<TopoDS_Shape*> from_bodies_shapes;
    3797 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> from_bodies ;
    3798 [ #  # ][ #  # ]:          0 :   DLIList<CubitBoolean> is_volume;
    3799         [ #  # ]:          0 :   from_bodies.append(from_body);
    3800                 :            :   //get the from_bodies underling shapes
    3801         [ #  # ]:          0 :   CubitStatus stat = get_shape_list(from_bodies, from_bodies_shapes, is_volume, CUBIT_FALSE);
    3802                 :            : 
    3803         [ #  # ]:          0 :   TopoDS_Shape* from_shape = from_bodies_shapes.get();
    3804                 :          0 :   int num_solids = 0;
    3805 [ #  # ][ #  # ]:          0 :   if(from_shape->ShapeType() == TopAbs_COMPOUND)
    3806                 :            :   {
    3807         [ #  # ]:          0 :     TopExp_Explorer Ex;
    3808 [ #  # ][ #  # ]:          0 :     for (Ex.Init(*from_shape, TopAbs_SOLID);Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    3809         [ #  # ]:          0 :       num_solids++;
    3810                 :            :   }
    3811         [ #  # ]:          0 :   BodySM* tool_copy = copy_body(tool_body);
    3812 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> tools;
    3813         [ #  # ]:          0 :   tools.append(tool_copy);
    3814         [ #  # ]:          0 :   from_bodies.clean_out() ;
    3815         [ #  # ]:          0 :   BodySM* from_copy = copy_body(from_body);
    3816         [ #  # ]:          0 :   from_bodies.append(from_copy);
    3817 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> new_bodies;
    3818         [ #  # ]:          0 :   stat = subtract(tools, from_bodies, new_bodies, false, false);
    3819         [ #  # ]:          0 :   if (stat)
    3820                 :            :   {
    3821 [ #  # ][ #  # ]:          0 :     if (num_solids > 1 && from_copy == new_bodies.get())
         [ #  # ][ #  # ]
    3822                 :            :     {
    3823                 :            :       //double check if subtract kept the original from_bodies pointer.
    3824                 :            :       //if so, do intersect first, then subtract.
    3825         [ #  # ]:          0 :       tool_copy = copy_body(tool_body);
    3826         [ #  # ]:          0 :       from_bodies.clean_out(); 
    3827         [ #  # ]:          0 :       from_copy = copy_body(from_body);
    3828         [ #  # ]:          0 :       from_bodies.append(from_copy);
    3829 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->delete_solid_model_entities(new_bodies);
    3830         [ #  # ]:          0 :       new_bodies.clean_out();
    3831         [ #  # ]:          0 :       intersect(tool_copy, from_bodies, new_bodies, false);
    3832                 :            : 
    3833         [ #  # ]:          0 :       tool_copy = copy_body(tool_body);
    3834         [ #  # ]:          0 :       tools.clean_out();
    3835         [ #  # ]:          0 :       tools.append(tool_copy);
    3836         [ #  # ]:          0 :       from_bodies.clean_out();
    3837         [ #  # ]:          0 :       from_bodies.append(from_body);
    3838         [ #  # ]:          0 :       subtract(tools, from_bodies, new_bodies, false, false);
    3839                 :            :     }
    3840                 :            :     else
    3841                 :            :     { 
    3842         [ #  # ]:          0 :       tool_copy = copy_body(tool_body);
    3843         [ #  # ]:          0 :       from_bodies.clean_out();
    3844         [ #  # ]:          0 :       from_bodies.append(from_body);
    3845         [ #  # ]:          0 :       intersect(tool_copy, from_bodies, new_bodies, false);
    3846                 :            :     }
    3847                 :            :     
    3848                 :            :     //make sure the first body in new_bodies is the one we want to keep.
    3849         [ #  # ]:          0 :     new_bodies.reverse();
    3850 [ #  # ][ #  # ]:          0 :     if(new_bodies.size() > 1)
    3851                 :            :     {
    3852         [ #  # ]:          0 :        DLIList<BodySM*> final_bodies;
    3853         [ #  # ]:          0 :        unite(new_bodies, final_bodies, false);
    3854         [ #  # ]:          0 :        new_bodies.clean_out();
    3855 [ #  # ][ #  # ]:          0 :        new_bodies = final_bodies;
    3856                 :            :     }
    3857         [ #  # ]:          0 :     newBody = new_bodies.get();
    3858                 :            :   }
    3859         [ #  # ]:          0 :   return stat;
    3860                 :            : } 
    3861                 :            : 
    3862                 :            : //===============================================================================
    3863                 :            : // Function   : imprint
    3864                 :            : // Member Type: PUBLIC
    3865                 :            : // Description: imprint curves onto body_list
    3866                 :            : // Author     : Jane Hu
    3867                 :            : // Date       : 05/08
    3868                 :            : //===============================================================================
    3869                 :          0 : CubitStatus     OCCModifyEngine::imprint( DLIList<BodySM*> &body_list,
    3870                 :            :                                            DLIList<Curve*> &ref_edge_list,
    3871                 :            :                                            DLIList<BodySM*>& new_body_list,
    3872                 :            :                                            DLIList<TopologyBridge*> &temp_bridges,
    3873                 :            :                                            bool keep_old,
    3874                 :            :                                            bool show_messages) const
    3875                 :            : {
    3876                 :          0 :   CubitStatus success = CUBIT_SUCCESS;
    3877 [ #  # ][ #  # ]:          0 :   DLIList<TopoDS_Shape*> shape_list, tool_shapes;
                 [ #  # ]
    3878 [ #  # ][ #  # ]:          0 :   DLIList<CubitBoolean> is_vo;
    3879         [ #  # ]:          0 :   CubitStatus stat = get_shape_list(body_list, shape_list, is_vo, keep_old);
    3880         [ #  # ]:          0 :   if (!stat)
    3881                 :          0 :     return stat;
    3882                 :            : 
    3883         [ #  # ]:          0 :   int size = ref_edge_list.size();
    3884                 :            :   // total number of imprints to be done
    3885                 :            : 
    3886 [ #  # ][ #  # ]:          0 :   if( size > 2 && show_messages)
    3887                 :            :   {
    3888                 :            :      char message[128];
    3889         [ #  # ]:          0 :      sprintf(message, "Imprinting %d OCC Bodies", body_list.size() );
    3890 [ #  # ][ #  # ]:          0 :      AppUtil::instance()->progress_tool()->start(0, size, message);
                 [ #  # ]
    3891                 :            :   }
    3892 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < ref_edge_list.size(); i++)
    3893                 :            :   {
    3894 [ #  # ][ #  # ]:          0 :     OCCCurve* curve = CAST_TO(ref_edge_list.get_and_step(), OCCCurve) ;
    3895         [ #  # ]:          0 :     if (!curve)
    3896                 :          0 :       continue;
    3897                 :            : 
    3898         [ #  # ]:          0 :     TopoDS_Edge* edge = curve->get_TopoDS_Edge();
    3899 [ #  # ][ #  # ]:          0 :     if (edge->IsNull())
    3900                 :          0 :       continue;
    3901                 :            :     
    3902 [ #  # ][ #  # ]:          0 :     if (AppUtil::instance()->interrupt())
                 [ #  # ]
    3903                 :            :     {
    3904                 :          0 :        success = CUBIT_FAILURE;
    3905                 :          0 :        break;
    3906                 :            :     }
    3907         [ #  # ]:          0 :     DLIList<TopoDS_Face*> face_list;
    3908 [ #  # ][ #  # ]:          0 :     for(int j = 0; j < shape_list.size(); j ++)
    3909                 :            :     {
    3910         [ #  # ]:          0 :       TopoDS_Shape* shape = shape_list.get();
    3911                 :            :         
    3912         [ #  # ]:          0 :       int result = imprint_toposhapes(shape, (TopoDS_Shape*)edge, face_list);
    3913         [ #  # ]:          0 :       if (result == 0)
    3914         [ #  # ]:          0 :         shape_list.change_to(shape);
    3915         [ #  # ]:          0 :       shape_list.step();
    3916         [ #  # ]:          0 :       body_list.step();
    3917                 :            :     }
    3918                 :            : 
    3919         [ #  # ]:          0 :     if( size > 2 )
    3920 [ #  # ][ #  # ]:          0 :       AppUtil::instance()->progress_tool()->step();
                 [ #  # ]
    3921         [ #  # ]:          0 :   }   
    3922                 :            : 
    3923 [ #  # ][ #  # ]:          0 :   for(int j = 0; j < shape_list.size(); j ++)
    3924                 :            :   {
    3925         [ #  # ]:          0 :     DLIList<TopologyBridge*> tbs;
    3926         [ #  # ]:          0 :     TopoDS_Shape* shape = shape_list.get_and_step();
    3927 [ #  # ][ #  # ]:          0 :     tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape);
         [ #  # ][ #  # ]
    3928 [ #  # ][ #  # ]:          0 :     new_body_list.append(CAST_TO(tbs.get(),BodySM));
                 [ #  # ]
    3929         [ #  # ]:          0 :   }
    3930                 :            : 
    3931         [ #  # ]:          0 :   if( size > 2 )
    3932 [ #  # ][ #  # ]:          0 :     AppUtil::instance()->progress_tool()->end();
                 [ #  # ]
    3933                 :            : 
    3934 [ #  # ][ #  # ]:          0 :   if( AppUtil::instance()->interrupt() )
                 [ #  # ]
    3935 [ #  # ][ #  # ]:          0 :         PRINT_INFO("Imprint aborted.\n"); 
         [ #  # ][ #  # ]
    3936         [ #  # ]:          0 :   return success;
    3937                 :            : }
    3938                 :            : 
    3939                 :            : //===============================================================================
    3940                 :            : // Function   : imprint
    3941                 :            : // Member Type: PUBLIC
    3942                 :            : // Description: to be consistante with  imprint.
    3943                 :            : //              The surfaces must be part of a body, but the curves 
    3944                 :            : //              just have to be valid OCC edge.
    3945                 :            : // Author     : Jane Hu
    3946                 :            : // Date       : 05/08
    3947                 :            : //===============================================================================
    3948                 :          0 : CubitStatus OCCModifyEngine::imprint( DLIList<Surface*> &ref_face_list,
    3949                 :            :                                       DLIList<Curve*> &edge_list,
    3950                 :            :                                       DLIList<TopologyBridge*> &temp_bridges,
    3951                 :            :                                       DLIList<BodySM*>& new_body_list,
    3952                 :            :                                       bool keep_old) const
    3953                 :            : {
    3954         [ #  # ]:          0 :   DLIList<TopoDS_Face*> face_list;
    3955 [ #  # ][ #  # ]:          0 :   DLIList<TopoDS_Shape*> shape_list;
    3956                 :            :  
    3957         [ #  # ]:          0 :   face_edge_imprint(ref_face_list, edge_list, face_list, shape_list, keep_old);
    3958                 :            : 
    3959 [ #  # ][ #  # ]:          0 :   TopExp_Explorer Ex;
    3960                 :          0 :   int num_face = 0;
    3961         [ #  # ]:          0 :   TopoDS_Shape* shape = shape_list.get_and_step();
    3962 [ #  # ][ #  # ]:          0 :   for (Ex.Init(*shape, TopAbs_FACE); Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    3963                 :            :     { 
    3964 [ #  # ][ #  # ]:          0 :       TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    3965                 :          0 :       num_face++;
    3966         [ #  # ]:          0 :     }
    3967                 :            : 
    3968 [ #  # ][ #  # ]:          0 :   for(int j = 0; j < shape_list.size(); j ++)
    3969                 :            :   {
    3970         [ #  # ]:          0 :     DLIList<TopologyBridge*> tbs;
    3971         [ #  # ]:          0 :     TopoDS_Shape* shape = shape_list.get_and_step();
    3972 [ #  # ][ #  # ]:          0 :     if (!shape || shape->IsNull())
         [ #  # ][ #  # ]
    3973                 :          0 :       continue;
    3974 [ #  # ][ #  # ]:          0 :     if (shape->ShapeType() == TopAbs_COMPOUND)
    3975                 :            :     {
    3976 [ #  # ][ #  # ]:          0 :       if(!OCCQueryEngine::instance()->OCCMap->IsBound(*shape)) 
                 [ #  # ]
    3977                 :            :       {
    3978         [ #  # ]:          0 :         TopExp_Explorer Ex;
    3979 [ #  # ][ #  # ]:          0 :         for (Ex.Init(*shape, TopAbs_SOLID);Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    3980                 :            :         {
    3981 [ #  # ][ #  # ]:          0 :           TopoDS_Shape subshape = Ex.Current();
    3982 [ #  # ][ #  # ]:          0 :           tbs += OCCQueryEngine::instance()->populate_topology_bridge(subshape);
         [ #  # ][ #  # ]
    3983 [ #  # ][ #  # ]:          0 :           new_body_list.append_unique(CAST_TO(tbs.get(),BodySM));
                 [ #  # ]
    3984 [ #  # ][ #  # ]:          0 :         }
    3985                 :            :       }
    3986                 :            :     }
    3987                 :            :     else
    3988                 :            :     {
    3989 [ #  # ][ #  # ]:          0 :       tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape);
         [ #  # ][ #  # ]
    3990 [ #  # ][ #  # ]:          0 :       new_body_list.append_unique(CAST_TO(tbs.get(),BodySM));
         [ #  # ][ #  # ]
                 [ #  # ]
    3991                 :            :     }
    3992                 :          0 :   }
    3993                 :            : 
    3994                 :            : /*
    3995                 :            :   if (keep_old)
    3996                 :            :   {
    3997                 :            :     for(int i = 0; i < face_list.size(); i++)
    3998                 :            :     {
    3999                 :            :       TopoDS_Face* face = face_list.get();
    4000                 :            :       face->Nullify();
    4001                 :            :       delete face;
    4002                 :            :       face =NULL;
    4003                 :            :     }
    4004                 :            :   }
    4005                 :            : */
    4006         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    4007                 :            : }
    4008                 :            : 
    4009                 :            : //===============================================================================
    4010                 :            : // Function   : face_edge_imprint
    4011                 :            : // Member Type: PRIVATE
    4012                 :            : // Description: to be consistante with  imprint.
    4013                 :            : //              The surfaces must be part of a body, but the curves
    4014                 :            : //              just have to be valid OCC edge.
    4015                 :            : // Author     : Jane Hu
    4016                 :            : // Date       : 05/08
    4017                 :            : //===============================================================================
    4018                 :            : CubitStatus 
    4019                 :          0 : OCCModifyEngine::face_edge_imprint( DLIList<Surface*> &ref_face_list,
    4020                 :            :                                     DLIList<Curve*> &edge_list,
    4021                 :            :                                     DLIList<TopoDS_Face*>& face_list,
    4022                 :            :                                     DLIList<TopoDS_Shape*>& shape_list,
    4023                 :            :                                     bool keep_old ) const
    4024                 :            : {
    4025 [ #  # ][ #  # ]:          0 :   for(int i = 0; i <ref_face_list.size(); i++)
    4026                 :            :   {
    4027 [ #  # ][ #  # ]:          0 :     OCCSurface* surface = CAST_TO(ref_face_list.get_and_step(), OCCSurface);
    4028         [ #  # ]:          0 :     if(!surface)
    4029                 :          0 :       continue;
    4030                 :            : 
    4031         [ #  # ]:          0 :     TopoDS_Face* topo_face = surface->get_TopoDS_Face();
    4032         [ #  # ]:          0 :     face_list.append(topo_face);
    4033                 :            : 
    4034                 :          0 :     OCCBody* occ_body = NULL;
    4035         [ #  # ]:          0 :     OCCShell* shell = surface->my_shell();
    4036 [ #  # ][ #  # ]:          0 :     if(shell && shell->my_body())
         [ #  # ][ #  # ]
    4037         [ #  # ]:          0 :       occ_body = shell->my_body();
    4038                 :            :     else
    4039                 :            :     {
    4040         [ #  # ]:          0 :       DLIList<OCCBody*> bodies;
    4041         [ #  # ]:          0 :       surface->get_bodies(bodies);
    4042 [ #  # ][ #  # ]:          0 :       if(bodies.size() != 1)
    4043                 :            :       {
    4044 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Can't find the corresponding manifold solid body.\n");
         [ #  # ][ #  # ]
    4045                 :          0 :         return CUBIT_FAILURE;
    4046                 :            :       }
    4047 [ #  # ][ #  # ]:          0 :       occ_body = bodies.get();
                 [ #  # ]
    4048                 :            :     }
    4049                 :            :     TopoDS_Shape *shape ; 
    4050         [ #  # ]:          0 :     occ_body->get_TopoDS_Shape(shape);
    4051                 :            : 
    4052 [ #  # ][ #  # ]:          0 :     if(shape && !shape->IsNull())
         [ #  # ][ #  # ]
    4053         [ #  # ]:          0 :       shape_list.append_unique(shape);
    4054                 :            :   }
    4055                 :            : 
    4056         [ #  # ]:          0 :   if(keep_old)
    4057                 :            :   {
    4058 [ #  # ][ #  # ]:          0 :     for(int i = 0; i < shape_list.size(); i++)
    4059                 :            :     {
    4060         [ #  # ]:          0 :       TopoDS_Shape* shape = shape_list.get();
    4061         [ #  # ]:          0 :       BRepBuilderAPI_Copy api_copy(*shape);
    4062 [ #  # ][ #  # ]:          0 :       TopoDS_Shape newShape = api_copy.ModifiedShape(*shape);
                 [ #  # ]
    4063 [ #  # ][ #  # ]:          0 :       TopoDS_Shape* Shape1 = new TopoDS_Shape(newShape);
    4064 [ #  # ][ #  # ]:          0 :       for(int j = 0; j < face_list.size(); j++)
    4065                 :            :       {
    4066         [ #  # ]:          0 :         TopoDS_Face* face = face_list.get();
    4067 [ #  # ][ #  # ]:          0 :         TopExp_Explorer Ex, Ex_new;
                 [ #  # ]
    4068 [ #  # ][ #  # ]:          0 :         for (Ex.Init(*shape, TopAbs_FACE); Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    4069                 :            :         {
    4070 [ #  # ][ #  # ]:          0 :           if(face->IsSame(Ex.Current()))
                 [ #  # ]
    4071                 :            :           {
    4072 [ #  # ][ #  # ]:          0 :             face = new TopoDS_Face(TopoDS::Face(api_copy.ModifiedShape(*face)));
         [ #  # ][ #  # ]
    4073         [ #  # ]:          0 :             face_list.change_to(face);
    4074                 :            :           }
    4075                 :            :         }
    4076         [ #  # ]:          0 :         face_list.step();
    4077         [ #  # ]:          0 :       }
    4078         [ #  # ]:          0 :       shape_list.change_to(Shape1);
    4079         [ #  # ]:          0 :       shape_list.step();
    4080         [ #  # ]:          0 :     }
    4081                 :            :   }
    4082                 :            : 
    4083 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < edge_list.size(); i++)
    4084                 :            :   {
    4085 [ #  # ][ #  # ]:          0 :     OCCCurve* curve = CAST_TO(edge_list.get_and_step(), OCCCurve) ;
    4086         [ #  # ]:          0 :     if (!curve)
    4087                 :          0 :       continue;
    4088                 :            : 
    4089         [ #  # ]:          0 :     TopoDS_Edge* edge = curve->get_TopoDS_Edge();
    4090 [ #  # ][ #  # ]:          0 :     if (edge->IsNull())
    4091                 :          0 :       continue;
    4092                 :            : 
    4093 [ #  # ][ #  # ]:          0 :     for(int j = 0; j < shape_list.size(); j ++)
    4094                 :            :     {
    4095         [ #  # ]:          0 :       TopoDS_Shape* shape = shape_list.get_and_step();
    4096         [ #  # ]:          0 :       DLIList<TopoDS_Face*> record_faces;
    4097 [ #  # ][ #  # ]:          0 :       for (int e = 0; e < face_list.size(); e++)
    4098 [ #  # ][ #  # ]:          0 :         record_faces.append(face_list.get_and_step()); 
    4099                 :            : 
    4100         [ #  # ]:          0 :       imprint_toposhapes(shape, (TopoDS_Shape*)edge, face_list);
    4101 [ #  # ][ #  # ]:          0 :       for (int e = 0; e < record_faces.size()&& keep_old; e++)  
         [ #  # ][ #  # ]
    4102                 :            :       {
    4103         [ #  # ]:          0 :         TopoDS_Face* test_face = record_faces.get_and_step();
    4104 [ #  # ][ #  # ]:          0 :         if(!face_list.move_to(test_face))
    4105                 :            :         {
    4106         [ #  # ]:          0 :           test_face->Nullify();
    4107 [ #  # ][ #  # ]:          0 :           delete test_face;
                 [ #  # ]
    4108                 :            :         }
    4109                 :            :       }
    4110         [ #  # ]:          0 :     }
    4111                 :            :   }
    4112                 :            : 
    4113 [ #  # ][ #  # ]:          0 :   for(int j = 0; keep_old && j < face_list.size(); j++)
         [ #  # ][ #  # ]
    4114                 :            :   {
    4115         [ #  # ]:          0 :     TopoDS_Face* face = face_list.get_and_step(); 
    4116         [ #  # ]:          0 :     face->Nullify();
    4117 [ #  # ][ #  # ]:          0 :     delete face;
                 [ #  # ]
    4118                 :            :   }
    4119                 :            : 
    4120         [ #  # ]:          0 :   TopExp_Explorer Ex;
    4121                 :          0 :   int num_face = 0;
    4122         [ #  # ]:          0 :   TopoDS_Shape* shape = shape_list.get_and_step();
    4123 [ #  # ][ #  # ]:          0 :   for (Ex.Init(*shape, TopAbs_FACE); Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    4124                 :            :     {
    4125 [ #  # ][ #  # ]:          0 :       TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    4126                 :          0 :       num_face++;
    4127         [ #  # ]:          0 :     }
    4128                 :            : 
    4129         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    4130                 :            : }
    4131                 :            : //===============================================================================
    4132                 :            : // Function   : imprint
    4133                 :            : // Member Type: PUBLIC
    4134                 :            : // Description: To be consistent with  ModifyEngine, althought it's hard
    4135                 :            : //              to have a GUI interface for users to input. All surface must
    4136                 :            : //              on the same body. 
    4137                 :            : // Author     : Jane HU 
    4138                 :            : // Date       : 06/08
    4139                 :            : //===============================================================================
    4140                 :          0 : CubitStatus OCCModifyEngine::imprint( DLIList<Surface*>& surface_list,
    4141                 :            :                                    DLIList<DLIList<Curve*>*>& curve_lists_list,
    4142                 :            :                                    BodySM*& new_body,
    4143                 :            :                                    bool keep_old,
    4144                 :            :                                    bool expand,
    4145                 :            :                                    DLIList<TopologyBridge*> *new_tbs,
    4146                 :            :                                    DLIList<TopologyBridge*> *att_tbs  ) const
    4147                 :            : {
    4148         [ #  # ]:          0 :   DLIList<TopoDS_Face*> face_list;
    4149 [ #  # ][ #  # ]:          0 :   DLIList<TopoDS_Shape*> shape_list;
    4150 [ #  # ][ #  # ]:          0 :   DLIList<TopoDS_Shape*> shape_list_all;
    4151 [ #  # ][ #  # ]:          0 :   DLIList<OCCSurface*> surfaces;
    4152 [ #  # ][ #  # ]:          0 :   DLIList<OCCCurve*> curves;
    4153 [ #  # ][ #  # ]:          0 :   DLIList<OCCPoint*> points;
    4154                 :            :  
    4155 [ #  # ][ #  # ]:          0 :   assert (surface_list.size() == curve_lists_list.size());
                 [ #  # ]
    4156 [ #  # ][ #  # ]:          0 :   DLIList<OCCBody*> bodies;
    4157                 :            : 
    4158 [ #  # ][ #  # ]:          0 :   std::map<OCCSurface*, std::pair<CubitVector, double> > surf_property_map;
    4159 [ #  # ][ #  # ]:          0 :   std::map<OCCCurve*, std::pair<CubitVector, double> > curve_property_map;
    4160                 :            : 
    4161 [ #  # ][ #  # ]:          0 :   for(int j = 0; j < surface_list.size(); j++)
    4162                 :            :   {
    4163         [ #  # ]:          0 :     Surface* surface = surface_list.get_and_step();
    4164                 :            :     
    4165                 :            :     //keep record of old bodies, surfaces, curves and points
    4166         [ #  # ]:          0 :     OCCSurface* occ_surface = CAST_TO(surface, OCCSurface);
    4167         [ #  # ]:          0 :     occ_surface->get_bodies(bodies);
    4168         [ #  # ]:          0 :     if(j == 0)
    4169                 :            :     {
    4170 [ #  # ][ #  # ]:          0 :       bodies.get()->get_all_surfaces(surfaces);
    4171 [ #  # ][ #  # ]:          0 :       bodies.get()->get_all_curves(curves);
    4172 [ #  # ][ #  # ]:          0 :       bodies.get()->get_all_points(points);
    4173                 :            :  
    4174                 :            :       //save surface with its area and center info in the map
    4175 [ #  # ][ #  # ]:          0 :       for(int i = 0; i < surfaces.size(); i++)
    4176                 :            :       {
    4177         [ #  # ]:          0 :         OCCSurface* surf = CAST_TO(surfaces.get(), OCCSurface);
    4178         [ #  # ]:          0 :         double d = surf->measure();
    4179         [ #  # ]:          0 :         CubitVector center = surf->center_point();
    4180                 :            :         surf_property_map.insert(valType
    4181 [ #  # ][ #  # ]:          0 :              (surf, std::pair<CubitVector, double>(center,d)));
         [ #  # ][ #  # ]
                 [ #  # ]
    4182                 :            :       }
    4183                 :            : 
    4184                 :            :       //save curve with its length and center info in the map
    4185 [ #  # ][ #  # ]:          0 :       for(int i = 0; i < curves.size(); i++)
    4186                 :            :       {
    4187         [ #  # ]:          0 :         OCCCurve* curve = CAST_TO(curves.get(), OCCCurve);
    4188         [ #  # ]:          0 :         double d = curve->measure();
    4189         [ #  # ]:          0 :         CubitVector center = curve->center_point();
    4190                 :            :         curve_property_map.insert(valType2
    4191 [ #  # ][ #  # ]:          0 :              (curve, std::pair<CubitVector, double>(center,d)));
         [ #  # ][ #  # ]
                 [ #  # ]
    4192                 :            :       }
    4193                 :            :     }
    4194         [ #  # ]:          0 :     DLIList<Surface*> ref_face_list;
    4195         [ #  # ]:          0 :     ref_face_list.append(surface);
    4196         [ #  # ]:          0 :     DLIList<Curve*> *edge_list = curve_lists_list.get_and_step();
    4197         [ #  # ]:          0 :     face_edge_imprint(ref_face_list, *edge_list, face_list, shape_list, keep_old);
    4198                 :            : 
    4199 [ #  # ][ #  # ]:          0 :     for(int i = 0; i < shape_list.size(); i++)
    4200                 :            :     {
    4201         [ #  # ]:          0 :       TopoDS_Shape* shape = shape_list.get_and_step();
    4202         [ #  # ]:          0 :       shape_list_all.append_unique(shape);
    4203                 :            :     }
    4204         [ #  # ]:          0 :     shape_list.clean_out();
    4205                 :            : 
    4206         [ #  # ]:          0 :     if (keep_old)
    4207                 :            :     {
    4208 [ #  # ][ #  # ]:          0 :       for(int i = 0; i < face_list.size(); i++)
    4209                 :            :       {
    4210         [ #  # ]:          0 :         TopoDS_Face* face = face_list.get();
    4211         [ #  # ]:          0 :         face->Nullify();
    4212 [ #  # ][ #  # ]:          0 :         delete face;
                 [ #  # ]
    4213                 :          0 :         face = NULL;
    4214                 :            :       }
    4215                 :            :     }
    4216                 :            : 
    4217         [ #  # ]:          0 :     face_list.clean_out();
    4218         [ #  # ]:          0 :   }
    4219                 :            : 
    4220 [ #  # ][ #  # ]:          0 :   assert (bodies.size() == 1);
    4221                 :            : 
    4222 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> new_body_list;
    4223 [ #  # ][ #  # ]:          0 :   shape_to_bodySM(shape_list, new_body_list);
                 [ #  # ]
    4224                 :            :   
    4225 [ #  # ][ #  # ]:          0 :   if (new_body_list.size() == 1)
    4226                 :            :   {
    4227         [ #  # ]:          0 :     new_body = new_body_list.get();
    4228                 :            :     //find new_tbs and att_tbs;
    4229         [ #  # ]:          0 :     DLIList<OCCSurface*> new_surfs;
    4230 [ #  # ][ #  # ]:          0 :     DLIList<OCCCurve*> new_curves;
    4231 [ #  # ][ #  # ]:          0 :     DLIList<OCCPoint*> new_points;
    4232 [ #  # ][ #  # ]:          0 :     if(new_tbs || att_tbs) 
    4233                 :            :     {
    4234         [ #  # ]:          0 :       OCCBody* occ_body = CAST_TO(new_body, OCCBody);
    4235         [ #  # ]:          0 :       occ_body->get_all_surfaces(new_surfs);
    4236         [ #  # ]:          0 :       occ_body->get_all_curves(new_curves);
    4237         [ #  # ]:          0 :       occ_body->get_all_points(new_points);
    4238                 :            :     } 
    4239         [ #  # ]:          0 :     if(new_tbs)
    4240                 :            :       get_new_tbs(surf_property_map, curve_property_map, points, new_surfs, 
    4241         [ #  # ]:          0 :                   new_curves, new_points, new_tbs);
    4242         [ #  # ]:          0 :     if(att_tbs)
    4243                 :            :       get_att_tbs(new_surfs, new_curves, new_points, "COMPOSITE_GEOM",
    4244 [ #  # ][ #  # ]:          0 :                   att_tbs);
                 [ #  # ]
    4245                 :            : 
    4246         [ #  # ]:          0 :     return CUBIT_SUCCESS;
    4247                 :            :   }
    4248         [ #  # ]:          0 :   return CUBIT_FAILURE;
    4249                 :            : }
    4250                 :            : 
    4251                 :            : //===============================================================================
    4252                 :            : // Function   : shape_to_bodySM
    4253                 :            : // Member Type: PRIVATE
    4254                 :            : // Description: After imprint, update shape list to bodySM_list
    4255                 :            : // Author     : Jane Hu
    4256                 :            : // Date       : 06/08
    4257                 :            : //===============================================================================
    4258                 :         11 : void OCCModifyEngine::shape_to_bodySM( DLIList<TopoDS_Shape*> shape_list,
    4259                 :            :                                        DLIList<BodySM*>& new_body_list)const
    4260                 :            : {
    4261         [ +  + ]:         22 :   for(int j = 0; j < shape_list.size(); j ++)
    4262                 :            :   {
    4263         [ +  - ]:         11 :     DLIList<TopologyBridge*> tbs;
    4264         [ +  - ]:         11 :     TopoDS_Shape* shape = shape_list.get_and_step();
    4265 [ +  - ][ -  + ]:         11 :     if (shape->ShapeType() == TopAbs_COMPOUND)
    4266                 :            :     {
    4267 [ #  # ][ #  # ]:          0 :       if(!OCCQueryEngine::instance()->OCCMap->IsBound(*shape))
                 [ #  # ]
    4268                 :            :       {
    4269         [ #  # ]:          0 :         TopExp_Explorer Ex;
    4270 [ #  # ][ #  # ]:          0 :         for (Ex.Init(*shape, TopAbs_SOLID);Ex.More(); Ex.Next())
         [ #  # ][ #  # ]
    4271                 :            :         {
    4272 [ #  # ][ #  # ]:          0 :           TopoDS_Shape subshape = Ex.Current();
    4273 [ #  # ][ #  # ]:          0 :           tbs += OCCQueryEngine::instance()->populate_topology_bridge(subshape);
         [ #  # ][ #  # ]
    4274 [ #  # ][ #  # ]:          0 :           new_body_list.append_unique(CAST_TO(tbs.get(),BodySM));
                 [ #  # ]
    4275 [ #  # ][ #  # ]:          0 :         }
    4276                 :            :       }
    4277                 :            :     }
    4278                 :            :     else
    4279                 :            :     {
    4280 [ +  - ][ +  - ]:         11 :       tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape);
         [ +  - ][ +  - ]
    4281 [ +  - ][ -  + ]:         11 :       BodySM* body = CAST_TO(tbs.get(),BodySM);
    4282         [ -  + ]:         11 :       if(body != NULL)
    4283         [ #  # ]:         11 :         new_body_list.append_unique(body);
    4284                 :            :     }
    4285         [ +  - ]:         11 :   }
    4286                 :         11 : }
    4287                 :            : 
    4288                 :            : //===============================================================================
    4289                 :            : // Function   : imprint
    4290                 :            : // Member Type: PUBLIC
    4291                 :            : // Description: Imprints locations to bodies (for splitting curves, there's
    4292                 :            : //              no known ways to put hard points on surfaces in OCC, so I just
    4293                 :            : //              add free_vertex on OCCSurface definition, mesh should look on
    4294                 :            : //              this structure).   
    4295                 :            : // Author     : Jane Hu
    4296                 :            : // Date       : 06/08
    4297                 :            : //===============================================================================
    4298                 :          0 : CubitStatus     OCCModifyEngine::imprint( DLIList<BodySM*> &body_list,
    4299                 :            :                                           DLIList<CubitVector> &vector_list,
    4300                 :            :                                           DLIList<BodySM*>& new_body_list,
    4301                 :            :                                           bool keep_old,
    4302                 :            :                                           DLIList<TopologyBridge*>* new_tbs,
    4303                 :            :                                           DLIList<TopologyBridge*>* att_tbs,
    4304                 :            :                                           double *tol_in ,
    4305                 :            :                                           bool clean_up_slivers ) const
    4306                 :            : {
    4307         [ #  # ]:          0 :   DLIList<TopoDS_Shape*> shape_list;
    4308 [ #  # ][ #  # ]:          0 :   DLIList<CubitBoolean> is_vo;
    4309                 :          0 :   double tol = 0.1;
    4310         [ #  # ]:          0 :   if(tol_in)
    4311                 :          0 :     tol = *tol_in;
    4312         [ #  # ]:          0 :   CubitStatus stat = get_shape_list(body_list, shape_list, is_vo, keep_old);
    4313         [ #  # ]:          0 :   if(!stat)
    4314                 :          0 :     return stat;
    4315                 :            : 
    4316 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < body_list.size(); i++)
    4317                 :            :   {
    4318 [ #  # ][ #  # ]:          0 :     OCCBody* body = CAST_TO(body_list.get_and_step(), OCCBody);
    4319         [ #  # ]:          0 :     TopoDS_Shape* from_shape = shape_list.get();
    4320         [ #  # ]:          0 :     if (!body)
    4321                 :          0 :       continue;
    4322         [ #  # ]:          0 :     DLIList<OCCSurface*> surfaces;
    4323 [ #  # ][ #  # ]:          0 :     DLIList<OCCCurve*> curves;
    4324                 :            : 
    4325         [ #  # ]:          0 :     body->get_all_surfaces(surfaces);
    4326         [ #  # ]:          0 :     body->get_all_curves(curves);
    4327                 :            :     
    4328                 :          0 :     CubitBoolean on_vertex = CUBIT_FALSE;
    4329                 :          0 :     CubitBoolean on_curve = CUBIT_FALSE;
    4330 [ #  # ][ #  # ]:          0 :     for (int j = 0; j < vector_list.size(); j ++)
    4331                 :            :     {
    4332         [ #  # ]:          0 :       CubitVector& v = vector_list[j];
    4333 [ #  # ][ #  # ]:          0 :       for (int k = 0;  k < curves.size(); k ++)
    4334                 :            :       {
    4335         [ #  # ]:          0 :          OCCCurve* curve = curves.get_and_step();
    4336         [ #  # ]:          0 :          CubitPointContainment pc = curve->point_containment(v);
    4337         [ #  # ]:          0 :          if(pc == CUBIT_PNT_BOUNDARY)
    4338                 :            :          {
    4339                 :          0 :            on_vertex = CUBIT_TRUE;
    4340                 :          0 :            break;
    4341                 :            :          }
    4342                 :            : 
    4343         [ #  # ]:          0 :          else if( pc == CUBIT_PNT_INSIDE)
    4344                 :            :          {
    4345                 :          0 :            on_curve = CUBIT_TRUE;
    4346                 :            :            //first make sure it won't generate a sliver curve
    4347                 :            :            //with respect to tol.
    4348         [ #  # ]:          0 :            if(clean_up_slivers)
    4349                 :            :            {
    4350         [ #  # ]:          0 :              double u = curve->u_from_position(v);
    4351                 :            :              double u_min, u_max;
    4352         [ #  # ]:          0 :              curve->get_param_range(u_min, u_max);
    4353         [ #  # ]:          0 :              double l1 = curve->length_from_u(u_min, u);
    4354         [ #  # ]:          0 :              double l2 = curve->measure() - l1;
    4355 [ #  # ][ #  # ]:          0 :              if(l1 <= tol || l2 <= tol)
    4356                 :            :                break;
    4357                 :            :            }
    4358                 :            : 
    4359         [ #  # ]:          0 :            const CubitVector location = v;
    4360         [ #  # ]:          0 :            DLIList<Curve*> created_curves;
    4361                 :            :            stat = split_shape_by_location(from_shape, (Curve*)curve, location, 
    4362         [ #  # ]:          0 :                                           created_curves);
    4363         [ #  # ]:          0 :            shape_list.change_to(from_shape);
    4364         [ #  # ]:          0 :            if(new_tbs)
    4365 [ #  # ][ #  # ]:          0 :              for(int ic=0; ic < created_curves.size(); ic++)
    4366 [ #  # ][ #  # ]:          0 :                new_tbs->append(created_curves.get_and_step());
    4367                 :            : 
    4368         [ #  # ]:          0 :            curves.remove(curve);
    4369 [ #  # ][ #  # ]:          0 :            for(int ic = 0; ic < created_curves.size(); ic++)
    4370 [ #  # ][ #  # ]:          0 :              curves.append(CAST_TO(created_curves.get_and_step(), OCCCurve));
                 [ #  # ]
    4371         [ #  # ]:          0 :            break;
    4372                 :            :          }  
    4373                 :            :        } 
    4374 [ #  # ][ #  # ]:          0 :        if(on_vertex || on_curve)
    4375                 :          0 :          continue;
    4376                 :            : 
    4377                 :            :        //check possible on surface
    4378 [ #  # ][ #  # ]:          0 :        for(int n = 0; n < surfaces.size(); n ++)
    4379                 :            :        {
    4380         [ #  # ]:          0 :           OCCSurface* surface = surfaces.get_and_step();
    4381 [ #  # ][ #  # ]:          0 :           if(!surface->is_position_on(v))
    4382                 :          0 :             continue;
    4383                 :            :            
    4384         [ #  # ]:          0 :           CubitPointContainment ps = surface->point_containment(v);
    4385         [ #  # ]:          0 :           if(ps == CUBIT_PNT_INSIDE)
    4386                 :            :           {
    4387         [ #  # ]:          0 :              TBPoint* p = make_Point(v);
    4388         [ #  # ]:          0 :              if(p)
    4389                 :            :              {
    4390 [ #  # ][ #  # ]:          0 :                surface->add_hardpoint(CAST_TO(p, OCCPoint));
    4391         [ #  # ]:          0 :                if(new_tbs)
    4392         [ #  # ]:          0 :                  new_tbs->append(p);
    4393                 :            :              }
    4394                 :          0 :              break;
    4395                 :            :           }
    4396                 :            :        }
    4397                 :            :     }
    4398         [ #  # ]:          0 :     shape_list.step();
    4399         [ #  # ]:          0 :   }       
    4400                 :            : 
    4401 [ #  # ][ #  # ]:          0 :   shape_to_bodySM(shape_list, new_body_list);
                 [ #  # ]
    4402                 :            :   
    4403 [ #  # ][ #  # ]:          0 :   DLIList<OCCSurface*> surfaces;
    4404 [ #  # ][ #  # ]:          0 :   DLIList<OCCCurve*>   curves;
    4405 [ #  # ][ #  # ]:          0 :   DLIList<OCCPoint*>   points;
    4406 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < new_body_list.size(); i++)
    4407                 :            :   {
    4408 [ #  # ][ #  # ]:          0 :     OCCBody * body = CAST_TO(new_body_list.get_and_step(), OCCBody);
    4409         [ #  # ]:          0 :     body->get_all_surfaces(surfaces);
    4410         [ #  # ]:          0 :     body->get_all_curves(curves);
    4411         [ #  # ]:          0 :     body->get_all_points(points);
    4412                 :            :   }
    4413                 :            : 
    4414 [ #  # ][ #  # ]:          0 :   get_att_tbs(surfaces, curves, points, "COMPOSITE_GEOM", att_tbs);
                 [ #  # ]
    4415                 :            : 
    4416         [ #  # ]:          0 :   return stat;
    4417                 :            : }
    4418                 :            : 
    4419                 :            : 
    4420                 :            : //===============================================================================
    4421                 :            : // Function   : imprint_projected_edges
    4422                 :            : // Member Type: PUBLIC
    4423                 :            : // Description: Projects a list of Curves on to a list of Surfaces
    4424                 :            : //              and imprint the faces with the new Curves
    4425                 :            : // Author     : Jane Hu
    4426                 :            : // Date       : 06/08
    4427                 :            : //===============================================================================
    4428                 :            : CubitStatus     
    4429                 :          0 : OCCModifyEngine::imprint_projected_edges( DLIList<Surface*> &ref_face_list,
    4430                 :            :                                           DLIList<Curve*> &ref_edge_list,
    4431                 :            :                                           DLIList<BodySM*>& new_body_list,
    4432                 :            :                                           DLIList<Curve*>& kept_free_edges,
    4433                 :            :                                           bool keep_old_body,
    4434                 :            :                                           bool keep_free_edges) const
    4435                 :            : {
    4436         [ #  # ]:          0 :   DLIList<Curve*> projected_curves;
    4437                 :            :   CubitStatus 
    4438         [ #  # ]:          0 :      stat = project_edges(ref_face_list, ref_edge_list, projected_curves);
    4439         [ #  # ]:          0 :   if(!stat)
    4440                 :          0 :     return stat;
    4441                 :            : 
    4442                 :            :   // imprint Surface with curves
    4443 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> temp_bridges;
    4444         [ #  # ]:          0 :   stat = imprint(ref_face_list, projected_curves, temp_bridges, new_body_list, keep_old_body );
    4445                 :            : 
    4446         [ #  # ]:          0 :   if(keep_free_edges)
    4447                 :            :   {
    4448         [ #  # ]:          0 :      kept_free_edges += projected_curves;
    4449                 :          0 :      return  stat;
    4450                 :            :   }
    4451                 :            : 
    4452 [ #  # ][ #  # ]:          0 :   PRINT_INFO( "Removing projected curves \n");
         [ #  # ][ #  # ]
    4453 [ #  # ][ #  # ]:          0 :   for(int i=0; i< projected_curves.size();i++)
    4454                 :            :   {
    4455                 :            :     // Now delete this Curve and its underlying solid model entities
    4456                 :            : 
    4457         [ #  # ]:          0 :     Curve* curve = projected_curves.get_and_step();
    4458 [ #  # ][ #  # ]:          0 :     stat = OCCQueryEngine::instance()->delete_solid_model_entities( curve );
    4459         [ #  # ]:          0 :     if (stat == CUBIT_FAILURE)
    4460                 :            :     {
    4461 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("In OCCQueryEngine::delete_geometry\n"
                 [ #  # ]
    4462                 :            :                  "       Could not delete OCCCurve.\n"
    4463                 :            :                  "       The Model database is likely corrupted "
    4464         [ #  # ]:          0 :                  "due to\n       this unsuccessful deletion.\n" );
    4465                 :            :     }
    4466                 :            :   } 
    4467         [ #  # ]:          0 :   return stat;
    4468                 :            : }
    4469                 :            : //===============================================================================
    4470                 :            : // Function   : project_edges
    4471                 :            : // Member Type: PUBLIC
    4472                 :            : // Description: Projects a list of Curves on to a list of Surfaces
    4473                 :            : // Author     : Jane Hu
    4474                 :            : // Date       : 06/08
    4475                 :            : //===============================================================================
    4476                 :          0 : CubitStatus OCCModifyEngine::project_edges( DLIList<Surface*> &ref_face_list,
    4477                 :            :                                             DLIList<Curve*> &ref_edge_list,
    4478                 :            :                                             DLIList<Curve*> &projected_curves,
    4479                 :            :                                             bool print_error ) const
    4480                 :            : 
    4481                 :            : {
    4482                 :          0 :   CubitVector* v = NULL;
    4483                 :          0 :   Curve* projected_curve = NULL;
    4484         [ #  # ]:          0 :   DLIList<TBPoint*> points;
    4485                 :            :   //project curves onto surfaces.
    4486 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < ref_edge_list.size(); i++)
    4487                 :            :   {
    4488 [ #  # ][ #  # ]:          0 :     OCCCurve* curve = CAST_TO(ref_edge_list.get_and_step(), OCCCurve);
    4489         [ #  # ]:          0 :     if(!curve)
    4490                 :          0 :        continue;
    4491                 :            : 
    4492 [ #  # ][ #  # ]:          0 :     for (int j = 0; j < ref_face_list.size(); j++)
    4493                 :            :     {
    4494 [ #  # ][ #  # ]:          0 :       OCCSurface* surface = CAST_TO(ref_face_list.get_and_step(), OCCSurface); 
    4495         [ #  # ]:          0 :       if(!surface)
    4496                 :          0 :         continue;
    4497 [ #  # ][ #  # ]:          0 :       if(surface->is_closed_in_U() || surface->is_closed_in_V())
         [ #  # ][ #  # ]
                 [ #  # ]
    4498                 :            :       {
    4499         [ #  # ]:          0 :         if(print_error)
    4500 [ #  # ][ #  # ]:          0 :           PRINT_ERROR("This function can't project curves on closed surfaces.\n");
         [ #  # ][ #  # ]
    4501                 :          0 :         return CUBIT_FAILURE;
    4502                 :            :       }
    4503                 :            :       
    4504                 :          0 :       projected_curve = NULL;
    4505         [ #  # ]:          0 :       projected_curve = curve->project_curve(surface, points, CUBIT_FALSE, v);
    4506         [ #  # ]:          0 :       if(projected_curve)
    4507         [ #  # ]:          0 :         projected_curves.append_unique(projected_curve);
    4508                 :            :     }
    4509                 :            :   }
    4510 [ #  # ][ #  # ]:          0 :   while(points.size() > 0)
    4511 [ #  # ][ #  # ]:          0 :     delete points.pop();
                 [ #  # ]
    4512         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    4513                 :            : }
    4514                 :            : 
    4515                 :            : //===============================================================================
    4516                 :            : // Function   : imprint_projected_edges
    4517                 :            : // Member Type: PUBLIC
    4518                 :            : // Description: Projects a list of curves on to a list of surfaces
    4519                 :            : //              and imprint the bodies with the new curves
    4520                 :            : // Author     : Jane Hu
    4521                 :            : // Date       : 06/08
    4522                 :            : //===============================================================================
    4523                 :            : CubitStatus 
    4524                 :          0 : OCCModifyEngine::imprint_projected_edges(DLIList<Surface*> &ref_face_list,
    4525                 :            :                                          DLIList<BodySM*> &body_list,
    4526                 :            :                                          DLIList<Curve*> &ref_edge_list,
    4527                 :            :                                          DLIList<BodySM*>& new_body_list,
    4528                 :            :                                          bool keep_old,
    4529                 :            :                                          bool keep_free_edges) const
    4530                 :            : {
    4531         [ #  # ]:          0 :   DLIList<Curve*> projected_curves;
    4532                 :            :   CubitStatus
    4533         [ #  # ]:          0 :      stat = project_edges(ref_face_list, ref_edge_list, projected_curves);
    4534         [ #  # ]:          0 :   if(!stat)
    4535                 :          0 :     return stat; 
    4536                 :          0 :   return CUBIT_FAILURE;
    4537                 :            : 
    4538                 :            :   // imprint bodies with curves
    4539                 :            :   DLIList<TopologyBridge*> temp_bridges;
    4540                 :            :   stat = imprint(body_list,projected_curves, new_body_list, temp_bridges, keep_old);
    4541                 :            : 
    4542                 :            :   if (keep_free_edges)
    4543                 :            :         return  stat;
    4544                 :            : 
    4545                 :            :   PRINT_INFO( "Removing projected curves \n");
    4546                 :            :   for(int i=0; i< projected_curves.size();i++)
    4547                 :            :   {
    4548                 :            :     // Now delete this Curve 
    4549                 :            :     Curve* curve = projected_curves.get_and_step();
    4550                 :            :     stat = OCCQueryEngine::instance()->
    4551                 :            :           delete_solid_model_entities( curve );
    4552                 :            :     if (stat == CUBIT_FAILURE)
    4553                 :            :     {
    4554                 :            :        PRINT_ERROR("In OCCModifyEngine::delete_geometry\n"
    4555                 :            :                    "       Could not delete Curve.\n"
    4556                 :            :                    "       The Model database is likely corrupted "
    4557                 :            :                    "due to\n       this unsuccessful deletion.\n" );
    4558                 :            :     }
    4559                 :            :   }
    4560         [ #  # ]:          0 :   return stat; 
    4561                 :            : }
    4562                 :            : 
    4563                 :            : //===============================================================================
    4564                 :            : // Function   : intersect
    4565                 :            : // Member Type: PUBLIC
    4566                 :            : // Description: intersect boolean operation of body with list of bodies.
    4567                 :            : // Author     : Jane Hu
    4568                 :            : // Date       : 06/08
    4569                 :            : //===============================================================================
    4570                 :         33 : CubitStatus OCCModifyEngine::intersect(BodySM*  tool_body_ptr,
    4571                 :            :                                        DLIList<BodySM*>  &from_bodies,
    4572                 :            :                                        DLIList<BodySM*>  &new_bodies,
    4573                 :            :                                        bool  keep_old,
    4574                 :            :                                        bool preview) const
    4575                 :            : {
    4576         [ +  - ]:         33 :   DLIList<BodySM*> tool_bodies;
    4577 [ +  - ][ +  - ]:         66 :   DLIList<TopoDS_Shape*> tool_shapes;
    4578 [ +  - ][ +  - ]:         66 :   DLIList<CubitBoolean> is_tool_volume, is_volume;
         [ +  - ][ +  - ]
    4579                 :            :   
    4580         [ +  - ]:         33 :   tool_bodies.append(tool_body_ptr);
    4581                 :            :   //get tool_body's underlying shape, copy it, so boolean wouldn't touch it.
    4582                 :            :   CubitStatus stat = 
    4583         [ +  - ]:         33 :        get_shape_list(tool_bodies, tool_shapes, is_tool_volume, CUBIT_TRUE); 
    4584         [ -  + ]:         33 :   if(!stat)
    4585                 :          0 :     return stat;
    4586                 :            : 
    4587 [ +  - ][ +  - ]:         66 :   DLIList<TopoDS_Shape*> shape_list;
    4588         [ +  - ]:         33 :   stat =  get_shape_list(from_bodies, shape_list, is_volume, keep_old);
    4589         [ -  + ]:         33 :   if(!stat)
    4590                 :            :   {
    4591 [ #  # ][ #  # ]:          0 :     for (int i = 0; i < tool_shapes.size(); i++)
    4592                 :            :     {
    4593         [ #  # ]:          0 :        TopoDS_Shape* shape = tool_shapes.get_and_step();
    4594 [ #  # ][ #  # ]:          0 :        delete shape;
                 [ #  # ]
    4595                 :          0 :        shape = NULL; 
    4596                 :            :     }
    4597         [ #  # ]:          0 :     tool_shapes.clean_out();
    4598                 :          0 :     return CUBIT_FAILURE;
    4599                 :            :   }
    4600                 :            : 
    4601         [ +  - ]:         33 :   TopoDS_Shape* tool_shape = tool_shapes.get();
    4602                 :            :   CubitBoolean has_changed;
    4603 [ +  - ][ +  - ]:         66 :   DLIList<TopologyBridge*> tbs;
    4604 [ +  - ][ +  - ]:         66 :   DLIList<TopoDS_Shape*> preview_list;
    4605 [ +  - ][ +  + ]:         66 :   for (int i = 0; i < shape_list.size(); i++)
    4606                 :            :   { 
    4607         [ +  - ]:         33 :     TopoDS_Shape* from_shape = shape_list.get_and_step();
    4608         [ +  - ]:         33 :     BodySM* from_body = from_bodies.get_and_step();
    4609         [ +  - ]:         33 :     BRepAlgoAPI_Common intersector(*from_shape, *tool_shape);
    4610                 :            : 
    4611 [ +  - ][ +  - ]:         66 :     TopTools_ListOfShape shapes;
                 [ +  - ]
    4612 [ +  - ][ +  - ]:         33 :     shapes.Assign(intersector.Modified(*tool_shape));
    4613                 :            :     
    4614 [ +  - ][ -  + ]:         33 :     if ( shapes.Extent() > 1)
    4615                 :            :     {
    4616 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Tool has multiple intersection with the shape, make it simpler. \n");
         [ #  # ][ #  # ]
    4617                 :          0 :       continue;
    4618                 :            :     }
    4619 [ +  - ][ +  - ]:         66 :     TopoDS_Shape common_shape;
         [ +  - ][ +  - ]
    4620 [ +  - ][ +  + ]:         33 :     if (shapes.IsEmpty())
    4621 [ +  - ][ +  - ]:         11 :       common_shape = intersector.Shape();
    4622                 :            :     else 
    4623 [ +  - ][ +  - ]:         22 :       common_shape = shapes.First();
    4624                 :            : 
    4625 [ +  - ][ +  - ]:         33 :     if (!common_shape.IsNull())
    4626                 :            :     {
    4627         [ +  - ]:         33 :       TopExp_Explorer Ex(common_shape, TopAbs_SOLID);
    4628 [ +  - ][ +  + ]:         55 :       if(!Ex.More() && is_volume[i] == CUBIT_TRUE && 
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  + ]
           [ +  +  #  # ]
    4629         [ +  - ]:         22 :          common_shape.ShapeType() > TopAbs_SOLID)
    4630                 :            :       {
    4631                 :         22 :         has_changed = CUBIT_TRUE;
    4632         [ +  - ]:         22 :         *from_shape = common_shape;
    4633                 :            :       }
    4634                 :            :       
    4635 [ +  - ][ +  - ]:         11 :       else if (is_volume[i] == CUBIT_FALSE && 
         [ -  + ][ #  # ]
                 [ +  - ]
           [ -  +  #  # ]
    4636         [ #  # ]:          0 :                common_shape.ShapeType() > TopAbs_FACE) 
    4637                 :            :       {
    4638         [ #  # ]:          0 :         Ex.Init(common_shape, TopAbs_SHELL, TopAbs_SOLID);
    4639 [ #  # ][ #  # ]:          0 :         if(!Ex.More())
    4640         [ #  # ]:          0 :           Ex.Init(common_shape, TopAbs_FACE);
    4641 [ #  # ][ #  # ]:          0 :         if(!Ex.More() && is_volume[i] == CUBIT_FALSE)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
    4642                 :            :         {
    4643                 :          0 :           has_changed = CUBIT_TRUE;
    4644         [ #  # ]:          0 :           *from_shape = common_shape;
    4645                 :            :         }
    4646                 :            :       }
    4647                 :            :       else
    4648                 :            :       {
    4649                 :         11 :         double after_mass = 0.0;
    4650         [ +  - ]:         11 :         GProp_GProps myProps;
    4651 [ +  - ][ +  - ]:         11 :         if(is_volume[i])
                 [ +  - ]
    4652         [ +  - ]:         11 :           BRepGProp::VolumeProperties(common_shape, myProps);
    4653                 :            :         
    4654                 :            :         else
    4655         [ #  # ]:          0 :           BRepGProp::SurfaceProperties(common_shape, myProps);
    4656         [ +  - ]:         11 :         after_mass = myProps.Mass();
    4657         [ +  - ]:         11 :         if(after_mass > TOL)
    4658                 :            :           check_operation(common_shape, from_shape, is_volume[i], has_changed,
    4659 [ +  - ][ +  - ]:         11 :                     &intersector, keep_old);
                 [ +  - ]
    4660                 :            :         else
    4661                 :            :         {
    4662         [ #  # ]:          0 :           if(!keep_old)
    4663 [ #  # ][ #  # ]:          0 :             OCCQueryEngine::instance()->delete_solid_model_entities(from_body); 
    4664                 :         11 :           from_shape = NULL;
    4665                 :            :         }
    4666         [ +  - ]:         33 :       }
    4667                 :            :     }
    4668                 :            : 
    4669 [ +  - ][ +  - ]:         33 :     if(from_shape == NULL || from_shape->IsNull() )
         [ -  + ][ -  + ]
    4670                 :            :     {
    4671 [ #  # ][ #  # ]:          0 :       PRINT_INFO("The %d body did not have common part with the tool_body.\n", i+1);
         [ #  # ][ #  # ]
    4672                 :            :     }
    4673                 :            :     else
    4674                 :            :     {
    4675         [ -  + ]:         33 :       if(preview)
    4676                 :            :       {
    4677 [ #  # ][ #  # ]:          0 :         TopoDS_Shape* p_shape = new TopoDS_Shape(common_shape);
    4678         [ #  # ]:          0 :         preview_list.append(p_shape);
    4679                 :            :       }
    4680                 :            :       else
    4681 [ +  - ][ +  - ]:         33 :         tbs += OCCQueryEngine::instance()->populate_topology_bridge(*from_shape);
         [ +  - ][ +  - ]
    4682                 :            :     }
    4683                 :         33 :   }
    4684                 :            : 
    4685         [ -  + ]:         33 :   if(preview)
    4686                 :            :   {
    4687         [ #  # ]:          0 :     GfxPreview::clear();
    4688 [ #  # ][ #  # ]:          0 :     for(int i = 0; i < preview_list.size(); i++)
    4689                 :            :     {
    4690         [ #  # ]:          0 :       TopoDS_Shape* new_shape = preview_list.get_and_step();
    4691                 :            :       // Draw this face
    4692                 :            :       OCCDrawTool::instance()->draw_TopoDS_Shape( new_shape, CUBIT_BLUE_INDEX,
    4693 [ #  # ][ #  # ]:          0 :                                                   CUBIT_FALSE, CUBIT_TRUE );
    4694 [ #  # ][ #  # ]:          0 :       delete new_shape;
                 [ #  # ]
    4695                 :            :     }
    4696                 :            :   }
    4697                 :            :   
    4698 [ +  - ][ +  + ]:         66 :   for (int i = 0; i< tbs.size(); i++)
    4699                 :            :   {
    4700 [ +  - ][ -  + ]:         33 :     BodySM* bodysm = CAST_TO(tbs.get_and_step(), BodySM);
    4701         [ +  - ]:         33 :     if (bodysm)
    4702         [ +  - ]:         33 :       new_bodies.append(bodysm);
    4703                 :            :   }
    4704                 :            :   
    4705                 :            :   //if(tbs.size() == 0)
    4706                 :            :   //  stat = CUBIT_FAILURE;
    4707                 :            :     
    4708                 :            :   //ok, we're done with all cuts, delete unnecessaries.
    4709         [ -  + ]:         33 :   if(!keep_old)
    4710 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(tool_body_ptr);   
    4711                 :            : 
    4712 [ +  - ][ +  + ]:         66 :   for(int i = 0; i < tool_shapes.size(); i++)
    4713                 :            :   {
    4714         [ +  - ]:         33 :     TopoDS_Shape* shape = tool_shapes.get_and_step();
    4715         [ +  - ]:         33 :     shape->Nullify();
    4716 [ +  - ][ +  - ]:         33 :     delete shape;
                 [ +  - ]
    4717                 :         33 :     shape = NULL;
    4718                 :            :   }
    4719                 :            : 
    4720         [ +  - ]:         33 :   if(keep_old)
    4721                 :            :   {
    4722         [ +  - ]:         33 :     int size  = shape_list.size();
    4723         [ +  + ]:         66 :     for (int i = 0; i < size; i++)
    4724                 :            :     {
    4725         [ +  - ]:         33 :       TopoDS_Shape* shape = shape_list.pop();
    4726         [ +  - ]:         33 :       shape->Nullify();
    4727 [ +  - ][ +  - ]:         33 :       delete shape;
                 [ +  - ]
    4728                 :         33 :       shape = NULL;
    4729                 :            :     }
    4730                 :            :   }
    4731         [ -  + ]:         33 :   if(!stat)
    4732                 :          0 :     return stat;
    4733         [ +  - ]:         66 :   return CUBIT_SUCCESS;
    4734                 :            : }
    4735                 :            : 
    4736                 :            : //===============================================================================
    4737                 :            : // Function   : check_operation
    4738                 :            : // Member Type: PRIVATE
    4739                 :            : // Description: check and update the from_shape according to type of the body.
    4740                 :            : // Author     : Jane Hu
    4741                 :            : // Date       : 06/08
    4742                 :            : //===============================================================================
    4743                 :        339 : void OCCModifyEngine::check_operation(TopoDS_Shape& cut_shape,
    4744                 :            :                                       TopoDS_Shape*& from_shape, //output
    4745                 :            :                                       CubitBoolean  is_volume,
    4746                 :            :                                       CubitBoolean& has_changed, //output
    4747                 :            :                                       BRepAlgoAPI_BooleanOperation* op,
    4748                 :            :                                       CubitBoolean keep_old) const
    4749                 :            : {
    4750                 :            :    //compare to see if the from_shape has gotten cut.
    4751         [ +  - ]:        339 :    if(is_volume)
    4752                 :            :    {
    4753         [ +  - ]:        339 :      GProp_GProps myProps;
    4754         [ +  - ]:        339 :      BRepGProp::VolumeProperties(*from_shape, myProps);
    4755         [ +  - ]:        339 :      double orig_mass = myProps.Mass();
    4756         [ +  - ]:        339 :      TopTools_IndexedMapOfShape M;
    4757         [ +  - ]:        339 :      TopExp::MapShapes(cut_shape, TopAbs_SOLID, M);
    4758                 :        339 :      double after_mass = 0.0;
    4759                 :        339 :      CubitBoolean no_volume = CUBIT_FALSE;
    4760 [ +  - ][ +  - ]:        339 :      if(M.Extent() > 0)
    4761                 :            :      {
    4762         [ +  - ]:        339 :        BRepGProp::VolumeProperties(cut_shape, myProps);
    4763         [ +  - ]:        339 :        after_mass = myProps.Mass();
    4764                 :            :      }
    4765                 :            :      else
    4766                 :          0 :        no_volume = CUBIT_TRUE;
    4767                 :            :  
    4768         [ -  + ]:        339 :      if(fabs(-after_mass + orig_mass) <= TOL)
    4769                 :            :      {
    4770                 :          0 :         has_changed= CUBIT_FALSE; //common is itself
    4771                 :          0 :         return;
    4772                 :            :      }
    4773                 :            : 
    4774                 :            :      //got cut. Update the entities
    4775 [ +  - ][ -  + ]:        339 :      if(after_mass < TOL || no_volume) //no common section
    4776         [ #  # ]:          0 :        cut_shape.Nullify();
    4777                 :        339 :      has_changed = CUBIT_TRUE;
    4778 [ +  - ][ +  - ]:        678 :      TopExp_Explorer Ex;
         [ +  - ][ +  - ]
    4779                 :        339 :      int num_solid = 0;
    4780         [ +  - ]:        339 :      Ex.Init(*from_shape, TopAbs_SOLID);
    4781 [ +  - ][ +  - ]:        678 :      TopoDS_Solid old_solid;
    4782 [ +  - ][ +  - ]:        700 :      for(; Ex.More(); Ex.Next())
                 [ +  + ]
    4783                 :            :      {
    4784                 :        361 :        num_solid ++;
    4785 [ +  - ][ +  - ]:        361 :        old_solid = TopoDS::Solid(Ex.Current());
                 [ +  - ]
    4786                 :            :      }
    4787         [ +  + ]:        339 :      if(num_solid == 1)
    4788         [ +  - ]:        317 :        OCCLump::update_OCC_entity(old_solid , cut_shape, op);
    4789                 :            :      
    4790         [ +  - ]:         22 :      else if(num_solid > 1)
    4791         [ +  - ]:        361 :        OCCBody::update_OCC_entity(*from_shape, cut_shape, op);
    4792                 :            :    }
    4793                 :            :    else
    4794                 :            :    {
    4795         [ #  # ]:          0 :      GProp_GProps myProps;
    4796         [ #  # ]:          0 :      BRepGProp::SurfaceProperties(*from_shape, myProps);
    4797         [ #  # ]:          0 :      double orig_mass = myProps.Mass();
    4798         [ #  # ]:          0 :      BRepGProp::SurfaceProperties(cut_shape, myProps);
    4799         [ #  # ]:          0 :      double after_mass = myProps.Mass();
    4800         [ #  # ]:          0 :      if(fabs(-after_mass + orig_mass) <= TOL)
    4801                 :            :      {
    4802                 :          0 :        has_changed= CUBIT_FALSE; //common is itself, or not cut
    4803                 :          0 :        return;
    4804                 :            :      }
    4805                 :            :      //got cut. Update the entities
    4806         [ #  # ]:          0 :      if(after_mass < TOL)//no common section
    4807         [ #  # ]:          0 :        cut_shape.Nullify();
    4808                 :          0 :      has_changed = CUBIT_TRUE;
    4809 [ #  # ][ #  # ]:          0 :      if(from_shape->ShapeType() == TopAbs_SHELL)
    4810                 :            :      {
    4811 [ #  # ][ #  # ]:          0 :        TopoDS_Shell old_shell = TopoDS::Shell(*from_shape);
    4812 [ #  # ][ #  # ]:          0 :        OCCShell::update_OCC_entity(old_shell,cut_shape, op);
    4813                 :            :      }
    4814                 :            :      else
    4815                 :            :      {
    4816 [ #  # ][ #  # ]:          0 :        TopoDS_Face old_face = TopoDS::Face(*from_shape);
    4817 [ #  # ][ #  # ]:          0 :        OCCSurface::update_OCC_entity(old_face,cut_shape, op);
    4818                 :            :      }
    4819                 :            :   }
    4820                 :            : //  if(keep_old) - Must not be deleted, causes random failure on OSX
    4821                 :            : //    delete from_shape;
    4822         [ +  - ]:        339 :   from_shape = new TopoDS_Shape(cut_shape);
    4823                 :            : }
    4824                 :            : 
    4825                 :            : //===============================================================================
    4826                 :            : // Function   : chop
    4827                 :            : // Member Type: PUBLIC
    4828                 :            : // Description: chop boolean operation between OCC-based bodies
    4829                 :            : //              bodies has a size() = 2, a blank body and a tool body.
    4830                 :            : //              chops the blank with the  tool, returing the body formed
    4831                 :            : //              by subtracting the tool from the blank, and the body formed
    4832                 :            : //              by intersecting the tool with the blank, simultaneously.
    4833                 :            : // Author     : Jane Hu
    4834                 :            : // Date       : 06/08
    4835                 :            : //===============================================================================
    4836                 :          0 : CubitStatus  OCCModifyEngine::chop(DLIList<BodySM*>& bodies, 
    4837                 :            :                                    DLIList<BodySM*> &intersectBodies, 
    4838                 :            :                                    DLIList<BodySM*> &outsideBodies,
    4839                 :            :                                    BodySM*& leftoversBody,
    4840                 :            :                                    bool keep_old ,
    4841                 :            :                                    bool nonreg) const
    4842                 :            : {
    4843                 :            :   //according to  chop function, leftoverBody = 0;
    4844                 :          0 :   leftoversBody = 0;
    4845                 :            : 
    4846                 :            :   //there's no effect of nonreg. keep_old mean if to keep the tool_body
    4847 [ #  # ][ #  # ]:          0 :   if(bodies.size() != 2)
    4848                 :            :   {
    4849 [ #  # ][ #  # ]:          0 :     PRINT_WARNING("Chop operation works only on two bodies. Nothing modified\n");  
         [ #  # ][ #  # ]
    4850                 :          0 :     return CUBIT_FAILURE; 
    4851                 :            :   }
    4852                 :            :   
    4853                 :            :   //outsideBodies keeps the surface, curve ids if keep_old is false.
    4854         [ #  # ]:          0 :   BodySM* blank_body = bodies.get();
    4855                 :            :   
    4856                 :            :   //copy blank_body for intersect operation, because it will get changed.
    4857 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> tool_bodies, from_bodies;
                 [ #  # ]
    4858         [ #  # ]:          0 :   from_bodies.append(blank_body);
    4859         [ #  # ]:          0 :   BodySM* tool_body = bodies.step_and_get();
    4860         [ #  # ]:          0 :   tool_bodies.append(tool_body);
    4861                 :            :   
    4862                 :            :   CubitStatus stat = intersect(tool_body, from_bodies, 
    4863         [ #  # ]:          0 :                                intersectBodies, CUBIT_TRUE);
    4864                 :            : 
    4865         [ #  # ]:          0 :   if(!stat)
    4866                 :          0 :     return CUBIT_FAILURE;
    4867                 :            : 
    4868                 :            :   stat = subtract(tool_bodies, from_bodies, outsideBodies, 
    4869         [ #  # ]:          0 :                   CUBIT_FALSE, keep_old);
    4870                 :            :   
    4871         [ #  # ]:          0 :   return stat;
    4872                 :            : }
    4873                 :            : 
    4874                 :            : //===============================================================================
    4875                 :            : // Function   : unite
    4876                 :            : // Member Type: PUBLIC
    4877                 :            : // Description: unite boolean operation between OCC-based bodies
    4878                 :            : // Author     : Jane Hu
    4879                 :            : // Date       : 06/08
    4880                 :            : //===============================================================================
    4881                 :         87 : CubitStatus     OCCModifyEngine::unite(DLIList<BodySM*> &bodies, 
    4882                 :            :                                        DLIList<BodySM*> &newBodies,
    4883                 :            :                                        bool keep_old) const
    4884                 :            : {
    4885 [ +  - ][ -  + ]:         87 :   if(bodies.size() < 2)
    4886                 :            :   {
    4887         [ #  # ]:          0 :     newBodies = bodies;
    4888                 :          0 :     return CUBIT_SUCCESS;
    4889                 :            :   }
    4890                 :            : 
    4891                 :            :   //In order to distinguish bodies who are not intersecting each other to 
    4892                 :            :   //avoid doing the boolean, check the minimum distance of the bodies first.
    4893         [ +  - ]:         87 :   DLIList<BodySM*> revised_bodies;
    4894 [ +  - ][ +  - ]:        174 :   DLIList<BodySM*> overlaped_bodies;
    4895 [ +  - ][ +  - ]:        174 :   DLIList<TopoDS_Shape*> overlap_shapes;
    4896 [ +  - ][ +  - ]:        174 :   DLIList<TopoDS_Shape*> shape_list;
    4897 [ +  - ][ +  - ]:        174 :   DLIList<TopoDS_Shape*> revised_shapes;
    4898 [ +  - ][ +  - ]:        174 :   DLIList<CubitBoolean> is_volume;
    4899                 :            :   CubitStatus stat =
    4900         [ +  - ]:         87 :         get_shape_list(bodies, shape_list, is_volume, keep_old); 
    4901                 :            : 
    4902         [ -  + ]:         87 :   if( !stat )
    4903                 :          0 :     return CUBIT_FAILURE;
    4904                 :            : 
    4905 [ +  - ][ +  + ]:        272 :   while(bodies.size() > 0)
    4906                 :            :   {
    4907         [ +  - ]:        185 :     TopoDS_Shape *shape1 = shape_list.pop();
    4908         [ +  - ]:        185 :     BodySM* first_body = bodies.pop();
    4909                 :        185 :     CubitBoolean intersect = false; 
    4910         [ +  - ]:        185 :     shape_list.reset();
    4911         [ +  - ]:        185 :     int size = shape_list.size();
    4912                 :            : 
    4913         [ +  - ]:        185 :     overlaped_bodies.clean_out();
    4914         [ +  - ]:        185 :     overlap_shapes.clean_out();
    4915         [ +  + ]:        635 :     for (int k = 0 ; k < size; k++)
    4916                 :            :     {
    4917         [ +  - ]:        450 :       TopoDS_Shape *shape2 = shape_list.get();
    4918         [ +  - ]:        450 :       BodySM* sec_body = bodies.get();
    4919         [ +  - ]:        450 :       BRepExtrema_DistShapeShape dist(*shape1, *shape2);
    4920                 :            :       //dist.Perform();
    4921 [ +  - ][ +  - ]:        450 :       if(dist.IsDone() && dist.Value() < TOL)
         [ +  - ][ +  + ]
                 [ +  + ]
    4922                 :            :       {
    4923         [ +  - ]:         99 :         overlaped_bodies.append(sec_body);
    4924         [ +  - ]:         99 :         overlap_shapes.append(shape2);
    4925         [ +  - ]:         99 :         bodies.change_to(NULL);
    4926         [ +  - ]:         99 :         shape_list.change_to(NULL);
    4927                 :         99 :         intersect = true;
    4928                 :            :       }
    4929         [ +  - ]:        450 :       bodies.step();
    4930         [ +  - ]:        450 :       shape_list.step();
    4931         [ +  - ]:        450 :     }
    4932         [ +  - ]:        185 :     bodies.remove_all_with_value(NULL);
    4933         [ +  - ]:        185 :     shape_list.remove_all_with_value(NULL);
    4934         [ +  + ]:        185 :     if (intersect != true)
    4935                 :            :     {
    4936         [ +  - ]:        108 :       revised_bodies.append(first_body);
    4937         [ +  - ]:        108 :       revised_shapes.append(shape1);
    4938                 :            :     }
    4939                 :            :     else
    4940                 :            :     {
    4941         [ +  - ]:         77 :       overlaped_bodies.append(first_body);
    4942         [ +  - ]:         77 :       overlap_shapes.append(shape1); 
    4943                 :            : 
    4944                 :            :       //find a non-sheet body to be the first shape
    4945                 :            :       TopoDS_Shape* first_shape;
    4946                 :            :       TopoDS_Shape* second_shape;
    4947                 :         77 :       CubitBoolean first_is_volume = false;
    4948 [ +  - ][ +  - ]:         77 :       for(int i = 0; i < overlap_shapes.size(); i++)
    4949                 :            :       {
    4950                 :            :         
    4951         [ +  - ]:         77 :         first_shape = overlap_shapes.get();
    4952 [ +  - ][ +  - ]:         77 :         if(first_shape->ShapeType() < TopAbs_SHELL)
    4953                 :            :         {
    4954                 :         77 :           first_is_volume = true;
    4955                 :         77 :           break;
    4956                 :            :         }
    4957         [ #  # ]:          0 :         overlap_shapes.step();
    4958         [ #  # ]:          0 :         overlaped_bodies.step();
    4959                 :            :       }
    4960         [ +  - ]:         77 :       overlap_shapes.remove(first_shape);
    4961         [ +  - ]:         77 :       BodySM* body1 = overlaped_bodies.remove();
    4962                 :         77 :       BodySM* body2 = NULL;
    4963         [ +  - ]:         77 :       overlap_shapes.reset();
    4964         [ +  - ]:         77 :       overlaped_bodies.reset();
    4965 [ +  - ][ +  + ]:        176 :       for(int i = 0; i < overlap_shapes.size(); i++)
    4966                 :            :       {
    4967         [ +  - ]:         99 :         second_shape = overlap_shapes.get_and_step();
    4968         [ +  - ]:         99 :         body2 = overlaped_bodies.get_and_step(); 
    4969         [ +  - ]:         99 :         BRepAlgoAPI_Fuse fuser(*first_shape, *second_shape);
    4970 [ +  - ][ +  - ]:        198 :         TopoDS_Shape new_shape = fuser.Shape();
                 [ +  - ]
    4971                 :            : 
    4972                 :            :         CubitBoolean has_changed;
    4973 [ +  - ][ +  - ]:        198 :         TopTools_IndexedMapOfShape M1, M2, M_new;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    4974         [ +  - ]:         99 :         TopExp::MapShapes(*first_shape, TopAbs_SOLID, M1); 
    4975         [ +  - ]:         99 :         TopExp::MapShapes(*second_shape, TopAbs_SOLID, M2);
    4976         [ +  - ]:         99 :         TopExp::MapShapes(new_shape, TopAbs_SOLID, M_new);
    4977 [ +  - ][ +  + ]:         99 :         if(M_new.Extent() == 1 && M1.Extent() > 1 && M2.Extent() == 1)
         [ +  - ][ +  + ]
         [ +  - ][ +  - ]
                 [ +  + ]
    4978                 :            :         {
    4979 [ +  - ][ +  - ]:         22 :           check_operation(new_shape,second_shape, is_volume[i], has_changed, &fuser, keep_old);
                 [ +  - ]
    4980         [ +  - ]:         22 :           check_operation(new_shape, first_shape, first_is_volume, has_changed, &fuser, keep_old);
    4981                 :            :         }
    4982                 :            :  
    4983 [ +  - ][ +  + ]:         77 :         else if(M_new.Extent() == 1 && M1.Extent() > 1 && M2.Extent() > 1)
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
                 [ -  + ]
    4984                 :            :         //two compound bodies unite into one solid lump body
    4985                 :            :         {
    4986 [ #  # ][ #  # ]:          0 :           OCCQueryEngine::instance()->copy_attributes(*first_shape, new_shape);
    4987 [ #  # ][ #  # ]:          0 :           OCCQueryEngine::instance()->copy_attributes(*second_shape, new_shape);
    4988 [ #  # ][ #  # ]:          0 :           first_shape = new TopoDS_Shape(new_shape);
    4989 [ #  # ][ #  # ]:          0 :           OCCQueryEngine::instance()->delete_solid_model_entities(body1);
    4990 [ #  # ][ #  # ]:          0 :           OCCQueryEngine::instance()->delete_solid_model_entities(body2);
    4991                 :            :         } 
    4992                 :            :         else
    4993                 :            :         {
    4994         [ +  - ]:         77 :           check_operation(new_shape, first_shape, first_is_volume, has_changed, &fuser, keep_old);
    4995                 :            : 
    4996 [ +  - ][ +  - ]:         77 :           check_operation(new_shape,second_shape, is_volume[i], has_changed, &fuser, keep_old);
                 [ +  - ]
    4997                 :            :         }
    4998         [ +  - ]:         99 :       }
    4999                 :            :       //ok, we're done with all unites, construct new Body'
    5000         [ +  - ]:         77 :       DLIList<TopologyBridge*> tbs;
    5001 [ +  - ][ +  - ]:         77 :       tbs += OCCQueryEngine::instance()->populate_topology_bridge(*first_shape);
         [ +  - ][ +  - ]
    5002                 :            : 
    5003 [ +  - ][ -  + ]:         77 :       BodySM* bodysm = CAST_TO(tbs.get(), BodySM);
    5004         [ +  - ]:         77 :       if (bodysm)
    5005                 :            :       {
    5006 [ -  + ][ +  - ]:         77 :         CAST_TO(bodysm, OCCBody)->get_TopoDS_Shape(first_shape);
    5007         [ +  - ]:         77 :         revised_bodies.append(bodysm);
    5008         [ +  - ]:         77 :         revised_shapes.append(first_shape);
    5009         [ +  - ]:        185 :       }
    5010                 :            :     } 
    5011                 :            :   }
    5012                 :            : 
    5013 [ +  - ][ +  + ]:         87 :   if (revised_bodies.size() > 1)
    5014                 :            :   {
    5015         [ +  - ]:         32 :     revised_shapes.clean_out();
    5016         [ +  - ]:         32 :     is_volume.clean_out();
    5017                 :            :     stat =
    5018         [ +  - ]:         32 :         get_shape_list(revised_bodies, revised_shapes, is_volume, true);
    5019                 :            : 
    5020                 :            :     //simply make all bodies into a compound
    5021         [ +  - ]:         32 :     TopoDS_Compound Co ;
    5022                 :            :     BRep_Builder B;
    5023         [ +  - ]:         32 :     B.MakeCompound(Co);
    5024 [ +  - ][ +  + ]:        162 :     for(int i = 0; i < revised_shapes.size(); i++)
    5025 [ +  - ][ +  - ]:        130 :       B.Add(Co, *revised_shapes.get_and_step());
    5026                 :            : 
    5027 [ +  - ][ +  - ]:         32 :     BodySM* body = OCCQueryEngine::instance()->populate_topology_bridge(Co);
    5028         [ +  - ]:         32 :     if(body)
    5029         [ +  - ]:         32 :       newBodies.append(body);
    5030                 :            : 
    5031                 :            :     //delete all other individial bodies
    5032         [ +  - ]:         32 :     if(keep_old == false)
    5033 [ +  - ][ +  + ]:        162 :       for(int i = 0; i < revised_bodies.size(); i++)
    5034         [ +  - ]:        130 :         OCCQueryEngine::instance()->
    5035 [ +  - ][ +  - ]:        130 :           delete_solid_model_entities(revised_bodies.get_and_step());
    5036 [ +  - ][ +  - ]:         32 :     revised_bodies.clean_out();
    5037                 :            :   }
    5038                 :            : 
    5039 [ +  - ][ +  - ]:         55 :   else if(revised_bodies.size() == 1)
    5040         [ +  - ]:         55 :     newBodies = revised_bodies;
    5041         [ +  - ]:        174 :   return CUBIT_SUCCESS; 
    5042                 :            : }
    5043                 :            : 
    5044                 :          0 : CubitStatus OCCModifyEngine::thicken( DLIList<BodySM*>& bodies,
    5045                 :            :                                       DLIList<BodySM*>& new_bodies,
    5046                 :            :                                       double depth,
    5047                 :            :                                       CubitBoolean both) const
    5048                 :            : {
    5049 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    5050                 :          0 :   return CUBIT_FAILURE;
    5051                 :            : }
    5052                 :            : 
    5053                 :            : //===============================================================================
    5054                 :            : // Function   : hollow
    5055                 :            : // Member Type: PUBLIC
    5056                 :            : // Description: Hollow existing solid body by remove one or several surfaces 
    5057                 :            : //              Can only take one body at a time.
    5058                 :            : //              depth > 0, thick body going outside bodies
    5059                 :            : //              depth < 0, thick body going inside bodies
    5060                 :            : // Author     : Jane Hu 
    5061                 :            : // Date       : 06/08
    5062                 :            : //===============================================================================
    5063                 :          0 : CubitStatus OCCModifyEngine::hollow( DLIList<BodySM*>& bodies, 
    5064                 :            :                                      DLIList<Surface*>& surfs_to_remove,
    5065                 :            :                                      DLIList<BodySM*>& new_bodies,
    5066                 :            :                                      double depth) const
    5067                 :            : {
    5068 [ #  # ][ #  # ]:          0 :   if(bodies.size() != 1 || surfs_to_remove.size() < 1)
         [ #  # ][ #  # ]
                 [ #  # ]
    5069                 :            :   {
    5070 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Making thick solid in OCC will take one body and at least one surface at a time.\n"); 
         [ #  # ][ #  # ]
    5071                 :          0 :     return CUBIT_FAILURE;
    5072                 :            :   }
    5073                 :            : 
    5074         [ #  # ]:          0 :   DLIList<TopoDS_Shape*> shape_list;
    5075 [ #  # ][ #  # ]:          0 :   DLIList<CubitBoolean> is_volume;
    5076         [ #  # ]:          0 :   CubitStatus stat = get_shape_list(bodies, shape_list, is_volume, CUBIT_FALSE);
    5077                 :            : 
    5078         [ #  # ]:          0 :   if(!stat)
    5079                 :          0 :     return stat;
    5080                 :            : 
    5081 [ #  # ][ #  # ]:          0 :   if(!is_volume.get())//sheet body
                 [ #  # ]
    5082                 :            :   {
    5083 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Making thick solid in OCC needs an initial solid body to hollow with.\n");
         [ #  # ][ #  # ]
    5084                 :          0 :     return CUBIT_FAILURE;
    5085                 :            :   }
    5086                 :            : 
    5087                 :            :   //make sure the body to be hollowed has only one lump
    5088 [ #  # ][ #  # ]:          0 :   OCCBody* occ_body = CAST_TO(bodies.get(), OCCBody);
    5089 [ #  # ][ #  # ]:          0 :   DLIList<Lump*> lumps;
    5090 [ #  # ][ #  # ]:          0 :   DLIList<OCCSurface*> surfaces;
    5091 [ #  # ][ #  # ]:          0 :   DLIList<OCCShell*> shells;
    5092 [ #  # ][ #  # ]:          0 :   surfaces = occ_body->my_sheet_surfaces();
                 [ #  # ]
    5093 [ #  # ][ #  # ]:          0 :   shells = occ_body->shells();
                 [ #  # ]
    5094 [ #  # ][ #  # ]:          0 :   lumps = occ_body->lumps();
                 [ #  # ]
    5095 [ #  # ][ #  # ]:          0 :   if(lumps.size()!=1 || surfaces.size() != 0 || shells.size() != 0)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    5096                 :            :   {
    5097 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("bodies with more than one lump can't be hollowed to make a thick body.\n");
         [ #  # ][ #  # ]
    5098                 :          0 :     return CUBIT_FAILURE;
    5099                 :            :   }
    5100                 :            : 
    5101                 :            :   //make sure surfs_to_remove are all in bodies
    5102 [ #  # ][ #  # ]:          0 :   TopTools_ListOfShape face_shapes;
    5103         [ #  # ]:          0 :   occ_body->get_all_surfaces(surfaces);
    5104 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < surfs_to_remove.size(); i++)
    5105                 :            :   {
    5106 [ #  # ][ #  # ]:          0 :     OCCSurface* occ_surf = CAST_TO(surfs_to_remove.get(), OCCSurface);
    5107         [ #  # ]:          0 :     if(!occ_surf)
    5108                 :          0 :       continue;
    5109 [ #  # ][ #  # ]:          0 :     if(!surfaces.is_in_list(occ_surf))
    5110                 :          0 :       continue;
    5111         [ #  # ]:          0 :     TopoDS_Face * face = occ_surf->get_TopoDS_Face();
    5112         [ #  # ]:          0 :     face_shapes.Append(*face); 
    5113                 :            :   }
    5114                 :            : 
    5115 [ #  # ][ #  # ]:          0 :   if(face_shapes.IsEmpty())
    5116                 :            :   {
    5117 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("The surfaces provided should be from the body to be hollowed.\n");
         [ #  # ][ #  # ]
    5118                 :          0 :     return CUBIT_FAILURE;
    5119                 :            :   }
    5120                 :            :   
    5121                 :          0 :   double dTOL = 1.e-3; //hard coded for now, can be changed by application
    5122         [ #  # ]:          0 :   TopoDS_Shape* solid = shape_list.get();
    5123                 :            :   BRepOffsetAPI_MakeThickSolid hollower(*solid, face_shapes, depth, dTOL,
    5124                 :            :                                         BRepOffset_Skin, Standard_False,
    5125 [ #  # ][ #  # ]:          0 :                                         Standard_False, GeomAbs_Intersection);
    5126 [ #  # ][ #  # ]:          0 :   TopoDS_Shape new_shape = hollower.Shape();
                 [ #  # ]
    5127 [ #  # ][ #  # ]:          0 :   if(solid->ShapeType() == TopAbs_SOLID)
    5128                 :            :   {
    5129 [ #  # ][ #  # ]:          0 :     TopoDS_Solid old_solid = TopoDS::Solid(*solid);
    5130 [ #  # ][ #  # ]:          0 :     OCCLump::update_OCC_entity(old_solid , new_shape, &hollower); 
    5131                 :            :   }
    5132 [ #  # ][ #  # ]:          0 :   else if(solid->ShapeType() == TopAbs_COMPOUND)
    5133         [ #  # ]:          0 :     OCCBody::update_OCC_entity(*solid, new_shape, &hollower);
    5134                 :            :  
    5135                 :            :   //ok, we're done with all hollowing, construct new Body'
    5136 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> tbs;
    5137 [ #  # ][ #  # ]:          0 :   tbs += OCCQueryEngine::instance()->populate_topology_bridge(new_shape);
         [ #  # ][ #  # ]
    5138                 :            : 
    5139 [ #  # ][ #  # ]:          0 :   for (int i = 0; i< tbs.size(); i++)
    5140                 :            :   {
    5141 [ #  # ][ #  # ]:          0 :     BodySM* bodysm = CAST_TO(tbs.get_and_step(), BodySM);
    5142         [ #  # ]:          0 :     if (bodysm)
    5143         [ #  # ]:          0 :       new_bodies.append(bodysm);
    5144                 :            :   }
    5145                 :            : 
    5146         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    5147                 :            : }
    5148                 :            : 
    5149                 :            : 
    5150                 :            : //===============================================================================
    5151                 :            : // Function   : flip_normals
    5152                 :            : // Member Type: PUBLIC
    5153                 :            : // Description: 
    5154                 :            : // Author     : Jane Hu
    5155                 :            : // Date       : 06/08
    5156                 :            : //===============================================================================
    5157                 :          0 : CubitStatus OCCModifyEngine :: flip_normals( DLIList<Surface*>& face_list ) const
    5158                 :            : {
    5159                 :          0 :   return CUBIT_FAILURE;
    5160                 :            : /*
    5161                 :            :   DLIList<Surface*> surface_list;
    5162                 :            :   while (face_list.size())
    5163                 :            :   {
    5164                 :            :     OCCSurface* occ_surface = CAST_TO(face_list.pop(), OCCSurface);
    5165                 :            :     OCCShell* occ_shell = occ_surface->my_shell();
    5166                 :            :     DLIList<OCCSurface*> surfaces;
    5167                 :            :     surfaces.append(occ_surface);
    5168                 :            :     if(occ_shell) //find all surfaces in face_list that belong to this shell
    5169                 :            :     {
    5170                 :            :       int size = face_list.size();
    5171                 :            :       for ( int i = 0; i < size; i++)
    5172                 :            :       {
    5173                 :            :         occ_surface = CAST_TO(face_list.get(), OCCSurface); 
    5174                 :            :         if(occ_shell == occ_surface->my_shell())
    5175                 :            :           surfaces.append(CAST_TO(face_list.remove(),OCCSurface));
    5176                 :            :         else
    5177                 :            :           face_list.step();
    5178                 :            :       } 
    5179                 :            :       
    5180                 :            :       if (!occ_shell->is_sheet())
    5181                 :            :       {
    5182                 :            :         DLIList<OCCSurface*> memberSurfs = occ_shell->getMemberSurfaces();
    5183                 :            :         for (int i = 0; i < memberSurfs.size(); ++i)
    5184                 :            :         {
    5185                 :            :           occ_surface = memberSurfs.get_and_step();
    5186                 :            :           if(surfaces.is_in_list(occ_surface))
    5187                 :            :           {
    5188                 :            :             // would need to implement flipping the normal here
    5189                 :            :             surface_list.append(occ_surface);
    5190                 :            :           }
    5191                 :            :         }
    5192                 :            :       }
    5193                 :            :     }        
    5194                 :            :     if(!occ_shell || occ_shell->is_sheet()) //sheet body 
    5195                 :            :     {
    5196                 :            :       // would need to implement flipping the normal here
    5197                 :            :       surface_list.append(occ_surface);
    5198                 :            :       PRINT_INFO( "Modified volume\n" );
    5199                 :            :     }
    5200                 :            :   }
    5201                 :            :   face_list = surface_list;
    5202                 :            :   return CUBIT_SUCCESS;
    5203                 :            : */
    5204                 :            : }
    5205                 :            : 
    5206                 :            : 
    5207                 :            : //===============================================================================
    5208                 :            : // Function   : sweep_translational
    5209                 :            : // Member Type: PUBLIC
    5210                 :            : // Description: 
    5211                 :            : // Author     : Jane Hu
    5212                 :            : // Date       : 09/08
    5213                 :            : //===============================================================================
    5214                 :          0 : CubitStatus OCCModifyEngine::sweep_translational(
    5215                 :            :   DLIList<GeometryEntity*>& ref_ent_list,
    5216                 :            :   DLIList<BodySM*>& result_body_list,
    5217                 :            :   const CubitVector& sweep_vector,
    5218                 :            :   double draft_angle, //in Radius
    5219                 :            :   int draft_type, //RightCorner=1 or RoundCorner =2
    5220                 :            :   bool switchside,//not used, shell and surfaces are one sided, not like
    5221                 :            :   bool rigid, //not used here, in , it means whether the end surface is
    5222                 :            :               // parallel to the starting surface, or perpendicular to the path
    5223                 :            :   bool anchor_entity, //not used in OCC
    5224                 :            :   bool keep_old) const
    5225                 :            : {
    5226                 :            :   //in OCC, there's no sweep surface with draft option, this can be done by
    5227                 :            :   //creating draft shell then make solid to achieve.
    5228                 :            :   //while if draft_angle is 0, directly use sweep functions.
    5229                 :            : 
    5230 [ #  # ][ #  # ]:          0 :   gp_Dir adir(sweep_vector.x(), sweep_vector.y(), sweep_vector.z());
         [ #  # ][ #  # ]
    5231 [ #  # ][ #  # ]:          0 :   gp_Vec aVec(sweep_vector.x(), sweep_vector.y(), sweep_vector.z());
         [ #  # ][ #  # ]
    5232                 :            :  
    5233 [ #  # ][ #  # ]:          0 :   for (int i = ref_ent_list.size(); i > 0; i--)
    5234                 :            :   {
    5235         [ #  # ]:          0 :     GeometryEntity *ref_ent = ref_ent_list.get_and_step();
    5236                 :            :     //Make copy of the surface for later to build solid.
    5237         [ #  # ]:          0 :     OCCSurface* surface = CAST_TO(ref_ent, OCCSurface);
    5238         [ #  # ]:          0 :     TopoDS_Shape toposhape ;
    5239         [ #  # ]:          0 :     if(surface != NULL)
    5240                 :            :     {
    5241         [ #  # ]:          0 :       CubitStatus stat = get_sweepable_toposhape(surface, &sweep_vector, toposhape);   
    5242         [ #  # ]:          0 :       if(!stat)
    5243                 :          0 :         continue;
    5244                 :            :     }
    5245         [ #  # ]:          0 :     OCCCurve* curve = CAST_TO(ref_ent, OCCCurve);
    5246         [ #  # ]:          0 :     if(curve != NULL)
    5247                 :            :     {
    5248         [ #  # ]:          0 :       CubitStatus stat = get_sweepable_toposhape(curve, toposhape);
    5249         [ #  # ]:          0 :       if(!stat)
    5250                 :          0 :         continue;
    5251                 :            :     }
    5252                 :            :   
    5253 [ #  # ][ #  # ]:          0 :     DLIList<TopologyBridge*> tbs;
              [ #  #  # ]
    5254                 :            :     //create the draft or the sweep
    5255                 :          0 :     BodySM* bodysm = NULL;
    5256         [ #  # ]:          0 :     if( draft_angle == 0.)
    5257                 :            :     {
    5258         [ #  # ]:          0 :       BRepSweep_Prism swept(toposhape, aVec);
    5259 [ #  # ][ #  # ]:          0 :       TopoDS_Shape new_shape = swept.Shape();
    5260                 :            : 
    5261 [ #  # ][ #  # ]:          0 :       tbs += OCCQueryEngine::instance()->populate_topology_bridge(new_shape);
         [ #  # ][ #  # ]
    5262 [ #  # ][ #  # ]:          0 :       assert(tbs.size() == 1);
    5263                 :            : 
    5264 [ #  # ][ #  # ]:          0 :       bodysm = CAST_TO(tbs.get(), BodySM); 
                 [ #  # ]
    5265                 :            :     }
    5266                 :            : 
    5267                 :            :     else
    5268                 :            :     {
    5269         [ #  # ]:          0 :       BRepOffsetAPI_MakeDraft draft(toposhape, adir, draft_angle);
    5270                 :            :       BRepBuilderAPI_TransitionMode Cornertype;
    5271         [ #  # ]:          0 :       if(draft_type == 1)
    5272                 :          0 :         Cornertype = BRepBuilderAPI_RightCorner;
    5273                 :            :       else 
    5274                 :          0 :         Cornertype = BRepBuilderAPI_RoundCorner;
    5275                 :            : 
    5276         [ #  # ]:          0 :       draft.SetOptions(Cornertype);
    5277 [ #  # ][ #  # ]:          0 :       draft.Perform(sweep_vector.length());
    5278 [ #  # ][ #  # ]:          0 :       TopoDS_Shape new_shape = draft.Shape();
                 [ #  # ]
              [ #  #  # ]
    5279                 :            : 
    5280 [ #  # ][ #  # ]:          0 :       tbs += OCCQueryEngine::instance()->populate_topology_bridge(new_shape);
         [ #  # ][ #  # ]
    5281                 :            : 
    5282 [ #  # ][ #  # ]:          0 :       assert(tbs.size() == 1);
    5283                 :            : 
    5284 [ #  # ][ #  # ]:          0 :       bodysm = CAST_TO(tbs.get(), BodySM);
    5285 [ #  # ][ #  # ]:          0 :       if(bodysm && surface != NULL) //only gets swept side and original surfaces
    5286                 :            :       {
    5287                 :            :          //get surfaces from the shell body and create a top surface to
    5288                 :            :          //make a swept solid.
    5289 [ #  # ][ #  # ]:          0 :          DLIList<OCCShell*> shells = CAST_TO(bodysm, OCCBody)->shells();
    5290 [ #  # ][ #  # ]:          0 :          if(shells.size() == 0)
    5291                 :            :          {
    5292 [ #  # ][ #  # ]:          0 :            PRINT_WARNING("Sweep surface failed inside OCC engine.\n");
         [ #  # ][ #  # ]
    5293                 :          0 :            return CUBIT_FAILURE;
    5294                 :            :          }
    5295 [ #  # ][ #  # ]:          0 :          assert(shells.size() == 1);
    5296                 :            :          DLIList<OCCSurface*> memberSurfaces =
    5297 [ #  # ][ #  # ]:          0 :              shells.get()->getMemberSurfaces();
                 [ #  # ]
              [ #  #  # ]
    5298 [ #  # ][ #  # ]:          0 :          DLIList<Surface*> surface_list;
              [ #  #  # ]
    5299 [ #  # ][ #  # ]:          0 :          for (int i = 0; i < memberSurfaces.size(); ++i)
    5300 [ #  # ][ #  # ]:          0 :            surface_list.append(memberSurfaces.get_and_step());
    5301                 :            : 
    5302                 :            :          //create the top surface from edges.
    5303 [ #  # ][ #  # ]:          0 :          DLIList<OCCCoEdge*> coedges;
              [ #  #  # ]
    5304 [ #  # ][ #  # ]:          0 :          for(int i = 0; i < surface_list.size(); i++)
    5305 [ #  # ][ #  # ]:          0 :            CAST_TO(surface_list.get_and_step(), OCCSurface)->get_coedges(coedges);
                 [ #  # ]
    5306 [ #  # ][ #  # ]:          0 :          for(int i = 0; i < coedges.size(); i++)
    5307                 :            :          {
    5308         [ #  # ]:          0 :            OCCCoEdge* coedge = coedges[i];
    5309         [ #  # ]:          0 :            if(coedge == NULL)
    5310                 :          0 :              continue;
    5311 [ #  # ][ #  # ]:          0 :            for(int j = i+1; j < coedges.size(); j++)
    5312                 :            :            {
    5313         [ #  # ]:          0 :               OCCCoEdge* temp_coedge = coedges[j];
    5314         [ #  # ]:          0 :               if(temp_coedge == NULL)
    5315                 :          0 :                 continue; 
    5316 [ #  # ][ #  # ]:          0 :               if(coedge->curve() == temp_coedge->curve()) //Since the shell 
                 [ #  # ]
    5317                 :            :               // is open, the sense of curve can be either the same or opposite. 
    5318                 :            :               {
    5319         [ #  # ]:          0 :                 coedges.move_to(coedge);
    5320         [ #  # ]:          0 :                 coedges.change_to((OCCCoEdge*)NULL);
    5321         [ #  # ]:          0 :                 coedges.move_to(temp_coedge);
    5322         [ #  # ]:          0 :                 coedges.change_to((OCCCoEdge*)NULL);
    5323                 :            :               }
    5324                 :            :            }
    5325                 :            :          } 
    5326         [ #  # ]:          0 :          coedges.remove_all_with_value(NULL);
    5327 [ #  # ][ #  # ]:          0 :          assert(coedges.size() > 0);
    5328 [ #  # ][ #  # ]:          0 :          DLIList<Curve*> curves;
              [ #  #  # ]
    5329 [ #  # ][ #  # ]:          0 :          for(int i = 0; i < coedges.size(); i++)
    5330 [ #  # ][ #  # ]:          0 :            curves.append(coedges.get_and_step()->curve());
                 [ #  # ]
    5331                 :            : 
    5332         [ #  # ]:          0 :          Surface* surf = make_Surface(PLANE_SURFACE_TYPE, curves);
    5333         [ #  # ]:          0 :          if(!surf)
    5334         [ #  # ]:          0 :            surf = make_Surface(BEST_FIT_SURFACE_TYPE, curves);
    5335         [ #  # ]:          0 :          if(!surf)
    5336                 :            :          {
    5337 [ #  # ][ #  # ]:          0 :            PRINT_ERROR("Can't calculate for the top surface.\n");
         [ #  # ][ #  # ]
    5338                 :          0 :            continue;
    5339                 :            :          }
    5340         [ #  # ]:          0 :          surface_list.append(surf);
    5341 [ #  # ][ #  # ]:          0 :          DLIList<BodySM*> bodies;
              [ #  #  # ]
    5342         [ #  # ]:          0 :          create_solid_bodies_from_surfs(surface_list, bodies);
    5343                 :            : 
    5344 [ #  # ][ #  # ]:          0 :          if(bodies.size() == 1)
    5345         [ #  # ]:          0 :            bodysm = bodies.get();
    5346                 :            :          else
    5347                 :            :          {
    5348 [ #  # ][ #  # ]:          0 :            PRINT_WARNING("Sweep surface failed in creating solid.\n");
         [ #  # ][ #  # ]
    5349 [ #  # ][ #  # ]:          0 :            return CUBIT_FAILURE;
    5350         [ #  # ]:          0 :          }
              [ #  #  # ]
    5351                 :          0 :        }
    5352                 :            :     }
    5353 [ #  # ][ #  # ]:          0 :     if(bodysm && !keep_old && surface != NULL)
                 [ #  # ]
    5354                 :            :     {
    5355                 :            :       //have to unite the new geometry with the old one.
    5356         [ #  # ]:          0 :       DLIList<BodySM*> bodies;
    5357 [ #  # ][ #  # ]:          0 :       DLIList<OCCBody*> occ_bodies;
    5358         [ #  # ]:          0 :       surface->get_bodies(occ_bodies);
    5359 [ #  # ][ #  # ]:          0 :       if(occ_bodies.size() == 1)
    5360                 :            :       {
    5361         [ #  # ]:          0 :         OCCBody* old_body = occ_bodies.get();
    5362                 :            :         //delete sheet body if surface is standalong.
    5363 [ #  # ][ #  # ]:          0 :         if (old_body->is_sheet_body())
    5364                 :            :         {
    5365 [ #  # ][ #  # ]:          0 :           OCCQueryEngine::instance()->delete_solid_model_entities(old_body);
    5366         [ #  # ]:          0 :           result_body_list.append(bodysm);
    5367                 :            :         }
    5368                 :            :         else
    5369                 :            :         {
    5370         [ #  # ]:          0 :           bodies.append(CAST_TO(old_body, BodySM));
    5371         [ #  # ]:          0 :           bodies.append(bodysm);
    5372         [ #  # ]:          0 :           DLIList<BodySM*> newBodies;
    5373                 :          0 :           bool keep_old = CUBIT_FALSE;
    5374         [ #  # ]:          0 :           CubitStatus stat = unite(bodies, newBodies, keep_old);
    5375         [ #  # ]:          0 :           if(stat)
    5376 [ #  # ][ #  # ]:          0 :             result_body_list.append(newBodies.get());
                 [ #  # ]
    5377                 :            :         }
    5378         [ #  # ]:          0 :       }
    5379                 :            :     }
    5380         [ #  # ]:          0 :     else if (bodysm)
    5381 [ #  # ][ #  # ]:          0 :       result_body_list.append(bodysm);
              [ #  #  # ]
    5382                 :          0 :   }
    5383                 :          0 :   return CUBIT_SUCCESS; 
    5384                 :            : }
    5385                 :            : 
    5386                 :          0 : CubitStatus OCCModifyEngine::get_sweepable_toposhape(OCCCurve*& curve,
    5387                 :            :                                               TopoDS_Shape& toposhape)const
    5388                 :            : {
    5389         [ #  # ]:          0 :   TopoDS_Edge *edge = curve->get_TopoDS_Edge( );
    5390         [ #  # ]:          0 :   BRepBuilderAPI_Copy api_copy(*edge);
    5391 [ #  # ][ #  # ]:          0 :   toposhape = api_copy.ModifiedShape(*edge);
    5392 [ #  # ][ #  # ]:          0 :   TopoDS_Edge new_edge = TopoDS::Edge(toposhape);
                 [ #  # ]
    5393 [ #  # ][ #  # ]:          0 :   toposhape = BRepBuilderAPI_MakeWire(new_edge);
         [ #  # ][ #  # ]
                 [ #  # ]
    5394                 :            : 
    5395         [ #  # ]:          0 :   return CUBIT_SUCCESS; 
    5396                 :            : }
    5397                 :            : 
    5398                 :         11 : CubitStatus OCCModifyEngine::get_sweepable_toposhape(OCCSurface*& surface,
    5399                 :            :                                                   const CubitVector* sweep_v_p,
    5400                 :            :                                                   TopoDS_Shape& toposhape)const
    5401                 :            : {
    5402                 :         11 :   GeometryEntity* ref_ent = surface;
    5403                 :            : 
    5404         [ +  - ]:         11 :   if(surface != NULL)
    5405                 :            :   {
    5406                 :            :     //Make copy of the surface's topo_shape.
    5407                 :            :     TopoDS_Shape* toposhape_prt =
    5408 [ +  - ][ +  - ]:         11 :           OCCQueryEngine::instance()->get_TopoDS_Shape_of_entity(ref_ent);
    5409                 :            : 
    5410         [ -  + ]:         11 :     if(!toposhape_prt)
    5411                 :            :     {
    5412 [ #  # ][ #  # ]:          0 :       PRINT_WARNING("GeometryEntity without TopoDS_Shape found.\n");
         [ #  # ][ #  # ]
    5413                 :          0 :       return CUBIT_FAILURE;
    5414                 :            :     }
    5415                 :            : 
    5416         [ +  - ]:         11 :     BRepBuilderAPI_Copy api_copy(*toposhape_prt);
    5417 [ +  - ][ +  - ]:         11 :     toposhape = api_copy.ModifiedShape(*toposhape_prt);
    5418         [ -  + ]:         11 :     if(sweep_v_p)
    5419                 :            :     {
    5420         [ #  # ]:          0 :       CubitVector center = surface->center_point();
    5421         [ #  # ]:          0 :       CubitVector normal;
    5422         [ #  # ]:          0 :       surface->closest_point(center,NULL,&normal);
    5423         [ #  # ]:          0 :       CubitVector sweep_vector = *sweep_v_p;
    5424                 :            :       // TODO: Determine where there might be need to have the normal vector
    5425                 :            :       // in the opposite direction if normal % sweep_vector > 0
    5426 [ #  # ][ #  # ]:          0 :       if (normal % sweep_vector == 0)
    5427                 :            :       {
    5428 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Sweeping direction should not be on the surface.\n");
         [ #  # ][ #  # ]
    5429 [ +  - ][ +  - ]:         11 :         return CUBIT_FAILURE;
    5430                 :            :       }
    5431                 :         11 :     }
    5432                 :            :   }
    5433                 :         11 :   return CUBIT_SUCCESS;
    5434                 :            : }
    5435                 :            : //===============================================================================
    5436                 :            : // Member Type: PUBLIC
    5437                 :            : // Description: 
    5438                 :            : // Author     : Jane Hu
    5439                 :            : // Date       : 10/08
    5440                 :            : //===============================================================================
    5441                 :          0 : CubitStatus OCCModifyEngine::sweep_perpendicular(
    5442                 :            :   DLIList<GeometryEntity*>& ref_ent_list,
    5443                 :            :   DLIList<BodySM*>& result_body_list,
    5444                 :            :   double distance,
    5445                 :            :   double draft_angle,
    5446                 :            :   int draft_type,
    5447                 :            :   bool switchside, //has no effect
    5448                 :            :   bool rigid, //has no effect
    5449                 :            :   bool anchor_entity, //not used in OCC
    5450                 :            :   bool keep_old) const
    5451                 :            : {
    5452                 :            :   //find the vector perpendicular to the ref_ent normal, and sweep_translate
    5453                 :            :   //the 'distance' along this vector
    5454         [ #  # ]:          0 :   DLIList<GeometryEntity*> edge_list;
    5455         [ #  # ]:          0 :   CubitVector vec;
    5456 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < ref_ent_list.size(); i++)
    5457                 :            :   {
    5458         [ #  # ]:          0 :      GeometryEntity *ref_ent = ref_ent_list.get_and_step();
    5459         [ #  # ]:          0 :      Surface *face = CAST_TO(ref_ent, Surface);
    5460         [ #  # ]:          0 :      Curve* edge = CAST_TO(ref_ent, Curve);
    5461         [ #  # ]:          0 :      DLIList<GeometryEntity*> face_list;
    5462         [ #  # ]:          0 :      if(face != NULL)
    5463                 :            :      {
    5464         [ #  # ]:          0 :         OCCSurface* occ_face = CAST_TO(face, OCCSurface);
    5465         [ #  # ]:          0 :         CubitVector center = occ_face->center_point();
    5466 [ #  # ][ #  # ]:          0 :         CubitVector closest_p, unit_normal;
    5467                 :            :         CubitStatus stat = 
    5468         [ #  # ]:          0 :                     occ_face->closest_point(center, &closest_p, &unit_normal);
    5469         [ #  # ]:          0 :         if(stat)
    5470                 :            :         {
    5471 [ #  # ][ #  # ]:          0 :           vec = distance * unit_normal;
    5472         [ #  # ]:          0 :           face_list.append(ref_ent);
    5473                 :            :           stat = sweep_translational(face_list, result_body_list, vec, 
    5474                 :            :                                      draft_angle, draft_type, switchside,
    5475         [ #  # ]:          0 :                                      rigid, anchor_entity, keep_old);
    5476                 :            :        }
    5477                 :            :      }
    5478         [ #  # ]:          0 :      else if (edge != NULL)
    5479                 :            :      {
    5480         [ #  # ]:          0 :         edge_list.append(ref_ent);
    5481                 :            :      }
    5482         [ #  # ]:          0 :   }
    5483 [ #  # ][ #  # ]:          0 :   if(edge_list.size())
    5484 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Curves cannot be swept perpendicularly, please use the vector sweep.\n");
         [ #  # ][ #  # ]
    5485                 :            : 
    5486         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    5487                 :            : }
    5488                 :            : 
    5489                 :            : //===============================================================================
    5490                 :            : // Function   : sweep_rotational
    5491                 :            : // Member Type: PUBLIC
    5492                 :            : // Description: 
    5493                 :            : // Author     : Jane Hu 
    5494                 :            : // Date       : 10/08
    5495                 :            : //===============================================================================
    5496                 :         11 : CubitStatus OCCModifyEngine:: sweep_rotational(
    5497                 :            :   DLIList<GeometryEntity*>& ref_ent_list,
    5498                 :            :   DLIList<BodySM*>& result_body_list,
    5499                 :            :   const CubitVector& point,
    5500                 :            :   const CubitVector& direction,
    5501                 :            :   double angle, //in radians
    5502                 :            :   int steps,  //not used
    5503                 :            :   double draft_angle, //not used
    5504                 :            :   int draft_type,  //not used
    5505                 :            :   bool switchside, //not used
    5506                 :            :   bool make_solid,
    5507                 :            :   bool rigid,  //not used
    5508                 :            :   bool anchor_entity, //not used
    5509                 :            :   bool keep_old ) const  
    5510                 :            : {
    5511 [ +  - ][ +  - ]:         11 :   gp_Dir adir(direction.x(), direction.y(), direction.z()); 
         [ +  - ][ +  - ]
    5512 [ +  - ][ +  - ]:         11 :   gp_Pnt pt = gp_Pnt( point.x(), point.y(), point.z());
         [ +  - ][ +  - ]
    5513         [ +  - ]:         11 :   gp_Ax1 axis = gp_Ax1(pt, adir);
    5514                 :            : 
    5515         [ +  - ]:         11 :   gp_Lin line = gp_Lin(axis);
    5516 [ +  - ][ +  - ]:         11 :   TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(line);
                 [ +  - ]
    5517 [ +  - ][ +  - ]:         11 :   OCCCurve* acurve = CAST_TO(OCCQueryEngine::instance()->populate_topology_bridge(edge, CUBIT_TRUE), OCCCurve);
                 [ -  + ]
    5518         [ -  + ]:         11 :   assert(acurve);
    5519                 :            : 
    5520         [ +  - ]:         11 :   CubitVector start;
    5521         [ +  - ]:         11 :   CubitVector end;
    5522                 :            : 
    5523 [ +  - ][ +  + ]:         22 :   for (int i = ref_ent_list.size(); i > 0; i--)
    5524                 :            :   {
    5525         [ +  - ]:         11 :     GeometryEntity *ref_ent = ref_ent_list.get_and_step();
    5526                 :            :     //Make copy of the surface or curve for later to build solid.
    5527         [ -  + ]:         11 :     OCCSurface* surface = CAST_TO(ref_ent, OCCSurface);
    5528         [ -  + ]:         11 :     OCCCurve* curve = CAST_TO(ref_ent, OCCCurve);
    5529         [ +  - ]:         11 :     TopoDS_Shape toposhape ;
    5530         [ +  - ]:         11 :     if(surface != NULL)
    5531                 :            :     {
    5532         [ +  - ]:         11 :       CubitStatus stat = get_sweepable_toposhape(surface, (CubitVector*)NULL, toposhape);
    5533         [ -  + ]:         11 :       if(!stat)
    5534                 :          0 :         continue;
    5535                 :            :       //only non-intersecting of surface and axis can be swept.
    5536         [ +  - ]:         11 :       DLIList<CubitVector> intersect_pts;
    5537         [ +  - ]:         11 :       OCCQueryEngine::instance()->get_intersections(acurve, surface,
    5538         [ +  - ]:         11 :                                     intersect_pts, CUBIT_TRUE);
    5539 [ +  - ][ -  + ]:         11 :       if(intersect_pts.size() > 0)
    5540                 :            :       { 
    5541 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Only surfaces with no intersection point with the axis can be revolve-swept.\n");
         [ #  # ][ #  # ]
    5542 [ +  - ][ +  - ]:         11 :         continue;
    5543                 :         11 :       } 
    5544                 :            :     }
    5545         [ #  # ]:          0 :     else if(curve != NULL)
    5546                 :            :     {
    5547         [ #  # ]:          0 :       CubitStatus stat = get_sweepable_toposhape(curve, toposhape);
    5548         [ #  # ]:          0 :       if(!stat)
    5549                 :          0 :         continue;
    5550                 :            :       //closed curve can't intersect with the axis, while open curve can only
    5551                 :            :       //intersect the axis at the end points. 
    5552                 :            :       //only curve not intersecting with axis in curve's middle locations
    5553                 :            :       //can be revolved
    5554         [ #  # ]:          0 :       DLIList<CubitVector> intersect_pts;
    5555         [ #  # ]:          0 :       OCCQueryEngine::instance()->get_intersections(curve, acurve,
    5556         [ #  # ]:          0 :                                   intersect_pts, CUBIT_TRUE, CUBIT_TRUE);
    5557 [ #  # ][ #  # ]:          0 :       if(!toposhape.Closed())
    5558                 :            :       {
    5559                 :            :         //get start and end points
    5560         [ #  # ]:          0 :         DLIList<OCCPoint*> point_list;
    5561         [ #  # ]:          0 :         curve->get_points(point_list);
    5562 [ #  # ][ #  # ]:          0 :         assert(2 == point_list.size());
    5563         [ #  # ]:          0 :         GeometryType type = curve->geometry_type();
    5564 [ #  # ][ #  # ]:          0 :         start = point_list.get_and_step()->coordinates();
                 [ #  # ]
    5565 [ #  # ][ #  # ]:          0 :         end = point_list.get()->coordinates();
                 [ #  # ]
    5566                 :          0 :         CubitBoolean start_int = CUBIT_FALSE;
    5567                 :          0 :         CubitBoolean end_int = CUBIT_FALSE;
    5568 [ #  # ][ #  # ]:          0 :         if(intersect_pts.size() > 0)
    5569                 :            :         {
    5570                 :          0 :           CubitBoolean non_int = CUBIT_FALSE;
    5571 [ #  # ][ #  # ]:          0 :           for(int i = 0; i < intersect_pts.size(); i++)
    5572                 :            :           {
    5573         [ #  # ]:          0 :              CubitVector &prt = intersect_pts.get_and_step();
    5574 [ #  # ][ #  # ]:          0 :              if(prt.distance_between(start) > TOL &&
         [ #  # ][ #  # ]
    5575         [ #  # ]:          0 :                 prt.distance_between(end) > TOL)
    5576                 :            :              {
    5577                 :          0 :                 non_int = CUBIT_TRUE;
    5578 [ #  # ][ #  # ]:          0 :                 PRINT_ERROR("Only curves with no intersection point with the axis can be revolve-swept.\n");
         [ #  # ][ #  # ]
    5579                 :          0 :                 break;
    5580                 :            :              }
    5581 [ #  # ][ #  # ]:          0 :              else if(prt.distance_between(start) <= TOL)
    5582                 :          0 :                 start_int = CUBIT_TRUE;
    5583 [ #  # ][ #  # ]:          0 :              else if(prt.distance_between(end) <= TOL)
    5584                 :          0 :                 end_int = CUBIT_TRUE;
    5585                 :            :           }
    5586         [ #  # ]:          0 :           if(non_int)
    5587                 :          0 :             continue;
    5588 [ #  # ][ #  # ]:          0 :           if(start_int && end_int && type == STRAIGHT_CURVE_TYPE)
                 [ #  # ]
    5589                 :            :           {
    5590 [ #  # ][ #  # ]:          0 :             PRINT_ERROR("Sweep along curve itself is not allowed.\n");
         [ #  # ][ #  # ]
    5591 [ #  # ][ #  # ]:          0 :             continue;
    5592                 :            :           } 
    5593                 :          0 :         }
    5594                 :            :       }
    5595                 :            :       else
    5596                 :            :       {
    5597 [ #  # ][ #  # ]:          0 :         if(intersect_pts.size() > 0)
    5598                 :            :         {
    5599 [ #  # ][ #  # ]:          0 :           PRINT_ERROR("Only curves with no intersection point with the axis can be revolve-swept.\n");
         [ #  # ][ #  # ]
    5600 [ #  # ][ #  # ]:          0 :           continue;
    5601                 :            :         }  
    5602                 :          0 :       }
    5603                 :            :     } 
    5604                 :            :     else
    5605                 :            :     {
    5606 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Only surface or curve can be revolve-swept.\n");
         [ #  # ][ #  # ]
    5607                 :          0 :       continue;
    5608                 :            :     }
    5609 [ +  - ][ +  - ]:         22 :     TopoDS_Shape new_shape;
    5610 [ +  - ][ +  - ]:         22 :     DLIList<TopologyBridge*> tbs;
    5611 [ -  + ][ #  # ]:         11 :     if(make_solid && curve != NULL )
    5612                 :            :     //giving an open wire and want a solid
    5613                 :            :     {
    5614 [ #  # ][ #  # ]:          0 :       if(!toposhape.Closed())
    5615                 :            :       {
    5616                 :            :         //project the start and end points onto the axis
    5617                 :          0 :         CubitBoolean start_closed = CUBIT_FALSE;
    5618                 :          0 :         CubitBoolean end_closed = CUBIT_FALSE;
    5619 [ #  # ][ #  # ]:          0 :         if(acurve->point_containment(start) != CUBIT_PNT_OFF)
    5620                 :          0 :           start_closed = CUBIT_TRUE;
    5621 [ #  # ][ #  # ]:          0 :         if(acurve->point_containment(end) != CUBIT_PNT_OFF)
    5622                 :          0 :           end_closed = CUBIT_TRUE; 
    5623 [ #  # ][ #  # ]:          0 :         CubitVector start_proj, end_proj;
    5624 [ #  # ][ #  # ]:          0 :         TopoDS_Edge edge1, edge2;
                 [ #  # ]
    5625 [ #  # ][ #  # ]:          0 :         BRepBuilderAPI_MakeWire m_wire;
    5626         [ #  # ]:          0 :         if(!start_closed)
    5627                 :            :         {
    5628         [ #  # ]:          0 :           acurve->closest_point(start, start_proj);
    5629 [ #  # ][ #  # ]:          0 :           gp_Pnt pt1 = gp_Pnt( start.x(), start.y(), start.z()); 
         [ #  # ][ #  # ]
    5630 [ #  # ][ #  # ]:          0 :           gp_Pnt pt2 = gp_Pnt( start_proj.x(), start_proj.y(), start_proj.z());
         [ #  # ][ #  # ]
    5631 [ #  # ][ #  # ]:          0 :           edge1 = BRepBuilderAPI_MakeEdge(pt1, pt2);
         [ #  # ][ #  # ]
                 [ #  # ]
    5632         [ #  # ]:          0 :           m_wire.Add(edge1);
    5633 [ #  # ][ #  # ]:          0 :           m_wire.Add(TopoDS::Wire(toposhape));
    5634                 :            :         }
    5635                 :            :         else
    5636                 :            :         {
    5637 [ #  # ][ #  # ]:          0 :           m_wire.Add(TopoDS::Wire(toposhape));
    5638         [ #  # ]:          0 :           start_proj = start;
    5639                 :            :         }
    5640                 :            :  
    5641         [ #  # ]:          0 :         if(!end_closed)
    5642                 :            :         {
    5643         [ #  # ]:          0 :           acurve->closest_point(end,end_proj);
    5644 [ #  # ][ #  # ]:          0 :           gp_Pnt pt1 = gp_Pnt( end.x(), end.y(), end.z());
         [ #  # ][ #  # ]
    5645 [ #  # ][ #  # ]:          0 :           gp_Pnt pt2 = gp_Pnt( end_proj.x(), end_proj.y(), end_proj.z());
         [ #  # ][ #  # ]
    5646 [ #  # ][ #  # ]:          0 :           edge2 = BRepBuilderAPI_MakeEdge(pt1, pt2);
         [ #  # ][ #  # ]
                 [ #  # ]
    5647         [ #  # ]:          0 :           m_wire.Add(edge2);
    5648                 :            :         }
    5649                 :            :       
    5650                 :            :         else
    5651         [ #  # ]:          0 :           end_proj = end;
    5652                 :            :         
    5653 [ #  # ][ #  # ]:          0 :         gp_Pnt pt1 = gp_Pnt( end_proj.x(), end_proj.y(), end_proj.z());
         [ #  # ][ #  # ]
    5654 [ #  # ][ #  # ]:          0 :         gp_Pnt pt2 = gp_Pnt( start_proj.x(), start_proj.y(), start_proj.z());
         [ #  # ][ #  # ]
    5655 [ #  # ][ #  # ]:          0 :         TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge(pt2, pt1);
         [ #  # ][ #  # ]
    5656         [ #  # ]:          0 :         m_wire.Add(edge3);
    5657                 :            :       
    5658 [ #  # ][ #  # ]:          0 :         TopoDS_Wire wire = m_wire.Wire();
                 [ #  # ]
    5659 [ #  # ][ #  # ]:          0 :         toposhape = BRepBuilderAPI_MakeFace(wire);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    5660                 :            :       }
    5661                 :            :       else //closed
    5662                 :            :       {
    5663 [ #  # ][ #  # ]:          0 :         TopoDS_Wire wire = TopoDS::Wire(toposhape);
    5664 [ #  # ][ #  # ]:          0 :         toposhape = BRepBuilderAPI_MakeFace(wire);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    5665                 :            :       }
    5666                 :            :     }
    5667 [ +  - ][ +  - ]:         22 :     BRepSweep_Revol revol(toposhape, axis, angle);
    5668 [ +  - ][ +  - ]:         11 :     new_shape = revol.Shape();
                 [ +  - ]
    5669                 :            : 
    5670 [ +  - ][ +  - ]:         11 :     tbs += OCCQueryEngine::instance()->populate_topology_bridge(new_shape);
         [ +  - ][ +  - ]
    5671 [ +  - ][ -  + ]:         11 :     assert(tbs.size() == 1);
    5672                 :            : 
    5673 [ +  - ][ -  + ]:         11 :     BodySM* bodysm = CAST_TO(tbs.get(), BodySM);
    5674                 :            : 
    5675 [ +  - ][ +  - ]:         11 :     if(bodysm && !keep_old && surface != NULL)
                 [ +  - ]
    5676                 :            :     {
    5677                 :            :       //have to unite the new geometry with the old one.
    5678         [ +  - ]:         11 :       DLIList<BodySM*> bodies; 
    5679 [ +  - ][ +  - ]:         22 :       DLIList<OCCBody*> occ_bodies;
    5680         [ +  - ]:         11 :       surface->get_bodies(occ_bodies);
    5681 [ +  - ][ +  - ]:         11 :       if(occ_bodies.size() == 1)
    5682                 :            :       {
    5683         [ +  - ]:         11 :         OCCBody* old_body = occ_bodies.get();
    5684                 :            :         //delete sheet body if surface is standalong.
    5685 [ +  - ][ +  - ]:         11 :         if (old_body->is_sheet_body())
    5686                 :            :         {
    5687 [ +  - ][ +  - ]:         11 :           OCCQueryEngine::instance()->delete_solid_model_entities(old_body);
    5688         [ +  - ]:         11 :           result_body_list.append(bodysm);
    5689                 :            :         }
    5690                 :            :         else
    5691                 :            :         {
    5692         [ #  # ]:          0 :           bodies.append(CAST_TO(old_body, BodySM));
    5693         [ #  # ]:          0 :           bodies.append(bodysm);
    5694         [ #  # ]:          0 :           DLIList<BodySM*> newBodies;
    5695         [ #  # ]:          0 :           CubitStatus stat = unite(bodies, newBodies, CUBIT_FALSE);
    5696         [ #  # ]:          0 :           if(stat)
    5697 [ #  # ][ #  # ]:         11 :             result_body_list.append(newBodies.get());
                 [ #  # ]
    5698                 :            :         }
    5699         [ +  - ]:         11 :       }
    5700                 :            :     }
    5701         [ #  # ]:          0 :     else if (bodysm)
    5702         [ #  # ]:          0 :       result_body_list.append(bodysm);
    5703                 :         11 :     continue;
    5704         [ +  - ]:         11 :   }
    5705 [ +  - ][ +  - ]:         11 :   OCCQueryEngine::instance()->delete_solid_model_entities(acurve);
    5706 [ +  - ][ +  - ]:         11 :   if(result_body_list.size()>0)
    5707                 :         11 :     return CUBIT_SUCCESS;
    5708                 :            :   else 
    5709         [ +  - ]:         11 :     return CUBIT_FAILURE;
    5710                 :            : }
    5711                 :            : 
    5712                 :            : //===============================================================================
    5713                 :            : // Function   : sweep_along_curve
    5714                 :            : // Member Type: PUBLIC
    5715                 :            : // Description: The ref_edge_list must provide a list of curves which are
    5716                 :            : //              connected, and making G1 continuous wire.
    5717                 :            : // Author     : Jane Hu
    5718                 :            : // Date       : 10/08
    5719                 :            : //===============================================================================
    5720                 :          0 : CubitStatus OCCModifyEngine::sweep_along_curve(
    5721                 :            :   DLIList<GeometryEntity*>& ref_ent_list,
    5722                 :            :   DLIList<BodySM*>& result_body_list,
    5723                 :            :   DLIList<Curve*>& ref_edge_list,
    5724                 :            :   double draft_angle, //only used for straight curve case
    5725                 :            :   int draft_type, //only used for straight curve case
    5726                 :            :   bool rigid, //not used
    5727                 :            :   bool anchor_entity, //not used
    5728                 :            :   bool keep_old) const 
    5729                 :            : {
    5730                 :            :   //make wire out of ref_edge_list
    5731         [ #  # ]:          0 :   BRepBuilderAPI_MakeWire awire;
    5732 [ #  # ][ #  # ]:          0 :   TopTools_ListOfShape L;
    5733                 :          0 :   OCCCurve* occ_curve = NULL;
    5734                 :          0 :   GeometryType type = UNDEFINED_CURVE_TYPE;
    5735                 :          0 :   int num_curve = 0;
    5736 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < ref_edge_list.size(); i++)
    5737                 :            :   {
    5738         [ #  # ]:          0 :     Curve* curve = ref_edge_list.get_and_step();
    5739         [ #  # ]:          0 :     occ_curve = CAST_TO(curve, OCCCurve);
    5740         [ #  # ]:          0 :     if(!occ_curve)
    5741                 :          0 :       continue;
    5742         [ #  # ]:          0 :     TopoDS_Edge* topoedge = occ_curve->get_TopoDS_Edge( );
    5743         [ #  # ]:          0 :     BRepBuilderAPI_Copy api_copy(*topoedge);
    5744 [ #  # ][ #  # ]:          0 :     TopoDS_Shape newShape = api_copy.ModifiedShape(*topoedge);
                 [ #  # ]
    5745         [ #  # ]:          0 :     L.Append(newShape);
    5746         [ #  # ]:          0 :     type = occ_curve->geometry_type();
    5747                 :          0 :     num_curve++;
    5748         [ #  # ]:          0 :   }
    5749 [ #  # ][ #  # ]:          0 :   if(L.IsEmpty())
    5750                 :            :   {
    5751 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("There's no valid sweeping path.\n");
         [ #  # ][ #  # ]
    5752                 :          0 :     return CUBIT_FAILURE;
    5753                 :            :   }
    5754                 :            :   
    5755 [ #  # ][ #  # ]:          0 :   if(num_curve == 1 && type == STRAIGHT_CURVE_TYPE && draft_angle != 0.0)
                 [ #  # ]
    5756                 :            :   {
    5757         [ #  # ]:          0 :     DLIList<OCCPoint*> point_list;
    5758         [ #  # ]:          0 :     occ_curve->get_points(point_list);
    5759 [ #  # ][ #  # ]:          0 :     CubitVector v1 = point_list.get_and_step()->coordinates();
    5760 [ #  # ][ #  # ]:          0 :     CubitVector v2 = point_list.get()->coordinates();
    5761         [ #  # ]:          0 :     CubitVector sweep_vector = v2-v1;
    5762                 :            :     return sweep_translational(ref_ent_list,result_body_list,sweep_vector,
    5763                 :            :                                draft_angle, draft_type, CUBIT_FALSE, 
    5764 [ #  # ][ #  # ]:          0 :                                rigid, anchor_entity, keep_old); 
    5765                 :            :   }
    5766         [ #  # ]:          0 :   awire.Add(L);
    5767 [ #  # ][ #  # ]:          0 :   TopoDS_Wire wire;
    5768 [ #  # ][ #  # ]:          0 :   wire = awire.Wire();
    5769                 :            : 
    5770 [ #  # ][ #  # ]:          0 :   BRepTools_WireExplorer it(wire);
    5771                 :          0 :   int num_edges = 0;
    5772 [ #  # ][ #  # ]:          0 :   for(; it.More(); it.Next())
                 [ #  # ]
    5773                 :          0 :     num_edges++; 
    5774                 :            :   
    5775 [ #  # ][ #  # ]:          0 :   BRepLib_FuseEdges fuser(wire);
    5776         [ #  # ]:          0 :   fuser.SetConcatBSpl();
    5777         [ #  # ]:          0 :   fuser.Perform();
    5778 [ #  # ][ #  # ]:          0 :   TopoDS_Shape  spline = fuser.Shape();
                 [ #  # ]
    5779 [ #  # ][ #  # ]:          0 :   wire = TopoDS::Wire(spline);
    5780                 :            : 
    5781 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> tbs;
    5782 [ #  # ][ #  # ]:          0 :   for (int i = ref_ent_list.size(); i > 0; i--)
    5783                 :            :   {
    5784         [ #  # ]:          0 :     GeometryEntity *ref_ent = ref_ent_list.get_and_step();
    5785                 :            :     //Make copy of the surface or curve for later to build solid.
    5786         [ #  # ]:          0 :     OCCSurface* surface = CAST_TO(ref_ent, OCCSurface);
    5787         [ #  # ]:          0 :     OCCCurve* curve = CAST_TO(ref_ent, OCCCurve);
    5788         [ #  # ]:          0 :     TopoDS_Shape toposhape ;
    5789         [ #  # ]:          0 :     if(surface != NULL)
    5790                 :            :     {
    5791         [ #  # ]:          0 :       CubitStatus stat = get_sweepable_toposhape(surface, (CubitVector*)NULL, toposhape);
    5792         [ #  # ]:          0 :       if(!stat)
    5793                 :          0 :         continue;
    5794                 :            :     } 
    5795         [ #  # ]:          0 :     else if(curve != NULL)
    5796                 :            :     {
    5797         [ #  # ]:          0 :       CubitStatus stat = get_sweepable_toposhape(curve, toposhape);
    5798         [ #  # ]:          0 :       if(!stat)
    5799                 :          0 :         continue;
    5800                 :            :     }
    5801                 :            : 
    5802                 :            :     //sweep along the wire
    5803 [ #  # ][ #  # ]:          0 :     BRepOffsetAPI_MakePipe maker(wire, toposhape);
                 [ #  # ]
    5804 [ #  # ][ #  # ]:          0 :     if(!maker.IsDone())
    5805                 :            :     {
    5806 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Can't sweep along the provided curve(s).\n");
         [ #  # ][ #  # ]
    5807                 :          0 :       continue;
    5808                 :            :     }
    5809 [ #  # ][ #  # ]:          0 :     TopoDS_Shape newShape = maker.Shape();
         [ #  # ][ #  # ]
                 [ #  # ]
    5810                 :            :     
    5811 [ #  # ][ #  # ]:          0 :     tbs += OCCQueryEngine::instance()->populate_topology_bridge(newShape);
         [ #  # ][ #  # ]
    5812 [ #  # ][ #  # ]:          0 :     assert(tbs.size() == 1);
    5813                 :            : 
    5814 [ #  # ][ #  # ]:          0 :     BodySM* bodysm = CAST_TO(tbs.get(), BodySM);
    5815                 :            : 
    5816 [ #  # ][ #  # ]:          0 :     if(bodysm && !keep_old && surface != NULL)
                 [ #  # ]
    5817                 :            :     {
    5818                 :            :       //have to unite the new geometry with the old one.
    5819         [ #  # ]:          0 :       DLIList<BodySM*> bodies;
    5820 [ #  # ][ #  # ]:          0 :       DLIList<OCCBody*> occ_bodies;
    5821         [ #  # ]:          0 :       surface->get_bodies(occ_bodies);
    5822 [ #  # ][ #  # ]:          0 :       if(occ_bodies.size() == 1)
    5823                 :            :       {
    5824         [ #  # ]:          0 :         OCCBody* old_body = occ_bodies.get();
    5825                 :            :         //delete sheet body if surface is standalong.
    5826 [ #  # ][ #  # ]:          0 :         if (old_body->is_sheet_body())
    5827                 :            :         {
    5828 [ #  # ][ #  # ]:          0 :           OCCQueryEngine::instance()->delete_solid_model_entities(old_body);
    5829         [ #  # ]:          0 :           result_body_list.append(bodysm);
    5830                 :            :         }
    5831                 :            :         else
    5832                 :            :         {
    5833         [ #  # ]:          0 :           bodies.append(CAST_TO(old_body, BodySM));
    5834         [ #  # ]:          0 :           bodies.append(bodysm);
    5835         [ #  # ]:          0 :           DLIList<BodySM*> newBodies;
    5836         [ #  # ]:          0 :           CubitStatus stat = unite(bodies, newBodies, CUBIT_FALSE);
    5837         [ #  # ]:          0 :           if(stat)
    5838 [ #  # ][ #  # ]:          0 :             result_body_list.append(newBodies.get());
                 [ #  # ]
    5839                 :            :         }
    5840         [ #  # ]:          0 :       }
    5841                 :            :     }
    5842         [ #  # ]:          0 :     else if (bodysm)
    5843         [ #  # ]:          0 :       result_body_list.append(bodysm);
    5844                 :          0 :   }
    5845         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    5846                 :            : }
    5847                 :            : 
    5848                 :          0 : CubitStatus OCCModifyEngine::sweep_to_body(
    5849                 :            :                                    DLIList<Curve*> curve_list,
    5850                 :            :                                    BodySM *target_body,
    5851                 :            :                                    CubitVector sweep_vector,
    5852                 :            :                                    DLIList<BodySM*> &new_bodies,
    5853                 :            :                                    bool unite) const
    5854                 :            : {
    5855                 :          0 :   TopoDS_Shape *stop_shape = NULL;
    5856         [ #  # ]:          0 :   OCCBody* occ_body = CAST_TO(target_body, OCCBody);
    5857         [ #  # ]:          0 :   occ_body->get_TopoDS_Shape(stop_shape);
    5858                 :            : 
    5859 [ #  # ][ #  # ]:          0 :   gp_Dir adir(sweep_vector.x(), sweep_vector.y(), sweep_vector.z());
         [ #  # ][ #  # ]
    5860                 :            : 
    5861         [ #  # ]:          0 :   DLIList<BodySM*> swept_bodies;
    5862 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < curve_list.size(); i++)
    5863                 :            :   {
    5864 [ #  # ][ #  # ]:          0 :     OCCCurve* curve = CAST_TO(curve_list.get_and_step(), OCCCurve);
    5865         [ #  # ]:          0 :     TopoDS_Shape toposhape ;
    5866         [ #  # ]:          0 :     CubitStatus stat = get_sweepable_toposhape(curve, toposhape);
    5867         [ #  # ]:          0 :     if(!stat)
    5868                 :          0 :       continue;
    5869 [ #  # ][ #  # ]:          0 :     BRepOffsetAPI_MakeDraft draft(toposhape, adir, 0.0);
         [ #  # ][ #  # ]
    5870         [ #  # ]:          0 :     draft.Perform(*stop_shape);
    5871 [ #  # ][ #  # ]:          0 :     TopoDS_Shape new_shape = draft.Shape();
                 [ #  # ]
    5872 [ #  # ][ #  # ]:          0 :     DLIList<TopologyBridge*> tbs;
    5873 [ #  # ][ #  # ]:          0 :     tbs = OCCQueryEngine::instance()->populate_topology_bridge(new_shape);
         [ #  # ][ #  # ]
    5874 [ #  # ][ #  # ]:          0 :     assert(tbs.size() == 1); 
    5875 [ #  # ][ #  # ]:          0 :     BodySM* bodysm = CAST_TO(tbs.get(), BodySM);
    5876         [ #  # ]:          0 :     if (bodysm)
    5877         [ #  # ]:          0 :       swept_bodies.append(bodysm);
    5878                 :          0 :   }
    5879         [ #  # ]:          0 :   if(unite)
    5880         [ #  # ]:          0 :     return this->unite(swept_bodies, new_bodies, CUBIT_FALSE);
    5881         [ #  # ]:          0 :   new_bodies += swept_bodies;
    5882         [ #  # ]:          0 :   return CUBIT_SUCCESS; 
    5883                 :            : }
    5884                 :            : 
    5885                 :          0 : CubitStatus OCCModifyEngine::sweep_to_body(
    5886                 :            :                                    Surface  *source_surface,
    5887                 :            :                                    BodySM *target_body,
    5888                 :            :                                    CubitVector sweep_vector,
    5889                 :            :                                    DLIList<BodySM*> &new_bodies ) const
    5890                 :            : {
    5891                 :          0 :   TopoDS_Shape *stop_shape = NULL;
    5892         [ #  # ]:          0 :   OCCBody* occ_body = CAST_TO(target_body, OCCBody);
    5893         [ #  # ]:          0 :   occ_body->get_TopoDS_Shape(stop_shape);
    5894                 :            : 
    5895 [ #  # ][ #  # ]:          0 :   gp_Dir adir(sweep_vector.x(), sweep_vector.y(), sweep_vector.z());
         [ #  # ][ #  # ]
    5896                 :            : 
    5897         [ #  # ]:          0 :   DLIList<BodySM*> swept_bodies;
    5898         [ #  # ]:          0 :   OCCSurface* surf = CAST_TO(source_surface, OCCSurface);
    5899 [ #  # ][ #  # ]:          0 :   TopoDS_Shape toposhape ;
    5900         [ #  # ]:          0 :   CubitStatus stat = get_sweepable_toposhape(surf, &sweep_vector, toposhape); 
    5901         [ #  # ]:          0 :   if(!stat)
    5902                 :          0 :     return CUBIT_FAILURE;
    5903 [ #  # ][ #  # ]:          0 :   BRepOffsetAPI_MakeDraft draft(toposhape, adir, 0.0);
    5904         [ #  # ]:          0 :   draft.Perform(*stop_shape);
    5905 [ #  # ][ #  # ]:          0 :   TopoDS_Shape new_shape = draft.Shape();
                 [ #  # ]
    5906 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> tbs;
    5907 [ #  # ][ #  # ]:          0 :   tbs = OCCQueryEngine::instance()->populate_topology_bridge(new_shape);
         [ #  # ][ #  # ]
    5908 [ #  # ][ #  # ]:          0 :   assert(tbs.size() == 1);
    5909 [ #  # ][ #  # ]:          0 :   BodySM* bodysm = CAST_TO(tbs.get(), BodySM);
    5910                 :            :   //get surfaces from the shell body and create a top surface to
    5911                 :            :   //make a swept solid.
    5912 [ #  # ][ #  # ]:          0 :   DLIList<OCCShell*> shells = CAST_TO(bodysm, OCCBody)->shells();
                 [ #  # ]
    5913 [ #  # ][ #  # ]:          0 :   if(shells.size() == 0)
    5914                 :            :   {
    5915 [ #  # ][ #  # ]:          0 :     PRINT_WARNING("Sweep surface failed inside OCC engine.\n");
         [ #  # ][ #  # ]
    5916                 :          0 :     return CUBIT_FAILURE;
    5917                 :            :   }
    5918 [ #  # ][ #  # ]:          0 :   assert(shells.size() == 1);
    5919 [ #  # ][ #  # ]:          0 :   DLIList<OCCSurface*> memberSurfaces = shells.get()->getMemberSurfaces();
                 [ #  # ]
    5920 [ #  # ][ #  # ]:          0 :   DLIList<Surface*> surface_list;
    5921 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < memberSurfaces.size(); ++i)
    5922 [ #  # ][ #  # ]:          0 :     surface_list.append(memberSurfaces.get_and_step());
    5923                 :            : 
    5924                 :            :   //create the top surface from edges.
    5925 [ #  # ][ #  # ]:          0 :   DLIList<OCCCoEdge*> coedges;
    5926 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < surface_list.size(); i++)
    5927 [ #  # ][ #  # ]:          0 :     CAST_TO(surface_list.get_and_step(), OCCSurface)->get_coedges(coedges);
                 [ #  # ]
    5928 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < coedges.size(); i++)
    5929                 :            :   {
    5930         [ #  # ]:          0 :     OCCCoEdge* coedge = coedges[i];
    5931         [ #  # ]:          0 :     if(coedge == NULL)
    5932                 :          0 :       continue;
    5933 [ #  # ][ #  # ]:          0 :     for(int j = i+1; j < coedges.size(); j++)
    5934                 :            :     {
    5935         [ #  # ]:          0 :       OCCCoEdge* temp_coedge = coedges[j];
    5936         [ #  # ]:          0 :       if(temp_coedge == NULL)
    5937                 :          0 :         continue;
    5938 [ #  # ][ #  # ]:          0 :       if(coedge->curve() == temp_coedge->curve()) //Since the shell
                 [ #  # ]
    5939                 :            :       // is open, the sense of curve can be either the same or opposite.
    5940                 :            :       {
    5941         [ #  # ]:          0 :          coedges.move_to(coedge);
    5942         [ #  # ]:          0 :          coedges.change_to((OCCCoEdge*)NULL);
    5943         [ #  # ]:          0 :          coedges.move_to(temp_coedge);
    5944         [ #  # ]:          0 :          coedges.change_to((OCCCoEdge*)NULL);
    5945                 :            :        }
    5946                 :            :     }
    5947                 :            :   }
    5948         [ #  # ]:          0 :   coedges.remove_all_with_value(NULL);
    5949 [ #  # ][ #  # ]:          0 :   assert(coedges.size() > 0);
    5950 [ #  # ][ #  # ]:          0 :   DLIList<Curve*> curves;
    5951 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < coedges.size(); i++)
    5952 [ #  # ][ #  # ]:          0 :     curves.append(coedges.get_and_step()->curve());
                 [ #  # ]
    5953                 :            : 
    5954         [ #  # ]:          0 :   Surface* surface = make_Surface(PLANE_SURFACE_TYPE, curves);
    5955         [ #  # ]:          0 :   if(!surface)
    5956         [ #  # ]:          0 :     surface = make_Surface(BEST_FIT_SURFACE_TYPE, curves);
    5957         [ #  # ]:          0 :   if(!surface)
    5958                 :            :   {
    5959 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't calculate for the top surface.\n");
         [ #  # ][ #  # ]
    5960                 :          0 :     return CUBIT_FAILURE;
    5961                 :            :   }
    5962         [ #  # ]:          0 :   surface_list.append(surface);
    5963 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> bodies;
    5964         [ #  # ]:          0 :     create_solid_bodies_from_surfs(surface_list, bodies);
    5965                 :            : 
    5966 [ #  # ][ #  # ]:          0 :   if(bodies.size() == 1)
    5967         [ #  # ]:          0 :     bodysm = bodies.get();
    5968                 :            :   else
    5969                 :            :   {
    5970 [ #  # ][ #  # ]:          0 :     PRINT_WARNING("Sweep surface failed in creating solid.\n");
         [ #  # ][ #  # ]
    5971                 :          0 :     return CUBIT_FAILURE;
    5972                 :            :   }
    5973         [ #  # ]:          0 :   if (bodysm)
    5974         [ #  # ]:          0 :     new_bodies.append(bodysm);
    5975         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    5976                 :            : }
    5977                 :            : 
    5978                 :            : //HEADER- Webcut-related functions
    5979                 :            : 
    5980                 :            : //===============================================================================
    5981                 :            : // Function   : webcut
    5982                 :            : // Member Type: PUBLIC
    5983                 :            : // Description: 
    5984                 :            : // Author     : Jane Hu
    5985                 :            : // Date       : 12/08
    5986                 :            : //===============================================================================
    5987                 :         11 : CubitStatus OCCModifyEngine::webcut(DLIList<BodySM*>& webcut_body_list,
    5988                 :            :                               const CubitVector &v1,
    5989                 :            :                               const CubitVector &v2,
    5990                 :            :                               const CubitVector &v3,
    5991                 :            :                               DLIList<BodySM*>& neighbor_imprint_list,
    5992                 :            :                               DLIList<BodySM*>& results_list,
    5993                 :            :                               ImprintType imprint_type,
    5994                 :            :                               bool preview ) const
    5995                 :            : {
    5996                 :            :   CubitStatus stat;
    5997         [ +  - ]:         11 :   DLIList<BodySM*> new_BodySMs;
    5998                 :            : 
    5999         [ -  + ]:         11 :   if(preview)
    6000                 :            :   {
    6001                 :            :     TopoDS_Face* p_face;
    6002         [ #  # ]:          0 :     stat = get_3_point_plane(v1, v2, v3, p_face);
    6003         [ #  # ]:          0 :     if(!stat)
    6004                 :          0 :       return stat;
    6005         [ #  # ]:          0 :     GfxPreview::clear();
    6006 [ #  # ][ #  # ]:          0 :     OCCDrawTool::instance()->draw_TopoDS_Shape(p_face, CUBIT_BLUE_INDEX, CUBIT_TRUE);
    6007 [ #  # ][ #  # ]:          0 :     delete p_face;
                 [ #  # ]
    6008                 :          0 :     p_face = NULL;
    6009                 :          0 :     return CUBIT_SUCCESS;
    6010                 :            :   }
    6011                 :            : 
    6012 [ +  - ][ +  - ]:         11 :   stat = OCCModifyEngine::instance()->section(webcut_body_list, v1, v2, v3, new_BodySMs, true, true,false);
    6013         [ -  + ]:         11 :   if(stat == CUBIT_FAILURE)
    6014                 :            :   {
    6015 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't webcut the bodies using a plane determined by 3 points.\n");
         [ #  # ][ #  # ]
    6016                 :          0 :     return stat;
    6017                 :            :   }
    6018                 :            :   
    6019 [ +  - ][ +  - ]:         11 :   stat = OCCModifyEngine::instance()->section(webcut_body_list, v1, v2, v3, new_BodySMs, false, false, false);
    6020         [ -  + ]:         11 :   if(stat == CUBIT_FAILURE)
    6021                 :            :   {
    6022 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't webcut the bodies using a plane determined by 3 points.\n");
         [ #  # ][ #  # ]
    6023                 :          0 :     return stat;
    6024                 :            :   }
    6025                 :            : 
    6026                 :            :   BodySM* new_body1, *new_body2;
    6027         [ +  - ]:         11 :   if(imprint_type > NO_IMPRINT)
    6028                 :            :   {
    6029 [ +  - ][ +  + ]:         22 :     for(int i = 0; i < new_BodySMs.size()-1; i ++)
    6030                 :            :     {
    6031         [ +  - ]:         11 :       BodySM* body1 = new_BodySMs[i];
    6032 [ +  - ][ +  + ]:         22 :       for(int j = i+1; j < new_BodySMs.size(); j++)
    6033                 :            :       {
    6034         [ +  - ]:         11 :         BodySM* body2 = new_BodySMs[j];
    6035         [ +  - ]:         11 :         stat =  this->imprint( body1, body2, new_body1, new_body2, false);
    6036 [ -  + ][ #  # ]:         11 :         if(new_body1 && body1 != new_body1)
    6037         [ #  # ]:          0 :           new_BodySMs[i] = new_body1;
    6038 [ -  + ][ #  # ]:         11 :         if(new_body2 && body2 != new_body2)
    6039         [ #  # ]:          0 :           new_BodySMs[j] = new_body2; 
    6040                 :            :       }
    6041                 :            :     }
    6042                 :            :   }
    6043                 :            : 
    6044         [ +  - ]:         11 :   results_list = new_BodySMs;
    6045                 :            : 
    6046                 :            :   //now imprint with the neighbors
    6047         [ -  + ]:         11 :   if( imprint_type == INCLUDE_NEIGHBORS  )
    6048                 :            :   {
    6049                 :            :     // Loop over all the neighboring Bodies
    6050 [ #  # ][ #  # ]:          0 :     DLIList<TopoDS_Shape*> shape_list1, shape_list2;
         [ #  # ][ #  # ]
    6051 [ #  # ][ #  # ]:          0 :     DLIList<CubitBoolean> is_volume;
                 [ #  # ]
    6052         [ #  # ]:          0 :     stat = get_shape_list(neighbor_imprint_list,shape_list1,is_volume,false);
    6053         [ #  # ]:          0 :     if (!stat)
    6054                 :            :     {
    6055 [ #  # ][ #  # ]:          0 :         PRINT_WARNING("Can't imprint using neighouring bodies.\n");
         [ #  # ][ #  # ]
    6056                 :          0 :         return CUBIT_SUCCESS;
    6057                 :            :     }    
    6058         [ #  # ]:          0 :     is_volume.clean_out();
    6059                 :            : 
    6060         [ #  # ]:          0 :     stat = get_shape_list(new_BodySMs,shape_list2,is_volume,false);
    6061                 :            :     { 
    6062 [ #  # ][ #  # ]:          0 :         PRINT_WARNING("Can't imprint using neighouring bodies.\n");
         [ #  # ][ #  # ]
    6063 [ #  # ][ #  # ]:          0 :         return CUBIT_SUCCESS;
    6064                 :            :     }
    6065                 :            :     // Loop over all the neighboring shapes
    6066                 :            :     DLIList<TopoDS_Face*> face_list;
    6067                 :            :     for (int i=shape_list1.size(); i--;)
    6068                 :            :     {
    6069                 :            :       TopoDS_Shape *neighbor_shape = shape_list1.get_and_step() ;
    6070                 :            :       for(int j = 0; j < shape_list2.size(); j ++)
    6071                 :            :       {
    6072                 :            :         TopoDS_Shape* shape2 = shape_list2[j];
    6073                 :            :         int result =  this->imprint_toposhapes( shape2, neighbor_shape,
    6074                 :            :                       face_list);
    6075                 :            :         if(result == 0)
    6076                 :            :           shape_list2[j] = shape2;   
    6077                 :            :       }
    6078                 :            :     }
    6079                 :            : 
    6080                 :            :     DLIList<TopologyBridge*> tbs;
    6081                 :            :     results_list.clean_out();
    6082                 :            :     for(int j = 0; j < shape_list2.size(); j ++)
    6083                 :            :     {
    6084                 :            :       TopoDS_Shape* shape2 = shape_list2[j];
    6085                 :            :         
    6086                 :            :       tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape2);
    6087                 :            :       BodySM* newBody1 = CAST_TO(tbs.get(),BodySM);
    6088                 :            :       results_list.append(newBody1);    
    6089                 :          0 :     }
    6090                 :            :   }
    6091                 :            : 
    6092         [ +  - ]:         11 :   return CUBIT_SUCCESS;  
    6093                 :            : }
    6094                 :            : 
    6095                 :            : //===============================================================================
    6096                 :            : // Function   : webcuts a list of bodies using another Body as the tool.
    6097                 :            : // Member Type: PUBLIC
    6098                 :            : // Description: 
    6099                 :            : // Author     : Jane Hu
    6100                 :            : // Date       : 01/09
    6101                 :            : //===============================================================================
    6102                 :         11 : CubitStatus    OCCModifyEngine::webcut(DLIList<BodySM*>& webcut_body_list,
    6103                 :            :                                 BodySM const* tool_body,
    6104                 :            :                                 DLIList<BodySM*>& neighbor_imprint_list,
    6105                 :            :                                 DLIList<BodySM*>& results_list,
    6106                 :            :                                 ImprintType imprint_type,
    6107                 :            :                                 bool preview ) const
    6108                 :            : {
    6109                 :            :   // tool_body and webct_body_list will be kept and webcut result is in 
    6110                 :            :   //results_list.
    6111                 :            :   //tool_body is a const pointer points to varible BodySM object
    6112                 :            :   //here trying to create a non-const pointer points to the same BodySM object.
    6113                 :            : 
    6114                 :         11 :   BodySM *body = const_cast<BodySM*>(tool_body);
    6115                 :            :   CubitStatus stat;
    6116         [ +  - ]:         11 :   DLIList<BodySM*> tool_bodies;
    6117         [ -  + ]:         11 :   if(preview)
    6118         [ #  # ]:          0 :     tool_bodies.append(body);
    6119                 :            : 
    6120         [ +  - ]:         11 :   BodySM *copy_tool = copy_body(body);
    6121                 :            :  
    6122         [ +  - ]:         11 :   if(!preview)
    6123         [ +  - ]:         11 :     tool_bodies.append(copy_tool);
    6124                 :            : 
    6125                 :            :   // preview the tool
    6126         [ -  + ]:         11 :   if (preview)
    6127                 :            :   {
    6128         [ #  # ]:          0 :     DLIList<TopoDS_Shape*> shape_list;
    6129 [ #  # ][ #  # ]:          0 :     DLIList<CubitBoolean> is_volume;
    6130         [ #  # ]:          0 :     stat = get_shape_list(tool_bodies,shape_list,is_volume,false);
    6131         [ #  # ]:          0 :     if(!stat)
    6132                 :            :     {
    6133 [ #  # ][ #  # ]:          0 :         PRINT_WARNING("tool_body is not an OCC body.\n");
         [ #  # ][ #  # ]
    6134                 :          0 :         return CUBIT_FAILURE;
    6135                 :            :     }
    6136         [ #  # ]:          0 :     GfxPreview::clear();
    6137         [ #  # ]:          0 :     OCCDrawTool::instance()->draw_TopoDS_Shape(shape_list.get(), 
    6138 [ #  # ][ #  # ]:          0 :                              CUBIT_BLUE_INDEX, CUBIT_TRUE);
    6139                 :            : 
    6140         [ #  # ]:          0 :     return CUBIT_SUCCESS;
    6141                 :            :   }
    6142                 :            : 
    6143                 :            :   //if the tool_body is a volume, use intersect & subtract,
    6144                 :            :   //if it's a shell or face body, use section then.
    6145         [ -  + ]:         11 :   OCCBody* occ_body = CAST_TO(body, OCCBody);
    6146 [ +  - ][ +  - ]:         22 :   DLIList<Lump*> lumps;
    6147 [ +  - ][ +  - ]:         11 :   lumps = occ_body->lumps();
                 [ +  - ]
    6148 [ +  - ][ +  - ]:         22 :   DLIList<OCCShell*> shells;
    6149 [ +  - ][ +  - ]:         11 :   shells = occ_body->shells();
                 [ +  - ]
    6150 [ +  - ][ +  - ]:         22 :   DLIList<OCCSurface*> surfaces;
    6151 [ +  - ][ +  - ]:         11 :   surfaces = occ_body->my_sheet_surfaces();
                 [ +  - ]
    6152                 :            : 
    6153 [ +  - ][ -  + ]:         11 :   if(lumps.size() == 0 && (shells.size()==1 || surfaces.size() == 1))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ -  + ]
    6154                 :            :   {
    6155                 :          0 :     OCCSurface * surface = NULL;
    6156                 :          0 :     TopoDS_Shell* topo_shell = NULL;
    6157                 :          0 :     TopoDS_Face *topo_face = NULL;
    6158 [ #  # ][ #  # ]:          0 :     if(shells.size() == 1)
    6159                 :            :     {
    6160         [ #  # ]:          0 :       OCCShell* shell = shells.get();
    6161 [ #  # ][ #  # ]:          0 :       surface = shell->getMemberSurfaces().get();
                 [ #  # ]
    6162         [ #  # ]:          0 :       topo_shell = shell->get_TopoDS_Shell();
    6163                 :            :     }
    6164                 :            :     else
    6165                 :            :     {
    6166         [ #  # ]:          0 :       surface = surfaces.get();
    6167         [ #  # ]:          0 :       topo_face = surface->get_TopoDS_Face();
    6168                 :            :     }
    6169 [ #  # ][ #  # ]:          0 :     CubitVector point_1, normal ;
    6170         [ #  # ]:          0 :     CubitStatus rsl = surface->get_point_normal(point_1, normal);
    6171         [ #  # ]:          0 :     assert(rsl);
    6172                 :            : 
    6173                 :            :     //compare the tool body's location with the webcut_body_list, to see if
    6174                 :            :     //one side of the normal will totally cover one or more volumes
    6175                 :            :     //while the other side cut through one volume, with no whole volume
    6176                 :            :     //covered. Make sure the tool body's normal direct to single cut-
    6177                 :            :     //through volume to make sure the boolean operation won't destory
    6178                 :            :     //webcut_body_list and create a new body.
    6179                 :          0 :     CubitBoolean reversed = CUBIT_FALSE;
    6180 [ #  # ][ #  # ]:          0 :     if(webcut_body_list.size() == 1)
    6181                 :            :     {
    6182         [ #  # ]:          0 :       DLIList<OCCSurface*> cut_surfaces;
    6183                 :          0 :       OCCSurface* cut_face = NULL;
    6184 [ #  # ][ #  # ]:          0 :       if(surfaces.size() == 1)
    6185                 :            :       {
    6186 [ #  # ][ #  # ]:          0 :         cut_surfaces = occ_body->my_sheet_surfaces();
                 [ #  # ]
    6187         [ #  # ]:          0 :         cut_face = cut_surfaces.get();
    6188                 :            :       }
    6189                 :            :       else
    6190                 :            :       {
    6191         [ #  # ]:          0 :         DLIList<OCCShell*> shells;
    6192 [ #  # ][ #  # ]:          0 :         shells = occ_body->shells();
                 [ #  # ]
    6193 [ #  # ][ #  # ]:          0 :         cut_face = shells.get()->my_surface();
                 [ #  # ]
    6194                 :            :       }
    6195         [ #  # ]:          0 :       if(cut_face != NULL)
    6196                 :            :       {
    6197         [ #  # ]:          0 :         CubitVector center = cut_face->center_point();
    6198         [ #  # ]:          0 :         CubitVector normal;
    6199         [ #  # ]:          0 :         cut_face->get_point_normal(center, normal);
    6200         [ #  # ]:          0 :         DLIList<Lump*> lumps;
    6201         [ #  # ]:          0 :         BodySM *from_body = webcut_body_list.get();
    6202         [ #  # ]:          0 :         from_body->lumps(lumps);
    6203                 :          0 :         int right = 0, left = 0;
    6204 [ #  # ][ #  # ]:          0 :         for(int kk = 0; kk < lumps.size(); kk++)
    6205                 :            :         {
    6206 [ #  # ][ #  # ]:          0 :           CubitBox box = lumps.get_and_step()->bounding_box();
    6207 [ #  # ][ #  # ]:          0 :           if(box <= center) //center outside of box
    6208                 :            :           {
    6209 [ #  # ][ #  # ]:          0 :             CubitVector v = box.center() - center;
    6210 [ #  # ][ #  # ]:          0 :             if(v%normal > 0)
    6211                 :          0 :               left ++;
    6212                 :            :             else
    6213                 :          0 :               right++;
    6214                 :            :           }
    6215         [ #  # ]:          0 :         }
    6216 [ #  # ][ #  # ]:          0 :         if(right > 0 && left == 0)
    6217         [ #  # ]:          0 :           reversed = CUBIT_TRUE;
    6218         [ #  # ]:          0 :       }
    6219                 :            :     }
    6220 [ #  # ][ #  # ]:          0 :     gp_Pnt pt = gp_Pnt( point_1.x(), point_1.y(), point_1.z());
         [ #  # ][ #  # ]
    6221 [ #  # ][ #  # ]:          0 :     gp_Dir normal_dir(normal.x(), normal.y(), normal.z());
         [ #  # ][ #  # ]
    6222         [ #  # ]:          0 :     gp_Vec vec(normal_dir);
    6223         [ #  # ]:          0 :     if(reversed)
    6224         [ #  # ]:          0 :       vec = -vec;
    6225         [ #  # ]:          0 :     pt =  pt.Translated(vec);
    6226                 :            : 
    6227         [ #  # ]:          0 :     TopoDS_Solid solid;
    6228 [ #  # ][ #  # ]:          0 :     if(shells.size() == 1)
    6229 [ #  # ][ #  # ]:          0 :       solid = BRepPrimAPI_MakeHalfSpace(*topo_shell, pt);
         [ #  # ][ #  # ]
                 [ #  # ]
    6230                 :            :     else
    6231 [ #  # ][ #  # ]:          0 :       solid = BRepPrimAPI_MakeHalfSpace(*topo_face,pt);
         [ #  # ][ #  # ]
                 [ #  # ]
    6232                 :            : 
    6233 [ #  # ][ #  # ]:          0 :     DLIList<CubitBoolean> is_tool_volume;
    6234         [ #  # ]:          0 :     is_tool_volume.append(CUBIT_TRUE);
    6235 [ #  # ][ #  # ]:          0 :     DLIList<CubitBox*> tool_boxes ;
    6236         [ #  # ]:          0 :     Bnd_Box box;
    6237         [ #  # ]:          0 :     BRepBndLib::Add(solid, box);
    6238                 :            :     double min[3], max[3];
    6239         [ #  # ]:          0 :     box.Get(min[0], min[1], min[2], max[0], max[1], max[2]);
    6240 [ #  # ][ #  # ]:          0 :     CubitBox* cBox = new CubitBox(min, max);
    6241                 :            : 
    6242         [ #  # ]:          0 :     tool_boxes.append(cBox);
    6243 [ #  # ][ #  # ]:          0 :     DLIList<TopoDS_Shape*> solids;
    6244         [ #  # ]:          0 :     solids.append(&solid);
    6245                 :            :     rsl = do_subtract(webcut_body_list, solids, is_tool_volume,
    6246         [ #  # ]:          0 :                      &tool_boxes, results_list, CUBIT_TRUE) ;
    6247 [ #  # ][ #  # ]:          0 :     delete cBox;
    6248         [ #  # ]:          0 :     if(!rsl)
    6249                 :            :     {
    6250 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Failed to webcut the bodies.\n");
         [ #  # ][ #  # ]
    6251                 :          0 :       return CUBIT_FAILURE;
    6252                 :            :     }
    6253         [ #  # ]:          0 :     gp_Vec vec2 =  -2 * vec;
    6254         [ #  # ]:          0 :     pt = pt.Translated(vec2);
    6255 [ #  # ][ #  # ]:          0 :     if(shells.size() == 1)
    6256 [ #  # ][ #  # ]:          0 :       solid = BRepPrimAPI_MakeHalfSpace(*topo_shell, pt);
         [ #  # ][ #  # ]
                 [ #  # ]
    6257                 :            :     else
    6258 [ #  # ][ #  # ]:          0 :       solid = BRepPrimAPI_MakeHalfSpace(*topo_face,pt);
         [ #  # ][ #  # ]
                 [ #  # ]
    6259         [ #  # ]:          0 :     Bnd_Box box2;
    6260         [ #  # ]:          0 :     BRepBndLib::Add(solid, box2);
    6261         [ #  # ]:          0 :     box2.Get(min[0], min[1], min[2], max[0], max[1], max[2]);
    6262 [ #  # ][ #  # ]:          0 :     cBox = new CubitBox(min, max);
    6263         [ #  # ]:          0 :     tool_boxes.clean_out();
    6264         [ #  # ]:          0 :     tool_boxes.append(cBox);
    6265         [ #  # ]:          0 :     solids.clean_out();
    6266         [ #  # ]:          0 :     solids.append(&solid);
    6267                 :            :     rsl = do_subtract(webcut_body_list, solids, is_tool_volume,
    6268         [ #  # ]:          0 :                      &tool_boxes, results_list, CUBIT_FALSE) ;
    6269                 :            :     //make sure the original body's pointer is the first.
    6270         [ #  # ]:          0 :     results_list.reverse();
    6271 [ #  # ][ #  # ]:          0 :     delete cBox;
    6272         [ #  # ]:          0 :     return rsl;
    6273                 :            :   }
    6274                 :            : 
    6275                 :            :   stat = intersect(body, webcut_body_list, results_list,
    6276         [ +  - ]:         11 :                                CUBIT_TRUE);
    6277                 :            :  
    6278         [ -  + ]:         11 :   if(!stat)
    6279                 :            :   { 
    6280 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Failed to webcut the bodies.\n"); 
         [ #  # ][ #  # ]
    6281                 :          0 :     return CUBIT_FAILURE;
    6282                 :            :   }
    6283                 :            : 
    6284                 :         11 :   bool imprint = CUBIT_TRUE;
    6285         [ +  - ]:         11 :   if(imprint_type == NO_IMPRINT)
    6286                 :         11 :     imprint = CUBIT_FALSE;
    6287                 :            : 
    6288                 :            :   stat = subtract(tool_bodies, webcut_body_list, results_list, imprint, 
    6289         [ +  - ]:         11 :                   CUBIT_FALSE);
    6290                 :            : 
    6291                 :            :   //intersect doesn't have to imprint option, so first do this imprint.
    6292                 :            :   BodySM* new_body1, *new_body2;
    6293         [ -  + ]:         11 :   if(imprint_type > NO_IMPRINT)
    6294                 :            :   {
    6295 [ #  # ][ #  # ]:          0 :     for(int i = 0; i < results_list.size()-1; i ++)
    6296                 :            :     {
    6297         [ #  # ]:          0 :       BodySM* body1 = results_list[i];
    6298 [ #  # ][ #  # ]:          0 :       for(int j = i+1; j < results_list.size(); j++)
    6299                 :            :       {
    6300         [ #  # ]:          0 :         BodySM* body2 = results_list[j];
    6301         [ #  # ]:          0 :         stat =  this->imprint( body1, body2, new_body1, new_body2, false);
    6302 [ #  # ][ #  # ]:          0 :         if(new_body1 && body1 != new_body1)
    6303         [ #  # ]:          0 :           results_list[i] = new_body1;
    6304 [ #  # ][ #  # ]:          0 :         if(new_body2 && body2 != new_body2)
    6305         [ #  # ]:          0 :           results_list[j] = new_body2;
    6306                 :            :       }
    6307                 :            :     }
    6308                 :            :   }
    6309                 :            : 
    6310                 :            :   //now imprint with the neighbors
    6311         [ -  + ]:         11 :   if( imprint_type == INCLUDE_NEIGHBORS  )
    6312                 :            :   {
    6313                 :            :     // Loop over all the neighboring Bodies
    6314 [ #  # ][ #  # ]:          0 :     DLIList<TopoDS_Shape*> shape_list1, shape_list2;
         [ #  # ][ #  # ]
    6315 [ #  # ][ #  # ]:          0 :     DLIList<CubitBoolean> is_volume;
                 [ #  # ]
    6316         [ #  # ]:          0 :     stat = get_shape_list(neighbor_imprint_list,shape_list1,is_volume,false);
    6317         [ #  # ]:          0 :     if (!stat)
    6318                 :            :     {
    6319 [ #  # ][ #  # ]:          0 :         PRINT_WARNING("Can't imprint using neighouring bodies.\n");
         [ #  # ][ #  # ]
    6320                 :          0 :         return CUBIT_SUCCESS;
    6321                 :            :     }
    6322         [ #  # ]:          0 :     is_volume.clean_out();
    6323                 :            : 
    6324         [ #  # ]:          0 :     stat = get_shape_list(results_list,shape_list2,is_volume,false);
    6325                 :            :     {
    6326 [ #  # ][ #  # ]:          0 :         PRINT_WARNING("Can't imprint using neighouring bodies.\n");
         [ #  # ][ #  # ]
    6327 [ #  # ][ #  # ]:          0 :         return CUBIT_SUCCESS;
    6328                 :            :     }
    6329                 :            :     // Loop over all the neighboring shapes
    6330                 :            :     DLIList<TopoDS_Face*> face_list;
    6331                 :            :     for (int i=shape_list1.size(); i--;)
    6332                 :            :     {
    6333                 :            :       TopoDS_Shape *neighbor_shape = shape_list1.get_and_step() ;
    6334                 :            :       for(int j = 0; j < shape_list2.size(); j ++)
    6335                 :            :       {
    6336                 :            :         TopoDS_Shape* shape2 = shape_list2[j];
    6337                 :            :         int result =  this->imprint_toposhapes( shape2, neighbor_shape, face_list);
    6338                 :            :         if(result == 0)
    6339                 :            :           shape_list2[j] = shape2;
    6340                 :            :       }
    6341                 :            :     }
    6342                 :            : 
    6343                 :            :     DLIList<TopologyBridge*> tbs;
    6344                 :            :     results_list.clean_out();
    6345                 :            :     for(int j = 0; j < shape_list2.size(); j ++)
    6346                 :            :     {
    6347                 :            :       TopoDS_Shape* shape2 = shape_list2[j];
    6348                 :            : 
    6349                 :            :       tbs += OCCQueryEngine::instance()->populate_topology_bridge(*shape2);
    6350                 :            :       BodySM* newBody1 = CAST_TO(tbs.get(),BodySM);
    6351                 :            :       results_list.append(newBody1);
    6352                 :          0 :     }
    6353                 :            :   } 
    6354         [ +  - ]:         22 :   return stat;
    6355                 :            : }
    6356                 :            : 
    6357                 :            : //Dummy functions to fulfill the pure virtural functions in parents, should
    6358                 :            : //not be called.       ---Jane Hu, 02/17/2012 
    6359                 :          0 : CubitStatus OCCModifyEngine::webcut_with_sheet(
    6360                 :            :                                     DLIList<BodySM*>& webcut_body_list,
    6361                 :            :                                     BodySM *sheet_body,
    6362                 :            :                                     DLIList<BodySM*>& neighbor_imprint_list,
    6363                 :            :                                     DLIList<BodySM*> &new_bodies,
    6364                 :            :                                     ImprintType imprint_type ,
    6365                 :            :                                     bool preview )
    6366                 :            : {
    6367                 :          0 :   return CUBIT_FAILURE;                     
    6368                 :            : }
    6369                 :            : 
    6370                 :          0 : CubitStatus OCCModifyEngine::webcut_with_extended_sheet(
    6371                 :            :                                     DLIList<BodySM*> &webcut_body_list,
    6372                 :            :                                     DLIList<Surface*> &surface_list,
    6373                 :            :                                     DLIList<BodySM*>& neighbor_imprint_list,
    6374                 :            :                                     DLIList<BodySM*> &new_bodies,
    6375                 :            :                                     int &num_cut,
    6376                 :            :                                     ImprintType imprint_type ,
    6377                 :            :                                     bool preview )
    6378                 :            : {
    6379 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("This feature is not implemented.\n");
    6380                 :          0 :   return CUBIT_FAILURE;
    6381                 :            : } 
    6382                 :            : 
    6383                 :          0 : CubitStatus OCCModifyEngine::webcut_with_sweep_curves(
    6384                 :            :                             DLIList<BodySM*> &blank_bodies,
    6385                 :            :                             DLIList<Curve*> &curves,
    6386                 :            :                             const CubitVector& sweep_vector,
    6387                 :            :                             bool through_all,
    6388                 :            :                             Surface *stop_surf,
    6389                 :            :                             Curve *curve_to_sweep_along,
    6390                 :            :                             DLIList<BodySM*>& neighbor_imprint_list,
    6391                 :            :                             DLIList<BodySM*> &results_list,
    6392                 :            :                             ImprintType imprint_type, 
    6393                 :            :                             CubitBoolean preview )
    6394                 :            : {
    6395                 :          0 :   return CUBIT_FAILURE;
    6396                 :            : }
    6397                 :            : 
    6398                 :          0 : CubitStatus OCCModifyEngine::webcut_with_sweep_curves_rotated(
    6399                 :            :                             DLIList<BodySM*> &blank_bodies,
    6400                 :            :                             DLIList<Curve*> &curves,
    6401                 :            :                             const CubitVector &point,
    6402                 :            :                             const CubitVector &sweep_axis,
    6403                 :            :                             double angle,
    6404                 :            :                             Surface *stop_surf,
    6405                 :            :                             DLIList<BodySM*>& neighbor_imprint_list,
    6406                 :            :                             DLIList<BodySM*> &results_list,
    6407                 :            :                             ImprintType imprint_type,
    6408                 :            :                             CubitBoolean preview )
    6409                 :            : {
    6410                 :          0 :   return CUBIT_FAILURE;
    6411                 :            : }
    6412                 :            : 
    6413                 :          0 : CubitStatus OCCModifyEngine::webcut_with_sweep_surfaces_rotated(
    6414                 :            :                             DLIList<BodySM*> &blank_bodies,
    6415                 :            :                             DLIList<Surface*> &surfaces,
    6416                 :            :                             const CubitVector &point,
    6417                 :            :                             const CubitVector &sweep_axis,
    6418                 :            :                             double angle,
    6419                 :            :                             Surface *stop_surf,
    6420                 :            :                             bool up_to_next,
    6421                 :            :                             DLIList<BodySM*>& neighbor_imprint_list,
    6422                 :            :                             DLIList<BodySM*> &results_list,
    6423                 :            :                             ImprintType imprint_type ,
    6424                 :            :                             CubitBoolean preview )
    6425                 :            : {
    6426                 :          0 :   return CUBIT_FAILURE;
    6427                 :            : }
    6428                 :            : 
    6429                 :          0 : CubitStatus OCCModifyEngine::webcut_with_sweep_surfaces(
    6430                 :            :                             DLIList<BodySM*> &blank_bodies,
    6431                 :            :                             DLIList<Surface*> &surfaces,
    6432                 :            :                             const CubitVector& sweep_vector,
    6433                 :            :                             bool sweep_perp,
    6434                 :            :                             bool through_all,
    6435                 :            :                             bool outward,
    6436                 :            :                             bool up_to_next,
    6437                 :            :                             Surface *stop_surf,
    6438                 :            :                             Curve *curve_to_sweep_along,
    6439                 :            :                             DLIList<BodySM*>& neighbor_imprint_list,
    6440                 :            :                             DLIList<BodySM*> &results_list,
    6441                 :            :                             ImprintType imprint_type ,
    6442                 :            :                             CubitBoolean preview )
    6443                 :            : {
    6444                 :          0 :   return CUBIT_FAILURE;
    6445                 :            : }
    6446                 :            : 
    6447                 :          0 : CubitStatus OCCModifyEngine::webcut_with_cylinder(
    6448                 :            :                                         DLIList<BodySM*> &webcut_body_list,
    6449                 :            :                                         double radius,
    6450                 :            :                                         const CubitVector &axis,
    6451                 :            :                                         const CubitVector &center,
    6452                 :            :                                         DLIList<BodySM*>& neighbor_imprint_list,
    6453                 :            :                                         DLIList<BodySM*>& results_list,
    6454                 :            :                                         ImprintType imprint_type ,
    6455                 :            :                                         CubitBoolean preview )
    6456                 :            : {
    6457                 :          0 :   return CUBIT_FAILURE;
    6458                 :            : }
    6459                 :            : 
    6460                 :          0 : CubitStatus OCCModifyEngine::webcut_with_brick(
    6461                 :            :                                      DLIList<BodySM*>& webcut_body_list,
    6462                 :            :                                      const CubitVector &center,
    6463                 :            :                                      const CubitVector axes[3],
    6464                 :            :                                      const CubitVector &extension,
    6465                 :            :                                      DLIList<BodySM*>& neighbor_imprint_list,
    6466                 :            :                                      DLIList<BodySM*> &results_list,
    6467                 :            :                                      ImprintType imprint_type ,
    6468                 :            :                                      CubitBoolean preview )
    6469                 :            : {
    6470                 :          0 :   return CUBIT_FAILURE;
    6471                 :            : }
    6472                 :            : 
    6473                 :          0 : CubitStatus OCCModifyEngine::webcut_with_planar_sheet(
    6474                 :            :                                             DLIList<BodySM*>& webcut_body_list,
    6475                 :            :                                             const CubitVector &center,
    6476                 :            :                                             const CubitVector axes[2],
    6477                 :            :                                             double width, double height,
    6478                 :            :                                             DLIList<BodySM*>& neighbor_imprint_list,
    6479                 :            :                                             DLIList<BodySM*> &results_list,
    6480                 :            :                                             ImprintType imprint_type ,
    6481                 :            :                                             bool preview )
    6482                 :            : {
    6483                 :          0 :   return CUBIT_FAILURE;
    6484                 :            : }
    6485                 :            : 
    6486                 :          0 : CubitStatus OCCModifyEngine::webcut_with_curve_loop(
    6487                 :            :                                          DLIList<BodySM*> &webcut_body_list,
    6488                 :            :                                          DLIList<Curve*> &ref_edge_list,
    6489                 :            :                                          DLIList<BodySM*>& neighbor_imprint_list,
    6490                 :            :                                          DLIList<BodySM*>& results_list,
    6491                 :            :                                          ImprintType imprint_type ,
    6492                 :            :                                          bool preview )
    6493                 :            : {
    6494                 :          0 :   return CUBIT_FAILURE;
    6495                 :            : }
    6496                 :            : 
    6497                 :            : //===============================================================================
    6498                 :            : // Function   : separate_surfaces
    6499                 :            : // Member Type: PUBLIC
    6500                 :            : // Description: separate surfaces in shells or compounds into independent ones,
    6501                 :            : //              still keep the original shell.
    6502                 :            : // Author     : Jane Hu
    6503                 :            : // Date       : 02/11
    6504                 :            : //===============================================================================
    6505                 :          0 : CubitStatus OCCModifyEngine::separate_surfaces( DLIList<Surface*> &surf_list,
    6506                 :            :                                          DLIList<BodySM*> &new_bodies )
    6507                 :            : {
    6508         [ #  # ]:          0 :   DLIList<OCCSurface*> surf_need_work;
    6509                 :            :   //find out the complexity that the surf_list involves.
    6510 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < surf_list.size(); i++)
    6511                 :            :   {
    6512         [ #  # ]:          0 :     Surface* surf = surf_list.get_and_step();
    6513         [ #  # ]:          0 :     OCCSurface *surface = CAST_TO(surf, OCCSurface);
    6514         [ #  # ]:          0 :     OCCBody* body = surface->my_body();
    6515         [ #  # ]:          0 :     if(body != NULL) //either a single surface body or a compound body
    6516                 :            :     {
    6517         [ #  # ]:          0 :       DLIList<Lump*> lumps;
    6518         [ #  # ]:          0 :       body->lumps(lumps);
    6519 [ #  # ][ #  # ]:          0 :       if (lumps.size() > 0) //compound body
    6520                 :            :       {
    6521         [ #  # ]:          0 :         surf_need_work.append(surface);
    6522                 :          0 :         continue;
    6523                 :            :       }
    6524 [ #  # ][ #  # ]:          0 :       DLIList< OCCShell*> shells;
    6525 [ #  # ][ #  # ]:          0 :       body->shells(shells);
                 [ #  # ]
    6526 [ #  # ][ #  # ]:          0 :       if(shells.size() > 0) //compound body
    6527         [ #  # ]:          0 :         surf_need_work.append(surface);
    6528         [ #  # ]:          0 :       continue;
    6529                 :            :     }
    6530                 :            : 
    6531                 :            :     OCCShell* shell;
    6532         [ #  # ]:          0 :     shell = surface->my_shell();
    6533 [ #  # ][ #  # ]:          0 :     if(shell != NULL && shell->my_surface() == NULL) //sheet body
         [ #  # ][ #  # ]
    6534                 :            :     {
    6535         [ #  # ]:          0 :       surf_need_work.append(surface);
    6536                 :          0 :       continue;
    6537                 :            :     }
    6538                 :            :   }
    6539                 :            :   
    6540                 :            :   //create sheet body for surf_need_work list.
    6541 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < surf_need_work.size(); i++)
    6542                 :            :   {
    6543 [ #  # ][ #  # ]:          0 :     Surface* copy_surf = make_Surface(surf_need_work.get_and_step());
    6544         [ #  # ]:          0 :     if (copy_surf == NULL)
    6545                 :            :     {
    6546 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Cannot create an OCC sheet bodySM from the given bodySM.\n");
         [ #  # ][ #  # ]
    6547                 :          0 :        return CUBIT_FAILURE;
    6548                 :            :     }
    6549                 :            : 
    6550         [ #  # ]:          0 :     OCCSurface* occ_surf = CAST_TO(copy_surf, OCCSurface);
    6551         [ #  # ]:          0 :     if(occ_surf != NULL)
    6552 [ #  # ][ #  # ]:          0 :      new_bodies.append( occ_surf->my_body() );
    6553                 :            :   }
    6554         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    6555                 :            : }
    6556                 :            : //===============================================================================
    6557                 :            : // Function   : section
    6558                 :            : // Member Type: PUBLIC
    6559                 :            : // Description: 
    6560                 :            : // Author     : Jane Hu
    6561                 :            : // Date       : 11/08
    6562                 :            : //===============================================================================
    6563                 :         33 : CubitStatus OCCModifyEngine::section( DLIList<BodySM*> &section_body_list,
    6564                 :            :                                       const CubitVector &point_1,
    6565                 :            :                                       const CubitVector &point_2,
    6566                 :            :                                       const CubitVector &point_3,
    6567                 :            :                                       DLIList<BodySM*>& new_body_list,
    6568                 :            :                                       bool keep_normal_side,
    6569                 :            :                                       bool keep_old,
    6570                 :            :                                       bool keep_both_sides)
    6571                 :            : {
    6572         [ -  + ]:         33 :   if (keep_both_sides == CUBIT_TRUE )
    6573                 :            :   {
    6574 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Please use webcut to for keep both sides option.\n");
         [ #  # ][ #  # ]
    6575                 :          0 :      return CUBIT_FAILURE;
    6576                 :            :   }
    6577                 :            :  
    6578                 :            :   //Calculate normal of the section plan
    6579 [ +  - ][ +  - ]:         33 :   CubitVector v1, v2, normal;
                 [ +  - ]
    6580 [ +  - ][ +  - ]:         33 :   v1 = point_2 - point_1;
    6581 [ +  - ][ +  - ]:         33 :   v2 = point_3 - point_1; 
    6582 [ +  - ][ +  - ]:         33 :   normal = ~(v1 * v2); 
                 [ +  - ]
    6583 [ +  - ][ -  + ]:         33 :   if(fabs(normal.length() - 1) > TOL)
    6584                 :            :   {
    6585 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("The three points are co-linear, and can't be used as a cutting plane.\n");
         [ #  # ][ #  # ]
    6586                 :          0 :      return CUBIT_FAILURE;
    6587                 :            :   }
    6588                 :            :   
    6589         [ +  + ]:         33 :   if(keep_normal_side)
    6590         [ +  - ]:         11 :     normal *= -1;
    6591                 :            : 
    6592 [ +  - ][ +  - ]:         33 :   gp_Pnt pt = gp_Pnt( point_1.x(), point_1.y(), point_1.z());
         [ +  - ][ +  - ]
    6593 [ +  - ][ +  - ]:         33 :   gp_Dir normal_dir(normal.x(), normal.y(), normal.z()); 
         [ +  - ][ +  - ]
    6594         [ +  - ]:         33 :   gp_Pln plane(pt, normal_dir);
    6595         [ +  - ]:         33 :   gp_Vec vec(normal_dir);
    6596         [ +  - ]:         33 :   pt =  pt.Translated(vec);
    6597                 :            : 
    6598 [ +  - ][ +  - ]:         33 :   TopoDS_Face face = BRepBuilderAPI_MakeFace(plane);
                 [ +  - ]
    6599 [ +  - ][ +  - ]:         66 :   TopoDS_Solid solid = BRepPrimAPI_MakeHalfSpace(face, pt);
         [ +  - ][ +  - ]
    6600                 :            :    
    6601 [ +  - ][ +  - ]:         66 :   DLIList<CubitBoolean> is_tool_volume;
    6602         [ +  - ]:         33 :   is_tool_volume.append(CUBIT_TRUE);
    6603 [ +  - ][ +  - ]:         66 :   DLIList<CubitBox*> tool_boxes ;
    6604         [ +  - ]:         33 :   Bnd_Box box;
    6605         [ +  - ]:         33 :   BRepBndLib::Add(solid, box);
    6606                 :            :   double min[3], max[3];
    6607         [ +  - ]:         33 :   box.Get(min[0], min[1], min[2], max[0], max[1], max[2]);
    6608 [ +  - ][ +  - ]:         33 :   CubitBox* cBox = new CubitBox(min, max);
    6609                 :            :   
    6610         [ +  - ]:         33 :   tool_boxes.append(cBox);
    6611 [ +  - ][ +  - ]:         66 :   DLIList<TopoDS_Shape*> solids;
    6612         [ +  - ]:         33 :   solids.append(&solid);
    6613                 :            :   CubitStatus stat = do_subtract(section_body_list, solids, is_tool_volume,
    6614         [ +  - ]:         33 :                      &tool_boxes, new_body_list, keep_old) ;
    6615 [ +  - ][ +  - ]:         33 :   delete cBox;
    6616         [ +  - ]:         33 :   return stat;
    6617                 :            : }
    6618                 :            : 
    6619                 :            : //===============================================================================
    6620                 :            : // Function   : split_body
    6621                 :            : // Member Type: PUBLIC
    6622                 :            : // Description: Splits multiple lumps in one body into separate bodies
    6623                 :            : // Author     : Jane Hu 
    6624                 :            : // Date       : 12/08
    6625                 :            : //===============================================================================
    6626                 :         11 : CubitStatus OCCModifyEngine::split_body( BodySM *body_ptr,
    6627                 :            :                                          DLIList<BodySM*> &new_bodies )
    6628                 :            : {
    6629         [ -  + ]:         11 :   OCCBody* occ_body = CAST_TO(body_ptr, OCCBody);
    6630         [ -  + ]:         11 :   if(!occ_body)
    6631                 :            :   {
    6632 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("This is not an OCC body to be split.\n");
         [ #  # ][ #  # ]
    6633                 :          0 :      return CUBIT_FAILURE;
    6634                 :            :   }
    6635         [ +  - ]:         11 :   DLIList<Lump*> lumps = occ_body->lumps();
    6636 [ +  - ][ -  + ]:         11 :   if(lumps.size() == 1) 
    6637                 :            :   {
    6638         [ #  # ]:          0 :     new_bodies.append(body_ptr);
    6639                 :          0 :     return CUBIT_SUCCESS;
    6640                 :            :   }
    6641 [ +  - ][ +  + ]:         99 :   for(int i = 0; i < lumps.size(); i++)
    6642                 :            :   {
    6643         [ +  - ]:         88 :     Lump* lump = lumps.get_and_step();
    6644         [ -  + ]:         88 :     OCCLump* occ_lump = CAST_TO(lump, OCCLump);
    6645         [ +  - ]:         88 :     OCCSurface* occ_surface = occ_lump->my_sheet_surface();
    6646                 :            :     //first delete the body which bounds all the stuff.
    6647         [ +  + ]:         88 :     if (i == 0)
    6648 [ +  - ][ +  - ]:         11 :       OCCQueryEngine::instance()->unhook_BodySM_from_OCC(body_ptr, CUBIT_FALSE);
    6649         [ -  + ]:         88 :     if(occ_surface) 
    6650                 :            :     {
    6651         [ #  # ]:          0 :       TopoDS_Face* face = occ_surface->get_TopoDS_Face();
    6652                 :            :       Surface* surface = 
    6653                 :            :         OCCQueryEngine::instance()->populate_topology_bridge(*face,
    6654 [ #  # ][ #  # ]:          0 :                                                              CUBIT_TRUE);
    6655 [ #  # ][ #  # ]:          0 :       new_bodies.append(CAST_TO(surface, OCCSurface)->my_body()); 
                 [ #  # ]
    6656                 :          0 :       continue;
    6657                 :            :     }
    6658         [ +  - ]:         88 :     OCCShell* occ_shell = occ_lump->my_shell();
    6659         [ -  + ]:         88 :     if(occ_shell) 
    6660                 :            :     {
    6661         [ #  # ]:          0 :       TopoDS_Shell* shell = occ_shell->get_TopoDS_Shell();
    6662                 :            :       OCCShell* ashell = 
    6663                 :            :          OCCQueryEngine::instance()->populate_topology_bridge(*shell,
    6664 [ #  # ][ #  # ]:          0 :                                                               CUBIT_TRUE);
    6665 [ #  # ][ #  # ]:          0 :       new_bodies.append(ashell->my_body());
    6666                 :          0 :       continue;
    6667                 :            :     }
    6668                 :            :     else
    6669                 :            :     {
    6670         [ +  - ]:         88 :       TopoDS_Solid* solid = occ_lump->get_TopoDS_Solid();
    6671                 :            :       Lump* alump = 
    6672                 :            :         OCCQueryEngine::instance()->populate_topology_bridge(*solid,
    6673 [ +  - ][ +  - ]:         88 :                                                              CUBIT_TRUE);
    6674 [ -  + ][ +  - ]:         88 :       new_bodies.append(CAST_TO(alump,OCCLump)->get_body());
                 [ +  - ]
    6675                 :         88 :       continue;
    6676                 :            :     }
    6677                 :            :   }
    6678                 :            :   
    6679 [ +  - ][ +  - ]:         11 :   if(lumps.size() > 1)
    6680 [ +  - ][ +  - ]:         11 :     delete body_ptr;
    6681         [ +  - ]:         11 :   return CUBIT_SUCCESS;
    6682                 :            : }
    6683                 :            : 
    6684                 :            : 
    6685                 :            : //===============================================================================
    6686                 :            : // Function   : reverse_body
    6687                 :            : // Member Type: PUBLIC
    6688                 :            : // Description: Turn body inside-out
    6689                 :            : // Author     : Jane Hu
    6690                 :            : // Date       : 03/03/09
    6691                 :            : //===============================================================================
    6692                 :          0 : CubitStatus OCCModifyEngine::reverse_body( BodySM* body_ptr )
    6693                 :            : {
    6694         [ #  # ]:          0 :   OCCBody* occ_body = CAST_TO(body_ptr, OCCBody);
    6695         [ #  # ]:          0 :   if (!occ_body)
    6696                 :            :   {
    6697 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Cannot reverse a non-OCC bodySM .\n"
                 [ #  # ]
    6698         [ #  # ]:          0 :                  "Possible incompatible geometry engines.\n");
    6699                 :          0 :      return CUBIT_FAILURE;
    6700                 :            :   }
    6701                 :            : 
    6702                 :            :   TopoDS_Shape* orig_S;
    6703         [ #  # ]:          0 :   TopoDS_Shape S;
    6704                 :            :   BRep_Builder B;
    6705         [ #  # ]:          0 :   occ_body->get_TopoDS_Shape(orig_S);
    6706 [ #  # ][ #  # ]:          0 :   S = orig_S->EmptyCopied();
                 [ #  # ]
    6707 [ #  # ][ #  # ]:          0 :   TopoDS_Iterator it(*orig_S);
    6708 [ #  # ][ #  # ]:          0 :   while (it.More()) {
    6709 [ #  # ][ #  # ]:          0 :     B.Add(S,it.Value().Reversed());
         [ #  # ][ #  # ]
    6710         [ #  # ]:          0 :     it.Next();
    6711                 :            :   } 
    6712 [ #  # ][ #  # ]:          0 :   occ_body->set_TopoDS_Shape(TopoDS::Compound(S));  
    6713                 :            :   //Bind the new shape and its underlining sub-shapes.
    6714 [ #  # ][ #  # ]:          0 :   TopExp_Explorer Ex_orig, Ex;
         [ #  # ][ #  # ]
    6715                 :          0 :   int k = -1;
    6716         [ #  # ]:          0 :   Ex.Init(S, TopAbs_COMPOUND);
    6717         [ #  # ]:          0 :   Ex_orig.Init(*orig_S, TopAbs_COMPOUND);
    6718 [ #  # ][ #  # ]:          0 :   for (; Ex_orig.More(), Ex.More(); Ex_orig.Next(), Ex.Next())
         [ #  # ][ #  # ]
                 [ #  # ]
    6719                 :            :   {
    6720 [ #  # ][ #  # ]:          0 :     if(OCCQueryEngine::instance()->OCCMap->IsBound(Ex.Current()))
         [ #  # ][ #  # ]
    6721                 :            :     {
    6722 [ #  # ][ #  # ]:          0 :       k = OCCQueryEngine::instance()->OCCMap->Find(Ex_orig.Current());   
                 [ #  # ]
    6723 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->OCCMap->UnBind(Ex_orig.Current());
                 [ #  # ]
    6724 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->OCCMap->Bind(Ex.Current(), k);
                 [ #  # ]
    6725 [ #  # ][ #  # ]:          0 :       TopExp_Explorer Ex_old_solid, Ex_solid;
                 [ #  # ]
    6726         [ #  # ]:          0 :       Ex_old_solid.Init(*orig_S,TopAbs_SOLID);
    6727         [ #  # ]:          0 :       Ex_solid.Init(S, TopAbs_SOLID);
    6728 [ #  # ][ #  # ]:          0 :       DLIList<Lump*> lumps = occ_body->lumps();
    6729 [ #  # ][ #  # ]:          0 :       for (; Ex_old_solid.More(), Ex_solid.More(); Ex_old_solid.Next(), Ex_solid.Next())
         [ #  # ][ #  # ]
                 [ #  # ]
    6730                 :            :       {
    6731 [ #  # ][ #  # ]:          0 :         k = OCCQueryEngine::instance()->OCCMap->Find(Ex_old_solid.Current());
                 [ #  # ]
    6732 [ #  # ][ #  # ]:          0 :         OCCQueryEngine::instance()->OCCMap->UnBind(Ex_old_solid.Current());
                 [ #  # ]
    6733 [ #  # ][ #  # ]:          0 :         OCCQueryEngine::instance()->OCCMap->Bind(Ex_solid.Current(), k);
                 [ #  # ]
    6734 [ #  # ][ #  # ]:          0 :         OCCLump* occ_lump = CAST_TO(lumps.get_and_step(), OCCLump);
    6735 [ #  # ][ #  # ]:          0 :         occ_lump->set_TopoDS_Solid(TopoDS::Solid(Ex_solid.Current()));
         [ #  # ][ #  # ]
                 [ #  # ]
    6736         [ #  # ]:          0 :       }
    6737                 :            :     } 
    6738                 :            :     
    6739                 :            :     else
    6740                 :            :     {
    6741 [ #  # ][ #  # ]:          0 :       Lump *lump = occ_body->lumps().get();
                 [ #  # ]
    6742         [ #  # ]:          0 :       OCCLump* occ_lump = CAST_TO(lump, OCCLump);
    6743 [ #  # ][ #  # ]:          0 :       TopoDS_Solid solid = *(occ_lump->get_TopoDS_Solid());
    6744 [ #  # ][ #  # ]:          0 :       k = OCCQueryEngine::instance()->OCCMap->Find(solid);
    6745 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->OCCMap->UnBind(solid);
    6746 [ #  # ][ #  # ]:          0 :       TopExp_Explorer Ex_local;
    6747         [ #  # ]:          0 :       Ex_local.Init(S, TopAbs_SOLID);
    6748 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->OCCMap->Bind(Ex_local.Current(), k);
                 [ #  # ]
    6749 [ #  # ][ #  # ]:          0 :       occ_lump->set_TopoDS_Solid(TopoDS::Solid(Ex_local.Current())); 
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    6750                 :            :     }
    6751                 :            :   }  
    6752                 :            :       
    6753         [ #  # ]:          0 :   Ex.Init(S, TopAbs_SHELL);
    6754         [ #  # ]:          0 :   Ex_orig.Init(*orig_S, TopAbs_SHELL);
    6755 [ #  # ][ #  # ]:          0 :   for (; Ex_orig.More(), Ex.More(); Ex_orig.Next(), Ex.Next())
         [ #  # ][ #  # ]
                 [ #  # ]
    6756                 :            :   {
    6757 [ #  # ][ #  # ]:          0 :     k = OCCQueryEngine::instance()->OCCMap->Find(Ex_orig.Current());
                 [ #  # ]
    6758 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->UnBind(Ex_orig.Current());
                 [ #  # ]
    6759 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->Bind(Ex.Current(), k);
                 [ #  # ]
    6760 [ #  # ][ #  # ]:          0 :     OCCShell *shell = (OCCShell*)(OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ #  # ]
    6761 [ #  # ][ #  # ]:          0 :     shell->set_TopoDS_Shell(TopoDS::Shell(Ex.Current())); 
         [ #  # ][ #  # ]
                 [ #  # ]
    6762                 :            :   }
    6763                 :            : 
    6764         [ #  # ]:          0 :   Ex.Init(S, TopAbs_FACE);
    6765         [ #  # ]:          0 :   Ex_orig.Init(*orig_S, TopAbs_FACE);
    6766 [ #  # ][ #  # ]:          0 :   for (; Ex_orig.More(), Ex.More(); Ex_orig.Next(), Ex.Next())
         [ #  # ][ #  # ]
                 [ #  # ]
    6767                 :            :   {
    6768 [ #  # ][ #  # ]:          0 :     k = OCCQueryEngine::instance()->OCCMap->Find(Ex_orig.Current());
                 [ #  # ]
    6769 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->UnBind(Ex_orig.Current());
                 [ #  # ]
    6770 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->Bind(Ex.Current(), k);
                 [ #  # ]
    6771 [ #  # ][ #  # ]:          0 :     OCCSurface *surface = (OCCSurface *)(OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ #  # ]
    6772 [ #  # ][ #  # ]:          0 :     TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    6773         [ #  # ]:          0 :     surface->set_TopoDS_Face(face);
    6774         [ #  # ]:          0 :   }
    6775                 :            : 
    6776         [ #  # ]:          0 :   Ex.Init(S, TopAbs_WIRE);
    6777         [ #  # ]:          0 :   Ex_orig.Init(*orig_S, TopAbs_WIRE);
    6778 [ #  # ][ #  # ]:          0 :   for (; Ex_orig.More(), Ex.More(); Ex_orig.Next(), Ex.Next())
         [ #  # ][ #  # ]
                 [ #  # ]
    6779                 :            :   {
    6780 [ #  # ][ #  # ]:          0 :     k = OCCQueryEngine::instance()->OCCMap->Find(Ex_orig.Current());
                 [ #  # ]
    6781 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->UnBind(Ex_orig.Current());
                 [ #  # ]
    6782 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->Bind(Ex.Current(), k);
                 [ #  # ]
    6783 [ #  # ][ #  # ]:          0 :     OCCLoop* wire = (OCCLoop*)(OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ #  # ]
    6784 [ #  # ][ #  # ]:          0 :     wire->set_TopoDS_Wire(TopoDS::Wire(Ex.Current()));
         [ #  # ][ #  # ]
                 [ #  # ]
    6785                 :            :   }
    6786                 :            : 
    6787         [ #  # ]:          0 :   Ex.Init(S, TopAbs_EDGE);
    6788         [ #  # ]:          0 :   Ex_orig.Init(*orig_S, TopAbs_EDGE);
    6789 [ #  # ][ #  # ]:          0 :   for (; Ex_orig.More(), Ex.More(); Ex_orig.Next(), Ex.Next())
         [ #  # ][ #  # ]
                 [ #  # ]
    6790                 :            :   {
    6791 [ #  # ][ #  # ]:          0 :     k = OCCQueryEngine::instance()->OCCMap->Find(Ex_orig.Current());
                 [ #  # ]
    6792 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->UnBind(Ex_orig.Current());
                 [ #  # ]
    6793 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->Bind(Ex.Current(), k);
                 [ #  # ]
    6794 [ #  # ][ #  # ]:          0 :     OCCCurve* edge = (OCCCurve*)(OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ #  # ]
    6795 [ #  # ][ #  # ]:          0 :     edge->set_TopoDS_Edge(TopoDS::Edge(Ex.Current()));
         [ #  # ][ #  # ]
                 [ #  # ]
    6796                 :            :   }
    6797                 :            : 
    6798         [ #  # ]:          0 :   Ex.Init(S, TopAbs_VERTEX);
    6799         [ #  # ]:          0 :   Ex_orig.Init(*orig_S, TopAbs_VERTEX);
    6800 [ #  # ][ #  # ]:          0 :   for (; Ex_orig.More(), Ex.More(); Ex_orig.Next(), Ex.Next())
         [ #  # ][ #  # ]
                 [ #  # ]
    6801                 :            :   {
    6802 [ #  # ][ #  # ]:          0 :     k = OCCQueryEngine::instance()->OCCMap->Find(Ex_orig.Current());
                 [ #  # ]
    6803 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->UnBind(Ex_orig.Current());
                 [ #  # ]
    6804 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->OCCMap->Bind(Ex.Current(), k);
                 [ #  # ]
    6805 [ #  # ][ #  # ]:          0 :     OCCPoint* point = (OCCPoint*)(OCCQueryEngine::instance()->OccToCGM->find(k))->second;
                 [ #  # ]
    6806 [ #  # ][ #  # ]:          0 :     point->set_TopoDS_Vertex(TopoDS::Vertex(Ex.Current()));
         [ #  # ][ #  # ]
                 [ #  # ]
    6807                 :            :   }
    6808         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    6809                 :            : }
    6810                 :            :     
    6811                 :            : 
    6812                 :            : 
    6813                 :            : //===============================================================================
    6814                 :            : // Function   : split_periodic
    6815                 :            : // Member Type: PUBLIC
    6816                 :            : // Description: 
    6817                 :            : // Author     : John Fowler
    6818                 :            : // Date       : 10/02
    6819                 :            : //===============================================================================
    6820                 :          0 : CubitStatus OCCModifyEngine::split_periodic( BodySM * /*body_ptr*/,
    6821                 :            :                                                BodySM *& /*new_body*/ )
    6822                 :            : {
    6823                 :          0 :   return CUBIT_FAILURE;
    6824                 :            : }
    6825                 :            : 
    6826                 :            : //===============================================================================
    6827                 :            : // Function   : regularize_body
    6828                 :            : // Member Type: PUBLIC
    6829                 :            : // Description: 
    6830                 :            : // Author     : John Fowler
    6831                 :            : // Date       : 10/02
    6832                 :            : //===============================================================================
    6833                 :          0 : CubitStatus    OCCModifyEngine::regularize_body( BodySM * /*body_ptr*/,
    6834                 :            :                                                    BodySM *& /*new_body_ptr*/ )
    6835                 :            : {
    6836 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    6837                 :          0 :   return CUBIT_FAILURE;
    6838                 :            : }
    6839                 :            : 
    6840                 :            : //===============================================================================
    6841                 :            : // Function   : regularize_refentity
    6842                 :            : // Member Type: PUBLIC
    6843                 :            : // Description: 
    6844                 :            : // Author     : John Fowler
    6845                 :            : // Date       : 10/02
    6846                 :            : //===============================================================================
    6847                 :          0 : CubitStatus  OCCModifyEngine::regularize_entity( GeometryEntity * /*old_entity_ptr*/,  
    6848                 :            :                                                       BodySM *& /*new_body_ptr*/ )
    6849                 :            : {
    6850 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    6851                 :          0 :   return CUBIT_FAILURE;
    6852                 :            : }
    6853                 :            : 
    6854                 :            : //===============================================================================
    6855                 :            : // Function   : offset_curves
    6856                 :            : // Member Type: PUBLIC
    6857                 :            : // Description: 
    6858                 :            : // Author     : Jane Hu
    6859                 :            : // Date       : 12/08
    6860                 :            : //===============================================================================
    6861                 :        110 : CubitStatus OCCModifyEngine::offset_curves( DLIList<Curve*>& curves, 
    6862                 :            :                                             DLIList<Curve*>& new_curves,
    6863                 :            :                                             double offset_distance,
    6864                 :            :                                             const CubitVector& offset_direction, 
    6865                 :            :                                             int gap_type )
    6866                 :            : {
    6867                 :            :   //gap_type has no effect here.
    6868 [ +  - ][ +  + ]:        198 :   if( curves.size() == 1 && (offset_direction.x() ||
         [ +  - ][ +  + ]
         [ +  - ][ +  + ]
    6869 [ +  - ][ +  - ]:         88 :         offset_direction.y() || offset_direction.z()) )
                 [ -  + ]
    6870                 :            :   {
    6871 [ +  - ][ +  - ]:         55 :     gp_Dir offset(offset_direction.x(), offset_direction.y(), offset_direction.z());
         [ +  - ][ +  - ]
    6872                 :            :     //check if the curve is straight, error out for non-straight curve.
    6873         [ +  - ]:         55 :     Curve* curve = curves.get();
    6874         [ -  + ]:         55 :     OCCCurve* occ_curve = CAST_TO(curve, OCCCurve);
    6875 [ +  - ][ +  + ]:         55 :     if(occ_curve->geometry_type() == STRAIGHT_CURVE_TYPE)
    6876                 :            :     {
    6877                 :            :       //based on the definitions of the offset curve on OCC, calculate the
    6878                 :            :       //offset direction to make it consistant with
    6879                 :            :       double u1, u2;
    6880         [ +  - ]:         22 :       occ_curve->get_param_range(u1, u2);
    6881 [ +  - ][ +  - ]:         22 :       CubitVector p1, p2, tangent;
                 [ +  - ]
    6882         [ +  - ]:         22 :       occ_curve->position_from_u(u1, p1);
    6883         [ +  - ]:         22 :       occ_curve->position_from_u(u2, p2);
    6884 [ +  - ][ +  - ]:         22 :       tangent = p2 -p1;
    6885         [ +  - ]:         22 :       CubitVector cal_offset_dir =  offset_direction * tangent;
    6886 [ +  - ][ +  - ]:         22 :       gp_Dir offset(cal_offset_dir.x(), cal_offset_dir.y(), cal_offset_dir.z()); 
         [ +  - ][ +  - ]
    6887         [ +  - ]:         22 :       TopoDS_Edge * edge = occ_curve->get_TopoDS_Edge();
    6888                 :            :       Standard_Real first;
    6889                 :            :       Standard_Real last;
    6890         [ +  - ]:         22 :       Handle(Geom_Curve) myCurve = BRep_Tool::Curve(*edge, first, last);
    6891                 :            :       Handle(Geom_OffsetCurve) new_curve =
    6892 [ +  - ][ +  - ]:         44 :         new Geom_OffsetCurve(myCurve,offset_distance, offset);
         [ +  - ][ +  - ]
    6893 [ +  - ][ -  + ]:         22 :       if(!new_curve)
    6894                 :            :       {
    6895         [ #  # ]:          0 :         TopologyEntity *entity = curve->topology_entity();
    6896         [ #  # ]:          0 :         BasicTopologyEntity *bte = CAST_TO(entity, BasicTopologyEntity);
    6897 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Can't create offset curve for curve %d.\n", bte->id());
         [ #  # ][ #  # ]
                 [ #  # ]
    6898                 :          0 :         return CUBIT_FAILURE;
    6899                 :            :       }
    6900 [ +  - ][ +  - ]:         44 :       TopoDS_Edge new_edge = BRepBuilderAPI_MakeEdge(new_curve, u1, u2);
         [ +  - ][ +  - ]
    6901 [ +  - ][ +  - ]:         22 :       Curve* offset_curve = OCCQueryEngine::instance()->populate_topology_bridge(new_edge, CUBIT_TRUE);
    6902         [ +  - ]:         22 :       new_curves.append(offset_curve);
    6903         [ +  - ]:         22 :       return CUBIT_SUCCESS;
    6904                 :            :     }
    6905                 :            :     else
    6906 [ +  - ][ +  - ]:         33 :       PRINT_WARNING( "Direction qualifier ignored - only valid for one straight curve\n" );
         [ +  - ][ +  - ]
    6907                 :            :   }
    6908                 :            : 
    6909 [ +  - ][ +  + ]:         55 :   else if( offset_direction.x() || offset_direction.y() || offset_direction.z() )
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
                 [ +  + ]
    6910 [ +  - ][ +  - ]:         11 :       PRINT_WARNING( "Direction qualifier ignored - only valid for one straight curve\n" );
         [ +  - ][ +  - ]
    6911                 :            : 
    6912 [ +  - ][ +  - ]:         88 :   else if (offset_direction.x() == 0.0 && offset_direction.y() == 0.0 &&
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    6913         [ +  - ]:         44 :            offset_direction.z() == 0.0)
    6914                 :            :   {
    6915 [ +  - ][ +  + ]:         77 :     for(int i = 0 ; i < curves.size(); i++)
    6916                 :            :     {
    6917         [ +  - ]:         44 :       Curve* curve = curves.get_and_step();
    6918         [ -  + ]:         44 :       OCCCurve* occ_curve = CAST_TO(curve, OCCCurve);
    6919 [ +  - ][ +  + ]:         44 :       if(occ_curve->geometry_type() == STRAIGHT_CURVE_TYPE)
    6920                 :            :       {
    6921                 :            :         // TODO: Remove this condition?
    6922                 :            :         // A planar nonlinear wire consisting of straight curves can be offset
    6923                 :            :         // but it isn't clear that the intent was to offset a wire instead
    6924                 :            :         // of each curve individually.
    6925 [ +  - ][ +  - ]:         11 :         PRINT_ERROR("Must have an offset direction for any straight curve.\n");
         [ +  - ][ +  - ]
    6926                 :         11 :         return CUBIT_FAILURE;
    6927                 :            :       }
    6928                 :            :     }
    6929                 :            :   }
    6930                 :            :   //make wire out of ref_edge_list
    6931         [ +  - ]:         77 :   BRepBuilderAPI_MakeWire awire;
    6932 [ +  - ][ +  - ]:        154 :   TopTools_ListOfShape L;
    6933                 :         77 :   OCCCurve* occ_curve = NULL;
    6934 [ +  - ][ +  - ]:        154 :   BRepBuilderAPI_Copy shapeCopier;
    6935 [ +  - ][ +  + ]:        165 :   for(int i = 0 ; i < curves.size(); i++)
    6936                 :            :   {
    6937         [ +  - ]:         88 :     Curve* curve = curves.get_and_step();
    6938         [ -  + ]:         88 :     occ_curve = CAST_TO(curve, OCCCurve);
    6939         [ -  + ]:         88 :     if(!occ_curve)
    6940                 :          0 :       continue;
    6941 [ +  - ][ +  - ]:         88 :     shapeCopier.Perform(*(occ_curve->get_TopoDS_Edge()));
    6942 [ +  - ][ +  - ]:         88 :     L.Append(shapeCopier.Shape());
    6943                 :            :   }
    6944                 :            : 
    6945         [ +  - ]:         77 :   awire.Add(L);
    6946 [ +  - ][ -  + ]:         77 :   if(awire.Error())
    6947                 :            :   {
    6948 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Curves must form a planar chain in order for offset to work.\n");
         [ #  # ][ #  # ]
    6949                 :          0 :     return CUBIT_FAILURE;
    6950                 :            :   }
    6951 [ +  - ][ +  - ]:        154 :   TopoDS_Wire wire;
    6952 [ +  - ][ +  - ]:         77 :   wire = awire.Wire();
    6953                 :            : 
    6954                 :            : #if OCC_VERSION_MAJOR < 6 || (OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8)
    6955                 :            :   CubitBoolean closed = wire.Closed();
    6956                 :            :   BRepOffsetAPI_MakeOffset offCurveBuilder(wire);
    6957                 :            :   offCurveBuilder.Perform(offset_distance);
    6958                 :            :   offCurveBuilder.Build();
    6959                 :            : 
    6960                 :            :   // Prior to OCC version 6.8 / OCE version 0.17
    6961                 :            :   // For an open wire:
    6962                 :            :   // It returns a closed wire, with two connecting curves and a positive offset
    6963                 :            :   // curve list and a negative offset curve list.
    6964                 :            :   // For a closed wire:
    6965                 :            :   // It returns a closed wire outside the original one if offset_distance > 0
    6966                 :            :   // It returns a closed wire inside the original one if offset_distance < 0
    6967                 :            : 
    6968                 :            :   TopoDS_Shape offWireShape = offCurveBuilder.Shape();
    6969                 :            :   wire = TopoDS::Wire(offWireShape);
    6970                 :            : 
    6971                 :            :   if (!closed)
    6972                 :            :   {
    6973                 :            :     int num_curves = countEdges(wire);
    6974                 :            :     if (num_curves != (2 + 2*curves.size()) )
    6975                 :            :     {
    6976                 :            :       PRINT_ERROR("Opencascade can't calculate one offset curve for each"
    6977                 :            :                   " input curve. It's a limitation, try to use another type"
    6978                 :            :                   " of curve to offset.\n");
    6979                 :            :       return CUBIT_FAILURE;
    6980                 :            :     }
    6981                 :            : 
    6982                 :            :     BRepTools_WireExplorer Ex(wire);
    6983                 :            :     Ex.Next(); // omit the initial cap/connecting curve
    6984                 :            :     for (int i = 0; i < curves.size(); ++i)
    6985                 :            :     {
    6986                 :            :       TopoDS_Edge new_edge = Ex.Current();
    6987                 :            :       Curve* curve = curves.get_and_step();
    6988                 :            :       Curve* offset_curve = OCCQueryEngine::instance()->
    6989                 :            :           populate_topology_bridge(new_edge, CUBIT_TRUE);
    6990                 :            :       // double check here to make sure we get the correct offset curve
    6991                 :            :       // which is if the offset_distance is positive, the new curve should
    6992                 :            :       // be longer than the original curve.
    6993                 :            :       if (i == 0)
    6994                 :            :       {
    6995                 :            :         double d_offset = offset_curve->measure();
    6996                 :            :         double d_orig = curve->measure();
    6997                 :            :         if ((offset_distance > 0 && d_offset < d_orig) ||
    6998                 :            :             (offset_distance < 0 && d_offset > d_orig))
    6999                 :            :         {
    7000                 :            :           for (int j = 0; j < curves.size(); ++j)
    7001                 :            :           {
    7002                 :            :             Ex.Next();
    7003                 :            :           }
    7004                 :            :           Ex.Next();
    7005                 :            :         }
    7006                 :            :         new_edge = Ex.Current();
    7007                 :            :         offset_curve = OCCQueryEngine::instance()->
    7008                 :            :             populate_topology_bridge(new_edge, CUBIT_TRUE);
    7009                 :            :       }
    7010                 :            :       new_curves.append(offset_curve);
    7011                 :            :       Ex.Next();
    7012                 :            :     }
    7013                 :            : 
    7014                 :            :     // successful offset of open wire
    7015                 :            :     return CUBIT_SUCCESS;
    7016                 :            :   }
    7017                 :            : 
    7018                 :            :   // if wire is closed
    7019                 :            :   for (BRepTools_WireExplorer Ex(wire); Ex.More(); Ex.Next())
    7020                 :            :   {
    7021                 :            :     TopoDS_Edge new_edge = Ex.Current();
    7022                 :            :     Curve* offset_curve = OCCQueryEngine::instance()->
    7023                 :            :         populate_topology_bridge(new_edge, CUBIT_TRUE);
    7024                 :            :     new_curves.append(offset_curve);
    7025                 :            :   }
    7026                 :            : 
    7027                 :            :   // successful offset of closed wire
    7028                 :            :   return CUBIT_SUCCESS;
    7029                 :            : 
    7030                 :            : #else
    7031                 :            : 
    7032                 :            :   // The behavior changed as of OCC 6.8 and OCE 0.17.
    7033                 :            :   // Not all cases have been tested.
    7034                 :            :   // Documentation in BRepFill_OffsetWire, which is used by
    7035                 :            :   // BRepOffsetAPI_MakeOffset, says that an offset will be "to the left"
    7036                 :            :   // of the spine wire, with each point at the specified offset from the
    7037                 :            :   // the closest point on the original wire.
    7038                 :            :   // Negative offsets are "to the right."
    7039                 :            :   // "Left" and "right" imply a normal direction on the face that contains
    7040                 :            :   // the wire.
    7041                 :            :   // The contract for this method in CGM is not documented well, but the
    7042                 :            :   // previous implementation suggests that a negative offset is intended
    7043                 :            :   // to return the shorter of the two open offset curves.  That may not be
    7044                 :            :   // well defined, and is hard to interpret when there are multiple
    7045                 :            :   // edges in the wire.
    7046                 :            :   //
    7047                 :            :   // When testing the offset functionality in a recent release version of
    7048                 :            :   // Cubit, it seemed that the direction of the offset depends on
    7049                 :            :   // how the wire turns.  If a closed wire has a positive turning number or
    7050                 :            :   // an open wire has what might be called a positive turning angle, then
    7051                 :            :   // the positive offset is to the right.  If the turning angle was
    7052                 :            :   // negative, then the positive offset was consistently to the left.
    7053                 :            :   // This behavior is independent of normal direction, since what appears
    7054                 :            :   // to be right and positive turning angle from one normal direction becomes
    7055                 :            :   // left and negative turning angle when the normal direction is flipped.
    7056                 :            : 
    7057                 :            :   // The current implementation here returns the result only if the number of
    7058                 :            :   // offset curves matches the number of input curves for both the
    7059                 :            :   // positive and negative offset.  In that situation, both the positive
    7060                 :            :   // and negative offsets are computed, the length of each wire is
    7061                 :            :   // computed, and the shorter result is returned if the offset is
    7062                 :            :   // negative.  The longer result is returned if the offset is positive.
    7063                 :            :   // If the lengths are equal then the curve(s) that OCC computed for the
    7064                 :            :   // offset with the same sign as the input offset are used.  This is
    7065                 :            :   // quite different from the behavior of Cubit, but passes the previously
    7066                 :            :   // existing offset_curves test and agrees with the local in-method
    7067                 :            :   // documentation that existed prior to OCC 6.8.
    7068                 :            : 
    7069                 :            :   // The WireExplorer is used in this method, which may miss some edges
    7070                 :            :   // if the result wire does not have all edges connected end to end.
    7071                 :            : 
    7072                 :         77 :   double positiveOffset = fabs(offset_distance);
    7073 [ +  - ][ +  - ]:        154 :   BRepOffsetAPI_MakeOffset posOffCurveBldr(wire);
    7074                 :            :   // Using an open offset, as in the following line, seems to produce results
    7075                 :            :   // closer to the original intent of this method, but the original behavior is
    7076                 :            :   // preserved better with the default Standard_False closed offset.
    7077                 :            : //  BRepOffsetAPI_MakeOffset posOffCurveBldr(wire, GeomAbs_Arc, Standard_True);
    7078         [ +  - ]:         77 :   posOffCurveBldr.Perform(positiveOffset);
    7079 [ +  - ][ +  - ]:        154 :   TopoDS_Shape posOffShape = posOffCurveBldr.Shape();
                 [ +  - ]
    7080 [ +  - ][ +  - ]:        154 :   TopoDS_Wire posOffWire = TopoDS::Wire(posOffShape);
                 [ +  - ]
    7081 [ +  - ][ +  - ]:         77 :   if (countEdges(posOffWire) != curves.size())
                 [ +  + ]
    7082                 :            :   {
    7083 [ +  - ][ +  - ]:         88 :       PRINT_ERROR("The number of positive offset curves computed by the OCE"
                 [ +  - ]
    7084                 :            :                   " geometry engine does not equal the number of curves in"
    7085         [ +  - ]:         44 :                   " the input.\n");
    7086                 :            :       // Remark: It appears to be possible to match curves in the output
    7087                 :            :       // to curves in the input by calling BRepOffsetAPI_MakeOffset::Generated.
    7088                 :            :       // One could also directly use BRepFill_OffsetWire.
    7089                 :            :       // Perhaps compounds curves could be constructed to make the
    7090                 :            :       // result curves match the input.
    7091                 :         44 :       return CUBIT_FAILURE;
    7092                 :            :   }
    7093                 :            : 
    7094                 :         33 :   double negativeOffset = -1.0*positiveOffset;
    7095 [ +  - ][ +  - ]:         66 :   BRepOffsetAPI_MakeOffset negOffCurveBldr(wire);
    7096                 :            :   // Using an open offset, as in the following line, seems to produce results
    7097                 :            :   // closer to the original intent of this method, but the original behavior is
    7098                 :            :   // preserved better with the default Standard_False closed offset.
    7099                 :            : //  BRepOffsetAPI_MakeOffset negOffCurveBldr(wire, GeomAbs_Arc, Standard_True);
    7100         [ +  - ]:         33 :   negOffCurveBldr.Perform(negativeOffset);
    7101 [ +  - ][ +  - ]:         66 :   TopoDS_Shape negOffShape = negOffCurveBldr.Shape();
                 [ +  - ]
    7102 [ +  - ][ +  - ]:         66 :   TopoDS_Wire negOffWire = TopoDS::Wire(negOffShape);
                 [ +  - ]
    7103 [ +  - ][ +  - ]:         33 :   if (countEdges(negOffWire) != curves.size())
                 [ -  + ]
    7104                 :            :   {
    7105 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("The number of negative offset curves computed by the OCE"
                 [ #  # ]
    7106                 :            :                   " geometry engine does not equal the number of curves in"
    7107         [ #  # ]:          0 :                   " the input.\n");
    7108                 :          0 :       return CUBIT_FAILURE;
    7109                 :            :   }
    7110                 :            : 
    7111                 :            :   // compute wire lengths and choose which wire to return
    7112                 :            :   TopoDS_Wire* wirePtrs[2];
    7113                 :            :   double wireLengths[2];
    7114                 :         33 :   wirePtrs[0] = &posOffWire;
    7115                 :         33 :   wirePtrs[1] = &negOffWire;
    7116                 :         33 :   wireLengths[0] = wireLengths[1] = 0.0;
    7117                 :            : 
    7118         [ +  + ]:         99 :   for (int wireIndex = 0; wireIndex < 2; ++wireIndex)
    7119                 :            :   {
    7120                 :         66 :     TopoDS_Wire* wirePtr = wirePtrs[wireIndex];
    7121                 :         66 :     double wireLen = 0.0;
    7122 [ +  - ][ +  - ]:        154 :     for (BRepTools_WireExplorer Ex(*wirePtr); Ex.More(); Ex.Next())
         [ +  - ][ +  + ]
    7123                 :            :     {
    7124         [ +  - ]:         88 :       GProp_GProps edgeProps;
    7125 [ +  - ][ +  - ]:         88 :       BRepGProp::LinearProperties(Ex.Current(), edgeProps);
    7126         [ +  - ]:         88 :       wireLen += edgeProps.Mass();
    7127         [ +  - ]:         66 :     }
    7128                 :         66 :     wireLengths[wireIndex] = wireLen;
    7129                 :            :   }
    7130                 :            : 
    7131                 :         33 :   TopoDS_Wire* chosenWirePtr = wirePtrs[0];
    7132         [ +  + ]:         33 :   if (offset_distance >= 0)
    7133                 :            :   {
    7134         [ +  + ]:         22 :     if (wireLengths[1] > wireLengths[0])
    7135                 :         11 :       chosenWirePtr = wirePtrs[1];
    7136                 :            :   }
    7137         [ -  + ]:         11 :   else if (wireLengths[1] <= wireLengths[0])
    7138                 :          0 :     chosenWirePtr = wirePtrs[1];
    7139                 :            : 
    7140 [ +  - ][ +  - ]:         77 :   for (BRepTools_WireExplorer Ex(*chosenWirePtr); Ex.More(); Ex.Next())
         [ +  - ][ +  + ]
    7141                 :            :   {
    7142                 :            :     Curve* offset_curve = OCCQueryEngine::instance()->
    7143 [ +  - ][ +  - ]:         44 :         populate_topology_bridge(Ex.Current(), CUBIT_TRUE);
                 [ +  - ]
    7144         [ +  - ]:         44 :     new_curves.append(offset_curve);
    7145         [ +  - ]:         33 :   }
    7146         [ +  - ]:        143 :   return CUBIT_SUCCESS;
    7147                 :            : #endif
    7148                 :            : }
    7149                 :            : 
    7150                 :            : //=============================================================================
    7151                 :            : // Function   : countEdges
    7152                 :            : // Member Type: private
    7153                 :            : // Description: Count the number of edges encountered by a
    7154                 :            : //     BRepTools_WireExplorer exploration of the specified wire.
    7155                 :            : //=============================================================================
    7156                 :        110 : int OCCModifyEngine::countEdges(TopoDS_Wire &wire)
    7157                 :            : {
    7158                 :        110 :   int numEdges = 0;
    7159 [ +  - ][ +  - ]:        550 :   for (BRepTools_WireExplorer Ex(wire); Ex.More(); Ex.Next())
         [ +  - ][ +  + ]
    7160         [ +  - ]:        110 :     ++numEdges;
    7161                 :        110 :   return numEdges;
    7162                 :            : }
    7163                 :            : 
    7164                 :            : //===============================================================================
    7165                 :            : // Function   : trim_curve
    7166                 :            : // Member Type: PUBLIC
    7167                 :            : // Description: 
    7168                 :            : // Author     : Jane Hu
    7169                 :            : // Date       : 12/08
    7170                 :            : //===============================================================================
    7171                 :          0 : Curve* OCCModifyEngine::trim_curve( Curve* trim_curve, 
    7172                 :            :                                     const CubitVector& trim_vector,
    7173                 :            :                                     const CubitVector& keep_vector,
    7174                 :            :                                     bool keep )
    7175                 :            : {
    7176         [ #  # ]:          0 :   OCCCurve* occ_crv = CAST_TO(trim_curve, OCCCurve);
    7177         [ #  # ]:          0 :   if(!occ_crv) 
    7178                 :            :   {
    7179 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("This is not a OCC curve to be trimmed.\n");
         [ #  # ][ #  # ]
    7180                 :          0 :     return (Curve*)NULL;
    7181                 :            :   }
    7182                 :            :   
    7183                 :            :   //Determine the trimmed curve's parameter range.
    7184                 :            :   double u1, u2;
    7185         [ #  # ]:          0 :   occ_crv->get_param_range(u1, u2);
    7186         [ #  # ]:          0 :   double trim_u = occ_crv->u_from_position(trim_vector);
    7187         [ #  # ]:          0 :   double keep_u = occ_crv->u_from_position(keep_vector);
    7188 [ #  # ][ #  # ]:          0 :   if(trim_u > u2+TOL || trim_u < u1 - TOL)
    7189                 :            :   {
    7190 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("The trim_vector is outside of the curve range.\n");
         [ #  # ][ #  # ]
    7191                 :          0 :     return (Curve*)NULL;
    7192                 :            :   }
    7193                 :            :  
    7194         [ #  # ]:          0 :   if(keep_u > trim_u )
    7195                 :          0 :      u1 =  trim_u;
    7196         [ #  # ]:          0 :   else if(keep_u < trim_u)
    7197                 :          0 :      u2 = trim_u;
    7198                 :            : 
    7199                 :            :   else
    7200                 :            :   {
    7201 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't determine which part of the curve to be kept.\n");
         [ #  # ][ #  # ]
    7202                 :          0 :     return (Curve*)NULL;
    7203                 :            :   }
    7204                 :            :   //get the Geom_Curve of the OCCCurve
    7205         [ #  # ]:          0 :   TopoDS_Edge * edge = occ_crv->get_TopoDS_Edge();
    7206                 :            :   Standard_Real first;
    7207                 :            :   Standard_Real last;
    7208         [ #  # ]:          0 :   Handle(Geom_Curve) myCurve = BRep_Tool::Curve(*edge, first, last);
    7209                 :            :  
    7210                 :            :   //Trim the curve
    7211 [ #  # ][ #  # ]:          0 :   TopoDS_Edge t_edge = BRepBuilderAPI_MakeEdge(myCurve, u1, u2);
         [ #  # ][ #  # ]
    7212 [ #  # ][ #  # ]:          0 :   Curve* t_curve = OCCQueryEngine::instance()->populate_topology_bridge(t_edge, CUBIT_TRUE);  
    7213         [ #  # ]:          0 :   if(!keep)
    7214                 :            :   {
    7215         [ #  # ]:          0 :     DLIList<OCCLoop*> loops = occ_crv->loops();
    7216 [ #  # ][ #  # ]:          0 :     if(loops.size() == 0)
    7217 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->delete_solid_model_entities(trim_curve);
                 [ #  # ]
    7218                 :            :   }
    7219         [ #  # ]:          0 :   return t_curve;
    7220                 :            : }
    7221                 :            : 
    7222                 :            : //===============================================================================
    7223                 :            : // Function   : create_body_from_surfs
    7224                 :            : // Member Type: PUBLIC
    7225                 :            : // Description:
    7226                 :            : // Author     : Jane Hu
    7227                 :            : // Date       : 4/22/08
    7228                 :            : //===============================================================================
    7229                 :          0 : CubitStatus OCCModifyEngine::create_solid_bodies_from_surfs(DLIList<Surface*> & ref_face_list,
    7230                 :            :                                           DLIList<BodySM*>& new_bodies,
    7231                 :            :                                           bool keep_old,
    7232                 :            :                                           bool heal,
    7233                 :            :                                           bool sheet) const
    7234                 :            : {
    7235                 :            :   //keep_old and heal are ignored, always delete old.
    7236                 :            :   //all surfaces should be stand along surface bodies or shell bodies' surface
    7237                 :          0 :   CubitStatus stat = CUBIT_SUCCESS;
    7238         [ #  # ]:          0 :   if(!sheet)
    7239                 :            :   {
    7240                 :          0 :     Lump* lump = make_Lump(ref_face_list);
    7241         [ #  # ]:          0 :     if (!lump)
    7242                 :          0 :       return CUBIT_FAILURE;
    7243                 :            :   
    7244 [ #  # ][ #  # ]:          0 :     new_bodies.append(CAST_TO(lump, OCCLump)->get_body());
    7245                 :            :   }
    7246                 :            :  
    7247                 :            :   else
    7248                 :            :   {
    7249         [ #  # ]:          0 :     DLIList<BodySM*> bodies;
    7250 [ #  # ][ #  # ]:          0 :     for(int i = 0 ; i < ref_face_list.size(); i++)
    7251                 :            :     {
    7252 [ #  # ][ #  # ]:          0 :       OCCSurface* surf = CAST_TO(ref_face_list.get_and_step(), OCCSurface);
    7253         [ #  # ]:          0 :       BodySM* body = surf->my_body();
    7254         [ #  # ]:          0 :       if(body)
    7255         [ #  # ]:          0 :         bodies.append_unique(body);
    7256                 :            :     }
    7257 [ #  # ][ #  # ]:          0 :     stat = unite(bodies, new_bodies, keep_old); 
    7258                 :            :   }
    7259                 :          0 :   return stat;
    7260                 :            : }
    7261                 :            : 
    7262                 :            : //===============================================================================
    7263                 :            : // Function   : create_arc_three
    7264                 :            : // Member Type: PUBLIC
    7265                 :            : // Description: 
    7266                 :            : // Author     : Jane Hu
    7267                 :            : // Date       : 12/08
    7268                 :            : //===============================================================================
    7269                 :         22 : Curve* OCCModifyEngine::create_arc_three( TBPoint* pt1, 
    7270                 :            :                                           TBPoint* pt2,
    7271                 :            :                                           TBPoint* pt3, 
    7272                 :            :                                           bool full,
    7273                 :            :                                           bool preview )
    7274                 :            : { 
    7275                 :         22 :   Curve* new_curve = NULL;
    7276         [ +  + ]:         22 :   if(!full)
    7277                 :            :   {
    7278         [ +  - ]:         11 :     CubitVector v2(pt2->coordinates());
    7279                 :            :     new_curve = const_cast<OCCModifyEngine*> (this)->
    7280         [ +  - ]:         11 :                   make_Curve(ARC_CURVE_TYPE,pt1,pt3, &v2);
    7281                 :            :   }
    7282                 :            :   else
    7283                 :            :   {
    7284         [ +  - ]:         11 :     CubitVector v1(pt1->coordinates());
    7285         [ +  - ]:         11 :     CubitVector v2(pt2->coordinates());
    7286         [ +  - ]:         11 :     CubitVector v3(pt3->coordinates());
    7287                 :            : 
    7288 [ +  - ][ +  - ]:         11 :     gp_Pnt gp_pt1(v1.x(),v1.y(), v1.z());
         [ +  - ][ +  - ]
    7289 [ +  - ][ +  - ]:         11 :     gp_Pnt gp_pt2(v2.x(),v2.y(), v2.z());
         [ +  - ][ +  - ]
    7290 [ +  - ][ +  - ]:         11 :     gp_Pnt gp_pt3(v3.x(),v3.y(), v3.z());
         [ +  - ][ +  - ]
    7291                 :            : 
    7292         [ +  - ]:         11 :     Handle(Geom_Circle) curve_ptr;
    7293 [ +  - ][ +  - ]:         11 :     curve_ptr = GC_MakeCircle(gp_pt1,gp_pt2,gp_pt3); 
         [ +  - ][ +  - ]
                 [ +  - ]
    7294                 :            : 
    7295         [ -  + ]:         11 :     OCCPoint* occ_pt1 = CAST_TO(const_cast<TBPoint*>(pt1),OCCPoint);
    7296         [ +  - ]:         11 :     TopoDS_Vertex * vt1 = occ_pt1->get_TopoDS_Vertex();
    7297 [ +  - ][ +  - ]:         22 :     TopoDS_Edge new_edge = BRepBuilderAPI_MakeEdge(curve_ptr, *vt1, *vt1);
         [ +  - ][ +  - ]
    7298                 :            :     new_curve = OCCQueryEngine::instance()->populate_topology_bridge(new_edge,
    7299 [ +  - ][ +  - ]:         22 :                                                                    CUBIT_TRUE);
                 [ +  - ]
    7300                 :            :   }
    7301         [ -  + ]:         22 :   if(preview)
    7302                 :            :   {
    7303                 :          0 :     GfxPreview::clear();
    7304         [ #  # ]:          0 :     OCCCurve* occ_curve = CAST_TO(new_curve, OCCCurve);
    7305                 :          0 :     TopoDS_Edge* h_edge = occ_curve->get_TopoDS_Edge();
    7306                 :            :     // Draw this edge
    7307                 :          0 :     OCCDrawTool::instance()->draw_EDGE( h_edge, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    7308                 :            :      
    7309                 :          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(new_curve);
    7310                 :          0 :     return (Curve*) NULL;
    7311                 :            :   }
    7312                 :            :   else
    7313                 :         22 :     return new_curve;
    7314                 :            : }
    7315                 :            : 
    7316                 :            : //===============================================================================
    7317                 :            : // Function   : create_arc_three
    7318                 :            : // Member Type: PUBLIC
    7319                 :            : // Description: 
    7320                 :            : // Author     : Jane Hu
    7321                 :            : // Date       : 12/08
    7322                 :            : //===============================================================================
    7323                 :          0 : Curve* OCCModifyEngine::create_arc_three( Curve* curve1, 
    7324                 :            :                                           Curve* curve2,
    7325                 :            :                                           Curve* curve3, 
    7326                 :            :                                           bool full, 
    7327                 :            :                                           bool preview  )
    7328                 :            : { 
    7329         [ #  # ]:          0 :   OCCCurve* occ_crv1 = CAST_TO(curve1, OCCCurve);
    7330         [ #  # ]:          0 :   OCCCurve* occ_crv2 = CAST_TO(curve2, OCCCurve);
    7331         [ #  # ]:          0 :   OCCCurve* occ_crv3 = CAST_TO(curve3, OCCCurve);
    7332         [ #  # ]:          0 :   GeometryType type1 = occ_crv1->geometry_type();
    7333         [ #  # ]:          0 :   GeometryType type2 = occ_crv2->geometry_type();
    7334         [ #  # ]:          0 :   GeometryType type3 = occ_crv3->geometry_type();
    7335 [ #  # ][ #  # ]:          0 :   if(type1 != STRAIGHT_CURVE_TYPE || type2 != STRAIGHT_CURVE_TYPE ||
                 [ #  # ]
    7336                 :            :      type3 != STRAIGHT_CURVE_TYPE)
    7337                 :            :   {
    7338 [ #  # ][ #  # ]:          0 :     PRINT_WARNING("Need three straight curves to calculate incenter.\n");
         [ #  # ][ #  # ]
    7339                 :          0 :     return (Curve*) NULL;
    7340                 :            :   } 
    7341                 :            :   
    7342                 :            :   //0.check that non of the curves are parallel of each other.
    7343         [ #  # ]:          0 :   DLIList<CubitVector> intscts;
    7344 [ #  # ][ #  # ]:          0 :   CubitVector vt1, vt2, vt3;
                 [ #  # ]
    7345                 :          0 :   CubitBoolean none = CUBIT_FALSE;
    7346 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->get_intersections(curve1, curve2, intscts,none,none);
    7347 [ #  # ][ #  # ]:          0 :   vt1 = intscts.get();
    7348         [ #  # ]:          0 :   intscts.clean_out();
    7349 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->get_intersections(curve2,curve3, intscts,none,none);
    7350 [ #  # ][ #  # ]:          0 :   vt2 = intscts.get();
    7351         [ #  # ]:          0 :   intscts.clean_out();
    7352 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->get_intersections(curve3, curve1, intscts,none,none);
    7353 [ #  # ][ #  # ]:          0 :   vt3 = intscts.get();
    7354                 :            : 
    7355                 :            :   double u11, u12, u21, u22, u31, u32;
    7356         [ #  # ]:          0 :   occ_crv1->get_param_range(u11, u12);
    7357         [ #  # ]:          0 :   occ_crv2->get_param_range(u21, u22);
    7358         [ #  # ]:          0 :   occ_crv3->get_param_range(u31, u32);
    7359                 :            : 
    7360 [ #  # ][ #  # ]:          0 :   CubitVector tangent1, tangent2, tangent3;
                 [ #  # ]
    7361         [ #  # ]:          0 :   occ_crv1->get_tangent(vt1, tangent1);
    7362         [ #  # ]:          0 :   occ_crv2->get_tangent(vt2, tangent2);
    7363         [ #  # ]:          0 :   occ_crv3->get_tangent(vt3, tangent3); 
    7364                 :            : 
    7365         [ #  # ]:          0 :   CubitVector normal1 = tangent1 * tangent2;
    7366         [ #  # ]:          0 :   CubitVector normal2 = tangent2 * tangent3;
    7367         [ #  # ]:          0 :   CubitVector normal3 = tangent3 * tangent1;
    7368 [ #  # ][ #  # ]:          0 :   if( normal1.length()< TOL || normal2.length()< TOL ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    7369         [ #  # ]:          0 :       normal3.length() < TOL )
    7370                 :            :   {
    7371 [ #  # ][ #  # ]:          0 :     PRINT_WARNING("Three curves must be able to form a triangle.\n");
         [ #  # ][ #  # ]
    7372                 :          0 :     return (Curve*) NULL;
    7373                 :            :   }
    7374                 :            : 
    7375                 :            :   //normals must parallel to each other, meaning all curves must be on
    7376                 :            :   //the same plane.
    7377         [ #  # ]:          0 :   normal1.normalize();
    7378         [ #  # ]:          0 :   normal2.normalize();
    7379         [ #  # ]:          0 :   normal3.normalize();
    7380                 :            :   
    7381         [ #  # ]:          0 :   CubitVector parallel1 = normal1 * normal2;
    7382         [ #  # ]:          0 :   CubitVector parallel2 = normal2 * normal3;
    7383         [ #  # ]:          0 :   CubitVector parallel3 = normal3 * normal1;
    7384 [ #  # ][ #  # ]:          0 :   if(parallel1.length() > TOL || parallel2.length() > TOL ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    7385         [ #  # ]:          0 :      parallel3.length() > TOL)
    7386                 :            :   {
    7387 [ #  # ][ #  # ]:          0 :     PRINT_WARNING("Three curves must be able to form a triangle.\n");
         [ #  # ][ #  # ]
    7388                 :          0 :     return (Curve*) NULL;
    7389                 :            :   }
    7390                 :            :   //1.find the angle between each of the two curves
    7391                 :            :   double angle1, angle2, angle3;
    7392         [ #  # ]:          0 :   angle1 = tangent1.interior_angle(tangent2);
    7393         [ #  # ]:          0 :   angle2 = tangent2.interior_angle(tangent3);
    7394         [ #  # ]:          0 :   angle3 = tangent3.interior_angle(tangent1);
    7395                 :            : 
    7396                 :            :   //2.create curves to bisection each of the angle passing through the
    7397                 :            :   // vertices of the triangle
    7398                 :            :   CubitVector t_curve11 = 
    7399         [ #  # ]:          0 :          vectorRotate(angle1/2.0, normal1, tangent1);  
    7400         [ #  # ]:          0 :   t_curve11.normalize();
    7401         [ #  # ]:          0 :   CubitVector p11 = vt1+t_curve11;
    7402                 :            : 
    7403                 :            :   CubitVector t_curve12 = 
    7404 [ #  # ][ #  # ]:          0 :          vectorRotate(90.0 - angle1/2.0, -normal1, tangent1);
    7405         [ #  # ]:          0 :   t_curve12.normalize();
    7406         [ #  # ]:          0 :   CubitVector p12 = vt1 + t_curve12;
    7407                 :            : 
    7408                 :            :   CubitVector t_curve21 =
    7409         [ #  # ]:          0 :          vectorRotate(angle2/2.0, normal2, tangent2);
    7410         [ #  # ]:          0 :   t_curve21.normalize();
    7411         [ #  # ]:          0 :   CubitVector p21 = vt2 + t_curve21;
    7412                 :            : 
    7413                 :            :   CubitVector t_curve22 = 
    7414 [ #  # ][ #  # ]:          0 :          vectorRotate(90.0 - angle2/2.0, -normal2, tangent2);
    7415         [ #  # ]:          0 :   t_curve22.normalize();
    7416         [ #  # ]:          0 :   CubitVector p22 = vt2 + t_curve22;
    7417                 :            : 
    7418                 :            :   CubitVector t_curve31 = 
    7419         [ #  # ]:          0 :          vectorRotate(angle3/2.0, normal3, tangent3);
    7420         [ #  # ]:          0 :   t_curve31.normalize();
    7421                 :            : 
    7422                 :            :   CubitVector t_curve32 =
    7423 [ #  # ][ #  # ]:          0 :          vectorRotate(90.0 - angle3/2.0, -normal3, tangent3);
    7424         [ #  # ]:          0 :   t_curve32.normalize();
    7425                 :            : 
    7426                 :            :   //3. find the three intersection points which when connected with the vertices,
    7427                 :            :   //intersect at same point.
    7428 [ #  # ][ #  # ]:          0 :   CubitVector line_p[4], c_p[4], c_ptemp;
         [ #  # ][ #  # ]
                 [ #  # ]
    7429                 :            :   double sc, tc;
    7430                 :            : 
    7431 [ #  # ][ #  # ]:          0 :   IntersectionTool int_tool;
    7432         [ #  # ]:          0 :   for(int i = 0; i < 4; i++)
    7433                 :            :   {
    7434         [ #  # ]:          0 :     if( i == 0)
    7435                 :            :     {
    7436         [ #  # ]:          0 :       line_p[0] = vt1;
    7437         [ #  # ]:          0 :       line_p[1] = p11;
    7438         [ #  # ]:          0 :       line_p[2] = vt2;
    7439         [ #  # ]:          0 :       line_p[3] = p21;
    7440                 :            :     } 
    7441         [ #  # ]:          0 :     else if(i == 1)
    7442         [ #  # ]:          0 :       line_p[3] = p22;
    7443         [ #  # ]:          0 :     else if(i == 2)
    7444         [ #  # ]:          0 :       line_p[1] = p12;
    7445                 :            :     else
    7446         [ #  # ]:          0 :       line_p[3] = p21;  
    7447                 :            :     int_tool.closest_points_on_segments(line_p[0], line_p[1], line_p[2],
    7448         [ #  # ]:          0 :                     line_p[3], c_ptemp, c_p[i], sc, tc);
    7449                 :            :         
    7450                 :            :     //check if the closeset point from c_p[i] to three curves are on three curves
    7451 [ #  # ][ #  # ]:          0 :     CubitVector closest1, closest2, closest3;
                 [ #  # ]
    7452         [ #  # ]:          0 :     occ_crv1->closest_point(c_p[i], closest1);
    7453         [ #  # ]:          0 :     double u = occ_crv1->u_from_position(closest1);
    7454 [ #  # ][ #  # ]:          0 :     if(u > u11-TOL && u < u12 + TOL)
    7455                 :            :     {
    7456         [ #  # ]:          0 :       occ_crv2->closest_point(c_p[i], closest2);
    7457         [ #  # ]:          0 :       u = occ_crv2->u_from_position(closest2);
    7458 [ #  # ][ #  # ]:          0 :       if(u > u21 - TOL && u < u22 + TOL)
    7459                 :            :       {
    7460         [ #  # ]:          0 :         occ_crv3->closest_point(c_p[i], closest3);
    7461         [ #  # ]:          0 :         u = occ_crv3->u_from_position(closest3);
    7462 [ #  # ][ #  # ]:          0 :         if(u > u31 - TOL && u < u32 + TOL)
    7463                 :            :         {
    7464                 :            :         //4. use the 3 intersection points to find the arc or circle.
    7465         [ #  # ]:          0 :           OCCPoint occ_p1(closest1);
    7466 [ #  # ][ #  # ]:          0 :           OCCPoint occ_p2(closest2);     
    7467 [ #  # ][ #  # ]:          0 :           OCCPoint occ_p3(closest3);
    7468 [ #  # ][ #  # ]:          0 :           return create_arc_three(&occ_p1, &occ_p2, &occ_p3, full, preview);
    7469                 :            :         } 
    7470                 :            :       }
    7471                 :            :     }
    7472                 :            :   }
    7473 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Can't find the tangent points to create circle.\n");
         [ #  # ][ #  # ]
    7474         [ #  # ]:          0 :   return (Curve*) NULL;
    7475                 :            : } 
    7476                 :            : 
    7477                 :            : //===============================================================================
    7478                 :            : // Function   : create_arc_center_edge
    7479                 :            : // Member Type: PUBLIC
    7480                 :            : // Description: 
    7481                 :            : // Author     : Jane Hu
    7482                 :            : // Date       : 12/08
    7483                 :            : //===============================================================================
    7484                 :          0 : Curve* OCCModifyEngine::create_arc_center_edge( TBPoint* pt1, 
    7485                 :            :                                                 TBPoint* pt2,
    7486                 :            :                                                 TBPoint* pt3,
    7487                 :            :                                                 const CubitVector& normal, 
    7488                 :            :                                                 double radius,
    7489                 :            :                                                 bool full,
    7490                 :            :                                                 bool preview ) 
    7491                 :            : { 
    7492         [ #  # ]:          0 :   CubitVector vec1 = pt1->coordinates(); // Center of arc
    7493         [ #  # ]:          0 :   CubitVector vec2 = pt2->coordinates(); // Position on arc
    7494         [ #  # ]:          0 :   CubitVector vec3 = pt3->coordinates(); // Position on arc
    7495                 :            : 
    7496         [ #  # ]:          0 :   CubitVector dir1( vec1, vec2 );
    7497         [ #  # ]:          0 :   CubitVector dir2( vec1, vec3 );
    7498                 :            :   // Re-adjust vec2, vec3 if radius was given
    7499         [ #  # ]:          0 :   if( radius != CUBIT_DBL_MAX )
    7500                 :            :   {
    7501         [ #  # ]:          0 :      CubitVector vec;
    7502         [ #  # ]:          0 :      vec1.next_point( dir1, radius, vec );
    7503 [ #  # ][ #  # ]:          0 :      if(vec.distance_between(vec2) > TOL)
    7504                 :            :      {
    7505         [ #  # ]:          0 :        vec2 = vec;
    7506 [ #  # ][ #  # ]:          0 :        pt2 = new OCCPoint(vec);
    7507                 :            :      }
    7508         [ #  # ]:          0 :      vec1.next_point( dir2, radius, vec );
    7509 [ #  # ][ #  # ]:          0 :      if(vec.distance_between(vec3) > TOL)
    7510                 :            :      {
    7511         [ #  # ]:          0 :        vec3 = vec;
    7512 [ #  # ][ #  # ]:          0 :        pt3 = new OCCPoint(vec);
    7513                 :            :      }
    7514                 :            :   }
    7515                 :            :  
    7516                 :            :   else
    7517                 :            :   {
    7518         [ #  # ]:          0 :     radius = vec1.distance_between(vec2);
    7519         [ #  # ]:          0 :     CubitVector vec;
    7520         [ #  # ]:          0 :     vec1.next_point( dir2, radius, vec );
    7521 [ #  # ][ #  # ]:          0 :     if(vec.distance_between(vec3) > TOL)
    7522                 :            :     {
    7523         [ #  # ]:          0 :        vec3 = vec;
    7524 [ #  # ][ #  # ]:          0 :        pt3 = new OCCPoint(vec);
    7525                 :            :     }
    7526                 :            :   }
    7527                 :            :  
    7528         [ #  # ]:          0 :   CubitVector normal_dir = normal;
    7529 [ #  # ][ #  # ]:          0 :   if(normal_dir.length() > TOL)
    7530                 :            :   {
    7531         [ #  # ]:          0 :     normal_dir.normalize();
    7532                 :            :     //verify sense
    7533 [ #  # ][ #  # ]:          0 :     if((dir1 * dir2) % normal_dir < 0.0)
                 [ #  # ]
    7534                 :            :     {
    7535                 :          0 :       TBPoint* p = pt2;
    7536                 :          0 :       pt2 = pt3;
    7537                 :          0 :       pt3 = p;
    7538                 :            :     }
    7539 [ #  # ][ #  # ]:          0 :     else if((dir1 * dir2) % normal_dir == 0.0)
                 [ #  # ]
    7540                 :            :     {
    7541 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Normal can't be on the plan of the arc.\n");
         [ #  # ][ #  # ]
    7542                 :          0 :       return (Curve*) NULL;
    7543                 :            :     }
    7544                 :            :   } 
    7545                 :            :   else 
    7546                 :            :   {
    7547 [ #  # ][ #  # ]:          0 :     normal_dir = dir1 * dir2;
    7548         [ #  # ]:          0 :     normal_dir.normalize();
    7549                 :            :   }
    7550                 :            :  
    7551         [ #  # ]:          0 :   Handle(Geom_Circle) curve_ptr;
    7552 [ #  # ][ #  # ]:          0 :   gp_Dir norm(normal_dir.x(), normal_dir.y(), normal_dir.z());
         [ #  # ][ #  # ]
    7553 [ #  # ][ #  # ]:          0 :   gp_Pnt center = gp_Pnt( vec1.x(), vec1.y(), vec1.z());
         [ #  # ][ #  # ]
    7554 [ #  # ][ #  # ]:          0 :   curve_ptr = GC_MakeCircle(center,norm,radius);
         [ #  # ][ #  # ]
                 [ #  # ]
    7555                 :            : 
    7556         [ #  # ]:          0 :   OCCPoint* occ_pt1 = CAST_TO(const_cast<TBPoint*>(pt2),OCCPoint);
    7557         [ #  # ]:          0 :   TopoDS_Vertex * vt1 = occ_pt1->get_TopoDS_Vertex();
    7558 [ #  # ][ #  # ]:          0 :   TopoDS_Edge new_edge;
    7559         [ #  # ]:          0 :   if(full)
    7560 [ #  # ][ #  # ]:          0 :     new_edge = BRepBuilderAPI_MakeEdge(curve_ptr, *vt1, *vt1);
         [ #  # ][ #  # ]
                 [ #  # ]
    7561                 :            :   
    7562                 :            :   else
    7563                 :            :   {
    7564         [ #  # ]:          0 :     Handle(Geom_TrimmedCurve) arc;
    7565 [ #  # ][ #  # ]:          0 :     gp_Pnt on_arc1 = gp_Pnt( vec2.x(), vec2.y(), vec2.z());
         [ #  # ][ #  # ]
    7566 [ #  # ][ #  # ]:          0 :     gp_Pnt on_arc2 = gp_Pnt( vec3.x(), vec3.y(), vec3.z());
         [ #  # ][ #  # ]
    7567 [ #  # ][ #  # ]:          0 :     arc = GC_MakeArcOfCircle(curve_ptr->Circ(), on_arc1, on_arc2, Standard_True);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7568         [ #  # ]:          0 :     OCCPoint* occ_pt2 = CAST_TO(const_cast<TBPoint*>(pt3),OCCPoint); 
    7569         [ #  # ]:          0 :     TopoDS_Vertex * vt2 = occ_pt2->get_TopoDS_Vertex();
    7570 [ #  # ][ #  # ]:          0 :     new_edge = BRepBuilderAPI_MakeEdge(arc, *vt1, *vt2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    7571                 :            :   } 
    7572                 :            : 
    7573         [ #  # ]:          0 :   if(preview)
    7574                 :            :   {
    7575         [ #  # ]:          0 :     GfxPreview::clear();
    7576                 :            :     // Draw this edge
    7577 [ #  # ][ #  # ]:          0 :     OCCDrawTool::instance()->draw_EDGE( &new_edge, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    7578                 :          0 :     return (Curve*) NULL;
    7579                 :            :   }
    7580 [ #  # ][ #  # ]:          0 :   return OCCQueryEngine::instance()->populate_topology_bridge(new_edge);
                 [ #  # ]
    7581                 :            : }
    7582                 :            : 
    7583                 :            : //===============================================================================
    7584                 :            : // Function   : create_curve_combine
    7585                 :            : // Member Type: PUBLIC
    7586                 :            : // Description: create a curve of combination of several curves.  
    7587                 :            : // Author     : Jane Hu 
    7588                 :            : // Date       : 03/09
    7589                 :            : //===============================================================================
    7590                 :            : 
    7591                 :            : CubitStatus 
    7592                 :          0 : OCCModifyEngine::create_curve_combine( DLIList<Curve*>& curve_list, 
    7593                 :            :                                     Curve *&new_curve_ptr )
    7594                 :            : {
    7595                 :            :   int i;
    7596                 :            : 
    7597 [ #  # ][ #  # ]:          0 :   DLIList<OCCCurve*> occ_curves(curve_list.size());
    7598 [ #  # ][ #  # ]:          0 :   CAST_LIST( curve_list, occ_curves, OCCCurve );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7599 [ #  # ][ #  # ]:          0 :   if (curve_list.size() != occ_curves.size())
                 [ #  # ]
    7600                 :            :   {
    7601 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("In OCCModifyEngine::create_curve_combine\n"
                 [ #  # ]
    7602         [ #  # ]:          0 :                 "       Not all input curves are OCC Curves.\n");
    7603                 :          0 :     return CUBIT_FAILURE;
    7604                 :            :   }
    7605                 :            :   
    7606 [ #  # ][ #  # ]:          0 :   BRepBuilderAPI_MakeWire aWire(*(occ_curves.get_and_step()->get_TopoDS_Edge()));
         [ #  # ][ #  # ]
    7607 [ #  # ][ #  # ]:          0 :   for(i =1 ; i < curve_list.size(); i++)
    7608                 :            :   {
    7609         [ #  # ]:          0 :     OCCCurve* curve = occ_curves.get_and_step();
    7610         [ #  # ]:          0 :     TopoDS_Edge* edge = curve->get_TopoDS_Edge();
    7611         [ #  # ]:          0 :       aWire.Add(*edge);
    7612 [ #  # ][ #  # ]:          0 :     if(!aWire.IsDone())
    7613                 :            :     {
    7614 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("In OCCModifyEngine::create_curve_combine\n"
                 [ #  # ]
    7615         [ #  # ]:          0 :                 "       The curves are not all connected.\n");
    7616                 :          0 :       return CUBIT_FAILURE;
    7617                 :            :     }
    7618                 :            :   }
    7619 [ #  # ][ #  # ]:          0 :   TopoDS_Wire wire = aWire.Wire(); 
                 [ #  # ]
    7620 [ #  # ][ #  # ]:          0 :   BRepAdaptor_CompCurve comp_curve(wire);
    7621         [ #  # ]:          0 :   GeomAbs_CurveType type = comp_curve.GetType();
    7622         [ #  # ]:          0 :   GeomAbs_Shape cont = comp_curve.Continuity();
    7623         [ #  # ]:          0 :   if(cont < GeomAbs_G1)
    7624                 :            :   {
    7625 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("In OCCModifyEngine::create_curve_combine\n"
                 [ #  # ]
    7626         [ #  # ]:          0 :                 "       The combined curve is not G1 continued.\n");
    7627                 :          0 :     return CUBIT_FAILURE;
    7628                 :            :   }
    7629                 :            : 
    7630                 :            :   //find the start/end vertices for the combined curve.
    7631         [ #  # ]:          0 :   double first_u = comp_curve.FirstParameter();
    7632         [ #  # ]:          0 :   double last_u = comp_curve.LastParameter();
    7633         [ #  # ]:          0 :   gp_Pnt first = comp_curve.Value(first_u);
    7634         [ #  # ]:          0 :   gp_Pnt last = comp_curve.Value(last_u);
    7635 [ #  # ][ #  # ]:          0 :   CubitVector first_v(first.X(), first.Y(), first.Z());
         [ #  # ][ #  # ]
    7636 [ #  # ][ #  # ]:          0 :   CubitVector last_v(last.X(), last.Y(), last.Z());
         [ #  # ][ #  # ]
    7637 [ #  # ][ #  # ]:          0 :   if(first_v.about_equal(last_v))
    7638         [ #  # ]:          0 :     comp_curve.SetPeriodic(Standard_True);
    7639                 :            : 
    7640 [ #  # ][ #  # ]:          0 :   DLIList<CubitVector> v_list;
    7641         [ #  # ]:          0 :   v_list.append(first_v);
    7642         [ #  # ]:          0 :   v_list.append(last_v);
    7643         [ #  # ]:          0 :   v_list.reset();
    7644                 :            : 
    7645 [ #  # ][ #  # ]:          0 :   DLIList<gp_Pnt*> V_list;
    7646         [ #  # ]:          0 :   for(int j = 0; j < 2; j++)
    7647                 :            :   {
    7648         [ #  # ]:          0 :     DLIList<TopologyBridge*> children;
    7649         [ #  # ]:          0 :     if (j == 0)
    7650         [ #  # ]:          0 :       occ_curves.reset();
    7651                 :            :     else
    7652         [ #  # ]:          0 :       occ_curves.last();
    7653 [ #  # ][ #  # ]:          0 :     occ_curves.get()->get_children_virt(children);
    7654 [ #  # ][ #  # ]:          0 :     CubitVector v = v_list.get_and_step();
    7655 [ #  # ][ #  # ]:          0 :     for(i = 0 ; i < children.size(); i++)
    7656                 :            :     {
    7657 [ #  # ][ #  # ]:          0 :       OCCPoint* vertex = CAST_TO(children.get_and_step(), OCCPoint); 
    7658         [ #  # ]:          0 :       CubitVector xyz = vertex->coordinates();
    7659 [ #  # ][ #  # ]:          0 :       if(xyz.about_equal(v))
    7660                 :            :       {
    7661 [ #  # ][ #  # ]:          0 :         gp_Pnt p ( v.x(), v.y(), v.z());
         [ #  # ][ #  # ]
    7662         [ #  # ]:          0 :         V_list.append(&p);
    7663                 :          0 :         break;
    7664                 :            :       }
    7665                 :            :     }
    7666         [ #  # ]:          0 :   }
    7667                 :            :    
    7668         [ #  # ]:          0 :   V_list.reset();
    7669 [ #  # ][ #  # ]:          0 :   TopoDS_Edge topo_edge; 
    7670         [ #  # ]:          0 :   gp_Lin line;
    7671         [ #  # ]:          0 :   gp_Circ circle;
    7672         [ #  # ]:          0 :   gp_Elips ellip;
    7673         [ #  # ]:          0 :   gp_Hypr hypr;
    7674         [ #  # ]:          0 :   gp_Parab parab;
    7675 [ #  # ][ #  # ]:          0 :   Handle_Geom_BezierCurve bezier;
    7676 [ #  # ][ #  # ]:          0 :   Handle_Geom_BSplineCurve spline;
    7677   [ #  #  #  #  :          0 :   switch(type)
             #  #  #  # ]
    7678                 :            :   {
    7679                 :            :     case GeomAbs_Line:
    7680         [ #  # ]:          0 :       line = comp_curve.Line();
    7681 [ #  # ][ #  # ]:          0 :       topo_edge = BRepBuilderAPI_MakeEdge(line,*V_list.get_and_step(), *V_list.get() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7682                 :          0 :       break;
    7683                 :            :     case GeomAbs_Circle:
    7684         [ #  # ]:          0 :       circle = comp_curve.Circle();
    7685 [ #  # ][ #  # ]:          0 :       topo_edge = BRepBuilderAPI_MakeEdge(circle,*V_list.get_and_step(), *V_list.get() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7686                 :          0 :       break;
    7687                 :            :     case GeomAbs_Ellipse:
    7688         [ #  # ]:          0 :       ellip = comp_curve.Ellipse();
    7689 [ #  # ][ #  # ]:          0 :       topo_edge = BRepBuilderAPI_MakeEdge(ellip,*V_list.get_and_step(), *V_list.get() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7690                 :          0 :       break;
    7691                 :            :     case GeomAbs_Hyperbola:
    7692         [ #  # ]:          0 :       hypr = comp_curve.Hyperbola();
    7693 [ #  # ][ #  # ]:          0 :       topo_edge = BRepBuilderAPI_MakeEdge(hypr,*V_list.get_and_step(), *V_list.get() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7694                 :          0 :       break;
    7695                 :            :     case GeomAbs_Parabola:
    7696         [ #  # ]:          0 :       parab = comp_curve.Parabola();
    7697 [ #  # ][ #  # ]:          0 :       topo_edge = BRepBuilderAPI_MakeEdge(parab,*V_list.get_and_step(), *V_list.get() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7698                 :          0 :       break;
    7699                 :            :     case GeomAbs_BezierCurve:
    7700 [ #  # ][ #  # ]:          0 :       bezier = comp_curve.Bezier();
                 [ #  # ]
    7701 [ #  # ][ #  # ]:          0 :       topo_edge = BRepBuilderAPI_MakeEdge(bezier,*V_list.get_and_step(), *V_list.get() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7702                 :          0 :       break;
    7703                 :            :     case GeomAbs_BSplineCurve:
    7704 [ #  # ][ #  # ]:          0 :       spline = comp_curve.BSpline();
                 [ #  # ]
    7705 [ #  # ][ #  # ]:          0 :       topo_edge = BRepBuilderAPI_MakeEdge(spline,*V_list.get_and_step(), *V_list.get() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7706                 :          0 :       break;
    7707                 :            :     default:
    7708 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("In OCCModifyEngine::create_curve_combine\n"
                 [ #  # ]
    7709         [ #  # ]:          0 :                 "       The combined curve is not G1 continued.\n");
    7710                 :          0 :       return CUBIT_FAILURE;
    7711                 :            :   }
    7712 [ #  # ][ #  # ]:          0 :   TopoDS_Edge *topo_edge_ptr = new TopoDS_Edge(topo_edge);
    7713 [ #  # ][ #  # ]:          0 :   OCCCurve* occ_c = new OCCCurve(topo_edge_ptr);
    7714                 :          0 :   new_curve_ptr = occ_c;
    7715         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    7716                 :            : }
    7717                 :            : 
    7718                 :            : //===============================================================================
    7719                 :            : // Function   : get_gqe
    7720                 :            : // Member Type: PUBLIC
    7721                 :            : // Description: get the facet geometry query engince instance pointer
    7722                 :            : // Author     : John Fowler
    7723                 :            : // Date       : 10/02
    7724                 :            : //===============================================================================
    7725                 :        735 : GeometryQueryEngine *OCCModifyEngine::get_gqe()
    7726                 :            : {
    7727                 :        735 :   return OCCQueryEngine::instance();
    7728                 :            : }
    7729                 :            : 
    7730                 :            : //===============================================================================
    7731                 :            : // Function   : is_modify_engine
    7732                 :            : // Member Type: PUBLIC
    7733                 :            : // Description: return CUBIT_TRUE if the tb_ptr belongs to this modify engine
    7734                 :            : // Author     : John Fowler
    7735                 :            : // Date       : 10/02
    7736                 :            : //===============================================================================
    7737                 :       1637 : CubitBoolean OCCModifyEngine::is_modify_engine(const TopologyBridge *tb_ptr) const 
    7738                 :            : {
    7739                 :       1637 :   return tb_ptr->get_geometry_query_engine() == OCCQueryEngine::instance();
    7740                 :            : }
    7741                 :            : 
    7742                 :            : //===============================================================================
    7743                 :            : // Function   : get_offset_intersections
    7744                 :            : // Member Type: PUBLIC
    7745                 :            : // Description: 
    7746                 :            : // Author     : Jane Hu
    7747                 :            : // Date       : 03/09
    7748                 :            : //===============================================================================
    7749                 :          0 : CubitStatus OCCModifyEngine::get_offset_intersections( Curve* curve1, 
    7750                 :            :                                               Curve* curve2,
    7751                 :            :                                               DLIList<CubitVector>& out_list,
    7752                 :            :                                               double offset,
    7753                 :            :                                               CubitBoolean ext_first ) 
    7754                 :            : {
    7755                 :            :   //offset the curve1 in both directions of normal direction of two curves at
    7756                 :            :   //center points.
    7757                 :            :     
    7758                 :          0 :   return CUBIT_SUCCESS;
    7759                 :            : }
    7760                 :            : 
    7761                 :            : //===============================================================================
    7762                 :            : // Function   : get_offset_intersections
    7763                 :            : // Member Type: PUBLIC
    7764                 :            : // Description: 
    7765                 :            : // Author     : Jane Hu
    7766                 :            : // Date       : 03/09
    7767                 :            : //===============================================================================
    7768                 :          0 : CubitStatus OCCModifyEngine::get_offset_intersections( Curve* curve1, 
    7769                 :            :                                            Surface* face_ptr,
    7770                 :            :                                            DLIList<CubitVector> & out_list,
    7771                 :            :                                            double offset,
    7772                 :            :                                            CubitBoolean ext_surf )
    7773                 :            : {
    7774                 :          0 :   Surface* new_surface = face_ptr;
    7775         [ #  # ]:          0 :   if(ext_surf)
    7776         [ #  # ]:          0 :     new_surface = make_Surface(face_ptr, CUBIT_TRUE);
    7777                 :            : 
    7778                 :          0 :   BodySM* bodysm = NULL;
    7779                 :          0 :   CubitStatus status = CUBIT_SUCCESS;
    7780         [ #  # ]:          0 :   status = create_offset_surface(new_surface, bodysm, offset); 
    7781         [ #  # ]:          0 :   if(status == CUBIT_FAILURE)
    7782                 :            :   {
    7783 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't offset surface. \n");
         [ #  # ][ #  # ]
    7784                 :          0 :     return status;
    7785                 :            :   }
    7786 [ #  # ][ #  # ]:          0 :   DLIList<OCCSurface*> surfaces = CAST_TO(bodysm, OCCBody)->my_sheet_surfaces();
    7787         [ #  # ]:          0 :   OCCSurface* surface = surfaces.get();
    7788 [ #  # ][ #  # ]:          0 :   status = OCCQueryEngine::instance()->get_intersections(curve1, surface, out_list);
    7789                 :            :   
    7790 [ #  # ][ #  # ]:          0 :   if(ext_surf || offset)
    7791 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(surface);
    7792                 :            :  
    7793                 :            :   //offset surface in opposite direction
    7794         [ #  # ]:          0 :   if(!offset)
    7795                 :          0 :     return status;
    7796                 :            : 
    7797         [ #  # ]:          0 :   status = create_offset_surface(new_surface, bodysm, -offset);
    7798         [ #  # ]:          0 :   if(status == CUBIT_FAILURE)
    7799                 :            :   {
    7800 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't offset surface. \n");
         [ #  # ][ #  # ]
    7801                 :          0 :     return status;
    7802                 :            :   }
    7803         [ #  # ]:          0 :   surfaces.clean_out();
    7804 [ #  # ][ #  # ]:          0 :   surfaces = CAST_TO(bodysm, OCCBody)->my_sheet_surfaces();
         [ #  # ][ #  # ]
    7805         [ #  # ]:          0 :   surface = surfaces.get();
    7806 [ #  # ][ #  # ]:          0 :   status = OCCQueryEngine::instance()->get_intersections(curve1, surface, out_list);
    7807 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->delete_solid_model_entities(surface);
    7808         [ #  # ]:          0 :   if(ext_surf)
    7809 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(new_surface);
    7810         [ #  # ]:          0 :   return status;
    7811                 :            : }
    7812                 :            : 
    7813                 :            : //===============================================================================
    7814                 :            : // Function   : surface_intersection
    7815                 :            : // Member Type: PUBLIC
    7816                 :            : // Description: 
    7817                 :            : // Author     : Jane Hu  
    7818                 :            : // Date       : 03/09
    7819                 :            : //===============================================================================
    7820                 :          0 : CubitStatus OCCModifyEngine::surface_intersection( Surface * surface1,
    7821                 :            :                                                    Surface * surface2,
    7822                 :            :                                                    DLIList<Curve*> &intscts,
    7823                 :            :                                                    const double tol) const
    7824                 :            : {
    7825         [ #  # ]:          0 :   OCCSurface *occ_surface1 =  CAST_TO(surface1, OCCSurface);
    7826         [ #  # ]:          0 :   if (occ_surface1 == NULL)
    7827                 :            :     {
    7828 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Option not supported for non-occ based geometry.\n");
         [ #  # ][ #  # ]
    7829                 :          0 :       return CUBIT_FAILURE;
    7830                 :            :     }
    7831                 :            : 
    7832         [ #  # ]:          0 :   OCCSurface *occ_surface2 =  CAST_TO(surface2, OCCSurface);
    7833         [ #  # ]:          0 :   if (occ_surface2 == NULL)
    7834                 :            :     {
    7835 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Option not supported for non-occ based geometry.\n");
         [ #  # ][ #  # ]
    7836                 :          0 :       return CUBIT_FAILURE;
    7837                 :            :     }
    7838                 :            :   
    7839                 :            :   //currently, there's no effect on 'closest' argument or bounded.
    7840         [ #  # ]:          0 :   BRepExtrema_DistShapeShape distShapeShape(*(occ_surface1->get_TopoDS_Face()),
    7841 [ #  # ][ #  # ]:          0 :                                             *(occ_surface2->get_TopoDS_Face()));
    7842                 :            : 
    7843                 :            :   //distShapeShape.Perform();
    7844 [ #  # ][ #  # ]:          0 :   if (!distShapeShape.IsDone())
    7845                 :            :     {
    7846 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Cannot calculate the intersection points for the input curve and surface.\n");
         [ #  # ][ #  # ]
    7847                 :          0 :       return CUBIT_FAILURE;
    7848                 :            :     }
    7849                 :            : 
    7850 [ #  # ][ #  # ]:          0 :   if (distShapeShape.Value() < tol) //intersect
    7851                 :            :     {
    7852         [ #  # ]:          0 :       int numSol = distShapeShape.NbSolution();
    7853         [ #  # ]:          0 :       for (int i = 1; i <= numSol; i++)
    7854                 :            :         {
    7855         [ #  # ]:          0 :           TopoDS_Shape shape = distShapeShape.SupportOnShape1(i);
    7856 [ #  # ][ #  # ]:          0 :           if(shape.ShapeType() != TopAbs_EDGE)
    7857                 :          0 :             continue;
    7858                 :            : 
    7859 [ #  # ][ #  # ]:          0 :           TopoDS_Edge* edge = new TopoDS_Edge(TopoDS::Edge(shape));
                 [ #  # ]
    7860 [ #  # ][ #  # ]:          0 :           OCCCurve* cv = new OCCCurve(edge);
    7861 [ #  # ][ #  # ]:          0 :           intscts.append(cv);
                 [ #  # ]
    7862                 :          0 :         }
    7863                 :            :     }
    7864                 :            : 
    7865         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    7866                 :            : }
    7867                 :            : 
    7868                 :            : //===============================================================================
    7869                 :            : // Function   : get_3_point_plane
    7870                 :            : // Member Type: PUBLIC
    7871                 :            : // Description:
    7872                 :            : // Author     : Jane Hu
    7873                 :            : // Date       : 01/11
    7874                 :            : //===============================================================================
    7875                 :          0 : CubitStatus OCCModifyEngine::get_3_point_plane( const CubitVector & point_1,
    7876                 :            :                                             const CubitVector & point_2,
    7877                 :            :                                             const CubitVector & point_3,
    7878                 :            :                                             TopoDS_Face*& p_face)const
    7879                 :            : {
    7880                 :            :   //Calculate normal of the plane
    7881 [ #  # ][ #  # ]:          0 :   CubitVector v1, v2, normal;
                 [ #  # ]
    7882 [ #  # ][ #  # ]:          0 :   v1 = point_2 - point_1;
    7883 [ #  # ][ #  # ]:          0 :   v2 = point_3 - point_1;
    7884 [ #  # ][ #  # ]:          0 :   normal = ~(v1 * v2);
                 [ #  # ]
    7885 [ #  # ][ #  # ]:          0 :   if(fabs(normal.length() - 1) > TOL)
    7886                 :            :   {
    7887 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("The three points are co-linear, and can't be used as a cutting plane.\n");
         [ #  # ][ #  # ]
    7888                 :          0 :      return CUBIT_FAILURE;
    7889                 :            :   }
    7890                 :            : 
    7891 [ #  # ][ #  # ]:          0 :   gp_Pnt pt = gp_Pnt( point_1.x(), point_1.y(), point_1.z());
         [ #  # ][ #  # ]
    7892 [ #  # ][ #  # ]:          0 :   gp_Dir normal_dir(normal.x(), normal.y(), normal.z());
         [ #  # ][ #  # ]
    7893         [ #  # ]:          0 :   gp_Pln plane(pt, normal_dir);
    7894                 :            : 
    7895 [ #  # ][ #  # ]:          0 :   TopoDS_Face face = BRepBuilderAPI_MakeFace(plane);
                 [ #  # ]
    7896 [ #  # ][ #  # ]:          0 :   p_face = new TopoDS_Face(face);
    7897         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    7898                 :            : }
    7899                 :            : 
    7900                 :            : //===============================================================================
    7901                 :            : // Function   : get_mid_plane
    7902                 :            : // Member Type: PUBLIC
    7903                 :            : // Description: 
    7904                 :            : // Author     : Jane Hu
    7905                 :            : // Date       : 01/09
    7906                 :            : //===============================================================================
    7907                 :         22 : CubitStatus OCCModifyEngine::get_mid_plane( const CubitVector & point_1,
    7908                 :            :                                             const CubitVector & point_2,
    7909                 :            :                                             const CubitVector & point_3,
    7910                 :            :                                             BodySM * body_to_trim_to,
    7911                 :            :                                             BodySM *& result_body ) const
    7912                 :            : {
    7913                 :            :   //Calculate normal of the mid  plane
    7914 [ +  - ][ +  - ]:         22 :   CubitVector v1, v2, normal;
                 [ +  - ]
    7915 [ +  - ][ +  - ]:         22 :   v1 = point_2 - point_1;
    7916 [ +  - ][ +  - ]:         22 :   v2 = point_3 - point_1;
    7917 [ +  - ][ +  - ]:         22 :   normal = ~(v1 * v2);
                 [ +  - ]
    7918 [ +  - ][ -  + ]:         22 :   if(fabs(normal.length() - 1) > TOL)
    7919                 :            :   {
    7920 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("The three points are co-linear, and can't be used as a cutting plane.\n");
         [ #  # ][ #  # ]
    7921                 :          0 :      return CUBIT_FAILURE;
    7922                 :            :   }
    7923                 :            :  
    7924 [ +  - ][ +  - ]:         22 :   gp_Pnt pt = gp_Pnt( point_1.x(), point_1.y(), point_1.z());
         [ +  - ][ +  - ]
    7925 [ +  - ][ +  - ]:         22 :   gp_Dir normal_dir(normal.x(), normal.y(), normal.z());
         [ +  - ][ +  - ]
    7926         [ +  - ]:         22 :   gp_Pln plane(pt, normal_dir);
    7927                 :            : 
    7928 [ +  - ][ +  - ]:         22 :   TopoDS_Face face = BRepBuilderAPI_MakeFace(plane);
                 [ +  - ]
    7929                 :            :   Surface *surf = OCCQueryEngine::instance()->populate_topology_bridge(face,
    7930 [ +  - ][ +  - ]:         22 :                                                CUBIT_TRUE);
    7931         [ -  + ]:         22 :   if(!surf)
    7932                 :            :   {
    7933 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't create cutting plane.\n");
         [ #  # ][ #  # ]
    7934                 :          0 :     return CUBIT_FAILURE;
    7935                 :            :   }
    7936                 :            :   
    7937 [ -  + ][ +  - ]:         22 :   BodySM* tool = CAST_TO(surf, OCCSurface)->my_body();
    7938 [ +  - ][ +  - ]:         44 :   DLIList<BodySM*> from_bodies;
    7939         [ +  - ]:         22 :   from_bodies.append(body_to_trim_to);
    7940 [ +  - ][ +  - ]:         44 :   DLIList<BodySM*> midplane_bodies;
    7941                 :            :   CubitStatus stat = intersect(tool, from_bodies, midplane_bodies, 
    7942         [ +  - ]:         22 :                                CUBIT_TRUE);
    7943 [ +  - ][ +  - ]:         22 :   OCCQueryEngine::instance()->delete_solid_model_entities(tool);
    7944 [ +  - ][ +  - ]:         22 :   if (midplane_bodies.size() == 1)
    7945         [ +  - ]:         22 :     result_body = midplane_bodies.get();
    7946                 :            :   else {
    7947 [ #  # ][ #  # ]:          0 :     for (int i = 0; i < midplane_bodies.size(); ++i)
    7948 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->delete_solid_model_entities(midplane_bodies.get_and_step());
                 [ #  # ]
    7949                 :          0 :     stat = CUBIT_FAILURE;
    7950                 :            :   }
    7951         [ +  - ]:         22 :   return stat;
    7952                 :            : }
    7953                 :            : 
    7954                 :            : //=============================================================================
    7955                 :            : // Function   : get_spheric_mid_surface
    7956                 :            : // Member Type: PUBLIC
    7957                 :            : // Description: Calculates a mid-surface between 2 spheric surfaces.
    7958                 :            : // Author     : Jane Hu
    7959                 :            : // Date       : 01/09
    7960                 :            : //=============================================================================
    7961                 :          0 : CubitStatus OCCModifyEngine::get_spheric_mid_surface( Surface* surface_ptr1,
    7962                 :            :                                     Surface* surface_ptr2,
    7963                 :            :                                     BodySM* body_to_trim_to,
    7964                 :            :                                     BodySM*& result_body ) const
    7965                 :            : {
    7966         [ #  # ]:          0 :   OCCSurface* occ_surf1 = CAST_TO(surface_ptr1, OCCSurface);
    7967         [ #  # ]:          0 :   OCCSurface* occ_surf2 = CAST_TO(surface_ptr2, OCCSurface);
    7968 [ #  # ][ #  # ]:          0 :   if(occ_surf1->geometry_type() != SPHERE_SURFACE_TYPE ||
         [ #  # ][ #  # ]
    7969         [ #  # ]:          0 :      occ_surf2->geometry_type() != SPHERE_SURFACE_TYPE)
    7970                 :            :   {
    7971 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Both surfaces provided should be sphere type.\n");
         [ #  # ][ #  # ]
    7972                 :          0 :     return CUBIT_FAILURE;
    7973                 :            :   }
    7974                 :            :  
    7975 [ #  # ][ #  # ]:          0 :   BRepAdaptor_Surface asurface1(*occ_surf1->get_TopoDS_Face());
    7976 [ #  # ][ #  # ]:          0 :   BRepAdaptor_Surface asurface2(*occ_surf2->get_TopoDS_Face());
                 [ #  # ]
    7977                 :            : 
    7978         [ #  # ]:          0 :   gp_Sphere sphere1 = asurface1.Sphere();
    7979         [ #  # ]:          0 :   gp_Sphere sphere2 = asurface2.Sphere();
    7980                 :            : 
    7981         [ #  # ]:          0 :   gp_Pnt center1 = sphere1.Location();
    7982         [ #  # ]:          0 :   gp_Pnt center2 = sphere2.Location();
    7983                 :            : 
    7984 [ #  # ][ #  # ]:          0 :   if(!center1.IsEqual(center2, TOL))
    7985                 :            :   {
    7986 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Spheres need to have the same center.\n");
         [ #  # ][ #  # ]
    7987                 :          0 :     return CUBIT_FAILURE;
    7988                 :            :   }
    7989                 :            : 
    7990 [ #  # ][ #  # ]:          0 :   double radius = sphere1.Radius()/2.0 + sphere2.Radius()/2.0;
    7991         [ #  # ]:          0 :   BodySM* tool = sphere(radius);
    7992 [ #  # ][ #  # ]:          0 :   CubitVector center(center1.X(), center1.Y(), center1.Z());
         [ #  # ][ #  # ]
    7993 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->translate(tool, center);
    7994                 :            : 
    7995                 :            :   //get the tool surfaces as the tool
    7996 [ #  # ][ #  # ]:          0 :   DLIList<Surface*> surfaces;
    7997         [ #  # ]:          0 :   tool->surfaces(surfaces);
    7998 [ #  # ][ #  # ]:          0 :   assert (surfaces.size() == 1);
    7999 [ #  # ][ #  # ]:          0 :   tool = make_BodySM(surfaces.get());
    8000                 :            : 
    8001 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> from_bodies, midsurface_bodies;
         [ #  # ][ #  # ]
    8002         [ #  # ]:          0 :   from_bodies.append(body_to_trim_to);
    8003                 :            : 
    8004                 :            :   CubitStatus stat = intersect(tool, from_bodies, midsurface_bodies,
    8005         [ #  # ]:          0 :                                CUBIT_TRUE);
    8006 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->delete_solid_model_entities(tool);
    8007 [ #  # ][ #  # ]:          0 :   if (midsurface_bodies.size() == 1)
    8008         [ #  # ]:          0 :     result_body = midsurface_bodies.get();
    8009                 :            :   else {
    8010 [ #  # ][ #  # ]:          0 :     for (int i = 0; i < midsurface_bodies.size(); ++i)
    8011 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->delete_solid_model_entities(midsurface_bodies.get_and_step());
                 [ #  # ]
    8012                 :          0 :     stat = CUBIT_FAILURE;
    8013                 :            :   }
    8014                 :            : 
    8015         [ #  # ]:          0 :   return stat;  
    8016                 :            : }
    8017                 :            : 
    8018                 :            : //=============================================================================
    8019                 :            : // Function   : get_conic_mid_surface
    8020                 :            : // Member Type: PUBLIC
    8021                 :            : // Description: Calculates a mid-surface between 2 conic surfaces.
    8022                 :            : // Author     : Jane Hu
    8023                 :            : // Date       : 01/09
    8024                 :            : //=============================================================================
    8025                 :          0 : CubitStatus OCCModifyEngine::get_conic_mid_surface( Surface* surface_ptr1,
    8026                 :            :                                     Surface* surface_ptr2,
    8027                 :            :                                     BodySM* body_to_trim_to,
    8028                 :            :                                     BodySM*& result_body ) const
    8029                 :            : {
    8030         [ #  # ]:          0 :   OCCSurface* occ_surf1 = CAST_TO(surface_ptr1, OCCSurface);
    8031         [ #  # ]:          0 :   OCCSurface* occ_surf2 = CAST_TO(surface_ptr2, OCCSurface);
    8032 [ #  # ][ #  # ]:          0 :   if(occ_surf1->geometry_type() != CONE_SURFACE_TYPE ||
         [ #  # ][ #  # ]
    8033         [ #  # ]:          0 :      occ_surf2->geometry_type() != CONE_SURFACE_TYPE)
    8034                 :            :   {
    8035 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Both surfaces provided should be conic type.\n");
         [ #  # ][ #  # ]
    8036                 :          0 :     return CUBIT_FAILURE;
    8037                 :            :   }  
    8038                 :            : 
    8039 [ #  # ][ #  # ]:          0 :   BRepAdaptor_Surface asurface1(*occ_surf1->get_TopoDS_Face());
    8040 [ #  # ][ #  # ]:          0 :   BRepAdaptor_Surface asurface2(*occ_surf2->get_TopoDS_Face());
                 [ #  # ]
    8041                 :            : 
    8042         [ #  # ]:          0 :   GeomAbs_SurfaceType  type1 = asurface1.GetType();
    8043         [ #  # ]:          0 :   GeomAbs_SurfaceType  type2 = asurface2.GetType();
    8044         [ #  # ]:          0 :   if(type1 != type2)
    8045                 :            :   {
    8046 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Both surfaces provided should be both cylinder or cone type.\n");
         [ #  # ][ #  # ]
    8047                 :          0 :     return CUBIT_FAILURE;
    8048                 :            :   }
    8049                 :            : 
    8050 [ #  # ][ #  # ]:          0 :   CubitBox bounding_box = GeometryQueryTool::instance()->model_bounding_box();
                 [ #  # ]
    8051 [ #  # ][ #  # ]:          0 :   double height = (bounding_box.diagonal()).length();
    8052         [ #  # ]:          0 :   OCCBody* body = CAST_TO(body_to_trim_to, OCCBody);
    8053         [ #  # ]:          0 :   CubitVector centroid;
    8054                 :            :   double volume;
    8055         [ #  # ]:          0 :   body->mass_properties(centroid, volume);
    8056                 :            :   BodySM* tool;
    8057         [ #  # ]:          0 :   if(type1 == GeomAbs_Cylinder)
    8058                 :            :   {
    8059         [ #  # ]:          0 :     gp_Cylinder cyl1 = asurface1.Cylinder();
    8060         [ #  # ]:          0 :     gp_Cylinder cyl2 = asurface2.Cylinder(); 
    8061         [ #  # ]:          0 :     gp_Ax1  axis1 = cyl1.Axis();
    8062         [ #  # ]:          0 :     gp_Ax1  axis2 = cyl2.Axis();
    8063 [ #  # ][ #  # ]:          0 :     if(!axis1.IsCoaxial(axis2, 0.001, TOL))
    8064                 :            :     {
    8065 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Cylinders need to have the same axis of symmetry.\n");
         [ #  # ][ #  # ]
    8066                 :          0 :       return CUBIT_FAILURE;
    8067                 :            :     }
    8068 [ #  # ][ #  # ]:          0 :     double radius = cyl1.Radius()/2.0 + cyl2.Radius()/2.0; 
    8069         [ #  # ]:          0 :     gp_Ax2 axis;
    8070         [ #  # ]:          0 :     axis.SetAxis(axis1);
    8071 [ #  # ][ #  # ]:          0 :     TopoDS_Solid S = BRepPrimAPI_MakeCylinder(axis, radius, height);
                 [ #  # ]
    8072                 :            : 
    8073                 :            :     Lump* lump = OCCQueryEngine::instance()->populate_topology_bridge(S,
    8074 [ #  # ][ #  # ]:          0 :                                                                 CUBIT_TRUE);
    8075                 :            : 
    8076         [ #  # ]:          0 :     if (lump == NULL)
    8077                 :            :     {
    8078 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("In OCCModifyEngine::get_conic_mid_surface\n"
                 [ #  # ]
    8079         [ #  # ]:          0 :                   "   Cannot create a cylinder for given radius.\n");
    8080                 :          0 :       return CUBIT_FAILURE;
    8081                 :            :     }
    8082                 :            : 
    8083 [ #  # ][ #  # ]:          0 :     tool = CAST_TO(lump, OCCLump)->get_body();
    8084         [ #  # ]:          0 :     double z = centroid.z();
    8085                 :          0 :     z -= height/2.0;
    8086         [ #  # ]:          0 :     centroid.z(z);
    8087 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->translate(tool, centroid);  
         [ #  # ][ #  # ]
    8088                 :            :   }
    8089                 :            : 
    8090                 :            :   else  //GeomAbs_Cone
    8091                 :            :   {
    8092         [ #  # ]:          0 :     gp_Cone cone1 = asurface1.Cone();
    8093         [ #  # ]:          0 :     gp_Cone cone2 = asurface2.Cone();
    8094         [ #  # ]:          0 :     double angle1 = cone1.SemiAngle();
    8095         [ #  # ]:          0 :     double angle2 = cone2.SemiAngle();
    8096         [ #  # ]:          0 :     if(fabs(angle1 - angle2) > 0.001)
    8097                 :            :     {
    8098 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Cones do not have the same semi-angle.\n");
         [ #  # ][ #  # ]
    8099                 :          0 :       return CUBIT_FAILURE;
    8100                 :            :     }
    8101         [ #  # ]:          0 :     gp_Ax1  axis1 = cone1.Axis();
    8102         [ #  # ]:          0 :     gp_Ax1  axis2 = cone2.Axis();
    8103 [ #  # ][ #  # ]:          0 :     if(!axis1.IsCoaxial(axis2, 0.001, TOL))
    8104                 :            :     {
    8105 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Cones need to have the same axis of symmetry.\n");
         [ #  # ][ #  # ]
    8106                 :          0 :       return CUBIT_FAILURE;
    8107                 :            :     } 
    8108 [ #  # ][ #  # ]:          0 :     if(axis1.IsOpposite(axis2, 0.001))
    8109                 :            :     {
    8110 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Cones need to have the same orientation of axis.\n");
         [ #  # ][ #  # ]
    8111                 :          0 :       return CUBIT_FAILURE;
    8112                 :            :     }
    8113 [ #  # ][ #  # ]:          0 :     double r1 = cone1.RefRadius()/2.0 + cone2.RefRadius()/2.0; 
    8114         [ #  # ]:          0 :     gp_Ax3 axis;
    8115         [ #  # ]:          0 :     axis.SetAxis(axis1);
    8116         [ #  # ]:          0 :     gp_Cone cone(axis, angle1, r1);
    8117 [ #  # ][ #  # ]:          0 :     TopoDS_Face face = BRepBuilderAPI_MakeFace(cone);
                 [ #  # ]
    8118                 :            :     Surface* surface = 
    8119 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->populate_topology_bridge(face, CUBIT_TRUE);
    8120 [ #  # ][ #  # ]:          0 :     tool = CAST_TO(surface,OCCSurface)->my_body();  
                 [ #  # ]
    8121                 :            :   } 
    8122 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> from_bodies, midsurface_bodies;
         [ #  # ][ #  # ]
    8123         [ #  # ]:          0 :   from_bodies.append(body_to_trim_to);
    8124                 :            : 
    8125                 :            :   CubitStatus stat = intersect(tool, from_bodies, midsurface_bodies,
    8126         [ #  # ]:          0 :                                CUBIT_TRUE);
    8127 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->delete_solid_model_entities(tool);
    8128 [ #  # ][ #  # ]:          0 :   if (midsurface_bodies.size() == 1)
    8129         [ #  # ]:          0 :     result_body = midsurface_bodies.get();
    8130                 :            :   else {
    8131 [ #  # ][ #  # ]:          0 :     for (int i = 0; i < midsurface_bodies.size(); ++i)
    8132 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->delete_solid_model_entities(midsurface_bodies.get_and_step());
                 [ #  # ]
    8133                 :          0 :     stat = CUBIT_FAILURE;
    8134                 :            :   }
    8135                 :            : 
    8136         [ #  # ]:          0 :   return stat;
    8137                 :            : }
    8138                 :            : 
    8139                 :            : //=============================================================================
    8140                 :            : // Function   : get_toric_mid_surface
    8141                 :            : // Member Type: PUBLIC
    8142                 :            : // Description: Calculates a mid-surface between 2 toric surfaces.
    8143                 :            : // Author     : Jane Hu
    8144                 :            : // Date       : 01/09
    8145                 :            : //=============================================================================
    8146                 :          0 : CubitStatus OCCModifyEngine::get_toric_mid_surface( Surface* surface_ptr1,
    8147                 :            :                                      Surface* surface_ptr2,
    8148                 :            :                                      BodySM* body_to_trim_to,
    8149                 :            :                                      BodySM*& result_body ) const
    8150                 :            : {
    8151         [ #  # ]:          0 :   OCCSurface* occ_surf1 = CAST_TO(surface_ptr1, OCCSurface);
    8152         [ #  # ]:          0 :   OCCSurface* occ_surf2 = CAST_TO(surface_ptr2, OCCSurface);
    8153 [ #  # ][ #  # ]:          0 :   if(occ_surf1->geometry_type() != TORUS_SURFACE_TYPE ||
         [ #  # ][ #  # ]
    8154         [ #  # ]:          0 :      occ_surf2->geometry_type() != TORUS_SURFACE_TYPE)
    8155                 :            :   {
    8156 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Both surfaces provided should be toric type.\n");
         [ #  # ][ #  # ]
    8157                 :          0 :     return CUBIT_FAILURE;
    8158                 :            :   }
    8159                 :            : 
    8160 [ #  # ][ #  # ]:          0 :   BRepAdaptor_Surface asurface1(*occ_surf1->get_TopoDS_Face());
    8161 [ #  # ][ #  # ]:          0 :   BRepAdaptor_Surface asurface2(*occ_surf2->get_TopoDS_Face());
                 [ #  # ]
    8162                 :            : 
    8163         [ #  # ]:          0 :   gp_Torus torus1 = asurface1.Torus();
    8164         [ #  # ]:          0 :   gp_Torus torus2 = asurface2.Torus();
    8165                 :            : 
    8166         [ #  # ]:          0 :   gp_Pnt center1 = torus1.Location();
    8167         [ #  # ]:          0 :   gp_Pnt center2 = torus2.Location();
    8168                 :            : 
    8169 [ #  # ][ #  # ]:          0 :   if(!center1.IsEqual(center2, TOL))
    8170                 :            :   {
    8171 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Torii need to have the same center.\n");
         [ #  # ][ #  # ]
    8172                 :          0 :     return CUBIT_FAILURE;
    8173                 :            :   }
    8174                 :            : 
    8175         [ #  # ]:          0 :   double major_r1 = torus1.MajorRadius();
    8176         [ #  # ]:          0 :   double major_r2 = torus2.MajorRadius();
    8177         [ #  # ]:          0 :   if(fabs(major_r1 - major_r2) > TOL)
    8178                 :            :   {
    8179 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Torii need to have the same major radius.\n");
         [ #  # ][ #  # ]
    8180                 :          0 :     return CUBIT_FAILURE;
    8181                 :            :   }
    8182                 :            : 
    8183         [ #  # ]:          0 :   gp_Ax1 axis1 = torus1.Axis();
    8184         [ #  # ]:          0 :   gp_Ax1 axis2 = torus2.Axis();
    8185 [ #  # ][ #  # ]:          0 :   if(!axis1.IsCoaxial(axis2, 0.001, TOL))
    8186                 :            :   {
    8187 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Torii need to have the same axis of symmetry.\n");
         [ #  # ][ #  # ]
    8188                 :          0 :     return CUBIT_FAILURE;
    8189                 :            :   }
    8190                 :            : 
    8191 [ #  # ][ #  # ]:          0 :   double radius = torus1.MinorRadius()/2.0 + torus2.MinorRadius()/2.0;
    8192         [ #  # ]:          0 :   gp_Ax2 axis;
    8193         [ #  # ]:          0 :   axis.SetAxis(axis1);
    8194 [ #  # ][ #  # ]:          0 :   TopoDS_Solid S = BRepPrimAPI_MakeTorus(axis, major_r1, radius);
         [ #  # ][ #  # ]
    8195                 :            : 
    8196                 :            :   Lump* lump = OCCQueryEngine::instance()->populate_topology_bridge(S,
    8197 [ #  # ][ #  # ]:          0 :                                                                 CUBIT_TRUE);
    8198                 :            : 
    8199         [ #  # ]:          0 :   if (lump == NULL)
    8200                 :            :   {
    8201 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("In OCCModifyEngine::get_toric_mid_surface\n"
                 [ #  # ]
    8202         [ #  # ]:          0 :                 "   Cannot create a torus for given radii.\n");
    8203                 :          0 :     return CUBIT_FAILURE;
    8204                 :            :   }
    8205                 :            : 
    8206 [ #  # ][ #  # ]:          0 :   BodySM* tool = CAST_TO(lump, OCCLump)->get_body();
    8207                 :            : 
    8208 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> from_bodies, midsurface_bodies;
         [ #  # ][ #  # ]
    8209         [ #  # ]:          0 :   from_bodies.append(body_to_trim_to);
    8210                 :            : 
    8211                 :            :   CubitStatus stat = intersect(tool, from_bodies, midsurface_bodies,
    8212         [ #  # ]:          0 :                                CUBIT_TRUE);
    8213 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->delete_solid_model_entities(tool);
    8214 [ #  # ][ #  # ]:          0 :   if (midsurface_bodies.size() == 1)
    8215         [ #  # ]:          0 :     result_body = midsurface_bodies.get();
    8216                 :            :   else {
    8217 [ #  # ][ #  # ]:          0 :     for (int i = 0; i < midsurface_bodies.size(); ++i)
    8218 [ #  # ][ #  # ]:          0 :       OCCQueryEngine::instance()->delete_solid_model_entities(midsurface_bodies.get_and_step());
                 [ #  # ]
    8219                 :          0 :     stat = CUBIT_FAILURE;
    8220                 :            :   }
    8221                 :            : 
    8222         [ #  # ]:          0 :   return stat; 
    8223                 :            : }
    8224                 :            : 
    8225                 :            : //=============================================================================
    8226                 :            : // Function   : tweak_chamfer
    8227                 :            : // Member Type: PUBLIC
    8228                 :            : // Description: Chamfer curves on solid bodies.  The left and right offsets are
    8229                 :            : //              with respect to the curve direction.  If the given right offset
    8230                 :            : //              is negative, the left offset is used.  Users can preview to
    8231                 :            : //              clarify the meaning of left and right.
    8232                 :            : // Author     : Jane Hu
    8233                 :            : // Date       : 03/2009
    8234                 :            : //=============================================================================
    8235                 :          0 : CubitStatus OCCModifyEngine::tweak_chamfer( DLIList<Curve*> & curve_list, 
    8236                 :            :                                             double left_offset,
    8237                 :            :                                             DLIList<BodySM*> & new_bodysm_list,
    8238                 :            :                                             double right_offset,
    8239                 :            :                                             CubitBoolean keep_old_body,
    8240                 :            :                                             CubitBoolean preview ) const
    8241                 :            : {
    8242                 :            :   CubitStatus stat;
    8243                 :          0 :   int count = 0;
    8244         [ #  # ]:          0 :   if(right_offset <= 0.0)
    8245                 :          0 :     right_offset = left_offset;
    8246                 :            : 
    8247         [ #  # ]:          0 :   for(int i = 0; i < curve_list.size(); i++)
    8248                 :            :   {
    8249                 :          0 :     BodySM * new_bodysm_ptr = NULL;
    8250         [ #  # ]:          0 :     stat = tweak_fillet(curve_list.get_and_step(), left_offset, right_offset,
    8251         [ #  # ]:          0 :                       new_bodysm_ptr , keep_old_body, CUBIT_FALSE, CUBIT_FALSE);
    8252 [ #  # ][ #  # ]:          0 :     if(stat && new_bodysm_ptr)
    8253                 :            :     {
    8254         [ #  # ]:          0 :       new_bodysm_list.append_unique(new_bodysm_ptr);
    8255         [ #  # ]:          0 :       count = new_bodysm_list.size();
    8256                 :            :     }
    8257                 :            :     else
    8258                 :            :       break;
    8259                 :            :   }
    8260                 :            : 
    8261         [ #  # ]:          0 :   if(count == 0)
    8262                 :          0 :     return CUBIT_FAILURE;
    8263                 :            : 
    8264         [ #  # ]:          0 :   if(preview)
    8265                 :            :   {
    8266                 :          0 :     GfxPreview::clear();
    8267         [ #  # ]:          0 :     for(int i = 0; i < new_bodysm_list.size(); i++)
    8268                 :            :     {
    8269         [ #  # ]:          0 :       BodySM* new_bodysm = new_bodysm_list.get_and_step();
    8270                 :            :       TopoDS_Shape* modified_shape; 
    8271 [ #  # ][ #  # ]:          0 :       CAST_TO(new_bodysm, OCCBody)->get_TopoDS_Shape(modified_shape);
    8272         [ #  # ]:          0 :       TopExp_Explorer Ex;
    8273         [ #  # ]:          0 :       Ex.Init(*modified_shape, TopAbs_FACE);
    8274 [ #  # ][ #  # ]:          0 :       for( ; Ex.More(); Ex.Next() )
                 [ #  # ]
    8275                 :            :       {
    8276 [ #  # ][ #  # ]:          0 :         TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    8277                 :            :         // Draw this face
    8278 [ #  # ][ #  # ]:          0 :         OCCDrawTool::instance()->draw_FACE( &face, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    8279         [ #  # ]:          0 :       }
    8280         [ #  # ]:          0 :     }
    8281                 :          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(new_bodysm_list);
    8282                 :          0 :     new_bodysm_list.clean_out();
    8283                 :            :   }
    8284                 :            : 
    8285                 :          0 :   return CUBIT_SUCCESS;
    8286                 :            : }
    8287                 :            : 
    8288                 :            : //=============================================================================
    8289                 :            : // Function   : tweak_chamfer
    8290                 :            : // Member Type: PUBLIC
    8291                 :            : // Description: Chamfer vertices on solid or sheet bodies.  On a solid body 
    8292                 :            : //              there can be up to 3 offsets; on a sheet body up to 2 offsets.
    8293                 :            : //              The offsets are in the direction of the supplied edges.  If 
    8294                 :            : //              multiple vertices are supplied, only one offset value is 
    8295                 :            : //              allowed and the edges are not used.
    8296                 :            : // Author     : Jane Hu
    8297                 :            : // Date       : 03/09
    8298                 :            : //=============================================================================
    8299                 :            : CubitStatus
    8300                 :          0 : OCCModifyEngine::tweak_chamfer( DLIList<TBPoint*> & point_list, 
    8301                 :            :                                 double offset1,
    8302                 :            :                                 DLIList<BodySM*> & new_bodysm_list,
    8303                 :            :                                 Curve * edge1,
    8304                 :            :                                 double offset2,
    8305                 :            :                                 Curve * edge2,
    8306                 :            :                                 double offset3,
    8307                 :            :                                 Curve * edge3,
    8308                 :            :                                 CubitBoolean keep_old_body,
    8309                 :            :                                 CubitBoolean preview ) const
    8310                 :            : {
    8311                 :            :   // Sort out vertices between sheet and solid bodies
    8312 [ #  # ][ #  # ]:          0 :   DLIList<TBPoint*> solid_points, sheet_points;
                 [ #  # ]
    8313 [ #  # ][ #  # ]:          0 :   DLIList<OCCSurface*> s_list;
    8314 [ #  # ][ #  # ]:          0 :   DLIList<OCCBody*> bodies;
    8315         [ #  # ]:          0 :   if( sort_points_by_body_type( point_list, solid_points, sheet_points, 
    8316         [ #  # ]:          0 :                                 s_list, bodies ) == CUBIT_FAILURE )
    8317                 :          0 :     return CUBIT_FAILURE;
    8318                 :            : 
    8319 [ #  # ][ #  # ]:          0 :   if(solid_points.size() > 0 && solid_points.size() != bodies.size())
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    8320                 :            :   {
    8321 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "cannot find bodies corresponding to the points.\n" );
         [ #  # ][ #  # ]
    8322                 :          0 :     return CUBIT_FAILURE;
    8323                 :            :   }
    8324                 :            : 
    8325 [ #  # ][ #  # ]:          0 :   if(sheet_points.size() > 0 && sheet_points.size() != s_list.size())
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    8326                 :            :   {
    8327 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "cannot find surfaces corresponding to the points.\n" );
         [ #  # ][ #  # ]
    8328                 :          0 :     return CUBIT_FAILURE;
    8329                 :            :   }
    8330                 :            : 
    8331                 :            :   // Do simple forms
    8332 [ #  # ][ #  # ]:          0 :   if( edge1 == NULL || offset2 <= 0.0 )
    8333                 :            :   {
    8334         [ #  # ]:          0 :     if( tweak_chamfer_solid( solid_points, bodies, offset1, new_bodysm_list,
    8335         [ #  # ]:          0 :       keep_old_body, preview )== CUBIT_FAILURE )
    8336                 :          0 :       return CUBIT_FAILURE;
    8337                 :            :     return tweak_fillet_chamfer_sheet( sheet_points, s_list, offset1, 
    8338 [ #  # ][ #  # ]:          0 :            CUBIT_FALSE, new_bodysm_list, keep_old_body, preview );
                 [ #  # ]
    8339                 :            :   }
    8340                 :            : 
    8341 [ #  # ][ #  # ]:          0 :   if( solid_points.size() > 1 || sheet_points.size() > 1 )
         [ #  # ][ #  # ]
                 [ #  # ]
    8342                 :            :   {
    8343 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "cannot chamfer multiple vertices with a variable radius.\n" );
         [ #  # ][ #  # ]
    8344                 :          0 :     return CUBIT_FAILURE;
    8345                 :            :   }
    8346                 :            : 
    8347 [ #  # ][ #  # ]:          0 :   if( solid_points.size() )
    8348                 :            :   {
    8349         [ #  # ]:          0 :     TBPoint *point_ptr = solid_points.get();
    8350                 :            : 
    8351 [ #  # ][ #  # ]:          0 :     if( tweak_chamfer_solid( point_ptr, bodies.get(), offset1, edge1, 
    8352                 :            :         offset2, edge2, offset3, edge3,
    8353         [ #  # ]:          0 :         new_bodysm_list, keep_old_body, preview ) == CUBIT_FAILURE )
    8354                 :          0 :       return CUBIT_FAILURE;
    8355                 :            : 
    8356                 :          0 :     return CUBIT_SUCCESS;
    8357                 :            :   }
    8358                 :            : 
    8359 [ #  # ][ #  # ]:          0 :   if( sheet_points.size() )
    8360                 :            :   {
    8361         [ #  # ]:          0 :     TBPoint *point_ptr = sheet_points.get();
    8362                 :            : 
    8363 [ #  # ][ #  # ]:          0 :     if( tweak_chamfer_sheet( point_ptr, s_list.get(), offset1, edge1, offset2, 
    8364         [ #  # ]:          0 :         edge2, new_bodysm_list, keep_old_body, preview ) == CUBIT_FAILURE )
    8365                 :          0 :       return CUBIT_FAILURE;
    8366                 :            : 
    8367                 :          0 :     return CUBIT_SUCCESS;
    8368                 :            :   }
    8369         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    8370                 :            : }
    8371                 :            : 
    8372                 :            : CubitStatus
    8373                 :          0 : OCCModifyEngine::tweak_chamfer_solid( DLIList<TBPoint*> &point_list,
    8374                 :            :                                     DLIList<OCCBody*> &bodies,
    8375                 :            :                                     double radius,
    8376                 :            :                                     DLIList<BodySM*> &new_bodysm_list,
    8377                 :            :                                     CubitBoolean keep_old_body,
    8378                 :            :                                     CubitBoolean preview )const
    8379                 :            : {
    8380                 :            :   //if point_list.size() > 1, after the first chamfer operation, the rest of 
    8381                 :            :   //the points in point_list maybe deleted and recreated, so can't use the 
    8382                 :            :   //points' pointers any more.
    8383         [ #  # ]:          0 :   DLIList<CubitVector> p_locs;
    8384 [ #  # ][ #  # ]:          0 :   if(point_list.size() > 1)
    8385                 :            :   {
    8386 [ #  # ][ #  # ]:          0 :     for (int i = 1; i < point_list.size(); i++)
    8387 [ #  # ][ #  # ]:          0 :      p_locs.append(point_list[i]->coordinates());
                 [ #  # ]
    8388                 :            :   }
    8389 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < point_list.size(); i++)
    8390                 :            :   {
    8391         [ #  # ]:          0 :     DLIList<TopologyBridge*> parents;
    8392         [ #  # ]:          0 :     TBPoint* point = point_list.get_and_step();
    8393         [ #  # ]:          0 :     OCCBody* body = bodies.get_and_step();
    8394 [ #  # ][ #  # ]:          0 :     DLIList<OCCPoint*> new_p_list;
                 [ #  # ]
    8395         [ #  # ]:          0 :     if( i > 0)
    8396                 :            :     {
    8397         [ #  # ]:          0 :       body->get_all_points(new_p_list);
    8398 [ #  # ][ #  # ]:          0 :       if(!new_p_list.move_to((OCCPoint*)point)) 
    8399                 :            :       {
    8400 [ #  # ][ #  # ]:          0 :         CubitVector p_loc = p_locs[i-1];
    8401 [ #  # ][ #  # ]:          0 :         for(int j = 0; j < new_p_list.size(); j++)
    8402                 :            :         {
    8403 [ #  # ][ #  # ]:          0 :           CubitVector test_loc = new_p_list.step_and_get()->coordinates();
    8404 [ #  # ][ #  # ]:          0 :           if(test_loc == p_loc)
    8405                 :            :           {
    8406         [ #  # ]:          0 :             point = new_p_list.get(); 
    8407                 :          0 :             break;
    8408                 :            :           }
    8409                 :            :         }
    8410                 :            :       }
    8411                 :            :     }
    8412         [ #  # ]:          0 :     OCCPoint* occ_point = CAST_TO(point, OCCPoint);
    8413         [ #  # ]:          0 :     if(occ_point != NULL)
    8414         [ #  # ]:          0 :       occ_point->get_parents_virt(parents); //OCCCurves
    8415 [ #  # ][ #  # ]:          0 :     assert(parents.size() == 3);
    8416 [ #  # ][ #  # ]:          0 :     DLIList<Curve*> curves;
                 [ #  # ]
    8417         [ #  # ]:          0 :     for(int j = 0; j < 3; j++)
    8418                 :            :     {
    8419 [ #  # ][ #  # ]:          0 :       OCCCurve* occ_curve = CAST_TO(parents.get_and_step(), OCCCurve); 
    8420         [ #  # ]:          0 :       curves.append(occ_curve);
    8421                 :            :     }
    8422                 :            :     CubitStatus stat;
    8423                 :            :     stat = tweak_chamfer_solid(point, body,radius, curves.pop(), radius, 
    8424                 :            :                         curves.pop(), radius, curves.pop(), new_bodysm_list,
    8425 [ #  # ][ #  # ]:          0 :                         keep_old_body, CUBIT_FALSE );
         [ #  # ][ #  # ]
    8426         [ #  # ]:          0 :     if(!stat)
    8427 [ #  # ][ #  # ]:          0 :       return CUBIT_FAILURE;
    8428                 :          0 :   }
    8429         [ #  # ]:          0 :   if(preview)
    8430                 :            :   {
    8431         [ #  # ]:          0 :     GfxPreview::clear();
    8432 [ #  # ][ #  # ]:          0 :     for(int i = 0; i < new_bodysm_list.size(); i++)
    8433                 :            :     {
    8434         [ #  # ]:          0 :       BodySM* new_bodysm = new_bodysm_list.get_and_step();
    8435                 :            :       TopoDS_Shape* modified_shape ;
    8436 [ #  # ][ #  # ]:          0 :       CAST_TO(new_bodysm, OCCBody)->get_TopoDS_Shape(modified_shape);
    8437         [ #  # ]:          0 :       TopExp_Explorer Ex;
    8438         [ #  # ]:          0 :       Ex.Init(*modified_shape, TopAbs_FACE);
    8439 [ #  # ][ #  # ]:          0 :       for( ; Ex.More(); Ex.Next() )
                 [ #  # ]
    8440                 :            :       {
    8441 [ #  # ][ #  # ]:          0 :         TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    8442                 :            :         // Draw this face
    8443 [ #  # ][ #  # ]:          0 :         OCCDrawTool::instance()->draw_FACE( &face, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    8444         [ #  # ]:          0 :       }
    8445         [ #  # ]:          0 :     }
    8446 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(new_bodysm_list);
    8447         [ #  # ]:          0 :     new_bodysm_list.clean_out();
    8448                 :            :   }
    8449                 :            : 
    8450         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    8451                 :            : 
    8452                 :            : }
    8453                 :            : 
    8454                 :            : CubitStatus
    8455                 :          0 : OCCModifyEngine::tweak_chamfer_solid( TBPoint* point_ptr,
    8456                 :            :                                     OCCBody* body,
    8457                 :            :                                     double r1,
    8458                 :            :                                     Curve *c1,
    8459                 :            :                                     double r2,
    8460                 :            :                                     Curve *c2,
    8461                 :            :                                     double r3,
    8462                 :            :                                     Curve *c3,
    8463                 :            :                                     DLIList<BodySM *> &new_bodysm_list,
    8464                 :            :                                     CubitBoolean keep_old_body,
    8465                 :            :                                     CubitBoolean preview )const
    8466                 :            : {
    8467 [ #  # ][ #  # ]:          0 :   if(r1 <= 0.0 || r2 <= 0.0 || r3 <= 0.0)
                 [ #  # ]
    8468                 :            :   {
    8469 [ #  # ][ #  # ]:          0 :     PRINT_ERROR( "Chamfer radii must be greater than zero.\n" );
         [ #  # ][ #  # ]
    8470                 :          0 :     return CUBIT_FAILURE;
    8471                 :            :   }
    8472                 :            :   
    8473         [ #  # ]:          0 :   DLIList<Curve*> curves;
    8474         [ #  # ]:          0 :   curves.append(c1);
    8475         [ #  # ]:          0 :   curves.append(c2);
    8476         [ #  # ]:          0 :   curves.append(c3);
    8477                 :            :   
    8478 [ #  # ][ #  # ]:          0 :   DLIList<double> radii;
    8479         [ #  # ]:          0 :   radii.append(r1);
    8480         [ #  # ]:          0 :   radii.append(r2);
    8481         [ #  # ]:          0 :   radii.append(r3);
    8482                 :            : 
    8483                 :            :   //check point on curves
    8484         [ #  # ]:          0 :   OCCPoint* occ_point = CAST_TO(point_ptr, OCCPoint);
    8485         [ #  # ]:          0 :   CubitVector position = occ_point->coordinates();
    8486 [ #  # ][ #  # ]:          0 :   DLIList<CubitVector> locations;
    8487         [ #  # ]:          0 :   for(int i = 0; i < 3; i++)
    8488                 :            :   {
    8489                 :          0 :     OCCCurve *occ_curve = NULL;
    8490 [ #  # ][ #  # ]:          0 :     occ_curve = CAST_TO(curves.get_and_step(), OCCCurve);
    8491         [ #  # ]:          0 :     double length = occ_curve->measure();
    8492                 :            : 
    8493         [ #  # ]:          0 :     DLIList<OCCPoint*> point_list;
    8494         [ #  # ]:          0 :     occ_curve->get_points(point_list);
    8495         [ #  # ]:          0 :     CubitBoolean in = point_list.is_in_list(occ_point); 
    8496         [ #  # ]:          0 :     if(!in)
    8497                 :            :     {
    8498 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Point is not on curve.\n" );
         [ #  # ][ #  # ]
    8499                 :          0 :       return CUBIT_FAILURE;
    8500                 :            :     }
    8501                 :            :     //find cutting points on curves
    8502                 :            :     double u, u1, u2;
    8503         [ #  # ]:          0 :     occ_curve->get_param_range(u1,u2);
    8504         [ #  # ]:          0 :     u = occ_curve->u_from_position(position); 
    8505         [ #  # ]:          0 :     if(fabs(u-u1) < TOL)
    8506 [ #  # ][ #  # ]:          0 :       u = occ_curve->u_from_arc_length(u1, radii[i]);
    8507                 :            :     else
    8508 [ #  # ][ #  # ]:          0 :       u = occ_curve->u_from_arc_length(u1, length-radii[i]);
    8509         [ #  # ]:          0 :     CubitVector c_p;
    8510         [ #  # ]:          0 :     occ_curve->position_from_u(u, c_p);
    8511 [ #  # ][ #  # ]:          0 :     locations.append(c_p);
                 [ #  # ]
    8512                 :          0 :   }
    8513                 :            : 
    8514                 :            :   //decide normal
    8515 [ #  # ][ #  # ]:          0 :   CubitVector v1, v2, normal;
                 [ #  # ]
    8516         [ #  # ]:          0 :   CubitVector point_1 = locations.pop();
    8517         [ #  # ]:          0 :   CubitVector point_2 = locations.pop();
    8518         [ #  # ]:          0 :   CubitVector point_3 = locations.pop();
    8519 [ #  # ][ #  # ]:          0 :   v1 = point_2 - point_1;
    8520 [ #  # ][ #  # ]:          0 :   v2 = point_1 - point_3;
    8521 [ #  # ][ #  # ]:          0 :   normal = ~(v1 * v2); 
                 [ #  # ]
    8522         [ #  # ]:          0 :   CubitVector center;
    8523                 :            :   double volume;
    8524         [ #  # ]:          0 :   body->mass_properties(center, volume); 
    8525 [ #  # ][ #  # ]:          0 :   CubitVector dir = ~(center - position);
    8526 [ #  # ][ #  # ]:          0 :   if(normal % dir > 0.0)//1, 3, 2 order
    8527                 :            :   {
    8528         [ #  # ]:          0 :     CubitVector v = point_2;
    8529         [ #  # ]:          0 :     point_2 = point_3;
    8530         [ #  # ]:          0 :     point_3 = v;
    8531                 :            :   }
    8532                 :            : 
    8533 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> bodies;
    8534                 :            :   BodySM* new_body;
    8535 [ #  # ][ #  # ]:          0 :   if(keep_old_body || preview)
    8536         [ #  # ]:          0 :     new_body = copy_body(body); 
    8537                 :            :   else
    8538                 :          0 :     new_body = body;
    8539                 :            : 
    8540         [ #  # ]:          0 :   bodies.append(new_body);
    8541         [ #  # ]:          0 :   const CubitVector p1 = point_1;
    8542         [ #  # ]:          0 :   const CubitVector p2 = point_2;
    8543         [ #  # ]:          0 :   const CubitVector p3 = point_3;
    8544                 :            :   CubitStatus status = const_cast<OCCModifyEngine*> (this)->
    8545                 :            :                                section(bodies, p1, p2, p3, 
    8546         [ #  # ]:          0 :                                new_bodysm_list, true,false, false);    
    8547         [ #  # ]:          0 :   if(!status)
    8548                 :          0 :     return CUBIT_FAILURE;
    8549                 :            : 
    8550         [ #  # ]:          0 :   if(!preview)
    8551                 :          0 :     return CUBIT_SUCCESS;
    8552                 :            : 
    8553         [ #  # ]:          0 :   GfxPreview::clear();
    8554                 :            : 
    8555 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < new_bodysm_list.size(); i++)
    8556                 :            :   {
    8557         [ #  # ]:          0 :      BodySM* new_bodysm = new_bodysm_list.get_and_step();
    8558 [ #  # ][ #  # ]:          0 :      DLIList<OCCSurface*> surfs = CAST_TO(new_bodysm, OCCBody)->my_sheet_surfaces();
    8559 [ #  # ][ #  # ]:          0 :      for(int j = 0 ; j < surfs.size(); j++)
    8560                 :            :      {
    8561 [ #  # ][ #  # ]:          0 :        TopoDS_Face* modified_shape = surfs.get_and_step()->get_TopoDS_Face();
    8562                 :            :        // Draw this face
    8563 [ #  # ][ #  # ]:          0 :        OCCDrawTool::instance()->draw_FACE( modified_shape, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    8564                 :            :      }
    8565         [ #  # ]:          0 :   }
    8566 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->delete_solid_model_entities(new_bodysm_list);
    8567         [ #  # ]:          0 :   new_bodysm_list.clean_out();
    8568                 :            : 
    8569         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    8570                 :            : }
    8571                 :            : 
    8572                 :            : CubitStatus
    8573                 :          0 : OCCModifyEngine::sort_points_by_body_type( DLIList<TBPoint*> &point_list,
    8574                 :            :                                          DLIList<TBPoint*> &solid_points,
    8575                 :            :                                          DLIList<TBPoint*> &sheet_points,
    8576                 :            :                                          DLIList<OCCSurface*> &s_list,
    8577                 :            :                                          DLIList<OCCBody*> &bodies )const
    8578                 :            : {
    8579         [ #  # ]:          0 :   for (int i = 0; i < point_list.size(); i++)
    8580                 :            :   {
    8581         [ #  # ]:          0 :     DLIList<TopologyBridge*> parents;
    8582 [ #  # ][ #  # ]:          0 :     OCCPoint* point = CAST_TO(point_list.get_and_step(), OCCPoint);
    8583                 :          0 :     int curve_size = 0;
    8584         [ #  # ]:          0 :     if(point != NULL)
    8585                 :            :     {
    8586         [ #  # ]:          0 :       point->get_parents_virt(parents); //OCCCurves
    8587 [ #  # ][ #  # ]:          0 :       if(parents.size() < 2)
    8588                 :            :       {
    8589 [ #  # ][ #  # ]:          0 :         PRINT_ERROR( "Vertex found not attached to any surfaces.\n" );
         [ #  # ][ #  # ]
    8590                 :          0 :         return CUBIT_FAILURE;
    8591                 :            :       } 
    8592 [ #  # ][ #  # ]:          0 :       else if(parents.size() > 3)
    8593                 :            :       {
    8594 [ #  # ][ #  # ]:          0 :         PRINT_ERROR( "Vertex found attached to multiple bodies.\n" );
         [ #  # ][ #  # ]
    8595                 :          0 :         return CUBIT_FAILURE;
    8596                 :            :       }
    8597         [ #  # ]:          0 :       curve_size = parents.size();
    8598                 :            :     }
    8599                 :            :     
    8600 [ #  # ][ #  # ]:          0 :     OCCCurve* occ_curve = CAST_TO(parents.get(), OCCCurve);
    8601         [ #  # ]:          0 :     parents.clean_out();
    8602         [ #  # ]:          0 :     occ_curve->get_parents_virt(parents); //OCCCoEdges
    8603 [ #  # ][ #  # ]:          0 :     if(parents.size() == 0)
    8604                 :            :     {
    8605 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Vertex found not attached to any surfaces.\n" );
         [ #  # ][ #  # ]
    8606                 :          0 :       return CUBIT_FAILURE;
    8607                 :            :     }
    8608 [ #  # ][ #  # ]:          0 :     OCCCoEdge* coedge = CAST_TO(parents.get(), OCCCoEdge);
    8609         [ #  # ]:          0 :     parents.clean_out();
    8610         [ #  # ]:          0 :     coedge->get_parents_virt(parents);  //OCCLoops
    8611 [ #  # ][ #  # ]:          0 :     assert(parents.size() > 0);
    8612 [ #  # ][ #  # ]:          0 :     OCCLoop* loop = CAST_TO(parents.get(), OCCLoop);
    8613         [ #  # ]:          0 :     parents.clean_out();
    8614         [ #  # ]:          0 :     loop->get_parents_virt(parents); //OCCSurface
    8615 [ #  # ][ #  # ]:          0 :     assert(parents.size() > 0);
    8616 [ #  # ][ #  # ]:          0 :     OCCSurface* s = CAST_TO(parents.get(), OCCSurface); 
    8617 [ #  # ][ #  # ]:          0 :     if(s->my_body() != NULL && curve_size == 2) //sheet body
         [ #  # ][ #  # ]
    8618                 :            :     {
    8619         [ #  # ]:          0 :       s_list.append(s);
    8620         [ #  # ]:          0 :       sheet_points.append(point);
    8621                 :            :     }
    8622 [ #  # ][ #  # ]:          0 :     else if(s->my_body() != NULL && curve_size == 3) //shell body
         [ #  # ][ #  # ]
    8623                 :            :     {
    8624 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Vertex found attached to multiple surfaces but not on bodies.\n" );
         [ #  # ][ #  # ]
    8625                 :          0 :       return CUBIT_FAILURE;
    8626                 :            :     }
    8627                 :            :     else
    8628                 :            :     {
    8629         [ #  # ]:          0 :       solid_points.append(point);
    8630         [ #  # ]:          0 :       DLIList<OCCBody*> solid_bodies;
    8631         [ #  # ]:          0 :       s->get_bodies(solid_bodies);
    8632 [ #  # ][ #  # ]:          0 :       assert(solid_bodies.size() == 1);
    8633 [ #  # ][ #  # ]:          0 :       bodies += solid_bodies;
         [ #  # ][ #  # ]
    8634                 :            :     }
    8635                 :          0 :   }
    8636                 :          0 :   return CUBIT_SUCCESS;
    8637                 :            : }
    8638                 :            : //=============================================================================
    8639                 :            : // Function   : tweak_fillet
    8640                 :            : // Member Type: PUBLIC
    8641                 :            : // Description: Create a round fillet (or blend) at the given curves on solid 
    8642                 :            : //              bodies.
    8643                 :            : // Author     : Jane Hu
    8644                 :            : // Date       : 01/09
    8645                 :            : //=============================================================================
    8646                 :          0 : CubitStatus OCCModifyEngine::tweak_fillet( DLIList<Curve*> & curve_list, 
    8647                 :            :                                            double radius,
    8648                 :            :                                            DLIList<BodySM*> & new_bodysm_list,
    8649                 :            :                                            CubitBoolean keep_old_body,
    8650                 :            :                                            CubitBoolean preview )const 
    8651                 :            : {
    8652                 :            :   CubitStatus stat;
    8653                 :          0 :   int count = 0;
    8654         [ #  # ]:          0 :   for(int i = 0; i < curve_list.size(); i++) 
    8655                 :            :   {
    8656                 :          0 :     BodySM * new_bodysm_ptr = NULL;
    8657         [ #  # ]:          0 :     stat = tweak_fillet(curve_list.get_and_step(), radius, radius, 
    8658         [ #  # ]:          0 :                         new_bodysm_ptr , keep_old_body, CUBIT_FALSE);
    8659 [ #  # ][ #  # ]:          0 :     if(stat && new_bodysm_ptr)
    8660                 :            :     {
    8661         [ #  # ]:          0 :       new_bodysm_list.append_unique(new_bodysm_ptr);
    8662         [ #  # ]:          0 :       count = new_bodysm_list.size();
    8663                 :            :     }
    8664                 :            :     else
    8665                 :            :       break;
    8666                 :            :   }
    8667                 :            : 
    8668         [ #  # ]:          0 :   if(count == 0) 
    8669                 :          0 :     return CUBIT_FAILURE;
    8670                 :            :  
    8671         [ #  # ]:          0 :   if(preview)
    8672                 :            :   {
    8673                 :          0 :     GfxPreview::clear();
    8674         [ #  # ]:          0 :     for(int i = 0; i < new_bodysm_list.size(); i++)
    8675                 :            :     {
    8676         [ #  # ]:          0 :       BodySM* new_bodysm = new_bodysm_list.get_and_step();
    8677                 :            :       TopoDS_Shape* modified_shape ; 
    8678 [ #  # ][ #  # ]:          0 :       CAST_TO(new_bodysm, OCCBody)->get_TopoDS_Shape(modified_shape);
    8679         [ #  # ]:          0 :       TopExp_Explorer Ex;
    8680         [ #  # ]:          0 :       Ex.Init(*modified_shape, TopAbs_FACE);
    8681 [ #  # ][ #  # ]:          0 :       for( ; Ex.More(); Ex.Next() )
                 [ #  # ]
    8682                 :            :       {
    8683 [ #  # ][ #  # ]:          0 :         TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    8684                 :            :         // Draw this face
    8685 [ #  # ][ #  # ]:          0 :         OCCDrawTool::instance()->draw_FACE( &face, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    8686         [ #  # ]:          0 :       }
    8687         [ #  # ]:          0 :     }
    8688                 :          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(new_bodysm_list);  
    8689                 :          0 :     new_bodysm_list.clean_out();
    8690                 :            :   }
    8691                 :            :   
    8692                 :          0 :   return CUBIT_SUCCESS;
    8693                 :            : }
    8694                 :            : 
    8695                 :            : //=============================================================================
    8696                 :            : // Function   : tweak_fillet
    8697                 :            : // Member Type: PUBLIC
    8698                 :            : // Description: Create a round fillet (or blend) at the given curves on a solid
    8699                 :            : //              body.  The fillet/chamfer has a variable radius from the
    8700                 :            : //              start to the end of the curve.
    8701                 :            : // Author     : Jane Hu
    8702                 :            : // Date       : 01/09
    8703                 :            : //=============================================================================
    8704                 :          0 : CubitStatus OCCModifyEngine::tweak_fillet( Curve * curve_ptr,
    8705                 :            :                                            double start_radius,
    8706                 :            :                                            double end_radius,
    8707                 :            :                                            BodySM *& new_bodysm_ptr,
    8708                 :            :                                            CubitBoolean keep_old_body,
    8709                 :            :                                            CubitBoolean preview )const
    8710                 :            : {
    8711                 :            :   return tweak_fillet(curve_ptr, start_radius, end_radius, new_bodysm_ptr,
    8712                 :          0 :                       keep_old_body, preview, CUBIT_TRUE);
    8713                 :            : }
    8714                 :            : 
    8715                 :            : //=============================================================================
    8716                 :            : // Function   : tweak_fillet
    8717                 :            : // Member Type: private
    8718                 :            : // Description: Create a round fillet (or blend) at the given curves on a solid 
    8719                 :            : //              body.  The fillet/chamfer has a variable radius from the 
    8720                 :            : //              start to the end of the curve.
    8721                 :            : // Author     : Jane Hu 
    8722                 :            : // Date       : 01/09
    8723                 :            : //=============================================================================
    8724                 :          0 : CubitStatus OCCModifyEngine::tweak_fillet( Curve * curve_ptr, 
    8725                 :            :                                            double start_radius,
    8726                 :            :                                            double end_radius,
    8727                 :            :                                            BodySM *& new_bodysm_ptr,
    8728                 :            :                                            CubitBoolean keep_old_body,
    8729                 :            :                                            CubitBoolean preview,
    8730                 :            :                                            CubitBoolean if_fillet ) const
    8731                 :            : {
    8732                 :            :   //check if this id is valid 
    8733         [ #  # ]:          0 :   OCCQueryEngine* oqe = OCCQueryEngine::instance();
    8734                 :          0 :   DLIList <OCCBody* > *bodies = oqe->BodyList;  
    8735         [ #  # ]:          0 :   DLIList<OCCCurve*> curves;
    8736 [ #  # ][ #  # ]:          0 :   for(int j = 0; j <  bodies->size(); j++)
    8737                 :            :   {
    8738         [ #  # ]:          0 :     OCCBody* body = bodies->get_and_step();
    8739         [ #  # ]:          0 :     body->get_all_curves(curves);
    8740                 :            :   }
    8741                 :            : 
    8742                 :          0 :   bool curve_alive = false;
    8743 [ #  # ][ #  # ]:          0 :   for(int j = 0; j <  curves.size(); j++)
    8744                 :            :   {
    8745 [ #  # ][ #  # ]:          0 :     if(curve_ptr == curves.get_and_step())
    8746                 :            :     {
    8747                 :          0 :       curve_alive = true; 
    8748                 :          0 :       break;
    8749                 :            :     }
    8750                 :            :   }
    8751                 :            : 
    8752         [ #  # ]:          0 :   if(!curve_alive)
    8753                 :            :   {
    8754 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("This curve is not valid in the current model.\n");
         [ #  # ][ #  # ]
    8755                 :          0 :     return CUBIT_FAILURE;
    8756                 :            :   }
    8757                 :            : 
    8758         [ #  # ]:          0 :   OCCCurve *occ_curve = CAST_TO(curve_ptr, OCCCurve);
    8759         [ #  # ]:          0 :   TopoDS_Edge* topo_edge = occ_curve->get_TopoDS_Edge();
    8760                 :            : 
    8761 [ #  # ][ #  # ]:          0 :   TopTools_IndexedDataMapOfShapeListOfShape M;
    8762 [ #  # ][ #  # ]:          0 :   DLIList<TopoDS_Shape*> shape_list;
    8763                 :          0 :   TopoDS_Face* s = NULL;
    8764 [ #  # ][ #  # ]:          0 :   for(int j = 0; j <  bodies->size(); j++)
    8765                 :            :   {
    8766         [ #  # ]:          0 :     OCCBody* body = bodies->get_and_step();
    8767         [ #  # ]:          0 :     TopExp_Explorer Ex;
    8768                 :            :     TopoDS_Shape* pshape ; 
    8769         [ #  # ]:          0 :     body->get_TopoDS_Shape(pshape);
    8770                 :            :     
    8771 [ #  # ][ #  # ]:          0 :     if (pshape && !pshape->IsNull())
         [ #  # ][ #  # ]
    8772                 :            :     {
    8773         [ #  # ]:          0 :       M.Clear();
    8774         [ #  # ]:          0 :       TopExp::MapShapesAndAncestors(*pshape, TopAbs_EDGE, TopAbs_COMPOUND, M);
    8775 [ #  # ][ #  # ]:          0 :       if(!M.Contains(*topo_edge))
    8776                 :          0 :          continue;
    8777                 :            : 
    8778         [ #  # ]:          0 :       shape_list.append_unique(pshape);
    8779                 :            :     }   
    8780                 :            : 
    8781         [ #  # ]:          0 :     if(!if_fillet) //for chamfer, need to know the face for the curve.
    8782                 :            :     {
    8783         [ #  # ]:          0 :       DLIList<TopologyBridge*> parents;
    8784         [ #  # ]:          0 :       occ_curve->get_parents_virt(parents); //OCCCoEdges
    8785 [ #  # ][ #  # ]:          0 :       assert(parents.size() > 1);
    8786 [ #  # ][ #  # ]:          0 :       OCCCoEdge* coedge = CAST_TO(parents.get(), OCCCoEdge);
    8787         [ #  # ]:          0 :       parents.clean_out();
    8788         [ #  # ]:          0 :       coedge->get_parents_virt(parents);  //OCCLoops
    8789 [ #  # ][ #  # ]:          0 :       assert(parents.size() > 0);
    8790 [ #  # ][ #  # ]:          0 :       OCCLoop* loop = CAST_TO(parents.get(), OCCLoop);
    8791         [ #  # ]:          0 :       parents.clean_out(); 
    8792         [ #  # ]:          0 :       loop->get_parents_virt(parents); //OCCSurface
    8793 [ #  # ][ #  # ]:          0 :       assert(parents.size() > 0);
    8794 [ #  # ][ #  # ]:          0 :       s = CAST_TO(parents.get(), OCCSurface)->get_TopoDS_Face();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    8795                 :            :     }
    8796                 :          0 :   }
    8797 [ #  # ][ #  # ]:          0 :   if(shape_list.size() != 1)
    8798                 :            :   {
    8799 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Fillets must be created on solids.\n");
         [ #  # ][ #  # ]
    8800                 :          0 :     return CUBIT_FAILURE;
    8801                 :            :   }
    8802                 :            : 
    8803 [ #  # ][ #  # ]:          0 :   TopoDS_Shape newShape;
    8804         [ #  # ]:          0 :   TopoDS_Shape* shape = shape_list.get();
    8805         [ #  # ]:          0 :   if(keep_old_body)
    8806                 :            :   {
    8807         [ #  # ]:          0 :     BRepBuilderAPI_Copy api_copy(*shape);
    8808 [ #  # ][ #  # ]:          0 :     newShape = api_copy.ModifiedShape(*shape);
                 [ #  # ]
    8809                 :            :   }
    8810                 :            :   else
    8811         [ #  # ]:          0 :     newShape = *shape;
    8812                 :            : 
    8813                 :            :   BRepBuilderAPI_MakeShape* fillet;
    8814         [ #  # ]:          0 :   if(if_fillet)
    8815                 :            :   {
    8816 [ #  # ][ #  # ]:          0 :     fillet = new BRepFilletAPI_MakeFillet(newShape);
    8817 [ #  # ][ #  # ]:          0 :     dynamic_cast<BRepFilletAPI_MakeFillet*>(fillet)->Add(start_radius, end_radius, *topo_edge);
    8818                 :            :   }
    8819                 :            :   else
    8820                 :            :   {
    8821 [ #  # ][ #  # ]:          0 :     fillet = new BRepFilletAPI_MakeChamfer(newShape);
    8822 [ #  # ][ #  # ]:          0 :     dynamic_cast<BRepFilletAPI_MakeChamfer*>(fillet)->Add(start_radius, end_radius, *topo_edge, *s);
    8823                 :            :   }
    8824         [ #  # ]:          0 :   fillet->Build();
    8825                 :            : 
    8826 [ #  # ][ #  # ]:          0 :   if(!fillet->IsDone())
    8827                 :            :   {
    8828 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't create fillet on given curve.\n");
         [ #  # ][ #  # ]
    8829                 :          0 :     return CUBIT_FAILURE;
    8830                 :            :   } 
    8831 [ #  # ][ #  # ]:          0 :   TopoDS_Shape modified_shape = fillet->Shape();
                 [ #  # ]
    8832                 :            : 
    8833         [ #  # ]:          0 :   if( !preview )
    8834                 :            :   {
    8835         [ #  # ]:          0 :     TopExp_Explorer Ex;
    8836         [ #  # ]:          0 :     Ex.Init(newShape, TopAbs_SOLID);
    8837 [ #  # ][ #  # ]:          0 :     TopoDS_Solid old_solid = TopoDS::Solid(Ex.Current());
         [ #  # ][ #  # ]
    8838         [ #  # ]:          0 :     OCCLump::update_OCC_entity(old_solid , modified_shape, fillet);     
    8839 [ #  # ][ #  # ]:          0 :     DLIList<TopologyBridge*> tbs = OCCQueryEngine::instance()->populate_topology_bridge(modified_shape);
                 [ #  # ]
    8840 [ #  # ][ #  # ]:          0 :     new_bodysm_ptr = CAST_TO(tbs.get(), BodySM);  
                 [ #  # ]
    8841                 :            :   }
    8842                 :            :   else
    8843                 :            :   {
    8844         [ #  # ]:          0 :     GfxPreview::clear();
    8845                 :            : 
    8846         [ #  # ]:          0 :     TopExp_Explorer Ex;
    8847         [ #  # ]:          0 :     Ex.Init(modified_shape, TopAbs_FACE); 
    8848 [ #  # ][ #  # ]:          0 :     for( ; Ex.More(); Ex.Next() )
                 [ #  # ]
    8849                 :            :     {
    8850 [ #  # ][ #  # ]:          0 :       TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    8851                 :            :       // Draw this face
    8852 [ #  # ][ #  # ]:          0 :       OCCDrawTool::instance()->draw_FACE( &face, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    8853 [ #  # ][ #  # ]:          0 :     }
    8854                 :            :   }
    8855 [ #  # ][ #  # ]:          0 :   delete fillet;
    8856         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    8857                 :            : }
    8858                 :            : 
    8859                 :            : //=============================================================================
    8860                 :            : // Function   : tweak_fillet
    8861                 :            : // Member Type: PUBLIC
    8862                 :            : // Description: Create a round fillet (or blend) at the given vertices on sheet
    8863                 :            : //              bodies.
    8864                 :            : // Author     : Jane Hu
    8865                 :            : // Date       : 01/09 
    8866                 :            : //=============================================================================
    8867                 :            : CubitStatus
    8868                 :          0 : OCCModifyEngine::tweak_fillet( DLIList<TBPoint*> & ref_vertex_list, 
    8869                 :            :                                double radius,
    8870                 :            :                                DLIList<BodySM*> & new_bodysm_list,
    8871                 :            :                                CubitBoolean keep_old_body,
    8872                 :            :                                CubitBoolean preview ) const
    8873                 :            : {
    8874         [ #  # ]:          0 :   DLIList<OCCSurface*> s_list;
    8875                 :            :   return tweak_fillet_chamfer_sheet(ref_vertex_list, s_list, radius, CUBIT_TRUE,
    8876 [ #  # ][ #  # ]:          0 :          new_bodysm_list, keep_old_body, preview);
         [ #  # ][ #  # ]
    8877                 :            : }
    8878                 :            : 
    8879                 :            : CubitStatus
    8880                 :          0 : OCCModifyEngine::tweak_fillet_chamfer_sheet( DLIList<TBPoint*> & ref_vertex_list,
    8881                 :            :                                DLIList<OCCSurface*> faces,
    8882                 :            :                                double radius,
    8883                 :            :                                CubitBoolean is_fillet,
    8884                 :            :                                DLIList<BodySM*> & new_bodysm_list,
    8885                 :            :                                CubitBoolean keep_old_body,
    8886                 :            :                                CubitBoolean preview )const
    8887                 :            : {
    8888         [ #  # ]:          0 :   TopTools_IndexedDataMapOfShapeListOfShape M;
    8889                 :            : 
    8890 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < ref_vertex_list.size(); i ++)
    8891                 :            :   {
    8892         [ #  # ]:          0 :     TBPoint* pnt = ref_vertex_list.get_and_step();
    8893         [ #  # ]:          0 :     OCCPoint* occ_pnt = CAST_TO(pnt, OCCPoint);
    8894         [ #  # ]:          0 :     TopoDS_Vertex* vertex = occ_pnt->get_TopoDS_Vertex();
    8895                 :          0 :     OCCSurface* face = NULL;
    8896                 :            : 
    8897 [ #  # ][ #  # ]:          0 :     if( faces.size() == 0)
    8898                 :            :     {
    8899         [ #  # ]:          0 :       OCCQueryEngine* oqe = OCCQueryEngine::instance();
    8900                 :            :       //make sure the vertex is on sheet body, not on a volume.
    8901                 :          0 :       DLIList <OCCBody*> *bodies = oqe->BodyList;
    8902 [ #  # ][ #  # ]:          0 :       for(int k =0 ; k < bodies->size(); k++)
    8903                 :            :       {
    8904         [ #  # ]:          0 :         OCCBody* occ_body = bodies->get_and_step();
    8905         [ #  # ]:          0 :         TopExp_Explorer Ex;
    8906                 :            :         TopoDS_Shape* pshape ; 
    8907         [ #  # ]:          0 :         occ_body->get_TopoDS_Shape(pshape);
    8908 [ #  # ][ #  # ]:          0 :         if(pshape && !pshape->IsNull())
         [ #  # ][ #  # ]
    8909                 :            :         {
    8910         [ #  # ]:          0 :           M.Clear();
    8911         [ #  # ]:          0 :           TopExp::MapShapesAndAncestors(*pshape, TopAbs_VERTEX, TopAbs_COMPOUND, M);
    8912 [ #  # ][ #  # ]:          0 :           if(M.Contains(*vertex) && !occ_body->is_sheet_body())
         [ #  # ][ #  # ]
                 [ #  # ]
    8913                 :            :           {
    8914 [ #  # ][ #  # ]:          0 :             PRINT_ERROR("Fillet on vertex can only be done on sheet body.\n");
         [ #  # ][ #  # ]
    8915                 :          0 :             return CUBIT_FAILURE;
    8916                 :            :           }
    8917 [ #  # ][ #  # ]:          0 :           else if(M.Contains(*vertex) && occ_body->is_sheet_body())
         [ #  # ][ #  # ]
                 [ #  # ]
    8918                 :            :           {
    8919         [ #  # ]:          0 :             DLIList<OCCSurface*> surfaces = occ_body->my_sheet_surfaces();
    8920 [ #  # ][ #  # ]:          0 :             face = surfaces.get();
         [ #  # ][ #  # ]
    8921                 :            :           }
    8922                 :            :         }
    8923                 :          0 :       } 
    8924                 :            :       //find corresponding faces.
    8925         [ #  # ]:          0 :       if(face == NULL) //in case there's a bug in code.
    8926                 :            :       {
    8927                 :          0 :         DLIList <OCCSurface* > *surfaces = oqe->SurfaceList;
    8928 [ #  # ][ #  # ]:          0 :         for(int k =0 ; k < surfaces->size(); k++)
    8929                 :            :         {
    8930         [ #  # ]:          0 :           OCCSurface* occ_face = surfaces->get_and_step();
    8931         [ #  # ]:          0 :           TopoDS_Face* topo_face = occ_face->get_TopoDS_Face();
    8932         [ #  # ]:          0 :           TopExp_Explorer Ex;
    8933         [ #  # ]:          0 :           M.Clear();
    8934         [ #  # ]:          0 :           TopExp::MapShapesAndAncestors(*topo_face, TopAbs_VERTEX, TopAbs_FACE, M);
    8935 [ #  # ][ #  # ]:          0 :           if(!M.Contains(*vertex))
    8936                 :          0 :             continue;
    8937                 :          0 :           face = occ_face; 
    8938 [ #  # ][ #  # ]:          0 :           break;
    8939                 :          0 :         }
    8940                 :            :       }
    8941                 :            :     }
    8942                 :            :     else
    8943         [ #  # ]:          0 :       face = faces.get_and_step();
    8944                 :            : 
    8945         [ #  # ]:          0 :     if(face == NULL)
    8946                 :            :     {
    8947 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Can't find corresponding surface for the vertex.\n");
         [ #  # ][ #  # ]
    8948                 :          0 :       return CUBIT_FAILURE;
    8949                 :            :     }
    8950                 :            : 
    8951         [ #  # ]:          0 :     if(!is_fillet)
    8952                 :            :     {
    8953                 :            :       //find the two edges sharing the vertex.
    8954         [ #  # ]:          0 :       DLIList<OCCCurve*> curves;
    8955         [ #  # ]:          0 :       face->get_curves(curves);
    8956         [ #  # ]:          0 :       int size = curves.size();
    8957         [ #  # ]:          0 :       for(int j = 0; j < size; j ++)
    8958                 :            :       {
    8959         [ #  # ]:          0 :         DLIList<OCCPoint*> point_list;   
    8960         [ #  # ]:          0 :         OCCCurve *curve = curves.get();
    8961         [ #  # ]:          0 :         curve->get_points(point_list);
    8962 [ #  # ][ #  # ]:          0 :         if(!point_list.is_in_list(occ_pnt))
    8963         [ #  # ]:          0 :           curves.remove();
    8964                 :            :         else
    8965         [ #  # ]:          0 :           curves.step();
    8966         [ #  # ]:          0 :       }
    8967 [ #  # ][ #  # ]:          0 :       assert (curves.size()==2);
    8968 [ #  # ][ #  # ]:          0 :       tweak_chamfer_sheet(pnt, face, radius, curves.pop(), radius, curves.pop(),
    8969 [ #  # ][ #  # ]:          0 :                         new_bodysm_list, keep_old_body, CUBIT_FALSE); 
    8970                 :            :     }
    8971                 :            : 
    8972                 :            :     else
    8973                 :            :     {
    8974         [ #  # ]:          0 :       TopoDS_Face *shape = face->get_TopoDS_Face();
    8975         [ #  # ]:          0 :       TopoDS_Face newShape;
    8976         [ #  # ]:          0 :       if(keep_old_body)
    8977                 :            :       {
    8978         [ #  # ]:          0 :         BRepBuilderAPI_Copy api_copy(*shape);
    8979 [ #  # ][ #  # ]:          0 :         newShape = TopoDS::Face(api_copy.ModifiedShape(*shape));
         [ #  # ][ #  # ]
    8980                 :            :       }
    8981                 :            :       else
    8982         [ #  # ]:          0 :         newShape = *shape;
    8983                 :            : 
    8984 [ #  # ][ #  # ]:          0 :       BRepFilletAPI_MakeFillet2d fillet(newShape);
                 [ #  # ]
    8985 [ #  # ][ #  # ]:          0 :       TopoDS_Edge fillet_edge;
                 [ #  # ]
    8986 [ #  # ][ #  # ]:          0 :       fillet_edge = fillet.AddFillet(*vertex, radius);
                 [ #  # ]
    8987         [ #  # ]:          0 :       fillet.Build();
    8988 [ #  # ][ #  # ]:          0 :       if(fillet.Status() != ChFi2d_IsDone)
    8989                 :            :       {
    8990 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Can't create fillet on given curve.\n");
         [ #  # ][ #  # ]
    8991                 :          0 :         return CUBIT_FAILURE;
    8992                 :            :       }
    8993 [ #  # ][ #  # ]:          0 :       TopoDS_Shape modified_shape = fillet.Shape();
         [ #  # ][ #  # ]
                 [ #  # ]
    8994                 :            : 
    8995 [ #  # ][ #  # ]:          0 :       TopExp_Explorer Ex;
    8996         [ #  # ]:          0 :       OCCSurface::update_OCC_entity(newShape , modified_shape, &fillet, vertex);
    8997 [ #  # ][ #  # ]:          0 :       TopoDS_Face modified_face = TopoDS::Face(modified_shape);
                 [ #  # ]
    8998 [ #  # ][ #  # ]:          0 :       Surface* surf = OCCQueryEngine::instance()->populate_topology_bridge(modified_face, CUBIT_TRUE);
    8999 [ #  # ][ #  # ]:          0 :       BodySM* new_bodysm_ptr = CAST_TO(surf,OCCSurface)->my_body();
    9000         [ #  # ]:          0 :       new_bodysm_list.append_unique(new_bodysm_ptr);
    9001                 :            :     }
    9002                 :            :   }
    9003                 :            : 
    9004         [ #  # ]:          0 :   if(!preview )
    9005                 :          0 :     return CUBIT_SUCCESS;
    9006                 :            : 
    9007         [ #  # ]:          0 :   GfxPreview::clear();
    9008                 :            : 
    9009 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < new_bodysm_list.size(); i++)
    9010                 :            :   {
    9011         [ #  # ]:          0 :      BodySM* new_bodysm = new_bodysm_list.get_and_step();
    9012 [ #  # ][ #  # ]:          0 :      DLIList<OCCSurface*> surfs = CAST_TO(new_bodysm, OCCBody)->my_sheet_surfaces();
    9013 [ #  # ][ #  # ]:          0 :      for(int j = 0; j < surfs.size(); j ++)
    9014                 :            :      {
    9015 [ #  # ][ #  # ]:          0 :        TopoDS_Face* modified_shape = surfs.get_and_step()->get_TopoDS_Face();
    9016                 :            :        // Draw this face
    9017 [ #  # ][ #  # ]:          0 :        OCCDrawTool::instance()->draw_FACE( modified_shape, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    9018                 :            :      }
    9019         [ #  # ]:          0 :   }
    9020 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->delete_solid_model_entities(new_bodysm_list);
    9021         [ #  # ]:          0 :   new_bodysm_list.clean_out();
    9022                 :            : 
    9023         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    9024                 :            : }
    9025                 :            : 
    9026                 :            : CubitStatus
    9027                 :          0 : OCCModifyEngine::tweak_chamfer_sheet(TBPoint* pnt,
    9028                 :            :                                      OCCSurface* face,
    9029                 :            :                                      double d1,
    9030                 :            :                                      Curve* edge1,
    9031                 :            :                                      double d2,
    9032                 :            :                                      Curve* edge2,
    9033                 :            :                                      DLIList<BodySM*> & new_bodysm_list,
    9034                 :            :                                      CubitBoolean keep_old_body,
    9035                 :            :                                      CubitBoolean preview ) const
    9036                 :            : {
    9037         [ #  # ]:          0 :   TopoDS_Face *shape = face->get_TopoDS_Face();
    9038         [ #  # ]:          0 :   TopoDS_Face newShape;
    9039         [ #  # ]:          0 :   if(keep_old_body)
    9040                 :            :   {
    9041         [ #  # ]:          0 :     BRepBuilderAPI_Copy api_copy(*shape);
    9042 [ #  # ][ #  # ]:          0 :     newShape = TopoDS::Face(api_copy.ModifiedShape(*shape));
         [ #  # ][ #  # ]
    9043                 :            :   }
    9044                 :            :   else
    9045         [ #  # ]:          0 :     newShape = *shape;
    9046                 :            : 
    9047 [ #  # ][ #  # ]:          0 :   BRepFilletAPI_MakeFillet2d fillet(newShape);
    9048                 :            : 
    9049 [ #  # ][ #  # ]:          0 :   TopoDS_Edge fillet_edge;
    9050 [ #  # ][ #  # ]:          0 :   if(edge1 == NULL || edge2 == NULL)
    9051                 :            :   {
    9052 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Cannot find the two edges for the vertex.\n");
         [ #  # ][ #  # ]
    9053                 :          0 :     return CUBIT_FAILURE;
    9054                 :            :   }
    9055 [ #  # ][ #  # ]:          0 :   TopoDS_Edge* topo_e1 = CAST_TO(edge1, OCCCurve)->get_TopoDS_Edge();
    9056 [ #  # ][ #  # ]:          0 :   TopoDS_Edge* topo_e2 = CAST_TO(edge2, OCCCurve)->get_TopoDS_Edge();
    9057 [ #  # ][ #  # ]:          0 :   TopoDS_Vertex common_v;
    9058         [ #  # ]:          0 :   TopExp::CommonVertex(*topo_e1, *topo_e2, common_v);
    9059 [ #  # ][ #  # ]:          0 :   fillet_edge = fillet.AddChamfer( *topo_e1, *topo_e2, d1, d2);
                 [ #  # ]
    9060                 :            : 
    9061         [ #  # ]:          0 :   fillet.Build() ;
    9062 [ #  # ][ #  # ]:          0 :   if(fillet.Status() != ChFi2d_IsDone)
    9063                 :            :   {
    9064 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't create chamfer on given vertex.\n");
         [ #  # ][ #  # ]
    9065                 :          0 :     return CUBIT_FAILURE;
    9066                 :            :   }
    9067 [ #  # ][ #  # ]:          0 :   TopoDS_Shape modified_shape = fillet.Shape();
                 [ #  # ]
    9068                 :            : 
    9069         [ #  # ]:          0 :   if( !preview )
    9070                 :            :   {
    9071         [ #  # ]:          0 :     TopExp_Explorer Ex;
    9072         [ #  # ]:          0 :     Ex.Init(newShape, TopAbs_FACE);
    9073 [ #  # ][ #  # ]:          0 :     TopoDS_Face old_face = TopoDS::Face(Ex.Current());
         [ #  # ][ #  # ]
    9074         [ #  # ]:          0 :     OCCSurface::update_OCC_entity(old_face , modified_shape, &fillet, &common_v);
    9075 [ #  # ][ #  # ]:          0 :     DLIList<TopologyBridge*> tbs = OCCQueryEngine::instance()->populate_topology_bridge(modified_shape);
                 [ #  # ]
    9076 [ #  # ][ #  # ]:          0 :     BodySM* new_bodysm_ptr = CAST_TO(tbs.get(), BodySM);
    9077 [ #  # ][ #  # ]:          0 :     new_bodysm_list.append_unique(new_bodysm_ptr);
    9078                 :            :   }
    9079                 :            :   else
    9080                 :            :   {
    9081         [ #  # ]:          0 :     GfxPreview::clear();
    9082                 :            : 
    9083         [ #  # ]:          0 :     TopExp_Explorer Ex;
    9084         [ #  # ]:          0 :     Ex.Init(modified_shape, TopAbs_FACE);
    9085 [ #  # ][ #  # ]:          0 :     for( ; Ex.More(); Ex.Next() )
                 [ #  # ]
    9086                 :            :     {
    9087 [ #  # ][ #  # ]:          0 :       TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    9088                 :            :       // Draw this face
    9089 [ #  # ][ #  # ]:          0 :       OCCDrawTool::instance()->draw_FACE( &face, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    9090 [ #  # ][ #  # ]:          0 :     }
    9091                 :            :   }
    9092         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    9093                 :            : }
    9094                 :            : //=============================================================================
    9095                 :            : // Function   : tweak_move
    9096                 :            : // Member Type: PUBLIC
    9097                 :            : // Description: Tweak specified faces of a volume or volumes along a vector.
    9098                 :            : // Author     : Jane Hu
    9099                 :            : // Date       : 04/09
    9100                 :            : //=============================================================================
    9101                 :          0 : CubitStatus OCCModifyEngine::tweak_move( DLIList<Surface*> & surface_list, 
    9102                 :            :                                          const CubitVector & delta,
    9103                 :            :                                          DLIList<BodySM*> & new_bodysm_list, 
    9104                 :            :                                          CubitBoolean keep_old_body ,
    9105                 :            :                                          CubitBoolean preview) const
    9106                 :            : {
    9107                 :            :   CubitStatus stat;
    9108         [ #  # ]:          0 :   for(int i = 0 ; i < surface_list.size(); i++)
    9109                 :            :   {
    9110         [ #  # ]:          0 :     Surface* surf = surface_list.get_and_step();
    9111         [ #  # ]:          0 :     OCCSurface* occ_surf = CAST_TO(surf, OCCSurface);
    9112         [ #  # ]:          0 :     if(!occ_surf)
    9113                 :          0 :       continue;
    9114                 :            : 
    9115         [ #  # ]:          0 :     BodySM* original_body = occ_surf->my_body();
    9116         [ #  # ]:          0 :     if(original_body == NULL)
    9117                 :            :     {
    9118         [ #  # ]:          0 :       DLIList<OCCBody*> original_bodies;
    9119         [ #  # ]:          0 :       occ_surf->get_bodies(original_bodies);
    9120 [ #  # ][ #  # ]:          0 :       if(original_bodies.size() > 1)
    9121                 :            :       {
    9122 [ #  # ][ #  # ]:          0 :         PRINT_ERROR( "Cannot tweak move the surface in non-mainfold solids. \n");
         [ #  # ][ #  # ]
    9123                 :          0 :         return CUBIT_FAILURE;
    9124                 :            :       }
    9125 [ #  # ][ #  # ]:          0 :       else if(original_bodies.size() == 0)
    9126                 :            :       {
    9127 [ #  # ][ #  # ]:          0 :         PRINT_ERROR( "Interal error: Can't find associated solid. \n");
         [ #  # ][ #  # ]
    9128                 :          0 :         return CUBIT_FAILURE;
    9129                 :            :       }
    9130         [ #  # ]:          0 :       original_body = original_bodies.get();
    9131 [ #  # ][ #  # ]:          0 :       assert(original_body != NULL);
                 [ #  # ]
    9132                 :            :     }
    9133                 :            : 
    9134                 :            :     //check to make sure that the surf is not on a sheet body. 
    9135         [ #  # ]:          0 :     OCCLump* lump = occ_surf->my_lump(); 
    9136 [ #  # ][ #  # ]:          0 :     if(lump != NULL && (lump->my_sheet_surface() || lump->my_shell()))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    9137                 :            :     {
    9138 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Cannot tweak move surfaces that are not in a solid\n");
         [ #  # ][ #  # ]
    9139                 :          0 :       return CUBIT_FAILURE;
    9140                 :            :     }
    9141         [ #  # ]:          0 :     DLIList<GeometryEntity*> ref_ent_list;
    9142         [ #  # ]:          0 :     ref_ent_list.append(occ_surf);
    9143 [ #  # ][ #  # ]:          0 :     DLIList<BodySM*> result_bodies;
                 [ #  # ]
    9144                 :            :     stat = sweep_translational(ref_ent_list, result_bodies, delta, 0.0, 1,
    9145         [ #  # ]:          0 :                                false, true, false, true); 
    9146         [ #  # ]:          0 :     if(stat == CUBIT_FAILURE)
    9147                 :            :     {
    9148 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Cannot tweak move the surface. \n");
         [ #  # ][ #  # ]
    9149                 :          0 :       return CUBIT_FAILURE;
    9150                 :            :     }
    9151 [ #  # ][ #  # ]:          0 :     assert(result_bodies.size() == 1);
    9152                 :            :     
    9153                 :            :     //determine if the delta is to trim the existing body or extend it.
    9154         [ #  # ]:          0 :     CubitVector center_point;
    9155 [ #  # ][ #  # ]:          0 :     center_point = occ_surf->center_point();
    9156 [ #  # ][ #  # ]:          0 :     center_point += ~delta;
    9157                 :            :      
    9158                 :          0 :     CubitBoolean trim = CUBIT_FALSE;
    9159 [ #  # ][ #  # ]:          0 :     if(original_body->point_containment(center_point) == CUBIT_PNT_INSIDE)
    9160                 :          0 :        trim = CUBIT_TRUE;
    9161                 :            : 
    9162                 :            :     //subtract or unite the two bodies
    9163         [ #  # ]:          0 :     if(!trim)
    9164                 :            :     {
    9165         [ #  # ]:          0 :       result_bodies.insert_first(original_body);
    9166         [ #  # ]:          0 :       stat = unite(result_bodies, new_bodysm_list, keep_old_body);
    9167                 :            :     }
    9168                 :            :     else
    9169                 :            :     {
    9170         [ #  # ]:          0 :       DLIList<BodySM*> from_bodies;
    9171         [ #  # ]:          0 :       from_bodies.append(original_body);
    9172                 :            :       stat = subtract(result_bodies, from_bodies, new_bodysm_list, CUBIT_FALSE,
    9173 [ #  # ][ #  # ]:          0 :                       keep_old_body);
    9174                 :            :     }
    9175         [ #  # ]:          0 :     if(stat == CUBIT_FAILURE)
    9176 [ #  # ][ #  # ]:          0 :       return CUBIT_FAILURE;
    9177                 :          0 :   } 
    9178         [ #  # ]:          0 :   if(preview)
    9179                 :            :   {
    9180                 :          0 :     GfxPreview::clear();
    9181         [ #  # ]:          0 :     for(int i = 0; i < new_bodysm_list.size(); i++)
    9182                 :            :     {
    9183         [ #  # ]:          0 :       BodySM* new_bodysm = new_bodysm_list.get_and_step();
    9184                 :            :       TopoDS_Shape* modified_shape ;
    9185 [ #  # ][ #  # ]:          0 :       CAST_TO(new_bodysm, OCCBody)->get_TopoDS_Shape(modified_shape);
    9186         [ #  # ]:          0 :       TopExp_Explorer Ex;
    9187         [ #  # ]:          0 :       Ex.Init(*modified_shape, TopAbs_FACE);
    9188 [ #  # ][ #  # ]:          0 :       for( ; Ex.More(); Ex.Next() )
                 [ #  # ]
    9189                 :            :       {
    9190 [ #  # ][ #  # ]:          0 :         TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    9191                 :            :         // Draw this face
    9192 [ #  # ][ #  # ]:          0 :         OCCDrawTool::instance()->draw_FACE( &face, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    9193         [ #  # ]:          0 :       }
    9194         [ #  # ]:          0 :     }
    9195                 :          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(new_bodysm_list);
    9196                 :          0 :     new_bodysm_list.clean_out();
    9197                 :            :   }
    9198                 :          0 :   return CUBIT_SUCCESS;
    9199                 :            : }
    9200                 :            : 
    9201                 :            : //=============================================================================
    9202                 :            : // Function   : tweak_move
    9203                 :            : // Member Type: PUBLIC
    9204                 :            : // Description: Tweak specified curves of a sheet body along a vector.
    9205                 :            : // Author     : Jane Hu
    9206                 :            : // Date       : 04/09
    9207                 :            : //=============================================================================
    9208                 :          0 : CubitStatus OCCModifyEngine::tweak_move( DLIList<Curve*> & curves,
    9209                 :            :                                          const CubitVector & delta,
    9210                 :            :                                          DLIList<BodySM*> & new_bodysm_list, 
    9211                 :            :                                          CubitBoolean keep_old_body,
    9212                 :            :                                          CubitBoolean preview ) const
    9213                 :            : {
    9214 [ #  # ][ #  # ]:          0 :   gp_Dir offset_dir(delta.x(), delta.y(), delta.z());
         [ #  # ][ #  # ]
    9215         [ #  # ]:          0 :   double length = delta.length();
    9216                 :            :   
    9217 [ #  # ][ #  # ]:          0 :   for(int i = 0 ; i < curves.size(); i++)
    9218                 :            :   {
    9219         [ #  # ]:          0 :     Curve* curve = curves.get_and_step();
    9220         [ #  # ]:          0 :     OCCCurve* occ_curve = CAST_TO(curve, OCCCurve);
    9221         [ #  # ]:          0 :     if(!occ_curve)
    9222                 :          0 :       continue;
    9223                 :            :     //check to make sure that the curve is on a sheet body.
    9224         [ #  # ]:          0 :     DLIList<OCCLoop*> loops;
    9225 [ #  # ][ #  # ]:          0 :     loops = occ_curve->loops();
                 [ #  # ]
    9226 [ #  # ][ #  # ]:          0 :     if(loops.size() == 0)
    9227                 :            :     {
    9228 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Cannot tweak move curves that are free\n");
         [ #  # ][ #  # ]
    9229                 :          0 :       return CUBIT_FAILURE;
    9230                 :            :     }
    9231 [ #  # ][ #  # ]:          0 :     else if(loops.size() != 1)
    9232                 :            :     {
    9233 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Can only tweak move curves attached to one surface\n");
         [ #  # ][ #  # ]
    9234                 :          0 :       return CUBIT_FAILURE;
    9235                 :            :     }
    9236                 :            :     //determine if the delta is to trim the existing surface or extend it.
    9237                 :            :     double u_low, u_upper;
    9238         [ #  # ]:          0 :     CubitVector a_point;
    9239         [ #  # ]:          0 :     occ_curve->get_param_range(u_low, u_upper);
    9240         [ #  # ]:          0 :     occ_curve->position_from_u((u_low + u_upper)/2, a_point);
    9241 [ #  # ][ #  # ]:          0 :     a_point += ~delta;
    9242 [ #  # ][ #  # ]:          0 :     DLIList<TopologyBridge*> parents;
                 [ #  # ]
    9243 [ #  # ][ #  # ]:          0 :     loops.get()->get_parents_virt(parents);
    9244 [ #  # ][ #  # ]:          0 :     OCCSurface* surface = CAST_TO(parents.get(), OCCSurface);
    9245         [ #  # ]:          0 :     BodySM* original_body = surface->my_body();
    9246         [ #  # ]:          0 :     if(!original_body)
    9247 [ #  # ][ #  # ]:          0 :       original_body = surface->my_shell()->my_body();
    9248         [ #  # ]:          0 :     if(!original_body)
    9249                 :            :     {
    9250 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Can't tweak move curves on volumes.\n");
         [ #  # ][ #  # ]
    9251                 :          0 :       return CUBIT_FAILURE;
    9252                 :            :     }
    9253                 :          0 :     CubitBoolean trim = CUBIT_FALSE;
    9254 [ #  # ][ #  # ]:          0 :     if(surface->point_containment(a_point) == CUBIT_PNT_INSIDE)
    9255                 :          0 :        trim = CUBIT_TRUE;
    9256                 :            : 
    9257         [ #  # ]:          0 :     TopoDS_Edge * edge = occ_curve->get_TopoDS_Edge();
    9258                 :            :     Standard_Real first;
    9259                 :            :     Standard_Real last;
    9260 [ #  # ][ #  # ]:          0 :     Handle(Geom_Curve) myCurve = BRep_Tool::Curve(*edge, first, last);
                 [ #  # ]
    9261                 :            :     Handle(Geom_SurfaceOfLinearExtrusion) new_surface = 
    9262 [ #  # ][ #  # ]:          0 :                new Geom_SurfaceOfLinearExtrusion(myCurve, offset_dir); 
         [ #  # ][ #  # ]
                 [ #  # ]
    9263                 :            :     Handle(Geom_RectangularTrimmedSurface) trimmed_surface = 
    9264                 :            :                new  Geom_RectangularTrimmedSurface(new_surface, first, last,
    9265 [ #  # ][ #  # ]:          0 :                                                    0, length);    
         [ #  # ][ #  # ]
                 [ #  # ]
    9266 [ #  # ][ #  # ]:          0 :     if(trimmed_surface == NULL)
    9267                 :            :     { 
    9268 [ #  # ][ #  # ]:          0 :       PRINT_ERROR( "Can not tweak move the %dth curve\n", i);
         [ #  # ][ #  # ]
    9269                 :          0 :       return CUBIT_FAILURE;
    9270                 :            :     }
    9271                 :            : #if OCC_VERSION_MINOR > 5
    9272 [ #  # ][ #  # ]:          0 :     TopoDS_Face FACE = BRepBuilderAPI_MakeFace(trimmed_surface, TOL);
         [ #  # ][ #  # ]
                 [ #  # ]
    9273                 :            : #else
    9274                 :            :   #if OCC_VERSION_MAINTENANCE < 2
    9275                 :            :     TopoDS_Face FACE = BRepBuilderAPI_MakeFace(trimmed_surface);
    9276                 :            :   #else
    9277                 :            :     TopoDS_Face FACE = BRepBuilderAPI_MakeFace(trimmed_surface, TOL);
    9278                 :            :   #endif
    9279                 :            : #endif
    9280 [ #  # ][ #  # ]:          0 :     Surface*  extrude_surf= OCCQueryEngine::instance()->populate_topology_bridge(FACE, CUBIT_TRUE);
    9281 [ #  # ][ #  # ]:          0 :     BodySM* body = CAST_TO(extrude_surf, OCCSurface)->my_body();
    9282                 :            :     //subtract or unite the two surfaces
    9283 [ #  # ][ #  # ]:          0 :     DLIList<BodySM*> bodies;
                 [ #  # ]
    9284         [ #  # ]:          0 :     bodies.append(original_body);
    9285                 :            :     CubitStatus stat;
    9286         [ #  # ]:          0 :     if(!trim)
    9287                 :            :     {
    9288         [ #  # ]:          0 :       bodies.append(body);
    9289         [ #  # ]:          0 :       stat = unite(bodies, new_bodysm_list, keep_old_body);
    9290                 :            :     }
    9291                 :            :     else 
    9292                 :            :     {
    9293         [ #  # ]:          0 :       DLIList<BodySM*> tool_bodies;
    9294         [ #  # ]:          0 :       tool_bodies.append(body);
    9295                 :            :       stat = subtract(tool_bodies, bodies, new_bodysm_list, CUBIT_FALSE, 
    9296 [ #  # ][ #  # ]:          0 :                       keep_old_body);
    9297                 :            :     } 
    9298         [ #  # ]:          0 :     if(stat == CUBIT_FAILURE)
    9299 [ #  # ][ #  # ]:          0 :       return CUBIT_FAILURE;    
    9300                 :          0 :   }
    9301         [ #  # ]:          0 :   if(preview)
    9302                 :            :   {
    9303         [ #  # ]:          0 :     GfxPreview::clear();
    9304 [ #  # ][ #  # ]:          0 :     for(int i = 0; i < new_bodysm_list.size(); i++)
    9305                 :            :     {
    9306         [ #  # ]:          0 :       BodySM* new_bodysm = new_bodysm_list.get_and_step();
    9307                 :            :       TopoDS_Shape* modified_shape ;
    9308 [ #  # ][ #  # ]:          0 :       CAST_TO(new_bodysm, OCCBody)->get_TopoDS_Shape(modified_shape);
    9309         [ #  # ]:          0 :       TopExp_Explorer Ex;
    9310         [ #  # ]:          0 :       Ex.Init(*modified_shape, TopAbs_FACE);
    9311 [ #  # ][ #  # ]:          0 :       for( ; Ex.More(); Ex.Next() )
                 [ #  # ]
    9312                 :            :       {
    9313 [ #  # ][ #  # ]:          0 :         TopoDS_Face face = TopoDS::Face(Ex.Current());
                 [ #  # ]
    9314                 :            :         // Draw this face
    9315 [ #  # ][ #  # ]:          0 :         OCCDrawTool::instance()->draw_FACE( &face, CUBIT_BLUE_INDEX, CUBIT_TRUE );
    9316         [ #  # ]:          0 :       }
    9317         [ #  # ]:          0 :     }
    9318 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(new_bodysm_list);
    9319         [ #  # ]:          0 :     new_bodysm_list.clean_out();
    9320                 :            :   }
    9321                 :          0 :   return CUBIT_SUCCESS;
    9322                 :            : }
    9323                 :            : 
    9324                 :            : //=============================================================================
    9325                 :            : // Function   : tweak_offset
    9326                 :            : // Member Type: PUBLIC
    9327                 :            : // Description: Tweak specified faces of a volume or volumes by offsetting
    9328                 :            : //              those faces by the offset distance.
    9329                 :            : // Author     : 
    9330                 :            : // Date       : 
    9331                 :            : //=============================================================================
    9332                 :          0 : CubitStatus OCCModifyEngine::tweak_offset( DLIList<Surface*> & /*surface_list*/, 
    9333                 :            :                                            double /*offset_distance*/,
    9334                 :            :                                            DLIList<Surface*> *add_surface_list_ptr,
    9335                 :            :                                            DLIList<double>*,
    9336                 :            :                                            DLIList<BodySM*> & /*new_bodysm_list*/,
    9337                 :            :                                            CubitBoolean /*keep_old_body*/,
    9338                 :            :                                            CubitBoolean show_preview ) const
    9339                 :            : {
    9340 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    9341                 :          0 :   return CUBIT_FAILURE;
    9342                 :            : }
    9343                 :            : 
    9344                 :            : //=============================================================================
    9345                 :            : // Function   : tweak_offset
    9346                 :            : // Member Type: PUBLIC
    9347                 :            : // Description: Tweak specified curves of a sheet body or bodies by offsetting
    9348                 :            : //              those curves by the offset distance.
    9349                 :            : // Author     : 
    9350                 :            : // Date       : 
    9351                 :            : //=============================================================================
    9352                 :          0 : CubitStatus OCCModifyEngine::tweak_offset( DLIList<Curve*> & /*curve_list*/,  
    9353                 :            :                                              double /*offset_distance*/,
    9354                 :            :                                              DLIList<Curve*>*,
    9355                 :            :                                              DLIList<double>*,
    9356                 :            :                                              DLIList<BodySM*> & /*new_bodysm_list*/,
    9357                 :            :                                              CubitBoolean /*keep_old_body*/,
    9358                 :            :                                              CubitBoolean show_preview ) const
    9359                 :            : {
    9360 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    9361                 :          0 :   return CUBIT_FAILURE;
    9362                 :            : }
    9363                 :            : 
    9364                 :            : //=============================================================================
    9365                 :            : // Function   : tweak_remove
    9366                 :            : // Member Type: PUBLIC
    9367                 :            : // Description: Function to remove surfaces from a body and then extend the 
    9368                 :            : //              remaining surfaces to fill the gap or hole.
    9369                 :            : // Author     : 
    9370                 :            : // Date       : 
    9371                 :            : //=============================================================================
    9372                 :          0 : CubitStatus OCCModifyEngine::tweak_remove( DLIList<Surface*> & /*surface_list*/,
    9373                 :            :                                              DLIList<BodySM*> & /*new_bodysm_list*/,
    9374                 :            :                                              CubitBoolean /*extend_adjoining*/,
    9375                 :            :                                              CubitBoolean /*keep_old_body*/,
    9376                 :            :                                              CubitBoolean show_preview ) const
    9377                 :            : {
    9378 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    9379                 :          0 :   return CUBIT_FAILURE;
    9380                 :            : }
    9381                 :            : 
    9382                 :            : //=============================================================================
    9383                 :            : // Function   : tweak_remove
    9384                 :            : // Member Type: PUBLIC
    9385                 :            : // Description: Function to remove curves from a sheet body and then extend the 
    9386                 :            : //              remaining curves or fill the gap or hole.
    9387                 :            : // Author     : 
    9388                 :            : // Date       : 
    9389                 :            : //=============================================================================
    9390                 :          0 : CubitStatus OCCModifyEngine::tweak_remove( DLIList<Curve*> & /*curve_list*/,
    9391                 :            :                                              DLIList<BodySM*> & /*new_bodysm_list*/, 
    9392                 :            :                                              CubitBoolean /*keep_old_body*/,
    9393                 :            :                                              CubitBoolean show_preview ) const
    9394                 :            : {
    9395 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    9396                 :          0 :   return CUBIT_FAILURE;
    9397                 :            : }
    9398                 :            : 
    9399                 :            : //=============================================================================
    9400                 :            : // Function   : tweak_target
    9401                 :            : // Member Type: PUBLIC
    9402                 :            : // Description: Tweak specified faces of a volume or volumes up to a target 
    9403                 :            : //              surface.
    9404                 :            : // Author     : 
    9405                 :            : // Date       : 
    9406                 :            : //=============================================================================
    9407                 :          0 : CubitStatus OCCModifyEngine::tweak_target( DLIList<Surface*> & /*surface_list*/,
    9408                 :            :                                            DLIList<Surface*> & ,
    9409                 :            :                                            DLIList<BodySM*> & /*new_bodysm_list*/,
    9410                 :            :                                            CubitBoolean extend_flg ,
    9411                 :            :                                            CubitPlane *limit_plane ,
    9412                 :            :                                            CubitBoolean /*reverse_flg*/,
    9413                 :            :                                            CubitBoolean /*keep_old_body*/,
    9414                 :            :                                            CubitBoolean show_preview ) const
    9415                 :            : {
    9416 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    9417                 :          0 :   return CUBIT_FAILURE;
    9418                 :            : }
    9419                 :            : 
    9420                 :            : //=============================================================================
    9421                 :            : // Function   : tweak_target
    9422                 :            : // Member Type: PUBLIC
    9423                 :            : // Description: Tweak specified edges of a surface or set of surfaces (in sheet
    9424                 :            : //              bodies) up to a target surface.
    9425                 :            : // Author     : 
    9426                 :            : // Date       : 
    9427                 :            : //=============================================================================
    9428                 :          0 : CubitStatus OCCModifyEngine::tweak_target( DLIList<Curve*> & /*curve_list*/,
    9429                 :            :                                            DLIList<Surface*> & /*target_surfs*/,
    9430                 :            :                                            DLIList<BodySM*> & /*new_bodysm_list*/, 
    9431                 :            :                                            CubitBoolean extend_flg ,
    9432                 :            :                                            CubitPlane *limit_plane ,
    9433                 :            :                                            CubitBoolean ,
    9434                 :            :                                            CubitBoolean /*keep_old_body*/,
    9435                 :            :                                            CubitBoolean show_preview,
    9436                 :            :                                            double max_area_increase ) const
    9437                 :            : {
    9438 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    9439                 :          0 :   return CUBIT_FAILURE;
    9440                 :            : }
    9441                 :            : 
    9442                 :            : //=============================================================================
    9443                 :            : // Function   : tweak_target
    9444                 :            : // Member Type: PUBLIC
    9445                 :            : // Description: Tweak specified edges of a sheet body or bodies up to a target
    9446                 :            : //              curve that is part of a sheet body.  The target is a surface 
    9447                 :            : //              created by thickening the owning surface of the target curve.
    9448                 :            : // Author     : 
    9449                 :            : // Date       : 
    9450                 :            : //=============================================================================
    9451                 :          0 : CubitStatus OCCModifyEngine::tweak_target( DLIList<Curve*> & /*curve_list*/,
    9452                 :            :                                            DLIList<Curve*> & /*target_curve_ptr*/, 
    9453                 :            :                                            DLIList<BodySM*> & /*new_bodysm_list*/, 
    9454                 :            :                                            CubitBoolean extend_flg,
    9455                 :            :                                            CubitPlane *limit_plane ,
    9456                 :            :                                            CubitBoolean,
    9457                 :            :                                            CubitBoolean /*keep_old_body*/,
    9458                 :            :                                            CubitBoolean show_preview,
    9459                 :            :                                            double max_area_increase ) const
    9460                 :            : {
    9461 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    9462                 :          0 :   return CUBIT_FAILURE;
    9463                 :            : }
    9464                 :            : 
    9465                 :          0 : CubitStatus OCCModifyEngine::tweak_target( TBPoint *point_ptr,
    9466                 :            :                                     DLIList<Surface*> &modify_surface_list,
    9467                 :            :                                     CubitVector &target_loc,
    9468                 :            :                                     BodySM *&new_bodysm_ptr,
    9469                 :            :                                     CubitBoolean keep_old_body ,
    9470                 :            :                                     CubitBoolean preview  ) const
    9471                 :            : {
    9472 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
    9473                 :          0 :   return CUBIT_FAILURE;
    9474                 :            : }
    9475                 :            : 
    9476                 :            : //================================================================================
    9477                 :            : // Description: split curve at split_location, upper level geometry gets 
    9478                 :            : //              updated as well.
    9479                 :            : // Author     : Jane Hu
    9480                 :            : // Date       : 02/11
    9481                 :            : //================================================================================
    9482                 :         11 : CubitStatus  OCCModifyEngine::split_curve( Curve* curve_to_split,
    9483                 :            :                                     const CubitVector& split_location,
    9484                 :            :                                     DLIList<Curve*>& created_curves ) 
    9485                 :            : {
    9486                 :            :   //find if the curve is stand-along or in a body.
    9487         [ +  - ]:         11 :   OCCQueryEngine* oqe = OCCQueryEngine::instance();
    9488                 :         11 :   DLIList <OCCBody* > *bodies = oqe->BodyList;
    9489                 :         11 :   DLIList<OCCLoop*> *loops = oqe->WireList;
    9490         [ -  + ]:         11 :   OCCCurve* occ_curve = CAST_TO(curve_to_split, OCCCurve);
    9491         [ +  - ]:         11 :   TopoDS_Edge* edge = occ_curve->get_TopoDS_Edge();
    9492                 :            :  
    9493         [ +  - ]:         11 :   LocOpe_SplitShape splitor;
    9494 [ +  - ][ +  - ]:         22 :   TopoDS_Shape from_shape;
    9495                 :         11 :   CubitBoolean found = false;
    9496                 :            :   //bodies consists compounds or solids.
    9497 [ +  - ][ -  + ]:         11 :   for(int i = 0; i < bodies->size(); i ++)
    9498                 :            :   {
    9499         [ #  # ]:          0 :     OCCBody* body = bodies->get_and_step();
    9500                 :            :     TopoDS_Shape* topo_shape;
    9501         [ #  # ]:          0 :     body->get_TopoDS_Shape(topo_shape);
    9502         [ #  # ]:          0 :     from_shape = *topo_shape;
    9503         [ #  # ]:          0 :     TopTools_IndexedDataMapOfShapeListOfShape M;
    9504                 :            : 
    9505         [ #  # ]:          0 :     TopExp::MapShapesAndAncestors(from_shape, TopAbs_EDGE, TopAbs_SHAPE, M);
    9506                 :            :     
    9507 [ #  # ][ #  # ]:          0 :     if(M.Contains(*edge) )   
    9508                 :            :     {
    9509                 :          0 :       found = true;
    9510 [ #  # ][ #  # ]:          0 :       break;
    9511                 :            :     }
    9512                 :          0 :   }
    9513                 :            :   
    9514 [ +  - ][ +  - ]:         11 :   for(int i = 0 ; found == false && i < loops->size(); i++)
         [ -  + ][ -  + ]
    9515                 :            :   {
    9516         [ #  # ]:          0 :     OCCLoop* loop = loops->get_and_step();
    9517         [ #  # ]:          0 :     TopoDS_Wire* topo_loop = loop->get_TopoDS_Wire();
    9518         [ #  # ]:          0 :     from_shape = *topo_loop;
    9519         [ #  # ]:          0 :     TopTools_IndexedDataMapOfShapeListOfShape M;
    9520         [ #  # ]:          0 :     TopExp::MapShapesAndAncestors(from_shape, TopAbs_EDGE, TopAbs_WIRE, M);  
    9521 [ #  # ][ #  # ]:          0 :     if(M.Contains(*edge))
    9522                 :            :     {
    9523                 :          0 :       found = true;
    9524 [ #  # ][ #  # ]:          0 :       break;
    9525                 :            :     }
    9526                 :          0 :   }
    9527                 :            :   
    9528         [ +  - ]:         11 :   if(!found)
    9529         [ +  - ]:         11 :     from_shape = *edge;
    9530                 :            :   
    9531                 :         11 :   TopoDS_Shape* p_shape = &from_shape;
    9532                 :            :   CubitStatus status = split_shape_by_location(p_shape, curve_to_split, 
    9533         [ +  - ]:         11 :                                    split_location, created_curves);
    9534                 :            : 
    9535 [ +  - ][ +  - ]:         22 :   DLIList<TopoDS_Shape*> shape_list;
    9536 [ +  - ][ +  - ]:         22 :   DLIList<BodySM*> new_body_list;
    9537         [ +  - ]:         11 :   shape_list.append(p_shape);
    9538 [ +  - ][ +  - ]:         11 :   shape_to_bodySM(shape_list, new_body_list);
                 [ +  - ]
    9539         [ +  - ]:         11 :   return status;
    9540                 :            : }
    9541                 :            : 
    9542                 :            : //================================================================================
    9543                 :            : // Function   : split_shape_by_location
    9544                 :            : // Description: split curve at split_location, upper level geometry (from_shape)
    9545                 :            : //              gets updated as well.
    9546                 :            : // Author     : Jane Hu
    9547                 :            : // Date       : 02/11
    9548                 :            : //================================================================================
    9549                 :         11 : CubitStatus OCCModifyEngine::split_shape_by_location(TopoDS_Shape *&from_shape,
    9550                 :            :                                            Curve* curve_to_split,
    9551                 :            :                                            const CubitVector& split_location,
    9552                 :            :                                            DLIList<Curve*>& created_curves)const
    9553                 :            : {
    9554         [ +  - ]:         11 :   LocOpe_SplitShape splitor(*from_shape);
    9555         [ +  - ]:         11 :   CubitBoolean is_edge = (from_shape->ShapeType() == TopAbs_EDGE);
    9556 [ -  + ][ +  - ]:         22 :   TopoDS_Edge edge = *CAST_TO(curve_to_split, OCCCurve)->get_TopoDS_Edge();
         [ +  - ][ +  - ]
    9557 [ +  - ][ +  - ]:         11 :   gp_Pnt pt = gp_Pnt(split_location.x(), split_location.y(), split_location.z());
         [ +  - ][ +  - ]
    9558 [ +  - ][ +  - ]:         22 :   TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(pt);
         [ +  - ][ +  - ]
    9559         [ +  - ]:         11 :   double param = curve_to_split->u_from_position(split_location);
    9560                 :            :   //double check that the split location is in curve
    9561                 :            :   double u_max, u_min;
    9562         [ +  - ]:         11 :   curve_to_split->get_param_range(u_min, u_max);
    9563 [ +  - ][ -  + ]:         11 :   if( param >= u_max || param <= u_min)
    9564                 :          0 :     return CUBIT_SUCCESS;
    9565                 :            : 
    9566         [ +  - ]:         11 :   splitor.Add(vertex, param, edge);
    9567                 :            :   
    9568                 :            :   //update the curve_list
    9569 [ +  - ][ +  - ]:         22 :   TopTools_ListOfShape edge_shapes;
    9570 [ +  - ][ +  - ]:         11 :   edge_shapes.Assign(splitor.DescendantShapes(edge));
    9571 [ +  - ][ +  + ]:         33 :   while(edge_shapes.Extent())
    9572                 :            :   {
    9573 [ +  - ][ +  - ]:         22 :      TopoDS_Shape edge_shape = edge_shapes.First();
    9574 [ +  - ][ +  - ]:         44 :      TopoDS_Edge occ_edge = TopoDS::Edge(edge_shape);
                 [ +  - ]
    9575                 :            :      OCCCurve* test_curve;
    9576 [ +  - ][ +  - ]:         22 :      if(!OCCQueryEngine::instance()->OCCMap->IsBound(occ_edge))
                 [ +  - ]
    9577                 :            :      {
    9578         [ +  - ]:         22 :        if(is_edge)
    9579 [ +  - ][ +  - ]:         22 :          test_curve = CAST_TO(OCCQueryEngine::instance()->populate_topology_bridge(occ_edge, CUBIT_TRUE), OCCCurve); 
                 [ -  + ]
    9580                 :            :        else
    9581 [ #  # ][ #  # ]:          0 :          test_curve = CAST_TO(OCCQueryEngine::instance()->populate_topology_bridge(occ_edge), OCCCurve);
                 [ #  # ]
    9582         [ +  - ]:         22 :        DLIList<OCCPoint*> points;
    9583         [ +  - ]:         22 :        test_curve->get_points(points);
    9584 [ +  - ][ +  + ]:         66 :        for(int i = 0 ; i <  points.size(); i++)
    9585 [ +  - ][ +  - ]:         66 :          points.get_and_step()->remove_curve(test_curve);
                 [ +  - ]
    9586                 :            :      }
    9587                 :            :      else
    9588 [ #  # ][ #  # ]:          0 :        test_curve = CAST_TO(OCCQueryEngine::instance()->populate_topology_bridge(occ_edge), OCCCurve);
                 [ #  # ]
    9589                 :            : 
    9590         [ +  - ]:         22 :      if(test_curve)
    9591                 :            :      {
    9592         [ +  - ]:         22 :        created_curves.append_unique(test_curve);
    9593                 :            :        //remove the points' curvelist of curve_to_split
    9594         [ +  - ]:         22 :        DLIList<OCCPoint*> points;
    9595         [ +  - ]:         22 :        test_curve->get_points(points);
    9596 [ +  - ][ +  + ]:         66 :        for(int i = 0; i < points.size(); i++)
    9597                 :            :        {
    9598         [ +  - ]:         44 :          OCCPoint* occ_p = points.get_and_step();
    9599 [ -  + ][ +  - ]:         44 :          occ_p->remove_curve(CAST_TO(curve_to_split, OCCCurve));
    9600 [ +  - ][ -  + ]:         44 :          if(from_shape->ShapeType() > TopAbs_EDGE)
    9601         [ #  # ]:          0 :            occ_p->remove_curve(test_curve);
    9602         [ +  - ]:         22 :        } 
    9603                 :            :      }
    9604         [ +  - ]:         22 :      edge_shapes.RemoveFirst();
    9605         [ +  - ]:         22 :   }
    9606                 :            : 
    9607 [ +  - ][ +  - ]:         22 :   TopTools_ListOfShape shapes;
    9608 [ +  - ][ +  - ]:         11 :   shapes.Assign(splitor.DescendantShapes(*from_shape));
    9609 [ +  - ][ -  + ]:         11 :   if(from_shape->ShapeType() ==TopAbs_COMPOUND)
    9610         [ #  # ]:          0 :     OCCBody::update_OCC_entity(*from_shape, shapes.First(),
    9611         [ #  # ]:          0 :                    (BRepBuilderAPI_MakeShape*) NULL, &splitor);
    9612                 :            : 
    9613 [ +  - ][ +  - ]:         11 :   else if(shapes.First().ShapeType() == TopAbs_SOLID)
                 [ -  + ]
    9614         [ #  # ]:          0 :     OCCLump::update_OCC_entity(TopoDS::Solid(*from_shape),
    9615 [ #  # ][ #  # ]:          0 :                    shapes.First(), (BRepBuilderAPI_MakeShape*) NULL, &splitor);
    9616                 :            : 
    9617 [ +  - ][ +  - ]:         11 :   else if(shapes.First().ShapeType() == TopAbs_SHELL)
                 [ -  + ]
    9618         [ #  # ]:          0 :     OCCShell::update_OCC_entity(TopoDS::Shell(*from_shape),
    9619 [ #  # ][ #  # ]:          0 :                    shapes.First(), (BRepBuilderAPI_MakeShape*) NULL, &splitor);
    9620                 :            : 
    9621 [ +  - ][ +  - ]:         11 :   else if(shapes.First().ShapeType() == TopAbs_FACE)
                 [ -  + ]
    9622         [ #  # ]:          0 :     OCCSurface::update_OCC_entity(TopoDS::Face(*from_shape),
    9623 [ #  # ][ #  # ]:          0 :               shapes.First(), (BRepBuilderAPI_MakeShape*) NULL, NULL, &splitor);
    9624                 :            : 
    9625 [ +  - ][ +  - ]:         11 :   else if(shapes.First().ShapeType() == TopAbs_WIRE)
                 [ -  + ]
    9626 [ #  # ][ #  # ]:          0 :     OCCLoop::update_OCC_entity(TopoDS::Wire(*from_shape), &splitor);
    9627                 :            :  
    9628 [ +  - ][ +  - ]:         11 :   from_shape = new TopoDS_Shape(shapes.First());
                 [ +  - ]
    9629         [ +  - ]:         11 :   return CUBIT_SUCCESS;
    9630                 :            : }
    9631                 :            : 
    9632                 :          0 : CubitStatus OCCModifyEngine::remove_curve_slivers( BodySM* body,
    9633                 :            :                                                    double lengthlimit ) const
    9634                 :            : {
    9635         [ #  # ]:          0 :   DLIList<CubitBoolean> is_volume;
    9636 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> bodies;
    9637 [ #  # ][ #  # ]:          0 :   DLIList<TopoDS_Shape*> shapes;
    9638         [ #  # ]:          0 :   bodies.append(body);
    9639         [ #  # ]:          0 :   CubitStatus status = get_shape_list(bodies, shapes, is_volume, CUBIT_FALSE);
    9640         [ #  # ]:          0 :   if(!status)
    9641                 :            :   {
    9642 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Can't find underlying TopoDS_Shape for this body.\n");
         [ #  # ][ #  # ]
    9643                 :          0 :     return CUBIT_FAILURE;
    9644                 :            :   }
    9645 [ #  # ][ #  # ]:          0 :   Handle(ShapeBuild_ReShape) context;
    9646         [ #  # ]:          0 :   TopoDS_Shape new_shape = ShapeFix::RemoveSmallEdges(*shapes.get(), 
    9647 [ #  # ][ #  # ]:          0 :                            lengthlimit, context);
    9648 [ #  # ][ #  # ]:          0 :   new_shape = context->Apply(new_shape, TopAbs_COMPOUND);
         [ #  # ][ #  # ]
    9649 [ #  # ][ #  # ]:          0 :   if(context->Status(ShapeExtend_OK))
                 [ #  # ]
    9650                 :            :   {
    9651 [ #  # ][ #  # ]:          0 :     PRINT_INFO("There's no small edges on this body.\n");
         [ #  # ][ #  # ]
    9652                 :          0 :     return CUBIT_SUCCESS;
    9653                 :            :   }
    9654                 :            :      
    9655 [ #  # ][ #  # ]:          0 :   else if(context->Status(ShapeExtend_FAIL))
                 [ #  # ]
    9656                 :            :   {
    9657 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Small edges can't be removed from this body.\n");
         [ #  # ][ #  # ]
    9658                 :          0 :     return CUBIT_FAILURE;
    9659                 :            :   }
    9660                 :            : 
    9661 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->delete_solid_model_entities(body);
    9662 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*>tbs = OCCQueryEngine::instance()->populate_topology_bridge(new_shape);
                 [ #  # ]
    9663                 :            :   
    9664         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    9665                 :            : }
    9666                 :            : 
    9667                 :            : //================================================================================
    9668                 :            : // Description: Creates a net surface.
    9669                 :            : // Author     : Tyronne Lim
    9670                 :            : // Date       : 08/18/03
    9671                 :            : //================================================================================
    9672                 :          0 : CubitStatus OCCModifyEngine::create_net_surface( DLIList<Surface*>& /*ref_face_list*/, 
    9673                 :            :                                                    BodySM *& /*new_body*/,
    9674                 :            :                                                    DLIList<DLIList<CubitVector*>*> & /*vec_lists_u*/, 
    9675                 :            :                                                    DLIList<DLIList<CubitVector*>*> & /*vec_lists_v*/, 
    9676                 :            :                                                    double /*net_tol*/, 
    9677                 :            :                                                    CubitBoolean /*heal*/ ) const
    9678                 :            : {
    9679 [ #  # ][ #  # ]:          0 :    PRINT_ERROR("Function not implemented in this engine.\n");
    9680                 :          0 :    return CUBIT_FAILURE;
    9681                 :            : }
    9682                 :            : 
    9683                 :            : //================================================================================
    9684                 :            : // Description: Creates a net surface.
    9685                 :            : // Author     : Tyronne Lim
    9686                 :            : // Date       : 08/18/03
    9687                 :            : //================================================================================
    9688                 :          0 : CubitStatus OCCModifyEngine::create_net_surface( DLIList<Curve*>& /*u_curves*/, 
    9689                 :            :                                                    DLIList<Curve*>& /*v_curves*/,
    9690                 :            :                                                    BodySM *& /*new_body*/, 
    9691                 :            :                                                    double /*net_tol*/, 
    9692                 :            :                                                    CubitBoolean /*heal*/ ) const
    9693                 :            : {
    9694 [ #  # ][ #  # ]:          0 :    PRINT_ERROR("Function not implemented in this engine.\n");
    9695                 :          0 :    return CUBIT_FAILURE;
    9696                 :            : }
    9697                 :            : 
    9698                 :            : //================================================================================
    9699                 :            : // Description: Creates an offset surface.
    9700                 :            : // Author     : Jane Hu
    9701                 :            : // Date       : 01/09
    9702                 :            : //================================================================================
    9703                 :          0 : CubitStatus OCCModifyEngine::create_offset_surface( Surface* face_ptr, 
    9704                 :            :                                                     BodySM*& new_body, 
    9705                 :            :                                                     double offset ) const
    9706                 :            : {
    9707                 :            :   //create offset surface from its center along center normal of distance 
    9708                 :            :   //"offset"
    9709         [ #  # ]:          0 :   OCCSurface *occ_surface =  CAST_TO(face_ptr, OCCSurface);
    9710         [ #  # ]:          0 :   if (occ_surface == NULL)
    9711                 :            :     {
    9712 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Option not supported for non-occ based geometry.\n");
         [ #  # ][ #  # ]
    9713                 :          0 :       return CUBIT_FAILURE;
    9714                 :            :     } 
    9715                 :            : 
    9716                 :          0 :   Surface* c_surface = NULL;
    9717         [ #  # ]:          0 :   c_surface = make_Surface(occ_surface);
    9718         [ #  # ]:          0 :   if (c_surface == NULL)
    9719                 :            :   {
    9720 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Cannot copy surface in sweep_translational.\n");
         [ #  # ][ #  # ]
    9721                 :          0 :     return CUBIT_FAILURE;
    9722                 :            :   }
    9723         [ #  # ]:          0 :   occ_surface = CAST_TO(c_surface, OCCSurface);
    9724                 :            : 
    9725         [ #  # ]:          0 :   CubitVector center = occ_surface->center_point();
    9726         [ #  # ]:          0 :   CubitVector normal;
    9727         [ #  # ]:          0 :   occ_surface->closest_point(center,NULL,&normal); 
    9728         [ #  # ]:          0 :   CubitVector v = normal * offset;
    9729 [ #  # ][ #  # ]:          0 :   OCCQueryEngine::instance()->translate(occ_surface, v);
    9730         [ #  # ]:          0 :   new_body = occ_surface->my_body();
    9731                 :          0 :   return CUBIT_SUCCESS;
    9732                 :            : }
    9733                 :            : 
    9734                 :            : //================================================================================
    9735                 :            : // Description: Creates an offset body.
    9736                 :            : // Author     : Jane Hu
    9737                 :            : // Date       : 01/09
    9738                 :            : //================================================================================
    9739                 :          0 : CubitStatus OCCModifyEngine::create_offset_body( BodySM* body_ptr, 
    9740                 :            :                                                  BodySM*& new_bodysm, 
    9741                 :            :                                                  double offset_distance ) const
    9742                 :            : {
    9743         [ #  # ]:          0 :   PRINT_ERROR("Function not implemented because offset_distance \n"
    9744         [ #  # ]:          0 :                "doesn't show offset direction.\n");
    9745                 :          0 :   return CUBIT_FAILURE;
    9746                 :            : }
    9747                 :            : 
    9748                 :            : //================================================================================
    9749                 :            : // Description: Creates a skin surface.
    9750                 :            : // Author     : Jane Hu
    9751                 :            : // Date       : 01/09
    9752                 :            : //================================================================================
    9753                 :         11 : CubitStatus OCCModifyEngine::create_skin_surface( DLIList<Curve*>& curves, 
    9754                 :            :                                                   BodySM*& new_body,
    9755                 :            :                                                   DLIList<Curve*>&) const
    9756                 :            : {
    9757                 :         11 :    new_body = NULL;
    9758                 :         11 :    Surface* surf = make_Surface(BEST_FIT_SURFACE_TYPE, curves);
    9759         [ +  - ]:         11 :    if(surf)
    9760                 :            :    {
    9761         [ -  + ]:         11 :      new_body = CAST_TO(surf, OCCSurface)->my_body();
    9762                 :         11 :      return CUBIT_SUCCESS;
    9763                 :            :    } 
    9764                 :          0 :    return CUBIT_FAILURE;
    9765                 :            : }
    9766                 :            : 
    9767                 :            : //================================================================================
    9768                 :            : // Description: Creates a shell body from lofting surfaces.
    9769                 :            : // Author     : Jane Hu
    9770                 :            : // Date       : 01/09
    9771                 :            : //================================================================================
    9772                 :            : //CubitStatus OCCModifyEngine::loft_surfaces( Surface * face1, 
    9773                 :            : //                                            const double & /*takeoff1*/,
    9774                 :            : //                                            Surface * face2, 
    9775                 :            : //                                            const double & /*takeoff2*/,
    9776                 :            : //                                           BodySM*& new_body,
    9777                 :            : //                                            CubitBoolean /*arc_length_option*/, 
    9778                 :            : //                                            CubitBoolean /*twist_option*/,
    9779                 :            : //                                            CubitBoolean /*align_direction*/, 
    9780                 :            : //                                            CubitBoolean /*perpendicular*/,
    9781                 :            : //                                            CubitBoolean /*simplify_option*/ ) const
    9782                 :            : //{
    9783                 :            : //   BRepOffsetAPI_ThruSections loft(CUBIT_FALSE);
    9784                 :            : //   CubitStatus stat = do_loft(loft, face1, face2);
    9785                 :            : //   if(!stat)
    9786                 :            : //     return CUBIT_FAILURE;
    9787                 :            : //
    9788                 :            : //   TopoDS_Shape shape = loft.Shape();
    9789                 :            : //   TopoDS_Shell shell = TopoDS::Shell(shape);
    9790                 :            : //   OCCShell* occ_shell = OCCQueryEngine::instance()->populate_topology_bridge(shell, CUBIT_TRUE);
    9791                 :            : //   if (occ_shell == NULL)
    9792                 :            : //   {
    9793                 :            : //     PRINT_ERROR("In OCCModifyEngine::loft_surfaces\n"
    9794                 :            : //                 "   Cannot create a loft surface for given surfaces.\n");
    9795                 :            : //     return CUBIT_FAILURE;
    9796                 :            : //   }
    9797                 :            : //   new_body = occ_shell->my_body();
    9798                 :            : //   return CUBIT_SUCCESS;
    9799                 :            : //}
    9800                 :            : 
    9801                 :            : //================================================================================
    9802                 :            : // Description: Creates a solid body by lofting surfaces between surfaces
    9803                 :            : // Author     : Jane Hu
    9804                 :            : // Date       : 02/12
    9805                 :            : //================================================================================
    9806                 :         11 : CubitStatus OCCModifyEngine::loft_surfaces_to_body( DLIList<Surface*> &surfaces,
    9807                 :            :                              DLIList<double> &takeoff_factor_list, //not used
    9808                 :            :                              DLIList<Surface*> &takeoff_vector_surface_list, //not used
    9809                 :            :                              DLIList<CubitVector> &surface_takeoff_vector_list, //not used
    9810                 :            :                              DLIList<Curve*> &takeoff_vector_curve_list, //not used
    9811                 :            :                              DLIList<CubitVector> &curve_takeoff_vector_list, //not used
    9812                 :            :                              DLIList<Curve*> &guides, 
    9813                 :            :                              DLIList<TBPoint*> &match_vertices_list, //not used
    9814                 :            :                              BodySM*& new_body,
    9815                 :            :                              CubitBoolean global_guides,
    9816                 :            :                              CubitBoolean closed, //not used
    9817                 :            :                              CubitBoolean show_matching_curves,
    9818                 :            :                              CubitBoolean preview)const
    9819                 :            : {
    9820         [ +  - ]:         11 :    BRepOffsetAPI_ThruSections loft(CUBIT_TRUE);
    9821 [ +  - ][ +  - ]:         11 :    if(global_guides || guides.size() > 0)
         [ -  + ][ -  + ]
    9822         [ #  # ]:          0 :      loft.Init(CUBIT_TRUE, CUBIT_TRUE);
    9823                 :            :    else
    9824         [ +  - ]:         11 :      loft.SetSmoothing(CUBIT_TRUE);
    9825         [ +  - ]:         11 :    CubitStatus stat = do_loft(loft, surfaces) ;
    9826         [ -  + ]:         11 :    if(!stat)
    9827                 :          0 :      return CUBIT_FAILURE;
    9828                 :            : 
    9829 [ +  - ][ +  - ]:         22 :    TopoDS_Shape shape = loft.Shape();
                 [ +  - ]
    9830 [ -  + ][ #  # ]:         11 :    if(preview && show_matching_curves)
    9831                 :            :    {
    9832 [ #  # ][ #  # ]:          0 :      PRINT_WARNING("Can't show matching curves in OCC.\n");
         [ #  # ][ #  # ]
    9833                 :            :    }
    9834         [ -  + ]:         11 :    else if(preview)
    9835                 :            :    {
    9836         [ #  # ]:          0 :      GfxPreview::clear();
    9837                 :            :      // Draw this topoDS_shape
    9838 [ #  # ][ #  # ]:          0 :      OCCDrawTool::instance()->draw_TopoDS_Shape( &shape, CUBIT_BLUE_INDEX, CUBIT_FALSE, CUBIT_TRUE );
    9839                 :            : 
    9840                 :          0 :      return CUBIT_SUCCESS;
    9841                 :            :    } 
    9842 [ +  - ][ +  - ]:         22 :    TopoDS_Solid solid = TopoDS::Solid(shape);
                 [ +  - ]
    9843 [ +  - ][ +  - ]:         11 :    Lump* lump = OCCQueryEngine::instance()->populate_topology_bridge(solid, CUBIT_TRUE);
    9844         [ -  + ]:         11 :    if (lump == NULL)
    9845                 :            :    {
    9846 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("In OCCModifyEngine::loft_surfaces_to_body\n"
                 [ #  # ]
    9847         [ #  # ]:          0 :                  "   Cannot create a loft body for given surfaces.\n");
    9848                 :          0 :      return CUBIT_FAILURE;
    9849                 :            :    }
    9850 [ -  + ][ +  - ]:         11 :    new_body = CAST_TO(lump, OCCLump)->get_body();
    9851         [ +  - ]:         22 :    return CUBIT_SUCCESS;   
    9852                 :            : }
    9853                 :            :  
    9854                 :         11 : CubitStatus OCCModifyEngine::do_loft(BRepOffsetAPI_ThruSections& loft,
    9855                 :            :                                   DLIList<Surface*> &surfaces) const
    9856                 :            : {
    9857         [ +  + ]:         33 :    for(int i = 0; i < surfaces.size(); i++)
    9858                 :            :    {
    9859 [ +  - ][ -  + ]:         22 :      OCCSurface* surf = CAST_TO(surfaces.get_and_step(), OCCSurface);
    9860         [ -  + ]:         22 :      if(!surf)
    9861                 :            :      {
    9862 [ #  # ][ #  # ]:          0 :        PRINT_ERROR("Surfaces are not OCC type.\n");
         [ #  # ][ #  # ]
    9863                 :          0 :        return CUBIT_FAILURE;
    9864                 :            :      }
    9865         [ +  - ]:         22 :      TopoDS_Face* topo_face = surf->get_TopoDS_Face();
    9866         [ +  - ]:         22 :      TopExp_Explorer Ex;
    9867         [ +  - ]:         22 :      Ex.Init(*topo_face, TopAbs_WIRE);
    9868 [ +  - ][ +  - ]:         44 :      TopoDS_Wire wire = TopoDS::Wire(Ex.Current());
         [ +  - ][ +  - ]
                 [ +  - ]
    9869 [ +  - ][ +  - ]:         22 :      if(Ex.More())
    9870                 :            :      {
    9871         [ +  - ]:         22 :        Ex.Next();
    9872 [ +  - ][ +  - ]:         22 :        if(Ex.Current().ShapeType() == TopAbs_WIRE)
                 [ -  + ]
    9873                 :            :        {
    9874 [ #  # ][ #  # ]:          0 :          PRINT_ERROR("Surface must have only one loop.\n");
         [ #  # ][ #  # ]
    9875                 :          0 :          return CUBIT_FAILURE;
    9876                 :            :        }
    9877                 :            :      }
    9878 [ +  - ][ +  - ]:         22 :      loft.AddWire(wire);
                 [ +  - ]
    9879                 :         22 :    }
    9880                 :         11 :    loft.Build();
    9881         [ -  + ]:         11 :    if(!loft.IsDone())
    9882                 :            :    {
    9883 [ #  # ][ #  # ]:          0 :      PRINT_ERROR("Surfaces can't be loft into a body.\n");
    9884                 :          0 :      return CUBIT_FAILURE;
    9885                 :            :    }
    9886                 :         11 :    return CUBIT_SUCCESS;
    9887                 :            : }  
    9888                 :            : 
    9889                 :            : //================================================================================
    9890                 :            : // Description: Creates a surface using a list of vectors, project to surface if
    9891                 :            : //              given. Those points are connected into a closed wire and then
    9892                 :            : //              a surface is created on it.
    9893                 :            : // Author     : Jane Hu
    9894                 :            : // Date       : 02/11
    9895                 :            : //================================================================================
    9896                 :          0 : CubitStatus OCCModifyEngine::create_surface( DLIList<CubitVector*>& vec_list, 
    9897                 :            :                                              BodySM *& new_body, 
    9898                 :            :                                              Surface * surface_ptr,
    9899                 :            :                                              CubitBoolean project_points) const
    9900                 :            : {
    9901                 :            :   int i;
    9902                 :            :   CubitStatus stat;
    9903         [ #  # ]:          0 :   DLIList<TBPoint*> new_points; 
    9904 [ #  # ][ #  # ]:          0 :   DLIList<CubitVector*> new_vec_list;
    9905         [ #  # ]:          0 :   if (surface_ptr)
    9906                 :            :   {
    9907                 :            :     // Check the project_points option and do the necessary checks or projections.
    9908         [ #  # ]:          0 :     if (project_points)
    9909                 :            :     {
    9910                 :            :       // Create a new list of points that are projected to the surface
    9911         [ #  # ]:          0 :       vec_list.reset();
    9912         [ #  # ]:          0 :       CubitVector *vec_ptr, new_vec;
    9913 [ #  # ][ #  # ]:          0 :       for( i=0; i<vec_list.size(); i++ )
    9914                 :            :       {
    9915         [ #  # ]:          0 :         vec_ptr = vec_list.get_and_step();
    9916         [ #  # ]:          0 :         stat = surface_ptr->closest_point( *vec_ptr, &new_vec );
    9917         [ #  # ]:          0 :         if(stat)
    9918 [ #  # ][ #  # ]:          0 :           new_vec_list.append(new CubitVector(new_vec) );
                 [ #  # ]
    9919                 :            :         else
    9920                 :            :         {
    9921 [ #  # ][ #  # ]:          0 :           PRINT_ERROR("Can't project the %dth point onto surface \n", i+1); 
         [ #  # ][ #  # ]
    9922 [ #  # ][ #  # ]:          0 :           for (int j = 0; j < new_vec_list.size(); j++)
    9923         [ #  # ]:          0 :             delete new_vec_list.get_and_step();
    9924                 :          0 :           return CUBIT_FAILURE;
    9925                 :            :         }         
    9926                 :            :       }
    9927                 :            :     } 
    9928                 :            : 
    9929                 :            :     else
    9930                 :            :     {
    9931                 :            :       // Make sure the points lie on the surface
    9932         [ #  # ]:          0 :       vec_list.reset();
    9933         [ #  # ]:          0 :       CubitVector loc_on_surf;
    9934                 :            :       CubitVector *vec_ptr;
    9935 [ #  # ][ #  # ]:          0 :       for( i=0; i<vec_list.size(); i++ )
    9936                 :            :       {
    9937         [ #  # ]:          0 :         vec_ptr = vec_list.get_and_step();
    9938         [ #  # ]:          0 :         surface_ptr->closest_point( *vec_ptr, &loc_on_surf );
    9939                 :            : 
    9940 [ #  # ][ #  # ]:          0 :         if (!vec_ptr->within_tolerance(loc_on_surf, GEOMETRY_RESABS))
    9941                 :            :         {
    9942 [ #  # ][ #  # ]:          0 :           PRINT_ERROR("all locations must lie on Surface\n" );
         [ #  # ][ #  # ]
    9943                 :          0 :           return CUBIT_FAILURE;
    9944                 :            :         }
    9945                 :            :       }
    9946         [ #  # ]:          0 :       new_vec_list = vec_list;
    9947                 :            :     }
    9948                 :            :   }
    9949                 :            : 
    9950                 :            :   // Make the surface in the solid modeller
    9951                 :            :   else
    9952         [ #  # ]:          0 :     new_vec_list = vec_list;
    9953                 :            : 
    9954 [ #  # ][ #  # ]:          0 :   for( i=0; i<new_vec_list.size(); i++ )
    9955                 :            :   {
    9956         [ #  # ]:          0 :      CubitVector* vec_ptr = new_vec_list.get_and_step();
    9957 [ #  # ][ #  # ]:          0 :      OCCPoint* point = new OCCPoint(*vec_ptr);
    9958         [ #  # ]:          0 :      new_points.append( (TBPoint*)point );
    9959                 :            :   }
    9960                 :            : 
    9961         [ #  # ]:          0 :   stat =  create_surface( new_points, new_body, NULL);
    9962                 :            : 
    9963 [ #  # ][ #  # ]:          0 :   if(project_points && surface_ptr)
    9964                 :            :   {
    9965 [ #  # ][ #  # ]:          0 :     for( i=0; i<new_vec_list.size(); i++ )
    9966                 :            :     {
    9967         [ #  # ]:          0 :       CubitVector *vec_ptr = new_vec_list.get_and_step();
    9968                 :          0 :       delete vec_ptr;
    9969                 :            :     }
    9970                 :            :   }
    9971         [ #  # ]:          0 :   return stat;
    9972                 :            : }
    9973                 :            : 
    9974                 :            : //================================================================================
    9975                 :            : // Description: Creates a surface using a list of points.
    9976                 :            : //              Those points are connected into a closed wire and then
    9977                 :            : //              a surface is created on it.
    9978                 :            : // Author     : Jane Hu
    9979                 :            : // Date       : 02/11
    9980                 :            : //================================================================================
    9981                 :            : CubitStatus
    9982                 :          0 : OCCModifyEngine::create_surface( DLIList<TBPoint*>& points,
    9983                 :            :                                BodySM *&new_body,
    9984                 :            :                                Surface * /*on_surface*/ )const
    9985                 :            : {
    9986         [ #  # ]:          0 :   TBPoint *start_point = points.get_and_step();
    9987         [ #  # ]:          0 :   DLIList<Curve*> curve_list;
    9988 [ #  # ][ #  # ]:          0 :   for(int i = 0; i < points.size(); i++)
    9989                 :            :   {
    9990         [ #  # ]:          0 :     CubitVector coord1 = start_point->coordinates();
    9991         [ #  # ]:          0 :     TBPoint *end_point = points.get_and_step();
    9992         [ #  # ]:          0 :     CubitVector coord2 = end_point->coordinates();
    9993 [ #  # ][ #  # ]:          0 :     if(coord1.within_tolerance( coord2, GEOMETRY_RESABS ) )
    9994                 :            :     {
    9995 [ #  # ][ #  # ]:          0 :        PRINT_ERROR( "Attempt to create a line between coincident points at (%f, %f, %f)\n",
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    9996         [ #  # ]:          0 :           coord1.x(), coord1.y(), coord1.z() );
    9997 [ #  # ][ #  # ]:          0 :        for(int  j=0; j<curve_list.size(); j++ )
    9998                 :            :        {
    9999         [ #  # ]:          0 :          Curve* curve_ptr = curve_list.get_and_step();
   10000 [ #  # ][ #  # ]:          0 :          OCCQueryEngine::instance()->delete_solid_model_entities( curve_ptr );
   10001                 :            :        }
   10002                 :          0 :        return CUBIT_FAILURE;
   10003                 :            :     }
   10004                 :            : 
   10005         [ #  # ]:          0 :     Curve* curve = make_Curve(start_point, end_point);
   10006         [ #  # ]:          0 :     curve_list.append(curve);
   10007                 :          0 :     start_point = end_point;
   10008                 :            :   }
   10009                 :            : 
   10010                 :            :   //make surface out of curves.
   10011         [ #  # ]:          0 :   Surface* surf = make_Surface(BEST_FIT_SURFACE_TYPE, curve_list); 
   10012                 :            :   OCCSurface* occ_surf;
   10013         [ #  # ]:          0 :   if(surf)
   10014         [ #  # ]:          0 :     occ_surf = CAST_TO(surf, OCCSurface);
   10015                 :            :   else
   10016                 :            :   {
   10017 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Failed to create a surface from given points. \n");
         [ #  # ][ #  # ]
   10018                 :          0 :     return CUBIT_FAILURE;
   10019                 :            :   }
   10020         [ #  # ]:          0 :   new_body = occ_surf->my_body(); 
   10021         [ #  # ]:          0 :   return CUBIT_SUCCESS; 
   10022                 :            : }
   10023                 :            : 
   10024                 :            : 
   10025                 :            : //================================================================================
   10026                 :            : // Description: Creates a weld surface.
   10027                 :            : // Author     : Tyronne Lim
   10028                 :            : // Date       : 08/18/03
   10029                 :            : //================================================================================
   10030                 :          0 : CubitStatus OCCModifyEngine::create_weld_surface( CubitVector & /*root*/,
   10031                 :            :                                                     Surface * /*ref_face1*/, 
   10032                 :            :                                                     double /*leg1*/, 
   10033                 :            :                                                     Surface * /*ref_face2*/, 
   10034                 :            :                                                     double /*leg2*/,
   10035                 :            :                                                     BodySM *& /*new_body*/ ) const
   10036                 :            : {
   10037 [ #  # ][ #  # ]:          0 :    PRINT_ERROR("Function not implemented in this engine.\n");
   10038                 :          0 :    return CUBIT_FAILURE;
   10039                 :            : }
   10040                 :            : 
   10041                 :         11 : CubitStatus OCCModifyEngine::scale( BodySM *&body, const CubitVector& factors )
   10042                 :            : {
   10043                 :         11 :   return OCCQueryEngine::instance()->scale( body, factors );
   10044                 :            : }
   10045                 :            : 
   10046                 :            : //================================================================================
   10047                 :            : // Description: According to what I read in ModifyEngine,
   10048                 :            : //              bridges_in are already the invalid_tbs, and we want to 
   10049                 :            : //              get all vertices, edges and surfaces below bridges_in into
   10050                 :            : //              bridges_out.
   10051                 :            : // Author     : Jane Hu 
   10052                 :            : // Date       : 02/11
   10053                 :            : //================================================================================
   10054                 :        262 : void OCCModifyEngine::get_possible_invalid_tbs(
   10055                 :            :                              DLIList<TopologyBridge*> &bridges_in,
   10056                 :            :                              DLIList<TopologyBridge*> &bridges_out)
   10057                 :            : {
   10058         [ +  - ]:        262 :   DLIList<OCCSurface*> surfaces;
   10059 [ +  - ][ +  - ]:        524 :   DLIList<OCCCurve*> curves;
   10060 [ +  - ][ +  - ]:        524 :   DLIList<OCCPoint*> points;
   10061                 :            : 
   10062 [ +  - ][ +  + ]:        590 :   for (int i = 0; i < bridges_in.size(); i++)
   10063                 :            :   {
   10064         [ +  - ]:        328 :      TopologyBridge* tb_in = bridges_in.get_and_step();
   10065         [ -  + ]:        328 :      if(! tb_in)
   10066                 :          0 :        continue;
   10067                 :            : 
   10068                 :        328 :      OCCBody *occ_body = NULL;
   10069 [ -  + ][ -  + ]:        328 :      if(OCCLump * lump_ptr = CAST_TO( tb_in,OCCLump))
   10070                 :            :      {
   10071         [ #  # ]:          0 :        BodySM* body = lump_ptr->get_body();
   10072         [ #  # ]:          0 :        assert (body);
   10073         [ #  # ]:          0 :        occ_body = CAST_TO(body, OCCBody);
   10074                 :            :      }
   10075                 :            :  
   10076 [ +  - ][ -  + ]:        328 :      else if( occ_body || (occ_body = CAST_TO( tb_in, OCCBody)))
         [ +  - ][ +  - ]
   10077                 :            :      {
   10078         [ +  - ]:        328 :        occ_body->get_all_surfaces(surfaces);
   10079         [ +  - ]:        328 :        occ_body->get_all_curves(curves);
   10080         [ +  - ]:        328 :        occ_body->get_all_points(points);
   10081                 :            :      }
   10082                 :            : 
   10083 [ #  # ][ #  # ]:          0 :      else if(OCCSurface *surface_ptr = CAST_TO( tb_in, OCCSurface))
   10084                 :            :      {
   10085         [ #  # ]:          0 :        surface_ptr->get_curves(curves);
   10086         [ #  # ]:          0 :        surface_ptr->get_points(points);
   10087         [ #  # ]:          0 :        surfaces.append(surface_ptr);
   10088                 :            :      }
   10089 [ #  # ][ #  # ]:          0 :      else if( OCCCurve *curve_ptr = CAST_TO( tb_in, OCCCurve))
   10090                 :            :      {
   10091         [ #  # ]:          0 :        curves.append(curve_ptr);
   10092         [ #  # ]:          0 :        curve_ptr->get_points(points);
   10093                 :            :      }
   10094 [ #  # ][ #  # ]:          0 :      else if( OCCPoint *point_ptr = CAST_TO( tb_in, OCCPoint))
   10095                 :            :      {
   10096         [ #  # ]:          0 :        points.append(point_ptr);
   10097                 :            :      }
   10098                 :            :   }
   10099 [ +  - ][ +  + ]:       4254 :   for (int i = 0; i < surfaces.size(); i++)
   10100 [ +  - ][ +  - ]:       3992 :     bridges_out.append((TopologyBridge*)surfaces.get_and_step());
   10101 [ +  - ][ +  + ]:       7620 :   for (int i = 0; i < curves.size(); i++)
   10102 [ +  - ][ +  - ]:       7358 :     bridges_out.append((TopologyBridge*)curves.get_and_step());
   10103 [ +  - ][ +  + ]:       5314 :   for (int i = 0; i < points.size(); i++)
   10104 [ +  - ][ +  - ]:       5314 :     bridges_out.append((TopologyBridge*)points.get_and_step());
                 [ +  - ]
   10105                 :        262 : }
   10106                 :          0 : CubitStatus OCCModifyEngine::curve_surface_intersection( Surface *surface,
   10107                 :            :                                             Curve* curve,
   10108                 :            :                                             DLIList<Curve*> &new_curves ) const
   10109                 :            : {
   10110                 :          0 :   return CUBIT_FAILURE;
   10111                 :            : }
   10112                 :            : 
   10113                 :          0 : BodySM* OCCModifyEngine::make_extended_sheet( DLIList<Surface*> &surface_list,
   10114                 :            :                                               CubitBox *clip_box_ptr,
   10115                 :            :                                               bool preview ) const
   10116                 :            : {
   10117 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("This feature is not implemented.\n");
   10118                 :          0 :   return (BodySM*) NULL;
   10119                 :            : }
   10120                 :            : 
   10121                 :          0 : CubitStatus OCCModifyEngine::remove_topology(DLIList<Curve*> &curves_to_remove,
   10122                 :            :                                        DLIList<Surface*> &surfs_to_remove,
   10123                 :            :                                        double backoff_distance,
   10124                 :            :                                        double small_edge_size,
   10125                 :            :                                        DLIList<BodySM*> &new_bodysm_list,
   10126                 :            :                                        CubitBoolean preview) const
   10127                 :            : {
   10128 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("This feature is not implemented.\n");
   10129                 :          0 :   return CUBIT_FAILURE;;
   10130                 :            : }
   10131                 :            : 
   10132                 :          0 : CubitStatus OCCModifyEngine::tolerant_imprint( DLIList<BodySM*> &bodies_in,
   10133                 :            :                                                DLIList<BodySM*> &new_bodies,
   10134                 :            :                                                DLIList<TopologyBridge*>*,
   10135                 :            :                                                DLIList<TopologyBridge*>* )  const
   10136                 :            : {
   10137 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
   10138                 :          0 :   return CUBIT_FAILURE;
   10139                 :            : }
   10140                 :            : 
   10141                 :          0 : CubitStatus OCCModifyEngine::tolerant_imprint(DLIList<Surface*> &surfs_in,
   10142                 :            :                              DLIList<BodySM*> &new_bodysm_list) const
   10143                 :            : {
   10144 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
   10145                 :          0 :   return CUBIT_FAILURE;
   10146                 :            : }
   10147                 :            : 
   10148                 :          0 : CubitStatus OCCModifyEngine::tolerant_imprint_surface_with_curves(
   10149                 :            :                                   Surface *surface_to_imprint,
   10150                 :            :                                   DLIList<Curve*> &curves,
   10151                 :            :                                   DLIList<TopologyBridge*> &temporary_bridges,
   10152                 :            :                                   BodySM *&new_body,
   10153                 :            :                                   DLIList<TopologyBridge*> *new_tbs,
   10154                 :            :                                   DLIList<TopologyBridge*> *att_tbs) const
   10155                 :            : {
   10156 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Option not supported for OCC based geometry.\n");
   10157                 :          0 :   return CUBIT_FAILURE;
   10158                 :            : }
   10159                 :            : 
   10160                 :            : //===============================================================================
   10161                 :            : // Function   : get_new_tbs
   10162                 :            : // Member Type: PUBLIC
   10163                 :            : // Description: given old list of surfaces, curves and points, and new list
   10164                 :            : //              of surfaces, curves and points, using physical comparison to
   10165                 :            : //              find out what entities are newly generated by imprinting.
   10166                 :            : //              And add imprint feature on the new entities.
   10167                 :            : // Author     : Jane HU
   10168                 :            : // Date       : 02/11
   10169                 :            : //===============================================================================
   10170                 :          0 : void OCCModifyEngine::get_new_tbs( 
   10171                 :            :       std::map<OCCSurface*, std::pair<CubitVector, double> >& surf_property_map,
   10172                 :            :       std::map<OCCCurve*, std::pair<CubitVector, double> >& curve_property_map,
   10173                 :            :       DLIList<OCCPoint*> &points, 
   10174                 :            :       DLIList<OCCSurface*> &new_surfaces,
   10175                 :            :       DLIList<OCCCurve*> &new_curves, 
   10176                 :            :       DLIList<OCCPoint*> &new_points, 
   10177                 :            :       DLIList<TopologyBridge*> *new_tbs)const
   10178                 :            : {
   10179                 :            : /*
   10180                 :            :   CubitSimpleAttrib *tmp_attrib = new CubitSimpleAttrib( "SOURCE_FEATURE", "IMPRINT" );
   10181                 :            : 
   10182                 :            :   CubitBoolean found = false;
   10183                 :            :   for (int i = 0; i < new_surfaces.size() ; i++)
   10184                 :            :   {
   10185                 :            :     OCCSurface* new_surf = new_surfaces.get_and_step(); 
   10186                 :            :     double new_d = new_surf->measure();
   10187                 :            :     CubitVector new_center = new_surf->center_point();
   10188                 :            :     std::map<OCCSurface*, std::pair<CubitVector, int> >::iterator it = 
   10189                 :            :             surf_property_map.find( new_surf);
   10190                 :            :     if(it != surf_property_map.end())
   10191                 :            :     {
   10192                 :            :       std::pair<CubitVector, int> pair;
   10193                 :            :       pair = it->second;
   10194                 :            :       double d = pair.second;
   10195                 :            :       CubitVector center = pair.first;
   10196                 :            :       surf_property_map.erase(it);
   10197                 :            :       if(center.about_equal(new_center) && fabs(d- new_d) <= TOL)
   10198                 :            :         found = true;
   10199                 :            :     }
   10200                 :            :     if(!found)
   10201                 :            :     {
   10202                 :            :       new_tbs->append(new_surf); 
   10203                 :            :       //Add an imprint feature to the topo.
   10204                 :            :       TopoDS_Face* new_shape = new_surf->get_TopoDS_Face(); 
   10205                 :            :       OCCAttribSet::append_attribute(tmp_attrib, *new_shape); 
   10206                 :            :     }
   10207                 :            :     found = false;
   10208                 :            :   }
   10209                 :            : 
   10210                 :            :   for (int i = 0; i < new_curves.size() ; i++)
   10211                 :            :   {
   10212                 :            :     OCCCurve* new_curve = new_curves.get_and_step();
   10213                 :            :     double new_d = new_curve->measure();
   10214                 :            :     CubitVector new_center;
   10215                 :            :     new_curve->position_from_u(0.5, new_center);
   10216                 :            :     std::map<OCCCurve*, std::pair<CubitVector, int> >::iterator it = 
   10217                 :            :       curve_property_map.find(new_curve);
   10218                 :            :     if( it != curve_property_map.end())
   10219                 :            :     {
   10220                 :            :       std::pair<CubitVector, int> pair;
   10221                 :            :       pair = it->second;
   10222                 :            :       double d = pair.second;
   10223                 :            :       CubitVector center = pair.first;
   10224                 :            :       curve_property_map.erase(it);
   10225                 :            :       if(center.about_equal(new_center) && fabs(d- new_d) <= TOL)
   10226                 :            :         found = true;
   10227                 :            :     }
   10228                 :            :     if(!found)
   10229                 :            :     {
   10230                 :            :       new_tbs->append(new_curve);
   10231                 :            :       //Add an imprint feature to the topo.
   10232                 :            :       TopoDS_Edge* new_shape = new_curve->get_TopoDS_Edge();
   10233                 :            :       OCCAttribSet::append_attribute(tmp_attrib, *new_shape);
   10234                 :            :     }
   10235                 :            :     found = false;
   10236                 :            :   }
   10237                 :            : 
   10238                 :            :   int num_new_points = new_points.size() -points.size(); 
   10239                 :            :   if(num_new_points > 0)
   10240                 :            :   {
   10241                 :            :     int  new_vertices_count = 0;
   10242                 :            :     CubitBoolean found = false; 
   10243                 :            :     for( int i = 0; i < new_points.size() && new_vertices_count < num_new_points; i++)
   10244                 :            :     {
   10245                 :            :       OCCPoint* new_point = new_points.get_and_step();
   10246                 :            :       for(int j = 0; j < points.size(); j ++)
   10247                 :            :       {
   10248                 :            :         OCCPoint* point = points.get(); 
   10249                 :            :         if(point == new_point)
   10250                 :            :         {
   10251                 :            :           found = true;
   10252                 :            :           points.remove();
   10253                 :            :           break;
   10254                 :            :         }
   10255                 :            :         points.step();
   10256                 :            :       }
   10257                 :            :       if(!found)
   10258                 :            :       {
   10259                 :            :         new_tbs->append(new_point);
   10260                 :            :         new_vertices_count ++;
   10261                 :            :         //Add an imprint feature to the topo.
   10262                 :            :         TopoDS_Vertex* new_shape = new_point->get_TopoDS_Vertex();
   10263                 :            :         OCCAttribSet::append_attribute(tmp_attrib, *new_shape);
   10264                 :            :       }
   10265                 :            :       found = false;
   10266                 :            :     }
   10267                 :            :   }
   10268                 :            :   delete tmp_attrib;
   10269                 :            : */
   10270                 :          0 : }
   10271                 :            : 
   10272                 :            : //===============================================================================
   10273                 :            : // Function   : get_att_tbs
   10274                 :            : // Member Type: PUBLIC
   10275                 :            : // Description: given new list of surfaces, curves and points for modified
   10276                 :            : //              bodies, find out what entities are "name" entities
   10277                 :            : // Author     : Jane HU
   10278                 :            : // Date       : 02/11
   10279                 :            : //===============================================================================
   10280                 :          0 : void OCCModifyEngine::get_att_tbs(DLIList<OCCSurface*> &new_surfaces,
   10281                 :            :                                   DLIList<OCCCurve*> &new_curves,
   10282                 :            :                                   DLIList<OCCPoint*> &new_points,
   10283                 :            :                                   const CubitString& name,
   10284                 :            :                                   DLIList<TopologyBridge*> *att_tbs)const
   10285                 :            : {
   10286         [ #  # ]:          0 :   DLIList<CubitSimpleAttrib> csa_list;
   10287 [ #  # ][ #  # ]:          0 :   for (int i = 0 ; i < new_surfaces.size(); i++)
   10288                 :            :   {
   10289         [ #  # ]:          0 :     OCCSurface* occ_surf = new_surfaces.get_and_step();
   10290         [ #  # ]:          0 :     csa_list.clean_out();
   10291         [ #  # ]:          0 :     occ_surf->get_simple_attribute(name, csa_list);
   10292 [ #  # ][ #  # ]:          0 :     if(csa_list.size() > 0)
   10293         [ #  # ]:          0 :       att_tbs->append(occ_surf);    
   10294                 :            :   }
   10295                 :            : 
   10296 [ #  # ][ #  # ]:          0 :   for (int i = 0 ; i < new_curves.size(); i++)
   10297                 :            :   {
   10298         [ #  # ]:          0 :     OCCCurve* occ_curve = new_curves.get_and_step();
   10299         [ #  # ]:          0 :     csa_list.clean_out();
   10300         [ #  # ]:          0 :     occ_curve->get_simple_attribute(name, csa_list);
   10301 [ #  # ][ #  # ]:          0 :     if(csa_list.size() > 0)
   10302         [ #  # ]:          0 :       att_tbs->append(occ_curve);
   10303                 :            :   }
   10304                 :            :  
   10305 [ #  # ][ #  # ]:          0 :   for (int i = 0 ; i < new_points.size(); i++)
   10306                 :            :   {
   10307         [ #  # ]:          0 :     OCCPoint* occ_point = new_points.get_and_step();
   10308         [ #  # ]:          0 :     csa_list.clean_out(); 
   10309         [ #  # ]:          0 :     occ_point->get_simple_attribute(name, csa_list);
   10310 [ #  # ][ #  # ]:          0 :     if(csa_list.size() > 0)
   10311         [ #  # ]:          0 :       att_tbs->append(occ_point);
   10312         [ #  # ]:          0 :   }
   10313                 :          0 : }
   10314                 :            : 
   10315                 :          0 : Curve* OCCModifyEngine::create_arc_radius(const CubitVector &center,
   10316                 :            :                                           TBPoint* ref_vertex_start,
   10317                 :            :                                           TBPoint* ref_vertex_end,
   10318                 :            :                                           const CubitVector &normal,
   10319                 :            :                                           double radius,
   10320                 :            :                                           bool full ,
   10321                 :            :                                           CubitBoolean preview  )
   10322                 :            : {
   10323         [ #  # ]:          0 :   CubitVector v1 = ref_vertex_start->coordinates();
   10324         [ #  # ]:          0 :   CubitVector v2 = ref_vertex_end->coordinates();  
   10325 [ #  # ][ #  # ]:          0 :   if ((2 * radius) < v1.distance_between(v2))
   10326                 :            :   {
   10327 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Unable to create acr from given radius and vertices. \n");
         [ #  # ][ #  # ]
   10328                 :          0 :     return (Curve*) NULL;
   10329                 :            :   }
   10330 [ #  # ][ #  # ]:          0 :   OCCPoint* center_point = new OCCPoint(center);
   10331                 :            :   Curve* curve =  create_arc_center_edge(center_point, ref_vertex_start, 
   10332                 :            :                                 ref_vertex_end,
   10333         [ #  # ]:          0 :                                 normal, radius, full , preview  );
   10334 [ #  # ][ #  # ]:          0 :   delete center_point;
   10335                 :            :   
   10336                 :          0 :   return curve;
   10337                 :            : }
   10338                 :            : 
   10339                 :         11 : Curve* OCCModifyEngine::create_arc(const CubitVector& position,
   10340                 :            :                                    double radius,
   10341                 :            :                                    double start_angle,//in degree
   10342                 :            :                                    double end_angle,//in degree
   10343                 :            :                                    CubitVector plane,
   10344                 :            :                                    bool preview )
   10345                 :            : {
   10346 [ +  - ][ +  - ]:         11 :   gp_Pnt P(position.x(), position.y(), position.z());
         [ +  - ][ +  - ]
   10347 [ +  - ][ +  - ]:         11 :   gp_Dir normal(plane.x(), plane.y(), plane.z());  
         [ +  - ][ +  - ]
   10348         [ +  - ]:         11 :   gp_Ax1 axis(P, normal);
   10349         [ +  - ]:         11 :   Handle(Geom_Circle) curve_ptr;
   10350 [ +  - ][ +  - ]:         11 :   curve_ptr = GC_MakeCircle( axis, radius);
         [ +  - ][ +  - ]
                 [ +  - ]
   10351 [ +  - ][ +  - ]:         11 :   gp_Circ circle = curve_ptr->Circ();
   10352                 :         11 :   start_angle *=  CUBIT_PI/180;
   10353                 :         11 :   end_angle *=  CUBIT_PI/180; 
   10354                 :         11 :   CubitBoolean sense = CUBIT_TRUE ;
   10355                 :            : 
   10356 [ +  - ][ +  - ]:         22 :   Handle_Geom_TrimmedCurve new_curve_ptr;
   10357 [ +  - ][ +  - ]:         11 :   new_curve_ptr =  GC_MakeArcOfCircle(circle, start_angle, end_angle, sense);
         [ +  - ][ +  - ]
                 [ +  - ]
   10358 [ +  - ][ +  - ]:         22 :   TopoDS_Edge new_edge = BRepBuilderAPI_MakeEdge(new_curve_ptr);
         [ +  - ][ +  - ]
   10359 [ +  - ][ +  - ]:         11 :   Curve*  new_curve = OCCQueryEngine::instance()->populate_topology_bridge(new_edge);
   10360         [ -  + ]:         11 :   if(preview)
   10361                 :            :   {
   10362         [ #  # ]:          0 :     GfxPreview::clear();
   10363         [ #  # ]:          0 :     OCCCurve* occ_curve = CAST_TO(new_curve, OCCCurve);
   10364         [ #  # ]:          0 :     TopoDS_Edge* h_edge = occ_curve->get_TopoDS_Edge();
   10365                 :            :     // Draw this edge
   10366 [ #  # ][ #  # ]:          0 :     OCCDrawTool::instance()->draw_EDGE( h_edge, CUBIT_BLUE_INDEX, CUBIT_TRUE );
   10367                 :            : 
   10368 [ #  # ][ #  # ]:          0 :     OCCQueryEngine::instance()->delete_solid_model_entities(new_curve);
   10369                 :          0 :     return (Curve*) NULL;
   10370                 :            :   }
   10371                 :            :   else
   10372         [ +  - ]:         22 :     return new_curve;
   10373                 :            : }
   10374                 :            : 
   10375                 :          0 : CubitStatus OCCModifyEngine::webcut_across_translate( 
   10376                 :            :                                      DLIList<BodySM*>& body_list,
   10377                 :            :                                      Surface* plane_surf1,
   10378                 :            :                                      Surface* plane_surf2,
   10379                 :            :                                      DLIList<BodySM*>& neighbor_imprint_list,
   10380                 :            :                                      DLIList<BodySM*>& results_list,
   10381                 :            :                                      ImprintType imprint_type ,
   10382                 :            :                                      bool preview ) const
   10383                 :            : {
   10384 [ #  # ][ #  # ]:          0 :   PRINT_WARNING("Not implemented yet. \n");
   10385                 :          0 :   return CUBIT_FAILURE;
   10386                 :            : }
   10387                 :            : //void OCCModifyEngine::start_tracking_history( DLIList<TopologyBridge*> &bridges,
   10388                 :            : //                                              OCCHistory &history_object,
   10389                 :            : //                                              bool ignore_parents )
   10390                 :            : //{
   10391                 :            : //}
   10392                 :            : 
   10393                 :            : //void OCCModifyEngine::stop_tracking_history( DLIList<BodySM*> &new_bodies,
   10394                 :            : //                                             OCCHistory &history_object )
   10395                 :            : //{
   10396                 :            : //  DLIList<TopologyBridge*> tbs;
   10397                 :            : //  CAST_LIST( new_bodies, tbs, TopologyBridge );
   10398                 :            : 
   10399                 :            :   //stop_tracking_history( tbs, history_object );
   10400                 :            : //}
   10401                 :            :  
   10402                 :            : //Following codes are OCC engine only, implemented by Boyd Tidwell
   10403                 :          0 : CubitStatus OCCModifyEngine::create_rectangle_surface( double width,
   10404                 :            :             double height,
   10405                 :            :             CubitVector plane,
   10406                 :            :             BodySM *&sheet_body) const
   10407                 :            : {
   10408                 :            :   //create points at the 4 corners
   10409         [ #  # ]:          0 :   CubitVector pos1( width*0.5, height*0.5, 0 );
   10410         [ #  # ]:          0 :   CubitVector pos2( -width*0.5, height*0.5, 0 );
   10411         [ #  # ]:          0 :   CubitVector pos3( -width*0.5, -height*0.5, 0 );
   10412         [ #  # ]:          0 :   CubitVector pos4( width*0.5, -height*0.5, 0 );
   10413                 :            : 
   10414         [ #  # ]:          0 :   DLIList<CubitVector*> vec_list(4);
   10415         [ #  # ]:          0 :   vec_list.append( &pos1 );
   10416         [ #  # ]:          0 :   vec_list.append( &pos2 );
   10417         [ #  # ]:          0 :   vec_list.append( &pos3 );
   10418         [ #  # ]:          0 :   vec_list.append( &pos4 );
   10419                 :            : 
   10420         [ #  # ]:          0 :   CubitStatus status = create_surface(vec_list, sheet_body, 0, CUBIT_FALSE );
   10421                 :            : 
   10422                 :            :   //rotate it so that it is aligned with the plane defined by vector 'plane'
   10423                 :            : 
   10424         [ #  # ]:          0 :   CubitVector current_plane(0,0,1);
   10425 [ #  # ][ #  # ]:          0 :   if (!plane.about_equal(current_plane))
   10426                 :            :   {
   10427         [ #  # ]:          0 :     CubitVector axis_of_rotation = current_plane * plane;
   10428                 :            :     double angle_of_rotation = axis_of_rotation.vector_angle(
   10429         [ #  # ]:          0 :          current_plane, plane );
   10430                 :            : 
   10431         [ #  # ]:          0 :     OCCQueryEngine::instance()->rotate( sheet_body, axis_of_rotation,
   10432         [ #  # ]:          0 :                                         RADIANS_TO_DEGREES(angle_of_rotation) );
   10433                 :            :   }
   10434                 :            : 
   10435         [ #  # ]:          0 :   return status;
   10436                 :            : }
   10437                 :            : 
   10438                 :          0 : CubitStatus OCCModifyEngine::create_ellipse_surface( TBPoint *pt1,
   10439                 :            :                                                      TBPoint *pt3,
   10440                 :            :                                                      CubitVector center_point,
   10441                 :            :                                                      BodySM *&sheet_body) const
   10442                 :            : {
   10443                 :            :   // make ellipse by creating two ellipse arcs in each sense direction
   10444         [ #  # ]:          0 :   Curve *ellipse1 = make_elliptical_Curve( pt1, pt3, center_point, 0, 360, CUBIT_FORWARD );
   10445         [ #  # ]:          0 :   if( NULL == ellipse1 )
   10446                 :          0 :     return CUBIT_FAILURE;
   10447         [ #  # ]:          0 :   DLIList<Curve*> curve_list(2);
   10448         [ #  # ]:          0 :   curve_list.append( ellipse1 );
   10449                 :            : 
   10450         [ #  # ]:          0 :   Curve *ellipse2 = make_elliptical_Curve( pt1, pt3, center_point, 0, 360, CUBIT_REVERSED );
   10451         [ #  # ]:          0 :   if( NULL == ellipse2 )
   10452                 :          0 :     return CUBIT_FAILURE;
   10453         [ #  # ]:          0 :   curve_list.append( ellipse2 );
   10454                 :            : 
   10455         [ #  # ]:          0 :   Surface *tmp_surface = make_Surface( PLANE_SURFACE_TYPE, curve_list, NULL, false );
   10456         [ #  # ]:          0 :   if( NULL == tmp_surface )
   10457                 :          0 :     return CUBIT_FAILURE;
   10458         [ #  # ]:          0 :   sheet_body = make_BodySM( tmp_surface );
   10459         [ #  # ]:          0 :   if( NULL == sheet_body)
   10460                 :          0 :     return CUBIT_FAILURE;
   10461                 :            : 
   10462         [ #  # ]:          0 :   return CUBIT_SUCCESS;
   10463                 :            : }
   10464                 :            : 
   10465                 :          0 : CubitStatus OCCModifyEngine::create_ellipse_surface( double major_radius,
   10466                 :            :                                                      double minor_radius,
   10467                 :            :                                                      CubitVector plane,
   10468                 :            :                                                      BodySM *&sheet_body) const
   10469                 :            : {
   10470                 :            :   //create the points
   10471         [ #  # ]:          0 :   CubitVector tmp_pt( major_radius, 0, 0 );
   10472         [ #  # ]:          0 :   TBPoint *pt1 = make_Point( tmp_pt );
   10473                 :            : 
   10474         [ #  # ]:          0 :   tmp_pt.set( 0, minor_radius, 0 );
   10475         [ #  # ]:          0 :   TBPoint *pt2 = make_Point( tmp_pt );
   10476                 :            : 
   10477         [ #  # ]:          0 :   CubitVector center_point(0,0,0);
   10478                 :            : 
   10479                 :            :   // make ellipse by creating two ellipse arcs in each sense direction
   10480         [ #  # ]:          0 :   Curve *ellipse1 = make_elliptical_Curve( pt1, pt2, center_point, 0, 360, CUBIT_FORWARD );
   10481         [ #  # ]:          0 :   if( NULL == ellipse1 )
   10482                 :          0 :     return CUBIT_FAILURE;
   10483         [ #  # ]:          0 :   DLIList<Curve*> curve_list(2);
   10484         [ #  # ]:          0 :   curve_list.append( ellipse1 );
   10485                 :            : 
   10486         [ #  # ]:          0 :   Curve *ellipse2 = make_elliptical_Curve( pt1, pt2, center_point, 0, 360, CUBIT_REVERSED );
   10487         [ #  # ]:          0 :   if( NULL == ellipse2 )
   10488                 :          0 :     return CUBIT_FAILURE;
   10489         [ #  # ]:          0 :   curve_list.append( ellipse2 );
   10490                 :            : 
   10491         [ #  # ]:          0 :   Surface *tmp_surface = make_Surface(PLANE_SURFACE_TYPE, curve_list, NULL, false );
   10492         [ #  # ]:          0 :   if( NULL == tmp_surface )
   10493                 :          0 :     return CUBIT_FAILURE;
   10494                 :            : 
   10495         [ #  # ]:          0 :   sheet_body = make_BodySM( tmp_surface );
   10496         [ #  # ]:          0 :   if( NULL == sheet_body)
   10497                 :          0 :     return CUBIT_FAILURE;
   10498                 :            : 
   10499                 :            :   //rotate it so that it is aligned with the plane defined by vector 'plane'
   10500         [ #  # ]:          0 :   CubitVector current_plane(0,0,1);
   10501 [ #  # ][ #  # ]:          0 :   if (!plane.about_equal(current_plane))
   10502                 :            :   {
   10503         [ #  # ]:          0 :     CubitVector axis_of_rotation = current_plane * plane;
   10504         [ #  # ]:          0 :     double angle_of_rotation = axis_of_rotation.vector_angle(current_plane, plane );
   10505                 :            : 
   10506         [ #  # ]:          0 :     OCCQueryEngine::instance()->rotate( sheet_body, axis_of_rotation,
   10507         [ #  # ]:          0 :                                         RADIANS_TO_DEGREES(angle_of_rotation) );
   10508                 :            :   }
   10509                 :            : 
   10510         [ #  # ]:          0 :   return CUBIT_SUCCESS;
   10511                 :            : }
   10512                 :            : 
   10513                 :          0 : Curve* OCCModifyEngine::make_elliptical_Curve( TBPoint const* point1,
   10514                 :            :                                                TBPoint const* point2,
   10515                 :            :                                                CubitVector &center_point,
   10516                 :            :                                                double start_angle,
   10517                 :            :                                                double end_angle,
   10518                 :            :                                                CubitSense sense) const
   10519                 :            : {
   10520                 :          0 :   GeometryType curve_type = ELLIPSE_CURVE_TYPE;
   10521                 :          0 :   Curve *curve = NULL;
   10522         [ #  # ]:          0 :   if(sense ==CUBIT_FORWARD)
   10523                 :          0 :     curve = make_Curve(curve_type, point1, point2, &center_point );
   10524                 :            :   else
   10525                 :          0 :     curve = make_Curve(curve_type, point2, point1, &center_point );
   10526         [ #  # ]:          0 :   if ( curve == NULL )
   10527                 :            :   {
   10528         [ #  # ]:          0 :     PRINT_ERROR("In OCCModifyEngine::make_elliptical_Curve\n"
   10529         [ #  # ]:          0 :                 "       Cannot make Curve object.\n");
   10530                 :          0 :     return (Curve *)NULL;
   10531                 :            :   }
   10532                 :          0 :   return curve;
   10533                 :            : }
   10534                 :            : 
   10535                 :            : //circle surface passes three points.
   10536                 :          0 : CubitStatus OCCModifyEngine::create_circle_surface( TBPoint *pt1,
   10537                 :            :                                                     CubitVector center_point,
   10538                 :            :                                                     TBPoint *pt3,
   10539                 :            :                                                     BodySM *&sheet_body)const
   10540                 :            : {
   10541 [ #  # ][ #  # ]:          0 :   CubitVector * center = new CubitVector(center_point);
   10542         [ #  # ]:          0 :   Curve *circle = make_Curve( ARC_CURVE_TYPE, pt1, pt3, center);
   10543                 :          0 :   delete center;
   10544                 :            : 
   10545         [ #  # ]:          0 :   DLIList<Curve*> curve_list(1);
   10546         [ #  # ]:          0 :   curve_list.append( circle );
   10547         [ #  # ]:          0 :   Surface *tmp_surface = make_Surface(PLANE_SURFACE_TYPE, curve_list, NULL, false );
   10548                 :            : 
   10549         [ #  # ]:          0 :   if( NULL == tmp_surface )
   10550                 :          0 :     return CUBIT_FAILURE;
   10551                 :            : 
   10552         [ #  # ]:          0 :   sheet_body = make_BodySM( tmp_surface );
   10553         [ #  # ]:          0 :   if( NULL == sheet_body)
   10554                 :          0 :     return CUBIT_FAILURE;
   10555                 :            : 
   10556         [ #  # ]:          0 :   return CUBIT_SUCCESS;
   10557                 :            : }
   10558                 :            : 
   10559                 :            : //circle surface passes pt1, pt3, and centered at center_point.
   10560                 :          0 : CubitStatus OCCModifyEngine::create_circle_surface( TBPoint *pt1,
   10561                 :            :                                                     TBPoint *pt3,
   10562                 :            :                                                     CubitVector center_point,
   10563                 :            :                                                     BodySM *&sheet_body)const
   10564                 :            : {
   10565         [ #  # ]:          0 :   CubitVector v1 = pt1->coordinates();
   10566         [ #  # ]:          0 :   CubitVector v3 = pt3->coordinates();
   10567         [ #  # ]:          0 :   CubitVector normal(0,0,0);
   10568         [ #  # ]:          0 :   CubitVector dir1 = v1 - center_point;
   10569         [ #  # ]:          0 :   CubitVector dir2 = v3 - center_point;
   10570                 :            : 
   10571 [ #  # ][ #  # ]:          0 :   normal = dir1 * dir2;
   10572 [ #  # ][ #  # ]:          0 :   if(normal.length() < TOL)
   10573                 :            :   {
   10574 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("The given points can't decide the surface plane. \n");
         [ #  # ][ #  # ]
   10575                 :          0 :     return CUBIT_FAILURE;
   10576                 :            :   }
   10577         [ #  # ]:          0 :   Handle(Geom_Circle) curve_ptr;
   10578 [ #  # ][ #  # ]:          0 :   gp_Dir norm(normal.x(), normal.y(), normal.z());
         [ #  # ][ #  # ]
   10579 [ #  # ][ #  # ]:          0 :   gp_Pnt center = gp_Pnt( center_point.x(), center_point.y(), center_point.z());
         [ #  # ][ #  # ]
   10580                 :            : 
   10581         [ #  # ]:          0 :   double radius = v1.distance_between(center_point);
   10582 [ #  # ][ #  # ]:          0 :   curve_ptr = GC_MakeCircle(center,norm,radius);
         [ #  # ][ #  # ]
                 [ #  # ]
   10583                 :            : 
   10584         [ #  # ]:          0 :   OCCPoint* occ_pt1 = CAST_TO(const_cast<TBPoint*>(pt1),OCCPoint);
   10585         [ #  # ]:          0 :   TopoDS_Vertex * vt1 = occ_pt1->get_TopoDS_Vertex();
   10586 [ #  # ][ #  # ]:          0 :   TopoDS_Edge new_edge;
   10587 [ #  # ][ #  # ]:          0 :   new_edge = BRepBuilderAPI_MakeEdge(curve_ptr, *vt1, *vt1);
         [ #  # ][ #  # ]
                 [ #  # ]
   10588                 :            : 
   10589                 :            :   Curve* circle = OCCQueryEngine::instance()->
   10590 [ #  # ][ #  # ]:          0 :                    populate_topology_bridge(new_edge, CUBIT_TRUE);
   10591 [ #  # ][ #  # ]:          0 :   DLIList<Curve*> curve_list(1);
   10592         [ #  # ]:          0 :   curve_list.append( circle );
   10593                 :            :   Surface *tmp_surface = make_Surface(PLANE_SURFACE_TYPE, curve_list, NULL,
   10594         [ #  # ]:          0 :                                       false );
   10595         [ #  # ]:          0 :   if( NULL == tmp_surface )
   10596                 :          0 :     return CUBIT_FAILURE;
   10597                 :            : 
   10598 [ #  # ][ #  # ]:          0 :   sheet_body = OCCModifyEngine::instance()->make_BodySM( tmp_surface );
   10599         [ #  # ]:          0 :   if( NULL == sheet_body)
   10600                 :          0 :     return CUBIT_FAILURE;
   10601                 :            : 
   10602         [ #  # ]:          0 :   return CUBIT_SUCCESS;
   10603                 :            : }
   10604                 :            : 
   10605                 :          0 : CubitStatus OCCModifyEngine::create_circle_surface( double radius,
   10606                 :            :                                                     CubitVector plane,
   10607                 :            :                                                     BodySM *&sheet_body) const
   10608                 :            : {
   10609         [ #  # ]:          0 :   CubitVector center_pt;
   10610         [ #  # ]:          0 :   center_pt.set(0, 0, 0);
   10611 [ #  # ][ #  # ]:          0 :   CubitVector pt2, pt3;
   10612 [ #  # ][ #  # ]:          0 :   if (plane.x() > 0 )
   10613                 :            :   {
   10614         [ #  # ]:          0 :     pt2.set( 0, radius, 0 );
   10615         [ #  # ]:          0 :     pt3.set( 0, 0, radius);
   10616                 :            :   }
   10617 [ #  # ][ #  # ]:          0 :   else if (plane.y() > 0)
   10618                 :            :   {
   10619         [ #  # ]:          0 :     pt2.set(radius, 0, 0);
   10620         [ #  # ]:          0 :     pt3.set(0, 0, -radius);
   10621                 :            :   }
   10622 [ #  # ][ #  # ]:          0 :   else if (plane.z() > 0)
   10623                 :            :   {
   10624         [ #  # ]:          0 :     pt2.set(radius, 0, 0);
   10625         [ #  # ]:          0 :     pt3.set(0, radius, 0);
   10626                 :            :   }
   10627                 :            :   else
   10628                 :            :   {
   10629 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("In OCCModifyEngine::create_circle_surface\n"
                 [ #  # ]
   10630         [ #  # ]:          0 :                 "       Invalid plane specified.\n");
   10631                 :          0 :     return CUBIT_FAILURE;
   10632                 :            :   }
   10633                 :            : 
   10634         [ #  # ]:          0 :   TBPoint *tbpt2 = make_Point( pt2 );
   10635         [ #  # ]:          0 :   TBPoint *tbpt3 = make_Point( pt3 );
   10636                 :            : 
   10637 [ #  # ][ #  # ]:          0 :   CubitStatus stat = create_circle_surface(tbpt2, tbpt3, center_pt, sheet_body); 
   10638                 :          0 :   return stat;
   10639                 :            : 
   10640                 :            : }
   10641                 :            : 
   10642                 :          0 : CubitStatus OCCModifyEngine::tolerant_imprint( DLIList<BodySM*> &bodies_in,
   10643                 :            :                                         DLIList<BodySM*> &new_bodies,
   10644                 :            :                                         double overlap_tol,
   10645                 :            :                                         double imprint_tol,
   10646                 :            :                                                                                 DLIList<TopologyBridge*> *new_tbs,
   10647                 :            :                                                                                 DLIList<TopologyBridge*> *att_tbs) const
   10648                 :            : {
   10649                 :          0 :         return CUBIT_FAILURE;
   10650 [ +  - ][ +  - ]:       6364 : }
   10651                 :            : 
   10652                 :            : #ifdef CGM_KCM  
   10653                 :            : CubitStatus OCCModifyEngine::mesh2brep(std::vector<double> &xvals,
   10654                 :            :                         std::vector<double> &yvals,
   10655                 :            :                         std::vector<double> &zvals,
   10656                 :            :                         std::vector<unsigned int> &tri_connectivity,
   10657                 :            :                         DLIList<BodySM*> &new_body_sms) const
   10658                 :            : {
   10659                 :            :         return CUBIT_FAILURE;
   10660                 :            : }
   10661                 :            : #endif
   10662                 :            : 
   10663                 :            : // EOF

Generated by: LCOV version 1.11