1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
19 #include <IGESData_DirChecker.hxx>
20 #include <IGESData_HArray1OfIGESEntity.hxx>
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>
32 #include <Interface_Macros.hxx>
33 #include <Interface_ShareTool.hxx>
34 #include <Message_Messenger.hxx>
35 #include <Standard_DomainError.hxx>
36 #include <TColStd_HArray1OfInteger.hxx>
39 IGESSolid_ToolBooleanTree::IGESSolid_ToolBooleanTree () { }
42 void IGESSolid_ToolBooleanTree::ReadOwnParams
43 (const Handle(IGESSolid_BooleanTree)& ent,
44 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
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;
52 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Length of post-order notation", length);
55 tempOperations = new TColStd_HArray1OfInteger(1,length); tempOperations->Init(0);
56 tempOperands = new IGESData_HArray1OfIGESEntity(1,length);
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);
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);
67 // Op. 3 -> length-1 : Operand or Operation
68 for (Standard_Integer i = 3; i < length; i++)
70 Standard_Integer curnum = PR.CurrentNumber();
71 PR.ReadInteger(PR.Current(), "Operation code", intvalue); //szv#4:S4163:12Mar99 `st=` not needed
73 entvalue = PR.ParamEntity (IR,curnum);
74 if (entvalue.IsNull()) PR.AddFail("Operand : incorrect reference");
75 else tempOperands->SetValue(i, entvalue);
77 else tempOperations->SetValue(i, intvalue);
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);
84 else PR.AddFail("Length of post-order : Not Positive");
86 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
87 ent->Init(tempOperands, tempOperations);
90 void IGESSolid_ToolBooleanTree::WriteOwnParams
91 (const Handle(IGESSolid_BooleanTree)& ent, IGESData_IGESWriter& IW) const
93 Standard_Integer length = ent->Length();
96 for (Standard_Integer i = 1; i <= length; i++)
98 if (ent->IsOperand(i)) IW.Send(ent->Operand(i), Standard_True);
99 else IW.Send(ent->Operation(i));
103 void IGESSolid_ToolBooleanTree::OwnShared
104 (const Handle(IGESSolid_BooleanTree)& ent, Interface_EntityIterator& iter) const
106 Standard_Integer length = ent->Length();
107 for (Standard_Integer i = 1; i <= length; i++)
109 if (ent->IsOperand(i)) iter.GetOneItem(ent->Operand(i));
113 void IGESSolid_ToolBooleanTree::OwnCopy
114 (const Handle(IGESSolid_BooleanTree)& another,
115 const Handle(IGESSolid_BooleanTree)& ent, Interface_CopyTool& TC) const
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);
125 for (i=1; i<= length; i++)
127 if (another->IsOperand(i)) // Operand
129 DeclareAndCast(IGESData_IGESEntity, new_ent,
130 TC.Transferred(another->Operand(i)));
131 tempOperands->SetValue(i, new_ent);
134 tempOperations->SetValue(i, another->Operation(i));
136 ent->Init (tempOperands, tempOperations);
140 IGESData_DirChecker IGESSolid_ToolBooleanTree::DirChecker
141 (const Handle(IGESSolid_BooleanTree)& /*ent*/) const
143 IGESData_DirChecker DC(180, 0);
144 DC.Structure (IGESData_DefVoid);
145 DC.LineFont (IGESData_DefAny);
146 DC.Color (IGESData_DefAny);
148 DC.UseFlagRequired (0);
149 DC.GraphicsIgnored (1);
153 void IGESSolid_ToolBooleanTree::OwnCheck
154 (const Handle(IGESSolid_BooleanTree)& ent,
155 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
157 Standard_Integer length = ent->Length();
159 ach->AddFail("Length of post-order notation : Less than three");
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");
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) {
169 sprintf(mess,"Item no. %d Incorrect",i);
175 void IGESSolid_ToolBooleanTree::OwnDump
176 (const Handle(IGESSolid_BooleanTree)& ent, const IGESData_IGESDumper& dumper,
177 Standard_OStream& S, const Standard_Integer level) const
179 Standard_Integer i, length = ent->Length();
181 S << "IGESSolid_Boolean Tree\n"
182 << "Length of the post-order notation :" << length << "\n";
185 S << "Post-order notation of the Boolean Tree :\n";
186 for (i = 1; i <= length; i++)
188 if (ent->IsOperand(i))
190 S << "[" << i << "] Operand : ";
191 dumper.Dump (ent->Operand(i),S, 1);
196 Standard_Integer opcode = ent->Operation(i);
197 S << "[" << i << "] Operator : " << opcode;
198 if (opcode == 1) S << " (Union)";
199 else if (opcode == 2) S << " (Intersection)\n";
200 else if (opcode == 3) S << " (Difference)\n";
201 else S << " (incorrect value)\n";
205 // aSender << std::endl;