0031939: Coding - correction of spelling errors in comments
[occt.git] / src / IGESGeom / IGESGeom_ToolTransformationMatrix.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_GTrsf.hxx>
20 #include <IGESData_DirChecker.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 <IGESGeom_ToolTransformationMatrix.hxx>
27 #include <IGESGeom_TransformationMatrix.hxx>
28 #include <Interface_Check.hxx>
29 #include <Interface_CopyTool.hxx>
30 #include <Interface_EntityIterator.hxx>
31 #include <Interface_Macros.hxx>
32 #include <Interface_ShareTool.hxx>
33 #include <Message_Msg.hxx>
34 #include <Standard_DomainError.hxx>
35 #include <TColStd_HArray2OfReal.hxx>
36
37 // MGE 03/08/98
38 //=======================================================================
39 //function : IGESGeom_ToolTransformationMatrix
40 //purpose  : 
41 //=======================================================================
42 IGESGeom_ToolTransformationMatrix::IGESGeom_ToolTransformationMatrix ()
43 {
44 }
45
46
47 //=======================================================================
48 //function : ReadOwnParams
49 //purpose  : 
50 //=======================================================================
51
52 void IGESGeom_ToolTransformationMatrix::ReadOwnParams
53   (const Handle(IGESGeom_TransformationMatrix)& ent,
54    const Handle(IGESData_IGESReaderData)& /*IR*/, IGESData_ParamReader& PR) const
55 {
56   // MGE 03/08/98
57
58   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
59   Standard_Real    temp;
60   Handle(TColStd_HArray2OfReal) aMatrix = new TColStd_HArray2OfReal(1,3,1,4);
61
62   for (Standard_Integer I = 1; I <= 3; I++) {
63     for (Standard_Integer J = 1; J <= 4; J++) {
64       //st = PR.ReadReal(PR.Current(), Msg215, temp); //szv#4:S4163:12Mar99 moved in if
65       //st = PR.ReadReal(PR.Current(), "Matrix Elements", temp);
66       if (PR.ReadReal(PR.Current(), temp))
67         aMatrix->SetValue(I, J, temp);
68       else{
69         Message_Msg Msg215("XSTEP_215");
70         PR.SendFail(Msg215);
71       }
72     }
73   }
74
75   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
76   ent->Init(aMatrix);
77 }
78
79
80 //=======================================================================
81 //function : WriteOwnParams
82 //purpose  : 
83 //=======================================================================
84
85 void IGESGeom_ToolTransformationMatrix::WriteOwnParams
86   (const Handle(IGESGeom_TransformationMatrix)& ent, IGESData_IGESWriter& IW) const
87 {
88   for (Standard_Integer I = 1; I <= 3; I++) {
89     for (Standard_Integer J = 1; J <= 4; J++) {
90       IW.Send(ent->Data(I, J));
91     }
92   }
93 }
94
95
96 //=======================================================================
97 //function : OwnShared
98 //purpose  : 
99 //=======================================================================
100
101 void  IGESGeom_ToolTransformationMatrix::OwnShared
102   (const Handle(IGESGeom_TransformationMatrix)& /*ent*/, Interface_EntityIterator& /*iter*/) const
103 {
104 }
105
106
107 //=======================================================================
108 //function : OwnCopy
109 //purpose  : 
110 //=======================================================================
111
112 void IGESGeom_ToolTransformationMatrix::OwnCopy
113   (const Handle(IGESGeom_TransformationMatrix)& another,
114    const Handle(IGESGeom_TransformationMatrix)& ent, Interface_CopyTool& /*TC*/) const
115 {
116   Handle(TColStd_HArray2OfReal) data = new TColStd_HArray2OfReal(1, 3, 1, 4);
117   for (Standard_Integer I = 1; I <= 3;I++) {
118     for (Standard_Integer J = 1; J <= 4; J++) {
119       data->SetValue(I, J, another->Data(I, J));
120     }
121   }
122
123   ent->Init(data);
124   ent->SetFormNumber(another->FormNumber());
125 }
126
127
128 //=======================================================================
129 //function : OwnCorrect
130 //purpose  : 
131 //=======================================================================
132
133 Standard_Boolean IGESGeom_ToolTransformationMatrix::OwnCorrect
134   (const Handle(IGESGeom_TransformationMatrix)& ent) const
135 {
136   if (ent->FormNumber() > 1) return Standard_False;
137   Standard_Integer cfn = (ent->Value().IsNegative() ? 1 : 0);
138   if (cfn == ent->FormNumber()) return Standard_False;
139   ent->SetFormNumber(cfn);
140   return Standard_True;
141 }
142
143
144 //=======================================================================
145 //function : DirChecker
146 //purpose  : 
147 //=======================================================================
148
149 IGESData_DirChecker IGESGeom_ToolTransformationMatrix::DirChecker
150   (const Handle(IGESGeom_TransformationMatrix)& /*ent*/)   const
151 {
152   IGESData_DirChecker DC(124);
153   DC.Structure(IGESData_DefVoid);
154   DC.LineFont(IGESData_DefAny);
155 //  DC.LineWeight(IGESData_DefAny);
156   DC.Color(IGESData_DefAny);
157   DC.BlankStatusIgnored();
158   DC.SubordinateStatusIgnored();
159   DC.UseFlagIgnored();
160   DC.HierarchyStatusIgnored();
161
162   return DC;
163 }
164
165
166 //=======================================================================
167 //function : OwnCheck
168 //purpose  : 
169 //=======================================================================
170
171 void IGESGeom_ToolTransformationMatrix::OwnCheck
172   (const Handle(IGESGeom_TransformationMatrix)& ent,
173    const Interface_ShareTool& , Handle(Interface_Check)& ach)  const
174 {
175   // MGE 03/08/98
176   // Building of messages
177   //========================================
178   //Message_Msg Msg71("XSTEP_71");
179   //========================================
180
181   Standard_Integer form = ent->FormNumber();
182   if ((form != 0) && (form != 1) && ((form < 10) || (form > 12))) {
183     Message_Msg Msg71("XSTEP_71");
184     ach->SendFail(Msg71);
185   }
186 // Theses messages are transferred in the translation procedure
187 /*
188   if (form > 1) return;    // ce qui suit : matrice orthogonale
189   if (form == 0 && ent->Value().IsNegative())
190     ach.AddFail("For Form 0, Determinant is not Positive");
191   else if (form == 1 && !ent->Value().IsNegative())
192     ach.AddFail("For Form 1, Determinant is not Negative");
193
194   Standard_Real p12 = ent->Data(1,1)*ent->Data(2,1) +
195     ent->Data(1,2)*ent->Data(2,2) + ent->Data(1,3)*ent->Data(2,3);
196   Standard_Real p13 = ent->Data(1,1)*ent->Data(3,1) +
197     ent->Data(1,2)*ent->Data(3,2) + ent->Data(1,3)*ent->Data(3,3);
198   Standard_Real p23 = ent->Data(2,1)*ent->Data(3,1) +
199     ent->Data(2,2)*ent->Data(3,2) + ent->Data(2,3)*ent->Data(3,3);
200   Standard_Real ep = 1.e-05;  // ?? Tolorance des tests ?
201   if (p12 < -ep || p12 > ep || p13 < -ep || p13 > ep || p23 < -ep || p23 > ep)
202     ach.AddFail("Matrix is not orthogonal");
203 */
204 }
205
206
207 //=======================================================================
208 //function : OwnDump
209 //purpose  : 
210 //=======================================================================
211
212 void IGESGeom_ToolTransformationMatrix::OwnDump
213   (const Handle(IGESGeom_TransformationMatrix)& ent, const IGESData_IGESDumper& /*dumper*/,
214    Standard_OStream& S, const Standard_Integer /*level*/)  const
215 {
216   S << "IGESGeom_TransformationMatrix\n"
217     << "| R11, R12, R13, T1 |       "
218     << ent->Data(1, 1) << ", " << ent->Data(1, 2) << ", "
219     << ent->Data(1, 3) << ", " << ent->Data(1, 4) << "\n"
220     << "| R21, R22, R23, T2 |       "
221     << ent->Data(2, 1) << ", " << ent->Data(2, 2) << ", "
222     << ent->Data(2, 3) << ", " << ent->Data(2, 4) << "\n"
223     << "| R31, R32, R33, T3 |       "
224     << ent->Data(3, 1) << ", " << ent->Data(3, 2) << ", "
225     << ent->Data(3, 3) << ", " << ent->Data(3, 4) << "\n";
226
227   switch (ent->FormNumber()) {
228     case  0 : S << "-- Direct Orthogonal Matrix"      << std::endl;  break;
229     case  1 : S << "-- Reverse Orthogonal Matrix"     << std::endl;  break;
230     case 10 : S << "-- Cartesien Coordinate System"   << std::endl;  break;
231     case 11 : S << "-- Cylindrical Coordinate System" << std::endl;  break;
232     case 12 : S << "-- Spherical Coordinate System"   << std::endl;  break;
233     default : S << "--  (Incorrect Form Number)"      << std::endl;  break;
234   }
235 }