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 <IGESData_DirChecker.hxx>
20 #include <IGESData_Dump.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 <IGESGraph_DrawingUnits.hxx>
27 #include <IGESGraph_ToolDrawingUnits.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_Messenger.hxx>
34 #include <Standard_DomainError.hxx>
35 #include <TCollection_HAsciiString.hxx>
37 IGESGraph_ToolDrawingUnits::IGESGraph_ToolDrawingUnits () { }
40 void IGESGraph_ToolDrawingUnits::ReadOwnParams
41 (const Handle(IGESGraph_DrawingUnits)& ent,
42 const Handle(IGESData_IGESReaderData)& /*IR*/, IGESData_ParamReader& PR) const
44 //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
46 Standard_Integer nbPropertyValues;
47 Standard_Integer flag;
48 Handle(TCollection_HAsciiString) unit;
50 // Reading nbPropertyValues(Integer)
51 PR.ReadInteger(PR.Current(), "No. of property values", nbPropertyValues); //szv#4:S4163:12Mar99 `st=` not needed
52 if (nbPropertyValues != 2)
53 PR.AddFail("No. of Property values : Value is not 2");
55 // Reading flag(Integer)
56 PR.ReadInteger(PR.Current(), "Units Flag", flag); //szv#4:S4163:12Mar99 `st=` not needed
58 // Reading unit(String)
59 PR.ReadText(PR.Current(), "Units Name", unit); //szv#4:S4163:12Mar99 `st=` not needed
61 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
62 ent->Init(nbPropertyValues, flag, unit);
65 void IGESGraph_ToolDrawingUnits::WriteOwnParams
66 (const Handle(IGESGraph_DrawingUnits)& ent, IGESData_IGESWriter& IW) const
68 IW.Send( ent->NbPropertyValues() );
69 IW.Send( ent->Flag() );
70 IW.Send( ent->Unit() );
73 void IGESGraph_ToolDrawingUnits::OwnShared
74 (const Handle(IGESGraph_DrawingUnits)& /*ent*/, Interface_EntityIterator& /*iter*/) const
78 void IGESGraph_ToolDrawingUnits::OwnCopy
79 (const Handle(IGESGraph_DrawingUnits)& another,
80 const Handle(IGESGraph_DrawingUnits)& ent, Interface_CopyTool& /*TC*/) const
82 Standard_Integer NbPropertyValues;
83 Standard_Integer Flag;
84 Handle(TCollection_HAsciiString) Unit;
86 NbPropertyValues = another->NbPropertyValues();
87 Flag = another->Flag();
88 Unit = new TCollection_HAsciiString(another->Unit());
90 ent->Init(NbPropertyValues, Flag, Unit);
93 Standard_Boolean IGESGraph_ToolDrawingUnits::OwnCorrect
94 (const Handle(IGESGraph_DrawingUnits)& ent) const
96 Standard_Boolean res = (ent->NbPropertyValues() != 2);
97 // ya aussi les noms : Flag a priorite sur Unit
98 Standard_Integer unf = ent->Flag();
99 Handle(TCollection_HAsciiString) name;
100 Standard_CString unm = "";
101 if (!ent->Unit().IsNull()) unm = ent->Unit()->ToCString();
104 if ((strcmp(unm,"IN") == 0) || (strcmp(unm,"INCH") == 0))
106 name = new TCollection_HAsciiString ("IN");
110 if (strcmp(unm,"MM") == 0)
112 name = new TCollection_HAsciiString ("MM");
118 if (strcmp(unm,"FT") == 0)
120 name = new TCollection_HAsciiString ("FT");
124 if (strcmp(unm,"MI") == 0)
126 name = new TCollection_HAsciiString ("MI");
130 if (strcmp(unm,"M") == 0)
132 name = new TCollection_HAsciiString ("M");
136 if (strcmp(unm,"KM") == 0)
138 name = new TCollection_HAsciiString ("KM");
142 if (strcmp(unm,"MIL") == 0)
144 name = new TCollection_HAsciiString ("MIL");
148 if (strcmp(unm,"UM") == 0)
150 name = new TCollection_HAsciiString ("UM");
154 if (strcmp(unm,"CM") == 0)
156 name = new TCollection_HAsciiString ("CM");
160 if (strcmp(unm,"UIN") == 0)
162 name = new TCollection_HAsciiString ("UIN");
166 break; // on ne peut rien faire ... ?
169 res |= (!name.IsNull());
170 if (name.IsNull()) name = ent->Unit();
171 if (res) ent->Init(2,unf,name); // nbpropertyvalues=2 + Unit Flag//Name
175 IGESData_DirChecker IGESGraph_ToolDrawingUnits::DirChecker
176 (const Handle(IGESGraph_DrawingUnits)& /*ent*/) const
178 IGESData_DirChecker DC (406, 17);
179 DC.Structure(IGESData_DefVoid);
180 DC.LineFont(IGESData_DefVoid);
181 DC.LineWeight(IGESData_DefVoid);
182 DC.Color(IGESData_DefVoid);
183 DC.BlankStatusIgnored();
185 DC.HierarchyStatusIgnored();
189 void IGESGraph_ToolDrawingUnits::OwnCheck
190 (const Handle(IGESGraph_DrawingUnits)& ent,
191 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
193 if (ent->NbPropertyValues() != 2)
194 ach->AddFail("No. of Property values : Value != 2");
195 // Check Flag//Unit Name
196 Standard_Integer unf = ent->Flag();
197 if (ent->Unit().IsNull()) {
198 if (unf == 3) ach->AddFail
199 ("Unit Flag = 3 (user def.) and Unit Name undefined");
201 Standard_CString unm = ent->Unit()->ToCString();
202 Standard_Boolean unok = Standard_True;
204 case 1 : unok = (!strcmp(unm,"IN") || !strcmp(unm,"INCH")); break;
205 case 2 : unok = !strcmp(unm,"MM"); break;
206 case 3 : unok = Standard_True; break; // nom libre
207 case 4 : unok = !strcmp(unm,"FT"); break;
208 case 5 : unok = !strcmp(unm,"MI"); break;
209 case 6 : unok = !strcmp(unm,"M"); break;
210 case 7 : unok = !strcmp(unm,"KM"); break;
211 case 8 : unok = !strcmp(unm,"MIL"); break;
212 case 9 : unok = !strcmp(unm,"UM"); break;
213 case 10 : unok = !strcmp(unm,"CM"); break;
214 case 11 : unok = !strcmp(unm,"UIN"); break;
215 default : ach->AddFail("Unit Flag not in range 1 - 11");
218 if (!unok) ach->AddFail("Unit Flag & Name not accorded");
222 void IGESGraph_ToolDrawingUnits::OwnDump
223 (const Handle(IGESGraph_DrawingUnits)& ent, const IGESData_IGESDumper& /*dumper*/,
224 const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
226 S << "IGESGraph_DrawingUnits" << endl;
228 S << "No. of property values : " << ent->NbPropertyValues() << endl;
229 S << " Units Flag : " << ent->Flag();
230 S << " Units Name : ";
231 IGESData_DumpString(S,ent->Unit());
232 S << " computed Value (in meters) : " << ent->UnitValue();