Branch data Line data Source code
1 : : //- Class: MergeTool
2 : : //- Description: Location of all Merge and Unmerge functionality
3 : : //- Owner: Steven Jankovich
4 : : //- Created: 27 April 1998
5 : : //- Checked by:
6 : :
7 : : #include <assert.h>
8 : :
9 : : #include "GeometryEntity.hpp"
10 : : #include "MergeTool.hpp"
11 : : #include "MergeToolAssistant.hpp"
12 : : #include "RefEntityFactory.hpp"
13 : : #include "GeometryQueryTool.hpp"
14 : : #include "GeometryQueryEngine.hpp"
15 : : #include "ModelQueryEngine.hpp"
16 : : #include "GeometryModifyTool.hpp"
17 : : #include "SurfaceOverlapTool.hpp"
18 : : #include "GeometryModifyEngine.hpp"
19 : : #include "CGMHistory.hpp"
20 : :
21 : : #include "CubitObserver.hpp"
22 : : #include "CubitUtil.hpp"
23 : : #include "RefEntity.hpp"
24 : : #include "BasicTopologyEntity.hpp"
25 : : #include "GroupingEntity.hpp"
26 : : #include "SenseEntity.hpp"
27 : : #include "GeometryEvent.hpp"
28 : :
29 : : #include "RefVertex.hpp"
30 : : #include "RefEdge.hpp"
31 : : #include "RefFace.hpp"
32 : : #include "RefVolume.hpp"
33 : : #include "RefGroup.hpp"
34 : :
35 : : #include "CoVertex.hpp"
36 : : #include "CoEdge.hpp"
37 : : #include "CoFace.hpp"
38 : :
39 : : #include "Chain.hpp"
40 : : #include "Loop.hpp"
41 : : #include "Shell.hpp"
42 : : #include "Body.hpp"
43 : : #include "BodySM.hpp"
44 : :
45 : : #include "ToolData.hpp"
46 : : #include "TDCompare.hpp"
47 : :
48 : : #include "DLIList.hpp"
49 : :
50 : : #include "Surface.hpp"
51 : : #include "Curve.hpp"
52 : : #include "Point.hpp"
53 : : #include "LoopSM.hpp"
54 : : #include "CoEdgeSM.hpp"
55 : : #include "ShellSM.hpp"
56 : :
57 : : #include "CpuTimer.hpp"
58 : : #include "ProgressTool.hpp"
59 : : #include "AppUtil.hpp"
60 : : #include "CastTo.hpp"
61 : : #include "RTree.hpp"
62 : : #include "AbstractTree.hpp"
63 : : #include "SettingHandler.hpp"
64 : :
65 : : MergeTool* MergeTool::instance_ = NULL;
66 : : CubitBoolean MergeTool::groupResults = CUBIT_FALSE;
67 : : CubitBoolean MergeTool::destroyDeadGeometry = CUBIT_TRUE;
68 : :
69 : : // Constructor
70 : 17057 : MergeTool* MergeTool::instance()
71 : : {
72 [ + + ]: 17057 : if( instance_ == NULL )
73 [ + - ]: 195 : instance_ = new MergeTool;
74 : 17057 : return instance_;
75 : : }
76 : :
77 : 874 : void MergeTool::initialize_settings( )
78 : : {
79 : 874 : }
80 : :
81 [ + - ][ + - ]: 390 : MergeTool::MergeTool()
[ + - ][ + - ]
82 : : {
83 : : //This is private. It can only be accessed through
84 : : //the instance() function above.
85 : :
86 : 195 : unmerged_list_in_use = CUBIT_FALSE;
87 : 195 : displayProgress = false;
88 : 195 : destroyDeadGeometry = true;
89 : : //These shouldn't get deleted, they
90 : : //get deleted when other groups get deleted (reset).
91 : 195 : lastSurfsMerged = NULL;
92 : 195 : lastCurvsMerged = NULL;
93 : 195 : lastVertsMerged = NULL;
94 : 195 : }
95 : :
96 : : // Destructor
97 [ + - ][ + - ]: 62 : MergeTool::~MergeTool()
[ + - ][ + - ]
98 : : {
99 [ + - ][ - + ]: 31 : while( assistant_list_.size() )
100 [ # # ][ # # ]: 0 : delete assistant_list_.pop();
[ # # ]
101 : 31 : instance_ = 0;
102 : 31 : }
103 : :
104 : 0 : void MergeTool::merge_with_auto_imprint(RefFace *surf1, RefFace *surf2)
105 : : {
106 [ # # ][ # # ]: 0 : DLIList<CubitString> ds, cs, ps;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
107 : 0 : RefFace *local_surf1 = surf1;
108 : 0 : RefFace *local_surf2 = surf2;
109 : 0 : bool time_to_stop = false;
110 : 0 : int cntr = 0;
111 : 0 : bool first_time = true;
112 [ # # ][ # # ]: 0 : while(!time_to_stop && local_surf1 &&
[ # # ][ # # ]
[ # # ]
113 [ # # ][ # # ]: 0 : local_surf2 && !local_surf1->is_merged() &&
[ # # ][ # # ]
114 [ # # ]: 0 : !local_surf2->is_merged() )
115 : : {
116 [ # # ]: 0 : int surf1_id = local_surf1->id();
117 [ # # ]: 0 : int surf2_id = local_surf2->id();
118 [ # # ]: 0 : if(first_time)
119 : : {
120 [ # # ]: 0 : Body *b1 = local_surf1->body();
121 [ # # ]: 0 : Body *b2 = local_surf2->body();
122 [ # # ][ # # ]: 0 : if(b1 && b2)
123 : : {
124 [ # # ][ # # ]: 0 : DLIList<Body*> body_list, new_bodies;
[ # # ][ # # ]
125 [ # # ]: 0 : body_list.append(b1);
126 [ # # ]: 0 : body_list.append(b2);
127 [ # # ][ # # ]: 0 : DLIList<RefFace*> faces_to_imprint;
[ # # ]
128 [ # # ]: 0 : faces_to_imprint.append( local_surf1 );
129 [ # # ]: 0 : faces_to_imprint.append( local_surf2 );
130 [ # # ][ # # ]: 0 : DLIList<RefEdge*> dummy_list;
[ # # ]
131 : : CubitStatus imprint_status;
132 [ # # ][ # # ]: 0 : imprint_status = GeometryModifyTool::instance()->tolerant_imprint( faces_to_imprint, dummy_list, new_bodies, true );
133 [ # # ]: 0 : if( CUBIT_FAILURE == imprint_status )
134 : 0 : return;
135 [ # # ][ # # ]: 0 : first_time = false;
136 : : }
137 : : }
138 : : else
139 : : {
140 : : this->imprint_merge_solutions_for_overlapping_surfaces(local_surf1,
141 [ # # ]: 0 : local_surf2, true, ds, cs, ps);
142 : : }
143 [ # # ][ # # ]: 0 : RefFace *new_surf1 = RefEntityFactory::instance()->get_ref_face(surf1_id);
144 [ # # ][ # # ]: 0 : RefFace *new_surf2 = RefEntityFactory::instance()->get_ref_face(surf2_id);
145 [ # # ][ # # ]: 0 : if(new_surf1 && new_surf1->is_merged())
[ # # ][ # # ]
146 : 0 : time_to_stop = true;
147 [ # # ][ # # ]: 0 : else if(new_surf2 && new_surf2->is_merged())
[ # # ][ # # ]
148 : 0 : time_to_stop = true;
149 : : else
150 : : {
151 [ # # ][ # # ]: 0 : if(new_surf1 && new_surf2)
152 : : {
153 [ # # ][ # # ]: 0 : DLIList<RefFace*> current_face_list, out1, out2;
[ # # ][ # # ]
[ # # ]
154 [ # # ][ # # ]: 0 : DLIList<RefEntity*> faces_to_draw;
155 [ # # ]: 0 : current_face_list.append(new_surf1);
156 [ # # ]: 0 : current_face_list.append(new_surf2);
157 : : SurfaceOverlapTool::instance()->find_overlapping_surfaces(current_face_list,
158 : : out1,
159 : : out2,
160 : : faces_to_draw,
161 : : CUBIT_FALSE,
162 [ # # ][ # # ]: 0 : CUBIT_TRUE);
163 [ # # ][ # # ]: 0 : if(out1.size() == 1 && out2.size() == 1 &&
[ # # ][ # # ]
[ # # ][ # # ]
164 [ # # ][ # # ]: 0 : ((out1.get() == new_surf1 && out2.get() == new_surf2) ||
[ # # ][ # # ]
165 [ # # ][ # # ]: 0 : (out1.get() == new_surf2 && out2.get() == new_surf1)))
[ # # ]
166 : : {
167 : 0 : local_surf1 = new_surf1;
168 : 0 : local_surf2 = new_surf2;
169 : : }
170 : : else
171 : : {
172 : 0 : time_to_stop = true;
173 [ # # ]: 0 : }
174 : : }
175 : : else
176 : : {
177 : 0 : time_to_stop = true;
178 : : }
179 : : }
180 : 0 : cntr++;
181 [ # # ]: 0 : if(cntr > 5)
182 : 0 : time_to_stop = true;
183 : 0 : }
184 : : }
185 : :
186 : : //Public Functions:
187 : 0 : CubitBoolean MergeTool::contains_merged_entities( DLIList<RefEntity*> &ref_entities,
188 : : DLIList<RefEntity*> *merged_ref_ents )
189 : : {
190 : : //Loop through the entities and their children to find
191 : : //merged entities. For now, just do it quickly, so
192 : : //if we find a merged entity, return true.
193 : :
194 [ # # ][ # # ]: 0 : DLIList<RefEntity*> all_entities, temp_entities;
[ # # ]
195 : :
196 [ # # ][ # # ]: 0 : if ( ref_entities.size() == 0 )
197 : 0 : return CUBIT_FALSE;
198 : :
199 [ # # ]: 0 : ref_entities.reset();
200 [ # # ][ # # ]: 0 : ref_entities.get()->get_all_child_ref_entities(ref_entities, temp_entities);
201 [ # # ]: 0 : temp_entities += ref_entities;
202 : :
203 [ # # ]: 0 : all_entities.merge_unique(temp_entities);
204 : :
205 [ # # ][ # # ]: 0 : for (int i = all_entities.size(); i > 0; i--) {
206 [ # # ]: 0 : RefEntity *temp_entity = all_entities.get_and_step();
207 [ # # ][ # # ]: 0 : if (entity_merged(CAST_TO(temp_entity, TopologyEntity)))
[ # # ]
208 : : {
209 [ # # ]: 0 : if( NULL == merged_ref_ents )
210 : 0 : return CUBIT_TRUE;
211 : : else
212 [ # # ]: 0 : merged_ref_ents->append( temp_entity );
213 : : }
214 : : }
215 : :
216 [ # # ]: 0 : if( merged_ref_ents )
217 [ # # ][ # # ]: 0 : if( merged_ref_ents->size() )
218 : 0 : return CUBIT_TRUE;
219 : :
220 [ # # ]: 0 : return CUBIT_FALSE;
221 : : }
222 : :
223 : 403 : CubitBoolean MergeTool::contains_merged_children( Body *body,
224 : : DLIList<RefEntity*> &merged_children)
225 : : {
226 : :
227 : 403 : RefEntity *ref_ent = NULL;
228 [ + - ]: 403 : DLIList<RefEntity*> ref_ent_list;
229 [ + - ]: 403 : body->get_all_child_ref_entities( ref_ent_list );
230 : : int i;
231 [ + - ][ + + ]: 8449 : for( i=ref_ent_list.size(); i--;)
232 : : {
233 [ + - ]: 8046 : ref_ent = ref_ent_list.get_and_step();
234 [ - + ][ + - ]: 8046 : if(entity_merged(CAST_TO(ref_ent, TopologyEntity)))
[ - + ]
235 [ # # ]: 0 : merged_children.append( ref_ent );
236 : : }
237 : :
238 [ + - ][ - + ]: 403 : if( merged_children.size() )
239 : 0 : return CUBIT_TRUE;
240 : : else
241 [ + - ]: 403 : return CUBIT_FALSE;
242 : : }
243 : :
244 : :
245 : 0 : CubitBoolean MergeTool::contains_merged_entities( DLIList<Body*> &bodies )
246 : : {
247 : : //Loop through the bodies and their entities to find
248 : : //merged entities. For now, just do it quickly, so
249 : : //if we find a merged entity, return true.
250 [ # # ]: 0 : DLIList<RefEntity*> ref_entities;
251 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT(bodies, ref_entities);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
252 [ # # ][ # # ]: 0 : return contains_merged_entities(ref_entities);
253 : : }
254 : :
255 : 25054 : CubitBoolean MergeTool::entity_merged( TopologyEntity *entity )
256 : : {
257 [ + + ]: 25054 : if (entity->bridge_manager()->number_of_bridges() > 1)
258 : 756 : return CUBIT_TRUE;
259 : : else
260 : 24298 : return CUBIT_FALSE;
261 : : }
262 : :
263 : 0 : CubitStatus MergeTool::merge_all_bodies()
264 : : {
265 [ # # ][ # # ]: 0 : int number_volumes = GeometryQueryTool::instance()->num_ref_volumes();
266 : :
267 [ # # ]: 0 : DLIList<RefEntity*> free_ref_ents;
268 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->get_free_ref_entities( free_ref_ents );
269 : :
270 [ # # ][ # # ]: 0 : if( number_volumes == 1 && free_ref_ents.size() == 0 )
[ # # ][ # # ]
271 : : {
272 [ # # ][ # # ]: 0 : PRINT_WARNING("Need more than 1 volume to merge anything\n");
[ # # ][ # # ]
273 : 0 : return CUBIT_FAILURE;
274 : : }
275 : :
276 [ # # ][ # # ]: 0 : PRINT_INFO( "\n...Merging all features in the model\n" );
[ # # ][ # # ]
277 : :
278 [ # # ][ # # ]: 0 : if( merge_all_reffaces() == CUBIT_FAILURE )
279 : : {
280 : 0 : return CUBIT_FAILURE;
281 : : }
282 : :
283 [ # # ][ # # ]: 0 : if( merge_all_refedges() == CUBIT_FAILURE )
284 : : {
285 : 0 : return CUBIT_FAILURE;
286 : : }
287 : :
288 [ # # ][ # # ]: 0 : if( merge_all_refvertices() == CUBIT_FAILURE )
289 : : {
290 : 0 : return CUBIT_FAILURE;
291 : : }
292 : :
293 [ # # ]: 0 : return CUBIT_SUCCESS;
294 : : }
295 : :
296 : 22 : CubitStatus MergeTool::merge_bodies( DLIList<Body*>& body_list )
297 : : {
298 [ + - ][ + - ]: 44 : DLIList<TopologyEntity*> query_input(body_list.size()), query_output;
[ + - ][ + - ]
299 [ + - ][ + - ]: 66 : CAST_LIST_TO_PARENT(body_list, query_input);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + + ]
300 [ + - ]: 22 : ModelQueryEngine *const mqe = ModelQueryEngine::instance();
301 : :
302 : : // Get the RefFaces
303 [ + - ]: 22 : query_output.clean_out();
304 [ + - ][ + - ]: 22 : mqe->query_model( query_input, DagType::ref_face_type(), query_output );
305 [ + - ][ + - ]: 44 : DLIList<RefFace*> refface_list(query_output.size());
[ + - ]
306 [ + - ][ + - ]: 286 : CAST_LIST(query_output, refface_list, RefFace);
[ + - ][ - + ]
[ + - ][ + - ]
[ + + ]
307 : :
308 : : // Merge the RefFaces
309 [ + - ][ - + ]: 22 : if( merge_reffaces( refface_list ) == CUBIT_FAILURE )
310 : : {
311 [ # # ][ # # ]: 0 : PRINT_ERROR( "Surface merging failed\n" );
[ # # ][ # # ]
312 : 0 : return CUBIT_FAILURE;
313 : : }
314 : :
315 : : // Get the RefEdges
316 [ + - ]: 22 : query_output.clean_out();
317 [ + - ][ + - ]: 22 : mqe->query_model( query_input, DagType::ref_edge_type(), query_output );
318 [ + - ][ + - ]: 44 : DLIList<RefEdge*> refedge_list(query_output.size());
[ + - ]
319 [ + - ][ + - ]: 462 : CAST_LIST(query_output, refedge_list, RefEdge);
[ + - ][ - + ]
[ + - ][ + - ]
[ + + ]
320 : :
321 : : // Merge the RefEdges
322 [ + - ][ - + ]: 22 : if( merge_refedges( refedge_list ) == CUBIT_FAILURE )
323 : : {
324 [ # # ][ # # ]: 0 : PRINT_ERROR( "Curve merging failed\n" );
[ # # ][ # # ]
325 : 0 : return CUBIT_FAILURE;
326 : : }
327 : :
328 : : // Get the RefVertices
329 [ + - ]: 22 : query_output.clean_out();
330 [ + - ][ + - ]: 22 : mqe->query_model( query_input, DagType::ref_vertex_type(), query_output );
331 [ + - ][ + - ]: 44 : DLIList<RefVertex*> refvertex_list(query_output.size());
[ + - ]
332 [ + - ][ + - ]: 286 : CAST_LIST(query_output, refvertex_list, RefVertex);
[ + - ][ - + ]
[ + - ][ + - ]
[ + + ]
333 : :
334 : : // Merge the RefVertices
335 [ + - ][ - + ]: 22 : if( merge_refvertices( refvertex_list ) == CUBIT_FAILURE )
336 : : {
337 [ # # ][ # # ]: 0 : PRINT_ERROR( "Vertex merging failed\n" );
[ # # ][ # # ]
338 : 0 : return CUBIT_FAILURE;
339 : : }
340 : :
341 [ + - ]: 44 : return CUBIT_SUCCESS;
342 : : }
343 : :
344 : 31 : CubitStatus MergeTool::merge_volumes( DLIList<RefVolume*>& vol_list,
345 : : CubitBoolean print_info )
346 : : {
347 : : int i;
348 [ + - ]: 31 : vol_list.reset();
349 : :
350 : : // Get the RefFaces
351 [ + - ]: 31 : DLIList<RefFace*> refface_list;
352 [ + - ][ + + ]: 124 : for( i = vol_list.size(); i > 0; i-- )
353 [ + - ][ + - ]: 93 : vol_list.get_and_step()->ref_faces( refface_list );
354 : :
355 : : // Merge the RefFaces
356 [ + - ][ - + ]: 31 : if( merge_reffaces( refface_list, print_info ) == CUBIT_FAILURE )
357 : : {
358 [ # # ][ # # ]: 0 : PRINT_ERROR( "Surface merging failed\n" );
[ # # ][ # # ]
359 : 0 : return CUBIT_FAILURE;
360 : : }
361 : :
362 : : // Get the RefEdges
363 [ + - ][ + - ]: 62 : DLIList<RefEdge*> refedge_list;
364 [ + - ][ + + ]: 124 : for( i = vol_list.size(); i > 0; i-- )
365 [ + - ][ + - ]: 93 : vol_list.get_and_step()->ref_edges( refedge_list );
366 : :
367 : : // Merge the RefEdges
368 [ + - ][ - + ]: 31 : if( merge_refedges( refedge_list, CUBIT_TRUE, print_info ) == CUBIT_FAILURE )
369 : : {
370 [ # # ][ # # ]: 0 : PRINT_ERROR( "Curve merging failed\n" );
[ # # ][ # # ]
371 : 0 : return CUBIT_FAILURE;
372 : : }
373 : :
374 : : // Get the RefVertices
375 [ + - ][ + - ]: 62 : DLIList<RefVertex*> refvertex_list;
376 [ + - ][ + + ]: 124 : for( i = vol_list.size(); i > 0; i-- )
377 [ + - ][ + - ]: 93 : vol_list.get_and_step()->ref_vertices( refvertex_list );
378 : :
379 : : // Merge the RefVertices
380 [ + - ][ - + ]: 31 : if( merge_refvertices( refvertex_list, print_info ) == CUBIT_FAILURE )
381 : : {
382 [ # # ][ # # ]: 0 : PRINT_ERROR( "Vertex merging failed\n" );
[ # # ][ # # ]
383 : 0 : return CUBIT_FAILURE;
384 : : }
385 : :
386 [ + - ]: 62 : return CUBIT_SUCCESS;
387 : : }
388 : :
389 : 0 : CubitStatus MergeTool::merge_all_reffaces()
390 : : {
391 : : // if( !displayProgress )
392 [ # # ][ # # ]: 0 : PRINT_INFO( "\n...Merging all Surfaces in the model\n" );
[ # # ][ # # ]
393 : :
394 : : // Get the list of all the RefFaces in the model
395 [ # # ]: 0 : DLIList<RefFace*> refface_list;
396 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->ref_faces(refface_list);
397 : :
398 : : // Merge the RefFaces in this list
399 [ # # ][ # # ]: 0 : if ( DEBUG_FLAG(139) )
[ # # ]
400 : : {
401 [ # # ]: 0 : test_r_tree(refface_list);
402 : : // test_r_star_tree(refface_list);
403 [ # # ]: 0 : test_no_tree(refface_list);
404 : : }
405 [ # # ][ # # ]: 0 : if( merge_reffaces( refface_list ) == CUBIT_FAILURE )
406 : : {
407 [ # # ][ # # ]: 0 : PRINT_ERROR( "Surface merging failed\n" );
[ # # ][ # # ]
408 : 0 : return CUBIT_FAILURE;
409 : : }
410 : :
411 [ # # ]: 0 : return CUBIT_SUCCESS;
412 : : }
413 : :
414 : 32 : CubitStatus MergeTool::merge_reffaces_old( DLIList<RefFace*>& refface_list,
415 : : CubitBoolean print_info)
416 : : {
417 : : // The basic algorithm is to step through the input list,
418 : : // compare every entity with every other entity, and
419 : : // merge the entities that are spatially equivalent.
420 : : // In the merge, the entity with the lowest ID is retained.
421 : : // This is complicated by the fact that once an entity has
422 : : // been merged out, we can no longer access that pointer
423 : : // since it is invalid. So...we need to remove it from the
424 : : // list, but still keep track of where we are in the list.
425 : : // If the entity that is deleted is before the retained item
426 : : // in the list, then we do not want to step or we will....
427 : :
428 [ + - ]: 32 : CpuTimer timer;
429 : 32 : int merge_count = 0;
430 : :
431 [ + - ][ + - ]: 32 : DLIList<RefFace*> refface_array( refface_list.size() );
432 [ + - ]: 32 : refface_list.reset();
433 : :
434 : : // Remove entities that should not be automatically merged
435 : 32 : int i = 0;
436 [ + - ][ + + ]: 416 : for( i = refface_list.size(); i > 0; i-- )
437 : : {
438 [ + - ]: 384 : RefFace *curr_face = refface_list.get_and_step();
439 [ + - ][ + - ]: 384 : if( curr_face->is_mergeable() )
440 [ + - ]: 384 : refface_array.append( curr_face );
441 : : }
442 : :
443 : 32 : ProgressTool* progress = 0;
444 [ - + ]: 32 : if( displayProgress )
445 : : {
446 : : char info[64];
447 [ # # ]: 0 : sprintf(info, "Comparing %d Surfaces for Merge", refface_array.size() );
448 [ # # ][ # # ]: 0 : progress = AppUtil::instance()->progress_tool();
449 [ # # ]: 0 : if (progress)
450 : : {
451 : : progress->start( 0, refface_array.size(), "Comparing Surfaces:",
452 [ # # ][ # # ]: 0 : info, CUBIT_TRUE, CUBIT_TRUE );
453 : : }
454 : : }
455 : :
456 : : // Now find overlapping RefFaces and merge them.
457 : : // Make sure that the operation is not performed on
458 : : // RefFaces that are deactivated.
459 : 32 : int j = 0;
460 : 32 : RefFace* refface_ptr = NULL;
461 : 32 : RefFace* compare_refface_ptr = NULL;
462 [ + - ]: 32 : int array_size = refface_array.size();
463 [ + - ][ + - ]: 64 : DLIList<RefFace*> faces_merged;
464 : :
465 [ + + ][ + - ]: 416 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ + - ][ + - ]
[ + + ]
466 : : {
467 [ - + ]: 384 : if( progress )
468 [ # # ]: 0 : progress->step();
469 : :
470 [ + - ]: 384 : refface_ptr = refface_array[i];
471 [ + + ]: 384 : if( refface_ptr == NULL )
472 : 32 : continue;
473 : :
474 : : // There is no need to compare if the first RefFace is
475 : : // deactivated.
476 [ + - ][ - + ]: 352 : if( refface_ptr->deactivated() == CUBIT_TRUE )
477 : 0 : continue ;
478 : :
479 : 352 : j = i+1;
480 [ + + ][ + - ]: 2389 : for( j = i+1; (j < array_size) && !AppUtil::instance()->interrupt(); j++ )
[ + - ][ + - ]
[ + + ]
481 : : {
482 [ + - ]: 2037 : compare_refface_ptr = refface_array[j];
483 [ + + ]: 2037 : if( compare_refface_ptr == NULL )
484 : 2005 : continue;
485 : :
486 : : // Make sure we are not comparing the same entity
487 : : // and that they are not deactivated.
488 [ + - ][ - + ]: 3772 : if( ( refface_ptr == compare_refface_ptr ) ||
[ - + ]
489 [ + - ]: 1886 : ( compare_refface_ptr->deactivated() == CUBIT_TRUE ) )
490 : 0 : continue;
491 : :
492 : : // IMPORTANT: this compare is for merging, so we set the
493 : : // last parameter to CUBIT_TRUE so that the
494 : : // compare sets the TDCompare data which will
495 : : // be used in the RefEntity compare and merge.
496 : : // By Jihong
497 : :
498 [ + - ]: 1886 : double geom_factor = GeometryQueryTool::get_geometry_factor();
499 : : CubitBoolean status =
500 : : refface_ptr->about_spatially_equal( compare_refface_ptr,
501 : : geom_factor,
502 : : CUBIT_TRUE,
503 [ + - ][ + - ]: 1886 : GeometryQueryTool::instance()->get_merge_test_bbox(),
504 [ + - ][ + - ]: 3772 : GeometryQueryTool::instance()->get_merge_test_internal() );
[ + - ]
505 [ + + ]: 1886 : if( status == CUBIT_FALSE )
506 : 1854 : continue;
507 : :
508 : : //don't merge 2 surfaces of solid volumes if they have
509 : : //opposite sense..indicative that they overlap
510 : : #if 0
511 : : if( refface_ptr->compare_alignment(compare_refface_ptr) == CUBIT_FORWARD )
512 : : {
513 : : //if they are both on solid volumes...bail
514 : : if( refface_ptr->body()->is_sheet_body() == CUBIT_FALSE &&
515 : : compare_refface_ptr->body()->is_sheet_body() == CUBIT_FALSE )
516 : : continue;
517 : : }
518 : : #endif
519 : : // If we are in this block, we want to merge the
520 : : // two entities. If they do not merge, there was
521 : : // an error somewhere.
522 : :
523 : : //First test to see if all the children of these
524 : : // reffaces are mergeable
525 [ + - ][ - + ]: 32 : if( !compare_refface_ptr->children_mergeable() )
526 : : {
527 [ # # ][ # # ]: 0 : PRINT_WARNING( "Cannot merge surfaces %d and %d\n"
[ # # ][ # # ]
[ # # ]
528 : : " Make sure all merge flags are on.\n",
529 [ # # ]: 0 : refface_ptr->id(), compare_refface_ptr->id() );
530 : 0 : continue;
531 : : }
532 : :
533 : : //Now let us test to see if we are merging two faces that
534 : : //belong to the same volume.
535 [ + - ][ + - ]: 64 : DLIList<RefVolume*> ref_vols_1, ref_vols_2;
[ + - ]
[ + - - ]
536 [ + - ]: 32 : refface_ptr->ref_volumes( ref_vols_1 );
537 [ + - ]: 32 : compare_refface_ptr->ref_volumes( ref_vols_2 );
538 [ + - ]: 32 : ref_vols_2.intersect( ref_vols_1 );
539 [ + - ][ - + ]: 32 : if( ref_vols_2.size() > 0 )
540 : : {
541 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Tolerance problems, trying to merge "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
542 : : "surfaces\non the same volume.\n"
543 : : " %s (surface %d) and %s (surface %d) on\n"
544 : : " %s (volume %d)\n",
545 : : refface_ptr->entity_name().c_str(),
546 : : refface_ptr->id(),
547 : : compare_refface_ptr->entity_name().c_str(),
548 : : compare_refface_ptr->id(),
549 : : ref_vols_2.get()->entity_name().c_str(),
550 [ # # ]: 0 : ref_vols_2.get()->id() );
551 [ # # ][ # # ]: 0 : if (print_info) { PRINT_DEBUG_19( "Try changing the merge tolerance.\n" ); }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
552 : 0 : continue;
553 : : }
554 : :
555 : : /*
556 : : //don't merge 2 surfaces of solid volumes if they have
557 : : //opposite sense..indicative that they overlap
558 : : if( refface_ptr->compare_alignment(compare_refface_ptr) == CUBIT_FORWARD )
559 : : {
560 : : continue;
561 : : } */
562 : :
563 : : // Always retain the entity with the lowest id.
564 : 32 : int nullify = j;
565 [ + - ][ + - ]: 32 : if( refface_ptr->id() > compare_refface_ptr->id() )
[ - + ]
566 : : {
567 [ # # ]: 0 : std::swap(refface_ptr, compare_refface_ptr);
568 : 0 : nullify = i;
569 : : }
570 [ - + ]: 32 : if (groupResults )
571 : : {
572 [ # # ]: 0 : faces_merged.append(refface_ptr);
573 : : }
574 : :
575 : : // Now check if merge is okay with all assistants.
576 : 32 : CubitBoolean assistant_says_no = CUBIT_FALSE;
577 [ + - ][ - + ]: 32 : for( int k = assistant_list_.size(); k > 0; k-- )
578 : : {
579 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
580 [ # # ]: 0 : ->can_merge( refface_ptr, compare_refface_ptr ) )
581 : : {
582 : 0 : assistant_says_no = CUBIT_TRUE;
583 : 0 : break;
584 : : }
585 : : }
586 [ - + ]: 32 : if( assistant_says_no )
587 : 0 : continue;
588 : :
589 : : // Need to retain these so that the pointers are not
590 : : // accessed after a merge operation when the 'deleted'
591 : : // pointer may be invalid.
592 [ + - ]: 32 : int retained_id = refface_ptr->id();
593 [ + - ]: 32 : int deleted_id = compare_refface_ptr->id();
594 : :
595 [ + - ][ + - ]: 32 : PRINT_DEBUG_19( "Consolidating RefFace %d and "
[ - + ][ # # ]
[ # # ][ # # ]
596 [ # # ]: 0 : "%d...\n", retained_id, deleted_id );
597 [ + - ][ + - ]: 32 : if( merge_BTE( refface_ptr, compare_refface_ptr ) )
598 : : {
599 : 32 : merge_count++;
600 [ + + ][ + - ]: 32 : if (print_info && !progress)
601 [ + - ][ + - ]: 44 : PRINT_INFO( "Surface %d and %d consolidated\n",
[ + - ]
602 [ + - ]: 22 : retained_id, deleted_id );
603 : :
604 : : // The 'deleted' RefFace is now gone. It is an
605 : : // error to access that pointer, so we need to
606 : : // get it out of the list.
607 [ + - ]: 32 : refface_array[nullify] = NULL;
608 : : }
609 : : else
610 : : {
611 [ # # ][ # # ]: 0 : PRINT_ERROR( "Failed to merge Surface %d and %d\n",
[ # # ]
612 [ # # ]: 0 : retained_id, deleted_id);
613 [ # # ][ # # ]: 0 : PRINT_INFO("Could be sliver geometry in the vecinity\n");
[ # # ][ # # ]
614 : : }
615 : :
616 [ - + ]: 32 : if (nullify == i)
617 [ + - ]: 32 : break;
[ + - - ]
618 : 32 : }
619 : : }
620 : :
621 : : // Remove the crud that accumulated during the merge
622 : : // operations, from the geometry database.
623 : :
624 [ + - ]: 32 : complete_merge();
625 [ - + ]: 32 : if (progress)
626 [ # # ]: 0 : progress->end();
627 [ + - ][ + - ]: 32 : PRINT_DEBUG_3( "Merge Reffaces time: %f secs\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
628 [ # # ]: 0 : timer.cpu_secs() );
629 : :
630 [ + - ][ + - ]: 32 : PRINT_DEBUG_19("Cleaning out TDCompare data from RefFaces...\n");
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
631 : :
632 [ - + ][ # # ]: 32 : if ( groupResults && faces_merged.size() )
[ # # ][ - + ]
633 : : {
634 [ # # ]: 0 : DLIList<RefEntity*> refentity_list;
635 : : RefFace *tmp_face;
636 [ # # ][ # # ]: 0 : for (int iii = faces_merged.size(); iii > 0; iii-- )
637 : : {
638 [ # # ]: 0 : tmp_face = faces_merged.get_and_step();
639 [ # # ][ # # ]: 0 : if ( !tmp_face->deactivated() )
640 [ # # ][ # # ]: 0 : refentity_list.append(tmp_face);
641 : : }
642 [ # # ][ # # ]: 0 : RefGroup *new_group = RefEntityFactory::instance()->construct_RefGroup("gr_surfs_merged");
643 [ # # ]: 0 : new_group->add_ref_entity( refentity_list );
644 [ # # ][ # # ]: 0 : if (print_info) PRINT_INFO("Created new group %s (Group %d)\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
645 : : " Group contains surfaces that were merged during\n"
646 : : " current merge operation\n",
647 : : new_group->entity_name().c_str(),
648 [ # # ]: 0 : new_group->id());
649 [ # # ]: 0 : lastSurfsMerged = new_group;
650 : : }
651 : : //since surface mergeing has occured and we either don't want the
652 : : //group or didn't store it, set the lastsurfs to null.
653 : : else
654 : 32 : lastSurfsMerged = NULL;
655 : :
656 [ + - ]: 32 : if( destroyDeadGeometry )
657 [ + - ][ + - ]: 32 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
658 : :
659 [ + - ][ + - ]: 32 : PRINT_DEBUG_3( "cleanout time: %f secs\n", timer.cpu_secs() );
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
660 [ + + ]: 32 : if (print_info)
661 : : {
662 [ + - ][ + - ]: 22 : PRINT_INFO( "Consolidated %d pair", merge_count);
[ + - ][ + - ]
663 [ - + ]: 22 : if(merge_count > 1)
664 [ # # ][ # # ]: 0 : PRINT_INFO("s");
[ # # ][ # # ]
665 [ + - ][ + - ]: 22 : PRINT_INFO( " of surfaces\n");
[ + - ][ + - ]
666 : : }
667 : :
668 [ + - ][ + - ]: 32 : if( AppUtil::instance()->interrupt() )
[ - + ]
669 : : {
670 [ # # ][ # # ]: 0 : PRINT_WARNING("Surface merging aborted.\n");
[ # # ][ # # ]
671 : 0 : return CUBIT_FAILURE;
672 : : }
673 : :
674 [ + - ]: 64 : return CUBIT_SUCCESS;
675 : : }
676 : :
677 : 53 : CubitStatus MergeTool::merge_reffaces( DLIList<RefFace*>& refface_list,
678 : : CubitBoolean print_info)
679 : : {
680 [ + - ][ + + ]: 53 : if (refface_list.size() < 20)
681 : : {
682 [ + - ][ - + ]: 32 : if ( merge_reffaces_old(refface_list, print_info) == CUBIT_FAILURE )
683 : 0 : return CUBIT_FAILURE;
684 : : else
685 : 32 : return CUBIT_SUCCESS;
686 : : }
687 : :
688 : : // The basic algorithm is to step through the input list,
689 : : // compare every entity with every entity within range of
690 : : // its bounding box and merge the spatially equivellant entities.
691 : : // An R-Tree is used to efficiently find the entities within range.
692 : : // In the merge, the entity with the lowest ID is retained.
693 : : // This is complicated by the fact that once an entity has
694 : : // been merged out, we can no longer access that pointer
695 : : // since it is invalid. So...we need to remove it from the
696 : : // tree, but still keep track of where we are in the list.
697 [ + - ]: 21 : double geom_factor = GeometryQueryTool::get_geometry_factor();
698 [ + - ]: 21 : RTree<RefFace*> a_tree(GEOMETRY_RESABS*geom_factor);
699 : : // AbstractTree <RefFace*> *a_tree = new RTree<RefFace*> (GEOMETRY_RESABS*geom_factor);
700 [ + - ]: 21 : CpuTimer timer;
701 : 21 : int merge_count = 0;
702 : :
703 [ + - ][ + - ]: 42 : DLIList<RefFace*> refface_array( refface_list.size() );
[ + - ]
704 [ + - ]: 21 : refface_list.reset();
705 : :
706 : : // Remove entities that should not be automatically merged
707 : 21 : int i = 0;
708 [ + - ]: 21 : int loop_size = refface_list.size();
709 [ + - ]: 21 : CpuTimer time_to_build;
710 [ + + ]: 525 : for( i = 0; i < loop_size; i++ )
711 : : {
712 [ + - ]: 504 : RefFace *curr_face = refface_list.get_and_step();
713 [ + - ][ + - ]: 504 : if( curr_face->is_mergeable() )
714 : : {
715 [ + - ]: 504 : refface_array.append( curr_face );
716 [ + - ]: 504 : a_tree.add(curr_face);
717 : : }
718 : : }
719 [ + - ][ + - ]: 21 : PRINT_DEBUG_3( "Time to build r_tree %f secs, with %d entries\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
720 [ # # ]: 0 : time_to_build.cpu_secs(), refface_array.size() );
721 : :
722 : : //initialize the marked flag for fast nulification...
723 [ + - ]: 21 : int array_size = refface_array.size();
724 [ + + ]: 525 : for ( i = 0; i < array_size; i++)
725 [ + - ][ + - ]: 504 : refface_array[i]->marked(i);
726 : :
727 : 21 : ProgressTool* progress = 0;
728 [ - + ]: 21 : if( displayProgress )
729 : : {
730 : : char info[64];
731 [ # # ]: 0 : sprintf(info, "Comparing %d Surfaces for Merge", refface_array.size() );
732 [ # # ][ # # ]: 0 : progress = AppUtil::instance()->progress_tool();
733 [ # # ]: 0 : if (progress)
734 : : {
735 : : progress->start( 0, refface_array.size(), "Comparing Surfaces:",
736 [ # # ][ # # ]: 0 : info, CUBIT_TRUE, CUBIT_TRUE );
737 : : }
738 : : }
739 : :
740 : : // Now find overlapping RefFaces and merge them.
741 : : // Make sure that the operation is not performed on
742 : : // RefFaces that are deactivated.
743 : 21 : int j = 0;
744 : 21 : RefFace* refface_ptr = NULL;
745 : 21 : RefFace* compare_refface_ptr = NULL;
746 [ + - ][ + - ]: 42 : DLIList<RefFace*> faces_merged, faces_in_range;
[ + - ][ + - ]
747 [ + - ][ + - ]: 42 : CubitBox temp_box;
748 [ + - ][ + - ]: 42 : std::map<RefFace*, RefFace*> failed_merges;
749 [ + - ]: 21 : std::map<RefFace*, RefFace*>::iterator map_iter;
750 : :
751 [ + + ][ + - ]: 525 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ + - ][ + - ]
[ + + ]
752 : : {
753 [ - + ][ # # ]: 504 : if( progress ) progress->step();
754 : :
755 [ + - ]: 504 : refface_ptr = refface_array[i];
756 [ + + ]: 504 : if( refface_ptr == NULL )
757 : 82 : continue;
758 : :
759 : : // There is no need to compare if the first RefFace is
760 : : // deactivated.
761 [ + - ][ - + ]: 422 : if( refface_ptr->deactivated() == CUBIT_TRUE )
762 : 0 : continue ;
763 : :
764 : : //Now from the atree, get the surfaces that are close.
765 [ + - ][ + - ]: 422 : temp_box = refface_ptr->bounding_box();
[ + - ]
766 [ + - ]: 422 : faces_in_range.clean_out();
767 [ + - ]: 422 : a_tree.find(temp_box, faces_in_range);
768 : :
769 [ + - ][ + + ]: 3970 : for( j = 0; (j < faces_in_range.size()) && !AppUtil::instance()->interrupt(); j++ )
[ + - ][ + - ]
[ + - ][ + + ]
770 : : {
771 [ + - ]: 3548 : compare_refface_ptr = faces_in_range.get_and_step();
772 [ - + ]: 3548 : if( compare_refface_ptr == NULL )
773 : 3466 : continue;
774 : :
775 : : // Make sure we are not comparing the same entity
776 : : // and that they are not deactivated.
777 [ + + ][ - + ]: 6674 : if( ( refface_ptr == compare_refface_ptr ) ||
[ + + ]
778 [ + - ]: 3126 : ( compare_refface_ptr->deactivated() == CUBIT_TRUE ) )
779 : 422 : continue;
780 : :
781 [ + - ]: 3126 : map_iter = failed_merges.find( refface_ptr );
782 [ + - ][ + - ]: 3126 : if( map_iter != failed_merges.end() )
[ - + ]
783 [ # # ][ # # ]: 0 : if( map_iter->second == compare_refface_ptr )
784 : 0 : continue;
785 : :
786 : : // IMPORTANT: this compare is for merging, so we set the
787 : : // last parameter to CUBIT_TRUE so that the
788 : : // compare sets the TDCompare data which will
789 : : // be used in the RefEntity compare and merge.
790 : : // By Jihong
791 : :
792 [ + - ]: 3126 : geom_factor = GeometryQueryTool::get_geometry_factor();
793 : : CubitBoolean status =
794 : : refface_ptr->about_spatially_equal( compare_refface_ptr,
795 : : geom_factor,
796 : : CUBIT_TRUE,
797 [ + - ][ + - ]: 3126 : GeometryQueryTool::instance()->get_merge_test_bbox(),
798 [ + - ][ + - ]: 6252 : GeometryQueryTool::instance()->get_merge_test_internal() );
[ + - ]
799 [ + + ]: 3126 : if( status == CUBIT_FALSE )
800 : 3044 : continue;
801 : :
802 : : //don't merge 2 surfaces of solid volumes if they have
803 : : //opposite sense..indicative that they overlap
804 : : #if 0
805 : : if( refface_ptr->compare_alignment(compare_refface_ptr) == CUBIT_FORWARD )
806 : : {
807 : : //if they are both on solid volumes...bail
808 : : if( refface_ptr->body()->is_sheet_body() == CUBIT_FALSE &&
809 : : compare_refface_ptr->body()->is_sheet_body() == CUBIT_FALSE )
810 : : continue;
811 : : }
812 : : #endif
813 : : // If we are in this block, we want to merge the
814 : : // two entities. If they do not merge, there was
815 : : // an error somewhere.
816 : :
817 : : //First test to see if all the children of these
818 : : // reffaces are mergeable
819 [ + - ][ - + ]: 82 : if( !compare_refface_ptr->children_mergeable() )
820 : : {
821 [ # # ][ # # ]: 0 : PRINT_WARNING( "Cannot merge surfaces %d and %d\n"
[ # # ][ # # ]
[ # # ]
822 : : " Make sure all merge flags are on.\n",
823 [ # # ]: 0 : refface_ptr->id(), compare_refface_ptr->id() );
824 : 0 : continue;
825 : : }
826 : :
827 : : //Now let us test to see if we are merging two faces that
828 : : //belong to the same volume.
829 [ + - ][ + - ]: 164 : DLIList<RefVolume*> ref_vols_1, ref_vols_2;
[ + - ]
[ + - - ]
830 [ + - ]: 82 : refface_ptr->ref_volumes( ref_vols_1 );
831 [ + - ]: 82 : compare_refface_ptr->ref_volumes( ref_vols_2 );
832 [ + - ]: 82 : ref_vols_2.intersect( ref_vols_1 );
833 [ + - ][ - + ]: 82 : if( ref_vols_2.size() > 0 )
834 : : {
835 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Tolerance problems, trying to merge "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
836 : : "surfaces\non the same volume.\n"
837 : : " %s (surface %d) and %s (surface %d) on\n"
838 : : " %s (volume %d)\n",
839 : : refface_ptr->entity_name().c_str(),
840 : : refface_ptr->id(),
841 : : compare_refface_ptr->entity_name().c_str(),
842 : : compare_refface_ptr->id(),
843 : : ref_vols_2.get()->entity_name().c_str(),
844 [ # # ]: 0 : ref_vols_2.get()->id() );
845 [ # # ][ # # ]: 0 : if (print_info) { PRINT_DEBUG_19( "Try changing the merge tolerance.\n" ); }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
846 : 0 : continue;
847 : : }
848 : :
849 : : // Always retain the entity with the lowest id.
850 [ + - ]: 82 : int nullify = compare_refface_ptr->marked();
851 [ + - ][ + - ]: 82 : if( refface_ptr->id() > compare_refface_ptr->id() )
[ - + ]
852 : : {
853 [ # # ]: 0 : std::swap(refface_ptr, compare_refface_ptr);
854 : 0 : nullify = i;
855 : : }
856 [ - + ]: 82 : if (groupResults )
857 : : {
858 [ # # ]: 0 : faces_merged.append(refface_ptr);
859 : : }
860 : :
861 : : // Now check if merge is okay with all assistants.
862 : 82 : CubitBoolean assistant_says_no = CUBIT_FALSE;
863 [ + - ][ - + ]: 82 : for( int k = assistant_list_.size(); k > 0; k-- )
864 : : {
865 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
866 [ # # ]: 0 : ->can_merge( refface_ptr, compare_refface_ptr ) )
867 : : {
868 : 0 : assistant_says_no = CUBIT_TRUE;
869 : 0 : break;
870 : : }
871 : : }
872 [ - + ]: 82 : if( assistant_says_no )
873 : 0 : continue;
874 : :
875 : : // Need to retain these so that the pointers are not
876 : : // accessed after a merge operation when the 'deleted'
877 : : // pointer may be invalid.
878 [ + - ]: 82 : int retained_id = refface_ptr->id();
879 [ + - ]: 82 : int deleted_id = compare_refface_ptr->id();
880 : :
881 [ + - ][ + - ]: 82 : PRINT_DEBUG_19( "Consolidating RefFace %d and "
[ - + ][ # # ]
[ # # ][ # # ]
882 [ # # ]: 0 : "%d...\n", retained_id, deleted_id );
883 : :
884 [ + - ]: 82 : a_tree.remove(compare_refface_ptr);
885 : :
886 [ + - ][ + - ]: 82 : if( merge_BTE( refface_ptr, compare_refface_ptr ) )
887 : : {
888 : 82 : merge_count++;
889 [ - + ][ # # ]: 82 : if (print_info && !progress)
890 [ # # ][ # # ]: 0 : PRINT_INFO( "Surface %d and %d consolidated\n",
[ # # ]
891 [ # # ]: 0 : retained_id, deleted_id );
892 : :
893 : : // The 'deleted' RefFace is now gone. It is an
894 : : // error to access that pointer, so we need to
895 : : // get it out of the list.
896 [ + - ]: 82 : refface_array[nullify] = NULL;
897 : : }
898 : : else
899 : : {
900 [ # # ][ # # ]: 0 : failed_merges.insert( std::make_pair(compare_refface_ptr, refface_ptr) );
[ # # ]
901 : :
902 [ # # ][ # # ]: 0 : PRINT_ERROR( "Failed to merge Surface %d and %d\n",
[ # # ]
903 [ # # ]: 0 : retained_id, deleted_id);
904 [ # # ][ # # ]: 0 : PRINT_INFO("Could be sliver geometry in the vicinity\n");
[ # # ][ # # ]
905 [ # # ]: 0 : a_tree.add(compare_refface_ptr);
906 : : }
907 : :
908 [ - + ]: 82 : if (nullify == i)
909 [ + - ]: 82 : break;
[ + - - ]
910 : :
911 : 82 : }
912 : : }
913 : : //clean the marks.
914 [ + + ]: 525 : for( i = 0; i < array_size; i++ )
915 : : {
916 [ + - ][ + + ]: 504 : if ( refface_array[i] != NULL )
917 [ + - ][ + - ]: 422 : refface_array[i]->marked(0);
918 : : }
919 [ + - ]: 21 : complete_merge();
920 [ - + ]: 21 : if (progress)
921 [ # # ]: 0 : progress->end();
922 [ + - ]: 21 : CpuTimer time_to_destroy;
923 : :
924 [ + - ][ + - ]: 21 : PRINT_DEBUG_3( "Time to destroy r_tree %f secs.\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
925 [ # # ]: 0 : time_to_destroy.cpu_secs());
926 : :
927 : : // Remove the crud that accumulated during the merge
928 : : // operations, from the geometry database.
929 [ + - ][ + - ]: 21 : PRINT_DEBUG_3( "Merge Reffaces time: %f secs\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
930 [ # # ]: 0 : timer.cpu_secs() );
931 : :
932 [ + - ][ + - ]: 21 : PRINT_DEBUG_19("Cleaning out TDCompare data from RefFaces...\n");
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
933 [ - + ][ # # ]: 21 : if ( groupResults && faces_merged.size() )
[ # # ][ - + ]
934 : : {
935 [ # # ]: 0 : DLIList<RefEntity*> refentity_list;
936 : : RefFace *tmp_face;
937 [ # # ][ # # ]: 0 : for (int iii = faces_merged.size(); iii > 0; iii-- )
938 : : {
939 [ # # ]: 0 : tmp_face = faces_merged.get_and_step();
940 [ # # ][ # # ]: 0 : if ( !tmp_face->deactivated() )
941 [ # # ][ # # ]: 0 : refentity_list.append(tmp_face);
942 : : }
943 [ # # ][ # # ]: 0 : RefGroup *new_group = RefEntityFactory::instance()->construct_RefGroup("gr_surfs_merged");
944 [ # # ]: 0 : new_group->add_ref_entity( refentity_list );
945 [ # # ][ # # ]: 0 : if (print_info) PRINT_INFO("Created new group %s (Group %d)\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
946 : : " Group contains surfaces that were merged during\n"
947 : : " current merge operation\n",
948 : : new_group->entity_name().c_str(),
949 [ # # ]: 0 : new_group->id());
950 [ # # ]: 0 : lastSurfsMerged = new_group;
951 : : }
952 : : //since surface mergeing has occured and we either don't want the
953 : : //group or didn't store it, set the lastsurfs to null.
954 : : else
955 : 21 : lastSurfsMerged = NULL;
956 : :
957 [ + - ]: 21 : if( destroyDeadGeometry )
958 [ + - ][ + - ]: 21 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
959 : :
960 [ + - ][ + - ]: 21 : PRINT_DEBUG_3( "cleanout time: %f secs\n", timer.cpu_secs() );
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
961 [ - + ]: 21 : if (print_info)
962 : : {
963 [ # # ][ # # ]: 0 : PRINT_INFO( "Consolidated %d pair", merge_count);
[ # # ][ # # ]
964 [ # # ]: 0 : if(merge_count > 1)
965 [ # # ][ # # ]: 0 : PRINT_INFO("s");
[ # # ][ # # ]
966 [ # # ][ # # ]: 0 : PRINT_INFO( " of surfaces\n");
[ # # ][ # # ]
967 : : }
968 [ + - ][ + - ]: 21 : if( AppUtil::instance()->interrupt() )
[ - + ]
969 : : {
970 [ # # ][ # # ]: 0 : PRINT_WARNING("Surface merging aborted.\n");
[ # # ][ # # ]
971 : 0 : return CUBIT_FAILURE;
972 : : }
973 : :
974 [ + - ][ - + ]: 21 : if( failed_merges.size() )
975 : 0 : return CUBIT_FAILURE;
976 : :
977 [ + - ]: 74 : return CUBIT_SUCCESS;
978 : : }
979 : :
980 : 0 : CubitStatus MergeTool::merge_all_refedges()
981 : : {
982 : : // if( !displayProgress )
983 [ # # ][ # # ]: 0 : PRINT_INFO( "\n...Merging all Curves in the model\n" );
[ # # ][ # # ]
984 : :
985 : : // Get the list of all the RefEdges in the model
986 [ # # ]: 0 : DLIList<RefEdge*> refedge_list_model;
987 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->ref_edges(refedge_list_model);
988 : :
989 : : // Merge the RefEdges in this list
990 [ # # ][ # # ]: 0 : if( merge_refedges( refedge_list_model ) == CUBIT_FAILURE )
991 : : {
992 [ # # ][ # # ]: 0 : PRINT_ERROR( "Curve merging failed\n" );
[ # # ][ # # ]
993 : 0 : return CUBIT_FAILURE;
994 : : }
995 : :
996 [ # # ]: 0 : return CUBIT_SUCCESS;
997 : : }
998 : :
999 : 0 : CubitStatus MergeTool::find_mergeable_refentities( DLIList<RefEntity*> &entities,
1000 : : DLIList< DLIList<RefFace*>*> &lists_of_mergeable_ref_faces,
1001 : : DLIList< DLIList<RefEdge*>*> &lists_of_mergeable_ref_edges,
1002 : : DLIList< DLIList<RefVertex*>*> &lists_of_mergeable_ref_vertices)
1003 : : {
1004 [ # # ]: 0 : DLIList<RefEntity*> tmp_ents;
1005 : :
1006 : : int i;
1007 : :
1008 : : //only want surfaces and above
1009 [ # # ][ # # ]: 0 : for( i=entities.size(); i--; )
1010 : : {
1011 [ # # ]: 0 : RefEntity *ref_ent = entities.get_and_step();
1012 [ # # ][ # # ]: 0 : if( ref_ent->dimension() > 1 || ref_ent->dimension() == -1 )
[ # # ][ # # ]
[ # # ]
1013 [ # # ]: 0 : tmp_ents.append( ref_ent );
1014 : : }
1015 [ # # ]: 0 : find_mergeable_reffaces( tmp_ents, lists_of_mergeable_ref_faces, false );
1016 : :
1017 : : //only want curves and above
1018 [ # # ]: 0 : tmp_ents.clean_out();
1019 [ # # ][ # # ]: 0 : for( i=entities.size(); i--; )
1020 : : {
1021 [ # # ]: 0 : RefEntity *ref_ent = entities.get_and_step();
1022 [ # # ][ # # ]: 0 : if( ref_ent->dimension() > 0 || ref_ent->dimension() == -1 )
[ # # ][ # # ]
[ # # ]
1023 [ # # ]: 0 : tmp_ents.append( ref_ent );
1024 : : }
1025 [ # # ]: 0 : find_mergeable_refedges( tmp_ents, lists_of_mergeable_ref_edges, false );
1026 : :
1027 [ # # ]: 0 : find_mergeable_refvertices( entities, lists_of_mergeable_ref_vertices, false);
1028 : :
1029 : : /*
1030 : : //remove the compare partners off everything
1031 : : DLIList<RefEntity*> all_ents;
1032 : : RefEntity::get_all_child_ref_entities( entities, all_ents );
1033 : : PRINT_INFO("Got %d children\n", all_ents.size() );
1034 : : all_ents += entities;
1035 : :
1036 : : int i;
1037 : : for( i=all_ents.size(); i--; )
1038 : : all_ents.get_and_step()->remove_compare_data();
1039 : : */
1040 [ # # ]: 0 : remove_compare_data();
1041 : :
1042 [ # # ]: 0 : return CUBIT_SUCCESS;
1043 : : }
1044 : :
1045 : 0 : CubitStatus MergeTool::find_mergeable_reffaces( DLIList<RefEntity*> &entities,
1046 : : DLIList< DLIList<RefFace*>*> &lists_of_mergeable_ref_faces,
1047 : : bool clean_up_compare_data )
1048 : : {
1049 [ # # ]: 0 : DLIList<TopologyEntity*> t_ents;
1050 [ # # ][ # # ]: 0 : CAST_LIST(entities, t_ents, TopologyEntity);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1051 : :
1052 [ # # ][ # # ]: 0 : DLIList<RefFace*> refface_list;
1053 : : int i;
1054 [ # # ][ # # ]: 0 : for( i=t_ents.size(); i--; )
1055 : : {
1056 [ # # ]: 0 : DLIList<RefFace*> tmp_faces;
1057 [ # # ][ # # ]: 0 : t_ents.get_and_step()->ref_faces( tmp_faces );
1058 [ # # ]: 0 : refface_list += tmp_faces;
1059 [ # # ]: 0 : }
1060 : :
1061 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
1062 [ # # ][ # # ]: 0 : RTree<RefFace*> a_tree(GEOMETRY_RESABS*geom_factor);
1063 : : // AbstractTree <RefFace*> *a_tree = new RTree<RefFace*> (GEOMETRY_RESABS*geom_factor);
1064 : :
1065 [ # # ][ # # ]: 0 : DLIList<RefFace*> refface_array( refface_list.size() );
[ # # ]
1066 [ # # ]: 0 : refface_list.reset();
1067 : :
1068 : : // Remove entities that should not be automatically merged
1069 [ # # ]: 0 : int loop_size = refface_list.size();
1070 [ # # ]: 0 : CpuTimer time_to_build;
1071 [ # # ]: 0 : for( i = 0; i < loop_size; i++ )
1072 : : {
1073 [ # # ]: 0 : RefFace *curr_face = refface_list.get_and_step();
1074 [ # # ][ # # ]: 0 : if( curr_face->is_mergeable() )
1075 : : {
1076 [ # # ]: 0 : refface_array.append( curr_face );
1077 [ # # ]: 0 : a_tree.add(curr_face);
1078 : : }
1079 : : }
1080 [ # # ][ # # ]: 0 : PRINT_DEBUG_3( "Time to build r_tree %f secs, with %d entries\n",
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1081 [ # # ]: 0 : time_to_build.cpu_secs(), refface_array.size() );
1082 : :
1083 : : //initialize the marked flag for fast nulification...
1084 [ # # ]: 0 : int array_size = refface_array.size();
1085 [ # # ]: 0 : for ( i = 0; i < array_size; i++)
1086 [ # # ][ # # ]: 0 : refface_array[i]->marked(i);
1087 : :
1088 : 0 : ProgressTool* progress = 0;
1089 [ # # ]: 0 : if( displayProgress )
1090 : : {
1091 : : char info[64];
1092 [ # # ]: 0 : sprintf(info, "Comparing %d Surfaces for Merge", refface_array.size() );
1093 [ # # ][ # # ]: 0 : progress = AppUtil::instance()->progress_tool();
1094 [ # # ]: 0 : if (progress)
1095 : : {
1096 : : progress->start( 0, refface_array.size(), "Comparing Surfaces:",
1097 [ # # ][ # # ]: 0 : info, CUBIT_TRUE, CUBIT_TRUE );
1098 : : }
1099 : : }
1100 : :
1101 : : // Now find overlapping RefFaces and merge them.
1102 : : // Make sure that the operation is not performed on
1103 : : // RefFaces that are deactivated.
1104 : 0 : int j = 0;
1105 : 0 : RefFace* refface_ptr = NULL;
1106 : 0 : RefFace* compare_refface_ptr = NULL;
1107 [ # # ][ # # ]: 0 : DLIList<RefFace*> faces_in_range;
1108 : :
1109 [ # # ][ # # ]: 0 : CubitBox temp_box;
1110 [ # # ][ # # ]: 0 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ # # ][ # # ]
[ # # ]
1111 : : {
1112 [ # # ][ # # ]: 0 : if( progress ) progress->step();
1113 : :
1114 [ # # ]: 0 : refface_ptr = refface_array[i];
1115 [ # # ]: 0 : if( refface_ptr == NULL )
1116 : 0 : continue;
1117 : :
1118 : : // There is no need to compare if the first RefFace is
1119 : : // deactivated.
1120 [ # # ][ # # ]: 0 : if( refface_ptr->deactivated() == CUBIT_TRUE )
1121 : 0 : continue ;
1122 : :
1123 : : //Now from the atree, get the surfaces that are close.
1124 [ # # ][ # # ]: 0 : temp_box = refface_ptr->bounding_box();
[ # # ]
1125 [ # # ]: 0 : faces_in_range.clean_out();
1126 [ # # ]: 0 : a_tree.find(temp_box, faces_in_range);
1127 : :
1128 [ # # ]: 0 : DLIList<RefVolume*> tmp_vols;
1129 [ # # ]: 0 : refface_ptr->ref_volumes( tmp_vols);
1130 [ # # ]: 0 : RefVolume* tmp_vol= tmp_vols.get();
1131 : :
1132 : 0 : DLIList<RefFace*> *new_list = NULL;
1133 [ # # ][ # # ]: 0 : for( j = 0; (j < faces_in_range.size()) && !AppUtil::instance()->interrupt(); j++ )
[ # # ][ # # ]
[ # # ][ # # ]
1134 : : {
1135 [ # # ]: 0 : compare_refface_ptr = faces_in_range.get_and_step();
1136 [ # # ]: 0 : if( compare_refface_ptr == NULL )
1137 : 0 : continue;
1138 : :
1139 [ # # ]: 0 : if( compare_refface_ptr == refface_ptr )
1140 : 0 : continue;
1141 : :
1142 : : //surfaces in the same bodies won't merge
1143 [ # # ]: 0 : tmp_vols.clean_out();
1144 [ # # ]: 0 : compare_refface_ptr->ref_volumes( tmp_vols );
1145 [ # # ]: 0 : RefVolume* compare_vol= tmp_vols.get();
1146 [ # # ]: 0 : if( tmp_vol == compare_vol )
1147 : 0 : continue;
1148 : :
1149 : : // Make sure we are not comparing the same entity
1150 : : // and that they are not deactivated.
1151 [ # # ][ # # ]: 0 : if( ( refface_ptr == compare_refface_ptr ) ||
[ # # ]
1152 [ # # ]: 0 : ( compare_refface_ptr->deactivated() == CUBIT_TRUE ) )
1153 : 0 : continue;
1154 : :
1155 [ # # ]: 0 : geom_factor = GeometryQueryTool::get_geometry_factor();
1156 : : CubitBoolean status =
1157 : : refface_ptr->about_spatially_equal( compare_refface_ptr,
1158 : : geom_factor,
1159 : : CUBIT_TRUE,
1160 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->get_merge_test_bbox(),
1161 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->get_merge_test_internal() );
[ # # ]
1162 [ # # ]: 0 : if( status == CUBIT_FALSE )
1163 : 0 : continue;
1164 : :
1165 : : //First test to see if all the children of these
1166 : : // reffaces are mergeable
1167 [ # # ][ # # ]: 0 : if( !compare_refface_ptr->children_mergeable() )
1168 : 0 : continue;
1169 : :
1170 : : //Now let us test to see if we are merging two faces that
1171 : : //belong to the same volume.
1172 [ # # ][ # # ]: 0 : DLIList<RefVolume*> ref_vols_1, ref_vols_2;
[ # # ][ # # ]
1173 [ # # ]: 0 : refface_ptr->ref_volumes( ref_vols_1 );
1174 [ # # ]: 0 : compare_refface_ptr->ref_volumes( ref_vols_2 );
1175 [ # # ]: 0 : ref_vols_2.intersect( ref_vols_1 );
1176 [ # # ][ # # ]: 0 : if( ref_vols_2.size() > 0 )
1177 : : {
1178 [ # # ][ # # ]: 0 : PRINT_ERROR( "Tolerance problems, trying to find mergeable "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1179 : : "surfaces\non the same volume.\n"
1180 : : " %s (surface %d) and %s (surface %d) on\n"
1181 : : " %s (volume %d)\n",
1182 : : refface_ptr->entity_name().c_str(),
1183 : : refface_ptr->id(),
1184 : : compare_refface_ptr->entity_name().c_str(),
1185 : : compare_refface_ptr->id(),
1186 : : ref_vols_2.get()->entity_name().c_str(),
1187 [ # # ]: 0 : ref_vols_2.get()->id() );
1188 : 0 : continue;
1189 : : }
1190 : :
1191 : : // Always retain the entity with the lowest id.
1192 [ # # ]: 0 : int nullify = compare_refface_ptr->marked();
1193 : :
1194 : : // Now check if merge is okay with all assistants.
1195 : 0 : CubitBoolean assistant_says_no = CUBIT_FALSE;
1196 [ # # ][ # # ]: 0 : for( int k = assistant_list_.size(); k > 0; k-- )
1197 : : {
1198 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
1199 [ # # ]: 0 : ->can_merge( refface_ptr, compare_refface_ptr ) )
1200 : : {
1201 : 0 : assistant_says_no = CUBIT_TRUE;
1202 : 0 : break;
1203 : : }
1204 : : }
1205 [ # # ]: 0 : if( assistant_says_no )
1206 : 0 : continue;
1207 : :
1208 [ # # ]: 0 : a_tree.remove(compare_refface_ptr);
1209 : :
1210 [ # # ]: 0 : refface_array[nullify] = NULL;
1211 : :
1212 [ # # ]: 0 : if( new_list == NULL )
1213 : : {
1214 [ # # ][ # # ]: 0 : new_list = new DLIList<RefFace*>;
1215 [ # # ]: 0 : new_list->append( refface_ptr );
1216 [ # # ]: 0 : new_list->append( compare_refface_ptr );
1217 : : }
1218 : : else
1219 [ # # ][ # # ]: 0 : new_list->append( compare_refface_ptr );
[ # # ]
1220 : 0 : }
1221 : :
1222 [ # # ]: 0 : if( new_list )
1223 [ # # ]: 0 : lists_of_mergeable_ref_faces.append( new_list );
1224 [ # # ]: 0 : }
1225 : : //clean the marks.
1226 [ # # ]: 0 : for( i = 0; i < array_size; i++ )
1227 : : {
1228 [ # # ][ # # ]: 0 : if ( refface_array[i] != NULL )
1229 [ # # ][ # # ]: 0 : refface_array[i]->marked(0);
1230 : : }
1231 : :
1232 [ # # ]: 0 : if( clean_up_compare_data )
1233 [ # # ]: 0 : remove_compare_data();
1234 : :
1235 [ # # ]: 0 : if (progress)
1236 [ # # ]: 0 : progress->end();
1237 : :
1238 : :
1239 [ # # ][ # # ]: 0 : if( AppUtil::instance()->interrupt() )
[ # # ]
1240 : : {
1241 [ # # ][ # # ]: 0 : PRINT_WARNING("Finding mergeable surfaces aborted.\n");
[ # # ][ # # ]
1242 : 0 : return CUBIT_FAILURE;
1243 : : }
1244 : :
1245 [ # # ]: 0 : return CUBIT_SUCCESS;
1246 : : }
1247 : :
1248 : 0 : CubitStatus MergeTool::find_mergeable_refedges( DLIList<RefEntity*> &entities,
1249 : : DLIList< DLIList<RefEdge*>*> &lists_of_mergeable_ref_edges,
1250 : : bool clean_up_compare_data )
1251 : : {
1252 : :
1253 [ # # ]: 0 : DLIList<TopologyEntity*> t_ents;
1254 [ # # ][ # # ]: 0 : CAST_LIST(entities, t_ents, TopologyEntity);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1255 : :
1256 [ # # ][ # # ]: 0 : DLIList<RefEdge*> refedge_list;
1257 : : int i;
1258 [ # # ][ # # ]: 0 : for( i=t_ents.size(); i--; )
1259 : : {
1260 [ # # ]: 0 : DLIList<RefEdge*> tmp_edges;
1261 [ # # ][ # # ]: 0 : t_ents.get_and_step()->ref_edges( tmp_edges );
1262 [ # # ]: 0 : refedge_list += tmp_edges;
1263 [ # # ]: 0 : }
1264 : :
1265 [ # # ][ # # ]: 0 : if( refedge_list.size() == 0 )
1266 : 0 : return CUBIT_SUCCESS;
1267 : :
1268 [ # # ][ # # ]: 0 : DLIList<RefEdge*> refedge_array( refedge_list.size() );
[ # # ]
1269 [ # # ]: 0 : refedge_list.reset();
1270 : :
1271 [ # # ][ # # ]: 0 : DLIList<RefEdge*> edges_on_two_surfs;
1272 : :
1273 [ # # ][ # # ]: 0 : for( i = refedge_list.size(); i > 0; i-- )
1274 : : {
1275 : : // Remove entities that should not be automatically merged
1276 [ # # ]: 0 : RefEdge *curr_edge = refedge_list.get_and_step();
1277 [ # # ][ # # ]: 0 : if( curr_edge->is_mergeable() )
1278 : : {
1279 : : //put all edges in the list first that are attached
1280 : : //to only one or zero surface. This prevents curves on sheet
1281 : : //bodies from being excluded.
1282 [ # # ]: 0 : DLIList<RefFace*> tmp_faces;
1283 [ # # ]: 0 : curr_edge->ref_faces( tmp_faces );
1284 [ # # ][ # # ]: 0 : if( tmp_faces.size() < 2 )
1285 [ # # ]: 0 : refedge_array.append( curr_edge );
1286 : : else
1287 [ # # ][ # # ]: 0 : edges_on_two_surfs.append( curr_edge );
1288 : : }
1289 : : }
1290 : :
1291 [ # # ][ # # ]: 0 : for( i = edges_on_two_surfs.size(); i--; )
1292 [ # # ][ # # ]: 0 : refedge_array.append( edges_on_two_surfs.get_and_step() );
1293 : :
1294 : 0 : ProgressTool* progress = 0;
1295 : :
1296 : 0 : int j = 0;
1297 : 0 : RefEdge* refedge_ptr = NULL;
1298 : 0 : RefEdge* compare_refedge_ptr = NULL;
1299 [ # # ]: 0 : int array_size = refedge_array.size();
1300 [ # # ][ # # ]: 0 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ # # ][ # # ]
[ # # ]
1301 : : {
1302 [ # # ][ # # ]: 0 : if( progress ) progress->step();
1303 : :
1304 [ # # ]: 0 : refedge_ptr = refedge_array[i];
1305 [ # # ]: 0 : if( refedge_ptr == NULL )
1306 : 0 : continue;
1307 : :
1308 : : // There is not need to compare if the first RefEdge is
1309 : : // dactivated.
1310 [ # # ][ # # ]: 0 : if ( refedge_ptr->deactivated() == CUBIT_TRUE )
1311 : 0 : continue ;
1312 : :
1313 [ # # ][ # # ]: 0 : if( refedge_ptr->get_compare_partner() )
1314 : : {
1315 : : //see if owning reface has compare partner...if so
1316 : : //edge is merged already.
1317 [ # # ]: 0 : DLIList<RefFace*> tmp_faces;
1318 [ # # ]: 0 : refedge_ptr->ref_faces( tmp_faces );
1319 : :
1320 : : int kk;
1321 : 0 : bool owning_surface_has_compare_partner = false;
1322 [ # # ][ # # ]: 0 : for( kk=tmp_faces.size(); kk--; )
1323 [ # # ][ # # ]: 0 : if( tmp_faces.get_and_step()->get_compare_partner() )
[ # # ]
1324 : 0 : owning_surface_has_compare_partner = true;
1325 : :
1326 [ # # ]: 0 : if( owning_surface_has_compare_partner )
1327 [ # # ][ # # ]: 0 : continue;
1328 : : }
1329 : :
1330 : 0 : DLIList<RefEdge*> *new_list = NULL;
1331 : :
1332 [ # # ][ # # ]: 0 : for( j = i+1; (j < array_size) && !AppUtil::instance()->interrupt(); j++ )
[ # # ][ # # ]
[ # # ]
1333 : : {
1334 [ # # ]: 0 : compare_refedge_ptr = refedge_array[j];
1335 [ # # ]: 0 : if( compare_refedge_ptr == NULL )
1336 : 0 : continue;
1337 : :
1338 : : // Make sure we are not comparing the same entity
1339 : : // and that they are not deactivated.
1340 [ # # ][ # # ]: 0 : if( ( refedge_ptr == compare_refedge_ptr ) ||
[ # # ]
1341 [ # # ]: 0 : ( compare_refedge_ptr->deactivated() == CUBIT_TRUE ) )
1342 : 0 : continue;
1343 : :
1344 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
1345 : : CubitBoolean status =
1346 : : refedge_ptr->about_spatially_equal(compare_refedge_ptr,
1347 : : geom_factor,
1348 : : (CubitSense*)NULL,
1349 [ # # ]: 0 : CUBIT_TRUE);
1350 [ # # ]: 0 : if( status == CUBIT_FALSE )
1351 : 0 : continue;
1352 : :
1353 : :
1354 : : //Make sure the children of the refedges are mergeable
1355 [ # # ][ # # ]: 0 : if( !refedge_ptr->children_mergeable() )
1356 : 0 : continue;
1357 : :
1358 : : //Now let us test to see if we are merging two edges that
1359 : : //belong to the same face
1360 [ # # ][ # # ]: 0 : DLIList<RefFace*> ref_faces_1, ref_faces_2;
[ # # ]
[ # # # ]
1361 [ # # ]: 0 : refedge_ptr->ref_faces( ref_faces_1 );
1362 [ # # ]: 0 : compare_refedge_ptr->ref_faces( ref_faces_2 );
1363 [ # # ]: 0 : ref_faces_2.intersect( ref_faces_1 );
1364 [ # # ][ # # ]: 0 : if( ref_faces_2.size() > 0 )
1365 : : {
1366 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Tolerance problems, trying to find mergeable"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1367 : : " curves\non the same surface.\n"
1368 : : "%s (curve %d) and %s (curve %d) on\n"
1369 : : "%s (surface %d)\n",
1370 : : refedge_ptr->entity_name().c_str(),
1371 : : refedge_ptr->id(),
1372 : : compare_refedge_ptr->entity_name().c_str(),
1373 : : compare_refedge_ptr->id(),
1374 : : ref_faces_2.get()->entity_name().c_str(),
1375 [ # # ]: 0 : ref_faces_2.get()->id() );
1376 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Try changing the merge tolerance.\n" );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1377 : 0 : continue;
1378 : : }
1379 : : // If we are in this block, we want to merge the
1380 : : // two entities. If they do not merge, there was
1381 : : // an error somewhere.
1382 : :
1383 : : // Always retain the entity with the lowest id.
1384 : 0 : int nullify = j;
1385 [ # # ][ # # ]: 0 : if( refedge_ptr->id() > compare_refedge_ptr->id() )
[ # # ]
1386 : : {
1387 [ # # ]: 0 : std::swap(refedge_ptr, compare_refedge_ptr);
1388 : 0 : nullify = i;
1389 : : }
1390 : :
1391 : : // Now check if merge is okay with all assistants.
1392 : 0 : CubitBoolean assistant_says_no = CUBIT_FALSE;
1393 [ # # ][ # # ]: 0 : for( int k = assistant_list_.size(); k > 0; k-- )
1394 : : {
1395 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
1396 [ # # ]: 0 : ->can_merge( refedge_ptr, compare_refedge_ptr ) )
1397 : : {
1398 : 0 : assistant_says_no = CUBIT_TRUE;
1399 : 0 : break;
1400 : : }
1401 : : }
1402 [ # # ]: 0 : if( assistant_says_no )
1403 : 0 : continue;
1404 : :
1405 : : // Need to retain these so that the pointers are not
1406 : : // accessed after a merge operation when the 'deleted'
1407 : : // pointer may be invalid.
1408 : : //int retained_id = refedge_ptr->id();
1409 : : //int deleted_id = compare_refedge_ptr->id();
1410 : :
1411 [ # # ]: 0 : if( new_list == NULL )
1412 : : {
1413 [ # # ][ # # ]: 0 : new_list = new DLIList<RefEdge*>;
1414 [ # # ]: 0 : new_list->append( refedge_ptr );
1415 [ # # ]: 0 : new_list->append( compare_refedge_ptr );
1416 : : }
1417 : : else
1418 [ # # ]: 0 : new_list->append( compare_refedge_ptr );
1419 : :
1420 [ # # ]: 0 : refedge_array[nullify] = NULL;
1421 : :
1422 [ # # ]: 0 : if (nullify == i)
1423 [ # # ]: 0 : break;
[ # # # ]
1424 : 0 : }
1425 : :
1426 [ # # ]: 0 : if( new_list )
1427 [ # # ]: 0 : lists_of_mergeable_ref_edges.append( new_list );
1428 : : }
1429 : :
1430 [ # # ]: 0 : if( clean_up_compare_data )
1431 [ # # ]: 0 : remove_compare_data();
1432 : :
1433 [ # # ]: 0 : if(progress)
1434 [ # # ]: 0 : progress->end();
1435 : :
1436 [ # # ]: 0 : return CUBIT_SUCCESS;
1437 : : }
1438 : :
1439 : 0 : CubitStatus MergeTool::find_only_mergeable_surfaces ( DLIList<BodySM*> &body_list,
1440 : : DLIList< DLIList<Surface*>*> &lists_of_mergeable_surfaces )
1441 : : {
1442 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
1443 : 0 : double merge_tolerance = geom_factor*GEOMETRY_RESABS;
1444 : : int i,j,k,l;
1445 : :
1446 [ # # ]: 0 : std::map< Surface*, DLIList<Surface*>*> surf_to_list_map;
1447 [ # # ]: 0 : std::map< Surface*, DLIList<Surface*>*>::iterator list_iter;
1448 : :
1449 [ # # ][ # # ]: 0 : DLIList<BodySM*> tmp_body_list = body_list;
1450 [ # # ]: 0 : tmp_body_list.reset();
1451 [ # # ][ # # ]: 0 : for(i=tmp_body_list.size(); i--; )
1452 : : {
1453 [ # # ]: 0 : BodySM *tmp_body1 = tmp_body_list.pop();
1454 [ # # ]: 0 : CubitBox body1_box = tmp_body1->bounding_box();
1455 [ # # ][ # # ]: 0 : for(j=tmp_body_list.size(); j--; )
1456 : : {
1457 [ # # ]: 0 : BodySM *tmp_body2 = tmp_body_list.get_and_step();
1458 [ # # ]: 0 : CubitBox body2_box = tmp_body2->bounding_box();
1459 : :
1460 : :
1461 [ # # ][ # # ]: 0 : if( body1_box.overlap( merge_tolerance, body2_box ) )
1462 : : {
1463 [ # # ]: 0 : DLIList<Surface*> body1_surfs;
1464 [ # # ][ # # ]: 0 : DLIList<Surface*> body2_surfs;
1465 : :
1466 [ # # ]: 0 : tmp_body1->surfaces( body1_surfs );
1467 [ # # ]: 0 : tmp_body2->surfaces( body2_surfs );
1468 : :
1469 [ # # ][ # # ]: 0 : for( k=body1_surfs.size(); k--; )
1470 : : {
1471 [ # # ]: 0 : Surface *body1_surf = body1_surfs.pop();
1472 [ # # ]: 0 : CubitBox surf1_box = body1_surf->bounding_box();
1473 : :
1474 [ # # ][ # # ]: 0 : for(l=body2_surfs.size(); l--; )
1475 : : {
1476 [ # # ]: 0 : Surface *body2_surf = body2_surfs.get();
1477 : :
1478 [ # # ]: 0 : if( body2_surf == NULL )
1479 : : {
1480 [ # # ]: 0 : body2_surfs.step();
1481 : 0 : continue;
1482 : : }
1483 : :
1484 [ # # ]: 0 : CubitBox surf2_box = body2_surf->bounding_box();
1485 : :
1486 [ # # ][ # # ]: 0 : if( surf1_box.overlap( merge_tolerance, surf2_box ) )
1487 : : {
1488 : :
1489 [ # # ][ # # ]: 0 : if( about_spatially_equal( body1_surf, body2_surf, geom_factor) )
1490 : : {
1491 : : //check to see if surfs have already been inserted into lists
1492 : 0 : DLIList<Surface*> *surf1_list = NULL;
1493 : 0 : DLIList<Surface*> *surf2_list = NULL;
1494 : :
1495 [ # # ]: 0 : list_iter = surf_to_list_map.find( body1_surf);
1496 [ # # ][ # # ]: 0 : if( list_iter != surf_to_list_map.end() )
[ # # ]
1497 [ # # ]: 0 : surf1_list = list_iter->second;
1498 : :
1499 [ # # ]: 0 : list_iter = surf_to_list_map.find( body2_surf);
1500 [ # # ][ # # ]: 0 : if( list_iter != surf_to_list_map.end() )
[ # # ]
1501 [ # # ]: 0 : surf2_list = list_iter->second;
1502 : :
1503 [ # # ][ # # ]: 0 : if( surf1_list == NULL && surf2_list == NULL )
1504 : : {
1505 [ # # ][ # # ]: 0 : surf1_list = new DLIList<Surface*>;
1506 [ # # ]: 0 : surf1_list->append( body1_surf );
1507 [ # # ]: 0 : surf1_list->append( body2_surf );
1508 : : surf_to_list_map.insert( std::map<Surface*,
1509 [ # # ][ # # ]: 0 : DLIList<Surface*>*>::value_type( body1_surf, surf1_list ));
1510 : : surf_to_list_map.insert( std::map<Surface*,
1511 [ # # ][ # # ]: 0 : DLIList<Surface*>*>::value_type( body2_surf, surf1_list ));
1512 [ # # ]: 0 : lists_of_mergeable_surfaces.append( surf1_list );
1513 : 0 : break;
1514 : : }
1515 [ # # ]: 0 : else if( surf1_list == NULL )
1516 : : {
1517 [ # # ][ # # ]: 0 : PRINT_ERROR("A surface cannot be merged with more than 1 other surface\n");
[ # # ][ # # ]
1518 : : }
1519 [ # # ]: 0 : else if( surf2_list == NULL )
1520 : : {
1521 [ # # ][ # # ]: 0 : PRINT_ERROR("A surface cannot be merged with more than 1 other surface\n");
[ # # ][ # # ]
1522 : : }
1523 : :
1524 [ # # ]: 0 : body2_surfs.change_to( NULL );
1525 : : }
1526 : : }
1527 [ # # ][ # # ]: 0 : body2_surfs.step();
[ # # ]
1528 : 0 : }
1529 [ # # ][ # # ]: 0 : }
1530 : : }
1531 [ # # ]: 0 : }
1532 [ # # ]: 0 : }
1533 [ # # ]: 0 : return CUBIT_SUCCESS;
1534 : : }
1535 : :
1536 : :
1537 : 0 : CubitStatus MergeTool::find_only_mergeable_surfaces ( DLIList<BodySM*> &body_list,
1538 : : DLIList< DLIList<Surface*>*> &lists_of_mergeable_surfaces, const double tol )
1539 : : {
1540 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
1541 : 0 : double merge_tolerance = tol;
1542 : : int i,j,k,l;
1543 : :
1544 [ # # ]: 0 : std::map< Surface*, DLIList<Surface*>*> surf_to_list_map;
1545 [ # # ]: 0 : std::map< Surface*, DLIList<Surface*>*>::iterator list_iter;
1546 : :
1547 [ # # ][ # # ]: 0 : DLIList<BodySM*> tmp_body_list = body_list;
1548 [ # # ]: 0 : tmp_body_list.reset();
1549 [ # # ][ # # ]: 0 : for(i=tmp_body_list.size(); i--; )
1550 : : {
1551 [ # # ]: 0 : BodySM *tmp_body1 = tmp_body_list.pop();
1552 [ # # ]: 0 : CubitBox body1_box = tmp_body1->bounding_box();
1553 [ # # ][ # # ]: 0 : for(j=tmp_body_list.size(); j--; )
1554 : : {
1555 [ # # ]: 0 : BodySM *tmp_body2 = tmp_body_list.get_and_step();
1556 [ # # ]: 0 : CubitBox body2_box = tmp_body2->bounding_box();
1557 : :
1558 : :
1559 [ # # ][ # # ]: 0 : if( body1_box.overlap( merge_tolerance, body2_box ) )
1560 : : {
1561 [ # # ]: 0 : DLIList<Surface*> body1_surfs;
1562 [ # # ][ # # ]: 0 : DLIList<Surface*> body2_surfs;
1563 : :
1564 [ # # ]: 0 : tmp_body1->surfaces( body1_surfs );
1565 [ # # ]: 0 : tmp_body2->surfaces( body2_surfs );
1566 : :
1567 [ # # ][ # # ]: 0 : for( k=body1_surfs.size(); k--; )
1568 : : {
1569 [ # # ]: 0 : Surface *body1_surf = body1_surfs.pop();
1570 [ # # ]: 0 : CubitBox surf1_box = body1_surf->bounding_box();
1571 : :
1572 [ # # ][ # # ]: 0 : for(l=body2_surfs.size(); l--; )
1573 : : {
1574 [ # # ]: 0 : Surface *body2_surf = body2_surfs.get();
1575 : :
1576 [ # # ]: 0 : if( body2_surf == NULL )
1577 : : {
1578 [ # # ]: 0 : body2_surfs.step();
1579 : 0 : continue;
1580 : : }
1581 : :
1582 [ # # ]: 0 : CubitBox surf2_box = body2_surf->bounding_box();
1583 : :
1584 [ # # ][ # # ]: 0 : if( surf1_box.overlap( merge_tolerance, surf2_box ) )
1585 : : {
1586 : :
1587 [ # # ][ # # ]: 0 : if( about_spatially_equal( body1_surf, body2_surf, geom_factor) )
1588 : : {
1589 : : //check to see if surfs have already been inserted into lists
1590 : 0 : DLIList<Surface*> *surf1_list = NULL;
1591 : 0 : DLIList<Surface*> *surf2_list = NULL;
1592 : :
1593 [ # # ]: 0 : list_iter = surf_to_list_map.find( body1_surf);
1594 [ # # ][ # # ]: 0 : if( list_iter != surf_to_list_map.end() )
[ # # ]
1595 [ # # ]: 0 : surf1_list = list_iter->second;
1596 : :
1597 [ # # ]: 0 : list_iter = surf_to_list_map.find( body2_surf);
1598 [ # # ][ # # ]: 0 : if( list_iter != surf_to_list_map.end() )
[ # # ]
1599 [ # # ]: 0 : surf2_list = list_iter->second;
1600 : :
1601 [ # # ][ # # ]: 0 : if( surf1_list == NULL && surf2_list == NULL )
1602 : : {
1603 [ # # ][ # # ]: 0 : surf1_list = new DLIList<Surface*>;
1604 [ # # ]: 0 : surf1_list->append( body1_surf );
1605 [ # # ]: 0 : surf1_list->append( body2_surf );
1606 : : surf_to_list_map.insert( std::map<Surface*,
1607 [ # # ][ # # ]: 0 : DLIList<Surface*>*>::value_type( body1_surf, surf1_list ));
1608 : : surf_to_list_map.insert( std::map<Surface*,
1609 [ # # ][ # # ]: 0 : DLIList<Surface*>*>::value_type( body2_surf, surf1_list ));
1610 [ # # ]: 0 : lists_of_mergeable_surfaces.append( surf1_list );
1611 : 0 : break;
1612 : : }
1613 [ # # ]: 0 : else if( surf1_list == NULL )
1614 : : {
1615 [ # # ][ # # ]: 0 : PRINT_ERROR("A surface cannot be merged with more than 1 other surface\n");
[ # # ][ # # ]
1616 : : }
1617 [ # # ]: 0 : else if( surf2_list == NULL )
1618 : : {
1619 [ # # ][ # # ]: 0 : PRINT_ERROR("A surface cannot be merged with more than 1 other surface\n");
[ # # ][ # # ]
1620 : : }
1621 : :
1622 [ # # ]: 0 : body2_surfs.change_to( NULL );
1623 : : }
1624 : : }
1625 [ # # ][ # # ]: 0 : body2_surfs.step();
[ # # ]
1626 : 0 : }
1627 [ # # ][ # # ]: 0 : }
1628 : : }
1629 [ # # ]: 0 : }
1630 [ # # ]: 0 : }
1631 [ # # ]: 0 : return CUBIT_SUCCESS;
1632 : : }
1633 : :
1634 : 0 : CubitStatus MergeTool::find_only_mergeable_curves( DLIList<Curve*> &all_curves,
1635 : : DLIList< DLIList<Curve*>*> &lists_of_mergeable_curves, double input_tol )
1636 : : {
1637 : : int i;
1638 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
1639 [ # # ]: 0 : if(input_tol > 0.0)
1640 : 0 : geom_factor = input_tol/GEOMETRY_RESABS;
1641 : :
1642 : : //build up a tree for speed purposes
1643 [ # # ]: 0 : RTree<Curve*> a_tree(GEOMETRY_RESABS*geom_factor);
1644 : : //AbstractTree <Curve*> *a_tree = new RTree<Curve*> (GEOMETRY_RESABS*geom_factor);
1645 [ # # ][ # # ]: 0 : for( i=all_curves.size(); i--; )
1646 [ # # ][ # # ]: 0 : a_tree.add( all_curves.get_and_step() );
1647 : :
1648 [ # # ][ # # ]: 0 : std::map< Curve*, DLIList<Curve*>*> curve_to_list_map;
1649 [ # # ]: 0 : std::map< Curve*, DLIList<Curve*>*>::iterator list_iter;
1650 : :
1651 [ # # ][ # # ]: 0 : for( i=all_curves.size(); i--; )
1652 : : {
1653 [ # # ]: 0 : Curve *curr_curve = all_curves.get_and_step();
1654 [ # # ]: 0 : if( curr_curve == NULL )
1655 : 0 : continue;
1656 : :
1657 [ # # ]: 0 : BodySM *cur_sm = curr_curve->bodysm();
1658 : :
1659 : : //get close curves
1660 [ # # ]: 0 : DLIList<Curve*> close_curves;
1661 [ # # ][ # # ]: 0 : a_tree.find(curr_curve->bounding_box(), close_curves);
[ # # ]
1662 : :
1663 : : int j;
1664 [ # # ][ # # ]: 0 : for( j=close_curves.size(); j--; )
1665 : : {
1666 [ # # ]: 0 : Curve *other_curve = close_curves.get_and_step();
1667 [ # # ]: 0 : if( curr_curve == other_curve )
1668 : 0 : continue;
1669 : :
1670 [ # # ]: 0 : BodySM *other_sm = other_curve->bodysm();
1671 : :
1672 [ # # ]: 0 : if(cur_sm != other_sm)
1673 : : {
1674 : 0 : bool mergeable = false;
1675 : :
1676 : : // If these curves are already merged add them to the list.
1677 [ # # ][ # # ]: 0 : if(curr_curve->bridge_manager() &&
[ # # ][ # # ]
1678 [ # # ][ # # ]: 0 : curr_curve->bridge_manager() == other_curve->bridge_manager())
1679 : : {
1680 : 0 : mergeable = true;
1681 : : }
1682 : :
1683 [ # # ]: 0 : if(!mergeable)
1684 : : {
1685 : : CubitSense rel_sense;
1686 : : CubitBoolean abs = about_spatially_equal( curr_curve, other_curve, rel_sense,
1687 [ # # ]: 0 : geom_factor );
1688 [ # # ]: 0 : if(abs)
1689 : 0 : mergeable = true;
1690 : : }
1691 : :
1692 [ # # ]: 0 : if( mergeable )
1693 : : {
1694 : : //check to see if curves have already been inserted into lists
1695 : 0 : DLIList<Curve*> *curve1_list = NULL;
1696 : :
1697 [ # # ]: 0 : list_iter = curve_to_list_map.find( curr_curve );
1698 [ # # ][ # # ]: 0 : if( list_iter != curve_to_list_map.end() )
[ # # ]
1699 [ # # ]: 0 : curve1_list = list_iter->second;
1700 : :
1701 [ # # ]: 0 : if( curve1_list == NULL )
1702 : : {
1703 [ # # ][ # # ]: 0 : curve1_list = new DLIList<Curve*>;
1704 [ # # ]: 0 : curve1_list->append( curr_curve );
1705 [ # # ]: 0 : curve1_list->append( other_curve );
1706 : : curve_to_list_map.insert( std::map<Curve*,
1707 [ # # ][ # # ]: 0 : DLIList<Curve*>*>::value_type( curr_curve , curve1_list ));
1708 : : curve_to_list_map.insert( std::map<Curve*,
1709 [ # # ][ # # ]: 0 : DLIList<Curve*>*>::value_type( other_curve, curve1_list ));
1710 [ # # ]: 0 : lists_of_mergeable_curves.append( curve1_list );
1711 : : }
1712 : : else
1713 : : {
1714 [ # # ]: 0 : curve1_list->append( other_curve );
1715 : : curve_to_list_map.insert( std::map<Curve*,
1716 [ # # ][ # # ]: 0 : DLIList<Curve*>*>::value_type( other_curve, curve1_list ));
1717 : : }
1718 : :
1719 : : //remove mergeable curves from list and reset list
1720 [ # # ]: 0 : int item_index = all_curves.where_is_item( other_curve );
1721 [ # # ]: 0 : if( item_index > 0 )
1722 : : {
1723 [ # # ]: 0 : int curr_index = all_curves.get_index();
1724 [ # # ]: 0 : all_curves.reset();
1725 [ # # ]: 0 : all_curves.step( item_index );
1726 [ # # ]: 0 : all_curves.change_to( NULL );
1727 [ # # ]: 0 : all_curves.reset();
1728 [ # # ]: 0 : all_curves.step( curr_index );
1729 : : }
1730 : : }
1731 : : }
1732 : : }
1733 [ # # ]: 0 : }
1734 [ # # ]: 0 : return CUBIT_SUCCESS;
1735 : : }
1736 : :
1737 : 0 : CubitStatus MergeTool::find_only_mergeable_curves( DLIList<Surface*> &surf_list,
1738 : : DLIList< DLIList<Curve*>*> &lists_of_mergeable_curves, double input_tol )
1739 : : {
1740 : : //collect all the curves from off the bodies
1741 [ # # ]: 0 : DLIList<Curve*> all_curves;
1742 [ # # ]: 0 : surf_list.reset();
1743 : : int i;
1744 [ # # ][ # # ]: 0 : for(i=surf_list.size(); i--; )
1745 : : {
1746 [ # # ]: 0 : Surface* tmp_surf = surf_list.get_and_step();
1747 [ # # ]: 0 : DLIList<Curve*> tmp_curves;
1748 [ # # ]: 0 : tmp_surf->curves(tmp_curves);
1749 [ # # ]: 0 : all_curves += tmp_curves;
1750 [ # # ]: 0 : }
1751 : :
1752 [ # # ][ # # ]: 0 : return find_only_mergeable_curves(all_curves, lists_of_mergeable_curves, input_tol);
1753 : : }
1754 : :
1755 : 0 : CubitStatus MergeTool::find_only_mergeable_curves( DLIList<BodySM*> &body_list,
1756 : : DLIList< DLIList<Curve*>*> &lists_of_mergeable_curves, double input_tol )
1757 : : {
1758 : : //collect all the curves from off the bodies
1759 [ # # ]: 0 : DLIList<Curve*> all_curves;
1760 [ # # ]: 0 : body_list.reset();
1761 : : int i;
1762 [ # # ][ # # ]: 0 : for(i=body_list.size(); i--; )
1763 : : {
1764 [ # # ]: 0 : BodySM* tmp_body = body_list.get_and_step();
1765 [ # # ]: 0 : DLIList<Curve*> tmp_curves;
1766 [ # # ]: 0 : tmp_body->curves( tmp_curves);
1767 [ # # ]: 0 : all_curves += tmp_curves;
1768 [ # # ]: 0 : }
1769 : :
1770 [ # # ][ # # ]: 0 : return find_only_mergeable_curves(all_curves, lists_of_mergeable_curves, input_tol);
1771 : :
1772 : : }
1773 : :
1774 : 0 : CubitStatus MergeTool::find_mergeable_refvertices( DLIList<RefEntity*> &entities,
1775 : : DLIList< DLIList<RefVertex*>*> &lists_of_mergeable_ref_vertices,
1776 : : bool clean_up_compare_data )
1777 : : {
1778 : :
1779 [ # # ]: 0 : DLIList<TopologyEntity*> t_ents;
1780 [ # # ][ # # ]: 0 : CAST_LIST(entities, t_ents, TopologyEntity);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1781 : :
1782 [ # # ][ # # ]: 0 : DLIList<RefVertex*> refvertex_list;
1783 : : int i;
1784 [ # # ][ # # ]: 0 : for( i=t_ents.size(); i--; )
1785 : : {
1786 [ # # ]: 0 : DLIList<RefVertex*> tmp_verts;
1787 [ # # ][ # # ]: 0 : t_ents.get_and_step()->ref_vertices( tmp_verts);
1788 [ # # ]: 0 : refvertex_list += tmp_verts;
1789 [ # # ]: 0 : }
1790 : :
1791 [ # # ][ # # ]: 0 : if( refvertex_list.size() == 0 )
1792 : 0 : return CUBIT_SUCCESS;
1793 : :
1794 [ # # ][ # # ]: 0 : DLIList<RefVertex*> refvertex_array( refvertex_list.size() );
[ # # ]
1795 [ # # ]: 0 : refvertex_list.reset();
1796 : :
1797 : : // Remove entities that should not be automatically merged
1798 [ # # ][ # # ]: 0 : for( i = refvertex_list.size(); i > 0; i-- )
1799 : : {
1800 [ # # ]: 0 : RefVertex *curr_vert = refvertex_list.get_and_step();
1801 [ # # ][ # # ]: 0 : if( curr_vert->is_mergeable() )
1802 [ # # ]: 0 : refvertex_array.append( curr_vert );
1803 : : }
1804 : :
1805 : 0 : ProgressTool* progress = 0;
1806 : :
1807 : : // Now find overlapping RefVertices and merge them.
1808 : : // Make sure that the operation is not performed on
1809 : : // RefVertices that are deactivated.
1810 : 0 : int j = 0;
1811 : 0 : RefVertex* refvertex_ptr = NULL;
1812 : 0 : RefVertex* compare_refvertex_ptr = NULL;
1813 [ # # ]: 0 : int array_size = refvertex_array.size();
1814 [ # # ][ # # ]: 0 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ # # ][ # # ]
[ # # ]
1815 : : {
1816 [ # # ][ # # ]: 0 : if( progress ) progress->step();
1817 : :
1818 [ # # ]: 0 : refvertex_ptr = refvertex_array[i];
1819 [ # # ]: 0 : if( refvertex_ptr == NULL )
1820 : 0 : continue;
1821 : :
1822 [ # # ][ # # ]: 0 : if( refvertex_ptr->get_compare_partner() )
1823 : 0 : continue;
1824 : :
1825 : : // There is not need to compare if the first RefVertex is
1826 : : // dactivated.
1827 [ # # ][ # # ]: 0 : if( refvertex_ptr->deactivated() == CUBIT_TRUE )
1828 : 0 : continue ;
1829 : :
1830 : 0 : DLIList<RefVertex*> *new_list = NULL;
1831 : :
1832 [ # # ][ # # ]: 0 : for( j = i+1; (j < array_size) && !AppUtil::instance()->interrupt(); j++ )
[ # # ][ # # ]
[ # # ]
1833 : : {
1834 [ # # ]: 0 : compare_refvertex_ptr = refvertex_array[j];
1835 [ # # ]: 0 : if( compare_refvertex_ptr == NULL )
1836 : 0 : continue;
1837 : :
1838 : : // Make sure we are not comparing the same entity
1839 : : // and that they are not deactivated.
1840 [ # # ][ # # ]: 0 : if( ( refvertex_ptr == compare_refvertex_ptr ) ||
[ # # ]
1841 [ # # ]: 0 : ( compare_refvertex_ptr->deactivated() == CUBIT_TRUE ) )
1842 : 0 : continue;
1843 : :
1844 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
1845 : : CubitBoolean status =
1846 : : refvertex_ptr->about_spatially_equal( compare_refvertex_ptr,
1847 [ # # ]: 0 : geom_factor );
1848 [ # # ]: 0 : if( status == CUBIT_FALSE )
1849 : 0 : continue;
1850 : :
1851 : : //Make sure we arn't merging two vertices on a
1852 : : //curve.
1853 [ # # ][ # # ]: 0 : DLIList<RefEdge*> edges_1, edges_2;
[ # # ]
[ # # # ]
1854 [ # # ]: 0 : refvertex_ptr->ref_edges( edges_1 );
1855 [ # # ]: 0 : compare_refvertex_ptr->ref_edges( edges_2 );
1856 [ # # ]: 0 : edges_2.intersect( edges_1 );
1857 [ # # ][ # # ]: 0 : if( edges_2.size() > 0 )
1858 : : {
1859 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Tolerance problems, trying to merge"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1860 : : " vertices\non the same curve.\n"
1861 : : "%s (vertex %d) and %s (vertex %d) on\n"
1862 : : "%s (curve %d)\n",
1863 : : refvertex_ptr->entity_name().c_str(),
1864 : : refvertex_ptr->id(),
1865 : : compare_refvertex_ptr->entity_name().c_str(),
1866 : : compare_refvertex_ptr->id(),
1867 : : edges_2.get()->entity_name().c_str(),
1868 [ # # ]: 0 : edges_2.get()->id() );
1869 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Try changing the merge tolerance.\n" );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1870 : 0 : continue;
1871 : : }
1872 : :
1873 : : // Always retain the entity with the lowest id.
1874 : 0 : int nullify = j;
1875 [ # # ][ # # ]: 0 : if( refvertex_ptr->id() > compare_refvertex_ptr->id() )
[ # # ]
1876 : : {
1877 [ # # ]: 0 : std::swap(refvertex_ptr, compare_refvertex_ptr);
1878 : 0 : nullify = i;
1879 : : }
1880 : :
1881 : : // Now check if merge is okay with all assistants.
1882 : 0 : CubitBoolean assistant_says_no = CUBIT_FALSE;
1883 [ # # ][ # # ]: 0 : for( int k = assistant_list_.size(); k > 0; k-- )
1884 : : {
1885 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
1886 [ # # ]: 0 : ->can_merge( refvertex_ptr, compare_refvertex_ptr ) )
1887 : : {
1888 : 0 : assistant_says_no = CUBIT_TRUE;
1889 : 0 : break;
1890 : : }
1891 : : }
1892 [ # # ]: 0 : if( assistant_says_no )
1893 : 0 : continue;
1894 : :
1895 : : // Need to retain these so that the pointers are not
1896 : : // accessed after a merge operation when the 'deleted'
1897 : : // pointer may be invalid.
1898 : : //int retained_id = refvertex_ptr->id();
1899 : : //int deleted_id = compare_refvertex_ptr->id();
1900 : :
1901 [ # # ]: 0 : refvertex_array[nullify] = NULL;
1902 : :
1903 [ # # ]: 0 : if( new_list == NULL )
1904 : : {
1905 [ # # ][ # # ]: 0 : new_list = new DLIList<RefVertex*>;
1906 [ # # ]: 0 : new_list->append( refvertex_ptr );
1907 [ # # ]: 0 : new_list->append( compare_refvertex_ptr );
1908 : : }
1909 : : else
1910 [ # # ]: 0 : new_list->append( compare_refvertex_ptr );
1911 : :
1912 [ # # ]: 0 : if( nullify == i )
1913 [ # # ]: 0 : break;
[ # # # ]
1914 : 0 : }
1915 : :
1916 [ # # ]: 0 : if( new_list )
1917 [ # # ]: 0 : lists_of_mergeable_ref_vertices.append( new_list );
1918 : : }
1919 : :
1920 [ # # ]: 0 : if(progress)
1921 [ # # ]: 0 : progress->end();
1922 : :
1923 [ # # ]: 0 : if( clean_up_compare_data )
1924 [ # # ]: 0 : remove_compare_data();
1925 : :
1926 [ # # ][ # # ]: 0 : if( AppUtil::instance()->interrupt() )
[ # # ]
1927 : : {
1928 [ # # ][ # # ]: 0 : PRINT_WARNING("Vertex merging aborted.\n");
[ # # ][ # # ]
1929 : 0 : return CUBIT_FAILURE;
1930 : : }
1931 [ # # ]: 0 : return CUBIT_SUCCESS;
1932 : : }
1933 : :
1934 : :
1935 : 53 : CubitStatus MergeTool::merge_refedges( DLIList<RefEdge*>& refedge_list,
1936 : : CubitBoolean should_clean_out,
1937 : : CubitBoolean print_info)
1938 : : {
1939 [ + - ][ - + ]: 53 : if( refedge_list.size() < 20 )
1940 [ # # ]: 0 : return old_merge_refedges( refedge_list, should_clean_out, print_info );
1941 : :
1942 : 53 : int merge_count = 0;
1943 [ + - ]: 53 : CpuTimer timer;
1944 : :
1945 [ + - ]: 53 : double geom_factor = GeometryQueryTool::get_geometry_factor();
1946 [ + - ]: 53 : RTree<RefEdge*> a_tree(GEOMETRY_RESABS*geom_factor);
1947 : : //AbstractTree <RefEdge*> *a_tree = new RTree<RefEdge*> (GEOMETRY_RESABS*geom_factor);
1948 : :
1949 [ + - ][ + - ]: 106 : DLIList<RefEdge*> refedge_array( refedge_list.size() );
[ + - ]
1950 [ + - ]: 53 : refedge_list.reset();
1951 : :
1952 : : // Remove entities that should not be automatically merged
1953 : 53 : int i = 0;
1954 [ + - ]: 53 : int loop_size = refedge_list.size();
1955 [ + - ]: 53 : CpuTimer time_to_build;
1956 [ + + ]: 1807 : for( i = 0; i < loop_size; i++ )
1957 : : {
1958 [ + - ]: 1754 : RefEdge *curr_edge = refedge_list.get_and_step();
1959 [ + - ][ + - ]: 1754 : if( curr_edge->is_mergeable() )
1960 : : {
1961 [ + - ]: 1754 : refedge_array.append( curr_edge );
1962 [ + - ]: 1754 : a_tree.add(curr_edge);
1963 : : }
1964 : : }
1965 : :
1966 : : //initialize the marked flag for fast nulification...
1967 [ + - ]: 53 : int array_size = refedge_array.size();
1968 [ + + ]: 1807 : for ( i = 0; i < array_size; i++)
1969 [ + - ][ + - ]: 1754 : refedge_array[i]->marked(i);
1970 : :
1971 : 53 : ProgressTool* progress = 0;
1972 [ - + ]: 53 : if( displayProgress )
1973 : : {
1974 : : char info[64];
1975 [ # # ]: 0 : sprintf(info, "Comparing %d Curves for Merge", refedge_array.size() );
1976 [ # # ][ # # ]: 0 : progress = AppUtil::instance()->progress_tool();
1977 [ # # ]: 0 : if (progress)
1978 : : {
1979 : : progress->start( 0, refedge_array.size(), "Comparing Curves:",
1980 [ # # ][ # # ]: 0 : info, CUBIT_TRUE, CUBIT_TRUE );
1981 : : }
1982 : : }
1983 : :
1984 : : // Now find overlapping RefEdges and merge them.
1985 : : // Make sure that the operation is not performed on
1986 : : // RefEdges that are deactivated.
1987 : 53 : int j = 0;
1988 : 53 : RefEdge* refedge_ptr = NULL;
1989 : 53 : RefEdge* compare_refedge_ptr = NULL;
1990 [ + - ][ + - ]: 106 : DLIList<RefEdge*> edges_merged, edges_in_range;
[ + - ][ + - ]
1991 [ + - ][ + - ]: 106 : CubitBox temp_box;
1992 [ + - ][ + - ]: 106 : std::map<RefEdge*, RefEdge*> failed_merges;
1993 [ + - ]: 53 : std::map<RefEdge*, RefEdge*>::iterator map_iter;
1994 : :
1995 [ + + ][ + - ]: 1807 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ + - ][ + - ]
[ + + ]
1996 : : {
1997 [ - + ][ # # ]: 1754 : if( progress ) progress->step();
1998 : :
1999 [ + - ]: 1754 : refedge_ptr = refedge_array[i];
2000 [ - + ]: 1754 : if( refedge_ptr == NULL )
2001 : 0 : continue;
2002 : :
2003 : : // There is no need to compare if the first RefEdge is
2004 : : // deactivated.
2005 [ + - ][ - + ]: 1754 : if( refedge_ptr->deactivated() == CUBIT_TRUE )
2006 : 0 : continue ;
2007 : :
2008 : : //Now from the atree, get the edges that are close.
2009 [ + - ][ + - ]: 1754 : temp_box = refedge_ptr->bounding_box();
[ + - ]
2010 [ + - ]: 1754 : edges_in_range.clean_out();
2011 [ + - ]: 1754 : a_tree.find(temp_box, edges_in_range);
2012 : :
2013 [ + - ][ + + ]: 14700 : for( j = 0; (j < edges_in_range.size()) && !AppUtil::instance()->interrupt(); j++ )
[ + - ][ + - ]
[ + - ][ + + ]
2014 : : {
2015 [ + - ]: 12946 : compare_refedge_ptr = edges_in_range.get_and_step();
2016 [ - + ]: 12946 : if( compare_refedge_ptr == NULL )
2017 : 0 : continue;
2018 : :
2019 : : // Make sure we are not comparing the same entity
2020 : : // and that they are not deactivated.
2021 [ + + ][ - + ]: 23522 : if( ( refedge_ptr == compare_refedge_ptr ) ||
[ + + ]
2022 [ + - ]: 10576 : ( compare_refedge_ptr->deactivated() == CUBIT_TRUE ) )
2023 : 2370 : continue;
2024 : :
2025 [ + - ]: 10576 : map_iter = failed_merges.find( refedge_ptr );
2026 [ + - ][ + - ]: 10576 : if( map_iter != failed_merges.end() )
[ - + ]
2027 [ # # ][ # # ]: 0 : if( map_iter->second == compare_refedge_ptr )
2028 : 0 : continue;
2029 : :
2030 : : // IMPORTANT: this compare is for merging, so we set the
2031 : : // last parameter to CUBIT_TRUE so that the
2032 : : // compare sets the TDCompare data which will
2033 : : // be used in the RefEntity compare and merge.
2034 : : // By Jihong
2035 : :
2036 [ + - ]: 10576 : geom_factor = GeometryQueryTool::get_geometry_factor();
2037 : : CubitBoolean status =
2038 : : refedge_ptr->about_spatially_equal( compare_refedge_ptr,
2039 : : geom_factor,
2040 : : (CubitSense*)NULL,
2041 [ + - ]: 10576 : CUBIT_TRUE );
2042 [ + - ]: 10576 : if( status == CUBIT_FALSE )
2043 : 10576 : continue;
2044 : :
2045 : : // If we are in this block, we want to merge the
2046 : : // two entities. If they do not merge, there was
2047 : : // an error somewhere.
2048 : :
2049 : : //First test to see if all the children of these
2050 : : // refedges are mergeable
2051 [ # # ][ # # ]: 0 : if( !compare_refedge_ptr->children_mergeable() )
2052 : : {
2053 [ # # ][ # # ]: 0 : PRINT_WARNING( "Cannot merge curve %d and %d\n"
[ # # ][ # # ]
[ # # ]
2054 : : " Make sure all merge flags are on.\n",
2055 [ # # ]: 0 : refedge_ptr->id(), compare_refedge_ptr->id() );
2056 : 0 : continue;
2057 : : }
2058 : :
2059 : : /*
2060 : : //refuse to merge free edges
2061 : : if( refedge_ptr->ref_volume() == NULL )
2062 : : {
2063 : : PRINT_WARNING("Merging of free curves prohibited: Curve %d\n", refedge_ptr->id() );
2064 : : continue;
2065 : : }
2066 : :
2067 : : if( compare_refedge_ptr->ref_volume() == NULL )
2068 : : {
2069 : : PRINT_WARNING("Merging of free curves prohibited: Curve %d\n", compare_refedge_ptr->id() );
2070 : : continue;
2071 : : } */
2072 : :
2073 : : // Always retain the entity with the lowest id.
2074 [ # # ]: 0 : int nullify = compare_refedge_ptr->marked();
2075 [ # # ][ # # ]: 0 : if( refedge_ptr->id() > compare_refedge_ptr->id() )
[ # # ]
2076 : : {
2077 [ # # ]: 0 : std::swap(refedge_ptr, compare_refedge_ptr);
2078 : 0 : nullify = i;
2079 : : }
2080 [ # # ]: 0 : if (groupResults )
2081 : : {
2082 [ # # ]: 0 : edges_merged.append(refedge_ptr);
2083 : : }
2084 : :
2085 : : // Now check if merge is okay with all assistants.
2086 : 0 : CubitBoolean assistant_says_no = CUBIT_FALSE;
2087 [ # # ][ # # ]: 0 : for( int k = assistant_list_.size(); k > 0; k-- )
2088 : : {
2089 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
2090 [ # # ]: 0 : ->can_merge( refedge_ptr, compare_refedge_ptr ) )
2091 : : {
2092 : 0 : assistant_says_no = CUBIT_TRUE;
2093 : 0 : break;
2094 : : }
2095 : : }
2096 [ # # ]: 0 : if( assistant_says_no )
2097 : 0 : continue;
2098 : :
2099 : : // Need to retain these so that the pointers are not
2100 : : // accessed after a merge operation when the 'deleted'
2101 : : // pointer may be invalid.
2102 [ # # ]: 0 : int retained_id = refedge_ptr->id();
2103 [ # # ]: 0 : int deleted_id = compare_refedge_ptr->id();
2104 : :
2105 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Consolidating RefEdge %d and "
[ # # ][ # # ]
[ # # ][ # # ]
2106 [ # # ]: 0 : "%d...\n", retained_id, deleted_id );
2107 : :
2108 [ # # ]: 0 : a_tree.remove(compare_refedge_ptr);
2109 [ # # ][ # # ]: 0 : if( merge_BTE( refedge_ptr, compare_refedge_ptr ) )
2110 : : {
2111 : 0 : merge_count++;
2112 [ # # ][ # # ]: 0 : if (print_info && !progress)
2113 [ # # ][ # # ]: 0 : PRINT_INFO( "Curve %d and %d consolidated\n",
[ # # ]
2114 [ # # ]: 0 : retained_id, deleted_id );
2115 : :
2116 : : // The 'deleted' RefEdge is now gone. It is an
2117 : : // error to access that pointer, so we need to
2118 : : // get it out of the list.
2119 [ # # ]: 0 : refedge_array[nullify] = NULL;
2120 : : }
2121 : : else
2122 : : {
2123 [ # # ][ # # ]: 0 : failed_merges.insert( std::make_pair(compare_refedge_ptr, refedge_ptr) );
[ # # ]
2124 [ # # ][ # # ]: 0 : PRINT_DEBUG_19("Failed to merge Curve %d and %d\n",
[ # # ][ # # ]
[ # # ][ # # ]
2125 [ # # ]: 0 : retained_id, deleted_id);
2126 [ # # ]: 0 : a_tree.add(compare_refedge_ptr);
2127 : : }
2128 : :
2129 [ # # ]: 0 : if (nullify == i)
2130 : 0 : break;
2131 : :
2132 : : }
2133 : : }
2134 : :
2135 : : //clean the marks.
2136 [ + + ]: 1807 : for( i = 0; i < array_size; i++ )
2137 : : {
2138 [ + - ][ + - ]: 1754 : if ( refedge_array[i] != NULL )
2139 [ + - ][ + - ]: 1754 : refedge_array[i]->marked(0);
2140 : : }
2141 [ + - ]: 53 : complete_merge();
2142 [ - + ]: 53 : if (progress)
2143 [ # # ]: 0 : progress->end();
2144 [ + - ]: 53 : CpuTimer time_to_destroy;
2145 : :
2146 [ + - ][ + - ]: 53 : PRINT_DEBUG_3( "Time to destroy r_tree %f secs.\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
2147 [ # # ]: 0 : time_to_destroy.cpu_secs());
2148 : :
2149 : : // Remove the crud that accumulated during the merge
2150 : : // operations, from the geometry database.
2151 [ + - ][ + - ]: 53 : PRINT_DEBUG_3( "Merge RefEdge time: %f secs\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
2152 [ # # ]: 0 : timer.cpu_secs() );
2153 : :
2154 [ + - ][ + - ]: 53 : PRINT_DEBUG_19("Cleaning out TDCompare data from RefEdges...\n");
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
2155 [ - + ][ # # ]: 53 : if ( groupResults && edges_merged.size() )
[ # # ][ - + ]
2156 : : {
2157 [ # # ]: 0 : DLIList<RefEntity*> refentity_list;
2158 : : RefEdge *tmp_edge;
2159 [ # # ][ # # ]: 0 : for (int iii = edges_merged.size(); iii > 0; iii-- )
2160 : : {
2161 [ # # ]: 0 : tmp_edge = edges_merged.get_and_step();
2162 [ # # ][ # # ]: 0 : if ( !tmp_edge->deactivated() )
2163 [ # # ][ # # ]: 0 : refentity_list.append(tmp_edge);
2164 : : }
2165 [ # # ][ # # ]: 0 : RefGroup *new_group = RefEntityFactory::instance()->construct_RefGroup("gr_curvs_merged");
2166 [ # # ]: 0 : new_group->add_ref_entity( refentity_list );
2167 [ # # ][ # # ]: 0 : if (print_info) PRINT_INFO("Created new group %s (Group %d)\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2168 : : " Group contains curves that were merged during\n"
2169 : : " current merge operation\n",
2170 : : new_group->entity_name().c_str(),
2171 [ # # ]: 0 : new_group->id());
2172 [ # # ]: 0 : lastCurvsMerged = new_group;
2173 : : }
2174 : : else
2175 : 53 : lastCurvsMerged = NULL;
2176 : :
2177 [ + - ]: 53 : if( destroyDeadGeometry )
2178 [ + - ][ + - ]: 53 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
2179 : :
2180 [ + - ][ + - ]: 53 : PRINT_DEBUG_3( "cleanout time: %f secs\n", timer.cpu_secs() );
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2181 [ + + ]: 53 : if (print_info)
2182 : : {
2183 [ + - ][ + - ]: 22 : PRINT_INFO( "Consolidated %d pair", merge_count);
[ + - ][ + - ]
2184 [ - + ]: 22 : if(merge_count > 1)
2185 [ # # ][ # # ]: 0 : PRINT_INFO("s");
[ # # ][ # # ]
2186 [ + - ][ + - ]: 22 : PRINT_INFO( " of curves \n");
[ + - ][ + - ]
2187 : : }
2188 [ + - ][ + - ]: 53 : if( AppUtil::instance()->interrupt() )
[ - + ]
2189 : : {
2190 [ # # ][ # # ]: 0 : PRINT_WARNING("Curve merging aborted.\n");
[ # # ][ # # ]
2191 : 0 : return CUBIT_FAILURE;
2192 : : }
2193 : :
2194 [ + - ]: 106 : return CUBIT_SUCCESS;
2195 : : }
2196 : :
2197 : :
2198 : 0 : CubitStatus MergeTool::old_merge_refedges( DLIList<RefEdge*>& refedge_list,
2199 : : CubitBoolean should_clean_out,
2200 : : CubitBoolean print_info)
2201 : : {
2202 : : // The basic algorithm is to step through the input list,
2203 : : // compare every entity with every other entity, and
2204 : : // merge the entities that are spatially equivalent.
2205 : : // In the merge, the entity with the lowest ID is retained.
2206 : : // NOTE: RefEdges can participate in multiple merges.
2207 : 0 : int merge_count = 0;
2208 [ # # ]: 0 : CpuTimer timer;
2209 [ # # ][ # # ]: 0 : DLIList<RefEdge*> refedge_array( refedge_list.size() );
2210 [ # # ]: 0 : refedge_list.reset();
2211 : :
2212 : : // Remove entities that should not be automatically merged
2213 : 0 : int i = 0;
2214 [ # # ][ # # ]: 0 : for( i = refedge_list.size(); i > 0; i-- )
2215 : : {
2216 [ # # ]: 0 : RefEdge *curr_edge = refedge_list.get_and_step();
2217 [ # # ][ # # ]: 0 : if( curr_edge->is_mergeable() )
2218 [ # # ]: 0 : refedge_array.append( curr_edge );
2219 : : }
2220 [ # # ][ # # ]: 0 : DLIList<RefEdge*> edges_merged;
2221 : :
2222 : :
2223 : 0 : ProgressTool* progress = 0;
2224 : : //if( displayProgress )
2225 : : //{
2226 : : // progress = AppUtil::instance()->progress_tool();
2227 : : // if (progress)
2228 : : // {
2229 : : // progress->start( 0, refedge_array.size(), "Comparing Curves:",
2230 : : // 0, CUBIT_TRUE, CUBIT_TRUE );
2231 : : // }
2232 : : //}
2233 : :
2234 : : // Now find overlapping Refedges and merge them.
2235 : : // Make sure that the operation is not performed
2236 : : // on Refedges that are deactivated.
2237 : 0 : int j = 0;
2238 : 0 : RefEdge* refedge_ptr = NULL;
2239 : 0 : RefEdge* compare_refedge_ptr = NULL;
2240 [ # # ]: 0 : int array_size = refedge_array.size();
2241 [ # # ][ # # ]: 0 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ # # ][ # # ]
[ # # ]
2242 : : {
2243 [ # # ][ # # ]: 0 : if( progress ) progress->step();
2244 : :
2245 [ # # ]: 0 : refedge_ptr = refedge_array[i];
2246 [ # # ]: 0 : if( refedge_ptr == NULL )
2247 : 0 : continue;
2248 : :
2249 : : // There is not need to compare if the first RefEdge is
2250 : : // dactivated.
2251 [ # # ][ # # ]: 0 : if ( refedge_ptr->deactivated() == CUBIT_TRUE )
2252 : 0 : continue ;
2253 : :
2254 : : // // Get the GeometryQueryEngine of the Refedges
2255 : : // // Try to merge this RefEdge only if it is associated
2256 : : // // with a SolidModelingEngine.
2257 : : // GeometryQueryEngine* firstGMEPtr =
2258 : : // refedge_ptr->get_geometry_query_engine();
2259 : : // SolidModelingEngine* SMEPtr = CAST_TO( firstGMEPtr, SolidModelingEngine );
2260 : :
2261 : : // // If the RefEdge is not associated with a
2262 : : // // SolidModelingEngine, go on to the next RefEdge.
2263 : : // if ( SMEPtr == NULL )
2264 : : // continue ;
2265 : :
2266 [ # # ][ # # ]: 0 : for( j = i+1; (j < array_size) && !AppUtil::instance()->interrupt(); j++ )
[ # # ][ # # ]
[ # # ]
2267 : : {
2268 [ # # ]: 0 : compare_refedge_ptr = refedge_array[j];
2269 [ # # ]: 0 : if( compare_refedge_ptr == NULL )
2270 : 0 : continue;
2271 : :
2272 : : // Make sure we are not comparing the same entity
2273 : : // and that they are not deactivated.
2274 [ # # ][ # # ]: 0 : if( ( refedge_ptr == compare_refedge_ptr ) ||
[ # # ]
2275 [ # # ]: 0 : ( compare_refedge_ptr->deactivated() == CUBIT_TRUE ) )
2276 : 0 : continue;
2277 : :
2278 : : // // Get the GeometryQueryEngine of the second RefEdge.
2279 : : // // Make sure that both engines are same before proceeding
2280 : : // // with the merge.
2281 : : // GeometryQueryEngine* secondGMEPtr =
2282 : : // compare_refedge_ptr->get_geometry_query_engine() ;
2283 : :
2284 : : // // If the two engines are different, move on to the
2285 : : // // next RefEdge.
2286 : : // if( firstGMEPtr != secondGMEPtr )
2287 : : // continue;
2288 : :
2289 : : // IMPORTANT: this compare is for merging, so we set the
2290 : : // last parameter to CUBIT_TRUE so that the
2291 : : // compare sets the TDCompare data which will
2292 : : // be used in the RefEntity compare and merge.
2293 : : // By Jihong
2294 : :
2295 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
2296 : : CubitBoolean status =
2297 : : refedge_ptr->about_spatially_equal(compare_refedge_ptr,
2298 : : geom_factor,
2299 : : (CubitSense*)NULL,
2300 [ # # ]: 0 : CUBIT_TRUE );
2301 [ # # ]: 0 : if( status == CUBIT_FALSE )
2302 : 0 : continue;
2303 : :
2304 : : //Make sure the children of the refedges are mergeable
2305 [ # # ][ # # ]: 0 : if( !refedge_ptr->children_mergeable() )
2306 : : {
2307 [ # # ][ # # ]: 0 : PRINT_WARNING( "Cannot merge curves %d and %d\n"
[ # # ][ # # ]
[ # # ]
2308 : : " Make sure merge flags are on\n",
2309 [ # # ]: 0 : refedge_ptr->id(), compare_refedge_ptr->id() );
2310 : 0 : continue;
2311 : : }
2312 : :
2313 : : //Now let us test to see if we are merging two edges that
2314 : : //belong to the same face
2315 [ # # ][ # # ]: 0 : DLIList<RefFace*> ref_faces_1, ref_faces_2;
[ # # ]
[ # # # ]
2316 [ # # ]: 0 : refedge_ptr->ref_faces( ref_faces_1 );
2317 [ # # ]: 0 : compare_refedge_ptr->ref_faces( ref_faces_2 );
2318 [ # # ]: 0 : ref_faces_2.intersect( ref_faces_1 );
2319 [ # # ][ # # ]: 0 : if( ref_faces_2.size() > 0 )
2320 : : {
2321 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Tolerance problems, trying to merge"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2322 : : " curves\non the same surface.\n"
2323 : : "%s (curve %d) and %s (curve %d) on\n"
2324 : : "%s (surface %d)\n",
2325 : : refedge_ptr->entity_name().c_str(),
2326 : : refedge_ptr->id(),
2327 : : compare_refedge_ptr->entity_name().c_str(),
2328 : : compare_refedge_ptr->id(),
2329 : : ref_faces_2.get()->entity_name().c_str(),
2330 [ # # ]: 0 : ref_faces_2.get()->id() );
2331 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Try changing the merge tolerance.\n" );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2332 : 0 : continue;
2333 : : }
2334 : : // If we are in this block, we want to merge the
2335 : : // two entities. If they do not merge, there was
2336 : : // an error somewhere.
2337 : :
2338 : : // Always retain the entity with the lowest id.
2339 : 0 : int nullify = j;
2340 [ # # ][ # # ]: 0 : if( refedge_ptr->id() > compare_refedge_ptr->id() )
[ # # ]
2341 : : {
2342 [ # # ]: 0 : std::swap(refedge_ptr, compare_refedge_ptr);
2343 : 0 : nullify = i;
2344 : : }
2345 : : /*
2346 : : //refuse to merge free edges
2347 : : if( refedge_ptr->ref_volume() == NULL )
2348 : : {
2349 : : PRINT_WARNING("Merging of free curves prohibited: Curve %d\n", refedge_ptr->id() );
2350 : : continue;
2351 : : }
2352 : :
2353 : : if( compare_refedge_ptr->ref_volume() == NULL )
2354 : : {
2355 : : PRINT_WARNING("Merging of free curves prohibited: Curve %d\n", compare_refedge_ptr->id() );
2356 : : continue;
2357 : : } */
2358 : :
2359 : : // Now check if merge is okay with all assistants.
2360 : 0 : CubitBoolean assistant_says_no = CUBIT_FALSE;
2361 [ # # ][ # # ]: 0 : for( int k = assistant_list_.size(); k > 0; k-- )
2362 : : {
2363 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
2364 [ # # ]: 0 : ->can_merge( refedge_ptr, compare_refedge_ptr ) )
2365 : : {
2366 : 0 : assistant_says_no = CUBIT_TRUE;
2367 : 0 : break;
2368 : : }
2369 : : }
2370 [ # # ]: 0 : if( assistant_says_no )
2371 : 0 : continue;
2372 : :
2373 : : // Need to retain these so that the pointers are not
2374 : : // accessed after a merge operation when the 'deleted'
2375 : : // pointer may be invalid.
2376 [ # # ]: 0 : int retained_id = refedge_ptr->id();
2377 [ # # ]: 0 : int deleted_id = compare_refedge_ptr->id();
2378 [ # # ]: 0 : if ( groupResults )
2379 : : {
2380 [ # # ]: 0 : edges_merged.append(refedge_ptr);
2381 : : }
2382 [ # # ][ # # ]: 0 : if( merge_BTE( refedge_ptr, compare_refedge_ptr ) )
2383 : : {
2384 : 0 : merge_count++;
2385 [ # # ][ # # ]: 0 : if (print_info && !progress)
2386 [ # # ][ # # ]: 0 : PRINT_INFO( "Curve %d and %d consolidated\n",
[ # # ]
2387 [ # # ]: 0 : retained_id, deleted_id);
2388 : :
2389 : : // The 'deleted' RefEdge is now gone. It is an
2390 : : // error to access that pointer, so we need to
2391 : : // get it out of the list.
2392 [ # # ]: 0 : refedge_array[nullify] = NULL;
2393 : : }
2394 : : else
2395 : : {
2396 [ # # ][ # # ]: 0 : PRINT_ERROR( "Failed to merge Curve %d and %d\n",
[ # # ]
2397 [ # # ]: 0 : retained_id, deleted_id);
2398 [ # # ][ # # ]: 0 : PRINT_INFO("Check for sliver geometry in the vicinity\n");
[ # # ][ # # ]
2399 : : }
2400 : :
2401 [ # # ]: 0 : if (nullify == i)
2402 [ # # ]: 0 : break;
[ # # # ]
2403 : 0 : }
2404 : : }
2405 : :
2406 : : // Remove the crud that accumulated during the
2407 : : // merge operations, from the geometry database.
2408 [ # # ][ # # ]: 0 : PRINT_DEBUG_3( "Merge RefEdges time: %f secs\n",
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2409 [ # # ]: 0 : timer.cpu_secs() );
2410 : :
2411 [ # # ][ # # ]: 0 : PRINT_DEBUG_19(
[ # # ][ # # ]
[ # # ][ # # ]
2412 [ # # ]: 0 : "Cleaning out TDCompare data from RefEdges...\n" );
2413 [ # # ]: 0 : complete_merge();
2414 [ # # ]: 0 : if (progress)
2415 [ # # ]: 0 : progress->end();
2416 : :
2417 [ # # ][ # # ]: 0 : if ( groupResults && edges_merged.size() )
[ # # ][ # # ]
2418 : : {
2419 [ # # ]: 0 : DLIList<RefEntity*> refentity_list;
2420 : : RefEdge *tmp_edge;
2421 [ # # ][ # # ]: 0 : for (int iii = edges_merged.size(); iii > 0; iii-- )
2422 : : {
2423 [ # # ]: 0 : tmp_edge = edges_merged.get_and_step();
2424 [ # # ][ # # ]: 0 : if ( !tmp_edge->deactivated() )
2425 [ # # ][ # # ]: 0 : refentity_list.append(tmp_edge);
2426 : : }
2427 [ # # ][ # # ]: 0 : RefGroup *new_group = RefEntityFactory::instance()->construct_RefGroup("gr_curvs_merged");
2428 [ # # ]: 0 : new_group->add_ref_entity( refentity_list );
2429 [ # # ][ # # ]: 0 : if (print_info) PRINT_INFO("Created new group %s (Group %d)\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2430 : : " Group contains curves that were seperatly merged during\n"
2431 : : " current merge operation (ie, not during surface merge)\n",
2432 : : new_group->entity_name().c_str(),
2433 [ # # ]: 0 : new_group->id());
2434 [ # # ]: 0 : lastCurvsMerged = new_group;
2435 : : }
2436 : : //set this to null otherwise.
2437 : : else
2438 : 0 : lastCurvsMerged = NULL;
2439 : :
2440 [ # # ][ # # ]: 0 : if( should_clean_out == CUBIT_TRUE && destroyDeadGeometry )
2441 : : {
2442 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
2443 [ # # ][ # # ]: 0 : PRINT_DEBUG_3( "cleanout time: %f secs\n",
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2444 [ # # ]: 0 : timer.cpu_secs() );
2445 : : }
2446 : :
2447 [ # # ]: 0 : if(print_info)
2448 [ # # ][ # # ]: 0 : PRINT_INFO( "Consolidated %d curves\n", merge_count );
[ # # ][ # # ]
2449 : :
2450 [ # # ][ # # ]: 0 : if( AppUtil::instance()->interrupt() )
[ # # ]
2451 : : {
2452 [ # # ][ # # ]: 0 : PRINT_WARNING("Curve merging aborted.\n");
[ # # ][ # # ]
2453 : 0 : return CUBIT_FAILURE;
2454 : : }
2455 : :
2456 [ # # ]: 0 : return CUBIT_SUCCESS;
2457 : : }
2458 : :
2459 : 0 : CubitStatus MergeTool::merge_all_refvertices()
2460 : : {
2461 : : // if( !displayProgress )
2462 [ # # ][ # # ]: 0 : PRINT_INFO( "\n...Merging all Vertices in the model\n" );
[ # # ][ # # ]
2463 : :
2464 : : // Get the list of all the RefVertices in the model
2465 [ # # ]: 0 : DLIList<RefVertex*> refvertex_list_model;
2466 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->ref_vertices(refvertex_list_model);
2467 : :
2468 : : // Merge the RefVerties in this list
2469 [ # # ][ # # ]: 0 : if( merge_refvertices( refvertex_list_model ) == CUBIT_FAILURE )
2470 : : {
2471 [ # # ][ # # ]: 0 : PRINT_ERROR( "Vertex merging failed\n" );
[ # # ][ # # ]
2472 : 0 : return CUBIT_FAILURE;
2473 : : }
2474 : :
2475 [ # # ]: 0 : return CUBIT_SUCCESS;
2476 : : }
2477 : :
2478 : :
2479 : 53 : CubitStatus MergeTool::merge_refvertices( DLIList<RefVertex*>& refvertex_list,
2480 : : CubitBoolean print_info)
2481 : : {
2482 [ + - ][ + + ]: 53 : if( refvertex_list.size() < 20 )
2483 [ + - ]: 32 : return old_merge_refvertices( refvertex_list, print_info );
2484 : :
2485 [ + - ]: 21 : CpuTimer timer;
2486 : 21 : int merge_count = 0;
2487 : :
2488 [ + - ]: 21 : double geom_factor = GeometryQueryTool::get_geometry_factor();
2489 [ + - ]: 21 : RTree<RefVertex*> a_tree(GEOMETRY_RESABS*geom_factor);
2490 [ + - ][ + - ]: 42 : DLIList<RefVertex*> refvertex_array( refvertex_list.size() );
[ + - ]
2491 [ + - ]: 21 : refvertex_list.reset();
2492 : :
2493 : : // Remove entities that should not be automatically merged
2494 : 21 : int i = 0;
2495 [ + - ][ + + ]: 737 : for( i = refvertex_list.size(); i > 0; i-- )
2496 : : {
2497 [ + - ]: 716 : RefVertex *curr_vert = refvertex_list.get_and_step();
2498 [ + - ][ + - ]: 716 : if( curr_vert->is_mergeable() )
2499 : : {
2500 [ + - ]: 716 : refvertex_array.append( curr_vert );
2501 [ + - ]: 716 : a_tree.add( curr_vert );
2502 : : }
2503 : : }
2504 : :
2505 : : //initialize the marked flag for fast nulification...
2506 [ + - ]: 21 : int array_size = refvertex_array.size();
2507 [ + + ]: 737 : for ( i = 0; i < array_size; i++)
2508 [ + - ][ + - ]: 716 : refvertex_array[i]->marked(i);
2509 : :
2510 [ + - ][ + - ]: 42 : DLIList<RefVertex*> vertices_merged;
2511 : :
2512 : 21 : ProgressTool* progress = 0;
2513 : :
2514 : : // Now find overlapping RefVertices and merge them.
2515 : : // Make sure that the operation is not performed on
2516 : : // RefVertices that are deactivated.
2517 : 21 : int j = 0;
2518 : 21 : RefVertex* refvertex_ptr = NULL;
2519 : 21 : RefVertex* compare_refvertex_ptr = NULL;
2520 [ + + ][ + - ]: 737 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ + - ][ + - ]
[ + + ]
2521 : : {
2522 [ - + ][ # # ]: 716 : if( progress ) progress->step();
2523 : :
2524 [ + - ]: 716 : refvertex_ptr = refvertex_array[i];
2525 [ - + ]: 716 : if( refvertex_ptr == NULL )
2526 : 0 : continue;
2527 : :
2528 : : // There is not need to compare if the first RefVertex is
2529 : : // dactivated.
2530 [ + - ][ - + ]: 716 : if( refvertex_ptr->deactivated() == CUBIT_TRUE )
2531 : 0 : continue ;
2532 : :
2533 [ + - ]: 716 : DLIList<RefVertex*> close_verts;
2534 [ + - ][ + - ]: 716 : a_tree.find(refvertex_ptr->bounding_box(), close_verts);
[ + - ]
2535 : :
2536 [ + - ][ + + ]: 1848 : for( j = 0; (j < close_verts.size()) && !AppUtil::instance()->interrupt(); j++ )
[ + - ][ + - ]
[ + - ][ + + ]
2537 : : {
2538 [ + - ]: 1132 : compare_refvertex_ptr = close_verts.get_and_step();
2539 : :
2540 : : //skip vertices already handled
2541 [ + - ][ + - ]: 1132 : if( refvertex_array[ compare_refvertex_ptr->marked() ] == NULL )
[ - + ]
2542 : 1132 : continue;
2543 : :
2544 [ - + ]: 1132 : if( compare_refvertex_ptr == NULL )
2545 : 0 : continue;
2546 : :
2547 : : // Make sure we are not comparing the same entity
2548 : : // and that they are not deactivated.
2549 [ - + ][ # # ]: 1132 : if( ( refvertex_ptr == compare_refvertex_ptr ) ||
[ + - ]
2550 [ # # ]: 0 : ( compare_refvertex_ptr->deactivated() == CUBIT_TRUE ) )
2551 : 1132 : continue;
2552 : :
2553 : : // IMPORTANT: this compare is for merging, so we set the
2554 : : // last parameter to CUBIT_TRUE so that the
2555 : : // compare sets the TDCompare data which will
2556 : : // be used in the RefEntity compare and merge.
2557 : : // By Jihong
2558 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
2559 : : CubitBoolean status =
2560 : : refvertex_ptr->about_spatially_equal( compare_refvertex_ptr,
2561 : : geom_factor,
2562 [ # # ]: 0 : CUBIT_TRUE );
2563 [ # # ]: 0 : if( status == CUBIT_FALSE )
2564 : 0 : continue;
2565 : :
2566 : : /* //refuse to merge free edges
2567 : : if( refvertex_ptr->ref_edge() == NULL )
2568 : : {
2569 : : PRINT_WARNING("Merging of free vertices prohibited: Vertex %d\n", refvertex_ptr->id() );
2570 : : continue;
2571 : : }
2572 : :
2573 : : if( compare_refvertex_ptr->ref_edge() == NULL )
2574 : : {
2575 : : PRINT_WARNING("Merging of free vertices prohibited: Vertex %d\n", compare_refvertex_ptr->id() );
2576 : : continue;
2577 : : } */
2578 : :
2579 : : //Make sure we arn't merging two vertices in the same volume.
2580 [ # # ][ # # ]: 0 : DLIList<RefVolume*> vols_1, vols_2;
[ # # ]
[ # # # ]
2581 [ # # ]: 0 : refvertex_ptr->ref_volumes(vols_1);
2582 [ # # ]: 0 : compare_refvertex_ptr->ref_volumes(vols_2);
2583 [ # # ]: 0 : vols_2.intersect( vols_1 );
2584 [ # # ][ # # ]: 0 : if( vols_2.size() > 0 )
2585 : : {
2586 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Tolerance problems, trying to merge"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2587 : : " vertices\non the same volume.\n"
2588 : : "%s (vertex %d) and %s (vertex %d) on\n"
2589 : : "%s (volume %d)\n",
2590 : : refvertex_ptr->entity_name().c_str(),
2591 : : refvertex_ptr->id(),
2592 : : compare_refvertex_ptr->entity_name().c_str(),
2593 : : compare_refvertex_ptr->id(),
2594 : : vols_2.get()->entity_name().c_str(),
2595 [ # # ]: 0 : vols_2.get()->id() );
2596 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Try changing the merge tolerance.\n" );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2597 : 0 : continue;
2598 : : }
2599 : :
2600 : : // Always retain the entity with the lowest id.
2601 [ # # ]: 0 : int nullify = compare_refvertex_ptr->marked();
2602 [ # # ][ # # ]: 0 : if( refvertex_ptr->id() > compare_refvertex_ptr->id() )
[ # # ]
2603 : : {
2604 [ # # ]: 0 : std::swap(refvertex_ptr, compare_refvertex_ptr);
2605 : 0 : nullify = i;
2606 : : }
2607 : :
2608 : : // Now check if merge is okay with all assistants.
2609 : 0 : CubitBoolean assistant_says_no = CUBIT_FALSE;
2610 [ # # ][ # # ]: 0 : for( int k = assistant_list_.size(); k > 0; k-- )
2611 : : {
2612 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
2613 [ # # ]: 0 : ->can_merge( refvertex_ptr, compare_refvertex_ptr ) )
2614 : : {
2615 : 0 : assistant_says_no = CUBIT_TRUE;
2616 : 0 : break;
2617 : : }
2618 : : }
2619 [ # # ]: 0 : if( assistant_says_no )
2620 : 0 : continue;
2621 : :
2622 : : // Need to retain these so that the pointers are not
2623 : : // accessed after a merge operation when the 'deleted'
2624 : : // pointer may be invalid.
2625 [ # # ]: 0 : int retained_id = refvertex_ptr->id();
2626 [ # # ]: 0 : int deleted_id = compare_refvertex_ptr->id();
2627 [ # # ]: 0 : if (groupResults)
2628 : : {
2629 [ # # ]: 0 : vertices_merged.append(refvertex_ptr);
2630 : : }
2631 : :
2632 [ # # ]: 0 : a_tree.remove( compare_refvertex_ptr );
2633 [ # # ][ # # ]: 0 : if( merge_BTE( refvertex_ptr, compare_refvertex_ptr ) )
2634 : : {
2635 : 0 : merge_count++;
2636 [ # # ][ # # ]: 0 : if(print_info && !progress)
2637 [ # # ][ # # ]: 0 : PRINT_INFO( "Vertex %d and %d consolidated\n",
[ # # ]
2638 [ # # ]: 0 : retained_id, deleted_id);
2639 : :
2640 : : // The 'deleted' RefVertex is now gone. It is an
2641 : : // error to access that pointer, so we need to
2642 : : // get it out of the list.
2643 [ # # ]: 0 : refvertex_array[nullify] = NULL;
2644 : : }
2645 : : else
2646 : : {
2647 [ # # ][ # # ]: 0 : PRINT_ERROR("Failed to merge Vertex %d and %d\n",
[ # # ]
2648 [ # # ]: 0 : retained_id, deleted_id );
2649 [ # # ][ # # ]: 0 : PRINT_INFO("Check for sliver geometry in the vicinity\n");
[ # # ][ # # ]
2650 [ # # ]: 0 : a_tree.add( compare_refvertex_ptr );
2651 : : }
2652 [ # # ]: 0 : if( nullify == i )
2653 [ # # ]: 0 : break;
[ # # # ]
2654 : 0 : }
2655 [ + - ]: 716 : }
2656 : :
2657 : : //clean the marks.
2658 [ + + ]: 737 : for( i = 0; i < array_size; i++ )
2659 : : {
2660 [ + - ][ + - ]: 716 : if ( refvertex_array[i] != NULL )
2661 [ + - ][ + - ]: 716 : refvertex_array[i]->marked(0);
2662 : : }
2663 : :
2664 : : // Remove the crud that accumulated during the merge
2665 : : // operations, from the geometry database.
2666 [ + - ][ + - ]: 21 : PRINT_DEBUG_3( "Merge RefVertexs time: %f secs\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
2667 [ # # ]: 0 : timer.cpu_secs() );
2668 : :
2669 [ + - ][ + - ]: 21 : PRINT_DEBUG_19( "Cleaning out TDCompare data from RefVertices...\n");
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
2670 [ + - ]: 21 : complete_merge();
2671 [ - + ]: 21 : if(progress)
2672 [ # # ]: 0 : progress->end();
2673 : :
2674 [ - + ][ # # ]: 21 : if ( groupResults && vertices_merged.size() )
[ # # ][ - + ]
2675 : : {
2676 [ # # ]: 0 : DLIList<RefEntity*> refentity_list;
2677 : : RefVertex *tmp_vertex;
2678 [ # # ][ # # ]: 0 : for (int iii = vertices_merged.size(); iii > 0; iii-- )
2679 : : {
2680 [ # # ]: 0 : tmp_vertex = vertices_merged.get_and_step();
2681 [ # # ][ # # ]: 0 : if ( !tmp_vertex->deactivated() )
2682 [ # # ][ # # ]: 0 : refentity_list.append(tmp_vertex);
2683 : : }
2684 [ # # ][ # # ]: 0 : RefGroup *new_group = RefEntityFactory::instance()->construct_RefGroup("gr_verts_merged");
2685 [ # # ]: 0 : new_group->add_ref_entity( refentity_list );
2686 [ # # ][ # # ]: 0 : if (print_info) PRINT_INFO("Created new group %s (Group %d)\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2687 : : " Group contains curves that were seperatly merged during\n"
2688 : : " current merge operation (ie, not during surface merge)\n",
2689 : : new_group->entity_name().c_str(),
2690 [ # # ]: 0 : new_group->id());
2691 [ # # ]: 0 : lastVertsMerged = new_group;
2692 : : }
2693 : : //set this to null otherwise.
2694 : : else
2695 : 21 : lastVertsMerged = NULL;
2696 : :
2697 [ + - ]: 21 : if( destroyDeadGeometry )
2698 [ + - ][ + - ]: 21 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
2699 [ + - ][ + - ]: 21 : PRINT_DEBUG_3( "cleanout time: %f secs\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
2700 [ # # ]: 0 : timer.cpu_secs() );
2701 : :
2702 [ - + ][ # # ]: 21 : if (print_info) PRINT_INFO( "Consolidated %d pairs of vertices\n", merge_count );
[ # # ][ # # ]
[ # # ]
2703 [ + - ][ + - ]: 21 : if( AppUtil::instance()->interrupt() )
[ - + ]
2704 : : {
2705 [ # # ][ # # ]: 0 : PRINT_WARNING("Vertex merging aborted.\n");
[ # # ][ # # ]
2706 : 0 : return CUBIT_FAILURE;
2707 : : }
2708 [ + - ]: 74 : return CUBIT_SUCCESS;
2709 : : }
2710 : :
2711 : : //----------------------------------------------------------------
2712 : : // Purpose : merge all items in the RefVertex list if
2713 : : // they can be merged.
2714 : : //
2715 : : // Special Notes :
2716 : : //
2717 : : // Creator : Jihong Ma
2718 : : //
2719 : : // Creation Date : 11/27/96
2720 : : //----------------------------------------------------------------
2721 : 32 : CubitStatus MergeTool::old_merge_refvertices( DLIList<RefVertex*>& refvertex_list,
2722 : : CubitBoolean print_info)
2723 : : {
2724 : : // The basic algorithm is to step through the input list,
2725 : : // compare every entity with every other entity, and
2726 : : // merge the entities that are spatially equivalent.
2727 : : // In the merge, the entity with the lowest ID is retained.
2728 : : // NOTE: RefVertices can participate in multiple merges.
2729 : :
2730 [ + - ]: 32 : CpuTimer timer;
2731 : 32 : int merge_count = 0;
2732 : :
2733 [ + - ][ + - ]: 32 : DLIList<RefVertex*> refvertex_array( refvertex_list.size() );
2734 [ + - ]: 32 : refvertex_list.reset();
2735 : :
2736 : : // Remove entities that should not be automatically merged
2737 : 32 : int i = 0;
2738 [ + - ][ + + ]: 456 : for( i = refvertex_list.size(); i > 0; i-- )
2739 : : {
2740 [ + - ]: 424 : RefVertex *curr_vert = refvertex_list.get_and_step();
2741 [ + - ][ + - ]: 424 : if( curr_vert->is_mergeable() )
2742 [ + - ]: 424 : refvertex_array.append( curr_vert );
2743 : : }
2744 [ + - ][ + - ]: 64 : DLIList<RefVertex*> vertices_merged;
2745 : :
2746 : 32 : ProgressTool* progress = 0;
2747 : : // if( displayProgress )
2748 : : // {
2749 : : // progress = AppUtil::instance()->progress_tool();
2750 : : // if (progress)
2751 : : // {
2752 : : // progress->start( 0, refvertex_array.size(),
2753 : : // "Comparing Vertices:", 0, CUBIT_TRUE, CUBIT_TRUE );
2754 : : // }
2755 : : // }
2756 : :
2757 : : // Now find overlapping RefVertices and merge them.
2758 : : // Make sure that the operation is not performed on
2759 : : // RefVertices that are deactivated.
2760 : 32 : int j = 0;
2761 : 32 : RefVertex* refvertex_ptr = NULL;
2762 : 32 : RefVertex* compare_refvertex_ptr = NULL;
2763 [ + - ]: 32 : int array_size = refvertex_array.size();
2764 [ + + ][ + - ]: 456 : for( i = 0; (i < array_size) && !AppUtil::instance()->interrupt(); i++ )
[ + - ][ + - ]
[ + + ]
2765 : : {
2766 [ - + ][ # # ]: 424 : if( progress ) progress->step();
2767 : :
2768 [ + - ]: 424 : refvertex_ptr = refvertex_array[i];
2769 [ - + ]: 424 : if( refvertex_ptr == NULL )
2770 : 0 : continue;
2771 : :
2772 : : // There is not need to compare if the first RefVertex is
2773 : : // dactivated.
2774 [ + - ][ - + ]: 424 : if( refvertex_ptr->deactivated() == CUBIT_TRUE )
2775 : 0 : continue ;
2776 : :
2777 : : // // Get the GeometryQueryEngine of the Refedges
2778 : : // // Try to merge this RefVertex only if it is associated
2779 : : // // with a SolidModelingEngine.
2780 : : // GeometryQueryEngine* firstGMEPtr =
2781 : : // refvertex_ptr->get_geometry_query_engine();
2782 : : // SolidModelingEngine* SMEPtr = CAST_TO( firstGMEPtr, SolidModelingEngine );
2783 : :
2784 : : // // If the RefVertex is not associated with a
2785 : : // // SolidModelingEngine, go on to the next RefVertex.
2786 : : // if( SMEPtr == NULL )
2787 : : // continue ;
2788 : :
2789 [ + + ][ + - ]: 3076 : for( j = i+1; (j < array_size) && !AppUtil::instance()->interrupt(); j++ )
[ + - ][ + - ]
[ + + ]
2790 : : {
2791 [ + - ]: 2652 : compare_refvertex_ptr = refvertex_array[j];
2792 [ - + ]: 2652 : if( compare_refvertex_ptr == NULL )
2793 : 2652 : continue;
2794 : :
2795 : : // Make sure we are not comparing the same entity
2796 : : // and that they are not deactivated.
2797 [ + + ][ - + ]: 5264 : if( ( refvertex_ptr == compare_refvertex_ptr ) ||
[ + + ]
2798 [ + - ]: 2612 : ( compare_refvertex_ptr->deactivated() == CUBIT_TRUE ) )
2799 : 40 : continue;
2800 : :
2801 : : // // Get the GeometryQueryEngine of the second
2802 : : // // RefVertex. Make sure that both engines are same
2803 : : // // before proceeding with the merge.
2804 : : // GeometryQueryEngine* secondGMEPtr =
2805 : : // compare_refvertex_ptr->get_geometry_query_engine() ;
2806 : :
2807 : : // // If the two engines are different, move on to the
2808 : : // // next RefVertex.
2809 : : // if( firstGMEPtr != secondGMEPtr )
2810 : : // continue ;
2811 : :
2812 : : // IMPORTANT: this compare is for merging, so we set the
2813 : : // last parameter to CUBIT_TRUE so that the
2814 : : // compare sets the TDCompare data which will
2815 : : // be used in the RefEntity compare and merge.
2816 : : // By Jihong
2817 [ + - ]: 2612 : double geom_factor = GeometryQueryTool::get_geometry_factor();
2818 : : CubitBoolean status =
2819 : : refvertex_ptr->about_spatially_equal( compare_refvertex_ptr,
2820 : : geom_factor,
2821 [ + - ]: 2612 : CUBIT_TRUE );
2822 [ + - ]: 2612 : if( status == CUBIT_FALSE )
2823 : 2612 : continue;
2824 : : /*
2825 : : //refuse to merge free edges
2826 : : if( refvertex_ptr->ref_edge() == NULL )
2827 : : {
2828 : : PRINT_WARNING("Merging of free vertices prohibited: Vertex %d\n", refvertex_ptr->id() );
2829 : : continue;
2830 : : }
2831 : :
2832 : : if( compare_refvertex_ptr->ref_edge() == NULL )
2833 : : {
2834 : : PRINT_WARNING("Merging of free vertices prohibited: Vertex %d\n", compare_refvertex_ptr->id() );
2835 : : continue;
2836 : : }
2837 : : */
2838 : : //Make sure we arn't merging two vertices on a that are in the same volume.
2839 [ # # ][ # # ]: 0 : DLIList<RefVolume*> vols_1, vols_2;
[ # # ]
[ # # # ]
2840 [ # # ]: 0 : refvertex_ptr->ref_volumes(vols_1);
2841 [ # # ]: 0 : compare_refvertex_ptr->ref_volumes(vols_2);
2842 [ # # ]: 0 : vols_2.intersect( vols_1 );
2843 [ # # ][ # # ]: 0 : if( vols_2.size() > 0 )
2844 : : {
2845 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Tolerance problems, trying to merge"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2846 : : " vertices\non the same volume.\n"
2847 : : "%s (vertex %d) and %s (vertex %d) on\n"
2848 : : "%s (volume %d)\n",
2849 : : refvertex_ptr->entity_name().c_str(),
2850 : : refvertex_ptr->id(),
2851 : : compare_refvertex_ptr->entity_name().c_str(),
2852 : : compare_refvertex_ptr->id(),
2853 : : vols_2.get()->entity_name().c_str(),
2854 [ # # ]: 0 : vols_2.get()->id() );
2855 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "Try changing the merge tolerance.\n" );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2856 : 0 : continue;
2857 : : }
2858 : :
2859 : : // Always retain the entity with the lowest id.
2860 : 0 : int nullify = j;
2861 [ # # ][ # # ]: 0 : if( refvertex_ptr->id() > compare_refvertex_ptr->id() )
[ # # ]
2862 : : {
2863 [ # # ]: 0 : std::swap(refvertex_ptr, compare_refvertex_ptr);
2864 : 0 : nullify = i;
2865 : : }
2866 : :
2867 : : // Now check if merge is okay with all assistants.
2868 : 0 : CubitBoolean assistant_says_no = CUBIT_FALSE;
2869 [ # # ][ # # ]: 0 : for( int k = assistant_list_.size(); k > 0; k-- )
2870 : : {
2871 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()
2872 [ # # ]: 0 : ->can_merge( refvertex_ptr, compare_refvertex_ptr ) )
2873 : : {
2874 : 0 : assistant_says_no = CUBIT_TRUE;
2875 : 0 : break;
2876 : : }
2877 : : }
2878 [ # # ]: 0 : if( assistant_says_no )
2879 : 0 : continue;
2880 : :
2881 : : // Need to retain these so that the pointers are not
2882 : : // accessed after a merge operation when the 'deleted'
2883 : : // pointer may be invalid.
2884 [ # # ]: 0 : int retained_id = refvertex_ptr->id();
2885 [ # # ]: 0 : int deleted_id = compare_refvertex_ptr->id();
2886 [ # # ]: 0 : if (groupResults)
2887 : : {
2888 [ # # ]: 0 : vertices_merged.append(refvertex_ptr);
2889 : : }
2890 [ # # ][ # # ]: 0 : if( merge_BTE( refvertex_ptr, compare_refvertex_ptr ) )
2891 : : {
2892 : 0 : merge_count++;
2893 [ # # ][ # # ]: 0 : if (print_info && !progress)
2894 : : {
2895 [ # # ][ # # ]: 0 : PRINT_INFO("Failed to merge Vertex %d and %d\n",
[ # # ]
2896 [ # # ]: 0 : retained_id, deleted_id);
2897 [ # # ][ # # ]: 0 : PRINT_INFO("Check for sliver geometry in the vicinity\n");
[ # # ][ # # ]
2898 : : }
2899 : :
2900 : : // The 'deleted' RefVertex is now gone. It is an
2901 : : // error to access that pointer, so we need to
2902 : : // get it out of the list.
2903 [ # # ]: 0 : refvertex_array[nullify] = NULL;
2904 : : }
2905 : : else
2906 : : {
2907 [ # # ][ # # ]: 0 : PRINT_ERROR("Failed to merge Vertex %d and %d\n",
[ # # ]
2908 [ # # ]: 0 : retained_id, deleted_id );
2909 : : }
2910 : :
2911 [ # # ]: 0 : if( nullify == i )
2912 [ # # ]: 0 : break;
[ # # # ]
2913 : 0 : }
2914 : : }
2915 : :
2916 : : // Remove the crud that accumulated during the merge
2917 : : // operations, from the geometry database.
2918 [ + - ][ + - ]: 32 : PRINT_DEBUG_3( "Merge RefVertexs time: %f secs\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
2919 [ # # ]: 0 : timer.cpu_secs() );
2920 : :
2921 [ + - ][ + - ]: 32 : PRINT_DEBUG_19(
[ - + ][ # # ]
[ # # ][ # # ]
2922 [ # # ]: 0 : "Cleaning out TDCompare data from RefVertices...\n");
2923 [ + - ]: 32 : complete_merge();
2924 [ - + ]: 32 : if (progress)
2925 [ # # ]: 0 : progress->end();
2926 [ - + ][ # # ]: 32 : if ( groupResults && vertices_merged.size() )
[ # # ][ - + ]
2927 : : {
2928 [ # # ]: 0 : DLIList<RefEntity*> refentity_list;
2929 : : RefVertex *tmp_vertex;
2930 [ # # ][ # # ]: 0 : for (int iii = vertices_merged.size(); iii > 0; iii-- )
2931 : : {
2932 [ # # ]: 0 : tmp_vertex = vertices_merged.get_and_step();
2933 [ # # ][ # # ]: 0 : if ( !tmp_vertex->deactivated() )
2934 [ # # ][ # # ]: 0 : refentity_list.append(tmp_vertex);
2935 : : }
2936 [ # # ][ # # ]: 0 : RefGroup *new_group = RefEntityFactory::instance()->construct_RefGroup("gr_verts_merged");
2937 [ # # ]: 0 : new_group->add_ref_entity( refentity_list );
2938 [ # # ][ # # ]: 0 : if (print_info) PRINT_INFO("Created new group %s (Group %d)\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2939 : : " Group contains curves that were seperatly merged during\n"
2940 : : " current merge operation (ie, not during surface merge)\n",
2941 : : new_group->entity_name().c_str(),
2942 [ # # ]: 0 : new_group->id());
2943 [ # # ]: 0 : lastVertsMerged = new_group;
2944 : : }
2945 : : //set this to null otherwise.
2946 : : else
2947 : 32 : lastVertsMerged = NULL;
2948 : :
2949 [ + - ]: 32 : if( destroyDeadGeometry )
2950 [ + - ][ + - ]: 32 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
2951 [ + - ][ + - ]: 32 : PRINT_DEBUG_3( "cleanout time: %f secs\n",
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ]
2952 [ # # ]: 0 : timer.cpu_secs() );
2953 : :
2954 [ + + ]: 32 : if(print_info)
2955 [ + - ][ + - ]: 22 : PRINT_INFO( "Consolidated %d pairs of vertices\n", merge_count );
[ + - ][ + - ]
2956 : :
2957 [ + - ][ + - ]: 32 : if( AppUtil::instance()->interrupt() )
[ - + ]
2958 : : {
2959 [ # # ][ # # ]: 0 : PRINT_WARNING("Vertex merging aborted.\n");
[ # # ][ # # ]
2960 : 0 : return CUBIT_FAILURE;
2961 : : }
2962 [ + - ]: 64 : return CUBIT_SUCCESS;
2963 : : }
2964 : :
2965 : :
2966 : : //-------------------------------------------------------------------------
2967 : : // Purpose : Unmerge everything
2968 : : //
2969 : : // Special Notes :
2970 : : //
2971 : : // Creator : Jason Kraftcheck
2972 : : //
2973 : : // Creation Date : 03/27/01
2974 : : //-------------------------------------------------------------------------
2975 : 0 : CubitStatus MergeTool::unmerge_all()
2976 : : {
2977 : : int i;
2978 : 0 : CubitStatus result = CUBIT_SUCCESS;
2979 [ # # ]: 0 : CubitBoolean top = start_unmerge();
2980 : :
2981 : :
2982 [ # # ]: 0 : DLIList<RefFace*> face_list;
2983 [ # # ][ # # ]: 0 : DLIList<RefEdge*> edge_list;
2984 [ # # ][ # # ]: 0 : DLIList<RefVertex*> vtx_list;
2985 : :
2986 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->ref_faces( face_list );
2987 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->ref_edges( edge_list );
2988 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->ref_vertices( vtx_list );
2989 : :
2990 [ # # ][ # # ]: 0 : for( i = face_list.size(); (i > 0) && !AppUtil::instance()->interrupt(); i-- )
[ # # ][ # # ]
[ # # ][ # # ]
2991 [ # # ][ # # ]: 0 : if( ! unmerge(face_list.get_and_step(),CUBIT_FALSE) )
[ # # ]
2992 : 0 : result = CUBIT_FAILURE;
2993 : :
2994 [ # # ][ # # ]: 0 : for( i = edge_list.size(); (i > 0) && !AppUtil::instance()->interrupt(); i-- )
[ # # ][ # # ]
[ # # ][ # # ]
2995 [ # # ][ # # ]: 0 : if( ! unmerge(edge_list.get_and_step(),CUBIT_FALSE) )
[ # # ]
2996 : 0 : result = CUBIT_FAILURE;
2997 : :
2998 [ # # ][ # # ]: 0 : for( i = vtx_list.size(); (i > 0) && !AppUtil::instance()->interrupt(); i-- )
[ # # ][ # # ]
[ # # ][ # # ]
2999 [ # # ][ # # ]: 0 : if( ! unmerge(vtx_list.get_and_step()) )
[ # # ]
3000 : 0 : result = CUBIT_FAILURE;
3001 : :
3002 [ # # ]: 0 : end_unmerge(top);
3003 : :
3004 [ # # ]: 0 : return result;
3005 : : }
3006 : :
3007 : :
3008 : : //-------------------------------------------------------------------------
3009 : : // Purpose : Unmerge RefEntities
3010 : : //
3011 : : // Special Notes :
3012 : : //
3013 : : // Creator : Jason Kraftcheck
3014 : : //
3015 : : // Creation Date : 01/18/01
3016 : : //-------------------------------------------------------------------------
3017 : 0 : CubitStatus MergeTool::unmerge( DLIList<RefEntity*> &entity_list,
3018 : : CubitBoolean descend )
3019 : : {
3020 : 0 : CubitBoolean top = start_unmerge();
3021 : :
3022 [ # # ][ # # ]: 0 : for( int i = entity_list.size(); (i > 0) && !AppUtil::instance()->interrupt(); i-- )
[ # # ]
3023 : 0 : unmerge( entity_list.get_and_step(), descend );
3024 : :
3025 : 0 : end_unmerge(top);
3026 : 0 : return CUBIT_SUCCESS;
3027 : : }
3028 : :
3029 : : //-------------------------------------------------------------------------
3030 : : // Purpose : Unmerge a RefEntity
3031 : : //
3032 : : // Special Notes : All parents must be unmerged.
3033 : : //
3034 : : // Creator : Jason Kraftcheck
3035 : : //
3036 : : // Creation Date : 01/18/01
3037 : : //-------------------------------------------------------------------------
3038 : 0 : CubitStatus MergeTool::unmerge( RefEntity* entity_ptr, CubitBoolean descend )
3039 : : {
3040 [ # # ][ # # ]: 0 : if( CAST_TO( entity_ptr, Body ) )
[ # # ]
3041 [ # # ][ # # ]: 0 : return descend ? unmerge(CAST_TO(entity_ptr,Body)) : CUBIT_FAILURE;
3042 [ # # ][ # # ]: 0 : else if( CAST_TO( entity_ptr, RefVolume ) )
[ # # ]
3043 [ # # ][ # # ]: 0 : return descend ? unmerge(CAST_TO(entity_ptr,RefVolume)) : CUBIT_FAILURE;
3044 [ # # ][ # # ]: 0 : else if( CAST_TO( entity_ptr, RefFace ) )
[ # # ]
3045 [ # # ]: 0 : return unmerge( CAST_TO(entity_ptr,RefFace), descend );
3046 [ # # ][ # # ]: 0 : else if( CAST_TO( entity_ptr, RefEdge ) )
[ # # ]
3047 [ # # ]: 0 : return unmerge( CAST_TO(entity_ptr,RefEdge), descend );
3048 [ # # ][ # # ]: 0 : else if( CAST_TO( entity_ptr, RefVertex ) )
[ # # ]
3049 [ # # ]: 0 : return unmerge( CAST_TO(entity_ptr,RefVertex) );
3050 : : else
3051 : : {
3052 [ # # ]: 0 : PRINT_ERROR("Bad Entity \"%s\" in "
3053 : : "MergeTool::unmerge(RefEntity*,CubitBoolean)\n",
3054 [ # # ]: 0 : entity_ptr->class_name());
3055 : 0 : return CUBIT_FAILURE;
3056 : : }
3057 : : }
3058 : :
3059 : : //-------------------------------------------------------------------------
3060 : : // Purpose : Unmerge
3061 : : //
3062 : : // Special Notes :
3063 : : //
3064 : : // Creator : Jason Kraftcheck
3065 : : //
3066 : : // Creation Date : 06/01/04
3067 : : //-------------------------------------------------------------------------
3068 : 0 : CubitStatus MergeTool::unmerge( Body* body_ptr )
3069 : : {
3070 [ # # ]: 0 : DLIList<Body*> list(1);
3071 [ # # ]: 0 : list.append( body_ptr );
3072 [ # # ][ # # ]: 0 : return separate_bodies( list );
3073 : : }
3074 : :
3075 : : //-------------------------------------------------------------------------
3076 : : // Purpose : Unmerge
3077 : : //
3078 : : // Special Notes :
3079 : : //
3080 : : // Creator : Jason Kraftcheck
3081 : : //
3082 : : // Creation Date : 06/01/04
3083 : : //-------------------------------------------------------------------------
3084 : 0 : CubitStatus MergeTool::unmerge( RefVolume* vol_ptr )
3085 : : {
3086 [ # # ]: 0 : DLIList<RefVolume*> list(1);
3087 [ # # ]: 0 : list.append( vol_ptr );
3088 [ # # ][ # # ]: 0 : return separate_volumes( list );
3089 : : }
3090 : :
3091 : : //-------------------------------------------------------------------------
3092 : : // Purpose : Unmerge
3093 : : //
3094 : : // Special Notes :
3095 : : //
3096 : : // Creator : Jason Kraftcheck
3097 : : //
3098 : : // Creation Date : 06/01/04
3099 : : //-------------------------------------------------------------------------
3100 : 0 : CubitStatus MergeTool::unmerge( RefFace* face_ptr, CubitBoolean descend,
3101 : : DLIList<RefFace*> *new_faces)
3102 : : {
3103 [ # # ]: 0 : CubitBoolean top = start_unmerge();
3104 : 0 : CubitStatus result = CUBIT_SUCCESS;
3105 : : int i;
3106 : :
3107 [ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
3108 [ # # ][ # # ]: 0 : face_ptr->bridge_manager()->get_bridge_list(bridge_list);
3109 [ # # ][ # # ]: 0 : if (bridge_list.size() < 2)
3110 : 0 : return CUBIT_SUCCESS;
3111 : :
3112 [ # # ][ # # ]: 0 : DLIList<Surface*> surf_list;
3113 [ # # ]: 0 : bridge_list.reset();
3114 [ # # ][ # # ]: 0 : for (i = bridge_list.size(); i > 1; i--)
3115 : : {
3116 [ # # ][ # # ]: 0 : Surface* surf = dynamic_cast<Surface*>(bridge_list.step_and_get());
3117 [ # # ]: 0 : surf_list.clean_out();
3118 [ # # ]: 0 : surf_list.append( surf );
3119 [ # # ]: 0 : RefFace *new_face = separate_face( surf_list, descend );
3120 : :
3121 [ # # ]: 0 : if (0 == new_face)
3122 : : {
3123 : 0 : result = CUBIT_FAILURE;
3124 : 0 : break;
3125 : : }
3126 : : else
3127 : : {
3128 [ # # ]: 0 : if(new_faces)
3129 [ # # ]: 0 : new_faces->append(new_face);
3130 : : }
3131 : : }
3132 : :
3133 [ # # ]: 0 : end_unmerge(top);
3134 [ # # ]: 0 : return result;
3135 : : }
3136 : :
3137 : :
3138 : : //-------------------------------------------------------------------------
3139 : : // Purpose : Unmerge
3140 : : //
3141 : : // Special Notes :
3142 : : //
3143 : : // Creator : Jason Kraftcheck
3144 : : //
3145 : : // Creation Date : 06/01/04
3146 : : //-------------------------------------------------------------------------
3147 : 0 : CubitStatus MergeTool::unmerge( RefEdge* edge_ptr, CubitBoolean descend,
3148 : : DLIList<RefEdge*> *new_curves)
3149 : : {
3150 [ # # ]: 0 : CubitBoolean top = start_unmerge();
3151 : 0 : CubitStatus result = CUBIT_SUCCESS;
3152 : : int i;
3153 : :
3154 [ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
3155 [ # # ][ # # ]: 0 : edge_ptr->bridge_manager()->get_bridge_list(bridge_list);
3156 [ # # ][ # # ]: 0 : if (bridge_list.size() < 2)
3157 : 0 : return CUBIT_SUCCESS;
3158 : :
3159 [ # # ][ # # ]: 0 : DLIList<Curve*> curve_list;
3160 [ # # ]: 0 : bridge_list.reset();
3161 [ # # ][ # # ]: 0 : for (i = bridge_list.size(); i > 1; i--)
3162 : : {
3163 [ # # ][ # # ]: 0 : Curve* curve = dynamic_cast<Curve*>(bridge_list.step_and_get());
3164 [ # # ]: 0 : curve_list.clean_out();
3165 [ # # ]: 0 : curve_list.append( curve );
3166 [ # # ]: 0 : RefEdge *new_curve = separate_edge( curve_list, descend );
3167 [ # # ]: 0 : if (0 == new_curve)
3168 : : {
3169 : 0 : result = CUBIT_FAILURE;
3170 : 0 : break;
3171 : : }
3172 : : else
3173 : : {
3174 [ # # ]: 0 : if(new_curves)
3175 [ # # ]: 0 : new_curves->append(new_curve);
3176 : : }
3177 : : }
3178 : :
3179 [ # # ]: 0 : end_unmerge(top);
3180 [ # # ]: 0 : return result;
3181 : : }
3182 : :
3183 : :
3184 : : //-------------------------------------------------------------------------
3185 : : // Purpose : Unmerge
3186 : : //
3187 : : // Special Notes :
3188 : : //
3189 : : // Creator : Jason Kraftcheck
3190 : : //
3191 : : // Creation Date : 06/01/04
3192 : : //-------------------------------------------------------------------------
3193 : 0 : CubitStatus MergeTool::unmerge( RefVertex* vtx_ptr, DLIList<RefVertex*> *new_verts )
3194 : : {
3195 [ # # ]: 0 : CubitBoolean top = start_unmerge();
3196 : 0 : CubitStatus result = CUBIT_SUCCESS;
3197 : : int i;
3198 : :
3199 [ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
3200 [ # # ][ # # ]: 0 : vtx_ptr->bridge_manager()->get_bridge_list(bridge_list);
3201 [ # # ][ # # ]: 0 : if (bridge_list.size() < 2)
3202 : 0 : return CUBIT_SUCCESS;
3203 : :
3204 [ # # ][ # # ]: 0 : DLIList<TBPoint*> point_list;
3205 [ # # ]: 0 : bridge_list.reset();
3206 [ # # ][ # # ]: 0 : for (i = bridge_list.size(); i > 1; i--)
3207 : : {
3208 [ # # ][ # # ]: 0 : TBPoint* point = dynamic_cast<TBPoint*>(bridge_list.step_and_get());
3209 [ # # ]: 0 : point_list.clean_out();
3210 [ # # ]: 0 : point_list.append( point );
3211 [ # # ]: 0 : RefVertex *new_vert = separate_vertex( point_list );
3212 [ # # ]: 0 : if(0 == new_vert)
3213 : : {
3214 : 0 : result = CUBIT_FAILURE;
3215 : 0 : break;
3216 : : }
3217 : : else
3218 : : {
3219 [ # # ]: 0 : if(new_verts)
3220 [ # # ]: 0 : new_verts->append(new_vert);
3221 : : }
3222 : : }
3223 : :
3224 [ # # ]: 0 : end_unmerge(top);
3225 [ # # ]: 0 : return result;
3226 : : }
3227 : :
3228 : :
3229 : :
3230 : :
3231 : :
3232 : : //-------------------------------------------------------------------------
3233 : : // Purpose : Handle sending various events as a result of unmerging.
3234 : : //
3235 : : // Special Notes :
3236 : : //
3237 : : // Creator : Jason Kraftcheck
3238 : : //
3239 : : // Creation Date : 01/18/01
3240 : : //-------------------------------------------------------------------------
3241 : 0 : void MergeTool::cleanup_unmerge()
3242 : : {
3243 [ # # ][ # # ]: 0 : std::set<CubitObservable*> modified_list, new_list;
[ # # ]
3244 : : int i;
3245 : : // CpuTimer timer;
3246 : 0 : int vtx_count = 0, curve_count = 0, surf_count = 0;
3247 : :
3248 [ # # ][ # # ]: 0 : DLIList<RefEntity*> parents;
3249 [ # # ][ # # ]: 0 : assert( new_unmerged.size() == old_unmerged.size() );
[ # # ]
3250 [ # # ]: 0 : new_unmerged.reset();
3251 [ # # ]: 0 : old_unmerged.reset();
3252 [ # # ][ # # ]: 0 : for (i = new_unmerged.size(); i--; )
3253 : : {
3254 [ # # ]: 0 : RefEntity* new_ptr = new_unmerged.get_and_step();
3255 [ # # ]: 0 : RefEntity* old_ptr = old_unmerged.get_and_step();
3256 [ # # ][ # # ]: 0 : if (dynamic_cast<RefVertex*>(new_ptr))
[ # # ]
3257 : 0 : vtx_count++;
3258 [ # # ][ # # ]: 0 : else if(dynamic_cast<RefEdge*>(new_ptr))
[ # # ]
3259 : 0 : curve_count++;
3260 [ # # ][ # # ]: 0 : if (dynamic_cast<RefFace*>(new_ptr))
[ # # ]
3261 : 0 : surf_count++;
3262 : :
3263 : :
3264 [ # # ]: 0 : new_ptr->get_parent_ref_entities( parents );
3265 : :
3266 [ # # ][ # # ]: 0 : if (parents.size() == 0)
3267 : : {
3268 [ # # ][ # # ]: 0 : if (new_list.insert(new_ptr).second)
[ # # ]
3269 : : {
3270 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::FREE_REF_ENTITY_GENERATED, new_ptr));
[ # # ][ # # ]
3271 [ # # ]: 0 : CGMHistory::Event evt(CGMHistory::TOP_LEVEL_ENTITY_CREATED, new_ptr);
3272 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->history().add_event(evt);
[ # # ][ # # ]
3273 : : }
3274 : : }
3275 : :
3276 [ # # ][ # # ]: 0 : while (parents.size())
3277 [ # # ][ # # ]: 0 : modified_list.insert( parents.pop() );
[ # # ]
3278 : :
3279 [ # # ]: 0 : old_ptr->get_parent_ref_entities( parents );
3280 [ # # ][ # # ]: 0 : while (parents.size())
3281 [ # # ][ # # ]: 0 : modified_list.insert( parents.pop() );
[ # # ]
3282 [ # # ][ # # ]: 0 : modified_list.insert( old_ptr );
3283 : :
3284 [ # # ]: 0 : UnMergeEvent event( old_ptr, new_ptr );
3285 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event( event );
3286 [ # # ]: 0 : }
3287 : :
3288 [ # # ]: 0 : std::set<CubitObservable*>::iterator iter;
3289 [ # # ][ # # ]: 0 : for (iter = modified_list.begin(); iter != modified_list.end(); ++iter)
[ # # ][ # # ]
[ # # ]
3290 : : {
3291 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_MODIFIED, static_cast<RefEntity*>(*iter)));
[ # # ][ # # ]
[ # # ][ # # ]
3292 [ # # ][ # # ]: 0 : CGMHistory::Event evt(CGMHistory::TOPOLOGY_CHANGED, static_cast<RefEntity*>(*iter));
[ # # ]
3293 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->history().add_event(evt);
[ # # ]
3294 [ # # ]: 0 : }
3295 : :
3296 [ # # ][ # # ]: 0 : for( int a = assistant_list_.size(); a--; )
3297 [ # # ][ # # ]: 0 : assistant_list_.get_and_step()->finish_unmerge();
3298 : :
3299 [ # # ]: 0 : if (vtx_count)
3300 [ # # ][ # # ]: 0 : PRINT_INFO("Unmerged %d vertices.\n", vtx_count);
[ # # ][ # # ]
3301 [ # # ]: 0 : if (curve_count)
3302 [ # # ][ # # ]: 0 : PRINT_INFO("Unmerged %d curves.\n", curve_count);
[ # # ][ # # ]
3303 [ # # ]: 0 : if (surf_count)
3304 [ # # ][ # # ]: 0 : PRINT_INFO("Unmerged %d surfaces.\n", surf_count);
[ # # ][ # # ]
3305 [ # # ]: 0 : if (vtx_count + curve_count + surf_count == 0)
3306 [ # # ][ # # ]: 0 : PRINT_INFO("No entities unmerged.\n");
[ # # ][ # # ]
[ # # ]
3307 : 0 : }
3308 : :
3309 : :
3310 : :
3311 : 3194 : void MergeTool::compare_notify(RefEntity *entity)
3312 : : {
3313 : : //- notifies MergeTool about comparisons found and put on ref entities
3314 : 3194 : compareEntityList.append_unique(entity);
3315 : 3194 : }
3316 : :
3317 : 846 : CubitStatus MergeTool::merge_BTE( BasicTopologyEntity* keeper_entity,
3318 : : BasicTopologyEntity* dead_entity )
3319 : : {
3320 : 846 : CubitStatus result = CUBIT_FAILURE;
3321 [ + - ][ + - ]: 1692 : DLIList<TopologyEntity*> query_results, query_results_2;
[ + - ]
3322 : :
3323 : : // save to notify at end
3324 [ + - ][ + - ]: 1692 : DLIList<RefEntity*> dead_parents;
3325 [ + - ]: 846 : dead_entity->get_parent_ref_entities(dead_parents);
3326 : :
3327 : : // Make sure that the 2 BTE's are of the same type
3328 [ + - ][ + - ]: 846 : if( keeper_entity->dag_type() != dead_entity->dag_type() )
[ + - ][ - + ]
3329 : : {
3330 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_BTE(), \n"
[ # # ][ # # ]
[ # # ][ # # ]
3331 : : " two different types of entities "
3332 : : "are merged. \n"
3333 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n");
3334 : 0 : return CUBIT_FAILURE;
3335 : : }
3336 : :
3337 : : // Debug info
3338 [ + - ][ + - ]: 1692 : CubitString keeper_entity_name(""), dead_entity_name("");
[ + - ][ + - ]
3339 [ + - ][ + - ]: 846 : if (DEBUG_FLAG(19))
[ - + ]
3340 : : {
3341 [ # # ][ # # ]: 0 : keeper_entity_name = keeper_entity->entity_name();
[ # # ]
3342 [ # # ][ # # ]: 0 : dead_entity_name = dead_entity->entity_name();
[ # # ]
3343 : :
3344 [ # # ][ # # ]: 0 : PRINT_DEBUG_19("...In MergeTool::merge_BTE - "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
3345 : : "Merging %s and %s\n",
3346 : : keeper_entity_name.c_str(),
3347 [ # # ]: 0 : dead_entity_name.c_str() );
3348 : : }
3349 : :
3350 : : // Sanity Check: don't merge the entities if either of them
3351 : : // is already deactivated
3352 [ + - ][ - + ]: 846 : if( keeper_entity->deactivated() )
3353 : : {
3354 [ # # ][ # # ]: 0 : PRINT_ERROR( "%s has already been merged\n",
[ # # ][ # # ]
[ # # ][ # # ]
3355 [ # # ]: 0 : keeper_entity->entity_name().c_str() );
3356 : 0 : return CUBIT_FAILURE;
3357 : : }
3358 [ + - ][ - + ]: 846 : if( dead_entity->deactivated() )
3359 : : {
3360 [ # # ][ # # ]: 0 : PRINT_ERROR( "%s has already been merged\n",
[ # # ][ # # ]
[ # # ][ # # ]
3361 [ # # ]: 0 : dead_entity->entity_name().c_str() );
3362 : 0 : return CUBIT_FAILURE;
3363 : : }
3364 : :
3365 : : // sanity check - don't merge entity with itself
3366 [ - + ]: 846 : if( keeper_entity == dead_entity )
3367 : : {
3368 : : // Debug info
3369 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( " Did not merge %s and %s. "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
3370 : : "Cannot merge entity with itself.\n",
3371 : : keeper_entity_name.c_str(),
3372 [ # # ]: 0 : dead_entity_name.c_str() );
3373 : 0 : return CUBIT_SUCCESS;
3374 : : }
3375 : :
3376 : : // sanity check - don't merge entities w/ same parent
3377 [ + - ]: 846 : ModelQueryEngine *const mqe = ModelQueryEngine::instance();
3378 [ + - ]: 846 : DagType parent_type = keeper_entity->get_parent_ref_entity_type();
3379 [ + - ]: 846 : mqe->query_model( *keeper_entity, parent_type, query_results );
3380 [ + - ]: 846 : mqe->query_model( *dead_entity, parent_type, query_results_2 );
3381 [ + - ]: 846 : query_results.intersect( query_results_2 );
3382 [ + - ][ - + ]: 846 : if (query_results.size())
3383 : : {
3384 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_BTE()\n" );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
3385 [ # # ][ # # ]: 0 : PRINT_INFO("\n");
[ # # ][ # # ]
3386 [ # # ][ # # ]: 0 : PRINT_WARNING("Attempting to merge two entities with same parent.\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
3387 : : " %s (%s %d) and %s (%s %d)\n",
3388 : : keeper_entity->entity_name().c_str(),
3389 : : keeper_entity->class_name(), keeper_entity->id(),
3390 : : dead_entity->entity_name().c_str(),
3391 [ # # ]: 0 : dead_entity->class_name(), dead_entity->id());
3392 [ # # ][ # # ]: 0 : PRINT_INFO("Check for sliver geometry in the vicinity\n");
[ # # ][ # # ]
3393 : 0 : return CUBIT_FAILURE;
3394 : : }
3395 : :
3396 : : // Merge the GroupingEntitys of the BasicTopologyEntity
3397 [ + - ][ + - ]: 1692 : DLIList<GroupingEntity*> keeper_GE_list;
3398 [ + - ][ + - ]: 1692 : DLIList<GroupingEntity*> dead_GE_list;
3399 : :
3400 : : // First get the GroupingEntities of the BTE's
3401 [ + - ]: 846 : keeper_entity->get_grouping_entity_list( keeper_GE_list );
3402 [ + - ]: 846 : dead_entity->get_grouping_entity_list( dead_GE_list );
3403 : :
3404 : : // Make sure they have the same number of GroupingEntities
3405 [ + - ][ + - ]: 846 : if( keeper_GE_list.size() != dead_GE_list.size() )
[ - + ]
3406 : : {
3407 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_BTE()\n"
[ # # ][ # # ]
[ # # ][ # # ]
3408 : : " the two entities have different "
3409 : : "numbers of GroupingEntities.\n"
3410 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3411 : 0 : return CUBIT_FAILURE;
3412 : : }
3413 : :
3414 : : // Merge all child BTEs
3415 : : BasicTopologyEntity *bte_ptr_1, *bte_ptr_2;
3416 [ + - ]: 846 : DagType child_type = keeper_entity->get_child_ref_entity_type();
3417 [ + - ][ + + ]: 846 : if (child_type.is_valid())
3418 : : {
3419 [ + - ]: 510 : query_results.clean_out();
3420 [ + - ]: 510 : mqe->query_model( *keeper_entity, child_type, query_results );
3421 [ + - ][ + + ]: 1698 : while (query_results.size())
3422 : : {
3423 [ + - ][ - + ]: 1188 : bte_ptr_1 = dynamic_cast<BasicTopologyEntity*>(query_results.pop());
3424 [ + - ][ + + ]: 1188 : bte_ptr_2 = dynamic_cast<BasicTopologyEntity*>(bte_ptr_1->get_compare_partner());
3425 [ + + ][ + - ]: 1188 : if (!bte_ptr_2 || bte_ptr_2->deactivated())
[ + + ][ + + ]
3426 : 456 : continue;
3427 : :
3428 [ + - ][ + - ]: 732 : if (bte_ptr_2->get_compare_partner() != bte_ptr_1)
[ - + ]
3429 : : {
3430 [ # # ][ # # ]: 0 : PRINT_DEBUG_19("Bad compare partner TDs encountered at %s:%d.\n"
[ # # ][ # # ]
[ # # ][ # # ]
3431 : : "This is a bug. Please report it.\n",
3432 [ # # ]: 0 : __FILE__, __LINE__ );
3433 : 0 : return CUBIT_FAILURE;
3434 : : }
3435 : :
3436 : : CubitStatus merge_status;
3437 [ + - ][ + - ]: 732 : if (bte_ptr_1->id() < bte_ptr_2->id())
[ + - ]
3438 [ + - ]: 732 : merge_status = merge_BTE(bte_ptr_1, bte_ptr_2);
3439 : : else
3440 [ # # ]: 0 : merge_status = merge_BTE(bte_ptr_2, bte_ptr_1);
3441 : :
3442 [ - + ]: 732 : if (!merge_status)
3443 : 0 : return CUBIT_FAILURE;
3444 : : }
3445 : : }
3446 : :
3447 : : // If RefFace or RefEdge, adjust sense of parent sense entities,
3448 : : // if necessary. This was previously handled by the
3449 : : // switch_child_notify() callback in DAGNode/TopologyEntity.
3450 : : // However, with virtual geometry, there may be CoEdges/CoFaces
3451 : : // that do not get merged with anything and still need to be
3452 : : // updated. Also, by taking this out of switch_child_notify,
3453 : : // compare_alignment() does not need to be called for every
3454 : : // SenseEntitiy merge. We only need to call it once.
3455 : 846 : CubitBoolean switch_sense = CUBIT_FALSE;
3456 : :
3457 [ + - ][ + + ]: 846 : if(CAST_TO( keeper_entity, RefFace ) )
[ + + ]
3458 : : {
3459 [ - + ]: 114 : RefFace* keep_face = CAST_TO(keeper_entity,RefFace);
3460 [ - + ]: 114 : RefFace* dead_face = CAST_TO( dead_entity,RefFace);
3461 [ + - ][ + + ]: 114 : if( keep_face->compare_alignment(dead_face) == CUBIT_REVERSED )
3462 : : {
3463 : 114 : switch_sense = CUBIT_TRUE;
3464 : : }
3465 : : //warn_about_refface_sense( keep_face, dead_face, switch_sense );
3466 : : }
3467 [ + - ][ + + ]: 732 : else if( CAST_TO( keeper_entity, RefEdge ) )
[ + + ]
3468 : : {
3469 [ - + ]: 396 : RefEdge* keep_edge = CAST_TO(keeper_entity,RefEdge);
3470 [ - + ]: 396 : RefEdge* dead_edge = CAST_TO( dead_entity,RefEdge);
3471 : : CubitSense sense;
3472 : : CubitBoolean junk;
3473 : : keep_edge->relative_sense( dead_edge,
3474 : : GeometryQueryTool::get_geometry_factor(),
3475 [ + - ][ + - ]: 396 : &sense, junk, CUBIT_TRUE );
3476 [ + + ]: 396 : if( sense == CUBIT_REVERSED )
3477 : 396 : switch_sense = CUBIT_TRUE;
3478 : : }
3479 : :
3480 : :
3481 : : // Let any assistants know that we are about to merge
3482 : : // these two entities.
3483 [ + - ][ - + ]: 846 : for( int a = assistant_list_.size(); a > 0; a-- )
3484 [ # # ]: 0 : assistant_list_.get_and_step()
3485 [ # # ][ # # ]: 0 : ->merging( keeper_entity, dead_entity, switch_sense );
[ # # ]
3486 : :
3487 : :
3488 : : // Now find the matching pairs of GroupingEntities to merge
3489 : 846 : GroupingEntity *keeper_GE = NULL;
3490 : 846 : GroupingEntity *dead_GE = NULL;
3491 : :
3492 : : CubitStatus found_flag;
3493 [ + - ]: 846 : keeper_GE_list.reset();
3494 [ + - ][ + + ]: 1356 : for( int i = 0; i< keeper_GE_list.size(); i++ )
3495 : : {
3496 : 510 : found_flag = CUBIT_FAILURE;
3497 [ + - ]: 510 : keeper_GE = keeper_GE_list.get_and_step();
3498 : :
3499 : : // if keeper_GE is deactivated,
3500 : : // then skip this one and come to the next one
3501 [ + - ][ - + ]: 510 : if( keeper_GE->deactivated() == CUBIT_TRUE )
3502 : 0 : continue;
3503 : :
3504 [ + - ]: 510 : dead_GE_list.reset();
3505 [ + - ][ + - ]: 510 : for( int j = 0; j < dead_GE_list.size(); j++ )
3506 : : {
3507 [ + - ]: 510 : dead_GE = dead_GE_list.get_and_step();
3508 : :
3509 : : // Before doing any compares, check to see if this
3510 : : // GroupingEntity has already been deactivated
3511 [ + - ][ - + ]: 510 : if( dead_GE->deactivated() == CUBIT_TRUE )
3512 : 0 : continue;
3513 : :
3514 : : // if find any item in dead_GE_list matches the item in
3515 : : // keeper_GE_list, then merge these two items, remove
3516 : : // dead_GE from the dead_GE_list, continue to the next
3517 : : // item in keeper_GE_list.
3518 [ + - ][ + - ]: 510 : if( compare_GE( keeper_GE, dead_GE ) )
3519 : : {
3520 [ + - ][ - + ]: 510 : if( merge_GE( keeper_GE, dead_GE ) == CUBIT_FAILURE )
3521 : : {
3522 [ # # ][ # # ]: 0 : PRINT_DEBUG_19("In MergeTool::merge_BTE()\n"
[ # # ][ # # ]
[ # # ][ # # ]
3523 : : " Cannot merge the GroupingEntities\n"
3524 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3525 : 0 : return CUBIT_FAILURE;
3526 : : }
3527 : : else
3528 : : {
3529 : : // A match was found and merged. Deactivation of
3530 : : // dead_GE is done in TopologyEntity::merge_links().
3531 : 510 : found_flag = CUBIT_SUCCESS;
3532 [ + - ]: 510 : dead_GE_list.reset();
3533 : 510 : break;
3534 : : }
3535 : : }
3536 : : }
3537 : :
3538 [ - + ]: 510 : if( found_flag == CUBIT_FAILURE )
3539 : : {
3540 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_BTE()\n"
[ # # ][ # # ]
[ # # ][ # # ]
3541 : : " cannot find the matching GroupingEntities.\n"
3542 : : " This may be due to curves smaller than the\n"
3543 : : " merge tolerance. You will probably want to\n"
3544 [ # # ]: 0 : " modify the geometry.\n");
3545 : 0 : return CUBIT_FAILURE;
3546 : : }
3547 : : }
3548 : :
3549 : : // Merge the name(s) of dead_entity to those of keeper_entity
3550 [ + - ][ + - ]: 846 : keeper_entity->merge_entity_names( dead_entity );
3551 : :
3552 : 846 : bool is_dead_entity_free_entity = false;
3553 [ + - ][ - + ]: 846 : if( dead_entity->num_parent_ref_entities() == 0 )
3554 : 0 : is_dead_entity_free_entity = true;
3555 : :
3556 : 846 : bool is_keeper_entity_free_entity = false;
3557 [ + - ][ - + ]: 846 : if( keeper_entity->num_parent_ref_entities() == 0 )
3558 : 0 : is_keeper_entity_free_entity = true;
3559 : :
3560 : : // Next, merge the links of these two BTEs
3561 : : SenseEntity* co_edge_ptr;
3562 : 846 : result = CUBIT_SUCCESS;
3563 [ + - ][ + + ]: 2760 : while( (co_edge_ptr = dead_entity->get_first_sense_entity_ptr()) )
3564 : : {
3565 [ + + ]: 1914 : if (switch_sense)
3566 [ + - ]: 149 : co_edge_ptr->reverse_sense();
3567 [ + - ][ - + ]: 1914 : if (!dead_entity->remove_sense_entity(co_edge_ptr))
3568 : 0 : result = CUBIT_FAILURE;
3569 [ + - ][ - + ]: 1914 : if (!keeper_entity->add_sense_entity(co_edge_ptr))
3570 : 0 : result = CUBIT_FAILURE;
3571 : : }
3572 : :
3573 [ - + ]: 846 : if( result == CUBIT_FAILURE )
3574 : : {
3575 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_BTE()\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
3576 : : " Could not merge the links of %s and %s.\n"
3577 : : " THIS IS A BUG - PLEASE REPORT IT!\n",
3578 : : keeper_entity->entity_name().c_str(),
3579 [ # # ]: 0 : dead_entity->entity_name().c_str() );
3580 : 0 : return CUBIT_FAILURE;
3581 : : }
3582 : :
3583 : : // Save IDs for geometry from dead entity.
3584 : : // Only do this for the first geometry if the dead
3585 : : // entity is already a merge of several. Others should
3586 : : // already have IDs saved from whatever they where
3587 : : // before they were merged.
3588 [ + - ]: 846 : GeometryEntity* geom = dead_entity->get_geometry_entity_ptr();
3589 [ + - ][ + - ]: 846 : geom->set_saved_id( dead_entity->id() );
3590 : :
3591 : :
3592 : : // TODO -- Suggestion to make this merge code more friendly for observers:
3593 : : // 1. emit only one merge event after the merge actually happened
3594 : : // 2. delete entities after the merge event was emitted
3595 : :
3596 : : // Destroy the old entity
3597 : :
3598 [ + - ][ + - ]: 846 : AppUtil::instance()->send_event( MergeEvent(dead_entity, keeper_entity) );
[ + - ][ + - ]
[ + - ][ + - ]
3599 : :
3600 [ + - ][ + - ]: 846 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_DESTRUCTED, dead_entity));
[ + - ][ + - ]
[ + - ]
3601 [ - + ]: 846 : if( is_dead_entity_free_entity ) //is free entity...top level
3602 : : {
3603 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOP_LEVEL_ENTITY_DESTRUCTED, dead_entity));
[ # # ][ # # ]
[ # # ]
3604 [ # # ][ # # ]: 0 : CGMHistory::Event evt(CGMHistory::TOP_LEVEL_ENTITY_DELETED, dead_entity);
3605 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->history().add_event(evt);
[ # # ][ # # ]
3606 : : }
3607 : :
3608 [ + - ]: 846 : dead_entity->deactivated(CUBIT_TRUE);
3609 : :
3610 [ + - ]: 846 : BridgeManager* keeper_GEs = keeper_entity->bridge_manager();
3611 [ + - ]: 846 : BridgeManager* dead_GEs = dead_entity->bridge_manager();
3612 : : result = keeper_GEs->merge( dead_GEs,
3613 [ + + ][ + - ]: 846 : switch_sense ? CUBIT_REVERSED : CUBIT_FORWARD );
3614 [ - + ]: 846 : if( result == CUBIT_FAILURE )
3615 : : {
3616 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_BTE()\n"
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
3617 : : " Could not merge the GeometryEntities "
3618 : : "of %s and %s.\n"
3619 : : " THIS IS A BUG - PLEASE REPORT IT!\n",
3620 : : keeper_entity->entity_name().c_str(),
3621 [ # # ]: 0 : dead_entity->entity_name().c_str() );
3622 : 0 : return CUBIT_FAILURE;
3623 : : }
3624 : :
3625 : : // Debug info
3626 [ + - ][ + - ]: 846 : PRINT_DEBUG_19(
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
3627 : : "\n...Merging of %s (retained) and %s (deleted) "
3628 : : "successful.\n\n\n", keeper_entity_name.c_str(),
3629 [ # # ]: 0 : dead_entity_name.c_str() );
3630 : :
3631 [ - + ][ # # ]: 846 : if( is_keeper_entity_free_entity && !is_dead_entity_free_entity ) //is free entity...top level
3632 : : {
3633 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOP_LEVEL_ENTITY_DESTRUCTED, keeper_entity));
[ # # ][ # # ]
[ # # ]
3634 [ # # ][ # # ]: 0 : CGMHistory::Event evt(CGMHistory::TOP_LEVEL_ENTITY_DELETED, keeper_entity);
3635 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->history().add_event(evt);
[ # # ][ # # ]
3636 : : }
3637 : :
3638 : :
3639 [ + - ][ + + ]: 2700 : for(int i=0; i<dead_parents.size(); i++)
3640 : : {
3641 [ + - ][ + - ]: 1854 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_MODIFIED, dead_parents[i]));
[ + - ][ + - ]
[ + - ]
3642 [ + - ][ + - ]: 1854 : CGMHistory::Event evt(CGMHistory::TOPOLOGY_CHANGED, dead_parents[i]);
3643 [ + - ][ + - ]: 1854 : GeometryQueryTool::instance()->history().add_event(evt);
[ + - ]
3644 [ + - ]: 1854 : }
3645 : :
3646 [ + - ]: 1692 : return CUBIT_SUCCESS;
3647 : : }
3648 : :
3649 : : //-------------------------------------------------------------------------
3650 : : // Purpose : When merging RefFaces with the same sense, check
3651 : : // CoFace senses to see if the adjacent RefVolumes overlap.
3652 : : //
3653 : : // Special Notes :
3654 : : //
3655 : : // Creator : Jason Kraftcheck
3656 : : //
3657 : : // Creation Date : 03/04/04
3658 : : //-------------------------------------------------------------------------
3659 : 0 : void MergeTool::warn_about_refface_sense( RefFace* face1, RefFace* face2,
3660 : : bool faces_reversed )
3661 : : {
3662 [ # # ][ # # ]: 0 : DLIList<CoFace*> coface_list_1, coface_list_2;
[ # # ]
3663 [ # # ]: 0 : face1->co_faces(coface_list_1);
3664 [ # # ]: 0 : face2->co_faces(coface_list_2);
3665 : 0 : bool non_manifold_1 = false, non_manifold_2 = false;
3666 [ # # ][ # # ]: 0 : while (coface_list_1.size())
3667 : : {
3668 [ # # ]: 0 : CoFace* coface1 = coface_list_1.pop();
3669 [ # # ][ # # ]: 0 : if (face1->is_nonmanifold(coface1->get_shell_ptr()))
[ # # ]
3670 : : {
3671 : 0 : non_manifold_1 = true;
3672 : 0 : continue;
3673 : : }
3674 : :
3675 [ # # ][ # # ]: 0 : for (int i = coface_list_2.size(); i--; )
3676 : : {
3677 [ # # ]: 0 : CoFace* coface2 = coface_list_2.pop();
3678 [ # # ][ # # ]: 0 : if (face2->is_nonmanifold(coface2->get_shell_ptr()))
[ # # ]
3679 : : {
3680 : 0 : non_manifold_2 = true;
3681 : 0 : continue;
3682 : : }
3683 : :
3684 [ # # ][ # # ]: 0 : bool cofaces_reversed = (coface1->get_sense() == coface2->get_sense());
3685 [ # # ]: 0 : if (faces_reversed != cofaces_reversed)
3686 : : {
3687 [ # # ][ # # ]: 0 : RefVolume* vol1 = coface1->get_shell_ptr()->get_ref_volume_ptr();
3688 [ # # ][ # # ]: 0 : RefVolume* vol2 = coface2->get_shell_ptr()->get_ref_volume_ptr();
3689 [ # # ][ # # ]: 0 : PRINT_WARNING("Merging %s (surface %d) and %s (surface %d): "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
3690 : : "%s (volume %d) and %s (volume %d) appear to be "
3691 : : "on the same side of the surfaces. This may "
3692 : : "indicate bad geometry.\n",
3693 : : face1->entity_name().c_str(), face1->id(),
3694 : : face2->entity_name().c_str(), face2->id(),
3695 : : vol1->entity_name().c_str(), vol1->id(),
3696 [ # # ]: 0 : vol2->entity_name().c_str(), vol2->id());
3697 : : }
3698 : : }
3699 : : }
3700 : :
3701 [ # # ]: 0 : if (non_manifold_1)
3702 [ # # ][ # # ]: 0 : PRINT_WARNING("Merging non-manifold surface %d (%s). Sheet body?\n",
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
3703 [ # # ]: 0 : face1->id(), face1->entity_name().c_str());
3704 [ # # ]: 0 : if (non_manifold_2)
3705 [ # # ][ # # ]: 0 : PRINT_WARNING("Merging non-manifold surface %d (%s). Sheet body?\n",
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
3706 [ # # ][ # # ]: 0 : face2->id(), face2->entity_name().c_str());
3707 : 0 : }
3708 : :
3709 : :
3710 : : //----------------------------------------------------------------
3711 : : // Purpose : Merge "this" GroupingEntity with the input
3712 : : // GroupingEntity
3713 : : //
3714 : : // Special Notes :
3715 : : //
3716 : : // Creator : jihong Ma
3717 : : //
3718 : : // Creation Date : 11/26/96
3719 : : //----------------------------------------------------------------
3720 : 510 : CubitStatus MergeTool::merge_GE( GroupingEntity *keeper_entity,
3721 : : GroupingEntity *dead_entity )
3722 : : {
3723 : : // first check if merging keeper_entity with itself
3724 [ - + ]: 510 : if( keeper_entity == dead_entity )
3725 : 0 : return CUBIT_SUCCESS;
3726 : :
3727 : 510 : CubitStatus result = CUBIT_FAILURE;
3728 : :
3729 : : // Merge is done whenever we find matching SenseEntities from
3730 : : // keeper_entity and dead_entity in compare_and_merge() with a
3731 : : // CUBIT_TRUE input parameter.
3732 : 510 : result = compare_and_merge( CUBIT_TRUE, keeper_entity, dead_entity );
3733 : :
3734 : : // When merging SenseEntities fails, print error and return
3735 [ - + ]: 510 : if( result == CUBIT_FAILURE )
3736 : : {
3737 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_GE()\n"
3738 : : " Could not merge the SenseEntities\n"
3739 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3740 : 0 : return CUBIT_FAILURE;
3741 : : }
3742 : :
3743 : : // After succussfully merging SenseEntities, merge the links
3744 : : // of the GeometryEntities.
3745 [ - + ]: 510 : assert(dead_entity->get_children() == 0);
3746 : 510 : dead_entity->deactivated(CUBIT_TRUE);
3747 : 510 : BasicTopologyEntity* parent = dead_entity->get_basic_topology_entity_ptr();
3748 : 510 : result = parent->remove_grouping_entity(dead_entity);
3749 : :
3750 [ - + ]: 510 : if( result == CUBIT_FAILURE )
3751 : : {
3752 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_GE()\n"
3753 : : " Could not merge the GroupingEntity links.\n"
3754 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3755 : 0 : return CUBIT_FAILURE;
3756 : : }
3757 : :
3758 : : // merge the OSME's.
3759 : 510 : BridgeManager* keeper_OSMEs = keeper_entity->bridge_manager();
3760 : 510 : BridgeManager* dead_OSMEs = dead_entity->bridge_manager();
3761 : :
3762 : 510 : result = keeper_OSMEs->merge(dead_OSMEs,CUBIT_UNKNOWN);
3763 [ - + ]: 510 : if( result == CUBIT_FAILURE )
3764 : : {
3765 [ # # ][ # # ]: 0 : PRINT_DEBUG_19( "In MergeTool::merge_GE()\n"
3766 : : " Could not merge the OSME's.\n"
3767 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3768 : 0 : return CUBIT_FAILURE;
3769 : : }
3770 : :
3771 : 510 : return CUBIT_SUCCESS;
3772 : : }
3773 : :
3774 : :
3775 : : //----------------------------------------------------------------
3776 : : // Purpose : Compare this GroupingEntity to the input
3777 : : // GroupingEntity to compare for spatial equality.
3778 : : //
3779 : : // Special Notes :
3780 : : //
3781 : : // Creator : jihong Ma
3782 : : //
3783 : : // Creation Date : 11/26/96
3784 : : //----------------------------------------------------------------
3785 : 510 : CubitBoolean MergeTool::compare_GE( GroupingEntity* keeper_entity,
3786 : : GroupingEntity* dead_entity )
3787 : : {
3788 : : // Comparison is done by comparing the SenseEntity list of
3789 : : // keeper_entity with the SenseEntity list of dead_entity.
3790 : : // If we find that all the SenseEntities of keeper_entity
3791 : : // match with all the SenseEntities of dead_entity
3792 : : // then the GroupingEntities are spatially equal.
3793 : :
3794 [ + - ]: 510 : if( compare_and_merge( CUBIT_FALSE, keeper_entity, dead_entity ) )
3795 : 510 : return CUBIT_TRUE;
3796 : : else
3797 : 0 : return CUBIT_FALSE;
3798 : : }
3799 : :
3800 : : //---------------------------------------------------------------
3801 : : // Purpose : spatially compare this GroupingEntity with the
3802 : : // input GroupingEntity. But if the merge_flag is
3803 : : // CUBIT_TRUE, merge the matching SenseEntity
3804 : : // pairs whenever found.
3805 : : //
3806 : : // Special Notes : Merging the OSME's and merging links are done
3807 : : // in merge_GE() function. In this function, ONLY
3808 : : // the matching SenseEntities can be merged when
3809 : : // asked to merge them ( i.e., merge_flag is
3810 : : // set to CUBIT_TRUE ).
3811 : : //
3812 : : // Grouping entities compare successfully if their
3813 : : // associated lists of SenseEntities compare
3814 : : // successfully. For example, 2 Loops compare if
3815 : : // their lists of CoEdges contain matching (ones
3816 : : // that compare) pairs.
3817 : : //
3818 : : // The first trial check that is done is to make
3819 : : // sure that the GroupingEntities have the same
3820 : : // number of SenseEntities. If they do not, then
3821 : : // we ASSUME that the GroupingEntities are not
3822 : : // spatially equal. This is not strictly a good
3823 : : // assumption, but we don't have a more exact
3824 : : // algorithm that takes care of the case where,
3825 : : // for example, the number of RefEdges associated
3826 : : // with two Loops are different, but the Loops
3827 : : // themselves are spatialy equal. Consider the
3828 : : // case of 2 Loops representing the exact same
3829 : : // square -- one can have 4 RefEdges and the other
3830 : : // could have 5 (just bisect one of the previous
3831 : : // ones...)
3832 : : //
3833 : : // Creator : jihong Ma
3834 : : //
3835 : : // Creation Date : 12/05/96
3836 : : //---------------------------------------------------------------
3837 : 1020 : CubitStatus MergeTool::compare_and_merge( CubitBoolean merge_flag,
3838 : : GroupingEntity* keeper_entity,
3839 : : GroupingEntity* dead_entity )
3840 : : {
3841 : : // check if they are equal
3842 [ - + ]: 1020 : if( keeper_entity == dead_entity )
3843 : 0 : return CUBIT_SUCCESS;
3844 : :
3845 : : // Make sure that the 2 GroupingEntities are of the same type
3846 [ + - ][ + - ]: 1020 : if( keeper_entity->dag_type() != dead_entity->dag_type() )
[ + - ][ - + ]
3847 : : {
3848 [ # # ][ # # ]: 0 : PRINT_ERROR( "In MergeTool::compare_and_merge()\n"
[ # # ]
3849 : : " Entities of different type are being compared.\n"
3850 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3851 : 0 : return CUBIT_FAILURE;
3852 : : }
3853 : :
3854 : : // Now compare, and merge if asked, the SenseEntities
3855 : : // Get the SenseEntity lists
3856 [ + - ]: 1020 : DLIList<SenseEntity*> keeper_SE_list;
3857 [ + - ][ + - ]: 2040 : DLIList<SenseEntity*> dead_SE_list;
3858 : :
3859 [ + - ]: 1020 : keeper_entity->get_sense_entity_list( keeper_SE_list );
3860 [ + - ]: 1020 : dead_entity->get_sense_entity_list( dead_SE_list );
3861 : :
3862 : : // Make sure the lists are of the same size. If not, then
3863 : : // there is a bug here as the 2 GroupingEntities should not
3864 : : // have passed the "compare" test.
3865 [ + - ][ + - ]: 1020 : if( keeper_SE_list.size() != dead_SE_list.size() )
[ - + ]
3866 : : {
3867 [ # # ]: 0 : if( merge_flag == CUBIT_TRUE )
3868 : : {
3869 [ # # ][ # # ]: 0 : PRINT_ERROR(" THIS IS A BUG - PLEASE REPORT IT!\n");
[ # # ][ # # ]
3870 : 0 : assert(0);
3871 : : }
3872 : 0 : return CUBIT_FAILURE;
3873 : : }
3874 : :
3875 : 1020 : SenseEntity* keeper_SE = NULL;
3876 : 1020 : SenseEntity* dead_SE = NULL;
3877 : : CubitStatus found_flag;
3878 : :
3879 : : // Now find the matching pairs of SenseEntities
3880 [ + - ]: 1020 : keeper_SE_list.reset();
3881 [ + - ][ + + ]: 3516 : for( int i = 0; i < keeper_SE_list.size(); i++ )
3882 : : {
3883 : 2496 : found_flag = CUBIT_FAILURE;
3884 [ + - ]: 2496 : keeper_SE = keeper_SE_list.get_and_step();
3885 : :
3886 : : // If this SenseEntity has already been deactivated,
3887 : : // then skip to the next one
3888 [ + - ][ - + ]: 2496 : if( keeper_SE->deactivated() == CUBIT_TRUE )
3889 : 0 : continue;
3890 : :
3891 [ + - ]: 2496 : dead_SE_list.reset();
3892 [ + - ][ + - ]: 4576 : for( int j = 0; j < dead_SE_list.size(); j++ )
3893 : : {
3894 [ + - ]: 4576 : dead_SE = dead_SE_list.get_and_step();
3895 : :
3896 : : // if dead_SE is deactivated, then skip to next one
3897 [ + - ][ + + ]: 4576 : if( dead_SE->deactivated() == CUBIT_TRUE )
3898 : 792 : continue;
3899 : :
3900 : : // look for an item in dead_SE_list that matches an
3901 : : // item in keeper_SE_list
3902 [ + - ][ + + ]: 3784 : if( compare_SE( keeper_SE, dead_SE ) )
3903 : : {
3904 : : // if asked to merge, then merge the matching
3905 : : // SenseEntities remove the dead_SE from the
3906 : : // dead_SE_list. Continue to the next item in
3907 : : // keeper_SE_list
3908 [ + + ]: 2496 : if( merge_flag == CUBIT_TRUE )
3909 : : {
3910 [ + - ][ - + ]: 1248 : if( merge_SE( keeper_SE, dead_SE ) == CUBIT_FAILURE )
3911 : : {
3912 [ # # ][ # # ]: 0 : PRINT_ERROR( "In MergeTool::compare_and_merge()\n"
[ # # ]
3913 : : " Cannot merge the matched SenseEntity\n"
3914 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3915 : 0 : return CUBIT_FAILURE;
3916 : : }
3917 : : }
3918 : :
3919 : : // if not asked to merge, just break to outer loop to
3920 : : // compare the next SenseEntity.
3921 : 2496 : found_flag = CUBIT_SUCCESS;
3922 [ + - ]: 2496 : dead_SE_list.reset();
3923 : 2496 : break;
3924 : : }
3925 : : }
3926 : :
3927 : : // If we were unable to find a match for one of the SEs,
3928 : : // return failure.
3929 [ - + ]: 2496 : if (found_flag == CUBIT_FAILURE)
3930 : 0 : return CUBIT_FAILURE;
3931 : : }
3932 [ + - ]: 2040 : return CUBIT_SUCCESS;
3933 : : }
3934 : :
3935 : : //----------------------------------------------------------------
3936 : : // Purpose : merge two SenseEntities
3937 : : //
3938 : : // Special Notes :
3939 : : //
3940 : : // Creator : jihong Ma
3941 : : //
3942 : : // Creation Date : 11/20/96
3943 : : //----------------------------------------------------------------
3944 : 1248 : CubitStatus MergeTool::merge_SE( SenseEntity* keeper_entity,
3945 : : SenseEntity* dead_entity )
3946 : : {
3947 : : // first check if merging the SenseEntity with itself
3948 [ - + ]: 1248 : if( keeper_entity == dead_entity )
3949 : 0 : return CUBIT_SUCCESS;
3950 : :
3951 : 1248 : CubitStatus result = CUBIT_FAILURE;
3952 : :
3953 : : // Make sure that the 2 SenseEntities are of the same type
3954 [ + - ][ - + ]: 1248 : if( keeper_entity->dag_type() != dead_entity->dag_type() )
3955 : : {
3956 [ # # ]: 0 : PRINT_ERROR( "In MergeTool::merge_SE()\n"
3957 : : " Merging SenseEntities of different types\n"
3958 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3959 : 0 : return CUBIT_FAILURE;
3960 : : }
3961 : :
3962 : : BasicTopologyEntity* keeper_BTE;
3963 : : BasicTopologyEntity* dead_BTE;
3964 : :
3965 : : // Get the BTE's of the SenseEntities being merged
3966 : 1248 : keeper_BTE = keeper_entity->get_basic_topology_entity_ptr();
3967 : 1248 : dead_BTE = dead_entity->get_basic_topology_entity_ptr();
3968 : :
3969 : : // Compare them to make sure that these SenseEntities can
3970 : : // really be merged.
3971 [ - + ]: 1248 : if( keeper_BTE != dead_BTE)
3972 : : {
3973 [ # # ]: 0 : PRINT_ERROR( "In MergeTool::merge_SE()\n"
3974 : : " Two SenseEntities have incompatible BTEs\n"
3975 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3976 : 0 : assert(0);
3977 : : return CUBIT_FAILURE;
3978 : : }
3979 : :
3980 : :
3981 [ + - ][ + - ]: 1248 : AppUtil::instance()->send_event(TopologyEvent(TopologyEvent::TOPOLOGY_ENTITY_DESTRUCTED, dead_entity));
3982 : :
3983 : : // Now that the BTE's have been successfully merged, merge the
3984 : : // the links of the SenseEntities.
3985 : 1248 : dead_entity->deactivated(CUBIT_TRUE);
3986 : 1248 : GroupingEntity* parent = dead_entity->get_grouping_entity_ptr();
3987 : 1248 : BasicTopologyEntity* child = dead_entity->get_basic_topology_entity_ptr();
3988 [ + - + - ]: 2496 : result = (CubitStatus)(parent->remove_sense_entity(dead_entity) &&
3989 : 1248 : child->remove_sense_entity(dead_entity));
3990 [ - + ]: 1248 : if( result == CUBIT_FAILURE )
3991 : : {
3992 [ # # ]: 0 : PRINT_ERROR( "In MergeTool::merge_SE()\n"
3993 : : " Couldn't merge the links of the SenseEntities.\n"
3994 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
3995 : 0 : assert(0);
3996 : : return CUBIT_FAILURE;
3997 : : }
3998 : :
3999 : : // Now that the BTE's have been successfully merged, merge the
4000 : : // OSME's of the SenseEntities being merged
4001 : 1248 : BridgeManager* keeper_OSMEs = keeper_entity->bridge_manager();
4002 : 1248 : BridgeManager* dead_OSMEs = dead_entity->bridge_manager();
4003 : :
4004 : 1248 : result = keeper_OSMEs->merge(dead_OSMEs,CUBIT_UNKNOWN);
4005 [ - + ]: 1248 : if (result == CUBIT_FAILURE)
4006 : : {
4007 [ # # ]: 0 : PRINT_ERROR( "In MergeTool::merge_SE()\n"
4008 : : " Could not merge the OSME's.\n"
4009 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
4010 : 0 : assert(0) ;
4011 : : return CUBIT_FAILURE;
4012 : : }
4013 : :
4014 : 1248 : return CUBIT_SUCCESS;
4015 : : }
4016 : :
4017 : : //----------------------------------------------------------------
4018 : : // Purpose : Compare two SenseEntities
4019 : : //
4020 : : // Special Notes : Sense entities compare successfully if their
4021 : : // associated BasicTopologyEntities compare
4022 : : // successfully. For example, 2 CoEdges compare
4023 : : // if their RefEdges compare.
4024 : : //
4025 : : // Creator : jihong Ma
4026 : : //
4027 : : // Creation Date : 11/20/96
4028 : : //----------------------------------------------------------------
4029 : 3784 : CubitBoolean MergeTool::compare_SE( SenseEntity* keeper_entity,
4030 : : SenseEntity* dead_entity )
4031 : : {
4032 : : // check if they are the same entity
4033 [ - + ]: 3784 : if( keeper_entity == dead_entity )
4034 : 0 : return CUBIT_TRUE;
4035 : :
4036 : : // first check if they are the same type
4037 [ + - ][ - + ]: 3784 : if( keeper_entity->dag_type() != dead_entity->dag_type() )
4038 : : {
4039 [ # # ]: 0 : PRINT_ERROR( "In MergeTool::compare_SE()\n"
4040 : : " SenseEntities of different type are compared\n"
4041 [ # # ]: 0 : " THIS IS A BUG - PLEASE REPORT IT!\n" );
4042 : 0 : return CUBIT_TRUE;
4043 : : }
4044 : :
4045 : : // Get their BTE's and compare them
4046 : 3784 : BasicTopologyEntity *keeper_BTE = NULL;
4047 : 3784 : BasicTopologyEntity *dead_BTE = NULL;
4048 : :
4049 : 3784 : keeper_BTE = keeper_entity->get_basic_topology_entity_ptr();
4050 : 3784 : dead_BTE = dead_entity->get_basic_topology_entity_ptr();
4051 : :
4052 : : // Return the status of comparing the BTE's
4053 : 3784 : return keeper_BTE == dead_BTE;
4054 : : }
4055 : :
4056 : 159 : void MergeTool::complete_merge()
4057 : : {
4058 : : // Merge operation was completed successfully or was aborted midway.
4059 : : // Clean up the temporary compare data that was added to the RefEntities
4060 : : // being compared (during the merge) and cleanout the local (Model) lists
4061 : : // that store pointers to such entities.
4062 : :
4063 : 159 : remove_compare_data();
4064 : :
4065 : : // Now clear the lists
4066 : 159 : compareEntityList.clean_out() ;
4067 : 159 : mergeSurvivorEntityList.clean_out();
4068 : :
4069 : : // Notify assistants
4070 [ - + ]: 159 : for( int j = assistant_list_.size(); j--; )
4071 : 0 : assistant_list_.get_and_step()->finish_merge();
4072 : 159 : }
4073 : :
4074 : 159 : void MergeTool::remove_compare_data()
4075 : : {
4076 : 159 : compareEntityList.reset();
4077 [ + + ]: 1851 : for(int i = compareEntityList.size(); i > 0 ; i-- )
4078 : : {
4079 : 1692 : RefEntity* ref_ent = compareEntityList.get();
4080 [ + - ][ + - ]: 4404 : if ( CAST_TO( ref_ent, RefVertex ) ||
4081 [ + - + + ]: 4632 : CAST_TO( ref_ent, RefEdge ) ||
[ + + ][ + - ]
4082 [ + - ]: 228 : CAST_TO( ref_ent, RefFace ) )
4083 : : {
4084 : : // Remove the TDCompare data attached to the entity
4085 [ - + ][ # # ]: 1692 : PRINT_DEBUG_19(
4086 : : "Model::notify Removing compare_TD from %s %d\n",
4087 : : ref_ent->class_name(),
4088 [ # # ]: 0 : ref_ent->id());
4089 : 1692 : ref_ent->remove_compare_data();
4090 : : }
4091 : : else
4092 : : {
4093 [ # # ][ # # ]: 0 : PRINT_WARNING("WARNING:Something went wrong with the merging data.\n");
4094 : 0 : compareEntityList.remove();
4095 : : }
4096 : 1692 : compareEntityList.step();
4097 : : }
4098 : 159 : compareEntityList.clean_out();
4099 : 159 : }
4100 : :
4101 : :
4102 : 0 : void MergeTool::remove_merge_tool_assistant( MergeToolAssistant* mta_ptr )
4103 : : {
4104 [ # # ]: 0 : if( assistant_list_.move_to( mta_ptr ) )
4105 : 0 : assistant_list_.remove();
4106 : 0 : }
4107 : :
4108 : 0 : void MergeTool::add_merge_tool_assistant( MergeToolAssistant* mta_ptr )
4109 : : {
4110 [ # # ]: 0 : if( !assistant_list_.is_in_list( mta_ptr ) )
4111 : 0 : assistant_list_.append( mta_ptr );
4112 : 0 : }
4113 : 0 : MergeToolAssistant* MergeTool::find_merge_tool_assistant( const std::type_info& type )
4114 : : {
4115 [ # # ]: 0 : for( int i = assistant_list_.size(); i > 0; i-- )
4116 : : {
4117 [ # # ][ # # ]: 0 : if( typeid( *(assistant_list_.step_and_get()) ) == type )
4118 : 0 : return assistant_list_.get();
4119 : : }
4120 : 0 : return 0;
4121 : : }
4122 : 0 : void MergeTool::test_r_tree(DLIList <RefFace*> &refface_list)
4123 : : {
4124 [ # # ]: 0 : CpuTimer timer;
4125 [ # # ]: 0 : timer.cpu_secs();
4126 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
4127 : 0 : double tol = GEOMETRY_RESABS*geom_factor;
4128 [ # # ]: 0 : RTree<RefFace*> a_tree(GEOMETRY_RESABS*geom_factor);
4129 : : // AbstractTree <RefFace*> *a_tree = new RTree<RefFace*> (tol);
4130 : :
4131 [ # # ][ # # ]: 0 : DLIList<RefFace*> refface_array( refface_list.size() );
[ # # ]
4132 [ # # ]: 0 : refface_list.reset();
4133 : :
4134 : : // Remove entities that should not be automatically merged
4135 : 0 : int i = 0;
4136 : : int j;
4137 [ # # ]: 0 : int loop_size = refface_list.size();
4138 [ # # ]: 0 : for( i = 0; i < loop_size; i++ )
4139 : : {
4140 [ # # ]: 0 : RefFace *curr_face = refface_list.get_and_step();
4141 [ # # ][ # # ]: 0 : if( curr_face->is_mergeable() )
4142 : : {
4143 [ # # ]: 0 : refface_array.append( curr_face );
4144 [ # # ]: 0 : a_tree.add(curr_face);
4145 : : }
4146 : : }
4147 [ # # ]: 0 : double time_to_build = timer.cpu_secs();
4148 : :
4149 : : //initialize the marked flag for fast nulification...
4150 [ # # ]: 0 : int array_size = refface_array.size();
4151 : : RefFace *ref_face, *ref_face1;
4152 [ # # ][ # # ]: 0 : CubitBox temp_box, temp_box2;
[ # # ][ # # ]
4153 [ # # ][ # # ]: 0 : DLIList<RefFace*> faces_in_range;
4154 : 0 : int hit = 0;
4155 [ # # ]: 0 : for ( i = 0; i < array_size; i++ )
4156 : : {
4157 [ # # ]: 0 : ref_face = refface_array[i];
4158 [ # # ][ # # ]: 0 : temp_box = ref_face->bounding_box();
[ # # ]
4159 [ # # ]: 0 : faces_in_range.clean_out();
4160 [ # # ]: 0 : a_tree.find(temp_box, faces_in_range);
4161 [ # # ][ # # ]: 0 : for ( j = 0; j<faces_in_range.size(); j++)
4162 : : {
4163 [ # # ]: 0 : ref_face1 = faces_in_range.get_and_step();
4164 [ # # ][ # # ]: 0 : temp_box2 = ref_face1->bounding_box();
[ # # ]
4165 [ # # ][ # # ]: 0 : if ( temp_box.overlap(tol, temp_box2) )
4166 : 0 : hit++;
4167 : : }
4168 : : }
4169 [ # # ][ # # ]: 0 : PRINT_INFO( "TREE: Total Merge Reffaces time: %f secs\n"
[ # # ][ # # ]
4170 : : "\tTime to build: %f secs\n",
4171 [ # # ][ # # ]: 0 : timer.cpu_secs()+time_to_build, time_to_build );
4172 : 0 : }
4173 : :
4174 : : // void MergeTool::test_r_star_tree(DLIList <RefFace*> &refface_list)
4175 : : // {
4176 : : // CpuTimer timer;
4177 : : // timer.cpu_secs();
4178 : : // double geom_factor = GeometryQueryTool::get_geometry_factor();
4179 : : // double tol = GEOMETRY_RESABS*geom_factor;
4180 : : // RStarTree <RefFace*> *r_tree = new RStarTree<RefFace*> (tol);
4181 : :
4182 : : // DLIList<RefFace*> refface_array( refface_list.size() );
4183 : : // refface_list.reset();
4184 : :
4185 : : // // Remove entities that should not be automatically merged
4186 : : // int i = 0;
4187 : : // int j;
4188 : : // int loop_size = refface_list.size();
4189 : : // for( i = 0; i < loop_size; i++ )
4190 : : // {
4191 : : // RefFace *curr_face = refface_list.get_and_step();
4192 : : // if( curr_face->is_mergeable() )
4193 : : // {
4194 : : // refface_array.append( curr_face );
4195 : : // r_tree->add(curr_face);
4196 : : // }
4197 : : // }
4198 : : // double time_to_build = timer.cpu_secs();
4199 : : // //initialize the marked flag for fast nulification...
4200 : : // int array_size = refface_array.size();
4201 : : // RefFace *ref_face, *ref_face1;
4202 : : // CubitBox temp_box, temp_box2;
4203 : : // DLIList<RefFace*> faces_in_range;
4204 : : // int hit = 0;
4205 : : // for ( i = 0; i < array_size; i++ )
4206 : : // {
4207 : : // ref_face = refface_array[i];
4208 : : // temp_box = ref_face->bounding_box();
4209 : : // faces_in_range.clean_out();
4210 : : // r_tree->find(temp_box, faces_in_range);
4211 : : // for ( j = 0; j<faces_in_range.size(); j++)
4212 : : // {
4213 : : // ref_face1 = faces_in_range.get_and_step();
4214 : : // temp_box2 = ref_face1->bounding_box();
4215 : : // if ( temp_box.overlap(tol, temp_box2) )
4216 : : // hit++;
4217 : : // }
4218 : : // }
4219 : : // PRINT_INFO( "RSTARTREE: Total Merge Reffaces time: %f secs\n"
4220 : : // "\tTime to build: %f secs\n",
4221 : : // timer.cpu_secs()+time_to_build, time_to_build );
4222 : : // }
4223 : 0 : void MergeTool::test_no_tree(DLIList <RefFace*> &refface_list)
4224 : : {
4225 [ # # ]: 0 : CpuTimer timer;
4226 [ # # ]: 0 : double geom_factor = GeometryQueryTool::get_geometry_factor();
4227 : 0 : double tol = GEOMETRY_RESABS*geom_factor;
4228 [ # # ][ # # ]: 0 : DLIList<RefFace*> refface_array( refface_list.size() );
4229 [ # # ]: 0 : refface_list.reset();
4230 : :
4231 : : // Remove entities that should not be automatically merged
4232 : 0 : int i = 0;
4233 : : int j;
4234 [ # # ]: 0 : int loop_size = refface_list.size();
4235 [ # # ]: 0 : for( i = 0; i < loop_size; i++ )
4236 : : {
4237 [ # # ]: 0 : RefFace *curr_face = refface_list.get_and_step();
4238 [ # # ][ # # ]: 0 : if( curr_face->is_mergeable() )
4239 [ # # ]: 0 : refface_array.append( curr_face );
4240 : : }
4241 : : //initialize the marked flag for fast nulification...
4242 [ # # ]: 0 : int array_size = refface_array.size();
4243 : : RefFace *ref_face, *ref_face1;
4244 [ # # ][ # # ]: 0 : CubitBox temp_box, temp_box2;
[ # # ][ # # ]
4245 : 0 : int hit = 0;
4246 [ # # ]: 0 : for ( i = 0; i < array_size; i++ )
4247 : : {
4248 [ # # ]: 0 : ref_face = refface_array[i];
4249 [ # # ][ # # ]: 0 : temp_box = ref_face->bounding_box();
[ # # ]
4250 [ # # ]: 0 : for ( j = i+1; j<array_size; j++)
4251 : : {
4252 [ # # ]: 0 : ref_face1 = refface_array[j];
4253 [ # # ][ # # ]: 0 : temp_box2 = ref_face1->bounding_box();
[ # # ]
4254 [ # # ][ # # ]: 0 : if ( temp_box.overlap(tol, temp_box2) )
4255 : 0 : hit++;
4256 : : }
4257 : : }
4258 [ # # ][ # # ]: 0 : PRINT_INFO( "NO TREE: Merge Reffaces time: %f secs\n",
[ # # ][ # # ]
4259 [ # # ][ # # ]: 0 : timer.cpu_secs() );
4260 : 0 : }
4261 : :
4262 : :
4263 : : //-------------------------------------------------------------------------
4264 : : // Purpose : Force-merge vertices
4265 : : //
4266 : : // Special Notes :
4267 : : //
4268 : : // Creator : Jason Kraftcheck
4269 : : //
4270 : : // Creation Date : 05/10/04
4271 : : //-------------------------------------------------------------------------
4272 : 0 : RefVertex* MergeTool::force_merge( RefVertex* vtx1, RefVertex* vtx2 )
4273 : : {
4274 [ # # ]: 0 : if (vtx1 == vtx2)
4275 : 0 : return vtx1;
4276 : :
4277 [ # # ][ # # ]: 0 : if (vtx1->id() > vtx2->id())
[ # # ]
4278 [ # # ]: 0 : std::swap(vtx1, vtx2);
4279 : :
4280 [ # # ][ # # ]: 0 : DLIList<RefFace*> faces1, faces2;
[ # # ]
4281 [ # # ][ # # ]: 0 : DLIList<RefEdge*> edges1, edges2;
[ # # ][ # # ]
4282 : :
4283 [ # # ]: 0 : vtx1->ref_faces( faces1 );
4284 [ # # ]: 0 : vtx2->ref_faces( faces2 );
4285 [ # # ]: 0 : faces1.intersect( faces2 );
4286 [ # # ][ # # ]: 0 : if (faces1.size())
4287 : : {
4288 [ # # ][ # # ]: 0 : PRINT_ERROR("Vertices %d and %d are both in Surface %d. "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4289 : : "Cannot merge vertices in the same surface.\n",
4290 [ # # ]: 0 : vtx1->id(), vtx2->id(), faces1.get()->id());
4291 : 0 : return NULL;
4292 : : }
4293 : :
4294 [ # # ]: 0 : vtx1->ref_edges( edges1 );
4295 [ # # ]: 0 : vtx2->ref_edges( edges2 );
4296 [ # # ]: 0 : edges1.intersect( edges2 );
4297 [ # # ][ # # ]: 0 : if (edges1.size())
4298 : : {
4299 [ # # ][ # # ]: 0 : PRINT_ERROR("Vertices %d and %d are both in Curve %d. "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4300 : : "Cannot merge vertices in the same curve.\n",
4301 [ # # ]: 0 : vtx1->id(), vtx2->id(), edges1.get()->id());
4302 : 0 : return NULL;
4303 : : }
4304 : :
4305 : : int k;
4306 [ # # ][ # # ]: 0 : for( k = assistant_list_.size(); k > 0; k-- )
4307 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()->can_merge( vtx1, vtx2 ) )
[ # # ]
4308 : 0 : break;
4309 : :
4310 [ # # ]: 0 : if (k)
4311 : 0 : return NULL;
4312 : :
4313 [ # # ][ # # ]: 0 : if (!merge_BTE( vtx1, vtx2 ))
4314 : 0 : return NULL;
4315 : :
4316 [ # # ]: 0 : if (destroyDeadGeometry)
4317 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
4318 : :
4319 [ # # ]: 0 : return vtx1;
4320 : : }
4321 : :
4322 : :
4323 : : //-------------------------------------------------------------------------
4324 : : // Purpose : Force-merge curves
4325 : : //
4326 : : // Special Notes :
4327 : : //
4328 : : // Creator : Jason Kraftcheck
4329 : : //
4330 : : // Creation Date : 05/10/04
4331 : : //-------------------------------------------------------------------------
4332 : 0 : RefEdge* MergeTool::force_merge( RefEdge* edge1, RefEdge* edge2 )
4333 : : {
4334 [ # # ]: 0 : if (edge1 == edge2)
4335 : 0 : return edge1;
4336 : :
4337 [ # # ][ # # ]: 0 : if (edge1->id() > edge2->id())
[ # # ]
4338 [ # # ]: 0 : std::swap(edge1, edge2);
4339 : :
4340 [ # # ][ # # ]: 0 : DLIList<RefFace*> faces1, faces2;
[ # # ]
4341 : :
4342 [ # # ]: 0 : edge1->ref_faces( faces1 );
4343 [ # # ]: 0 : edge2->ref_faces( faces2 );
4344 [ # # ]: 0 : faces1.intersect( faces2 );
4345 [ # # ][ # # ]: 0 : if (faces1.size())
4346 : : {
4347 [ # # ][ # # ]: 0 : PRINT_ERROR("Curves %d and %d are both in Surface %d. "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4348 : : "Cannot merge curves in the same surface.\n",
4349 [ # # ]: 0 : edge1->id(), edge2->id(), faces1.get()->id());
4350 : 0 : return NULL;
4351 : : }
4352 : :
4353 [ # # ][ # # ]: 0 : bool closed1 = edge1->start_vertex() == edge1->end_vertex();
4354 [ # # ][ # # ]: 0 : bool closed2 = edge2->start_vertex() == edge2->end_vertex();
4355 [ # # ]: 0 : if (closed1 != closed2)
4356 : : {
4357 [ # # ][ # # ]: 0 : PRINT_ERROR("Curves %d and %d do not have the same number of vertices.\n",
[ # # ][ # # ]
[ # # ]
4358 [ # # ]: 0 : edge1->id(), edge2->id());
4359 : 0 : return NULL;
4360 : : }
4361 : :
4362 : : int k;
4363 [ # # ][ # # ]: 0 : for( k = assistant_list_.size(); k > 0; k-- )
4364 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()->can_merge( edge1, edge2 ) )
[ # # ]
4365 : 0 : break;
4366 : :
4367 [ # # ]: 0 : if (k)
4368 : 0 : return NULL;
4369 : :
4370 : :
4371 : : CubitSense sense;
4372 : : CubitBoolean equal;
4373 [ # # ][ # # ]: 0 : if (!edge1->relative_sense( edge2, 1.0, &sense, equal, true))
4374 : 0 : return NULL;
4375 : :
4376 [ # # ]: 0 : if (closed1)
4377 : : {
4378 [ # # ][ # # ]: 0 : if (edge1->start_vertex() != edge2->start_vertex())
[ # # ]
4379 [ # # ][ # # ]: 0 : edge1->start_vertex()->comparison_found( edge2->start_vertex());
[ # # ][ # # ]
4380 : : }
4381 : : else
4382 : : {
4383 [ # # ]: 0 : RefVertex *start2 = edge2->start_vertex();
4384 [ # # ]: 0 : RefVertex *end2 = edge2->end_vertex();
4385 [ # # ]: 0 : if (sense == CUBIT_REVERSED)
4386 [ # # ]: 0 : std::swap(start2, end2);
4387 : :
4388 [ # # ][ # # ]: 0 : if (edge1->start_vertex() == end2 || edge1->end_vertex() == start2)
[ # # ][ # # ]
[ # # ]
4389 : : {
4390 [ # # ][ # # ]: 0 : PRINT_ERROR("Error merging curves: invalid relative sense calculation.\n");
[ # # ][ # # ]
4391 : 0 : return NULL;
4392 : : }
4393 : :
4394 [ # # ][ # # ]: 0 : if (edge1->start_vertex() != start2)
4395 [ # # ][ # # ]: 0 : edge1->start_vertex()->comparison_found( start2 );
[ # # ]
4396 [ # # ][ # # ]: 0 : if (edge1->end_vertex() != end2)
4397 [ # # ][ # # ]: 0 : edge1->end_vertex()->comparison_found( end2 );
[ # # ]
4398 : : }
4399 : :
4400 [ # # ][ # # ]: 0 : if (!merge_BTE( edge1, edge2 ))
4401 : : {
4402 [ # # ][ # # ]: 0 : PRINT_ERROR("Merge failed.\n");
[ # # ][ # # ]
4403 [ # # ]: 0 : remove_compare_data();
4404 : 0 : return NULL;
4405 : : }
4406 : :
4407 [ # # ]: 0 : remove_compare_data();
4408 [ # # ]: 0 : if (destroyDeadGeometry)
4409 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
4410 : :
4411 [ # # ]: 0 : return edge1;
4412 : : }
4413 : :
4414 : : //-------------------------------------------------------------------------
4415 : : // Purpose : Force-merge RefFaces
4416 : : //
4417 : : // Special Notes :
4418 : : //
4419 : : // Creator : Jason Kraftcheck
4420 : : //
4421 : : // Creation Date : 05/10/04
4422 : : //-------------------------------------------------------------------------
4423 : 0 : RefFace* MergeTool::force_merge( RefFace* face1, RefFace* face2 )
4424 : : {
4425 [ # # ]: 0 : if (face1 == face2)
4426 : 0 : return face1;
4427 : :
4428 : : int i, j;
4429 [ # # ][ # # ]: 0 : if (face1->id() > face2->id())
[ # # ]
4430 [ # # ]: 0 : std::swap(face1, face2);
4431 : :
4432 [ # # ][ # # ]: 0 : DLIList<RefVolume*> vols1, vols2;
[ # # ]
4433 : :
4434 [ # # ]: 0 : face1->ref_volumes( vols1 );
4435 [ # # ]: 0 : face2->ref_volumes( vols2 );
4436 [ # # ]: 0 : vols1.intersect( vols2 );
4437 [ # # ][ # # ]: 0 : if (vols1.size())
4438 : : {
4439 [ # # ][ # # ]: 0 : PRINT_ERROR("Surfaces %d and %d are both in Volume %d. "
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4440 : : "Cannot merge surfaces in the same volume.\n",
4441 [ # # ]: 0 : face1->id(), face2->id(), vols1.get()->id());
4442 : 0 : return NULL;
4443 : : }
4444 : :
4445 [ # # ][ # # ]: 0 : DLIList<RefVertex*> vertices1, vertices2;
[ # # ][ # # ]
4446 [ # # ][ # # ]: 0 : DLIList<Loop*> loops1, loops2, tmp_loops;
[ # # ][ # # ]
[ # # ][ # # ]
4447 : :
4448 [ # # ]: 0 : face1->loops( loops1 );
4449 [ # # ]: 0 : face2->loops( loops2 );
4450 [ # # ]: 0 : face1->ref_vertices( vertices1 );
4451 [ # # ]: 0 : face2->ref_vertices( vertices2 );
4452 : :
4453 [ # # ][ # # ]: 0 : if (loops1.size() != loops2.size() || vertices1.size() != vertices2.size())
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4454 : : {
4455 [ # # ][ # # ]: 0 : PRINT_ERROR("Surfaces %d and %d do not have equivalent topology.\n",
[ # # ][ # # ]
[ # # ]
4456 [ # # ]: 0 : face1->id(), face2->id() );
4457 : 0 : return 0;
4458 : : }
4459 : :
4460 : : // Need relative sense so we know in which order to compare
4461 : : // coedges of a loop and the expected sense of the coedges.
4462 [ # # ]: 0 : CubitSense rel_sense = face1->compare_alignment( face2 );
4463 [ # # ]: 0 : if (rel_sense == CUBIT_UNKNOWN)
4464 : : {
4465 [ # # ][ # # ]: 0 : PRINT_ERROR("Cound not calculate relative sense of surfaces.\n");
[ # # ][ # # ]
4466 : 0 : return 0;
4467 : : }
4468 : :
4469 : : // Remove from consideration any vertices that are already merged.
4470 [ # # ][ # # ]: 0 : DLIList<RefVertex*> common( vertices1 );
4471 [ # # ]: 0 : common.intersect( vertices2 );
4472 [ # # ]: 0 : vertices1 -= common;
4473 [ # # ]: 0 : vertices2 -= common;
4474 : :
4475 : : // Match vertex pairs
4476 [ # # ]: 0 : vertices1.reset();
4477 [ # # ][ # # ]: 0 : for (i = vertices1.size(); i--; )
4478 : : {
4479 [ # # ]: 0 : RefVertex* vtx1 = vertices1.get_and_step();
4480 : :
4481 : 0 : RefVertex* closest = 0;
4482 : 0 : double shortest = CUBIT_DBL_MAX;
4483 [ # # ]: 0 : vertices2.reset();
4484 [ # # ][ # # ]: 0 : for (j = vertices2.size(); j--; )
4485 : : {
4486 [ # # ]: 0 : RefVertex* vtx2 = vertices2.get_and_step();
4487 [ # # ][ # # ]: 0 : double d = (vtx1->coordinates() - vtx2->coordinates()).length_squared();
[ # # ][ # # ]
4488 [ # # ]: 0 : if (d < shortest)
4489 : : {
4490 : 0 : shortest = d;
4491 : 0 : closest = vtx2;
4492 : : }
4493 : : }
4494 : :
4495 [ # # ]: 0 : vertices2.move_to( closest );
4496 [ # # ]: 0 : vertices2.extract();
4497 [ # # ]: 0 : if (vtx1 != closest)
4498 [ # # ][ # # ]: 0 : vtx1->comparison_found( closest );
4499 : : }
4500 : :
4501 : : // Compare all loops, find RefEdge merge pairs
4502 [ # # ][ # # ]: 0 : DLIList<CoEdge*> coedges1, coedges2;
[ # # ][ # # ]
4503 [ # # ]: 0 : loops1.reset();
4504 [ # # ][ # # ]: 0 : for (i = loops1.size(); i--; )
4505 : : {
4506 [ # # ]: 0 : Loop* loop1 = loops1.get_and_step();
4507 : :
4508 : : // Given a vertex in a loop in the first surface,
4509 : : // find the loop connected to that vertex and in
4510 : : // the second surface.
4511 [ # # ]: 0 : vertices1.clean_out();
4512 [ # # ]: 0 : loop1->ref_vertices( vertices1 );
4513 [ # # ]: 0 : RefVertex* vtx = vertices1.get();
4514 [ # # ][ # # ]: 0 : if (vtx->get_compare_partner())
4515 [ # # ][ # # ]: 0 : vtx = dynamic_cast<RefVertex*>(vtx->get_compare_partner());
4516 [ # # ]: 0 : tmp_loops.clean_out();
4517 [ # # ]: 0 : vtx->loops( tmp_loops );
4518 : 0 : Loop* loop2 = 0;
4519 [ # # ][ # # ]: 0 : for (j = tmp_loops.size(); j--; )
4520 : : {
4521 [ # # ][ # # ]: 0 : if (tmp_loops.step_and_get()->get_ref_face_ptr() == face2)
[ # # ]
4522 : : {
4523 [ # # ]: 0 : loop2 = tmp_loops.get();
4524 : 0 : break;
4525 : : }
4526 : : }
4527 : :
4528 [ # # ][ # # ]: 0 : if (!loop2 || !loops2.move_to(loop2))
[ # # ][ # # ]
4529 : : {
4530 [ # # ][ # # ]: 0 : PRINT_ERROR("RefFace topology does not match. Cannot merge surfaces %d and %d.\n", face1->id(), face2->id());
[ # # ][ # # ]
[ # # ][ # # ]
4531 [ # # ]: 0 : remove_compare_data();
4532 : 0 : return 0;
4533 : : }
4534 [ # # ]: 0 : loops2.extract();
4535 : :
4536 : : // Compare loop coedges
4537 [ # # ]: 0 : coedges1.clean_out();
4538 [ # # ]: 0 : coedges2.clean_out();
4539 [ # # ]: 0 : loop1->co_edges( coedges1 );
4540 [ # # ]: 0 : loop2->co_edges( coedges2 );
4541 [ # # ][ # # ]: 0 : if (coedges1.size() != coedges2.size())
[ # # ]
4542 : : {
4543 [ # # ][ # # ]: 0 : PRINT_ERROR("RefFace topology does not match. Cannot merge surfaces %d and %d.\n", face1->id(), face2->id());
[ # # ][ # # ]
[ # # ][ # # ]
4544 [ # # ]: 0 : remove_compare_data();
4545 : 0 : return 0;
4546 : : }
4547 [ # # ]: 0 : if (CUBIT_REVERSED == rel_sense)
4548 [ # # ]: 0 : coedges2.reverse();
4549 : :
4550 : : // Given a coedge in the first loop, find the
4551 : : // matching coedge in the second loop
4552 [ # # ]: 0 : coedges1.reset();
4553 [ # # ]: 0 : coedges2.reset();
4554 [ # # ][ # # ]: 0 : RefVertex* start1 = coedges1.get()->start_vertex();
4555 [ # # ][ # # ]: 0 : RefVertex* end1 = coedges1.get()->end_vertex();
4556 [ # # ]: 0 : if (CUBIT_REVERSED == rel_sense)
4557 [ # # ]: 0 : std::swap(start1, end1);
4558 [ # # ][ # # ]: 0 : if (start1->get_compare_partner())
4559 [ # # ][ # # ]: 0 : start1 = dynamic_cast<RefVertex*>(start1->get_compare_partner());
4560 [ # # ][ # # ]: 0 : if (end1->get_compare_partner())
4561 [ # # ][ # # ]: 0 : end1 = dynamic_cast<RefVertex*>(end1->get_compare_partner());
4562 : :
4563 [ # # ][ # # ]: 0 : for (j = coedges2.size(); j > 0; j-- )
4564 : : {
4565 [ # # ][ # # ]: 0 : if (coedges2.get()->start_vertex() == start1 &&
[ # # ][ # # ]
[ # # ]
4566 [ # # ][ # # ]: 0 : coedges2.get()->end_vertex() == end1)
4567 : 0 : break;
4568 : :
4569 [ # # ]: 0 : coedges2.step();
4570 : : }
4571 : :
4572 : : // No matching coedge
4573 [ # # ]: 0 : if (!j)
4574 : : {
4575 [ # # ][ # # ]: 0 : PRINT_ERROR("RefFace topology does not match. Cannot merge surfaces %d and %d.\n", face1->id(), face2->id());
[ # # ][ # # ]
[ # # ][ # # ]
4576 [ # # ]: 0 : remove_compare_data();
4577 : 0 : return 0;
4578 : : }
4579 : :
4580 : : // Check that remaining coedges match, and mark RefEdges accordingly
4581 [ # # ][ # # ]: 0 : for (j = coedges1.size(); j--; )
4582 : : {
4583 [ # # ]: 0 : CoEdge* coedge1 = coedges1.get_and_step();
4584 [ # # ]: 0 : CoEdge* coedge2 = coedges2.get_and_step();
4585 [ # # ][ # # ]: 0 : if (coedge1->get_ref_edge_ptr() == coedge2->get_ref_edge_ptr())
[ # # ]
4586 : 0 : continue;
4587 : :
4588 [ # # ]: 0 : RefVertex* start1 = coedge1->start_vertex();
4589 [ # # ]: 0 : RefVertex* end1 = coedge1->end_vertex();
4590 [ # # ]: 0 : if (CUBIT_REVERSED == rel_sense)
4591 [ # # ]: 0 : std::swap(start1, end1);
4592 [ # # ][ # # ]: 0 : if (start1->get_compare_partner())
4593 [ # # ][ # # ]: 0 : start1 = dynamic_cast<RefVertex*>(start1->get_compare_partner());
4594 [ # # ][ # # ]: 0 : if (end1->get_compare_partner())
4595 [ # # ][ # # ]: 0 : end1 = dynamic_cast<RefVertex*>(end1->get_compare_partner());
4596 : :
4597 [ # # ][ # # ]: 0 : if (coedge2->start_vertex() != start1 ||
[ # # ][ # # ]
4598 [ # # ]: 0 : coedge2->end_vertex() != end1)
4599 : : {
4600 [ # # ][ # # ]: 0 : PRINT_ERROR("RefFace topology does not match. Merge aborted.\n");
[ # # ][ # # ]
4601 [ # # ]: 0 : remove_compare_data();
4602 : 0 : return 0;
4603 : : }
4604 : :
4605 [ # # ][ # # ]: 0 : coedge1->get_ref_edge_ptr()->comparison_found( coedge2->get_ref_edge_ptr());
[ # # ][ # # ]
4606 : : }
4607 : : } // for(loops1)
4608 : :
4609 : : // check if mesh can be merged, etc.
4610 [ # # ][ # # ]: 0 : for( i = assistant_list_.size(); i > 0; i-- )
4611 [ # # ][ # # ]: 0 : if( ! assistant_list_.get_and_step()->can_merge( face1, face2 ) )
[ # # ]
4612 [ # # ]: 0 : { remove_compare_data(); return 0; }
4613 : :
4614 : : // merge
4615 [ # # ][ # # ]: 0 : if (!merge_BTE( face1, face2 ))
4616 : : {
4617 [ # # ][ # # ]: 0 : PRINT_ERROR("Merge Failed.\n");
[ # # ][ # # ]
4618 [ # # ]: 0 : remove_compare_data();
4619 : 0 : return 0;
4620 : : }
4621 : :
4622 [ # # ]: 0 : remove_compare_data();
4623 [ # # ]: 0 : if (destroyDeadGeometry)
4624 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->cleanout_deactivated_geometry();
4625 : :
4626 [ # # ]: 0 : return face1;
4627 : : }
4628 : :
4629 : : //-------------------------------------------------------------------------
4630 : : // Purpose : Force-merge RefEntities
4631 : : //
4632 : : // Special Notes :
4633 : : //
4634 : : // Creator : Jason Kraftcheck
4635 : : //
4636 : : // Creation Date : 05/10/04
4637 : : //-------------------------------------------------------------------------
4638 : 0 : RefEntity* MergeTool::force_merge( RefEntity* ent1, RefEntity* ent2 )
4639 : : {
4640 [ # # ][ # # ]: 0 : if (RefFace* face1 = dynamic_cast<RefFace*>(ent1))
4641 : : {
4642 [ # # ][ # # ]: 0 : if (RefFace* face2 = dynamic_cast<RefFace*>(ent2))
4643 [ # # ]: 0 : return force_merge( face1, face2 );
4644 : : }
4645 [ # # ][ # # ]: 0 : else if (RefEdge* edge1 = dynamic_cast<RefEdge*>(ent1))
4646 : : {
4647 [ # # ][ # # ]: 0 : if (RefEdge* edge2 = dynamic_cast<RefEdge*>(ent2))
4648 [ # # ]: 0 : return force_merge( edge1, edge2 );
4649 : : }
4650 [ # # ][ # # ]: 0 : else if (RefVertex* vtx1 = dynamic_cast<RefVertex*>(ent1))
4651 : : {
4652 [ # # ][ # # ]: 0 : if (RefVertex* vtx2 = dynamic_cast<RefVertex*>(ent2))
4653 [ # # ]: 0 : return force_merge( vtx1, vtx2 );
4654 : : }
4655 : :
4656 [ # # ][ # # ]: 0 : PRINT_ERROR("Invalid entities passed to MergeTool::force_merge\n");
4657 : 0 : return NULL;
4658 : : }
4659 : :
4660 : : //-------------------------------------------------------------------------
4661 : : // Purpose : Force-merge RefEntities
4662 : : //
4663 : : // Special Notes : Provied for use by CAMergeAttribute only
4664 : : //
4665 : : // Creator : Jason Kraftcheck
4666 : : //
4667 : : // Creation Date : 05/10/04
4668 : : //-------------------------------------------------------------------------
4669 : 0 : RefEntity* MergeTool::force_merge( const DLIList<RefEntity*>& list )
4670 : : {
4671 : 0 : RefEntity* result = list.get();
4672 [ # # ][ # # ]: 0 : for (int i = 1; result && i < list.size(); i++ )
[ # # ]
4673 : 0 : result = force_merge( list.next(i), result );
4674 : 0 : return result;
4675 : : }
4676 : :
4677 : : //-------------------------------------------------------------------------
4678 : : // Purpose : Un-merge
4679 : : //
4680 : : // Special Notes :
4681 : : //
4682 : : // Creator : Jason Kraftcheck
4683 : : //
4684 : : // Creation Date : 06/01/04
4685 : : //-------------------------------------------------------------------------
4686 : 0 : CubitStatus MergeTool::separate_bodies( DLIList<Body*>& separate_list,
4687 : : DLIList<Body*>* from_list )
4688 : : {
4689 [ # # ]: 0 : CubitBoolean top = start_unmerge();
4690 [ # # ][ # # ]: 0 : DLIList<RefVolume*> volume_list, tmp_list;
[ # # ]
4691 [ # # ]: 0 : separate_list.reset();
4692 [ # # ][ # # ]: 0 : for (int i = separate_list.size(); i--; )
4693 : : {
4694 [ # # ]: 0 : Body* body = separate_list.get_and_step();
4695 [ # # ]: 0 : tmp_list.clean_out();
4696 [ # # ]: 0 : body->ref_volumes( tmp_list );
4697 [ # # ]: 0 : volume_list += tmp_list;
4698 : : }
4699 : :
4700 : : CubitStatus result;
4701 [ # # ]: 0 : if (from_list == NULL)
4702 : : {
4703 [ # # ]: 0 : result = separate_volumes( volume_list, NULL );
4704 : : }
4705 : : else
4706 : : {
4707 [ # # ]: 0 : DLIList<RefVolume*> from_vols;
4708 [ # # ]: 0 : from_list->reset();
4709 [ # # ][ # # ]: 0 : for (int i = from_list->size(); i--; )
4710 : : {
4711 [ # # ]: 0 : Body* body = from_list->get_and_step();
4712 [ # # ]: 0 : tmp_list.clean_out();
4713 [ # # ]: 0 : body->ref_volumes( tmp_list );
4714 [ # # ]: 0 : from_vols += tmp_list;
4715 : : }
4716 : :
4717 [ # # ][ # # ]: 0 : result = separate_volumes( volume_list, &from_vols );
4718 : : }
4719 : :
4720 [ # # ]: 0 : end_unmerge(top);
4721 [ # # ]: 0 : return result;
4722 : : }
4723 : :
4724 : : //-------------------------------------------------------------------------
4725 : : // Purpose : Unmerge
4726 : : //
4727 : : // Special Notes :
4728 : : //
4729 : : // Creator : Jason Kraftcheck
4730 : : //
4731 : : // Creation Date : 06/01/04
4732 : : //-------------------------------------------------------------------------
4733 : 0 : CubitStatus MergeTool::separate_volumes( DLIList<RefVolume*>& split_list,
4734 : : DLIList<RefVolume*>* from_list )
4735 : : {
4736 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> entity_list( split_list.size() );
4737 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( split_list, entity_list );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4738 [ # # ]: 0 : if (from_list)
4739 : : {
4740 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> from_list2( from_list->size() );
4741 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( *from_list, from_list2 );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4742 [ # # ][ # # ]: 0 : return separate_entities( entity_list, &from_list2 );
4743 : : }
4744 : : else
4745 : : {
4746 [ # # ]: 0 : return separate_entities( entity_list );
4747 [ # # ]: 0 : }
4748 : : }
4749 : 0 : CubitStatus MergeTool::separate_faces( DLIList<RefFace*>& split_list,
4750 : : DLIList<RefFace*>* from_list )
4751 : : {
4752 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> entity_list( split_list.size() );
4753 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( split_list, entity_list );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4754 [ # # ]: 0 : if (from_list)
4755 : : {
4756 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> from_list2( from_list->size() );
4757 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( *from_list, from_list2 );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4758 [ # # ][ # # ]: 0 : return separate_entities( entity_list, &from_list2 );
4759 : : }
4760 : : else
4761 : : {
4762 [ # # ]: 0 : return separate_entities( entity_list );
4763 [ # # ]: 0 : }
4764 : : }
4765 : 0 : CubitStatus MergeTool::separate_edges( DLIList<RefEdge*>& split_list,
4766 : : DLIList<RefEdge*>* from_list )
4767 : : {
4768 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> entity_list( split_list.size() );
4769 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( split_list, entity_list );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4770 [ # # ]: 0 : if (from_list)
4771 : : {
4772 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> from_list2( from_list->size() );
4773 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( *from_list, from_list2 );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4774 [ # # ][ # # ]: 0 : return separate_entities( entity_list, &from_list2 );
4775 : : }
4776 : : else
4777 : : {
4778 [ # # ]: 0 : return separate_entities( entity_list );
4779 [ # # ]: 0 : }
4780 : : }
4781 : :
4782 : :
4783 : : //-------------------------------------------------------------------------
4784 : : // Purpose : Unmerge
4785 : : //
4786 : : // Special Notes :
4787 : : //
4788 : : // Creator : Jason Kraftcheck
4789 : : //
4790 : : // Creation Date : 06/02/04
4791 : : //-------------------------------------------------------------------------
4792 : 0 : CubitStatus MergeTool::separate_entities( DLIList<TopologyEntity*>& volume_list,
4793 : : DLIList<TopologyEntity*>* from_list )
4794 : : {
4795 : : int i, j, k, l;
4796 [ # # ]: 0 : CubitBoolean top = start_unmerge();
4797 : 0 : CubitStatus result = CUBIT_SUCCESS;
4798 : :
4799 [ # # ][ # # ]: 0 : if (!volume_list.size())
4800 : 0 : return CUBIT_FAILURE;
4801 : :
4802 [ # # ][ # # ]: 0 : DagType parent_type = volume_list.get()->dag_type();
4803 [ # # ][ # # ]: 0 : for (i = volume_list.size(); i--;)
4804 [ # # ][ # # ]: 0 : if (volume_list.get_and_step()->dag_type() != parent_type)
[ # # ][ # # ]
4805 : 0 : return CUBIT_FAILURE;
4806 [ # # ]: 0 : if (from_list)
4807 [ # # ][ # # ]: 0 : for (i = from_list->size(); i--; )
4808 [ # # ][ # # ]: 0 : if (from_list->get_and_step()->dag_type() != parent_type)
[ # # ][ # # ]
4809 : 0 : return CUBIT_FAILURE;
4810 : :
4811 : :
4812 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> query_input( volume_list.size() ), query_output;
[ # # ][ # # ]
4813 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( volume_list, query_input );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4814 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list, split_list, parent_bridges;
[ # # ][ # # ]
[ # # ][ # # ]
4815 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> entity_vol_list;
4816 [ # # ][ # # ]: 0 : DLIList<BasicTopologyEntity*> entity_list;
4817 [ # # ][ # # ]: 0 : DLIList<Lump*> lump_list;
4818 [ # # ][ # # ]: 0 : DLIList<Surface*> surface_list;
4819 [ # # ][ # # ]: 0 : DLIList<Curve*> curve_list;
4820 [ # # ][ # # ]: 0 : DLIList<TBPoint*> point_list;
4821 : :
4822 : :
4823 : : // Loop once for each type,
4824 : : DagType types[] = { DagType::ref_face_type(),
4825 : : DagType::ref_edge_type(),
4826 [ # # ][ # # ]: 0 : DagType::ref_vertex_type() };
[ # # ]
4827 [ # # ]: 0 : for (j = 0; j < 3; j++)
4828 : : {
4829 [ # # ][ # # ]: 0 : if (types[j] >= parent_type)
4830 : 0 : continue;
4831 : :
4832 : : // Get RefFaces/RefEdges/RefVertices from RefVolumes
4833 [ # # ]: 0 : query_output.clean_out();
4834 [ # # ]: 0 : entity_list.clean_out();
4835 [ # # ][ # # ]: 0 : ModelQueryEngine::instance()->query_model( query_input, types[j], query_output );
4836 [ # # ][ # # ]: 0 : CAST_LIST( query_output, entity_list, BasicTopologyEntity );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4837 : :
4838 [ # # ]: 0 : entity_list.reset();
4839 [ # # ][ # # ]: 0 : for (i = entity_list.size(); i--; )
4840 : : {
4841 [ # # ]: 0 : BasicTopologyEntity* entity = entity_list.get_and_step();
4842 [ # # ]: 0 : split_list.clean_out();
4843 : :
4844 : : // Get parent volumes to unmerge from
4845 [ # # ]: 0 : entity_vol_list.clean_out();
4846 [ # # ]: 0 : query_output.clean_out();
4847 [ # # ][ # # ]: 0 : ModelQueryEngine::instance()->query_model( *entity, parent_type, query_output );
4848 [ # # ][ # # ]: 0 : CAST_LIST( query_output, entity_vol_list, TopologyEntity );
[ # # ][ # # ]
[ # # ][ # # ]
4849 [ # # ]: 0 : entity_vol_list -= volume_list;
4850 [ # # ]: 0 : if (from_list)
4851 [ # # ]: 0 : entity_vol_list.intersect( *from_list );
4852 [ # # ][ # # ]: 0 : if (!entity_vol_list.size())
4853 : 0 : continue;
4854 : :
4855 : : // For each merged bridge in the entity
4856 [ # # ]: 0 : bridge_list.clean_out();
4857 [ # # ][ # # ]: 0 : entity->bridge_manager()->get_bridge_list( bridge_list );
4858 [ # # ]: 0 : bridge_list.reset();
4859 [ # # ][ # # ]: 0 : for (k = bridge_list.size(); k--; )
4860 : : {
4861 [ # # ]: 0 : TopologyBridge* bridge = bridge_list.get_and_step();
4862 : :
4863 [ # # ]: 0 : parent_bridges.clean_out();
4864 [ # # ][ # # ]: 0 : if (parent_type == DagType::ref_volume_type())
[ # # ]
4865 : : {
4866 [ # # ]: 0 : lump_list.clean_out();
4867 [ # # ]: 0 : bridge->lumps( lump_list );
4868 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( lump_list, parent_bridges );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4869 : : }
4870 [ # # ][ # # ]: 0 : else if(parent_type == DagType::ref_face_type())
[ # # ]
4871 : : {
4872 [ # # ]: 0 : surface_list.clean_out();
4873 [ # # ]: 0 : bridge->surfaces( surface_list );
4874 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( surface_list, parent_bridges );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4875 : : }
4876 [ # # ][ # # ]: 0 : else if(parent_type == DagType::ref_edge_type())
[ # # ]
4877 : : {
4878 [ # # ]: 0 : curve_list.clean_out();
4879 [ # # ]: 0 : bridge->curves( curve_list );
4880 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( curve_list, parent_bridges );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
4881 : : }
4882 : : else
4883 : : {
4884 : 0 : assert(0);
4885 : : return CUBIT_FAILURE;
4886 : : }
4887 : :
4888 : : // Check if bridge is in RefVolumes to unmerge from
4889 : :
4890 [ # # ][ # # ]: 0 : for (l = parent_bridges.size(); l--; )
4891 : : {
4892 [ # # ]: 0 : TopologyBridge* lump = parent_bridges.get_and_step();
4893 [ # # ][ # # ]: 0 : if (entity_vol_list.is_in_list(lump->topology_entity()))
[ # # ]
4894 [ # # ]: 0 : split_list.append( bridge );
4895 : : }
4896 : : }
4897 : :
4898 : : // If there are bridges to unmerge...
4899 [ # # ][ # # ]: 0 : if (split_list.size() != 0 && split_list.size() != bridge_list.size())
[ # # ][ # # ]
[ # # ][ # # ]
4900 : : {
4901 [ # # ][ # # ]: 0 : if (types[j] == DagType::ref_face_type())
[ # # ]
4902 : : {
4903 [ # # ]: 0 : surface_list.clean_out();
4904 [ # # ][ # # ]: 0 : CAST_LIST( split_list, surface_list, Surface );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4905 [ # # ]: 0 : RefFace* face = separate_face( surface_list, false );
4906 [ # # ]: 0 : if (0 == face)
4907 : 0 : result = CUBIT_FAILURE;
4908 : : }
4909 [ # # ][ # # ]: 0 : else if(types[j] == DagType::ref_edge_type())
[ # # ]
4910 : : {
4911 [ # # ]: 0 : curve_list.clean_out();
4912 [ # # ][ # # ]: 0 : CAST_LIST( split_list, curve_list, Curve );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4913 [ # # ]: 0 : RefEdge* edge = separate_edge( curve_list, false );
4914 [ # # ]: 0 : if (0 == edge)
4915 : 0 : result = CUBIT_FAILURE;
4916 : : }
4917 : : else
4918 : : {
4919 [ # # ]: 0 : point_list.clean_out();
4920 [ # # ][ # # ]: 0 : CAST_LIST( split_list, point_list, TBPoint );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
4921 [ # # ][ # # ]: 0 : assert( split_list.size() == point_list.size() );
[ # # ]
4922 [ # # ]: 0 : RefVertex* vtx = separate_vertex( point_list );
4923 [ # # ]: 0 : if (0 == vtx)
4924 : 0 : result = CUBIT_FAILURE;
4925 : : }
4926 : : }
4927 : : } // for(i in entity_list)
4928 : : } // for(j in type)
4929 : :
4930 [ # # ]: 0 : end_unmerge(top);
4931 [ # # ]: 0 : return result;
4932 : : }
4933 : :
4934 : :
4935 : :
4936 : : //-------------------------------------------------------------------------
4937 : : // Purpose : Common code for separate functions.
4938 : : // Check if bridges have same owner (are merged together),
4939 : : // and if check_parents == true, check if unmerging the
4940 : : // bridges will invalidate the parent topology.
4941 : : //
4942 : : // Special Notes :
4943 : : //
4944 : : // Creator : Jason Kraftcheck
4945 : : //
4946 : : // Creation Date : 06/01/04
4947 : : //-------------------------------------------------------------------------
4948 : 0 : BasicTopologyEntity* MergeTool::can_separate( DLIList<TopologyBridge*>& bridges,
4949 : : bool check_parents )
4950 : : {
4951 : : int i;
4952 : 0 : BasicTopologyEntity* bte = 0;
4953 : :
4954 [ # # ][ # # ]: 0 : TBOwner* owner = bridges.get_and_step()->owner();
4955 [ # # ][ # # ]: 0 : for (i = bridges.size(); i > 1; i--)
4956 [ # # ][ # # ]: 0 : if (bridges.get_and_step()->owner() != owner)
[ # # ]
4957 : 0 : return 0;
4958 : :
4959 [ # # ]: 0 : BridgeManager* bmanager = dynamic_cast<BridgeManager*>(owner);
4960 [ # # ]: 0 : if (!bmanager)
4961 : 0 : { assert(0); return 0; }
4962 : :
4963 [ # # ][ # # ]: 0 : bte = dynamic_cast<BasicTopologyEntity*>(bmanager->topology_entity());
4964 [ # # ]: 0 : if (!bte)
4965 : 0 : { assert(0); return 0; }
4966 : :
4967 [ # # ][ # # ]: 0 : if (bmanager->number_of_bridges() == bridges.size())
[ # # ]
4968 : 0 : return 0;
4969 : :
4970 [ # # ]: 0 : if (!check_parents)
4971 : 0 : return bte;
4972 : :
4973 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> parent_bridges, bte_bridges;
[ # # ]
4974 [ # # ][ # # ]: 0 : DLIList<TBOwner*> parent_owners;
4975 [ # # ][ # # ]: 0 : bte->bridge_manager()->get_bridge_list( bte_bridges );
4976 [ # # ]: 0 : bte_bridges -= bridges;
4977 : :
4978 [ # # ][ # # ]: 0 : for (i = bte_bridges.size(); i--;)
4979 : : {
4980 [ # # ][ # # ]: 0 : bte_bridges.step_and_get()->get_parents( parent_bridges );
4981 [ # # ][ # # ]: 0 : while (parent_bridges.size())
4982 [ # # ][ # # ]: 0 : parent_owners.append( parent_bridges.pop()->owner() );
[ # # ]
4983 : : }
4984 [ # # ][ # # ]: 0 : for (i = bridges.size(); i--; )
4985 : : {
4986 [ # # ][ # # ]: 0 : bridges.step_and_get()->get_parents( parent_bridges );
4987 [ # # ][ # # ]: 0 : while (parent_bridges.size())
4988 [ # # ][ # # ]: 0 : if (parent_owners.is_in_list( parent_bridges.pop()->owner() ))
[ # # ][ # # ]
4989 : 0 : return 0;
4990 : : }
4991 : :
4992 [ # # ]: 0 : return bte;
4993 : : }
4994 : :
4995 : :
4996 : : //-------------------------------------------------------------------------
4997 : : // Purpose : Split a RefFace
4998 : : //
4999 : : // Special Notes :
5000 : : //
5001 : : // Creator : Jason Kraftcheck
5002 : : //
5003 : : // Creation Date : 06/01/04
5004 : : //-------------------------------------------------------------------------
5005 : 0 : RefFace* MergeTool::separate_face( DLIList<Surface*>& surfaces,
5006 : : bool unmerge_curves )
5007 : : {
5008 : : int i, j, k;
5009 : :
5010 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list( surfaces.size() );
5011 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( surfaces, bridge_list );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
5012 [ # # ][ # # ]: 0 : RefFace* old_face = dynamic_cast<RefFace*>( can_separate( bridge_list, false ) );
5013 [ # # ]: 0 : if (!old_face)
5014 : 0 : return 0;
5015 : :
5016 [ # # ]: 0 : CubitBoolean top = start_unmerge();
5017 : :
5018 : : // Split the RefFace
5019 : :
5020 : : // Remove surfaces from old entity
5021 [ # # ][ # # ]: 0 : for (i = surfaces.size(); i--; )
5022 [ # # ][ # # ]: 0 : old_face->bridge_manager()->remove_bridge( surfaces.get_and_step() );
[ # # ]
5023 [ # # ]: 0 : check_saved_id( old_face );
5024 [ # # ]: 0 : surfaces.reset();
5025 : : // Use surface with smallest saved ID as primary
5026 [ # # ][ # # ]: 0 : for (j = 0, i = 1; i < surfaces.size(); i++)
5027 [ # # ][ # # ]: 0 : if (surfaces.next(i)->get_saved_id() < surfaces.next(j)->get_saved_id())
[ # # ][ # # ]
[ # # ]
5028 : 0 : j = i;
5029 [ # # ]: 0 : surfaces.step( j );
5030 : : // Create new face
5031 [ # # ][ # # ]: 0 : RefFace* new_face = RefEntityFactory::instance()->construct_RefFace( surfaces.get() );
[ # # ]
5032 : :
5033 [ # # ][ # # ]: 0 : for (i = surfaces.size(); i > 1; i-- )
5034 [ # # ][ # # ]: 0 : new_face->bridge_manager()->add_bridge( surfaces.step_and_get() );
[ # # ]
5035 : :
5036 : : // Move CoFaces
5037 [ # # ]: 0 : bridge_list.clean_out();
5038 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_parents;
5039 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> shells;
5040 [ # # ][ # # ]: 0 : DLIList<CoFace*> co_faces;
5041 [ # # ]: 0 : old_face->co_faces( co_faces );
5042 [ # # ][ # # ]: 0 : for (i = surfaces.size(); i > 0; i--)
5043 : : {
5044 [ # # ][ # # ]: 0 : surfaces.get_and_step()->get_parents( bridge_list );
5045 [ # # ][ # # ]: 0 : while (bridge_list.size())
5046 [ # # ][ # # ]: 0 : shells.append( bridge_list.pop()->topology_entity() );
[ # # ]
5047 : : }
5048 [ # # ]: 0 : co_faces.reset();
5049 [ # # ][ # # ]: 0 : for (i = co_faces.size(); i--; )
5050 : : {
5051 [ # # ]: 0 : CoFace* co_face = co_faces.get_and_step();
5052 [ # # ][ # # ]: 0 : if (shells.is_in_list( co_face->get_grouping_entity_ptr() ))
[ # # ]
5053 : : {
5054 [ # # ]: 0 : co_face->switch_basic_topology_entity( new_face );
5055 : : }
5056 : : }
5057 : :
5058 : : // Split loops and coedges
5059 [ # # ][ # # ]: 0 : DLIList<Loop*> loops;
5060 [ # # ][ # # ]: 0 : DLIList<CoEdge*> coedges;
5061 [ # # ][ # # ]: 0 : DLIList<SenseEntity*> new_coedges, junk_list;
[ # # ][ # # ]
5062 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> loop_bridges;
5063 [ # # ]: 0 : old_face->loops( loops );
5064 [ # # ]: 0 : loops.reset();
5065 [ # # ][ # # ]: 0 : for (i = loops.size(); i--; )
5066 : : {
5067 [ # # ]: 0 : Loop* old_loop = loops.get_and_step();
5068 [ # # ][ # # ]: 0 : Loop* new_loop = new Loop;
5069 [ # # ]: 0 : new_face->add_grouping_entity( new_loop );
5070 : :
5071 [ # # ]: 0 : loop_bridges.clean_out();
5072 [ # # ]: 0 : bridge_list.clean_out();
5073 [ # # ][ # # ]: 0 : old_loop->bridge_manager()->get_bridge_list( bridge_list );
5074 [ # # ]: 0 : bridge_list.reset();
5075 [ # # ][ # # ]: 0 : for (j = bridge_list.size(); j--; )
5076 : : {
5077 [ # # ]: 0 : TopologyBridge* loopsm = bridge_list.get_and_step();
5078 [ # # ]: 0 : loopsm->get_parents( bridge_parents );
5079 [ # # ][ # # ]: 0 : Surface* loop_surf = dynamic_cast<Surface*>(bridge_parents.pop());
5080 [ # # ][ # # ]: 0 : assert (loop_surf && !bridge_parents.size());
[ # # ]
5081 [ # # ][ # # ]: 0 : if (surfaces.is_in_list(loop_surf))
5082 : : {
5083 [ # # ][ # # ]: 0 : old_loop->bridge_manager()->remove_bridge( loopsm );
5084 [ # # ][ # # ]: 0 : new_loop->bridge_manager()->add_bridge( loopsm );
5085 [ # # ]: 0 : loop_bridges.append( loopsm );
5086 : : }
5087 : : }
5088 : :
5089 [ # # ]: 0 : new_coedges.clean_out();
5090 [ # # ]: 0 : coedges.clean_out();
5091 [ # # ]: 0 : old_loop->co_edges( coedges );
5092 [ # # ]: 0 : coedges.reset();
5093 [ # # ][ # # ]: 0 : for (j = coedges.size(); j--; )
5094 : : {
5095 [ # # ]: 0 : CoEdge* old_coedge = coedges.get_and_step();
5096 : : CoEdge* new_coedge = new CoEdge( old_coedge->get_ref_edge_ptr(),
5097 [ # # ][ # # ]: 0 : old_coedge->get_sense() );
[ # # ][ # # ]
5098 [ # # ]: 0 : new_coedges.append( new_coedge );
5099 : :
5100 [ # # ]: 0 : bridge_list.clean_out();
5101 [ # # ][ # # ]: 0 : old_coedge->bridge_manager()->get_bridge_list( bridge_list );
5102 [ # # ]: 0 : bridge_list.reset();
5103 [ # # ][ # # ]: 0 : for (k = bridge_list.size(); k--; )
5104 : : {
5105 [ # # ]: 0 : TopologyBridge* coedgesm = bridge_list.get_and_step();
5106 [ # # ]: 0 : coedgesm->get_parents( bridge_parents );
5107 [ # # ][ # # ]: 0 : LoopSM* coedgesm_loop = dynamic_cast<LoopSM*>(bridge_parents.pop());
5108 [ # # ][ # # ]: 0 : assert (coedgesm_loop && !bridge_parents.size());
[ # # ]
5109 [ # # ][ # # ]: 0 : if (loop_bridges.is_in_list(coedgesm_loop))
5110 : : {
5111 [ # # ][ # # ]: 0 : old_coedge->bridge_manager()->remove_bridge( coedgesm );
5112 [ # # ][ # # ]: 0 : new_coedge->bridge_manager()->add_bridge( coedgesm );
5113 : : }
5114 : : }
5115 : : }
5116 : :
5117 [ # # ]: 0 : new_loop->set_sense_entity_list( new_coedges, junk_list );
5118 : : }
5119 : :
5120 : : // Check if should reverse new face
5121 : 0 : bool reverse_new = true;
5122 [ # # ][ # # ]: 0 : for (i = surfaces.size(); i--; )
5123 [ # # ][ # # ]: 0 : if (surfaces.get_and_step()->bridge_sense() != CUBIT_REVERSED)
[ # # ]
5124 : 0 : reverse_new = false;
5125 [ # # ]: 0 : if (reverse_new)
5126 : : {
5127 [ # # ][ # # ]: 0 : new_face->bridge_manager()->reverse_bridge_senses();
5128 [ # # ]: 0 : new_face->reverse_topology();
5129 : : }
5130 : :
5131 : : // Check if should reverse old face
5132 : 0 : bool reverse_old = true;
5133 [ # # ]: 0 : bridge_list.clean_out();
5134 [ # # ][ # # ]: 0 : old_face->bridge_manager()->get_bridge_list( bridge_list );
5135 [ # # ][ # # ]: 0 : for (i = bridge_list.size(); i--; )
5136 [ # # ][ # # ]: 0 : if (bridge_list.get_and_step()->bridge_sense() != CUBIT_REVERSED)
[ # # ]
5137 : 0 : reverse_old = false;
5138 [ # # ]: 0 : if (reverse_old)
5139 : : {
5140 [ # # ][ # # ]: 0 : old_face->bridge_manager()->reverse_bridge_senses();
5141 [ # # ]: 0 : old_face->reverse_topology();
5142 : : }
5143 : :
5144 : : // Misc stuff for updating other code for changed topology
5145 : 0 : bool reversed = reverse_old != reverse_new;
5146 [ # # ][ # # ]: 0 : new_unmerged.append( new_face );
5147 [ # # ][ # # ]: 0 : old_unmerged.append( old_face );
5148 [ # # ][ # # ]: 0 : for (i = assistant_list_.size(); i--; )
5149 [ # # ][ # # ]: 0 : assistant_list_.get_and_step()->unmerged( old_face, new_face, reversed );
[ # # ][ # # ]
5150 : :
5151 [ # # ]: 0 : if (unmerge_curves)
5152 : : {
5153 [ # # ]: 0 : DLIList<RefEdge*> edge_list;
5154 [ # # ][ # # ]: 0 : DLIList<Curve*> curve_list;
5155 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_children;
5156 [ # # ]: 0 : new_face->ref_edges( edge_list );
5157 [ # # ]: 0 : edge_list.reset();
5158 : :
5159 [ # # ][ # # ]: 0 : for (i = edge_list.size(); i--;)
5160 : : {
5161 [ # # ]: 0 : curve_list.clean_out();
5162 : :
5163 [ # # ]: 0 : RefEdge* edge = edge_list.get_and_step();
5164 [ # # ]: 0 : bridge_list.clean_out();
5165 [ # # ][ # # ]: 0 : edge->bridge_manager()->get_bridge_list( bridge_list );
5166 [ # # ][ # # ]: 0 : if (bridge_list.size() < 2)
5167 : 0 : continue;
5168 : :
5169 : : // Find the curve(s) in the just-unmerged refface
5170 [ # # ]: 0 : bridge_list.reset();
5171 [ # # ]: 0 : DLIList<Curve*> other_curves_to_unmerge;
5172 [ # # ][ # # ]: 0 : for (j = bridge_list.size(); j--; )
5173 : : {
5174 [ # # ]: 0 : TopologyBridge* bridge = bridge_list.get_and_step();
5175 [ # # ]: 0 : bridge_parents.clean_out();
5176 [ # # ]: 0 : bridge->get_parents( bridge_parents );
5177 [ # # ]: 0 : bridge_parents.reset();
5178 : 0 : bool in_old = false, in_new = false;
5179 : :
5180 [ # # ][ # # ]: 0 : while (bridge_parents.size())
5181 : : {
5182 [ # # ][ # # ]: 0 : CoEdge* coedge = dynamic_cast<CoEdge*>(bridge_parents.pop()->topology_entity());
[ # # ]
5183 [ # # ]: 0 : BasicTopologyEntity* bte = coedge->get_parent_basic_topology_entity_ptr();
5184 [ # # ]: 0 : if (bte == new_face)
5185 : 0 : in_new = true;
5186 [ # # ]: 0 : else if(bte == old_face)
5187 : 0 : in_old = true;
5188 : : }
5189 : :
5190 [ # # ][ # # ]: 0 : if (in_old && in_new)
5191 : : {
5192 [ # # ]: 0 : curve_list.clean_out();
5193 : 0 : break;
5194 : : }
5195 [ # # ]: 0 : else if(in_new)
5196 : : {
5197 [ # # ][ # # ]: 0 : curve_list.append( dynamic_cast<Curve*>(bridge) );
5198 : 0 : continue;
5199 : : }
5200 : :
5201 : : //Some other curves might be merge candidates now..
5202 : : //If both surfaces on either side of the curve have been unmerged,
5203 : : //then this curve can be unmerged too.
5204 : 0 : bool unmerge_curve = true;
5205 [ # # ]: 0 : bridge_parents.clean_out();
5206 [ # # ]: 0 : bridge->get_parents( bridge_parents );
5207 [ # # ][ # # ]: 0 : while (bridge_parents.size())
5208 : : {
5209 [ # # ][ # # ]: 0 : CoEdge* coedge = dynamic_cast<CoEdge*>(bridge_parents.pop()->topology_entity());
[ # # ]
5210 [ # # ][ # # ]: 0 : if( coedge->bridge_manager()->number_of_bridges() != 1 )
[ # # ]
5211 : : {
5212 : 0 : unmerge_curve = false;
5213 : 0 : break;
5214 : : }
5215 : : }
5216 : :
5217 [ # # ]: 0 : if( unmerge_curve == true )
5218 [ # # ][ # # ]: 0 : other_curves_to_unmerge.append_unique( dynamic_cast<Curve*>(bridge) );
5219 : :
5220 : : } // for( j in bridge_list )
5221 : :
5222 : : // Find curve(s) that must remain merged.
5223 [ # # ]: 0 : curve_list.reset();
5224 [ # # ][ # # ]: 0 : for (j = 0; j < curve_list.size(); j++)
5225 : : {
5226 [ # # ]: 0 : bridge_parents.clean_out();
5227 [ # # ][ # # ]: 0 : curve_list.get_and_step()->get_parents( bridge_parents );
5228 [ # # ]: 0 : bridge_parents.reset();
5229 [ # # ][ # # ]: 0 : for (k = 0; k< bridge_parents.size(); k++)
5230 : : {
5231 [ # # ]: 0 : bridge_list.clean_out();
5232 [ # # ][ # # ]: 0 : BridgeManager* bm = bridge_parents.get_and_step()->bridge_manager();
5233 [ # # ]: 0 : bm->get_bridge_list( bridge_list );
5234 : :
5235 [ # # ]: 0 : bridge_list.reset();
5236 [ # # ][ # # ]: 0 : for (int l = bridge_list.size(); l--; )
5237 : : {
5238 [ # # ]: 0 : bridge_children.clean_out();
5239 [ # # ][ # # ]: 0 : bridge_list.get_and_step()->get_children( bridge_children );
5240 [ # # ][ # # ]: 0 : assert (bridge_children.size() == 1); // bridges are coedges, must have 1 curve
5241 [ # # ][ # # ]: 0 : Curve* curve = dynamic_cast<Curve*>(bridge_children.get());
5242 [ # # ][ # # ]: 0 : assert (curve->owner() == edge->bridge_manager());
[ # # ]
5243 [ # # ]: 0 : curve_list.append_unique( curve );
5244 : : }
5245 : : }
5246 : : } // for( j in curve_list )
5247 : :
5248 [ # # ][ # # ]: 0 : if (curve_list.size() != 0 &&
[ # # ][ # # ]
5249 [ # # ][ # # ]: 0 : curve_list.size() != edge->bridge_manager()->number_of_bridges())
[ # # ]
5250 : : {
5251 [ # # ]: 0 : separate_edge( curve_list, true );
5252 : : }
5253 : :
5254 [ # # ][ # # ]: 0 : if( other_curves_to_unmerge.size() )
5255 [ # # ]: 0 : separate_edge( other_curves_to_unmerge, true );
5256 : :
5257 [ # # ][ # # ]: 0 : } // for (i in edge_list)
5258 : : } // if (unmerge_curves)
5259 : :
5260 [ # # ]: 0 : end_unmerge(top);
5261 [ # # ]: 0 : return new_face;
5262 : : }
5263 : :
5264 : :
5265 : : //-------------------------------------------------------------------------
5266 : : // Purpose : Split a RefEdge
5267 : : //
5268 : : // Special Notes :
5269 : : //
5270 : : // Creator : Jason Kraftcheck
5271 : : //
5272 : : // Creation Date : 06/01/04
5273 : : //-------------------------------------------------------------------------
5274 : 0 : RefEdge* MergeTool::separate_edge( DLIList<Curve*>& curves,
5275 : : bool unmerge_vertices )
5276 : : {
5277 : : int i, j, k;
5278 : :
5279 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list( curves.size() );
5280 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( curves, bridge_list );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
5281 [ # # ][ # # ]: 0 : RefEdge* old_edge = dynamic_cast<RefEdge*>( can_separate( bridge_list, true ) );
5282 [ # # ]: 0 : if (!old_edge)
5283 : 0 : return 0;
5284 : :
5285 : 0 : bool old_edge_free_before = true;
5286 [ # # ][ # # ]: 0 : if( old_edge->num_parent_ref_entities() )
5287 : 0 : old_edge_free_before = false;
5288 : :
5289 [ # # ]: 0 : CubitBoolean top = start_unmerge();
5290 : :
5291 : : // Split the RefEdge
5292 : :
5293 : : // Remove curves from old edge
5294 [ # # ][ # # ]: 0 : for (i = curves.size(); i--; )
5295 [ # # ][ # # ]: 0 : old_edge->bridge_manager()->remove_bridge( curves.get_and_step() );
[ # # ]
5296 [ # # ]: 0 : check_saved_id( old_edge );
5297 [ # # ]: 0 : curves.reset();
5298 : : // Use curve with smallest saved ID as primary
5299 [ # # ][ # # ]: 0 : for (j = 0, i = 1; i < curves.size(); i++)
5300 [ # # ][ # # ]: 0 : if (curves.next(i)->get_saved_id() < curves.next(j)->get_saved_id())
[ # # ][ # # ]
[ # # ]
5301 : 0 : j = i;
5302 [ # # ]: 0 : curves.step( j );
5303 : : // Create new edge
5304 [ # # ][ # # ]: 0 : RefEdge* new_edge = RefEntityFactory::instance()->construct_RefEdge( curves.get() );
[ # # ]
5305 : :
5306 [ # # ][ # # ]: 0 : for (i = curves.size(); i > 1; i-- )
5307 [ # # ][ # # ]: 0 : new_edge->bridge_manager()->add_bridge( curves.step_and_get() );
[ # # ]
5308 : :
5309 : : // Move CoEdges
5310 [ # # ]: 0 : bridge_list.clean_out();
5311 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> new_coedges;
5312 [ # # ][ # # ]: 0 : DLIList<CoEdge*> old_coedges;
5313 [ # # ]: 0 : old_edge->co_edges( old_coedges );
5314 [ # # ][ # # ]: 0 : for (i = curves.size(); i > 0; i--)
5315 : : {
5316 [ # # ][ # # ]: 0 : curves.get_and_step()->get_parents( bridge_list );
5317 [ # # ][ # # ]: 0 : while (bridge_list.size())
5318 [ # # ][ # # ]: 0 : new_coedges.append( bridge_list.pop()->topology_entity() );
[ # # ]
5319 : : }
5320 [ # # ]: 0 : old_coedges.reset();
5321 [ # # ][ # # ]: 0 : for (i = old_coedges.size(); i--; )
5322 : : {
5323 [ # # ]: 0 : CoEdge* co_edge = old_coedges.get_and_step();
5324 [ # # ][ # # ]: 0 : if (new_coedges.is_in_list( co_edge ))
5325 : : {
5326 [ # # ]: 0 : co_edge->switch_basic_topology_entity( new_edge );
5327 : : }
5328 : : }
5329 : :
5330 : : // Construct chain and co-vertices
5331 [ # # ][ # # ]: 0 : Chain* new_chain = new Chain;
5332 [ # # ]: 0 : new_edge->add_grouping_entity( new_chain );
5333 [ # # ][ # # ]: 0 : CoVertex* start = new CoVertex( old_edge->start_vertex() );
[ # # ]
5334 [ # # ]: 0 : new_chain->add_sense_entity( start );
5335 [ # # ][ # # ]: 0 : CoVertex* end = new CoVertex( old_edge->end_vertex() );
[ # # ]
5336 [ # # ]: 0 : new_chain->add_sense_entity( end, start );
5337 : :
5338 : : // Check if should reverse new edge
5339 : 0 : bool reverse_new = true;
5340 [ # # ][ # # ]: 0 : for (i = curves.size(); i--; )
5341 [ # # ][ # # ]: 0 : if (curves.get_and_step()->bridge_sense() != CUBIT_REVERSED)
[ # # ]
5342 : 0 : reverse_new = false;
5343 [ # # ]: 0 : if (reverse_new)
5344 : : {
5345 [ # # ][ # # ]: 0 : new_edge->bridge_manager()->reverse_bridge_senses();
5346 [ # # ]: 0 : new_edge->reverse_topology();
5347 : : }
5348 : :
5349 : : // Check if should reverse old edge
5350 : 0 : bool reverse_old = true;
5351 [ # # ]: 0 : bridge_list.clean_out();
5352 [ # # ][ # # ]: 0 : old_edge->bridge_manager()->get_bridge_list( bridge_list );
5353 [ # # ][ # # ]: 0 : for (i = bridge_list.size(); i--; )
5354 [ # # ][ # # ]: 0 : if (bridge_list.get_and_step()->bridge_sense() != CUBIT_REVERSED)
[ # # ]
5355 : 0 : reverse_old = false;
5356 [ # # ]: 0 : if (reverse_old)
5357 : : {
5358 [ # # ][ # # ]: 0 : old_edge->bridge_manager()->reverse_bridge_senses();
5359 [ # # ]: 0 : old_edge->reverse_topology();
5360 : : }
5361 : :
5362 : : // Misc stuff for updating other code for changed topology
5363 : 0 : bool reversed = reverse_old != reverse_new;
5364 [ # # ][ # # ]: 0 : new_unmerged.append( new_edge );
5365 [ # # ][ # # ]: 0 : old_unmerged.append( old_edge );
5366 [ # # ][ # # ]: 0 : for (i = assistant_list_.size(); i--; )
5367 [ # # ][ # # ]: 0 : assistant_list_.get_and_step()->unmerged( old_edge, new_edge, reversed );
[ # # ][ # # ]
5368 : :
5369 [ # # ]: 0 : if (unmerge_vertices)
5370 : : {
5371 : : // Split vertices
5372 [ # # ]: 0 : DLIList<TBPoint*> point_list;
5373 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> parent_curves, curve_points;
[ # # ][ # # ]
5374 : :
5375 [ # # ]: 0 : int n_vert = old_edge->num_ref_vertices();
5376 [ # # ]: 0 : assert(n_vert < 3);
5377 : :
5378 [ # # ]: 0 : for (i = 0; i < n_vert; i++)
5379 : : {
5380 [ # # ]: 0 : point_list.clean_out();
5381 : : #ifndef NDEBUG
5382 [ # # ][ # # ]: 0 : RefVertex* vtx = i ? old_edge->end_vertex() : old_edge->start_vertex();
[ # # ]
5383 : : #endif
5384 [ # # ]: 0 : CubitSense sense = i ? CUBIT_REVERSED : CUBIT_FORWARD;
5385 : :
5386 [ # # ]: 0 : curves.reset();
5387 [ # # ][ # # ]: 0 : for (j = curves.size(); j--; )
5388 : : {
5389 [ # # ]: 0 : Curve* curve = curves.get_and_step();
5390 [ # # ]: 0 : bridge_list.clean_out();
5391 [ # # ]: 0 : curve->get_children( bridge_list );
5392 [ # # ]: 0 : bridge_list.reset();
5393 [ # # ][ # # ]: 0 : if (reversed != (curve->bridge_sense() != sense))
5394 [ # # ]: 0 : bridge_list.step();
5395 [ # # ][ # # ]: 0 : TBPoint* point = dynamic_cast<TBPoint*>(bridge_list.get());
5396 [ # # ][ # # ]: 0 : assert (point->owner() == vtx->bridge_manager());
[ # # ]
5397 [ # # ]: 0 : point_list.append( point );
5398 : : }
5399 : :
5400 [ # # ][ # # ]: 0 : for (j = 0; j < point_list.size(); j++)
5401 : : {
5402 [ # # ]: 0 : point_list.reset();
5403 [ # # ]: 0 : point_list.step(j);
5404 [ # # ]: 0 : TBPoint* point = point_list.get();
5405 [ # # ]: 0 : parent_curves.clean_out();
5406 [ # # ]: 0 : point->get_parents( parent_curves );
5407 : :
5408 [ # # ]: 0 : parent_curves.reset();
5409 [ # # ][ # # ]: 0 : for (k = parent_curves.size(); k--; )
5410 : : {
5411 [ # # ]: 0 : TopologyBridge* curve = parent_curves.get_and_step();
5412 [ # # ]: 0 : BridgeManager* bm = curve->bridge_manager();
5413 [ # # ]: 0 : bridge_list.clean_out();
5414 [ # # ]: 0 : bm->get_bridge_list( bridge_list );
5415 : :
5416 [ # # ]: 0 : bridge_list.reset();
5417 [ # # ][ # # ]: 0 : for (int l = bridge_list.size(); l--; )
5418 : : {
5419 [ # # ]: 0 : curve_points.clean_out();
5420 [ # # ][ # # ]: 0 : bridge_list.get_and_step()->get_children( curve_points );
5421 [ # # ][ # # ]: 0 : assert(curve_points.size() < 3);
5422 [ # # ][ # # ]: 0 : if (curve_points.get()->owner() == point->owner())
[ # # ][ # # ]
5423 [ # # ][ # # ]: 0 : point_list.append_unique( dynamic_cast<TBPoint*>(curve_points.get()) );
[ # # ]
5424 [ # # ][ # # ]: 0 : else if (curve_points.next()->owner() == point->owner())
[ # # ][ # # ]
5425 [ # # ][ # # ]: 0 : point_list.append_unique( dynamic_cast<TBPoint*>(curve_points.next()) );
[ # # ]
5426 : : }
5427 : : }
5428 : : }
5429 [ # # ]: 0 : separate_vertex( point_list );
5430 [ # # ]: 0 : }
5431 : : }
5432 : :
5433 [ # # ][ # # ]: 0 : if( !old_edge_free_before && old_edge->num_parent_ref_entities() == 0 )
[ # # ][ # # ]
5434 : : {
5435 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::FREE_REF_ENTITY_GENERATED, old_edge));
[ # # ][ # # ]
[ # # ]
5436 [ # # ][ # # ]: 0 : CGMHistory::Event evt(CGMHistory::TOP_LEVEL_ENTITY_CREATED, old_edge );
5437 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->history().add_event(evt);
[ # # ][ # # ]
5438 : : }
5439 : :
5440 : :
5441 [ # # ]: 0 : end_unmerge(top);
5442 [ # # ]: 0 : return new_edge;
5443 : : }
5444 : :
5445 : :
5446 : :
5447 : : //-------------------------------------------------------------------------
5448 : : // Purpose : Split a RefVertex
5449 : : //
5450 : : // Special Notes :
5451 : : //
5452 : : // Creator : Jason Kraftcheck
5453 : : //
5454 : : // Creation Date : 06/01/04
5455 : : //-------------------------------------------------------------------------
5456 : 0 : RefVertex* MergeTool::separate_vertex( DLIList<TBPoint*>& points )
5457 : : {
5458 : : int i, j;
5459 [ # # ][ # # ]: 0 : DLIList<TopologyBridge*> bridge_list( points.size() );
5460 [ # # ][ # # ]: 0 : CAST_LIST_TO_PARENT( points, bridge_list );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
5461 [ # # ][ # # ]: 0 : RefVertex* old_vtx = dynamic_cast<RefVertex*>( can_separate( bridge_list, true ) );
5462 [ # # ]: 0 : if (!old_vtx)
5463 : 0 : return 0;
5464 : :
5465 : 0 : bool old_vtx_free_before = true;
5466 [ # # ][ # # ]: 0 : if( old_vtx->num_parent_ref_entities() )
5467 : 0 : old_vtx_free_before = false;
5468 : :
5469 [ # # ]: 0 : CubitBoolean top = start_unmerge();
5470 : :
5471 : : // Split the RefVertex
5472 : :
5473 : : // Remove points from old vertex
5474 [ # # ][ # # ]: 0 : for (i = points.size(); i--; )
5475 [ # # ][ # # ]: 0 : old_vtx->bridge_manager()->remove_bridge( points.get_and_step() );
[ # # ]
5476 [ # # ]: 0 : check_saved_id( old_vtx );
5477 [ # # ]: 0 : points.reset();
5478 : : // Use point with smallest saved ID as primary
5479 [ # # ][ # # ]: 0 : for (j = 0, i = 1; i < points.size(); i++)
5480 [ # # ][ # # ]: 0 : if (points.next(i)->get_saved_id() < points.next(j)->get_saved_id())
[ # # ][ # # ]
[ # # ]
5481 : 0 : j = i;
5482 [ # # ]: 0 : points.step( j );
5483 : : // Create new vertex
5484 [ # # ][ # # ]: 0 : RefVertex* new_vtx = RefEntityFactory::instance()->construct_RefVertex( points.get() );
[ # # ]
5485 [ # # ][ # # ]: 0 : for (i = points.size(); i > 1; i-- )
5486 [ # # ][ # # ]: 0 : new_vtx->bridge_manager()->add_bridge( points.step_and_get() );
[ # # ]
5487 : :
5488 : : // Move CoVertices
5489 [ # # ]: 0 : bridge_list.clean_out();
5490 [ # # ][ # # ]: 0 : DLIList<TopologyEntity*> edges;
5491 [ # # ][ # # ]: 0 : DLIList<CoVertex*> co_vertices;
5492 [ # # ]: 0 : old_vtx->co_vertices( co_vertices );
5493 [ # # ][ # # ]: 0 : for (i = points.size(); i > 0; i--)
5494 : : {
5495 [ # # ][ # # ]: 0 : points.get_and_step()->get_parents( bridge_list );
5496 [ # # ][ # # ]: 0 : while (bridge_list.size())
5497 [ # # ][ # # ]: 0 : edges.append( bridge_list.pop()->topology_entity() );
[ # # ]
5498 : : }
5499 [ # # ]: 0 : co_vertices.reset();
5500 [ # # ][ # # ]: 0 : for (i = co_vertices.size(); i--; )
5501 : : {
5502 [ # # ]: 0 : CoVertex* covtx = co_vertices.get_and_step();
5503 [ # # ][ # # ]: 0 : if (edges.is_in_list( covtx->get_parent_basic_topology_entity_ptr() ))
[ # # ]
5504 : : {
5505 [ # # ]: 0 : covtx->switch_basic_topology_entity( new_vtx );
5506 : : }
5507 : : }
5508 : :
5509 : : // Misc stuff for updating other code for changed topology
5510 [ # # ][ # # ]: 0 : new_unmerged.append( new_vtx );
5511 [ # # ][ # # ]: 0 : old_unmerged.append( old_vtx );
5512 [ # # ][ # # ]: 0 : for (i = assistant_list_.size(); i--; )
5513 [ # # ][ # # ]: 0 : assistant_list_.get_and_step()->unmerged( old_vtx, new_vtx, false );
[ # # ][ # # ]
5514 : :
5515 [ # # ][ # # ]: 0 : if( !old_vtx_free_before && old_vtx->num_parent_ref_entities() == 0 )
[ # # ][ # # ]
5516 : : {
5517 [ # # ][ # # ]: 0 : AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::FREE_REF_ENTITY_GENERATED, old_vtx));
[ # # ][ # # ]
[ # # ]
5518 [ # # ][ # # ]: 0 : CGMHistory::Event evt(CGMHistory::TOP_LEVEL_ENTITY_CREATED, old_vtx );
5519 [ # # ][ # # ]: 0 : GeometryQueryTool::instance()->history().add_event(evt);
[ # # ][ # # ]
5520 : : }
5521 : :
5522 : :
5523 [ # # ]: 0 : end_unmerge(top);
5524 [ # # ]: 0 : return new_vtx;
5525 : : }
5526 : :
5527 : :
5528 : : //-------------------------------------------------------------------------
5529 : : // Purpose : Set entity ID to smallest saved bridge ID
5530 : : //
5531 : : // Special Notes :
5532 : : //
5533 : : // Creator : Jason Kraftcheck
5534 : : //
5535 : : // Creation Date : 06/03/04
5536 : : //-------------------------------------------------------------------------
5537 : 0 : CubitStatus MergeTool::check_saved_id( BasicTopologyEntity* bte )
5538 : : {
5539 [ # # ]: 0 : DLIList<TopologyBridge*> bridge_list;
5540 [ # # ][ # # ]: 0 : bte->bridge_manager()->get_bridge_list( bridge_list );
5541 : :
5542 [ # # ]: 0 : bridge_list.reset();
5543 [ # # ][ # # ]: 0 : int smallest = dynamic_cast<GeometryEntity*>(bridge_list.get())->get_saved_id();
[ # # ]
5544 [ # # ][ # # ]: 0 : if (smallest == bte->id())
5545 : 0 : return CUBIT_SUCCESS;
5546 : :
5547 [ # # ][ # # ]: 0 : for (int i = 1; i < bridge_list.size(); i++)
5548 : : {
5549 [ # # ][ # # ]: 0 : int id = dynamic_cast<GeometryEntity*>(bridge_list.next(i))->get_saved_id();
[ # # ]
5550 : : // if (!id)
5551 : : // ;
5552 [ # # ][ # # ]: 0 : if (id == bte->id())
5553 : 0 : return CUBIT_SUCCESS;
5554 [ # # ]: 0 : else if(id < smallest)
5555 : 0 : smallest = id;
5556 : : }
5557 : :
5558 [ # # ]: 0 : if (smallest)
5559 : : {
5560 : : //make sure this id isn't in use already
5561 : : RefEntity *tmp_ent =
5562 [ # # ][ # # ]: 0 : RefEntityFactory::instance()->get_ref_entity( bte->entity_type_info(), smallest );
[ # # ]
5563 : :
5564 [ # # ]: 0 : if( tmp_ent == NULL )
5565 [ # # ]: 0 : bte->set_id(smallest);
5566 : : }
5567 : :
5568 [ # # ]: 0 : return CUBIT_SUCCESS;
5569 : : }
5570 : :
5571 : :
5572 : 0 : CubitBoolean MergeTool::about_spatially_equal( Surface *surf_1, Surface *surf_2,
5573 : : double tolerance_factor )
5574 : : {
5575 [ # # ]: 0 : if( surf_1 == surf_2 )
5576 : 0 : return CUBIT_TRUE;
5577 : :
5578 : : //make sure number of edges between surfaces is identical
5579 [ # # ]: 0 : DLIList<Curve*> surf_1_edges;
5580 [ # # ][ # # ]: 0 : DLIList<Curve*> surf_2_edges;
5581 [ # # ]: 0 : surf_1->curves( surf_1_edges );
5582 [ # # ]: 0 : surf_2->curves( surf_2_edges );
5583 [ # # ][ # # ]: 0 : if( surf_1_edges.size() != surf_2_edges.size() )
[ # # ]
5584 : 0 : return CUBIT_FALSE;
5585 : :
5586 [ # # ]: 0 : int test_internal = GeometryQueryTool::get_merge_test_internal();
5587 [ # # ]: 0 : if( test_internal == 2 )
5588 : : {
5589 [ # # ]: 0 : const GeometryType surf_1_type = surf_1->geometry_type();
5590 [ # # ]: 0 : const GeometryType surf_2_type = surf_2->geometry_type();
5591 : :
5592 [ # # ][ # # ]: 0 : if (surf_1_type != SPLINE_SURFACE_TYPE &&
5593 [ # # ]: 0 : surf_1_type != BEST_FIT_SURFACE_TYPE &&
5594 [ # # ]: 0 : surf_1_type != UNDEFINED_SURFACE_TYPE &&
5595 [ # # ]: 0 : surf_2_type != SPLINE_SURFACE_TYPE &&
5596 [ # # ]: 0 : surf_2_type != BEST_FIT_SURFACE_TYPE &&
5597 : : surf_2_type != UNDEFINED_SURFACE_TYPE )
5598 : 0 : test_internal = 0;
5599 : : }
5600 : :
5601 : : //make sure number of loops between surfaces is identical
5602 [ # # ][ # # ]: 0 : DLIList<LoopSM*> surf_1_loops;
5603 [ # # ][ # # ]: 0 : DLIList<LoopSM*> surf_2_loops;
5604 [ # # ]: 0 : surf_1->loopsms( surf_1_loops );
5605 [ # # ]: 0 : surf_2->loopsms( surf_2_loops );
5606 [ # # ][ # # ]: 0 : if( surf_1_loops.size() != surf_2_loops.size() )
[ # # ]
5607 : 0 : return CUBIT_FALSE;
5608 : :
5609 : : //compare algnment (sense)
5610 : 0 : CubitSense relative_sense = CUBIT_FORWARD;
5611 [ # # ][ # # ]: 0 : CubitVector bbox_center = surf_1->bounding_box().center();
[ # # ]
5612 [ # # ]: 0 : CubitVector center_point_1;
5613 [ # # ]: 0 : surf_1->closest_point( bbox_center, ¢er_point_1 );
5614 : :
5615 [ # # ][ # # ]: 0 : bbox_center = surf_2->bounding_box().center();
[ # # ][ # # ]
5616 [ # # ]: 0 : CubitVector center_point_2;
5617 [ # # ]: 0 : surf_2->closest_point( bbox_center, ¢er_point_2 );
5618 : :
5619 [ # # ][ # # ]: 0 : CubitVector normal_1, normal_2;
5620 [ # # ]: 0 : surf_1->closest_point( center_point_1, NULL, &normal_1 );
5621 [ # # ]: 0 : surf_2->closest_point( center_point_2, NULL, &normal_2 );
5622 [ # # ]: 0 : double dot = normal_1 % normal_2;
5623 [ # # ]: 0 : if ( dot < 0 )
5624 : 0 : relative_sense = CUBIT_REVERSED;
5625 : :
5626 : : //compare loops
5627 : : int i,j;
5628 [ # # ][ # # ]: 0 : for( i=surf_1_loops.size(); i--; )
5629 : : {
5630 [ # # ]: 0 : LoopSM *surf_1_loop = surf_1_loops.get_and_step();
5631 : 0 : bool loop_match = false;
5632 : :
5633 : : //check every loop in surf_2_loops to see if it matches
5634 : : //the current loop from surf_1_loops
5635 [ # # ][ # # ]: 0 : for( j=surf_2_loops.size(); j-- && !loop_match; )
[ # # ][ # # ]
5636 : : {
5637 [ # # ]: 0 : LoopSM *surf_2_loop = surf_2_loops.get_and_step();
5638 : : loop_match = about_spatially_equal( surf_1_loop, surf_2_loop, relative_sense,
5639 [ # # ]: 0 : tolerance_factor );
5640 : :
5641 [ # # ]: 0 : if( ! loop_match )
5642 : 0 : return CUBIT_FALSE;
5643 : :
5644 : : }
5645 : : }
5646 : :
5647 [ # # ]: 0 : return CUBIT_TRUE;
5648 : :
5649 : : }
5650 : :
5651 : 0 : CubitBoolean MergeTool::about_spatially_equal( LoopSM *loop_1, LoopSM *loop_2,
5652 : : CubitSense relative_sense, double tolerance_factor )
5653 : : {
5654 : :
5655 : : //get the coedges from the loops
5656 [ # # ]: 0 : DLIList<CoEdgeSM*> loop_1_coedges;
5657 [ # # ][ # # ]: 0 : DLIList<CoEdgeSM*> loop_2_coedges;
5658 [ # # ]: 0 : loop_1->coedgesms( loop_1_coedges );
5659 [ # # ]: 0 : loop_2->coedgesms( loop_2_coedges );
5660 : :
5661 [ # # ][ # # ]: 0 : if( loop_1_coedges.size() != loop_2_coedges.size() )
[ # # ]
5662 : 0 : return CUBIT_FALSE;
5663 : :
5664 : : // Want to compare coedges in order, so make sure we have
5665 : : // them in the correct order.
5666 [ # # ]: 0 : if (relative_sense == CUBIT_REVERSED)
5667 [ # # ]: 0 : loop_1_coedges.reverse();
5668 : :
5669 : : // Try to match all coedges. Begin with the first coedge
5670 : : // in this loop. For each coedge in the other loop that
5671 : : // it matches, check if all the other coedges match in the
5672 : : // correct order.
5673 : 0 : int other_loop_index = 0;
5674 [ # # ]: 0 : loop_1_coedges.reset();
5675 [ # # ]: 0 : loop_2_coedges.reset();
5676 [ # # ]: 0 : CoEdgeSM* coedge_1 = loop_1_coedges.get_and_step();
5677 : : int i;
5678 [ # # ][ # # ]: 0 : for (i = loop_2_coedges.size(); i--; )
5679 : : {
5680 : : // Loop until we find a matching CoEdge
5681 [ # # ]: 0 : CoEdgeSM* coedge_2 = loop_2_coedges.get_and_step();
5682 : :
5683 [ # # ][ # # ]: 0 : if (!about_spatially_equal( coedge_1, coedge_2, relative_sense,tolerance_factor ))
5684 : 0 : continue;
5685 : :
5686 : : // Found a matching coedge. Now try to match all the
5687 : : // others in the correct order.
5688 : 0 : bool match = true;
5689 [ # # ]: 0 : other_loop_index = loop_2_coedges.get_index();
5690 [ # # ][ # # ]: 0 : for (int j = loop_2_coedges.size() - 1; j-- && match; )
[ # # ][ # # ]
5691 : : {
5692 [ # # ]: 0 : coedge_1 = loop_1_coedges.get_and_step();
5693 [ # # ]: 0 : coedge_2 = loop_2_coedges.get_and_step();
5694 [ # # ]: 0 : match = about_spatially_equal( coedge_1, coedge_2, relative_sense, tolerance_factor );
5695 : : }
5696 : :
5697 : : // Matched all coedges, in order. Done.
5698 [ # # ]: 0 : if (match)
5699 : 0 : return CUBIT_TRUE;
5700 : :
5701 : : // Try again, as perhaps the first coedge of this loop
5702 : : // also matches some other one in the second loop and
5703 : : // if we start with that one, the remaining coedges will
5704 : : // also match.
5705 [ # # ]: 0 : loop_1_coedges.reset();
5706 [ # # ]: 0 : coedge_1 = loop_1_coedges.get_and_step();
5707 [ # # ]: 0 : loop_2_coedges.reset();
5708 [ # # ]: 0 : loop_2_coedges.step( other_loop_index );
5709 : : }
5710 : :
5711 : : // If here, loops didn't match.
5712 [ # # ]: 0 : return CUBIT_FALSE;
5713 : :
5714 : : }
5715 : :
5716 : 0 : CubitBoolean MergeTool::about_spatially_equal( CoEdgeSM *coedge_1, CoEdgeSM *coedge_2,
5717 : : CubitSense relative_sense,
5718 : : double tolerance_factor )
5719 : : {
5720 [ # # ]: 0 : DLIList<Curve*> curves_1;
5721 [ # # ][ # # ]: 0 : DLIList<Curve*> curves_2;
5722 [ # # ]: 0 : coedge_1->curves( curves_1 );
5723 [ # # ]: 0 : coedge_2->curves( curves_2 );
5724 : :
5725 [ # # ]: 0 : Curve* curve_1 = curves_1.get();
5726 [ # # ]: 0 : Curve* curve_2 = curves_2.get();
5727 : :
5728 : : CubitSense edge_sense;
5729 : :
5730 [ # # ][ # # ]: 0 : if( !about_spatially_equal( curve_1, curve_2, edge_sense, tolerance_factor ) )
5731 : 0 : return CUBIT_FALSE;
5732 : :
5733 [ # # ][ # # ]: 0 : if( curve_1->geometry_type() == POINT_CURVE_TYPE ||
[ # # ][ # # ]
5734 [ # # ]: 0 : curve_2->geometry_type() == POINT_CURVE_TYPE )
5735 : 0 : return CUBIT_TRUE;
5736 : :
5737 [ # # ]: 0 : if (edge_sense == CUBIT_UNKNOWN)
5738 : : {
5739 [ # # ][ # # ]: 0 : PRINT_WARNING("Failed to determine relative sense of curves.\n");
[ # # ][ # # ]
5740 : 0 : return CUBIT_TRUE;
5741 : : }
5742 : :
5743 [ # # ][ # # ]: 0 : bool coedges_reversed = coedge_1->sense() != coedge_2->sense();
5744 : 0 : bool want_reversed = edge_sense != relative_sense;
5745 [ # # ]: 0 : if (coedges_reversed == want_reversed)
5746 : 0 : return CUBIT_TRUE;
5747 : :
5748 [ # # ]: 0 : return CUBIT_FALSE;
5749 : : }
5750 : :
5751 : 0 : CubitBoolean MergeTool::about_spatially_equal( Curve *curve_1, Curve *curve_2,
5752 : : CubitSense &relative_sense,
5753 : : double tolerance_factor )
5754 : : {
5755 [ # # ]: 0 : if( curve_1 == curve_2 )
5756 : 0 : return CUBIT_TRUE;
5757 : :
5758 : 0 : relative_sense = CUBIT_FORWARD;
5759 : 0 : const double ONE_THIRD = 1.0/3.0;
5760 : :
5761 : : // Find the point 1/3 along curve_1
5762 [ # # ][ # # ]: 0 : CubitVector test_point_1, test_point_2;
5763 [ # # ][ # # ]: 0 : if( curve_1->position_from_fraction( ONE_THIRD, test_point_1 ) != CUBIT_SUCCESS )
5764 : 0 : return CUBIT_FALSE;
5765 : :
5766 : : // See if the 1/3 point on curve_1 lies on curve_2
5767 [ # # ][ # # ]: 0 : if ( curve_2->closest_point_trimmed(test_point_1, test_point_2)
5768 : : != CUBIT_SUCCESS )
5769 : : {
5770 : 0 : return CUBIT_FALSE;
5771 : : }
5772 : :
5773 [ # # ]: 0 : if ( GeometryQueryTool::instance()->
5774 [ # # ][ # # ]: 0 : about_spatially_equal(test_point_1, test_point_2, tolerance_factor )
5775 : : != CUBIT_SUCCESS )
5776 : : {
5777 : 0 : return CUBIT_FALSE;
5778 : : }
5779 : :
5780 [ # # ][ # # ]: 0 : CubitVector tangent_1, tangent_2;
5781 [ # # ][ # # ]: 0 : if( curve_1->closest_point(test_point_2, test_point_1, &tangent_1) != CUBIT_SUCCESS )
5782 : 0 : return CUBIT_FALSE;
5783 [ # # ][ # # ]: 0 : if( curve_2->closest_point(test_point_1, test_point_2, &tangent_2) != CUBIT_SUCCESS )
5784 : 0 : return CUBIT_FALSE;
5785 : :
5786 : : //If one of the curves is zero-length, it will have a zero
5787 : : //tangent vector.
5788 [ # # ][ # # ]: 0 : double len_product = tangent_1.length() * tangent_2.length();
5789 [ # # ]: 0 : if( len_product > CUBIT_DBL_MIN )
5790 : : {
5791 [ # # ]: 0 : double dot_product = (tangent_1 % tangent_2);
5792 [ # # ]: 0 : if (dot_product < 0)
5793 : 0 : relative_sense = CUBIT_REVERSED;
5794 : : }
5795 : : else
5796 : : {
5797 : : //If one of the tangents is zero-length, one of the curves had
5798 : : //better be as well.
5799 [ # # ][ # # ]: 0 : assert( (curve_1->measure() * curve_2->measure()) < CUBIT_RESABS );
[ # # ]
5800 : : }
5801 : :
5802 : : //compare the start and end vertices to be spatially equal.
5803 [ # # ][ # # ]: 0 : DLIList<TBPoint*> curve_1_points(2), curve_2_points(2);
[ # # ]
5804 [ # # ]: 0 : curve_1->points( curve_1_points );
5805 [ # # ]: 0 : curve_2->points( curve_2_points );
5806 : :
5807 [ # # ][ # # ]: 0 : if( curve_1->bridge_sense() == CUBIT_REVERSED )
5808 [ # # ]: 0 : curve_1_points.reverse();
5809 [ # # ][ # # ]: 0 : if( curve_2->bridge_sense() == CUBIT_REVERSED )
5810 [ # # ]: 0 : curve_2_points.reverse();
5811 : :
5812 [ # # ]: 0 : TBPoint* curve_1_start = curve_1_points.get();
5813 [ # # ]: 0 : curve_1_points.last();
5814 [ # # ]: 0 : TBPoint* curve_1_end = curve_1_points.get();
5815 : :
5816 [ # # ]: 0 : TBPoint* curve_2_start = curve_2_points.get();
5817 [ # # ]: 0 : curve_2_points.last();
5818 [ # # ]: 0 : TBPoint* curve_2_end = curve_2_points.get();
5819 : :
5820 [ # # ]: 0 : if (relative_sense == CUBIT_REVERSED)
5821 [ # # ]: 0 : std::swap(curve_2_start, curve_2_end);
5822 : :
5823 [ # # ][ # # ]: 0 : if (curve_1_start == curve_1_end ||curve_2_start == curve_2_end)
5824 : : {
5825 [ # # ][ # # ]: 0 : if ((curve_1_start != curve_1_end) ||
5826 [ # # ][ # # ]: 0 : (curve_2_start != curve_2_end) ||
5827 [ # # ]: 0 : !about_spatially_equal(curve_1_start, curve_2_start, tolerance_factor))
5828 : 0 : return CUBIT_FALSE;
5829 : : }
5830 : : else
5831 : : {
5832 [ # # ][ # # ]: 0 : if ((curve_1_start == curve_2_end) ||
5833 [ # # ]: 0 : (curve_1_end == curve_2_start) ||
5834 [ # # ][ # # ]: 0 : !about_spatially_equal(curve_1_start, curve_2_start, tolerance_factor ) ||
[ # # ]
5835 [ # # ]: 0 : !about_spatially_equal(curve_1_end, curve_2_end, tolerance_factor ))
5836 : 0 : return CUBIT_FALSE;
5837 : : }
5838 : :
5839 [ # # ]: 0 : return CUBIT_TRUE;
5840 : :
5841 : : }
5842 : :
5843 : 0 : CubitBoolean MergeTool::about_spatially_equal( TBPoint *point_1, TBPoint *point_2,
5844 : : double tolerance_factor )
5845 : : {
5846 [ # # ]: 0 : if( point_1 == point_2 )
5847 : 0 : return CUBIT_TRUE;
5848 : :
5849 [ # # ]: 0 : CubitVector point_1_pos = point_1->coordinates();
5850 [ # # ]: 0 : CubitVector point_2_pos = point_2->coordinates();
5851 : :
5852 [ # # ]: 0 : if (!GeometryQueryTool::instance()-> about_spatially_equal(
5853 [ # # ][ # # ]: 0 : point_1_pos, point_2_pos, tolerance_factor))
5854 : 0 : return CUBIT_FALSE;
5855 : :
5856 : 0 : return CUBIT_TRUE;
5857 : : }
5858 : :
5859 : 0 : void MergeTool::imprint_merge_solutions_for_overlapping_surfaces(
5860 : : RefFace *face1,
5861 : : RefFace *face2,
5862 : : bool execute,
5863 : : DLIList<CubitString> &display_strings,
5864 : : DLIList<CubitString> &command_strings,
5865 : : DLIList<CubitString> &preview_strings )
5866 : : {
5867 : : //collect all the unmerged curves between the 2 surfaces
5868 [ # # ][ # # ]: 0 : DLIList<RefEdge*> edges1, edges2, tmp_list;
[ # # ][ # # ]
[ # # ]
5869 [ # # ]: 0 : face1->ref_edges( edges1 );
5870 [ # # ]: 0 : face2->ref_edges( edges2 );
5871 [ # # ]: 0 : tmp_list += edges1;
5872 [ # # ]: 0 : tmp_list.intersect_unordered( edges2 );
5873 : :
5874 : : //remove all the common edges from both lists
5875 [ # # ]: 0 : edges1 -= tmp_list;
5876 [ # # ]: 0 : edges2 -= tmp_list;
5877 : :
5878 [ # # ]: 0 : double tolerance = GeometryQueryTool::get_geometry_factor()*GEOMETRY_RESABS;
5879 : :
5880 [ # # ][ # # ]: 0 : CubitString preview_string;
5881 : :
5882 [ # # ]: 0 : if(!execute)
5883 : : {
5884 [ # # ][ # # ]: 0 : preview_string = CubitString("draw surface ");
[ # # ]
5885 [ # # ][ # # ]: 0 : preview_string += CubitString::number(face1->id());
[ # # ][ # # ]
5886 [ # # ][ # # ]: 0 : preview_string += " ";
[ # # ]
5887 [ # # ][ # # ]: 0 : preview_string += CubitString::number(face2->id());
[ # # ][ # # ]
5888 [ # # ][ # # ]: 0 : preview_string += " overlap";
[ # # ]
5889 : : }
5890 : :
5891 : : //if all curves of both surfaces are merged, suggest 'force merge'
5892 [ # # ][ # # ]: 0 : if( edges1.size() == 0 && edges2.size() == 0 )
[ # # ][ # # ]
[ # # ]
5893 : : {
5894 : : //quick check to make sure that centerpoints are nearly coincident
5895 [ # # ]: 0 : CubitVector center1 = face1->center_point();
5896 [ # # ]: 0 : CubitVector center2 = face2->center_point();
5897 : :
5898 [ # # ][ # # ]: 0 : if( center1.distance_between( center2 ) <= (tolerance*5) )
5899 : : {
5900 [ # # ]: 0 : if(execute)
5901 : : {
5902 [ # # ][ # # ]: 0 : MergeTool::instance()->force_merge(face1, face2);
5903 : : }
5904 : : else
5905 : : {
5906 : : //display strings
5907 [ # # ]: 0 : CubitString display_string("Force merge Surface ");
5908 [ # # ][ # # ]: 0 : display_string += CubitString::number(face1->id());
[ # # ][ # # ]
5909 [ # # ][ # # ]: 0 : display_string += " ";
[ # # ]
5910 [ # # ][ # # ]: 0 : display_string += CubitString::number(face2->id());
[ # # ][ # # ]
5911 [ # # ]: 0 : display_strings.append( display_string );
5912 : :
5913 [ # # ][ # # ]: 0 : CubitString command_string("merge surface ");
5914 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
5915 [ # # ][ # # ]: 0 : command_string += " ";
[ # # ]
5916 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
5917 [ # # ][ # # ]: 0 : command_string += " force";
[ # # ]
5918 [ # # ]: 0 : command_strings.append( command_string );
5919 : :
5920 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
5921 : : }
5922 : :
5923 : 0 : return;
5924 : : }
5925 : : }
5926 : :
5927 : : //get all the vertices
5928 [ # # ][ # # ]: 0 : DLIList<RefVertex*> verts1, verts2, merged_vertices;
[ # # ][ # # ]
[ # # ][ # # ]
5929 [ # # ]: 0 : face1->ref_vertices( verts1 );
5930 [ # # ]: 0 : face2->ref_vertices( verts2 );
5931 [ # # ]: 0 : merged_vertices += verts1;
5932 [ # # ]: 0 : merged_vertices.intersect_unordered( verts2 );
5933 : :
5934 : : //remove all the merged vertices from both lists
5935 [ # # ]: 0 : verts1 -= merged_vertices;
5936 [ # # ]: 0 : verts2 -= merged_vertices;
5937 : :
5938 : : int i,j,k;
5939 : : //another force merge case...all vertices are merged, but some
5940 : : //coincident curves remain unmerged still.
5941 [ # # ][ # # ]: 0 : if( verts1.size() == 0 && verts2.size() == 0 )
[ # # ][ # # ]
[ # # ]
5942 : : {
5943 [ # # ]: 0 : DLIList<RefEdge*> tmp_edges1( edges1 );
5944 [ # # ][ # # ]: 0 : DLIList<RefEdge*> tmp_edges2( edges2 );
[ # # ]
5945 : :
5946 : : //find edges that are close to one another
5947 [ # # ][ # # ]: 0 : for( i=tmp_edges1.size(); i--; )
5948 : : {
5949 [ # # ]: 0 : RefEdge *edge1 = tmp_edges1.get_and_step();
5950 : :
5951 : : //get some random point on curve edge1
5952 [ # # ]: 0 : CubitVector position_on_edge1;
5953 [ # # ]: 0 : edge1->position_from_fraction( 0.634, position_on_edge1 );
5954 : :
5955 : 0 : bool found_pair = false;
5956 [ # # ][ # # ]: 0 : for( j=tmp_edges2.size(); j--; )
5957 : : {
5958 [ # # ]: 0 : RefEdge *edge2 = tmp_edges2.get_and_step();
5959 : :
5960 [ # # ]: 0 : if( edge2 == NULL )
5961 : 0 : continue;
5962 : :
5963 : : //make sure that they have the same vertices
5964 [ # # ][ # # ]: 0 : if( (edge1->start_vertex() == edge2->start_vertex() ||
[ # # ][ # # ]
5965 [ # # ][ # # ]: 0 : edge1->start_vertex() == edge2->end_vertex() ) &&
[ # # ][ # # ]
5966 [ # # ][ # # ]: 0 : (edge1->end_vertex() == edge2->end_vertex() ||
[ # # ]
5967 [ # # ][ # # ]: 0 : edge1->end_vertex() == edge2->start_vertex() ) )
5968 : : {
5969 : : //find the closest point
5970 [ # # ]: 0 : CubitVector close_pt;
5971 [ # # ]: 0 : edge2->closest_point_trimmed( position_on_edge1, close_pt );
5972 : :
5973 : : //adjust tolerance to be larger possibly, a thousandanth of the curve's length
5974 [ # # ]: 0 : double tmp_tolerance = edge2->measure()*0.01;
5975 [ # # ]: 0 : if( tolerance > tmp_tolerance )
5976 : 0 : tmp_tolerance = tolerance;
5977 : :
5978 [ # # ][ # # ]: 0 : if( close_pt.distance_between( position_on_edge1 ) < tmp_tolerance )
5979 : : {
5980 : : //remove both from the list
5981 [ # # ]: 0 : tmp_edges2.back();
5982 [ # # ]: 0 : tmp_edges2.change_to( NULL );
5983 : 0 : found_pair = true;
5984 : 0 : break;
5985 : : }
5986 : : }
5987 : : }
5988 [ # # ]: 0 : if( found_pair == true )
5989 : : {
5990 [ # # ]: 0 : tmp_edges1.back();
5991 [ # # ]: 0 : tmp_edges1.change_to( NULL );
5992 [ # # ]: 0 : tmp_edges1.step();
5993 : : }
5994 : : }
5995 : :
5996 [ # # ]: 0 : tmp_edges1.remove_all_with_value( NULL );
5997 [ # # ]: 0 : tmp_edges2.remove_all_with_value( NULL );
5998 : :
5999 [ # # ][ # # ]: 0 : if( tmp_edges1.size() == 0 && tmp_edges2.size() == 0 )
[ # # ][ # # ]
[ # # ]
6000 : : {
6001 [ # # ]: 0 : if(execute)
6002 : : {
6003 [ # # ][ # # ]: 0 : MergeTool::instance()->force_merge(face1, face2);
6004 : : }
6005 : : else
6006 : : {
6007 : : //display strings
6008 [ # # ]: 0 : CubitString display_string("Force merge Surface ");
6009 [ # # ][ # # ]: 0 : display_string += CubitString::number(face1->id());
[ # # ][ # # ]
6010 [ # # ][ # # ]: 0 : display_string += " ";
[ # # ]
6011 [ # # ][ # # ]: 0 : display_string += CubitString::number(face2->id());
[ # # ][ # # ]
6012 [ # # ]: 0 : display_strings.append( display_string );
6013 : :
6014 [ # # ][ # # ]: 0 : CubitString command_string("merge surface ");
6015 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
6016 [ # # ][ # # ]: 0 : command_string += " ";
[ # # ]
6017 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
6018 [ # # ][ # # ]: 0 : command_string += " force";
[ # # ]
6019 [ # # ]: 0 : command_strings.append( command_string );
6020 : :
6021 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
6022 : : }
6023 [ # # ][ # # ]: 0 : return;
6024 : 0 : }
6025 : : }
6026 : :
6027 : : //Look for near-coincident vertices between surfaces.
6028 : : //If any vertices are less than merge_tolerance*5 apart,
6029 : : //merge all the vertices
6030 [ # # ]: 0 : verts1.clean_out();
6031 [ # # ]: 0 : verts2.clean_out();
6032 [ # # ]: 0 : face1->ref_vertices( verts1 );
6033 [ # # ]: 0 : face2->ref_vertices( verts2 );
6034 : 0 : double tmp_tol = tolerance * 5;
6035 : 0 : double recommended_tol = -1;
6036 : :
6037 [ # # ][ # # ]: 0 : for( i=verts1.size(); i--; )
6038 : : {
6039 [ # # ]: 0 : RefVertex *vert1 = verts1.get_and_step();
6040 [ # # ]: 0 : CubitVector pos1 = vert1->coordinates();
6041 : :
6042 [ # # ][ # # ]: 0 : for( j=verts2.size(); j--; )
6043 : : {
6044 [ # # ]: 0 : RefVertex *vert2 = verts2.get_and_step();
6045 [ # # ]: 0 : if( vert2 == vert1 )//already merged case
6046 : 0 : continue;
6047 [ # # ]: 0 : CubitVector pos2 = vert2->coordinates();
6048 : :
6049 [ # # ]: 0 : double tmp_dist = pos1.distance_between( pos2 );
6050 [ # # ]: 0 : if( tmp_dist < tmp_tol )
6051 : : {
6052 [ # # ]: 0 : if( tmp_dist > recommended_tol )
6053 : : {
6054 : 0 : recommended_tol = tmp_dist;
6055 : : }
6056 : : }
6057 : : }
6058 : : }
6059 : :
6060 [ # # ]: 0 : if( recommended_tol > 0 )
6061 : : {
6062 [ # # ]: 0 : double merge_tol = GeometryQueryTool::get_geometry_factor()*GEOMETRY_RESABS;
6063 : :
6064 [ # # ]: 0 : if(execute)
6065 : : {
6066 : 0 : double old_merge_tol = -1;
6067 [ # # ]: 0 : if( recommended_tol > merge_tol )
6068 : : {
6069 [ # # ]: 0 : old_merge_tol = GeometryQueryTool::get_geometry_factor();
6070 [ # # ]: 0 : GeometryQueryTool::set_geometry_factor(recommended_tol);
6071 : : }
6072 [ # # ]: 0 : DLIList<RefVertex*> merge_vert_list;
6073 [ # # ]: 0 : face1->ref_vertices(merge_vert_list);
6074 [ # # ]: 0 : face2->ref_vertices(merge_vert_list);
6075 [ # # ][ # # ]: 0 : MergeTool::instance()->merge_refvertices( merge_vert_list );
6076 [ # # ]: 0 : if( old_merge_tol != -1 )
6077 [ # # ][ # # ]: 0 : GeometryQueryTool::set_geometry_factor( old_merge_tol );
6078 : : }
6079 : : else
6080 : : {
6081 [ # # ]: 0 : CubitString display_string("Merge vertices of surface ");
6082 [ # # ][ # # ]: 0 : display_string += CubitString::number(face1->id());
[ # # ][ # # ]
6083 [ # # ][ # # ]: 0 : display_string += " ";
[ # # ]
6084 [ # # ][ # # ]: 0 : display_string += CubitString::number(face2->id());
[ # # ][ # # ]
6085 [ # # ]: 0 : if( recommended_tol > merge_tol )
6086 : : {
6087 : 0 : recommended_tol *= 1.1;
6088 [ # # ][ # # ]: 0 : display_string += " tolerance ";
[ # # ]
6089 [ # # ][ # # ]: 0 : display_string += CubitString::number( recommended_tol, 0, 7 );
[ # # ]
6090 : : }
6091 [ # # ]: 0 : display_strings.append( display_string );
6092 : :
6093 [ # # ][ # # ]: 0 : CubitString command_string("merge vertex in surface ");
6094 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
6095 [ # # ][ # # ]: 0 : command_string += " ";
[ # # ]
6096 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
6097 [ # # ]: 0 : if( recommended_tol > merge_tol )
6098 : : {
6099 [ # # ][ # # ]: 0 : command_string += " tolerance ";
[ # # ]
6100 [ # # ][ # # ]: 0 : command_string += CubitString::number( recommended_tol, 0, 7 );
[ # # ]
6101 : : }
6102 [ # # ]: 0 : command_strings.append( command_string );
6103 : :
6104 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
6105 : : }
6106 : 0 : return;
6107 : : }
6108 : :
6109 [ # # ][ # # ]: 0 : DLIList<CubitVector> positions_to_imprint_onto_face1;
6110 [ # # ][ # # ]: 0 : DLIList<CubitVector> positions_to_imprint_onto_face2;
6111 : :
6112 : 0 : double possible_slivers_on_face1 = 0;
6113 : 0 : double possible_slivers_on_face2 = 0;
6114 : :
6115 : : double dist1, dist2, dist3;
6116 : :
6117 : : //if you have overlapping curves, suggest imprinting owning volume with vertex
6118 [ # # ][ # # ]: 0 : std::map<RefEdge*, DLIList<CurveOverlapFacet*>* > facet_map;
6119 : :
6120 [ # # ][ # # ]: 0 : DLIList<RefEdge*> overlapping_edges2;
6121 : :
6122 [ # # ][ # # ]: 0 : for( i=edges1.size(); i--; )
6123 : : {
6124 [ # # ]: 0 : RefEdge *edge1 = edges1.get_and_step();
6125 : :
6126 [ # # ]: 0 : DLIList<RefVertex*> verts1;
6127 [ # # ]: 0 : edge1->ref_vertices( verts1 );
6128 [ # # ]: 0 : RefVertex *s_vert1 = verts1.get_and_step();
6129 [ # # ]: 0 : RefVertex *e_vert1 = verts1.get();
6130 : :
6131 : 0 : bool overlaps_with_another_curve = false;
6132 [ # # ]: 0 : double edge1_length = edge1->measure();
6133 : 0 : double curve_overlap_tolerance = 0.005;
6134 : :
6135 [ # # ][ # # ]: 0 : for( j=edges2.size(); j--; )
6136 : : {
6137 [ # # ]: 0 : RefEdge *edge2 = edges2.get_and_step();
6138 : :
6139 [ # # ]: 0 : if( edge2 == NULL )
6140 : 0 : continue;
6141 : :
6142 [ # # ][ # # ]: 0 : if( SurfaceOverlapTool::instance()->check_overlap( edge1, edge2,
6143 : : &facet_map,
6144 [ # # ]: 0 : &curve_overlap_tolerance ))
6145 : : {
6146 [ # # ]: 0 : overlapping_edges2.append_unique( edge2 );
6147 : 0 : overlaps_with_another_curve = true;
6148 : :
6149 [ # # ]: 0 : DLIList<RefVertex*> verts2;
6150 [ # # ]: 0 : edge2->ref_vertices( verts2 );
6151 [ # # ]: 0 : RefVertex *s_vert2 = verts2.get_and_step();
6152 [ # # ]: 0 : RefVertex *e_vert2 = verts2.get();
6153 : :
6154 [ # # ]: 0 : CubitVector close_pt;
6155 [ # # ][ # # ]: 0 : edge1->closest_point_trimmed( s_vert2->coordinates(), close_pt );
6156 : :
6157 [ # # ]: 0 : double edge2_length = edge2->measure();
6158 : :
6159 : 0 : double tmp_tolerance = edge2_length;
6160 [ # # ]: 0 : if( edge1_length < edge2_length )
6161 : 0 : tmp_tolerance = edge1_length;
6162 : :
6163 : : //For a vertex of curve A to be imprinted on curve B, that vertex of A
6164 : : //must be a distance greater than 1/2 a percent of the lenght of
6165 : : //whichever curve is smaller (A or B)
6166 : 0 : tmp_tolerance *= 0.005;
6167 : 0 : double sliver_tolerance = tmp_tolerance * 2;
6168 : :
6169 [ # # ]: 0 : if( tolerance < tmp_tolerance )
6170 : 0 : tolerance = tmp_tolerance;
6171 : :
6172 [ # # ][ # # ]: 0 : dist1 = close_pt.distance_between( s_vert2->coordinates() );
6173 [ # # ][ # # ]: 0 : dist2 = close_pt.distance_between( s_vert1->coordinates() );
6174 [ # # ][ # # ]: 0 : dist3 = close_pt.distance_between( e_vert1->coordinates() );
6175 : :
6176 : : //decide what vertex needs to be imprinted where
6177 [ # # ][ # # ]: 0 : if( dist1 < tolerance &&
6178 [ # # ]: 0 : dist2 > tolerance &&
6179 : : dist3 > tolerance )
6180 : : {
6181 : :
6182 : : //make sure this position doesn't already exist
6183 : 0 : bool add_position = true;
6184 [ # # ][ # # ]: 0 : for( k=positions_to_imprint_onto_face1.size(); k--; )
6185 : : {
6186 [ # # ][ # # ]: 0 : CubitVector tmp_vec = positions_to_imprint_onto_face1.get_and_step();
6187 : :
6188 [ # # ][ # # ]: 0 : if( close_pt.distance_between( tmp_vec ) < tolerance )
6189 : : {
6190 : 0 : add_position = false;
6191 : 0 : break;
6192 : : }
6193 : : }
6194 : :
6195 [ # # ]: 0 : if( add_position )
6196 : : {
6197 : : //imprint body of edge1 with vertex at this location
6198 [ # # ]: 0 : CubitVector tmp_vec = CubitVector( close_pt );
6199 [ # # ]: 0 : positions_to_imprint_onto_face1.append( tmp_vec );
6200 : :
6201 : : //watch for possible sliver creation
6202 [ # # ][ # # ]: 0 : if( dist2 < sliver_tolerance || dist3 < sliver_tolerance )
6203 : 0 : possible_slivers_on_face1++;
6204 : : }
6205 : : }
6206 : :
6207 [ # # ][ # # ]: 0 : edge1->closest_point_trimmed( e_vert2->coordinates(), close_pt );
6208 : :
6209 [ # # ][ # # ]: 0 : dist1 = close_pt.distance_between( e_vert2->coordinates() );
6210 [ # # ][ # # ]: 0 : dist2 = close_pt.distance_between( s_vert1->coordinates() );
6211 [ # # ][ # # ]: 0 : dist3 = close_pt.distance_between( e_vert1->coordinates() );
6212 : :
6213 [ # # ][ # # ]: 0 : if( dist1 < tolerance &&
6214 [ # # ]: 0 : dist2 > tolerance &&
6215 : : dist3 > tolerance )
6216 : : {
6217 : : //make sure this position doesn't already exist
6218 : 0 : bool add_position = true;
6219 [ # # ][ # # ]: 0 : for( k=positions_to_imprint_onto_face1.size(); k--; )
6220 : : {
6221 [ # # ][ # # ]: 0 : CubitVector tmp_vec = positions_to_imprint_onto_face1.get_and_step();
6222 : :
6223 [ # # ][ # # ]: 0 : if( close_pt.distance_between( tmp_vec ) < tolerance )
6224 : : {
6225 : 0 : add_position = false;
6226 : 0 : break;
6227 : : }
6228 : : }
6229 : :
6230 [ # # ]: 0 : if( add_position )
6231 : : {
6232 : : //imprint body of edge1 with vertex at this location
6233 [ # # ]: 0 : CubitVector tmp_vec = CubitVector( close_pt );
6234 [ # # ]: 0 : positions_to_imprint_onto_face1.append( tmp_vec );
6235 : :
6236 : : //watch for possible sliver creation
6237 [ # # ][ # # ]: 0 : if( dist2 < sliver_tolerance || dist3 < sliver_tolerance )
6238 : 0 : possible_slivers_on_face1++;
6239 : : }
6240 : : }
6241 : :
6242 [ # # ][ # # ]: 0 : edge2->closest_point_trimmed( s_vert1->coordinates(), close_pt );
6243 : :
6244 [ # # ][ # # ]: 0 : dist1 = close_pt.distance_between( s_vert1->coordinates() );
6245 [ # # ][ # # ]: 0 : dist2 = close_pt.distance_between( s_vert2->coordinates() );
6246 [ # # ][ # # ]: 0 : dist3 = close_pt.distance_between( e_vert2->coordinates() );
6247 : :
6248 [ # # ][ # # ]: 0 : if( dist1 < tolerance &&
6249 [ # # ]: 0 : dist2 > tolerance &&
6250 : : dist3 > tolerance )
6251 : : {
6252 : : //make sure this position doesn't already exist
6253 : 0 : bool add_position = true;
6254 [ # # ][ # # ]: 0 : for( k=positions_to_imprint_onto_face2.size(); k--; )
6255 : : {
6256 [ # # ][ # # ]: 0 : CubitVector tmp_vec = positions_to_imprint_onto_face2.get_and_step();
6257 : :
6258 [ # # ][ # # ]: 0 : if( close_pt.distance_between( tmp_vec ) < tolerance )
6259 : : {
6260 : 0 : add_position = false;
6261 : 0 : break;
6262 : : }
6263 : : }
6264 : :
6265 [ # # ]: 0 : if( add_position )
6266 : : {
6267 : : //imprint body of edge1 with vertex at this location
6268 [ # # ]: 0 : CubitVector tmp_vec = CubitVector( close_pt );
6269 [ # # ]: 0 : positions_to_imprint_onto_face2.append( tmp_vec );
6270 : :
6271 : : //watch for possible sliver creation
6272 [ # # ][ # # ]: 0 : if( dist2 < sliver_tolerance || dist3 < sliver_tolerance )
6273 : 0 : possible_slivers_on_face2++;
6274 : : }
6275 : : }
6276 : :
6277 [ # # ][ # # ]: 0 : edge2->closest_point_trimmed( e_vert1->coordinates(), close_pt );
6278 : :
6279 [ # # ][ # # ]: 0 : dist1 = close_pt.distance_between( e_vert1->coordinates() );
6280 [ # # ][ # # ]: 0 : dist2 = close_pt.distance_between( s_vert2->coordinates() );
6281 [ # # ][ # # ]: 0 : dist3 = close_pt.distance_between( e_vert2->coordinates() );
6282 : :
6283 [ # # ][ # # ]: 0 : if( dist1 < tolerance &&
6284 [ # # ]: 0 : dist2 > tolerance &&
6285 : : dist3 > tolerance )
6286 : : {
6287 : : //make sure this position doesn't already exist
6288 : 0 : bool add_position = true;
6289 [ # # ][ # # ]: 0 : for( k=positions_to_imprint_onto_face2.size(); k--; )
6290 : : {
6291 [ # # ][ # # ]: 0 : CubitVector tmp_vec = positions_to_imprint_onto_face2.get_and_step();
6292 : :
6293 [ # # ][ # # ]: 0 : if( close_pt.distance_between( tmp_vec ) < tolerance )
6294 : : {
6295 : 0 : add_position = false;
6296 : 0 : break;
6297 : : }
6298 : : }
6299 : :
6300 [ # # ]: 0 : if( add_position )
6301 : : {
6302 : : //imprint body of edge1 with vertex at this location
6303 [ # # ]: 0 : CubitVector tmp_vec = CubitVector( close_pt );
6304 [ # # ]: 0 : positions_to_imprint_onto_face2.append( tmp_vec );
6305 : :
6306 : : //watch for possible sliver creation
6307 [ # # ][ # # ]: 0 : if( dist2 < sliver_tolerance || dist3 < sliver_tolerance )
6308 : 0 : possible_slivers_on_face2++;
6309 : : }
6310 [ # # ]: 0 : }
6311 : : }
6312 : : }
6313 : :
6314 : : //remove this curve if it really overlaps
6315 [ # # ]: 0 : if( overlaps_with_another_curve == true )
6316 : : {
6317 [ # # ]: 0 : edges1.back();
6318 [ # # ]: 0 : edges1.change_to( NULL );
6319 [ # # ]: 0 : edges1.step();
6320 : : }
6321 [ # # ]: 0 : }
6322 : :
6323 : : //clean up facets
6324 [ # # ]: 0 : std::map<RefEdge*, DLIList<CurveOverlapFacet*>* >::iterator facet_iter;
6325 [ # # ]: 0 : facet_iter=facet_map.begin();
6326 [ # # ][ # # ]: 0 : for(; facet_iter != facet_map.end(); facet_iter++ )
[ # # ][ # # ]
6327 : : {
6328 [ # # ]: 0 : DLIList<CurveOverlapFacet*> *co_facet_list = facet_iter->second;
6329 : :
6330 : : //delete all the facets in the list
6331 [ # # ][ # # ]: 0 : for( i=co_facet_list->size(); i--; )
6332 [ # # ][ # # ]: 0 : delete co_facet_list->get_and_step();
[ # # ]
6333 [ # # ][ # # ]: 0 : delete co_facet_list;
6334 : : }
6335 : :
6336 : : //reset tolerance
6337 [ # # ]: 0 : tolerance = GeometryQueryTool::get_geometry_factor()*GEOMETRY_RESABS;
6338 : :
6339 : : //after this you should only be left with unmerged, non-overlapping edges
6340 [ # # ]: 0 : edges1.remove_all_with_value( NULL );
6341 [ # # ]: 0 : edges2 -= overlapping_edges2;
6342 : :
6343 : : //if all the curves are either merged or overlapping and
6344 : : //no vertices of any curve will imprint onto any other curve...
6345 : : //suggest force merging the 2 surfaces
6346 [ # # ][ # # ]: 0 : if( edges1.size() == 0 && edges2.size() == 0 &&
[ # # ][ # # ]
[ # # ]
6347 [ # # ][ # # ]: 0 : positions_to_imprint_onto_face1.size() == 0 &&
[ # # ]
6348 [ # # ]: 0 : positions_to_imprint_onto_face2.size() == 0 )
6349 : : {
6350 : :
6351 : : //make sure the 2 surfaces have same number of curves and vertices
6352 [ # # ][ # # ]: 0 : if( face1->num_ref_vertices() == face2->num_ref_vertices() &&
[ # # ][ # # ]
[ # # ]
6353 [ # # ][ # # ]: 0 : face1->num_ref_edges() == face2->num_ref_edges() )
6354 : : {
6355 [ # # ]: 0 : if(execute)
6356 : : {
6357 [ # # ][ # # ]: 0 : MergeTool::instance()->force_merge(face1, face2);
6358 : : }
6359 : : else
6360 : : {
6361 [ # # ]: 0 : CubitString display_string("Force merge Surface ");
6362 [ # # ][ # # ]: 0 : display_string += CubitString::number(face1->id());
[ # # ][ # # ]
6363 [ # # ][ # # ]: 0 : display_string += " ";
[ # # ]
6364 [ # # ][ # # ]: 0 : display_string += CubitString::number(face2->id());
[ # # ][ # # ]
6365 [ # # ]: 0 : display_strings.append( display_string );
6366 : :
6367 [ # # ][ # # ]: 0 : CubitString command_string("merge surface ");
6368 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
6369 [ # # ][ # # ]: 0 : command_string += " ";
[ # # ]
6370 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
6371 [ # # ][ # # ]: 0 : command_string += " force";
[ # # ]
6372 [ # # ]: 0 : command_strings.append( command_string );
6373 : :
6374 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
6375 : : }
6376 : 0 : return;
6377 : : }
6378 : : }
6379 : :
6380 : : //try to suggest some curves you can imprint onto a surface
6381 [ # # ][ # # ]: 0 : if( edges1.size() || edges2.size() )
[ # # ][ # # ]
[ # # ]
6382 : : {
6383 [ # # ]: 0 : DLIList<RefFace*> face_list(1);
6384 [ # # ]: 0 : face_list.append( face2 );
6385 : :
6386 : : //see what edges in edges1 will imprint onto face2
6387 [ # # ][ # # ]: 0 : DLIList<RefEdge*> edges_to_imprint_onto_face2;
[ # # ]
6388 [ # # ][ # # ]: 0 : for( i=edges1.size(); i--; )
6389 : : {
6390 [ # # ]: 0 : RefEdge *edge1 = edges1.get_and_step();
6391 : :
6392 : : //project
6393 [ # # ]: 0 : DLIList<RefEdge*> edge_list(1);
6394 [ # # ][ # # ]: 0 : DLIList<RefEdge*> new_edges;
[ # # ]
6395 [ # # ]: 0 : edge_list.append( edge1);
6396 : :
6397 [ # # ][ # # ]: 0 : DLIList<Surface*> surface_list(1);
[ # # ]
6398 [ # # ][ # # ]: 0 : DLIList<Curve*> curves_to_project(1), projected_curves;
[ # # ][ # # ]
[ # # ][ # # ]
6399 : : GeometryModifyEngine* gme = GeometryModifyTool::instance()->common_modify_engine(
6400 : : face_list,
6401 : : edge_list,
6402 : : surface_list,
6403 [ # # ][ # # ]: 0 : curves_to_project);
6404 : : CubitStatus status = gme->
6405 [ # # ]: 0 : project_edges( surface_list, curves_to_project, projected_curves);
6406 : :
6407 [ # # ][ # # ]: 0 : if( projected_curves.size() == 0 )
6408 : 0 : continue;
6409 : :
6410 [ # # ]: 0 : Curve *projected_curve = projected_curves.get();
6411 : :
6412 : : //if midpoint of projected curve is far from original curve, continue
6413 [ # # ]: 0 : CubitVector original_curve_mid_point = edge1->center_point();
6414 [ # # ][ # # ]: 0 : if( original_curve_mid_point.distance_between( projected_curve->center_point() ) > tolerance )
[ # # ]
6415 : : {
6416 [ # # ][ # # ]: 0 : gme->get_gqe()->delete_solid_model_entities( projected_curve );
6417 : 0 : continue;
6418 : : }
6419 : :
6420 : 0 : bool is_curve_on_surface = false;
6421 : : //do a surface-curve intersection to see if the curve lies on the surface
6422 [ # # ][ # # ]: 0 : DLIList<Curve*> intersection_curves;
[ # # ]
6423 [ # # ]: 0 : status = gme->curve_surface_intersection( surface_list.get(),
6424 : : projected_curve,
6425 [ # # ]: 0 : intersection_curves);
6426 : :
6427 [ # # ][ # # ]: 0 : if( status == CUBIT_SUCCESS && intersection_curves.size() )
[ # # ][ # # ]
6428 : : {
6429 : : //remove any sliver curves
6430 [ # # ][ # # ]: 0 : for( j=intersection_curves.size(); j--; )
6431 : : {
6432 [ # # ]: 0 : Curve *tmp_curve = intersection_curves.get_and_step();
6433 [ # # ][ # # ]: 0 : if( tmp_curve->measure() < tolerance )
6434 : : {
6435 [ # # ][ # # ]: 0 : gme->get_gqe()->delete_solid_model_entities( tmp_curve );
6436 [ # # ]: 0 : intersection_curves.back();
6437 [ # # ]: 0 : intersection_curves.change_to( NULL );
6438 [ # # ]: 0 : intersection_curves.step();
6439 : : }
6440 : : }
6441 : :
6442 [ # # ]: 0 : intersection_curves.remove_all_with_value( NULL );
6443 : :
6444 [ # # ][ # # ]: 0 : if( intersection_curves.size() )
6445 : 0 : is_curve_on_surface = true;
6446 : :
6447 : : //delete the intersection curves
6448 [ # # ][ # # ]: 0 : for( j=intersection_curves.size(); j--; )
6449 [ # # ][ # # ]: 0 : gme->get_gqe()->delete_solid_model_entities( intersection_curves.get_and_step() );
[ # # ]
6450 : : }
6451 : :
6452 : : //maybe the surface-curve intersection method above didn't work...do
6453 : : //this more primitive method instead
6454 [ # # ]: 0 : if( is_curve_on_surface == false )
6455 : : {
6456 : : double distances_on_curves[3];
6457 : 0 : distances_on_curves[0] = .235;
6458 : 0 : distances_on_curves[1] = .468;
6459 : 0 : distances_on_curves[2] = .894;
6460 : :
6461 [ # # ]: 0 : for( j=0; j<3; j++ )
6462 : : {
6463 [ # # ]: 0 : CubitVector position_on_curve;
6464 : : projected_curve->position_from_fraction( distances_on_curves[j],
6465 [ # # ]: 0 : position_on_curve );
6466 : :
6467 [ # # ]: 0 : CubitVector closest_point_on_surface;
6468 : : face2->find_closest_point_trimmed( position_on_curve,
6469 [ # # ][ # # ]: 0 : closest_point_on_surface );
6470 : :
6471 [ # # ][ # # ]: 0 : if( position_on_curve.distance_between( closest_point_on_surface ) < tolerance )
6472 : : {
6473 : 0 : is_curve_on_surface = true;
6474 : 0 : break;
6475 : : }
6476 : : }
6477 : : }
6478 : :
6479 : : //delete the projected curve
6480 [ # # ][ # # ]: 0 : gme->get_gqe()->delete_solid_model_entities( projected_curve );
6481 : :
6482 [ # # ]: 0 : if( is_curve_on_surface == false )
6483 : 0 : continue;
6484 : :
6485 [ # # ][ # # ]: 0 : edges_to_imprint_onto_face2.append( edge1 );
[ # # ]
6486 : 0 : }
6487 : :
6488 : : //a possible force merge situation???
6489 [ # # ][ # # ]: 0 : if( edges_to_imprint_onto_face2.size() )
6490 : : {
6491 : : //are the number of vertices on both faces the same?
6492 [ # # ][ # # ]: 0 : if( face1->num_ref_vertices() == face2->num_ref_vertices() &&
[ # # ][ # # ]
[ # # ]
6493 [ # # ][ # # ]: 0 : face1->num_ref_edges() == face2->num_ref_edges() )
6494 : : {
6495 : 0 : double overlapping_area = 0;
6496 : : SurfaceOverlapTool::instance()->check_overlap(
6497 [ # # ][ # # ]: 0 : face1, face2, CUBIT_FALSE, CUBIT_FALSE, &overlapping_area );
6498 [ # # ]: 0 : double face1_area = face1->area();
6499 [ # # ]: 0 : double face2_area = face2->area();
6500 : :
6501 : : //make sure overlapping area is more than 99% of both surface areas
6502 : 0 : double area_diff1 = fabs( overlapping_area - face1_area );
6503 : 0 : double area_diff2 = fabs( overlapping_area - face2_area );
6504 : :
6505 [ # # ][ # # ]: 0 : if( area_diff1 < (face1_area*0.01) &&
6506 : 0 : area_diff2 < (face2_area*0.01) )
6507 : : {
6508 [ # # ]: 0 : if(execute)
6509 : : {
6510 [ # # ][ # # ]: 0 : MergeTool::instance()->force_merge(face1, face2);
6511 : : }
6512 : : else
6513 : : {
6514 [ # # ]: 0 : CubitString display_string("Force merge Surface ");
6515 [ # # ][ # # ]: 0 : display_string += CubitString::number(face1->id());
[ # # ][ # # ]
6516 [ # # ][ # # ]: 0 : display_string += " ";
[ # # ]
6517 [ # # ][ # # ]: 0 : display_string += CubitString::number(face2->id());
[ # # ][ # # ]
6518 [ # # ]: 0 : display_strings.append( display_string );
6519 : :
6520 [ # # ][ # # ]: 0 : CubitString command_string("merge surface ");
6521 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
6522 [ # # ][ # # ]: 0 : command_string += " ";
[ # # ]
6523 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
6524 [ # # ][ # # ]: 0 : command_string += " force";
[ # # ]
6525 [ # # ]: 0 : command_strings.append( command_string );
6526 : :
6527 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
6528 : : }
6529 : 0 : return;
6530 : : }
6531 : : }
6532 : : }
6533 : :
6534 [ # # ]: 0 : face_list.clean_out();
6535 [ # # ]: 0 : face_list.append( face1 );
6536 : :
6537 [ # # ][ # # ]: 0 : DLIList<RefEdge*> edges_to_imprint_onto_face1;
[ # # ]
6538 : : //see what edges in edges2 will imprint onto face1
6539 [ # # ][ # # ]: 0 : for( i=edges2.size(); i--; )
6540 : : {
6541 [ # # ]: 0 : RefEdge *edge2 = edges2.get_and_step();
6542 : :
6543 : : //project
6544 [ # # ]: 0 : DLIList<RefEdge*> edge_list(1);
6545 [ # # ][ # # ]: 0 : DLIList<RefEdge*> new_edges;
[ # # ]
6546 [ # # ]: 0 : edge_list.append( edge2);
6547 : :
6548 [ # # ][ # # ]: 0 : DLIList<Surface*> surface_list(1);
[ # # ]
6549 [ # # ][ # # ]: 0 : DLIList<Curve*> curves_to_project(1), projected_curves;
[ # # ][ # # ]
[ # # ][ # # ]
6550 : : GeometryModifyEngine* gme = GeometryModifyTool::instance()->common_modify_engine(
6551 : : face_list,
6552 : : edge_list,
6553 : : surface_list,
6554 [ # # ][ # # ]: 0 : curves_to_project);
6555 : : CubitStatus status = gme->
6556 [ # # ]: 0 : project_edges( surface_list, curves_to_project, projected_curves);
6557 : :
6558 [ # # ][ # # ]: 0 : if( projected_curves.size() == 0 )
6559 : 0 : continue;
6560 : :
6561 [ # # ]: 0 : Curve *projected_curve = projected_curves.get();
6562 : :
6563 : : //if midpoint of projected curve is far from original curve, continue
6564 [ # # ]: 0 : CubitVector original_curve_mid_point = edge2->center_point();
6565 [ # # ][ # # ]: 0 : if( original_curve_mid_point.distance_between( projected_curve->center_point() ) > tolerance )
[ # # ]
6566 : : {
6567 [ # # ][ # # ]: 0 : gme->get_gqe()->delete_solid_model_entities( projected_curve );
6568 : 0 : continue;
6569 : : }
6570 : :
6571 : 0 : bool is_curve_on_surface = false;
6572 : : //do a surface-curve intersection to see if the curve lies on the surface
6573 [ # # ][ # # ]: 0 : DLIList<Curve*> intersection_curves;
[ # # ]
6574 [ # # ]: 0 : status = gme->curve_surface_intersection( surface_list.get(),
6575 : : projected_curve,
6576 [ # # ]: 0 : intersection_curves);
6577 : :
6578 [ # # ][ # # ]: 0 : if( status == CUBIT_SUCCESS && intersection_curves.size() )
[ # # ][ # # ]
6579 : : {
6580 : : //remove any sliver curves
6581 [ # # ][ # # ]: 0 : for( j=intersection_curves.size(); j--; )
6582 : : {
6583 [ # # ]: 0 : Curve *tmp_curve = intersection_curves.get_and_step();
6584 [ # # ][ # # ]: 0 : if( tmp_curve->measure() < tolerance )
6585 : : {
6586 [ # # ][ # # ]: 0 : gme->get_gqe()->delete_solid_model_entities( tmp_curve );
6587 [ # # ]: 0 : intersection_curves.back();
6588 [ # # ]: 0 : intersection_curves.change_to( NULL );
6589 [ # # ]: 0 : intersection_curves.step();
6590 : : }
6591 : : }
6592 : :
6593 [ # # ]: 0 : intersection_curves.remove_all_with_value( NULL );
6594 : :
6595 [ # # ][ # # ]: 0 : if( intersection_curves.size() )
6596 : 0 : is_curve_on_surface = true;
6597 : :
6598 : : //delete the intersection curves
6599 [ # # ][ # # ]: 0 : for( j=intersection_curves.size(); j--; )
6600 [ # # ][ # # ]: 0 : gme->get_gqe()->delete_solid_model_entities( intersection_curves.get_and_step() );
[ # # ]
6601 : : }
6602 : :
6603 : : //maybe the surface-curve intersection method above didn't work...do
6604 : : //this more primitive method instead
6605 [ # # ]: 0 : if( is_curve_on_surface == false )
6606 : : {
6607 : : double distances_on_curves[3];
6608 : 0 : distances_on_curves[0] = .235;
6609 : 0 : distances_on_curves[1] = .468;
6610 : 0 : distances_on_curves[2] = .894;
6611 : :
6612 [ # # ]: 0 : for( j=0; j<3; j++ )
6613 : : {
6614 [ # # ]: 0 : CubitVector position_on_curve;
6615 : : projected_curve->position_from_fraction( distances_on_curves[j],
6616 [ # # ]: 0 : position_on_curve );
6617 : :
6618 [ # # ]: 0 : CubitVector closest_point_on_surface;
6619 : : face1->find_closest_point_trimmed( position_on_curve,
6620 [ # # ][ # # ]: 0 : closest_point_on_surface );
6621 : :
6622 [ # # ][ # # ]: 0 : if( position_on_curve.distance_between( closest_point_on_surface ) < tolerance )
6623 : : {
6624 : 0 : is_curve_on_surface = true;
6625 : 0 : break;
6626 : : }
6627 : : }
6628 : : }
6629 : :
6630 : : //delete the projected curve
6631 [ # # ][ # # ]: 0 : gme->get_gqe()->delete_solid_model_entities( projected_curve );
6632 : :
6633 [ # # ]: 0 : if( is_curve_on_surface == false )
6634 : 0 : continue;
6635 : :
6636 [ # # ][ # # ]: 0 : edges_to_imprint_onto_face1.append( edge2 );
[ # # ]
6637 : 0 : }
6638 : :
6639 : : //a possible force merge situation???
6640 [ # # ][ # # ]: 0 : if( edges_to_imprint_onto_face1.size() )
6641 : : {
6642 : : //are the number of vertices on both faces the same?
6643 [ # # ][ # # ]: 0 : if( face1->num_ref_vertices() == face2->num_ref_vertices() &&
[ # # ][ # # ]
[ # # ]
6644 [ # # ][ # # ]: 0 : face1->num_ref_edges() == face2->num_ref_edges() )
6645 : : {
6646 : 0 : double overlapping_area = 0;
6647 : : SurfaceOverlapTool::instance()->check_overlap(
6648 [ # # ][ # # ]: 0 : face1, face2, CUBIT_FALSE, CUBIT_FALSE, &overlapping_area );
6649 [ # # ]: 0 : double face1_area = face1->area();
6650 [ # # ]: 0 : double face2_area = face2->area();
6651 : :
6652 : : //make sure overlapping area is less than 1% of both surface areas
6653 : 0 : double area_diff1 = fabs( overlapping_area - face1_area );
6654 : 0 : double area_diff2 = fabs( overlapping_area - face2_area );
6655 : :
6656 [ # # ][ # # ]: 0 : if( area_diff1 < (face1_area*0.01) &&
6657 : 0 : area_diff2 < (face2_area*0.01) )
6658 : : {
6659 [ # # ]: 0 : if(execute)
6660 : : {
6661 [ # # ][ # # ]: 0 : MergeTool::instance()->force_merge(face1, face2);
6662 : : }
6663 : : else
6664 : : {
6665 [ # # ]: 0 : CubitString display_string("Force merge Surface ");
6666 [ # # ][ # # ]: 0 : display_string += CubitString::number(face1->id());
[ # # ][ # # ]
6667 [ # # ][ # # ]: 0 : display_string += " ";
[ # # ]
6668 [ # # ][ # # ]: 0 : display_string += CubitString::number(face2->id());
[ # # ][ # # ]
6669 [ # # ]: 0 : display_strings.append( display_string );
6670 : :
6671 [ # # ][ # # ]: 0 : CubitString command_string("merge surface ");
6672 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
6673 [ # # ][ # # ]: 0 : command_string += " ";
[ # # ]
6674 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
6675 [ # # ][ # # ]: 0 : command_string += " force";
[ # # ]
6676 [ # # ]: 0 : command_strings.append( command_string );
6677 : :
6678 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
6679 : : }
6680 : 0 : return;
6681 : : }
6682 : : }
6683 : : }
6684 : :
6685 : : //imprint all the edges onto both surfaces in a single command
6686 [ # # ][ # # ]: 0 : if( edges_to_imprint_onto_face1.size() &&
[ # # ][ # # ]
6687 [ # # ]: 0 : edges_to_imprint_onto_face2.size() )
6688 : : {
6689 [ # # ]: 0 : if(execute)
6690 : : {
6691 [ # # ]: 0 : DLIList<RefFace*> ref_face_list;
6692 [ # # ]: 0 : ref_face_list.append(face1);
6693 [ # # ]: 0 : ref_face_list.append(face2);
6694 [ # # ][ # # ]: 0 : DLIList<RefEdge*> ref_edge_list;
6695 [ # # ][ # # ]: 0 : for( i=edges_to_imprint_onto_face2.size(); i--; )
6696 [ # # ][ # # ]: 0 : ref_edge_list.append(edges_to_imprint_onto_face2.get_and_step());
6697 [ # # ][ # # ]: 0 : for( i=edges_to_imprint_onto_face1.size(); i--; )
6698 [ # # ][ # # ]: 0 : ref_edge_list.append(edges_to_imprint_onto_face1.get_and_step());
6699 [ # # ][ # # ]: 0 : DLIList<Body*> tmp_new_bodies;
6700 : : GeometryModifyTool::instance()->tolerant_imprint( ref_face_list,
6701 : : ref_edge_list,
6702 [ # # ][ # # ]: 0 : tmp_new_bodies, true );
6703 [ # # ]: 0 : return;
6704 : : }
6705 : : else
6706 : : {
6707 [ # # ]: 0 : CubitString command_string("Imprint tolerant surface ");
6708 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
6709 [ # # ][ # # ]: 0 : command_string += " ";
[ # # ]
6710 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
6711 [ # # ][ # # ]: 0 : command_string += " with curve ";
[ # # ]
6712 : :
6713 [ # # ][ # # ]: 0 : CubitString display_string("Imprint with curves ");
6714 : :
6715 [ # # ][ # # ]: 0 : CubitString curve_ids;
6716 [ # # ][ # # ]: 0 : for( i=edges_to_imprint_onto_face2.size(); i--; )
6717 : : {
6718 [ # # ]: 0 : RefEdge *tmp_edge = edges_to_imprint_onto_face2.get_and_step();
6719 [ # # ][ # # ]: 0 : curve_ids += CubitString::number(tmp_edge->id());
[ # # ][ # # ]
6720 [ # # ][ # # ]: 0 : curve_ids += " ";
[ # # ]
6721 : : }
6722 [ # # ][ # # ]: 0 : for( i=edges_to_imprint_onto_face1.size(); i--; )
6723 : : {
6724 [ # # ]: 0 : RefEdge *tmp_edge = edges_to_imprint_onto_face1.get_and_step();
6725 [ # # ][ # # ]: 0 : curve_ids += CubitString::number(tmp_edge->id());
[ # # ][ # # ]
6726 [ # # ][ # # ]: 0 : curve_ids += " ";
[ # # ]
6727 : : }
6728 : :
6729 [ # # ]: 0 : display_string += curve_ids;
6730 [ # # ]: 0 : command_string += curve_ids;
6731 [ # # ][ # # ]: 0 : command_string += "merge";
[ # # ]
6732 : :
6733 [ # # ][ # # ]: 0 : preview_string += " &&& highlight curve ";
[ # # ]
6734 [ # # ]: 0 : preview_string += curve_ids;
6735 : :
6736 [ # # ]: 0 : display_strings.append( display_string );
6737 [ # # ]: 0 : command_strings.append( command_string );
6738 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
6739 : : }
6740 : : }
6741 : : //imprint edges onto a single surface
6742 [ # # ][ # # ]: 0 : else if( edges_to_imprint_onto_face2.size() )
6743 : : {
6744 [ # # ]: 0 : if(execute)
6745 : : {
6746 [ # # ]: 0 : DLIList<RefFace*> ref_face_list;
6747 [ # # ]: 0 : ref_face_list.append(face2);
6748 [ # # ][ # # ]: 0 : DLIList<Body*> tmp_new_bodies;
6749 : : GeometryModifyTool::instance()->tolerant_imprint( ref_face_list,
6750 : : edges_to_imprint_onto_face2,
6751 [ # # ][ # # ]: 0 : tmp_new_bodies, true );
6752 [ # # ]: 0 : return;
6753 : : }
6754 : : else
6755 : : {
6756 [ # # ]: 0 : CubitString command_string("Imprint tolerant surface ");
6757 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
6758 [ # # ][ # # ]: 0 : command_string += " with curve ";
[ # # ]
6759 : :
6760 [ # # ][ # # ]: 0 : CubitString display_string("Imprint with curves ");
6761 [ # # ][ # # ]: 0 : preview_string += " &&& highlight curve ";
[ # # ]
6762 : :
6763 [ # # ][ # # ]: 0 : CubitString curve_ids;
6764 [ # # ][ # # ]: 0 : for( i=edges_to_imprint_onto_face2.size(); i--; )
6765 : : {
6766 [ # # ]: 0 : RefEdge *tmp_edge = edges_to_imprint_onto_face2.get_and_step();
6767 [ # # ][ # # ]: 0 : curve_ids += CubitString::number(tmp_edge->id());
[ # # ][ # # ]
6768 [ # # ][ # # ]: 0 : curve_ids += " ";
[ # # ]
6769 : : }
6770 : :
6771 [ # # ]: 0 : command_string += curve_ids;
6772 [ # # ]: 0 : display_string += curve_ids;
6773 [ # # ]: 0 : preview_string += curve_ids;
6774 : :
6775 [ # # ][ # # ]: 0 : command_string += " merge";
[ # # ]
6776 : :
6777 [ # # ]: 0 : display_strings.append( display_string );
6778 [ # # ]: 0 : command_strings.append( command_string );
6779 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
6780 : : }
6781 : : }
6782 : : //imprint edges onto a single surface
6783 [ # # ][ # # ]: 0 : else if( edges_to_imprint_onto_face1.size() )
6784 : : {
6785 [ # # ]: 0 : if(execute)
6786 : : {
6787 [ # # ]: 0 : DLIList<RefFace*> ref_face_list;
6788 [ # # ]: 0 : ref_face_list.append(face1);
6789 [ # # ][ # # ]: 0 : DLIList<Body*> tmp_new_bodies;
6790 : : GeometryModifyTool::instance()->tolerant_imprint( ref_face_list,
6791 : : edges_to_imprint_onto_face1,
6792 [ # # ][ # # ]: 0 : tmp_new_bodies, true );
6793 [ # # ]: 0 : return;
6794 : : }
6795 : : else
6796 : : {
6797 [ # # ]: 0 : CubitString command_string("Imprint tolerant surface ");
6798 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
6799 [ # # ][ # # ]: 0 : command_string += " with curve ";
[ # # ]
6800 : :
6801 [ # # ][ # # ]: 0 : CubitString display_string("Imprint with curves ");
6802 [ # # ][ # # ]: 0 : preview_string += " &&& highlight curve ";
[ # # ]
6803 : :
6804 [ # # ][ # # ]: 0 : CubitString curve_ids;
6805 [ # # ][ # # ]: 0 : for( i=edges_to_imprint_onto_face1.size(); i--; )
6806 : : {
6807 [ # # ]: 0 : RefEdge *tmp_edge = edges_to_imprint_onto_face1.get_and_step();
6808 [ # # ][ # # ]: 0 : curve_ids += CubitString::number(tmp_edge->id());
[ # # ][ # # ]
6809 [ # # ][ # # ]: 0 : curve_ids += " ";
[ # # ]
6810 : : }
6811 : :
6812 [ # # ]: 0 : command_string += curve_ids;
6813 [ # # ]: 0 : display_string += curve_ids;
6814 [ # # ]: 0 : preview_string += curve_ids;
6815 : :
6816 [ # # ][ # # ]: 0 : command_string += " merge";
[ # # ]
6817 : :
6818 [ # # ]: 0 : display_strings.append( display_string );
6819 [ # # ]: 0 : command_strings.append( command_string );
6820 [ # # ][ # # ]: 0 : preview_strings.append( preview_string );
6821 : : }
6822 : : }
6823 : :
6824 : : //if we came up with some solutions, get out
6825 [ # # ][ # # ]: 0 : if( display_strings.size() )
6826 [ # # ][ # # ]: 0 : return;
6827 : : }
6828 : :
6829 : : //just suggest some vertex imprints
6830 [ # # ][ # # ]: 0 : if( positions_to_imprint_onto_face1.size() ||
[ # # ][ # # ]
6831 [ # # ]: 0 : positions_to_imprint_onto_face2.size() )
6832 : : {
6833 : : //Are you possibly generating sliver curves?
6834 : : //Offer a merge force merge instead if topology is identical
6835 [ # # ][ # # ]: 0 : if( face1->num_ref_vertices() == face2->num_ref_vertices() &&
[ # # ][ # # ]
[ # # ]
6836 [ # # ][ # # ]: 0 : face1->num_ref_edges() == face2->num_ref_edges() )
6837 : : {
6838 [ # # ][ # # ]: 0 : if((positions_to_imprint_onto_face1.size() &&
[ # # ]
6839 [ # # ][ # # ]: 0 : positions_to_imprint_onto_face1.size() == possible_slivers_on_face1 ) ||
[ # # ]
6840 [ # # ][ # # ]: 0 : (positions_to_imprint_onto_face2.size() &&
6841 [ # # ]: 0 : positions_to_imprint_onto_face2.size() == possible_slivers_on_face2 ))
6842 : : {
6843 [ # # ]: 0 : if(execute)
6844 : : {
6845 [ # # ][ # # ]: 0 : MergeTool::instance()->force_merge(face1, face2);
6846 : : }
6847 : : else
6848 : : {
6849 [ # # ]: 0 : CubitString display_string("Force merge Surface ");
6850 [ # # ][ # # ]: 0 : display_string += CubitString::number(face1->id());
[ # # ][ # # ]
6851 [ # # ][ # # ]: 0 : display_string += " ";
[ # # ]
6852 [ # # ][ # # ]: 0 : display_string += CubitString::number(face2->id());
[ # # ][ # # ]
6853 [ # # ]: 0 : display_strings.append( display_string );
6854 : :
6855 [ # # ][ # # ]: 0 : CubitString command_string("merge surface ");
6856 [ # # ][ # # ]: 0 : command_string += CubitString::number(face1->id());
[ # # ][ # # ]
6857 [ # # ][ # # ]: 0 : command_string += " ";
[ # # ]
6858 [ # # ][ # # ]: 0 : command_string += CubitString::number(face2->id());
[ # # ][ # # ]
6859 [ # # ][ # # ]: 0 : command_string += " force";
[ # # ]
6860 [ # # ][ # # ]: 0 : command_strings.append( command_string );
6861 : : }
6862 : :
6863 : 0 : return;
6864 : : }
6865 : : }
6866 : :
6867 [ # # ]: 0 : CubitString command_string;
6868 : : // CubitString *preview_string = NULL;
6869 [ # # ][ # # ]: 0 : if( positions_to_imprint_onto_face1.size() )
6870 : : {
6871 [ # # ]: 0 : if(execute)
6872 : : {
6873 [ # # ]: 0 : Body *b = face1->body();
6874 [ # # ]: 0 : if(b)
6875 : : {
6876 [ # # ]: 0 : DLIList<Body*> body_list;
6877 [ # # ]: 0 : body_list.append(b);
6878 [ # # ][ # # ]: 0 : DLIList<Body*> new_bodies;
6879 : : GeometryModifyTool::instance()->imprint( body_list, positions_to_imprint_onto_face1,
6880 [ # # ][ # # ]: 0 : new_bodies, false, true );
[ # # ]
6881 : : }
6882 : : }
6883 : : else
6884 : : {
6885 [ # # ][ # # ]: 0 : command_string = CubitString("Imprint volume ");
[ # # ]
6886 [ # # ]: 0 : RefVolume *volume1 = face1->ref_volume();
6887 [ # # ][ # # ]: 0 : command_string += CubitString::number(volume1->id());
[ # # ][ # # ]
6888 [ # # ][ # # ]: 0 : command_string += " with";
[ # # ]
6889 [ # # ][ # # ]: 0 : preview_string += " &&& highlight";
[ # # ]
6890 [ # # ][ # # ]: 0 : for( i=positions_to_imprint_onto_face1.size(); i--; )
6891 : : {
6892 : : //construct the command string
6893 [ # # ][ # # ]: 0 : command_string += " position {";
[ # # ]
6894 [ # # ][ # # ]: 0 : CubitVector tmp_pos = positions_to_imprint_onto_face1.get_and_step();
6895 [ # # ][ # # ]: 0 : command_string += CubitString::number( tmp_pos.x(), 0, 7 );
[ # # ][ # # ]
6896 [ # # ][ # # ]: 0 : command_string += "} {";
[ # # ]
6897 [ # # ][ # # ]: 0 : command_string += CubitString::number( tmp_pos.y(), 0, 7 );
[ # # ][ # # ]
6898 [ # # ][ # # ]: 0 : command_string += "} {";
[ # # ]
6899 [ # # ][ # # ]: 0 : command_string += CubitString::number( tmp_pos.z(), 0, 7 );
[ # # ][ # # ]
6900 [ # # ][ # # ]: 0 : command_string += "}";
[ # # ]
6901 : :
6902 : : //construct the preview string
6903 [ # # ][ # # ]: 0 : preview_string += " location ";
[ # # ]
6904 [ # # ][ # # ]: 0 : preview_string += CubitString::number( tmp_pos.x(), 0, 7 );
[ # # ][ # # ]
6905 [ # # ][ # # ]: 0 : preview_string += " ";
[ # # ]
6906 [ # # ][ # # ]: 0 : preview_string += CubitString::number( tmp_pos.y(), 0, 7 );
[ # # ][ # # ]
6907 [ # # ][ # # ]: 0 : preview_string += " ";
[ # # ]
6908 [ # # ][ # # ]: 0 : preview_string += CubitString::number( tmp_pos.z(), 0, 7 );
[ # # ][ # # ]
6909 [ # # ][ # # ]: 0 : preview_string += " ";
[ # # ]
6910 : : }
6911 [ # # ][ # # ]: 0 : command_string += " merge";
[ # # ]
6912 : : }
6913 : : }
6914 : :
6915 [ # # ][ # # ]: 0 : if( positions_to_imprint_onto_face2.size() )
6916 : : {
6917 [ # # ]: 0 : if(execute)
6918 : : {
6919 [ # # ]: 0 : Body *b = face2->body();
6920 [ # # ]: 0 : if(b)
6921 : : {
6922 [ # # ]: 0 : DLIList<Body*> body_list;
6923 [ # # ]: 0 : body_list.append(b);
6924 [ # # ][ # # ]: 0 : DLIList<Body*> new_bodies;
6925 : : GeometryModifyTool::instance()->imprint( body_list, positions_to_imprint_onto_face2,
6926 [ # # ][ # # ]: 0 : new_bodies, false, true );
[ # # ]
6927 : : }
6928 : : }
6929 : : else
6930 : : {
6931 [ # # ][ # # ]: 0 : if( command_string.is_empty() )
6932 [ # # ][ # # ]: 0 : command_string = CubitString("Imprint volume ");
[ # # ]
6933 : : else
6934 [ # # ][ # # ]: 0 : command_string += " &&& Imprint volume ";
[ # # ]
6935 : :
6936 [ # # ][ # # ]: 0 : if( positions_to_imprint_onto_face1.size() == 0 )
6937 [ # # ][ # # ]: 0 : preview_string += " &&& highlight";
[ # # ]
6938 : :
6939 [ # # ]: 0 : RefVolume *volume2 = face2->ref_volume();
6940 [ # # ][ # # ]: 0 : command_string += CubitString::number(volume2->id());
[ # # ][ # # ]
6941 [ # # ][ # # ]: 0 : command_string += " with";
[ # # ]
6942 [ # # ][ # # ]: 0 : for( i=positions_to_imprint_onto_face2.size(); i--; )
6943 : : {
6944 [ # # ][ # # ]: 0 : command_string += " position {";
[ # # ]
6945 [ # # ][ # # ]: 0 : CubitVector tmp_pos = positions_to_imprint_onto_face2.get_and_step();
6946 : :
6947 [ # # ][ # # ]: 0 : command_string += CubitString::number( tmp_pos.x(), 0, 7 );
[ # # ][ # # ]
6948 [ # # ][ # # ]: 0 : command_string += "} {";
[ # # ]
6949 [ # # ][ # # ]: 0 : command_string += CubitString::number( tmp_pos.y(), 0, 7 );
[ # # ][ # # ]
6950 [ # # ][ # # ]: 0 : command_string += "} {";
[ # # ]
6951 [ # # ][ # # ]: 0 : command_string += CubitString::number( tmp_pos.z(), 0, 7 );
[ # # ][ # # ]
6952 [ # # ][ # # ]: 0 : command_string += "}";
[ # # ]
6953 : :
6954 : : //construct the preview string
6955 [ # # ][ # # ]: 0 : preview_string += " location ";
[ # # ]
6956 [ # # ][ # # ]: 0 : preview_string += CubitString::number( tmp_pos.x(), 0, 7 );
[ # # ][ # # ]
6957 [ # # ][ # # ]: 0 : preview_string += " ";
[ # # ]
6958 [ # # ][ # # ]: 0 : preview_string += CubitString::number( tmp_pos.y(), 0, 7 );
[ # # ][ # # ]
6959 [ # # ][ # # ]: 0 : preview_string += " ";
[ # # ]
6960 [ # # ][ # # ]: 0 : preview_string += CubitString::number( tmp_pos.z(), 0, 7 );
[ # # ][ # # ]
6961 [ # # ][ # # ]: 0 : preview_string += " ";
[ # # ]
6962 : : }
6963 [ # # ][ # # ]: 0 : command_string += " merge";
[ # # ]
6964 : : }
6965 : : }
6966 : :
6967 [ # # ]: 0 : if(!execute)
6968 : : {
6969 [ # # ]: 0 : command_strings.append( command_string );
6970 [ # # ]: 0 : preview_strings.append( preview_string );
6971 : :
6972 : : //create the display string
6973 [ # # ]: 0 : CubitString display_string("Imprint with positions" );
6974 [ # # ][ # # ]: 0 : display_strings.append( display_string );
6975 [ # # ]: 0 : }
6976 : : }
6977 : :
6978 [ # # ]: 0 : return;
6979 [ + - ][ + - ]: 6540 : }
6980 : :
6981 : :
|