89223742711f2262eb733aa76a526f645560f2d0
[occt.git] / src / IGESSolid / IGESSolid_ToolShell.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 <IGESData_DirChecker.hxx>
20 #include <IGESData_Dump.hxx>
21 #include <IGESData_IGESDumper.hxx>
22 #include <IGESData_IGESReaderData.hxx>
23 #include <IGESData_IGESWriter.hxx>
24 #include <IGESData_ParamCursor.hxx>
25 #include <IGESData_ParamReader.hxx>
26 #include <IGESData_Status.hxx>
27 #include <IGESSolid.hxx>
28 #include <IGESSolid_Face.hxx>
29 #include <IGESSolid_HArray1OfFace.hxx>
30 #include <IGESSolid_Shell.hxx>
31 #include <IGESSolid_ToolShell.hxx>
32 #include <Interface_Check.hxx>
33 #include <Interface_CopyTool.hxx>
34 #include <Interface_EntityIterator.hxx>
35 #include <Interface_Macros.hxx>
36 #include <Interface_ShareTool.hxx>
37 #include <Message_Messenger.hxx>
38 #include <Message_Msg.hxx>
39 #include <Standard_DomainError.hxx>
40 #include <TColStd_HArray1OfInteger.hxx>
41
42 // MGE 03/08/98
43 //=======================================================================
44 //function : IGESSolid_ToolShell
45 //purpose  : 
46 //=======================================================================
47 IGESSolid_ToolShell::IGESSolid_ToolShell ()
48 {
49 }
50
51
52 //=======================================================================
53 //function : ReadOwnParams
54 //purpose  : 
55 //=======================================================================
56
57 void IGESSolid_ToolShell::ReadOwnParams(const Handle(IGESSolid_Shell)& ent,
58                                         const Handle(IGESData_IGESReaderData)& IR,
59                                         IGESData_ParamReader& PR) const
60 {
61
62   // MGE 03/08/98
63
64   //Standard_Boolean abool; //szv#4:S4163:12Mar99 moved down
65   Standard_Integer nbfaces=0; //szv#4:S4163:12Mar99 `i` moved in for
66   //Handle(IGESSolid_Face) aface; //szv#4:S4163:12Mar99 moved down
67   Handle(IGESSolid_HArray1OfFace) tempFaces;
68   Handle(TColStd_HArray1OfInteger) tempOrientation;
69
70   //st = PR.ReadInteger(PR.Current(), Msg200, nbfaces); //szv#4:S4163:12Mar99 moved in if
71   //st = PR.ReadInteger(PR.Current(), "Number of faces", nbfaces);
72   Standard_Boolean sb = PR.ReadInteger(PR.Current(), nbfaces);
73   if (sb && nbfaces > 0 ) {
74     Message_Msg Msg180("XSTEP_180");
75     
76     Standard_Boolean abool;
77     Handle(IGESSolid_Face) aface;
78     tempFaces = new IGESSolid_HArray1OfFace(1, nbfaces);
79     tempOrientation = new TColStd_HArray1OfInteger(1, nbfaces);
80     IGESData_Status aStatus;
81     for (Standard_Integer i=1; i<=nbfaces; i++) {
82       //st = PR.ReadEntity(IR, PR.Current(),Msg201, STANDARD_TYPE(IGESSolid_Face), aface); //szv#4:S4163:12Mar99 moved in if
83       //st = PR.ReadEntity(IR, PR.Current(), "Faces", STANDARD_TYPE(IGESSolid_Face), aface);
84       if (PR.ReadEntity(IR, PR.Current(),aStatus, STANDARD_TYPE(IGESSolid_Face), aface))
85         tempFaces->SetValue(i, aface);
86       else{
87         Message_Msg Msg201("XSTEP_201");
88         switch(aStatus) {
89         case IGESData_ReferenceError: {  
90           Message_Msg Msg216 ("IGES_216");
91           Msg201.Arg(Msg216.Value());
92           PR.SendFail(Msg201);
93           break; }
94         case IGESData_EntityError: {
95           Message_Msg Msg217 ("IGES_217");
96           Msg201.Arg(Msg217.Value());
97           PR.SendFail(Msg201);
98           break; }
99         case IGESData_TypeError: {
100           Message_Msg Msg218 ("IGES_218");
101           Msg201.Arg(Msg218.Value());
102           PR.SendFail(Msg201);
103           break; }
104         default:{
105         }
106         }
107       }
108       //st = PR.ReadBoolean(PR.Current(), Msg180, abool); //szv#4:S4163:12Mar99 moved in if
109       //st = PR.ReadBoolean(PR.Current(), "Orientation flags", abool);
110       if (PR.ReadBoolean(PR.Current(), Msg180, abool))
111         tempOrientation->SetValue(i, (abool ? 1 : 0) );
112     }
113   }
114   else {
115     Message_Msg Msg200("XSTEP_200");
116     PR.SendFail(Msg200);
117   }
118   
119   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
120   ent->Init (tempFaces, tempOrientation);
121 }
122
123
124 //=======================================================================
125 //function : WriteOwnParams
126 //purpose  : 
127 //=======================================================================
128
129 void IGESSolid_ToolShell::WriteOwnParams(const Handle(IGESSolid_Shell)& ent,
130                                          IGESData_IGESWriter& IW) const
131 {
132   Standard_Integer i, nbfaces = ent->NbFaces();
133
134   IW.Send(nbfaces);
135   for (i = 1; i <= nbfaces; i ++)
136     {
137       IW.Send(ent->Face(i));
138       IW.SendBoolean(ent->Orientation(i));
139     }
140 }
141
142
143 //=======================================================================
144 //function : OwnShared
145 //purpose  : 
146 //=======================================================================
147
148 void IGESSolid_ToolShell::OwnShared(const Handle(IGESSolid_Shell)& ent,
149                                     Interface_EntityIterator& iter) const
150 {
151   Standard_Integer nbfaces = ent->NbFaces();
152   for (Standard_Integer i = 1; i <= nbfaces; i ++)
153     iter.GetOneItem(ent->Face(i));
154 }
155
156
157 //=======================================================================
158 //function : OwnCopy
159 //purpose  : 
160 //=======================================================================
161
162 void IGESSolid_ToolShell::OwnCopy(const Handle(IGESSolid_Shell)& another,
163                                   const Handle(IGESSolid_Shell)& ent,
164                                   Interface_CopyTool& TC) const
165 {
166   Standard_Integer nbfaces = another->NbFaces();
167
168   Handle(IGESSolid_HArray1OfFace) tempFaces = new
169     IGESSolid_HArray1OfFace(1, nbfaces);
170   Handle(TColStd_HArray1OfInteger) tempOrientation = new
171     TColStd_HArray1OfInteger(1, nbfaces);
172   for (Standard_Integer i=1; i<=nbfaces; i++)
173     {
174       DeclareAndCast(IGESSolid_Face, face,
175                      TC.Transferred(another->Face(i)));
176       tempFaces->SetValue(i, face);
177       tempOrientation->SetValue(i, (another->Orientation(i) ? 1 : 0) );
178     }
179   ent->Init (tempFaces, tempOrientation);
180 }
181
182
183 //=======================================================================
184 //function : DirChecker
185 //purpose  : 
186 //=======================================================================
187
188 IGESData_DirChecker IGESSolid_ToolShell::DirChecker
189   (const Handle(IGESSolid_Shell)& /* ent */ ) const
190 {
191   IGESData_DirChecker DC(514, 1,2);
192
193   DC.Structure  (IGESData_DefVoid);
194   DC.LineFont   (IGESData_DefVoid);
195   DC.LineWeight (IGESData_DefVoid);
196   DC.Color      (IGESData_DefVoid);
197
198   DC.SubordinateStatusRequired(1);
199   return DC;
200 }
201
202
203 //=======================================================================
204 //function : OwnCheck
205 //purpose  : 
206 //=======================================================================
207
208 void IGESSolid_ToolShell::OwnCheck(const Handle(IGESSolid_Shell)& ent,
209                                    const Interface_ShareTool&,
210                                    Handle(Interface_Check)& ach) const
211 {
212   // MGE 03/08/98
213   // Building of messages
214   //========================================
215   //Message_Msg Msg200("XSTEP_200");
216   //========================================
217
218   if (ent->NbFaces() <= 0) {
219     Message_Msg Msg200("XSTEP_200");
220     ach->SendFail(Msg200);
221   }
222 }
223
224
225 //=======================================================================
226 //function : OwnDump
227 //purpose  : 
228 //=======================================================================
229
230 void IGESSolid_ToolShell::OwnDump(const Handle(IGESSolid_Shell)& ent,
231                                   const IGESData_IGESDumper& dumper,
232                                   Standard_OStream& S,
233                                   const Standard_Integer level) const
234 {
235   S << "IGESSolid_Shell\n";
236   Standard_Integer upper = ent->NbFaces();
237   Standard_Integer sublevel = (level <= 4) ? 0 : 1;
238
239   S << "Faces :\nOrientation flags : ";
240   IGESData_DumpEntities(S,dumper,-level,1, ent->NbFaces(),ent->Face);
241   S << "\n";
242   if (level > 4)
243     {
244       S << "[\n";
245       for (Standard_Integer i = 1; i <= upper; i ++)
246         {
247           S << "[" << i << "]:  "
248             << "Face : ";
249           dumper.Dump (ent->Face(i),S, sublevel);
250           S << "  - Orientation flag : ";
251           if (ent->Orientation(i)) S << "True\n";
252           else                     S << "False\n";
253         }
254     }
255   S << std::endl;
256 }