80d37a9d85a2c692ee5d3ecd74f06c5a02846c7c
[occt.git] / src / IGESGeom / IGESGeom_ToolTrimmedSurface.cxx
1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-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
20 //--------------------------------------------------------------------
21 //--------------------------------------------------------------------
22
23 #include <IGESGeom_ToolTrimmedSurface.ixx>
24 #include <IGESData_ParamCursor.hxx>
25 #include <IGESData_IGESEntity.hxx>
26 #include <IGESGeom_CurveOnSurface.hxx>
27 #include <IGESGeom_HArray1OfCurveOnSurface.hxx>
28 #include <IGESData_Dump.hxx>
29 #include <Interface_Macros.hxx>
30
31 // MGE 31/07/98
32 #include <Message_Msg.hxx>
33 #include <IGESData_Status.hxx>
34
35 //=======================================================================
36 //function : IGESGeom_ToolTrimmedSurface
37 //purpose  : 
38 //=======================================================================
39
40 IGESGeom_ToolTrimmedSurface::IGESGeom_ToolTrimmedSurface ()
41 {
42 }
43
44
45 //=======================================================================
46 //function : ReadOwnParams
47 //purpose  : 
48 //=======================================================================
49
50 void IGESGeom_ToolTrimmedSurface::ReadOwnParams
51   (const Handle(IGESGeom_TrimmedSurface)& ent,
52    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
53 {
54   // MGE 31/07/98
55   // Building of messages
56   //========================================
57   //========================================
58
59   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
60   Standard_Integer aFlag;
61   Standard_Integer count;
62   Handle(IGESData_IGESEntity) aSurface;
63   Handle(IGESGeom_CurveOnSurface) anOuter;
64   Handle(IGESGeom_HArray1OfCurveOnSurface) anInner;
65   IGESData_Status aStatus;
66
67   //szv#4:S4163:12Mar99 `st=` not needed
68   if (!PR.ReadEntity(IR, PR.Current(), aStatus, aSurface)){
69     Message_Msg Msg169("XSTEP_169");
70     switch(aStatus) {
71     case IGESData_ReferenceError: {  
72       Message_Msg Msg216 ("IGES_216");
73       Msg169.Arg(Msg216.Value());
74       PR.SendFail(Msg169);
75       break; }
76     case IGESData_EntityError: {
77       Message_Msg Msg217 ("IGES_217");
78       Msg169.Arg(Msg217.Value());
79       PR.SendFail(Msg169);
80       break; }
81     default:{
82     }
83     }
84   }
85   if (!PR.ReadInteger(PR.Current(), aFlag)){
86     Message_Msg Msg170("XSTEP_170");
87     PR.SendFail(Msg170);
88   }
89   //st = PR.ReadInteger(PR.Current(), Msg171, count); //szv#4:S4163:12Mar99 moved in if
90
91 /*
92   st = PR.ReadEntity(IR, PR.Current(), "Surface to be trimmed", aSurface);
93   st = PR.ReadInteger(PR.Current(), "Outer boundary type", aFlag);
94   st = PR.ReadInteger(PR.Current(), "Number of inner boundary closed curves", count);
95 */
96   if (PR.ReadInteger(PR.Current(), count)) {
97     if (count < 0){
98       Message_Msg Msg171("XSTEP_171");
99       PR.SendFail (Msg171);
100     }
101     else  if (count > 0) anInner =
102       new IGESGeom_HArray1OfCurveOnSurface(1, count);
103   }
104   else {
105     Message_Msg Msg171("XSTEP_171");
106     PR.SendFail(Msg171);
107   }
108
109   if (!PR.ReadEntity(IR, PR.Current(), aStatus,
110                 STANDARD_TYPE(IGESGeom_CurveOnSurface), anOuter,Standard_True)){
111     Message_Msg Msg172("XSTEP_172");
112     switch(aStatus) {
113     case IGESData_ReferenceError: {  
114       Message_Msg Msg216 ("IGES_216");
115       Msg172.Arg(Msg216.Value());
116       PR.SendFail(Msg172);
117       break; }
118     case IGESData_EntityError: {
119       Message_Msg Msg217 ("IGES_217");
120       Msg172.Arg(Msg217.Value());
121       PR.SendFail(Msg172);
122       break; }
123     case IGESData_TypeError: {
124       Message_Msg Msg218 ("IGES_218");
125       Msg172.Arg(Msg218.Value());
126       PR.SendFail(Msg172);
127       break; }
128     default:{
129     }
130     }
131   } //szv#4:S4163:12Mar99 `st=` not needed
132 /*  st = PR.ReadEntity(IR, PR.Current(), "Outer boundary curve",
133                      STANDARD_TYPE(IGESGeom_CurveOnSurface), anOuter,Standard_True);
134 */
135   if (! anInner.IsNull()) {
136     Standard_Integer I;
137     for (I = 1; I <= count; I++ ) {
138       Handle(IGESGeom_CurveOnSurface) tempEnt;
139       //st = PR.ReadEntity(IR, PR.Current(), Msg173,
140                            //STANDARD_TYPE(IGESGeom_CurveOnSurface), tempEnt); //szv#4:S4163:12Mar99 moved in if
141 /*      st = PR.ReadEntity(IR, PR.Current(), "Inner boundary curves",
142                          STANDARD_TYPE(IGESGeom_CurveOnSurface), tempEnt);
143 */
144       if (PR.ReadEntity(IR, PR.Current(), aStatus, STANDARD_TYPE(IGESGeom_CurveOnSurface), tempEnt))
145         anInner->SetValue(I, tempEnt);
146       else{
147         Message_Msg Msg173("XSTEP_173");
148         switch(aStatus) {
149         case IGESData_ReferenceError: {  
150           Message_Msg Msg216 ("IGES_216");
151           Msg173.Arg(Msg216.Value());
152           PR.SendFail(Msg173);
153           break; }
154         case IGESData_EntityError: {
155           Message_Msg Msg217 ("IGES_217");
156           Msg173.Arg(Msg217.Value());
157           PR.SendFail(Msg173);
158           break; }
159         case IGESData_TypeError: {
160           Message_Msg Msg218 ("IGES_218");
161           Msg173.Arg(Msg218.Value());
162           PR.SendFail(Msg173);
163           break; }
164         default:{
165         }
166         }
167       }
168     }
169   }
170
171   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
172   ent->Init(aSurface, aFlag, anOuter, anInner);
173 }
174
175
176 //=======================================================================
177 //function : WriteOwnParams
178 //purpose  : 
179 //=======================================================================
180
181 void IGESGeom_ToolTrimmedSurface::WriteOwnParams
182   (const Handle(IGESGeom_TrimmedSurface)& ent, IGESData_IGESWriter& IW)  const
183 {
184   Standard_Integer up  = ent->NbInnerContours();
185   IW.Send(ent->Surface());
186   IW.Send(ent->OuterBoundaryType());
187   IW.Send(up);
188
189   IW.Send(ent->OuterContour());
190   Standard_Integer I;
191   for (I = 1; I <= up; I ++)
192     IW.Send(ent->InnerContour(I));
193 }
194
195
196 //=======================================================================
197 //function : OwnShared
198 //purpose  : 
199 //=======================================================================
200
201 void IGESGeom_ToolTrimmedSurface::OwnShared(const Handle(IGESGeom_TrimmedSurface)& ent,
202                                             Interface_EntityIterator& iter) const
203 {
204   Standard_Integer up  = ent->NbInnerContours();
205   iter.GetOneItem(ent->Surface());
206   iter.GetOneItem(ent->OuterContour());
207   Standard_Integer I;
208   for (I = 1; I <= up; I ++)  iter.GetOneItem(ent->InnerContour(I));
209 }
210
211
212 //=======================================================================
213 //function : OwnCopy
214 //purpose  : 
215 //=======================================================================
216
217 void IGESGeom_ToolTrimmedSurface::OwnCopy(const Handle(IGESGeom_TrimmedSurface)& another,
218                                           const Handle(IGESGeom_TrimmedSurface)& ent,
219                                           Interface_CopyTool& TC) const
220 {
221   Handle(IGESGeom_HArray1OfCurveOnSurface) anInner;
222
223   DeclareAndCast(IGESData_IGESEntity, aSurface,
224                  TC.Transferred(another->Surface()));
225   Standard_Integer aFlag = another->OuterBoundaryType();
226   DeclareAndCast(IGESGeom_CurveOnSurface, anOuter,
227                  TC.Transferred(another->OuterContour()));
228   Standard_Integer count = another->NbInnerContours();
229
230   if (count > 0) {
231     anInner = new IGESGeom_HArray1OfCurveOnSurface(1, count);
232     Standard_Integer I;
233     for (I = 1; I <= count; I++) {
234       DeclareAndCast(IGESGeom_CurveOnSurface, temp,
235                      TC.Transferred(another->InnerContour(I)));
236       anInner->SetValue(I, temp);
237     }
238   }
239
240   ent->Init(aSurface, aFlag, anOuter, anInner);
241 }
242
243
244 //=======================================================================
245 //function : DirChecker
246 //purpose  : 
247 //=======================================================================
248
249 IGESData_DirChecker IGESGeom_ToolTrimmedSurface::DirChecker
250   (const Handle(IGESGeom_TrimmedSurface)& /* ent */ )   const
251 {
252   IGESData_DirChecker DC(144, 0);
253   DC.Structure(IGESData_DefVoid);
254   DC.LineFont(IGESData_DefAny);
255 //  DC.LineWeight(IGESData_DefValue);
256   DC.Color(IGESData_DefAny);
257   DC.UseFlagRequired (0);
258   DC.HierarchyStatusIgnored();
259
260   return DC;
261 }
262
263
264 //=======================================================================
265 //function : OwnCheck
266 //purpose  : 
267 //=======================================================================
268
269 void IGESGeom_ToolTrimmedSurface::OwnCheck(const Handle(IGESGeom_TrimmedSurface)& ent,
270                                            const Interface_ShareTool&,
271                                            Handle(Interface_Check)& ach)  const
272 {
273   // MGE 31/07/98
274   // Building of messages
275   //========================================
276   //Message_Msg Msg172("XSTEP_172");
277   //========================================
278
279   if (ent->OuterBoundaryType() != 0 &&   ent->OuterBoundaryType() != 1) {
280     Message_Msg Msg172("XSTEP_172");
281     ach->SendFail(Msg172);
282   }
283 }
284
285
286 //=======================================================================
287 //function : OwnDump
288 //purpose  : 
289 //=======================================================================
290
291 void IGESGeom_ToolTrimmedSurface::OwnDump(const Handle(IGESGeom_TrimmedSurface)& ent,
292                                           const IGESData_IGESDumper& dumper,
293                                           const Handle(Message_Messenger)& S,
294                                           const Standard_Integer level)  const
295 {
296   Standard_Integer tempSubLevel = (level <= 4) ? 0 : 1;
297
298   S << "IGESGeom_TrimmedSurface" << endl;
299
300   S << "Surface to be trimmed : ";
301   dumper.Dump(ent->Surface(),S, tempSubLevel);
302   S << endl;
303   S << "Boundary type    : " << ent->OuterBoundaryType() << endl;
304   S << "Outer Boundary   : ";
305   dumper.Dump(ent->OuterContour(),S, tempSubLevel);
306   S << endl;
307   S << "Inner Boundaries : ";
308   IGESData_DumpEntities(S,dumper ,level,1, ent->NbInnerContours(),ent->InnerContour);
309   S << endl;
310 }