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 //--------------------------------------------------------------------
18 //#54 rln 24.12.98 CCI60005
21 #include <IGESData_DirChecker.hxx>
22 #include <IGESData_Dump.hxx>
23 #include <IGESData_IGESDumper.hxx>
24 #include <IGESData_IGESReaderData.hxx>
25 #include <IGESData_IGESWriter.hxx>
26 #include <IGESData_ParamCursor.hxx>
27 #include <IGESData_ParamReader.hxx>
28 #include <IGESGeom_BSplineCurve.hxx>
29 #include <IGESGeom_ToolBSplineCurve.hxx>
30 #include <Interface_Check.hxx>
31 #include <Interface_CopyTool.hxx>
32 #include <Interface_EntityIterator.hxx>
33 #include <Interface_Macros.hxx>
34 #include <Interface_ShareTool.hxx>
35 #include <Message_Messenger.hxx>
36 #include <Message_Msg.hxx>
37 #include <Standard_DomainError.hxx>
38 #include <TColgp_HArray1OfXYZ.hxx>
39 #include <TColStd_HArray1OfReal.hxx>
42 //=======================================================================
43 //function : IGESGeom_ToolBSplineCurve
45 //=======================================================================
46 IGESGeom_ToolBSplineCurve::IGESGeom_ToolBSplineCurve ()
51 //=======================================================================
52 //function : ReadOwnParams
54 //=======================================================================
56 void IGESGeom_ToolBSplineCurve::ReadOwnParams(const Handle(IGESGeom_BSplineCurve)& ent,
57 const Handle(IGESData_IGESReaderData)& /* IR */,
58 IGESData_ParamReader& PR) const
61 // Building of messages
62 //========================================
63 Message_Msg Msg99("XSTEP_99");
64 Message_Msg Msg100("XSTEP_100");
65 Message_Msg Msg101("XSTEP_101");
66 Message_Msg Msg102("XSTEP_102");
67 Message_Msg Msg103("XSTEP_103");
68 //========================================
70 Standard_Integer anIndex, aDegree;
71 Standard_Boolean aPlanar, aClosed, aPolynomial, aPeriodic;
72 Standard_Real aUmin, aUmax, normX,normY,normZ;
73 gp_XYZ aNorm (0.,0.,0.);
74 Handle(TColStd_HArray1OfReal) allKnots;
75 Handle(TColStd_HArray1OfReal) allWeights;
76 Handle(TColgp_HArray1OfXYZ) allPoles;
78 //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
80 //st = PR.ReadInteger(PR.Current(), Msg97, anIndex); //szv#4:S4163:12Mar99 moved in if
81 //st = PR.ReadInteger(PR.Current(), "Upper Index Of Sum", anIndex);
83 //szv#4:S4163:12Mar99 optimized
84 /*if (st && anIndex >= 0) {
85 allPoles = new TColgp_HArray1OfXYZ(0, anIndex);
86 // allWeights = new TColStd_HArray1OfReal(1, anIndex+1); done by ReadReals
89 if (st && anIndex < 0)
94 if (PR.ReadInteger(PR.Current(), anIndex)) {
96 Message_Msg Msg97("XSTEP_97");
101 allPoles = new TColgp_HArray1OfXYZ(0, anIndex);
102 // allWeights = new TColStd_HArray1OfReal(1, anIndex+1); done by ReadReals
106 Message_Msg Msg97("XSTEP_97");
110 //st = PR.ReadInteger(PR.Current(), Msg98, aDegree); //szv#4:S4163:12Mar99 moved in if
111 // if (st && ! allWeights.IsNull() ) done by ReadReals
112 // allKnots = new TColStd_HArray1OfReal(-aDegree, anIndex+1);
113 if (!PR.ReadInteger(PR.Current(), aDegree)){
114 aDegree = 0; //szv#4:S4163:12Mar99 `st=` not needed
115 Message_Msg Msg98("XSTEP_98");
118 //szv#4:S4163:12Mar99 `st=` not needed
119 PR.ReadBoolean(PR.Current(), Msg99, aPlanar);
120 PR.ReadBoolean(PR.Current(), Msg100, aClosed);
121 PR.ReadBoolean(PR.Current(), Msg101, aPolynomial);
122 PR.ReadBoolean(PR.Current(), Msg102, aPeriodic);
124 //st = PR.ReadBoolean(PR.Current(), "Planar/Non Planar Flag", aPlanar);
125 //st = PR.ReadBoolean(PR.Current(), "Open/Closed Flag", aClosed);
126 //st = PR.ReadBoolean(PR.Current(), "Rational/Polynomial Flag", aPolynomial);
127 //st = PR.ReadBoolean(PR.Current(), "NonPeriodic/Periodic Flag", aPeriodic);
129 Standard_Integer nbKnots = anIndex + aDegree + 2;
130 // Reading all the knot sequences
132 PR.ReadReals(PR.CurrentList(nbKnots), Msg103 , allKnots, -aDegree); //szv#4:S4163:12Mar99 `st=` not needed
135 // (PR.CurrentList(nbKnots), "Knot sequence values", allKnots, -aDegree);
137 if (! allPoles.IsNull() )
139 Message_Msg Msg104("XSTEP_104");
140 Message_Msg Msg105("XSTEP_105");
141 PR.ReadReals(PR.CurrentList(anIndex+1), Msg104, allWeights,0); //szv#4:S4163:12Mar99 `st=` not needed
142 //st = PR.ReadReals(PR.CurrentList(anIndex+1), "Weights", allWeights,0);
144 for (Standard_Integer I = 0; I <= anIndex; I ++)
147 //st = PR.ReadXYZ(PR.CurrentList(1, 3), Msg105, tempPole); //szv#4:S4163:12Mar99 moved down
148 //st = PR.ReadXYZ(PR.CurrentList(1, 3), "Control Points", tempPole);
149 if (PR.ReadXYZ(PR.CurrentList(1, 3), Msg105, tempPole)) allPoles->SetValue(I, tempPole);
153 if (!PR.ReadReal(PR.Current(), aUmin)){
154 Message_Msg Msg106("XSTEP_106");
156 } //szv#4:S4163:12Mar99 `st=` not needed
157 if (!PR.ReadReal(PR.Current(), aUmax)){
158 Message_Msg Msg107("XSTEP_107");
160 } //szv#4:S4163:12Mar99 `st=` not needed
162 st = PR.ReadReal(PR.Current(), "Starting Parameter Value", aUmin);
163 st = PR.ReadReal(PR.Current(), "Ending Parameter Value", aUmax);
165 Standard_Boolean st = Standard_False;
166 if (PR.DefinedElseSkip()){
167 st = PR.ReadReal(PR.Current(), normX);
169 Message_Msg Msg108("XSTEP_108");
173 //st = PR.ReadReal(PR.Current(), "Unit Normal X", normX);
175 if (PR.DefinedElseSkip()){
176 st = PR.ReadReal(PR.Current(), normY);
178 Message_Msg Msg108("XSTEP_108");
182 //st = PR.ReadReal(PR.Current(), "Unit Normal Y", normY);
184 if (PR.DefinedElseSkip()){
185 st = PR.ReadReal(PR.Current(), normZ);
187 Message_Msg Msg108("XSTEP_108");
191 //st = PR.ReadReal(PR.Current(), "Unit Normal Z", normZ);
193 if (st) aNorm.SetCoord(normX,normY,normZ);
195 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
197 (anIndex,aDegree, aPlanar, aClosed, aPolynomial, aPeriodic,
198 allKnots, allWeights, allPoles, aUmin, aUmax, aNorm);
202 //=======================================================================
203 //function : WriteOwnParams
205 //=======================================================================
207 void IGESGeom_ToolBSplineCurve::WriteOwnParams
208 (const Handle(IGESGeom_BSplineCurve)& ent, IGESData_IGESWriter& IW) const
210 Standard_Integer low, up ;
212 Standard_Integer index = ent->UpperIndex();
213 Standard_Integer degree = ent->Degree();
216 IW.SendBoolean(ent->IsPlanar());
217 IW.SendBoolean(ent->IsClosed());
218 IW.SendBoolean(ent->IsPolynomial());
219 IW.SendBoolean(ent->IsPeriodic());
223 for (I = low; I <= up; I ++)
224 IW.Send(ent->Knot(I));
228 for (I = low; I <= up; I ++)
229 IW.Send(ent->Weight(I));
231 for (I = low; I <= up; I ++) {
232 IW.Send((ent->Pole(I)).X());
233 IW.Send((ent->Pole(I)).Y());
234 IW.Send((ent->Pole(I)).Z());
236 IW.Send(ent->UMin());
237 IW.Send(ent->UMax());
238 IW.Send(ent->Normal().X());
239 IW.Send(ent->Normal().Y());
240 IW.Send(ent->Normal().Z());
244 //=======================================================================
245 //function : OwnShared
247 //=======================================================================
249 void IGESGeom_ToolBSplineCurve::OwnShared(const Handle(IGESGeom_BSplineCurve)& /* ent */,
250 Interface_EntityIterator& /* iter */) const
255 //=======================================================================
258 //=======================================================================
260 void IGESGeom_ToolBSplineCurve::OwnCopy
261 (const Handle(IGESGeom_BSplineCurve)& another,
262 const Handle(IGESGeom_BSplineCurve)& ent, Interface_CopyTool& /* TC */) const
265 Standard_Integer low, up;
266 Standard_Integer anIndex, aDegree;
267 Standard_Boolean aPlanar, aClosed, aPolynomial, aPeriodic;
268 Handle(TColStd_HArray1OfReal) allKnots, allWeights;
269 Handle(TColgp_HArray1OfXYZ) allPoles;
270 Standard_Real aUmin, aUmax;
273 anIndex = another->UpperIndex();
274 aDegree = another->Degree();
275 aPlanar = another->IsPlanar();
276 aClosed = another->IsClosed();
277 aPolynomial = another->IsPolynomial();
278 aPeriodic = another->IsPeriodic();
280 allKnots = new TColStd_HArray1OfReal(-aDegree, anIndex+1);
284 for (I = low; I <= up; I++)
285 allKnots->SetValue(I, another->Knot(I));
287 allWeights = new TColStd_HArray1OfReal(0, anIndex);
291 for (I = low; I <= up; I++)
292 allWeights->SetValue(I, another->Weight(I));
294 allPoles = new TColgp_HArray1OfXYZ(0, anIndex);
296 for (I = low; I <= up; I++)
297 allPoles->SetValue(I, (another->Pole(I)).XYZ());
299 aUmin = another->UMin();
300 aUmax = another->UMax();
301 aNorm = another->Normal();
303 ent->Init (anIndex,aDegree, aPlanar, aClosed, aPolynomial, aPeriodic,
304 allKnots, allWeights, allPoles, aUmin, aUmax, aNorm);
308 //=======================================================================
309 //function : DirChecker
311 //=======================================================================
313 IGESData_DirChecker IGESGeom_ToolBSplineCurve::DirChecker
314 (const Handle(IGESGeom_BSplineCurve)& /* ent */ ) const
316 IGESData_DirChecker DC(126, 0, 5);
317 DC.Structure(IGESData_DefVoid);
318 DC.LineFont(IGESData_DefAny);
319 // DC.LineWeight(IGESData_DefValue);
320 DC.Color(IGESData_DefAny);
321 DC.HierarchyStatusIgnored();
326 //=======================================================================
327 //function : OwnCheck
329 //=======================================================================
331 void IGESGeom_ToolBSplineCurve::OwnCheck(const Handle(IGESGeom_BSplineCurve)& ent,
332 const Interface_ShareTool&,
333 Handle(Interface_Check)& ach) const
336 // Building of messages
337 //========================================
338 //Message_Msg Msg104("XSTEP_104");
339 //Message_Msg Msg109("XSTEP_109");
340 //========================================
342 Standard_Real eps = 1.E-04; // Tolerance des tests ??
343 // Standard_Real norm = ent->Normal().SquareModulus();
345 //modified by rln 17/12/97 check of flag PROP2 according to IGES Standard
346 //It is possible to compare V(0) and V(1) only if StartingParameter = FirstKnot
347 //and EndingParameter = LastKnot (else we must build real geometrical curve)
348 //The fail is replaced with warning because it is not a serious problem
349 //if (ent->UMin() == ent->Knot(-ent->Degree() ) &&
350 // ent->UMax() == ent->Knot( ent->UpperIndex() + 1) ) {
351 // Standard_Real udif = ent->UMax() - ent->UMin();
352 // if (udif < 0) udif = -udif;
353 // Standard_Real udif = ent->Pole(0).SquareDistance (ent->Pole(ent->UpperIndex()));
354 // if (udif < eps * eps && !ent->IsClosed())
355 // ach.AddWarning("V(0) == V(1) for an Open Curve (PROP2 = 0)");
356 // if (udif >= eps * eps && ent->IsClosed())
357 // ach.AddWarning("V(0) != V(1) for a Closed Curve (PROP2 = 1)");
360 Standard_Integer lower = 0;
361 Standard_Integer upper = ent->UpperIndex();
362 Standard_Boolean Flag = Standard_True;
364 Standard_Integer I; // svv Jan 11 2000 : porting on DEC
365 for (I = 0; ((I < upper) && (Flag)); I++)
366 Flag &= (ent->Weight(I) > 0);
369 Message_Msg Msg104("XSTEP_104");
370 ach->SendFail(Msg104);
373 Flag = Standard_True;
374 Standard_Real tempVal = ent->Weight(lower);
376 for (I = lower; ((I < upper) && (Flag)); I++)
377 Flag &= (ent->Weight(I) == tempVal);
379 if (Flag && !ent->IsPolynomial(Standard_True))
380 ach.AddWarning("All weights equal & PROP3 != 1 (Curve Not Polynomial)");
381 if (!Flag && ent->IsPolynomial(Standard_True))
382 ach.AddWarning("All weights not equal & PROP3 != 0 (Curve Not Rational)");
385 if (ent->IsPlanar()) {
386 gp_XYZ aNorm = ent->Normal();
387 Standard_Real epsn = eps * 10.; // Tolerance ?? ici large
388 Standard_Real normod = aNorm.SquareModulus();
390 Message_Msg Msg109("XSTEP_109");
391 ach->AddWarning(Msg109);
397 //=======================================================================
400 //=======================================================================
402 void IGESGeom_ToolBSplineCurve::OwnDump(const Handle(IGESGeom_BSplineCurve)& ent,
403 const IGESData_IGESDumper& /* dumper */,
404 const Handle(Message_Messenger)& S,
405 const Standard_Integer level) const
407 Standard_Integer upind = ent->UpperIndex();
408 S << "BSplineCurve from IGESGeom" << Message_EndLine;
409 S << "Sum UpperIndex : " << upind;
410 S << " Degree : " << ent->Degree() << " ";
411 S << (ent->IsPlanar() ? "Planar" : "NonPlanar") << Message_EndLine;
412 S << (ent->IsClosed() ? "Closed" : "Open") << " ";
413 S << (ent->IsPeriodic() ? "Periodic" : "NonPeriodic") << " ";//#54 rln 24.12.98 CCI60005
414 S << (ent->IsPolynomial(Standard_True) ? "Polynomial" : "Rational");
416 S << Message_EndLine << "Knots : ";
417 IGESData_DumpVals(S ,level,-ent->Degree(), upind+1,ent->Knot);
418 S << Message_EndLine << "Weights : ";
419 IGESData_DumpVals(S ,level,0, upind,ent->Weight);
420 S << Message_EndLine << "Control Points (Poles) : ";
421 IGESData_DumpListXYZL(S ,level,0, upind, ent->Pole, ent->Location());
422 S << Message_EndLine << "Starting Parameter Value : " << ent->UMin();
423 S << " Ending Parameter Value : " << ent->UMax() << Message_EndLine;
424 S << "Unit Normal : ";
425 IGESData_DumpXYZL(S,level, ent->Normal(), ent->Location());
426 S << Message_EndLine;