1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
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>
38 //=======================================================================
39 //function : IGESGeom_ToolTransformationMatrix
41 //=======================================================================
42 IGESGeom_ToolTransformationMatrix::IGESGeom_ToolTransformationMatrix ()
47 //=======================================================================
48 //function : ReadOwnParams
50 //=======================================================================
52 void IGESGeom_ToolTransformationMatrix::ReadOwnParams
53 (const Handle(IGESGeom_TransformationMatrix)& ent,
54 const Handle(IGESData_IGESReaderData)& /*IR*/, IGESData_ParamReader& PR) const
58 //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
60 Handle(TColStd_HArray2OfReal) aMatrix = new TColStd_HArray2OfReal(1,3,1,4);
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);
69 Message_Msg Msg215("XSTEP_215");
75 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
80 //=======================================================================
81 //function : WriteOwnParams
83 //=======================================================================
85 void IGESGeom_ToolTransformationMatrix::WriteOwnParams
86 (const Handle(IGESGeom_TransformationMatrix)& ent, IGESData_IGESWriter& IW) const
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));
96 //=======================================================================
97 //function : OwnShared
99 //=======================================================================
101 void IGESGeom_ToolTransformationMatrix::OwnShared
102 (const Handle(IGESGeom_TransformationMatrix)& /*ent*/, Interface_EntityIterator& /*iter*/) const
107 //=======================================================================
110 //=======================================================================
112 void IGESGeom_ToolTransformationMatrix::OwnCopy
113 (const Handle(IGESGeom_TransformationMatrix)& another,
114 const Handle(IGESGeom_TransformationMatrix)& ent, Interface_CopyTool& /*TC*/) const
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));
124 ent->SetFormNumber(another->FormNumber());
128 //=======================================================================
129 //function : OwnCorrect
131 //=======================================================================
133 Standard_Boolean IGESGeom_ToolTransformationMatrix::OwnCorrect
134 (const Handle(IGESGeom_TransformationMatrix)& ent) const
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;
144 //=======================================================================
145 //function : DirChecker
147 //=======================================================================
149 IGESData_DirChecker IGESGeom_ToolTransformationMatrix::DirChecker
150 (const Handle(IGESGeom_TransformationMatrix)& /*ent*/) const
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();
160 DC.HierarchyStatusIgnored();
166 //=======================================================================
167 //function : OwnCheck
169 //=======================================================================
171 void IGESGeom_ToolTransformationMatrix::OwnCheck
172 (const Handle(IGESGeom_TransformationMatrix)& ent,
173 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
176 // Building of messages
177 //========================================
178 //Message_Msg Msg71("XSTEP_71");
179 //========================================
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);
186 // These messages are transferred in the translation procedure
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");
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");
207 //=======================================================================
210 //=======================================================================
212 void IGESGeom_ToolTransformationMatrix::OwnDump
213 (const Handle(IGESGeom_TransformationMatrix)& ent, const IGESData_IGESDumper& /*dumper*/,
214 Standard_OStream& S, const Standard_Integer /*level*/) const
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";
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;