Branch data Line data Source code
1 : : //-------------------------------------------------------------------------
2 : : // Copyright Notice
3 : : //
4 : : // Copyright (c) 1996
5 : : // by Malcolm J. Panthaki, DBA, and the University of New Mexico.
6 : : //-------------------------------------------------------------------------
7 : :
8 : : //-------------------------------------------------------------------------
9 : : //
10 : : // Filename : ModelQueryEngine.C
11 : : //
12 : : // Purpose : This file contains the implementation of the class
13 : : // ModelQueryEngine.
14 : : //
15 : : // Special Notes :
16 : : //
17 : : // Creator : Xuechen Liu
18 : : //
19 : : // Creation Date : 06/08/96
20 : : //
21 : : // Owner : Malcolm J. Panthaki
22 : : //-------------------------------------------------------------------------
23 : :
24 : : // ********** BEGIN STANDARD INCLUDES **********
25 : :
26 : : #include <stdio.h>
27 : :
28 : : // ********** END STANDARD INCLUDES **********
29 : :
30 : : // ********** BEGIN MOTIF INCLUDES **********
31 : : // ********** END MOTIF INCLUDES **********
32 : :
33 : : // ********** BEGIN OPEN INVENTOR INCLUDES **********
34 : : // ********** END OPEN INVENTOR INCLUDES **********
35 : :
36 : : // ********** BEGIN CUBIT INCLUDES **********
37 : :
38 : : #include "CubitMessage.hpp"
39 : : #include "ModelQueryEngine.hpp"
40 : : #include "TopologyEntity.hpp"
41 : : #include "DLIList.hpp"
42 : : #include "CastTo.hpp"
43 : : #include "RefVertex.hpp"
44 : : #include "CoVertex.hpp"
45 : : #include "Chain.hpp"
46 : : #include "RefEdge.hpp"
47 : : #include "CoEdge.hpp"
48 : : #include "Loop.hpp"
49 : : #include "RefFace.hpp"
50 : : #include "CoFace.hpp"
51 : : #include "Shell.hpp"
52 : : #include "Body.hpp"
53 : : #include "CoVolume.hpp"
54 : : // ********** END CUBIT INCLUDES **********
55 : :
56 : : // ********** BEGIN STATIC DECLARATIONS **********
57 : :
58 : : ModelQueryEngine* ModelQueryEngine::instance_ = NULL;
59 : :
60 : : // ********** END STATIC DECLARATIONS **********
61 : :
62 : : // ********** BEGIN PUBLIC FUNCTIONS **********
63 : :
64 : : //-------------------------------------------------------------------------
65 : : // Purpose : Controls the access and creation of the sole instance
66 : : // of this class.
67 : : //
68 : : // Special Notes :
69 : : //
70 : : // Creator : Xuechen Liu
71 : : //
72 : : // Creation Date : 06/08/96
73 : : //-------------------------------------------------------------------------
74 : 5648181 : ModelQueryEngine* ModelQueryEngine::instance()
75 : : {
76 [ + + ]: 5648181 : if (instance_ == NULL)
77 : : {
78 [ + - ]: 683 : instance_ = new ModelQueryEngine;
79 : : }
80 : 5648181 : return instance_;
81 : : }
82 : :
83 : : //-------------------------------------------------------------------------
84 : : // Purpose : Destructor of the ModelQueryEngine class.
85 : : //
86 : : // Special Notes :
87 : : //
88 : : // Creator : Xuechen Liu
89 : : //
90 : : // Creation Date : 06/08/96
91 : : //-------------------------------------------------------------------------
92 [ + - ][ + + ]: 724 : ModelQueryEngine::~ModelQueryEngine()
[ + - ]
93 : : {
94 : : // Set static instance_ to zero to indicated that we are dead.
95 : 181 : instance_ = NULL;
96 : 181 : }
97 : :
98 : :
99 : : // ********** END PUBLIC FUNCTIONS **********
100 : :
101 : : // ********** BEGIN PROTECTED FUNCTIONS **********
102 : :
103 : : //-------------------------------------------------------------------------
104 : : // Purpose : Constructor of the ModelQueryEngine class.
105 : : //
106 : : // Special Notes :
107 : : //
108 : : // Creator : Xuechen Liu
109 : : //
110 : : // Creation Date : 06/08/96
111 : : //-------------------------------------------------------------------------
112 [ + - ]: 2732 : ModelQueryEngine::ModelQueryEngine() : queryCallStackDepth(0)
[ + + # # ]
113 : : {
114 [ # # ]: 683 : }
115 : :
116 : :
117 : : //-------------------------------------------------------------------------
118 : : // Purpose : Query model
119 : : //
120 : : // Special Notes :
121 : : //
122 : : // Creator : Jason Kraftcheck
123 : : //
124 : : // Creation Date : 07/29/03
125 : : //-------------------------------------------------------------------------
126 : 471852 : CubitStatus ModelQueryEngine::query_model_and_append(
127 : : TopologyEntity& source_object,
128 : : DagType target_type,
129 : : DLIList<TopologyEntity*>& result_set )
130 : : {
131 [ + - ]: 471852 : BeginQuery lock;
132 : :
133 [ + - ]: 471852 : DagType source_type = source_object.dag_type();
134 : :
135 [ + - ][ + - ]: 471852 : if (!source_type.is_valid() || !target_type.is_valid())
[ + - ][ - + ]
[ - + ]
136 : 0 : return CUBIT_FAILURE;
137 : :
138 [ + - ][ + + ]: 471852 : else if (source_type < target_type)
139 [ + - ]: 68748 : return query_append_parents( source_object, target_type, result_set );
140 : :
141 [ + - ][ + + ]: 403104 : else if (source_type > target_type)
142 [ + - ]: 399498 : return query_append_children( source_object, target_type, result_set );
143 : :
144 : : else // same type
145 : : {
146 [ + - ][ - + ]: 3606 : assert(source_type == target_type);
147 [ + - ][ + + ]: 3606 : if (!encountered(&source_object))
148 [ + - ]: 11 : result_set.append(&source_object);
149 : 3606 : return CUBIT_SUCCESS;
150 [ + - ]: 471852 : }
151 : : }
152 : :
153 : :
154 : : //-------------------------------------------------------------------------
155 : : // Purpose : Query model
156 : : //
157 : : // Special Notes :
158 : : //
159 : : // Creator : Jason Kraftcheck
160 : : //
161 : : // Creation Date : 07/29/03
162 : : //-------------------------------------------------------------------------
163 : 433472 : CubitStatus ModelQueryEngine::query_model(
164 : : TopologyEntity& source_object,
165 : : DagType target_type,
166 : : DLIList<TopologyEntity*>& result_set )
167 : : {
168 : 433472 : result_set.clean_out();
169 : 433472 : return query_model_and_append( source_object, target_type, result_set );
170 : : }
171 : :
172 : :
173 : : //-------------------------------------------------------------------------
174 : : // Purpose : Query model
175 : : //
176 : : // Special Notes :
177 : : //
178 : : // Creator : Jason Kraftcheck
179 : : //
180 : : // Creation Date : 07/29/03
181 : : //-------------------------------------------------------------------------
182 : 25626 : CubitStatus ModelQueryEngine::query_model(
183 : : DLIList<TopologyEntity*>& source_set,
184 : : DagType target_type,
185 : : DLIList<TopologyEntity*>& result_set )
186 : : {
187 : 25626 : result_set.clean_out();
188 : 25626 : return query_model_and_append( source_set, target_type, result_set );
189 : : }
190 : :
191 : :
192 : : //-------------------------------------------------------------------------
193 : : // Purpose : Query model
194 : : //
195 : : // Special Notes :
196 : : //
197 : : // Creator : Jason Kraftcheck
198 : : //
199 : : // Creation Date : 07/29/03
200 : : //-------------------------------------------------------------------------
201 : 25626 : CubitStatus ModelQueryEngine::query_model_and_append(
202 : : DLIList<TopologyEntity*>& source_set,
203 : : DagType target_type,
204 : : DLIList<TopologyEntity*>& result_set )
205 : : {
206 [ + - ]: 25626 : BeginQuery lock;
207 : 25626 : CubitStatus result = CUBIT_SUCCESS;
208 : :
209 [ + - ]: 25626 : source_set.reset();
210 [ + - ][ + + ]: 64006 : for (int i = source_set.size(); i--; )
211 : : {
212 [ + - ]: 38380 : TopologyEntity& source = *source_set.get_and_step();
213 [ + - ][ - + ]: 38380 : if (!query_model_and_append( source, target_type, result_set ))
214 : 0 : result = CUBIT_FAILURE;
215 : : }
216 : :
217 [ + - ]: 25626 : return result;
218 : : }
219 : :
220 : : // ********** END PROTECTED FUNCTIONS **********
221 : :
222 : : //-------------------------------------------------------------------------
223 : : // Purpose : Query downwards
224 : : //
225 : : // Special Notes :
226 : : //
227 : : // Creator : Jason Kraftcheck
228 : : //
229 : : // Creation Date : 07/29/03
230 : : //-------------------------------------------------------------------------
231 : 399498 : CubitStatus ModelQueryEngine::query_append_children (
232 : : TopologyEntity& source_object,
233 : : DagType target_type,
234 : : DLIList<TopologyEntity*>& result_set )
235 : : {
236 [ + - ]: 399498 : BeginQuery lock;
237 : :
238 [ + - ]: 399498 : DagType current_type = source_object.dag_type();
239 [ + - ][ + - ]: 399498 : assert(current_type.is_valid() && target_type.is_valid());
[ + - ][ - + ]
240 [ + - ][ - + ]: 399498 : assert(current_type > target_type);
241 : :
242 [ + - ]: 399498 : intermediateNodeSets[0].clean_out();
243 [ + - ]: 399498 : intermediateNodeSets[0].append(&source_object);
244 : 399498 : int current_index = 0;
245 : :
246 [ + - ][ + + ]: 1329616 : while (current_type > target_type)
247 : : {
248 : 930118 : DLIList<TopologyEntity*>& current_set = intermediateNodeSets[ current_index];
249 : 930118 : DLIList<TopologyEntity*>& next_set = intermediateNodeSets[!current_index];
250 : :
251 [ + - ]: 930118 : next_set.clean_out();
252 [ + - ]: 930118 : current_set.reset();
253 [ + - ][ + + ]: 3899625 : for (int i = current_set.size(); i--; )
254 : : {
255 [ + - ]: 2969507 : TopologyEntity* current_ptr = current_set.get_and_step();
256 [ + - ]: 2969507 : current_ptr->query_append_children(next_set);
257 : : }
258 : :
259 : 930118 : current_index = !current_index;
260 [ + - ]: 930118 : current_type--;
261 : : }
262 : :
263 [ + - ]: 399498 : result_set += intermediateNodeSets[current_index];
264 [ + - ]: 399498 : return CUBIT_SUCCESS;
265 : : }
266 : :
267 : :
268 : : //-------------------------------------------------------------------------
269 : : // Purpose : Query upwards
270 : : //
271 : : // Special Notes :
272 : : //
273 : : // Creator : Jason Kraftcheck
274 : : //
275 : : // Creation Date : 07/29/03
276 : : //-------------------------------------------------------------------------
277 : 68748 : CubitStatus ModelQueryEngine::query_append_parents(
278 : : TopologyEntity& source_object,
279 : : DagType target_type,
280 : : DLIList<TopologyEntity*>& result_set )
281 : : {
282 [ + - ]: 68748 : BeginQuery lock;
283 : :
284 [ + - ]: 68748 : DagType current_type = source_object.dag_type();
285 [ + - ][ + - ]: 68748 : assert(current_type.is_valid() && target_type.is_valid());
[ + - ][ - + ]
286 [ + - ][ - + ]: 68748 : assert(current_type < target_type);
287 : :
288 [ + - ]: 68748 : intermediateNodeSets[0].clean_out();
289 [ + - ]: 68748 : intermediateNodeSets[0].append(&source_object);
290 : 68748 : int current_index = 0;
291 : :
292 [ + - ][ + + ]: 273430 : while (current_type < target_type)
293 : : {
294 : 204682 : DLIList<TopologyEntity*>& current_set = intermediateNodeSets[ current_index];
295 : 204682 : DLIList<TopologyEntity*>& next_set = intermediateNodeSets[!current_index];
296 : :
297 [ + - ]: 204682 : next_set.clean_out();
298 [ + - ]: 204682 : current_set.reset();
299 [ + - ][ + + ]: 600739 : for (int i = current_set.size(); i--; )
300 : : {
301 [ + - ]: 396057 : TopologyEntity* current_ptr = current_set.get_and_step();
302 [ + - ]: 396057 : current_ptr->query_append_parents(next_set);
303 : : }
304 : :
305 : 204682 : current_index = !current_index;
306 [ + - ]: 204682 : current_type++;
307 : : }
308 : :
309 [ + - ]: 68748 : result_set += intermediateNodeSets[current_index];
310 [ + - ]: 68748 : return CUBIT_SUCCESS;
311 : : }
312 : :
313 : : //-------------------------------------------------------------------------
314 : : // Purpose : Mark node encountered
315 : : //
316 : : // Special Notes :
317 : : //
318 : : // Creator : Jason Kraftcheck
319 : : //
320 : : // Creation Date : 07/24/03
321 : : //-------------------------------------------------------------------------
322 : 4476162 : bool ModelQueryEngine::encountered( TopologyEntity* node_ptr )
323 : : {
324 [ + + ]: 4476162 : if (node_ptr->encountered_)
325 : 626745 : return true;
326 : :
327 : 3849417 : encounteredSet.append(node_ptr);
328 : 3849417 : node_ptr->encountered_ = true;
329 : 3849417 : return false;
330 : : }
331 : :
332 : 965724 : void ModelQueryEngine::inc_query_call_stack()
333 : : {
334 : 965724 : queryCallStackDepth++;
335 : 965724 : }
336 : :
337 : 965724 : void ModelQueryEngine::dec_query_call_stack()
338 : : {
339 [ - + ]: 965724 : assert(queryCallStackDepth > 0);
340 : 965724 : queryCallStackDepth--;
341 [ + + ]: 965724 : if (queryCallStackDepth == 0)
342 [ + + ]: 4308515 : while (encounteredSet.size())
343 : 3849417 : encounteredSet.pop()->encountered_ = CUBIT_FALSE;
344 [ + - ][ + - ]: 6540 : }
345 : :
346 : : // ********** BEGIN PRIVATE FUNCTIONS **********
347 : : // ********** END PRIVATE FUNCTIONS **********
348 : :
349 : : // ********** BEGIN HELPER CLASSES **********
350 : : // ********** END HELPER CLASSES **********
351 : :
352 : : // ********** BEGIN EXTERN FUNCTIONS **********
353 : : // ********** END EXTERN FUNCTIONS **********
354 : :
355 : : // ********** BEGIN STATIC FUNCTIONS **********
356 : : // ********** END STATIC FUNCTIONS **********
357 : :
358 : :
|