0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / IGESGeom / IGESGeom_ToolPlane.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 <gp_Pnt.hxx>
20 #include <gp_XYZ.hxx>
21 #include <IGESData_DirChecker.hxx>
22 #include <IGESData_Dump.hxx>
23 #include <IGESData_IGESDumper.hxx>
24 #include <IGESData_IGESEntity.hxx>
25 #include <IGESData_IGESReaderData.hxx>
26 #include <IGESData_IGESWriter.hxx>
27 #include <IGESData_ParamCursor.hxx>
28 #include <IGESData_ParamReader.hxx>
29 #include <IGESData_Status.hxx>
30 #include <IGESGeom_Plane.hxx>
31 #include <IGESGeom_ToolPlane.hxx>
32 #include <Interface_Check.hxx>
33 #include <Interface_CopyTool.hxx>
34 #include <Interface_EntityIterator.hxx>
35 #include <Interface_Macros.hxx>
36 #include <Interface_MSG.hxx>
37 #include <Interface_ShareTool.hxx>
38 #include <Message_Messenger.hxx>
39 #include <Message_Msg.hxx>
40 #include <Standard_DomainError.hxx>
41
42 #include <stdio.h>
43 // MGE 30/07/98
44 //=======================================================================
45 //function : IGESGeom_ToolPlane
46 //purpose  : 
47 //=======================================================================
48 IGESGeom_ToolPlane::IGESGeom_ToolPlane ()
49 {
50 }
51
52
53 //=======================================================================
54 //function : ReadOwnParams
55 //purpose  : 
56 //=======================================================================
57
58 void IGESGeom_ToolPlane::ReadOwnParams(const Handle(IGESGeom_Plane)& ent,
59                                        const Handle(IGESData_IGESReaderData)& IR,
60                                        IGESData_ParamReader& PR) const
61 {
62   // MGE 30/07/98
63
64   Standard_Real A, B = 0., C = 0., D = 0., aSize = 0.;
65   Handle(IGESData_IGESEntity) aCurve;
66   gp_XYZ attach (0.,0.,0.);
67   IGESData_Status aStatus;
68   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
69
70 /*  PR.ReadReal(PR.Current(), Msg135, A); //szv#4:S4163:12Mar99 `st=` not needed
71   PR.ReadReal(PR.Current(), Msg135, B); //szv#4:S4163:12Mar99 `st=` not needed
72   PR.ReadReal(PR.Current(), Msg135, C); //szv#4:S4163:12Mar99 `st=` not needed
73   PR.ReadReal(PR.Current(), Msg135, D); //szv#4:S4163:12Mar99 `st=` not needed
74 */
75   if ((!PR.ReadReal(PR.Current(),A)) || (!PR.ReadReal(PR.Current(),B)) ||
76       (!PR.ReadReal(PR.Current(),C)) || (!PR.ReadReal(PR.Current(),D))){
77     Message_Msg Msg135("XSTEP_135");
78     PR.SendFail(Msg135);
79   }
80 /*
81   st = PR.ReadReal(PR.Current(), "Coefficient Of Plane", A);
82   st = PR.ReadReal(PR.Current(), "Coefficient Of Plane", B);
83   st = PR.ReadReal(PR.Current(), "Coefficient Of Plane", C);
84   st = PR.ReadReal(PR.Current(), "Coefficient Of Plane", D);
85 */
86   if (PR.IsParamDefined(PR.CurrentNumber())) {
87     if (!PR.ReadEntity(IR, PR.Current(), aStatus, aCurve,Standard_True)){
88       Message_Msg Msg136("XSTEP_136");
89       switch(aStatus) {
90       case IGESData_ReferenceError: {  
91         Message_Msg Msg216 ("IGES_216");
92         Msg136.Arg(Msg216.Value());
93         PR.SendFail(Msg136);
94         break; }
95       case IGESData_EntityError: {
96         Message_Msg Msg217 ("IGES_217");
97         Msg136.Arg(Msg217.Value());
98         PR.SendFail(Msg136);
99         break; }
100       default:{
101       }
102       }
103     }
104   } //szv#4:S4163:12Mar99 `st=` not needed
105     //st = PR.ReadEntity(IR, PR.Current(), "Bounding Curve", aCurve,Standard_True);
106 //  en principe exige si FormNumber != 0 ... cf OwnCheck (Load accepte)
107
108   if (PR.IsParamDefined(PR.CurrentNumber())) {
109     Message_Msg Msg139("XSTEP_139");
110    
111     PR.ReadXYZ(PR.CurrentList(1, 3), Msg139, attach); //szv#4:S4163:12Mar99 `st=` not needed
112     //st = PR.ReadXYZ(PR.CurrentList(1, 3), "Coord of DisplaySymbol", attach);
113
114     if (!PR.ReadReal(PR.Current(), aSize)){
115       Message_Msg Msg138("XSTEP_138");
116       PR.SendFail(Msg138);
117     } //szv#4:S4163:12Mar99 `st=` not needed
118     //st = PR.ReadReal(PR.Current(), "DisplaySymbol Size", aSize);
119   }// else {
120    /* for (int i = 1; i <= 4; i ++) st = PR.DefinedElseSkip();
121     PR.AddWarning("Display Symbol not defined at all");
122    */ 
123  // }
124
125   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
126   ent->Init(A, B, C, D, aCurve, attach, aSize);
127 }
128
129
130 //=======================================================================
131 //function : WriteOwnParams
132 //purpose  : 
133 //=======================================================================
134
135 void IGESGeom_ToolPlane::WriteOwnParams(const Handle(IGESGeom_Plane)& ent,
136                                         IGESData_IGESWriter& IW)  const
137 {
138   Standard_Real A,B,C,D;
139   ent->Equation(A,B,C,D);
140   IW.Send(A);
141   IW.Send(B);
142   IW.Send(C);
143   IW.Send(D);
144
145   IW.Send(ent->BoundingCurve());
146
147   IW.Send(ent->SymbolAttach().X());
148   IW.Send(ent->SymbolAttach().Y());
149   IW.Send(ent->SymbolAttach().Z());
150   IW.Send(ent->SymbolSize());
151 }
152
153
154 //=======================================================================
155 //function : OwnShared
156 //purpose  : 
157 //=======================================================================
158
159 void IGESGeom_ToolPlane::OwnShared(const Handle(IGESGeom_Plane)& ent,
160                                    Interface_EntityIterator& iter) const
161 {
162   iter.GetOneItem(ent->BoundingCurve());
163 }
164
165
166 //=======================================================================
167 //function : OwnCopy
168 //purpose  : 
169 //=======================================================================
170
171 void IGESGeom_ToolPlane::OwnCopy(const Handle(IGESGeom_Plane)& another,
172                                  const Handle(IGESGeom_Plane)& ent,
173                                  Interface_CopyTool& TC) const
174 {
175   Standard_Real A, B, C, D;
176   another->Equation(A, B, C, D);
177   gp_XYZ attach = (another->SymbolAttach()).XYZ();
178   Standard_Real aSize = another->SymbolSize();
179   DeclareAndCast(IGESData_IGESEntity,aCurve,
180                  TC.Transferred(another->BoundingCurve()));
181   ent->Init(A, B, C, D, aCurve, attach, aSize);
182   ent->SetFormNumber(another->FormNumber());
183 }
184
185
186 //=======================================================================
187 //function : DirChecker
188 //purpose  : 
189 //=======================================================================
190
191 IGESData_DirChecker IGESGeom_ToolPlane::DirChecker
192   (const Handle(IGESGeom_Plane)& ent )  const
193 {
194   IGESData_DirChecker DC(108,-1,1);
195   DC.Structure(IGESData_DefVoid);
196   if (ent->FormNumber() != 0)
197     {
198       DC.LineFont(IGESData_DefAny);
199 //      DC.LineWeight(IGESData_DefValue);
200     }
201   else
202     {
203       DC.LineFont(IGESData_DefVoid);
204       DC.LineWeight(IGESData_DefVoid);
205       DC.HierarchyStatusIgnored();
206     }
207   DC.Color(IGESData_DefAny);
208   return DC;
209 }
210
211
212 //=======================================================================
213 //function : OwnCheck
214 //purpose  : 
215 //=======================================================================
216
217 void IGESGeom_ToolPlane::OwnCheck(const Handle(IGESGeom_Plane)& ent,
218                                   const Interface_ShareTool&,
219                                   Handle(Interface_Check)& ach)  const
220 {
221   // MGE 30/07/98
222   // Building of messages
223   //========================================
224   //Message_Msg Msg71("XSTEP_71");
225   //Message_Msg Msg137("XSTEP_137");
226   //========================================
227
228   //szv#4:S4163:12Mar99 not needed
229   //Standard_Real eps = 1.E-06;  // ?? Precision
230   //Standard_Real A,B,C,D;
231   //ent->Equation(A,B,C,D);
232   if (ent->FormNumber() < -1 || ent->FormNumber() > 1) {
233     Message_Msg Msg71("XSTEP_71");
234     ach->SendFail(Msg71);
235   }
236   //szv#4:S4163:12Mar99 `!=` wrong operation on Standard_Boolean
237   Standard_Boolean unbounded1 = ent->BoundingCurve().IsNull();
238   Standard_Boolean unbounded2 = (ent->FormNumber() == 0);
239   if ( (unbounded1 && !unbounded2) || (!unbounded1 && unbounded2) ) {
240     Message_Msg Msg137("XSTEP_137");
241     ach->SendFail(Msg137);
242   }
243 // These messages are transfered in the translation procedure
244 //  if ( (A*A + B*B + C*C) < eps)    //  pas nul !
245 //    ach.SendFail("Incorrect Coefficients for the Plane");
246   if ( !ent->HasBoundingCurve()) return;
247 //  Symbol : verifie si Size defini > 0 (sinon, n a pas de signification)
248 /*  Standard_Real ec = 0.;
249   if (ent->SymbolSize() > 0.) ec = A*ent->SymbolAttach().X() + B*ent->SymbolAttach().Y() +
250       C * ent->SymbolAttach().Z() - D;
251   if ( ec > eps || ec < -eps) {
252     char mess[80];
253     Sprintf(mess,"Symbol Attach not in the Plane, gap/equation over %f",
254             Interface_MSG::Intervalled(ec));
255     ach.SendWarning(mess,"Symbol Attach not in the Plane");
256
257   }
258 */
259 }
260
261
262 //=======================================================================
263 //function : OwnDump
264 //purpose  : 
265 //=======================================================================
266
267 void IGESGeom_ToolPlane::OwnDump(const Handle(IGESGeom_Plane)& ent,
268                                  const IGESData_IGESDumper& dumper,
269                                  const Handle(Message_Messenger)& S,
270                                  const Standard_Integer level)  const
271 {
272   S << "IGESGeom_Plane" << endl;
273   Standard_Real A,B,C,D;
274   ent->Equation(A,B,C,D);
275
276   S << "Plane Coefficient A : " << A << endl;
277   S << "Plane Coefficient B : " << B << endl;
278   S << "Plane Coefficient C : " << C << endl;
279   S << "Plane Coefficient D : " << D << endl;
280   S << "The Bounding Curve  : " ;
281   dumper.Dump(ent->BoundingCurve(),S, (level <= 4) ? 0 : 1);
282   S << endl;
283   S << "Display Symbol Location : ";
284   IGESData_DumpXYZL(S,level, ent->SymbolAttach(), ent->Location());
285   S << "  Size  : " << ent->SymbolSize() << endl;
286 }