0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / IGESSolid / IGESSolid_ToolFace.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_IGESEntity.hxx>
23 #include <IGESData_IGESReaderData.hxx>
24 #include <IGESData_IGESWriter.hxx>
25 #include <IGESData_ParamCursor.hxx>
26 #include <IGESData_ParamReader.hxx>
27 #include <IGESData_Status.hxx>
28 #include <IGESSolid_Face.hxx>
29 #include <IGESSolid_HArray1OfLoop.hxx>
30 #include <IGESSolid_Loop.hxx>
31 #include <IGESSolid_ToolFace.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
41 // MGE 03/08/98
42 //=======================================================================
43 //function : IGESSolid_ToolFace
44 //purpose  : 
45 //=======================================================================
46 IGESSolid_ToolFace::IGESSolid_ToolFace ()
47 {
48 }
49
50
51 //=======================================================================
52 //function : ReadOwnParams
53 //purpose  : 
54 //=======================================================================
55
56 void IGESSolid_ToolFace::ReadOwnParams(const Handle(IGESSolid_Face)& ent,
57                                        const Handle(IGESData_IGESReaderData)& IR,
58                                        IGESData_ParamReader& PR) const
59 {
60   // MGE 03/08/98
61   // Building of messages
62   //========================================
63   Message_Msg Msg197("XSTEP_197");
64   Message_Msg Msg198("XSTEP_198");
65   //========================================
66
67   Standard_Boolean outerLoopFlag; //szv#4:S4163:12Mar99 `st` moved down
68   Handle(IGESData_IGESEntity) anent;
69   Handle(IGESSolid_Loop) aloop;
70   Handle(IGESData_IGESEntity) tempSurface;
71   Standard_Integer nbloops;
72   Handle(IGESSolid_HArray1OfLoop) tempLoops;
73   IGESData_Status aStatus;
74
75   if (!PR.ReadEntity(IR, PR.Current(), aStatus, tempSurface)){ //szv#4:S4163:12Mar99 `st=` not needed
76     Message_Msg Msg196("XSTEP_196");
77     switch(aStatus) {
78     case IGESData_ReferenceError: {  
79       Message_Msg Msg216 ("IGES_216");
80       Msg196.Arg(Msg216.Value());
81       PR.SendFail(Msg196);
82       break; }
83     case IGESData_EntityError: {
84       Message_Msg Msg217 ("IGES_217");
85       Msg196.Arg(Msg217.Value());
86       PR.SendFail(Msg196);
87       break; }
88     default:{
89     }
90     }
91   }
92   Standard_Boolean st = PR.ReadInteger(PR.Current(), nbloops);
93   if(!st){
94     PR.SendFail(Msg197);
95   }
96 /*
97   st = PR.ReadEntity(IR, PR.Current(), "Surface", tempSurface);
98   st = PR.ReadInteger(PR.Current(), "Number of loops", nbloops);
99 */
100   if (st && nbloops > 0) tempLoops = new IGESSolid_HArray1OfLoop(1, nbloops);
101   else  PR.SendFail(Msg197);
102
103   PR.ReadBoolean(PR.Current(), Msg198, outerLoopFlag); //szv#4:S4163:12Mar99 `st=` not needed
104   //st = PR.ReadBoolean(PR.Current(), "Outer loop flag", outerLoopFlag);
105
106   if (!tempLoops.IsNull()) {
107     for (Standard_Integer i=1; i<=nbloops; i++) {
108       //st = PR.ReadEntity(IR, PR.Current(), Msg199, STANDARD_TYPE(IGESSolid_Loop), aloop); //szv#4:S4163:12Mar99 moved in if
109       //st = PR.ReadEntity(IR, PR.Current(), "Loops", STANDARD_TYPE(IGESSolid_Loop), aloop);
110       if (PR.ReadEntity(IR, PR.Current(), aStatus, STANDARD_TYPE(IGESSolid_Loop), aloop))
111         tempLoops->SetValue(i, aloop);
112       else{
113         Message_Msg Msg199("XSTEP_199");
114         switch(aStatus) {
115         case IGESData_ReferenceError: {  
116           Message_Msg Msg216 ("IGES_216");
117           Msg199.Arg(Msg216.Value());
118           PR.SendFail(Msg199);
119           break; }
120         case IGESData_EntityError: {
121           Message_Msg Msg217 ("IGES_217");
122           Msg199.Arg(Msg217.Value());
123           PR.SendFail(Msg199);
124           break; }
125         case IGESData_TypeError: {
126           Message_Msg Msg218 ("IGES_218");
127           Msg199.Arg(Msg218.Value());
128           PR.SendFail(Msg199);
129           break; }
130         default:{
131         }
132         }
133       }
134     }
135   }
136   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
137   ent->Init (tempSurface, outerLoopFlag, tempLoops);
138 }
139
140
141 //=======================================================================
142 //function : WriteOwnParams
143 //purpose  : 
144 //=======================================================================
145
146 void IGESSolid_ToolFace::WriteOwnParams(const Handle(IGESSolid_Face)& ent,
147                                         IGESData_IGESWriter& IW) const
148 {
149   Standard_Integer  upper = ent->NbLoops();
150   IW.Send(ent->Surface());
151   IW.Send(upper);
152   IW.SendBoolean(ent->HasOuterLoop());
153   for (Standard_Integer i = 1; i <= upper; i ++)
154     IW.Send(ent->Loop(i));
155 }
156
157
158 //=======================================================================
159 //function : OwnShared
160 //purpose  : 
161 //=======================================================================
162
163 void IGESSolid_ToolFace::OwnShared(const Handle(IGESSolid_Face)& ent,
164                                    Interface_EntityIterator& iter) const
165 {
166   Standard_Integer  upper = ent->NbLoops();
167   iter.GetOneItem(ent->Surface());
168   for (Standard_Integer i = 1; i <= upper; i ++)
169     iter.GetOneItem(ent->Loop(i));
170 }
171
172
173 //=======================================================================
174 //function : OwnCopy
175 //purpose  : 
176 //=======================================================================
177
178 void IGESSolid_ToolFace::OwnCopy(const Handle(IGESSolid_Face)& another,
179                                  const Handle(IGESSolid_Face)& ent,
180                                  Interface_CopyTool& TC) const
181 {
182   DeclareAndCast(IGESData_IGESEntity, tempSurface,
183                  TC.Transferred(another->Surface()));
184   Standard_Integer nbloops = another->NbLoops();
185   Standard_Boolean outerLoopFlag = another->HasOuterLoop();
186
187   Handle(IGESSolid_HArray1OfLoop) tempLoops =
188     new IGESSolid_HArray1OfLoop(1, nbloops);
189   for (Standard_Integer i=1; i<=nbloops; i++)
190     {
191       DeclareAndCast(IGESSolid_Loop, anent,
192                      TC.Transferred(another->Loop(i)));
193       tempLoops->SetValue(i, anent);
194     }
195
196   ent->Init (tempSurface, outerLoopFlag, tempLoops);
197 }
198
199
200 //=======================================================================
201 //function : DirChecker
202 //purpose  : 
203 //=======================================================================
204
205 IGESData_DirChecker IGESSolid_ToolFace::DirChecker
206   (const Handle(IGESSolid_Face)& /* ent */ ) const
207 {
208   IGESData_DirChecker DC(510, 1);
209
210   DC.Structure  (IGESData_DefVoid);
211   DC.LineFont   (IGESData_DefVoid);
212   DC.LineWeight (IGESData_DefVoid);
213   DC.Color      (IGESData_DefAny);
214
215   DC.SubordinateStatusRequired(1);
216   return DC;
217 }
218
219
220 //=======================================================================
221 //function : OwnCheck
222 //purpose  : 
223 //=======================================================================
224
225 void IGESSolid_ToolFace::OwnCheck(const Handle(IGESSolid_Face)& ent,
226                                   const Interface_ShareTool&,
227                                   Handle(Interface_Check)& ach) const
228 {
229   // MGE 03/08/98
230   // Building of messages
231   //========================================
232   //Message_Msg Msg197("XSTEP_197");
233   //========================================
234
235   if (ent->NbLoops() <= 0) {
236     Message_Msg Msg197("XSTEP_197");
237     ach->SendFail(Msg197);
238   }
239 }
240
241
242 //=======================================================================
243 //function : OwnDump
244 //purpose  : 
245 //=======================================================================
246
247 void IGESSolid_ToolFace::OwnDump(const Handle(IGESSolid_Face)& ent,
248                                  const IGESData_IGESDumper& dumper,
249                                  const Handle(Message_Messenger)& S,
250                                  const Standard_Integer level) const
251 {
252   S << "IGESSolid_Face" << endl;
253
254   Standard_Integer sublevel = (level <= 4) ? 0 : 1;
255   S << "Surface : ";
256   dumper.Dump(ent->Surface(),S, sublevel);
257   S << endl;
258   if (ent->HasOuterLoop())  S << "Outer loop is present (First one)" << endl;
259   else                      S << "Outer loop is not present" << endl;
260   S << "Loops : ";
261   IGESData_DumpEntities(S,dumper ,level,1, ent->NbLoops(),ent->Loop);
262   S << endl;
263 }
264