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