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 //--------------------------------------------------------------------
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_LineFontEntity.hxx>
27 #include <IGESData_ParamCursor.hxx>
28 #include <IGESData_ParamReader.hxx>
29 #include <IGESDimen_CenterLine.hxx>
30 #include <IGESDimen_ToolCenterLine.hxx>
31 #include <Interface_Check.hxx>
32 #include <Interface_CopyTool.hxx>
33 #include <Interface_EntityIterator.hxx>
34 #include <Interface_Macros.hxx>
35 #include <Interface_ShareTool.hxx>
36 #include <Message_Messenger.hxx>
37 #include <Standard_DomainError.hxx>
38 #include <TColgp_HArray1OfXY.hxx>
40 IGESDimen_ToolCenterLine::IGESDimen_ToolCenterLine () { }
43 void IGESDimen_ToolCenterLine::ReadOwnParams
44 (const Handle(IGESDimen_CenterLine)& ent,
45 const Handle(IGESData_IGESReaderData)& /* IR */, IGESData_ParamReader& PR) const
47 //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
49 Standard_Integer datatype;
50 Standard_Real zDisplacement;
51 Standard_Integer nbval;
52 Handle(TColgp_HArray1OfXY) dataPoints;
54 PR.ReadInteger(PR.Current(), "Interpretation Flag", datatype); //szv#4:S4163:12Mar99 `st=` not needed
56 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of data points", nbval);
57 if (st && nbval > 0) dataPoints = new TColgp_HArray1OfXY(1, nbval);
58 else PR.AddFail("Number of data points: Not Positive");
60 PR.ReadReal(PR.Current(), "Common Z Displacement", zDisplacement); //szv#4:S4163:12Mar99 `st=` not needed
62 if (! dataPoints.IsNull())
63 for (Standard_Integer i = 1; i <= nbval; i++)
66 //st = PR.ReadXY(PR.CurrentList(1, 2), "Data Points", tempXY); //szv#4:S4163:12Mar99 moved in if
67 if (PR.ReadXY(PR.CurrentList(1, 2), "Data Points", tempXY))
68 dataPoints->SetValue(i, tempXY);
71 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
72 ent->Init(datatype, zDisplacement, dataPoints);
75 void IGESDimen_ToolCenterLine::WriteOwnParams
76 (const Handle(IGESDimen_CenterLine)& ent, IGESData_IGESWriter& IW) const
78 Standard_Integer upper = ent->NbPoints();
79 IW.Send(ent->Datatype());
81 IW.Send(ent->ZDisplacement());
82 for (Standard_Integer i = 1; i <= upper; i++)
84 IW.Send((ent->Point(i)).X());
85 IW.Send((ent->Point(i)).Y());
89 void IGESDimen_ToolCenterLine::OwnShared
90 (const Handle(IGESDimen_CenterLine)& /* ent */, Interface_EntityIterator& /* iter */) const
94 void IGESDimen_ToolCenterLine::OwnCopy
95 (const Handle(IGESDimen_CenterLine)& another,
96 const Handle(IGESDimen_CenterLine)& ent, Interface_CopyTool& /* TC */) const
98 Standard_Integer datatype = another->Datatype();
99 Standard_Integer nbval = another->NbPoints();
100 Standard_Real zDisplacement = another->ZDisplacement();
102 Handle(TColgp_HArray1OfXY) dataPoints = new TColgp_HArray1OfXY(1, nbval);
104 for (Standard_Integer i = 1; i <= nbval; i++)
106 gp_Pnt tempPnt = (another->Point(i));
107 gp_XY tempPnt2d(tempPnt.X(), tempPnt.Y());
108 dataPoints->SetValue(i, tempPnt2d);
110 ent->Init(datatype, zDisplacement, dataPoints);
111 ent->SetCrossHair (another->IsCrossHair());
114 Standard_Boolean IGESDimen_ToolCenterLine::OwnCorrect
115 (const Handle(IGESDimen_CenterLine)& ent) const
117 Standard_Boolean res = (ent->RankLineFont() != 1);
119 Handle(IGESData_LineFontEntity) nulfont;
120 ent->InitLineFont(nulfont,1);
122 if (ent->Datatype() == 1) return res;
123 // Forcer DataType = 1 -> reconstruire
124 Standard_Integer nb = ent->NbPoints();
125 if (nb == 0) return res; // rien pu faire (est-ce possible ?)
126 Handle(TColgp_HArray1OfXY) pts = new TColgp_HArray1OfXY(1,nb);
127 for (Standard_Integer i = 1; i <= nb; i ++)
128 pts->SetValue(i, gp_XY(ent->Point(i).X(),ent->Point(i).Y()) );
129 ent->Init (1,ent->ZDisplacement(),pts);
130 return Standard_True;
133 IGESData_DirChecker IGESDimen_ToolCenterLine::DirChecker
134 (const Handle(IGESDimen_CenterLine)& /* ent */) const
136 IGESData_DirChecker DC (106, 20, 21);
137 DC.Structure(IGESData_DefVoid);
138 DC.LineFont(IGESData_DefValue);
139 DC.LineWeight(IGESData_DefValue);
140 DC.Color(IGESData_DefAny);
141 DC.UseFlagRequired(1);
142 DC.HierarchyStatusIgnored();
146 void IGESDimen_ToolCenterLine::OwnCheck
147 (const Handle(IGESDimen_CenterLine)& ent,
148 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
150 if (ent->RankLineFont() != 1)
151 ach->AddFail("Line Font Pattern != 1");
152 if (ent->Datatype() != 1)
153 ach->AddFail("Interpretation Flag != 1");
154 if (ent->NbPoints()%2 != 0)
155 ach->AddFail("Number of data points is not even");
158 void IGESDimen_ToolCenterLine::OwnDump
159 (const Handle(IGESDimen_CenterLine)& ent, const IGESData_IGESDumper& /* dumper */,
160 const Handle(Message_Messenger)& S, const Standard_Integer level) const
162 S << "IGESDimen_CenterLine" << Message_EndLine;
163 if (ent->IsCrossHair()) S << "Cross Hair" << Message_EndLine;
164 else S << "Through Circle Centers" << Message_EndLine;
165 S << "Data Type : " << ent->Datatype() << " ";
166 S << "Number of Data Points : " << ent->NbPoints() << " ";
167 S << "Common Z displacement : " << ent->ZDisplacement() << " ";
168 S << "Data Points : " << Message_EndLine;
169 IGESData_DumpListXYLZ(S ,level,1, ent->NbPoints(),ent->Point,
170 ent->Location(), ent->ZDisplacement());
171 S << Message_EndLine;