0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / IGESBasic / IGESBasic_ToolSingleParent.cxx
1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
18
19 #include <IGESBasic_SingleParent.hxx>
20 #include <IGESBasic_ToolSingleParent.hxx>
21 #include <IGESData_DirChecker.hxx>
22 #include <IGESData_Dump.hxx>
23 #include <IGESData_HArray1OfIGESEntity.hxx>
24 #include <IGESData_IGESDumper.hxx>
25 #include <IGESData_IGESEntity.hxx>
26 #include <IGESData_IGESReaderData.hxx>
27 #include <IGESData_IGESWriter.hxx>
28 #include <IGESData_ParamCursor.hxx>
29 #include <IGESData_ParamReader.hxx>
30 #include <IGESData_Status.hxx>
31 #include <Interface_Check.hxx>
32 #include <Interface_CopyTool.hxx>
33 #include <Interface_EntityIterator.hxx>
34 #include <Interface_Macros.hxx>
35 #include <Interface_ShareTool.hxx>
36 #include <Message_Messenger.hxx>
37 #include <Message_Msg.hxx>
38 #include <Standard_DomainError.hxx>
39
40 // MGE 03/08/98
41 IGESBasic_ToolSingleParent::IGESBasic_ToolSingleParent ()    {  }
42
43
44 void  IGESBasic_ToolSingleParent::ReadOwnParams
45   (const Handle(IGESBasic_SingleParent)& ent,
46    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
47 {
48   // MGE 03/08/98
49   // Building of messages
50   //========================================
51   Message_Msg Msg207("XSTEP_207");
52   //========================================
53
54   Standard_Integer tempNbParentEntities;
55   Handle(IGESData_IGESEntity) tempParent;
56   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
57   Standard_Integer nbval = 0;
58   Handle(IGESData_HArray1OfIGESEntity)  tempChildren;
59   IGESData_Status aStatus;
60
61   if(!PR.ReadInteger (PR.Current(),tempNbParentEntities)){ //szv#4:S4163:12Mar99 `st=` not needed
62     Message_Msg Msg204("XSTEP_204");
63     PR.SendFail(Msg204);
64   }
65   //st = PR.ReadInteger(PR.Current(), Msg205, nbval); //szv#4:S4163:12Mar99 moved down
66
67 //  st = PR.ReadInteger (PR.Current(),"Number of Parent entities",tempNbParentEntities);
68 //  st = PR.ReadInteger(PR.Current(), "Count of Children", nbval);
69   if (!PR.ReadInteger(PR.Current(), nbval)){
70     Message_Msg Msg205("XSTEP_205");
71     PR.SendFail(Msg205);
72     nbval = -1;
73   }
74   if (!PR.ReadEntity(IR,PR.Current(),aStatus,tempParent)){ //szv#4:S4163:12Mar99 `st=` not needed
75   //st = PR.ReadEntity(IR,PR.Current(),"ParentEntity",tempParent);
76     Message_Msg Msg206("XSTEP_206");
77     switch(aStatus) {
78     case IGESData_ReferenceError: {  
79       Message_Msg Msg216 ("IGES_216");
80       Msg206.Arg(Msg216.Value());
81       PR.SendFail(Msg206);
82       break; }
83     case IGESData_EntityError: {
84       Message_Msg Msg217 ("IGES_217");
85       Msg206.Arg(Msg217.Value());
86       PR.SendFail(Msg206);
87       break; }
88     default:{
89     }
90     }
91   }
92
93   if (nbval > 0) PR.ReadEnts (IR,PR.CurrentList(nbval),Msg207,tempChildren); //szv#4:S4163:12Mar99 `st=` not needed
94   //st = PR.ReadEnts (IR,PR.CurrentList(nbval),"Child Entities",tempChildren);
95   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
96   ent->Init(tempNbParentEntities,tempParent,tempChildren);
97 }
98
99 void  IGESBasic_ToolSingleParent::WriteOwnParams
100   (const Handle(IGESBasic_SingleParent)& ent, IGESData_IGESWriter& IW) const
101 {
102   Standard_Integer upper = ent->NbChildren();
103   IW.Send(ent->NbParentEntities());
104   IW.Send(upper);
105   IW.Send(ent->SingleParent());
106   for (Standard_Integer i = 1; i <= upper; i ++)
107     IW.Send(ent->Child(i));
108 }
109
110 void  IGESBasic_ToolSingleParent::OwnShared
111   (const Handle(IGESBasic_SingleParent)& ent, Interface_EntityIterator& iter) const
112 {
113   iter.GetOneItem(ent->SingleParent());
114   Standard_Integer upper = ent->NbChildren();
115   for (Standard_Integer i = 1; i <= upper; i ++)
116     iter.GetOneItem(ent->Child(i));
117 }
118
119 void  IGESBasic_ToolSingleParent::OwnCopy
120   (const Handle(IGESBasic_SingleParent)& another,
121    const Handle(IGESBasic_SingleParent)& ent, Interface_CopyTool& TC) const
122 {
123   Standard_Integer aNbParentEntities = another->NbParentEntities();
124   DeclareAndCast(IGESData_IGESEntity,aparent,
125                  TC.Transferred(another->SingleParent()));
126   Standard_Integer upper = another->NbChildren();
127   Handle(IGESData_HArray1OfIGESEntity)  EntArray = new
128     IGESData_HArray1OfIGESEntity(1,upper);
129   for (Standard_Integer i = 1; i <= upper; i ++)
130     {
131       DeclareAndCast
132         (IGESData_IGESEntity,myentity,TC.Transferred(another->Child(i)));
133       EntArray->SetValue(i,myentity);
134     }
135   ent->Init(aNbParentEntities,aparent,EntArray);
136 }
137
138 Standard_Boolean  IGESBasic_ToolSingleParent::OwnCorrect
139   (const Handle(IGESBasic_SingleParent)& ent) const
140 {
141   if (ent->NbParentEntities() == 1) return Standard_False;
142   Standard_Integer nb = ent->NbChildren();
143   Handle(IGESData_HArray1OfIGESEntity)  EntArray = new
144     IGESData_HArray1OfIGESEntity (1,nb);
145   for (Standard_Integer i = 1; i <= nb; i ++)
146     EntArray->SetValue(i,ent->Child(i));
147   ent->Init (1,ent->SingleParent(),EntArray);
148   return Standard_True;    // nbparents = 1
149 }
150
151 IGESData_DirChecker  IGESBasic_ToolSingleParent::DirChecker
152   (const Handle(IGESBasic_SingleParent)& /* ent */ ) const
153 {
154   IGESData_DirChecker DC(402,9);  //Form no = 9 & Type = 402
155   DC.Structure(IGESData_DefVoid);
156   DC.GraphicsIgnored();
157   DC.BlankStatusIgnored();
158   DC.HierarchyStatusIgnored();
159   return DC;
160 }
161
162 void  IGESBasic_ToolSingleParent::OwnCheck
163   (const Handle(IGESBasic_SingleParent)& ent,
164    const Interface_ShareTool& , Handle(Interface_Check)& ach) const
165 {
166    // MGE 03/08/98
167   // Building of messages
168   //========================================
169 //  Message_Msg Msg204("XSTEP_204");
170   //========================================
171   if (ent->NbParentEntities() != 1){
172     Message_Msg Msg204("XSTEP_204");
173     ach->SendFail(Msg204);
174   }
175 }
176
177 void  IGESBasic_ToolSingleParent::OwnDump
178   (const Handle(IGESBasic_SingleParent)& ent, const IGESData_IGESDumper& dumper,
179    Standard_OStream& S, const Standard_Integer level) const
180 {
181   S << "IGESBasic_SingleParent\n"
182     << "Number of ParentEntities : " << ent->NbParentEntities() << "\n"
183     << "ParentEntity : ";
184   dumper.Dump(ent->SingleParent(),S,(level <= 4) ? 0 : 1);
185   S << "\n"
186     << "Children : ";
187   IGESData_DumpEntities(S,dumper ,level,1, ent->NbChildren(),ent->Child);
188   S << std::endl;
189 }