LCOV - code coverage report
Current view: top level - geom/virtual - CompositeEngine.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 352 3428 10.3 %
Date: 2020-06-30 00:58:45 Functions: 16 97 16.5 %
Branches: 650 9227 7.0 %

           Branch data     Line data    Source code
       1                 :            : #include <assert.h>
       2                 :            : 
       3                 :            : #include "CompositeEngine.hpp"
       4                 :            : #include "PartitionEngine.hpp"
       5                 :            : 
       6                 :            : #include "DLIList.hpp"
       7                 :            : #include "TDUniqueId.hpp"
       8                 :            : #include "CubitTransformMatrix.hpp"
       9                 :            : #include "RTree.hpp"
      10                 :            : 
      11                 :            : #include "CompositePoint.hpp"
      12                 :            : #include "CompositeCurve.hpp"
      13                 :            : #include "CompositeCoEdge.hpp"
      14                 :            : #include "CompositeLoop.hpp"
      15                 :            : #include "CompositeSurface.hpp"
      16                 :            : #include "CompositeShell.hpp"
      17                 :            : #include "CompositeLump.hpp"
      18                 :            : #include "CompositeBody.hpp"
      19                 :            : #include "GfxPreview.hpp"
      20                 :            : 
      21                 :            : #include "PartitionPoint.hpp"
      22                 :            : #include "SegmentedCurve.hpp"
      23                 :            : 
      24                 :            : #include "CADefines.hpp"
      25                 :            : 
      26                 :            : #include "VGLoopTool.hpp"
      27                 :            : #include "Body.hpp"
      28                 :            : #include "LumpSM.hpp"
      29                 :            : 
      30                 :            : #include "GeometryQueryTool.hpp"
      31                 :            : #include "AppUtil.hpp"
      32                 :            : #include "GeometryEvent.hpp"
      33                 :            : 
      34                 :            : typedef VGLoopTool<CompositeSurface,
      35                 :            :                    CompositeLoop,
      36                 :            :                    CompositeCoEdge,
      37                 :            :                    CompositeCurve,
      38                 :            :                    CompositePoint> CompLoopTool;
      39                 :            : 
      40                 :            : CompositeEngine* CompositeEngine::instance_ = NULL; 
      41                 :            : 
      42                 :            : 
      43                 :          0 : CompositeEngine::~CompositeEngine()
      44                 :            : {
      45 [ #  # ][ #  # ]:          0 :   GeometryQueryTool::instance()->unregister_intermediate_engine(this);
      46         [ #  # ]:          0 : }
      47                 :            : 
      48                 :          0 : void CompositeEngine::delete_instance()
      49                 :            : {
      50         [ #  # ]:          0 :   if( NULL != instance_ )
      51                 :            :   {
      52         [ #  # ]:          0 :     delete instance_;
      53                 :          0 :     instance_ = NULL;
      54                 :            :   }
      55                 :          0 : }
      56                 :            : 
      57                 :        841 : CompositeEngine& CompositeEngine::instance()
      58                 :            : {
      59         [ +  - ]:        841 :   if( instance_ == NULL )
      60                 :            :   {
      61         [ +  - ]:        841 :     instance_ = new CompositeEngine();
      62         [ -  + ]:        841 :     assert( instance_ != NULL );
      63                 :            :   }
      64                 :            :   
      65                 :        841 :   return *instance_;
      66                 :            : }
      67                 :            : 
      68                 :            : // This function goes through all of the curves and vertices and
      69                 :            : // removes any named attributes specified below.
      70                 :          0 : void CompositeEngine::remove_imprint_attributes_after_modify( DLIList<BodySM*> &old_sms,
      71                 :            :                                 DLIList<BodySM*> &new_sms )
      72                 :            : {
      73                 :            :   int k, m, q, w, g, b, s, t;
      74         [ #  # ]:          0 :   CubitString name("IMPRINT_PREEXISTING");
      75 [ #  # ][ #  # ]:          0 :   std::vector<CubitString> string_list;
      76         [ #  # ]:          0 :   string_list.push_back( name );
      77 [ #  # ][ #  # ]:          0 :   CubitSimpleAttrib geom_attrib( &string_list, 0, 0 );
      78                 :            : 
      79 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> all_sms = old_sms;
      80         [ #  # ]:          0 :   all_sms += new_sms;
      81 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> top_bridges;
      82 [ #  # ][ #  # ]:          0 :   CAST_LIST_TO_PARENT(all_sms, top_bridges);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      83 [ #  # ][ #  # ]:          0 :   for(k=top_bridges.size(); k--;)
      84                 :            :   {
      85         [ #  # ]:          0 :     TopologyBridge *cur_body = top_bridges.get_and_step();
      86         [ #  # ]:          0 :     DLIList<TopologyBridge*> lumps;
      87         [ #  # ]:          0 :     cur_body->get_children_virt(lumps);
      88 [ #  # ][ #  # ]:          0 :     for(m=lumps.size(); m--;)
      89                 :            :     {
      90         [ #  # ]:          0 :       TopologyBridge *cur_lump = lumps.get_and_step();
      91         [ #  # ]:          0 :       DLIList<TopologyBridge*> shells;
      92         [ #  # ]:          0 :       cur_lump->get_children_virt(shells);
      93 [ #  # ][ #  # ]:          0 :       for(q=shells.size(); q--;)
      94                 :            :       {
      95         [ #  # ]:          0 :         TopologyBridge *cur_shell = shells.get_and_step();
      96         [ #  # ]:          0 :         DLIList<TopologyBridge*> surfaces;
      97         [ #  # ]:          0 :         cur_shell->get_children_virt(surfaces);
      98 [ #  # ][ #  # ]:          0 :         for(w=surfaces.size(); w--;)
      99                 :            :         {
     100         [ #  # ]:          0 :           TopologyBridge *cur_surface = surfaces.get_and_step();
     101         [ #  # ]:          0 :           DLIList<TopologyBridge*> loops;
     102         [ #  # ]:          0 :           cur_surface->get_children_virt(loops);
     103 [ #  # ][ #  # ]:          0 :           for(g=loops.size(); g--;)
     104                 :            :           {
     105         [ #  # ]:          0 :             TopologyBridge *cur_loop = loops.get_and_step();
     106         [ #  # ]:          0 :             DLIList<TopologyBridge*> coedges;
     107         [ #  # ]:          0 :             cur_loop->get_children_virt(coedges);
     108 [ #  # ][ #  # ]:          0 :             for(b=coedges.size(); b--;)
     109                 :            :             {
     110         [ #  # ]:          0 :               TopologyBridge *cur_coedge = coedges.get_and_step();
     111         [ #  # ]:          0 :               DLIList<TopologyBridge*> curves;
     112         [ #  # ]:          0 :               cur_coedge->get_children_virt(curves);
     113 [ #  # ][ #  # ]:          0 :               for(s=curves.size(); s--;)
     114                 :            :               {
     115         [ #  # ]:          0 :                 TopologyBridge *cur_curve = curves.get_and_step();
     116         [ #  # ]:          0 :                 DLIList<CubitSimpleAttrib> list;
     117 [ #  # ][ #  # ]:          0 :                 cur_curve->get_simple_attribute("IMPRINT_PREEXISTING",list);
                 [ #  # ]
     118 [ #  # ][ #  # ]:          0 :                 if(list.size() != 0)
     119 [ #  # ][ #  # ]:          0 :                   cur_curve->remove_simple_attribute_virt(list.get());
     120 [ #  # ][ #  # ]:          0 :                 DLIList<TopologyBridge*> pts;
     121         [ #  # ]:          0 :                 cur_curve->get_children_virt(pts);
     122 [ #  # ][ #  # ]:          0 :                 for(t=pts.size(); t--;)
     123                 :            :                 {
     124         [ #  # ]:          0 :                   TopologyBridge *cur_pt = pts.get_and_step();
     125         [ #  # ]:          0 :                   list.clean_out();
     126 [ #  # ][ #  # ]:          0 :                   cur_pt->get_simple_attribute("IMPRINT_PREEXISTING",list);
                 [ #  # ]
     127 [ #  # ][ #  # ]:          0 :                   if(list.size() != 0)
     128 [ #  # ][ #  # ]:          0 :                     cur_pt->remove_simple_attribute_virt(list.get());
     129                 :            :                 }
     130         [ #  # ]:          0 :               }
     131         [ #  # ]:          0 :             }
     132         [ #  # ]:          0 :           }
     133         [ #  # ]:          0 :         }
     134         [ #  # ]:          0 :       }
     135         [ #  # ]:          0 :     }
     136 [ #  # ][ #  # ]:          0 :   }
     137                 :          0 : }
     138                 :            : 
     139                 :          0 : void CompositeEngine::push_imprint_attributes_before_modify
     140                 :            :                      ( DLIList<BodySM*> &bodies)
     141                 :            : {
     142                 :          0 : }
     143                 :            : 
     144                 :          0 : void CompositeEngine::push_named_attributes_to_curves_and_points
     145                 :            : //                     ( DLIList<BodySM*> &bodies, char *name_in)
     146                 :            :                      ( DLIList<TopologyBridge*> &in_list, const char *name_in)
     147                 :            : {
     148                 :            :   int i/*, k, m, q, w, g, b, s, t*/;
     149         [ #  # ]:          0 :   CubitString name(name_in);
     150 [ #  # ][ #  # ]:          0 :   std::vector<CubitString> string_list;
     151         [ #  # ]:          0 :   string_list.push_back( name );
     152 [ #  # ][ #  # ]:          0 :   CubitSimpleAttrib attrib( &string_list, 0, 0 );
     153                 :            : 
     154 [ #  # ][ #  # ]:          0 :   for(i=in_list.size(); i>0; i--)
     155                 :            :   {
     156         [ #  # ]:          0 :     TopologyBridge *tb = in_list.get_and_step();
     157 [ #  # ][ #  # ]:          0 :     if(dynamic_cast<BodySM*>(tb))
                 [ #  # ]
     158                 :            :     {
     159         [ #  # ]:          0 :       DLIList<TopologyBridge*> lumps;
     160         [ #  # ]:          0 :       tb->get_children_virt(lumps);
     161 [ #  # ][ #  # ]:          0 :       push_named_attributes_to_curves_and_points(lumps, name_in);
     162                 :            :     }
     163 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<Lump*>(tb))
                 [ #  # ]
     164                 :            :     {
     165         [ #  # ]:          0 :       DLIList<TopologyBridge*> shells;
     166         [ #  # ]:          0 :       tb->get_children_virt(shells);
     167 [ #  # ][ #  # ]:          0 :       push_named_attributes_to_curves_and_points(shells, name_in);
     168                 :            :     }
     169 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<ShellSM*>(tb))
                 [ #  # ]
     170                 :            :     {
     171         [ #  # ]:          0 :       DLIList<TopologyBridge*> surfs;
     172         [ #  # ]:          0 :       tb->get_children_virt(surfs);
     173 [ #  # ][ #  # ]:          0 :       push_named_attributes_to_curves_and_points(surfs, name_in);
     174                 :            :     }
     175 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<Surface*>(tb))
                 [ #  # ]
     176                 :            :     {
     177         [ #  # ]:          0 :       DLIList<TopologyBridge*> loops;
     178         [ #  # ]:          0 :       tb->get_children_virt(loops);
     179 [ #  # ][ #  # ]:          0 :       push_named_attributes_to_curves_and_points(loops, name_in);
     180                 :            :     }
     181 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<LoopSM*>(tb))
                 [ #  # ]
     182                 :            :     {
     183         [ #  # ]:          0 :       DLIList<TopologyBridge*> coedges;
     184         [ #  # ]:          0 :       tb->get_children_virt(coedges);
     185 [ #  # ][ #  # ]:          0 :       push_named_attributes_to_curves_and_points(coedges, name_in);
     186                 :            :     }
     187 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<CoEdgeSM*>(tb))
                 [ #  # ]
     188                 :            :     {
     189         [ #  # ]:          0 :       DLIList<TopologyBridge*> curves;
     190         [ #  # ]:          0 :       tb->get_children_virt(curves);
     191 [ #  # ][ #  # ]:          0 :       push_named_attributes_to_curves_and_points(curves, name_in);
     192                 :            :     }
     193 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<Curve*>(tb))
                 [ #  # ]
     194                 :            :     {
     195         [ #  # ]:          0 :       append_attrib( tb, attrib );
     196         [ #  # ]:          0 :       DLIList<TopologyBridge*> points;
     197         [ #  # ]:          0 :       tb->get_children_virt(points);
     198 [ #  # ][ #  # ]:          0 :       push_named_attributes_to_curves_and_points(points, name_in);
     199                 :            :     }
     200 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<TBPoint*>(tb))
                 [ #  # ]
     201                 :            :     {
     202         [ #  # ]:          0 :       append_attrib( tb, attrib );
     203                 :            :     }
     204         [ #  # ]:          0 :   }
     205                 :            : 
     206                 :            : /*
     207                 :            : 
     208                 :            : 
     209                 :            :   DLIList<TopologyBridge*> top_bridges;
     210                 :            :   CAST_LIST_TO_PARENT(bodies, top_bridges);
     211                 :            :   for(k=top_bridges.size(); k--;)
     212                 :            :   {
     213                 :            :     TopologyBridge *cur_body = top_bridges.get_and_step();
     214                 :            :     DLIList<TopologyBridge*> lumps;
     215                 :            :     cur_body->get_children_virt(lumps);
     216                 :            :     for(m=lumps.size(); m--;)
     217                 :            :     {
     218                 :            :       TopologyBridge *cur_lump = lumps.get_and_step();
     219                 :            :       DLIList<TopologyBridge*> shells;
     220                 :            :       cur_lump->get_children_virt(shells);
     221                 :            :       for(q=shells.size(); q--;)
     222                 :            :       {
     223                 :            :         TopologyBridge *cur_shell = shells.get_and_step();
     224                 :            :         DLIList<TopologyBridge*> surfaces;
     225                 :            :         cur_shell->get_children_virt(surfaces);
     226                 :            :         for(w=surfaces.size(); w--;)
     227                 :            :         {
     228                 :            :           TopologyBridge *cur_surface = surfaces.get_and_step();
     229                 :            :           DLIList<TopologyBridge*> loops;
     230                 :            :           cur_surface->get_children_virt(loops);
     231                 :            :           for(g=loops.size(); g--;)
     232                 :            :           {
     233                 :            :             TopologyBridge *cur_loop = loops.get_and_step();
     234                 :            :             DLIList<TopologyBridge*> coedges;
     235                 :            :             cur_loop->get_children_virt(coedges);
     236                 :            :             for(b=coedges.size(); b--;)
     237                 :            :             {
     238                 :            :               TopologyBridge *cur_coedge = coedges.get_and_step();
     239                 :            :               DLIList<TopologyBridge*> curves;
     240                 :            :               cur_coedge->get_children_virt(curves);
     241                 :            :               for(s=curves.size(); s--;)
     242                 :            :               {
     243                 :            :                 TopologyBridge *cur_curve = curves.get_and_step();
     244                 :            :                 append_attrib( cur_curve, &attrib );
     245                 :            :                 DLIList<TopologyBridge*> pts;
     246                 :            :                 cur_curve->get_children_virt(pts);
     247                 :            :                 for(t=pts.size(); t--;)
     248                 :            :                 {
     249                 :            :                   TopologyBridge *cur_pt = pts.get_and_step();
     250                 :            :                   append_attrib( cur_pt, &attrib );
     251                 :            :                 }
     252                 :            :               }
     253                 :            :             }
     254                 :            :           }
     255                 :            :         }
     256                 :            :       }
     257                 :            :     }
     258                 :            :   }
     259                 :            :   */
     260                 :          0 : }
     261                 :            : 
     262                 :          0 : void CompositeEngine::get_all_curves_and_points(DLIList<TopologyBridge*> &tb_list,
     263                 :            :                                                 DLIList<Curve*> &curves,
     264                 :            :                                                 DLIList<TBPoint*> &points)
     265                 :            : {
     266                 :            :   int i;
     267                 :            :   Curve *crv;
     268                 :            :   TBPoint *pt;
     269 [ #  # ][ #  # ]:          0 :   for(i=tb_list.size(); i>0; i--)
     270                 :            :   {
     271         [ #  # ]:          0 :     TopologyBridge *tb = tb_list.get_and_step();
     272 [ #  # ][ #  # ]:          0 :     if(dynamic_cast<BodySM*>(tb))
                 [ #  # ]
     273                 :            :     {
     274         [ #  # ]:          0 :       DLIList<TopologyBridge*> lumps;
     275         [ #  # ]:          0 :       tb->get_children_virt(lumps);
     276 [ #  # ][ #  # ]:          0 :       get_all_curves_and_points(lumps, curves, points);
     277                 :            :     }
     278 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<Lump*>(tb))
                 [ #  # ]
     279                 :            :     {
     280         [ #  # ]:          0 :       DLIList<TopologyBridge*> shells;
     281         [ #  # ]:          0 :       tb->get_children_virt(shells);
     282 [ #  # ][ #  # ]:          0 :       get_all_curves_and_points(shells, curves, points);
     283                 :            :     }
     284 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<ShellSM*>(tb))
                 [ #  # ]
     285                 :            :     {
     286         [ #  # ]:          0 :       DLIList<TopologyBridge*> surfs;
     287         [ #  # ]:          0 :       tb->get_children_virt(surfs);
     288 [ #  # ][ #  # ]:          0 :       get_all_curves_and_points(surfs, curves, points);
     289                 :            :     }
     290 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<Surface*>(tb))
                 [ #  # ]
     291                 :            :     {
     292         [ #  # ]:          0 :       DLIList<TopologyBridge*> loops;
     293         [ #  # ]:          0 :       tb->get_children_virt(loops);
     294 [ #  # ][ #  # ]:          0 :       get_all_curves_and_points(loops, curves, points);
     295                 :            :     }
     296 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<LoopSM*>(tb))
                 [ #  # ]
     297                 :            :     {
     298         [ #  # ]:          0 :       DLIList<TopologyBridge*> coedges;
     299         [ #  # ]:          0 :       tb->get_children_virt(coedges);
     300 [ #  # ][ #  # ]:          0 :       get_all_curves_and_points(coedges, curves, points);
     301                 :            :     }
     302 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<CoEdgeSM*>(tb))
                 [ #  # ]
     303                 :            :     {
     304         [ #  # ]:          0 :       DLIList<TopologyBridge*> tmp_curves;
     305         [ #  # ]:          0 :       tb->get_children_virt(tmp_curves);
     306 [ #  # ][ #  # ]:          0 :       get_all_curves_and_points(tmp_curves, curves, points);
     307                 :            :     }
     308 [ #  # ][ #  # ]:          0 :     else if((crv = dynamic_cast<Curve*>(tb)))
     309                 :            :     {
     310         [ #  # ]:          0 :       curves.append(crv);
     311         [ #  # ]:          0 :       DLIList<TopologyBridge*> tmp_points;
     312         [ #  # ]:          0 :       tb->get_children_virt(tmp_points);
     313 [ #  # ][ #  # ]:          0 :       get_all_curves_and_points(tmp_points, curves, points);
     314                 :            :     }
     315 [ #  # ][ #  # ]:          0 :     else if((pt = dynamic_cast<TBPoint*>(tb)))
     316                 :            :     {
     317         [ #  # ]:          0 :       points.append(pt);
     318                 :            :     }
     319                 :            :   }
     320                 :          0 : }
     321                 :            : 
     322                 :            : // Function to apply/remove COMPOSITE_GEOM attributes as necessary based
     323                 :            : // on imprinting.
     324                 :          0 : void CompositeEngine::attribute_after_imprinting(DLIList<TopologyBridge*> &tb_list,
     325                 :            :                                                  DLIList<Body*> &old_bodies)
     326                 :            : {
     327         [ #  # ]:          0 :   DLIList<TopologyBridge*> all_bridges = tb_list;
     328                 :            :   int i, j, k;
     329 [ #  # ][ #  # ]:          0 :   for(k = old_bodies.size(); k>0; k--)
     330                 :            :   {
     331         [ #  # ]:          0 :     Body *body = old_bodies.get_and_step();
     332 [ #  # ][ #  # ]:          0 :     TopologyBridge *tb = body->bridge_manager()->topology_bridge();
     333         [ #  # ]:          0 :     if(tb)
     334         [ #  # ]:          0 :       all_bridges.append_unique(tb);
     335                 :            :   }
     336                 :            : 
     337 [ #  # ][ #  # ]:          0 :   DLIList<Curve*> all_curves;
     338 [ #  # ][ #  # ]:          0 :   DLIList<TBPoint*> all_points;
     339         [ #  # ]:          0 :   get_all_curves_and_points(all_bridges, all_curves, all_points);
     340         [ #  # ]:          0 :   all_curves.uniquify_ordered();
     341         [ #  # ]:          0 :   all_points.uniquify_ordered();
     342                 :            : 
     343         [ #  # ]:          0 :   double geom_factor = GeometryQueryTool::get_geometry_factor();
     344                 :          0 :   double merge_tol = geom_factor*GEOMETRY_RESABS;
     345                 :            : 
     346 [ #  # ][ #  # ]:          0 :   AbstractTree<TBPoint*> *pt_tree = new RTree<TBPoint*>(merge_tol);
     347 [ #  # ][ #  # ]:          0 :   AbstractTree<Curve*> *crv_tree = new RTree<Curve*>(merge_tol);
     348                 :            : 
     349 [ #  # ][ #  # ]:          0 :   DLIList<Curve*> all_curves_with_composite_att;
     350 [ #  # ][ #  # ]:          0 :   DLIList<TBPoint*> all_points_with_composite_att;
     351 [ #  # ][ #  # ]:          0 :   for(k=all_curves.size(); k>0; k--)
     352                 :            :   {
     353         [ #  # ]:          0 :     Curve *cur_curve = all_curves.get_and_step();
     354         [ #  # ]:          0 :     crv_tree->add(cur_curve);
     355         [ #  # ]:          0 :     DLIList<CubitSimpleAttrib> list;
     356 [ #  # ][ #  # ]:          0 :     cur_curve->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     357 [ #  # ][ #  # ]:          0 :     if(list.size() > 0)
     358         [ #  # ]:          0 :       all_curves_with_composite_att.append(cur_curve);
     359         [ #  # ]:          0 :   }
     360 [ #  # ][ #  # ]:          0 :   for(k=all_points.size(); k>0; k--)
     361                 :            :   {
     362         [ #  # ]:          0 :     TBPoint *cur_point = all_points.get_and_step();
     363         [ #  # ]:          0 :     pt_tree->add(cur_point);
     364         [ #  # ]:          0 :     DLIList<CubitSimpleAttrib> list;
     365 [ #  # ][ #  # ]:          0 :     cur_point->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     366 [ #  # ][ #  # ]:          0 :     if(list.size() > 0)
     367         [ #  # ]:          0 :       all_points_with_composite_att.append(cur_point);
     368         [ #  # ]:          0 :   }
     369                 :            : 
     370 [ #  # ][ #  # ]:          0 :   DLIList<CubitSimpleAttrib> list;
     371 [ #  # ][ #  # ]:          0 :   while(all_points_with_composite_att.size())
     372                 :            :   {
     373         [ #  # ]:          0 :     DLIList<TBPoint*> other_pts;
     374 [ #  # ][ #  # ]:          0 :     DLIList<BodySM*> other_bodies;
     375 [ #  # ][ #  # ]:          0 :     DLIList<double> other_distances;
     376                 :            : 
     377                 :            :     // For the given pt we will look for "coincident" pts (those within merge tol)
     378                 :            :     // and categorize them as either having or not having a composite att.
     379         [ #  # ]:          0 :     TBPoint *cur_pt = all_points_with_composite_att.extract();
     380         [ #  # ]:          0 :     pt_tree->remove(cur_pt);
     381                 :            : 
     382         [ #  # ]:          0 :     BodySM *cur_body = cur_pt->bodysm();
     383 [ #  # ][ #  # ]:          0 :     DLIList<TBPoint*> coincident_pts_with_composite_att, coincident_pts_without_composite_att;
         [ #  # ][ #  # ]
     384 [ #  # ][ #  # ]:          0 :     DLIList<TBPoint*> close_pts;
     385 [ #  # ][ #  # ]:          0 :     CubitBox bbox = cur_pt->bounding_box();
     386         [ #  # ]:          0 :     pt_tree->find(bbox, close_pts);
     387                 :            : 
     388                 :            :     // Only keep the closest pt from each body.
     389 [ #  # ][ #  # ]:          0 :     for(j=close_pts.size(); j>0; j--)
     390                 :            :     {
     391         [ #  # ]:          0 :       TBPoint *other_pt = close_pts.get_and_step();
     392         [ #  # ]:          0 :       BodySM *other_body = other_pt->bodysm();
     393                 :            :       // Don't keep anything that is in the same body as the current pt.
     394         [ #  # ]:          0 :       if(other_body != cur_body)
     395                 :            :       {
     396 [ #  # ][ #  # ]:          0 :         double cur_dist_sq = cur_pt->coordinates().distance_between_squared(other_pt->coordinates());
                 [ #  # ]
     397 [ #  # ][ #  # ]:          0 :         if(other_bodies.move_to(other_body))
     398                 :            :         {
     399         [ #  # ]:          0 :           int list_index = other_bodies.get_index();
     400         [ #  # ]:          0 :           other_distances.reset();
     401         [ #  # ]:          0 :           other_distances.step(list_index);
     402         [ #  # ]:          0 :           double prev_dist_sq = other_distances.get();
     403         [ #  # ]:          0 :           if(cur_dist_sq < prev_dist_sq)
     404                 :            :           {
     405         [ #  # ]:          0 :             other_distances.change_to(cur_dist_sq);
     406         [ #  # ]:          0 :             other_pts.reset();
     407         [ #  # ]:          0 :             other_pts.step(list_index);
     408         [ #  # ]:          0 :             other_pts.change_to(other_pt);
     409                 :            :           }
     410                 :            :         }
     411                 :            :         else
     412                 :            :         {
     413         [ #  # ]:          0 :           other_bodies.append(other_body);
     414         [ #  # ]:          0 :           other_pts.append(other_pt);
     415         [ #  # ]:          0 :           other_distances.append(cur_dist_sq);
     416                 :            :         }
     417                 :            :       }
     418                 :            :     }
     419                 :            :     // Make sure our current pt is added to a list.
     420         [ #  # ]:          0 :     coincident_pts_with_composite_att.append(cur_pt);
     421                 :            :     // Classify the coincident pts as either having or not
     422                 :            :     // having a composite att.
     423 [ #  # ][ #  # ]:          0 :     for(j=other_pts.size(); j>0; j--)
     424                 :            :     {
     425         [ #  # ]:          0 :       TBPoint *pt = other_pts.get_and_step();
     426         [ #  # ]:          0 :       list.clean_out();
     427 [ #  # ][ #  # ]:          0 :       pt->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     428 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     429                 :            :       {
     430         [ #  # ]:          0 :         coincident_pts_with_composite_att.append(pt);
     431 [ #  # ][ #  # ]:          0 :         if(all_points_with_composite_att.move_to(pt))
     432         [ #  # ]:          0 :           all_points_with_composite_att.extract();
     433                 :            :       }
     434                 :            :       else
     435         [ #  # ]:          0 :         coincident_pts_without_composite_att.append(pt);
     436                 :            :     }
     437                 :            : 
     438                 :            :     // If we have found at least one other pt coincident with the current point...
     439 [ #  # ][ #  # ]:          0 :     if(coincident_pts_with_composite_att.size() > 1 ||
         [ #  # ][ #  # ]
     440         [ #  # ]:          0 :       coincident_pts_without_composite_att.size() > 0)
     441                 :            :     {
     442                 :            :       // If there is at least one pt without a composite att that is an imprinter we
     443                 :            :       // will remove all composite atts from coincident pts
     444                 :          0 :       bool found = false;
     445 [ #  # ][ #  # ]:          0 :       for(j=coincident_pts_without_composite_att.size(); j>0 && !found; j--)
                 [ #  # ]
     446                 :            :       {
     447         [ #  # ]:          0 :         TBPoint *tmp_pt = coincident_pts_without_composite_att.get_and_step();
     448         [ #  # ]:          0 :         list.clean_out();
     449 [ #  # ][ #  # ]:          0 :         tmp_pt->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     450 [ #  # ][ #  # ]:          0 :         if(list.size() > 0)
     451                 :          0 :           found = true;
     452                 :            :       }
     453         [ #  # ]:          0 :       if(found)
     454                 :            :       {
     455                 :            :         // Remove all composite atts.
     456 [ #  # ][ #  # ]:          0 :         for(j=coincident_pts_with_composite_att.size(); j>0; j--)
     457                 :            :         {
     458         [ #  # ]:          0 :           TBPoint *tmp_pt = coincident_pts_with_composite_att.get_and_step();
     459         [ #  # ]:          0 :           list.clean_out();
     460 [ #  # ][ #  # ]:          0 :           tmp_pt->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     461 [ #  # ][ #  # ]:          0 :           if(list.size() > 0)
     462 [ #  # ][ #  # ]:          0 :             tmp_pt->remove_simple_attribute_virt(list.get());
     463                 :            :         }
     464                 :            :       }
     465                 :            :       else
     466                 :            :       {
     467                 :            :         // There were no imprinter points that didn't have composite atts.  
     468                 :            :         // Next we will look for imprinter points with composite atts.  These
     469                 :            :         // may have resulted in a new point.  If there is a non composite att
     470                 :            :         // point that doesn't have an ORIGINAL att we will know it is new
     471                 :            :         // from the imprinter composite att point and we know to put a composite
     472                 :            :         // att on it.
     473                 :          0 :         found = false;
     474 [ #  # ][ #  # ]:          0 :         for(j=coincident_pts_with_composite_att.size(); j>0 && !found; j--)
                 [ #  # ]
     475                 :            :         {
     476         [ #  # ]:          0 :           TBPoint *tmp_pt = coincident_pts_with_composite_att.get_and_step();
     477         [ #  # ]:          0 :           list.clean_out();
     478 [ #  # ][ #  # ]:          0 :           tmp_pt->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     479 [ #  # ][ #  # ]:          0 :           if(list.size() > 0)
     480                 :          0 :             found = true;
     481                 :            :         }
     482         [ #  # ]:          0 :         if(found)
     483                 :            :         {
     484                 :            :           // Now put a composite att on any point that doesn't have one.
     485 [ #  # ][ #  # ]:          0 :           for(j=coincident_pts_without_composite_att.size(); j>0; j--)
     486                 :            :           {
     487         [ #  # ]:          0 :             TBPoint *tmp_pt = coincident_pts_without_composite_att.get_and_step();
     488         [ #  # ]:          0 :             list.clean_out();
     489 [ #  # ][ #  # ]:          0 :             tmp_pt->get_simple_attribute("ORIGINAL", list);
                 [ #  # ]
     490 [ #  # ][ #  # ]:          0 :             if(list.size() == 0)
     491                 :            :             {
     492                 :            :               // The point was not in the original model and therefore was created by 
     493                 :            :               // the imprint of a pt with a composite att.  We need to put a composite
     494                 :            :               // att on it.
     495         [ #  # ]:          0 :               list.clean_out();
     496 [ #  # ][ #  # ]:          0 :               coincident_pts_with_composite_att.get()->get_simple_attribute("COMPOSITE_GEOM",list);
         [ #  # ][ #  # ]
     497 [ #  # ][ #  # ]:          0 :               tmp_pt->append_simple_attribute_virt(list.get());
     498                 :            :             }
     499                 :            :           }
     500                 :            :         }
     501                 :            :       }
     502                 :            :     }
     503                 :            : 
     504 [ #  # ][ #  # ]:          0 :     for(i=coincident_pts_with_composite_att.size(); i>0; i--)
     505                 :            :     {
     506         [ #  # ]:          0 :       TBPoint *pt = coincident_pts_with_composite_att.get_and_step();
     507         [ #  # ]:          0 :       list.clean_out();
     508 [ #  # ][ #  # ]:          0 :       pt->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     509 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     510 [ #  # ][ #  # ]:          0 :         pt->remove_simple_attribute_virt(list.get());
     511         [ #  # ]:          0 :       list.clean_out();
     512 [ #  # ][ #  # ]:          0 :       pt->get_simple_attribute("ORIGINAL",list);
                 [ #  # ]
     513 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     514 [ #  # ][ #  # ]:          0 :         pt->remove_simple_attribute_virt(list.get());
     515                 :            :     }
     516 [ #  # ][ #  # ]:          0 :     for(i=coincident_pts_without_composite_att.size(); i>0; i--)
     517                 :            :     {
     518         [ #  # ]:          0 :       TBPoint *pt = coincident_pts_without_composite_att.get_and_step();
     519         [ #  # ]:          0 :       list.clean_out();
     520 [ #  # ][ #  # ]:          0 :       pt->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     521 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     522 [ #  # ][ #  # ]:          0 :         pt->remove_simple_attribute_virt(list.get());
     523         [ #  # ]:          0 :       list.clean_out();
     524 [ #  # ][ #  # ]:          0 :       pt->get_simple_attribute("ORIGINAL",list);
                 [ #  # ]
     525 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     526 [ #  # ][ #  # ]:          0 :         pt->remove_simple_attribute_virt(list.get());
     527                 :            :     }
     528         [ #  # ]:          0 :   }
     529 [ #  # ][ #  # ]:          0 :   delete pt_tree;
     530                 :            : 
     531                 :            :   CubitSense rel_sense;
     532 [ #  # ][ #  # ]:          0 :   while(all_curves_with_composite_att.size())
     533                 :            :   {
     534         [ #  # ]:          0 :     DLIList<Curve*> other_crvs;
     535 [ #  # ][ #  # ]:          0 :     DLIList<BodySM*> other_bodies;
     536 [ #  # ][ #  # ]:          0 :     DLIList<double> other_distances;
     537                 :            : 
     538         [ #  # ]:          0 :     Curve *cur_crv = all_curves_with_composite_att.extract();
     539         [ #  # ]:          0 :     crv_tree->remove(cur_crv);
     540                 :            : 
     541         [ #  # ]:          0 :     BodySM *cur_body = cur_crv->bodysm();
     542 [ #  # ][ #  # ]:          0 :     DLIList<Curve*> coincident_crvs_with_composite_att, coincident_crvs_without_composite_att;
         [ #  # ][ #  # ]
     543 [ #  # ][ #  # ]:          0 :     DLIList<Curve*> close_crvs;
     544 [ #  # ][ #  # ]:          0 :     CubitBox bbox = cur_crv->bounding_box();
     545         [ #  # ]:          0 :     crv_tree->find(bbox, close_crvs);
     546                 :            : 
     547 [ #  # ][ #  # ]:          0 :     for(j=close_crvs.size(); j>0; j--)
     548                 :            :     {
     549         [ #  # ]:          0 :       Curve *other_crv = close_crvs.get_and_step();
     550         [ #  # ]:          0 :       BodySM *other_body = other_crv->bodysm();
     551                 :            :       // Only consider curves from other bodies.
     552         [ #  # ]:          0 :       if(cur_body != other_body)
     553                 :            :       {
     554 [ #  # ][ #  # ]:          0 :         if(this->about_spatially_equal(cur_crv, other_crv, rel_sense, geom_factor, 0))
     555                 :            :         {
     556 [ #  # ][ #  # ]:          0 :           CubitVector pos1, pos2;
     557                 :            :           double cur_dist;
     558         [ #  # ]:          0 :           cur_crv->get_geometry_query_engine()->entity_entity_distance(
     559         [ #  # ]:          0 :             cur_crv, other_crv, pos1, pos2, cur_dist );
     560 [ #  # ][ #  # ]:          0 :           if(other_bodies.move_to(other_body))
     561                 :            :           {
     562         [ #  # ]:          0 :             int list_index = other_bodies.get_index();
     563         [ #  # ]:          0 :             other_distances.reset();
     564         [ #  # ]:          0 :             other_distances.step(list_index);
     565         [ #  # ]:          0 :             double prev_dist = other_distances.get();
     566         [ #  # ]:          0 :             if(cur_dist < prev_dist)
     567                 :            :             {
     568         [ #  # ]:          0 :               other_distances.change_to(cur_dist);
     569         [ #  # ]:          0 :               other_crvs.reset();
     570         [ #  # ]:          0 :               other_crvs.step(list_index);
     571         [ #  # ]:          0 :               other_crvs.change_to(other_crv);
     572                 :            :             }
     573                 :            :           }
     574                 :            :           else
     575                 :            :           {
     576         [ #  # ]:          0 :             other_bodies.append(other_body);
     577         [ #  # ]:          0 :             other_crvs.append(other_crv);
     578         [ #  # ]:          0 :             other_distances.append(cur_dist);
     579                 :            :           }
     580                 :            :         }
     581                 :            :       }
     582         [ #  # ]:          0 :       coincident_crvs_with_composite_att.append(cur_crv);
     583 [ #  # ][ #  # ]:          0 :       for(j=other_crvs.size(); j>0; j--)
     584                 :            :       {
     585         [ #  # ]:          0 :         Curve *crv = other_crvs.get_and_step();
     586         [ #  # ]:          0 :         list.clean_out();
     587 [ #  # ][ #  # ]:          0 :         crv->get_simple_attribute("COMPOSITE_GEOM", list);
                 [ #  # ]
     588 [ #  # ][ #  # ]:          0 :         if(list.size() > 0)
     589                 :            :         {
     590         [ #  # ]:          0 :           coincident_crvs_with_composite_att.append(other_crv);
     591 [ #  # ][ #  # ]:          0 :           if(all_curves_with_composite_att.move_to(other_crv))
     592         [ #  # ]:          0 :             all_curves_with_composite_att.extract();
     593                 :            :         }
     594                 :            :         else
     595         [ #  # ]:          0 :           coincident_crvs_without_composite_att.append(other_crv);
     596                 :            :       }
     597                 :            :     }
     598                 :            : 
     599                 :            :     // If we have found at least one other crv coincident with the current crv...
     600 [ #  # ][ #  # ]:          0 :     if(coincident_crvs_with_composite_att.size() > 1 ||
         [ #  # ][ #  # ]
     601         [ #  # ]:          0 :       coincident_crvs_without_composite_att.size() > 0)
     602                 :            :     {
     603                 :            :       // If there is at least one curve without a composite att that is an imprinter we
     604                 :            :       // will remove all composite atts from coincident curves
     605                 :          0 :       bool found = false;
     606 [ #  # ][ #  # ]:          0 :       for(j=coincident_crvs_without_composite_att.size(); j>0 && !found; j--)
                 [ #  # ]
     607                 :            :       {
     608         [ #  # ]:          0 :         Curve *tmp_crv = coincident_crvs_without_composite_att.get_and_step();
     609         [ #  # ]:          0 :         list.clean_out();
     610 [ #  # ][ #  # ]:          0 :         tmp_crv->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     611 [ #  # ][ #  # ]:          0 :         if(list.size() > 0)
     612                 :          0 :           found = true;
     613                 :            :       }
     614         [ #  # ]:          0 :       if(found)
     615                 :            :       {
     616                 :            :         // Remove all composite atts.
     617 [ #  # ][ #  # ]:          0 :         for(j=coincident_crvs_with_composite_att.size(); j>0; j--)
     618                 :            :         {
     619         [ #  # ]:          0 :           Curve *tmp_crv = coincident_crvs_with_composite_att.get_and_step();
     620         [ #  # ]:          0 :           list.clean_out();
     621 [ #  # ][ #  # ]:          0 :           tmp_crv->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     622 [ #  # ][ #  # ]:          0 :           if(list.size() > 0)
     623 [ #  # ][ #  # ]:          0 :             tmp_crv->remove_simple_attribute_virt(list.get());
     624                 :            :         }
     625                 :            :       }
     626                 :            :       else
     627                 :            :       {
     628                 :            :         // There were no imprinter crvs that didn't have composite atts.  
     629                 :            :         // Next we will look for imprinter crvs with composite atts.  These
     630                 :            :         // may have resulted in a new crv.  If there is a non composite att
     631                 :            :         // crv that doesn't have an ORIGINAL att we will know it is new
     632                 :            :         // from the imprinter composite att crv and we know to put a composite
     633                 :            :         // att on it.
     634                 :          0 :         found = false;
     635 [ #  # ][ #  # ]:          0 :         for(j=coincident_crvs_with_composite_att.size(); j>0 && !found; j--)
                 [ #  # ]
     636                 :            :         {
     637         [ #  # ]:          0 :           Curve *tmp_crv = coincident_crvs_with_composite_att.get_and_step();
     638         [ #  # ]:          0 :           list.clean_out();
     639 [ #  # ][ #  # ]:          0 :           tmp_crv->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     640 [ #  # ][ #  # ]:          0 :           if(list.size() > 0)
     641                 :          0 :             found = true;
     642                 :            :         }
     643         [ #  # ]:          0 :         if(found)
     644                 :            :         {
     645                 :            :           // Now put a composite att on any crv that doesn't have one.
     646 [ #  # ][ #  # ]:          0 :           for(j=coincident_crvs_without_composite_att.size(); j>0; j--)
     647                 :            :           {
     648         [ #  # ]:          0 :             Curve *tmp_crv = coincident_crvs_without_composite_att.get_and_step();
     649         [ #  # ]:          0 :             list.clean_out();
     650 [ #  # ][ #  # ]:          0 :             tmp_crv->get_simple_attribute("ORIGINAL", list);
                 [ #  # ]
     651 [ #  # ][ #  # ]:          0 :             if(list.size() == 0)
     652                 :            :             {
     653                 :            :               // The crv was not in the original model and therefore was created by 
     654                 :            :               // the imprint of a crv with a composite att.  We need to put a composite
     655                 :            :               // att on it.
     656         [ #  # ]:          0 :               list.clean_out();
     657 [ #  # ][ #  # ]:          0 :               coincident_crvs_with_composite_att.get()->get_simple_attribute("COMPOSITE_GEOM",list);
         [ #  # ][ #  # ]
     658 [ #  # ][ #  # ]:          0 :               tmp_crv->append_simple_attribute_virt(list.get());
     659                 :            :             }
     660                 :            :           }
     661                 :            :         }
     662                 :            :       }
     663                 :            :     }
     664                 :            : 
     665 [ #  # ][ #  # ]:          0 :     for(i=coincident_crvs_with_composite_att.size(); i>0; i--)
     666                 :            :     {
     667         [ #  # ]:          0 :       Curve *crv = coincident_crvs_with_composite_att.get_and_step();
     668         [ #  # ]:          0 :       list.clean_out();
     669 [ #  # ][ #  # ]:          0 :       crv->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     670 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     671 [ #  # ][ #  # ]:          0 :         crv->remove_simple_attribute_virt(list.get());
     672         [ #  # ]:          0 :       list.clean_out();
     673 [ #  # ][ #  # ]:          0 :       crv->get_simple_attribute("ORIGINAL",list);
                 [ #  # ]
     674 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     675 [ #  # ][ #  # ]:          0 :         crv->remove_simple_attribute_virt(list.get());
     676                 :            :     }
     677 [ #  # ][ #  # ]:          0 :     for(i=coincident_crvs_without_composite_att.size(); i>0; i--)
     678                 :            :     {
     679         [ #  # ]:          0 :       Curve *crv = coincident_crvs_without_composite_att.get_and_step();
     680         [ #  # ]:          0 :       list.clean_out();
     681 [ #  # ][ #  # ]:          0 :       crv->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     682 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     683 [ #  # ][ #  # ]:          0 :         crv->remove_simple_attribute_virt(list.get());
     684         [ #  # ]:          0 :       list.clean_out();
     685 [ #  # ][ #  # ]:          0 :       crv->get_simple_attribute("ORIGINAL",list);
                 [ #  # ]
     686 [ #  # ][ #  # ]:          0 :       if(list.size() > 0)
     687 [ #  # ][ #  # ]:          0 :         crv->remove_simple_attribute_virt(list.get());
     688                 :            :     }
     689         [ #  # ]:          0 :   }
     690 [ #  # ][ #  # ]:          0 :   delete crv_tree;
     691 [ #  # ][ #  # ]:          0 :   for(i=all_curves.size(); i>0; i--)
     692                 :            :   {
     693         [ #  # ]:          0 :     Curve *cur_curve = all_curves.get_and_step();
     694         [ #  # ]:          0 :     list.clean_out();
     695 [ #  # ][ #  # ]:          0 :     cur_curve->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     696 [ #  # ][ #  # ]:          0 :     if(list.size() > 0)
     697 [ #  # ][ #  # ]:          0 :       cur_curve->remove_simple_attribute_virt(list.get());
     698         [ #  # ]:          0 :     list.clean_out();
     699 [ #  # ][ #  # ]:          0 :     cur_curve->get_simple_attribute("ORIGINAL",list);
                 [ #  # ]
     700 [ #  # ][ #  # ]:          0 :     if(list.size() > 0)
     701 [ #  # ][ #  # ]:          0 :       cur_curve->remove_simple_attribute_virt(list.get());
     702                 :            :   }
     703 [ #  # ][ #  # ]:          0 :   for(i=all_points.size(); i>0; i--)
     704                 :            :   {
     705         [ #  # ]:          0 :     TBPoint *cur_point = all_points.get_and_step();
     706         [ #  # ]:          0 :     list.clean_out();
     707 [ #  # ][ #  # ]:          0 :     cur_point->get_simple_attribute("IMPRINTER",list);
                 [ #  # ]
     708 [ #  # ][ #  # ]:          0 :     if(list.size() > 0)
     709 [ #  # ][ #  # ]:          0 :       cur_point->remove_simple_attribute_virt(list.get());
     710         [ #  # ]:          0 :     list.clean_out();
     711 [ #  # ][ #  # ]:          0 :     cur_point->get_simple_attribute("ORIGINAL",list);
                 [ #  # ]
     712 [ #  # ][ #  # ]:          0 :     if(list.size() > 0)
     713 [ #  # ][ #  # ]:          0 :       cur_point->remove_simple_attribute_virt(list.get());
     714         [ #  # ]:          0 :   }
     715                 :          0 : }
     716                 :            : 
     717                 :          0 : void CompositeEngine::process_curves_after_imprint(Curve *att_cur, 
     718                 :            :                                                    Curve *other_cur,
     719                 :            :                                                    DLIList<BodySM*> &new_sms)
     720                 :            : {
     721         [ #  # ]:          0 :   DLIList<CubitSimpleAttrib> list;
     722                 :            : 
     723         [ #  # ]:          0 :   if(att_cur == other_cur)
     724                 :            :   {
     725                 :            :     // This case will happen when we have manually added one of the existing
     726                 :            :     // curves on the surface to be imprinted to the "new_ENTITIES" list.  We
     727                 :            :     // do this in cases where the curve to imprint on the surface exactly 
     728                 :            :     // falls on one of the existing curves.  In this case the  face
     729                 :            :     // doesn't get new curves created but we need to consider the 
     730                 :            :     // curve on the face as new because it may have been hidden in a 
     731                 :            :     // composite surface and needs to be reintroduced.  So, in this
     732                 :            :     // case we will remove the attribute so that the curve is no longer
     733                 :            :     // hidden.
     734 [ #  # ][ #  # ]:          0 :     att_cur->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     735 [ #  # ][ #  # ]:          0 :     att_cur->remove_simple_attribute_virt(list.get());
     736                 :            :   }
     737                 :            :   else
     738                 :            :   {
     739 [ #  # ][ #  # ]:          0 :     other_cur->get_simple_attribute("IMPRINT_PREEXISTING",list);
                 [ #  # ]
     740 [ #  # ][ #  # ]:          0 :     if(list.size() == 0)
     741                 :            :     {
     742                 :            :       // This is a new bridge created by imprinting this hidden bridge.  In 
     743                 :            :       // this case we need to add a COMPOSITE_GEOM attribute to the new bridge
     744                 :            :       // so we don't see a resulting imprinted bridge from the hidden bridge.
     745         [ #  # ]:          0 :       list.clean_out();
     746 [ #  # ][ #  # ]:          0 :       att_cur->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     747 [ #  # ][ #  # ]:          0 :       other_cur->append_simple_attribute_virt(list.get());
     748                 :            :     }
     749                 :            :     else
     750                 :            :     {
     751                 :            :       // This bridge existed before the imprint operation.  Therefore it
     752                 :            :       // could also have a COMPOSITE_GEOM attribute on it.  Check this.
     753         [ #  # ]:          0 :       list.clean_out();
     754 [ #  # ][ #  # ]:          0 :       other_cur->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     755 [ #  # ][ #  # ]:          0 :       if(list.size() == 0)
     756                 :            :       {
     757                 :            :         // It doesn't have a COMPOSITE_GEOM attribute so we need to remove
     758                 :            :         // the COMPOSITE_GEOM from att_bridge because the hidden nature gets
     759                 :            :         // wiped out by the imprinting process.
     760 [ #  # ][ #  # ]:          0 :         att_cur->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     761 [ #  # ][ #  # ]:          0 :         att_cur->remove_simple_attribute_virt(list.get());
     762         [ #  # ]:          0 :         TBOwner *bridge_owner = att_cur->owner();
     763         [ #  # ]:          0 :         CompositeCurve *cc_bridge_owner = dynamic_cast<CompositeCurve*>(bridge_owner);
     764         [ #  # ]:          0 :         if(cc_bridge_owner)
     765                 :            :         {
     766         [ #  # ]:          0 :           TBOwner *cc_owner = cc_bridge_owner->owner();
     767         [ #  # ]:          0 :           HiddenEntitySet *hes = dynamic_cast<HiddenEntitySet*>(cc_owner);
     768         [ #  # ]:          0 :           if(hes)
     769                 :            :           {
     770 [ #  # ][ #  # ]:          0 :             CompositeSurface *cs = dynamic_cast<CompositeSurface*>(hes->owner());
     771         [ #  # ]:          0 :             if(cs)
     772                 :          0 :               cs->HadBridgeRemoved = 1;
     773                 :            :               // This is currently how we are notifying the owning CompositeSurface
     774                 :            :               // that it needs to be deactivated and rebuilt.  It really has 
     775                 :            :               // nothing to do with the bridge being removed though.  Bad.
     776                 :            :           }
     777                 :            :         }
     778                 :            :       }
     779                 :            :       else
     780                 :            :       {
     781                 :            :         // This bridge was also hidden so do nothing.
     782                 :            :       }
     783                 :            :     }
     784         [ #  # ]:          0 :   }
     785                 :          0 : }
     786                 :            : 
     787                 :          0 : void CompositeEngine::process_points_after_imprint(TBPoint *att_pt, 
     788                 :            :                                                    TBPoint *other_pt,
     789                 :            :                                                    DLIList<BodySM*> &new_sms)
     790                 :            : {
     791                 :            :   int i;
     792         [ #  # ]:          0 :   DLIList<CubitSimpleAttrib> list;
     793                 :            : 
     794         [ #  # ]:          0 :   if(att_pt == other_pt)
     795                 :            :   {
     796                 :            :     // This case will happen when we have manually added one of the existing
     797                 :            :     // pts on the surface to be imprinted to the "new_ENTITIES" list.  We
     798                 :            :     // do this in cases where the pt to imprint on the surface exactly 
     799                 :            :     // falls on one of the existing pts.  In this case the  face
     800                 :            :     // doesn't get new pts created but we need to consider the 
     801                 :            :     // pt on the face as new because it may have been hidden in a 
     802                 :            :     // composite curve and needs to be reintroduced.  So, in this
     803                 :            :     // case we will remove the attribute so that the pt is no longer
     804                 :            :     // hidden.
     805 [ #  # ][ #  # ]:          0 :     att_pt->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     806 [ #  # ][ #  # ]:          0 :     att_pt->remove_simple_attribute_virt(list.get());
     807                 :            :   }
     808                 :            :   else
     809                 :            :   {
     810 [ #  # ][ #  # ]:          0 :     other_pt->get_simple_attribute("IMPRINT_PREEXISTING",list);
                 [ #  # ]
     811 [ #  # ][ #  # ]:          0 :     if(list.size() == 0)
     812                 :            :     {
     813                 :            :       // This is a new bridge created by imprinting this hidden bridge.  In 
     814                 :            :       // this case we need to add a COMPOSITE_GEOM attribute to the new bridge
     815                 :            :       // if possible so we don't see a resulting imprinted bridge from the hidden bridge.
     816                 :          0 :       int num_visible_curves = 0;
     817         [ #  # ]:          0 :       DLIList<TopologyBridge*> curves;
     818         [ #  # ]:          0 :       att_pt->get_parents_virt(curves);
     819 [ #  # ][ #  # ]:          0 :       for(i=curves.size(); i--;)
     820                 :            :       {
     821         [ #  # ]:          0 :         list.clean_out();
     822         [ #  # ]:          0 :         TopologyBridge *c = curves.get_and_step();
     823 [ #  # ][ #  # ]:          0 :         c->get_simple_attribute("COMPOSITE_GEOM", list);
                 [ #  # ]
     824 [ #  # ][ #  # ]:          0 :         if(list.size() == 0)
     825                 :          0 :           num_visible_curves++;
     826                 :            :       }
     827         [ #  # ]:          0 :       if(num_visible_curves > 2)
     828                 :            :       {
     829         [ #  # ]:          0 :         list.clean_out();
     830 [ #  # ][ #  # ]:          0 :         att_pt->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     831 [ #  # ][ #  # ]:          0 :         att_pt->remove_simple_attribute_virt(list.get());
     832         [ #  # ]:          0 :         TBOwner *bridge_owner = att_pt->owner();
     833         [ #  # ]:          0 :         CompositePoint *cp_bridge_owner = dynamic_cast<CompositePoint*>(bridge_owner);
     834         [ #  # ]:          0 :         if(cp_bridge_owner)
     835                 :            :         {
     836         [ #  # ]:          0 :           TBOwner *cp_owner = cp_bridge_owner->owner();
     837         [ #  # ]:          0 :           HiddenEntitySet *hes = dynamic_cast<HiddenEntitySet*>(cp_owner);
     838         [ #  # ]:          0 :           if(hes)
     839                 :            :           {
     840 [ #  # ][ #  # ]:          0 :             CompositeCurve *cc = dynamic_cast<CompositeCurve*>(hes->owner());
     841         [ #  # ]:          0 :             if(cc)
     842                 :          0 :               cc->HadBridgeRemoved = 1;
     843                 :            :               // This is currently how we are notifying the owning CompositeCurve
     844                 :            :               // that it needs to be deactivated and rebuilt.  It really has 
     845                 :            :               // nothing to do with the bridge being removed though.  Bad.
     846                 :            :           }
     847                 :            :         }
     848                 :            :       }
     849                 :            :       else
     850                 :            :       {
     851         [ #  # ]:          0 :         list.clean_out();
     852 [ #  # ][ #  # ]:          0 :         att_pt->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     853 [ #  # ][ #  # ]:          0 :         other_pt->append_simple_attribute_virt(list.get());
     854         [ #  # ]:          0 :       }
     855                 :            :     }
     856                 :            :     else
     857                 :            :     {
     858                 :            :       // This bridge existed before the imprint operation.  Therefore it
     859                 :            :       // could also have a COMPOSITE_GEOM attribute on it.  Check this.
     860         [ #  # ]:          0 :       list.clean_out();
     861 [ #  # ][ #  # ]:          0 :       other_pt->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     862 [ #  # ][ #  # ]:          0 :       if(list.size() == 0)
     863                 :            :       {
     864                 :            :         // It doesn't have a COMPOSITE_GEOM attribute so we need to remove
     865                 :            :         // the COMPOSITE_GEOM from att_bridge because the hidden nature gets
     866                 :            :         // wiped out by the imprinting process.
     867 [ #  # ][ #  # ]:          0 :         att_pt->get_simple_attribute("COMPOSITE_GEOM",list);
                 [ #  # ]
     868 [ #  # ][ #  # ]:          0 :         att_pt->remove_simple_attribute_virt(list.get());
     869         [ #  # ]:          0 :         TBOwner *bridge_owner = att_pt->owner();
     870         [ #  # ]:          0 :         CompositePoint *cp_bridge_owner = dynamic_cast<CompositePoint*>(bridge_owner);
     871         [ #  # ]:          0 :         if(cp_bridge_owner)
     872                 :            :         {
     873         [ #  # ]:          0 :           TBOwner *cp_owner = cp_bridge_owner->owner();
     874         [ #  # ]:          0 :           HiddenEntitySet *hes = dynamic_cast<HiddenEntitySet*>(cp_owner);
     875         [ #  # ]:          0 :           if(hes)
     876                 :            :           {
     877 [ #  # ][ #  # ]:          0 :             CompositeCurve *cc = dynamic_cast<CompositeCurve*>(hes->owner());
     878         [ #  # ]:          0 :             if(cc)
     879                 :          0 :               cc->HadBridgeRemoved = 1;
     880                 :            :               // This is currently how we are notifying the owning CompositeCurve
     881                 :            :               // that it needs to be deactivated and rebuilt.  It really has 
     882                 :            :               // nothing to do with the bridge being removed though.  Bad.
     883                 :            :           }
     884                 :            :         }
     885                 :            :       }
     886                 :            :       else
     887                 :            :       {
     888                 :            :         // This bridge was also hidden so do nothing.
     889                 :            :       }
     890                 :            :     }
     891         [ #  # ]:          0 :   }
     892                 :          0 : }
     893                 :            : 
     894                 :            : // This is a copy of the function in MergeTool with the difference that it
     895                 :            : // accepts a layer flag to dictate at which level the topology is traversed
     896                 :            : // (solid modeler level or virtual level).
     897                 :          0 : CubitBoolean CompositeEngine::about_spatially_equal( Curve *curve_1, Curve *curve_2,
     898                 :            :                                                CubitSense &relative_sense, 
     899                 :            :                                                double tolerance_factor,
     900                 :            :                                                int layer)
     901                 :            : {
     902         [ #  # ]:          0 :   if( curve_1 == curve_2 )
     903                 :          0 :     return CUBIT_TRUE;
     904                 :            : 
     905                 :          0 :   relative_sense = CUBIT_FORWARD;
     906                 :          0 :   const double ONE_THIRD = 1.0/3.0;
     907                 :            : 
     908                 :            :   // Find the point 1/3 along curve_1 
     909 [ #  # ][ #  # ]:          0 :   CubitVector test_point_1, test_point_2;
     910 [ #  # ][ #  # ]:          0 :   if( curve_1->position_from_fraction( ONE_THIRD, test_point_1 ) != CUBIT_SUCCESS )
     911                 :          0 :     return CUBIT_FALSE;
     912                 :            : 
     913                 :            :   // See if the 1/3 point on curve_1 lies on curve_2
     914 [ #  # ][ #  # ]:          0 :   if ( curve_2->closest_point_trimmed(test_point_1, test_point_2)
     915                 :            :        != CUBIT_SUCCESS )
     916                 :            :   {
     917                 :          0 :     return CUBIT_FALSE;
     918                 :            :   }
     919                 :            : 
     920         [ #  # ]:          0 :   if ( GeometryQueryTool::instance()->
     921 [ #  # ][ #  # ]:          0 :        about_spatially_equal(test_point_1, test_point_2, tolerance_factor )
     922                 :            :        != CUBIT_SUCCESS )
     923                 :            :   {
     924                 :          0 :     return CUBIT_FALSE;
     925                 :            :   }
     926                 :            :   
     927 [ #  # ][ #  # ]:          0 :   CubitVector tangent_1, tangent_2;
     928 [ #  # ][ #  # ]:          0 :   if( curve_1->closest_point(test_point_2, test_point_1, &tangent_1) != CUBIT_SUCCESS )
     929                 :          0 :     return CUBIT_FALSE;
     930 [ #  # ][ #  # ]:          0 :   if( curve_2->closest_point(test_point_1, test_point_2, &tangent_2) != CUBIT_SUCCESS )
     931                 :          0 :     return CUBIT_FALSE;
     932                 :            : 
     933                 :            :   //If one of the curves is zero-length, it will have a zero
     934                 :            :   //tangent vector.
     935 [ #  # ][ #  # ]:          0 :   double len_product = tangent_1.length() * tangent_2.length();
     936         [ #  # ]:          0 :   if( len_product > CUBIT_DBL_MIN )
     937                 :            :   {
     938         [ #  # ]:          0 :     double dot_product = (tangent_1 % tangent_2);
     939         [ #  # ]:          0 :     if (dot_product < 0)
     940                 :          0 :     relative_sense = CUBIT_REVERSED;
     941                 :            :   }
     942                 :            :   else
     943                 :            :   {
     944                 :            :     //If one of the tangents is zero-length, one of the curves had
     945                 :            :     //better be as well.
     946 [ #  # ][ #  # ]:          0 :     assert( (curve_1->measure() * curve_2->measure()) < CUBIT_RESABS );
                 [ #  # ]
     947                 :            :   }
     948                 :            : 
     949                 :            :   //compare the start and end vertices to be spatially equal.
     950 [ #  # ][ #  # ]:          0 :   DLIList<TBPoint*> curve_1_points(2), curve_2_points(2);
                 [ #  # ]
     951 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> c1pts, c2pts;
         [ #  # ][ #  # ]
     952         [ #  # ]:          0 :   curve_1->get_children(c1pts, false, layer);
     953         [ #  # ]:          0 :   curve_2->get_children(c2pts, false, layer);
     954 [ #  # ][ #  # ]:          0 :   CAST_LIST( c1pts, curve_1_points, TBPoint );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     955 [ #  # ][ #  # ]:          0 :   CAST_LIST( c2pts, curve_2_points, TBPoint );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     956                 :            : 
     957 [ #  # ][ #  # ]:          0 :   if( curve_1->bridge_sense() == CUBIT_REVERSED )
     958         [ #  # ]:          0 :     curve_1_points.reverse();
     959 [ #  # ][ #  # ]:          0 :   if( curve_2->bridge_sense() == CUBIT_REVERSED )
     960         [ #  # ]:          0 :     curve_2_points.reverse();
     961                 :            : 
     962         [ #  # ]:          0 :   TBPoint* curve_1_start = curve_1_points.get(); 
     963         [ #  # ]:          0 :   curve_1_points.last();
     964         [ #  # ]:          0 :   TBPoint* curve_1_end =  curve_1_points.get();
     965                 :            : 
     966         [ #  # ]:          0 :   TBPoint* curve_2_start = curve_2_points.get(); 
     967         [ #  # ]:          0 :   curve_2_points.last();
     968         [ #  # ]:          0 :   TBPoint* curve_2_end =  curve_2_points.get();
     969                 :            : 
     970         [ #  # ]:          0 :   if (relative_sense == CUBIT_REVERSED)
     971         [ #  # ]:          0 :     std::swap(curve_2_start, curve_2_end);
     972                 :            : 
     973 [ #  # ][ #  # ]:          0 :   if (curve_1_start == curve_1_end ||curve_2_start == curve_2_end)
     974                 :            :   {
     975         [ #  # ]:          0 :     CubitVector c1start = curve_1_start->coordinates();
     976         [ #  # ]:          0 :     CubitVector c2start = curve_2_start->coordinates();
     977 [ #  # ][ #  # ]:          0 :     if ((curve_1_start != curve_1_end) ||
     978 [ #  # ][ #  # ]:          0 :         (curve_2_start != curve_2_end) ||
     979 [ #  # ][ #  # ]:          0 :         !GeometryQueryTool::instance()->about_spatially_equal(c1start, c2start, tolerance_factor))
     980                 :          0 :       return CUBIT_FALSE;
     981                 :            :   }
     982                 :            :   else
     983                 :            :   {
     984         [ #  # ]:          0 :     CubitVector c1start = curve_1_start->coordinates();
     985         [ #  # ]:          0 :     CubitVector c1end = curve_1_end->coordinates();
     986         [ #  # ]:          0 :     CubitVector c2start = curve_2_start->coordinates();
     987         [ #  # ]:          0 :     CubitVector c2end = curve_2_end->coordinates();
     988 [ #  # ][ #  # ]:          0 :     if ((curve_1_start == curve_2_end) ||
     989         [ #  # ]:          0 :         (curve_1_end == curve_2_start) ||
     990 [ #  # ][ #  # ]:          0 :         !GeometryQueryTool::instance()->about_spatially_equal(c1start, c2start, tolerance_factor ) ||
         [ #  # ][ #  # ]
     991 [ #  # ][ #  # ]:          0 :         !GeometryQueryTool::instance()->about_spatially_equal(c1end, c2end, tolerance_factor ))
     992                 :          0 :       return CUBIT_FALSE;
     993                 :            :   }
     994                 :            : 
     995         [ #  # ]:          0 :   return CUBIT_TRUE;
     996                 :            : 
     997                 :            : }
     998                 :            : 
     999                 :            : // This function will try to determine if virtual topology bridges have
    1000                 :            : // been modified and if so will deactivate them so that they can be 
    1001                 :            : // rebuilt later using the COMPOSITE_GEOM attributes on the underlying
    1002                 :            : // solid model topology.
    1003                 :        120 : void CompositeEngine::remove_modified(DLIList<Surface*> &surfaces,  
    1004                 :            :                                       DLIList<Curve*> &curves, 
    1005                 :            :                                       DLIList<TBPoint*> &points)
    1006                 :            : {
    1007         [ +  - ]:        120 :   clean_out_deactivated_geometry();
    1008                 :            : 
    1009                 :            :   int i, j, k, m, n, w;
    1010                 :        120 :   int something_changed = 1;
    1011         [ +  - ]:        120 :   DLIList<TBPoint*> already_deactivated_points;
    1012 [ +  - ][ +  - ]:        240 :   DLIList<Curve*> already_deactivated_curves;
    1013 [ +  - ][ +  - ]:        240 :   DLIList<Surface*> already_deactivated_surfs;
    1014                 :            : 
    1015         [ +  + ]:        240 :   while(something_changed)
    1016                 :            :   {
    1017                 :        120 :     something_changed = 0;
    1018                 :            : 
    1019         [ +  - ]:        120 :     DLIList<TBPoint*> deactivated_points;
    1020 [ +  - ][ +  - ]:        240 :     DLIList<Curve*> deactivated_curves;
    1021 [ +  - ][ +  - ]:        240 :     DLIList<Surface*> deactivated_surfs;
    1022                 :            : 
    1023                 :            :     // Look for composite points that are out of date.
    1024 [ +  - ][ +  + ]:       2206 :     for(w=points.size(); w--;)
    1025                 :            :     {
    1026 [ +  - ][ -  + ]:       2086 :       CompositePoint *p = dynamic_cast<CompositePoint*>(points.get_and_step());
    1027 [ -  + ][ #  # ]:       2086 :       if(p && !already_deactivated_points.is_in_list(p))
         [ #  # ][ -  + ]
           [ -  +  #  # ]
    1028         [ #  # ]:          0 :         deactivated_points.append(p);
    1029                 :            :     }
    1030         [ +  - ]:        120 :     deactivated_points.uniquify_ordered();
    1031                 :            : 
    1032                 :            :     // Look for composite curves that are out of date.
    1033 [ +  - ][ +  + ]:       3139 :     for(w=curves.size(); w--;)
    1034                 :            :     {
    1035         [ +  - ]:       3019 :       Curve *current_curve = curves.get_and_step();
    1036         [ -  + ]:       3019 :       CompositeCurve *cur = dynamic_cast<CompositeCurve*>(current_curve);
    1037 [ -  + ][ #  # ]:       3019 :       if(cur && !already_deactivated_curves.is_in_list(cur))
         [ #  # ][ -  + ]
           [ -  +  #  # ]
    1038         [ #  # ]:          0 :         deactivated_curves.append(cur);
    1039                 :            :     }
    1040         [ +  - ]:        120 :     deactivated_curves.uniquify_ordered();
    1041                 :            : 
    1042                 :            :     // Look for composite surfaces that are out of date.
    1043 [ +  - ][ +  + ]:       1775 :     for(w=surfaces.size(); w--;)
    1044                 :            :     {
    1045 [ +  - ][ -  + ]:       1655 :       CompositeSurface* csurf = dynamic_cast<CompositeSurface*> (surfaces.get_and_step());
    1046 [ -  + ][ #  # ]:       1655 :       if (csurf && !already_deactivated_surfs.is_in_list(csurf))
         [ #  # ][ -  + ]
           [ -  +  #  # ]
    1047         [ #  # ]:          0 :         deactivated_surfs.append(csurf);
    1048                 :            :     }
    1049         [ +  - ]:        120 :     deactivated_surfs.uniquify_ordered();
    1050                 :            : 
    1051         [ +  - ]:        120 :     already_deactivated_points += deactivated_points;
    1052         [ +  - ]:        120 :     already_deactivated_curves += deactivated_curves;
    1053         [ +  - ]:        120 :     already_deactivated_surfs += deactivated_surfs;
    1054                 :            : 
    1055 [ +  - ][ +  - ]:        120 :     something_changed += deactivated_surfs.size() + deactivated_curves.size() +
    1056         [ +  - ]:        120 :       deactivated_points.size();
    1057                 :            : 
    1058                 :            :     // Now actually deactivate the out of date composite surfs.
    1059 [ +  - ][ -  + ]:        120 :     for(j=deactivated_surfs.size(); j--;)
    1060                 :            :     {
    1061 [ #  # ][ #  # ]:          0 :       CompositeSurface *csurf = dynamic_cast<CompositeSurface*>(deactivated_surfs.get_and_step());
    1062                 :            : 
    1063                 :            :       // We have to also deactivate the boundary curves.  When we deactivate
    1064                 :            :       // the CompositeSurface it removes all of the CompositeCoEdges associated
    1065                 :            :       // with it.  However, it doesn't deactivate the composite curves associated
    1066                 :            :       // with the composite coedges.  Therefore you can end up with a regular
    1067                 :            :       // CoEdge pointing to a CompositeCurve and if the CompositeCurve has more
    1068                 :            :       // than 1 curve in it later calls to replace_surface (which will in turn
    1069                 :            :       // call replace_curve) will fail.
    1070         [ #  # ]:          0 :       DLIList<Curve*> boundary_curves;
    1071         [ #  # ]:          0 :       csurf->curves(boundary_curves);
    1072 [ #  # ][ #  # ]:          0 :       for (k=boundary_curves.size(); k--; )
    1073                 :            :       {
    1074 [ #  # ][ #  # ]:          0 :         CompositeCurve* c = dynamic_cast<CompositeCurve*>(boundary_curves.get_and_step());
    1075         [ #  # ]:          0 :         assert(NULL != c);
    1076         [ #  # ]:          0 :         deactivated_curves.append_unique(c);
    1077         [ #  # ]:          0 :         already_deactivated_curves.append_unique(c);
    1078                 :            : 
    1079         [ #  # ]:          0 :         DLIList<TBPoint*> boundary_pts;
    1080         [ #  # ]:          0 :         c->points(boundary_pts);
    1081 [ #  # ][ #  # ]:          0 :         for (int e=boundary_pts.size(); e--; )
    1082                 :            :         {
    1083 [ #  # ][ #  # ]:          0 :           CompositePoint* p = dynamic_cast<CompositePoint*>(boundary_pts.get_and_step());
    1084         [ #  # ]:          0 :           deactivated_points.append_unique(p);
    1085         [ #  # ]:          0 :           already_deactivated_points.append_unique(p);
    1086         [ #  # ]:          0 :           notify_deactivated(p);
    1087                 :            :         }
    1088                 :            : 
    1089         [ #  # ]:          0 :         notify_deactivated(c);
    1090         [ #  # ]:          0 :       }
    1091                 :            : 
    1092         [ #  # ]:          0 :       notify_deactivated(csurf);
    1093                 :            : 
    1094 [ #  # ][ #  # ]:          0 :       DLIList<Curve*> hidden;
    1095         [ #  # ]:          0 :       csurf->get_hidden_curves(hidden);
    1096 [ #  # ][ #  # ]:          0 :       for (k=hidden.size(); k--; )
    1097                 :            :       {
    1098 [ #  # ][ #  # ]:          0 :         CompositeCurve* hcurve = dynamic_cast<CompositeCurve*>(hidden.pop());
    1099         [ #  # ]:          0 :         assert(NULL != hcurve);
    1100                 :            : 
    1101         [ #  # ]:          0 :         deactivated_curves.append_unique(hcurve);
    1102         [ #  # ]:          0 :         already_deactivated_curves.append_unique(hcurve);
    1103         [ #  # ]:          0 :         notify_deactivated(hcurve);
    1104                 :            : 
    1105 [ #  # ][ #  # ]:          0 :         if(hcurve->num_curves() == 1)
    1106                 :            :         {
    1107         [ #  # ]:          0 :           Curve *c = hcurve->get_curve(0);
    1108         [ #  # ]:          0 :           DLIList<TopologyBridge*> end_pts;
    1109         [ #  # ]:          0 :           c->get_children(end_pts, false, 0);
    1110 [ #  # ][ #  # ]:          0 :           for(m=end_pts.size(); m--;)
    1111                 :            :           {
    1112 [ #  # ][ #  # ]:          0 :             TBPoint *cur_p = dynamic_cast<TBPoint*>(end_pts.get_and_step());
    1113         [ #  # ]:          0 :             if(cur_p)
    1114                 :            :             {
    1115 [ #  # ][ #  # ]:          0 :               CompositePoint* cp = dynamic_cast<CompositePoint*>(cur_p->owner());
    1116         [ #  # ]:          0 :               if(cp)
    1117                 :          0 :                 cur_p = (TBPoint*)cp;
    1118         [ #  # ]:          0 :               TBOwner *own = cur_p->owner();
    1119         [ #  # ]:          0 :               HiddenEntitySet *hes = dynamic_cast<HiddenEntitySet*>(own);
    1120         [ #  # ]:          0 :               if(hes)
    1121                 :            :               {
    1122 [ #  # ][ #  # ]:          0 :                 CompositeCurve *cc = dynamic_cast<CompositeCurve*>(hes->owner());
    1123         [ #  # ]:          0 :                 if(cc)
    1124                 :            :                 {
    1125         [ #  # ]:          0 :                   deactivated_curves.append_unique(cc);
    1126         [ #  # ]:          0 :                   already_deactivated_curves.append_unique(cc);
    1127         [ #  # ]:          0 :                   notify_deactivated(cc);
    1128                 :            : 
    1129         [ #  # ]:          0 :                   DLIList<TBPoint*> hidden_pts;
    1130         [ #  # ]:          0 :                   cc->get_hidden_points(hidden_pts);
    1131 [ #  # ][ #  # ]:          0 :                   for (n=hidden_pts.size(); n--; )
    1132                 :            :                   {
    1133 [ #  # ][ #  # ]:          0 :                     CompositePoint *hpoint = dynamic_cast<CompositePoint*>(hidden_pts.pop());
    1134         [ #  # ]:          0 :                     assert(NULL != hpoint);
    1135         [ #  # ]:          0 :                     deactivated_points.append_unique(hpoint);
    1136         [ #  # ]:          0 :                     already_deactivated_points.append_unique(hpoint);
    1137         [ #  # ]:          0 :                     notify_deactivated(hpoint);
    1138         [ #  # ]:          0 :                   }
    1139                 :            :                 }
    1140                 :            :               }
    1141                 :            :             }
    1142         [ #  # ]:          0 :           }
    1143                 :            :         }
    1144                 :            :       }
    1145         [ #  # ]:          0 :     }
    1146                 :            : 
    1147                 :            :     // Now actually deactivate the out of date composite curves.
    1148 [ +  - ][ -  + ]:        120 :     for(j=deactivated_curves.size(); j--;)
    1149                 :            :     {
    1150 [ #  # ][ #  # ]:          0 :       CompositeCurve *ccurve = dynamic_cast<CompositeCurve*>(deactivated_curves.get_and_step());
    1151                 :            : 
    1152         [ #  # ]:          0 :       DLIList<TBPoint*> boundary_pts;
    1153         [ #  # ]:          0 :       ccurve->points(boundary_pts);
    1154 [ #  # ][ #  # ]:          0 :       for (k=boundary_pts.size(); k--; )
    1155                 :            :       {
    1156 [ #  # ][ #  # ]:          0 :         CompositePoint* p = dynamic_cast<CompositePoint*>(boundary_pts.get_and_step());
    1157         [ #  # ]:          0 :         deactivated_points.append_unique(p);
    1158         [ #  # ]:          0 :         already_deactivated_points.append_unique(p);
    1159         [ #  # ]:          0 :         notify_deactivated(p);
    1160                 :            :       }
    1161                 :            : 
    1162         [ #  # ]:          0 :       notify_deactivated(ccurve);
    1163                 :            : 
    1164                 :            :       int j;
    1165 [ #  # ][ #  # ]:          0 :       DLIList<TBPoint*> hidden;
    1166         [ #  # ]:          0 :       ccurve->get_hidden_points(hidden);
    1167 [ #  # ][ #  # ]:          0 :       for (j=hidden.size(); j--; )
    1168                 :            :       {
    1169 [ #  # ][ #  # ]:          0 :         CompositePoint *hpoint = dynamic_cast<CompositePoint*>(hidden.pop());
    1170         [ #  # ]:          0 :         assert(NULL != hpoint);
    1171         [ #  # ]:          0 :         deactivated_points.append_unique(hpoint);
    1172         [ #  # ]:          0 :         already_deactivated_points.append_unique(hpoint);
    1173         [ #  # ]:          0 :         notify_deactivated(hpoint);
    1174                 :            :       }
    1175         [ #  # ]:          0 :     }
    1176                 :            : 
    1177                 :            :     // Now actually deactivate the out of date composite points.
    1178 [ +  - ][ -  + ]:        120 :     for(j=deactivated_points.size(); j--;)
    1179                 :            :     {
    1180 [ #  # ][ #  # ]:          0 :       CompositePoint* cpoint = dynamic_cast<CompositePoint*> (deactivated_points.pop());
    1181         [ #  # ]:          0 :       notify_deactivated(cpoint);
    1182                 :            :     }
    1183         [ +  - ]:        120 :   }
    1184                 :            : 
    1185                 :        120 :   int remove_point_atts = 1;
    1186         [ +  - ]:        120 :   if(remove_point_atts)
    1187                 :            :   {
    1188                 :            :     // Remove any COMPOSITE_GEOM attributes on points that
    1189                 :            :     // have a valence of more than two (real curves - hidden curves).
    1190 [ +  - ][ +  + ]:       2206 :     for(i=points.size(); i>0; i--)
    1191                 :            :     {
    1192         [ +  - ]:       2086 :       TBPoint *pt = points.get_and_step();
    1193         [ -  + ]:       2086 :       CompositePoint *cp = dynamic_cast<CompositePoint*>(pt);
    1194         [ -  + ]:       2086 :       if(cp)
    1195         [ #  # ]:          0 :         pt = cp->get_point();
    1196         [ +  - ]:       2086 :       DLIList<CubitSimpleAttrib> attribs;
    1197 [ +  - ][ +  - ]:       2086 :       pt->get_simple_attribute("COMPOSITE_GEOM", attribs);
                 [ +  - ]
    1198 [ +  - ][ -  + ]:       2086 :       if(attribs.size() > 0)
    1199                 :            :       {
    1200         [ #  # ]:          0 :         DLIList<TopologyBridge*> tmp_curves;
    1201         [ #  # ]:          0 :         pt->get_parents_virt(tmp_curves);
    1202                 :          0 :         int num_curves = 0;
    1203 [ #  # ][ #  # ]:          0 :         for(j=tmp_curves.size(); j>0; j--)
    1204                 :            :         {
    1205         [ #  # ]:          0 :           TopologyBridge *crv = tmp_curves.get_and_step();
    1206         [ #  # ]:          0 :           DLIList<CubitSimpleAttrib> attribs;
    1207 [ #  # ][ #  # ]:          0 :           crv->get_simple_attribute("COMPOSITE_GEOM", attribs);
                 [ #  # ]
    1208 [ #  # ][ #  # ]:          0 :           if(attribs.size() == 0)
    1209                 :          0 :             num_curves++;
    1210         [ #  # ]:          0 :         }
    1211         [ #  # ]:          0 :         if(num_curves != 2)
    1212                 :            :         {
    1213 [ #  # ][ #  # ]:          0 :           for(j=attribs.size(); j>0; j--)
    1214                 :            :           {
    1215         [ #  # ]:          0 :             const CubitSimpleAttrib &csa = attribs.get_and_step();
    1216         [ #  # ]:          0 :             pt->remove_simple_attribute_virt(csa);
    1217                 :            :           }
    1218         [ #  # ]:          0 :         }
    1219                 :            :       }
    1220         [ +  - ]:       2086 :     }
    1221         [ +  - ]:        120 :   }
    1222                 :        120 : }
    1223                 :            : 
    1224                 :            : //-------------------------------------------------------------------------
    1225                 :            : // Purpose       : Constructor
    1226                 :            : //
    1227                 :            : // Special Notes : 
    1228                 :            : //
    1229                 :            : // Creator       : Jason Kraftcheck
    1230                 :            : //
    1231                 :            : // Creation Date : 08/25/03
    1232                 :            : //-------------------------------------------------------------------------
    1233                 :       1682 : CompositeEngine::CompositeEngine()
    1234                 :            : {
    1235                 :            :   CubitStatus result = GeometryQueryTool::instance()->
    1236 [ +  - ][ +  - ]:        841 :     register_intermediate_engine( this );
    1237         [ -  + ]:        841 :   assert(result == CUBIT_SUCCESS);
    1238         [ -  + ]:        841 :   if (CUBIT_SUCCESS != result) {
    1239 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Failed to register intermediate engine.\n");
         [ #  # ][ #  # ]
    1240                 :            :   }
    1241                 :        841 : }
    1242                 :            : 
    1243                 :            : //-------------------------------------------------------------------------
    1244                 :            : // Purpose       : Get composite-level query results from
    1245                 :            : //                 query of underlying topology.
    1246                 :            : //
    1247                 :            : // Special Notes : 
    1248                 :            : //
    1249                 :            : // Creator       : Jason Kraftcheck
    1250                 :            : //
    1251                 :            : // Creation Date : 03/13/02
    1252                 :            : //-------------------------------------------------------------------------
    1253                 :            : /*
    1254                 :            : void CompositeEngine::fix_up_query_results( DLIList<TopologyBridge*>& list,
    1255                 :            :                                             bool keep_hidden )
    1256                 :            : {
    1257                 :            :   DLIList<TopologyBridge*> tmp_list;
    1258                 :            :   int i;
    1259                 :            :   
    1260                 :            :   list.reset();
    1261                 :            :   for( i = list.size(); i--; )
    1262                 :            :   {
    1263                 :            :     TopologyBridge* bridge = list.get();
    1264                 :            :     TBOwnerSet* set = dynamic_cast<TBOwnerSet*>(bridge->owner());
    1265                 :            :     if( set )
    1266                 :            :     {
    1267                 :            :       tmp_list.clean_out();
    1268                 :            :       set->get_owners( tmp_list );
    1269                 :            :       if( tmp_list.size() )
    1270                 :            :       {
    1271                 :            :         tmp_list.reset();
    1272                 :            :         list.change_to( tmp_list.get_and_step() );
    1273                 :            :         for( int j = 1; j < tmp_list.size(); j++ )
    1274                 :            :           list.insert( tmp_list.get_and_step() );
    1275                 :            :       }
    1276                 :            :       else
    1277                 :            :       {
    1278                 :            :         list.change_to(0);
    1279                 :            :       }
    1280                 :            :     }
    1281                 :            :     list.step();
    1282                 :            :   }
    1283                 :            :   
    1284                 :            :   list.remove_all_with_value( 0 );
    1285                 :            :   
    1286                 :            :   list.reset();
    1287                 :            :   for( i = list.size(); i--; )
    1288                 :            :   {
    1289                 :            :     TopologyBridge* bridge = list.get();
    1290                 :            :     TopologyBridge *next = 0;
    1291                 :            :     while( next = dynamic_cast<TopologyBridge*>(bridge->owner()) )
    1292                 :            :       bridge = next;
    1293                 :            :     
    1294                 :            :     if( !keep_hidden && dynamic_cast<HiddenEntitySet*>(bridge->owner()) )
    1295                 :            :     {
    1296                 :            :       list.change_to(0);
    1297                 :            :     }
    1298                 :            :     else if( list.get() != bridge )
    1299                 :            :     {
    1300                 :            :       if( list.is_in_list( bridge ) )
    1301                 :            :         list.change_to(0);
    1302                 :            :       else
    1303                 :            :         list.change_to(bridge);
    1304                 :            :     }
    1305                 :            :     
    1306                 :            :     list.step();
    1307                 :            :   }
    1308                 :            :   
    1309                 :            :   list.remove_all_with_value( 0 );
    1310                 :            : }
    1311                 :            : */
    1312                 :            : 
    1313                 :            : 
    1314                 :            : //-------------------------------------------------------------------------
    1315                 :            : // Purpose       : Combine two curves
    1316                 :            : //
    1317                 :            : // Special Notes : 
    1318                 :            : //
    1319                 :            : // Creator       : Jason Kraftcheck
    1320                 :            : //
    1321                 :            : // Creation Date : 03/13/02
    1322                 :            : //-------------------------------------------------------------------------
    1323                 :          0 : CompositeCurve* CompositeEngine::composite( Curve* keep_curve,
    1324                 :            :                                             Curve* dead_curve,
    1325                 :            :                                             TBPoint* keep_point,
    1326                 :            :                                             bool remove_partition )
    1327                 :            : {
    1328         [ #  # ]:          0 :   if( keep_curve == dead_curve )
    1329                 :            :   {
    1330 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Cannot remove vertex from single-vertex curve.\n");
    1331                 :          0 :     return 0;
    1332                 :            :   }
    1333                 :            :   
    1334                 :          0 :   CompositeCurve* result = 0;
    1335         [ #  # ]:          0 :   CompositeCurve* ckeep = dynamic_cast<CompositeCurve*>(keep_curve);
    1336         [ #  # ]:          0 :   CompositeCurve* cdead = dynamic_cast<CompositeCurve*>(dead_curve);
    1337                 :          0 :   bool replaced1 = false;
    1338                 :          0 :   bool replaced2 = false;
    1339                 :            :   
    1340         [ #  # ]:          0 :   if( !ckeep )
    1341                 :            :   {
    1342                 :          0 :     ckeep = replace_curve( keep_curve );
    1343                 :          0 :     replaced1 = true;
    1344                 :            :   }
    1345         [ #  # ]:          0 :   if( !cdead )
    1346                 :            :   {
    1347                 :          0 :     cdead = replace_curve( dead_curve );
    1348                 :          0 :     replaced2 = true;
    1349                 :            :   }
    1350                 :            :   
    1351         [ #  # ]:          0 :   CompositePoint* comppoint = dynamic_cast<CompositePoint*>(keep_point);
    1352 [ #  # ][ #  # ]:          0 :   if( keep_point && !comppoint )
    1353                 :            :   {
    1354         [ #  # ]:          0 :     comppoint = dynamic_cast<CompositePoint*>(keep_point->owner());
    1355         [ #  # ]:          0 :     assert( comppoint!= NULL );
    1356                 :            :   }
    1357                 :            :   
    1358 [ #  # ][ #  # ]:          0 :   if( !ckeep || !cdead || 
         [ #  # ][ #  # ]
    1359                 :          0 :       !(result = combine(ckeep, cdead, comppoint, remove_partition)) )
    1360                 :            :   {
    1361 [ #  # ][ #  # ]:          0 :     if( replaced1 && ckeep )
    1362                 :            :     {
    1363                 :          0 :       Curve* s = remove_composite( ckeep );
    1364         [ #  # ]:          0 :       assert( s != 0 );
    1365         [ #  # ]:          0 :       if (NULL == s) {
    1366 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Failed to remove a 1-curve composite.\n");
    1367                 :          0 :         return NULL;
    1368                 :            :       }
    1369                 :            :     }
    1370 [ #  # ][ #  # ]:          0 :     if( replaced2 && cdead )
    1371                 :            :     {
    1372                 :          0 :       Curve* s = remove_composite( cdead );
    1373         [ #  # ]:          0 :       assert( s != 0 );
    1374         [ #  # ]:          0 :       if (NULL == s) {
    1375 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Failed to remove a 1-curve composite.\n");
    1376                 :          0 :         return NULL;
    1377                 :            :       }
    1378                 :            :     }
    1379                 :            :   }
    1380                 :            :   
    1381                 :          0 :   return result;
    1382                 :            : }
    1383                 :            : 
    1384                 :            : //-------------------------------------------------------------------------
    1385                 :            : // Purpose       : Replace a "point" curve with a composite
    1386                 :            : //
    1387                 :            : // Special Notes : 
    1388                 :            : //
    1389                 :            : // Creator       : Jason Kraftcheck
    1390                 :            : //
    1391                 :            : // Creation Date : 11/26/02
    1392                 :            : //-------------------------------------------------------------------------
    1393                 :          0 : CompositePoint* CompositeEngine::replace_point( TBPoint* point )
    1394                 :            : {
    1395 [ #  # ][ #  # ]:          0 :   assert( !dynamic_cast<CompositePoint*>(point) );
    1396         [ #  # ]:          0 :   return new CompositePoint( point );
    1397                 :            : }
    1398                 :            : 
    1399                 :            : //-------------------------------------------------------------------------
    1400                 :            : // Purpose       : Replace a "real" curve with a composite
    1401                 :            : //
    1402                 :            : // Special Notes : 
    1403                 :            : //
    1404                 :            : // Creator       : Jason Kraftcheck
    1405                 :            : //
    1406                 :            : // Creation Date : 03/13/02
    1407                 :            : //-------------------------------------------------------------------------
    1408                 :          0 : CompositeCurve* CompositeEngine::replace_curve( Curve* curve )
    1409                 :            : {
    1410 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> points, coedges;
                 [ #  # ]
    1411                 :            :   //curve->get_children_virt( points );
    1412                 :            :   //fix_up_query_results(points);
    1413         [ #  # ]:          0 :   curve->get_children( points, true, COMPOSITE_LAYER );
    1414                 :            : 
    1415 [ #  # ][ #  # ]:          0 :   if(points.size() > 2)
    1416                 :          0 :     return 0;
    1417                 :            :     
    1418         [ #  # ]:          0 :   points.reset();
    1419 [ #  # ][ #  # ]:          0 :   TBPoint* start_pt = dynamic_cast<TBPoint*>(points.get_and_step());
    1420 [ #  # ][ #  # ]:          0 :   TBPoint*   end_pt = dynamic_cast<TBPoint*>(points.get_and_step());
    1421                 :            : 
    1422         [ #  # ]:          0 :   CompositeCurve* composite = dynamic_cast<CompositeCurve*>(curve);
    1423                 :            :   
    1424         [ #  # ]:          0 :   if(!composite)
    1425 [ #  # ][ #  # ]:          0 :     composite = new CompositeCurve( curve );
    1426                 :            :   else
    1427                 :            :   {
    1428 [ #  # ][ #  # ]:          0 :     if(composite->num_curves() > 1)
    1429                 :            :     {
    1430 [ #  # ][ #  # ]:          0 :       PRINT_ERROR("Error replacing existing composite curve with more than one underlying curve\n");
         [ #  # ][ #  # ]
    1431                 :          0 :       return 0;
    1432                 :            :     }
    1433                 :            :   }
    1434                 :            : 
    1435         [ #  # ]:          0 :   CompositePoint* start = dynamic_cast<CompositePoint*>(start_pt);
    1436         [ #  # ]:          0 :   if( !start ) 
    1437         [ #  # ]:          0 :     start = replace_point( start_pt );
    1438                 :          0 :   CompositePoint* end = 0;
    1439         [ #  # ]:          0 :   if ( end_pt == start_pt )
    1440                 :          0 :     end = start;
    1441 [ #  # ][ #  # ]:          0 :   else if ( !(end = dynamic_cast<CompositePoint*>(end_pt)) )
    1442         [ #  # ]:          0 :     end = replace_point( end_pt );
    1443 [ #  # ][ #  # ]:          0 :   assert( start && end );
    1444                 :            : 
    1445         [ #  # ]:          0 :   composite->start_point( start );
    1446         [ #  # ]:          0 :   composite->  end_point(   end );
    1447                 :            : 
    1448 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> existing_composite_coedges;
    1449 [ #  # ][ #  # ]:          0 :   if(dynamic_cast<CompositeCurve*>(curve))
                 [ #  # ]
    1450                 :            :   {
    1451 [ #  # ][ #  # ]:          0 :     dynamic_cast<CompositeCurve*>(curve)->get_curve(0)->get_parents_virt(coedges);
                 [ #  # ]
    1452         [ #  # ]:          0 :     curve->get_parents_virt(existing_composite_coedges);
    1453                 :            :   }
    1454                 :            :   else
    1455                 :            :   {
    1456         [ #  # ]:          0 :     curve->get_parents_virt( coedges );
    1457                 :            :   }
    1458 [ #  # ][ #  # ]:          0 :   for( int i = coedges.size(); i--; )
    1459                 :            :   {
    1460 [ #  # ][ #  # ]:          0 :     CoEdgeSM* coedge = dynamic_cast<CoEdgeSM*>(coedges.get_and_step());
    1461         [ #  # ]:          0 :     assert(coedge);
    1462                 :          0 :     CompositeCoEdge* ccoedge = NULL;
    1463 [ #  # ][ #  # ]:          0 :     for(int h=existing_composite_coedges.size(); h>0; h--)
    1464                 :            :     {
    1465 [ #  # ][ #  # ]:          0 :       CompositeCoEdge *temp = dynamic_cast<CompositeCoEdge*>(existing_composite_coedges.get_and_step());
    1466 [ #  # ][ #  # ]:          0 :       if(temp->get_coedge(0) == coedge)
    1467                 :            :       {
    1468                 :          0 :         ccoedge = temp;
    1469                 :          0 :         h = 0;
    1470                 :            :       }
    1471                 :            :     }
    1472         [ #  # ]:          0 :     if(!ccoedge)
    1473                 :            :     {
    1474 [ #  # ][ #  # ]:          0 :       ccoedge = new CompositeCoEdge( coedge );
    1475 [ #  # ][ #  # ]:          0 :       if( composite->get_sense(0) == CUBIT_REVERSED )
    1476         [ #  # ]:          0 :         ccoedge->reverse();
    1477                 :            :       
    1478 [ #  # ][ #  # ]:          0 :       assert( ccoedge->get_curve() == 0 );
    1479         [ #  # ]:          0 :       composite->add( ccoedge );
    1480                 :            :     }
    1481                 :            :   }
    1482                 :            :   
    1483         [ #  # ]:          0 :   return composite;
    1484                 :            : }
    1485                 :            : 
    1486                 :            : 
    1487                 :            : //-------------------------------------------------------------------------
    1488                 :            : // Purpose       : Replace a "real" surface with a composite
    1489                 :            : //
    1490                 :            : // Special Notes : 
    1491                 :            : //
    1492                 :            : // Creator       : Jason Kraftcheck
    1493                 :            : //
    1494                 :            : // Creation Date : 03/13/02
    1495                 :            : //-------------------------------------------------------------------------
    1496                 :          0 : CompositeSurface* CompositeEngine::replace_surface( Surface* surface )
    1497                 :            : {
    1498 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> loops, coedges, curves;
         [ #  # ][ #  # ]
                 [ #  # ]
    1499                 :            :   int i, j;
    1500 [ #  # ][ #  # ]:          0 :   if( dynamic_cast<CompositeSurface*>(surface) )
                 [ #  # ]
    1501                 :          0 :     return 0;
    1502                 :            :   
    1503 [ #  # ][ #  # ]:          0 :   CompositeSurface* compsurf = new CompositeSurface( surface );
    1504                 :            :   //surface->get_children_virt( loops );
    1505                 :            :   //fix_up_query_results(loops);
    1506         [ #  # ]:          0 :   surface->get_children( loops, false, COMPOSITE_LAYER );
    1507         [ #  # ]:          0 :   loops.reset();
    1508 [ #  # ][ #  # ]:          0 :   for( i = loops.size();i--; )
    1509                 :            :   {
    1510         [ #  # ]:          0 :     TopologyBridge* loop_bridge = loops.get_and_step();
    1511 [ #  # ][ #  # ]:          0 :     CompositeLoop* comploop = new CompositeLoop();
    1512         [ #  # ]:          0 :     compsurf->add( comploop );
    1513 [ #  # ][ #  # ]:          0 :     if( loop_bridge->owner() )
    1514                 :            :     {
    1515 [ #  # ][ #  # ]:          0 :       loop_bridge->owner()->swap_bridge( loop_bridge, comploop, false );
    1516         [ #  # ]:          0 :       loop_bridge->owner(0);
    1517                 :            :     }
    1518                 :            :     //compsurf->hidden_entities().hide( loop_bridge );
    1519                 :            :     
    1520         [ #  # ]:          0 :     coedges.clean_out();
    1521                 :            :     //loop_bridge->get_children_virt( coedges );
    1522                 :            :     //fix_up_query_results(coedges);
    1523         [ #  # ]:          0 :     loop_bridge->get_children( coedges, false, COMPOSITE_LAYER );
    1524                 :            :     
    1525         [ #  # ]:          0 :     coedges.reset();
    1526                 :          0 :     CompositeCoEdge* prev = 0;
    1527 [ #  # ][ #  # ]:          0 :     for( j = coedges.size(); j--; )
    1528                 :            :     {
    1529 [ #  # ][ #  # ]:          0 :       CoEdgeSM* coedge = dynamic_cast<CoEdgeSM*>(coedges.get_and_step());
    1530         [ #  # ]:          0 :       CompositeCoEdge* comp_coedge = dynamic_cast<CompositeCoEdge*>(coedge);
    1531         [ #  # ]:          0 :       if( !comp_coedge )
    1532                 :            :       {
    1533         [ #  # ]:          0 :         curves.clean_out();
    1534                 :            :         //coedge->get_children_virt( curves );
    1535                 :            :         //fix_up_query_results(curves);
    1536         [ #  # ]:          0 :         coedge->get_children(curves, false, COMPOSITE_LAYER);
    1537 [ #  # ][ #  # ]:          0 :         assert( curves.size() == 1 );
    1538 [ #  # ][ #  # ]:          0 :         replace_curve( dynamic_cast<Curve*>(curves.get()) );
                 [ #  # ]
    1539 [ #  # ][ #  # ]:          0 :         comp_coedge = dynamic_cast<CompositeCoEdge*>(coedge->owner());
    1540         [ #  # ]:          0 :         assert( comp_coedge!= NULL );
    1541                 :            :       }
    1542                 :            :       else
    1543                 :            :       {
    1544                 :            :         /*
    1545                 :            :         PRINT_INFO("\nStart: %lf %lf %lf", comp_coedge->start_point()->coordinates().x(),
    1546                 :            :           comp_coedge->start_point()->coordinates().y(), comp_coedge->start_point()->coordinates().z());
    1547                 :            :         PRINT_INFO("\nEnd: %lf %lf %lf", comp_coedge->end_point()->coordinates().x(),
    1548                 :            :           comp_coedge->end_point()->coordinates().y(), comp_coedge->end_point()->coordinates().z());
    1549                 :            :        */
    1550                 :            :       }
    1551         [ #  # ]:          0 :       comploop->insert_after( comp_coedge, prev );
    1552                 :          0 :       prev = comp_coedge;
    1553                 :            :     }
    1554                 :            :   }
    1555                 :            :   
    1556         [ #  # ]:          0 :   return compsurf;
    1557                 :            : }
    1558                 :            :       
    1559                 :            : 
    1560                 :            : 
    1561                 :            : //-------------------------------------------------------------------------
    1562                 :            : // Purpose       : Replace a "real" lump with a composite
    1563                 :            : //
    1564                 :            : // Special Notes : 
    1565                 :            : //
    1566                 :            : // Creator       : Jason Kraftcheck
    1567                 :            : //
    1568                 :            : // Creation Date : 07/19/02
    1569                 :            : //-------------------------------------------------------------------------
    1570                 :          0 : CompositeLump* CompositeEngine::replace_lump( Lump* lump )
    1571                 :            : {
    1572 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> shells, surfaces;
                 [ #  # ]
    1573                 :            :   int i, j;
    1574 [ #  # ][ #  # ]:          0 :   if( dynamic_cast<CompositeLump*>(lump) )
                 [ #  # ]
    1575                 :          0 :     return 0;
    1576                 :            :   
    1577 [ #  # ][ #  # ]:          0 :   CompositeLump* complump = new CompositeLump( lump );
    1578                 :            :   //lump->get_children_virt( shells );
    1579                 :            :   //fix_up_query_results(shells);
    1580         [ #  # ]:          0 :   lump->get_children(shells, false, COMPOSITE_LAYER);
    1581         [ #  # ]:          0 :   shells.reset();
    1582 [ #  # ][ #  # ]:          0 :   for( i = shells.size();i--; )
    1583                 :            :   {
    1584 [ #  # ][ #  # ]:          0 :     CompositeShell* compshell = new CompositeShell();
    1585         [ #  # ]:          0 :     complump->add( compshell );
    1586         [ #  # ]:          0 :     TopologyBridge* shell_bridge = shells.get_and_step();
    1587 [ #  # ][ #  # ]:          0 :     if( shell_bridge->owner() )
    1588                 :            :     {
    1589 [ #  # ][ #  # ]:          0 :       shell_bridge->owner()->swap_bridge(shell_bridge, compshell, false);
    1590         [ #  # ]:          0 :       shell_bridge->owner(0);
    1591                 :            :     }
    1592                 :            :     //complump->hidden_entities().hide( shell_bridge );
    1593                 :            :     
    1594                 :            :     
    1595         [ #  # ]:          0 :     surfaces.clean_out();
    1596                 :            :     //shell_bridge->get_children_virt( surfaces );
    1597                 :            :     //fix_up_query_results(surfaces);
    1598         [ #  # ]:          0 :     shell_bridge->get_children(surfaces, false, COMPOSITE_LAYER);
    1599                 :            :     
    1600         [ #  # ]:          0 :     surfaces.reset();
    1601 [ #  # ][ #  # ]:          0 :     for( j = surfaces.size(); j--; )
    1602                 :            :     {
    1603 [ #  # ][ #  # ]:          0 :       Surface* surface = dynamic_cast<Surface*>(surfaces.get_and_step());
    1604         [ #  # ]:          0 :       CompositeSurface* compsurf = dynamic_cast<CompositeSurface*>(surface);
    1605         [ #  # ]:          0 :       if( !compsurf )
    1606                 :            :       {
    1607         [ #  # ]:          0 :         compsurf = replace_surface( surface );
    1608         [ #  # ]:          0 :         assert( compsurf!= NULL );
    1609                 :            :       }
    1610                 :            : 
    1611         [ #  # ]:          0 :       compshell->add( compsurf, CUBIT_FORWARD );
    1612                 :            :     }
    1613                 :            :   }
    1614                 :            :   
    1615         [ #  # ]:          0 :   return complump;
    1616                 :            : }
    1617                 :            :       
    1618                 :            : 
    1619                 :            : 
    1620                 :            : //-------------------------------------------------------------------------
    1621                 :            : // Purpose       : Replace a "real" bodysm with a composite
    1622                 :            : //
    1623                 :            : // Special Notes : 
    1624                 :            : //
    1625                 :            : // Creator       : Jason Kraftcheck
    1626                 :            : //
    1627                 :            : // Creation Date : 07/19/02
    1628                 :            : //-------------------------------------------------------------------------
    1629                 :          0 : CompositeBody* CompositeEngine::replace_body( BodySM* body )
    1630                 :            : {
    1631         [ #  # ]:          0 :   DLIList<TopologyBridge*> lumps;
    1632                 :            :   int i;
    1633 [ #  # ][ #  # ]:          0 :   if( dynamic_cast<CompositeBody*>(body) )
                 [ #  # ]
    1634                 :          0 :     return 0;
    1635                 :            :   
    1636 [ #  # ][ #  # ]:          0 :   CompositeBody* compbody = new CompositeBody( );
    1637         [ #  # ]:          0 :   compbody->add(body);
    1638         [ #  # ]:          0 :   body->get_children( lumps, false, COMPOSITE_LAYER );
    1639         [ #  # ]:          0 :   lumps.reset();
    1640 [ #  # ][ #  # ]:          0 :   for( i = lumps.size();i--; )
    1641                 :            :   {
    1642 [ #  # ][ #  # ]:          0 :     Lump* lump = dynamic_cast<Lump*>(lumps.get_and_step());
    1643         [ #  # ]:          0 :     CompositeLump* complump = dynamic_cast<CompositeLump*>(lump);
    1644         [ #  # ]:          0 :     if( !complump )
    1645         [ #  # ]:          0 :       complump = replace_lump( lump );
    1646         [ #  # ]:          0 :     compbody->add( complump );
    1647                 :            :   }
    1648                 :            :   
    1649         [ #  # ]:          0 :   return compbody;
    1650                 :            : }
    1651                 :            : 
    1652                 :          0 : TBPoint* CompositeEngine::remove_composite( CompositePoint* composite )
    1653                 :            : {
    1654         [ #  # ]:          0 :   assert( composite->next_curve() == 0 );
    1655 [ #  # ][ #  # ]:          0 :   assert( !dynamic_cast<HiddenEntitySet*>(composite->owner()) );
    1656                 :          0 :   TBPoint* result = composite->get_point();
    1657         [ #  # ]:          0 :   delete composite;
    1658                 :          0 :   return result;
    1659                 :            : }
    1660                 :            : 
    1661                 :            : 
    1662                 :            : 
    1663                 :            : //-------------------------------------------------------------------------
    1664                 :            : // Purpose       : Reomve a 1-curve composite
    1665                 :            : //
    1666                 :            : // Special Notes : Inverse of replace_curve(..)
    1667                 :            : //
    1668                 :            : // Creator       : Jason Kraftcheck
    1669                 :            : //
    1670                 :            : // Creation Date : 03/13/02
    1671                 :            : //-------------------------------------------------------------------------
    1672                 :          0 : Curve* CompositeEngine::remove_composite( CompositeCurve* composite )
    1673                 :            : {
    1674 [ #  # ][ #  # ]:          0 :   assert( composite->num_curves() == 1 && 
         [ #  # ][ #  # ]
    1675                 :            :           !composite->has_parent_composite_surface() &&
    1676                 :            :           !dynamic_cast<HiddenEntitySet*>(composite->owner()) &&
    1677         [ #  # ]:          0 :           !composite->is_stitched() );
    1678                 :            : 
    1679                 :          0 :   CompositeCoEdge* coedge = 0;
    1680         [ #  # ]:          0 :   while( (coedge = composite->first_coedge()) )
    1681                 :            :   {
    1682 [ #  # ][ #  # ]:          0 :     assert( !coedge->get_loop() && coedge->num_coedges() == 1 );
    1683                 :          0 :     composite->remove( coedge );
    1684                 :          0 :     CoEdgeSM* real_coedge = coedge->get_coedge(0);
    1685                 :          0 :     coedge->remove_coedge( 0 );
    1686         [ #  # ]:          0 :     if( coedge->owner() )
    1687                 :          0 :       coedge->owner()->swap_bridge( coedge, real_coedge, false );
    1688         [ #  # ]:          0 :     delete coedge;
    1689                 :            :   }
    1690                 :            :   
    1691                 :          0 :   CompositePoint* sp = composite->start_point();
    1692                 :          0 :   CompositePoint* ep = composite->end_point();
    1693                 :          0 :   Curve* curve = composite->get_curve( 0 );
    1694                 :          0 :   bool reversed = composite->get_sense(0) == CUBIT_REVERSED;
    1695                 :          0 :   composite->remove_curve(0);
    1696         [ #  # ]:          0 :   if( composite->owner() )
    1697                 :          0 :     composite->owner()->swap_bridge( composite, curve, reversed );
    1698                 :            :  
    1699                 :          0 :   composite->start_point(0);
    1700                 :          0 :   composite->end_point(0);
    1701         [ #  # ]:          0 :   delete composite;
    1702                 :            :   
    1703         [ #  # ]:          0 :   if( ! sp->next_curve() )
    1704                 :          0 :     remove_composite(sp);
    1705 [ #  # ][ #  # ]:          0 :   if( ep != sp && !ep->next_curve() )
                 [ #  # ]
    1706                 :          0 :     remove_composite(ep);
    1707                 :            :   
    1708                 :            :   // we must notify the graphics of the modify from "real" to virtual -- KGM
    1709                 :            :   // I realize that this is not where the other notifies are completed but there
    1710                 :            :   // is no knowledge of the change later on. 
    1711         [ #  # ]:          0 :   CubitObservable* observable = dynamic_cast<CubitObservable*>(curve->topology_entity());
    1712         [ #  # ]:          0 :   if (observable)
    1713                 :            :   {
    1714 [ #  # ][ #  # ]:          0 :     AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::GEOMETRY_MODIFIED, dynamic_cast<RefEntity*>(curve->topology_entity())));
                 [ #  # ]
    1715                 :            :   }
    1716                 :            : 
    1717                 :          0 :   return curve;
    1718                 :            : }
    1719                 :            : 
    1720                 :            : 
    1721                 :            : //-------------------------------------------------------------------------
    1722                 :            : // Purpose       : Remove a 1-surface composite
    1723                 :            : //
    1724                 :            : // Special Notes : inverse of replace_surface(..)
    1725                 :            : //
    1726                 :            : // Creator       : Jason Kraftcheck
    1727                 :            : //
    1728                 :            : // Creation Date : 03/13/02
    1729                 :            : //-------------------------------------------------------------------------
    1730                 :          0 : Surface* CompositeEngine::remove_composite( CompositeSurface* composite )
    1731                 :            : {
    1732         [ #  # ]:          0 :   assert( ! composite->has_hidden_entities() );
    1733         [ #  # ]:          0 :   assert( composite->next_co_surface(0) == 0 );
    1734                 :            :   CompositeLoop* loop;
    1735                 :            :   CompositeCoEdge* coedge;
    1736                 :            :   CompositeCurve* curve;
    1737                 :            :   
    1738         [ #  # ]:          0 :   while( (loop = composite->first_loop()) )
    1739                 :            :   {
    1740                 :          0 :     composite->remove( loop );
    1741         [ #  # ]:          0 :     while( (coedge = loop->first_coedge()) )
    1742                 :            :     {
    1743                 :          0 :       loop->remove(coedge);
    1744                 :          0 :       curve = coedge->get_curve();
    1745 [ #  # ][ #  # ]:          0 :       if( curve->num_curves() == 1 &&
    1746 [ #  # ][ #  # ]:          0 :           !curve->has_parent_composite_surface() &&
    1747                 :          0 :           !curve->is_stitched()) 
    1748                 :          0 :         remove_composite(curve);
    1749                 :            :     }
    1750         [ #  # ]:          0 :     delete loop;
    1751                 :            :   }
    1752                 :            :   
    1753                 :          0 :   Surface* surface = composite->get_surface( 0 );
    1754                 :          0 :   bool reversed = composite->get_sense(0) == CUBIT_REVERSED;
    1755                 :          0 :   composite->remove_surface(0);
    1756         [ #  # ]:          0 :   if( composite->owner() )
    1757                 :          0 :     composite->owner()->swap_bridge( composite, surface, reversed );
    1758         [ #  # ]:          0 :   delete composite;
    1759                 :            :   
    1760                 :          0 :   return surface;
    1761                 :            : }
    1762                 :            : 
    1763                 :            : //-------------------------------------------------------------------------
    1764                 :            : // Purpose       : Remove a 1-lump composite
    1765                 :            : //
    1766                 :            : // Special Notes : inverse of replace_lump(..)
    1767                 :            : //
    1768                 :            : // Creator       : Jason Kraftcheck
    1769                 :            : //
    1770                 :            : // Creation Date : 07/19/02
    1771                 :            : //-------------------------------------------------------------------------
    1772                 :          0 : Lump* CompositeEngine::remove_composite( CompositeLump* composite )
    1773                 :            : {
    1774         [ #  # ]:          0 :   assert( composite->num_lumps() == 1 );
    1775         [ #  # ]:          0 :   assert( composite->get_body() == 0 );
    1776                 :            :   
    1777         [ #  # ]:          0 :   for( CompositeShell* shell = composite->first_shell();
    1778                 :            :        shell != 0;
    1779                 :            :        shell = composite->next_shell( shell ) )
    1780                 :            :   {
    1781                 :          0 :     composite->remove( shell );
    1782         [ #  # ]:          0 :     while( shell->first_co_surf() )
    1783                 :            :     {
    1784                 :          0 :       CompositeCoSurf* cos = shell->first_co_surf();
    1785                 :          0 :       CompositeSurface* surface = cos->get_surface();
    1786                 :          0 :       shell->remove( cos );
    1787                 :          0 :       surface->remove( cos );
    1788         [ #  # ]:          0 :       delete cos;
    1789                 :            :       
    1790   [ #  #  #  # ]:          0 :       if( surface->next_co_surface() == 0 &&
                 [ #  # ]
    1791                 :          0 :           !surface->has_hidden_entities() )
    1792                 :          0 :         remove_composite( surface );
    1793                 :            :     }
    1794         [ #  # ]:          0 :     delete shell;
    1795                 :            :   }
    1796                 :            :   
    1797                 :          0 :   Lump* result = composite->get_lump( 0 );
    1798                 :          0 :   composite->remove_bridge(result);
    1799         [ #  # ]:          0 :   if( composite->owner() )
    1800                 :          0 :     composite->owner()->swap_bridge( composite, result, false );
    1801         [ #  # ]:          0 :   delete composite;
    1802                 :            :   
    1803                 :          0 :   return result;
    1804                 :            : }
    1805                 :            : 
    1806                 :            : 
    1807                 :            : //-------------------------------------------------------------------------
    1808                 :            : // Purpose       : Remove a 1-body composite
    1809                 :            : //
    1810                 :            : // Special Notes : inverse of replace_body(..)
    1811                 :            : //
    1812                 :            : // Creator       : Jason Kraftcheck
    1813                 :            : //
    1814                 :            : // Creation Date : 07/19/02
    1815                 :            : //-------------------------------------------------------------------------
    1816                 :          0 : BodySM* CompositeEngine::remove_composite( CompositeBody* composite )
    1817                 :            : {
    1818         [ #  # ]:          0 :   assert( composite->num_bodies() == 1 );
    1819                 :            :   
    1820         [ #  # ]:          0 :   while( CompositeLump* lump = composite->next_lump() )
    1821                 :            :   {
    1822                 :          0 :     composite->remove( lump );
    1823                 :          0 :     remove_composite( lump );
    1824                 :            :   }
    1825                 :            :   
    1826                 :          0 :   BodySM* result = composite->get_body( 0 );
    1827                 :          0 :   composite->remove_bridge(result);
    1828         [ #  # ]:          0 :   if( composite->owner() )
    1829                 :          0 :     composite->owner()->swap_bridge( composite, result, false );
    1830         [ #  # ]:          0 :   delete composite;
    1831                 :            :   
    1832                 :          0 :   return result;
    1833                 :            : }
    1834                 :            : 
    1835                 :            :   
    1836                 :            : //-------------------------------------------------------------------------
    1837                 :            : // Purpose       : Combine two curves into a composite
    1838                 :            : //
    1839                 :            : // Special Notes : 
    1840                 :            : //
    1841                 :            : // Creator       : Jason Kraftcheck
    1842                 :            : //
    1843                 :            : // Creation Date : 03/13/02
    1844                 :            : //-------------------------------------------------------------------------
    1845                 :          0 : CompositeCurve* CompositeEngine::combine( CompositeCurve* keep, 
    1846                 :            :                                           CompositeCurve* dead,
    1847                 :            :                                           CompositePoint* keep_point,
    1848                 :            :                                           bool remove_partitions )
    1849                 :            : {
    1850 [ #  # ][ #  # ]:          0 :   if( keep->start_point() == keep->end_point() ||
         [ #  # ][ #  # ]
                 [ #  # ]
    1851 [ #  # ][ #  # ]:          0 :       dead->start_point() == dead->end_point() )
    1852                 :          0 :     return 0;
    1853                 :            :   
    1854                 :            :     // find the point to remove by compositing.
    1855         [ #  # ]:          0 :   CompositePoint* common = keep->common_point( dead );
    1856         [ #  # ]:          0 :   if (!common)
    1857                 :          0 :     return 0;
    1858                 :            :     
    1859 [ #  # ][ #  # ]:          0 :   if (keep_point && common == keep_point)
    1860                 :            :   {
    1861         [ #  # ]:          0 :     common = keep->other_point(common);
    1862 [ #  # ][ #  # ]:          0 :     if (dead->other_point(common) != keep_point)
    1863                 :          0 :       return 0;
    1864                 :            :   }
    1865                 :            :   
    1866         [ #  # ]:          0 :   bool prepend = (common == keep->start_point());
    1867         [ #  # ]:          0 :   bool reverse = ((common == dead->end_point()) != prepend);
    1868                 :            :   
    1869                 :            :     // Order coedges such that each coedge from the 
    1870                 :            :     // dead curve is grouped with the corresponding
    1871                 :            :     // coedge from the curve to be kept.
    1872 [ #  # ][ #  # ]:          0 :   DLIList<CompositeCoEdge*> dead_coedges, sorted_coedges;
                 [ #  # ]
    1873                 :            :   CompositeCoEdge* coedge;
    1874 [ #  # ][ #  # ]:          0 :   for( coedge = dead->first_coedge();
    1875                 :          0 :        coedge != 0;
    1876         [ #  # ]:          0 :        coedge = dead->next_coedge( coedge ) )
    1877         [ #  # ]:          0 :     dead_coedges.append( coedge );
    1878                 :            :   
    1879                 :          0 :   int keep_count = 0;
    1880                 :          0 :   CompositeCoEdge *keep_coedge = NULL;
    1881 [ #  # ][ #  # ]:          0 :   for( keep_coedge = keep->first_coedge();
                 [ #  # ]
    1882                 :            :        keep_coedge != 0;
    1883                 :            :        keep_coedge = keep->next_coedge( keep_coedge ) )
    1884                 :            :   {
    1885                 :          0 :     keep_count++;
    1886         [ #  # ]:          0 :     LoopSM* keep_loop = keep_coedge->get_parent_loop();
    1887         [ #  # ]:          0 :     CubitSense keep_sense = keep_coedge->sense();
    1888                 :            :     
    1889 [ #  # ][ #  # ]:          0 :     for( int j = dead_coedges.size(); j--;  )
    1890                 :            :     {
    1891         [ #  # ]:          0 :       CompositeCoEdge* dead_coedge = dead_coedges.step_and_get();
    1892 [ #  # ][ #  # ]:          0 :       if( dead_coedge->get_parent_loop() == keep_loop &&
         [ #  # ][ #  # ]
    1893         [ #  # ]:          0 :          (reverse == (keep_sense != dead_coedge->sense()) ) )
    1894                 :            :       {
    1895         [ #  # ]:          0 :         dead_coedges.extract();
    1896         [ #  # ]:          0 :         sorted_coedges.append( dead_coedge );
    1897                 :          0 :         break;
    1898                 :            :       }
    1899                 :            :     }
    1900                 :            :   }
    1901                 :            :   
    1902                 :            :     // If not all coedges were paired up, can't proceed.
    1903 [ #  # ][ #  # ]:          0 :   if( sorted_coedges.size() != keep_count )
    1904                 :          0 :     return 0;
    1905                 :            :   
    1906                 :            :     // If dead is reversed wrt keep, reverse it such that
    1907                 :            :     // both curves have the same relative sense.
    1908         [ #  # ]:          0 :   if( reverse )
    1909                 :            :   {
    1910         [ #  # ]:          0 :     dead->reverse();
    1911 [ #  # ][ #  # ]:          0 :     for( coedge = dead->first_coedge();
    1912                 :          0 :          coedge != 0;
    1913         [ #  # ]:          0 :          coedge = dead->next_coedge( coedge) )
    1914         [ #  # ]:          0 :       coedge->reverse();
    1915                 :            :   }
    1916                 :            :   
    1917                 :            :     // Combine the CoEdges
    1918         [ #  # ]:          0 :   sorted_coedges.reset();
    1919 [ #  # ][ #  # ]:          0 :   for ( keep_coedge = keep->first_coedge();
                 [ #  # ]
    1920                 :            :         keep_coedge != 0;
    1921                 :            :         keep_coedge = keep->next_coedge( keep_coedge ) )
    1922                 :            :   {
    1923         [ #  # ]:          0 :     CompositeCoEdge* dead_coedge = sorted_coedges.get_and_step();
    1924         [ #  # ]:          0 :     keep_coedge->combine( dead_coedge, prepend );
    1925                 :            :     
    1926 [ #  # ][ #  # ]:          0 :     if ( dead_coedge->owner() )
    1927 [ #  # ][ #  # ]:          0 :       dead_coedge->owner()->remove_bridge( dead_coedge );
    1928 [ #  # ][ #  # ]:          0 :     delete dead_coedge;
    1929                 :            :   }
    1930                 :            :   
    1931                 :            :   
    1932                 :            :     // hide point
    1933 [ #  # ][ #  # ]:          0 :   keep->hidden_entities().hide( common );
    1934                 :            :   
    1935                 :            :     // combine curves
    1936         [ #  # ]:          0 :   keep->combine( dead, prepend );
    1937         [ #  # ]:          0 :   if (prepend)
    1938 [ #  # ][ #  # ]:          0 :     keep->start_point( dead->other_point( common ) );
    1939                 :            :   else
    1940 [ #  # ][ #  # ]:          0 :     keep->end_point( dead->other_point( common ) );
    1941                 :            :   
    1942 [ #  # ][ #  # ]:          0 :   if (dead->owner())
    1943 [ #  # ][ #  # ]:          0 :     dead->owner()->remove_bridge(dead);
    1944         [ #  # ]:          0 :   dead->start_point(0);
    1945         [ #  # ]:          0 :   dead->end_point(0);
    1946 [ #  # ][ #  # ]:          0 :   delete dead;
    1947                 :            :   
    1948         [ #  # ]:          0 :   if( remove_partitions )
    1949         [ #  # ]:          0 :     remove_partition_point( common );
    1950                 :            :   
    1951         [ #  # ]:          0 :   return keep;
    1952                 :            : }
    1953                 :            : 
    1954                 :            : 
    1955                 :            : //-------------------------------------------------------------------------
    1956                 :            : // Purpose       : Restore hidden point 
    1957                 :            : //
    1958                 :            : // Special Notes : May create point-curve if point is hidden by a surface.
    1959                 :            : //
    1960                 :            : // Creator       : Jason Kraftcheck
    1961                 :            : //
    1962                 :            : // Creation Date : 02/27/04
    1963                 :            : //-------------------------------------------------------------------------
    1964                 :          0 : CubitStatus CompositeEngine::restore_point( TBPoint* point )
    1965                 :            : {
    1966                 :            :   HiddenEntitySet* set;
    1967                 :            :   
    1968         [ #  # ]:          0 :   CompositePoint* comp = dynamic_cast<CompositePoint*>(point);
    1969         [ #  # ]:          0 :   if (!comp)
    1970         [ #  # ]:          0 :     comp = dynamic_cast<CompositePoint*>(point->owner());
    1971         [ #  # ]:          0 :   if (!comp)
    1972                 :          0 :     return CUBIT_FAILURE;
    1973                 :            :   
    1974         [ #  # ]:          0 :   set = dynamic_cast<HiddenEntitySet*>(comp->owner());
    1975         [ #  # ]:          0 :   if (!set)
    1976                 :          0 :     return CUBIT_FAILURE;
    1977                 :            :   
    1978 [ #  # ][ #  # ]:          0 :   if (dynamic_cast<CompositeCurve*>(set->owner()))
                 [ #  # ]
    1979                 :            :   {
    1980                 :          0 :     point = comp->get_point();
    1981         [ #  # ]:          0 :     if (!restore_point_in_curve(comp))
    1982                 :          0 :       return CUBIT_FAILURE;
    1983                 :            :     
    1984                 :            :       // check if we still have a composite point
    1985                 :            :       // if this was the only point splitting the curve,
    1986                 :            :       // then the composite point will have been destroyed.
    1987         [ #  # ]:          0 :     comp = dynamic_cast<CompositePoint*>(point->owner());
    1988         [ #  # ]:          0 :     if (!comp)
    1989                 :          0 :       return CUBIT_SUCCESS;
    1990                 :            :     
    1991                 :            :       // If the point is no longer hidden, we're done.
    1992         [ #  # ]:          0 :     set = dynamic_cast<HiddenEntitySet*>(comp->owner());
    1993         [ #  # ]:          0 :     if (!set)
    1994                 :          0 :       return CUBIT_SUCCESS;
    1995                 :            :   }
    1996                 :            :   
    1997                 :            :     // Need to create point-curve?
    1998 [ #  # ][ #  # ]:          0 :   if (dynamic_cast<CompositeSurface*>(set->owner()))
                 [ #  # ]
    1999                 :            :   {
    2000         [ #  # ]:          0 :     if (!restore_point_in_surface(comp))
    2001                 :          0 :       return CUBIT_FAILURE;
    2002                 :            :     
    2003                 :            :       // If the point is no longer hidden, we're done.
    2004         [ #  # ]:          0 :     set = dynamic_cast<HiddenEntitySet*>(comp->owner());
    2005         [ #  # ]:          0 :     if (!set)
    2006                 :          0 :       return CUBIT_SUCCESS;
    2007                 :            :   }
    2008                 :            :   
    2009                 :            :     // Something went wrong.
    2010                 :          0 :   return CUBIT_FAILURE;
    2011                 :            : }
    2012                 :            :     
    2013                 :            : 
    2014                 :            : 
    2015                 :            : //-------------------------------------------------------------------------
    2016                 :            : // Purpose       : Restore a point removed when a curve was composited
    2017                 :            : //                 (split a composite point)
    2018                 :            : //
    2019                 :            : // Special Notes : 
    2020                 :            : //
    2021                 :            : // Creator       : Jason Kraftcheck
    2022                 :            : //
    2023                 :            : // Creation Date : 03/13/02
    2024                 :            : //-------------------------------------------------------------------------
    2025                 :          0 : CubitStatus CompositeEngine::restore_point_in_curve( TBPoint* point )
    2026                 :            : {
    2027                 :            :     // find CompositePoint
    2028         [ #  # ]:          0 :   CompositePoint* comppoint = dynamic_cast<CompositePoint*>(point);
    2029         [ #  # ]:          0 :   if( !comppoint )
    2030 [ #  # ][ #  # ]:          0 :     comppoint = dynamic_cast<CompositePoint*>(point->owner());
    2031         [ #  # ]:          0 :   if( !comppoint )
    2032                 :          0 :     return CUBIT_FAILURE;
    2033                 :            : 
    2034                 :            :   // find CompositeCurve.
    2035 [ #  # ][ #  # ]:          0 :   HiddenEntitySet* hs = dynamic_cast<HiddenEntitySet*>(comppoint->owner());
    2036         [ #  # ]:          0 :   if( !hs )
    2037                 :          0 :     return CUBIT_FAILURE;
    2038 [ #  # ][ #  # ]:          0 :   CompositeCurve* compcurve = dynamic_cast<CompositeCurve*>(hs->owner());
    2039         [ #  # ]:          0 :   if( !compcurve )
    2040                 :          0 :     return CUBIT_FAILURE;
    2041                 :            :   
    2042                 :            :     // find which curves in the composite contain the point
    2043         [ #  # ]:          0 :   DLIList<TopologyBridge*> points;
    2044                 :          0 :   int index = -1;
    2045 [ #  # ][ #  # ]:          0 :   for( int i = 0; i < compcurve->num_curves() && index < 0; i++ )
         [ #  # ][ #  # ]
    2046                 :            :   {
    2047         [ #  # ]:          0 :     Curve* curve = compcurve->get_curve(i);
    2048         [ #  # ]:          0 :     points.clean_out();
    2049         [ #  # ]:          0 :     curve->get_children( points, true, COMPOSITE_LAYER );
    2050 [ #  # ][ #  # ]:          0 :     for( int j = points.size(); j--; )
    2051                 :            :     {
    2052 [ #  # ][ #  # ]:          0 :       TBPoint* pt = dynamic_cast<TBPoint*>(points.get_and_step());
    2053         [ #  # ]:          0 :       assert( pt!= NULL );
    2054         [ #  # ]:          0 :       if( pt == comppoint )
    2055                 :            :       {
    2056                 :          0 :         index = i;
    2057                 :          0 :         break;
    2058                 :            :       }
    2059                 :            :     }
    2060                 :            :   }
    2061                 :            :   
    2062         [ #  # ]:          0 :   assert( index >= 0 );
    2063                 :            :   Curve *curve1, *curve2;
    2064 [ #  # ][ #  # ]:          0 :   return split( compcurve, index, curve1, curve2 );
    2065                 :            : }
    2066                 :            : 
    2067                 :            : 
    2068                 :            :   
    2069                 :            :   
    2070                 :            :   
    2071                 :            : 
    2072                 :            : //-------------------------------------------------------------------------
    2073                 :            : // Purpose       : Split a composite at the index-th point (after the
    2074                 :            : //                 index-th underlying curve)
    2075                 :            : //
    2076                 :            : // Special Notes : 
    2077                 :            : //
    2078                 :            : // Creator       : Jason Kraftcheck
    2079                 :            : //
    2080                 :            : // Creation Date : 03/13/02
    2081                 :            : //-------------------------------------------------------------------------
    2082                 :          0 : CubitStatus CompositeEngine::split( CompositeCurve* curve, int index,
    2083                 :            :                                     Curve*& result1, Curve*& result2 )
    2084                 :            : {
    2085                 :          0 :   result1 = result2 = 0;
    2086                 :            :   
    2087                 :            :     // Split the composite geometry
    2088 [ #  # ][ #  # ]:          0 :   CompositeCurve* new_curve = curve->split( curve->get_curve(index) );
    2089         [ #  # ]:          0 :   if( !new_curve )
    2090                 :          0 :     return CUBIT_FAILURE;
    2091 [ #  # ][ #  # ]:          0 :   HiddenEntitySet* ownerSet = dynamic_cast<HiddenEntitySet*>(curve->owner());
    2092         [ #  # ]:          0 :   if( ownerSet )
    2093         [ #  # ]:          0 :     ownerSet->hide(new_curve);
    2094                 :            :   
    2095                 :            :     // Split owning CoEdges
    2096 [ #  # ][ #  # ]:          0 :   for( CompositeCoEdge* old_coe = curve->first_coedge();
                 [ #  # ]
    2097                 :            :        old_coe != 0;
    2098                 :            :        old_coe = curve->next_coedge( old_coe ) )
    2099                 :            :   {
    2100         [ #  # ]:          0 :     CompositeCoEdge* new_coe = old_coe->split( index );
    2101         [ #  # ]:          0 :     assert( new_coe != NULL );
    2102         [ #  # ]:          0 :     new_curve->add( new_coe );
    2103         [ #  # ]:          0 :     if( ownerSet )
    2104         [ #  # ]:          0 :       ownerSet->hide(new_coe);
    2105                 :            :     
    2106 [ #  # ][ #  # ]:          0 :     if( old_coe->get_loop() )
    2107 [ #  # ][ #  # ]:          0 :         old_coe->get_loop()->insert_after( new_coe, old_coe );
    2108                 :            :   }
    2109                 :            :   
    2110                 :            :     // update end point of original curve
    2111         [ #  # ]:          0 :   DLIList<TopologyBridge*> children;
    2112         [ #  # ]:          0 :   int last = curve->num_curves() - 1;
    2113         [ #  # ]:          0 :   Curve* last_curve = curve->get_curve(last);
    2114         [ #  # ]:          0 :   children.clean_out();
    2115         [ #  # ]:          0 :   last_curve->get_children( children, true, COMPOSITE_LAYER );
    2116 [ #  # ][ #  # ]:          0 :   assert( children.size() == 2 );
    2117         [ #  # ]:          0 :   children.reset();
    2118 [ #  # ][ #  # ]:          0 :   if( curve->get_sense(last) == CUBIT_FORWARD )
    2119         [ #  # ]:          0 :     children.step();
    2120 [ #  # ][ #  # ]:          0 :   CompositePoint* endpt = dynamic_cast<CompositePoint*>(children.get());
    2121         [ #  # ]:          0 :   assert( !!endpt );
    2122         [ #  # ]:          0 :   CompositePoint* oldendpt = curve->end_point();
    2123         [ #  # ]:          0 :   curve->end_point( endpt );
    2124                 :            :   
    2125                 :            :     // attach start and end point to new curve
    2126         [ #  # ]:          0 :   children.clean_out();
    2127         [ #  # ]:          0 :   Curve* first_curve = new_curve->get_curve(0);
    2128         [ #  # ]:          0 :   first_curve->get_children( children, true, COMPOSITE_LAYER );
    2129 [ #  # ][ #  # ]:          0 :   assert( children.size() == 2 );
    2130         [ #  # ]:          0 :   children.reset();
    2131 [ #  # ][ #  # ]:          0 :   if( new_curve->get_sense(0) == CUBIT_REVERSED )
    2132         [ #  # ]:          0 :     children.step();
    2133 [ #  # ][ #  # ]:          0 :   CompositePoint* startpt = dynamic_cast<CompositePoint*>(children.get());
    2134         [ #  # ]:          0 :   assert( startpt!= NULL );
    2135         [ #  # ]:          0 :   new_curve->start_point( startpt );
    2136         [ #  # ]:          0 :   new_curve->end_point( oldendpt );
    2137                 :            : 
    2138                 :            :     // unhide restored (split) point
    2139         [ #  # ]:          0 :   HiddenEntitySet& old_hidden = curve->hidden_entities();
    2140 [ #  # ][ #  # ]:          0 :   old_hidden.restore( curve->end_point() );
    2141 [ #  # ][ #  # ]:          0 :   old_hidden.restore( new_curve->start_point() );
    2142         [ #  # ]:          0 :   if( ownerSet )
    2143                 :            :   {
    2144 [ #  # ][ #  # ]:          0 :     ownerSet->hide(curve->end_point());
    2145 [ #  # ][ #  # ]:          0 :     if(new_curve->start_point() != curve->end_point() )
                 [ #  # ]
    2146 [ #  # ][ #  # ]:          0 :       ownerSet->hide(new_curve->start_point());
    2147                 :            :   }
    2148                 :            :   
    2149                 :            :     // move other hidden points from old curve to new curve
    2150                 :            :     // as needed
    2151 [ #  # ][ #  # ]:          0 :   for( int j = 0; j < new_curve->num_curves(); j++ )
    2152                 :            :   {
    2153         [ #  # ]:          0 :     Curve* r_curve = new_curve->get_curve(j);
    2154         [ #  # ]:          0 :     children.clean_out();
    2155         [ #  # ]:          0 :     r_curve->get_children( children, true, COMPOSITE_LAYER );
    2156 [ #  # ][ #  # ]:          0 :     TBPoint* sp = dynamic_cast<TBPoint*>(children.get_and_step() );
    2157 [ #  # ][ #  # ]:          0 :     TBPoint* ep = dynamic_cast<TBPoint*>(children.get_and_step() );
    2158 [ #  # ][ #  # ]:          0 :     assert( sp && ep && sp != ep );
                 [ #  # ]
    2159 [ #  # ][ #  # ]:          0 :     if( old_hidden.restore( sp ) )
    2160 [ #  # ][ #  # ]:          0 :       new_curve->hidden_entities().hide( sp );
    2161 [ #  # ][ #  # ]:          0 :     if( old_hidden.restore( ep ) )
    2162 [ #  # ][ #  # ]:          0 :       new_curve->hidden_entities().hide( ep );
    2163                 :            :   }
    2164                 :            : 
    2165                 :            :     // Remove composite geometry if a 'composite' of one curve
    2166                 :          0 :   result1 = curve;
    2167                 :          0 :   result2 = new_curve;
    2168 [ #  # ][ #  # ]:          0 :   if( curve->num_curves() == 1 && !ownerSet &&
         [ #  # ][ #  # ]
                 [ #  # ]
    2169         [ #  # ]:          0 :       !curve->has_parent_composite_surface() )
    2170         [ #  # ]:          0 :     result1 = remove_composite( curve );
    2171 [ #  # ][ #  # ]:          0 :   if( new_curve->num_curves() == 1 && !ownerSet && 
         [ #  # ][ #  # ]
                 [ #  # ]
    2172         [ #  # ]:          0 :       !new_curve->has_parent_composite_surface() )
    2173         [ #  # ]:          0 :     result2 = remove_composite( new_curve );
    2174                 :            :     
    2175         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    2176                 :            : }
    2177                 :            : 
    2178                 :            : 
    2179                 :            : //-------------------------------------------------------------------------
    2180                 :            : // Purpose       : Create a composite surface by removing a curve
    2181                 :            : //
    2182                 :            : // Special Notes : 
    2183                 :            : //
    2184                 :            : // Creator       : Jason Kraftcheck
    2185                 :            : //
    2186                 :            : // Creation Date : 03/13/02
    2187                 :            : //-------------------------------------------------------------------------
    2188                 :          0 : CompositeSurface* CompositeEngine::remove_curve( Curve* dead_curve,
    2189                 :            :                                                  bool remove_partitions,
    2190                 :            :                                                  Surface* survivor )
    2191                 :            : {
    2192 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> temp, coedges, loops, surfaces, curves,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    2193 [ #  # ][ #  # ]:          0 :                            surf1_shells, surf2_shells;
         [ #  # ][ #  # ]
    2194                 :            :   
    2195 [ #  # ][ #  # ]:          0 :   if( dynamic_cast<CompositeCurve*>(dead_curve->owner()) )
         [ #  # ][ #  # ]
    2196 [ #  # ][ #  # ]:          0 :     dead_curve = dynamic_cast<Curve*>(dead_curve->owner());
    2197                 :            :   
    2198                 :            :     // If this is a null-geometry composite curve (a composite
    2199                 :            :     // point-curve without a corresponding real point-curve),
    2200                 :            :     // just destroy it and hide the defining point.
    2201         [ #  # ]:          0 :   CompositeCurve* compcurve = dynamic_cast<CompositeCurve*>(dead_curve);
    2202 [ #  # ][ #  # ]:          0 :   if (compcurve && compcurve->num_curves() == 0)
         [ #  # ][ #  # ]
    2203                 :            :   {
    2204 [ #  # ][ #  # ]:          0 :     CompositeSurface* surf = compcurve->first_coedge()->get_loop()->get_surface();
                 [ #  # ]
    2205         [ #  # ]:          0 :     CompositePoint* geom_pt = destroy_point_curve(compcurve);
    2206 [ #  # ][ #  # ]:          0 :     surf->hidden_entities().hide(geom_pt);
    2207                 :          0 :     return surf;
    2208                 :            :   }
    2209                 :            :   
    2210                 :            :     // Get two coedges to remove, and put curve(s) in 'curves'
    2211         [ #  # ]:          0 :   dead_curve->get_parents_virt( coedges );
    2212 [ #  # ][ #  # ]:          0 :   if( coedges.size() != 2 )  
    2213                 :          0 :     return 0;
    2214                 :            :   
    2215         [ #  # ]:          0 :   coedges.reset();
    2216         [ #  # ]:          0 :   TopologyBridge* coedge1 = coedges.get_and_step();
    2217         [ #  # ]:          0 :   TopologyBridge* coedge2 = coedges.get_and_step();
    2218                 :            :   
    2219                 :            :     // Get surfaces corresponding to loops
    2220         [ #  # ]:          0 :   loops.clean_out();
    2221         [ #  # ]:          0 :   coedge1->get_parents_virt( loops );
    2222 [ #  # ][ #  # ]:          0 :   assert( loops.size() == 1 );
    2223         [ #  # ]:          0 :   surfaces.clean_out();
    2224 [ #  # ][ #  # ]:          0 :   loops.get()->get_parents_virt( surfaces );
    2225 [ #  # ][ #  # ]:          0 :   assert( surfaces.size() == 1 );
    2226 [ #  # ][ #  # ]:          0 :   Surface* surface1 = dynamic_cast<Surface*>(surfaces.get());
    2227                 :            :   
    2228         [ #  # ]:          0 :   loops.clean_out();
    2229         [ #  # ]:          0 :   coedge2->get_parents_virt( loops );
    2230 [ #  # ][ #  # ]:          0 :   assert( loops.size() == 1 );
    2231         [ #  # ]:          0 :   surfaces.clean_out();
    2232 [ #  # ][ #  # ]:          0 :   loops.get()->get_parents_virt( surfaces );
    2233 [ #  # ][ #  # ]:          0 :   assert( surfaces.size() == 1 );
    2234 [ #  # ][ #  # ]:          0 :   Surface* surface2 = dynamic_cast<Surface*>(surfaces.get());
    2235                 :            :   
    2236         [ #  # ]:          0 :   if (surface2 == survivor)
    2237         [ #  # ]:          0 :     std::swap(surface1,surface2);
    2238                 :            :   
    2239                 :            :     // Make sure surfaces have same parent shells
    2240         [ #  # ]:          0 :   surface1->get_parents_virt( surf1_shells );
    2241         [ #  # ]:          0 :   surface2->get_parents_virt( surf2_shells );
    2242 [ #  # ][ #  # ]:          0 :   if( surf1_shells != surf2_shells )
    2243                 :          0 :     return 0;
    2244                 :            :   
    2245                 :            :     // get/make composites of surfaces
    2246         [ #  # ]:          0 :   CompositeSurface* compsurf1 = dynamic_cast<CompositeSurface*>(surface1);
    2247         [ #  # ]:          0 :   if( ! compsurf1 )
    2248                 :            :   {
    2249         [ #  # ]:          0 :     compsurf1 = replace_surface( surface1 );
    2250                 :            :   }
    2251                 :            :   
    2252                 :          0 :   CompositeSurface* compsurf2 = 0;
    2253         [ #  # ]:          0 :   if( surface2 == surface1 )
    2254                 :            :   {
    2255                 :          0 :     compsurf2 = compsurf1;
    2256                 :            :   }
    2257                 :            :   else
    2258                 :            :   {
    2259         [ #  # ]:          0 :     compsurf2 = dynamic_cast<CompositeSurface*>(surface2);
    2260         [ #  # ]:          0 :     if( !compsurf2 )
    2261                 :            :     {
    2262         [ #  # ]:          0 :       compsurf2 = replace_surface( surface2 );
    2263                 :            :     }
    2264                 :            :   }
    2265 [ #  # ][ #  # ]:          0 :   assert( compsurf1 && compsurf2 );
    2266                 :            :   
    2267                 :            :     // get composite(s) of curve(s)
    2268         [ #  # ]:          0 :   compcurve = dynamic_cast<CompositeCurve*>(dead_curve);
    2269         [ #  # ]:          0 :   if( !compcurve) 
    2270 [ #  # ][ #  # ]:          0 :     compcurve = dynamic_cast<CompositeCurve*>(dead_curve->owner());
    2271         [ #  # ]:          0 :   assert( !!compcurve );
    2272                 :            :   
    2273                 :            :     // Get composite coedges
    2274         [ #  # ]:          0 :   CompositeCoEdge *compcoedge1 = dynamic_cast<CompositeCoEdge*>(coedge1);
    2275         [ #  # ]:          0 :   if (!compcoedge1)
    2276 [ #  # ][ #  # ]:          0 :     compcoedge1 = dynamic_cast<CompositeCoEdge*>(coedge1->owner());
    2277         [ #  # ]:          0 :   CompositeCoEdge *compcoedge2 = dynamic_cast<CompositeCoEdge*>(coedge2);
    2278         [ #  # ]:          0 :   if (!compcoedge2)
    2279 [ #  # ][ #  # ]:          0 :     compcoedge2 = dynamic_cast<CompositeCoEdge*>(coedge2->owner());
    2280                 :            :   
    2281                 :            :     // combine the composite surfaces (not loops yet.)
    2282         [ #  # ]:          0 :   if( compsurf1 != compsurf2 )
    2283                 :            :   {
    2284                 :            :       // If second surface has opposite sense, fix it so
    2285                 :            :       // that both have the same sense.
    2286 [ #  # ][ #  # ]:          0 :     if( compcoedge2->sense() == compcoedge1->sense() )
                 [ #  # ]
    2287                 :            :     {
    2288                 :          0 :       bool b_reverse_coedges = true; // automatically handle reversing the coedges for the loop
    2289         [ #  # ]:          0 :       compsurf2->reverse_sense();
    2290 [ #  # ][ #  # ]:          0 :       for( CompositeLoop* loop = compsurf2->first_loop();
                 [ #  # ]
    2291                 :            :            loop != 0;
    2292                 :            :            loop = compsurf2->next_loop( loop ) )
    2293         [ #  # ]:          0 :         loop->reverse(b_reverse_coedges);
    2294                 :            :     }
    2295                 :            :     
    2296                 :            :       // Move all loops from old surface to new
    2297 [ #  # ][ #  # ]:          0 :     while( CompositeLoop* loop = compsurf2->first_loop() )
    2298                 :            :     {
    2299         [ #  # ]:          0 :       compsurf2->remove( loop );
    2300         [ #  # ]:          0 :       compsurf1->add( loop );
    2301                 :            :     }
    2302                 :            :     
    2303                 :            :       // Combine the set of underlying, real surfaces
    2304         [ #  # ]:          0 :     compsurf1->combine( compsurf2 );
    2305 [ #  # ][ #  # ]:          0 :     if( compsurf2->owner() )
    2306 [ #  # ][ #  # ]:          0 :       compsurf2->owner()->remove_bridge( compsurf2 );
    2307 [ #  # ][ #  # ]:          0 :     delete compsurf2;
    2308                 :          0 :     compsurf2 = 0;
    2309                 :            :   }
    2310                 :            :   
    2311         [ #  # ]:          0 :   CompositeLoop* loop1 = compcoedge1->get_loop();
    2312         [ #  # ]:          0 :   CompositeLoop* loop2 = compcoedge2->get_loop();
    2313                 :            : 
    2314                 :          0 :   bool split_loop = false;
    2315                 :            : 
    2316                 :            :     // same loop => remove sipe || split loop
    2317         [ #  # ]:          0 :   if( loop1 == loop2 ) 
    2318                 :            :   {
    2319                 :            :       // split loop
    2320 [ #  # ][ #  # ]:          0 :     if( loop1->next_coedge( compcoedge1 ) != compcoedge2 &&
         [ #  # ][ #  # ]
    2321         [ #  # ]:          0 :         loop1->prev_coedge( compcoedge1 ) != compcoedge2 )
    2322                 :            :     {
    2323                 :          0 :       split_loop = true;
    2324 [ #  # ][ #  # ]:          0 :       loop2 = new CompositeLoop();
    2325         [ #  # ]:          0 :       CompositeCoEdge* coedge = loop1->next_coedge( compcoedge1 );
    2326                 :          0 :       CompositeCoEdge* prev = 0;
    2327         [ #  # ]:          0 :       while( coedge != compcoedge2 )
    2328                 :            :       {
    2329         [ #  # ]:          0 :         loop1->remove( coedge );
    2330         [ #  # ]:          0 :         loop2->insert_after( coedge, prev );
    2331                 :          0 :         prev = coedge;
    2332         [ #  # ]:          0 :         coedge = loop1->next_coedge( compcoedge1 );
    2333                 :            :       }
    2334         [ #  # ]:          0 :       compsurf1->add( loop2 );
    2335                 :            :     }
    2336                 :            :       
    2337         [ #  # ]:          0 :     loop1->remove( compcoedge1 );
    2338         [ #  # ]:          0 :     loop1->remove( compcoedge2 );
    2339                 :            : 
    2340                 :            :     //if we have a merged surface, when we split the loop into two loops, 
    2341                 :            :     //we can end up with the original two loops in the same bridge manager
    2342                 :            : 
    2343 [ #  # ][ #  # ]:          0 :     if( split_loop && loop1->bridge_manager() && loop1->bridge_manager()->number_of_bridges() == 2 )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    2344                 :            :     {
    2345         [ #  # ]:          0 :       DLIList<TopologyBridge*> merged_loops;
    2346 [ #  # ][ #  # ]:          0 :       loop1->bridge_manager()->get_bridge_list( merged_loops );
    2347         [ #  # ]:          0 :       LoopSM *loop1 = static_cast<LoopSM*>(merged_loops[0]);
    2348         [ #  # ]:          0 :       LoopSM *loop2 = static_cast<LoopSM*>(merged_loops[1]);
    2349 [ #  # ][ #  # ]:          0 :       DLIList<CoEdgeSM*> coedges1, coedges2;
         [ #  # ][ #  # ]
    2350         [ #  # ]:          0 :       loop1->coedgesms( coedges1 );
    2351         [ #  # ]:          0 :       loop2->coedgesms( coedges2 );
    2352                 :            : 
    2353 [ #  # ][ #  # ]:          0 :       if( coedges1.size() == coedges2.size() )
                 [ #  # ]
    2354 [ #  # ][ #  # ]:          0 :         loop1->bridge_manager()->remove_bridge( merged_loops[1] );
         [ #  # ][ #  # ]
    2355                 :            :     }
    2356                 :            : 
    2357 [ #  # ][ #  # ]:          0 :     if( loop1->num_coedges() == 0 )
    2358                 :            :     {
    2359         [ #  # ]:          0 :       compsurf1->remove( loop1 );
    2360 [ #  # ][ #  # ]:          0 :       delete loop1;
    2361                 :            :     }
    2362                 :            :   }
    2363                 :            :     // stitch loops
    2364                 :            :   else 
    2365                 :            :   {
    2366                 :            :     CompositeCoEdge* coedge;
    2367                 :            :     
    2368                 :            :       // insert coedges
    2369 [ #  # ][ #  # ]:          0 :     while( loop2->num_coedges() > 1 )  // all but the dead one
    2370                 :            :     {
    2371         [ #  # ]:          0 :       coedge = loop2->next_coedge( compcoedge2 );
    2372         [ #  # ]:          0 :       loop2->remove( coedge );
    2373         [ #  # ]:          0 :       loop1->insert_before( coedge, compcoedge1 );
    2374                 :            :     }
    2375         [ #  # ]:          0 :     loop1->remove( compcoedge1 );
    2376         [ #  # ]:          0 :     loop2->remove( compcoedge2 );
    2377 [ #  # ][ #  # ]:          0 :     assert( loop2->num_coedges() == 0 );
    2378 [ #  # ][ #  # ]:          0 :     if( loop2->get_surface() )
    2379 [ #  # ][ #  # ]:          0 :       loop2->get_surface()->remove( loop2 );
    2380 [ #  # ][ #  # ]:          0 :     delete loop2;
    2381                 :            :     
    2382                 :            :       // If loops only had one coedge each, then we
    2383                 :            :       // just removed a hole.
    2384 [ #  # ][ #  # ]:          0 :     if( loop1->num_coedges() == 0 )
    2385                 :            :     {
    2386 [ #  # ][ #  # ]:          0 :       if( loop1->get_surface() )
    2387 [ #  # ][ #  # ]:          0 :         loop1->get_surface()->remove( loop1 );
    2388 [ #  # ][ #  # ]:          0 :       delete loop1;
    2389                 :            :     }
    2390                 :            :   }
    2391                 :            :   
    2392 [ #  # ][ #  # ]:          0 :   compsurf1->hidden_entities().hide( compcoedge1 );
    2393 [ #  # ][ #  # ]:          0 :   compsurf1->hidden_entities().hide( compcoedge2 );
    2394                 :            :   
    2395                 :            :     // clean up dead curve(s) and points
    2396         [ #  # ]:          0 :   curves.clean_out();
    2397 [ #  # ][ #  # ]:          0 :   compcurve->start_point()->get_parents_virt( curves );
    2398 [ #  # ][ #  # ]:          0 :   if( curves.size() == 1 )
    2399 [ #  # ][ #  # ]:          0 :     compsurf1->hidden_entities().hide( compcurve->start_point() );
                 [ #  # ]
    2400         [ #  # ]:          0 :   curves.clean_out();
    2401 [ #  # ][ #  # ]:          0 :   compcurve->end_point()->get_parents_virt( curves );
    2402 [ #  # ][ #  # ]:          0 :   if( curves.size() == 1 )
    2403 [ #  # ][ #  # ]:          0 :     compsurf1->hidden_entities().hide( compcurve->end_point() );
                 [ #  # ]
    2404 [ #  # ][ #  # ]:          0 :   compsurf1->hidden_entities().hide( compcurve );
    2405                 :            :   
    2406         [ #  # ]:          0 :   if( remove_partitions )
    2407         [ #  # ]:          0 :     remove_partition_curves( compcurve );
    2408                 :            :   
    2409         [ #  # ]:          0 :   return compsurf1;
    2410                 :            : }
    2411                 :            : 
    2412                 :            : 
    2413                 :          0 : static void cme_hide_surface( HiddenEntitySet& set,
    2414                 :            :                               CompositeSurface* surface )
    2415                 :            : {
    2416                 :          0 :   set.hide( surface );
    2417                 :          0 :   CompositeLoop* loop = 0;
    2418         [ #  # ]:          0 :   while (NULL != (loop = surface->next_loop( loop )))
    2419                 :            :   {
    2420                 :          0 :     set.hide( loop );
    2421                 :          0 :     CompositeCoEdge* coedge = loop->first_coedge();
    2422         [ #  # ]:          0 :     do {
    2423                 :          0 :       set.hide( coedge );
    2424                 :            :       
    2425                 :          0 :       bool hide_curve = true;
    2426                 :          0 :       CompositeCurve* curve = coedge->get_curve();
    2427                 :          0 :       CompositeCoEdge* curve_coedge = 0;
    2428         [ #  # ]:          0 :       while ((curve_coedge = curve->next_coedge( curve_coedge )))
    2429         [ #  # ]:          0 :         if (curve_coedge->owner() != &set)
    2430                 :          0 :           { hide_curve = false; break; }
    2431                 :            :       
    2432         [ #  # ]:          0 :       if (hide_curve)
    2433                 :            :       {
    2434                 :          0 :         set.hide( curve );
    2435         [ #  # ]:          0 :         int num_pts = 1 + (curve->start_point() == curve->end_point());
    2436         [ #  # ]:          0 :         for (int i = 0; i < num_pts; i++)
    2437                 :            :         {
    2438         [ #  # ]:          0 :           CompositePoint* pnt = i ? curve->end_point() : curve->start_point();
    2439                 :          0 :           bool hide_pnt = true;
    2440                 :          0 :           CompositeCurve* pnt_curve = 0;
    2441         [ #  # ]:          0 :           while ((pnt_curve = pnt->next_curve( pnt_curve )))
    2442         [ #  # ]:          0 :             if (pnt_curve->owner() != &set)
    2443                 :          0 :               { hide_pnt = false; break; }
    2444                 :            :           
    2445         [ #  # ]:          0 :           if (hide_pnt)
    2446                 :          0 :             set.hide( pnt );
    2447                 :            :         }
    2448                 :            :       }
    2449                 :          0 :     } while((coedge = loop->next_coedge(coedge)) != loop->first_coedge());
    2450                 :            :   }
    2451                 :          0 : }
    2452                 :            : 
    2453                 :          0 : static void cme_unhide_surface( CompositeSurface* surf )
    2454                 :            : {
    2455         [ #  # ]:          0 :   HiddenEntitySet* set = dynamic_cast<HiddenEntitySet*>(surf->owner());
    2456         [ #  # ]:          0 :   assert( !!set );
    2457                 :          0 :   set->restore( surf );
    2458                 :          0 :   CompositeLoop* loop = 0;
    2459         [ #  # ]:          0 :   while (NULL != (loop = surf->next_loop( loop )))
    2460                 :            :   {
    2461                 :          0 :     set->restore( loop );
    2462                 :          0 :     CompositeCoEdge* coedge = loop->first_coedge();
    2463         [ #  # ]:          0 :     do {
    2464         [ #  # ]:          0 :       if (coedge->owner() == set)
    2465                 :            :       {
    2466                 :          0 :         CompositeCurve* curve = coedge->get_curve();
    2467                 :          0 :         set->restore( coedge );
    2468                 :          0 :         set->restore( curve );
    2469         [ #  # ]:          0 :         if (curve->start_point()->owner() == set)
    2470                 :          0 :           set->restore( curve->start_point() );
    2471         [ #  # ]:          0 :         if (curve->end_point()->owner() == set)
    2472                 :          0 :           set->restore( curve->end_point() );
    2473                 :            :       }
    2474                 :          0 :     } while ((coedge = loop->next_coedge(coedge)) != loop->first_coedge());
    2475                 :            :   }
    2476                 :          0 : }
    2477                 :            :   
    2478                 :            : 
    2479                 :            : 
    2480                 :            : //-------------------------------------------------------------------------
    2481                 :            : // Purpose       : Create composite volume by removing a surface
    2482                 :            : //
    2483                 :            : // Special Notes : 
    2484                 :            : //
    2485                 :            : // Creator       : Jason Kraftcheck
    2486                 :            : //
    2487                 :            : // Creation Date : 06/10/04
    2488                 :            : //-------------------------------------------------------------------------
    2489                 :          0 : CompositeLump* CompositeEngine::remove_surface( Surface* dead_surf,
    2490                 :            :                                                 Surface* stitch_partner,
    2491                 :            :                                                 bool /*remove_partitions*/  )
    2492                 :            : {
    2493                 :          0 :   bool okay = true;
    2494                 :            :   Surface* sptr;
    2495 [ #  # ][ #  # ]:          0 :   if ((sptr = dynamic_cast<Surface*>(dead_surf->owner())))
                 [ #  # ]
    2496                 :          0 :     dead_surf = sptr;
    2497 [ #  # ][ #  # ]:          0 :   if ((sptr = dynamic_cast<Surface*>(stitch_partner->owner())))
                 [ #  # ]
    2498                 :          0 :     stitch_partner = sptr;
    2499                 :            :   
    2500                 :            :     // Get composite surfaces
    2501                 :          0 :   bool replaced_1 = false, replaced_2 = false;
    2502                 :          0 :   CompositeSurface *surf1 = 0, *surf2 = 0;
    2503 [ #  # ][ #  # ]:          0 :   if (NULL == (surf1 = dynamic_cast<CompositeSurface*>(dead_surf)))
    2504                 :            :   {
    2505         [ #  # ]:          0 :     surf1 = replace_surface( dead_surf );
    2506                 :          0 :     replaced_1 = true;
    2507                 :            :   }
    2508         [ #  # ]:          0 :   if (NULL == stitch_partner)
    2509                 :            :   {
    2510                 :          0 :     surf2 = surf1;
    2511                 :            :   }
    2512 [ #  # ][ #  # ]:          0 :   else if (NULL == (surf2 = dynamic_cast<CompositeSurface*>(stitch_partner)))
    2513                 :            :   {
    2514         [ #  # ]:          0 :     surf2 = replace_surface( stitch_partner );
    2515                 :          0 :     replaced_2 = true;
    2516                 :            :   }  
    2517                 :            :   
    2518                 :            :     // Check if surfaces are stitched
    2519         [ #  # ]:          0 :   if (surf2 != surf1)
    2520                 :            :   {
    2521         [ #  # ]:          0 :     std::set<CompositeLoop*> used_loops;
    2522                 :          0 :     CompositeLoop* loop = 0;
    2523 [ #  # ][ #  # ]:          0 :     while (NULL != (loop = surf1->next_loop(loop)))
    2524                 :            :     {
    2525         [ #  # ]:          0 :       CompositeCoEdge* coedge1 = loop->first_coedge();
    2526         [ #  # ]:          0 :       CompositeCurve* curve = coedge1->get_curve();
    2527                 :          0 :       CompositeCoEdge* coedge2 = 0;
    2528 [ #  # ][ #  # ]:          0 :       while (NULL != (coedge2 = curve->next_coedge(coedge2)))
    2529 [ #  # ][ #  # ]:          0 :         if (coedge2->get_loop() &&
         [ #  # ][ #  # ]
    2530 [ #  # ][ #  # ]:          0 :             coedge2->get_loop()->get_surface() == surf2)
    2531                 :          0 :           break;
    2532                 :            :       
    2533         [ #  # ]:          0 :       if (!coedge2) 
    2534                 :            :       {
    2535                 :          0 :         break;
    2536                 :            :         okay = false;
    2537                 :            :       }
    2538                 :            :       
    2539         [ #  # ]:          0 :       CompositeLoop* loop2 = coedge2->get_loop();
    2540 [ #  # ][ #  # ]:          0 :       if (used_loops.insert( loop2 ).second == false)
    2541                 :            :       {
    2542                 :          0 :         okay = false;
    2543                 :          0 :         break;
    2544                 :            :       }
    2545                 :            :       
    2546                 :          0 :       CompositeCoEdge* coedge = coedge1;
    2547 [ #  # ][ #  # ]:          0 :       while ((coedge = loop->next_coedge(coedge)) != coedge1)
    2548                 :            :       {
    2549         [ #  # ]:          0 :         curve = coedge->get_curve();
    2550                 :          0 :         coedge2 = 0;
    2551 [ #  # ][ #  # ]:          0 :         while (NULL != (coedge2 = curve->next_coedge(coedge2)))
    2552 [ #  # ][ #  # ]:          0 :           if (coedge2->get_loop() == loop2)
    2553                 :          0 :             break;
    2554                 :            :         
    2555         [ #  # ]:          0 :         if (!coedge2)
    2556                 :            :         {
    2557                 :          0 :           okay = false;
    2558                 :          0 :           break;
    2559                 :            :         }
    2560                 :            :       }
    2561                 :            :     }
    2562         [ #  # ]:          0 :     surf1->stitch( surf2 );
    2563                 :            :     
    2564         [ #  # ]:          0 :     if (!okay)
    2565                 :            :     {
    2566         [ #  # ]:          0 :       if (replaced_1)
    2567         [ #  # ]:          0 :         remove_composite( surf1 );
    2568         [ #  # ]:          0 :       if (replaced_2)
    2569         [ #  # ]:          0 :         remove_composite( surf2 );
    2570 [ #  # ][ #  # ]:          0 :       return 0;
    2571                 :          0 :     }
    2572                 :            :   }
    2573                 :            :   
    2574                 :            :     // Replace volumes/bodies with composites, combine bodies if necessary
    2575         [ #  # ]:          0 :   DLIList<BodySM*> body_list;
    2576         [ #  # ]:          0 :   surf1->bodysms( body_list );
    2577 [ #  # ][ #  # ]:          0 :   if (body_list.size() != 1)
    2578                 :          0 :     return 0;
    2579                 :            :   
    2580         [ #  # ]:          0 :   BodySM* body1 = body_list.pop();
    2581                 :          0 :   BodySM* body2 = 0;
    2582                 :          0 :   CompositeBody* body = 0;
    2583                 :            :   
    2584         [ #  # ]:          0 :   if (surf2)
    2585                 :            :   {
    2586         [ #  # ]:          0 :     surf2->bodysms( body_list );
    2587 [ #  # ][ #  # ]:          0 :     if (body_list.size() != 1)
    2588                 :          0 :       return 0;
    2589         [ #  # ]:          0 :     body2 = body_list.pop();
    2590                 :            :   }
    2591                 :            :   
    2592 [ #  # ][ #  # ]:          0 :   if (body2 && body2 != body1)
    2593                 :            :   {
    2594         [ #  # ]:          0 :     body = combine_bodies( body1, body2 );
    2595                 :            :   }
    2596                 :            :   else
    2597                 :            :   {
    2598 [ #  # ][ #  # ]:          0 :     if (NULL == (body = dynamic_cast<CompositeBody*>(body1)) &&
         [ #  # ][ #  # ]
    2599 [ #  # ][ #  # ]:          0 :         NULL == (body = dynamic_cast<CompositeBody*>(body1->owner())))
    2600                 :            :     {
    2601         [ #  # ]:          0 :       body = replace_body( body1 );
    2602                 :            :     }
    2603                 :            :   }
    2604                 :            :   
    2605         [ #  # ]:          0 :   if (!body)
    2606                 :          0 :     return 0;
    2607                 :            :   
    2608                 :            :     // Get CoSurfaces to combine must be exactly two of them.
    2609                 :          0 :   CompositeCoSurf *cosurf1 = 0, *cosurf2 = 0;
    2610         [ #  # ]:          0 :   cosurf1 = surf1->next_co_surface(NULL);
    2611         [ #  # ]:          0 :   cosurf2 = surf1->next_co_surface(cosurf1);
    2612         [ #  # ]:          0 :   if (!cosurf1)
    2613                 :            :   {
    2614                 :          0 :     okay = false;
    2615                 :            :   }
    2616         [ #  # ]:          0 :   else if (cosurf2)
    2617                 :            :   {
    2618 [ #  # ][ #  # ]:          0 :     if (surf2 || surf1->next_co_surface(cosurf2))
         [ #  # ][ #  # ]
    2619                 :          0 :       okay = false;
    2620                 :            :   }
    2621         [ #  # ]:          0 :   else if (surf2)
    2622                 :            :   {
    2623         [ #  # ]:          0 :     cosurf2 = surf2->next_co_surface(NULL);
    2624 [ #  # ][ #  # ]:          0 :     if (!cosurf2 || surf2->next_co_surface(cosurf2))
         [ #  # ][ #  # ]
    2625                 :          0 :       okay = false;
    2626                 :            :   }
    2627         [ #  # ]:          0 :   if (!okay)
    2628                 :            :   {
    2629                 :            : //    if (replaced_body)
    2630                 :            : //      restore_body( body );
    2631                 :          0 :     return 0;
    2632                 :            :   }
    2633                 :            :   
    2634                 :            :   
    2635                 :            :     // combine the composite lumps (not shells yet.)
    2636 [ #  # ][ #  # ]:          0 :   CompositeLump* lump1 = cosurf1->get_shell()->get_lump();
    2637 [ #  # ][ #  # ]:          0 :   CompositeLump* lump2 = cosurf2->get_shell()->get_lump();
    2638         [ #  # ]:          0 :   if( lump1 != lump2 )
    2639                 :            :   {
    2640                 :            :     
    2641                 :            :       // Move all shells from old lump to new
    2642 [ #  # ][ #  # ]:          0 :     while( CompositeShell* shell = lump2->first_shell() )
    2643                 :            :     {
    2644         [ #  # ]:          0 :       lump2->remove( shell );
    2645         [ #  # ]:          0 :       lump1->add( shell );
    2646                 :            :     }
    2647                 :            :     
    2648                 :            :       // Combine the set of underlying, real lumps
    2649         [ #  # ]:          0 :     lump1->combine( lump2 );
    2650 [ #  # ][ #  # ]:          0 :     if( lump2->owner() )
    2651 [ #  # ][ #  # ]:          0 :       lump2->owner()->remove_bridge( lump2 );
    2652         [ #  # ]:          0 :     body->remove(lump2);
    2653 [ #  # ][ #  # ]:          0 :     delete lump2;
    2654                 :          0 :     lump2 = 0;
    2655                 :            :   }
    2656                 :            :   
    2657                 :            :     // remove surface(s)
    2658         [ #  # ]:          0 :   CompositeShell* shell1 = cosurf1->get_shell();
    2659         [ #  # ]:          0 :   CompositeShell* shell2 = cosurf2->get_shell();
    2660 [ #  # ][ #  # ]:          0 :   cme_hide_surface( lump1->hidden_entities(), surf1 );
    2661         [ #  # ]:          0 :   if (surf2)
    2662 [ #  # ][ #  # ]:          0 :     cme_hide_surface( lump1->hidden_entities(), surf2 );
    2663 [ #  # ][ #  # ]:          0 :   delete cosurf1;
    2664 [ #  # ][ #  # ]:          0 :   delete cosurf2;
    2665                 :            : 
    2666         [ #  # ]:          0 :   if (shell1 != shell2)
    2667                 :            :   {
    2668 [ #  # ][ #  # ]:          0 :     while (CompositeCoSurf* cosurf = shell2->next_co_surf(0))
    2669                 :            :     {
    2670         [ #  # ]:          0 :       shell2->remove( cosurf );
    2671         [ #  # ]:          0 :       shell1->add( cosurf );
    2672                 :            :     }
    2673         [ #  # ]:          0 :     lump1->remove( shell2 );
    2674 [ #  # ][ #  # ]:          0 :     delete shell2;
    2675                 :            :   }
    2676                 :            :   else // if (shell1 == shell2)
    2677                 :            :   {
    2678         [ #  # ]:          0 :     shell2 = split_shell( shell1 );
    2679         [ #  # ]:          0 :     if (shell2)
    2680         [ #  # ]:          0 :       lump1->add( shell2 );
    2681                 :            :   }
    2682                 :            :   
    2683         [ #  # ]:          0 :   return lump1;
    2684                 :            : }
    2685                 :            : 
    2686                 :            : 
    2687                 :            : //-------------------------------------------------------------------------
    2688                 :            : // Purpose       : Test if a CompositeShell needs to be split, and
    2689                 :            : //                 split it
    2690                 :            : //
    2691                 :            : // Special Notes : Copied from PartitionEngine::split_shell
    2692                 :            : //
    2693                 :            : // Creator       : Jason Kraftcheck
    2694                 :            : //
    2695                 :            : // Creation Date : 06/11/04
    2696                 :            : //-------------------------------------------------------------------------
    2697                 :          0 : CompositeShell* CompositeEngine::split_shell( CompositeShell* shell_to_split )
    2698                 :            : {
    2699         [ #  # ]:          0 :   std::map<CompositeSurface*, int> marks;
    2700                 :            : 
    2701                 :            :     // Make sure all cosurface surface marks are cleared
    2702                 :          0 :   CompositeCoSurf* cosurf = 0;
    2703 [ #  # ][ #  # ]:          0 :   while( (cosurf = shell_to_split->next_co_surf( cosurf )) )
    2704 [ #  # ][ #  # ]:          0 :     marks[cosurf->get_surface()] = 0;
    2705                 :            :   
    2706                 :            :     // Identify non-manifold surfaces, marking them either
    2707                 :            :     // with a 2 if they can be used to split the volume
    2708                 :            :     // (if they are part of a connected patch for which the
    2709                 :            :     // bounadary of that patch intersects the volume boundary
    2710                 :            :     // at all curves) or a 3 if they are other non-manifold
    2711                 :            :     // surfaces.  This will get a bit tricky if there are
    2712                 :            :     // non-manifold surfaces hanging off of the patch of
    2713                 :            :     // split surfaces.
    2714                 :            :   
    2715                 :            :     // First for all non-manifold surfaces, if the surface has
    2716                 :            :     // a curve that is not shared with any other surface, mark
    2717                 :            :     // it with a 3.  Otherwise mark it with a 2.
    2718                 :          0 :   cosurf = 0;
    2719 [ #  # ][ #  # ]:          0 :   DLIList<CompositeSurface*> surf_stack;
    2720 [ #  # ][ #  # ]:          0 :   while ( (cosurf = shell_to_split->next_co_surf(cosurf)) )
    2721                 :            :   {
    2722         [ #  # ]:          0 :     CompositeSurface* surf = cosurf->get_surface();
    2723                 :            :       // If we haven't done this surface yet and it is non-manifold
    2724 [ #  # ][ #  # ]:          0 :     if ( !marks[surf] && surf->find_next(cosurf) )
         [ #  # ][ #  # ]
                 [ #  # ]
    2725                 :            :     {
    2726         [ #  # ]:          0 :       marks[surf] = 2;
    2727                 :          0 :       bool no_free_curve = true;
    2728                 :          0 :       CompositeLoop* loop = 0;
    2729 [ #  # ][ #  # ]:          0 :       while( no_free_curve && (loop = surf->next_loop(loop)) ) 
         [ #  # ][ #  # ]
    2730                 :            :       {
    2731         [ #  # ]:          0 :         CompositeCoEdge* coedge = loop->first_coedge();
    2732         [ #  # ]:          0 :         do 
    2733                 :            :         {
    2734         [ #  # ]:          0 :           CompositeCurve* curve = coedge->get_curve();
    2735                 :            :             // If the curve has more than one coedge, it 
    2736                 :            :             // is not a free curve (this also accounts for
    2737                 :            :             // the case where the curve is a non-manifold 
    2738                 :            :             // curve on the surface interioir -- e.g. a sipe)
    2739 [ #  # ][ #  # ]:          0 :           if ( !curve->next_coedge(coedge) && 
         [ #  # ][ #  # ]
    2740         [ #  # ]:          0 :                curve->next_coedge(0) == coedge )
    2741                 :            :           {
    2742                 :          0 :             no_free_curve = false;
    2743                 :          0 :             break;
    2744                 :            :           }
    2745         [ #  # ]:          0 :           coedge = loop->next_coedge(coedge);
    2746         [ #  # ]:          0 :         } while( coedge != loop->first_coedge() );
    2747                 :            :       }
    2748                 :            :       
    2749         [ #  # ]:          0 :       if( !no_free_curve )
    2750                 :            :       {
    2751         [ #  # ]:          0 :         marks[surf] = 3;
    2752         [ #  # ]:          0 :         surf_stack.append( surf );
    2753                 :            :       }
    2754                 :            :     }
    2755                 :            :   }
    2756                 :            :   
    2757                 :            :     // Now for each surface we marked with a three, traverse
    2758                 :            :     // and mark adjacent surfaces until we come to a curve
    2759                 :            :     // connected to more that two surfaces.
    2760 [ #  # ][ #  # ]:          0 :   while( surf_stack.size() ) 
    2761                 :            :   {
    2762         [ #  # ]:          0 :     CompositeSurface* surf = surf_stack.pop();
    2763                 :          0 :     CompositeLoop* loop = 0;
    2764 [ #  # ][ #  # ]:          0 :     while ( (loop = surf->next_loop(loop)) )
    2765                 :            :     {
    2766         [ #  # ]:          0 :       CompositeCoEdge* coedge = loop->first_coedge();
    2767         [ #  # ]:          0 :       do 
    2768                 :            :       {
    2769         [ #  # ]:          0 :         CompositeCurve* curve = coedge->get_curve();
    2770                 :          0 :         int split_count = 0;
    2771                 :          0 :         int boundary_count = 0;
    2772                 :          0 :         CompositeCoEdge* curve_coe = 0;
    2773 [ #  # ][ #  # ]:          0 :         while ( (curve_coe = curve->next_coedge(curve_coe) ) != NULL )
    2774                 :            :         {
    2775 [ #  # ][ #  # ]:          0 :           CompositeSurface* curve_surf = curve_coe->get_loop()->get_surface();
    2776         [ #  # ]:          0 :           switch ( marks[curve_surf] ) 
              [ #  #  # ]
    2777                 :            :           {
    2778                 :          0 :             case 0: boundary_count++; break;
    2779                 :          0 :             case 2: split_count++;    break;
    2780                 :            :           }
    2781                 :            :         }
    2782                 :            :         
    2783 [ #  # ][ #  # ]:          0 :         if ( split_count == 1 && !boundary_count )
    2784                 :            :         {
    2785                 :          0 :           curve_coe = 0;
    2786 [ #  # ][ #  # ]:          0 :           while ( (curve_coe = curve->next_coedge(curve_coe) ) != NULL )
    2787                 :            :           {
    2788 [ #  # ][ #  # ]:          0 :             CompositeSurface* curve_surf = curve_coe->get_loop()->get_surface();
    2789 [ #  # ][ #  # ]:          0 :             if ( marks[curve_surf] == 2 )
    2790                 :            :             {
    2791         [ #  # ]:          0 :               marks[curve_surf] = 3;
    2792         [ #  # ]:          0 :               surf_stack.append(curve_surf);
    2793                 :            :             }
    2794                 :            :           }
    2795                 :            :         }
    2796                 :            :         
    2797         [ #  # ]:          0 :         coedge = loop->next_coedge( coedge );
    2798         [ #  # ]:          0 :       } while( coedge != loop->first_coedge() );
    2799                 :            :     }
    2800                 :            :   }
    2801                 :            :   
    2802                 :            :     // Now build a new shell by traversing cofaces, marking
    2803                 :            :     // each with that will go in a new shell with a 1.
    2804                 :            :   
    2805                 :            :     // Start with any cosurf that does not have a free
    2806                 :            :     // non-manifold surface (marked with a 3).  We'll handle
    2807                 :            :     // free non-manifold surfaces later.
    2808         [ #  # ]:          0 :   std::set<CompositeCoSurf*> marked_cosurfs;
    2809 [ #  # ][ #  # ]:          0 :   DLIList<CompositeCoSurf*> cosurf_stack;
    2810                 :          0 :   cosurf = 0;
    2811 [ #  # ][ #  # ]:          0 :   while ( (cosurf = shell_to_split->next_co_surf(cosurf)) )
    2812 [ #  # ][ #  # ]:          0 :     if ( marks[cosurf->get_surface()] != 3 )
                 [ #  # ]
    2813                 :          0 :       break;
    2814         [ #  # ]:          0 :   if ( cosurf )
    2815                 :            :   {
    2816         [ #  # ]:          0 :     marked_cosurfs.insert(cosurf);
    2817         [ #  # ]:          0 :     cosurf_stack.append( cosurf );
    2818                 :            :   }
    2819                 :            :   
    2820                 :            :     // Traverse over adjacent cosurfaces, marking them with a 1
    2821 [ #  # ][ #  # ]:          0 :   while (cosurf_stack.size())
    2822                 :            :   {
    2823         [ #  # ]:          0 :     cosurf = cosurf_stack.pop();
    2824         [ #  # ]:          0 :     CompositeSurface* surf = cosurf->get_surface();
    2825                 :          0 :     CompositeLoop* loop = 0;
    2826 [ #  # ][ #  # ]:          0 :     while ( (loop = surf->next_loop(loop)) )
    2827                 :            :     {
    2828         [ #  # ]:          0 :       CompositeCoEdge* coedge = loop->first_coedge();
    2829         [ #  # ]:          0 :       do
    2830                 :            :       {
    2831         [ #  # ]:          0 :         CompositeCurve* curve = coedge->get_curve();
    2832                 :          0 :         CompositeCoEdge* curve_coe = 0;
    2833                 :          0 :         CompositeCoSurf *boundary_cosurf = 0, *split_cosurf = 0;
    2834                 :          0 :         int split_cosurf_count = 0;
    2835 [ #  # ][ #  # ]:          0 :         while ( (curve_coe = curve->next_coedge(curve_coe)) )
    2836                 :            :         {
    2837         [ #  # ]:          0 :           if ( curve_coe == coedge )
    2838                 :          0 :             continue;
    2839                 :            :           
    2840 [ #  # ][ #  # ]:          0 :           bool same_coe_sense = curve_coe->sense() == coedge->sense();
    2841 [ #  # ][ #  # ]:          0 :           CompositeSurface* curve_surf = curve_coe->get_loop()->get_surface();
    2842                 :          0 :           CompositeCoSurf* curve_cosurf = 0;
    2843 [ #  # ][ #  # ]:          0 :           while ( (curve_cosurf = curve_surf->next_co_surface(curve_cosurf)) )
    2844                 :            :           {
    2845 [ #  # ][ #  # ]:          0 :             if ( curve_cosurf->get_shell() != shell_to_split )
    2846                 :          0 :               continue;
    2847                 :            :             
    2848 [ #  # ][ #  # ]:          0 :             bool same_cos_sense = curve_cosurf->sense() == cosurf->sense();
    2849         [ #  # ]:          0 :             if ( same_cos_sense == same_coe_sense )
    2850                 :          0 :               continue;
    2851                 :            :             
    2852                 :            :               // Always choose split surface first if we
    2853                 :            :               // found one
    2854 [ #  # ][ #  # ]:          0 :             if ( marks[curve_cosurf->get_surface()] == 2 ) {
                 [ #  # ]
    2855                 :          0 :               split_cosurf_count++;
    2856                 :          0 :               split_cosurf = curve_cosurf;
    2857                 :            :             }
    2858                 :            :             
    2859                 :            :               // Skip other non-manifold surfaces.  We'll
    2860                 :            :               // handle those later.
    2861 [ #  # ][ #  # ]:          0 :             else if( marks[curve_cosurf->get_surface()] != 3 )
                 [ #  # ]
    2862                 :          0 :               boundary_cosurf = curve_cosurf;
    2863                 :            :           }
    2864                 :            :         }
    2865                 :            :         
    2866         [ #  # ]:          0 :         CompositeCoSurf* next_cosurf = split_cosurf ? split_cosurf : boundary_cosurf;
    2867 [ #  # ][ #  # ]:          0 :         if ( marked_cosurfs.find(next_cosurf) == marked_cosurfs.end()
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
    2868 [ #  # ][ #  # ]:          0 :              && split_cosurf_count < 2 )
    2869                 :            :         {
    2870         [ #  # ]:          0 :           marked_cosurfs.insert(next_cosurf);
    2871         [ #  # ]:          0 :           cosurf_stack.append(next_cosurf);
    2872                 :            :         }
    2873                 :            :       
    2874         [ #  # ]:          0 :         coedge = loop->next_coedge(coedge);
    2875         [ #  # ]:          0 :       } while( coedge != loop->first_coedge() );
    2876                 :            :     } // end while (loop)
    2877                 :            :   } // end while (cosurf_stack.size())
    2878                 :            :     
    2879                 :            :   
    2880                 :            :     // build lists of cosurfaces, one for each shell and
    2881                 :            :     // one of other non-manifold surfaces
    2882 [ #  # ][ #  # ]:          0 :   DLIList<CompositeCoSurf*> marked_list, unmarked_list, other_list;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2883 [ #  # ][ #  # ]:          0 :   while( (cosurf = shell_to_split->next_co_surf(0)) )
    2884                 :            :   {
    2885         [ #  # ]:          0 :     shell_to_split->remove(cosurf);
    2886 [ #  # ][ #  # ]:          0 :     if ( marks[cosurf->get_surface()] == 3 )
                 [ #  # ]
    2887         [ #  # ]:          0 :       other_list.append( cosurf );
    2888 [ #  # ][ #  # ]:          0 :     else if( marked_cosurfs.find(cosurf) != marked_cosurfs.end() )
         [ #  # ][ #  # ]
    2889         [ #  # ]:          0 :       marked_list.append( cosurf );
    2890                 :            :     else
    2891         [ #  # ]:          0 :       unmarked_list.append( cosurf );
    2892                 :            :   }
    2893                 :            :   
    2894                 :            :     // If one of marked_list or unmarked_list is empty,
    2895                 :            :     // we can't split the shell yet.  Put cofaces back in
    2896                 :            :     // shell and exit.
    2897 [ #  # ][ #  # ]:          0 :   if ( !marked_list.size() || !unmarked_list.size() )
         [ #  # ][ #  # ]
                 [ #  # ]
    2898                 :            :   {
    2899         [ #  # ]:          0 :     marked_list += unmarked_list;
    2900         [ #  # ]:          0 :     marked_list += other_list;
    2901         [ #  # ]:          0 :     marked_list.reverse();
    2902 [ #  # ][ #  # ]:          0 :     while ( marked_list.size() )
    2903                 :            :     {
    2904         [ #  # ]:          0 :       cosurf = marked_list.pop();
    2905         [ #  # ]:          0 :       shell_to_split->add( cosurf );
    2906                 :            :     }
    2907                 :          0 :     return 0;
    2908                 :            :   }
    2909                 :            :   
    2910                 :            :     // Put unmarked list back in old shell
    2911         [ #  # ]:          0 :   unmarked_list.reverse();
    2912 [ #  # ][ #  # ]:          0 :   while ( unmarked_list.size() )
    2913                 :            :   {
    2914         [ #  # ]:          0 :     cosurf = unmarked_list.pop();
    2915         [ #  # ]:          0 :     shell_to_split->add(cosurf);
    2916                 :            :   }
    2917                 :            :   
    2918                 :            :     // Put marked list in new shell
    2919 [ #  # ][ #  # ]:          0 :   CompositeShell* new_shell = new CompositeShell;
    2920         [ #  # ]:          0 :   marked_list.reverse();
    2921 [ #  # ][ #  # ]:          0 :   while ( marked_list.size() )
    2922                 :            :   {
    2923         [ #  # ]:          0 :     cosurf = marked_list.pop();
    2924         [ #  # ]:          0 :     new_shell->add(cosurf);
    2925                 :            :   }
    2926                 :            :   
    2927                 :            :     // Now sort out other non-manifold surfaces
    2928                 :            :   
    2929                 :            :     // Clear marks and get list of surface from cosurfaces
    2930         [ #  # ]:          0 :   surf_stack.clean_out();
    2931 [ #  # ][ #  # ]:          0 :   while( other_list.size() )
    2932                 :            :   {
    2933         [ #  # ]:          0 :     cosurf = other_list.pop();
    2934         [ #  # ]:          0 :     CompositeSurface* surf = cosurf->get_surface();
    2935 [ #  # ][ #  # ]:          0 :     if ( marks[surf] )
    2936         [ #  # ]:          0 :       surf_stack.append(surf);
    2937                 :            :   }
    2938                 :            :   
    2939         [ #  # ]:          0 :   insert_nonmanifold_surfaces( surf_stack, shell_to_split, new_shell );
    2940 [ #  # ][ #  # ]:          0 :   return new_shell;
    2941                 :            : }
    2942                 :            :  
    2943                 :            : //-------------------------------------------------------------------------
    2944                 :            : // Purpose       : After a shell is split, determine which of the two
    2945                 :            : //                 resulting shells each non-manifold surface belongs in.
    2946                 :            : //
    2947                 :            : // Special Notes : Copied from PartitionEngine::insert_nonmanifold_surfaces
    2948                 :            : //
    2949                 :            : // Creator       : Jason Kraftcheck
    2950                 :            : //
    2951                 :            : // Creation Date : 06/11/04
    2952                 :            : //-------------------------------------------------------------------------
    2953                 :          0 : void CompositeEngine::insert_nonmanifold_surfaces( 
    2954                 :            :                                    DLIList<CompositeSurface*>& surf_stack,
    2955                 :            :                                    CompositeShell* shell1,
    2956                 :            :                                    CompositeShell* shell2 )
    2957                 :            : {
    2958 [ #  # ][ #  # ]:          0 :   DLIList<CompositeSurface*> known_list(surf_stack.size()), 
    2959 [ #  # ][ #  # ]:          0 :                            unknown_list(surf_stack.size());
                 [ #  # ]
    2960                 :            :   
    2961                 :            :   CompositeCoSurf* cosurf;
    2962                 :            :   CompositeSurface* surf;
    2963                 :            :   CompositeLoop* loop;
    2964                 :            :   CompositeCoEdge *coedge, *curve_coe;
    2965                 :            :   CompositeCurve* curve;
    2966                 :            :   
    2967                 :            :     // Loop until we've placed all the surfaces in one
    2968                 :            :     // shell or the other.
    2969 [ #  # ][ #  # ]:          0 :   while ( surf_stack.size() )
    2970                 :            :   {
    2971                 :          0 :     bool did_some = false;
    2972                 :            :     
    2973                 :            :       // Put any surfaces for which we immediately
    2974                 :            :       // know the shell into the appropriate shell.
    2975                 :            :       // Put others in known_list or unknown_list
    2976                 :            :       // depending on if we can determine which shell
    2977                 :            :       // they go in using a geometric comparison.
    2978         [ #  # ]:          0 :     known_list.clean_out();
    2979         [ #  # ]:          0 :     unknown_list.clean_out();
    2980                 :            : 
    2981                 :            :       // Take all surfaces out of stack in this loop.
    2982                 :            :       // We might put some back in after the loop (thus
    2983                 :            :       // the outer loop.)
    2984 [ #  # ][ #  # ]:          0 :     while ( surf_stack.size() )
    2985                 :            :     {
    2986         [ #  # ]:          0 :       surf = surf_stack.pop();
    2987                 :            :       
    2988                 :          0 :       CompositeShell* known_shell = 0;
    2989                 :          0 :       bool found_shell = false;
    2990                 :          0 :       loop = 0;
    2991 [ #  # ][ #  # ]:          0 :       while ( (loop = surf->next_loop(loop)) )
    2992                 :            :       {
    2993         [ #  # ]:          0 :         coedge = loop->first_coedge();
    2994         [ #  # ]:          0 :         do
    2995                 :            :         {
    2996         [ #  # ]:          0 :           curve = coedge->get_curve();
    2997                 :          0 :           curve_coe = 0;
    2998 [ #  # ][ #  # ]:          0 :           while ( (curve_coe = curve->next_coedge(curve_coe)) )
    2999                 :            :           {
    3000 [ #  # ][ #  # ]:          0 :             CompositeSurface* surf = curve_coe->get_loop()->get_surface();
    3001                 :          0 :             cosurf = 0;
    3002 [ #  # ][ #  # ]:          0 :             while ( (cosurf = surf->next_co_surface( cosurf )) )
    3003                 :            :             {
    3004 [ #  # ][ #  # ]:          0 :               if( cosurf->get_shell() == shell1 ||
         [ #  # ][ #  # ]
    3005         [ #  # ]:          0 :                   cosurf->get_shell() == shell2 )
    3006                 :            :               {
    3007                 :          0 :                 found_shell = true;
    3008 [ #  # ][ #  # ]:          0 :                 if ( known_shell && known_shell != cosurf->get_shell() )
         [ #  # ][ #  # ]
    3009                 :          0 :                   known_shell = 0;
    3010                 :            :                 else
    3011         [ #  # ]:          0 :                   known_shell = cosurf->get_shell();
    3012                 :            :               }
    3013                 :            :             }
    3014                 :            :           }
    3015                 :            :         
    3016         [ #  # ]:          0 :           coedge = loop->next_coedge(coedge);
    3017         [ #  # ]:          0 :         } while( coedge != loop->first_coedge() );
    3018                 :            :       } // end while(loop)
    3019                 :            :         
    3020                 :            :         // This surface does not intersect the shell at
    3021                 :            :         // any curve.  We can't do this one yet.
    3022         [ #  # ]:          0 :       if ( !found_shell )
    3023                 :            :       {
    3024         [ #  # ]:          0 :         unknown_list.append( surf );
    3025                 :          0 :         continue;
    3026                 :            :       }
    3027                 :            :       
    3028                 :            :         // This surface intersected both shells at some
    3029                 :            :         // curves, but did not have a curve that intersected
    3030                 :            :         // only one shell.  We can do this one geometricly
    3031                 :            :         // if we have to.
    3032         [ #  # ]:          0 :       if ( !known_shell )
    3033                 :            :       {
    3034         [ #  # ]:          0 :         known_list.append( surf );
    3035                 :          0 :         continue;
    3036                 :            :       }
    3037                 :            :       
    3038                 :            :         // If we got this far, then the surface had at least
    3039                 :            :         // one curve that intersected only one of the shells.
    3040                 :            :         // We know it goes in that shell.
    3041                 :          0 :       did_some = true;
    3042         [ #  # ]:          0 :       CompositeCoSurf* cosurf1 = surf->find_first((CompositeShell*)0);
    3043         [ #  # ]:          0 :       CompositeCoSurf* cosurf2 = surf->find_next(cosurf1);
    3044         [ #  # ]:          0 :       known_shell->add(cosurf1);
    3045         [ #  # ]:          0 :       known_shell->add(cosurf2);
    3046                 :            :     
    3047                 :            :     } // while(surf_stack)  -- the inside one
    3048                 :            :     
    3049                 :            :       // Unknown_list always goes back in surf_stack to
    3050                 :            :       // try again.
    3051         [ #  # ]:          0 :     surf_stack += unknown_list;
    3052                 :            :     
    3053                 :            :       // If we did some surfaces, then put the rest back
    3054                 :            :       // in surf_stack and try again.  If they intersect
    3055                 :            :       // one of the surfaces we did place in this iteration,
    3056                 :            :       // we can avoid needing to do geometric checks.
    3057         [ #  # ]:          0 :     if ( did_some )
    3058                 :            :     {
    3059         [ #  # ]:          0 :       surf_stack += known_list;
    3060                 :          0 :       continue;
    3061                 :            :     }
    3062                 :            :     
    3063                 :            :       // If known_list is empty, somethings wrong (we're
    3064                 :            :       // going to loop forever.)  Abort the loop and try
    3065                 :            :       // to recover as best we can.
    3066 [ #  # ][ #  # ]:          0 :     if( !known_list.size() )
    3067                 :          0 :       break;
    3068                 :            :     
    3069                 :            :       // choose a single surface in do a geometric comparison
    3070                 :            :       // for, and put the rest back in surf_stack
    3071         [ #  # ]:          0 :     surf = known_list.pop();
    3072         [ #  # ]:          0 :     surf_stack += known_list;
    3073                 :            :     
    3074                 :          0 :     bool in_shell = false;
    3075 [ #  # ][ #  # ]:          0 :     if ( ! inside_shell( shell2, surf, in_shell ) )
    3076                 :            :     {
    3077                 :            :         // if inside_shell failed, abort.
    3078         [ #  # ]:          0 :       surf_stack.append(surf);
    3079                 :          0 :       break;
    3080                 :            :     }
    3081                 :            :     
    3082         [ #  # ]:          0 :     CompositeShell* shell = in_shell ? shell2 : shell1;
    3083 [ #  # ][ #  # ]:          0 :     shell->add(surf->find_first((CompositeShell*)0));
    3084 [ #  # ][ #  # ]:          0 :     shell->add(surf->find_first((CompositeShell*)0));
    3085                 :            :   }
    3086                 :            :   
    3087                 :            :     // something went wrong
    3088 [ #  # ][ #  # ]:          0 :   if( surf_stack.size() )
    3089                 :            :   {
    3090 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Internal error splitting volume at %s:%d\n"
                 [ #  # ]
    3091                 :            :                 "Topology may be invalid.  Please report this.\n",
    3092         [ #  # ]:          0 :                 __FILE__, __LINE__);
    3093 [ #  # ][ #  # ]:          0 :     while( surf_stack.size() ) 
    3094                 :            :     {
    3095         [ #  # ]:          0 :       CompositeSurface* surf = surf_stack.pop();
    3096                 :          0 :       cosurf = 0;
    3097 [ #  # ][ #  # ]:          0 :       while( (cosurf = surf->next_co_surface(cosurf)) )
    3098 [ #  # ][ #  # ]:          0 :         if( !cosurf->get_shell() )
    3099         [ #  # ]:          0 :           shell1->add(cosurf);
    3100                 :            :     }
    3101         [ #  # ]:          0 :   }
    3102                 :          0 : }
    3103                 :            : 
    3104                 :            : 
    3105                 :          0 : CubitStatus CompositeEngine::inside_shell( CompositeShell* const shell,
    3106                 :            :                                            CompositeSurface* const surf,
    3107                 :            :                                            bool& result )
    3108                 :            : {
    3109                 :            :     // Find the curve and coedge at which the nonmanifold surface
    3110                 :            :     // intersects the shells
    3111                 :          0 :   CompositeLoop* loop = 0;
    3112                 :          0 :   CompositeCoEdge *nonman_coedge = 0;
    3113 [ #  # ][ #  # ]:          0 :   while ( !nonman_coedge && (loop = surf->next_loop(loop)) )
         [ #  # ][ #  # ]
    3114                 :            :   {
    3115         [ #  # ]:          0 :     CompositeCoEdge* loop_coedge = loop->first_coedge();
    3116         [ #  # ]:          0 :     do 
    3117                 :            :     {
    3118                 :            :         // Check if this curve is the curve of intersection
    3119                 :            :         // Iterate through curve coedges.
    3120         [ #  # ]:          0 :       CompositeCurve* curve = loop_coedge->get_curve();
    3121                 :          0 :       CompositeCoEdge* curve_coedge = 0;
    3122 [ #  # ][ #  # ]:          0 :       while ( (curve_coedge = curve->next_coedge(curve_coedge)) )
    3123                 :            :       {
    3124                 :            :         
    3125 [ #  # ][ #  # ]:          0 :         CompositeSurface* coedge_surf = curve_coedge->get_loop()->get_surface();
    3126 [ #  # ][ #  # ]:          0 :         if( coedge_surf->find_first(shell) )
    3127                 :            :         {
    3128                 :          0 :           nonman_coedge = curve_coedge;
    3129                 :          0 :           break;
    3130                 :            :         }
    3131                 :            :       }
    3132                 :            :     
    3133         [ #  # ]:          0 :       loop_coedge = loop->next_coedge(loop_coedge);
    3134 [ #  # ][ #  # ]:          0 :     } while( !nonman_coedge && loop_coedge != loop->first_coedge() );
                 [ #  # ]
    3135                 :            :   }
    3136                 :            :   
    3137         [ #  # ]:          0 :   if ( !nonman_coedge ) // bad input!
    3138                 :          0 :     return CUBIT_FAILURE;
    3139                 :            : 
    3140                 :            :     // There must exist two surfaces in the shell that are manifold 
    3141                 :            :     // in the shell and that are adjacent to the curve
    3142         [ #  # ]:          0 :   CompositeCurve* common_curve = nonman_coedge->get_curve();
    3143                 :          0 :   CompositeCoSurf *cosurf1 = 0, *cosurf2 = 0, *cosurf;
    3144                 :          0 :   CompositeCoEdge *coedge1 = 0, *coedge2 = 0, *coedge = 0;
    3145 [ #  # ][ #  # ]:          0 :   while ( (coedge = common_curve->next_coedge(coedge)) )
    3146                 :            :   {
    3147 [ #  # ][ #  # ]:          0 :     CompositeSurface* surf = coedge->get_loop()->get_surface();
    3148 [ #  # ][ #  # ]:          0 :     if ( (cosurf = surf->find_first(shell)) && !surf->find_next(cosurf) )
         [ #  # ][ #  # ]
                 [ #  # ]
    3149                 :            :     {
    3150         [ #  # ]:          0 :       if( coedge1 ) {
    3151                 :          0 :         coedge2 = coedge;
    3152                 :          0 :         cosurf2 = cosurf;
    3153                 :            :       } else {
    3154                 :          0 :         coedge1 = coedge;
    3155                 :          0 :         cosurf1 = cosurf;
    3156                 :            :       }
    3157                 :            :     }
    3158                 :            :   }
    3159 [ #  # ][ #  # ]:          0 :   if ( !coedge1 || !coedge2 )
    3160                 :          0 :     return CUBIT_FAILURE;
    3161                 :            :   
    3162                 :            :     // Evaluate normals at midpoint of curve
    3163 [ #  # ][ #  # ]:          0 :   CubitVector base, tangent, point;
                 [ #  # ]
    3164 [ #  # ][ #  # ]:          0 :   double u = (common_curve->start_param()+common_curve->end_param())/2.0;
    3165         [ #  # ]:          0 :   common_curve->position_from_u( u, base );
    3166         [ #  # ]:          0 :   common_curve->closest_point( base, point, &tangent );
    3167         [ #  # ]:          0 :   tangent.normalize();
    3168                 :            :   
    3169 [ #  # ][ #  # ]:          0 :   CubitVector normal1, normal2, normal;
                 [ #  # ]
    3170         [ #  # ]:          0 :   surf->closest_point( base, 0, &normal );
    3171 [ #  # ][ #  # ]:          0 :   cosurf1->get_surface()->closest_point( base, 0, &normal1 );
    3172 [ #  # ][ #  # ]:          0 :   cosurf2->get_surface()->closest_point( base, 0, &normal2 );
    3173                 :            :   
    3174                 :            :     // Try to handle tangencies
    3175 [ #  # ][ #  # ]:          0 :   bool fix1 = (normal1 * normal).length_squared() < CUBIT_RESABS;
    3176 [ #  # ][ #  # ]:          0 :   bool fix2 = (normal2 * normal).length_squared() < CUBIT_RESABS;
    3177 [ #  # ][ #  # ]:          0 :   if ( fix1 || fix2 )
    3178                 :            :   {
    3179         [ #  # ]:          0 :     CubitVector dir = tangent * normal;
    3180         [ #  # ]:          0 :     double len = dir.length();
    3181         [ #  # ]:          0 :     assert(len > GEOMETRY_RESABS);
    3182         [ #  # ]:          0 :     dir /= len;
    3183 [ #  # ][ #  # ]:          0 :     if ( nonman_coedge->sense() == CUBIT_FORWARD )
    3184 [ #  # ][ #  # ]:          0 :       dir = -dir;
    3185                 :            :       
    3186 [ #  # ][ #  # ]:          0 :     CubitVector diag = surf->bounding_box().diagonal();
                 [ #  # ]
    3187         [ #  # ]:          0 :     if ( fix1 )
    3188                 :            :     {
    3189 [ #  # ][ #  # ]:          0 :       CubitVector d = cosurf1->get_surface()->bounding_box().diagonal();
         [ #  # ][ #  # ]
    3190 [ #  # ][ #  # ]:          0 :       if ( diag.x() < d.x() ) diag.x(d.x());
         [ #  # ][ #  # ]
                 [ #  # ]
    3191 [ #  # ][ #  # ]:          0 :       if ( diag.y() < d.y() ) diag.y(d.y());
         [ #  # ][ #  # ]
                 [ #  # ]
    3192 [ #  # ][ #  # ]:          0 :       if ( diag.z() < d.z() ) diag.z(d.z());
         [ #  # ][ #  # ]
                 [ #  # ]
    3193                 :            :     }
    3194         [ #  # ]:          0 :     if( fix2 )
    3195                 :            :     {
    3196 [ #  # ][ #  # ]:          0 :       CubitVector d = cosurf2->get_surface()->bounding_box().diagonal();
         [ #  # ][ #  # ]
    3197 [ #  # ][ #  # ]:          0 :       if ( diag.x() < d.x() ) diag.x(d.x());
         [ #  # ][ #  # ]
                 [ #  # ]
    3198 [ #  # ][ #  # ]:          0 :       if ( diag.y() < d.y() ) diag.y(d.y());
         [ #  # ][ #  # ]
                 [ #  # ]
    3199 [ #  # ][ #  # ]:          0 :       if ( diag.z() < d.z() ) diag.z(d.z());
         [ #  # ][ #  # ]
                 [ #  # ]
    3200                 :            :     }
    3201                 :            :     
    3202         [ #  # ]:          0 :     double step = 1e-3 * fabs( diag % dir );
    3203         [ #  # ]:          0 :     if ( step < 2*GEOMETRY_RESABS )
    3204                 :          0 :       step = 2*GEOMETRY_RESABS;
    3205                 :            :     
    3206         [ #  # ]:          0 :     for ( int i = 0; i < 1000; i++ )
    3207                 :            :     {
    3208 [ #  # ][ #  # ]:          0 :       point = base + i * step * dir;
                 [ #  # ]
    3209         [ #  # ]:          0 :       surf->closest_point( base, 0, &normal );
    3210         [ #  # ]:          0 :       if( fix1 )
    3211 [ #  # ][ #  # ]:          0 :         cosurf1->get_surface()->closest_point( base, 0, &normal1 );
    3212         [ #  # ]:          0 :       if( fix2 )
    3213 [ #  # ][ #  # ]:          0 :         cosurf2->get_surface()->closest_point( base, 0, &normal2 );
    3214                 :            :       
    3215 [ #  # ][ #  # ]:          0 :       bool done1 = !fix1 || (normal1 * normal).length_squared() > CUBIT_RESABS;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3216 [ #  # ][ #  # ]:          0 :       bool done2 = !fix2 || (normal2 * normal).length_squared() > CUBIT_RESABS;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3217 [ #  # ][ #  # ]:          0 :       if ( done1 && done2 )
    3218                 :            :       {
    3219                 :          0 :         fix1 = fix2 = false;
    3220                 :          0 :         break;
    3221                 :            :       }
    3222                 :            :     }
    3223                 :            :   }
    3224                 :            :   
    3225 [ #  # ][ #  # ]:          0 :   if ( fix1 || fix2 )
    3226                 :            :   {
    3227 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Failed to adjust for surface tangencies.\n"
                 [ #  # ]
    3228         [ #  # ]:          0 :                 "This is a BUG.  %s:%d\n", __FILE__, __LINE__ );
    3229                 :          0 :     return CUBIT_FAILURE;
    3230                 :            :   }
    3231                 :            :   
    3232 [ #  # ][ #  # ]:          0 :   if ( nonman_coedge->sense() == CUBIT_FORWARD )
    3233 [ #  # ][ #  # ]:          0 :     normal = -normal;
    3234 [ #  # ][ #  # ]:          0 :   if ( cosurf1->sense() == coedge1->sense() )
                 [ #  # ]
    3235 [ #  # ][ #  # ]:          0 :     normal1 = -normal1;
    3236 [ #  # ][ #  # ]:          0 :   if ( cosurf2->sense() == coedge2->sense() )
                 [ #  # ]
    3237 [ #  # ][ #  # ]:          0 :     normal2 = -normal2;
    3238                 :            :   
    3239         [ #  # ]:          0 :   result = tangent.vector_angle(normal1, normal ) <=
    3240         [ #  # ]:          0 :            tangent.vector_angle(normal1, normal2);
    3241                 :          0 :   return CUBIT_SUCCESS;
    3242                 :            : }
    3243                 :            : 
    3244                 :            :   
    3245                 :            : 
    3246                 :            : 
    3247                 :            : 
    3248                 :            : //-------------------------------------------------------------------------
    3249                 :            : // Purpose       : Destroy a point-curve
    3250                 :            : //
    3251                 :            : // Special Notes : 
    3252                 :            : //
    3253                 :            : // Creator       : Jason Kraftcheck
    3254                 :            : //
    3255                 :            : // Creation Date : 02/28/04
    3256                 :            : //-------------------------------------------------------------------------
    3257                 :          0 : CompositePoint* CompositeEngine::destroy_point_curve( CompositeCurve* curve )
    3258                 :            : {
    3259                 :          0 :   CompositePoint* geom_pt = curve->start_point();
    3260                 :          0 :   CompositeCoEdge* coedge = curve->first_coedge();
    3261                 :          0 :   CompositeLoop* loop = coedge->get_loop();
    3262                 :          0 :   CompositeSurface* surf = loop->get_surface();
    3263                 :            : 
    3264                 :            :     // Make sure topology looks like a point curve
    3265 [ #  # ][ #  # ]:          0 :   if (curve->num_curves()        >  0       ||
    3266         [ #  # ]:          0 :       curve->end_point()         != geom_pt ||
    3267 [ #  # ][ #  # ]:          0 :       curve->next_coedge(coedge) != NULL    ||
    3268                 :          0 :       loop->next_coedge(coedge)  != coedge   )
    3269                 :            :   {
    3270         [ #  # ]:          0 :     assert( geom_pt == curve->start_point() );
    3271         [ #  # ]:          0 :     assert( curve->next_coedge(coedge) == NULL );
    3272         [ #  # ]:          0 :     assert( loop->next_coedge(coedge) == coedge );
    3273                 :          0 :     return 0;
    3274                 :            :   }
    3275                 :            : 
    3276                 :            :     // Destroy point-curve and corresponding topology
    3277                 :          0 :   curve->remove(coedge);
    3278                 :          0 :   loop->remove(coedge);
    3279         [ #  # ]:          0 :   delete coedge;
    3280                 :            : 
    3281                 :          0 :   surf->remove(loop);
    3282         [ #  # ]:          0 :   delete loop;
    3283                 :            : 
    3284                 :          0 :   curve->start_point(0);
    3285                 :          0 :   curve->end_point(0);
    3286         [ #  # ]:          0 :   delete curve;
    3287                 :            : 
    3288                 :          0 :   return geom_pt;
    3289                 :            : }
    3290                 :            :   
    3291                 :            : 
    3292                 :            : 
    3293                 :          0 : CubitStatus CompositeEngine::restore_curve( Curve* curve )
    3294                 :            : {
    3295                 :          0 :   CompositeSurface* new_surf = 0;
    3296                 :            :   
    3297                 :            :     // find compostie surface owning the curve
    3298                 :          0 :   TopologyBridge* bridge = curve;
    3299                 :          0 :   HiddenEntitySet* owner_set = NULL;
    3300 [ #  # ][ #  # ]:          0 :   while( bridge && !(owner_set = dynamic_cast<HiddenEntitySet*>(bridge->owner())) )
         [ #  # ][ #  # ]
                 [ #  # ]
    3301                 :            :   {
    3302 [ #  # ][ #  # ]:          0 :     bridge = dynamic_cast<TopologyBridge*>(bridge->owner());
    3303                 :            :   }
    3304                 :            :   
    3305         [ #  # ]:          0 :   if( !owner_set )
    3306                 :          0 :     return CUBIT_FAILURE;
    3307                 :            :   
    3308 [ #  # ][ #  # ]:          0 :   CompositeSurface* compsurf = dynamic_cast<CompositeSurface*>(owner_set->owner());
    3309         [ #  # ]:          0 :   if( !compsurf )
    3310                 :          0 :     return CUBIT_FAILURE;
    3311                 :            :   
    3312         [ #  # ]:          0 :   CompositeCurve* compcurve = dynamic_cast<CompositeCurve*>(curve);
    3313         [ #  # ]:          0 :   if( !compcurve )
    3314 [ #  # ][ #  # ]:          0 :     compcurve = dynamic_cast<CompositeCurve*>(curve->owner());
    3315         [ #  # ]:          0 :   if( !compcurve )
    3316                 :          0 :     return CUBIT_FAILURE;
    3317                 :            :   
    3318         [ #  # ]:          0 :   CompositePoint *start_point = compcurve->start_point();
    3319         [ #  # ]:          0 :   CompositePoint *end_point   = compcurve->end_point();
    3320                 :          0 :   CompositeCurve *stitch_partner = 0; // find_stitch( compcurve );
    3321                 :            :   
    3322                 :            :     // Clean up any null-geometry point-curves attached to the
    3323                 :            :     // start and/or end points.
    3324         [ #  # ]:          0 :   CompositeCurve* itor = start_point->next_curve(NULL);
    3325         [ #  # ]:          0 :   while (itor)
    3326                 :            :   {
    3327         [ #  # ]:          0 :     CompositeCurve* next = start_point->next_curve(itor);
    3328 [ #  # ][ #  # ]:          0 :     if (itor->num_curves() == 0)
    3329         [ #  # ]:          0 :       destroy_point_curve(itor);
    3330                 :          0 :     itor = next;
    3331                 :            :   }
    3332         [ #  # ]:          0 :   itor = end_point->next_curve(NULL);
    3333         [ #  # ]:          0 :   while (itor)
    3334                 :            :   {
    3335         [ #  # ]:          0 :     CompositeCurve* next = end_point->next_curve(itor);
    3336 [ #  # ][ #  # ]:          0 :     if (itor->num_curves() == 0)
    3337         [ #  # ]:          0 :       destroy_point_curve(itor);
    3338                 :          0 :     itor = next;
    3339                 :            :   }
    3340                 :            :   
    3341                 :            :     // Check if end points are hidden by a CompositeCurve, and
    3342                 :            :     // if so, split the composite curve so that the end point(s)
    3343                 :            :     // are no longer hidden.
    3344                 :            :   HiddenEntitySet* hs;
    3345 [ #  # ][ #  # ]:          0 :   if( (hs = dynamic_cast<HiddenEntitySet*>(start_point->owner())) 
    3346 [ #  # ][ #  # ]:          0 :       && dynamic_cast<CompositeCurve*>(hs->owner())
                 [ #  # ]
    3347 [ #  # ][ #  # ]:          0 :       && !restore_point_in_curve( start_point ) )
         [ #  # ][ #  # ]
    3348                 :          0 :     return CUBIT_FAILURE;
    3349         [ #  # ]:          0 :   if( end_point != start_point
    3350 [ #  # ][ #  # ]:          0 :       && (hs = dynamic_cast<HiddenEntitySet*>(end_point->owner()))
                 [ #  # ]
    3351 [ #  # ][ #  # ]:          0 :       && dynamic_cast<CompositeCurve*>(hs->owner())
                 [ #  # ]
    3352 [ #  # ][ #  # ]:          0 :       && !restore_point_in_curve( end_point ) )
                 [ #  # ]
    3353                 :          0 :     return CUBIT_FAILURE;
    3354                 :            :   
    3355                 :            :     // Find which loop(s) to insert CoEdge in, and where in
    3356                 :            :     // the loop(s) to insert it.  For the start point of the
    3357                 :            :     // curve, start_loop is the loop containing that point and
    3358                 :            :     // start_prev_coedge and start_next_coedge are the previous
    3359                 :            :     // and next coedges in the loop at that point, respectively.
    3360                 :            :     // Similarly, end_loop, end_prev_coedge and end_next_coedge
    3361                 :            :     // for the end point.
    3362                 :          0 :   CompositeLoop *start_loop = 0, *end_loop = 0;
    3363                 :          0 :   CompositeCoEdge *start_prev_coedge = 0, *start_next_coedge = 0;
    3364                 :          0 :   CompositeCoEdge *end_prev_coedge = 0, *end_next_coedge = 0;
    3365                 :            :   
    3366         [ #  # ]:          0 :   if ( ! find_coedges( compsurf, compcurve, start_point, 
    3367         [ #  # ]:          0 :                        start_prev_coedge, start_next_coedge ) )
    3368                 :          0 :     return CUBIT_FAILURE;
    3369         [ #  # ]:          0 :   if( start_prev_coedge )
    3370                 :            :   {
    3371         [ #  # ]:          0 :     start_loop = start_prev_coedge->get_loop();
    3372 [ #  # ][ #  # ]:          0 :     assert(start_next_coedge && 
    3373         [ #  # ]:          0 :            start_next_coedge->get_loop() == start_loop );
    3374                 :            :   }
    3375                 :            : 
    3376         [ #  # ]:          0 :   if ( ! find_coedges( compsurf, compcurve, end_point, 
    3377         [ #  # ]:          0 :                        end_prev_coedge, end_next_coedge ) )
    3378                 :          0 :     return CUBIT_FAILURE;
    3379         [ #  # ]:          0 :   if( end_prev_coedge )
    3380                 :            :   {
    3381         [ #  # ]:          0 :     end_loop = end_prev_coedge->get_loop();
    3382 [ #  # ][ #  # ]:          0 :     assert(end_next_coedge &&
    3383         [ #  # ]:          0 :            end_next_coedge->get_loop()== end_loop );
    3384                 :            :   }
    3385                 :            :                                      
    3386                 :            :     // must be all or none
    3387 [ #  # ][ #  # ]:          0 :   assert( !start_loop || (start_prev_coedge && start_next_coedge) );
                 [ #  # ]
    3388 [ #  # ][ #  # ]:          0 :   assert( !end_loop || (end_prev_coedge && end_next_coedge) );
                 [ #  # ]
    3389                 :            :     // closed curve?
    3390 [ #  # ][ #  # ]:          0 :   assert( (start_point != end_point) || 
    3391         [ #  # ]:          0 :           (start_prev_coedge == end_prev_coedge && start_next_coedge == end_next_coedge) );
    3392                 :            :   
    3393                 :            :     // Find coedges, and un-hide coedegs, curve, and
    3394                 :            :     // end points.  
    3395         [ #  # ]:          0 :   CompositeCoEdge* coedge1 = compcurve->first_coedge();
    3396 [ #  # ][ #  # ]:          0 :   while (coedge1 && coedge1->owner() != &compsurf->hidden_entities())
         [ #  # ][ #  # ]
                 [ #  # ]
    3397         [ #  # ]:          0 :     coedge1 = compcurve->next_coedge(coedge1);
    3398         [ #  # ]:          0 :   assert( coedge1 );
    3399         [ #  # ]:          0 :   CompositeCoEdge* coedge2 = compcurve->next_coedge( coedge1 );
    3400 [ #  # ][ #  # ]:          0 :   while (coedge2 && coedge2->owner() != &compsurf->hidden_entities())
         [ #  # ][ #  # ]
                 [ #  # ]
    3401         [ #  # ]:          0 :     coedge2 = compcurve->next_coedge(coedge2);
    3402         [ #  # ]:          0 :   if (!coedge2)
    3403                 :            :   {
    3404         [ #  # ]:          0 :     DLIList<CompositeCurve*> stitched;
    3405         [ #  # ]:          0 :     compcurve->get_stitched( stitched );
    3406         [ #  # ]:          0 :     stitched.remove( compcurve );
    3407 [ #  # ][ #  # ]:          0 :     while (!coedge2 && stitched.size())
         [ #  # ][ #  # ]
    3408                 :            :     {
    3409         [ #  # ]:          0 :       CompositeCurve* other = stitched.pop();
    3410         [ #  # ]:          0 :       coedge2 = other->first_coedge();
    3411 [ #  # ][ #  # ]:          0 :       while (coedge2 && coedge2->owner() != &compsurf->hidden_entities())
         [ #  # ][ #  # ]
                 [ #  # ]
    3412         [ #  # ]:          0 :         coedge2 = other->next_coedge(coedge2);
    3413         [ #  # ]:          0 :     }
    3414                 :            :   }
    3415 [ #  # ][ #  # ]:          0 :   assert (coedge2 || compcurve->geometry_type() == POINT_CURVE_TYPE);
                 [ #  # ]
    3416 [ #  # ][ #  # ]:          0 :   compsurf->hidden_entities().restore( coedge1 );
    3417         [ #  # ]:          0 :   if (coedge2) // no coedge2 for point-curves
    3418 [ #  # ][ #  # ]:          0 :     compsurf->hidden_entities().restore( coedge2 );
    3419                 :            : 
    3420 [ #  # ][ #  # ]:          0 :   compsurf->hidden_entities().restore( compcurve );
    3421 [ #  # ][ #  # ]:          0 :   if( compcurve->start_point()->owner() == &(compsurf->hidden_entities()) )
         [ #  # ][ #  # ]
    3422 [ #  # ][ #  # ]:          0 :     compsurf->hidden_entities().restore( compcurve->start_point() );
                 [ #  # ]
    3423 [ #  # ][ #  # ]:          0 :   if( compcurve->end_point()->owner() == &(compsurf->hidden_entities()) )
         [ #  # ][ #  # ]
    3424 [ #  # ][ #  # ]:          0 :     compsurf->hidden_entities().restore( compcurve->end_point() );
                 [ #  # ]
    3425         [ #  # ]:          0 :   if( stitch_partner )
    3426 [ #  # ][ #  # ]:          0 :     compsurf->hidden_entities().restore( stitch_partner );
    3427                 :            : 
    3428                 :            :     // If neither point intersected a loop (topologically), then
    3429                 :            :     // create a new loop containing the curve.
    3430 [ #  # ][ #  # ]:          0 :   if( !start_loop && !end_loop )
    3431                 :            :   {
    3432                 :            :       // hole
    3433 [ #  # ][ #  # ]:          0 :     if ( compcurve->start_point() == compcurve->end_point() )
                 [ #  # ]
    3434                 :            :     {
    3435 [ #  # ][ #  # ]:          0 :       start_loop = new CompositeLoop();
    3436         [ #  # ]:          0 :       start_loop->insert_after(coedge1,0);
    3437         [ #  # ]:          0 :       compsurf->add(start_loop);
    3438         [ #  # ]:          0 :       if (coedge2)  // no coedge2 for point-curves
    3439                 :            :       {
    3440 [ #  # ][ #  # ]:          0 :         end_loop = new CompositeLoop();
    3441         [ #  # ]:          0 :         end_loop->insert_after(coedge2,0);
    3442         [ #  # ]:          0 :         compsurf->add(end_loop);
    3443 [ #  # ][ #  # ]:          0 :         if ( CompLoopTool::loop_angle_metric(coedge1) >
    3444         [ #  # ]:          0 :              CompLoopTool::loop_angle_metric(coedge2) )
    3445                 :            :         {
    3446         [ #  # ]:          0 :           compsurf->remove(end_loop);
    3447         [ #  # ]:          0 :           new_surf = split_surface(compsurf, start_loop, end_loop);
    3448                 :            :         }
    3449                 :            :         else
    3450                 :            :         {
    3451         [ #  # ]:          0 :           compsurf->remove(start_loop);
    3452         [ #  # ]:          0 :           new_surf = split_surface(compsurf, end_loop, start_loop);
    3453                 :            :         }
    3454                 :            :       }
    3455                 :            :     }
    3456                 :            :       // hardline
    3457                 :            :     else
    3458                 :            :     {
    3459 [ #  # ][ #  # ]:          0 :       CompositeLoop* new_loop = new CompositeLoop();
    3460         [ #  # ]:          0 :       new_loop->insert_after( coedge1, 0 );
    3461         [ #  # ]:          0 :       new_loop->insert_after( coedge2, coedge1 );
    3462         [ #  # ]:          0 :       compsurf->add( new_loop );
    3463                 :          0 :     }
    3464                 :            :   }
    3465                 :            : 
    3466                 :            :     // If only one of the end points intersected a loop, then
    3467                 :            :     // create a sipe in that loop.
    3468 [ #  # ][ #  # ]:          0 :   else if( !start_loop || !end_loop )
    3469                 :            :   {
    3470                 :            :     CompositeCoEdge* prev;
    3471                 :            :     CompositeLoop* loop;
    3472         [ #  # ]:          0 :     if( start_loop )
    3473                 :            :     {
    3474                 :          0 :       loop = start_loop;
    3475                 :          0 :       prev = start_prev_coedge;
    3476                 :            :     }
    3477                 :            :     else 
    3478                 :            :     {
    3479                 :          0 :       loop = end_loop;
    3480                 :          0 :       prev = end_prev_coedge;
    3481                 :            :     }
    3482                 :            :     
    3483 [ #  # ][ #  # ]:          0 :     if( coedge1->start_point() == prev->end_point() )
                 [ #  # ]
    3484                 :            :     {
    3485         [ #  # ]:          0 :       loop->insert_after( coedge1, prev );
    3486         [ #  # ]:          0 :       loop->insert_after( coedge2, coedge1 );
    3487                 :            :     }
    3488                 :            :     else
    3489                 :            :     {
    3490 [ #  # ][ #  # ]:          0 :       assert( coedge2->start_point() == prev->end_point() );
                 [ #  # ]
    3491         [ #  # ]:          0 :       loop->insert_after( coedge2, prev );
    3492         [ #  # ]:          0 :       loop->insert_after( coedge1, coedge2 );
    3493                 :          0 :     }
    3494                 :            :   }
    3495                 :            :     
    3496                 :            :     // If the end points of the curve intersected different
    3497                 :            :     // loops, combine the loops such that the curve becomes
    3498                 :            :     // a "bridge" between them.
    3499         [ #  # ]:          0 :   else if( start_loop != end_loop )
    3500                 :            :   {
    3501                 :          0 :     CompositeCoEdge* prev = start_prev_coedge;
    3502                 :          0 :     CompositeCoEdge* coedge = end_next_coedge;
    3503                 :          0 :     CompositeCoEdge* next = 0;
    3504                 :            :     
    3505                 :            :       // Which of the two coedges for the curve we are
    3506                 :            :       // restoring do we want to begin with (and store
    3507                 :            :       // the other as other_coedge).
    3508                 :          0 :     CompositeCoEdge* other_coedge = NULL;
    3509 [ #  # ][ #  # ]:          0 :     if( coedge1->start_point() == prev->end_point() )
                 [ #  # ]
    3510                 :            :     {
    3511         [ #  # ]:          0 :       start_loop->insert_after( coedge1, prev );
    3512                 :          0 :       prev = coedge1;
    3513                 :          0 :       other_coedge = coedge2;
    3514                 :            :     }
    3515 [ #  # ][ #  # ]:          0 :     else if( coedge2->start_point() == prev->end_point() )
                 [ #  # ]
    3516                 :            :     {
    3517         [ #  # ]:          0 :       start_loop->insert_after( coedge2, prev );
    3518                 :          0 :       prev = coedge2;
    3519                 :          0 :       other_coedge = coedge1;
    3520                 :            :     }
    3521                 :          0 :     else assert( 0 );
    3522                 :            :     
    3523 [ #  # ][ #  # ]:          0 :     while( end_loop->first_coedge() ) // while loop has coedges
    3524                 :            :     {
    3525         [ #  # ]:          0 :       next = end_loop->next_coedge( coedge );
    3526         [ #  # ]:          0 :       end_loop->remove( coedge );
    3527         [ #  # ]:          0 :       start_loop->insert_after( coedge, prev );
    3528                 :          0 :       prev = coedge;
    3529                 :          0 :       coedge = next;
    3530                 :            :     }
    3531                 :            :     
    3532                 :            :       // The other coedge for the curve we are restoring...
    3533         [ #  # ]:          0 :     start_loop->insert_after( other_coedge, prev );
    3534                 :            :     
    3535 [ #  # ][ #  # ]:          0 :     assert( end_loop->num_coedges() == 0 );
    3536         [ #  # ]:          0 :     compsurf->remove( end_loop );
    3537 [ #  # ][ #  # ]:          0 :     delete end_loop;
    3538                 :            :   }
    3539                 :            :     
    3540                 :            :     // If both end points of the curve intersected the same
    3541                 :            :     // loop, then split the loop (and the composite surface)
    3542                 :            :     // into two.
    3543                 :            :   else
    3544                 :            :   {
    3545         [ #  # ]:          0 :     assert( start_loop == end_loop );
    3546                 :            : 
    3547                 :            :       // Special case:
    3548                 :            :       // Hole intersecting original loop at one point
    3549                 :            :       // (when loop is split, oringinal loop has all
    3550                 :            :       //  original coedges, and new loop has only the
    3551                 :            :       //  curve we are restoring)  Figure out which
    3552                 :            :       // coedge belongs in the hole.
    3553 [ #  # ][ #  # ]:          0 :     if( coedge1->start_point() == coedge1->end_point() )
                 [ #  # ]
    3554                 :            :     {
    3555         [ #  # ]:          0 :       assert( start_next_coedge == end_next_coedge );
    3556         [ #  # ]:          0 :       assert( start_prev_coedge == end_prev_coedge );
    3557                 :            :       
    3558 [ #  # ][ #  # ]:          0 :       CubitVector prev_tan, coe1_tan, coe2_tan, norm, junk;
         [ #  # ][ #  # ]
                 [ #  # ]
    3559 [ #  # ][ #  # ]:          0 :       CubitVector point = coedge1->start_point()->coordinates();
    3560 [ #  # ][ #  # ]:          0 :       start_prev_coedge->get_curve()->closest_point( point, junk, &prev_tan );
    3561 [ #  # ][ #  # ]:          0 :       if( start_prev_coedge->sense() == CUBIT_FORWARD ) // yes, forward!!!
    3562         [ #  # ]:          0 :         prev_tan *= -1.0;
    3563 [ #  # ][ #  # ]:          0 :       coedge1->get_curve()->closest_point( point, junk, &coe1_tan );
    3564         [ #  # ]:          0 :       coe2_tan = coe1_tan;
    3565 [ #  # ][ #  # ]:          0 :       if( coedge1->sense() == CUBIT_REVERSED )
    3566         [ #  # ]:          0 :         coe1_tan *= -1.0;
    3567 [ #  # ][ #  # ]:          0 :       if( coedge2->sense() == CUBIT_REVERSED )
    3568         [ #  # ]:          0 :         coe2_tan *= -1.0;
    3569         [ #  # ]:          0 :       compsurf->closest_point( point, 0, &norm );
    3570                 :            :         
    3571         [ #  # ]:          0 :       double angle1 = norm.vector_angle( prev_tan, coe1_tan );
    3572         [ #  # ]:          0 :       double angle2 = norm.vector_angle( prev_tan, coe2_tan );
    3573                 :            :       
    3574         [ #  # ]:          0 :       if( angle2 < angle1 )
    3575                 :            :       {
    3576                 :          0 :         CompositeCoEdge* temp = coedge2;
    3577                 :          0 :         coedge2 = coedge1;
    3578                 :          0 :         coedge1 = temp;
    3579                 :            :       }
    3580                 :            :     }
    3581                 :            :     
    3582                 :            :       // Normal case (not a hole)
    3583                 :            :     else
    3584                 :            :     {
    3585                 :            :         // Make sure coedge1 is the reverse one
    3586 [ #  # ][ #  # ]:          0 :       if( coedge1->sense() == CUBIT_FORWARD )
    3587         [ #  # ]:          0 :         std::swap(coedge1,coedge2);
    3588                 :            :     }
    3589                 :            :     
    3590 [ #  # ][ #  # ]:          0 :     end_loop = new CompositeLoop();
    3591         [ #  # ]:          0 :     start_loop->insert_after( coedge1, end_prev_coedge );
    3592         [ #  # ]:          0 :     end_loop->insert_after( coedge2, 0 );
    3593                 :            :     
    3594                 :          0 :     CompositeCoEdge* coedge = end_next_coedge;
    3595                 :          0 :     CompositeCoEdge* prev = coedge2;
    3596         [ #  # ]:          0 :     while( coedge != start_next_coedge )
    3597                 :            :     {
    3598         [ #  # ]:          0 :       CompositeCoEdge* next = start_loop->next_coedge( coedge );
    3599         [ #  # ]:          0 :       start_loop->remove( coedge );
    3600         [ #  # ]:          0 :       end_loop->insert_after( coedge, prev );
    3601                 :          0 :       prev = coedge;
    3602                 :          0 :       coedge = next;
    3603                 :            :     }
    3604                 :            :     
    3605         [ #  # ]:          0 :     new_surf = split_surface(  compsurf, start_loop, end_loop );
    3606                 :            :     
    3607                 :            :   }
    3608                 :            :   
    3609         [ #  # ]:          0 :   if( new_surf )
    3610                 :            :   {
    3611 [ #  # ][ #  # ]:          0 :     if( compsurf->next_co_surface() )
    3612                 :            :     {
    3613                 :          0 :       CompositeCoSurf* cos = 0;
    3614 [ #  # ][ #  # ]:          0 :       while( (cos = compsurf->next_co_surface(cos)) )
    3615 [ #  # ][ #  # ]:          0 :         cos->get_shell()->add( new_surf, cos->sense() );
                 [ #  # ]
    3616                 :            :     }
    3617                 :            :     
    3618 [ #  # ][ #  # ]:          0 :     if( ! new_surf->has_hidden_entities() &&
         [ #  # ][ #  # ]
    3619         [ #  # ]:          0 :         ! new_surf->next_co_surface(0) )
    3620         [ #  # ]:          0 :       remove_composite( new_surf );
    3621                 :            :   }
    3622                 :            :   
    3623 [ #  # ][ #  # ]:          0 :   if( ! compsurf->has_hidden_entities() &&
         [ #  # ][ #  # ]
    3624         [ #  # ]:          0 :       ! compsurf->next_co_surface(0) )
    3625         [ #  # ]:          0 :     remove_composite( compsurf );
    3626                 :            :   
    3627                 :          0 :   return CUBIT_SUCCESS;
    3628                 :            : }
    3629                 :            : 
    3630                 :            : 
    3631                 :            : //-------------------------------------------------------------------------
    3632                 :            : // Purpose       : Given a point that intersects a loop in the passed 
    3633                 :            : //                 surface, find the location in that loop at which the
    3634                 :            : //                 passed curve should be inserted.  If there are only two
    3635                 :            : //                 coedges in the loop at the passed point, then the answer
    3636                 :            : //                 is obvious.  If there is a sipe at the point, then use
    3637                 :            : //                 topological information of underlying real surfaces to
    3638                 :            : //                 determine the two coedges between which the new curve
    3639                 :            : //                 should be inserted.
    3640                 :            : //
    3641                 :            : // Special Notes : 
    3642                 :            : //
    3643                 :            : // Creator       : Jason Kraftcheck
    3644                 :            : //
    3645                 :            : // Creation Date : 03/19/03
    3646                 :            : //-------------------------------------------------------------------------
    3647                 :          0 : CubitStatus CompositeEngine::find_coedges( CompositeSurface* surface,
    3648                 :            :                                            CompositeCurve* curve,
    3649                 :            :                                            CompositePoint* point,
    3650                 :            :                                            CompositeCoEdge*& previous,
    3651                 :            :                                            CompositeCoEdge*& next )
    3652                 :            : {
    3653                 :          0 :   const char* const bad_loop_message = "Internal error: Invalid loop. (%s:%d)\n";
    3654                 :            :   
    3655                 :            :     // Find list of all coedges around passed point
    3656                 :            :     // and in passed surface.
    3657         [ #  # ]:          0 :   DLIList<CompositeCoEdge*> point_coedges;
    3658                 :          0 :   CompositeCurve* pt_curve = 0;
    3659 [ #  # ][ #  # ]:          0 :   while ( (pt_curve = point->next_curve(pt_curve)) )
    3660                 :            :   {
    3661                 :          0 :     CompositeCoEdge* coedge = 0;
    3662 [ #  # ][ #  # ]:          0 :     while ( (coedge = pt_curve->next_coedge(coedge)) )
    3663                 :            :     {
    3664 [ #  # ][ #  # ]:          0 :       if (coedge->get_loop() && coedge->get_loop()->get_surface() == surface)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3665         [ #  # ]:          0 :         point_coedges.append(coedge);
    3666                 :            :     }
    3667                 :            :   }
    3668                 :            :   
    3669                 :            :     // Point is at end of a sipe/hardline
    3670 [ #  # ][ #  # ]:          0 :   if ( point_coedges.size() == 0 )
    3671                 :            :   {
    3672                 :          0 :     previous = next = 0;
    3673                 :          0 :     return CUBIT_SUCCESS;
    3674                 :            :   }
    3675                 :            :   
    3676                 :            :     // One coedge - closed curve
    3677 [ #  # ][ #  # ]:          0 :   if ( point_coedges.size() == 1 &&
         [ #  # ][ #  # ]
    3678 [ #  # ][ #  # ]:          0 :        point_coedges.get()->start_point() ==
    3679 [ #  # ][ #  # ]:          0 :        point_coedges.get()->end_point() )
    3680                 :            :   {
    3681         [ #  # ]:          0 :     previous = next = point_coedges.get();
    3682                 :          0 :     return CUBIT_SUCCESS;
    3683                 :            :   }
    3684                 :            :   
    3685                 :            :     // Broken loop?
    3686 [ #  # ][ #  # ]:          0 :   if ( point_coedges.size() % 2 != 0 )
    3687                 :            :   {
    3688 [ #  # ][ #  # ]:          0 :     PRINT_ERROR(bad_loop_message,__FILE__,__LINE__);
         [ #  # ][ #  # ]
    3689                 :          0 :     assert(0);
    3690                 :            :     return CUBIT_FAILURE;
    3691                 :            :   }
    3692                 :            :   
    3693                 :            :     // If only two coedges, then we're done
    3694 [ #  # ][ #  # ]:          0 :   if ( point_coedges.size() == 2 )
    3695                 :            :   {
    3696         [ #  # ]:          0 :     previous = point_coedges.get();
    3697         [ #  # ]:          0 :     next = point_coedges.next();
    3698                 :            :     
    3699 [ #  # ][ #  # ]:          0 :     if ( previous->start_point() == point )
    3700         [ #  # ]:          0 :       std::swap(previous, next);
    3701                 :            :     
    3702                 :          0 :     return CUBIT_SUCCESS;
    3703                 :            :   }
    3704                 :            :   
    3705                 :            :     // Find previous/next coedges by using order of
    3706                 :            :     // coedges about point in underlying surfaces.
    3707                 :            :     // Coedges must occur in clock-wise order about point.
    3708                 :            :   
    3709                 :            :     // Get the real curve at the point
    3710 [ #  # ][ #  # ]:          0 :   int curve_index = point == curve->start_point() ? 0 : curve->num_curves() - 1;
                 [ #  # ]
    3711         [ #  # ]:          0 :   Curve* real_curve = curve->get_curve(curve_index);
    3712                 :            :   
    3713                 :            :     // Get two coedges in composite
    3714 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> coedge_bridges, loop_bridges(1), surface_bridges(1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3715         [ #  # ]:          0 :   real_curve->get_parents_virt(coedge_bridges);
    3716 [ #  # ][ #  # ]:          0 :   DLIList<CoEdgeSM*> curve_coedges;
    3717 [ #  # ][ #  # ]:          0 :   while (coedge_bridges.size())
    3718                 :            :   {
    3719         [ #  # ]:          0 :     TopologyBridge* coe_bridge = coedge_bridges.pop();
    3720                 :            :     
    3721         [ #  # ]:          0 :     loop_bridges.clean_out();
    3722         [ #  # ]:          0 :     surface_bridges.clean_out();
    3723                 :            :     
    3724         [ #  # ]:          0 :     coe_bridge->get_parents_virt(loop_bridges);
    3725 [ #  # ][ #  # ]:          0 :     assert(loop_bridges.size() == 1);
    3726                 :            :     
    3727 [ #  # ][ #  # ]:          0 :     loop_bridges.get()->get_parents_virt(surface_bridges);
    3728 [ #  # ][ #  # ]:          0 :     assert(surface_bridges.size() == 1);
    3729                 :            :     
    3730 [ #  # ][ #  # ]:          0 :     if ( surface->contains_bridge(surface_bridges.get()) )
                 [ #  # ]
    3731                 :            :     {
    3732 [ #  # ][ #  # ]:          0 :       curve_coedges.append(dynamic_cast<CoEdgeSM*>(coe_bridge));
    3733                 :            :     }
    3734                 :            :   }
    3735 [ #  # ][ #  # ]:          0 :   if ( curve_coedges.size() != 2 )
    3736                 :            :   {
    3737 [ #  # ][ #  # ]:          0 :     PRINT_ERROR(bad_loop_message,__FILE__,__LINE__);
         [ #  # ][ #  # ]
    3738                 :          0 :     assert(0);
    3739                 :            :     return CUBIT_FAILURE;
    3740                 :            :   }
    3741                 :            :   
    3742                 :            :     // Assign coedges such that prev_coe_sm goes "out of"
    3743                 :            :     // the point and next_coe_sm goes "into" the point.
    3744                 :            :     // (Unless surface sense is reversed in composite surface.)
    3745         [ #  # ]:          0 :   curve_coedges.reset();
    3746         [ #  # ]:          0 :   CoEdgeSM *prev_coe_sm = curve_coedges.get();
    3747         [ #  # ]:          0 :   CoEdgeSM *next_coe_sm = curve_coedges.next();
    3748 [ #  # ][ #  # ]:          0 :   CompositeCoEdge* prev_owner = dynamic_cast<CompositeCoEdge*>(prev_coe_sm->owner());
    3749                 :            : #ifndef NDEBUG
    3750 [ #  # ][ #  # ]:          0 :   CompositeCoEdge* next_owner = dynamic_cast<CompositeCoEdge*>(next_coe_sm->owner());
    3751 [ #  # ][ #  # ]:          0 :   assert( prev_owner && next_owner );
    3752                 :            : #endif
    3753 [ #  # ][ #  # ]:          0 :   if ( prev_owner->start_point() == point )
    3754                 :            :   {
    3755                 :            : #ifndef NDEBUG
    3756 [ #  # ][ #  # ]:          0 :     assert(next_owner->end_point() == point);
    3757                 :            : #endif
    3758                 :            :   }
    3759                 :            :   else
    3760                 :            :   {
    3761                 :            : #ifndef NDEBUG
    3762 [ #  # ][ #  # ]:          0 :     assert(next_owner->start_point() == point);
    3763 [ #  # ][ #  # ]:          0 :     assert(prev_owner->end_point() == point);
    3764                 :            : #endif
    3765         [ #  # ]:          0 :     std::swap(prev_coe_sm, next_coe_sm);
    3766                 :            :   }
    3767                 :            :     
    3768                 :            :     // Now iterate through real coedges around point to
    3769                 :            :     // find the next/prev composite coedges.
    3770                 :            :   CompositeCoEdge* prev_result 
    3771         [ #  # ]:          0 :     = find_next_point_coedge( surface, prev_coe_sm, point, point_coedges );
    3772                 :            :   CompositeCoEdge* next_result 
    3773         [ #  # ]:          0 :     = find_next_point_coedge( surface, next_coe_sm, point, point_coedges );
    3774                 :            :   
    3775 [ #  # ][ #  # ]:          0 :   if( !prev_result || !next_result )
    3776                 :            :   {
    3777 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Internal error: Invalid composite. (%s:%d)\n",__FILE__,__LINE__);
         [ #  # ][ #  # ]
    3778                 :          0 :     return CUBIT_FAILURE;
    3779                 :            :   }
    3780                 :            : 
    3781         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    3782                 :            : }
    3783                 :            : 
    3784                 :            : //-------------------------------------------------------------------------
    3785                 :            : // Purpose       : Find next coedge by traversing real coedges on
    3786                 :            : //                 surfaces hidden by composite.
    3787                 :            : //
    3788                 :            : // Special Notes : 
    3789                 :            : //
    3790                 :            : // Creator       : Jason Kraftcheck
    3791                 :            : //
    3792                 :            : // Creation Date : 03/19/03
    3793                 :            : //-------------------------------------------------------------------------
    3794                 :          0 : CompositeCoEdge* CompositeEngine::find_next_point_coedge( 
    3795                 :            :                                      CompositeSurface* const compsurf,
    3796                 :            :                                      CoEdgeSM* const first_coedge,
    3797                 :            :                                      CompositePoint* point,
    3798                 :            :                                      DLIList<CompositeCoEdge*>& point_coedges )
    3799                 :            : {
    3800 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> loop_bridges(1), coedge_bridges, curve_pts(2);
         [ #  # ][ #  # ]
                 [ #  # ]
    3801                 :          0 :   CoEdgeSM* coedge = first_coedge;
    3802                 :            :   
    3803         [ #  # ]:          0 :   coedge_bridges.clean_out();
    3804         [ #  # ]:          0 :   coedge->get_children(coedge_bridges,true,COMPOSITE_LAYER-1);
    3805 [ #  # ][ #  # ]:          0 :   assert(coedge_bridges.size() == 1);
    3806 [ #  # ][ #  # ]:          0 :   Curve* curvesm = dynamic_cast<Curve*>(coedge_bridges.get());
    3807                 :            :  
    3808         [ #  # ]:          0 :   do
    3809                 :            :   {
    3810                 :            :       // Get loop from coedge
    3811         [ #  # ]:          0 :     loop_bridges.clean_out();
    3812         [ #  # ]:          0 :     coedge->get_parents_virt(loop_bridges);
    3813 [ #  # ][ #  # ]:          0 :     assert(loop_bridges.size() == 1);
    3814 [ #  # ][ #  # ]:          0 :     LoopSM* loop_sm = dynamic_cast<LoopSM*>(loop_bridges.get());
    3815                 :            :     
    3816                 :            :       // Make sure we're still inside the composite.
    3817                 :            :       // It's a bug if this check fails.
    3818         [ #  # ]:          0 :     loop_bridges.clean_out();
    3819         [ #  # ]:          0 :     loop_sm->get_parents_virt(loop_bridges);
    3820 [ #  # ][ #  # ]:          0 :     if ( !compsurf->contains_bridge(loop_bridges.get()) )
                 [ #  # ]
    3821                 :          0 :       { assert(0); break; }
    3822                 :            :     
    3823                 :            :       // Get direction of curve wrt point : forward if the
    3824                 :            :       // curve ends at the point or reverse if it begins at
    3825                 :            :       // the point.
    3826         [ #  # ]:          0 :     curve_pts.clean_out();
    3827         [ #  # ]:          0 :     curvesm->get_children(curve_pts,true,COMPOSITE_LAYER-1);
    3828         [ #  # ]:          0 :     curve_pts.reset();
    3829                 :            :     CubitSense curve_sense;
    3830 [ #  # ][ #  # ]:          0 :     if ( curve_pts.next()->owner() == point )
         [ #  # ][ #  # ]
    3831                 :          0 :       curve_sense = CUBIT_FORWARD;
    3832 [ #  # ][ #  # ]:          0 :     else if( curve_pts.get()->owner() == point )
         [ #  # ][ #  # ]
    3833                 :          0 :       curve_sense = CUBIT_REVERSED;
    3834                 :            :     else
    3835                 :          0 :       { assert(0); break; } //bug - shouldn't happen
    3836                 :            :       
    3837                 :            :       // Get the next coedge in the loop. If the coedge
    3838                 :            :       // begins at the point, then the adjacent coedge
    3839                 :            :       // is the previous one in the loop.  Otherwise
    3840                 :            :       // it is the next one in the loop.
    3841         [ #  # ]:          0 :     coedge_bridges.clean_out();
    3842         [ #  # ]:          0 :     loop_sm->get_children(coedge_bridges,true,COMPOSITE_LAYER-1);
    3843         [ #  # ]:          0 :     coedge_bridges.move_to(coedge);
    3844 [ #  # ][ #  # ]:          0 :     assert(coedge_bridges.get() == coedge);
    3845 [ #  # ][ #  # ]:          0 :     if ( coedge->sense() == curve_sense )
    3846 [ #  # ][ #  # ]:          0 :       coedge = dynamic_cast<CoEdgeSM*>(coedge_bridges.next());
    3847                 :            :     else
    3848 [ #  # ][ #  # ]:          0 :       coedge = dynamic_cast<CoEdgeSM*>(coedge_bridges.prev());
    3849                 :            : 
    3850                 :            :       // Are we done?  This is the real end condition.
    3851                 :            :       // Any other return path is an error.
    3852 [ #  # ][ #  # ]:          0 :     CompositeCoEdge* result = dynamic_cast<CompositeCoEdge*>(coedge->owner());
    3853         [ #  # ]:          0 :     assert(!!result);
    3854 [ #  # ][ #  # ]:          0 :     if ( point_coedges.is_in_list(result) )
    3855                 :          0 :       return result;
    3856                 :            : 
    3857                 :            :       // get the curve for the current coedge
    3858         [ #  # ]:          0 :     coedge_bridges.clean_out();
    3859         [ #  # ]:          0 :     coedge->get_children(coedge_bridges,true,COMPOSITE_LAYER-1);
    3860 [ #  # ][ #  # ]:          0 :     assert(coedge_bridges.size() == 1);
    3861 [ #  # ][ #  # ]:          0 :     curvesm = dynamic_cast<Curve*>(coedge_bridges.get());
    3862                 :            : 
    3863                 :            :       // Get the other coedge on the curve
    3864         [ #  # ]:          0 :     coedge_bridges.clean_out();
    3865         [ #  # ]:          0 :     curvesm->get_parents_virt(coedge_bridges);
    3866 [ #  # ][ #  # ]:          0 :     if ( coedge_bridges.size() != 2 )
    3867                 :          0 :       break;  // Reached boundary of composite
    3868         [ #  # ]:          0 :     coedge_bridges.move_to( coedge );
    3869 [ #  # ][ #  # ]:          0 :     assert(coedge_bridges.get() == coedge );
    3870 [ #  # ][ #  # ]:          0 :     coedge = dynamic_cast<CoEdgeSM*>(coedge_bridges.next());
    3871                 :            :   
    3872                 :            :   } while( coedge != first_coedge );
    3873                 :            :   
    3874         [ #  # ]:          0 :   return 0;
    3875                 :            : }
    3876                 :            :   
    3877                 :            :   
    3878                 :            : 
    3879                 :            : 
    3880                 :            : 
    3881                 :            : //-------------------------------------------------------------------------
    3882                 :            : // Purpose       : 
    3883                 :            : //
    3884                 :            : // Special Notes : 
    3885                 :            : //
    3886                 :            : // Creator       : Jason Kraftcheck
    3887                 :            : //
    3888                 :            : // Creation Date : 
    3889                 :            : //-------------------------------------------------------------------------
    3890                 :          0 : CompositeSurface* CompositeEngine::split_surface( 
    3891                 :            :                                  CompositeSurface* surf_to_split,
    3892                 :            :                                  CompositeLoop* loop_on_orig,
    3893                 :            :                                  CompositeLoop* loop_on_new )
    3894                 :            : {
    3895                 :            :   int i;
    3896                 :            :   
    3897         [ #  # ]:          0 :   DLIList<CoEdgeSM*> front_list;
    3898 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> bridge_list, loop_list, coedge_list;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3899 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> hidden_loops_to_move;
    3900 [ #  # ][ #  # ]:          0 :   DLIList<Surface*> surfs_to_move;
    3901                 :            :   
    3902                 :            :     // Do advancing front across surfaces underlying composite surface
    3903                 :            :     // to find which must be moved to the new composite.
    3904                 :            :     
    3905                 :            :     // Begin with the coedges in loop_on_new.
    3906         [ #  # ]:          0 :   CompositeCoEdge* coedge = loop_on_new->first_coedge();
    3907         [ #  # ]:          0 :   do
    3908                 :            :   { 
    3909 [ #  # ][ #  # ]:          0 :     for( i = 0; i < coedge->num_coedges(); i++ )
    3910 [ #  # ][ #  # ]:          0 :       front_list.append( coedge->get_coedge(i) );
    3911         [ #  # ]:          0 :     coedge = loop_on_new->next_coedge( coedge );
    3912         [ #  # ]:          0 :   } while( coedge != loop_on_new->first_coedge() );
    3913                 :            :   
    3914                 :            :     // Loop until front_list is empty
    3915 [ #  # ][ #  # ]:          0 :   while( front_list.size() )
    3916                 :            :   {
    3917         [ #  # ]:          0 :     CoEdgeSM* coe_real = front_list.pop();
    3918                 :            :     
    3919                 :            :       // Loop and Surface from CoEdge
    3920         [ #  # ]:          0 :     bridge_list.clean_out();
    3921         [ #  # ]:          0 :     coe_real->get_parents_virt( bridge_list );
    3922 [ #  # ][ #  # ]:          0 :     assert( bridge_list.size() == 1 );
    3923         [ #  # ]:          0 :     TopologyBridge* loop = bridge_list.get();
    3924         [ #  # ]:          0 :     bridge_list.clean_out();
    3925         [ #  # ]:          0 :     loop->get_parents_virt( bridge_list );
    3926 [ #  # ][ #  # ]:          0 :     if( bridge_list.size() != 1 )
    3927                 :            :     {
    3928         [ #  # ]:          0 :       assert( loop == loop_on_new );
    3929 [ #  # ][ #  # ]:          0 :       assert( bridge_list.size() == 0 );
    3930                 :          0 :       continue;
    3931                 :            :     }
    3932                 :            :     
    3933 [ #  # ][ #  # ]:          0 :     Surface* surf = dynamic_cast<Surface*>(bridge_list.get());
    3934         [ #  # ]:          0 :     assert( surf!= NULL  );
    3935                 :            :     
    3936 [ #  # ][ #  # ]:          0 :     if( surf->owner() != surf_to_split )
                 [ #  # ]
    3937                 :          0 :       continue;
    3938                 :            :       
    3939                 :            :       // Add surface to list of Surfaces to move to new composite
    3940         [ #  # ]:          0 :     surfs_to_move.append_unique( surf );  
    3941                 :            :     
    3942                 :            :       // Get list of all surface coedges (coedge_list)
    3943                 :            :       // and all loops to hidden_loops_to_move
    3944         [ #  # ]:          0 :     loop_list.clean_out();
    3945         [ #  # ]:          0 :     surf->get_children_virt( loop_list );
    3946 [ #  # ][ #  # ]:          0 :     for( i = loop_list.size(); i--; )
    3947                 :            :     {
    3948         [ #  # ]:          0 :       TopologyBridge* loop_bridge = loop_list.get_and_step();
    3949 [ #  # ][ #  # ]:          0 :       if( hidden_loops_to_move.is_in_list( loop_bridge ) )
    3950                 :          0 :         continue;
    3951         [ #  # ]:          0 :       hidden_loops_to_move.append( loop_bridge );
    3952         [ #  # ]:          0 :       bridge_list.clean_out();
    3953         [ #  # ]:          0 :       loop_bridge->get_children( bridge_list, true, COMPOSITE_LAYER-1 );
    3954         [ #  # ]:          0 :       coedge_list += bridge_list;
    3955                 :            :     }
    3956                 :            :     
    3957                 :            :       // For each coedge on the surface (all coedges in coedge_list),
    3958                 :            :       // get the curve and search for any other coedges that are 
    3959                 :            :       // parents of that curve and children of a surface hidden by
    3960                 :            :       // the composite.  Add them to front_list.
    3961 [ #  # ][ #  # ]:          0 :     while( coedge_list.size() )
    3962                 :            :     {
    3963         [ #  # ]:          0 :       TopologyBridge* coe_bridge = coedge_list.pop();
    3964         [ #  # ]:          0 :       bridge_list.clean_out();
    3965         [ #  # ]:          0 :       coe_bridge->get_children_virt( bridge_list );
    3966 [ #  # ][ #  # ]:          0 :       assert( bridge_list.size() == 1 );
    3967         [ #  # ]:          0 :       TopologyBridge* curve_bridge = bridge_list.get();
    3968         [ #  # ]:          0 :       bridge_list.clean_out();
    3969         [ #  # ]:          0 :       curve_bridge->get_parents_virt( bridge_list );
    3970                 :            :       
    3971 [ #  # ][ #  # ]:          0 :       while( bridge_list.size() )
    3972                 :            :       {
    3973         [ #  # ]:          0 :         TopologyBridge* other_coe = bridge_list.pop();
    3974         [ #  # ]:          0 :               if( other_coe == coe_bridge ) 
    3975                 :          0 :                 continue;
    3976                 :            :         
    3977         [ #  # ]:          0 :               CompositeCoEdge* compcoe = dynamic_cast<CompositeCoEdge*>(other_coe);
    3978         [ #  # ]:          0 :               if( !compcoe )
    3979                 :            :               {
    3980 [ #  # ][ #  # ]:          0 :                 compcoe = dynamic_cast<CompositeCoEdge*>(other_coe->owner());
    3981                 :            :               }
    3982 [ #  # ][ #  # ]:          0 :               if( !compcoe || compcoe->get_loop() != loop_on_orig )
         [ #  # ][ #  # ]
    3983 [ #  # ][ #  # ]:          0 :                 front_list.append( dynamic_cast<CoEdgeSM*>( other_coe ) );
    3984                 :            :       }
    3985                 :            :     }
    3986                 :            :   }
    3987                 :            :   
    3988                 :            :     // Check if surface needs to be split.  A new, closed loop
    3989                 :            :     // does not always indicate the surface needs to be split.
    3990                 :            :     // See PR#2140 for an example.
    3991 [ #  # ][ #  # ]:          0 :   if (surfs_to_move.size() == surf_to_split->num_surfs())
                 [ #  # ]
    3992                 :            :   {
    3993         [ #  # ]:          0 :     surf_to_split->add( loop_on_new );
    3994                 :          0 :     return 0;
    3995                 :            :   }
    3996                 :            :   
    3997                 :            :     // Split the composite (pass in indices of surfaces that 
    3998                 :            :     // should be in new composite rather than old.)
    3999 [ #  # ][ #  # ]:          0 :   VGArray<int> index_array( surfs_to_move.size() );
                 [ #  # ]
    4000 [ #  # ][ #  # ]:          0 :   for( i = 0; i < surfs_to_move.size(); i++ )
    4001 [ #  # ][ #  # ]:          0 :     index_array[i] = surf_to_split->index_of( surfs_to_move.get_and_step() );
                 [ #  # ]
    4002         [ #  # ]:          0 :   CompositeSurface* new_surf = surf_to_split->split( index_array );
    4003         [ #  # ]:          0 :   if( !new_surf )
    4004                 :            :   {
    4005         [ #  # ]:          0 :     surf_to_split->add( loop_on_new );
    4006                 :          0 :     return 0;
    4007                 :            :   }
    4008                 :            :   
    4009 [ #  # ][ #  # ]:          0 :   assert( new_surf->num_surfs() && surf_to_split->num_surfs() );
         [ #  # ][ #  # ]
    4010         [ #  # ]:          0 :   new_surf->add( loop_on_new );
    4011                 :            : 
    4012                 :            :     // Move hidden coedges from old surface's hidden set to
    4013                 :            :     // new surface.
    4014         [ #  # ]:          0 :   HiddenEntitySet* new_set = &(new_surf->hidden_entities());
    4015         [ #  # ]:          0 :   HiddenEntitySet* old_set = &(surf_to_split->hidden_entities());
    4016 [ #  # ][ #  # ]:          0 :   for ( i = 0; i < new_surf->num_surfs(); i++ )
    4017                 :            :   {
    4018         [ #  # ]:          0 :     loop_list.clean_out();
    4019 [ #  # ][ #  # ]:          0 :     new_surf->get_surface(i)->get_children_virt(loop_list);
    4020 [ #  # ][ #  # ]:          0 :     for ( int j = loop_list.size(); j--; )
    4021                 :            :     {
    4022         [ #  # ]:          0 :       coedge_list.clean_out();
    4023 [ #  # ][ #  # ]:          0 :       loop_list.get_and_step()->get_children( coedge_list, true, COMPOSITE_LAYER );
    4024 [ #  # ][ #  # ]:          0 :       for ( int k = coedge_list.size(); k--; )
    4025                 :            :       {
    4026         [ #  # ]:          0 :         TopologyBridge* coedge_ptr = coedge_list.get_and_step();
    4027 [ #  # ][ #  # ]:          0 :         if ( coedge_ptr->owner() == old_set )
    4028                 :            :         {
    4029         [ #  # ]:          0 :           old_set->restore(coedge_ptr);
    4030         [ #  # ]:          0 :           new_set->hide(coedge_ptr);
    4031                 :            :         }
    4032                 :            :       }
    4033                 :            :     }
    4034                 :            :   }
    4035                 :            :   
    4036                 :            : 
    4037                 :            :     // Move hidden curves from old surface's hidden set to
    4038                 :            :     // new surface.
    4039 [ #  # ][ #  # ]:          0 :   DLIList<Curve*> hidden_curves;
    4040         [ #  # ]:          0 :   old_set->hidden_curves( hidden_curves );
    4041 [ #  # ][ #  # ]:          0 :   for( i = hidden_curves.size(); i--; )
    4042                 :            :   {
    4043         [ #  # ]:          0 :     Curve* curve = hidden_curves.get_and_step();
    4044         [ #  # ]:          0 :     CompositeCurve* comp_curve = dynamic_cast<CompositeCurve*>(curve);
    4045         [ #  # ]:          0 :     assert(!!comp_curve);
    4046                 :            :     
    4047                 :          0 :     bool all_new = true;
    4048                 :          0 :     bool all_old = true;
    4049                 :          0 :     CompositeCoEdge* coedge_ptr = 0;
    4050 [ #  # ][ #  # ]:          0 :     while( (coedge_ptr = comp_curve->next_coedge(coedge_ptr)) )
    4051                 :            :     {
    4052 [ #  # ][ #  # ]:          0 :       if( coedge_ptr->owner() != new_set )
    4053                 :          0 :         all_new = false;
    4054 [ #  # ][ #  # ]:          0 :       if( coedge_ptr->owner() != old_set )
    4055                 :          0 :         all_old = false;
    4056                 :            :     }
    4057         [ #  # ]:          0 :     if( ! all_old )
    4058         [ #  # ]:          0 :       old_set->restore( curve );
    4059         [ #  # ]:          0 :     if( all_new )
    4060         [ #  # ]:          0 :       new_set->hide( curve );
    4061                 :            :   }
    4062                 :            : 
    4063                 :            :     // Move hidden points from old surface's hidden set to
    4064                 :            :     // new surface.
    4065 [ #  # ][ #  # ]:          0 :   DLIList<TBPoint*> hidden_points;
    4066         [ #  # ]:          0 :   old_set->hidden_points( hidden_points );
    4067 [ #  # ][ #  # ]:          0 :   for( i = hidden_points.size(); i--; )
    4068                 :            :   {
    4069         [ #  # ]:          0 :     TBPoint* point = hidden_points.get_and_step();
    4070         [ #  # ]:          0 :     CompositePoint* comp_pt = dynamic_cast<CompositePoint*>(point);
    4071         [ #  # ]:          0 :     assert(!!comp_pt);
    4072                 :            :     
    4073                 :          0 :     CompositeCurve* curve = 0;
    4074                 :          0 :     bool all_new = true;
    4075                 :          0 :     bool all_old = true;
    4076 [ #  # ][ #  # ]:          0 :     while ( (curve = comp_pt->next_curve(curve)) )
    4077                 :            :     {
    4078 [ #  # ][ #  # ]:          0 :       if ( curve->owner() != new_set )
    4079                 :          0 :         all_new = false;
    4080 [ #  # ][ #  # ]:          0 :       if ( curve->owner() != old_set )
    4081                 :          0 :         all_old = false;
    4082                 :            :     }
    4083                 :            :     
    4084         [ #  # ]:          0 :     if( ! all_old )
    4085         [ #  # ]:          0 :       old_set->restore( point );
    4086         [ #  # ]:          0 :     if( all_new )
    4087         [ #  # ]:          0 :       new_set->hide( point );
    4088                 :            :   }
    4089                 :            :   
    4090                 :            : 
    4091                 :            : 
    4092                 :            :     // figure out which visible loops need to be moved
    4093 [ #  # ][ #  # ]:          0 :   DLIList<CompositeLoop*> loops_to_move;
    4094 [ #  # ][ #  # ]:          0 :   for( CompositeLoop* loop = surf_to_split->first_loop();
    4095                 :          0 :        loop != 0;
    4096         [ #  # ]:          0 :        loop = loop->next_loop() )
    4097                 :            :   {
    4098         [ #  # ]:          0 :     CompositeCoEdge* a_coedge = loop->first_coedge();
    4099         [ #  # ]:          0 :     CoEdgeSM* real_coe = a_coedge->get_coedge(0);
    4100         [ #  # ]:          0 :     assert( real_coe!= NULL  );
    4101         [ #  # ]:          0 :     bridge_list.clean_out();
    4102         [ #  # ]:          0 :     real_coe->get_parents_virt( bridge_list );
    4103 [ #  # ][ #  # ]:          0 :     assert( bridge_list.size() == 1 );
    4104         [ #  # ]:          0 :     TopologyBridge* loop_bridge = bridge_list.get();
    4105         [ #  # ]:          0 :     bridge_list.clean_out();
    4106         [ #  # ]:          0 :     loop_bridge->get_parents_virt( bridge_list );
    4107 [ #  # ][ #  # ]:          0 :     Surface* surf = dynamic_cast<Surface*>(bridge_list.get());
    4108         [ #  # ]:          0 :     assert( surf!= NULL  );
    4109 [ #  # ][ #  # ]:          0 :     if( surf->owner() == new_surf )
                 [ #  # ]
    4110         [ #  # ]:          0 :       loops_to_move.append( loop );
    4111                 :            :   }
    4112                 :            :   
    4113                 :            :     // move visible loops to new surface
    4114 [ #  # ][ #  # ]:          0 :   while( loops_to_move.size() )
    4115                 :            :   {
    4116         [ #  # ]:          0 :     CompositeLoop* loop = loops_to_move.pop();
    4117         [ #  # ]:          0 :     surf_to_split->remove( loop );
    4118         [ #  # ]:          0 :     new_surf->add( loop );
    4119                 :            :   }
    4120                 :            :   
    4121 [ #  # ][ #  # ]:          0 :   assert( loop_on_orig->get_surface() == surf_to_split );  
    4122         [ #  # ]:          0 :   return new_surf;
    4123                 :            : }
    4124                 :            : 
    4125                 :            : 
    4126                 :            :     
    4127                 :            : //-------------------------------------------------------------------------
    4128                 :            : // Purpose       : Composite Curves
    4129                 :            : //
    4130                 :            : // Special Notes : 
    4131                 :            : //
    4132                 :            : // Creator       : Jason Kraftcheck
    4133                 :            : //
    4134                 :            : // Creation Date : 
    4135                 :            : //-------------------------------------------------------------------------
    4136                 :          0 : CompositeCurve* CompositeEngine::remove_point( TBPoint* dead_point,
    4137                 :            :                                                bool remove_partition,
    4138                 :            :                                                Curve* survivor )
    4139                 :            : { 
    4140 [ #  # ][ #  # ]:          0 :   if( dynamic_cast<CompositePoint*>(dead_point->owner()) )
         [ #  # ][ #  # ]
    4141 [ #  # ][ #  # ]:          0 :     dead_point = dynamic_cast<TBPoint*>(dead_point->owner());
    4142                 :            :  
    4143         [ #  # ]:          0 :   DLIList<TopologyBridge*> query_results;
    4144         [ #  # ]:          0 :   dead_point->get_parents_virt( query_results );
    4145 [ #  # ][ #  # ]:          0 :   if( query_results.size() != 2 )
    4146                 :          0 :     return 0;
    4147                 :            :   
    4148 [ #  # ][ #  # ]:          0 :   Curve* curve1 = dynamic_cast<Curve*>(query_results.get_and_step());
    4149 [ #  # ][ #  # ]:          0 :   Curve* curve2 = dynamic_cast<Curve*>(query_results.get_and_step());
    4150 [ #  # ][ #  # ]:          0 :   assert( curve1 && curve2 );
    4151                 :            :   
    4152         [ #  # ]:          0 :   query_results.clean_out();
    4153         [ #  # ]:          0 :   curve1->get_children( query_results, COMPOSITE_LAYER );
    4154 [ #  # ][ #  # ]:          0 :   assert( query_results.size() == 2 && query_results.move_to( dead_point ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    4155         [ #  # ]:          0 :   query_results.move_to( dead_point );
    4156 [ #  # ][ #  # ]:          0 :   TBPoint* other1 = dynamic_cast<TBPoint*>(query_results.step_and_get());
    4157                 :            :   
    4158         [ #  # ]:          0 :   query_results.clean_out();
    4159         [ #  # ]:          0 :   curve2->get_children( query_results, COMPOSITE_LAYER );
    4160 [ #  # ][ #  # ]:          0 :   assert( query_results.size() == 2 && query_results.move_to( dead_point ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    4161         [ #  # ]:          0 :   query_results.move_to( dead_point );
    4162 [ #  # ][ #  # ]:          0 :   TBPoint* other2 = dynamic_cast<TBPoint*>(query_results.step_and_get());
    4163                 :            :   
    4164                 :            :     // If curves form a closed two-curve loop, we need to 
    4165                 :            :     // specify which point to keep.
    4166         [ #  # ]:          0 :   TBPoint* keep = other1 == other2 ? other1 : 0;
    4167 [ #  # ][ #  # ]:          0 :   if (survivor == curve2) std::swap(curve1, curve2);
    4168 [ #  # ][ #  # ]:          0 :   return composite( curve1, curve2, keep, remove_partition );
    4169                 :            : }
    4170                 :            : 
    4171                 :            : //-------------------------------------------------------------------------
    4172                 :            : // Purpose       : Remove curve partitions beneath a composite curve
    4173                 :            : //
    4174                 :            : // Special Notes : 
    4175                 :            : //
    4176                 :            : // Creator       : Jason Kraftcheck
    4177                 :            : //
    4178                 :            : // Creation Date : 03/11/03
    4179                 :            : //-------------------------------------------------------------------------
    4180                 :          0 : CubitStatus CompositeEngine::remove_partition_point( CompositePoint* comp )
    4181                 :            : {
    4182         [ #  # ]:          0 :   PartitionPoint* pt = dynamic_cast<PartitionPoint*>(comp->get_point());
    4183 [ #  # ][ #  # ]:          0 :   if( !pt || pt->real_point() )
                 [ #  # ]
    4184                 :          0 :     return CUBIT_SUCCESS;
    4185                 :            :   
    4186         [ #  # ]:          0 :   if( comp->next_curve() )
    4187                 :          0 :     return CUBIT_FAILURE;
    4188                 :            :   
    4189         [ #  # ]:          0 :   if ( !PartitionEngine::instance().remove_point( pt ) )
    4190                 :          0 :     return CUBIT_FAILURE;
    4191                 :            :   
    4192         [ #  # ]:          0 :   assert( !comp->get_point() );
    4193                 :          0 :   clean_out_deactivated_geometry();
    4194                 :            :   
    4195                 :          0 :   return CUBIT_SUCCESS;
    4196                 :            : }
    4197                 :            : 
    4198                 :            : //-------------------------------------------------------------------------
    4199                 :            : // Purpose       : Remove surface partitions beneath a composite surface
    4200                 :            : //
    4201                 :            : // Special Notes : 
    4202                 :            : //
    4203                 :            : // Creator       : Jason Kraftcheck
    4204                 :            : //
    4205                 :            : // Creation Date : 03/11/03
    4206                 :            : //-------------------------------------------------------------------------
    4207                 :          0 : CubitStatus CompositeEngine::remove_partition_curves( CompositeCurve* curve )
    4208                 :            : {
    4209 [ #  # ][ #  # ]:          0 :   if( ! dynamic_cast<HiddenEntitySet*>(curve->owner()) )
         [ #  # ][ #  # ]
    4210                 :          0 :     { assert(0); return CUBIT_FAILURE; }
    4211                 :            :   
    4212         [ #  # ]:          0 :   DLIList<CompositeCurve*> hidden_curves;
    4213         [ #  # ]:          0 :   hidden_curves.append( curve );
    4214                 :            :     
    4215                 :            :     // Split composite such that each partition curve to be removed
    4216                 :            :     // is owned by a seperate composite curve.  Put the partitition
    4217                 :            :     // curves in dead_curves and their owning composite curves in
    4218                 :            :     // dead_composites.
    4219                 :            :   int i;
    4220                 :          0 :   CubitStatus result = CUBIT_SUCCESS;
    4221 [ #  # ][ #  # ]:          0 :   DLIList<PartitionCurve*> dead_curves;
    4222 [ #  # ][ #  # ]:          0 :   while( hidden_curves.size() )
    4223                 :            :   {
    4224         [ #  # ]:          0 :     CompositeCurve* comp = hidden_curves.pop();
    4225                 :            :     
    4226                 :            :       // If this curve has a single underlying curve,
    4227                 :            :       // we're done with it.  Add the underlying curve
    4228                 :            :       // to the dead curve list if it is a PartitionCurve
    4229                 :            :       // and move on to the next composite curve.
    4230 [ #  # ][ #  # ]:          0 :     if( comp->num_curves() == 1 )
    4231                 :            :     {
    4232 [ #  # ][ #  # ]:          0 :       SegmentedCurve* segcurve = dynamic_cast<SegmentedCurve*>(comp->get_curve(0));
    4233         [ #  # ]:          0 :       if( segcurve )
    4234                 :            :       {
    4235         [ #  # ]:          0 :         dead_curves.append(segcurve);
    4236                 :            :       }
    4237                 :          0 :       continue;
    4238                 :            :     }
    4239                 :            :     
    4240                 :            :       // Search for a partition curve in the composite
    4241 [ #  # ][ #  # ]:          0 :     for ( i = 1; i < comp->num_curves(); i++ )
    4242 [ #  # ][ #  # ]:          0 :       if( dynamic_cast<SegmentedCurve*>(comp->get_curve(i)) )
         [ #  # ][ #  # ]
    4243                 :          0 :         break;
    4244                 :            :         
    4245                 :            :       // Composite doesn't contain any partition curves.
    4246                 :            :       // Move on to the next composite curve.
    4247 [ #  # ][ #  # ]:          0 :     if( i == comp->num_curves() )
    4248                 :          0 :       continue;
    4249                 :            :     
    4250                 :            :       // Split composite curve at the partition curve. 
    4251                 :            :     Curve* r1, *r2;
    4252 [ #  # ][ #  # ]:          0 :     if ( !split( comp, i, r1, r2 ) )
    4253                 :            :     {
    4254                 :          0 :       result = CUBIT_FAILURE;
    4255                 :          0 :       continue;
    4256                 :            :     }
    4257                 :            :     
    4258                 :            :       // Add the resulting composites back onto hidden_curves.
    4259                 :            :       // Continue processing them until all partitions are in their
    4260                 :            :       // own composite, or the composite contains no more partitions.
    4261         [ #  # ]:          0 :     CompositeCurve* comp1 = dynamic_cast<CompositeCurve*>(r1);
    4262         [ #  # ]:          0 :     CompositeCurve* comp2 = dynamic_cast<CompositeCurve*>(r2);
    4263 [ #  # ][ #  # ]:          0 :     assert(comp1 && comp2);
    4264         [ #  # ]:          0 :     hidden_curves.append(comp1);
    4265         [ #  # ]:          0 :     hidden_curves.append(comp2);
    4266                 :            :   }
    4267                 :            :   
    4268                 :            :   
    4269                 :            :     // Now actually remove the partition curves
    4270 [ #  # ][ #  # ]:          0 :   while ( dead_curves.size() )
    4271 [ #  # ][ #  # ]:          0 :     if ( ! PartitionEngine::instance().remove_curve( dead_curves.pop() ) )
         [ #  # ][ #  # ]
    4272                 :          0 :       result = CUBIT_FAILURE;
    4273                 :            :   
    4274                 :            :     // Last, delete the remaining composite curves
    4275         [ #  # ]:          0 :   clean_out_deactivated_geometry();
    4276                 :            :   
    4277         [ #  # ]:          0 :   return result;
    4278                 :            : }
    4279                 :            : 
    4280                 :            : //-------------------------------------------------------------------------
    4281                 :            : // Purpose       : Create a point-curve given a point hidden by a composite
    4282                 :            : //                 surface.
    4283                 :            : //
    4284                 :            : // Special Notes : 
    4285                 :            : //
    4286                 :            : // Creator       : Jason Kraftcheck
    4287                 :            : //
    4288                 :            : // Creation Date : 02/27/04
    4289                 :            : //-------------------------------------------------------------------------
    4290                 :          0 : CompositeCurve* CompositeEngine::restore_point_in_surface( TBPoint* pt )
    4291                 :            : {
    4292                 :            :     // If real point is hidden by a composite surface, it should
    4293                 :            :     // have already been replaced by a composite point. Get the
    4294                 :            :     // composite point.
    4295         [ #  # ]:          0 :   CompositePoint* point = dynamic_cast<CompositePoint*>(pt);
    4296 [ #  # ][ #  # ]:          0 :   if (!point && !(point = dynamic_cast<CompositePoint*>(pt->owner())))
         [ #  # ][ #  # ]
    4297                 :          0 :     return NULL;
    4298                 :            :   
    4299                 :            :     // Get the surface hiding the point.
    4300         [ #  # ]:          0 :   HiddenEntitySet* hidden_set = dynamic_cast<HiddenEntitySet*>(point->owner());
    4301         [ #  # ]:          0 :   if (!hidden_set)
    4302                 :          0 :     return NULL;
    4303                 :            :     
    4304         [ #  # ]:          0 :   CompositeSurface* surface = dynamic_cast<CompositeSurface*>(hidden_set->owner());
    4305         [ #  # ]:          0 :   if (!surface)
    4306                 :          0 :     return NULL;
    4307                 :            :   
    4308                 :            :     // Check if the point is already owned by a point curve.
    4309                 :          0 :   CompositeCurve* curve = 0;
    4310         [ #  # ]:          0 :   while ( (curve = point->next_curve(curve)) )
    4311         [ #  # ]:          0 :     if (curve->geometry_type() == POINT_CURVE_TYPE)
    4312         [ #  # ]:          0 :       return restore_curve(curve) ? curve : NULL;
    4313                 :            :   
    4314                 :            :     // Construct null-geometry composite curve
    4315                 :          0 :   surface->hidden_entities().restore(point);
    4316         [ #  # ]:          0 :   curve = new CompositeCurve(point);
    4317         [ #  # ]:          0 :   CompositeCoEdge* coedge = new CompositeCoEdge(curve);
    4318         [ #  # ]:          0 :   CompositeLoop* loop = new CompositeLoop();
    4319                 :          0 :   loop->insert_after( coedge, NULL );
    4320                 :          0 :   surface->add(loop);
    4321                 :          0 :   return curve;
    4322                 :            : }
    4323                 :            :   
    4324                 :            : //-------------------------------------------------------------------------
    4325                 :            : // Purpose       : Create a new cosurface with appropriate sense
    4326                 :            : //
    4327                 :            : // Special Notes : 
    4328                 :            : //
    4329                 :            : // Creator       : Jason Kraftcheck
    4330                 :            : //
    4331                 :            : // Creation Date : 09/27/04
    4332                 :            : //-------------------------------------------------------------------------
    4333                 :          0 : static CompositeCoSurf* cme_create_cosurf( CompositeLump* lump,
    4334                 :            :                                            CompositeSurface* surf )
    4335                 :            : {
    4336         [ #  # ]:          0 :   Surface* real_surf = surf->get_surface(0);
    4337                 :            :   
    4338 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> shells, lumps(1);
                 [ #  # ]
    4339         [ #  # ]:          0 :   real_surf->get_parents( shells );
    4340 [ #  # ][ #  # ]:          0 :   while (shells.size())
    4341                 :            :   {
    4342         [ #  # ]:          0 :     TopologyBridge* shell = shells.pop();
    4343         [ #  # ]:          0 :     lumps.clean_out();
    4344         [ #  # ]:          0 :     shell->get_parents( lumps );
    4345 [ #  # ][ #  # ]:          0 :     assert( lumps.size() == 1 );
    4346         [ #  # ]:          0 :     TopologyBridge* real_lump = lumps.pop();
    4347 [ #  # ][ #  # ]:          0 :     if (real_lump->owner() == lump)
                 [ #  # ]
    4348                 :            :     {
    4349 [ #  # ][ #  # ]:          0 :       CubitSense sense = real_surf->get_shell_sense( dynamic_cast<ShellSM*>(shell) );
    4350         [ #  # ]:          0 :       if (sense == CUBIT_UNKNOWN)
    4351                 :          0 :         sense = CUBIT_FORWARD;
    4352 [ #  # ][ #  # ]:          0 :       else if (surf->get_sense(0) == CUBIT_REVERSED)
    4353                 :          0 :         sense = (sense == CUBIT_REVERSED) ? CUBIT_FORWARD : CUBIT_REVERSED;
    4354                 :            :     
    4355 [ #  # ][ #  # ]:          0 :       CompositeCoSurf* result = new CompositeCoSurf(sense);
    4356         [ #  # ]:          0 :       surf->add( result );
    4357                 :          0 :       return result;
    4358                 :            :     }
    4359                 :            :   }
    4360                 :            :   
    4361         [ #  # ]:          0 :   return NULL;
    4362                 :            : }
    4363                 :            : 
    4364                 :            : //-------------------------------------------------------------------------
    4365                 :            : // Purpose       : Restore a surface hidden by a composite volume
    4366                 :            : //
    4367                 :            : // Special Notes : 
    4368                 :            : //
    4369                 :            : // Creator       : Jason Kraftcheck
    4370                 :            : //
    4371                 :            : // Creation Date : 09/27/04
    4372                 :            : //-------------------------------------------------------------------------
    4373                 :          0 : CubitStatus CompositeEngine::restore_surface( Surface* surf,
    4374                 :            :                                               Surface*& stitch_partner )
    4375                 :            : { 
    4376                 :            :     // find composite lump owning the curve
    4377                 :          0 :   TopologyBridge* bridge = surf;
    4378                 :          0 :   HiddenEntitySet* owner_set = NULL;
    4379 [ #  # ][ #  # ]:          0 :   while( bridge && !(owner_set = dynamic_cast<HiddenEntitySet*>(bridge->owner())) )
         [ #  # ][ #  # ]
                 [ #  # ]
    4380                 :            :   {
    4381 [ #  # ][ #  # ]:          0 :     bridge = dynamic_cast<TopologyBridge*>(bridge->owner());
    4382                 :            :   }
    4383                 :            :   
    4384         [ #  # ]:          0 :   if( !owner_set )
    4385                 :          0 :     return CUBIT_FAILURE;
    4386                 :            :   
    4387 [ #  # ][ #  # ]:          0 :   CompositeLump* lump = dynamic_cast<CompositeLump*>(owner_set->owner());
    4388         [ #  # ]:          0 :   if( !lump )
    4389                 :          0 :     return CUBIT_FAILURE;
    4390                 :            :   
    4391         [ #  # ]:          0 :   CompositeSurface* surf1 = dynamic_cast<CompositeSurface*>(surf);
    4392         [ #  # ]:          0 :   if( !surf1 )
    4393 [ #  # ][ #  # ]:          0 :     surf1 = dynamic_cast<CompositeSurface*>(surf1->owner());
    4394         [ #  # ]:          0 :   if( !surf1 )
    4395                 :          0 :     return CUBIT_FAILURE;
    4396                 :            :   
    4397                 :            :     // Check if and curves are hidden by a CompositeSurface, and
    4398                 :            :     // if so, split the composite surface so that the curve(s)
    4399                 :            :     // are no longer hidden.
    4400                 :            :   HiddenEntitySet* hs;
    4401                 :            :   CompositeLoop* loop;
    4402                 :            :   CompositeCoEdge* coedge;
    4403 [ #  # ][ #  # ]:          0 :   for (loop = surf1->first_loop(); loop; loop = surf1->next_loop(loop))
                 [ #  # ]
    4404                 :            :   {
    4405         [ #  # ]:          0 :     coedge = loop->first_coedge();
    4406 [ #  # ][ #  # ]:          0 :     do {
    4407         [ #  # ]:          0 :       CompositeCurve* curv = coedge->get_curve();
    4408 [ #  # ][ #  # ]:          0 :       if ( (hs = dynamic_cast<HiddenEntitySet*>(curv->owner()))
    4409 [ #  # ][ #  # ]:          0 :         && dynamic_cast<CompositeSurface*>(hs->owner())
                 [ #  # ]
    4410 [ #  # ][ #  # ]:          0 :         && !restore_curve(curv))
         [ #  # ][ #  # ]
    4411                 :          0 :         return CUBIT_FAILURE;
    4412         [ #  # ]:          0 :     } while ((coedge = loop->next_coedge(coedge)) != loop->first_coedge());
    4413                 :            :   } 
    4414                 :            :   
    4415                 :            :     // Un-hide surf's and children
    4416         [ #  # ]:          0 :   CompositeSurface* surf2 = surf1->unstitch();
    4417         [ #  # ]:          0 :   cme_unhide_surface( surf1 );
    4418         [ #  # ]:          0 :   if (surf2 != surf)
    4419         [ #  # ]:          0 :     cme_unhide_surface( surf2 );
    4420                 :            :   
    4421                 :            :     // Find affected shells.
    4422                 :          0 :   bool all_connected = true;
    4423         [ #  # ]:          0 :   DLIList<CompositeShell*> modified_shell_list;
    4424 [ #  # ][ #  # ]:          0 :   DLIList<CompositeCurve*> curve_list;
    4425 [ #  # ][ #  # ]:          0 :   for (loop = surf1->first_loop(); loop; loop = surf1->next_loop(loop))
                 [ #  # ]
    4426                 :            :   {
    4427         [ #  # ]:          0 :     coedge = loop->first_coedge();
    4428 [ #  # ][ #  # ]:          0 :     do {
    4429         [ #  # ]:          0 :       CompositeCurve* curv = coedge->get_curve();
    4430         [ #  # ]:          0 :       curv->get_stitched( curve_list );
    4431                 :          0 :       bool found_adj_surf = false;
    4432 [ #  # ][ #  # ]:          0 :       while (curve_list.size())
    4433                 :            :       {
    4434         [ #  # ]:          0 :         curv = curve_list.pop();
    4435                 :          0 :         CompositeCoEdge* curve_coedge = 0;
    4436 [ #  # ][ #  # ]:          0 :         while ((curve_coedge = curv->next_coedge(curve_coedge)))
    4437                 :            :         {
    4438 [ #  # ][ #  # ]:          0 :           if (!curve_coedge->get_loop())
    4439                 :          0 :             continue;
    4440                 :            : 
    4441 [ #  # ][ #  # ]:          0 :           CompositeSurface* adj_surf = curve_coedge->get_loop()->get_surface();
    4442 [ #  # ][ #  # ]:          0 :           if (adj_surf == surf1 || adj_surf == surf2)
    4443                 :          0 :             continue;
    4444                 :            :             
    4445                 :          0 :           CompositeCoSurf* cosurf = 0;
    4446 [ #  # ][ #  # ]:          0 :           while ((cosurf = adj_surf->next_co_surface( cosurf )))
    4447                 :            :           {
    4448 [ #  # ][ #  # ]:          0 :             if (cosurf->get_shell()->get_lump() == lump)
                 [ #  # ]
    4449                 :            :             {
    4450                 :          0 :               found_adj_surf = true;
    4451 [ #  # ][ #  # ]:          0 :               modified_shell_list.append_unique( cosurf->get_shell() );
    4452                 :            :             }
    4453                 :            :           }
    4454                 :            :         }
    4455                 :            :       }
    4456                 :            :       
    4457         [ #  # ]:          0 :       if (!found_adj_surf)
    4458                 :          0 :         all_connected = false;
    4459                 :            :         
    4460         [ #  # ]:          0 :     } while ((coedge = loop->next_coedge( coedge )) != loop->first_coedge());
    4461                 :            :   }
    4462                 :            :   
    4463                 :            :   
    4464                 :            :     // Create Co-Surfacs
    4465         [ #  # ]:          0 :   CompositeCoSurf *cosurf2, *cosurf1 = cme_create_cosurf( lump, surf1 );
    4466         [ #  # ]:          0 :   if (surf1 == surf2)
    4467                 :            :   {
    4468         [ #  # ]:          0 :     CubitSense sense = cosurf1->sense() == CUBIT_FORWARD ?
    4469         [ #  # ]:          0 :                        CUBIT_REVERSED : CUBIT_FORWARD;
    4470 [ #  # ][ #  # ]:          0 :     cosurf2 = new CompositeCoSurf( sense );
    4471         [ #  # ]:          0 :     surf2->add( cosurf2 );
    4472                 :            :   }
    4473                 :            :   else
    4474                 :            :   {
    4475         [ #  # ]:          0 :     cosurf2 = cme_create_cosurf( lump, surf2 );
    4476                 :            :   }
    4477                 :            : 
    4478                 :            : 
    4479                 :          0 :   CompositeShell* shell_to_split = 0;
    4480 [ #  # ][ #  # ]:          0 :   if (modified_shell_list.size() == 0)
    4481                 :            :   {
    4482                 :            :     // No adjacent shells -- create void
    4483 [ #  # ][ #  # ]:          0 :     CompositeShell* shell_to_split = new CompositeShell();
    4484         [ #  # ]:          0 :     lump->add( shell_to_split );
    4485                 :            :     
    4486                 :            :     // If surface is closed, set all_connected to true
    4487                 :            :     // to indicate that the volume must be split (to create
    4488                 :            :     // the void)
    4489                 :          0 :     loop = 0;
    4490                 :          0 :     all_connected = true;
    4491 [ #  # ][ #  # ]:          0 :     while ((loop = surf1->next_loop(loop)))
    4492                 :            :     {
    4493         [ #  # ]:          0 :       coedge = loop->first_coedge();
    4494 [ #  # ][ #  # ]:          0 :       do {
    4495         [ #  # ]:          0 :         CompositeCurve* curv = coedge->get_curve();
    4496                 :          0 :         CompositeCoEdge* curv_coedge = 0;
    4497                 :          0 :         bool closed = false;
    4498 [ #  # ][ #  # ]:          0 :         while ((curv_coedge = curv->next_coedge(curv_coedge)))
    4499                 :            :         {
    4500 [ #  # ][ #  # ]:          0 :           if (curv_coedge != coedge &&
    4501 [ #  # ][ #  # ]:          0 :               curv_coedge->get_loop() &&
                 [ #  # ]
    4502 [ #  # ][ #  # ]:          0 :               (curv_coedge->get_loop()->get_surface() == surf1 ||
                 [ #  # ]
    4503 [ #  # ][ #  # ]:          0 :                curv_coedge->get_loop()->get_surface() == surf2))
    4504                 :            :           {
    4505                 :          0 :             closed = true;
    4506                 :          0 :             break;
    4507                 :            :           }
    4508                 :            :         }
    4509         [ #  # ]:          0 :         if (!closed)
    4510                 :          0 :           all_connected = false;
    4511         [ #  # ]:          0 :       } while ((coedge = loop->next_coedge(coedge)) != loop->first_coedge());
    4512                 :            :     }
    4513                 :            :   }
    4514                 :            :   else
    4515                 :            :   {
    4516                 :            :     // otherwise combine all connected shells
    4517         [ #  # ]:          0 :     modified_shell_list.reverse();
    4518         [ #  # ]:          0 :     shell_to_split = modified_shell_list.pop();
    4519 [ #  # ][ #  # ]:          0 :     while (modified_shell_list.size())
    4520                 :            :     {
    4521         [ #  # ]:          0 :       CompositeShell* shell = modified_shell_list.pop();
    4522 [ #  # ][ #  # ]:          0 :       while (CompositeCoSurf* cosurf = shell->first_co_surf())
    4523                 :            :       {
    4524         [ #  # ]:          0 :         shell->remove( cosurf );
    4525         [ #  # ]:          0 :         shell_to_split->add( cosurf );
    4526                 :            :       }
    4527         [ #  # ]:          0 :       lump->remove( shell );
    4528 [ #  # ][ #  # ]:          0 :       delete shell;
    4529                 :          0 :     }
    4530                 :            :   }
    4531                 :            :   
    4532         [ #  # ]:          0 :   shell_to_split->add( cosurf1 );
    4533         [ #  # ]:          0 :   shell_to_split->add( cosurf2 );
    4534                 :            :   
    4535         [ #  # ]:          0 :   stitch_partner = surf1 == surf2 ? NULL : surf2;
    4536         [ #  # ]:          0 :   if (all_connected)
    4537                 :            :   {
    4538         [ #  # ]:          0 :     CompositeLump* new_lump = split_lump( shell_to_split );
    4539 [ #  # ][ #  # ]:          0 :     lump->get_body()->add( new_lump );
    4540                 :            :     //if (!new_lump->has_hidden_entities())
    4541                 :            :     //  remove_composite( new_lump );
    4542                 :            :   }
    4543                 :            : //  if (!lump->has_hidden_entities())
    4544                 :            : //    remove_composite( lump );
    4545                 :            :   
    4546         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    4547                 :            : }
    4548                 :            : 
    4549                 :            : //-------------------------------------------------------------------------
    4550                 :            : // Purpose       : Test if a CompositeShell needs to be split, and if
    4551                 :            : //                 so, split it and the owning lump.
    4552                 :            : //
    4553                 :            : // Special Notes : 
    4554                 :            : //
    4555                 :            : // Creator       : Jason Kraftcheck
    4556                 :            : //
    4557                 :            : // Creation Date : 09/27/04
    4558                 :            : //-------------------------------------------------------------------------
    4559                 :          0 : CompositeLump* CompositeEngine::split_lump( CompositeShell* shell_to_split )
    4560                 :            : {
    4561                 :            :   int i, j;
    4562                 :            :   
    4563                 :            :     // split the shell
    4564         [ #  # ]:          0 :   CompositeShell* new_shell = split_shell( shell_to_split );
    4565         [ #  # ]:          0 :   if (!new_shell)
    4566         [ #  # ]:          0 :     return shell_to_split->get_lump();
    4567                 :            :     
    4568                 :            :     // Get list of shells to move to new lump
    4569 [ #  # ][ #  # ]:          0 :   shell_to_split->get_lump()->add( new_shell );
    4570 [ #  # ][ #  # ]:          0 :   DLIList<CompositeShell*> shell_list, shells_to_move;
                 [ #  # ]
    4571         [ #  # ]:          0 :   shell_list.append( new_shell );
    4572         [ #  # ]:          0 :   shells_to_move.append( new_shell );
    4573 [ #  # ][ #  # ]:          0 :   while (shell_list.size())
    4574                 :            :   {
    4575         [ #  # ]:          0 :     CompositeShell* shell = shell_list.pop();
    4576                 :          0 :     CompositeCoSurf* cosurf = 0;
    4577 [ #  # ][ #  # ]:          0 :     while ((cosurf = shell->next_co_surf( cosurf )))
    4578                 :            :     {
    4579         [ #  # ]:          0 :       CompositeSurface* surf = cosurf->get_surface();
    4580         [ #  # ]:          0 :       surf = surf->get_stitch_partner();
    4581         [ #  # ]:          0 :       if (!surf)
    4582                 :          0 :         continue;
    4583                 :            :       
    4584                 :          0 :       CompositeCoSurf* surf_cosurf = 0;
    4585 [ #  # ][ #  # ]:          0 :       while ((surf_cosurf = surf->next_co_surface( surf_cosurf )))
    4586                 :            :       {
    4587         [ #  # ]:          0 :         CompositeShell* surf_shell = surf_cosurf->get_shell();
    4588 [ #  # ][ #  # ]:          0 :         if (surf_shell == shell_to_split ||
    4589 [ #  # ][ #  # ]:          0 :             surf_shell->get_lump() != shell_to_split->get_lump() ||
         [ #  # ][ #  # ]
    4590         [ #  # ]:          0 :             shells_to_move.is_in_list( surf_shell ))
    4591                 :          0 :           continue;
    4592                 :            :         
    4593         [ #  # ]:          0 :         shell_list.append( surf_shell );
    4594         [ #  # ]:          0 :         shells_to_move.append( surf_shell );
    4595                 :            :       }
    4596                 :            :     }
    4597                 :            :   }
    4598                 :            :   
    4599                 :            :     // Get list of real lumps defining composite lump that
    4600                 :            :     // are to be moved to the new composite lump
    4601 [ #  # ][ #  # ]:          0 :   DLIList<Lump*> lumps_to_move;
    4602 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> shells, lumps;
         [ #  # ][ #  # ]
    4603 [ #  # ][ #  # ]:          0 :   for (i = shells_to_move.size(); i--; )
    4604                 :            :   {
    4605         [ #  # ]:          0 :     CompositeShell* shell = shells_to_move.get_and_step();
    4606                 :          0 :     CompositeCoSurf* cosurf = 0;
    4607 [ #  # ][ #  # ]:          0 :     while ((cosurf = shell->next_co_surf( cosurf )))
    4608                 :            :     {
    4609         [ #  # ]:          0 :       CompositeSurface* surf = cosurf->get_surface();
    4610 [ #  # ][ #  # ]:          0 :       for (j = 0; j < surf->num_surfs(); j++)
    4611                 :            :       {
    4612         [ #  # ]:          0 :         Surface* real_surf = surf->get_surface(j);
    4613         [ #  # ]:          0 :         real_surf->get_parents_virt( shells );
    4614 [ #  # ][ #  # ]:          0 :         while (shells.size())
    4615                 :            :         {
    4616 [ #  # ][ #  # ]:          0 :           shells.pop()->get_parents_virt( lumps );
    4617 [ #  # ][ #  # ]:          0 :           assert( lumps.size() == 1 );
    4618         [ #  # ]:          0 :           TopologyBridge* lump = lumps.pop();
    4619 [ #  # ][ #  # ]:          0 :           if (lump->owner() == shell_to_split->get_lump())
         [ #  # ][ #  # ]
    4620 [ #  # ][ #  # ]:          0 :             lumps_to_move.append_unique( dynamic_cast<Lump*>(lump) );
    4621                 :            :         }
    4622                 :            :       }
    4623                 :            :     }
    4624                 :            :   }
    4625                 :            :   
    4626 [ #  # ][ #  # ]:          0 :   if (lumps_to_move.size() == shell_to_split->get_lump()->num_lumps())
         [ #  # ][ #  # ]
    4627         [ #  # ]:          0 :     return shell_to_split->get_lump();
    4628                 :            :   
    4629                 :            :     // Split composite lump and move shells to new lump
    4630 [ #  # ][ #  # ]:          0 :   VGArray<int> vol_indices( lumps_to_move.size() );
                 [ #  # ]
    4631         [ #  # ]:          0 :   lumps_to_move.reset();
    4632 [ #  # ][ #  # ]:          0 :   for (i = lumps_to_move.size(); i--; )
    4633 [ #  # ][ #  # ]:          0 :     vol_indices[i] = shell_to_split->get_lump()->index_of( lumps_to_move.next(i) );
         [ #  # ][ #  # ]
    4634 [ #  # ][ #  # ]:          0 :   CompositeLump* new_lump = shell_to_split->get_lump()->split( vol_indices );
    4635         [ #  # ]:          0 :   new_lump->add( new_shell );
    4636         [ #  # ]:          0 :   shells_to_move.reverse();
    4637 [ #  # ][ #  # ]:          0 :   while (shells_to_move.size())
    4638                 :            :   {
    4639         [ #  # ]:          0 :     CompositeShell* shell = shells_to_move.pop();
    4640 [ #  # ][ #  # ]:          0 :     shell_to_split->get_lump()->remove( shell );
    4641         [ #  # ]:          0 :     new_lump->add( new_shell );
    4642                 :            :   }
    4643                 :            :   
    4644                 :            :     // Move any hidden entities from old composite to new
    4645 [ #  # ][ #  # ]:          0 :   HiddenEntitySet* old_set = &shell_to_split->get_lump()->hidden_entities();
    4646 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> surfs;
    4647 [ #  # ][ #  # ]:          0 :   while (lumps_to_move.size())
    4648                 :            :   {
    4649         [ #  # ]:          0 :     Lump* lump = lumps_to_move.pop();
    4650         [ #  # ]:          0 :     lump->get_children( shells, true, COMPOSITE_LAYER-1 );
    4651 [ #  # ][ #  # ]:          0 :     while (shells.size())
    4652                 :            :     {
    4653         [ #  # ]:          0 :       TopologyBridge* shell = shells.pop();
    4654         [ #  # ]:          0 :       shell->get_children( surfs, true, COMPOSITE_LAYER );
    4655 [ #  # ][ #  # ]:          0 :       while (surfs.size())
    4656                 :            :       {
    4657 [ #  # ][ #  # ]:          0 :         CompositeSurface* surf = dynamic_cast<CompositeSurface*>(surfs.pop());
    4658 [ #  # ][ #  # ]:          0 :         if (surf->owner() != old_set)
    4659                 :          0 :           continue;
    4660                 :            :           
    4661         [ #  # ]:          0 :         cme_unhide_surface( surf );
    4662 [ #  # ][ #  # ]:          0 :         cme_hide_surface( new_lump->hidden_entities(), surf );
    4663                 :            :       }
    4664                 :            :     }
    4665                 :            :   }
    4666                 :            : 
    4667         [ #  # ]:          0 :   return new_lump;
    4668                 :            : }
    4669                 :            :   
    4670                 :            : 
    4671                 :            : 
    4672                 :            : //-------------------------------------------------------------------------
    4673                 :            : // Purpose       : Recreate composites stored in attributes
    4674                 :            : //
    4675                 :            : // Special Notes : 
    4676                 :            : //
    4677                 :            : // Creator       : Jason Kraftcheck
    4678                 :            : //
    4679                 :            : // Creation Date : 06/18/02
    4680                 :            : //-------------------------------------------------------------------------
    4681                 :       1257 : CubitStatus CompositeEngine::import_geometry( DLIList<TopologyBridge*>& imported_geom )
    4682                 :            : {
    4683                 :       1257 :   CubitStatus result = CUBIT_SUCCESS;
    4684                 :            :   int i;
    4685                 :            :   
    4686         [ +  - ]:       1257 :   DLIList<BodySM*>  bodies;
    4687 [ +  - ][ +  - ]:       2514 :   DLIList<Lump*>    lumps,    temp_lumps;
         [ +  - ][ +  - ]
    4688 [ +  - ][ +  - ]:       2514 :   DLIList<Surface*> surfaces, temp_surfaces;
         [ +  - ][ +  - ]
    4689 [ +  - ][ +  - ]:       2514 :   DLIList<Curve*>   curves,   temp_curves;
         [ +  - ][ +  - ]
    4690 [ +  - ][ +  - ]:       2514 :   DLIList<TBPoint*>  points,   temp_points;
         [ +  - ][ +  - ]
    4691                 :            :   
    4692 [ +  - ][ +  - ]:       3410 :   CAST_LIST( imported_geom, bodies,   BodySM  );
         [ +  - ][ -  + ]
         [ +  + ][ +  - ]
                 [ +  + ]
    4693 [ +  - ][ +  - ]:       3410 :   CAST_LIST( imported_geom, lumps,    Lump    );
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
                 [ +  + ]
    4694 [ +  - ][ +  - ]:       3410 :   CAST_LIST( imported_geom, surfaces, Surface );
         [ +  - ][ -  + ]
         [ +  + ][ +  - ]
                 [ +  + ]
    4695 [ +  - ][ +  - ]:       3410 :   CAST_LIST( imported_geom, curves,   Curve   );
         [ +  - ][ -  + ]
         [ +  + ][ +  - ]
                 [ +  + ]
    4696 [ +  - ][ +  - ]:       3410 :   CAST_LIST( imported_geom, points,   TBPoint   );
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
                 [ +  + ]
    4697                 :            : 
    4698 [ +  - ][ +  - ]:       1257 :   i = bodies.size() + lumps.size() + surfaces.size() + curves.size() + points.size();
         [ +  - ][ +  - ]
                 [ +  - ]
    4699 [ +  - ][ -  + ]:       1257 :   if( i != imported_geom.size() )
    4700                 :            :   {
    4701 [ #  # ][ #  # ]:          0 :     PRINT_WARNING("CompositeEngine: unknown geometry types encountered during import.\n");
         [ #  # ][ #  # ]
    4702                 :            :   }
    4703                 :            :   
    4704                 :            :     // get points from free curves
    4705 [ +  - ][ +  + ]:       1455 :   for( i = curves.size(); i--; )
    4706                 :            :   {
    4707         [ +  - ]:        198 :     Curve* ptr = curves.get_and_step();
    4708         [ +  - ]:        198 :     temp_points.clean_out();
    4709         [ +  - ]:        198 :     ptr->points( temp_points );
    4710         [ +  - ]:        198 :     points += temp_points;
    4711                 :            :   }
    4712                 :            :   
    4713                 :            :     // get points and curves from free surfaces
    4714 [ +  - ][ +  + ]:       1268 :   for( i = surfaces.size(); i--; )
    4715                 :            :   {
    4716         [ +  - ]:         11 :     Surface* ptr = surfaces.get_and_step();
    4717                 :            :     
    4718         [ +  - ]:         11 :     temp_points.clean_out();
    4719         [ +  - ]:         11 :     temp_curves.clean_out();
    4720                 :            :     
    4721         [ +  - ]:         11 :     ptr->points( temp_points );
    4722         [ +  - ]:         11 :     ptr->curves( temp_curves );
    4723                 :            :     
    4724         [ +  - ]:         11 :     points += temp_points;
    4725         [ +  - ]:         11 :     curves += temp_curves;
    4726                 :            :   }
    4727                 :            :   
    4728                 :            :     // get child geometry from free lumps
    4729                 :            :     // (are there ever any free lumps?)
    4730 [ +  - ][ -  + ]:       1257 :   for( i = lumps.size(); i--; )
    4731                 :            :   {
    4732         [ #  # ]:          0 :     Lump* ptr = lumps.get_and_step();
    4733                 :            :     
    4734         [ #  # ]:          0 :     temp_points.clean_out();
    4735         [ #  # ]:          0 :     temp_curves.clean_out();
    4736         [ #  # ]:          0 :     temp_surfaces.clean_out();
    4737                 :            :     
    4738         [ #  # ]:          0 :     ptr->points( temp_points );
    4739         [ #  # ]:          0 :     ptr->curves( temp_curves );
    4740         [ #  # ]:          0 :     ptr->surfaces( temp_surfaces );
    4741                 :            :     
    4742         [ #  # ]:          0 :     points += temp_points;
    4743         [ #  # ]:          0 :     curves += temp_curves;
    4744         [ #  # ]:          0 :     surfaces += temp_surfaces;
    4745                 :            :   }
    4746                 :            :   
    4747                 :            :     // get child geometry from bodies
    4748 [ +  - ][ +  + ]:       3201 :   for( i = bodies.size(); i--; )
    4749                 :            :   {
    4750         [ +  - ]:       1944 :     BodySM* ptr = bodies.get_and_step();
    4751                 :            :     
    4752         [ +  - ]:       1944 :     temp_points.clean_out();
    4753         [ +  - ]:       1944 :     temp_curves.clean_out();
    4754         [ +  - ]:       1944 :     temp_surfaces.clean_out();
    4755         [ +  - ]:       1944 :     temp_lumps.clean_out();
    4756                 :            :     
    4757         [ +  - ]:       1944 :     ptr->points( temp_points );
    4758         [ +  - ]:       1944 :     ptr->curves( temp_curves );
    4759         [ +  - ]:       1944 :     ptr->surfaces( temp_surfaces );
    4760         [ +  - ]:       1944 :     ptr->lumps( temp_lumps );
    4761                 :            :     
    4762         [ +  - ]:       1944 :     points += temp_points;
    4763         [ +  - ]:       1944 :     curves += temp_curves;
    4764         [ +  - ]:       1944 :     surfaces += temp_surfaces;
    4765         [ +  - ]:       1944 :     lumps += temp_lumps;
    4766                 :            :   }
    4767                 :            : 
    4768                 :            :  
    4769                 :            :   // assert that lists do not contain duplicates
    4770                 :            :   //assert( (i = points.size(),   points.uniquify_ordered(),   i == points.size()  ) );
    4771                 :            :   //assert( (i = curves.size(),   curves.uniquify_ordered(),   i == curves.size()  ) );  
    4772         [ +  - ]:       1257 :   points.uniquify_ordered(); // can have duplicates in some non-manifold cases
    4773         [ +  - ]:       1257 :   curves.uniquify_ordered(); // can have duplicates in some non-manifold cases
    4774 [ +  - ][ +  - ]:       1257 :   assert( (i = surfaces.size(), surfaces.uniquify_ordered(), i == surfaces.size()) );
         [ +  - ][ -  + ]
    4775 [ +  - ][ +  - ]:       1257 :   assert( (i = lumps.size(),    lumps.uniquify_ordered(),    i == lumps.size()   ) );
         [ +  - ][ -  + ]
    4776                 :            :   
    4777 [ +  - ][ +  - ]:       2317 :   if ( CGMApp::instance()->attrib_manager()->auto_actuate_flag(CA_COMPOSITE_VG) &&
         [ +  - ][ +  + ]
         [ +  - ][ +  + ]
    4778 [ +  - ][ +  - ]:       1060 :        CGMApp::instance()->attrib_manager()->auto_read_flag(CA_COMPOSITE_VG) )
                 [ +  - ]
    4779                 :            :   {
    4780                 :            : 
    4781                 :            :     // Loop through the surfaces and if there is a 
    4782                 :            :     // TOPLOGY_BRIDGE_ID attribute get the id and set
    4783                 :            :     // it in the toplogy bridge for the surface.
    4784         [ +  - ]:       1060 :     surfaces.reset();
    4785 [ +  - ][ +  + ]:      12249 :     for(i=surfaces.size(); i--;)
    4786                 :            :     {
    4787         [ +  - ]:      11189 :       Surface *s = surfaces.get_and_step();
    4788                 :      11189 :       GeometryEntity *ge = dynamic_cast<GeometryEntity*>(s);
    4789                 :      11189 :       TopologyBridge *tb = dynamic_cast<TopologyBridge*>(s);
    4790 [ +  - ][ +  - ]:      11189 :       if(ge && tb)
    4791                 :            :       {
    4792         [ +  - ]:      11189 :         DLIList<CubitSimpleAttrib> list;
    4793 [ +  - ][ +  - ]:      11189 :         ge->get_simple_attribute("TOPOLOGY_BRIDGE_ID",list);
                 [ +  - ]
    4794         [ +  - ]:      11189 :         list.reset();
    4795 [ +  - ][ -  + ]:      11189 :         for(int j = list.size(); j--;)
    4796                 :            :         {
    4797         [ #  # ]:          0 :           const CubitSimpleAttrib& attrib = list.get_and_step();
    4798 [ #  # ][ #  # ]:          0 :           assert(attrib.int_data_list().size() == 1);
                 [ #  # ]
    4799 [ #  # ][ #  # ]:          0 :           int id = attrib.int_data_list()[0];
    4800         [ #  # ]:          0 :           ge->set_saved_id(id);
    4801                 :            :           
    4802 [ #  # ][ #  # ]:          0 :           std::vector<CubitString> names = attrib.string_data_list();
    4803 [ #  # ][ #  # ]:          0 :           if(!names.empty())
    4804 [ #  # ][ #  # ]:          0 :             names.erase(names.begin());
    4805                 :            : 
    4806         [ #  # ]:          0 :           ge->set_saved_names( names );
    4807                 :            : 
    4808         [ #  # ]:          0 :           tb->remove_simple_attribute_virt(attrib);
    4809 [ #  # ][ +  - ]:      11189 :         }
    4810                 :            :       }
    4811                 :            :     }
    4812                 :            : 
    4813                 :            :     // Need to do curves here too.
    4814         [ +  - ]:       1060 :     curves.reset();
    4815 [ +  - ][ +  + ]:      24335 :     for(i=curves.size(); i--;)
    4816                 :            :     {
    4817         [ +  - ]:      23275 :       Curve *c = curves.get_and_step();
    4818                 :      23275 :       GeometryEntity *ge = dynamic_cast<GeometryEntity*>(c);
    4819                 :      23275 :       TopologyBridge *tb = dynamic_cast<TopologyBridge*>(c);
    4820 [ +  - ][ +  - ]:      23275 :       if(ge && tb)
    4821                 :            :       {
    4822         [ +  - ]:      23275 :         DLIList<CubitSimpleAttrib> list;
    4823 [ +  - ][ +  - ]:      23275 :         ge->get_simple_attribute("TOPOLOGY_BRIDGE_ID",list);
                 [ +  - ]
    4824         [ +  - ]:      23275 :         list.reset();
    4825 [ +  - ][ -  + ]:      23275 :         for(int j = list.size(); j--;)
    4826                 :            :         {
    4827         [ #  # ]:          0 :           const CubitSimpleAttrib& attrib = list.get_and_step();
    4828 [ #  # ][ #  # ]:          0 :           assert(attrib.int_data_list().size() == 1);
                 [ #  # ]
    4829 [ #  # ][ #  # ]:          0 :           int id = attrib.int_data_list()[0];
    4830         [ #  # ]:          0 :           ge->set_saved_id(id);
    4831                 :            :           
    4832 [ #  # ][ #  # ]:          0 :           std::vector<CubitString> names = attrib.string_data_list();
    4833 [ #  # ][ #  # ]:          0 :           if(!names.empty())
    4834 [ #  # ][ #  # ]:          0 :             names.erase(names.begin());
    4835         [ #  # ]:          0 :           ge->set_saved_names( names );
    4836                 :            : 
    4837         [ #  # ]:          0 :           tb->remove_simple_attribute_virt(attrib);
    4838 [ #  # ][ +  - ]:      23275 :         }
    4839                 :            :       }
    4840                 :            :     }
    4841                 :            :     
    4842                 :            :     // create composites top-down
    4843 [ +  - ][ -  + ]:       1060 :     if( !create_composites( bodies   ) ) result = CUBIT_FAILURE;
    4844 [ +  - ][ -  + ]:       1060 :     if( !create_composites( surfaces ) ) result = CUBIT_FAILURE;
    4845 [ +  - ][ +  - ]:       1060 :     if( !create_composites( curves   ) ) result = CUBIT_FAILURE;
    4846 [ +  - ][ +  - ]:       1060 :     if( !create_composites( points   ) ) result = CUBIT_FAILURE;   
    4847                 :            :     
    4848                 :            :     
    4849 [ +  - ][ +  + ]:       2488 :     for( i = bodies.size(); i--; )
    4850                 :            :     {
    4851         [ +  - ]:       1428 :       BodySM* ptr = bodies.get_and_step();
    4852                 :            :       
    4853         [ +  - ]:       1428 :       temp_curves.clean_out();
    4854         [ +  - ]:       1428 :       temp_surfaces.clean_out();
    4855                 :            :       
    4856         [ +  - ]:       1428 :       ptr->curves( temp_curves );
    4857         [ +  - ]:       1428 :       ptr->surfaces( temp_surfaces );      
    4858                 :            :    
    4859                 :            :       //for each curve or surface, if it is not a composite,
    4860                 :            :       //and has a COMPOSIT_DATA_ATTRIB_NAME, 
    4861                 :            :       //which is an ENTITY_NAME, convert it into an ENTITY_NAME attribute
    4862                 :            : 
    4863 [ +  - ][ +  + ]:      24692 :       for( int k=temp_curves.size(); k--; )
    4864                 :            :       {
    4865         [ +  - ]:      23264 :         Curve *tmp_curve =  temp_curves.get_and_step();
    4866                 :            : 
    4867         [ +  - ]:      23264 :         DLIList<CubitSimpleAttrib> list;
    4868 [ +  - ][ +  - ]:      23264 :         tmp_curve->get_simple_attribute("COMPOSITE_ATTRIB",list);
                 [ +  - ]
    4869 [ +  - ][ -  + ]:      23264 :         for( int j = list.size(); j--; )
    4870                 :            :         {
    4871 [ #  # ][ #  # ]:          0 :           CubitSimpleAttrib tmp_attrib = list.get_and_step();
    4872 [ #  # ][ #  # ]:          0 :           std::vector<CubitString> string_list = tmp_attrib.string_data_list();
                 [ #  # ]
    4873 [ #  # ][ #  # ]:          0 :           if( string_list[1] == "ENTITY_NAME" && !dynamic_cast<CompositeCurve*>( tmp_curve ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
    4874                 :            :           {         
    4875                 :            :             //convert the attribute into an ENTITY_NAME attribute                        
    4876         [ #  # ]:          0 :             tmp_curve->remove_simple_attribute_virt( tmp_attrib );
    4877 [ #  # ][ #  # ]:          0 :             tmp_attrib.string_data_list().erase( tmp_attrib.string_data_list().begin() );            
         [ #  # ][ #  # ]
    4878         [ #  # ]:          0 :             tmp_curve->append_simple_attribute_virt( tmp_attrib );   
    4879                 :            :           }
    4880         [ #  # ]:          0 :         }                
    4881         [ +  - ]:      23264 :       }
    4882                 :            :       
    4883 [ +  - ][ +  + ]:      12606 :       for( int k=temp_surfaces.size(); k--; )
    4884                 :            :       {
    4885         [ +  - ]:      11178 :         Surface *tmp_surf = temp_surfaces.get_and_step();
    4886                 :            : 
    4887         [ +  - ]:      11178 :         DLIList<CubitSimpleAttrib> list;
    4888 [ +  - ][ +  - ]:      11178 :         tmp_surf->get_simple_attribute("COMPOSITE_ATTRIB",list);
                 [ +  - ]
    4889 [ +  - ][ -  + ]:      11178 :         for( int j = list.size(); j--; )
    4890                 :            :         {
    4891 [ #  # ][ #  # ]:          0 :           CubitSimpleAttrib tmp_attrib = list.get_and_step();
    4892 [ #  # ][ #  # ]:          0 :           std::vector<CubitString> string_list = tmp_attrib.string_data_list();
                 [ #  # ]
    4893 [ #  # ][ #  # ]:          0 :           if( string_list[1] == "ENTITY_NAME" && !dynamic_cast<CompositeSurface*>( tmp_surf ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
    4894                 :            :           {       
    4895                 :            :             //convert the attribute into an ENTITY_NAME attribute            
    4896         [ #  # ]:          0 :             tmp_surf->remove_simple_attribute_virt( tmp_attrib );
    4897 [ #  # ][ #  # ]:          0 :             tmp_attrib.string_data_list().erase( tmp_attrib.string_data_list().begin() );
         [ #  # ][ #  # ]
    4898         [ #  # ]:          0 :             tmp_surf->append_simple_attribute_virt( tmp_attrib );
    4899                 :            :           }
    4900         [ #  # ]:          0 :         }                
    4901         [ +  - ]:      11178 :       }
    4902                 :            :     }   
    4903                 :            :   }
    4904                 :            : 
    4905 [ +  - ][ +  + ]:       3201 :   for ( i = bodies.size(); i--; )
    4906 [ +  - ][ +  - ]:       1944 :     strip_attributes( bodies.get_and_step() );
    4907 [ +  - ][ +  + ]:      15091 :   for ( i = surfaces.size(); i--; )
    4908 [ +  - ][ +  - ]:      13834 :     strip_attributes( surfaces.get_and_step() );
    4909 [ +  - ][ +  + ]:      31956 :   for ( i = curves.size(); i--; )
    4910 [ +  - ][ +  - ]:      30699 :     strip_attributes( curves.get_and_step() );
    4911 [ +  - ][ +  + ]:      22230 :   for ( i = points.size(); i--; )
    4912 [ +  - ][ +  - ]:      20973 :     strip_attributes( points.get_and_step() );
    4913                 :            :   
    4914                 :            :     // update imported_geom list to contain composites rather than
    4915                 :            :     // entities used to create the composites
    4916 [ +  - ][ +  + ]:       3410 :   for( i = imported_geom.size(); i--; )
    4917                 :            :   {
    4918         [ +  - ]:       2153 :     TopologyBridge* bridge = imported_geom.step_and_get();
    4919 [ +  - ][ +  + ]:       2153 :     TopologyBridge* virt = dynamic_cast<TopologyBridge*>(bridge->owner());
    4920         [ -  + ]:       2153 :     if( virt )
    4921         [ #  # ]:          0 :       imported_geom.change_to( virt );
    4922                 :            :   }
    4923                 :            :     
    4924                 :            : /* DON'T DO THIS.  IT CHANGES THE ORDER OF THE IMPORT LIST,
    4925                 :            :    CAUSING IDS TO CHANGE.  FURTHER, IT RANDOMIZES THE IDS. 
    4926                 :            :    
    4927                 :            :     // composites were put in the list once for each underlying
    4928                 :            :     // entity.  need to remove the duplicates.
    4929                 :            :   imported_geom.uniquify_unordered();
    4930                 :            : */
    4931                 :            :     // that's all folks
    4932         [ +  - ]:       1257 :   return result;
    4933                 :            : } 
    4934                 :            : 
    4935                 :          0 : bool CompositeEngine::is_composite(TBOwner *bridge_owner)
    4936                 :            : {
    4937                 :          0 :   bool ret = false;
    4938         [ #  # ]:          0 :   if(bridge_owner)
    4939                 :            :   {
    4940 [ #  # ][ #  # ]:          0 :     if(dynamic_cast<CompositeBody*>(bridge_owner) ||
    4941 [ #  # ][ #  # ]:          0 :        dynamic_cast<CompositeLump*>(bridge_owner) ||
                 [ #  # ]
    4942 [ #  # ][ #  # ]:          0 :        dynamic_cast<CompositeSurface*>(bridge_owner) ||
    4943 [ #  # ][ #  # ]:          0 :        dynamic_cast<CompositeCurve*>(bridge_owner) ||
    4944 [ #  # ][ #  # ]:          0 :        dynamic_cast<CompositeCoEdge*>(bridge_owner) ||
                 [ #  # ]
    4945         [ #  # ]:          0 :        dynamic_cast<CompositePoint*>(bridge_owner))
    4946                 :            :     {
    4947                 :          0 :       ret = true;
    4948                 :            :     }
    4949                 :            :   }
    4950                 :          0 :   return ret;
    4951                 :            : }
    4952                 :            : 
    4953                 :          0 : bool CompositeEngine::is_composite(TopologyBridge *bridge)
    4954                 :            : {
    4955                 :          0 :   bool ret = false;
    4956         [ #  # ]:          0 :   if(bridge)
    4957                 :            :   {
    4958 [ #  # ][ #  # ]:          0 :     if(dynamic_cast<CompositeBody*>(bridge) ||
    4959 [ #  # ][ #  # ]:          0 :        dynamic_cast<CompositeLump*>(bridge) ||
                 [ #  # ]
    4960 [ #  # ][ #  # ]:          0 :        dynamic_cast<CompositeSurface*>(bridge) ||
    4961 [ #  # ][ #  # ]:          0 :        dynamic_cast<CompositeCurve*>(bridge) ||
    4962 [ #  # ][ #  # ]:          0 :        dynamic_cast<CompositeCoEdge*>(bridge) ||
                 [ #  # ]
    4963         [ #  # ]:          0 :        dynamic_cast<CompositePoint*>(bridge))
    4964                 :            :     {
    4965                 :          0 :       ret = true;
    4966                 :            :     }
    4967                 :            :   }
    4968                 :          0 :   return ret;
    4969                 :            : }
    4970                 :            : 
    4971                 :          0 : bool CompositeEngine::is_partition(TBOwner *bridge_owner)
    4972                 :            : {
    4973                 :          0 :   return false;
    4974                 :            : }
    4975                 :            : 
    4976                 :        615 : void CompositeEngine::remove_attributes( DLIList<TopologyBridge*> &bridge_list )
    4977                 :            : {
    4978                 :            :   //remove attributes off of underlying/hidden entities
    4979 [ +  - ][ +  - ]:       1230 :   DLIList<Curve*> curve_list, temp_curves;
                 [ +  - ]
    4980 [ +  - ][ +  - ]:       1230 :   DLIList<Surface*> surface_list, temp_surfaces;
         [ +  - ][ +  - ]
    4981 [ +  - ][ +  - ]:       1230 :   DLIList<Lump*> lump_list;
    4982 [ +  - ][ +  - ]:       1230 :   DLIList<BodySM*> body_list;
    4983                 :            : 
    4984 [ +  - ][ +  - ]:       2536 :   CAST_LIST( bridge_list, curve_list, Curve );
         [ +  - ][ -  + ]
         [ +  + ][ +  - ]
                 [ +  + ]
    4985 [ +  - ][ +  - ]:       2536 :   CAST_LIST( bridge_list, surface_list, Surface );
         [ +  - ][ -  + ]
         [ +  + ][ +  - ]
                 [ +  + ]
    4986 [ +  - ][ +  - ]:       2536 :   CAST_LIST( bridge_list, lump_list, Lump );
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
                 [ +  + ]
    4987 [ +  - ][ +  - ]:       2536 :   CAST_LIST( bridge_list, body_list, BodySM );
         [ +  - ][ -  + ]
         [ +  + ][ +  - ]
                 [ +  + ]
    4988                 :            : 
    4989                 :            :   int i;
    4990 [ +  - ][ +  + ]:        626 :   for( i = surface_list.size(); i--; )
    4991                 :            :   {
    4992         [ +  - ]:         11 :     temp_curves.clean_out();
    4993 [ +  - ][ +  - ]:         11 :     surface_list.get_and_step()->curves( temp_curves );
    4994         [ +  - ]:         11 :     curve_list += temp_curves;
    4995                 :            :   }
    4996                 :            : 
    4997 [ +  - ][ -  + ]:        615 :   for( i = lump_list.size(); i--; )
    4998                 :            :   {
    4999         [ #  # ]:          0 :     Lump* lump = lump_list.get_and_step();
    5000                 :            : 
    5001         [ #  # ]:          0 :     temp_curves.clean_out();
    5002         [ #  # ]:          0 :     lump->curves( temp_curves );
    5003         [ #  # ]:          0 :     curve_list += temp_curves;
    5004                 :            : 
    5005         [ #  # ]:          0 :     temp_surfaces.clean_out();
    5006         [ #  # ]:          0 :     lump->surfaces( temp_surfaces );
    5007         [ #  # ]:          0 :     surface_list += temp_surfaces;
    5008                 :            :   }
    5009 [ +  - ][ +  + ]:       1788 :   for( i = body_list.size(); i--; )
    5010                 :            :   {
    5011         [ +  - ]:       1173 :     BodySM* body = body_list.get_and_step();
    5012                 :            : 
    5013         [ +  - ]:       1173 :     temp_curves.clean_out();
    5014         [ +  - ]:       1173 :     body->curves( temp_curves );
    5015         [ +  - ]:       1173 :     curve_list += temp_curves;
    5016                 :            : 
    5017         [ +  - ]:       1173 :     temp_surfaces.clean_out();
    5018         [ +  - ]:       1173 :     body->surfaces( temp_surfaces );
    5019         [ +  - ]:       1173 :     surface_list += temp_surfaces;
    5020                 :            :   }
    5021                 :            : 
    5022                 :            : //  DLIList<CompositeCurve*> ccurve_list;
    5023                 :            : //  DLIList<CompositeSurface*> csurf_list;
    5024                 :            : 
    5025                 :            : //  CAST_LIST( curve_list, ccurve_list, CompositeCurve );
    5026                 :            : //  CAST_LIST( surface_list, csurf_list, CompositeSurface );
    5027                 :            : 
    5028                 :            : //  ccurve_list.uniquify_unordered();
    5029                 :            : //  csurf_list.uniquify_unordered();
    5030         [ +  - ]:        615 :   curve_list.uniquify_ordered();
    5031         [ +  - ]:        615 :   surface_list.uniquify_ordered();
    5032                 :            : 
    5033                 :            :   int j,k;
    5034 [ +  - ][ +  + ]:      14750 :   for( i = curve_list.size(); i--; )
    5035                 :            :   {
    5036         [ +  - ]:      14135 :     Curve *tmp_curve = curve_list.get_and_step();
    5037         [ +  - ]:      14135 :     strip_attributes(tmp_curve);
    5038         [ -  + ]:      14135 :     CompositeCurve* tmp_comp_curve = dynamic_cast<CompositeCurve*>(tmp_curve);
    5039         [ -  + ]:      14135 :     if(tmp_comp_curve)
    5040                 :            :     {
    5041 [ #  # ][ #  # ]:          0 :       for( j = 0; j < tmp_comp_curve->num_curves(); j++ )
    5042                 :            :       {
    5043 [ #  # ][ #  # ]:          0 :         strip_attributes( tmp_comp_curve->get_curve(j) );
    5044                 :            : 
    5045                 :            :         //remove attributes off underlying points too
    5046         [ #  # ]:          0 :         DLIList<TBPoint*> hidden_points;
    5047         [ #  # ]:          0 :         tmp_comp_curve->get_hidden_points( hidden_points );
    5048 [ #  # ][ #  # ]:          0 :         for( k=hidden_points.size(); k--; )
    5049 [ #  # ][ #  # ]:          0 :           strip_attributes( hidden_points.get_and_step() );
    5050         [ #  # ]:          0 :       }
    5051                 :            :     }
    5052                 :            :   }
    5053 [ +  - ][ +  + ]:       6378 :   for( i = surface_list.size(); i--; )
    5054                 :            :   {
    5055         [ +  - ]:       5763 :     Surface *tmp_surf = surface_list.get_and_step();
    5056         [ +  - ]:       5763 :     strip_attributes(tmp_surf);
    5057         [ -  + ]:       5763 :     CompositeSurface *tmp_comp_surf = dynamic_cast<CompositeSurface*>(tmp_surf);
    5058         [ -  + ]:       5763 :     if(tmp_comp_surf)
    5059                 :            :     {
    5060 [ #  # ][ #  # ]:          0 :       for( int j = 0; j < tmp_comp_surf->num_surfs(); j++ )
    5061 [ #  # ][ #  # ]:          0 :         strip_attributes( tmp_comp_surf->get_surface(j) );
    5062                 :            :     }
    5063                 :            :   }
    5064                 :            : 
    5065                 :            :   //remove attrigutes off of bridges passed in
    5066 [ +  - ][ +  + ]:       2536 :   for( i=bridge_list.size(); i--; )
    5067 [ +  - ][ +  - ]:       2536 :     strip_attributes( bridge_list.get_and_step() );
                 [ +  - ]
    5068                 :        615 : }
    5069                 :            : 
    5070                 :          0 : void CompositeEngine::remove_attributes_from_unmodifed_virtual( DLIList<TopologyBridge*> &bridge_list )
    5071                 :            : {
    5072                 :            :   //remove attributes off of underlying/hidden entities
    5073 [ #  # ][ #  # ]:          0 :   DLIList<Curve*> curve_list, temp_curves;
                 [ #  # ]
    5074 [ #  # ][ #  # ]:          0 :   DLIList<Surface*> surface_list, temp_surfaces;
         [ #  # ][ #  # ]
    5075 [ #  # ][ #  # ]:          0 :   DLIList<Lump*> lump_list;
    5076 [ #  # ][ #  # ]:          0 :   DLIList<BodySM*> body_list;
    5077                 :            : 
    5078 [ #  # ][ #  # ]:          0 :   CAST_LIST( bridge_list, curve_list, Curve );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    5079 [ #  # ][ #  # ]:          0 :   CAST_LIST( bridge_list, surface_list, Surface );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    5080 [ #  # ][ #  # ]:          0 :   CAST_LIST( bridge_list, lump_list, Lump );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    5081 [ #  # ][ #  # ]:          0 :   CAST_LIST( bridge_list, body_list, BodySM );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    5082                 :            : 
    5083                 :            :   int i;
    5084 [ #  # ][ #  # ]:          0 :   for( i = surface_list.size(); i--; )
    5085                 :            :   {
    5086         [ #  # ]:          0 :     temp_curves.clean_out();
    5087 [ #  # ][ #  # ]:          0 :     surface_list.get_and_step()->curves( temp_curves );
    5088         [ #  # ]:          0 :     curve_list += temp_curves;
    5089                 :            :   }
    5090                 :            : 
    5091 [ #  # ][ #  # ]:          0 :   for( i = lump_list.size(); i--; )
    5092                 :            :   {
    5093         [ #  # ]:          0 :     Lump* lump = lump_list.get_and_step();
    5094                 :            : 
    5095         [ #  # ]:          0 :     temp_curves.clean_out();
    5096         [ #  # ]:          0 :     lump->curves( temp_curves );
    5097         [ #  # ]:          0 :     curve_list += temp_curves;
    5098                 :            : 
    5099         [ #  # ]:          0 :     temp_surfaces.clean_out();
    5100         [ #  # ]:          0 :     lump->surfaces( temp_surfaces );
    5101         [ #  # ]:          0 :     surface_list += temp_surfaces;
    5102                 :            :   }
    5103 [ #  # ][ #  # ]:          0 :   for( i = body_list.size(); i--; )
    5104                 :            :   {
    5105         [ #  # ]:          0 :     BodySM* body = body_list.get_and_step();
    5106                 :            : 
    5107         [ #  # ]:          0 :     temp_curves.clean_out();
    5108         [ #  # ]:          0 :     body->curves( temp_curves );
    5109         [ #  # ]:          0 :     curve_list += temp_curves;
    5110                 :            : 
    5111         [ #  # ]:          0 :     temp_surfaces.clean_out();
    5112         [ #  # ]:          0 :     body->surfaces( temp_surfaces );
    5113         [ #  # ]:          0 :     surface_list += temp_surfaces;
    5114                 :            :   }
    5115                 :            : 
    5116 [ #  # ][ #  # ]:          0 :   DLIList<CompositeCurve*> ccurve_list;
    5117 [ #  # ][ #  # ]:          0 :   DLIList<CompositeSurface*> csurf_list;
    5118                 :            : 
    5119 [ #  # ][ #  # ]:          0 :   CAST_LIST( curve_list, ccurve_list, CompositeCurve );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    5120 [ #  # ][ #  # ]:          0 :   CAST_LIST( surface_list, csurf_list, CompositeSurface );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    5121                 :            : 
    5122         [ #  # ]:          0 :   ccurve_list.uniquify_ordered();
    5123         [ #  # ]:          0 :   csurf_list.uniquify_ordered();
    5124                 :            : 
    5125                 :            :   int k;
    5126 [ #  # ][ #  # ]:          0 :   for( i = ccurve_list.size(); i--; )
    5127                 :            :   {
    5128         [ #  # ]:          0 :     CompositeCurve* tmp_comp_curve = ccurve_list.get_and_step();
    5129                 :            :     /*
    5130                 :            :     for( j = 0; j < tmp_comp_curve->num_curves(); j++ )
    5131                 :            :     {
    5132                 :            : //      strip_attributes( tmp_comp_curve->get_curve(j) );
    5133                 :            : 
    5134                 :            :       //remove attributes off underlying points too
    5135                 :            :     }
    5136                 :            :     */
    5137         [ #  # ]:          0 :     DLIList<TBPoint*> hidden_points;
    5138         [ #  # ]:          0 :     tmp_comp_curve->get_hidden_points( hidden_points );
    5139 [ #  # ][ #  # ]:          0 :     for( k=hidden_points.size(); k--; )
    5140 [ #  # ][ #  # ]:          0 :       strip_attributes( hidden_points.get_and_step() );
    5141         [ #  # ]:          0 :   }
    5142 [ #  # ][ #  # ]:          0 :   for( i = csurf_list.size(); i--; )
    5143                 :            :   {
    5144         [ #  # ]:          0 :     CompositeSurface *tmp_comp_surf = csurf_list.get_and_step();
    5145                 :            :     /*
    5146                 :            :     for( int j = 0; j < tmp_comp_surf->num_surfs(); j++ )
    5147                 :            :       strip_attributes( tmp_comp_surf->get_surface(j) );
    5148                 :            :       */
    5149         [ #  # ]:          0 :     DLIList<Curve*> hidden_curves;
    5150         [ #  # ]:          0 :     tmp_comp_surf->get_hidden_curves( hidden_curves );
    5151 [ #  # ][ #  # ]:          0 :     for( k=hidden_curves.size(); k--; )
    5152 [ #  # ][ #  # ]:          0 :       strip_attributes( hidden_curves.get_and_step() );
    5153 [ #  # ][ #  # ]:          0 :   }
    5154                 :            : 
    5155                 :            :   //remove attrigutes off of bridges passed in
    5156                 :            :   /*
    5157                 :            :   for( i=bridge_list.size(); i--; )
    5158                 :            :     strip_attributes( bridge_list.get_and_step() );
    5159                 :            :     */
    5160                 :          0 : }
    5161                 :            : 
    5162                 :      89269 : void CompositeEngine::strip_attributes( TopologyBridge* bridge )
    5163                 :            : {
    5164                 :            :   const char* const attrib_names[] = { "COMPOSITE_GEOM",
    5165                 :            :                                        "COMPOSITE_STITCH",
    5166                 :            :                                        "COMPOSITE_SENSE",
    5167                 :            :                                        "COMPOSITE_ATTRIB",
    5168                 :            :                                        "COMPOSITE_NULLGEOM",
    5169                 :            :                                        "TOPOLOGY_BRIDGE_ID",
    5170                 :      89269 :                                        0 };
    5171                 :            :   
    5172         [ +  - ]:      89269 :   DLIList<CubitSimpleAttrib> list;
    5173         [ +  + ]:     624883 :   for( int i = 0; attrib_names[i]; i++ )
    5174                 :            :   {
    5175 [ +  - ][ +  - ]:     535614 :     bridge->get_simple_attribute( attrib_names[i], list );
                 [ +  - ]
    5176 [ +  - ][ -  + ]:     535614 :     while( list.size() )
    5177                 :            :     {
    5178 [ #  # ][ #  # ]:          0 :       bridge->remove_simple_attribute_virt(list.pop());
                 [ #  # ]
    5179                 :            :     }
    5180         [ +  - ]:      89269 :   }
    5181                 :      89269 : }
    5182                 :            : 
    5183                 :            :       
    5184                 :            : //-------------------------------------------------------------------------
    5185                 :            : // Purpose       : Retreive the CSA with the specified name if it exists
    5186                 :            : //
    5187                 :            : // Special Notes : 
    5188                 :            : //
    5189                 :            : // Creator       : Jason Kraftcheck
    5190                 :            : //
    5191                 :            : // Creation Date : 06/18/02
    5192                 :            : //-------------------------------------------------------------------------
    5193                 :            : CubitSimpleAttrib
    5194                 :      53577 : CompositeEngine::find_attribute_by_name( TopologyBridge* bridge, 
    5195                 :            :                                          const CubitString name )
    5196                 :            : {
    5197         [ +  - ]:      53577 :   CubitSimpleAttrib result;
    5198 [ +  - ][ +  - ]:     107154 :   DLIList<CubitSimpleAttrib> attrib_list;
    5199         [ +  - ]:      53577 :   bridge->get_simple_attribute( name, attrib_list );
    5200         [ +  - ]:      53577 :   attrib_list.reset();
    5201 [ +  - ][ -  + ]:      53577 :   if ( attrib_list.size() )
    5202 [ #  # ][ #  # ]:          0 :     result = attrib_list.extract();
                 [ #  # ]
    5203                 :            :     
    5204                 :     107154 :   return result;
    5205                 :            : }  
    5206                 :            :       
    5207                 :            : //-------------------------------------------------------------------------
    5208                 :            : // Purpose       : Create composite surfaces
    5209                 :            : //
    5210                 :            : // Special Notes : 
    5211                 :            : //
    5212                 :            : // Creator       : Jason Kraftcheck
    5213                 :            : //
    5214                 :            : // Creation Date : 06/18/02
    5215                 :            : //-------------------------------------------------------------------------
    5216                 :       1060 : CubitStatus CompositeEngine::create_composites( DLIList<Curve*>& list )
    5217                 :            : {
    5218                 :       1060 :   CubitStatus result = CUBIT_FAILURE;
    5219                 :            :   
    5220         [ +  + ]:      24335 :   for( int i = list.size(); i--; )
    5221                 :            :   {
    5222         [ +  - ]:      23275 :     Curve* curve = list.get_and_step();
    5223                 :            :     CompositeCurve* ccurve;
    5224 [ +  - ][ +  + ]:      23275 :     ccurve = dynamic_cast<CompositeCurve*>(curve->owner());
    5225         [ -  + ]:      23275 :     if( ccurve )
    5226                 :          0 :       curve = ccurve;
    5227 [ +  - ][ +  - ]:      23275 :     CubitSimpleAttrib attrib = find_attribute_by_name( curve, "COMPOSITE_GEOM" );
                 [ +  - ]
    5228 [ +  - ][ -  + ]:      23275 :     if( !attrib.isEmpty() )
    5229                 :            :     {
    5230         [ #  # ]:          0 :       curve->remove_simple_attribute_virt( attrib );
    5231                 :            :       
    5232                 :            : /*
    5233                 :            :       Curve* stitch_partner = 0;
    5234                 :            :       if( attrib->int_data_list()->size() )
    5235                 :            :       {
    5236                 :            :         assert(attrib->int_data_list()->size() == 1 );
    5237                 :            :         attrib->int_data_list()->reset();
    5238                 :            :         int stitch_partner_id = *attrib->int_data_list()->get();
    5239                 :            :         TopologyBridge* bridge = stitchMap[stitch_partner_id];
    5240                 :            :         if( !bridge )
    5241                 :            :         {
    5242                 :            :           stitchMap[stitch_partner_id] = curve;
    5243                 :            :           continue;
    5244                 :            :         }
    5245                 :            :         
    5246                 :            :         stitch_partner = dynamic_cast<Curve*>(bridge);
    5247                 :            :         assert( !!stitch_partner );
    5248                 :            :       }
    5249                 :            :       
    5250                 :            :       CompositeCurve* ccurve;
    5251                 :            :       ccurve = dynamic_cast<CompositeCurve*>(curve->owner());
    5252                 :            :       if( ccurve )
    5253                 :            :         curve = ccurve;
    5254                 :            :       if( stitch_partner )
    5255                 :            :       {
    5256                 :            :         ccurve = dynamic_cast<CompositeCurve*>(stitch_partner->owner());
    5257                 :            :         if( ccurve )
    5258                 :            :           stitch_partner = ccurve;
    5259                 :            :       }
    5260                 :            :       
    5261                 :            :       CompositeSurface* surf = remove_curve( curve, stitch_partner );
    5262                 :            :       if( !surf )
    5263                 :            :       {
    5264                 :            :         PRINT_ERROR("Error creating composite surface.  Could not remove curve.\n");
    5265                 :            :         result = CUBIT_FAILURE;
    5266                 :            :       }
    5267                 :            : */
    5268         [ #  # ]:          0 :       CompositeSurface* surf = remove_curve( curve );
    5269         [ #  # ]:          0 :       if( !surf )
    5270                 :            :       {
    5271 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Error creating composite surface.  Could not remove curve.\n");
         [ #  # ][ #  # ]
    5272                 :          0 :         result = CUBIT_FAILURE;
    5273                 :            :       }
    5274                 :            :       else
    5275                 :            :       {
    5276                 :            :         // Tell the composite surface which surfaces to ignore during
    5277                 :            :         // evaluation.
    5278 [ #  # ][ #  # ]:          0 :         for(int j=0; j<surf->num_surfs(); j++)
    5279                 :            :         {
    5280         [ #  # ]:          0 :           Surface *srf = surf->get_surface(j);
    5281 [ #  # ][ #  # ]:          0 :           CubitSimpleAttrib ignore_attrib = find_attribute_by_name( srf, "COMPOSITE_IGNORE" );
                 [ #  # ]
    5282 [ #  # ][ #  # ]:          0 :           if( !ignore_attrib.isEmpty() )
    5283                 :            :           {
    5284         [ #  # ]:          0 :             surf->ignore_surface(srf);
    5285         [ #  # ]:          0 :             srf->remove_simple_attribute_virt( ignore_attrib );
    5286                 :            :           }
    5287         [ #  # ]:          0 :         }
    5288         [ #  # ]:          0 :         surf->read_attributes();
    5289                 :            :       }
    5290                 :            :     }
    5291         [ +  - ]:      23275 :   }
    5292                 :       1060 :   return result;
    5293                 :            : }
    5294                 :            :       
    5295                 :            :   
    5296                 :            : //-------------------------------------------------------------------------
    5297                 :            : // Purpose       : Create composite curves
    5298                 :            : //
    5299                 :            : // Special Notes : 
    5300                 :            : //
    5301                 :            : // Creator       : Jason Kraftcheck
    5302                 :            : //
    5303                 :            : // Creation Date : 06/18/02
    5304                 :            : //-------------------------------------------------------------------------
    5305                 :       1060 : CubitStatus CompositeEngine::create_composites( DLIList<TBPoint*>& list )
    5306                 :            : {
    5307                 :       1060 :   CubitStatus result = CUBIT_FAILURE;
    5308                 :            :   
    5309                 :            :     // Restore composite curves.
    5310                 :            :   int i;
    5311         [ +  + ]:      16211 :   for( i = list.size(); i--; )
    5312                 :            :   {
    5313         [ +  - ]:      15151 :     TBPoint* point = list.get_and_step();
    5314                 :            :     CompositePoint* cpoint;
    5315 [ +  - ][ +  + ]:      15151 :     cpoint = dynamic_cast<CompositePoint*>(point->owner());
    5316         [ -  + ]:      15151 :     if( cpoint )
    5317                 :          0 :       point = cpoint;
    5318 [ +  - ][ +  - ]:      15151 :     CubitSimpleAttrib attrib = find_attribute_by_name( point, "COMPOSITE_GEOM" );
                 [ +  - ]
    5319 [ +  - ][ -  + ]:      15151 :     if( !attrib.isEmpty() )
    5320                 :            :     {
    5321         [ #  # ]:          0 :       point->remove_simple_attribute_virt( attrib );
    5322                 :            :       // Make sure we have a situation where we can perform
    5323                 :            :       // the composite before trying.
    5324         [ #  # ]:          0 :       DLIList<TopologyBridge*> attached_curves;
    5325         [ #  # ]:          0 :       point->get_parents_virt(attached_curves);
    5326 [ #  # ][ #  # ]:          0 :       if(attached_curves.size() == 2 &&
         [ #  # ][ #  # ]
    5327 [ #  # ][ #  # ]:          0 :          attached_curves[0] != attached_curves[1])
    5328                 :            :       {
    5329         [ #  # ]:          0 :         CompositeCurve* curve = remove_point(point);
    5330         [ #  # ]:          0 :         if( !curve )
    5331                 :            :         {
    5332 [ #  # ][ #  # ]:          0 :           PRINT_ERROR("Error creating composite curve.  Could not remove point.\n");
         [ #  # ][ #  # ]
    5333                 :          0 :           result = CUBIT_FAILURE;
    5334                 :            :         }
    5335                 :            :         else
    5336                 :            :         {
    5337         [ #  # ]:          0 :           curve->read_attributes();
    5338                 :            :         }
    5339         [ #  # ]:          0 :       }
    5340                 :            :     }
    5341         [ +  - ]:      15151 :   }
    5342                 :            :   
    5343                 :            :     // Restore point curves
    5344         [ +  + ]:      16211 :   for( i = list.size(); i--; )
    5345                 :            :   {
    5346         [ +  - ]:      15151 :     TBPoint* point = list.get_and_step();
    5347                 :            :     CompositePoint* cpoint;
    5348 [ +  - ][ +  + ]:      15151 :     cpoint = dynamic_cast<CompositePoint*>(point->owner());
    5349         [ -  + ]:      15151 :     if( cpoint )
    5350                 :          0 :       point = cpoint;
    5351 [ +  - ][ +  - ]:      15151 :     CubitSimpleAttrib attrib = find_attribute_by_name( point, "COMPOSITE_NULLGEOM" );
                 [ +  - ]
    5352 [ +  - ][ -  + ]:      15151 :     if( !attrib.isEmpty() )
    5353                 :            :     {
    5354         [ #  # ]:          0 :       point->remove_simple_attribute_virt( attrib );
    5355                 :            :    
    5356         [ #  # ]:          0 :       CompositeCurve* curve = restore_point_in_surface( point );
    5357         [ #  # ]:          0 :       if( !curve )
    5358                 :            :       {
    5359 [ #  # ][ #  # ]:          0 :         PRINT_ERROR("Error creating composite curve.  Could not rrestore point-curve.\n");
         [ #  # ][ #  # ]
    5360                 :          0 :         result = CUBIT_FAILURE;
    5361                 :            :       }
    5362                 :            :       else
    5363                 :            :       {
    5364         [ #  # ]:          0 :         curve->read_attributes();
    5365                 :            :       }
    5366                 :            :     }
    5367         [ +  - ]:      15151 :   }
    5368                 :            :   
    5369                 :       1060 :   return result;
    5370                 :            : }
    5371                 :            :       
    5372                 :            : 
    5373                 :            : //-------------------------------------------------------------------------
    5374                 :            : // Purpose       : Create composite lumps
    5375                 :            : //
    5376                 :            : // Special Notes : 
    5377                 :            : //
    5378                 :            : // Creator       : Jason Kraftcheck
    5379                 :            : //
    5380                 :            : // Creation Date : 06/18/02
    5381                 :            : //-------------------------------------------------------------------------
    5382                 :       1060 : CubitStatus CompositeEngine::create_composites( DLIList<Surface*>&  )
    5383                 :       1060 :   { return CUBIT_SUCCESS; }
    5384                 :            :   
    5385                 :            : //-------------------------------------------------------------------------
    5386                 :            : // Purpose       : Create composite bodies
    5387                 :            : //
    5388                 :            : // Special Notes : 
    5389                 :            : //
    5390                 :            : // Creator       : Jason Kraftcheck
    5391                 :            : //
    5392                 :            : // Creation Date : 06/18/02
    5393                 :            : //-------------------------------------------------------------------------
    5394                 :       1060 : CubitStatus CompositeEngine::create_composites( DLIList<BodySM*>&  )
    5395                 :            : { 
    5396                 :       1060 :   return CUBIT_SUCCESS; 
    5397                 :            : }
    5398                 :            : 
    5399                 :            : //-------------------------------------------------------------------------
    5400                 :            : // Purpose       : Save composite geometry
    5401                 :            : //
    5402                 :            : // Special Notes : 
    5403                 :            : //
    5404                 :            : // Creator       : Jason Kraftcheck
    5405                 :            : //
    5406                 :            : // Creation Date : 06/18/02
    5407                 :            : //-------------------------------------------------------------------------
    5408                 :        615 : CubitStatus CompositeEngine::export_geometry( DLIList<TopologyBridge*>& list )
    5409                 :            : {
    5410                 :            :   int i;
    5411                 :        615 :   CubitStatus result = CUBIT_SUCCESS;
    5412                 :            : 
    5413 [ +  - ][ +  - ]:       1032 :   if ( CGMApp::instance()->attrib_manager()->auto_update_flag(CA_COMPOSITE_VG) &&
         [ +  - ][ +  + ]
         [ +  - ][ +  + ]
    5414 [ +  - ][ +  - ]:        417 :        CGMApp::instance()->attrib_manager()->auto_write_flag(CA_COMPOSITE_VG) )
                 [ +  - ]
    5415                 :            :   {
    5416                 :            : 
    5417 [ +  - ][ +  - ]:        834 :     DLIList<Curve*> curve_list, temp_curves;
                 [ +  - ]
    5418 [ +  - ][ +  - ]:        834 :     DLIList<Surface*> surface_list, temp_surfaces;
         [ +  - ][ +  - ]
    5419 [ +  - ][ +  - ]:        834 :     DLIList<Lump*> lump_list, temp_lumps;
         [ +  - ][ +  - ]
    5420 [ +  - ][ +  - ]:        834 :     DLIList<BodySM*> body_list;
    5421                 :            : 
    5422 [ +  - ][ +  - ]:       1149 :     CAST_LIST( list, curve_list, Curve );
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
                 [ +  + ]
    5423 [ +  - ][ +  - ]:       1149 :     CAST_LIST( list, surface_list, Surface );
         [ +  - ][ -  + ]
         [ +  + ][ +  - ]
                 [ +  + ]
    5424 [ +  - ][ +  - ]:       1149 :     CAST_LIST( list, lump_list, Lump );
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
                 [ +  + ]
    5425 [ +  - ][ +  - ]:       1149 :     CAST_LIST( list, body_list, BodySM );
         [ +  - ][ -  + ]
         [ +  + ][ +  - ]
                 [ +  + ]
    5426                 :            : 
    5427 [ +  - ][ +  + ]:        428 :     for( i = surface_list.size(); i--; )
    5428                 :            :     {
    5429         [ +  - ]:         11 :       Surface* surf = surface_list.get_and_step();
    5430         [ +  - ]:         11 :       temp_curves.clean_out();
    5431         [ +  - ]:         11 :       surf->curves( temp_curves );
    5432         [ +  - ]:         11 :       curve_list += temp_curves;
    5433                 :            :     }
    5434 [ +  - ][ -  + ]:        417 :     for( i = lump_list.size(); i--; )
    5435                 :            :     {
    5436         [ #  # ]:          0 :       Lump* lump = lump_list.get_and_step();
    5437                 :            : 
    5438         [ #  # ]:          0 :       temp_curves.clean_out();
    5439         [ #  # ]:          0 :       lump->curves( temp_curves );
    5440         [ #  # ]:          0 :       curve_list += temp_curves;
    5441                 :            : 
    5442         [ #  # ]:          0 :       temp_surfaces.clean_out();
    5443         [ #  # ]:          0 :       lump->surfaces( temp_surfaces );
    5444         [ #  # ]:          0 :       surface_list += temp_surfaces;
    5445                 :            :     }
    5446 [ +  - ][ +  + ]:       1138 :     for( i = body_list.size(); i--; )
    5447                 :            :     {
    5448         [ +  - ]:        721 :       BodySM* body = body_list.get_and_step();
    5449                 :            : 
    5450         [ +  - ]:        721 :       temp_curves.clean_out();
    5451         [ +  - ]:        721 :       body->curves( temp_curves );
    5452         [ +  - ]:        721 :       curve_list += temp_curves;
    5453                 :            : 
    5454         [ +  - ]:        721 :       temp_surfaces.clean_out();
    5455         [ +  - ]:        721 :       body->surfaces( temp_surfaces );
    5456         [ +  - ]:        721 :       surface_list += temp_surfaces;
    5457                 :            : 
    5458         [ +  - ]:        721 :       temp_lumps.clean_out();
    5459         [ +  - ]:        721 :       body->lumps( temp_lumps );
    5460         [ +  - ]:        721 :       lump_list += temp_lumps;
    5461                 :            :     }
    5462                 :            : 
    5463 [ +  - ][ +  - ]:        834 :     DLIList<CompositeCurve*> ccurve_list;
    5464 [ +  - ][ +  - ]:        834 :     DLIList<CompositeSurface*> csurf_list;
    5465 [ +  - ][ +  - ]:        834 :     DLIList<CompositeLump*> clump_list;
    5466 [ +  - ][ +  - ]:        834 :     DLIList<CompositeBody*> cbody_list;
    5467                 :            : 
    5468 [ +  - ][ +  - ]:       7050 :     CAST_LIST( curve_list, ccurve_list, CompositeCurve );
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
                 [ +  + ]
    5469 [ +  - ][ +  - ]:       3991 :     CAST_LIST( surface_list, csurf_list, CompositeSurface );
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
                 [ +  + ]
    5470                 :            :   //  CAST_LIST( lump_list, clump_list, CompositeLump );
    5471                 :            :   //  CAST_LIST( body_list, cbody_list, CompositeBody );
    5472                 :            : 
    5473         [ +  - ]:        417 :     ccurve_list.uniquify_ordered();
    5474         [ +  - ]:        417 :     csurf_list.uniquify_ordered();
    5475                 :            : 
    5476                 :            : 
    5477                 :            :    // Add an attribute to each topology bridge specifying what its id is.  Upon restoring
    5478                 :            :    // the file these attributes will be read so that the topology id can be stored with the
    5479                 :            :    // topology bridge.  Normally, the ids would get set when creating the associated RefEntity
    5480                 :            :    // and the topology bridge id would be set to be that of the RefEntity.  However, for the
    5481                 :            :    // underlying entities of a composite RefEntities are not created so the ids never get
    5482                 :            :    // set when restoring.  Thus we are doing it manually here.  Only doing curves and
    5483                 :            :    // surfaces right now.
    5484         [ +  - ]:        417 :    csurf_list.reset();
    5485 [ +  - ][ -  + ]:        417 :    for(i=csurf_list.size(); i--;)
    5486                 :            :    {
    5487         [ #  # ]:          0 :      CompositeSurface *cs = csurf_list.get_and_step();
    5488         [ #  # ]:          0 :      int number_surfs = cs->num_surfs();
    5489         [ #  # ]:          0 :      for(int j=0; j<number_surfs; ++j)
    5490                 :            :      {
    5491         [ #  # ]:          0 :        Surface *s = cs->get_surface(j);
    5492                 :          0 :        GeometryEntity *ge = dynamic_cast<GeometryEntity*>(s);
    5493                 :          0 :        TopologyBridge *tb = dynamic_cast<TopologyBridge*>(s);
    5494 [ #  # ][ #  # ]:          0 :        if(ge && tb)
    5495                 :            :        {
    5496         [ #  # ]:          0 :          std::vector<int> int_list;
    5497 [ #  # ][ #  # ]:          0 :          int_list.push_back(ge->get_saved_id() );
    5498                 :            : 
    5499                 :            :          //save out the names
    5500 [ #  # ][ #  # ]:          0 :          std::vector<CubitString> names;
    5501         [ #  # ]:          0 :          ge->get_saved_names( names );
    5502 [ #  # ][ #  # ]:          0 :          names.insert(names.begin(), CubitString("TOPOLOGY_BRIDGE_ID"));
         [ #  # ][ #  # ]
    5503 [ #  # ][ #  # ]:          0 :          CubitSimpleAttrib geom_attrib( &names, 0, &int_list );
    5504 [ #  # ][ #  # ]:          0 :          append_attrib(tb, geom_attrib);
    5505                 :            :        }
    5506                 :            :      }
    5507                 :            :    }
    5508                 :            : 
    5509         [ +  - ]:        417 :    ccurve_list.reset();
    5510 [ +  - ][ -  + ]:        417 :    for(i=ccurve_list.size(); i--;)
    5511                 :            :    {
    5512         [ #  # ]:          0 :      CompositeCurve *cc = ccurve_list.get_and_step();
    5513         [ #  # ]:          0 :      int number_curves = cc->num_curves();
    5514         [ #  # ]:          0 :      for(int j=0; j<number_curves; ++j)
    5515                 :            :      {
    5516         [ #  # ]:          0 :        Curve *c = cc->get_curve(j);
    5517                 :          0 :        GeometryEntity *ge = dynamic_cast<GeometryEntity*>(c);
    5518                 :          0 :        TopologyBridge *tb = dynamic_cast<TopologyBridge*>(c);
    5519 [ #  # ][ #  # ]:          0 :        if(ge && tb)
    5520                 :            :        {
    5521         [ #  # ]:          0 :          std::vector<int> int_list;
    5522 [ #  # ][ #  # ]:          0 :          int_list.push_back( ge->get_saved_id() );
    5523                 :            : 
    5524                 :            :          //save out the names
    5525 [ #  # ][ #  # ]:          0 :          std::vector<CubitString> names;
    5526         [ #  # ]:          0 :          ge->get_saved_names( names );
    5527 [ #  # ][ #  # ]:          0 :          names.insert(names.begin(), CubitString("TOPOLOGY_BRIDGE_ID"));
         [ #  # ][ #  # ]
    5528                 :            : 
    5529 [ #  # ][ #  # ]:          0 :          CubitSimpleAttrib geom_attrib( &names, 0, &int_list );
    5530 [ #  # ][ #  # ]:          0 :          append_attrib(tb, geom_attrib);
    5531                 :            :        }
    5532                 :            :      }
    5533                 :            :    }
    5534                 :            : 
    5535 [ +  - ][ -  + ]:        417 :     for( i = ccurve_list.size(); i--; )
    5536 [ #  # ][ #  # ]:          0 :       save( ccurve_list.get_and_step() );
    5537 [ +  - ][ -  + ]:        417 :     for( i = csurf_list.size(); i--; )
    5538 [ #  # ][ #  # ]:          0 :       save( csurf_list.get_and_step() );
    5539 [ +  - ][ -  + ]:        417 :     for( i = clump_list.size(); i--; )
    5540 [ #  # ][ #  # ]:          0 :       save( clump_list.get_and_step() );
    5541 [ +  - ][ -  + ]:        417 :     for( i = cbody_list.size(); i--; )
    5542 [ #  # ][ #  # ]:        417 :       save( cbody_list.get_and_step() );
                 [ +  - ]
    5543                 :            :   }
    5544                 :            :   
    5545         [ +  - ]:        615 :   list.reset();
    5546         [ +  - ]:        615 :   DLIList<TopologyBridge*> underlying;
    5547 [ +  - ][ +  + ]:       2711 :   for( i = list.size(); i--; )
    5548                 :            :   {
    5549         [ +  - ]:       2096 :     TopologyBridge* ptr = list.step_and_get();
    5550         [ +  - ]:       2096 :     underlying.clean_out();
    5551 [ -  + ][ -  + ]:       2096 :     if( CompositeCurve* curve = dynamic_cast<CompositeCurve*>(ptr) )
    5552 [ #  # ][ #  # ]:          0 :       for( int j = 0; j < curve->num_curves(); j++ )
    5553 [ #  # ][ #  # ]:          0 :         underlying.append( curve->get_curve(j) );
    5554 [ -  + ][ -  + ]:       2096 :     else if( CompositeSurface* surf = dynamic_cast<CompositeSurface*>(ptr) )
    5555 [ #  # ][ #  # ]:          0 :       for( int j = 0; j < surf->num_surfs(); j++ )
    5556 [ #  # ][ #  # ]:          0 :         underlying.append( surf->get_surface(j) );
    5557                 :            : /*
    5558                 :            :     else if( CompositeLump* lump = dynamic_cast<CompositeLump*>)(ptr) )
    5559                 :            :       for( int j = 0; j < lump->num_entities(); j++ )
    5560                 :            :         underlying.append( lump->lump(j) );
    5561                 :            :     else if( CompositeBody* body = dynamic_cast<CompositeBody*>)(ptr) )
    5562                 :            :       for( int j = 0; j < body->num_entities(); j++ )
    5563                 :            :         underlying.append( body->body(j) );
    5564                 :            : */
    5565 [ +  - ][ -  + ]:       2096 :     if( underlying.size() )
    5566                 :            :     {
    5567 [ #  # ][ #  # ]:          0 :       list.change_to( underlying.pop() );
    5568         [ #  # ]:          0 :       list += underlying;
    5569                 :            :     }
    5570                 :            :   }
    5571                 :            :   
    5572         [ +  - ]:        615 :   return result;
    5573                 :            : }
    5574                 :            : 
    5575                 :            : 
    5576                 :          0 : void CompositeEngine::append_attrib( TopologyBridge* tb, 
    5577                 :            :                                      const CubitSimpleAttrib& csa )
    5578                 :            : {
    5579                 :            :   CubitSimpleAttrib old = find_attribute_by_name( tb,
    5580 [ #  # ][ #  # ]:          0 :                            csa.character_type() );
                 [ #  # ]
    5581 [ #  # ][ #  # ]:          0 :   if( !old.isEmpty() )
    5582                 :            :   {
    5583         [ #  # ]:          0 :     tb->remove_simple_attribute_virt( old );
    5584                 :            :   }
    5585 [ #  # ][ #  # ]:          0 :   tb->append_simple_attribute_virt( csa );
    5586                 :          0 : }
    5587                 :            : 
    5588                 :            : 
    5589                 :          0 : CubitStatus CompositeEngine::save( CompositePoint* point )
    5590                 :            : {
    5591         [ #  # ]:          0 :   DLIList<CompositePoint*> points;
    5592         [ #  # ]:          0 :   point->get_stitched( points );
    5593 [ #  # ][ #  # ]:          0 :   if( points.size() > 1 )
    5594                 :            :   {
    5595         [ #  # ]:          0 :     CubitString name("COMPOSITE_STITCH");
    5596 [ #  # ][ #  # ]:          0 :     std::vector<CubitString> string_list;
    5597         [ #  # ]:          0 :     string_list.push_back(name);
    5598 [ #  # ][ #  # ]:          0 :     CubitSimpleAttrib geom_attrib( &string_list, 0, 0 );
    5599         [ #  # ]:          0 :     int uid = TDUniqueId::generate_unique_id();
    5600 [ #  # ][ #  # ]:          0 :     geom_attrib.int_data_list().push_back( uid );
    5601                 :            :     
    5602 [ #  # ][ #  # ]:          0 :     for( int i = points.size(); i--; )
    5603 [ #  # ][ #  # ]:          0 :       append_attrib( points.step_and_get()->get_point(), geom_attrib );
         [ #  # ][ #  # ]
    5604                 :            :   }
    5605         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    5606                 :            : }
    5607                 :            :     
    5608                 :            : 
    5609                 :          0 : CubitStatus CompositeEngine::save( CompositeCurve* curve  )
    5610                 :            : {
    5611         [ #  # ]:          0 :   DLIList<TBPoint*> hidden_points;
    5612 [ #  # ][ #  # ]:          0 :   std::vector<CubitString> string_list;
    5613                 :            : 
    5614 [ #  # ][ #  # ]:          0 :   if (curve->num_curves() == 0) // point-curve
    5615                 :            :   {
    5616 [ #  # ][ #  # ]:          0 :     assert(hidden_points.size() == 0);
    5617         [ #  # ]:          0 :     CubitString ptname("COMPOSITE_NULLGEOM");
    5618         [ #  # ]:          0 :     string_list.clear();
    5619         [ #  # ]:          0 :     string_list.push_back( ptname );
    5620 [ #  # ][ #  # ]:          0 :     CubitSimpleAttrib null_geom_attrib( &string_list, 0, 0 );
    5621         [ #  # ]:          0 :     CompositePoint* pt = curve->start_point();
    5622 [ #  # ][ #  # ]:          0 :     assert(curve->end_point() == pt);
    5623         [ #  # ]:          0 :     append_attrib( pt, null_geom_attrib );
    5624         [ #  # ]:          0 :     curve->write_attributes();
    5625         [ #  # ]:          0 :     return CUBIT_SUCCESS;
    5626                 :            :   }
    5627                 :            :   
    5628                 :            :   ;
    5629 [ #  # ][ #  # ]:          0 :   string_list.push_back( CubitString("COMPOSITE_GEOM") );
                 [ #  # ]
    5630 [ #  # ][ #  # ]:          0 :   CubitSimpleAttrib geom_attrib( &string_list, 0, 0 );
    5631                 :            : 
    5632                 :            :   int i;
    5633                 :            : 
    5634         [ #  # ]:          0 :   curve->write_attributes();
    5635         [ #  # ]:          0 :   curve->get_hidden_points( hidden_points );
    5636 [ #  # ][ #  # ]:          0 :   for( i = hidden_points.size(); i--; )
    5637                 :            :   {
    5638         [ #  # ]:          0 :     TBPoint* point = hidden_points.get_and_step();
    5639 [ #  # ][ #  # ]:          0 :     if( CompositePoint* cpoint = dynamic_cast<CompositePoint*>(point) )
    5640         [ #  # ]:          0 :       save(cpoint);
    5641                 :            :     
    5642         [ #  # ]:          0 :     append_attrib( point, geom_attrib );
    5643                 :            :   }
    5644                 :            : 
    5645                 :            : 
    5646 [ #  # ][ #  # ]:          0 :   if( curve->is_stitched() && curve == curve->primary_stitched_curve() )
         [ #  # ][ #  # ]
                 [ #  # ]
    5647                 :            :   {
    5648         [ #  # ]:          0 :     int stitch_uid = TDUniqueId::generate_unique_id();
    5649         [ #  # ]:          0 :     DLIList<CompositeCurve*> curve_list;
    5650         [ #  # ]:          0 :     curve->get_stitched( curve_list );
    5651                 :            : 
    5652 [ #  # ][ #  # ]:          0 :     string_list[0] = "COMPOSITE_STITCH";
         [ #  # ][ #  # ]
    5653 [ #  # ][ #  # ]:          0 :     CubitSimpleAttrib stitch_attrib( &string_list, 0, 0 );
    5654 [ #  # ][ #  # ]:          0 :     stitch_attrib.int_data_list().push_back(stitch_uid);
    5655 [ #  # ][ #  # ]:          0 :     for( i = curve_list.size(); i--; )
    5656 [ #  # ][ #  # ]:          0 :       append_attrib( curve_list.step_and_get(), stitch_attrib );
    5657 [ #  # ][ #  # ]:          0 :     stitch_attrib.int_data_list().clear();
    5658                 :            : 
    5659 [ #  # ][ #  # ]:          0 :     if( curve_list.move_to( curve ) )
    5660         [ #  # ]:          0 :       curve_list.extract();
    5661                 :            : 
    5662 [ #  # ][ #  # ]:          0 :     for( i = curve_list.size(); i--; )
    5663 [ #  # ][ #  # ]:          0 :       save( curve_list.step_and_get() );
                 [ #  # ]
    5664                 :            :   }
    5665                 :            : 
    5666                 :            :   
    5667 [ #  # ][ #  # ]:          0 :   string_list[0] = "COMPOSITE_SENSE";
         [ #  # ][ #  # ]
    5668 [ #  # ][ #  # ]:          0 :   CubitSimpleAttrib sense_attrib( &string_list, 0, 0 );
    5669                 :            :   
    5670 [ #  # ][ #  # ]:          0 :   for( i = 0; i < curve->num_curves(); i++ )
    5671                 :            :   {
    5672 [ #  # ][ #  # ]:          0 :     CubitSimpleAttrib old = find_attribute_by_name( curve->get_curve(i), "COMPOSITE_SENSE" );
         [ #  # ][ #  # ]
    5673 [ #  # ][ #  # ]:          0 :     if( !old.isEmpty() )
    5674                 :            :     {
    5675 [ #  # ][ #  # ]:          0 :       if( curve->get_sense(i) == CUBIT_FORWARD )
    5676 [ #  # ][ #  # ]:          0 :         curve->get_curve(i)->remove_simple_attribute_virt( old );
    5677                 :            :     }
    5678 [ #  # ][ #  # ]:          0 :     else if( curve->get_sense(i) == CUBIT_REVERSED )
    5679                 :            :     {
    5680 [ #  # ][ #  # ]:          0 :       curve->get_curve(i)->append_simple_attribute_virt( sense_attrib );
    5681                 :            :     }
    5682         [ #  # ]:          0 :   }
    5683                 :            : 
    5684         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    5685                 :            : }
    5686                 :            : 
    5687                 :            :    
    5688                 :          0 : CubitStatus CompositeEngine::save( CompositeSurface* surf )
    5689                 :            : { 
    5690         [ #  # ]:          0 :   DLIList<Curve*> comp_curves;
    5691 [ #  # ][ #  # ]:          0 :   surf->hidden_entities().hidden_curves( comp_curves );
    5692         [ #  # ]:          0 :   surf->write_attributes();
    5693                 :            :   
    5694 [ #  # ][ #  # ]:          0 :   std::vector<CubitString> string_list;
    5695 [ #  # ][ #  # ]:          0 :   string_list.push_back( CubitString("COMPOSITE_GEOM") );
                 [ #  # ]
    5696 [ #  # ][ #  # ]:          0 :   CubitSimpleAttrib geom_attrib( &string_list, 0, 0 );
    5697                 :            : 
    5698                 :            :   int i, j;
    5699                 :            : 
    5700 [ #  # ][ #  # ]:          0 :   for( i = comp_curves.size(); i--; )
    5701                 :            :   {
    5702                 :            :     CompositeCurve* ccurve = 
    5703 [ #  # ][ #  # ]:          0 :       dynamic_cast<CompositeCurve*>(comp_curves.get_and_step());
    5704         [ #  # ]:          0 :     assert(ccurve!= NULL );
    5705                 :            :     
    5706 [ #  # ][ #  # ]:          0 :     for( j = 0; j < ccurve->num_curves(); j++ )
    5707                 :            :     {      
    5708         [ #  # ]:          0 :       Curve* tb = ccurve->get_curve(j);
    5709         [ #  # ]:          0 :       append_attrib( tb, geom_attrib );
    5710                 :            :     }  
    5711                 :            :   }
    5712                 :            :   
    5713                 :            : 
    5714 [ #  # ][ #  # ]:          0 :   if( surf->get_stitch_partner() )
    5715                 :            :   {
    5716                 :            :     CubitSimpleAttrib old =
    5717 [ #  # ][ #  # ]:          0 :       find_attribute_by_name( surf->get_stitch_partner(), "COMPOSITE_STITCH" );
         [ #  # ][ #  # ]
    5718 [ #  # ][ #  # ]:          0 :     if( !old.isEmpty() )
    5719                 :            :     {
    5720         [ #  # ]:          0 :       append_attrib( surf, old );
    5721                 :            :     }
    5722                 :            :     else
    5723                 :            :     {
    5724         [ #  # ]:          0 :       int stitch_uid = TDUniqueId::generate_unique_id();
    5725 [ #  # ][ #  # ]:          0 :       string_list[0] = "COMPOSITE_STITCH";
         [ #  # ][ #  # ]
    5726         [ #  # ]:          0 :       CubitSimpleAttrib stitch_attrib( &string_list, 0, 0);
    5727 [ #  # ][ #  # ]:          0 :       stitch_attrib.int_data_list().push_back( stitch_uid );
    5728         [ #  # ]:          0 :       append_attrib( surf, stitch_attrib );
    5729 [ #  # ][ #  # ]:          0 :       stitch_attrib.int_data_list().clear();
                 [ #  # ]
    5730         [ #  # ]:          0 :     }
    5731                 :            :   }
    5732                 :            : 
    5733                 :            :   
    5734 [ #  # ][ #  # ]:          0 :   string_list[0] = "COMPOSITE_SENSE";
         [ #  # ][ #  # ]
    5735 [ #  # ][ #  # ]:          0 :   CubitSimpleAttrib sense_attrib( &string_list, 0, 0 );
    5736                 :            :   
    5737 [ #  # ][ #  # ]:          0 :   for( i = 0; i < surf->num_surfs(); i++ )
    5738                 :            :   {
    5739 [ #  # ][ #  # ]:          0 :     CubitSimpleAttrib old = find_attribute_by_name( surf->get_surface(i), "COMPOSITE_SENSE" );
         [ #  # ][ #  # ]
    5740 [ #  # ][ #  # ]:          0 :     if( !old.isEmpty() )
    5741                 :            :     {
    5742 [ #  # ][ #  # ]:          0 :       if( surf->get_sense(i) == CUBIT_FORWARD )
    5743 [ #  # ][ #  # ]:          0 :         surf->get_surface(i)->remove_simple_attribute_virt( old );
    5744                 :            :     }
    5745 [ #  # ][ #  # ]:          0 :     else if( surf->get_sense(i) == CUBIT_REVERSED )
    5746                 :            :     {
    5747 [ #  # ][ #  # ]:          0 :       surf->get_surface(i)->append_simple_attribute_virt( sense_attrib );
    5748                 :            :     }
    5749         [ #  # ]:          0 :   }
    5750                 :            : 
    5751 [ #  # ][ #  # ]:          0 :   string_list[0] = "COMPOSITE_IGNORE";
         [ #  # ][ #  # ]
    5752 [ #  # ][ #  # ]:          0 :   CubitSimpleAttrib ignore_attrib( &string_list, 0, 0 );
    5753                 :            : 
    5754 [ #  # ][ #  # ]:          0 :   DLIList<Surface*> srfs;
    5755         [ #  # ]:          0 :   surf->get_ignored_surfs(srfs);
    5756 [ #  # ][ #  # ]:          0 :   for( i = 0; i < surf->num_surfs(); i++ )
    5757                 :            :   {
    5758         [ #  # ]:          0 :     Surface *srf = surf->get_surface(i);
    5759 [ #  # ][ #  # ]:          0 :     if(srfs.is_in_list(srf))
    5760         [ #  # ]:          0 :       srf->append_simple_attribute_virt(ignore_attrib);
    5761                 :            :   }
    5762                 :            : 
    5763                 :            : 
    5764         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    5765                 :            : }
    5766                 :            : 
    5767                 :          0 : CubitStatus CompositeEngine::save( CompositeLump* lump )
    5768                 :            : {
    5769         [ #  # ]:          0 :   DLIList<Surface*> comp_surfs;
    5770 [ #  # ][ #  # ]:          0 :   lump->hidden_entities().hidden_surfaces( comp_surfs );
    5771                 :            :   
    5772 [ #  # ][ #  # ]:          0 :   CubitString name("COMPOSITE_GEOM");
    5773 [ #  # ][ #  # ]:          0 :   std::vector<CubitString> string_list;
    5774         [ #  # ]:          0 :   string_list.push_back( name );
    5775 [ #  # ][ #  # ]:          0 :   CubitSimpleAttrib geom_attrib( &string_list, 0, 0 );
    5776                 :            : 
    5777                 :            :   int i, j;
    5778                 :            :   
    5779 [ #  # ][ #  # ]:          0 :   for( i = comp_surfs.size(); i--; )
    5780                 :            :   {
    5781                 :            :     CompositeSurface* csurf = 
    5782 [ #  # ][ #  # ]:          0 :       dynamic_cast<CompositeSurface*>(comp_surfs.get_and_step());
    5783         [ #  # ]:          0 :     assert(csurf!= NULL );
    5784                 :            :     
    5785 [ #  # ][ #  # ]:          0 :     for( j = 0; j < csurf->num_surfs(); j++ )
    5786                 :            :     {
    5787         [ #  # ]:          0 :       append_attrib( csurf, geom_attrib );
    5788 [ #  # ][ #  # ]:          0 :       geom_attrib.int_data_list().clear();
    5789                 :            :     }  
    5790                 :            :   }
    5791                 :            :   
    5792         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    5793                 :            : }
    5794                 :            : 
    5795                 :          0 : CubitStatus CompositeEngine::save( CompositeBody* )
    5796                 :          0 : { return CUBIT_SUCCESS; }
    5797                 :            : 
    5798                 :            : 
    5799                 :          0 : CompositePoint* CompositeEngine::stitch_points( TBPoint* pt1, TBPoint* pt2 )
    5800                 :            : {
    5801         [ #  # ]:          0 :   CompositePoint* cp1 = dynamic_cast<CompositePoint*>(pt1);
    5802         [ #  # ]:          0 :   CompositePoint* cp2 = dynamic_cast<CompositePoint*>(pt2);
    5803         [ #  # ]:          0 :   if( !cp1 ) cp1 = replace_point( pt1 );
    5804         [ #  # ]:          0 :   if( !cp2 ) cp2 = replace_point( pt2 );
    5805                 :            :   
    5806         [ #  # ]:          0 :   while( CompositeCurve* curve = cp2->next_curve() )
    5807                 :            :   {
    5808         [ #  # ]:          0 :     if( curve->start_point() == cp2 )
    5809                 :          0 :       curve->start_point( cp1 );
    5810         [ #  # ]:          0 :     if( curve->end_point() == cp2 )
    5811                 :          0 :       curve->end_point( cp1 );
    5812                 :            :   }
    5813                 :            :   
    5814                 :          0 :   cp1->stitch( cp2 );
    5815                 :          0 :   return cp1;
    5816                 :            : }
    5817                 :            : 
    5818                 :          0 : CompositeCurve* CompositeEngine::stitch_curves( Curve* curve1, Curve* curve2 )
    5819                 :            : {
    5820         [ #  # ]:          0 :   CompositeCurve* c1 = dynamic_cast<CompositeCurve*>(curve1);
    5821         [ #  # ]:          0 :   CompositeCurve* c2 = dynamic_cast<CompositeCurve*>(curve2);
    5822         [ #  # ]:          0 :   if( !c1 ) c1 = replace_curve( curve1 );
    5823         [ #  # ]:          0 :   if( !c2 ) c2 = replace_curve( curve2 );
    5824                 :            :   
    5825                 :          0 :   bool reversed = false, fail = false;
    5826         [ #  # ]:          0 :   if( c1->start_point() == c2->end_point() )
    5827                 :          0 :     reversed = true;
    5828         [ #  # ]:          0 :   else if( c1->start_point() != c2->start_point() )
    5829                 :          0 :     fail = true;
    5830                 :            :     
    5831         [ #  # ]:          0 :   if (c1->start_point() == c1->end_point())
    5832                 :            :   {
    5833 [ #  # ][ #  # ]:          0 :     CubitVector pt, tan1, tan2, junk;
         [ #  # ][ #  # ]
    5834         [ #  # ]:          0 :     c1->position_from_fraction( 0.5, pt );
    5835         [ #  # ]:          0 :     c1->closest_point( pt, junk, &tan1 );
    5836         [ #  # ]:          0 :     c2->closest_point( pt, junk, &tan2 );
    5837         [ #  # ]:          0 :     reversed = (tan1 % tan2) < 0.0;
    5838                 :            :   }
    5839                 :            :   
    5840 [ #  # ][ #  # ]:          0 :   if( fail || 
    5841 [ #  # ][ #  # ]:          0 :       (reversed && c1->end_point() != c2->start_point()) ||
                 [ #  # ]
    5842         [ #  # ]:          0 :       (!reversed && c1->end_point() != c2->end_point()) )
    5843                 :            :   {
    5844         [ #  # ]:          0 :     if( c1->num_curves() == 1 )
    5845                 :          0 :       remove_composite( c1 );
    5846         [ #  # ]:          0 :     if( c2->num_curves() == 1 )
    5847                 :          0 :       remove_composite( c2 );
    5848                 :          0 :     return 0;
    5849                 :            :   }
    5850                 :            :   
    5851                 :            :   //while( CompositeCoEdge* coedge = c2->first_coedge() )
    5852                 :            :   //{
    5853                 :            :     //c2->remove( coedge );
    5854                 :            :     //c1->add( coedge );
    5855                 :            :     //if( reversed )
    5856                 :            :    //   coedge->reverse();
    5857                 :            :   //}
    5858                 :          0 :   CompositeCoEdge* coedge = 0;
    5859 [ #  # ][ #  # ]:          0 :   if (reversed) while ((coedge = c2->next_coedge( coedge )))
    5860                 :          0 :     coedge->reverse();
    5861                 :            :     
    5862                 :            : 
    5863                 :          0 :   c1->stitch( c2 );
    5864                 :          0 :   return c1;
    5865                 :            : }
    5866                 :            : 
    5867                 :            : CompositeSurface* 
    5868                 :          0 : CompositeEngine::stitch_surfaces( Surface* /*surf1*/, Surface* /*surf2*/ )
    5869                 :            : {
    5870                 :          0 :   return 0;
    5871                 :            : /*
    5872                 :            :   CompositeSurface* cs1 = dynamic_cast<CompositeSurface*>(surf1);
    5873                 :            :   CompositeSurface* cs2 = dynamic_cast<CompositeSurface*>(surf2);
    5874                 :            :   
    5875                 :            :     // Can only stitch pairs of surfaces. Fail if either 
    5876                 :            :     // surface is already stitched with another surface.
    5877                 :            :   if( (cs1 && cs1->get_stitch_partner()) ||
    5878                 :            :       (cs2 && cs2->get_stitch_partner())  )
    5879                 :            :     return 0;
    5880                 :            :   
    5881                 :            :   if( ! cs1 ) cs1 = replace_surface( surf1 );
    5882                 :            :   if( ! cs2 ) cs2 = replace_surface( surf2 );
    5883                 :            :   
    5884                 :            :     // special case - topological sphere
    5885                 :            :   if( !cs1->first_loop() && !cs2->first_loop() )
    5886                 :            :   {
    5887                 :            :     if( cs1->stitch( cs2 ) )
    5888                 :            :       return cs1;  // success
    5889                 :            :     
    5890                 :            :     if( !cs1->has_hidden_entities() )
    5891                 :            :       remove_composite( cs1 );
    5892                 :            :     if( !cs2->has_hidden_entities() )
    5893                 :            :       remove_composite( cs2 );
    5894                 :            :     return 0; // fail
    5895                 :            :   }
    5896                 :            :   
    5897                 :            :     // make sure all curves are merged
    5898                 :            :   CompositeLoop* loop = 0;
    5899                 :            :   bool reversed = false;
    5900                 :            :   bool failed = false;
    5901                 :            :   while( !failed && (loop = cs1->next_loop(loop)) )
    5902                 :            :   {
    5903                 :            :     CompositeCoEdge* coedge = loop->first_coedge();
    5904                 :            :     do
    5905                 :            :     {
    5906                 :            :       if( ! coedge->get_curve()->find_coedge( cs2 ) )
    5907                 :            :       {
    5908                 :            :         failed = true;
    5909                 :            :         break;
    5910                 :            :       }
    5911                 :            :       coedge = coedge->next();
    5912                 :            :     }
    5913                 :            :     while( coedge != loop->first_coedge() );
    5914                 :            :   }
    5915                 :            :   
    5916                 :            :   if( failed )
    5917                 :            :   {
    5918                 :            :     if( ! cs1->has_hidden_entities() )
    5919                 :            :       remove_composite( cs1 );
    5920                 :            :     if( ! cs2->has_hidden_entities() )
    5921                 :            :       remove_composite( cs2 );
    5922                 :            :   
    5923                 :            :     return 0;
    5924                 :            :   }
    5925                 :            :   
    5926                 :            :   while( CompositeCoSurf* cosurf = cs2->next_co_surface() )
    5927                 :            :   {
    5928                 :            :     cs2->remove( cosurf );
    5929                 :            :     cs1->add( cosurf );
    5930                 :            :     if( reversed )
    5931                 :            :     {
    5932                 :            :       CubitSense sense = cosurf->sense();
    5933                 :            :       sense = sense == CUBIT_REVERSED ? CUBIT_FORWARD : CUBIT_REVERSED;
    5934                 :            :       cosurf->sense( sense );
    5935                 :            :     }
    5936                 :            :   }
    5937                 :            :   cs1->stitch( cs2 );
    5938                 :            : 
    5939                 :            :   return cs1;
    5940                 :            : */
    5941                 :            : }
    5942                 :            : 
    5943                 :          0 : TBPoint* CompositeEngine::insert_point(CompositeCurve* curve, double u)
    5944                 :            : {
    5945                 :            :   int i, index;
    5946                 :            :   double param;
    5947                 :          0 :   TBPoint *result = 0;
    5948         [ #  # ]:          0 :   CubitVector position;
    5949         [ #  # ]:          0 :   DLIList<TBPoint*> pts;
    5950                 :          0 :   double tolsqr = GEOMETRY_RESABS*GEOMETRY_RESABS;
    5951                 :            :   TBPoint *start, *end;
    5952 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> pt_list;
    5953                 :          0 :   Curve *rcurve = 0;
    5954                 :            : 
    5955                 :            :   // Get the curve in the CompositeCurve on which the
    5956                 :            :   // parameter u lies.
    5957 [ #  # ][ #  # ]:          0 :   if( ! curve->curve_param( u, param, index ) )
    5958                 :          0 :     return 0;
    5959         [ #  # ]:          0 :   rcurve = curve->get_curve(index);
    5960                 :            : 
    5961                 :            :   // Get the position corresponding with u.
    5962 [ #  # ][ #  # ]:          0 :   if( !rcurve->position_from_u(param,position) )
    5963                 :          0 :     return 0;
    5964                 :            :   
    5965                 :            :   // Get the CompositeCurve's hidden points.  We will
    5966                 :            :   // first see if the position to insert is on top of 
    5967                 :            :   // one of the hidden points.
    5968         [ #  # ]:          0 :   curve->get_hidden_points(pts);
    5969 [ #  # ][ #  # ]:          0 :   for(i=pts.size(); i--;)
    5970                 :            :   {
    5971         [ #  # ]:          0 :     TBPoint *cur_pt = pts.get_and_step();
    5972                 :            : 
    5973                 :            :     // Don't use GEOMETRY_RESABS if we can get a
    5974                 :            :     // value from the solid modeling engine.
    5975                 :          0 :     double tmp_tol = tolsqr;
    5976         [ #  # ]:          0 :     CompositePoint *cp = dynamic_cast<CompositePoint*>(cur_pt);
    5977                 :          0 :     GeometryQueryEngine *gqe = NULL;
    5978         [ #  # ]:          0 :     if(cp)
    5979                 :            :     {
    5980         [ #  # ]:          0 :       TBPoint *real_pt = cp->get_point();
    5981         [ #  # ]:          0 :       gqe = real_pt->get_geometry_query_engine();
    5982                 :            :     }
    5983                 :            :     else
    5984         [ #  # ]:          0 :       gqe = cur_pt->get_geometry_query_engine();
    5985         [ #  # ]:          0 :     if(gqe)
    5986                 :            :     {
    5987         [ #  # ]:          0 :       double tmp_tol = gqe->get_sme_resabs_tolerance();
    5988                 :          0 :       tmp_tol *= tmp_tol;
    5989         [ #  # ]:          0 :       if(tmp_tol > tolsqr)
    5990                 :          0 :         tolsqr = tmp_tol;
    5991                 :            :     }
    5992 [ #  # ][ #  # ]:          0 :     if( (cur_pt->coordinates() - position).length_squared() < tmp_tol )
         [ #  # ][ #  # ]
    5993                 :            :     {
    5994                 :          0 :       result = cur_pt;
    5995                 :          0 :       i = 0;
    5996                 :            :     }
    5997                 :            :   }
    5998                 :            : 
    5999                 :            :   // If the insert position wasn't one of the hidden 
    6000                 :            :   // points look at the ends of the underlying curves
    6001                 :            :   // to see if it is one of the end points.
    6002         [ #  # ]:          0 :   if(!result)
    6003                 :            :   {
    6004         [ #  # ]:          0 :     rcurve->get_children_virt(pt_list);
    6005 [ #  # ][ #  # ]:          0 :     assert(pt_list.size());
    6006         [ #  # ]:          0 :     pt_list.reset();
    6007 [ #  # ][ #  # ]:          0 :     start = dynamic_cast<TBPoint*>(pt_list.get());
    6008 [ #  # ][ #  # ]:          0 :     end = dynamic_cast<TBPoint*>(pt_list.next());
    6009 [ #  # ][ #  # ]:          0 :     assert( start && end );
    6010                 :            :     
    6011 [ #  # ][ #  # ]:          0 :     if( (start->coordinates() - position).length_squared() < tolsqr )
         [ #  # ][ #  # ]
    6012                 :            :     {
    6013                 :          0 :       result = start;
    6014                 :            :     }
    6015 [ #  # ][ #  # ]:          0 :     else if( (end->coordinates() - position).length_squared() < tolsqr )
         [ #  # ][ #  # ]
    6016                 :            :     {
    6017                 :          0 :       result = end;
    6018                 :            :     }
    6019                 :            :     else
    6020                 :            :     {
    6021                 :            :       // If the insert position wasn't one of the end points go 
    6022                 :            :       // ahead and insert a point into the curve.
    6023 [ #  # ][ #  # ]:          0 :       result = PartitionEngine::instance().insert_point(rcurve,param);
    6024         [ #  # ]:          0 :       if( !result )
    6025                 :          0 :         return 0;
    6026                 :            :     }
    6027                 :            :   }
    6028                 :            :     
    6029                 :            :   // Work with a real point here because functions called from
    6030                 :            :   // restore_point_in_curve() may remove the composite all together
    6031                 :            :   // leaving us with a stale CompositePoint pointer at this level.
    6032         [ #  # ]:          0 :   CompositePoint *comp_pt = dynamic_cast<CompositePoint*>(result);
    6033         [ #  # ]:          0 :   if(comp_pt)
    6034         [ #  # ]:          0 :     result = comp_pt->get_point();
    6035                 :            : 
    6036                 :            :   // Finally, undo the composite.
    6037 [ #  # ][ #  # ]:          0 :   if ( ! restore_point_in_curve( result ) )
    6038                 :          0 :     return 0;
    6039                 :            :     
    6040 [ #  # ][ #  # ]:          0 :   TBPoint* comp = dynamic_cast<CompositePoint*>(result->owner());
    6041 [ #  # ][ #  # ]:          0 :   return comp ? comp : result;
    6042                 :            : }
    6043                 :            : 
    6044                 :          0 : TBPoint* CompositeEngine::insert_point_curve( CompositeSurface* surf,
    6045                 :            :                                             const CubitVector& pos )
    6046                 :            : {
    6047                 :            :     // find closest surface
    6048         [ #  # ]:          0 :   int i = surf->closest_underlying_surface( pos );
    6049         [ #  # ]:          0 :   Surface *dummy_surf, *real_surf = surf->get_surface(i);
    6050                 :            :   
    6051 [ #  # ][ #  # ]:          0 :   TBPoint* pt = PartitionEngine::instance().insert_point_curve( real_surf, pos, dummy_surf );
    6052         [ #  # ]:          0 :   if ( !pt )
    6053                 :          0 :     return 0;
    6054                 :            :   
    6055 [ #  # ][ #  # ]:          0 :   if (!restore_point(pt))
    6056                 :          0 :     return 0;
    6057                 :            :   
    6058 [ #  # ][ #  # ]:          0 :   return dynamic_cast<CompositePoint*>(pt->owner());
    6059                 :            : }
    6060                 :            : 
    6061                 :          0 : int CompositeEngine::is_hidden(TopologyBridge *tb)
    6062                 :            : {
    6063                 :          0 :   int ret = 0;
    6064                 :          0 :   int done = 0;
    6065                 :          0 :   TopologyBridge *cur_bridge = tb;
    6066         [ #  # ]:          0 :   while(!done)
    6067                 :            :   {
    6068                 :          0 :     TBOwner *tbowner = cur_bridge->owner();
    6069 [ #  # ][ #  # ]:          0 :     if(dynamic_cast<BridgeManager*>(tbowner))
                 [ #  # ]
    6070                 :            :     {
    6071                 :          0 :       done = 1;
    6072                 :          0 :       ret = 0;
    6073                 :            :     }
    6074 [ #  # ][ #  # ]:          0 :     else if(dynamic_cast<HiddenEntitySet*>(tbowner))
                 [ #  # ]
    6075                 :            :     {
    6076                 :          0 :       done = 1;
    6077                 :          0 :       ret = 1;
    6078                 :            :     }
    6079         [ #  # ]:          0 :     cur_bridge = dynamic_cast<TopologyBridge*>(tbowner);
    6080         [ #  # ]:          0 :     if(!cur_bridge)
    6081                 :          0 :       done = 1;
    6082                 :            :   }
    6083                 :          0 :   return ret;
    6084                 :            : }
    6085                 :            : 
    6086                 :          0 : CubitStatus CompositeEngine::insert_curve( DLIList<Surface*>& surfaces,
    6087                 :            :                                            DLIList<CubitVector*>& polyline,
    6088                 :            :                                            DLIList<Surface*>& new_surfaces,
    6089                 :            :                                            DLIList<Curve*>& new_curves )
    6090                 :            : {
    6091                 :            :   int i;
    6092                 :            :   
    6093         [ #  # ]:          0 :   DLIList<Surface*> surfs_to_reverse;
    6094 [ #  # ][ #  # ]:          0 :   DLIList<Surface*> real_surfs;
    6095 [ #  # ][ #  # ]:          0 :   DLIList<TBPoint*> points;
    6096         [ #  # ]:          0 :   surfaces.reset();
    6097                 :            : 
    6098 [ #  # ][ #  # ]:          0 :   for ( i = surfaces.size(); i--; )
    6099                 :            :   {
    6100         [ #  # ]:          0 :     Surface* surf = surfaces.get_and_step();
    6101         [ #  # ]:          0 :     CompositeSurface* comp = dynamic_cast<CompositeSurface*>(surf);
    6102         [ #  # ]:          0 :     if ( !comp )
    6103                 :            :     {
    6104         [ #  # ]:          0 :       real_surfs.append(surf);
    6105                 :          0 :       continue;
    6106                 :            :     }
    6107                 :            :     
    6108                 :            :     // Partitioning needs all of the surfaces involved in the partition
    6109                 :            :     // to have facets oriented in the same direction w.r.t. the volume (in or out).
    6110                 :            :     // For surface facets that will have to be flipped we also want to reverse
    6111                 :            :     // the sense of the PartitionSurfaces to be consistent.  Therefore, we
    6112                 :            :     // create a list here of surfaces/facets that need to be flipped.  We
    6113                 :            :     // will use the sense info from the CompositeSurface to determine this.
    6114 [ #  # ][ #  # ]:          0 :     for ( int j = 0; j < comp->num_surfs(); j++ )
    6115                 :            :     {
    6116 [ #  # ][ #  # ]:          0 :       real_surfs.append( comp->get_surface( j ) );
    6117 [ #  # ][ #  # ]:          0 :       if(comp->get_sense(j) == CUBIT_REVERSED)
    6118 [ #  # ][ #  # ]:          0 :         surfs_to_reverse.append(comp->get_surface(j));
    6119                 :            :     }
    6120                 :            :       
    6121                 :            :       // append all real points visible on composite surfaces
    6122                 :            :       // to list.
    6123                 :          0 :     CompositeLoop* loop = 0;
    6124 [ #  # ][ #  # ]:          0 :     while( (loop = comp->next_loop(loop) ) != NULL )
    6125                 :            :     {
    6126         [ #  # ]:          0 :       CompositeCoEdge* coe = loop->first_coedge();
    6127         [ #  # ]:          0 :       do {
    6128 [ #  # ][ #  # ]:          0 :         points.append(coe->get_curve()->start_point()->get_point());
         [ #  # ][ #  # ]
    6129 [ #  # ][ #  # ]:          0 :         points.append(coe->get_curve()->end_point()->get_point());
         [ #  # ][ #  # ]
    6130         [ #  # ]:          0 :         coe = coe->next();
    6131         [ #  # ]:          0 :       } while( coe != loop->first_coedge() );
    6132                 :            :     }
    6133                 :            :   }
    6134                 :            :   
    6135         [ #  # ]:          0 :   CubitStatus s = PartitionEngine::instance().
    6136                 :            :     insert_curve( real_surfs, polyline, new_surfaces, new_curves, NULL,
    6137 [ #  # ][ #  # ]:          0 :     surfs_to_reverse.size() ? &surfs_to_reverse : NULL);
                 [ #  # ]
    6138         [ #  # ]:          0 :   if ( !s )
    6139                 :          0 :     return CUBIT_FAILURE;
    6140                 :            :   
    6141         [ #  # ]:          0 :   new_curves.last();
    6142 [ #  # ][ #  # ]:          0 :   for ( i = new_curves.size(); i--; )
    6143                 :            :   {
    6144         [ #  # ]:          0 :     Curve* curve = new_curves.step_and_get();
    6145 [ #  # ][ #  # ]:          0 :     CompositeCurve* ccurve = dynamic_cast<CompositeCurve*>(curve->owner());
    6146         [ #  # ]:          0 :     if ( !ccurve ) continue;
    6147                 :            :     
    6148         [ #  # ]:          0 :     restore_curve( ccurve );
    6149 [ #  # ][ #  # ]:          0 :     ccurve = dynamic_cast<CompositeCurve*>(curve->owner());
    6150         [ #  # ]:          0 :     if ( ccurve )
    6151         [ #  # ]:          0 :       new_curves.change_to(ccurve);
    6152                 :            :   }
    6153                 :            :   
    6154                 :            :     // The remainder of this function tries to composite over
    6155                 :            :     // 2-valence vertics in the chain of resulting curves.
    6156                 :            :     // These vertices are the result of intersections with 
    6157                 :            :     // hidden curves.  If there is only one result curve, then
    6158                 :            :     // skip the rest.
    6159 [ #  # ][ #  # ]:          0 :   if (new_curves.size() == 1)
    6160                 :            :   {
    6161         [ #  # ]:          0 :     clean_out_deactivated_geometry();
    6162                 :          0 :     return CUBIT_SUCCESS;
    6163                 :            :   }
    6164                 :            :   
    6165                 :            :   
    6166                 :            :     // Remove any 2-valence vertices in chain of resulting curves.
    6167                 :            :     // These are intersections with hidden curves.
    6168         [ #  # ]:          0 :   new_curves.reset();
    6169         [ #  # ]:          0 :   Curve* prev_curve = new_curves.get();
    6170 [ #  # ][ #  # ]:          0 :   DLIList<TopologyBridge*> prev_pts(2), next_pts(2), pt_curves;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    6171 [ #  # ][ #  # ]:          0 :   DLIList<TBPoint*> dead_points;
    6172         [ #  # ]:          0 :   prev_curve->get_children( prev_pts, false, COMPOSITE_LAYER );
    6173 [ #  # ][ #  # ]:          0 :   for ( i = new_curves.size(); i--; )
    6174                 :            :   {
    6175         [ #  # ]:          0 :     Curve* curve = new_curves.step_and_get();
    6176         [ #  # ]:          0 :     curve->get_children( next_pts, false, COMPOSITE_LAYER );
    6177 [ #  # ][ #  # ]:          0 :     while( prev_pts.size() )
    6178                 :            :     {
    6179 [ #  # ][ #  # ]:          0 :       TBPoint* point = dynamic_cast<TBPoint*>(prev_pts.pop());
    6180 [ #  # ][ #  # ]:          0 :       if( !next_pts.move_to( point ) )
    6181                 :          0 :         continue;
    6182         [ #  # ]:          0 :       next_pts.extract();
    6183                 :            :       
    6184         [ #  # ]:          0 :       pt_curves.clean_out();
    6185         [ #  # ]:          0 :       point->get_parents( pt_curves );
    6186 [ #  # ][ #  # ]:          0 :       if ( pt_curves.size() != 2 || points.is_in_list(point) )
         [ #  # ][ #  # ]
                 [ #  # ]
    6187                 :          0 :         continue;
    6188                 :            :        
    6189 [ #  # ][ #  # ]:          0 :       if ( CompositePoint* comp = dynamic_cast<CompositePoint*>(point) )
    6190 [ #  # ][ #  # ]:          0 :         if ( points.is_in_list(comp->get_point()) )
                 [ #  # ]
    6191                 :          0 :           continue;
    6192                 :            :        
    6193         [ #  # ]:          0 :       dead_points.append( point );
    6194         [ #  # ]:          0 :       prev_pts.clean_out();
    6195                 :            :     } 
    6196                 :            :        
    6197         [ #  # ]:          0 :     prev_pts = next_pts;
    6198         [ #  # ]:          0 :     next_pts.clean_out();
    6199                 :            :   }
    6200                 :            : 
    6201                 :            :       
    6202 [ #  # ][ #  # ]:          0 :   while( dead_points.size() )
    6203                 :            :   {
    6204         [ #  # ]:          0 :     TBPoint* point = dead_points.pop();
    6205 [ #  # ][ #  # ]:          0 :     if ( CompositePoint* comp = dynamic_cast<CompositePoint*>(point->owner()) )
                 [ #  # ]
    6206                 :          0 :       point = comp;
    6207                 :            :       
    6208         [ #  # ]:          0 :     pt_curves.clean_out();
    6209         [ #  # ]:          0 :     point->get_parents( pt_curves );
    6210 [ #  # ][ #  # ]:          0 :     if ( pt_curves.size() == 1 )
    6211                 :          0 :       continue;
    6212 [ #  # ][ #  # ]:          0 :     assert(pt_curves.size() == 2);
    6213                 :            :     
    6214         [ #  # ]:          0 :     CompositeCurve* keep = remove_point(point);
    6215         [ #  # ]:          0 :     if (!keep)
    6216                 :          0 :       continue;
    6217                 :            :     
    6218                 :          0 :     bool add = true;
    6219 [ #  # ][ #  # ]:          0 :     if ( pt_curves.move_to(keep) )
    6220                 :            :     {
    6221         [ #  # ]:          0 :       pt_curves.extract();
    6222                 :          0 :       add = false;
    6223                 :            :     }
    6224                 :            :     
    6225 [ #  # ][ #  # ]:          0 :     while( pt_curves.size() )
    6226                 :            :     {
    6227         [ #  # ]:          0 :       Curve* stale_ptr = reinterpret_cast<Curve*>(pt_curves.pop());
    6228 [ #  # ][ #  # ]:          0 :       if ( new_curves.move_to( stale_ptr ) )
    6229                 :            :       {
    6230         [ #  # ]:          0 :         if ( add )
    6231                 :            :         {
    6232         [ #  # ]:          0 :           new_curves.change_to( keep );
    6233                 :          0 :           add = false;
    6234                 :            :         }
    6235                 :            :         else
    6236                 :            :         {
    6237         [ #  # ]:          0 :           new_curves.remove();
    6238                 :            :         }
    6239                 :            :       }
    6240                 :            :     }
    6241         [ #  # ]:          0 :     if ( add )
    6242         [ #  # ]:          0 :       new_curves.append( keep );
    6243                 :            :   }
    6244                 :            :  
    6245         [ #  # ]:          0 :   clean_out_deactivated_geometry();
    6246         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    6247                 :            : }
    6248                 :            : 
    6249                 :            : //-------------------------------------------------------------------------
    6250                 :            : // Purpose       : Update for destroted underlying topology
    6251                 :            : //
    6252                 :            : // Special Notes : 
    6253                 :            : //
    6254                 :            : // Creator       : Jason Kraftcheck
    6255                 :            : //
    6256                 :            : // Creation Date : 06/14/04
    6257                 :            : //-------------------------------------------------------------------------
    6258                 :          0 : void CompositeEngine::notify_deactivated (CompositeBody* body)
    6259                 :            : {
    6260         [ #  # ]:          0 :   while (CompositeLump* vol_ptr = body->next_lump(NULL))
    6261                 :            :   {
    6262                 :          0 :     body->remove( vol_ptr );
    6263                 :            :   }
    6264         [ #  # ]:          0 :   deactivatedList.append_unique( body );
    6265                 :          0 : }
    6266                 :            : 
    6267                 :            : //-------------------------------------------------------------------------
    6268                 :            : // Purpose       : Update for destroted underlying topology
    6269                 :            : //
    6270                 :            : // Special Notes : 
    6271                 :            : //
    6272                 :            : // Creator       : Jason Kraftcheck
    6273                 :            : //
    6274                 :            : // Creation Date : 06/14/04
    6275                 :            : //-------------------------------------------------------------------------
    6276                 :          0 : void CompositeEngine::notify_deactivated( CompositeLump* vol )
    6277                 :            : {
    6278         [ #  # ]:          0 :   while (CompositeShell* shell = vol->next_shell(NULL))
    6279                 :            :   {
    6280         [ #  # ]:          0 :     while (CompositeCoSurf* cosurf = shell->first_co_surf())
    6281                 :            :     {
    6282                 :          0 :       shell->remove( cosurf );
    6283                 :          0 :       CompositeSurface* surf = cosurf->get_surface();
    6284         [ #  # ]:          0 :       if (surf)
    6285                 :          0 :         surf->remove( cosurf );
    6286         [ #  # ]:          0 :       delete cosurf;
    6287                 :            :     }
    6288                 :          0 :     vol->remove( shell );
    6289         [ #  # ]:          0 :     deactivatedList.append_unique( shell );
    6290                 :          0 :   }
    6291         [ #  # ]:          0 :   deactivatedList.append_unique( vol );
    6292                 :          0 : }
    6293                 :            : 
    6294                 :            :   
    6295                 :            : //-------------------------------------------------------------------------
    6296                 :            : // Purpose       : Update for destroted underlying topology
    6297                 :            : //
    6298                 :            : // Special Notes : 
    6299                 :            : //
    6300                 :            : // Creator       : Jason Kraftcheck
    6301                 :            : //
    6302                 :            : // Creation Date : 07/31/03
    6303                 :            : //-------------------------------------------------------------------------
    6304                 :          0 : void CompositeEngine::notify_deactivated (CompositeSurface* surface)
    6305                 :            : {
    6306         [ #  # ]:          0 :   while (CompositeCoSurf* cosurf_ptr = surface->next_co_surface(NULL))
    6307                 :            :   {
    6308         [ #  # ]:          0 :     if (cosurf_ptr->get_shell())
    6309                 :          0 :       cosurf_ptr->get_shell()->remove(cosurf_ptr);
    6310                 :          0 :     surface->remove(cosurf_ptr);
    6311         [ #  # ]:          0 :     delete cosurf_ptr;
    6312                 :            :   }
    6313                 :            :   
    6314         [ #  # ]:          0 :   while (CompositeLoop* loop_ptr = surface->first_loop())
    6315                 :            :   {
    6316         [ #  # ]:          0 :     while (CompositeCoEdge* coedge_ptr = loop_ptr->first_coedge())
    6317                 :            :     {
    6318                 :          0 :       CompositeCurve* curve = coedge_ptr->get_curve();
    6319         [ #  # ]:          0 :       if (curve)
    6320                 :            :       {
    6321                 :          0 :         curve->remove(coedge_ptr);
    6322                 :            :           // Clean up point-curves with surface...
    6323         [ #  # ]:          0 :         if (curve->num_curves() == 0)
    6324                 :          0 :           notify_deactivated(curve);
    6325                 :            :       }
    6326                 :          0 :       loop_ptr->remove(coedge_ptr);
    6327         [ #  # ]:          0 :       deactivatedList.append_unique(coedge_ptr);
    6328                 :            :     }
    6329                 :          0 :     surface->remove(loop_ptr);
    6330         [ #  # ]:          0 :     deactivatedList.append_unique(loop_ptr);
    6331                 :          0 :   }
    6332         [ #  # ]:          0 :   deactivatedList.append_unique(surface);
    6333                 :          0 : }
    6334                 :            : 
    6335                 :          0 : void CompositeEngine::notify_deactivated (CompositeCurve* curve)
    6336                 :            : {
    6337         [ #  # ]:          0 :   while (CompositeCoEdge* coedge_ptr = curve->next_coedge(NULL))
    6338                 :            :   {
    6339         [ #  # ]:          0 :     if (coedge_ptr->get_loop())
    6340                 :          0 :       coedge_ptr->get_loop()->remove(coedge_ptr);
    6341                 :          0 :     curve->remove(coedge_ptr);
    6342         [ #  # ]:          0 :     deactivatedList.append_unique(coedge_ptr);
    6343                 :            :   }
    6344                 :            :   
    6345         [ #  # ]:          0 :   if (curve->start_point())
    6346                 :          0 :     curve->start_point(0);
    6347         [ #  # ]:          0 :   if (curve->end_point())
    6348                 :          0 :     curve->end_point(0);
    6349                 :            :     
    6350         [ #  # ]:          0 :   deactivatedList.append_unique(curve);
    6351                 :          0 : }
    6352                 :            : 
    6353                 :          0 : void CompositeEngine::notify_deactivated (CompositePoint* point)
    6354                 :            : {
    6355         [ #  # ]:          0 :   while (CompositeCurve* curve_ptr = point->next_curve(NULL))
    6356                 :            :   {
    6357         [ #  # ]:          0 :     if (point == curve_ptr->start_point())
    6358                 :          0 :       curve_ptr->start_point(0);
    6359         [ #  # ]:          0 :     if (point == curve_ptr->end_point())
    6360                 :          0 :       curve_ptr->end_point(0);
    6361                 :            :   }
    6362                 :            :   
    6363         [ #  # ]:          0 :   deactivatedList.append_unique(point);
    6364                 :          0 : }
    6365                 :            : 
    6366                 :       1826 : void CompositeEngine::clean_out_deactivated_geometry()
    6367                 :            : {
    6368         [ -  + ]:       1826 :   while (deactivatedList.size())
    6369         [ #  # ]:          0 :     delete deactivatedList.pop();
    6370                 :       1826 : }
    6371                 :            : 
    6372                 :            :         
    6373                 :          0 : CubitStatus CompositeEngine::translate( CompositeBody* body, 
    6374                 :            :                                         const CubitVector& delta )
    6375                 :            : {
    6376 [ #  # ][ #  # ]:          0 :   assert (body && delta.length_squared());
    6377                 :          0 :   return CUBIT_FAILURE;
    6378                 :            : }
    6379                 :            : 
    6380                 :          0 : CubitStatus CompositeEngine::rotate( CompositeBody* body,
    6381                 :            :                                      const CubitVector& axis,
    6382                 :            :                                      double degrees )
    6383                 :            : {
    6384 [ #  # ][ #  # ]:          0 :   assert( body && axis.length_squared() && degrees );
                 [ #  # ]
    6385                 :          0 :   return CUBIT_FAILURE;
    6386                 :            : }
    6387                 :            : 
    6388                 :          0 : CubitStatus CompositeEngine::scale( CompositeBody* body,
    6389                 :            :                                     const CubitVector& factors )
    6390                 :            : {
    6391 [ #  # ][ #  # ]:          0 :   assert( body && factors.x() && factors.y() && factors.z() );
         [ #  # ][ #  # ]
    6392                 :          0 :   return CUBIT_FAILURE;
    6393                 :            : }
    6394                 :            : 
    6395                 :          0 : CubitStatus CompositeEngine::reflect( CompositeBody* body,
    6396                 :            :                                       const CubitVector& axis )
    6397                 :            : 
    6398                 :            : {
    6399 [ #  # ][ #  # ]:          0 :   assert( body && axis.length() );
    6400                 :          0 :   return CUBIT_FAILURE;
    6401                 :            : }
    6402                 :            : 
    6403                 :          0 : CubitStatus CompositeEngine::restore_transform( CompositeBody* body )
    6404                 :            : {
    6405         [ #  # ]:          0 :   assert( 0 != body );
    6406                 :          0 :   return CUBIT_FAILURE;
    6407                 :            : }
    6408                 :            : 
    6409                 :            : 
    6410                 :          0 : CubitStatus CompositeEngine::translate( CompositeSurface* surf, 
    6411                 :            :                                         const CubitVector& delta )
    6412                 :            : {
    6413 [ #  # ][ #  # ]:          0 :   assert (surf && delta.length_squared());
    6414                 :          0 :   return CUBIT_FAILURE;
    6415                 :            : }
    6416                 :            : 
    6417                 :          0 : CubitStatus CompositeEngine::rotate( CompositeSurface* surf,
    6418                 :            :                                      const CubitVector& axis,
    6419                 :            :                                      double degrees )
    6420                 :            : {
    6421 [ #  # ][ #  # ]:          0 :   assert( surf && axis.length_squared() && degrees );
                 [ #  # ]
    6422                 :          0 :   return CUBIT_FAILURE;
    6423                 :            : }
    6424                 :            : 
    6425                 :          0 : CubitStatus CompositeEngine::scale( CompositeSurface* surf,
    6426                 :            :                                     const CubitVector& factors )
    6427                 :            : {
    6428 [ #  # ][ #  # ]:          0 :   assert( surf && factors.x() && factors.y() && factors.z() );
         [ #  # ][ #  # ]
    6429                 :          0 :   return CUBIT_FAILURE;
    6430                 :            : }
    6431                 :            : 
    6432                 :          0 : CubitStatus CompositeEngine::reflect( CompositeSurface* surf,
    6433                 :            :                                       const CubitVector& axis )
    6434                 :            : 
    6435                 :            : {
    6436 [ #  # ][ #  # ]:          0 :   assert( surf && axis.length() );
    6437                 :          0 :   return CUBIT_FAILURE;
    6438                 :            : }
    6439                 :            : 
    6440                 :            : 
    6441                 :          0 : CubitStatus CompositeEngine::translate( CompositeCurve* curve, 
    6442                 :            :                                         const CubitVector& delta )
    6443                 :            : {
    6444 [ #  # ][ #  # ]:          0 :   assert (curve && delta.length_squared());
    6445                 :          0 :   return CUBIT_FAILURE;
    6446                 :            : }
    6447                 :            : 
    6448                 :          0 : CubitStatus CompositeEngine::rotate( CompositeCurve* curve,
    6449                 :            :                                      const CubitVector& axis,
    6450                 :            :                                      double degrees )
    6451                 :            : {
    6452 [ #  # ][ #  # ]:          0 :   assert( curve && axis.length_squared() && degrees );
                 [ #  # ]
    6453                 :          0 :   return CUBIT_FAILURE;
    6454                 :            : }
    6455                 :            : 
    6456                 :          0 : CubitStatus CompositeEngine::scale( CompositeCurve* curve,
    6457                 :            :                                     const CubitVector& factors )
    6458                 :            : {
    6459 [ #  # ][ #  # ]:          0 :   assert( curve && factors.x() && factors.y() && factors.z() );
         [ #  # ][ #  # ]
    6460                 :          0 :   return CUBIT_FAILURE;
    6461                 :            : }
    6462                 :            : 
    6463                 :          0 : CubitStatus CompositeEngine::reflect( CompositeCurve* curve,
    6464                 :            :                                       const CubitVector& axis )
    6465                 :            : 
    6466                 :            : {
    6467 [ #  # ][ #  # ]:          0 :   assert( curve && axis.length() );
    6468                 :          0 :   return CUBIT_FAILURE;
    6469                 :            : }
    6470                 :            : 
    6471                 :        444 : CubitStatus CompositeEngine::notify_transform( TopologyBridge* bridge,
    6472                 :            :                                                const CubitTransformMatrix& xform )
    6473                 :            : {
    6474                 :            :   int i;
    6475 [ +  - ][ +  - ]:        888 :   DLIList<TopologyBridge*> lumps, shells, surfaces, tmp_list;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    6476                 :            :   
    6477 [ -  + ][ +  - ]:        444 :   if (BodySM* body_sm = dynamic_cast<BodySM*>(bridge))
    6478         [ +  - ]:        444 :     body_sm->get_children( lumps, true, COMPOSITE_LAYER);
    6479 [ #  # ][ #  # ]:          0 :   else if (Lump* lump = dynamic_cast<Lump*>(bridge))
    6480         [ #  # ]:          0 :     lumps.append(lump);
    6481 [ #  # ][ #  # ]:          0 :   else if (ShellSM* shell = dynamic_cast<ShellSM*>(bridge))
    6482         [ #  # ]:          0 :     shells.append(shell);
    6483 [ #  # ][ #  # ]:          0 :   else if (Surface* surface = dynamic_cast<Surface*>(bridge))
    6484         [ #  # ]:          0 :     surfaces.append(surface);
    6485                 :            :   else  
    6486                 :          0 :     return CUBIT_SUCCESS;
    6487                 :            :   
    6488 [ +  - ][ +  + ]:        888 :   for (i = lumps.size(); i--; )
    6489                 :            :   {
    6490         [ +  - ]:        444 :     TopologyBridge* lump = lumps.step_and_get();
    6491         [ -  + ]:        444 :     CompositeLump* comp_lump = dynamic_cast<CompositeLump*>(lump);
    6492         [ -  + ]:        444 :     if (comp_lump)
    6493         [ #  # ]:          0 :       comp_lump->update();
    6494                 :            :   }
    6495                 :            : 
    6496 [ +  - ][ +  + ]:        888 :   while (lumps.size())
    6497                 :            :   {
    6498         [ +  - ]:        444 :     TopologyBridge* lump = lumps.pop();
    6499         [ +  - ]:        444 :     tmp_list.clean_out();
    6500         [ +  - ]:        444 :     lump->get_children( tmp_list, true, COMPOSITE_LAYER );
    6501         [ +  - ]:        444 :     shells += tmp_list;
    6502                 :            :   }
    6503                 :            :   
    6504 [ +  - ][ +  + ]:        888 :   while (shells.size())
    6505                 :            :   {
    6506         [ +  - ]:        444 :     TopologyBridge* shell = shells.pop();
    6507         [ +  - ]:        444 :     tmp_list.clean_out();
    6508         [ +  - ]:        444 :     shell->get_children( tmp_list, true, COMPOSITE_LAYER );
    6509         [ +  - ]:        444 :     surfaces += tmp_list;
    6510                 :            :   }
    6511                 :            :   
    6512 [ +  - ][ +  + ]:       2492 :   for (i = surfaces.size(); i--; )
    6513                 :            :   {
    6514         [ +  - ]:       2048 :     TopologyBridge* surface = surfaces.step_and_get();
    6515         [ -  + ]:       2048 :     CompositeSurface* composite = dynamic_cast<CompositeSurface*>(surface);
    6516         [ -  + ]:       2048 :     if (composite)
    6517                 :            :     {
    6518         [ #  # ]:          0 :       composite->notify_transformed();
    6519         [ #  # ]:          0 :       composite->update();
    6520                 :            :     }
    6521         [ +  - ]:       2048 :     DLIList<Curve*> curves;
    6522         [ +  - ]:       2048 :     surface->curves(curves);
    6523                 :            :     int j;
    6524 [ +  - ][ +  + ]:       9532 :     for (j = 0; j < curves.size(); j++)
    6525                 :            :     {
    6526                 :            :        CompositeCurve* comp = 
    6527 [ +  - ][ -  + ]:       7484 :           dynamic_cast<CompositeCurve*>(curves.get_and_step());
    6528         [ -  + ]:       7484 :        if (comp)
    6529         [ #  # ]:          0 :           comp->update();
    6530                 :            :     }
    6531         [ +  - ]:       2048 :   }
    6532                 :            :   
    6533 [ +  - ][ +  - ]:        444 :   double det = xform.sub_matrix( 3, 3 ).determinant();
                 [ +  - ]
    6534                 :        444 :   bool reverse = det < 0.0;
    6535         [ +  + ]:        444 :   if (!reverse)
    6536                 :        433 :     return CUBIT_SUCCESS;
    6537                 :            : 
    6538                 :            :   // if we get here, the transform was a reflection so we need to make sure all
    6539                 :            :   // loops and coedges get reversed
    6540 [ +  - ][ +  - ]:         22 :   DLIList<TopologyBridge*> loops;
    6541 [ +  - ][ +  - ]:         22 :   DLIList<TopologyBridge*> tmp_loops;
    6542 [ +  - ][ +  - ]:         22 :   DLIList<TopologyBridge*> coedges;
    6543                 :            : 
    6544 [ +  - ][ +  + ]:         77 :   while (surfaces.size())
    6545                 :            :   {
    6546 [ +  - ][ +  - ]:         66 :     surfaces.pop()->get_children( tmp_loops, true, COMPOSITE_LAYER );
    6547         [ +  - ]:         66 :     loops += tmp_loops;
    6548 [ +  - ][ +  + ]:        132 :     while (tmp_loops.size())
    6549                 :            :     {
    6550 [ +  - ][ +  - ]:         66 :       tmp_loops.pop()->get_children( tmp_list, true, COMPOSITE_LAYER );
    6551         [ +  - ]:         66 :       coedges += tmp_list;
    6552         [ +  - ]:         66 :       tmp_list.clean_out();
    6553                 :            :     }
    6554                 :            :  }
    6555                 :            : 
    6556                 :            :   // reverse loops and coedges separately, since composite coedges in non-composite
    6557                 :            :   // loops also need to be reversed
    6558                 :         11 :   bool b_reverse_coedges = false;  
    6559 [ +  - ][ +  + ]:         77 :   while (loops.size())
    6560                 :            :   {
    6561 [ +  - ][ -  + ]:         66 :     CompositeLoop* loop = dynamic_cast<CompositeLoop*>(loops.pop());
    6562         [ -  + ]:         66 :     if (loop)
    6563         [ #  # ]:          0 :       loop->reverse(b_reverse_coedges);
    6564                 :            :   }
    6565                 :            : 
    6566                 :            :   // reverse the coedges
    6567 [ +  - ][ +  + ]:        275 :   while (coedges.size())
    6568                 :            :   {
    6569 [ +  - ][ -  + ]:        264 :     CompositeCoEdge* comp = dynamic_cast<CompositeCoEdge*>(coedges.pop());
    6570         [ -  + ]:        264 :     if (comp)
    6571                 :            :     {
    6572         [ #  # ]:          0 :       comp->reverse();
    6573                 :            :     }
    6574                 :            :   }
    6575                 :            : 
    6576         [ +  - ]:        444 :   return CUBIT_SUCCESS;
    6577                 :            : }
    6578                 :            : 
    6579                 :            : 
    6580                 :            : //-------------------------------------------------------------------------
    6581                 :            : // Purpose       : Combine bodies
    6582                 :            : //
    6583                 :            : // Special Notes : 
    6584                 :            : //
    6585                 :            : // Creator       : Jason Kraftcheck
    6586                 :            : //
    6587                 :            : // Creation Date : 06/11/04
    6588                 :            : //-------------------------------------------------------------------------
    6589                 :          0 : CompositeBody* CompositeEngine::combine_bodies( BodySM* body1, BodySM* body2 )
    6590                 :            : {
    6591         [ #  # ]:          0 :   CompositeBody* comp1 = dynamic_cast<CompositeBody*>(body1);
    6592         [ #  # ]:          0 :   if (!comp1)
    6593         [ #  # ]:          0 :     comp1 = dynamic_cast<CompositeBody*>(body1->owner());
    6594         [ #  # ]:          0 :   if (!comp1)
    6595                 :          0 :     comp1 = replace_body( body1 );
    6596                 :            :   
    6597         [ #  # ]:          0 :   CompositeBody* comp2 = dynamic_cast<CompositeBody*>(body2);
    6598         [ #  # ]:          0 :   if (!comp2)
    6599         [ #  # ]:          0 :     comp2 = dynamic_cast<CompositeBody*>(body2->owner());
    6600         [ #  # ]:          0 :   if (!comp2)
    6601                 :          0 :     comp2 = replace_body( body2 );
    6602                 :            :   
    6603 [ #  # ][ #  # ]:          0 :   assert(comp1 && comp2);
    6604         [ #  # ]:          0 :   if (comp1 == comp2)
    6605                 :          0 :     return comp1;
    6606                 :            :     
    6607                 :          0 :   comp1->combine( comp2 );
    6608                 :            :   
    6609         [ #  # ]:          0 :   while (CompositeLump* lump = comp2->next_lump(0))
    6610                 :            :   {
    6611                 :          0 :     comp2->remove( lump );
    6612                 :          0 :     comp1->add( lump );
    6613                 :            :   }
    6614                 :            :   
    6615         [ #  # ]:          0 :   delete comp2;
    6616                 :          0 :   return comp1;
    6617                 :            : }
    6618                 :            : 
    6619                 :          0 : void CompositeEngine::get_tbs_with_bridge_manager_as_owner( TopologyBridge *source_bridge, 
    6620                 :            :                                                             DLIList<TopologyBridge*> &tbs )
    6621                 :            : {
    6622                 :          0 :   TBOwner* tb_owner = source_bridge->owner();
    6623         [ #  # ]:          0 :   CompositeSurface *comp_surf = CAST_TO(tb_owner, CompositeSurface );
    6624         [ #  # ]:          0 :   if( comp_surf )  
    6625                 :            :   { 
    6626         [ #  # ]:          0 :     if( comp_surf->bridge_manager() )
    6627                 :            :     {
    6628         [ #  # ]:          0 :       tbs.append( comp_surf );
    6629                 :          0 :       return;
    6630                 :            :     }
    6631                 :            :   } 
    6632                 :            : 
    6633         [ #  # ]:          0 :   CompositeCurve *comp_curve = CAST_TO(tb_owner, CompositeCurve );
    6634         [ #  # ]:          0 :   if( comp_curve )  
    6635                 :            :   { 
    6636         [ #  # ]:          0 :     if( comp_curve->bridge_manager() )
    6637                 :            :     {
    6638         [ #  # ]:          0 :       tbs.append( comp_curve );
    6639                 :          0 :       return;
    6640                 :            :     }
    6641                 :            :   } 
    6642                 :            : 
    6643         [ #  # ]:          0 :   CompositePoint *comp_pt = CAST_TO(tb_owner, CompositePoint );
    6644         [ #  # ]:          0 :   if( comp_pt )  
    6645                 :            :   { 
    6646         [ #  # ]:          0 :     if( comp_pt->bridge_manager() )
    6647                 :            :     {
    6648         [ #  # ]:          0 :       tbs.append( comp_pt );
    6649                 :          0 :       return;
    6650                 :            :     }
    6651                 :            :   } 
    6652                 :            : 
    6653         [ #  # ]:          0 :   HiddenEntitySet *hidden_ent_set = CAST_TO(tb_owner, HiddenEntitySet );
    6654         [ #  # ]:          0 :   if( hidden_ent_set )
    6655                 :            :   {
    6656                 :          0 :     TBOwner *owner = hidden_ent_set->owner();
    6657         [ #  # ]:          0 :     CompositeCurve *comp_curve = CAST_TO(owner, CompositeCurve );
    6658 [ #  # ][ #  # ]:          0 :     if( comp_curve && comp_curve->bridge_manager() )
                 [ #  # ]
    6659                 :            :     {
    6660         [ #  # ]:          0 :       tbs.append( comp_curve );
    6661                 :          0 :       return;
    6662                 :            :     }
    6663                 :            : 
    6664         [ #  # ]:          0 :     CompositeSurface *comp_surf = CAST_TO(owner, CompositeSurface );
    6665         [ #  # ]:          0 :     if( comp_surf )
    6666                 :          0 :       return;
    6667                 :            : 
    6668                 :          0 :     assert(0);
    6669                 :            :   }
    6670                 :            :   else
    6671                 :            :   {
    6672         [ #  # ]:          0 :     CompositePoint *comp_pt = CAST_TO(tb_owner, CompositePoint);   
    6673                 :            : 
    6674         [ #  # ]:          0 :     if( comp_pt )
    6675                 :            :     {
    6676                 :          0 :       TBOwner *other_owner = comp_pt->owner();
    6677                 :            : 
    6678         [ #  # ]:          0 :       HiddenEntitySet *hidden_ent_set = CAST_TO(other_owner, HiddenEntitySet );
    6679         [ #  # ]:          0 :       if( hidden_ent_set )
    6680                 :            :       {
    6681                 :          0 :         TBOwner *owner = hidden_ent_set->owner();
    6682         [ #  # ]:          0 :         CompositeCurve *comp_curve = CAST_TO(owner, CompositeCurve );
    6683 [ #  # ][ #  # ]:          0 :         if( comp_curve && comp_curve->bridge_manager() )
                 [ #  # ]
    6684                 :            :         {
    6685         [ #  # ]:          0 :           tbs.append( comp_curve );
    6686                 :          0 :           return;
    6687                 :            :         }       
    6688                 :            : 
    6689         [ #  # ]:          0 :         CompositeSurface *comp_surf = CAST_TO(owner, CompositeSurface );
    6690 [ #  # ][ #  # ]:          0 :         if( comp_surf && comp_surf->bridge_manager() )
                 [ #  # ]
    6691                 :            :         {
    6692         [ #  # ]:          0 :           tbs.append( comp_surf );
    6693                 :          0 :           return;
    6694                 :            :         }       
    6695                 :            :       }
    6696                 :            :     }
    6697                 :            : 
    6698         [ #  # ]:          0 :     CompositeCurve *comp_curve = CAST_TO(tb_owner, CompositeCurve);   
    6699                 :            : 
    6700         [ #  # ]:          0 :     if( comp_curve )
    6701                 :            :     {
    6702                 :          0 :       TBOwner *other_owner = comp_curve->owner();
    6703                 :            : 
    6704         [ #  # ]:          0 :       HiddenEntitySet *hidden_ent_set = CAST_TO(other_owner, HiddenEntitySet );
    6705         [ #  # ]:          0 :       if( hidden_ent_set )
    6706                 :            :       {
    6707                 :          0 :         TBOwner *owner = hidden_ent_set->owner();
    6708         [ #  # ]:          0 :         CompositeSurface *comp_surf = CAST_TO(owner, CompositeSurface );
    6709         [ #  # ]:          0 :         if( comp_surf->bridge_manager() )
    6710                 :            :         {
    6711         [ #  # ]:          0 :           tbs.append( comp_surf );
    6712                 :          0 :           return;
    6713                 :            :         }        
    6714                 :            :       }
    6715                 :            :     }
    6716                 :            :   }
    6717                 :            : 
    6718                 :          0 :     return;
    6719 [ +  - ][ +  - ]:       6364 : }
    6720                 :            : 
    6721                 :            : 

Generated by: LCOV version 1.11