b311480e |
1 | // Created by: CKY / Contract Toubro-Larsen |
2 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
7fd59977 |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
7fd59977 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
16 | //-------------------------------------------------------------------- |
7fd59977 |
17 | //-------------------------------------------------------------------- |
18 | |
42cf5bc1 |
19 | #include <IGESData_DirChecker.hxx> |
7fd59977 |
20 | #include <IGESData_HArray1OfIGESEntity.hxx> |
42cf5bc1 |
21 | #include <IGESData_IGESDumper.hxx> |
22 | #include <IGESData_IGESEntity.hxx> |
23 | #include <IGESData_IGESReaderData.hxx> |
24 | #include <IGESData_IGESWriter.hxx> |
25 | #include <IGESData_ParamCursor.hxx> |
26 | #include <IGESData_ParamReader.hxx> |
27 | #include <IGESSolid_BooleanTree.hxx> |
28 | #include <IGESSolid_ToolBooleanTree.hxx> |
29 | #include <Interface_Check.hxx> |
30 | #include <Interface_CopyTool.hxx> |
31 | #include <Interface_EntityIterator.hxx> |
7fd59977 |
32 | #include <Interface_Macros.hxx> |
42cf5bc1 |
33 | #include <Interface_ShareTool.hxx> |
34 | #include <Message_Messenger.hxx> |
35 | #include <Standard_DomainError.hxx> |
36 | #include <TColStd_HArray1OfInteger.hxx> |
7fd59977 |
37 | |
42cf5bc1 |
38 | #include <stdio.h> |
7fd59977 |
39 | IGESSolid_ToolBooleanTree::IGESSolid_ToolBooleanTree () { } |
40 | |
41 | |
42 | void IGESSolid_ToolBooleanTree::ReadOwnParams |
43 | (const Handle(IGESSolid_BooleanTree)& ent, |
44 | const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const |
45 | { |
46 | //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down |
47 | Standard_Integer length, intvalue; |
48 | Handle(IGESData_IGESEntity) entvalue; |
49 | Handle(TColStd_HArray1OfInteger) tempOperations; |
50 | Handle(IGESData_HArray1OfIGESEntity) tempOperands; |
51 | |
52 | Standard_Boolean st = PR.ReadInteger(PR.Current(), "Length of post-order notation", length); |
53 | if (st && length > 0) |
54 | { |
55 | tempOperations = new TColStd_HArray1OfInteger(1,length); tempOperations->Init(0); |
56 | tempOperands = new IGESData_HArray1OfIGESEntity(1,length); |
57 | |
58 | // Op. 1-2 : Operands |
59 | //st = PR.ReadEntity(IR, PR.Current(), "Operand 1", entvalue); //szv#4:S4163:12Mar99 moved in if |
60 | if (PR.ReadEntity(IR, PR.Current(), "Operand 1", entvalue)) |
61 | tempOperands->SetValue(1, entvalue); |
62 | |
63 | //st = PR.ReadEntity(IR, PR.Current(), "Operand 2", entvalue); //szv#4:S4163:12Mar99 moved in if |
64 | if (PR.ReadEntity(IR, PR.Current(), "Operand 2", entvalue)) |
65 | tempOperands->SetValue(2, entvalue); |
66 | |
67 | // Op. 3 -> length-1 : Operand or Operation |
68 | for (Standard_Integer i = 3; i < length; i++) |
69 | { |
70 | Standard_Integer curnum = PR.CurrentNumber(); |
71 | PR.ReadInteger(PR.Current(), "Operation code", intvalue); //szv#4:S4163:12Mar99 `st=` not needed |
72 | if (intvalue < 0) { |
73 | entvalue = PR.ParamEntity (IR,curnum); |
74 | if (entvalue.IsNull()) PR.AddFail("Operand : incorrect reference"); |
75 | else tempOperands->SetValue(i, entvalue); |
76 | } |
77 | else tempOperations->SetValue(i, intvalue); |
78 | } |
79 | // Last Op. : Operation |
80 | //st = PR.ReadInteger(PR.Current(), "Operation code", intvalue); //szv#4:S4163:12Mar99 moved in if |
81 | if (PR.ReadInteger(PR.Current(), "Operation code", intvalue)) |
82 | tempOperations->SetValue(length, intvalue); |
83 | } |
84 | else PR.AddFail("Length of post-order : Not Positive"); |
85 | |
86 | DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent); |
87 | ent->Init(tempOperands, tempOperations); |
88 | } |
89 | |
90 | void IGESSolid_ToolBooleanTree::WriteOwnParams |
91 | (const Handle(IGESSolid_BooleanTree)& ent, IGESData_IGESWriter& IW) const |
92 | { |
93 | Standard_Integer length = ent->Length(); |
94 | |
95 | IW.Send(length); |
96 | for (Standard_Integer i = 1; i <= length; i++) |
97 | { |
98 | if (ent->IsOperand(i)) IW.Send(ent->Operand(i), Standard_True); |
99 | else IW.Send(ent->Operation(i)); |
100 | } |
101 | } |
102 | |
103 | void IGESSolid_ToolBooleanTree::OwnShared |
104 | (const Handle(IGESSolid_BooleanTree)& ent, Interface_EntityIterator& iter) const |
105 | { |
106 | Standard_Integer length = ent->Length(); |
107 | for (Standard_Integer i = 1; i <= length; i++) |
108 | { |
109 | if (ent->IsOperand(i)) iter.GetOneItem(ent->Operand(i)); |
110 | } |
111 | } |
112 | |
113 | void IGESSolid_ToolBooleanTree::OwnCopy |
114 | (const Handle(IGESSolid_BooleanTree)& another, |
115 | const Handle(IGESSolid_BooleanTree)& ent, Interface_CopyTool& TC) const |
116 | { |
117 | Standard_Integer i; |
118 | |
119 | Standard_Integer length = another->Length(); |
120 | Handle(TColStd_HArray1OfInteger) tempOperations = |
121 | new TColStd_HArray1OfInteger(1, length); |
122 | Handle(IGESData_HArray1OfIGESEntity) tempOperands = |
123 | new IGESData_HArray1OfIGESEntity(1, length); |
124 | |
125 | for (i=1; i<= length; i++) |
126 | { |
127 | if (another->IsOperand(i)) // Operand |
128 | { |
129 | DeclareAndCast(IGESData_IGESEntity, new_ent, |
130 | TC.Transferred(another->Operand(i))); |
131 | tempOperands->SetValue(i, new_ent); |
132 | } |
133 | else // Operation |
134 | tempOperations->SetValue(i, another->Operation(i)); |
135 | } |
136 | ent->Init (tempOperands, tempOperations); |
137 | |
138 | } |
139 | |
140 | IGESData_DirChecker IGESSolid_ToolBooleanTree::DirChecker |
141 | (const Handle(IGESSolid_BooleanTree)& /*ent*/) const |
142 | { |
143 | IGESData_DirChecker DC(180, 0); |
144 | DC.Structure (IGESData_DefVoid); |
145 | DC.LineFont (IGESData_DefAny); |
146 | DC.Color (IGESData_DefAny); |
147 | |
148 | DC.UseFlagRequired (0); |
149 | DC.GraphicsIgnored (1); |
150 | return DC; |
151 | } |
152 | |
153 | void IGESSolid_ToolBooleanTree::OwnCheck |
154 | (const Handle(IGESSolid_BooleanTree)& ent, |
155 | const Interface_ShareTool& , Handle(Interface_Check)& ach) const |
156 | { |
157 | Standard_Integer length = ent->Length(); |
158 | if (length <= 2) |
159 | ach->AddFail("Length of post-order notation : Less than three"); |
160 | else { |
161 | if (!ent->IsOperand(1)) ach->AddFail("First Item is not an Operand"); |
162 | if (!ent->IsOperand(2)) ach->AddFail("Second Item is not an Operand"); |
163 | if ( ent->IsOperand(length)) ach->AddFail("Last Item is not an Operation"); |
164 | } |
165 | for (Standard_Integer i = 1; i <= length; i ++) { |
166 | if (!ent->Operand(i).IsNull()) continue; |
167 | if (ent->Operation(i) < 1 || ent->Operation(i) > 3) { |
168 | char mess[80]; |
169 | sprintf(mess,"Item no. %d Incorrect",i); |
170 | ach->AddFail(mess); |
171 | } |
172 | } |
173 | } |
174 | |
175 | void IGESSolid_ToolBooleanTree::OwnDump |
176 | (const Handle(IGESSolid_BooleanTree)& ent, const IGESData_IGESDumper& dumper, |
0ebe5b0a |
177 | Standard_OStream& S, const Standard_Integer level) const |
7fd59977 |
178 | { |
179 | Standard_Integer i, length = ent->Length(); |
180 | |
0ebe5b0a |
181 | S << "IGESSolid_Boolean Tree\n" |
182 | << "Length of the post-order notation :" << length << "\n"; |
7fd59977 |
183 | if (level > 4) |
184 | { |
0ebe5b0a |
185 | S << "Post-order notation of the Boolean Tree :\n"; |
7fd59977 |
186 | for (i = 1; i <= length; i++) |
187 | { |
188 | if (ent->IsOperand(i)) |
189 | { |
190 | S << "[" << i << "] Operand : "; |
191 | dumper.Dump (ent->Operand(i),S, 1); |
0ebe5b0a |
192 | S << "\n"; |
7fd59977 |
193 | } |
194 | else |
195 | { |
196 | Standard_Integer opcode = ent->Operation(i); |
197 | S << "[" << i << "] Operator : " << opcode; |
198 | if (opcode == 1) S << " (Union)"; |
0ebe5b0a |
199 | else if (opcode == 2) S << " (Intersection)\n"; |
200 | else if (opcode == 3) S << " (Difference)\n"; |
201 | else S << " (incorrect value)\n"; |
7fd59977 |
202 | } |
203 | } |
204 | } |
0ebe5b0a |
205 | // aSender << std::endl; |
7fd59977 |
206 | } |