Branch data Line data Source code
1 : : #include "CADeferredAttrib.hpp"
2 : : #include "CubitSimpleAttrib.hpp"
3 : : #include "ToolDataUser.hpp"
4 : : #include "TDUniqueId.hpp"
5 : : #include "CastTo.hpp"
6 : : #include "RefEntity.hpp"
7 : : #include "DLIList.hpp"
8 : : #include "CubitMessage.hpp"
9 : : #include <algorithm>
10 : :
11 : 1635 : std::vector<CubitAttrib*> CADeferredAttrib::unactuatedCAs;
12 : 1635 : std::vector<CADeferredAttrib*> CADeferredAttrib::allCADeferredAttribs;
13 : :
14 : 10348 : CubitAttrib* CADeferredAttrib_creator(RefEntity* entity, const CubitSimpleAttrib& p_csa)
15 : : {
16 : 10348 : CADeferredAttrib *new_attrib = NULL;
17 : :
18 : : // Deferred attributes are a special case -- they should only get created
19 : : // when restoring from a file, in which case p_csa should be non-NULL
20 [ - + ]: 10348 : if (!p_csa.isEmpty())
21 : : {
22 [ # # ]: 0 : new_attrib = new CADeferredAttrib(entity, p_csa);
23 : : }
24 : 10348 : return new_attrib;
25 : : }
26 : :
27 : :
28 [ # # ]: 0 : CADeferredAttrib::~CADeferredAttrib()
29 : : {
30 : : allCADeferredAttribs.erase(
31 : : std::remove(allCADeferredAttribs.begin(), allCADeferredAttribs.end(), this), allCADeferredAttribs.end()
32 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
[ # # ]
33 [ # # ]: 0 : }
34 : :
35 : 0 : CADeferredAttrib::CADeferredAttrib(RefEntity *, const CubitSimpleAttrib &csa_ptr)
36 [ # # ]: 0 : : CubitAttrib(NULL)
37 : : {
38 [ # # ]: 0 : init_csa(csa_ptr);
39 : 0 : hasUpdated = CUBIT_TRUE;
40 : 0 : }
41 : :
42 : : namespace {
43 : : struct find_attrib_id
44 : : {
45 : : int mId;
46 : 0 : find_attrib_id(int id) : mId(id) {}
47 : 0 : bool operator()(CADeferredAttrib* attr)
48 : : {
49 : 0 : return attr->unique_id() == mId;
50 : : }
51 : : };
52 : :
53 : : }
54 : :
55 : :
56 : 0 : CubitStatus CADeferredAttrib::init_csa(const CubitSimpleAttrib &csa_ptr)
57 : : {
58 [ # # ][ # # ]: 0 : int csa_type = CGMApp::instance()->attrib_manager()->attrib_type(csa_ptr);
[ # # ]
59 [ # # ]: 0 : if (CA_DEFERRED_ATTRIB != csa_type)
60 : : {
61 : 0 : assert(false);
62 : : return CUBIT_FAILURE;
63 : : }
64 : :
65 : : // initialize this according to csa_ptr
66 : :
67 : : // first get the uniqueId off the csa
68 [ # # ][ # # ]: 0 : uniqueId = csa_ptr.int_data_list()[0];
69 [ # # ]: 0 : assert(uniqueId > 0);
70 : :
71 : : // now check to see if we have this CADA alreedy; if so, set the
72 : : // delete flag and exit
73 [ # # ][ # # ]: 0 : std::vector<CADeferredAttrib*>::iterator iter = std::find_if(allCADeferredAttribs.begin(), allCADeferredAttribs.end(), find_attrib_id(uniqueId));
[ # # ]
74 : :
75 [ # # ][ # # ]: 0 : if (iter != allCADeferredAttribs.end()) {
[ # # ]
76 : 0 : deleteAttrib = CUBIT_TRUE;
77 : 0 : return CUBIT_SUCCESS;
78 : : }
79 : :
80 : : // copy the info on the csa; need a new one, since
81 : : // we don't own the original
82 [ # # ][ # # ]: 0 : thisCSA = csa_from_dcsa(csa_ptr);
[ # # ]
83 [ # # ][ # # ]: 0 : assert(!thisCSA.isEmpty());
84 : :
85 : : // add this to the global list
86 [ # # ]: 0 : allCADeferredAttribs.push_back(this);
87 : :
88 : 0 : return CUBIT_SUCCESS;
89 : : }
90 : :
91 : 0 : CubitStatus CADeferredAttrib::actuate()
92 : : {
93 : : // test to see if we can assign this CADA to a new owner; set
94 : : // flag accordingly
95 [ # # ]: 0 : if (assign_to_owner()) {
96 : 0 : hasActuated = CUBIT_TRUE;
97 : 0 : return CUBIT_SUCCESS;
98 : : }
99 : 0 : else return CUBIT_FAILURE;
100 : : }
101 : :
102 : 0 : CubitStatus CADeferredAttrib::update()
103 : : {
104 : : // the hasUpdated flag should always be true by the time
105 : : // we get here, since the function that put this CA on the
106 : : // owning entity set the flag
107 [ # # ]: 0 : assert(hasUpdated == CUBIT_TRUE);
108 : 0 : return CUBIT_SUCCESS;
109 : : }
110 : :
111 : 0 : CubitStatus CADeferredAttrib::reset()
112 : : {
113 : : // do nothing; this CA manages its own duplicates, so no need
114 : : // to worry about them in parent code
115 : 0 : return CUBIT_SUCCESS;
116 : : }
117 : :
118 : 0 : CubitSimpleAttrib CADeferredAttrib::cubit_simple_attrib()
119 : : {
120 : 0 : return thisCSA;
121 : : }
122 : :
123 : 0 : CubitStatus CADeferredAttrib::assign_to_owner(CubitAttribUser *owner)
124 : : {
125 : : //- looks for an entity with the right uid, assigns itself to
126 : : //- that entity if found
127 : :
128 [ # # ]: 0 : if (uniqueId == 0) return CUBIT_FAILURE;
129 : :
130 [ # # ]: 0 : if (owner == NULL) {
131 [ # # ]: 0 : ToolDataUser *tdu = TDUniqueId::find_td_unique_id(uniqueId);
132 [ # # ]: 0 : owner = CAST_TO(tdu, CubitAttribUser);
133 : : }
134 : :
135 [ # # ]: 0 : if (owner == NULL) return CUBIT_FAILURE;
136 : :
137 : : // ok, we have an owner; create a new CA using the csa, assigning
138 : : // it to the ref entity
139 [ # # ]: 0 : RefEntity *ref_ent = CAST_TO(owner, RefEntity);
140 [ # # ]: 0 : assert (ref_ent != 0);
141 : :
142 : : // CubitAttrib *new_cubit_attrib =
143 : : // CGMApp::instance()->attrib_manager()->create_cubit_attrib(thisCSA, ref_ent);
144 [ # # ][ # # ]: 0 : int attrib_type = CGMApp::instance()->attrib_manager()->attrib_type(thisCSA);
[ # # ]
145 : : CubitAttrib *new_cubit_attrib =
146 [ # # ][ # # ]: 0 : CGMApp::instance()->attrib_manager()->create_cubit_attrib(attrib_type, ref_ent, thisCSA);
[ # # ]
147 : :
148 : : // now remove this CADA from the global list and add the new CA
149 : : // to the unactuated list
150 : : allCADeferredAttribs.erase(
151 : : std::remove(allCADeferredAttribs.begin(), allCADeferredAttribs.end(), this), allCADeferredAttribs.end()
152 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
[ # # ]
153 : :
154 : : // new attribute might be NULL, if there was already one there
155 [ # # ]: 0 : if (NULL != new_cubit_attrib)
156 [ # # ]: 0 : unactuatedCAs.push_back(new_cubit_attrib);
157 : :
158 : : // ok, all done
159 : :
160 : 0 : deleteAttrib = CUBIT_TRUE;
161 : 0 : return CUBIT_SUCCESS;
162 : : }
163 : :
164 : 0 : CubitStatus CADeferredAttrib::get_deferred_attribs(const int uid,
165 : : std::vector<CADeferredAttrib*> &cada_list)
166 : : {
167 : : // find a deferred attribute for the entity with the uid passed in
168 : 0 : cada_list.clear();
169 : :
170 [ # # ][ # # ]: 0 : for(std::vector<CADeferredAttrib*>::iterator iter=allCADeferredAttribs.begin();
[ # # ][ # # ]
171 [ # # ]: 0 : iter != allCADeferredAttribs.end(); ++iter)
172 : : {
173 [ # # ][ # # ]: 0 : if((*iter)->unique_id() == uid)
[ # # ]
174 : : {
175 [ # # ][ # # ]: 0 : cada_list.push_back(*iter);
176 : : }
177 : : }
178 : :
179 [ # # ]: 0 : if (cada_list.size() > 0) return CUBIT_SUCCESS;
180 : 0 : else return CUBIT_FAILURE;
181 : : }
182 : :
183 : 1137 : CubitStatus CADeferredAttrib::cleanup_cadas(const CubitBoolean from_constructor,
184 : : const CubitBoolean after_geom_changes)
185 : : {
186 : 1137 : CubitStatus status = CUBIT_FAILURE;
187 : :
188 [ + - ]: 1137 : if (CUBIT_TRUE == from_constructor)
189 : 1137 : status = CADeferredAttrib::cleanup_cadas_private(CUBIT_TRUE, CUBIT_FALSE);
190 : :
191 : : // exit if we're not to actuate for after_geom_changes
192 [ + - ]: 1137 : if (CUBIT_TRUE == after_geom_changes)
193 : 1137 : status = CADeferredAttrib::cleanup_cadas_private(CUBIT_FALSE, CUBIT_TRUE);
194 : :
195 : 1137 : return status;
196 : : }
197 : :
198 : 2274 : CubitStatus CADeferredAttrib::cleanup_cadas_private(const CubitBoolean from_constructor,
199 : : const CubitBoolean after_geom_changes)
200 : : {
201 : : // moves between the global CADA list and the unactuated list:
202 : : //
203 : : // 1. tries to actuate all CADAs on unactuated list
204 : : // 2. tries to assign_to_owner all CADAs on global list
205 : : //
206 : : // after each of these steps, if anything happened, the loop is
207 : : // repeated
208 : : // this function should be called as part of the auto actuate process
209 : :
210 : : // first call for from_constructor and !after_geom_changes attributes
211 : 2274 : CubitBoolean done = CUBIT_FALSE;
212 : 2274 : CubitStatus did_something = CUBIT_FAILURE;
213 : :
214 [ + - ]: 2274 : while (done == CUBIT_FALSE) {
215 : 2274 : done = CUBIT_TRUE;
216 [ + - ][ + - ]: 4298 : for(std::vector<CubitAttrib*>::iterator iter = unactuatedCAs.begin(); iter != unactuatedCAs.end();)
[ + - ][ + + ]
217 : : {
218 [ + - ]: 2024 : CubitAttrib *attrib = *iter;
219 [ - + ]: 2024 : if( attrib == 0 )
220 : : {
221 [ # # ]: 0 : ++iter;
222 : 0 : continue;
223 : : }
224 : :
225 : : // check the auto actuate flag for this CA; since this function
226 : : // is only called from the auto actuating process, we don't need
227 : : // to check whether the user requested that this attribute be actuated
228 [ + - ][ + + ]: 6072 : if (attrib->auto_actuate_flag() == CUBIT_TRUE &&
[ + - ]
229 [ + - ][ + - ]: 5060 : (!from_constructor || attrib->actuate_in_constructor()) &&
[ + - ][ + + ]
230 [ + - ][ + - ]: 1012 : (after_geom_changes || !attrib->actuate_after_geom_changes()))
231 : : {
232 : :
233 : : // if the attribute has already actuated, but is still in our list,
234 : : // count it as doing something
235 [ - + ]: 2024 : if ( /*attrib->has_actuated() || */
236 [ + - ]: 2024 : attrib->actuate() == CUBIT_SUCCESS) {
237 [ # # ][ # # ]: 0 : PRINT_DEBUG_90("Actuated a CADA of type %s\n",
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
238 [ # # ]: 0 : attrib->att_internal_name());
239 : 0 : did_something = CUBIT_SUCCESS;
240 : 0 : done = CUBIT_FALSE;
241 [ # # ]: 0 : iter = unactuatedCAs.erase(iter);
242 : : }
243 : : else
244 : : {
245 [ + - ]: 2024 : ++iter;
246 : : }
247 : : }
248 : : else
249 : : {
250 [ # # ]: 0 : ++iter;
251 : : }
252 : : }
253 : :
254 [ + - ]: 2274 : if (done == CUBIT_TRUE) break;
255 : :
256 : : // if we did something in the previous loop, some of our CADAs might
257 : : // now have owners; check and see
258 [ # # ][ # # ]: 0 : for (std::vector<CADeferredAttrib*>::iterator iter = allCADeferredAttribs.begin();
[ # # ][ # # ]
259 [ # # ]: 0 : iter != allCADeferredAttribs.end(); ++iter)
260 : : {
261 [ # # ]: 0 : CADeferredAttrib *cada = *iter;
262 [ # # ][ # # ]: 0 : if (cada->assign_to_owner() == CUBIT_SUCCESS) {
263 [ # # ][ # # ]: 0 : PRINT_DEBUG_90("Assigned a CADA to a new owner in CADA::cleanup_cadas\n");
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
264 : 0 : did_something = CUBIT_SUCCESS;
265 : 0 : done = CUBIT_FALSE;
266 : : }
267 : : }
268 : : }
269 : :
270 : : // if there wasn't anthing to do in the first place, we didn't
271 : : // really fail
272 [ + - ][ + + ]: 2274 : if (did_something == CUBIT_FAILURE && unactuatedCAs.size() == 0)
[ + + ]
273 : 2230 : did_something = CUBIT_SUCCESS;
274 : :
275 : 2274 : return did_something;
276 : : }
277 : :
278 : 0 : CubitStatus CADeferredAttrib::owner_created(RefEntity *new_owner, const int uid)
279 : : {
280 : : // for a newly created ref entity, assigns any CADA with the same uid to the
281 : : // new entity
282 : :
283 : : // get any CADAs with the same uid
284 [ # # ]: 0 : std::vector<CADeferredAttrib*> attrib_list;
285 [ # # ]: 0 : get_deferred_attribs(uid, attrib_list);
286 : :
287 : : // now assign them to the owner
288 [ # # ][ # # ]: 0 : for (std::vector<CADeferredAttrib*>::iterator iter = attrib_list.begin();
[ # # ][ # # ]
289 [ # # ]: 0 : iter != attrib_list.end(); ++iter)
290 : : {
291 [ # # ][ # # ]: 0 : (*iter)->assign_to_owner(new_owner);
[ # # ]
292 : : }
293 : :
294 [ # # ][ # # ]: 0 : if (attrib_list.size() > 0) return CUBIT_SUCCESS;
295 [ # # ]: 0 : else return CUBIT_FAILURE;
296 : : }
297 : : /*
298 : : CubitBoolean CADeferredAttrib::is_match(CubitSimpleAttrib *csa_ptr,
299 : : const int uid)
300 : : {
301 : : //- returns true if the simple attribute is deferred type and matches
302 : : //- uid
303 : : assert(csa_ptr && uid > 0);
304 : : csa_ptr.string_data_list()->reset();
305 : : csa_ptr.string_data_list()->step();
306 : : csa_ptr.int_data_list()->reset();
307 : : if (!strcmp(csa_ptr.string_data_list()->get()->c_str(),
308 : : CGMApp::instance()->attrib_manager()->att_internal_name(CA_DEFERRED_ATTRIB)) &&
309 : : *csa_ptr.int_data_list()->get() == uid)
310 : : return CUBIT_TRUE;
311 : : else
312 : : return CUBIT_FALSE;
313 : : }
314 : : */
315 : :
316 : :
317 : 0 : CubitSimpleAttrib CADeferredAttrib::csa_from_dcsa(const CubitSimpleAttrib &csa_ptr,
318 : : const int uid)
319 : : {
320 : :
321 : : //- given a deferred csa, convert it to a normal csa by removing
322 : : //- first type string and first int; if first int doesn't match
323 : : //- uid passed in, NULL is returned
324 [ # # ][ # # ]: 0 : if (csa_ptr.string_data_list()[0] != CGMApp::instance()->attrib_manager()->att_internal_name(CA_DEFERRED_ATTRIB))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
325 : : // csa isn't deferred type - return
326 [ # # ]: 0 : return CubitSimpleAttrib();
327 : :
328 [ # # ][ # # ]: 0 : if (uid != 0 && csa_ptr.int_data_list()[0] != uid)
[ # # ][ # # ]
[ # # ]
329 : : // csa uid doesn't match - return
330 [ # # ]: 0 : return CubitSimpleAttrib();
331 : :
332 [ # # ]: 0 : CubitSimpleAttrib c = csa_ptr;
333 [ # # ][ # # ]: 0 : c.string_data_list().erase(c.string_data_list().begin());
[ # # ][ # # ]
334 [ # # ][ # # ]: 0 : c.int_data_list().erase(c.int_data_list().begin());
[ # # ][ # # ]
335 : :
336 : : // else we have a match - build new csa
337 [ # # ][ # # ]: 0 : return c;
338 : : }
339 : :
340 : 5016 : bool CADeferredAttrib::add_unactuated_ca(CubitAttrib *ca_ptr)
341 : : {
342 [ + - ][ + - ]: 5016 : std::vector<CubitAttrib*>::iterator iter = std::find(unactuatedCAs.begin(), unactuatedCAs.end(), ca_ptr);
[ + - ]
343 [ + - ][ + - ]: 5016 : if(iter == unactuatedCAs.end())
[ + + ]
344 : : {
345 [ + - ]: 1012 : unactuatedCAs.push_back(ca_ptr);
346 : 1012 : return true;
347 : : }
348 : 5016 : return false;
349 : : }
350 : :
351 : 223504 : bool CADeferredAttrib::remove_unactuated_ca( CubitAttrib* ca_ptr )
352 : : {
353 [ + - ][ + - ]: 223504 : std::vector<CubitAttrib*>::iterator iter = std::find(unactuatedCAs.begin(), unactuatedCAs.end(), ca_ptr);
[ + - ]
354 [ + - ][ + - ]: 223504 : if(iter != unactuatedCAs.end())
[ + + ]
355 : : {
356 [ + - ]: 1012 : *iter = NULL;
357 : 1012 : return true;
358 : : }
359 : 223504 : return false;
360 [ + - ][ + - ]: 6540 : }
|