Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1996-12-18 |
2 | // Created by: Yves FRICAUD | |
3 | // Copyright (c) 1996-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
7fd59977 | 17 | |
42cf5bc1 | 18 | #include <BRepBuilderAPI_MakeVertex.hxx> |
19 | #include <gp_Pnt.hxx> | |
20 | #include <Standard.hxx> | |
21 | #include <Standard_ConstructionError.hxx> | |
22 | #include <Standard_GUID.hxx> | |
23 | #include <Standard_NoMoreObject.hxx> | |
24 | #include <Standard_NoSuchObject.hxx> | |
25 | #include <Standard_NullObject.hxx> | |
26 | #include <Standard_Type.hxx> | |
27 | #include <TDF_Attribute.hxx> | |
28 | #include <TDF_AttributeDelta.hxx> | |
29 | #include <TDF_AttributeIterator.hxx> | |
7fd59977 | 30 | #include <TDF_Data.hxx> |
42cf5bc1 | 31 | #include <TDF_DataSet.hxx> |
7fd59977 | 32 | #include <TDF_DeltaOnAddition.hxx> |
42cf5bc1 | 33 | #include <TDF_DeltaOnModification.hxx> |
34 | #include <TDF_DeltaOnRemoval.hxx> | |
35 | #include <TDF_Label.hxx> | |
36 | #include <TDF_RelocationTable.hxx> | |
37 | #include <TNaming_Builder.hxx> | |
38 | #include <TNaming_CopyShape.hxx> | |
39 | #include <TNaming_DeltaOnModification.hxx> | |
40 | #include <TNaming_DeltaOnRemoval.hxx> | |
7fd59977 | 41 | #include <TNaming_Iterator.hxx> |
42cf5bc1 | 42 | #include <TNaming_NamedShape.hxx> |
7fd59977 | 43 | #include <TNaming_NewShapeIterator.hxx> |
44 | #include <TNaming_OldShapeIterator.hxx> | |
42cf5bc1 | 45 | #include <TNaming_PtrNode.hxx> |
46 | #include <TNaming_PtrRefShape.hxx> | |
47 | #include <TNaming_RefShape.hxx> | |
7fd59977 | 48 | #include <TNaming_SameShapeIterator.hxx> |
42cf5bc1 | 49 | #include <TNaming_Tool.hxx> |
50 | #include <TNaming_UsedShapes.hxx> | |
51 | #include <TopoDS_Shape.hxx> | |
7fd59977 | 52 | #include <TopoDS_Vertex.hxx> |
53 | ||
92efcf78 | 54 | IMPLEMENT_STANDARD_RTTIEXT(TNaming_NamedShape,TDF_Attribute) |
55 | ||
7fd59977 | 56 | // Defines the nodes classes |
7fd59977 | 57 | //#define MDTV_DEB_HASL |
58 | //======================================================================= | |
59 | //function : GetID | |
60 | //purpose : | |
61 | //======================================================================= | |
7fd59977 | 62 | const Standard_GUID& TNaming_NamedShape::GetID() |
63 | { | |
64 | static Standard_GUID TNaming_NamedShapeID("c4ef4200-568f-11d1-8940-080009dc3333"); | |
65 | return TNaming_NamedShapeID; | |
66 | } | |
67 | ||
68 | //======================================================================= | |
69 | //class: TNaming_Node | |
70 | //======================================================================= | |
71 | ||
72 | class TNaming_Node { | |
73 | public: | |
74 | TNaming_Node(TNaming_PtrRefShape Old, | |
75 | TNaming_PtrRefShape New) | |
76 | : myOld(Old),myNew(New), | |
77 | myAtt(0L), | |
78 | nextSameAttribute(0L), nextSameOld(0L),nextSameNew(0L) | |
79 | {} | |
80 | ||
81 | //Label : Donne le Label | |
82 | TDF_Label Label(); | |
83 | ||
84 | // NextSameShape | |
85 | TNaming_Node* NextSameShape(TNaming_RefShape* prs); | |
86 | ||
87 | // Test si l evolution est valide dans la transaction Trans | |
88 | // ie : Trans n est pas anterieure a sa creation | |
89 | // et Trans n est pas posterieure a son BackUp | |
90 | Standard_Boolean IsValidInTrans(Standard_Integer Trans); | |
91 | ||
92 | // Memory management | |
1c35b92f | 93 | DEFINE_STANDARD_ALLOC |
7fd59977 | 94 | |
95 | TNaming_PtrRefShape myOld; | |
96 | TNaming_PtrRefShape myNew; | |
97 | TNaming_NamedShape* myAtt; | |
98 | TNaming_PtrNode nextSameAttribute; | |
99 | TNaming_PtrNode nextSameOld; | |
100 | TNaming_PtrNode nextSameNew; | |
101 | }; | |
102 | ||
103 | //======================================================================= | |
104 | //function : NextSameShape | |
105 | //purpose : | |
106 | //======================================================================= | |
107 | ||
108 | TNaming_Node* TNaming_Node::NextSameShape(TNaming_RefShape* prs) | |
109 | { | |
110 | if (myOld == prs) return nextSameOld; | |
111 | if (myNew == prs) return nextSameNew; | |
112 | return nextSameNew; | |
113 | } | |
114 | ||
115 | //======================================================================= | |
116 | //function : Label | |
117 | //purpose : | |
118 | //======================================================================= | |
119 | ||
120 | TDF_Label TNaming_Node::Label() | |
121 | { | |
122 | return myAtt->Label(); | |
123 | } | |
124 | ||
125 | //======================================================================= | |
126 | //function : IsValidInTrans | |
127 | //purpose : | |
128 | //======================================================================= | |
129 | ||
130 | Standard_Boolean TNaming_Node::IsValidInTrans(Standard_Integer Trans) | |
131 | { | |
132 | if (myAtt->Transaction() <= Trans && Trans <= myAtt->UntilTransaction()) { | |
133 | return 1; | |
134 | } | |
135 | return 0; | |
136 | } | |
137 | ||
138 | //********************************************************************** | |
139 | // Methods of TNaming_NamedShape | |
140 | //********************************************************************** | |
141 | ||
142 | //======================================================================= | |
143 | //function : TNaming_NamedShape | |
144 | //purpose : | |
145 | //======================================================================= | |
146 | ||
147 | TNaming_NamedShape::TNaming_NamedShape() | |
148 | { | |
149 | myNode = 0L; | |
150 | myVersion = 0; | |
151 | } | |
152 | ||
153 | //======================================================================= | |
154 | //function : IsEmpty | |
155 | //purpose : | |
156 | //======================================================================= | |
157 | ||
158 | Standard_Boolean TNaming_NamedShape::IsEmpty () const | |
159 | { | |
160 | TNaming_Iterator it (this); | |
161 | return !it.More(); | |
162 | } | |
163 | ||
164 | ||
165 | //======================================================================= | |
166 | //function : Get | |
167 | //purpose : | |
168 | //======================================================================= | |
169 | ||
170 | TopoDS_Shape TNaming_NamedShape::Get () const | |
171 | { | |
172 | return TNaming_Tool::GetShape (this); | |
173 | } | |
174 | ||
175 | ||
176 | ||
177 | ||
178 | //======================================================================= | |
179 | //function : RemoveNode | |
180 | //purpose : | |
181 | //======================================================================= | |
182 | ||
183 | static void RemoveNode(Standard_Boolean MapExist , | |
184 | TNaming_DataMapOfShapePtrRefShape& M, | |
185 | TNaming_Node*& N) | |
186 | { | |
187 | TNaming_RefShape* pos = N->myOld; | |
188 | if (pos != 0L) { | |
189 | if (pos->FirstUse() == N) { | |
190 | TNaming_Node* nextOld = N->nextSameOld; | |
191 | if (nextOld != 0L) | |
997cf5f2 G |
192 | pos->FirstUse(nextOld); |
193 | else { | |
194 | // le shape disparait | |
195 | if (MapExist) | |
196 | M.UnBind(pos->Shape()); | |
997cf5f2 G |
197 | N->myOld = 0L; |
198 | if(pos != N->myNew) | |
199 | { | |
200 | delete pos; | |
201 | pos = 0L; | |
202 | } | |
997cf5f2 | 203 | } |
7fd59977 | 204 | } |
205 | else { | |
206 | TNaming_Node* pdn = pos->FirstUse(); | |
207 | while (pdn != 0L) { | |
997cf5f2 G |
208 | |
209 | if (pdn->NextSameShape(pos) == N) { | |
210 | if (pdn->myOld == pos) pdn->nextSameOld = N->nextSameOld; | |
211 | else pdn->nextSameNew = N->nextSameOld; | |
212 | break; | |
213 | } | |
214 | pdn = pdn->NextSameShape(pos); | |
7fd59977 | 215 | } |
216 | } | |
217 | } | |
218 | ||
219 | TNaming_RefShape* pns = N->myNew; | |
220 | if (pns != 0L) { | |
221 | if (pns->FirstUse() == N) { | |
222 | TNaming_Node* nextNew = N->nextSameNew; | |
223 | if (nextNew != 0L) | |
997cf5f2 | 224 | pns->FirstUse(nextNew); |
7fd59977 | 225 | else |
997cf5f2 G |
226 | { |
227 | // le shape disparait | |
228 | if (MapExist) | |
229 | M.UnBind(pns->Shape()); | |
230 | ||
231 | pns->FirstUse(0L); | |
232 | delete pns; | |
233 | pns = 0L; | |
234 | ||
235 | N->myNew = 0L; | |
236 | ||
237 | } | |
7fd59977 | 238 | } |
239 | else { | |
240 | TNaming_Node* pdn = pns->FirstUse(); | |
241 | while (pdn != 0L) { | |
997cf5f2 G |
242 | if (pdn->NextSameShape(pns) == N) { |
243 | if (pdn->myOld == pns) pdn->nextSameOld = N->nextSameNew; | |
244 | else pdn->nextSameNew = N->nextSameNew; | |
245 | break; | |
246 | } | |
247 | pdn = pdn->NextSameShape(pns); | |
7fd59977 | 248 | } |
249 | } | |
250 | } | |
251 | } | |
252 | ||
253 | //======================================================================= | |
254 | //function : Clear | |
255 | //purpose : | |
256 | //======================================================================= | |
257 | ||
258 | void TNaming_NamedShape::Clear() | |
259 | { | |
260 | if (Label().IsNull()) { | |
0797d9d3 | 261 | #ifdef OCCT_DEBUG_BUILDER |
7fd59977 | 262 | cout << "attention etat fantomatique" << endl; |
263 | #endif | |
264 | return; | |
265 | } | |
266 | ||
267 | Handle(TNaming_UsedShapes) US; | |
268 | ||
269 | TNaming_DataMapOfShapePtrRefShape* M=NULL; | |
270 | ||
271 | // Recuperation de la map si celle-ci n est pas deja detruite. | |
272 | //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US); | |
273 | ||
274 | Standard_Boolean MapExist = Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US); | |
275 | if (MapExist) M = &(US->Map()); | |
276 | ||
277 | TNaming_Node* p = myNode; | |
278 | while (p != 0L) { | |
279 | RemoveNode (MapExist,*M,p); | |
280 | p = p->nextSameAttribute; | |
281 | } | |
282 | ||
283 | p = myNode; | |
284 | TNaming_Node* q; | |
285 | while (p != 0L) { | |
286 | q = p; | |
287 | p = p->nextSameAttribute; | |
997cf5f2 G |
288 | if( q !=0L) |
289 | { | |
290 | delete q; | |
291 | q = 0L; | |
292 | } | |
7fd59977 | 293 | } |
294 | ||
295 | myNode = 0L; | |
296 | } | |
297 | ||
298 | //======================================================================= | |
299 | //function : BeforeRemoval | |
300 | //purpose : | |
301 | //======================================================================= | |
302 | ||
303 | void TNaming_NamedShape::BeforeRemoval() | |
304 | { | |
305 | Clear(); | |
306 | } | |
307 | ||
308 | ||
309 | //======================================================================= | |
310 | //function : BeforeUndo | |
311 | //purpose : before application of a TDF_Delta. | |
312 | //======================================================================= | |
313 | ||
314 | Standard_Boolean TNaming_NamedShape::BeforeUndo | |
315 | (const Handle(TDF_AttributeDelta)& /*anAttDelta*/, | |
316 | const Standard_Boolean /*forceIt*/) | |
317 | { | |
318 | // if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) { | |
319 | // anAttDelta->Attribute()->BeforeRemoval(); | |
320 | // } | |
321 | return Standard_True; | |
322 | } | |
323 | ||
324 | //======================================================================= | |
325 | //function : AfterUndo | |
326 | //purpose : After application of a TDF_Delta. | |
327 | //======================================================================= | |
328 | ||
329 | Standard_Boolean TNaming_NamedShape::AfterUndo | |
330 | (const Handle(TDF_AttributeDelta)& anAttDelta, | |
331 | const Standard_Boolean /*forceIt*/) | |
332 | { | |
333 | if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) { | |
334 | Handle(TNaming_UsedShapes) US; | |
335 | ||
336 | TNaming_DataMapOfShapePtrRefShape* M=NULL; | |
337 | ||
338 | // Recuperation de la map si celle-ci n est pas deja detruite. | |
339 | //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US); | |
340 | ||
341 | Standard_Boolean MapExist = anAttDelta->Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US); | |
342 | ||
343 | if (MapExist) M = &(US->Map()); | |
344 | ||
345 | TNaming_Node* p = myNode; | |
346 | while (p != 0L) { | |
347 | RemoveNode (MapExist,*M,p); | |
348 | p = p->nextSameAttribute; | |
349 | } | |
350 | ||
351 | p = myNode; | |
352 | TNaming_Node* q; | |
353 | while (p != 0L) { | |
354 | q = p; | |
355 | p = p->nextSameAttribute; | |
997cf5f2 G |
356 | if(q != 0L) |
357 | { | |
358 | delete q; | |
359 | q = 0L; | |
360 | } | |
7fd59977 | 361 | } |
362 | ||
363 | myNode = 0L; | |
364 | } | |
365 | return Standard_True; | |
366 | } | |
367 | ||
368 | ||
369 | //======================================================================= | |
370 | //function : BackupCopy | |
371 | //purpose : | |
372 | //======================================================================= | |
373 | ||
374 | Handle(TDF_Attribute) TNaming_NamedShape::BackupCopy() const | |
375 | { | |
376 | // Remarque dans le copy il est important de reporter le noeud de l attribut | |
377 | // pour ne pas casser le chemin nextSameShape. | |
378 | ||
379 | Handle(TNaming_NamedShape) Cop = new TNaming_NamedShape(); | |
380 | Cop->myNode = myNode; | |
381 | Cop->myEvolution = myEvolution; | |
382 | Cop->myVersion = myVersion; | |
383 | ||
384 | // Mise a jour de myAtt sur les noeuds dans l attribut. | |
385 | TNaming_Node* CN = Cop->myNode; | |
386 | ||
387 | Handle(TNaming_NamedShape) A = this; | |
388 | A->myNode = 0L; | |
389 | ||
390 | while (CN != 0L) { | |
391 | CN->myAtt = Cop.operator->(); | |
392 | CN = CN->nextSameAttribute; | |
393 | } | |
394 | return Cop; | |
395 | } | |
396 | ||
397 | ||
398 | //======================================================================= | |
399 | //function : Restore | |
400 | //purpose : | |
401 | //======================================================================= | |
402 | ||
403 | void TNaming_NamedShape::Restore(const Handle(TDF_Attribute)& anAttribute) | |
404 | { | |
405 | Clear(); | |
406 | ||
407 | TNaming_NamedShape* PAtt = (TNaming_NamedShape*)anAttribute.operator->(); | |
408 | myNode = PAtt->myNode; | |
409 | myEvolution = PAtt->myEvolution; | |
410 | myVersion = PAtt->myVersion; | |
411 | ||
412 | // Mise a jour de myAtt sur les noeuds dans l attribut. | |
413 | TNaming_Node* CN = myNode; | |
414 | while (CN != 0L) { | |
415 | CN->myAtt = this; | |
416 | CN = CN->nextSameAttribute; | |
417 | } | |
418 | PAtt->myNode = 0L; //un noeud est dans un seul attribut. | |
419 | } | |
420 | ||
421 | ||
422 | //======================================================================= | |
423 | //function : DeltaOnModification | |
424 | //purpose : | |
425 | //======================================================================= | |
426 | ||
427 | Handle(TDF_DeltaOnModification) TNaming_NamedShape::DeltaOnModification | |
428 | (const Handle(TDF_Attribute)& anOldAttribute) const | |
429 | { | |
430 | ||
c5f3a425 | 431 | return new TNaming_DeltaOnModification(Handle(TNaming_NamedShape)::DownCast (anOldAttribute)); |
7fd59977 | 432 | } |
433 | ||
434 | //======================================================================= | |
435 | //function : DeltaOnModification | |
436 | //purpose : | |
437 | //======================================================================= | |
438 | ||
439 | void TNaming_NamedShape::DeltaOnModification(const Handle(TDF_DeltaOnModification)& aDelta) | |
440 | { | |
441 | aDelta->Apply(); | |
442 | } | |
443 | ||
444 | //======================================================================= | |
445 | //function : DeltaOnRemoval | |
446 | //purpose : | |
447 | //======================================================================= | |
448 | ||
449 | Handle(TDF_DeltaOnRemoval) TNaming_NamedShape::DeltaOnRemoval() const | |
450 | { | |
451 | return new TNaming_DeltaOnRemoval(this); | |
452 | } | |
453 | ||
454 | //======================================================================= | |
455 | //function : NewEmpty | |
456 | //purpose : | |
457 | //======================================================================= | |
458 | ||
459 | Handle(TDF_Attribute) TNaming_NamedShape::NewEmpty () const | |
460 | { | |
461 | return new TNaming_NamedShape(); | |
462 | } | |
463 | ||
7fd59977 | 464 | //======================================================================= |
465 | //function : Paste | |
466 | //purpose : | |
467 | //======================================================================= | |
468 | ||
469 | void TNaming_NamedShape::Paste(const Handle(TDF_Attribute)& into, | |
470 | const Handle(TDF_RelocationTable)& Tab) | |
471 | const | |
472 | { | |
473 | TDF_Label Lab = into->Label(); | |
474 | if (Lab.IsNull()) { | |
9775fa61 | 475 | throw Standard_NullObject("TNaming_NamedShape::Paste"); |
7fd59977 | 476 | } |
477 | TNaming_Builder B(Lab); | |
478 | ||
479 | TNaming_Iterator It (this); | |
480 | for ( ;It.More() ; It.Next()) { | |
481 | const TopoDS_Shape& OS = It.OldShape(); | |
482 | const TopoDS_Shape& NS = It.NewShape(); | |
9fd2d2c3 | 483 | TNaming_Evolution aStatus = It.Evolution(); |
7fd59977 | 484 | |
485 | // Modification_1 24.06.99 (szy) | |
486 | TopoDS_Shape copOS, copNS; | |
9fd2d2c3 | 487 | if(aStatus != TNaming_PRIMITIVE) |
7fd59977 | 488 | TNaming_CopyShape::CopyTool(OS, Tab->TransientTable(), copOS); |
489 | else copOS.Nullify(); | |
9fd2d2c3 | 490 | if(aStatus != TNaming_DELETE ) |
7fd59977 | 491 | TNaming_CopyShape::CopyTool(NS, Tab->TransientTable(), copNS); |
492 | else copNS.Nullify(); | |
493 | ||
9fd2d2c3 | 494 | switch (aStatus) { |
7fd59977 | 495 | case TNaming_PRIMITIVE : |
496 | { | |
497 | B.Generated(copNS); | |
498 | break; | |
499 | } | |
500 | case TNaming_GENERATED : | |
501 | { | |
502 | B.Generated(copOS, copNS); | |
503 | break; | |
504 | } | |
505 | case TNaming_MODIFY : | |
506 | { | |
507 | B.Modify(copOS, copNS); | |
508 | break; | |
509 | } | |
510 | case TNaming_DELETE : | |
511 | { | |
512 | B.Delete (copOS); | |
513 | break; | |
514 | } | |
515 | case TNaming_SELECTED : | |
516 | { | |
517 | B.Select(copNS,copOS); | |
518 | break; | |
519 | } | |
520 | ||
521 | default: | |
522 | break; | |
523 | } | |
524 | } | |
525 | } | |
526 | ||
527 | //======================================================================= | |
528 | //function : References | |
529 | //purpose : | |
530 | //======================================================================= | |
531 | ||
532 | void TNaming_NamedShape::References(const Handle(TDF_DataSet)& aDataSet) const | |
533 | { | |
534 | // Recherche des dependances. | |
535 | // Pour chaque OldShape de l attribut on ajoute au dataSet son label d origine. | |
536 | TNaming_Node* Current = myNode; | |
537 | while (Current != NULL) { | |
538 | if (Current->myOld != NULL) { | |
539 | TNaming_RefShape* prs = Current->myOld; | |
540 | TNaming_Node* pdn = prs->FirstUse(); | |
541 | ||
542 | while (pdn != NULL) { | |
543 | if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) { | |
544 | aDataSet->AddLabel(pdn->Label()); | |
545 | } | |
546 | pdn = pdn->NextSameShape(prs); | |
547 | } | |
548 | } | |
549 | Current = Current->nextSameAttribute; | |
550 | } | |
551 | } | |
552 | ||
553 | ||
554 | //======================================================================= | |
555 | //function : Add | |
556 | //purpose : | |
557 | //======================================================================= | |
558 | ||
559 | void TNaming_NamedShape::Add(TNaming_Node*& pdn ) | |
560 | { | |
561 | pdn->myAtt = this; | |
c29a9290 | 562 | if (myNode != 0L){ |
7fd59977 | 563 | pdn->nextSameAttribute = myNode; |
564 | } | |
565 | myNode = pdn; | |
566 | } | |
567 | ||
568 | //======================================================================= | |
569 | //function : Dump | |
570 | //purpose : | |
571 | //======================================================================= | |
572 | ||
573 | Standard_OStream& TNaming_NamedShape::Dump(Standard_OStream& anOS) const | |
574 | { | |
575 | return anOS; | |
576 | } | |
577 | ||
578 | //*************************************** | |
579 | // Fin Class Named_Shape. | |
580 | //*************************************** | |
581 | ||
582 | ||
583 | //********************************************************************** | |
584 | // Methods of the TNaming_Builder class | |
585 | //********************************************************************** | |
586 | ||
587 | ///======================================================================= | |
588 | //function : TNaming_Builder | |
589 | //purpose : | |
590 | //======================================================================= | |
591 | ||
592 | TNaming_Builder::TNaming_Builder (const TDF_Label& L) | |
593 | { | |
7fd59977 | 594 | // Find or Build Map; |
595 | const TDF_Label& root = L.Root(); | |
8b8bffc6 | 596 | if (!root.FindAttribute(TNaming_UsedShapes::GetID(),myShapes)) { |
597 | myShapes = new TNaming_UsedShapes(); | |
598 | root.AddAttribute (myShapes); | |
7fd59977 | 599 | } |
7fd59977 | 600 | |
601 | //Find Or Build Attribute in LIns. | |
8b8bffc6 | 602 | if (!L.FindAttribute(TNaming_NamedShape::GetID(),myAtt)) { |
603 | myAtt = new TNaming_NamedShape(); | |
604 | L.AddAttribute(myAtt); | |
7fd59977 | 605 | } |
606 | else { | |
8b8bffc6 | 607 | myAtt->Backup(); |
608 | myAtt->Clear(); | |
609 | myAtt->myVersion++; | |
7fd59977 | 610 | } |
7fd59977 | 611 | } |
612 | ||
613 | //======================================================================= | |
614 | //function : TNaming_Builder | |
615 | //purpose : | |
616 | //======================================================================= | |
617 | ||
618 | Handle(TNaming_NamedShape) TNaming_Builder::NamedShape() const | |
619 | { | |
620 | return myAtt; | |
621 | } | |
622 | ||
623 | //======================================================================= | |
624 | //function : UpdateNextSameShape | |
625 | //purpose : | |
626 | //======================================================================= | |
627 | ||
628 | static void UpdateFirstUseOrNextSameShape(TNaming_RefShape*& prs, | |
629 | TNaming_Node*& pdn) | |
630 | { | |
631 | TNaming_Node* ldn = prs->FirstUse(); | |
632 | if (ldn == 0L) { | |
633 | prs->FirstUse(pdn); | |
634 | } | |
635 | else { | |
636 | TNaming_Node* cdn = ldn; | |
637 | while (cdn != 0L) { | |
638 | ldn = cdn; | |
639 | cdn = cdn->NextSameShape(prs); | |
640 | if (ldn == cdn) { | |
9775fa61 | 641 | throw Standard_ConstructionError("UpdateFirstUseOrNextSameShape"); |
7fd59977 | 642 | break; |
643 | } | |
644 | } | |
645 | // boucle interdite et inutile. | |
646 | if (ldn != pdn) { | |
647 | if (ldn->myOld == prs) ldn->nextSameOld = pdn; | |
648 | if (ldn->myNew == prs) ldn->nextSameNew = pdn; | |
649 | } | |
650 | } | |
651 | } | |
652 | ||
653 | //======================================================================= | |
654 | //function : Generate | |
655 | //purpose : | |
656 | //======================================================================= | |
657 | ||
658 | void TNaming_Builder::Generated(const TopoDS_Shape& newShape) | |
659 | { | |
660 | if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_PRIMITIVE; | |
661 | else { | |
662 | if (myAtt->myEvolution != TNaming_PRIMITIVE) | |
9775fa61 | 663 | throw Standard_ConstructionError("TNaming_Builder : not same evolution"); |
7fd59977 | 664 | } |
665 | ||
666 | TNaming_RefShape* pos = 0L; | |
667 | TNaming_RefShape* pns; | |
668 | ||
8b8bffc6 | 669 | if (myShapes->myMap.IsBound(newShape)) { |
0797d9d3 | 670 | #ifdef OCCT_DEBUG_BUILDER |
7fd59977 | 671 | cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<endl; |
672 | #endif | |
8b8bffc6 | 673 | pns = myShapes->myMap.ChangeFind(newShape); |
674 | if (pns->FirstUse()->myAtt == myAtt.operator->()) { | |
9775fa61 | 675 | throw Standard_ConstructionError("TNaming_Builder::Generate"); |
7fd59977 | 676 | } |
677 | TNaming_Node* pdn = new TNaming_Node(pos,pns); | |
678 | myAtt->Add(pdn); | |
679 | UpdateFirstUseOrNextSameShape (pns,pdn); | |
680 | } | |
681 | else { | |
682 | pns = new TNaming_RefShape(newShape); | |
683 | TNaming_Node* pdn = new TNaming_Node(pos,pns); | |
684 | pns ->FirstUse(pdn); | |
8b8bffc6 | 685 | myShapes->myMap.Bind (newShape , pns); |
7fd59977 | 686 | myAtt->Add(pdn); |
687 | } | |
688 | } | |
689 | ||
690 | ||
691 | ||
692 | //======================================================================= | |
693 | //function : Delete | |
694 | //purpose : | |
695 | //======================================================================= | |
696 | ||
697 | void TNaming_Builder::Delete(const TopoDS_Shape& oldShape) | |
698 | { | |
699 | if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_DELETE; | |
700 | else { | |
701 | if (myAtt->myEvolution != TNaming_DELETE) | |
9775fa61 | 702 | throw Standard_ConstructionError("TNaming_Builder : not same evolution"); |
7fd59977 | 703 | } |
704 | ||
fa6fc587 | 705 | TNaming_RefShape* pns; |
7fd59977 | 706 | TNaming_RefShape* pos; |
707 | ||
8b8bffc6 | 708 | if (myShapes->myMap.IsBound(oldShape)) |
709 | pos = myShapes->myMap.ChangeFind(oldShape); | |
7fd59977 | 710 | else { |
0797d9d3 | 711 | #ifdef OCCT_DEBUG_BUILDER |
7fd59977 | 712 | cout <<"TNaming_Builder::Delete : the shape is not in the data"<<endl; |
713 | #endif | |
714 | pos = new TNaming_RefShape(oldShape); | |
8b8bffc6 | 715 | myShapes->myMap.Bind(oldShape, pos); |
7fd59977 | 716 | } |
fa6fc587 | 717 | |
718 | TopoDS_Shape nullShape; | |
719 | pns = new TNaming_RefShape(nullShape); | |
720 | myShapes->myMap.Bind(nullShape, pns); | |
721 | ||
7fd59977 | 722 | TNaming_Node* pdn = new TNaming_Node(pos,pns); |
723 | myAtt->Add(pdn); | |
724 | UpdateFirstUseOrNextSameShape (pos,pdn); | |
725 | } | |
726 | ||
727 | //======================================================================= | |
728 | //function : Generate | |
729 | //purpose : | |
730 | //======================================================================= | |
731 | ||
732 | void TNaming_Builder::Generated(const TopoDS_Shape& oldShape, | |
733 | const TopoDS_Shape& newShape) | |
734 | { | |
735 | if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_GENERATED; | |
736 | else { | |
737 | if (myAtt->myEvolution != TNaming_GENERATED) | |
9775fa61 | 738 | throw Standard_ConstructionError("TNaming_Builder : not same evolution"); |
7fd59977 | 739 | } |
740 | ||
741 | if (oldShape.IsSame(newShape)) { | |
0797d9d3 | 742 | #ifdef OCCT_DEBUG_BUILDER |
7fd59977 | 743 | cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<endl; |
744 | #endif | |
745 | return; | |
746 | } | |
747 | TNaming_RefShape* pos; | |
8b8bffc6 | 748 | if (!myShapes->myMap.IsBound(oldShape)) { |
7fd59977 | 749 | pos = new TNaming_RefShape(oldShape); |
8b8bffc6 | 750 | myShapes->myMap.Bind(oldShape,pos); |
7fd59977 | 751 | } |
752 | else | |
8b8bffc6 | 753 | pos = myShapes->myMap.ChangeFind(oldShape); |
7fd59977 | 754 | |
755 | TNaming_RefShape* pns; | |
8b8bffc6 | 756 | if (!myShapes->myMap.IsBound(newShape)) { |
7fd59977 | 757 | pns = new TNaming_RefShape(newShape); |
8b8bffc6 | 758 | myShapes->myMap.Bind(newShape,pns); |
7fd59977 | 759 | } |
760 | else | |
8b8bffc6 | 761 | pns = myShapes->myMap.ChangeFind(newShape); |
7fd59977 | 762 | |
763 | TNaming_Node* pdn = new TNaming_Node(pos,pns); | |
764 | myAtt->Add(pdn); | |
765 | UpdateFirstUseOrNextSameShape (pos,pdn); | |
766 | UpdateFirstUseOrNextSameShape (pns,pdn); | |
767 | } | |
768 | ||
769 | ||
770 | //======================================================================= | |
771 | //function : Modify | |
772 | //purpose : | |
773 | //======================================================================= | |
774 | ||
775 | void TNaming_Builder::Modify(const TopoDS_Shape& oldShape, | |
776 | const TopoDS_Shape& newShape) | |
777 | { | |
778 | if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_MODIFY; | |
779 | else { | |
780 | if (myAtt->myEvolution != TNaming_MODIFY) | |
9775fa61 | 781 | throw Standard_ConstructionError("TNaming_Builder : not same evolution"); |
7fd59977 | 782 | } |
783 | ||
784 | if (oldShape.IsSame(newShape)) { | |
0797d9d3 | 785 | #ifdef OCCT_DEBUG_BUILDER |
7fd59977 | 786 | cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl; |
787 | #endif | |
788 | return; | |
789 | } | |
790 | TNaming_RefShape* pos; | |
8b8bffc6 | 791 | if (!myShapes->myMap.IsBound(oldShape)) { |
7fd59977 | 792 | pos = new TNaming_RefShape(oldShape); |
8b8bffc6 | 793 | myShapes->myMap.Bind(oldShape,pos); |
7fd59977 | 794 | } |
795 | else | |
8b8bffc6 | 796 | pos = myShapes->myMap.ChangeFind(oldShape); |
7fd59977 | 797 | |
798 | TNaming_RefShape* pns; | |
8b8bffc6 | 799 | if (!myShapes->myMap.IsBound(newShape)) { |
7fd59977 | 800 | pns = new TNaming_RefShape(newShape); |
8b8bffc6 | 801 | myShapes->myMap.Bind(newShape,pns); |
7fd59977 | 802 | } |
803 | else | |
8b8bffc6 | 804 | pns = myShapes->myMap.ChangeFind(newShape); |
7fd59977 | 805 | |
806 | TNaming_Node* pdn = new TNaming_Node(pos,pns); | |
807 | myAtt->Add(pdn); | |
808 | UpdateFirstUseOrNextSameShape (pos,pdn); | |
809 | UpdateFirstUseOrNextSameShape (pns,pdn); | |
810 | ||
811 | } | |
812 | ||
7fd59977 | 813 | //======================================================================= |
814 | //function : Select | |
815 | //purpose : | |
816 | //======================================================================= | |
817 | void TNaming_Builder::Select (const TopoDS_Shape& S, | |
818 | const TopoDS_Shape& InS) | |
819 | { | |
820 | if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_SELECTED; | |
821 | else { | |
822 | if (myAtt->myEvolution != TNaming_SELECTED) | |
9775fa61 | 823 | throw Standard_ConstructionError("TNaming_Builder : not same evolution"); |
7fd59977 | 824 | } |
825 | ||
7dcac1df | 826 | TNaming_RefShape* pos; |
827 | if (!myShapes->myMap.IsBound(InS)) { | |
828 | pos = new TNaming_RefShape(InS); | |
829 | myShapes->myMap.Bind(InS,pos); | |
7fd59977 | 830 | } |
7dcac1df | 831 | else |
832 | pos = myShapes->myMap.ChangeFind(InS); | |
7fd59977 | 833 | |
834 | TNaming_RefShape* pns; | |
8b8bffc6 | 835 | if (!myShapes->myMap.IsBound(S)) { |
7fd59977 | 836 | pns = new TNaming_RefShape(S); |
8b8bffc6 | 837 | myShapes->myMap.Bind(S,pns); |
7fd59977 | 838 | } |
839 | else | |
8b8bffc6 | 840 | pns = myShapes->myMap.ChangeFind(S); |
7fd59977 | 841 | |
842 | TNaming_Node* pdn = new TNaming_Node(pos,pns); | |
843 | myAtt->Add(pdn); | |
844 | UpdateFirstUseOrNextSameShape (pos,pdn); | |
845 | UpdateFirstUseOrNextSameShape (pns,pdn); | |
846 | } | |
847 | ||
848 | //********************************************************************** | |
849 | //Methods of the TNaming_Iterator class | |
850 | //********************************************************************** | |
851 | ||
852 | //======================================================================= | |
853 | //function : TNaming_Iterator | |
854 | //purpose : | |
855 | //======================================================================= | |
856 | ||
857 | TNaming_Iterator::TNaming_Iterator(const Handle(TNaming_NamedShape)& Att) | |
858 | :myTrans(-1) | |
859 | { | |
860 | myNode = Att->myNode; | |
861 | } | |
862 | ||
863 | //======================================================================= | |
864 | //function : TNaming_Iterator | |
865 | //purpose : | |
866 | //======================================================================= | |
867 | ||
868 | TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab) | |
869 | :myTrans(-1) | |
870 | { | |
871 | Handle(TNaming_NamedShape) Att; | |
872 | if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Att)) { | |
873 | myNode = Att->myNode; | |
874 | } | |
875 | else { | |
876 | myNode = 0L; | |
877 | } | |
878 | } | |
879 | ||
880 | //===================================================================== | |
881 | //function : TNaming_Iterator | |
882 | //purpose : | |
883 | //======================================================================= | |
884 | ||
885 | TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab, | |
886 | const Standard_Integer Trans) | |
887 | :myTrans(Trans) | |
888 | { | |
aa00364d | 889 | Handle(TDF_Attribute) Att; |
7fd59977 | 890 | if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) { |
aa00364d | 891 | myNode = Handle(TNaming_NamedShape)::DownCast (Att)->myNode; |
7fd59977 | 892 | } |
893 | else { | |
894 | myNode = 0L; | |
0797d9d3 | 895 | #ifdef OCCT_DEBUG |
7fd59977 | 896 | cout <<"TNaming_Iterator : No Shape for this label"<<endl; |
897 | #endif | |
898 | } | |
899 | } | |
900 | ||
901 | //======================================================================= | |
902 | //function : Next | |
903 | //purpose : | |
904 | //======================================================================= | |
905 | ||
906 | void TNaming_Iterator::Next() | |
907 | { | |
908 | Standard_NoMoreObject_Raise_if(myNode == 0L, | |
909 | "TNaming_Iterator::Next"); | |
910 | myNode = myNode->nextSameAttribute; | |
911 | } | |
912 | ||
913 | //======================================================================= | |
914 | //function : OldShape | |
915 | //purpose : | |
916 | //======================================================================= | |
917 | ||
918 | const TopoDS_Shape& TNaming_Iterator::OldShape() const | |
919 | { | |
920 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
921 | "TNaming_Iterator::OldShape"); | |
922 | if (myNode->myOld == 0L) { | |
923 | static TopoDS_Shape NullShape; | |
924 | return NullShape; | |
925 | } | |
926 | return myNode->myOld->Shape(); | |
927 | } | |
928 | ||
929 | //======================================================================= | |
930 | //function : NewShape | |
931 | //purpose : | |
932 | //======================================================================= | |
933 | ||
934 | const TopoDS_Shape& TNaming_Iterator::NewShape() const | |
935 | { | |
936 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
937 | "TNaming_Iterator::NewShape"); | |
938 | if (myNode->myNew == 0L) { | |
939 | static TopoDS_Shape NullShape; | |
940 | return NullShape; | |
941 | } | |
942 | return myNode->myNew->Shape(); | |
943 | } | |
944 | ||
945 | ||
946 | //======================================================================= | |
947 | //function : IsModification | |
948 | //purpose : | |
949 | //======================================================================= | |
950 | ||
951 | Standard_Boolean TNaming_Iterator::IsModification() const | |
952 | { | |
953 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
954 | "TNaming_Iterator::IsModification"); | |
955 | return (myNode->myAtt->myEvolution == TNaming_MODIFY || | |
956 | myNode->myAtt->myEvolution == TNaming_DELETE ); | |
957 | } | |
958 | ||
959 | //======================================================================= | |
960 | //function : Evolution | |
961 | //purpose : | |
962 | //======================================================================= | |
963 | ||
964 | TNaming_Evolution TNaming_Iterator::Evolution() const | |
965 | { | |
966 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
967 | "TNaming_Iterator::IsModification"); | |
968 | return myNode->myAtt->myEvolution; | |
969 | } | |
970 | ||
971 | ||
972 | ||
973 | //********************************************************************** | |
974 | //Methods of the TNaming_NewShapeIterator class | |
975 | //********************************************************************** | |
976 | ||
977 | //======================================================================= | |
978 | //function : SelectSameShape | |
979 | //purpose : Selectionne le prochain noeud ou le shape est le meme que celui | |
980 | // de RS. Old = 0 si il doit etre new dans le noeud a chercher. | |
981 | // selection dans la transaction valide. | |
982 | // On saute aussi les noeud ou OS = NS; | |
983 | //======================================================================= | |
984 | ||
985 | static void SelectSameShape (TNaming_Node*& myNode, | |
986 | Standard_Boolean Old, | |
987 | TNaming_RefShape*& RS, | |
988 | const Standard_Integer& Trans) | |
989 | { | |
990 | TNaming_Node* pdn = myNode; | |
991 | ||
992 | while (pdn != 0L) { | |
993 | Standard_Boolean Valid; | |
994 | if (Trans < 0) Valid = pdn->myAtt->IsValid(); | |
995 | else Valid = pdn->IsValidInTrans(Trans); | |
996 | ||
997 | if (Valid) | |
eafb234b | 998 | { |
7fd59977 | 999 | if (Old) { |
eafb234b | 1000 | if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) { |
1001 | break; | |
1002 | } | |
7fd59977 | 1003 | } |
1004 | else { | |
eafb234b | 1005 | if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) { |
1006 | break; | |
1007 | } | |
7fd59977 | 1008 | } |
eafb234b | 1009 | } |
7fd59977 | 1010 | pdn = pdn->NextSameShape(RS); |
1011 | } | |
1012 | myNode = pdn; | |
1013 | } | |
1014 | ||
1015 | //======================================================================= | |
1016 | //function : TNaming_NewShapeIterator | |
1017 | //purpose : | |
1018 | //======================================================================= | |
1019 | ||
1020 | TNaming_NewShapeIterator::TNaming_NewShapeIterator | |
1021 | (const TopoDS_Shape& aShape, | |
1022 | const Standard_Integer Trans, | |
1023 | const Handle(TNaming_UsedShapes)& Shapes) | |
1024 | :myTrans(Trans) | |
ddd926fe | 1025 | { |
1026 | Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), | |
1027 | "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape"); | |
1028 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); | |
7fd59977 | 1029 | myNode = RS->FirstUse(); |
ddd926fe | 1030 | Standard_Boolean Old(Standard_True); |
7fd59977 | 1031 | SelectSameShape(myNode,Old,RS,myTrans); |
1032 | } | |
1033 | ||
1034 | //======================================================================= | |
1035 | //function : TNaming_NewShapeIterator | |
1036 | //purpose : | |
1037 | //======================================================================= | |
1038 | ||
1039 | TNaming_NewShapeIterator::TNaming_NewShapeIterator | |
1040 | (const TopoDS_Shape& aShape, | |
1041 | const Standard_Integer Trans, | |
1042 | const TDF_Label& access) | |
1043 | :myTrans(Trans) | |
1044 | { | |
1045 | Handle(TNaming_UsedShapes) Shapes; | |
ddd926fe | 1046 | if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) { |
1047 | Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), | |
1048 | "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape"); | |
1049 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); | |
7fd59977 | 1050 | myNode = RS->FirstUse(); |
ddd926fe | 1051 | Standard_Boolean Old(Standard_True); |
7fd59977 | 1052 | SelectSameShape(myNode,Old,RS,myTrans); |
1053 | } | |
1054 | } | |
1055 | ||
1056 | //======================================================================= | |
1057 | //function : TNaming_NewShapeIterator | |
1058 | //purpose : | |
1059 | //======================================================================= | |
1060 | ||
1061 | TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator) | |
1062 | :myTrans(anIterator.myTrans) | |
1063 | { | |
ddd926fe | 1064 | Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L, |
1065 | "TNaming_NewShapeIterator::TNaming_NewShapeIterator"); | |
1066 | myNode = anIterator.myNode; | |
7fd59977 | 1067 | TNaming_RefShape* RS = myNode->myNew; |
1068 | if (RS == 0L) | |
1069 | myNode = 0L; // No descendant | |
1070 | else { | |
1071 | // il faut repartir de la premiere utilisation. | |
1072 | myNode = RS->FirstUse(); | |
ddd926fe | 1073 | Standard_Boolean Old(Standard_True); |
7fd59977 | 1074 | SelectSameShape(myNode,Old,RS,myTrans); |
1075 | } | |
1076 | } | |
1077 | ||
1078 | //======================================================================= | |
1079 | //function : TNaming_NewShapeIterator | |
1080 | //purpose : | |
1081 | //======================================================================= | |
1082 | ||
1083 | TNaming_NewShapeIterator::TNaming_NewShapeIterator | |
1084 | (const TopoDS_Shape& aShape, | |
1085 | const Handle(TNaming_UsedShapes)& Shapes) | |
1086 | :myTrans(-1) | |
1087 | { | |
ddd926fe | 1088 | Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), |
1089 | "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape"); | |
7fd59977 | 1090 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); |
1091 | myNode = RS->FirstUse(); | |
ddd926fe | 1092 | Standard_Boolean Old(Standard_True); |
7fd59977 | 1093 | SelectSameShape(myNode,Old,RS,myTrans); |
1094 | } | |
1095 | ||
1096 | //======================================================================= | |
1097 | //function : TNaming_NewShapeIterator | |
1098 | //purpose : | |
1099 | //======================================================================= | |
1100 | ||
1101 | TNaming_NewShapeIterator::TNaming_NewShapeIterator | |
1102 | (const TopoDS_Shape& aShape, | |
1103 | const TDF_Label& access) | |
1104 | :myTrans(-1) | |
1105 | { | |
1106 | Handle(TNaming_UsedShapes) Shapes; | |
1107 | if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) { | |
ddd926fe | 1108 | Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), |
1109 | "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape"); | |
1110 | Standard_Boolean Old(Standard_True); | |
1111 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); | |
7fd59977 | 1112 | myNode = RS->FirstUse(); |
1113 | SelectSameShape(myNode,Old,RS,myTrans); | |
1114 | } | |
1115 | } | |
1116 | ||
1117 | //======================================================================= | |
1118 | //function : TNaming_NewShapeIterator | |
1119 | //purpose : | |
1120 | //======================================================================= | |
1121 | ||
1122 | TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator) | |
1123 | :myTrans(anIterator.myTrans) | |
1124 | { | |
ddd926fe | 1125 | Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L, |
1126 | "TNaming_NewShapeIterator::TNaming_NewShapeIterator"); | |
7fd59977 | 1127 | myNode = anIterator.myNode; |
1128 | TNaming_RefShape* RS = myNode->myNew; | |
1129 | if (RS == 0L) | |
1130 | myNode = 0L; // No descendant | |
1131 | else { | |
1132 | // il faut repartir de la premiere utilisation. | |
1133 | myNode = RS->FirstUse(); | |
ddd926fe | 1134 | Standard_Boolean Old(Standard_True); |
7fd59977 | 1135 | SelectSameShape(myNode,Old,RS,myTrans); |
1136 | } | |
1137 | } | |
1138 | ||
1139 | //======================================================================= | |
1140 | //function : Next | |
1141 | //purpose : | |
1142 | //======================================================================= | |
1143 | ||
1144 | void TNaming_NewShapeIterator::Next() | |
1145 | { | |
7fd59977 | 1146 | TNaming_RefShape* RS = myNode->myOld; |
1147 | myNode = myNode->NextSameShape(RS); | |
ddd926fe | 1148 | Standard_Boolean Old(Standard_True); |
7fd59977 | 1149 | SelectSameShape(myNode,Old,RS,myTrans); |
1150 | } | |
1151 | ||
1152 | //======================================================================= | |
1153 | //function : Label | |
1154 | //purpose : | |
1155 | //======================================================================= | |
1156 | ||
1157 | TDF_Label TNaming_NewShapeIterator::Label() const | |
1158 | { | |
1159 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
1160 | "TNaming_NewShapeIterator::Label"); | |
1161 | return myNode->Label(); | |
1162 | } | |
1163 | ||
1164 | //======================================================================= | |
1165 | //function : NamedShape | |
1166 | //purpose : | |
1167 | //======================================================================= | |
1168 | ||
1169 | Handle(TNaming_NamedShape) TNaming_NewShapeIterator::NamedShape() const | |
1170 | { | |
1171 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
1172 | "TNaming_NewShapeIterator::Label"); | |
1173 | return myNode->myAtt; | |
1174 | } | |
1175 | ||
1176 | //======================================================================= | |
1177 | //function : Shape | |
1178 | //purpose : | |
1179 | //======================================================================= | |
1180 | ||
1181 | const TopoDS_Shape& TNaming_NewShapeIterator::Shape() const | |
1182 | { | |
1183 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
1184 | "TNaming_NewShapeIterator::Shape"); | |
1185 | return myNode->myNew->Shape(); | |
1186 | } | |
1187 | ||
1188 | //======================================================================= | |
1189 | //function : IsModification | |
1190 | //purpose : | |
1191 | //======================================================================= | |
1192 | ||
1193 | Standard_Boolean TNaming_NewShapeIterator::IsModification() const | |
1194 | { | |
1195 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
1196 | "TNaming_NewShapeIterator::IsModification"); | |
1197 | ||
1198 | return (myNode->myAtt->myEvolution == TNaming_MODIFY || | |
1199 | myNode->myAtt->myEvolution == TNaming_DELETE ); | |
1200 | } | |
1201 | ||
1202 | //********************************************************************** | |
1203 | //Methods of the TNaming_OldShapeIterator class | |
1204 | //********************************************************************** | |
1205 | //======================================================================= | |
1206 | //function : TNaming_OldShapeIterator | |
1207 | //purpose : | |
1208 | //======================================================================= | |
1209 | ||
1210 | TNaming_OldShapeIterator::TNaming_OldShapeIterator | |
1211 | (const TopoDS_Shape& aShape, | |
1212 | const Standard_Integer Trans, | |
1213 | const Handle(TNaming_UsedShapes)& Shapes) | |
1214 | :myTrans(Trans) | |
1215 | { | |
ddd926fe | 1216 | Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), |
1217 | "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); | |
7fd59977 | 1218 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); |
1219 | myNode = RS->FirstUse(); | |
ddd926fe | 1220 | Standard_Boolean Old(Standard_False); |
7fd59977 | 1221 | SelectSameShape(myNode,Old,RS,myTrans); |
1222 | } | |
1223 | ||
1224 | //======================================================================= | |
1225 | //function : TNaming_OldShapeIterator | |
1226 | //purpose : | |
1227 | //======================================================================= | |
1228 | ||
1229 | TNaming_OldShapeIterator::TNaming_OldShapeIterator | |
1230 | (const TopoDS_Shape& aShape, | |
1231 | const Standard_Integer Trans, | |
1232 | const TDF_Label& access) | |
1233 | :myTrans(Trans) | |
1234 | { | |
1235 | Handle(TNaming_UsedShapes) Shapes; | |
1236 | if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) { | |
ddd926fe | 1237 | Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), |
1238 | "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); | |
7fd59977 | 1239 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); |
1240 | myNode = RS->FirstUse(); | |
ddd926fe | 1241 | Standard_Boolean Old(Standard_False); |
7fd59977 | 1242 | SelectSameShape(myNode,Old,RS,myTrans); |
1243 | } | |
1244 | } | |
1245 | //======================================================================= | |
1246 | //function : TNaming_OldShapeIterator | |
1247 | //purpose : | |
1248 | //======================================================================= | |
1249 | ||
1250 | TNaming_OldShapeIterator::TNaming_OldShapeIterator | |
1251 | (const TopoDS_Shape& aShape, | |
1252 | const Handle(TNaming_UsedShapes)& Shapes) | |
1253 | :myTrans(-1) | |
1254 | { | |
ddd926fe | 1255 | Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), |
1256 | "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); | |
7fd59977 | 1257 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); |
1258 | myNode = RS->FirstUse(); | |
ddd926fe | 1259 | Standard_Boolean Old(Standard_False); |
7fd59977 | 1260 | SelectSameShape(myNode,Old,RS,myTrans); |
1261 | } | |
1262 | ||
1263 | //======================================================================= | |
1264 | //function : TNaming_OldShapeIterator | |
1265 | //purpose : | |
1266 | //======================================================================= | |
1267 | ||
1268 | TNaming_OldShapeIterator::TNaming_OldShapeIterator | |
1269 | (const TopoDS_Shape& aShape, | |
1270 | const TDF_Label& access) | |
1271 | :myTrans(-1) | |
1272 | { | |
1273 | Handle(TNaming_UsedShapes) Shapes; | |
ddd926fe | 1274 | if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) { |
1275 | Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), | |
1276 | "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); | |
7fd59977 | 1277 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); |
1278 | myNode = RS->FirstUse(); | |
ddd926fe | 1279 | Standard_Boolean Old(Standard_False); |
7fd59977 | 1280 | SelectSameShape(myNode,Old,RS,myTrans); |
1281 | } | |
1282 | } | |
1283 | ||
1284 | //======================================================================= | |
1285 | //function : TNaming_OldShapeIterator | |
1286 | //purpose : | |
1287 | //======================================================================= | |
1288 | ||
1289 | TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator) | |
1290 | :myTrans(anIterator.myTrans) | |
1291 | { | |
ddd926fe | 1292 | Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L, |
1293 | "TNaming_OldShapeIterator::TNaming_OldShapeIterator"); | |
1294 | myNode = anIterator.myNode; | |
7fd59977 | 1295 | TNaming_RefShape* RS = myNode->myNew; |
1296 | if (RS == 0L) | |
1297 | myNode = 0L; // No descendant | |
1298 | else { | |
1299 | // il faut repartir de la premiere utilisation. | |
1300 | myNode = RS->FirstUse(); | |
ddd926fe | 1301 | Standard_Boolean Old(Standard_False); |
7fd59977 | 1302 | SelectSameShape(myNode,Old,RS,myTrans); |
1303 | } | |
1304 | } | |
1305 | ||
1306 | //======================================================================= | |
1307 | //function : TNaming_OldShapeIterator | |
1308 | //purpose : | |
1309 | //======================================================================= | |
1310 | ||
1311 | TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator) | |
1312 | :myTrans(anIterator.myTrans) | |
1313 | { | |
ddd926fe | 1314 | Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L, |
1315 | "TNaming_OldShapeIterator::TNaming_OldShapeIterator"); | |
1316 | myNode = anIterator.myNode; | |
7fd59977 | 1317 | TNaming_RefShape* RS = myNode->myOld; |
1318 | if (RS == 0L) | |
1319 | myNode = 0L; // No descendant | |
1320 | else { | |
1321 | // il faut repartir de la premiere utilisation. | |
1322 | myNode = RS->FirstUse(); | |
ddd926fe | 1323 | Standard_Boolean Old(Standard_False); |
7fd59977 | 1324 | SelectSameShape(myNode,Old,RS,myTrans); |
1325 | } | |
1326 | } | |
1327 | ||
1328 | //======================================================================= | |
1329 | //function : Next | |
1330 | //purpose : | |
1331 | //======================================================================= | |
1332 | ||
1333 | void TNaming_OldShapeIterator::Next() | |
1334 | { | |
1335 | Standard_Boolean Old = Standard_False; | |
1336 | TNaming_RefShape* RS = myNode->myNew; | |
1337 | myNode = myNode->NextSameShape(RS); | |
1338 | SelectSameShape(myNode,Old,RS,myTrans); | |
1339 | } | |
1340 | ||
1341 | //======================================================================= | |
1342 | //function : Label | |
1343 | //purpose : | |
1344 | //======================================================================= | |
1345 | ||
1346 | TDF_Label TNaming_OldShapeIterator::Label() const | |
1347 | { | |
9775fa61 | 1348 | if (myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Label"); |
7fd59977 | 1349 | return myNode->Label(); |
1350 | ||
1351 | } | |
1352 | ||
1353 | //======================================================================= | |
1354 | //function : NamedShape | |
1355 | //purpose : | |
1356 | //======================================================================= | |
1357 | ||
1358 | Handle(TNaming_NamedShape) TNaming_OldShapeIterator::NamedShape() const | |
1359 | { | |
9775fa61 | 1360 | if (myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Label"); |
7fd59977 | 1361 | return myNode->myAtt; |
1362 | } | |
1363 | //======================================================================= | |
1364 | //function : Shape | |
1365 | //purpose : | |
1366 | //======================================================================= | |
1367 | ||
1368 | const TopoDS_Shape& TNaming_OldShapeIterator::Shape() const | |
1369 | { | |
9775fa61 | 1370 | if(myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Shape"); |
7fd59977 | 1371 | return myNode->myOld->Shape(); |
1372 | } | |
1373 | ||
1374 | //======================================================================= | |
1375 | //function : IsModification | |
1376 | //purpose : | |
1377 | //======================================================================= | |
1378 | ||
1379 | Standard_Boolean TNaming_OldShapeIterator::IsModification() const | |
1380 | { | |
1381 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
1382 | "TNaming_OldShapeIterator::IsModification"); | |
1383 | return (myNode->myAtt->myEvolution == TNaming_MODIFY || | |
1384 | myNode->myAtt->myEvolution == TNaming_DELETE ); | |
1385 | } | |
1386 | ||
1387 | ||
1388 | //********************************************************************** | |
1389 | //Methods of the SameShapeIterator | |
1390 | //********************************************************************** | |
1391 | ||
1392 | //======================================================================= | |
1393 | //function : | |
1394 | //purpose : | |
1395 | //======================================================================= | |
1396 | ||
1397 | TNaming_SameShapeIterator::TNaming_SameShapeIterator | |
1398 | (const TopoDS_Shape& aShape, | |
1399 | const Handle(TNaming_UsedShapes)& Shapes) | |
1400 | { | |
1401 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); | |
1402 | myNode = RS->FirstUse(); | |
1403 | myIsNew = (myNode->myNew == RS); | |
1404 | } | |
1405 | ||
1406 | ||
1407 | //======================================================================= | |
1408 | //function : TNaming_SameShapeIterator | |
1409 | //purpose : | |
1410 | //======================================================================= | |
1411 | ||
1412 | TNaming_SameShapeIterator::TNaming_SameShapeIterator | |
1413 | (const TopoDS_Shape& aShape, | |
1414 | const TDF_Label& access) | |
1415 | { | |
1416 | Handle(TNaming_UsedShapes) Shapes; | |
1417 | if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) { | |
1418 | TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape); | |
1419 | myNode = RS->FirstUse(); | |
1420 | myIsNew = (myNode->myNew == RS); | |
1421 | } | |
1422 | } | |
1423 | ||
1424 | //======================================================================= | |
1425 | //function : Next | |
1426 | //purpose : | |
1427 | //======================================================================= | |
1428 | ||
1429 | void TNaming_SameShapeIterator::Next() | |
1430 | { | |
1431 | TNaming_RefShape* prs; | |
1432 | if (myIsNew) prs = myNode->myNew; else prs = myNode->myOld; | |
1433 | ||
1434 | myNode = myNode->NextSameShape(prs); | |
1435 | if (myNode != 0L) myIsNew = (myNode->myNew == prs); | |
1436 | } | |
1437 | ||
1438 | //======================================================================= | |
1439 | //function : Label | |
1440 | //purpose : | |
1441 | //======================================================================= | |
1442 | ||
1443 | TDF_Label TNaming_SameShapeIterator::Label() const | |
1444 | { | |
1445 | Standard_NoSuchObject_Raise_if(myNode == 0L, | |
1446 | "TNaming_SameShapeIterator::Label"); | |
1447 | return myNode->Label(); | |
1448 | } | |
1449 | ||
1450 | ||
1451 | //********************************************************************** | |
1452 | //Methods of the TNaming_RefShape | |
1453 | //********************************************************************** | |
1454 | //======================================================================= | |
1455 | //function : Label | |
1456 | //purpose : | |
1457 | //======================================================================= | |
1458 | ||
1459 | TDF_Label TNaming_RefShape::Label() const | |
1460 | { | |
1461 | return myFirstUse->myAtt->Label(); | |
1462 | } | |
1463 | ||
1464 | //======================================================================= | |
1465 | //function : NamedShape | |
1466 | //purpose : | |
1467 | //======================================================================= | |
1468 | ||
1469 | Handle(TNaming_NamedShape) TNaming_RefShape::NamedShape() const | |
1470 | { | |
1471 | return myFirstUse->myAtt; | |
1472 | } | |
1473 | ||
1474 | ||
1475 | //********************************************************************** | |
1476 | //Methods of the TNaming_Tool class | |
1477 | //********************************************************************** | |
1478 | ||
1479 | //======================================================================= | |
1480 | //function : HasLabel | |
1481 | //purpose : | |
1482 | //======================================================================= | |
1483 | ||
1484 | Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label& access, | |
1485 | const TopoDS_Shape& S) | |
1486 | { | |
1487 | Handle(TNaming_UsedShapes) US; | |
1488 | if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) { | |
1489 | return (US->Map().IsBound(S)); | |
1490 | } | |
0797d9d3 | 1491 | #ifdef OCCT_DEBUG_HASL |
7fd59977 | 1492 | cout << "##==> Sub-Shape has no Label!" <<endl; |
1493 | #endif | |
1494 | return Standard_False; | |
1495 | } | |
1496 | ||
1497 | ||
1498 | //======================================================================= | |
1499 | //function : Label | |
1500 | //purpose : | |
1501 | //======================================================================= | |
1502 | ||
1503 | TDF_Label TNaming_Tool::Label(const TDF_Label& access, | |
1504 | const TopoDS_Shape& S, | |
1505 | Standard_Integer& Trans) | |
1506 | { | |
1507 | Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::Label"); | |
1508 | Handle(TNaming_UsedShapes) US; | |
1509 | access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US); | |
1510 | return TNaming_Tool::Label(US,S,Trans); | |
1511 | } | |
1512 | ||
1513 | ||
1514 | //======================================================================= | |
1515 | //function : IsValidInTrans | |
1516 | //purpose : un shape est valid tant que l attribut ou il est cree est valid | |
1517 | //======================================================================= | |
1518 | ||
1519 | Standard_Integer TNaming_Tool::ValidUntil (const TDF_Label& access, const TopoDS_Shape& S) | |
1520 | { | |
1521 | Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::ValidUntil"); | |
1522 | Handle(TNaming_UsedShapes) US; | |
1523 | access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US); | |
1524 | return TNaming_Tool::ValidUntil(S,US); | |
1525 | } | |
1526 | ||
1527 | ||
1528 | //======================================================================= | |
1529 | //function : HasLabel | |
1530 | //purpose : | |
1531 | //======================================================================= | |
1532 | ||
1533 | Standard_Boolean TNaming_Tool::HasLabel(const Handle(TNaming_UsedShapes)& Shapes, | |
1534 | const TopoDS_Shape& S) | |
1535 | { | |
1536 | return (Shapes->Map().IsBound(S)); | |
1537 | } | |
1538 | ||
1539 | ||
1540 | //======================================================================= | |
1541 | //function : Label | |
1542 | //purpose : | |
1543 | //======================================================================= | |
1544 | ||
1545 | TDF_Label TNaming_Tool::Label(const Handle(TNaming_UsedShapes)& Shapes, | |
1546 | const TopoDS_Shape& S, | |
1547 | Standard_Integer& Trans) | |
1548 | { | |
1549 | Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(Shapes,S),"TNaming_Tool::Label"); | |
1550 | TNaming_RefShape* prs = Shapes->Map().Find(S); | |
1551 | TNaming_Node* pdn = prs->FirstUse(); | |
1552 | ||
1553 | while (pdn != 0L && !(pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED)){ | |
1554 | pdn = pdn->NextSameShape(prs); | |
1555 | } | |
1556 | if (pdn == 0L) pdn = prs->FirstUse(); | |
1557 | ||
1558 | TDF_Label L = pdn->Label(); | |
1559 | Trans = pdn->myAtt->Transaction(); | |
1560 | return L; | |
1561 | } | |
1562 | //======================================================================= | |
1563 | //function : NamedShape | |
1564 | //purpose : | |
1565 | //======================================================================= | |
1566 | Handle(TNaming_NamedShape) TNaming_Tool::NamedShape(const TopoDS_Shape& S, | |
1567 | const TDF_Label& Acces) | |
1568 | { | |
1569 | Handle(TNaming_UsedShapes) US; | |
1570 | Acces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US); | |
1571 | Handle(TNaming_NamedShape) NS; | |
1572 | ||
1573 | if(!TNaming_Tool::HasLabel(US,S)) { | |
1574 | return NS; | |
1575 | } | |
1576 | ||
1577 | TNaming_RefShape* prs = US->Map().Find(S); | |
1578 | TNaming_Node* pdn = prs->FirstUse(); | |
1579 | TNaming_Node* res = 0L; | |
1580 | ||
1581 | while (pdn != 0L) { | |
1582 | if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) { | |
1583 | res = pdn; | |
1584 | if (pdn->myAtt->Evolution() != TNaming_GENERATED) { | |
1585 | // Les modifications sont privilegiees par rapport au generation. | |
1586 | // Dans le cas des shapes qui sont a la fois des modifications et des generations | |
1587 | // faces tangentes. | |
1588 | break; | |
1589 | } | |
1590 | } | |
1591 | pdn = pdn->NextSameShape(prs); | |
1592 | } | |
1593 | ||
1594 | if (res == 0L) return NS; | |
1595 | ||
1596 | // VERUE EN ATTENDANT DE REVOIR ABORT 03/11/98 | |
1597 | // Protection pour eviter de renvoyer un attribut backuped | |
1598 | TDF_Label Lab = res->Label(); | |
1599 | Lab.FindAttribute(TNaming_NamedShape::GetID(),NS); | |
1600 | return NS; | |
1601 | // return res->myAtt; | |
1602 | } | |
1603 | ||
1604 | //======================================================================= | |
1605 | //function : IsValidInTrans | |
1606 | //purpose : un shape est valid tant que l attribut ou il est cree est valid | |
1607 | //======================================================================= | |
1608 | ||
1609 | Standard_Integer TNaming_Tool::ValidUntil (const TopoDS_Shape& S, | |
1610 | const Handle(TNaming_UsedShapes)& US) | |
1611 | { | |
1612 | Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(US,S),"TNaming_Tool::ValidUntil"); | |
1613 | ||
1614 | TNaming_RefShape* RS = US->Map().ChangeFind(S); | |
1615 | Standard_Integer Cur; | |
1616 | Standard_Integer Until = 0; | |
1617 | TNaming_Node* Node = RS->FirstUse(); | |
1618 | ||
1619 | while (Node != 0L) { | |
1620 | if (Node->myNew != 0L && Node->myNew == RS) { | |
1621 | Cur = Node->myAtt->UntilTransaction(); | |
1622 | if (Cur > Until) Until = Cur; | |
1623 | } | |
1624 | Node = Node->NextSameShape(RS); | |
1625 | } | |
1626 | return Until; | |
1627 | } |