0023337: The 'strcmp' function returns 0 if corresponding strings are equal. (1)
[occt.git] / src / IGESGraph / IGESGraph_ToolDrawingUnits.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 <IGESGraph_ToolDrawingUnits.ixx>
24#include <IGESData_ParamCursor.hxx>
25#include <TCollection_HAsciiString.hxx>
26#include <Interface_Macros.hxx>
27#include <IGESData_Dump.hxx>
28
29
30IGESGraph_ToolDrawingUnits::IGESGraph_ToolDrawingUnits () { }
31
32
33void IGESGraph_ToolDrawingUnits::ReadOwnParams
34 (const Handle(IGESGraph_DrawingUnits)& ent,
35 const Handle(IGESData_IGESReaderData)& /*IR*/, IGESData_ParamReader& PR) const
36{
37 //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
38
39 Standard_Integer nbPropertyValues;
40 Standard_Integer flag;
41 Handle(TCollection_HAsciiString) unit;
42
43 // Reading nbPropertyValues(Integer)
44 PR.ReadInteger(PR.Current(), "No. of property values", nbPropertyValues); //szv#4:S4163:12Mar99 `st=` not needed
45 if (nbPropertyValues != 2)
46 PR.AddFail("No. of Property values : Value is not 2");
47
48 // Reading flag(Integer)
49 PR.ReadInteger(PR.Current(), "Units Flag", flag); //szv#4:S4163:12Mar99 `st=` not needed
50
51 // Reading unit(String)
52 PR.ReadText(PR.Current(), "Units Name", unit); //szv#4:S4163:12Mar99 `st=` not needed
53
54 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
55 ent->Init(nbPropertyValues, flag, unit);
56}
57
58void IGESGraph_ToolDrawingUnits::WriteOwnParams
59 (const Handle(IGESGraph_DrawingUnits)& ent, IGESData_IGESWriter& IW) const
60{
61 IW.Send( ent->NbPropertyValues() );
62 IW.Send( ent->Flag() );
63 IW.Send( ent->Unit() );
64}
65
66void IGESGraph_ToolDrawingUnits::OwnShared
67 (const Handle(IGESGraph_DrawingUnits)& /*ent*/, Interface_EntityIterator& /*iter*/) const
68{
69}
70
71void IGESGraph_ToolDrawingUnits::OwnCopy
72 (const Handle(IGESGraph_DrawingUnits)& another,
73 const Handle(IGESGraph_DrawingUnits)& ent, Interface_CopyTool& /*TC*/) const
74{
75 Standard_Integer NbPropertyValues;
76 Standard_Integer Flag;
77 Handle(TCollection_HAsciiString) Unit;
78
79 NbPropertyValues = another->NbPropertyValues();
80 Flag = another->Flag();
81 Unit = new TCollection_HAsciiString(another->Unit());
82
83 ent->Init(NbPropertyValues, Flag, Unit);
84}
85
86Standard_Boolean IGESGraph_ToolDrawingUnits::OwnCorrect
87 (const Handle(IGESGraph_DrawingUnits)& ent) const
88{
89 Standard_Boolean res = (ent->NbPropertyValues() != 2);
90// ya aussi les noms : Flag a priorite sur Unit
91 Standard_Integer unf = ent->Flag();
92 Handle(TCollection_HAsciiString) name;
93 Standard_CString unm = "";
94 if (!ent->Unit().IsNull()) unm = ent->Unit()->ToCString();
95 switch (unf) {
b28f4666 96 case 1 : if ((strcmp(unm,"IN") == 0) || (strcmp(unm,"INCH") == 0))
7fd59977 97 name = new TCollection_HAsciiString ("IN"); break;
b28f4666 98 case 2 : if (strcmp(unm,"MM") == 0)
7fd59977 99 name = new TCollection_HAsciiString ("MM"); break;
100 case 3 : break; // nom libre
b28f4666 101 case 4 : if (strcmp(unm,"FT") == 0)
7fd59977 102 name = new TCollection_HAsciiString ("FT"); break;
b28f4666 103 case 5 : if (strcmp(unm,"MI") == 0)
7fd59977 104 name = new TCollection_HAsciiString ("MI"); break;
b28f4666 105 case 6 : if (strcmp(unm,"M") == 0)
7fd59977 106 name = new TCollection_HAsciiString ("M"); break;
b28f4666 107 case 7 : if (strcmp(unm,"KM") == 0)
7fd59977 108 name = new TCollection_HAsciiString ("KM"); break;
b28f4666 109 case 8 : if (strcmp(unm,"MIL") == 0)
7fd59977 110 name = new TCollection_HAsciiString ("MIL"); break;
b28f4666 111 case 9 : if (strcmp(unm,"UM") == 0)
7fd59977 112 name = new TCollection_HAsciiString ("UM"); break;
b28f4666 113 case 10 : if (strcmp(unm,"CM") == 0)
7fd59977 114 name = new TCollection_HAsciiString ("CM"); break;
b28f4666 115 case 11 : if (strcmp(unm,"UIN") == 0)
7fd59977 116 name = new TCollection_HAsciiString ("UIN"); break;
117 default : break; // on ne peut rien faire ... ?
118 }
119
120 res |= (!name.IsNull());
121 if (name.IsNull()) name = ent->Unit();
122 if (res) ent->Init(2,unf,name); // nbpropertyvalues=2 + Unit Flag//Name
123 return res;
124}
125
126IGESData_DirChecker IGESGraph_ToolDrawingUnits::DirChecker
127 (const Handle(IGESGraph_DrawingUnits)& /*ent*/) const
128{
129 IGESData_DirChecker DC (406, 17);
130 DC.Structure(IGESData_DefVoid);
131 DC.LineFont(IGESData_DefVoid);
132 DC.LineWeight(IGESData_DefVoid);
133 DC.Color(IGESData_DefVoid);
134 DC.BlankStatusIgnored();
135 DC.UseFlagIgnored();
136 DC.HierarchyStatusIgnored();
137 return DC;
138}
139
140void IGESGraph_ToolDrawingUnits::OwnCheck
141 (const Handle(IGESGraph_DrawingUnits)& ent,
142 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
143{
144 if (ent->NbPropertyValues() != 2)
145 ach->AddFail("No. of Property values : Value != 2");
146// Check Flag//Unit Name
147 Standard_Integer unf = ent->Flag();
148 if (ent->Unit().IsNull()) {
149 if (unf == 3) ach->AddFail
150 ("Unit Flag = 3 (user def.) and Unit Name undefined");
151 } else {
152 Standard_CString unm = ent->Unit()->ToCString();
153 Standard_Boolean unok = Standard_True;
154 switch (unf) {
155 case 1 : unok = (!strcmp(unm,"IN") || !strcmp(unm,"INCH")); break;
156 case 2 : unok = !strcmp(unm,"MM"); break;
157 case 3 : unok = Standard_True; break; // nom libre
158 case 4 : unok = !strcmp(unm,"FT"); break;
159 case 5 : unok = !strcmp(unm,"MI"); break;
160 case 6 : unok = !strcmp(unm,"M"); break;
161 case 7 : unok = !strcmp(unm,"KM"); break;
162 case 8 : unok = !strcmp(unm,"MIL"); break;
163 case 9 : unok = !strcmp(unm,"UM"); break;
164 case 10 : unok = !strcmp(unm,"CM"); break;
165 case 11 : unok = !strcmp(unm,"UIN"); break;
166 default : ach->AddFail("Unit Flag not in range 1 - 11");
167 break;
168 }
169 if (!unok) ach->AddFail("Unit Flag & Name not accorded");
170 }
171}
172
173void IGESGraph_ToolDrawingUnits::OwnDump
174 (const Handle(IGESGraph_DrawingUnits)& ent, const IGESData_IGESDumper& /*dumper*/,
175 const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
176{
177 S << "IGESGraph_DrawingUnits" << endl;
178
179 S << "No. of property values : " << ent->NbPropertyValues() << endl;
180 S << " Units Flag : " << ent->Flag();
181 S << " Units Name : ";
182 IGESData_DumpString(S,ent->Unit());
183 S << " computed Value (in meters) : " << ent->UnitValue();
184 S << endl;
185}