b311480e |
1 | // Created on: 2007-04-17 |
2 | // Created by: Michael Sazonov |
3 | // Copyright (c) 2007-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | // The original implementation Copyright: (C) RINA S.p.A |
21 | |
22 | #include <TObj_CheckModel.hxx> |
23 | |
24 | #include <TObj_ObjectIterator.hxx> |
25 | #include <Message_Msg.hxx> |
26 | #include <Message_Status.hxx> |
27 | #include <Message_Messenger.hxx> |
28 | |
29 | IMPLEMENT_STANDARD_HANDLE(TObj_CheckModel,Message_Algorithm) |
30 | IMPLEMENT_STANDARD_RTTIEXT(TObj_CheckModel,Message_Algorithm) |
31 | |
32 | //======================================================================= |
33 | //function : Perform |
34 | //purpose : |
35 | //======================================================================= |
36 | |
37 | Standard_Boolean TObj_CheckModel::Perform() |
38 | { |
39 | ClearStatus(); |
40 | if (myModel.IsNull() || myModel->GetLabel().IsNull()) |
41 | { |
42 | SetStatus (Message_Fail1); |
43 | return Standard_False; |
44 | } |
45 | return checkReferences(); |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : checkReferences |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | Standard_Boolean TObj_CheckModel::checkReferences() |
54 | { |
55 | // iterate by all objects in the model |
56 | Handle(TObj_ObjectIterator) anIt; |
57 | for(anIt = myModel->GetObjects(); anIt->More(); anIt->Next()) |
58 | { |
59 | Handle(TObj_Object) anObj = anIt->Value(); |
60 | if (anObj.IsNull()) |
61 | { |
62 | SetStatus (Message_Alarm1, anIt->DynamicType()->Name()); |
63 | continue; |
64 | } |
65 | |
66 | // Check references |
67 | Handle(TObj_ObjectIterator) aRefIter; |
68 | for ( aRefIter = anObj->GetReferences(); aRefIter->More(); aRefIter->Next()) |
69 | { |
70 | Handle(TObj_Object) aReferred = aRefIter->Value(); |
71 | if (aReferred.IsNull() || ! aReferred->IsAlive()) |
72 | { |
73 | SetStatus (Message_Alarm2, anObj->GetName()); |
74 | continue; |
75 | } |
76 | |
77 | // check availability of corresponding back reference |
78 | Handle(TObj_ObjectIterator) aBackIter = aReferred->GetBackReferences(); |
79 | if ( aBackIter.IsNull() ) |
80 | continue; // object does not support back references |
81 | |
82 | for ( ; aBackIter->More(); aBackIter->Next() ) |
83 | if ( aBackIter->Value() == anObj ) break; |
84 | if ( aBackIter->More() ) |
85 | continue; // ok, back reference found |
86 | |
87 | if ( IsToFix() ) |
88 | { |
89 | SetStatus (Message_Warn1, anObj->GetName()); |
90 | aReferred->AddBackReference (anObj); |
91 | } |
92 | else |
93 | SetStatus (Message_Alarm4, anObj->GetName()); |
94 | } |
95 | |
96 | // Checking back references |
97 | aRefIter = anObj->GetBackReferences(); |
98 | if ( aRefIter.IsNull() ) |
99 | continue; // object does not support back references |
100 | TObj_SequenceOfObject aBadBackRefs; |
101 | for ( ; aRefIter->More(); aRefIter->Next()) |
102 | { |
103 | Handle(TObj_Object) aReferring = aRefIter->Value(); |
104 | if (aReferring.IsNull() || ! aReferring->IsAlive()) |
105 | { |
106 | SetStatus (Message_Alarm3, anObj->GetName()); |
107 | continue; |
108 | } |
109 | |
110 | Handle(TObj_ObjectIterator) aForwIter = aReferring->GetReferences(); |
111 | for ( ; aForwIter->More(); aForwIter->Next()) |
112 | if ( aForwIter->Value() == anObj ) break; |
113 | if ( aForwIter->More() ) |
114 | continue; // ok, reference found |
115 | |
116 | if ( IsToFix() ) |
117 | { |
118 | SetStatus (Message_Warn2, anObj->GetName()); |
119 | aBadBackRefs.Append (aReferring); |
120 | } |
121 | else |
122 | SetStatus (Message_Alarm5, anObj->GetName()); |
123 | } |
124 | |
125 | // remove back references to objects that are not referenced actually |
126 | for ( int i=1; i <= aBadBackRefs.Length(); i++ ) |
127 | anObj->RemoveBackReference (aBadBackRefs(i)); |
128 | } |
129 | |
130 | return ! GetStatus().IsAlarm() && ! GetStatus().IsFail(); |
131 | } |