0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / IGESSolid / IGESSolid_ToolManifoldSolid.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_HArray1OfShell.hxx>
28 #include <IGESSolid_ManifoldSolid.hxx>
29 #include <IGESSolid_Shell.hxx>
30 #include <IGESSolid_ToolManifoldSolid.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 #include <TColStd_HArray1OfInteger.hxx>
40
41 // MGE 31/07/98
42 IGESSolid_ToolManifoldSolid::IGESSolid_ToolManifoldSolid ()    {  }
43
44
45 void  IGESSolid_ToolManifoldSolid::ReadOwnParams
46   (const Handle(IGESSolid_ManifoldSolid)& ent,
47    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
48 {
49
50   // MGE 31/07/98
51   // Building of messages
52   //========================================
53   Message_Msg Msg180("XSTEP_180");
54   //========================================
55
56   Standard_Boolean abool, shellFlag; //szv#4:S4163:12Mar99 `st` moved down
57   Standard_Integer nbshells, i;
58   Handle(TColStd_HArray1OfInteger) voidShellFlags;
59   Handle(IGESData_IGESEntity) shell;
60   Handle(IGESSolid_Shell) ashell;
61   Handle(IGESSolid_HArray1OfShell) voidShells;
62   IGESData_Status aStatus;
63
64   if (!PR.ReadEntity(IR, PR.Current(), aStatus, shell)){ //szv#4:S4163:12Mar99 `st=` not needed
65     Message_Msg Msg178("XSTEP_178");
66     switch(aStatus) {
67     case IGESData_ReferenceError: {  
68       Message_Msg Msg216 ("IGES_216");
69       Msg178.Arg(Msg216.Value());
70       PR.SendFail(Msg178);
71       break; }
72     case IGESData_EntityError: {
73       Message_Msg Msg217 ("IGES_217");
74       Msg178.Arg(Msg217.Value());
75       PR.SendFail(Msg178);
76       break; }
77     default:{
78     }
79     }
80   }
81
82   PR.ReadBoolean(PR.Current(), Msg180, shellFlag); //szv#4:S4163:12Mar99 `st=` not needed
83   Standard_Boolean st = PR.ReadInteger(PR.Current(), nbshells);
84   if(!st){
85     Message_Msg Msg181("XSTEP_181");
86     PR.SendFail(Msg181);
87   }
88 /*
89   st = PR.ReadEntity(IR, PR.Current(), "Shell", shell);
90   st = PR.ReadBoolean(PR.Current(), "Shell orientation", shellFlag);
91   st = PR.ReadInteger(PR.Current(), "Number of shells", nbshells);
92 */  
93   if (st && nbshells > 0)
94     {
95       voidShells = new IGESSolid_HArray1OfShell(1, nbshells);
96       voidShellFlags = new TColStd_HArray1OfInteger(1, nbshells); voidShellFlags->Init(0);
97       for (i=1; i<=nbshells; i++)
98         {
99           //st = PR.ReadEntity(IR, PR.Current(), Msg179,
100                              //STANDARD_TYPE(IGESSolid_Shell), ashell); //szv#4:S4163:12Mar99 moved in if
101           /*
102           st = PR.ReadEntity(IR, PR.Current(), "Void shells",
103                              STANDARD_TYPE(IGESSolid_Shell), ashell);
104           */
105           if (PR.ReadEntity(IR, PR.Current(), aStatus, STANDARD_TYPE(IGESSolid_Shell), ashell))
106             voidShells->SetValue(i, ashell);
107           else {
108             Message_Msg Msg179("XSTEP_179");
109             switch(aStatus) {
110             case IGESData_ReferenceError: {  
111               Message_Msg Msg216 ("IGES_216");
112               Msg179.Arg(Msg216.Value());
113               PR.SendFail(Msg179);
114               break; }
115             case IGESData_EntityError: {
116               Message_Msg Msg217 ("IGES_217");
117               Msg179.Arg(Msg217.Value());
118               PR.SendFail(Msg179);
119               break; }
120             case IGESData_TypeError: {
121               Message_Msg Msg218 ("IGES_218");
122               Msg179.Arg(Msg218.Value());
123               PR.SendFail(Msg179);
124               break; }
125             default:{
126             }
127             }
128           }
129
130           PR.ReadBoolean(PR.Current(), Msg180, abool); //szv#4:S4163:12Mar99 `st=` not needed
131           if (abool) voidShellFlags->SetValue(i, 1);
132         }
133     }
134   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
135   ent->Init (Handle(IGESSolid_Shell)::DownCast (shell), shellFlag, voidShells, voidShellFlags);
136 }
137
138 void  IGESSolid_ToolManifoldSolid::WriteOwnParams
139   (const Handle(IGESSolid_ManifoldSolid)& ent, IGESData_IGESWriter& IW) const
140 {
141   Standard_Integer i;
142   Standard_Integer nbshells = ent->NbVoidShells();
143
144   IW.Send(ent->Shell());
145   IW.SendBoolean(ent->OrientationFlag());
146   IW.Send(nbshells);
147   for (i = 1; i <= nbshells; i ++)
148     {
149       IW.Send(ent->VoidShell(i));
150       IW.SendBoolean(ent->VoidOrientationFlag(i));
151     }
152 }
153
154 void  IGESSolid_ToolManifoldSolid::OwnShared
155   (const Handle(IGESSolid_ManifoldSolid)& ent, Interface_EntityIterator& iter) const
156 {
157   Standard_Integer i;
158   Standard_Integer nbshells = ent->NbVoidShells();
159
160   iter.GetOneItem(ent->Shell());
161   for (i = 1; i <= nbshells; i ++)    iter.GetOneItem(ent->VoidShell(i));
162 }
163
164 void  IGESSolid_ToolManifoldSolid::OwnCopy
165   (const Handle(IGESSolid_ManifoldSolid)& another,
166    const Handle(IGESSolid_ManifoldSolid)& ent, Interface_CopyTool& TC) const
167 {
168   DeclareAndCast(IGESSolid_Shell, shell, TC.Transferred(another->Shell()));
169   Standard_Boolean shellFlag = another->OrientationFlag();
170
171   Standard_Integer nbshells = another->NbVoidShells();
172   Handle(IGESSolid_HArray1OfShell) voidShells;
173   Handle(TColStd_HArray1OfInteger) voidFlags;
174   if (nbshells > 0)
175     {
176       voidShells = new IGESSolid_HArray1OfShell(1, nbshells);
177       voidFlags  = new TColStd_HArray1OfInteger(1, nbshells);
178       for (Standard_Integer i = 1; i <= nbshells; i ++)
179         {
180           DeclareAndCast(IGESSolid_Shell, voidshell,
181                          TC.Transferred(another->VoidShell(i)));
182           voidShells->SetValue(i, voidshell);
183           voidFlags->SetValue(i, (another->VoidOrientationFlag(i) ? 1 : 0));
184         }
185     }
186   ent->Init (shell, shellFlag, voidShells, voidFlags);
187 }
188
189 IGESData_DirChecker  IGESSolid_ToolManifoldSolid::DirChecker
190   (const Handle(IGESSolid_ManifoldSolid)& /* ent */ ) const
191 {
192   IGESData_DirChecker DC(186, 0);
193
194   DC.Structure  (IGESData_DefVoid);
195   DC.LineFont   (IGESData_DefVoid);
196   DC.LineWeight (IGESData_DefVoid);
197   DC.Color      (IGESData_DefAny);
198
199   return DC;
200 }
201
202 void  IGESSolid_ToolManifoldSolid::OwnCheck
203   (const Handle(IGESSolid_ManifoldSolid)& /* ent */,
204    const Interface_ShareTool& , Handle(Interface_Check)& /* ach */) const
205 {
206 }
207
208 void  IGESSolid_ToolManifoldSolid::OwnDump
209   (const Handle(IGESSolid_ManifoldSolid)& ent, const IGESData_IGESDumper& dumper,
210    const Handle(Message_Messenger)& S, const Standard_Integer level) const
211 {
212   S << "IGESSolid_ManifoldSolid" << endl;
213
214   Standard_Integer sublevel = (level <= 4) ? 0 : 1;
215   S << "Shell : ";
216   dumper.Dump(ent->Shell(),S, sublevel);
217   S << endl;
218   if (ent->OrientationFlag())
219     S << "Orientation agrees with the underlying surface" << endl;
220   else
221     S << "Orientation does not agrees with the underlying surface" << endl;
222   S << "Void shells :" << endl << "Orientation flags : ";
223   IGESData_DumpEntities(S,dumper,-level,1, ent->NbVoidShells(),ent->VoidShell);
224   S << endl;
225   if (level > 4)
226     {
227       S << "[ " << endl;
228       if (ent->NbVoidShells() > 0)
229         {
230           Standard_Integer upper = ent->NbVoidShells();
231           for (Standard_Integer i = 1; i <= upper; i ++)
232             {
233               S << "[" << i << "]:  ";
234               S << "Void shell : ";
235               dumper.Dump (ent->VoidShell(i),S, sublevel);
236               S << "  - Orientation flag : ";
237               if (ent->VoidOrientationFlag(i)) S << "True"  << endl;
238               else                             S << "False" << endl;
239             }
240         }
241       S << " ]" << endl;
242     }
243   S << endl;
244 }
245