0023258: Missing parenthesis
[occt.git] / src / IGESGeom / IGESGeom_ToolBSplineSurface.cxx
CommitLineData
b311480e 1// Created by: CKY / Contract Toubro-Larsen
2// Copyright (c) 1993-1999 Matra Datavision
3// Copyright (c) 1999-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
7fd59977 9//
b311480e 10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
7fd59977 12//
b311480e 13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20//--------------------------------------------------------------------
7fd59977 21//--------------------------------------------------------------------
22
23#include <IGESGeom_ToolBSplineSurface.ixx>
24#include <IGESData_ParamCursor.hxx>
25#include <gp_XYZ.hxx>
26#include <TColStd_HArray1OfReal.hxx>
27#include <TColStd_HArray2OfReal.hxx>
28#include <TColgp_HArray2OfXYZ.hxx>
29#include <IGESData_Dump.hxx>
30#include <Interface_Macros.hxx>
31
32// MGE 31/07/98
33#include <Message_Msg.hxx>
34
35
36//=======================================================================
37//function : IGESGeom_ToolBSplineSurface
38//purpose :
39//=======================================================================
40
41IGESGeom_ToolBSplineSurface::IGESGeom_ToolBSplineSurface ()
42{
43}
44
45
46//=======================================================================
47//function : ReadOwnParams
48//purpose :
49//=======================================================================
50
51void IGESGeom_ToolBSplineSurface::ReadOwnParams
52 (const Handle(IGESGeom_BSplineSurface)& ent,
53 const Handle(IGESData_IGESReaderData)& /* IR */, IGESData_ParamReader& PR) const
54{
55 // MGE 31/07/98
56 // Building of messages
57 //========================================
58 Message_Msg Msg100("XSTEP_100");
59 Message_Msg Msg101("XSTEP_101");
60 Message_Msg Msg102("XSTEP_102");
61 Message_Msg Msg103("XSTEP_103");
62 Message_Msg Msg159("XSTEP_159");
63 //========================================
64
65 Standard_Integer I, J;
66 Standard_Integer anIndexU, anIndexV, aDegU, aDegV;
67 Standard_Boolean aCloseU, aCloseV, aPolynom, aPeriodU, aPeriodV;
68 Standard_Real aUmin, aUmax, aVmin, aVmax;
69 Standard_Real tempVal;
70 gp_XYZ tempXYZ;
71 Handle(TColStd_HArray1OfReal) allKnotsU;
72 Handle(TColStd_HArray1OfReal) allKnotsV;
73 Handle(TColStd_HArray2OfReal) allWeights;
74 Handle(TColgp_HArray2OfXYZ) allPoles;
75
76 //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
77 Standard_Boolean FlagindexU = PR.ReadInteger(PR.Current(), anIndexU);
78
79 Standard_Boolean FlagindexV = PR.ReadInteger(PR.Current(), anIndexV);
80
81 if (!FlagindexU || !FlagindexV){
82 Message_Msg Msg97("XSTEP_97");
83 PR.SendFail(Msg97);
84 }
85
86 Standard_Boolean FlagdegU = PR.ReadInteger(PR.Current(), aDegU);
87
88 Standard_Boolean FlagdegV = PR.ReadInteger(PR.Current(), aDegV);
89
90 if (!FlagdegU || !FlagdegV){
91 Message_Msg Msg98("XSTEP_98");
92 PR.SendFail(Msg98);
93 }
94 //szv#4:S4163:12Mar99 `st=` not needed
95 PR.ReadBoolean(PR.Current(), Msg100,aCloseU);
96 PR.ReadBoolean(PR.Current(), Msg100,aCloseV);
97 PR.ReadBoolean(PR.Current(), Msg101, aPolynom);
98 PR.ReadBoolean(PR.Current(), Msg102, aPeriodU);
99 PR.ReadBoolean(PR.Current(), Msg102, aPeriodV);
100
101/*
102 Standard_Boolean FlagindexU =
103 PR.ReadInteger(PR.Current(), "Upper Index in U", anIndexU);
104
105 Standard_Boolean FlagindexV =
106 PR.ReadInteger(PR.Current(), "Upper Index in V", anIndexV);
107
108 Standard_Boolean FlagdegU =
109 PR.ReadInteger(PR.Current(), "Degree Of First Basis Functions", aDegU);
110
111 Standard_Boolean FlagdegV =
112 PR.ReadInteger(PR.Current(), "Degree Of Second Basis Functions",aDegV);
113
114 st = PR.ReadBoolean(PR.Current(), "Closed/Open flag in U Direction",aCloseU);
115 st = PR.ReadBoolean(PR.Current(), "Closed/Open flag in V Direction",aCloseV);
116 st = PR.ReadBoolean(PR.Current(), "Polynomial / Rational", aPolynom);
117 st = PR.ReadBoolean(PR.Current(), "Periodic flag in U direction", aPeriodU);
118 st = PR.ReadBoolean(PR.Current(), "Periodic flag in V direction", aPeriodV);
119*/
120 if ( FlagdegU && FlagindexU )
121 {
122// allKnotsU = new TColStd_HArray1OfReal(-aDegU, anIndexU+1); done by :
123 Standard_Integer tempind = anIndexU+aDegU+2;
124 PR.ReadReals(PR.CurrentList(tempind), Msg103, allKnotsU, -aDegU); //szv#4:S4163:12Mar99 `st=` not needed
125 //st = PR.ReadReals(PR.CurrentList(tempind), "First knot sequence values", allKnotsU, -aDegU);
126 }
127
128 if ( FlagdegV && FlagindexV )
129 {
130// allKnotsV = new TColStd_HArray1OfReal(-aDegV, anIndexV+1); done by :
131 Standard_Integer tempind = anIndexV+aDegV+2;
132 PR.ReadReals(PR.CurrentList(tempind), Msg103, allKnotsV, -aDegV); //szv#4:S4163:12Mar99 `st=` not needed
133 //st = PR.ReadReals(PR.CurrentList(tempind), "Second knot sequence values", allKnotsV, -aDegV);
134 }
135
136 if ( FlagindexU && FlagindexV )
137 {
138 allWeights = new TColStd_HArray2OfReal (0, anIndexU, 0, anIndexV);
139 allPoles = new TColgp_HArray2OfXYZ (0, anIndexU, 0, anIndexV);
140
141 Standard_Boolean BadWeigth = Standard_False;
142 Message_Msg Msg105("XSTEP_105");
143
144 for (J = 0; J <= anIndexV; J ++) {
145 for (I = 0; I <= anIndexU; I ++) {
146 //st = PR.ReadReal(PR.Current(), Msg104, tempVal); //szv#4:S4163:12Mar99 moved down
147 //st = PR.ReadReal(PR.Current(), "Weights", tempVal);
148 if (PR.ReadReal(PR.Current(), tempVal)) {
149 if(tempVal<Precision::PConfusion()) { // skl for OCC2821 11.06.2003
150 BadWeigth = Standard_True;
151 }
152 allWeights->SetValue(I, J, tempVal);
153 }
154 else{
155 Message_Msg Msg104("XSTEP_104");
156 PR.SendFail(Msg104);
157 }
158 }
159 }
160 if(BadWeigth) { // skl for OCC2821 11.06.2003
161 for (J = 0; J <= anIndexV; J ++) {
162 for (I = 0; I <= anIndexU; I ++) {
163 allWeights->SetValue(I, J, 1.);
164 }
165 }
166 }
167
168 for (J = 0; J <= anIndexV; J ++)
169 for (I = 0; I <= anIndexU; I ++) {
170 //st = PR.ReadXYZ (PR.CurrentList(1, 3), Msg105, tempXYZ); //szv#4:S4163:12Mar99 moved down
171 //st = PR.ReadXYZ (PR.CurrentList(1, 3), "Control Points", tempXYZ);
172 if (PR.ReadXYZ (PR.CurrentList(1, 3), Msg105, tempXYZ))
173 allPoles->SetValue(I, J, tempXYZ);
174 }
175 }
176
177 //szv#4:S4163:12Mar99 `st=` not needed
178 /* PR.ReadReal(PR.Current(), Msg106, aUmin);
179 PR.ReadReal(PR.Current(), Msg107, aUmax);
180 PR.ReadReal(PR.Current(), Msg106, aVmin);
181 PR.ReadReal(PR.Current(), Msg107, aVmax);
182*/
183 if (!PR.ReadReal(PR.Current(), aUmin) || !PR.ReadReal(PR.Current(), aVmin)){
184 Message_Msg Msg106("XSTEP_106");
185 PR.SendFail(Msg106);
186 }
187
188 if (!PR.ReadReal(PR.Current(), aUmax) || !PR.ReadReal(PR.Current(), aVmax)){
189 Message_Msg Msg107("XSTEP_107");
190 PR.SendFail(Msg107);
191 }
192/*
193 st = PR.ReadReal(PR.Current(), "Starting Value For U Direction", aUmin);
194 st = PR.ReadReal(PR.Current(), "Ending Value For U Direction", aUmax);
195 st = PR.ReadReal(PR.Current(), "Starting Value For V Direction", aVmin);
196 st = PR.ReadReal(PR.Current(), "Ending Value For U Direction", aVmax);
197*/
198// PROTECTION contre ANSYS 5.3 qui ecrit 3 flottants en plus ...
199 Standard_Integer icur = PR.CurrentNumber(), imax = PR.NbParams();
200 Standard_Real bid; Standard_Integer pbfin = 0;
201 //st = Standard_True; //szv#4:S4163:12Mar99 not needed
202 while (imax >= icur) {
203 Interface_ParamType pt = PR.ParamType(icur);
204 if (pt == Interface_ParamReal) {
205 if (!PR.ReadReal (PR.Current(),bid)){
206 PR.SendFail(Msg159);
207 } //szv#4:S4163:12Mar99 `st=` not needed
208 if (pbfin == 0) pbfin = 1;
209 }
210 else if (pt == Interface_ParamInteger || pt == Interface_ParamVoid) break;
211 else pbfin = -1;
212 icur ++;
213 }
214 if (pbfin > 0) PR.SendWarning(Msg159);
215 if (pbfin < 0){
216 Message_Msg Msg158("XSTEP_158");
217 PR.SendFail(Msg158);
218 }
219 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
220 ent->Init
221 (anIndexU, anIndexV, aDegU, aDegV, aCloseU, aCloseV,
222 aPolynom, aPeriodU, aPeriodV, allKnotsU, allKnotsV,
223 allWeights, allPoles, aUmin, aUmax, aVmin, aVmax);
224}
225
226
227//=======================================================================
228//function : WriteOwnParams
229//purpose :
230//=======================================================================
231
232void IGESGeom_ToolBSplineSurface::WriteOwnParams
233 (const Handle(IGESGeom_BSplineSurface)& ent, IGESData_IGESWriter& IW) const
234{
235 Standard_Integer indU = ent->UpperIndexU();
236 Standard_Integer indV = ent->UpperIndexV();
237 Standard_Integer degU = ent->DegreeU();
238 Standard_Integer degV = ent->DegreeV();
239 Standard_Integer I, J;
240 IW.Send(indU);
241 IW.Send(indV);
242 IW.Send(degU);
243 IW.Send(degV);
244 IW.SendBoolean(ent->IsClosedU());
245 IW.SendBoolean(ent->IsClosedV());
246 IW.SendBoolean(ent->IsPolynomial());
247 IW.SendBoolean(ent->IsPeriodicU());
248 IW.SendBoolean(ent->IsPeriodicV());
249
250 for (I = -degU; I <= indU + 1; I ++)
251 IW.Send(ent->KnotU(I));
252
253 for (I = -degV; I <= indV + 1; I ++)
254 IW.Send(ent->KnotV(I));
255
256 for (J = 0; J <= indV; J ++)
257 for (I = 0; I <= indU; I ++)
258 IW.Send(ent->Weight(I, J));
259
260 for (J = 0; J <= indV; J ++)
261 for (I = 0; I <= indU; I ++) {
262 gp_XYZ tempXYZ = ent->Pole(I, J).XYZ();
263 IW.Send(tempXYZ.X());
264 IW.Send(tempXYZ.Y());
265 IW.Send(tempXYZ.Z());
266 }
267 IW.Send(ent->UMin());
268 IW.Send(ent->UMax());
269 IW.Send(ent->VMin());
270 IW.Send(ent->VMax());
271}
272
273
274//=======================================================================
275//function : OwnShared
276//purpose :
277//=======================================================================
278
279void IGESGeom_ToolBSplineSurface::OwnShared(const Handle(IGESGeom_BSplineSurface)& /* ent */,
280 Interface_EntityIterator& /* iter */) const
281{
282}
283
284
285//=======================================================================
286//function : OwnCopy
287//purpose :
288//=======================================================================
289
290void IGESGeom_ToolBSplineSurface::OwnCopy(const Handle(IGESGeom_BSplineSurface)& another,
291 const Handle(IGESGeom_BSplineSurface)& ent,
292 Interface_CopyTool& /* TC */) const
293{
294 Standard_Integer I, J;
295 Standard_Integer anIndexU, anIndexV, aDegU, aDegV;
296 Standard_Boolean aCloseU, aCloseV, aPolynom;
297 Standard_Boolean aPeriodU, aPeriodV;
298 Standard_Real aUmin, aUmax, aVmin, aVmax;
299
300 anIndexU = another->UpperIndexU();
301 anIndexV = another->UpperIndexV();
302 aDegU = another->DegreeU();
303 aDegV = another->DegreeV();
304 aCloseU = another->IsClosedU();
305 aCloseV = another->IsClosedV();
306 aPolynom = another->IsPolynomial();
307 aPeriodU = another->IsPeriodicU();
308 aPeriodV = another->IsPeriodicV();
309
310 Handle(TColStd_HArray1OfReal) allKnotsU =
311 new TColStd_HArray1OfReal(-aDegU, anIndexU+1);
312 Handle(TColStd_HArray1OfReal) allKnotsV =
313 new TColStd_HArray1OfReal(-aDegV, anIndexV+1);
314
315 for (I = -aDegU; I <= anIndexU + 1; I ++)
316 allKnotsU->SetValue(I, another->KnotU(I));
317
318 for (I = -aDegV; I <= anIndexV + 1; I ++)
319 allKnotsV->SetValue(I, another->KnotV(I));
320
321 Handle(TColStd_HArray2OfReal) allWeights =
322 new TColStd_HArray2OfReal (0, anIndexU, 0, anIndexV);
323 Handle(TColgp_HArray2OfXYZ) allPoles =
324 new TColgp_HArray2OfXYZ (0, anIndexU, 0, anIndexV);
325
326 for (J = 0; J <= anIndexV; J ++)
327 for (I = 0; I <= anIndexU; I ++)
328 allWeights->SetValue(I, J, another->Weight(I,J));
329
330 for (J = 0; J <= anIndexV; J ++)
331 for (I = 0; I <= anIndexU; I ++)
332 allPoles->SetValue(I, J, another->Pole(I, J).XYZ());
333
334 aUmin = another->UMin();
335 aUmax = another->UMax();
336 aVmin = another->VMin();
337 aVmax = another->VMax();
338
339 ent->Init (anIndexU, anIndexV, aDegU, aDegV, aCloseU, aCloseV,
340 aPolynom, aPeriodU, aPeriodV, allKnotsU, allKnotsV,
341 allWeights, allPoles, aUmin, aUmax, aVmin, aVmax);
342 ent->SetFormNumber(another->FormNumber());
343}
344
345
346//=======================================================================
347//function : DirChecker
348//purpose :
349//=======================================================================
350
351IGESData_DirChecker IGESGeom_ToolBSplineSurface::DirChecker
352 (const Handle(IGESGeom_BSplineSurface)& /* ent */ ) const
353{
354 IGESData_DirChecker DC(128, 0, 9);
355 DC.Structure(IGESData_DefVoid);
356 DC.LineFont(IGESData_DefAny);
357// DC.LineWeight(IGESData_DefValue);
358 DC.Color(IGESData_DefAny);
359 DC.HierarchyStatusIgnored();
360 return DC;
361}
362
363
364//=======================================================================
365//function : OwnCheck
366//purpose :
367//=======================================================================
368
369void IGESGeom_ToolBSplineSurface::OwnCheck(const Handle(IGESGeom_BSplineSurface)& ent,
370 const Interface_ShareTool&,
371 Handle(Interface_Check)& ach) const
372{
373 // MGE 31/07/98
374 // Building of messages
375 //========================================
376 //Message_Msg Msg104("XSTEP_104");
377 //Message_Msg Msg160("XSTEP_160");
378 //Message_Msg Msg161("XSTEP_161");
379 //========================================
380
381
382
383 //Standard_Real eps = 1.E-04; // Tolerance des tests ?? //szv#4:S4163:12Mar99 not needed
384
385 //modified by rln 18/12/97 check of flag PROP2 according to IGES Standard
386 //The same as in IGESGeom_ToolBSplineCurve::OwnCheck()
387 //It is possible to compare U(0) and U(1) only if UStartingParameter = UFirstKnot
388 //and UEndingParameter = ULastKnot and the same for V(0),V(1)
389 //(else we must build real geometrical curve)
390 //The fail is replaced with warning because it is not a serious problem
391/*
392 if (ent->UMin() == ent->KnotU(-ent->DegreeU() ) &&
393 ent->UMax() == ent->KnotU( ent->UpperIndexU() + 1) ) {
394 Standard_Real udif = Max (ent->Pole(0, 0).SquareDistance (ent->Pole(ent->UpperIndexU(), 0)),
395 ent->Pole(0, ent->UpperIndexV()).SquareDistance (ent->Pole(ent->UpperIndexU(), ent->UpperIndexV())));
396// if ((ent->UMin() == ent->UMax()) && !ent->IsClosedU())
397// if (udif < eps * eps && !ent->IsClosedU())
398// ach.AddWarning("U(0) == U(1) & PROP1 != 1");
399// if ((ent->UMin() != ent->UMax()) && ent->IsClosedU())
400// if (udif >= eps * eps && ent->IsClosedU())
401// ach.AddWarning("U(0) != U(1) & PROP1 != 0");
402 }
403
404 if (ent->VMin() == ent->KnotV(-ent->DegreeV() ) &&
405 ent->VMax() == ent->KnotV( ent->UpperIndexV() + 1) ) {
406 Standard_Real vdif = Max (ent->Pole(0, 0).SquareDistance (ent->Pole(0, ent->UpperIndexV())),
407 ent->Pole(ent->UpperIndexU(), 0).SquareDistance (ent->Pole(ent->UpperIndexU(), ent->UpperIndexV())));
408// if ((ent->VMin() == ent->VMax()) && !ent->IsClosedV())
409// if (vdif < eps * eps && !ent->IsClosedV())
410// ach.AddWarning("V(0) == V(1) & PROP2 != 1");
411// if ((ent->VMin() != ent->VMax()) && ent->IsClosedV())
412// if (vdif >= eps * eps && ent->IsClosedV())
413// ach.AddWarning("V(0) != V(1) & PROP2 != 0");
414 }
415*/
416
417 Standard_Boolean Flag = Standard_True;
418 Standard_Integer indU = ent->UpperIndexU();
419 Standard_Integer indV = ent->UpperIndexV();
420 Standard_Integer I,J;
421
422 if (ent->NbKnotsU() != (indU + ent->DegreeU() +2)) {
423 Message_Msg Msg160("XSTEP_160");
424 Msg160.Arg(indU + ent->DegreeU() +2);
425 ach->SendFail(Msg160);
426 }
427 if (ent->NbKnotsV() != (indV + ent->DegreeV() +2)) {
428 Message_Msg Msg161("XSTEP_161");
429 Msg161.Arg(indV + ent->DegreeV() +2);
430 ach->SendFail(Msg161);
431 }
432
433 for ( J = 0; ((J < indV) && (Flag)); J ++)
434 for ( I = 0; ((I < indU) && (Flag)); I ++)
435 Flag &= (ent->Weight(I,J) > 0);
436
437 if (!Flag) {
438 Message_Msg Msg104("XSTEP_104");
439 ach->SendFail(Msg104);
440 }
441
442 Flag = Standard_True;
443 Standard_Real tempVal = ent->Weight(0,0);
444
445 for ( J = 0; ((J < indV) && (Flag)); J ++)
446 for ( I = 0; ((I < indU) && (Flag)); I ++)
447 Flag &= (ent->Weight(I,J) == tempVal);
448
449// Standard_Boolean Flap = ent->IsPolynomial(Standard_True);
450// if (Flag && !Flap)
451// ach.AddWarning("All weights equal & PROP3 != 1. (Surface not Polynomial)");
452// if (!Flag && Flap)
453// ach.AddWarning("All weights not equal & PROP3 != 0 (Surface not Rational)");
454}
455
456
457//=======================================================================
458//function : OwnDump
459//purpose :
460//=======================================================================
461
462void IGESGeom_ToolBSplineSurface::OwnDump(const Handle(IGESGeom_BSplineSurface)& ent,
463 const IGESData_IGESDumper& /* dumper */,
464 const Handle(Message_Messenger)& S,
465 const Standard_Integer level) const
466{
467 S << "BSplineSurface from IGESGeom" << endl << endl;
468
469 Standard_Integer indU = ent->UpperIndexU();
470 Standard_Integer indV = ent->UpperIndexV();
471 Standard_Integer degU = ent->DegreeU();
472 Standard_Integer degV = ent->DegreeV();
473
474 S << "In U : Upper Knot Index : " << indU;
475 S << " Degree : " << degU << " ";
476 S << (ent->IsClosedU() ? "Closed" : "Open") << " ";
477 S << (ent->IsPeriodicU() ? "Periodic" : "Non Periodic");
478 S << endl;
479 S << "In V : Upper Knot Index : " << indV;
480 S << " Degree : " << degV << " ";
481 S << (ent->IsClosedV() ? "Closed" : "Open") << " ";
482 S << (ent->IsPeriodicV() ? "Periodic" : "Non Periodic") << " ";
483 S << (ent->IsPolynomial(Standard_True) ? "Polynomial" : "Rational") << endl;
484
485 S << "Starting Parameter for U direction : " << ent->UMin() << endl;
486 S << "Ending Parameter for U direction : " << ent->UMax() << endl;
487 S << "Starting Parameter for V direction : " << ent->VMin() << endl;
488 S << "Ending Parameter for V direction : " << ent->VMax() << endl;
489
490 S << " Knots in U : ";
491 IGESData_DumpVals(S ,level,-degU, indU+1,ent->KnotU);
492 S << endl;
493 S << " Knots in V : ";
494 IGESData_DumpVals(S ,level,-degV, indV+1,ent->KnotV);
495 S << endl;
496 S << "Weights : (Row -> IndexU, Col -> IndexV)";
497 IGESData_DumpRectVals(S ,level,0, indU,0,indV,ent->Weight);
498 S << endl;
499 S << "Control Points (Poles) : ";
500//IGESData_DumpRectXYZL(S,level,1, ent->NbPoles(),ent->Pole, ent->Location());
501 if (level < 5) { S << " [ content : ask level > 4 ]" << endl; return; }
502 gp_GTrsf loca = ent->Location();
503 for (Standard_Integer JP = 0; JP <= indV; JP ++)
504 for (Standard_Integer IP = 0; IP <= indU; IP ++) {
505 if (IP == 0) S << endl;
506 S <<" - ["<<IP<<","<<JP<<"]: ";
507 IGESData_DumpXYZL(S,level,ent->Pole(IP,JP),loca);
508 }
509 S << endl;
510}